summaryrefslogtreecommitdiff
path: root/tests/webchannel
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2013-12-19 16:46:40 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-12-27 15:50:36 +0100
commit25568c9d01e5ace5557c9aebc42d0de3cf2873e4 (patch)
treeab176384dee0c4c8e55dbe9d7e67190e883f597a /tests/webchannel
parent85fb9ea87356d28c2ba05fcb2b2018f6a0a91842 (diff)
downloadqtwebchannel-25568c9d01e5ace5557c9aebc42d0de3cf2873e4.tar.gz
Port MetaObjectPublisher benchmarks to C++.
This allows us to remove the public API for the tests and allows for more tests and benchmarks in the future. To achieve this, we re-use the new qmetaobjectpublisher_p.h, which then also must be exported. Change-Id: I3c33b2f5be6cc674cd3092667151dd8da2263cf5 Reviewed-by: Zeno Albisser <zeno.albisser@digia.com>
Diffstat (limited to 'tests/webchannel')
-rw-r--r--tests/webchannel/tst_webchannel.cpp96
-rw-r--r--tests/webchannel/tst_webchannel.h97
2 files changed, 193 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)
diff --git a/tests/webchannel/tst_webchannel.h b/tests/webchannel/tst_webchannel.h
index 5ea7a45..173921b 100644
--- a/tests/webchannel/tst_webchannel.h
+++ b/tests/webchannel/tst_webchannel.h
@@ -92,6 +92,98 @@ private slots:
void slot4() {}
};
+class BenchObject : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY(int p0 MEMBER m_p0 NOTIFY p0Changed)
+ Q_PROPERTY(int p1 MEMBER m_p1 NOTIFY p1Changed)
+ Q_PROPERTY(int p2 MEMBER m_p2 NOTIFY p2Changed)
+ Q_PROPERTY(int p3 MEMBER m_p3 NOTIFY p3Changed)
+ Q_PROPERTY(int p4 MEMBER m_p4 NOTIFY p4Changed)
+ Q_PROPERTY(int p5 MEMBER m_p5 NOTIFY p5Changed)
+ Q_PROPERTY(int p6 MEMBER m_p6 NOTIFY p6Changed)
+ Q_PROPERTY(int p7 MEMBER m_p7 NOTIFY p7Changed)
+ Q_PROPERTY(int p8 MEMBER m_p8 NOTIFY p8Changed)
+ Q_PROPERTY(int p9 MEMBER m_p9 NOTIFY p9Changed)
+public:
+ explicit BenchObject(QObject *parent = 0)
+ : QObject(parent)
+ , m_p0(0)
+ , m_p1(0)
+ , m_p2(0)
+ , m_p3(0)
+ , m_p4(0)
+ , m_p5(0)
+ , m_p6(0)
+ , m_p7(0)
+ , m_p8(0)
+ , m_p9(0)
+ { }
+
+ void change()
+ {
+ m_p0++;
+ m_p1++;
+ m_p2++;
+ m_p3++;
+ m_p4++;
+ m_p5++;
+ m_p6++;
+ m_p7++;
+ m_p8++;
+ m_p9++;
+ emit p0Changed(m_p0);
+ emit p1Changed(m_p1);
+ emit p2Changed(m_p2);
+ emit p3Changed(m_p3);
+ emit p4Changed(m_p4);
+ emit p5Changed(m_p5);
+ emit p6Changed(m_p6);
+ emit p7Changed(m_p7);
+ emit p8Changed(m_p8);
+ emit p9Changed(m_p9);
+ }
+
+signals:
+ void s0();
+ void s1();
+ void s2();
+ void s3();
+ void s4();
+ void s5();
+ void s6();
+ void s7();
+ void s8();
+ void s9();
+
+ void p0Changed(int);
+ void p1Changed(int);
+ void p2Changed(int);
+ void p3Changed(int);
+ void p4Changed(int);
+ void p5Changed(int);
+ void p6Changed(int);
+ void p7Changed(int);
+ void p8Changed(int);
+ void p9Changed(int);
+
+public slots:
+ void m0(){};
+ void m1(){};
+ void m2(){};
+ void m3(){};
+ void m4(){};
+ void m5(){};
+ void m6(){};
+ void m7(){};
+ void m8(){};
+ void m9(){};
+
+private:
+ int m_p0, m_p1, m_p2, m_p3, m_p4, m_p5, m_p6, m_p7, m_p8, m_p9;
+};
+
class TestWebChannel : public QObject
{
Q_OBJECT
@@ -104,6 +196,11 @@ private slots:
void testInitChannel();
void testRegisterObjects();
void testInfoForObject();
+
+ void benchClassInfo();
+ void benchInitializeClients();
+ void benchPropertyUpdates();
+ void benchRegisterObjects();
};
#endif // TST_WEBCHANNEL_H