aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quickcontrols/controls/data/tst_swipeview.qml
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/quickcontrols/controls/data/tst_swipeview.qml')
-rw-r--r--tests/auto/quickcontrols/controls/data/tst_swipeview.qml164
1 files changed, 124 insertions, 40 deletions
diff --git a/tests/auto/quickcontrols/controls/data/tst_swipeview.qml b/tests/auto/quickcontrols/controls/data/tst_swipeview.qml
index c853f6dd55..8d59c4a09a 100644
--- a/tests/auto/quickcontrols/controls/data/tst_swipeview.qml
+++ b/tests/auto/quickcontrols/controls/data/tst_swipeview.qml
@@ -1,5 +1,5 @@
// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
import QtQuick
import QtTest
@@ -28,24 +28,26 @@ TestCase {
SignalSpy { }
}
- function test_defaults() {
+ function init() {
failOnWarning(/.?/)
+ }
+ function test_defaults() {
let control = createTemporaryObject(swipeView, testCase)
verify(control)
}
function test_current() {
- var control = createTemporaryObject(swipeView, testCase)
+ let control = createTemporaryObject(swipeView, testCase)
- var currentItemChangedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "currentItemChanged"})
+ let currentItemChangedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "currentItemChanged"})
verify(currentItemChangedSpy.valid)
compare(control.count, 0)
compare(control.currentIndex, -1)
compare(control.currentItem, null)
- var item0 = page.createObject(control, {text: "0"})
+ let item0 = page.createObject(control, {text: "0"})
control.addItem(item0)
compare(control.count, 1)
compare(control.currentIndex, 0)
@@ -54,7 +56,7 @@ TestCase {
compare(control.contentWidth, item0.implicitWidth)
compare(control.contentHeight, item0.implicitHeight)
- var item1 = page.createObject(control, {text: "11"})
+ let item1 = page.createObject(control, {text: "11"})
control.addItem(item1)
compare(control.count, 2)
compare(control.currentIndex, 0)
@@ -63,7 +65,7 @@ TestCase {
compare(control.contentWidth, item0.implicitWidth)
compare(control.contentHeight, item0.implicitHeight)
- var item2 = page.createObject(control, {text: "222"})
+ let item2 = page.createObject(control, {text: "222"})
control.addItem(item2)
compare(control.count, 3)
compare(control.currentIndex, 0)
@@ -119,7 +121,7 @@ TestCase {
}
function test_initialCurrent() {
- var control = createTemporaryObject(initialCurrentSwipeView, testCase)
+ let control = createTemporaryObject(initialCurrentSwipeView, testCase)
compare(control.count, 2)
compare(control.currentIndex, 1)
@@ -127,7 +129,7 @@ TestCase {
}
function test_addRemove() {
- var control = createTemporaryObject(swipeView, testCase)
+ let control = createTemporaryObject(swipeView, testCase)
function verifyCurrentIndexCountDiff() {
verify(control.currentIndex < control.count)
@@ -135,7 +137,7 @@ TestCase {
control.currentIndexChanged.connect(verifyCurrentIndexCountDiff)
control.countChanged.connect(verifyCurrentIndexCountDiff)
- var currentItemChangedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "currentItemChanged"})
+ let currentItemChangedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "currentItemChanged"})
verify(currentItemChangedSpy.valid)
compare(control.count, 0)
@@ -235,12 +237,12 @@ TestCase {
}
function test_content() {
- var control = createTemporaryObject(contentView, testCase)
+ let control = createTemporaryObject(contentView, testCase)
function compareObjectNames(content, names) {
if (content.length !== names.length)
return false
- for (var i = 0; i < names.length; ++i) {
+ for (let i = 0; i < names.length; ++i) {
if (content[i].objectName !== names[i])
return false
}
@@ -280,20 +282,20 @@ TestCase {
}
function test_repeater() {
- var control = createTemporaryObject(repeated, testCase)
+ let control = createTemporaryObject(repeated, testCase)
verify(control)
- var model = control.contentModel
+ let model = control.contentModel
verify(model)
- var repeater = control.repeater
+ let repeater = control.repeater
verify(repeater)
compare(repeater.count, 5)
compare(model.count, 5)
- for (var i = 0; i < 5; ++i) {
- var item1 = control.itemAt(i)
+ for (let i = 0; i < 5; ++i) {
+ let item1 = control.itemAt(i)
verify(item1)
compare(item1.idx, i)
compare(model.get(i), item1)
@@ -304,8 +306,8 @@ TestCase {
compare(repeater.count, 3)
compare(model.count, 3)
- for (var j = 0; j < 3; ++j) {
- var item2 = control.itemAt(j)
+ for (let j = 0; j < 3; ++j) {
+ let item2 = control.itemAt(j)
verify(item2)
compare(item2.idx, j)
compare(model.get(j), item2)
@@ -334,7 +336,7 @@ TestCase {
}
function test_order() {
- var control = createTemporaryObject(ordered, testCase)
+ let control = createTemporaryObject(ordered, testCase)
verify(control)
compare(control.count, 7)
@@ -395,14 +397,14 @@ TestCase {
}
function test_move(data) {
- var control = createTemporaryObject(swipeView, testCase)
+ let control = createTemporaryObject(swipeView, testCase)
compare(control.count, 0)
- var titles = ["1", "2", "3"]
+ let titles = ["1", "2", "3"]
- var i = 0;
+ let i = 0;
for (i = 0; i < titles.length; ++i) {
- var item = pageAttached.createObject(control, {text: titles[i]})
+ let item = pageAttached.createObject(control, {text: titles[i]})
control.addItem(item)
}
@@ -427,7 +429,7 @@ TestCase {
compare(control.count, titles.length)
compare(control.currentIndex, data.currentAfter)
- var title = titles[data.from]
+ let title = titles[data.from]
titles.splice(data.from, 1)
titles.splice(data.to, 0, title)
@@ -455,13 +457,13 @@ TestCase {
}
function test_dynamic() {
- var control = createTemporaryObject(dynamicView, testCase)
+ let control = createTemporaryObject(dynamicView, testCase)
// insertItem(), addItem(), createObject() and static page {}
compare(control.count, 4)
compare(control.itemAt(0).text, "inserted")
- var tab = page.createObject(control, {text: "dying"})
+ let tab = page.createObject(control, {text: "dying"})
compare(control.count, 5)
compare(control.itemAt(4).text, "dying")
@@ -472,9 +474,9 @@ TestCase {
}
function test_attachedParent() {
- var control = createTemporaryObject(swipeView, testCase);
+ let control = createTemporaryObject(swipeView, testCase);
- var page = createTemporaryObject(pageAttached, testCase);
+ let page = createTemporaryObject(pageAttached, testCase);
compare(page.view, null);
compare(page.index, -1);
compare(page.isCurrentItem, false);
@@ -509,17 +511,17 @@ TestCase {
}
function test_orientation() {
- var control = createTemporaryObject(swipeView, testCase, {width: 200, height: 200})
+ let control = createTemporaryObject(swipeView, testCase, {width: 200, height: 200})
verify(control)
- for (var i = 0; i < 3; ++i)
+ for (let i = 0; i < 3; ++i)
control.addItem(page.createObject(control, {text: i}))
compare(control.orientation, Qt.Horizontal)
compare(control.horizontal, true)
compare(control.vertical, false)
- for (i = 0; i < control.count; ++i) {
+ for (let i = 0; i < control.count; ++i) {
control.currentIndex = i
compare(control.itemAt(i).y, 0)
}
@@ -529,7 +531,7 @@ TestCase {
compare(control.horizontal, false)
compare(control.vertical, true)
- for (i = 0; i < control.count; ++i) {
+ for (let i = 0; i < control.count; ++i) {
control.currentIndex = i
compare(control.itemAt(i).x, 0)
}
@@ -564,7 +566,7 @@ TestCase {
if (Qt.styleHints.tabFocusBehavior !== Qt.TabFocusAllControls)
skip("This platform only allows tab focus for text controls")
- var control = createTemporaryObject(focusSwipeViewComponent, testCase)
+ let control = createTemporaryObject(focusSwipeViewComponent, testCase)
verify(control)
compare(control.focus, true)
compare(control.contentItem.focus, true)
@@ -643,7 +645,7 @@ TestCase {
tryCompare(rect, "visible", true)
if (Qt.platform.pluginName === "offscreen")
skip("grabImage() is not functional on the offscreen platform (QTBUG-63185)")
- var image = grabImage(control)
+ let image = grabImage(control)
compare(image.pixel(3, 3), "#ffff00")
}
@@ -651,7 +653,10 @@ TestCase {
id: translucentPages
SwipeView {
spacing: 10
- padding: 10
+ leftPadding: 10
+ topPadding: 10
+ rightPadding: 10
+ bottomPadding: 10
Text { text: "page 0" }
Text { text: "page 1"; font.pointSize: 16 }
Text { text: "page 2"; font.pointSize: 24 }
@@ -662,18 +667,97 @@ TestCase {
function test_initialPositions() { // QTBUG-102487
const control = createTemporaryObject(translucentPages, testCase, {width: 320, height: 200})
verify(control)
+ compare(control.contentItem.width, control.width - control.leftPadding - control.rightPadding)
+ compare(control.spacing, 10)
+
compare(control.orientation, Qt.Horizontal)
- for (var i = 0; i < control.count; ++i) {
+ for (let i = 0; i < control.count; ++i) {
const page = control.itemAt(i)
- // control.contentItem.width + control.spacing == 310; except Imagine style has contentItem.width == 320
- compare(page.x, i * 310)
+ compare(page.x, i * (control.contentItem.width + control.spacing))
compare(page.y, 0)
+ compare(page.width, control.contentItem.width)
+ compare(page.height, control.contentItem.height)
}
control.orientation = Qt.Vertical
- for (var i = 0; i < control.count; ++i) {
+ for (let i = 0; i < control.count; ++i) {
const page = control.itemAt(i)
compare(page.y, i * (control.contentItem.height + control.spacing))
compare(page.x, 0)
+ compare(page.width, control.contentItem.width)
+ compare(page.height, control.contentItem.height)
+ }
+
+ // QTBUG-115468: add a page after startup and check that that works too.
+ control.orientation = Qt.Horizontal
+ let page4 = page.createObject(control, { text: "page 4", "font.pointSize": 40 })
+ control.insertItem(control.count, page4)
+ compare(page4.x, (control.count - 1) * 310)
+ compare(page4.y, 0)
+ compare(page4.width, control.contentItem.width)
+ compare(page4.height, control.contentItem.height)
+ }
+
+ Component {
+ id: doublePageWithLabels
+ SwipeView {
+ anchors.fill: parent
+ property alias item1: item1
+ property alias item2: item2
+ Item {
+ id: item1
+ property alias label: label1
+ Label { id: label1; anchors.centerIn: parent; text: "1"; }
+ }
+ Item {
+ id: item2
+ property alias label: label2
+ Label { id: label2; anchors.centerIn: parent; text: "2"; }
+ }
+ }
+ }
+
+ function test_rightClick_data() {
+ return [
+ { tag: "mouse_left", mouse: true, button: Qt.LeftButton },
+ { tag: "mouse_right", mouse: true, button: Qt.RightButton },
+ { tag: "touch", touch: true }
+ ]
+ }
+
+ function test_rightClick(data) {
+ let swipeView = createTemporaryObject(doublePageWithLabels, testCase)
+ verify(swipeView)
+ let item1 = swipeView.item1
+ verify(item1)
+ let item2 = swipeView.item2
+ verify(item2)
+ let label1 = item1.label
+ verify(label1)
+ let label2 = item2.label
+ verify(label2)
+ const swipeListView = swipeView.contentItem
+ verify(swipeListView)
+
+ swipeView.currentIndex = 0
+ compare(swipeView.currentIndex, 0)
+ compare(swipeView.currentItem, item1)
+ tryCompare(swipeListView, "contentX", 0, 1000)
+ compare(item2.x, swipeListView.width)
+
+ let touch = data.touch ? touchEvent(swipeView) : null
+
+ if (data.touch) {
+ touch.press(0, label1, label1.width / 2, label1.height / 2)
+ touch.commit()
+ touch.release(0, label1, label1.width / 2, label1.height / 2)
+ touch.commit()
+ } else if (data.mouse) {
+ mouseClick(label1, label1.width / 2, label1.height / 2, data.button)
}
+ swipeView.currentIndex = 1
+ compare(swipeView.currentIndex, 1)
+ compare(swipeView.currentItem, item2)
+ tryCompare(swipeListView, "contentX", swipeListView.width, 1000)
+ compare(item2.x, swipeListView.width)
}
}