aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2011-07-14 15:40:30 +1000
committerQt by Nokia <qt-info@nokia.com>2011-08-18 09:25:04 +0200
commiteaf52673ef38b4d7a14f9fb9f258d8f1c6097401 (patch)
treea607ea443865da0668029725283009cf17d2ffe1 /tests
parent36767e3fe1f0038441ae06ef5b5e1cb19a3738fa (diff)
Add support for a vector4d type in QML
QVector4D is a value-type which is supported but was not able to be constructed using a Qt object function. This commit allows properties of vector4d type to be constructed, and adds a function to the global Qt object and adds unit tests to ensure that it behaves correctly. Task-number: QTBUG-18559 Change-Id: I96509a4f496b644d20fdb1d977d0afe430d89e13 Reviewed-on: http://codereview.qt.nokia.com/1626 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp19
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/assignBasicTypes.qml1
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/assignLiteralToVariant.qml1
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/testtypes.h10
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp3
-rw-r--r--tests/auto/declarative/qdeclarativeqt/data/vector4.qml8
-rw-r--r--tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp21
7 files changed, 63 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp b/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp
index e6e87d1bbd..f432cbff49 100644
--- a/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp
+++ b/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp
@@ -63,6 +63,7 @@ private slots:
void rect();
void rectf();
void vector3d();
+ void vector4d();
void time();
};
@@ -682,6 +683,24 @@ void tst_qdeclarativeinstruction::vector3d()
QCOMPARE(vector.z(), (qreal)(float)12.0);
}
+void tst_qdeclarativeinstruction::vector4d()
+{
+ QCOMPARE(sizeof(QDeclarativeInstruction::instr_storeVector4D::QVector4D), sizeof(QVector4D));
+ QCOMPARE(Q_ALIGNOF(QDeclarativeInstruction::instr_storeVector4D::QVector4D), Q_ALIGNOF(QVector4D));
+
+ QDeclarativeInstruction i;
+ i.storeVector4D.vector.xp = 8.2;
+ i.storeVector4D.vector.yp = 99.3;
+ i.storeVector4D.vector.zp = 12.0;
+ i.storeVector4D.vector.wp = 121.1;
+
+ const QVector4D &vector = (const QVector4D &)(i.storeVector4D.vector);
+ QCOMPARE(vector.x(), (qreal)(float)8.2);
+ QCOMPARE(vector.y(), (qreal)(float)99.3);
+ QCOMPARE(vector.z(), (qreal)(float)12.0);
+ QCOMPARE(vector.w(), (qreal)(float)121.1);
+}
+
void tst_qdeclarativeinstruction::time()
{
QCOMPARE(sizeof(QDeclarativeInstruction::instr_storeTime::QTime), sizeof(QTime));
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/assignBasicTypes.qml b/tests/auto/declarative/qdeclarativelanguage/data/assignBasicTypes.qml
index 9fe0ded459..2313499d19 100644
--- a/tests/auto/declarative/qdeclarativelanguage/data/assignBasicTypes.qml
+++ b/tests/auto/declarative/qdeclarativelanguage/data/assignBasicTypes.qml
@@ -21,6 +21,7 @@ MyTypeObject {
boolProperty: true
variantProperty: "Hello World!"
vectorProperty: "10,1,2.2"
+ vector4Property: "10,1,2.2,2.3"
urlProperty: "main.qml"
objectProperty: MyTypeObject { intProperty: 8 }
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/assignLiteralToVariant.qml b/tests/auto/declarative/qdeclarativelanguage/data/assignLiteralToVariant.qml
index de476ae47f..f6f9a139dc 100644
--- a/tests/auto/declarative/qdeclarativelanguage/data/assignLiteralToVariant.qml
+++ b/tests/auto/declarative/qdeclarativelanguage/data/assignLiteralToVariant.qml
@@ -12,5 +12,6 @@ QtObject {
property variant test9: String("#FF008800")
property variant test10: true
property variant test11: false
+ property variant test12: "100,100,100,100"
}
diff --git a/tests/auto/declarative/qdeclarativelanguage/testtypes.h b/tests/auto/declarative/qdeclarativelanguage/testtypes.h
index c11bc33eab..dad0e23ae3 100644
--- a/tests/auto/declarative/qdeclarativelanguage/testtypes.h
+++ b/tests/auto/declarative/qdeclarativelanguage/testtypes.h
@@ -47,6 +47,7 @@
#include <QtGui/qmatrix.h>
#include <QtGui/qcolor.h>
#include <QtGui/qvector3d.h>
+#include <QtGui/qvector4d.h>
#include <QtDeclarative/qdeclarative.h>
#include <QtDeclarative/qdeclarativecomponent.h>
#include <QtDeclarative/qdeclarativeparserstatus.h>
@@ -224,6 +225,7 @@ class MyTypeObject : public QObject
Q_PROPERTY(bool boolProperty READ boolProperty WRITE setBoolProperty)
Q_PROPERTY(QVariant variantProperty READ variantProperty WRITE setVariantProperty)
Q_PROPERTY(QVector3D vectorProperty READ vectorProperty WRITE setVectorProperty)
+ Q_PROPERTY(QVector4D vector4Property READ vector4Property WRITE setVector4Property)
Q_PROPERTY(QUrl urlProperty READ urlProperty WRITE setUrlProperty)
Q_PROPERTY(QDeclarativeScriptString scriptProperty READ scriptProperty WRITE setScriptProperty)
@@ -442,6 +444,14 @@ public:
vectorPropertyValue = v;
}
+ QVector4D vector4PropertyValue;
+ QVector4D vector4Property() const {
+ return vector4PropertyValue;
+ }
+ void setVector4Property(const QVector4D &v) {
+ vector4PropertyValue = v;
+ }
+
QUrl urlPropertyValue;
QUrl urlProperty() const {
return urlPropertyValue;
diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
index dfaf3d1618..5e9bc418cc 100644
--- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
+++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
@@ -564,6 +564,7 @@ void tst_qdeclarativelanguage::assignBasicTypes()
QCOMPARE(object->boolProperty(), true);
QCOMPARE(object->variantProperty(), QVariant("Hello World!"));
QCOMPARE(object->vectorProperty(), QVector3D(10, 1, 2.2));
+ QCOMPARE(object->vector4Property(), QVector4D(10, 1, 2.2, 2.3));
QCOMPARE(object->urlProperty(), component.url().resolved(QUrl("main.qml")));
QVERIFY(object->objectProperty() != 0);
MyTypeObject *child = qobject_cast<MyTypeObject *>(object->objectProperty());
@@ -610,6 +611,7 @@ void tst_qdeclarativelanguage::assignLiteralToVariant()
QCOMPARE(object->property("test9").userType(), (int)QVariant::String);
QCOMPARE(object->property("test10").userType(), (int)QVariant::Bool);
QCOMPARE(object->property("test11").userType(), (int)QVariant::Bool);
+ QCOMPARE(object->property("test12").userType(), (int)QVariant::Vector4D);
QVERIFY(object->property("test1") == QVariant(1));
QVERIFY(object->property("test2") == QVariant((double)1.7));
@@ -622,6 +624,7 @@ void tst_qdeclarativelanguage::assignLiteralToVariant()
QVERIFY(object->property("test9") == QVariant(QString(QLatin1String("#FF008800"))));
QVERIFY(object->property("test10") == QVariant(bool(true)));
QVERIFY(object->property("test11") == QVariant(bool(false)));
+ QVERIFY(object->property("test12") == QVariant(QVector4D(100, 100, 100, 100)));
delete object;
}
diff --git a/tests/auto/declarative/qdeclarativeqt/data/vector4.qml b/tests/auto/declarative/qdeclarativeqt/data/vector4.qml
new file mode 100644
index 0000000000..554dd1e9d4
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeqt/data/vector4.qml
@@ -0,0 +1,8 @@
+import QtQuick 2.0
+
+QtObject {
+ property variant test1: Qt.vector4d(1, 0, 0.9, 0.6);
+ property variant test2: Qt.vector4d(102, -10, -982.1, 10);
+ property variant test3: Qt.vector4d(102, -10, -982.1);
+ property variant test4: Qt.vector4d(102, -10, -982.1, 10, 15);
+}
diff --git a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
index 4a9bb4513c..d9cd2b8fdf 100644
--- a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
+++ b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
@@ -72,6 +72,7 @@ private slots:
void point();
void size();
void vector();
+ void vector4d();
void lighter();
void darker();
void tint();
@@ -243,6 +244,26 @@ void tst_qdeclarativeqt::vector()
delete object;
}
+void tst_qdeclarativeqt::vector4d()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("vector4.qml"));
+
+ QString warning1 = component.url().toString() + ":6: Error: Qt.vector4d(): Invalid arguments";
+ QString warning2 = component.url().toString() + ":7: Error: Qt.vector4d(): Invalid arguments";
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
+
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QCOMPARE(qvariant_cast<QVector4D>(object->property("test1")), QVector4D(1, 0, 0.9, 0.6));
+ QCOMPARE(qvariant_cast<QVector4D>(object->property("test2")), QVector4D(102, -10, -982.1, 10));
+ QCOMPARE(qvariant_cast<QVector4D>(object->property("test3")), QVector4D());
+ QCOMPARE(qvariant_cast<QVector4D>(object->property("test4")), QVector4D());
+
+ delete object;
+}
+
void tst_qdeclarativeqt::lighter()
{
QDeclarativeComponent component(&engine, TEST_FILE("lighter.qml"));