summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativeproperty
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-11-29 08:41:24 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-11-29 08:41:24 (GMT)
commit312604c85b1e6a6fc6de505bac86848936f81edd (patch)
tree40708cd6a968a54dcdbbbf7d0e98007f6cae1ab5 /tests/auto/declarative/qdeclarativeproperty
parentb604dc0b77a3a4b9001d682925006a3438e00cb7 (diff)
downloadQt-312604c85b1e6a6fc6de505bac86848936f81edd.zip
Qt-312604c85b1e6a6fc6de505bac86848936f81edd.tar.gz
Qt-312604c85b1e6a6fc6de505bac86848936f81edd.tar.bz2
Improve consistency in handling of aliases, bindings and value types
Task-number: QTBUG-13719
Diffstat (limited to 'tests/auto/declarative/qdeclarativeproperty')
-rw-r--r--tests/auto/declarative/qdeclarativeproperty/data/aliasPropertyBindings.qml19
-rw-r--r--tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp69
2 files changed, 88 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeproperty/data/aliasPropertyBindings.qml b/tests/auto/declarative/qdeclarativeproperty/data/aliasPropertyBindings.qml
new file mode 100644
index 0000000..a253a58
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeproperty/data/aliasPropertyBindings.qml
@@ -0,0 +1,19 @@
+import QtQuick 1.0
+
+Item {
+ id: root
+
+ property real test: 9
+ property real test2: 3
+
+ property real realProperty: test * test + test
+ property alias aliasProperty: root.realProperty
+
+ states: State {
+ name: "switch"
+ PropertyChanges {
+ target: root
+ aliasProperty: 32 * test2
+ }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp b/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp
index 0ca0e03..3cc71bb 100644
--- a/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp
+++ b/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp
@@ -132,6 +132,7 @@ private slots:
// Bugs
void crashOnValueProperty();
+ void aliasPropertyBindings();
void copy();
private:
@@ -1308,6 +1309,74 @@ void tst_qdeclarativeproperty::crashOnValueProperty()
QCOMPARE(p.read(), QVariant(20));
}
+// QTBUG-13719
+void tst_qdeclarativeproperty::aliasPropertyBindings()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("aliasPropertyBindings.qml"));
+
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->property("realProperty").toReal(), 90.);
+ QCOMPARE(object->property("aliasProperty").toReal(), 90.);
+
+ object->setProperty("test", 10);
+
+ QCOMPARE(object->property("realProperty").toReal(), 110.);
+ QCOMPARE(object->property("aliasProperty").toReal(), 110.);
+
+ QDeclarativeProperty realProperty(object, QLatin1String("realProperty"));
+ QDeclarativeProperty aliasProperty(object, QLatin1String("aliasProperty"));
+
+ // Check there is a binding on these two properties
+ QVERIFY(QDeclarativePropertyPrivate::binding(realProperty) != 0);
+ QVERIFY(QDeclarativePropertyPrivate::binding(aliasProperty) != 0);
+
+ // Check that its the same binding on these two properties
+ QCOMPARE(QDeclarativePropertyPrivate::binding(realProperty),
+ QDeclarativePropertyPrivate::binding(aliasProperty));
+
+ // Change the binding
+ object->setProperty("state", QString("switch"));
+
+ QVERIFY(QDeclarativePropertyPrivate::binding(realProperty) != 0);
+ QVERIFY(QDeclarativePropertyPrivate::binding(aliasProperty) != 0);
+ QCOMPARE(QDeclarativePropertyPrivate::binding(realProperty),
+ QDeclarativePropertyPrivate::binding(aliasProperty));
+
+ QCOMPARE(object->property("realProperty").toReal(), 96.);
+ QCOMPARE(object->property("aliasProperty").toReal(), 96.);
+
+ // Check the old binding really has not effect any more
+ object->setProperty("test", 4);
+
+ QCOMPARE(object->property("realProperty").toReal(), 96.);
+ QCOMPARE(object->property("aliasProperty").toReal(), 96.);
+
+ object->setProperty("test2", 9);
+
+ QCOMPARE(object->property("realProperty").toReal(), 288.);
+ QCOMPARE(object->property("aliasProperty").toReal(), 288.);
+
+ // Revert
+ object->setProperty("state", QString(""));
+
+ QVERIFY(QDeclarativePropertyPrivate::binding(realProperty) != 0);
+ QVERIFY(QDeclarativePropertyPrivate::binding(aliasProperty) != 0);
+ QCOMPARE(QDeclarativePropertyPrivate::binding(realProperty),
+ QDeclarativePropertyPrivate::binding(aliasProperty));
+
+ QCOMPARE(object->property("realProperty").toReal(), 20.);
+ QCOMPARE(object->property("aliasProperty").toReal(), 20.);
+
+ object->setProperty("test2", 3);
+
+ QCOMPARE(object->property("realProperty").toReal(), 20.);
+ QCOMPARE(object->property("aliasProperty").toReal(), 20.);
+
+ delete object;
+}
+
void tst_qdeclarativeproperty::copy()
{
PropertyObject object;