diff options
author | Matthew Vogt <matthew.vogt@nokia.com> | 2012-07-25 16:59:17 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-31 00:22:36 +0200 |
commit | c9b7582a2e7ad9fcd03dd999c3b7a16b72803238 (patch) | |
tree | d1ffdb193576fef0c243600f46c69b180d2ad2a8 /tests/auto/qml/qqmldirparser | |
parent | 2e6accbbbb9783ff6e5ad171f179d5021b0761af (diff) |
Implement strict mode for qmldir modules
Allow a module's qmldir to contain a module directive, which when
present specifies 'strict mode' import processing. In strict mode,
type registrations are only permitted into the namespace identified
in the qmldir file's module directive. In addition, any type
registrations to that namespace originating from other modules are
treated as error conditions.
Task-number: QTBUG-26551
Change-Id: I081bde2d3b83d3f28524440177fb2cd1ccee34ad
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'tests/auto/qml/qqmldirparser')
19 files changed, 333 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmldirparser/data/empty/qmldir b/tests/auto/qml/qqmldirparser/data/empty/qmldir new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/auto/qml/qqmldirparser/data/empty/qmldir diff --git a/tests/auto/qml/qqmldirparser/data/excessive-module/qmldir b/tests/auto/qml/qqmldirparser/data/excessive-module/qmldir new file mode 100644 index 0000000000..c4fdbd4e35 --- /dev/null +++ b/tests/auto/qml/qqmldirparser/data/excessive-module/qmldir @@ -0,0 +1 @@ +module foo bar diff --git a/tests/auto/qml/qqmldirparser/data/excessive-plugin/qmldir b/tests/auto/qml/qqmldirparser/data/excessive-plugin/qmldir new file mode 100644 index 0000000000..4acde714ac --- /dev/null +++ b/tests/auto/qml/qqmldirparser/data/excessive-plugin/qmldir @@ -0,0 +1 @@ +plugin foo bar baz diff --git a/tests/auto/qml/qqmldirparser/data/four-sections/qmldir b/tests/auto/qml/qqmldirparser/data/four-sections/qmldir new file mode 100644 index 0000000000..03b37a0d27 --- /dev/null +++ b/tests/auto/qml/qqmldirparser/data/four-sections/qmldir @@ -0,0 +1 @@ +foo bar baz qux diff --git a/tests/auto/qml/qqmldirparser/data/incomplete-module/qmldir b/tests/auto/qml/qqmldirparser/data/incomplete-module/qmldir new file mode 100644 index 0000000000..0cca093d7a --- /dev/null +++ b/tests/auto/qml/qqmldirparser/data/incomplete-module/qmldir @@ -0,0 +1 @@ +module diff --git a/tests/auto/qml/qqmldirparser/data/incomplete-plugin/qmldir b/tests/auto/qml/qqmldirparser/data/incomplete-plugin/qmldir new file mode 100644 index 0000000000..8cb205e9b3 --- /dev/null +++ b/tests/auto/qml/qqmldirparser/data/incomplete-plugin/qmldir @@ -0,0 +1 @@ +plugin diff --git a/tests/auto/qml/qqmldirparser/data/invalid-versioned-component/qmldir b/tests/auto/qml/qqmldirparser/data/invalid-versioned-component/qmldir new file mode 100644 index 0000000000..c322b0f278 --- /dev/null +++ b/tests/auto/qml/qqmldirparser/data/invalid-versioned-component/qmldir @@ -0,0 +1 @@ +foo 100 bar diff --git a/tests/auto/qml/qqmldirparser/data/multiple/qmldir b/tests/auto/qml/qqmldirparser/data/multiple/qmldir new file mode 100644 index 0000000000..e74bad5617 --- /dev/null +++ b/tests/auto/qml/qqmldirparser/data/multiple/qmldir @@ -0,0 +1,15 @@ + +# +# Comment + +module ModuleNamespace + +plugin PluginA plugina.so # More comment + +ComponentA 1.0 componenta-1_0.qml +ScriptA 1.0 scripta-1_0.js + +# +ComponentA 1.5 componenta-1_5.qml +ComponentB 1.5 componentb-1_5.qml + diff --git a/tests/auto/qml/qqmldirparser/data/name-path-plugin/qmldir b/tests/auto/qml/qqmldirparser/data/name-path-plugin/qmldir new file mode 100644 index 0000000000..5cf8bd345d --- /dev/null +++ b/tests/auto/qml/qqmldirparser/data/name-path-plugin/qmldir @@ -0,0 +1 @@ +plugin foo bar diff --git a/tests/auto/qml/qqmldirparser/data/name-plugin/qmldir b/tests/auto/qml/qqmldirparser/data/name-plugin/qmldir new file mode 100644 index 0000000000..fb12cab37d --- /dev/null +++ b/tests/auto/qml/qqmldirparser/data/name-plugin/qmldir @@ -0,0 +1 @@ +plugin foo diff --git a/tests/auto/qml/qqmldirparser/data/no-content/qmldir b/tests/auto/qml/qqmldirparser/data/no-content/qmldir new file mode 100644 index 0000000000..3ce87ada21 --- /dev/null +++ b/tests/auto/qml/qqmldirparser/data/no-content/qmldir @@ -0,0 +1,4 @@ + +# only empty lines + # and comments + diff --git a/tests/auto/qml/qqmldirparser/data/non-first-module/qmldir b/tests/auto/qml/qqmldirparser/data/non-first-module/qmldir new file mode 100644 index 0000000000..932e43a94c --- /dev/null +++ b/tests/auto/qml/qqmldirparser/data/non-first-module/qmldir @@ -0,0 +1,2 @@ +plugin foo +module bar diff --git a/tests/auto/qml/qqmldirparser/data/one-section/qmldir b/tests/auto/qml/qqmldirparser/data/one-section/qmldir new file mode 100644 index 0000000000..257cc5642c --- /dev/null +++ b/tests/auto/qml/qqmldirparser/data/one-section/qmldir @@ -0,0 +1 @@ +foo diff --git a/tests/auto/qml/qqmldirparser/data/repeated-module/qmldir b/tests/auto/qml/qqmldirparser/data/repeated-module/qmldir new file mode 100644 index 0000000000..80c3e0c750 --- /dev/null +++ b/tests/auto/qml/qqmldirparser/data/repeated-module/qmldir @@ -0,0 +1,2 @@ +module foo +module bar diff --git a/tests/auto/qml/qqmldirparser/data/unversioned-component/qmldir b/tests/auto/qml/qqmldirparser/data/unversioned-component/qmldir new file mode 100644 index 0000000000..d675fa44e5 --- /dev/null +++ b/tests/auto/qml/qqmldirparser/data/unversioned-component/qmldir @@ -0,0 +1 @@ +foo bar diff --git a/tests/auto/qml/qqmldirparser/data/versioned-component/qmldir b/tests/auto/qml/qqmldirparser/data/versioned-component/qmldir new file mode 100644 index 0000000000..a2afd1835e --- /dev/null +++ b/tests/auto/qml/qqmldirparser/data/versioned-component/qmldir @@ -0,0 +1 @@ +foo 33.66 bar diff --git a/tests/auto/qml/qqmldirparser/data/versioned-script/qmldir b/tests/auto/qml/qqmldirparser/data/versioned-script/qmldir new file mode 100644 index 0000000000..1345a6855b --- /dev/null +++ b/tests/auto/qml/qqmldirparser/data/versioned-script/qmldir @@ -0,0 +1 @@ +foo 33.66 bar.js diff --git a/tests/auto/qml/qqmldirparser/qqmldirparser.pro b/tests/auto/qml/qqmldirparser/qqmldirparser.pro new file mode 100644 index 0000000000..8efb415d43 --- /dev/null +++ b/tests/auto/qml/qqmldirparser/qqmldirparser.pro @@ -0,0 +1,10 @@ +CONFIG += testcase +TARGET = tst_qqmldirparser +QT += qml testlib v8-private +macx:CONFIG -= app_bundle + +SOURCES += tst_qqmldirparser.cpp + +include (../../shared/util.pri) + +CONFIG += parallel_test diff --git a/tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp b/tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp new file mode 100644 index 0000000000..82616ffa8a --- /dev/null +++ b/tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp @@ -0,0 +1,288 @@ +/**************************************************************************** +** +** 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 "../../shared/util.h" + +#include <qtest.h> +#include <QObject> +#include <QQmlEngine> +#include <QQmlComponent> +#include <private/v8.h> +#include <private/qqmldirparser_p.h> +#include <QDebug> + +// Test the parsing of qmldir files + +class tst_qqmldirparser : public QQmlDataTest +{ + Q_OBJECT +public: + tst_qqmldirparser(); + +private slots: + void parse_data(); + void parse(); +}; + +tst_qqmldirparser::tst_qqmldirparser() +{ +} + +namespace { + + QStringList toStringList(const QList<QQmlError> &errors) + { + QStringList rv; + + foreach (const QQmlError &e, errors) + rv.append(e.toString()); + + return rv; + } + + QString toString(const QQmlDirParser::Plugin &p) + { + return p.name + "|" + p.path; + } + + QStringList toStringList(const QList<QQmlDirParser::Plugin> &plugins) + { + QStringList rv; + + foreach (const QQmlDirParser::Plugin &p, plugins) + rv.append(toString(p)); + + return rv; + } + + QString toString(const QQmlDirParser::Component &c) + { + return c.typeName + "|" + c.fileName + "|" + QString::number(c.majorVersion) + "|" + QString::number(c.minorVersion) + "|" + (c.internal ? "true" : "false"); + } + + QStringList toStringList(const QQmlDirComponents &components) + { + QStringList rv; + + foreach (const QQmlDirParser::Component &c, components.values()) + rv.append(toString(c)); + + qSort(rv); + return rv; + } + + QString toString(const QQmlDirParser::Script &s) + { + return s.nameSpace + "|" + s.fileName + "|" + QString::number(s.majorVersion) + "|" + QString::number(s.minorVersion); + } + + QStringList toStringList(const QList<QQmlDirParser::Script> &scripts) + { + QStringList rv; + + foreach (const QQmlDirParser::Script &s, scripts) + rv.append(toString(s)); + + return rv; + } +} + +void tst_qqmldirparser::parse_data() +{ + QTest::addColumn<QString>("file"); + QTest::addColumn<QStringList>("errors"); + QTest::addColumn<QStringList>("plugins"); + QTest::addColumn<QStringList>("components"); + QTest::addColumn<QStringList>("scripts"); + + QTest::newRow("empty") + << "empty/qmldir" + << QStringList() + << QStringList() + << QStringList() + << QStringList(); + + QTest::newRow("no-content") + << "no-content/qmldir" + << QStringList() + << QStringList() + << QStringList() + << QStringList(); + + QTest::newRow("one-section") + << "one-section/qmldir" + << (QStringList() << "qmldir:1: a component declaration requires two or three arguments, but 1 were provided") + << QStringList() + << QStringList() + << QStringList(); + + QTest::newRow("four-sections") + << "four-sections/qmldir" + << (QStringList() << "qmldir:1:12: unexpected token" + << "qmldir:1: invalid qmldir directive contains too many tokens") + << QStringList() + << QStringList() + << QStringList(); + + QTest::newRow("incomplete-module") + << "incomplete-module/qmldir" + << (QStringList() << "qmldir:1: module directive requires one argument, but 0 were provided") + << QStringList() + << QStringList() + << QStringList(); + + QTest::newRow("excessive-module") + << "excessive-module/qmldir" + << (QStringList() << "qmldir:1: module directive requires one argument, but 2 were provided") + << QStringList() + << QStringList() + << QStringList(); + + QTest::newRow("repeated-module") + << "repeated-module/qmldir" + << (QStringList() << "qmldir:2: only one module directive may be defined in a qmldir file") + << QStringList() + << QStringList() + << QStringList(); + + QTest::newRow("non-first-module") + << "non-first-module/qmldir" + << (QStringList() << "qmldir:2: module directive must be the first directive in a qmldir file") + << (QStringList() << "foo|") + << QStringList() + << QStringList(); + + QTest::newRow("incomplete-plugin") + << "incomplete-plugin/qmldir" + << (QStringList() << "qmldir:1: plugin directive requires one or two arguments, but 0 were provided") + << QStringList() + << QStringList() + << QStringList(); + + QTest::newRow("excessive-plugin") + << "excessive-plugin/qmldir" + << (QStringList() << "qmldir:1:15: unexpected token" + << "qmldir:1: invalid qmldir directive contains too many tokens") + << QStringList() + << QStringList() + << QStringList(); + + QTest::newRow("name-plugin") + << "name-plugin/qmldir" + << QStringList() + << (QStringList() << "foo|") + << QStringList() + << QStringList(); + + QTest::newRow("name-path-plugin") + << "name-path-plugin/qmldir" + << QStringList() + << (QStringList() << "foo|bar") + << QStringList() + << QStringList(); + + QTest::newRow("unversioned-component") + << "unversioned-component/qmldir" + << QStringList() + << QStringList() + << (QStringList() << "foo|bar|-1|-1|false") + << QStringList(); + + QTest::newRow("invalid-versioned-component") + << "invalid-versioned-component/qmldir" + << (QStringList() << "qmldir:1: expected '.'") + << QStringList() + << QStringList() + << QStringList(); + + QTest::newRow("versioned-component") + << "versioned-component/qmldir" + << QStringList() + << QStringList() + << (QStringList() << "foo|bar|33|66|false") + << QStringList(); + + QTest::newRow("versioned-script") + << "versioned-script/qmldir" + << QStringList() + << QStringList() + << QStringList() + << (QStringList() << "foo|bar.js|33|66"); + + QTest::newRow("multiple") + << "multiple/qmldir" + << QStringList() + << (QStringList() << "PluginA|plugina.so") + << (QStringList() << "ComponentA|componenta-1_0.qml|1|0|false" + << "ComponentA|componenta-1_5.qml|1|5|false" + << "ComponentB|componentb-1_5.qml|1|5|false") + << (QStringList() << "ScriptA|scripta-1_0.js|1|0"); +} + +void tst_qqmldirparser::parse() +{ + QFETCH(QString, file); + QFETCH(QStringList, errors); + QFETCH(QStringList, plugins); + QFETCH(QStringList, components); + QFETCH(QStringList, scripts); + + QFile f(testFile(file)); + f.open(QIODevice::ReadOnly); + + QQmlDirParser p; + p.parse(f.readAll()); + + if (errors.isEmpty()) { + QCOMPARE(p.hasError(), false); + } else { + QCOMPARE(p.hasError(), true); + QCOMPARE(toStringList(p.errors("qmldir")), errors); + } + + QCOMPARE(toStringList(p.plugins()), plugins); + QCOMPARE(toStringList(p.components()), components); + QCOMPARE(toStringList(p.scripts()), scripts); +} + +QTEST_MAIN(tst_qqmldirparser) + +#include "tst_qqmldirparser.moc" |