diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp index 65a2bc7323..423d9b0256 100644 --- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp +++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp @@ -95,30 +95,26 @@ void tst_qqmlvaluetypes::point() { { QQmlComponent component(&engine, testFileUrl("point_read.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->property("p_x").toInt(), 10); QCOMPARE(object->property("p_y").toInt(), 4); QCOMPARE(object->property("copy"), QVariant(QPoint(10, 4))); - - delete object; } { QQmlComponent component(&engine, testFileUrl("point_write.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->point(), QPoint(11, 12)); - - delete object; } { QQmlComponent component(&engine, testFileUrl("point_compare.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QString tostring = QLatin1String("QPoint(10, 4)"); QCOMPARE(object->property("tostring").toString(), tostring); @@ -131,8 +127,6 @@ void tst_qqmlvaluetypes::point() QCOMPARE(object->property("equalsSelf").toBool(), true); QCOMPARE(object->property("equalsOther").toBool(), false); QCOMPARE(object->property("pointEqualsPointf").toBool(), true); - - delete object; } } @@ -140,30 +134,26 @@ void tst_qqmlvaluetypes::pointf() { { QQmlComponent component(&engine, testFileUrl("pointf_read.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(float(object->property("p_x").toDouble()), float(11.3)); QCOMPARE(float(object->property("p_y").toDouble()), float(-10.9)); QCOMPARE(object->property("copy"), QVariant(QPointF(11.3, -10.9))); - - delete object; } { QQmlComponent component(&engine, testFileUrl("pointf_write.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->pointf(), QPointF(6.8, 9.3)); - - delete object; } { QQmlComponent component(&engine, testFileUrl("pointf_compare.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QString tostring = QLatin1String("QPointF(11.3, -10.9)"); QCOMPARE(object->property("tostring").toString(), tostring); @@ -176,8 +166,6 @@ void tst_qqmlvaluetypes::pointf() QCOMPARE(object->property("equalsSelf").toBool(), true); QCOMPARE(object->property("equalsOther").toBool(), false); QCOMPARE(object->property("pointfEqualsPoint").toBool(), true); - - delete object; } } @@ -185,30 +173,26 @@ void tst_qqmlvaluetypes::size() { { QQmlComponent component(&engine, testFileUrl("size_read.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->property("s_width").toInt(), 1912); QCOMPARE(object->property("s_height").toInt(), 1913); QCOMPARE(object->property("copy"), QVariant(QSize(1912, 1913))); - - delete object; } { QQmlComponent component(&engine, testFileUrl("size_write.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->size(), QSize(13, 88)); - - delete object; } { QQmlComponent component(&engine, testFileUrl("size_compare.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QString tostring = QLatin1String("QSize(1912, 1913)"); QCOMPARE(object->property("tostring").toString(), tostring); @@ -221,8 +205,6 @@ void tst_qqmlvaluetypes::size() QCOMPARE(object->property("equalsSelf").toBool(), true); QCOMPARE(object->property("equalsOther").toBool(), false); QCOMPARE(object->property("sizeEqualsSizef").toBool(), true); - - delete object; } } @@ -230,30 +212,26 @@ void tst_qqmlvaluetypes::sizef() { { QQmlComponent component(&engine, testFileUrl("sizef_read.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(float(object->property("s_width").toDouble()), float(0.1)); QCOMPARE(float(object->property("s_height").toDouble()), float(100923.2)); QCOMPARE(object->property("copy"), QVariant(QSizeF(0.1, 100923.2))); - - delete object; } { QQmlComponent component(&engine, testFileUrl("sizef_write.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->sizef(), QSizeF(44.3, 92.8)); - - delete object; } { QQmlComponent component(&engine, testFileUrl("sizef_compare.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QString tostring = QLatin1String("QSizeF(0.1, 100923)"); QCOMPARE(object->property("tostring").toString(), tostring); @@ -266,8 +244,6 @@ void tst_qqmlvaluetypes::sizef() QCOMPARE(object->property("equalsSelf").toBool(), true); QCOMPARE(object->property("equalsOther").toBool(), false); QCOMPARE(object->property("sizefEqualsSize").toBool(), true); - - delete object; } } @@ -313,29 +289,25 @@ void tst_qqmlvaluetypes::locale() void tst_qqmlvaluetypes::qmlproperty() { QQmlComponent component(&engine, testFileUrl("qmlproperty_read.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); - QCOMPARE(object->property("colorPropertyObject").value(), object); + QCOMPARE(object->property("colorPropertyObject").value(), object.get()); QCOMPARE(object->property("colorPropertyName").toString(), "color"); QCOMPARE(object->property("invalidPropertyObject").value(), nullptr); QCOMPARE(object->property("invalidPropertyName").toString(), ""); - - delete object; } void tst_qqmlvaluetypes::sizereadonly() { { QQmlComponent component(&engine, testFileUrl("sizereadonly_read.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->property("s_width").toInt(), 1912); QCOMPARE(object->property("s_height").toInt(), 1913); QCOMPARE(object->property("copy"), QVariant(QSize(1912, 1913))); - - delete object; } { @@ -359,12 +331,10 @@ void tst_qqmlvaluetypes::sizereadonly() { QQmlComponent component(&engine, testFileUrl("sizereadonly_writeerror4.qml")); - QObject *object = component.create(); + std::unique_ptr object { component.create() }; QVERIFY(object); QCOMPARE(object->property("sizereadonly").toSize(), QSize(1912, 1913)); - - delete object; } } @@ -372,8 +342,8 @@ void tst_qqmlvaluetypes::rect() { { QQmlComponent component(&engine, testFileUrl("rect_read.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->property("r_x").toInt(), 2); QCOMPARE(object->property("r_y").toInt(), 3); @@ -384,24 +354,20 @@ void tst_qqmlvaluetypes::rect() QCOMPARE(object->property("r_top").toInt(), 3); QCOMPARE(object->property("r_bottom").toInt(), 104); QCOMPARE(object->property("copy"), QVariant(QRect(2, 3, 109, 102))); - - delete object; } { QQmlComponent component(&engine, testFileUrl("rect_write.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->rect(), QRect(1234, 7, 56, 63)); - - delete object; } { QQmlComponent component(&engine, testFileUrl("rect_compare.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QString tostring = QLatin1String("QRect(2, 3, 109, 102)"); QCOMPARE(object->property("tostring").toString(), tostring); @@ -414,8 +380,6 @@ void tst_qqmlvaluetypes::rect() QCOMPARE(object->property("equalsSelf").toBool(), true); QCOMPARE(object->property("equalsOther").toBool(), false); QCOMPARE(object->property("rectEqualsRectf").toBool(), true); - - delete object; } } @@ -423,8 +387,8 @@ void tst_qqmlvaluetypes::rectf() { { QQmlComponent component(&engine, testFileUrl("rectf_read.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(float(object->property("r_x").toDouble()), float(103.8)); QCOMPARE(float(object->property("r_y").toDouble()), float(99.2)); @@ -435,24 +399,20 @@ void tst_qqmlvaluetypes::rectf() QCOMPARE(float(object->property("r_top").toDouble()), float(99.2)); QCOMPARE(float(object->property("r_bottom").toDouble()), float(176.8)); QCOMPARE(object->property("copy"), QVariant(QRectF(103.8, 99.2, 88.1, 77.6))); - - delete object; } { QQmlComponent component(&engine, testFileUrl("rectf_write.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->rectf(), QRectF(70.1, -113.2, 80924.8, 99.2)); - - delete object; } { QQmlComponent component(&engine, testFileUrl("rectf_compare.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QString tostring = QLatin1String("QRectF(103.8, 99.2, 88.1, 77.6)"); QCOMPARE(object->property("tostring").toString(), tostring); @@ -465,8 +425,6 @@ void tst_qqmlvaluetypes::rectf() QCOMPARE(object->property("equalsSelf").toBool(), true); QCOMPARE(object->property("equalsOther").toBool(), false); QCOMPARE(object->property("rectfEqualsRect").toBool(), true); - - delete object; } } @@ -474,30 +432,26 @@ void tst_qqmlvaluetypes::vector2d() { { QQmlComponent component(&engine, testFileUrl("vector2d_read.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE((float)object->property("v_x").toDouble(), (float)32.88); QCOMPARE((float)object->property("v_y").toDouble(), (float)1.3); QCOMPARE(object->property("copy"), QVariant(QVector2D(32.88f, 1.3f))); - - delete object; } { QQmlComponent component(&engine, testFileUrl("vector2d_write.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->vector2(), QVector2D(-0.3f, -12.9f)); - - delete object; } { QQmlComponent component(&engine, testFileUrl("vector2d_compare.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QString tostring = QLatin1String("QVector2D(32.88, 1.3)"); QCOMPARE(object->property("tostring").toString(), tostring); @@ -508,16 +462,13 @@ void tst_qqmlvaluetypes::vector2d() QCOMPARE(object->property("equalsPoint").toBool(), false); QCOMPARE(object->property("equalsRect").toBool(), false); QCOMPARE(object->property("equalsSelf").toBool(), true); - - delete object; } { QQmlComponent component(&engine, testFileUrl("vector2d_invokables.qml")); - QObject *object = component.create(); - QVERIFY(object != nullptr); + std::unique_ptr object { component.create() }; + QVERIFY(object); QVERIFY(object->property("success").toBool()); - delete object; } } @@ -525,31 +476,27 @@ void tst_qqmlvaluetypes::vector3d() { { QQmlComponent component(&engine, testFileUrl("vector3d_read.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE((float)object->property("v_x").toDouble(), (float)23.88); QCOMPARE((float)object->property("v_y").toDouble(), (float)3.1); QCOMPARE((float)object->property("v_z").toDouble(), (float)4.3); QCOMPARE(object->property("copy"), QVariant(QVector3D(23.88f, 3.1f, 4.3f))); - - delete object; } { QQmlComponent component(&engine, testFileUrl("vector3d_write.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->vector(), QVector3D(-0.3f, -12.9f, 907.4f)); - - delete object; } { QQmlComponent component(&engine, testFileUrl("vector3d_compare.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QString tostring = QLatin1String("QVector3D(23.88, 3.1, 4.3)"); QCOMPARE(object->property("tostring").toString(), tostring); @@ -561,16 +508,13 @@ void tst_qqmlvaluetypes::vector3d() QCOMPARE(object->property("equalsRect").toBool(), false); QCOMPARE(object->property("equalsSelf").toBool(), true); QCOMPARE(object->property("equalsOther").toBool(), false); - - delete object; } { QQmlComponent component(&engine, testFileUrl("vector3d_invokables.qml")); - QObject *object = component.create(); - QVERIFY(object != nullptr); + std::unique_ptr object { component.create() }; + QVERIFY(object); QVERIFY(object->property("success").toBool()); - delete object; } } @@ -578,32 +522,28 @@ void tst_qqmlvaluetypes::vector4d() { { QQmlComponent component(&engine, testFileUrl("vector4d_read.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE((float)object->property("v_x").toDouble(), (float)54.2); QCOMPARE((float)object->property("v_y").toDouble(), (float)23.88); QCOMPARE((float)object->property("v_z").toDouble(), (float)3.1); QCOMPARE((float)object->property("v_w").toDouble(), (float)4.3); QCOMPARE(object->property("copy"), QVariant(QVector4D(54.2f, 23.88f, 3.1f, 4.3f))); - - delete object; } { QQmlComponent component(&engine, testFileUrl("vector4d_write.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->vector4(), QVector4D(-0.3f, -12.9f, 907.4f, 88.5f)); - - delete object; } { QQmlComponent component(&engine, testFileUrl("vector4d_compare.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QString tostring = QLatin1String("QVector4D(54.2, 23.88, 3.1, 4.3)"); QCOMPARE(object->property("tostring").toString(), tostring); @@ -614,16 +554,13 @@ void tst_qqmlvaluetypes::vector4d() QCOMPARE(object->property("equalsPoint").toBool(), false); QCOMPARE(object->property("equalsRect").toBool(), false); QCOMPARE(object->property("equalsSelf").toBool(), true); - - delete object; } { QQmlComponent component(&engine, testFileUrl("vector4d_invokables.qml")); - QObject *object = component.create(); - QVERIFY(object != nullptr); + std::unique_ptr object { component.create() }; + QVERIFY(object); QVERIFY(object->property("success").toBool()); - delete object; } } @@ -631,32 +568,28 @@ void tst_qqmlvaluetypes::quaternion() { { QQmlComponent component(&engine, testFileUrl("quaternion_read.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE((float)object->property("v_scalar").toDouble(), (float)4.3); QCOMPARE((float)object->property("v_x").toDouble(), (float)54.2); QCOMPARE((float)object->property("v_y").toDouble(), (float)23.88); QCOMPARE((float)object->property("v_z").toDouble(), (float)3.1); QCOMPARE(object->property("copy"), QVariant(QQuaternion(4.3f, 54.2f, 23.88f, 3.1f))); - - delete object; } { QQmlComponent component(&engine, testFileUrl("quaternion_write.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->quaternion(), QQuaternion(88.5f, -0.3f, -12.9f, 907.4f)); - - delete object; } { QQmlComponent component(&engine, testFileUrl("quaternion_compare.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QString tostring = QLatin1String("QQuaternion(4.3, 54.2, 23.88, 3.1)"); QCOMPARE(object->property("tostring").toString(), tostring); @@ -667,16 +600,13 @@ void tst_qqmlvaluetypes::quaternion() QCOMPARE(object->property("equalsPoint").toBool(), false); QCOMPARE(object->property("equalsRect").toBool(), false); QCOMPARE(object->property("equalsSelf").toBool(), true); - - delete object; } { QQmlComponent component(&engine, testFileUrl("quaternion_invokables.qml")); - QObject *object = component.create(); - QVERIFY(object != nullptr); + std::unique_ptr object { component.create() }; + QVERIFY(object); QVERIFY(object->property("success").toBool()); - delete object; } } @@ -684,8 +614,8 @@ void tst_qqmlvaluetypes::matrix4x4() { { QQmlComponent component(&engine, testFileUrl("matrix4x4_read.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE((float)object->property("v_m11").toDouble(), (float)1); QCOMPARE((float)object->property("v_m12").toDouble(), (float)2); @@ -708,27 +638,23 @@ void tst_qqmlvaluetypes::matrix4x4() 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16))); - - delete object; } { QQmlComponent component(&engine, testFileUrl("matrix4x4_write.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->matrix(), QMatrix4x4(11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34, 41, 42, 43, 44)); - - delete object; } { QQmlComponent component(&engine, testFileUrl("matrix4x4_compare.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); 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); @@ -739,16 +665,13 @@ void tst_qqmlvaluetypes::matrix4x4() QCOMPARE(object->property("equalsPoint").toBool(), false); QCOMPARE(object->property("equalsRect").toBool(), false); QCOMPARE(object->property("equalsSelf").toBool(), true); - - delete object; } { QQmlComponent component(&engine, testFileUrl("matrix4x4_invokables.qml")); - QObject *object = component.create(); - QVERIFY(object != nullptr); + std::unique_ptr object { component.create() }; + QVERIFY(object); QCOMPARE(object->property("success").toBool(), true); - delete object; } } @@ -756,9 +679,9 @@ void tst_qqmlvaluetypes::font() { { QQmlComponent component(&engine, testFileUrl("font_read.qml")); - MyTypeObject *object = qobject_cast(component.create()); + std::unique_ptr object { qobject_cast(component.create()) }; QVERIFY2(component.isReady(), qPrintable(component.errorString())); - QVERIFY(object != nullptr); + QVERIFY(object); QCOMPARE(object->property("f_family").toString(), object->font().family()); QCOMPARE(object->property("f_bold").toBool(), object->font().bold()); @@ -785,14 +708,12 @@ void tst_qqmlvaluetypes::font() QCOMPARE(object->property("f_wordSpacing").toDouble(), object->font().wordSpacing()); QCOMPARE(object->property("copy"), QVariant(object->font())); - - delete object; } { QQmlComponent component(&engine, testFileUrl("font_write.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QFont font; font.setFamily("Helvetica"); @@ -817,46 +738,38 @@ void tst_qqmlvaluetypes::font() QCOMPARE(f.capitalization(), font.capitalization()); QCOMPARE(f.letterSpacing(), font.letterSpacing()); QCOMPARE(f.wordSpacing(), font.wordSpacing()); - - delete object; } // Test pixelSize { QQmlComponent component(&engine, testFileUrl("font_write.2.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->font().pixelSize(), 10); - - delete object; } // Test pixelSize and pointSize { QQmlComponent component(&engine, testFileUrl("font_write.3.qml")); QTest::ignoreMessage(QtWarningMsg, "Both point size and pixel size set. Using pixel size."); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->font().pixelSize(), 10); - - delete object; } { QQmlComponent component(&engine, testFileUrl("font_write.4.qml")); QTest::ignoreMessage(QtWarningMsg, "Both point size and pixel size set. Using pixel size."); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->font().pixelSize(), 10); - - delete object; } { QQmlComponent component(&engine, testFileUrl("font_write.5.qml")); - QObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); MyTypeObject *object1 = object->findChild("object1"); QVERIFY(object1 != nullptr); MyTypeObject *object2 = object->findChild("object2"); @@ -864,14 +777,12 @@ void tst_qqmlvaluetypes::font() QCOMPARE(object1->font().pixelSize(), 19); QCOMPARE(object2->font().pointSize(), 14); - - delete object; } { QQmlComponent component(&engine, testFileUrl("font_compare.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QString tostring = QLatin1String("QFont(") + object->font().toString() + QLatin1Char(')'); QCOMPARE(object->property("tostring").toString(), tostring); @@ -882,8 +793,6 @@ void tst_qqmlvaluetypes::font() QCOMPARE(object->property("equalsPoint").toBool(), false); QCOMPARE(object->property("equalsRect").toBool(), false); QCOMPARE(object->property("equalsSelf").toBool(), true); - - delete object; } } @@ -891,8 +800,8 @@ void tst_qqmlvaluetypes::color() { { QQmlComponent component(&engine, testFileUrl("color_read.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(float(object->property("v_r").toDouble()), 0.2f); QCOMPARE(float(object->property("v_g").toDouble()), 0.88f); @@ -918,14 +827,12 @@ void tst_qqmlvaluetypes::color() comparison.setBlueF(0.6f); comparison.setAlphaF(0.34f); QCOMPARE(object->property("copy"), QVariant(comparison)); - - delete object; } { QQmlComponent component(&engine, testFileUrl("color_write.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QColor newColor; newColor.setRedF(0.5f); @@ -933,38 +840,32 @@ void tst_qqmlvaluetypes::color() newColor.setBlueF(0.3f); newColor.setAlphaF(0.7f); QCOMPARE(object->color(), newColor); - - delete object; } { QQmlComponent component(&engine, testFileUrl("color_write_HSV.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QColor newColor; newColor.setHsvF(0.43f, 0.77f, 0.88f, 0.7f); QCOMPARE(object->color(), newColor); - - delete object; } { QQmlComponent component(&engine, testFileUrl("color_write_HSL.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QColor newColor; newColor.setHslF(0.43f, 0.74f, 0.54f, 0.7f); QCOMPARE(object->color(), newColor); - - delete object; } { QQmlComponent component(&engine, testFileUrl("color_compare.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QColor comparison; comparison.setRedF(0.2f); comparison.setGreenF(0.88f); @@ -992,8 +893,6 @@ void tst_qqmlvaluetypes::color() 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; } } @@ -1003,8 +902,8 @@ void tst_qqmlvaluetypes::bindingAssignment() // binding declaration { QQmlComponent component(&engine, testFileUrl("bindingAssignment.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->rect().x(), 10); QCOMPARE(object->rect().y(), 15); @@ -1013,8 +912,6 @@ void tst_qqmlvaluetypes::bindingAssignment() QCOMPARE(object->rect().x(), 92); QCOMPARE(object->rect().y(), 97); - - delete object; } // function assignment should fail without crashing @@ -1024,12 +921,11 @@ void tst_qqmlvaluetypes::bindingAssignment() QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1)); QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2)); QQmlComponent component(&engine, testFileUrl("bindingAssignment.2.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->rect().x(), 5); object->setProperty("value", QVariant(92)); QCOMPARE(object->rect().x(), 5); - delete object; } } @@ -1037,42 +933,36 @@ void tst_qqmlvaluetypes::bindingAssignment() void tst_qqmlvaluetypes::bindingRead() { QQmlComponent component(&engine, testFileUrl("bindingRead.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->property("value").toInt(), 2); object->setRect(QRect(19, 3, 88, 2)); QCOMPARE(object->property("value").toInt(), 19); - - delete object; } // Test static values can assign to value types void tst_qqmlvaluetypes::staticAssignment() { QQmlComponent component(&engine, testFileUrl("staticAssignment.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->rect().x(), 9); - - delete object; } // Test scripts can read/write value types void tst_qqmlvaluetypes::scriptAccess() { QQmlComponent component(&engine, testFileUrl("scriptAccess.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->property("valuePre").toInt(), 2); QCOMPARE(object->rect().x(), 19); QCOMPARE(object->property("valuePost").toInt(), 19); - - delete object; } // Test that assigning a constant from script removes any binding @@ -1080,8 +970,8 @@ void tst_qqmlvaluetypes::autoBindingRemoval() { { QQmlComponent component(&engine, testFileUrl("autoBindingRemoval.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->rect().x(), 10); @@ -1096,14 +986,12 @@ void tst_qqmlvaluetypes::autoBindingRemoval() object->setProperty("value", QVariant(92)); QCOMPARE(object->rect().x(), 42); - - delete object; } { QQmlComponent component(&engine, testFileUrl("autoBindingRemoval.2.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->rect().x(), 10); @@ -1118,16 +1006,14 @@ void tst_qqmlvaluetypes::autoBindingRemoval() object->setProperty("value", QVariant(92)); QCOMPARE(object->rect(), QRect(10, 10, 10, 10)); - - delete object; } { QQmlComponent component(&engine, testFileUrl("autoBindingRemoval.3.qml")); QString warning = component.url().toString() + ":6:5: Unable to assign [undefined] to QRect"; QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); object->setProperty("value", QVariant(QRect(9, 22, 33, 44))); @@ -1140,8 +1026,6 @@ void tst_qqmlvaluetypes::autoBindingRemoval() object->setProperty("value", QVariant(QRect(19, 3, 4, 8))); QCOMPARE(object->rect(), QRect(44, 22, 33, 44)); - - delete object; } } @@ -1149,12 +1033,10 @@ void tst_qqmlvaluetypes::autoBindingRemoval() void tst_qqmlvaluetypes::valueSources() { QQmlComponent component(&engine, testFileUrl("valueSources.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->rect().x(), 3345); - - delete object; } static void checkNoErrors(QQmlComponent& component) @@ -1172,17 +1054,15 @@ static void checkNoErrors(QQmlComponent& component) void tst_qqmlvaluetypes::valueInterceptors() { QQmlComponent component(&engine, testFileUrl("valueInterceptors.qml")); - MyTypeObject *object = qobject_cast(component.create()); + std::unique_ptr object { qobject_cast(component.create()) }; checkNoErrors(component); - QVERIFY(object != nullptr); + QVERIFY(object); QCOMPARE(object->rect().x(), 13); object->setProperty("value", 99); QCOMPARE(object->rect().x(), 112); - - delete object; } // Test that you can't assign a binding to the "root" value type, and a sub-property @@ -1194,11 +1074,10 @@ void tst_qqmlvaluetypes::bindingConflict() #define CPP_TEST(type, v) \ { \ - type *t = new type; \ + std::unique_ptr t = std::make_unique(); \ QVariant value(v); \ t->setValue(value); \ QCOMPARE(t->value(), value); \ - delete t; \ } // Test that accessing a reference to a valuetype after the owning object is deleted @@ -1207,87 +1086,76 @@ void tst_qqmlvaluetypes::deletedObject() { QQmlComponent component(&engine, testFileUrl("deletedObject.qml")); QTest::ignoreMessage(QtDebugMsg, "Test: 2"); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); - QObject *dObject = qvariant_cast(object->property("object")); - QVERIFY(dObject != nullptr); - delete dObject; + std::unique_ptr dObject { qvariant_cast(object->property("object")) }; + QVERIFY(dObject); + dObject.reset(); QTest::ignoreMessage(QtDebugMsg, "Test: undefined"); object->emitRunScript(); - - delete object; } // Test that value types can be assigned to another value type property in a binding void tst_qqmlvaluetypes::bindingVariantCopy() { QQmlComponent component(&engine, testFileUrl("bindingVariantCopy.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->rect(), QRect(19, 33, 5, 99)); - - delete object; } // Test that value types can be assigned to another value type property in script void tst_qqmlvaluetypes::scriptVariantCopy() { QQmlComponent component(&engine, testFileUrl("scriptVariantCopy.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->rect(), QRect(2, 3, 109, 102)); object->emitRunScript(); QCOMPARE(object->rect(), QRect(19, 33, 5, 99)); - - delete object; } void tst_qqmlvaluetypes::enums() { { QQmlComponent component(&engine, testFileUrl("enums.1.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->font().capitalization(), QFont::AllUppercase); - delete object; } { QQmlComponent component(&engine, testFileUrl("enums.2.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->font().capitalization(), QFont::AllUppercase); - delete object; } { QQmlComponent component(&engine, testFileUrl("enums.3.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->font().capitalization(), QFont::AllUppercase); - delete object; } { QQmlComponent component(&engine, testFileUrl("enums.4.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->font().capitalization(), QFont::AllUppercase); - delete object; } { QQmlComponent component(&engine, testFileUrl("enums.5.qml")); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != nullptr); + std::unique_ptr object { qobject_cast(component.create()) }; + QVERIFY(object); QCOMPARE(object->font().capitalization(), QFont::AllUppercase); - delete object; } } @@ -1297,83 +1165,73 @@ void tst_qqmlvaluetypes::conflictingBindings() { { QQmlComponent component(&engine, testFileUrl("conflicting.1.qml")); - QObject *object = component.create(); - QVERIFY(object != nullptr); + std::unique_ptr object { component.create() }; + QVERIFY(object); QCOMPARE(qvariant_cast(object->property("font")).pixelSize(), 12); - QMetaObject::invokeMethod(object, "toggle"); + QMetaObject::invokeMethod(object.get(), "toggle"); QCOMPARE(qvariant_cast(object->property("font")).pixelSize(), 6); - QMetaObject::invokeMethod(object, "toggle"); + QMetaObject::invokeMethod(object.get(), "toggle"); QCOMPARE(qvariant_cast(object->property("font")).pixelSize(), 12); - - delete object; } { QQmlComponent component(&engine, testFileUrl("conflicting.2.qml")); - QObject *object = component.create(); - QVERIFY(object != nullptr); + std::unique_ptr object { component.create() }; + QVERIFY(object); QCOMPARE(qvariant_cast(object->property("font")).pixelSize(), 6); - QMetaObject::invokeMethod(object, "toggle"); + QMetaObject::invokeMethod(object.get(), "toggle"); QCOMPARE(qvariant_cast(object->property("font")).pixelSize(), 12); - QMetaObject::invokeMethod(object, "toggle"); + QMetaObject::invokeMethod(object.get(), "toggle"); QCOMPARE(qvariant_cast(object->property("font")).pixelSize(), 6); - - delete object; } { QQmlComponent component(&engine, testFileUrl("conflicting.3.qml")); - QObject *object = component.create(); - QVERIFY(object != nullptr); + std::unique_ptr object { component.create() }; + QVERIFY(object); QCOMPARE(qvariant_cast(object->property("font")).pixelSize(), 12); - QMetaObject::invokeMethod(object, "toggle"); + QMetaObject::invokeMethod(object.get(), "toggle"); QCOMPARE(qvariant_cast(object->property("font")).pixelSize(), 24); - QMetaObject::invokeMethod(object, "toggle"); + QMetaObject::invokeMethod(object.get(), "toggle"); QCOMPARE(qvariant_cast(object->property("font")).pixelSize(), 12); - - delete object; } } void tst_qqmlvaluetypes::returnValues() { QQmlComponent component(&engine, testFileUrl("returnValues.qml")); - QObject *object = component.create(); - QVERIFY(object != nullptr); + std::unique_ptr object { component.create() }; + QVERIFY(object); QCOMPARE(object->property("test1").toBool(), true); QCOMPARE(object->property("test2").toBool(), true); QCOMPARE(object->property("size").toSize(), QSize(13, 14)); - - delete object; } void tst_qqmlvaluetypes::varAssignment() { QQmlComponent component(&engine, testFileUrl("varAssignment.qml")); - QObject *object = component.create(); - QVERIFY(object != nullptr); + std::unique_ptr object { component.create() }; + QVERIFY(object); QCOMPARE(object->property("x").toInt(), 1); QCOMPARE(object->property("y").toInt(), 2); QCOMPARE(object->property("z").toInt(), 3); - - delete object; } // Test bindings splice together correctly @@ -1381,77 +1239,63 @@ void tst_qqmlvaluetypes::bindingsSpliceCorrectly() { { QQmlComponent component(&engine, testFileUrl("bindingsSpliceCorrectly.1.qml")); - QObject *object = component.create(); - QVERIFY(object != nullptr); + std::unique_ptr object { component.create() }; + QVERIFY(object); QCOMPARE(object->property("test").toBool(), true); - - delete object; } { QQmlComponent component(&engine, testFileUrl("bindingsSpliceCorrectly.2.qml")); - QObject *object = component.create(); - QVERIFY(object != nullptr); + std::unique_ptr object { component.create() }; + QVERIFY(object); QCOMPARE(object->property("test").toBool(), true); - - delete object; } { QQmlComponent component(&engine, testFileUrl("bindingsSpliceCorrectly.3.qml")); - QObject *object = component.create(); - QVERIFY(object != nullptr); + std::unique_ptr object { component.create() }; + QVERIFY(object); QCOMPARE(object->property("test").toBool(), true); - - delete object; } { QQmlComponent component(&engine, testFileUrl("bindingsSpliceCorrectly.4.qml")); - QObject *object = component.create(); - QVERIFY(object != nullptr); + std::unique_ptr object { component.create() }; + QVERIFY(object); QCOMPARE(object->property("test").toBool(), true); - - delete object; } { QQmlComponent component(&engine, testFileUrl("bindingsSpliceCorrectly.5.qml")); - QObject *object = component.create(); - QVERIFY(object != nullptr); + std::unique_ptr object { component.create() }; + QVERIFY(object); QCOMPARE(object->property("test").toBool(), true); - - delete object; } } void tst_qqmlvaluetypes::nonValueTypeComparison() { QQmlComponent component(&engine, testFileUrl("nonValueTypeComparison.qml")); - QObject *object = component.create(); - QVERIFY(object != nullptr); + std::unique_ptr object { component.create() }; + QVERIFY(object); QCOMPARE(object->property("test1").toBool(), true); QCOMPARE(object->property("test2").toBool(), true); - - delete object; } void tst_qqmlvaluetypes::initializeByWrite() { QQmlComponent component(&engine, testFileUrl("initializeByWrite.qml")); - QObject *object = component.create(); - QVERIFY(object != nullptr); + std::unique_ptr object { component.create() }; + QVERIFY(object); QCOMPARE(object->property("test").toBool(), true); - - delete object; } void tst_qqmlvaluetypes::groupedInterceptors_data() @@ -1485,8 +1329,8 @@ void tst_qqmlvaluetypes::groupedInterceptors() QFETCH(QColor, expectedFinalColor); QQmlComponent component(&engine, testFileUrl(qmlfile)); - QObject *object = component.create(); - QVERIFY2(object != nullptr, qPrintable(component.errorString())); + std::unique_ptr object { component.create() }; + QVERIFY2(object.get(), qPrintable(component.errorString())); QColor initialColor = object->property("color").value(); QVERIFY(fuzzyCompare(initialColor.redF(), expectedInitialColor.redF())); @@ -1501,8 +1345,6 @@ void tst_qqmlvaluetypes::groupedInterceptors() QVERIFY(fuzzyCompare(finalColor.greenF(), expectedFinalColor.greenF())); QVERIFY(fuzzyCompare(finalColor.blueF(), expectedFinalColor.blueF())); QVERIFY(fuzzyCompare(finalColor.alphaF(), expectedFinalColor.alphaF())); - - delete object; } struct MyDesk