diff options
Diffstat (limited to 'tests/auto/qml/qmltc_qprocess')
5 files changed, 106 insertions, 6 deletions
diff --git a/tests/auto/qml/qmltc_qprocess/CMakeLists.txt b/tests/auto/qml/qmltc_qprocess/CMakeLists.txt index 5644a622a2..04d2084d4f 100644 --- a/tests/auto/qml/qmltc_qprocess/CMakeLists.txt +++ b/tests/auto/qml/qmltc_qprocess/CMakeLists.txt @@ -9,6 +9,11 @@ qt_internal_add_test(tst_qmltc_qprocess Qt::Qml Qt::QuickTestUtilsPrivate ) + +# special setup for singleton files: +set_source_files_properties(data/SingletonThing.qml data/singletonUncreatable.qml + PROPERTIES QT_QML_SINGLETON_TYPE true) + qt6_add_qml_module(tst_qmltc_qprocess VERSION 1.0 URI QmltcQProcessTests @@ -23,6 +28,8 @@ qt6_add_qml_module(tst_qmltc_qprocess data/invalidAliasRevision.qml data/ComponentType.qml data/inlineComponentWithEnum.qml + data/singletonUncreatable.qml + data/uncreatable.qml ) set(common_libraries @@ -37,9 +44,6 @@ set(common_libraries target_include_directories(tst_qmltc_qprocess PUBLIC cpptypes/) target_link_libraries(tst_qmltc_qprocess PUBLIC ${common_libraries}) -# special setup for singleton files: -set_source_files_properties(SingletonThing.qml PROPERTIES QT_QML_SINGLETON_TYPE true) - add_dependencies(tst_qmltc_qprocess Qt::qmltc) # fetch --resource arguments manually (mimics the logic of qmltc compilation diff --git a/tests/auto/qml/qmltc_qprocess/cpptypes/testtype.h b/tests/auto/qml/qmltc_qprocess/cpptypes/testtype.h index a6fdb4a51a..6082870c76 100644 --- a/tests/auto/qml/qmltc_qprocess/cpptypes/testtype.h +++ b/tests/auto/qml/qmltc_qprocess/cpptypes/testtype.h @@ -3,12 +3,15 @@ #ifndef TESTTYPE_H #define TESTTYPE_H + +#include <QtQmlIntegration/qqmlintegration.h> #include <QtCore/qobject.h> #include <QtQml/qqmlregistration.h> class TypeWithVersionedAlias : public QObject { Q_OBJECT + QML_UNCREATABLE("") QML_ELEMENT QString m_readAndWrite; @@ -17,4 +20,53 @@ public: Q_PROPERTY(QString notExisting MEMBER m_readAndWrite REVISION(6, 0)); Q_PROPERTY(QString existing MEMBER m_readAndWrite REVISION(1, 0)); }; + +class UncreatableType : public QObject +{ + Q_OBJECT + QML_ELEMENT + QML_UNCREATABLE("") +}; + +class NoDefaultConstructorType : public QObject +{ + Q_OBJECT + QML_ELEMENT + NoDefaultConstructorType() = delete; +}; + +class SingletonType : public QObject +{ + Q_OBJECT + QML_ELEMENT + QML_SINGLETON +}; + +class NotSingletonType : public SingletonType +{ + Q_OBJECT + QML_ELEMENT +}; + +class NormalTypeAttached : public QObject +{ + Q_OBJECT + QML_ANONYMOUS +public: + NormalTypeAttached(QObject* parent): QObject(parent) {} +}; + +class NormalType : public QObject +{ + Q_OBJECT + QML_ELEMENT + QML_ATTACHED(NormalTypeAttached) + + static NormalTypeAttached *qmlAttachedProperties(QObject *object) { + return new NormalTypeAttached(object); + } +}; + + + #endif // TESTTYPE_H diff --git a/tests/auto/qml/qmltc_qprocess/data/singletonUncreatable.qml b/tests/auto/qml/qmltc_qprocess/data/singletonUncreatable.qml new file mode 100644 index 0000000000..d48a4ee186 --- /dev/null +++ b/tests/auto/qml/qmltc_qprocess/data/singletonUncreatable.qml @@ -0,0 +1,5 @@ +pragma Singleton + +UncreatableType { + +} diff --git a/tests/auto/qml/qmltc_qprocess/data/uncreatable.qml b/tests/auto/qml/qmltc_qprocess/data/uncreatable.qml new file mode 100644 index 0000000000..aad6ef3421 --- /dev/null +++ b/tests/auto/qml/qmltc_qprocess/data/uncreatable.qml @@ -0,0 +1,23 @@ +import QtQuick + +Item { + // Illegal cases: + UncreatableType {} + SingletonThing {} + SingletonType {} + + component A: SingletonThing {} + component AA: A {} + component AAA: AA {} + AAA {} + + component B: SingletonType {} + component BB: B {} + component BBB: BB {} + BBB {} + + // Legal cases, where qmltc should not crash + property SingletonThing myQmlSingleton + property SingletonType myCppSingleton + NotSingletonType {} // ok because a non composite type inheriting from a singleton does not become a singleton! +} diff --git a/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp b/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp index ae01f4697f..ea30e3c83f 100644 --- a/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp +++ b/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp @@ -189,9 +189,25 @@ void tst_qmltc_qprocess::inlineComponent() void tst_qmltc_qprocess::singleton() { - const auto errors = runQmltc(u"SingletonThing.qml"_s, false); - QEXPECT_FAIL("", "qmltc does not support singletons at the moment", Continue); - QVERIFY(!errors.contains(u"Singleton types are not supported"_s)); + { + const auto errors = runQmltc(u"singletonUncreatable.qml"_s, false); + QVERIFY(errors.contains("singletonUncreatable.qml:3:1: Type UncreatableType is not " + "creatable. [uncreatable-type]")); + } + { + const auto errors = runQmltc(u"uncreatable.qml"_s, false); + QVERIFY(errors.contains( + "uncreatable.qml:5:5: Type UncreatableType is not creatable. [uncreatable-type]")); + QVERIFY(errors.contains("uncreatable.qml:6:5: Singleton Type SingletonThing is not " + "creatable. [uncreatable-type]")); + QVERIFY(errors.contains("uncreatable.qml:7:5: Singleton Type SingletonType is not " + "creatable. [uncreatable-type]")); + QVERIFY(errors.contains("uncreatable.qml:9:18: Singleton Type SingletonThing is not " + "creatable. [uncreatable-type]")); + QVERIFY(errors.contains("uncreatable.qml:14:18: Singleton Type SingletonType is not " + "creatable. [uncreatable-type]")); + QVERIFY(!errors.contains("NotSingletonType")); + } } void tst_qmltc_qprocess::warningsAsErrors() |