Stabilize and fix comparisons in animator tests.
authorGunnar Sletta <gunnar@sletta.org>
Wed, 8 Oct 2014 16:14:43 +0000 (18:14 +0200)
committerGunnar Sletta <gunnar@sletta.org>
Fri, 10 Oct 2014 12:15:55 +0000 (14:15 +0200)
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 <michael.brasser@live.com>
tests/auto/qmltest/animators/tst_behavior.qml
tests/auto/qmltest/animators/tst_mixedparallel.qml
tests/auto/qmltest/animators/tst_mixedsequential.qml
tests/auto/qmltest/animators/tst_opacity.qml
tests/auto/qmltest/animators/tst_parallel.qml
tests/auto/qmltest/animators/tst_rotation.qml
tests/auto/qmltest/animators/tst_scale.qml
tests/auto/qmltest/animators/tst_transformorigin.qml
tests/auto/qmltest/animators/tst_transition.qml
tests/auto/qmltest/animators/tst_x.qml
tests/auto/qmltest/animators/tst_y.qml

index 0b74a74..87b0eff 100644 (file)
@@ -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
index da5fb9c..2b6ebfc 100644 (file)
@@ -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));
         }
     }
 
index 02caa3c..6165cf5 100644 (file)
@@ -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));
         }
     }
 
index e8c3edd..37603a9 100644 (file)
@@ -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);
index e9efbda..7702dd7 100644 (file)
@@ -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));
         }
     }
 
index 8c29df0..9ff4278 100644 (file)
@@ -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));
         }
     }
 
index 83ab2e5..10f3430 100644 (file)
@@ -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));
         }
     }
 
index 5dfe070..bd3483d 100644 (file)
@@ -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);
 
         }
     }
index 72dcd34..67230d2 100644 (file)
@@ -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"
index 8236a82..35e410e 100644 (file)
@@ -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
         }
     }
 
index 37400eb..79fd50e 100644 (file)
@@ -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
         }
     }