diff options
Diffstat (limited to 'tests/auto/controls/data/tst_rangeslider.qml')
-rw-r--r-- | tests/auto/controls/data/tst_rangeslider.qml | 278 |
1 files changed, 233 insertions, 45 deletions
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() } } |