aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2018-01-22 16:46:03 +0100
committerLars Knoll <lars.knoll@qt.io>2018-01-28 16:37:26 +0000
commite5b157275d7b924e1a0f39d27958a7ad1eed9cef (patch)
tree8d08a8a9fb0c79d77449875cc9e62ee6df99b2ea /tests
parente29047555be764d59c52801553e23767ed367cec (diff)
Add support for compiling QML/JS files ahead of time in resources
This is bringing over the loading infrastructure from the Qt Quick Compiler that allows embedding qml/js files in resources and compiling them ahead of time. At the moment, the approach of generating one cpp file per qml/js file and the loader stub is needed because the build system does not support dynamic resource generation. In addition, as per QTBUG-60961, we must ensure that the generated data structures are aligned. To retain compatibility this is enabled via CONFIG += qtquickcompiler, but we may need to find a new name (but should keep the old one in any case). Task-number: QTBUG-60961 Change-Id: Ia9839bf98d3af4c50636b6e06815364a9fc7ee57 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qmlcachegen/qmlcachegen.pro6
-rw-r--r--tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp15
-rw-r--r--tests/auto/qml/qmlcachegen/worker.js3
-rw-r--r--tests/auto/qml/qmlcachegen/worker.qml12
4 files changed, 35 insertions, 1 deletions
diff --git a/tests/auto/qml/qmlcachegen/qmlcachegen.pro b/tests/auto/qml/qmlcachegen/qmlcachegen.pro
index 8d8b37be15..a8b72224ba 100644
--- a/tests/auto/qml/qmlcachegen/qmlcachegen.pro
+++ b/tests/auto/qml/qmlcachegen/qmlcachegen.pro
@@ -1,7 +1,11 @@
-CONFIG += testcase
+CONFIG += testcase qtquickcompiler
TARGET = tst_qmlcachegen
macos:CONFIG -= app_bundle
SOURCES += tst_qmlcachegen.cpp
+workerscripts_test.files = worker.js worker.qml
+workerscripts_test.prefix = /workerscripts
+RESOURCES += workerscripts_test
+
QT += core-private qml-private testlib
diff --git a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
index b20af06746..a7b02f3cca 100644
--- a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
+++ b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
@@ -46,6 +46,8 @@ private slots:
void signalHandlerParameters();
void errorOnArgumentsInSignalHandler();
void aheadOfTimeCompilation();
+
+ void workerScripts();
};
// A wrapper around QQmlComponent to ensure the temporary reference counts
@@ -259,6 +261,19 @@ void tst_qmlcachegen::aheadOfTimeCompilation()
QCOMPARE(result.toInt(), 42);
}
+void tst_qmlcachegen::workerScripts()
+{
+ QVERIFY(QFile::exists(":/workerscripts/worker.js"));
+ QVERIFY(QFile::exists(":/workerscripts/worker.qml"));
+ QCOMPARE(QFileInfo(":/workerscripts/worker.js").size(), 0);
+
+ QQmlEngine engine;
+ CleanlyLoadingComponent component(&engine, QUrl("qrc:///workerscripts/worker.qml"));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY(!obj.isNull());
+ QTRY_VERIFY(obj->property("success").toBool());
+}
+
QTEST_GUILESS_MAIN(tst_qmlcachegen)
#include "tst_qmlcachegen.moc"
diff --git a/tests/auto/qml/qmlcachegen/worker.js b/tests/auto/qml/qmlcachegen/worker.js
new file mode 100644
index 0000000000..dd2d0b843d
--- /dev/null
+++ b/tests/auto/qml/qmlcachegen/worker.js
@@ -0,0 +1,3 @@
+WorkerScript.onMessage = function(message) {
+ WorkerScript.sendMessage({ reply: message });
+}
diff --git a/tests/auto/qml/qmlcachegen/worker.qml b/tests/auto/qml/qmlcachegen/worker.qml
new file mode 100644
index 0000000000..1f1c9d1ac7
--- /dev/null
+++ b/tests/auto/qml/qmlcachegen/worker.qml
@@ -0,0 +1,12 @@
+import QtQml 2.0
+import QtQuick 2.0
+QtObject {
+ property bool success: false
+ property WorkerScript worker: WorkerScript {
+ source: "worker.js"
+ onMessage: {
+ success = true
+ }
+ }
+ Component.onCompleted: worker.sendMessage("Hello")
+}