From 2ef3e2c34f4ef1649e2e2c918238fb83e2eea757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amanda=20Hamblin-Tru=C3=A9?= Date: Thu, 3 Aug 2023 14:21:19 +0200 Subject: [PATCH] tst_qqmlenginecleanup: Clean up memory management Task-number: QTBUG-115222 Change-Id: Ifc526a17039662c69b16e115133271c1419fd3b6 Reviewed-by: Fabian Kosmale --- .../tst_qqmlenginecleanup.cpp | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/tests/auto/qml/qqmlenginecleanup/tst_qqmlenginecleanup.cpp b/tests/auto/qml/qqmlenginecleanup/tst_qqmlenginecleanup.cpp index c9049c7ca4..643360db53 100644 --- a/tests/auto/qml/qqmlenginecleanup/tst_qqmlenginecleanup.cpp +++ b/tests/auto/qml/qqmlenginecleanup/tst_qqmlenginecleanup.cpp @@ -47,8 +47,8 @@ public: void tst_qqmlenginecleanup::test_qmlClearTypeRegistrations() { //Test for preventing memory leaks is in tests/manual/qmltypememory - QQmlEngine* engine; - CleanlyLoadingComponent* component; + std::unique_ptr engine; + std::unique_ptr component; QUrl testFile = testFileUrl("types.qml"); const auto qmlTypeForTestType = []() { @@ -60,12 +60,12 @@ void tst_qqmlenginecleanup::test_qmlClearTypeRegistrations() qmlRegisterType("Test", 2, 0, "TestTypeCpp"); QVERIFY(qmlTypeForTestType().isValid()); - engine = new QQmlEngine; - component = new CleanlyLoadingComponent(engine, testFile); + engine = std::make_unique(); + component = std::make_unique(engine.get(), testFile); QVERIFY(component->isReady()); - delete component; - delete engine; + component.reset(); + engine.reset(); { auto cppType = qmlTypeForTestType(); @@ -81,24 +81,21 @@ void tst_qqmlenginecleanup::test_qmlClearTypeRegistrations() //2nd run verifies that types can reload after a qmlClearTypeRegistrations qmlRegisterType("Test", 2, 0, "TestTypeCpp"); QVERIFY(qmlTypeForTestType().isValid()); - engine = new QQmlEngine; - component = new CleanlyLoadingComponent(engine, testFile); + engine = std::make_unique(); + component = std::make_unique(engine.get(), testFile); QVERIFY(component->isReady()); - delete component; - delete engine; + component.reset(); + engine.reset(); qmlClearTypeRegistrations(); QVERIFY(!qmlTypeForTestType().isValid()); //3nd run verifies that TestTypeCpp is no longer registered - engine = new QQmlEngine; - component = new CleanlyLoadingComponent(engine, testFile); + engine = std::make_unique(); + component = std::make_unique(engine.get(), testFile); QVERIFY(component->isError()); QCOMPARE(component->errorString(), testFile.toString() +":8 module \"Test\" is not installed\n"); - - delete component; - delete engine; } static void cleanState(QQmlEngine **e)