aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2021-10-20 11:14:52 +0200
committerAndrei Golubev <andrei.golubev@qt.io>2021-11-16 09:02:57 +0100
commit6ec7953257ef1155aef8a0a4b8379205ee850283 (patch)
tree1dac0463d8500bb3a90c37095a09890607423ec7 /tests/auto
parent88dfbe0deaa780f1cb5793d644341367d02e3073 (diff)
qmltc: support user-specified namespaces in the generated code
Already during the prototyping phase, conflicts in class names were encountered within Qt code base. Those could be avoided by namespaces. Initial qmltc logic was using meaningless "q_qmltc" namespace, so let's improve that by allowing user-specified namespaces + making Qt's own QML files (compiled to C++) being available under QT_NAMESPACE. The latter is achieved by providing (and using) the internal version of a qmltc-invoking function Task-number: QTBUG-84368 Task-number: QTBUG-96040 Change-Id: I99cdf1baba8838c093b6b469f6744869f72af093 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qml/qmltc/CMakeLists.txt6
-rw-r--r--tests/auto/qml/qmltc/tst_qmltc.cpp19
2 files changed, 20 insertions, 5 deletions
diff --git a/tests/auto/qml/qmltc/CMakeLists.txt b/tests/auto/qml/qmltc/CMakeLists.txt
index 5e6026046c..66d1e4bf01 100644
--- a/tests/auto/qml/qmltc/CMakeLists.txt
+++ b/tests/auto/qml/qmltc/CMakeLists.txt
@@ -32,7 +32,8 @@ qt6_add_qml_module(tst_qmltc_diskcache
target_compile_definitions(tst_qmltc_diskcache PRIVATE
QMLTC_TESTS_DISABLE_CACHE=0
)
-qt6_target_compile_qml_to_cpp(tst_qmltc_diskcache
+qt_internal_target_compile_qml_to_cpp(tst_qmltc_diskcache
+ NAMESPACE QmltcTest
FILES
${qml_sources}
)
@@ -55,7 +56,8 @@ qt6_add_qml_module(tst_qmltc_nodiskcache
target_compile_definitions(tst_qmltc_nodiskcache PRIVATE
QMLTC_TESTS_DISABLE_CACHE=1
)
-qt6_target_compile_qml_to_cpp(tst_qmltc_nodiskcache
+qt_internal_target_compile_qml_to_cpp(tst_qmltc_nodiskcache
+ # NAMESPACE QmltcTest # use QT_NAMESPACE instead
FILES
${qml_sources}
)
diff --git a/tests/auto/qml/qmltc/tst_qmltc.cpp b/tests/auto/qml/qmltc/tst_qmltc.cpp
index 566f4f117f..d9a5ca06e1 100644
--- a/tests/auto/qml/qmltc/tst_qmltc.cpp
+++ b/tests/auto/qml/qmltc/tst_qmltc.cpp
@@ -40,6 +40,19 @@
#include <QtQml/qqmlcomponent.h>
#include <QtQml/qqmlengine.h>
+// on top of testing different cache configurations, we can also test namespace
+// generation for the test classes using the same macro
+#ifdef QMLTC_TESTS_DISABLE_CACHE
+# if QMLTC_TESTS_DISABLE_CACHE
+# define PREPEND_NAMESPACE(name) QT_PREPEND_NAMESPACE(name)
+# else
+# define PREPEND_NAMESPACE(name) \
+ ::QmltcTest::name // silent contract that the namespace is QmltcTest
+# endif
+#else
+# error "QMLTC_TESTS_DISABLE_CACHE is supposed to be defined and be equal to either 0 or 1"
+#endif
+
tst_qmltc::tst_qmltc()
{
#if defined(QMLTC_TESTS_DISABLE_CACHE) && QMLTC_TESTS_DISABLE_CACHE
@@ -75,20 +88,20 @@ void tst_qmltc::qmlNameConflictResolution()
QQmlEngine e;
// Note: the C++ class name is derived from the source qml file path, not
// the output .h/.cpp, so: NameConflict class name for NameConflict.qml
- q_qmltc::NameConflict created(&e); // note: declared in ResolvedNameConflict.h
+ PREPEND_NAMESPACE(NameConflict) created(&e); // note: declared in ResolvedNameConflict.h
}
void tst_qmltc::helloWorld()
{
QQmlEngine e;
- q_qmltc::HelloWorld created(&e);
+ PREPEND_NAMESPACE(HelloWorld) created(&e);
QSKIP("Nothing is supported yet.");
}
void tst_qmltc::qtQuickIncludes()
{
QQmlEngine e;
- q_qmltc::simpleQtQuickTypes created(&e); // it should just compile as well
+ PREPEND_NAMESPACE(simpleQtQuickTypes) created(&e); // it should just compile as well
// since the file name is lower-case, let's also test that it's marked as
// QML_ANONYMOUS
const QMetaObject *mo = created.metaObject();