aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2012-01-25 10:32:43 +1000
committerMichael Brasser <michael.brasser@nokia.com>2012-01-25 01:55:37 +0100
commit35794301d188b731a7b596d92fc632fff58586c0 (patch)
tree88673e90eaf9f42a2148dbea8d906c87c9a9e9c3
parent4c97a8091eff18cdff92d4fc5243a88bf57146d3 (diff)
Add and fix animation autotests.
Change-Id: I11894325e73b8bb5b6ece4c626b15bd1d099f229 Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
-rw-r--r--tests/auto/qtquick2/qdeclarativeanimations/data/looping.qml16
-rw-r--r--tests/auto/qtquick2/qdeclarativeanimations/data/pathAnimation2.qml4
-rw-r--r--tests/auto/qtquick2/qdeclarativeanimations/data/reanchor.qml46
-rw-r--r--tests/auto/qtquick2/qdeclarativeanimations/data/reparent.qml56
-rw-r--r--tests/auto/qtquick2/qdeclarativeanimations/tst_qdeclarativeanimations.cpp162
5 files changed, 281 insertions, 3 deletions
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/pathAnimation2.qml b/tests/auto/qtquick2/qdeclarativeanimations/data/pathAnimation2.qml
index 951c5b2e57..2f64dac2cc 100644
--- a/tests/auto/qtquick2/qdeclarativeanimations/data/pathAnimation2.qml
+++ b/tests/auto/qtquick2/qdeclarativeanimations/data/pathAnimation2.qml
@@ -15,8 +15,8 @@ Rectangle {
target: redRect
duration: 100;
endRotation: 0
- orientationEntryInterval: .1
- orientationExitInterval: .1
+ orientationEntryDuration: 10
+ orientationExitDuration: 10
orientation: PathAnimation.RightFirst
path: Path {
startX: 50; startY: 50
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 9491083cd4..683f1c7603 100644
--- a/tests/auto/qtquick2/qdeclarativeanimations/tst_qdeclarativeanimations.cpp
+++ b/tests/auto/qtquick2/qdeclarativeanimations/tst_qdeclarativeanimations.cpp
@@ -42,13 +42,13 @@
#include <QtDeclarative/qdeclarativeengine.h>
#include <QtDeclarative/qdeclarativecomponent.h>
#include <QtQuick/qquickview.h>
+#include <QtDeclarative/private/qanimationgroupjob_p.h>
#include <QtQuick/private/qquickrectangle_p.h>
#include <QtQuick/private/qdeclarativeanimation_p.h>
#include <QtQuick/private/qdeclarativetransition_p.h>
#include <QtQuick/private/qquickanimation_p.h>
#include <QtQuick/private/qdeclarativepathinterpolator_p.h>
#include <QtQuick/private/qquickitem_p.h>
-#include <QVariantAnimation>
#include <QEasingCurve>
#include <limits.h>
@@ -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<QQuickPathAnimation*>();
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<QQuickRectangle*>(c.create());
+ QVERIFY(rect);
+
+ QQuickRectangle *greenRect = rect->findChild<QQuickRectangle*>();
+ 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<QQuickRectangle*>(c.create());
+ QVERIFY(rect);
+
+ QQuickRectangle *target = rect->findChild<QQuickRectangle*>("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<QQuickRectangle*>("viaParent");
+ QVERIFY(viaParent);
+
+ QQuickRectangle *newParent = rect->findChild<QQuickRectangle*>("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<QDeclarativeAbstractAnimation*>();
+ QVERIFY(anim != 0);
+ QCOMPARE(anim->qtAnimation()->totalDuration(), 300);
+ QCOMPARE(anim->isRunning(), true);
+ QTRY_COMPARE(static_cast<QAnimationGroupJob*>(anim->qtAnimation())->firstChild()->currentLoop(), 2);
+ QTRY_COMPARE(anim->isRunning(), false);
+
+ QQuickRectangle *rect = obj->findChild<QQuickRectangle*>();
+ QVERIFY(rect != 0);
+ QCOMPARE(rect->rotation(), qreal(90));
+
+ delete obj;
+}
+
QTEST_MAIN(tst_qdeclarativeanimations)
#include "tst_qdeclarativeanimations.moc"