summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2013-12-28 19:20:58 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-08 15:59:28 +0100
commit66c0d916131c1e9e896705971f20385c75e753a2 (patch)
tree59b25cd7b9bc1ff688ff46c2b4f4c21fa60019cf /tests
parent318576f0cc0ebef78c5b27106b1a8429eb54fac8 (diff)
downloadqtwebchannel-66c0d916131c1e9e896705971f20385c75e753a2.tar.gz
Simplify usage of QWebChannel on the server side.
This is achieved by hiding the MetaObjectPublisher completely as private API. The QWebChannel is the only publisher API and now handles both the socket as well as the publisher internally. This now allows us to create a proper QML api in the new QmlWebChannel. Change-Id: I3096364af8485353ca9bc19df4a81a8e4552c3d7 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/qml/tst_bench.qml14
-rw-r--r--tests/qml/tst_metaobjectpublisher.qml21
-rw-r--r--tests/webchannel/tst_webchannel.cpp80
3 files changed, 38 insertions, 77 deletions
diff --git a/tests/qml/tst_bench.qml b/tests/qml/tst_bench.qml
index 46eb6be..c6359ce 100644
--- a/tests/qml/tst_bench.qml
+++ b/tests/qml/tst_bench.qml
@@ -75,18 +75,6 @@ WebChannelTest {
}
}
- MetaObjectPublisher {
- id: publisher
- webChannel: test.webChannel
- }
-
- Connections {
- target: test.webChannel
- onRawMessageReceived: {
- publisher.handleRequest(JSON.parse(rawMessage));
- }
- }
-
property var objects: ({})
function initTestCase()
@@ -97,7 +85,7 @@ WebChannelTest {
objects[id] = component.createObject(test, properties);
}
- publisher.registerObjects(objects);
+ webChannel.registerObjects(objects);
}
function benchmark_init_baseline()
diff --git a/tests/qml/tst_metaobjectpublisher.qml b/tests/qml/tst_metaobjectpublisher.qml
index 5e1e825..cc679ad 100644
--- a/tests/qml/tst_metaobjectpublisher.qml
+++ b/tests/qml/tst_metaobjectpublisher.qml
@@ -78,26 +78,9 @@ WebChannelTest {
}
}
- MetaObjectPublisher {
- id: publisher
- webChannel: test.webChannel
- }
-
- 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);
- }
- }
- }
-
function initTestCase()
{
- publisher.registerObjects({
+ webChannel.registerObjects({
"myObj": myObj,
"myOtherObj": myOtherObj,
"myFactory": myFactory
@@ -119,7 +102,7 @@ WebChannelTest {
verify(msg);
verify(msg.data);
compare(msg.data.type, "Qt.idle");
- verify(publisher.test_clientIsIdle())
+ verify(webChannel.test_clientIsIdle())
}
function awaitMessageSkipIdle()
diff --git a/tests/webchannel/tst_webchannel.cpp b/tests/webchannel/tst_webchannel.cpp
index 3b90744..7fbe5f9 100644
--- a/tests/webchannel/tst_webchannel.cpp
+++ b/tests/webchannel/tst_webchannel.cpp
@@ -43,7 +43,7 @@
#include "tst_webchannel.h"
#include <qwebchannel.h>
-#include <qmetaobjectpublisher.h>
+#include <qwebchannel_p.h>
#include <qmetaobjectpublisher_p.h>
#include <QtTest>
@@ -58,7 +58,7 @@ TestWebChannel::~TestWebChannel()
}
- void TestWebChannel::testInitChannel()
+void TestWebChannel::testInitChannel()
{
QWebChannel channel;
@@ -76,26 +76,24 @@ TestWebChannel::~TestWebChannel()
void TestWebChannel::testRegisterObjects()
{
QWebChannel channel;
- QMetaObjectPublisher publisher;
- publisher.setWebChannel(&channel);
-
QObject plain;
- QVariantMap objects;
- objects["plain"] = QVariant::fromValue(&plain);
- objects["channel"] = QVariant::fromValue(&channel);
- objects["publisher"] = QVariant::fromValue(&publisher);
- objects["test"] = QVariant::fromValue(this);
+ QHash<QString, QObject*> objects;
+ objects[QStringLiteral("plain")] = &plain;
+ objects[QStringLiteral("channel")] = &channel;
+ objects[QStringLiteral("publisher")] = channel.d->publisher;
+ objects[QStringLiteral("test")] = this;
- publisher.registerObjects(objects);
+ channel.registerObjects(objects);
}
void TestWebChannel::testInfoForObject()
{
TestObject obj;
obj.setObjectName("myTestObject");
- QMetaObjectPublisher publisher;
- const QJsonObject info = publisher.classInfoForObject(&obj);
+
+ QWebChannel channel;
+ const QJsonObject info = channel.d->publisher->classInfoForObject(&obj);
QCOMPARE(info.keys(), QStringList() << "enums" << "methods" << "properties" << "signals");
@@ -216,12 +214,13 @@ void TestWebChannel::testInfoForObject()
}
}
-static QVariantMap createObjects(QObject *parent)
+static QHash<QString, QObject*> createObjects(QObject *parent)
{
const int num = 100;
- QVariantMap objects;
+ QHash<QString, QObject*> objects;
+ objects.reserve(num);
for (int i = 0; i < num; ++i) {
- objects[QStringLiteral("obj%1").arg(i)] = QVariant::fromValue(new BenchObject(parent));
+ objects[QStringLiteral("obj%1").arg(i)] = new BenchObject(parent);
}
return objects;
}
@@ -232,14 +231,13 @@ void TestWebChannel::benchClassInfo()
QSignalSpy initSpy(&channel, SIGNAL(initialized()));
QVERIFY(initSpy.wait());
- QMetaObjectPublisher publisher;
- publisher.setWebChannel(&channel);
-
QObject parent;
- const QVariantMap objects = createObjects(&parent);
+ const QHash<QString, QObject*> objects = createObjects(&parent);
QBENCHMARK {
- publisher.classInfoForObjects(objects);
+ foreach (const QObject *object, objects) {
+ channel.d->publisher->classInfoForObject(object);
+ }
}
}
@@ -249,19 +247,16 @@ void TestWebChannel::benchInitializeClients()
QSignalSpy initSpy(&channel, SIGNAL(initialized()));
QVERIFY(initSpy.wait());
- QMetaObjectPublisher publisher;
- publisher.setWebChannel(&channel);
-
QObject parent;
- const QVariantMap objects = createObjects(&parent);
- publisher.registerObjects(objects);
+ channel.registerObjects(createObjects(&parent));
+ QMetaObjectPublisher *publisher = channel.d->publisher;
QBENCHMARK {
- publisher.d->initializeClients();
+ publisher->initializeClients();
- publisher.d->propertyUpdatesInitialized = false;
- publisher.d->signalToPropertyMap.clear();
- publisher.d->signalHandler.clear();
+ publisher->propertyUpdatesInitialized = false;
+ publisher->signalToPropertyMap.clear();
+ publisher->signalHandler.clear();
}
}
@@ -271,26 +266,24 @@ void TestWebChannel::benchPropertyUpdates()
QSignalSpy initSpy(&channel, SIGNAL(initialized()));
QVERIFY(initSpy.wait());
- QMetaObjectPublisher publisher;
- publisher.setWebChannel(&channel);
-
QObject parent;
- const QVariantMap objects = createObjects(&parent);
+ const QHash<QString, QObject*> objects = createObjects(&parent);
QVector<BenchObject*> objectList;
- foreach (const QVariant &var, objects) {
- objectList << var.value<BenchObject*>();
+ objectList.reserve(objects.size());
+ foreach (QObject *obj, objects) {
+ objectList << qobject_cast<BenchObject*>(obj);
}
- publisher.registerObjects(objects);
- publisher.d->initializeClients();
+ channel.registerObjects(objects);
+ channel.d->publisher->initializeClients();
QBENCHMARK {
foreach (BenchObject *obj, objectList) {
obj->change();
}
- publisher.d->clientIsIdle = true;
- publisher.d->sendPendingPropertyUpdates();
+ channel.d->publisher->clientIsIdle = true;
+ channel.d->publisher->sendPendingPropertyUpdates();
}
}
@@ -300,14 +293,11 @@ void TestWebChannel::benchRegisterObjects()
QSignalSpy initSpy(&channel, SIGNAL(initialized()));
QVERIFY(initSpy.wait());
- QMetaObjectPublisher publisher;
- publisher.setWebChannel(&channel);
-
QObject parent;
- const QVariantMap objects = createObjects(&parent);
+ const QHash<QString, QObject*> objects = createObjects(&parent);
QBENCHMARK {
- publisher.registerObjects(objects);
+ channel.registerObjects(objects);
}
}