From 1a81f8d676d7481e58f44dbb380acffe0800d93d Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 27 Jul 2009 16:48:13 +0200 Subject: Make typeToName testcase pass, and add basic test for Math3D classes. Reviewed-by: Trustme --- tests/auto/qvariant/tst_qvariant.cpp | 86 +++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 2 deletions(-) diff --git a/tests/auto/qvariant/tst_qvariant.cpp b/tests/auto/qvariant/tst_qvariant.cpp index 63e47ab..a9b9afd 100644 --- a/tests/auto/qvariant/tst_qvariant.cpp +++ b/tests/auto/qvariant/tst_qvariant.cpp @@ -59,9 +59,14 @@ #include #include #include -#include +#include #include #include +#include +#include +#include +#include +#include #include @@ -194,6 +199,12 @@ private slots: void transform(); + void matrix4x4(); + void vector2D(); + void vector3D(); + void vector4D(); + void quaternion(); + void url(); void userType(); @@ -1403,6 +1414,19 @@ void tst_QVariant::matrix() QMetaType::destroy(QVariant::Matrix, mmatrix); } +void tst_QVariant::matrix4x4() +{ + QVariant variant; + QMatrix4x4 matrix = qVariantValue(variant); + QVERIFY(matrix.isIdentity()); + qVariantSetValue(variant, QMatrix4x4().scale(2.0)); + QCOMPARE(QMatrix4x4().scale(2.0), qVariantValue(variant)); + + void *mmatrix = QMetaType::construct(QVariant::Matrix4x4, 0); + QVERIFY(mmatrix); + QMetaType::destroy(QVariant::Matrix4x4, mmatrix); +} + void tst_QVariant::transform() { QVariant variant; @@ -1416,6 +1440,59 @@ void tst_QVariant::transform() QMetaType::destroy(QVariant::Transform, mmatrix); } + +void tst_QVariant::vector2D() +{ + QVariant variant; + QVector2D vector = qVariantValue(variant); + QVERIFY(vector.isNull()); + qVariantSetValue(variant, QVector2D(0.1, 0.2)); + QCOMPARE(QVector2D(0.1, 0.2), qVariantValue(variant)); + + void *pvector = QMetaType::construct(QVariant::Vector2D, 0); + QVERIFY(pvector); + QMetaType::destroy(QVariant::Vector2D, pvector); +} + +void tst_QVariant::vector3D() +{ + QVariant variant; + QVector3D vector = qVariantValue(variant); + QVERIFY(vector.isNull()); + qVariantSetValue(variant, QVector3D(0.1, 0.2, 0.3)); + QCOMPARE(QVector3D(0.1, 0.2, 0.3), qVariantValue(variant)); + + void *pvector = QMetaType::construct(QVariant::Vector3D, 0); + QVERIFY(pvector); + QMetaType::destroy(QVariant::Vector3D, pvector); +} + +void tst_QVariant::vector4D() +{ + QVariant variant; + QVector4D vector = qVariantValue(variant); + QVERIFY(vector.isNull()); + qVariantSetValue(variant, QVector4D(0.1, 0.2, 0.3, 0.4)); + QCOMPARE(QVector4D(0.1, 0.2, 0.3, 0.4), qVariantValue(variant)); + + void *pvector = QMetaType::construct(QVariant::Vector4D, 0); + QVERIFY(pvector); + QMetaType::destroy(QVariant::Vector4D, pvector); +} + +void tst_QVariant::quaternion() +{ + QVariant variant; + QQuaternion quaternion = qVariantValue(variant); + QVERIFY(quaternion.isIdentity()); + qVariantSetValue(variant, QQuaternion(0.1, 0.2, 0.3, 0.4)); + QCOMPARE(QQuaternion(0.1, 0.2, 0.3, 0.4), qVariantValue(variant)); + + void *pquaternion = QMetaType::construct(QVariant::Quaternion, 0); + QVERIFY(pquaternion); + QMetaType::destroy(QVariant::Quaternion, pquaternion); +} + void tst_QVariant::writeToReadFromDataStream_data() { @@ -1955,6 +2032,11 @@ void tst_QVariant::typeName_data() QTest::newRow("45") << int(QVariant::Matrix) << QByteArray("QMatrix"); QTest::newRow("46") << int(QVariant::Transform) << QByteArray("QTransform"); QTest::newRow("47") << int(QVariant::Hash) << QByteArray("QVariantHash"); + QTest::newRow("48") << int(QVariant::Matrix4x4) << QByteArray("QMatrix4x4"); + QTest::newRow("49") << int(QVariant::Vector2D) << QByteArray("QVector2D"); + QTest::newRow("50") << int(QVariant::Vector3D) << QByteArray("QVector3D"); + QTest::newRow("51") << int(QVariant::Vector4D) << QByteArray("QVector4D"); + QTest::newRow("52") << int(QVariant::Quaternion) << QByteArray("QQuaternion"); } void tst_QVariant::typeName() @@ -1972,7 +2054,7 @@ void tst_QVariant::typeToName() QCOMPARE( QVariant::typeToName( v.type() ), (const char*)0 ); // Invalid // assumes that QVariant::Type contains consecutive values - int max = QVariant::Transform; + int max = QVariant::Quaternion; for ( int t = 1; t <= max; t++ ) { const char *n = QVariant::typeToName( (QVariant::Type)t ); if (n) -- cgit v0.12