Initial import from the monolithic Qt.
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / qdeclarativepositioners / tst_qdeclarativepositioners.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 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 <QtTest/QtTest>
42 #include <private/qlistmodelinterface_p.h>
43 #include <qdeclarativeview.h>
44 #include <qdeclarativeengine.h>
45 #include <private/qdeclarativerectangle_p.h>
46 #include <private/qdeclarativepositioners_p.h>
47 #include <private/qdeclarativetransition_p.h>
48 #include <private/qdeclarativeitem_p.h>
49 #include <qdeclarativeexpression.h>
50 #include <QtGui/qgraphicswidget.h>
51 #include "../../../shared/util.h"
52
53 #ifdef Q_OS_SYMBIAN
54 // In Symbian OS test data is located in applications private dir
55 #define SRCDIR "."
56 #endif
57
58 class tst_QDeclarativePositioners : public QObject
59 {
60     Q_OBJECT
61 public:
62     tst_QDeclarativePositioners();
63
64 private slots:
65     void test_horizontal();
66     void test_horizontal_rtl();
67     void test_horizontal_spacing();
68     void test_horizontal_spacing_rightToLeft();
69     void test_horizontal_animated();
70     void test_horizontal_animated_rightToLeft();
71     void test_vertical();
72     void test_vertical_spacing();
73     void test_vertical_animated();
74     void test_grid();
75     void test_grid_topToBottom();
76     void test_grid_rightToLeft();
77     void test_grid_spacing();
78     void test_grid_animated();
79     void test_grid_animated_rightToLeft();
80     void test_grid_zero_columns();
81     void test_propertychanges();
82     void test_repeater();
83     void test_flow();
84     void test_flow_rightToLeft();
85     void test_flow_topToBottom();
86     void test_flow_resize();
87     void test_flow_resize_rightToLeft();
88     void test_flow_implicit_resize();
89     void test_conflictinganchors();
90     void test_vertical_qgraphicswidget();
91     void test_mirroring();
92     void testQtQuick11Attributes();
93     void testQtQuick11Attributes_data();
94 private:
95     QDeclarativeView *createView(const QString &filename);
96 };
97
98 tst_QDeclarativePositioners::tst_QDeclarativePositioners()
99 {
100 }
101
102 void tst_QDeclarativePositioners::test_horizontal()
103 {
104     QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal.qml");
105
106     canvas->rootObject()->setProperty("testRightToLeft", false);
107
108     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
109     QVERIFY(one != 0);
110
111     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
112     QVERIFY(two != 0);
113
114     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
115     QVERIFY(three != 0);
116
117     QCOMPARE(one->x(), 0.0);
118     QCOMPARE(one->y(), 0.0);
119     QCOMPARE(two->x(), 50.0);
120     QCOMPARE(two->y(), 0.0);
121     QCOMPARE(three->x(), 70.0);
122     QCOMPARE(three->y(), 0.0);
123
124     QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
125     QCOMPARE(row->width(), 110.0);
126     QCOMPARE(row->height(), 50.0);
127
128     delete canvas;
129 }
130
131 void tst_QDeclarativePositioners::test_horizontal_rtl()
132 {
133     QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal.qml");
134
135     canvas->rootObject()->setProperty("testRightToLeft", true);
136
137     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
138     QVERIFY(one != 0);
139
140     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
141     QVERIFY(two != 0);
142
143     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
144     QVERIFY(three != 0);
145
146     QCOMPARE(one->x(), 60.0);
147     QCOMPARE(one->y(), 0.0);
148     QCOMPARE(two->x(), 40.0);
149     QCOMPARE(two->y(), 0.0);
150     QCOMPARE(three->x(), 0.0);
151     QCOMPARE(three->y(), 0.0);
152
153     QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
154     QCOMPARE(row->width(), 110.0);
155     QCOMPARE(row->height(), 50.0);
156
157     // Change the width of the row and check that items stay to the right
158     row->setWidth(200);
159     QCOMPARE(one->x(), 150.0);
160     QCOMPARE(one->y(), 0.0);
161     QCOMPARE(two->x(), 130.0);
162     QCOMPARE(two->y(), 0.0);
163     QCOMPARE(three->x(), 90.0);
164     QCOMPARE(three->y(), 0.0);
165
166     delete canvas;
167 }
168
169 void tst_QDeclarativePositioners::test_horizontal_spacing()
170 {
171     QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal-spacing.qml");
172
173     canvas->rootObject()->setProperty("testRightToLeft", false);
174
175     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
176     QVERIFY(one != 0);
177
178     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
179     QVERIFY(two != 0);
180
181     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
182     QVERIFY(three != 0);
183
184     QCOMPARE(one->x(), 0.0);
185     QCOMPARE(one->y(), 0.0);
186     QCOMPARE(two->x(), 60.0);
187     QCOMPARE(two->y(), 0.0);
188     QCOMPARE(three->x(), 90.0);
189     QCOMPARE(three->y(), 0.0);
190
191     QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
192     QCOMPARE(row->width(), 130.0);
193     QCOMPARE(row->height(), 50.0);
194
195     delete canvas;
196 }
197
198 void tst_QDeclarativePositioners::test_horizontal_spacing_rightToLeft()
199 {
200     QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal-spacing.qml");
201
202     canvas->rootObject()->setProperty("testRightToLeft", true);
203
204     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
205     QVERIFY(one != 0);
206
207     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
208     QVERIFY(two != 0);
209
210     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
211     QVERIFY(three != 0);
212
213     QCOMPARE(one->x(), 80.0);
214     QCOMPARE(one->y(), 0.0);
215     QCOMPARE(two->x(), 50.0);
216     QCOMPARE(two->y(), 0.0);
217     QCOMPARE(three->x(), 00.0);
218     QCOMPARE(three->y(), 0.0);
219
220     QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
221     QCOMPARE(row->width(), 130.0);
222     QCOMPARE(row->height(), 50.0);
223
224     delete canvas;
225 }
226
227 void tst_QDeclarativePositioners::test_horizontal_animated()
228 {
229     QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal-animated.qml");
230
231     canvas->rootObject()->setProperty("testRightToLeft", false);
232
233     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
234     QVERIFY(one != 0);
235
236     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
237     QVERIFY(two != 0);
238
239     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
240     QVERIFY(three != 0);
241
242     //Note that they animate in
243     QCOMPARE(one->x(), -100.0);
244     QCOMPARE(two->x(), -100.0);
245     QCOMPARE(three->x(), -100.0);
246
247     QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
248     QVERIFY(row);
249     QCOMPARE(row->width(), 100.0);
250     QCOMPARE(row->height(), 50.0);
251
252     //QTRY_COMPARE used instead of waiting for the expected time of animation completion
253     //Note that this means the duration of the animation is NOT tested
254
255     QTRY_COMPARE(one->x(), 0.0);
256     QTRY_COMPARE(one->y(), 0.0);
257     QTRY_COMPARE(two->opacity(), 0.0);
258     QTRY_COMPARE(two->x(), -100.0);//Not 'in' yet
259     QTRY_COMPARE(two->y(), 0.0);
260     QTRY_COMPARE(three->x(), 50.0);
261     QTRY_COMPARE(three->y(), 0.0);
262
263     //Add 'two'
264     two->setOpacity(1.0);
265     QCOMPARE(two->opacity(), 1.0);
266
267     // New size should be immediate
268     QCOMPARE(row->width(), 150.0);
269     QCOMPARE(row->height(), 50.0);
270
271     QTest::qWait(0);//Let the animation start
272     QCOMPARE(two->x(), -100.0);
273     QCOMPARE(three->x(), 50.0);
274
275     QTRY_COMPARE(two->x(), 50.0);
276     QTRY_COMPARE(three->x(), 100.0);
277
278     delete canvas;
279 }
280
281 void tst_QDeclarativePositioners::test_horizontal_animated_rightToLeft()
282 {
283     QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal-animated.qml");
284
285     canvas->rootObject()->setProperty("testRightToLeft", true);
286
287     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
288     QVERIFY(one != 0);
289
290     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
291     QVERIFY(two != 0);
292
293     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
294     QVERIFY(three != 0);
295
296     //Note that they animate in
297     QCOMPARE(one->x(), -100.0);
298     QCOMPARE(two->x(), -100.0);
299     QCOMPARE(three->x(), -100.0);
300
301     QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
302     QVERIFY(row);
303     QCOMPARE(row->width(), 100.0);
304     QCOMPARE(row->height(), 50.0);
305
306     //QTRY_COMPARE used instead of waiting for the expected time of animation completion
307     //Note that this means the duration of the animation is NOT tested
308
309     QTRY_COMPARE(one->x(), 50.0);
310     QTRY_COMPARE(one->y(), 0.0);
311     QTRY_COMPARE(two->opacity(), 0.0);
312     QTRY_COMPARE(two->x(), -100.0);//Not 'in' yet
313     QTRY_COMPARE(two->y(), 0.0);
314     QTRY_COMPARE(three->x(), 0.0);
315     QTRY_COMPARE(three->y(), 0.0);
316
317     //Add 'two'
318     two->setOpacity(1.0);
319     QCOMPARE(two->opacity(), 1.0);
320
321     // New size should be immediate
322     QCOMPARE(row->width(), 150.0);
323     QCOMPARE(row->height(), 50.0);
324
325     QTest::qWait(0);//Let the animation start
326     QCOMPARE(one->x(), 50.0);
327     QCOMPARE(two->x(), -100.0);
328
329     QTRY_COMPARE(one->x(), 100.0);
330     QTRY_COMPARE(two->x(), 50.0);
331
332     delete canvas;
333 }
334
335 void tst_QDeclarativePositioners::test_vertical()
336 {
337     QDeclarativeView *canvas = createView(SRCDIR "/data/vertical.qml");
338
339     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
340     QVERIFY(one != 0);
341
342     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
343     QVERIFY(two != 0);
344
345     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
346     QVERIFY(three != 0);
347
348     QCOMPARE(one->x(), 0.0);
349     QCOMPARE(one->y(), 0.0);
350     QCOMPARE(two->x(), 0.0);
351     QCOMPARE(two->y(), 50.0);
352     QCOMPARE(three->x(), 0.0);
353     QCOMPARE(three->y(), 60.0);
354
355     QDeclarativeItem *column = canvas->rootObject()->findChild<QDeclarativeItem*>("column");
356     QVERIFY(column);
357     QCOMPARE(column->height(), 80.0);
358     QCOMPARE(column->width(), 50.0);
359
360     delete canvas;
361 }
362
363 void tst_QDeclarativePositioners::test_vertical_spacing()
364 {
365     QDeclarativeView *canvas = createView(SRCDIR "/data/vertical-spacing.qml");
366
367     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
368     QVERIFY(one != 0);
369
370     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
371     QVERIFY(two != 0);
372
373     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
374     QVERIFY(three != 0);
375
376     QCOMPARE(one->x(), 0.0);
377     QCOMPARE(one->y(), 0.0);
378     QCOMPARE(two->x(), 0.0);
379     QCOMPARE(two->y(), 60.0);
380     QCOMPARE(three->x(), 0.0);
381     QCOMPARE(three->y(), 80.0);
382
383     QDeclarativeItem *column = canvas->rootObject()->findChild<QDeclarativeItem*>("column");
384     QCOMPARE(column->height(), 100.0);
385     QCOMPARE(column->width(), 50.0);
386
387     delete canvas;
388 }
389
390 void tst_QDeclarativePositioners::test_vertical_animated()
391 {
392     QDeclarativeView *canvas = createView(SRCDIR "/data/vertical-animated.qml");
393
394     //Note that they animate in
395     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
396     QVERIFY(one != 0);
397     QCOMPARE(one->y(), -100.0);
398
399     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
400     QVERIFY(two != 0);
401     QCOMPARE(two->y(), -100.0);
402
403     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
404     QVERIFY(three != 0);
405     QCOMPARE(three->y(), -100.0);
406
407     QDeclarativeItem *column = canvas->rootObject()->findChild<QDeclarativeItem*>("column");
408     QVERIFY(column);
409     QCOMPARE(column->height(), 100.0);
410     QCOMPARE(column->width(), 50.0);
411
412     //QTRY_COMPARE used instead of waiting for the expected time of animation completion
413     //Note that this means the duration of the animation is NOT tested
414
415     QTRY_COMPARE(one->y(), 0.0);
416     QTRY_COMPARE(one->x(), 0.0);
417     QTRY_COMPARE(two->opacity(), 0.0);
418     QTRY_COMPARE(two->y(), -100.0);//Not 'in' yet
419     QTRY_COMPARE(two->x(), 0.0);
420     QTRY_COMPARE(three->y(), 50.0);
421     QTRY_COMPARE(three->x(), 0.0);
422
423     //Add 'two'
424     two->setOpacity(1.0);
425     QTRY_COMPARE(two->opacity(), 1.0);
426     QCOMPARE(column->height(), 150.0);
427     QCOMPARE(column->width(), 50.0);
428     QTest::qWait(0);//Let the animation start
429     QCOMPARE(two->y(), -100.0);
430     QCOMPARE(three->y(), 50.0);
431
432     QTRY_COMPARE(two->y(), 50.0);
433     QTRY_COMPARE(three->y(), 100.0);
434
435     delete canvas;
436 }
437
438 void tst_QDeclarativePositioners::test_grid()
439 {
440     QDeclarativeView *canvas = createView(SRCDIR "/data/gridtest.qml");
441
442     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
443     QVERIFY(one != 0);
444     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
445     QVERIFY(two != 0);
446     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
447     QVERIFY(three != 0);
448     QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
449     QVERIFY(four != 0);
450     QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
451     QVERIFY(five != 0);
452
453     QCOMPARE(one->x(), 0.0);
454     QCOMPARE(one->y(), 0.0);
455     QCOMPARE(two->x(), 50.0);
456     QCOMPARE(two->y(), 0.0);
457     QCOMPARE(three->x(), 70.0);
458     QCOMPARE(three->y(), 0.0);
459     QCOMPARE(four->x(), 0.0);
460     QCOMPARE(four->y(), 50.0);
461     QCOMPARE(five->x(), 50.0);
462     QCOMPARE(five->y(), 50.0);
463
464     QDeclarativeGrid *grid = canvas->rootObject()->findChild<QDeclarativeGrid*>("grid");
465     QCOMPARE(grid->flow(), QDeclarativeGrid::LeftToRight);
466     QCOMPARE(grid->width(), 100.0);
467     QCOMPARE(grid->height(), 100.0);
468
469     delete canvas;
470 }
471
472 void tst_QDeclarativePositioners::test_grid_topToBottom()
473 {
474     QDeclarativeView *canvas = createView(SRCDIR "/data/grid-toptobottom.qml");
475
476     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
477     QVERIFY(one != 0);
478     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
479     QVERIFY(two != 0);
480     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
481     QVERIFY(three != 0);
482     QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
483     QVERIFY(four != 0);
484     QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
485     QVERIFY(five != 0);
486
487     QCOMPARE(one->x(), 0.0);
488     QCOMPARE(one->y(), 0.0);
489     QCOMPARE(two->x(), 0.0);
490     QCOMPARE(two->y(), 50.0);
491     QCOMPARE(three->x(), 0.0);
492     QCOMPARE(three->y(), 100.0);
493     QCOMPARE(four->x(), 50.0);
494     QCOMPARE(four->y(), 0.0);
495     QCOMPARE(five->x(), 50.0);
496     QCOMPARE(five->y(), 50.0);
497
498     QDeclarativeGrid *grid = canvas->rootObject()->findChild<QDeclarativeGrid*>("grid");
499     QCOMPARE(grid->flow(), QDeclarativeGrid::TopToBottom);
500     QCOMPARE(grid->width(), 100.0);
501     QCOMPARE(grid->height(), 120.0);
502
503     delete canvas;
504 }
505
506 void tst_QDeclarativePositioners::test_grid_rightToLeft()
507 {
508     QDeclarativeView *canvas = createView(SRCDIR "/data/gridtest.qml");
509
510     canvas->rootObject()->setProperty("testRightToLeft", true);
511
512     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
513     QVERIFY(one != 0);
514     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
515     QVERIFY(two != 0);
516     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
517     QVERIFY(three != 0);
518     QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
519     QVERIFY(four != 0);
520     QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
521     QVERIFY(five != 0);
522
523     QCOMPARE(one->x(), 50.0);
524     QCOMPARE(one->y(), 0.0);
525     QCOMPARE(two->x(), 30.0);
526     QCOMPARE(two->y(), 0.0);
527     QCOMPARE(three->x(), 0.0);
528     QCOMPARE(three->y(), 0.0);
529     QCOMPARE(four->x(), 50.0);
530     QCOMPARE(four->y(), 50.0);
531     QCOMPARE(five->x(), 40.0);
532     QCOMPARE(five->y(), 50.0);
533
534     QDeclarativeGrid *grid = canvas->rootObject()->findChild<QDeclarativeGrid*>("grid");
535     QCOMPARE(grid->layoutDirection(), Qt::RightToLeft);
536     QCOMPARE(grid->width(), 100.0);
537     QCOMPARE(grid->height(), 100.0);
538
539     // Change the width of the grid and check that items stay to the right
540     grid->setWidth(200);
541     QCOMPARE(one->x(), 150.0);
542     QCOMPARE(one->y(), 0.0);
543     QCOMPARE(two->x(), 130.0);
544     QCOMPARE(two->y(), 0.0);
545     QCOMPARE(three->x(), 100.0);
546     QCOMPARE(three->y(), 0.0);
547     QCOMPARE(four->x(), 150.0);
548     QCOMPARE(four->y(), 50.0);
549     QCOMPARE(five->x(), 140.0);
550     QCOMPARE(five->y(), 50.0);
551
552     delete canvas;
553 }
554
555 void tst_QDeclarativePositioners::test_grid_spacing()
556 {
557     QDeclarativeView *canvas = createView(SRCDIR "/data/grid-spacing.qml");
558
559     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
560     QVERIFY(one != 0);
561     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
562     QVERIFY(two != 0);
563     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
564     QVERIFY(three != 0);
565     QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
566     QVERIFY(four != 0);
567     QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
568     QVERIFY(five != 0);
569
570     QCOMPARE(one->x(), 0.0);
571     QCOMPARE(one->y(), 0.0);
572     QCOMPARE(two->x(), 54.0);
573     QCOMPARE(two->y(), 0.0);
574     QCOMPARE(three->x(), 78.0);
575     QCOMPARE(three->y(), 0.0);
576     QCOMPARE(four->x(), 0.0);
577     QCOMPARE(four->y(), 54.0);
578     QCOMPARE(five->x(), 54.0);
579     QCOMPARE(five->y(), 54.0);
580
581     QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid");
582     QCOMPARE(grid->width(), 128.0);
583     QCOMPARE(grid->height(), 104.0);
584
585     delete canvas;
586 }
587
588 void tst_QDeclarativePositioners::test_grid_animated()
589 {
590     QDeclarativeView *canvas = createView(SRCDIR "/data/grid-animated.qml");
591
592     canvas->rootObject()->setProperty("testRightToLeft", false);
593
594     //Note that all animate in
595     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
596     QVERIFY(one != 0);
597     QCOMPARE(one->x(), -100.0);
598     QCOMPARE(one->y(), -100.0);
599
600     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
601     QVERIFY(two != 0);
602     QCOMPARE(two->x(), -100.0);
603     QCOMPARE(two->y(), -100.0);
604
605     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
606     QVERIFY(three != 0);
607     QCOMPARE(three->x(), -100.0);
608     QCOMPARE(three->y(), -100.0);
609
610     QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
611     QVERIFY(four != 0);
612     QCOMPARE(four->x(), -100.0);
613     QCOMPARE(four->y(), -100.0);
614
615     QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
616     QVERIFY(five != 0);
617     QCOMPARE(five->x(), -100.0);
618     QCOMPARE(five->y(), -100.0);
619
620     QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid");
621     QVERIFY(grid);
622     QCOMPARE(grid->width(), 150.0);
623     QCOMPARE(grid->height(), 100.0);
624
625     //QTRY_COMPARE used instead of waiting for the expected time of animation completion
626     //Note that this means the duration of the animation is NOT tested
627
628     QTRY_COMPARE(one->y(), 0.0);
629     QTRY_COMPARE(one->x(), 0.0);
630     QTRY_COMPARE(two->opacity(), 0.0);
631     QTRY_COMPARE(two->y(), -100.0);
632     QTRY_COMPARE(two->x(), -100.0);
633     QTRY_COMPARE(three->y(), 0.0);
634     QTRY_COMPARE(three->x(), 50.0);
635     QTRY_COMPARE(four->y(), 0.0);
636     QTRY_COMPARE(four->x(), 100.0);
637     QTRY_COMPARE(five->y(), 50.0);
638     QTRY_COMPARE(five->x(), 0.0);
639
640     //Add 'two'
641     two->setOpacity(1.0);
642     QCOMPARE(two->opacity(), 1.0);
643     QCOMPARE(grid->width(), 150.0);
644     QCOMPARE(grid->height(), 100.0);
645     QTest::qWait(0);//Let the animation start
646     QCOMPARE(two->x(), -100.0);
647     QCOMPARE(two->y(), -100.0);
648     QCOMPARE(one->x(), 0.0);
649     QCOMPARE(one->y(), 0.0);
650     QCOMPARE(three->x(), 50.0);
651     QCOMPARE(three->y(), 0.0);
652     QCOMPARE(four->x(), 100.0);
653     QCOMPARE(four->y(), 0.0);
654     QCOMPARE(five->x(), 0.0);
655     QCOMPARE(five->y(), 50.0);
656     //Let the animation complete
657     QTRY_COMPARE(two->x(), 50.0);
658     QTRY_COMPARE(two->y(), 0.0);
659     QTRY_COMPARE(one->x(), 0.0);
660     QTRY_COMPARE(one->y(), 0.0);
661     QTRY_COMPARE(three->x(), 100.0);
662     QTRY_COMPARE(three->y(), 0.0);
663     QTRY_COMPARE(four->x(), 0.0);
664     QTRY_COMPARE(four->y(), 50.0);
665     QTRY_COMPARE(five->x(), 50.0);
666     QTRY_COMPARE(five->y(), 50.0);
667
668     delete canvas;
669 }
670
671 void tst_QDeclarativePositioners::test_grid_animated_rightToLeft()
672 {
673     QDeclarativeView *canvas = createView(SRCDIR "/data/grid-animated.qml");
674
675     canvas->rootObject()->setProperty("testRightToLeft", true);
676
677     //Note that all animate in
678     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
679     QVERIFY(one != 0);
680     QCOMPARE(one->x(), -100.0);
681     QCOMPARE(one->y(), -100.0);
682
683     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
684     QVERIFY(two != 0);
685     QCOMPARE(two->x(), -100.0);
686     QCOMPARE(two->y(), -100.0);
687
688     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
689     QVERIFY(three != 0);
690     QCOMPARE(three->x(), -100.0);
691     QCOMPARE(three->y(), -100.0);
692
693     QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
694     QVERIFY(four != 0);
695     QCOMPARE(four->x(), -100.0);
696     QCOMPARE(four->y(), -100.0);
697
698     QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
699     QVERIFY(five != 0);
700     QCOMPARE(five->x(), -100.0);
701     QCOMPARE(five->y(), -100.0);
702
703     QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid");
704     QVERIFY(grid);
705     QCOMPARE(grid->width(), 150.0);
706     QCOMPARE(grid->height(), 100.0);
707
708     //QTRY_COMPARE used instead of waiting for the expected time of animation completion
709     //Note that this means the duration of the animation is NOT tested
710
711     QTRY_COMPARE(one->y(), 0.0);
712     QTRY_COMPARE(one->x(), 100.0);
713     QTRY_COMPARE(two->opacity(), 0.0);
714     QTRY_COMPARE(two->y(), -100.0);
715     QTRY_COMPARE(two->x(), -100.0);
716     QTRY_COMPARE(three->y(), 0.0);
717     QTRY_COMPARE(three->x(), 50.0);
718     QTRY_COMPARE(four->y(), 0.0);
719     QTRY_COMPARE(four->x(), 0.0);
720     QTRY_COMPARE(five->y(), 50.0);
721     QTRY_COMPARE(five->x(), 100.0);
722
723     //Add 'two'
724     two->setOpacity(1.0);
725     QCOMPARE(two->opacity(), 1.0);
726     QCOMPARE(grid->width(), 150.0);
727     QCOMPARE(grid->height(), 100.0);
728     QTest::qWait(0);//Let the animation start
729     QCOMPARE(two->x(), -100.0);
730     QCOMPARE(two->y(), -100.0);
731     QCOMPARE(one->x(), 100.0);
732     QCOMPARE(one->y(), 0.0);
733     QCOMPARE(three->x(), 50.0);
734     QCOMPARE(three->y(), 0.0);
735     QCOMPARE(four->x(), 0.0);
736     QCOMPARE(four->y(), 0.0);
737     QCOMPARE(five->x(), 100.0);
738     QCOMPARE(five->y(), 50.0);
739     //Let the animation complete
740     QTRY_COMPARE(two->x(), 50.0);
741     QTRY_COMPARE(two->y(), 0.0);
742     QTRY_COMPARE(one->x(), 100.0);
743     QTRY_COMPARE(one->y(), 0.0);
744     QTRY_COMPARE(three->x(), 0.0);
745     QTRY_COMPARE(three->y(), 0.0);
746     QTRY_COMPARE(four->x(), 100.0);
747     QTRY_COMPARE(four->y(), 50.0);
748     QTRY_COMPARE(five->x(), 50.0);
749     QTRY_COMPARE(five->y(), 50.0);
750
751     delete canvas;
752 }
753
754 void tst_QDeclarativePositioners::test_grid_zero_columns()
755 {
756     QDeclarativeView *canvas = createView(SRCDIR "/data/gridzerocolumns.qml");
757
758     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
759     QVERIFY(one != 0);
760     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
761     QVERIFY(two != 0);
762     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
763     QVERIFY(three != 0);
764     QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
765     QVERIFY(four != 0);
766     QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
767     QVERIFY(five != 0);
768
769     QCOMPARE(one->x(), 0.0);
770     QCOMPARE(one->y(), 0.0);
771     QCOMPARE(two->x(), 50.0);
772     QCOMPARE(two->y(), 0.0);
773     QCOMPARE(three->x(), 70.0);
774     QCOMPARE(three->y(), 0.0);
775     QCOMPARE(four->x(), 120.0);
776     QCOMPARE(four->y(), 0.0);
777     QCOMPARE(five->x(), 0.0);
778     QCOMPARE(five->y(), 50.0);
779
780     QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid");
781     QCOMPARE(grid->width(), 170.0);
782     QCOMPARE(grid->height(), 60.0);
783
784     delete canvas;
785 }
786
787 void tst_QDeclarativePositioners::test_propertychanges()
788 {
789     QDeclarativeView *canvas = createView(SRCDIR "/data/propertychangestest.qml");
790
791     QDeclarativeGrid *grid = qobject_cast<QDeclarativeGrid*>(canvas->rootObject());
792     QVERIFY(grid != 0);
793     QDeclarativeTransition *rowTransition = canvas->rootObject()->findChild<QDeclarativeTransition*>("rowTransition");
794     QDeclarativeTransition *columnTransition = canvas->rootObject()->findChild<QDeclarativeTransition*>("columnTransition");
795
796     QSignalSpy addSpy(grid, SIGNAL(addChanged()));
797     QSignalSpy moveSpy(grid, SIGNAL(moveChanged()));
798     QSignalSpy columnsSpy(grid, SIGNAL(columnsChanged()));
799     QSignalSpy rowsSpy(grid, SIGNAL(rowsChanged()));
800
801     QVERIFY(grid);
802     QVERIFY(rowTransition);
803     QVERIFY(columnTransition);
804     QCOMPARE(grid->add(), columnTransition);
805     QCOMPARE(grid->move(), columnTransition);
806     QCOMPARE(grid->columns(), 4);
807     QCOMPARE(grid->rows(), -1);
808
809     grid->setAdd(rowTransition);
810     grid->setMove(rowTransition);
811     QCOMPARE(grid->add(), rowTransition);
812     QCOMPARE(grid->move(), rowTransition);
813     QCOMPARE(addSpy.count(),1);
814     QCOMPARE(moveSpy.count(),1);
815
816     grid->setAdd(rowTransition);
817     grid->setMove(rowTransition);
818     QCOMPARE(addSpy.count(),1);
819     QCOMPARE(moveSpy.count(),1);
820
821     grid->setAdd(0);
822     grid->setMove(0);
823     QCOMPARE(addSpy.count(),2);
824     QCOMPARE(moveSpy.count(),2);
825
826     grid->setColumns(-1);
827     grid->setRows(3);
828     QCOMPARE(grid->columns(), -1);
829     QCOMPARE(grid->rows(), 3);
830     QCOMPARE(columnsSpy.count(),1);
831     QCOMPARE(rowsSpy.count(),1);
832
833     grid->setColumns(-1);
834     grid->setRows(3);
835     QCOMPARE(columnsSpy.count(),1);
836     QCOMPARE(rowsSpy.count(),1);
837
838     grid->setColumns(2);
839     grid->setRows(2);
840     QCOMPARE(columnsSpy.count(),2);
841     QCOMPARE(rowsSpy.count(),2);
842
843     delete canvas;
844 }
845
846 void tst_QDeclarativePositioners::test_repeater()
847 {
848     QDeclarativeView *canvas = createView(SRCDIR "/data/repeatertest.qml");
849
850     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
851     QVERIFY(one != 0);
852
853     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
854     QVERIFY(two != 0);
855
856     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
857     QVERIFY(three != 0);
858
859     QCOMPARE(one->x(), 0.0);
860     QCOMPARE(one->y(), 0.0);
861     QCOMPARE(two->x(), 50.0);
862     QCOMPARE(two->y(), 0.0);
863     QCOMPARE(three->x(), 100.0);
864     QCOMPARE(three->y(), 0.0);
865
866     delete canvas;
867 }
868
869 void tst_QDeclarativePositioners::test_flow()
870 {
871     QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest.qml");
872
873     canvas->rootObject()->setProperty("testRightToLeft", false);
874
875     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
876     QVERIFY(one != 0);
877     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
878     QVERIFY(two != 0);
879     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
880     QVERIFY(three != 0);
881     QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
882     QVERIFY(four != 0);
883     QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
884     QVERIFY(five != 0);
885
886     QCOMPARE(one->x(), 0.0);
887     QCOMPARE(one->y(), 0.0);
888     QCOMPARE(two->x(), 50.0);
889     QCOMPARE(two->y(), 0.0);
890     QCOMPARE(three->x(), 0.0);
891     QCOMPARE(three->y(), 50.0);
892     QCOMPARE(four->x(), 0.0);
893     QCOMPARE(four->y(), 70.0);
894     QCOMPARE(five->x(), 50.0);
895     QCOMPARE(five->y(), 70.0);
896
897     QDeclarativeItem *flow = canvas->rootObject()->findChild<QDeclarativeItem*>("flow");
898     QVERIFY(flow);
899     QCOMPARE(flow->width(), 90.0);
900     QCOMPARE(flow->height(), 120.0);
901
902     delete canvas;
903 }
904
905 void tst_QDeclarativePositioners::test_flow_rightToLeft()
906 {
907     QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest.qml");
908
909     canvas->rootObject()->setProperty("testRightToLeft", true);
910
911     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
912     QVERIFY(one != 0);
913     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
914     QVERIFY(two != 0);
915     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
916     QVERIFY(three != 0);
917     QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
918     QVERIFY(four != 0);
919     QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
920     QVERIFY(five != 0);
921
922     QCOMPARE(one->x(), 40.0);
923     QCOMPARE(one->y(), 0.0);
924     QCOMPARE(two->x(), 20.0);
925     QCOMPARE(two->y(), 0.0);
926     QCOMPARE(three->x(), 40.0);
927     QCOMPARE(three->y(), 50.0);
928     QCOMPARE(four->x(), 40.0);
929     QCOMPARE(four->y(), 70.0);
930     QCOMPARE(five->x(), 30.0);
931     QCOMPARE(five->y(), 70.0);
932
933     QDeclarativeItem *flow = canvas->rootObject()->findChild<QDeclarativeItem*>("flow");
934     QVERIFY(flow);
935     QCOMPARE(flow->width(), 90.0);
936     QCOMPARE(flow->height(), 120.0);
937
938     delete canvas;
939 }
940
941 void tst_QDeclarativePositioners::test_flow_topToBottom()
942 {
943     QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest-toptobottom.qml");
944
945     canvas->rootObject()->setProperty("testRightToLeft", false);
946
947     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
948     QVERIFY(one != 0);
949     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
950     QVERIFY(two != 0);
951     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
952     QVERIFY(three != 0);
953     QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
954     QVERIFY(four != 0);
955     QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
956     QVERIFY(five != 0);
957
958     QCOMPARE(one->x(), 0.0);
959     QCOMPARE(one->y(), 0.0);
960     QCOMPARE(two->x(), 50.0);
961     QCOMPARE(two->y(), 0.0);
962     QCOMPARE(three->x(), 50.0);
963     QCOMPARE(three->y(), 50.0);
964     QCOMPARE(four->x(), 100.0);
965     QCOMPARE(four->y(), 00.0);
966     QCOMPARE(five->x(), 100.0);
967     QCOMPARE(five->y(), 50.0);
968
969     QDeclarativeItem *flow = canvas->rootObject()->findChild<QDeclarativeItem*>("flow");
970     QVERIFY(flow);
971     QCOMPARE(flow->height(), 90.0);
972     QCOMPARE(flow->width(), 150.0);
973
974     canvas->rootObject()->setProperty("testRightToLeft", true);
975
976     QVERIFY(flow);
977     QCOMPARE(flow->height(), 90.0);
978     QCOMPARE(flow->width(), 150.0);
979
980     QCOMPARE(one->x(), 100.0);
981     QCOMPARE(one->y(), 0.0);
982     QCOMPARE(two->x(), 80.0);
983     QCOMPARE(two->y(), 0.0);
984     QCOMPARE(three->x(), 50.0);
985     QCOMPARE(three->y(), 50.0);
986     QCOMPARE(four->x(), 0.0);
987     QCOMPARE(four->y(), 0.0);
988     QCOMPARE(five->x(), 40.0);
989     QCOMPARE(five->y(), 50.0);
990
991     delete canvas;
992 }
993
994 void tst_QDeclarativePositioners::test_flow_resize()
995 {
996     QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest.qml");
997
998     QDeclarativeItem *root = qobject_cast<QDeclarativeItem*>(canvas->rootObject());
999     QVERIFY(root);
1000     root->setWidth(125);
1001     root->setProperty("testRightToLeft", false);
1002
1003     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
1004     QVERIFY(one != 0);
1005     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
1006     QVERIFY(two != 0);
1007     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
1008     QVERIFY(three != 0);
1009     QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
1010     QVERIFY(four != 0);
1011     QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
1012     QVERIFY(five != 0);
1013
1014     QCOMPARE(one->x(), 0.0);
1015     QCOMPARE(one->y(), 0.0);
1016     QCOMPARE(two->x(), 50.0);
1017     QCOMPARE(two->y(), 0.0);
1018     QCOMPARE(three->x(), 70.0);
1019     QCOMPARE(three->y(), 0.0);
1020     QCOMPARE(four->x(), 0.0);
1021     QCOMPARE(four->y(), 50.0);
1022     QCOMPARE(five->x(), 50.0);
1023     QCOMPARE(five->y(), 50.0);
1024
1025     delete canvas;
1026 }
1027
1028 void tst_QDeclarativePositioners::test_flow_resize_rightToLeft()
1029 {
1030     QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest.qml");
1031
1032     QDeclarativeItem *root = qobject_cast<QDeclarativeItem*>(canvas->rootObject());
1033     QVERIFY(root);
1034     root->setWidth(125);
1035     root->setProperty("testRightToLeft", true);
1036
1037     QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
1038     QVERIFY(one != 0);
1039     QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
1040     QVERIFY(two != 0);
1041     QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
1042     QVERIFY(three != 0);
1043     QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
1044     QVERIFY(four != 0);
1045     QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
1046     QVERIFY(five != 0);
1047
1048     QCOMPARE(one->x(), 75.0);
1049     QCOMPARE(one->y(), 0.0);
1050     QCOMPARE(two->x(), 55.0);
1051     QCOMPARE(two->y(), 0.0);
1052     QCOMPARE(three->x(), 5.0);
1053     QCOMPARE(three->y(), 0.0);
1054     QCOMPARE(four->x(), 75.0);
1055     QCOMPARE(four->y(), 50.0);
1056     QCOMPARE(five->x(), 65.0);
1057     QCOMPARE(five->y(), 50.0);
1058
1059     delete canvas;
1060 }
1061
1062 void tst_QDeclarativePositioners::test_flow_implicit_resize()
1063 {
1064     QDeclarativeView *canvas = createView(SRCDIR "/data/flow-testimplicitsize.qml");
1065     QVERIFY(canvas->rootObject() != 0);
1066
1067     QDeclarativeFlow *flow = canvas->rootObject()->findChild<QDeclarativeFlow*>("flow");
1068     QVERIFY(flow != 0);
1069
1070     QCOMPARE(flow->width(), 100.0);
1071     QCOMPARE(flow->height(), 120.0);
1072
1073     canvas->rootObject()->setProperty("flowLayout", 0);
1074     QCOMPARE(flow->flow(), QDeclarativeFlow::LeftToRight);
1075     QCOMPARE(flow->width(), 220.0);
1076     QCOMPARE(flow->height(), 50.0);
1077
1078     canvas->rootObject()->setProperty("flowLayout", 1);
1079     QCOMPARE(flow->flow(), QDeclarativeFlow::TopToBottom);
1080     QCOMPARE(flow->width(), 100.0);
1081     QCOMPARE(flow->height(), 120.0);
1082
1083     canvas->rootObject()->setProperty("flowLayout", 2);
1084     QCOMPARE(flow->layoutDirection(), Qt::RightToLeft);
1085     QCOMPARE(flow->width(), 220.0);
1086     QCOMPARE(flow->height(), 50.0);
1087
1088     delete canvas;
1089 }
1090
1091 QString warningMessage;
1092
1093 void interceptWarnings(QtMsgType type, const char *msg)
1094 {
1095     Q_UNUSED( type );
1096     warningMessage = msg;
1097 }
1098
1099 void tst_QDeclarativePositioners::test_conflictinganchors()
1100 {
1101     QtMsgHandler oldMsgHandler = qInstallMsgHandler(interceptWarnings);
1102     QDeclarativeEngine engine;
1103     QDeclarativeComponent component(&engine);
1104
1105     component.setData("import QtQuick 1.0\nColumn { Item {} }", QUrl::fromLocalFile(""));
1106     QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
1107     QVERIFY(item);
1108     QVERIFY(warningMessage.isEmpty());
1109
1110     component.setData("import QtQuick 1.0\nRow { Item {} }", QUrl::fromLocalFile(""));
1111     item = qobject_cast<QDeclarativeItem*>(component.create());
1112     QVERIFY(item);
1113     QVERIFY(warningMessage.isEmpty());
1114
1115     component.setData("import QtQuick 1.0\nGrid { Item {} }", QUrl::fromLocalFile(""));
1116     item = qobject_cast<QDeclarativeItem*>(component.create());
1117     QVERIFY(item);
1118     QVERIFY(warningMessage.isEmpty());
1119
1120     component.setData("import QtQuick 1.0\nFlow { Item {} }", QUrl::fromLocalFile(""));
1121     item = qobject_cast<QDeclarativeItem*>(component.create());
1122     QVERIFY(item);
1123     QVERIFY(warningMessage.isEmpty());
1124
1125     component.setData("import QtQuick 1.0\nColumn { Item { anchors.top: parent.top } }", QUrl::fromLocalFile(""));
1126     item = qobject_cast<QDeclarativeItem*>(component.create());
1127     QVERIFY(item);
1128     QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column"));
1129     warningMessage.clear();
1130
1131     component.setData("import QtQuick 1.0\nColumn { Item { anchors.centerIn: parent } }", QUrl::fromLocalFile(""));
1132     item = qobject_cast<QDeclarativeItem*>(component.create());
1133     QVERIFY(item);
1134     QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column"));
1135     warningMessage.clear();
1136
1137     component.setData("import QtQuick 1.0\nColumn { Item { anchors.left: parent.left } }", QUrl::fromLocalFile(""));
1138     item = qobject_cast<QDeclarativeItem*>(component.create());
1139     QVERIFY(item);
1140     QVERIFY(warningMessage.isEmpty());
1141     warningMessage.clear();
1142
1143     component.setData("import QtQuick 1.0\nRow { Item { anchors.left: parent.left } }", QUrl::fromLocalFile(""));
1144     item = qobject_cast<QDeclarativeItem*>(component.create());
1145     QVERIFY(item);
1146     QCOMPARE(warningMessage, QString("file::2:1: QML Row: Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row"));
1147     warningMessage.clear();
1148
1149     component.setData("import QtQuick 1.0\nRow { Item { anchors.fill: parent } }", QUrl::fromLocalFile(""));
1150     item = qobject_cast<QDeclarativeItem*>(component.create());
1151     QVERIFY(item);
1152     QCOMPARE(warningMessage, QString("file::2:1: QML Row: Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row"));
1153     warningMessage.clear();
1154
1155     component.setData("import QtQuick 1.0\nRow { Item { anchors.top: parent.top } }", QUrl::fromLocalFile(""));
1156     item = qobject_cast<QDeclarativeItem*>(component.create());
1157     QVERIFY(item);
1158     QVERIFY(warningMessage.isEmpty());
1159     warningMessage.clear();
1160
1161     component.setData("import QtQuick 1.0\nGrid { Item { anchors.horizontalCenter: parent.horizontalCenter } }", QUrl::fromLocalFile(""));
1162     item = qobject_cast<QDeclarativeItem*>(component.create());
1163     QVERIFY(item);
1164     QCOMPARE(warningMessage, QString("file::2:1: QML Grid: Cannot specify anchors for items inside Grid"));
1165     warningMessage.clear();
1166
1167     component.setData("import QtQuick 1.0\nGrid { Item { anchors.centerIn: parent } }", QUrl::fromLocalFile(""));
1168     item = qobject_cast<QDeclarativeItem*>(component.create());
1169     QVERIFY(item);
1170     QCOMPARE(warningMessage, QString("file::2:1: QML Grid: Cannot specify anchors for items inside Grid"));
1171     warningMessage.clear();
1172
1173     component.setData("import QtQuick 1.0\nFlow { Item { anchors.verticalCenter: parent.verticalCenter } }", QUrl::fromLocalFile(""));
1174     item = qobject_cast<QDeclarativeItem*>(component.create());
1175     QVERIFY(item);
1176     QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow"));
1177
1178     component.setData("import QtQuick 1.0\nFlow { Item { anchors.fill: parent } }", QUrl::fromLocalFile(""));
1179     item = qobject_cast<QDeclarativeItem*>(component.create());
1180     QVERIFY(item);
1181     QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow"));
1182     qInstallMsgHandler(oldMsgHandler);
1183 }
1184
1185 void tst_QDeclarativePositioners::test_vertical_qgraphicswidget()
1186 {
1187     QDeclarativeView *canvas = createView(SRCDIR "/data/verticalqgraphicswidget.qml");
1188
1189     QGraphicsWidget *one = canvas->rootObject()->findChild<QGraphicsWidget*>("one");
1190     QVERIFY(one != 0);
1191
1192     QGraphicsWidget *two = canvas->rootObject()->findChild<QGraphicsWidget*>("two");
1193     QVERIFY(two != 0);
1194
1195     QGraphicsWidget *three = canvas->rootObject()->findChild<QGraphicsWidget*>("three");
1196     QVERIFY(three != 0);
1197
1198     QCOMPARE(one->x(), 0.0);
1199     QCOMPARE(one->y(), 0.0);
1200     QCOMPARE(two->x(), 0.0);
1201     QCOMPARE(two->y(), 50.0);
1202     QCOMPARE(three->x(), 0.0);
1203     QCOMPARE(three->y(), 60.0);
1204
1205     QDeclarativeItem *column = canvas->rootObject()->findChild<QDeclarativeItem*>("column");
1206     QVERIFY(column);
1207     QCOMPARE(column->height(), 80.0);
1208     QCOMPARE(column->width(), 50.0);
1209
1210     two->resize(QSizeF(two->size().width(), 20.0));
1211     QCOMPARE(three->x(), 0.0);
1212     QCOMPARE(three->y(), 70.0);
1213
1214     two->setOpacity(0.0);
1215     QCOMPARE(one->x(), 0.0);
1216     QCOMPARE(one->y(), 0.0);
1217     QCOMPARE(three->x(), 0.0);
1218     QCOMPARE(three->y(), 50.0);
1219
1220     one->setVisible(false);
1221     QCOMPARE(three->x(), 0.0);
1222     QCOMPARE(three->y(), 0.0);
1223
1224     delete canvas;
1225 }
1226
1227 void tst_QDeclarativePositioners::test_mirroring()
1228 {
1229     QList<QString> qmlFiles;
1230     qmlFiles << "horizontal.qml" << "gridtest.qml" << "flowtest.qml";
1231     QList<QString> objectNames;
1232     objectNames << "one" << "two" << "three" << "four" << "five";
1233
1234     foreach(const QString qmlFile, qmlFiles) {
1235         QDeclarativeView *canvasA = createView(QString(SRCDIR) + "/data/" + qmlFile);
1236         QDeclarativeItem *rootA = qobject_cast<QDeclarativeItem*>(canvasA->rootObject());
1237
1238         QDeclarativeView *canvasB = createView(QString(SRCDIR) + "/data/" + qmlFile);
1239         QDeclarativeItem *rootB = qobject_cast<QDeclarativeItem*>(canvasB->rootObject());
1240
1241         rootA->setProperty("testRightToLeft", true); // layoutDirection: Qt.RightToLeft
1242
1243         // LTR != RTL
1244         foreach(const QString objectName, objectNames) {
1245             // horizontal.qml only has three items
1246             if (qmlFile == QString("horizontal.qml") && objectName == QString("four"))
1247                 break;
1248             QDeclarativeItem *itemA = rootA->findChild<QDeclarativeItem*>(objectName);
1249             QDeclarativeItem *itemB = rootB->findChild<QDeclarativeItem*>(objectName);
1250             QVERIFY(itemA->x() != itemB->x());
1251         }
1252
1253         QDeclarativeItemPrivate* rootPrivateB = QDeclarativeItemPrivate::get(rootB);
1254
1255         rootPrivateB->effectiveLayoutMirror = true; // LayoutMirroring.enabled: true
1256         rootPrivateB->isMirrorImplicit = false;
1257         rootPrivateB->inheritMirrorFromItem = true; // LayoutMirroring.childrenInherit: true
1258         rootPrivateB->resolveLayoutMirror();
1259
1260         // RTL == mirror
1261         foreach(const QString objectName, objectNames) {
1262             // horizontal.qml only has three items
1263             if (qmlFile == QString("horizontal.qml") && objectName == QString("four"))
1264                 break;
1265             QDeclarativeItem *itemA = rootA->findChild<QDeclarativeItem*>(objectName);
1266             QDeclarativeItem *itemB = rootB->findChild<QDeclarativeItem*>(objectName);
1267             QCOMPARE(itemA->x(), itemB->x());
1268         }
1269
1270         rootA->setProperty("testRightToLeft", false); // layoutDirection: Qt.LeftToRight
1271         rootB->setProperty("testRightToLeft", true); // layoutDirection: Qt.RightToLeft
1272
1273         // LTR == RTL + mirror
1274         foreach(const QString objectName, objectNames) {
1275             // horizontal.qml only has three items
1276             if (qmlFile == QString("horizontal.qml") && objectName == QString("four"))
1277                 break;
1278             QDeclarativeItem *itemA = rootA->findChild<QDeclarativeItem*>(objectName);
1279             QDeclarativeItem *itemB = rootB->findChild<QDeclarativeItem*>(objectName);
1280             QCOMPARE(itemA->x(), itemB->x());
1281         }
1282         delete canvasA;
1283         delete canvasB;
1284     }
1285 }
1286
1287 void tst_QDeclarativePositioners::testQtQuick11Attributes()
1288 {
1289     QFETCH(QString, code);
1290     QFETCH(QString, warning);
1291     QFETCH(QString, error);
1292
1293     QDeclarativeEngine engine;
1294     QObject *obj;
1295
1296     QDeclarativeComponent valid(&engine);
1297     valid.setData("import QtQuick 1.1; " + code.toUtf8(), QUrl(""));
1298     obj = valid.create();
1299     QVERIFY(obj);
1300     QVERIFY(valid.errorString().isEmpty());
1301     delete obj;
1302
1303     QDeclarativeComponent invalid(&engine);
1304     invalid.setData("import QtQuick 1.0; " + code.toUtf8(), QUrl(""));
1305     QTest::ignoreMessage(QtWarningMsg, warning.toUtf8());
1306     obj = invalid.create();
1307     QCOMPARE(invalid.errorString(), error);
1308     delete obj;
1309 }
1310
1311 void tst_QDeclarativePositioners::testQtQuick11Attributes_data()
1312 {
1313     QTest::addColumn<QString>("code");
1314     QTest::addColumn<QString>("warning");
1315     QTest::addColumn<QString>("error");
1316
1317     QTest::newRow("Flow.layoutDirection") << "Flow { layoutDirection: Qt.LeftToRight }"
1318         << "QDeclarativeComponent: Component is not ready"
1319         << ":1 \"Flow.layoutDirection\" is not available in QtQuick 1.0.\n";
1320
1321     QTest::newRow("Row.layoutDirection") << "Row { layoutDirection: Qt.LeftToRight }"
1322         << "QDeclarativeComponent: Component is not ready"
1323         << ":1 \"Row.layoutDirection\" is not available in QtQuick 1.0.\n";
1324
1325     QTest::newRow("Grid.layoutDirection") << "Grid { layoutDirection: Qt.LeftToRight }"
1326         << "QDeclarativeComponent: Component is not ready"
1327         << ":1 \"Grid.layoutDirection\" is not available in QtQuick 1.0.\n";
1328 }
1329
1330 QDeclarativeView *tst_QDeclarativePositioners::createView(const QString &filename)
1331 {
1332     QDeclarativeView *canvas = new QDeclarativeView(0);
1333
1334     canvas->setSource(QUrl::fromLocalFile(filename));
1335
1336     return canvas;
1337 }
1338
1339
1340 QTEST_MAIN(tst_QDeclarativePositioners)
1341
1342 #include "tst_qdeclarativepositioners.moc"