diff options
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qml/qqmltypeloader/data/ValueSource.qml | 7 | ||||
-rw-r--r-- | tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp | 25 |
2 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmltypeloader/data/ValueSource.qml b/tests/auto/qml/qqmltypeloader/data/ValueSource.qml new file mode 100644 index 0000000000..19e6e730c8 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/ValueSource.qml @@ -0,0 +1,7 @@ +pragma Singleton +import QtQuick 2.6 + +Item { + id: valueSource + property int something: 10 +} diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp index 3d3a7ff725..24f3cbc20d 100644 --- a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp +++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp @@ -43,6 +43,7 @@ private slots: void loadComponentSynchronously(); void trimCache(); void trimCache2(); + void keepSingleton(); }; void tst_QQMLTypeLoader::testLoadComplete() @@ -120,6 +121,30 @@ 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()); +} + QTEST_MAIN(tst_QQMLTypeLoader) #include "tst_qqmltypeloader.moc" |