diff options
Diffstat (limited to 'tests/auto/qml')
14 files changed, 246 insertions, 10 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/singletonTest.qml b/tests/auto/qml/qqmlecmascript/data/singletonTest.qml index ca3784322a..1c8984ce8c 100644 --- a/tests/auto/qml/qqmlecmascript/data/singletonTest.qml +++ b/tests/auto/qml/qqmlecmascript/data/singletonTest.qml @@ -1,12 +1,22 @@ /**************************************************************************** ** ** Copyright (C) 2013 Canonical Limited and/or its subsidiary(-ies). -** Contact: http://www.qt.io/licensing/ +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are diff --git a/tests/auto/qml/qqmlecmascript/data/singletonTest2.qml b/tests/auto/qml/qqmlecmascript/data/singletonTest2.qml index ef08745812..85549f4e87 100644 --- a/tests/auto/qml/qqmlecmascript/data/singletonTest2.qml +++ b/tests/auto/qml/qqmlecmascript/data/singletonTest2.qml @@ -1,12 +1,22 @@ /**************************************************************************** ** ** Copyright (C) 2013 Canonical Limited and/or its subsidiary(-ies). -** Contact: http://www.qt.io/licensing/ +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are diff --git a/tests/auto/qml/qqmllanguage/data/MyDeferredProperties.qml b/tests/auto/qml/qqmllanguage/data/MyDeferredProperties.qml new file mode 100644 index 0000000000..67e92e5a05 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/MyDeferredProperties.qml @@ -0,0 +1,19 @@ +import QtQml 2.0 +import Test 1.0 +DeferredProperties { + groupProperty: QtObject { + objectName: "innerobj" + property bool wasCompleted: false + Component.onCompleted: wasCompleted = true + } + QtObject { + objectName: "innerlist1" + property bool wasCompleted: false + Component.onCompleted: wasCompleted = true + } + QtObject { + objectName: "innerlist2" + property bool wasCompleted: false + Component.onCompleted: wasCompleted = true + } +} diff --git a/tests/auto/qml/qqmllanguage/data/deferredProperties.qml b/tests/auto/qml/qqmllanguage/data/deferredProperties.qml new file mode 100644 index 0000000000..07b146967c --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/deferredProperties.qml @@ -0,0 +1,19 @@ +import QtQml 2.0 +import Test 1.0 +MyDeferredProperties { + groupProperty: QtObject { + objectName: "outerobj" + property bool wasCompleted: false + Component.onCompleted: wasCompleted = true + } + QtObject { + objectName: "outerlist1" + property bool wasCompleted: false + Component.onCompleted: wasCompleted = true + } + QtObject { + objectName: "outerlist2" + property bool wasCompleted: false + Component.onCompleted: wasCompleted = true + } +} diff --git a/tests/auto/qml/qqmllanguage/data/singleton/RegisteredCompositeSingletonType.qml b/tests/auto/qml/qqmllanguage/data/singleton/RegisteredCompositeSingletonType.qml index d5a4e2ccf6..65d351a975 100644 --- a/tests/auto/qml/qqmllanguage/data/singleton/RegisteredCompositeSingletonType.qml +++ b/tests/auto/qml/qqmllanguage/data/singleton/RegisteredCompositeSingletonType.qml @@ -1,12 +1,22 @@ /**************************************************************************** ** ** Copyright (C) 2013 BlackBerry Limited. All rights reserved. -** Contact: http://www.qt.io/licensing/ +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are diff --git a/tests/auto/qml/qqmllanguage/data/singleton/js/jspragma.js b/tests/auto/qml/qqmllanguage/data/singleton/js/jspragma.js index a3dcfd398f..5932178ee3 100644 --- a/tests/auto/qml/qqmllanguage/data/singleton/js/jspragma.js +++ b/tests/auto/qml/qqmllanguage/data/singleton/js/jspragma.js @@ -1,12 +1,22 @@ /**************************************************************************** ** ** Copyright (C) 2013 BlackBerry Limited. All rights reserved. -** Contact: http://www.qt.io/licensing/ +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are diff --git a/tests/auto/qml/qqmllanguage/data/singletonTest17.qml b/tests/auto/qml/qqmllanguage/data/singletonTest17.qml index 192099845b..f8bebd9752 100644 --- a/tests/auto/qml/qqmllanguage/data/singletonTest17.qml +++ b/tests/auto/qml/qqmllanguage/data/singletonTest17.qml @@ -1,12 +1,22 @@ /**************************************************************************** ** ** Copyright (C) 2013 BlackBerry Limited. All rights reserved. -** Contact: http://www.qt.io/licensing/ +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are diff --git a/tests/auto/qml/qqmllanguage/testtypes.cpp b/tests/auto/qml/qqmllanguage/testtypes.cpp index 72e06d26aa..d2240d25a9 100644 --- a/tests/auto/qml/qqmllanguage/testtypes.cpp +++ b/tests/auto/qml/qqmllanguage/testtypes.cpp @@ -105,6 +105,7 @@ void registerTypes() qmlRegisterType<MyArrayBufferTestClass>("Test", 1, 0, "MyArrayBufferTestClass"); qmlRegisterType<LazyDeferredSubObject>("Test", 1, 0, "LazyDeferredSubObject"); + qmlRegisterType<DeferredProperties>("Test", 1, 0, "DeferredProperties"); } QVariant myCustomVariantTypeConverter(const QString &data) diff --git a/tests/auto/qml/qqmllanguage/testtypes.h b/tests/auto/qml/qqmllanguage/testtypes.h index 09c6992a51..5025a6e7f2 100644 --- a/tests/auto/qml/qqmllanguage/testtypes.h +++ b/tests/auto/qml/qqmllanguage/testtypes.h @@ -1369,6 +1369,21 @@ private: QObject *obj; }; +class DeferredProperties : public QObject +{ + Q_OBJECT + Q_PROPERTY(QObject *groupProperty MEMBER m_group) + Q_PROPERTY(QQmlListProperty<QObject> listProperty READ listProperty) + Q_CLASSINFO("DeferredPropertyNames", "groupProperty,listProperty") + Q_CLASSINFO("DefaultProperty", "listProperty") +public: + QQmlListProperty<QObject> listProperty() { return QQmlListProperty<QObject>(this, m_list); } + +private: + QObject *m_group = 0; + QObjectList m_list; +}; + void registerTypes(); #endif // TESTTYPES_H diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index eb462979ed..21efb0336d 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -252,6 +252,7 @@ private slots: void rootObjectInCreationNotForSubObjects(); void lazyDeferredSubObject(); + void deferredProperties(); void noChildEvents(); @@ -4354,6 +4355,53 @@ void tst_qqmllanguage::lazyDeferredSubObject() QCOMPARE(subObject->objectName(), QStringLiteral("custom")); } +// QTBUG-63200 +void tst_qqmllanguage::deferredProperties() +{ + QQmlComponent component(&engine, testFile("deferredProperties.qml")); + VERIFY_ERRORS(0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); + + QObject *innerObj = object->findChild<QObject *>(QStringLiteral("innerobj")); + QVERIFY(!innerObj); + + QObject *outerObj = object->findChild<QObject *>(QStringLiteral("outerobj")); + QVERIFY(!outerObj); + + QObject *groupProperty = object->property("groupProperty").value<QObject *>(); + QVERIFY(!groupProperty); + + QQmlListProperty<QObject> listProperty = object->property("listProperty").value<QQmlListProperty<QObject>>(); + QCOMPARE(listProperty.count(&listProperty), 0); + + qmlExecuteDeferred(object.data()); + + innerObj = object->findChild<QObject *>(QStringLiteral("innerobj")); // MyDeferredListProperty.qml + QVERIFY(innerObj); + QCOMPARE(innerObj->property("wasCompleted"), QVariant(true)); + + outerObj = object->findChild<QObject *>(QStringLiteral("outerobj")); // deferredListProperty.qml + QVERIFY(outerObj); + QCOMPARE(outerObj->property("wasCompleted"), QVariant(true)); + + groupProperty = object->property("groupProperty").value<QObject *>(); + QCOMPARE(groupProperty, outerObj); + + listProperty = object->property("listProperty").value<QQmlListProperty<QObject>>(); + QCOMPARE(listProperty.count(&listProperty), 4); + + QCOMPARE(listProperty.at(&listProperty, 0)->objectName(), QStringLiteral("innerlist1")); // MyDeferredListProperty.qml + QCOMPARE(listProperty.at(&listProperty, 0)->property("wasCompleted"), QVariant(true)); + QCOMPARE(listProperty.at(&listProperty, 1)->objectName(), QStringLiteral("innerlist2")); // MyDeferredListProperty.qml + QCOMPARE(listProperty.at(&listProperty, 1)->property("wasCompleted"), QVariant(true)); + + QCOMPARE(listProperty.at(&listProperty, 2)->objectName(), QStringLiteral("outerlist1")); // deferredListProperty.qml + QCOMPARE(listProperty.at(&listProperty, 2)->property("wasCompleted"), QVariant(true)); + QCOMPARE(listProperty.at(&listProperty, 3)->objectName(), QStringLiteral("outerlist2")); // deferredListProperty.qml + QCOMPARE(listProperty.at(&listProperty, 3)->property("wasCompleted"), QVariant(true)); +} + void tst_qqmllanguage::noChildEvents() { QQmlComponent component(&engine); diff --git a/tests/auto/qml/qqmltypeloader/data/Fast/Fast.qml b/tests/auto/qml/qqmltypeloader/data/Fast/Fast.qml new file mode 100644 index 0000000000..e879577e10 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/Fast/Fast.qml @@ -0,0 +1,4 @@ +import QtQml 2.0 + +QtObject { +} diff --git a/tests/auto/qml/qqmltypeloader/data/Fast/qmldir b/tests/auto/qml/qqmltypeloader/data/Fast/qmldir new file mode 100644 index 0000000000..a6a4c9e6c7 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/Fast/qmldir @@ -0,0 +1 @@ +Fast 1.0 Fast.qml 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..68b450ab26 100644 --- a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp +++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp @@ -43,6 +43,8 @@ private slots: void loadComponentSynchronously(); void trimCache(); void trimCache2(); + void keepSingleton(); + void keepRegistrations(); }; void tst_QQMLTypeLoader::testLoadComplete() @@ -120,6 +122,76 @@ 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()); +} + +class TestObject : public QObject +{ + Q_OBJECT +public: + TestObject(QObject *parent = 0) : QObject(parent) {} +}; + +QML_DECLARE_TYPE(TestObject) + +static void verifyTypes(bool shouldHaveTestObject, bool shouldHaveFast) +{ + bool hasTestObject = false; + bool hasFast = false; + for (const QQmlType &type : QQmlMetaType::qmlAllTypes()) { + if (type.elementName() == QLatin1String("Fast")) + hasFast = true; + else if (type.elementName() == QLatin1String("TestObject")) + hasTestObject = true; + } + QCOMPARE(hasTestObject, shouldHaveTestObject); + QCOMPARE(hasFast, shouldHaveFast); +} + +void tst_QQMLTypeLoader::keepRegistrations() +{ + verifyTypes(false, false); + qmlRegisterType<TestObject>("Test", 1, 0, "TestObject"); + verifyTypes(true, false); + + { + QQmlEngine engine; + engine.addImportPath(dataDirectory()); + QQmlComponent component(&engine); + component.setData("import Fast 1.0\nFast {}", QUrl()); + QVERIFY2(component.errorString().isEmpty(), component.errorString().toUtf8().constData()); + QCOMPARE(component.status(), QQmlComponent::Ready); + QScopedPointer<QObject> o(component.create()); + QVERIFY(o.data()); + verifyTypes(true, true); + } + + verifyTypes(true, false); // Fast is gone again, even though an event was still scheduled. + QQmlMetaType::freeUnusedTypesAndCaches(); + verifyTypes(true, false); // qmlRegisterType creates an undeletable type. +} + QTEST_MAIN(tst_QQMLTypeLoader) #include "tst_qqmltypeloader.moc" |