diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-06-08 00:59:53 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2010-06-08 00:59:53 (GMT) |
commit | 0656d1578e86a2e9e0e1ec1d3c79e8766415a86d (patch) | |
tree | 0593be8f73cdd09a94826e2d8fc2c7b1356c1016 /tests | |
parent | d660ea1a68d282763e8f574f066d2ef958cd3c1b (diff) | |
download | Qt-0656d1578e86a2e9e0e1ec1d3c79e8766415a86d.zip Qt-0656d1578e86a2e9e0e1ec1d3c79e8766415a86d.tar.gz Qt-0656d1578e86a2e9e0e1ec1d3c79e8766415a86d.tar.bz2 |
Add test for PropertyChanges with attached properties.
Task-number: QTBUG-11283
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative/qdeclarativestates/data/attachedPropertyChanges.qml | 20 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp | 43 |
2 files changed, 63 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativestates/data/attachedPropertyChanges.qml b/tests/auto/declarative/qdeclarativestates/data/attachedPropertyChanges.qml new file mode 100644 index 0000000..e17823b --- /dev/null +++ b/tests/auto/declarative/qdeclarativestates/data/attachedPropertyChanges.qml @@ -0,0 +1,20 @@ +import Qt.test 1.0 +import Qt 4.7 + +Item { + id: item + width: 100; height: 100 + MyRectangle.foo: 0 + + states: State { + name: "foo1" + PropertyChanges { + target: item + MyRectangle.foo: 1 + width: 50 + } + } + + Component.onCompleted: item.state = "foo1" +} + diff --git a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp index 055a34c..1ddbe4d 100644 --- a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp +++ b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp @@ -50,6 +50,20 @@ #include <private/qdeclarativeitem_p.h> +class MyAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(int foo READ foo WRITE setFoo) +public: + MyAttached(QObject *parent) : QObject(parent), m_foo(13) {} + + int foo() const { return m_foo; } + void setFoo(int f) { m_foo = f; } + +private: + int m_foo; +}; + class MyRect : public QDeclarativeRectangle { Q_OBJECT @@ -61,6 +75,10 @@ public: int propertyWithNotify() const { return m_prop; } void setPropertyWithNotify(int i) { m_prop = i; emit oddlyNamedNotifySignal(); } + + static MyAttached *qmlAttachedProperties(QObject *o) { + return new MyAttached(o); + } Q_SIGNALS: void didSomething(); void oddlyNamedNotifySignal(); @@ -69,6 +87,8 @@ private: int m_prop; }; +QML_DECLARE_TYPE(MyRect) +QML_DECLARE_TYPEINFO(MyRect, QML_HAS_ATTACHED_PROPERTIES) class tst_qdeclarativestates : public QObject { @@ -83,6 +103,7 @@ private slots: void initTestCase(); void basicChanges(); + void attachedPropertyChanges(); void basicExtension(); void basicBinding(); void signalOverride(); @@ -220,6 +241,28 @@ void tst_qdeclarativestates::basicChanges() } } +void tst_qdeclarativestates::attachedPropertyChanges() +{ + QDeclarativeEngine engine; + + QDeclarativeComponent component(&engine, SRCDIR "/data/attachedPropertyChanges.qml"); + QVERIFY(component.isReady()); + + QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create()); + QVERIFY(item != 0); + QCOMPARE(item->width(), 50.0); + + // Ensure attached property has been changed + QObject *attObj = qmlAttachedPropertiesObject<MyRect>(item, false); + QVERIFY(attObj); + + MyAttached *att = qobject_cast<MyAttached*>(attObj); + QVERIFY(att); + + QEXPECT_FAIL("", "QTBUG-11283", Abort); + QCOMPARE(att->foo(), 1); +} + void tst_qdeclarativestates::basicExtension() { QDeclarativeEngine engine; |