diff options
Diffstat (limited to 'tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp')
-rw-r--r-- | tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp | 297 |
1 files changed, 297 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp index aa4c014d99..3ccd5cb341 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp +++ b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp @@ -77,6 +77,7 @@ private slots: void quaternion(); void matrix4x4(); void font(); + void color(); void variant(); void bindingAssignment(); @@ -134,6 +135,26 @@ void tst_qdeclarativevaluetypes::point() delete object; } + + { + QDeclarativeComponent component(&engine, TEST_FILE("point_compare.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QString tostring = QLatin1String("QPoint(10, 4)"); + QCOMPARE(object->property("tostring").toString(), tostring); + QCOMPARE(object->property("equalsString").toBool(), true); + QCOMPARE(object->property("equalsColor").toBool(), false); + QCOMPARE(object->property("equalsVector3d").toBool(), false); + QCOMPARE(object->property("equalsSize").toBool(), false); + QCOMPARE(object->property("equalsPoint").toBool(), true); + QCOMPARE(object->property("equalsRect").toBool(), false); + QCOMPARE(object->property("equalsSelf").toBool(), true); + QCOMPARE(object->property("equalsOther").toBool(), false); + QCOMPARE(object->property("pointEqualsPointf").toBool(), true); + + delete object; + } } void tst_qdeclarativevaluetypes::pointf() @@ -159,6 +180,26 @@ void tst_qdeclarativevaluetypes::pointf() delete object; } + + { + QDeclarativeComponent component(&engine, TEST_FILE("pointf_compare.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QString tostring = QLatin1String("QPointF(11.3, -10.9)"); + QCOMPARE(object->property("tostring").toString(), tostring); + QCOMPARE(object->property("equalsString").toBool(), true); + QCOMPARE(object->property("equalsColor").toBool(), false); + QCOMPARE(object->property("equalsVector3d").toBool(), false); + QCOMPARE(object->property("equalsSize").toBool(), false); + QCOMPARE(object->property("equalsPoint").toBool(), true); + QCOMPARE(object->property("equalsRect").toBool(), false); + QCOMPARE(object->property("equalsSelf").toBool(), true); + QCOMPARE(object->property("equalsOther").toBool(), false); + QCOMPARE(object->property("pointfEqualsPoint").toBool(), true); + + delete object; + } } void tst_qdeclarativevaluetypes::size() @@ -184,6 +225,26 @@ void tst_qdeclarativevaluetypes::size() delete object; } + + { + QDeclarativeComponent component(&engine, TEST_FILE("size_compare.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QString tostring = QLatin1String("QSize(1912, 1913)"); + QCOMPARE(object->property("tostring").toString(), tostring); + QCOMPARE(object->property("equalsString").toBool(), true); + QCOMPARE(object->property("equalsColor").toBool(), false); + QCOMPARE(object->property("equalsVector3d").toBool(), false); + QCOMPARE(object->property("equalsSize").toBool(), true); + QCOMPARE(object->property("equalsPoint").toBool(), false); + QCOMPARE(object->property("equalsRect").toBool(), false); + QCOMPARE(object->property("equalsSelf").toBool(), true); + QCOMPARE(object->property("equalsOther").toBool(), false); + QCOMPARE(object->property("sizeEqualsSizef").toBool(), true); + + delete object; + } } void tst_qdeclarativevaluetypes::sizef() @@ -209,6 +270,26 @@ void tst_qdeclarativevaluetypes::sizef() delete object; } + + { + QDeclarativeComponent component(&engine, TEST_FILE("sizef_compare.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QString tostring = QLatin1String("QSizeF(0.1, 100923)"); + QCOMPARE(object->property("tostring").toString(), tostring); + QCOMPARE(object->property("equalsString").toBool(), true); + QCOMPARE(object->property("equalsColor").toBool(), false); + QCOMPARE(object->property("equalsVector3d").toBool(), false); + QCOMPARE(object->property("equalsSize").toBool(), true); + QCOMPARE(object->property("equalsPoint").toBool(), false); + QCOMPARE(object->property("equalsRect").toBool(), false); + QCOMPARE(object->property("equalsSelf").toBool(), true); + QCOMPARE(object->property("equalsOther").toBool(), false); + QCOMPARE(object->property("sizefEqualsSize").toBool(), true); + + delete object; + } } void tst_qdeclarativevaluetypes::variant() @@ -293,6 +374,26 @@ void tst_qdeclarativevaluetypes::rect() delete object; } + + { + QDeclarativeComponent component(&engine, TEST_FILE("rect_compare.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QString tostring = QLatin1String("QRect(2, 3, 109, 102)"); + QCOMPARE(object->property("tostring").toString(), tostring); + QCOMPARE(object->property("equalsString").toBool(), true); + QCOMPARE(object->property("equalsColor").toBool(), false); + QCOMPARE(object->property("equalsVector3d").toBool(), false); + QCOMPARE(object->property("equalsSize").toBool(), false); + QCOMPARE(object->property("equalsPoint").toBool(), false); + QCOMPARE(object->property("equalsRect").toBool(), true); + QCOMPARE(object->property("equalsSelf").toBool(), true); + QCOMPARE(object->property("equalsOther").toBool(), false); + QCOMPARE(object->property("rectEqualsRectf").toBool(), true); + + delete object; + } } void tst_qdeclarativevaluetypes::rectf() @@ -320,6 +421,26 @@ void tst_qdeclarativevaluetypes::rectf() delete object; } + + { + QDeclarativeComponent component(&engine, TEST_FILE("rectf_compare.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QString tostring = QLatin1String("QRectF(103.8, 99.2, 88.1, 77.6)"); + QCOMPARE(object->property("tostring").toString(), tostring); + QCOMPARE(object->property("equalsString").toBool(), true); + QCOMPARE(object->property("equalsColor").toBool(), false); + QCOMPARE(object->property("equalsVector3d").toBool(), false); + QCOMPARE(object->property("equalsSize").toBool(), false); + QCOMPARE(object->property("equalsPoint").toBool(), false); + QCOMPARE(object->property("equalsRect").toBool(), true); + QCOMPARE(object->property("equalsSelf").toBool(), true); + QCOMPARE(object->property("equalsOther").toBool(), false); + QCOMPARE(object->property("rectfEqualsRect").toBool(), true); + + delete object; + } } void tst_qdeclarativevaluetypes::vector2d() @@ -345,6 +466,24 @@ void tst_qdeclarativevaluetypes::vector2d() delete object; } + + { + QDeclarativeComponent component(&engine, TEST_FILE("vector2d_compare.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QString tostring = QLatin1String("QVector2D(32.88, 1.3)"); + QCOMPARE(object->property("tostring").toString(), tostring); + QCOMPARE(object->property("equalsString").toBool(), true); + QCOMPARE(object->property("equalsColor").toBool(), false); + QCOMPARE(object->property("equalsVector3d").toBool(), false); + QCOMPARE(object->property("equalsSize").toBool(), false); + QCOMPARE(object->property("equalsPoint").toBool(), false); + QCOMPARE(object->property("equalsRect").toBool(), false); + QCOMPARE(object->property("equalsSelf").toBool(), true); + + delete object; + } } void tst_qdeclarativevaluetypes::vector3d() @@ -371,6 +510,25 @@ void tst_qdeclarativevaluetypes::vector3d() delete object; } + + { + QDeclarativeComponent component(&engine, TEST_FILE("vector3d_compare.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QString tostring = QLatin1String("QVector3D(23.88, 3.1, 4.3)"); + QCOMPARE(object->property("tostring").toString(), tostring); + QCOMPARE(object->property("equalsString").toBool(), true); + QCOMPARE(object->property("equalsColor").toBool(), false); + QCOMPARE(object->property("equalsVector3d").toBool(), true); + QCOMPARE(object->property("equalsSize").toBool(), false); + QCOMPARE(object->property("equalsPoint").toBool(), false); + QCOMPARE(object->property("equalsRect").toBool(), false); + QCOMPARE(object->property("equalsSelf").toBool(), true); + QCOMPARE(object->property("equalsOther").toBool(), false); + + delete object; + } } void tst_qdeclarativevaluetypes::vector4d() @@ -398,6 +556,24 @@ void tst_qdeclarativevaluetypes::vector4d() delete object; } + + { + QDeclarativeComponent component(&engine, TEST_FILE("vector4d_compare.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QString tostring = QLatin1String("QVector4D(54.2, 23.88, 3.1, 4.3)"); + QCOMPARE(object->property("tostring").toString(), tostring); + QCOMPARE(object->property("equalsString").toBool(), true); + QCOMPARE(object->property("equalsColor").toBool(), false); + QCOMPARE(object->property("equalsVector3d").toBool(), false); + QCOMPARE(object->property("equalsSize").toBool(), false); + QCOMPARE(object->property("equalsPoint").toBool(), false); + QCOMPARE(object->property("equalsRect").toBool(), false); + QCOMPARE(object->property("equalsSelf").toBool(), true); + + delete object; + } } void tst_qdeclarativevaluetypes::quaternion() @@ -425,6 +601,24 @@ void tst_qdeclarativevaluetypes::quaternion() delete object; } + + { + QDeclarativeComponent component(&engine, TEST_FILE("quaternion_compare.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QString tostring = QLatin1String("QQuaternion(4.3, 54.2, 23.88, 3.1)"); + QCOMPARE(object->property("tostring").toString(), tostring); + QCOMPARE(object->property("equalsString").toBool(), true); + QCOMPARE(object->property("equalsColor").toBool(), false); + QCOMPARE(object->property("equalsVector3d").toBool(), false); + QCOMPARE(object->property("equalsSize").toBool(), false); + QCOMPARE(object->property("equalsPoint").toBool(), false); + QCOMPARE(object->property("equalsRect").toBool(), false); + QCOMPARE(object->property("equalsSelf").toBool(), true); + + delete object; + } } void tst_qdeclarativevaluetypes::matrix4x4() @@ -471,6 +665,24 @@ void tst_qdeclarativevaluetypes::matrix4x4() delete object; } + + { + QDeclarativeComponent component(&engine, TEST_FILE("matrix4x4_compare.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QString tostring = QLatin1String("QMatrix4x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)"); + QCOMPARE(object->property("tostring").toString(), tostring); + QCOMPARE(object->property("equalsString").toBool(), true); + QCOMPARE(object->property("equalsColor").toBool(), false); + QCOMPARE(object->property("equalsVector3d").toBool(), false); + QCOMPARE(object->property("equalsSize").toBool(), false); + QCOMPARE(object->property("equalsPoint").toBool(), false); + QCOMPARE(object->property("equalsRect").toBool(), false); + QCOMPARE(object->property("equalsSelf").toBool(), true); + + delete object; + } } void tst_qdeclarativevaluetypes::font() @@ -576,6 +788,91 @@ void tst_qdeclarativevaluetypes::font() delete object; } + + { + QDeclarativeComponent component(&engine, TEST_FILE("font_compare.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QString tostring = QLatin1String("QFont(") + object->font().toString() + QLatin1Char(')'); + QCOMPARE(object->property("tostring").toString(), tostring); + QCOMPARE(object->property("equalsString").toBool(), true); + QCOMPARE(object->property("equalsColor").toBool(), false); + QCOMPARE(object->property("equalsVector3d").toBool(), false); + QCOMPARE(object->property("equalsSize").toBool(), false); + QCOMPARE(object->property("equalsPoint").toBool(), false); + QCOMPARE(object->property("equalsRect").toBool(), false); + QCOMPARE(object->property("equalsSelf").toBool(), true); + + delete object; + } +} + +void tst_qdeclarativevaluetypes::color() +{ + { + QDeclarativeComponent component(&engine, TEST_FILE("color_read.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QCOMPARE((float)object->property("v_r").toDouble(), (float)0.2); + QCOMPARE((float)object->property("v_g").toDouble(), (float)0.88); + QCOMPARE((float)object->property("v_b").toDouble(), (float)0.6); + QCOMPARE((float)object->property("v_a").toDouble(), (float)0.34); + QColor comparison; + comparison.setRedF(0.2); + comparison.setGreenF(0.88); + comparison.setBlueF(0.6); + comparison.setAlphaF(0.34); + QCOMPARE(object->property("copy"), QVariant(comparison)); + + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("color_write.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QColor newColor; + newColor.setRedF(0.5); + newColor.setGreenF(0.38); + newColor.setBlueF(0.3); + newColor.setAlphaF(0.7); + QCOMPARE(object->color(), newColor); + + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("color_compare.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + QString colorString("#33e199"); + QCOMPARE(object->property("colorToString").toString(), colorString); + QCOMPARE(object->property("colorEqualsIdenticalRgba").toBool(), true); + QCOMPARE(object->property("colorEqualsDifferentAlpha").toBool(), false); + QCOMPARE(object->property("colorEqualsDifferentRgba").toBool(), false); + QCOMPARE(object->property("colorToStringEqualsColorString").toBool(), true); + QCOMPARE(object->property("colorToStringEqualsDifferentAlphaString").toBool(), true); + QCOMPARE(object->property("colorToStringEqualsDifferentRgbaString").toBool(), false); + QCOMPARE(object->property("colorEqualsColorString").toBool(), true); // maintaining behaviour with QtQuick 1.0 + QCOMPARE(object->property("colorEqualsDifferentAlphaString").toBool(), true); // maintaining behaviour with QtQuick 1.0 + QCOMPARE(object->property("colorEqualsDifferentRgbaString").toBool(), false); + + QCOMPARE(object->property("equalsColor").toBool(), true); + QCOMPARE(object->property("equalsVector3d").toBool(), false); + QCOMPARE(object->property("equalsSize").toBool(), false); + QCOMPARE(object->property("equalsPoint").toBool(), false); + QCOMPARE(object->property("equalsRect").toBool(), false); + + // Color == Property and Property == Color should return the same result. + QCOMPARE(object->property("equalsColorRHS").toBool(), object->property("equalsColor").toBool()); + QCOMPARE(object->property("colorEqualsCopy").toBool(), true); + QCOMPARE(object->property("copyEqualsColor").toBool(), object->property("colorEqualsCopy").toBool()); + + delete object; + } } // Test bindings can write to value types |