author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 11:15:19 +0300 | |
branch | RCL_3 |
changeset 11 | 25a739ee40f4 |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
||
44 |
#include <QtTest/QtTest> |
|
45 |
||
46 |
#include <QtDBus> |
|
47 |
||
48 |
#include "../qdbusmarshall/common.h" |
|
49 |
||
50 |
const char *slotSpy; |
|
51 |
QString valueSpy; |
|
52 |
||
53 |
QT_BEGIN_NAMESPACE |
|
54 |
namespace QTest { |
|
55 |
char *toString(QDBusMessage::MessageType t) |
|
56 |
{ |
|
57 |
switch (t) |
|
58 |
{ |
|
59 |
case QDBusMessage::InvalidMessage: |
|
60 |
return qstrdup("InvalidMessage"); |
|
61 |
case QDBusMessage::MethodCallMessage: |
|
62 |
return qstrdup("MethodCallMessage"); |
|
63 |
case QDBusMessage::ReplyMessage: |
|
64 |
return qstrdup("ReplyMessage"); |
|
65 |
case QDBusMessage::ErrorMessage: |
|
66 |
return qstrdup("ErrorMessage"); |
|
67 |
case QDBusMessage::SignalMessage: |
|
68 |
return qstrdup("SignalMessage"); |
|
69 |
default: |
|
70 |
return 0; |
|
71 |
} |
|
72 |
} |
|
73 |
} |
|
74 |
QT_END_NAMESPACE |
|
75 |
||
76 |
class tst_QDBusAbstractAdaptor: public QObject |
|
77 |
{ |
|
78 |
Q_OBJECT |
|
79 |
||
80 |
private slots: |
|
81 |
void initTestCase() { commonInit(); } |
|
82 |
void methodCalls_data(); |
|
83 |
void methodCalls(); |
|
84 |
void methodCallScriptable(); |
|
85 |
void signalEmissions_data(); |
|
86 |
void signalEmissions(); |
|
87 |
void sameSignalDifferentPaths(); |
|
88 |
void sameObjectDifferentPaths(); |
|
89 |
void scriptableSignalOrNot(); |
|
90 |
void overloadedSignalEmission_data(); |
|
91 |
void overloadedSignalEmission(); |
|
92 |
void readProperties(); |
|
93 |
void readPropertiesInvalidInterface(); |
|
94 |
void readPropertiesEmptyInterface_data(); |
|
95 |
void readPropertiesEmptyInterface(); |
|
96 |
void readAllProperties(); |
|
97 |
void readAllPropertiesInvalidInterface(); |
|
98 |
void readAllPropertiesEmptyInterface_data(); |
|
99 |
void readAllPropertiesEmptyInterface(); |
|
100 |
void writeProperties(); |
|
101 |
||
102 |
void typeMatching_data(); |
|
103 |
void typeMatching(); |
|
104 |
||
105 |
void methodWithMoreThanOneReturnValue(); |
|
106 |
}; |
|
107 |
||
108 |
class QDBusSignalSpy: public QObject |
|
109 |
{ |
|
110 |
Q_OBJECT |
|
111 |
||
112 |
public slots: |
|
113 |
void slot(const QDBusMessage &msg) |
|
114 |
{ |
|
115 |
++count; |
|
116 |
interface = msg.interface(); |
|
117 |
name = msg.member(); |
|
118 |
signature = msg.signature(); |
|
119 |
path = msg.path(); |
|
120 |
value.clear(); |
|
121 |
if (msg.arguments().count()) |
|
122 |
value = msg.arguments().at(0); |
|
123 |
} |
|
124 |
||
125 |
public: |
|
126 |
QDBusSignalSpy() : count(0) { } |
|
127 |
||
128 |
int count; |
|
129 |
QString interface; |
|
130 |
QString name; |
|
131 |
QString signature; |
|
132 |
QString path; |
|
133 |
QVariant value; |
|
134 |
}; |
|
135 |
||
136 |
class Interface1: public QDBusAbstractAdaptor |
|
137 |
{ |
|
138 |
Q_OBJECT |
|
139 |
Q_CLASSINFO("D-Bus Interface", "local.Interface1") |
|
140 |
public: |
|
141 |
Interface1(QObject *parent) : QDBusAbstractAdaptor(parent) |
|
142 |
{ } |
|
143 |
}; |
|
144 |
||
145 |
class Interface2: public QDBusAbstractAdaptor |
|
146 |
{ |
|
147 |
Q_OBJECT |
|
148 |
Q_CLASSINFO("D-Bus Interface", "local.Interface2") |
|
149 |
Q_PROPERTY(QString prop1 READ prop1) |
|
150 |
Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2 SCRIPTABLE true) |
|
151 |
Q_PROPERTY(QUrl nonDBusProperty READ nonDBusProperty) |
|
152 |
public: |
|
153 |
Interface2(QObject *parent) : QDBusAbstractAdaptor(parent) |
|
154 |
{ setAutoRelaySignals(true); } |
|
155 |
||
156 |
QString prop1() const |
|
157 |
{ return QLatin1String("QString Interface2::prop1() const"); } |
|
158 |
||
159 |
QString prop2() const |
|
160 |
{ return QLatin1String("QString Interface2::prop2() const"); } |
|
161 |
||
162 |
void setProp2(const QString &value) |
|
163 |
{ |
|
164 |
slotSpy = "void Interface2::setProp2(const QString &)"; |
|
165 |
valueSpy = value; |
|
166 |
} |
|
167 |
||
168 |
QUrl nonDBusProperty() const |
|
169 |
{ return QUrl(); } |
|
170 |
||
171 |
void emitSignal(const QString &, const QVariant &) |
|
172 |
{ emit signal(); } |
|
173 |
||
174 |
public slots: |
|
175 |
void method() |
|
176 |
{ |
|
177 |
slotSpy = "void Interface2::method()"; |
|
178 |
} |
|
179 |
||
180 |
Q_SCRIPTABLE void scriptableMethod() |
|
181 |
{ |
|
182 |
slotSpy = "void Interface2::scriptableMethod()"; |
|
183 |
} |
|
184 |
||
185 |
signals: |
|
186 |
void signal(); |
|
187 |
}; |
|
188 |
||
189 |
class Interface3: public QDBusAbstractAdaptor |
|
190 |
{ |
|
191 |
Q_OBJECT |
|
192 |
Q_CLASSINFO("D-Bus Interface", "local.Interface3") |
|
193 |
Q_PROPERTY(QString prop1 READ prop1) |
|
194 |
Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2) |
|
195 |
Q_PROPERTY(QString interface3prop READ interface3prop) |
|
196 |
public: |
|
197 |
Interface3(QObject *parent) : QDBusAbstractAdaptor(parent) |
|
198 |
{ setAutoRelaySignals(true); } |
|
199 |
||
200 |
QString prop1() const |
|
201 |
{ return QLatin1String("QString Interface3::prop1() const"); } |
|
202 |
||
203 |
QString prop2() const |
|
204 |
{ return QLatin1String("QString Interface3::prop2() const"); } |
|
205 |
||
206 |
void setProp2(const QString &value) |
|
207 |
{ |
|
208 |
slotSpy = "void Interface3::setProp2(const QString &)"; |
|
209 |
valueSpy = value; |
|
210 |
} |
|
211 |
||
212 |
QString interface3prop() const |
|
213 |
{ return QLatin1String("QString Interface3::interface3prop() const"); } |
|
214 |
||
215 |
void emitSignal(const QString &name, const QVariant &value) |
|
216 |
{ |
|
217 |
if (name == "signalVoid") |
|
218 |
emit signalVoid(); |
|
219 |
else if (name == "signalInt") |
|
220 |
emit signalInt(value.toInt()); |
|
221 |
else if (name == "signalString") |
|
222 |
emit signalString(value.toString()); |
|
223 |
} |
|
224 |
||
225 |
public slots: |
|
226 |
void methodVoid() { slotSpy = "void Interface3::methodVoid()"; } |
|
227 |
void methodInt(int) { slotSpy = "void Interface3::methodInt(int)"; } |
|
228 |
void methodString(QString) { slotSpy = "void Interface3::methodString(QString)"; } |
|
229 |
||
230 |
int methodStringString(const QString &s, QString &out) |
|
231 |
{ |
|
232 |
slotSpy = "int Interface3::methodStringString(const QString &, QString &)"; |
|
233 |
out = s; |
|
234 |
return 42; |
|
235 |
} |
|
236 |
||
237 |
signals: |
|
238 |
void signalVoid(); |
|
239 |
void signalInt(int); |
|
240 |
void signalString(const QString &); |
|
241 |
}; |
|
242 |
||
243 |
class Interface4: public QDBusAbstractAdaptor |
|
244 |
{ |
|
245 |
Q_OBJECT |
|
246 |
Q_CLASSINFO("D-Bus Interface", "local.Interface4") |
|
247 |
Q_PROPERTY(QString prop1 READ prop1) |
|
248 |
Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2) |
|
249 |
Q_PROPERTY(QString interface4prop READ interface4prop) |
|
250 |
public: |
|
251 |
Interface4(QObject *parent) : QDBusAbstractAdaptor(parent) |
|
252 |
{ setAutoRelaySignals(true); } |
|
253 |
||
254 |
QString prop1() const |
|
255 |
{ return QLatin1String("QString Interface4::prop1() const"); } |
|
256 |
||
257 |
QString prop2() const |
|
258 |
{ return QLatin1String("QString Interface4::prop2() const"); } |
|
259 |
||
260 |
QString interface4prop() const |
|
261 |
{ return QLatin1String("QString Interface4::interface4prop() const"); } |
|
262 |
||
263 |
void setProp2(const QString &value) |
|
264 |
{ |
|
265 |
slotSpy = "void Interface4::setProp2(const QString &)"; |
|
266 |
valueSpy = value; |
|
267 |
} |
|
268 |
||
269 |
void emitSignal(const QString &, const QVariant &value) |
|
270 |
{ |
|
271 |
switch (value.type()) |
|
272 |
{ |
|
273 |
case QVariant::Invalid: |
|
274 |
emit signal(); |
|
275 |
break; |
|
276 |
case QVariant::Int: |
|
277 |
emit signal(value.toInt()); |
|
278 |
break; |
|
279 |
case QVariant::String: |
|
280 |
emit signal(value.toString()); |
|
281 |
break; |
|
282 |
default: |
|
283 |
break; |
|
284 |
} |
|
285 |
} |
|
286 |
||
287 |
public slots: |
|
288 |
void method() { slotSpy = "void Interface4::method()"; } |
|
289 |
void method(int) { slotSpy = "void Interface4::method(int)"; } |
|
290 |
void method(QString) { slotSpy = "void Interface4::method(QString)"; } |
|
291 |
||
292 |
signals: |
|
293 |
void signal(); |
|
294 |
void signal(int); |
|
295 |
void signal(const QString &); |
|
296 |
}; |
|
297 |
||
298 |
class MyObject: public QObject |
|
299 |
{ |
|
300 |
Q_OBJECT |
|
301 |
Q_CLASSINFO("D-Bus Interface", "local.MyObject") |
|
302 |
public: |
|
303 |
Interface1 *if1; |
|
304 |
Interface2 *if2; |
|
305 |
Interface3 *if3; |
|
306 |
Interface4 *if4; |
|
307 |
||
308 |
MyObject(int n = 4) |
|
309 |
: if1(0), if2(0), if3(0), if4(0) |
|
310 |
{ |
|
311 |
switch (n) |
|
312 |
{ |
|
313 |
case 4: |
|
314 |
if4 = new Interface4(this); |
|
315 |
case 3: |
|
316 |
if3 = new Interface3(this); |
|
317 |
case 2: |
|
318 |
if2 = new Interface2(this); |
|
319 |
case 1: |
|
320 |
if1 = new Interface1(this); |
|
321 |
} |
|
322 |
} |
|
323 |
||
324 |
void emitSignal(const QString &name, const QVariant &value) |
|
325 |
{ |
|
326 |
if (name == "scriptableSignalVoid") |
|
327 |
emit scriptableSignalVoid(); |
|
328 |
else if (name == "scriptableSignalInt") |
|
329 |
emit scriptableSignalInt(value.toInt()); |
|
330 |
else if (name == "scriptableSignalString") |
|
331 |
emit scriptableSignalString(value.toString()); |
|
332 |
else if (name == "nonScriptableSignalVoid") |
|
333 |
emit nonScriptableSignalVoid(); |
|
334 |
} |
|
335 |
||
336 |
signals: |
|
337 |
Q_SCRIPTABLE void scriptableSignalVoid(); |
|
338 |
Q_SCRIPTABLE void scriptableSignalInt(int); |
|
339 |
Q_SCRIPTABLE void scriptableSignalString(QString); |
|
340 |
void nonScriptableSignalVoid(); |
|
341 |
}; |
|
342 |
||
343 |
class TypesInterface: public QDBusAbstractAdaptor |
|
344 |
{ |
|
345 |
Q_OBJECT |
|
346 |
Q_CLASSINFO("D-Bus Interface", "local.TypesInterface") |
|
347 |
public: |
|
348 |
TypesInterface(QObject *parent) |
|
349 |
: QDBusAbstractAdaptor(parent) |
|
350 |
{ } |
|
351 |
||
352 |
union |
|
353 |
{ |
|
354 |
bool b; |
|
355 |
uchar uc; |
|
356 |
short s; |
|
357 |
ushort us; |
|
358 |
int i; |
|
359 |
uint ui; |
|
360 |
qlonglong ll; |
|
361 |
qulonglong ull; |
|
362 |
double d; |
|
363 |
} dataSpy; |
|
364 |
QVariant variantSpy; |
|
365 |
QString stringSpy; |
|
366 |
QVariantList listSpy; |
|
367 |
QStringList stringlistSpy; |
|
368 |
QByteArray bytearraySpy; |
|
369 |
QVariantMap mapSpy; |
|
370 |
StringStringMap ssmapSpy; |
|
371 |
LLDateTimeMap lldtmapSpy; |
|
372 |
MyStruct structSpy; |
|
373 |
||
374 |
public slots: |
|
375 |
void methodBool(bool b) |
|
376 |
{ |
|
377 |
slotSpy = "void TypesInterface::methodBool(bool)"; |
|
378 |
dataSpy.b = b; |
|
379 |
} |
|
380 |
||
381 |
void methodUChar(uchar uc) |
|
382 |
{ |
|
383 |
slotSpy = "void TypesInterface::methodUChar(uchar)"; |
|
384 |
dataSpy.uc = uc; |
|
385 |
} |
|
386 |
||
387 |
void methodShort(short s) |
|
388 |
{ |
|
389 |
slotSpy = "void TypesInterface::methodShort(short)"; |
|
390 |
dataSpy.s = s; |
|
391 |
} |
|
392 |
||
393 |
void methodUShort(ushort us) |
|
394 |
{ |
|
395 |
slotSpy = "void TypesInterface::methodUShort(ushort)"; |
|
396 |
dataSpy.us = us; |
|
397 |
} |
|
398 |
||
399 |
void methodInt(int i) |
|
400 |
{ |
|
401 |
slotSpy = "void TypesInterface::methodInt(int)"; |
|
402 |
dataSpy.i = i; |
|
403 |
} |
|
404 |
||
405 |
void methodUInt(uint ui) |
|
406 |
{ |
|
407 |
slotSpy = "void TypesInterface::methodUInt(uint)"; |
|
408 |
dataSpy.ui = ui; |
|
409 |
} |
|
410 |
||
411 |
void methodLongLong(qlonglong ll) |
|
412 |
{ |
|
413 |
slotSpy = "void TypesInterface::methodLongLong(qlonglong)"; |
|
414 |
dataSpy.ll = ll; |
|
415 |
} |
|
416 |
||
417 |
void methodULongLong(qulonglong ull) |
|
418 |
{ |
|
419 |
slotSpy = "void TypesInterface::methodULongLong(qulonglong)"; |
|
420 |
dataSpy.ull = ull; |
|
421 |
} |
|
422 |
||
423 |
void methodDouble(double d) |
|
424 |
{ |
|
425 |
slotSpy = "void TypesInterface::methodDouble(double)"; |
|
426 |
dataSpy.d = d; |
|
427 |
} |
|
428 |
||
429 |
void methodString(const QString &s) |
|
430 |
{ |
|
431 |
slotSpy = "void TypesInterface::methodString(const QString &)"; |
|
432 |
stringSpy = s; |
|
433 |
} |
|
434 |
||
435 |
void methodObjectPath(const QDBusObjectPath &op) |
|
436 |
{ |
|
437 |
slotSpy = "void TypesInterface::methodObjectPath(const QDBusObjectPath &)"; |
|
438 |
stringSpy = op.path(); |
|
439 |
} |
|
440 |
||
441 |
void methodSignature(const QDBusSignature &s) |
|
442 |
{ |
|
443 |
slotSpy = "void TypesInterface::methodSignature(const QDBusSignature &)"; |
|
444 |
stringSpy = s.signature(); |
|
445 |
} |
|
446 |
||
447 |
void methodVariant(const QDBusVariant &v) |
|
448 |
{ |
|
449 |
slotSpy = "void TypesInterface::methodVariant(const QDBusVariant &)"; |
|
450 |
variantSpy = v.variant(); |
|
451 |
} |
|
452 |
||
453 |
void methodList(const QVariantList &l) |
|
454 |
{ |
|
455 |
slotSpy = "void TypesInterface::methodList(const QVariantList &)"; |
|
456 |
listSpy = l; |
|
457 |
} |
|
458 |
||
459 |
void methodStringList(const QStringList &sl) |
|
460 |
{ |
|
461 |
slotSpy = "void TypesInterface::methodStringList(const QStringList &)"; |
|
462 |
stringlistSpy = sl; |
|
463 |
} |
|
464 |
||
465 |
void methodByteArray(const QByteArray &ba) |
|
466 |
{ |
|
467 |
slotSpy = "void TypesInterface::methodByteArray(const QByteArray &)"; |
|
468 |
bytearraySpy = ba; |
|
469 |
} |
|
470 |
||
471 |
void methodMap(const QVariantMap &m) |
|
472 |
{ |
|
473 |
slotSpy = "void TypesInterface::methodMap(const QVariantMap &)"; |
|
474 |
mapSpy = m; |
|
475 |
} |
|
476 |
||
477 |
void methodSSMap(const StringStringMap &ssmap) |
|
478 |
{ |
|
479 |
slotSpy = "void TypesInterface::methodSSMap(const StringStringMap &)"; |
|
480 |
ssmapSpy = ssmap; |
|
481 |
} |
|
482 |
||
483 |
void methodLLDateTimeMap(const LLDateTimeMap &lldtmap) |
|
484 |
{ |
|
485 |
slotSpy = "void TypesInterface::methodLLDateTimeMap(const LLDateTimeMap &)"; |
|
486 |
lldtmapSpy = lldtmap; |
|
487 |
} |
|
488 |
||
489 |
void methodStruct(const MyStruct &s) |
|
490 |
{ |
|
491 |
slotSpy = "void TypesInterface::methodStruct(const MyStruct &)"; |
|
492 |
structSpy = s; |
|
493 |
} |
|
494 |
||
495 |
bool retrieveBool() |
|
496 |
{ |
|
497 |
return dataSpy.b; |
|
498 |
} |
|
499 |
||
500 |
uchar retrieveUChar() |
|
501 |
{ |
|
502 |
return dataSpy.uc; |
|
503 |
} |
|
504 |
||
505 |
short retrieveShort() |
|
506 |
{ |
|
507 |
return dataSpy.s; |
|
508 |
} |
|
509 |
||
510 |
ushort retrieveUShort() |
|
511 |
{ |
|
512 |
return dataSpy.us; |
|
513 |
} |
|
514 |
||
515 |
int retrieveInt() |
|
516 |
{ |
|
517 |
return dataSpy.i; |
|
518 |
} |
|
519 |
||
520 |
uint retrieveUInt() |
|
521 |
{ |
|
522 |
return dataSpy.ui; |
|
523 |
} |
|
524 |
||
525 |
qlonglong retrieveLongLong() |
|
526 |
{ |
|
527 |
return dataSpy.ll; |
|
528 |
} |
|
529 |
||
530 |
qulonglong retrieveULongLong() |
|
531 |
{ |
|
532 |
return dataSpy.ull; |
|
533 |
} |
|
534 |
||
535 |
double retrieveDouble() |
|
536 |
{ |
|
537 |
return dataSpy.d; |
|
538 |
} |
|
539 |
||
540 |
QString retrieveString() |
|
541 |
{ |
|
542 |
return stringSpy; |
|
543 |
} |
|
544 |
||
545 |
QDBusObjectPath retrieveObjectPath() |
|
546 |
{ |
|
547 |
return QDBusObjectPath(stringSpy); |
|
548 |
} |
|
549 |
||
550 |
QDBusSignature retrieveSignature() |
|
551 |
{ |
|
552 |
return QDBusSignature(stringSpy); |
|
553 |
} |
|
554 |
||
555 |
QDBusVariant retrieveVariant() |
|
556 |
{ |
|
557 |
return QDBusVariant(variantSpy); |
|
558 |
} |
|
559 |
||
560 |
QVariantList retrieveList() |
|
561 |
{ |
|
562 |
return listSpy; |
|
563 |
} |
|
564 |
||
565 |
QStringList retrieveStringList() |
|
566 |
{ |
|
567 |
return stringlistSpy; |
|
568 |
} |
|
569 |
||
570 |
QByteArray retrieveByteArray() |
|
571 |
{ |
|
572 |
return bytearraySpy; |
|
573 |
} |
|
574 |
||
575 |
QVariantMap retrieveMap() |
|
576 |
{ |
|
577 |
return mapSpy; |
|
578 |
} |
|
579 |
||
580 |
StringStringMap retrieveSSMap() |
|
581 |
{ |
|
582 |
return ssmapSpy; |
|
583 |
} |
|
584 |
||
585 |
LLDateTimeMap retrieveLLDateTimeMap() |
|
586 |
{ |
|
587 |
return lldtmapSpy; |
|
588 |
} |
|
589 |
||
590 |
MyStruct retrieveStruct() |
|
591 |
{ |
|
592 |
return structSpy; |
|
593 |
} |
|
594 |
}; |
|
595 |
||
596 |
void tst_QDBusAbstractAdaptor::methodCalls_data() |
|
597 |
{ |
|
598 |
QTest::addColumn<int>("nInterfaces"); |
|
599 |
QTest::newRow("0") << 0; |
|
600 |
QTest::newRow("1") << 1; |
|
601 |
QTest::newRow("2") << 2; |
|
602 |
QTest::newRow("3") << 3; |
|
603 |
QTest::newRow("4") << 4; |
|
604 |
} |
|
605 |
||
606 |
void tst_QDBusAbstractAdaptor::methodCalls() |
|
607 |
{ |
|
608 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
609 |
QVERIFY(con.isConnected()); |
|
610 |
||
611 |
//QDBusInterface emptycon.baseService(), "/", QString()); |
|
612 |
||
613 |
{ |
|
614 |
// must fail: no object |
|
615 |
QDBusInterface if1(con.baseService(), "/", "local.Interface1", con); |
|
616 |
QCOMPARE(if1.call(QDBus::BlockWithGui, "method").type(), QDBusMessage::ErrorMessage); |
|
617 |
} |
|
618 |
||
619 |
QFETCH(int, nInterfaces); |
|
620 |
MyObject obj(nInterfaces); |
|
621 |
con.registerObject("/", &obj); |
|
622 |
||
623 |
QDBusInterface if1(con.baseService(), "/", "local.Interface1", con); |
|
624 |
QDBusInterface if2(con.baseService(), "/", "local.Interface2", con); |
|
625 |
QDBusInterface if3(con.baseService(), "/", "local.Interface3", con); |
|
626 |
QDBusInterface if4(con.baseService(), "/", "local.Interface4", con); |
|
627 |
||
628 |
// must fail: no such method |
|
629 |
QCOMPARE(if1.call(QDBus::BlockWithGui, "method").type(), QDBusMessage::ErrorMessage); |
|
630 |
if (!nInterfaces--) |
|
631 |
return; |
|
632 |
if (!nInterfaces--) |
|
633 |
return; |
|
634 |
||
635 |
// simple call: one such method exists |
|
636 |
QCOMPARE(if2.call(QDBus::BlockWithGui, "method").type(), QDBusMessage::ReplyMessage); |
|
637 |
QCOMPARE(slotSpy, "void Interface2::method()"); |
|
638 |
if (!nInterfaces--) |
|
639 |
return; |
|
640 |
||
641 |
// multiple methods in multiple interfaces, no name overlap |
|
642 |
QCOMPARE(if1.call(QDBus::BlockWithGui, "methodVoid").type(), QDBusMessage::ErrorMessage); |
|
643 |
QCOMPARE(if1.call(QDBus::BlockWithGui, "methodInt").type(), QDBusMessage::ErrorMessage); |
|
644 |
QCOMPARE(if1.call(QDBus::BlockWithGui, "methodString").type(), QDBusMessage::ErrorMessage); |
|
645 |
QCOMPARE(if2.call(QDBus::BlockWithGui, "methodVoid").type(), QDBusMessage::ErrorMessage); |
|
646 |
QCOMPARE(if2.call(QDBus::BlockWithGui, "methodInt").type(), QDBusMessage::ErrorMessage); |
|
647 |
QCOMPARE(if2.call(QDBus::BlockWithGui, "methodString").type(), QDBusMessage::ErrorMessage); |
|
648 |
||
649 |
QCOMPARE(if3.call(QDBus::BlockWithGui, "methodVoid").type(), QDBusMessage::ReplyMessage); |
|
650 |
QCOMPARE(slotSpy, "void Interface3::methodVoid()"); |
|
651 |
QCOMPARE(if3.call(QDBus::BlockWithGui, "methodInt", 42).type(), QDBusMessage::ReplyMessage); |
|
652 |
QCOMPARE(slotSpy, "void Interface3::methodInt(int)"); |
|
653 |
QCOMPARE(if3.call(QDBus::BlockWithGui, "methodString", QString("")).type(), QDBusMessage::ReplyMessage); |
|
654 |
QCOMPARE(slotSpy, "void Interface3::methodString(QString)"); |
|
655 |
||
656 |
if (!nInterfaces--) |
|
657 |
return; |
|
658 |
||
659 |
// method overloading: different interfaces |
|
660 |
QCOMPARE(if4.call(QDBus::BlockWithGui, "method").type(), QDBusMessage::ReplyMessage); |
|
661 |
QCOMPARE(slotSpy, "void Interface4::method()"); |
|
662 |
||
663 |
// method overloading: different parameters |
|
664 |
QCOMPARE(if4.call(QDBus::BlockWithGui, "method.i", 42).type(), QDBusMessage::ReplyMessage); |
|
665 |
QCOMPARE(slotSpy, "void Interface4::method(int)"); |
|
666 |
QCOMPARE(if4.call(QDBus::BlockWithGui, "method.s", QString()).type(), QDBusMessage::ReplyMessage); |
|
667 |
QCOMPARE(slotSpy, "void Interface4::method(QString)"); |
|
668 |
||
669 |
} |
|
670 |
||
671 |
void tst_QDBusAbstractAdaptor::methodCallScriptable() |
|
672 |
{ |
|
673 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
674 |
QVERIFY(con.isConnected()); |
|
675 |
||
676 |
MyObject obj(2); |
|
677 |
con.registerObject("/", &obj); |
|
678 |
||
679 |
QDBusInterface if2(con.baseService(), "/", "local.Interface2", con); |
|
680 |
||
681 |
QCOMPARE(if2.call(QDBus::BlockWithGui,"scriptableMethod").type(), QDBusMessage::ReplyMessage); |
|
682 |
QCOMPARE(slotSpy, "void Interface2::scriptableMethod()"); |
|
683 |
} |
|
684 |
||
685 |
static void emitSignal(MyObject *obj, const QString &iface, const QString &name, |
|
686 |
const QVariant ¶meter) |
|
687 |
{ |
|
688 |
if (iface.endsWith('2')) |
|
689 |
obj->if2->emitSignal(name, parameter); |
|
690 |
else if (iface.endsWith('3')) |
|
691 |
obj->if3->emitSignal(name, parameter); |
|
692 |
else if (iface.endsWith('4')) |
|
693 |
obj->if4->emitSignal(name, parameter); |
|
694 |
else |
|
695 |
obj->emitSignal(name, parameter); |
|
696 |
||
697 |
QTest::qWait(200); |
|
698 |
} |
|
699 |
||
700 |
void tst_QDBusAbstractAdaptor::signalEmissions_data() |
|
701 |
{ |
|
702 |
QTest::addColumn<QString>("interface"); |
|
703 |
QTest::addColumn<QString>("name"); |
|
704 |
QTest::addColumn<QString>("signature"); |
|
705 |
QTest::addColumn<QVariant>("parameter"); |
|
706 |
||
707 |
QTest::newRow("Interface2.signal") << "local.Interface2" << "signal" << QString() << QVariant(); |
|
708 |
QTest::newRow("Interface3.signalVoid") << "local.Interface3" << "signalVoid" << QString() << QVariant(); |
|
709 |
QTest::newRow("Interface3.signalInt") << "local.Interface3" << "signalInt" << "i" << QVariant(1); |
|
710 |
QTest::newRow("Interface3.signalString") << "local.Interface3" << "signalString" << "s" << QVariant("foo"); |
|
711 |
QTest::newRow("MyObject.scriptableSignalVoid") << "local.MyObject" << "scriptableSignalVoid" << QString() << QVariant(); |
|
712 |
QTest::newRow("MyObject.scriptableSignalInt") << "local.MyObject" << "scriptableSignalInt" << "i" << QVariant(1); |
|
713 |
QTest::newRow("MyObject.nySignalString") << "local.MyObject" << "scriptableSignalString" << "s" << QVariant("foo"); |
|
714 |
} |
|
715 |
||
716 |
void tst_QDBusAbstractAdaptor::signalEmissions() |
|
717 |
{ |
|
718 |
QFETCH(QString, interface); |
|
719 |
QFETCH(QString, name); |
|
720 |
QFETCH(QVariant, parameter); |
|
721 |
||
722 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
723 |
QVERIFY(con.isConnected()); |
|
724 |
con.registerService("com.trolltech.tst_QDBusAbstractAdaptor"); |
|
725 |
||
726 |
MyObject obj(3); |
|
727 |
con.registerObject("/", &obj, QDBusConnection::ExportAdaptors |
|
728 |
| QDBusConnection::ExportScriptableSignals); |
|
729 |
||
730 |
// connect all signals and emit only one |
|
731 |
{ |
|
732 |
QDBusSignalSpy spy; |
|
733 |
con.connect(con.baseService(), "/", "local.Interface2", "signal", |
|
734 |
&spy, SLOT(slot(QDBusMessage))); |
|
735 |
con.connect(con.baseService(), "/", "local.Interface3", "signalVoid", |
|
736 |
&spy, SLOT(slot(QDBusMessage))); |
|
737 |
con.connect(con.baseService(), "/", "local.Interface3", "signalInt", |
|
738 |
&spy, SLOT(slot(QDBusMessage))); |
|
739 |
con.connect(con.baseService(), "/", "local.Interface3", "signalString", |
|
740 |
&spy, SLOT(slot(QDBusMessage))); |
|
741 |
con.connect(con.baseService(), "/", "local.MyObject", "scriptableSignalVoid", |
|
742 |
&spy, SLOT(slot(QDBusMessage))); |
|
743 |
con.connect(con.baseService(), "/", "local.MyObject", "scriptableSignalInt", |
|
744 |
&spy, SLOT(slot(QDBusMessage))); |
|
745 |
con.connect(con.baseService(), "/", "local.MyObject", "scriptableSignalString", |
|
746 |
&spy, SLOT(slot(QDBusMessage))); |
|
747 |
||
748 |
emitSignal(&obj, interface, name, parameter); |
|
749 |
||
750 |
QCOMPARE(spy.count, 1); |
|
751 |
QCOMPARE(spy.interface, interface); |
|
752 |
QCOMPARE(spy.name, name); |
|
753 |
QTEST(spy.signature, "signature"); |
|
754 |
QCOMPARE(spy.value, parameter); |
|
755 |
} |
|
756 |
||
757 |
// connect one signal and emit them all |
|
758 |
{ |
|
759 |
QDBusSignalSpy spy; |
|
760 |
con.connect(con.baseService(), "/", interface, name, &spy, SLOT(slot(QDBusMessage))); |
|
761 |
emitSignal(&obj, "local.Interface2", "signal", QVariant()); |
|
762 |
emitSignal(&obj, "local.Interface3", "signalVoid", QVariant()); |
|
763 |
emitSignal(&obj, "local.Interface3", "signalInt", QVariant(1)); |
|
764 |
emitSignal(&obj, "local.Interface3", "signalString", QVariant("foo")); |
|
765 |
emitSignal(&obj, "local.MyObject", "scriptableSignalVoid", QVariant()); |
|
766 |
emitSignal(&obj, "local.MyObject", "scriptableSignalInt", QVariant(1)); |
|
767 |
emitSignal(&obj, "local.MyObject", "scriptableSignalString", QVariant("foo")); |
|
768 |
||
769 |
QCOMPARE(spy.count, 1); |
|
770 |
QCOMPARE(spy.interface, interface); |
|
771 |
QCOMPARE(spy.name, name); |
|
772 |
QTEST(spy.signature, "signature"); |
|
773 |
QCOMPARE(spy.value, parameter); |
|
774 |
} |
|
775 |
} |
|
776 |
||
777 |
void tst_QDBusAbstractAdaptor::sameSignalDifferentPaths() |
|
778 |
{ |
|
779 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
780 |
QVERIFY(con.isConnected()); |
|
781 |
||
782 |
MyObject obj(2); |
|
783 |
||
784 |
con.registerObject("/p1",&obj); |
|
785 |
con.registerObject("/p2",&obj); |
|
786 |
||
787 |
QDBusSignalSpy spy; |
|
788 |
con.connect(con.baseService(), "/p1", "local.Interface2", "signal", &spy, SLOT(slot(QDBusMessage))); |
|
789 |
obj.if2->emitSignal(QString(), QVariant()); |
|
790 |
QTest::qWait(200); |
|
791 |
||
792 |
QCOMPARE(spy.count, 1); |
|
793 |
QCOMPARE(spy.interface, QString("local.Interface2")); |
|
794 |
QCOMPARE(spy.name, QString("signal")); |
|
795 |
QVERIFY(spy.signature.isEmpty()); |
|
796 |
||
797 |
// now connect the other one |
|
798 |
spy.count = 0; |
|
799 |
con.connect(con.baseService(), "/p2", "local.Interface2", "signal", &spy, SLOT(slot(QDBusMessage))); |
|
800 |
obj.if2->emitSignal(QString(), QVariant()); |
|
801 |
QTest::qWait(200); |
|
802 |
||
803 |
QCOMPARE(spy.count, 2); |
|
804 |
} |
|
805 |
||
806 |
void tst_QDBusAbstractAdaptor::sameObjectDifferentPaths() |
|
807 |
{ |
|
808 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
809 |
QVERIFY(con.isConnected()); |
|
810 |
||
811 |
MyObject obj(2); |
|
812 |
||
813 |
con.registerObject("/p1",&obj); |
|
814 |
con.registerObject("/p2",&obj, 0); // don't export anything |
|
815 |
||
816 |
QDBusSignalSpy spy; |
|
817 |
con.connect(con.baseService(), "/p1", "local.Interface2", "signal", &spy, SLOT(slot(QDBusMessage))); |
|
818 |
con.connect(con.baseService(), "/p2", "local.Interface2", "signal", &spy, SLOT(slot(QDBusMessage))); |
|
819 |
obj.if2->emitSignal(QString(), QVariant()); |
|
820 |
QTest::qWait(200); |
|
821 |
||
822 |
QCOMPARE(spy.count, 1); |
|
823 |
QCOMPARE(spy.interface, QString("local.Interface2")); |
|
824 |
QCOMPARE(spy.name, QString("signal")); |
|
825 |
QVERIFY(spy.signature.isEmpty()); |
|
826 |
} |
|
827 |
||
828 |
void tst_QDBusAbstractAdaptor::scriptableSignalOrNot() |
|
829 |
{ |
|
830 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
831 |
QVERIFY(con.isConnected()); |
|
832 |
||
833 |
{ |
|
834 |
MyObject obj(0); |
|
835 |
||
836 |
con.registerObject("/p1",&obj, QDBusConnection::ExportScriptableSignals); |
|
837 |
con.registerObject("/p2",&obj, 0); // don't export anything |
|
838 |
||
839 |
QDBusSignalSpy spy; |
|
840 |
con.connect(con.baseService(), "/p1", "local.MyObject", "scriptableSignalVoid", &spy, SLOT(slot(QDBusMessage))); |
|
841 |
con.connect(con.baseService(), "/p2", "local.MyObject", "scriptableSignalVoid", &spy, SLOT(slot(QDBusMessage))); |
|
842 |
con.connect(con.baseService(), "/p1", "local.MyObject", "nonScriptableSignalVoid", &spy, SLOT(slot(QDBusMessage))); |
|
843 |
con.connect(con.baseService(), "/p2", "local.MyObject", "nonScriptableSignalVoid", &spy, SLOT(slot(QDBusMessage))); |
|
844 |
obj.emitSignal("scriptableSignalVoid", QVariant()); |
|
845 |
obj.emitSignal("nonScriptableSignalVoid", QVariant()); |
|
846 |
QTest::qWait(200); |
|
847 |
||
848 |
QCOMPARE(spy.count, 1); // only /p1 must have emitted |
|
849 |
QCOMPARE(spy.interface, QString("local.MyObject")); |
|
850 |
QCOMPARE(spy.name, QString("scriptableSignalVoid")); |
|
851 |
QCOMPARE(spy.path, QString("/p1")); |
|
852 |
QVERIFY(spy.signature.isEmpty()); |
|
853 |
} |
|
854 |
||
855 |
{ |
|
856 |
MyObject obj(0); |
|
857 |
||
858 |
con.registerObject("/p1",&obj, QDBusConnection::ExportScriptableSignals); |
|
859 |
con.registerObject("/p2",&obj, QDBusConnection::ExportScriptableSignals |
|
860 |
| QDBusConnection::ExportNonScriptableSignals); |
|
861 |
||
862 |
QDBusSignalSpy spy; |
|
863 |
con.connect(con.baseService(), "/p1", "local.MyObject", "nonScriptableSignalVoid", &spy, SLOT(slot(QDBusMessage))); |
|
864 |
con.connect(con.baseService(), "/p2", "local.MyObject", "nonScriptableSignalVoid", &spy, SLOT(slot(QDBusMessage))); |
|
865 |
obj.emitSignal("nonScriptableSignalVoid", QVariant()); |
|
866 |
QTest::qWait(200); |
|
867 |
||
868 |
QCOMPARE(spy.count, 1); // only /p2 must have emitted now |
|
869 |
QCOMPARE(spy.interface, QString("local.MyObject")); |
|
870 |
QCOMPARE(spy.name, QString("nonScriptableSignalVoid")); |
|
871 |
QCOMPARE(spy.path, QString("/p2")); |
|
872 |
QVERIFY(spy.signature.isEmpty()); |
|
873 |
} |
|
874 |
||
875 |
{ |
|
876 |
QDBusSignalSpy spy; |
|
877 |
con.connect(con.baseService(), "/p1", "local.MyObject", "destroyed", &spy, SLOT(slot(QDBusMessage))); |
|
878 |
con.connect(con.baseService(), "/p2", "local.MyObject", "destroyed", &spy, SLOT(slot(QDBusMessage))); |
|
879 |
||
880 |
{ |
|
881 |
MyObject obj(0); |
|
882 |
||
883 |
con.registerObject("/p1",&obj, QDBusConnection::ExportScriptableSignals); |
|
884 |
con.registerObject("/p2",&obj, QDBusConnection::ExportScriptableSignals |
|
885 |
| QDBusConnection::ExportNonScriptableSignals); |
|
886 |
} // <--- QObject emits the destroyed(QObject*) signal at this point |
|
887 |
||
888 |
QTest::qWait(200); |
|
889 |
||
890 |
QCOMPARE(spy.count, 0); |
|
891 |
} |
|
892 |
} |
|
893 |
||
894 |
void tst_QDBusAbstractAdaptor::overloadedSignalEmission_data() |
|
895 |
{ |
|
896 |
QTest::addColumn<QString>("signature"); |
|
897 |
QTest::addColumn<QVariant>("parameter"); |
|
898 |
QTest::newRow("void") << QString("") << QVariant(); |
|
899 |
QTest::newRow("int") << "i" << QVariant(1); |
|
900 |
QTest::newRow("string") << "s" << QVariant("foo"); |
|
901 |
} |
|
902 |
||
903 |
void tst_QDBusAbstractAdaptor::overloadedSignalEmission() |
|
904 |
{ |
|
905 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
906 |
QVERIFY(con.isConnected()); |
|
907 |
||
908 |
MyObject obj; |
|
909 |
con.registerObject("/", &obj); |
|
910 |
||
911 |
QString interface = "local.Interface4"; |
|
912 |
QString name = "signal"; |
|
913 |
QFETCH(QVariant, parameter); |
|
914 |
//QDBusInterface *if4 = new QDBusInterface(con.baseService(), "/", interface, con); |
|
915 |
||
916 |
// connect all signals and emit only one |
|
917 |
{ |
|
918 |
QDBusSignalSpy spy; |
|
919 |
con.connect(con.baseService(), "/", "local.Interface4", "signal", "", |
|
920 |
&spy, SLOT(slot(QDBusMessage))); |
|
921 |
con.connect(con.baseService(), "/", "local.Interface4", "signal", "i", |
|
922 |
&spy, SLOT(slot(QDBusMessage))); |
|
923 |
con.connect(con.baseService(), "/", "local.Interface4", "signal", "s", |
|
924 |
&spy, SLOT(slot(QDBusMessage))); |
|
925 |
||
926 |
emitSignal(&obj, interface, name, parameter); |
|
927 |
||
928 |
QCOMPARE(spy.count, 1); |
|
929 |
QCOMPARE(spy.interface, interface); |
|
930 |
QCOMPARE(spy.name, name); |
|
931 |
QTEST(spy.signature, "signature"); |
|
932 |
QCOMPARE(spy.value, parameter); |
|
933 |
} |
|
934 |
||
935 |
QFETCH(QString, signature); |
|
936 |
// connect one signal and emit them all |
|
937 |
{ |
|
938 |
QDBusSignalSpy spy; |
|
939 |
con.connect(con.baseService(), "/", interface, name, signature, &spy, SLOT(slot(QDBusMessage))); |
|
940 |
emitSignal(&obj, "local.Interface4", "signal", QVariant()); |
|
941 |
emitSignal(&obj, "local.Interface4", "signal", QVariant(1)); |
|
942 |
emitSignal(&obj, "local.Interface4", "signal", QVariant("foo")); |
|
943 |
||
944 |
QCOMPARE(spy.count, 1); |
|
945 |
QCOMPARE(spy.interface, interface); |
|
946 |
QCOMPARE(spy.name, name); |
|
947 |
QTEST(spy.signature, "signature"); |
|
948 |
QCOMPARE(spy.value, parameter); |
|
949 |
} |
|
950 |
} |
|
951 |
||
952 |
void tst_QDBusAbstractAdaptor::readProperties() |
|
953 |
{ |
|
954 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
955 |
QVERIFY(con.isConnected()); |
|
956 |
||
957 |
MyObject obj; |
|
958 |
con.registerObject("/", &obj); |
|
959 |
||
960 |
QDBusInterface properties(con.baseService(), "/", "org.freedesktop.DBus.Properties", con); |
|
961 |
for (int i = 2; i <= 4; ++i) { |
|
962 |
QString name = QString("Interface%1").arg(i); |
|
963 |
||
964 |
for (int j = 1; j <= 2; ++j) { |
|
965 |
QString propname = QString("prop%1").arg(j); |
|
966 |
QDBusReply<QVariant> reply = |
|
967 |
properties.call(QDBus::BlockWithGui, "Get", "local." + name, propname); |
|
968 |
QVariant value = reply; |
|
969 |
||
970 |
QCOMPARE(value.userType(), int(QVariant::String)); |
|
971 |
QCOMPARE(value.toString(), QString("QString %1::%2() const").arg(name, propname)); |
|
972 |
} |
|
973 |
} |
|
974 |
} |
|
975 |
||
976 |
void tst_QDBusAbstractAdaptor::readPropertiesInvalidInterface() |
|
977 |
{ |
|
978 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
979 |
QVERIFY(con.isConnected()); |
|
980 |
||
981 |
MyObject obj; |
|
982 |
con.registerObject("/", &obj); |
|
983 |
||
984 |
QDBusInterface properties(con.baseService(), "/", "org.freedesktop.DBus.Properties", con); |
|
985 |
||
986 |
// test an invalid interface: |
|
987 |
QDBusReply<QVariant> reply = properties.call(QDBus::BlockWithGui, "Get", "local.DoesntExist", "prop1"); |
|
988 |
QVERIFY(!reply.isValid()); |
|
989 |
} |
|
990 |
||
991 |
void tst_QDBusAbstractAdaptor::readPropertiesEmptyInterface_data() |
|
992 |
{ |
|
993 |
QTest::addColumn<QVariantMap>("expectedProperties"); |
|
994 |
QTest::addColumn<bool>("existing"); |
|
995 |
||
996 |
QVariantMap expectedProperties; |
|
997 |
expectedProperties["prop1"] = QVariant(); |
|
998 |
expectedProperties["prop2"] = QVariant(); |
|
999 |
expectedProperties["interface3prop"] = "QString Interface3::interface3prop() const"; |
|
1000 |
expectedProperties["interface4prop"] = "QString Interface4::interface4prop() const"; |
|
1001 |
QTest::newRow("existing") << expectedProperties << true; |
|
1002 |
||
1003 |
expectedProperties.clear(); |
|
1004 |
expectedProperties["prop5"] = QVariant(); |
|
1005 |
expectedProperties["foobar"] = QVariant(); |
|
1006 |
QTest::newRow("non-existing") << expectedProperties << false; |
|
1007 |
} |
|
1008 |
||
1009 |
void tst_QDBusAbstractAdaptor::readPropertiesEmptyInterface() |
|
1010 |
{ |
|
1011 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
1012 |
QVERIFY(con.isConnected()); |
|
1013 |
||
1014 |
MyObject obj; |
|
1015 |
con.registerObject("/", &obj); |
|
1016 |
||
1017 |
QDBusInterface properties(con.baseService(), "/", "org.freedesktop.DBus.Properties", con); |
|
1018 |
||
1019 |
QFETCH(QVariantMap, expectedProperties); |
|
1020 |
QFETCH(bool, existing); |
|
1021 |
||
1022 |
QVariantMap::ConstIterator it = expectedProperties.constBegin(); |
|
1023 |
for ( ; it != expectedProperties.constEnd(); ++it) { |
|
1024 |
QDBusReply<QVariant> reply = properties.call(QDBus::BlockWithGui, "Get", "", it.key()); |
|
1025 |
||
1026 |
if (existing) { |
|
1027 |
QVERIFY2(reply.isValid(), qPrintable(it.key())); |
|
1028 |
} else { |
|
1029 |
QVERIFY2(!reply.isValid(), qPrintable(it.key())); |
|
1030 |
continue; |
|
1031 |
} |
|
1032 |
||
1033 |
QCOMPARE(int(reply.value().type()), int(QVariant::String)); |
|
1034 |
if (it.value().isValid()) |
|
1035 |
QCOMPARE(reply.value().toString(), it.value().toString()); |
|
1036 |
} |
|
1037 |
} |
|
1038 |
||
1039 |
void tst_QDBusAbstractAdaptor::readAllProperties() |
|
1040 |
{ |
|
1041 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
1042 |
QVERIFY(con.isConnected()); |
|
1043 |
||
1044 |
MyObject obj; |
|
1045 |
con.registerObject("/", &obj); |
|
1046 |
||
1047 |
QDBusInterface properties(con.baseService(), "/", "org.freedesktop.DBus.Properties", con); |
|
1048 |
for (int i = 2; i <= 4; ++i) { |
|
1049 |
QString name = QString("Interface%1").arg(i); |
|
1050 |
QDBusReply<QVariantMap> reply = |
|
1051 |
properties.call(QDBus::BlockWithGui, "GetAll", "local." + name); |
|
1052 |
||
1053 |
for (int j = 1; j <= 2; ++j) { |
|
1054 |
QString propname = QString("prop%1").arg(j); |
|
1055 |
QVERIFY2(reply.value().contains(propname), |
|
1056 |
qPrintable(propname + " on " + name)); |
|
1057 |
QVariant value = reply.value().value(propname); |
|
1058 |
||
1059 |
QCOMPARE(value.userType(), int(QVariant::String)); |
|
1060 |
QCOMPARE(value.toString(), QString("QString %1::%2() const").arg(name, propname)); |
|
1061 |
} |
|
1062 |
} |
|
1063 |
} |
|
1064 |
||
1065 |
void tst_QDBusAbstractAdaptor::readAllPropertiesInvalidInterface() |
|
1066 |
{ |
|
1067 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
1068 |
QVERIFY(con.isConnected()); |
|
1069 |
||
1070 |
MyObject obj; |
|
1071 |
con.registerObject("/", &obj); |
|
1072 |
||
1073 |
QDBusInterface properties(con.baseService(), "/", "org.freedesktop.DBus.Properties", con); |
|
1074 |
||
1075 |
// test an invalid interface: |
|
1076 |
QDBusReply<QVariantMap> reply = properties.call(QDBus::BlockWithGui, "GetAll", "local.DoesntExist"); |
|
1077 |
QVERIFY(!reply.isValid()); |
|
1078 |
} |
|
1079 |
||
1080 |
void tst_QDBusAbstractAdaptor::readAllPropertiesEmptyInterface_data() |
|
1081 |
{ |
|
1082 |
readPropertiesEmptyInterface_data(); |
|
1083 |
} |
|
1084 |
||
1085 |
void tst_QDBusAbstractAdaptor::readAllPropertiesEmptyInterface() |
|
1086 |
{ |
|
1087 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
1088 |
QVERIFY(con.isConnected()); |
|
1089 |
||
1090 |
MyObject obj; |
|
1091 |
con.registerObject("/", &obj); |
|
1092 |
||
1093 |
QDBusInterface properties(con.baseService(), "/", "org.freedesktop.DBus.Properties", con); |
|
1094 |
||
1095 |
QDBusReply<QVariantMap> reply = properties.call(QDBus::BlockWithGui, "GetAll", ""); |
|
1096 |
QVERIFY(reply.isValid()); |
|
1097 |
||
1098 |
QVariantMap allprops = reply; |
|
1099 |
||
1100 |
QFETCH(QVariantMap, expectedProperties); |
|
1101 |
QFETCH(bool, existing); |
|
1102 |
||
1103 |
QVariantMap::ConstIterator it = expectedProperties.constBegin(); |
|
1104 |
if (existing) { |
|
1105 |
for ( ; it != expectedProperties.constEnd(); ++it) { |
|
1106 |
QVERIFY2(allprops.contains(it.key()), qPrintable(it.key())); |
|
1107 |
||
1108 |
QVariant propvalue = allprops.value(it.key()); |
|
1109 |
QVERIFY2(!propvalue.isNull(), qPrintable(it.key())); |
|
1110 |
QVERIFY2(propvalue.isValid(), qPrintable(it.key())); |
|
1111 |
||
1112 |
QString stringvalue = propvalue.toString(); |
|
1113 |
QVERIFY2(!stringvalue.isEmpty(), qPrintable(it.key())); |
|
1114 |
||
1115 |
if (it.value().isValid()) |
|
1116 |
QCOMPARE(stringvalue, it.value().toString()); |
|
1117 |
||
1118 |
// remove this property from the map |
|
1119 |
allprops.remove(it.key()); |
|
1120 |
} |
|
1121 |
||
1122 |
QVERIFY2(allprops.isEmpty(), |
|
1123 |
qPrintable(QStringList(allprops.keys()).join(" "))); |
|
1124 |
} else { |
|
1125 |
for ( ; it != expectedProperties.constEnd(); ++it) |
|
1126 |
QVERIFY2(!allprops.contains(it.key()), qPrintable(it.key())); |
|
1127 |
} |
|
1128 |
} |
|
1129 |
||
1130 |
void tst_QDBusAbstractAdaptor::writeProperties() |
|
1131 |
{ |
|
1132 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
1133 |
QVERIFY(con.isConnected()); |
|
1134 |
||
1135 |
MyObject obj; |
|
1136 |
con.registerObject("/", &obj); |
|
1137 |
||
1138 |
QDBusInterface properties(con.baseService(), "/", "org.freedesktop.DBus.Properties", con); |
|
1139 |
for (int i = 2; i <= 4; ++i) { |
|
1140 |
QString name = QString("Interface%1").arg(i); |
|
1141 |
||
1142 |
valueSpy.clear(); |
|
1143 |
properties.call(QDBus::BlockWithGui, "Set", "local." + name, QString("prop1"), |
|
1144 |
qVariantFromValue(QDBusVariant(name))); |
|
1145 |
QVERIFY(valueSpy.isEmpty()); // call mustn't have succeeded |
|
1146 |
||
1147 |
properties.call(QDBus::BlockWithGui, "Set", "local." + name, QString("prop2"), |
|
1148 |
qVariantFromValue(QDBusVariant(name))); |
|
1149 |
QCOMPARE(valueSpy, name); |
|
1150 |
QCOMPARE(QString(slotSpy), QString("void %1::setProp2(const QString &)").arg(name)); |
|
1151 |
} |
|
1152 |
} |
|
1153 |
||
1154 |
#if 0 |
|
1155 |
void tst_QDBusAbstractAdaptor::adaptorIntrospection_data() |
|
1156 |
{ |
|
1157 |
methodCalls_data(); |
|
1158 |
} |
|
1159 |
||
1160 |
void tst_QDBusAbstractAdaptor::adaptorIntrospection() |
|
1161 |
{ |
|
1162 |
QDBusConnection con = QDBus::sessionBus(); |
|
1163 |
QVERIFY(con.isConnected()); |
|
1164 |
||
1165 |
QObject obj; |
|
1166 |
con.registerObject("/", &obj); |
|
1167 |
||
1168 |
QFETCH(int, nInterfaces); |
|
1169 |
switch (nInterfaces) |
|
1170 |
{ |
|
1171 |
case 4: |
|
1172 |
new Interface4(&obj); |
|
1173 |
case 3: |
|
1174 |
new Interface3(&obj); |
|
1175 |
case 2: |
|
1176 |
new Interface2(&obj); |
|
1177 |
case 1: |
|
1178 |
new Interface1(&obj); |
|
1179 |
} |
|
1180 |
||
1181 |
QDBusObject dobj = con.findObject(con.baseService(), "/"); |
|
1182 |
QVERIFY(dobj.isValid()); |
|
1183 |
||
1184 |
QString xml = dobj.introspect(); |
|
1185 |
QVERIFY(!xml.isEmpty()); |
|
1186 |
||
1187 |
QStringList interfaces = dobj.interfaces(); |
|
1188 |
QCOMPARE(interfaces.count(), nInterfaces + 2); |
|
1189 |
switch (nInterfaces) |
|
1190 |
{ |
|
1191 |
case 4: { |
|
1192 |
QVERIFY(interfaces.contains("local.Interface4")); |
|
1193 |
QDBusInterface iface(dobj, "local.Interface4"); |
|
1194 |
QCOMPARE(iface.methodData(), Interface4::methodData); |
|
1195 |
QCOMPARE(iface.signalData(), Interface4::signalData); |
|
1196 |
QCOMPARE(iface.propertyData(), Interface4::propertyData); |
|
1197 |
} |
|
1198 |
case 3: { |
|
1199 |
QVERIFY(interfaces.contains("local.Interface3")); |
|
1200 |
QDBusInterface iface(dobj, "local.Interface3"); |
|
1201 |
QCOMPARE(iface.methodData(), Interface3::methodData); |
|
1202 |
QCOMPARE(iface.signalData(), Interface3::signalData); |
|
1203 |
QCOMPARE(iface.propertyData(), Interface3::propertyData); |
|
1204 |
} |
|
1205 |
case 2: { |
|
1206 |
QVERIFY(interfaces.contains("local.Interface2")); |
|
1207 |
QDBusInterface iface(dobj, "local.Interface2"); |
|
1208 |
QCOMPARE(iface.methodData(), Interface2::methodData); |
|
1209 |
QCOMPARE(iface.signalData(), Interface2::signalData); |
|
1210 |
QCOMPARE(iface.propertyData(), Interface2::propertyData); |
|
1211 |
} |
|
1212 |
case 1: { |
|
1213 |
QVERIFY(interfaces.contains("local.Interface1")); |
|
1214 |
QDBusInterface iface(dobj, "local.Interface1"); |
|
1215 |
QCOMPARE(iface.methodData(), Interface1::methodData); |
|
1216 |
QCOMPARE(iface.signalData(), Interface1::signalData); |
|
1217 |
QCOMPARE(iface.propertyData(), Interface1::propertyData); |
|
1218 |
} |
|
1219 |
} |
|
1220 |
} |
|
1221 |
||
1222 |
void tst_QDBusAbstractAdaptor::objectTreeIntrospection() |
|
1223 |
{ |
|
1224 |
QDBusConnection con = QDBus::sessionBus(); |
|
1225 |
QVERIFY(con.isConnected()); |
|
1226 |
||
1227 |
{ |
|
1228 |
QDBusObject dobj = con.findObject(con.baseService(), "/"); |
|
1229 |
QString xml = dobj.introspect(); |
|
1230 |
||
1231 |
QDBusIntrospection::Object tree = |
|
1232 |
QDBusIntrospection::parseObject(xml); |
|
1233 |
QVERIFY(tree.childObjects.isEmpty()); |
|
1234 |
} |
|
1235 |
||
1236 |
QObject root; |
|
1237 |
con.registerObject("/", &root); |
|
1238 |
{ |
|
1239 |
QDBusObject dobj = con.findObject(con.baseService(), "/"); |
|
1240 |
QString xml = dobj.introspect(); |
|
1241 |
||
1242 |
QDBusIntrospection::Object tree = |
|
1243 |
QDBusIntrospection::parseObject(xml); |
|
1244 |
QVERIFY(tree.childObjects.isEmpty()); |
|
1245 |
} |
|
1246 |
||
1247 |
QObject p1; |
|
1248 |
con.registerObject("/p1", &p1); |
|
1249 |
{ |
|
1250 |
QDBusObject dobj = con.findObject(con.baseService(), "/"); |
|
1251 |
QString xml = dobj.introspect(); |
|
1252 |
||
1253 |
QDBusIntrospection::Object tree = |
|
1254 |
QDBusIntrospection::parseObject(xml); |
|
1255 |
QVERIFY(tree.childObjects.contains("p1")); |
|
1256 |
} |
|
1257 |
||
1258 |
con.unregisterObject("/"); |
|
1259 |
{ |
|
1260 |
QDBusObject dobj = con.findObject(con.baseService(), "/"); |
|
1261 |
QString xml = dobj.introspect(); |
|
1262 |
||
1263 |
QDBusIntrospection::Object tree = |
|
1264 |
QDBusIntrospection::parseObject(xml); |
|
1265 |
QVERIFY(tree.childObjects.contains("p1")); |
|
1266 |
} |
|
1267 |
||
1268 |
con.registerObject("/p1/q/r", &root); |
|
1269 |
{ |
|
1270 |
QDBusObject dobj = con.findObject(con.baseService(), "/p1"); |
|
1271 |
QString xml = dobj.introspect(); |
|
1272 |
||
1273 |
QDBusIntrospection::Object tree = |
|
1274 |
QDBusIntrospection::parseObject(xml); |
|
1275 |
QVERIFY(tree.childObjects.contains("q")); |
|
1276 |
} |
|
1277 |
{ |
|
1278 |
QDBusObject dobj = con.findObject(con.baseService(), "/p1/q"); |
|
1279 |
QString xml = dobj.introspect(); |
|
1280 |
||
1281 |
QDBusIntrospection::Object tree = |
|
1282 |
QDBusIntrospection::parseObject(xml); |
|
1283 |
QVERIFY(tree.childObjects.contains("r")); |
|
1284 |
} |
|
1285 |
||
1286 |
con.unregisterObject("/p1", QDBusConnection::UnregisterTree); |
|
1287 |
{ |
|
1288 |
QDBusObject dobj = con.findObject(con.baseService(), "/"); |
|
1289 |
QString xml = dobj.introspect(); |
|
1290 |
||
1291 |
QDBusIntrospection::Object tree = |
|
1292 |
QDBusIntrospection::parseObject(xml); |
|
1293 |
QVERIFY(tree.childObjects.isEmpty()); |
|
1294 |
} |
|
1295 |
||
1296 |
QObject p2; |
|
1297 |
con.registerObject("/p2", &p2, QDBusConnection::ExportChildObjects); |
|
1298 |
{ |
|
1299 |
QDBusObject dobj = con.findObject(con.baseService(), "/"); |
|
1300 |
QString xml = dobj.introspect(); |
|
1301 |
||
1302 |
QDBusIntrospection::Object tree = |
|
1303 |
QDBusIntrospection::parseObject(xml); |
|
1304 |
QVERIFY(!tree.childObjects.contains("p1")); |
|
1305 |
QVERIFY(tree.childObjects.contains("p2")); |
|
1306 |
} |
|
1307 |
||
1308 |
QObject q; |
|
1309 |
q.setParent(&p2); |
|
1310 |
{ |
|
1311 |
QDBusObject dobj = con.findObject(con.baseService(), "/p2"); |
|
1312 |
QString xml = dobj.introspect(); |
|
1313 |
||
1314 |
QDBusIntrospection::Object tree = |
|
1315 |
QDBusIntrospection::parseObject(xml); |
|
1316 |
QVERIFY(!tree.childObjects.contains("q")); |
|
1317 |
} |
|
1318 |
||
1319 |
q.setObjectName("q"); |
|
1320 |
{ |
|
1321 |
QDBusObject dobj = con.findObject(con.baseService(), "/p2"); |
|
1322 |
QString xml = dobj.introspect(); |
|
1323 |
||
1324 |
QDBusIntrospection::Object tree = |
|
1325 |
QDBusIntrospection::parseObject(xml); |
|
1326 |
QVERIFY(tree.childObjects.contains("q")); |
|
1327 |
} |
|
1328 |
||
1329 |
q.setParent(0); |
|
1330 |
{ |
|
1331 |
QDBusObject dobj = con.findObject(con.baseService(), "/p2"); |
|
1332 |
QString xml = dobj.introspect(); |
|
1333 |
||
1334 |
QDBusIntrospection::Object tree = |
|
1335 |
QDBusIntrospection::parseObject(xml); |
|
1336 |
QVERIFY(!tree.childObjects.contains("q")); |
|
1337 |
} |
|
1338 |
} |
|
1339 |
#endif |
|
1340 |
||
1341 |
void tst_QDBusAbstractAdaptor::typeMatching_data() |
|
1342 |
{ |
|
1343 |
QTest::addColumn<QString>("basename"); |
|
1344 |
QTest::addColumn<QString>("signature"); |
|
1345 |
QTest::addColumn<QVariant>("value"); |
|
1346 |
||
1347 |
QTest::newRow("bool") << "Bool" << "b" << QVariant(true); |
|
1348 |
QTest::newRow("byte") << "UChar" << "y" << qVariantFromValue(uchar(42)); |
|
1349 |
QTest::newRow("short") << "Short" << "n" << qVariantFromValue(short(-43)); |
|
1350 |
QTest::newRow("ushort") << "UShort" << "q" << qVariantFromValue(ushort(44)); |
|
1351 |
QTest::newRow("int") << "Int" << "i" << QVariant(42); |
|
1352 |
QTest::newRow("uint") << "UInt" << "u" << QVariant(42U); |
|
1353 |
QTest::newRow("qlonglong") << "LongLong" << "x" << QVariant(Q_INT64_C(42)); |
|
1354 |
QTest::newRow("qulonglong") << "ULongLong" << "t" << QVariant(Q_UINT64_C(42)); |
|
1355 |
QTest::newRow("double") << "Double" << "d" << QVariant(2.5); |
|
1356 |
QTest::newRow("string") << "String" << "s" << QVariant("Hello, World!"); |
|
1357 |
||
1358 |
QTest::newRow("variant") << "Variant" << "v" << qVariantFromValue(QDBusVariant("Hello again!")); |
|
1359 |
QTest::newRow("list") << "List" << "av" << QVariant(QVariantList() |
|
1360 |
<< 42 |
|
1361 |
<< QString("foo") |
|
1362 |
<< QByteArray("bar") |
|
1363 |
<< qVariantFromValue(QDBusVariant(QString("baz")))); |
|
1364 |
QTest::newRow("stringlist") << "StringList" << "as" << QVariant(QStringList() << "Hello" << "world"); |
|
1365 |
QTest::newRow("bytearray") << "ByteArray" << "ay" << QVariant(QByteArray("foo")); |
|
1366 |
||
1367 |
QVariantMap map; |
|
1368 |
map["one"] = 1; // int |
|
1369 |
map["The answer to life, the Universe and everything"] = 42u; // uint |
|
1370 |
map["In the beginning..."] = QString("There was nothing"); // string |
|
1371 |
map["but Unix came and said"] = QByteArray("\"Hello, World\""); // bytearray |
|
1372 |
map["two"] = qVariantFromValue(short(2)); // short |
|
1373 |
QTest::newRow("map") << "Map" << "a{sv}" << QVariant(map); |
|
1374 |
||
1375 |
StringStringMap ssmap; |
|
1376 |
ssmap["a"] = "A"; |
|
1377 |
ssmap["A"] = "a"; |
|
1378 |
QTest::newRow("ssmap") << "SSMap" << "a{ss}" << qVariantFromValue(ssmap); |
|
1379 |
||
1380 |
LLDateTimeMap lldtmap; |
|
1381 |
lldtmap[-1] = QDateTime(); |
|
1382 |
QDateTime now = QDateTime::currentDateTime(); |
|
1383 |
lldtmap[now.toTime_t()] = now; // array of struct of int64 and struct of 3 ints and struct of 4 ints and int |
|
1384 |
QTest::newRow("lldtmap") << "LLDateTimeMap" << "a{x((iii)(iiii)i)}" << qVariantFromValue(lldtmap); |
|
1385 |
||
1386 |
MyStruct s; |
|
1387 |
s.i = 42; |
|
1388 |
s.s = "A value"; |
|
1389 |
QTest::newRow("struct") << "Struct" << "(is)" << qVariantFromValue(s); |
|
1390 |
} |
|
1391 |
||
1392 |
void tst_QDBusAbstractAdaptor::typeMatching() |
|
1393 |
{ |
|
1394 |
QObject obj; |
|
1395 |
new TypesInterface(&obj); |
|
1396 |
||
1397 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
1398 |
con.registerObject("/types", &obj); |
|
1399 |
||
1400 |
QFETCH(QString, basename); |
|
1401 |
QFETCH(QString, signature); |
|
1402 |
QFETCH(QVariant, value); |
|
1403 |
||
1404 |
QDBusMessage reply; |
|
1405 |
QDBusInterface iface(con.baseService(), "/types", "local.TypesInterface", con); |
|
1406 |
||
1407 |
reply = iface.callWithArgumentList(QDBus::BlockWithGui, "method" + basename, |
|
1408 |
QVariantList() << value); |
|
1409 |
QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); |
|
1410 |
||
1411 |
reply = iface.call(QDBus::BlockWithGui, "retrieve" + basename); |
|
1412 |
QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); |
|
1413 |
QCOMPARE(reply.arguments().count(), 1); |
|
1414 |
||
1415 |
const QVariant &retval = reply.arguments().at(0); |
|
1416 |
QVERIFY(compare(retval, value)); |
|
1417 |
} |
|
1418 |
||
1419 |
void tst_QDBusAbstractAdaptor::methodWithMoreThanOneReturnValue() |
|
1420 |
{ |
|
1421 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
1422 |
QVERIFY(con.isConnected()); |
|
1423 |
||
1424 |
MyObject obj; |
|
1425 |
con.registerObject("/", &obj); |
|
1426 |
||
1427 |
QString testString = "This is a test string."; |
|
1428 |
||
1429 |
QDBusInterface remote(con.baseService(), "/", "local.Interface3", con); |
|
1430 |
QDBusMessage reply = remote.call(QDBus::BlockWithGui, "methodStringString", testString); |
|
1431 |
QVERIFY(reply.arguments().count() == 2); |
|
1432 |
||
1433 |
QDBusReply<int> intreply = reply; |
|
1434 |
QVERIFY(intreply.isValid()); |
|
1435 |
QCOMPARE(intreply.value(), 42); |
|
1436 |
||
1437 |
QCOMPARE(reply.arguments().at(1).userType(), int(QVariant::String)); |
|
1438 |
QCOMPARE(qdbus_cast<QString>(reply.arguments().at(1)), testString); |
|
1439 |
} |
|
1440 |
||
1441 |
QTEST_MAIN(tst_QDBusAbstractAdaptor) |
|
1442 |
||
1443 |
#include "tst_qdbusabstractadaptor.moc" |