aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2019-05-28 17:59:34 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2019-05-28 17:59:40 +0200
commit1f3c157ec6b8be5de1eb89295713c2980fb1a7aa (patch)
treeb85888d73518f6abc7bbde74ab71a27887682f9d /tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp
parent44ca7e31ee9365a72cd17ecd335ec4d0161420a9 (diff)
parent0f5c34f2c6b64bae3429706a6c4211334c689092 (diff)
Merge "Merge remote-tracking branch 'origin/dev' into wip/scenegraphng"wip/scenegraphng
Diffstat (limited to 'tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp')
-rw-r--r--tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp b/tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp
index 34cf21024d..717fd5dbd1 100644
--- a/tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp
+++ b/tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp
@@ -42,6 +42,9 @@ private slots:
void binding();
void whenAfterValue();
void restoreBinding();
+ void restoreBindingValue();
+ void restoreBindingVarValue();
+ void restoreBindingJSValue();
void restoreBindingWithLoop();
void restoreBindingWithoutCrash();
void deletedObject();
@@ -134,6 +137,78 @@ void tst_qqmlbinding::restoreBinding()
delete rect;
}
+void tst_qqmlbinding::restoreBindingValue()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, testFileUrl("restoreBinding2.qml"));
+ QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));
+ QVERIFY(!rect.isNull());
+
+ auto myItem = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("myItem"));
+ QVERIFY(myItem != nullptr);
+
+ QCOMPARE(myItem->height(), 100);
+ myItem->setProperty("when", QVariant(false));
+ QCOMPARE(myItem->height(), 300); // make sure the original value was restored
+
+ myItem->setProperty("when", QVariant(true));
+ QCOMPARE(myItem->height(), 100); // make sure the value specified in Binding is set
+ rect->setProperty("boundValue", 200);
+ QCOMPARE(myItem->height(), 200); // make sure the changed binding value is set
+ myItem->setProperty("when", QVariant(false));
+ // make sure that the original value is back, not e.g. the value from before the
+ // change (i.e. 100)
+ QCOMPARE(myItem->height(), 300);
+}
+
+void tst_qqmlbinding::restoreBindingVarValue()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, testFileUrl("restoreBinding3.qml"));
+ QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));
+ QVERIFY(!rect.isNull());
+
+ auto myItem = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("myItem"));
+ QVERIFY(myItem != nullptr);
+
+ QCOMPARE(myItem->property("foo"), 13);
+ myItem->setProperty("when", QVariant(false));
+ QCOMPARE(myItem->property("foo"), 42); // make sure the original value was restored
+
+ myItem->setProperty("when", QVariant(true));
+ QCOMPARE(myItem->property("foo"), 13); // make sure the value specified in Binding is set
+ rect->setProperty("boundValue", 31337);
+ QCOMPARE(myItem->property("foo"), 31337); // make sure the changed binding value is set
+ myItem->setProperty("when", QVariant(false));
+ // make sure that the original value is back, not e.g. the value from before the
+ // change (i.e. 100)
+ QCOMPARE(myItem->property("foo"), 42);
+}
+
+void tst_qqmlbinding::restoreBindingJSValue()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, testFileUrl("restoreBinding4.qml"));
+ QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));
+ QVERIFY(!rect.isNull());
+
+ auto myItem = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("myItem"));
+ QVERIFY(myItem != nullptr);
+
+ QCOMPARE(myItem->property("fooCheck"), false);
+ myItem->setProperty("when", QVariant(false));
+ QCOMPARE(myItem->property("fooCheck"), true); // make sure the original value was restored
+
+ myItem->setProperty("when", QVariant(true));
+ QCOMPARE(myItem->property("fooCheck"), false); // make sure the value specified in Binding is set
+ rect->setProperty("boundValue", 31337);
+ QCOMPARE(myItem->property("fooCheck"), false); // make sure the changed binding value is set
+ myItem->setProperty("when", QVariant(false));
+ // make sure that the original value is back, not e.g. the value from before the change
+ QCOMPARE(myItem->property("fooCheck"), true);
+
+}
+
void tst_qqmlbinding::restoreBindingWithLoop()
{
QQmlEngine engine;