1 /****************************************************************************
3 ** Copyright (C) 2012 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/private/qdeclarativesmoothedanimation_p.h>
45 #include <QtQuick1/private/qdeclarativerectangle_p.h>
46 #include <private/qdeclarativevaluetype_p.h>
48 class tst_qdeclarativesmoothedanimation : public QObject
52 tst_qdeclarativesmoothedanimation();
58 void simpleAnimation();
63 QDeclarativeEngine engine;
66 tst_qdeclarativesmoothedanimation::tst_qdeclarativesmoothedanimation()
70 void tst_qdeclarativesmoothedanimation::defaultValues()
72 QDeclarativeEngine engine;
73 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/smoothedanimation1.qml"));
74 QDeclarative1SmoothedAnimation *obj = qobject_cast<QDeclarative1SmoothedAnimation*>(c.create());
78 QCOMPARE(obj->to(), 0.);
79 QCOMPARE(obj->velocity(), 200.);
80 QCOMPARE(obj->duration(), -1);
81 QCOMPARE(obj->maximumEasingTime(), -1);
82 QCOMPARE(obj->reversingMode(), QDeclarative1SmoothedAnimation::Eased);
87 void tst_qdeclarativesmoothedanimation::values()
89 QDeclarativeEngine engine;
90 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/smoothedanimation2.qml"));
91 QDeclarative1SmoothedAnimation *obj = qobject_cast<QDeclarative1SmoothedAnimation*>(c.create());
95 QCOMPARE(obj->to(), 10.);
96 QCOMPARE(obj->velocity(), 200.);
97 QCOMPARE(obj->duration(), 300);
98 QCOMPARE(obj->maximumEasingTime(), -1);
99 QCOMPARE(obj->reversingMode(), QDeclarative1SmoothedAnimation::Immediate);
104 void tst_qdeclarativesmoothedanimation::disabled()
106 QDeclarativeEngine engine;
107 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/smoothedanimation3.qml"));
108 QDeclarative1SmoothedAnimation *obj = qobject_cast<QDeclarative1SmoothedAnimation*>(c.create());
112 QCOMPARE(obj->to(), 10.);
113 QCOMPARE(obj->velocity(), 250.);
114 QCOMPARE(obj->maximumEasingTime(), 150);
115 QCOMPARE(obj->reversingMode(), QDeclarative1SmoothedAnimation::Sync);
120 void tst_qdeclarativesmoothedanimation::simpleAnimation()
122 QDeclarative1Rectangle rect;
123 QDeclarative1SmoothedAnimation animation;
124 animation.setTarget(&rect);
125 animation.setProperty("x");
126 animation.setTo(200);
127 animation.setDuration(250);
128 QVERIFY(animation.target() == &rect);
129 QVERIFY(animation.property() == "x");
130 QVERIFY(animation.to() == 200);
132 QVERIFY(animation.isRunning());
133 QTest::qWait(animation.duration());
134 QTRY_COMPARE(rect.x(), qreal(200));
139 QVERIFY(animation.isRunning());
140 QVERIFY(animation.isPaused());
141 animation.setCurrentTime(125);
142 QVERIFY(animation.currentTime() == 125);
143 QCOMPARE(rect.x(), qreal(100));
146 void tst_qdeclarativesmoothedanimation::valueSource()
148 QDeclarativeEngine engine;
150 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/smoothedanimationValueSource.qml"));
152 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
155 QDeclarative1Rectangle *theRect = rect->findChild<QDeclarative1Rectangle*>("theRect");
158 QDeclarative1SmoothedAnimation *easeX = rect->findChild<QDeclarative1SmoothedAnimation*>("easeX");
160 QVERIFY(easeX->isRunning());
162 QDeclarative1SmoothedAnimation *easeY = rect->findChild<QDeclarative1SmoothedAnimation*>("easeY");
164 QVERIFY(easeY->isRunning());
166 // XXX get the proper duration
169 QTRY_VERIFY(!easeX->isRunning());
170 QTRY_VERIFY(!easeY->isRunning());
172 QTRY_COMPARE(theRect->x(), qreal(200));
173 QTRY_COMPARE(theRect->y(), qreal(200));
178 void tst_qdeclarativesmoothedanimation::behavior()
180 QDeclarativeEngine engine;
182 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/smoothedanimationBehavior.qml"));
184 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
187 QDeclarative1Rectangle *theRect = rect->findChild<QDeclarative1Rectangle*>("theRect");
190 QDeclarative1SmoothedAnimation *easeX = rect->findChild<QDeclarative1SmoothedAnimation*>("easeX");
193 QDeclarative1SmoothedAnimation *easeY = rect->findChild<QDeclarative1SmoothedAnimation*>("easeY");
196 // XXX get the proper duration
199 QTRY_VERIFY(!easeX->isRunning());
200 QTRY_VERIFY(!easeY->isRunning());
202 QTRY_COMPARE(theRect->x(), qreal(200));
203 QTRY_COMPARE(theRect->y(), qreal(200));
208 QTEST_MAIN(tst_qdeclarativesmoothedanimation)
210 #include "tst_qdeclarativesmoothedanimation.moc"