From 0cf756891d94bcfef52c7c18ce4e3e3f7e64e2d7 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 3 Nov 2009 16:10:53 +1000 Subject: Add more Behavior autotests. --- tests/auto/declarative/behaviors/data/simple.qml | 5 ++- tests/auto/declarative/behaviors/tst_behaviors.cpp | 43 ++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/tests/auto/declarative/behaviors/data/simple.qml b/tests/auto/declarative/behaviors/data/simple.qml index a715f7b..37c3915 100644 --- a/tests/auto/declarative/behaviors/data/simple.qml +++ b/tests/auto/declarative/behaviors/data/simple.qml @@ -6,7 +6,10 @@ Rectangle { id: rect objectName: "MyRect" width: 100; height: 100; color: "green" - x: Behavior { NumberAnimation { duration: 200; } } + x: Behavior { + objectName: "MyBehavior"; + NumberAnimation { duration: 200; } + } } MouseRegion { id: clicker diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp index 9803a9d..7bdc82e 100644 --- a/tests/auto/declarative/behaviors/tst_behaviors.cpp +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include class tst_behaviors : public QObject @@ -60,6 +61,9 @@ private slots: void replaceBinding(); //void transitionOverrides(); void group(); + void emptyBehavior(); + void nonSelectingBehavior(); + void reassignedAnimation(); }; void tst_behaviors::simpleBehavior() @@ -68,6 +72,7 @@ void tst_behaviors::simpleBehavior() QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/simple.qml")); QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); + QVERIFY(qobject_cast(rect->findChild("MyBehavior"))->animation()); rect->setState("moved"); QTest::qWait(100); @@ -189,6 +194,44 @@ void tst_behaviors::group() } } +void tst_behaviors::emptyBehavior() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/empty.qml")); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //should change immediately +} + +void tst_behaviors::nonSelectingBehavior() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/nonSelecting.qml")); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //should change immediately +} + +void tst_behaviors::reassignedAnimation() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/reassignedAnimation.qml")); + QTest::ignoreMessage(QtWarningMsg, "QML QmlBehavior (file://" SRCDIR "/data/reassignedAnimation.qml:9:12) Can't change the animation assigned to a Behavior."); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + QTest::qWait(200 + 100); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + QVERIFY(x > 0 && x < 200); //i.e. the right behavior has been triggered +} + QTEST_MAIN(tst_behaviors) #include "tst_behaviors.moc" -- cgit v0.12