aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp')
-rw-r--r--tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp752
1 files changed, 361 insertions, 391 deletions
diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
index cf02195d52..2634044238 100644
--- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
+++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <qtest.h>
#include <QQmlEngine>
@@ -36,7 +11,7 @@
#include <private/qqmlglobal_p.h>
#include <private/qv4engine_p.h>
#include <private/qv4variantobject_p.h>
-#include "../../shared/util.h"
+#include <QtQuickTestUtils/private/qmlutils_p.h>
#include "testtypes.h"
QT_BEGIN_NAMESPACE
@@ -47,7 +22,7 @@ class tst_qqmlvaluetypes : public QQmlDataTest
{
Q_OBJECT
public:
- tst_qqmlvaluetypes() {}
+ tst_qqmlvaluetypes() : QQmlDataTest(QT_QMLTEST_DATADIR) {}
private slots:
void initTestCase() override;
@@ -100,6 +75,9 @@ private slots:
void scarceTypes();
void nonValueTypes();
void char16Type();
+ void writeBackOnFunctionCall();
+ void valueTypeConversions();
+ void readReferenceOnGetOwnProperty();
private:
QQmlEngine engine;
@@ -115,30 +93,26 @@ void tst_qqmlvaluetypes::point()
{
{
QQmlComponent component(&engine, testFileUrl("point_read.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QCOMPARE(object->point(), QPoint(11, 12));
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("point_compare.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QString tostring = QLatin1String("QPoint(10, 4)");
QCOMPARE(object->property("tostring").toString(), tostring);
@@ -151,8 +125,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;
}
}
@@ -160,30 +132,26 @@ void tst_qqmlvaluetypes::pointf()
{
{
QQmlComponent component(&engine, testFileUrl("pointf_read.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QString tostring = QLatin1String("QPointF(11.3, -10.9)");
QCOMPARE(object->property("tostring").toString(), tostring);
@@ -196,8 +164,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;
}
}
@@ -205,30 +171,26 @@ void tst_qqmlvaluetypes::size()
{
{
QQmlComponent component(&engine, testFileUrl("size_read.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QCOMPARE(object->size(), QSize(13, 88));
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("size_compare.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QString tostring = QLatin1String("QSize(1912, 1913)");
QCOMPARE(object->property("tostring").toString(), tostring);
@@ -241,8 +203,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;
}
}
@@ -250,30 +210,26 @@ void tst_qqmlvaluetypes::sizef()
{
{
QQmlComponent component(&engine, testFileUrl("sizef_read.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QString tostring = QLatin1String("QSizeF(0.1, 100923)");
QCOMPARE(object->property("tostring").toString(), tostring);
@@ -286,15 +242,14 @@ void tst_qqmlvaluetypes::sizef()
QCOMPARE(object->property("equalsSelf").toBool(), true);
QCOMPARE(object->property("equalsOther").toBool(), false);
QCOMPARE(object->property("sizefEqualsSize").toBool(), true);
-
- delete object;
}
}
void tst_qqmlvaluetypes::locale()
{
- {
- QQmlComponent component(&engine, testFileUrl("locale_read.qml"));
+ for (const QUrl &testFile :
+ { testFileUrl("locale_read.qml"), testFileUrl("locale_read_singleton.qml") }) {
+ QQmlComponent component(&engine, testFile);
QScopedPointer<QObject> object(component.create());
QVERIFY(!object.isNull());
@@ -311,7 +266,7 @@ void tst_qqmlvaluetypes::locale()
QCOMPARE(object->property("groupSeparator").toString().at(0), locale.groupSeparator());
QCOMPARE(object->property("measurementSystem").toInt(), int(locale.measurementSystem()));
QCOMPARE(object->property("name").toString(), locale.name());
- QCOMPARE(object->property("nativeCountryName").toString(), locale.nativeCountryName());
+ QCOMPARE(object->property("nativeCountryName").toString(), locale.nativeTerritoryName());
QCOMPARE(object->property("nativeLanguageName").toString(), locale.nativeLanguageName());
QCOMPARE(object->property("negativeSign").toString().at(0), locale.negativeSign());
QCOMPARE(object->property("percent").toString().at(0), locale.percent());
@@ -320,9 +275,9 @@ void tst_qqmlvaluetypes::locale()
QCOMPARE(object->property("textDirection").toInt(), int(locale.textDirection()));
QCOMPARE(object->property("uiLanguages").toStringList(), locale.uiLanguages());
QList<Qt::DayOfWeek> weekDays;
- foreach (const QVariant &weekDay, object->property("weekDays").toList()) {
+ const QVariantList weekDaysProperty = object->property("weekDays").toList();
+ for (const QVariant &weekDay : weekDaysProperty)
weekDays.append(Qt::DayOfWeek(weekDay.toInt()));
- }
QCOMPARE(weekDays, locale.weekdays());
QCOMPARE(object->property("zeroDigit").toString().at(0), locale.zeroDigit());
#endif // im
@@ -332,29 +287,25 @@ void tst_qqmlvaluetypes::locale()
void tst_qqmlvaluetypes::qmlproperty()
{
QQmlComponent component(&engine, testFileUrl("qmlproperty_read.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
- QCOMPARE(object->property("colorPropertyObject").value<QObject *>(), object);
+ QCOMPARE(object->property("colorPropertyObject").value<QObject *>(), object.get());
QCOMPARE(object->property("colorPropertyName").toString(), "color");
QCOMPARE(object->property("invalidPropertyObject").value<QObject *>(), nullptr);
QCOMPARE(object->property("invalidPropertyName").toString(), "");
-
- delete object;
}
void tst_qqmlvaluetypes::sizereadonly()
{
{
QQmlComponent component(&engine, testFileUrl("sizereadonly_read.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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;
}
{
@@ -378,12 +329,10 @@ void tst_qqmlvaluetypes::sizereadonly()
{
QQmlComponent component(&engine, testFileUrl("sizereadonly_writeerror4.qml"));
- QObject *object = component.create();
+ std::unique_ptr<QObject> object { component.create() };
QVERIFY(object);
QCOMPARE(object->property("sizereadonly").toSize(), QSize(1912, 1913));
-
- delete object;
}
}
@@ -391,8 +340,8 @@ void tst_qqmlvaluetypes::rect()
{
{
QQmlComponent component(&engine, testFileUrl("rect_read.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QCOMPARE(object->property("r_x").toInt(), 2);
QCOMPARE(object->property("r_y").toInt(), 3);
@@ -403,24 +352,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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QString tostring = QLatin1String("QRect(2, 3, 109, 102)");
QCOMPARE(object->property("tostring").toString(), tostring);
@@ -433,8 +378,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;
}
}
@@ -442,8 +385,8 @@ void tst_qqmlvaluetypes::rectf()
{
{
QQmlComponent component(&engine, testFileUrl("rectf_read.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QCOMPARE(float(object->property("r_x").toDouble()), float(103.8));
QCOMPARE(float(object->property("r_y").toDouble()), float(99.2));
@@ -454,24 +397,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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QString tostring = QLatin1String("QRectF(103.8, 99.2, 88.1, 77.6)");
QCOMPARE(object->property("tostring").toString(), tostring);
@@ -484,8 +423,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;
}
}
@@ -493,30 +430,26 @@ void tst_qqmlvaluetypes::vector2d()
{
{
QQmlComponent component(&engine, testFileUrl("vector2d_read.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QString tostring = QLatin1String("QVector2D(32.88, 1.3)");
QCOMPARE(object->property("tostring").toString(), tostring);
@@ -527,16 +460,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<QObject> object { component.create() };
+ QVERIFY(object);
QVERIFY(object->property("success").toBool());
- delete object;
}
}
@@ -544,31 +474,27 @@ void tst_qqmlvaluetypes::vector3d()
{
{
QQmlComponent component(&engine, testFileUrl("vector3d_read.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QString tostring = QLatin1String("QVector3D(23.88, 3.1, 4.3)");
QCOMPARE(object->property("tostring").toString(), tostring);
@@ -580,16 +506,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<QObject> object { component.create() };
+ QVERIFY(object);
QVERIFY(object->property("success").toBool());
- delete object;
}
}
@@ -597,32 +520,28 @@ void tst_qqmlvaluetypes::vector4d()
{
{
QQmlComponent component(&engine, testFileUrl("vector4d_read.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QString tostring = QLatin1String("QVector4D(54.2, 23.88, 3.1, 4.3)");
QCOMPARE(object->property("tostring").toString(), tostring);
@@ -633,16 +552,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<QObject> object { component.create() };
+ QVERIFY(object);
QVERIFY(object->property("success").toBool());
- delete object;
}
}
@@ -650,32 +566,28 @@ void tst_qqmlvaluetypes::quaternion()
{
{
QQmlComponent component(&engine, testFileUrl("quaternion_read.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QString tostring = QLatin1String("QQuaternion(4.3, 54.2, 23.88, 3.1)");
QCOMPARE(object->property("tostring").toString(), tostring);
@@ -686,8 +598,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"));
+ std::unique_ptr<QObject> object { component.create() };
+ QVERIFY(object);
+ QVERIFY(object->property("success").toBool());
}
}
@@ -695,8 +612,8 @@ void tst_qqmlvaluetypes::matrix4x4()
{
{
QQmlComponent component(&engine, testFileUrl("matrix4x4_read.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QCOMPARE((float)object->property("v_m11").toDouble(), (float)1);
QCOMPARE((float)object->property("v_m12").toDouble(), (float)2);
@@ -719,27 +636,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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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);
@@ -750,16 +663,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<QObject> object { component.create() };
+ QVERIFY(object);
QCOMPARE(object->property("success").toBool(), true);
- delete object;
}
}
@@ -767,9 +677,9 @@ void tst_qqmlvaluetypes::font()
{
{
QQmlComponent component(&engine, testFileUrl("font_read.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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());
@@ -796,14 +706,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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QFont font;
font.setFamily("Helvetica");
@@ -828,46 +736,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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QCOMPARE(object->font().pixelSize(), 10);
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("font_write.5.qml"));
- QObject *object = qobject_cast<QObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<QObject> object { qobject_cast<QObject *>(component.create()) };
+ QVERIFY(object);
MyTypeObject *object1 = object->findChild<MyTypeObject *>("object1");
QVERIFY(object1 != nullptr);
MyTypeObject *object2 = object->findChild<MyTypeObject *>("object2");
@@ -875,14 +775,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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QString tostring = QLatin1String("QFont(") + object->font().toString() + QLatin1Char(')');
QCOMPARE(object->property("tostring").toString(), tostring);
@@ -893,8 +791,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;
}
}
@@ -902,13 +798,13 @@ void tst_qqmlvaluetypes::color()
{
{
QQmlComponent component(&engine, testFileUrl("color_read.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
- 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);
+ QCOMPARE(float(object->property("v_r").toDouble()), 0.2f);
+ QCOMPARE(float(object->property("v_g").toDouble()), 0.88f);
+ QCOMPARE(float(object->property("v_b").toDouble()), 0.6f);
+ QCOMPARE(float(object->property("v_a").toDouble()), 0.34f);
QCOMPARE(qRound(object->property("hsv_h").toDouble() * 100), 43);
QCOMPARE(qRound(object->property("hsv_s").toDouble() * 100), 77);
@@ -924,63 +820,55 @@ void tst_qqmlvaluetypes::color()
QVERIFY(!object->property("invalid").toBool());
QColor comparison;
- comparison.setRedF(0.2);
- comparison.setGreenF(0.88);
- comparison.setBlueF(0.6);
- comparison.setAlphaF(0.34);
+ comparison.setRedF(0.2f);
+ comparison.setGreenF(0.88f);
+ 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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QColor newColor;
- newColor.setRedF(0.5);
- newColor.setGreenF(0.38);
- newColor.setBlueF(0.3);
- newColor.setAlphaF(0.7);
+ newColor.setRedF(0.5f);
+ newColor.setGreenF(0.38f);
+ 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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QColor newColor;
- newColor.setHsvF(0.43, 0.77, 0.88, 0.7);
+ 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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QColor newColor;
- newColor.setHslF(0.43, 0.74, 0.54, 0.7);
+ 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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QColor comparison;
- comparison.setRedF(0.2);
- comparison.setGreenF(0.88);
- comparison.setBlueF(0.6);
- comparison.setAlphaF(0.34);
+ comparison.setRedF(0.2f);
+ comparison.setGreenF(0.88f);
+ comparison.setBlueF(0.6f);
+ comparison.setAlphaF(0.34f);
QString colorString = comparison.name(QColor::HexArgb);
QCOMPARE(object->property("colorToString").toString(), colorString);
QCOMPARE(object->property("colorEqualsIdenticalRgba").toBool(), true);
@@ -1003,8 +891,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;
}
}
@@ -1014,8 +900,8 @@ void tst_qqmlvaluetypes::bindingAssignment()
// binding declaration
{
QQmlComponent component(&engine, testFileUrl("bindingAssignment.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QCOMPARE(object->rect().x(), 10);
QCOMPARE(object->rect().y(), 15);
@@ -1024,8 +910,6 @@ void tst_qqmlvaluetypes::bindingAssignment()
QCOMPARE(object->rect().x(), 92);
QCOMPARE(object->rect().y(), 97);
-
- delete object;
}
// function assignment should fail without crashing
@@ -1035,12 +919,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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QCOMPARE(object->rect().x(), 5);
object->setProperty("value", QVariant(92));
QCOMPARE(object->rect().x(), 5);
- delete object;
}
}
@@ -1048,42 +931,36 @@ void tst_qqmlvaluetypes::bindingAssignment()
void tst_qqmlvaluetypes::bindingRead()
{
QQmlComponent component(&engine, testFileUrl("bindingRead.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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
@@ -1091,8 +968,8 @@ void tst_qqmlvaluetypes::autoBindingRemoval()
{
{
QQmlComponent component(&engine, testFileUrl("autoBindingRemoval.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QCOMPARE(object->rect().x(), 10);
@@ -1107,14 +984,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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QCOMPARE(object->rect().x(), 10);
@@ -1129,16 +1004,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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
object->setProperty("value", QVariant(QRect(9, 22, 33, 44)));
@@ -1151,8 +1024,6 @@ void tst_qqmlvaluetypes::autoBindingRemoval()
object->setProperty("value", QVariant(QRect(19, 3, 4, 8)));
QCOMPARE(object->rect(), QRect(44, 22, 33, 44));
-
- delete object;
}
}
@@ -1160,12 +1031,10 @@ void tst_qqmlvaluetypes::autoBindingRemoval()
void tst_qqmlvaluetypes::valueSources()
{
QQmlComponent component(&engine, testFileUrl("valueSources.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QCOMPARE(object->rect().x(), 3345);
-
- delete object;
}
static void checkNoErrors(QQmlComponent& component)
@@ -1173,7 +1042,7 @@ static void checkNoErrors(QQmlComponent& component)
QList<QQmlError> errors = component.errors();
if (errors.isEmpty())
return;
- for (int ii = 0; ii < errors.count(); ++ii) {
+ for (int ii = 0; ii < errors.size(); ++ii) {
const QQmlError &error = errors.at(ii);
qWarning("%d:%d:%s",error.line(),error.column(),error.description().toUtf8().constData());
}
@@ -1183,17 +1052,15 @@ static void checkNoErrors(QQmlComponent& component)
void tst_qqmlvaluetypes::valueInterceptors()
{
QQmlComponent component(&engine, testFileUrl("valueInterceptors.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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
@@ -1205,11 +1072,10 @@ void tst_qqmlvaluetypes::bindingConflict()
#define CPP_TEST(type, v) \
{ \
- type *t = new type; \
+ std::unique_ptr<type> t = std::make_unique<type>(); \
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
@@ -1218,87 +1084,76 @@ void tst_qqmlvaluetypes::deletedObject()
{
QQmlComponent component(&engine, testFileUrl("deletedObject.qml"));
QTest::ignoreMessage(QtDebugMsg, "Test: 2");
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
- QObject *dObject = qvariant_cast<QObject *>(object->property("object"));
- QVERIFY(dObject != nullptr);
- delete dObject;
+ std::unique_ptr<QObject> dObject { qvariant_cast<QObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(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<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QCOMPARE(object->font().capitalization(), QFont::AllUppercase);
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("enums.2.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QCOMPARE(object->font().capitalization(), QFont::AllUppercase);
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("enums.3.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QCOMPARE(object->font().capitalization(), QFont::AllUppercase);
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("enums.4.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QCOMPARE(object->font().capitalization(), QFont::AllUppercase);
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("enums.5.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
+ std::unique_ptr<MyTypeObject> object { qobject_cast<MyTypeObject *>(component.create()) };
+ QVERIFY(object);
QCOMPARE(object->font().capitalization(), QFont::AllUppercase);
- delete object;
}
}
@@ -1308,83 +1163,73 @@ void tst_qqmlvaluetypes::conflictingBindings()
{
{
QQmlComponent component(&engine, testFileUrl("conflicting.1.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ std::unique_ptr<QObject> object { component.create() };
+ QVERIFY(object);
QCOMPARE(qvariant_cast<QFont>(object->property("font")).pixelSize(), 12);
- QMetaObject::invokeMethod(object, "toggle");
+ QMetaObject::invokeMethod(object.get(), "toggle");
QCOMPARE(qvariant_cast<QFont>(object->property("font")).pixelSize(), 6);
- QMetaObject::invokeMethod(object, "toggle");
+ QMetaObject::invokeMethod(object.get(), "toggle");
QCOMPARE(qvariant_cast<QFont>(object->property("font")).pixelSize(), 12);
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("conflicting.2.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ std::unique_ptr<QObject> object { component.create() };
+ QVERIFY(object);
QCOMPARE(qvariant_cast<QFont>(object->property("font")).pixelSize(), 6);
- QMetaObject::invokeMethod(object, "toggle");
+ QMetaObject::invokeMethod(object.get(), "toggle");
QCOMPARE(qvariant_cast<QFont>(object->property("font")).pixelSize(), 12);
- QMetaObject::invokeMethod(object, "toggle");
+ QMetaObject::invokeMethod(object.get(), "toggle");
QCOMPARE(qvariant_cast<QFont>(object->property("font")).pixelSize(), 6);
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("conflicting.3.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ std::unique_ptr<QObject> object { component.create() };
+ QVERIFY(object);
QCOMPARE(qvariant_cast<QFont>(object->property("font")).pixelSize(), 12);
- QMetaObject::invokeMethod(object, "toggle");
+ QMetaObject::invokeMethod(object.get(), "toggle");
QCOMPARE(qvariant_cast<QFont>(object->property("font")).pixelSize(), 24);
- QMetaObject::invokeMethod(object, "toggle");
+ QMetaObject::invokeMethod(object.get(), "toggle");
QCOMPARE(qvariant_cast<QFont>(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<QObject> 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<QObject> 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
@@ -1392,77 +1237,63 @@ void tst_qqmlvaluetypes::bindingsSpliceCorrectly()
{
{
QQmlComponent component(&engine, testFileUrl("bindingsSpliceCorrectly.1.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ std::unique_ptr<QObject> 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<QObject> 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<QObject> 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<QObject> 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<QObject> 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<QObject> 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<QObject> object { component.create() };
+ QVERIFY(object);
QCOMPARE(object->property("test").toBool(), true);
-
- delete object;
}
void tst_qqmlvaluetypes::groupedInterceptors_data()
@@ -1496,8 +1327,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<QObject> object { component.create() };
+ QVERIFY2(object.get(), qPrintable(component.errorString()));
QColor initialColor = object->property("color").value<QColor>();
QVERIFY(fuzzyCompare(initialColor.redF(), expectedInitialColor.redF()));
@@ -1512,8 +1343,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
@@ -1703,8 +1532,8 @@ void tst_qqmlvaluetypes::sequences()
{
QList<BaseGadget> gadgetList{1, 4, 7, 8, 15};
QJSValue value = engine.toScriptValue(gadgetList);
- QCOMPARE(value.property("length").toInt(), gadgetList.length());
- for (int i = 0; i < gadgetList.length(); ++i)
+ QCOMPARE(value.property("length").toInt(), gadgetList.size());
+ for (int i = 0; i < gadgetList.size(); ++i)
QCOMPARE(value.property(i).property("baseProperty").toInt(), gadgetList.at(i).baseProperty());
}
{
@@ -1712,13 +1541,13 @@ void tst_qqmlvaluetypes::sequences()
QJSValue value = engine.toScriptValue(container);
QCOMPARE(value.property("length").toInt(), int(container.size()));
for (size_t i = 0; i < container.size(); ++i)
- QCOMPARE(value.property(i).property("baseProperty").toInt(), container.at(i).baseProperty());
+ QCOMPARE(value.property(quint32(i)).property("baseProperty").toInt(), container.at(i).baseProperty());
}
{
QVector<QChar> qcharVector{QChar(1), QChar(4), QChar(42), QChar(8), QChar(15)};
QJSValue value = engine.toScriptValue(qcharVector);
- QCOMPARE(value.property("length").toInt(), qcharVector.length());
- for (int i = 0; i < qcharVector.length(); ++i)
+ QCOMPARE(value.property("length").toInt(), qcharVector.size());
+ for (int i = 0; i < qcharVector.size(); ++i)
QCOMPARE(value.property(i).toString(), qcharVector.at(i));
}
{
@@ -1780,7 +1609,7 @@ void tst_qqmlvaluetypes::enumerableProperties()
names.insert(name);
}
- QCOMPARE(names.count(), 2);
+ QCOMPARE(names.size(), 2);
QVERIFY(names.contains(QStringLiteral("baseProperty")));
QVERIFY(names.contains(QStringLiteral("derivedProperty")));
}
@@ -1862,6 +1691,147 @@ void tst_qqmlvaluetypes::char16Type()
QCOMPARE(scoped->toQString(), "a");
}
+struct Foo {
+ Q_GADGET
+ QML_ANONYMOUS
+public:
+ int val = 1;
+ Q_INVOKABLE int value() const { return val; }
+ Q_INVOKABLE void setValue(int v) { val = v; }
+};
+
+Q_DECLARE_METATYPE(Foo);
+
+class S : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(Foo foo READ foo WRITE setFoo NOTIFY fooChanged);
+ QML_ELEMENT
+public:
+ int writeCount = 0;
+ Foo f;
+ Foo foo() { return f; }
+ void setFoo(Foo f)
+ {
+ ++writeCount;
+ this->f = f;
+ emit fooChanged();
+ }
+ Q_INVOKABLE Foo get() { return f; }
+signals:
+ void fooChanged();
+};
+
+void tst_qqmlvaluetypes::writeBackOnFunctionCall()
+{
+ qmlRegisterTypesAndRevisions<Foo>("WriteBack", 1);
+ qmlRegisterTypesAndRevisions<S>("WriteBack", 1);
+
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.setData("import QtQml 2.15\n"
+ "import WriteBack 1.0\n"
+ "QtObject {\n"
+ " property S s: S {}\n"
+ " property int a: -1\n"
+ " property int b: -1\n"
+ " Component.onCompleted: {\n"
+ " var f = s.foo\n"
+ " f.setValue(3)\n"
+ " s.foo = f\n"
+ " a = f.value()\n"
+ " f = s.get()\n"
+ " f.setValue(3)\n"
+ " b = f.value()\n"
+ " }\n"
+ "}\n", QUrl());
+ QVERIFY2(component.isReady(), component.errorString().toUtf8());
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY(!o.isNull());
+ QCOMPARE(o->property("a").toInt(), 3);
+ QCOMPARE(o->property("b").toInt(), 3);
+ S *s = qvariant_cast<S *>(o->property("s"));
+ QVERIFY(s);
+ // f.value() should not write back.
+ QCOMPARE(s->writeCount, 2);
+}
+
+struct TypeB;
+struct TypeA
+{
+ Q_GADGET
+
+public:
+ TypeA() = default;
+ TypeA(const TypeB &other);
+ TypeA &operator=(const TypeB &other);
+
+ int a = 4;
+};
+
+struct TypeB
+{
+ Q_GADGET
+
+public:
+ TypeB() = default;
+ TypeB(const TypeA &other) : b(other.a) {}
+ TypeB &operator=(const TypeA &other) { b = other.a; return *this; }
+
+ int b = 5;
+};
+
+TypeA::TypeA(const TypeB &other) : a(other.b) {}
+TypeA &TypeA::operator=(const TypeB &other) { a = other.b; return *this; }
+
+void tst_qqmlvaluetypes::valueTypeConversions()
+{
+ QMetaType::registerConverter<TypeA, TypeB>();
+ QMetaType::registerConverter<TypeB, TypeA>();
+
+ TypeA a;
+ TypeB b;
+
+ QJSEngine engine;
+ QJSValue jsA = engine.toScriptValue(a);
+ QJSValue jsB = engine.toScriptValue(b);
+
+ TypeA resultA = engine.fromScriptValue<TypeA>(jsB);
+ TypeB resultB = engine.fromScriptValue<TypeB>(jsA);
+
+ QCOMPARE(resultA.a, b.b);
+ QCOMPARE(resultB.b, a.a);
+}
+
+class Chose : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QRectF f READ ff CONSTANT)
+public:
+ Chose(QObject *parent = nullptr) : QObject(parent) {}
+ QRectF ff() const { return QRectF(); }
+ Q_INVOKABLE bool g(QJSValue v) { return v.hasProperty("x"); }
+};
+
+void tst_qqmlvaluetypes::readReferenceOnGetOwnProperty()
+{
+ Chose chose;
+ QQmlEngine engine;
+ engine.rootContext()->setContextProperty(QStringLiteral("chose"), &chose);
+ QQmlComponent c(&engine);
+ c.setData(R"fin(
+ import QtQml
+ QtObject {
+ property bool allo: chose.g(chose.f)
+ }
+ )fin", QUrl());
+
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(!o.isNull());
+ QVERIFY(o->property("allo").toBool());
+}
+
#undef CHECK_TYPE_IS_NOT_VALUETYPE
QTEST_MAIN(tst_qqmlvaluetypes)