1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
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.
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.
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.
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.
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 class tst_qdeclarativeanimations : public QObject
55 tst_qdeclarativeanimations() {}
58 void initTestCase() { QDeclarativeEngine engine; } // ensure types are registered
60 void simpleProperty();
63 void simpleRotation();
64 void alwaysRunToEnd();
72 void propertiesTransition();
73 void invalidDuration();
75 void propertyValueSourceDefaultStart();
77 void easingProperties();
79 void runningTrueBug();
80 void nonTransitionBug();
81 void registrationBug();
82 void doubleRegistrationBug();
83 void alwaysRunToEndRestartBug();
84 void transitionAssignmentBug();
88 #define QTIMED_COMPARE(lhs, rhs) do { \
89 for (int ii = 0; ii < 5; ++ii) { \
97 void tst_qdeclarativeanimations::simpleProperty()
99 QDeclarative1Rectangle rect;
100 QDeclarative1PropertyAnimation animation;
101 animation.setTarget(&rect);
102 animation.setProperty("pos");
103 animation.setTo(QPointF(200,200));
104 QVERIFY(animation.target() == &rect);
105 QVERIFY(animation.property() == "pos");
106 QVERIFY(animation.to().toPointF() == QPointF(200,200));
108 QVERIFY(animation.isRunning());
109 QTest::qWait(animation.duration());
110 QTIMED_COMPARE(rect.pos(), QPointF(200,200));
115 QVERIFY(animation.isRunning());
116 QVERIFY(animation.isPaused());
117 animation.setCurrentTime(125);
118 QVERIFY(animation.currentTime() == 125);
119 QCOMPARE(rect.pos(), QPointF(100,100));
122 void tst_qdeclarativeanimations::simpleNumber()
124 QDeclarative1Rectangle rect;
125 QDeclarative1NumberAnimation animation;
126 animation.setTarget(&rect);
127 animation.setProperty("x");
128 animation.setTo(200);
129 QVERIFY(animation.target() == &rect);
130 QVERIFY(animation.property() == "x");
131 QVERIFY(animation.to() == 200);
133 QVERIFY(animation.isRunning());
134 QTest::qWait(animation.duration());
135 QTIMED_COMPARE(rect.x(), qreal(200));
140 QVERIFY(animation.isRunning());
141 QVERIFY(animation.isPaused());
142 animation.setCurrentTime(125);
143 QVERIFY(animation.currentTime() == 125);
144 QCOMPARE(rect.x(), qreal(100));
147 void tst_qdeclarativeanimations::simpleColor()
149 QDeclarative1Rectangle rect;
150 QDeclarative1ColorAnimation animation;
151 animation.setTarget(&rect);
152 animation.setProperty("color");
153 animation.setTo(QColor("red"));
154 QVERIFY(animation.target() == &rect);
155 QVERIFY(animation.property() == "color");
156 QVERIFY(animation.to() == QColor("red"));
158 QVERIFY(animation.isRunning());
159 QTest::qWait(animation.duration());
160 QTIMED_COMPARE(rect.color(), QColor("red"));
162 rect.setColor(QColor("blue"));
165 QVERIFY(animation.isRunning());
166 QVERIFY(animation.isPaused());
167 animation.setCurrentTime(125);
168 QVERIFY(animation.currentTime() == 125);
169 QCOMPARE(rect.color(), QColor::fromRgbF(0.498039, 0, 0.498039, 1));
171 rect.setColor(QColor("green"));
172 animation.setFrom(QColor("blue"));
173 QVERIFY(animation.from() == QColor("blue"));
175 QCOMPARE(rect.color(), QColor("blue"));
176 QVERIFY(animation.isRunning());
177 animation.setCurrentTime(125);
178 QCOMPARE(rect.color(), QColor::fromRgbF(0.498039, 0, 0.498039, 1));
181 void tst_qdeclarativeanimations::simpleRotation()
183 QDeclarative1Rectangle rect;
184 QDeclarative1RotationAnimation animation;
185 animation.setTarget(&rect);
186 animation.setProperty("rotation");
187 animation.setTo(270);
188 QVERIFY(animation.target() == &rect);
189 QVERIFY(animation.property() == "rotation");
190 QVERIFY(animation.to() == 270);
191 QVERIFY(animation.direction() == QDeclarative1RotationAnimation::Numerical);
193 QVERIFY(animation.isRunning());
194 QTest::qWait(animation.duration());
195 QTIMED_COMPARE(rect.rotation(), qreal(270));
200 QVERIFY(animation.isRunning());
201 QVERIFY(animation.isPaused());
202 animation.setCurrentTime(125);
203 QVERIFY(animation.currentTime() == 125);
204 QCOMPARE(rect.rotation(), qreal(135));
207 void tst_qdeclarativeanimations::alwaysRunToEnd()
209 QDeclarative1Rectangle rect;
210 QDeclarative1PropertyAnimation animation;
211 animation.setTarget(&rect);
212 animation.setProperty("x");
213 animation.setTo(200);
214 animation.setDuration(1000);
215 animation.setLoops(-1);
216 animation.setAlwaysRunToEnd(true);
217 QVERIFY(animation.loops() == -1);
218 QVERIFY(animation.alwaysRunToEnd() == true);
222 QVERIFY(rect.x() != qreal(200));
224 QTIMED_COMPARE(rect.x(), qreal(200));
227 void tst_qdeclarativeanimations::complete()
229 QDeclarative1Rectangle rect;
230 QDeclarative1PropertyAnimation animation;
231 animation.setTarget(&rect);
232 animation.setProperty("x");
233 animation.setFrom(1);
234 animation.setTo(200);
235 animation.setDuration(500);
236 QVERIFY(animation.from() == 1);
240 QVERIFY(rect.x() != qreal(200));
243 QVERIFY(animation.isRunning());
244 animation.complete();
245 QCOMPARE(rect.x(), qreal(200));
248 void tst_qdeclarativeanimations::resume()
250 QDeclarative1Rectangle rect;
251 QDeclarative1PropertyAnimation animation;
252 animation.setTarget(&rect);
253 animation.setProperty("x");
254 animation.setFrom(10);
255 animation.setTo(200);
256 animation.setDuration(1000);
257 QVERIFY(animation.from() == 10);
263 QVERIFY(x != qreal(200) && x != qreal(10));
264 QVERIFY(animation.isRunning());
265 QVERIFY(animation.isPaused());
268 QVERIFY(animation.isRunning());
269 QVERIFY(!animation.isPaused());
272 QVERIFY(rect.x() > x);
275 void tst_qdeclarativeanimations::dotProperty()
277 QDeclarativeEngine engine;
278 QString componentStr = "import QtQuick 1.0\nRectangle{ id: rect; NumberAnimation{ objectName: \"anim\"; target: rect; property: \"border.width\"; to: 10 }}";
279 QDeclarativeComponent animationComponent(&engine);
280 animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
281 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(animationComponent.create());
283 QDeclarative1NumberAnimation *animation = rect->findChild<QDeclarative1NumberAnimation*>("anim");
287 QTest::qWait(animation->duration()+50);
288 QTIMED_COMPARE(rect->border()->width(), 10);
290 rect->border()->setWidth(0);
293 animation->setCurrentTime(125);
294 QVERIFY(animation->currentTime() == 125);
295 QCOMPARE(rect->border()->width(), 5);
300 void tst_qdeclarativeanimations::badTypes()
304 QDeclarativeView *view = new QDeclarativeView;
305 view->setSource(QUrl::fromLocalFile(SRCDIR "/data/badtype1.qml"));
307 qApp->processEvents();
312 //make sure we get a compiler error
314 QDeclarativeEngine engine;
315 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/badtype2.qml"));
316 QTest::ignoreMessage(QtWarningMsg, "QDeclarativeComponent: Component is not ready");
319 QVERIFY(c.errors().count() == 1);
320 QCOMPARE(c.errors().at(0).description(), QLatin1String("Invalid property assignment: number expected"));
323 //make sure we get a compiler error
325 QDeclarativeEngine engine;
326 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/badtype3.qml"));
327 QTest::ignoreMessage(QtWarningMsg, "QDeclarativeComponent: Component is not ready");
330 QVERIFY(c.errors().count() == 1);
331 QCOMPARE(c.errors().at(0).description(), QLatin1String("Invalid property assignment: color expected"));
336 QDeclarativeEngine engine;
337 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/badtype4.qml"));
338 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
341 QDeclarativeItemPrivate::get(rect)->setState("state1");
342 QTest::qWait(1000 + 50);
343 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("MyRect");
345 QCOMPARE(myRect->x(),qreal(200));
349 void tst_qdeclarativeanimations::badProperties()
351 //make sure we get a runtime error
353 QDeclarativeEngine engine;
355 QDeclarativeComponent c1(&engine, QUrl::fromLocalFile(SRCDIR "/data/badproperty1.qml"));
356 QByteArray message = QUrl::fromLocalFile(SRCDIR "/data/badproperty1.qml").toString().toUtf8() + ":18:9: QML ColorAnimation: Cannot animate non-existent property \"border.colr\"";
357 QTest::ignoreMessage(QtWarningMsg, message);
358 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c1.create());
361 QDeclarativeComponent c2(&engine, QUrl::fromLocalFile(SRCDIR "/data/badproperty2.qml"));
362 message = QUrl::fromLocalFile(SRCDIR "/data/badproperty2.qml").toString().toUtf8() + ":18:9: QML ColorAnimation: Cannot animate read-only property \"border\"";
363 QTest::ignoreMessage(QtWarningMsg, message);
364 rect = qobject_cast<QDeclarative1Rectangle*>(c2.create());
367 //### should we warn here are well?
368 //rect->setState("state1");
372 //test animating mixed types with property animation in a transition
373 //for example, int + real; color + real; etc
374 void tst_qdeclarativeanimations::mixedTypes()
376 //assumes border.width stays a real -- not real robust
378 QDeclarativeEngine engine;
379 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/mixedtype1.qml"));
380 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
383 QDeclarativeItemPrivate::get(rect)->setState("state1");
385 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("MyRect");
388 //rather inexact -- is there a better way?
389 QVERIFY(myRect->x() > 100 && myRect->x() < 200);
390 QVERIFY(myRect->border()->width() > 1 && myRect->border()->width() < 10);
394 QDeclarativeEngine engine;
395 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/mixedtype2.qml"));
396 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
399 QDeclarativeItemPrivate::get(rect)->setState("state1");
401 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("MyRect");
404 //rather inexact -- is there a better way?
405 QVERIFY(myRect->x() > 100 && myRect->x() < 200);
406 QVERIFY(myRect->color() != QColor("red") && myRect->color() != QColor("blue"));
410 void tst_qdeclarativeanimations::properties()
412 const int waitDuration = 300;
414 QDeclarativeEngine engine;
415 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/properties.qml"));
416 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
419 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
421 QTest::qWait(waitDuration);
422 QTIMED_COMPARE(myRect->x(),qreal(200));
426 QDeclarativeEngine engine;
427 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/properties2.qml"));
428 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
431 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
433 QTest::qWait(waitDuration);
434 QTIMED_COMPARE(myRect->x(),qreal(200));
438 QDeclarativeEngine engine;
439 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/properties3.qml"));
440 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
443 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
445 QTest::qWait(waitDuration);
446 QTIMED_COMPARE(myRect->x(),qreal(300));
450 QDeclarativeEngine engine;
451 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/properties4.qml"));
452 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
455 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
457 QTest::qWait(waitDuration);
458 QTIMED_COMPARE(myRect->y(),qreal(200));
459 QTIMED_COMPARE(myRect->x(),qreal(100));
463 QDeclarativeEngine engine;
464 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/properties5.qml"));
465 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
468 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
470 QTest::qWait(waitDuration);
471 QTIMED_COMPARE(myRect->x(),qreal(100));
472 QTIMED_COMPARE(myRect->y(),qreal(200));
476 void tst_qdeclarativeanimations::propertiesTransition()
478 const int waitDuration = 300;
480 QDeclarativeEngine engine;
481 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition.qml"));
482 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
485 QDeclarativeItemPrivate::get(rect)->setState("moved");
486 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
488 QTest::qWait(waitDuration);
489 QTIMED_COMPARE(myRect->x(),qreal(200));
493 QDeclarativeEngine engine;
494 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition2.qml"));
495 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
498 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
500 QDeclarativeItemPrivate::get(rect)->setState("moved");
501 QCOMPARE(myRect->x(),qreal(200));
502 QCOMPARE(myRect->y(),qreal(100));
503 QTest::qWait(waitDuration);
504 QTIMED_COMPARE(myRect->y(),qreal(200));
508 QDeclarativeEngine engine;
509 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition3.qml"));
510 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
513 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
515 QDeclarativeItemPrivate::get(rect)->setState("moved");
516 QCOMPARE(myRect->x(),qreal(200));
517 QCOMPARE(myRect->y(),qreal(100));
521 QDeclarativeEngine engine;
522 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition4.qml"));
523 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
526 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
528 QDeclarativeItemPrivate::get(rect)->setState("moved");
529 QCOMPARE(myRect->x(),qreal(100));
530 QTest::qWait(waitDuration);
531 QTIMED_COMPARE(myRect->x(),qreal(200));
535 QDeclarativeEngine engine;
536 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition5.qml"));
537 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
540 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
542 QDeclarativeItemPrivate::get(rect)->setState("moved");
543 QCOMPARE(myRect->x(),qreal(100));
544 QTest::qWait(waitDuration);
545 QTIMED_COMPARE(myRect->x(),qreal(200));
549 QDeclarativeEngine engine;
550 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition6.qml"));
551 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
554 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
556 QDeclarativeItemPrivate::get(rect)->setState("moved");
557 QCOMPARE(myRect->x(),qreal(100));
558 QTest::qWait(waitDuration);
559 QTIMED_COMPARE(myRect->x(),qreal(100));
563 QDeclarativeEngine engine;
564 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertiesTransition7.qml"));
565 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
568 QDeclarativeItemPrivate::get(rect)->setState("moved");
569 QDeclarative1Rectangle *myRect = rect->findChild<QDeclarative1Rectangle*>("TheRect");
571 QTest::qWait(waitDuration);
572 QTIMED_COMPARE(myRect->x(),qreal(200));
577 void tst_qdeclarativeanimations::invalidDuration()
579 QDeclarative1PropertyAnimation *animation = new QDeclarative1PropertyAnimation;
580 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML PropertyAnimation: Cannot set a duration of < 0");
581 animation->setDuration(-1);
582 QCOMPARE(animation->duration(), 250);
584 QDeclarative1PauseAnimation *pauseAnimation = new QDeclarative1PauseAnimation;
585 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML PauseAnimation: Cannot set a duration of < 0");
586 pauseAnimation->setDuration(-1);
587 QCOMPARE(pauseAnimation->duration(), 250);
590 void tst_qdeclarativeanimations::attached()
592 QDeclarativeEngine engine;
594 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/attached.qml"));
595 QTest::ignoreMessage(QtDebugMsg, "off");
596 QTest::ignoreMessage(QtDebugMsg, "on");
597 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
601 void tst_qdeclarativeanimations::propertyValueSourceDefaultStart()
604 QDeclarativeEngine engine;
606 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/valuesource.qml"));
608 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
611 QDeclarative1AbstractAnimation *myAnim = rect->findChild<QDeclarative1AbstractAnimation*>("MyAnim");
613 QVERIFY(myAnim->isRunning());
617 QDeclarativeEngine engine;
619 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/valuesource2.qml"));
621 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
624 QDeclarative1AbstractAnimation *myAnim = rect->findChild<QDeclarative1AbstractAnimation*>("MyAnim");
626 QVERIFY(myAnim->isRunning() == false);
630 QDeclarativeEngine engine;
632 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/dontAutoStart.qml"));
634 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
637 QDeclarative1AbstractAnimation *myAnim = rect->findChild<QDeclarative1AbstractAnimation*>("MyAnim");
638 QVERIFY(myAnim && myAnim->qtAnimation());
639 QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped);
644 void tst_qdeclarativeanimations::dontStart()
647 QDeclarativeEngine engine;
649 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/dontStart.qml"));
651 QString warning = c.url().toString() + ":14:13: QML NumberAnimation: setRunning() cannot be used on non-root animation nodes.";
652 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
653 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
656 QDeclarative1AbstractAnimation *myAnim = rect->findChild<QDeclarative1AbstractAnimation*>("MyAnim");
657 QVERIFY(myAnim && myAnim->qtAnimation());
658 QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped);
662 QDeclarativeEngine engine;
664 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/dontStart2.qml"));
666 QString warning = c.url().toString() + ":15:17: QML NumberAnimation: setRunning() cannot be used on non-root animation nodes.";
667 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
668 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
671 QDeclarative1AbstractAnimation *myAnim = rect->findChild<QDeclarative1AbstractAnimation*>("MyAnim");
672 QVERIFY(myAnim && myAnim->qtAnimation());
673 QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped);
677 void tst_qdeclarativeanimations::easingProperties()
680 QDeclarativeEngine engine;
681 QString componentStr = "import QtQuick 1.0\nNumberAnimation { easing.type: \"InOutQuad\" }";
682 QDeclarativeComponent animationComponent(&engine);
683 animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
684 QDeclarative1PropertyAnimation *animObject = qobject_cast<QDeclarative1PropertyAnimation*>(animationComponent.create());
686 QVERIFY(animObject != 0);
687 QCOMPARE(animObject->easing().type(), QEasingCurve::InOutQuad);
691 QDeclarativeEngine engine;
692 QString componentStr = "import QtQuick 1.0\nPropertyAnimation { easing.type: \"OutBounce\"; easing.amplitude: 5.0 }";
693 QDeclarativeComponent animationComponent(&engine);
694 animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
695 QDeclarative1PropertyAnimation *animObject = qobject_cast<QDeclarative1PropertyAnimation*>(animationComponent.create());
697 QVERIFY(animObject != 0);
698 QCOMPARE(animObject->easing().type(), QEasingCurve::OutBounce);
699 QCOMPARE(animObject->easing().amplitude(), 5.0);
703 QDeclarativeEngine engine;
704 QString componentStr = "import QtQuick 1.0\nPropertyAnimation { easing.type: \"OutElastic\"; easing.amplitude: 5.0; easing.period: 3.0}";
705 QDeclarativeComponent animationComponent(&engine);
706 animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
707 QDeclarative1PropertyAnimation *animObject = qobject_cast<QDeclarative1PropertyAnimation*>(animationComponent.create());
709 QVERIFY(animObject != 0);
710 QCOMPARE(animObject->easing().type(), QEasingCurve::OutElastic);
711 QCOMPARE(animObject->easing().amplitude(), 5.0);
712 QCOMPARE(animObject->easing().period(), 3.0);
716 QDeclarativeEngine engine;
717 QString componentStr = "import QtQuick 1.0\nPropertyAnimation { easing.type: \"InOutBack\"; easing.overshoot: 2 }";
718 QDeclarativeComponent animationComponent(&engine);
719 animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
720 QDeclarative1PropertyAnimation *animObject = qobject_cast<QDeclarative1PropertyAnimation*>(animationComponent.create());
722 QVERIFY(animObject != 0);
723 QCOMPARE(animObject->easing().type(), QEasingCurve::InOutBack);
724 QCOMPARE(animObject->easing().overshoot(), 2.0);
728 void tst_qdeclarativeanimations::rotation()
730 QDeclarativeEngine engine;
731 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/rotation.qml"));
732 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
735 QDeclarative1Rectangle *rr = rect->findChild<QDeclarative1Rectangle*>("rr");
736 QDeclarative1Rectangle *rr2 = rect->findChild<QDeclarative1Rectangle*>("rr2");
737 QDeclarative1Rectangle *rr3 = rect->findChild<QDeclarative1Rectangle*>("rr3");
738 QDeclarative1Rectangle *rr4 = rect->findChild<QDeclarative1Rectangle*>("rr4");
740 QDeclarativeItemPrivate::get(rect)->setState("state1");
742 qreal r1 = rr->rotation();
743 qreal r2 = rr2->rotation();
744 qreal r3 = rr3->rotation();
745 qreal r4 = rr4->rotation();
747 QVERIFY(r1 > qreal(0) && r1 < qreal(370));
748 QVERIFY(r2 > qreal(0) && r2 < qreal(370));
749 QVERIFY(r3 < qreal(0) && r3 > qreal(-350));
750 QVERIFY(r4 > qreal(0) && r4 < qreal(10));
755 QTIMED_COMPARE(rr->rotation() + rr2->rotation() + rr3->rotation() + rr4->rotation(), qreal(370*4));
758 void tst_qdeclarativeanimations::runningTrueBug()
760 //ensure we start correctly when "running: true" is explicitly set
761 QDeclarativeEngine engine;
762 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/runningTrueBug.qml"));
763 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
766 QDeclarative1Rectangle *cloud = rect->findChild<QDeclarative1Rectangle*>("cloud");
769 QVERIFY(cloud->x() > qreal(0));
773 void tst_qdeclarativeanimations::nonTransitionBug()
775 //tests that the animation values from the previous transition are properly cleared
776 //in the case where an animation in the transition doesn't match anything (but previously did)
777 QDeclarativeEngine engine;
779 QDeclarativeComponent c(&engine, SRCDIR "/data/nonTransitionBug.qml");
780 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
782 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect);
783 QDeclarative1Rectangle *mover = rect->findChild<QDeclarative1Rectangle*>("mover");
786 QCOMPARE(mover->x(), qreal(100));
788 rectPrivate->setState("left");
789 QTRY_COMPARE(mover->x(), qreal(0));
792 QCOMPARE(mover->x(), qreal(100));
794 //make sure we don't try to animate back to 0
795 rectPrivate->setState("free");
797 QCOMPARE(mover->x(), qreal(100));
801 void tst_qdeclarativeanimations::registrationBug()
803 QDeclarativeEngine engine;
805 QDeclarativeComponent c(&engine, SRCDIR "/data/registrationBug.qml");
806 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
808 QTRY_COMPARE(rect->property("value"), QVariant(int(100)));
811 void tst_qdeclarativeanimations::doubleRegistrationBug()
813 QDeclarativeEngine engine;
815 QDeclarativeComponent c(&engine, SRCDIR "/data/doubleRegistrationBug.qml");
816 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
819 QDeclarative1AbstractAnimation *anim = rect->findChild<QDeclarative1AbstractAnimation*>("animation");
821 QTRY_COMPARE(anim->qtAnimation()->state(), QAbstractAnimation::Stopped);
825 void tst_qdeclarativeanimations::alwaysRunToEndRestartBug()
827 QDeclarative1Rectangle rect;
828 QDeclarative1PropertyAnimation animation;
829 animation.setTarget(&rect);
830 animation.setProperty("x");
831 animation.setTo(200);
832 animation.setDuration(1000);
833 animation.setLoops(-1);
834 animation.setAlwaysRunToEnd(true);
835 QVERIFY(animation.loops() == -1);
836 QVERIFY(animation.alwaysRunToEnd() == true);
842 QVERIFY(rect.x() != qreal(200));
844 QTIMED_COMPARE(rect.x(), qreal(200));
845 QCOMPARE(static_cast<QDeclarative1AbstractAnimation*>(&animation)->qtAnimation()->state(), QAbstractAnimation::Stopped);
849 void tst_qdeclarativeanimations::transitionAssignmentBug()
851 QDeclarativeEngine engine;
853 QDeclarativeComponent c(&engine, SRCDIR "/data/transitionAssignmentBug.qml");
854 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
857 QCOMPARE(rect->property("nullObject").toBool(), false);
861 void tst_qdeclarativeanimations::pauseBug()
863 QDeclarativeEngine engine;
865 QDeclarativeComponent c(&engine, SRCDIR "/data/pauseBug.qml");
866 QDeclarative1AbstractAnimation *anim = qobject_cast<QDeclarative1AbstractAnimation*>(c.create());
868 QCOMPARE(anim->qtAnimation()->state(), QAbstractAnimation::Paused);
869 QCOMPARE(anim->isPaused(), true);
870 QCOMPARE(anim->isRunning(), true);
875 QTEST_MAIN(tst_qdeclarativeanimations)
877 #include "tst_qdeclarativeanimations.moc"