|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 #include <QtTest/QtTest> |
|
42 #include <private/qlistmodelinterface_p.h> |
|
43 #include <qdeclarativeview.h> |
|
44 #include <qdeclarativeengine.h> |
|
45 #include <private/qdeclarativerectangle_p.h> |
|
46 #include <private/qdeclarativepositioners_p.h> |
|
47 #include <private/qdeclarativetransition_p.h> |
|
48 #include <qdeclarativeexpression.h> |
|
49 #include "../../../shared/util.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_spacing(); |
|
60 void test_horizontal_animated(); |
|
61 void test_vertical(); |
|
62 void test_vertical_spacing(); |
|
63 void test_vertical_animated(); |
|
64 void test_grid(); |
|
65 void test_grid_topToBottom(); |
|
66 void test_grid_spacing(); |
|
67 void test_grid_animated(); |
|
68 void test_grid_zero_columns(); |
|
69 void test_propertychanges(); |
|
70 void test_repeater(); |
|
71 void test_flow(); |
|
72 void test_flow_resize(); |
|
73 void test_conflictinganchors(); |
|
74 private: |
|
75 QDeclarativeView *createView(const QString &filename); |
|
76 }; |
|
77 |
|
78 tst_QDeclarativePositioners::tst_QDeclarativePositioners() |
|
79 { |
|
80 } |
|
81 |
|
82 void tst_QDeclarativePositioners::test_horizontal() |
|
83 { |
|
84 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal.qml"); |
|
85 |
|
86 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one"); |
|
87 QVERIFY(one != 0); |
|
88 |
|
89 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two"); |
|
90 QVERIFY(two != 0); |
|
91 |
|
92 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three"); |
|
93 QVERIFY(three != 0); |
|
94 |
|
95 QCOMPARE(one->x(), 0.0); |
|
96 QCOMPARE(one->y(), 0.0); |
|
97 QCOMPARE(two->x(), 50.0); |
|
98 QCOMPARE(two->y(), 0.0); |
|
99 QCOMPARE(three->x(), 70.0); |
|
100 QCOMPARE(three->y(), 0.0); |
|
101 |
|
102 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row"); |
|
103 QCOMPARE(row->width(), 110.0); |
|
104 QCOMPARE(row->height(), 50.0); |
|
105 |
|
106 delete canvas; |
|
107 } |
|
108 |
|
109 void tst_QDeclarativePositioners::test_horizontal_spacing() |
|
110 { |
|
111 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal-spacing.qml"); |
|
112 |
|
113 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one"); |
|
114 QVERIFY(one != 0); |
|
115 |
|
116 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two"); |
|
117 QVERIFY(two != 0); |
|
118 |
|
119 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three"); |
|
120 QVERIFY(three != 0); |
|
121 |
|
122 QCOMPARE(one->x(), 0.0); |
|
123 QCOMPARE(one->y(), 0.0); |
|
124 QCOMPARE(two->x(), 60.0); |
|
125 QCOMPARE(two->y(), 0.0); |
|
126 QCOMPARE(three->x(), 90.0); |
|
127 QCOMPARE(three->y(), 0.0); |
|
128 |
|
129 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row"); |
|
130 QCOMPARE(row->width(), 130.0); |
|
131 QCOMPARE(row->height(), 50.0); |
|
132 |
|
133 delete canvas; |
|
134 } |
|
135 |
|
136 void tst_QDeclarativePositioners::test_horizontal_animated() |
|
137 { |
|
138 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal-animated.qml"); |
|
139 |
|
140 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one"); |
|
141 QVERIFY(one != 0); |
|
142 |
|
143 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two"); |
|
144 QVERIFY(two != 0); |
|
145 |
|
146 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three"); |
|
147 QVERIFY(three != 0); |
|
148 |
|
149 //Note that they animate in |
|
150 QCOMPARE(one->x(), -100.0); |
|
151 QCOMPARE(two->x(), -100.0); |
|
152 QCOMPARE(three->x(), -100.0); |
|
153 |
|
154 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row"); |
|
155 QVERIFY(row); |
|
156 QCOMPARE(row->width(), 100.0); |
|
157 QCOMPARE(row->height(), 50.0); |
|
158 |
|
159 //QTRY_COMPARE used instead of waiting for the expected time of animation completion |
|
160 //Note that this means the duration of the animation is NOT tested |
|
161 |
|
162 QTRY_COMPARE(one->x(), 0.0); |
|
163 QTRY_COMPARE(one->y(), 0.0); |
|
164 QTRY_COMPARE(two->opacity(), 0.0); |
|
165 QTRY_COMPARE(two->x(), -100.0);//Not 'in' yet |
|
166 QTRY_COMPARE(two->y(), 0.0); |
|
167 QTRY_COMPARE(three->x(), 50.0); |
|
168 QTRY_COMPARE(three->y(), 0.0); |
|
169 |
|
170 //Add 'two' |
|
171 two->setOpacity(1.0); |
|
172 QCOMPARE(two->opacity(), 1.0); |
|
173 |
|
174 // New size should be immediate |
|
175 QCOMPARE(row->width(), 150.0); |
|
176 QCOMPARE(row->height(), 50.0); |
|
177 |
|
178 QTest::qWait(0);//Let the animation start |
|
179 QCOMPARE(two->x(), -100.0); |
|
180 QCOMPARE(three->x(), 50.0); |
|
181 |
|
182 QTRY_COMPARE(two->x(), 50.0); |
|
183 QTRY_COMPARE(three->x(), 100.0); |
|
184 |
|
185 delete canvas; |
|
186 } |
|
187 |
|
188 void tst_QDeclarativePositioners::test_vertical() |
|
189 { |
|
190 QDeclarativeView *canvas = createView(SRCDIR "/data/vertical.qml"); |
|
191 |
|
192 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one"); |
|
193 QVERIFY(one != 0); |
|
194 |
|
195 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two"); |
|
196 QVERIFY(two != 0); |
|
197 |
|
198 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three"); |
|
199 QVERIFY(three != 0); |
|
200 |
|
201 QCOMPARE(one->x(), 0.0); |
|
202 QCOMPARE(one->y(), 0.0); |
|
203 QCOMPARE(two->x(), 0.0); |
|
204 QCOMPARE(two->y(), 50.0); |
|
205 QCOMPARE(three->x(), 0.0); |
|
206 QCOMPARE(three->y(), 60.0); |
|
207 |
|
208 QDeclarativeItem *column = canvas->rootObject()->findChild<QDeclarativeItem*>("column"); |
|
209 QVERIFY(column); |
|
210 QCOMPARE(column->height(), 80.0); |
|
211 QCOMPARE(column->width(), 50.0); |
|
212 |
|
213 delete canvas; |
|
214 } |
|
215 |
|
216 void tst_QDeclarativePositioners::test_vertical_spacing() |
|
217 { |
|
218 QDeclarativeView *canvas = createView(SRCDIR "/data/vertical-spacing.qml"); |
|
219 |
|
220 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one"); |
|
221 QVERIFY(one != 0); |
|
222 |
|
223 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two"); |
|
224 QVERIFY(two != 0); |
|
225 |
|
226 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three"); |
|
227 QVERIFY(three != 0); |
|
228 |
|
229 QCOMPARE(one->x(), 0.0); |
|
230 QCOMPARE(one->y(), 0.0); |
|
231 QCOMPARE(two->x(), 0.0); |
|
232 QCOMPARE(two->y(), 60.0); |
|
233 QCOMPARE(three->x(), 0.0); |
|
234 QCOMPARE(three->y(), 80.0); |
|
235 |
|
236 QDeclarativeItem *column = canvas->rootObject()->findChild<QDeclarativeItem*>("column"); |
|
237 QCOMPARE(column->height(), 100.0); |
|
238 QCOMPARE(column->width(), 50.0); |
|
239 |
|
240 delete canvas; |
|
241 } |
|
242 |
|
243 void tst_QDeclarativePositioners::test_vertical_animated() |
|
244 { |
|
245 QDeclarativeView *canvas = createView(SRCDIR "/data/vertical-animated.qml"); |
|
246 |
|
247 //Note that they animate in |
|
248 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one"); |
|
249 QVERIFY(one != 0); |
|
250 QCOMPARE(one->y(), -100.0); |
|
251 |
|
252 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two"); |
|
253 QVERIFY(two != 0); |
|
254 QCOMPARE(two->y(), -100.0); |
|
255 |
|
256 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three"); |
|
257 QVERIFY(three != 0); |
|
258 QCOMPARE(three->y(), -100.0); |
|
259 |
|
260 QDeclarativeItem *column = canvas->rootObject()->findChild<QDeclarativeItem*>("column"); |
|
261 QVERIFY(column); |
|
262 QCOMPARE(column->height(), 100.0); |
|
263 QCOMPARE(column->width(), 50.0); |
|
264 |
|
265 //QTRY_COMPARE used instead of waiting for the expected time of animation completion |
|
266 //Note that this means the duration of the animation is NOT tested |
|
267 |
|
268 QTRY_COMPARE(one->y(), 0.0); |
|
269 QTRY_COMPARE(one->x(), 0.0); |
|
270 QTRY_COMPARE(two->opacity(), 0.0); |
|
271 QTRY_COMPARE(two->y(), -100.0);//Not 'in' yet |
|
272 QTRY_COMPARE(two->x(), 0.0); |
|
273 QTRY_COMPARE(three->y(), 50.0); |
|
274 QTRY_COMPARE(three->x(), 0.0); |
|
275 |
|
276 //Add 'two' |
|
277 two->setOpacity(1.0); |
|
278 QTRY_COMPARE(two->opacity(), 1.0); |
|
279 QCOMPARE(column->height(), 150.0); |
|
280 QCOMPARE(column->width(), 50.0); |
|
281 QTest::qWait(0);//Let the animation start |
|
282 QCOMPARE(two->y(), -100.0); |
|
283 QCOMPARE(three->y(), 50.0); |
|
284 |
|
285 QTRY_COMPARE(two->y(), 50.0); |
|
286 QTRY_COMPARE(three->y(), 100.0); |
|
287 |
|
288 delete canvas; |
|
289 } |
|
290 |
|
291 void tst_QDeclarativePositioners::test_grid() |
|
292 { |
|
293 QDeclarativeView *canvas = createView(SRCDIR "/data/gridtest.qml"); |
|
294 |
|
295 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one"); |
|
296 QVERIFY(one != 0); |
|
297 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two"); |
|
298 QVERIFY(two != 0); |
|
299 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three"); |
|
300 QVERIFY(three != 0); |
|
301 QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four"); |
|
302 QVERIFY(four != 0); |
|
303 QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five"); |
|
304 QVERIFY(five != 0); |
|
305 |
|
306 QCOMPARE(one->x(), 0.0); |
|
307 QCOMPARE(one->y(), 0.0); |
|
308 QCOMPARE(two->x(), 50.0); |
|
309 QCOMPARE(two->y(), 0.0); |
|
310 QCOMPARE(three->x(), 70.0); |
|
311 QCOMPARE(three->y(), 0.0); |
|
312 QCOMPARE(four->x(), 0.0); |
|
313 QCOMPARE(four->y(), 50.0); |
|
314 QCOMPARE(five->x(), 50.0); |
|
315 QCOMPARE(five->y(), 50.0); |
|
316 |
|
317 QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid"); |
|
318 QCOMPARE(grid->width(), 120.0); |
|
319 QCOMPARE(grid->height(), 100.0); |
|
320 |
|
321 delete canvas; |
|
322 } |
|
323 |
|
324 void tst_QDeclarativePositioners::test_grid_topToBottom() |
|
325 { |
|
326 QDeclarativeView *canvas = createView(SRCDIR "/data/grid-toptobottom.qml"); |
|
327 |
|
328 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one"); |
|
329 QVERIFY(one != 0); |
|
330 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two"); |
|
331 QVERIFY(two != 0); |
|
332 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three"); |
|
333 QVERIFY(three != 0); |
|
334 QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four"); |
|
335 QVERIFY(four != 0); |
|
336 QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five"); |
|
337 QVERIFY(five != 0); |
|
338 |
|
339 QCOMPARE(one->x(), 0.0); |
|
340 QCOMPARE(one->y(), 0.0); |
|
341 QCOMPARE(two->x(), 0.0); |
|
342 QCOMPARE(two->y(), 50.0); |
|
343 QCOMPARE(three->x(), 0.0); |
|
344 QCOMPARE(three->y(), 100.0); |
|
345 QCOMPARE(four->x(), 50.0); |
|
346 QCOMPARE(four->y(), 0.0); |
|
347 QCOMPARE(five->x(), 50.0); |
|
348 QCOMPARE(five->y(), 50.0); |
|
349 |
|
350 QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid"); |
|
351 QCOMPARE(grid->width(), 100.0); |
|
352 QCOMPARE(grid->height(), 120.0); |
|
353 |
|
354 delete canvas; |
|
355 } |
|
356 |
|
357 void tst_QDeclarativePositioners::test_grid_spacing() |
|
358 { |
|
359 QDeclarativeView *canvas = createView(SRCDIR "/data/grid-spacing.qml"); |
|
360 |
|
361 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one"); |
|
362 QVERIFY(one != 0); |
|
363 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two"); |
|
364 QVERIFY(two != 0); |
|
365 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three"); |
|
366 QVERIFY(three != 0); |
|
367 QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four"); |
|
368 QVERIFY(four != 0); |
|
369 QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five"); |
|
370 QVERIFY(five != 0); |
|
371 |
|
372 QCOMPARE(one->x(), 0.0); |
|
373 QCOMPARE(one->y(), 0.0); |
|
374 QCOMPARE(two->x(), 54.0); |
|
375 QCOMPARE(two->y(), 0.0); |
|
376 QCOMPARE(three->x(), 78.0); |
|
377 QCOMPARE(three->y(), 0.0); |
|
378 QCOMPARE(four->x(), 0.0); |
|
379 QCOMPARE(four->y(), 54.0); |
|
380 QCOMPARE(five->x(), 54.0); |
|
381 QCOMPARE(five->y(), 54.0); |
|
382 |
|
383 QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid"); |
|
384 QCOMPARE(grid->width(), 128.0); |
|
385 QCOMPARE(grid->height(), 104.0); |
|
386 |
|
387 delete canvas; |
|
388 } |
|
389 |
|
390 void tst_QDeclarativePositioners::test_grid_animated() |
|
391 { |
|
392 QDeclarativeView *canvas = createView(SRCDIR "/data/grid-animated.qml"); |
|
393 |
|
394 //Note that all animate in |
|
395 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one"); |
|
396 QVERIFY(one != 0); |
|
397 QCOMPARE(one->x(), -100.0); |
|
398 QCOMPARE(one->y(), -100.0); |
|
399 |
|
400 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two"); |
|
401 QVERIFY(two != 0); |
|
402 QCOMPARE(two->x(), -100.0); |
|
403 QCOMPARE(two->y(), -100.0); |
|
404 |
|
405 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three"); |
|
406 QVERIFY(three != 0); |
|
407 QCOMPARE(three->x(), -100.0); |
|
408 QCOMPARE(three->y(), -100.0); |
|
409 |
|
410 QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four"); |
|
411 QVERIFY(four != 0); |
|
412 QCOMPARE(four->x(), -100.0); |
|
413 QCOMPARE(four->y(), -100.0); |
|
414 |
|
415 QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five"); |
|
416 QVERIFY(five != 0); |
|
417 QCOMPARE(five->x(), -100.0); |
|
418 QCOMPARE(five->y(), -100.0); |
|
419 |
|
420 QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid"); |
|
421 QVERIFY(grid); |
|
422 QCOMPARE(grid->width(), 150.0); |
|
423 QCOMPARE(grid->height(), 100.0); |
|
424 |
|
425 //QTRY_COMPARE used instead of waiting for the expected time of animation completion |
|
426 //Note that this means the duration of the animation is NOT tested |
|
427 |
|
428 QTRY_COMPARE(one->y(), 0.0); |
|
429 QTRY_COMPARE(one->x(), 0.0); |
|
430 QTRY_COMPARE(two->opacity(), 0.0); |
|
431 QTRY_COMPARE(two->y(), -100.0); |
|
432 QTRY_COMPARE(two->x(), -100.0); |
|
433 QTRY_COMPARE(three->y(), 0.0); |
|
434 QTRY_COMPARE(three->x(), 50.0); |
|
435 QTRY_COMPARE(four->y(), 0.0); |
|
436 QTRY_COMPARE(four->x(), 100.0); |
|
437 QTRY_COMPARE(five->y(), 50.0); |
|
438 QTRY_COMPARE(five->x(), 0.0); |
|
439 |
|
440 //Add 'two' |
|
441 two->setOpacity(1.0); |
|
442 QCOMPARE(two->opacity(), 1.0); |
|
443 QCOMPARE(grid->width(), 150.0); |
|
444 QCOMPARE(grid->height(), 100.0); |
|
445 QTest::qWait(0);//Let the animation start |
|
446 QCOMPARE(two->x(), -100.0); |
|
447 QCOMPARE(two->y(), -100.0); |
|
448 QCOMPARE(one->x(), 0.0); |
|
449 QCOMPARE(one->y(), 0.0); |
|
450 QCOMPARE(three->x(), 50.0); |
|
451 QCOMPARE(three->y(), 0.0); |
|
452 QCOMPARE(four->x(), 100.0); |
|
453 QCOMPARE(four->y(), 0.0); |
|
454 QCOMPARE(five->x(), 0.0); |
|
455 QCOMPARE(five->y(), 50.0); |
|
456 //Let the animation complete |
|
457 QTRY_COMPARE(two->x(), 50.0); |
|
458 QTRY_COMPARE(two->y(), 0.0); |
|
459 QTRY_COMPARE(one->x(), 0.0); |
|
460 QTRY_COMPARE(one->y(), 0.0); |
|
461 QTRY_COMPARE(three->x(), 100.0); |
|
462 QTRY_COMPARE(three->y(), 0.0); |
|
463 QTRY_COMPARE(four->x(), 0.0); |
|
464 QTRY_COMPARE(four->y(), 50.0); |
|
465 QTRY_COMPARE(five->x(), 50.0); |
|
466 QTRY_COMPARE(five->y(), 50.0); |
|
467 |
|
468 delete canvas; |
|
469 } |
|
470 |
|
471 void tst_QDeclarativePositioners::test_grid_zero_columns() |
|
472 { |
|
473 QDeclarativeView *canvas = createView(SRCDIR "/data/gridzerocolumns.qml"); |
|
474 |
|
475 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one"); |
|
476 QVERIFY(one != 0); |
|
477 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two"); |
|
478 QVERIFY(two != 0); |
|
479 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three"); |
|
480 QVERIFY(three != 0); |
|
481 QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four"); |
|
482 QVERIFY(four != 0); |
|
483 QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five"); |
|
484 QVERIFY(five != 0); |
|
485 |
|
486 QCOMPARE(one->x(), 0.0); |
|
487 QCOMPARE(one->y(), 0.0); |
|
488 QCOMPARE(two->x(), 50.0); |
|
489 QCOMPARE(two->y(), 0.0); |
|
490 QCOMPARE(three->x(), 70.0); |
|
491 QCOMPARE(three->y(), 0.0); |
|
492 QCOMPARE(four->x(), 120.0); |
|
493 QCOMPARE(four->y(), 0.0); |
|
494 QCOMPARE(five->x(), 0.0); |
|
495 QCOMPARE(five->y(), 50.0); |
|
496 |
|
497 QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid"); |
|
498 QCOMPARE(grid->width(), 170.0); |
|
499 QCOMPARE(grid->height(), 60.0); |
|
500 |
|
501 delete canvas; |
|
502 } |
|
503 |
|
504 void tst_QDeclarativePositioners::test_propertychanges() |
|
505 { |
|
506 QDeclarativeView *canvas = createView(SRCDIR "/data/propertychangestest.qml"); |
|
507 |
|
508 QDeclarativeGrid *grid = qobject_cast<QDeclarativeGrid*>(canvas->rootObject()); |
|
509 QVERIFY(grid != 0); |
|
510 QDeclarativeTransition *rowTransition = canvas->rootObject()->findChild<QDeclarativeTransition*>("rowTransition"); |
|
511 QDeclarativeTransition *columnTransition = canvas->rootObject()->findChild<QDeclarativeTransition*>("columnTransition"); |
|
512 |
|
513 QSignalSpy addSpy(grid, SIGNAL(addChanged())); |
|
514 QSignalSpy moveSpy(grid, SIGNAL(moveChanged())); |
|
515 QSignalSpy columnsSpy(grid, SIGNAL(columnsChanged())); |
|
516 QSignalSpy rowsSpy(grid, SIGNAL(rowsChanged())); |
|
517 |
|
518 QVERIFY(grid); |
|
519 QVERIFY(rowTransition); |
|
520 QVERIFY(columnTransition); |
|
521 QCOMPARE(grid->add(), columnTransition); |
|
522 QCOMPARE(grid->move(), columnTransition); |
|
523 QCOMPARE(grid->columns(), 4); |
|
524 QCOMPARE(grid->rows(), -1); |
|
525 |
|
526 grid->setAdd(rowTransition); |
|
527 grid->setMove(rowTransition); |
|
528 QCOMPARE(grid->add(), rowTransition); |
|
529 QCOMPARE(grid->move(), rowTransition); |
|
530 QCOMPARE(addSpy.count(),1); |
|
531 QCOMPARE(moveSpy.count(),1); |
|
532 |
|
533 grid->setAdd(rowTransition); |
|
534 grid->setMove(rowTransition); |
|
535 QCOMPARE(addSpy.count(),1); |
|
536 QCOMPARE(moveSpy.count(),1); |
|
537 |
|
538 grid->setAdd(0); |
|
539 grid->setMove(0); |
|
540 QCOMPARE(addSpy.count(),2); |
|
541 QCOMPARE(moveSpy.count(),2); |
|
542 |
|
543 grid->setColumns(-1); |
|
544 grid->setRows(3); |
|
545 QCOMPARE(grid->columns(), -1); |
|
546 QCOMPARE(grid->rows(), 3); |
|
547 QCOMPARE(columnsSpy.count(),1); |
|
548 QCOMPARE(rowsSpy.count(),1); |
|
549 |
|
550 grid->setColumns(-1); |
|
551 grid->setRows(3); |
|
552 QCOMPARE(columnsSpy.count(),1); |
|
553 QCOMPARE(rowsSpy.count(),1); |
|
554 |
|
555 grid->setColumns(2); |
|
556 grid->setRows(2); |
|
557 QCOMPARE(columnsSpy.count(),2); |
|
558 QCOMPARE(rowsSpy.count(),2); |
|
559 |
|
560 delete canvas; |
|
561 } |
|
562 |
|
563 void tst_QDeclarativePositioners::test_repeater() |
|
564 { |
|
565 QDeclarativeView *canvas = createView(SRCDIR "/data/repeatertest.qml"); |
|
566 |
|
567 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one"); |
|
568 QVERIFY(one != 0); |
|
569 |
|
570 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two"); |
|
571 QVERIFY(two != 0); |
|
572 |
|
573 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three"); |
|
574 QVERIFY(three != 0); |
|
575 |
|
576 QCOMPARE(one->x(), 0.0); |
|
577 QCOMPARE(one->y(), 0.0); |
|
578 QCOMPARE(two->x(), 50.0); |
|
579 QCOMPARE(two->y(), 0.0); |
|
580 QCOMPARE(three->x(), 100.0); |
|
581 QCOMPARE(three->y(), 0.0); |
|
582 |
|
583 delete canvas; |
|
584 } |
|
585 |
|
586 void tst_QDeclarativePositioners::test_flow() |
|
587 { |
|
588 QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest.qml"); |
|
589 |
|
590 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one"); |
|
591 QVERIFY(one != 0); |
|
592 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two"); |
|
593 QVERIFY(two != 0); |
|
594 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three"); |
|
595 QVERIFY(three != 0); |
|
596 QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four"); |
|
597 QVERIFY(four != 0); |
|
598 QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five"); |
|
599 QVERIFY(five != 0); |
|
600 |
|
601 QCOMPARE(one->x(), 0.0); |
|
602 QCOMPARE(one->y(), 0.0); |
|
603 QCOMPARE(two->x(), 50.0); |
|
604 QCOMPARE(two->y(), 0.0); |
|
605 QCOMPARE(three->x(), 0.0); |
|
606 QCOMPARE(three->y(), 50.0); |
|
607 QCOMPARE(four->x(), 0.0); |
|
608 QCOMPARE(four->y(), 70.0); |
|
609 QCOMPARE(five->x(), 50.0); |
|
610 QCOMPARE(five->y(), 70.0); |
|
611 |
|
612 QDeclarativeItem *flow = canvas->rootObject()->findChild<QDeclarativeItem*>("flow"); |
|
613 QVERIFY(flow); |
|
614 QCOMPARE(flow->width(), 90.0); |
|
615 QCOMPARE(flow->height(), 120.0); |
|
616 |
|
617 delete canvas; |
|
618 } |
|
619 |
|
620 void tst_QDeclarativePositioners::test_flow_resize() |
|
621 { |
|
622 QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest.qml"); |
|
623 |
|
624 QDeclarativeItem *root = qobject_cast<QDeclarativeItem*>(canvas->rootObject()); |
|
625 QVERIFY(root); |
|
626 root->setWidth(125); |
|
627 |
|
628 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one"); |
|
629 QVERIFY(one != 0); |
|
630 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two"); |
|
631 QVERIFY(two != 0); |
|
632 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three"); |
|
633 QVERIFY(three != 0); |
|
634 QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four"); |
|
635 QVERIFY(four != 0); |
|
636 QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five"); |
|
637 QVERIFY(five != 0); |
|
638 |
|
639 QCOMPARE(one->x(), 0.0); |
|
640 QCOMPARE(one->y(), 0.0); |
|
641 QCOMPARE(two->x(), 50.0); |
|
642 QCOMPARE(two->y(), 0.0); |
|
643 QCOMPARE(three->x(), 70.0); |
|
644 QCOMPARE(three->y(), 0.0); |
|
645 QCOMPARE(four->x(), 0.0); |
|
646 QCOMPARE(four->y(), 50.0); |
|
647 QCOMPARE(five->x(), 50.0); |
|
648 QCOMPARE(five->y(), 50.0); |
|
649 |
|
650 delete canvas; |
|
651 } |
|
652 |
|
653 QString warningMessage; |
|
654 |
|
655 void interceptWarnings(QtMsgType type, const char *msg) |
|
656 { |
|
657 Q_UNUSED( type ); |
|
658 warningMessage = msg; |
|
659 } |
|
660 |
|
661 void tst_QDeclarativePositioners::test_conflictinganchors() |
|
662 { |
|
663 qInstallMsgHandler(interceptWarnings); |
|
664 QDeclarativeEngine engine; |
|
665 QDeclarativeComponent component(&engine); |
|
666 |
|
667 component.setData("import Qt 4.7\nColumn { Item {} }", QUrl::fromLocalFile("")); |
|
668 QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create()); |
|
669 QVERIFY(item); |
|
670 QVERIFY(warningMessage.isEmpty()); |
|
671 |
|
672 component.setData("import Qt 4.7\nRow { Item {} }", QUrl::fromLocalFile("")); |
|
673 item = qobject_cast<QDeclarativeItem*>(component.create()); |
|
674 QVERIFY(item); |
|
675 QVERIFY(warningMessage.isEmpty()); |
|
676 |
|
677 component.setData("import Qt 4.7\nGrid { Item {} }", QUrl::fromLocalFile("")); |
|
678 item = qobject_cast<QDeclarativeItem*>(component.create()); |
|
679 QVERIFY(item); |
|
680 QVERIFY(warningMessage.isEmpty()); |
|
681 |
|
682 component.setData("import Qt 4.7\nFlow { Item {} }", QUrl::fromLocalFile("")); |
|
683 item = qobject_cast<QDeclarativeItem*>(component.create()); |
|
684 QVERIFY(item); |
|
685 QVERIFY(warningMessage.isEmpty()); |
|
686 |
|
687 component.setData("import Qt 4.7\nColumn { Item { anchors.top: parent.top } }", QUrl::fromLocalFile("")); |
|
688 item = qobject_cast<QDeclarativeItem*>(component.create()); |
|
689 QVERIFY(item); |
|
690 QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column")); |
|
691 warningMessage.clear(); |
|
692 |
|
693 component.setData("import Qt 4.7\nColumn { Item { anchors.centerIn: parent } }", QUrl::fromLocalFile("")); |
|
694 item = qobject_cast<QDeclarativeItem*>(component.create()); |
|
695 QVERIFY(item); |
|
696 QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column")); |
|
697 warningMessage.clear(); |
|
698 |
|
699 component.setData("import Qt 4.7\nColumn { Item { anchors.left: parent.left } }", QUrl::fromLocalFile("")); |
|
700 item = qobject_cast<QDeclarativeItem*>(component.create()); |
|
701 QVERIFY(item); |
|
702 QVERIFY(warningMessage.isEmpty()); |
|
703 warningMessage.clear(); |
|
704 |
|
705 component.setData("import Qt 4.7\nRow { Item { anchors.left: parent.left } }", QUrl::fromLocalFile("")); |
|
706 item = qobject_cast<QDeclarativeItem*>(component.create()); |
|
707 QVERIFY(item); |
|
708 QCOMPARE(warningMessage, QString("file::2:1: QML Row: Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row")); |
|
709 warningMessage.clear(); |
|
710 |
|
711 component.setData("import Qt 4.7\nRow { Item { anchors.fill: parent } }", QUrl::fromLocalFile("")); |
|
712 item = qobject_cast<QDeclarativeItem*>(component.create()); |
|
713 QVERIFY(item); |
|
714 QCOMPARE(warningMessage, QString("file::2:1: QML Row: Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row")); |
|
715 warningMessage.clear(); |
|
716 |
|
717 component.setData("import Qt 4.7\nRow { Item { anchors.top: parent.top } }", QUrl::fromLocalFile("")); |
|
718 item = qobject_cast<QDeclarativeItem*>(component.create()); |
|
719 QVERIFY(item); |
|
720 QVERIFY(warningMessage.isEmpty()); |
|
721 warningMessage.clear(); |
|
722 |
|
723 component.setData("import Qt 4.7\nGrid { Item { anchors.horizontalCenter: parent.horizontalCenter } }", QUrl::fromLocalFile("")); |
|
724 item = qobject_cast<QDeclarativeItem*>(component.create()); |
|
725 QVERIFY(item); |
|
726 QCOMPARE(warningMessage, QString("file::2:1: QML Grid: Cannot specify anchors for items inside Grid")); |
|
727 warningMessage.clear(); |
|
728 |
|
729 component.setData("import Qt 4.7\nGrid { Item { anchors.centerIn: parent } }", QUrl::fromLocalFile("")); |
|
730 item = qobject_cast<QDeclarativeItem*>(component.create()); |
|
731 QVERIFY(item); |
|
732 QCOMPARE(warningMessage, QString("file::2:1: QML Grid: Cannot specify anchors for items inside Grid")); |
|
733 warningMessage.clear(); |
|
734 |
|
735 component.setData("import Qt 4.7\nFlow { Item { anchors.verticalCenter: parent.verticalCenter } }", QUrl::fromLocalFile("")); |
|
736 item = qobject_cast<QDeclarativeItem*>(component.create()); |
|
737 QVERIFY(item); |
|
738 QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow")); |
|
739 |
|
740 component.setData("import Qt 4.7\nFlow { Item { anchors.fill: parent } }", QUrl::fromLocalFile("")); |
|
741 item = qobject_cast<QDeclarativeItem*>(component.create()); |
|
742 QVERIFY(item); |
|
743 QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow")); |
|
744 } |
|
745 |
|
746 QDeclarativeView *tst_QDeclarativePositioners::createView(const QString &filename) |
|
747 { |
|
748 QDeclarativeView *canvas = new QDeclarativeView(0); |
|
749 |
|
750 canvas->setSource(QUrl::fromLocalFile(filename)); |
|
751 |
|
752 return canvas; |
|
753 } |
|
754 |
|
755 |
|
756 QTEST_MAIN(tst_QDeclarativePositioners) |
|
757 |
|
758 #include "tst_qdeclarativepositioners.moc" |