aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickbehaviors
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@jollamobile.com>2014-02-10 10:16:08 -0600
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-20 04:27:24 +0100
commitbd510dfa02f33fa497894fe8aa4236f7d8705482 (patch)
tree2a07b5c25506daa889de8d52d921ec34b4b7ffd5 /tests/auto/quick/qquickbehaviors
parent7da483bfbefcaabb1dbbf3e2f1d5b5f7aadc3b06 (diff)
Ensure Behavior stops animating when a new value is set while disabled.
Otherwise the Behavior could cause the property value to end up in an unwanted and inconsistent state. For example, in the following case: x: myXValue Behavior on x { NumberAnimation {} } x could end up *not equal* to myXValue if myXValue was changed while the Behavior was still animating but currently disabled. Change-Id: I3826fdc3f48b2722e778638b116546db7e831e87 Reviewed-by: Martin Jones <martin.jones@jollamobile.com>
Diffstat (limited to 'tests/auto/quick/qquickbehaviors')
-rw-r--r--tests/auto/quick/qquickbehaviors/data/disabledWriteWhileRunning.qml14
-rw-r--r--tests/auto/quick/qquickbehaviors/data/disabledWriteWhileRunning2.qml14
-rw-r--r--tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp87
3 files changed, 115 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickbehaviors/data/disabledWriteWhileRunning.qml b/tests/auto/quick/qquickbehaviors/data/disabledWriteWhileRunning.qml
new file mode 100644
index 0000000000..1ec3a923d4
--- /dev/null
+++ b/tests/auto/quick/qquickbehaviors/data/disabledWriteWhileRunning.qml
@@ -0,0 +1,14 @@
+import QtQuick 2.0
+Rectangle {
+ width: 400
+ height: 400
+ Rectangle {
+ id: rect
+ objectName: "MyRect"
+ width: 100; height: 100; color: "green"
+ Behavior on x {
+ objectName: "MyBehavior"
+ NumberAnimation { id: myAnimation; objectName: "MyAnimation"; duration: 1000; }
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickbehaviors/data/disabledWriteWhileRunning2.qml b/tests/auto/quick/qquickbehaviors/data/disabledWriteWhileRunning2.qml
new file mode 100644
index 0000000000..fcd9c06de9
--- /dev/null
+++ b/tests/auto/quick/qquickbehaviors/data/disabledWriteWhileRunning2.qml
@@ -0,0 +1,14 @@
+import QtQuick 2.0
+Rectangle {
+ width: 400
+ height: 400
+ Rectangle {
+ id: rect
+ objectName: "MyRect"
+ width: 100; height: 100; color: "green"
+ Behavior on x {
+ objectName: "MyBehavior"
+ SmoothedAnimation { id: myAnimation; objectName: "MyAnimation"; duration: 1000; velocity: -1 }
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp
index 5deda2d96b..cabc029b82 100644
--- a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp
+++ b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp
@@ -47,6 +47,7 @@
#include <QtQuick/private/qquicktext_p.h>
#include <QtQuick/private/qquickbehavior_p.h>
#include <QtQuick/private/qquickanimation_p.h>
+#include <QtQuick/private/qquicksmoothedanimation_p.h>
#include <private/qquickitem_p.h>
#include "../../shared/util.h"
@@ -82,6 +83,7 @@ private slots:
void startOnCompleted();
void multipleChangesToValueType();
void currentValue();
+ void disabledWriteWhileRunning();
};
void tst_qquickbehaviors::simpleBehavior()
@@ -549,6 +551,91 @@ void tst_qquickbehaviors::currentValue()
}
}
+void tst_qquickbehaviors::disabledWriteWhileRunning()
+{
+ {
+ QQmlEngine engine;
+ QQmlComponent c(&engine, testFileUrl("disabledWriteWhileRunning.qml"));
+ QQuickItem *root = qobject_cast<QQuickItem*>(c.create());
+ QVERIFY(root);
+
+ QQuickRectangle *myRect = qobject_cast<QQuickRectangle*>(root->findChild<QQuickRectangle*>("MyRect"));
+ QQuickBehavior *myBehavior = qobject_cast<QQuickBehavior*>(root->findChild<QQuickBehavior*>("MyBehavior"));
+ QQuickNumberAnimation *myAnimation = qobject_cast<QQuickNumberAnimation*>(root->findChild<QQuickNumberAnimation*>("MyAnimation"));
+ QVERIFY(myRect);
+ QVERIFY(myBehavior);
+ QVERIFY(myAnimation);
+
+ // initial values
+ QCOMPARE(myBehavior->enabled(), true);
+ QCOMPARE(myAnimation->isRunning(), false);
+ QCOMPARE(myRect->x(), qreal(0));
+
+ // start animation
+ myRect->setProperty("x", 200);
+ QCOMPARE(myAnimation->isRunning(), true);
+ QTRY_VERIFY(myRect->x() != qreal(0) && myRect->x() != qreal(200));
+
+ // set disabled while animation is in progress
+ myBehavior->setProperty("enabled", false);
+ QCOMPARE(myAnimation->isRunning(), true);
+
+ // force new value while disabled and previous animation is in progress.
+ // animation should be stopped and value stay at forced value
+ myRect->setProperty("x", 100);
+ QCOMPARE(myAnimation->isRunning(), false);
+ QCOMPARE(myRect->x(), qreal(100));
+ QTest::qWait(200);
+ QCOMPARE(myRect->x(), qreal(100));
+
+ delete root;
+ }
+
+ //test additional complications with SmoothedAnimation
+ {
+ QQmlEngine engine;
+ QQmlComponent c(&engine, testFileUrl("disabledWriteWhileRunning2.qml"));
+ QQuickItem *root = qobject_cast<QQuickItem*>(c.create());
+ QVERIFY(root);
+
+ QQuickRectangle *myRect = qobject_cast<QQuickRectangle*>(root->findChild<QQuickRectangle*>("MyRect"));
+ QQuickBehavior *myBehavior = qobject_cast<QQuickBehavior*>(root->findChild<QQuickBehavior*>("MyBehavior"));
+ QQuickSmoothedAnimation *myAnimation = qobject_cast<QQuickSmoothedAnimation*>(root->findChild<QQuickNumberAnimation*>("MyAnimation"));
+ QVERIFY(myRect);
+ QVERIFY(myBehavior);
+ QVERIFY(myAnimation);
+
+ // initial values
+ QCOMPARE(myBehavior->enabled(), true);
+ QCOMPARE(myAnimation->isRunning(), false);
+ QCOMPARE(myRect->x(), qreal(0));
+
+ // start animation
+ myRect->setProperty("x", 200);
+ QCOMPARE(myAnimation->isRunning(), true);
+ QTRY_VERIFY(myRect->x() != qreal(0) && myRect->x() != qreal(200));
+
+ //set second value
+ myRect->setProperty("x", 300);
+ QCOMPARE(myAnimation->isRunning(), true);
+ QTRY_VERIFY(myRect->x() != qreal(0) && myRect->x() != qreal(200));
+
+ // set disabled while animation is in progress
+ myBehavior->setProperty("enabled", false);
+ QCOMPARE(myAnimation->isRunning(), true);
+
+ // force new value while disabled and previous animation is in progress.
+ // animation should be stopped and value stay at forced value
+ myRect->setProperty("x", 100);
+ QCOMPARE(myAnimation->isRunning(), false);
+ QCOMPARE(myRect->x(), qreal(100));
+ QTest::qWait(200);
+ QCOMPARE(myRect->x(), qreal(100));
+
+ delete root;
+ }
+}
+
QTEST_MAIN(tst_qquickbehaviors)
#include "tst_qquickbehaviors.moc"