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/private/qdeclarativesmoothedanimation_p.h>
45 #include <QtQuick1/private/qdeclarativerectangle_p.h>
46 #include <private/qdeclarativevaluetype_p.h>
47 #include "../../../shared/util.h"
50 // In Symbian OS test data is located in applications private dir
54 class tst_qdeclarativesmoothedanimation : public QObject
58 tst_qdeclarativesmoothedanimation();
64 void simpleAnimation();
69 QDeclarativeEngine engine;
72 tst_qdeclarativesmoothedanimation::tst_qdeclarativesmoothedanimation()
76 void tst_qdeclarativesmoothedanimation::defaultValues()
78 QDeclarativeEngine engine;
79 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/smoothedanimation1.qml"));
80 QDeclarative1SmoothedAnimation *obj = qobject_cast<QDeclarative1SmoothedAnimation*>(c.create());
84 QCOMPARE(obj->to(), 0.);
85 QCOMPARE(obj->velocity(), 200.);
86 QCOMPARE(obj->duration(), -1);
87 QCOMPARE(obj->maximumEasingTime(), -1);
88 QCOMPARE(obj->reversingMode(), QDeclarative1SmoothedAnimation::Eased);
93 void tst_qdeclarativesmoothedanimation::values()
95 QDeclarativeEngine engine;
96 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/smoothedanimation2.qml"));
97 QDeclarative1SmoothedAnimation *obj = qobject_cast<QDeclarative1SmoothedAnimation*>(c.create());
101 QCOMPARE(obj->to(), 10.);
102 QCOMPARE(obj->velocity(), 200.);
103 QCOMPARE(obj->duration(), 300);
104 QCOMPARE(obj->maximumEasingTime(), -1);
105 QCOMPARE(obj->reversingMode(), QDeclarative1SmoothedAnimation::Immediate);
110 void tst_qdeclarativesmoothedanimation::disabled()
112 QDeclarativeEngine engine;
113 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/smoothedanimation3.qml"));
114 QDeclarative1SmoothedAnimation *obj = qobject_cast<QDeclarative1SmoothedAnimation*>(c.create());
118 QCOMPARE(obj->to(), 10.);
119 QCOMPARE(obj->velocity(), 250.);
120 QCOMPARE(obj->maximumEasingTime(), 150);
121 QCOMPARE(obj->reversingMode(), QDeclarative1SmoothedAnimation::Sync);
126 void tst_qdeclarativesmoothedanimation::simpleAnimation()
128 QDeclarative1Rectangle rect;
129 QDeclarative1SmoothedAnimation animation;
130 animation.setTarget(&rect);
131 animation.setProperty("x");
132 animation.setTo(200);
133 animation.setDuration(250);
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 QTRY_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_qdeclarativesmoothedanimation::valueSource()
154 QDeclarativeEngine engine;
156 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/smoothedanimationValueSource.qml"));
158 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
161 QDeclarative1Rectangle *theRect = rect->findChild<QDeclarative1Rectangle*>("theRect");
164 QDeclarative1SmoothedAnimation *easeX = rect->findChild<QDeclarative1SmoothedAnimation*>("easeX");
166 QVERIFY(easeX->isRunning());
168 QDeclarative1SmoothedAnimation *easeY = rect->findChild<QDeclarative1SmoothedAnimation*>("easeY");
170 QVERIFY(easeY->isRunning());
172 // XXX get the proper duration
175 QTRY_VERIFY(!easeX->isRunning());
176 QTRY_VERIFY(!easeY->isRunning());
178 QTRY_COMPARE(theRect->x(), qreal(200));
179 QTRY_COMPARE(theRect->y(), qreal(200));
184 void tst_qdeclarativesmoothedanimation::behavior()
186 QDeclarativeEngine engine;
188 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/smoothedanimationBehavior.qml"));
190 QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
193 QDeclarative1Rectangle *theRect = rect->findChild<QDeclarative1Rectangle*>("theRect");
196 QDeclarative1SmoothedAnimation *easeX = rect->findChild<QDeclarative1SmoothedAnimation*>("easeX");
199 QDeclarative1SmoothedAnimation *easeY = rect->findChild<QDeclarative1SmoothedAnimation*>("easeY");
202 // XXX get the proper duration
205 QTRY_VERIFY(!easeX->isRunning());
206 QTRY_VERIFY(!easeY->isRunning());
208 QTRY_COMPARE(theRect->x(), qreal(200));
209 QTRY_COMPARE(theRect->y(), qreal(200));
214 QTEST_MAIN(tst_qdeclarativesmoothedanimation)
216 #include "tst_qdeclarativesmoothedanimation.moc"