aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlvaluetypes
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2012-07-16 16:32:49 +1000
committerQt by Nokia <qt-info@nokia.com>2012-08-09 07:58:06 +0200
commit42f9444e983b5257241c17242471ca63f208c3f6 (patch)
tree4847ae743a0e05b0ff9d3d4ab6003ea257a6c682 /tests/auto/qml/qqmlvaluetypes
parentf09517bd9c907698a05ee92ccf158a06db3340b8 (diff)
Allow invokable functions of value-type classes to be called
Previously, invokable functions of value-type classes were returned as properties. This commit fixes that bug by allowing such functions to be invoked normally. It also improves copy-value type handling. This commit also ensures that QMatrix4x4 value types are constructed with qreal values as this is the storage type used internally. Change-Id: Iab0fe4c522ed53d60154e8a8d46dda925fb9f4de Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests/auto/qml/qqmlvaluetypes')
-rw-r--r--tests/auto/qml/qqmlvaluetypes/data/matrix4x4_invokables.qml31
-rw-r--r--tests/auto/qml/qqmlvaluetypes/data/vector2d_invokables.qml23
-rw-r--r--tests/auto/qml/qqmlvaluetypes/data/vector3d_invokables.qml25
-rw-r--r--tests/auto/qml/qqmlvaluetypes/data/vector4d_invokables.qml25
-rw-r--r--tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp34
5 files changed, 136 insertions, 2 deletions
diff --git a/tests/auto/qml/qqmlvaluetypes/data/matrix4x4_invokables.qml b/tests/auto/qml/qqmlvaluetypes/data/matrix4x4_invokables.qml
new file mode 100644
index 0000000000..aa26956922
--- /dev/null
+++ b/tests/auto/qml/qqmlvaluetypes/data/matrix4x4_invokables.qml
@@ -0,0 +1,31 @@
+import QtQuick 2.0
+
+Item {
+ property bool success: false
+
+ property variant m1: Qt.matrix4x4(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4)
+ property variant m2: Qt.matrix4x4(5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8)
+ property variant m3: Qt.matrix4x4(123,22,6,42,55,54,67,77,777,1,112,22,55,6696,77,777)
+ property variant v1: Qt.vector4d(1,2,3,4)
+ property variant v2: Qt.vector3d(1,2,3)
+ property real factor: 2.23
+
+ Component.onCompleted: {
+ success = true;
+ if (m1.times(m2) != Qt.matrix4x4(26, 26, 26, 26, 52, 52, 52, 52, 78, 78, 78, 78, 104, 104, 104, 104)) success = false;
+ if (m1.times(v1) != Qt.vector4d(10, 20, 30, 40)) success = false;
+ if (m1.times(v2) != Qt.vector3d(0.25, 0.5, 0.75)) success = false;
+ if (!m1.times(factor).fuzzyEquals(Qt.matrix4x4(2.23, 2.23, 2.23, 2.23, 4.46, 4.46, 4.46, 4.46, 6.69, 6.69, 6.69, 6.69, 8.92, 8.92, 8.92, 8.92))) success = false;
+ if (m1.plus(m2) != Qt.matrix4x4(6, 6, 6, 6, 8, 8, 8, 8, 10, 10, 10, 10, 12, 12, 12, 12)) success = false;
+ if (m2.minus(m1) != Qt.matrix4x4(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)) success = false;
+ if (m1.row(2) != Qt.vector4d(3,3,3,3)) success = false;
+ if (m1.column(2) != Qt.vector4d(1,2,3,4)) success = false;
+ if (m1.determinant() != 0) success = false;
+ if (m3.determinant() != -15260238498) success = false;
+ if (m1.inverted() != Qt.matrix4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)) success = false; // non-invertible
+ if (!m3.inverted().fuzzyEquals(Qt.matrix4x4(0.0028384, -0.00188321, 0.000970577, 0.00000571656, -0.00206701, -0.000598587, 0.000358192, 0.000160908, -0.0235917, 0.0122695, 0.00286765, -0.0000218643, 0.01995, 0.00407588, -0.00343969, -0.000097903), 0.00001)) success = false;
+ if (m1.transposed() != Qt.matrix4x4(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4)) success = false;
+ if (m1.fuzzyEquals(m2)) success = false;
+ if (!m1.fuzzyEquals(m2, 10)) success = false;
+ }
+}
diff --git a/tests/auto/qml/qqmlvaluetypes/data/vector2d_invokables.qml b/tests/auto/qml/qqmlvaluetypes/data/vector2d_invokables.qml
new file mode 100644
index 0000000000..9f84a50950
--- /dev/null
+++ b/tests/auto/qml/qqmlvaluetypes/data/vector2d_invokables.qml
@@ -0,0 +1,23 @@
+import QtQuick 2.0
+
+Item {
+ property bool success: false
+
+ property variant v1: Qt.vector2d(1,2)
+ property variant v2: Qt.vector2d(5,6)
+ property real factor: 2.23
+
+ Component.onCompleted: {
+ success = true;
+ if (v1.times(v2) != Qt.vector2d(5, 12)) success = false;
+ if (v1.times(factor) != Qt.vector2d(2.23, 4.46)) success = false;
+ if (v1.plus(v2) != Qt.vector2d(6, 8)) success = false;
+ if (v2.minus(v1) != Qt.vector2d(4, 4)) success = false;
+ if (!v1.normalized().fuzzyEquals(Qt.vector2d(0.447214, 0.894427), 0.000001)) success = false;
+ if ((v1.length() == v2.length()) || (v1.length() != Qt.vector2d(2,1).length())) success = false;
+ if (v1.toVector3d() != Qt.vector3d(1,2,0)) success = false;
+ if (v1.toVector4d() != Qt.vector4d(1,2,0,0)) success = false;
+ if (v1.fuzzyEquals(v2)) success = false;
+ if (!v1.fuzzyEquals(v2, 4)) success = false;
+ }
+}
diff --git a/tests/auto/qml/qqmlvaluetypes/data/vector3d_invokables.qml b/tests/auto/qml/qqmlvaluetypes/data/vector3d_invokables.qml
new file mode 100644
index 0000000000..48185f9089
--- /dev/null
+++ b/tests/auto/qml/qqmlvaluetypes/data/vector3d_invokables.qml
@@ -0,0 +1,25 @@
+import QtQuick 2.0
+
+Item {
+ property bool success: false
+
+ property variant v1: Qt.vector3d(1,2,3)
+ property variant v2: Qt.vector3d(5,6,7)
+ property variant m1: Qt.matrix4x4(5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8)
+ property real factor: 2.23
+
+ Component.onCompleted: {
+ success = true;
+ if (v1.times(v2) != Qt.vector3d(5, 12, 21)) success = false;
+ if (v1.times(m1) != Qt.vector3d(1, 1, 1)) success = false;
+ if (v1.times(factor) != Qt.vector3d(2.23, 4.46, 6.69)) success = false;
+ if (v1.plus(v2) != Qt.vector3d(6, 8, 10)) success = false;
+ if (v2.minus(v1) != Qt.vector3d(4, 4, 4)) success = false;
+ if (!v1.normalized().fuzzyEquals(Qt.vector3d(0.267261, 0.534522, 0.801784), 0.00001)) success = false;
+ if ((v1.length() == v2.length()) || (v1.length() != Qt.vector3d(3,2,1).length())) success = false;
+ if (v1.toVector2d() != Qt.vector2d(1,2)) success = false;
+ if (v1.toVector4d() != Qt.vector4d(1,2,3,0)) success = false;
+ if (v1.fuzzyEquals(v2)) success = false;
+ if (!v1.fuzzyEquals(v2, 4)) success = false;
+ }
+}
diff --git a/tests/auto/qml/qqmlvaluetypes/data/vector4d_invokables.qml b/tests/auto/qml/qqmlvaluetypes/data/vector4d_invokables.qml
new file mode 100644
index 0000000000..c80ee0dc54
--- /dev/null
+++ b/tests/auto/qml/qqmlvaluetypes/data/vector4d_invokables.qml
@@ -0,0 +1,25 @@
+import QtQuick 2.0
+
+Item {
+ property bool success: false
+
+ property variant v1: Qt.vector4d(1,2,3,4)
+ property variant v2: Qt.vector4d(5,6,7,8)
+ property variant m1: Qt.matrix4x4(5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8)
+ property real factor: 2.23
+
+ Component.onCompleted: {
+ success = true;
+ if (v1.times(v2) != Qt.vector4d(5, 12, 21, 32)) success = false;
+ if (v1.times(m1) != Qt.vector4d(70, 70, 70, 70)) success = false;
+ if (v1.times(factor) != Qt.vector4d(2.23, 4.46, 6.69, 8.92)) success = false;
+ if (v1.plus(v2) != Qt.vector4d(6, 8, 10, 12)) success = false;
+ if (v2.minus(v1) != Qt.vector4d(4, 4, 4, 4)) success = false;
+ if (!v1.normalized().fuzzyEquals(Qt.vector4d(0.182574, 0.365148, 0.547723, 0.730297), 0.00001)) success = false;
+ if ((v1.length() == v2.length()) || (v1.length() != Qt.vector4d(4,3,2,1).length())) success = false;
+ if (v1.toVector2d() != Qt.vector2d(1,2)) success = false;
+ if (v1.toVector3d() != Qt.vector3d(1,2,3)) success = false;
+ if (v1.fuzzyEquals(v2)) success = false;
+ if (!v1.fuzzyEquals(v2, 4)) success = false;
+ }
+}
diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
index a323db5d5f..cf8eb34fd6 100644
--- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
+++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
@@ -303,8 +303,6 @@ void tst_qqmlvaluetypes::variant()
}
{
- QString w1 = testFileUrl("variant_write.1.qml").toString() + QLatin1String(":9: TypeError: Object QVector2D(8, 2) has no method 'plus'");
- QTest::ignoreMessage(QtWarningMsg, qPrintable(w1));
QQmlComponent component(&engine, testFileUrl("variant_write.1.qml"));
QObject *object = component.create();
QVERIFY(object != 0);
@@ -502,6 +500,14 @@ void tst_qqmlvaluetypes::vector2d()
delete object;
}
+
+ {
+ QQmlComponent component(&engine, testFileUrl("vector2d_invokables.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QVERIFY(object->property("success").toBool());
+ delete object;
+ }
}
void tst_qqmlvaluetypes::vector3d()
@@ -547,6 +553,14 @@ void tst_qqmlvaluetypes::vector3d()
delete object;
}
+
+ {
+ QQmlComponent component(&engine, testFileUrl("vector3d_invokables.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QVERIFY(object->property("success").toBool());
+ delete object;
+ }
}
void tst_qqmlvaluetypes::vector4d()
@@ -592,6 +606,14 @@ void tst_qqmlvaluetypes::vector4d()
delete object;
}
+
+ {
+ QQmlComponent component(&engine, testFileUrl("vector4d_invokables.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QVERIFY(object->property("success").toBool());
+ delete object;
+ }
}
void tst_qqmlvaluetypes::quaternion()
@@ -701,6 +723,14 @@ void tst_qqmlvaluetypes::matrix4x4()
delete object;
}
+
+ {
+ QQmlComponent component(&engine, testFileUrl("matrix4x4_invokables.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QCOMPARE(object->property("success").toBool(), true);
+ delete object;
+ }
}
void tst_qqmlvaluetypes::font()