aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/controls/data
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/controls/data')
-rw-r--r--tests/auto/controls/data/tst_abstractbutton.qml36
-rw-r--r--tests/auto/controls/data/tst_combobox.qml63
-rw-r--r--tests/auto/controls/data/tst_spinbox.qml32
-rw-r--r--tests/auto/controls/data/tst_tabbar.qml32
-rw-r--r--tests/auto/controls/data/tst_tooltip.qml76
-rw-r--r--tests/auto/controls/data/tst_tumbler.qml137
6 files changed, 333 insertions, 43 deletions
diff --git a/tests/auto/controls/data/tst_abstractbutton.qml b/tests/auto/controls/data/tst_abstractbutton.qml
index cb12f6f1..27fc4525 100644
--- a/tests/auto/controls/data/tst_abstractbutton.qml
+++ b/tests/auto/controls/data/tst_abstractbutton.qml
@@ -55,6 +55,11 @@ TestCase {
AbstractButton {}
}
+ Component {
+ id: item
+ Item { }
+ }
+
function test_text() {
var control = button.createObject(testCase);
verify(control);
@@ -67,4 +72,35 @@ TestCase {
control.destroy();
}
+
+ function test_baseline() {
+ var control = button.createObject(testCase, {padding: 6})
+ verify(control)
+ compare(control.baselineOffset, 0)
+ control.contentItem = item.createObject(control, {baselineOffset: 12})
+ compare(control.baselineOffset, 18)
+ control.destroy()
+ }
+
+ function test_implicitSize() {
+ var control = button.createObject(testCase)
+ verify(control)
+
+ compare(control.implicitWidth, 0)
+ compare(control.implicitHeight, 0)
+
+ control.contentItem = item.createObject(control, {implicitWidth: 10, implicitHeight: 20})
+ compare(control.implicitWidth, 10)
+ compare(control.implicitHeight, 20)
+
+ control.background = item.createObject(control, {implicitWidth: 20, implicitHeight: 30})
+ compare(control.implicitWidth, 20)
+ compare(control.implicitHeight, 30)
+
+ control.padding = 100
+ compare(control.implicitWidth, 210)
+ compare(control.implicitHeight, 220)
+
+ control.destroy()
+ }
}
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index 4db8c439..5ae1e0a6 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -62,7 +62,17 @@ TestCase {
}
Component {
+ id: signalSpy
+ SignalSpy { }
+ }
+
+ Component {
id: comboBox
+ ComboBox { }
+ }
+
+ Component {
+ id: emptyBox
ComboBox {
delegate: ItemDelegate {
width: popup.width
@@ -131,7 +141,7 @@ TestCase {
}
function test_objects() {
- var control = comboBox.createObject(testCase)
+ var control = emptyBox.createObject(testCase)
verify(control)
var items = [
@@ -238,7 +248,7 @@ TestCase {
}
function test_textRole(data) {
- var control = comboBox.createObject(testCase)
+ var control = emptyBox.createObject(testCase)
verify(control)
control.model = data.model
@@ -443,7 +453,7 @@ TestCase {
keyClick(Qt.Key_Space)
compare(control.currentIndex, 1)
- compare(control.highlightedIndex, -1)
+ tryCompare(control, "highlightedIndex", -1)
control.destroy()
}
@@ -861,4 +871,51 @@ TestCase {
control.destroy()
}
+
+ // QTBUG-55030
+ function test_highlightRange() {
+ var control = comboBox.createObject(testCase, {model: 100})
+ verify(control)
+
+ control.currentIndex = 50
+ compare(control.currentIndex, 50)
+ compare(control.highlightedIndex, -1)
+
+ var openedSpy = signalSpy.createObject(control, {target: control.popup, signalName: "opened"})
+ verify(openedSpy.valid)
+
+ control.popup.open()
+ compare(control.highlightedIndex, 50)
+ tryCompare(openedSpy, "count", 1)
+
+ var listview = control.popup.contentItem
+ verify(listview)
+
+ var first = listview.itemAt(0, listview.contentY)
+ verify(first)
+ compare(first.text, "50")
+
+ var closedSpy = signalSpy.createObject(control, {target: control.popup, signalName: "closed"})
+ verify(closedSpy.valid)
+
+ control.popup.close()
+ tryCompare(closedSpy, "count", 1)
+ compare(control.highlightedIndex, -1)
+
+ control.currentIndex = 99
+ compare(control.currentIndex, 99)
+ compare(control.highlightedIndex, -1)
+
+ control.popup.open()
+ compare(control.highlightedIndex, 99)
+ tryCompare(openedSpy, "count", 2)
+
+ var last = listview.itemAt(0, listview.contentY + listview.height - 1)
+ verify(last)
+ compare(last.text, "99")
+
+ openedSpy.target = null
+ closedSpy.target = null
+ control.destroy()
+ }
}
diff --git a/tests/auto/controls/data/tst_spinbox.qml b/tests/auto/controls/data/tst_spinbox.qml
index 9e836285..81c67681 100644
--- a/tests/auto/controls/data/tst_spinbox.qml
+++ b/tests/auto/controls/data/tst_spinbox.qml
@@ -507,4 +507,36 @@ TestCase {
control.destroy()
}
+
+ function test_valueFromText_data() {
+ return [
+ { tag: "editable", editable: true },
+ { tag: "non-editable", editable: false }
+ ]
+ }
+
+ function test_valueFromText(data) {
+ var control = spinBox.createObject(testCase, {editable: data.editable})
+ verify(control)
+
+ control.forceActiveFocus()
+ verify(control.activeFocus)
+
+ var valueFromTextCalls = 0
+ control.valueFromText = function(text, locale) {
+ ++valueFromTextCalls
+ return Number.fromLocaleString(locale, text);
+ }
+
+ keyClick(Qt.Key_Enter)
+ compare(valueFromTextCalls, data.editable ? 1 : 0)
+
+ keyClick(Qt.Key_Return)
+ compare(valueFromTextCalls, data.editable ? 2 : 0)
+
+ control.focus = false
+ compare(valueFromTextCalls, data.editable ? 3 : 0)
+
+ control.destroy()
+ }
}
diff --git a/tests/auto/controls/data/tst_tabbar.qml b/tests/auto/controls/data/tst_tabbar.qml
index 666fc2cb..92e80952 100644
--- a/tests/auto/controls/data/tst_tabbar.qml
+++ b/tests/auto/controls/data/tst_tabbar.qml
@@ -514,17 +514,37 @@ TestCase {
control.destroy()
}
- function test_layout() {
- var control = tabBar.createObject(testCase, {spacing: 0, width: 200})
+ function test_layout_data() {
+ return [
+ { tag: "spacing:0", spacing: 0 },
+ { tag: "spacing:1", spacing: 1 },
+ { tag: "spacing:10", spacing: 10 },
+ ]
+ }
+
+ function test_layout(data) {
+ var control = tabBar.createObject(testCase, {spacing: data.spacing, width: 200})
- var tab1 = tabButton.createObject(control)
+ var tab1 = tabButton.createObject(control, {text: "First"})
control.addItem(tab1)
tryCompare(tab1, "width", control.width)
- var tab2 = tabButton.createObject(control)
+ var tab2 = tabButton.createObject(control, {text: "Second"})
control.addItem(tab2)
- tryCompare(tab1, "width", control.width / 2)
- tryCompare(tab2, "width", control.width / 2)
+ tryCompare(tab1, "width", (control.width - data.spacing) / 2)
+ compare(tab2.width, (control.width - data.spacing) / 2)
+
+ var tab3 = tabButton.createObject(control, {width: 50, text: "Third"})
+ control.addItem(tab3)
+ tryCompare(tab1, "width", (control.width - 2 * data.spacing - 50) / 2)
+ compare(tab2.width, (control.width - 2 * data.spacing - 50) / 2)
+ compare(tab3.width, 50)
+
+ var expectedWidth = tab3.contentItem.implicitWidth + tab3.leftPadding + tab3.rightPadding
+ tab3.width = tab3.implicitWidth
+ tryCompare(tab1, "width", (control.width - 2 * data.spacing - expectedWidth) / 2)
+ tryCompare(tab2, "width", (control.width - 2 * data.spacing - expectedWidth) / 2)
+ compare(tab3.width, expectedWidth)
control.destroy()
}
diff --git a/tests/auto/controls/data/tst_tooltip.qml b/tests/auto/controls/data/tst_tooltip.qml
index 1e6ecf01..d9c95dbf 100644
--- a/tests/auto/controls/data/tst_tooltip.qml
+++ b/tests/auto/controls/data/tst_tooltip.qml
@@ -156,8 +156,10 @@ TestCase {
function test_delay_data() {
return [
- {tag: "0", delay: 0},
- {tag: "100", delay: 100},
+ {tag: "imperative:0", delay: 0, imperative: true},
+ {tag: "imperative:100", delay: 100, imperative: true},
+ {tag: "declarative:0", delay: 0, imperative: false},
+ {tag: "declarative:100", delay: 100, imperative: false}
]
}
@@ -165,18 +167,31 @@ TestCase {
var control = toolTip.createObject(testCase, {delay: data.delay})
compare(control.visible, false)
- control.open()
+ if (data.imperative)
+ control.open()
+ else
+ control.visible = true
compare(control.visible, data.delay <= 0)
tryCompare(control, "visible", true)
control.destroy()
}
- function test_timeout() {
+ function test_timeout_data() {
+ return [
+ {tag: "imperative", imperative: true},
+ {tag: "declarative", imperative: false}
+ ]
+ }
+
+ function test_timeout(data) {
var control = toolTip.createObject(testCase, {timeout: 100})
compare(control.visible, false)
- control.open()
+ if (data.imperative)
+ control.open()
+ else
+ control.visible = true
compare(control.visible, true)
tryCompare(control, "visible", false)
@@ -185,6 +200,55 @@ TestCase {
function test_warning() {
ignoreWarning(Qt.resolvedUrl("tst_tooltip.qml") + ":68:5: QML QtObject: ToolTip must be attached to an Item")
- object.ToolTip.text = ""
+ ignoreWarning("<Unknown File>:1:30: QML ToolTip: cannot find any window to open popup in.")
+ object.ToolTip.show("") // don't crash (QTBUG-56243)
+ }
+
+ Component {
+ id: toolTipWithExitTransition
+
+ ToolTip {
+ enter: Transition {
+ NumberAnimation { property: "opacity"; from: 0.0; to: 1.0; duration: 100 }
+ }
+ exit: Transition {
+ NumberAnimation { property: "opacity"; from: 1.0; to: 0.0; duration: 1000 }
+ }
+ }
+ }
+
+ function test_makeVisibleWhileExitTransitionRunning_data() {
+ return [
+ { tag: "imperative", imperative: true },
+ { tag: "declarative", imperative: false }
+ ]
+ }
+
+ function test_makeVisibleWhileExitTransitionRunning(data) {
+ var control = toolTipWithExitTransition.createObject(testCase)
+
+ // Show, hide, and show the tooltip again. Its exit transition should
+ // start and get cancelled, and then its enter transition should run.
+ if (data.imperative)
+ control.open()
+ else
+ control.visible = true
+ tryCompare(control, "opacity", 1)
+
+ if (data.imperative)
+ control.close()
+ else
+ control.visible = false
+ verify(control.exit.running)
+ wait(100) // TODO: replace with tryVerify() in 5.8
+ verify(control.opacity < 1)
+
+ if (data.imperative)
+ control.open()
+ else
+ control.visible = true
+ tryCompare(control, "opacity", 1)
+
+ control.destroy()
}
}
diff --git a/tests/auto/controls/data/tst_tumbler.qml b/tests/auto/controls/data/tst_tumbler.qml
index 6f1f0200..b3230ca4 100644
--- a/tests/auto/controls/data/tst_tumbler.qml
+++ b/tests/auto/controls/data/tst_tumbler.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -51,6 +51,9 @@ TestCase {
name: "Tumbler"
property var tumbler: null
+ // With the help of cleanup(), ensures that all items created during a test function
+ // are destroyed if that test fails.
+ property Item cleanupItem
readonly property real implicitTumblerWidth: 60
readonly property real implicitTumblerHeight: 200
readonly property real defaultImplicitDelegateHeight: implicitTumblerHeight / 3
@@ -66,20 +69,37 @@ TestCase {
}
}
+ Component {
+ id: itemComponent
+
+ Item {
+ anchors.fill: parent
+ }
+ }
+
function init() {
- createTumbler();
+ cleanupItem = itemComponent.createObject(testCase);
+ verify(cleanupItem);
}
function cleanup() {
- tumbler.destroy();
- tumblerView = null;
+ var destroyed = false;
+ cleanupItem.Component.destruction.connect(function() { destroyed = true; });
+
+ cleanupItem.destroy();
+
+ // Waiting until it's deleted before continuing makes debugging
+ // test failures much easier, because there aren't unrelated items hanging around.
+ // TODO: Replace with tryVerify(!tumbler) in 5.8.
+ while (!destroyed)
+ wait(0)
}
function createTumbler(args) {
if (args === undefined)
- tumbler = tumblerComponent.createObject(testCase);
+ tumbler = tumblerComponent.createObject(cleanupItem);
else
- tumbler = tumblerComponent.createObject(testCase, args);
+ tumbler = tumblerComponent.createObject(cleanupItem, args);
verify(tumbler, "Tumbler: failed to create an instance");
tumblerView = findView(tumbler);
verify(tumblerView);
@@ -128,6 +148,7 @@ TestCase {
}
function test_wrapWithoutAttachedProperties() {
+ createTumbler();
verify(tumbler.wrap);
tumbler.delegate = noAttachedPropertiesDelegate;
@@ -136,7 +157,14 @@ TestCase {
verify(findView(tumbler));
}
+ // TODO: test that currentIndex is maintained between contentItem changes...
+// function tst_dynamicContentItemChange() {
+// }
+
function test_currentIndex() {
+ createTumbler();
+ compare(tumbler.contentItem.parent, tumbler);
+
tumbler.model = 5;
compare(tumbler.currentIndex, 0);
@@ -256,7 +284,7 @@ TestCase {
function test_currentIndexAtCreation(data) {
// Test setting currentIndex at creation time
- var tumbler = data.component.createObject(testCase);
+ tumbler = data.component.createObject(cleanupItem);
verify(tumbler);
// A "statically declared" currentIndex will be pending until the count has changed,
// which happens when the model is set, which happens on the TumblerView's next polish.
@@ -279,11 +307,11 @@ TestCase {
} else {
fuzzyCompare(tumblerView.contentY, tumblerDelegateHeight * data.currentIndex - tumblerView.preferredHighlightBegin, fuzz);
}
-
- tumbler.destroy();
}
function test_keyboardNavigation() {
+ createTumbler();
+
tumbler.model = 5;
tumbler.forceActiveFocus();
tumblerView.highlightMoveDuration = 0;
@@ -312,6 +340,8 @@ TestCase {
}
function test_itemsCorrectlyPositioned() {
+ createTumbler();
+
tumbler.model = 4;
tumbler.height = 120;
compare(tumblerDelegateHeight, 40);
@@ -320,7 +350,7 @@ TestCase {
wait(tumblerView.highlightMoveDuration);
var firstItemCenterPos = itemCenterPos(1);
var firstItem = tumblerView.itemAt(firstItemCenterPos.x, firstItemCenterPos.y);
- var actualPos = testCase.mapFromItem(firstItem, 0, 0);
+ var actualPos = cleanupItem.mapFromItem(firstItem, 0, 0);
compare(actualPos.x, tumbler.leftPadding);
compare(actualPos.y, tumbler.topPadding + 40);
@@ -331,7 +361,7 @@ TestCase {
firstItem = tumblerView.itemAt(firstItemCenterPos.x, firstItemCenterPos.y);
verify(firstItem);
// Test QTBUG-40298.
- actualPos = testCase.mapFromItem(firstItem, 0, 0);
+ actualPos = cleanupItem.mapFromItem(firstItem, 0, 0);
compare(actualPos.x, tumbler.leftPadding);
compare(actualPos.y, tumbler.topPadding);
@@ -348,8 +378,11 @@ TestCase {
}
function test_focusPastTumbler() {
+ tumbler = tumblerComponent.createObject(cleanupItem);
+ verify(tumbler);
+
var mouseArea = Qt.createQmlObject(
- "import QtQuick 2.2; TextInput { activeFocusOnTab: true; width: 50; height: 50 }", testCase, "");
+ "import QtQuick 2.2; TextInput { activeFocusOnTab: true; width: 50; height: 50 }", cleanupItem, "");
tumbler.forceActiveFocus();
verify(tumbler.activeFocus);
@@ -357,16 +390,12 @@ TestCase {
keyClick(Qt.Key_Tab);
verify(!tumbler.activeFocus);
verify(mouseArea.activeFocus);
-
- mouseArea.destroy();
}
function test_datePicker() {
- tumbler.destroy();
-
var component = Qt.createComponent("TumblerDatePicker.qml");
compare(component.status, Component.Ready, component.errorString());
- tumbler = component.createObject(testCase);
+ tumbler = component.createObject(cleanupItem);
// Should not be any warnings.
tryCompare(tumbler.dayTumbler, "currentIndex", 0);
@@ -396,6 +425,44 @@ TestCase {
tryCompare(tumbler.dayTumbler, "currentIndex", 27);
}
+ Component {
+ id: timePickerComponent
+
+ Row {
+ property alias minuteTumbler: minuteTumbler
+ property alias amPmTumbler: amPmTumbler
+
+ Tumbler {
+ id: minuteTumbler
+ currentIndex: 6
+ model: 60
+ width: 50
+ height: 150
+ }
+
+ Tumbler {
+ id: amPmTumbler
+ model: ["AM", "PM"]
+ width: 50
+ height: 150
+ contentItem: ListView {
+ anchors.fill: parent
+ model: amPmTumbler.model
+ delegate: amPmTumbler.delegate
+ }
+ }
+ }
+ }
+
+ function test_listViewTimePicker() {
+ var root = timePickerComponent.createObject(cleanupItem);
+ verify(root);
+
+ mouseDrag(root.minuteTumbler, root.minuteTumbler.width / 2, root.minuteTumbler.height / 2, 0, 50);
+ // Shouldn't crash.
+ mouseDrag(root.amPmTumbler, root.amPmTumbler.width / 2, root.amPmTumbler.height / 2, 0, 50);
+ }
+
function test_displacement_data() {
var data = [
// At 0 offset, the first item is current.
@@ -451,6 +518,8 @@ TestCase {
}
function test_displacement(data) {
+ createTumbler();
+
// TODO: test setting these in the opposite order (delegate after model
// doesn't seem to cause a change in delegates in PathView)
tumbler.wrap = true;
@@ -468,6 +537,8 @@ TestCase {
}
function test_wrap() {
+ createTumbler();
+
tumbler.model = 5;
compare(tumbler.count, 5);
@@ -501,6 +572,9 @@ TestCase {
}
function test_countWrap() {
+ tumbler = tumblerComponent.createObject(cleanupItem);
+ verify(tumbler);
+
// Check that a count that is less than visibleItemCount results in wrap being set to false.
verify(2 < tumbler.visibleItemCount);
tumbler.model = 2;
@@ -510,7 +584,7 @@ TestCase {
function test_explicitlyNonwrapping() {
// Check that explicitly setting wrap to false works even when it was implicitly false.
- var explicitlyNonWrapping = twoItemTumbler.createObject(testCase);
+ var explicitlyNonWrapping = twoItemTumbler.createObject(cleanupItem);
verify(explicitlyNonWrapping);
tryCompare(explicitlyNonWrapping, "wrap", false);
@@ -523,13 +597,11 @@ TestCase {
// Test resetting wrap back to the default behavior.
explicitlyNonWrapping.wrap = undefined;
compare(explicitlyNonWrapping.wrap, true);
-
- explicitlyNonWrapping.destroy();
}
function test_explicitlyWrapping() {
// Check that explicitly setting wrap to true works even when it was implicitly true.
- var explicitlyWrapping = tenItemTumbler.createObject(testCase);
+ var explicitlyWrapping = tenItemTumbler.createObject(cleanupItem);
verify(explicitlyWrapping);
compare(explicitlyWrapping.wrap, true);
@@ -541,8 +613,6 @@ TestCase {
// Test resetting wrap back to the default behavior.
explicitlyWrapping.wrap = undefined;
compare(explicitlyWrapping.wrap, false);
-
- explicitlyWrapping.destroy();
}
Component {
@@ -603,7 +673,7 @@ TestCase {
}
function test_customContentItemAtConstruction(data) {
- var tumbler = data.component.createObject(testCase);
+ var tumbler = data.component.createObject(cleanupItem);
// Shouldn't assert.
tumbler.model = 5;
@@ -622,8 +692,6 @@ TestCase {
compare(tumbler.count, 5);
compare(tumblerView.currentIndex, 3);
compare(tumbler.currentIndex, 3);
-
- tumbler.destroy();
}
function test_customContentItemAfterConstruction_data() {
@@ -634,6 +702,8 @@ TestCase {
}
function test_customContentItemAfterConstruction(data) {
+ createTumbler();
+
tumbler.model = 5;
compare(tumbler.count, 5);
@@ -692,6 +762,8 @@ TestCase {
}
function test_displacementListView(data) {
+ createTumbler();
+
tumbler.wrap = false;
tumbler.delegate = displacementDelegate;
tumbler.model = 5;
@@ -761,6 +833,8 @@ TestCase {
}
function test_listViewFlickAboveBounds(data) {
+ createTumbler();
+
tumbler.wrap = false;
tumbler.delegate = displacementDelegate;
tumbler.model = data.model;
@@ -826,6 +900,8 @@ TestCase {
}
function test_visibleItemCount(data) {
+ createTumbler();
+
tumbler.delegate = objectNameDelegate;
tumbler.visibleItemCount = data.visibleItemCount;
@@ -851,6 +927,9 @@ TestCase {
}
function test_attachedProperties() {
+ tumbler = tumblerComponent.createObject(cleanupItem);
+ verify(tumbler);
+
// TODO: crashes somewhere in QML's guts
// tumbler.model = 5;
// tumbler.delegate = wrongDelegateTypeComponent;
@@ -862,8 +941,8 @@ TestCase {
noParentDelegateComponent.createObject(null);
ignoreWarning("Tumbler: attempting to access attached property on item without an \"index\" property");
- var object = noParentDelegateComponent.createObject(testCase);
- object.destroy();
+ var object = noParentDelegateComponent.createObject(cleanupItem);
+ verify(object);
}
property Component paddingDelegate: Text {
@@ -910,6 +989,8 @@ TestCase {
}
function test_padding(data) {
+ createTumbler();
+
tumbler.delegate = paddingDelegate;
tumbler.model = 5;
compare(tumbler.padding, 0);