tst_qqmlenginecleanup: Clean up memory management

Task-number: QTBUG-115222
Change-Id: Ifc526a17039662c69b16e115133271c1419fd3b6
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Amanda Hamblin-Trué 2023-08-03 14:21:19 +02:00
parent 1284917e72
commit 2ef3e2c34f
1 changed files with 12 additions and 15 deletions

View File

@ -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<QQmlEngine> engine;
std::unique_ptr<CleanlyLoadingComponent> component;
QUrl testFile = testFileUrl("types.qml");
const auto qmlTypeForTestType = []() {
@ -60,12 +60,12 @@ void tst_qqmlenginecleanup::test_qmlClearTypeRegistrations()
qmlRegisterType<QObject>("Test", 2, 0, "TestTypeCpp");
QVERIFY(qmlTypeForTestType().isValid());
engine = new QQmlEngine;
component = new CleanlyLoadingComponent(engine, testFile);
engine = std::make_unique<QQmlEngine>();
component = std::make_unique<CleanlyLoadingComponent>(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<QObject>("Test", 2, 0, "TestTypeCpp");
QVERIFY(qmlTypeForTestType().isValid());
engine = new QQmlEngine;
component = new CleanlyLoadingComponent(engine, testFile);
engine = std::make_unique<QQmlEngine>();
component = std::make_unique<CleanlyLoadingComponent>(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<QQmlEngine>();
component = std::make_unique<CleanlyLoadingComponent>(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)