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