diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2013-11-21 13:11:03 +0100 |
---|---|---|
committer | Milian Wolff <milian.wolff@kdab.com> | 2013-12-11 13:08:40 +0100 |
commit | acf7f0b1ae956f2fac7182c194e0441cd9c6f4d0 (patch) | |
tree | 21420faece9a6c1eca68727c916660c9a286c912 /tests/qml/tst_metaobjectpublisher.qml | |
parent | b6158dc3525c1c906d4040b2e88cd20feb21a2b2 (diff) | |
download | qtwebchannel-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/qml/tst_metaobjectpublisher.qml')
-rw-r--r-- | tests/qml/tst_metaobjectpublisher.qml | 74 |
1 files changed, 36 insertions, 38 deletions
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); |