diff options
Diffstat (limited to 'tests/auto')
15 files changed, 358 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp index bfa7e2f13f..68739886c4 100644 --- a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp +++ b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp @@ -41,6 +41,8 @@ private slots: void importPathOrder(); void testDesignerSupported(); void uiFormatLoading(); + void completeQmldirPaths_data(); + void completeQmldirPaths(); void cleanup(); }; @@ -146,6 +148,43 @@ void tst_QQmlImport::importPathOrder() QCOMPARE(expectedImportPaths, engine.importPathList()); } +Q_DECLARE_METATYPE(QQmlImports::ImportVersion) + +void tst_QQmlImport::completeQmldirPaths_data() +{ + QTest::addColumn<QString>("uri"); + QTest::addColumn<QStringList>("basePaths"); + QTest::addColumn<int>("majorVersion"); + QTest::addColumn<int>("minorVersion"); + QTest::addColumn<QStringList>("expectedPaths"); + + QTest::newRow("QtQml") << "QtQml" << (QStringList() << "qtbase/qml/" << "path/to/qml") << 2 << 7 + << (QStringList() << "qtbase/qml/QtQml.2.7/qmldir" << "path/to/qml/QtQml.2.7/qmldir" + << "qtbase/qml/QtQml.2/qmldir" << "path/to/qml/QtQml.2/qmldir" + << "qtbase/qml/QtQml/qmldir" << "path/to/qml/QtQml/qmldir"); + + QTest::newRow("QtQml.Models") << "QtQml.Models" << QStringList("qtbase/qml/") << 2 << 2 + << (QStringList() << "qtbase/qml/QtQml/Models.2.2/qmldir" << "qtbase/qml/QtQml.2.2/Models/qmldir" + << "qtbase/qml/QtQml/Models.2/qmldir" << "qtbase/qml/QtQml.2/Models/qmldir" + << "qtbase/qml/QtQml/Models/qmldir"); + + QTest::newRow("org.qt-project.foo.bar") << "org.qt-project.foo.bar" << QStringList("qtbase/qml/") << 0 << 1 + << (QStringList() << "qtbase/qml/org/qt-project/foo/bar.0.1/qmldir" << "qtbase/qml/org/qt-project/foo.0.1/bar/qmldir" << "qtbase/qml/org/qt-project.0.1/foo/bar/qmldir" << "qtbase/qml/org.0.1/qt-project/foo/bar/qmldir" + << "qtbase/qml/org/qt-project/foo/bar.0/qmldir" << "qtbase/qml/org/qt-project/foo.0/bar/qmldir" << "qtbase/qml/org/qt-project.0/foo/bar/qmldir" << "qtbase/qml/org.0/qt-project/foo/bar/qmldir" + << "qtbase/qml/org/qt-project/foo/bar/qmldir"); +} + +void tst_QQmlImport::completeQmldirPaths() +{ + QFETCH(QString, uri); + QFETCH(QStringList, basePaths); + QFETCH(int, majorVersion); + QFETCH(int, minorVersion); + QFETCH(QStringList, expectedPaths); + + QCOMPARE(QQmlImports::completeQmldirPaths(uri, basePaths, majorVersion, minorVersion), expectedPaths); +} + QTEST_MAIN(tst_QQmlImport) #include "tst_qqmlimport.moc" diff --git a/tests/auto/qml/qqmlmoduleplugin/data/child.qml b/tests/auto/qml/qqmlmoduleplugin/data/child.qml new file mode 100644 index 0000000000..a11ae297d7 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/data/child.qml @@ -0,0 +1,3 @@ +import org.qtproject.AutoTestQmlPluginType.ChildPlugin 1.0 + +MyChildPluginType { value: 123 } diff --git a/tests/auto/qml/qqmlmoduleplugin/data/child2.qml b/tests/auto/qml/qqmlmoduleplugin/data/child2.qml new file mode 100644 index 0000000000..667164516a --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/data/child2.qml @@ -0,0 +1,3 @@ +import org.qtproject.AutoTestQmlPluginType.ChildPlugin 2.0 + +MyChildPluginType { valueOnlyIn2: 123 } diff --git a/tests/auto/qml/qqmlmoduleplugin/data/child21.qml b/tests/auto/qml/qqmlmoduleplugin/data/child21.qml new file mode 100644 index 0000000000..064d5474e0 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/data/child21.qml @@ -0,0 +1,3 @@ +import org.qtproject.AutoTestQmlPluginType.ChildPlugin 2.1 + +MyChildPluginType { valueOnlyIn2: 123 } diff --git a/tests/auto/qml/qqmlmoduleplugin/plugin.2.1/childplugin/childplugin.cpp b/tests/auto/qml/qqmlmoduleplugin/plugin.2.1/childplugin/childplugin.cpp new file mode 100644 index 0000000000..53247e7912 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/plugin.2.1/childplugin/childplugin.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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 <QStringList> +#include <QtQml/qqmlextensionplugin.h> +#include <QtQml/qqml.h> +#include <QDebug> + +class MyChildPluginType : public QObject +{ + Q_OBJECT + Q_PROPERTY(int value READ value WRITE setValue) + Q_PROPERTY(int valueOnlyIn2 READ value WRITE setValue) + +public: + MyChildPluginType(QObject *parent=0) : QObject(parent) + { + qWarning("child import2.1 worked"); + } + + int value() const { return v; } + void setValue(int i) { v = i; } + +private: + int v; +}; + + +class MyChildPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + MyChildPlugin() + { + qWarning("child plugin2.1 created"); + } + + void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == "org.qtproject.AutoTestQmlPluginType.ChildPlugin"); + qmlRegisterType<MyChildPluginType>(uri, 2, 1, "MyChildPluginType"); + } +}; + +#include "childplugin.moc" diff --git a/tests/auto/qml/qqmlmoduleplugin/plugin.2.1/childplugin/childplugin.pro b/tests/auto/qml/qqmlmoduleplugin/plugin.2.1/childplugin/childplugin.pro new file mode 100644 index 0000000000..7a0cd6f80f --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/plugin.2.1/childplugin/childplugin.pro @@ -0,0 +1,12 @@ +TEMPLATE = lib +CONFIG += childplugin +SOURCES = childplugin.cpp +QT = core qml +DESTDIR = ../../imports/org/qtproject/AutoTestQmlPluginType.2.1/ChildPlugin + +QT += core-private gui-private qml-private + +IMPORT_FILES = \ + qmldir + +include (../../../../shared/imports.pri) diff --git a/tests/auto/qml/qqmlmoduleplugin/plugin.2.1/childplugin/qmldir b/tests/auto/qml/qqmlmoduleplugin/plugin.2.1/childplugin/qmldir new file mode 100644 index 0000000000..c8d6488065 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/plugin.2.1/childplugin/qmldir @@ -0,0 +1 @@ +plugin childplugin diff --git a/tests/auto/qml/qqmlmoduleplugin/plugin.2/childplugin/childplugin.cpp b/tests/auto/qml/qqmlmoduleplugin/plugin.2/childplugin/childplugin.cpp new file mode 100644 index 0000000000..a59347d3a9 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/plugin.2/childplugin/childplugin.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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 <QStringList> +#include <QtQml/qqmlextensionplugin.h> +#include <QtQml/qqml.h> +#include <QDebug> + +class MyChildPluginType : public QObject +{ + Q_OBJECT + Q_PROPERTY(int value READ value WRITE setValue) + Q_PROPERTY(int valueOnlyIn2 READ value WRITE setValue) + +public: + MyChildPluginType(QObject *parent=0) : QObject(parent) + { + qWarning("child import2 worked"); + } + + int value() const { return v; } + void setValue(int i) { v = i; } + +private: + int v; +}; + + +class MyChildPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + MyChildPlugin() + { + qWarning("child plugin2 created"); + } + + void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == "org.qtproject.AutoTestQmlPluginType.ChildPlugin"); + qmlRegisterType<MyChildPluginType>(uri, 2, 0, "MyChildPluginType"); + } +}; + +#include "childplugin.moc" diff --git a/tests/auto/qml/qqmlmoduleplugin/plugin.2/childplugin/childplugin.pro b/tests/auto/qml/qqmlmoduleplugin/plugin.2/childplugin/childplugin.pro new file mode 100644 index 0000000000..c9283411f3 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/plugin.2/childplugin/childplugin.pro @@ -0,0 +1,13 @@ +TEMPLATE = lib +CONFIG += childplugin +SOURCES = childplugin.cpp +QT = core qml +DESTDIR = ../../imports/org/qtproject/AutoTestQmlPluginType.2/ChildPlugin + +QT += core-private gui-private qml-private + +IMPORT_DIR = DESTDIR +IMPORT_FILES = \ + qmldir + +include (../../../../shared/imports.pri) diff --git a/tests/auto/qml/qqmlmoduleplugin/plugin.2/childplugin/qmldir b/tests/auto/qml/qqmlmoduleplugin/plugin.2/childplugin/qmldir new file mode 100644 index 0000000000..c8d6488065 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/plugin.2/childplugin/qmldir @@ -0,0 +1 @@ +plugin childplugin diff --git a/tests/auto/qml/qqmlmoduleplugin/plugin/childplugin/childplugin.cpp b/tests/auto/qml/qqmlmoduleplugin/plugin/childplugin/childplugin.cpp new file mode 100644 index 0000000000..5f4f96f7e4 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/plugin/childplugin/childplugin.cpp @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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 <QStringList> +#include <QtQml/qqmlextensionplugin.h> +#include <QtQml/qqml.h> +#include <QDebug> + +class MyChildPluginType : public QObject +{ + Q_OBJECT + Q_PROPERTY(int value READ value WRITE setValue) + +public: + MyChildPluginType(QObject *parent=0) : QObject(parent) + { + qWarning("child import worked"); + } + + int value() const { return v; } + void setValue(int i) { v = i; } + +private: + int v; +}; + + +class MyChildPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + MyChildPlugin() + { + qWarning("child plugin created"); + } + + void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == "org.qtproject.AutoTestQmlPluginType.ChildPlugin"); + qmlRegisterType<MyChildPluginType>(uri, 1, 0, "MyChildPluginType"); + } +}; + +#include "childplugin.moc" diff --git a/tests/auto/qml/qqmlmoduleplugin/plugin/childplugin/childplugin.pro b/tests/auto/qml/qqmlmoduleplugin/plugin/childplugin/childplugin.pro new file mode 100644 index 0000000000..5f5c01f77e --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/plugin/childplugin/childplugin.pro @@ -0,0 +1,12 @@ +TEMPLATE = lib +CONFIG += childplugin +SOURCES = childplugin.cpp +QT = core qml +DESTDIR = ../../imports/org/qtproject/AutoTestQmlPluginType/ChildPlugin + +QT += core-private gui-private qml-private + +IMPORT_FILES = \ + qmldir + +include (../../../../shared/imports.pri) diff --git a/tests/auto/qml/qqmlmoduleplugin/plugin/childplugin/qmldir b/tests/auto/qml/qqmlmoduleplugin/plugin/childplugin/qmldir new file mode 100644 index 0000000000..c8d6488065 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/plugin/childplugin/qmldir @@ -0,0 +1 @@ +plugin childplugin diff --git a/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro b/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro index 5c30d8cc00..889968f6cc 100644 --- a/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro +++ b/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro @@ -17,7 +17,10 @@ SUBDIRS =\ preemptedStrictModule\ invalidNamespaceModule\ invalidFirstCommandModule\ - protectedModule + protectedModule\ + plugin/childplugin\ + plugin.2/childplugin\ + plugin.2.1/childplugin tst_qqmlmoduleplugin_pro.depends += plugin SUBDIRS += tst_qqmlmoduleplugin.pro diff --git a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp index 6ae1a6654f..265492b435 100644 --- a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp +++ b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp @@ -70,6 +70,9 @@ private slots: void importStrictModule(); void importStrictModule_data(); void importProtectedModule(); + void importsChildPlugin(); + void importsChildPlugin2(); + void importsChildPlugin21(); private: QString m_importsDirectory; @@ -575,6 +578,57 @@ void tst_qqmlmoduleplugin::importProtectedModule() QVERIFY(object != 0); } +void tst_qqmlmoduleplugin::importsChildPlugin() +{ + QQmlEngine engine; + engine.addImportPath(m_importsDirectory); + QTest::ignoreMessage(QtWarningMsg, "child plugin created"); + QTest::ignoreMessage(QtWarningMsg, "child import worked"); + QTest::ignoreMessage(QtWarningMsg, "Module 'org.qtproject.AutoTestQmlPluginType.ChildPlugin' does not contain a module identifier directive - it cannot be protected from external registrations."); + QQmlComponent component(&engine, testFileUrl(QStringLiteral("child.qml"))); + foreach (QQmlError err, component.errors()) + qWarning() << err; + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); + QCOMPARE(object->property("value").toInt(),123); + delete object; +} + +void tst_qqmlmoduleplugin::importsChildPlugin2() +{ + QQmlEngine engine; + engine.addImportPath(m_importsDirectory); + QTest::ignoreMessage(QtWarningMsg, "child plugin2 created"); + QTest::ignoreMessage(QtWarningMsg, "child import2 worked"); + QTest::ignoreMessage(QtWarningMsg, "Module 'org.qtproject.AutoTestQmlPluginType.ChildPlugin' does not contain a module identifier directive - it cannot be protected from external registrations."); + QQmlComponent component(&engine, testFileUrl(QStringLiteral("child2.qml"))); + foreach (QQmlError err, component.errors()) + qWarning() << err; + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); + QCOMPARE(object->property("value").toInt(),123); + delete object; +} + +void tst_qqmlmoduleplugin::importsChildPlugin21() +{ + QQmlEngine engine; + engine.addImportPath(m_importsDirectory); + QTest::ignoreMessage(QtWarningMsg, "child plugin2.1 created"); + QTest::ignoreMessage(QtWarningMsg, "child import2.1 worked"); + QTest::ignoreMessage(QtWarningMsg, "Module 'org.qtproject.AutoTestQmlPluginType.ChildPlugin' does not contain a module identifier directive - it cannot be protected from external registrations."); + QQmlComponent component(&engine, testFileUrl(QStringLiteral("child21.qml"))); + foreach (QQmlError err, component.errors()) + qWarning() << err; + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); + QCOMPARE(object->property("value").toInt(),123); + delete object; +} + QTEST_MAIN(tst_qqmlmoduleplugin) #include "tst_qqmlmoduleplugin.moc" |