47 #include <private/qdeclarativetext_p.h> |
47 #include <private/qdeclarativetext_p.h> |
48 #include <private/qdeclarativepropertychanges_p.h> |
48 #include <private/qdeclarativepropertychanges_p.h> |
49 #include <private/qdeclarativestategroup_p.h> |
49 #include <private/qdeclarativestategroup_p.h> |
50 #include <private/qdeclarativeitem_p.h> |
50 #include <private/qdeclarativeitem_p.h> |
51 |
51 |
|
52 #ifdef Q_OS_SYMBIAN |
|
53 // In Symbian OS test data is located in applications private dir |
|
54 #define SRCDIR "." |
|
55 #endif |
|
56 |
|
57 class MyAttached : public QObject |
|
58 { |
|
59 Q_OBJECT |
|
60 Q_PROPERTY(int foo READ foo WRITE setFoo) |
|
61 public: |
|
62 MyAttached(QObject *parent) : QObject(parent), m_foo(13) {} |
|
63 |
|
64 int foo() const { return m_foo; } |
|
65 void setFoo(int f) { m_foo = f; } |
|
66 |
|
67 private: |
|
68 int m_foo; |
|
69 }; |
52 |
70 |
53 class MyRect : public QDeclarativeRectangle |
71 class MyRect : public QDeclarativeRectangle |
54 { |
72 { |
55 Q_OBJECT |
73 Q_OBJECT |
56 Q_PROPERTY(int propertyWithNotify READ propertyWithNotify WRITE setPropertyWithNotify NOTIFY oddlyNamedNotifySignal) |
74 Q_PROPERTY(int propertyWithNotify READ propertyWithNotify WRITE setPropertyWithNotify NOTIFY oddlyNamedNotifySignal) |
59 |
77 |
60 void doSomething() { emit didSomething(); } |
78 void doSomething() { emit didSomething(); } |
61 |
79 |
62 int propertyWithNotify() const { return m_prop; } |
80 int propertyWithNotify() const { return m_prop; } |
63 void setPropertyWithNotify(int i) { m_prop = i; emit oddlyNamedNotifySignal(); } |
81 void setPropertyWithNotify(int i) { m_prop = i; emit oddlyNamedNotifySignal(); } |
|
82 |
|
83 static MyAttached *qmlAttachedProperties(QObject *o) { |
|
84 return new MyAttached(o); |
|
85 } |
64 Q_SIGNALS: |
86 Q_SIGNALS: |
65 void didSomething(); |
87 void didSomething(); |
66 void oddlyNamedNotifySignal(); |
88 void oddlyNamedNotifySignal(); |
67 |
89 |
68 private: |
90 private: |
69 int m_prop; |
91 int m_prop; |
70 }; |
92 }; |
71 |
93 |
|
94 QML_DECLARE_TYPE(MyRect) |
|
95 QML_DECLARE_TYPEINFO(MyRect, QML_HAS_ATTACHED_PROPERTIES) |
72 |
96 |
73 class tst_qdeclarativestates : public QObject |
97 class tst_qdeclarativestates : public QObject |
74 { |
98 { |
75 Q_OBJECT |
99 Q_OBJECT |
76 public: |
100 public: |
94 void anchorChanges2(); |
119 void anchorChanges2(); |
95 void anchorChanges3(); |
120 void anchorChanges3(); |
96 void anchorChanges4(); |
121 void anchorChanges4(); |
97 void anchorChanges5(); |
122 void anchorChanges5(); |
98 void anchorChangesCrash(); |
123 void anchorChangesCrash(); |
|
124 void anchorRewindBug(); |
99 void script(); |
125 void script(); |
100 void restoreEntryValues(); |
126 void restoreEntryValues(); |
101 void explicitChanges(); |
127 void explicitChanges(); |
102 void propertyErrors(); |
128 void propertyErrors(); |
103 void incorrectRestoreBug(); |
129 void incorrectRestoreBug(); |
110 void reset(); |
136 void reset(); |
111 void illegalObjectCreation(); |
137 void illegalObjectCreation(); |
112 void whenOrdering(); |
138 void whenOrdering(); |
113 void urlResolution(); |
139 void urlResolution(); |
114 void unnamedWhen(); |
140 void unnamedWhen(); |
|
141 void returnToBase(); |
115 }; |
142 }; |
116 |
143 |
117 void tst_qdeclarativestates::initTestCase() |
144 void tst_qdeclarativestates::initTestCase() |
118 { |
145 { |
119 qmlRegisterType<MyRect>("Qt.test", 1, 0, "MyRectangle"); |
146 qmlRegisterType<MyRect>("Qt.test", 1, 0, "MyRectangle"); |
215 QCOMPARE(rect->color(), QColor(Qt::red)); |
242 QCOMPARE(rect->color(), QColor(Qt::red)); |
216 |
243 |
217 rect->setPropertyWithNotify(100); |
244 rect->setPropertyWithNotify(100); |
218 QCOMPARE(rect->color(), QColor(Qt::blue)); |
245 QCOMPARE(rect->color(), QColor(Qt::blue)); |
219 } |
246 } |
|
247 } |
|
248 |
|
249 void tst_qdeclarativestates::attachedPropertyChanges() |
|
250 { |
|
251 QDeclarativeEngine engine; |
|
252 |
|
253 QDeclarativeComponent component(&engine, SRCDIR "/data/attachedPropertyChanges.qml"); |
|
254 QVERIFY(component.isReady()); |
|
255 |
|
256 QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create()); |
|
257 QVERIFY(item != 0); |
|
258 QCOMPARE(item->width(), 50.0); |
|
259 |
|
260 // Ensure attached property has been changed |
|
261 QObject *attObj = qmlAttachedPropertiesObject<MyRect>(item, false); |
|
262 QVERIFY(attObj); |
|
263 |
|
264 MyAttached *att = qobject_cast<MyAttached*>(attObj); |
|
265 QVERIFY(att); |
|
266 |
|
267 QCOMPARE(att->foo(), 1); |
220 } |
268 } |
221 |
269 |
222 void tst_qdeclarativestates::basicExtension() |
270 void tst_qdeclarativestates::basicExtension() |
223 { |
271 { |
224 QDeclarativeEngine engine; |
272 QDeclarativeEngine engine; |
758 QDeclarativeItemPrivate::get(rect)->setState("reanchored"); |
806 QDeclarativeItemPrivate::get(rect)->setState("reanchored"); |
759 |
807 |
760 delete rect; |
808 delete rect; |
761 } |
809 } |
762 |
810 |
|
811 // QTBUG-12273 |
|
812 void tst_qdeclarativestates::anchorRewindBug() |
|
813 { |
|
814 QDeclarativeEngine engine; |
|
815 |
|
816 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/anchorRewindBug.qml"); |
|
817 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
818 QVERIFY(rect != 0); |
|
819 |
|
820 QDeclarativeItem * column = rect->findChild<QDeclarativeItem*>("column"); |
|
821 |
|
822 QVERIFY(column != 0); |
|
823 QVERIFY(!QDeclarativeItemPrivate::get(column)->heightValid); |
|
824 QVERIFY(!QDeclarativeItemPrivate::get(column)->widthValid); |
|
825 QCOMPARE(column->height(), 200.0); |
|
826 QDeclarativeItemPrivate::get(rect)->setState("reanchored"); |
|
827 |
|
828 // column height and width should stay implicit |
|
829 // and column's implicit resizing should still work |
|
830 QVERIFY(!QDeclarativeItemPrivate::get(column)->heightValid); |
|
831 QVERIFY(!QDeclarativeItemPrivate::get(column)->widthValid); |
|
832 QCOMPARE(column->height(), 100.0); |
|
833 |
|
834 QDeclarativeItemPrivate::get(rect)->setState(""); |
|
835 |
|
836 // column height and width should stay implicit |
|
837 // and column's implicit resizing should still work |
|
838 QVERIFY(!QDeclarativeItemPrivate::get(column)->heightValid); |
|
839 QVERIFY(!QDeclarativeItemPrivate::get(column)->widthValid); |
|
840 QCOMPARE(column->height(), 200.0); |
|
841 |
|
842 delete rect; |
|
843 } |
|
844 |
763 void tst_qdeclarativestates::script() |
845 void tst_qdeclarativestates::script() |
764 { |
846 { |
765 QDeclarativeEngine engine; |
847 QDeclarativeEngine engine; |
766 |
848 |
767 { |
849 { |
838 QVERIFY(rect != 0); |
920 QVERIFY(rect != 0); |
839 |
921 |
840 QCOMPARE(rect->color(),QColor("red")); |
922 QCOMPARE(rect->color(),QColor("red")); |
841 |
923 |
842 QTest::ignoreMessage(QtWarningMsg, fullDataPath("/data/propertyErrors.qml") + ":8:9: QML PropertyChanges: Cannot assign to non-existent property \"colr\""); |
924 QTest::ignoreMessage(QtWarningMsg, fullDataPath("/data/propertyErrors.qml") + ":8:9: QML PropertyChanges: Cannot assign to non-existent property \"colr\""); |
843 QTest::ignoreMessage(QtWarningMsg, fullDataPath("/data/propertyErrors.qml") + ":8:9: QML PropertyChanges: Cannot assign to read-only property \"wantsFocus\""); |
925 QTest::ignoreMessage(QtWarningMsg, fullDataPath("/data/propertyErrors.qml") + ":8:9: QML PropertyChanges: Cannot assign to read-only property \"activeFocus\""); |
844 QDeclarativeItemPrivate::get(rect)->setState("blue"); |
926 QDeclarativeItemPrivate::get(rect)->setState("blue"); |
845 } |
927 } |
846 |
928 |
847 void tst_qdeclarativestates::incorrectRestoreBug() |
929 void tst_qdeclarativestates::incorrectRestoreBug() |
848 { |
930 { |
1083 rect->setProperty("triggerState", false); |
1165 rect->setProperty("triggerState", false); |
1084 QCOMPARE(rectPrivate->state(), QLatin1String("")); |
1166 QCOMPARE(rectPrivate->state(), QLatin1String("")); |
1085 QCOMPARE(rect->property("stateString").toString(), QLatin1String("")); |
1167 QCOMPARE(rect->property("stateString").toString(), QLatin1String("")); |
1086 } |
1168 } |
1087 |
1169 |
|
1170 void tst_qdeclarativestates::returnToBase() |
|
1171 { |
|
1172 QDeclarativeEngine engine; |
|
1173 |
|
1174 QDeclarativeComponent c(&engine, SRCDIR "/data/returnToBase.qml"); |
|
1175 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); |
|
1176 QVERIFY(rect != 0); |
|
1177 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
1178 |
|
1179 QCOMPARE(rectPrivate->state(), QLatin1String("")); |
|
1180 QCOMPARE(rect->property("stateString").toString(), QLatin1String("")); |
|
1181 rect->setProperty("triggerState", true); |
|
1182 QCOMPARE(rectPrivate->state(), QLatin1String("anonymousState1")); |
|
1183 QCOMPARE(rect->property("stateString").toString(), QLatin1String("inState")); |
|
1184 rect->setProperty("triggerState", false); |
|
1185 QCOMPARE(rectPrivate->state(), QLatin1String("")); |
|
1186 QCOMPARE(rect->property("stateString").toString(), QLatin1String("originalState")); |
|
1187 } |
|
1188 |
|
1189 |
1088 QTEST_MAIN(tst_qdeclarativestates) |
1190 QTEST_MAIN(tst_qdeclarativestates) |
1089 |
1191 |
1090 #include "tst_qdeclarativestates.moc" |
1192 #include "tst_qdeclarativestates.moc" |