Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / tests / auto / qtquick1 / qdeclarativesmoothedanimation / tst_qdeclarativesmoothedanimation.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 #include <qtest.h>
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
48 class tst_qdeclarativesmoothedanimation : public QObject
49 {
50     Q_OBJECT
51 public:
52     tst_qdeclarativesmoothedanimation();
53
54 private slots:
55     void defaultValues();
56     void values();
57     void disabled();
58     void simpleAnimation();
59     void valueSource();
60     void behavior();
61
62 private:
63     QDeclarativeEngine engine;
64 };
65
66 tst_qdeclarativesmoothedanimation::tst_qdeclarativesmoothedanimation()
67 {
68 }
69
70 void tst_qdeclarativesmoothedanimation::defaultValues()
71 {
72     QDeclarativeEngine engine;
73     QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/smoothedanimation1.qml"));
74     QDeclarative1SmoothedAnimation *obj = qobject_cast<QDeclarative1SmoothedAnimation*>(c.create());
75
76     QVERIFY(obj != 0);
77
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);
83
84     delete obj;
85 }
86
87 void tst_qdeclarativesmoothedanimation::values()
88 {
89     QDeclarativeEngine engine;
90     QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/smoothedanimation2.qml"));
91     QDeclarative1SmoothedAnimation *obj = qobject_cast<QDeclarative1SmoothedAnimation*>(c.create());
92
93     QVERIFY(obj != 0);
94
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);
100
101     delete obj;
102 }
103
104 void tst_qdeclarativesmoothedanimation::disabled()
105 {
106     QDeclarativeEngine engine;
107     QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/smoothedanimation3.qml"));
108     QDeclarative1SmoothedAnimation *obj = qobject_cast<QDeclarative1SmoothedAnimation*>(c.create());
109
110     QVERIFY(obj != 0);
111
112     QCOMPARE(obj->to(), 10.);
113     QCOMPARE(obj->velocity(), 250.);
114     QCOMPARE(obj->maximumEasingTime(), 150);
115     QCOMPARE(obj->reversingMode(), QDeclarative1SmoothedAnimation::Sync);
116
117     delete obj;
118 }
119
120 void tst_qdeclarativesmoothedanimation::simpleAnimation()
121 {
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);
131     animation.start();
132     QVERIFY(animation.isRunning());
133     QTest::qWait(animation.duration());
134     QTRY_COMPARE(rect.x(), qreal(200));
135
136     rect.setX(0);
137     animation.start();
138     animation.pause();
139     QVERIFY(animation.isRunning());
140     QVERIFY(animation.isPaused());
141     animation.setCurrentTime(125);
142     QVERIFY(animation.currentTime() == 125);
143     QCOMPARE(rect.x(), qreal(100));
144 }
145
146 void tst_qdeclarativesmoothedanimation::valueSource()
147 {
148     QDeclarativeEngine engine;
149
150     QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/smoothedanimationValueSource.qml"));
151
152     QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
153     QVERIFY(rect);
154
155     QDeclarative1Rectangle *theRect = rect->findChild<QDeclarative1Rectangle*>("theRect");
156     QVERIFY(theRect);
157
158     QDeclarative1SmoothedAnimation *easeX = rect->findChild<QDeclarative1SmoothedAnimation*>("easeX");
159     QVERIFY(easeX);
160     QVERIFY(easeX->isRunning());
161
162     QDeclarative1SmoothedAnimation *easeY = rect->findChild<QDeclarative1SmoothedAnimation*>("easeY");
163     QVERIFY(easeY);
164     QVERIFY(easeY->isRunning());
165
166     // XXX get the proper duration
167     QTest::qWait(100);
168
169     QTRY_VERIFY(!easeX->isRunning());
170     QTRY_VERIFY(!easeY->isRunning());
171
172     QTRY_COMPARE(theRect->x(), qreal(200));
173     QTRY_COMPARE(theRect->y(), qreal(200));
174
175     delete rect;
176 }
177
178 void tst_qdeclarativesmoothedanimation::behavior()
179 {
180     QDeclarativeEngine engine;
181
182     QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/smoothedanimationBehavior.qml"));
183
184     QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create());
185     QVERIFY(rect);
186
187     QDeclarative1Rectangle *theRect = rect->findChild<QDeclarative1Rectangle*>("theRect");
188     QVERIFY(theRect);
189
190     QDeclarative1SmoothedAnimation *easeX = rect->findChild<QDeclarative1SmoothedAnimation*>("easeX");
191     QVERIFY(easeX);
192
193     QDeclarative1SmoothedAnimation *easeY = rect->findChild<QDeclarative1SmoothedAnimation*>("easeY");
194     QVERIFY(easeY);
195
196     // XXX get the proper duration
197     QTest::qWait(400);
198
199     QTRY_VERIFY(!easeX->isRunning());
200     QTRY_VERIFY(!easeY->isRunning());
201
202     QTRY_COMPARE(theRect->x(), qreal(200));
203     QTRY_COMPARE(theRect->y(), qreal(200));
204
205     delete rect;
206 }
207
208 QTEST_MAIN(tst_qdeclarativesmoothedanimation)
209
210 #include "tst_qdeclarativesmoothedanimation.moc"