author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 |
** All rights reserved. |
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
#include <QtCore/QObject> |
|
42 |
#include <QtCore/QVariant> |
|
43 |
#include <QtCore/QList> |
|
44 |
#include <QtCore/QVector> |
|
45 |
#include <QtTest/QtTest> |
|
46 |
#ifndef QT_NO_DBUS |
|
47 |
#include <QtDBus> |
|
48 |
||
49 |
typedef QMap<int,QString> IntStringMap; |
|
50 |
Q_DECLARE_METATYPE(IntStringMap) |
|
51 |
||
52 |
struct MyStruct |
|
53 |
{ |
|
54 |
int i; |
|
55 |
QString s; |
|
56 |
||
57 |
MyStruct() : i(1), s("String") { } |
|
58 |
bool operator==(const MyStruct &other) const |
|
59 |
{ return i == other.i && s == other.s; } |
|
60 |
}; |
|
61 |
Q_DECLARE_METATYPE(MyStruct) |
|
62 |
||
63 |
QDBusArgument &operator<<(QDBusArgument &arg, const MyStruct &ms) |
|
64 |
{ |
|
65 |
arg.beginStructure(); |
|
66 |
arg << ms.i << ms.s; |
|
67 |
arg.endStructure(); |
|
68 |
return arg; |
|
69 |
} |
|
70 |
||
71 |
const QDBusArgument &operator>>(const QDBusArgument &arg, MyStruct &ms) |
|
72 |
{ |
|
73 |
arg.beginStructure(); |
|
74 |
arg >> ms.i >> ms.s; |
|
75 |
arg.endStructure(); |
|
76 |
return arg; |
|
77 |
} |
|
78 |
||
79 |
class TypesInterface; |
|
80 |
class tst_QDBusPendingReply: public QObject |
|
81 |
{ |
|
82 |
Q_OBJECT |
|
83 |
QDBusInterface *iface; |
|
84 |
TypesInterface *adaptor; |
|
85 |
public: |
|
86 |
tst_QDBusPendingReply(); |
|
87 |
||
88 |
private slots: |
|
89 |
void initTestCase() |
|
90 |
{ |
|
91 |
qDBusRegisterMetaType<IntStringMap>(); |
|
92 |
qDBusRegisterMetaType<MyStruct>(); |
|
93 |
} |
|
94 |
||
95 |
void init(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
96 |
void unconnected(); |
0 | 97 |
void simpleTypes(); |
98 |
void complexTypes(); |
|
99 |
void wrongTypes(); |
|
100 |
void multipleTypes(); |
|
101 |
||
102 |
void synchronousSimpleTypes(); |
|
103 |
||
104 |
void errors(); |
|
105 |
}; |
|
106 |
||
107 |
class TypesInterface: public QDBusAbstractAdaptor |
|
108 |
{ |
|
109 |
Q_OBJECT |
|
110 |
Q_CLASSINFO("D-Bus Interface", "com.trolltech.Qt.Autotests.TypesInterface") |
|
111 |
public: |
|
112 |
TypesInterface(QObject *parent) |
|
113 |
: QDBusAbstractAdaptor(parent) |
|
114 |
{ } |
|
115 |
||
116 |
public slots: |
|
117 |
void retrieveVoid() |
|
118 |
{ } |
|
119 |
||
120 |
bool retrieveBool() |
|
121 |
{ |
|
122 |
return true; |
|
123 |
} |
|
124 |
||
125 |
uchar retrieveUChar() |
|
126 |
{ |
|
127 |
return 'A'; |
|
128 |
} |
|
129 |
||
130 |
short retrieveShort() |
|
131 |
{ |
|
132 |
return -47; |
|
133 |
} |
|
134 |
||
135 |
ushort retrieveUShort() |
|
136 |
{ |
|
137 |
return 42U; |
|
138 |
} |
|
139 |
||
140 |
int retrieveInt() |
|
141 |
{ |
|
142 |
return -470000; |
|
143 |
} |
|
144 |
||
145 |
void retrieveIntInt(int &i1, int &i2) |
|
146 |
{ |
|
147 |
i1 = -424242; |
|
148 |
i2 = 434343; |
|
149 |
} |
|
150 |
||
151 |
uint retrieveUInt() |
|
152 |
{ |
|
153 |
return 42424242; |
|
154 |
} |
|
155 |
||
156 |
qlonglong retrieveLongLong() |
|
157 |
{ |
|
158 |
return -(Q_INT64_C(1) << 32); |
|
159 |
} |
|
160 |
||
161 |
qulonglong retrieveULongLong() |
|
162 |
{ |
|
163 |
return Q_INT64_C(1) << 32; |
|
164 |
} |
|
165 |
||
166 |
double retrieveDouble() |
|
167 |
{ |
|
168 |
return 1.5; |
|
169 |
} |
|
170 |
||
171 |
QString retrieveString() |
|
172 |
{ |
|
173 |
return "This string you should see"; |
|
174 |
} |
|
175 |
||
176 |
QDBusObjectPath retrieveObjectPath() |
|
177 |
{ |
|
178 |
return QDBusObjectPath("/"); |
|
179 |
} |
|
180 |
||
181 |
QDBusSignature retrieveSignature() |
|
182 |
{ |
|
183 |
return QDBusSignature("g"); |
|
184 |
} |
|
185 |
||
186 |
QDBusVariant retrieveVariant() |
|
187 |
{ |
|
188 |
return QDBusVariant(retrieveString()); |
|
189 |
} |
|
190 |
||
191 |
QStringList retrieveStringList() |
|
192 |
{ |
|
193 |
return QStringList() << "one" << "two"; |
|
194 |
} |
|
195 |
||
196 |
QByteArray retrieveByteArray() |
|
197 |
{ |
|
198 |
return "Hello, World"; |
|
199 |
} |
|
200 |
||
201 |
QVariantList retrieveList() |
|
202 |
{ |
|
203 |
return QVariantList() << retrieveInt() << retrieveString() |
|
204 |
<< retrieveByteArray(); |
|
205 |
} |
|
206 |
||
207 |
QVariantMap retrieveMap() |
|
208 |
{ |
|
209 |
QVariantMap map; |
|
210 |
map["one"] = 1; |
|
211 |
map["two"] = 2U; |
|
212 |
map["string"] = retrieveString(); |
|
213 |
map["stringlist"] = retrieveStringList(); |
|
214 |
return map; |
|
215 |
} |
|
216 |
||
217 |
IntStringMap retrieveIntStringMap() |
|
218 |
{ |
|
219 |
IntStringMap map; |
|
220 |
map[1] = "1"; |
|
221 |
map[2] = "2"; |
|
222 |
map[-1231456] = "foo"; |
|
223 |
return map; |
|
224 |
} |
|
225 |
||
226 |
MyStruct retrieveStruct() |
|
227 |
{ |
|
228 |
return MyStruct(); |
|
229 |
} |
|
230 |
||
231 |
void sendError(const QDBusMessage &msg) |
|
232 |
{ |
|
233 |
msg.setDelayedReply(true); |
|
234 |
QDBusConnection::sessionBus() |
|
235 |
.send(msg.createErrorReply("local.AnErrorName", "You've got an error!")); |
|
236 |
} |
|
237 |
}; |
|
238 |
||
239 |
tst_QDBusPendingReply::tst_QDBusPendingReply() |
|
240 |
{ |
|
241 |
adaptor = new TypesInterface(this); |
|
242 |
QDBusConnection::sessionBus().registerObject("/", this); |
|
243 |
||
244 |
iface = new QDBusInterface(QDBusConnection::sessionBus().baseService(), "/", |
|
245 |
"com.trolltech.Qt.Autotests.TypesInterface", |
|
246 |
QDBusConnection::sessionBus(), |
|
247 |
this); |
|
248 |
} |
|
249 |
||
250 |
void tst_QDBusPendingReply::init() |
|
251 |
{ |
|
252 |
QVERIFY(iface); |
|
253 |
QVERIFY(iface->isValid()); |
|
254 |
} |
|
255 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
256 |
void tst_QDBusPendingReply::unconnected() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
257 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
258 |
QDBusConnection con("invalid stored connection"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
259 |
QVERIFY(!con.isConnected()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
260 |
QDBusInterface iface("doesnt.matter", "/", "doesnt.matter", con); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
261 |
QVERIFY(!iface.isValid()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
262 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
263 |
QDBusPendingReply<> rvoid = iface.asyncCall("ReloadConfig"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
264 |
QVERIFY(rvoid.isFinished()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
265 |
QVERIFY(!rvoid.isValid()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
266 |
QVERIFY(rvoid.isError()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
267 |
rvoid.waitForFinished(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
268 |
QVERIFY(!rvoid.isValid()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
269 |
QVERIFY(rvoid.isError()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
270 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
271 |
QDBusPendingReply<QString> rstring = iface.asyncCall("GetId"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
272 |
QVERIFY(rstring.isFinished()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
273 |
QVERIFY(!rstring.isValid()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
274 |
QVERIFY(rstring.isError()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
275 |
rstring.waitForFinished(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
276 |
QVERIFY(!rstring.isValid()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
277 |
QVERIFY(rstring.isError()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
278 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
279 |
|
0 | 280 |
void tst_QDBusPendingReply::simpleTypes() |
281 |
{ |
|
282 |
QDBusPendingReply<> rvoid = iface->asyncCall("retrieveVoid"); |
|
283 |
rvoid.waitForFinished(); |
|
284 |
QVERIFY(rvoid.isFinished()); |
|
285 |
QVERIFY(!rvoid.isError()); |
|
286 |
||
287 |
QDBusPendingReply<bool> rbool = iface->asyncCall("retrieveBool"); |
|
288 |
rbool.waitForFinished(); |
|
289 |
QVERIFY(rbool.isFinished()); |
|
290 |
QCOMPARE(rbool.argumentAt<0>(), adaptor->retrieveBool()); |
|
291 |
||
292 |
QDBusPendingReply<uchar> ruchar = iface->asyncCall("retrieveUChar"); |
|
293 |
ruchar.waitForFinished(); |
|
294 |
QVERIFY(ruchar.isFinished()); |
|
295 |
QCOMPARE(ruchar.argumentAt<0>(), adaptor->retrieveUChar()); |
|
296 |
||
297 |
QDBusPendingReply<short> rshort = iface->asyncCall("retrieveShort"); |
|
298 |
rshort.waitForFinished(); |
|
299 |
QVERIFY(rshort.isFinished()); |
|
300 |
QCOMPARE(rshort.argumentAt<0>(), adaptor->retrieveShort()); |
|
301 |
||
302 |
QDBusPendingReply<ushort> rushort = iface->asyncCall("retrieveUShort"); |
|
303 |
rushort.waitForFinished(); |
|
304 |
QVERIFY(rushort.isFinished()); |
|
305 |
QCOMPARE(rushort.argumentAt<0>(), adaptor->retrieveUShort()); |
|
306 |
||
307 |
QDBusPendingReply<int> rint = iface->asyncCall("retrieveInt"); |
|
308 |
rint.waitForFinished(); |
|
309 |
QVERIFY(rint.isFinished()); |
|
310 |
QCOMPARE(rint.argumentAt<0>(), adaptor->retrieveInt()); |
|
311 |
||
312 |
QDBusPendingReply<uint> ruint = iface->asyncCall("retrieveUInt"); |
|
313 |
ruint.waitForFinished(); |
|
314 |
QVERIFY(ruint.isFinished()); |
|
315 |
QCOMPARE(ruint.argumentAt<0>(), adaptor->retrieveUInt()); |
|
316 |
||
317 |
QDBusPendingReply<qlonglong> rqlonglong = iface->asyncCall("retrieveLongLong"); |
|
318 |
rqlonglong.waitForFinished(); |
|
319 |
QVERIFY(rqlonglong.isFinished()); |
|
320 |
QCOMPARE(rqlonglong.argumentAt<0>(), adaptor->retrieveLongLong()); |
|
321 |
||
322 |
QDBusPendingReply<qulonglong> rqulonglong = iface->asyncCall("retrieveULongLong"); |
|
323 |
rqulonglong.waitForFinished(); |
|
324 |
QVERIFY(rqulonglong.isFinished()); |
|
325 |
QCOMPARE(rqulonglong.argumentAt<0>(), adaptor->retrieveULongLong()); |
|
326 |
||
327 |
QDBusPendingReply<double> rdouble = iface->asyncCall("retrieveDouble"); |
|
328 |
rdouble.waitForFinished(); |
|
329 |
QVERIFY(rdouble.isFinished()); |
|
330 |
QCOMPARE(rdouble.argumentAt<0>(), adaptor->retrieveDouble()); |
|
331 |
||
332 |
QDBusPendingReply<QString> rstring = iface->asyncCall("retrieveString"); |
|
333 |
rstring.waitForFinished(); |
|
334 |
QVERIFY(rstring.isFinished()); |
|
335 |
QCOMPARE(rstring.argumentAt<0>(), adaptor->retrieveString()); |
|
336 |
||
337 |
QDBusPendingReply<QDBusObjectPath> robjectpath = iface->asyncCall("retrieveObjectPath"); |
|
338 |
robjectpath.waitForFinished(); |
|
339 |
QVERIFY(robjectpath.isFinished()); |
|
340 |
QCOMPARE(robjectpath.argumentAt<0>().path(), adaptor->retrieveObjectPath().path()); |
|
341 |
||
342 |
QDBusPendingReply<QDBusSignature> rsignature = iface->asyncCall("retrieveSignature"); |
|
343 |
rsignature.waitForFinished(); |
|
344 |
QVERIFY(rsignature.isFinished()); |
|
345 |
QCOMPARE(rsignature.argumentAt<0>().signature(), adaptor->retrieveSignature().signature()); |
|
346 |
||
347 |
QDBusPendingReply<QDBusVariant> rdbusvariant = iface->asyncCall("retrieveVariant"); |
|
348 |
rdbusvariant.waitForFinished(); |
|
349 |
QVERIFY(rdbusvariant.isFinished()); |
|
350 |
QCOMPARE(rdbusvariant.argumentAt<0>().variant(), adaptor->retrieveVariant().variant()); |
|
351 |
||
352 |
QDBusPendingReply<QVariant> rvariant = iface->asyncCall("retrieveVariant"); |
|
353 |
rvariant.waitForFinished(); |
|
354 |
QVERIFY(rvariant.isFinished()); |
|
355 |
QCOMPARE(rvariant.argumentAt<0>(), adaptor->retrieveVariant().variant()); |
|
356 |
||
357 |
QDBusPendingReply<QByteArray> rbytearray = iface->asyncCall("retrieveByteArray"); |
|
358 |
rbytearray.waitForFinished(); |
|
359 |
QVERIFY(rbytearray.isFinished()); |
|
360 |
QCOMPARE(rbytearray.argumentAt<0>(), adaptor->retrieveByteArray()); |
|
361 |
||
362 |
QDBusPendingReply<QStringList> rstringlist = iface->asyncCall("retrieveStringList"); |
|
363 |
rstringlist.waitForFinished(); |
|
364 |
QVERIFY(rstringlist.isFinished()); |
|
365 |
QCOMPARE(rstringlist.argumentAt<0>(), adaptor->retrieveStringList()); |
|
366 |
} |
|
367 |
||
368 |
void tst_QDBusPendingReply::complexTypes() |
|
369 |
{ |
|
370 |
QDBusPendingReply<QVariantList> rlist = iface->asyncCall("retrieveList"); |
|
371 |
rlist.waitForFinished(); |
|
372 |
QVERIFY(rlist.isFinished()); |
|
373 |
QCOMPARE(rlist.argumentAt<0>(), adaptor->retrieveList()); |
|
374 |
||
375 |
QDBusPendingReply<QVariantMap> rmap = iface->asyncCall("retrieveMap"); |
|
376 |
rmap.waitForFinished(); |
|
377 |
QVERIFY(rmap.isFinished()); |
|
378 |
QCOMPARE(rmap.argumentAt<0>(), adaptor->retrieveMap()); |
|
379 |
||
380 |
QDBusPendingReply<IntStringMap> rismap = iface->asyncCall("retrieveIntStringMap"); |
|
381 |
rismap.waitForFinished(); |
|
382 |
QVERIFY(rismap.isFinished()); |
|
383 |
QCOMPARE(rismap.argumentAt<0>(), adaptor->retrieveIntStringMap()); |
|
384 |
||
385 |
QDBusPendingReply<MyStruct> rstruct = iface->asyncCall("retrieveStruct"); |
|
386 |
rstruct.waitForFinished(); |
|
387 |
QVERIFY(rstruct.isFinished()); |
|
388 |
QCOMPARE(rstruct.argumentAt<0>(), adaptor->retrieveStruct()); |
|
389 |
} |
|
390 |
||
391 |
#define VERIFY_WRONG_TYPE(error) \ |
|
392 |
QVERIFY(error.isValid()); \ |
|
393 |
QCOMPARE(error.type(), QDBusError::InvalidSignature) |
|
394 |
||
395 |
void tst_QDBusPendingReply::wrongTypes() |
|
396 |
{ |
|
397 |
QDBusError error; |
|
398 |
||
399 |
QDBusPendingReply<bool> rbool = iface->asyncCall("retrieveInt"); |
|
400 |
rbool.waitForFinished(); |
|
401 |
QVERIFY(rbool.isFinished()); |
|
402 |
QVERIFY(rbool.isError()); |
|
403 |
error = rbool.error(); |
|
404 |
VERIFY_WRONG_TYPE(error); |
|
405 |
||
406 |
rbool = iface->asyncCall("retrieveShort"); |
|
407 |
rbool.waitForFinished(); |
|
408 |
QVERIFY(rbool.isFinished()); |
|
409 |
QVERIFY(rbool.isError()); |
|
410 |
error = rbool.error(); |
|
411 |
VERIFY_WRONG_TYPE(error); |
|
412 |
||
413 |
rbool = iface->asyncCall("retrieveStruct"); |
|
414 |
rbool.waitForFinished(); |
|
415 |
QVERIFY(rbool.isFinished()); |
|
416 |
QVERIFY(rbool.isError()); |
|
417 |
error = rbool.error(); |
|
418 |
VERIFY_WRONG_TYPE(error); |
|
419 |
||
420 |
QDBusPendingReply<short> rshort = iface->asyncCall("retrieveInt"); |
|
421 |
rshort.waitForFinished(); |
|
422 |
QVERIFY(rshort.isFinished()); |
|
423 |
QVERIFY(rshort.isError()); |
|
424 |
error = rshort.error(); |
|
425 |
VERIFY_WRONG_TYPE(error); |
|
426 |
||
427 |
rshort = iface->asyncCall("retrieveBool"); |
|
428 |
rshort.waitForFinished(); |
|
429 |
QVERIFY(rshort.isFinished()); |
|
430 |
QVERIFY(rshort.isError()); |
|
431 |
error = rshort.error(); |
|
432 |
VERIFY_WRONG_TYPE(error); |
|
433 |
||
434 |
rshort = iface->asyncCall("retrieveStruct"); |
|
435 |
rshort.waitForFinished(); |
|
436 |
QVERIFY(rshort.isFinished()); |
|
437 |
QVERIFY(rshort.isError()); |
|
438 |
error = rshort.error(); |
|
439 |
VERIFY_WRONG_TYPE(error); |
|
440 |
||
441 |
QDBusPendingReply<MyStruct> rstruct = iface->asyncCall("retrieveInt"); |
|
442 |
rstruct.waitForFinished(); |
|
443 |
QVERIFY(rstruct.isFinished()); |
|
444 |
QVERIFY(rstruct.isError()); |
|
445 |
error = rstruct.error(); |
|
446 |
VERIFY_WRONG_TYPE(error); |
|
447 |
||
448 |
rstruct = iface->asyncCall("retrieveShort"); |
|
449 |
rstruct.waitForFinished(); |
|
450 |
QVERIFY(rstruct.isFinished()); |
|
451 |
QVERIFY(rstruct.isError()); |
|
452 |
error = rstruct.error(); |
|
453 |
VERIFY_WRONG_TYPE(error); |
|
454 |
||
455 |
rstruct = iface->asyncCall("retrieveIntStringMap"); |
|
456 |
rstruct.waitForFinished(); |
|
457 |
QVERIFY(rstruct.isFinished()); |
|
458 |
QVERIFY(rstruct.isError()); |
|
459 |
error = rstruct.error(); |
|
460 |
VERIFY_WRONG_TYPE(error); |
|
461 |
} |
|
462 |
||
463 |
void tst_QDBusPendingReply::multipleTypes() |
|
464 |
{ |
|
465 |
QDBusPendingReply<int, int> rintint = iface->asyncCall("retrieveIntInt"); |
|
466 |
rintint.waitForFinished(); |
|
467 |
QVERIFY(rintint.isFinished()); |
|
468 |
QVERIFY(!rintint.isError()); |
|
469 |
||
470 |
int i1, i2; |
|
471 |
adaptor->retrieveIntInt(i1, i2); |
|
472 |
QCOMPARE(rintint.argumentAt<0>(), i1); |
|
473 |
QCOMPARE(rintint.argumentAt<1>(), i2); |
|
474 |
} |
|
475 |
||
476 |
void tst_QDBusPendingReply::synchronousSimpleTypes() |
|
477 |
{ |
|
478 |
QDBusPendingReply<bool> rbool = iface->call("retrieveBool"); |
|
479 |
rbool.waitForFinished(); |
|
480 |
QVERIFY(rbool.isFinished()); |
|
481 |
QCOMPARE(rbool.argumentAt<0>(), adaptor->retrieveBool()); |
|
482 |
||
483 |
QDBusPendingReply<uchar> ruchar = iface->call("retrieveUChar"); |
|
484 |
ruchar.waitForFinished(); |
|
485 |
QVERIFY(ruchar.isFinished()); |
|
486 |
QCOMPARE(ruchar.argumentAt<0>(), adaptor->retrieveUChar()); |
|
487 |
||
488 |
QDBusPendingReply<short> rshort = iface->call("retrieveShort"); |
|
489 |
rshort.waitForFinished(); |
|
490 |
QVERIFY(rshort.isFinished()); |
|
491 |
QCOMPARE(rshort.argumentAt<0>(), adaptor->retrieveShort()); |
|
492 |
||
493 |
QDBusPendingReply<ushort> rushort = iface->call("retrieveUShort"); |
|
494 |
rushort.waitForFinished(); |
|
495 |
QVERIFY(rushort.isFinished()); |
|
496 |
QCOMPARE(rushort.argumentAt<0>(), adaptor->retrieveUShort()); |
|
497 |
||
498 |
QDBusPendingReply<int> rint = iface->call("retrieveInt"); |
|
499 |
rint.waitForFinished(); |
|
500 |
QVERIFY(rint.isFinished()); |
|
501 |
QCOMPARE(rint.argumentAt<0>(), adaptor->retrieveInt()); |
|
502 |
||
503 |
QDBusPendingReply<uint> ruint = iface->call("retrieveUInt"); |
|
504 |
ruint.waitForFinished(); |
|
505 |
QVERIFY(ruint.isFinished()); |
|
506 |
QCOMPARE(ruint.argumentAt<0>(), adaptor->retrieveUInt()); |
|
507 |
||
508 |
QDBusPendingReply<qlonglong> rqlonglong = iface->call("retrieveLongLong"); |
|
509 |
rqlonglong.waitForFinished(); |
|
510 |
QVERIFY(rqlonglong.isFinished()); |
|
511 |
QCOMPARE(rqlonglong.argumentAt<0>(), adaptor->retrieveLongLong()); |
|
512 |
||
513 |
QDBusPendingReply<qulonglong> rqulonglong = iface->call("retrieveULongLong"); |
|
514 |
rqulonglong.waitForFinished(); |
|
515 |
QVERIFY(rqulonglong.isFinished()); |
|
516 |
QCOMPARE(rqulonglong.argumentAt<0>(), adaptor->retrieveULongLong()); |
|
517 |
||
518 |
QDBusPendingReply<double> rdouble = iface->call("retrieveDouble"); |
|
519 |
rdouble.waitForFinished(); |
|
520 |
QVERIFY(rdouble.isFinished()); |
|
521 |
QCOMPARE(rdouble.argumentAt<0>(), adaptor->retrieveDouble()); |
|
522 |
||
523 |
QDBusPendingReply<QString> rstring = iface->call("retrieveString"); |
|
524 |
rstring.waitForFinished(); |
|
525 |
QVERIFY(rstring.isFinished()); |
|
526 |
QCOMPARE(rstring.argumentAt<0>(), adaptor->retrieveString()); |
|
527 |
||
528 |
QDBusPendingReply<QDBusObjectPath> robjectpath = iface->call("retrieveObjectPath"); |
|
529 |
robjectpath.waitForFinished(); |
|
530 |
QVERIFY(robjectpath.isFinished()); |
|
531 |
QCOMPARE(robjectpath.argumentAt<0>().path(), adaptor->retrieveObjectPath().path()); |
|
532 |
||
533 |
QDBusPendingReply<QDBusSignature> rsignature = iface->call("retrieveSignature"); |
|
534 |
rsignature.waitForFinished(); |
|
535 |
QVERIFY(rsignature.isFinished()); |
|
536 |
QCOMPARE(rsignature.argumentAt<0>().signature(), adaptor->retrieveSignature().signature()); |
|
537 |
||
538 |
QDBusPendingReply<QDBusVariant> rdbusvariant = iface->call("retrieveVariant"); |
|
539 |
rdbusvariant.waitForFinished(); |
|
540 |
QVERIFY(rdbusvariant.isFinished()); |
|
541 |
QCOMPARE(rdbusvariant.argumentAt<0>().variant(), adaptor->retrieveVariant().variant()); |
|
542 |
||
543 |
QDBusPendingReply<QByteArray> rbytearray = iface->call("retrieveByteArray"); |
|
544 |
rbytearray.waitForFinished(); |
|
545 |
QVERIFY(rbytearray.isFinished()); |
|
546 |
QCOMPARE(rbytearray.argumentAt<0>(), adaptor->retrieveByteArray()); |
|
547 |
||
548 |
QDBusPendingReply<QStringList> rstringlist = iface->call("retrieveStringList"); |
|
549 |
rstringlist.waitForFinished(); |
|
550 |
QVERIFY(rstringlist.isFinished()); |
|
551 |
QCOMPARE(rstringlist.argumentAt<0>(), adaptor->retrieveStringList()); |
|
552 |
} |
|
553 |
||
554 |
#define VERIFY_ERROR(error) \ |
|
555 |
QVERIFY(error.isValid()); \ |
|
556 |
QCOMPARE(error.name(), QString("local.AnErrorName")); \ |
|
557 |
QCOMPARE(error.type(), QDBusError::Other) |
|
558 |
||
559 |
void tst_QDBusPendingReply::errors() |
|
560 |
{ |
|
561 |
QDBusError error; |
|
562 |
||
563 |
QDBusPendingReply<> rvoid = iface->asyncCall("sendError"); |
|
564 |
rvoid.waitForFinished(); |
|
565 |
QVERIFY(rvoid.isFinished()); |
|
566 |
QVERIFY(rvoid.isError()); |
|
567 |
error = rvoid.error(); |
|
568 |
VERIFY_ERROR(error); |
|
569 |
||
570 |
QDBusPendingReply<int> rint = iface->asyncCall("sendError"); |
|
571 |
rint.waitForFinished(); |
|
572 |
QVERIFY(rint.isFinished()); |
|
573 |
QVERIFY(rint.isError()); |
|
574 |
error = rint.error(); |
|
575 |
VERIFY_ERROR(error); |
|
576 |
||
577 |
QDBusPendingReply<int,int> rintint = iface->asyncCall("sendError"); |
|
578 |
rintint.waitForFinished(); |
|
579 |
QVERIFY(rintint.isFinished()); |
|
580 |
QVERIFY(rintint.isError()); |
|
581 |
error = rintint.error(); |
|
582 |
VERIFY_ERROR(error); |
|
583 |
||
584 |
QDBusPendingReply<QString> rstring = iface->asyncCall("sendError"); |
|
585 |
rstring.waitForFinished(); |
|
586 |
QVERIFY(rstring.isFinished()); |
|
587 |
QVERIFY(rstring.isError()); |
|
588 |
error = rstring.error(); |
|
589 |
VERIFY_ERROR(error); |
|
590 |
} |
|
591 |
||
592 |
QTEST_MAIN(tst_QDBusPendingReply) |
|
593 |
||
594 |
#include "tst_qdbuspendingreply.moc" |
|
595 |
#else |
|
596 |
QTEST_NOOP_MAIN |
|
597 |
#endif |