aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlvaluetypeproviders
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qqmlvaluetypeproviders')
-rw-r--r--tests/auto/qml/qqmlvaluetypeproviders/data/comparisonSemantics.qml95
-rw-r--r--tests/auto/qml/qqmlvaluetypeproviders/data/cppIntegration.qml98
-rw-r--r--tests/auto/qml/qqmlvaluetypeproviders/data/jsObjectConversion.qml48
-rw-r--r--tests/auto/qml/qqmlvaluetypeproviders/data/qtqmlValueTypes.qml48
-rw-r--r--tests/auto/qml/qqmlvaluetypeproviders/data/qtquickValueTypes.qml119
-rw-r--r--tests/auto/qml/qqmlvaluetypeproviders/qqmlvaluetypeproviders.pro16
-rw-r--r--tests/auto/qml/qqmlvaluetypeproviders/testtypes.cpp46
-rw-r--r--tests/auto/qml/qqmlvaluetypeproviders/testtypes.h195
-rw-r--r--tests/auto/qml/qqmlvaluetypeproviders/tst_qqmlvaluetypeproviders.cpp173
9 files changed, 838 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlvaluetypeproviders/data/comparisonSemantics.qml b/tests/auto/qml/qqmlvaluetypeproviders/data/comparisonSemantics.qml
new file mode 100644
index 0000000000..e37cf9bc8d
--- /dev/null
+++ b/tests/auto/qml/qqmlvaluetypeproviders/data/comparisonSemantics.qml
@@ -0,0 +1,95 @@
+import QtQuick 2.0
+
+QtObject {
+ property bool comparisonSuccess: false
+
+ property date d: new Date(1999, 8, 8)
+ property date d2: new Date(1998, 8, 8)
+
+ property rect g: Qt.rect(1, 2, 3, 4)
+ property rect g2: Qt.rect(5, 6, 7, 8)
+ property point p: Qt.point(1, 2)
+ property point p2: Qt.point(3, 4)
+ property size z: Qt.size(1, 2)
+ property size z2: Qt.size(3, 4)
+
+ property vector2d v2: Qt.vector2d(1,2)
+ property vector2d v22: Qt.vector2d(3,4)
+ property vector3d v3: Qt.vector3d(1,2,3)
+ property vector3d v32: Qt.vector3d(4,5,6)
+ property vector4d v4: Qt.vector4d(1,2,3,4)
+ property vector4d v42: Qt.vector4d(5,6,7,8)
+ property quaternion q: Qt.quaternion(1,2,3,4)
+ property quaternion q2: Qt.quaternion(5,6,7,8)
+ property matrix4x4 m: Qt.matrix4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
+ property matrix4x4 m2: Qt.matrix4x4(21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36)
+ property color c: "red"
+ property color c2: "blue"
+ property font f: Qt.font({family: "Arial", pointSize: 20})
+ property font f2: Qt.font({family: "Arial", pointSize: 22})
+
+ Component.onCompleted: {
+ comparisonSuccess = true;
+
+ // same type comparison.
+ if (d == d2) comparisonSuccess = false;
+ d = d2;
+ if (d == d2) comparisonSuccess = false; // QML date uses same comparison semantics as JS date!
+ if (d.toString() != d2.toString()) comparisonSuccess = false;
+
+ if (g == g2) comparisonSuccess = false;
+ g = g2;
+ if (g != g2) comparisonSuccess = false;
+
+ if (p == p2) comparisonSuccess = false;
+ p = p2;
+ if (p != p2) comparisonSuccess = false;
+
+ if (z == z2) comparisonSuccess = false;
+ z = z2;
+ if (z != z2) comparisonSuccess = false;
+
+ if (v2 == v22) comparisonSuccess = false;
+ v2 = v22;
+ if (v2 != v22) comparisonSuccess = false;
+
+ if (v3 == v32) comparisonSuccess = false;
+ v3 = v32;
+ if (v3 != v32) comparisonSuccess = false;
+
+ if (v4 == v42) comparisonSuccess = false;
+ v4 = v42;
+ if (v4 != v42) comparisonSuccess = false;
+
+ if (q == q2) comparisonSuccess = false;
+ q = q2;
+ if (q != q2) comparisonSuccess = false;
+
+ if (m == m2) comparisonSuccess = false;
+ m = m2;
+ if (m != m2) comparisonSuccess = false;
+
+ if (c == c2) comparisonSuccess = false;
+ c = c2;
+ if (c != c2) comparisonSuccess = false;
+
+ if (f == f2) comparisonSuccess = false;
+ f = f2;
+ if (f != f2) comparisonSuccess = false;
+
+ // cross-type comparison.
+ p = Qt.point(1,2);
+ z = Qt.size(1,2);
+ v2 = Qt.vector2d(1,2);
+ if (p == z || p == v2 || z == v2) comparisonSuccess = false;
+ if (z == p || v2 == p || v2 == z) comparisonSuccess = false;
+
+ g = Qt.rect(1,2,3,4);
+ q = Qt.quaternion(1,2,3,4);
+ v4 = Qt.vector4d(1,2,3,4);
+ if (g == q || g == v4 || q == v4) comparisonSuccess = false;
+ if (q == g || v4 == g || v4 == q) comparisonSuccess = false;
+
+ if (c == f) comparisonSuccess = false;
+ }
+}
diff --git a/tests/auto/qml/qqmlvaluetypeproviders/data/cppIntegration.qml b/tests/auto/qml/qqmlvaluetypeproviders/data/cppIntegration.qml
new file mode 100644
index 0000000000..06756f7a18
--- /dev/null
+++ b/tests/auto/qml/qqmlvaluetypeproviders/data/cppIntegration.qml
@@ -0,0 +1,98 @@
+import QtQuick 2.0
+import Test 1.0
+
+MyTypeObject {
+ property bool success: false
+
+ // the values come from the MyTypeObject property definitions,
+ // which were defined in C++.
+
+ property rect g: rectf
+ property point p: pointf
+ property size z: sizef
+
+ property vector2d v2: vector2
+ property vector3d v3: vector
+ property vector4d v4: vector4
+ property quaternion q: quaternion
+ property matrix4x4 m: matrix
+ property color c: color
+ property font f: font
+
+ Component.onCompleted: {
+ success = true;
+
+ // ensure that the semantics of the properties
+ // defined in C++ match those of the properties
+ // defined in QML, and that we can compare/assign etc.
+
+ if (g != rectf) success = false;
+ g = Qt.rect(1,2,3,4);
+ if (g == rectf) success = false;
+ g = rectf;
+ if (g != rectf) success = false;
+ g = rect;
+ if (g != rect) success = false;
+ g = rectf; // for the cpp-size value comparison.
+
+ if (p != pointf) success = false;
+ p = Qt.point(1,2);
+ if (p == pointf) success = false;
+ p = pointf;
+ if (p != pointf) success = false;
+ p = point;
+ if (p != point) success = false;
+ p = pointf; // for the cpp-size value comparison.
+
+ if (z != sizef) success = false;
+ z = Qt.size(1,2);
+ if (z == sizef) success = false;
+ z = sizef;
+ if (z != sizef) success = false;
+ z = size;
+ if (z != size) success = false;
+ z = sizef; // for the cpp-size value comparison.
+
+ if (v2 != vector2) success = false;
+ v2 = Qt.vector2d(1,2);
+ if (v2 == vector2) success = false;
+ v2 = vector2;
+ if (v2 != vector2) success = false;
+
+ if (v3 != vector) success = false;
+ v3 = Qt.vector3d(1,2,3);
+ if (v3 == vector) success = false;
+ v3 = vector;
+ if (v3 != vector) success = false;
+
+ if (v4 != vector4) success = false;
+ v4 = Qt.vector4d(1,2,3,4);
+ if (v4 == vector4) success = false;
+ v4 = vector4;
+ if (v4 != vector4) success = false;
+
+ if (q != quaternion) success = false;
+ q = Qt.quaternion(1,2,3,4);
+ if (q == quaternion) success = false;
+ q = quaternion;
+ if (q != quaternion) success = false;
+
+ if (m != matrix) success = false;
+ m = Qt.matrix4x4(120, 230, 340, 450, 560, 670, 780, 890, 900, 1010, 1120, 1230, 1340, 1450, 1560, 1670);
+ if (m == matrix) success = false;
+ m = matrix;
+ if (m != matrix) success = false;
+
+ if (c != color) success = false;
+ c = Qt.rgba(1,0,0,.5);
+ if (c == color) success = false;
+ c = color;
+ if (c != color) success = false;
+
+ if (f != font) success = false;
+ f = Qt.font({family: "Arial", pointSize: 15, weight: Font.DemiBold, italic: false});
+ if (f == font) success = false;
+ f = font;
+ if (f != font) success = false;
+ }
+}
diff --git a/tests/auto/qml/qqmlvaluetypeproviders/data/jsObjectConversion.qml b/tests/auto/qml/qqmlvaluetypeproviders/data/jsObjectConversion.qml
new file mode 100644
index 0000000000..cd51b6c8cb
--- /dev/null
+++ b/tests/auto/qml/qqmlvaluetypeproviders/data/jsObjectConversion.qml
@@ -0,0 +1,48 @@
+import QtQuick 2.0
+
+QtObject {
+ property bool qtquickTypeSuccess: false
+
+ // currently, only conversion from js object to font and matrix is supported.
+ property matrix4x4 m: Qt.matrix4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
+ property matrix4x4 m2: Qt.matrix4x4([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
+ property font f: Qt.font({ family: "Arial", pointSize: 10, weight: Font.Bold, italic: true })
+ property font f2: Qt.font({ family: "Arial", pointSize: 10, weight: Font.Bold, italic: true })
+
+ Component.onCompleted: {
+ qtquickTypeSuccess = true;
+
+ // check that the initialisation worked
+ if (m != m2) qtquickTypeSuccess = false;
+ if (f != f2) qtquickTypeSuccess = false;
+
+ // check that assignment works
+ m = Qt.matrix4x4(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4)
+ m2 = Qt.matrix4x4([1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4])
+ if (m != m2) qtquickTypeSuccess = false;
+ f = Qt.font({ family: "Arial", pointSize: 16, weight: Font.Black, italic: false });
+ f2 = Qt.font({ family: "Arial", pointSize: 16, weight: Font.Black, italic: false });
+ if (f != f2) qtquickTypeSuccess = false;
+
+ // ensure that equality works as required.
+ if (m2 != Qt.matrix4x4([1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4])) qtquickTypeSucces = false;
+ if (f2 != Qt.font({ family: "Arial", pointSize: 16, weight: Font.Black, italic: false })) qtquickTypeSuccess = false;
+
+ // just to ensure comparison of values from js object assigned values is consistent.
+ m = Qt.matrix4x4(5,5,5,5,2,2,2,2,3,3,3,3,4,4,4,4);
+ m2 = Qt.matrix4x4([6,6,6,6,2,2,2,2,3,3,3,3,4,4,4,4]);
+ if (m == m2) qtquickTypeSuccess = false;
+ m = Qt.matrix4x4(6,6,6,6,2,2,2,2,3,3,3,3,4,4,4,4);
+ if (m != m2) qtquickTypeSuccess = false;
+ m = Qt.matrix4x4([7,7,7,7,2,2,2,2,3,3,3,3,4,4,4,4]);
+ if (m == m2) qtquickTypeSuccess = false;
+ m = Qt.matrix4x4([6,6,6,6,2,2,2,2,3,3,3,3,4,4,4,4]);
+ if (m != m2) qtquickTypeSuccess = false;
+
+ f = Qt.font({ family: "Arial", pointSize: 10, weight: Font.Bold, italic: true });
+ f2 = Qt.font({ family: "Arial", pointSize: 16, weight: Font.Black, italic: false });
+ if (f == f2) qtquickTypeSuccess = false;
+ f = Qt.font({ family: "Arial", pointSize: 16, weight: Font.Black, italic: false });
+ if (f != f2) qtquickTypeSuccess = false;
+ }
+}
diff --git a/tests/auto/qml/qqmlvaluetypeproviders/data/qtqmlValueTypes.qml b/tests/auto/qml/qqmlvaluetypeproviders/data/qtqmlValueTypes.qml
new file mode 100644
index 0000000000..30bc92d8af
--- /dev/null
+++ b/tests/auto/qml/qqmlvaluetypeproviders/data/qtqmlValueTypes.qml
@@ -0,0 +1,48 @@
+import QtQml 2.0
+
+QtObject {
+ property bool qtqmlTypeSuccess: false
+ property bool qtquickTypeSuccess: false
+
+ property int i: 10
+ property bool b: true
+ property real r: 5.5
+ property string s: "Hello"
+
+ property date d: new Date(1999, 8, 8)
+
+ property rect g: Qt.rect(1, 2, 3, 4)
+ property point p: Qt.point(1, 2)
+ property size z: Qt.size(1, 2)
+
+ // the following property types are valid syntax in QML
+ // but their valuetype implementation is provided by QtQuick.
+ // Thus, we can define properties of the type, but not use them.
+ property vector2d v2
+ property vector3d v3
+ property vector4d v4
+ property quaternion q
+ property matrix4x4 m
+ property color c
+ property font f
+
+ Component.onCompleted: {
+ qtqmlTypeSuccess = true;
+ qtquickTypeSuccess = true;
+
+ // test that the base qtqml provided types work
+ if (i != 10) qtqmlTypeSuccess = false;
+ if (b != true) qtqmlTypeSuccess = false;
+ if (r != 5.5) qtqmlTypeSuccess = false;
+ if (s != "Hello") qtqmlTypeSuccess = false;
+ if (d.toDateString() != (new Date(1999,8,8)).toDateString()) qtqmlTypeSuccess = false;
+ if (g != Qt.rect(1, 2, 3, 4)) qtqmlTypeSuccess = false;
+ if (p != Qt.point(1, 2)) qtqmlTypeSuccess = false;
+ if (z != Qt.size(1, 2)) qtqmlTypeSuccess = false;
+
+ // This should also work, as the base value types are provided by QtQml.
+ if (g.x != 1 || g.y != 2 || g.width != 3 || g.height != 4) qtqmlTypeSuccess = false;
+ if (p.x != 1 || p.y != 2) qtqmlTypeSuccess = false;
+ if (z.width != 1 || z.height != 2) qtqmlTypeSuccess = false;
+ }
+}
diff --git a/tests/auto/qml/qqmlvaluetypeproviders/data/qtquickValueTypes.qml b/tests/auto/qml/qqmlvaluetypeproviders/data/qtquickValueTypes.qml
new file mode 100644
index 0000000000..f723dc3e2e
--- /dev/null
+++ b/tests/auto/qml/qqmlvaluetypeproviders/data/qtquickValueTypes.qml
@@ -0,0 +1,119 @@
+import QtQuick 2.0
+
+QtObject {
+ property bool qtqmlTypeSuccess: false
+ property bool qtquickTypeSuccess: false
+
+ property int i: 10
+ property bool b: true
+ property real r: 5.5
+ property string s: "Hello"
+
+ property date d: new Date(1999, 8, 8)
+
+ property rect g: Qt.rect(1, 2, 3, 4)
+ property point p: Qt.point(1, 2)
+ property size z: Qt.size(1, 2)
+
+ property vector2d v2: Qt.vector2d(1,2)
+ property vector3d v3: Qt.vector3d(1,2,3)
+ property vector4d v4: Qt.vector4d(1,2,3,4)
+ property quaternion q: Qt.quaternion(1,2,3,4)
+ property matrix4x4 m: Qt.matrix4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
+ property color c: "red"
+ property color c2: "red"
+ property font f: Qt.font({ family: "Arial", pointSize: 20 })
+
+ // ensure that group property specification works as expected.
+ property font f2
+ f2.family: "Arial"
+ f2.pointSize: 45
+ f2.italic: true
+ v22.x: 5
+ v22.y: 10
+ property vector2d v22
+ property font f3 // note: cannot specify grouped subproperties inline with property declaration :-/
+ f3 {
+ family: "Arial"
+ pointSize: 45
+ italic: true
+ }
+
+ Component.onCompleted: {
+ qtqmlTypeSuccess = true;
+ qtquickTypeSuccess = true;
+
+ // check base types still work even though we imported QtQuick
+ if (i != 10) qtqmlTypeSuccess = false;
+ if (b != true) qtqmlTypeSuccess = false;
+ if (r != 5.5) qtqmlTypeSuccess = false;
+ if (s != "Hello") qtqmlTypeSuccess = false;
+ if (d.toDateString() != (new Date(1999,8,8)).toDateString()) qtqmlTypeSuccess = false;
+
+ // check language-provided value types still work.
+ if (g != Qt.rect(1, 2, 3, 4)) qtqmlTypeSuccess = false;
+ if (g.x != 1 || g.y != 2 || g.width != 3 || g.height != 4) qtqmlTypeSuccess = false;
+ if (p != Qt.point(1, 2)) qtqmlTypeSuccess = false;
+ if (p.x != 1 || p.y != 2) qtqmlTypeSuccess = false;
+ if (z != Qt.size(1, 2)) qtqmlTypeSuccess = false;
+ if (z.width != 1 || z.height != 2) qtqmlTypeSuccess = false;
+
+ // Check that the value type provider for vector3d and other non-QtQml value-types is provided by QtQuick.
+ if (v2.x != 1 || v2.y != 2) qtquickTypeSuccess = false;
+ if (v2 != Qt.vector2d(1,2)) qtquickTypeSuccess = false;
+ if (v3.x != 1 || v3.y != 2 || v3.z != 3) qtquickTypeSuccess = false;
+ if (v3 != Qt.vector3d(1,2,3)) qtquickTypeSuccess = false;
+ if (v4.x != 1 || v4.y != 2 || v4.z != 3 || v4.w != 4) qtquickTypeSuccess = false;
+ if (v4 != Qt.vector4d(1,2,3,4)) qtquickTypeSuccess = false;
+ if (q.scalar != 1 || q.x != 2 || q.y != 3 || q.z != 4) qtquickTypeSuccess = false;
+ if (q != Qt.quaternion(1,2,3,4)) qtquickTypeSuccess = false;
+ if (m != Qt.matrix4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)) qtquickTypeSuccess = false;
+ if (c != Qt.rgba(1,0,0,1)) qtquickTypeSuccess = false;
+ if (c != c2) qtquickTypeSuccess = false; // can compare two colors directly.
+ if (f.family != "Arial" || f.pointSize != 20) qtquickTypeSuccess = false;
+ if (f != Qt.font({ family: "Arial", pointSize: 20 })) qtquickTypeSuccess = false;
+ if (f2.family != "Arial" || f2.pointSize != 45 || f2.italic != true) qtquickTypeSuccess = false;
+ if (f2 != f3) qtquickTypeSuccess = false;
+ if (v22.x != 5 || v22.y != 10) qtquickTypeSuccess = false;
+
+ // font has some optional parameters.
+ var defaultFont = Qt.font({ family: "Arial", pointSize: 22 }); // normal should be default weight.
+ var lightFont = Qt.font({ family: "Arial", pointSize: 22, weight: Font.Light });
+ var normalFont = Qt.font({ family: "Arial", pointSize: 22, weight: Font.Normal });
+ var demiboldFont = Qt.font({ family: "Arial", pointSize: 22, weight: Font.DemiBold });
+ var boldFont = Qt.font({ family: "Arial", pointSize: 22, weight: Font.Bold });
+ var blackFont = Qt.font({ family: "Arial", pointSize: 22, weight: Font.Black });
+
+ f = Qt.font({ family: "Arial", pointSize: 22, weight: Font.Light });
+ if (f.family != "Arial" || f.pointSize != 22 || f.weight != lightFont.weight || f.weight == normalFont.weight) qtquickTypeSuccess = false;
+ f = Qt.font({ family: "Arial", pointSize: 22, weight: Font.Normal, italic: true });
+ if (f.family != "Arial" || f.pointSize != 22 || f.weight != normalFont.weight || f.italic != true) qtquickTypeSuccess = false;
+ f = Qt.font({ family: "Arial", pointSize: 22, weight: Font.DemiBold, italic: false });
+ if (f.family != "Arial" || f.pointSize != 22 || f.weight != demiboldFont.weight || f.italic != false) qtquickTypeSuccess = false;
+ f = Qt.font({ family: "Arial", pointSize: 22, weight: Font.Bold }); // italic should be false by default
+ if (f.family != "Arial" || f.pointSize != 22 || f.weight != boldFont.weight || f.italic != false) qtquickTypeSuccess = false;
+ f = Qt.font({ family: "Arial", pointSize: 22, weight: Font.Black }); // italic should be false by default
+ if (f.family != "Arial" || f.pointSize != 22 || f.weight != blackFont.weight || f.italic != false) qtquickTypeSuccess = false;
+
+ // Check the string conversion codepaths.
+ v2 = "5,6";
+ if (v2 != Qt.vector2d(5,6)) qtquickTypeSuccess = false;
+ if (v2.toString() != "QVector2D(5, 6)") qtquickTypeSuccess = false;
+ v3 = "5,6,7";
+ if (v3 != Qt.vector3d(5,6,7)) qtquickTypeSuccess = false;
+ if (v3.toString() != "QVector3D(5, 6, 7)") qtquickTypeSuccess = false;
+ v4 = "5,6,7,8";
+ if (v4 != Qt.vector4d(5,6,7,8)) qtquickTypeSuccess = false;
+ if (v4.toString() != "QVector4D(5, 6, 7, 8)") qtquickTypeSuccess = false;
+ q = "5,6,7,8";
+ if (q != Qt.quaternion(5,6,7,8)) qtquickTypeSuccess = false;
+ if (q.toString() != "QQuaternion(5, 6, 7, 8)") qtquickTypeSuccess = false;
+ m = "4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7";
+ if (m != Qt.matrix4x4(4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7)) qtquickTypeSuccess = false;
+ if (m.toString() != "QMatrix4x4(4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7)") qtquickTypeSuccess = false;
+ c = "blue";
+ if (c.toString() != Qt.rgba(0,0,1,0).toString()) qtquickTypeSuccess = false;
+ if (c.toString() != "#0000FF" && c.toString() != "#0000ff") qtquickTypeSuccess = false; // color string converter is special
+ // no string converter for fonts.
+ }
+}
diff --git a/tests/auto/qml/qqmlvaluetypeproviders/qqmlvaluetypeproviders.pro b/tests/auto/qml/qqmlvaluetypeproviders/qqmlvaluetypeproviders.pro
new file mode 100644
index 0000000000..fb670606e2
--- /dev/null
+++ b/tests/auto/qml/qqmlvaluetypeproviders/qqmlvaluetypeproviders.pro
@@ -0,0 +1,16 @@
+CONFIG += testcase
+TARGET = tst_qqmlvaluetypeproviders
+macx:CONFIG -= app_bundle
+
+HEADERS += testtypes.h
+
+SOURCES += tst_qqmlvaluetypeproviders.cpp \
+ testtypes.cpp
+
+include (../../shared/util.pri)
+
+TESTDATA = data/*
+
+CONFIG += parallel_test
+
+QT += core-private gui-private v8-private qml-private quick-private gui testlib
diff --git a/tests/auto/qml/qqmlvaluetypeproviders/testtypes.cpp b/tests/auto/qml/qqmlvaluetypeproviders/testtypes.cpp
new file mode 100644
index 0000000000..c70179744c
--- /dev/null
+++ b/tests/auto/qml/qqmlvaluetypeproviders/testtypes.cpp
@@ -0,0 +1,46 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "testtypes.h"
+
+void registerTypes()
+{
+ qmlRegisterType<MyTypeObject>("Test", 1, 0, "MyTypeObject");
+}
diff --git a/tests/auto/qml/qqmlvaluetypeproviders/testtypes.h b/tests/auto/qml/qqmlvaluetypeproviders/testtypes.h
new file mode 100644
index 0000000000..bdd5ce656b
--- /dev/null
+++ b/tests/auto/qml/qqmlvaluetypeproviders/testtypes.h
@@ -0,0 +1,195 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef TESTTYPES_H
+#define TESTTYPES_H
+
+#include <QObject>
+#include <QPoint>
+#include <QPointF>
+#include <QSize>
+#include <QSizeF>
+#include <QRect>
+#include <QRectF>
+#include <QVector2D>
+#include <QVector3D>
+#include <QVector4D>
+#include <QQuaternion>
+#include <QMatrix4x4>
+#include <QFont>
+#include <QColor>
+#include <qqml.h>
+
+class MyTypeObject : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QPoint point READ point WRITE setPoint NOTIFY changed)
+ Q_PROPERTY(QPointF pointf READ pointf WRITE setPointf NOTIFY changed)
+ Q_PROPERTY(QPointF pointfpoint READ pointfpoint WRITE setPointfpoint NOTIFY changed)
+ Q_PROPERTY(QSize size READ size WRITE setSize NOTIFY changed)
+ Q_PROPERTY(QSizeF sizef READ sizef WRITE setSizef NOTIFY changed)
+ Q_PROPERTY(QSizeF sizefsize READ sizefsize WRITE setSizefsize NOTIFY changed)
+ Q_PROPERTY(QSize sizereadonly READ size NOTIFY changed)
+ Q_PROPERTY(QRect rect READ rect WRITE setRect NOTIFY changed)
+ Q_PROPERTY(QRectF rectf READ rectf WRITE setRectf NOTIFY changed)
+ Q_PROPERTY(QRectF rectfrect READ rectfrect WRITE setRectfrect NOTIFY changed)
+ Q_PROPERTY(QVector2D vector2 READ vector2 WRITE setVector2 NOTIFY changed)
+ Q_PROPERTY(QVector3D vector READ vector WRITE setVector NOTIFY changed)
+ Q_PROPERTY(QVector4D vector4 READ vector4 WRITE setVector4 NOTIFY changed)
+ Q_PROPERTY(QQuaternion quaternion READ quaternion WRITE setQuaternion NOTIFY changed)
+ Q_PROPERTY(QMatrix4x4 matrix READ matrix WRITE setMatrix NOTIFY changed)
+ Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY changed)
+ Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY changed)
+ Q_PROPERTY(QVariant variant READ variant NOTIFY changed)
+
+public:
+ MyTypeObject() :
+ m_point(10, 4),
+ m_pointf(11.3, -10.9),
+ m_pointfpoint(10.0, 4.0),
+ m_size(1912, 1913),
+ m_sizef(0.1, 100923.2),
+ m_sizefsize(1912.0, 1913.0),
+ m_rect(2, 3, 109, 102),
+ m_rectf(103.8, 99.2, 88.1, 77.6),
+ m_rectfrect(2.0, 3.0, 109.0, 102.0),
+ m_vector2(32.88, 1.3),
+ m_vector(23.88, 3.1, 4.3),
+ m_vector4(54.2, 23.88, 3.1, 4.3),
+ m_quaternion(4.3, 54.2, 23.88, 3.1),
+ m_matrix(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
+ {
+ m_font.setFamily("Arial");
+ m_font.setBold(true);
+ m_font.setWeight(QFont::DemiBold);
+ m_font.setItalic(true);
+ m_font.setUnderline(true);
+ m_font.setOverline(true);
+ m_font.setStrikeOut(true);
+ m_font.setPointSize(29);
+ m_font.setCapitalization(QFont::AllLowercase);
+ m_font.setLetterSpacing(QFont::AbsoluteSpacing, 10.2);
+ m_font.setWordSpacing(19.7);
+ m_color.setRedF(0.2);
+ m_color.setGreenF(0.88);
+ m_color.setBlueF(0.6);
+ m_color.setAlphaF(0.34);
+ }
+
+ QPoint m_point;
+ QPoint point() const { return m_point; }
+ void setPoint(const QPoint &v) { m_point = v; emit changed(); }
+
+ QPointF m_pointf;
+ QPointF pointf() const { return m_pointf; }
+ void setPointf(const QPointF &v) { m_pointf = v; emit changed(); }
+
+ QPointF m_pointfpoint;
+ QPointF pointfpoint() const { return m_pointfpoint; }
+ void setPointfpoint(const QPointF &v) { m_pointfpoint = v; emit changed(); }
+
+ QSize m_size;
+ QSize size() const { return m_size; }
+ void setSize(const QSize &v) { m_size = v; emit changed(); }
+
+ QSizeF m_sizef;
+ QSizeF sizef() const { return m_sizef; }
+ void setSizef(const QSizeF &v) { m_sizef = v; emit changed(); }
+
+ QSizeF m_sizefsize;
+ QSizeF sizefsize() const { return m_sizefsize; }
+ void setSizefsize(const QSizeF &v) { m_sizefsize = v; emit changed(); }
+
+ QRect m_rect;
+ QRect rect() const { return m_rect; }
+ void setRect(const QRect &v) { m_rect = v; emit changed(); }
+
+ QRectF m_rectf;
+ QRectF rectf() const { return m_rectf; }
+ void setRectf(const QRectF &v) { m_rectf = v; emit changed(); }
+
+ QRectF m_rectfrect;
+ QRectF rectfrect() const { return m_rectfrect; }
+ void setRectfrect(const QRectF &v) { m_rectfrect = v; emit changed(); }
+
+ QVector2D m_vector2;
+ QVector2D vector2() const { return m_vector2; }
+ void setVector2(const QVector2D &v) { m_vector2 = v; emit changed(); }
+
+ QVector3D m_vector;
+ QVector3D vector() const { return m_vector; }
+ void setVector(const QVector3D &v) { m_vector = v; emit changed(); }
+
+ QVector4D m_vector4;
+ QVector4D vector4() const { return m_vector4; }
+ void setVector4(const QVector4D &v) { m_vector4 = v; emit changed(); }
+
+ QQuaternion m_quaternion;
+ QQuaternion quaternion() const { return m_quaternion; }
+ void setQuaternion(const QQuaternion &v) { m_quaternion = v; emit changed(); }
+
+ QMatrix4x4 m_matrix;
+ QMatrix4x4 matrix() const { return m_matrix; }
+ void setMatrix(const QMatrix4x4 &v) { m_matrix = v; emit changed(); }
+
+ QFont m_font;
+ QFont font() const { return m_font; }
+ void setFont(const QFont &v) { m_font = v; emit changed(); }
+
+ QColor m_color;
+ QColor color() const { return m_color; }
+ void setColor(const QColor &v) { m_color = v; emit changed(); }
+
+ QVariant variant() const { return sizef(); }
+
+ void emitRunScript() { emit runScript(); }
+
+signals:
+ void changed();
+ void runScript();
+
+public slots:
+ QSize method() { return QSize(13, 14); }
+};
+
+void registerTypes();
+
+#endif // TESTTYPES_H
diff --git a/tests/auto/qml/qqmlvaluetypeproviders/tst_qqmlvaluetypeproviders.cpp b/tests/auto/qml/qqmlvaluetypeproviders/tst_qqmlvaluetypeproviders.cpp
new file mode 100644
index 0000000000..d811767489
--- /dev/null
+++ b/tests/auto/qml/qqmlvaluetypeproviders/tst_qqmlvaluetypeproviders.cpp
@@ -0,0 +1,173 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QQmlEngine>
+#include <QQmlComponent>
+#include <QDebug>
+#include <private/qquickvaluetypes_p.h>
+#include "../../shared/util.h"
+#include "testtypes.h"
+
+QT_BEGIN_NAMESPACE
+extern int qt_defaultDpi(void);
+QT_END_NAMESPACE
+
+// There is some overlap between the qqmllanguage and qqmlvaluetypes
+// test here, but it needs to be separate to ensure that no QML plugins
+// are loaded prior to these tests, which could contaminate the type
+// system with more providers.
+
+class tst_qqmlvaluetypeproviders : public QQmlDataTest
+{
+ Q_OBJECT
+public:
+ tst_qqmlvaluetypeproviders() {}
+
+private slots:
+ void initTestCase();
+
+ void qtqmlValueTypes(); // This test function _must_ be the first test function run.
+ void qtquickValueTypes();
+ void comparisonSemantics();
+ void cppIntegration();
+ void jsObjectConversion();
+};
+
+void tst_qqmlvaluetypeproviders::initTestCase()
+{
+ QQmlDataTest::initTestCase();
+ registerTypes();
+}
+
+void tst_qqmlvaluetypeproviders::qtqmlValueTypes()
+{
+ QQmlEngine e;
+ QQmlComponent component(&e, testFileUrl("qtqmlValueTypes.qml"));
+ QVERIFY(!component.isError());
+ QVERIFY(component.errors().isEmpty());
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QVERIFY(object->property("qtqmlTypeSuccess").toBool());
+ QVERIFY(object->property("qtquickTypeSuccess").toBool());
+ delete object;
+}
+
+void tst_qqmlvaluetypeproviders::qtquickValueTypes()
+{
+ QQmlEngine e;
+ QQmlComponent component(&e, testFileUrl("qtquickValueTypes.qml"));
+ QVERIFY(!component.isError());
+ QVERIFY(component.errors().isEmpty());
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QVERIFY(object->property("qtqmlTypeSuccess").toBool());
+ QVERIFY(object->property("qtquickTypeSuccess").toBool());
+ delete object;
+}
+
+void tst_qqmlvaluetypeproviders::comparisonSemantics()
+{
+ QQmlEngine e;
+ QQmlComponent component(&e, testFileUrl("comparisonSemantics.qml"));
+ QVERIFY(!component.isError());
+ QVERIFY(component.errors().isEmpty());
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QVERIFY(object->property("comparisonSuccess").toBool());
+ delete object;
+}
+
+void tst_qqmlvaluetypeproviders::cppIntegration()
+{
+ QQmlEngine e;
+ QQmlComponent component(&e, testFileUrl("cppIntegration.qml"));
+ QVERIFY(!component.isError());
+ QVERIFY(component.errors().isEmpty());
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ // ensure accessing / comparing / assigning cpp-defined props
+ // and qml-defined props works in QML.
+ QVERIFY(object->property("success").toBool());
+
+ // ensure types match
+ QCOMPARE(object->property("g").userType(), object->property("rectf").userType());
+ QCOMPARE(object->property("p").userType(), object->property("pointf").userType());
+ QCOMPARE(object->property("z").userType(), object->property("sizef").userType());
+ QCOMPARE(object->property("v2").userType(), object->property("vector2").userType());
+ QCOMPARE(object->property("v3").userType(), object->property("vector").userType());
+ QCOMPARE(object->property("v4").userType(), object->property("vector4").userType());
+ QCOMPARE(object->property("q").userType(), object->property("quaternion").userType());
+ QCOMPARE(object->property("m").userType(), object->property("matrix").userType());
+ QCOMPARE(object->property("c").userType(), object->property("color").userType());
+ QCOMPARE(object->property("f").userType(), object->property("font").userType());
+
+ // ensure values match
+ QCOMPARE(object->property("g").value<QRectF>(), object->property("rectf").value<QRectF>());
+ QCOMPARE(object->property("p").value<QPointF>(), object->property("pointf").value<QPointF>());
+ QCOMPARE(object->property("z").value<QSizeF>(), object->property("sizef").value<QSizeF>());
+ QCOMPARE(object->property("v2").value<QVector2D>(), object->property("vector2").value<QVector2D>());
+ QCOMPARE(object->property("v3").value<QVector3D>(), object->property("vector").value<QVector3D>());
+ QCOMPARE(object->property("v4").value<QVector4D>(), object->property("vector4").value<QVector4D>());
+ QCOMPARE(object->property("q").value<QQuaternion>(), object->property("quaternion").value<QQuaternion>());
+ QCOMPARE(object->property("m").value<QMatrix4x4>(), object->property("matrix").value<QMatrix4x4>());
+ QCOMPARE(object->property("c").value<QColor>(), object->property("color").value<QColor>());
+ QCOMPARE(object->property("f").value<QFont>(), object->property("font").value<QFont>());
+
+ delete object;
+}
+
+void tst_qqmlvaluetypeproviders::jsObjectConversion()
+{
+ QQmlEngine e;
+ QQmlComponent component(&e, testFileUrl("jsObjectConversion.qml"));
+ QVERIFY(!component.isError());
+ QVERIFY(component.errors().isEmpty());
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QVERIFY(object->property("qtquickTypeSuccess").toBool());
+ delete object;
+}
+
+QTEST_MAIN(tst_qqmlvaluetypeproviders)
+
+#include "tst_qqmlvaluetypeproviders.moc"