diff options
Diffstat (limited to 'tests/auto/qml/qmltyperegistrar')
-rw-r--r-- | tests/auto/qml/qmltyperegistrar/foreign/foreign.cpp | 43 | ||||
-rw-r--r-- | tests/auto/qml/qmltyperegistrar/foreign/foreign.h | 59 | ||||
-rw-r--r-- | tests/auto/qml/qmltyperegistrar/foreign/foreign.pro | 10 | ||||
-rw-r--r-- | tests/auto/qml/qmltyperegistrar/hppheader.hpp | 64 | ||||
-rw-r--r-- | tests/auto/qml/qmltyperegistrar/noextheader | 64 | ||||
-rw-r--r-- | tests/auto/qml/qmltyperegistrar/qmltyperegistrar.pro | 4 | ||||
-rw-r--r-- | tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp | 78 | ||||
-rw-r--r-- | tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h | 96 | ||||
-rw-r--r-- | tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.pro | 20 |
9 files changed, 438 insertions, 0 deletions
diff --git a/tests/auto/qml/qmltyperegistrar/foreign/foreign.cpp b/tests/auto/qml/qmltyperegistrar/foreign/foreign.cpp new file mode 100644 index 0000000000..db080a5cad --- /dev/null +++ b/tests/auto/qml/qmltyperegistrar/foreign/foreign.cpp @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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 "foreign.h" + +int Foreign::things() const +{ + return m_things; +} + +void Foreign::setThings(int things) +{ + if (m_things == things) + return; + + m_things = things; + emit thingsChanged(m_things); +} diff --git a/tests/auto/qml/qmltyperegistrar/foreign/foreign.h b/tests/auto/qml/qmltyperegistrar/foreign/foreign.h new file mode 100644 index 0000000000..dc9fbc84a8 --- /dev/null +++ b/tests/auto/qml/qmltyperegistrar/foreign/foreign.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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 FOREIGN_H +#define FOREIGN_H + +#include <QtCore/qobject.h> +#include <QtCore/qsize.h> + +class Foreign : public QObject +{ + Q_OBJECT + Q_PROPERTY(int things READ things WRITE setThings NOTIFY thingsChanged) + +public: + int things() const; + +public slots: + void setThings(int things); + +signals: + void thingsChanged(int things); + +private: + int m_things = 0; +}; + +class SizeGadget : public QSize +{ + Q_GADGET + Q_PROPERTY(int height READ height WRITE setHeight FINAL) +}; + +#endif // FOREIGN_H diff --git a/tests/auto/qml/qmltyperegistrar/foreign/foreign.pro b/tests/auto/qml/qmltyperegistrar/foreign/foreign.pro new file mode 100644 index 0000000000..87521eac43 --- /dev/null +++ b/tests/auto/qml/qmltyperegistrar/foreign/foreign.pro @@ -0,0 +1,10 @@ +TEMPLATE = lib +QT = core + +macos:CONFIG -= app_bundle +CONFIG -= debug_and_release_target + +SOURCES = foreign.cpp +HEADERS = foreign.h + +CONFIG += metatypes static diff --git a/tests/auto/qml/qmltyperegistrar/hppheader.hpp b/tests/auto/qml/qmltyperegistrar/hppheader.hpp new file mode 100644 index 0000000000..f5fc881b77 --- /dev/null +++ b/tests/auto/qml/qmltyperegistrar/hppheader.hpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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 HPPHEADER_HPP +#define HPPHEADER_HPP + +#include <QtCore/qobject.h> +#include <QtQml/qqml.h> + +class HppClass : public QObject +{ + Q_OBJECT + QML_ELEMENT + Q_PROPERTY(int eieiei READ eieiei WRITE setEieiei NOTIFY eieieiChanged) + +public: + int eieiei() const + { + return m_eieiei; + } + +public slots: + void setEieiei(int eieiei) + { + if (m_eieiei == eieiei) + return; + + m_eieiei = eieiei; + emit eieieiChanged(m_eieiei); + } + +signals: + void eieieiChanged(int eieiei); + +private: + int m_eieiei; +}; + +#endif // HPPHEADER_HPP diff --git a/tests/auto/qml/qmltyperegistrar/noextheader b/tests/auto/qml/qmltyperegistrar/noextheader new file mode 100644 index 0000000000..3b6cb6d72c --- /dev/null +++ b/tests/auto/qml/qmltyperegistrar/noextheader @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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 NOEXTHEADER +#define NOEXTHEADER + +#include <QtCore/qobject.h> +#include <QtQml/qqml.h> + +class Noext : public QObject +{ + Q_OBJECT + QML_ELEMENT + Q_PROPERTY(int gagaga READ gagaga WRITE setGagaga NOTIFY gagagaChanged) + +public: + int gagaga() const + { + return m_gagaga; + } + +public slots: + void setGagaga(int gagaga) + { + if (m_gagaga == gagaga) + return; + + m_gagaga = gagaga; + emit gagagaChanged(m_gagaga); + } + +signals: + void gagagaChanged(int gagaga); + +private: + int m_gagaga; +}; + +#endif // NOEXTHEADER diff --git a/tests/auto/qml/qmltyperegistrar/qmltyperegistrar.pro b/tests/auto/qml/qmltyperegistrar/qmltyperegistrar.pro new file mode 100644 index 0000000000..738d099123 --- /dev/null +++ b/tests/auto/qml/qmltyperegistrar/qmltyperegistrar.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +SUBDIRS = foreign tst_qmltyperegistrar.pro + +tst_qmltyperegistrar_pro.depends = foreign diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp new file mode 100644 index 0000000000..1cfcd689c6 --- /dev/null +++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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 "tst_qmltyperegistrar.h" +#include <QtTest/qtest.h> +#include <QtCore/qcoreapplication.h> +#include <QtCore/qfile.h> + +void tst_qmltyperegistrar::initTestCase() +{ + QFile file(QCoreApplication::applicationDirPath() + "/tst_qmltyperegistrar.qmltypes"); + QVERIFY(file.open(QIODevice::ReadOnly)); + qmltypesData = file.readAll(); + QVERIFY(file.atEnd()); + QCOMPARE(file.error(), QFile::NoError); +} + +void tst_qmltyperegistrar::qmltypesHasForeign() +{ + QVERIFY(qmltypesData.contains("things")); +} + +void tst_qmltyperegistrar::qmltypesHasHppClassAndNoext() +{ + QVERIFY(qmltypesData.contains("HppClass")); + QVERIFY(qmltypesData.contains("Noext")); +} + +void tst_qmltyperegistrar::qmltypesHasFileNames() +{ + QVERIFY(qmltypesData.contains("file: \"hppheader.hpp\"")); + QVERIFY(qmltypesData.contains("file: \"noextheader\"")); + QVERIFY(qmltypesData.contains("file: \"tst_qmltyperegistrar.h\"")); +} + +void tst_qmltyperegistrar::qmltypesHasFlags() +{ + QVERIFY(qmltypesData.contains("name: \"Flags\"")); + QVERIFY(qmltypesData.contains("alias: \"Flag\"")); + QVERIFY(qmltypesData.contains("isFlag: true")); +} + +void tst_qmltyperegistrar::superAndForeignTypes() +{ + QVERIFY(qmltypesData.contains("values: [\"Pixel\", \"Centimeter\", \"Inch\", \"Point\"]")); + QVERIFY(qmltypesData.contains("name: \"SizeGadget\"")); + QVERIFY(qmltypesData.contains("prototype: \"SizeEnums\"")); + QVERIFY(qmltypesData.contains("Property { name: \"height\"; type: \"int\" }")); + QVERIFY(qmltypesData.contains("Property { name: \"width\"; type: \"int\" }")); + QVERIFY(qmltypesData.contains("Method { name: \"sizeToString\"; type: \"string\" }")); +} + +QTEST_MAIN(tst_qmltyperegistrar) diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h new file mode 100644 index 0000000000..09485ab0b6 --- /dev/null +++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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 TST_QMLTYPEREGISTRAR_H +#define TST_QMLTYPEREGISTRAR_H + +#include "foreign.h" + +#include <QtQml/qqml.h> + +class SizeEnums +{ + Q_GADGET + QML_NAMED_ELEMENT(SizeEnums) + QML_UNCREATABLE("Element is not creatable.") + +public: + enum Unit { Pixel, Centimeter, Inch, Point }; + Q_ENUM(Unit) +}; + +class SizeValueType : public SizeEnums +{ + QSize v; + Q_GADGET + Q_PROPERTY(int width READ width WRITE setWidth FINAL) + QML_NAMED_ELEMENT(MySize) + QML_FOREIGN(SizeGadget) + +public: + Q_INVOKABLE QString sizeToString() const + { + return QString::fromLatin1("%1x%2").arg(v.width()).arg(v.height()); + } + + int width() const { return v.width(); } + void setWidth(int width) { v.setWidth(width); } +}; + +class Local : public Foreign +{ + Q_OBJECT + QML_ELEMENT +public: + enum Flag { + Flag1 = 0x1, + Flag2 = 0x2, + Flag3 = 0x4, + Flag4 = 0x8 + }; + Q_DECLARE_FLAGS(Flags, Flag) + Q_FLAG(Flags) +}; + +class tst_qmltyperegistrar : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + void qmltypesHasForeign(); + void qmltypesHasHppClassAndNoext(); + void qmltypesHasFileNames(); + void qmltypesHasFlags(); + void superAndForeignTypes(); + +private: + QByteArray qmltypesData; +}; + +#endif // TST_QMLTYPEREGISTRAR_H diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.pro b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.pro new file mode 100644 index 0000000000..fe21b122c2 --- /dev/null +++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.pro @@ -0,0 +1,20 @@ +TEMPLATE = app + +QT = core qml testlib +CONFIG += testcase qmltypes +CONFIG -= debug_and_release_target +macos:CONFIG -= app_bundle + +SOURCES += tst_qmltyperegistrar.cpp +HEADERS += \ + hppheader.hpp \ + noextheader \ + tst_qmltyperegistrar.h + +QMLTYPES_FILENAME = tst_qmltyperegistrar.qmltypes +QML_FOREIGN_METATYPES += foreign/foreign_metatypes.json +QML_IMPORT_NAME = QmlTypeRegistrarTest +QML_IMPORT_VERSION = 1.0 + +INCLUDEPATH += foreign +LIBS += -Lforeign -lforeign |