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 <private/qdeclarativesmoothedanimation_p.h>
45 #include <QtQuick/private/qquickrectangle_p.h>
46 #include <private/qdeclarativevaluetype_p.h>
47 #include "../../shared/util.h"
49 class tst_qdeclarativesmoothedanimation : public QDeclarativeDataTest
53 tst_qdeclarativesmoothedanimation();
59 void simpleAnimation();
64 QDeclarativeEngine engine;
67 tst_qdeclarativesmoothedanimation::tst_qdeclarativesmoothedanimation()
71 void tst_qdeclarativesmoothedanimation::defaultValues()
73 QDeclarativeEngine engine;
74 QDeclarativeComponent c(&engine, testFileUrl("smoothedanimation1.qml"));
75 QDeclarativeSmoothedAnimation *obj = qobject_cast<QDeclarativeSmoothedAnimation*>(c.create());
79 QCOMPARE(obj->to(), 0.);
80 QCOMPARE(obj->velocity(), 200.);
81 QCOMPARE(obj->duration(), -1);
82 QCOMPARE(obj->maximumEasingTime(), -1);
83 QCOMPARE(obj->reversingMode(), QDeclarativeSmoothedAnimation::Eased);
88 void tst_qdeclarativesmoothedanimation::values()
90 QDeclarativeEngine engine;
91 QDeclarativeComponent c(&engine, testFileUrl("smoothedanimation2.qml"));
92 QDeclarativeSmoothedAnimation *obj = qobject_cast<QDeclarativeSmoothedAnimation*>(c.create());
96 QCOMPARE(obj->to(), 10.);
97 QCOMPARE(obj->velocity(), 200.);
98 QCOMPARE(obj->duration(), 300);
99 QCOMPARE(obj->maximumEasingTime(), -1);
100 QCOMPARE(obj->reversingMode(), QDeclarativeSmoothedAnimation::Immediate);
105 void tst_qdeclarativesmoothedanimation::disabled()
107 QDeclarativeEngine engine;
108 QDeclarativeComponent c(&engine, testFileUrl("smoothedanimation3.qml"));
109 QDeclarativeSmoothedAnimation *obj = qobject_cast<QDeclarativeSmoothedAnimation*>(c.create());
113 QCOMPARE(obj->to(), 10.);
114 QCOMPARE(obj->velocity(), 250.);
115 QCOMPARE(obj->maximumEasingTime(), 150);
116 QCOMPARE(obj->reversingMode(), QDeclarativeSmoothedAnimation::Sync);
121 void tst_qdeclarativesmoothedanimation::simpleAnimation()
123 QQuickRectangle rect;
124 QDeclarativeSmoothedAnimation animation;
125 animation.setTarget(&rect);
126 animation.setProperty("x");
127 animation.setTo(200);
128 animation.setDuration(250);
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 QTRY_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_qdeclarativesmoothedanimation::valueSource()
149 QDeclarativeEngine engine;
151 QDeclarativeComponent c(&engine, testFileUrl("smoothedanimationValueSource.qml"));
153 QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
156 QQuickRectangle *theRect = rect->findChild<QQuickRectangle*>("theRect");
159 QDeclarativeSmoothedAnimation *easeX = rect->findChild<QDeclarativeSmoothedAnimation*>("easeX");
161 QVERIFY(easeX->isRunning());
163 QDeclarativeSmoothedAnimation *easeY = rect->findChild<QDeclarativeSmoothedAnimation*>("easeY");
165 QVERIFY(easeY->isRunning());
167 // XXX get the proper duration
170 QTRY_VERIFY(!easeX->isRunning());
171 QTRY_VERIFY(!easeY->isRunning());
173 QTRY_COMPARE(theRect->x(), qreal(200));
174 QTRY_COMPARE(theRect->y(), qreal(200));
179 void tst_qdeclarativesmoothedanimation::behavior()
181 QDeclarativeEngine engine;
183 QDeclarativeComponent c(&engine, testFileUrl("smoothedanimationBehavior.qml"));
185 QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
188 QQuickRectangle *theRect = rect->findChild<QQuickRectangle*>("theRect");
191 QDeclarativeSmoothedAnimation *easeX = rect->findChild<QDeclarativeSmoothedAnimation*>("easeX");
194 QDeclarativeSmoothedAnimation *easeY = rect->findChild<QDeclarativeSmoothedAnimation*>("easeY");
197 // XXX get the proper duration
200 QTRY_VERIFY(!easeX->isRunning());
201 QTRY_VERIFY(!easeY->isRunning());
203 QTRY_COMPARE(theRect->x(), qreal(200));
204 QTRY_COMPARE(theRect->y(), qreal(200));
209 QTEST_MAIN(tst_qdeclarativesmoothedanimation)
211 #include "tst_qdeclarativesmoothedanimation.moc"