diff options
Diffstat (limited to 'tests/auto')
55 files changed, 2201 insertions, 918 deletions
diff --git a/tests/auto/controls/data/TumblerListView.qml b/tests/auto/controls/data/TumblerListView.qml index 4ab2918b..87623f8c 100644 --- a/tests/auto/controls/data/TumblerListView.qml +++ b/tests/auto/controls/data/TumblerListView.qml @@ -48,6 +48,6 @@ ListView { snapMode: ListView.SnapToItem highlightRangeMode: ListView.StrictlyEnforceRange preferredHighlightBegin: height / 2 - (height / parent.visibleItemCount / 2) - preferredHighlightEnd: height / 2 + (height / parent.visibleItemCount / 2) + preferredHighlightEnd: height / 2 + (height / parent.visibleItemCount / 2) clip: true } diff --git a/tests/auto/controls/data/tst_abstractbutton.qml b/tests/auto/controls/data/tst_abstractbutton.qml index b785b7a1..33ee5846 100644 --- a/tests/auto/controls/data/tst_abstractbutton.qml +++ b/tests/auto/controls/data/tst_abstractbutton.qml @@ -66,7 +66,7 @@ TestCase { } function test_text() { - var control = button.createObject(testCase); + var control = createTemporaryObject(button, testCase); verify(control); compare(control.text, ""); @@ -74,21 +74,18 @@ TestCase { compare(control.text, "Button"); control.text = ""; compare(control.text, ""); - - control.destroy(); } function test_baseline() { - var control = button.createObject(testCase, {padding: 6}) + var control = createTemporaryObject(button, 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) + var control = createTemporaryObject(button, testCase) verify(control) compare(control.implicitWidth, 0) @@ -105,12 +102,10 @@ TestCase { control.padding = 100 compare(control.implicitWidth, 210) compare(control.implicitHeight, 220) - - control.destroy() } function test_pressAndHold() { - var control = button.createObject(testCase, {checkable: true}) + var control = createTemporaryObject(button, testCase, {checkable: true}) verify(control) var pressAndHoldSpy = signalSpy.createObject(control, {target: control, signalName: "pressAndHold"}) @@ -122,7 +117,5 @@ TestCase { mouseRelease(control) compare(control.checked, false) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_busyindicator.qml b/tests/auto/controls/data/tst_busyindicator.qml index 284554d4..f142f551 100644 --- a/tests/auto/controls/data/tst_busyindicator.qml +++ b/tests/auto/controls/data/tst_busyindicator.qml @@ -56,13 +56,11 @@ TestCase { } function test_running() { - var control = busyIndicator.createObject(testCase) + var control = createTemporaryObject(busyIndicator, testCase) verify(control) compare(control.running, true) control.running = false compare(control.running, false) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_button.qml b/tests/auto/controls/data/tst_button.qml index 699f0e1e..c7e2d650 100644 --- a/tests/auto/controls/data/tst_button.qml +++ b/tests/auto/controls/data/tst_button.qml @@ -58,7 +58,7 @@ TestCase { Component { id: signalSequenceSpy SignalSequenceSpy { - signals: ["pressed", "released", "canceled", "clicked", "doubleClicked", "pressedChanged", "downChanged", "checkedChanged"] + signals: ["pressed", "released", "canceled", "clicked", "toggled", "doubleClicked", "pressedChanged", "downChanged", "checkedChanged"] } } @@ -68,7 +68,7 @@ TestCase { } function test_text() { - var control = button.createObject(testCase) + var control = createTemporaryObject(button, testCase) verify(control) compare(control.text, "") @@ -76,12 +76,10 @@ TestCase { compare(control.text, "Button") control.text = "" compare(control.text, "") - - control.destroy() } function test_mouse() { - var control = button.createObject(testCase) + var control = createTemporaryObject(button, testCase) verify(control) var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) @@ -148,12 +146,10 @@ TestCase { "clicked"] mouseDoubleClickSequence(control, control.width / 2, control.height / 2, Qt.LeftButton) verify(sequenceSpy.success) - - control.destroy() } function test_keys() { - var control = button.createObject(testCase) + var control = createTemporaryObject(button, testCase) verify(control) control.forceActiveFocus() @@ -180,8 +176,6 @@ TestCase { keyClick(keys[i]) verify(sequenceSpy.success) } - - control.destroy() } function eventErrorMessage(actual, expected) { @@ -189,7 +183,7 @@ TestCase { } function test_autoRepeat() { - var control = button.createObject(testCase) + var control = createTemporaryObject(button, testCase) verify(control) compare(control.autoRepeat, false) @@ -270,19 +264,16 @@ TestCase { compare(clickSpy.count, 0) compare(pressSpy.count, 0) compare(releaseSpy.count, 0) - - control.destroy() } function test_baseline() { - var control = button.createObject(testCase) + var control = createTemporaryObject(button, testCase) verify(control) compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) - control.destroy() } function test_checkable() { - var control = button.createObject(testCase) + var control = createTemporaryObject(button, testCase) verify(control) verify(control.hasOwnProperty("checkable")) verify(!control.checkable) @@ -306,6 +297,7 @@ TestCase { ["pressedChanged", { "pressed": false }], ["downChanged", { "down": false }], ["checkedChanged", { "checked": true }], + "toggled", "released", "clicked"] control.checkable = true @@ -319,23 +311,20 @@ TestCase { ["pressedChanged", { "pressed": false }], ["downChanged", { "down": false }], ["checkedChanged", { "checked": false }], + "toggled", "released", "clicked"] mouseClick(control) verify(!control.checked) verify(sequenceSpy.success) - - control.destroy() } function test_highlighted() { - var control = button.createObject(testCase) + var control = createTemporaryObject(button, testCase) verify(control) verify(!control.highlighted) control.highlighted = true verify(control.highlighted) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_buttongroup.qml b/tests/auto/controls/data/tst_buttongroup.qml index 7d97614e..8ffdf74e 100644 --- a/tests/auto/controls/data/tst_buttongroup.qml +++ b/tests/auto/controls/data/tst_buttongroup.qml @@ -61,13 +61,11 @@ TestCase { } function test_null() { - var group = buttonGroup.createObject(testCase) + var group = createTemporaryObject(buttonGroup, testCase) verify(group) group.addButton(null) group.removeButton(null) - - group.destroy() } Component { @@ -81,16 +79,16 @@ TestCase { } function test_current() { - var group = buttonGroup.createObject(testCase) + var group = createTemporaryObject(buttonGroup, testCase) verify(group) - var checkedButtonSpy = signalSpy.createObject(testCase, {target: group, signalName: "checkedButtonChanged"}) + var checkedButtonSpy = createTemporaryObject(signalSpy, testCase, {target: group, signalName: "checkedButtonChanged"}) verify(checkedButtonSpy.valid) verify(!group.checkedButton) - var button1 = button.createObject(testCase, {checked: true}) - var button2 = button.createObject(testCase, {checked: false}) - var button3 = button.createObject(testCase, {checked: true, objectName: "3"}) + var button1 = createTemporaryObject(button, testCase, {checked: true}) + var button2 = createTemporaryObject(button, testCase, {checked: false}) + var button3 = createTemporaryObject(button, testCase, {checked: true, objectName: "3"}) // add checked group.addButton(button1) @@ -147,22 +145,20 @@ TestCase { compare(button2.checked, false) compare(button3.checked, false) compare(checkedButtonSpy.count, 5) - - group.destroy() } function test_buttons() { - var group = buttonGroup.createObject(testCase) + var group = createTemporaryObject(buttonGroup, testCase) verify(group) - var buttonsSpy = signalSpy.createObject(testCase, {target: group, signalName: "buttonsChanged"}) + var buttonsSpy = createTemporaryObject(signalSpy, testCase, {target: group, signalName: "buttonsChanged"}) verify(buttonsSpy.valid) compare(group.buttons.length, 0) compare(group.checkedButton, null) - var button1 = button.createObject(testCase, {checked: true}) - var button2 = button.createObject(testCase, {checked: false}) + var button1 = createTemporaryObject(button, testCase, {checked: true}) + var button2 = createTemporaryObject(button, testCase, {checked: false}) group.buttons = [button1, button2] compare(group.buttons.length, 2) @@ -171,7 +167,7 @@ TestCase { compare(group.checkedButton, button1) compare(buttonsSpy.count, 2) - var button3 = button.createObject(testCase, {checked: true}) + var button3 = createTemporaryObject(button, testCase, {checked: true}) group.addButton(button3) compare(group.buttons.length, 3) @@ -192,19 +188,17 @@ TestCase { compare(group.buttons.length, 0) tryCompare(group, "checkedButton", null) compare(buttonsSpy.count, 5) - - group.destroy() } function test_clicked() { - var group = buttonGroup.createObject(testCase) + var group = createTemporaryObject(buttonGroup, testCase) verify(group) - var clickedSpy = signalSpy.createObject(testCase, {target: group, signalName: "clicked"}) + var clickedSpy = createTemporaryObject(signalSpy, testCase, {target: group, signalName: "clicked"}) verify(clickedSpy.valid) - var button1 = button.createObject(testCase) - var button2 = button.createObject(testCase) + var button1 = createTemporaryObject(button, testCase) + var button2 = createTemporaryObject(button, testCase) group.addButton(button1) group.addButton(button2) @@ -216,10 +210,6 @@ TestCase { button2.clicked() compare(clickedSpy.count, 2) compare(clickedSpy.signalArguments[1][0], button2) - - group.destroy() - button1.destroy() - button2.destroy() } Component { @@ -276,7 +266,7 @@ TestCase { } function test_controls(data) { - var container = data.component.createObject(testCase) + var container = createTemporaryObject(data.component, testCase) verify(container) verify(!container.group.checkedButton) @@ -298,18 +288,16 @@ TestCase { compare(container.control1.checked, false) compare(container.control2.checked, false) compare(container.control3.checked, true) - - container.destroy() } function test_buttonDestroyed() { - var group = buttonGroup.createObject(testCase) + var group = createTemporaryObject(buttonGroup, testCase) verify(group) - var buttonsSpy = signalSpy.createObject(testCase, {target: group, signalName: "buttonsChanged"}) + var buttonsSpy = createTemporaryObject(signalSpy, testCase, {target: group, signalName: "buttonsChanged"}) verify(buttonsSpy.valid) - var button1 = button.createObject(testCase, {objectName: "button1", checked: true}) + var button1 = createTemporaryObject(button, testCase, {objectName: "button1", checked: true}) group.addButton(button1) compare(group.buttons.length, 1) @@ -322,8 +310,6 @@ TestCase { compare(group.buttons.length, 0) compare(group.checkedButton, null) compare(buttonsSpy.count, 2) - - group.destroy() } Component { @@ -344,12 +330,10 @@ TestCase { } function test_repeater() { - var container = repeater.createObject(testCase) + var container = createTemporaryObject(repeater, testCase) verify(container) verify(container.group.checkedButton) compare(container.group.checkedButton.objectName, "0") - - container.destroy() } } diff --git a/tests/auto/controls/data/tst_checkbox.qml b/tests/auto/controls/data/tst_checkbox.qml index b93a8a21..2ed29aec 100644 --- a/tests/auto/controls/data/tst_checkbox.qml +++ b/tests/auto/controls/data/tst_checkbox.qml @@ -40,7 +40,7 @@ import QtQuick 2.2 import QtTest 1.0 -import QtQuick.Controls 2.1 +import QtQuick.Controls 2.2 TestCase { id: testCase @@ -58,12 +58,12 @@ TestCase { Component { id: signalSequenceSpy SignalSequenceSpy { - signals: ["pressed", "released", "canceled", "clicked", "pressedChanged", "checkedChanged", "checkStateChanged"] + signals: ["pressed", "released", "canceled", "clicked", "toggled", "pressedChanged", "checkedChanged", "checkStateChanged"] } } function test_text() { - var control = checkBox.createObject(testCase) + var control = createTemporaryObject(checkBox, testCase) verify(control) compare(control.text, "") @@ -71,12 +71,10 @@ TestCase { compare(control.text, "CheckBox") control.text = "" compare(control.text, "") - - control.destroy() } function test_checked() { - var control = checkBox.createObject(testCase) + var control = createTemporaryObject(checkBox, testCase) verify(control) var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) @@ -99,12 +97,10 @@ TestCase { compare(control.checked, false) compare(control.checkState, Qt.Unchecked) verify(sequenceSpy.success) - - control.destroy() } function test_checkState() { - var control = checkBox.createObject(testCase) + var control = createTemporaryObject(checkBox, testCase) verify(control) var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) @@ -127,12 +123,10 @@ TestCase { compare(control.checked, false) compare(control.checkState, Qt.Unchecked) verify(sequenceSpy.success) - - control.destroy() } function test_mouse() { - var control = checkBox.createObject(testCase) + var control = createTemporaryObject(checkBox, testCase) verify(control) var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) @@ -147,6 +141,7 @@ TestCase { sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": false, "checkState": Qt.Unchecked }], ["checkStateChanged", { "pressed": false, "checked": true, "checkState": Qt.Checked }], ["checkedChanged", { "pressed": false, "checked": true, "checkState": Qt.Checked }], + "toggled", "released", "clicked"] mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton) @@ -164,6 +159,7 @@ TestCase { sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": true, "checkState": Qt.Checked }], ["checkStateChanged", { "pressed": false, "checked": false, "checkState": Qt.Unchecked }], ["checkedChanged", { "pressed": false, "checked": false, "checkState": Qt.Unchecked }], + "toggled", "released", "clicked"] mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton) @@ -198,12 +194,10 @@ TestCase { compare(control.checkState, Qt.Unchecked) compare(control.pressed, false) verify(sequenceSpy.success) - - control.destroy() } function test_keys() { - var control = checkBox.createObject(testCase) + var control = createTemporaryObject(checkBox, testCase) verify(control) var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) @@ -219,6 +213,7 @@ TestCase { ["pressedChanged", { "pressed": false, "checked": false, "checkState": Qt.Unchecked }], ["checkStateChanged", { "pressed": false, "checked": true, "checkState": Qt.Checked }], ["checkedChanged", { "pressed": false, "checked": true, "checkState": Qt.Checked }], + "toggled", "released", "clicked"] keyClick(Qt.Key_Space) @@ -232,6 +227,7 @@ TestCase { ["pressedChanged", { "pressed": false, "checked": true, "checkState": Qt.Checked }], ["checkStateChanged", { "pressed": false, "checked": false, "checkState": Qt.Unchecked }], ["checkedChanged", { "pressed": false, "checked": false, "checkState": Qt.Unchecked }], + "toggled", "released", "clicked"] keyClick(Qt.Key_Space) @@ -248,8 +244,6 @@ TestCase { compare(control.checked, false) verify(sequenceSpy.success) } - - control.destroy() } Component { @@ -261,7 +255,7 @@ TestCase { } function test_checked_binding() { - var container = checkedBoundBoxes.createObject(testCase) + var container = createTemporaryObject(checkedBoundBoxes, testCase) verify(container) compare(container.cb1.checked, false) @@ -280,8 +274,6 @@ TestCase { compare(container.cb1.checkState, Qt.Unchecked) compare(container.cb2.checked, false) compare(container.cb2.checkState, Qt.Unchecked) - - container.destroy() } Component { @@ -293,7 +285,7 @@ TestCase { } function test_checkState_binding() { - var container = checkStateBoundBoxes.createObject(testCase) + var container = createTemporaryObject(checkStateBoundBoxes, testCase) verify(container) compare(container.cb1.checked, false) @@ -324,12 +316,10 @@ TestCase { compare(container.cb1.tristate, true) compare(container.cb2.tristate, true) - - container.destroy() } function test_tristate() { - var control = checkBox.createObject(testCase) + var control = createTemporaryObject(checkBox, testCase) var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) @@ -424,14 +414,11 @@ TestCase { compare(control.checked, true) compare(control.checkState, Qt.PartiallyChecked) verify(sequenceSpy.success) - - control.destroy() } function test_baseline() { - var control = checkBox.createObject(testCase) + var control = createTemporaryObject(checkBox, testCase) verify(control) compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) - control.destroy() } } diff --git a/tests/auto/controls/data/tst_checkdelegate.qml b/tests/auto/controls/data/tst_checkdelegate.qml index b014f696..a838702c 100644 --- a/tests/auto/controls/data/tst_checkdelegate.qml +++ b/tests/auto/controls/data/tst_checkdelegate.qml @@ -58,14 +58,13 @@ TestCase { // TODO: data-fy tst_checkbox (rename to tst_check?) so we don't duplicate its tests here? function test_defaults() { - var control = checkDelegate.createObject(testCase); + var control = createTemporaryObject(checkDelegate, testCase); verify(control); verify(!control.checked); - control.destroy(); } function test_checked() { - var control = checkDelegate.createObject(testCase); + var control = createTemporaryObject(checkDelegate, testCase); verify(control); mouseClick(control); @@ -73,14 +72,11 @@ TestCase { mouseClick(control); verify(!control.checked); - - control.destroy(); } function test_baseline() { - var control = checkDelegate.createObject(testCase); + var control = createTemporaryObject(checkDelegate, testCase); verify(control); compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset); - control.destroy(); } } diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml index 0cd2e258..4bcbd8b4 100644 --- a/tests/auto/controls/data/tst_combobox.qml +++ b/tests/auto/controls/data/tst_combobox.qml @@ -65,7 +65,7 @@ TestCase { id: emptyBox ComboBox { delegate: ItemDelegate { - width: popup.width + width: parent.width } } } @@ -713,6 +713,74 @@ TestCase { control.destroy() } + function test_down() { + var control = comboBox.createObject(testCase, {model: 3}) + verify(control) + + // some styles position the popup over the combo button. move it out + // of the way to avoid stealing mouse presses. we want to test the + // combinations of the button being pressed and the popup being visible. + control.popup.y = control.height + + var downSpy = signalSpy.createObject(control, {target: control, signalName: "downChanged"}) + verify(downSpy.valid) + + var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) + verify(pressedSpy.valid) + + mousePress(control) + compare(control.popup.visible, false) + compare(control.pressed, true) + compare(control.down, true) + compare(downSpy.count, 1) + compare(pressedSpy.count, 1) + + mouseRelease(control) + compare(control.popup.visible, true) + compare(control.pressed, false) + compare(control.down, true) + compare(downSpy.count, 3) + compare(pressedSpy.count, 2) + + control.down = false + compare(control.down, false) + compare(downSpy.count, 4) + + mousePress(control) + compare(control.popup.visible, true) + compare(control.pressed, true) + compare(control.down, false) // explicit false + compare(downSpy.count, 4) + compare(pressedSpy.count, 3) + + control.down = undefined + compare(control.down, true) + compare(downSpy.count, 5) + + mouseRelease(control) + tryCompare(control.popup, "visible", false) + compare(control.pressed, false) + compare(control.down, false) + compare(downSpy.count, 6) + compare(pressedSpy.count, 4) + + control.popup.open() + compare(control.popup.visible, true) + compare(control.pressed, false) + compare(control.down, true) + compare(downSpy.count, 7) + compare(pressedSpy.count, 4) + + control.popup.close() + tryCompare(control.popup, "visible", false) + compare(control.pressed, false) + compare(control.down, false) + compare(downSpy.count, 8) + compare(pressedSpy.count, 4) + + control.destroy() + } + function test_focus() { var control = comboBox.createObject(testCase, {model: 3}) verify(control) @@ -1045,4 +1113,302 @@ TestCase { closedSpy.target = null control.destroy() } + + RegExpValidator { + id: regExpValidator + regExp: /(red|blue|green)?/ + } + + function test_validator() { + var control = comboBox.createObject(testCase, {editable: true, validator: regExpValidator}) + + control.editText = "blu" + compare(control.acceptableInput, false) + control.editText = "blue" + compare(control.acceptableInput, true) + control.editText = "bluee" + compare(control.acceptableInput, false) + control.editText = "" + compare(control.acceptableInput, true) + control.editText = "" + control.forceActiveFocus() + keyPress(Qt.Key_A) + compare(control.editText, "") + keyPress(Qt.Key_A) + compare(control.editText, "") + keyPress(Qt.Key_R) + compare(control.editText, "r") + keyPress(Qt.Key_A) + compare(control.editText, "r") + compare(control.acceptableInput, false) + keyPress(Qt.Key_E) + compare(control.editText, "re") + compare(control.acceptableInput, false) + keyPress(Qt.Key_D) + compare(control.editText, "red") + compare(control.acceptableInput, true) + + control.destroy() + } + + Component { + id: appendFindBox + ComboBox { + editable: true + model: ListModel { + ListElement { text:"first" } + } + onAccepted: { + if (find(editText) === -1) + model.append({text: editText}) + } + } + } + + function test_append_find() { + var control = appendFindBox.createObject(testCase) + + compare(control.currentIndex, 0) + compare(control.currentText, "first") + control.forceActiveFocus() + compare(control.activeFocus, true) + + control.selectAll() + keyPress(Qt.Key_T) + keyPress(Qt.Key_H) + keyPress(Qt.Key_I) + keyPress(Qt.Key_R) + keyPress(Qt.Key_D) + compare(control.count, 1) + compare(control.currentText, "first") + compare(control.editText, "third") + + keyPress(Qt.Key_Enter) + compare(control.count, 2) + compare(control.currentIndex, 1) + compare(control.currentText, "third") + + control.destroy() + } + + function test_editable() { + var control = comboBox.createObject(testCase, {editable: true, model: ["Banana", "Coco", "Coconut", "Apple", "Cocomuffin"]}) + verify(control) + + control.forceActiveFocus() + verify(control.activeFocus) + + var acceptCount = 0 + + var acceptSpy = signalSpy.createObject(control, {target: control, signalName: "accepted"}) + verify(acceptSpy.valid) + + compare(control.editText, "Banana") + compare(control.currentText, "Banana") + compare(control.currentIndex, 0) + compare(acceptSpy.count, 0) + control.editText = "" + + keyPress(Qt.Key_C) + compare(control.editText, "coco") + compare(control.currentText, "Banana") + compare(control.currentIndex, 0) + + keyPress(Qt.Key_Right) + keyPress(Qt.Key_N) + compare(control.editText, "coconut") + compare(control.currentText, "Banana") + compare(control.currentIndex, 0) + + keyPress(Qt.Key_Enter) // Accept + compare(control.editText, "Coconut") + compare(control.currentText, "Coconut") + compare(control.currentIndex, 2) + compare(acceptSpy.count, ++acceptCount) + + keyPress(Qt.Key_Backspace) + keyPress(Qt.Key_Backspace) + keyPress(Qt.Key_Backspace) + keyPress(Qt.Key_M) + compare(control.editText, "Cocomuffin") + compare(control.currentText, "Coconut") + compare(control.currentIndex, 2) + + keyPress(Qt.Key_Enter) // Accept + compare(control.editText, "Cocomuffin") + compare(control.currentText, "Cocomuffin") + compare(control.currentIndex, 4) + compare(acceptSpy.count, ++acceptCount) + + keyPress(Qt.Key_Return) // Accept + compare(control.editText, "Cocomuffin") + compare(control.currentText, "Cocomuffin") + compare(control.currentIndex, 4) + compare(acceptSpy.count, ++acceptCount) + + control.editText = "" + compare(control.editText, "") + compare(control.currentText, "Cocomuffin") + compare(control.currentIndex, 4) + + keyPress(Qt.Key_A) + compare(control.editText, "apple") + compare(control.currentText, "Cocomuffin") + compare(control.currentIndex, 4) + + keyPress(Qt.Key_Return) // Accept + compare(control.editText, "Apple") + compare(control.currentText, "Apple") + compare(control.currentIndex, 3) + compare(acceptSpy.count, ++acceptCount) + + control.editText = "" + keyPress(Qt.Key_A) + keyPress(Qt.Key_B) + compare(control.editText, "ab") + compare(control.currentText, "Apple") + compare(control.currentIndex, 3) + + keyPress(Qt.Key_Return) // Accept + compare(control.editText, "ab") + compare(control.currentText, "") + compare(control.currentIndex, -1) + compare(acceptSpy.count, ++acceptCount) + + control.editText = "" + compare(control.editText, "") + compare(control.currentText, "") + compare(control.currentIndex, -1) + + keyPress(Qt.Key_C) + keyPress(Qt.Key_Return) // Accept + compare(control.editText, "Coco") + compare(control.currentText, "Coco") + compare(control.currentIndex, 1) + compare(acceptSpy.count, ++acceptCount) + + keyPress(Qt.Key_Down) + compare(control.editText, "Coconut") + compare(control.currentText, "Coconut") + compare(control.currentIndex, 2) + + keyPress(Qt.Key_Up) + compare(control.editText, "Coco") + compare(control.currentText, "Coco") + compare(control.currentIndex, 1) + + control.editText = "" + compare(control.editText, "") + compare(control.currentText, "Coco") + compare(control.currentIndex, 1) + + keyPress(Qt.Key_C) + keyPress(Qt.Key_O) + keyPress(Qt.Key_C) // autocompletes "coco" + keyPress(Qt.Key_Backspace) + keyPress(Qt.Key_Return) // Accept "coc" + compare(control.editText, "coc") + compare(control.currentText, "") + compare(control.currentIndex, -1) + compare(acceptSpy.count, ++acceptCount) + + control.editText = "" + compare(control.editText, "") + compare(control.currentText, "") + compare(control.currentIndex, -1) + + keyPress(Qt.Key_C) + keyPress(Qt.Key_O) + keyPress(Qt.Key_C) // autocompletes "coc" + keyPress(Qt.Key_Space) + keyPress(Qt.Key_Return) // Accept "coc " + compare(control.editText, "coc ") + compare(control.currentText, "") + compare(control.currentIndex, -1) + compare(acceptSpy.count, ++acceptCount) + + control.destroy() + } + + Component { + id: keysAttachedBox + ComboBox { + editable: true + property bool gotit: false + Keys.onPressed: { + if (!gotit && event.key === Qt.Key_B) { + gotit = true + event.accepted = true + } + } + } + } + + function test_keys_attached() { + var control = keysAttachedBox.createObject(testCase) + verify(control) + + control.forceActiveFocus() + verify(control.activeFocus) + + verify(!control.gotit) + compare(control.editText, "") + + keyPress(Qt.Key_A) + verify(control.activeFocus) + verify(!control.gotit) + compare(control.editText, "a") + + keyPress(Qt.Key_B) + verify(control.activeFocus) + expectFail("", "An editable ComboBox does not yet support the Keys attached property.") + verify(control.gotit) + compare(control.editText, "a") + + keyPress(Qt.Key_B) + verify(control.activeFocus) + verify(control.gotit) + compare(control.editText, "ab") + + control.destroy() + } + + function test_minusOneIndexResetsSelection_QTBUG_35794_data() { + return [ + { tag: "editable", editable: true }, + { tag: "non-editable", editable: false } + ] + } + + function test_minusOneIndexResetsSelection_QTBUG_35794(data) { + var control = comboBox.createObject(testCase, {editable: data.editable, model: ["A", "B", "C"]}) + verify(control) + + compare(control.currentIndex, 0) + compare(control.currentText, "A") + control.currentIndex = -1 + compare(control.currentIndex, -1) + compare(control.currentText, "") + control.currentIndex = 1 + compare(control.currentIndex, 1) + compare(control.currentText, "B") + + control.destroy() + } + + function test_minusOneToZeroSelection_QTBUG_38036() { + var control = comboBox.createObject(testCase, {model: ["A", "B", "C"]}) + verify(control) + + compare(control.currentIndex, 0) + compare(control.currentText, "A") + control.currentIndex = -1 + compare(control.currentIndex, -1) + compare(control.currentText, "") + control.currentIndex = 0 + compare(control.currentIndex, 0) + compare(control.currentText, "A") + + control.destroy() + } } diff --git a/tests/auto/controls/data/tst_container.qml b/tests/auto/controls/data/tst_container.qml index bf6ec283..da77def2 100644 --- a/tests/auto/controls/data/tst_container.qml +++ b/tests/auto/controls/data/tst_container.qml @@ -62,7 +62,7 @@ TestCase { } function test_implicitSize() { - var control = container.createObject(testCase) + var control = createTemporaryObject(container, testCase) verify(control) compare(control.implicitWidth, 0) @@ -79,7 +79,5 @@ TestCase { control.padding = 100 compare(control.implicitWidth, 210) compare(control.implicitHeight, 220) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_control.qml b/tests/auto/controls/data/tst_control.qml index 9e41af7e..33802817 100644 --- a/tests/auto/controls/data/tst_control.qml +++ b/tests/auto/controls/data/tst_control.qml @@ -72,7 +72,7 @@ TestCase { } function test_padding() { - var control = component.createObject(testCase) + var control = createTemporaryObject(component, testCase) verify(control) compare(control.padding, 0) @@ -127,12 +127,10 @@ TestCase { compare(control.leftPadding, 30) compare(control.rightPadding, 40) compare(control.bottomPadding, 50) - - control.destroy() } function test_availableSize() { - var control = component.createObject(testCase) + var control = createTemporaryObject(component, testCase) verify(control) var availableWidthSpy = signalSpy.createObject(control, {target: control, signalName: "availableWidthChanged"}) @@ -199,12 +197,10 @@ TestCase { compare(control.availableHeight, 0) compare(availableWidthSpy.count, availableWidthChanges) compare(availableHeightSpy.count, ++availableHeightChanges) - - control.destroy() } function test_mirrored() { - var control = component.createObject(testCase) + var control = createTemporaryObject(component, testCase) verify(control) var mirroredSpy = signalSpy.createObject(control, {target: control, signalName: "mirroredChanged"}) @@ -230,12 +226,10 @@ TestCase { control.LayoutMirroring.enabled = false compare(control.mirrored, false) compare(mirroredSpy.count, 2) - - control.destroy() } function test_background() { - var control = component.createObject(testCase) + var control = createTemporaryObject(component, testCase) verify(control) control.background = component.createObject(control) @@ -277,8 +271,6 @@ TestCase { control.background.y = 10 control.height -= 20 verify(control.background.height !== control.height) - - control.destroy() } Component { @@ -319,7 +311,7 @@ TestCase { } function test_font() { - var control2 = component2.createObject(testCase) + var control2 = createTemporaryObject(component2, testCase) verify(control2) verify(control2.item2_2) verify(control2.item2_3) @@ -412,8 +404,6 @@ TestCase { compare(control2.item2_6.font.family, "Arial") compare(control2.item2_6.font.pointSize, 36) compare(control2.item2_6.font.weight, Font.Black) - - control2.destroy() } Component { @@ -464,7 +454,7 @@ TestCase { } function test_font_2() { - var control3 = component3.createObject(testCase) + var control3 = createTemporaryObject(component3, testCase) verify(control3) verify(control3.item3_2) verify(control3.item3_3) @@ -551,8 +541,6 @@ TestCase { compare(control3.item3_8.font.family, "Arial") compare(control3.item3_8.font.pointSize, 36) compare(control3.item3_8.font.weight, Font.Black) - - control3.destroy() } Component { @@ -581,7 +569,7 @@ TestCase { } function test_font_3() { - var control4 = component4.createObject(testCase) + var control4 = createTemporaryObject(component4, testCase) verify(control4) verify(control4.item4_2) verify(control4.item4_3) @@ -602,8 +590,6 @@ TestCase { compare(control4.item4_2.font.pixelSize, control4.font.pixelSize + 15) compare(control4.item4_3.font.pixelSize, control4.font.pixelSize - 1) compare(control4.item4_4.font.pixelSize, control4.font.pixelSize + 15) - - control4.destroy() } function test_font_explicit_attributes_data() { @@ -620,7 +606,7 @@ TestCase { } function test_font_explicit_attributes(data) { - var control = component.createObject(testCase) + var control = createTemporaryObject(component, testCase) verify(control) var child = component.createObject(control) @@ -645,12 +631,10 @@ TestCase { compare(child.font[data.tag], defaultValue) compare(childSpy.count, 0) - - control.destroy() } function test_locale() { - var control = component.createObject(testCase) + var control = createTemporaryObject(component, testCase) verify(control) control.locale = Qt.locale("en_US") @@ -658,8 +642,6 @@ TestCase { control.locale = Qt.locale("nb_NO") compare(control.locale.name, "nb_NO") - - control.destroy() } Component { @@ -723,7 +705,7 @@ TestCase { } function test_locale_2() { - var control = component5.createObject(testCase) + var control = createTemporaryObject(component5, testCase) verify(control) verify(control.item2_2) verify(control.item2_3) @@ -816,7 +798,7 @@ TestCase { } function test_locale_3() { - var control = component6.createObject(testCase) + var control = createTemporaryObject(component6, testCase) verify(control) verify(control.item6_2) verify(control.item6_3) @@ -855,7 +837,7 @@ TestCase { } function test_hover(data) { - var control = data.target.createObject(testCase, {width: 100, height: 100}) + var control = createTemporaryObject(data.target, testCase, {width: 100, height: 100}) verify(control) compare(control.hovered, false) @@ -889,12 +871,10 @@ TestCase { control.visible = false compare(control.hovered, false) - - control.destroy() } function test_hoverEnabled() { - var control = component.createObject(testCase) + var control = createTemporaryObject(component, testCase) compare(control.hoverEnabled, Qt.styleHints.useHoverEffects) var child = component.createObject(control) @@ -925,12 +905,10 @@ TestCase { compare(childExplicitHoverDisabled.hoverEnabled, false) compare(grandChildExplicitHoverEnabled.hoverEnabled, true) - - control.destroy() } function test_implicitSize() { - var control = component.createObject(testCase) + var control = createTemporaryObject(component, testCase) verify(control) compare(control.implicitWidth, 0) @@ -947,7 +925,5 @@ TestCase { control.padding = 100 compare(control.implicitWidth, 210) compare(control.implicitHeight, 220) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_delaybutton.qml b/tests/auto/controls/data/tst_delaybutton.qml new file mode 100644 index 00000000..d5c9bd0c --- /dev/null +++ b/tests/auto/controls/data/tst_delaybutton.qml @@ -0,0 +1,248 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import QtQuick.Controls 2.2 + +TestCase { + id: testCase + width: 200 + height: 200 + visible: true + when: windowShown + name: "DelayButton" + + Component { + id: delayButton + DelayButton { + delay: 200 + } + } + + Component { + id: signalSequenceSpy + SignalSequenceSpy { + signals: ["pressed", "released", "canceled", "clicked", "toggled", "doubleClicked", "pressedChanged", "downChanged", "checkedChanged", "activated"] + } + } + + Component { + id: signalSpy + SignalSpy { } + } + + function test_mouse() { + var control = createTemporaryObject(delayButton, testCase) + verify(control) + + var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) + + // click + sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true }], + ["downChanged", { "down": true }], + "pressed", + ["pressedChanged", { "pressed": false }], + ["downChanged", { "down": false }], + "released", + "clicked"] + mouseClick(control) + verify(sequenceSpy.success) + + // check + sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true }], + ["downChanged", { "down": true }], + "pressed", + "activated"] + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(control.pressed, true) + tryVerify(function() { return sequenceSpy.success}) + + sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": false }], + ["downChanged", { "down": false }], + ["checkedChanged", { "checked": true }], + "released", + "clicked"] + mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(control.pressed, false) + verify(sequenceSpy.success) + + // uncheck + sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true }], + ["downChanged", { "down": true }], + "pressed"] + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(control.pressed, true) + verify(sequenceSpy.success) + + sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": false }], + ["downChanged", { "down": false }], + ["checkedChanged", { "checked": false }], + "released", + "clicked"] + mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(control.pressed, false) + verify(sequenceSpy.success) + + // release outside + sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true }], + ["downChanged", { "down": true }], + "pressed"] + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(control.pressed, true) + verify(sequenceSpy.success) + + sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": false }], + ["downChanged", { "down": false }]] + mouseMove(control, control.width * 2, control.height * 2, 0, Qt.LeftButton) + compare(control.pressed, false) + verify(sequenceSpy.success) + + sequenceSpy.expectedSequence = [["canceled", { "pressed": false }]] + mouseRelease(control, control.width * 2, control.height * 2, Qt.LeftButton) + compare(control.pressed, false) + verify(sequenceSpy.success) + + // right button + sequenceSpy.expectedSequence = [] + mousePress(control, control.width / 2, control.height / 2, Qt.RightButton) + compare(control.pressed, false) + + mouseRelease(control, control.width / 2, control.height / 2, Qt.RightButton) + compare(control.pressed, false) + verify(sequenceSpy.success) + + // double click + sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true }], + ["downChanged", { "down": true }], + "pressed", + ["pressedChanged", { "pressed": false }], + ["downChanged", { "down": false }], + "released", + "clicked", + ["pressedChanged", { "pressed": true }], + ["downChanged", { "down": true }], + "pressed", + "doubleClicked", + ["pressedChanged", { "pressed": false }], + ["downChanged", { "down": false }], + "released", + "clicked"] + mouseDoubleClickSequence(control, control.width / 2, control.height / 2, Qt.LeftButton) + verify(sequenceSpy.success) + } + + function test_keys() { + var control = createTemporaryObject(delayButton, testCase) + verify(control) + + control.forceActiveFocus() + verify(control.activeFocus) + + var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) + + // click + sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true }], + ["downChanged", { "down": true }], + "pressed", + ["pressedChanged", { "pressed": false }], + ["downChanged", { "down": false }], + "released", + "clicked"] + keyClick(Qt.Key_Space) + verify(sequenceSpy.success) + + // check + sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true }], + ["downChanged", { "down": true }], + "pressed", + "activated"] + keyPress(Qt.Key_Space) + tryVerify(function() { return sequenceSpy.success}) + + sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": false }], + ["downChanged", { "down": false }], + ["checkedChanged", { "checked": true }], + "released", + "clicked"] + keyRelease(Qt.Key_Space) + verify(sequenceSpy.success) + + // uncheck + sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true }], + ["downChanged", { "down": true }], + "pressed", + ["pressedChanged", { "pressed": false }], + ["downChanged", { "down": false }], + ["checkedChanged", { "checked": false }], + "released", + "clicked"] + keyClick(Qt.Key_Space) + verify(sequenceSpy.success) + + // no change + sequenceSpy.expectedSequence = [] + var keys = [Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape, Qt.Key_Tab] + for (var i = 0; i < keys.length; ++i) { + sequenceSpy.reset() + keyClick(keys[i]) + verify(sequenceSpy.success) + } + } + + function test_progress() { + var control = createTemporaryObject(delayButton, testCase) + verify(control) + + var progressSpy = signalSpy.createObject(control, {target: control, signalName: "progressChanged"}) + verify(progressSpy.valid) + + compare(control.progress, 0.0) + mousePress(control) + tryCompare(control, "progress", 1.0) + verify(progressSpy.count > 0) + } + + function test_baseline() { + var control = createTemporaryObject(delayButton, testCase) + verify(control) + compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) + } +} diff --git a/tests/auto/controls/data/tst_dial.qml b/tests/auto/controls/data/tst_dial.qml index 7998d4fc..f6b6a720 100644 --- a/tests/auto/controls/data/tst_dial.qml +++ b/tests/auto/controls/data/tst_dial.qml @@ -55,19 +55,14 @@ TestCase { Dial {} } - property var dial: null - - function init() { - dial = dialComponent.createObject(testCase); - verify(dial, "Dial: failed to create an instance"); - } - - function cleanup() { - if (dial) - dial.destroy(); + Component { + id: signalSpy + SignalSpy {} } function test_instance() { + var dial = createTemporaryObject(dialComponent, testCase); + verify(dial); compare(dial.value, 0.0); compare(dial.from, 0.0); compare(dial.to, 1.0); @@ -77,6 +72,8 @@ TestCase { } function test_value() { + var dial = createTemporaryObject(dialComponent, testCase); + verify(dial); compare(dial.value, 0.0); dial.value = 0.5; @@ -93,6 +90,9 @@ TestCase { } function test_range() { + var dial = createTemporaryObject(dialComponent, testCase); + verify(dial); + dial.from = 0; dial.to = 100; dial.value = 50; @@ -125,9 +125,8 @@ TestCase { } function test_inverted() { - dial.destroy(); - dial = dialComponent.createObject(testCase, { from: 1.0, to: -1.0 }); - verify(dial, "Dial: failed to create an instance"); + var dial = createTemporaryObject(dialComponent, testCase, { from: 1.0, to: -1.0 }); + verify(dial); compare(dial.from, 1.0); compare(dial.to, -1.0); compare(dial.value, 0.0); @@ -152,6 +151,9 @@ TestCase { } function test_pressed() { + var dial = createTemporaryObject(dialComponent, testCase); + verify(dial); + pressSpy.target = dial; verify(pressSpy.valid); verify(!dial.pressed); @@ -163,6 +165,15 @@ TestCase { mouseRelease(dial, dial.width / 2, dial.height / 2); verify(!dial.pressed); compare(pressSpy.count, 2); + + var touch = touchEvent(dial); + touch.press(0).commit(); + verify(dial.pressed); + compare(pressSpy.count, 3); + + touch.release(0).commit(); + verify(!dial.pressed); + compare(pressSpy.count, 4); } SignalSpy { @@ -172,47 +183,68 @@ TestCase { function test_dragging_data() { return [ - { tag: "default", from: 0, to: 1, leftValue: 0.20, topValue: 0.5, rightValue: 0.8, bottomValue: 1.0 }, - { tag: "scaled2", from: 0, to: 2, leftValue: 0.4, topValue: 1.0, rightValue: 1.6, bottomValue: 2.0 }, - { tag: "scaled1", from: -1, to: 0, leftValue: -0.8, topValue: -0.5, rightValue: -0.2, bottomValue: 0.0 } + { tag: "default", from: 0, to: 1, leftValue: 0.20, topValue: 0.5, rightValue: 0.8, bottomValue: 1.0, live: false }, + { tag: "scaled2", from: 0, to: 2, leftValue: 0.4, topValue: 1.0, rightValue: 1.6, bottomValue: 2.0, live: false }, + { tag: "scaled1", from: -1, to: 0, leftValue: -0.8, topValue: -0.5, rightValue: -0.2, bottomValue: 0.0, live: false }, + { tag: "live", from: 0, to: 1, leftValue: 0.20, topValue: 0.5, rightValue: 0.8, bottomValue: 1.0, live: true } ] } function test_dragging(data) { + var dial = createTemporaryObject(dialComponent, testCase); + verify(dial); + dial.wrap = true; verify(dial.wrap); dial.from = data.from; dial.to = data.to; + dial.live = data.live; valueSpy.target = dial; verify(valueSpy.valid); + var moveSpy = createTemporaryObject(signalSpy, testCase, {target: dial, signalName: "moved"}); + verify(moveSpy.valid); + + var minimumExpectedValueCount = data.live ? 2 : 1; + // drag to the left mouseDrag(dial, dial.width / 2, dial.height / 2, -dial.width / 2, 0, Qt.LeftButton); fuzzyCompare(dial.value, data.leftValue, 0.1); - verify(valueSpy.count > 0); + verify(valueSpy.count >= minimumExpectedValueCount); valueSpy.clear(); + verify(moveSpy.count > 0); + moveSpy.clear(); // drag to the top mouseDrag(dial, dial.width / 2, dial.height / 2, 0, -dial.height / 2, Qt.LeftButton); fuzzyCompare(dial.value, data.topValue, 0.1); - verify(valueSpy.count > 0); + verify(valueSpy.count >= minimumExpectedValueCount); valueSpy.clear(); + verify(moveSpy.count > 0); + moveSpy.clear(); // drag to the right mouseDrag(dial, dial.width / 2, dial.height / 2, dial.width / 2, 0, Qt.LeftButton); fuzzyCompare(dial.value, data.rightValue, 0.1); - verify(valueSpy.count > 0); + verify(valueSpy.count >= minimumExpectedValueCount); valueSpy.clear(); + verify(moveSpy.count > 0); + moveSpy.clear(); // drag to the bottom (* 0.6 to ensure we don't go over to the minimum position) mouseDrag(dial, dial.width / 2, dial.height / 2, 10, dial.height / 2, Qt.LeftButton); fuzzyCompare(dial.value, data.bottomValue, 0.1); - verify(valueSpy.count > 0); + verify(valueSpy.count >= minimumExpectedValueCount); valueSpy.clear(); + verify(moveSpy.count > 0); + moveSpy.clear(); } function test_nonWrapping() { + var dial = createTemporaryObject(dialComponent, testCase); + verify(dial); + compare(dial.wrap, false); dial.value = 0; @@ -249,6 +281,90 @@ TestCase { verify(dial.position > positionAtPress); } + function test_touch() { + var dial = createTemporaryObject(dialComponent, testCase); + verify(dial); + + var touch = touchEvent(dial); + + // Ensure that dragging from bottom left to bottom right doesn't work. + var yPos = dial.height * 0.75; + touch.press(0, dial, dial.width * 0.25, yPos).commit(); + var positionAtPress = dial.position; + touch.move(0, dial, dial.width * 0.5, yPos).commit(); + compare(dial.position, positionAtPress); + touch.move(0, dial, dial.width * 0.75, yPos).commit(); + compare(dial.position, positionAtPress); + touch.release(0, dial, dial.width * 0.75, yPos).commit(); + compare(dial.position, positionAtPress); + + // Try the same thing, but a bit higher. + yPos = dial.height * 0.6; + touch.press(0, dial, dial.width * 0.25, yPos).commit(); + positionAtPress = dial.position; + touch.move(0, dial, dial.width * 0.5, yPos).commit(); + compare(dial.position, positionAtPress); + touch.move(0, dial, dial.width * 0.75, yPos).commit(); + compare(dial.position, positionAtPress); + touch.release(0, dial, dial.width * 0.75, yPos).commit(); + compare(dial.position, positionAtPress); + + // Going from below the center of the dial to above it should work (once it gets above the center). + touch.press(0, dial, dial.width * 0.25, dial.height * 0.75).commit(); + positionAtPress = dial.position; + touch.move(0, dial, dial.width * 0.5, dial.height * 0.6).commit(); + compare(dial.position, positionAtPress); + touch.move(0, dial, dial.width * 0.75, dial.height * 0.4).commit(); + verify(dial.position > positionAtPress); + touch.release(0, dial, dial.width * 0.75, dial.height * 0.3).commit(); + verify(dial.position > positionAtPress); + } + + function test_multiTouch() { + var dial1 = createTemporaryObject(dialComponent, testCase); + verify(dial1); + + var touch = touchEvent(dial1); + touch.press(0, dial1).commit().move(0, dial1, dial1.width / 4, dial1.height / 4).commit(); + compare(dial1.pressed, true); + verify(dial1.position > 0.0); + + var pos1Before = dial1.position; + + // second touch point on the same control is ignored + touch.stationary(0).press(1, dial1, 0, 0).commit() + touch.stationary(0).move(1, dial1).commit() + touch.stationary(0).release(1).commit() + compare(dial1.pressed, true); + compare(dial1.position, pos1Before); + + var dial2 = createTemporaryObject(dialComponent, testCase, {y: dial1.height}); + verify(dial2); + waitForRendering(dial2); + + // press the second dial + touch.stationary(0).press(2, dial2, 0, 0).commit(); + compare(dial2.pressed, true); + compare(dial2.position, 0.0); + + pos1Before = dial1.position; + var pos2Before = dial2.position; + + // move both dials + touch.move(0, dial1).move(2, dial2, dial2.width / 4, dial2.height / 4).commit(); + compare(dial1.pressed, true); + verify(dial1.position !== pos1Before); + compare(dial2.pressed, true); + verify(dial2.position !== pos2Before); + + // release both dials + touch.release(0, dial1).release(2, dial2).commit(); + compare(dial1.pressed, false); + compare(dial1.value, dial1.position); + compare(dial2.pressed, false); + compare(dial2.value, dial2.position); + } + property Component focusTest: Component { FocusScope { signal receivedKeyPress @@ -264,13 +380,21 @@ TestCase { } function test_keyboardNavigation() { - var focusScope = focusTest.createObject(testCase); + var dial = createTemporaryObject(dialComponent, testCase); + verify(dial); + + var focusScope = createTemporaryObject(focusTest, testCase); verify(focusScope); + var moveCount = 0; + // Tests that we've accepted events that we're interested in. parentEventSpy.target = focusScope; parentEventSpy.signalName = "receivedKeyPress"; + var moveSpy = createTemporaryObject(signalSpy, testCase, {target: dial, signalName: "moved"}); + verify(moveSpy.valid); + dial.parent = focusScope; compare(dial.activeFocusOnTab, true); compare(dial.value, 0); @@ -281,45 +405,54 @@ TestCase { keyClick(Qt.Key_Left); compare(parentEventSpy.count, 0); + compare(moveSpy.count, moveCount); compare(dial.value, 0); - + var oldValue = 0.0; var keyPairs = [[Qt.Key_Left, Qt.Key_Right], [Qt.Key_Down, Qt.Key_Up]]; for (var keyPairIndex = 0; keyPairIndex < 2; ++keyPairIndex) { for (var i = 1; i <= 10; ++i) { + oldValue = dial.value; keyClick(keyPairs[keyPairIndex][1]); compare(parentEventSpy.count, 0); + if (oldValue !== dial.value) + compare(moveSpy.count, ++moveCount); compare(dial.value, dial.stepSize * i); } compare(dial.value, dial.to); for (i = 10; i > 0; --i) { + oldValue = dial.value; keyClick(keyPairs[keyPairIndex][0]); compare(parentEventSpy.count, 0); + if (oldValue !== dial.value) + compare(moveSpy.count, ++moveCount); compare(dial.value, dial.stepSize * (i - 1)); } } + dial.value = 0.5; + + keyClick(Qt.Key_Home); + compare(parentEventSpy.count, 0); + compare(moveSpy.count, ++moveCount); compare(dial.value, dial.from); keyClick(Qt.Key_Home); compare(parentEventSpy.count, 0); + compare(moveSpy.count, moveCount); compare(dial.value, dial.from); keyClick(Qt.Key_End); compare(parentEventSpy.count, 0); + compare(moveSpy.count, ++moveCount); compare(dial.value, dial.to); keyClick(Qt.Key_End); compare(parentEventSpy.count, 0); + compare(moveSpy.count, moveCount); compare(dial.value, dial.to); - - keyClick(Qt.Key_Home); - compare(parentEventSpy.count, 0); - compare(dial.value, dial.from); - - focusScope.destroy(); } function test_snapMode_data() { @@ -336,7 +469,14 @@ TestCase { ] } - function test_snapMode(data) { + function test_snapMode_mouse_data() { + return test_snapMode_data() + } + + function test_snapMode_mouse(data) { + var dial = createTemporaryObject(dialComponent, testCase); + verify(dial); + dial.snapMode = data.snapMode; dial.from = data.from; dial.to = data.to; @@ -357,6 +497,35 @@ TestCase { fuzzyCompare(dial.position, data.positions[2], fuzz); } + function test_snapMode_touch_data() { + return test_snapMode_data() + } + + function test_snapMode_touch(data) { + var dial = createTemporaryObject(dialComponent, testCase); + verify(dial); + + dial.snapMode = data.snapMode; + dial.from = data.from; + dial.to = data.to; + dial.stepSize = 0.2; + + var fuzz = 0.05; + + var touch = touchEvent(dial); + touch.press(0, dial, dial.width * 0.25, dial.height * 0.75).commit() + compare(dial.value, data.values[0]); + compare(dial.position, data.positions[0]); + + touch.move(0, dial, dial.width * 0.5, dial.height * 0.25).commit(); + fuzzyCompare(dial.value, data.values[1], fuzz); + fuzzyCompare(dial.position, data.positions[1], fuzz); + + touch.release(0, dial, dial.width * 0.5, dial.height * 0.25).commit(); + fuzzyCompare(dial.value, data.values[2], fuzz); + fuzzyCompare(dial.position, data.positions[2], fuzz); + } + function test_wheel_data() { return [ { tag: "horizontal", orientation: Qt.Horizontal, dx: 120, dy: 0 }, @@ -365,7 +534,7 @@ TestCase { } function test_wheel(data) { - var control = dialComponent.createObject(testCase, {wheelEnabled: true, orientation: data.orientation}) + var control = createTemporaryObject(dialComponent, testCase, {wheelEnabled: true, orientation: data.orientation}) verify(control) compare(control.value, 0.0) @@ -400,7 +569,5 @@ TestCase { mouseWheel(control, control.width / 2, control.height / 2, -data.dx, -data.dy) compare(control.value, 2.5) compare(control.position, 0.25) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_dialog.qml b/tests/auto/controls/data/tst_dialog.qml index c295c0c1..fe81a2fa 100644 --- a/tests/auto/controls/data/tst_dialog.qml +++ b/tests/auto/controls/data/tst_dialog.qml @@ -67,39 +67,36 @@ TestCase { } function test_defaults() { - var control = dialog.createObject(testCase) + var control = createTemporaryObject(dialog, testCase) verify(control) verify(control.header) verify(control.footer) compare(control.standardButtons, 0) - control.destroy() } function test_accept() { - var control = dialog.createObject(testCase) + var control = createTemporaryObject(dialog, testCase) control.open() waitForRendering(control.contentItem) verify(control.visible) - var acceptedSpy = signalSpy.createObject(testCase, {target: control, signalName: "accepted"}) + var acceptedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "accepted"}) verify(acceptedSpy.valid) control.accept() compare(acceptedSpy.count, 1) tryCompare(control, "visible", false) - - control.destroy() } function test_reject() { - var control = dialog.createObject(testCase) + var control = createTemporaryObject(dialog, testCase) control.open() waitForRendering(control.contentItem) verify(control.visible) - var rejectedSpy = signalSpy.createObject(testCase, {target: control, signalName: "rejected"}) + var rejectedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rejected"}) verify(rejectedSpy.valid) control.reject() compare(rejectedSpy.count, 1) @@ -149,8 +146,6 @@ TestCase { mouseRelease(testCase, 1, 1) compare(rejectedSpy.count, 4) tryCompare(control, "visible", false) - - control.destroy() } function test_buttonBox_data() { @@ -161,7 +156,7 @@ TestCase { } function test_buttonBox(data) { - var control = dialog.createObject(testCase) + var control = createTemporaryObject(dialog, testCase) if (data.custom) control.footer = buttonBox.createObject(testCase) @@ -170,21 +165,19 @@ TestCase { verify(box) compare(box.standardButtons, Dialog.Ok | Dialog.Cancel) - var acceptedSpy = signalSpy.createObject(testCase, {target: control, signalName: "accepted"}) + var acceptedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "accepted"}) verify(acceptedSpy.valid) box.accepted() compare(acceptedSpy.count, 1) - var rejectedSpy = signalSpy.createObject(testCase, {target: control, signalName: "rejected"}) + var rejectedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rejected"}) verify(rejectedSpy.valid) box.rejected() compare(rejectedSpy.count, 1) - - control.destroy() } function test_standardButtons() { - var control = dialog.createObject(testCase) + var control = createTemporaryObject(dialog, testCase) control.standardButtons = Dialog.Ok @@ -217,12 +210,10 @@ TestCase { control.standardButtons = 0 compare(box.count, 0) - - control.destroy() } function test_layout() { - var control = dialog.createObject(testCase, {width: 100, height: 100}) + var control = createTemporaryObject(dialog, testCase, {width: 100, height: 100}) verify(control) control.open() @@ -296,8 +287,6 @@ TestCase { control.footer.implicitWidth = 160 compare(control.implicitWidth, control.footer.implicitWidth) - - control.destroy() } function test_spacing_data() { @@ -313,7 +302,7 @@ TestCase { } function test_spacing(data) { - var control = dialog.createObject(testCase, {spacing: 20, width: 100, height: 100}) + var control = createTemporaryObject(dialog, testCase, {spacing: 20, width: 100, height: 100}) verify(control) control.open() @@ -340,7 +329,5 @@ TestCase { compare(control.contentItem.height, control.availableHeight - (data.header ? control.header.height + control.spacing : 0) - (data.footer ? control.footer.height + control.spacing : 0)) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_dialogbuttonbox.qml b/tests/auto/controls/data/tst_dialogbuttonbox.qml index 880d44c7..603b069b 100644 --- a/tests/auto/controls/data/tst_dialogbuttonbox.qml +++ b/tests/auto/controls/data/tst_dialogbuttonbox.qml @@ -66,17 +66,16 @@ TestCase { } function test_defaults() { - var control = buttonBox.createObject(testCase) + var control = createTemporaryObject(buttonBox, testCase) verify(control) compare(control.count, 0) verify(control.delegate) compare(control.standardButtons, 0) - control.destroy() } function test_standardButtons() { - var control = buttonBox.createObject(testCase) - + var control = createTemporaryObject(buttonBox, testCase) + verify(control) compare(control.count, 0) control.standardButtons = DialogButtonBox.Ok @@ -107,12 +106,11 @@ TestCase { control.standardButtons = 0 compare(control.count, 0) - - control.destroy() } function test_attached() { - var control = buttonBox.createObject(testCase) + var control = createTemporaryObject(buttonBox, testCase) + verify(control) control.standardButtons = DialogButtonBox.Ok var okButton = control.itemAt(0) @@ -125,7 +123,7 @@ TestCase { saveButton.DialogButtonBox.buttonRole = DialogButtonBox.AcceptRole compare(saveButton.DialogButtonBox.buttonRole, DialogButtonBox.AcceptRole) - var closeButton = button.createObject(null, {text: "Save"}) + var closeButton = createTemporaryObject(button, null, {text: "Save"}) compare(closeButton.DialogButtonBox.buttonBox, null) compare(closeButton.DialogButtonBox.buttonRole, DialogButtonBox.InvalidRole) closeButton.DialogButtonBox.buttonRole = DialogButtonBox.DestructiveRole @@ -137,8 +135,6 @@ TestCase { compare(okButton.DialogButtonBox.buttonBox, null) compare(saveButton.DialogButtonBox.buttonBox, null) compare(closeButton.DialogButtonBox.buttonBox, null) - - control.destroy() } function test_signals_data() { @@ -165,7 +161,8 @@ TestCase { } function test_signals(data) { - var control = buttonBox.createObject(testCase) + var control = createTemporaryObject(buttonBox, testCase) + verify(control) control.standardButtons = data.standardButton compare(control.count, 1) @@ -182,7 +179,5 @@ TestCase { compare(clickedSpy.count, 1) compare(clickedSpy.signalArguments[0][0], button) compare(roleSpy.count, !!data.signalName ? 1 : 0) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_drawer.qml b/tests/auto/controls/data/tst_drawer.qml index 91e934c4..887db22d 100644 --- a/tests/auto/controls/data/tst_drawer.qml +++ b/tests/auto/controls/data/tst_drawer.qml @@ -56,12 +56,11 @@ TestCase { } function test_defaults() { - var control = drawer.createObject(testCase) + var control = createTemporaryObject(drawer, testCase) compare(control.edge, Qt.LeftEdge) compare(control.position, 0.0) compare(control.dragMargin, Qt.styleHints.startDragDistance) compare(control.parent, ApplicationWindow.overlay) - control.destroy() } Component { @@ -79,7 +78,7 @@ TestCase { function test_swipeVelocity() { skip("QTBUG-52003"); - var control = rectDrawer.createObject(testCase) + var control = createTemporaryObject(rectDrawer, testCase) verify(control.contentItem) compare(control.edge, Qt.LeftEdge) compare(control.position, 0.0) @@ -95,7 +94,5 @@ TestCase { tryCompare(control, "position", distance / control.contentItem.width) mouseRelease(control, distance, 0, Qt.LeftButton) tryCompare(control, "position", 1.0) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_frame.qml b/tests/auto/controls/data/tst_frame.qml index 7d8ab7c3..2f4748c4 100644 --- a/tests/auto/controls/data/tst_frame.qml +++ b/tests/auto/controls/data/tst_frame.qml @@ -90,49 +90,41 @@ TestCase { } function test_empty() { - var control = frame.createObject(testCase) + var control = createTemporaryObject(frame, testCase) verify(control) verify(control.contentItem) compare(control.contentWidth, 0) compare(control.contentHeight, 0) - - control.destroy() } function test_oneChild() { - var control = oneChildFrame.createObject(testCase) + var control = createTemporaryObject(oneChildFrame, testCase) verify(control) compare(control.contentWidth, 100) compare(control.contentHeight, 30) verify(control.implicitWidth > 100) verify(control.implicitHeight > 30) - - control.destroy() } function test_twoChildren() { - var control = twoChildrenFrame.createObject(testCase) + var control = createTemporaryObject(twoChildrenFrame, testCase) verify(control) compare(control.contentWidth, 0) compare(control.contentHeight, 0) verify(control.implicitWidth > 0) verify(control.implicitHeight > 0) - - control.destroy() } function test_contentItem() { - var control = contentFrame.createObject(testCase) + var control = createTemporaryObject(contentFrame, testCase) verify(control) compare(control.contentWidth, 100) compare(control.contentHeight, 30) verify(control.implicitWidth > 100) verify(control.implicitHeight > 30) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_groupbox.qml b/tests/auto/controls/data/tst_groupbox.qml index 05348ad5..1108ba4d 100644 --- a/tests/auto/controls/data/tst_groupbox.qml +++ b/tests/auto/controls/data/tst_groupbox.qml @@ -90,49 +90,41 @@ TestCase { } function test_empty() { - var control = groupBox.createObject(testCase) + var control = createTemporaryObject(groupBox, testCase) verify(control) verify(control.contentItem) compare(control.contentWidth, 0) compare(control.contentHeight, 0) - - control.destroy() } function test_oneChild() { - var control = oneChildBox.createObject(testCase) + var control = createTemporaryObject(oneChildBox, testCase) verify(control) compare(control.contentWidth, 100) compare(control.contentHeight, 30) verify(control.implicitWidth > 100) verify(control.implicitHeight > 30) - - control.destroy() } function test_twoChildren() { - var control = twoChildrenBox.createObject(testCase) + var control = createTemporaryObject(twoChildrenBox, testCase) verify(control) compare(control.contentWidth, 0) compare(control.contentHeight, 0) verify(control.implicitWidth > 0) verify(control.implicitHeight > 0) - - control.destroy() } function test_contentItem() { - var control = contentBox.createObject(testCase) + var control = createTemporaryObject(contentBox, testCase) verify(control) compare(control.contentWidth, 100) compare(control.contentHeight, 30) verify(control.implicitWidth > 100) verify(control.implicitHeight > 30) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_itemdelegate.qml b/tests/auto/controls/data/tst_itemdelegate.qml index 3c5ee1cb..ac47ed45 100644 --- a/tests/auto/controls/data/tst_itemdelegate.qml +++ b/tests/auto/controls/data/tst_itemdelegate.qml @@ -56,20 +56,17 @@ TestCase { } function test_baseline() { - var control = itemDelegate.createObject(testCase) + var control = createTemporaryObject(itemDelegate, testCase) verify(control) compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) - control.destroy() } function test_highlighted() { - var control = itemDelegate.createObject(testCase) + var control = createTemporaryObject(itemDelegate, testCase) verify(control) verify(!control.highlighted) control.highlighted = true verify(control.highlighted) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_label.qml b/tests/auto/controls/data/tst_label.qml index 8dde8951..41faa1f7 100644 --- a/tests/auto/controls/data/tst_label.qml +++ b/tests/auto/controls/data/tst_label.qml @@ -61,9 +61,8 @@ TestCase { } function test_creation() { - var control = label.createObject(testCase) + var control = createTemporaryObject(label, testCase) verify(control) - control.destroy() } function test_font_explicit_attributes_data() { @@ -80,7 +79,7 @@ TestCase { } function test_font_explicit_attributes(data) { - var control = label.createObject(testCase) + var control = createTemporaryObject(label, testCase) verify(control) var child = label.createObject(control) @@ -105,7 +104,5 @@ TestCase { compare(child.font[data.tag], defaultValue) compare(childSpy.count, 0) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_menuitem.qml b/tests/auto/controls/data/tst_menuitem.qml index f00e229a..75fd3830 100644 --- a/tests/auto/controls/data/tst_menuitem.qml +++ b/tests/auto/controls/data/tst_menuitem.qml @@ -56,14 +56,13 @@ TestCase { } function test_baseline() { - var control = menuItem.createObject(testCase) + var control = createTemporaryObject(menuItem, testCase) verify(control) compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) - control.destroy() } function test_checkable() { - var control = menuItem.createObject(testCase) + var control = createTemporaryObject(menuItem, testCase) verify(control) verify(control.hasOwnProperty("checkable")) verify(!control.checkable) @@ -77,18 +76,14 @@ TestCase { mouseClick(control) verify(!control.checked) - - control.destroy() } function test_highlighted() { - var control = menuItem.createObject(testCase) + var control = createTemporaryObject(menuItem, testCase) verify(control) verify(!control.highlighted) control.highlighted = true verify(control.highlighted) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_page.qml b/tests/auto/controls/data/tst_page.qml index 0388bc0a..52625382 100644 --- a/tests/auto/controls/data/tst_page.qml +++ b/tests/auto/controls/data/tst_page.qml @@ -95,65 +95,55 @@ TestCase { } function test_defaults() { - var control = page.createObject(testCase) + var control = createTemporaryObject(page, testCase) verify(control) verify(control.contentItem) compare(control.header, null) compare(control.footer, null) - - control.destroy() } function test_empty() { - var control = page.createObject(testCase) + var control = createTemporaryObject(page, testCase) verify(control) verify(control.contentItem) compare(control.contentWidth, 0) compare(control.contentHeight, 0) - - control.destroy() } function test_oneChild() { - var control = oneChildPage.createObject(testCase) + var control = createTemporaryObject(oneChildPage, testCase) verify(control) compare(control.contentWidth, 100) compare(control.contentHeight, 30) compare(control.implicitWidth, 100 + control.leftPadding + control.rightPadding) compare(control.implicitHeight, 30 + control.topPadding + control.bottomPadding) - - control.destroy() } function test_twoChildren() { - var control = twoChildrenPage.createObject(testCase) + var control = createTemporaryObject(twoChildrenPage, testCase) verify(control) compare(control.contentWidth, 0) compare(control.contentHeight, 0) compare(control.implicitWidth, control.leftPadding + control.rightPadding) compare(control.implicitHeight, control.topPadding + control.bottomPadding) - - control.destroy() } function test_contentItem() { - var control = contentPage.createObject(testCase) + var control = createTemporaryObject(contentPage, testCase) verify(control) compare(control.contentWidth, 100) compare(control.contentHeight, 30) compare(control.implicitWidth, 100 + control.leftPadding + control.rightPadding) compare(control.implicitHeight, 30 + control.topPadding + control.bottomPadding) - - control.destroy() } function test_layout() { - var control = page.createObject(testCase, {width: 100, height: 100}) + var control = createTemporaryObject(page, testCase, {width: 100, height: 100}) verify(control) compare(control.width, 100) @@ -223,8 +213,6 @@ TestCase { control.footer.implicitWidth = 160 compare(control.implicitWidth, control.footer.implicitWidth + control.leftPadding + control.rightPadding) - - control.destroy() } function test_spacing_data() { @@ -240,7 +228,7 @@ TestCase { } function test_spacing(data) { - var control = page.createObject(testCase, {spacing: 20, width: 100, height: 100}) + var control = createTemporaryObject(page, testCase, {spacing: 20, width: 100, height: 100}) verify(control) control.contentItem.visible = data.content @@ -263,7 +251,5 @@ TestCase { compare(control.contentItem.height, control.availableHeight - (data.header ? control.header.height + control.spacing : 0) - (data.footer ? control.footer.height + control.spacing : 0)) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_pageindicator.qml b/tests/auto/controls/data/tst_pageindicator.qml index 4094a293..4341d7b2 100644 --- a/tests/auto/controls/data/tst_pageindicator.qml +++ b/tests/auto/controls/data/tst_pageindicator.qml @@ -56,29 +56,25 @@ TestCase { } function test_count() { - var control = pageIndicator.createObject(testCase) + var control = createTemporaryObject(pageIndicator, testCase) verify(control) compare(control.count, 0) control.count = 3 compare(control.count, 3) - - control.destroy() } function test_currentIndex() { - var control = pageIndicator.createObject(testCase) + var control = createTemporaryObject(pageIndicator, testCase) verify(control) compare(control.currentIndex, 0) control.currentIndex = 5 compare(control.currentIndex, 5) - - control.destroy() } function test_interactive() { - var control = pageIndicator.createObject(testCase, {count: 5}) + var control = createTemporaryObject(pageIndicator, testCase, {count: 5}) verify(control) verify(!control.interactive) @@ -110,7 +106,5 @@ TestCase { } } } - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_pane.qml b/tests/auto/controls/data/tst_pane.qml index ec188afb..0c1b54db 100644 --- a/tests/auto/controls/data/tst_pane.qml +++ b/tests/auto/controls/data/tst_pane.qml @@ -103,54 +103,46 @@ TestCase { } function test_empty() { - var control = pane.createObject(testCase) + var control = createTemporaryObject(pane, testCase) verify(control) verify(control.contentItem) compare(control.contentWidth, 0) compare(control.contentHeight, 0) - - control.destroy() } function test_oneChild() { - var control = oneChildPane.createObject(testCase) + var control = createTemporaryObject(oneChildPane, testCase) verify(control) compare(control.contentWidth, 100) compare(control.contentHeight, 30) verify(control.implicitWidth > 100) verify(control.implicitHeight > 30) - - control.destroy() } function test_twoChildren() { - var control = twoChildrenPane.createObject(testCase) + var control = createTemporaryObject(twoChildrenPane, testCase) verify(control) compare(control.contentWidth, 0) compare(control.contentHeight, 0) verify(control.implicitWidth > 0) verify(control.implicitHeight > 0) - - control.destroy() } function test_contentItem() { - var control = contentPane.createObject(testCase) + var control = createTemporaryObject(contentPane, testCase) verify(control) compare(control.contentWidth, 100) compare(control.contentHeight, 30) verify(control.implicitWidth > 100) verify(control.implicitHeight > 30) - - control.destroy() } function test_press() { - var control = pressPane.createObject(testCase) + var control = createTemporaryObject(pressPane, testCase) verify(control) compare(control.pressCount, 0) @@ -160,7 +152,5 @@ TestCase { control.children[0].enabled = false mouseClick(control) compare(control.pressCount, 1) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_popup.qml b/tests/auto/controls/data/tst_popup.qml index ee98e2ae..1059ca82 100644 --- a/tests/auto/controls/data/tst_popup.qml +++ b/tests/auto/controls/data/tst_popup.qml @@ -78,22 +78,22 @@ TestCase { } function test_padding() { - var control = popupTemplate.createObject(testCase) + var control = createTemporaryObject(popupTemplate, testCase) verify(control) - var paddingSpy = signalSpy.createObject(testCase, {target: control, signalName: "paddingChanged"}) + var paddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "paddingChanged"}) verify(paddingSpy.valid) - var topPaddingSpy = signalSpy.createObject(testCase, {target: control, signalName: "topPaddingChanged"}) + var topPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "topPaddingChanged"}) verify(topPaddingSpy.valid) - var leftPaddingSpy = signalSpy.createObject(testCase, {target: control, signalName: "leftPaddingChanged"}) + var leftPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "leftPaddingChanged"}) verify(leftPaddingSpy.valid) - var rightPaddingSpy = signalSpy.createObject(testCase, {target: control, signalName: "rightPaddingChanged"}) + var rightPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rightPaddingChanged"}) verify(rightPaddingSpy.valid) - var bottomPaddingSpy = signalSpy.createObject(testCase, {target: control, signalName: "bottomPaddingChanged"}) + var bottomPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "bottomPaddingChanged"}) verify(bottomPaddingSpy.valid) var paddingChanges = 0 @@ -184,18 +184,16 @@ TestCase { compare(leftPaddingSpy.count, leftPaddingChanges) compare(rightPaddingSpy.count, rightPaddingChanges) compare(bottomPaddingSpy.count, bottomPaddingChanges) - - control.destroy() } function test_availableSize() { var control = popupTemplate.createObject(testCase) verify(control) - var availableWidthSpy = signalSpy.createObject(testCase, {target: control, signalName: "availableWidthChanged"}) + var availableWidthSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "availableWidthChanged"}) verify(availableWidthSpy.valid) - var availableHeightSpy = signalSpy.createObject(testCase, {target: control, signalName: "availableHeightChanged"}) + var availableHeightSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "availableHeightChanged"}) verify(availableHeightSpy.valid) var availableWidthChanges = 0 @@ -256,19 +254,17 @@ TestCase { compare(control.availableHeight, 0) compare(availableWidthSpy.count, availableWidthChanges) compare(availableHeightSpy.count, ++availableHeightChanges) - - control.destroy() } function test_position() { - var control = popupControl.createObject(testCase, {visible: true, leftMargin: 10, topMargin: 20, width: 100, height: 100}) + var control = createTemporaryObject(popupControl, testCase, {visible: true, leftMargin: 10, topMargin: 20, width: 100, height: 100}) verify(control) verify(control.visible) - var xSpy = signalSpy.createObject(testCase, {target: control, signalName: "xChanged"}) + var xSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "xChanged"}) verify(xSpy.valid) - var ySpy = signalSpy.createObject(testCase, {target: control, signalName: "yChanged"}) + var ySpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "yChanged"}) verify(ySpy.valid) // moving outside margins does not trigger change notifiers @@ -298,7 +294,7 @@ TestCase { compare(ySpy.count, 1) // re-parent and reset the position - control.parent = rect.createObject(testCase, {color: "red", width: 100, height: 100}) + control.parent = createTemporaryObject(rect, testCase, {color: "red", width: 100, height: 100}) control.x = 0 control.y = 0 compare(xSpy.count, 2) @@ -314,12 +310,10 @@ TestCase { compare(control.y, 60 + control.topMargin) compare(xSpy.count, 3) compare(ySpy.count, 3) - - control.destroy() } function test_resetSize() { - var control = popupControl.createObject(testCase, {visible: true, margins: 0}) + var control = createTemporaryObject(popupControl, testCase, {visible: true, margins: 0}) verify(control) control.width = control.implicitWidth = testCase.width + 10 @@ -332,12 +326,10 @@ TestCase { control.height = undefined compare(control.width, testCase.width) compare(control.height, testCase.height) - - control.destroy() } function test_negativeMargins() { - var control = popupControl.createObject(testCase, {implicitWidth: testCase.width, implicitHeight: testCase.height}) + var control = createTemporaryObject(popupControl, testCase, {implicitWidth: testCase.width, implicitHeight: testCase.height}) verify(control) control.open() @@ -356,12 +348,10 @@ TestCase { control.y = -10 compare(control.x, 0) compare(control.y, 0) - - control.destroy() } function test_margins() { - var control = popupControl.createObject(testCase, {width: 100, height: 100}) + var control = createTemporaryObject(popupControl, testCase, {width: 100, height: 100}) verify(control) control.open() @@ -444,12 +434,10 @@ TestCase { compare(control.leftMargin, -1) compare(control.contentItem.parent.x, -testCase.width) compare(control.contentItem.parent.y, -testCase.height) - - control.destroy() } function test_background() { - var control = popupTemplate.createObject(testCase) + var control = createTemporaryObject(popupTemplate, testCase) verify(control) control.background = rect.createObject(testCase) @@ -491,8 +479,6 @@ TestCase { control.background.y = 10 control.height -= 20 verify(control.background.height !== control.height) - - control.destroy() } function getChild(control, objname, idx) { @@ -566,7 +552,7 @@ TestCase { } function test_font() { // QTBUG_50984, QTBUG-51696 - var window = component.createObject(testCase) + var window = createTemporaryObject(component, testCase) verify(window) compare(window.font.pixelSize, 40) @@ -643,8 +629,6 @@ TestCase { compare(window.popup.listview.contentItem.children[idx1].fontspy.count, 2) compare(window.popup.listview.contentItem.children[idx2].font.pixelSize, 60) compare(window.popup.listview.contentItem.children[idx2].fontspy.count, 2) - - window.destroy() } Component { @@ -687,7 +671,7 @@ TestCase { function test_locale() { // QTBUG_50984 // test looking up natural locale from ancestors - var control = localeComponent.createObject(applicationWindow.contentItem) + var control = createTemporaryObject(localeComponent, applicationWindow.contentItem) verify(control) compare(control.locale.name, "en_US") @@ -697,7 +681,6 @@ TestCase { compare(control.popup.button2.locale.name, "nb_NO") control.ApplicationWindow.window.locale = undefined - control.destroy() } Component { @@ -771,7 +754,7 @@ TestCase { function test_locale_changes() { // QTBUG_50984 // test default locale and locale inheritance - var control = localeChangeComponent.createObject(applicationWindow.contentItem) + var control = createTemporaryObject(localeChangeComponent, applicationWindow.contentItem) verify(control) var defaultLocale = Qt.locale() @@ -937,12 +920,10 @@ TestCase { compare(control.popup.button1.mirrorspy.count, 2) compare(control.popup.button2.localespy.count, 5) compare(control.popup.button2.mirrorspy.count, 2) - - control.destroy() } function test_size() { - var control = popupControl.createObject(testCase) + var control = createTemporaryObject(popupControl, testCase) verify(control) control.open() @@ -991,12 +972,10 @@ TestCase { compare(control.implicitHeight, 40) compare(control.height, 40) compare(control.contentItem.height, control.height - control.topPadding - control.bottomPadding) - - control.destroy() } function test_visible() { - var control = popupTemplate.createObject(testCase, {visible: true}) + var control = createTemporaryObject(popupTemplate, testCase, {visible: true}) verify(control) // QTBUG-51989 @@ -1005,8 +984,6 @@ TestCase { // QTBUG-55347 control.parent = null verify(!control.visible) - - control.destroy() } Component { @@ -1070,7 +1047,7 @@ TestCase { } function test_overlay() { - var window = overlayTest.createObject(testCase) + var window = createTemporaryObject(overlayTest, testCase) verify(window) window.requestActivate() @@ -1168,12 +1145,10 @@ TestCase { window.modalPopupWithoutDim.close() tryCompare(window.modalPopupWithoutDim, "visible", false) compare(window.overlay.children.length, 0) // popup + overlay removed - - window.destroy() } function test_attached_applicationwindow() { - var control = popupControl.createObject(applicationWindow.contentItem) + var control = createTemporaryObject(popupControl, applicationWindow.contentItem) verify(control) var child = rect.createObject(control.contentItem) @@ -1186,8 +1161,6 @@ TestCase { compare(control.ApplicationWindow.window, null) compare(control.contentItem.ApplicationWindow.window, null) compare(child.ApplicationWindow.window, null) - - control.destroy() } SignalSpy { @@ -1209,7 +1182,7 @@ TestCase { } function test_openedClosed() { - var control = pausePopup.createObject(testCase) + var control = createTemporaryObject(pausePopup, testCase) verify(control) openedSpy.target = control @@ -1226,8 +1199,6 @@ TestCase { compare(closedSpy.count, 0) tryCompare(closedSpy, "count", 1) compare(control.visible, false) - - control.destroy() } Component { @@ -1253,11 +1224,10 @@ TestCase { } function test_xyBindingLoop() { - var window = xyBindingLoop.createObject(testCase) + var window = createTemporaryObject(xyBindingLoop, testCase) var control = window.popup waitForRendering(control.contentItem) compare(control.x, (control.parent.width - control.width) / 2) compare(control.y, (control.parent.height - control.height) / 2) - window.destroy() } } diff --git a/tests/auto/controls/data/tst_progressbar.qml b/tests/auto/controls/data/tst_progressbar.qml index 8f73b367..a51e01eb 100644 --- a/tests/auto/controls/data/tst_progressbar.qml +++ b/tests/auto/controls/data/tst_progressbar.qml @@ -56,7 +56,7 @@ TestCase { } function test_value() { - var control = progressBar.createObject(testCase) + var control = createTemporaryObject(progressBar, testCase) verify(control) compare(control.value, 0.0) @@ -68,12 +68,10 @@ TestCase { compare(control.value, 0.0) control.value = 2.0 compare(control.value, 1.0) - - control.destroy() } function test_range() { - var control = progressBar.createObject(testCase, {from: 0, to: 100, value: 50}) + var control = createTemporaryObject(progressBar, testCase, {from: 0, to: 100, value: 50}) verify(control) compare(control.from, 0) @@ -102,12 +100,10 @@ TestCase { control.value = 50 compare(control.value, 50) compare(control.position, 0.5) - - control.destroy() } function test_inverted() { - var control = progressBar.createObject(testCase, {from: 1.0, to: -1.0}) + var control = createTemporaryObject(progressBar, testCase, {from: 1.0, to: -1.0}) verify(control) compare(control.from, 1.0) @@ -126,12 +122,10 @@ TestCase { control.value = 0.0 compare(control.value, 0.0) compare(control.position, 0.5) - - control.destroy() } function test_position() { - var control = progressBar.createObject(testCase) + var control = createTemporaryObject(progressBar, testCase) verify(control) compare(control.value, 0) @@ -144,12 +138,10 @@ TestCase { control.value = 0.75 compare(control.value, 0.75) compare(control.position, 0.75) - - control.destroy() } function test_visualPosition() { - var control = progressBar.createObject(testCase) + var control = createTemporaryObject(progressBar, testCase) verify(control) compare(control.value, 0) @@ -178,12 +170,10 @@ TestCase { // LayoutMirroring control.LayoutMirroring.enabled = true compare(control.visualPosition, 0.75) - - control.destroy() } function test_indeterminate() { - var control = progressBar.createObject(testCase) + var control = createTemporaryObject(progressBar, testCase) verify(control) compare(control.indeterminate, false) @@ -192,7 +182,5 @@ TestCase { wait(100) // Shouldn't crash... control.indeterminate = false - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_radiobutton.qml b/tests/auto/controls/data/tst_radiobutton.qml index 046924c0..35f039b6 100644 --- a/tests/auto/controls/data/tst_radiobutton.qml +++ b/tests/auto/controls/data/tst_radiobutton.qml @@ -58,12 +58,12 @@ TestCase { Component { id: signalSequenceSpy SignalSequenceSpy { - signals: ["pressed", "released", "canceled", "clicked", "pressedChanged", "checkedChanged"] + signals: ["pressed", "released", "canceled", "clicked", "toggled", "pressedChanged", "checkedChanged"] } } function test_text() { - var control = radioButton.createObject(testCase) + var control = createTemporaryObject(radioButton, testCase) verify(control) compare(control.text, "") @@ -71,12 +71,10 @@ TestCase { compare(control.text, "RadioButton") control.text = "" compare(control.text, "") - - control.destroy() } function test_checked() { - var control = radioButton.createObject(testCase) + var control = createTemporaryObject(radioButton, testCase) verify(control) var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) @@ -94,12 +92,10 @@ TestCase { control.checked = false compare(control.checked, false) verify(sequenceSpy.success) - - control.destroy() } function test_mouse() { - var control = radioButton.createObject(testCase) + var control = createTemporaryObject(radioButton, testCase) verify(control) var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) @@ -112,6 +108,7 @@ TestCase { verify(sequenceSpy.success) sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": false }], ["checkedChanged", { "pressed": false, "checked": true }], + "toggled", "released", "clicked"] mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton) @@ -157,12 +154,10 @@ TestCase { compare(control.checked, true) compare(control.pressed, false) verify(sequenceSpy.success) - - control.destroy() } function test_keys() { - var control = radioButton.createObject(testCase) + var control = createTemporaryObject(radioButton, testCase) verify(control) var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) @@ -177,6 +172,7 @@ TestCase { "pressed", ["pressedChanged", { "pressed": false, "checked": false }], ["checkedChanged", { "pressed": false, "checked": true }], + "toggled", "released", "clicked"] keyClick(Qt.Key_Space) @@ -202,12 +198,10 @@ TestCase { compare(control.checked, true) verify(sequenceSpy.success) } - - control.destroy() } Component { - id: twoRadioButtones + id: twoRadioButtons Item { property RadioButton rb1: RadioButton { id: rb1 } property RadioButton rb2: RadioButton { id: rb2; checked: rb1.checked; enabled: false } @@ -215,7 +209,7 @@ TestCase { } function test_binding() { - var container = twoRadioButtones.createObject(testCase) + var container = createTemporaryObject(twoRadioButtons, testCase) verify(container) compare(container.rb1.checked, false) @@ -228,8 +222,6 @@ TestCase { container.rb1.checked = false compare(container.rb1.checked, false) compare(container.rb2.checked, false) - - container.destroy() } Component { @@ -256,7 +248,7 @@ TestCase { } function test_autoExclusive() { - var container = radioButtonGroup.createObject(testCase) + var container = createTemporaryObject(radioButtonGroup, testCase) compare(container.children.length, 8) var checkStates = [false, false, false, false, false, false, false, false] @@ -311,14 +303,11 @@ TestCase { checkStates[1] = false for (i = 0; i < 8; ++i) compare(container.children[i].checked, checkStates[i]) - - container.destroy() } function test_baseline() { - var control = radioButton.createObject(testCase) + var control = createTemporaryObject(radioButton, testCase) verify(control) compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) - control.destroy() } } diff --git a/tests/auto/controls/data/tst_radiodelegate.qml b/tests/auto/controls/data/tst_radiodelegate.qml index 8cc1d1f7..23446aa9 100644 --- a/tests/auto/controls/data/tst_radiodelegate.qml +++ b/tests/auto/controls/data/tst_radiodelegate.qml @@ -58,14 +58,13 @@ TestCase { // TODO: data-fy tst_radiobutton (rename to tst_radio?) so we don't duplicate its tests here? function test_defaults() { - var control = radioDelegate.createObject(testCase); + var control = createTemporaryObject(radioDelegate, testCase); verify(control); verify(!control.checked); - control.destroy(); } function test_checked() { - var control = radioDelegate.createObject(testCase); + var control = createTemporaryObject(radioDelegate, testCase); verify(control); mouseClick(control); @@ -73,14 +72,11 @@ TestCase { mouseClick(control); verify(control.checked); - - control.destroy(); } function test_baseline() { - var control = radioDelegate.createObject(testCase); + var control = createTemporaryObject(radioDelegate, testCase); verify(control); compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset); - control.destroy(); } } diff --git a/tests/auto/controls/data/tst_rangeslider.qml b/tests/auto/controls/data/tst_rangeslider.qml index ba3a1c9e..b015b2de 100644 --- a/tests/auto/controls/data/tst_rangeslider.qml +++ b/tests/auto/controls/data/tst_rangeslider.qml @@ -40,7 +40,7 @@ import QtQuick 2.2 import QtTest 1.0 -import QtQuick.Controls 2.1 +import QtQuick.Controls 2.2 TestCase { id: testCase @@ -80,18 +80,16 @@ TestCase { } function test_defaults() { - var control = sliderComponent.createObject(testCase) + var control = createTemporaryObject(sliderComponent, testCase) verify(control) compare(control.stepSize, 0) compare(control.snapMode, RangeSlider.NoSnap) compare(control.orientation, Qt.Horizontal) - - control.destroy() } function test_values() { - var control = sliderComponent.createObject(testCase) + var control = createTemporaryObject(sliderComponent, testCase) verify(control) compare(control.first.value, 0.0) @@ -113,12 +111,10 @@ TestCase { compare(control.first.value, 0.5) control.second.value = 0 compare(control.second.value, 0.5) - - control.destroy() } function test_range() { - var control = sliderComponent.createObject(testCase, { from: 0, to: 100, "first.value": 50, "second.value": 100 }) + var control = createTemporaryObject(sliderComponent, testCase, { from: 0, to: 100, "first.value": 50, "second.value": 100 }) verify(control) compare(control.from, 0) @@ -149,12 +145,10 @@ TestCase { control.first.value = 50 compare(control.first.value, 50) compare(control.first.position, 0.5) - - control.destroy() } function test_setValues() { - var control = sliderComponent.createObject(testCase) + var control = createTemporaryObject(sliderComponent, testCase) verify(control) compare(control.from, 0) @@ -176,12 +170,10 @@ TestCase { compare(control.second.value, 200) compare(control.first.position, 0.333333) compare(control.second.position, 0.666666) - - control.destroy() } function test_inverted() { - var control = sliderComponent.createObject(testCase, { from: 1.0, to: -1.0 }) + var control = createTemporaryObject(sliderComponent, testCase, { from: 1.0, to: -1.0 }) verify(control) compare(control.from, 1.0) @@ -208,12 +200,10 @@ TestCase { compare(control.first.position, 0.5) compare(control.second.value, 0.0); compare(control.second.position, 0.5); - - control.destroy() } function test_visualPosition() { - var control = sliderComponent.createObject(testCase) + var control = createTemporaryObject(sliderComponent, testCase) verify(control) compare(control.first.value, 0.0) @@ -255,12 +245,10 @@ TestCase { control.LayoutMirroring.enabled = true compare(control.first.visualPosition, 0.75) compare(control.second.visualPosition, 0.0) - - control.destroy() } function test_orientation() { - var control = sliderComponent.createObject(testCase) + var control = createTemporaryObject(sliderComponent, testCase) verify(control) compare(control.orientation, Qt.Horizontal) @@ -268,19 +256,19 @@ TestCase { control.orientation = Qt.Vertical compare(control.orientation, Qt.Vertical) verify(control.width < control.height) - - control.destroy() } function test_mouse_data() { return [ - { tag: "horizontal", orientation: Qt.Horizontal }, - { tag: "vertical", orientation: Qt.Vertical } + { tag: "horizontal", orientation: Qt.Horizontal, live: false }, + { tag: "vertical", orientation: Qt.Vertical, live: false }, + { tag: "horizontal:live", orientation: Qt.Horizontal, live: true }, + { tag: "vertical:live", orientation: Qt.Vertical, live: true } ] } function test_mouse(data) { - var control = sliderComponent.createObject(testCase, { orientation: data.orientation }) + var control = createTemporaryObject(sliderComponent, testCase, { orientation: data.orientation, live: data.live }) verify(control) var firstPressedSpy = signalSpy.createObject(control, {target: control.first, signalName: "pressedChanged"}) @@ -366,7 +354,7 @@ TestCase { compare(firstPressedSpy.count, 5) compare(secondPressedSpy.count, 2) compare(control.first.pressed, true) - compare(control.first.value, 0.0) + compare(control.first.value, data.live ? 0.5 : 0.0) compare(control.first.position, 0.5) compare(control.first.visualPosition, 0.5) compare(control.second.pressed, false) @@ -385,12 +373,188 @@ TestCase { compare(control.second.value, 1.0) compare(control.second.position, 1.0) compare(control.second.visualPosition, horizontal ? 1.0 : 0.0) + } - control.destroy() + function test_touch_data() { + return [ + { tag: "horizontal", orientation: Qt.Horizontal, live: false }, + { tag: "vertical", orientation: Qt.Vertical, live: false }, + { tag: "horizontal:live", orientation: Qt.Horizontal, live: true }, + { tag: "vertical:live", orientation: Qt.Vertical, live: true } + ] + } + + function test_touch(data) { + var control = createTemporaryObject(sliderComponent, testCase, { orientation: data.orientation, live: data.live }) + verify(control) + + var firstPressedSpy = signalSpy.createObject(control, {target: control.first, signalName: "pressedChanged"}) + verify(firstPressedSpy.valid) + + var secondPressedSpy = signalSpy.createObject(control, {target: control.second, signalName: "pressedChanged"}) + verify(secondPressedSpy.valid) + + var touch = touchEvent(control) + touch.press(0, control, control.width * 0.25, control.height * 0.75).commit() + compare(firstPressedSpy.count, 1) + compare(secondPressedSpy.count, 0) + compare(control.first.pressed, true) + compare(control.first.value, 0.0) + compare(control.first.position, 0.0) + compare(control.second.pressed, false) + compare(control.second.value, 1.0) + compare(control.second.position, 1.0) + + touch.release(0, control, control.width * 0.25, control.height * 0.75).commit() + compare(firstPressedSpy.count, 2) + compare(secondPressedSpy.count, 0) + compare(control.first.pressed, false) + compare(control.first.value, 0.0) + compare(control.first.position, 0.0) + compare(control.second.pressed, false) + compare(control.second.value, 1.0) + compare(control.second.position, 1.0) + + touch.press(0, control, control.width * 0.75, control.height * 0.25).commit() + compare(firstPressedSpy.count, 2) + compare(secondPressedSpy.count, 1) + compare(control.first.pressed, false) + compare(control.first.value, 0.0) + compare(control.first.position, 0.0) + compare(control.second.pressed, true) + compare(control.second.value, 1.0) + compare(control.second.position, 1.0) + + touch.release(0, control, control.width * 0.75, control.height * 0.25).commit() + compare(firstPressedSpy.count, 2) + compare(secondPressedSpy.count, 2) + compare(control.first.pressed, false) + compare(control.first.value, 0.0) + compare(control.first.position, 0.0) + compare(control.second.pressed, false) + compare(control.second.value, 1.0) + compare(control.second.position, 1.0) + + touch.press(0, control, 0, control.height).commit() + compare(firstPressedSpy.count, 3) + compare(secondPressedSpy.count, 2) + compare(control.first.pressed, true) + compare(control.first.value, 0.0) + compare(control.first.position, 0.0) + compare(control.second.pressed, false) + compare(control.second.value, 1.0) + compare(control.second.position, 1.0) + + touch.release(0, control, 0, control.height).commit() + compare(firstPressedSpy.count, 4) + compare(secondPressedSpy.count, 2) + compare(control.first.pressed, false) + compare(control.first.value, 0.0) + compare(control.first.position, 0.0) + compare(control.second.pressed, false) + compare(control.second.value, 1.0) + compare(control.second.position, 1.0) + + touch.press(0, control, control.first.handle.x, control.first.handle.y).commit() + compare(firstPressedSpy.count, 5) + compare(secondPressedSpy.count, 2) + compare(control.first.pressed, true) + compare(control.first.value, 0.0) + compare(control.first.position, 0.0) + compare(control.second.pressed, false) + compare(control.second.value, 1.0) + compare(control.second.position, 1.0) + + var horizontal = control.orientation === Qt.Horizontal + var toX = horizontal ? control.width * 0.5 : control.first.handle.x + var toY = horizontal ? control.first.handle.y : control.height * 0.5 + touch.move(0, control, toX, toY).commit() + compare(firstPressedSpy.count, 5) + compare(secondPressedSpy.count, 2) + compare(control.first.pressed, true) + compare(control.first.value, data.live ? 0.5 : 0.0) + compare(control.first.position, 0.5) + compare(control.first.visualPosition, 0.5) + compare(control.second.pressed, false) + compare(control.second.value, 1.0) + compare(control.second.position, 1.0) + compare(control.second.visualPosition, horizontal ? 1.0 : 0.0) + + touch.release(0, control, toX, toY).commit() + compare(firstPressedSpy.count, 6) + compare(secondPressedSpy.count, 2) + compare(control.first.pressed, false) + compare(control.first.value, 0.5) + compare(control.first.position, 0.5) + compare(control.first.visualPosition, 0.5) + compare(control.second.pressed, false) + compare(control.second.value, 1.0) + compare(control.second.position, 1.0) + compare(control.second.visualPosition, horizontal ? 1.0 : 0.0) + } + + function test_multiTouch() { + var control1 = createTemporaryObject(sliderComponent, testCase) + verify(control1) + + // press and move the first handle of the first slider + var touch = touchEvent(control1) + touch.press(0, control1, 0, 0).commit().move(0, control1, control1.width / 2, control1.height / 2).commit() + compare(control1.first.pressed, true) + compare(control1.first.position, 0.5) + compare(control1.second.pressed, false) + compare(control1.second.position, 1.0) + + // press and move the second handle of the first slider + touch.stationary(0).press(1, control1, control1.width, control1.height).commit() + touch.stationary(0).move(1, control1, control1.width / 2, control1.height / 2).commit() + compare(control1.first.pressed, true) + compare(control1.first.position, 0.5) + compare(control1.second.pressed, true) + compare(control1.second.position, 0.5) + + var control2 = createTemporaryObject(sliderComponent, testCase, {y: control1.height}) + verify(control2) + waitForRendering(control2) + + // press and move the first handle of the second slider + touch.stationary(0).stationary(1).press(2, control2, 0, 0).commit() + touch.stationary(0).stationary(1).move(2, control2, control2.width / 2, control2.height / 2).commit() + compare(control1.first.pressed, true) + compare(control1.first.position, 0.5) + compare(control1.second.pressed, true) + compare(control1.second.position, 0.5) + compare(control2.first.pressed, true) + compare(control2.first.position, 0.5) + compare(control2.second.pressed, false) + compare(control2.second.position, 1.0) + + // press and move the second handle of the second slider + touch.stationary(0).stationary(1).stationary(2).press(3, control2, control2.width, control2.height).commit() + touch.stationary(0).stationary(1).stationary(2).move(3, control2, control2.width / 2, control2.height / 2).commit() + compare(control1.first.pressed, true) + compare(control1.first.position, 0.5) + compare(control1.second.pressed, true) + compare(control1.second.position, 0.5) + compare(control2.first.pressed, true) + compare(control2.first.position, 0.5) + compare(control2.second.pressed, true) + compare(control2.second.position, 0.5) + + // release the both handles of the both sliders + touch.release(0, control1).release(1, control1).release(2, control2).release(3, control2).commit() + compare(control1.first.pressed, false) + compare(control1.first.position, 0.5) + compare(control1.second.pressed, false) + compare(control1.second.position, 0.5) + compare(control2.first.pressed, false) + compare(control2.first.position, 0.5) + compare(control2.second.pressed, false) + compare(control2.second.position, 0.5) } function test_overlappingHandles() { - var control = sliderComponent.createObject(testCase, { orientation: data.orientation }) + var control = createTemporaryObject(sliderComponent, testCase, { orientation: data.orientation }) verify(control) // By default, we force the second handle to be after the first in @@ -436,8 +600,6 @@ TestCase { verify(!control.first.pressed) compare(control.first.handle.z, 1) compare(control.second.handle.z, 0) - - control.destroy() } function test_keys_data() { @@ -448,7 +610,7 @@ TestCase { } function test_keys(data) { - var control = sliderComponent.createObject(testCase, { orientation: data.orientation }) + var control = createTemporaryObject(sliderComponent, testCase, { orientation: data.orientation }) verify(control) var pressedCount = 0 @@ -522,15 +684,13 @@ TestCase { compare(control.second.pressed, false) compare(secondPressedSpy.count, ++pressedCount) } - - control.destroy() } function test_padding() { // test with "unbalanced" paddings (left padding != right padding) to ensure // that the slider position calculation is done taking padding into account // ==> the position is _not_ 0.5 in the middle of the control - var control = sliderComponent.createObject(testCase, { leftPadding: 10, rightPadding: 20 }) + var control = createTemporaryObject(sliderComponent, testCase, { leftPadding: 10, rightPadding: 20 }) verify(control) var firstPressedSpy = signalSpy.createObject(control, {target: control.first, signalName: "pressedChanged"}) @@ -595,8 +755,6 @@ TestCase { compare(control.first.value, 0.5) compare(control.first.position, 0.5) compare(control.first.visualPosition, 0.5) - - control.destroy() } function test_snapMode_data() { @@ -613,8 +771,12 @@ TestCase { ] } - function test_snapMode(data) { - var control = sliderComponent.createObject(testCase, {snapMode: data.snapMode, from: data.from, to: data.to, stepSize: 0.2}) + function test_snapMode_mouse_data() { + return test_snapMode_data() + } + + function test_snapMode_mouse(data) { + var control = createTemporaryObject(sliderComponent, testCase, {snapMode: data.snapMode, from: data.from, to: data.to, stepSize: 0.2}) verify(control) control.first.value = 0 @@ -638,12 +800,42 @@ TestCase { compare(control.first.pressed, false) verify(sliderCompare(control.first.value, data.values[2])) verify(sliderCompare(control.first.position, data.positions[2])) + } + + function test_snapMode_touch_data() { + return test_snapMode_data() + } + + function test_snapMode_touch(data) { + var control = createTemporaryObject(sliderComponent, testCase, {snapMode: data.snapMode, from: data.from, to: data.to, stepSize: 0.2}) + verify(control) + + control.first.value = 0 + control.second.value = data.to - control.destroy() + function sliderCompare(left, right) { + return Math.abs(left - right) < 0.05 + } + + var touch = touchEvent(control) + touch.press(0, control, control.first.handle.x, control.first.handle.y).commit() + compare(control.first.pressed, true) + compare(control.first.value, data.values[0]) + compare(control.first.position, data.positions[0]) + + touch.move(0, control, control.leftPadding + 0.15 * (control.availableWidth + control.first.handle.width / 2)).commit() + compare(control.first.pressed, true) + verify(sliderCompare(control.first.value, data.values[1])) + verify(sliderCompare(control.first.position, data.positions[1])) + + touch.release(0, control, control.leftPadding + 0.15 * (control.availableWidth + control.first.handle.width / 2)).commit() + compare(control.first.pressed, false) + verify(sliderCompare(control.first.value, data.values[2])) + verify(sliderCompare(control.first.position, data.positions[2])) } function test_focus() { - var control = sliderComponent.createObject(testCase) + var control = createTemporaryObject(sliderComponent, testCase) verify(control) waitForRendering(control) @@ -672,8 +864,6 @@ TestCase { compare(control.activeFocus, true) compare(control.first.handle.activeFocus, false) compare(control.second.handle.activeFocus, true) - - control.destroy() } function test_hover_data() { @@ -686,7 +876,7 @@ TestCase { } function test_hover(data) { - var control = sliderComponent.createObject(testCase, {hoverEnabled: data.hoverEnabled}) + var control = createTemporaryObject(sliderComponent, testCase, {hoverEnabled: data.hoverEnabled}) verify(control) var node = control[data.node] @@ -699,7 +889,5 @@ TestCase { mouseMove(control, node.handle.x - 1, node.handle.y - 1) compare(node.hovered, false) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_roundbutton.qml b/tests/auto/controls/data/tst_roundbutton.qml index e3844523..4f90eea1 100644 --- a/tests/auto/controls/data/tst_roundbutton.qml +++ b/tests/auto/controls/data/tst_roundbutton.qml @@ -56,7 +56,7 @@ TestCase { } function test_radius() { - var control = roundButton.createObject(testCase); + var control = createTemporaryObject(roundButton, testCase); verify(control); var implicitRadius = control.radius; @@ -73,7 +73,5 @@ TestCase { control.width = 10; compare(control.radius, 5); - - control.destroy(); } } diff --git a/tests/auto/controls/data/tst_scrollbar.qml b/tests/auto/controls/data/tst_scrollbar.qml index 92fe8496..8727b6da 100644 --- a/tests/auto/controls/data/tst_scrollbar.qml +++ b/tests/auto/controls/data/tst_scrollbar.qml @@ -40,7 +40,7 @@ import QtQuick 2.2 import QtTest 1.0 -import QtQuick.Controls 2.1 +import QtQuick.Controls 2.2 TestCase { id: testCase @@ -73,7 +73,7 @@ TestCase { } function test_attach() { - var container = flickable.createObject(testCase) + var container = createTemporaryObject(flickable, testCase) verify(container) waitForRendering(container) @@ -105,7 +105,7 @@ TestCase { container.width += 10 compare(vertical.x, 123) - var horizontal = scrollBar.createObject() + var horizontal = createTemporaryObject(scrollBar, null) verify(!horizontal.parent) compare(horizontal.size, 0.0) compare(horizontal.position, 0.0) @@ -170,8 +170,6 @@ TestCase { container.width += 10 compare(horizontal.x, oldX - 10) compare(horizontal.width, oldWidth) - - container.destroy() } function test_mouse_data() { @@ -182,7 +180,7 @@ TestCase { } function test_mouse(data) { - var control = scrollBar.createObject(testCase, data.properties) + var control = createTemporaryObject(scrollBar, testCase, data.properties) verify(control) var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) @@ -227,8 +225,6 @@ TestCase { compare(pressedSpy.count, 4) compare(control.pressed, false) compare(control.position, 0.25) - - control.destroy() } function test_increase_decrease_data() { @@ -241,7 +237,7 @@ TestCase { } function test_increase_decrease(data) { - var control = scrollBar.createObject(testCase, {position: 0.5, active: data.active}) + var control = createTemporaryObject(scrollBar, testCase, {position: 0.5, active: data.active}) verify(control) if (data.increase) { @@ -252,8 +248,6 @@ TestCase { compare(control.position, 0.4) } compare(control.active, data.active) - - control.destroy() } function test_stepSize_data() { @@ -265,7 +259,7 @@ TestCase { } function test_stepSize(data) { - var control = scrollBar.createObject(testCase, {stepSize: data.stepSize}) + var control = createTemporaryObject(scrollBar, testCase, {stepSize: data.stepSize}) verify(control) compare(control.stepSize, data.stepSize) @@ -290,8 +284,6 @@ TestCase { } control.decrease() compare(control.position, 0.0) - - control.destroy() } function test_padding_data() { @@ -302,14 +294,12 @@ TestCase { } function test_padding(data) { - var control = scrollBar.createObject(testCase, data.properties) + var control = createTemporaryObject(scrollBar, testCase, data.properties) mousePress(control, control.leftPadding + control.availableWidth * 0.5, control.topPadding + control.availableHeight * 0.5, Qt.LeftButton) mouseRelease(control, control.leftPadding + control.availableWidth * 0.5, control.topPadding + control.availableHeight * 0.5, Qt.LeftButton) compare(control.position, 0.5) - - control.destroy() } function test_warning() { @@ -318,7 +308,7 @@ TestCase { } function test_mirrored() { - var container = flickable.createObject(testCase) + var container = createTemporaryObject(flickable, testCase) verify(container) waitForRendering(container) @@ -326,8 +316,6 @@ TestCase { compare(container.ScrollBar.vertical.x, container.width - container.ScrollBar.vertical.width) container.ScrollBar.vertical.locale = Qt.locale("ar_EG") compare(container.ScrollBar.vertical.x, 0) - - container.destroy() } function test_hover_data() { @@ -338,7 +326,7 @@ TestCase { } function test_hover(data) { - var control = scrollBar.createObject(testCase, {hoverEnabled: data.hoverEnabled}) + var control = createTemporaryObject(scrollBar, testCase, {hoverEnabled: data.hoverEnabled}) verify(control) compare(control.hovered, false) @@ -350,7 +338,76 @@ TestCase { mouseMove(control, -1, -1) compare(control.hovered, false) compare(control.active, false) + } + + function test_snapMode_data() { + return [ + { tag: "NoSnap", snapMode: ScrollBar.NoSnap, stepSize: 0.1, size: 0.2, width: 100, steps: 80 }, /* 0.8*100 */ + { tag: "NoSnap2", snapMode: ScrollBar.NoSnap, stepSize: 0.2, size: 0.1, width: 200, steps: 180 }, /* 0.9*200 */ + + { tag: "SnapAlways", snapMode: ScrollBar.SnapAlways, stepSize: 0.1, size: 0.2, width: 100, steps: 10 }, + { tag: "SnapAlways2", snapMode: ScrollBar.SnapAlways, stepSize: 0.2, size: 0.1, width: 200, steps: 5 }, + + { tag: "SnapOnRelease", snapMode: ScrollBar.SnapOnRelease, stepSize: 0.1, size: 0.2, width: 100, steps: 80 }, /* 0.8*100 */ + { tag: "SnapOnRelease2", snapMode: ScrollBar.SnapOnRelease, stepSize: 0.2, size: 0.1, width: 200, steps: 180 }, /* 0.9*200 */ + ] + } + + function test_snapMode_mouse_data() { + return test_snapMode_data() + } + + function test_snapMode_mouse(data) { + var control = createTemporaryObject(scrollBar, testCase, {snapMode: data.snapMode, orientation: Qt.Horizontal, stepSize: data.stepSize, size: data.size, width: data.width}) + verify(control) + + function snappedPosition(pos) { + var effectiveStep = control.stepSize * (1.0 - control.size) + return Math.round(pos / effectiveStep) * effectiveStep + } + + function boundPosition(pos) { + return Math.max(0, Math.min(pos, 1.0 - control.size)) + } + + mousePress(control, 0, 0) + compare(control.position, 0) + + mouseMove(control, control.width * 0.3, 0) + var expectedMovePos = 0.3 + if (control.snapMode === ScrollBar.SnapAlways) { + expectedMovePos = snappedPosition(expectedMovePos) + verify(expectedMovePos !== 0.3) + } + compare(control.position, expectedMovePos) + + mouseRelease(control, control.width * 0.75, 0) + var expectedReleasePos = 0.75 + if (control.snapMode !== ScrollBar.NoSnap) { + expectedReleasePos = snappedPosition(expectedReleasePos) + verify(expectedReleasePos !== 0.75) + } + compare(control.position, expectedReleasePos) + + control.position = 0 + mousePress(control, 0, 0) + + var steps = 0 + var prevPos = 0 + + for (var x = 0; x < control.width; ++x) { + mouseMove(control, x, 0) + expectedMovePos = boundPosition(x / control.width) + if (control.snapMode === ScrollBar.SnapAlways) + expectedMovePos = snappedPosition(expectedMovePos) + compare(control.position, expectedMovePos) + + if (control.position !== prevPos) + ++steps + prevPos = control.position + } + compare(steps, data.steps) - control.destroy() + mouseRelease(control, control.width - 1, 0) } } diff --git a/tests/auto/controls/data/tst_scrollindicator.qml b/tests/auto/controls/data/tst_scrollindicator.qml index 1f86311a..cf0c9a27 100644 --- a/tests/auto/controls/data/tst_scrollindicator.qml +++ b/tests/auto/controls/data/tst_scrollindicator.qml @@ -68,11 +68,11 @@ TestCase { } function test_attach() { - var container = flickable.createObject(testCase) + var container = createTemporaryObject(flickable, testCase) verify(container) waitForRendering(container) - var vertical = scrollIndicator.createObject() + var vertical = createTemporaryObject(scrollIndicator, null) verify(!vertical.parent) compare(vertical.size, 0.0) compare(vertical.position, 0.0) @@ -100,7 +100,7 @@ TestCase { container.width += 10 compare(vertical.x, 123) - var horizontal = scrollIndicator.createObject() + var horizontal = createTemporaryObject(scrollIndicator, null) verify(!horizontal.parent) compare(horizontal.size, 0.0) compare(horizontal.position, 0.0) @@ -165,8 +165,6 @@ TestCase { container.width += 10 compare(horizontal.x, oldX - 10) compare(horizontal.width, oldWidth) - - container.destroy() } function test_warning() { @@ -175,7 +173,7 @@ TestCase { } function test_overshoot() { - var container = flickable.createObject(testCase) + var container = createTemporaryObject(flickable, testCase) verify(container) waitForRendering(container) @@ -204,7 +202,5 @@ TestCase { horizontal.position = 0.8 compare(horizontal.contentItem.x, horizontal.leftPadding + 0.8 * horizontal.availableWidth) compare(horizontal.contentItem.width, 0.2 * horizontal.availableWidth) - - container.destroy() } } diff --git a/tests/auto/controls/data/tst_slider.qml b/tests/auto/controls/data/tst_slider.qml index 92560001..1dec038e 100644 --- a/tests/auto/controls/data/tst_slider.qml +++ b/tests/auto/controls/data/tst_slider.qml @@ -40,7 +40,7 @@ import QtQuick 2.2 import QtTest 1.0 -import QtQuick.Controls 2.1 +import QtQuick.Controls 2.2 TestCase { id: testCase @@ -61,18 +61,16 @@ TestCase { } function test_defaults() { - var control = slider.createObject(testCase) + var control = createTemporaryObject(slider, testCase) verify(control) compare(control.stepSize, 0) compare(control.snapMode, Slider.NoSnap) compare(control.orientation, Qt.Horizontal) - - control.destroy() } function test_value() { - var control = slider.createObject(testCase) + var control = createTemporaryObject(slider, testCase) verify(control) compare(control.value, 0.0) @@ -84,12 +82,10 @@ TestCase { compare(control.value, 0.0) control.value = 2.0 compare(control.value, 1.0) - - control.destroy() } function test_range() { - var control = slider.createObject(testCase, {from: 0, to: 100, value: 50}) + var control = createTemporaryObject(slider, testCase, {from: 0, to: 100, value: 50}) verify(control) compare(control.from, 0) @@ -118,12 +114,10 @@ TestCase { control.value = 50 compare(control.value, 50) compare(control.position, 0.5) - - control.destroy() } function test_inverted() { - var control = slider.createObject(testCase, {from: 1.0, to: -1.0}) + var control = createTemporaryObject(slider, testCase, {from: 1.0, to: -1.0}) verify(control) compare(control.from, 1.0) @@ -142,12 +136,10 @@ TestCase { control.value = 0.0 compare(control.value, 0.0) compare(control.position, 0.5) - - control.destroy() } function test_position() { - var control = slider.createObject(testCase) + var control = createTemporaryObject(slider, testCase) verify(control) compare(control.value, 0.0) @@ -160,12 +152,10 @@ TestCase { control.value = 0.75 compare(control.value, 0.75) compare(control.position, 0.75) - - control.destroy() } function test_visualPosition() { - var control = slider.createObject(testCase) + var control = createTemporaryObject(slider, testCase) verify(control) compare(control.value, 0.0) @@ -194,12 +184,10 @@ TestCase { // LayoutMirroring control.LayoutMirroring.enabled = true compare(control.visualPosition, 0.75) - - control.destroy() } function test_orientation() { - var control = slider.createObject(testCase) + var control = createTemporaryObject(slider, testCase) verify(control) compare(control.orientation, Qt.Horizontal) @@ -207,70 +195,84 @@ TestCase { control.orientation = Qt.Vertical compare(control.orientation, Qt.Vertical) verify(control.width < control.height) - - control.destroy() } function test_mouse_data() { return [ - { tag: "horizontal", orientation: Qt.Horizontal }, - { tag: "vertical", orientation: Qt.Vertical } + { tag: "horizontal", orientation: Qt.Horizontal, live: false }, + { tag: "vertical", orientation: Qt.Vertical, live: false }, + { tag: "horizontal:live", orientation: Qt.Horizontal, live: true }, + { tag: "vertical:live", orientation: Qt.Vertical, live: true } ] } function test_mouse(data) { - var control = slider.createObject(testCase, {orientation: data.orientation}) + var control = createTemporaryObject(slider, testCase, {orientation: data.orientation, live: data.live}) verify(control) + var pressedCount = 0 + var movedCount = 0 + var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) verify(pressedSpy.valid) + var movedSpy = signalSpy.createObject(control, {target: control, signalName: "moved"}) + verify(movedSpy.valid) + mousePress(control, 0, 0, Qt.LeftButton) - compare(pressedSpy.count, 1) + compare(pressedSpy.count, ++pressedCount) + compare(movedSpy.count, movedCount) compare(control.pressed, true) compare(control.value, 0.0) compare(control.position, 0.0) // mininum on the left in horizontal vs. at the bottom in vertical mouseMove(control, -control.width, 2 * control.height, 0, Qt.LeftButton) - compare(pressedSpy.count, 1) + compare(pressedSpy.count, pressedCount) + compare(movedSpy.count, movedCount) compare(control.pressed, true) compare(control.value, 0.0) compare(control.position, 0.0) mouseMove(control, control.width * 0.5, control.height * 0.5, 0, Qt.LeftButton) - compare(pressedSpy.count, 1) + compare(pressedSpy.count, pressedCount) + compare(movedSpy.count, ++movedCount) compare(control.pressed, true) - compare(control.value, 0.0) - verify(control.position, 0.5) + compare(control.value, data.live ? 0.5 : 0.0) + compare(control.position, 0.5) mouseRelease(control, control.width * 0.5, control.height * 0.5, Qt.LeftButton) - compare(pressedSpy.count, 2) + compare(pressedSpy.count, ++pressedCount) + compare(movedSpy.count, movedCount) compare(control.pressed, false) compare(control.value, 0.5) compare(control.position, 0.5) mousePress(control, control.width, control.height, Qt.LeftButton) - compare(pressedSpy.count, 3) + compare(pressedSpy.count, ++pressedCount) + compare(movedSpy.count, movedCount) compare(control.pressed, true) compare(control.value, 0.5) compare(control.position, 0.5) // maximum on the right in horizontal vs. at the top in vertical mouseMove(control, control.width * 2, -control.height, 0, Qt.LeftButton) - compare(pressedSpy.count, 3) + compare(pressedSpy.count, pressedCount) + compare(movedSpy.count, ++movedCount) compare(control.pressed, true) - compare(control.value, 0.5) + compare(control.value, data.live ? 1.0 : 0.5) compare(control.position, 1.0) mouseMove(control, control.width * 0.75, control.height * 0.25, 0, Qt.LeftButton) - compare(pressedSpy.count, 3) + compare(pressedSpy.count, pressedCount) + compare(movedSpy.count, ++movedCount) compare(control.pressed, true) - compare(control.value, 0.5) + compare(control.value, data.live ? control.position : 0.5) verify(control.position >= 0.75) mouseRelease(control, control.width * 0.25, control.height * 0.75, Qt.LeftButton) - compare(pressedSpy.count, 4) + compare(pressedSpy.count, ++pressedCount) + compare(movedSpy.count, ++movedCount) compare(control.pressed, false) compare(control.value, control.position) verify(control.value <= 0.25 && control.value >= 0.0) @@ -278,11 +280,188 @@ TestCase { // QTBUG-53846 mouseClick(control, control.width * 0.5, control.height * 0.5, Qt.LeftButton) - compare(pressedSpy.count, 6) + compare(movedSpy.count, ++movedCount) + compare(pressedSpy.count, pressedCount += 2) + compare(control.value, 0.5) + compare(control.position, 0.5) + } + + function test_touch_data() { + return [ + { tag: "horizontal", orientation: Qt.Horizontal, live: false }, + { tag: "vertical", orientation: Qt.Vertical, live: false }, + { tag: "horizontal:live", orientation: Qt.Horizontal, live: true }, + { tag: "vertical:live", orientation: Qt.Vertical, live: true } + ] + } + + function test_touch(data) { + var control = createTemporaryObject(slider, testCase, {orientation: data.orientation, live: data.live}) + verify(control) + + var pressedCount = 0 + var movedCount = 0 + + var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) + verify(pressedSpy.valid) + + var movedSpy = signalSpy.createObject(control, {target: control, signalName: "moved"}) + verify(movedSpy.valid) + + var touch = touchEvent(control) + touch.press(0, control, 0, 0).commit() + compare(pressedSpy.count, ++pressedCount) + compare(movedSpy.count, movedCount) + compare(control.pressed, true) + compare(control.value, 0.0) + compare(control.position, 0.0) + + // mininum on the left in horizontal vs. at the bottom in vertical + touch.move(0, control, -control.width, 2 * control.height, 0).commit() + compare(pressedSpy.count, pressedCount) + compare(movedSpy.count, movedCount) + compare(control.pressed, true) + compare(control.value, 0.0) + compare(control.position, 0.0) + + touch.move(0, control, control.width * 0.5, control.height * 0.5, 0).commit() + compare(pressedSpy.count, pressedCount) + compare(movedSpy.count, ++movedCount) + compare(control.pressed, true) + compare(control.value, data.live ? 0.5 : 0.0) + compare(control.position, 0.5) + + touch.release(0, control, control.width * 0.5, control.height * 0.5).commit() + compare(pressedSpy.count, ++pressedCount) + compare(movedSpy.count, movedCount) + compare(control.pressed, false) + compare(control.value, 0.5) + compare(control.position, 0.5) + + touch.press(0, control, control.width, control.height).commit() + compare(pressedSpy.count, ++pressedCount) + compare(movedSpy.count, movedCount) + compare(control.pressed, true) + compare(control.value, 0.5) + compare(control.position, 0.5) + + // maximum on the right in horizontal vs. at the top in vertical + touch.move(0, control, control.width * 2, -control.height, 0).commit() + compare(pressedSpy.count, pressedCount) + compare(movedSpy.count, ++movedCount) + compare(control.pressed, true) + compare(control.value, data.live ? 1.0 : 0.5) + compare(control.position, 1.0) + + touch.move(0, control, control.width * 0.75, control.height * 0.25, 0).commit() + compare(pressedSpy.count, pressedCount) + compare(movedSpy.count, ++movedCount) + compare(control.pressed, true) + compare(control.value, data.live ? control.position : 0.5) + verify(control.position >= 0.75) + + touch.release(0, control, control.width * 0.25, control.height * 0.75).commit() + compare(pressedSpy.count, ++pressedCount) + compare(movedSpy.count, ++movedCount) + compare(control.pressed, false) + compare(control.value, control.position) + verify(control.value <= 0.25 && control.value >= 0.0) + verify(control.position <= 0.25 && control.position >= 0.0) + + // QTBUG-53846 + touch.press(0, control).commit().release(0, control).commit() + compare(movedSpy.count, ++movedCount) + compare(pressedSpy.count, pressedCount += 2) compare(control.value, 0.5) compare(control.position, 0.5) + } + + function test_multiTouch() { + var control1 = createTemporaryObject(slider, testCase) + verify(control1) + + var pressedCount1 = 0 + var movedCount1 = 0 + + var pressedSpy1 = signalSpy.createObject(control1, {target: control1, signalName: "pressedChanged"}) + verify(pressedSpy1.valid) + + var movedSpy1 = signalSpy.createObject(control1, {target: control1, signalName: "moved"}) + verify(movedSpy1.valid) + + var touch = touchEvent(control1) + touch.press(0, control1, 0, 0).commit().move(0, control1, control1.width, control1.height).commit() + + compare(pressedSpy1.count, ++pressedCount1) + compare(movedSpy1.count, ++movedCount1) + compare(control1.pressed, true) + compare(control1.position, 1.0) + + // second touch point on the same control is ignored + touch.stationary(0).press(1, control1, 0, 0).commit() + touch.stationary(0).move(1, control1).commit() + touch.stationary(0).release(1).commit() + + compare(pressedSpy1.count, pressedCount1) + compare(movedSpy1.count, movedCount1) + compare(control1.pressed, true) + compare(control1.position, 1.0) + + var control2 = createTemporaryObject(slider, testCase, {y: control1.height}) + verify(control2) + waitForRendering(control2) + + var pressedCount2 = 0 + var movedCount2 = 0 + + var pressedSpy2 = signalSpy.createObject(control2, {target: control2, signalName: "pressedChanged"}) + verify(pressedSpy2.valid) + + var movedSpy2 = signalSpy.createObject(control2, {target: control2, signalName: "moved"}) + verify(movedSpy2.valid) + + // press the second slider + touch.stationary(0).press(2, control2, 0, 0).commit() + + compare(pressedSpy2.count, ++pressedCount2) + compare(movedSpy2.count, movedCount2) + compare(control2.pressed, true) + compare(control2.position, 0.0) + + compare(pressedSpy1.count, pressedCount1) + compare(movedSpy1.count, movedCount1) + compare(control1.pressed, true) + compare(control1.position, 1.0) + + // move both sliders + touch.move(0, control1).move(2, control2).commit() + + compare(pressedSpy2.count, pressedCount2) + compare(movedSpy2.count, ++movedCount2) + compare(control2.pressed, true) + compare(control2.position, 0.5) + compare(control2.value, 0.0) + + compare(pressedSpy1.count, pressedCount1) + compare(movedSpy1.count, ++movedCount1) + compare(control1.pressed, true) + compare(control1.position, 0.5) + compare(control1.value, 0.0) + + // release both sliders + touch.release(0, control1).release(2, control2).commit() + + compare(pressedSpy2.count, ++pressedCount2) + compare(movedSpy2.count, movedCount2) + compare(control2.pressed, false) + compare(control2.position, 0.5) + compare(control2.value, 0.5) - control.destroy() + compare(pressedSpy1.count, ++pressedCount1) + compare(movedSpy1.count, movedCount1) + compare(control1.pressed, false) + compare(control1.position, 0.5) + compare(control1.value, 0.5) } function test_keys_data() { @@ -293,23 +472,31 @@ TestCase { } function test_keys(data) { - var control = slider.createObject(testCase, {orientation: data.orientation}) + var control = createTemporaryObject(slider, testCase, {orientation: data.orientation}) verify(control) var pressedCount = 0 + var movedCount = 0 var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) verify(pressedSpy.valid) + var movedSpy = signalSpy.createObject(control, {target: control, signalName: "moved"}) + verify(movedSpy.valid) + control.forceActiveFocus() verify(control.activeFocus) + var oldValue = 0.0 control.value = 0.5 for (var d1 = 1; d1 <= 10; ++d1) { + oldValue = control.value keyPress(data.decrease) compare(control.pressed, true) compare(pressedSpy.count, ++pressedCount) + if (oldValue !== control.value) + compare(movedSpy.count, ++movedCount) compare(control.value, Math.max(0.0, 0.5 - d1 * 0.1)) compare(control.value, control.position) @@ -317,12 +504,16 @@ TestCase { keyRelease(data.decrease) compare(control.pressed, false) compare(pressedSpy.count, ++pressedCount) + compare(movedSpy.count, movedCount) } for (var i1 = 1; i1 <= 20; ++i1) { + oldValue = control.value keyPress(data.increase) compare(control.pressed, true) compare(pressedSpy.count, ++pressedCount) + if (oldValue !== control.value) + compare(movedSpy.count, ++movedCount) compare(control.value, Math.min(1.0, 0.0 + i1 * 0.1)) compare(control.value, control.position) @@ -330,14 +521,18 @@ TestCase { keyRelease(data.increase) compare(control.pressed, false) compare(pressedSpy.count, ++pressedCount) + compare(movedSpy.count, movedCount) } control.stepSize = 0.25 for (var d2 = 1; d2 <= 10; ++d2) { + oldValue = control.value keyPress(data.decrease) compare(control.pressed, true) compare(pressedSpy.count, ++pressedCount) + if (oldValue !== control.value) + compare(movedSpy.count, ++movedCount) compare(control.value, Math.max(0.0, 1.0 - d2 * 0.25)) compare(control.value, control.position) @@ -345,12 +540,16 @@ TestCase { keyRelease(data.decrease) compare(control.pressed, false) compare(pressedSpy.count, ++pressedCount) + compare(movedSpy.count, movedCount) } for (var i2 = 1; i2 <= 10; ++i2) { + oldValue = control.value keyPress(data.increase) compare(control.pressed, true) compare(pressedSpy.count, ++pressedCount) + if (oldValue !== control.value) + compare(movedSpy.count, ++movedCount) compare(control.value, Math.min(1.0, 0.0 + i2 * 0.25)) compare(control.value, control.position) @@ -358,16 +557,15 @@ TestCase { keyRelease(data.increase) compare(control.pressed, false) compare(pressedSpy.count, ++pressedCount) + compare(movedSpy.count, movedCount) } - - control.destroy() } function test_padding() { // test with "unbalanced" paddings (left padding != right padding) to ensure // that the slider position calculation is done taking padding into account // ==> the position is _not_ 0.5 in the middle of the control - var control = slider.createObject(testCase, {leftPadding: 10, rightPadding: 20}) + var control = createTemporaryObject(slider, testCase, {leftPadding: 10, rightPadding: 20}) verify(control) var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) @@ -432,8 +630,6 @@ TestCase { compare(control.value, 0.5) compare(control.position, 0.5) compare(control.visualPosition, 0.5) - - control.destroy() } function test_snapMode_data() { @@ -450,8 +646,12 @@ TestCase { ] } - function test_snapMode(data) { - var control = slider.createObject(testCase, {snapMode: data.snapMode, from: data.from, to: data.to, stepSize: 0.2}) + function test_snapMode_mouse_data() { + return test_snapMode_data() + } + + function test_snapMode_mouse(data) { + var control = createTemporaryObject(slider, testCase, {snapMode: data.snapMode, from: data.from, to: data.to, stepSize: 0.2}) verify(control) function sliderCompare(left, right) { @@ -470,8 +670,33 @@ TestCase { mouseRelease(control, control.leftPadding + 0.15 * (control.availableWidth + control.handle.width / 2)) verify(sliderCompare(control.value, data.values[2])) verify(sliderCompare(control.position, data.positions[2])) + } + + function test_snapMode_touch_data() { + return test_snapMode_data() + } + + function test_snapMode_touch(data) { + var control = createTemporaryObject(slider, testCase, {snapMode: data.snapMode, from: data.from, to: data.to, stepSize: 0.2}) + verify(control) + + function sliderCompare(left, right) { + return Math.abs(left - right) < 0.05 + } + + var touch = touchEvent(control) + touch.press(0, control, control.leftPadding).commit() + compare(control.value, data.values[0]) + compare(control.position, data.positions[0]) + + touch.move(0, control, control.leftPadding + 0.15 * (control.availableWidth + control.handle.width / 2)).commit() + + verify(sliderCompare(control.value, data.values[1])) + verify(sliderCompare(control.position, data.positions[1])) - control.destroy() + touch.release(0, control, control.leftPadding + 0.15 * (control.availableWidth + control.handle.width / 2)).commit() + verify(sliderCompare(control.value, data.values[2])) + verify(sliderCompare(control.position, data.positions[2])) } function test_wheel_data() { @@ -482,24 +707,37 @@ TestCase { } function test_wheel(data) { - var control = slider.createObject(testCase, {wheelEnabled: true, orientation: data.orientation}) + var control = createTemporaryObject(slider, testCase, {wheelEnabled: true, orientation: data.orientation}) verify(control) + var movedCount = 0 + var movedSpy = signalSpy.createObject(control, {target: control, signalName: "moved"}) + verify(movedSpy.valid) + compare(control.value, 0.0) mouseWheel(control, control.width / 2, control.height / 2, data.dx, data.dy) + compare(movedSpy.count, ++movedCount) compare(control.value, 0.1) compare(control.position, 0.1) control.stepSize = 0.2 mouseWheel(control, control.width / 2, control.height / 2, data.dx, data.dy) + compare(movedSpy.count, ++movedCount) compare(control.value, 0.3) compare(control.position, 0.3) control.stepSize = 10.0 mouseWheel(control, control.width / 2, control.height / 2, -data.dx, -data.dy) + compare(movedSpy.count, ++movedCount) + compare(control.value, 0.0) + compare(control.position, 0.0) + + // no change + mouseWheel(control, control.width / 2, control.height / 2, -data.dx, -data.dy) + compare(movedSpy.count, movedCount) compare(control.value, 0.0) compare(control.position, 0.0) @@ -507,18 +745,19 @@ TestCase { control.stepSize = 5.0 mouseWheel(control, control.width / 2, control.height / 2, data.dx, data.dy) + compare(movedSpy.count, ++movedCount) compare(control.value, 5.0) compare(control.position, 0.5) mouseWheel(control, control.width / 2, control.height / 2, 0.5 * data.dx, 0.5 * data.dy) + compare(movedSpy.count, ++movedCount) compare(control.value, 7.5) compare(control.position, 0.75) mouseWheel(control, control.width / 2, control.height / 2, -data.dx, -data.dy) + compare(movedSpy.count, ++movedCount) compare(control.value, 2.5) compare(control.position, 0.25) - - control.destroy() } function test_valueAt_data() { @@ -530,14 +769,12 @@ TestCase { } function test_valueAt(data) { - var control = slider.createObject(testCase, {from: data.from, to: data.to}) + var control = createTemporaryObject(slider, testCase, {from: data.from, to: data.to}) verify(control) compare(control.valueAt(0.0), data.values[0]) compare(control.valueAt(0.2), data.values[1]) compare(control.valueAt(0.5), data.values[2]) compare(control.valueAt(1.0), data.values[3]) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_spinbox.qml b/tests/auto/controls/data/tst_spinbox.qml index 06426f40..850dd014 100644 --- a/tests/auto/controls/data/tst_spinbox.qml +++ b/tests/auto/controls/data/tst_spinbox.qml @@ -61,7 +61,7 @@ TestCase { } function test_defaults() { - var control = spinBox.createObject(testCase) + var control = createTemporaryObject(spinBox, testCase) verify(control) compare(control.from, 0) @@ -73,12 +73,10 @@ TestCase { compare(control.up.indicator.enabled, true) compare(control.down.pressed, false) compare(control.down.indicator.enabled, false) - - control.destroy() } function test_value() { - var control = spinBox.createObject(testCase) + var control = createTemporaryObject(spinBox, testCase) verify(control) compare(control.value, 0) @@ -90,12 +88,10 @@ TestCase { compare(control.value, 0) control.value = 100 compare(control.value, 99) - - control.destroy() } function test_range() { - var control = spinBox.createObject(testCase, {from: 0, to: 100, value: 50}) + var control = createTemporaryObject(spinBox, testCase, {from: 0, to: 100, value: 50}) verify(control) compare(control.from, 0) @@ -135,12 +131,10 @@ TestCase { compare(control.value, 40) compare(control.up.indicator.enabled, false) compare(control.down.indicator.enabled, true) - - control.destroy() } function test_inverted() { - var control = spinBox.createObject(testCase, {from: 100, to: -100}) + var control = createTemporaryObject(spinBox, testCase, {from: 100, to: -100}) verify(control) compare(control.from, 100) @@ -163,12 +157,10 @@ TestCase { compare(control.value, 0) compare(control.up.indicator.enabled, true) compare(control.down.indicator.enabled, true) - - control.destroy() } function test_mouse() { - var control = spinBox.createObject(testCase, {stepSize: 50}) + var control = createTemporaryObject(spinBox, testCase, {stepSize: 50}) verify(control) var upPressedSpy = signalSpy.createObject(control, {target: control.up, signalName: "pressedChanged"}) @@ -177,12 +169,16 @@ TestCase { var downPressedSpy = signalSpy.createObject(control, {target: control.down, signalName: "pressedChanged"}) verify(downPressedSpy.valid) + var valueModifiedSpy = signalSpy.createObject(control, {target: control, signalName: "valueModified"}) + verify(valueModifiedSpy.valid) + mousePress(control.up.indicator) compare(upPressedSpy.count, 1) compare(control.up.pressed, true) compare(downPressedSpy.count, 0) compare(control.down.pressed, false) compare(control.value, 0) + compare(valueModifiedSpy.count, 0) mouseRelease(control.up.indicator) compare(upPressedSpy.count, 2) @@ -190,6 +186,7 @@ TestCase { compare(downPressedSpy.count, 0) compare(control.down.pressed, false) compare(control.value, 50) + compare(valueModifiedSpy.count, 1) // Disable the up button and try again. control.value = control.to @@ -201,6 +198,7 @@ TestCase { compare(downPressedSpy.count, 0) compare(control.down.pressed, false) compare(control.value, control.to) + compare(valueModifiedSpy.count, 1) mouseRelease(control.up.indicator) compare(upPressedSpy.count, 2) @@ -208,6 +206,7 @@ TestCase { compare(downPressedSpy.count, 0) compare(control.down.pressed, false) compare(control.value, control.to) + compare(valueModifiedSpy.count, 1) control.value = 50; mousePress(control.down.indicator) @@ -216,6 +215,7 @@ TestCase { compare(upPressedSpy.count, 2) compare(control.up.pressed, false) compare(control.value, 50) + compare(valueModifiedSpy.count, 1) mouseRelease(control.down.indicator) compare(downPressedSpy.count, 2) @@ -223,6 +223,7 @@ TestCase { compare(upPressedSpy.count, 2) compare(control.up.pressed, false) compare(control.value, 0) + compare(valueModifiedSpy.count, 2) // Disable the down button and try again. control.value = control.from @@ -234,6 +235,7 @@ TestCase { compare(upPressedSpy.count, 2) compare(control.up.pressed, false) compare(control.value, control.from) + compare(valueModifiedSpy.count, 2) mouseRelease(control.down.indicator) compare(downPressedSpy.count, 2) @@ -241,16 +243,16 @@ TestCase { compare(upPressedSpy.count, 2) compare(control.up.pressed, false) compare(control.value, control.from) - - control.destroy() + compare(valueModifiedSpy.count, 2) } function test_keys() { - var control = spinBox.createObject(testCase) + var control = createTemporaryObject(spinBox, testCase) verify(control) var upPressedCount = 0 var downPressedCount = 0 + var valueModifiedCount = 0 var upPressedSpy = signalSpy.createObject(control, {target: control.up, signalName: "pressedChanged"}) verify(upPressedSpy.valid) @@ -258,6 +260,9 @@ TestCase { var downPressedSpy = signalSpy.createObject(control, {target: control.down, signalName: "pressedChanged"}) verify(downPressedSpy.valid) + var valueModifiedSpy = signalSpy.createObject(control, {target: control, signalName: "valueModified"}) + verify(valueModifiedSpy.valid) + control.forceActiveFocus() verify(control.activeFocus) @@ -269,6 +274,7 @@ TestCase { compare(control.down.pressed, true) compare(control.up.pressed, false) compare(downPressedSpy.count, ++downPressedCount) + compare(valueModifiedSpy.count, ++valueModifiedCount) compare(control.value, 50 - d1) @@ -276,6 +282,7 @@ TestCase { compare(control.down.pressed, false) compare(control.up.pressed, false) compare(downPressedSpy.count, ++downPressedCount) + compare(valueModifiedSpy.count, valueModifiedCount) } compare(control.value, 40) @@ -284,6 +291,7 @@ TestCase { compare(control.up.pressed, true) compare(control.down.pressed, false) compare(upPressedSpy.count, ++upPressedCount) + compare(valueModifiedSpy.count, ++valueModifiedCount) compare(control.value, 40 + i1) @@ -291,6 +299,7 @@ TestCase { compare(control.down.pressed, false) compare(control.up.pressed, false) compare(upPressedSpy.count, ++upPressedCount) + compare(valueModifiedSpy.count, valueModifiedCount) } compare(control.value, 50) @@ -302,9 +311,12 @@ TestCase { keyPress(Qt.Key_Down) compare(control.down.pressed, wasDownEnabled) compare(control.up.pressed, false) - if (wasDownEnabled) + if (wasDownEnabled) { ++downPressedCount + ++valueModifiedCount + } compare(downPressedSpy.count, downPressedCount) + compare(valueModifiedSpy.count, valueModifiedCount) compare(control.value, Math.max(0, 50 - d2 * 25)) @@ -314,6 +326,7 @@ TestCase { if (wasDownEnabled) ++downPressedCount compare(downPressedSpy.count, downPressedCount) + compare(valueModifiedSpy.count, valueModifiedCount) } compare(control.value, 0) @@ -322,9 +335,12 @@ TestCase { keyPress(Qt.Key_Up) compare(control.up.pressed, wasUpEnabled) compare(control.down.pressed, false) - if (wasUpEnabled) + if (wasUpEnabled) { ++upPressedCount + ++valueModifiedCount + } compare(upPressedSpy.count, upPressedCount) + compare(valueModifiedSpy.count, valueModifiedCount) compare(control.value, Math.min(99, i2 * 25)) @@ -334,14 +350,13 @@ TestCase { if (wasUpEnabled) ++upPressedCount compare(upPressedSpy.count, upPressedCount) + compare(valueModifiedSpy.count, valueModifiedCount) } compare(control.value, 99) - - control.destroy() } function test_locale() { - var control = spinBox.createObject(testCase) + var control = createTemporaryObject(spinBox, testCase) verify(control) control.locale = Qt.locale("ar_EG") // Arabic, Egypt @@ -351,19 +366,16 @@ TestCase { control.value = i compare(control.contentItem.text, numbers[i]) } - - control.destroy() } function test_baseline() { - var control = spinBox.createObject(testCase) + var control = createTemporaryObject(spinBox, testCase) verify(control) compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) - control.destroy() } function test_focus() { - var control = spinBox.createObject(testCase, {from: 10, to: 1000, value: 100, focus: true}) + var control = createTemporaryObject(spinBox, testCase, {from: 10, to: 1000, value: 100, focus: true}) verify(control) control.forceActiveFocus() @@ -379,12 +391,10 @@ TestCase { compare(control.from, 10) compare(control.to, 1000) compare(control.value, 100) - - control.destroy() } function test_editable() { - var control = spinBox.createObject(testCase) + var control = createTemporaryObject(spinBox, testCase) verify(control) control.contentItem.forceActiveFocus() @@ -402,43 +412,48 @@ TestCase { keyClick(Qt.Key_5) keyClick(Qt.Key_Return) compare(control.value, 5) - - control.destroy() } function test_wheel(data) { - var control = spinBox.createObject(testCase, {wheelEnabled: true}) + var control = createTemporaryObject(spinBox, testCase, {wheelEnabled: true}) verify(control) + var valueModifiedSpy = signalSpy.createObject(control, {target: control, signalName: "valueModified"}) + verify(valueModifiedSpy.valid) + var delta = 120 compare(control.value, 0) mouseWheel(control, control.width / 2, control.height / 2, delta, delta) compare(control.value, 1) + compare(valueModifiedSpy.count, 1) control.stepSize = 2 mouseWheel(control, control.width / 2, control.height / 2, delta, delta) compare(control.value, 3) + compare(valueModifiedSpy.count, 2) control.stepSize = 10 mouseWheel(control, control.width / 2, control.height / 2, -delta, -delta) compare(control.value, 0) + compare(valueModifiedSpy.count, 3) control.stepSize = 5 mouseWheel(control, control.width / 2, control.height / 2, delta, delta) compare(control.value, 5) + compare(valueModifiedSpy.count, 4) mouseWheel(control, control.width / 2, control.height / 2, 0.5 * delta, 0.5 * delta) compare(control.value, 8) + compare(valueModifiedSpy.count, 5) mouseWheel(control, control.width / 2, control.height / 2, -delta, -delta) compare(control.value, 3) - - control.destroy() + compare(valueModifiedSpy.count, 6) } function test_initiallyDisabledIndicators_data() { @@ -451,13 +466,11 @@ TestCase { } function test_initiallyDisabledIndicators(data) { - var control = spinBox.createObject(testCase, { from: data.from, value: data.value, to: data.to }) + var control = createTemporaryObject(spinBox, testCase, { from: data.from, value: data.value, to: data.to }) verify(control) compare(control.up.indicator.enabled, data.upEnabled) compare(control.down.indicator.enabled, data.downEnabled) - - control.destroy() } function test_hover_data() { @@ -472,7 +485,7 @@ TestCase { } function test_hover(data) { - var control = spinBox.createObject(testCase, {hoverEnabled: data.hoverEnabled, value: data.value}) + var control = createTemporaryObject(spinBox, testCase, {hoverEnabled: data.hoverEnabled, value: data.value}) verify(control) var button = control[data.button] @@ -485,8 +498,6 @@ TestCase { mouseMove(control, button.indicator.x - 1, button.indicator.y - 1) compare(button.hovered, false) - - control.destroy() } function test_valueFromText_data() { @@ -497,7 +508,7 @@ TestCase { } function test_valueFromText(data) { - var control = spinBox.createObject(testCase, {editable: data.editable}) + var control = createTemporaryObject(spinBox, testCase, {editable: data.editable}) verify(control) control.forceActiveFocus() @@ -517,12 +528,10 @@ TestCase { control.focus = false compare(valueFromTextCalls, data.editable ? 3 : 0) - - control.destroy() } function test_autoRepeat() { - var control = spinBox.createObject(testCase) + var control = createTemporaryObject(spinBox, testCase) verify(control) compare(control.value, 0) @@ -579,7 +588,5 @@ TestCase { mouseRelease(control.up.indicator, -1, -1) verify(!control.up.pressed) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_swipedelegate.qml b/tests/auto/controls/data/tst_swipedelegate.qml index 98c99438..a36a2770 100644 --- a/tests/auto/controls/data/tst_swipedelegate.qml +++ b/tests/auto/controls/data/tst_swipedelegate.qml @@ -40,7 +40,7 @@ import QtQuick 2.6 import QtTest 1.0 -import QtQuick.Controls 2.1 +import QtQuick.Controls 2.2 TestCase { @@ -128,10 +128,8 @@ TestCase { ignoreWarning(warningMessage); - var control = data.component.createObject(testCase); + var control = createTemporaryObject(data.component, testCase); verify(control.contentItem); - - control.destroy(); } Component { @@ -204,11 +202,11 @@ TestCase { } function test_settingDelegates() { - var control = swipeDelegateComponent.createObject(testCase); + var control = createTemporaryObject(swipeDelegateComponent, testCase); verify(control); ignoreWarning(Qt.resolvedUrl("tst_swipedelegate.qml") + - ":160:9: QML SwipeDelegate: cannot set both behind and left/right properties") + ":158:9: QML SwipeDelegate: cannot set both behind and left/right properties") control.swipe.behind = itemComponent; // Shouldn't be any warnings when unsetting delegates. @@ -217,7 +215,7 @@ TestCase { // right is still set. ignoreWarning(Qt.resolvedUrl("tst_swipedelegate.qml") + - ":160:9: QML SwipeDelegate: cannot set both behind and left/right properties") + ":158:9: QML SwipeDelegate: cannot set both behind and left/right properties") control.swipe.behind = itemComponent; control.swipe.right = null; @@ -226,11 +224,11 @@ TestCase { control.swipe.behind = itemComponent; ignoreWarning(Qt.resolvedUrl("tst_swipedelegate.qml") + - ":160:9: QML SwipeDelegate: cannot set both behind and left/right properties") + ":158:9: QML SwipeDelegate: cannot set both behind and left/right properties") control.swipe.left = itemComponent; ignoreWarning(Qt.resolvedUrl("tst_swipedelegate.qml") + - ":160:9: QML SwipeDelegate: cannot set both behind and left/right properties") + ":158:9: QML SwipeDelegate: cannot set both behind and left/right properties") control.swipe.right = itemComponent; control.swipe.behind = null; @@ -245,7 +243,7 @@ TestCase { var oldLeft = control.swipe.left; var oldLeftItem = control.swipe.leftItem; ignoreWarning(Qt.resolvedUrl("tst_swipedelegate.qml") + - ":160:9: QML SwipeDelegate: left/right/behind properties may only be set when swipe.position is 0") + ":158:9: QML SwipeDelegate: left/right/behind properties may only be set when swipe.position is 0") control.swipe.left = null; compare(control.swipe.left, oldLeft); compare(control.swipe.leftItem, oldLeftItem); @@ -256,7 +254,7 @@ TestCase { var oldRight = control.swipe.right; var oldRightItem = control.swipe.rightItem; ignoreWarning(Qt.resolvedUrl("tst_swipedelegate.qml") + - ":160:9: QML SwipeDelegate: left/right/behind properties may only be set when swipe.position is 0") + ":158:9: QML SwipeDelegate: left/right/behind properties may only be set when swipe.position is 0") control.swipe.right = null; compare(control.swipe.right, oldRight); compare(control.swipe.rightItem, oldRightItem); @@ -282,24 +280,20 @@ TestCase { var oldBehind = control.swipe.behind; var oldBehindItem = control.swipe.behindItem; ignoreWarning(Qt.resolvedUrl("tst_swipedelegate.qml") + - ":160:9: QML SwipeDelegate: left/right/behind properties may only be set when swipe.position is 0") + ":158:9: QML SwipeDelegate: left/right/behind properties may only be set when swipe.position is 0") control.swipe.behind = null; compare(control.swipe.behind, oldBehind); compare(control.swipe.behindItem, oldBehindItem); - - control.destroy(); } function test_defaults() { - var control = swipeDelegateComponent.createObject(testCase); + var control = createTemporaryObject(swipeDelegateComponent, testCase); verify(control); compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset); compare(control.swipe.position, 0); verify(!control.pressed); verify(!control.swipe.complete); - - control.destroy(); } SignalSequenceSpy { @@ -308,7 +302,7 @@ TestCase { } function test_swipe() { - var control = swipeDelegateComponent.createObject(testCase); + var control = createTemporaryObject(swipeDelegateComponent, testCase); verify(control); var overDragDistance = Math.round(dragDistance * 1.1); @@ -317,6 +311,14 @@ TestCase { verify(completedSpy); verify(completedSpy.valid); + var openedSpy = signalSpyComponent.createObject(control, { target: control.swipe, signalName: "opened" }); + verify(openedSpy); + verify(openedSpy.valid); + + var closedSpy = signalSpyComponent.createObject(control, { target: control.swipe, signalName: "closed" }); + verify(closedSpy); + verify(closedSpy.valid); + mouseSignalSequenceSpy.target = control; mouseSignalSequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true }], "pressed"]; mousePress(control, control.width / 2, control.height / 2); @@ -324,6 +326,8 @@ TestCase { compare(control.swipe.position, 0.0); verify(!control.swipe.complete); compare(completedSpy.count, 0); + compare(openedSpy.count, 0); + compare(closedSpy.count, 0); verify(mouseSignalSequenceSpy.success); verify(!control.swipe.leftItem); verify(!control.swipe.rightItem); @@ -334,6 +338,8 @@ TestCase { compare(control.swipe.position, overDragDistance / control.width); verify(!control.swipe.complete); compare(completedSpy.count, 0); + compare(openedSpy.count, 0); + compare(closedSpy.count, 0); verify(control.swipe.leftItem); verify(control.swipe.leftItem.visible); compare(control.swipe.leftItem.parent, control); @@ -346,6 +352,8 @@ TestCase { compare(control.swipe.position, 0.0); verify(!control.swipe.complete); compare(completedSpy.count, 0); + compare(openedSpy.count, 0); + compare(closedSpy.count, 0); verify(control.swipe.leftItem); verify(control.swipe.leftItem.visible); compare(control.swipe.leftItem.parent, control); @@ -359,6 +367,8 @@ TestCase { compare(control.swipe.position, -overDragDistance / control.width); verify(!control.swipe.complete); compare(completedSpy.count, 0); + compare(openedSpy.count, 0); + compare(closedSpy.count, 0); verify(control.swipe.leftItem); verify(!control.swipe.leftItem.visible); verify(control.swipe.rightItem); @@ -372,6 +382,8 @@ TestCase { compare(control.swipe.position, 0.6); verify(!control.swipe.complete); compare(completedSpy.count, 0); + compare(openedSpy.count, 0); + compare(closedSpy.count, 0); verify(control.swipe.leftItem); verify(control.swipe.leftItem.visible); verify(control.swipe.rightItem); @@ -380,9 +392,11 @@ TestCase { mouseSignalSequenceSpy.expectedSequence = [["pressedChanged", { "pressed": false }], "canceled"]; mouseRelease(control, control.width / 2, control.height / 2); verify(!control.pressed); - compare(control.swipe.position, 1.0); - verify(control.swipe.complete); + tryCompare(control.swipe, "position", 1.0); + tryCompare(control.swipe, "complete", true); compare(completedSpy.count, 1); + compare(openedSpy.count, 1); + compare(closedSpy.count, 0); verify(mouseSignalSequenceSpy.success); verify(control.swipe.leftItem); verify(control.swipe.leftItem.visible); @@ -399,21 +413,27 @@ TestCase { // haven't started grabbing behind's mouse events. verify(control.swipe.complete); compare(completedSpy.count, 1); + compare(openedSpy.count, 1); + compare(closedSpy.count, 0); verify(mouseSignalSequenceSpy.success); mouseMove(control, control.width / 2 - overDragDistance, control.height / 2); verify(control.pressed); verify(!control.swipe.complete); compare(completedSpy.count, 1); + compare(openedSpy.count, 1); + compare(closedSpy.count, 0); compare(control.swipe.position, 1.0 - overDragDistance / control.width); // Since we went over the drag distance, we should expect canceled() to be emitted. mouseSignalSequenceSpy.expectedSequence = [["pressedChanged", { "pressed": false }], "canceled"]; mouseRelease(control, control.width * 0.4, control.height / 2); verify(!control.pressed); - compare(control.swipe.position, 1.0); - verify(control.swipe.complete); + tryCompare(control.swipe, "position", 1.0); + tryCompare(control.swipe, "complete", true); compare(completedSpy.count, 2); + compare(openedSpy.count, 2); + compare(closedSpy.count, 0); verify(mouseSignalSequenceSpy.success); tryCompare(control.contentItem, "x", control.width + control.leftPadding); @@ -424,24 +444,28 @@ TestCase { compare(control.swipe.position, 1.0); verify(control.swipe.complete); compare(completedSpy.count, 2); + compare(openedSpy.count, 2); + compare(closedSpy.count, 0); verify(mouseSignalSequenceSpy.success); mouseMove(control, control.width * -0.1, control.height / 2); verify(control.pressed); verify(!control.swipe.complete); compare(completedSpy.count, 2); + compare(openedSpy.count, 2); + compare(closedSpy.count, 0); compare(control.swipe.position, 0.4); mouseSignalSequenceSpy.expectedSequence = [["pressedChanged", { "pressed": false }], "canceled"]; mouseRelease(control, control.width * -0.1, control.height / 2); verify(!control.pressed); - compare(control.swipe.position, 0.0); + tryCompare(control.swipe, "position", 0.0); verify(!control.swipe.complete); compare(completedSpy.count, 2); + compare(openedSpy.count, 2); + tryCompare(closedSpy, "count", 1); verify(mouseSignalSequenceSpy.success); tryCompare(control.contentItem, "x", control.leftPadding); - - control.destroy(); } function test_swipeVelocity_data() { @@ -454,7 +478,7 @@ TestCase { function test_swipeVelocity(data) { skip("QTBUG-52003"); - var control = swipeDelegateComponent.createObject(testCase); + var control = createTemporaryObject(swipeDelegateComponent, testCase); verify(control); var distance = Math.round(dragDistance * 1.1); @@ -514,8 +538,6 @@ TestCase { verify(expectedVisibleItem.visible); verify(!expectedHiddenItem); tryCompare(control.contentItem, "x", expectedContentItemX); - - control.destroy(); } Component { @@ -532,9 +554,13 @@ TestCase { } function test_eventsToLeftAndRight() { - var control = swipeDelegateWithButtonComponent.createObject(testCase); + var control = createTemporaryObject(swipeDelegateWithButtonComponent, testCase); verify(control); + var closedSpy = signalSpyComponent.createObject(control, { target: control.swipe, signalName: "closed" }); + verify(closedSpy); + verify(closedSpy.valid); + // The button should be pressed instead of the SwipeDelegate. mouseDrag(control, control.width / 2, control.height / 2, -control.width, 0); // Mouse has been released by this stage. @@ -572,18 +598,17 @@ TestCase { // Returning back to a position of 0 and pressing on the control should // result in the control being pressed. mouseDrag(control, control.width / 2, control.height / 2, control.width * 0.6, 0); + tryCompare(closedSpy, "count", 1); compare(control.swipe.position, 0); mousePress(control, control.width / 2, control.height / 2); verify(control.pressed); verify(!button.pressed); mouseRelease(control, control.width / 2, control.height / 2); verify(!control.pressed); - - control.destroy(); } function test_mouseButtons() { - var control = swipeDelegateComponent.createObject(testCase); + var control = createTemporaryObject(swipeDelegateComponent, testCase); verify(control); // click @@ -644,8 +669,6 @@ TestCase { mouseRelease(control); compare(control.pressed, false); verify(mouseSignalSequenceSpy.success); - - control.destroy(); } Component { @@ -709,7 +732,7 @@ TestCase { } function test_removableDelegates() { - var listView = removableDelegatesComponent.createObject(testCase); + var listView = createTemporaryObject(removableDelegatesComponent, testCase); verify(listView); compare(listView.count, 3); @@ -730,8 +753,8 @@ TestCase { mouseRelease(listView, firstItem.width / 2, firstItem.height / 2); verify(!firstItem.pressed); - compare(firstItem.swipe.position, 1.0); - verify(firstItem.swipe.complete); + tryCompare(firstItem.swipe, "position", 1.0); + tryCompare(firstItem.swipe, "complete", true); compare(listView.count, 3); // Wait for it to settle down. @@ -767,8 +790,6 @@ TestCase { break; } compare(listView.count, 2); - - listView.destroy(); } Component { @@ -825,7 +846,7 @@ TestCase { } function test_leadingTrailing(data) { - var control = data.component.createObject(testCase); + var control = createTemporaryObject(data.component, testCase); verify(control); mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton); @@ -833,12 +854,10 @@ TestCase { verify(control.swipe.leftItem); compare(control.swipe.leftItem.x, -control.width / 2); mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton); - - control.destroy(); } function test_minMaxPosition() { - var control = leadingTrailingXComponent.createObject(testCase); + var control = createTemporaryObject(leadingTrailingXComponent, testCase); verify(control); // Should be limited within the range -1.0 to 1.0. @@ -850,8 +869,6 @@ TestCase { mouseMove(control, control.width * -1.6, control.height / 2, Qt.LeftButton); compare(control.swipe.position, -1.0); mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton); - - control.destroy(); } Component { @@ -876,7 +893,7 @@ TestCase { // swipe.position should be scaled to the width of the relevant delegate, // and it shouldn't be possible to drag past the delegate (so that content behind the control is visible). function test_delegateWidth() { - var control = emptySwipeDelegateComponent.createObject(testCase); + var control = createTemporaryObject(emptySwipeDelegateComponent, testCase); verify(control); control.swipe.left = smallLeftComponent; @@ -901,8 +918,6 @@ TestCase { mouseRelease(control, control.width / 2 + control.swipe.leftItem.width, control.height / 2, Qt.LeftButton); compare(control.swipe.position, 1.0); tryCompare(control.background, "x", control.swipe.leftItem.width, 1000); - - control.destroy(); } SignalSpy { @@ -916,7 +931,7 @@ TestCase { } function test_positionAfterSwipeCompleted() { - var control = swipeDelegateComponent.createObject(testCase); + var control = createTemporaryObject(swipeDelegateComponent, testCase); verify(control); // Ensure that both delegates are constructed. @@ -960,8 +975,6 @@ TestCase { compare(control.swipe.position, 1.0); tryCompare(control.background, "x", control.swipe.leftItem.width, 1000); mouseRelease(control, control.swipe.leftItem.width, control.height / 2, Qt.LeftButton); - - control.destroy(); } // TODO: this somehow results in the behind item having a negative width @@ -1012,7 +1025,7 @@ TestCase { } function test_leadingTrailingBehindItem() { - var control = behindSwipeDelegateComponent.createObject(testCase); + var control = createTemporaryObject(behindSwipeDelegateComponent, testCase); verify(control); swipe(control, 0.0, 1.0); @@ -1032,7 +1045,7 @@ TestCase { mouseMove(control, control.width / 2 + control.swipe.behindItem.width * 0.8, control.height / 2, Qt.LeftButton); compare(control.swipe.position, -0.2); mouseRelease(control, control.width / 2 + control.swipe.behindItem.width * 0.8, control.height / 2, Qt.LeftButton); - compare(control.swipe.position, 0.0); + tryCompare(control.swipe, "position", 0.0); // Try wrapping the other way. swipe(control, 0.0, -1.0); @@ -1043,9 +1056,7 @@ TestCase { mouseMove(control, control.width / 2 - control.swipe.behindItem.width * 0.8, control.height / 2, Qt.LeftButton); compare(control.swipe.position, 0.2); mouseRelease(control, control.width / 2 - control.swipe.behindItem.width * 0.8, control.height / 2, Qt.LeftButton); - compare(control.swipe.position, 0.0); - - control.destroy(); + tryCompare(control.swipe, "position", 0.0); } Component { @@ -1065,9 +1076,13 @@ TestCase { } function test_close() { - var control = closeSwipeDelegateComponent.createObject(testCase); + var control = createTemporaryObject(closeSwipeDelegateComponent, testCase); verify(control); + var closedSpy = signalSpyComponent.createObject(control, { target: control.swipe, signalName: "closed" }); + verify(closedSpy); + verify(closedSpy.valid); + swipe(control, 0.0, -1.0); compare(control.swipe.rightItem.visible, true); // Should animate, so it shouldn't change right away. @@ -1079,12 +1094,11 @@ TestCase { mouseRelease(control); verify(!control.swipe.rightItem.SwipeDelegate.pressed); - tryCompare(control.swipe, "position", 0); + tryCompare(closedSpy, "count", 1); + compare(control.swipe.position, 0); // Swiping after closing should work as normal. swipe(control, 0.0, -1.0); - - control.destroy(); } Component { @@ -1133,7 +1147,7 @@ TestCase { // Tests that it's possible to have multiple non-interactive items in one delegate // (e.g. left/right/behind) that can each receive clicks. function test_multipleClickableActions() { - var control = multiActionSwipeDelegateComponent.createObject(testCase); + var control = createTemporaryObject(multiActionSwipeDelegateComponent, testCase); verify(control); swipe(control, 0.0, -1.0); @@ -1178,8 +1192,6 @@ TestCase { compare(control.swipe.rightItem.secondAction.SwipeDelegate.pressed, false); compare(secondClickedSpy.count, 1); compare(control.swipe.rightItem.secondClickCount, 1); - - control.destroy(); } // Pressing on a "side action" and then dragging should eventually @@ -1187,7 +1199,7 @@ TestCase { // When this happens, it will grab the mouse and hence we must clear // that action's pressed state so that it doesn't stay pressed after releasing. function test_dragSideAction() { - var listView = removableDelegatesComponent.createObject(testCase); + var listView = createTemporaryObject(removableDelegatesComponent, testCase); verify(listView); var control = listView.itemAt(0, 0); @@ -1208,15 +1220,13 @@ TestCase { verify(listView.contentY !== 0); compare(control.swipe.leftItem.SwipeDelegate.pressed, false); - - listView.destroy(); } // When the width of a SwipeDelegate changes (as it does upon portrait => landscape // rotation, for example), the positions of the contentItem and background items // should be updated accordingly. function test_contentItemPosOnWidthChanged() { - var control = swipeDelegateComponent.createObject(testCase); + var control = createTemporaryObject(swipeDelegateComponent, testCase); verify(control); swipe(control, 0.0, 1.0); @@ -1226,12 +1236,10 @@ TestCase { control.width += 100; compare(control.contentItem.x, oldContentItemX + 100); compare(control.background.x, oldBackgroundX + 100); - - control.destroy(); } function test_contentItemHeightOnHeightChanged() { - var control = swipeDelegateComponent.createObject(testCase); + var control = createTemporaryObject(swipeDelegateComponent, testCase); verify(control); // Try when swipe.complete is false. @@ -1250,8 +1258,6 @@ TestCase { compare(control.contentItem.height, control.availableHeight); verify(control.contentItem.height < originalContentItemHeight); compare(control.contentItem.y, control.topPadding); - - control.destroy(); } function test_releaseOutside_data() { @@ -1262,7 +1268,7 @@ TestCase { } function test_releaseOutside(data) { - var control = data.component.createObject(testCase); + var control = createTemporaryObject(data.component, testCase); verify(control); // Press and then release below the control. @@ -1345,7 +1351,7 @@ TestCase { } function test_beginSwipeOverRightItem() { - var control = leftRightWithLabelsComponent.createObject(testCase); + var control = createTemporaryObject(leftRightWithLabelsComponent, testCase); verify(control); // Swipe to the left, exposing the right item. @@ -1364,8 +1370,146 @@ TestCase { mouseRelease(rightLabel, rightLabel.width / 2 - overDragDistance, control.height / 2, Qt.LeftButton); verify(!control.swipe.leftItem); + } + + Component { + id: swipeDelegateDisabledComponent + + SwipeDelegate { + id: swipeDelegate + text: "SwipeDelegate" + width: parent.width + height: checked ? implicitHeight * 2 : implicitHeight + checkable: true + + swipe.enabled: false + swipe.right: Label { + text: swipeDelegate.checked ? qsTr("Expanded") : qsTr("Collapsed") + width: parent.width + height: parent.height + padding: 12 + color: "white" + verticalAlignment: Label.AlignVCenter + horizontalAlignment: Label.AlignRight + } + } + } + + function test_swipeEnabled() { + var control = createTemporaryObject(swipeDelegateDisabledComponent, testCase); + + mousePress(control, control.width / 2, control.height / 2); + verify(control.pressed); + compare(control.swipe.position, 0.0); + verify(!control.swipe.complete); + verify(!control.swipe.leftItem); + verify(!control.swipe.rightItem); + + // It shouldn't be possible to swipe. + var overDragDistance = Math.round(dragDistance * 1.1); + mouseMove(control, control.width / 2 - overDragDistance, control.height / 2); + verify(control.pressed); + compare(control.swipe.position, 0.0); + verify(!control.swipe.complete); + verify(!control.swipe.leftItem); + verify(!control.swipe.rightItem); + + // Now move outside the right edge of the control and release. + mouseMove(control, control.width * 1.1, control.height / 2); + verify(control.pressed); + compare(control.swipe.position, 0.0); + verify(!control.swipe.complete); + verify(!control.swipe.leftItem); + verify(!control.swipe.rightItem); + + mouseRelease(control, control.width / 2, control.height / 2); + verify(!control.pressed); + compare(control.swipe.position, 0.0); + verify(!control.swipe.complete); + verify(!control.swipe.leftItem); + verify(!control.swipe.rightItem); + + // Now enabled swiping so that we can swipe to the left. + control.swipe.enabled = true; + swipe(control, 0, -1); + verify(control.swipe.complete); + + // Now that the swipe is complete, disable swiping and then try to swipe again. + // It should stay at its position of -1. + control.swipe.enabled = false; + + mousePress(control, control.width / 2, control.height / 2); + verify(control.pressed); + compare(control.swipe.position, -1.0); + + mouseMove(control, control.width / 2 + overDragDistance, control.height / 2); + verify(control.pressed); + compare(control.swipe.position, -1.0); + verify(control.swipe.complete); + + mouseRelease(control, control.width / 2 + overDragDistance, control.height / 2); + verify(!control.pressed); + compare(control.swipe.position, -1.0); + verify(control.swipe.complete); + } + + function test_side() { + compare(SwipeDelegate.Left, 1.0); + compare(SwipeDelegate.Right, -1.0); + } + + function test_open_side_data() { + return [ + { tag: "left", side: SwipeDelegate.Left, position: 1, complete: true, left: greenLeftComponent, right: null, behind: null }, + { tag: "right", side: SwipeDelegate.Right, position: -1, complete: true, left: null, right: redRightComponent, behind: null }, + { tag: "behind,left", side: SwipeDelegate.Left, position: 1, complete: true, left: null, right: null, behind: greenLeftComponent }, + { tag: "behind,right", side: SwipeDelegate.Right, position: -1, complete: true, left: null, right: null, behind: redRightComponent }, + { tag: "left,behind", side: SwipeDelegate.Left, position: 1, complete: true, left: null, right: null, behind: greenLeftComponent }, + { tag: "right,behind", side: SwipeDelegate.Right, position: -1, complete: true, left: null, right: null, behind: redRightComponent }, + { tag: "left,null", side: SwipeDelegate.Left, position: 0, complete: false, left: null, right: null, behind: null }, + { tag: "right,null", side: SwipeDelegate.Right, position: 0, complete: false, left: null, right: null, behind: null }, + { tag: "invalid", side: 0, position: 0, complete: false, left: greenLeftComponent, right: null, behind: null } + ] + } + + function test_open_side(data) { + var control = createTemporaryObject(emptySwipeDelegateComponent, testCase, + {"swipe.left": data.left, "swipe.right": data.right, "swipe.behind": data.behind}); + verify(control); + + control.swipe.open(data.side); + tryCompare(control.swipe, "position", data.position); + tryCompare(control.swipe, "complete", data.complete); + } + + Component { + id: openSwipeDelegateComponent + + SwipeDelegate { + text: "SwipeDelegate" + width: 150 - control.destroy(); + onClicked: swipe.open(SwipeDelegate.Right) + + swipe.right: Item { + width: parent.width + height: parent.height + } + } + } + + function test_open() { + var control = createTemporaryObject(openSwipeDelegateComponent, testCase); + verify(control); + + mouseClick(control); + tryCompare(control.swipe, "position", SwipeDelegate.Right); + tryCompare(control.background, "x", -control.background.width); + + // Swiping after opening should work as normal. + swipe(control, SwipeDelegate.Right, 0.0); + tryCompare(control.swipe, "position", 0.0); + tryCompare(control.background, "x", 0); } Component { @@ -1377,6 +1521,7 @@ TestCase { width: 150 swipe.left: greenLeftComponent swipe.right: redRightComponent + swipe.transition: null property alias behavior: xBehavior property alias animation: numberAnimation @@ -1400,7 +1545,7 @@ TestCase { function test_animations() { // Test that animations are run when releasing from a drag. - var control = animationSwipeDelegateComponent.createObject(testCase); + var control = createTemporaryObject(animationSwipeDelegateComponent, testCase); verify(control); mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton); @@ -1413,7 +1558,5 @@ TestCase { verify(!control.down); verify(control.behavior.enabled); verify(control.animation.running); - - control.destroy(); } } diff --git a/tests/auto/controls/data/tst_swipeview.qml b/tests/auto/controls/data/tst_swipeview.qml index 7fd0ab37..d330b73c 100644 --- a/tests/auto/controls/data/tst_swipeview.qml +++ b/tests/auto/controls/data/tst_swipeview.qml @@ -66,9 +66,9 @@ TestCase { } function test_current() { - var control = swipeView.createObject(testCase) + var control = createTemporaryObject(swipeView, testCase) - var currentItemChangedSpy = signalSpy.createObject(testCase, {target: control, signalName: "currentItemChanged"}) + var currentItemChangedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "currentItemChanged"}) verify(currentItemChangedSpy.valid) compare(control.count, 0) @@ -112,8 +112,6 @@ TestCase { compare(control.currentIndex, 2) compare(control.currentItem.text, "2") compare(currentItemChangedSpy.count, 5); - - control.destroy() } Component { @@ -134,17 +132,15 @@ TestCase { } function test_initialCurrent() { - var control = initialCurrentSwipeView.createObject(testCase) + var control = createTemporaryObject(initialCurrentSwipeView, testCase) compare(control.count, 2) compare(control.currentIndex, 1) compare(control.currentItem, control.item1) - - control.destroy() } function test_addRemove() { - var control = swipeView.createObject(testCase) + var control = createTemporaryObject(swipeView, testCase) function verifyCurrentIndexCountDiff() { verify(control.currentIndex < control.count) @@ -152,7 +148,7 @@ TestCase { control.currentIndexChanged.connect(verifyCurrentIndexCountDiff) control.countChanged.connect(verifyCurrentIndexCountDiff) - var currentItemChangedSpy = signalSpy.createObject(testCase, {target: control, signalName: "currentItemChanged"}) + var currentItemChangedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "currentItemChanged"}) verify(currentItemChangedSpy.valid) compare(control.count, 0) @@ -238,8 +234,6 @@ TestCase { compare(control.count, 0) compare(control.currentIndex, -1) compare(currentItemChangedSpy.count, 2) - - control.destroy() } Component { @@ -254,7 +248,7 @@ TestCase { } function test_content() { - var control = contentView.createObject(testCase) + var control = createTemporaryObject(contentView, testCase) function compareObjectNames(content, names) { if (content.length !== names.length) @@ -284,8 +278,6 @@ TestCase { control.removeItem(0) verify(compareObjectNames(control.contentData, ["object", "page1", "timer", "page2", "", "page3"])) verify(compareObjectNames(control.contentChildren, ["page2", "page1", "page3"])) - - control.destroy() } Component { @@ -301,7 +293,7 @@ TestCase { } function test_repeater() { - var control = repeated.createObject(testCase) + var control = createTemporaryObject(repeated, testCase) verify(control) var model = control.contentModel @@ -332,8 +324,6 @@ TestCase { compare(model.get(j), item2) compare(repeater.itemAt(j), item2) } - - control.destroy() } Component { @@ -357,7 +347,7 @@ TestCase { } function test_order() { - var control = ordered.createObject(testCase) + var control = createTemporaryObject(ordered, testCase) verify(control) compare(control.count, 7) @@ -368,8 +358,6 @@ TestCase { compare(control.itemAt(4).text, "static_4") compare(control.itemAt(5).text, "dynamic_5") compare(control.itemAt(6).text, "dynamic_6") - - control.destroy() } function test_move_data() { @@ -420,7 +408,7 @@ TestCase { } function test_move(data) { - var control = swipeView.createObject(testCase) + var control = createTemporaryObject(swipeView, testCase) compare(control.count, 0) var titles = ["1", "2", "3"] @@ -464,8 +452,6 @@ TestCase { compare(control.itemAt(i).SwipeView.isNextItem, i === data.currentAfter + 1) compare(control.itemAt(i).SwipeView.isPreviousItem, i === data.currentAfter - 1) } - - control.destroy() } Component { @@ -482,7 +468,7 @@ TestCase { } function test_dynamic() { - var control = dynamicView.createObject(testCase) + var control = createTemporaryObject(dynamicView, testCase) // insertItem(), addItem(), createObject() and static page {} compare(control.count, 4) @@ -496,14 +482,12 @@ TestCase { // tab.destroy() // wait(0) // compare(control.count, 4) - - control.destroy() } function test_attachedParent() { - var control = swipeView.createObject(testCase); + var control = createTemporaryObject(swipeView, testCase); - var page = pageAttached.createObject(testCase); + var page = createTemporaryObject(pageAttached, testCase); compare(page.view, null); compare(page.index, -1); compare(page.isCurrentItem, false); @@ -511,7 +495,7 @@ TestCase { compare(page.isPreviousItem, false); page.destroy(); - page = pageAttached.createObject(null); + page = createTemporaryObject(pageAttached, null); compare(page.view, null); compare(page.index, -1); compare(page.isCurrentItem, false); @@ -535,7 +519,5 @@ TestCase { compare(page.isCurrentItem, false); compare(page.isNextItem, false); compare(page.isPreviousItem, false); - - control.destroy(); } } diff --git a/tests/auto/controls/data/tst_switch.qml b/tests/auto/controls/data/tst_switch.qml index 314848c8..6cf7ec66 100644 --- a/tests/auto/controls/data/tst_switch.qml +++ b/tests/auto/controls/data/tst_switch.qml @@ -58,12 +58,12 @@ TestCase { Component { id: signalSequenceSpy SignalSequenceSpy { - signals: ["pressed", "released", "canceled", "clicked", "pressedChanged", "checkedChanged"] + signals: ["pressed", "released", "canceled", "clicked", "toggled", "pressedChanged", "checkedChanged"] } } function test_text() { - var control = swtch.createObject(testCase) + var control = createTemporaryObject(swtch, testCase) verify(control) compare(control.text, "") @@ -71,12 +71,10 @@ TestCase { compare(control.text, "Switch") control.text = "" compare(control.text, "") - - control.destroy() } function test_checked() { - var control = swtch.createObject(testCase) + var control = createTemporaryObject(swtch, testCase) verify(control) compare(control.checked, false) @@ -91,8 +89,6 @@ TestCase { control.checked = false compare(control.checked, false) verify(spy.success) - - control.destroy() } function test_pressed_data() { @@ -103,7 +99,7 @@ TestCase { } function test_pressed(data) { - var control = swtch.createObject(testCase, {padding: 10}) + var control = createTemporaryObject(swtch, testCase, {padding: 10}) verify(control) // stays pressed when dragged outside @@ -114,12 +110,10 @@ TestCase { compare(control.pressed, true) mouseRelease(control, -1, control.height / 2, Qt.LeftButton) compare(control.pressed, false) - - control.destroy() } function test_mouse() { - var control = swtch.createObject(testCase) + var control = createTemporaryObject(swtch, testCase) verify(control) // check @@ -131,6 +125,7 @@ TestCase { verify(spy.success) spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": false }], ["checkedChanged", { "pressed": false, "checked": true }], + "toggled", "released", "clicked"] mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton) @@ -146,6 +141,7 @@ TestCase { verify(spy.success) spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": true }], ["checkedChanged", { "pressed": false, "checked": false }], + "toggled", "released", "clicked"] mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton) @@ -163,6 +159,7 @@ TestCase { compare(control.pressed, true) spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": false }], ["checkedChanged", { "pressed": false, "checked": true }], + "toggled", "released", "clicked"] mouseRelease(control, control.width * 2, control.height / 2, Qt.LeftButton) @@ -180,6 +177,7 @@ TestCase { compare(control.pressed, true) spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": true }], ["checkedChanged", { "pressed": false, "checked": false }], + "toggled", "released", "clicked"] mouseRelease(control, -control.width, control.height / 2, Qt.LeftButton) @@ -196,12 +194,10 @@ TestCase { compare(control.checked, false) compare(control.pressed, false) verify(spy.success) - - control.destroy() } function test_drag() { - var control = swtch.createObject(testCase, {leftPadding: 100, rightPadding: 100}) + var control = createTemporaryObject(swtch, testCase, {leftPadding: 100, rightPadding: 100}) verify(control) var spy = signalSequenceSpy.createObject(control, {target: control}) @@ -225,6 +221,7 @@ TestCase { spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": false }], ["checkedChanged", { "pressed": false, "checked": true }], + "toggled", "released", "clicked"] mouseRelease(control.indicator, control.indicator.width) @@ -259,6 +256,7 @@ TestCase { spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": true }], ["checkedChanged", { "pressed": false, "checked": false }], + "toggled", "released", "clicked"] mouseRelease(control, control.width) @@ -293,6 +291,7 @@ TestCase { spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": false }], ["checkedChanged", { "pressed": false, "checked": true }], + "toggled", "released", "clicked"] mouseRelease(control, control.width) @@ -300,12 +299,10 @@ TestCase { compare(control.checked, true) compare(control.pressed, false) verify(spy.success) - - control.destroy() } function test_keys() { - var control = swtch.createObject(testCase) + var control = createTemporaryObject(swtch, testCase) verify(control) control.forceActiveFocus() @@ -317,6 +314,7 @@ TestCase { "pressed", ["pressedChanged", { "pressed": false, "checked": false }], ["checkedChanged", { "pressed": false, "checked": true }], + "toggled", "released", "clicked"] keyClick(Qt.Key_Space) @@ -328,6 +326,7 @@ TestCase { "pressed", ["pressedChanged", { "pressed": false, "checked": true }], ["checkedChanged", { "pressed": false, "checked": false }], + "toggled", "released", "clicked"] keyClick(Qt.Key_Space) @@ -342,8 +341,6 @@ TestCase { compare(control.checked, false) verify(spy.success) } - - control.destroy() } Component { @@ -355,7 +352,7 @@ TestCase { } function test_binding() { - var container = twoSwitches.createObject(testCase) + var container = createTemporaryObject(twoSwitches, testCase) verify(container) compare(container.sw1.checked, false) @@ -368,25 +365,20 @@ TestCase { container.sw1.checked = false compare(container.sw1.checked, false) compare(container.sw2.checked, false) - - container.destroy() } function test_baseline() { - var control = swtch.createObject(testCase) + var control = createTemporaryObject(swtch, testCase) verify(control) compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) - control.destroy() } function test_focus() { - var control = swtch.createObject(testCase) + var control = createTemporaryObject(swtch, testCase) verify(control) verify(!control.activeFocus) mouseClick(control.indicator) verify(control.activeFocus) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_switchdelegate.qml b/tests/auto/controls/data/tst_switchdelegate.qml index 23117ce7..54b8c4b0 100644 --- a/tests/auto/controls/data/tst_switchdelegate.qml +++ b/tests/auto/controls/data/tst_switchdelegate.qml @@ -58,21 +58,20 @@ TestCase { Component { id: signalSequenceSpy SignalSequenceSpy { - signals: ["pressed", "released", "canceled", "clicked", "pressedChanged", "checkedChanged"] + signals: ["pressed", "released", "canceled", "clicked", "toggled", "pressedChanged", "checkedChanged"] } } // TODO: data-fy tst_checkbox (rename to tst_check?) so we don't duplicate its tests here? function test_defaults() { - var control = switchDelegate.createObject(testCase); + var control = createTemporaryObject(switchDelegate, testCase); verify(control); verify(!control.checked); - control.destroy(); } function test_checked() { - var control = switchDelegate.createObject(testCase); + var control = createTemporaryObject(switchDelegate, testCase); verify(control); mouseClick(control); @@ -80,15 +79,12 @@ TestCase { mouseClick(control); verify(!control.checked); - - control.destroy(); } function test_baseline() { - var control = switchDelegate.createObject(testCase); + var control = createTemporaryObject(switchDelegate, testCase); verify(control); compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset); - control.destroy(); } function test_pressed_data() { @@ -99,7 +95,7 @@ TestCase { } function test_pressed(data) { - var control = switchDelegate.createObject(testCase, {padding: 10}) + var control = createTemporaryObject(switchDelegate, testCase, {padding: 10}) verify(control) // stays pressed when dragged outside @@ -110,12 +106,10 @@ TestCase { compare(control.pressed, true) mouseRelease(control, -1, control.height / 2, Qt.LeftButton) compare(control.pressed, false) - - control.destroy() } function test_mouse() { - var control = switchDelegate.createObject(testCase) + var control = createTemporaryObject(switchDelegate, testCase) verify(control) // check @@ -127,6 +121,7 @@ TestCase { verify(spy.success) spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": false }], ["checkedChanged", { "pressed": false, "checked": true }], + "toggled", "released", "clicked"] mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton) @@ -142,6 +137,7 @@ TestCase { verify(spy.success) spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": true }], ["checkedChanged", { "pressed": false, "checked": false }], + "toggled", "released", "clicked"] mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton) @@ -159,6 +155,7 @@ TestCase { compare(control.pressed, true) spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": false }], ["checkedChanged", { "pressed": false, "checked": true }], + "toggled", "released", "clicked"] mouseRelease(control, control.width * 2, control.height / 2, Qt.LeftButton) @@ -176,6 +173,7 @@ TestCase { compare(control.pressed, true) spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": true }], ["checkedChanged", { "pressed": false, "checked": false }], + "toggled", "released", "clicked"] mouseRelease(control, -control.width, control.height / 2, Qt.LeftButton) @@ -192,12 +190,10 @@ TestCase { compare(control.checked, false) compare(control.pressed, false) verify(spy.success) - - control.destroy() } function test_drag() { - var control = switchDelegate.createObject(testCase, {leftPadding: 100, rightPadding: 100}) + var control = createTemporaryObject(switchDelegate, testCase, {leftPadding: 100, rightPadding: 100}) verify(control) var spy = signalSequenceSpy.createObject(control, {target: control}) @@ -221,6 +217,7 @@ TestCase { spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": false }], ["checkedChanged", { "pressed": false, "checked": true }], + "toggled", "released", "clicked"] mouseRelease(control.indicator, control.indicator.width) @@ -255,6 +252,7 @@ TestCase { spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": true }], ["checkedChanged", { "pressed": false, "checked": false }], + "toggled", "released", "clicked"] mouseRelease(control, control.width) @@ -289,6 +287,7 @@ TestCase { spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": false }], ["checkedChanged", { "pressed": false, "checked": true }], + "toggled", "released", "clicked"] mouseRelease(control, control.width) @@ -296,7 +295,5 @@ TestCase { compare(control.checked, true) compare(control.pressed, false) verify(spy.success) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_tabbar.qml b/tests/auto/controls/data/tst_tabbar.qml index ff3596f6..33df97ce 100644 --- a/tests/auto/controls/data/tst_tabbar.qml +++ b/tests/auto/controls/data/tst_tabbar.qml @@ -91,16 +91,15 @@ TestCase { } function test_defaults() { - var control = tabBar.createObject(testCase) + var control = createTemporaryObject(tabBar, testCase) verify(control) compare(control.count, 0) compare(control.currentIndex, -1) compare(control.currentItem, null) - control.destroy() } function test_current() { - var control = tabBar.createObject(testCase) + var control = createTemporaryObject(tabBar, testCase) compare(control.count, 0) compare(control.currentIndex, -1) @@ -143,32 +142,26 @@ TestCase { compare(control.currentIndex, 2) compare(control.currentItem.text, "2") compare(control.currentItem.checked, true) - - control.destroy() } function test_current_static() { - var control = tabBarStaticTabs.createObject(testCase) + var control = createTemporaryObject(tabBarStaticTabs, testCase) compare(control.count, 2) compare(control.currentIndex, 0) compare(control.currentItem.text, "0") compare(control.currentItem.checked, true) - control.destroy() - - control = tabBarStaticTabsCurrent.createObject(testCase) + control = createTemporaryObject(tabBarStaticTabsCurrent, testCase) compare(control.count, 2) compare(control.currentIndex, 1) compare(control.currentItem.text, "1") compare(control.currentItem.checked, true) - - control.destroy() } function test_addRemove() { - var control = tabBar.createObject(testCase) + var control = createTemporaryObject(tabBar, testCase) function verifyCurrentIndexCountDiff() { verify(control.currentIndex < control.count) @@ -176,7 +169,7 @@ TestCase { control.currentIndexChanged.connect(verifyCurrentIndexCountDiff) control.countChanged.connect(verifyCurrentIndexCountDiff) - var contentChildrenSpy = signalSpy.createObject(testCase, {target: control, signalName: "contentChildrenChanged"}) + var contentChildrenSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "contentChildrenChanged"}) verify(contentChildrenSpy.valid) compare(control.count, 0) @@ -265,8 +258,6 @@ TestCase { compare(control.count, 0) compare(control.currentIndex, -1) compare(contentChildrenSpy.count, 12) - - control.destroy() } Component { @@ -281,7 +272,7 @@ TestCase { } function test_content() { - var control = contentBar.createObject(testCase) + var control = createTemporaryObject(contentBar, testCase) function compareObjectNames(content, names) { if (content.length !== names.length) @@ -293,7 +284,7 @@ TestCase { return true } - var contentChildrenSpy = signalSpy.createObject(testCase, {target: control, signalName: "contentChildrenChanged"}) + var contentChildrenSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "contentChildrenChanged"}) verify(contentChildrenSpy.valid) verify(compareObjectNames(control.contentData, ["object", "button1", "timer", "button2", ""])) @@ -318,8 +309,6 @@ TestCase { verify(compareObjectNames(control.contentData, ["object", "button1", "timer", "button2", "", "button3"])) verify(compareObjectNames(control.contentChildren, ["button2", "button1", "button3"])) compare(contentChildrenSpy.count, 5) - - control.destroy() } Component { @@ -335,7 +324,7 @@ TestCase { } function test_repeater() { - var control = repeated.createObject(testCase) + var control = createTemporaryObject(repeated, testCase) verify(control) var model = control.contentModel @@ -366,8 +355,6 @@ TestCase { compare(model.get(j), item2) compare(repeater.itemAt(j), item2) } - - control.destroy() } Component { @@ -391,7 +378,7 @@ TestCase { } function test_order() { - var control = ordered.createObject(testCase) + var control = createTemporaryObject(ordered, testCase) verify(control) compare(control.count, 7) @@ -402,8 +389,6 @@ TestCase { compare(control.itemAt(4).text, "static_4") compare(control.itemAt(5).text, "dynamic_5") compare(control.itemAt(6).text, "dynamic_6") - - control.destroy() } function test_move_data() { @@ -442,7 +427,7 @@ TestCase { } function test_move(data) { - var control = tabBar.createObject(testCase) + var control = createTemporaryObject(tabBar, testCase) compare(control.count, 0) var titles = ["1", "2", "3"] @@ -468,8 +453,6 @@ TestCase { compare(control.count, titles.length) for (i = 0; i < control.count; ++i) compare(control.itemAt(i).text, titles[i]) - - control.destroy() } Component { @@ -486,7 +469,7 @@ TestCase { } function test_dynamic() { - var control = dynamicBar.createObject(testCase) + var control = createTemporaryObject(dynamicBar, testCase) // insertItem(), addItem(), createObject() and static TabButton {} compare(control.count, 4) @@ -500,8 +483,6 @@ TestCase { // tab.destroy() // wait(0) // compare(control.count, 4) - - control.destroy() } function test_layout_data() { @@ -513,29 +494,49 @@ TestCase { } function test_layout(data) { - var control = tabBar.createObject(testCase, {spacing: data.spacing, width: 200}) + var control = createTemporaryObject(tabBar, testCase, {spacing: data.spacing, width: 200}) + + // remove the implicit size from the background so that it won't affect + // the implicit size of the tabbar, so the implicit sizes tested below + // are entirely based on the content size + control.background.implicitWidth = 0 var tab1 = tabButton.createObject(control, {text: "First"}) control.addItem(tab1) tryCompare(tab1, "width", control.width) + compare(control.contentWidth, tab1.implicitWidth) + compare(control.implicitWidth, control.contentWidth + control.leftPadding + control.rightPadding) var tab2 = tabButton.createObject(control, {text: "Second"}) control.addItem(tab2) tryCompare(tab1, "width", (control.width - data.spacing) / 2) compare(tab2.width, (control.width - data.spacing) / 2) + compare(control.contentWidth, tab1.implicitWidth + tab2.implicitWidth + data.spacing) + compare(control.implicitWidth, control.contentWidth + control.leftPadding + control.rightPadding) 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) + compare(control.contentWidth, tab1.implicitWidth + tab2.implicitWidth + tab3.width + 2 * data.spacing) + compare(control.implicitWidth, control.contentWidth + control.leftPadding + control.rightPadding) 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) + compare(control.contentWidth, tab1.implicitWidth + tab2.implicitWidth + tab3.implicitWidth + 2 * data.spacing) + compare(control.implicitWidth, control.contentWidth + control.leftPadding + control.rightPadding) + + tab3.width = undefined + control.width = undefined - control.destroy() + control.contentWidth = 300 + expectedWidth = (control.contentWidth - 2 * data.spacing) / 3 + tryCompare(tab1, "width", expectedWidth) + tryCompare(tab2, "width", expectedWidth) + tryCompare(tab3, "width", expectedWidth) } } diff --git a/tests/auto/controls/data/tst_tabbutton.qml b/tests/auto/controls/data/tst_tabbutton.qml index 98bb542a..72ea4e58 100644 --- a/tests/auto/controls/data/tst_tabbutton.qml +++ b/tests/auto/controls/data/tst_tabbutton.qml @@ -66,7 +66,7 @@ TestCase { } function test_autoExclusive() { - var container = repeater.createObject(testCase) + var container = createTemporaryObject(repeater, testCase) for (var i = 0; i < 3; ++i) { container.children[i].checked = true @@ -78,14 +78,11 @@ TestCase { compare(container.children[j].checked, false) } } - - container.destroy() } function test_baseline() { - var control = tabButton.createObject(testCase) + var control = createTemporaryObject(tabButton, testCase) verify(control) compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) - control.destroy() } } diff --git a/tests/auto/controls/data/tst_textarea.qml b/tests/auto/controls/data/tst_textarea.qml index e058ec19..de3e6854 100644 --- a/tests/auto/controls/data/tst_textarea.qml +++ b/tests/auto/controls/data/tst_textarea.qml @@ -70,13 +70,12 @@ TestCase { } function test_creation() { - var control = textArea.createObject(testCase) + var control = createTemporaryObject(textArea, testCase) verify(control) - control.destroy() } function test_implicitSize() { - var control = textArea.createObject(testCase) + var control = createTemporaryObject(textArea, testCase) var implicitWidthSpy = signalSpy.createObject(control, { target: control, signalName: "implicitWidthChanged"} ) var implicitHeightSpy = signalSpy.createObject(control, { target: control, signalName: "implicitHeightChanged"} ) @@ -86,18 +85,65 @@ TestCase { compare(control.implicitHeight, 200) compare(implicitWidthSpy.count, 1) compare(implicitHeightSpy.count, 1) + } - control.destroy() + function test_alignment_data() { + return [ + { tag: "empty", text: "", placeholderText: "", textAlignment: undefined, placeholderAlignment: Qt.AlignLeft }, + { tag: "empty,left", text: "", placeholderText: "", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft }, + { tag: "empty,center", text: "", placeholderText: "", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter }, + { tag: "empty,right", text: "", placeholderText: "", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight }, + + { tag: "empty,ltr", text: "", placeholderText: "Search", textAlignment: undefined, placeholderAlignment: Qt.AlignLeft }, + { tag: "empty,ltr,left", text: "", placeholderText: "Search", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft }, + { tag: "empty,ltr,center", text: "", placeholderText: "Search", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter }, + { tag: "empty,ltr,right", text: "", placeholderText: "Search", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight }, + + { tag: "empty,rtl", text: "", placeholderText: "بحث", textAlignment: undefined, placeholderAlignment: Qt.AlignRight }, + { tag: "empty,rtl,left", text: "", placeholderText: "بحث", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft }, + { tag: "empty,rtl,center", text: "", placeholderText: "بحث", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter }, + { tag: "empty,rtl,right", text: "", placeholderText: "بحث", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight }, + + { tag: "ltr,empty", text: "Text", placeholderText: "", textAlignment: undefined, placeholderAlignment: Qt.AlignLeft }, + { tag: "ltr,empty,left", text: "Text", placeholderText: "", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft }, + { tag: "ltr,empty,center", text: "Text", placeholderText: "", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter }, + { tag: "ltr,empty,right", text: "Text", placeholderText: "", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight }, + + { tag: "ltr,ltr", text: "Text", placeholderText: "Search", textAlignment: undefined, placeholderAlignment: Qt.AlignLeft }, + { tag: "ltr,ltr,left", text: "Text", placeholderText: "Search", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft }, + { tag: "ltr,ltr,center", text: "Text", placeholderText: "Search", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter }, + { tag: "ltr,ltr,right", text: "Text", placeholderText: "Search", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight }, + + { tag: "ltr,rtl", text: "Text", placeholderText: "بحث", textAlignment: undefined, placeholderAlignment: Qt.AlignRight }, + { tag: "ltr,rtl,left", text: "Text", placeholderText: "بحث", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft }, + { tag: "ltr,rtl,center", text: "Text", placeholderText: "بحث", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter }, + { tag: "ltr,rtl,right", text: "Text", placeholderText: "بحث", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight }, + + { tag: "rtl,empty", text: "نص", placeholderText: "", textAlignment: undefined, placeholderAlignment: Qt.AlignLeft }, + { tag: "rtl,empty,left", text: "نص", placeholderText: "", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft }, + { tag: "rtl,empty,center", text: "نص", placeholderText: "", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter }, + { tag: "rtl,empty,right", text: "نص", placeholderText: "", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight }, + + { tag: "rtl,ltr", text: "نص", placeholderText: "Search", textAlignment: undefined, placeholderAlignment: Qt.AlignLeft }, + { tag: "rtl,ltr,left", text: "نص", placeholderText: "Search", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft }, + { tag: "rtl,ltr,center", text: "نص", placeholderText: "Search", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter }, + { tag: "rtl,ltr,right", text: "نص", placeholderText: "Search", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight }, + + { tag: "rtl,rtl", text: "نص", placeholderText: "بحث", textAlignment: undefined, placeholderAlignment: Qt.AlignRight }, + { tag: "rtl,rtl,left", text: "نص", placeholderText: "بحث", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft }, + { tag: "rtl,rtl,center", text: "نص", placeholderText: "بحث", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter }, + { tag: "rtl,rtl,right", text: "نص", placeholderText: "بحث", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight }, + ] } - function test_alignment() { - var control = textArea.createObject(testCase) + function test_alignment(data) { + var control = createTemporaryObject(textArea, testCase, {text: data.text, placeholderText: data.placeholderText, horizontalAlignment: data.textAlignment}) - control.horizontalAlignment = TextArea.AlignRight - compare(control.horizontalAlignment, TextArea.AlignRight) + if (data.textAlignment !== undefined) + compare(control.horizontalAlignment, data.textAlignment) for (var i = 0; i < control.children.length; ++i) { if (control.children[i].hasOwnProperty("horizontalAlignment")) - compare(control.children[i].horizontalAlignment, Text.AlignRight) // placeholder + compare(control.children[i].effectiveHorizontalAlignment, data.placeholderAlignment) // placeholder } control.verticalAlignment = TextArea.AlignBottom @@ -106,8 +152,6 @@ TestCase { if (control.children[j].hasOwnProperty("verticalAlignment")) compare(control.children[j].verticalAlignment, Text.AlignBottom) // placeholder } - - control.destroy() } function test_font_explicit_attributes_data() { @@ -124,7 +168,7 @@ TestCase { } function test_font_explicit_attributes(data) { - var control = textArea.createObject(testCase) + var control = createTemporaryObject(textArea, testCase) verify(control) var child = textArea.createObject(control) @@ -149,12 +193,10 @@ TestCase { compare(child.font[data.tag], defaultValue) compare(childSpy.count, 0) - - control.destroy() } function test_flickable() { - var control = flickable.createObject(testCase, {text:"line0", selectByMouse: true}) + var control = createTemporaryObject(flickable, testCase, {text:"line0", selectByMouse: true}) verify(control) var textArea = control.TextArea.flickable @@ -190,8 +232,6 @@ TestCase { verify(above > 0 && above < center) mouseClick(textArea, control.width / 2, 0) compare(textArea.cursorPosition, center) // no change - - control.destroy() } function test_warning() { @@ -207,7 +247,7 @@ TestCase { } function test_hover(data) { - var control = textArea.createObject(testCase, {text: "TextArea", hoverEnabled: data.hoverEnabled}) + var control = createTemporaryObject(textArea, testCase, {text: "TextArea", hoverEnabled: data.hoverEnabled}) verify(control) compare(control.hovered, false) @@ -217,8 +257,6 @@ TestCase { mouseMove(control, -1, -1) compare(control.hovered, false) - - control.destroy() } function test_pressedReleased_data() { @@ -274,7 +312,7 @@ TestCase { } function test_pressedReleased(data) { - var mouseArea = mouseAreaComponent.createObject(testCase) + var mouseArea = createTemporaryObject(mouseAreaComponent, testCase) verify(mouseArea) var control = textArea.createObject(mouseArea, {text: "TextArea"}) verify(control) @@ -321,8 +359,6 @@ TestCase { mouseRelease(control, data.x, data.y, data.button) compare(controlReleasedSpy.count, data.controlReleaseEvent ? 1 : 0) compare(parentReleasedSpy.count, data.parentReleaseEvent ? 1 : 0) - - mouseArea.destroy() } Component { @@ -346,7 +382,7 @@ TestCase { } function test_ignorePressRelease() { - var mouseArea = mouseAreaComponent.createObject(testCase) + var mouseArea = createTemporaryObject(mouseAreaComponent, testCase) verify(mouseArea) var control = ignoreTextArea.createObject(mouseArea) verify(control) @@ -385,12 +421,10 @@ TestCase { compare(parentReleasedSpy.count, 1) control.onPressed.disconnect(checkEventAccepted) control.onReleased.disconnect(checkEventIgnored) - - mouseArea.destroy() } function test_multiClick() { - var control = textArea.createObject(testCase, {text: "Qt Quick Controls 2 TextArea", selectByMouse: true}) + var control = createTemporaryObject(textArea, testCase, {text: "Qt Quick Controls 2 TextArea", selectByMouse: true}) verify(control) waitForRendering(control) @@ -404,7 +438,5 @@ TestCase { // tripple click -> select whole line mouseClick(control, rect.x + rect.width / 2, rect.y + rect.height / 2) compare(control.selectedText, "Qt Quick Controls 2 TextArea") - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_textfield.qml b/tests/auto/controls/data/tst_textfield.qml index 4847dffe..a6686a13 100644 --- a/tests/auto/controls/data/tst_textfield.qml +++ b/tests/auto/controls/data/tst_textfield.qml @@ -61,13 +61,12 @@ TestCase { } function test_creation() { - var control = textField.createObject(testCase) + var control = createTemporaryObject(textField, testCase) verify(control) - control.destroy() } function test_implicitSize() { - var control = textField.createObject(testCase) + var control = createTemporaryObject(textField, testCase) verify(control.implicitWidth > control.leftPadding + control.rightPadding) var implicitWidthSpy = signalSpy.createObject(control, { target: control, signalName: "implicitWidthChanged"} ) @@ -97,18 +96,65 @@ TestCase { compare(control.implicitHeight, control.contentHeight + control.topPadding + control.bottomPadding) compare(implicitWidthSpy.count, 4) compare(implicitHeightSpy.count, 2) + } - control.destroy() + function test_alignment_data() { + return [ + { tag: "empty", text: "", placeholderText: "", textAlignment: undefined, placeholderAlignment: Qt.AlignLeft }, + { tag: "empty,left", text: "", placeholderText: "", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft }, + { tag: "empty,center", text: "", placeholderText: "", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter }, + { tag: "empty,right", text: "", placeholderText: "", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight }, + + { tag: "empty,ltr", text: "", placeholderText: "Search", textAlignment: undefined, placeholderAlignment: Qt.AlignLeft }, + { tag: "empty,ltr,left", text: "", placeholderText: "Search", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft }, + { tag: "empty,ltr,center", text: "", placeholderText: "Search", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter }, + { tag: "empty,ltr,right", text: "", placeholderText: "Search", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight }, + + { tag: "empty,rtl", text: "", placeholderText: "بحث", textAlignment: undefined, placeholderAlignment: Qt.AlignRight }, + { tag: "empty,rtl,left", text: "", placeholderText: "بحث", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft }, + { tag: "empty,rtl,center", text: "", placeholderText: "بحث", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter }, + { tag: "empty,rtl,right", text: "", placeholderText: "بحث", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight }, + + { tag: "ltr,empty", text: "Text", placeholderText: "", textAlignment: undefined, placeholderAlignment: Qt.AlignLeft }, + { tag: "ltr,empty,left", text: "Text", placeholderText: "", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft }, + { tag: "ltr,empty,center", text: "Text", placeholderText: "", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter }, + { tag: "ltr,empty,right", text: "Text", placeholderText: "", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight }, + + { tag: "ltr,ltr", text: "Text", placeholderText: "Search", textAlignment: undefined, placeholderAlignment: Qt.AlignLeft }, + { tag: "ltr,ltr,left", text: "Text", placeholderText: "Search", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft }, + { tag: "ltr,ltr,center", text: "Text", placeholderText: "Search", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter }, + { tag: "ltr,ltr,right", text: "Text", placeholderText: "Search", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight }, + + { tag: "ltr,rtl", text: "Text", placeholderText: "بحث", textAlignment: undefined, placeholderAlignment: Qt.AlignRight }, + { tag: "ltr,rtl,left", text: "Text", placeholderText: "بحث", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft }, + { tag: "ltr,rtl,center", text: "Text", placeholderText: "بحث", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter }, + { tag: "ltr,rtl,right", text: "Text", placeholderText: "بحث", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight }, + + { tag: "rtl,empty", text: "نص", placeholderText: "", textAlignment: undefined, placeholderAlignment: Qt.AlignLeft }, + { tag: "rtl,empty,left", text: "نص", placeholderText: "", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft }, + { tag: "rtl,empty,center", text: "نص", placeholderText: "", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter }, + { tag: "rtl,empty,right", text: "نص", placeholderText: "", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight }, + + { tag: "rtl,ltr", text: "نص", placeholderText: "Search", textAlignment: undefined, placeholderAlignment: Qt.AlignLeft }, + { tag: "rtl,ltr,left", text: "نص", placeholderText: "Search", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft }, + { tag: "rtl,ltr,center", text: "نص", placeholderText: "Search", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter }, + { tag: "rtl,ltr,right", text: "نص", placeholderText: "Search", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight }, + + { tag: "rtl,rtl", text: "نص", placeholderText: "بحث", textAlignment: undefined, placeholderAlignment: Qt.AlignRight }, + { tag: "rtl,rtl,left", text: "نص", placeholderText: "بحث", textAlignment: Qt.AlignLeft, placeholderAlignment: Qt.AlignLeft }, + { tag: "rtl,rtl,center", text: "نص", placeholderText: "بحث", textAlignment: Qt.AlignHCenter, placeholderAlignment: Qt.AlignHCenter }, + { tag: "rtl,rtl,right", text: "نص", placeholderText: "بحث", textAlignment: Qt.AlignRight, placeholderAlignment: Qt.AlignRight }, + ] } - function test_alignment() { - var control = textField.createObject(testCase) + function test_alignment(data) { + var control = createTemporaryObject(textField, testCase, {text: data.text, placeholderText: data.placeholderText, horizontalAlignment: data.textAlignment}) - control.horizontalAlignment = TextField.AlignRight - compare(control.horizontalAlignment, TextField.AlignRight) + if (data.textAlignment !== undefined) + compare(control.horizontalAlignment, data.textAlignment) for (var i = 0; i < control.children.length; ++i) { if (control.children[i].hasOwnProperty("horizontalAlignment")) - compare(control.children[i].horizontalAlignment, Text.AlignRight) // placeholder + compare(control.children[i].effectiveHorizontalAlignment, data.placeholderAlignment) // placeholder } control.verticalAlignment = TextField.AlignBottom @@ -117,8 +163,6 @@ TestCase { if (control.children[j].hasOwnProperty("verticalAlignment")) compare(control.children[j].verticalAlignment, Text.AlignBottom) // placeholder } - - control.destroy() } function test_font_explicit_attributes_data() { @@ -135,7 +179,7 @@ TestCase { } function test_font_explicit_attributes(data) { - var control = textField.createObject(testCase) + var control = createTemporaryObject(textField, testCase) verify(control) var child = textField.createObject(control) @@ -160,8 +204,6 @@ TestCase { compare(child.font[data.tag], defaultValue) compare(childSpy.count, 0) - - control.destroy() } function test_hover_data() { @@ -172,7 +214,7 @@ TestCase { } function test_hover(data) { - var control = textField.createObject(testCase, {hoverEnabled: data.hoverEnabled}) + var control = createTemporaryObject(textField, testCase, {hoverEnabled: data.hoverEnabled}) verify(control) compare(control.hovered, false) @@ -182,8 +224,6 @@ TestCase { mouseMove(control, -1, -1) compare(control.hovered, false) - - control.destroy() } function test_pressedReleased_data() { @@ -239,7 +279,7 @@ TestCase { } function test_pressedReleased(data) { - var mouseArea = mouseAreaComponent.createObject(testCase) + var mouseArea = createTemporaryObject(mouseAreaComponent, testCase) verify(mouseArea) var control = textField.createObject(mouseArea) verify(control) @@ -286,8 +326,6 @@ TestCase { mouseRelease(control, data.x, data.y, data.button) compare(controlReleasedSpy.count, data.controlReleaseEvent ? 1 : 0) compare(parentReleasedSpy.count, data.parentReleaseEvent ? 1 : 0) - - mouseArea.destroy() } Component { @@ -311,7 +349,7 @@ TestCase { } function test_ignorePressRelease() { - var mouseArea = mouseAreaComponent.createObject(testCase) + var mouseArea = createTemporaryObject(mouseAreaComponent, testCase) verify(mouseArea) var control = ignoreTextField.createObject(mouseArea) verify(control) @@ -350,12 +388,10 @@ TestCase { compare(parentReleasedSpy.count, 1) control.onPressed.disconnect(checkEventAccepted) control.onReleased.disconnect(checkEventIgnored) - - mouseArea.destroy() } function test_multiClick() { - var control = textField.createObject(testCase, {text: "Qt Quick Controls 2 TextArea", selectByMouse: true}) + var control = createTemporaryObject(textField, testCase, {text: "Qt Quick Controls 2 TextArea", selectByMouse: true}) verify(control) waitForRendering(control) @@ -369,7 +405,5 @@ TestCase { // tripple click -> select whole line mouseClick(control, rect.x + rect.width / 2, rect.y + rect.height / 2) compare(control.selectedText, "Qt Quick Controls 2 TextArea") - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_toolbar.qml b/tests/auto/controls/data/tst_toolbar.qml index 49459b12..56d279ef 100644 --- a/tests/auto/controls/data/tst_toolbar.qml +++ b/tests/auto/controls/data/tst_toolbar.qml @@ -90,49 +90,41 @@ TestCase { } function test_empty() { - var control = toolBar.createObject(testCase) + var control = createTemporaryObject(toolBar, testCase) verify(control) verify(control.contentItem) compare(control.contentWidth, 0) compare(control.contentHeight, 0) - - control.destroy() } function test_oneChild() { - var control = oneChildBar.createObject(testCase) + var control = createTemporaryObject(oneChildBar, testCase) verify(control) compare(control.contentWidth, 100) compare(control.contentHeight, 30) verify(control.implicitWidth >= 100) verify(control.implicitHeight >= 30) - - control.destroy() } function test_twoChildren() { - var control = twoChildrenBar.createObject(testCase) + var control = createTemporaryObject(twoChildrenBar, testCase) verify(control) compare(control.contentWidth, 0) compare(control.contentHeight, 0) verify(control.implicitWidth >= 0) verify(control.implicitHeight >= 0) - - control.destroy() } function test_contentItem() { - var control = contentBar.createObject(testCase) + var control = createTemporaryObject(contentBar, testCase) verify(control) compare(control.contentWidth, 100) compare(control.contentHeight, 30) verify(control.implicitWidth >= 100) verify(control.implicitHeight >= 30) - - control.destroy() } } diff --git a/tests/auto/controls/data/tst_toolbutton.qml b/tests/auto/controls/data/tst_toolbutton.qml index c00661f0..eef15d02 100644 --- a/tests/auto/controls/data/tst_toolbutton.qml +++ b/tests/auto/controls/data/tst_toolbutton.qml @@ -61,7 +61,7 @@ TestCase { } function test_text() { - var control = toolButton.createObject(testCase) + var control = createTemporaryObject(toolButton, testCase) verify(control) compare(control.text, "") @@ -69,12 +69,10 @@ TestCase { compare(control.text, "ToolButton") control.text = "" compare(control.text, "") - - control.destroy() } function test_mouse() { - var control = toolButton.createObject(testCase) + var control = createTemporaryObject(toolButton, testCase) verify(control) var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) @@ -140,12 +138,10 @@ TestCase { compare(downSpy.count, 6) compare(control.pressed, false) compare(control.down, false) - - control.destroy() } function test_keys() { - var control = toolButton.createObject(testCase) + var control = createTemporaryObject(toolButton, testCase) verify(control) var clickedSpy = signalSpy.createObject(control, {target: control, signalName: "clicked"}) @@ -168,14 +164,11 @@ TestCase { keyClick(keys[i]) compare(clickedSpy.count, 2) } - - control.destroy() } function test_baseline() { - var control = toolButton.createObject(testCase) + var control = createTemporaryObject(toolButton, testCase) verify(control) compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) - control.destroy() } } diff --git a/tests/auto/controls/data/tst_toolseparator.qml b/tests/auto/controls/data/tst_toolseparator.qml index a87ca5a2..bd11bfb1 100644 --- a/tests/auto/controls/data/tst_toolseparator.qml +++ b/tests/auto/controls/data/tst_toolseparator.qml @@ -55,12 +55,10 @@ TestCase { } function test_size() { - var control = toolSeparator.createObject(testCase); + var control = createTemporaryObject(toolSeparator, testCase); verify(control); verify(control.width > 1); verify(control.height > 1); - - control.destroy(); } Component { @@ -69,7 +67,7 @@ TestCase { } function test_orientation() { - var control = toolSeparator.createObject(testCase); + var control = createTemporaryObject(toolSeparator, testCase); verify(control); compare(control.horizontal, false); compare(control.vertical, true); @@ -93,7 +91,5 @@ TestCase { compare(control.horizontal, false); compare(control.vertical, true); compare(orientationSpy.count, 2); - - control.destroy(); } } diff --git a/tests/auto/controls/data/tst_tooltip.qml b/tests/auto/controls/data/tst_tooltip.qml index 3e50ee25..9529922b 100644 --- a/tests/auto/controls/data/tst_tooltip.qml +++ b/tests/auto/controls/data/tst_tooltip.qml @@ -69,6 +69,11 @@ TestCase { id: object } + SignalSpy { + id: sharedSpy + target: ToolTip.toolTip + } + function test_properties_data() { return [ {tag: "text", property: "text", defaultValue: "", setValue: "Hello", signalName: "textChanged"}, @@ -119,8 +124,9 @@ TestCase { verify(spy2.valid) var sharedTip = ToolTip.toolTip - var sharedSpy = signalSpy.createObject(testCase, {target: sharedTip, signalName: data.signalName}) + sharedSpy.signalName = data.signalName verify(sharedSpy.valid) + sharedSpy.clear() // change attached properties while the shared tooltip is not visible item1.ToolTip[data.property] = data.setValue diff --git a/tests/auto/controls/data/tst_tumbler.qml b/tests/auto/controls/data/tst_tumbler.qml index c200d733..d371c877 100644 --- a/tests/auto/controls/data/tst_tumbler.qml +++ b/tests/auto/controls/data/tst_tumbler.qml @@ -40,7 +40,7 @@ import QtQuick 2.2 import QtTest 1.0 -import QtQuick.Controls 2.1 +import QtQuick.Controls 2.2 TestCase { id: testCase @@ -51,9 +51,6 @@ 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 @@ -77,23 +74,8 @@ TestCase { } } - function init() { - cleanupItem = itemComponent.createObject(testCase); - verify(cleanupItem); - } - - function cleanup() { - cleanupItem.destroy(); - // Waiting until it's deleted before continuing makes debugging - // test failures much easier, because there aren't unrelated items hanging around. - tryVerify(function() { return !tumbler; }); - } - function createTumbler(args) { - if (args === undefined) - tumbler = tumblerComponent.createObject(cleanupItem); - else - tumbler = tumblerComponent.createObject(cleanupItem, args); + tumbler = createTemporaryObject(tumblerComponent, testCase, args); verify(tumbler, "Tumbler: failed to create an instance"); tumblerView = findView(tumbler); verify(tumblerView); @@ -278,7 +260,7 @@ TestCase { function test_currentIndexAtCreation(data) { // Test setting currentIndex at creation time - tumbler = data.component.createObject(cleanupItem); + tumbler = createTemporaryObject(data.component, testCase); 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. @@ -344,7 +326,7 @@ TestCase { wait(tumblerView.highlightMoveDuration); var firstItemCenterPos = itemCenterPos(1); var firstItem = tumblerView.itemAt(firstItemCenterPos.x, firstItemCenterPos.y); - var actualPos = cleanupItem.mapFromItem(firstItem, 0, 0); + var actualPos = testCase.mapFromItem(firstItem, 0, 0); compare(actualPos.x, tumbler.leftPadding); compare(actualPos.y, tumbler.topPadding + 40); @@ -355,7 +337,7 @@ TestCase { firstItem = tumblerView.itemAt(firstItemCenterPos.x, firstItemCenterPos.y); verify(firstItem); // Test QTBUG-40298. - actualPos = cleanupItem.mapFromItem(firstItem, 0, 0); + actualPos = testCase.mapFromItem(firstItem, 0, 0); compare(actualPos.x, tumbler.leftPadding); compare(actualPos.y, tumbler.topPadding); @@ -372,11 +354,11 @@ TestCase { } function test_focusPastTumbler() { - tumbler = tumblerComponent.createObject(cleanupItem); + tumbler = createTemporaryObject(tumblerComponent, testCase); verify(tumbler); - var mouseArea = Qt.createQmlObject( - "import QtQuick 2.2; TextInput { activeFocusOnTab: true; width: 50; height: 50 }", cleanupItem, ""); + var mouseArea = createTemporaryQmlObject( + "import QtQuick 2.2; TextInput { activeFocusOnTab: true; width: 50; height: 50 }", testCase, ""); tumbler.forceActiveFocus(); verify(tumbler.activeFocus); @@ -389,7 +371,7 @@ TestCase { function test_datePicker() { var component = Qt.createComponent("TumblerDatePicker.qml"); compare(component.status, Component.Ready, component.errorString()); - tumbler = component.createObject(cleanupItem); + tumbler = createTemporaryObject(component, testCase); // Should not be any warnings. tryCompare(tumbler.dayTumbler, "currentIndex", 0); @@ -449,7 +431,7 @@ TestCase { } function test_listViewTimePicker() { - var root = timePickerComponent.createObject(cleanupItem); + var root = createTemporaryObject(timePickerComponent, testCase); verify(root); mouseDrag(root.minuteTumbler, root.minuteTumbler.width / 2, root.minuteTumbler.height / 2, 0, 50); @@ -566,7 +548,7 @@ TestCase { } function test_countWrap() { - tumbler = tumblerComponent.createObject(cleanupItem); + tumbler = createTemporaryObject(tumblerComponent, testCase); verify(tumbler); // Check that a count that is less than visibleItemCount results in wrap being set to false. @@ -578,7 +560,7 @@ TestCase { function test_explicitlyNonwrapping() { // Check that explicitly setting wrap to false works even when it was implicitly false. - var explicitlyNonWrapping = twoItemTumbler.createObject(cleanupItem); + var explicitlyNonWrapping = createTemporaryObject(twoItemTumbler, testCase); verify(explicitlyNonWrapping); tryCompare(explicitlyNonWrapping, "wrap", false); @@ -595,7 +577,7 @@ TestCase { function test_explicitlyWrapping() { // Check that explicitly setting wrap to true works even when it was implicitly true. - var explicitlyWrapping = tenItemTumbler.createObject(cleanupItem); + var explicitlyWrapping = createTemporaryObject(tenItemTumbler, testCase); verify(explicitlyWrapping); compare(explicitlyWrapping.wrap, true); @@ -623,7 +605,7 @@ TestCase { snapMode: ListView.SnapToItem highlightRangeMode: ListView.StrictlyEnforceRange preferredHighlightBegin: height / 2 - (height / listViewTumbler.visibleItemCount / 2) - preferredHighlightEnd: height / 2 + (height / listViewTumbler.visibleItemCount / 2) + preferredHighlightEnd: height / 2 + (height / listViewTumbler.visibleItemCount / 2) clip: true } } @@ -667,7 +649,7 @@ TestCase { } function test_customContentItemAtConstruction(data) { - var tumbler = data.component.createObject(cleanupItem); + var tumbler = createTemporaryObject(data.component, testCase); // Shouldn't assert. tumbler.model = 5; @@ -707,7 +689,7 @@ TestCase { var contentItemComponent = Qt.createComponent(data.componentPath); compare(contentItemComponent.status, Component.Ready); - var customContentItem = contentItemComponent.createObject(tumbler); + var customContentItem = createTemporaryObject(contentItemComponent, tumbler); tumbler.contentItem = customContentItem; compare(tumbler.count, 5); tumblerView = findView(tumbler); @@ -921,7 +903,7 @@ TestCase { } function test_attachedProperties() { - tumbler = tumblerComponent.createObject(cleanupItem); + tumbler = createTemporaryObject(tumblerComponent, testCase); verify(tumbler); // TODO: crashes somewhere in QML's guts @@ -932,10 +914,10 @@ TestCase { // tumbler.contentItem.offset += 1; ignoreWarning("Tumbler: attached properties must be accessed through a delegate item that has a parent"); - noParentDelegateComponent.createObject(null); + createTemporaryObject(noParentDelegateComponent, null); ignoreWarning("Tumbler: attempting to access attached property on item without an \"index\" property"); - var object = noParentDelegateComponent.createObject(cleanupItem); + var object = createTemporaryObject(noParentDelegateComponent, testCase); verify(object); } @@ -1039,4 +1021,30 @@ TestCase { ++tumbler.currentIndex; tryCompare(tumblerView, "offset", 4, tumblerView.highlightMoveDuration * 2); } + + function test_moving_data() { + return [ + { tag: "wrap:true", wrap: true }, + { tag: "wrap:false", wrap: false } + ] + } + + function test_moving(data) { + createTumbler({wrap: data.wrap, model: 5}) + compare(tumbler.wrap, data.wrap) + compare(tumbler.moving, false) + + waitForRendering(tumbler) + + mousePress(tumbler, tumbler.width / 2, tumbler.height / 2, Qt.LeftButton) + compare(tumbler.moving, false) + + for (var y = tumbler.height / 2; y >= tumbler.height / 4; y -= 10) + mouseMove(tumbler, tumbler.width / 2, y, 1) + compare(tumbler.moving, true) + + mouseRelease(tumbler, tumbler.width / 2, tumbler.height / 4, Qt.LeftButton) + compare(tumbler.moving, true) + tryCompare(tumbler, "moving", false) + } } diff --git a/tests/auto/controls/default/tst_default.cpp b/tests/auto/controls/default/tst_default.cpp index 80ae5160..d21f13ad 100644 --- a/tests/auto/controls/default/tst_default.cpp +++ b/tests/auto/controls/default/tst_default.cpp @@ -40,5 +40,6 @@ int main(int argc, char *argv[]) { QTEST_ADD_GPU_BLACKLIST_SUPPORT QTEST_SET_MAIN_SOURCE_PATH + qputenv("QML_NO_TOUCH_COMPRESSION", "1"); return quick_test_main(argc, argv, "tst_controls::Default", TST_CONTROLS_DATA); } diff --git a/tests/auto/controls/material/tst_material.cpp b/tests/auto/controls/material/tst_material.cpp index 5964abf8..7d1953c2 100644 --- a/tests/auto/controls/material/tst_material.cpp +++ b/tests/auto/controls/material/tst_material.cpp @@ -41,6 +41,7 @@ int main(int argc, char *argv[]) { QTEST_ADD_GPU_BLACKLIST_SUPPORT QTEST_SET_MAIN_SOURCE_PATH + qputenv("QML_NO_TOUCH_COMPRESSION", "1"); QQuickStyle::setStyle("Material"); return quick_test_main(argc, argv, "tst_controls::Material", TST_CONTROLS_DATA); } diff --git a/tests/auto/controls/universal/tst_universal.cpp b/tests/auto/controls/universal/tst_universal.cpp index 8372aeba..d293dc4c 100644 --- a/tests/auto/controls/universal/tst_universal.cpp +++ b/tests/auto/controls/universal/tst_universal.cpp @@ -41,6 +41,7 @@ int main(int argc, char *argv[]) { QTEST_ADD_GPU_BLACKLIST_SUPPORT QTEST_SET_MAIN_SOURCE_PATH + qputenv("QML_NO_TOUCH_COMPRESSION", "1"); QQuickStyle::setStyle("Universal"); return quick_test_main(argc, argv, "tst_controls::Universal", TST_CONTROLS_DATA); } diff --git a/tests/auto/drawer/tst_drawer.cpp b/tests/auto/drawer/tst_drawer.cpp index cfc403a2..251f5567 100644 --- a/tests/auto/drawer/tst_drawer.cpp +++ b/tests/auto/drawer/tst_drawer.cpp @@ -84,6 +84,9 @@ private slots: void touch(); void grabber(); + + void interactive_data(); + void interactive(); }; void tst_Drawer::visible_data() @@ -799,6 +802,60 @@ void tst_Drawer::grabber() QTRY_COMPARE(popupClosedSpy.count(), 1); } +void tst_Drawer::interactive_data() +{ + QTest::addColumn<QString>("source"); + QTest::newRow("Window") << "window.qml"; + QTest::newRow("ApplicationWindow") << "applicationwindow.qml"; +} + +void tst_Drawer::interactive() +{ + QFETCH(QString, source); + QQuickApplicationHelper helper(this, source); + + QQuickWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowActive(window)); + + QQuickDrawer *drawer = window->property("drawer").value<QQuickDrawer*>(); + QVERIFY(drawer); + + drawer->setInteractive(false); + + QSignalSpy openedSpy(drawer, SIGNAL(opened())); + QSignalSpy aboutToHideSpy(drawer, SIGNAL(aboutToHide())); + QVERIFY(openedSpy.isValid()); + QVERIFY(aboutToHideSpy.isValid()); + + drawer->open(); + QVERIFY(openedSpy.wait()); + + // click outside + QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(300, 100)); + QCOMPARE(aboutToHideSpy.count(), 0); + + // drag inside + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(drawer->width(), 0)); + QTest::mouseMove(window, QPoint(0, 0)); + QCOMPARE(drawer->position(), 1.0); + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(0, 0)); + QCOMPARE(drawer->position(), 1.0); + QCOMPARE(aboutToHideSpy.count(), 0); + + // drag outside + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(window->width() - 1, 0)); + QTest::mouseMove(window, QPoint(0, 0)); + QCOMPARE(drawer->position(), 1.0); + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(0, 0)); + QCOMPARE(drawer->position(), 1.0); + QCOMPARE(aboutToHideSpy.count(), 0); + + // close on escape + QTest::keyClick(window, Qt::Key_Escape); + QCOMPARE(aboutToHideSpy.count(), 0); +} + QTEST_MAIN(tst_Drawer) #include "tst_drawer.moc" diff --git a/tests/auto/qquickstyle/tst_qquickstyle.cpp b/tests/auto/qquickstyle/tst_qquickstyle.cpp index cafe5df3..3487a21e 100644 --- a/tests/auto/qquickstyle/tst_qquickstyle.cpp +++ b/tests/auto/qquickstyle/tst_qquickstyle.cpp @@ -50,6 +50,7 @@ private slots: void lookup(); void commandLineArgument(); void environmentVariables(); + void availableStyles(); }; void tst_QQuickStyle::init() @@ -94,6 +95,13 @@ void tst_QQuickStyle::environmentVariables() QCOMPARE(QQuickStylePrivate::fallbackStyle(), QString("EnvVarFallbackStyle")); } +void tst_QQuickStyle::availableStyles() +{ + QStringList styles = QQuickStyle::availableStyles(); + QVERIFY(!styles.isEmpty()); + QCOMPARE(styles.first(), QString("Default")); +} + QTEST_MAIN(tst_QQuickStyle) #include "tst_qquickstyle.moc" diff --git a/tests/auto/revisions/tst_revisions.cpp b/tests/auto/revisions/tst_revisions.cpp index 0547941f..8a7a5d6e 100644 --- a/tests/auto/revisions/tst_revisions.cpp +++ b/tests/auto/revisions/tst_revisions.cpp @@ -52,12 +52,9 @@ void tst_revisions::revisions_data() { QTest::addColumn<int>("revision"); - // In theory, this could be done in a loop from 5.7 to QT_VERSION, but - // the test would immediately fail when the Qt version was bumped up. - // Therefore it is better to just add these lines by hand when adding - // new revisions. - QTest::newRow("2.0") << 0; // Qt 5.7 - QTest::newRow("2.1") << 1; // Qt 5.8 + // Qt 5.7: 2.0, Qt 5.8: 2.1, Qt 5.9: 2.2... + for (int i = 0; i <= QT_VERSION_MINOR - 7; ++i) + QTest::newRow(qPrintable(QString("2.%1").arg(i))) << i; } void tst_revisions::revisions() @@ -67,6 +64,7 @@ void tst_revisions::revisions() QQmlEngine engine; QQmlComponent component(&engine); component.setData(QString("import QtQuick 2.0; \ + import QtQuick.Templates 2.%1 as T; \ import QtQuick.Controls 2.%1; \ import QtQuick.Controls.impl 2.%1; \ import QtQuick.Controls.Material 2.%1; \ diff --git a/tests/auto/sanity/BLACKLIST b/tests/auto/sanity/BLACKLIST index 768f3985..965790e7 100644 --- a/tests/auto/sanity/BLACKLIST +++ b/tests/auto/sanity/BLACKLIST @@ -1,10 +1,4 @@ -[signalHandlers:material/SpinBox.qml] -* -[signalHandlers:material/TextArea.qml] -* -[signalHandlers:material/TextField.qml] -* -[attachedObjects:controls/ComboBox.qml] +[signalHandlers:material/CursorDelegate.qml] * [attachedObjects:material/ComboBox.qml] * diff --git a/tests/auto/sanity/tst_sanity.cpp b/tests/auto/sanity/tst_sanity.cpp index 5168219b..8d3fee7b 100644 --- a/tests/auto/sanity/tst_sanity.cpp +++ b/tests/auto/sanity/tst_sanity.cpp @@ -314,7 +314,7 @@ void tst_Sanity::attachedObjects_data() QTest::addColumn<QUrl>("url"); addTestRows(&engine, "calendar", "Qt/labs/calendar"); addTestRows(&engine, "controls", "QtQuick/Controls.2", QStringList() << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator"); - addTestRows(&engine, "controls/material", "QtQuick/Controls.2/Material", QStringList() << "Ripple" << "SliderHandle" << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator" << "BoxShadow" << "ElevationEffect"); + addTestRows(&engine, "controls/material", "QtQuick/Controls.2/Material", QStringList() << "Ripple" << "SliderHandle" << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator" << "BoxShadow" << "ElevationEffect" << "CursorDelegate"); addTestRows(&engine, "controls/universal", "QtQuick/Controls.2/Universal", QStringList() << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator"); } diff --git a/tests/auto/shared/util.h b/tests/auto/shared/util.h index 43b6e690..4295d798 100644 --- a/tests/auto/shared/util.h +++ b/tests/auto/shared/util.h @@ -65,7 +65,7 @@ public: inline QString dataDirectory() const { return m_dataDirectory; } inline QUrl dataDirectoryUrl() const { return m_dataDirectoryUrl; } - inline QString directory() const { return m_directory; } + inline QString directory() const { return m_directory; } static inline QQmlDataTest *instance() { return m_instance; } |