summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2013-11-21 13:11:03 +0100
committerMilian Wolff <milian.wolff@kdab.com>2013-12-11 13:08:40 +0100
commitacf7f0b1ae956f2fac7182c194e0441cd9c6f4d0 (patch)
tree21420faece9a6c1eca68727c916660c9a286c912 /tests
parentb6158dc3525c1c906d4040b2e88cd20feb21a2b2 (diff)
downloadqtwebchannel-acf7f0b1ae956f2fac7182c194e0441cd9c6f4d0.tar.gz
Port the MetaObjectPublisher to C++.
This will allow us to create a stand-alone WebChannel C++ library, without any QML dependencies, that can be used to publisher QObjects to remote clients running in any browser engine supporting WebSockets. The patch is large, as working with introspection through the QMetaObject from C++ is more complicated compared to QML. On the other hand, the move to C++ allows a much more performant implementation of quite some parts of the publisher. One thing is that signal and method invocations can be handled via numeric indices, where before we needed to transmit the string identifier of the signal or method. Eventually this can now also be applied to properties, further decreasing the size of messages between server and clients. Note that this patch contains quite some TODOs and rough edges, such as the invokable bench_* helper functions in the public API of the MetaObjectPublisher. These are to be seen as temporary, and will be cleaned up in followup commits later. This is done to prevent a further blow-up of this already big patch. Change-Id: I57e788d8a19edd410651611382d912f9ad6660c9 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/qml/tst_bench.qml28
-rw-r--r--tests/qml/tst_metaobjectpublisher.qml74
-rw-r--r--tests/qml/wrapper.html1
3 files changed, 46 insertions, 57 deletions
diff --git a/tests/qml/tst_bench.qml b/tests/qml/tst_bench.qml
index 729aca9..c7c7c7c 100644
--- a/tests/qml/tst_bench.qml
+++ b/tests/qml/tst_bench.qml
@@ -78,12 +78,12 @@ WebChannelTest {
MetaObjectPublisher {
id: publisher
webChannel: test.webChannel
+ }
- Connections {
- target: webChannel
- onRawMessageReceived: {
- publisher.handleRequest(JSON.parse(rawMessage));
- }
+ Connections {
+ target: test.webChannel
+ onRawMessageReceived: {
+ publisher.handleRequest(JSON.parse(rawMessage));
}
}
@@ -107,19 +107,13 @@ WebChannelTest {
function benchmark_initializeClients()
{
- publisher.propertyUpdatesInitialized = false;
- publisher.signalToPropertyMap = {}
- publisher.subscriberCountMap = {}
-
- publisher.initializeClients()
+ publisher.bench_initializeClients();
}
function benchmark_propertyUpdates()
{
- if (!publisher.propertyUpdatesInitialized) {
- // required to make the benchmark work standalone
- publisher.initializeClients()
- }
+ // required to make the benchmark work standalone
+ publisher.bench_ensureUpdatesInitialized();
for (var o in objects) {
objects[o].p0++;
@@ -133,14 +127,12 @@ WebChannelTest {
objects[o].p8++;
objects[o].p9++;
}
- publisher.clientIsIdle = true
- publisher.sendPendingPropertyUpdates()
+ publisher.bench_sendPendingPropertyUpdates();
}
function benchmark_registerObjects()
{
- publisher.propertyUpdatesInitialized = false;
- publisher.registerObjects(objects);
+ publisher.bench_registerObjects(objects);
}
function benchmark_init_baseline()
diff --git a/tests/qml/tst_metaobjectpublisher.qml b/tests/qml/tst_metaobjectpublisher.qml
index 4754c3d..6cb01e6 100644
--- a/tests/qml/tst_metaobjectpublisher.qml
+++ b/tests/qml/tst_metaobjectpublisher.qml
@@ -59,9 +59,11 @@ WebChannelTest {
}
QtObject {
id: myFactory
+ property var lastObj
function create(id)
{
- return component.createObject(myFactory, {objectName: id});
+ lastObj = component.createObject(myFactory, {objectName: id});
+ return lastObj;
}
}
@@ -79,16 +81,16 @@ WebChannelTest {
MetaObjectPublisher {
id: publisher
webChannel: test.webChannel
+ }
- Connections {
- target: webChannel
- onRawMessageReceived: {
- var message = JSON.parse(rawMessage);
- verify(message);
- var handled = publisher.handleRequest(message);
- if (message.data && message.data.type) {
- verify(handled);
- }
+ Connections {
+ target: test.webChannel
+ onRawMessageReceived: {
+ var message = JSON.parse(rawMessage);
+ verify(message);
+ var handled = publisher.handleRequest(message);
+ if (message.data && message.data.type) {
+ verify(handled);
}
}
}
@@ -117,7 +119,18 @@ WebChannelTest {
verify(msg);
verify(msg.data);
compare(msg.data.type, "Qt.idle");
- verify(publisher.clientIsIdle)
+ verify(publisher.test_clientIsIdle())
+ }
+
+ function awaitMessageSkipIdle()
+ {
+ var msg;
+ do {
+ msg = awaitMessage();
+ verify(msg);
+ verify(msg.data);
+ } while (msg.data.type === "Qt.idle");
+ return msg;
}
function test_property()
@@ -178,7 +191,6 @@ WebChannelTest {
var msg = awaitMessage();
compare(msg.data.type, "Qt.connectToSignal");
compare(msg.data.object, "myObj");
- compare(msg.data.signal, "mySignal");
awaitIdle();
@@ -215,54 +227,45 @@ WebChannelTest {
loadUrl("wrapper.html");
awaitInit();
- var msg = awaitMessage();
+ var msg = awaitMessageSkipIdle();
compare(msg.data.type, "Qt.invokeMethod");
compare(msg.data.object, "myFactory");
- compare(msg.data.method, "create");
+ verify(myFactory.lastObj);
+ compare(myFactory.lastObj.objectName, "testObj");
- awaitIdle();
-
- msg = awaitMessage();
+ msg = awaitMessageSkipIdle();
compare(msg.data.type, "Qt.connectToSignal");
- compare(msg.data.signal, "destroyed");
verify(msg.data.object);
var objId = msg.data.object;
- var obj = publisher.unwrapObject(objId);
- verify(obj);
- compare(obj.objectName, "testObj");
- msg = awaitMessage();
+ msg = awaitMessageSkipIdle();
compare(msg.data.type, "Qt.connectToSignal");
compare(msg.data.object, objId);
- compare(msg.data.signal, "mySignal");
- msg = awaitMessage();
+ msg = awaitMessageSkipIdle();
compare(msg.data.type, "Qt.setProperty");
compare(msg.data.object, objId);
- compare(obj.myProperty, 42);
+ compare(myFactory.lastObj.myProperty, 42);
- msg = awaitMessage();
+ msg = awaitMessageSkipIdle();
compare(msg.data.type, "Qt.invokeMethod");
compare(msg.data.object, objId);
- compare(msg.data.method, "myMethod");
compare(msg.data.args, ["foobar"]);
- msg = awaitMessage();
+ msg = awaitMessageSkipIdle();
compare(msg.data.label, "signalReceived");
compare(msg.data.args, ["foobar", 42]);
// pass QObject* on the fly and trigger deleteLater from client side
webChannel.sendMessage("triggerDelete");
- awaitIdle();
- msg = awaitMessage();
+ msg = awaitMessageSkipIdle();
compare(msg.data.type, "Qt.invokeMethod");
compare(msg.data.object, objId);
- compare(msg.data.method, "deleteLater");
- verify(!publisher.unwrapObject(objId));
webChannel.sendMessage("report");
- msg = awaitMessage();
+
+ msg = awaitMessageSkipIdle();
compare(msg.data.label, "report");
compare(msg.data.obj, {});
}
@@ -274,9 +277,7 @@ WebChannelTest {
var msg = awaitMessage();
compare(msg.data.type, "Qt.connectToSignal");
- compare(msg.data.signal, "mySignal");
compare(msg.data.object, "myObj");
- verify(publisher.subscriberCountMap["myObj"].hasOwnProperty("mySignal"));
awaitIdle();
@@ -289,9 +290,6 @@ WebChannelTest {
msg = awaitMessage();
compare(msg.data.type, "Qt.disconnectFromSignal");
compare(msg.data.object, "myObj");
- compare(msg.data.signal, "mySignal");
-
- verify(!publisher.subscriberCountMap["myObj"].hasOwnProperty("mySignal"));
myObj.mySignal(0);
diff --git a/tests/qml/wrapper.html b/tests/qml/wrapper.html
index a6c313b..54f456b 100644
--- a/tests/qml/wrapper.html
+++ b/tests/qml/wrapper.html
@@ -16,7 +16,6 @@
obj.myMethod("foobar");
});
channel.subscribe("triggerDelete", function() {
- console.log(testObj);
testObj.deleteLater();
});
channel.subscribe("report", function() {