summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2010-05-26 04:47:11 (GMT)
committerBea Lam <bea.lam@nokia.com>2010-05-26 07:29:29 (GMT)
commitdc9602f6bb805751beb3b7963398679d12753e53 (patch)
treef9827376ec7f8c971795f5822a59d8ce0d7e0653 /tests/auto
parentb930d1a26b0c5999c205f224d75d7de6fa40699c (diff)
downloadQt-dc9602f6bb805751beb3b7963398679d12753e53.zip
Qt-dc9602f6bb805751beb3b7963398679d12753e53.tar.gz
Qt-dc9602f6bb805751beb3b7963398679d12753e53.tar.bz2
Allow js files with '.pragma library' to be used from WorkerScript
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/declarative/qdeclarativeworkerscript/data/BaseWorker.qml24
-rw-r--r--tests/auto/declarative/qdeclarativeworkerscript/data/script.js1
-rw-r--r--tests/auto/declarative/qdeclarativeworkerscript/data/script_fixed_return.js4
-rw-r--r--tests/auto/declarative/qdeclarativeworkerscript/data/script_pragma.js6
-rw-r--r--tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml21
-rw-r--r--tests/auto/declarative/qdeclarativeworkerscript/data/worker_pragma.qml6
-rw-r--r--tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp43
7 files changed, 76 insertions, 29 deletions
diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/BaseWorker.qml b/tests/auto/declarative/qdeclarativeworkerscript/data/BaseWorker.qml
new file mode 100644
index 0000000..d275ca8
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeworkerscript/data/BaseWorker.qml
@@ -0,0 +1,24 @@
+import Qt 4.7
+
+WorkerScript {
+ id: worker
+
+ property variant response
+
+ signal done()
+
+ function testSend(value) {
+ worker.sendMessage(value)
+ }
+
+ function compareLiteralResponse(expected) {
+ var e = eval('(' + expected + ')')
+ return worker.response == e
+ }
+
+ onMessage: {
+ worker.response = messageObject
+ worker.done()
+ }
+}
+
diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/script.js b/tests/auto/declarative/qdeclarativeworkerscript/data/script.js
index 09199de..90aae26 100644
--- a/tests/auto/declarative/qdeclarativeworkerscript/data/script.js
+++ b/tests/auto/declarative/qdeclarativeworkerscript/data/script.js
@@ -2,4 +2,3 @@ WorkerScript.onMessage = function(msg) {
WorkerScript.sendMessage(msg)
}
-
diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/script_fixed_return.js b/tests/auto/declarative/qdeclarativeworkerscript/data/script_fixed_return.js
new file mode 100644
index 0000000..14f6f17
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeworkerscript/data/script_fixed_return.js
@@ -0,0 +1,4 @@
+WorkerScript.onMessage = function(msg) {
+ WorkerScript.sendMessage('Hello_World')
+}
+
diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/script_pragma.js b/tests/auto/declarative/qdeclarativeworkerscript/data/script_pragma.js
new file mode 100644
index 0000000..cb3b6d3
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeworkerscript/data/script_pragma.js
@@ -0,0 +1,6 @@
+.pragma library
+
+WorkerScript.onMessage = function(msg) {
+ WorkerScript.sendMessage(msg)
+}
+
diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml b/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml
index 5c7a5ff..1a20098 100644
--- a/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml
+++ b/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml
@@ -1,24 +1,5 @@
import Qt 4.7
-WorkerScript {
- id: worker
+BaseWorker {
source: "script.js"
-
- property variant response
-
- signal done()
-
- function testSend(value) {
- worker.sendMessage(value)
- }
-
- function compareLiteralResponse(expected) {
- var e = eval('(' + expected + ')')
- return worker.response == e
- }
-
- onMessage: {
- worker.response = messageObject
- worker.done()
- }
}
diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/worker_pragma.qml b/tests/auto/declarative/qdeclarativeworkerscript/data/worker_pragma.qml
new file mode 100644
index 0000000..3b720ef
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeworkerscript/data/worker_pragma.qml
@@ -0,0 +1,6 @@
+import Qt 4.7
+
+BaseWorker {
+ source: "script_pragma.js"
+}
+
diff --git a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp
index a1dae24..7a4315a 100644
--- a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp
+++ b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp
@@ -64,6 +64,7 @@ private slots:
void messaging_data();
void messaging_sendQObjectList();
void messaging_sendJsObject();
+ void script_with_pragma();
private:
void waitForEchoMessage(QDeclarativeWorkerScript *worker) {
@@ -82,18 +83,25 @@ private:
void tst_QDeclarativeWorkerScript::source()
{
- QUrl source = QUrl::fromLocalFile(SRCDIR "/data/worker.qml");
-
- QDeclarativeComponent component(&m_engine);
- component.setData("import Qt 4.7\nWorkerScript { source: '" + source.toString().toUtf8() + "'; }", QUrl());
+ QDeclarativeComponent component(&m_engine, SRCDIR "/data/worker.qml");
+ QDeclarativeWorkerScript *worker = qobject_cast<QDeclarativeWorkerScript*>(component.create());
+ QVERIFY(worker != 0);
+ const QMetaObject *mo = worker->metaObject();
- QDeclarativeWorkerScript *item = qobject_cast<QDeclarativeWorkerScript*>(component.create());
- QVERIFY(item != 0);
+ QVariant value(100);
+ QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value)));
+ waitForEchoMessage(worker);
+ QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).value<QVariant>(), value);
- QCOMPARE(item->source(), source);
+ QUrl source = QUrl::fromLocalFile(SRCDIR "/data/script_fixed_return.js");
+ worker->setSource(source);
+ QCOMPARE(worker->source(), source);
+ QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value)));
+ waitForEchoMessage(worker);
+ QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).value<QVariant>(), qVariantFromValue(QString("Hello_World")));
qApp->processEvents();
- delete item;
+ delete worker;
}
void tst_QDeclarativeWorkerScript::messaging()
@@ -177,6 +185,25 @@ void tst_QDeclarativeWorkerScript::messaging_sendJsObject()
delete worker;
}
+void tst_QDeclarativeWorkerScript::script_with_pragma()
+{
+ QVariant value(100);
+
+ QDeclarativeComponent component(&m_engine, SRCDIR "/data/worker_pragma.qml");
+ QDeclarativeWorkerScript *worker = qobject_cast<QDeclarativeWorkerScript*>(component.create());
+ QVERIFY(worker != 0);
+
+ QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value)));
+ waitForEchoMessage(worker);
+
+ const QMetaObject *mo = worker->metaObject();
+ QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).value<QVariant>(), value);
+
+ qApp->processEvents();
+ delete worker;
+}
+
+
QTEST_MAIN(tst_QDeclarativeWorkerScript)
#include "tst_qdeclarativeworkerscript.moc"