aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-03-01 10:11:18 +0100
committerUlf Hermann <ulf.hermann@qt.io>2021-03-04 23:35:39 +0100
commitce52c245aaccf3183ef4759882e25b51b539195a (patch)
tree5229da9fac5299d95671e551bd2e513942b71d02 /tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp
parent3881f0df3d115ba8e59a5cedea970f3b085aa84a (diff)
Add a "prefer" directive to qmldir
The argument is the path from which further files from the module should be loaded. This allows us to load potentially pre-compiled files from a resource contained in a plugin. The qmldir file has to be stored outside the plugin in order for the QML engine to find it, but the QML files can now be stored inside the plugin. [ChangeLog][QtQml] You can now specify that QML files in a QML module should be loaded from a different place than the directory where the qmldir file is found. To do this, add a "prefer" directive to the qmldir file. The most useful application of this is adding the QML files as resources to a plugin, and using qmlcachegen to pre-compile them. You can then add their path inside the resource file system as "prefer" path in order to make the engine load the pre-compiled files. The plain files should still be installed next to the qmldir file so that they remain visible to tooling. Change-Id: Ib281b39230621b3762432095a47fb499412cbaa6 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp')
-rw-r--r--tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp b/tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp
index d53de4fd52..8f0c58653b 100644
--- a/tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp
+++ b/tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp
@@ -150,6 +150,7 @@ namespace {
void tst_qqmldirparser::parse_data()
{
QTest::addColumn<QString>("file");
+ QTest::addColumn<QString>("preferredPath");
QTest::addColumn<QStringList>("errors");
QTest::addColumn<QStringList>("plugins");
QTest::addColumn<QStringList>("classnames");
@@ -160,6 +161,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("empty")
<< "empty/qmldir"
+ << QString()
<< QStringList()
<< QStringList()
<< QStringList()
@@ -170,6 +172,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("no-content")
<< "no-content/qmldir"
+ << QString()
<< QStringList()
<< QStringList()
<< QStringList()
@@ -180,6 +183,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("one-section")
<< "one-section/qmldir"
+ << QString()
<< (QStringList() << "qmldir:1: a component declaration requires two or three arguments, but 1 were provided")
<< QStringList()
<< QStringList()
@@ -190,6 +194,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("four-sections")
<< "four-sections/qmldir"
+ << QString()
<< (QStringList() << "qmldir:1: a component declaration requires two or three arguments, but 4 were provided")
<< QStringList()
<< QStringList()
@@ -200,6 +205,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("incomplete-module")
<< "incomplete-module/qmldir"
+ << QString()
<< (QStringList() << "qmldir:1: module identifier directive requires one argument, but 0 were provided")
<< QStringList()
<< QStringList()
@@ -210,6 +216,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("excessive-module")
<< "excessive-module/qmldir"
+ << QString()
<< (QStringList() << "qmldir:1: module identifier directive requires one argument, but 2 were provided")
<< QStringList()
<< QStringList()
@@ -220,6 +227,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("repeated-module")
<< "repeated-module/qmldir"
+ << QString()
<< (QStringList() << "qmldir:2: only one module identifier directive may be defined in a qmldir file")
<< QStringList()
<< QStringList()
@@ -230,6 +238,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("non-first-module")
<< "non-first-module/qmldir"
+ << QString()
<< (QStringList() << "qmldir:2: module identifier directive must be the first directive in a qmldir file")
<< (QStringList() << "foo|")
<< QStringList()
@@ -240,6 +249,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("incomplete-plugin")
<< "incomplete-plugin/qmldir"
+ << QString()
<< (QStringList() << "qmldir:1: plugin directive requires one or two arguments, but 0 were provided")
<< QStringList()
<< QStringList()
@@ -250,6 +260,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("excessive-plugin")
<< "excessive-plugin/qmldir"
+ << QString()
<< (QStringList() << "qmldir:1: plugin directive requires one or two arguments, but 3 were provided")
<< QStringList()
<< QStringList()
@@ -260,6 +271,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("name-plugin")
<< "name-plugin/qmldir"
+ << QString()
<< QStringList()
<< (QStringList() << "foo|")
<< QStringList()
@@ -270,6 +282,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("name-path-plugin")
<< "name-path-plugin/qmldir"
+ << QString()
<< QStringList()
<< (QStringList() << "foo|bar")
<< QStringList()
@@ -280,6 +293,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("unversioned-component")
<< "unversioned-component/qmldir"
+ << QString()
<< QStringList()
<< QStringList()
<< QStringList()
@@ -290,6 +304,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("invalid-versioned-component")
<< "invalid-versioned-component/qmldir"
+ << QString()
<< (QStringList() << "qmldir:1: invalid version 100, expected <major>.<minor>")
<< QStringList()
<< QStringList()
@@ -300,6 +315,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("versioned-component")
<< "versioned-component/qmldir"
+ << QString()
<< QStringList()
<< QStringList()
<< QStringList()
@@ -310,6 +326,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("invalid-versioned-script")
<< "invalid-versioned-script/qmldir"
+ << QString()
<< (QStringList() << "qmldir:1: invalid version 100, expected <major>.<minor>")
<< QStringList()
<< QStringList()
@@ -320,6 +337,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("versioned-script")
<< "versioned-script/qmldir"
+ << QString()
<< QStringList()
<< QStringList()
<< QStringList()
@@ -330,6 +348,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("multiple")
<< "multiple/qmldir"
+ << QString()
<< QStringList()
<< (QStringList() << "PluginA|plugina.so")
<< QStringList()
@@ -342,6 +361,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("designersupported-yes")
<< "designersupported-yes/qmldir"
+ << QString()
<< QStringList()
<< (QStringList() << "foo|")
<< QStringList()
@@ -352,6 +372,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("designersupported-no")
<< "designersupported-no/qmldir"
+ << QString()
<< QStringList()
<< (QStringList() << "foo|")
<< QStringList()
@@ -362,6 +383,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("invalid-versioned-dependency")
<< "invalid-versioned-dependency/qmldir"
+ << QString()
<< (QStringList() << "qmldir:1: invalid version 100, expected <major>.<minor>")
<< QStringList()
<< QStringList()
@@ -372,6 +394,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("dependency")
<< "dependency/qmldir"
+ << QString()
<< QStringList()
<< (QStringList() << "foo|")
<< QStringList()
@@ -382,6 +405,7 @@ void tst_qqmldirparser::parse_data()
QTest::newRow("classname")
<< "classname/qmldir"
+ << QString()
<< QStringList()
<< (QStringList() << "qtquick2plugin|")
<< (QStringList() << "QtQuick2Plugin")
@@ -389,6 +413,39 @@ void tst_qqmldirparser::parse_data()
<< QStringList()
<< QStringList()
<< true;
+
+ QTest::newRow("prefer")
+ << "prefer/qmldir"
+ << ":/foo/bar/"
+ << QStringList()
+ << QStringList({"doesnotexist|"})
+ << QStringList({"FooBarInstance"})
+ << QStringList({"Foo|Foo.qml|1|0|false"})
+ << QStringList()
+ << QStringList()
+ << false;
+
+ QTest::newRow("two-prefer")
+ << "two-prefer/qmldir"
+ << ":/foo/bar/"
+ << QStringList({"qmldir:4: only one prefer directive may be defined in a qmldir file"})
+ << QStringList({"doesnotexist|"})
+ << QStringList({"FooBarInstance"})
+ << QStringList({"Foo|Foo.qml|1|0|false"})
+ << QStringList()
+ << QStringList()
+ << false;
+
+ QTest::newRow("prefer-no-slash")
+ << "prefer-no-slash/qmldir"
+ << QString()
+ << QStringList({"qmldir:3: the preferred directory has to end with a '/'"})
+ << QStringList({"doesnotexist|"})
+ << QStringList({"FooBarInstance"})
+ << QStringList({"Foo|Foo.qml|1|0|false"})
+ << QStringList()
+ << QStringList()
+ << false;
}
void tst_qqmldirparser::parse()