diff options
author | Liang Qi <liang.qi@qt.io> | 2017-10-24 12:32:39 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2017-10-24 12:32:39 +0000 |
commit | 1aa91f8b0b140c417c6e97dfd22fa498d31bceb6 (patch) | |
tree | 714b9c79ca84cf9bda9912ea723cd925f0e8f4c9 /tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp | |
parent | 83c8f8d90a960965c1f166c4421f514f4236212a (diff) | |
parent | 15dd1b7883f5dbe66266aeb588381f85f3532ab9 (diff) |
Merge "Merge remote-tracking branch 'origin/5.9' into 5.10" into refs/staging/5.10
Diffstat (limited to 'tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp')
-rw-r--r-- | tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp index 3d3a7ff725..68b450ab26 100644 --- a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp +++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp @@ -43,6 +43,8 @@ private slots: void loadComponentSynchronously(); void trimCache(); void trimCache2(); + void keepSingleton(); + void keepRegistrations(); }; void tst_QQMLTypeLoader::testLoadComplete() @@ -120,6 +122,76 @@ void tst_QQMLTypeLoader::trimCache2() QCOMPARE(loader.isTypeLoaded(testFileUrl("MyComponent2.qml")), false); } +static void checkSingleton(const QString &dataDirectory) +{ + QQmlEngine engine; + engine.addImportPath(dataDirectory); + QQmlComponent component(&engine); + component.setData("import ClusterDemo 1.0\n" + "import QtQuick 2.6\n" + "import \"..\"\n" + "Item { property int t: ValueSource.something }", + QUrl::fromLocalFile(dataDirectory + "/abc/Xyz.qml")); + QCOMPARE(component.status(), QQmlComponent::Ready); + QScopedPointer<QObject> o(component.create()); + QVERIFY(o.data()); + QCOMPARE(o->property("t").toInt(), 10); +} + +void tst_QQMLTypeLoader::keepSingleton() +{ + qmlRegisterSingletonType(testFileUrl("ValueSource.qml"), "ClusterDemo", 1, 0, "ValueSource"); + checkSingleton(dataDirectory()); + QQmlMetaType::freeUnusedTypesAndCaches(); + checkSingleton(dataDirectory()); +} + +class TestObject : public QObject +{ + Q_OBJECT +public: + TestObject(QObject *parent = 0) : QObject(parent) {} +}; + +QML_DECLARE_TYPE(TestObject) + +static void verifyTypes(bool shouldHaveTestObject, bool shouldHaveFast) +{ + bool hasTestObject = false; + bool hasFast = false; + for (const QQmlType &type : QQmlMetaType::qmlAllTypes()) { + if (type.elementName() == QLatin1String("Fast")) + hasFast = true; + else if (type.elementName() == QLatin1String("TestObject")) + hasTestObject = true; + } + QCOMPARE(hasTestObject, shouldHaveTestObject); + QCOMPARE(hasFast, shouldHaveFast); +} + +void tst_QQMLTypeLoader::keepRegistrations() +{ + verifyTypes(false, false); + qmlRegisterType<TestObject>("Test", 1, 0, "TestObject"); + verifyTypes(true, false); + + { + QQmlEngine engine; + engine.addImportPath(dataDirectory()); + QQmlComponent component(&engine); + component.setData("import Fast 1.0\nFast {}", QUrl()); + QVERIFY2(component.errorString().isEmpty(), component.errorString().toUtf8().constData()); + QCOMPARE(component.status(), QQmlComponent::Ready); + QScopedPointer<QObject> o(component.create()); + QVERIFY(o.data()); + verifyTypes(true, true); + } + + verifyTypes(true, false); // Fast is gone again, even though an event was still scheduled. + QQmlMetaType::freeUnusedTypesAndCaches(); + verifyTypes(true, false); // qmlRegisterType creates an undeletable type. +} + QTEST_MAIN(tst_QQMLTypeLoader) #include "tst_qqmltypeloader.moc" |