diff options
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp')
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 5ae9a6b038..b1a1ed4dec 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -356,6 +356,7 @@ private slots: void callPropertyOnUndefined(); void jumpStrictNotEqualUndefined(); void removeBindingsWithNoDependencies(); + void preserveBindingWithUnresolvedNames(); void temporaryDeadZone(); void importLexicalVariables_data(); void importLexicalVariables(); @@ -369,6 +370,8 @@ private slots: void intMinDividedByMinusOne(); void undefinedPropertiesInObjectWrapper(); void hugeRegexpQuantifiers(); + void singletonTypeWrapperLookup(); + void getThisObject(); private: // static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter); @@ -8841,6 +8844,18 @@ void tst_qqmlecmascript::removeBindingsWithNoDependencies() } +void tst_qqmlecmascript::preserveBindingWithUnresolvedNames() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("preserveBindingWithUnresolvedNames.qml")); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); + QCOMPARE(object->property("testTypeOf").toString(), QString("undefined")); + QObject obj; + engine.rootContext()->setContextProperty("contextProp", &obj); + QCOMPARE(object->property("testTypeOf").toString(), QString("object")); +} + void tst_qqmlecmascript::temporaryDeadZone() { QJSEngine engine; @@ -9007,6 +9022,66 @@ 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([&]() { + QQmlMetaType::unregisterType(singletonTypeId1); + QQmlMetaType::unregisterType(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); +} + +void tst_qqmlecmascript::getThisObject() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("getThis.qml")); + QVERIFY(component.isReady()); + QScopedPointer<QObject> test(component.create()); + QVERIFY(!test.isNull()); + + QTRY_COMPARE(qvariant_cast<QObject *>(test->property("self")), test.data()); +} + QTEST_MAIN(tst_qqmlecmascript) #include "tst_qqmlecmascript.moc" |