summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativestates
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/declarative/qdeclarativestates')
-rw-r--r--tests/auto/declarative/qdeclarativestates/data/attachedPropertyChanges.qml20
-rw-r--r--tests/auto/declarative/qdeclarativestates/data/returnToBase.qml21
-rw-r--r--tests/auto/declarative/qdeclarativestates/qdeclarativestates.pro4
-rw-r--r--tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp68
4 files changed, 110 insertions, 3 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/data/returnToBase.qml b/tests/auto/declarative/qdeclarativestates/data/returnToBase.qml
new file mode 100644
index 0000000..e342331
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativestates/data/returnToBase.qml
@@ -0,0 +1,21 @@
+import Qt 4.7
+
+Rectangle {
+ id: theRect
+ property bool triggerState: false
+ property string stateString: ""
+ states: [ State {
+ when: triggerState
+ PropertyChanges {
+ target: theRect
+ stateString: "inState"
+ }
+ },
+ State {
+ name: ""
+ PropertyChanges {
+ target: theRect
+ stateString: "originalState"
+ }
+ }]
+}
diff --git a/tests/auto/declarative/qdeclarativestates/qdeclarativestates.pro b/tests/auto/declarative/qdeclarativestates/qdeclarativestates.pro
index 6f4ecb3..2bae041 100644
--- a/tests/auto/declarative/qdeclarativestates/qdeclarativestates.pro
+++ b/tests/auto/declarative/qdeclarativestates/qdeclarativestates.pro
@@ -4,11 +4,9 @@ macx:CONFIG -= app_bundle
SOURCES += tst_qdeclarativestates.cpp
-# Define SRCDIR equal to test's source directory
symbian: {
- DEFINES += SRCDIR=\".\"
importFiles.sources = data
- importFiles.path =
+ importFiles.path = .
DEPLOYMENT = importFiles
} else {
DEFINES += SRCDIR=\\\"$$PWD\\\"
diff --git a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp
index ea074a4..2913ddd 100644
--- a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp
+++ b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp
@@ -49,6 +49,24 @@
#include <private/qdeclarativestategroup_p.h>
#include <private/qdeclarativeitem_p.h>
+#ifdef Q_OS_SYMBIAN
+// In Symbian OS test data is located in applications private dir
+#define SRCDIR "."
+#endif
+
+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
{
@@ -61,6 +79,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 +91,8 @@ private:
int m_prop;
};
+QML_DECLARE_TYPE(MyRect)
+QML_DECLARE_TYPEINFO(MyRect, QML_HAS_ATTACHED_PROPERTIES)
class tst_qdeclarativestates : public QObject
{
@@ -83,6 +107,7 @@ private slots:
void initTestCase();
void basicChanges();
+ void attachedPropertyChanges();
void basicExtension();
void basicBinding();
void signalOverride();
@@ -112,6 +137,7 @@ private slots:
void whenOrdering();
void urlResolution();
void unnamedWhen();
+ void returnToBase();
};
void tst_qdeclarativestates::initTestCase()
@@ -219,6 +245,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;
@@ -1085,6 +1133,26 @@ void tst_qdeclarativestates::unnamedWhen()
QCOMPARE(rect->property("stateString").toString(), QLatin1String(""));
}
+void tst_qdeclarativestates::returnToBase()
+{
+ QDeclarativeEngine engine;
+
+ QDeclarativeComponent c(&engine, SRCDIR "/data/returnToBase.qml");
+ QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
+ QVERIFY(rect != 0);
+ QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect);
+
+ QCOMPARE(rectPrivate->state(), QLatin1String(""));
+ QCOMPARE(rect->property("stateString").toString(), QLatin1String(""));
+ rect->setProperty("triggerState", true);
+ QCOMPARE(rectPrivate->state(), QLatin1String("anonymousState1"));
+ QCOMPARE(rect->property("stateString").toString(), QLatin1String("inState"));
+ rect->setProperty("triggerState", false);
+ QCOMPARE(rectPrivate->state(), QLatin1String(""));
+ QCOMPARE(rect->property("stateString").toString(), QLatin1String("originalState"));
+}
+
+
QTEST_MAIN(tst_qdeclarativestates)
#include "tst_qdeclarativestates.moc"