diff options
Diffstat (limited to 'tests')
12 files changed, 138 insertions, 106 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/singletontype/qobjectSingletonType.qml b/tests/auto/qml/qqmlecmascript/data/singletontype/qobjectSingletonType.qml index e0ada559ef..012890f12f 100644 --- a/tests/auto/qml/qqmlecmascript/data/singletontype/qobjectSingletonType.qml +++ b/tests/auto/qml/qqmlecmascript/data/singletontype/qobjectSingletonType.qml @@ -10,12 +10,15 @@ QtObject { property int existingUriTest: QtTest.QObject.qobjectTestProperty property int qobjectTest: QtTestQObjectApi.QObject.qobjectTestProperty property int qobjectMethodTest: 3 + property int qobjectMinorVersionMethodTest: 3 property int qobjectMinorVersionTest: QtTestMinorVersionQObjectApi.QObject.qobjectTestProperty property int qobjectMajorVersionTest: QtTestMajorVersionQObjectApi.QObject.qobjectTestProperty property int qobjectParentedTest: QtTestParentedQObjectApi.QObject.qobjectTestProperty Component.onCompleted: { - qobjectMethodTest = QtTestQObjectApi.QObject.qobjectTestMethod(); + qobjectMethodTest = QtTestQObjectApi.QObject.qobjectTestMethod(); // should be 1 + qobjectMethodTest = QtTestQObjectApi.QObject.qobjectTestMethod(); // should be 2 + qobjectMinorVersionMethodTest = QtTestMinorVersionQObjectApi.QObject.qobjectTestMethod(); // should be 1 } } diff --git a/tests/auto/qml/qqmlecmascript/data/singletontype/qobjectSingletonTypeCaching.qml b/tests/auto/qml/qqmlecmascript/data/singletontype/qobjectSingletonTypeCaching.qml index 03f07db290..94921ab4e0 100644 --- a/tests/auto/qml/qqmlecmascript/data/singletontype/qobjectSingletonTypeCaching.qml +++ b/tests/auto/qml/qqmlecmascript/data/singletontype/qobjectSingletonTypeCaching.qml @@ -4,7 +4,12 @@ import Qt.test 1.0 as QtTest // singleton T import Qt.test.qobjectApiParented 1.0 as QtTestParentedQObjectApi // qobject (with parent) singleton Type installed into a new uri QtObject { - property int existingUriTest: QtTest.QObject.qobjectTestProperty - property int qobjectParentedTest: QtTestParentedQObjectApi.QObject.qobjectTestProperty + property int existingUriTest: QtTest.QObject.qobjectTestWritableProperty + property int qobjectParentedTest: QtTestParentedQObjectApi.QObject.qobjectTestWritableProperty + + function modifyValues() { + QtTest.QObject.qobjectTestWritableProperty = 50; + QtTestParentedQObjectApi.QObject.qobjectTestWritableProperty = 65; + } } diff --git a/tests/auto/qml/qqmlecmascript/data/singletontype/scriptSingletonType.qml b/tests/auto/qml/qqmlecmascript/data/singletontype/scriptSingletonType.qml index 24b5112224..6197bbcfd8 100644 --- a/tests/auto/qml/qqmlecmascript/data/singletontype/scriptSingletonType.qml +++ b/tests/auto/qml/qqmlecmascript/data/singletontype/scriptSingletonType.qml @@ -2,5 +2,5 @@ import QtQuick 2.0 import Qt.test.scriptApi 1.0 as QtTestScriptApi // script singleton Type installed into new uri QtObject { - property int scriptTest: QtTestScriptApi.Script.scriptTestProperty // script singleton type's only provide properties. + property int scriptTest: QtTestScriptApi.Script.scriptTestProperty // script singleton types only provide properties. } diff --git a/tests/auto/qml/qqmlecmascript/data/singletontype/scriptSingletonTypeCaching.qml b/tests/auto/qml/qqmlecmascript/data/singletontype/scriptSingletonTypeCaching.qml index 287258bdc6..81ba9a66e4 100644 --- a/tests/auto/qml/qqmlecmascript/data/singletontype/scriptSingletonTypeCaching.qml +++ b/tests/auto/qml/qqmlecmascript/data/singletontype/scriptSingletonTypeCaching.qml @@ -3,4 +3,10 @@ import Qt.test.scriptApi 1.0 as QtTestScriptApi // script sing QtObject { property int scriptTest: QtTestScriptApi.Script.scriptTestProperty + + function modifyValues() { + // the constructor function of the script singleton will modify + // the value if it were called again (via the static int increment). + // So, we don't need to do anything in this function. + } } diff --git a/tests/auto/qml/qqmlecmascript/data/singletontype/singletonTypeMinorVersionFail.qml b/tests/auto/qml/qqmlecmascript/data/singletontype/singletonTypeMinorVersionFail.qml index 04eee77e75..6746388e21 100644 --- a/tests/auto/qml/qqmlecmascript/data/singletontype/singletonTypeMinorVersionFail.qml +++ b/tests/auto/qml/qqmlecmascript/data/singletontype/singletonTypeMinorVersionFail.qml @@ -2,7 +2,7 @@ import QtQuick 2.0 // this qml file attempts to import an invalid version of a qobject singleton Type. -import Qt.test.qobjectApi 1.2 as QtTestMinorVersionQObjectApi // qobject singleton Type installed into existing uri with nonexistent minor version +import Qt.test.qobjectApi 1.7 as QtTestMinorVersionQObjectApi // qobject singleton Type installed into existing uri with nonexistent minor version QtObject { property int qobjectMinorVersionTest: QtTestMinorVersionedQObjectApi.qobjectTestProperty diff --git a/tests/auto/qml/qqmlecmascript/data/singletontype/singletonTypeMultiple.qml b/tests/auto/qml/qqmlecmascript/data/singletontype/singletonTypeMultiple.qml new file mode 100644 index 0000000000..cbb43dfa89 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/singletontype/singletonTypeMultiple.qml @@ -0,0 +1,11 @@ +import QtQuick 2.0 +import Qt.test.qobjectApis 1.0 + +Item { + property int first: One.qobjectTestWritableProperty + property int second: Two.twoTestProperty + + Component.onCompleted: { + One.qobjectTestWritableProperty = 35; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/singletontype/singletonTypeResolution.qml b/tests/auto/qml/qqmlecmascript/data/singletontype/singletonTypeResolution.qml index c00a94c529..f58149bd62 100644 --- a/tests/auto/qml/qqmlecmascript/data/singletontype/singletonTypeResolution.qml +++ b/tests/auto/qml/qqmlecmascript/data/singletontype/singletonTypeResolution.qml @@ -9,9 +9,8 @@ QtObject { Component.onCompleted: { var s0 = Data.value === 37 && Namespace.Data.value === 37 && Data.value === Namespace.Data.value; - var s1 = NamespaceAndType.value === NamespaceAndType.NamespaceAndType.value && - NamespaceAndType.value === 37 && - NamespaceAndType.NamespaceAndType.value === 37; - success = (s0 === true) && (s1 === true); + var s1 = NamespaceAndType.NamespaceAndType.value === 37; // qualifier should shadow typename. + var s2 = NamespaceAndType.value === undefined; // should resolve to the qualifier, not the singleton type. + success = (s0 === true) && (s1 === true) && (s2 === true); } } diff --git a/tests/auto/qml/qqmlecmascript/testtypes.cpp b/tests/auto/qml/qqmlecmascript/testtypes.cpp index 72c9757450..a2ccb3a0b8 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.cpp +++ b/tests/auto/qml/qqmlecmascript/testtypes.cpp @@ -174,6 +174,15 @@ static QObject *qobject_api(QQmlEngine *engine, QJSEngine *scriptEngine) return o; } +static QObject *qobject_api_two(QQmlEngine *engine, QJSEngine *scriptEngine) +{ + Q_UNUSED(engine) + Q_UNUSED(scriptEngine) + + testQObjectApiTwo *o = new testQObjectApiTwo; + return o; +} + static QObject *qobject_api_engine_parent(QQmlEngine *engine, QJSEngine *scriptEngine) { Q_UNUSED(scriptEngine) @@ -284,6 +293,9 @@ void registerTypes() qmlRegisterSingletonType<testQObjectApi>("Qt.test.qobjectApi",2,0,"QObject",qobject_api); // register (qobject) singleton Type for a uri which doesn't contain elements, major version set qmlRegisterSingletonType<testQObjectApi>("Qt.test.qobjectApiParented",1,0,"QObject",qobject_api_engine_parent); // register (parented qobject) singleton Type for a uri which doesn't contain elements + qmlRegisterSingletonType<testQObjectApi>("Qt.test.qobjectApis",1,0,"One",qobject_api); // register multiple qobject singleton types in a single namespace + qmlRegisterSingletonType<testQObjectApiTwo>("Qt.test.qobjectApis",1,0,"Two",qobject_api_two); // register multiple qobject singleton types in a single namespace + qRegisterMetaType<MyQmlObject::MyEnum2>("MyEnum2"); qRegisterMetaType<Qt::MouseButtons>("Qt::MouseButtons"); diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h index 2fc0568fda..a4983f13db 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.h +++ b/tests/auto/qml/qqmlecmascript/testtypes.h @@ -1133,6 +1133,25 @@ private: QObject *m_trackedObject; }; +class testQObjectApiTwo : public QObject +{ + Q_OBJECT + Q_PROPERTY(int twoTestProperty READ twoTestProperty WRITE setTwoTestProperty NOTIFY twoTestPropertyChanged) + +public: + testQObjectApiTwo(QObject *parent = 0) : QObject(parent), m_ttp(42) {} + ~testQObjectApiTwo() {} + + void setTwoTestProperty(int v) { m_ttp = v; emit twoTestPropertyChanged(); } + int twoTestProperty() const { return m_ttp; } + +signals: + void twoTestPropertyChanged(); + +private: + int m_ttp; +}; + class testImportOrderApi : public QObject { Q_OBJECT diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 10425db0d1..4c5fb6f123 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -153,11 +153,10 @@ private slots: void signalWithQJSValue(); void singletonType_data(); void singletonType(); + void singletonTypeCaching_data(); + void singletonTypeCaching(); void singletonTypeImportOrder(); void singletonTypeResolution(); - void singletonTypeConflicts1(); - void singletonTypeConflicts2(); - void singletonTypeConflicts3(); void importScripts_data(); void importScripts(); void scarceResources(); @@ -3602,8 +3601,9 @@ void tst_qqmlecmascript::singletonType_data() << QString() << QStringList() << (QStringList() << "existingUriTest" << "qobjectTest" << "qobjectMethodTest" - << "qobjectMinorVersionTest" << "qobjectMajorVersionTest" << "qobjectParentedTest") - << (QVariantList() << 20 << 20 << 2 << 20 << 20 << 26) + << "qobjectMinorVersionMethodTest" << "qobjectMinorVersionTest" + << "qobjectMajorVersionTest" << "qobjectParentedTest") + << (QVariantList() << 20 << 20 << 2 << 1 << 20 << 20 << 26) << QStringList() << QVariantList() << QStringList() @@ -3614,29 +3614,7 @@ void tst_qqmlecmascript::singletonType_data() << QString() << QStringList() << (QStringList() << "scriptTest") - << (QVariantList() << 13) - << QStringList() - << QVariantList() - << QStringList() - << QVariantList(); - - QTest::newRow("qobject, caching + read") - << testFileUrl("singletontype/qobjectSingletonTypeCaching.qml") - << QString() - << QStringList() - << (QStringList() << "existingUriTest" << "qobjectParentedTest") - << (QVariantList() << 20 << 26) // 26, shouldn't have incremented to 27. - << QStringList() - << QVariantList() - << QStringList() - << QVariantList(); - - QTest::newRow("script, caching + read") - << testFileUrl("singletontype/scriptSingletonTypeCaching.qml") - << QString() - << QStringList() - << (QStringList() << "scriptTest") - << (QVariantList() << 13) // 13, shouldn't have incremented to 14. + << (QVariantList() << 14) // will have incremented, since we create a new engine each row in this test. << QStringList() << QVariantList() << QStringList() @@ -3658,7 +3636,7 @@ void tst_qqmlecmascript::singletonType_data() << QString() << (QStringList() << QString(testFileUrl("singletontype/scriptSingletonTypeWriting.qml").toString() + QLatin1String(":21: Error: Cannot assign to read-only property \"scriptTestProperty\""))) << (QStringList() << "readBack" << "unchanged") - << (QVariantList() << 13 << 42) + << (QVariantList() << 15 << 42) << (QStringList() << "firstProperty" << "secondProperty") << (QVariantList() << 30 << 30) << (QStringList() << "readBack" << "unchanged") @@ -3696,6 +3674,17 @@ void tst_qqmlecmascript::singletonType_data() << QVariantList() << QStringList() << QVariantList(); + + QTest::newRow("qobject, multiple in namespace") + << testFileUrl("singletontype/singletonTypeMultiple.qml") + << QString() + << QStringList() + << (QStringList() << "first" << "second") + << (QVariantList() << 35 << 42) + << QStringList() + << QVariantList() + << QStringList() + << QVariantList(); } void tst_qqmlecmascript::singletonType() @@ -3710,7 +3699,8 @@ void tst_qqmlecmascript::singletonType() QFETCH(QStringList, readBackProperties); QFETCH(QVariantList, readBackExpectedValues); - QQmlComponent component(&engine, testfile); + QQmlEngine cleanEngine; // so tests don't interfere which each other, as singleton types are engine-singletons only. + QQmlComponent component(&cleanEngine, testfile); if (!errorMessage.isEmpty()) QTest::ignoreMessage(QtWarningMsg, errorMessage.toLatin1().constData()); @@ -3734,6 +3724,45 @@ void tst_qqmlecmascript::singletonType() } } +void tst_qqmlecmascript::singletonTypeCaching_data() +{ + QTest::addColumn<QUrl>("testfile"); + QTest::addColumn<QStringList>("readProperties"); + + QTest::newRow("qobject, caching + read") + << testFileUrl("singletontype/qobjectSingletonTypeCaching.qml") + << (QStringList() << "existingUriTest" << "qobjectParentedTest"); + + QTest::newRow("script, caching + read") + << testFileUrl("singletontype/scriptSingletonTypeCaching.qml") + << (QStringList() << "scriptTest"); +} + +void tst_qqmlecmascript::singletonTypeCaching() +{ + QFETCH(QUrl, testfile); + QFETCH(QStringList, readProperties); + + // ensure that the singleton type instances are cached per-engine. + + QQmlEngine cleanEngine; + QQmlComponent component(&cleanEngine, testfile); + QObject *object = component.create(); + QVERIFY(object != 0); + QList<QVariant> firstValues; + QMetaObject::invokeMethod(object, "modifyValues"); + for (int i = 0; i < readProperties.size(); ++i) + firstValues << object->property(readProperties.at(i).toLatin1().constData()); + delete object; + + QQmlComponent component2(&cleanEngine, testfile); + QObject *object2 = component2.create(); + QVERIFY(object2 != 0); + for (int i = 0; i < readProperties.size(); ++i) + QCOMPARE(object2->property(readProperties.at(i).toLatin1().constData()), firstValues.at(i)); // cached, shouldn't have changed. + delete object2; +} + void tst_qqmlecmascript::singletonTypeImportOrder() { QQmlComponent component(&engine, testFileUrl("singletontype/singletonTypeImportOrder.qml")); @@ -3752,72 +3781,6 @@ void tst_qqmlecmascript::singletonTypeResolution() delete object; } -void tst_qqmlecmascript::singletonTypeConflicts1() -{ - const char *warning = "Cannot register singleton type TypeName in uri Test.Conflict1 1.5 (a conflicting singleton type already exists)"; - QTest::ignoreMessage(QtWarningMsg, warning); - - int i0 = qmlRegisterSingletonType<testImportOrderApi>("Test.Conflict1", 1, 5, "TypeName", 0); - QVERIFY(i0 != -1); - - int i1 = qmlRegisterSingletonType<testImportOrderApi>("Test.Conflict1", 2, 0, "TypeName", 0); - QVERIFY(i1 != -1); - - int i2 = qmlRegisterSingletonType<testImportOrderApi>("Test.Conflict1", 1, 5, "TypeName", 0); - QVERIFY(i2 == -1); - - int i3 = qmlRegisterSingletonType<testImportOrderApi>("Test.Conflict1", 1, 2, "TypeName", 0); - QVERIFY(i3 != -1); - - int i4 = qmlRegisterSingletonType<testImportOrderApi>("Test.Conflict1", 1, 8, "TypeName", 0); - QVERIFY(i4 != -1); -} - -void tst_qqmlecmascript::singletonTypeConflicts2() -{ - int i0 = qmlRegisterType<MyQmlObject>("Test.Conflict2", 1, 5, "TypeName"); - QVERIFY(i0 != -1); - - int i2 = qmlRegisterType<MyQmlObject>("Test.Conflict2", 1, 8, "TypeName"); - QVERIFY(i2 != -1); - - int i3 = qmlRegisterType<MyQmlObject>("Test.Conflict2", 2, 0, "TypeName"); - QVERIFY(i3 != -1); - - int i4 = qmlRegisterSingletonType<testImportOrderApi>("Test.Conflict2", 1, 0, "TypeName", 0); - QVERIFY(i4 != -1); - - const char *warning2 = "Cannot register singleton type TypeName in uri Test.Conflict2 1.9 (a conflicting type already exists)"; - QTest::ignoreMessage(QtWarningMsg, warning2); - - int i5 = qmlRegisterSingletonType<testImportOrderApi>("Test.Conflict2", 1, 9, "TypeName", 0); - QVERIFY(i5 == -1); -} - -void tst_qqmlecmascript::singletonTypeConflicts3() -{ - int i0 = qmlRegisterSingletonType<testImportOrderApi>("Test.Conflict3", 1, 0, "TypeName", 0); - QVERIFY(i0 != -1); - - int i1 = qmlRegisterSingletonType<testImportOrderApi>("Test.Conflict3", 1, 5, "TypeName", 0); - QVERIFY(i1 != -1); - - int i2 = qmlRegisterSingletonType<testImportOrderApi>("Test.Conflict3", 1, 8, "TypeName", 0); - QVERIFY(i2 != -1); - - int i3 = qmlRegisterSingletonType<testImportOrderApi>("Test.Conflict3", 2, 0, "TypeName", 0); - QVERIFY(i3 != -1); - - const char *warning = "Cannot register type TypeName in uri Test.Conflict3 1.0 (a conflicting singleton type already exists)"; - QTest::ignoreMessage(QtWarningMsg, warning); - - int i4 = qmlRegisterType<MyQmlObject>("Test.Conflict3", 1, 0, "TypeName"); - QVERIFY(i4 == -1); - - int i5 = qmlRegisterType<MyQmlObject>("Test.Conflict3", 1, 3, "TypeName"); - QVERIFY(i5 != -1); -} - void tst_qqmlecmascript::importScripts_data() { QTest::addColumn<QUrl>("testfile"); diff --git a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp index 520697909a..3df18fc77f 100644 --- a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp +++ b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp @@ -59,6 +59,7 @@ private slots: void qmlPropertyValueSourceCast(); void qmlPropertyValueInterceptorCast(); void qmlType(); + void invalidQmlTypeName(); void isList(); @@ -188,6 +189,19 @@ void tst_qqmlmetatype::qmlType() QCOMPARE(type->qmlTypeName(), QLatin1String("Test/ParserStatusTestType")); } +void tst_qqmlmetatype::invalidQmlTypeName() +{ + QStringList currFailures = QQmlMetaType::typeRegistrationFailures(); + QCOMPARE(qmlRegisterType<TestType>("TestNamespace", 1, 0, "Test$Type"), -1); // should fail due to invalid QML type name. + QStringList nowFailures = QQmlMetaType::typeRegistrationFailures(); + + foreach (const QString &f, currFailures) + nowFailures.removeOne(f); + + QCOMPARE(nowFailures.size(), 1); + QCOMPARE(nowFailures.at(0), QStringLiteral("Invalid QML element name \"Test$Type\"")); +} + void tst_qqmlmetatype::isList() { QCOMPARE(QQmlMetaType::isList(QVariant::Invalid), false); diff --git a/tests/auto/qml/v4/tst_v4.cpp b/tests/auto/qml/v4/tst_v4.cpp index fa01baf441..d39649a09a 100644 --- a/tests/auto/qml/v4/tst_v4.cpp +++ b/tests/auto/qml/v4/tst_v4.cpp @@ -995,7 +995,7 @@ void tst_v4::debuggingDumpInstructions() expectedPreAddress << "\t\tLoadId\t\t\tId_Offset(0) -> Output_Reg(0)"; expectedPreAddress << "\t\tLoadScope\t\t-> Output_Reg(0)"; expectedPreAddress << "\t\tLoadRoot\t\t-> Output_Reg(0)"; - expectedPreAddress << "\t\tLoadModuleObject\t\t) -> Output_Reg(0)"; + expectedPreAddress << "\t\tLoadSingletonObject\t\t) -> Output_Reg(0)"; expectedPreAddress << "\t\tLoadAttached\t\tObject_Reg(0) Attached_Index(0) -> Output_Reg(0)"; expectedPreAddress << "\t\tUnaryNot\t\tInput_Reg(0) -> Output_Reg(0)"; expectedPreAddress << "\t\tUnaryMinusNumber\t\tInput_Reg(0) -> Output_Reg(0)"; |