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