diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2012-02-03 12:26:37 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-07 05:32:47 +0100 |
commit | ce3dee765c858a0b573d468ef8fee6b838e576d1 (patch) | |
tree | b7026a061b0b58bac6af30eaab6e610c5ebeb504 /tests/auto/qtquick2 | |
parent | 0ca9d3f0f720e1933379ef40bc5c29253e21cba0 (diff) |
Add and use new animation backend.
The new backend improves performance, and allows us to create
multiple running animation jobs from a single Transition. It is
based off of the existing Qt animation framework.
Change-Id: Id1d0162f6e5c65bf31267f3f9f2042c354375d57
Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
Diffstat (limited to 'tests/auto/qtquick2')
9 files changed, 165 insertions, 43 deletions
diff --git a/tests/auto/qtquick2/qdeclarativeanimationcontroller/data/tst_numberanimation.qml b/tests/auto/qtquick2/qdeclarativeanimationcontroller/data/tst_numberanimation.qml new file mode 100644 index 0000000000..7c4496b206 --- /dev/null +++ b/tests/auto/qtquick2/qdeclarativeanimationcontroller/data/tst_numberanimation.qml @@ -0,0 +1,38 @@ +import QtQuick 2.0 +import QtTest 1.0 + +Rectangle { + id:container + width:50 + height:50 + + Rectangle {id:rect; x:0; y:0; color:"red"; width:10; height:10} + AnimationController { + id:numberAnimationcontroller + progress:1 + animation: NumberAnimation {target: rect; property: "x"; from:0; to:40; duration: 1000} + } + + TestCase { + name:"AnimationController" + when:windowShown + function test_numberAnimation() { + numberAnimationcontroller.progress = 0; + compare(rect.x, 0); + numberAnimationcontroller.progress = 0.5; + compare(rect.x, 20); + + // <=0 -> 0 + numberAnimationcontroller.progress = -1; + compare(rect.x, 0); + + //>=1 -> 1 + numberAnimationcontroller.progress = 1.1; + compare(rect.x, 40); + + //make sure the progress can be set backward + numberAnimationcontroller.progress = 0.5; + compare(rect.x, 20); + } + } +}
\ No newline at end of file diff --git a/tests/auto/qtquick2/qdeclarativeanimationcontroller/qdeclarativeanimationcontroller.pro b/tests/auto/qtquick2/qdeclarativeanimationcontroller/qdeclarativeanimationcontroller.pro new file mode 100644 index 0000000000..52cafc33a6 --- /dev/null +++ b/tests/auto/qtquick2/qdeclarativeanimationcontroller/qdeclarativeanimationcontroller.pro @@ -0,0 +1,10 @@ +QT += core-private gui-private declarative-private +TEMPLATE=app +TARGET=tst_qdeclarativeanimationcontroller + +CONFIG += warn_on qmltestcase +SOURCES += tst_qdeclarativeanimationcontroller.cpp + +importFiles.files = data +importFiles.path = . +DEPLOYMENT += importFiles diff --git a/tests/auto/qtquick2/qdeclarativeanimationcontroller/tst_qdeclarativeanimationcontroller.cpp b/tests/auto/qtquick2/qdeclarativeanimationcontroller/tst_qdeclarativeanimationcontroller.cpp new file mode 100644 index 0000000000..744f92b99d --- /dev/null +++ b/tests/auto/qtquick2/qdeclarativeanimationcontroller/tst_qdeclarativeanimationcontroller.cpp @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtQuickTest/quicktest.h> +QUICK_TEST_MAIN(qdeclarativeanimationcontroller) diff --git a/tests/auto/qtquick2/qdeclarativeanimations/tst_qdeclarativeanimations.cpp b/tests/auto/qtquick2/qdeclarativeanimations/tst_qdeclarativeanimations.cpp index 1340b514f9..3151a99407 100644 --- a/tests/auto/qtquick2/qdeclarativeanimations/tst_qdeclarativeanimations.cpp +++ b/tests/auto/qtquick2/qdeclarativeanimations/tst_qdeclarativeanimations.cpp @@ -130,8 +130,8 @@ void tst_qdeclarativeanimations::simpleProperty() rect.setPos(QPointF(0,0)); animation.start(); - animation.pause(); QVERIFY(animation.isRunning()); + animation.pause(); QVERIFY(animation.isPaused()); animation.setCurrentTime(125); QVERIFY(animation.currentTime() == 125); @@ -887,8 +887,8 @@ void tst_qdeclarativeanimations::propertyValueSourceDefaultStart() QVERIFY(rect); QDeclarativeAbstractAnimation *myAnim = rect->findChild<QDeclarativeAbstractAnimation*>("MyAnim"); - QVERIFY(myAnim && myAnim->qtAnimation()); - QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped); + QVERIFY(myAnim && !myAnim->qtAnimation()); + //QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimationJob::Stopped); } } @@ -906,8 +906,8 @@ void tst_qdeclarativeanimations::dontStart() QVERIFY(rect); QDeclarativeAbstractAnimation *myAnim = rect->findChild<QDeclarativeAbstractAnimation*>("MyAnim"); - QVERIFY(myAnim && myAnim->qtAnimation()); - QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped); + QVERIFY(myAnim && !myAnim->qtAnimation()); + //QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimationJob::Stopped); } { @@ -921,8 +921,8 @@ void tst_qdeclarativeanimations::dontStart() QVERIFY(rect); QDeclarativeAbstractAnimation *myAnim = rect->findChild<QDeclarativeAbstractAnimation*>("MyAnim"); - QVERIFY(myAnim && myAnim->qtAnimation()); - QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped); + QVERIFY(myAnim && !myAnim->qtAnimation()); + //QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimationJob::Stopped); } } @@ -1086,7 +1086,7 @@ void tst_qdeclarativeanimations::doubleRegistrationBug() QDeclarativeAbstractAnimation *anim = rect->findChild<QDeclarativeAbstractAnimation*>("animation"); QVERIFY(anim != 0); - QTRY_COMPARE(anim->qtAnimation()->state(), QAbstractAnimation::Stopped); + QTRY_COMPARE(anim->qtAnimation()->state(), QAbstractAnimationJob::Stopped); } //QTBUG-16736 @@ -1110,7 +1110,7 @@ void tst_qdeclarativeanimations::alwaysRunToEndRestartBug() QVERIFY(rect.x() != qreal(200)); QTest::qWait(800); QTIMED_COMPARE(rect.x(), qreal(200)); - QCOMPARE(static_cast<QDeclarativeAbstractAnimation*>(&animation)->qtAnimation()->state(), QAbstractAnimation::Stopped); + QCOMPARE(static_cast<QDeclarativeAbstractAnimation*>(&animation)->qtAnimation()->state(), QAbstractAnimationJob::Stopped); } //QTBUG-20227 @@ -1134,7 +1134,7 @@ void tst_qdeclarativeanimations::pauseBindingBug() QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); QVERIFY(rect != 0); QDeclarativeAbstractAnimation *anim = rect->findChild<QDeclarativeAbstractAnimation*>("animation"); - QVERIFY(anim->qtAnimation()->state() == QAbstractAnimation::Paused); + QVERIFY(anim->qtAnimation()->state() == QAbstractAnimationJob::Paused); delete rect; } @@ -1147,7 +1147,7 @@ void tst_qdeclarativeanimations::pauseBug() QDeclarativeComponent c(&engine, testFileUrl("pauseBug.qml")); QDeclarativeAbstractAnimation *anim = qobject_cast<QDeclarativeAbstractAnimation*>(c.create()); QVERIFY(anim != 0); - QCOMPARE(anim->qtAnimation()->state(), QAbstractAnimation::Paused); + QCOMPARE(anim->qtAnimation()->state(), QAbstractAnimationJob::Paused); QCOMPARE(anim->isPaused(), true); QCOMPARE(anim->isRunning(), true); diff --git a/tests/auto/qtquick2/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp b/tests/auto/qtquick2/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp index 085f4000f0..c1e60f1560 100644 --- a/tests/auto/qtquick2/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp +++ b/tests/auto/qtquick2/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp @@ -335,8 +335,7 @@ void tst_qdeclarativebehaviors::dontStart() QVERIFY(rect); QDeclarativeAbstractAnimation *myAnim = rect->findChild<QDeclarativeAbstractAnimation*>("MyAnim"); - QVERIFY(myAnim && myAnim->qtAnimation()); - QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped); + QVERIFY(myAnim && !myAnim->qtAnimation()); delete rect; } diff --git a/tests/auto/qtquick2/qdeclarativesmoothedanimation/data/simpleanimation.qml b/tests/auto/qtquick2/qdeclarativesmoothedanimation/data/simpleanimation.qml new file mode 100644 index 0000000000..b2be63ec94 --- /dev/null +++ b/tests/auto/qtquick2/qdeclarativesmoothedanimation/data/simpleanimation.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0 + +Rectangle { + width: 300; height: 300; + Rectangle { + objectName: "rect" + color: "red" + width: 60; height: 60; + x: 100; y: 100; + } + SmoothedAnimation { objectName: "anim"} +}
\ No newline at end of file diff --git a/tests/auto/qtquick2/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp b/tests/auto/qtquick2/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp index 5ab3e96e06..f60955c58e 100644 --- a/tests/auto/qtquick2/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp +++ b/tests/auto/qtquick2/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp @@ -41,7 +41,7 @@ #include <qtest.h> #include <QtDeclarative/qdeclarativeengine.h> #include <QtDeclarative/qdeclarativecomponent.h> -#include <private/qdeclarativesmoothedanimation_p.h> +#include <QtQuick/private/qdeclarativesmoothedanimation_p.h> #include <QtQuick/private/qquickrectangle_p.h> #include <private/qdeclarativevaluetype_p.h> #include "../../shared/util.h" @@ -120,28 +120,40 @@ void tst_qdeclarativesmoothedanimation::disabled() void tst_qdeclarativesmoothedanimation::simpleAnimation() { - QQuickRectangle rect; - QDeclarativeSmoothedAnimation animation; - animation.setTarget(&rect); - animation.setProperty("x"); - animation.setTo(200); - animation.setDuration(250); - QVERIFY(animation.target() == &rect); - QVERIFY(animation.property() == "x"); - QVERIFY(animation.to() == 200); - animation.start(); - QVERIFY(animation.isRunning()); - QTest::qWait(animation.duration()); - QTRY_COMPARE(rect.x(), qreal(200)); - - rect.setX(0); - animation.start(); - animation.pause(); - QVERIFY(animation.isRunning()); - QVERIFY(animation.isPaused()); - animation.setCurrentTime(125); - QVERIFY(animation.currentTime() == 125); - QCOMPARE(rect.x(), qreal(100)); + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, testFileUrl("simpleanimation.qml")); + QObject *obj = c.create(); + QVERIFY(obj); + + QQuickRectangle *rect = obj->findChild<QQuickRectangle*>("rect"); + QVERIFY(rect); + + QDeclarativeSmoothedAnimation *animation = obj->findChild<QDeclarativeSmoothedAnimation*>("anim"); + QVERIFY(animation); + + animation->setTarget(rect); + animation->setProperty("x"); + animation->setTo(200); + animation->setDuration(250); + QVERIFY(animation->target() == rect); + QVERIFY(animation->property() == "x"); + QVERIFY(animation->to() == 200); + animation->start(); + QVERIFY(animation->isRunning()); + QTest::qWait(animation->duration()); + QTRY_COMPARE(rect->x(), qreal(200)); + QTest::qWait(100); //smoothed animation doesn't report stopped until delayed timer fires + + QVERIFY(!animation->isRunning()); + rect->setX(0); + animation->start(); + QVERIFY(animation->isRunning()); + animation->pause(); + QVERIFY(animation->isRunning()); + QVERIFY(animation->isPaused()); + animation->setCurrentTime(125); + QVERIFY(animation->currentTime() == 125); + QCOMPARE(rect->x(), qreal(100)); } void tst_qdeclarativesmoothedanimation::valueSource() diff --git a/tests/auto/qtquick2/qdeclarativespringanimation/data/springanimation2.qml b/tests/auto/qtquick2/qdeclarativespringanimation/data/springanimation2.qml index 172cc57ca8..9f72e51533 100644 --- a/tests/auto/qtquick2/qdeclarativespringanimation/data/springanimation2.qml +++ b/tests/auto/qtquick2/qdeclarativespringanimation/data/springanimation2.qml @@ -1,9 +1,16 @@ import QtQuick 2.0 -SpringAnimation { - to: 1.44; velocity: 0.9 - spring: 1.0; damping: 0.5 - epsilon: 0.25; modulus: 360.0 - mass: 2.0; - running: true; +Item { + Item { + id: item + } + + SpringAnimation { + target: item; property: "x" + to: 1.44; velocity: 0.9 + spring: 1.0; damping: 0.5 + epsilon: 0.25; modulus: 360.0 + mass: 2.0; + running: true; + } } diff --git a/tests/auto/qtquick2/qdeclarativespringanimation/tst_qdeclarativespringanimation.cpp b/tests/auto/qtquick2/qdeclarativespringanimation/tst_qdeclarativespringanimation.cpp index 15a3263eed..64956d7753 100644 --- a/tests/auto/qtquick2/qdeclarativespringanimation/tst_qdeclarativespringanimation.cpp +++ b/tests/auto/qtquick2/qdeclarativespringanimation/tst_qdeclarativespringanimation.cpp @@ -88,7 +88,9 @@ void tst_qdeclarativespringanimation::values() { QDeclarativeEngine engine; QDeclarativeComponent c(&engine, testFileUrl("springanimation2.qml")); - QDeclarativeSpringAnimation *obj = qobject_cast<QDeclarativeSpringAnimation*>(c.create()); + QObject *root = c.create(); + + QDeclarativeSpringAnimation *obj = root->findChild<QDeclarativeSpringAnimation*>(); QVERIFY(obj != 0); |