diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-09-09 07:48:13 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-09-09 07:48:13 (GMT) |
commit | 25bed69b3c643943dac195227d3f3fadc441516c (patch) | |
tree | 86a30e40e2bd46d7d73b3d5686af52b156b36e8e | |
parent | d3bd0567fbc16263fcb181d58529e6d7aeee1bbd (diff) | |
download | Qt-25bed69b3c643943dac195227d3f3fadc441516c.zip Qt-25bed69b3c643943dac195227d3f3fadc441516c.tar.gz Qt-25bed69b3c643943dac195227d3f3fadc441516c.tar.bz2 |
Autotest for property aliases
-rw-r--r-- | tests/auto/declarative/qmlparser/Alias.qml | 8 | ||||
-rw-r--r-- | tests/auto/declarative/qmlparser/alias.1.qml | 8 | ||||
-rw-r--r-- | tests/auto/declarative/qmlparser/alias.2.qml | 8 | ||||
-rw-r--r-- | tests/auto/declarative/qmlparser/alias.3.qml | 10 | ||||
-rw-r--r-- | tests/auto/declarative/qmlparser/testtypes.h | 8 | ||||
-rw-r--r-- | tests/auto/declarative/qmlparser/tst_qmlparser.cpp | 71 |
6 files changed, 112 insertions, 1 deletions
diff --git a/tests/auto/declarative/qmlparser/Alias.qml b/tests/auto/declarative/qmlparser/Alias.qml new file mode 100644 index 0000000..8264e0d --- /dev/null +++ b/tests/auto/declarative/qmlparser/Alias.qml @@ -0,0 +1,8 @@ +import Qt 4.6 + +Object { + id: Root + property int value: 1892 + property alias aliasValue: Root.value +} + diff --git a/tests/auto/declarative/qmlparser/alias.1.qml b/tests/auto/declarative/qmlparser/alias.1.qml new file mode 100644 index 0000000..492d99a --- /dev/null +++ b/tests/auto/declarative/qmlparser/alias.1.qml @@ -0,0 +1,8 @@ +import Test 1.0 +import Qt 4.6 + +Object { + id: Root + property int value: 10 + property alias valueAlias: Root.value +} diff --git a/tests/auto/declarative/qmlparser/alias.2.qml b/tests/auto/declarative/qmlparser/alias.2.qml new file mode 100644 index 0000000..aa4d103 --- /dev/null +++ b/tests/auto/declarative/qmlparser/alias.2.qml @@ -0,0 +1,8 @@ +import Test 1.0 + +MyQmlObject { + id: Root + property alias aliasObject: Root.qmlobjectProperty + + qmlobjectProperty: MyQmlObject { value : 10 } +} diff --git a/tests/auto/declarative/qmlparser/alias.3.qml b/tests/auto/declarative/qmlparser/alias.3.qml new file mode 100644 index 0000000..e25fbae --- /dev/null +++ b/tests/auto/declarative/qmlparser/alias.3.qml @@ -0,0 +1,10 @@ +import Qt 4.6 + +Object { + property var other + other: Alias { id: MyAliasObject } + + property alias value: MyAliasObject.aliasValue + property alias value2: MyAliasObject.value +} + diff --git a/tests/auto/declarative/qmlparser/testtypes.h b/tests/auto/declarative/qmlparser/testtypes.h index 3b5d3ae..e3e9aae 100644 --- a/tests/auto/declarative/qmlparser/testtypes.h +++ b/tests/auto/declarative/qmlparser/testtypes.h @@ -59,9 +59,11 @@ class MyQmlObject : public QObject, public MyInterface, public QmlParserStatus Q_PROPERTY(MyInterface *interfaceProperty READ interface WRITE setInterface) Q_PROPERTY(int onLiteralSignal READ onLiteralSignal WRITE setOnLiteralSignal); Q_PROPERTY(MyCustomVariantType customType READ customType WRITE setCustomType); + Q_PROPERTY(MyQmlObject *qmlobjectProperty READ qmlobject WRITE setQmlobject) + Q_INTERFACES(MyInterface QmlParserStatus) public: - MyQmlObject() : m_value(-1), m_interface(0) { qRegisterMetaType<MyCustomVariantType>("MyCustomVariantType"); } + MyQmlObject() : m_value(-1), m_interface(0), m_qmlobject(0) { qRegisterMetaType<MyCustomVariantType>("MyCustomVariantType"); } int value() const { return m_value; } void setValue(int v) { m_value = v; } @@ -88,6 +90,9 @@ public: int onLiteralSignal() const { return m_value; } void setOnLiteralSignal(int v) { m_value = v; } + MyQmlObject *qmlobject() const { return m_qmlobject; } + void setQmlobject(MyQmlObject *o) { m_qmlobject = o; } + MyCustomVariantType customType() const { return m_custom; } void setCustomType(const MyCustomVariantType &v) { m_custom = v; } public slots: @@ -100,6 +105,7 @@ private: friend class tst_qmlparser; int m_value; MyInterface *m_interface; + MyQmlObject *m_qmlobject; MyCustomVariantType m_custom; }; QML_DECLARE_TYPE(MyQmlObject); diff --git a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp index e3735e7..93666aa 100644 --- a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp +++ b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp @@ -48,6 +48,7 @@ private slots: void customVariantTypes(); void valueTypes(); void cppnamespace(); + void aliasProperties(); void importsBuiltin_data(); void importsBuiltin(); @@ -517,6 +518,76 @@ void tst_qmlparser::cppnamespace() delete object; } +void tst_qmlparser::aliasProperties() +{ + // Simple "int" alias + { + QmlComponent component(&engine, TEST_FILE("alias.1.qml")); + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); + + // Read through alias + QCOMPARE(object->property("valueAlias").toInt(), 10); + object->setProperty("value", QVariant(13)); + QCOMPARE(object->property("valueAlias").toInt(), 13); + + // Write throught alias + object->setProperty("valueAlias", QVariant(19)); + QCOMPARE(object->property("valueAlias").toInt(), 19); + QCOMPARE(object->property("value").toInt(), 19); + + delete object; + } + + // Complex object alias + { + QmlComponent component(&engine, TEST_FILE("alias.2.qml")); + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); + + // Read through alias + MyQmlObject *v = + qvariant_cast<MyQmlObject *>(object->property("aliasObject")); + QVERIFY(v != 0); + QCOMPARE(v->value(), 10); + + // Write through alias + MyQmlObject *v2 = new MyQmlObject(); + v2->setParent(object); + object->setProperty("aliasObject", qVariantFromValue(v2)); + MyQmlObject *v3 = + qvariant_cast<MyQmlObject *>(object->property("aliasObject")); + QVERIFY(v3 != 0); + QCOMPARE(v3, v2); + + delete object; + } + + // Nested aliases + { + QmlComponent component(&engine, TEST_FILE("alias.3.qml")); + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("value").toInt(), 1892); + QCOMPARE(object->property("value2").toInt(), 1892); + + object->setProperty("value", QVariant(1313)); + QCOMPARE(object->property("value").toInt(), 1313); + QCOMPARE(object->property("value2").toInt(), 1313); + + object->setProperty("value2", QVariant(8080)); + QCOMPARE(object->property("value").toInt(), 8080); + QCOMPARE(object->property("value2").toInt(), 8080); + + delete object; + } + +} + class TestType : public QObject { Q_OBJECT public: |