6e7aca96e8f0d01bdcb34ba59f8f17b9a5ffc155
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / qdeclarativevaluetypes / tst_qdeclarativevaluetypes.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
42 #include <qtest.h>
43 #include <QDeclarativeEngine>
44 #include <QDeclarativeComponent>
45 #include <QDebug>
46 #include <private/qdeclarativevaluetype_p.h>
47 #include "../../shared/util.h"
48 #include "testtypes.h"
49
50 QT_BEGIN_NAMESPACE
51 extern int qt_defaultDpi();
52 QT_END_NAMESPACE
53
54 class tst_qdeclarativevaluetypes : public QDeclarativeDataTest
55 {
56     Q_OBJECT
57 public:
58     tst_qdeclarativevaluetypes() {}
59
60 private slots:
61     void initTestCase();
62
63     void point();
64     void pointf();
65     void size();
66     void sizef();
67     void sizereadonly();
68     void rect();
69     void rectf();
70     void vector2d();
71     void vector3d();
72     void vector4d();
73     void quaternion();
74     void matrix4x4();
75     void font();
76     void color();
77     void variant();
78
79     void bindingAssignment();
80     void bindingRead();
81     void staticAssignment();
82     void scriptAccess();
83     void autoBindingRemoval();
84     void valueSources();
85     void valueInterceptors();
86     void bindingConflict();
87     void deletedObject();
88     void bindingVariantCopy();
89     void scriptVariantCopy();
90     void cppClasses();
91     void enums();
92     void conflictingBindings();
93     void returnValues();
94     void varAssignment();
95     void bindingsSpliceCorrectly();
96
97 private:
98     QDeclarativeEngine engine;
99 };
100
101 void tst_qdeclarativevaluetypes::initTestCase()
102 {
103     QDeclarativeDataTest::initTestCase();
104     registerTypes();
105 }
106
107 void tst_qdeclarativevaluetypes::point()
108 {
109     {
110         QDeclarativeComponent component(&engine, testFileUrl("point_read.qml"));
111         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
112         QVERIFY(object != 0);
113
114         QCOMPARE(object->property("p_x").toInt(), 10);
115         QCOMPARE(object->property("p_y").toInt(), 4);
116         QCOMPARE(object->property("copy"), QVariant(QPoint(10, 4)));
117
118         delete object;
119     }
120
121     {
122         QDeclarativeComponent component(&engine, testFileUrl("point_write.qml"));
123         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
124         QVERIFY(object != 0);
125
126         QCOMPARE(object->point(), QPoint(11, 12));
127
128         delete object;
129     }
130
131     {
132         QDeclarativeComponent component(&engine, testFileUrl("point_compare.qml"));
133         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
134         QVERIFY(object != 0);
135
136         QString tostring = QLatin1String("QPoint(10, 4)");
137         QCOMPARE(object->property("tostring").toString(), tostring);
138         QCOMPARE(object->property("equalsString").toBool(), true);
139         QCOMPARE(object->property("equalsColor").toBool(), false);
140         QCOMPARE(object->property("equalsVector3d").toBool(), false);
141         QCOMPARE(object->property("equalsSize").toBool(), false);
142         QCOMPARE(object->property("equalsPoint").toBool(), true);
143         QCOMPARE(object->property("equalsRect").toBool(), false);
144         QCOMPARE(object->property("equalsSelf").toBool(), true);
145         QCOMPARE(object->property("equalsOther").toBool(), false);
146         QCOMPARE(object->property("pointEqualsPointf").toBool(), true);
147
148         delete object;
149     }
150 }
151
152 void tst_qdeclarativevaluetypes::pointf()
153 {
154     {
155         QDeclarativeComponent component(&engine, testFileUrl("pointf_read.qml"));
156         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
157         QVERIFY(object != 0);
158
159         QCOMPARE(float(object->property("p_x").toDouble()), float(11.3));
160         QCOMPARE(float(object->property("p_y").toDouble()), float(-10.9));
161         QCOMPARE(object->property("copy"), QVariant(QPointF(11.3, -10.9)));
162
163         delete object;
164     }
165
166     {
167         QDeclarativeComponent component(&engine, testFileUrl("pointf_write.qml"));
168         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
169         QVERIFY(object != 0);
170
171         QCOMPARE(object->pointf(), QPointF(6.8, 9.3));
172
173         delete object;
174     }
175
176     {
177         QDeclarativeComponent component(&engine, testFileUrl("pointf_compare.qml"));
178         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
179         QVERIFY(object != 0);
180
181         QString tostring = QLatin1String("QPointF(11.3, -10.9)");
182         QCOMPARE(object->property("tostring").toString(), tostring);
183         QCOMPARE(object->property("equalsString").toBool(), true);
184         QCOMPARE(object->property("equalsColor").toBool(), false);
185         QCOMPARE(object->property("equalsVector3d").toBool(), false);
186         QCOMPARE(object->property("equalsSize").toBool(), false);
187         QCOMPARE(object->property("equalsPoint").toBool(), true);
188         QCOMPARE(object->property("equalsRect").toBool(), false);
189         QCOMPARE(object->property("equalsSelf").toBool(), true);
190         QCOMPARE(object->property("equalsOther").toBool(), false);
191         QCOMPARE(object->property("pointfEqualsPoint").toBool(), true);
192
193         delete object;
194     }
195 }
196
197 void tst_qdeclarativevaluetypes::size()
198 {
199     {
200         QDeclarativeComponent component(&engine, testFileUrl("size_read.qml"));
201         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
202         QVERIFY(object != 0);
203
204         QCOMPARE(object->property("s_width").toInt(), 1912);
205         QCOMPARE(object->property("s_height").toInt(), 1913);
206         QCOMPARE(object->property("copy"), QVariant(QSize(1912, 1913)));
207
208         delete object;
209     }
210
211     {
212         QDeclarativeComponent component(&engine, testFileUrl("size_write.qml"));
213         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
214         QVERIFY(object != 0);
215
216         QCOMPARE(object->size(), QSize(13, 88));
217
218         delete object;
219     }
220
221     {
222         QDeclarativeComponent component(&engine, testFileUrl("size_compare.qml"));
223         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
224         QVERIFY(object != 0);
225
226         QString tostring = QLatin1String("QSize(1912, 1913)");
227         QCOMPARE(object->property("tostring").toString(), tostring);
228         QCOMPARE(object->property("equalsString").toBool(), true);
229         QCOMPARE(object->property("equalsColor").toBool(), false);
230         QCOMPARE(object->property("equalsVector3d").toBool(), false);
231         QCOMPARE(object->property("equalsSize").toBool(), true);
232         QCOMPARE(object->property("equalsPoint").toBool(), false);
233         QCOMPARE(object->property("equalsRect").toBool(), false);
234         QCOMPARE(object->property("equalsSelf").toBool(), true);
235         QCOMPARE(object->property("equalsOther").toBool(), false);
236         QCOMPARE(object->property("sizeEqualsSizef").toBool(), true);
237
238         delete object;
239     }
240 }
241
242 void tst_qdeclarativevaluetypes::sizef()
243 {
244     {
245         QDeclarativeComponent component(&engine, testFileUrl("sizef_read.qml"));
246         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
247         QVERIFY(object != 0);
248
249         QCOMPARE(float(object->property("s_width").toDouble()), float(0.1));
250         QCOMPARE(float(object->property("s_height").toDouble()), float(100923.2));
251         QCOMPARE(object->property("copy"), QVariant(QSizeF(0.1, 100923.2)));
252
253         delete object;
254     }
255
256     {
257         QDeclarativeComponent component(&engine, testFileUrl("sizef_write.qml"));
258         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
259         QVERIFY(object != 0);
260
261         QCOMPARE(object->sizef(), QSizeF(44.3, 92.8));
262
263         delete object;
264     }
265
266     {
267         QDeclarativeComponent component(&engine, testFileUrl("sizef_compare.qml"));
268         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
269         QVERIFY(object != 0);
270
271         QString tostring = QLatin1String("QSizeF(0.1, 100923)");
272         QCOMPARE(object->property("tostring").toString(), tostring);
273         QCOMPARE(object->property("equalsString").toBool(), true);
274         QCOMPARE(object->property("equalsColor").toBool(), false);
275         QCOMPARE(object->property("equalsVector3d").toBool(), false);
276         QCOMPARE(object->property("equalsSize").toBool(), true);
277         QCOMPARE(object->property("equalsPoint").toBool(), false);
278         QCOMPARE(object->property("equalsRect").toBool(), false);
279         QCOMPARE(object->property("equalsSelf").toBool(), true);
280         QCOMPARE(object->property("equalsOther").toBool(), false);
281         QCOMPARE(object->property("sizefEqualsSize").toBool(), true);
282
283         delete object;
284     }
285 }
286
287 void tst_qdeclarativevaluetypes::variant()
288 {
289     QDeclarativeComponent component(&engine, testFileUrl("variant_read.qml"));
290     MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
291     QVERIFY(object != 0);
292
293     QCOMPARE(float(object->property("s_width").toDouble()), float(0.1));
294     QCOMPARE(float(object->property("s_height").toDouble()), float(100923.2));
295     QCOMPARE(object->property("copy"), QVariant(QSizeF(0.1, 100923.2)));
296
297     delete object;
298 }
299
300 void tst_qdeclarativevaluetypes::sizereadonly()
301 {
302     {
303         QDeclarativeComponent component(&engine, testFileUrl("sizereadonly_read.qml"));
304         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
305         QVERIFY(object != 0);
306
307         QCOMPARE(object->property("s_width").toInt(), 1912);
308         QCOMPARE(object->property("s_height").toInt(), 1913);
309         QCOMPARE(object->property("copy"), QVariant(QSize(1912, 1913)));
310
311         delete object;
312     }
313
314     {
315         QDeclarativeComponent component(&engine, testFileUrl("sizereadonly_writeerror.qml"));
316         QVERIFY(component.isError());
317         QCOMPARE(component.errors().at(0).description(), QLatin1String("Invalid property assignment: \"sizereadonly\" is a read-only property"));
318     }
319
320     {
321         QDeclarativeComponent component(&engine, testFileUrl("sizereadonly_writeerror2.qml"));
322         QVERIFY(component.isError());
323         QCOMPARE(component.errors().at(0).description(), QLatin1String("Invalid property assignment: \"sizereadonly\" is a read-only property"));
324     }
325
326     {
327         QDeclarativeComponent component(&engine, testFileUrl("sizereadonly_writeerror3.qml"));
328         QVERIFY(component.isError());
329         QCOMPARE(component.errors().at(0).description(), QLatin1String("Invalid property assignment: \"sizereadonly\" is a read-only property"));
330     }
331
332     {
333         QDeclarativeComponent component(&engine, testFileUrl("sizereadonly_writeerror4.qml"));
334
335         QObject *object = component.create();
336         QVERIFY(object);
337
338         QCOMPARE(object->property("sizereadonly").toSize(), QSize(1912, 1913));
339
340         delete object;
341     }
342 }
343
344 void tst_qdeclarativevaluetypes::rect()
345 {
346     {
347         QDeclarativeComponent component(&engine, testFileUrl("rect_read.qml"));
348         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
349         QVERIFY(object != 0);
350
351         QCOMPARE(object->property("r_x").toInt(), 2);
352         QCOMPARE(object->property("r_y").toInt(), 3);
353         QCOMPARE(object->property("r_width").toInt(), 109);
354         QCOMPARE(object->property("r_height").toInt(), 102);
355         QCOMPARE(object->property("copy"), QVariant(QRect(2, 3, 109, 102)));
356
357         delete object;
358     }
359
360     {
361         QDeclarativeComponent component(&engine, testFileUrl("rect_write.qml"));
362         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
363         QVERIFY(object != 0);
364
365         QCOMPARE(object->rect(), QRect(1234, 7, 56, 63));
366
367         delete object;
368     }
369
370     {
371         QDeclarativeComponent component(&engine, testFileUrl("rect_compare.qml"));
372         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
373         QVERIFY(object != 0);
374
375         QString tostring = QLatin1String("QRect(2, 3, 109, 102)");
376         QCOMPARE(object->property("tostring").toString(), tostring);
377         QCOMPARE(object->property("equalsString").toBool(), true);
378         QCOMPARE(object->property("equalsColor").toBool(), false);
379         QCOMPARE(object->property("equalsVector3d").toBool(), false);
380         QCOMPARE(object->property("equalsSize").toBool(), false);
381         QCOMPARE(object->property("equalsPoint").toBool(), false);
382         QCOMPARE(object->property("equalsRect").toBool(), true);
383         QCOMPARE(object->property("equalsSelf").toBool(), true);
384         QCOMPARE(object->property("equalsOther").toBool(), false);
385         QCOMPARE(object->property("rectEqualsRectf").toBool(), true);
386
387         delete object;
388     }
389 }
390
391 void tst_qdeclarativevaluetypes::rectf()
392 {
393     {
394         QDeclarativeComponent component(&engine, testFileUrl("rectf_read.qml"));
395         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
396         QVERIFY(object != 0);
397
398         QCOMPARE(float(object->property("r_x").toDouble()), float(103.8));
399         QCOMPARE(float(object->property("r_y").toDouble()), float(99.2));
400         QCOMPARE(float(object->property("r_width").toDouble()), float(88.1));
401         QCOMPARE(float(object->property("r_height").toDouble()), float(77.6));
402         QCOMPARE(object->property("copy"), QVariant(QRectF(103.8, 99.2, 88.1, 77.6)));
403
404         delete object;
405     }
406
407     {
408         QDeclarativeComponent component(&engine, testFileUrl("rectf_write.qml"));
409         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
410         QVERIFY(object != 0);
411
412         QCOMPARE(object->rectf(), QRectF(70.1, -113.2, 80924.8, 99.2));
413
414         delete object;
415     }
416
417     {
418         QDeclarativeComponent component(&engine, testFileUrl("rectf_compare.qml"));
419         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
420         QVERIFY(object != 0);
421
422         QString tostring = QLatin1String("QRectF(103.8, 99.2, 88.1, 77.6)");
423         QCOMPARE(object->property("tostring").toString(), tostring);
424         QCOMPARE(object->property("equalsString").toBool(), true);
425         QCOMPARE(object->property("equalsColor").toBool(), false);
426         QCOMPARE(object->property("equalsVector3d").toBool(), false);
427         QCOMPARE(object->property("equalsSize").toBool(), false);
428         QCOMPARE(object->property("equalsPoint").toBool(), false);
429         QCOMPARE(object->property("equalsRect").toBool(), true);
430         QCOMPARE(object->property("equalsSelf").toBool(), true);
431         QCOMPARE(object->property("equalsOther").toBool(), false);
432         QCOMPARE(object->property("rectfEqualsRect").toBool(), true);
433
434         delete object;
435     }
436 }
437
438 void tst_qdeclarativevaluetypes::vector2d()
439 {
440     {
441         QDeclarativeComponent component(&engine, testFileUrl("vector2d_read.qml"));
442         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
443         QVERIFY(object != 0);
444
445         QCOMPARE((float)object->property("v_x").toDouble(), (float)32.88);
446         QCOMPARE((float)object->property("v_y").toDouble(), (float)1.3);
447         QCOMPARE(object->property("copy"), QVariant(QVector2D(32.88, 1.3)));
448
449         delete object;
450     }
451
452     {
453         QDeclarativeComponent component(&engine, testFileUrl("vector2d_write.qml"));
454         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
455         QVERIFY(object != 0);
456
457         QCOMPARE(object->vector2(), QVector2D(-0.3, -12.9));
458
459         delete object;
460     }
461
462     {
463         QDeclarativeComponent component(&engine, testFileUrl("vector2d_compare.qml"));
464         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
465         QVERIFY(object != 0);
466
467         QString tostring = QLatin1String("QVector2D(32.88, 1.3)");
468         QCOMPARE(object->property("tostring").toString(), tostring);
469         QCOMPARE(object->property("equalsString").toBool(), true);
470         QCOMPARE(object->property("equalsColor").toBool(), false);
471         QCOMPARE(object->property("equalsVector3d").toBool(), false);
472         QCOMPARE(object->property("equalsSize").toBool(), false);
473         QCOMPARE(object->property("equalsPoint").toBool(), false);
474         QCOMPARE(object->property("equalsRect").toBool(), false);
475         QCOMPARE(object->property("equalsSelf").toBool(), true);
476
477         delete object;
478     }
479 }
480
481 void tst_qdeclarativevaluetypes::vector3d()
482 {
483     {
484         QDeclarativeComponent component(&engine, testFileUrl("vector3d_read.qml"));
485         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
486         QVERIFY(object != 0);
487
488         QCOMPARE((float)object->property("v_x").toDouble(), (float)23.88);
489         QCOMPARE((float)object->property("v_y").toDouble(), (float)3.1);
490         QCOMPARE((float)object->property("v_z").toDouble(), (float)4.3);
491         QCOMPARE(object->property("copy"), QVariant(QVector3D(23.88, 3.1, 4.3)));
492
493         delete object;
494     }
495
496     {
497         QDeclarativeComponent component(&engine, testFileUrl("vector3d_write.qml"));
498         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
499         QVERIFY(object != 0);
500
501         QCOMPARE(object->vector(), QVector3D(-0.3, -12.9, 907.4));
502
503         delete object;
504     }
505
506     {
507         QDeclarativeComponent component(&engine, testFileUrl("vector3d_compare.qml"));
508         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
509         QVERIFY(object != 0);
510
511         QString tostring = QLatin1String("QVector3D(23.88, 3.1, 4.3)");
512         QCOMPARE(object->property("tostring").toString(), tostring);
513         QCOMPARE(object->property("equalsString").toBool(), true);
514         QCOMPARE(object->property("equalsColor").toBool(), false);
515         QCOMPARE(object->property("equalsVector3d").toBool(), true);
516         QCOMPARE(object->property("equalsSize").toBool(), false);
517         QCOMPARE(object->property("equalsPoint").toBool(), false);
518         QCOMPARE(object->property("equalsRect").toBool(), false);
519         QCOMPARE(object->property("equalsSelf").toBool(), true);
520         QCOMPARE(object->property("equalsOther").toBool(), false);
521
522         delete object;
523     }
524 }
525
526 void tst_qdeclarativevaluetypes::vector4d()
527 {
528     {
529         QDeclarativeComponent component(&engine, testFileUrl("vector4d_read.qml"));
530         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
531         QVERIFY(object != 0);
532
533         QCOMPARE((float)object->property("v_x").toDouble(), (float)54.2);
534         QCOMPARE((float)object->property("v_y").toDouble(), (float)23.88);
535         QCOMPARE((float)object->property("v_z").toDouble(), (float)3.1);
536         QCOMPARE((float)object->property("v_w").toDouble(), (float)4.3);
537         QCOMPARE(object->property("copy"), QVariant(QVector4D(54.2, 23.88, 3.1, 4.3)));
538
539         delete object;
540     }
541
542     {
543         QDeclarativeComponent component(&engine, testFileUrl("vector4d_write.qml"));
544         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
545         QVERIFY(object != 0);
546
547         QCOMPARE(object->vector4(), QVector4D(-0.3, -12.9, 907.4, 88.5));
548
549         delete object;
550     }
551
552     {
553         QDeclarativeComponent component(&engine, testFileUrl("vector4d_compare.qml"));
554         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
555         QVERIFY(object != 0);
556
557         QString tostring = QLatin1String("QVector4D(54.2, 23.88, 3.1, 4.3)");
558         QCOMPARE(object->property("tostring").toString(), tostring);
559         QCOMPARE(object->property("equalsString").toBool(), true);
560         QCOMPARE(object->property("equalsColor").toBool(), false);
561         QCOMPARE(object->property("equalsVector3d").toBool(), false);
562         QCOMPARE(object->property("equalsSize").toBool(), false);
563         QCOMPARE(object->property("equalsPoint").toBool(), false);
564         QCOMPARE(object->property("equalsRect").toBool(), false);
565         QCOMPARE(object->property("equalsSelf").toBool(), true);
566
567         delete object;
568     }
569 }
570
571 void tst_qdeclarativevaluetypes::quaternion()
572 {
573     {
574         QDeclarativeComponent component(&engine, testFileUrl("quaternion_read.qml"));
575         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
576         QVERIFY(object != 0);
577
578         QCOMPARE((float)object->property("v_scalar").toDouble(), (float)4.3);
579         QCOMPARE((float)object->property("v_x").toDouble(), (float)54.2);
580         QCOMPARE((float)object->property("v_y").toDouble(), (float)23.88);
581         QCOMPARE((float)object->property("v_z").toDouble(), (float)3.1);
582         QCOMPARE(object->property("copy"), QVariant(QQuaternion(4.3, 54.2, 23.88, 3.1)));
583
584         delete object;
585     }
586
587     {
588         QDeclarativeComponent component(&engine, testFileUrl("quaternion_write.qml"));
589         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
590         QVERIFY(object != 0);
591
592         QCOMPARE(object->quaternion(), QQuaternion(88.5, -0.3, -12.9, 907.4));
593
594         delete object;
595     }
596
597     {
598         QDeclarativeComponent component(&engine, testFileUrl("quaternion_compare.qml"));
599         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
600         QVERIFY(object != 0);
601
602         QString tostring = QLatin1String("QQuaternion(4.3, 54.2, 23.88, 3.1)");
603         QCOMPARE(object->property("tostring").toString(), tostring);
604         QCOMPARE(object->property("equalsString").toBool(), true);
605         QCOMPARE(object->property("equalsColor").toBool(), false);
606         QCOMPARE(object->property("equalsVector3d").toBool(), false);
607         QCOMPARE(object->property("equalsSize").toBool(), false);
608         QCOMPARE(object->property("equalsPoint").toBool(), false);
609         QCOMPARE(object->property("equalsRect").toBool(), false);
610         QCOMPARE(object->property("equalsSelf").toBool(), true);
611
612         delete object;
613     }
614 }
615
616 void tst_qdeclarativevaluetypes::matrix4x4()
617 {
618     {
619         QDeclarativeComponent component(&engine, testFileUrl("matrix4x4_read.qml"));
620         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
621         QVERIFY(object != 0);
622
623         QCOMPARE((float)object->property("v_m11").toDouble(), (float)1);
624         QCOMPARE((float)object->property("v_m12").toDouble(), (float)2);
625         QCOMPARE((float)object->property("v_m13").toDouble(), (float)3);
626         QCOMPARE((float)object->property("v_m14").toDouble(), (float)4);
627         QCOMPARE((float)object->property("v_m21").toDouble(), (float)5);
628         QCOMPARE((float)object->property("v_m22").toDouble(), (float)6);
629         QCOMPARE((float)object->property("v_m23").toDouble(), (float)7);
630         QCOMPARE((float)object->property("v_m24").toDouble(), (float)8);
631         QCOMPARE((float)object->property("v_m31").toDouble(), (float)9);
632         QCOMPARE((float)object->property("v_m32").toDouble(), (float)10);
633         QCOMPARE((float)object->property("v_m33").toDouble(), (float)11);
634         QCOMPARE((float)object->property("v_m34").toDouble(), (float)12);
635         QCOMPARE((float)object->property("v_m41").toDouble(), (float)13);
636         QCOMPARE((float)object->property("v_m42").toDouble(), (float)14);
637         QCOMPARE((float)object->property("v_m43").toDouble(), (float)15);
638         QCOMPARE((float)object->property("v_m44").toDouble(), (float)16);
639         QCOMPARE(object->property("copy"),
640                  QVariant(QMatrix4x4(1, 2, 3, 4,
641                                      5, 6, 7, 8,
642                                      9, 10, 11, 12,
643                                      13, 14, 15, 16)));
644
645         delete object;
646     }
647
648     {
649         QDeclarativeComponent component(&engine, testFileUrl("matrix4x4_write.qml"));
650         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
651         QVERIFY(object != 0);
652
653         QCOMPARE(object->matrix(), QMatrix4x4(11, 12, 13, 14,
654                                               21, 22, 23, 24,
655                                               31, 32, 33, 34,
656                                               41, 42, 43, 44));
657
658         delete object;
659     }
660
661     {
662         QDeclarativeComponent component(&engine, testFileUrl("matrix4x4_compare.qml"));
663         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
664         QVERIFY(object != 0);
665
666         QString tostring = QLatin1String("QMatrix4x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)");
667         QCOMPARE(object->property("tostring").toString(), tostring);
668         QCOMPARE(object->property("equalsString").toBool(), true);
669         QCOMPARE(object->property("equalsColor").toBool(), false);
670         QCOMPARE(object->property("equalsVector3d").toBool(), false);
671         QCOMPARE(object->property("equalsSize").toBool(), false);
672         QCOMPARE(object->property("equalsPoint").toBool(), false);
673         QCOMPARE(object->property("equalsRect").toBool(), false);
674         QCOMPARE(object->property("equalsSelf").toBool(), true);
675
676         delete object;
677     }
678 }
679
680 void tst_qdeclarativevaluetypes::font()
681 {
682     {
683         QDeclarativeComponent component(&engine, testFileUrl("font_read.qml"));
684         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
685         QVERIFY(object != 0);
686
687         QCOMPARE(object->property("f_family").toString(), object->font().family());
688         QCOMPARE(object->property("f_bold").toBool(), object->font().bold());
689         QCOMPARE(object->property("f_weight").toInt(), object->font().weight());
690         QCOMPARE(object->property("f_italic").toBool(), object->font().italic());
691         QCOMPARE(object->property("f_underline").toBool(), object->font().underline());
692         QCOMPARE(object->property("f_overline").toBool(), object->font().overline());
693         QCOMPARE(object->property("f_strikeout").toBool(), object->font().strikeOut());
694         QCOMPARE(object->property("f_pointSize").toDouble(), object->font().pointSizeF());
695         QCOMPARE(object->property("f_pixelSize").toInt(), int((object->font().pointSizeF() * qt_defaultDpi()) / qreal(72.)));
696         QCOMPARE(object->property("f_capitalization").toInt(), (int)object->font().capitalization());
697         QCOMPARE(object->property("f_letterSpacing").toDouble(), object->font().letterSpacing());
698         QCOMPARE(object->property("f_wordSpacing").toDouble(), object->font().wordSpacing());
699
700         QCOMPARE(object->property("copy"), QVariant(object->font()));
701
702         delete object;
703     }
704
705     {
706         QDeclarativeComponent component(&engine, testFileUrl("font_write.qml"));
707         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
708         QVERIFY(object != 0);
709
710         QFont font;
711         font.setFamily("Helvetica");
712         font.setBold(false);
713         font.setWeight(QFont::Normal);
714         font.setItalic(false);
715         font.setUnderline(false);
716         font.setStrikeOut(false);
717         font.setPointSize(15);
718         font.setCapitalization(QFont::AllLowercase);
719         font.setLetterSpacing(QFont::AbsoluteSpacing, 9.7);
720         font.setWordSpacing(11.2);
721
722         QFont f = object->font();
723         QCOMPARE(f.family(), font.family());
724         QCOMPARE(f.bold(), font.bold());
725         QCOMPARE(f.weight(), font.weight());
726         QCOMPARE(f.italic(), font.italic());
727         QCOMPARE(f.underline(), font.underline());
728         QCOMPARE(f.strikeOut(), font.strikeOut());
729         QCOMPARE(f.pointSize(), font.pointSize());
730         QCOMPARE(f.capitalization(), font.capitalization());
731         QCOMPARE(f.letterSpacing(), font.letterSpacing());
732         QCOMPARE(f.wordSpacing(), font.wordSpacing());
733
734         delete object;
735     }
736
737     // Test pixelSize
738     {
739         QDeclarativeComponent component(&engine, testFileUrl("font_write.2.qml"));
740         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
741         QVERIFY(object != 0);
742
743         QCOMPARE(object->font().pixelSize(), 10);
744
745         delete object;
746     }
747
748     // Test pixelSize and pointSize
749     {
750         QDeclarativeComponent component(&engine, testFileUrl("font_write.3.qml"));
751         QTest::ignoreMessage(QtWarningMsg, "Both point size and pixel size set. Using pixel size. ");
752         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
753         QVERIFY(object != 0);
754
755         QCOMPARE(object->font().pixelSize(), 10);
756
757         delete object;
758     }
759     {
760         QDeclarativeComponent component(&engine, testFileUrl("font_write.4.qml"));
761         QTest::ignoreMessage(QtWarningMsg, "Both point size and pixel size set. Using pixel size. ");
762         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
763         QVERIFY(object != 0);
764
765         QCOMPARE(object->font().pixelSize(), 10);
766
767         delete object;
768     }
769     {
770         QDeclarativeComponent component(&engine, testFileUrl("font_write.5.qml"));
771         QObject *object = qobject_cast<QObject *>(component.create());
772         QVERIFY(object != 0);
773         MyTypeObject *object1 = object->findChild<MyTypeObject *>("object1");
774         QVERIFY(object1 != 0);
775         MyTypeObject *object2 = object->findChild<MyTypeObject *>("object2");
776         QVERIFY(object2 != 0);
777
778         QCOMPARE(object1->font().pixelSize(), 19);
779         QCOMPARE(object2->font().pointSize(), 14);
780
781         delete object;
782     }
783
784     {
785         QDeclarativeComponent component(&engine, testFileUrl("font_compare.qml"));
786         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
787         QVERIFY(object != 0);
788
789         QString tostring = QLatin1String("QFont(") + object->font().toString() + QLatin1Char(')');
790         QCOMPARE(object->property("tostring").toString(), tostring);
791         QCOMPARE(object->property("equalsString").toBool(), true);
792         QCOMPARE(object->property("equalsColor").toBool(), false);
793         QCOMPARE(object->property("equalsVector3d").toBool(), false);
794         QCOMPARE(object->property("equalsSize").toBool(), false);
795         QCOMPARE(object->property("equalsPoint").toBool(), false);
796         QCOMPARE(object->property("equalsRect").toBool(), false);
797         QCOMPARE(object->property("equalsSelf").toBool(), true);
798
799         delete object;
800     }
801 }
802
803 void tst_qdeclarativevaluetypes::color()
804 {
805     {
806         QDeclarativeComponent component(&engine, testFileUrl("color_read.qml"));
807         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
808         QVERIFY(object != 0);
809
810         QCOMPARE((float)object->property("v_r").toDouble(), (float)0.2);
811         QCOMPARE((float)object->property("v_g").toDouble(), (float)0.88);
812         QCOMPARE((float)object->property("v_b").toDouble(), (float)0.6);
813         QCOMPARE((float)object->property("v_a").toDouble(), (float)0.34);
814         QColor comparison;
815         comparison.setRedF(0.2);
816         comparison.setGreenF(0.88);
817         comparison.setBlueF(0.6);
818         comparison.setAlphaF(0.34);
819         QCOMPARE(object->property("copy"), QVariant(comparison));
820
821         delete object;
822     }
823
824     {
825         QDeclarativeComponent component(&engine, testFileUrl("color_write.qml"));
826         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
827         QVERIFY(object != 0);
828
829         QColor newColor;
830         newColor.setRedF(0.5);
831         newColor.setGreenF(0.38);
832         newColor.setBlueF(0.3);
833         newColor.setAlphaF(0.7);
834         QCOMPARE(object->color(), newColor);
835
836         delete object;
837     }
838
839     {
840         QDeclarativeComponent component(&engine, testFileUrl("color_compare.qml"));
841         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
842         QVERIFY(object != 0);
843         QString colorString("#33e199");
844         QCOMPARE(object->property("colorToString").toString(), colorString);
845         QCOMPARE(object->property("colorEqualsIdenticalRgba").toBool(), true);
846         QCOMPARE(object->property("colorEqualsDifferentAlpha").toBool(), false);
847         QCOMPARE(object->property("colorEqualsDifferentRgba").toBool(), false);
848         QCOMPARE(object->property("colorToStringEqualsColorString").toBool(), true);
849         QCOMPARE(object->property("colorToStringEqualsDifferentAlphaString").toBool(), true);
850         QCOMPARE(object->property("colorToStringEqualsDifferentRgbaString").toBool(), false);
851         QCOMPARE(object->property("colorEqualsColorString").toBool(), true);          // maintaining behaviour with QtQuick 1.0
852         QCOMPARE(object->property("colorEqualsDifferentAlphaString").toBool(), true); // maintaining behaviour with QtQuick 1.0
853         QCOMPARE(object->property("colorEqualsDifferentRgbaString").toBool(), false);
854
855         QCOMPARE(object->property("equalsColor").toBool(), true);
856         QCOMPARE(object->property("equalsVector3d").toBool(), false);
857         QCOMPARE(object->property("equalsSize").toBool(), false);
858         QCOMPARE(object->property("equalsPoint").toBool(), false);
859         QCOMPARE(object->property("equalsRect").toBool(), false);
860
861         // Color == Property and Property == Color should return the same result.
862         QCOMPARE(object->property("equalsColorRHS").toBool(), object->property("equalsColor").toBool());
863         QCOMPARE(object->property("colorEqualsCopy").toBool(), true);
864         QCOMPARE(object->property("copyEqualsColor").toBool(), object->property("colorEqualsCopy").toBool());
865
866         delete object;
867     }
868 }
869
870 // Test bindings can write to value types
871 void tst_qdeclarativevaluetypes::bindingAssignment()
872 {
873     QDeclarativeComponent component(&engine, testFileUrl("bindingAssignment.qml"));
874     MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
875     QVERIFY(object != 0);
876
877     QCOMPARE(object->rect().x(), 10);
878
879     object->setProperty("value", QVariant(92));
880
881     QCOMPARE(object->rect().x(), 92);
882
883     delete object;
884 }
885
886 // Test bindings can read from value types
887 void tst_qdeclarativevaluetypes::bindingRead()
888 {
889     QDeclarativeComponent component(&engine, testFileUrl("bindingRead.qml"));
890     MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
891     QVERIFY(object != 0);
892
893     QCOMPARE(object->property("value").toInt(), 2);
894
895     object->setRect(QRect(19, 3, 88, 2));
896
897     QCOMPARE(object->property("value").toInt(), 19);
898
899     delete object;
900 }
901
902 // Test static values can assign to value types
903 void tst_qdeclarativevaluetypes::staticAssignment()
904 {
905     QDeclarativeComponent component(&engine, testFileUrl("staticAssignment.qml"));
906     MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
907     QVERIFY(object != 0);
908
909     QCOMPARE(object->rect().x(), 9);
910
911     delete object;
912 }
913
914 // Test scripts can read/write value types
915 void tst_qdeclarativevaluetypes::scriptAccess()
916 {
917     QDeclarativeComponent component(&engine, testFileUrl("scriptAccess.qml"));
918     MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
919     QVERIFY(object != 0);
920
921     QCOMPARE(object->property("valuePre").toInt(), 2);
922     QCOMPARE(object->rect().x(), 19);
923     QCOMPARE(object->property("valuePost").toInt(), 19);
924
925     delete object;
926 }
927
928 // Test that assigning a constant from script removes any binding
929 void tst_qdeclarativevaluetypes::autoBindingRemoval()
930 {
931     {
932         QDeclarativeComponent component(&engine, testFileUrl("autoBindingRemoval.qml"));
933         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
934         QVERIFY(object != 0);
935
936         QCOMPARE(object->rect().x(), 10);
937
938         object->setProperty("value", QVariant(13));
939
940         QCOMPARE(object->rect().x(), 13);
941
942         object->emitRunScript();
943
944         QCOMPARE(object->rect().x(), 42);
945
946         object->setProperty("value", QVariant(92));
947
948         QCOMPARE(object->rect().x(), 42);
949
950         delete object;
951     }
952
953     /*
954     {
955         QDeclarativeComponent component(&engine, testFileUrl("autoBindingRemoval.2.qml"));
956         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
957         QVERIFY(object != 0);
958
959         QCOMPARE(object->rect().x(), 10);
960
961         object->setProperty("value", QVariant(13));
962
963         QCOMPARE(object->rect().x(), 13);
964
965         object->emitRunScript();
966
967         QCOMPARE(object->rect(), QRect(10, 10, 10, 10));
968
969         object->setProperty("value", QVariant(92));
970
971         QCOMPARE(object->rect(), QRect(10, 10, 10, 10));
972
973         delete object;
974     }
975
976     {
977         QDeclarativeComponent component(&engine, testFileUrl("autoBindingRemoval.3.qml"));
978         MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
979         QVERIFY(object != 0);
980
981         object->setProperty("value", QVariant(QRect(9, 22, 33, 44)));
982
983         QCOMPARE(object->rect(), QRect(9, 22, 33, 44));
984
985         object->emitRunScript();
986
987         QCOMPARE(object->rect(), QRect(44, 22, 33, 44));
988
989         object->setProperty("value", QVariant(QRect(19, 3, 4, 8)));
990
991         QCOMPARE(object->rect(), QRect(44, 22, 33, 44));
992
993         delete object;
994     }
995 */
996 }
997
998 // Test that property value sources assign to value types
999 void tst_qdeclarativevaluetypes::valueSources()
1000 {
1001     QDeclarativeComponent component(&engine, testFileUrl("valueSources.qml"));
1002     MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
1003     QVERIFY(object != 0);
1004
1005     QCOMPARE(object->rect().x(), 3345);
1006
1007     delete object;
1008 }
1009
1010 static void checkNoErrors(QDeclarativeComponent& component)
1011 {
1012     QList<QDeclarativeError> errors = component.errors();
1013     if (errors.isEmpty())
1014         return;
1015     for (int ii = 0; ii < errors.count(); ++ii) {
1016         const QDeclarativeError &error = errors.at(ii);
1017         qWarning("%d:%d:%s",error.line(),error.column(),error.description().toUtf8().constData());
1018     }
1019 }
1020
1021 // Test that property value interceptors can be applied to value types
1022 void tst_qdeclarativevaluetypes::valueInterceptors()
1023 {
1024     QDeclarativeComponent component(&engine, testFileUrl("valueInterceptors.qml"));
1025     MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
1026     checkNoErrors(component);
1027     QVERIFY(object != 0);
1028
1029     QCOMPARE(object->rect().x(), 13);
1030
1031     object->setProperty("value", 99);
1032
1033     QCOMPARE(object->rect().x(), 112);
1034
1035     delete object;
1036 }
1037
1038 // Test that you can't assign a binding to the "root" value type, and a sub-property
1039 void tst_qdeclarativevaluetypes::bindingConflict()
1040 {
1041     QDeclarativeComponent component(&engine, testFileUrl("bindingConflict.qml"));
1042     QCOMPARE(component.isError(), true);
1043 }
1044
1045 #define CPP_TEST(type, v) \
1046 { \
1047     type *t = new type; \
1048     QVariant value(v); \
1049     t->setValue(value); \
1050     QCOMPARE(t->value(), value); \
1051     delete t; \
1052 }
1053
1054 // Test that accessing a reference to a valuetype after the owning object is deleted
1055 // doesn't crash
1056 void tst_qdeclarativevaluetypes::deletedObject()
1057 {
1058     QDeclarativeComponent component(&engine, testFileUrl("deletedObject.qml"));
1059     QTest::ignoreMessage(QtDebugMsg, "Test: 2");
1060     MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
1061     QVERIFY(object != 0);
1062
1063     QObject *dObject = qvariant_cast<QObject *>(object->property("object"));
1064     QVERIFY(dObject != 0);
1065     delete dObject;
1066
1067     QTest::ignoreMessage(QtDebugMsg, "Test: undefined");
1068     object->emitRunScript();
1069
1070     delete object;
1071 }
1072
1073 // Test that value types can be assigned to another value type property in a binding
1074 void tst_qdeclarativevaluetypes::bindingVariantCopy()
1075 {
1076     QDeclarativeComponent component(&engine, testFileUrl("bindingVariantCopy.qml"));
1077     MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
1078     QVERIFY(object != 0);
1079
1080     QCOMPARE(object->rect(), QRect(19, 33, 5, 99));
1081
1082     delete object;
1083 }
1084
1085 // Test that value types can be assigned to another value type property in script
1086 void tst_qdeclarativevaluetypes::scriptVariantCopy()
1087 {
1088     QDeclarativeComponent component(&engine, testFileUrl("scriptVariantCopy.qml"));
1089     MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
1090     QVERIFY(object != 0);
1091
1092     QCOMPARE(object->rect(), QRect(2, 3, 109, 102));
1093
1094     object->emitRunScript();
1095
1096     QCOMPARE(object->rect(), QRect(19, 33, 5, 99));
1097
1098     delete object;
1099 }
1100
1101
1102 // Test that the value type classes can be used manually
1103 void tst_qdeclarativevaluetypes::cppClasses()
1104 {
1105     CPP_TEST(QDeclarativePointValueType, QPoint(19, 33));
1106     CPP_TEST(QDeclarativePointFValueType, QPointF(33.6, -23));
1107     CPP_TEST(QDeclarativeSizeValueType, QSize(-100, 18));
1108     CPP_TEST(QDeclarativeSizeFValueType, QSizeF(-100.7, 18.2));
1109     CPP_TEST(QDeclarativeRectValueType, QRect(13, 39, 10928, 88));
1110     CPP_TEST(QDeclarativeRectFValueType, QRectF(88.2, -90.1, 103.2, 118));
1111     CPP_TEST(QDeclarativeVector2DValueType, QVector2D(19.7, 1002));
1112     CPP_TEST(QDeclarativeVector3DValueType, QVector3D(18.2, 19.7, 1002));
1113     CPP_TEST(QDeclarativeVector4DValueType, QVector4D(18.2, 19.7, 1002, 54));
1114     CPP_TEST(QDeclarativeQuaternionValueType, QQuaternion(18.2, 19.7, 1002, 54));
1115     CPP_TEST(QDeclarativeMatrix4x4ValueType,
1116              QMatrix4x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16));
1117     CPP_TEST(QDeclarativeFontValueType, QFont("Helvetica"));
1118
1119 }
1120
1121 void tst_qdeclarativevaluetypes::enums()
1122 {
1123     {
1124     QDeclarativeComponent component(&engine, testFileUrl("enums.1.qml"));
1125     MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
1126     QVERIFY(object != 0);
1127     QVERIFY(object->font().capitalization() == QFont::AllUppercase);
1128     delete object;
1129     }
1130
1131     {
1132     QDeclarativeComponent component(&engine, testFileUrl("enums.2.qml"));
1133     MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
1134     QVERIFY(object != 0);
1135     QVERIFY(object->font().capitalization() == QFont::AllUppercase);
1136     delete object;
1137     }
1138
1139     {
1140     QDeclarativeComponent component(&engine, testFileUrl("enums.3.qml"));
1141     MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
1142     QVERIFY(object != 0);
1143     QVERIFY(object->font().capitalization() == QFont::AllUppercase);
1144     delete object;
1145     }
1146
1147     {
1148     QDeclarativeComponent component(&engine, testFileUrl("enums.4.qml"));
1149     MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
1150     QVERIFY(object != 0);
1151     QVERIFY(object->font().capitalization() == QFont::AllUppercase);
1152     delete object;
1153     }
1154
1155     {
1156     QDeclarativeComponent component(&engine, testFileUrl("enums.5.qml"));
1157     MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
1158     QVERIFY(object != 0);
1159     QVERIFY(object->font().capitalization() == QFont::AllUppercase);
1160     delete object;
1161     }
1162 }
1163
1164 // Tests switching between "conflicting" bindings (eg. a binding on the core
1165 // property, to a binding on the value-type sub-property)
1166 void tst_qdeclarativevaluetypes::conflictingBindings()
1167 {
1168     {
1169     QDeclarativeComponent component(&engine, testFileUrl("conflicting.1.qml"));
1170     QObject *object = component.create();
1171     QVERIFY(object != 0);
1172
1173     QCOMPARE(qvariant_cast<QFont>(object->property("font")).pixelSize(), 12);
1174
1175     QMetaObject::invokeMethod(object, "toggle");
1176
1177     QCOMPARE(qvariant_cast<QFont>(object->property("font")).pixelSize(), 6);
1178
1179     QMetaObject::invokeMethod(object, "toggle");
1180
1181     QCOMPARE(qvariant_cast<QFont>(object->property("font")).pixelSize(), 12);
1182
1183     delete object;
1184     }
1185
1186     {
1187     QDeclarativeComponent component(&engine, testFileUrl("conflicting.2.qml"));
1188     QObject *object = component.create();
1189     QVERIFY(object != 0);
1190
1191     QCOMPARE(qvariant_cast<QFont>(object->property("font")).pixelSize(), 6);
1192
1193     QMetaObject::invokeMethod(object, "toggle");
1194
1195     QCOMPARE(qvariant_cast<QFont>(object->property("font")).pixelSize(), 12);
1196
1197     QMetaObject::invokeMethod(object, "toggle");
1198
1199     QCOMPARE(qvariant_cast<QFont>(object->property("font")).pixelSize(), 6);
1200
1201     delete object;
1202     }
1203
1204     {
1205     QDeclarativeComponent component(&engine, testFileUrl("conflicting.3.qml"));
1206     QObject *object = component.create();
1207     QVERIFY(object != 0);
1208
1209     QCOMPARE(qvariant_cast<QFont>(object->property("font")).pixelSize(), 12);
1210
1211     QMetaObject::invokeMethod(object, "toggle");
1212
1213     QCOMPARE(qvariant_cast<QFont>(object->property("font")).pixelSize(), 24);
1214
1215     QMetaObject::invokeMethod(object, "toggle");
1216
1217     QCOMPARE(qvariant_cast<QFont>(object->property("font")).pixelSize(), 12);
1218
1219     delete object;
1220     }
1221 }
1222
1223 void tst_qdeclarativevaluetypes::returnValues()
1224 {
1225     QDeclarativeComponent component(&engine, testFileUrl("returnValues.qml"));
1226     QObject *object = component.create();
1227     QVERIFY(object != 0);
1228
1229     QCOMPARE(object->property("test1").toBool(), true);
1230     QCOMPARE(object->property("test2").toBool(), true);
1231     QCOMPARE(object->property("size").toSize(), QSize(13, 14));
1232
1233     delete object;
1234 }
1235
1236 void tst_qdeclarativevaluetypes::varAssignment()
1237 {
1238     QDeclarativeComponent component(&engine, testFileUrl("varAssignment.qml"));
1239     QObject *object = component.create();
1240     QVERIFY(object != 0);
1241
1242     QCOMPARE(object->property("x").toInt(), 1);
1243     QCOMPARE(object->property("y").toInt(), 2);
1244     QCOMPARE(object->property("z").toInt(), 3);
1245
1246     delete object;
1247 }
1248
1249 // Test bindings splice together correctly
1250 void tst_qdeclarativevaluetypes::bindingsSpliceCorrectly()
1251 {
1252     {
1253     QDeclarativeComponent component(&engine, testFileUrl("bindingsSpliceCorrectly.1.qml"));
1254     QObject *object = component.create();
1255     QVERIFY(object != 0);
1256
1257     QCOMPARE(object->property("test").toBool(), true);
1258
1259     delete object;
1260     }
1261
1262     {
1263     QDeclarativeComponent component(&engine, testFileUrl("bindingsSpliceCorrectly.2.qml"));
1264     QObject *object = component.create();
1265     QVERIFY(object != 0);
1266
1267     QCOMPARE(object->property("test").toBool(), true);
1268
1269     delete object;
1270     }
1271
1272
1273     {
1274     QDeclarativeComponent component(&engine, testFileUrl("bindingsSpliceCorrectly.3.qml"));
1275     QObject *object = component.create();
1276     QVERIFY(object != 0);
1277
1278     QCOMPARE(object->property("test").toBool(), true);
1279
1280     delete object;
1281     }
1282
1283     {
1284     QDeclarativeComponent component(&engine, testFileUrl("bindingsSpliceCorrectly.4.qml"));
1285     QObject *object = component.create();
1286     QVERIFY(object != 0);
1287
1288     QCOMPARE(object->property("test").toBool(), true);
1289
1290     delete object;
1291     }
1292
1293     {
1294     QDeclarativeComponent component(&engine, testFileUrl("bindingsSpliceCorrectly.5.qml"));
1295     QObject *object = component.create();
1296     QVERIFY(object != 0);
1297
1298     QCOMPARE(object->property("test").toBool(), true);
1299
1300     delete object;
1301     }
1302 }
1303
1304 QTEST_MAIN(tst_qdeclarativevaluetypes)
1305
1306 #include "tst_qdeclarativevaluetypes.moc"