From 624844f3db601b48205d7f545732870d45d78300 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Wed, 8 Oct 2014 18:14:43 +0200 Subject: [PATCH] Stabilize and fix comparisons in animator tests. compare() will compare properties of objects and neither Qt.rgba nor image.pixel created objects has enumeratable properties so compare is pretty much useless. Use verify + == which will rely on toString() which is ok. A few of the tests relied on execution order of signals emitted on animation.running being changed and would occasionally fail. Change-Id: I531c7f21b58a922a6be9ca2b6de120a68209a6d6 Reviewed-by: Michael Brasser --- tests/auto/qmltest/animators/tst_behavior.qml | 7 ++- tests/auto/qmltest/animators/tst_mixedparallel.qml | 4 +- .../auto/qmltest/animators/tst_mixedsequential.qml | 4 +- tests/auto/qmltest/animators/tst_opacity.qml | 3 +- tests/auto/qmltest/animators/tst_parallel.qml | 4 +- tests/auto/qmltest/animators/tst_rotation.qml | 5 +- tests/auto/qmltest/animators/tst_scale.qml | 5 +- .../auto/qmltest/animators/tst_transformorigin.qml | 72 +++++++++++----------- tests/auto/qmltest/animators/tst_transition.qml | 6 +- tests/auto/qmltest/animators/tst_x.qml | 7 +-- tests/auto/qmltest/animators/tst_y.qml | 7 +-- 11 files changed, 60 insertions(+), 64 deletions(-) diff --git a/tests/auto/qmltest/animators/tst_behavior.qml b/tests/auto/qmltest/animators/tst_behavior.qml index 0b74a74..87b0eff 100644 --- a/tests/auto/qmltest/animators/tst_behavior.qml +++ b/tests/auto/qmltest/animators/tst_behavior.qml @@ -47,8 +47,9 @@ Item { compare(box.scaleChangeCounter, 1); compare(box.scale, 2); var image = grabImage(root); - compare(image.pixel(0, 0), Qt.rgba(1, 0, 0, 1)); - compare(image.pixel(199, 199), Qt.rgba(0, 0, 1, 1)); + + verify(image.pixel(0, 0) == Qt.rgba(1, 0, 0)); + verify(image.pixel(199, 199) == Qt.rgba(0, 0, 1)); } } @@ -58,7 +59,7 @@ Item { } Timer { - interval: 1000; + interval: 100; repeat: false running: true onTriggered: box.scale = 2 diff --git a/tests/auto/qmltest/animators/tst_mixedparallel.qml b/tests/auto/qmltest/animators/tst_mixedparallel.qml index da5fb9c..2b6ebfc 100644 --- a/tests/auto/qmltest/animators/tst_mixedparallel.qml +++ b/tests/auto/qmltest/animators/tst_mixedparallel.qml @@ -48,8 +48,8 @@ Item { compare(box.scale, 2); compare(box.rotation, 180); var image = grabImage(root); - compare(image.pixel(0, 0), Qt.rgba(0, 0, 1, 1)); - compare(image.pixel(199, 199), Qt.rgba(1, 0, 0, 1)); + verify(image.pixel(0, 0) == Qt.rgba(0, 0, 1)); + verify(image.pixel(199, 199) == Qt.rgba(1, 0, 0)); } } diff --git a/tests/auto/qmltest/animators/tst_mixedsequential.qml b/tests/auto/qmltest/animators/tst_mixedsequential.qml index 02caa3c..6165cf5 100644 --- a/tests/auto/qmltest/animators/tst_mixedsequential.qml +++ b/tests/auto/qmltest/animators/tst_mixedsequential.qml @@ -48,8 +48,8 @@ Item { compare(box.scale, 2); compare(box.rotation, 180); var image = grabImage(root); - compare(image.pixel(0, 0), Qt.rgba(0, 0, 1, 1)); - compare(image.pixel(199, 199), Qt.rgba(1, 0, 0, 1)); + verify(image.pixel(0, 0) == Qt.rgba(0, 0, 1)); + verify(image.pixel(199, 199) == Qt.rgba(1, 0, 0)); } } diff --git a/tests/auto/qmltest/animators/tst_opacity.qml b/tests/auto/qmltest/animators/tst_opacity.qml index e8c3edd..37603a9 100644 --- a/tests/auto/qmltest/animators/tst_opacity.qml +++ b/tests/auto/qmltest/animators/tst_opacity.qml @@ -42,10 +42,9 @@ Item { TestCase { id: testCase name: "animators-opacity" - when: !animation.running + when: box.opacity == 0.5 function test_endresult() { compare(box.opacityChangeCounter, 1); - compare(box.opacity, 0.5); var image = grabImage(root); compare(image.red(50, 50), 255); verify(image.green(50, 50) > 0); diff --git a/tests/auto/qmltest/animators/tst_parallel.qml b/tests/auto/qmltest/animators/tst_parallel.qml index e9efbda..7702dd7 100644 --- a/tests/auto/qmltest/animators/tst_parallel.qml +++ b/tests/auto/qmltest/animators/tst_parallel.qml @@ -49,8 +49,8 @@ Item { compare(box.scale, 2); compare(box.rotation, 180); var image = grabImage(root); - compare(image.pixel(0, 0), Qt.rgba(0, 0, 1, 1)); - compare(image.pixel(199, 199), Qt.rgba(1, 0, 0, 1)); + verify(image.pixel(0, 0) == Qt.rgba(0, 0, 1)); + verify(image.pixel(199, 199) == Qt.rgba(1, 0, 0)); } } diff --git a/tests/auto/qmltest/animators/tst_rotation.qml b/tests/auto/qmltest/animators/tst_rotation.qml index 8c29df0..9ff4278 100644 --- a/tests/auto/qmltest/animators/tst_rotation.qml +++ b/tests/auto/qmltest/animators/tst_rotation.qml @@ -42,12 +42,11 @@ Item { TestCase { id: testCase name: "animators-rotation" - when: !animation.running + when: box.rotation == 180 function test_endresult() { compare(box.rotationChangeCounter, 1); - compare(box.rotation, 180); var image = grabImage(root); - compare(image.pixel(50, 50), Qt.rgba(0, 0, 1)); + verify(image.pixel(50, 50) == Qt.rgba(0, 0, 1)); } } diff --git a/tests/auto/qmltest/animators/tst_scale.qml b/tests/auto/qmltest/animators/tst_scale.qml index 83ab2e5..10f3430 100644 --- a/tests/auto/qmltest/animators/tst_scale.qml +++ b/tests/auto/qmltest/animators/tst_scale.qml @@ -42,12 +42,11 @@ Item { TestCase { id: testCase name: "animators-scale" - when: !animation.running + when: box.scale == 2; function test_endresult() { compare(box.scaleChangeCounter, 1); - compare(box.scale, 2); var image = grabImage(root); - compare(image.pixel(0, 0), Qt.rgba(1, 0, 0)); + verify(image.pixel(0, 0) == Qt.rgba(1, 0, 0)); } } diff --git a/tests/auto/qmltest/animators/tst_transformorigin.qml b/tests/auto/qmltest/animators/tst_transformorigin.qml index 5dfe070..bd3483d 100644 --- a/tests/auto/qmltest/animators/tst_transformorigin.qml +++ b/tests/auto/qmltest/animators/tst_transformorigin.qml @@ -61,60 +61,60 @@ Item { // topleft - compare(image.pixel(40, 40), white); - compare(image.pixel(60, 40), white); - compare(image.pixel(40, 60), white); - compare(image.pixel(60, 60), blue); + verify(image.pixel(40, 40) == white); + verify(image.pixel(60, 40) == white); + verify(image.pixel(40, 60) == white); + verify(image.pixel(60, 60) == blue); // top - compare(image.pixel(140, 40), white); - compare(image.pixel(160, 40), white); - compare(image.pixel(140, 60), blue); - compare(image.pixel(160, 60), blue); + verify(image.pixel(140, 40) == white); + verify(image.pixel(160, 40) == white); + verify(image.pixel(140, 60) == blue); + verify(image.pixel(160, 60) == blue); // topright - compare(image.pixel(240, 40), white); - compare(image.pixel(260, 40), white); - compare(image.pixel(240, 60), blue); - compare(image.pixel(260, 60), white); + verify(image.pixel(240, 40) == white); + verify(image.pixel(260, 40) == white); + verify(image.pixel(240, 60) == blue); + verify(image.pixel(260, 60) == white); // left - compare(image.pixel(40, 140), white); - compare(image.pixel(60, 140), blue); - compare(image.pixel(40, 160), white); - compare(image.pixel(60, 160), blue); + verify(image.pixel(40, 140) == white); + verify(image.pixel(60, 140) == blue); + verify(image.pixel(40, 160) == white); + verify(image.pixel(60, 160) == blue); // center - compare(image.pixel(140, 140), blue); - compare(image.pixel(160, 140), blue); - compare(image.pixel(140, 160), blue); - compare(image.pixel(160, 160), blue); + verify(image.pixel(140, 140) == blue); + verify(image.pixel(160, 140) == blue); + verify(image.pixel(140, 160) == blue); + verify(image.pixel(160, 160) == blue); // right - compare(image.pixel(240, 140), blue); - compare(image.pixel(260, 140), white); - compare(image.pixel(240, 160), blue); - compare(image.pixel(260, 160), white); + verify(image.pixel(240, 140) == blue); + verify(image.pixel(260, 140) == white); + verify(image.pixel(240, 160) == blue); + verify(image.pixel(260, 160) == white); // bottomleft - compare(image.pixel(40, 240), white); - compare(image.pixel(60, 240), blue); - compare(image.pixel(40, 260), white); - compare(image.pixel(60, 260), white); + verify(image.pixel(40, 240) == white); + verify(image.pixel(60, 240) == blue); + verify(image.pixel(40, 260) == white); + verify(image.pixel(60, 260) == white); // bottom - compare(image.pixel(140, 240), blue); - compare(image.pixel(160, 240), blue); - compare(image.pixel(140, 260), white); - compare(image.pixel(160, 260), white); + verify(image.pixel(140, 240) == blue); + verify(image.pixel(160, 240) == blue); + verify(image.pixel(140, 260) == white); + verify(image.pixel(160, 260) == white); // bottomright - compare(image.pixel(240, 240), blue); - compare(image.pixel(260, 240), white); - compare(image.pixel(240, 260), white); - compare(image.pixel(260, 260), white); + verify(image.pixel(240, 240) == blue); + verify(image.pixel(260, 240) == white); + verify(image.pixel(240, 260) == white); + verify(image.pixel(260, 260) == white); } } diff --git a/tests/auto/qmltest/animators/tst_transition.qml b/tests/auto/qmltest/animators/tst_transition.qml index 72dcd34..67230d2 100644 --- a/tests/auto/qmltest/animators/tst_transition.qml +++ b/tests/auto/qmltest/animators/tst_transition.qml @@ -47,8 +47,8 @@ Item { compare(box.scaleChangeCounter, 1); compare(box.scale, 2); var image = grabImage(root); - compare(image.pixel(0, 0), Qt.rgba(1, 0, 0)); - compare(image.pixel(199, 199), Qt.rgba(0, 0, 1)); + verify(image.pixel(0, 0) == Qt.rgba(1, 0, 0)); + verify(image.pixel(199, 199) == Qt.rgba(0, 0, 1)); } } @@ -75,7 +75,7 @@ Item { } Timer { - interval: 1000; + interval: 100; repeat: false running: true onTriggered: root.state = "two" diff --git a/tests/auto/qmltest/animators/tst_x.qml b/tests/auto/qmltest/animators/tst_x.qml index 8236a82..35e410e 100644 --- a/tests/auto/qmltest/animators/tst_x.qml +++ b/tests/auto/qmltest/animators/tst_x.qml @@ -42,13 +42,12 @@ Item { TestCase { id: testCase name: "animators-x" - when: !animation.running + when: box.x == 100 function test_endresult() { compare(box.xChangeCounter, 1); - compare(box.x, 100); var image = grabImage(root); - compare(image.pixel(100, 50), Qt.rgba(1, 0, 0)); - compare(image.pixel(99, 50), Qt.rgba(1, 1, 1)); // outside on the left + verify(image.pixel(100, 0) == Qt.rgba(1, 0, 0)); + verify(image.pixel(99, 0) == Qt.rgba(1, 1, 1)); // outside on the left } } diff --git a/tests/auto/qmltest/animators/tst_y.qml b/tests/auto/qmltest/animators/tst_y.qml index 37400eb..79fd50e 100644 --- a/tests/auto/qmltest/animators/tst_y.qml +++ b/tests/auto/qmltest/animators/tst_y.qml @@ -42,13 +42,12 @@ Item { TestCase { id: testCase name: "animators-y" - when: !animation.running + when: box.y == 100 function test_endresult() { compare(box.yChangeCounter, 1); - compare(box.y, 100); var image = grabImage(root); - compare(image.pixel(50, 100), Qt.rgba(1, 0, 0)); - compare(image.pixel(50, 99), Qt.rgba(1, 1, 1)); // outside on the left + verify(image.pixel(0, 100) == Qt.rgba(1, 0, 0)); + verify(image.pixel(0, 99) == Qt.rgba(1, 1, 1)); // outside on the top } } -- 2.7.4