aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml
diff options
context:
space:
mode:
authorMatthew Vogt <matthew.vogt@nokia.com>2012-06-29 12:25:20 +1000
committerQt by Nokia <qt-info@nokia.com>2012-07-16 04:46:50 +0200
commit432a48b8f2d9ebaef1bd7be4a168a45524faaf68 (patch)
treede7ff211c9e1b3b2bd0156b464bacbfbea475a1d /tests/auto/qml
parent9bc216f6fa34484bf582cbc3ccd2bb7b45826bc7 (diff)
Support remote import paths
Probe for installed modules in import path elements which are not local to the machine. Note that all local paths in the import path list will be tried before any remote locations are probed. Task-number: QTBUG-21386 Change-Id: I4f7b9e54e54c1d62a5e7cb7f059ee1e9319ef054 Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Diffstat (limited to 'tests/auto/qml')
-rw-r--r--tests/auto/qml/qqmlecmascript/data/jsimport/testJsModuleRemoteImport.js5
-rw-r--r--tests/auto/qml/qqmlecmascript/data/jsimport/testJsRemoteImport.qml13
-rw-r--r--tests/auto/qml/qqmlecmascript/data/remote/com/nokia/JsRemoteModule/ScriptAPI.js5
-rw-r--r--tests/auto/qml/qqmlecmascript/data/remote/com/nokia/JsRemoteModule/qmldir1
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp24
-rw-r--r--tests/auto/qml/qqmllanguage/data/lib/testModule/Test.qml5
-rw-r--r--tests/auto/qml/qqmllanguage/data/lib/testModule/qmldir1
-rw-r--r--tests/auto/qml/qqmllanguage/data/lib2/testModule/Test.qml5
-rw-r--r--tests/auto/qml/qqmllanguage/data/lib2/testModule/qmldir1
-rw-r--r--tests/auto/qml/qqmllanguage/data/lib3/testModule.1.0/Test.qml5
-rw-r--r--tests/auto/qml/qqmllanguage/data/lib3/testModule.1.0/qmldir1
-rw-r--r--tests/auto/qml/qqmllanguage/data/lib3/testModule.1/Test.qml5
-rw-r--r--tests/auto/qml/qqmllanguage/data/lib3/testModule.1/qmldir1
-rw-r--r--tests/auto/qml/qqmllanguage/data/lib4/testModule.1/Test.qml5
-rw-r--r--tests/auto/qml/qqmllanguage/data/lib4/testModule.1/qmldir1
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp119
16 files changed, 196 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/testJsModuleRemoteImport.js b/tests/auto/qml/qqmlecmascript/data/jsimport/testJsModuleRemoteImport.js
new file mode 100644
index 0000000000..e6e41bc6b2
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/jsimport/testJsModuleRemoteImport.js
@@ -0,0 +1,5 @@
+.import com.nokia.JsRemoteModule 1.0 as JsModule
+
+function importedValue() {
+ return JsModule.ScriptAPI.greeting();
+}
diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/testJsRemoteImport.qml b/tests/auto/qml/qqmlecmascript/data/jsimport/testJsRemoteImport.qml
new file mode 100644
index 0000000000..4199bb022d
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/jsimport/testJsRemoteImport.qml
@@ -0,0 +1,13 @@
+import QtQuick 2.0
+
+import com.nokia.JsModule 1.0
+import com.nokia.JsModule 1.0 as RenamedModule
+import "testJsModuleRemoteImport.js" as TestJsModuleImport
+
+QtObject {
+ id: testQtObject
+
+ property string importedScriptStringValue: ScriptAPI.greeting();
+ property string renamedScriptStringValue: RenamedModule.ScriptAPI.greeting();
+ property string reimportedScriptStringValue: TestJsModuleImport.importedValue();
+}
diff --git a/tests/auto/qml/qqmlecmascript/data/remote/com/nokia/JsRemoteModule/ScriptAPI.js b/tests/auto/qml/qqmlecmascript/data/remote/com/nokia/JsRemoteModule/ScriptAPI.js
new file mode 100644
index 0000000000..b90033eeb4
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/remote/com/nokia/JsRemoteModule/ScriptAPI.js
@@ -0,0 +1,5 @@
+var major = 1
+var minor = 0
+
+function greeting() { return "Hello" }
+
diff --git a/tests/auto/qml/qqmlecmascript/data/remote/com/nokia/JsRemoteModule/qmldir b/tests/auto/qml/qqmlecmascript/data/remote/com/nokia/JsRemoteModule/qmldir
new file mode 100644
index 0000000000..c33d1e7a0d
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/remote/com/nokia/JsRemoteModule/qmldir
@@ -0,0 +1 @@
+ScriptAPI 1.0 ScriptAPI.js
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index aaa6d365bd..c7763fcbd4 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -3784,6 +3784,17 @@ void tst_qqmlecmascript::importScripts_data()
<< QVariant(QString("Hello"))
<< QVariant(QString("Hello")));
+ QTest::newRow("import module which exports a script which imports a remote module")
+ << testFileUrl("jsimport/testJsRemoteImport.qml")
+ << QString()
+ << QStringList()
+ << (QStringList() << QLatin1String("importedScriptStringValue")
+ << QLatin1String("renamedScriptStringValue")
+ << QLatin1String("reimportedScriptStringValue"))
+ << (QVariantList() << QVariant(QString("Hello"))
+ << QVariant(QString("Hello"))
+ << QVariant(QString("Hello")));
+
QTest::newRow("malformed import statement")
<< testFileUrl("jsimportfail/malformedImport.qml")
<< QString()
@@ -3870,6 +3881,15 @@ void tst_qqmlecmascript::importScripts()
QFETCH(QStringList, propertyNames);
QFETCH(QVariantList, propertyValues);
+ TestHTTPServer server(8111);
+ QVERIFY(server.isValid());
+ server.serveDirectory(dataDirectory() + "/remote");
+
+ QStringList importPathList = engine.importPathList();
+
+ QString remotePath(QLatin1String("http://127.0.0.1:8111/"));
+ engine.addImportPath(remotePath);
+
QQmlComponent component(&engine, testfile);
if (!errorMessage.isEmpty())
@@ -3879,6 +3899,8 @@ void tst_qqmlecmascript::importScripts()
foreach (const QString &warning, warningMessages)
QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData());
+ QTRY_VERIFY(component.isReady());
+
QObject *object = component.create();
if (!errorMessage.isEmpty()) {
QVERIFY(object == 0);
@@ -3888,6 +3910,8 @@ void tst_qqmlecmascript::importScripts()
QCOMPARE(object->property(propertyNames.at(i).toLatin1().constData()), propertyValues.at(i));
delete object;
}
+
+ engine.setImportPathList(importPathList);
}
void tst_qqmlecmascript::scarceResources_other()
diff --git a/tests/auto/qml/qqmllanguage/data/lib/testModule/Test.qml b/tests/auto/qml/qqmllanguage/data/lib/testModule/Test.qml
new file mode 100644
index 0000000000..f53382871f
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/lib/testModule/Test.qml
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+Item {
+ property string test: 'foo'
+}
diff --git a/tests/auto/qml/qqmllanguage/data/lib/testModule/qmldir b/tests/auto/qml/qqmllanguage/data/lib/testModule/qmldir
new file mode 100644
index 0000000000..d6a9461666
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/lib/testModule/qmldir
@@ -0,0 +1 @@
+Test 1.0 Test.qml
diff --git a/tests/auto/qml/qqmllanguage/data/lib2/testModule/Test.qml b/tests/auto/qml/qqmllanguage/data/lib2/testModule/Test.qml
new file mode 100644
index 0000000000..cb44ffd44e
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/lib2/testModule/Test.qml
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+Item {
+ property string test: 'bar'
+}
diff --git a/tests/auto/qml/qqmllanguage/data/lib2/testModule/qmldir b/tests/auto/qml/qqmllanguage/data/lib2/testModule/qmldir
new file mode 100644
index 0000000000..d6a9461666
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/lib2/testModule/qmldir
@@ -0,0 +1 @@
+Test 1.0 Test.qml
diff --git a/tests/auto/qml/qqmllanguage/data/lib3/testModule.1.0/Test.qml b/tests/auto/qml/qqmllanguage/data/lib3/testModule.1.0/Test.qml
new file mode 100644
index 0000000000..2c597ba3e2
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/lib3/testModule.1.0/Test.qml
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+Item {
+ property string test: 'baz'
+}
diff --git a/tests/auto/qml/qqmllanguage/data/lib3/testModule.1.0/qmldir b/tests/auto/qml/qqmllanguage/data/lib3/testModule.1.0/qmldir
new file mode 100644
index 0000000000..d6a9461666
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/lib3/testModule.1.0/qmldir
@@ -0,0 +1 @@
+Test 1.0 Test.qml
diff --git a/tests/auto/qml/qqmllanguage/data/lib3/testModule.1/Test.qml b/tests/auto/qml/qqmllanguage/data/lib3/testModule.1/Test.qml
new file mode 100644
index 0000000000..6feec2ea6b
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/lib3/testModule.1/Test.qml
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+Item {
+ property string test: 'unused'
+}
diff --git a/tests/auto/qml/qqmllanguage/data/lib3/testModule.1/qmldir b/tests/auto/qml/qqmllanguage/data/lib3/testModule.1/qmldir
new file mode 100644
index 0000000000..d6a9461666
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/lib3/testModule.1/qmldir
@@ -0,0 +1 @@
+Test 1.0 Test.qml
diff --git a/tests/auto/qml/qqmllanguage/data/lib4/testModule.1/Test.qml b/tests/auto/qml/qqmllanguage/data/lib4/testModule.1/Test.qml
new file mode 100644
index 0000000000..b6b45ae283
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/lib4/testModule.1/Test.qml
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+Item {
+ property string test: 'qux'
+}
diff --git a/tests/auto/qml/qqmllanguage/data/lib4/testModule.1/qmldir b/tests/auto/qml/qqmllanguage/data/lib4/testModule.1/qmldir
new file mode 100644
index 0000000000..d6a9461666
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/lib4/testModule.1/qmldir
@@ -0,0 +1 @@
+Test 1.0 Test.qml
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
index 689a0769f7..187815688d 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -41,6 +41,7 @@
#include <qtest.h>
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlcomponent.h>
+#include <QtQml/qqmlincubator.h>
#include <QtCore/qcoreapplication.h>
#include <QtCore/qfile.h>
#include <QtCore/qdebug.h>
@@ -146,6 +147,10 @@ private slots:
void importsRemote();
void importsInstalled_data();
void importsInstalled();
+ void importsInstalledRemote_data();
+ void importsInstalledRemote();
+ void importsPath_data();
+ void importsPath();
void importsOrder_data();
void importsOrder();
void importIncorrectCase();
@@ -176,6 +181,8 @@ private slots:
private:
QQmlEngine engine;
+ QStringList defaultImportPathList;
+
void testType(const QString& qml, const QString& type, const QString& error, bool partialMatch = false);
};
@@ -1837,6 +1844,9 @@ void tst_qqmllanguage::reservedWords()
// Check that first child of qml is of given type. Empty type insists on error.
void tst_qqmllanguage::testType(const QString& qml, const QString& type, const QString& expectederror, bool partialMatch)
{
+ if (engine.importPathList() == defaultImportPathList)
+ engine.addImportPath(testFile("lib"));
+
QQmlComponent component(&engine);
component.setData(qml.toUtf8(), testFileUrl("empty.qml")); // just a file for relative local imports
@@ -1858,6 +1868,8 @@ void tst_qqmllanguage::testType(const QString& qml, const QString& type, const Q
QCOMPARE(QString(object->metaObject()->className()), type);
delete object;
}
+
+ engine.setImportPathList(defaultImportPathList);
}
// QTBUG-17276
@@ -2200,6 +2212,102 @@ void tst_qqmllanguage::importsInstalled()
testType(qml,type,error);
}
+void tst_qqmllanguage::importsInstalledRemote_data()
+{
+ // Repeat the tests for local installed data
+ importsInstalled_data();
+}
+
+void tst_qqmllanguage::importsInstalledRemote()
+{
+ QFETCH(QString, qml);
+ QFETCH(QString, type);
+ QFETCH(QString, error);
+
+ TestHTTPServer server(14447);
+ server.serveDirectory(dataDirectory());
+
+ QString serverdir = "http://127.0.0.1:14447/lib/";
+ engine.setImportPathList(QStringList(defaultImportPathList) << serverdir);
+
+ testType(qml,type,error);
+
+ engine.setImportPathList(defaultImportPathList);
+}
+
+void tst_qqmllanguage::importsPath_data()
+{
+ QTest::addColumn<QStringList>("importPath");
+ QTest::addColumn<QString>("qml");
+ QTest::addColumn<QString>("value");
+
+ QTest::newRow("local takes priority normal")
+ << (QStringList() << testFile("lib") << "http://127.0.0.1:14447/lib2/")
+ << "import testModule 1.0\n"
+ "Test {}"
+ << "foo";
+
+ QTest::newRow("local takes priority reversed")
+ << (QStringList() << "http://127.0.0.1:14447/lib/" << testFile("lib2"))
+ << "import testModule 1.0\n"
+ "Test {}"
+ << "bar";
+
+ QTest::newRow("earlier takes priority 1")
+ << (QStringList() << "http://127.0.0.1:14447/lib/" << "http://127.0.0.1:14447/lib2/")
+ << "import testModule 1.0\n"
+ "Test {}"
+ << "foo";
+
+ QTest::newRow("earlier takes priority 2")
+ << (QStringList() << "http://127.0.0.1:14447/lib2/" << "http://127.0.0.1:14447/lib/")
+ << "import testModule 1.0\n"
+ "Test {}"
+ << "bar";
+
+ QTest::newRow("major version takes priority over unversioned")
+ << (QStringList() << "http://127.0.0.1:14447/lib/" << "http://127.0.0.1:14447/lib3/")
+ << "import testModule 1.0\n"
+ "Test {}"
+ << "baz";
+
+ QTest::newRow("major version takes priority over minor")
+ << (QStringList() << "http://127.0.0.1:14447/lib4/" << "http://127.0.0.1:14447/lib3/")
+ << "import testModule 1.0\n"
+ "Test {}"
+ << "baz";
+
+ QTest::newRow("minor version takes priority over unversioned")
+ << (QStringList() << "http://127.0.0.1:14447/lib/" << "http://127.0.0.1:14447/lib4/")
+ << "import testModule 1.0\n"
+ "Test {}"
+ << "qux";
+}
+
+void tst_qqmllanguage::importsPath()
+{
+ QFETCH(QStringList, importPath);
+ QFETCH(QString, qml);
+ QFETCH(QString, value);
+
+ TestHTTPServer server(14447);
+ server.serveDirectory(dataDirectory());
+
+ engine.setImportPathList(QStringList(defaultImportPathList) << importPath);
+
+ QQmlComponent component(&engine);
+ component.setData(qml.toUtf8(), testFileUrl("empty.qml"));
+
+ QTRY_VERIFY(component.isReady());
+ VERIFY_ERRORS(0);
+
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QCOMPARE(object->property("test").toString(), value);
+ delete object;
+
+ engine.setImportPathList(defaultImportPathList);
+}
void tst_qqmllanguage::importsOrder_data()
{
@@ -2298,6 +2406,9 @@ void tst_qqmllanguage::importsOrder()
void tst_qqmllanguage::importIncorrectCase()
{
+ if (engine.importPathList() == defaultImportPathList)
+ engine.addImportPath(testFile("lib"));
+
QQmlComponent component(&engine, testFileUrl("importIncorrectCase.qml"));
QList<QQmlError> errors = component.errors();
@@ -2310,6 +2421,8 @@ void tst_qqmllanguage::importIncorrectCase()
#endif
QCOMPARE(errors.at(0).description(), expectedError);
+
+ engine.setImportPathList(defaultImportPathList);
}
void tst_qqmllanguage::importJs_data()
@@ -2375,6 +2488,7 @@ void tst_qqmllanguage::importJs()
QFETCH(QString, errorFile);
QFETCH(bool, performTest);
+ engine.setImportPathList(QStringList(defaultImportPathList) << testFile("lib"));
QQmlComponent component(&engine, testFileUrl(file));
@@ -2394,6 +2508,8 @@ void tst_qqmllanguage::importJs()
QCOMPARE(object->property("test").toBool(),true);
delete object;
}
+
+ engine.setImportPathList(defaultImportPathList);
}
void tst_qqmllanguage::qmlAttachedPropertiesObjectMethod()
@@ -2576,8 +2692,9 @@ void tst_qqmllanguage::initTestCase()
QQmlDataTest::initTestCase();
QVERIFY2(QDir::setCurrent(dataDirectory()), qPrintable("Could not chdir to " + dataDirectory()));
+ defaultImportPathList = engine.importPathList();
+
QQmlMetaType::registerCustomStringConverter(qMetaTypeId<MyCustomVariantType>(), myCustomVariantTypeConverter);
- engine.addImportPath(testFile("lib"));
registerTypes();