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