diff options
author | Matthew Vogt <matthew.vogt@nokia.com> | 2012-03-26 16:39:00 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-29 00:36:49 +0200 |
commit | e4baefacff3e04ea3b599c5279e883d75d2ad489 (patch) | |
tree | dc78ce14db08c0aa771ddff9df8c23da8b8919ba /tests/auto/qml/qqmlmoduleplugin | |
parent | 5de103291d8159a236cabcc689caade265de1bd5 (diff) |
Re-order imports statements to import nested imports later
Re-order the imports for a script by increasing order of URI length.
This ensures that an import of the type 'import X.Y' is processed
after the import of 'import X' which contains the type definitions for
the namespace X.Y.
Task-number: QTBUG-24369
Change-Id: I1b06e9d114a97c9f47279f8f33383a27e0efb4bb
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests/auto/qml/qqmlmoduleplugin')
11 files changed, 162 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlmoduleplugin/data/importsNested.1.qml b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.1.qml new file mode 100644 index 0000000000..b3f9ac6c3f --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.1.qml @@ -0,0 +1,5 @@ +import com.nokia.AutoTestQmlNestedPluginType.Nested 1.0 +import com.nokia.AutoTestQmlNestedPluginType 1.0 + +MyNestedPluginType { +} diff --git a/tests/auto/qml/qqmlmoduleplugin/data/importsNested.2.qml b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.2.qml new file mode 100644 index 0000000000..cb8e0e33d1 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.2.qml @@ -0,0 +1,5 @@ +import com.nokia.AutoTestQmlNestedPluginType 1.0 +import com.nokia.AutoTestQmlNestedPluginType.Nested 1.0 + +MyNestedPluginType { +} diff --git a/tests/auto/qml/qqmlmoduleplugin/data/importsNested.3.errors.txt b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.3.errors.txt new file mode 100644 index 0000000000..f0c73e336f --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.3.errors.txt @@ -0,0 +1 @@ +3:1:MyNestedPluginType is not a type diff --git a/tests/auto/qml/qqmlmoduleplugin/data/importsNested.3.qml b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.3.qml new file mode 100644 index 0000000000..69c6a34f46 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.3.qml @@ -0,0 +1,4 @@ +import com.nokia.AutoTestQmlNestedPluginType 1.0 + +MyNestedPluginType { +} diff --git a/tests/auto/qml/qqmlmoduleplugin/data/importsNested.4.errors.txt b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.4.errors.txt new file mode 100644 index 0000000000..9743ae4f68 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.4.errors.txt @@ -0,0 +1 @@ +2:1:module "com.nokia.AutoTestQmlNestedPluginType.Nested" version 6.66 is not installed diff --git a/tests/auto/qml/qqmlmoduleplugin/data/importsNested.4.qml b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.4.qml new file mode 100644 index 0000000000..dce8b7564a --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.4.qml @@ -0,0 +1,5 @@ +import com.nokia.AutoTestQmlNestedPluginType 1.0 +import com.nokia.AutoTestQmlNestedPluginType.Nested 6.66 + +MyNestedPluginType { +} diff --git a/tests/auto/qml/qqmlmoduleplugin/imports/com/nokia/AutoTestQmlNestedPluginType/qmldir b/tests/auto/qml/qqmlmoduleplugin/imports/com/nokia/AutoTestQmlNestedPluginType/qmldir new file mode 100644 index 0000000000..f6ed20dda4 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/imports/com/nokia/AutoTestQmlNestedPluginType/qmldir @@ -0,0 +1 @@ +plugin nestedPlugin diff --git a/tests/auto/qml/qqmlmoduleplugin/nestedPlugin/nestedPlugin.cpp b/tests/auto/qml/qqmlmoduleplugin/nestedPlugin/nestedPlugin.cpp new file mode 100644 index 0000000000..2d0af471c2 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/nestedPlugin/nestedPlugin.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QStringList> +#include <QtQml/qqmlextensionplugin.h> +#include <QtQml/qqml.h> +#include <QDebug> + +class MyPluginType : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString value READ value) + +public: + MyPluginType(QObject *parent=0) : QObject(parent) {} + + QString value() const { return "Hello"; } +}; + +class MyNestedPluginType : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString value READ value) + +public: + MyNestedPluginType(QObject *parent=0) : QObject(parent) {} + + QString value() const { return "Goodbye"; } +}; + + +class MyPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface" FILE "../empty.json") + +public: + MyPlugin() {} + + void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == "com.nokia.AutoTestQmlNestedPluginType"); + qmlRegisterType<MyPluginType>(uri, 1, 0, "MyPluginType"); + + QString nestedUri(uri); + nestedUri += QLatin1String(".Nested"); + + qmlRegisterType<MyNestedPluginType>(nestedUri.toLatin1().constData(), 1, 0, "MyNestedPluginType"); + } +}; + +#include "nestedPlugin.moc" diff --git a/tests/auto/qml/qqmlmoduleplugin/nestedPlugin/nestedPlugin.pro b/tests/auto/qml/qqmlmoduleplugin/nestedPlugin/nestedPlugin.pro new file mode 100644 index 0000000000..94dc236a4c --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/nestedPlugin/nestedPlugin.pro @@ -0,0 +1,7 @@ +TEMPLATE = lib +CONFIG += nestedPlugin +SOURCES = nestedPlugin.cpp +QT = core qml +DESTDIR = ../imports/com/nokia/AutoTestQmlNestedPluginType + +QT += core-private gui-private qml-private diff --git a/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro b/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro index 42eedc20f2..6da88320cd 100644 --- a/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro +++ b/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro @@ -1,6 +1,6 @@ QT = core TEMPLATE = subdirs -SUBDIRS = plugin plugin.2 plugin.2.1 pluginWrongCase pluginWithQmlFile pluginMixed pluginVersion +SUBDIRS = plugin plugin.2 plugin.2.1 pluginWrongCase pluginWithQmlFile pluginMixed pluginVersion nestedPlugin 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 b574bad595..c110ce71d3 100644 --- a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp +++ b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp @@ -70,6 +70,8 @@ private slots: void versionNotInstalled_data(); void implicitQmldir(); void implicitQmldir_data(); + void importsNested(); + void importsNested_data(); private: QString m_importsDirectory; @@ -347,6 +349,47 @@ void tst_qqmlmoduleplugin::implicitQmldir() delete obj; } +void tst_qqmlmoduleplugin::importsNested_data() +{ + QTest::addColumn<QString>("file"); + QTest::addColumn<QString>("errorFile"); + + // Note: specific order required to induce failure (no other test case should import the + // plugin used for this test, or the alternate order test will pass spuriously) + QTest::newRow("alternateOrder") << "importsNested.1.qml" << QString(); + QTest::newRow("expectedOrder") << "importsNested.2.qml" << QString(); + QTest::newRow("missingImport") << "importsNested.3.qml" << "importsNested.3.errors.txt"; + QTest::newRow("invalidVersion") << "importsNested.4.qml" << "importsNested.4.errors.txt"; +} +void tst_qqmlmoduleplugin::importsNested() +{ + QFETCH(QString, file); + QFETCH(QString, errorFile); + + // Note: because imports are cached between test case data rows (and the plugins remain loaded), + // these tests should really be run in new instances of the app... + + QQmlEngine engine; + engine.addImportPath(m_importsDirectory); + + if (!errorFile.isEmpty()) { + QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready"); + } + + QQmlComponent component(&engine, testFile(file)); + QObject *obj = component.create(); + + if (errorFile.isEmpty()) { + if (qgetenv("DEBUG") != "" && !component.errors().isEmpty()) + qWarning() << "Unexpected Errors:" << component.errors(); + QVERIFY(obj); + delete obj; + } else { + QList<QQmlError> errors = component.errors(); + VERIFY_ERRORS(errorFile.toLatin1().constData()); + QVERIFY(!obj); + } +} QTEST_MAIN(tst_qqmlmoduleplugin) |