aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlecmascript
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-05-26 23:04:40 +0200
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-05-26 23:04:41 +0200
commit3ecdd85b2c7b8d56c4fd1a12a6cbaab663024ddb (patch)
tree255dae23f41c011b28167efe4ac8035384ef0346 /tests/auto/qml/qqmlecmascript
parentfb4c12a9db86a4b886058cc937c3c20b798bd2e2 (diff)
parent3e716029ae61bf4c7bb33643ac331156e70e34f1 (diff)
Merge remote-tracking branch 'origin/5.12' into 5.13
Diffstat (limited to 'tests/auto/qml/qqmlecmascript')
-rw-r--r--tests/auto/qml/qqmlecmascript/data/SingletonLookupTest.qml14
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp50
2 files changed, 64 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/SingletonLookupTest.qml b/tests/auto/qml/qqmlecmascript/data/SingletonLookupTest.qml
new file mode 100644
index 0000000000..3166ab647d
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/SingletonLookupTest.qml
@@ -0,0 +1,14 @@
+import QtQml 2.0
+import Test.Singletons 1.0
+
+QtObject {
+ property Component singletonAccessor : Component {
+ QtObject {
+ property var singletonHolder;
+ property int result: singletonHolder.testVar
+ }
+ }
+
+ property int firstLookup: singletonAccessor.createObject(this, { singletonHolder: CppSingleton1 }).result;
+ property int secondLookup: singletonAccessor.createObject(this, { singletonHolder: CppSingleton2 }).result;
+}
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 09b271c5f1..43cf8192a5 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -369,6 +369,7 @@ private slots:
void intMinDividedByMinusOne();
void undefinedPropertiesInObjectWrapper();
void hugeRegexpQuantifiers();
+ void singletonTypeWrapperLookup();
private:
// static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter);
@@ -8986,6 +8987,55 @@ void tst_qqmlecmascript::hugeRegexpQuantifiers()
QVERIFY(value.isRegExp());
}
+struct CppSingleton1 : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int testVar MEMBER testVar CONSTANT)
+public:
+ const int testVar = 0;
+};
+
+struct CppSingleton2 : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int testVar MEMBER testVar CONSTANT)
+public:
+ const int testVar = 1;
+};
+
+void tst_qqmlecmascript::singletonTypeWrapperLookup()
+{
+ QQmlEngine engine;
+
+ auto singletonTypeId1 = qmlRegisterSingletonType<CppSingleton1>("Test.Singletons", 1, 0, "CppSingleton1",
+ [](QQmlEngine *, QJSEngine *) -> QObject * {
+ return new CppSingleton1;
+ });
+
+ auto singletonTypeId2 = qmlRegisterSingletonType<CppSingleton2>("Test.Singletons", 1, 0, "CppSingleton2",
+ [](QQmlEngine *, QJSEngine *) -> QObject * {
+ return new CppSingleton2;
+ });
+
+ auto cleanup = qScopeGuard([&]() {
+ qmlUnregisterType(singletonTypeId1);
+ qmlUnregisterType(singletonTypeId2);
+ });
+
+ QQmlComponent component(&engine, testFileUrl("SingletonLookupTest.qml"));
+ QScopedPointer<QObject> test(component.create());
+ QVERIFY2(!test.isNull(), qPrintable(component.errorString()));
+
+ auto singleton1 = engine.singletonInstance<CppSingleton1*>(singletonTypeId1);
+ QVERIFY(singleton1);
+
+ auto singleton2 = engine.singletonInstance<CppSingleton2*>(singletonTypeId2);
+ QVERIFY(singleton2);
+
+ QCOMPARE(test->property("firstLookup").toInt(), singleton1->testVar);
+ QCOMPARE(test->property("secondLookup").toInt(), singleton2->testVar);
+}
+
QTEST_MAIN(tst_qqmlecmascript)
#include "tst_qqmlecmascript.moc"