diff options
Diffstat (limited to 'tests/webchannel/tst_webchannel.cpp')
-rw-r--r-- | tests/webchannel/tst_webchannel.cpp | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/tests/webchannel/tst_webchannel.cpp b/tests/webchannel/tst_webchannel.cpp index c1f23d1..e997bd7 100644 --- a/tests/webchannel/tst_webchannel.cpp +++ b/tests/webchannel/tst_webchannel.cpp @@ -44,6 +44,7 @@ #include <qwebchannel.h> #include <qmetaobjectpublisher.h> +#include <qmetaobjectpublisher_p.h> #include <QtTest> @@ -145,4 +146,99 @@ void TestWebChannel::testInfoForObject() } } +static QVariantMap createObjects(QObject *parent) +{ + const int num = 100; + QVariantMap objects; + for (int i = 0; i < num; ++i) { + objects[QStringLiteral("obj%1").arg(i)] = QVariant::fromValue(new BenchObject(parent)); + } + return objects; +} + +void TestWebChannel::benchClassInfo() +{ + QWebChannel channel; + QSignalSpy initSpy(&channel, SIGNAL(initialized())); + QVERIFY(initSpy.wait()); + + QMetaObjectPublisher publisher; + publisher.setWebChannel(&channel); + + QObject parent; + const QVariantMap objects = createObjects(&parent); + + QBENCHMARK { + publisher.classInfoForObjects(objects); + } +} + +void TestWebChannel::benchInitializeClients() +{ + QWebChannel channel; + QSignalSpy initSpy(&channel, SIGNAL(initialized())); + QVERIFY(initSpy.wait()); + + QMetaObjectPublisher publisher; + publisher.setWebChannel(&channel); + + QObject parent; + const QVariantMap objects = createObjects(&parent); + publisher.registerObjects(objects); + + QBENCHMARK { + publisher.d->initializeClients(); + + publisher.d->propertyUpdatesInitialized = false; + publisher.d->signalToPropertyMap.clear(); + publisher.d->signalHandler.clear(); + } +} + +void TestWebChannel::benchPropertyUpdates() +{ + QWebChannel channel; + QSignalSpy initSpy(&channel, SIGNAL(initialized())); + QVERIFY(initSpy.wait()); + + QMetaObjectPublisher publisher; + publisher.setWebChannel(&channel); + + QObject parent; + const QVariantMap objects = createObjects(&parent); + QVector<BenchObject*> objectList; + foreach (const QVariant &var, objects) { + objectList << var.value<BenchObject*>(); + } + + publisher.registerObjects(objects); + publisher.d->initializeClients(); + + QBENCHMARK { + foreach (BenchObject *obj, objectList) { + obj->change(); + } + + publisher.d->clientIsIdle = true; + publisher.d->sendPendingPropertyUpdates(); + } +} + +void TestWebChannel::benchRegisterObjects() +{ + QWebChannel channel; + QSignalSpy initSpy(&channel, SIGNAL(initialized())); + QVERIFY(initSpy.wait()); + + QMetaObjectPublisher publisher; + publisher.setWebChannel(&channel); + + QObject parent; + const QVariantMap objects = createObjects(&parent); + + QBENCHMARK { + publisher.registerObjects(objects); + } +} + QTEST_MAIN(TestWebChannel) |