diff options
author | Sami Shalayel <sami.shalayel@qt.io> | 2022-12-22 11:33:18 +0100 |
---|---|---|
committer | Sami Shalayel <sami.shalayel@qt.io> | 2023-01-06 11:40:59 +0100 |
commit | c4b0acd5eb06f1bb96e4186711dfc6a63195f528 (patch) | |
tree | 8d4eecf6bcf1f3635dc8419d30578f6f4a214017 /tests/auto/qml/qmltc | |
parent | 434e19bede219c51af1213f2fc56bf2d6367e52e (diff) |
qmltc: test C++-namespace support
Add a test to see if qmltc handles c++ types correctly, that are wrapped
into namespaces.
Fixes: QTBUG-106830
Change-Id: I9ba89d209b84dfb8104073a02588cd824e657658
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qmltc')
-rw-r--r-- | tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/auto/qml/qmltc/QmltcTests/NamespacedTypes.qml | 12 | ||||
-rw-r--r-- | tests/auto/qml/qmltc/QmltcTests/cpptypes/typewithnamespace.cpp | 11 | ||||
-rw-r--r-- | tests/auto/qml/qmltc/QmltcTests/cpptypes/typewithnamespace.h | 54 | ||||
-rw-r--r-- | tests/auto/qml/qmltc/tst_qmltc.cpp | 11 | ||||
-rw-r--r-- | tests/auto/qml/qmltc/tst_qmltc.h | 1 |
6 files changed, 91 insertions, 0 deletions
diff --git a/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt b/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt index dc9a25a33a..cfb1469a38 100644 --- a/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt +++ b/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt @@ -20,6 +20,7 @@ set(cpp_sources cpptypes/typewithmanyproperties.h cpptypes/singletontype.h cpptypes/singletontype.cpp + cpptypes/typewithnamespace.h cpptypes/typewithnamespace.cpp cpptypes/typewithsignal.h ) @@ -121,6 +122,7 @@ set(qml_sources SingletonThing.qml InlineComponentProvider.qml InlineComponentReexporter.qml + NamespacedTypes.qml badFile.qml ) diff --git a/tests/auto/qml/qmltc/QmltcTests/NamespacedTypes.qml b/tests/auto/qml/qmltc/QmltcTests/NamespacedTypes.qml new file mode 100644 index 0000000000..93ed662b87 --- /dev/null +++ b/tests/auto/qml/qmltc/QmltcTests/NamespacedTypes.qml @@ -0,0 +1,12 @@ +import QtQml +import QmltcTests + +TypeWithSubnamespace { + property TypeWithNamespace myType: TypeWithNamespace {} + property QtObject myObject : QtObject { + property int value: 123 + } + function f() { + myObject.value = x + } +} diff --git a/tests/auto/qml/qmltc/QmltcTests/cpptypes/typewithnamespace.cpp b/tests/auto/qml/qmltc/QmltcTests/cpptypes/typewithnamespace.cpp new file mode 100644 index 0000000000..fbfaf447da --- /dev/null +++ b/tests/auto/qml/qmltc/QmltcTests/cpptypes/typewithnamespace.cpp @@ -0,0 +1,11 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include "typewithnamespace.h" + +MyNamespace::TypeWithNamespace::TypeWithNamespace(QObject *parent) : QObject{ parent } { } + +MyNamespace::Sub1::Sub2::Sub3::TypeWithSubnamespace::TypeWithSubnamespace(QObject *parent) + : QObject{ parent } +{ +} diff --git a/tests/auto/qml/qmltc/QmltcTests/cpptypes/typewithnamespace.h b/tests/auto/qml/qmltc/QmltcTests/cpptypes/typewithnamespace.h new file mode 100644 index 0000000000..7b8bc7803a --- /dev/null +++ b/tests/auto/qml/qmltc/QmltcTests/cpptypes/typewithnamespace.h @@ -0,0 +1,54 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#ifndef TYPEWITHNAMESPACE_H +#define TYPEWITHNAMESPACE_H + +#include <QtCore/qobject.h> +#include <QtQml/qqmlregistration.h> + +namespace MyNamespace { + +class TypeWithNamespace : public QObject +{ + Q_OBJECT + QML_ELEMENT +public: + TypeWithNamespace(QObject *parent = nullptr); + +signals: +}; + +namespace Sub1 { +namespace Sub2 { +namespace Sub3 { + +class TypeWithSubnamespace : public QObject +{ + Q_OBJECT + QML_ELEMENT + + int m_x = 55; + +public: + TypeWithSubnamespace(QObject *parent = nullptr); + + Q_PROPERTY(int x READ x WRITE setX NOTIFY xChanged); + int x() { return m_x; } + void setX(int x) + { + if (x == m_x) + return; + m_x = x; + emit xChanged(); + } + +signals: + void xChanged(); +}; +} // namespace Sub3 +} // namespace Sub2 +} // namespace Sub1 +} // namespace MyNamespace + +#endif // TYPEWITHNAMESPACE_H diff --git a/tests/auto/qml/qmltc/tst_qmltc.cpp b/tests/auto/qml/qmltc/tst_qmltc.cpp index 06d63333fc..4e65554e45 100644 --- a/tests/auto/qml/qmltc/tst_qmltc.cpp +++ b/tests/auto/qml/qmltc/tst_qmltc.cpp @@ -81,6 +81,7 @@ #include "testprivateproperty.h" #include "singletons.h" #include "mysignals.h" +#include "namespacedtypes.h" // Qt: #include <QtCore/qstring.h> @@ -3182,4 +3183,14 @@ void tst_qmltc::constSignalParameters() QCOMPARE(fromQmltc.object(), &myItem); } +void tst_qmltc::cppNamespaces() +{ + // see if qmltc works correctly with c++ namespaced types + QQmlEngine e; + PREPEND_NAMESPACE(NamespacedTypes) createdByQmltc(&e); + QCOMPARE(createdByQmltc.myObject()->property("value"), 123); + createdByQmltc.f(); + QCOMPARE(createdByQmltc.myObject()->property("value"), 55); +} + QTEST_MAIN(tst_qmltc) diff --git a/tests/auto/qml/qmltc/tst_qmltc.h b/tests/auto/qml/qmltc/tst_qmltc.h index 05a05bf9b6..a2d656bae7 100644 --- a/tests/auto/qml/qmltc/tst_qmltc.h +++ b/tests/auto/qml/qmltc/tst_qmltc.h @@ -91,4 +91,5 @@ private slots: void inlineComponentsFromDifferentFiles(); void singletons(); void constSignalParameters(); + void cppNamespaces(); }; |