diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-04-21 15:41:48 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-04-21 15:15:40 +0000 |
commit | 8425727f242400f2f1218e410804570384fdf20d (patch) | |
tree | f6bb884b375c6ad9f38fbeb48e769ee72fe1a687 /tests/auto/controls/data/tst_spinbox.qml | |
parent | d82dcc5dc79f140b68697b6b092601e0861b0c2c (diff) |
tst_spinbox: make test_keys() and test_wheel() data-driven
This makes it much easier to add new data rows for wrapping SpinBox.
The formulas used to calculate expected values would get complicated
and hard to read with wrapping enabled. Passing the expected values
step by step is a lot easier to understand.
Task-number: QTBUG-58760
Change-Id: Id4894e5b104f36aa9b4771fab2ff833a28a9c83b
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/controls/data/tst_spinbox.qml')
-rw-r--r-- | tests/auto/controls/data/tst_spinbox.qml | 139 |
1 files changed, 51 insertions, 88 deletions
diff --git a/tests/auto/controls/data/tst_spinbox.qml b/tests/auto/controls/data/tst_spinbox.qml index 6d681d60..399c9b9b 100644 --- a/tests/auto/controls/data/tst_spinbox.qml +++ b/tests/auto/controls/data/tst_spinbox.qml @@ -275,8 +275,16 @@ TestCase { compare(valueModifiedSpy.count, 2) } - function test_keys() { - var control = createTemporaryObject(spinBox, testCase) + function test_keys_data() { + return [ + { tag: "1", from: 1, to: 10, value: 1, stepSize: 1, upSteps: [2,3,4], downSteps: [3,2,1,1] }, + { tag: "2", from: 1, to: 10, value: 10, stepSize: 2, upSteps: [10,10], downSteps: [8,6,4] }, + { tag: "25", from: 0, to: 100, value: 50, stepSize: 25, upSteps: [75,100,100], downSteps: [75,50,25,0,0] } + ] + } + + function test_keys(data) { + var control = createTemporaryObject(spinBox, testCase, {from: data.from, to: data.to, value: data.value, stepSize: data.stepSize}) verify(control) var upPressedCount = 0 @@ -295,47 +303,30 @@ TestCase { control.forceActiveFocus() verify(control.activeFocus) - control.value = 50 - compare(control.value, 50) - - for (var d1 = 1; d1 <= 10; ++d1) { - keyPress(Qt.Key_Down) - compare(control.down.pressed, true) - compare(control.up.pressed, false) - compare(downPressedSpy.count, ++downPressedCount) - compare(valueModifiedSpy.count, ++valueModifiedCount) - - compare(control.value, 50 - d1) - - keyRelease(Qt.Key_Down) - compare(control.down.pressed, false) - compare(control.up.pressed, false) - compare(downPressedSpy.count, ++downPressedCount) - compare(valueModifiedSpy.count, valueModifiedCount) - } - compare(control.value, 40) - - for (var i1 = 1; i1 <= 10; ++i1) { + for (var u = 0; u < data.upSteps.length; ++u) { + var wasUpEnabled = control.value < control.to keyPress(Qt.Key_Up) - compare(control.up.pressed, true) + compare(control.up.pressed, wasUpEnabled) compare(control.down.pressed, false) - compare(upPressedSpy.count, ++upPressedCount) - compare(valueModifiedSpy.count, ++valueModifiedCount) + if (wasUpEnabled) { + ++upPressedCount + ++valueModifiedCount + } + compare(upPressedSpy.count, upPressedCount) + compare(valueModifiedSpy.count, valueModifiedCount) - compare(control.value, 40 + i1) + compare(control.value, data.upSteps[u]) keyRelease(Qt.Key_Up) compare(control.down.pressed, false) compare(control.up.pressed, false) - compare(upPressedSpy.count, ++upPressedCount) + if (wasUpEnabled) + ++upPressedCount + compare(upPressedSpy.count, upPressedCount) compare(valueModifiedSpy.count, valueModifiedCount) } - compare(control.value, 50) - control.stepSize = 25 - compare(control.stepSize, 25) - - for (var d2 = 1; d2 <= 10; ++d2) { + for (var d = 0; d < data.downSteps.length; ++d) { var wasDownEnabled = control.value > control.from keyPress(Qt.Key_Down) compare(control.down.pressed, wasDownEnabled) @@ -347,7 +338,7 @@ TestCase { compare(downPressedSpy.count, downPressedCount) compare(valueModifiedSpy.count, valueModifiedCount) - compare(control.value, Math.max(0, 50 - d2 * 25)) + compare(control.value, data.downSteps[d]) keyRelease(Qt.Key_Down) compare(control.down.pressed, false) @@ -357,31 +348,6 @@ TestCase { compare(downPressedSpy.count, downPressedCount) compare(valueModifiedSpy.count, valueModifiedCount) } - compare(control.value, 0) - - for (var i2 = 1; i2 <= 10; ++i2) { - var wasUpEnabled = control.value < control.to - keyPress(Qt.Key_Up) - compare(control.up.pressed, wasUpEnabled) - compare(control.down.pressed, false) - if (wasUpEnabled) { - ++upPressedCount - ++valueModifiedCount - } - compare(upPressedSpy.count, upPressedCount) - compare(valueModifiedSpy.count, valueModifiedCount) - - compare(control.value, Math.min(99, i2 * 25)) - - keyRelease(Qt.Key_Up) - compare(control.down.pressed, false) - compare(control.up.pressed, false) - if (wasUpEnabled) - ++upPressedCount - compare(upPressedSpy.count, upPressedCount) - compare(valueModifiedSpy.count, valueModifiedCount) - } - compare(control.value, 99) } function test_locale() { @@ -443,46 +409,43 @@ TestCase { compare(control.value, 5) } + function test_wheel_data() { + return [ + { tag: "1", from: 1, to: 10, value: 1, stepSize: 1, upSteps: [2,3,4], downSteps: [3,2,1,1] }, + { tag: "2", from: 1, to: 10, value: 10, stepSize: 2, upSteps: [10,10], downSteps: [8,6,4] }, + { tag: "25", from: 0, to: 100, value: 50, stepSize: 25, upSteps: [75,100,100], downSteps: [75,50,25,0,0] } + ] + } + function test_wheel(data) { - var control = createTemporaryObject(spinBox, testCase, {wheelEnabled: true}) + var control = createTemporaryObject(spinBox, testCase, {from: data.from, to: data.to, value: data.value, stepSize: data.stepSize, wheelEnabled: true}) verify(control) + var valueModifiedCount = 0 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 + for (var u = 0; u < data.upSteps.length; ++u) { + var wasUpEnabled = control.value < control.to + mouseWheel(control, control.width / 2, control.height / 2, delta, delta) + if (wasUpEnabled) + ++valueModifiedCount + compare(valueModifiedSpy.count, valueModifiedCount) - mouseWheel(control, control.width / 2, control.height / 2, delta, delta) - compare(control.value, 5) - compare(valueModifiedSpy.count, 4) + compare(control.value, data.upSteps[u]) + } - mouseWheel(control, control.width / 2, control.height / 2, 0.5 * delta, 0.5 * delta) - compare(control.value, 8) - compare(valueModifiedSpy.count, 5) + for (var d = 0; d < data.downSteps.length; ++d) { + var wasDownEnabled = control.value > control.from + mouseWheel(control, control.width / 2, control.height / 2, -delta, -delta) + if (wasDownEnabled) + ++valueModifiedCount + compare(valueModifiedSpy.count, valueModifiedCount) - mouseWheel(control, control.width / 2, control.height / 2, -delta, -delta) - compare(control.value, 3) - compare(valueModifiedSpy.count, 6) + compare(control.value, data.downSteps[d]) + } } function test_initiallyDisabledIndicators_data() { |