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 <qsharedpointer.h> |
|
44 |
||
45 |
#include <QtTest/QtTest> |
|
46 |
||
47 |
#include <QtDBus> |
|
48 |
||
49 |
#include "interface.h" |
|
50 |
#include "pinger.h" |
|
51 |
||
52 |
typedef QSharedPointer<com::trolltech::QtDBus::Pinger> Pinger; |
|
53 |
||
54 |
class tst_QDBusAbstractInterface: public QObject |
|
55 |
{ |
|
56 |
Q_OBJECT |
|
57 |
Interface targetObj; |
|
58 |
||
59 |
Pinger getPinger(QString service = "", const QString &path = "/") |
|
60 |
{ |
|
61 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
62 |
if (!con.isConnected()) |
|
63 |
return Pinger(); |
|
64 |
if (service.isEmpty() && !service.isNull()) |
|
65 |
service = con.baseService(); |
|
66 |
return Pinger(new com::trolltech::QtDBus::Pinger(service, path, con)); |
|
67 |
} |
|
68 |
||
69 |
public: |
|
70 |
tst_QDBusAbstractInterface(); |
|
71 |
||
72 |
private slots: |
|
73 |
void initTestCase(); |
|
74 |
||
75 |
void makeVoidCall(); |
|
76 |
void makeStringCall(); |
|
77 |
void makeComplexCall(); |
|
78 |
void makeMultiOutCall(); |
|
79 |
||
80 |
void makeAsyncVoidCall(); |
|
81 |
void makeAsyncStringCall(); |
|
82 |
void makeAsyncComplexCall(); |
|
83 |
void makeAsyncMultiOutCall(); |
|
84 |
||
85 |
void stringPropRead(); |
|
86 |
void stringPropWrite(); |
|
87 |
void variantPropRead(); |
|
88 |
void variantPropWrite(); |
|
89 |
void complexPropRead(); |
|
90 |
void complexPropWrite(); |
|
91 |
||
92 |
void stringPropDirectRead(); |
|
93 |
void stringPropDirectWrite(); |
|
94 |
void variantPropDirectRead(); |
|
95 |
void variantPropDirectWrite(); |
|
96 |
void complexPropDirectRead(); |
|
97 |
void complexPropDirectWrite(); |
|
98 |
||
99 |
void getVoidSignal_data(); |
|
100 |
void getVoidSignal(); |
|
101 |
void getStringSignal_data(); |
|
102 |
void getStringSignal(); |
|
103 |
void getComplexSignal_data(); |
|
104 |
void getComplexSignal(); |
|
105 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
106 |
void followSignal(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
107 |
|
0 | 108 |
void createErrors_data(); |
109 |
void createErrors(); |
|
110 |
||
111 |
void callErrors_data(); |
|
112 |
void callErrors(); |
|
113 |
void asyncCallErrors_data(); |
|
114 |
void asyncCallErrors(); |
|
115 |
||
116 |
void propertyReadErrors_data(); |
|
117 |
void propertyReadErrors(); |
|
118 |
void propertyWriteErrors_data(); |
|
119 |
void propertyWriteErrors(); |
|
120 |
void directPropertyReadErrors_data(); |
|
121 |
void directPropertyReadErrors(); |
|
122 |
void directPropertyWriteErrors_data(); |
|
123 |
void directPropertyWriteErrors(); |
|
124 |
}; |
|
125 |
||
126 |
tst_QDBusAbstractInterface::tst_QDBusAbstractInterface() |
|
127 |
{ |
|
128 |
// register the meta types |
|
129 |
qDBusRegisterMetaType<RegisteredType>(); |
|
130 |
qRegisterMetaType<UnregisteredType>(); |
|
131 |
} |
|
132 |
||
133 |
void tst_QDBusAbstractInterface::initTestCase() |
|
134 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
135 |
// enable debugging temporarily: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
136 |
//putenv("QDBUS_DEBUG=1"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
137 |
|
0 | 138 |
// register the object |
139 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
140 |
QVERIFY(con.isConnected()); |
|
141 |
con.registerObject("/", &targetObj, QDBusConnection::ExportScriptableContents); |
|
142 |
} |
|
143 |
||
144 |
void tst_QDBusAbstractInterface::makeVoidCall() |
|
145 |
{ |
|
146 |
Pinger p = getPinger(); |
|
147 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
148 |
||
149 |
QDBusReply<void> r = p->voidMethod(); |
|
150 |
QVERIFY(r.isValid()); |
|
151 |
} |
|
152 |
||
153 |
void tst_QDBusAbstractInterface::makeStringCall() |
|
154 |
{ |
|
155 |
Pinger p = getPinger(); |
|
156 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
157 |
||
158 |
QDBusReply<QString> r = p->stringMethod(); |
|
159 |
QVERIFY(r.isValid()); |
|
160 |
QCOMPARE(r.value(), targetObj.stringMethod()); |
|
161 |
} |
|
162 |
||
163 |
void tst_QDBusAbstractInterface::makeComplexCall() |
|
164 |
{ |
|
165 |
Pinger p = getPinger(); |
|
166 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
167 |
||
168 |
QDBusReply<RegisteredType> r = p->complexMethod(); |
|
169 |
QVERIFY(r.isValid()); |
|
170 |
QCOMPARE(r.value(), targetObj.complexMethod()); |
|
171 |
} |
|
172 |
||
173 |
void tst_QDBusAbstractInterface::makeMultiOutCall() |
|
174 |
{ |
|
175 |
Pinger p = getPinger(); |
|
176 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
177 |
||
178 |
int value; |
|
179 |
QDBusReply<QString> r = p->multiOutMethod(value); |
|
180 |
QVERIFY(r.isValid()); |
|
181 |
||
182 |
int expectedValue; |
|
183 |
QCOMPARE(r.value(), targetObj.multiOutMethod(expectedValue)); |
|
184 |
QCOMPARE(value, expectedValue); |
|
185 |
} |
|
186 |
||
187 |
void tst_QDBusAbstractInterface::makeAsyncVoidCall() |
|
188 |
{ |
|
189 |
Pinger p = getPinger(); |
|
190 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
191 |
||
192 |
QDBusPendingReply<void> r = p->voidMethod(); |
|
193 |
r.waitForFinished(); |
|
194 |
QVERIFY(r.isValid()); |
|
195 |
} |
|
196 |
||
197 |
void tst_QDBusAbstractInterface::makeAsyncStringCall() |
|
198 |
{ |
|
199 |
Pinger p = getPinger(); |
|
200 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
201 |
||
202 |
QDBusPendingReply<QString> r = p->stringMethod(); |
|
203 |
r.waitForFinished(); |
|
204 |
QVERIFY(r.isValid()); |
|
205 |
QCOMPARE(r.value(), targetObj.stringMethod()); |
|
206 |
} |
|
207 |
||
208 |
void tst_QDBusAbstractInterface::makeAsyncComplexCall() |
|
209 |
{ |
|
210 |
Pinger p = getPinger(); |
|
211 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
212 |
||
213 |
QDBusPendingReply<RegisteredType> r = p->complexMethod(); |
|
214 |
r.waitForFinished(); |
|
215 |
QVERIFY(r.isValid()); |
|
216 |
QCOMPARE(r.value(), targetObj.complexMethod()); |
|
217 |
} |
|
218 |
||
219 |
void tst_QDBusAbstractInterface::makeAsyncMultiOutCall() |
|
220 |
{ |
|
221 |
Pinger p = getPinger(); |
|
222 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
223 |
||
224 |
QDBusPendingReply<QString, int> r = p->multiOutMethod(); |
|
225 |
r.waitForFinished(); |
|
226 |
QVERIFY(r.isValid()); |
|
227 |
||
228 |
int expectedValue; |
|
229 |
QCOMPARE(r.value(), targetObj.multiOutMethod(expectedValue)); |
|
230 |
QCOMPARE(r.argumentAt<1>(), expectedValue); |
|
231 |
} |
|
232 |
||
233 |
void tst_QDBusAbstractInterface::stringPropRead() |
|
234 |
{ |
|
235 |
Pinger p = getPinger(); |
|
236 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
237 |
||
238 |
QString expectedValue = targetObj.m_stringProp = "This is a test"; |
|
239 |
QVariant v = p->property("stringProp"); |
|
240 |
QVERIFY(v.isValid()); |
|
241 |
QCOMPARE(v.toString(), expectedValue); |
|
242 |
} |
|
243 |
||
244 |
void tst_QDBusAbstractInterface::stringPropWrite() |
|
245 |
{ |
|
246 |
Pinger p = getPinger(); |
|
247 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
248 |
||
249 |
QString expectedValue = "This is a value"; |
|
250 |
QVERIFY(p->setProperty("stringProp", expectedValue)); |
|
251 |
QCOMPARE(targetObj.m_stringProp, expectedValue); |
|
252 |
} |
|
253 |
||
254 |
void tst_QDBusAbstractInterface::variantPropRead() |
|
255 |
{ |
|
256 |
Pinger p = getPinger(); |
|
257 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
258 |
||
259 |
QDBusVariant expectedValue = targetObj.m_variantProp = QDBusVariant(QVariant(42)); |
|
260 |
QVariant v = p->property("variantProp"); |
|
261 |
QVERIFY(v.isValid()); |
|
262 |
QDBusVariant value = v.value<QDBusVariant>(); |
|
263 |
QCOMPARE(value.variant().userType(), expectedValue.variant().userType()); |
|
264 |
QCOMPARE(value.variant(), expectedValue.variant()); |
|
265 |
} |
|
266 |
||
267 |
void tst_QDBusAbstractInterface::variantPropWrite() |
|
268 |
{ |
|
269 |
Pinger p = getPinger(); |
|
270 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
271 |
||
272 |
QDBusVariant expectedValue = QDBusVariant(Q_INT64_C(-47)); |
|
273 |
QVERIFY(p->setProperty("variantProp", qVariantFromValue(expectedValue))); |
|
274 |
QCOMPARE(targetObj.m_variantProp.variant(), expectedValue.variant()); |
|
275 |
} |
|
276 |
||
277 |
void tst_QDBusAbstractInterface::complexPropRead() |
|
278 |
{ |
|
279 |
Pinger p = getPinger(); |
|
280 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
281 |
||
282 |
RegisteredType expectedValue = targetObj.m_complexProp = RegisteredType("This is a test"); |
|
283 |
QVariant v = p->property("complexProp"); |
|
284 |
QVERIFY(v.userType() == qMetaTypeId<RegisteredType>()); |
|
285 |
QCOMPARE(v.value<RegisteredType>(), targetObj.m_complexProp); |
|
286 |
} |
|
287 |
||
288 |
void tst_QDBusAbstractInterface::complexPropWrite() |
|
289 |
{ |
|
290 |
Pinger p = getPinger(); |
|
291 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
292 |
||
293 |
RegisteredType expectedValue = RegisteredType("This is a value"); |
|
294 |
QVERIFY(p->setProperty("complexProp", qVariantFromValue(expectedValue))); |
|
295 |
QCOMPARE(targetObj.m_complexProp, expectedValue); |
|
296 |
} |
|
297 |
||
298 |
void tst_QDBusAbstractInterface::stringPropDirectRead() |
|
299 |
{ |
|
300 |
Pinger p = getPinger(); |
|
301 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
302 |
||
303 |
QString expectedValue = targetObj.m_stringProp = "This is a test"; |
|
304 |
QCOMPARE(p->stringProp(), expectedValue); |
|
305 |
} |
|
306 |
||
307 |
void tst_QDBusAbstractInterface::stringPropDirectWrite() |
|
308 |
{ |
|
309 |
Pinger p = getPinger(); |
|
310 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
311 |
||
312 |
QString expectedValue = "This is a value"; |
|
313 |
p->setStringProp(expectedValue); |
|
314 |
QCOMPARE(targetObj.m_stringProp, expectedValue); |
|
315 |
} |
|
316 |
||
317 |
void tst_QDBusAbstractInterface::variantPropDirectRead() |
|
318 |
{ |
|
319 |
Pinger p = getPinger(); |
|
320 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
321 |
||
322 |
QDBusVariant expectedValue = targetObj.m_variantProp = QDBusVariant(42); |
|
323 |
QCOMPARE(p->variantProp().variant(), expectedValue.variant()); |
|
324 |
} |
|
325 |
||
326 |
void tst_QDBusAbstractInterface::variantPropDirectWrite() |
|
327 |
{ |
|
328 |
Pinger p = getPinger(); |
|
329 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
330 |
||
331 |
QDBusVariant expectedValue = QDBusVariant(Q_INT64_C(-47)); |
|
332 |
p->setVariantProp(expectedValue); |
|
333 |
QCOMPARE(targetObj.m_variantProp.variant().userType(), expectedValue.variant().userType()); |
|
334 |
QCOMPARE(targetObj.m_variantProp.variant(), expectedValue.variant()); |
|
335 |
} |
|
336 |
||
337 |
void tst_QDBusAbstractInterface::complexPropDirectRead() |
|
338 |
{ |
|
339 |
Pinger p = getPinger(); |
|
340 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
341 |
||
342 |
RegisteredType expectedValue = targetObj.m_complexProp = RegisteredType("This is a test"); |
|
343 |
QCOMPARE(p->complexProp(), targetObj.m_complexProp); |
|
344 |
} |
|
345 |
||
346 |
void tst_QDBusAbstractInterface::complexPropDirectWrite() |
|
347 |
{ |
|
348 |
Pinger p = getPinger(); |
|
349 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
350 |
||
351 |
RegisteredType expectedValue = RegisteredType("This is a value"); |
|
352 |
p->setComplexProp(expectedValue); |
|
353 |
QCOMPARE(targetObj.m_complexProp, expectedValue); |
|
354 |
} |
|
355 |
||
356 |
void tst_QDBusAbstractInterface::getVoidSignal_data() |
|
357 |
{ |
|
358 |
QTest::addColumn<QString>("service"); |
|
359 |
QTest::addColumn<QString>("path"); |
|
360 |
||
361 |
QTest::newRow("specific") << QDBusConnection::sessionBus().baseService() << "/"; |
|
362 |
QTest::newRow("service-wildcard") << QString() << "/"; |
|
363 |
QTest::newRow("path-wildcard") << QDBusConnection::sessionBus().baseService() << QString(); |
|
364 |
QTest::newRow("full-wildcard") << QString() << QString(); |
|
365 |
} |
|
366 |
||
367 |
void tst_QDBusAbstractInterface::getVoidSignal() |
|
368 |
{ |
|
369 |
QFETCH(QString, service); |
|
370 |
QFETCH(QString, path); |
|
371 |
Pinger p = getPinger(service, path); |
|
372 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
373 |
||
374 |
// we need to connect the signal somewhere in order for D-Bus to enable the rules |
|
375 |
QTestEventLoop::instance().connect(p.data(), SIGNAL(voidSignal()), SLOT(exitLoop())); |
|
376 |
QSignalSpy s(p.data(), SIGNAL(voidSignal())); |
|
377 |
||
378 |
emit targetObj.voidSignal(); |
|
379 |
QTestEventLoop::instance().enterLoop(2); |
|
380 |
QVERIFY(!QTestEventLoop::instance().timeout()); |
|
381 |
||
382 |
QVERIFY(s.size() == 1); |
|
383 |
QVERIFY(s.at(0).size() == 0); |
|
384 |
} |
|
385 |
||
386 |
void tst_QDBusAbstractInterface::getStringSignal_data() |
|
387 |
{ |
|
388 |
getVoidSignal_data(); |
|
389 |
} |
|
390 |
||
391 |
void tst_QDBusAbstractInterface::getStringSignal() |
|
392 |
{ |
|
393 |
QFETCH(QString, service); |
|
394 |
QFETCH(QString, path); |
|
395 |
Pinger p = getPinger(service, path); |
|
396 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
397 |
||
398 |
// we need to connect the signal somewhere in order for D-Bus to enable the rules |
|
399 |
QTestEventLoop::instance().connect(p.data(), SIGNAL(stringSignal(QString)), SLOT(exitLoop())); |
|
400 |
QSignalSpy s(p.data(), SIGNAL(stringSignal(QString))); |
|
401 |
||
402 |
QString expectedValue = "Good morning"; |
|
403 |
emit targetObj.stringSignal(expectedValue); |
|
404 |
QTestEventLoop::instance().enterLoop(2); |
|
405 |
QVERIFY(!QTestEventLoop::instance().timeout()); |
|
406 |
||
407 |
QVERIFY(s.size() == 1); |
|
408 |
QVERIFY(s[0].size() == 1); |
|
409 |
QCOMPARE(s[0][0].userType(), int(QVariant::String)); |
|
410 |
QCOMPARE(s[0][0].toString(), expectedValue); |
|
411 |
} |
|
412 |
||
413 |
void tst_QDBusAbstractInterface::getComplexSignal_data() |
|
414 |
{ |
|
415 |
getVoidSignal_data(); |
|
416 |
} |
|
417 |
||
418 |
void tst_QDBusAbstractInterface::getComplexSignal() |
|
419 |
{ |
|
420 |
QFETCH(QString, service); |
|
421 |
QFETCH(QString, path); |
|
422 |
Pinger p = getPinger(service, path); |
|
423 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
424 |
||
425 |
// we need to connect the signal somewhere in order for D-Bus to enable the rules |
|
426 |
QTestEventLoop::instance().connect(p.data(), SIGNAL(complexSignal(RegisteredType)), SLOT(exitLoop())); |
|
427 |
QSignalSpy s(p.data(), SIGNAL(complexSignal(RegisteredType))); |
|
428 |
||
429 |
RegisteredType expectedValue("Good evening"); |
|
430 |
emit targetObj.complexSignal(expectedValue); |
|
431 |
QTestEventLoop::instance().enterLoop(2); |
|
432 |
QVERIFY(!QTestEventLoop::instance().timeout()); |
|
433 |
||
434 |
QVERIFY(s.size() == 1); |
|
435 |
QVERIFY(s[0].size() == 1); |
|
436 |
QCOMPARE(s[0][0].userType(), qMetaTypeId<RegisteredType>()); |
|
437 |
QCOMPARE(s[0][0].value<RegisteredType>(), expectedValue); |
|
438 |
} |
|
439 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
440 |
void tst_QDBusAbstractInterface::followSignal() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
441 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
442 |
const QString serviceToFollow = "com.trolltech.tst_qdbusabstractinterface.FollowMe"; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
443 |
Pinger p = getPinger(serviceToFollow); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
444 |
QVERIFY2(p, "Not connected to D-Bus"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
445 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
446 |
QDBusConnection con = p->connection(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
447 |
QVERIFY(!con.interface()->isServiceRegistered(serviceToFollow)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
448 |
Pinger control = getPinger(""); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
449 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
450 |
// we need to connect the signal somewhere in order for D-Bus to enable the rules |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
451 |
QTestEventLoop::instance().connect(p.data(), SIGNAL(voidSignal()), SLOT(exitLoop())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
452 |
QTestEventLoop::instance().connect(control.data(), SIGNAL(voidSignal()), SLOT(exitLoop())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
453 |
QSignalSpy s(p.data(), SIGNAL(voidSignal())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
454 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
455 |
emit targetObj.voidSignal(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
456 |
QTestEventLoop::instance().enterLoop(200); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
457 |
QVERIFY(!QTestEventLoop::instance().timeout()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
458 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
459 |
// signal must not have been received because the service isn't registered |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
460 |
QVERIFY(s.isEmpty()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
461 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
462 |
// now register the service |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
463 |
QDBusReply<QDBusConnectionInterface::RegisterServiceReply> r = |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
464 |
con.interface()->registerService(serviceToFollow, QDBusConnectionInterface::DontQueueService, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
465 |
QDBusConnectionInterface::DontAllowReplacement); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
466 |
QVERIFY(r.isValid() && r.value() == QDBusConnectionInterface::ServiceRegistered); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
467 |
QVERIFY(con.interface()->isServiceRegistered(serviceToFollow)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
468 |
QCoreApplication::instance()->processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
469 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
470 |
// emit the signal again: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
471 |
emit targetObj.voidSignal(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
472 |
QTestEventLoop::instance().enterLoop(2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
473 |
QVERIFY(!QTestEventLoop::instance().timeout()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
474 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
475 |
// now the signal must have been received: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
476 |
QCOMPARE(s.size(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
477 |
QVERIFY(s.at(0).size() == 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
478 |
s.clear(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
479 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
480 |
// disconnect the signal |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
481 |
disconnect(p.data(), SIGNAL(voidSignal()), &QTestEventLoop::instance(), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
482 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
483 |
// emit the signal again: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
484 |
emit targetObj.voidSignal(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
485 |
QTestEventLoop::instance().enterLoop(2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
486 |
QVERIFY(!QTestEventLoop::instance().timeout()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
487 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
488 |
// and now it mustn't have been received |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
489 |
QVERIFY(s.isEmpty()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
490 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
491 |
// cleanup: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
492 |
con.interface()->unregisterService(serviceToFollow); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
493 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
494 |
|
0 | 495 |
void tst_QDBusAbstractInterface::createErrors_data() |
496 |
{ |
|
497 |
QTest::addColumn<QString>("service"); |
|
498 |
QTest::addColumn<QString>("path"); |
|
499 |
QTest::addColumn<QString>("errorName"); |
|
500 |
||
501 |
QTest::newRow("invalid-service") << "this isn't valid" << "/" << "com.trolltech.QtDBus.Error.InvalidService"; |
|
502 |
QTest::newRow("invalid-path") << QDBusConnection::sessionBus().baseService() << "this isn't valid" |
|
503 |
<< "com.trolltech.QtDBus.Error.InvalidObjectPath"; |
|
504 |
} |
|
505 |
||
506 |
void tst_QDBusAbstractInterface::createErrors() |
|
507 |
{ |
|
508 |
QFETCH(QString, service); |
|
509 |
QFETCH(QString, path); |
|
510 |
Pinger p = getPinger(service, path); |
|
511 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
512 |
||
513 |
QVERIFY(!p->isValid()); |
|
514 |
QTEST(p->lastError().name(), "errorName"); |
|
515 |
} |
|
516 |
||
517 |
void tst_QDBusAbstractInterface::callErrors_data() |
|
518 |
{ |
|
519 |
createErrors_data(); |
|
520 |
QTest::newRow("service-wildcard") << QString() << "/" << "com.trolltech.QtDBus.Error.InvalidService"; |
|
521 |
QTest::newRow("path-wildcard") << QDBusConnection::sessionBus().baseService() << QString() |
|
522 |
<< "com.trolltech.QtDBus.Error.InvalidObjectPath"; |
|
523 |
QTest::newRow("full-wildcard") << QString() << QString() << "com.trolltech.QtDBus.Error.InvalidService"; |
|
524 |
} |
|
525 |
||
526 |
void tst_QDBusAbstractInterface::callErrors() |
|
527 |
{ |
|
528 |
QFETCH(QString, service); |
|
529 |
QFETCH(QString, path); |
|
530 |
Pinger p = getPinger(service, path); |
|
531 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
532 |
||
533 |
// we shouldn't be able to make this call: |
|
534 |
QDBusReply<QString> r = p->stringMethod(); |
|
535 |
QVERIFY(!r.isValid()); |
|
536 |
QTEST(r.error().name(), "errorName"); |
|
537 |
QCOMPARE(p->lastError().name(), r.error().name()); |
|
538 |
} |
|
539 |
||
540 |
void tst_QDBusAbstractInterface::asyncCallErrors_data() |
|
541 |
{ |
|
542 |
callErrors_data(); |
|
543 |
} |
|
544 |
||
545 |
void tst_QDBusAbstractInterface::asyncCallErrors() |
|
546 |
{ |
|
547 |
QFETCH(QString, service); |
|
548 |
QFETCH(QString, path); |
|
549 |
Pinger p = getPinger(service, path); |
|
550 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
551 |
||
552 |
// we shouldn't be able to make this call: |
|
553 |
QDBusPendingReply<QString> r = p->stringMethod(); |
|
554 |
QVERIFY(r.isError()); |
|
555 |
QTEST(r.error().name(), "errorName"); |
|
556 |
QCOMPARE(p->lastError().name(), r.error().name()); |
|
557 |
} |
|
558 |
||
559 |
void tst_QDBusAbstractInterface::propertyReadErrors_data() |
|
560 |
{ |
|
561 |
callErrors_data(); |
|
562 |
} |
|
563 |
||
564 |
void tst_QDBusAbstractInterface::propertyReadErrors() |
|
565 |
{ |
|
566 |
QFETCH(QString, service); |
|
567 |
QFETCH(QString, path); |
|
568 |
Pinger p = getPinger(service, path); |
|
569 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
570 |
||
571 |
// we shouldn't be able to get this value: |
|
572 |
QVariant v = p->property("stringProp"); |
|
573 |
QVERIFY(v.isNull()); |
|
574 |
QVERIFY(!v.isValid()); |
|
575 |
QTEST(p->lastError().name(), "errorName"); |
|
576 |
} |
|
577 |
||
578 |
void tst_QDBusAbstractInterface::propertyWriteErrors_data() |
|
579 |
{ |
|
580 |
callErrors_data(); |
|
581 |
} |
|
582 |
||
583 |
void tst_QDBusAbstractInterface::propertyWriteErrors() |
|
584 |
{ |
|
585 |
QFETCH(QString, service); |
|
586 |
QFETCH(QString, path); |
|
587 |
Pinger p = getPinger(service, path); |
|
588 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
589 |
||
590 |
// we shouldn't be able to get this value: |
|
591 |
if (p->isValid()) |
|
592 |
QCOMPARE(int(p->lastError().type()), int(QDBusError::NoError)); |
|
593 |
QVERIFY(!p->setProperty("stringProp", "")); |
|
594 |
QTEST(p->lastError().name(), "errorName"); |
|
595 |
} |
|
596 |
||
597 |
void tst_QDBusAbstractInterface::directPropertyReadErrors_data() |
|
598 |
{ |
|
599 |
callErrors_data(); |
|
600 |
} |
|
601 |
||
602 |
void tst_QDBusAbstractInterface::directPropertyReadErrors() |
|
603 |
{ |
|
604 |
QFETCH(QString, service); |
|
605 |
QFETCH(QString, path); |
|
606 |
Pinger p = getPinger(service, path); |
|
607 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
608 |
||
609 |
// we shouldn't be able to get this value: |
|
610 |
QString v = p->stringProp(); |
|
611 |
QVERIFY(v.isNull()); |
|
612 |
QTEST(p->lastError().name(), "errorName"); |
|
613 |
} |
|
614 |
||
615 |
void tst_QDBusAbstractInterface::directPropertyWriteErrors_data() |
|
616 |
{ |
|
617 |
callErrors_data(); |
|
618 |
} |
|
619 |
||
620 |
void tst_QDBusAbstractInterface::directPropertyWriteErrors() |
|
621 |
{ |
|
622 |
QFETCH(QString, service); |
|
623 |
QFETCH(QString, path); |
|
624 |
Pinger p = getPinger(service, path); |
|
625 |
QVERIFY2(p, "Not connected to D-Bus"); |
|
626 |
||
627 |
// we shouldn't be able to get this value: |
|
628 |
// but there's no direct way of verifying that the setting failed |
|
629 |
if (p->isValid()) |
|
630 |
QCOMPARE(int(p->lastError().type()), int(QDBusError::NoError)); |
|
631 |
p->setStringProp(""); |
|
632 |
QTEST(p->lastError().name(), "errorName"); |
|
633 |
} |
|
634 |
||
635 |
QTEST_MAIN(tst_QDBusAbstractInterface) |
|
636 |
#include "tst_qdbusabstractinterface.moc" |