aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlecmascript
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-05-07 12:32:46 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2021-05-11 16:20:55 +0200
commite8ea7a12623b2189c6186965ffec4d7c17798e82 (patch)
tree3c79526f1281e7d3203b87a93ac4f0a652e91a8a /tests/auto/qml/qqmlecmascript
parentcb25a1d13d331a5b26d5dac963cd88497264c770 (diff)
Clean up tst_qqmlecmascript: don't leak on failure
Lots of tests were following the antipattern of deleting a pointer after the last QVERIFY() or QCOMPARE(), which leads to the pointer being leaked on failure. Use QScopedPointer consistently (it was already in use patchily). That changed one mis-use of QPointer (that was only checked for non-null immediately on creation, never referenced later, so being cleared on deletion wasn't relevant; and thus needed an overt delete, that QScopedPointer made redundant); but another appears to be deliberate, so documented that as such (to the best of my understanding, gc is meant to pick it up). This mostly arose with component.create() results, most of which were checked, albeit in inconsistent ways. Always check these before dereferencing, and use the same form for the check in all cases: use QScopedPointer's in-built cast-to-bool rather than !isNull(); and report the component.errorString(), using QVERIFY2(), on failure. In many cases the return from component.create() is passed through a qobject_cast<> before use; in principle, this could result in null even though create() returned a non-null pointer. Convert those to hold the return from create() in the QScopedPointer<> and cast its data() to get a plain pointer for subsequent use. Split assorted lines that got long (or longer) as a result. Removed a fatuous empty constructor. Change-Id: I88abba9e7ea72e30c92a11a5af5f17486f07f847 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript')
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp2080
1 files changed, 933 insertions, 1147 deletions
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 6f2e241cc1..db878bc325 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2017 Crimson AS <info@crimson.no>
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -71,8 +71,6 @@ Static QML language issues are covered in qmllanguage
class tst_qqmlecmascript : public QQmlDataTest
{
Q_OBJECT
-public:
- tst_qqmlecmascript() {}
private slots:
void initTestCase() override;
@@ -480,7 +478,9 @@ void tst_qqmlecmascript::assignBasicTypes()
QQmlEngine engine;
{
QQmlComponent component(&engine, testFileUrl("assignBasicTypes.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyTypeObject *object = qobject_cast<MyTypeObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->flagProperty(), MyTypeObject::FlagVal1 | MyTypeObject::FlagVal3);
QCOMPARE(object->enumProperty(), MyTypeObject::EnumVal2);
@@ -505,11 +505,12 @@ void tst_qqmlecmascript::assignBasicTypes()
QCOMPARE(object->variantProperty(), QVariant("Hello World!"));
QCOMPARE(object->vectorProperty(), QVector3D(10, 1, 2.2f));
QCOMPARE(object->urlProperty(), QUrl("main.qml"));
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("assignBasicTypes.2.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyTypeObject *object = qobject_cast<MyTypeObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->flagProperty(), MyTypeObject::FlagVal1 | MyTypeObject::FlagVal3);
QCOMPARE(object->enumProperty(), MyTypeObject::EnumVal2);
@@ -534,7 +535,6 @@ void tst_qqmlecmascript::assignBasicTypes()
QCOMPARE(object->variantProperty(), QVariant("Hello World!"));
QCOMPARE(object->vectorProperty(), QVector3D(10, 1, 2.2f));
QCOMPARE(object->urlProperty(), QUrl("main.qml"));
- delete object;
}
}
@@ -560,6 +560,7 @@ void tst_qqmlecmascript::assignDate()
QQmlEngine engine;
QQmlComponent component(&engine, source);
QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
MyTypeObject *object = qobject_cast<MyTypeObject *>(obj.data());
QVERIFY(object != nullptr);
@@ -644,6 +645,7 @@ void tst_qqmlecmascript::exportDate()
QQmlComponent component(&e, source);
QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
MyTypeObject *object = qobject_cast<MyTypeObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->boolProperty(), true);
@@ -681,6 +683,7 @@ void tst_qqmlecmascript::checkDate()
QQmlEngine e;
QQmlComponent component(&e, source);
QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
MyTypeObject *object = qobject_cast<MyTypeObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->dateProperty(), date);
@@ -722,6 +725,7 @@ void tst_qqmlecmascript::checkDateTime()
QQmlEngine e;
QQmlComponent component(&e, source);
QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
MyTypeObject *object = qobject_cast<MyTypeObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->dateTimeProperty(), when);
@@ -733,22 +737,24 @@ void tst_qqmlecmascript::idShortcutInvalidates()
QQmlEngine engine;
{
QQmlComponent component(&engine, testFileUrl("idShortcutInvalidates.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QVERIFY(object->objectProperty() != nullptr);
delete object->objectProperty();
QVERIFY(!object->objectProperty());
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("idShortcutInvalidates.1.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QVERIFY(object->objectProperty() != nullptr);
delete object->objectProperty();
QVERIFY(!object->objectProperty());
- delete object;
}
}
@@ -757,17 +763,19 @@ void tst_qqmlecmascript::boolPropertiesEvaluateAsBool()
QQmlEngine engine;
{
QQmlComponent component(&engine, testFileUrl("boolPropertiesEvaluateAsBool.1.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->stringProperty(), QLatin1String("pass"));
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("boolPropertiesEvaluateAsBool.2.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->stringProperty(), QLatin1String("pass"));
- delete object;
}
}
@@ -776,22 +784,24 @@ void tst_qqmlecmascript::signalAssignment()
QQmlEngine engine;
{
QQmlComponent component(&engine, testFileUrl("signalAssignment.1.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->string(), QString());
emit object->basicSignal();
QCOMPARE(object->string(), QString("pass"));
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("signalAssignment.2.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->string(), QString());
emit object->argumentSignal(19, "Hello world!", 10.25, MyQmlObject::EnumValue4, Qt::RightButton);
QCOMPARE(object->string(), QString("pass 19 Hello world! 10.25 3 2"));
- delete object;
}
{
@@ -814,24 +824,26 @@ void tst_qqmlecmascript::signalArguments()
QQmlEngine engine;
{
QQmlComponent component(&engine, testFileUrl("signalArguments.1.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->string(), QString());
emit object->basicSignal();
QCOMPARE(object->string(), QString("pass"));
QCOMPARE(object->property("argumentCount").toInt(), 0);
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("signalArguments.2.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->string(), QString());
emit object->argumentSignal(19, "Hello world!", 10.25, MyQmlObject::EnumValue4, Qt::RightButton);
QCOMPARE(object->string(), QString("pass 19 Hello world! 10.25 3 2"));
QCOMPARE(object->property("argumentCount").toInt(), 5);
- delete object;
}
}
@@ -840,52 +852,51 @@ void tst_qqmlecmascript::methods()
QQmlEngine engine;
{
QQmlComponent component(&engine, testFileUrl("methods.1.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->methodCalled(), false);
QCOMPARE(object->methodIntCalled(), false);
emit object->basicSignal();
QCOMPARE(object->methodCalled(), true);
QCOMPARE(object->methodIntCalled(), false);
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("methods.2.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->methodCalled(), false);
QCOMPARE(object->methodIntCalled(), false);
emit object->basicSignal();
QCOMPARE(object->methodCalled(), false);
QCOMPARE(object->methodIntCalled(), true);
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("methods.3.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toInt(), 19);
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("methods.4.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toInt(), 19);
QCOMPARE(object->property("test2").toInt(), 17);
QCOMPARE(object->property("test3").toInt(), 16);
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("methods.5.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toInt(), 9);
- delete object;
}
}
@@ -895,9 +906,8 @@ void tst_qqmlecmascript::bindingLoop()
QQmlComponent component(&engine, testFileUrl("bindingLoop.qml"));
QString warning = component.url().toString() + ":9:9: QML MyQmlObject: Binding loop detected for property \"stringProperty\"";
QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData());
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- delete object;
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
}
@@ -1063,14 +1073,14 @@ void tst_qqmlecmascript::contextPropertiesTriggerReeval()
QQmlContext context(engine.rootContext());
MyQmlObject object1;
MyQmlObject object2;
- MyQmlObject *object3 = new MyQmlObject;
+ QScopedPointer<MyQmlObject>object3(new MyQmlObject);
object1.setStringProperty("Hello");
object2.setStringProperty("World");
context.setContextProperty("testProp", QVariant(1));
context.setContextProperty("testObj", &object1);
- context.setContextProperty("testObj2", object3);
+ context.setContextProperty("testObj2", object3.data());
{
MyExpression expr(&context, "testProp + 1");
@@ -1115,10 +1125,9 @@ void tst_qqmlecmascript::contextPropertiesTriggerReeval()
{
MyExpression expr(&context, "testObj2");
QCOMPARE(expr.changed, false);
- QCOMPARE(expr.evaluate(), QVariant::fromValue((QObject *)object3));
+ QCOMPARE(expr.evaluate(), QVariant::fromValue((QObject *)object3.data()));
}
- delete object3;
}
void tst_qqmlecmascript::objectPropertiesTriggerReeval()
@@ -1192,8 +1201,9 @@ void tst_qqmlecmascript::deferredProperties()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("deferredProperties.qml"));
- MyDeferredObject *object =
- qobject_cast<MyDeferredObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyDeferredObject *object = qobject_cast<MyDeferredObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->value(), 0);
QVERIFY(!object->objectProperty());
@@ -1201,14 +1211,11 @@ void tst_qqmlecmascript::deferredProperties()
qmlExecuteDeferred(object);
QCOMPARE(object->value(), 10);
QVERIFY(object->objectProperty() != nullptr);
- MyQmlObject *qmlObject =
- qobject_cast<MyQmlObject *>(object->objectProperty());
+ MyQmlObject *qmlObject = qobject_cast<MyQmlObject *>(object->objectProperty());
QVERIFY(qmlObject != nullptr);
QCOMPARE(qmlObject->value(), 10);
object->setValue(19);
QCOMPARE(qmlObject->value(), 19);
-
- delete object;
}
// Check errors on deferred properties are correctly emitted
@@ -1216,8 +1223,9 @@ void tst_qqmlecmascript::deferredPropertiesErrors()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("deferredPropertiesErrors.qml"));
- MyDeferredObject *object =
- qobject_cast<MyDeferredObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyDeferredObject *object = qobject_cast<MyDeferredObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->value(), 0);
QVERIFY(!object->objectProperty());
@@ -1227,8 +1235,6 @@ void tst_qqmlecmascript::deferredPropertiesErrors()
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
qmlExecuteDeferred(object);
-
- delete object;
}
void tst_qqmlecmascript::deferredPropertiesInComponents()
@@ -1236,10 +1242,8 @@ void tst_qqmlecmascript::deferredPropertiesInComponents()
// Test that it works when the property is set inside and outside component
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("deferredPropertiesInComponents.qml"));
- QObject *object = component.create();
- if (!object)
- qDebug() << component.errorString();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("value").value<int>(), 10);
MyDeferredObject *defObjectA =
@@ -1259,8 +1263,6 @@ void tst_qqmlecmascript::deferredPropertiesInComponents()
qmlExecuteDeferred(defObjectB);
QVERIFY(defObjectB->objectProperty() != nullptr);
QCOMPARE(defObjectB->objectProperty()->property("value").value<int>(), 10);
-
- delete object;
}
void tst_qqmlecmascript::deferredPropertiesInDestruction()
@@ -1270,19 +1272,18 @@ void tst_qqmlecmascript::deferredPropertiesInDestruction()
//
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("deferredPropertiesInDestruction.qml"));
- QObject *object = component.create();
- if (!object)
- qDebug() << component.errorString();
- QVERIFY(object != nullptr);
- delete object; //QTBUG-33112 was that this used to cause a crash
+ // QTBUG-33112 - deleting this used to cause a crash:
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
}
void tst_qqmlecmascript::extensionObjects()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("extensionObjects.qml"));
- MyExtendedObject *object =
- qobject_cast<MyExtendedObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyExtendedObject *object = qobject_cast<MyExtendedObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->baseProperty(), 13);
QCOMPARE(object->coreProperty(), 9);
@@ -1291,7 +1292,8 @@ void tst_qqmlecmascript::extensionObjects()
QCOMPARE(object->coreProperty(), 11);
QCOMPARE(object->baseProperty(), 92);
- MyExtendedObject *nested = qobject_cast<MyExtendedObject*>(qvariant_cast<QObject *>(object->property("nested")));
+ MyExtendedObject *nested = qobject_cast<MyExtendedObject *>(
+ qvariant_cast<QObject *>(object->property("nested")));
QVERIFY(nested);
QCOMPARE(nested->baseProperty(), 13);
QCOMPARE(nested->coreProperty(), 9);
@@ -1299,21 +1301,19 @@ void tst_qqmlecmascript::extensionObjects()
nested->setProperty("baseExtendedProperty", QVariant(92));
QCOMPARE(nested->coreProperty(), 11);
QCOMPARE(nested->baseProperty(), 92);
-
- delete object;
}
void tst_qqmlecmascript::overrideExtensionProperties()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("extensionObjectsPropertyOverride.qml"));
- OverrideDefaultPropertyObject *object =
- qobject_cast<OverrideDefaultPropertyObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ OverrideDefaultPropertyObject *object
+ = qobject_cast<OverrideDefaultPropertyObject *>(obj.data());
QVERIFY(object != nullptr);
QVERIFY(object->secondProperty() != nullptr);
QVERIFY(!object->firstProperty());
-
- delete object;
}
void tst_qqmlecmascript::attachedProperties()
@@ -1322,40 +1322,36 @@ void tst_qqmlecmascript::attachedProperties()
{
QQmlComponent component(&engine, testFileUrl("attachedProperty.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("a").toInt(), 19);
QCOMPARE(object->property("b").toInt(), 19);
QCOMPARE(object->property("c").toInt(), 19);
QCOMPARE(object->property("d").toInt(), 19);
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("attachedProperty.2.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("a").toInt(), 26);
QCOMPARE(object->property("b").toInt(), 26);
QCOMPARE(object->property("c").toInt(), 26);
QCOMPARE(object->property("d").toInt(), 26);
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("writeAttachedProperty.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
- QMetaObject::invokeMethod(object, "writeValue2");
+ QMetaObject::invokeMethod(object.data(), "writeValue2");
- MyQmlAttachedObject *attached =
- qobject_cast<MyQmlAttachedObject *>(qmlAttachedPropertiesObject<MyQmlObject>(object));
+ MyQmlAttachedObject *attached = qobject_cast<MyQmlAttachedObject *>(
+ qmlAttachedPropertiesObject<MyQmlObject>(object.data()));
QVERIFY(attached != nullptr);
QCOMPARE(attached->value2(), 9);
- delete object;
}
}
@@ -1366,8 +1362,8 @@ void tst_qqmlecmascript::enums()
// Existent enums
{
QQmlComponent component(&engine, testFileUrl("enums.1.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("enumProperty").toInt(), (int)MyQmlObject::EnumValue2);
QCOMPARE(object->property("relatedEnumProperty").toInt(), (int)MyEnumContainer::RelatedValue);
@@ -1385,8 +1381,6 @@ void tst_qqmlecmascript::enums()
QCOMPARE(object->property("j").toInt(), 19);
QCOMPARE(object->property("k").toInt(), 42);
QCOMPARE(object->property("l").toInt(), 333);
-
- delete object;
}
// Non-existent enums
{
@@ -1403,33 +1397,31 @@ void tst_qqmlecmascript::enums()
QTest::ignoreMessage(QtWarningMsg, qPrintable(w7));
QQmlComponent component(&engine, testFileUrl("enums.2.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("a").toInt(), 0);
QCOMPARE(object->property("b").toInt(), 0);
QCOMPARE(object->property("c").toInt(), 1); // Change from Qt 5: type gets automatically registered
QString w9 = file.toString() + ":18: Error: Cannot assign JavaScript function to MyUnregisteredEnumTypeObject::MyEnum";
QTest::ignoreMessage(QtWarningMsg, qPrintable(w9));
- QMetaObject::invokeMethod(object, "testAssignmentOne");
+ QMetaObject::invokeMethod(object.data(), "testAssignmentOne");
QString w10 = file.toString() + ":21: Error: Cannot assign [undefined] to MyUnregisteredEnumTypeObject::MyEnum";
QTest::ignoreMessage(QtWarningMsg, qPrintable(w10));
- QMetaObject::invokeMethod(object, "testAssignmentTwo");
+ QMetaObject::invokeMethod(object.data(), "testAssignmentTwo");
QString w11 = file.toString() + ":24: Error: Cannot assign [undefined] to MyUnregisteredEnumTypeObject::MyEnum";
QTest::ignoreMessage(QtWarningMsg, qPrintable(w11));
- QMetaObject::invokeMethod(object, "testAssignmentThree");
-
- QMetaObject::invokeMethod(object, "testAssignmentFour");
+ QMetaObject::invokeMethod(object.data(), "testAssignmentThree");
- delete object;
+ QMetaObject::invokeMethod(object.data(), "testAssignmentFour");
}
// Enums as literals
{
QQmlComponent component(&engine, testFileUrl("enums.3.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
// check the values are what we expect
QCOMPARE(object->property("a").toInt(), 4);
@@ -1454,8 +1446,6 @@ void tst_qqmlecmascript::enums()
QCOMPARE(object->property("ic").toInt(), 1); // namespace -> binding
QCOMPARE(object->property("jc").toInt(), 0);
QCOMPARE(object->property("kc").toInt(), 0);
-
- delete object;
}
}
@@ -1463,12 +1453,12 @@ void tst_qqmlecmascript::valueTypeFunctions()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("valueTypeFunctions.qml"));
- MyTypeObject *obj = qobject_cast<MyTypeObject*>(component.create());
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
+ MyTypeObject *obj = qobject_cast<MyTypeObject *>(object.data());
QVERIFY(obj != nullptr);
QCOMPARE(obj->rectProperty(), QRect(0,0,100,100));
QCOMPARE(obj->rectFProperty(), QRectF(0,0.5,100,99.5));
-
- delete obj;
}
/*
@@ -1482,7 +1472,9 @@ void tst_qqmlecmascript::constantsOverrideBindings()
// From ECMAScript
{
QQmlComponent component(&engine, testFileUrl("constantsOverrideBindings.1.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->property("c2").toInt(), 0);
@@ -1494,14 +1486,14 @@ void tst_qqmlecmascript::constantsOverrideBindings()
QCOMPARE(object->property("c2").toInt(), 13);
object->setProperty("c1", QVariant(8));
QCOMPARE(object->property("c2").toInt(), 13);
-
- delete object;
}
// During construction
{
QQmlComponent component(&engine, testFileUrl("constantsOverrideBindings.2.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->property("c1").toInt(), 0);
@@ -1509,16 +1501,16 @@ void tst_qqmlecmascript::constantsOverrideBindings()
object->setProperty("c1", QVariant(9));
QCOMPARE(object->property("c1").toInt(), 9);
QCOMPARE(object->property("c2").toInt(), 10);
-
- delete object;
}
#if 0
// From C++
{
QQmlComponent component(&engine, testFileUrl("constantsOverrideBindings.3.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
- QVERIFY(object != 0);
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
+ QVERIFY(object != nullptr);
QCOMPARE(object->property("c2").toInt(), 0);
object->setProperty("c1", QVariant(9));
@@ -1529,15 +1521,15 @@ void tst_qqmlecmascript::constantsOverrideBindings()
object->setProperty("c1", QVariant(7));
QCOMPARE(object->property("c1").toInt(), 7);
QCOMPARE(object->property("c2").toInt(), 13);
-
- delete object;
}
#endif
// Using an alias
{
QQmlComponent component(&engine, testFileUrl("constantsOverrideBindings.4.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->property("c1").toInt(), 0);
@@ -1545,8 +1537,6 @@ void tst_qqmlecmascript::constantsOverrideBindings()
object->setProperty("c1", QVariant(9));
QCOMPARE(object->property("c1").toInt(), 9);
QCOMPARE(object->property("c3").toInt(), 10);
-
- delete object;
}
}
@@ -1557,9 +1547,10 @@ the original binding to be disabled.
void tst_qqmlecmascript::outerBindingOverridesInnerBinding()
{
QQmlEngine engine;
- QQmlComponent component(&engine,
- testFileUrl("outerBindingOverridesInnerBinding.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QQmlComponent component(&engine, testFileUrl("outerBindingOverridesInnerBinding.qml"));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->property("c1").toInt(), 0);
@@ -1575,8 +1566,6 @@ void tst_qqmlecmascript::outerBindingOverridesInnerBinding()
QCOMPARE(object->property("c1").toInt(), 9);
QCOMPARE(object->property("c2").toInt(), 8);
QCOMPARE(object->property("c3").toInt(), 8);
-
- delete object;
}
/*
@@ -1592,10 +1581,8 @@ void tst_qqmlecmascript::nonExistentAttachedObject()
QString warning = component.url().toString() + ":4:5: Unable to assign [undefined] to QString";
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
-
- delete object;
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
}
void tst_qqmlecmascript::scope()
@@ -1604,8 +1591,8 @@ void tst_qqmlecmascript::scope()
{
QQmlComponent component(&engine, testFileUrl("scope.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test1").toInt(), 1);
QCOMPARE(object->property("test2").toInt(), 2);
@@ -1617,14 +1604,12 @@ void tst_qqmlecmascript::scope()
QCOMPARE(object->property("test8").toInt(), 2);
QCOMPARE(object->property("test9").toInt(), 1);
QCOMPARE(object->property("test10").toInt(), 3);
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("scope.2.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test1").toInt(), 19);
QCOMPARE(object->property("test2").toInt(), 19);
@@ -1632,27 +1617,25 @@ void tst_qqmlecmascript::scope()
QCOMPARE(object->property("test4").toInt(), 14);
QCOMPARE(object->property("test5").toInt(), 24);
QCOMPARE(object->property("test6").toInt(), 24);
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("scope.3.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test1").toBool(), true);
QEXPECT_FAIL("", "Properties resolvable at compile time come before the global object, which is not 100% compatible with older QML versions", Continue);
QCOMPARE(object->property("test2").toBool(), true);
QCOMPARE(object->property("test3").toBool(), true);
-
- delete object;
}
// Signal argument scope
{
QQmlComponent component(&engine, testFileUrl("scope.4.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->property("test").toInt(), 0);
@@ -1662,29 +1645,23 @@ void tst_qqmlecmascript::scope()
QCOMPARE(object->property("test").toInt(), 13);
QCOMPARE(object->property("test2").toString(), QString("Argument Scope"));
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("scope.5.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test1").toBool(), true);
QCOMPARE(object->property("test2").toBool(), true);
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("scope.6.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toBool(), true);
-
- delete object;
}
}
@@ -1694,12 +1671,10 @@ void tst_qqmlecmascript::importScope()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("importScope.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject>o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test").toInt(), 240);
-
- delete o;
}
/*
@@ -1710,7 +1685,9 @@ void tst_qqmlecmascript::signalParameterTypes()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("signalParameterTypes.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
emit object->basicSignal();
@@ -1727,8 +1704,6 @@ void tst_qqmlecmascript::signalParameterTypes()
emit object->qjsValueEmittingSignal(QJSValue(42));
QVERIFY(!object->property("emittedQjsValueWasUndefined").toBool());
QCOMPARE(object->property("emittedQjsValueAsInt").value<int>(), 42);
-
- delete object;
}
/*
@@ -1738,16 +1713,14 @@ void tst_qqmlecmascript::objectsCompareAsEqual()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("objectsCompareAsEqual.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test1").toBool(), true);
QCOMPARE(object->property("test2").toBool(), true);
QCOMPARE(object->property("test3").toBool(), true);
QCOMPARE(object->property("test4").toBool(), true);
QCOMPARE(object->property("test5").toBool(), true);
-
- delete object;
}
/*
@@ -1759,8 +1732,8 @@ void tst_qqmlecmascript::aliasPropertyAndBinding()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("aliasPropertyAndBinding.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("c2").toInt(), 3);
QCOMPARE(object->property("c3").toInt(), 3);
@@ -1769,8 +1742,6 @@ void tst_qqmlecmascript::aliasPropertyAndBinding()
QCOMPARE(object->property("c2").toInt(), 19);
QCOMPARE(object->property("c3").toInt(), 19);
-
- delete object;
}
/*
@@ -1780,79 +1751,74 @@ and that the aliased property is reset correctly if possible.
void tst_qqmlecmascript::aliasPropertyReset()
{
QQmlEngine engine;
- QObject *object = nullptr;
+ QScopedPointer<QObject> object;
// test that a manual write (of undefined) to a resettable aliased property succeeds
QQmlComponent c1(&engine, testFileUrl("aliasreset/aliasPropertyReset.1.qml"));
- object = c1.create();
- QVERIFY(object != nullptr);
+ object.reset(c1.create());
+ QVERIFY2(object, qPrintable(c1.errorString()));
QVERIFY(object->property("sourceComponentAlias").value<QQmlComponent*>() != 0);
QCOMPARE(object->property("aliasIsUndefined"), QVariant(false));
- QMetaObject::invokeMethod(object, "resetAliased");
+ QMetaObject::invokeMethod(object.data(), "resetAliased");
QVERIFY(!object->property("sourceComponentAlias").value<QQmlComponent*>());
QCOMPARE(object->property("aliasIsUndefined"), QVariant(true));
- delete object;
// test that a manual write (of undefined) to a resettable alias property succeeds
QQmlComponent c2(&engine, testFileUrl("aliasreset/aliasPropertyReset.2.qml"));
- object = c2.create();
- QVERIFY(object != nullptr);
+ object.reset(c2.create());
+ QVERIFY2(object, qPrintable(c2.errorString()));
QVERIFY(object->property("sourceComponentAlias").value<QQmlComponent*>() != 0);
QCOMPARE(object->property("loaderSourceComponentIsUndefined"), QVariant(false));
- QMetaObject::invokeMethod(object, "resetAlias");
+ QMetaObject::invokeMethod(object.data(), "resetAlias");
QVERIFY(!object->property("sourceComponentAlias").value<QQmlComponent*>());
QCOMPARE(object->property("loaderSourceComponentIsUndefined"), QVariant(true));
- delete object;
// test that an alias to a bound property works correctly
QQmlComponent c3(&engine, testFileUrl("aliasreset/aliasPropertyReset.3.qml"));
- object = c3.create();
- QVERIFY(object != nullptr);
+ object.reset(c3.create());
+ QVERIFY2(object, qPrintable(c3.errorString()));
QVERIFY(object->property("sourceComponentAlias").value<QQmlComponent*>() != 0);
QCOMPARE(object->property("loaderOneSourceComponentIsUndefined"), QVariant(false));
QCOMPARE(object->property("loaderTwoSourceComponentIsUndefined"), QVariant(false));
- QMetaObject::invokeMethod(object, "resetAlias");
+ QMetaObject::invokeMethod(object.data(), "resetAlias");
QVERIFY(!object->property("sourceComponentAlias").value<QQmlComponent*>());
QCOMPARE(object->property("loaderOneSourceComponentIsUndefined"), QVariant(true));
QCOMPARE(object->property("loaderTwoSourceComponentIsUndefined"), QVariant(false));
- delete object;
// test that a manual write (of undefined) to a resettable alias property
// whose aliased property's object has been deleted, does not crash.
QQmlComponent c4(&engine, testFileUrl("aliasreset/aliasPropertyReset.4.qml"));
- object = c4.create();
- QVERIFY(object != nullptr);
+ object.reset(c4.create());
+ QVERIFY2(object, qPrintable(c4.errorString()));
QVERIFY(object->property("sourceComponentAlias").value<QQmlComponent*>() != 0);
QObject *loader = object->findChild<QObject*>("loader");
QVERIFY(loader != nullptr);
delete loader;
QVERIFY(object->property("sourceComponentAlias").value<QQmlComponent*>() == 0); // deletion should have caused value unset.
- QMetaObject::invokeMethod(object, "resetAlias"); // shouldn't crash.
+ QMetaObject::invokeMethod(object.data(), "resetAlias"); // shouldn't crash.
QVERIFY(!object->property("sourceComponentAlias").value<QQmlComponent*>());
- QMetaObject::invokeMethod(object, "setAlias"); // shouldn't crash, and shouldn't change value (since it's no longer referencing anything).
+ // Shouldn't crash, and shouldn't change value (since it's no longer referencing anything):
+ QMetaObject::invokeMethod(object.data(), "setAlias");
QVERIFY(!object->property("sourceComponentAlias").value<QQmlComponent*>());
- delete object;
// test that binding an alias property to an undefined value works correctly
QQmlComponent c5(&engine, testFileUrl("aliasreset/aliasPropertyReset.5.qml"));
- object = c5.create();
- QVERIFY(object != nullptr);
+ object.reset(c5.create());
+ QVERIFY2(object, qPrintable(c5.errorString()));
QVERIFY(object->property("sourceComponentAlias").value<QQmlComponent*>() == 0); // bound to undefined value.
- delete object;
// test that a manual write (of undefined) to a non-resettable property fails properly
QUrl url = testFileUrl("aliasreset/aliasPropertyReset.error.1.qml");
QString warning1 = url.toString() + QLatin1String(":15: Error: Cannot assign [undefined] to int");
QQmlComponent e1(&engine, url);
- object = e1.create();
- QVERIFY(object != nullptr);
+ object.reset(e1.create());
+ QVERIFY2(object, qPrintable(e1.errorString()));
QCOMPARE(object->property("intAlias").value<int>(), 12);
QCOMPARE(object->property("aliasedIntIsUndefined"), QVariant(false));
QTest::ignoreMessage(QtWarningMsg, warning1.toLatin1().constData());
- QMetaObject::invokeMethod(object, "resetAlias");
+ QMetaObject::invokeMethod(object.data(), "resetAlias");
QCOMPARE(object->property("intAlias").value<int>(), 12);
QCOMPARE(object->property("aliasedIntIsUndefined"), QVariant(false));
- delete object;
}
void tst_qqmlecmascript::componentCreation_data()
@@ -1917,10 +1883,12 @@ void tst_qqmlecmascript::componentCreation()
}
QQmlComponent component(&engine, testUrl);
- QScopedPointer<MyTypeObject> object(qobject_cast<MyTypeObject*>(component.create()));
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyTypeObject *object = qobject_cast<MyTypeObject *>(obj.data());
+ QVERIFY2(object, qPrintable(component.errorString()));
- QMetaObject::invokeMethod(object.get(), method.toUtf8());
+ QMetaObject::invokeMethod(object, method.toUtf8());
QQmlComponent *created = object->componentProperty();
if (creationError.isEmpty()) {
@@ -1928,7 +1896,7 @@ void tst_qqmlecmascript::componentCreation()
QObject *expectedParent = reinterpret_cast<QObject *>(quintptr(-1));
if (createdParent == QLatin1String("obj")) {
- expectedParent = object.get();
+ expectedParent = object;
} else if ((createdParent == QLatin1String("null")) || createdParent.isEmpty()) {
expectedParent = nullptr;
}
@@ -1957,15 +1925,15 @@ void tst_qqmlecmascript::dynamicCreation()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("dynamicCreation.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QMetaObject::invokeMethod(object, method.toUtf8());
QObject *created = object->objectProperty();
QVERIFY(created);
QCOMPARE(created->objectName(), createdName);
-
- delete object;
}
/*
@@ -1978,7 +1946,7 @@ void tst_qqmlecmascript::dynamicDestruction()
{
QQmlComponent component(&engine, testFileUrl("dynamicDeletion.qml"));
QPointer<MyQmlObject> object = qobject_cast<MyQmlObject*>(component.create());
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
QPointer<QObject> createdQmlObject = nullptr;
QMetaObject::invokeMethod(object, "create");
@@ -2011,36 +1979,34 @@ void tst_qqmlecmascript::dynamicDestruction()
{
QQmlComponent component(&engine, testFileUrl("dynamicDeletion.2.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject>o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QVERIFY(!qvariant_cast<QObject*>(o->property("objectProperty")));
- QMetaObject::invokeMethod(o, "create");
+ QMetaObject::invokeMethod(o.data(), "create");
QVERIFY(qvariant_cast<QObject*>(o->property("objectProperty")) != 0);
- QMetaObject::invokeMethod(o, "destroy");
+ QMetaObject::invokeMethod(o.data(), "destroy");
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
QCoreApplication::processEvents();
QVERIFY(!qvariant_cast<QObject*>(o->property("objectProperty")));
-
- delete o;
}
{
// QTBUG-23451
QPointer<QObject> createdQmlObject = nullptr;
QQmlComponent component(&engine, testFileUrl("dynamicDeletion.3.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject>o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QVERIFY(!qvariant_cast<QObject*>(o->property("objectProperty")));
- QMetaObject::invokeMethod(o, "create");
+ QMetaObject::invokeMethod(o.data(), "create");
createdQmlObject = qvariant_cast<QObject*>(o->property("objectProperty"));
QVERIFY(createdQmlObject);
- QMetaObject::invokeMethod(o, "destroy");
+ QMetaObject::invokeMethod(o.data(), "destroy");
QCOMPARE(qvariant_cast<bool>(o->property("test")), false);
for (int ii = 0; createdQmlObject && ii < 50; ++ii) { // After 5 seconds we should give up
QTest::qWait(100);
@@ -2049,7 +2015,6 @@ void tst_qqmlecmascript::dynamicDestruction()
}
QVERIFY(!qvariant_cast<QObject*>(o->property("objectProperty")));
QCOMPARE(qvariant_cast<bool>(o->property("test")), true);
- delete o;
}
}
@@ -2060,13 +2025,13 @@ void tst_qqmlecmascript::objectToString()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("qmlToString.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QMetaObject::invokeMethod(object, "testToString");
QVERIFY(object->stringProperty().startsWith("MyQmlObject_QML_"));
QVERIFY(object->stringProperty().endsWith(", \"objName\")"));
-
- delete object;
}
/*
@@ -2081,13 +2046,13 @@ void tst_qqmlecmascript::objectHasOwnProperty()
QQmlEngine engine;
QQmlComponent component(&engine, url);
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
// test QObjects in QML
- QMetaObject::invokeMethod(object, "testHasOwnPropertySuccess");
+ QMetaObject::invokeMethod(object.data(), "testHasOwnPropertySuccess");
QVERIFY(object->property("result").value<bool>());
- QMetaObject::invokeMethod(object, "testHasOwnPropertyFailure");
+ QMetaObject::invokeMethod(object.data(), "testHasOwnPropertyFailure");
QVERIFY(!object->property("result").value<bool>());
// now test other types in QML
@@ -2115,8 +2080,6 @@ void tst_qqmlecmascript::objectHasOwnProperty()
QTest::ignoreMessage(QtWarningMsg, warning3.toLatin1().constData());
QMetaObject::invokeMethod(child, "testHasOwnPropertyFailureThree");
QCOMPARE(child->property("listAtInvalidHasOwnProperty").toBool(), false);
-
- delete object;
}
/*
@@ -2130,18 +2093,16 @@ void tst_qqmlecmascript::selfDeletingBinding()
{
QQmlComponent component(&engine, testFileUrl("selfDeletingBinding.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
object->setProperty("triggerDelete", true);
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("selfDeletingBinding.2.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
object->setProperty("triggerDelete", true);
- delete object;
}
}
@@ -2156,9 +2117,8 @@ void tst_qqmlecmascript::extendedObjectPropertyLookup()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("extendedObjectPropertyLookup.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- delete object;
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
}
/*
@@ -2168,14 +2128,12 @@ void tst_qqmlecmascript::extendedObjectPropertyLookup2()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("extendedObjectPropertyLookup2.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QVariant returnValue;
- QVERIFY(QMetaObject::invokeMethod(object, "getValue", Q_RETURN_ARG(QVariant, returnValue)));
+ QVERIFY(QMetaObject::invokeMethod(object.data(), "getValue", Q_RETURN_ARG(QVariant, returnValue)));
QCOMPARE(returnValue.toInt(), 42);
-
- delete object;
}
/*
@@ -2186,7 +2144,7 @@ void tst_qqmlecmascript::uncreatableExtendedObjectFailureCheck()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("uncreatableExtendedObjectFailureCheck.qml"));
- QObject *object = component.create();
+ QScopedPointer<QObject> object(component.create());
QVERIFY(!object);
}
@@ -2198,18 +2156,19 @@ void tst_qqmlecmascript::extendedObjectPropertyLookup3()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("extendedObjectPropertyLookup3.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QVariant returnValue;
- QVERIFY(QMetaObject::invokeMethod(object, "getAbstractProperty", Q_RETURN_ARG(QVariant, returnValue)));
+ QVERIFY(QMetaObject::invokeMethod(object.data(), "getAbstractProperty",
+ Q_RETURN_ARG(QVariant, returnValue)));
QCOMPARE(returnValue.toInt(), -1);
- QVERIFY(QMetaObject::invokeMethod(object, "getImplementedProperty", Q_RETURN_ARG(QVariant, returnValue)));
+ QVERIFY(QMetaObject::invokeMethod(object.data(), "getImplementedProperty",
+ Q_RETURN_ARG(QVariant, returnValue)));
QCOMPARE(returnValue.toInt(), 883);
- QVERIFY(QMetaObject::invokeMethod(object, "getExtendedProperty", Q_RETURN_ARG(QVariant, returnValue)));
+ QVERIFY(QMetaObject::invokeMethod(object.data(), "getExtendedProperty",
+ Q_RETURN_ARG(QVariant, returnValue)));
QCOMPARE(returnValue.toInt(), 42);
-
- delete object;
}
/*
Test file/lineNumbers for binding/Script errors.
@@ -2234,7 +2193,9 @@ void tst_qqmlecmascript::scriptErrors()
QTest::ignoreMessage(QtWarningMsg, warning3.toLatin1().constData());
QTest::ignoreMessage(QtWarningMsg, warning5.toLatin1().constData());
QTest::ignoreMessage(QtWarningMsg, warning6.toLatin1().constData());
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QTest::ignoreMessage(QtWarningMsg, warning4.toLatin1().constData());
@@ -2245,8 +2206,6 @@ void tst_qqmlecmascript::scriptErrors()
QTest::ignoreMessage(QtWarningMsg, warning8.toLatin1().constData());
emit object->thirdBasicSignal();
-
- delete object;
}
/*
@@ -2262,22 +2221,21 @@ void tst_qqmlecmascript::functionErrors()
QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData());
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- delete object;
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
// test that if an exception occurs while invoking js function from cpp, it is reported as expected.
QQmlComponent componentTwo(&engine, testFileUrl("scarceResourceFunctionFail.var.qml"));
url = componentTwo.url().toString();
- object = componentTwo.create();
- QVERIFY(object != nullptr);
+ object.reset(componentTwo.create());
+ QVERIFY2(object, qPrintable(componentTwo.errorString()));
- QObject *resource = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
+ QObject *resource = qobject_cast<ScarceResourceObject *>(
+ QQmlProperty::read(object.data(), "a").value<QObject*>());
warning = url + QLatin1String(":16: TypeError: Property 'scarceResource' of object ScarceResourceObject(0x%1) is not a function");
warning = warning.arg(QString::number(quintptr(resource), 16));
QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); // we expect a meaningful warning to be printed.
- QMetaObject::invokeMethod(object, "retrieveScarceResource");
- delete object;
+ QMetaObject::invokeMethod(object.data(), "retrieveScarceResource");
}
/*
@@ -2290,13 +2248,11 @@ void tst_qqmlecmascript::propertyAssignmentErrors()
QString url = component.url().toString();
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test1").toBool(), true);
QCOMPARE(object->property("test2").toBool(), true);
-
- delete object;
}
/*
@@ -2307,7 +2263,9 @@ void tst_qqmlecmascript::signalTriggeredBindings()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("signalTriggeredBindings.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->property("base").toReal(), 50.);
@@ -2325,8 +2283,6 @@ void tst_qqmlecmascript::signalTriggeredBindings()
QCOMPARE(object->property("base").toReal(), 400.);
QCOMPARE(object->property("test1").toReal(), 400.);
QCOMPARE(object->property("test2").toReal(), 400.);
-
- delete object;
}
/*
@@ -2336,15 +2292,15 @@ void tst_qqmlecmascript::listProperties()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("listProperties.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->property("test1").toInt(), 21);
QCOMPARE(object->property("test2").toInt(), 2);
QCOMPARE(object->property("test3").toBool(), true);
QCOMPARE(object->property("test4").toBool(), true);
-
- delete object;
}
void tst_qqmlecmascript::exceptionClearsOnReeval()
@@ -2356,7 +2312,9 @@ void tst_qqmlecmascript::exceptionClearsOnReeval()
QString warning = url + ":4: TypeError: Cannot read property 'objectProperty' of null";
QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData());
- MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->property("test").toBool(), false);
@@ -2367,8 +2325,6 @@ void tst_qqmlecmascript::exceptionClearsOnReeval()
object->setObjectProperty(&object2);
QCOMPARE(object->property("test").toBool(), true);
-
- delete object;
}
void tst_qqmlecmascript::exceptionSlotProducesWarning()
@@ -2380,9 +2336,10 @@ void tst_qqmlecmascript::exceptionSlotProducesWarning()
QString warning = component.url().toString() + ":6: Error: JS exception";
QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData());
- MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
- delete object;
}
void tst_qqmlecmascript::exceptionBindingProducesWarning()
@@ -2394,9 +2351,10 @@ void tst_qqmlecmascript::exceptionBindingProducesWarning()
QString warning = component.url().toString() + ":5: Error: JS exception";
QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData());
- MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
- delete object;
}
void tst_qqmlecmascript::compileInvalidBinding()
@@ -2404,9 +2362,8 @@ void tst_qqmlecmascript::compileInvalidBinding()
// QTBUG-23387: ensure that invalid bindings don't cause a crash.
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("v8bindingException.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- delete object;
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
}
// Check that transient binding errors are not displayed
@@ -2419,12 +2376,10 @@ void tst_qqmlecmascript::transientErrors()
QQmlTestMessageHandler messageHandler;
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QVERIFY2(messageHandler.messages().isEmpty(), qPrintable(messageHandler.messageString()));
-
- delete object;
}
// One binding erroring multiple times, but then resolving
@@ -2433,12 +2388,10 @@ void tst_qqmlecmascript::transientErrors()
QQmlTestMessageHandler messageHandler;
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QVERIFY2(messageHandler.messages().isEmpty(), qPrintable(messageHandler.messageString()));
-
- delete object;
}
}
@@ -2447,13 +2400,11 @@ void tst_qqmlecmascript::shutdownErrors()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("shutdownErrors.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QQmlTestMessageHandler messageHandler;
-
- delete object;
-
+ object.reset();
QVERIFY2(messageHandler.messages().isEmpty(), qPrintable(messageHandler.messageString()));
}
@@ -2463,8 +2414,7 @@ void tst_qqmlecmascript::compositePropertyType()
QQmlComponent component(&engine, testFileUrl("compositePropertyType.qml"));
QTest::ignoreMessage(QtDebugMsg, "hello world");
- QObject *object = qobject_cast<QObject *>(component.create());
- delete object;
+ QScopedPointer<QObject> object(component.create());
}
// QTBUG-5759
@@ -2472,12 +2422,10 @@ void tst_qqmlecmascript::jsObject()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("jsObject.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toInt(), 92);
-
- delete object;
}
void tst_qqmlecmascript::undefinedResetsProperty()
@@ -2486,8 +2434,8 @@ void tst_qqmlecmascript::undefinedResetsProperty()
{
QQmlComponent component(&engine, testFileUrl("undefinedResetsProperty.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("resettableProperty").toInt(), 92);
@@ -2498,21 +2446,17 @@ void tst_qqmlecmascript::undefinedResetsProperty()
object->setProperty("setUndefined", false);
QCOMPARE(object->property("resettableProperty").toInt(), 92);
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("undefinedResetsProperty.2.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("resettableProperty").toInt(), 19);
- QMetaObject::invokeMethod(object, "doReset");
+ QMetaObject::invokeMethod(object.data(), "doReset");
QCOMPARE(object->property("resettableProperty").toInt(), 13);
-
- delete object;
}
}
@@ -2533,7 +2477,7 @@ void tst_qqmlecmascript::undefinedResetsEveryTime()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl(file));
QScopedPointer<QObject> object(component.create());
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
auto qmlObject = qobject_cast<MyQmlObject *>(object.get());
QVERIFY(qmlObject);
@@ -2555,12 +2499,10 @@ void tst_qqmlecmascript::qtbug_22464()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("qtbug_22464.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toBool(), true);
-
- delete object;
}
void tst_qqmlecmascript::qtbug_21580()
@@ -2568,12 +2510,10 @@ void tst_qqmlecmascript::qtbug_21580()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("qtbug_21580.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toBool(), true);
-
- delete object;
}
// Causes a v8 binding, but not all v8 bindings to be destroyed during evaluation
@@ -2582,9 +2522,8 @@ void tst_qqmlecmascript::singleV8BindingDestroyedDuringEvaluation()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("singleV8BindingDestroyedDuringEvaluation.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- delete object;
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
}
// QTBUG-6781
@@ -2592,8 +2531,8 @@ void tst_qqmlecmascript::bug1()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("bug.1.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toInt(), 14);
@@ -2605,7 +2544,6 @@ void tst_qqmlecmascript::bug1()
QCOMPARE(object->property("test").toInt(), 9);
- delete object;
}
#ifndef QT_NO_WIDGETS
@@ -2615,10 +2553,8 @@ void tst_qqmlecmascript::bug2()
QQmlComponent component(&engine);
component.setData("import Qt.test 1.0;\nQPlainTextEdit { width: 100 }", QUrl());
- QObject *object = component.create();
- QVERIFY(object != nullptr);
-
- delete object;
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
}
#endif
@@ -2627,15 +2563,15 @@ void tst_qqmlecmascript::dynamicCreationCrash()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("dynamicCreation.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready");
QMetaObject::invokeMethod(object, "dontCrash");
QObject *created = object->objectProperty();
QVERIFY(!created);
-
- delete object;
}
// ownership transferred to JS, ensure that GC runs the dtor
@@ -2648,26 +2584,25 @@ void tst_qqmlecmascript::dynamicCreationOwnership()
{
QQmlEngine dcoEngine;
QQmlComponent component(&dcoEngine, testFileUrl("dynamicCreationOwnership.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- MyDynamicCreationDestructionObject *mdcdo = object->findChild<MyDynamicCreationDestructionObject*>("mdcdo");
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
+ MyDynamicCreationDestructionObject *mdcdo
+ = object->findChild<MyDynamicCreationDestructionObject*>("mdcdo");
QVERIFY(mdcdo != nullptr);
mdcdo->setDtorCount(&dtorCount);
for (int i = 1; i < 105; ++i, ++expectedDtorCount) {
- QMetaObject::invokeMethod(object, "dynamicallyCreateJsOwnedObject");
+ QMetaObject::invokeMethod(object.data(), "dynamicallyCreateJsOwnedObject");
if (i % 90 == 0) {
// we do this once manually, but it should be done automatically
// when the engine goes out of scope (since it should gc in dtor)
- QMetaObject::invokeMethod(object, "performGc");
+ QMetaObject::invokeMethod(object.data(), "performGc");
}
if (i % 10 == 0) {
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
QCoreApplication::processEvents();
}
}
-
- delete object;
}
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
QCoreApplication::processEvents();
@@ -2681,8 +2616,10 @@ void tst_qqmlecmascript::regExpBug()
//QTBUG-9367
{
QQmlComponent component(&engine, testFileUrl("regularExpression.qml"));
- QScopedPointer<MyQmlObject> object(qobject_cast<MyQmlObject*>(component.create()));
- QVERIFY(!object.isNull());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
+ QVERIFY(object != nullptr);
QCOMPARE(object->regularExpression().pattern(), QLatin1String("[a-zA-z]"));
}
@@ -2694,7 +2631,7 @@ void tst_qqmlecmascript::regExpBug()
.arg(testFileUrl("regularExpression.2.qml").toString());
QQmlComponent component(&engine, testFileUrl("regularExpression.2.qml"));
QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready");
- MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create());
+ QScopedPointer<QObject> object(component.create());
QVERIFY(!object);
QCOMPARE(component.errorString(), err);
}
@@ -3408,13 +3345,11 @@ void tst_qqmlecmascript::invokableObjectArg()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("invokableObjectArg.qml"));
- QObject *o = component.create();
- QVERIFY(o);
- MyQmlObject *qmlobject = qobject_cast<MyQmlObject *>(o);
+ QScopedPointer<QObject>o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
+ MyQmlObject *qmlobject = qobject_cast<MyQmlObject *>(o.data());
QVERIFY(qmlobject);
QCOMPARE(qmlobject->myinvokableObject, qmlobject);
-
- delete o;
}
// QTBUG-13047 (check that you can return registered object types from methods)
@@ -3423,10 +3358,9 @@ void tst_qqmlecmascript::invokableObjectRet()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("invokableObjectRet.qml"));
- QObject *o = component.create();
- QVERIFY(o);
+ QScopedPointer<QObject>o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test").toBool(), true);
- delete o;
}
void tst_qqmlecmascript::invokableEnumRet()
@@ -3434,10 +3368,9 @@ void tst_qqmlecmascript::invokableEnumRet()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("invokableEnumRet.qml"));
- QObject *o = component.create();
- QVERIFY(o);
+ QScopedPointer<QObject>o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test").toBool(), true);
- delete o;
}
// QTBUG-5675
@@ -3451,14 +3384,12 @@ void tst_qqmlecmascript::listToVariant()
QQmlContext context(engine.rootContext());
context.setContextObject(&container);
- QObject *object = component.create(&context);
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create(&context));
+ QVERIFY2(object, qPrintable(component.errorString()));
QVariant v = object->property("test");
QCOMPARE(v.typeId(), qMetaTypeId<QQmlListReference>());
QCOMPARE(qvariant_cast<QQmlListReference>(v).object(), &container);
-
- delete object;
}
// QTBUG-16316
@@ -3466,14 +3397,14 @@ void tst_qqmlecmascript::listAssignment()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("listAssignment.qml"));
- QObject *obj = component.create();
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
QCOMPARE(obj->property("list1length").toInt(), 2);
QQmlListProperty<MyQmlObject> list1 = obj->property("list1").value<QQmlListProperty<MyQmlObject> >();
QQmlListProperty<MyQmlObject> list2 = obj->property("list2").value<QQmlListProperty<MyQmlObject> >();
QCOMPARE(list1.count(&list1), list2.count(&list2));
QCOMPARE(list1.at(&list1, 0), list2.at(&list2, 0));
QCOMPARE(list1.at(&list1, 1), list2.at(&list2, 1));
- delete obj;
}
// QTBUG-7957
@@ -3490,14 +3421,13 @@ void tst_qqmlecmascript::multiEngineObject()
e2.rootContext()->setContextProperty("thing", &obj);
QQmlComponent c2(&e2, testFileUrl("multiEngineObject.qml"));
- QObject *o1 = c1.create();
- QObject *o2 = c2.create();
+ QScopedPointer<QObject>o1(c1.create());
+ QVERIFY2(o1, qPrintable(c1.errorString()));
+ QScopedPointer<QObject>o2(c2.create());
+ QVERIFY2(o2, qPrintable(c2.errorString()));
QCOMPARE(o1->property("test").toString(), QString("Howdy planet"));
QCOMPARE(o2->property("test").toString(), QString("Howdy planet"));
-
- delete o2;
- delete o1;
}
// Test that references to QObjects are cleanup when the object is destroyed
@@ -3506,14 +3436,13 @@ void tst_qqmlecmascript::deletedObject()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("deletedObject.qml"));
- QObject *object = component.create();
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test1").toBool(), true);
QCOMPARE(object->property("test2").toBool(), true);
QCOMPARE(object->property("test3").toBool(), true);
QCOMPARE(object->property("test4").toBool(), true);
-
- delete object;
}
void tst_qqmlecmascript::attachedPropertyScope()
@@ -3521,11 +3450,11 @@ void tst_qqmlecmascript::attachedPropertyScope()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("attachedPropertyScope.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
- MyQmlAttachedObject *attached =
- qobject_cast<MyQmlAttachedObject *>(qmlAttachedPropertiesObject<MyQmlObject>(object));
+ MyQmlAttachedObject *attached = qobject_cast<MyQmlAttachedObject *>(
+ qmlAttachedPropertiesObject<MyQmlObject>(object.data()));
QVERIFY(attached != nullptr);
QCOMPARE(object->property("value2").toInt(), 0);
@@ -3533,8 +3462,6 @@ void tst_qqmlecmascript::attachedPropertyScope()
attached->emitMySignal();
QCOMPARE(object->property("value2").toInt(), 9);
-
- delete object;
}
void tst_qqmlecmascript::scriptConnect()
@@ -3544,46 +3471,48 @@ void tst_qqmlecmascript::scriptConnect()
{
QQmlComponent component(&engine, testFileUrl("scriptConnect.1.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->property("test").toBool(), false);
emit object->argumentSignal(19, "Hello world!", 10.25, MyQmlObject::EnumValue4, Qt::RightButton);
QCOMPARE(object->property("test").toBool(), true);
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("scriptConnect.2.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->property("test").toBool(), false);
emit object->argumentSignal(19, "Hello world!", 10.25, MyQmlObject::EnumValue4, Qt::RightButton);
QCOMPARE(object->property("test").toBool(), true);
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("scriptConnect.3.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->property("test").toBool(), false);
emit object->argumentSignal(19, "Hello world!", 10.25, MyQmlObject::EnumValue4, Qt::RightButton);
QCOMPARE(object->property("test").toBool(), true);
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("scriptConnect.4.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->methodCalled(), false);
@@ -3592,14 +3521,14 @@ void tst_qqmlecmascript::scriptConnect()
QTest::ignoreMessage(QtWarningMsg, QRegularExpression("Too many arguments, ignoring 5"));
emit object->argumentSignal(19, "Hello world!", 10.25, MyQmlObject::EnumValue4, Qt::RightButton);
QCOMPARE(object->methodCalled(), true);
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("scriptConnect.5.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->methodCalled(), false);
@@ -3607,32 +3536,30 @@ void tst_qqmlecmascript::scriptConnect()
QTest::ignoreMessage(QtWarningMsg, QRegularExpression("Too many arguments, ignoring 5"));
emit object->argumentSignal(19, "Hello world!", 10.25, MyQmlObject::EnumValue4, Qt::RightButton);
QCOMPARE(object->methodCalled(), true);
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("scriptConnect.6.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->property("test").toInt(), 0);
emit object->argumentSignal(19, "Hello world!", 10.25, MyQmlObject::EnumValue4, Qt::RightButton);
QCOMPARE(object->property("test").toInt(), 2);
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("scriptConnect.dynamic.1.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toInt(), 0);
- QMetaObject::invokeMethod(object, "outer");
+ QMetaObject::invokeMethod(object.data(), "outer");
QCOMPARE(object->property("test").toInt(), 1);
// process the dynamic object deletion queried with deleteLater()
@@ -3640,28 +3567,24 @@ void tst_qqmlecmascript::scriptConnect()
QCoreApplication::processEvents();
// after deletion, further invocations do not update the property
- QMetaObject::invokeMethod(object, "outer");
+ QMetaObject::invokeMethod(object.data(), "outer");
QCOMPARE(object->property("test").toInt(), 1);
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("scriptConnect.dynamic.2.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toInt(), 0);
- QMetaObject::invokeMethod(object, "outer");
+ QMetaObject::invokeMethod(object.data(), "outer");
QCOMPARE(object->property("test").toInt(), 1);
// no need to manually process events here, as we disconnect explicitly
- QMetaObject::invokeMethod(object, "outer");
+ QMetaObject::invokeMethod(object.data(), "outer");
QCOMPARE(object->property("test").toInt(), 1);
-
- delete object;
}
{
@@ -3680,7 +3603,9 @@ void tst_qqmlecmascript::scriptDisconnect()
{
QQmlComponent component(&engine, testFileUrl("scriptDisconnect.1.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->property("test").toInt(), 0);
@@ -3692,14 +3617,14 @@ void tst_qqmlecmascript::scriptDisconnect()
QCOMPARE(object->property("test").toInt(), 2);
emit object->argumentSignal(19, "Hello world!", 10.25, MyQmlObject::EnumValue4, Qt::RightButton);
QCOMPARE(object->property("test").toInt(), 2);
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("scriptDisconnect.2.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->property("test").toInt(), 0);
@@ -3711,14 +3636,14 @@ void tst_qqmlecmascript::scriptDisconnect()
QCOMPARE(object->property("test").toInt(), 2);
emit object->argumentSignal(19, "Hello world!", 10.25, MyQmlObject::EnumValue4, Qt::RightButton);
QCOMPARE(object->property("test").toInt(), 2);
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("scriptDisconnect.3.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->property("test").toInt(), 0);
@@ -3730,13 +3655,13 @@ void tst_qqmlecmascript::scriptDisconnect()
QCOMPARE(object->property("test").toInt(), 2);
emit object->argumentSignal(19, "Hello world!", 10.25, MyQmlObject::EnumValue4, Qt::RightButton);
QCOMPARE(object->property("test").toInt(), 3);
-
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("scriptDisconnect.4.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->property("test").toInt(), 0);
@@ -3748,8 +3673,6 @@ void tst_qqmlecmascript::scriptDisconnect()
QCOMPARE(object->property("test").toInt(), 2);
emit object->argumentSignal(19, "Hello world!", 10.25, MyQmlObject::EnumValue4, Qt::RightButton);
QCOMPARE(object->property("test").toInt(), 3);
-
- delete object;
}
}
@@ -3769,7 +3692,7 @@ void tst_qqmlecmascript::ownership()
{
QQmlEngine engine;
OwnershipObject own;
- QQmlContext *context = new QQmlContext(engine.rootContext());
+ QScopedPointer<QQmlContext>context(new QQmlContext(engine.rootContext()));
context->setContextObject(&own);
{
@@ -3777,7 +3700,7 @@ void tst_qqmlecmascript::ownership()
QVERIFY(own.object != nullptr);
- QObject *object = component.create(context);
+ QScopedPointer<QObject> object(component.create(context.data()));
engine.collectGarbage();
@@ -3785,8 +3708,6 @@ void tst_qqmlecmascript::ownership()
QCoreApplication::processEvents();
QVERIFY(own.object.isNull());
-
- delete object;
}
own.object = new QObject(&own);
@@ -3796,7 +3717,7 @@ void tst_qqmlecmascript::ownership()
QVERIFY(own.object != nullptr);
- QObject *object = component.create(context);
+ QScopedPointer<QObject> object(component.create(context.data()));
engine.collectGarbage();
@@ -3804,11 +3725,7 @@ void tst_qqmlecmascript::ownership()
QCoreApplication::processEvents();
QVERIFY(own.object != nullptr);
-
- delete object;
}
-
- delete context;
}
class CppOwnershipReturnValue : public QObject
@@ -3848,12 +3765,10 @@ void tst_qqmlecmascript::cppOwnershipReturnValue()
QQmlComponent component(&engine);
component.setData("import QtQuick 2.0\nQtObject {\nComponent.onCompleted: { var a = source.create(); }\n}\n", QUrl());
- QObject *object = component.create();
+ QScopedPointer<QObject> object(component.create());
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
QVERIFY(source.value != nullptr);
-
- delete object;
}
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
@@ -3877,12 +3792,10 @@ void tst_qqmlecmascript::ownershipCustomReturnValue()
QQmlComponent component(&engine);
component.setData("import QtQuick 2.0\nQtObject {\nComponent.onCompleted: { var a = source.createQmlObject(); }\n}\n", QUrl());
- QObject *object = component.create();
+ QScopedPointer<QObject> object(component.create());
QVERIFY(object != nullptr);
QVERIFY(source.value != nullptr);
-
- delete object;
}
engine.collectGarbage();
@@ -3911,12 +3824,12 @@ void tst_qqmlecmascript::ownershipRootObject()
{
QQmlEngine engine;
OwnershipChangingObject own;
- QQmlContext *context = new QQmlContext(engine.rootContext());
+ QScopedPointer<QQmlContext>context(new QQmlContext(engine.rootContext()));
context->setContextObject(&own);
QQmlComponent component(&engine, testFileUrl("ownershipRootObject.qml"));
- QPointer<QObject> object = component.create(context);
- QVERIFY(object);
+ QScopedPointer<QObject> object(component.create(context.data()));
+ QVERIFY2(object, qPrintable(component.errorString()));
engine.collectGarbage();
@@ -3924,16 +3837,13 @@ void tst_qqmlecmascript::ownershipRootObject()
QCoreApplication::processEvents();
QVERIFY(own.object != nullptr);
-
- delete context;
- delete object;
}
void tst_qqmlecmascript::ownershipConsistency()
{
QQmlEngine engine;
OwnershipChangingObject own;
- QQmlContext *context = new QQmlContext(engine.rootContext());
+ QScopedPointer<QQmlContext>context(new QQmlContext(engine.rootContext()));
context->setContextObject(&own);
QString expectedWarning = testFileUrl("ownershipConsistency.qml").toString() + QLatin1String(":19: Error: Invalid attempt to destroy() an indestructible object");
@@ -3946,8 +3856,8 @@ void tst_qqmlecmascript::ownershipConsistency()
QTest::ignoreMessage(QtWarningMsg, qPrintable(expectedWarning)); // we expect a meaningful warning to be printed.
QQmlComponent component(&engine, testFileUrl("ownershipConsistency.qml"));
- QPointer<QObject> object = component.create(context);
- QVERIFY(object);
+ QScopedPointer<QObject> object(component.create(context.data()));
+ QVERIFY2(object, qPrintable(component.errorString()));
engine.collectGarbage();
@@ -3955,28 +3865,23 @@ void tst_qqmlecmascript::ownershipConsistency()
QCoreApplication::processEvents();
QVERIFY(own.object != nullptr);
-
- delete context;
- delete object;
}
void tst_qqmlecmascript::ownershipQmlIncubated()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("ownershipQmlIncubated.qml"));
- QObject *object = component.create();
- QVERIFY(object);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QTRY_VERIFY(object->property("incubatedItem").value<QObject*>() != 0);
- QMetaObject::invokeMethod(object, "deleteIncubatedItem");
+ QMetaObject::invokeMethod(object.data(), "deleteIncubatedItem");
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
QCoreApplication::processEvents();
QVERIFY(!object->property("incubatedItem").value<QObject*>());
-
- delete object;
}
class QListQObjectMethodsObject : public QObject
@@ -4004,18 +3909,15 @@ void tst_qqmlecmascript::qlistqobjectMethods()
{
QQmlEngine engine;
QListQObjectMethodsObject obj;
- QQmlContext *context = new QQmlContext(engine.rootContext());
+ QScopedPointer<QQmlContext>context(new QQmlContext(engine.rootContext()));
context->setContextObject(&obj);
QQmlComponent component(&engine, testFileUrl("qlistqobjectMethods.qml"));
-
- QObject *object = component.create(context);
+ QScopedPointer<QObject> object(component.create(context.data()));
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toInt(), 2);
QCOMPARE(object->property("test2").toBool(), true);
-
- delete object;
- delete context;
}
// QTBUG-9205
@@ -4024,8 +3926,8 @@ void tst_qqmlecmascript::strictlyEquals()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("strictlyEquals.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test1").toBool(), true);
QCOMPARE(object->property("test2").toBool(), true);
@@ -4035,8 +3937,6 @@ void tst_qqmlecmascript::strictlyEquals()
QCOMPARE(object->property("test6").toBool(), true);
QCOMPARE(object->property("test7").toBool(), true);
QCOMPARE(object->property("test8").toBool(), true);
-
- delete object;
}
void tst_qqmlecmascript::compiled()
@@ -4044,8 +3944,8 @@ void tst_qqmlecmascript::compiled()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("compiled.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test1").toReal(), qreal(15.7));
QCOMPARE(object->property("test2").toReal(), qreal(-6.7));
@@ -4075,8 +3975,6 @@ void tst_qqmlecmascript::compiled()
QCOMPARE(object->property("test23").toBool(), true);
QCOMPARE(qvariant_cast<QColor>(object->property("test24")), QColor(0x11,0x22,0x33));
QCOMPARE(qvariant_cast<QColor>(object->property("test25")), QColor(0x11,0x22,0x33,0xAA));
-
- delete object;
}
// Test that numbers assigned in bindings as strings work consistently
@@ -4085,8 +3983,8 @@ void tst_qqmlecmascript::numberAssignment()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("numberAssignment.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test1"), QVariant((qreal)6.7));
QCOMPARE(object->property("test2"), QVariant((qreal)6.7));
@@ -4103,8 +4001,6 @@ void tst_qqmlecmascript::numberAssignment()
QCOMPARE(object->property("test10"), QVariant((unsigned int)7));
QCOMPARE(object->property("test11"), QVariant((unsigned int)6));
QCOMPARE(object->property("test12"), QVariant((unsigned int)6));
-
- delete object;
}
void tst_qqmlecmascript::propertySplicing()
@@ -4112,12 +4008,10 @@ void tst_qqmlecmascript::propertySplicing()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("propertySplicing.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toBool(), true);
-
- delete object;
}
// QTBUG-16683
@@ -4125,8 +4019,9 @@ void tst_qqmlecmascript::signalWithUnknownTypes()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("signalWithUnknownTypes.qml"));
-
- MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
MyQmlObject::MyType type;
@@ -4143,8 +4038,6 @@ void tst_qqmlecmascript::signalWithUnknownTypes()
QEXPECT_FAIL("", "New metaobject implementation causes test to pass", Continue);
QVERIFY(!object->variant().isValid());
-
- delete object;
}
void tst_qqmlecmascript::signalWithJSValueInVariant_data()
@@ -4180,7 +4073,9 @@ void tst_qqmlecmascript::signalWithJSValueInVariant()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("signalWithJSValueInVariant.qml"));
- QScopedPointer<MyQmlObject> object(qobject_cast<MyQmlObject *>(component.create()));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QJSValue value = engine.evaluate(expression);
@@ -4205,7 +4100,9 @@ void tst_qqmlecmascript::signalWithJSValueInVariant_twoEngines()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("signalWithJSValueInVariant.qml"));
- QScopedPointer<MyQmlObject> object(qobject_cast<MyQmlObject *>(component.create()));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QJSEngine engine2;
@@ -4239,7 +4136,9 @@ void tst_qqmlecmascript::signalWithQJSValue()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("signalWithQJSValue.qml"));
- QScopedPointer<MyQmlObject> object(qobject_cast<MyQmlObject *>(component.create()));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QJSValue value = engine.evaluate(expression);
@@ -4401,9 +4300,9 @@ void tst_qqmlecmascript::singletonType()
for (const QString &warning : qAsConst(warningMessages))
QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData());
- QObject *object = component.create();
+ QScopedPointer<QObject> object(component.create());
if (!errorMessage.isEmpty()) {
- QVERIFY(!object);
+ QVERIFY2(!object, qPrintable(component.errorString()));
} else {
QVERIFY(object != nullptr);
for (int i = 0; i < readProperties.size(); ++i)
@@ -4412,7 +4311,6 @@ void tst_qqmlecmascript::singletonType()
QVERIFY(object->setProperty(writeProperties.at(i).toLatin1().constData(), writeValues.at(i)));
for (int i = 0; i < readBackProperties.size(); ++i)
QCOMPARE(object->property(readBackProperties.at(i).toLatin1().constData()), readBackExpectedValues.at(i));
- delete object;
}
}
@@ -4439,40 +4337,37 @@ void tst_qqmlecmascript::singletonTypeCaching()
QQmlEngine cleanEngine;
QQmlComponent component(&cleanEngine, testfile);
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QList<QVariant> firstValues;
- QMetaObject::invokeMethod(object, "modifyValues");
+ QMetaObject::invokeMethod(object.data(), "modifyValues");
for (int i = 0; i < readProperties.size(); ++i)
firstValues << object->property(readProperties.at(i).toLatin1().constData());
- delete object;
+ object.reset();
QQmlComponent component2(&cleanEngine, testfile);
- QObject *object2 = component2.create();
- QVERIFY(object2 != nullptr);
+ QScopedPointer<QObject> object2(component2.create());
+ QVERIFY2(object2, qPrintable(component2.errorString()));
for (int i = 0; i < readProperties.size(); ++i)
QCOMPARE(object2->property(readProperties.at(i).toLatin1().constData()), firstValues.at(i)); // cached, shouldn't have changed.
- delete object2;
}
void tst_qqmlecmascript::singletonTypeImportOrder()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("singletontype/singletonTypeImportOrder.qml"));
- QObject *object = component.create();
- QVERIFY(object);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("v").toInt(), 1);
- delete object;
}
void tst_qqmlecmascript::singletonTypeResolution()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("singletontype/singletonTypeResolution.qml"));
- QObject *object = component.create();
- QVERIFY(object);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QVERIFY(object->property("success").toBool());
- delete object;
}
void tst_qqmlecmascript::verifyContextLifetime(const QQmlRefPointer<QQmlContextData> &ctxt) {
@@ -4775,7 +4670,7 @@ void tst_qqmlecmascript::importScripts()
QScopedPointer<QObject> object {component.create()};
if (!errorMessage.isEmpty()) {
- QVERIFY(!object);
+ QVERIFY2(!object, qPrintable(component.errorString()));
} else {
QVERIFY(!object.isNull());
tst_qqmlecmascript::verifyContextLifetime(QQmlContextData::get(engine.rootContext()));
@@ -4792,7 +4687,7 @@ void tst_qqmlecmascript::importCreationContext()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("jsimport/creationContext.qml"));
QScopedPointer<QObject> object(component.create());
- QVERIFY(!object.isNull());
+ QVERIFY2(object, qPrintable(component.errorString()));
bool success = object->property("success").toBool();
if (!success) {
QSignalSpy readySpy(object.data(), SIGNAL(loaded()));
@@ -4814,141 +4709,151 @@ void tst_qqmlecmascript::scarceResources_other()
QV4::ExecutionEngine *v4 = engine.handle();
ScarceResourceObject *eo = nullptr;
QObject *srsc = nullptr;
- QObject *object = nullptr;
+ QScopedPointer<QObject> object;
/* property var semantics */
// test that scarce resources are handled properly in signal invocation
QQmlComponent varComponentTen(&engine, testFileUrl("scarceResourceSignal.var.qml"));
- object = varComponentTen.create();
+ object.reset(varComponentTen.create());
+ QVERIFY2(object, qPrintable(varComponentTen.errorString()));
srsc = object->findChild<QObject*>("srsc");
QVERIFY(srsc);
QVERIFY(!srsc->property("scarceResourceCopy").isValid()); // hasn't been instantiated yet.
QCOMPARE(srsc->property("width"), QVariant(5)); // default value is 5.
- eo = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
+ eo = qobject_cast<ScarceResourceObject *>(
+ QQmlProperty::read(object.data(), "a").value<QObject*>());
QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage.
QMetaObject::invokeMethod(srsc, "testSignal");
QVERIFY(!srsc->property("scarceResourceCopy").isValid()); // still hasn't been instantiated
QCOMPARE(srsc->property("width"), QVariant(10)); // but width was assigned to 10.
- eo = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
+ eo = qobject_cast<ScarceResourceObject *>(
+ QQmlProperty::read(object.data(), "a").value<QObject*>());
QVERIFY(eo->scarceResourceIsDetached()); // should still be no other copies of it at this stage.
QMetaObject::invokeMethod(srsc, "testSignal2"); // assigns scarceResourceCopy to the scarce pixmap.
QVERIFY(srsc->property("scarceResourceCopy").isValid());
QCOMPARE(srsc->property("scarceResourceCopy").value<QPixmap>(), origPixmap);
- eo = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
+ eo = qobject_cast<ScarceResourceObject *>(
+ QQmlProperty::read(object.data(), "a").value<QObject*>());
QVERIFY(!(eo->scarceResourceIsDetached())); // should be another copy of the resource now.
QVERIFY(v4->scarceResources.isEmpty()); // should have been released by this point.
- delete object;
// test that scarce resources are handled properly from js functions in qml files
QQmlComponent varComponentEleven(&engine, testFileUrl("scarceResourceFunction.var.qml"));
- object = varComponentEleven.create();
- QVERIFY(object != nullptr);
+ object.reset(varComponentEleven.create());
+ QVERIFY2(object, qPrintable(varComponentEleven.errorString()));
QVERIFY(!object->property("scarceResourceCopy").isValid()); // not yet assigned, so should not be valid
- eo = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
+ eo = qobject_cast<ScarceResourceObject *>(
+ QQmlProperty::read(object.data(), "a").value<QObject*>());
QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage.
- QMetaObject::invokeMethod(object, "retrieveScarceResource");
+ QMetaObject::invokeMethod(object.data(), "retrieveScarceResource");
QVERIFY(object->property("scarceResourceCopy").isValid()); // assigned, so should be valid.
QCOMPARE(object->property("scarceResourceCopy").value<QPixmap>(), origPixmap);
- eo = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
+ eo = qobject_cast<ScarceResourceObject *>(
+ QQmlProperty::read(object.data(), "a").value<QObject*>());
QVERIFY(!eo->scarceResourceIsDetached()); // should be a copy of the resource at this stage.
- QMetaObject::invokeMethod(object, "releaseScarceResource");
+ QMetaObject::invokeMethod(object.data(), "releaseScarceResource");
QVERIFY(!object->property("scarceResourceCopy").isValid()); // just released, so should not be valid
- eo = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
+ eo = qobject_cast<ScarceResourceObject *>(
+ QQmlProperty::read(object.data(), "a").value<QObject*>());
QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage.
QVERIFY(v4->scarceResources.isEmpty()); // should have been released by this point.
- delete object;
// test that if an exception occurs while invoking js function from cpp, that the resources are released.
QQmlComponent varComponentTwelve(&engine, testFileUrl("scarceResourceFunctionFail.var.qml"));
- object = varComponentTwelve.create();
- QVERIFY(object != nullptr);
+ object.reset(varComponentTwelve.create());
+ QVERIFY2(object, qPrintable(varComponentTwelve.errorString()));
QVERIFY(!object->property("scarceResourceCopy").isValid()); // not yet assigned, so should not be valid
- eo = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
+ eo = qobject_cast<ScarceResourceObject *>(
+ QQmlProperty::read(object.data(), "a").value<QObject*>());
QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage.
expectedWarning = varComponentTwelve.url().toString() + QLatin1String(":16: TypeError: Property 'scarceResource' of object ScarceResourceObject(0x%1) is not a function");
expectedWarning = expectedWarning.arg(QString::number(quintptr(eo), 16));
QTest::ignoreMessage(QtWarningMsg, qPrintable(expectedWarning)); // we expect a meaningful warning to be printed.
- QMetaObject::invokeMethod(object, "retrieveScarceResource");
+ QMetaObject::invokeMethod(object.data(), "retrieveScarceResource");
QVERIFY(!object->property("scarceResourceCopy").isValid()); // due to exception, assignment will NOT have occurred.
- eo = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
+ eo = qobject_cast<ScarceResourceObject *>(
+ QQmlProperty::read(object.data(), "a").value<QObject*>());
QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage.
QVERIFY(v4->scarceResources.isEmpty()); // should have been released by this point.
- delete object;
// test that if an Item which has JS ownership but has a scarce resource property is garbage collected,
// that the scarce resource is removed from the engine's list of scarce resources to clean up.
QQmlComponent varComponentThirteen(&engine, testFileUrl("scarceResourceObjectGc.var.qml"));
- object = varComponentThirteen.create();
- QVERIFY(object != nullptr);
+ object.reset(varComponentThirteen.create());
+ QVERIFY2(object, qPrintable(varComponentThirteen.errorString()));
QVERIFY(!object->property("varProperty").isValid()); // not assigned yet
- QMetaObject::invokeMethod(object, "assignVarProperty");
+ QMetaObject::invokeMethod(object.data(), "assignVarProperty");
QVERIFY(v4->scarceResources.isEmpty()); // the scarce resource is a VME property.
- QMetaObject::invokeMethod(object, "deassignVarProperty");
+ QMetaObject::invokeMethod(object.data(), "deassignVarProperty");
gc(engine);
QVERIFY(v4->scarceResources.isEmpty()); // should still be empty; the resource should have been released on gc.
- delete object;
/* property variant semantics */
// test that scarce resources are handled properly in signal invocation
QQmlComponent variantComponentTen(&engine, testFileUrl("scarceResourceSignal.variant.qml"));
- object = variantComponentTen.create();
- QVERIFY(object != nullptr);
+ object.reset(variantComponentTen.create());
+ QVERIFY2(object, qPrintable(variantComponentTen.errorString()));
srsc = object->findChild<QObject*>("srsc");
QVERIFY(srsc);
QVERIFY(!srsc->property("scarceResourceCopy").isValid()); // hasn't been instantiated yet.
QCOMPARE(srsc->property("width"), QVariant(5)); // default value is 5.
- eo = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
+ eo = qobject_cast<ScarceResourceObject *>(
+ QQmlProperty::read(object.data(), "a").value<QObject*>());
QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage.
QMetaObject::invokeMethod(srsc, "testSignal");
QVERIFY(!srsc->property("scarceResourceCopy").isValid()); // still hasn't been instantiated
QCOMPARE(srsc->property("width"), QVariant(10)); // but width was assigned to 10.
- eo = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
+ eo = qobject_cast<ScarceResourceObject *>(
+ QQmlProperty::read(object.data(), "a").value<QObject*>());
QVERIFY(eo->scarceResourceIsDetached()); // should still be no other copies of it at this stage.
QMetaObject::invokeMethod(srsc, "testSignal2"); // assigns scarceResourceCopy to the scarce pixmap.
QVERIFY(srsc->property("scarceResourceCopy").isValid());
QCOMPARE(srsc->property("scarceResourceCopy").value<QPixmap>(), origPixmap);
- eo = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
+ eo = qobject_cast<ScarceResourceObject *>(
+ QQmlProperty::read(object.data(), "a").value<QObject*>());
QVERIFY(!(eo->scarceResourceIsDetached())); // should be another copy of the resource now.
QVERIFY(v4->scarceResources.isEmpty()); // should have been released by this point.
- delete object;
// test that scarce resources are handled properly from js functions in qml files
QQmlComponent variantComponentEleven(&engine, testFileUrl("scarceResourceFunction.variant.qml"));
- object = variantComponentEleven.create();
- QVERIFY(object != nullptr);
+ object.reset(variantComponentEleven.create());
+ QVERIFY2(object, qPrintable(variantComponentEleven.errorString()));
QVERIFY(!object->property("scarceResourceCopy").isValid()); // not yet assigned, so should not be valid
- eo = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
+ eo = qobject_cast<ScarceResourceObject *>(
+ QQmlProperty::read(object.data(), "a").value<QObject*>());
QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage.
- QMetaObject::invokeMethod(object, "retrieveScarceResource");
+ QMetaObject::invokeMethod(object.data(), "retrieveScarceResource");
QVERIFY(object->property("scarceResourceCopy").isValid()); // assigned, so should be valid.
QCOMPARE(object->property("scarceResourceCopy").value<QPixmap>(), origPixmap);
- eo = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
+ eo = qobject_cast<ScarceResourceObject *>(
+ QQmlProperty::read(object.data(), "a").value<QObject*>());
QVERIFY(!eo->scarceResourceIsDetached()); // should be a copy of the resource at this stage.
- QMetaObject::invokeMethod(object, "releaseScarceResource");
+ QMetaObject::invokeMethod(object.data(), "releaseScarceResource");
QVERIFY(!object->property("scarceResourceCopy").isValid()); // just released, so should not be valid
- eo = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
+ eo = qobject_cast<ScarceResourceObject *>(
+ QQmlProperty::read(object.data(), "a").value<QObject*>());
QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage.
QVERIFY(v4->scarceResources.isEmpty()); // should have been released by this point.
- delete object;
// test that if an exception occurs while invoking js function from cpp, that the resources are released.
QQmlComponent variantComponentTwelve(&engine, testFileUrl("scarceResourceFunctionFail.variant.qml"));
- object = variantComponentTwelve.create();
- QVERIFY(object != nullptr);
+ object.reset(variantComponentTwelve.create());
+ QVERIFY2(object, qPrintable(variantComponentTwelve.errorString()));
QVERIFY(!object->property("scarceResourceCopy").isValid()); // not yet assigned, so should not be valid
- eo = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
+ eo = qobject_cast<ScarceResourceObject *>(
+ QQmlProperty::read(object.data(), "a").value<QObject*>());
QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage.
expectedWarning = variantComponentTwelve.url().toString() + QLatin1String(":16: TypeError: Property 'scarceResource' of object ScarceResourceObject(0x%1) is not a function");
expectedWarning = expectedWarning.arg(QString::number(quintptr(eo), 16));
QTest::ignoreMessage(QtWarningMsg, qPrintable(expectedWarning)); // we expect a meaningful warning to be printed.
- QMetaObject::invokeMethod(object, "retrieveScarceResource");
+ QMetaObject::invokeMethod(object.data(), "retrieveScarceResource");
QVERIFY(!object->property("scarceResourceCopy").isValid()); // due to exception, assignment will NOT have occurred.
- eo = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
+ eo = qobject_cast<ScarceResourceObject *>(
+ QQmlProperty::read(object.data(), "a").value<QObject*>());
QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage.
QVERIFY(v4->scarceResources.isEmpty()); // should have been released by this point.
- delete object;
}
void tst_qqmlecmascript::scarceResources_data()
@@ -5097,11 +5002,10 @@ void tst_qqmlecmascript::scarceResources()
QQmlEngine engine;
QV4::ExecutionEngine *v4 = engine.handle();
ScarceResourceObject *eo = nullptr;
- QObject *object = nullptr;
QQmlComponent c(&engine, qmlFile);
- object = c.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(c.create());
+ QVERIFY2(object, qPrintable(c.errorString()));
for (int i = 0; i < propertyNames.size(); ++i) {
QString prop = propertyNames.at(i);
bool validity = expectedValidity.at(i).toBool();
@@ -5111,17 +5015,18 @@ void tst_qqmlecmascript::scarceResources()
if (value.typeId() == QMetaType::Int) {
QCOMPARE(object->property(prop.toLatin1().constData()).toInt(), value.toInt());
} else if (value.typeId() == QMetaType::QPixmap) {
- QCOMPARE(object->property(prop.toLatin1().constData()).value<QPixmap>(), value.value<QPixmap>());
+ QCOMPARE(object->property(prop.toLatin1().constData()).value<QPixmap>(),
+ value.value<QPixmap>());
}
}
if (readDetachStatus) {
- eo = qobject_cast<ScarceResourceObject*>(QQmlProperty::read(object, "a").value<QObject*>());
+ eo = qobject_cast<ScarceResourceObject *>(
+ QQmlProperty::read(object.data(), "a").value<QObject*>());
QCOMPARE(eo->scarceResourceIsDetached(), expectedDetachStatus);
}
QVERIFY(v4->scarceResources.isEmpty());
- delete object;
}
void tst_qqmlecmascript::propertyChangeSlots()
@@ -5129,42 +5034,37 @@ void tst_qqmlecmascript::propertyChangeSlots()
// ensure that allowable property names are allowed and onPropertyNameChanged slots are generated correctly.
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("changeslots/propertyChangeSlots.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- delete object;
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
// ensure that invalid property names fail properly.
QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready");
QQmlComponent e1(&engine, testFileUrl("changeslots/propertyChangeSlotErrors.1.qml"));
QString expectedErrorString = e1.url().toString() + QLatin1String(":9:5: Cannot assign to non-existent property \"on_nameWithUnderscoreChanged\"");
QCOMPARE(e1.errors().at(0).toString(), expectedErrorString);
- object = e1.create();
+ object.reset(e1.create());
QVERIFY(!object);
- delete object;
QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready");
QQmlComponent e2(&engine, testFileUrl("changeslots/propertyChangeSlotErrors.2.qml"));
expectedErrorString = e2.url().toString() + QLatin1String(":9:5: Cannot assign to non-existent property \"on____nameWithUnderscoresChanged\"");
QCOMPARE(e2.errors().at(0).toString(), expectedErrorString);
- object = e2.create();
+ object.reset(e2.create());
QVERIFY(!object);
- delete object;
QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready");
QQmlComponent e3(&engine, testFileUrl("changeslots/propertyChangeSlotErrors.3.qml"));
expectedErrorString = e3.url().toString() + QLatin1String(":9:5: Cannot assign to non-existent property \"on$NameWithDollarsignChanged\"");
QCOMPARE(e3.errors().at(0).toString(), expectedErrorString);
- object = e3.create();
+ object.reset(e3.create());
QVERIFY(!object);
- delete object;
QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready");
QQmlComponent e4(&engine, testFileUrl("changeslots/propertyChangeSlotErrors.4.qml"));
expectedErrorString = e4.url().toString() + QLatin1String(":9:5: Cannot assign to non-existent property \"on_6NameWithUnderscoreNumberChanged\"");
QCOMPARE(e4.errors().at(0).toString(), expectedErrorString);
- object = e4.create();
+ object.reset(e4.create());
QVERIFY(!object);
- delete object;
}
void tst_qqmlecmascript::propertyVar_data()
@@ -5196,12 +5096,10 @@ void tst_qqmlecmascript::propertyVar()
QQmlEngine engine;
QQmlComponent component(&engine, qmlFile);
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toBool(), true);
-
- delete object;
}
void tst_qqmlecmascript::propertyQJSValue_data()
@@ -5236,26 +5134,22 @@ void tst_qqmlecmascript::propertyQJSValue()
QQmlEngine engine;
QQmlComponent component(&engine, qmlFile);
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toBool(), true);
-
- delete object;
}
// Tests that we can write QVariant values to var properties from C++
void tst_qqmlecmascript::propertyVarCpp()
{
- QObject *object = nullptr;
-
// ensure that writing to and reading from a var property from cpp works as required.
// Literal values stored in var properties can be read and written as QVariants
// of a specific type, whereas object values are read as QVariantMaps.
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("propertyVarCpp.qml"));
- object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
// assign int to property var that currently has int assigned
QVERIFY(object->setProperty("varProperty", QVariant::fromValue(10)));
QCOMPARE(object->property("varBound"), QVariant(15));
@@ -5269,7 +5163,6 @@ void tst_qqmlecmascript::propertyVarCpp()
QCOMPARE(object->property("varProperty2").typeId(), QMetaType::QString);
// now enforce behaviour when accessing JavaScript objects from cpp.
QCOMPARE(object->property("jsobject").typeId(), qMetaTypeId<QJSValue>());
- delete object;
}
void tst_qqmlecmascript::propertyVarOwnership()
@@ -5279,33 +5172,31 @@ void tst_qqmlecmascript::propertyVarOwnership()
// Referenced JS objects are not collected
{
QQmlComponent component(&engine, testFileUrl("propertyVarOwnership.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toBool(), false);
- QMetaObject::invokeMethod(object, "runTest");
+ QMetaObject::invokeMethod(object.data(), "runTest");
QCOMPARE(object->property("test").toBool(), true);
- delete object;
}
// Referenced JS objects are not collected
{
QQmlComponent component(&engine, testFileUrl("propertyVarOwnership.2.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toBool(), false);
- QMetaObject::invokeMethod(object, "runTest");
+ QMetaObject::invokeMethod(object.data(), "runTest");
QCOMPARE(object->property("test").toBool(), true);
- delete object;
}
// Qt objects are not collected until they've been dereferenced
{
QQmlComponent component(&engine, testFileUrl("propertyVarOwnership.3.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test2").toBool(), false);
QCOMPARE(object->property("test2").toBool(), false);
- QMetaObject::invokeMethod(object, "runTest");
+ QMetaObject::invokeMethod(object.data(), "runTest");
QCOMPARE(object->property("test1").toBool(), true);
QPointer<QObject> referencedObject = object->property("object").value<QObject*>();
@@ -5313,18 +5204,16 @@ void tst_qqmlecmascript::propertyVarOwnership()
gc(engine);
QVERIFY(!referencedObject.isNull());
- QMetaObject::invokeMethod(object, "runTest2");
+ QMetaObject::invokeMethod(object.data(), "runTest2");
QCOMPARE(object->property("test2").toBool(), true);
gc(engine);
QVERIFY(referencedObject.isNull());
-
- delete object;
}
// Self reference does not prevent Qt object collection
{
QQmlComponent component(&engine, testFileUrl("propertyVarOwnership.4.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toBool(), true);
@@ -5333,22 +5222,19 @@ void tst_qqmlecmascript::propertyVarOwnership()
gc(engine);
QVERIFY(!referencedObject.isNull());
- QMetaObject::invokeMethod(object, "runTest");
+ QMetaObject::invokeMethod(object.data(), "runTest");
gc(engine);
QVERIFY(referencedObject.isNull());
-
- delete object;
}
// Garbage collection cannot result in attempted dereference of empty handle
{
QQmlComponent component(&engine, testFileUrl("propertyVarOwnership.5.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- QMetaObject::invokeMethod(object, "createComponent");
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
+ QMetaObject::invokeMethod(object.data(), "createComponent");
engine.collectGarbage();
- QMetaObject::invokeMethod(object, "runTest");
+ QMetaObject::invokeMethod(object.data(), "runTest");
QCOMPARE(object->property("test").toBool(), true);
- delete object;
}
}
@@ -5359,9 +5245,9 @@ void tst_qqmlecmascript::propertyVarImplicitOwnership()
// has implicit ownership of the constructed QObject.
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("propertyVarImplicitOwnership.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- QMetaObject::invokeMethod(object, "assignCircular");
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
+ QMetaObject::invokeMethod(object.data(), "assignCircular");
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); // process deleteLater() events from QV8QObjectWrapper.
QCoreApplication::processEvents();
QObject *rootObject = object->property("vp").value<QObject*>();
@@ -5370,16 +5256,16 @@ void tst_qqmlecmascript::propertyVarImplicitOwnership()
QVERIFY(childObject != nullptr);
QCOMPARE(rootObject->property("rectCanary").toInt(), 5);
QCOMPARE(childObject->property("textCanary").toInt(), 10);
- QMetaObject::invokeMethod(childObject, "constructQObject"); // creates a reference to a constructed QObject.
+ // Creates a reference to a constructed QObject:
+ QMetaObject::invokeMethod(childObject, "constructQObject");
QPointer<QObject> qobjectGuard(childObject->property("vp").value<QObject*>()); // get the pointer prior to processing deleteLater events.
QVERIFY(!qobjectGuard.isNull());
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); // process deleteLater() events from QV8QObjectWrapper.
QCoreApplication::processEvents();
QVERIFY(!qobjectGuard.isNull());
- QMetaObject::invokeMethod(object, "deassignCircular");
+ QMetaObject::invokeMethod(object.data(), "deassignCircular");
gc(engine);
QVERIFY(qobjectGuard.isNull()); // should have been collected now.
- delete object;
}
void tst_qqmlecmascript::propertyVarReparent()
@@ -5387,9 +5273,9 @@ void tst_qqmlecmascript::propertyVarReparent()
// ensure that nothing breaks if we re-parent objects
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("propertyVar.reparent.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- QMetaObject::invokeMethod(object, "assignVarProp");
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
+ QMetaObject::invokeMethod(object.data(), "assignVarProp");
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); // process deleteLater() events from QV8QObjectWrapper.
QCoreApplication::processEvents();
QObject *rect = object->property("vp").value<QObject*>();
@@ -5417,10 +5303,9 @@ void tst_qqmlecmascript::propertyVarReparent()
QCOMPARE(text2->property("textCanary").toInt(), 22);
QVERIFY(!imageGuard.isNull()); // should still be alive.
QCOMPARE(image->property("imageCanary").toInt(), 13); // still able to access var properties
- QMetaObject::invokeMethod(object, "deassignVarProp"); // now deassign the root-object's vp, causing gc of rect+text+text2
+ QMetaObject::invokeMethod(object.data(), "deassignVarProp"); // now deassign the root-object's vp, causing gc of rect+text+text2
gc(engine);
QVERIFY(imageGuard.isNull()); // should now have been deleted, due to parent being deleted.
- delete object;
}
void tst_qqmlecmascript::propertyVarReparentNullContext()
@@ -5430,9 +5315,9 @@ void tst_qqmlecmascript::propertyVarReparentNullContext()
// this test ensures that no crash occurs in that situation.
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("propertyVar.reparent.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- QMetaObject::invokeMethod(object, "assignVarProp");
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
+ QMetaObject::invokeMethod(object.data(), "assignVarProp");
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); // process deleteLater() events from QV8QObjectWrapper.
QCoreApplication::processEvents();
QObject *rect = object->property("vp").value<QObject*>();
@@ -5453,12 +5338,12 @@ void tst_qqmlecmascript::propertyVarReparentNullContext()
QVERIFY(!imageGuard.isNull());
QCOMPARE(image->property("imageCanary").toInt(), 13);
// now reparent the "Image" object (currently, it has JS ownership)
- image->setParent(object); // reparented to base object. after deassignVarProp, the ctxt will be invalid.
- QMetaObject::invokeMethod(object, "deassignVarProp"); // now deassign the root-object's vp, causing gc of rect+text+text2
+ image->setParent(object.data()); // reparented to base object. after deassignVarProp, the ctxt will be invalid.
+ QMetaObject::invokeMethod(object.data(), "deassignVarProp"); // now deassign the root-object's vp, causing gc of rect+text+text2
gc(engine);
QVERIFY(!imageGuard.isNull()); // should still be alive.
QVERIFY(!image->property("imageCanary").isValid()); // but varProperties won't be available (null context).
- delete object;
+ object.reset();
QVERIFY(imageGuard.isNull()); // should now be dead.
}
@@ -5467,9 +5352,9 @@ void tst_qqmlecmascript::propertyVarCircular()
// enforce behaviour regarding circular references - ensure qdvmemo deletion.
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("propertyVar.circular.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- QMetaObject::invokeMethod(object, "assignCircular"); // cause assignment and gc
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
+ QMetaObject::invokeMethod(object.data(), "assignCircular"); // cause assignment and gc
{
QCOMPARE(object->property("canaryInt"), QVariant(5));
QVariant canaryResourceVariant = object->property("canaryResource");
@@ -5483,15 +5368,14 @@ void tst_qqmlecmascript::propertyVarCircular()
QVERIFY(canaryResourceVariant.isValid());
QPixmap canaryResourcePixmap = canaryResourceVariant.value<QPixmap>();
canaryResourceVariant = QVariant(); // invalidate it to remove one copy of the pixmap from memory.
- QMetaObject::invokeMethod(object, "deassignCanaryResource"); // remove one copy of the pixmap from memory
+ QMetaObject::invokeMethod(object.data(), "deassignCanaryResource"); // remove one copy of the pixmap from memory
gc(engine);
QVERIFY(!canaryResourcePixmap.isDetached()); // two copies extant - this and the propertyVar.vp.vp.vp.vp.memoryHog.
- QMetaObject::invokeMethod(object, "deassignCircular"); // cause deassignment and gc
+ QMetaObject::invokeMethod(object.data(), "deassignCircular"); // cause deassignment and gc
gc(engine);
QCOMPARE(object->property("canaryInt"), QVariant(2));
QCOMPARE(object->property("canaryResource"), QVariant(1));
QVERIFY(canaryResourcePixmap.isDetached()); // now detached, since orig copy was member of qdvmemo which was deleted.
- delete object;
}
void tst_qqmlecmascript::propertyVarCircular2()
@@ -5500,9 +5384,9 @@ void tst_qqmlecmascript::propertyVarCircular2()
// where the child has a var property referencing its parent.
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("propertyVar.circular.2.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- QMetaObject::invokeMethod(object, "assignCircular");
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
+ QMetaObject::invokeMethod(object.data(), "assignCircular");
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); // process deleteLater() events from QV8QObjectWrapper.
QCoreApplication::processEvents();
QObject *rootObject = object->property("vp").value<QObject*>();
@@ -5516,11 +5400,10 @@ void tst_qqmlecmascript::propertyVarCircular2()
gc(engine);
QCOMPARE(rootObject->property("rectCanary").toInt(), 5);
QCOMPARE(childObject->property("textCanary").toInt(), 10);
- QMetaObject::invokeMethod(object, "deassignCircular");
+ QMetaObject::invokeMethod(object.data(), "deassignCircular");
gc(engine);
QVERIFY(rootObjectTracker.isNull()); // should have been collected
QVERIFY(childObjectTracker.isNull()); // should have been collected
- delete object;
}
void tst_qqmlecmascript::propertyVarInheritance()
@@ -5529,9 +5412,9 @@ void tst_qqmlecmascript::propertyVarInheritance()
// The particular component under test here has a chain of references.
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("propertyVar.inherit.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- QMetaObject::invokeMethod(object, "assignCircular"); // cause assignment and gc
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
+ QMetaObject::invokeMethod(object.data(), "assignCircular"); // cause assignment and gc
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); // process deleteLater() events from QV8QObjectWrapper.
QCoreApplication::processEvents();
// we want to be able to track when the varProperties array of the last metaobject is disposed
@@ -5558,13 +5441,13 @@ void tst_qqmlecmascript::propertyVarInheritance()
QVERIFY(!ccoCanaryHandle.isUndefined());
}
// now we deassign the var prop, which should trigger collection of item subtrees.
- QMetaObject::invokeMethod(object, "deassignCircular"); // cause deassignment and gc
+ QMetaObject::invokeMethod(object.data(), "deassignCircular"); // cause deassignment and gc
// ensure that there are only weak handles to the underlying varProperties array remaining.
gc(engine);
// an equivalent for pragma GCC optimize is still work-in-progress for CLang, so this test will fail.
QVERIFY(icoCanaryHandle.isUndefined());
QVERIFY(ccoCanaryHandle.isUndefined());
- delete object;
+ object.reset();
// since there are no parent vmemo's to keep implicit references alive, and the only handles
// to what remains are weak, all varProperties arrays must have been collected.
}
@@ -5575,9 +5458,9 @@ void tst_qqmlecmascript::propertyVarInheritance2()
// only link between rootObject and childObject is that rootObject is the parent of childObject.
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("propertyVar.circular.2.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- QMetaObject::invokeMethod(object, "assignCircular");
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
+ QMetaObject::invokeMethod(object.data(), "assignCircular");
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); // process deleteLater() events from QV8QObjectWrapper.
QCoreApplication::processEvents();
QObject *rootObject = object->property("vp").value<QObject*>();
@@ -5596,11 +5479,10 @@ void tst_qqmlecmascript::propertyVarInheritance2()
QCOMPARE(childObject->property("vp").value<QObject*>(), rootObject);
QCOMPARE(childObject->property("textCanary").toInt(), 10);
}
- QMetaObject::invokeMethod(object, "deassignCircular");
+ QMetaObject::invokeMethod(object.data(), "deassignCircular");
gc(engine);
// an equivalent for pragma GCC optimize is still work-in-progress for CLang, so this test will fail.
QVERIFY(childObjectVarArrayValueHandle.isUndefined()); // should have been collected now.
- delete object;
}
@@ -5610,12 +5492,10 @@ void tst_qqmlecmascript::elementAssign()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("elementAssign.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toBool(), true);
-
- delete object;
}
// QTBUG-12457
@@ -5624,12 +5504,10 @@ void tst_qqmlecmascript::objectPassThroughSignals()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("objectsPassThroughSignals.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toBool(), true);
-
- delete object;
}
// QTBUG-21626
@@ -5638,13 +5516,11 @@ void tst_qqmlecmascript::objectConversion()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("objectConversion.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QVariant retn;
- QMetaObject::invokeMethod(object, "circularObject", Q_RETURN_ARG(QVariant, retn));
+ QMetaObject::invokeMethod(object.data(), "circularObject", Q_RETURN_ARG(QVariant, retn));
QCOMPARE(retn.value<QJSValue>().property("test").toInt(), int(100));
-
- delete object;
}
@@ -5654,8 +5530,8 @@ void tst_qqmlecmascript::booleanConversion()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("booleanConversion.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test_true1").toBool(), true);
QCOMPARE(object->property("test_true2").toBool(), true);
@@ -5666,8 +5542,6 @@ void tst_qqmlecmascript::booleanConversion()
QCOMPARE(object->property("test_false1").toBool(), false);
QCOMPARE(object->property("test_false2").toBool(), false);
QCOMPARE(object->property("test_false3").toBool(), false);
-
- delete object;
}
void tst_qqmlecmascript::handleReferenceManagement()
@@ -5677,14 +5551,14 @@ void tst_qqmlecmascript::handleReferenceManagement()
// Linear QObject reference
QQmlEngine hrmEngine;
QQmlComponent component(&hrmEngine, testFileUrl("handleReferenceManagement.object.1.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
CircularReferenceObject *cro = object->findChild<CircularReferenceObject*>("cro");
cro->setDtorCount(&dtorCount);
- QMetaObject::invokeMethod(object, "createReference");
+ QMetaObject::invokeMethod(object.data(), "createReference");
gc(hrmEngine);
QCOMPARE(dtorCount, 0); // second has JS ownership, kept alive by first's reference
- delete object;
+ object.reset();
hrmEngine.collectGarbage();
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
QCoreApplication::processEvents();
@@ -5696,14 +5570,14 @@ void tst_qqmlecmascript::handleReferenceManagement()
// Circular QObject reference
QQmlEngine hrmEngine;
QQmlComponent component(&hrmEngine, testFileUrl("handleReferenceManagement.object.2.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
CircularReferenceObject *cro = object->findChild<CircularReferenceObject*>("cro");
cro->setDtorCount(&dtorCount);
- QMetaObject::invokeMethod(object, "circularReference");
+ QMetaObject::invokeMethod(object.data(), "circularReference");
gc(hrmEngine);
QCOMPARE(dtorCount, 2); // both should be cleaned up, since circular references shouldn't keep alive.
- delete object;
+ object.reset();
hrmEngine.collectGarbage();
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
QCoreApplication::processEvents();
@@ -5714,51 +5588,48 @@ void tst_qqmlecmascript::handleReferenceManagement()
// Dynamic variant property reference keeps target alive
QQmlEngine hrmEngine;
QQmlComponent component(&hrmEngine, testFileUrl("handleReferenceManagement.dynprop.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- QMetaObject::invokeMethod(object, "createReference");
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
+ QMetaObject::invokeMethod(object.data(), "createReference");
gc(hrmEngine);
- QMetaObject::invokeMethod(object, "ensureReference");
+ QMetaObject::invokeMethod(object.data(), "ensureReference");
gc(hrmEngine);
- QMetaObject::invokeMethod(object, "removeReference");
+ QMetaObject::invokeMethod(object.data(), "removeReference");
gc(hrmEngine);
- QMetaObject::invokeMethod(object, "ensureDeletion");
+ QMetaObject::invokeMethod(object.data(), "ensureDeletion");
QCOMPARE(object->property("success").toBool(), true);
- delete object;
}
{
// Dynamic Item property reference keeps target alive
QQmlEngine hrmEngine;
QQmlComponent component(&hrmEngine, testFileUrl("handleReferenceManagement.dynprop.2.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- QMetaObject::invokeMethod(object, "createReference");
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
+ QMetaObject::invokeMethod(object.data(), "createReference");
gc(hrmEngine);
- QMetaObject::invokeMethod(object, "ensureReference");
+ QMetaObject::invokeMethod(object.data(), "ensureReference");
gc(hrmEngine);
- QMetaObject::invokeMethod(object, "removeReference");
+ QMetaObject::invokeMethod(object.data(), "removeReference");
gc(hrmEngine);
- QMetaObject::invokeMethod(object, "ensureDeletion");
+ QMetaObject::invokeMethod(object.data(), "ensureDeletion");
QCOMPARE(object->property("success").toBool(), true);
- delete object;
}
{
// Item property reference to deleted item doesn't crash
QQmlEngine hrmEngine;
QQmlComponent component(&hrmEngine, testFileUrl("handleReferenceManagement.dynprop.3.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- QMetaObject::invokeMethod(object, "createReference");
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
+ QMetaObject::invokeMethod(object.data(), "createReference");
gc(hrmEngine);
- QMetaObject::invokeMethod(object, "ensureReference");
+ QMetaObject::invokeMethod(object.data(), "ensureReference");
gc(hrmEngine);
- QMetaObject::invokeMethod(object, "manuallyDelete");
+ QMetaObject::invokeMethod(object.data(), "manuallyDelete");
gc(hrmEngine);
- QMetaObject::invokeMethod(object, "ensureDeleted");
+ QMetaObject::invokeMethod(object.data(), "ensureDeleted");
QCOMPARE(object->property("success").toBool(), true);
- delete object;
}
}
@@ -5766,17 +5637,15 @@ void tst_qqmlecmascript::stringArg()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("stringArg.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- QMetaObject::invokeMethod(object, "success");
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
+ QMetaObject::invokeMethod(object.data(), "success");
QVERIFY(object->property("returnValue").toBool());
QString w1 = testFileUrl("stringArg.qml").toString() + QLatin1String(":45: Error: String.arg(): Invalid arguments");
QTest::ignoreMessage(QtWarningMsg, w1.toLatin1().constData());
- QMetaObject::invokeMethod(object, "failure");
+ QMetaObject::invokeMethod(object.data(), "failure");
QVERIFY(object->property("returnValue").toBool());
-
- delete object;
}
void tst_qqmlecmascript::readonlyDeclaration()
@@ -5784,12 +5653,10 @@ void tst_qqmlecmascript::readonlyDeclaration()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("readonlyDeclaration.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toBool(), true);
-
- delete object;
}
Q_DECLARE_METATYPE(QList<int>)
@@ -5804,12 +5671,12 @@ void tst_qqmlecmascript::sequenceConversionRead()
{
QUrl qmlFile = testFileUrl("sequenceConversion.read.qml");
QQmlComponent component(&engine, qmlFile);
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
MySequenceConversionObject *seq = object->findChild<MySequenceConversionObject*>("msco");
QVERIFY(seq != nullptr);
- QMetaObject::invokeMethod(object, "readSequences");
+ QMetaObject::invokeMethod(object.data(), "readSequences");
QList<int> intList; intList << 1 << 2 << 3 << 4;
QCOMPARE(object->property("intListLength").toInt(), intList.length());
QCOMPARE(object->property("intList").value<QList<int> >(), intList);
@@ -5829,7 +5696,7 @@ void tst_qqmlecmascript::sequenceConversionRead()
QCOMPARE(object->property("qstringListLength").toInt(), qstringList.length());
QCOMPARE(object->property("qstringList").value<QStringList>(), qstringList);
- QMetaObject::invokeMethod(object, "readSequenceElements");
+ QMetaObject::invokeMethod(object.data(), "readSequenceElements");
QCOMPARE(object->property("intVal").toInt(), 2);
QCOMPARE(object->property("qrealVal").toReal(), 2.2);
QCOMPARE(object->property("boolVal").toBool(), false);
@@ -5837,7 +5704,7 @@ void tst_qqmlecmascript::sequenceConversionRead()
QCOMPARE(object->property("urlVal").toUrl(), QUrl("http://www.example2.com"));
QCOMPARE(object->property("qstringVal").toString(), QString(QLatin1String("second")));
- QMetaObject::invokeMethod(object, "enumerateSequenceElements");
+ QMetaObject::invokeMethod(object.data(), "enumerateSequenceElements");
QCOMPARE(object->property("enumerationMatches").toBool(), true);
intList.clear(); intList << 1 << 2 << 3 << 4 << 5; // set by the enumerateSequenceElements test.
@@ -5846,17 +5713,15 @@ void tst_qqmlecmascript::sequenceConversionRead()
QQmlProperty seqProp2(seq, "intListProperty", &engine);
QCOMPARE(seqProp2.read().value<QList<int> >(), intList);
- QMetaObject::invokeMethod(object, "testReferenceDeletion");
+ QMetaObject::invokeMethod(object.data(), "testReferenceDeletion");
QCOMPARE(object->property("referenceDeletion").toBool(), true);
-
- delete object;
}
{
QUrl qmlFile = testFileUrl("sequenceConversion.read.error.qml");
QQmlComponent component(&engine, qmlFile);
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
MySequenceConversionObject *seq = object->findChild<MySequenceConversionObject*>("msco");
QVERIFY(seq != nullptr);
@@ -5864,12 +5729,11 @@ void tst_qqmlecmascript::sequenceConversionRead()
QString warningTwo = qmlFile.toString() + QLatin1String(":18: Error: Cannot assign [undefined] to int");
QTest::ignoreMessage(QtWarningMsg, warningTwo.toLatin1().constData());
- QMetaObject::invokeMethod(object, "performTest");
+ QMetaObject::invokeMethod(object.data(), "performTest");
// QList<NonRegisteredType> has not been registered as a sequence type.
QCOMPARE(object->property("pointListLength").toInt(), 0);
QVERIFY(!object->property("pointList").isValid());
- delete object;
}
}
@@ -5879,43 +5743,39 @@ void tst_qqmlecmascript::sequenceConversionWrite()
{
QUrl qmlFile = testFileUrl("sequenceConversion.write.qml");
QQmlComponent component(&engine, qmlFile);
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
MySequenceConversionObject *seq = object->findChild<MySequenceConversionObject*>("msco");
QVERIFY(seq != nullptr);
- QMetaObject::invokeMethod(object, "writeSequences");
+ QMetaObject::invokeMethod(object.data(), "writeSequences");
QCOMPARE(object->property("success").toBool(), true);
- QMetaObject::invokeMethod(object, "writeSequenceElements");
+ QMetaObject::invokeMethod(object.data(), "writeSequenceElements");
QCOMPARE(object->property("success").toBool(), true);
- QMetaObject::invokeMethod(object, "writeOtherElements");
+ QMetaObject::invokeMethod(object.data(), "writeOtherElements");
QCOMPARE(object->property("success").toBool(), true);
- QMetaObject::invokeMethod(object, "testReferenceDeletion");
+ QMetaObject::invokeMethod(object.data(), "testReferenceDeletion");
QCOMPARE(object->property("referenceDeletion").toBool(), true);
-
- delete object;
}
{
QUrl qmlFile = testFileUrl("sequenceConversion.write.error.qml");
QQmlComponent component(&engine, qmlFile);
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
MySequenceConversionObject *seq = object->findChild<MySequenceConversionObject*>("msco");
QVERIFY(seq != nullptr);
// Behavior change in 5.14: due to added auto-magical conversions, it is possible to assign to
// QList<QPoint>, even though it is not a registered sequence type
QTest::ignoreMessage(QtMsgType::QtWarningMsg, QRegularExpression("Could not convert array value at position 1 from QString to QPoint"));
- QMetaObject::invokeMethod(object, "performTest");
+ QMetaObject::invokeMethod(object.data(), "performTest");
QList<QPoint> pointList; pointList << QPoint(7, 7) << QPoint(0,0) << QPoint(8, 8) << QPoint(9, 9); // original values, shouldn't have changed
QCOMPARE(seq->pointListProperty(), pointList);
-
- delete object;
}
}
@@ -5926,7 +5786,7 @@ void tst_qqmlecmascript::sequenceConversionArray()
QQmlEngine engine;
QQmlComponent component(&engine, qmlFile);
QScopedPointer<QObject> object(component.create());
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
QMetaObject::invokeMethod(object.data(), "indexedAccess");
QVERIFY(object->property("success").toBool());
QMetaObject::invokeMethod(object.data(), "arrayOperations");
@@ -5947,19 +5807,18 @@ void tst_qqmlecmascript::sequenceConversionIndexes()
QUrl qmlFile = testFileUrl("sequenceConversion.indexes.qml");
QQmlEngine engine;
QQmlComponent component(&engine, qmlFile);
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QString w1 = qmlFile.toString() + QLatin1String(":34: Index out of range during length set");
QString w2 = qmlFile.toString() + QLatin1String(":41: Index out of range during indexed set");
QString w3 = qmlFile.toString() + QLatin1String(":48: Index out of range during indexed get");
QTest::ignoreMessage(QtWarningMsg, qPrintable(w1));
QTest::ignoreMessage(QtWarningMsg, qPrintable(w2));
QTest::ignoreMessage(QtWarningMsg, qPrintable(w3));
- QMetaObject::invokeMethod(object, "indexedAccess");
+ QMetaObject::invokeMethod(object.data(), "indexedAccess");
QVERIFY(object->property("success").toBool());
- QMetaObject::invokeMethod(object, "indexOf");
+ QMetaObject::invokeMethod(object.data(), "indexOf");
QVERIFY(object->property("success").toBool());
- delete object;
}
void tst_qqmlecmascript::sequenceConversionThreads()
@@ -5969,38 +5828,36 @@ void tst_qqmlecmascript::sequenceConversionThreads()
QUrl qmlFile = testFileUrl("sequenceConversion.threads.qml");
QQmlEngine engine;
QQmlComponent component(&engine, qmlFile);
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
- QMetaObject::invokeMethod(object, "testIntSequence");
+ QMetaObject::invokeMethod(object.data(), "testIntSequence");
QTRY_VERIFY(object->property("finished").toBool());
QVERIFY(object->property("success").toBool());
- QMetaObject::invokeMethod(object, "testQrealSequence");
+ QMetaObject::invokeMethod(object.data(), "testQrealSequence");
QTRY_VERIFY(object->property("finished").toBool());
QVERIFY(object->property("success").toBool());
- QMetaObject::invokeMethod(object, "testBoolSequence");
+ QMetaObject::invokeMethod(object.data(), "testBoolSequence");
QTRY_VERIFY(object->property("finished").toBool());
QVERIFY(object->property("success").toBool());
- QMetaObject::invokeMethod(object, "testStringSequence");
+ QMetaObject::invokeMethod(object.data(), "testStringSequence");
QTRY_VERIFY(object->property("finished").toBool());
QVERIFY(object->property("success").toBool());
- QMetaObject::invokeMethod(object, "testQStringSequence");
+ QMetaObject::invokeMethod(object.data(), "testQStringSequence");
QTRY_VERIFY(object->property("finished").toBool());
QVERIFY(object->property("success").toBool());
- QMetaObject::invokeMethod(object, "testUrlSequence");
+ QMetaObject::invokeMethod(object.data(), "testUrlSequence");
QTRY_VERIFY(object->property("finished").toBool());
QVERIFY(object->property("success").toBool());
- QMetaObject::invokeMethod(object, "testVariantSequence");
+ QMetaObject::invokeMethod(object.data(), "testVariantSequence");
QTRY_VERIFY(object->property("finished").toBool());
QVERIFY(object->property("success").toBool());
-
- delete object;
}
void tst_qqmlecmascript::sequenceConversionBindings()
@@ -6009,14 +5866,13 @@ void tst_qqmlecmascript::sequenceConversionBindings()
{
QUrl qmlFile = testFileUrl("sequenceConversion.bindings.qml");
QQmlComponent component(&engine, qmlFile);
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QList<int> intList; intList << 1 << 2 << 3 << 12 << 7;
QCOMPARE(object->property("boundSequence").value<QList<int> >(), intList);
QCOMPARE(object->property("boundElement").toInt(), intList.at(3));
QList<int> intListTwo; intListTwo << 1 << 2 << 3 << 12 << 14;
QCOMPARE(object->property("boundSequenceTwo").value<QList<int> >(), intListTwo);
- delete object;
}
{
@@ -6024,9 +5880,8 @@ void tst_qqmlecmascript::sequenceConversionBindings()
QString warning = QString(QLatin1String("%1:17:9: Unable to assign QList<int> to QList<bool>")).arg(qmlFile.toString());
QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData());
QQmlComponent component(&engine, qmlFile);
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- delete object;
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
}
}
@@ -6037,88 +5892,88 @@ void tst_qqmlecmascript::assignSequenceTypes()
// test binding array to sequence type property
{
QQmlComponent component(&engine, testFileUrl("assignSequenceTypes.1.qml"));
- MySequenceConversionObject *object = qobject_cast<MySequenceConversionObject *>(component.create());
- QVERIFY(object != nullptr);
+ QScopedPointer<MySequenceConversionObject> object(
+ qobject_cast<MySequenceConversionObject *>(component.create()));
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->intListProperty(), (QList<int>() << 1 << 2));
QCOMPARE(object->qrealListProperty(), (QList<qreal>() << 1.1 << 2.2 << 3));
QCOMPARE(object->boolListProperty(), (QList<bool>() << false << true));
QCOMPARE(object->urlListProperty(), (QList<QUrl>() << QUrl("http://www.example1.com") << QUrl("http://www.example2.com")));
QCOMPARE(object->stringListProperty(), (QList<QString>() << QLatin1String("one") << QLatin1String("two")));
QCOMPARE(object->qstringListProperty(), (QStringList() << QLatin1String("one") << QLatin1String("two")));
- delete object;
}
// test binding literal to sequence type property
{
QQmlComponent component(&engine, testFileUrl("assignSequenceTypes.2.qml"));
- MySequenceConversionObject *object = qobject_cast<MySequenceConversionObject *>(component.create());
- QVERIFY(object != nullptr);
+ QScopedPointer<MySequenceConversionObject> object(
+ qobject_cast<MySequenceConversionObject *>(component.create()));
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->intListProperty(), (QList<int>() << 1));
QCOMPARE(object->qrealListProperty(), (QList<qreal>() << 1.1));
QCOMPARE(object->boolListProperty(), (QList<bool>() << false));
QCOMPARE(object->urlListProperty(), (QList<QUrl>() << QUrl("http://www.example1.com")));
QCOMPARE(object->stringListProperty(), (QList<QString>() << QLatin1String("one")));
QCOMPARE(object->qstringListProperty(), (QStringList() << QLatin1String("two")));
- delete object;
}
// test binding single value to sequence type property
{
QQmlComponent component(&engine, testFileUrl("assignSequenceTypes.3.qml"));
- MySequenceConversionObject *object = qobject_cast<MySequenceConversionObject *>(component.create());
- QVERIFY(object != nullptr);
+ QScopedPointer<MySequenceConversionObject> object(
+ qobject_cast<MySequenceConversionObject *>(component.create()));
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->intListProperty(), (QList<int>() << 1));
QCOMPARE(object->qrealListProperty(), (QList<qreal>() << 1));
QCOMPARE(object->boolListProperty(), (QList<bool>() << false));
QCOMPARE(object->urlListProperty(), (QList<QUrl>() << QUrl(testFileUrl("example.html"))));
- delete object;
}
// test assigning array to sequence type property in js function
{
QQmlComponent component(&engine, testFileUrl("assignSequenceTypes.4.qml"));
- MySequenceConversionObject *object = qobject_cast<MySequenceConversionObject *>(component.create());
- QVERIFY(object != nullptr);
+ QScopedPointer<MySequenceConversionObject> object(
+ qobject_cast<MySequenceConversionObject *>(component.create()));
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->intListProperty(), (QList<int>() << 1 << 2));
QCOMPARE(object->qrealListProperty(), (QList<qreal>() << 1.1 << 2.2 << 3));
QCOMPARE(object->boolListProperty(), (QList<bool>() << false << true));
QCOMPARE(object->urlListProperty(), (QList<QUrl>() << QUrl("http://www.example1.com") << QUrl("http://www.example2.com")));
QCOMPARE(object->stringListProperty(), (QList<QString>() << QLatin1String("one") << QLatin1String("two")));
QCOMPARE(object->qstringListProperty(), (QStringList() << QLatin1String("one") << QLatin1String("two")));
- delete object;
}
// test assigning literal to sequence type property in js function
{
QQmlComponent component(&engine, testFileUrl("assignSequenceTypes.5.qml"));
- MySequenceConversionObject *object = qobject_cast<MySequenceConversionObject *>(component.create());
- QVERIFY(object != nullptr);
+ QScopedPointer<MySequenceConversionObject> object(
+ qobject_cast<MySequenceConversionObject *>(component.create()));
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->intListProperty(), (QList<int>() << 1));
QCOMPARE(object->qrealListProperty(), (QList<qreal>() << 1.1));
QCOMPARE(object->boolListProperty(), (QList<bool>() << false));
QCOMPARE(object->urlListProperty(), (QList<QUrl>() << QUrl("http://www.example1.com")));
QCOMPARE(object->stringListProperty(), (QList<QString>() << QLatin1String("one")));
QCOMPARE(object->qstringListProperty(), (QStringList() << QLatin1String("two")));
- delete object;
}
// test assigning single value to sequence type property in js function
{
QQmlComponent component(&engine, testFileUrl("assignSequenceTypes.6.qml"));
- MySequenceConversionObject *object = qobject_cast<MySequenceConversionObject *>(component.create());
- QVERIFY(object != nullptr);
+ QScopedPointer<MySequenceConversionObject> object(
+ qobject_cast<MySequenceConversionObject *>(component.create()));
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->intListProperty(), (QList<int>() << 1));
QCOMPARE(object->qrealListProperty(), (QList<qreal>() << 1));
QCOMPARE(object->boolListProperty(), (QList<bool>() << false));
QCOMPARE(object->urlListProperty(), (QList<QUrl>() << QUrl(testFileUrl("example.html"))));
- delete object;
}
// test QList<QUrl> literal assignment and binding assignment causes url resolution when required
{
QQmlComponent component(&engine, testFileUrl("assignSequenceTypes.7.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
MySequenceConversionObject *msco1 = object->findChild<MySequenceConversionObject *>(QLatin1String("msco1"));
MySequenceConversionObject *msco2 = object->findChild<MySequenceConversionObject *>(QLatin1String("msco2"));
MySequenceConversionObject *msco3 = object->findChild<MySequenceConversionObject *>(QLatin1String("msco3"));
@@ -6130,13 +5985,12 @@ void tst_qqmlecmascript::assignSequenceTypes()
QCOMPARE(msco3->urlListProperty(), (QList<QUrl>() << QUrl("example.html") << QUrl("example2.html")));
QCOMPARE(msco4->urlListProperty(), (QList<QUrl>() << QUrl("example.html") << QUrl("example2.html")));
QCOMPARE(msco5->urlListProperty(), (QList<QUrl>() << QUrl(testFileUrl("example.html")) << QUrl(testFileUrl("example2.html"))));
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("assignSequenceTypes.8.qml"));
QScopedPointer<QObject> object(component.create());
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
QVariant result;
QMetaObject::invokeMethod(object.data(), "tryWritingReadOnlySequence", Q_RETURN_ARG(QVariant, result));
QVERIFY(result.typeId() == QMetaType::Bool);
@@ -6151,12 +6005,10 @@ void tst_qqmlecmascript::nullObjectBinding()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("nullObjectBinding.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QVERIFY(object->property("test") == QVariant::fromValue((QObject *)nullptr));
-
- delete object;
}
void tst_qqmlecmascript::nullObjectInitializer()
@@ -6165,7 +6017,7 @@ void tst_qqmlecmascript::nullObjectInitializer()
{
QQmlComponent component(&engine, testFileUrl("nullObjectInitializer.qml"));
QScopedPointer<QObject> obj(component.create());
- QVERIFY(!obj.isNull());
+ QVERIFY2(obj, qPrintable(component.errorString()));
QQmlData *ddata = QQmlData::get(obj.data(), /*create*/false);
QVERIFY(ddata);
@@ -6184,7 +6036,7 @@ void tst_qqmlecmascript::nullObjectInitializer()
{
QQmlComponent component(&engine, testFileUrl("nullObjectInitializer.2.qml"));
QScopedPointer<QObject> obj(component.create());
- QVERIFY(!obj.isNull());
+ QVERIFY2(obj, qPrintable(component.errorString()));
QQmlData *ddata = QQmlData::get(obj.data(), /*create*/false);
QVERIFY(ddata);
@@ -6205,7 +6057,7 @@ void tst_qqmlecmascript::nullObjectInitializer()
{
QQmlComponent component(&engine, testFileUrl("qmlVarNullBinding.qml"));
QScopedPointer<QObject> obj(component.create());
- QVERIFY(!obj.isNull());
+ QVERIFY2(obj, qPrintable(component.errorString()));
QVERIFY(!obj->property("signalSeen").toBool());
}
}
@@ -6216,8 +6068,7 @@ void tst_qqmlecmascript::deletedEngine()
QScopedPointer<QQmlEngine> engine(new QQmlEngine);
QQmlComponent component(engine.data(), testFileUrl("deletedEngine.qml"));
QScopedPointer<QObject> object(component.create());
-
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("a").toInt(), 39);
object->setProperty("b", QVariant(9));
@@ -6237,10 +6088,8 @@ void tst_qqmlecmascript::libraryScriptAssert()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("libraryScriptAssert.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
-
- delete object;
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
}
void tst_qqmlecmascript::variantsAssignedUndefined()
@@ -6248,8 +6097,8 @@ void tst_qqmlecmascript::variantsAssignedUndefined()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("variantsAssignedUndefined.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test1").toInt(), 10);
QCOMPARE(object->property("test2").toInt(), 11);
@@ -6258,9 +6107,6 @@ void tst_qqmlecmascript::variantsAssignedUndefined()
QCOMPARE(object->property("test1"), QVariant());
QCOMPARE(object->property("test2"), QVariant());
-
-
- delete object;
}
void tst_qqmlecmascript::variants()
@@ -6269,7 +6115,7 @@ void tst_qqmlecmascript::variants()
QQmlComponent component(&engine, testFileUrl("variants.qml"));
QScopedPointer<QObject> object(component.create());
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("undefinedVariant").typeId(), QMetaType::UnknownType);
QCOMPARE(object->property("nullVariant").typeId(), QMetaType::Nullptr);
@@ -6300,6 +6146,7 @@ void tst_qqmlecmascript::qtbug_9792()
// to the root QQmlContextData. We want the context data to be destroyed.
QQmlComponent component(&engine, testFileUrl("qtbug_9792.qml"));
object.reset(component.create(context.data()));
+ QVERIFY2(object, qPrintable(component.errorString()));
myQmlObject = qobject_cast<MyQmlObject*>(object.data());
}
QVERIFY(myQmlObject != nullptr);
@@ -6322,20 +6169,22 @@ void tst_qqmlecmascript::qtcreatorbug_1289()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("qtcreatorbug_1289.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
- QObject *nested = qvariant_cast<QObject *>(o->property("object"));
+ {
+ QScopedPointer<QObject>nested(qvariant_cast<QObject *>(o->property("object")));
QVERIFY(nested != nullptr);
- QVERIFY(qvariant_cast<QObject *>(nested->property("nestedObject")) == o);
+ QVERIFY(qvariant_cast<QObject *>(nested->property("nestedObject")) == o.data());
- delete nested;
- nested = qvariant_cast<QObject *>(o->property("object"));
+ nested.reset(nullptr); // Old one must be deleted before new is asked for.
+ nested.reset(qvariant_cast<QObject *>(o->property("object")));
QVERIFY(!nested);
+ }
// If the bug is present, the next line will crash
- delete o;
+ o.reset();
}
// Test that we shut down without stupid warnings
@@ -6345,11 +6194,11 @@ void tst_qqmlecmascript::noSpuriousWarningsAtShutdown()
{
QQmlComponent component(&engine, testFileUrl("noSpuriousWarningsAtShutdown.qml"));
- QObject *o = component.create();
+ QScopedPointer<QObject> o(component.create());
QQmlTestMessageHandler messageHandler;
- delete o;
+ o.reset();
QVERIFY2(messageHandler.messages().isEmpty(), qPrintable(messageHandler.messageString()));
}
@@ -6358,11 +6207,11 @@ void tst_qqmlecmascript::noSpuriousWarningsAtShutdown()
{
QQmlComponent component(&engine, testFileUrl("noSpuriousWarningsAtShutdown.2.qml"));
- QObject *o = component.create();
+ QScopedPointer<QObject> o(component.create());
QQmlTestMessageHandler messageHandler;
- delete o;
+ o.reset();
QVERIFY2(messageHandler.messages().isEmpty(), qPrintable(messageHandler.messageString()));
}
@@ -6374,7 +6223,9 @@ void tst_qqmlecmascript::canAssignNullToQObject()
{
QQmlComponent component(&engine, testFileUrl("canAssignNullToQObject.1.qml"));
- MyQmlObject *o = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *o = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(o != nullptr);
QVERIFY(o->objectProperty() != nullptr);
@@ -6382,19 +6233,17 @@ void tst_qqmlecmascript::canAssignNullToQObject()
o->setProperty("runTest", true);
QVERIFY(!o->objectProperty());
-
- delete o;
}
{
QQmlComponent component(&engine, testFileUrl("canAssignNullToQObject.2.qml"));
- MyQmlObject *o = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *o = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(o != nullptr);
QVERIFY(!o->objectProperty());
-
- delete o;
}
}
@@ -6409,11 +6258,10 @@ void tst_qqmlecmascript::functionAssignment_fromBinding()
QTest::ignoreMessage(QtWarningMsg, w1.toLatin1().constData());
QTest::ignoreMessage(QtWarningMsg, w2.toLatin1().constData());
- MyQmlObject *o = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *o = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(o != nullptr);
-
-
- delete o;
}
void tst_qqmlecmascript::functionAssignment_fromJS()
@@ -6424,7 +6272,9 @@ void tst_qqmlecmascript::functionAssignment_fromJS()
QQmlComponent component(&engine, testFileUrl("functionAssignment.2.qml"));
QVERIFY2(component.errorString().isEmpty(), qPrintable(component.errorString()));
- MyQmlObject *o = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *o = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(o != nullptr);
QVERIFY(!o->property("a").isValid());
@@ -6434,8 +6284,6 @@ void tst_qqmlecmascript::functionAssignment_fromJS()
o->setProperty("aNumber", QVariant(10));
QCOMPARE(o->property("a"), QVariant(100));
-
- delete o;
}
void tst_qqmlecmascript::functionAssignment_fromJS_data()
@@ -6457,7 +6305,9 @@ void tst_qqmlecmascript::functionAssignmentfromJS_invalid()
QQmlComponent component(&engine, testFileUrl("functionAssignment.2.qml"));
QVERIFY2(component.errorString().isEmpty(), qPrintable(component.errorString()));
- MyQmlObject *o = qobject_cast<MyQmlObject *>(component.create());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *o = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(o != nullptr);
QVERIFY(!o->property("a").isValid());
@@ -6472,8 +6322,6 @@ void tst_qqmlecmascript::functionAssignmentfromJS_invalid()
warning = url + ":71: Unable to assign QString to int";
QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData());
o->setProperty("assignWrongTypeToValueType", true);
-
- delete o;
}
void tst_qqmlecmascript::functionAssignment_afterBinding()
@@ -6485,12 +6333,10 @@ void tst_qqmlecmascript::functionAssignment_afterBinding()
QString w1 = url + ":16: Error: Cannot assign JavaScript function to int";
QTest::ignoreMessage(QtWarningMsg, w1.toLatin1().constData());
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("t1"), QVariant::fromValue<int>(4)); // should have bound
QCOMPARE(o->property("t2"), QVariant::fromValue<int>(2)); // should not have changed
-
- delete o;
}
void tst_qqmlecmascript::eval()
@@ -6498,16 +6344,14 @@ void tst_qqmlecmascript::eval()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("eval.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test1").toBool(), true);
QCOMPARE(o->property("test2").toBool(), true);
QCOMPARE(o->property("test3").toBool(), true);
QCOMPARE(o->property("test4").toBool(), true);
QCOMPARE(o->property("test5").toBool(), true);
-
- delete o;
}
void tst_qqmlecmascript::function()
@@ -6515,14 +6359,12 @@ void tst_qqmlecmascript::function()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("function.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test1").toBool(), true);
QCOMPARE(o->property("test2").toBool(), true);
QCOMPARE(o->property("test3").toBool(), true);
-
- delete o;
}
// QTBUG-77096
@@ -6532,9 +6374,7 @@ void tst_qqmlecmascript::topLevelGeneratorFunction()
QQmlComponent component(&engine, testFileUrl("generatorFunction.qml"));
QScopedPointer<QObject> o {component.create()};
- if (!o)
- qDebug() << component.errorString();
- QVERIFY(o != nullptr);
+ QVERIFY2(o, qPrintable(component.errorString()));
// check that generator works correctly in QML
QCOMPARE(o->property("test1").toBool(), true);
@@ -6556,7 +6396,6 @@ void tst_qqmlecmascript::generatorCrashNewProperty()
QQmlComponent component(&engine, testFileUrl("generatorCrashNewProperty.qml"));
QScopedPointer<QObject> o(component.create());
-
QVERIFY2(o != nullptr, qPrintable(component.errorString()));
QCOMPARE(o->property("a").toInt(), 42);
@@ -6572,7 +6411,7 @@ void tst_qqmlecmascript::include()
{
QQmlComponent component(&engine, testFileUrl("include.qml"));
QScopedPointer<QObject> o(component.create());
- QVERIFY(o != nullptr);
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test0").toInt(), 99);
QCOMPARE(o->property("test1").toBool(), true);
@@ -6587,7 +6426,7 @@ void tst_qqmlecmascript::include()
{
QQmlComponent component(&engine, testFileUrl("include_shared.qml"));
QScopedPointer<QObject> o(component.create());
- QVERIFY(o != nullptr);
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test0").toInt(), 99);
QCOMPARE(o->property("test1").toBool(), true);
@@ -6602,7 +6441,7 @@ void tst_qqmlecmascript::include()
{
QQmlComponent component(&engine, testFileUrl("include_callback.qml"));
QScopedPointer<QObject> o(component.create());
- QVERIFY(o != nullptr);
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test1").toBool(), true);
QCOMPARE(o->property("test2").toBool(), true);
@@ -6617,7 +6456,7 @@ void tst_qqmlecmascript::include()
{
QQmlComponent component(&engine, testFileUrl("include_pragma.qml"));
QScopedPointer<QObject> o(component.create());
- QVERIFY(o != nullptr);
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test1").toInt(), 100);
}
@@ -6626,7 +6465,7 @@ void tst_qqmlecmascript::include()
{
QQmlComponent component(&engine, testFileUrl("include_pragma_shadow.qml"));
QScopedPointer<QObject> o(component.create());
- QVERIFY(!o.isNull());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("result").toBool(), true);
}
@@ -6647,14 +6486,13 @@ void tst_qqmlecmascript::include()
QCOMPARE(o->property("test1").toBool(), true);
QCOMPARE(o->property("test2").toBool(), true);
QCOMPARE(o->property("test3").toBool(), true);
-
}
// include from resources
{
QQmlComponent component(&engine, QUrl("qrc:///data/include.qml"));
QScopedPointer<QObject> o(component.create());
- QVERIFY(o != nullptr);
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test0").toInt(), 99);
QCOMPARE(o->property("test1").toBool(), true);
@@ -6662,7 +6500,6 @@ void tst_qqmlecmascript::include()
QCOMPARE(o->property("test2_1").toBool(), true);
QCOMPARE(o->property("test3").toBool(), true);
QCOMPARE(o->property("test3_1").toBool(), true);
-
}
}
@@ -6676,7 +6513,7 @@ void tst_qqmlecmascript::includeRemoteSuccess()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("include_remote.qml"));
- QObject *o = component.beginCreate(engine.rootContext());
+ QScopedPointer<QObject>o(component.beginCreate(engine.rootContext()));
QVERIFY(o != nullptr);
o->setProperty("serverBaseUrl", server.baseUrl().toString());
component.completeCreate();
@@ -6695,8 +6532,6 @@ void tst_qqmlecmascript::includeRemoteSuccess()
QCOMPARE(o->property("test8").toBool(), true);
QCOMPARE(o->property("test9").toBool(), true);
QCOMPARE(o->property("test10").toBool(), true);
-
- delete o;
}
void tst_qqmlecmascript::signalHandlers()
@@ -6704,7 +6539,7 @@ void tst_qqmlecmascript::signalHandlers()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("signalHandlers.qml"));
QScopedPointer<QObject> o(component.create());
- QVERIFY(o != nullptr);
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("count").toInt(), 0);
QMetaObject::invokeMethod(o.data(), "testSignalCall");
QCOMPARE(o->property("count").toInt(), 1);
@@ -6755,7 +6590,7 @@ void tst_qqmlecmascript::qtbug_37351()
engine.rootContext()->setContextProperty("testObject", &signalEmitter);
QScopedPointer<QObject> object(component.create());
- QVERIFY(!object.isNull());
+ QVERIFY2(object, qPrintable(component.errorString()));
}
signalEmitter.doAction();
// Don't crash
@@ -6765,39 +6600,35 @@ void tst_qqmlecmascript::qtbug_10696()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("qtbug_10696.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
- delete o;
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
}
void tst_qqmlecmascript::qtbug_11606()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("qtbug_11606.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test").toBool(), true);
- delete o;
}
void tst_qqmlecmascript::qtbug_11600()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("qtbug_11600.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test").toBool(), true);
- delete o;
}
void tst_qqmlecmascript::qtbug_21864()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("qtbug_21864.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test").toBool(), true);
- delete o;
}
void tst_qqmlecmascript::rewriteMultiLineStrings()
@@ -6806,17 +6637,15 @@ void tst_qqmlecmascript::rewriteMultiLineStrings()
{
// QTBUG-23387
QQmlComponent component(&engine, testFileUrl("rewriteMultiLineStrings.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QTRY_COMPARE(o->property("test").toBool(), true);
- delete o;
}
{
QQmlComponent component(&engine, testFileUrl("rewriteMultiLineStrings_crlf.1.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
- delete o;
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
}
}
@@ -6829,10 +6658,9 @@ void tst_qqmlecmascript::qobjectConnectionListExceptionHandling()
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test").toBool(), true);
- delete o;
}
// Reading and writing non-scriptable properties should fail
@@ -6840,11 +6668,10 @@ void tst_qqmlecmascript::nonscriptable()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("nonscriptable.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("readOk").toBool(), true);
QCOMPARE(o->property("writeOk").toBool(), true);
- delete o;
}
// deleteLater() should not be callable from QML
@@ -6852,10 +6679,9 @@ void tst_qqmlecmascript::deleteLater()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("deleteLater.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test").toBool(), true);
- delete o;
}
// objectNameChanged() should be usable from QML
@@ -6863,12 +6689,11 @@ void tst_qqmlecmascript::objectNameChangedSignal()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("objectNameChangedSignal.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test").toBool(), false);
o->setObjectName("obj");
QCOMPARE(o->property("test").toBool(), true);
- delete o;
}
// destroyed() should not be usable from QML
@@ -6886,11 +6711,10 @@ void tst_qqmlecmascript::in()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("in.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test1").toBool(), true);
QCOMPARE(o->property("test2").toBool(), true);
- delete o;
}
void tst_qqmlecmascript::typeOf()
@@ -6898,8 +6722,8 @@ void tst_qqmlecmascript::typeOf()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("typeOf.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test1").toString(), QLatin1String("undefined"));
QCOMPARE(o->property("test2").toString(), QLatin1String("object"));
@@ -6910,8 +6734,6 @@ void tst_qqmlecmascript::typeOf()
QCOMPARE(o->property("test7").toString(), QLatin1String("undefined"));
QCOMPARE(o->property("test8").toString(), QLatin1String("boolean"));
QCOMPARE(o->property("test9").toString(), QLatin1String("object"));
-
- delete o;
}
void tst_qqmlecmascript::qtbug_24448()
@@ -6919,7 +6741,7 @@ void tst_qqmlecmascript::qtbug_24448()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("qtbug_24448.qml"));
QScopedPointer<QObject> o(component.create());
- QVERIFY(o != nullptr);
+ QVERIFY2(o, qPrintable(component.errorString()));
QVERIFY(o->property("test").toBool());
}
@@ -6927,11 +6749,10 @@ void tst_qqmlecmascript::sharedAttachedObject()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("sharedAttachedObject.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test1").toBool(), true);
QCOMPARE(o->property("test2").toBool(), true);
- delete o;
}
// QTBUG-13999
@@ -6939,8 +6760,8 @@ void tst_qqmlecmascript::objectName()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("objectName.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test1").toString(), QString("hello"));
QCOMPARE(o->property("test2").toString(), QString("ell"));
@@ -6949,20 +6770,16 @@ void tst_qqmlecmascript::objectName()
QCOMPARE(o->property("test1").toString(), QString("world"));
QCOMPARE(o->property("test2").toString(), QString("orl"));
-
- delete o;
}
void tst_qqmlecmascript::writeRemovesBinding()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("writeRemovesBinding.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test").toBool(), true);
-
- delete o;
}
// Test bindings assigned to alias properties actually assign to the alias' target
@@ -6970,12 +6787,10 @@ void tst_qqmlecmascript::aliasBindingsAssignCorrectly()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("aliasBindingsAssignCorrectly.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test").toBool(), true);
-
- delete o;
}
// Test bindings assigned to alias properties override a binding on the target (QTBUG-13719)
@@ -6984,32 +6799,26 @@ void tst_qqmlecmascript::aliasBindingsOverrideTarget()
QQmlEngine engine;
{
QQmlComponent component(&engine, testFileUrl("aliasBindingsOverrideTarget.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test").toBool(), true);
-
- delete o;
}
{
QQmlComponent component(&engine, testFileUrl("aliasBindingsOverrideTarget.2.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test").toBool(), true);
-
- delete o;
}
{
QQmlComponent component(&engine, testFileUrl("aliasBindingsOverrideTarget.3.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test").toBool(), true);
-
- delete o;
}
}
@@ -7019,32 +6828,26 @@ void tst_qqmlecmascript::aliasWritesOverrideBindings()
QQmlEngine engine;
{
QQmlComponent component(&engine, testFileUrl("aliasWritesOverrideBindings.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test").toBool(), true);
-
- delete o;
}
{
QQmlComponent component(&engine, testFileUrl("aliasWritesOverrideBindings.2.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test").toBool(), true);
-
- delete o;
}
{
QQmlComponent component(&engine, testFileUrl("aliasWritesOverrideBindings.3.qml"));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(o->property("test").toBool(), true);
-
- delete o;
}
}
@@ -7055,10 +6858,8 @@ void tst_qqmlecmascript::aliasToCompositeElement()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("aliasToCompositeElement.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
-
- delete object;
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
}
void tst_qqmlecmascript::qtbug_20344()
@@ -7069,10 +6870,8 @@ void tst_qqmlecmascript::qtbug_20344()
QString warning = component.url().toString() + ":5: Error: Exception thrown from within QObject slot";
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
-
- delete object;
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
}
void tst_qqmlecmascript::revisionErrors()
@@ -7089,9 +6888,9 @@ void tst_qqmlecmascript::revisionErrors()
QTest::ignoreMessage(QtWarningMsg, warning1.toLatin1().constData());
QTest::ignoreMessage(QtWarningMsg, warning2.toLatin1().constData());
QTest::ignoreMessage(QtWarningMsg, warning3.toLatin1().constData());
- MyRevisionedClass *object = qobject_cast<MyRevisionedClass *>(component.create());
- QVERIFY(object != nullptr);
- delete object;
+ QScopedPointer<MyRevisionedClass> object(
+ qobject_cast<MyRevisionedClass *>(component.create()));
+ QVERIFY2(object, qPrintable(component.errorString()));
}
{
QQmlComponent component(&engine, testFileUrl("metaobjectRevisionErrors2.qml"));
@@ -7111,9 +6910,9 @@ void tst_qqmlecmascript::revisionErrors()
QTest::ignoreMessage(QtWarningMsg, warning3.toLatin1().constData());
QTest::ignoreMessage(QtWarningMsg, warning4.toLatin1().constData());
QTest::ignoreMessage(QtWarningMsg, warning5.toLatin1().constData());
- MyRevisionedClass *object = qobject_cast<MyRevisionedClass *>(component.create());
- QVERIFY(object != nullptr);
- delete object;
+ QScopedPointer<MyRevisionedClass> object(
+ qobject_cast<MyRevisionedClass *>(component.create()));
+ QVERIFY2(object, qPrintable(component.errorString()));
}
{
QQmlComponent component(&engine, testFileUrl("metaobjectRevisionErrors3.qml"));
@@ -7127,9 +6926,9 @@ void tst_qqmlecmascript::revisionErrors()
QTest::ignoreMessage(QtWarningMsg, warning1.toLatin1().constData());
QTest::ignoreMessage(QtWarningMsg, warning2.toLatin1().constData());
QTest::ignoreMessage(QtWarningMsg, warning3.toLatin1().constData());
- MyRevisionedClass *object = qobject_cast<MyRevisionedClass *>(component.create());
- QVERIFY(object != nullptr);
- delete object;
+ QScopedPointer<MyRevisionedClass> object(
+ qobject_cast<MyRevisionedClass *>(component.create()));
+ QVERIFY2(object, qPrintable(component.errorString()));
}
}
@@ -7140,43 +6939,41 @@ void tst_qqmlecmascript::revision()
QQmlComponent component(&engine, testFileUrl("metaobjectRevision.qml"));
QString url = component.url().toString();
- MyRevisionedClass *object = qobject_cast<MyRevisionedClass *>(component.create());
- QVERIFY(object != nullptr);
- delete object;
+ QScopedPointer<MyRevisionedClass> object(
+ qobject_cast<MyRevisionedClass *>(component.create()));
+ QVERIFY2(object, qPrintable(component.errorString()));
}
{
QQmlComponent component(&engine, testFileUrl("metaobjectRevision2.qml"));
QString url = component.url().toString();
- MyRevisionedClass *object = qobject_cast<MyRevisionedClass *>(component.create());
- QVERIFY(object != nullptr);
- delete object;
+ QScopedPointer<MyRevisionedClass> object(
+ qobject_cast<MyRevisionedClass *>(component.create()));
+ QVERIFY2(object, qPrintable(component.errorString()));
}
{
QQmlComponent component(&engine, testFileUrl("metaobjectRevision3.qml"));
QString url = component.url().toString();
- MyRevisionedClass *object = qobject_cast<MyRevisionedClass *>(component.create());
- QVERIFY(object != nullptr);
- delete object;
+ QScopedPointer<MyRevisionedClass> object(
+ qobject_cast<MyRevisionedClass *>(component.create()));
+ QVERIFY2(object, qPrintable(component.errorString()));
}
// Test that non-root classes can resolve revisioned methods
{
QQmlComponent component(&engine, testFileUrl("metaobjectRevision4.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toReal(), 11.);
- delete object;
}
{
QQmlComponent component(&engine, testFileUrl("metaobjectRevision5.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toReal(), 11.);
- delete object;
}
}
@@ -7184,13 +6981,15 @@ void tst_qqmlecmascript::realToInt()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("realToInt.qml"));
- QScopedPointer<MyQmlObject> object(qobject_cast<MyQmlObject*>(component.create()));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
- QMetaObject::invokeMethod(object.get(), "test1");
- QCOMPARE(object->value(), int(4));
- QMetaObject::invokeMethod(object.get(), "test2");
- QCOMPARE(object->value(), int(7));
+ QMetaObject::invokeMethod(object, "test1");
+ QCOMPARE(object->value(), 4);
+ QMetaObject::invokeMethod(object, "test2");
+ QCOMPARE(object->value(), 7);
}
void tst_qqmlecmascript::urlProperty()
@@ -7198,7 +6997,9 @@ void tst_qqmlecmascript::urlProperty()
QQmlEngine engine;
{
QQmlComponent component(&engine, testFileUrl("urlProperty.1.qml"));
- QScopedPointer<MyQmlObject> object(qobject_cast<MyQmlObject*>(component.create()));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
object->setStringProperty("http://qt-project.org");
QCOMPARE(object->urlProperty(), QUrl("http://qt-project.org/index.html"));
@@ -7213,7 +7014,9 @@ void tst_qqmlecmascript::urlPropertyWithEncoding()
QQmlEngine engine;
{
QQmlComponent component(&engine, testFileUrl("urlProperty.2.qml"));
- QScopedPointer<MyQmlObject> object(qobject_cast<MyQmlObject*>(component.create()));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
object->setStringProperty("http://qt-project.org");
const QUrl encoded = QUrl::fromEncoded("http://qt-project.org/?get%3cDATA%3e", QUrl::TolerantMode);
@@ -7228,8 +7031,8 @@ void tst_qqmlecmascript::urlListPropertyWithEncoding()
QQmlEngine engine;
{
QQmlComponent component(&engine, testFileUrl("urlListProperty.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
MySequenceConversionObject *msco1 = object->findChild<MySequenceConversionObject *>(QLatin1String("msco1"));
MySequenceConversionObject *msco2 = object->findChild<MySequenceConversionObject *>(QLatin1String("msco2"));
MySequenceConversionObject *msco3 = object->findChild<MySequenceConversionObject *>(QLatin1String("msco3"));
@@ -7240,7 +7043,6 @@ void tst_qqmlecmascript::urlListPropertyWithEncoding()
QCOMPARE(msco2->urlListProperty(), (QList<QUrl>() << encoded));
QCOMPARE(msco3->urlListProperty(), (QList<QUrl>() << encoded << encoded));
QCOMPARE(msco4->urlListProperty(), (QList<QUrl>() << encoded << encoded));
- delete object;
}
}
@@ -7249,7 +7051,7 @@ void tst_qqmlecmascript::dynamicString()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("dynamicString.qml"));
QScopedPointer<QObject> object(component.create());
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("stringProperty").toString(),
QString::fromLatin1("string:Hello World false:0 true:1 uint32:100 int32:-100 double:3.14159 date:2011-02-11 05::30:50!"));
}
@@ -7259,7 +7061,7 @@ void tst_qqmlecmascript::deleteLaterObjectMethodCall()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("deleteLaterObjectMethodCall.qml"));
QScopedPointer<QObject> object(component.create());
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
}
void tst_qqmlecmascript::automaticSemicolon()
@@ -7267,7 +7069,7 @@ void tst_qqmlecmascript::automaticSemicolon()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("automaticSemicolon.qml"));
QScopedPointer<QObject> object(component.create());
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
}
void tst_qqmlecmascript::compatibilitySemicolon()
@@ -7275,7 +7077,7 @@ void tst_qqmlecmascript::compatibilitySemicolon()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("compatibilitySemicolon.qml"));
QScopedPointer<QObject> object(component.create());
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
}
void tst_qqmlecmascript::incrDecrSemicolon1()
@@ -7283,7 +7085,7 @@ void tst_qqmlecmascript::incrDecrSemicolon1()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("incrDecrSemicolon1.qml"));
QScopedPointer<QObject> object(component.create());
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
}
void tst_qqmlecmascript::incrDecrSemicolon2()
@@ -7291,14 +7093,14 @@ void tst_qqmlecmascript::incrDecrSemicolon2()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("incrDecrSemicolon2.qml"));
QScopedPointer<QObject> object(component.create());
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
}
void tst_qqmlecmascript::incrDecrSemicolon_error1()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("incrDecrSemicolon_error1.qml"));
- QObject *object = component.create();
+ QScopedPointer<QObject> object(component.create());
QVERIFY(!object);
}
@@ -7307,7 +7109,7 @@ void tst_qqmlecmascript::unaryExpression()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("unaryExpression.qml"));
QScopedPointer<QObject> object(component.create());
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
}
// Makes sure that a binding isn't double re-evaluated when it depends on the same variable twice
@@ -7315,17 +7117,15 @@ void tst_qqmlecmascript::doubleEvaluate()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("doubleEvaluate.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- WriteCounter *wc = qobject_cast<WriteCounter *>(object);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
+ WriteCounter *wc = qobject_cast<WriteCounter *>(object.data());
QVERIFY(wc != nullptr);
QCOMPARE(wc->count(), 1);
wc->setProperty("x", 9);
QCOMPARE(wc->count(), 2);
-
- delete object;
}
void tst_qqmlecmascript::nonNotifyable()
@@ -7335,9 +7135,8 @@ void tst_qqmlecmascript::nonNotifyable()
QQmlTestMessageHandler messageHandler;
- QObject *object = component.create();
-
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QString expected1 = QLatin1String("QQmlExpression: Expression ") +
component.url().toString() +
@@ -7349,8 +7148,6 @@ void tst_qqmlecmascript::nonNotifyable()
QCOMPARE(messageHandler.messages().length(), 2);
QCOMPARE(messageHandler.messages().at(0), expected1);
QCOMPARE(messageHandler.messages().at(1), expected2);
-
- delete object;
}
void tst_qqmlecmascript::nonNotifyableConstant()
@@ -7362,7 +7159,7 @@ void tst_qqmlecmascript::nonNotifyableConstant()
// Shouldn't produce an error message about non-NOTIFYable properties,
// as the property has the CONSTANT attribute.
QScopedPointer<QObject> object(component.create());
- QVERIFY(object);
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(messageHandler.messages().size(), 0);
}
@@ -7370,10 +7167,10 @@ void tst_qqmlecmascript::forInLoop()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("forInLoop.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
- QMetaObject::invokeMethod(object, "listProperty");
+ QMetaObject::invokeMethod(object.data(), "listProperty");
QStringList r = object->property("listResult").toString().split("|", Qt::SkipEmptyParts);
QCOMPARE(r.size(), 3);
@@ -7381,9 +7178,7 @@ void tst_qqmlecmascript::forInLoop()
QCOMPARE(r[1],QLatin1String("1=obj2"));
QCOMPARE(r[2],QLatin1String("2=obj3"));
- //TODO: should test for in loop for other objects (such as QObjects) as well.
-
- delete object;
+ // TODO: should test for in loop for other objects (such as QObjects) as well.
}
// An object the binding depends on is deleted while the binding is still running
@@ -7391,9 +7186,8 @@ void tst_qqmlecmascript::deleteWhileBindingRunning()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("deleteWhileBindingRunning.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- delete object;
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
}
void tst_qqmlecmascript::qtbug_22679()
@@ -7407,10 +7201,9 @@ void tst_qqmlecmascript::qtbug_22679()
qRegisterMetaType<QList<QQmlError> >("QList<QQmlError>");
QSignalSpy warningsSpy(&engine, SIGNAL(warnings(QList<QQmlError>)));
- QObject *o = component.create();
- QVERIFY(o != nullptr);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(warningsSpy.count(), 0);
- delete o;
}
void tst_qqmlecmascript::qtbug_22843_data()
@@ -7446,7 +7239,9 @@ void tst_qqmlecmascript::switchStatement()
QQmlEngine engine;
{
QQmlComponent component(&engine, testFileUrl("switchStatement.1.qml"));
- QScopedPointer<MyQmlObject> object(qobject_cast<MyQmlObject*>(component.create()));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
// `object->value()' is the number of executed statements
@@ -7469,7 +7264,9 @@ void tst_qqmlecmascript::switchStatement()
{
QQmlComponent component(&engine, testFileUrl("switchStatement.2.qml"));
- QScopedPointer<MyQmlObject> object(qobject_cast<MyQmlObject*>(component.create()));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
// `object->value()' is the number of executed statements
@@ -7492,7 +7289,9 @@ void tst_qqmlecmascript::switchStatement()
{
QQmlComponent component(&engine, testFileUrl("switchStatement.3.qml"));
- QScopedPointer<MyQmlObject> object(qobject_cast<MyQmlObject*>(component.create()));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
// `object->value()' is the number of executed statements
@@ -7519,7 +7318,9 @@ void tst_qqmlecmascript::switchStatement()
QString warning = component.url().toString() + ":4:5: Unable to assign [undefined] to int";
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
- QScopedPointer<MyQmlObject> object(qobject_cast<MyQmlObject*>(component.create()));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
// `object->value()' is the number of executed statements
@@ -7543,7 +7344,9 @@ void tst_qqmlecmascript::switchStatement()
{
QQmlComponent component(&engine, testFileUrl("switchStatement.5.qml"));
- QScopedPointer<MyQmlObject> object(qobject_cast<MyQmlObject*>(component.create()));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
// `object->value()' is the number of executed statements
@@ -7566,7 +7369,9 @@ void tst_qqmlecmascript::switchStatement()
{
QQmlComponent component(&engine, testFileUrl("switchStatement.6.qml"));
- QScopedPointer<MyQmlObject> object(qobject_cast<MyQmlObject*>(component.create()));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
// `object->value()' is the number of executed statements
@@ -7594,7 +7399,9 @@ void tst_qqmlecmascript::withStatement()
{
QUrl url = testFileUrl("withStatement.1.qml");
QQmlComponent component(&engine, url);
- QScopedPointer<MyQmlObject> object(qobject_cast<MyQmlObject*>(component.create()));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->value(), 123);
@@ -7606,7 +7413,9 @@ void tst_qqmlecmascript::tryStatement()
QQmlEngine engine;
{
QQmlComponent component(&engine, testFileUrl("tryStatement.1.qml"));
- QScopedPointer<MyQmlObject> object(qobject_cast<MyQmlObject*>(component.create()));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->value(), 123);
@@ -7614,7 +7423,9 @@ void tst_qqmlecmascript::tryStatement()
{
QQmlComponent component(&engine, testFileUrl("tryStatement.2.qml"));
- QScopedPointer<MyQmlObject> object(qobject_cast<MyQmlObject*>(component.create()));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QCOMPARE(object->value(), 321);
@@ -7622,7 +7433,9 @@ void tst_qqmlecmascript::tryStatement()
{
QQmlComponent component(&engine, testFileUrl("tryStatement.3.qml"));
- QScopedPointer<MyQmlObject> object(qobject_cast<MyQmlObject*>(component.create()));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QVERIFY(object->qjsvalue().isUndefined());
@@ -7630,7 +7443,9 @@ void tst_qqmlecmascript::tryStatement()
{
QQmlComponent component(&engine, testFileUrl("tryStatement.4.qml"));
- QScopedPointer<MyQmlObject> object(qobject_cast<MyQmlObject*>(component.create()));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
QVERIFY(object != nullptr);
QVERIFY(object->qjsvalue().isUndefined());
@@ -7667,12 +7482,10 @@ void tst_qqmlecmascript::invokableWithQObjectDerived()
QQmlComponent component(&engine, testFileUrl("qobjectDerivedArgument.qml"));
- QObject *object = component.create();
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
- QVERIFY(object != nullptr);
QVERIFY(object->property("result").value<bool>());
-
- delete object;
}
}
@@ -7682,7 +7495,7 @@ void tst_qqmlecmascript::realTypePrecision()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("realTypePrecision.qml"));
QScopedPointer<QObject> object(component.create());
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("test").toDouble(), 1234567890.);
QCOMPARE(object->property("test2").toDouble(), 1234567890.);
QCOMPARE(object->property("test3").toDouble(), 1234567890.);
@@ -7696,6 +7509,7 @@ void tst_qqmlecmascript::registeredFlagMethod()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("registeredFlagMethod.qml"));
QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
MyQmlObject *object = qobject_cast<MyQmlObject *>(o.data());
QVERIFY(object != nullptr);
@@ -7709,22 +7523,20 @@ void tst_qqmlecmascript::replaceBinding()
{
QQmlEngine engine;
QQmlComponent c(&engine, testFileUrl("replaceBinding.qml"));
- QObject *obj = c.create();
- QVERIFY(obj != nullptr);
+ QScopedPointer<QObject> obj(c.create());
+ QVERIFY2(obj, qPrintable(c.errorString()));
QVERIFY(obj->property("success").toBool());
- delete obj;
}
void tst_qqmlecmascript::bindingBoundFunctions()
{
QQmlEngine engine;
QQmlComponent c(&engine, testFileUrl("bindingBoundFunctions.qml"));
- QObject *obj = c.create();
- QVERIFY(obj != nullptr);
+ QScopedPointer<QObject> obj(c.create());
+ QVERIFY2(obj, qPrintable(c.errorString()));
QVERIFY(obj->property("success").toBool());
- delete obj;
}
void tst_qqmlecmascript::qpropertyAndQtBinding()
@@ -7733,8 +7545,9 @@ void tst_qqmlecmascript::qpropertyAndQtBinding()
qmlRegisterType<QPropertyQtBindingTester>("test", 1, 0, "Tester");
QQmlComponent c(&engine, testFileUrl("qpropertyAndQtBinding.qml"));
QTest::ignoreMessage(QtMsgType::QtWarningMsg, QRegularExpression("Error: Failed to set binding on QPropertyQtBindingTester.*::readOnlyBindable."));
- QScopedPointer<QPropertyQtBindingTester> root(qobject_cast<QPropertyQtBindingTester *>(c.create()));
- QVERIFY(root);
+ QScopedPointer<QPropertyQtBindingTester> root(
+ qobject_cast<QPropertyQtBindingTester *>(c.create()));
+ QVERIFY2(root, qPrintable(c.errorString()));
QCOMPARE(root->nonBound(), 42);
bool ok = root->setProperty("i", 24);
QVERIFY(ok);
@@ -7750,21 +7563,19 @@ void tst_qqmlecmascript::deleteRootObjectInCreation()
QQmlEngine engine;
{
QQmlComponent c(&engine, testFileUrl("deleteRootObjectInCreation.qml"));
- QObject *obj = c.create();
- QVERIFY(obj != nullptr);
+ QScopedPointer<QObject> obj(c.create());
+ QVERIFY2(obj, qPrintable(c.errorString()));
QVERIFY(obj->property("rootIndestructible").toBool());
QVERIFY(!obj->property("childDestructible").toBool());
QTest::qWait(1);
QVERIFY(obj->property("childDestructible").toBool());
- delete obj;
}
{
QQmlComponent c(&engine, testFileUrl("deleteRootObjectInCreation.2.qml"));
- QObject *object = c.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(c.create());
+ QVERIFY2(object, qPrintable(c.errorString()));
QVERIFY(object->property("testConditionsMet").toBool());
- delete object;
}
}
@@ -7775,9 +7586,9 @@ void tst_qqmlecmascript::onDestruction()
// prior to engine destruction.
QQmlEngine engine;
QQmlComponent c(&engine, testFileUrl("onDestruction.qml"));
- QObject *obj = c.create();
- QVERIFY(obj != nullptr);
- delete obj;
+ QScopedPointer<QObject> obj(c.create());
+ QVERIFY2(obj, qPrintable(c.errorString()));
+ obj.reset();
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
}
@@ -7789,7 +7600,7 @@ void tst_qqmlecmascript::onDestruction()
QQmlEngine engine;
QQmlComponent c(&engine, testFileUrl("onDestruction.qml"));
QScopedPointer<QObject> obj(c.create());
- QVERIFY(obj != nullptr);
+ QVERIFY2(obj, qPrintable(c.errorString()));
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
}
}
@@ -7884,7 +7695,9 @@ void tst_qqmlecmascript::onDestructionViaGC()
weakRef->set(v4, v4->newObject());
QVERIFY(!weakRef->isNullOrUndefined());
- QPointer<WeakReferenceMutator> weakReferenceMutator = qobject_cast<WeakReferenceMutator *>(component.create());
+ // Deliberately leaked because gc should pick it up:
+ QPointer<WeakReferenceMutator> weakReferenceMutator(
+ qobject_cast<WeakReferenceMutator *>(component.create()));
QVERIFY2(!weakReferenceMutator.isNull(), qPrintable(component.errorString()));
weakReferenceMutator->init(v4, weakRef.data(), &mutatorResult);
@@ -7919,9 +7732,9 @@ void tst_qqmlecmascript::bindingSuppression()
QQmlTestMessageHandler messageHandler;
QQmlComponent c(&engine, testFileUrl("bindingSuppression.qml"));
- QObject *obj = c.create();
- QVERIFY(obj != nullptr);
- delete obj;
+ QScopedPointer<QObject> obj(c.create());
+ QVERIFY2(obj, qPrintable(c.errorString()));
+ obj.reset();
QVERIFY2(messageHandler.messages().isEmpty(), qPrintable(messageHandler.messageString()));
}
@@ -7932,33 +7745,30 @@ void tst_qqmlecmascript::signalEmitted()
// calling destroy on the sibling.
QQmlEngine engine;
QQmlComponent c(&engine, testFileUrl("signalEmitted.2.qml"));
- QObject *obj = c.create();
- QVERIFY(obj != nullptr);
+ QScopedPointer<QObject> obj(c.create());
+ QVERIFY2(obj, qPrintable(c.errorString()));
QTRY_VERIFY(obj->property("success").toBool());
- delete obj;
}
{
// allowing gc to clean up the sibling.
QQmlEngine engine;
QQmlComponent c(&engine, testFileUrl("signalEmitted.3.qml"));
- QObject *obj = c.create();
- QVERIFY(obj != nullptr);
+ QScopedPointer<QObject> obj(c.create());
+ QVERIFY2(obj, qPrintable(c.errorString()));
gc(engine); // should collect c1.
QTRY_VERIFY(obj->property("success").toBool());
- delete obj;
}
{
// allowing gc to clean up the sibling after manually destroying target.
QQmlEngine engine;
QQmlComponent c(&engine, testFileUrl("signalEmitted.4.qml"));
- QObject *obj = c.create();
- QVERIFY(obj != nullptr);
+ QScopedPointer<QObject> obj(c.create());
+ QVERIFY2(obj, qPrintable(c.errorString()));
gc(engine); // should collect c1.
- QMetaObject::invokeMethod(obj, "destroyC2");
+ QMetaObject::invokeMethod(obj.data(), "destroyC2");
QTRY_VERIFY(obj->property("success").toBool()); // handles events (incl. delete later).
- delete obj;
}
}
@@ -7969,13 +7779,13 @@ void tst_qqmlecmascript::threadSignal()
{
QQmlComponent c(&engine, testFileUrl("threadSignal.qml"));
QScopedPointer<QObject> object(c.create());
- QVERIFY(!object.isNull());
+ QVERIFY2(object, qPrintable(c.errorString()));
QTRY_VERIFY(object->property("passed").toBool());
}
{
QQmlComponent c(&engine, testFileUrl("threadSignal.2.qml"));
QScopedPointer<QObject> object(c.create());
- QVERIFY(!object.isNull());
+ QVERIFY2(object, qPrintable(c.errorString()));
QMetaObject::invokeMethod(object.data(), "doIt");
QTRY_VERIFY(object->property("passed").toBool());
}
@@ -7988,8 +7798,8 @@ void tst_qqmlecmascript::qqmldataDestroyed()
// gc cleans up a qobject, later the qqmldata destroyed handler will run.
{
QQmlComponent c(&engine, testFileUrl("qqmldataDestroyed.qml"));
- QObject *object = c.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(c.create());
+ QVERIFY2(object, qPrintable(c.errorString()));
// now gc causing the collection of the dynamically constructed object.
engine.collectGarbage();
engine.collectGarbage();
@@ -7997,21 +7807,21 @@ void tst_qqmlecmascript::qqmldataDestroyed()
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
QCoreApplication::processEvents();
// shouldn't crash.
- delete object;
+ object.reset();
}
// in this case, the object has CPP ownership, and the gc will
// be triggered during its beginCreate stage.
{
QQmlComponent c(&engine, testFileUrl("qqmldataDestroyed.2.qml"));
- QObject *object = c.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(c.create());
+ QVERIFY2(object, qPrintable(c.errorString()));
QVERIFY(object->property("testConditionsMet").toBool());
// the gc() within the handler will have triggered the weak
// qobject reference callback. If that incorrectly disposes
// the handle, when the qqmldata::destroyed() handler is
// called due to object deletion we will see a crash.
- delete object;
+ object.reset();
// shouldn't have crashed.
}
}
@@ -8020,10 +7830,9 @@ void tst_qqmlecmascript::secondAlias()
{
QQmlEngine engine;
QQmlComponent c(&engine, testFileUrl("secondAlias.qml"));
- QObject *object = c.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(c.create());
+ QVERIFY2(object, qPrintable(c.errorString()));
QCOMPARE(object->property("test").toInt(), 200);
- delete object;
}
// An alias to a var property works
@@ -8031,10 +7840,9 @@ void tst_qqmlecmascript::varAlias()
{
QQmlEngine engine;
QQmlComponent c(&engine, testFileUrl("varAlias.qml"));
- QObject *object = c.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(c.create());
+ QVERIFY2(object, qPrintable(c.errorString()));
QCOMPARE(object->property("test").toInt(), 192);
- delete object;
}
// Used to trigger an assert in the lazy meta object creation stage
@@ -8042,10 +7850,9 @@ void tst_qqmlecmascript::overrideDataAssert()
{
QQmlEngine engine;
QQmlComponent c(&engine, testFileUrl("overrideDataAssert.qml"));
- QObject *object = c.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(c.create());
+ QVERIFY2(object, qPrintable(c.errorString()));
object->metaObject();
- delete object;
}
void tst_qqmlecmascript::fallbackBindings_data()
@@ -8069,7 +7876,7 @@ void tst_qqmlecmascript::fallbackBindings()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl(source));
QScopedPointer<QObject> object(component.create());
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("success").toBool(), true);
}
@@ -8079,7 +7886,7 @@ void tst_qqmlecmascript::propertyOverride()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("propertyOverride.qml"));
QScopedPointer<QObject> object(component.create());
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("success").toBool(), true);
}
@@ -8115,16 +7922,13 @@ void tst_qqmlecmascript::sequenceSort()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("sequenceSort.qml"));
- QObject *object = component.create();
- if (object == nullptr)
- qDebug() << component.errorString();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QVariant q;
- QMetaObject::invokeMethod(object, function.toLatin1().constData(), Q_RETURN_ARG(QVariant, q), Q_ARG(QVariant, useComparer));
+ QMetaObject::invokeMethod(object.data(), function.toLatin1().constData(),
+ Q_RETURN_ARG(QVariant, q), Q_ARG(QVariant, useComparer));
QVERIFY(q.toBool());
-
- delete object;
}
void tst_qqmlecmascript::dateParse()
@@ -8133,9 +7937,7 @@ void tst_qqmlecmascript::dateParse()
QQmlComponent component(&engine, testFileUrl("date.qml"));
QScopedPointer<QObject> object(component.create());
- if (object == nullptr)
- qDebug() << component.errorString();
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
QVariant q;
QMetaObject::invokeMethod(object.get(), "test_is_invalid_jsDateTime", Q_RETURN_ARG(QVariant, q));
@@ -8154,9 +7956,7 @@ void tst_qqmlecmascript::utcDate()
QQmlComponent component(&engine, testFileUrl("utcdate.qml"));
QScopedPointer<QObject> object(component.create());
- if (object == nullptr)
- qDebug() << component.errorString();
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
QVariant q;
QVariant val = QString::fromLatin1("2014-07-16T23:30:31");
@@ -8170,9 +7970,7 @@ void tst_qqmlecmascript::negativeYear()
QQmlComponent component(&engine, testFileUrl("negativeyear.qml"));
QScopedPointer<QObject> object(component.create());
- if (object == nullptr)
- qDebug() << component.errorString();
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
QVariant q;
QMetaObject::invokeMethod(object.get(), "check_negative_tostring", Q_RETURN_ARG(QVariant, q));
@@ -8190,15 +7988,14 @@ void tst_qqmlecmascript::concatenatedStringPropertyAccess()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("concatenatedStringPropertyAccess.qml"));
- QObject *object = component.create();
- QVERIFY(object);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QVERIFY(object->property("success").toBool());
- delete object;
}
void tst_qqmlecmascript::jsOwnedObjectsDeletedOnEngineDestroy()
{
- QQmlEngine *myEngine = new QQmlEngine;
+ QScopedPointer<QQmlEngine>myEngine(new QQmlEngine);
MyDeleteObject deleteObject;
deleteObject.setObjectName("deleteObject");
@@ -8214,19 +8011,19 @@ void tst_qqmlecmascript::jsOwnedObjectsDeletedOnEngineDestroy()
QQmlEngine::setObjectOwnership(object2, QQmlEngine::JavaScriptOwnership);
myEngine->rootContext()->setContextProperty("deleteObject", &deleteObject);
- QQmlComponent component(myEngine, testFileUrl("jsOwnedObjectsDeletedOnEngineDestroy.qml"));
- QObject *object = component.create();
- QVERIFY(object);
+ QQmlComponent component(myEngine.data(),
+ testFileUrl("jsOwnedObjectsDeletedOnEngineDestroy.qml"));
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
// Destroying the engine should delete all JS owned QObjects
QSignalSpy spy1(object1, SIGNAL(destroyed()));
QSignalSpy spy2(object2, SIGNAL(destroyed()));
- delete myEngine;
+ myEngine.reset();
QCOMPARE(spy1.count(), 1);
QCOMPARE(spy2.count(), 1);
deleteObject.deleteNestedObject();
- delete object;
}
void tst_qqmlecmascript::updateCall()
@@ -8238,7 +8035,7 @@ void tst_qqmlecmascript::updateCall()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl(file));
QScopedPointer<QObject> object(component.create());
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
}
void tst_qqmlecmascript::numberParsing()
@@ -8249,7 +8046,7 @@ void tst_qqmlecmascript::numberParsing()
file = file.arg(i);
QQmlComponent component(&engine, testFileUrl(file));
QScopedPointer<QObject> object(component.create());
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
}
for (int i = 1; i < 3; ++i) {
QString file("numberParsing_error.%1.qml");
@@ -8266,7 +8063,7 @@ void tst_qqmlecmascript::stringParsing()
QString file("stringParsing_error.%1.qml");
file = file.arg(i);
QQmlComponent component(&engine, testFileUrl(file));
- QObject *object = component.create();
+ QScopedPointer<QObject> object(component.create());
QVERIFY(!object);
}
}
@@ -8289,7 +8086,7 @@ void tst_qqmlecmascript::qtbug_32801()
QQmlComponent component(&engine, testFileUrl("qtbug_32801.qml"));
QScopedPointer<QObject> obj(component.create());
- QVERIFY(obj != nullptr);
+ QVERIFY2(obj, qPrintable(component.errorString()));
// do not crash when a QML signal is connected to a non-void slot
connect(obj.data(), SIGNAL(testSignal(QString)), obj.data(), SLOT(slotWithReturnValue(QString)));
@@ -8300,10 +8097,9 @@ void tst_qqmlecmascript::thisObject()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("thisObject.qml"));
- QObject *object = component.create();
- QVERIFY(object);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(qvariant_cast<QObject*>(object->property("subObject"))->property("test").toInt(), 2);
- delete object;
}
void tst_qqmlecmascript::qtbug_33754()
@@ -8312,7 +8108,7 @@ void tst_qqmlecmascript::qtbug_33754()
QQmlComponent component(&engine, testFileUrl("qtbug_33754.qml"));
QScopedPointer<QObject> obj(component.create());
- QVERIFY(obj != nullptr);
+ QVERIFY2(obj, qPrintable(component.errorString()));
}
void tst_qqmlecmascript::qtbug_34493()
@@ -8321,10 +8117,10 @@ void tst_qqmlecmascript::qtbug_34493()
QQmlComponent component(&engine, testFileUrl("qtbug_34493.qml"));
QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
if (component.errors().size())
qDebug() << component.errors();
QVERIFY(component.errors().isEmpty());
- QVERIFY(obj != nullptr);
QVERIFY(QMetaObject::invokeMethod(obj.data(), "doIt"));
QTRY_VERIFY(obj->property("prop").toString() == QLatin1String("Hello World!"));
}
@@ -8336,10 +8132,10 @@ void tst_qqmlecmascript::singletonFromQMLToCpp()
QQmlEngine engine;
QQmlComponent component(&engine, testFile("singletonTest.qml"));
QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
if (component.errors().size())
qDebug() << component.errors();
QVERIFY(component.errors().isEmpty());
- QVERIFY(obj != nullptr);
QCOMPARE(obj->property("qobjectTest"), QVariant(true));
QCOMPARE(obj->property("myQmlObjectTest"), QVariant(true));
@@ -8354,10 +8150,10 @@ void tst_qqmlecmascript::singletonFromQMLAndBackAndCompare()
QQmlEngine engine;
QQmlComponent component(&engine, testFile("singletonTest2.qml"));
QScopedPointer<QObject> o(component.create());
+ QVERIFY2(o, qPrintable(component.errorString()));
if (component.errors().size())
qDebug() << component.errors();
QVERIFY(component.errors().isEmpty());
- QVERIFY(o != nullptr);
QCOMPARE(o->property("myInheritedQmlObjectTest1"), QVariant(true));
QCOMPARE(o->property("myInheritedQmlObjectTest2"), QVariant(true));
@@ -8381,18 +8177,16 @@ void tst_qqmlecmascript::setPropertyOnInvalid()
QQmlComponent component(&engine, testFileUrl("setPropertyOnNull.qml"));
QString warning = component.url().toString() + ":4: TypeError: Value is null and could not be converted to an object";
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
- QObject *object = component.create();
- QVERIFY(object);
- delete object;
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
}
{
QQmlComponent component(&engine, testFileUrl("setPropertyOnUndefined.qml"));
QString warning = component.url().toString() + ":4: TypeError: Value is undefined and could not be converted to an object";
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
- QObject *object = component.create();
- QVERIFY(object);
- delete object;
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
}
}
@@ -8401,22 +8195,22 @@ void tst_qqmlecmascript::miscTypeTest()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("misctypetest.qml"));
- QObject *object = component.create();
- if (object == nullptr)
- qDebug() << component.errorString();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
QVariant q;
- QMetaObject::invokeMethod(object, "test_invalid_url_equal", Q_RETURN_ARG(QVariant, q));
+ QMetaObject::invokeMethod(object.data(),
+ "test_invalid_url_equal", Q_RETURN_ARG(QVariant, q));
QVERIFY(q.toBool());
- QMetaObject::invokeMethod(object, "test_invalid_url_strictequal", Q_RETURN_ARG(QVariant, q));
+ QMetaObject::invokeMethod(object.data(),
+ "test_invalid_url_strictequal", Q_RETURN_ARG(QVariant, q));
QVERIFY(q.toBool());
- QMetaObject::invokeMethod(object, "test_valid_url_equal", Q_RETURN_ARG(QVariant, q));
+ QMetaObject::invokeMethod(object.data(),
+ "test_valid_url_equal", Q_RETURN_ARG(QVariant, q));
QVERIFY(q.toBool());
- QMetaObject::invokeMethod(object, "test_valid_url_strictequal", Q_RETURN_ARG(QVariant, q));
+ QMetaObject::invokeMethod(object.data(),
+ "test_valid_url_strictequal", Q_RETURN_ARG(QVariant, q));
QVERIFY(q.toBool());
-
- delete object;
}
void tst_qqmlecmascript::stackLimits()
@@ -8440,11 +8234,8 @@ void tst_qqmlecmascript::qtbug_34792()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("qtbug34792.qml"));
- QObject *object = component.create();
- if (object == nullptr)
- qDebug() << component.errorString();
- QVERIFY(object != nullptr);
- delete object;
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object, qPrintable(component.errorString()));
}
void tst_qqmlecmascript::noCaptureWhenWritingProperty()
@@ -8452,7 +8243,7 @@ void tst_qqmlecmascript::noCaptureWhenWritingProperty()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("noCaptureWhenWritingProperty.qml"));
QScopedPointer<QObject> obj(component.create());
- QVERIFY(!obj.isNull());
+ QVERIFY2(obj, qPrintable(component.errorString()));
QCOMPARE(obj->property("somePropertyEvaluated").toBool(), false);
}
@@ -8461,9 +8252,7 @@ void tst_qqmlecmascript::singletonWithEnum()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("singletontype/singletonWithEnum.qml"));
QScopedPointer<QObject> obj(component.create());
- if (obj.isNull())
- qDebug() << component.errors().first().toString();
- QVERIFY(!obj.isNull());
+ QVERIFY2(obj, qPrintable(component.errorString()));
QVariant prop = obj->property("testValue");
QCOMPARE(prop.typeId(), QMetaType::Int);
QCOMPARE(prop.toInt(), int(SingletonWithEnum::TestValue));
@@ -8483,9 +8272,7 @@ void tst_qqmlecmascript::lazyBindingEvaluation()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("lazyBindingEvaluation.qml"));
QScopedPointer<QObject> obj(component.create());
- if (obj.isNull())
- qDebug() << component.errors().first().toString();
- QVERIFY(!obj.isNull());
+ QVERIFY2(obj, qPrintable(component.errorString()));
QVariant prop = obj->property("arrayLength");
QCOMPARE(prop.typeId(), QMetaType::Int);
QCOMPARE(prop.toInt(), 2);
@@ -8496,9 +8283,7 @@ void tst_qqmlecmascript::varPropertyAccessOnObjectWithInvalidContext()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("varPropertyAccessOnObjectWithInvalidContext.qml"));
QScopedPointer<QObject> obj(component.create());
- if (obj.isNull())
- qDebug() << component.errors().first().toString();
- QVERIFY(!obj.isNull());
+ QVERIFY2(obj, qPrintable(component.errorString()));
QVERIFY(obj->property("success").toBool());
}
@@ -8509,9 +8294,7 @@ void tst_qqmlecmascript::importedScriptsAccessOnObjectWithInvalidContext()
QTest::ignoreMessage(QtWarningMsg, qPrintable(url.toString() + ":29: TypeError: Cannot read property 'Foo' of null"));
QQmlComponent component(&engine, url);
QScopedPointer<QObject> obj(component.create());
- if (obj.isNull())
- qDebug() << component.errors().first().toString();
- QVERIFY(!obj.isNull());
+ QVERIFY2(obj, qPrintable(component.errorString()));
QTRY_VERIFY(obj->property("success").toBool());
}
@@ -8520,9 +8303,7 @@ void tst_qqmlecmascript::importedScriptsWithoutQmlMode()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("importScriptsWithoutQmlMode.qml"));
QScopedPointer<QObject> obj(component.create());
- if (obj.isNull())
- qDebug() << component.errors().first().toString();
- QVERIFY(!obj.isNull());
+ QVERIFY2(obj, qPrintable(component.errorString()));
QTRY_VERIFY(obj->property("success").toBool());
}
@@ -8531,9 +8312,7 @@ void tst_qqmlecmascript::contextObjectOnLazyBindings()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("contextObjectOnLazyBindings.qml"));
QScopedPointer<QObject> obj(component.create());
- if (obj.isNull())
- qDebug() << component.errors().first().toString();
- QVERIFY(!obj.isNull());
+ QVERIFY2(obj, qPrintable(component.errorString()));
QObject *subObject = qvariant_cast<QObject*>(obj->property("subObject"));
QVERIFY(subObject);
QCOMPARE(subObject->property("testValue").toInt(), int(42));
@@ -8554,7 +8333,7 @@ void tst_qqmlecmascript::garbageCollectionDuringCreation()
QUrl());
QScopedPointer<QObject> object(component.create());
- QVERIFY(!object.isNull());
+ QVERIFY2(object, qPrintable(component.errorString()));
QObjectContainer *container = qobject_cast<QObjectContainer*>(object.data());
QCOMPARE(container->dataChildren.count(), 1);
@@ -8586,7 +8365,7 @@ void tst_qqmlecmascript::qtbug_39520()
QUrl());
QScopedPointer<QObject> object(component.create());
- QVERIFY(!object.isNull());
+ QVERIFY2(object, qPrintable(component.errorString()));
QString s = object->property("s").toString();
QCOMPARE(s.count('\n'), 1 * 1000 * 1000);
@@ -8648,7 +8427,7 @@ void tst_qqmlecmascript::readUnregisteredQObjectProperty()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("accessUnregisteredQObjectProperty.qml"));
QScopedPointer<QObject> root(component.create());
- QVERIFY(root);
+ QVERIFY2(root, qPrintable(component.errorString()));
QMetaObject::invokeMethod(root.get(), "readProperty");
QCOMPARE(root->property("container").value<ObjectContainer*>()->mGetterCalled, true);
@@ -8660,7 +8439,7 @@ void tst_qqmlecmascript::writeUnregisteredQObjectProperty()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("accessUnregisteredQObjectProperty.qml"));
QScopedPointer<QObject> root(component.create());
- QVERIFY(root);
+ QVERIFY2(root, qPrintable(component.errorString()));
QMetaObject::invokeMethod(root.get(), "writeProperty");
QCOMPARE(root->property("container").value<ObjectContainer*>()->mSetterCalled, true);
@@ -8695,7 +8474,7 @@ void tst_qqmlecmascript::qtbug_46022()
QQmlComponent component(&engine, testFileUrl("qtbug_46022.qml"));
QScopedPointer<QObject> obj(component.create());
- QVERIFY(obj != nullptr);
+ QVERIFY2(obj, qPrintable(component.errorString()));
QCOMPARE(obj->property("test1").toBool(), true);
QCOMPARE(obj->property("test2").toBool(), true);
}
@@ -8705,7 +8484,7 @@ void tst_qqmlecmascript::qtbug_52340()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("qtbug_52340.qml"));
QScopedPointer<QObject> object(component.create());
- QVERIFY(!object.isNull());
+ QVERIFY2(object, qPrintable(component.errorString()));
QVariant returnValue;
QVERIFY(QMetaObject::invokeMethod(object.data(), "testCall", Q_RETURN_ARG(QVariant, returnValue)));
QVERIFY(returnValue.isValid());
@@ -8718,7 +8497,7 @@ void tst_qqmlecmascript::qtbug_54589()
QQmlComponent component(&engine, testFileUrl("qtbug_54589.qml"));
QScopedPointer<QObject> obj(component.create());
- QVERIFY(obj != nullptr);
+ QVERIFY2(obj, qPrintable(component.errorString()));
QCOMPARE(obj->property("result").toBool(), true);
}
@@ -8735,7 +8514,7 @@ void tst_qqmlecmascript::stringify_qtbug_50592()
QQmlComponent component(&engine, testFileUrl("stringify_qtbug_50592.qml"));
QScopedPointer<QObject> obj(component.create());
- QVERIFY(obj != nullptr);
+ QVERIFY2(obj, qPrintable(component.errorString()));
QCOMPARE(obj->property("source").toString(),
QString::fromLatin1("\"http://example.org/some_nonexistant_image.png\""));
}
@@ -8924,7 +8703,7 @@ void tst_qqmlecmascript::singleBlockLoops()
QQmlComponent component(&engine, testFileUrl("qtbug_59012.qml"));
QScopedPointer<QObject> obj(component.create());
- QVERIFY(obj != nullptr);
+ QVERIFY2(obj, qPrintable(component.errorString()));
QVERIFY(!component.isError());
}
@@ -8935,7 +8714,7 @@ void tst_qqmlecmascript::qtbug_60547()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("qtbug60547/main.qml"));
QScopedPointer<QObject> object(component.create());
- QVERIFY2(!object.isNull(), qPrintable(component.errorString()));
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("counter"), QVariant(int(1)));
}
@@ -8944,7 +8723,7 @@ void tst_qqmlecmascript::anotherNaN()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("nans.qml"));
QScopedPointer<QObject> object(component.create());
- QVERIFY2(!object.isNull(), qPrintable(component.errorString()));
+ QVERIFY2(object, qPrintable(component.errorString()));
object->setProperty("prop", std::numeric_limits<double>::quiet_NaN()); // don't crash
std::uint64_t anotherNaN = 0xFFFFFF01000000F7ul;
@@ -9052,7 +8831,7 @@ void tst_qqmlecmascript::removeBindingsWithNoDependencies()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("removeBindingsWithNoDependencies.qml"));
QScopedPointer<QObject> object(component.create());
- QVERIFY(!object.isNull());
+ QVERIFY2(object, qPrintable(component.errorString()));
QVariant rect = object->property("placement");
QCOMPARE(rect.toRectF(), QRectF(0, 0, 100, 100));
const QMetaObject *metaObject = object->metaObject();
@@ -9089,7 +8868,7 @@ void tst_qqmlecmascript::preserveBindingWithUnresolvedNames()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("preserveBindingWithUnresolvedNames.qml"));
QScopedPointer<QObject> object(component.create());
- QVERIFY(!object.isNull());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("testTypeOf").toString(), QString("undefined"));
QObject obj;
engine.rootContext()->setContextProperty("contextProp", &obj);
@@ -9133,7 +8912,7 @@ void tst_qqmlecmascript::importLexicalVariables()
QQmlEngine engine;
QQmlComponent component(&engine, testFile);
QScopedPointer<QObject> object(component.create());
- QVERIFY(object != nullptr);
+ QVERIFY2(object, qPrintable(component.errorString()));
QVERIFY(!component.isError());
QVariant result;
@@ -9239,7 +9018,7 @@ void tst_qqmlecmascript::intMinDividedByMinusOne()
"}"), QUrl());
QVERIFY(component.isReady());
QScopedPointer<QObject> object(component.create());
- QVERIFY(!object.isNull());
+ QVERIFY2(object, qPrintable(component.errorString()));
QCOMPARE(object->property("doesNotFitInInt").toUInt(), 2147483648u);
}
@@ -9249,7 +9028,7 @@ void tst_qqmlecmascript::undefinedPropertiesInObjectWrapper()
QQmlComponent component(&engine, testFile("undefinedPropertiesInObjectWrapper.qml"));
QVERIFY(component.isReady());
QScopedPointer<QObject> object(component.create());
- QVERIFY(!object.isNull());
+ QVERIFY2(object, qPrintable(component.errorString()));
}
void tst_qqmlecmascript::qpropertyBindingHandlesUndefinedCorrectly_data()
@@ -9375,7 +9154,7 @@ void tst_qqmlecmascript::singletonTypeWrapperLookup()
QQmlComponent component(&engine, testFileUrl("SingletonLookupTest.qml"));
QScopedPointer<QObject> test(component.create());
- QVERIFY2(!test.isNull(), qPrintable(component.errorString()));
+ QVERIFY2(test, qPrintable(component.errorString()));
auto singleton1 = engine.singletonInstance<CppSingleton1*>(singletonTypeId1);
QVERIFY(singleton1);
@@ -9393,7 +9172,7 @@ void tst_qqmlecmascript::getThisObject()
QQmlComponent component(&engine, testFileUrl("getThis.qml"));
QVERIFY(component.isReady());
QScopedPointer<QObject> test(component.create());
- QVERIFY(!test.isNull());
+ QVERIFY2(test, qPrintable(component.errorString()));
QTRY_COMPARE(qvariant_cast<QObject *>(test->property("self")), test.data());
}
@@ -9405,7 +9184,7 @@ void tst_qqmlecmascript::semicolonAfterProperty()
QQmlComponent component(&engine, testFileUrl("semicolonAfterProperty.qml"));
QVERIFY(component.isReady());
QScopedPointer<QObject> test(component.create());
- QVERIFY(!test.isNull());
+ QVERIFY2(test, qPrintable(component.errorString()));
}
void tst_qqmlecmascript::hugeStack()
@@ -9414,7 +9193,7 @@ void tst_qqmlecmascript::hugeStack()
QQmlComponent component(&engine, testFileUrl("hugeStack.qml"));
QVERIFY(component.isReady());
QScopedPointer<QObject> test(component.create());
- QVERIFY(!test.isNull());
+ QVERIFY2(test, qPrintable(component.errorString()));
QVariant huge = test->property("longList");
QCOMPARE(qvariant_cast<QJSValue>(huge).property(QLatin1String("length")).toInt(), 33059);
@@ -9473,6 +9252,7 @@ void tst_qqmlecmascript::bindingOnQProperty()
QQmlComponent component(&engine, testFileUrl("bindingOnQProperty.qml"));
QVERIFY2(component.isReady(), qPrintable(component.errorString()));
QScopedPointer<QObject> test(component.create());
+ QVERIFY2(test, qPrintable(component.errorString()));
test->setProperty("externalValue", 42);
QCOMPARE(test->property("value").toInt(), 42);
QCOMPARE(test->property("changeHandlerCount").toInt(), 1);
@@ -9491,6 +9271,7 @@ void tst_qqmlecmascript::overwrittenBindingOnQProperty()
QQmlComponent component(&engine, testFileUrl("QPropertyOverwrite.qml"));
QVERIFY2(component.isReady(), qPrintable(component.errorString()));
QScopedPointer<QObject> root(component.create());
+ QVERIFY2(root, qPrintable(component.errorString()));
auto test = root->findChild<ClassWithQProperty *>("test");
QVERIFY(test);
QCOMPARE(test->value.value(), 13.f);
@@ -9503,6 +9284,7 @@ void tst_qqmlecmascript::aliasOfQProperty() {
QQmlComponent component(&engine, testFileUrl("aliasOfQProperty.qml"));
QVERIFY2(component.isReady(), qPrintable(component.errorString()));
QScopedPointer<QObject> root(component.create());
+ QVERIFY2(root, qPrintable(component.errorString()));
QProperty<float> &qprop = static_cast<ClassWithQProperty*>(root.data())->value;
QProperty<float> otherProperty;
@@ -9537,14 +9319,16 @@ void tst_qqmlecmascript::aliasOfQProperty() {
void tst_qqmlecmascript::bindingOnQPropertyContextProperty()
{
QSKIP("Test needs to be adjusted");
- // QQmlEngine engine;
- // QQmlComponent component(&engine, testFileUrl("bindingOnQPropertyContextProperty.qml"));
- // QVERIFY2(component.isReady(), qPrintable(component.errorString()));
- // QScopedPointer<QObject> test(component.create());
- // QVERIFY(!test.isNull());
- // auto classWithQProperty = test->property("testee").value<ClassWithQProperty2 *>();
- // QVERIFY(classWithQProperty);
- // QCOMPARE(classWithQProperty->value.value(), 2);
+#if 0
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("bindingOnQPropertyContextProperty.qml"));
+ QVERIFY2(component.isReady(), qPrintable(component.errorString()));
+ QScopedPointer<QObject> test(component.create());
+ QVERIFY2(test, qPrintable(component.errorString()));
+ auto classWithQProperty = test->property("testee").value<ClassWithQProperty2 *>();
+ QVERIFY(classWithQProperty);
+ QCOMPARE(classWithQProperty->value.value(), 2);
+#endif
}
void tst_qqmlecmascript::bindingContainingQProperty()
@@ -9553,7 +9337,7 @@ void tst_qqmlecmascript::bindingContainingQProperty()
QQmlComponent component(&engine, testFileUrl("bindingContainingQProperty.qml"));
QVERIFY2(component.isReady(), qPrintable(component.errorString()));
QScopedPointer<QObject> test(component.create());
- QVERIFY(!test.isNull());
+ QVERIFY2(test, qPrintable(component.errorString()));
test->setProperty("value", 42.0);
QCOMPARE(test->property("expected"), 42.0);
}
@@ -9811,7 +9595,7 @@ void tst_qqmlecmascript::variantConversionMethod()
QQmlComponent component(&qmlengine, testFileUrl("variantConvert.qml"));
QScopedPointer<QObject> o(component.create());
- QVERIFY(o != nullptr);
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(obj.funcCalled, QLatin1String("QModelIndex"));
}
@@ -9824,7 +9608,7 @@ void tst_qqmlecmascript::sequenceConversionMethod()
QQmlComponent component(&qmlengine, testFileUrl("sequenceConvert.qml"));
QScopedPointer<QObject> o(component.create());
- QVERIFY(o != nullptr);
+ QVERIFY2(o, qPrintable(component.errorString()));
QCOMPARE(obj.funcCalled, QLatin1String("stringlist"));
}
@@ -9833,7 +9617,7 @@ void tst_qqmlecmascript::proxyIteration()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("proxyIteration.qml"));
QScopedPointer<QObject> root(component.create());
- QVERIFY2(root != nullptr, qPrintable(component.errorString()));
+ QVERIFY2(root, qPrintable(component.errorString()));
QCOMPARE(root->property("sum").toInt(), 6);
}
@@ -9883,6 +9667,7 @@ void tst_qqmlecmascript::frozenQObject()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("frozenQObject.qml"));
QScopedPointer<QObject> root(component.create());
+ QVERIFY2(root, qPrintable(component.errorString()));
QVERIFY(root->property("caughtException").toBool());
QVERIFY(root->property("nameCorrect").toBool());
}
@@ -9904,6 +9689,7 @@ void tst_qqmlecmascript::constPointer()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("constPointer.qml"));
QScopedPointer<QObject> root(component.create());
+ QVERIFY2(root, qPrintable(component.errorString()));
QVERIFY(root->property("invokableOk").toBool());
QVERIFY(root->property("propertyOk").toBool());
}