aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2021-10-29 12:43:44 +0200
committerAndrei Golubev <andrei.golubev@qt.io>2021-11-17 18:04:41 +0100
commit590dd43c4d1bdb67a2db66081357390458f87de8 (patch)
tree3236800c2538b1940eb727d5498156588e9768b1 /tests
parent06d99e4032ecd0611513d500d7c099ad9cb5d872 (diff)
qmltc: Compile QML enums into C++
Task-number: QTBUG-84368 Change-Id: Idf6c724496c807477ce0914ab0d32a80a9b90b5a Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qmltc/CMakeLists.txt1
-rw-r--r--tests/auto/qml/qmltc/data/typeWithEnums.qml10
-rw-r--r--tests/auto/qml/qmltc/tst_qmltc.cpp34
-rw-r--r--tests/auto/qml/qmltc/tst_qmltc.h1
4 files changed, 46 insertions, 0 deletions
diff --git a/tests/auto/qml/qmltc/CMakeLists.txt b/tests/auto/qml/qmltc/CMakeLists.txt
index 66d1e4bf01..f7f33fe214 100644
--- a/tests/auto/qml/qmltc/CMakeLists.txt
+++ b/tests/auto/qml/qmltc/CMakeLists.txt
@@ -9,6 +9,7 @@ set(qml_sources
data/HelloWorld.qml
data/NameConflict.qml
data/simpleQtQuickTypes.qml
+ data/typeWithEnums.qml
)
set_source_files_properties(data/NameConflict.qml PROPERTIES
diff --git a/tests/auto/qml/qmltc/data/typeWithEnums.qml b/tests/auto/qml/qmltc/data/typeWithEnums.qml
new file mode 100644
index 0000000000..7aaad03562
--- /dev/null
+++ b/tests/auto/qml/qmltc/data/typeWithEnums.qml
@@ -0,0 +1,10 @@
+import QtQml
+QtObject {
+ enum NoValuesSpecified {
+ A, B, C, D
+ }
+
+ enum ValuesSpecified {
+ A_ = 1, B_, B2_, C_ = 41, D_
+ }
+}
diff --git a/tests/auto/qml/qmltc/tst_qmltc.cpp b/tests/auto/qml/qmltc/tst_qmltc.cpp
index d9a5ca06e1..19e32e7941 100644
--- a/tests/auto/qml/qmltc/tst_qmltc.cpp
+++ b/tests/auto/qml/qmltc/tst_qmltc.cpp
@@ -32,6 +32,7 @@
#include "ResolvedNameConflict.h"
#include "helloworld.h"
#include "simpleqtquicktypes.h"
+#include "typewithenums.h"
// Qt:
#include <QtCore/qstring.h>
@@ -72,6 +73,8 @@ void tst_qmltc::initTestCase()
QUrl urls[] = {
QUrl("qrc:/QmltcTests/data/NameConflict.qml"),
QUrl("qrc:/QmltcTests/data/HelloWorld.qml"),
+ QUrl("qrc:/QmltcTests/data/simpleQtQuickTypes.qml"),
+ QUrl("qrc:/QmltcTests/data/typeWithEnums.qml"),
};
QQmlEngine e;
@@ -109,4 +112,35 @@ void tst_qmltc::qtQuickIncludes()
QCOMPARE(mo->classInfo(mo->indexOfClassInfo("QML.Element")).value(), "anonymous");
}
+void tst_qmltc::enumerations()
+{
+ QQmlEngine e;
+ PREPEND_NAMESPACE(typeWithEnums) created(&e);
+
+ // sanity
+ QCOMPARE(PREPEND_NAMESPACE(typeWithEnums)::NoValuesSpecified::A, 0);
+ QCOMPARE(PREPEND_NAMESPACE(typeWithEnums)::NoValuesSpecified::B, 1);
+ QCOMPARE(PREPEND_NAMESPACE(typeWithEnums)::NoValuesSpecified::C, 2);
+ QCOMPARE(PREPEND_NAMESPACE(typeWithEnums)::NoValuesSpecified::D, 3);
+
+ QCOMPARE(PREPEND_NAMESPACE(typeWithEnums)::ValuesSpecified::A_, 1);
+ QCOMPARE(PREPEND_NAMESPACE(typeWithEnums)::ValuesSpecified::B_, 2);
+ QCOMPARE(PREPEND_NAMESPACE(typeWithEnums)::ValuesSpecified::B2_, 3);
+ QCOMPARE(PREPEND_NAMESPACE(typeWithEnums)::ValuesSpecified::C_, 41);
+ QCOMPARE(PREPEND_NAMESPACE(typeWithEnums)::ValuesSpecified::D_, 42);
+
+ const QMetaObject *mo = created.metaObject();
+ const QMetaEnum enumerator1 = mo->enumerator(mo->indexOfEnumerator("NoValuesSpecified"));
+ QCOMPARE(enumerator1.enumName(), "NoValuesSpecified");
+ QCOMPARE(enumerator1.keyCount(), 4);
+ QCOMPARE(enumerator1.key(2), "C");
+ QCOMPARE(enumerator1.value(2), PREPEND_NAMESPACE(typeWithEnums)::NoValuesSpecified::C);
+
+ const QMetaEnum enumerator2 = mo->enumerator(mo->indexOfEnumerator("ValuesSpecified"));
+ QCOMPARE(enumerator2.enumName(), "ValuesSpecified");
+ QCOMPARE(enumerator2.keyCount(), 5);
+ QCOMPARE(enumerator2.key(2), "B2_");
+ QCOMPARE(enumerator2.value(2), PREPEND_NAMESPACE(typeWithEnums)::ValuesSpecified::B2_);
+}
+
QTEST_MAIN(tst_qmltc)
diff --git a/tests/auto/qml/qmltc/tst_qmltc.h b/tests/auto/qml/qmltc/tst_qmltc.h
index 2680aefac8..23c2d383c4 100644
--- a/tests/auto/qml/qmltc/tst_qmltc.h
+++ b/tests/auto/qml/qmltc/tst_qmltc.h
@@ -47,4 +47,5 @@ private slots:
void qmlNameConflictResolution();
void helloWorld();
void qtQuickIncludes();
+ void enumerations();
};