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