diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/singletonTest18.qml | 9 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/testtypes.cpp | 9 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 26 |
3 files changed, 42 insertions, 2 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/singletonTest18.qml b/tests/auto/qml/qqmllanguage/data/singletonTest18.qml new file mode 100644 index 0000000000..7616c23531 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/singletonTest18.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 +import "singleton" +import Test 1.0 + +Item { + property var qmlSingleton: SingletonType + property var jsSingleton: MyQJSValueQObjectSingleton + property var cppSingleton: MyTypeObjectSingleton +} diff --git a/tests/auto/qml/qqmllanguage/testtypes.cpp b/tests/auto/qml/qqmllanguage/testtypes.cpp index 0eb4f26878..7e247b1906 100644 --- a/tests/auto/qml/qqmllanguage/testtypes.cpp +++ b/tests/auto/qml/qqmllanguage/testtypes.cpp @@ -35,6 +35,14 @@ static QObject *myTypeObjectSingleton(QQmlEngine *engine, QJSEngine *scriptEngin return new MyTypeObject(); } +static QJSValue myQJSValueQObjectSingleton(QQmlEngine *engine, QJSEngine *scriptEngine) +{ + Q_UNUSED(engine) + + QJSValue value = scriptEngine->newQObject(new MyTypeObject()); + return value; +} + void registerTypes() { qmlRegisterInterface<MyInterface>("MyInterface"); @@ -101,6 +109,7 @@ void registerTypes() qmlRegisterType<MyCompositeBaseType>("Test", 1, 0, "MyCompositeBaseType"); qmlRegisterSingletonType<MyTypeObjectSingleton>("Test", 1, 0, "MyTypeObjectSingleton", myTypeObjectSingleton); + qmlRegisterSingletonType("Test", 1, 0, "MyQJSValueQObjectSingleton", myQJSValueQObjectSingleton); qmlRegisterType<MyArrayBufferTestClass>("Test", 1, 0, "MyArrayBufferTestClass"); diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 400c28928a..39f973f3fd 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -246,6 +246,8 @@ private slots: void compositeSingletonRegistered(); void compositeSingletonCircular(); + void singletonsHaveContextAndEngine(); + void customParserBindingScopes(); void customParserEvaluateEnum(); void customParserProperties(); @@ -3923,11 +3925,13 @@ void tst_qqmllanguage::getSingletonInstance(QObject* o, const char* propertyName return; QVariant variant = o->property(propertyName); - QVERIFY(variant.userType() == qMetaTypeId<QObject *>()); + QVERIFY(variant.isValid()); QObject *singleton = nullptr; - if (variant.canConvert<QObject*>()) + if (variant.userType() == qMetaTypeId<QObject *>()) singleton = variant.value<QObject*>(); + else if (variant.userType() == qMetaTypeId<QJSValue>()) + singleton = variant.value<QJSValue>().toQObject(); QVERIFY(singleton != nullptr); *result = singleton; @@ -4232,6 +4236,24 @@ void tst_qqmllanguage::compositeSingletonCircular() QCOMPARE(o->property("value").toInt(), 2); } +void tst_qqmllanguage::singletonsHaveContextAndEngine() +{ + QObject *qmlSingleton = nullptr; + getSingletonInstance(engine, "singletonTest18.qml", "qmlSingleton", &qmlSingleton); + QVERIFY(qmlContext(qmlSingleton)); + QCOMPARE(qmlEngine(qmlSingleton), &engine); + + QObject *jsSingleton = nullptr; + getSingletonInstance(engine, "singletonTest18.qml", "jsSingleton", &jsSingleton); + QVERIFY(qmlContext(jsSingleton)); + QCOMPARE(qmlEngine(jsSingleton), &engine); + + QObject *cppSingleton = nullptr; + getSingletonInstance(engine, "singletonTest18.qml", "cppSingleton", &cppSingleton); + QVERIFY(qmlContext(cppSingleton)); + QCOMPARE(qmlEngine(cppSingleton), &engine); +} + void tst_qqmllanguage::customParserBindingScopes() { QQmlComponent component(&engine, testFile("customParserBindingScopes.qml")); |