diff options
Diffstat (limited to 'tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp')
-rw-r--r-- | tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp b/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp index a44ea6e..ec6b87f 100644 --- a/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp +++ b/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp @@ -113,6 +113,7 @@ private slots: void name(); void read(); void write(); + void reset(); // Functionality void writeObjectToList(); @@ -153,6 +154,7 @@ void tst_qmlmetaproperty::qmlmetaproperty() QCOMPARE(prop.isDefault(), false); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), false); QCOMPARE(prop.object(), (QObject *)0); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::InvalidProperty); @@ -178,9 +180,12 @@ class PropertyObject : public QObject Q_PROPERTY(QRect rectProperty READ rectProperty); Q_PROPERTY(QRect wrectProperty READ wrectProperty WRITE setWRectProperty); Q_PROPERTY(QUrl url READ url WRITE setUrl); + Q_PROPERTY(int resettableProperty READ resettableProperty WRITE setResettableProperty RESET resetProperty); Q_CLASSINFO("DefaultProperty", "defaultProperty"); public: + PropertyObject() : m_resetProperty(9) {} + int defaultProperty() { return 10; } QRect rectProperty() { return QRect(10, 10, 1, 209); } @@ -190,10 +195,15 @@ public: QUrl url() { return m_url; } void setUrl(const QUrl &u) { m_url = u; } + int resettableProperty() const { return m_resetProperty; } + void setResettableProperty(int r) { m_resetProperty = r; } + void resetProperty() { m_resetProperty = 9; } + signals: void clicked(); private: + int m_resetProperty; QRect m_rect; QUrl m_url; }; @@ -230,6 +240,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object() QCOMPARE(prop.isDefault(), false); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), false); QCOMPARE(prop.object(), (QObject *)0); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::InvalidProperty); @@ -276,6 +287,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object() QCOMPARE(prop.isDefault(), true); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), true); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), true); QCOMPARE(prop.object(), &dobject); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::Normal); @@ -329,6 +341,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string() QCOMPARE(prop.isDefault(), false); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), false); QCOMPARE(prop.object(), (QObject *)0); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::InvalidProperty); @@ -375,6 +388,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string() QCOMPARE(prop.isDefault(), false); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), true); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), true); QCOMPARE(prop.object(), &dobject); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::Normal); @@ -423,6 +437,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string() QCOMPARE(prop.isDefault(), false); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), true); QCOMPARE(prop.object(), &dobject); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::InvalidProperty); @@ -475,6 +490,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_context() QCOMPARE(prop.isDefault(), false); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), false); QCOMPARE(prop.object(), (QObject *)0); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::InvalidProperty); @@ -521,6 +537,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_context() QCOMPARE(prop.isDefault(), true); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), true); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), true); QCOMPARE(prop.object(), &dobject); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::Normal); @@ -574,6 +591,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string_context() QCOMPARE(prop.isDefault(), false); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), false); QCOMPARE(prop.object(), (QObject *)0); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::InvalidProperty); @@ -620,6 +638,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string_context() QCOMPARE(prop.isDefault(), false); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), true); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), true); QCOMPARE(prop.object(), &dobject); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::Normal); @@ -668,6 +687,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string_context() QCOMPARE(prop.isDefault(), false); QCOMPARE(prop.isWritable(), false); QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); QCOMPARE(prop.isValid(), true); QCOMPARE(prop.object(), &dobject); QCOMPARE(prop.propertyCategory(), QmlMetaProperty::InvalidProperty); @@ -973,6 +993,79 @@ void tst_qmlmetaproperty::write() } } +void tst_qmlmetaproperty::reset() +{ + // Invalid + { + QmlMetaProperty p; + QCOMPARE(p.isResettable(), false); + QCOMPARE(p.reset(), false); + } + + // Read-only default prop + { + PropertyObject o; + QmlMetaProperty p(&o); + QCOMPARE(p.isResettable(), false); + QCOMPARE(p.reset(), false); + } + + // Invalid default prop + { + QObject o; + QmlMetaProperty p(&o); + QCOMPARE(p.isResettable(), false); + QCOMPARE(p.reset(), false); + } + + // Non-resettable-only prop by name + { + PropertyObject o; + QmlMetaProperty p(&o, QString("defaultProperty")); + QCOMPARE(p.isResettable(), false); + QCOMPARE(p.reset(), false); + } + + // Resettable prop by name + { + PropertyObject o; + QmlMetaProperty p(&o, QString("resettableProperty")); + + QCOMPARE(p.read(), QVariant(9)); + QCOMPARE(p.write(QVariant(11)), true); + QCOMPARE(p.read(), QVariant(11)); + + QCOMPARE(p.isResettable(), true); + QCOMPARE(p.reset(), true); + + QCOMPARE(p.read(), QVariant(9)); + } + + // Deleted object + { + PropertyObject *o = new PropertyObject; + + QmlMetaProperty p(o, QString("resettableProperty")); + + QCOMPARE(p.isResettable(), true); + QCOMPARE(p.reset(), true); + + delete o; + + QCOMPARE(p.isResettable(), false); + QCOMPARE(p.reset(), false); + } + + // Signal property + { + PropertyObject o; + QmlMetaProperty p(&o, "onClicked"); + + QCOMPARE(p.isResettable(), false); + QCOMPARE(p.reset(), false); + } +} + void tst_qmlmetaproperty::writeObjectToList() { QmlComponent containerComponent(&engine); |