aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickbehaviors
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/quick/qquickbehaviors')
-rw-r--r--tests/auto/quick/qquickbehaviors/data/ItemWithInnerBehavior.qml1
-rw-r--r--tests/auto/quick/qquickbehaviors/data/aliased.qml1
-rw-r--r--tests/auto/quick/qquickbehaviors/data/oneway.qml20
-rw-r--r--tests/auto/quick/qquickbehaviors/qquickbehaviors.pro2
-rw-r--r--tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp49
5 files changed, 72 insertions, 1 deletions
diff --git a/tests/auto/quick/qquickbehaviors/data/ItemWithInnerBehavior.qml b/tests/auto/quick/qquickbehaviors/data/ItemWithInnerBehavior.qml
index 09983645ef..0ac7f87c42 100644
--- a/tests/auto/quick/qquickbehaviors/data/ItemWithInnerBehavior.qml
+++ b/tests/auto/quick/qquickbehaviors/data/ItemWithInnerBehavior.qml
@@ -5,6 +5,7 @@ Item {
property bool someValue
Behavior on someValue {
+ objectName: "behavior"
ScriptAction { script: { parent.behaviorTriggered = true }}
}
}
diff --git a/tests/auto/quick/qquickbehaviors/data/aliased.qml b/tests/auto/quick/qquickbehaviors/data/aliased.qml
index e65e035d83..1840cdd22e 100644
--- a/tests/auto/quick/qquickbehaviors/data/aliased.qml
+++ b/tests/auto/quick/qquickbehaviors/data/aliased.qml
@@ -17,6 +17,7 @@ Rectangle {
anchors.fill: parent
value: accelerating ? 400 : 0
Behavior on value {
+ objectName: "behavior"
NumberAnimation {
duration: 500
}
diff --git a/tests/auto/quick/qquickbehaviors/data/oneway.qml b/tests/auto/quick/qquickbehaviors/data/oneway.qml
new file mode 100644
index 0000000000..0b438b80f6
--- /dev/null
+++ b/tests/auto/quick/qquickbehaviors/data/oneway.qml
@@ -0,0 +1,20 @@
+import QtQuick 2.0
+Rectangle {
+ width: 400
+ height: 400
+ Rectangle {
+ id: rect
+ objectName: "MyRectOneWay"
+ width: 100; height: 100; color: "green"
+ Behavior on x {
+ id: behavior
+ objectName: "MyBehaviorOneWay";
+ enabled: (behavior.targetValue === 0)
+ NumberAnimation {
+ id: ani
+ objectName: "MyAnimationOneWay";
+ duration: 200;
+ }
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickbehaviors/qquickbehaviors.pro b/tests/auto/quick/qquickbehaviors/qquickbehaviors.pro
index 51bc42c390..fd64eb1d40 100644
--- a/tests/auto/quick/qquickbehaviors/qquickbehaviors.pro
+++ b/tests/auto/quick/qquickbehaviors/qquickbehaviors.pro
@@ -7,5 +7,5 @@ include (../../shared/util.pri)
macx:CONFIG -= app_bundle
TESTDATA = data/*
-
+DISTFILES = $$files(data/*)
QT += core-private gui-private qml-private quick-private testlib
diff --git a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp
index fa9eba095d..6367f327da 100644
--- a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp
+++ b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp
@@ -73,6 +73,7 @@ private slots:
void disabledWriteWhileRunning();
void aliasedProperty();
void innerBehaviorOverwritten();
+ void oneWay();
};
void tst_qquickbehaviors::simpleBehavior()
@@ -516,6 +517,7 @@ void tst_qquickbehaviors::disabledWriteWhileRunning()
myRect->setProperty("x", 200);
QCOMPARE(myAnimation->isRunning(), true);
QTRY_VERIFY(myRect->x() != qreal(0) && myRect->x() != qreal(200));
+ QCOMPARE(myBehavior->targetValue(), 200); // grabbed before starting the animation
// set disabled while animation is in progress
myBehavior->setProperty("enabled", false);
@@ -526,6 +528,7 @@ void tst_qquickbehaviors::disabledWriteWhileRunning()
myRect->setProperty("x", 100);
QCOMPARE(myAnimation->isRunning(), false);
QCOMPARE(myRect->x(), qreal(100));
+ QCOMPARE(myBehavior->targetValue(), 100);
QTest::qWait(200);
QCOMPARE(myRect->x(), qreal(100));
}
@@ -546,17 +549,20 @@ void tst_qquickbehaviors::disabledWriteWhileRunning()
// initial values
QCOMPARE(myBehavior->enabled(), true);
+ QCOMPARE(myBehavior->targetValue(), QVariant());
QCOMPARE(myAnimation->isRunning(), false);
QCOMPARE(myRect->x(), qreal(0));
// start animation
myRect->setProperty("x", 200);
QCOMPARE(myAnimation->isRunning(), true);
+ QCOMPARE(myBehavior->targetValue(), 200);
QTRY_VERIFY(myRect->x() != qreal(0) && myRect->x() != qreal(200));
//set second value
myRect->setProperty("x", 300);
QCOMPARE(myAnimation->isRunning(), true);
+ QCOMPARE(myBehavior->targetValue(), 300);
QTRY_VERIFY(myRect->x() != qreal(0) && myRect->x() != qreal(200));
// set disabled while animation is in progress
@@ -568,6 +574,7 @@ void tst_qquickbehaviors::disabledWriteWhileRunning()
myRect->setProperty("x", 100);
QCOMPARE(myAnimation->isRunning(), false);
QCOMPARE(myRect->x(), qreal(100));
+ QCOMPARE(myBehavior->targetValue(), 100);
QTest::qWait(200);
QCOMPARE(myRect->x(), qreal(100));
}
@@ -580,7 +587,12 @@ void tst_qquickbehaviors::aliasedProperty()
QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));
QVERIFY2(!rect.isNull(), qPrintable(c.errorString()));
+ QQuickBehavior* behavior =
+ qobject_cast<QQuickBehavior*>(rect->findChild<QQuickBehavior*>("behavior"));
+ QSignalSpy targetValueSpy(behavior, SIGNAL(targetValueChanged()));
QQuickItemPrivate::get(rect.data())->setState("moved");
+ QCOMPARE(behavior->targetValue(), 400);
+ QCOMPARE(targetValueSpy.count(), 1);
QScopedPointer<QQuickRectangle> acc(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("acc")));
QScopedPointer<QQuickRectangle> range(qobject_cast<QQuickRectangle*>(acc->findChild<QQuickRectangle*>("range")));
QTRY_VERIFY(acc->property("value").toDouble() > 0);
@@ -595,7 +607,44 @@ void tst_qquickbehaviors::innerBehaviorOverwritten()
QQmlEngine engine;
QQmlComponent c(&engine, testFileUrl("overwrittenbehavior.qml"));
QScopedPointer<QQuickItem> item(qobject_cast<QQuickItem*>(c.create()));
+ QQuickBehavior* behavior =
+ qobject_cast<QQuickBehavior*>(item->findChild<QQuickBehavior*>("behavior"));
QVERIFY(item->property("behaviorTriggered").toBool());
+ QCOMPARE(behavior->targetValue(), true);
+}
+
+void tst_qquickbehaviors::oneWay()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, testFileUrl("oneway.qml"));
+ QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));;
+ QVERIFY2(!rect.isNull(), qPrintable(c.errorString()));
+ QQuickBehavior* behavior =
+ qobject_cast<QQuickBehavior*>(rect->findChild<QQuickBehavior*>("MyBehaviorOneWay"));
+ QCOMPARE(behavior->enabled(), false);
+ QCOMPARE(behavior->targetValue(), QVariant());
+
+ QSignalSpy targetValueSpy(behavior, SIGNAL(targetValueChanged()));
+ QQuickRectangle *myRect = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRectOneWay"));
+ myRect->setProperty("x", 100);
+ QCOMPARE(behavior->targetValue(), 100);
+ QCOMPARE(targetValueSpy.count(), 1);
+ QCOMPARE(behavior->enabled(), false);
+ qreal x = myRect->x();
+ QCOMPARE(x, qreal(100)); //should change immediately
+ QQuickNumberAnimation *myAnimation =
+ qobject_cast<QQuickNumberAnimation*>(behavior->findChild<QQuickNumberAnimation*>("MyAnimationOneWay"));
+ QCOMPARE(myAnimation->isRunning(), false);
+
+ myRect->setProperty("x", 0);
+ QCOMPARE(behavior->targetValue(), 0);
+ QCOMPARE(targetValueSpy.count(), 2);
+ QCOMPARE(behavior->enabled(), true);
+ QCOMPARE(myAnimation->isRunning(), true);
+ QVERIFY(myRect->x() > 0.0);
+ QTRY_VERIFY(myRect->x() < 100.0);
+ QTRY_COMPARE(myRect->x(), qreal(0));
+ QCOMPARE(myAnimation->isRunning(), false);
}
QTEST_MAIN(tst_qquickbehaviors)