|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 #include <qtest.h> |
|
42 #include <QtDeclarative/qdeclarativeengine.h> |
|
43 #include <QtDeclarative/qdeclarativecomponent.h> |
|
44 #include <private/qdeclarativeanchors_p_p.h> |
|
45 #include <private/qdeclarativerectangle_p.h> |
|
46 #include <private/qdeclarativeimage_p.h> |
|
47 #include <private/qdeclarativetext_p.h> |
|
48 #include <private/qdeclarativepropertychanges_p.h> |
|
49 #include <private/qdeclarativestategroup_p.h> |
|
50 #include <private/qdeclarativeitem_p.h> |
|
51 |
|
52 |
|
53 class MyRect : public QDeclarativeRectangle |
|
54 { |
|
55 Q_OBJECT |
|
56 Q_PROPERTY(int propertyWithNotify READ propertyWithNotify WRITE setPropertyWithNotify NOTIFY oddlyNamedNotifySignal) |
|
57 public: |
|
58 MyRect() {} |
|
59 |
|
60 void doSomething() { emit didSomething(); } |
|
61 |
|
62 int propertyWithNotify() const { return m_prop; } |
|
63 void setPropertyWithNotify(int i) { m_prop = i; emit oddlyNamedNotifySignal(); } |
|
64 Q_SIGNALS: |
|
65 void didSomething(); |
|
66 void oddlyNamedNotifySignal(); |
|
67 |
|
68 private: |
|
69 int m_prop; |
|
70 }; |
|
71 |
|
72 |
|
73 class tst_qdeclarativestates : public QObject |
|
74 { |
|
75 Q_OBJECT |
|
76 public: |
|
77 tst_qdeclarativestates() {} |
|
78 |
|
79 private: |
|
80 static QByteArray fullDataPath(const QString &path); |
|
81 |
|
82 private slots: |
|
83 void initTestCase(); |
|
84 |
|
85 void basicChanges(); |
|
86 void basicExtension(); |
|
87 void basicBinding(); |
|
88 void signalOverride(); |
|
89 void signalOverrideCrash(); |
|
90 void signalOverrideCrash2(); |
|
91 void parentChange(); |
|
92 void parentChangeErrors(); |
|
93 void anchorChanges(); |
|
94 void anchorChanges2(); |
|
95 void anchorChanges3(); |
|
96 void anchorChanges4(); |
|
97 void anchorChanges5(); |
|
98 void anchorChangesCrash(); |
|
99 void script(); |
|
100 void restoreEntryValues(); |
|
101 void explicitChanges(); |
|
102 void propertyErrors(); |
|
103 void incorrectRestoreBug(); |
|
104 void autoStateAtStartupRestoreBug(); |
|
105 void deletingChange(); |
|
106 void deletingState(); |
|
107 void tempState(); |
|
108 void illegalTempState(); |
|
109 void nonExistantProperty(); |
|
110 void reset(); |
|
111 void illegalObjectCreation(); |
|
112 void whenOrdering(); |
|
113 void urlResolution(); |
|
114 void unnamedWhen(); |
|
115 }; |
|
116 |
|
117 void tst_qdeclarativestates::initTestCase() |
|
118 { |
|
119 qmlRegisterType<MyRect>("Qt.test", 1, 0, "MyRectangle"); |
|
120 } |
|
121 |
|
122 QByteArray tst_qdeclarativestates::fullDataPath(const QString &path) |
|
123 { |
|
124 return QUrl::fromLocalFile(SRCDIR + path).toString().toUtf8(); |
|
125 } |
|
126 |
|
127 void tst_qdeclarativestates::basicChanges() |
|
128 { |
|
129 QDeclarativeEngine engine; |
|
130 |
|
131 { |
|
132 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/basicChanges.qml"); |
|
133 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
134 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
135 QVERIFY(rect != 0); |
|
136 |
|
137 QCOMPARE(rect->color(),QColor("red")); |
|
138 |
|
139 rectPrivate->setState("blue"); |
|
140 QCOMPARE(rect->color(),QColor("blue")); |
|
141 |
|
142 rectPrivate->setState(""); |
|
143 QCOMPARE(rect->color(),QColor("red")); |
|
144 } |
|
145 |
|
146 { |
|
147 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/basicChanges2.qml"); |
|
148 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
149 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
150 QVERIFY(rect != 0); |
|
151 |
|
152 QCOMPARE(rect->color(),QColor("red")); |
|
153 |
|
154 rectPrivate->setState("blue"); |
|
155 QCOMPARE(rect->color(),QColor("blue")); |
|
156 |
|
157 rectPrivate->setState("green"); |
|
158 QCOMPARE(rect->color(),QColor("green")); |
|
159 |
|
160 rectPrivate->setState(""); |
|
161 QCOMPARE(rect->color(),QColor("red")); |
|
162 |
|
163 rectPrivate->setState("green"); |
|
164 QCOMPARE(rect->color(),QColor("green")); |
|
165 } |
|
166 |
|
167 { |
|
168 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/basicChanges3.qml"); |
|
169 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
170 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
171 QVERIFY(rect != 0); |
|
172 |
|
173 QCOMPARE(rect->color(),QColor("red")); |
|
174 QCOMPARE(rect->border()->width(),1); |
|
175 |
|
176 rectPrivate->setState("blue"); |
|
177 QCOMPARE(rect->color(),QColor("blue")); |
|
178 QCOMPARE(rect->border()->width(),1); |
|
179 |
|
180 rectPrivate->setState("bordered"); |
|
181 QCOMPARE(rect->color(),QColor("red")); |
|
182 QCOMPARE(rect->border()->width(),2); |
|
183 |
|
184 rectPrivate->setState(""); |
|
185 QCOMPARE(rect->color(),QColor("red")); |
|
186 QCOMPARE(rect->border()->width(),1); |
|
187 //### we should be checking that this is an implicit rather than explicit 1 (which currently fails) |
|
188 |
|
189 rectPrivate->setState("bordered"); |
|
190 QCOMPARE(rect->color(),QColor("red")); |
|
191 QCOMPARE(rect->border()->width(),2); |
|
192 |
|
193 rectPrivate->setState("blue"); |
|
194 QCOMPARE(rect->color(),QColor("blue")); |
|
195 QCOMPARE(rect->border()->width(),1); |
|
196 |
|
197 } |
|
198 |
|
199 { |
|
200 // Test basicChanges4.qml can magically connect to propertyWithNotify's notify |
|
201 // signal using 'onPropertyWithNotifyChanged' even though the signal name is |
|
202 // actually 'oddlyNamedNotifySignal' |
|
203 |
|
204 QDeclarativeComponent component(&engine, SRCDIR "/data/basicChanges4.qml"); |
|
205 QVERIFY(component.isReady()); |
|
206 |
|
207 MyRect *rect = qobject_cast<MyRect*>(component.create()); |
|
208 QVERIFY(rect != 0); |
|
209 |
|
210 QMetaProperty prop = rect->metaObject()->property(rect->metaObject()->indexOfProperty("propertyWithNotify")); |
|
211 QVERIFY(prop.hasNotifySignal()); |
|
212 QString notifySignal = QByteArray(prop.notifySignal().signature()); |
|
213 QVERIFY(!notifySignal.startsWith("propertyWithNotifyChanged(")); |
|
214 |
|
215 QCOMPARE(rect->color(), QColor(Qt::red)); |
|
216 |
|
217 rect->setPropertyWithNotify(100); |
|
218 QCOMPARE(rect->color(), QColor(Qt::blue)); |
|
219 } |
|
220 } |
|
221 |
|
222 void tst_qdeclarativestates::basicExtension() |
|
223 { |
|
224 QDeclarativeEngine engine; |
|
225 |
|
226 { |
|
227 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/basicExtension.qml"); |
|
228 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
229 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
230 QVERIFY(rect != 0); |
|
231 |
|
232 QCOMPARE(rect->color(),QColor("red")); |
|
233 QCOMPARE(rect->border()->width(),1); |
|
234 |
|
235 rectPrivate->setState("blue"); |
|
236 QCOMPARE(rect->color(),QColor("blue")); |
|
237 QCOMPARE(rect->border()->width(),1); |
|
238 |
|
239 rectPrivate->setState("bordered"); |
|
240 QCOMPARE(rect->color(),QColor("blue")); |
|
241 QCOMPARE(rect->border()->width(),2); |
|
242 |
|
243 rectPrivate->setState("blue"); |
|
244 QCOMPARE(rect->color(),QColor("blue")); |
|
245 QCOMPARE(rect->border()->width(),1); |
|
246 |
|
247 rectPrivate->setState(""); |
|
248 QCOMPARE(rect->color(),QColor("red")); |
|
249 QCOMPARE(rect->border()->width(),1); |
|
250 |
|
251 rectPrivate->setState("bordered"); |
|
252 QCOMPARE(rect->color(),QColor("blue")); |
|
253 QCOMPARE(rect->border()->width(),2); |
|
254 |
|
255 rectPrivate->setState(""); |
|
256 QCOMPARE(rect->color(),QColor("red")); |
|
257 QCOMPARE(rect->border()->width(),1); |
|
258 } |
|
259 |
|
260 { |
|
261 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/fakeExtension.qml"); |
|
262 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
263 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
264 QVERIFY(rect != 0); |
|
265 |
|
266 QCOMPARE(rect->color(),QColor("red")); |
|
267 |
|
268 rectPrivate->setState("blue"); |
|
269 QCOMPARE(rect->color(),QColor("blue")); |
|
270 |
|
271 rectPrivate->setState("green"); |
|
272 QCOMPARE(rect->color(),QColor("green")); |
|
273 |
|
274 rectPrivate->setState("blue"); |
|
275 QCOMPARE(rect->color(),QColor("blue")); |
|
276 |
|
277 rectPrivate->setState("green"); |
|
278 QCOMPARE(rect->color(),QColor("green")); |
|
279 |
|
280 rectPrivate->setState(""); |
|
281 QCOMPARE(rect->color(),QColor("red")); |
|
282 |
|
283 rectPrivate->setState("green"); |
|
284 QCOMPARE(rect->color(),QColor("green")); |
|
285 } |
|
286 } |
|
287 |
|
288 void tst_qdeclarativestates::basicBinding() |
|
289 { |
|
290 QDeclarativeEngine engine; |
|
291 |
|
292 { |
|
293 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/basicBinding.qml"); |
|
294 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
295 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
296 QVERIFY(rect != 0); |
|
297 |
|
298 QCOMPARE(rect->color(),QColor("red")); |
|
299 |
|
300 rectPrivate->setState("blue"); |
|
301 QCOMPARE(rect->color(),QColor("blue")); |
|
302 |
|
303 rectPrivate->setState(""); |
|
304 QCOMPARE(rect->color(),QColor("red")); |
|
305 |
|
306 rectPrivate->setState("blue"); |
|
307 QCOMPARE(rect->color(),QColor("blue")); |
|
308 rect->setProperty("sourceColor", QColor("green")); |
|
309 QCOMPARE(rect->color(),QColor("green")); |
|
310 |
|
311 rectPrivate->setState(""); |
|
312 QCOMPARE(rect->color(),QColor("red")); |
|
313 rect->setProperty("sourceColor", QColor("yellow")); |
|
314 QCOMPARE(rect->color(),QColor("red")); |
|
315 |
|
316 rectPrivate->setState("blue"); |
|
317 QCOMPARE(rect->color(),QColor("yellow")); |
|
318 } |
|
319 |
|
320 { |
|
321 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/basicBinding2.qml"); |
|
322 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
323 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
324 QVERIFY(rect != 0); |
|
325 |
|
326 QCOMPARE(rect->color(),QColor("red")); |
|
327 |
|
328 rectPrivate->setState("blue"); |
|
329 QCOMPARE(rect->color(),QColor("blue")); |
|
330 |
|
331 rectPrivate->setState(""); |
|
332 QCOMPARE(rect->color(),QColor("red")); |
|
333 |
|
334 rectPrivate->setState("blue"); |
|
335 QCOMPARE(rect->color(),QColor("blue")); |
|
336 rect->setProperty("sourceColor", QColor("green")); |
|
337 QCOMPARE(rect->color(),QColor("blue")); |
|
338 |
|
339 rectPrivate->setState(""); |
|
340 QCOMPARE(rect->color(),QColor("green")); |
|
341 rect->setProperty("sourceColor", QColor("yellow")); |
|
342 QCOMPARE(rect->color(),QColor("yellow")); |
|
343 |
|
344 rectPrivate->setState("blue"); |
|
345 QCOMPARE(rect->color(),QColor("blue")); |
|
346 |
|
347 rectPrivate->setState(""); |
|
348 QCOMPARE(rect->color(),QColor("yellow")); |
|
349 } |
|
350 |
|
351 { |
|
352 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/basicBinding3.qml"); |
|
353 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
354 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
355 QVERIFY(rect != 0); |
|
356 |
|
357 QCOMPARE(rect->color(),QColor("red")); |
|
358 rect->setProperty("sourceColor", QColor("green")); |
|
359 QCOMPARE(rect->color(),QColor("green")); |
|
360 |
|
361 rectPrivate->setState("blue"); |
|
362 QCOMPARE(rect->color(),QColor("blue")); |
|
363 rect->setProperty("sourceColor", QColor("red")); |
|
364 QCOMPARE(rect->color(),QColor("blue")); |
|
365 rect->setProperty("sourceColor2", QColor("yellow")); |
|
366 QCOMPARE(rect->color(),QColor("yellow")); |
|
367 |
|
368 rectPrivate->setState(""); |
|
369 QCOMPARE(rect->color(),QColor("red")); |
|
370 rect->setProperty("sourceColor2", QColor("green")); |
|
371 QCOMPARE(rect->color(),QColor("red")); |
|
372 rect->setProperty("sourceColor", QColor("yellow")); |
|
373 QCOMPARE(rect->color(),QColor("yellow")); |
|
374 } |
|
375 |
|
376 { |
|
377 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/basicBinding4.qml"); |
|
378 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
379 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
380 QVERIFY(rect != 0); |
|
381 |
|
382 QCOMPARE(rect->color(),QColor("red")); |
|
383 |
|
384 rectPrivate->setState("blue"); |
|
385 QCOMPARE(rect->color(),QColor("blue")); |
|
386 rect->setProperty("sourceColor", QColor("yellow")); |
|
387 QCOMPARE(rect->color(),QColor("yellow")); |
|
388 |
|
389 rectPrivate->setState("green"); |
|
390 QCOMPARE(rect->color(),QColor("green")); |
|
391 rect->setProperty("sourceColor", QColor("purple")); |
|
392 QCOMPARE(rect->color(),QColor("green")); |
|
393 |
|
394 rectPrivate->setState("blue"); |
|
395 QCOMPARE(rect->color(),QColor("purple")); |
|
396 |
|
397 rectPrivate->setState("green"); |
|
398 QCOMPARE(rect->color(),QColor("green")); |
|
399 |
|
400 rectPrivate->setState(""); |
|
401 QCOMPARE(rect->color(),QColor("red")); |
|
402 } |
|
403 } |
|
404 |
|
405 void tst_qdeclarativestates::signalOverride() |
|
406 { |
|
407 QDeclarativeEngine engine; |
|
408 |
|
409 { |
|
410 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/signalOverride.qml"); |
|
411 MyRect *rect = qobject_cast<MyRect*>(rectComponent.create()); |
|
412 QVERIFY(rect != 0); |
|
413 |
|
414 QCOMPARE(rect->color(),QColor("red")); |
|
415 rect->doSomething(); |
|
416 QCOMPARE(rect->color(),QColor("blue")); |
|
417 |
|
418 QDeclarativeItemPrivate::get(rect)->setState("green"); |
|
419 rect->doSomething(); |
|
420 QCOMPARE(rect->color(),QColor("green")); |
|
421 } |
|
422 |
|
423 { |
|
424 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/signalOverride2.qml"); |
|
425 MyRect *rect = qobject_cast<MyRect*>(rectComponent.create()); |
|
426 QVERIFY(rect != 0); |
|
427 |
|
428 QCOMPARE(rect->color(),QColor("white")); |
|
429 rect->doSomething(); |
|
430 QCOMPARE(rect->color(),QColor("blue")); |
|
431 |
|
432 QDeclarativeRectangle *innerRect = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("extendedRect")); |
|
433 QDeclarativeItemPrivate::get(innerRect)->setState("green"); |
|
434 rect->doSomething(); |
|
435 QCOMPARE(rect->color(),QColor("blue")); |
|
436 QCOMPARE(innerRect->color(),QColor("green")); |
|
437 QCOMPARE(innerRect->property("extendedColor").value<QColor>(),QColor("green")); |
|
438 } |
|
439 } |
|
440 |
|
441 void tst_qdeclarativestates::signalOverrideCrash() |
|
442 { |
|
443 QDeclarativeEngine engine; |
|
444 |
|
445 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/signalOverrideCrash.qml"); |
|
446 MyRect *rect = qobject_cast<MyRect*>(rectComponent.create()); |
|
447 QVERIFY(rect != 0); |
|
448 |
|
449 QDeclarativeItemPrivate::get(rect)->setState("overridden"); |
|
450 rect->doSomething(); |
|
451 } |
|
452 |
|
453 void tst_qdeclarativestates::signalOverrideCrash2() |
|
454 { |
|
455 QDeclarativeEngine engine; |
|
456 |
|
457 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/signalOverrideCrash2.qml"); |
|
458 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
459 QVERIFY(rect != 0); |
|
460 |
|
461 QDeclarativeItemPrivate::get(rect)->setState("state1"); |
|
462 QDeclarativeItemPrivate::get(rect)->setState("state2"); |
|
463 QDeclarativeItemPrivate::get(rect)->setState("state1"); |
|
464 |
|
465 delete rect; |
|
466 } |
|
467 |
|
468 void tst_qdeclarativestates::parentChange() |
|
469 { |
|
470 QDeclarativeEngine engine; |
|
471 |
|
472 { |
|
473 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/parentChange1.qml"); |
|
474 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
475 QVERIFY(rect != 0); |
|
476 |
|
477 QDeclarativeRectangle *innerRect = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect")); |
|
478 QVERIFY(innerRect != 0); |
|
479 |
|
480 QDeclarativeListReference list(rect, "states"); |
|
481 QDeclarativeState *state = qobject_cast<QDeclarativeState*>(list.at(0)); |
|
482 QVERIFY(state != 0); |
|
483 |
|
484 qmlExecuteDeferred(state); |
|
485 QDeclarativeParentChange *pChange = qobject_cast<QDeclarativeParentChange*>(state->operationAt(0)); |
|
486 QVERIFY(pChange != 0); |
|
487 QDeclarativeItem *nParent = qobject_cast<QDeclarativeItem*>(rect->findChild<QDeclarativeItem*>("NewParent")); |
|
488 QVERIFY(nParent != 0); |
|
489 |
|
490 QCOMPARE(pChange->parent(), nParent); |
|
491 |
|
492 QDeclarativeItemPrivate::get(rect)->setState("reparented"); |
|
493 QCOMPARE(innerRect->rotation(), qreal(0)); |
|
494 QCOMPARE(innerRect->scale(), qreal(1)); |
|
495 QCOMPARE(innerRect->x(), qreal(-133)); |
|
496 QCOMPARE(innerRect->y(), qreal(-300)); |
|
497 } |
|
498 |
|
499 { |
|
500 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/parentChange2.qml"); |
|
501 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
502 QVERIFY(rect != 0); |
|
503 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
504 QDeclarativeRectangle *innerRect = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect")); |
|
505 QVERIFY(innerRect != 0); |
|
506 |
|
507 rectPrivate->setState("reparented"); |
|
508 QCOMPARE(innerRect->rotation(), qreal(15)); |
|
509 QCOMPARE(innerRect->scale(), qreal(.5)); |
|
510 QCOMPARE(QString("%1").arg(innerRect->x()), QString("%1").arg(-19.9075)); |
|
511 QCOMPARE(QString("%1").arg(innerRect->y()), QString("%1").arg(-8.73433)); |
|
512 } |
|
513 |
|
514 { |
|
515 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/parentChange3.qml"); |
|
516 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
517 QVERIFY(rect != 0); |
|
518 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
519 QDeclarativeRectangle *innerRect = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect")); |
|
520 QVERIFY(innerRect != 0); |
|
521 |
|
522 rectPrivate->setState("reparented"); |
|
523 QCOMPARE(innerRect->rotation(), qreal(-37)); |
|
524 QCOMPARE(innerRect->scale(), qreal(.25)); |
|
525 QCOMPARE(QString("%1").arg(innerRect->x()), QString("%1").arg(-217.305)); |
|
526 QCOMPARE(QString("%1").arg(innerRect->y()), QString("%1").arg(-164.413)); |
|
527 |
|
528 rectPrivate->setState(""); |
|
529 QCOMPARE(innerRect->rotation(), qreal(0)); |
|
530 QCOMPARE(innerRect->scale(), qreal(1)); |
|
531 QCOMPARE(innerRect->x(), qreal(5)); |
|
532 //do a non-qFuzzyCompare fuzzy compare |
|
533 QVERIFY(innerRect->y() < qreal(0.00001) && innerRect->y() > qreal(-0.00001)); |
|
534 } |
|
535 } |
|
536 |
|
537 void tst_qdeclarativestates::parentChangeErrors() |
|
538 { |
|
539 QDeclarativeEngine engine; |
|
540 |
|
541 { |
|
542 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/parentChange4.qml"); |
|
543 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
544 QVERIFY(rect != 0); |
|
545 |
|
546 QDeclarativeRectangle *innerRect = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect")); |
|
547 QVERIFY(innerRect != 0); |
|
548 |
|
549 QTest::ignoreMessage(QtWarningMsg, fullDataPath("/data/parentChange4.qml") + ":25:9: QML ParentChange: Unable to preserve appearance under non-uniform scale"); |
|
550 QDeclarativeItemPrivate::get(rect)->setState("reparented"); |
|
551 QCOMPARE(innerRect->rotation(), qreal(0)); |
|
552 QCOMPARE(innerRect->scale(), qreal(1)); |
|
553 QCOMPARE(innerRect->x(), qreal(5)); |
|
554 QCOMPARE(innerRect->y(), qreal(5)); |
|
555 } |
|
556 |
|
557 { |
|
558 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/parentChange5.qml"); |
|
559 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
560 QVERIFY(rect != 0); |
|
561 |
|
562 QDeclarativeRectangle *innerRect = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect")); |
|
563 QVERIFY(innerRect != 0); |
|
564 |
|
565 QTest::ignoreMessage(QtWarningMsg, fullDataPath("/data/parentChange5.qml") + ":25:9: QML ParentChange: Unable to preserve appearance under complex transform"); |
|
566 QDeclarativeItemPrivate::get(rect)->setState("reparented"); |
|
567 QCOMPARE(innerRect->rotation(), qreal(0)); |
|
568 QCOMPARE(innerRect->scale(), qreal(1)); |
|
569 QCOMPARE(innerRect->x(), qreal(5)); |
|
570 QCOMPARE(innerRect->y(), qreal(5)); |
|
571 } |
|
572 } |
|
573 |
|
574 void tst_qdeclarativestates::anchorChanges() |
|
575 { |
|
576 QDeclarativeEngine engine; |
|
577 |
|
578 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/anchorChanges1.qml"); |
|
579 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
580 QVERIFY(rect != 0); |
|
581 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
582 |
|
583 QDeclarativeRectangle *innerRect = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect")); |
|
584 QVERIFY(innerRect != 0); |
|
585 |
|
586 QDeclarativeListReference list(rect, "states"); |
|
587 QDeclarativeState *state = qobject_cast<QDeclarativeState*>(list.at(0)); |
|
588 QVERIFY(state != 0); |
|
589 |
|
590 qmlExecuteDeferred(state); |
|
591 QDeclarativeAnchorChanges *aChanges = qobject_cast<QDeclarativeAnchorChanges*>(state->operationAt(0)); |
|
592 QVERIFY(aChanges != 0); |
|
593 |
|
594 rectPrivate->setState("right"); |
|
595 QCOMPARE(innerRect->x(), qreal(150)); |
|
596 QCOMPARE(aChanges->object(), qobject_cast<QDeclarativeItem*>(innerRect)); |
|
597 QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->left().anchorLine, QDeclarativeAnchorLine::Invalid); //### was reset (how do we distinguish from not set at all) |
|
598 QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->right().item, rectPrivate->right().item); |
|
599 QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->right().anchorLine, rectPrivate->right().anchorLine); |
|
600 |
|
601 rectPrivate->setState(""); |
|
602 QCOMPARE(innerRect->x(), qreal(5)); |
|
603 |
|
604 delete rect; |
|
605 } |
|
606 |
|
607 void tst_qdeclarativestates::anchorChanges2() |
|
608 { |
|
609 QDeclarativeEngine engine; |
|
610 |
|
611 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/anchorChanges2.qml"); |
|
612 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
613 QVERIFY(rect != 0); |
|
614 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
615 |
|
616 QDeclarativeRectangle *innerRect = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect")); |
|
617 QVERIFY(innerRect != 0); |
|
618 |
|
619 rectPrivate->setState("right"); |
|
620 QCOMPARE(innerRect->x(), qreal(150)); |
|
621 |
|
622 rectPrivate->setState(""); |
|
623 QCOMPARE(innerRect->x(), qreal(5)); |
|
624 |
|
625 delete rect; |
|
626 } |
|
627 |
|
628 void tst_qdeclarativestates::anchorChanges3() |
|
629 { |
|
630 QDeclarativeEngine engine; |
|
631 |
|
632 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/anchorChanges3.qml"); |
|
633 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
634 QVERIFY(rect != 0); |
|
635 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
636 |
|
637 QDeclarativeRectangle *innerRect = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect")); |
|
638 QVERIFY(innerRect != 0); |
|
639 |
|
640 QDeclarativeItem *leftGuideline = qobject_cast<QDeclarativeItem*>(rect->findChild<QDeclarativeItem*>("LeftGuideline")); |
|
641 QVERIFY(leftGuideline != 0); |
|
642 |
|
643 QDeclarativeItem *bottomGuideline = qobject_cast<QDeclarativeItem*>(rect->findChild<QDeclarativeItem*>("BottomGuideline")); |
|
644 QVERIFY(bottomGuideline != 0); |
|
645 |
|
646 QDeclarativeListReference list(rect, "states"); |
|
647 QDeclarativeState *state = qobject_cast<QDeclarativeState*>(list.at(0)); |
|
648 QVERIFY(state != 0); |
|
649 |
|
650 qmlExecuteDeferred(state); |
|
651 QDeclarativeAnchorChanges *aChanges = qobject_cast<QDeclarativeAnchorChanges*>(state->operationAt(0)); |
|
652 QVERIFY(aChanges != 0); |
|
653 |
|
654 rectPrivate->setState("reanchored"); |
|
655 QCOMPARE(aChanges->object(), qobject_cast<QDeclarativeItem*>(innerRect)); |
|
656 QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->left().item, QDeclarativeItemPrivate::get(leftGuideline)->left().item); |
|
657 QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->left().anchorLine, QDeclarativeItemPrivate::get(leftGuideline)->left().anchorLine); |
|
658 QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->right().item, rectPrivate->right().item); |
|
659 QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->right().anchorLine, rectPrivate->right().anchorLine); |
|
660 QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->top().item, rectPrivate->top().item); |
|
661 QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->top().anchorLine, rectPrivate->top().anchorLine); |
|
662 QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->bottom().item, QDeclarativeItemPrivate::get(bottomGuideline)->bottom().item); |
|
663 QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->bottom().anchorLine, QDeclarativeItemPrivate::get(bottomGuideline)->bottom().anchorLine); |
|
664 |
|
665 QCOMPARE(innerRect->x(), qreal(10)); |
|
666 QCOMPARE(innerRect->y(), qreal(0)); |
|
667 QCOMPARE(innerRect->width(), qreal(190)); |
|
668 QCOMPARE(innerRect->height(), qreal(150)); |
|
669 |
|
670 rectPrivate->setState(""); |
|
671 QCOMPARE(innerRect->x(), qreal(0)); |
|
672 QCOMPARE(innerRect->y(), qreal(10)); |
|
673 QCOMPARE(innerRect->width(), qreal(150)); |
|
674 QCOMPARE(innerRect->height(), qreal(190)); |
|
675 |
|
676 delete rect; |
|
677 } |
|
678 |
|
679 void tst_qdeclarativestates::anchorChanges4() |
|
680 { |
|
681 QDeclarativeEngine engine; |
|
682 |
|
683 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/anchorChanges4.qml"); |
|
684 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
685 QVERIFY(rect != 0); |
|
686 |
|
687 QDeclarativeRectangle *innerRect = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect")); |
|
688 QVERIFY(innerRect != 0); |
|
689 |
|
690 QDeclarativeItem *leftGuideline = qobject_cast<QDeclarativeItem*>(rect->findChild<QDeclarativeItem*>("LeftGuideline")); |
|
691 QVERIFY(leftGuideline != 0); |
|
692 |
|
693 QDeclarativeItem *bottomGuideline = qobject_cast<QDeclarativeItem*>(rect->findChild<QDeclarativeItem*>("BottomGuideline")); |
|
694 QVERIFY(bottomGuideline != 0); |
|
695 |
|
696 QDeclarativeListReference list(rect, "states"); |
|
697 QDeclarativeState *state = qobject_cast<QDeclarativeState*>(list.at(0)); |
|
698 QVERIFY(state != 0); |
|
699 |
|
700 qmlExecuteDeferred(state); |
|
701 QDeclarativeAnchorChanges *aChanges = qobject_cast<QDeclarativeAnchorChanges*>(state->operationAt(0)); |
|
702 QVERIFY(aChanges != 0); |
|
703 |
|
704 QDeclarativeItemPrivate::get(rect)->setState("reanchored"); |
|
705 QCOMPARE(aChanges->object(), qobject_cast<QDeclarativeItem*>(innerRect)); |
|
706 QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->horizontalCenter().item, QDeclarativeItemPrivate::get(bottomGuideline)->horizontalCenter().item); |
|
707 QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->horizontalCenter().anchorLine, QDeclarativeItemPrivate::get(bottomGuideline)->horizontalCenter().anchorLine); |
|
708 QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->verticalCenter().item, QDeclarativeItemPrivate::get(leftGuideline)->verticalCenter().item); |
|
709 QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->verticalCenter().anchorLine, QDeclarativeItemPrivate::get(leftGuideline)->verticalCenter().anchorLine); |
|
710 |
|
711 delete rect; |
|
712 } |
|
713 |
|
714 void tst_qdeclarativestates::anchorChanges5() |
|
715 { |
|
716 QDeclarativeEngine engine; |
|
717 |
|
718 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/anchorChanges5.qml"); |
|
719 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
720 QVERIFY(rect != 0); |
|
721 |
|
722 QDeclarativeRectangle *innerRect = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect")); |
|
723 QVERIFY(innerRect != 0); |
|
724 |
|
725 QDeclarativeItem *leftGuideline = qobject_cast<QDeclarativeItem*>(rect->findChild<QDeclarativeItem*>("LeftGuideline")); |
|
726 QVERIFY(leftGuideline != 0); |
|
727 |
|
728 QDeclarativeItem *bottomGuideline = qobject_cast<QDeclarativeItem*>(rect->findChild<QDeclarativeItem*>("BottomGuideline")); |
|
729 QVERIFY(bottomGuideline != 0); |
|
730 |
|
731 QDeclarativeListReference list(rect, "states"); |
|
732 QDeclarativeState *state = qobject_cast<QDeclarativeState*>(list.at(0)); |
|
733 QVERIFY(state != 0); |
|
734 |
|
735 qmlExecuteDeferred(state); |
|
736 QDeclarativeAnchorChanges *aChanges = qobject_cast<QDeclarativeAnchorChanges*>(state->operationAt(0)); |
|
737 QVERIFY(aChanges != 0); |
|
738 |
|
739 QDeclarativeItemPrivate::get(rect)->setState("reanchored"); |
|
740 QCOMPARE(aChanges->object(), qobject_cast<QDeclarativeItem*>(innerRect)); |
|
741 //QCOMPARE(aChanges->anchors()->horizontalCenter().item, bottomGuideline->horizontalCenter().item); |
|
742 //QCOMPARE(aChanges->anchors()->horizontalCenter().anchorLine, bottomGuideline->horizontalCenter().anchorLine); |
|
743 //QCOMPARE(aChanges->anchors()->baseline().item, leftGuideline->baseline().item); |
|
744 //QCOMPARE(aChanges->anchors()->baseline().anchorLine, leftGuideline->baseline().anchorLine); |
|
745 |
|
746 delete rect; |
|
747 } |
|
748 |
|
749 //QTBUG-9609 |
|
750 void tst_qdeclarativestates::anchorChangesCrash() |
|
751 { |
|
752 QDeclarativeEngine engine; |
|
753 |
|
754 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/anchorChangesCrash.qml"); |
|
755 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
756 QVERIFY(rect != 0); |
|
757 |
|
758 QDeclarativeItemPrivate::get(rect)->setState("reanchored"); |
|
759 |
|
760 delete rect; |
|
761 } |
|
762 |
|
763 void tst_qdeclarativestates::script() |
|
764 { |
|
765 QDeclarativeEngine engine; |
|
766 |
|
767 { |
|
768 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/script.qml"); |
|
769 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
770 QVERIFY(rect != 0); |
|
771 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
772 QCOMPARE(rect->color(),QColor("red")); |
|
773 |
|
774 rectPrivate->setState("blue"); |
|
775 QCOMPARE(rect->color(),QColor("blue")); |
|
776 |
|
777 rectPrivate->setState(""); |
|
778 QCOMPARE(rect->color(),QColor("blue")); // a script isn't reverted |
|
779 } |
|
780 } |
|
781 |
|
782 void tst_qdeclarativestates::restoreEntryValues() |
|
783 { |
|
784 QDeclarativeEngine engine; |
|
785 |
|
786 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/restoreEntryValues.qml"); |
|
787 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
788 QVERIFY(rect != 0); |
|
789 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
790 QCOMPARE(rect->color(),QColor("red")); |
|
791 |
|
792 rectPrivate->setState("blue"); |
|
793 QCOMPARE(rect->color(),QColor("blue")); |
|
794 |
|
795 rectPrivate->setState(""); |
|
796 QCOMPARE(rect->color(),QColor("blue")); |
|
797 } |
|
798 |
|
799 void tst_qdeclarativestates::explicitChanges() |
|
800 { |
|
801 QDeclarativeEngine engine; |
|
802 |
|
803 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/explicit.qml"); |
|
804 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
805 QVERIFY(rect != 0); |
|
806 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
807 QDeclarativeListReference list(rect, "states"); |
|
808 QDeclarativeState *state = qobject_cast<QDeclarativeState*>(list.at(0)); |
|
809 QVERIFY(state != 0); |
|
810 |
|
811 qmlExecuteDeferred(state); |
|
812 QDeclarativePropertyChanges *changes = qobject_cast<QDeclarativePropertyChanges*>(rect->findChild<QDeclarativePropertyChanges*>("changes")); |
|
813 QVERIFY(changes != 0); |
|
814 QVERIFY(changes->isExplicit()); |
|
815 |
|
816 QCOMPARE(rect->color(),QColor("red")); |
|
817 |
|
818 rectPrivate->setState("blue"); |
|
819 QCOMPARE(rect->color(),QColor("blue")); |
|
820 |
|
821 rect->setProperty("sourceColor", QColor("green")); |
|
822 QCOMPARE(rect->color(),QColor("blue")); |
|
823 |
|
824 rectPrivate->setState(""); |
|
825 QCOMPARE(rect->color(),QColor("red")); |
|
826 rect->setProperty("sourceColor", QColor("yellow")); |
|
827 QCOMPARE(rect->color(),QColor("red")); |
|
828 |
|
829 rectPrivate->setState("blue"); |
|
830 QCOMPARE(rect->color(),QColor("yellow")); |
|
831 } |
|
832 |
|
833 void tst_qdeclarativestates::propertyErrors() |
|
834 { |
|
835 QDeclarativeEngine engine; |
|
836 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/propertyErrors.qml"); |
|
837 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
838 QVERIFY(rect != 0); |
|
839 |
|
840 QCOMPARE(rect->color(),QColor("red")); |
|
841 |
|
842 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\""); |
|
844 QDeclarativeItemPrivate::get(rect)->setState("blue"); |
|
845 } |
|
846 |
|
847 void tst_qdeclarativestates::incorrectRestoreBug() |
|
848 { |
|
849 QDeclarativeEngine engine; |
|
850 |
|
851 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/basicChanges.qml"); |
|
852 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
853 QVERIFY(rect != 0); |
|
854 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
855 QCOMPARE(rect->color(),QColor("red")); |
|
856 |
|
857 rectPrivate->setState("blue"); |
|
858 QCOMPARE(rect->color(),QColor("blue")); |
|
859 |
|
860 rectPrivate->setState(""); |
|
861 QCOMPARE(rect->color(),QColor("red")); |
|
862 |
|
863 // make sure if we change the base state value, we then restore to it correctly |
|
864 rect->setColor(QColor("green")); |
|
865 |
|
866 rectPrivate->setState("blue"); |
|
867 QCOMPARE(rect->color(),QColor("blue")); |
|
868 |
|
869 rectPrivate->setState(""); |
|
870 QCOMPARE(rect->color(),QColor("green")); |
|
871 } |
|
872 |
|
873 void tst_qdeclarativestates::autoStateAtStartupRestoreBug() |
|
874 { |
|
875 QDeclarativeEngine engine; |
|
876 |
|
877 QDeclarativeComponent component(&engine, SRCDIR "/data/autoStateAtStartupRestoreBug.qml"); |
|
878 QObject *obj = component.create(); |
|
879 |
|
880 QVERIFY(obj != 0); |
|
881 QCOMPARE(obj->property("test").toInt(), 3); |
|
882 |
|
883 obj->setProperty("input", 2); |
|
884 |
|
885 QCOMPARE(obj->property("test").toInt(), 9); |
|
886 |
|
887 delete obj; |
|
888 } |
|
889 |
|
890 void tst_qdeclarativestates::deletingChange() |
|
891 { |
|
892 QDeclarativeEngine engine; |
|
893 |
|
894 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/deleting.qml"); |
|
895 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
896 QVERIFY(rect != 0); |
|
897 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
898 rectPrivate->setState("blue"); |
|
899 QCOMPARE(rect->color(),QColor("blue")); |
|
900 QCOMPARE(rect->radius(),qreal(5)); |
|
901 |
|
902 rectPrivate->setState(""); |
|
903 QCOMPARE(rect->color(),QColor("red")); |
|
904 QCOMPARE(rect->radius(),qreal(0)); |
|
905 |
|
906 QDeclarativePropertyChanges *pc = rect->findChild<QDeclarativePropertyChanges*>("pc1"); |
|
907 QVERIFY(pc != 0); |
|
908 delete pc; |
|
909 |
|
910 QDeclarativeState *state = rect->findChild<QDeclarativeState*>(); |
|
911 QVERIFY(state != 0); |
|
912 qmlExecuteDeferred(state); |
|
913 QCOMPARE(state->operationCount(), 1); |
|
914 |
|
915 rectPrivate->setState("blue"); |
|
916 QCOMPARE(rect->color(),QColor("red")); |
|
917 QCOMPARE(rect->radius(),qreal(5)); |
|
918 |
|
919 delete rect; |
|
920 } |
|
921 |
|
922 void tst_qdeclarativestates::deletingState() |
|
923 { |
|
924 QDeclarativeEngine engine; |
|
925 |
|
926 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/deletingState.qml"); |
|
927 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
928 QVERIFY(rect != 0); |
|
929 |
|
930 QDeclarativeStateGroup *sg = rect->findChild<QDeclarativeStateGroup*>(); |
|
931 QVERIFY(sg != 0); |
|
932 QVERIFY(sg->findState("blue") != 0); |
|
933 |
|
934 sg->setState("blue"); |
|
935 QCOMPARE(rect->color(),QColor("blue")); |
|
936 |
|
937 sg->setState(""); |
|
938 QCOMPARE(rect->color(),QColor("red")); |
|
939 |
|
940 QDeclarativeState *state = rect->findChild<QDeclarativeState*>(); |
|
941 QVERIFY(state != 0); |
|
942 delete state; |
|
943 |
|
944 QVERIFY(sg->findState("blue") == 0); |
|
945 |
|
946 //### should we warn that state doesn't exist |
|
947 sg->setState("blue"); |
|
948 QCOMPARE(rect->color(),QColor("red")); |
|
949 |
|
950 delete rect; |
|
951 } |
|
952 |
|
953 void tst_qdeclarativestates::tempState() |
|
954 { |
|
955 QDeclarativeEngine engine; |
|
956 |
|
957 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/legalTempState.qml"); |
|
958 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
959 QVERIFY(rect != 0); |
|
960 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
961 QTest::ignoreMessage(QtDebugMsg, "entering placed"); |
|
962 QTest::ignoreMessage(QtDebugMsg, "entering idle"); |
|
963 rectPrivate->setState("placed"); |
|
964 QCOMPARE(rectPrivate->state(), QLatin1String("idle")); |
|
965 } |
|
966 |
|
967 void tst_qdeclarativestates::illegalTempState() |
|
968 { |
|
969 QDeclarativeEngine engine; |
|
970 |
|
971 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/illegalTempState.qml"); |
|
972 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
973 QVERIFY(rect != 0); |
|
974 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
975 QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML StateGroup: Can't apply a state change as part of a state definition."); |
|
976 rectPrivate->setState("placed"); |
|
977 QCOMPARE(rectPrivate->state(), QLatin1String("placed")); |
|
978 } |
|
979 |
|
980 void tst_qdeclarativestates::nonExistantProperty() |
|
981 { |
|
982 QDeclarativeEngine engine; |
|
983 |
|
984 QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/nonExistantProp.qml"); |
|
985 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); |
|
986 QVERIFY(rect != 0); |
|
987 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
988 QTest::ignoreMessage(QtWarningMsg, fullDataPath("/data/nonExistantProp.qml") + ":9:9: QML PropertyChanges: Cannot assign to non-existent property \"colr\""); |
|
989 rectPrivate->setState("blue"); |
|
990 QCOMPARE(rectPrivate->state(), QLatin1String("blue")); |
|
991 } |
|
992 |
|
993 void tst_qdeclarativestates::reset() |
|
994 { |
|
995 QDeclarativeEngine engine; |
|
996 |
|
997 QDeclarativeComponent c(&engine, SRCDIR "/data/reset.qml"); |
|
998 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); |
|
999 QVERIFY(rect != 0); |
|
1000 |
|
1001 QDeclarativeText *text = rect->findChild<QDeclarativeText*>(); |
|
1002 QVERIFY(text != 0); |
|
1003 QCOMPARE(text->width(), qreal(40.)); |
|
1004 QVERIFY(text->width() < text->height()); |
|
1005 |
|
1006 QDeclarativeItemPrivate::get(rect)->setState("state1"); |
|
1007 |
|
1008 QVERIFY(text->width() > 41); |
|
1009 QVERIFY(text->width() > text->height()); |
|
1010 } |
|
1011 |
|
1012 void tst_qdeclarativestates::illegalObjectCreation() |
|
1013 { |
|
1014 QDeclarativeEngine engine; |
|
1015 |
|
1016 QDeclarativeComponent component(&engine, SRCDIR "/data/illegalObj.qml"); |
|
1017 QList<QDeclarativeError> errors = component.errors(); |
|
1018 QVERIFY(errors.count() == 1); |
|
1019 const QDeclarativeError &error = errors.at(0); |
|
1020 QCOMPARE(error.line(), 9); |
|
1021 QCOMPARE(error.column(), 23); |
|
1022 QCOMPARE(error.description().toUtf8().constData(), "PropertyChanges does not support creating state-specific objects."); |
|
1023 } |
|
1024 |
|
1025 void tst_qdeclarativestates::whenOrdering() |
|
1026 { |
|
1027 QDeclarativeEngine engine; |
|
1028 |
|
1029 QDeclarativeComponent c(&engine, SRCDIR "/data/whenOrdering.qml"); |
|
1030 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); |
|
1031 QVERIFY(rect != 0); |
|
1032 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
1033 |
|
1034 QCOMPARE(rectPrivate->state(), QLatin1String("")); |
|
1035 rect->setProperty("condition2", true); |
|
1036 QCOMPARE(rectPrivate->state(), QLatin1String("state2")); |
|
1037 rect->setProperty("condition1", true); |
|
1038 QCOMPARE(rectPrivate->state(), QLatin1String("state1")); |
|
1039 rect->setProperty("condition2", false); |
|
1040 QCOMPARE(rectPrivate->state(), QLatin1String("state1")); |
|
1041 rect->setProperty("condition2", true); |
|
1042 QCOMPARE(rectPrivate->state(), QLatin1String("state1")); |
|
1043 rect->setProperty("condition1", false); |
|
1044 rect->setProperty("condition2", false); |
|
1045 QCOMPARE(rectPrivate->state(), QLatin1String("")); |
|
1046 } |
|
1047 |
|
1048 void tst_qdeclarativestates::urlResolution() |
|
1049 { |
|
1050 QDeclarativeEngine engine; |
|
1051 |
|
1052 QDeclarativeComponent c(&engine, SRCDIR "/data/urlResolution.qml"); |
|
1053 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); |
|
1054 QVERIFY(rect != 0); |
|
1055 |
|
1056 QDeclarativeItem *myType = rect->findChild<QDeclarativeItem*>("MyType"); |
|
1057 QDeclarativeImage *image1 = rect->findChild<QDeclarativeImage*>("image1"); |
|
1058 QDeclarativeImage *image2 = rect->findChild<QDeclarativeImage*>("image2"); |
|
1059 QDeclarativeImage *image3 = rect->findChild<QDeclarativeImage*>("image3"); |
|
1060 QVERIFY(myType != 0 && image1 != 0 && image2 != 0 && image3 != 0); |
|
1061 |
|
1062 QDeclarativeItemPrivate::get(myType)->setState("SetImageState"); |
|
1063 QUrl resolved = QUrl::fromLocalFile(SRCDIR "/data/Implementation/images/qt-logo.png"); |
|
1064 QCOMPARE(image1->source(), resolved); |
|
1065 QCOMPARE(image2->source(), resolved); |
|
1066 QCOMPARE(image3->source(), resolved); |
|
1067 } |
|
1068 |
|
1069 void tst_qdeclarativestates::unnamedWhen() |
|
1070 { |
|
1071 QDeclarativeEngine engine; |
|
1072 |
|
1073 QDeclarativeComponent c(&engine, SRCDIR "/data/unnamedWhen.qml"); |
|
1074 QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); |
|
1075 QVERIFY(rect != 0); |
|
1076 QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); |
|
1077 |
|
1078 QCOMPARE(rectPrivate->state(), QLatin1String("")); |
|
1079 QCOMPARE(rect->property("stateString").toString(), QLatin1String("")); |
|
1080 rect->setProperty("triggerState", true); |
|
1081 QCOMPARE(rectPrivate->state(), QLatin1String("anonymousState1")); |
|
1082 QCOMPARE(rect->property("stateString").toString(), QLatin1String("inState")); |
|
1083 rect->setProperty("triggerState", false); |
|
1084 QCOMPARE(rectPrivate->state(), QLatin1String("")); |
|
1085 QCOMPARE(rect->property("stateString").toString(), QLatin1String("")); |
|
1086 } |
|
1087 |
|
1088 QTEST_MAIN(tst_qdeclarativestates) |
|
1089 |
|
1090 #include "tst_qdeclarativestates.moc" |