QML_RUNTIME_TESTING should be disabled by default.
[profile/ivi/qtdeclarative.git] / tests / auto / qtquick2 / qdeclarativeanimations / tst_qdeclarativeanimations.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 #include <QtTest/QtTest>
42 #include <QtDeclarative/qdeclarativeengine.h>
43 #include <QtDeclarative/qdeclarativecomponent.h>
44 #include <QtQuick/qquickview.h>
45 #include <QtDeclarative/private/qanimationgroupjob_p.h>
46 #include <QtQuick/private/qquickrectangle_p.h>
47 #include <QtQuick/private/qdeclarativeanimation_p.h>
48 #include <QtQuick/private/qdeclarativetransition_p.h>
49 #include <QtQuick/private/qquickanimation_p.h>
50 #include <QtQuick/private/qdeclarativepathinterpolator_p.h>
51 #include <QtQuick/private/qquickitem_p.h>
52 #include <QEasingCurve>
53
54 #include <limits.h>
55 #include <math.h>
56
57 #include "../../shared/util.h"
58
59 class tst_qdeclarativeanimations : public QDeclarativeDataTest
60 {
61     Q_OBJECT
62 public:
63     tst_qdeclarativeanimations() {}
64
65 private slots:
66     void initTestCase()
67     {
68         QDeclarativeEngine engine;  // ensure types are registered
69         QDeclarativeDataTest::initTestCase();
70     }
71
72     void simpleProperty();
73     void simpleNumber();
74     void simpleColor();
75     void simpleRotation();
76     void simplePath();
77     void simpleAnchor();
78     void reparent();
79     void pathInterpolator();
80     void pathInterpolatorBackwardJump();
81     void pathWithNoStart();
82     void alwaysRunToEnd();
83     void complete();
84     void resume();
85     void dotProperty();
86     void badTypes();
87     void badProperties();
88     void mixedTypes();
89     void properties();
90     void propertiesTransition();
91     void pathTransition();
92     void disabledTransition();
93     void invalidDuration();
94     void attached();
95     void propertyValueSourceDefaultStart();
96     void dontStart();
97     void easingProperties();
98     void rotation();
99     void runningTrueBug();
100     void nonTransitionBug();
101     void registrationBug();
102     void doubleRegistrationBug();
103     void alwaysRunToEndRestartBug();
104     void transitionAssignmentBug();
105     void pauseBindingBug();
106     void pauseBug();
107     void loopingBug();
108 };
109
110 #define QTIMED_COMPARE(lhs, rhs) do { \
111     for (int ii = 0; ii < 5; ++ii) { \
112         if (lhs == rhs)  \
113             break; \
114         QTest::qWait(50); \
115     } \
116     QCOMPARE(lhs, rhs); \
117 } while (false)
118
119 void tst_qdeclarativeanimations::simpleProperty()
120 {
121     QQuickRectangle rect;
122     QDeclarativePropertyAnimation animation;
123     animation.setTargetObject(&rect);
124     animation.setProperty("x");
125     animation.setTo(200);
126     QVERIFY(animation.target() == &rect);
127     QVERIFY(animation.property() == "x");
128     QVERIFY(animation.to().toReal() == 200.0);
129     animation.start();
130     QVERIFY(animation.isRunning());
131     QTest::qWait(animation.duration());
132     QTIMED_COMPARE(rect.x(), 200.0);
133
134     rect.setPos(QPointF(0,0));
135     animation.start();
136     QVERIFY(animation.isRunning());
137     animation.pause();
138     QVERIFY(animation.isPaused());
139     animation.setCurrentTime(125);
140     QVERIFY(animation.currentTime() == 125);
141     QCOMPARE(rect.x(),100.0);
142 }
143
144 void tst_qdeclarativeanimations::simpleNumber()
145 {
146     QQuickRectangle rect;
147     QDeclarativeNumberAnimation animation;
148     animation.setTargetObject(&rect);
149     animation.setProperty("x");
150     animation.setTo(200);
151     QVERIFY(animation.target() == &rect);
152     QVERIFY(animation.property() == "x");
153     QVERIFY(animation.to() == 200);
154     animation.start();
155     QVERIFY(animation.isRunning());
156     QTest::qWait(animation.duration());
157     QTIMED_COMPARE(rect.x(), qreal(200));
158
159     rect.setX(0);
160     animation.start();
161     animation.pause();
162     QVERIFY(animation.isRunning());
163     QVERIFY(animation.isPaused());
164     animation.setCurrentTime(125);
165     QVERIFY(animation.currentTime() == 125);
166     QCOMPARE(rect.x(), qreal(100));
167 }
168
169 void tst_qdeclarativeanimations::simpleColor()
170 {
171     QQuickRectangle rect;
172     QDeclarativeColorAnimation animation;
173     animation.setTargetObject(&rect);
174     animation.setProperty("color");
175     animation.setTo(QColor("red"));
176     QVERIFY(animation.target() == &rect);
177     QVERIFY(animation.property() == "color");
178     QVERIFY(animation.to() == QColor("red"));
179     animation.start();
180     QVERIFY(animation.isRunning());
181     QTest::qWait(animation.duration());
182     QTIMED_COMPARE(rect.color(), QColor("red"));
183
184     rect.setColor(QColor("blue"));
185     animation.start();
186     animation.pause();
187     QVERIFY(animation.isRunning());
188     QVERIFY(animation.isPaused());
189     animation.setCurrentTime(125);
190     QVERIFY(animation.currentTime() == 125);
191 #if defined(UBUNTU_ONEIRIC) && defined(__x86_64__)
192     QEXPECT_FAIL("", "Fails on this platform - QTBUG-23385", Abort);
193 #endif
194     QCOMPARE(rect.color(), QColor::fromRgbF(0.498039, 0, 0.498039, 1));
195
196     rect.setColor(QColor("green"));
197     animation.setFrom(QColor("blue"));
198     QVERIFY(animation.from() == QColor("blue"));
199     animation.restart();
200     QCOMPARE(rect.color(), QColor("blue"));
201     QVERIFY(animation.isRunning());
202     animation.setCurrentTime(125);
203     QCOMPARE(rect.color(), QColor::fromRgbF(0.498039, 0, 0.498039, 1));
204 }
205
206 void tst_qdeclarativeanimations::simpleRotation()
207 {
208     QQuickRectangle rect;
209     QDeclarativeRotationAnimation animation;
210     animation.setTargetObject(&rect);
211     animation.setProperty("rotation");
212     animation.setTo(270);
213     QVERIFY(animation.target() == &rect);
214     QVERIFY(animation.property() == "rotation");
215     QVERIFY(animation.to() == 270);
216     QVERIFY(animation.direction() == QDeclarativeRotationAnimation::Numerical);
217     animation.start();
218     QVERIFY(animation.isRunning());
219     QTest::qWait(animation.duration());
220     QTIMED_COMPARE(rect.rotation(), qreal(270));
221
222     rect.setRotation(0);
223     animation.start();
224     animation.pause();
225     QVERIFY(animation.isRunning());
226     QVERIFY(animation.isPaused());
227     animation.setCurrentTime(125);
228     QVERIFY(animation.currentTime() == 125);
229     QCOMPARE(rect.rotation(), qreal(135));
230 }
231
232 void tst_qdeclarativeanimations::simplePath()
233 {
234     {
235         QDeclarativeEngine engine;
236         QDeclarativeComponent c(&engine, testFileUrl("pathAnimation.qml"));
237         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
238         QVERIFY(rect);
239
240         QQuickRectangle *redRect = rect->findChild<QQuickRectangle*>();
241         QVERIFY(redRect);
242         QQuickPathAnimation *pathAnim = rect->findChild<QQuickPathAnimation*>();
243         QVERIFY(pathAnim);
244
245         QCOMPARE(pathAnim->duration(), 100);
246         QCOMPARE(pathAnim->target(), redRect);
247
248         pathAnim->start();
249         pathAnim->pause();
250
251         pathAnim->setCurrentTime(30);
252         QCOMPARE(redRect->x(), qreal(167));
253         QCOMPARE(redRect->y(), qreal(104));
254
255         pathAnim->setCurrentTime(100);
256         QCOMPARE(redRect->x(), qreal(300));
257         QCOMPARE(redRect->y(), qreal(300));
258
259         //verify animation runs to end
260         pathAnim->start();
261         QCOMPARE(redRect->x(), qreal(50));
262         QCOMPARE(redRect->y(), qreal(50));
263         QTRY_COMPARE(redRect->x(), qreal(300));
264         QCOMPARE(redRect->y(), qreal(300));
265
266         pathAnim->setOrientation(QQuickPathAnimation::RightFirst);
267         QCOMPARE(pathAnim->orientation(), QQuickPathAnimation::RightFirst);
268         pathAnim->start();
269         QTRY_VERIFY(redRect->rotation() != 0);
270         pathAnim->stop();
271
272         delete rect;
273     }
274
275     {
276         QDeclarativeEngine engine;
277         QDeclarativeComponent c(&engine, testFileUrl("pathAnimation2.qml"));
278         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
279         QVERIFY(rect);
280
281         QQuickRectangle *redRect = rect->findChild<QQuickRectangle*>();
282         QVERIFY(redRect);
283         QQuickPathAnimation *pathAnim = rect->findChild<QQuickPathAnimation*>();
284         QVERIFY(pathAnim);
285
286         QCOMPARE(pathAnim->orientation(), QQuickPathAnimation::RightFirst);
287         QCOMPARE(pathAnim->endRotation(), qreal(0));
288         QCOMPARE(pathAnim->orientationEntryDuration(), 10);
289         QCOMPARE(pathAnim->orientationExitDuration(), 10);
290
291         pathAnim->start();
292         pathAnim->pause();
293         QCOMPARE(redRect->x(), qreal(50));
294         QCOMPARE(redRect->y(), qreal(50));
295         QCOMPARE(redRect->rotation(), qreal(-360));
296
297         pathAnim->setCurrentTime(50);
298         QCOMPARE(redRect->x(), qreal(175));
299         QCOMPARE(redRect->y(), qreal(175));
300         QCOMPARE(redRect->rotation(), qreal(-315));
301
302         pathAnim->setCurrentTime(100);
303         QCOMPARE(redRect->x(), qreal(300));
304         QCOMPARE(redRect->y(), qreal(300));
305         QCOMPARE(redRect->rotation(), qreal(0));
306
307         delete rect;
308     }
309 }
310
311 void tst_qdeclarativeanimations::simpleAnchor()
312 {
313     QDeclarativeEngine engine;
314     QDeclarativeComponent c(&engine, testFileUrl("reanchor.qml"));
315     QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
316     QVERIFY(rect);
317
318     QQuickRectangle *greenRect = rect->findChild<QQuickRectangle*>();
319     QVERIFY(greenRect);
320
321     QCOMPARE(rect->state(), QLatin1String("reanchored"));
322     QCOMPARE(greenRect->x(), qreal(10));
323     QCOMPARE(greenRect->y(), qreal(0));
324     QCOMPARE(greenRect->width(), qreal(190));
325     QCOMPARE(greenRect->height(), qreal(150));
326
327     rect->setState("");
328
329     //verify animation in progress
330     QTRY_VERIFY(greenRect->x() < 10 && greenRect->x() > 0);
331     QVERIFY(greenRect->y() > 0 && greenRect->y() < 10);
332     QVERIFY(greenRect->width() < 190 && greenRect->width() > 150);
333     QVERIFY(greenRect->height() > 150 && greenRect->height() < 190);
334
335     //verify end state ("")
336     QTRY_COMPARE(greenRect->x(), qreal(0));
337     QCOMPARE(greenRect->y(), qreal(10));
338     QCOMPARE(greenRect->width(), qreal(150));
339     QCOMPARE(greenRect->height(), qreal(190));
340
341     rect->setState("reanchored2");
342
343     //verify animation in progress
344     QTRY_VERIFY(greenRect->y() > 10 && greenRect->y() < 50);
345     QVERIFY(greenRect->height() > 125 && greenRect->height() < 190);
346     //NOTE: setting left/right anchors to undefined removes the anchors, but does not resize.
347     QCOMPARE(greenRect->x(), qreal(0));
348     QCOMPARE(greenRect->width(), qreal(150));
349
350     //verify end state ("reanchored2")
351     QTRY_COMPARE(greenRect->y(), qreal(50));
352     QCOMPARE(greenRect->height(), qreal(125));
353     QCOMPARE(greenRect->x(), qreal(0));
354     QCOMPARE(greenRect->width(), qreal(150));
355
356     rect->setState("reanchored");
357
358     //verify animation in progress
359     QTRY_VERIFY(greenRect->x() < 10 && greenRect->x() > 0);
360     QVERIFY(greenRect->y() > 0 && greenRect->y() < 50);
361     QVERIFY(greenRect->width() < 190 && greenRect->width() > 150);
362     QVERIFY(greenRect->height() > 125 && greenRect->height() < 150);
363
364     //verify end state ("reanchored")
365     QTRY_COMPARE(greenRect->x(), qreal(10));
366     QCOMPARE(greenRect->y(), qreal(0));
367     QCOMPARE(greenRect->width(), qreal(190));
368     QCOMPARE(greenRect->height(), qreal(150));
369
370     rect->setState("reanchored2");
371
372     //verify animation in progress
373     QTRY_VERIFY(greenRect->x() < 10 && greenRect->x() > 0);
374     QVERIFY(greenRect->y() > 0 && greenRect->y() < 50);
375     QVERIFY(greenRect->width() < 190 && greenRect->width() > 150);
376     QVERIFY(greenRect->height() > 125 && greenRect->height() < 150);
377
378     //verify end state ("reanchored2")
379     QTRY_COMPARE(greenRect->x(), qreal(0));
380     QCOMPARE(greenRect->y(), qreal(50));
381     QCOMPARE(greenRect->width(), qreal(150));
382     QCOMPARE(greenRect->height(), qreal(125));
383
384     delete rect;
385 }
386
387 void tst_qdeclarativeanimations::reparent()
388 {
389     QDeclarativeEngine engine;
390     QDeclarativeComponent c(&engine, testFileUrl("reparent.qml"));
391     QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
392     QVERIFY(rect);
393
394     QQuickRectangle *target = rect->findChild<QQuickRectangle*>("target");
395     QVERIFY(target);
396
397     QCOMPARE(target->parentItem(), rect);
398     QCOMPARE(target->x(), qreal(0));
399     QCOMPARE(target->y(), qreal(0));
400     QCOMPARE(target->width(), qreal(50));
401     QCOMPARE(target->height(), qreal(50));
402     QCOMPARE(target->rotation(), qreal(0));
403     QCOMPARE(target->scale(), qreal(1));
404
405     rect->setState("state1");
406
407     QQuickRectangle *viaParent = rect->findChild<QQuickRectangle*>("viaParent");
408     QVERIFY(viaParent);
409
410     QQuickRectangle *newParent = rect->findChild<QQuickRectangle*>("newParent");
411     QVERIFY(newParent);
412
413     QTest::qWait(100);
414
415     //animation in progress
416     QTRY_COMPARE(target->parentItem(), viaParent);
417     QVERIFY(target->x() > -100 && target->x() < 50);
418     QVERIFY(target->y() > -100 && target->y() < 50);
419     QVERIFY(target->width() > 50 && target->width() < 100);
420     QCOMPARE(target->height(), qreal(50));
421     QCOMPARE(target->rotation(), qreal(-45));
422     QCOMPARE(target->scale(), qreal(.5));
423
424     //end state
425     QTRY_COMPARE(target->parentItem(), newParent);
426     QCOMPARE(target->x(), qreal(50));
427     QCOMPARE(target->y(), qreal(50));
428     QCOMPARE(target->width(), qreal(100));
429     QCOMPARE(target->height(), qreal(50));
430     QCOMPARE(target->rotation(), qreal(0));
431     QCOMPARE(target->scale(), qreal(1));
432
433     delete rect;
434 }
435
436 void tst_qdeclarativeanimations::pathInterpolator()
437 {
438     QDeclarativeEngine engine;
439     QDeclarativeComponent c(&engine, testFileUrl("pathInterpolator.qml"));
440     QDeclarativePathInterpolator *interpolator = qobject_cast<QDeclarativePathInterpolator*>(c.create());
441     QVERIFY(interpolator);
442
443     QCOMPARE(interpolator->progress(), qreal(0));
444     QCOMPARE(interpolator->x(), qreal(50));
445     QCOMPARE(interpolator->y(), qreal(50));
446     QCOMPARE(interpolator->angle(), qreal(0));
447
448     interpolator->setProgress(.5);
449     QCOMPARE(interpolator->progress(), qreal(.5));
450     QCOMPARE(interpolator->x(), qreal(175));
451     QCOMPARE(interpolator->y(), qreal(175));
452     QCOMPARE(interpolator->angle(), qreal(90));
453
454     interpolator->setProgress(1);
455     QCOMPARE(interpolator->progress(), qreal(1));
456     QCOMPARE(interpolator->x(), qreal(300));
457     QCOMPARE(interpolator->y(), qreal(300));
458     QCOMPARE(interpolator->angle(), qreal(0));
459 }
460
461 void tst_qdeclarativeanimations::pathInterpolatorBackwardJump()
462 {
463     {
464         QDeclarativeEngine engine;
465         QDeclarativeComponent c(&engine, testFileUrl("pathInterpolatorBack.qml"));
466         QDeclarativePathInterpolator *interpolator = qobject_cast<QDeclarativePathInterpolator*>(c.create());
467         QVERIFY(interpolator);
468
469         QCOMPARE(interpolator->progress(), qreal(0));
470         QCOMPARE(interpolator->x(), qreal(50));
471         QCOMPARE(interpolator->y(), qreal(50));
472         QCOMPARE(interpolator->angle(), qreal(90));
473
474         interpolator->setProgress(.5);
475         QCOMPARE(interpolator->progress(), qreal(.5));
476         QCOMPARE(interpolator->x(), qreal(100));
477         QCOMPARE(interpolator->y(), qreal(75));
478         QCOMPARE(interpolator->angle(), qreal(270));
479
480         interpolator->setProgress(1);
481         QCOMPARE(interpolator->progress(), qreal(1));
482         QCOMPARE(interpolator->x(), qreal(200));
483         QCOMPARE(interpolator->y(), qreal(50));
484         QCOMPARE(interpolator->angle(), qreal(0));
485
486         //make sure we don't get caught in infinite loop here
487         interpolator->setProgress(0);
488         QCOMPARE(interpolator->progress(), qreal(0));
489         QCOMPARE(interpolator->x(), qreal(50));
490         QCOMPARE(interpolator->y(), qreal(50));
491         QCOMPARE(interpolator->angle(), qreal(90));
492     }
493
494     {
495         QDeclarativeEngine engine;
496         QDeclarativeComponent c(&engine, testFileUrl("pathInterpolatorBack2.qml"));
497         QDeclarativePathInterpolator *interpolator = qobject_cast<QDeclarativePathInterpolator*>(c.create());
498         QVERIFY(interpolator);
499
500         QCOMPARE(interpolator->progress(), qreal(0));
501         QCOMPARE(interpolator->x(), qreal(200));
502         QCOMPARE(interpolator->y(), qreal(280));
503         QCOMPARE(interpolator->angle(), qreal(180));
504
505         interpolator->setProgress(1);
506         QCOMPARE(interpolator->progress(), qreal(1));
507         QCOMPARE(interpolator->x(), qreal(0));
508         QCOMPARE(interpolator->y(), qreal(80));
509         QCOMPARE(interpolator->angle(), qreal(180));
510
511         //make sure we don't get caught in infinite loop here
512         interpolator->setProgress(0);
513         QCOMPARE(interpolator->progress(), qreal(0));
514         QCOMPARE(interpolator->x(), qreal(200));
515         QCOMPARE(interpolator->y(), qreal(280));
516         QCOMPARE(interpolator->angle(), qreal(180));
517     }
518 }
519
520 void tst_qdeclarativeanimations::pathWithNoStart()
521 {
522     QDeclarativeEngine engine;
523     QDeclarativeComponent c(&engine, testFileUrl("pathAnimationNoStart.qml"));
524     QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
525     QVERIFY(rect);
526
527     QQuickRectangle *redRect = rect->findChild<QQuickRectangle*>();
528     QVERIFY(redRect);
529     QQuickPathAnimation *pathAnim = rect->findChild<QQuickPathAnimation*>();
530     QVERIFY(pathAnim);
531
532     pathAnim->start();
533     pathAnim->pause();
534     QCOMPARE(redRect->x(), qreal(50));
535     QCOMPARE(redRect->y(), qreal(50));
536
537     pathAnim->setCurrentTime(50);
538     QCOMPARE(redRect->x(), qreal(175));
539     QCOMPARE(redRect->y(), qreal(175));
540
541     pathAnim->setCurrentTime(100);
542     QCOMPARE(redRect->x(), qreal(300));
543     QCOMPARE(redRect->y(), qreal(300));
544
545     redRect->setX(100);
546     redRect->setY(100);
547     pathAnim->start();
548     QCOMPARE(redRect->x(), qreal(100));
549     QCOMPARE(redRect->y(), qreal(100));
550     QTRY_COMPARE(redRect->x(), qreal(300));
551     QCOMPARE(redRect->y(), qreal(300));
552 }
553
554 void tst_qdeclarativeanimations::alwaysRunToEnd()
555 {
556     QQuickRectangle rect;
557     QDeclarativePropertyAnimation animation;
558     animation.setTargetObject(&rect);
559     animation.setProperty("x");
560     animation.setTo(200);
561     animation.setDuration(1000);
562     animation.setLoops(-1);
563     animation.setAlwaysRunToEnd(true);
564     QVERIFY(animation.loops() == -1);
565     QVERIFY(animation.alwaysRunToEnd() == true);
566     animation.start();
567     QTest::qWait(1500);
568     animation.stop();
569     QVERIFY(rect.x() != qreal(200));
570     QTest::qWait(500);
571     QTIMED_COMPARE(rect.x(), qreal(200));
572 }
573
574 void tst_qdeclarativeanimations::complete()
575 {
576     QQuickRectangle rect;
577     QDeclarativePropertyAnimation animation;
578     animation.setTargetObject(&rect);
579     animation.setProperty("x");
580     animation.setFrom(1);
581     animation.setTo(200);
582     animation.setDuration(500);
583     QVERIFY(animation.from() == 1);
584     animation.start();
585     QTest::qWait(50);
586     animation.stop();
587     QVERIFY(rect.x() != qreal(200));
588     animation.start();
589     QTest::qWait(50);
590     QVERIFY(animation.isRunning());
591     animation.complete();
592     QCOMPARE(rect.x(), qreal(200));
593 }
594
595 void tst_qdeclarativeanimations::resume()
596 {
597     QQuickRectangle rect;
598     QDeclarativePropertyAnimation animation;
599     animation.setTargetObject(&rect);
600     animation.setProperty("x");
601     animation.setFrom(10);
602     animation.setTo(200);
603     animation.setDuration(1000);
604     QVERIFY(animation.from() == 10);
605
606     animation.start();
607     QTest::qWait(400);
608     animation.pause();
609     qreal x = rect.x();
610     QVERIFY(x != qreal(200) && x != qreal(10));
611     QVERIFY(animation.isRunning());
612     QVERIFY(animation.isPaused());
613
614     animation.resume();
615     QVERIFY(animation.isRunning());
616     QVERIFY(!animation.isPaused());
617     QTest::qWait(400);
618     animation.stop();
619     QVERIFY(rect.x() > x);
620 }
621
622 void tst_qdeclarativeanimations::dotProperty()
623 {
624     QQuickRectangle rect;
625     QDeclarativeNumberAnimation animation;
626     animation.setTargetObject(&rect);
627     animation.setProperty("border.width");
628     animation.setTo(10);
629     animation.start();
630     QTest::qWait(animation.duration()+50);
631     QTIMED_COMPARE(rect.border()->width(), 10.0);
632
633     rect.border()->setWidth(0);
634     animation.start();
635     animation.pause();
636     animation.setCurrentTime(125);
637     QVERIFY(animation.currentTime() == 125);
638     QCOMPARE(rect.border()->width(), 5.0);
639 }
640
641 void tst_qdeclarativeanimations::badTypes()
642 {
643     //don't crash
644     {
645         QQuickView *view = new QQuickView;
646         view->setSource(testFileUrl("badtype1.qml"));
647
648         qApp->processEvents();
649
650         delete view;
651     }
652
653     //make sure we get a compiler error
654     {
655         QDeclarativeEngine engine;
656         QDeclarativeComponent c(&engine, testFileUrl("badtype2.qml"));
657         QTest::ignoreMessage(QtWarningMsg, "QDeclarativeComponent: Component is not ready");
658         c.create();
659
660         QVERIFY(c.errors().count() == 1);
661         QCOMPARE(c.errors().at(0).description(), QLatin1String("Invalid property assignment: number expected"));
662     }
663
664     //make sure we get a compiler error
665     {
666         QDeclarativeEngine engine;
667         QDeclarativeComponent c(&engine, testFileUrl("badtype3.qml"));
668         QTest::ignoreMessage(QtWarningMsg, "QDeclarativeComponent: Component is not ready");
669         c.create();
670
671         QVERIFY(c.errors().count() == 1);
672         QCOMPARE(c.errors().at(0).description(), QLatin1String("Invalid property assignment: color expected"));
673     }
674
675     //don't crash
676     {
677         QDeclarativeEngine engine;
678         QDeclarativeComponent c(&engine, testFileUrl("badtype4.qml"));
679         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
680         QVERIFY(rect);
681
682         QQuickItemPrivate::get(rect)->setState("state1");
683         QTest::qWait(1000 + 50);
684         QQuickRectangle *myRect = rect->findChild<QQuickRectangle*>("MyRect");
685         QVERIFY(myRect);
686         QCOMPARE(myRect->x(),qreal(200));
687     }
688 }
689
690 void tst_qdeclarativeanimations::badProperties()
691 {
692     //make sure we get a runtime error
693     {
694         QDeclarativeEngine engine;
695
696         QDeclarativeComponent c1(&engine, testFileUrl("badproperty1.qml"));
697         QByteArray message = testFileUrl("badproperty1.qml").toString().toUtf8() + ":18:9: QML ColorAnimation: Cannot animate non-existent property \"border.colr\"";
698         QTest::ignoreMessage(QtWarningMsg, message);
699         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c1.create());
700         QVERIFY(rect);
701
702         QDeclarativeComponent c2(&engine, testFileUrl("badproperty2.qml"));
703         message = testFileUrl("badproperty2.qml").toString().toUtf8() + ":18:9: QML ColorAnimation: Cannot animate read-only property \"border\"";
704         QTest::ignoreMessage(QtWarningMsg, message);
705         rect = qobject_cast<QQuickRectangle*>(c2.create());
706         QVERIFY(rect);
707
708         //### should we warn here are well?
709         //rect->setState("state1");
710     }
711 }
712
713 //test animating mixed types with property animation in a transition
714 //for example, int + real; color + real; etc
715 void tst_qdeclarativeanimations::mixedTypes()
716 {
717     //assumes border.width stays a real -- not real robust
718     {
719         QDeclarativeEngine engine;
720         QDeclarativeComponent c(&engine, testFileUrl("mixedtype1.qml"));
721         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
722         QVERIFY(rect);
723
724         QQuickItemPrivate::get(rect)->setState("state1");
725         QTest::qWait(500);
726         QQuickRectangle *myRect = rect->findChild<QQuickRectangle*>("MyRect");
727         QVERIFY(myRect);
728
729         //rather inexact -- is there a better way?
730         QVERIFY(myRect->x() > 100 && myRect->x() < 200);
731         QVERIFY(myRect->border()->width() > 1 && myRect->border()->width() < 10);
732     }
733
734     {
735         QDeclarativeEngine engine;
736         QDeclarativeComponent c(&engine, testFileUrl("mixedtype2.qml"));
737         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
738         QVERIFY(rect);
739
740         QQuickItemPrivate::get(rect)->setState("state1");
741         QTest::qWait(500);
742         QQuickRectangle *myRect = rect->findChild<QQuickRectangle*>("MyRect");
743         QVERIFY(myRect);
744
745         //rather inexact -- is there a better way?
746         QVERIFY(myRect->x() > 100 && myRect->x() < 200);
747 #if defined(UBUNTU_ONEIRIC) && defined(__x86_64__)
748         QEXPECT_FAIL("", "Fails on this platform - QTBUG-23385", Continue);
749 #endif
750         QVERIFY(myRect->color() != QColor("red") && myRect->color() != QColor("blue"));
751     }
752 }
753
754 void tst_qdeclarativeanimations::properties()
755 {
756     const int waitDuration = 300;
757     {
758         QDeclarativeEngine engine;
759         QDeclarativeComponent c(&engine, testFileUrl("properties.qml"));
760         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
761         QVERIFY(rect);
762
763         QQuickRectangle *myRect = rect->findChild<QQuickRectangle*>("TheRect");
764         QVERIFY(myRect);
765         QTest::qWait(waitDuration);
766         QTIMED_COMPARE(myRect->x(),qreal(200));
767     }
768
769     {
770         QDeclarativeEngine engine;
771         QDeclarativeComponent c(&engine, testFileUrl("properties2.qml"));
772         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
773         QVERIFY(rect);
774
775         QQuickRectangle *myRect = rect->findChild<QQuickRectangle*>("TheRect");
776         QVERIFY(myRect);
777         QTest::qWait(waitDuration);
778         QTIMED_COMPARE(myRect->x(),qreal(200));
779     }
780
781     {
782         QDeclarativeEngine engine;
783         QDeclarativeComponent c(&engine, testFileUrl("properties3.qml"));
784         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
785         QVERIFY(rect);
786
787         QQuickRectangle *myRect = rect->findChild<QQuickRectangle*>("TheRect");
788         QVERIFY(myRect);
789         QTest::qWait(waitDuration);
790         QTIMED_COMPARE(myRect->x(),qreal(300));
791     }
792
793     {
794         QDeclarativeEngine engine;
795         QDeclarativeComponent c(&engine, testFileUrl("properties4.qml"));
796         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
797         QVERIFY(rect);
798
799         QQuickRectangle *myRect = rect->findChild<QQuickRectangle*>("TheRect");
800         QVERIFY(myRect);
801         QTest::qWait(waitDuration);
802         QTIMED_COMPARE(myRect->y(),qreal(200));
803         QTIMED_COMPARE(myRect->x(),qreal(100));
804     }
805
806     {
807         QDeclarativeEngine engine;
808         QDeclarativeComponent c(&engine, testFileUrl("properties5.qml"));
809         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
810         QVERIFY(rect);
811
812         QQuickRectangle *myRect = rect->findChild<QQuickRectangle*>("TheRect");
813         QVERIFY(myRect);
814         QTest::qWait(waitDuration);
815         QTIMED_COMPARE(myRect->x(),qreal(100));
816         QTIMED_COMPARE(myRect->y(),qreal(200));
817     }
818 }
819
820 void tst_qdeclarativeanimations::propertiesTransition()
821 {
822     const int waitDuration = 300;
823     {
824         QDeclarativeEngine engine;
825         QDeclarativeComponent c(&engine, testFileUrl("propertiesTransition.qml"));
826         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
827         QVERIFY(rect);
828
829         QQuickItemPrivate::get(rect)->setState("moved");
830         QQuickRectangle *myRect = rect->findChild<QQuickRectangle*>("TheRect");
831         QVERIFY(myRect);
832         QTest::qWait(waitDuration);
833         QTIMED_COMPARE(myRect->x(),qreal(200));
834     }
835
836     {
837         QDeclarativeEngine engine;
838         QDeclarativeComponent c(&engine, testFileUrl("propertiesTransition2.qml"));
839         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
840         QVERIFY(rect);
841
842         QQuickRectangle *myRect = rect->findChild<QQuickRectangle*>("TheRect");
843         QVERIFY(myRect);
844         QQuickItemPrivate::get(rect)->setState("moved");
845         QCOMPARE(myRect->x(),qreal(200));
846         QCOMPARE(myRect->y(),qreal(100));
847         QTest::qWait(waitDuration);
848         QTIMED_COMPARE(myRect->y(),qreal(200));
849     }
850
851     {
852         QDeclarativeEngine engine;
853         QDeclarativeComponent c(&engine, testFileUrl("propertiesTransition3.qml"));
854         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
855         QVERIFY(rect);
856
857         QQuickRectangle *myRect = rect->findChild<QQuickRectangle*>("TheRect");
858         QVERIFY(myRect);
859         QQuickItemPrivate::get(rect)->setState("moved");
860         QCOMPARE(myRect->x(),qreal(200));
861         QCOMPARE(myRect->y(),qreal(100));
862     }
863
864     {
865         QDeclarativeEngine engine;
866         QDeclarativeComponent c(&engine, testFileUrl("propertiesTransition4.qml"));
867         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
868         QVERIFY(rect);
869
870         QQuickRectangle *myRect = rect->findChild<QQuickRectangle*>("TheRect");
871         QVERIFY(myRect);
872         QQuickItemPrivate::get(rect)->setState("moved");
873         QCOMPARE(myRect->x(),qreal(100));
874         QTest::qWait(waitDuration);
875         QTIMED_COMPARE(myRect->x(),qreal(200));
876     }
877
878     {
879         QDeclarativeEngine engine;
880         QDeclarativeComponent c(&engine, testFileUrl("propertiesTransition5.qml"));
881         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
882         QVERIFY(rect);
883
884         QQuickRectangle *myRect = rect->findChild<QQuickRectangle*>("TheRect");
885         QVERIFY(myRect);
886         QQuickItemPrivate::get(rect)->setState("moved");
887         QCOMPARE(myRect->x(),qreal(100));
888         QTest::qWait(waitDuration);
889         QTIMED_COMPARE(myRect->x(),qreal(200));
890     }
891
892     /*{
893         QDeclarativeEngine engine;
894         QDeclarativeComponent c(&engine, testFileUrl("propertiesTransition6.qml"));
895         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
896         QVERIFY(rect);
897
898         QQuickRectangle *myRect = rect->findChild<QQuickRectangle*>("TheRect");
899         QVERIFY(myRect);
900         QQuickItemPrivate::get(rect)->setState("moved");
901         QCOMPARE(myRect->x(),qreal(100));
902         QTest::qWait(waitDuration);
903         QTIMED_COMPARE(myRect->x(),qreal(100));
904     }*/
905
906     {
907         QDeclarativeEngine engine;
908         QDeclarativeComponent c(&engine, testFileUrl("propertiesTransition7.qml"));
909         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
910         QVERIFY(rect);
911
912         QQuickItemPrivate::get(rect)->setState("moved");
913         QQuickRectangle *myRect = rect->findChild<QQuickRectangle*>("TheRect");
914         QVERIFY(myRect);
915         QTest::qWait(waitDuration);
916         QTIMED_COMPARE(myRect->x(),qreal(200));
917     }
918
919 }
920
921 void tst_qdeclarativeanimations::pathTransition()
922 {
923     QDeclarativeEngine engine;
924     QDeclarativeComponent c(&engine, testFileUrl("pathTransition.qml"));
925     QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
926     QVERIFY(rect);
927
928     QQuickRectangle *myRect = rect->findChild<QQuickRectangle*>("redRect");
929     QVERIFY(myRect);
930
931     QQuickItemPrivate::get(rect)->setState("moved");
932     QTRY_VERIFY(myRect->x() < 500 && myRect->x() > 100 && myRect->y() > 50 && myRect->y() < 700 );  //animation started
933     QTRY_VERIFY(qFuzzyCompare(myRect->x(), qreal(100)) && qFuzzyCompare(myRect->y(), qreal(700)));
934     QTest::qWait(100);
935
936     QQuickItemPrivate::get(rect)->setState("");
937     QTRY_VERIFY(myRect->x() < 500 && myRect->x() > 100 && myRect->y() > 50 && myRect->y() < 700 );  //animation started
938     QTRY_VERIFY(qFuzzyCompare(myRect->x(), qreal(500)) && qFuzzyCompare(myRect->y(), qreal(50)));
939 }
940
941 void tst_qdeclarativeanimations::disabledTransition()
942 {
943     QDeclarativeEngine engine;
944     QDeclarativeComponent c(&engine, testFileUrl("disabledTransition.qml"));
945     QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
946     QVERIFY(rect);
947
948     QQuickRectangle *myRect = rect->findChild<QQuickRectangle*>("TheRect");
949     QVERIFY(myRect);
950
951     QDeclarativeTransition *trans = rect->findChild<QDeclarativeTransition*>();
952     QVERIFY(trans);
953
954     QCOMPARE(trans->enabled(), false);
955
956     QQuickItemPrivate::get(rect)->setState("moved");
957     QCOMPARE(myRect->x(),qreal(200));
958
959     trans->setEnabled(true);
960
961     QQuickItemPrivate::get(rect)->setState("");
962     QCOMPARE(myRect->x(),qreal(200));
963     QTest::qWait(300);
964     QTIMED_COMPARE(myRect->x(),qreal(100));
965 }
966
967 void tst_qdeclarativeanimations::invalidDuration()
968 {
969     QDeclarativePropertyAnimation *animation = new QDeclarativePropertyAnimation;
970     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML PropertyAnimation: Cannot set a duration of < 0");
971     animation->setDuration(-1);
972     QCOMPARE(animation->duration(), 250);
973
974     QDeclarativePauseAnimation *pauseAnimation = new QDeclarativePauseAnimation;
975     QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML PauseAnimation: Cannot set a duration of < 0");
976     pauseAnimation->setDuration(-1);
977     QCOMPARE(pauseAnimation->duration(), 250);
978 }
979
980 void tst_qdeclarativeanimations::attached()
981 {
982     QDeclarativeEngine engine;
983
984     QDeclarativeComponent c(&engine, testFileUrl("attached.qml"));
985     QTest::ignoreMessage(QtDebugMsg, "off");
986     QTest::ignoreMessage(QtDebugMsg, "on");
987     QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
988     QVERIFY(rect);
989 }
990
991 void tst_qdeclarativeanimations::propertyValueSourceDefaultStart()
992 {
993     {
994         QDeclarativeEngine engine;
995
996         QDeclarativeComponent c(&engine, testFileUrl("valuesource.qml"));
997
998         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
999         QVERIFY(rect);
1000
1001         QDeclarativeAbstractAnimation *myAnim = rect->findChild<QDeclarativeAbstractAnimation*>("MyAnim");
1002         QVERIFY(myAnim);
1003         QVERIFY(myAnim->isRunning());
1004     }
1005
1006     {
1007         QDeclarativeEngine engine;
1008
1009         QDeclarativeComponent c(&engine, testFileUrl("valuesource2.qml"));
1010
1011         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
1012         QVERIFY(rect);
1013
1014         QDeclarativeAbstractAnimation *myAnim = rect->findChild<QDeclarativeAbstractAnimation*>("MyAnim");
1015         QVERIFY(myAnim);
1016         QVERIFY(myAnim->isRunning() == false);
1017     }
1018
1019     {
1020         QDeclarativeEngine engine;
1021
1022         QDeclarativeComponent c(&engine, testFileUrl("dontAutoStart.qml"));
1023
1024         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
1025         QVERIFY(rect);
1026
1027         QDeclarativeAbstractAnimation *myAnim = rect->findChild<QDeclarativeAbstractAnimation*>("MyAnim");
1028         QVERIFY(myAnim && !myAnim->qtAnimation());
1029         //QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimationJob::Stopped);
1030     }
1031 }
1032
1033
1034 void tst_qdeclarativeanimations::dontStart()
1035 {
1036     {
1037         QDeclarativeEngine engine;
1038
1039         QDeclarativeComponent c(&engine, testFileUrl("dontStart.qml"));
1040
1041         QString warning = c.url().toString() + ":14:13: QML NumberAnimation: setRunning() cannot be used on non-root animation nodes.";
1042         QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
1043         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
1044         QVERIFY(rect);
1045
1046         QDeclarativeAbstractAnimation *myAnim = rect->findChild<QDeclarativeAbstractAnimation*>("MyAnim");
1047         QVERIFY(myAnim && !myAnim->qtAnimation());
1048         //QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimationJob::Stopped);
1049     }
1050
1051     {
1052         QDeclarativeEngine engine;
1053
1054         QDeclarativeComponent c(&engine, testFileUrl("dontStart2.qml"));
1055
1056         QString warning = c.url().toString() + ":15:17: QML NumberAnimation: setRunning() cannot be used on non-root animation nodes.";
1057         QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
1058         QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
1059         QVERIFY(rect);
1060
1061         QDeclarativeAbstractAnimation *myAnim = rect->findChild<QDeclarativeAbstractAnimation*>("MyAnim");
1062         QVERIFY(myAnim && !myAnim->qtAnimation());
1063         //QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimationJob::Stopped);
1064     }
1065 }
1066
1067 void tst_qdeclarativeanimations::easingProperties()
1068 {
1069     {
1070         QDeclarativeEngine engine;
1071         QString componentStr = "import QtQuick 2.0\nNumberAnimation { easing.type: \"InOutQuad\" }";
1072         QDeclarativeComponent animationComponent(&engine);
1073         animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1074         QDeclarativePropertyAnimation *animObject = qobject_cast<QDeclarativePropertyAnimation*>(animationComponent.create());
1075
1076         QVERIFY(animObject != 0);
1077         QCOMPARE(animObject->easing().type(), QEasingCurve::InOutQuad);
1078     }
1079
1080     {
1081         QDeclarativeEngine engine;
1082         QString componentStr = "import QtQuick 2.0\nPropertyAnimation { easing.type: \"OutBounce\"; easing.amplitude: 5.0 }";
1083         QDeclarativeComponent animationComponent(&engine);
1084         animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1085         QDeclarativePropertyAnimation *animObject = qobject_cast<QDeclarativePropertyAnimation*>(animationComponent.create());
1086
1087         QVERIFY(animObject != 0);
1088         QCOMPARE(animObject->easing().type(), QEasingCurve::OutBounce);
1089         QCOMPARE(animObject->easing().amplitude(), 5.0);
1090     }
1091
1092     {
1093         QDeclarativeEngine engine;
1094         QString componentStr = "import QtQuick 2.0\nPropertyAnimation { easing.type: \"OutElastic\"; easing.amplitude: 5.0; easing.period: 3.0}";
1095         QDeclarativeComponent animationComponent(&engine);
1096         animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1097         QDeclarativePropertyAnimation *animObject = qobject_cast<QDeclarativePropertyAnimation*>(animationComponent.create());
1098
1099         QVERIFY(animObject != 0);
1100         QCOMPARE(animObject->easing().type(), QEasingCurve::OutElastic);
1101         QCOMPARE(animObject->easing().amplitude(), 5.0);
1102         QCOMPARE(animObject->easing().period(), 3.0);
1103     }
1104
1105     {
1106         QDeclarativeEngine engine;
1107         QString componentStr = "import QtQuick 2.0\nPropertyAnimation { easing.type: \"InOutBack\"; easing.overshoot: 2 }";
1108         QDeclarativeComponent animationComponent(&engine);
1109         animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1110         QDeclarativePropertyAnimation *animObject = qobject_cast<QDeclarativePropertyAnimation*>(animationComponent.create());
1111
1112         QVERIFY(animObject != 0);
1113         QCOMPARE(animObject->easing().type(), QEasingCurve::InOutBack);
1114         QCOMPARE(animObject->easing().overshoot(), 2.0);
1115     }
1116
1117     {
1118         QDeclarativeEngine engine;
1119         QString componentStr = "import QtQuick 2.0\nPropertyAnimation { easing.type: \"Bezier\"; easing.bezierCurve: [0.5, 0.2, 0.13, 0.65, 1.0, 1.0] }";
1120         QDeclarativeComponent animationComponent(&engine);
1121         animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1122         QDeclarativePropertyAnimation *animObject = qobject_cast<QDeclarativePropertyAnimation*>(animationComponent.create());
1123
1124         QVERIFY(animObject != 0);
1125         QCOMPARE(animObject->easing().type(), QEasingCurve::BezierSpline);
1126         QList<QPointF> points = animObject->easing().cubicBezierSpline();
1127         QCOMPARE(points.count(), 3);
1128         QCOMPARE(points.at(0), QPointF(0.5, 0.2));
1129         QCOMPARE(points.at(1), QPointF(0.13, 0.65));
1130         QCOMPARE(points.at(2), QPointF(1.0, 1.0));
1131     }
1132 }
1133
1134 void tst_qdeclarativeanimations::rotation()
1135 {
1136     QDeclarativeEngine engine;
1137     QDeclarativeComponent c(&engine, testFileUrl("rotation.qml"));
1138     QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
1139     QVERIFY(rect);
1140
1141     QQuickRectangle *rr = rect->findChild<QQuickRectangle*>("rr");
1142     QQuickRectangle *rr2 = rect->findChild<QQuickRectangle*>("rr2");
1143     QQuickRectangle *rr3 = rect->findChild<QQuickRectangle*>("rr3");
1144     QQuickRectangle *rr4 = rect->findChild<QQuickRectangle*>("rr4");
1145
1146     QQuickItemPrivate::get(rect)->setState("state1");
1147     QTest::qWait(800);
1148     qreal r1 = rr->rotation();
1149     qreal r2 = rr2->rotation();
1150     qreal r3 = rr3->rotation();
1151     qreal r4 = rr4->rotation();
1152
1153     QVERIFY(r1 > qreal(0) && r1 < qreal(370));
1154     QVERIFY(r2 > qreal(0) && r2 < qreal(370));
1155     QVERIFY(r3 < qreal(0) && r3 > qreal(-350));
1156     QVERIFY(r4 > qreal(0) && r4 < qreal(10));
1157     QCOMPARE(r1,r2);
1158     QVERIFY(r4 < r2);
1159
1160     QTest::qWait(800);
1161     QTIMED_COMPARE(rr->rotation() + rr2->rotation() + rr3->rotation() + rr4->rotation(), qreal(370*4));
1162 }
1163
1164 void tst_qdeclarativeanimations::runningTrueBug()
1165 {
1166     //ensure we start correctly when "running: true" is explicitly set
1167     QDeclarativeEngine engine;
1168     QDeclarativeComponent c(&engine, testFileUrl("runningTrueBug.qml"));
1169     QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
1170     QVERIFY(rect);
1171
1172     QQuickRectangle *cloud = rect->findChild<QQuickRectangle*>("cloud");
1173     QVERIFY(cloud);
1174     QTest::qWait(1000);
1175     QVERIFY(cloud->x() > qreal(0));
1176 }
1177
1178 //QTBUG-12805
1179 void tst_qdeclarativeanimations::nonTransitionBug()
1180 {
1181     //tests that the animation values from the previous transition are properly cleared
1182     //in the case where an animation in the transition doesn't match anything (but previously did)
1183     QDeclarativeEngine engine;
1184
1185     QDeclarativeComponent c(&engine, testFileUrl("nonTransitionBug.qml"));
1186     QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
1187     QVERIFY(rect != 0);
1188     QQuickItemPrivate *rectPrivate = QQuickItemPrivate::get(rect);
1189     QQuickRectangle *mover = rect->findChild<QQuickRectangle*>("mover");
1190
1191     mover->setX(100);
1192     QCOMPARE(mover->x(), qreal(100));
1193
1194     rectPrivate->setState("left");
1195     QTRY_COMPARE(mover->x(), qreal(0));
1196
1197     mover->setX(100);
1198     QCOMPARE(mover->x(), qreal(100));
1199
1200     //make sure we don't try to animate back to 0
1201     rectPrivate->setState("free");
1202     QTest::qWait(300);
1203     QCOMPARE(mover->x(), qreal(100));
1204 }
1205
1206 //QTBUG-14042
1207 void tst_qdeclarativeanimations::registrationBug()
1208 {
1209     QDeclarativeEngine engine;
1210
1211     QDeclarativeComponent c(&engine, testFileUrl("registrationBug.qml"));
1212     QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
1213     QVERIFY(rect != 0);
1214     QTRY_COMPARE(rect->property("value"), QVariant(int(100)));
1215 }
1216
1217 void tst_qdeclarativeanimations::doubleRegistrationBug()
1218 {
1219     QDeclarativeEngine engine;
1220
1221     QDeclarativeComponent c(&engine, testFileUrl("doubleRegistrationBug.qml"));
1222     QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
1223     QVERIFY(rect != 0);
1224
1225     QDeclarativeAbstractAnimation *anim = rect->findChild<QDeclarativeAbstractAnimation*>("animation");
1226     QVERIFY(anim != 0);
1227     QTRY_COMPARE(anim->qtAnimation()->state(), QAbstractAnimationJob::Stopped);
1228 }
1229
1230 //QTBUG-16736
1231 void tst_qdeclarativeanimations::alwaysRunToEndRestartBug()
1232 {
1233     QQuickRectangle rect;
1234     QDeclarativePropertyAnimation animation;
1235     animation.setTargetObject(&rect);
1236     animation.setProperty("x");
1237     animation.setTo(200);
1238     animation.setDuration(1000);
1239     animation.setLoops(-1);
1240     animation.setAlwaysRunToEnd(true);
1241     QVERIFY(animation.loops() == -1);
1242     QVERIFY(animation.alwaysRunToEnd() == true);
1243     animation.start();
1244     animation.stop();
1245     animation.start();
1246     animation.stop();
1247     QTest::qWait(500);
1248     QVERIFY(rect.x() != qreal(200));
1249     QTest::qWait(800);
1250     QTIMED_COMPARE(rect.x(), qreal(200));
1251     QCOMPARE(static_cast<QDeclarativeAbstractAnimation*>(&animation)->qtAnimation()->state(), QAbstractAnimationJob::Stopped);
1252 }
1253
1254 //QTBUG-20227
1255 void tst_qdeclarativeanimations::transitionAssignmentBug()
1256 {
1257     QDeclarativeEngine engine;
1258
1259     QDeclarativeComponent c(&engine, testFileUrl("transitionAssignmentBug.qml"));
1260     QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
1261     QVERIFY(rect != 0);
1262
1263     QCOMPARE(rect->property("nullObject").toBool(), false);
1264 }
1265
1266 //QTBUG-19080
1267 void tst_qdeclarativeanimations::pauseBindingBug()
1268 {
1269     QDeclarativeEngine engine;
1270
1271     QDeclarativeComponent c(&engine, testFileUrl("pauseBindingBug.qml"));
1272     QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
1273     QVERIFY(rect != 0);
1274     QDeclarativeAbstractAnimation *anim = rect->findChild<QDeclarativeAbstractAnimation*>("animation");
1275     QVERIFY(anim->qtAnimation()->state() == QAbstractAnimationJob::Paused);
1276
1277     delete rect;
1278 }
1279
1280 //QTBUG-13598
1281 void tst_qdeclarativeanimations::pauseBug()
1282 {
1283     QDeclarativeEngine engine;
1284
1285     QDeclarativeComponent c(&engine, testFileUrl("pauseBug.qml"));
1286     QDeclarativeAbstractAnimation *anim = qobject_cast<QDeclarativeAbstractAnimation*>(c.create());
1287     QVERIFY(anim != 0);
1288     QCOMPARE(anim->qtAnimation()->state(), QAbstractAnimationJob::Paused);
1289     QCOMPARE(anim->isPaused(), true);
1290     QCOMPARE(anim->isRunning(), true);
1291
1292     delete anim;
1293 }
1294
1295 //QTBUG-23092
1296 void tst_qdeclarativeanimations::loopingBug()
1297 {
1298     QDeclarativeEngine engine;
1299
1300     QDeclarativeComponent c(&engine, testFileUrl("looping.qml"));
1301     QObject *obj = c.create();
1302
1303     QDeclarativeAbstractAnimation *anim = obj->findChild<QDeclarativeAbstractAnimation*>();
1304     QVERIFY(anim != 0);
1305     QCOMPARE(anim->qtAnimation()->totalDuration(), 300);
1306     QCOMPARE(anim->isRunning(), true);
1307     QTRY_COMPARE(static_cast<QAnimationGroupJob*>(anim->qtAnimation())->firstChild()->currentLoop(), 2);
1308     QTRY_COMPARE(anim->isRunning(), false);
1309
1310     QQuickRectangle *rect = obj->findChild<QQuickRectangle*>();
1311     QVERIFY(rect != 0);
1312     QCOMPARE(rect->rotation(), qreal(90));
1313
1314     delete obj;
1315 }
1316
1317 QTEST_MAIN(tst_qdeclarativeanimations)
1318
1319 #include "tst_qdeclarativeanimations.moc"