aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlincubator
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2020-06-09 11:24:55 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2020-06-09 18:43:55 +0200
commit84b53c165e9d492a547c04499450007d2c293bc8 (patch)
treeb60b91d4253e564395ffa802ec96d3d17b8bbb45 /tests/auto/qml/qqmlincubator
parent052bfad934352f08d75665d8c154bd665f452616 (diff)
tst_qqmlincubator: Reduce memory leaks
This patch fixes memory leaks caused by the test itself. There are still memory leakes left in deleteSelf and requiredProperties; the latter might indicate an actual issue when the incubator fails due to required properties missing; this should be fixed (in another commit). deleteSelf is rather weird, and requires more investigation. Change-Id: I53f1da608c4bf6095d39fd573c6eeefcc9219c7c Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlincubator')
-rw-r--r--tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp b/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp
index 6c5416c784..1650a3a1d6 100644
--- a/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp
+++ b/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp
@@ -473,6 +473,13 @@ class Switcher : public QObject
Q_OBJECT
public:
Switcher(QQmlEngine *e) : QObject(), engine(e) { }
+ ~Switcher()
+ {
+ if (component)
+ component->deleteLater();
+ if (incubator && incubator->object())
+ incubator->object()->deleteLater();
+ }
struct MyIncubator : public QQmlIncubator
{
@@ -489,13 +496,13 @@ public:
void start()
{
- incubator = new MyIncubator(QQmlIncubator::Synchronous, this);
+ incubator.reset(new MyIncubator(QQmlIncubator::Synchronous, this));
component = new QQmlComponent(engine, QQmlDataTest::instance()->testFileUrl("recursiveClear.1.qml"));
component->create(*incubator);
}
QQmlEngine *engine;
- MyIncubator *incubator;
+ QScopedPointer<MyIncubator> incubator;
QQmlComponent *component;
public slots:
@@ -594,18 +601,17 @@ void tst_qqmlincubator::asynchronousIfNested()
QQmlComponent component(&engine, testFileUrl("asynchronousIfNested.1.qml"));
QVERIFY(component.isReady());
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object { component.create() };
+ QVERIFY(object);
QCOMPARE(object->property("a").toInt(), 10);
QQmlIncubator incubator(QQmlIncubator::AsynchronousIfNested);
- component.create(incubator, nullptr, qmlContext(object));
+ component.create(incubator, nullptr, qmlContext(object.get()));
QVERIFY(incubator.isReady());
QVERIFY(incubator.object());
QCOMPARE(incubator.object()->property("a").toInt(), 10);
delete incubator.object();
- delete object;
}
// Asynchronous if nested within an executing context behaves asynchronously, but prevents
@@ -679,6 +685,7 @@ void tst_qqmlincubator::asynchronousIfNested()
if (incubator.object()->property("a").toInt() != 10) return;
d->pass = true;
+ incubator.object()->deleteLater();
}
};
@@ -806,6 +813,9 @@ void tst_qqmlincubator::chainedAsynchronousIfNested()
QVERIFY(incubator.isReady());
QVERIFY(incubator1.isReady());
QVERIFY(incubator2.isReady());
+ incubator.object()->deleteLater();
+ incubator1.object()->deleteLater();
+ incubator2.object()->deleteLater();
}
// Checks that new AsynchronousIfNested incubators can be correctly chained if started in
@@ -934,6 +944,11 @@ void tst_qqmlincubator::chainedAsynchronousIfNestedOnCompleted()
QVERIFY(incubator1.isReady());
QVERIFY(incubator2.isReady());
QVERIFY(incubator3.isReady());
+
+ incubator.object()->deleteLater();
+ incubator1.object()->deleteLater();
+ incubator2.object()->deleteLater();
+ incubator3.object()->deleteLater();
}
// Checks that new AsynchronousIfNested incubators can be correctly cleared if started in
@@ -1050,6 +1065,10 @@ void tst_qqmlincubator::chainedAsynchronousClear()
QVERIFY(incubator1.isReady());
QVERIFY(incubator2.isReady());
QVERIFY(incubator3.isNull());
+
+
+ incubator1.object()->deleteLater();
+ incubator2.object()->deleteLater();
}
void tst_qqmlincubator::selfDelete()