QSslSocket autotest: fix failing tests
[qt-netbsd.git] / tests / auto / qdbusperformance / tst_qdbusperformance.cpp
blob60a1326ee116caa7502ddd7878c1cfc2f61f96df
1 /****************************************************************************
2 **
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: Nokia Corporation (qt-info@nokia.com)
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** No Commercial Usage
10 ** This file contains pre-release code and may not be distributed.
11 ** You may use this file in accordance with the terms and conditions
12 ** contained in the Technology Preview License Agreement accompanying
13 ** this package.
15 ** GNU Lesser General Public License Usage
16 ** Alternatively, this file may be used under the terms of the GNU Lesser
17 ** General Public License version 2.1 as published by the Free Software
18 ** Foundation and appearing in the file LICENSE.LGPL included in the
19 ** packaging of this file. Please review the following information to
20 ** ensure the GNU Lesser General Public License version 2.1 requirements
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 ** In addition, as a special exception, Nokia gives you certain
24 ** additional rights. These rights are described in the Nokia Qt LGPL
25 ** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this
26 ** package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
41 #include <QtCore/QtCore>
42 #include <QtTest/QtTest>
43 #include <QtDBus/QtDBus>
45 #include "./serverobject.h"
47 static const char serviceName[] = "com.trolltech.autotests.performance";
48 static const int runTime = 500;
50 class tst_QDBusPerformance: public QObject
52 Q_OBJECT
53 QProcess proc;
54 QDBusInterface *target;
56 QDBusInterface *remote;
57 QDBusInterface *local;
59 bool executeTest(const char *funcname, int size, const QVariant &data);
61 public slots:
62 void initTestCase_data();
63 void initTestCase();
64 void init();
66 private slots:
67 void callSpeed();
69 void oneWay_data();
70 void oneWay();
71 void oneWayVariant_data();
72 void oneWayVariant();
74 void roundTrip_data();
75 void roundTrip();
76 void roundTripVariant_data();
77 void roundTripVariant();
79 Q_DECLARE_METATYPE(QVariant)
81 void tst_QDBusPerformance::initTestCase()
83 #ifdef Q_OS_WIN
84 proc.start("server");
85 #else
86 proc.start("./server/server");
87 #endif
88 QVERIFY(proc.waitForStarted());
90 QDBusConnection con = QDBusConnection::sessionBus();
91 QVERIFY(con.isConnected());
93 connect(con.interface(), SIGNAL(serviceOwnerChanged(QString,QString,QString)),
94 &QTestEventLoop::instance(), SLOT(exitLoop()));
95 QTime timer;
96 timer.start();
98 while (timer.elapsed() < 5000) {
99 QTestEventLoop::instance().enterLoop(5);
100 if (con.interface()->isServiceRegistered(serviceName))
101 break;
103 QVERIFY(con.interface()->isServiceRegistered(serviceName));
105 remote = new QDBusInterface(serviceName, "/", "com.trolltech.autotests.Performance", con, this);
106 QVERIFY(remote->isValid());
108 new ServerObject("/", con, this);
109 local = new QDBusInterface(con.baseService(), "/", "com.trolltech.autotests.Performance", con, this);
110 QVERIFY(local->isValid());
113 void tst_QDBusPerformance::initTestCase_data()
115 QTest::addColumn<bool>("loopback");
117 QTest::newRow("normal") << false;
118 QTest::newRow("loopback") << true;
121 void tst_QDBusPerformance::init()
123 QFETCH_GLOBAL(bool, loopback);
124 if (loopback)
125 target = local;
126 else
127 target = remote;
130 void tst_QDBusPerformance::callSpeed()
132 QTime timer;
134 int callCount = 0;
135 timer.start();
136 while (timer.elapsed() < runTime) {
137 QDBusReply<void> reply = target->call("nothing");
138 QVERIFY(reply.isValid());
140 ++callCount;
142 qDebug() << callCount << "calls in" << timer.elapsed() << "ms:"
143 << (callCount * 1000.0 / timer.elapsed()) << "calls/sec";
146 bool tst_QDBusPerformance::executeTest(const char *funcname, int size, const QVariant &data)
148 QTime timer;
150 int callCount = 0;
151 qint64 transferred = 0;
152 timer.start();
153 while (timer.elapsed() < runTime) {
154 QDBusMessage reply = target->call(funcname, data);
155 if (reply.type() != QDBusMessage::ReplyMessage)
156 return false;
158 transferred += size;
159 ++callCount;
161 qDebug() << transferred << "bytes in" << timer.elapsed() << "ms"
162 << "(in" << callCount << "calls):"
163 << (transferred * 1000.0 / timer.elapsed() / 1024 / 1024) << "MB/s";
165 return true;
168 void tst_QDBusPerformance::oneWay_data()
170 QTest::addColumn<QVariant>("data");
171 QTest::addColumn<int>("size");
173 QByteArray ba(256, 'a');
174 while (ba.size() < 8193) {
175 QTest::newRow(QString("%1-byteArray").arg(ba.size()).toAscii()) << qVariantFromValue(ba) << ba.size();
176 ba += ba;
179 QString s(256, QLatin1Char('a'));
180 while (s.size() < 8193) {
181 QTest::newRow(QString("%1-string").arg(s.size()).toAscii()) << qVariantFromValue(s) << s.size();
182 s += s;
186 void tst_QDBusPerformance::oneWay()
188 QFETCH(QVariant, data);
189 QFETCH(int, size);
191 QVERIFY(executeTest("size", size, data));
194 void tst_QDBusPerformance::oneWayVariant_data()
196 oneWay_data();
199 void tst_QDBusPerformance::oneWayVariant()
201 QFETCH(QVariant, data);
202 QFETCH(int, size);
204 QVERIFY(executeTest("size", size, qVariantFromValue(QDBusVariant(data))));
207 void tst_QDBusPerformance::roundTrip_data()
209 oneWay_data();
212 void tst_QDBusPerformance::roundTrip()
214 QFETCH(QVariant, data);
215 QFETCH(int, size);
217 QVERIFY(executeTest("echo", size, data));
220 void tst_QDBusPerformance::roundTripVariant_data()
222 oneWay_data();
225 void tst_QDBusPerformance::roundTripVariant()
227 QFETCH(QVariant, data);
228 QFETCH(int, size);
230 QVERIFY(executeTest("echo", size, qVariantFromValue(QDBusVariant(data))));
233 QTEST_MAIN(tst_QDBusPerformance)
234 #include "tst_qdbusperformance.moc"