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 <qcoreapplication.h> |
|
42 |
#include <qdebug.h> |
|
43 |
#include <qvariant.h> |
|
44 |
||
45 |
#include <QtTest/QtTest> |
|
46 |
||
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_QDBusReply: public QObject |
|
81 |
{ |
|
82 |
Q_OBJECT |
|
83 |
QDBusInterface *iface; |
|
84 |
TypesInterface *adaptor; |
|
85 |
public: |
|
86 |
tst_QDBusReply(); |
|
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 |
}; |
|
101 |
||
102 |
class TypesInterface: public QDBusAbstractAdaptor |
|
103 |
{ |
|
104 |
Q_OBJECT |
|
105 |
Q_CLASSINFO("D-Bus Interface", "com.trolltech.Qt.Autotests.TypesInterface") |
|
106 |
public: |
|
107 |
TypesInterface(QObject *parent) |
|
108 |
: QDBusAbstractAdaptor(parent) |
|
109 |
{ } |
|
110 |
||
111 |
public slots: |
|
112 |
bool retrieveBool() |
|
113 |
{ |
|
114 |
return true; |
|
115 |
} |
|
116 |
||
117 |
uchar retrieveUChar() |
|
118 |
{ |
|
119 |
return 'A'; |
|
120 |
} |
|
121 |
||
122 |
short retrieveShort() |
|
123 |
{ |
|
124 |
return -47; |
|
125 |
} |
|
126 |
||
127 |
ushort retrieveUShort() |
|
128 |
{ |
|
129 |
return 42U; |
|
130 |
} |
|
131 |
||
132 |
int retrieveInt() |
|
133 |
{ |
|
134 |
return -470000; |
|
135 |
} |
|
136 |
||
137 |
uint retrieveUInt() |
|
138 |
{ |
|
139 |
return 42424242; |
|
140 |
} |
|
141 |
||
142 |
qlonglong retrieveLongLong() |
|
143 |
{ |
|
144 |
return -(Q_INT64_C(1) << 32); |
|
145 |
} |
|
146 |
||
147 |
qulonglong retrieveULongLong() |
|
148 |
{ |
|
149 |
return Q_INT64_C(1) << 32; |
|
150 |
} |
|
151 |
||
152 |
double retrieveDouble() |
|
153 |
{ |
|
154 |
return 1.5; |
|
155 |
} |
|
156 |
||
157 |
QString retrieveString() |
|
158 |
{ |
|
159 |
return "This string you should see"; |
|
160 |
} |
|
161 |
||
162 |
QDBusObjectPath retrieveObjectPath() |
|
163 |
{ |
|
164 |
return QDBusObjectPath("/"); |
|
165 |
} |
|
166 |
||
167 |
QDBusSignature retrieveSignature() |
|
168 |
{ |
|
169 |
return QDBusSignature("g"); |
|
170 |
} |
|
171 |
||
172 |
QDBusVariant retrieveVariant() |
|
173 |
{ |
|
174 |
return QDBusVariant(retrieveString()); |
|
175 |
} |
|
176 |
||
177 |
QStringList retrieveStringList() |
|
178 |
{ |
|
179 |
return QStringList() << "one" << "two"; |
|
180 |
} |
|
181 |
||
182 |
QByteArray retrieveByteArray() |
|
183 |
{ |
|
184 |
return "Hello, World"; |
|
185 |
} |
|
186 |
||
187 |
QVariantList retrieveList() |
|
188 |
{ |
|
189 |
return QVariantList() << retrieveInt() << retrieveString() |
|
190 |
<< retrieveByteArray(); |
|
191 |
} |
|
192 |
||
193 |
QList<QDBusObjectPath> retrieveObjectPathList() |
|
194 |
{ |
|
195 |
return QList<QDBusObjectPath>() << QDBusObjectPath("/") << QDBusObjectPath("/foo"); |
|
196 |
} |
|
197 |
||
198 |
QVariantMap retrieveMap() |
|
199 |
{ |
|
200 |
QVariantMap map; |
|
201 |
map["one"] = 1; |
|
202 |
map["two"] = 2U; |
|
203 |
map["string"] = retrieveString(); |
|
204 |
map["stringlist"] = retrieveStringList(); |
|
205 |
return map; |
|
206 |
} |
|
207 |
||
208 |
IntStringMap retrieveIntStringMap() |
|
209 |
{ |
|
210 |
IntStringMap map; |
|
211 |
map[1] = "1"; |
|
212 |
map[2] = "2"; |
|
213 |
map[-1231456] = "foo"; |
|
214 |
return map; |
|
215 |
} |
|
216 |
||
217 |
MyStruct retrieveStruct() |
|
218 |
{ |
|
219 |
return MyStruct(); |
|
220 |
} |
|
221 |
}; |
|
222 |
||
223 |
tst_QDBusReply::tst_QDBusReply() |
|
224 |
{ |
|
225 |
adaptor = new TypesInterface(this); |
|
226 |
QDBusConnection::sessionBus().registerObject("/", this); |
|
227 |
||
228 |
iface = new QDBusInterface(QDBusConnection::sessionBus().baseService(), "/", |
|
229 |
"com.trolltech.Qt.Autotests.TypesInterface", |
|
230 |
QDBusConnection::sessionBus(), |
|
231 |
this); |
|
232 |
} |
|
233 |
||
234 |
void tst_QDBusReply::init() |
|
235 |
{ |
|
236 |
QVERIFY(iface); |
|
237 |
QVERIFY(iface->isValid()); |
|
238 |
} |
|
239 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
240 |
void tst_QDBusReply::unconnected() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
241 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
242 |
QDBusConnection con("invalid stored connection"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
243 |
QVERIFY(!con.isConnected()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
244 |
QDBusInterface iface("doesnt.matter", "/", "doesnt.matter", con); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
245 |
QVERIFY(!iface.isValid()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
246 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
247 |
QDBusReply<void> rvoid = iface.asyncCall("ReloadConfig"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
248 |
QVERIFY(!rvoid.isValid()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
249 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
250 |
QDBusReply<QString> rstring = iface.asyncCall("GetId"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
251 |
QVERIFY(!rstring.isValid()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
252 |
QVERIFY(rstring.value().isEmpty()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
253 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
254 |
|
0 | 255 |
void tst_QDBusReply::simpleTypes() |
256 |
{ |
|
257 |
QDBusReply<bool> rbool = iface->call(QDBus::BlockWithGui, "retrieveBool"); |
|
258 |
QVERIFY(rbool.isValid()); |
|
259 |
QCOMPARE(rbool.value(), adaptor->retrieveBool()); |
|
260 |
||
261 |
QDBusReply<uchar> ruchar = iface->call(QDBus::BlockWithGui, "retrieveUChar"); |
|
262 |
QVERIFY(ruchar.isValid()); |
|
263 |
QCOMPARE(ruchar.value(), adaptor->retrieveUChar()); |
|
264 |
||
265 |
QDBusReply<short> rshort = iface->call(QDBus::BlockWithGui, "retrieveShort"); |
|
266 |
QVERIFY(rshort.isValid()); |
|
267 |
QCOMPARE(rshort.value(), adaptor->retrieveShort()); |
|
268 |
||
269 |
QDBusReply<ushort> rushort = iface->call(QDBus::BlockWithGui, "retrieveUShort"); |
|
270 |
QVERIFY(rushort.isValid()); |
|
271 |
QCOMPARE(rushort.value(), adaptor->retrieveUShort()); |
|
272 |
||
273 |
QDBusReply<int> rint = iface->call(QDBus::BlockWithGui, "retrieveInt"); |
|
274 |
QVERIFY(rint.isValid()); |
|
275 |
QCOMPARE(rint.value(), adaptor->retrieveInt()); |
|
276 |
||
277 |
QDBusReply<uint> ruint = iface->call(QDBus::BlockWithGui, "retrieveUInt"); |
|
278 |
QVERIFY(ruint.isValid()); |
|
279 |
QCOMPARE(ruint.value(), adaptor->retrieveUInt()); |
|
280 |
||
281 |
QDBusReply<qlonglong> rqlonglong = iface->call(QDBus::BlockWithGui, "retrieveLongLong"); |
|
282 |
QVERIFY(rqlonglong.isValid()); |
|
283 |
QCOMPARE(rqlonglong.value(), adaptor->retrieveLongLong()); |
|
284 |
||
285 |
QDBusReply<qulonglong> rqulonglong = iface->call(QDBus::BlockWithGui, "retrieveULongLong"); |
|
286 |
QVERIFY(rqulonglong.isValid()); |
|
287 |
QCOMPARE(rqulonglong.value(), adaptor->retrieveULongLong()); |
|
288 |
||
289 |
QDBusReply<double> rdouble = iface->call(QDBus::BlockWithGui, "retrieveDouble"); |
|
290 |
QVERIFY(rdouble.isValid()); |
|
291 |
QCOMPARE(rdouble.value(), adaptor->retrieveDouble()); |
|
292 |
||
293 |
QDBusReply<QString> rstring = iface->call(QDBus::BlockWithGui, "retrieveString"); |
|
294 |
QVERIFY(rstring.isValid()); |
|
295 |
QCOMPARE(rstring.value(), adaptor->retrieveString()); |
|
296 |
||
297 |
QDBusReply<QDBusObjectPath> robjectpath = iface->call(QDBus::BlockWithGui, "retrieveObjectPath"); |
|
298 |
QVERIFY(robjectpath.isValid()); |
|
299 |
QCOMPARE(robjectpath.value().path(), adaptor->retrieveObjectPath().path()); |
|
300 |
||
301 |
QDBusReply<QDBusSignature> rsignature = iface->call(QDBus::BlockWithGui, "retrieveSignature"); |
|
302 |
QVERIFY(rsignature.isValid()); |
|
303 |
QCOMPARE(rsignature.value().signature(), adaptor->retrieveSignature().signature()); |
|
304 |
||
305 |
QDBusReply<QDBusVariant> rdbusvariant = iface->call(QDBus::BlockWithGui, "retrieveVariant"); |
|
306 |
QVERIFY(rdbusvariant.isValid()); |
|
307 |
QCOMPARE(rdbusvariant.value().variant(), adaptor->retrieveVariant().variant()); |
|
308 |
||
309 |
QDBusReply<QVariant> rvariant = iface->call(QDBus::BlockWithGui, "retrieveVariant"); |
|
310 |
QVERIFY(rvariant.isValid()); |
|
311 |
QCOMPARE(rvariant.value(), adaptor->retrieveVariant().variant()); |
|
312 |
||
313 |
QDBusReply<QByteArray> rbytearray = iface->call(QDBus::BlockWithGui, "retrieveByteArray"); |
|
314 |
QVERIFY(rbytearray.isValid()); |
|
315 |
QCOMPARE(rbytearray.value(), adaptor->retrieveByteArray()); |
|
316 |
||
317 |
QDBusReply<QStringList> rstringlist = iface->call(QDBus::BlockWithGui, "retrieveStringList"); |
|
318 |
QVERIFY(rstringlist.isValid()); |
|
319 |
QCOMPARE(rstringlist.value(), adaptor->retrieveStringList()); |
|
320 |
} |
|
321 |
||
322 |
void tst_QDBusReply::complexTypes() |
|
323 |
{ |
|
324 |
QDBusReply<QVariantList> rlist = iface->call(QDBus::BlockWithGui, "retrieveList"); |
|
325 |
QVERIFY(rlist.isValid()); |
|
326 |
QCOMPARE(rlist.value(), adaptor->retrieveList()); |
|
327 |
||
328 |
QDBusReply<QList<QDBusObjectPath> > rolist = iface->call(QDBus::BlockWithGui, "retrieveObjectPathList"); |
|
329 |
QVERIFY(rolist.isValid()); |
|
330 |
QCOMPARE(rolist.value(), adaptor->retrieveObjectPathList()); |
|
331 |
||
332 |
QDBusReply<QVariantMap> rmap = iface->call(QDBus::BlockWithGui, "retrieveMap"); |
|
333 |
QVERIFY(rmap.isValid()); |
|
334 |
QCOMPARE(rmap.value(), adaptor->retrieveMap()); |
|
335 |
||
336 |
QDBusReply<IntStringMap> rismap = iface->call(QDBus::BlockWithGui, "retrieveIntStringMap"); |
|
337 |
QVERIFY(rismap.isValid()); |
|
338 |
QCOMPARE(rismap.value(), adaptor->retrieveIntStringMap()); |
|
339 |
||
340 |
QDBusReply<MyStruct> rstruct = iface->call(QDBus::BlockWithGui, "retrieveStruct"); |
|
341 |
QVERIFY(rstruct.isValid()); |
|
342 |
QCOMPARE(rstruct.value(), adaptor->retrieveStruct()); |
|
343 |
} |
|
344 |
||
345 |
void tst_QDBusReply::wrongTypes() |
|
346 |
{ |
|
347 |
QDBusReply<bool> rbool = iface->call(QDBus::BlockWithGui, "retrieveInt"); |
|
348 |
QVERIFY(!rbool.isValid()); |
|
349 |
||
350 |
rbool = iface->call(QDBus::BlockWithGui, "retrieveShort"); |
|
351 |
QVERIFY(!rbool.isValid()); |
|
352 |
||
353 |
rbool = iface->call(QDBus::BlockWithGui, "retrieveStruct"); |
|
354 |
QVERIFY(!rbool.isValid()); |
|
355 |
||
356 |
QDBusReply<short> rshort = iface->call(QDBus::BlockWithGui, "retrieveInt"); |
|
357 |
QVERIFY(!rshort.isValid()); |
|
358 |
||
359 |
rshort = iface->call(QDBus::BlockWithGui, "retrieveBool"); |
|
360 |
QVERIFY(!rshort.isValid()); |
|
361 |
||
362 |
rshort = iface->call(QDBus::BlockWithGui, "retrieveStruct"); |
|
363 |
QVERIFY(!rshort.isValid()); |
|
364 |
||
365 |
QDBusReply<MyStruct> rstruct = iface->call(QDBus::BlockWithGui, "retrieveInt"); |
|
366 |
QVERIFY(!rstruct.isValid()); |
|
367 |
||
368 |
rstruct = iface->call(QDBus::BlockWithGui, "retrieveShort"); |
|
369 |
QVERIFY(!rstruct.isValid()); |
|
370 |
||
371 |
rstruct = iface->call(QDBus::BlockWithGui, "retrieveIntStringMap"); |
|
372 |
QVERIFY(!rstruct.isValid()); |
|
373 |
} |
|
374 |
||
375 |
QTEST_MAIN(tst_QDBusReply) |
|
376 |
||
377 |
#include "tst_qdbusreply.moc" |