aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp')
-rw-r--r--tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp61
1 files changed, 60 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp
index 19cda21685..30e517c8f9 100644
--- a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp
+++ b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp
@@ -26,6 +26,7 @@
**
****************************************************************************/
+#include <qstandardpaths.h>
#include <qtest.h>
#include <qqml.h>
#include <qqmlprivate.h>
@@ -51,8 +52,10 @@ private slots:
void qmlPropertyValueInterceptorCast();
void qmlType();
void invalidQmlTypeName();
+ void prettyTypeName();
void registrationType();
void compositeType();
+ void externalEnums();
void isList();
@@ -70,6 +73,30 @@ public:
};
QML_DECLARE_TYPE(TestType);
+class TestType2 : public QObject
+{
+ Q_OBJECT
+};
+
+class TestType3 : public QObject
+{
+ Q_OBJECT
+};
+
+class ExternalEnums : public QObject
+{
+ Q_OBJECT
+ Q_ENUMS(QStandardPaths::StandardLocation QStandardPaths::LocateOptions)
+public:
+ ExternalEnums(QObject *parent = nullptr) : QObject(parent) {}
+
+ static QObject *create(QQmlEngine *engine, QJSEngine *scriptEngine) {
+ Q_UNUSED(scriptEngine);
+ return new ExternalEnums(engine);
+ }
+};
+QML_DECLARE_TYPE(ExternalEnums);
+
QObject *testTypeProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine);
@@ -198,13 +225,28 @@ void tst_qqmlmetatype::invalidQmlTypeName()
{
QStringList currFailures = QQmlMetaType::typeRegistrationFailures();
QCOMPARE(qmlRegisterType<TestType>("TestNamespace", 1, 0, "Test$Type"), -1); // should fail due to invalid QML type name.
+ QCOMPARE(qmlRegisterType<TestType>("Test", 1, 0, "EndingInSlash/"), -1);
QStringList nowFailures = QQmlMetaType::typeRegistrationFailures();
foreach (const QString &f, currFailures)
nowFailures.removeOne(f);
- QCOMPARE(nowFailures.size(), 1);
+ QCOMPARE(nowFailures.size(), 2);
QCOMPARE(nowFailures.at(0), QStringLiteral("Invalid QML element name \"Test$Type\""));
+ QCOMPARE(nowFailures.at(1), QStringLiteral("Invalid QML element name \"EndingInSlash/\""));
+}
+
+void tst_qqmlmetatype::prettyTypeName()
+{
+ TestType2 obj2;
+ QCOMPARE(QQmlMetaType::prettyTypeName(&obj2), QString("TestType2"));
+ QVERIFY(qmlRegisterType<TestType2>("Test", 1, 0, "") >= 0);
+ QCOMPARE(QQmlMetaType::prettyTypeName(&obj2), QString("TestType2"));
+
+ TestType3 obj3;
+ QCOMPARE(QQmlMetaType::prettyTypeName(&obj3), QString("TestType3"));
+ QVERIFY(qmlRegisterType<TestType3>("Test", 1, 0, "OtherName") >= 0);
+ QCOMPARE(QQmlMetaType::prettyTypeName(&obj3), QString("OtherName"));
}
void tst_qqmlmetatype::isList()
@@ -271,6 +313,23 @@ void tst_qqmlmetatype::compositeType()
QCOMPARE(type->sourceUrl(), testFileUrl("ImplicitType.qml"));
}
+void tst_qqmlmetatype::externalEnums()
+{
+ QQmlEngine engine;
+ qmlRegisterSingletonType<ExternalEnums>("x.y.z", 1, 0, "ExternalEnums", ExternalEnums::create);
+
+ QQmlComponent c(&engine, testFileUrl("testExternalEnums.qml"));
+ QObject *obj = c.create();
+ QVERIFY(obj);
+ QVariant a = obj->property("a");
+ QCOMPARE(a.type(), QVariant::Int);
+ QCOMPARE(a.toInt(), int(QStandardPaths::DocumentsLocation));
+ QVariant b = obj->property("b");
+ QCOMPARE(b.type(), QVariant::Int);
+ QCOMPARE(b.toInt(), int(QStandardPaths::DocumentsLocation));
+
+}
+
QTEST_MAIN(tst_qqmlmetatype)
#include "tst_qqmlmetatype.moc"