From a52c11229a0c55071a43c9352b6c2e9e8ae481fa Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 25 Jan 2012 10:32:43 +1000 Subject: Add additional animation autotests. Change-Id: I11894325e73b8bb5b6ece4c626b15bd1d099f229 Reviewed-by: Yunqiao Yin --- .../qdeclarativeanimations/data/looping.qml | 16 ++ .../qdeclarativeanimations/data/reanchor.qml | 46 ++++++ .../qdeclarativeanimations/data/reparent.qml | 56 +++++++ .../tst_qdeclarativeanimations.cpp | 162 ++++++++++++++++++++- 4 files changed, 279 insertions(+), 1 deletion(-) create mode 100644 tests/auto/qtquick2/qdeclarativeanimations/data/looping.qml create mode 100644 tests/auto/qtquick2/qdeclarativeanimations/data/reanchor.qml create mode 100644 tests/auto/qtquick2/qdeclarativeanimations/data/reparent.qml (limited to 'tests/auto/qtquick2') diff --git a/tests/auto/qtquick2/qdeclarativeanimations/data/looping.qml b/tests/auto/qtquick2/qdeclarativeanimations/data/looping.qml new file mode 100644 index 0000000000..a3d40ae837 --- /dev/null +++ b/tests/auto/qtquick2/qdeclarativeanimations/data/looping.qml @@ -0,0 +1,16 @@ +import QtQuick 2.0 + +Item { + width: 200; height: 200 + + Rectangle { + x: 50; y: 50; width: 50; height: 50; color: "red" + + SequentialAnimation on rotation { + NumberAnimation { + from: 0; to: 90; duration: 100 + loops: 3 + } + } + } +} diff --git a/tests/auto/qtquick2/qdeclarativeanimations/data/reanchor.qml b/tests/auto/qtquick2/qdeclarativeanimations/data/reanchor.qml new file mode 100644 index 0000000000..241cc81a96 --- /dev/null +++ b/tests/auto/qtquick2/qdeclarativeanimations/data/reanchor.qml @@ -0,0 +1,46 @@ +import QtQuick 2.0 + +Rectangle { + id: container + width: 200; height: 200 + Rectangle { + id: myRect + color: "green"; + anchors.left: parent.left + anchors.right: rightGuideline.left + anchors.top: topGuideline.top + anchors.bottom: container.bottom + } + Item { id: leftGuideline; x: 10 } + Item { id: rightGuideline; x: 150 } + Item { id: topGuideline; y: 10 } + Item { id: bottomGuideline; y: 150 } + Item { id: topGuideline2; y: 50 } + Item { id: bottomGuideline2; y: 175 } + + states: [ State { + name: "reanchored" + AnchorChanges { + target: myRect; + anchors.left: leftGuideline.left + anchors.right: container.right + anchors.top: container.top + anchors.bottom: bottomGuideline.bottom + } + }, State { + name: "reanchored2" + AnchorChanges { + target: myRect; + anchors.left: undefined + anchors.right: undefined + anchors.top: topGuideline2.top + anchors.bottom: bottomGuideline2.bottom + } + }] + + transitions: Transition { + AnchorAnimation { } + } + + state: "reanchored" +} diff --git a/tests/auto/qtquick2/qdeclarativeanimations/data/reparent.qml b/tests/auto/qtquick2/qdeclarativeanimations/data/reparent.qml new file mode 100644 index 0000000000..39f1e7a6d2 --- /dev/null +++ b/tests/auto/qtquick2/qdeclarativeanimations/data/reparent.qml @@ -0,0 +1,56 @@ +import QtQuick 2.0 + +Rectangle { + width: 400; + height: 240; + color: "black"; + + Rectangle { + id: gr + objectName: "target" + color: "green" + width: 50; height: 50 + } + + Rectangle { + id: np + objectName: "newParent" + x: 150 + width: 150; height: 150 + color: "yellow" + clip: true + Rectangle { + color: "red" + x: 50; y: 50; height: 50; width: 50 + } + + } + + Rectangle { + id: vp + objectName: "viaParent" + x: 100; y: 100 + width: 50; height: 50 + color: "blue" + rotation: 45 + scale: 2 + } + + states: State { + name: "state1" + ParentChange { + target: gr + parent: np + x: 50; y: 50; width: 100; + } + } + + transitions: Transition { + reversible: true + to: "state1" + ParentAnimation { + target: gr; via: vp; + NumberAnimation { properties: "x,y,rotation,scale,width" } + } + } +} diff --git a/tests/auto/qtquick2/qdeclarativeanimations/tst_qdeclarativeanimations.cpp b/tests/auto/qtquick2/qdeclarativeanimations/tst_qdeclarativeanimations.cpp index 3151a99407..5ae66628b2 100644 --- a/tests/auto/qtquick2/qdeclarativeanimations/tst_qdeclarativeanimations.cpp +++ b/tests/auto/qtquick2/qdeclarativeanimations/tst_qdeclarativeanimations.cpp @@ -42,13 +42,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include #include #include @@ -74,6 +74,8 @@ private slots: void simpleColor(); void simpleRotation(); void simplePath(); + void simpleAnchor(); + void reparent(); void pathInterpolator(); void pathInterpolatorBackwardJump(); void pathWithNoStart(); @@ -102,6 +104,7 @@ private slots: void transitionAssignmentBug(); void pauseBindingBug(); void pauseBug(); + void loopingBug(); }; #define QTIMED_COMPARE(lhs, rhs) do { \ @@ -239,6 +242,9 @@ void tst_qdeclarativeanimations::simplePath() QQuickPathAnimation *pathAnim = rect->findChild(); QVERIFY(pathAnim); + QCOMPARE(pathAnim->duration(), 100); + QCOMPARE(pathAnim->target(), redRect); + pathAnim->start(); pathAnim->pause(); @@ -262,6 +268,8 @@ void tst_qdeclarativeanimations::simplePath() pathAnim->start(); QTRY_VERIFY(redRect->rotation() != 0); pathAnim->stop(); + + delete rect; } { @@ -276,6 +284,9 @@ void tst_qdeclarativeanimations::simplePath() QVERIFY(pathAnim); QCOMPARE(pathAnim->orientation(), QQuickPathAnimation::RightFirst); + QCOMPARE(pathAnim->endRotation(), qreal(0)); + QCOMPARE(pathAnim->orientationEntryDuration(), 10); + QCOMPARE(pathAnim->orientationExitDuration(), 10); pathAnim->start(); pathAnim->pause(); @@ -292,9 +303,136 @@ void tst_qdeclarativeanimations::simplePath() QCOMPARE(redRect->x(), qreal(300)); QCOMPARE(redRect->y(), qreal(300)); QCOMPARE(redRect->rotation(), qreal(0)); + + delete rect; } } +void tst_qdeclarativeanimations::simpleAnchor() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, testFileUrl("reanchor.qml")); + QQuickRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + QQuickRectangle *greenRect = rect->findChild(); + QVERIFY(greenRect); + + QCOMPARE(rect->state(), QLatin1String("reanchored")); + QCOMPARE(greenRect->x(), qreal(10)); + QCOMPARE(greenRect->y(), qreal(0)); + QCOMPARE(greenRect->width(), qreal(190)); + QCOMPARE(greenRect->height(), qreal(150)); + + rect->setState(""); + + //verify animation in progress + QTRY_VERIFY(greenRect->x() < 10 && greenRect->x() > 0); + QVERIFY(greenRect->y() > 0 && greenRect->y() < 10); + QVERIFY(greenRect->width() < 190 && greenRect->width() > 150); + QVERIFY(greenRect->height() > 150 && greenRect->height() < 190); + + //verify end state ("") + QTRY_COMPARE(greenRect->x(), qreal(0)); + QCOMPARE(greenRect->y(), qreal(10)); + QCOMPARE(greenRect->width(), qreal(150)); + QCOMPARE(greenRect->height(), qreal(190)); + + rect->setState("reanchored2"); + + //verify animation in progress + QTRY_VERIFY(greenRect->y() > 10 && greenRect->y() < 50); + QVERIFY(greenRect->height() > 125 && greenRect->height() < 190); + //NOTE: setting left/right anchors to undefined removes the anchors, but does not resize. + QCOMPARE(greenRect->x(), qreal(0)); + QCOMPARE(greenRect->width(), qreal(150)); + + //verify end state ("reanchored2") + QTRY_COMPARE(greenRect->y(), qreal(50)); + QCOMPARE(greenRect->height(), qreal(125)); + QCOMPARE(greenRect->x(), qreal(0)); + QCOMPARE(greenRect->width(), qreal(150)); + + rect->setState("reanchored"); + + //verify animation in progress + QTRY_VERIFY(greenRect->x() < 10 && greenRect->x() > 0); + QVERIFY(greenRect->y() > 0 && greenRect->y() < 50); + QVERIFY(greenRect->width() < 190 && greenRect->width() > 150); + QVERIFY(greenRect->height() > 125 && greenRect->height() < 150); + + //verify end state ("reanchored") + QTRY_COMPARE(greenRect->x(), qreal(10)); + QCOMPARE(greenRect->y(), qreal(0)); + QCOMPARE(greenRect->width(), qreal(190)); + QCOMPARE(greenRect->height(), qreal(150)); + + rect->setState("reanchored2"); + + //verify animation in progress + QTRY_VERIFY(greenRect->x() < 10 && greenRect->x() > 0); + QVERIFY(greenRect->y() > 0 && greenRect->y() < 50); + QVERIFY(greenRect->width() < 190 && greenRect->width() > 150); + QVERIFY(greenRect->height() > 125 && greenRect->height() < 150); + + //verify end state ("reanchored2") + QTRY_COMPARE(greenRect->x(), qreal(0)); + QCOMPARE(greenRect->y(), qreal(50)); + QCOMPARE(greenRect->width(), qreal(150)); + QCOMPARE(greenRect->height(), qreal(125)); + + delete rect; +} + +void tst_qdeclarativeanimations::reparent() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, testFileUrl("reparent.qml")); + QQuickRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + QQuickRectangle *target = rect->findChild("target"); + QVERIFY(target); + + QCOMPARE(target->parentItem(), rect); + QCOMPARE(target->x(), qreal(0)); + QCOMPARE(target->y(), qreal(0)); + QCOMPARE(target->width(), qreal(50)); + QCOMPARE(target->height(), qreal(50)); + QCOMPARE(target->rotation(), qreal(0)); + QCOMPARE(target->scale(), qreal(1)); + + rect->setState("state1"); + + QQuickRectangle *viaParent = rect->findChild("viaParent"); + QVERIFY(viaParent); + + QQuickRectangle *newParent = rect->findChild("newParent"); + QVERIFY(newParent); + + QTest::qWait(100); + + //animation in progress + QTRY_COMPARE(target->parentItem(), viaParent); + QVERIFY(target->x() > -100 && target->x() < 50); + QVERIFY(target->y() > -100 && target->y() < 50); + QVERIFY(target->width() > 50 && target->width() < 100); + QCOMPARE(target->height(), qreal(50)); + QCOMPARE(target->rotation(), qreal(-45)); + QCOMPARE(target->scale(), qreal(.5)); + + //end state + QTRY_COMPARE(target->parentItem(), newParent); + QCOMPARE(target->x(), qreal(50)); + QCOMPARE(target->y(), qreal(50)); + QCOMPARE(target->width(), qreal(100)); + QCOMPARE(target->height(), qreal(50)); + QCOMPARE(target->rotation(), qreal(0)); + QCOMPARE(target->scale(), qreal(1)); + + delete rect; +} + void tst_qdeclarativeanimations::pathInterpolator() { QDeclarativeEngine engine; @@ -1154,6 +1292,28 @@ void tst_qdeclarativeanimations::pauseBug() delete anim; } +//QTBUG-23092 +void tst_qdeclarativeanimations::loopingBug() +{ + QDeclarativeEngine engine; + + QDeclarativeComponent c(&engine, testFileUrl("looping.qml")); + QObject *obj = c.create(); + + QDeclarativeAbstractAnimation *anim = obj->findChild(); + QVERIFY(anim != 0); + QCOMPARE(anim->qtAnimation()->totalDuration(), 300); + QCOMPARE(anim->isRunning(), true); + QTRY_COMPARE(static_cast(anim->qtAnimation())->firstChild()->currentLoop(), 2); + QTRY_COMPARE(anim->isRunning(), false); + + QQuickRectangle *rect = obj->findChild(); + QVERIFY(rect != 0); + QCOMPARE(rect->rotation(), qreal(90)); + + delete obj; +} + QTEST_MAIN(tst_qdeclarativeanimations) #include "tst_qdeclarativeanimations.moc" -- cgit v1.2.3