aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-01-25 13:56:24 +0100
committerUlf Hermann <ulf.hermann@qt.io>2021-01-25 16:53:32 +0100
commit79ac5a2053c09246860d61a9d5124d89d0b30abd (patch)
treeea67dc128b323c6147b866877a10b296968f58fa /tests/auto/qml
parentbe26ca6bcaaf0ddd7337cb8ff856a2e97866278a (diff)
qmltyperegistrar: Make sure we have metatypes for all QML types
We need to be able to resolve any QML type from its C++ name using QMetaType::fromName(). qmltyperegistrar can generate the missing metatypes, either by creating synthetic ones (for namespaces), or by making sure the existing ones are registered (for others). Change-Id: If775af56d891f2c2a5bb94589b3cb05a199c7c35 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml')
-rw-r--r--tests/auto/qml/qmltyperegistrar/CMakeLists.txt1
-rw-r--r--tests/auto/qml/qmltyperegistrar/foo.cpp35
-rw-r--r--tests/auto/qml/qmltyperegistrar/foo.h73
-rw-r--r--tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp29
-rw-r--r--tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h12
5 files changed, 150 insertions, 0 deletions
diff --git a/tests/auto/qml/qmltyperegistrar/CMakeLists.txt b/tests/auto/qml/qmltyperegistrar/CMakeLists.txt
index c12ef77ebb..0839f56c4f 100644
--- a/tests/auto/qml/qmltyperegistrar/CMakeLists.txt
+++ b/tests/auto/qml/qmltyperegistrar/CMakeLists.txt
@@ -10,6 +10,7 @@ qt_internal_add_test(tst_qmltyperegistrar
hppheader.hpp
# noextheader special case
tst_qmltyperegistrar.cpp tst_qmltyperegistrar.h
+ foo.cpp foo.h
INCLUDE_DIRECTORIES
foreign
PUBLIC_LIBRARIES
diff --git a/tests/auto/qml/qmltyperegistrar/foo.cpp b/tests/auto/qml/qmltyperegistrar/foo.cpp
new file mode 100644
index 0000000000..25aed2d8f0
--- /dev/null
+++ b/tests/auto/qml/qmltyperegistrar/foo.cpp
@@ -0,0 +1,35 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "foo.h"
+#include <QDebug>
+
+void Ooo::blah()
+{
+ qDebug() << "blah";
+}
diff --git a/tests/auto/qml/qmltyperegistrar/foo.h b/tests/auto/qml/qmltyperegistrar/foo.h
new file mode 100644
index 0000000000..2da5b92fc5
--- /dev/null
+++ b/tests/auto/qml/qmltyperegistrar/foo.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FOO_H
+#define FOO_H
+
+#include <QtCore/qobject.h>
+#include <qqml.h>
+
+class Bbb : public QObject
+{
+ Q_OBJECT
+public:
+ Bbb(QObject *parent = nullptr) : QObject(parent) {}
+};
+
+class Ccc : public QObject
+{
+ Q_OBJECT
+public:
+ Ccc(QObject *parent) : QObject(parent) {}
+};
+
+class Ooo : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+ QML_EXTENDED(Bbb)
+ QML_ATTACHED(Ccc);
+public:
+ Q_INVOKABLE void blah();
+
+ static Ccc *qmlAttachedProperties(QObject *o) { return new Ccc(o); }
+};
+
+namespace Foo {
+Q_NAMESPACE
+QML_ELEMENT
+
+enum Bar {
+ A, B, C
+};
+
+Q_ENUM_NS(Bar);
+}
+
+
+#endif // FOO_H
diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp
index 7b82be20f7..b5efefba9a 100644
--- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp
+++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp
@@ -126,4 +126,33 @@ void tst_qmltyperegistrar::namespacedElement()
QVERIFY2(!c.isError(), qPrintable(c.errorString()));
}
+void tst_qmltyperegistrar::derivedFromForeign()
+{
+ QVERIFY(qmltypesData.contains("name: \"DerivedFromForeign\""));
+ QVERIFY(qmltypesData.contains("prototype: \"QTimeLine\""));
+ QVERIFY(qmltypesData.contains("name: \"QTimeLine\""));
+}
+
+void tst_qmltyperegistrar::metaTypesRegistered()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine);
+ c.setData("import QmlTypeRegistrarTest\nOoo {}", QUrl());
+ QVERIFY(c.isReady());
+ QScopedPointer<QObject> obj(c.create());
+
+ auto verifyMetaType = [](const char *name, const char *className) {
+ const auto foundMetaType = QMetaType::fromName(name);
+ QVERIFY(foundMetaType.isValid());
+ QCOMPARE(foundMetaType.name(), name);
+ QVERIFY(foundMetaType.metaObject());
+ QCOMPARE(foundMetaType.metaObject()->className(), className);
+ };
+
+ verifyMetaType("Foo", "Foo");
+ verifyMetaType("Ooo*", "Ooo");
+ verifyMetaType("Bbb*", "Bbb");
+ verifyMetaType("Ccc*", "Ccc");
+}
+
QTEST_MAIN(tst_qmltyperegistrar)
diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h
index 509816f62c..486009ea59 100644
--- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h
+++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h
@@ -33,6 +33,7 @@
#include <QtQml/qqml.h>
#include <QtCore/qproperty.h>
+#include <QtCore/qtimeline.h>
class Interface {};
class Interface2 {};
@@ -141,6 +142,14 @@ namespace Namespace {
};
}
+class DerivedFromForeign : public QTimeLine
+{
+ Q_OBJECT
+ QML_ELEMENT
+public:
+ DerivedFromForeign(QObject *parent) : QTimeLine(1000, parent) {}
+};
+
class tst_qmltyperegistrar : public QObject
{
Q_OBJECT
@@ -158,6 +167,9 @@ private slots:
void pastMajorVersions();
void implementsInterfaces();
void namespacedElement();
+ void derivedFromForeign();
+ void metaTypesRegistered();
+
private:
QByteArray qmltypesData;
};