aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlmetatype
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2017-03-15 13:29:24 +0100
committerUlf Hermann <ulf.hermann@qt.io>2017-03-15 14:40:43 +0000
commitaf9536deeaf1123aaae5ce78cee7b4014a01d595 (patch)
tree0cab0cec6f1d3e805ebb8af729ef0aeea727d507 /tests/auto/qml/qqmlmetatype
parentd88164fdbcc5af073f6f3c9b067d0edb5fa0e6d2 (diff)
Fix QQmlMetaType::prettyTypeName to deal with malformed type names
We can have QML type names that are empty or end in '/'. In those cases use the QMetaObject to retrieve a more meaningful type name. Change-Id: I4dd0841de13d4e7524a104f0bbc08cb854484cfe Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlmetatype')
-rw-r--r--tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp
index 9fbd719d7b..30e517c8f9 100644
--- a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp
+++ b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp
@@ -52,6 +52,7 @@ private slots:
void qmlPropertyValueInterceptorCast();
void qmlType();
void invalidQmlTypeName();
+ void prettyTypeName();
void registrationType();
void compositeType();
void externalEnums();
@@ -72,6 +73,16 @@ public:
};
QML_DECLARE_TYPE(TestType);
+class TestType2 : public QObject
+{
+ Q_OBJECT
+};
+
+class TestType3 : public QObject
+{
+ Q_OBJECT
+};
+
class ExternalEnums : public QObject
{
Q_OBJECT
@@ -214,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()