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 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include <QtDeclarative/qdeclarativeengine.h>
43 #include <QtDeclarative/qdeclarativecomponent.h>
44 #include <QtQuick1/qdeclarativeview.h>
45 #include <QtQuick1/private/qdeclarativerectangle_p.h>
46 #include <QtQuick1/private/qdeclarativeanimation_p.h>
47 #include <QtQuick1/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 QDeclarative1Rectangle rect;
105 QDeclarative1PropertyAnimation 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 QDeclarative1Rectangle rect;
130 QDeclarative1NumberAnimation 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 QDeclarative1Rectangle rect;
155 QDeclarative1ColorAnimation 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 QDeclarative1Rectangle rect;
189 QDeclarative1RotationAnimation 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() == QDeclarative1RotationAnimation::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 QDeclarative1Rectangle rect;
215 QDeclarative1PropertyAnimation 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 QDeclarative1Rectangle rect;
235 QDeclarative1PropertyAnimation 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 QDeclarative1Rectangle rect;
256 QDeclarative1PropertyAnimation 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 QDeclarativeEngine engine;
283 QString componentStr = "import QtQuick 1.0\nRectangle{ id: rect; NumberAnimation{ objectName: \"anim\"; target: rect; property: \"border.width\"; to: 10 }}";
284 QDeclarativeComponent animationComponent(&engine);
285 animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
286 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(animationComponent.create());
288 QDeclarative1NumberAnimation *animation = rect->findChild<QDeclarative1NumberAnimation*>("anim");
292 QTest::qWait(animation->duration()+50);
293 QTIMED_COMPARE(rect->border()->width(), 10);
295 rect->border()->setWidth(0);
298 animation->setCurrentTime(125);
299 QVERIFY(animation->currentTime() == 125);
300 QCOMPARE(rect->border()->width(), 5);
305 void tst_qdeclarativeanimations::badTypes()
309 QDeclarativeView *view = new QDeclarativeView;
310 view->setSource(QUrl::fromLocalFile(SRCDIR "/data/badtype1.qml"));
312 qApp->processEvents();
317 //make sure we get a compiler error
319 QDeclarativeEngine engine;
320 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/badtype2.qml"));
321 QTest::ignoreMessage(QtWarningMsg, "QDeclarativeComponent: Component is not ready");
324 QVERIFY(c.errors().count() == 1);
325 QCOMPARE(c.errors().at(0).description(), QLatin1String("Invalid property assignment: number expected"));
328 //make sure we get a compiler error
330 QDeclarativeEngine engine;
331 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/badtype3.qml"));
332 QTest::ignoreMessage(QtWarningMsg, "QDeclarativeComponent: Component is not ready");
335 QVERIFY(c.errors().count() == 1);
336 QCOMPARE(c.errors().at(0).description(), QLatin1String("Invalid property assignment: color expected"));
341 QDeclarativeEngine engine;
342 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/badtype4.qml"));
343 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
346 QDeclarativeItemPrivate::get(rect)->setState("state1");
347 QTest::qWait(1000 + 50);
348 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("MyRect");
350 QCOMPARE(myRect->x(),qreal(200));
354 void tst_qdeclarativeanimations::badProperties()
356 //make sure we get a runtime error
358 QDeclarativeEngine engine;
360 QDeclarativeComponent c1(&engine, QUrl::fromLocalFile(SRCDIR "/data/badproperty1.qml"));
361 QByteArray message = QUrl::fromLocalFile(SRCDIR "/data/badproperty1.qml").toString().toUtf8() + ":18:9: QML ColorAnimation: Cannot animate non-existent property \"border.colr\"";
362 QTest::ignoreMessage(QtWarningMsg, message);
363 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c1.create());
366 QDeclarativeComponent c2(&engine, QUrl::fromLocalFile(SRCDIR "/data/badproperty2.qml"));
367 message = QUrl::fromLocalFile(SRCDIR "/data/badproperty2.qml").toString().toUtf8() + ":18:9: QML ColorAnimation: Cannot animate read-only property \"border\"";
368 QTest::ignoreMessage(QtWarningMsg, message);
369 rect = qobject_cast<QDeclarative1Rectangle*>(c2.create());
372 //### should we warn here are well?
373 //rect->setState("state1");
377 //test animating mixed types with property animation in a transition
378 //for example, int + real; color + real; etc
379 void tst_qdeclarativeanimations::mixedTypes()
381 //assumes border.width stays a real -- not real robust
383 QDeclarativeEngine engine;
384 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/mixedtype1.qml"));
385 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
388 QDeclarativeItemPrivate::get(rect)->setState("state1");
390 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("MyRect");
393 //rather inexact -- is there a better way?
394 QVERIFY(myRect->x() > 100 && myRect->x() < 200);
395 QVERIFY(myRect->border()->width() > 1 && myRect->border()->width() < 10);
399 QDeclarativeEngine engine;
400 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/mixedtype2.qml"));
401 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
404 QDeclarativeItemPrivate::get(rect)->setState("state1");
406 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("MyRect");
409 //rather inexact -- is there a better way?
410 QVERIFY(myRect->x() > 100 && myRect->x() < 200);
411 QVERIFY(myRect->color() != QColor("red") && myRect->color() != QColor("blue"));
415 void tst_qdeclarativeanimations::properties()
417 const int waitDuration = 300;
419 QDeclarativeEngine engine;
420 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/properties.qml"));
421 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
424 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
426 QTest::qWait(waitDuration);
427 QTIMED_COMPARE(myRect->x(),qreal(200));
431 QDeclarativeEngine engine;
432 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/properties2.qml"));
433 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
436 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
438 QTest::qWait(waitDuration);
439 QTIMED_COMPARE(myRect->x(),qreal(200));
443 QDeclarativeEngine engine;
444 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/properties3.qml"));
445 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
448 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
450 QTest::qWait(waitDuration);
451 QTIMED_COMPARE(myRect->x(),qreal(300));
455 QDeclarativeEngine engine;
456 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/properties4.qml"));
457 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
460 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
462 QTest::qWait(waitDuration);
463 QTIMED_COMPARE(myRect->y(),qreal(200));
464 QTIMED_COMPARE(myRect->x(),qreal(100));
468 QDeclarativeEngine engine;
469 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/properties5.qml"));
470 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
473 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
475 QTest::qWait(waitDuration);
476 QTIMED_COMPARE(myRect->x(),qreal(100));
477 QTIMED_COMPARE(myRect->y(),qreal(200));
481 void tst_qdeclarativeanimations::propertiesTransition()
483 const int waitDuration = 300;
485 QDeclarativeEngine engine;
486 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition.qml"));
487 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
490 QDeclarativeItemPrivate::get(rect)->setState("moved");
491 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
493 QTest::qWait(waitDuration);
494 QTIMED_COMPARE(myRect->x(),qreal(200));
498 QDeclarativeEngine engine;
499 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition2.qml"));
500 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
503 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
505 QDeclarativeItemPrivate::get(rect)->setState("moved");
506 QCOMPARE(myRect->x(),qreal(200));
507 QCOMPARE(myRect->y(),qreal(100));
508 QTest::qWait(waitDuration);
509 QTIMED_COMPARE(myRect->y(),qreal(200));
513 QDeclarativeEngine engine;
514 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition3.qml"));
515 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
518 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
520 QDeclarativeItemPrivate::get(rect)->setState("moved");
521 QCOMPARE(myRect->x(),qreal(200));
522 QCOMPARE(myRect->y(),qreal(100));
526 QDeclarativeEngine engine;
527 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition4.qml"));
528 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
531 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
533 QDeclarativeItemPrivate::get(rect)->setState("moved");
534 QCOMPARE(myRect->x(),qreal(100));
535 QTest::qWait(waitDuration);
536 QTIMED_COMPARE(myRect->x(),qreal(200));
540 QDeclarativeEngine engine;
541 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition5.qml"));
542 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
545 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
547 QDeclarativeItemPrivate::get(rect)->setState("moved");
548 QCOMPARE(myRect->x(),qreal(100));
549 QTest::qWait(waitDuration);
550 QTIMED_COMPARE(myRect->x(),qreal(200));
554 QDeclarativeEngine engine;
555 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition6.qml"));
556 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
559 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
561 QDeclarativeItemPrivate::get(rect)->setState("moved");
562 QCOMPARE(myRect->x(),qreal(100));
563 QTest::qWait(waitDuration);
564 QTIMED_COMPARE(myRect->x(),qreal(100));
568 QDeclarativeEngine engine;
569 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition7.qml"));
570 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
573 QDeclarativeItemPrivate::get(rect)->setState("moved");
574 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
576 QTest::qWait(waitDuration);
577 QTIMED_COMPARE(myRect->x(),qreal(200));
582 void tst_qdeclarativeanimations::invalidDuration()
584 QDeclarative1PropertyAnimation *animation = new QDeclarative1PropertyAnimation;
585 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML PropertyAnimation: Cannot set a duration of < 0");
586 animation->setDuration(-1);
587 QCOMPARE(animation->duration(), 250);
589 QDeclarative1PauseAnimation *pauseAnimation = new QDeclarative1PauseAnimation;
590 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML PauseAnimation: Cannot set a duration of < 0");
591 pauseAnimation->setDuration(-1);
592 QCOMPARE(pauseAnimation->duration(), 250);
595 void tst_qdeclarativeanimations::attached()
597 QDeclarativeEngine engine;
599 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/attached.qml"));
600 QTest::ignoreMessage(QtDebugMsg, "off");
601 QTest::ignoreMessage(QtDebugMsg, "on");
602 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
606 void tst_qdeclarativeanimations::propertyValueSourceDefaultStart()
609 QDeclarativeEngine engine;
611 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/valuesource.qml"));
613 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
616 QDeclarative1AbstractAnimation *myAnim = rect->findChild<QDeclarative1AbstractAnimation*>("MyAnim");
618 QVERIFY(myAnim->isRunning());
622 QDeclarativeEngine engine;
624 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/valuesource2.qml"));
626 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
629 QDeclarative1AbstractAnimation *myAnim = rect->findChild<QDeclarative1AbstractAnimation*>("MyAnim");
631 QVERIFY(myAnim->isRunning() == false);
635 QDeclarativeEngine engine;
637 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/dontAutoStart.qml"));
639 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
642 QDeclarative1AbstractAnimation *myAnim = rect->findChild<QDeclarative1AbstractAnimation*>("MyAnim");
643 QVERIFY(myAnim && myAnim->qtAnimation());
644 QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped);
649 void tst_qdeclarativeanimations::dontStart()
652 QDeclarativeEngine engine;
654 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/dontStart.qml"));
656 QString warning = c.url().toString() + ":14:13: QML NumberAnimation: setRunning() cannot be used on non-root animation nodes.";
657 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
658 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
661 QDeclarative1AbstractAnimation *myAnim = rect->findChild<QDeclarative1AbstractAnimation*>("MyAnim");
662 QVERIFY(myAnim && myAnim->qtAnimation());
663 QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped);
667 QDeclarativeEngine engine;
669 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/dontStart2.qml"));
671 QString warning = c.url().toString() + ":15:17: QML NumberAnimation: setRunning() cannot be used on non-root animation nodes.";
672 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
673 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
676 QDeclarative1AbstractAnimation *myAnim = rect->findChild<QDeclarative1AbstractAnimation*>("MyAnim");
677 QVERIFY(myAnim && myAnim->qtAnimation());
678 QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped);
682 void tst_qdeclarativeanimations::easingProperties()
685 QDeclarativeEngine engine;
686 QString componentStr = "import QtQuick 1.0\nNumberAnimation { easing.type: \"InOutQuad\" }";
687 QDeclarativeComponent animationComponent(&engine);
688 animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
689 QDeclarative1PropertyAnimation *animObject = qobject_cast<QDeclarative1PropertyAnimation*>(animationComponent.create());
691 QVERIFY(animObject != 0);
692 QCOMPARE(animObject->easing().type(), QEasingCurve::InOutQuad);
696 QDeclarativeEngine engine;
697 QString componentStr = "import QtQuick 1.0\nPropertyAnimation { easing.type: \"OutBounce\"; easing.amplitude: 5.0 }";
698 QDeclarativeComponent animationComponent(&engine);
699 animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
700 QDeclarative1PropertyAnimation *animObject = qobject_cast<QDeclarative1PropertyAnimation*>(animationComponent.create());
702 QVERIFY(animObject != 0);
703 QCOMPARE(animObject->easing().type(), QEasingCurve::OutBounce);
704 QCOMPARE(animObject->easing().amplitude(), 5.0);
708 QDeclarativeEngine engine;
709 QString componentStr = "import QtQuick 1.0\nPropertyAnimation { easing.type: \"OutElastic\"; easing.amplitude: 5.0; easing.period: 3.0}";
710 QDeclarativeComponent animationComponent(&engine);
711 animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
712 QDeclarative1PropertyAnimation *animObject = qobject_cast<QDeclarative1PropertyAnimation*>(animationComponent.create());
714 QVERIFY(animObject != 0);
715 QCOMPARE(animObject->easing().type(), QEasingCurve::OutElastic);
716 QCOMPARE(animObject->easing().amplitude(), 5.0);
717 QCOMPARE(animObject->easing().period(), 3.0);
721 QDeclarativeEngine engine;
722 QString componentStr = "import QtQuick 1.0\nPropertyAnimation { easing.type: \"InOutBack\"; easing.overshoot: 2 }";
723 QDeclarativeComponent animationComponent(&engine);
724 animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
725 QDeclarative1PropertyAnimation *animObject = qobject_cast<QDeclarative1PropertyAnimation*>(animationComponent.create());
727 QVERIFY(animObject != 0);
728 QCOMPARE(animObject->easing().type(), QEasingCurve::InOutBack);
729 QCOMPARE(animObject->easing().overshoot(), 2.0);
733 void tst_qdeclarativeanimations::rotation()
735 QDeclarativeEngine engine;
736 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/rotation.qml"));
737 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
740 QDeclarative1Rectangle *rr = rect->findChild<QDeclarative1Rectangle*>("rr");
741 QDeclarative1Rectangle *rr2 = rect->findChild<QDeclarative1Rectangle*>("rr2");
742 QDeclarative1Rectangle *rr3 = rect->findChild<QDeclarative1Rectangle*>("rr3");
743 QDeclarative1Rectangle *rr4 = rect->findChild<QDeclarative1Rectangle*>("rr4");
745 QDeclarativeItemPrivate::get(rect)->setState("state1");
747 qreal r1 = rr->rotation();
748 qreal r2 = rr2->rotation();
749 qreal r3 = rr3->rotation();
750 qreal r4 = rr4->rotation();
752 QVERIFY(r1 > qreal(0) && r1 < qreal(370));
753 QVERIFY(r2 > qreal(0) && r2 < qreal(370));
754 QVERIFY(r3 < qreal(0) && r3 > qreal(-350));
755 QVERIFY(r4 > qreal(0) && r4 < qreal(10));
760 QTIMED_COMPARE(rr->rotation() + rr2->rotation() + rr3->rotation() + rr4->rotation(), qreal(370*4));
763 void tst_qdeclarativeanimations::runningTrueBug()
765 //ensure we start correctly when "running: true" is explicitly set
766 QDeclarativeEngine engine;
767 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/runningTrueBug.qml"));
768 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
771 QDeclarative1Rectangle *cloud = rect->findChild<QDeclarative1Rectangle*>("cloud");
774 QVERIFY(cloud->x() > qreal(0));
778 void tst_qdeclarativeanimations::nonTransitionBug()
780 //tests that the animation values from the previous transition are properly cleared
781 //in the case where an animation in the transition doesn't match anything (but previously did)
782 QDeclarativeEngine engine;
784 QDeclarativeComponent c(&engine, SRCDIR "/data/nonTransitionBug.qml");
785 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
787 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect);
788 QDeclarative1Rectangle *mover = rect->findChild<QDeclarative1Rectangle*>("mover");
791 QCOMPARE(mover->x(), qreal(100));
793 rectPrivate->setState("left");
794 QTRY_COMPARE(mover->x(), qreal(0));
797 QCOMPARE(mover->x(), qreal(100));
799 //make sure we don't try to animate back to 0
800 rectPrivate->setState("free");
802 QCOMPARE(mover->x(), qreal(100));
806 void tst_qdeclarativeanimations::registrationBug()
808 QDeclarativeEngine engine;
810 QDeclarativeComponent c(&engine, SRCDIR "/data/registrationBug.qml");
811 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
813 QTRY_COMPARE(rect->property("value"), QVariant(int(100)));
816 void tst_qdeclarativeanimations::doubleRegistrationBug()
818 QDeclarativeEngine engine;
820 QDeclarativeComponent c(&engine, SRCDIR "/data/doubleRegistrationBug.qml");
821 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
824 QDeclarative1AbstractAnimation *anim = rect->findChild<QDeclarative1AbstractAnimation*>("animation");
826 QTRY_COMPARE(anim->qtAnimation()->state(), QAbstractAnimation::Stopped);
830 void tst_qdeclarativeanimations::alwaysRunToEndRestartBug()
832 QDeclarative1Rectangle rect;
833 QDeclarative1PropertyAnimation animation;
834 animation.setTarget(&rect);
835 animation.setProperty("x");
836 animation.setTo(200);
837 animation.setDuration(1000);
838 animation.setLoops(-1);
839 animation.setAlwaysRunToEnd(true);
840 QVERIFY(animation.loops() == -1);
841 QVERIFY(animation.alwaysRunToEnd() == true);
847 QVERIFY(rect.x() != qreal(200));
849 QTIMED_COMPARE(rect.x(), qreal(200));
850 QCOMPARE(static_cast<QDeclarative1AbstractAnimation*>(&animation)->qtAnimation()->state(), QAbstractAnimation::Stopped);
853 QTEST_MAIN(tst_qdeclarativeanimations)
855 #include "tst_qdeclarativeanimations.moc"