1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #include <QtDeclarative/qdeclarativeengine.h>
43 #include <QtDeclarative/qdeclarativecomponent.h>
44 #include <QtDeclarative/qdeclarativeview.h>
45 #include <private/qdeclarativerectangle_p.h>
46 #include <private/qdeclarativeanimation_p.h>
47 #include <private/qdeclarativeitem_p.h>
48 #include <QVariantAnimation>
49 #include <QEasingCurve>
51 #include "../../../shared/util.h"
54 // In Symbian OS test data is located in applications private dir
58 class tst_qdeclarativeanimations : public QObject
62 tst_qdeclarativeanimations() {}
65 void initTestCase() { QDeclarativeEngine engine; } // ensure types are registered
67 void simpleProperty();
70 void simpleRotation();
71 void alwaysRunToEnd();
79 void propertiesTransition();
80 void invalidDuration();
82 void propertyValueSourceDefaultStart();
84 void easingProperties();
86 void runningTrueBug();
87 void nonTransitionBug();
88 void registrationBug();
89 void doubleRegistrationBug();
90 void alwaysRunToEndRestartBug();
93 #define QTIMED_COMPARE(lhs, rhs) do { \
94 for (int ii = 0; ii < 5; ++ii) { \
102 void tst_qdeclarativeanimations::simpleProperty()
104 QDeclarativeRectangle rect;
105 QDeclarativePropertyAnimation animation;
106 animation.setTarget(&rect);
107 animation.setProperty("pos");
108 animation.setTo(QPointF(200,200));
109 QVERIFY(animation.target() == &rect);
110 QVERIFY(animation.property() == "pos");
111 QVERIFY(animation.to().toPointF() == QPointF(200,200));
113 QVERIFY(animation.isRunning());
114 QTest::qWait(animation.duration());
115 QTIMED_COMPARE(rect.pos(), QPointF(200,200));
120 QVERIFY(animation.isRunning());
121 QVERIFY(animation.isPaused());
122 animation.setCurrentTime(125);
123 QVERIFY(animation.currentTime() == 125);
124 QCOMPARE(rect.pos(), QPointF(100,100));
127 void tst_qdeclarativeanimations::simpleNumber()
129 QDeclarativeRectangle rect;
130 QDeclarativeNumberAnimation animation;
131 animation.setTarget(&rect);
132 animation.setProperty("x");
133 animation.setTo(200);
134 QVERIFY(animation.target() == &rect);
135 QVERIFY(animation.property() == "x");
136 QVERIFY(animation.to() == 200);
138 QVERIFY(animation.isRunning());
139 QTest::qWait(animation.duration());
140 QTIMED_COMPARE(rect.x(), qreal(200));
145 QVERIFY(animation.isRunning());
146 QVERIFY(animation.isPaused());
147 animation.setCurrentTime(125);
148 QVERIFY(animation.currentTime() == 125);
149 QCOMPARE(rect.x(), qreal(100));
152 void tst_qdeclarativeanimations::simpleColor()
154 QDeclarativeRectangle rect;
155 QDeclarativeColorAnimation animation;
156 animation.setTarget(&rect);
157 animation.setProperty("color");
158 animation.setTo(QColor("red"));
159 QVERIFY(animation.target() == &rect);
160 QVERIFY(animation.property() == "color");
161 QVERIFY(animation.to() == QColor("red"));
163 QVERIFY(animation.isRunning());
164 QTest::qWait(animation.duration());
165 QTIMED_COMPARE(rect.color(), QColor("red"));
167 rect.setColor(QColor("blue"));
170 QVERIFY(animation.isRunning());
171 QVERIFY(animation.isPaused());
172 animation.setCurrentTime(125);
173 QVERIFY(animation.currentTime() == 125);
174 QCOMPARE(rect.color(), QColor::fromRgbF(0.498039, 0, 0.498039, 1));
176 rect.setColor(QColor("green"));
177 animation.setFrom(QColor("blue"));
178 QVERIFY(animation.from() == QColor("blue"));
180 QCOMPARE(rect.color(), QColor("blue"));
181 QVERIFY(animation.isRunning());
182 animation.setCurrentTime(125);
183 QCOMPARE(rect.color(), QColor::fromRgbF(0.498039, 0, 0.498039, 1));
186 void tst_qdeclarativeanimations::simpleRotation()
188 QDeclarativeRectangle rect;
189 QDeclarativeRotationAnimation animation;
190 animation.setTarget(&rect);
191 animation.setProperty("rotation");
192 animation.setTo(270);
193 QVERIFY(animation.target() == &rect);
194 QVERIFY(animation.property() == "rotation");
195 QVERIFY(animation.to() == 270);
196 QVERIFY(animation.direction() == QDeclarativeRotationAnimation::Numerical);
198 QVERIFY(animation.isRunning());
199 QTest::qWait(animation.duration());
200 QTIMED_COMPARE(rect.rotation(), qreal(270));
205 QVERIFY(animation.isRunning());
206 QVERIFY(animation.isPaused());
207 animation.setCurrentTime(125);
208 QVERIFY(animation.currentTime() == 125);
209 QCOMPARE(rect.rotation(), qreal(135));
212 void tst_qdeclarativeanimations::alwaysRunToEnd()
214 QDeclarativeRectangle rect;
215 QDeclarativePropertyAnimation animation;
216 animation.setTarget(&rect);
217 animation.setProperty("x");
218 animation.setTo(200);
219 animation.setDuration(1000);
220 animation.setLoops(-1);
221 animation.setAlwaysRunToEnd(true);
222 QVERIFY(animation.loops() == -1);
223 QVERIFY(animation.alwaysRunToEnd() == true);
227 QVERIFY(rect.x() != qreal(200));
229 QTIMED_COMPARE(rect.x(), qreal(200));
232 void tst_qdeclarativeanimations::complete()
234 QDeclarativeRectangle rect;
235 QDeclarativePropertyAnimation animation;
236 animation.setTarget(&rect);
237 animation.setProperty("x");
238 animation.setFrom(1);
239 animation.setTo(200);
240 animation.setDuration(500);
241 QVERIFY(animation.from() == 1);
245 QVERIFY(rect.x() != qreal(200));
248 QVERIFY(animation.isRunning());
249 animation.complete();
250 QCOMPARE(rect.x(), qreal(200));
253 void tst_qdeclarativeanimations::resume()
255 QDeclarativeRectangle rect;
256 QDeclarativePropertyAnimation animation;
257 animation.setTarget(&rect);
258 animation.setProperty("x");
259 animation.setFrom(10);
260 animation.setTo(200);
261 animation.setDuration(1000);
262 QVERIFY(animation.from() == 10);
268 QVERIFY(x != qreal(200) && x != qreal(10));
269 QVERIFY(animation.isRunning());
270 QVERIFY(animation.isPaused());
273 QVERIFY(animation.isRunning());
274 QVERIFY(!animation.isPaused());
277 QVERIFY(rect.x() > x);
280 void tst_qdeclarativeanimations::dotProperty()
282 QDeclarativeRectangle rect;
283 QDeclarativeNumberAnimation animation;
284 animation.setTarget(&rect);
285 animation.setProperty("border.width");
288 QTest::qWait(animation.duration()+50);
289 QTIMED_COMPARE(rect.border()->width(), 10);
291 rect.border()->setWidth(0);
294 animation.setCurrentTime(125);
295 QVERIFY(animation.currentTime() == 125);
296 QCOMPARE(rect.border()->width(), 5);
299 void tst_qdeclarativeanimations::badTypes()
303 QDeclarativeView *view = new QDeclarativeView;
304 view->setSource(QUrl::fromLocalFile(SRCDIR "/data/badtype1.qml"));
306 qApp->processEvents();
311 //make sure we get a compiler error
313 QDeclarativeEngine engine;
314 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/badtype2.qml"));
315 QTest::ignoreMessage(QtWarningMsg, "QDeclarativeComponent: Component is not ready");
318 QVERIFY(c.errors().count() == 1);
319 QCOMPARE(c.errors().at(0).description(), QLatin1String("Invalid property assignment: number expected"));
322 //make sure we get a compiler error
324 QDeclarativeEngine engine;
325 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/badtype3.qml"));
326 QTest::ignoreMessage(QtWarningMsg, "QDeclarativeComponent: Component is not ready");
329 QVERIFY(c.errors().count() == 1);
330 QCOMPARE(c.errors().at(0).description(), QLatin1String("Invalid property assignment: color expected"));
335 QDeclarativeEngine engine;
336 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/badtype4.qml"));
337 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
340 QDeclarativeItemPrivate::get(rect)->setState("state1");
341 QTest::qWait(1000 + 50);
342 QDeclarativeRectangle *myRect = rect->findChild<QDeclarativeRectangle*>("MyRect");
344 QCOMPARE(myRect->x(),qreal(200));
348 void tst_qdeclarativeanimations::badProperties()
350 //make sure we get a runtime error
352 QDeclarativeEngine engine;
354 QDeclarativeComponent c1(&engine, QUrl::fromLocalFile(SRCDIR "/data/badproperty1.qml"));
355 QByteArray message = QUrl::fromLocalFile(SRCDIR "/data/badproperty1.qml").toString().toUtf8() + ":18:9: QML ColorAnimation: Cannot animate non-existent property \"border.colr\"";
356 QTest::ignoreMessage(QtWarningMsg, message);
357 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c1.create());
360 QDeclarativeComponent c2(&engine, QUrl::fromLocalFile(SRCDIR "/data/badproperty2.qml"));
361 message = QUrl::fromLocalFile(SRCDIR "/data/badproperty2.qml").toString().toUtf8() + ":18:9: QML ColorAnimation: Cannot animate read-only property \"border\"";
362 QTest::ignoreMessage(QtWarningMsg, message);
363 rect = qobject_cast<QDeclarativeRectangle*>(c2.create());
366 //### should we warn here are well?
367 //rect->setState("state1");
371 //test animating mixed types with property animation in a transition
372 //for example, int + real; color + real; etc
373 void tst_qdeclarativeanimations::mixedTypes()
375 //assumes border.width stays a real -- not real robust
377 QDeclarativeEngine engine;
378 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/mixedtype1.qml"));
379 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
382 QDeclarativeItemPrivate::get(rect)->setState("state1");
384 QDeclarativeRectangle *myRect = rect->findChild<QDeclarativeRectangle*>("MyRect");
387 //rather inexact -- is there a better way?
388 QVERIFY(myRect->x() > 100 && myRect->x() < 200);
389 QVERIFY(myRect->border()->width() > 1 && myRect->border()->width() < 10);
393 QDeclarativeEngine engine;
394 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/mixedtype2.qml"));
395 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
398 QDeclarativeItemPrivate::get(rect)->setState("state1");
400 QDeclarativeRectangle *myRect = rect->findChild<QDeclarativeRectangle*>("MyRect");
403 //rather inexact -- is there a better way?
404 QVERIFY(myRect->x() > 100 && myRect->x() < 200);
405 QVERIFY(myRect->color() != QColor("red") && myRect->color() != QColor("blue"));
409 void tst_qdeclarativeanimations::properties()
411 const int waitDuration = 300;
413 QDeclarativeEngine engine;
414 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/properties.qml"));
415 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
418 QDeclarativeRectangle *myRect = rect->findChild<QDeclarativeRectangle*>("TheRect");
420 QTest::qWait(waitDuration);
421 QTIMED_COMPARE(myRect->x(),qreal(200));
425 QDeclarativeEngine engine;
426 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/properties2.qml"));
427 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
430 QDeclarativeRectangle *myRect = rect->findChild<QDeclarativeRectangle*>("TheRect");
432 QTest::qWait(waitDuration);
433 QTIMED_COMPARE(myRect->x(),qreal(200));
437 QDeclarativeEngine engine;
438 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/properties3.qml"));
439 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
442 QDeclarativeRectangle *myRect = rect->findChild<QDeclarativeRectangle*>("TheRect");
444 QTest::qWait(waitDuration);
445 QTIMED_COMPARE(myRect->x(),qreal(300));
449 QDeclarativeEngine engine;
450 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/properties4.qml"));
451 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
454 QDeclarativeRectangle *myRect = rect->findChild<QDeclarativeRectangle*>("TheRect");
456 QTest::qWait(waitDuration);
457 QTIMED_COMPARE(myRect->y(),qreal(200));
458 QTIMED_COMPARE(myRect->x(),qreal(100));
462 QDeclarativeEngine engine;
463 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/properties5.qml"));
464 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
467 QDeclarativeRectangle *myRect = rect->findChild<QDeclarativeRectangle*>("TheRect");
469 QTest::qWait(waitDuration);
470 QTIMED_COMPARE(myRect->x(),qreal(100));
471 QTIMED_COMPARE(myRect->y(),qreal(200));
475 void tst_qdeclarativeanimations::propertiesTransition()
477 const int waitDuration = 300;
479 QDeclarativeEngine engine;
480 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition.qml"));
481 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
484 QDeclarativeItemPrivate::get(rect)->setState("moved");
485 QDeclarativeRectangle *myRect = rect->findChild<QDeclarativeRectangle*>("TheRect");
487 QTest::qWait(waitDuration);
488 QTIMED_COMPARE(myRect->x(),qreal(200));
492 QDeclarativeEngine engine;
493 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition2.qml"));
494 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
497 QDeclarativeRectangle *myRect = rect->findChild<QDeclarativeRectangle*>("TheRect");
499 QDeclarativeItemPrivate::get(rect)->setState("moved");
500 QCOMPARE(myRect->x(),qreal(200));
501 QCOMPARE(myRect->y(),qreal(100));
502 QTest::qWait(waitDuration);
503 QTIMED_COMPARE(myRect->y(),qreal(200));
507 QDeclarativeEngine engine;
508 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition3.qml"));
509 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
512 QDeclarativeRectangle *myRect = rect->findChild<QDeclarativeRectangle*>("TheRect");
514 QDeclarativeItemPrivate::get(rect)->setState("moved");
515 QCOMPARE(myRect->x(),qreal(200));
516 QCOMPARE(myRect->y(),qreal(100));
520 QDeclarativeEngine engine;
521 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition4.qml"));
522 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
525 QDeclarativeRectangle *myRect = rect->findChild<QDeclarativeRectangle*>("TheRect");
527 QDeclarativeItemPrivate::get(rect)->setState("moved");
528 QCOMPARE(myRect->x(),qreal(100));
529 QTest::qWait(waitDuration);
530 QTIMED_COMPARE(myRect->x(),qreal(200));
534 QDeclarativeEngine engine;
535 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition5.qml"));
536 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
539 QDeclarativeRectangle *myRect = rect->findChild<QDeclarativeRectangle*>("TheRect");
541 QDeclarativeItemPrivate::get(rect)->setState("moved");
542 QCOMPARE(myRect->x(),qreal(100));
543 QTest::qWait(waitDuration);
544 QTIMED_COMPARE(myRect->x(),qreal(200));
548 QDeclarativeEngine engine;
549 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition6.qml"));
550 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
553 QDeclarativeRectangle *myRect = rect->findChild<QDeclarativeRectangle*>("TheRect");
555 QDeclarativeItemPrivate::get(rect)->setState("moved");
556 QCOMPARE(myRect->x(),qreal(100));
557 QTest::qWait(waitDuration);
558 QTIMED_COMPARE(myRect->x(),qreal(100));
562 QDeclarativeEngine engine;
563 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition7.qml"));
564 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
567 QDeclarativeItemPrivate::get(rect)->setState("moved");
568 QDeclarativeRectangle *myRect = rect->findChild<QDeclarativeRectangle*>("TheRect");
570 QTest::qWait(waitDuration);
571 QTIMED_COMPARE(myRect->x(),qreal(200));
576 void tst_qdeclarativeanimations::invalidDuration()
578 QDeclarativePropertyAnimation *animation = new QDeclarativePropertyAnimation;
579 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML PropertyAnimation: Cannot set a duration of < 0");
580 animation->setDuration(-1);
581 QCOMPARE(animation->duration(), 250);
583 QDeclarativePauseAnimation *pauseAnimation = new QDeclarativePauseAnimation;
584 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML PauseAnimation: Cannot set a duration of < 0");
585 pauseAnimation->setDuration(-1);
586 QCOMPARE(pauseAnimation->duration(), 250);
589 void tst_qdeclarativeanimations::attached()
591 QDeclarativeEngine engine;
593 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/attached.qml"));
594 QTest::ignoreMessage(QtDebugMsg, "off");
595 QTest::ignoreMessage(QtDebugMsg, "on");
596 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
600 void tst_qdeclarativeanimations::propertyValueSourceDefaultStart()
603 QDeclarativeEngine engine;
605 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/valuesource.qml"));
607 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
610 QDeclarativeAbstractAnimation *myAnim = rect->findChild<QDeclarativeAbstractAnimation*>("MyAnim");
612 QVERIFY(myAnim->isRunning());
616 QDeclarativeEngine engine;
618 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/valuesource2.qml"));
620 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
623 QDeclarativeAbstractAnimation *myAnim = rect->findChild<QDeclarativeAbstractAnimation*>("MyAnim");
625 QVERIFY(myAnim->isRunning() == false);
629 QDeclarativeEngine engine;
631 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/dontAutoStart.qml"));
633 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
636 QDeclarativeAbstractAnimation *myAnim = rect->findChild<QDeclarativeAbstractAnimation*>("MyAnim");
637 QVERIFY(myAnim && myAnim->qtAnimation());
638 QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped);
643 void tst_qdeclarativeanimations::dontStart()
646 QDeclarativeEngine engine;
648 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/dontStart.qml"));
650 QString warning = c.url().toString() + ":14:13: QML NumberAnimation: setRunning() cannot be used on non-root animation nodes.";
651 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
652 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
655 QDeclarativeAbstractAnimation *myAnim = rect->findChild<QDeclarativeAbstractAnimation*>("MyAnim");
656 QVERIFY(myAnim && myAnim->qtAnimation());
657 QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped);
661 QDeclarativeEngine engine;
663 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/dontStart2.qml"));
665 QString warning = c.url().toString() + ":15:17: QML NumberAnimation: setRunning() cannot be used on non-root animation nodes.";
666 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
667 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
670 QDeclarativeAbstractAnimation *myAnim = rect->findChild<QDeclarativeAbstractAnimation*>("MyAnim");
671 QVERIFY(myAnim && myAnim->qtAnimation());
672 QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped);
676 void tst_qdeclarativeanimations::easingProperties()
679 QDeclarativeEngine engine;
680 QString componentStr = "import QtQuick 1.0\nNumberAnimation { easing.type: \"InOutQuad\" }";
681 QDeclarativeComponent animationComponent(&engine);
682 animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
683 QDeclarativePropertyAnimation *animObject = qobject_cast<QDeclarativePropertyAnimation*>(animationComponent.create());
685 QVERIFY(animObject != 0);
686 QCOMPARE(animObject->easing().type(), QEasingCurve::InOutQuad);
690 QDeclarativeEngine engine;
691 QString componentStr = "import QtQuick 1.0\nPropertyAnimation { easing.type: \"OutBounce\"; easing.amplitude: 5.0 }";
692 QDeclarativeComponent animationComponent(&engine);
693 animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
694 QDeclarativePropertyAnimation *animObject = qobject_cast<QDeclarativePropertyAnimation*>(animationComponent.create());
696 QVERIFY(animObject != 0);
697 QCOMPARE(animObject->easing().type(), QEasingCurve::OutBounce);
698 QCOMPARE(animObject->easing().amplitude(), 5.0);
702 QDeclarativeEngine engine;
703 QString componentStr = "import QtQuick 1.0\nPropertyAnimation { easing.type: \"OutElastic\"; easing.amplitude: 5.0; easing.period: 3.0}";
704 QDeclarativeComponent animationComponent(&engine);
705 animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
706 QDeclarativePropertyAnimation *animObject = qobject_cast<QDeclarativePropertyAnimation*>(animationComponent.create());
708 QVERIFY(animObject != 0);
709 QCOMPARE(animObject->easing().type(), QEasingCurve::OutElastic);
710 QCOMPARE(animObject->easing().amplitude(), 5.0);
711 QCOMPARE(animObject->easing().period(), 3.0);
715 QDeclarativeEngine engine;
716 QString componentStr = "import QtQuick 1.0\nPropertyAnimation { easing.type: \"InOutBack\"; easing.overshoot: 2 }";
717 QDeclarativeComponent animationComponent(&engine);
718 animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
719 QDeclarativePropertyAnimation *animObject = qobject_cast<QDeclarativePropertyAnimation*>(animationComponent.create());
721 QVERIFY(animObject != 0);
722 QCOMPARE(animObject->easing().type(), QEasingCurve::InOutBack);
723 QCOMPARE(animObject->easing().overshoot(), 2.0);
727 void tst_qdeclarativeanimations::rotation()
729 QDeclarativeEngine engine;
730 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/rotation.qml"));
731 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
734 QDeclarativeRectangle *rr = rect->findChild<QDeclarativeRectangle*>("rr");
735 QDeclarativeRectangle *rr2 = rect->findChild<QDeclarativeRectangle*>("rr2");
736 QDeclarativeRectangle *rr3 = rect->findChild<QDeclarativeRectangle*>("rr3");
737 QDeclarativeRectangle *rr4 = rect->findChild<QDeclarativeRectangle*>("rr4");
739 QDeclarativeItemPrivate::get(rect)->setState("state1");
741 qreal r1 = rr->rotation();
742 qreal r2 = rr2->rotation();
743 qreal r3 = rr3->rotation();
744 qreal r4 = rr4->rotation();
746 QVERIFY(r1 > qreal(0) && r1 < qreal(370));
747 QVERIFY(r2 > qreal(0) && r2 < qreal(370));
748 QVERIFY(r3 < qreal(0) && r3 > qreal(-350));
749 QVERIFY(r4 > qreal(0) && r4 < qreal(10));
754 QTIMED_COMPARE(rr->rotation() + rr2->rotation() + rr3->rotation() + rr4->rotation(), qreal(370*4));
757 void tst_qdeclarativeanimations::runningTrueBug()
759 //ensure we start correctly when "running: true" is explicitly set
760 QDeclarativeEngine engine;
761 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/runningTrueBug.qml"));
762 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
765 QDeclarativeRectangle *cloud = rect->findChild<QDeclarativeRectangle*>("cloud");
768 QVERIFY(cloud->x() > qreal(0));
772 void tst_qdeclarativeanimations::nonTransitionBug()
774 //tests that the animation values from the previous transition are properly cleared
775 //in the case where an animation in the transition doesn't match anything (but previously did)
776 QDeclarativeEngine engine;
778 QDeclarativeComponent c(&engine, SRCDIR "/data/nonTransitionBug.qml");
779 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
781 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect);
782 QDeclarativeRectangle *mover = rect->findChild<QDeclarativeRectangle*>("mover");
785 QCOMPARE(mover->x(), qreal(100));
787 rectPrivate->setState("left");
788 QTRY_COMPARE(mover->x(), qreal(0));
791 QCOMPARE(mover->x(), qreal(100));
793 //make sure we don't try to animate back to 0
794 rectPrivate->setState("free");
796 QCOMPARE(mover->x(), qreal(100));
800 void tst_qdeclarativeanimations::registrationBug()
802 QDeclarativeEngine engine;
804 QDeclarativeComponent c(&engine, SRCDIR "/data/registrationBug.qml");
805 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
807 QTRY_COMPARE(rect->property("value"), QVariant(int(100)));
810 void tst_qdeclarativeanimations::doubleRegistrationBug()
812 QDeclarativeEngine engine;
814 QDeclarativeComponent c(&engine, SRCDIR "/data/doubleRegistrationBug.qml");
815 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
818 QDeclarativeAbstractAnimation *anim = rect->findChild<QDeclarativeAbstractAnimation*>("animation");
820 QTRY_COMPARE(anim->qtAnimation()->state(), QAbstractAnimation::Stopped);
824 void tst_qdeclarativeanimations::alwaysRunToEndRestartBug()
826 QDeclarativeRectangle rect;
827 QDeclarativePropertyAnimation animation;
828 animation.setTarget(&rect);
829 animation.setProperty("x");
830 animation.setTo(200);
831 animation.setDuration(1000);
832 animation.setLoops(-1);
833 animation.setAlwaysRunToEnd(true);
834 QVERIFY(animation.loops() == -1);
835 QVERIFY(animation.alwaysRunToEnd() == true);
841 QVERIFY(rect.x() != qreal(200));
843 QTIMED_COMPARE(rect.x(), qreal(200));
844 QCOMPARE(static_cast<QDeclarativeAbstractAnimation*>(&animation)->qtAnimation()->state(), QAbstractAnimation::Stopped);
847 QTEST_MAIN(tst_qdeclarativeanimations)
849 #include "tst_qdeclarativeanimations.moc"