author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 3 | 41300fa6a67c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
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 |
/* -*- C++ -*- |
|
42 |
*/ |
|
43 |
#include <qcoreapplication.h> |
|
44 |
#include <qmetatype.h> |
|
45 |
#include <QtTest/QtTest> |
|
46 |
#include <QtCore/qvariant.h> |
|
47 |
#include <QtDBus/QtDBus> |
|
48 |
||
49 |
#include "../qdbusmarshall/common.h" |
|
50 |
||
51 |
Q_DECLARE_METATYPE(QVariantList) |
|
52 |
||
53 |
#define TEST_INTERFACE_NAME "com.trolltech.QtDBus.MyObject" |
|
54 |
#define TEST_SIGNAL_NAME "somethingHappened" |
|
55 |
||
56 |
class MyObject: public QObject |
|
57 |
{ |
|
58 |
Q_OBJECT |
|
59 |
Q_CLASSINFO("D-Bus Interface", "com.trolltech.QtDBus.MyObject") |
|
60 |
Q_CLASSINFO("D-Bus Introspection", "" |
|
61 |
" <interface name=\"com.trolltech.QtDBus.MyObject\" >\n" |
|
62 |
" <property access=\"readwrite\" type=\"i\" name=\"prop1\" />\n" |
|
63 |
" <property name=\"complexProp\" type=\"ai\" access=\"readwrite\">\n" |
|
64 |
" <annotation name=\"com.trolltech.QtDBus.QtTypeName\" value=\"QList<int>\"/>\n" |
|
65 |
" </property>\n" |
|
66 |
" <signal name=\"somethingHappened\" >\n" |
|
67 |
" <arg direction=\"out\" type=\"s\" />\n" |
|
68 |
" </signal>\n" |
|
69 |
" <method name=\"ping\" >\n" |
|
70 |
" <arg direction=\"in\" type=\"v\" name=\"ping\" />\n" |
|
71 |
" <arg direction=\"out\" type=\"v\" name=\"ping\" />\n" |
|
72 |
" </method>\n" |
|
73 |
" <method name=\"ping\" >\n" |
|
74 |
" <arg direction=\"in\" type=\"v\" name=\"ping1\" />\n" |
|
75 |
" <arg direction=\"in\" type=\"v\" name=\"ping2\" />\n" |
|
76 |
" <arg direction=\"out\" type=\"v\" name=\"pong1\" />\n" |
|
77 |
" <arg direction=\"out\" type=\"v\" name=\"pong2\" />\n" |
|
78 |
" </method>\n" |
|
79 |
" <method name=\"ping\" >\n" |
|
80 |
" <arg direction=\"in\" type=\"ai\" name=\"ping\" />\n" |
|
81 |
" <arg direction=\"out\" type=\"ai\" name=\"ping\" />\n" |
|
82 |
" <annotation name=\"com.trolltech.QtDBus.QtTypeName.In0\" value=\"QList<int>\"/>\n" |
|
83 |
" <annotation name=\"com.trolltech.QtDBus.QtTypeName.Out0\" value=\"QList<int>\"/>\n" |
|
84 |
" </method>\n" |
|
85 |
" </interface>\n" |
|
86 |
"") |
|
87 |
Q_PROPERTY(int prop1 READ prop1 WRITE setProp1) |
|
88 |
Q_PROPERTY(QList<int> complexProp READ complexProp WRITE setComplexProp) |
|
89 |
||
90 |
public: |
|
91 |
static int callCount; |
|
92 |
static QVariantList callArgs; |
|
93 |
MyObject() |
|
94 |
{ |
|
95 |
QObject *subObject = new QObject(this); |
|
96 |
subObject->setObjectName("subObject"); |
|
97 |
} |
|
98 |
||
99 |
int m_prop1; |
|
100 |
int prop1() const |
|
101 |
{ |
|
102 |
++callCount; |
|
103 |
return m_prop1; |
|
104 |
} |
|
105 |
void setProp1(int value) |
|
106 |
{ |
|
107 |
++callCount; |
|
108 |
m_prop1 = value; |
|
109 |
} |
|
110 |
||
111 |
QList<int> m_complexProp; |
|
112 |
QList<int> complexProp() const |
|
113 |
{ |
|
114 |
++callCount; |
|
115 |
return m_complexProp; |
|
116 |
} |
|
117 |
void setComplexProp(const QList<int> &value) |
|
118 |
{ |
|
119 |
++callCount; |
|
120 |
m_complexProp = value; |
|
121 |
} |
|
122 |
||
123 |
public slots: |
|
124 |
||
125 |
void ping(QDBusMessage msg) |
|
126 |
{ |
|
127 |
QDBusConnection sender = QDBusConnection::sender(); |
|
128 |
if (!sender.isConnected()) |
|
129 |
exit(1); |
|
130 |
||
131 |
++callCount; |
|
132 |
callArgs = msg.arguments(); |
|
133 |
||
134 |
msg.setDelayedReply(true); |
|
135 |
if (!sender.send(msg.createReply(callArgs))) |
|
136 |
exit(1); |
|
137 |
} |
|
138 |
}; |
|
139 |
int MyObject::callCount = 0; |
|
140 |
QVariantList MyObject::callArgs; |
|
141 |
||
142 |
class Spy: public QObject |
|
143 |
{ |
|
144 |
Q_OBJECT |
|
145 |
public: |
|
146 |
QString received; |
|
147 |
int count; |
|
148 |
||
149 |
Spy() : count(0) |
|
150 |
{ } |
|
151 |
||
152 |
public slots: |
|
153 |
void spySlot(const QString& arg) |
|
154 |
{ |
|
155 |
received = arg; |
|
156 |
++count; |
|
157 |
} |
|
158 |
}; |
|
159 |
||
160 |
// helper function |
|
161 |
void emitSignal(const QString &interface, const QString &name, const QString &arg) |
|
162 |
{ |
|
163 |
QDBusMessage msg = QDBusMessage::createSignal("/", interface, name); |
|
164 |
msg << arg; |
|
165 |
QDBusConnection::sessionBus().send(msg); |
|
166 |
||
167 |
QTest::qWait(1000); |
|
168 |
} |
|
169 |
||
170 |
class tst_QDBusInterface: public QObject |
|
171 |
{ |
|
172 |
Q_OBJECT |
|
173 |
MyObject obj; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
174 |
public slots: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
175 |
void testServiceOwnerChanged(const QString &service) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
176 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
177 |
if (service == "com.example.Test") |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
178 |
QTestEventLoop::instance().exitLoop(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
180 |
|
0 | 181 |
private slots: |
182 |
void initTestCase(); |
|
183 |
||
184 |
void notConnected(); |
|
185 |
void notValid(); |
|
186 |
void invalidAfterServiceOwnerChanged(); |
|
187 |
void introspect(); |
|
188 |
void callMethod(); |
|
189 |
void invokeMethod(); |
|
190 |
void invokeMethodWithReturn(); |
|
191 |
void invokeMethodWithMultiReturn(); |
|
192 |
void invokeMethodWithComplexReturn(); |
|
193 |
||
194 |
void signal(); |
|
195 |
||
196 |
void propertyRead(); |
|
197 |
void propertyWrite(); |
|
198 |
void complexPropertyRead(); |
|
199 |
void complexPropertyWrite(); |
|
200 |
}; |
|
201 |
||
202 |
void tst_QDBusInterface::initTestCase() |
|
203 |
{ |
|
204 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
205 |
QVERIFY(con.isConnected()); |
|
206 |
QTest::qWait(500); |
|
207 |
||
208 |
con.registerObject("/", &obj, QDBusConnection::ExportAllProperties |
|
209 |
| QDBusConnection::ExportAllSlots |
|
210 |
| QDBusConnection::ExportChildObjects); |
|
211 |
} |
|
212 |
||
213 |
void tst_QDBusInterface::notConnected() |
|
214 |
{ |
|
215 |
QDBusConnection connection(""); |
|
216 |
QVERIFY(!connection.isConnected()); |
|
217 |
||
218 |
QDBusInterface interface("org.freedesktop.DBus", "/", "org.freedesktop.DBus", |
|
219 |
connection); |
|
220 |
||
221 |
QVERIFY(!interface.isValid()); |
|
222 |
} |
|
223 |
||
224 |
void tst_QDBusInterface::notValid() |
|
225 |
{ |
|
226 |
QDBusConnection connection(""); |
|
227 |
QVERIFY(!connection.isConnected()); |
|
228 |
||
229 |
QDBusInterface interface("com.example.Test", QString(), "org.example.Test", |
|
230 |
connection); |
|
231 |
||
232 |
QVERIFY(!interface.isValid()); |
|
233 |
} |
|
234 |
||
235 |
void tst_QDBusInterface::invalidAfterServiceOwnerChanged() |
|
236 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
237 |
// this test is technically the same as tst_QDBusAbstractInterface::followSignal |
0 | 238 |
QDBusConnection conn = QDBusConnection::sessionBus(); |
239 |
QDBusConnectionInterface *connIface = conn.interface(); |
|
240 |
||
241 |
QDBusInterface validInterface(conn.baseService(), "/"); |
|
242 |
QVERIFY(validInterface.isValid()); |
|
243 |
QDBusInterface invalidInterface("com.example.Test", "/"); |
|
244 |
QVERIFY(!invalidInterface.isValid()); |
|
245 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
246 |
QTestEventLoop::instance().connect(connIface, SIGNAL(serviceOwnerChanged(QString, QString, QString)), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
247 |
SLOT(exitLoop())); |
0 | 248 |
QVERIFY(connIface->registerService("com.example.Test") == QDBusConnectionInterface::ServiceRegistered); |
249 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
250 |
QTestEventLoop::instance().enterLoop(5); |
0 | 251 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
252 |
QVERIFY(!QTestEventLoop::instance().timeout()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
253 |
QVERIFY(invalidInterface.isValid()); |
0 | 254 |
} |
255 |
||
256 |
void tst_QDBusInterface::introspect() |
|
257 |
{ |
|
258 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
259 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
260 |
TEST_INTERFACE_NAME); |
|
261 |
||
262 |
const QMetaObject *mo = iface.metaObject(); |
|
263 |
||
264 |
QCOMPARE(mo->methodCount() - mo->methodOffset(), 4); |
|
265 |
QVERIFY(mo->indexOfSignal(TEST_SIGNAL_NAME "(QString)") != -1); |
|
266 |
||
267 |
QCOMPARE(mo->propertyCount() - mo->propertyOffset(), 2); |
|
268 |
QVERIFY(mo->indexOfProperty("prop1") != -1); |
|
269 |
QVERIFY(mo->indexOfProperty("complexProp") != -1); |
|
270 |
} |
|
271 |
||
272 |
void tst_QDBusInterface::callMethod() |
|
273 |
{ |
|
274 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
275 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
276 |
TEST_INTERFACE_NAME); |
|
277 |
||
278 |
MyObject::callCount = 0; |
|
279 |
QDBusMessage reply = iface.call("ping", qVariantFromValue(QDBusVariant("foo"))); |
|
280 |
QCOMPARE(MyObject::callCount, 1); |
|
281 |
QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); |
|
282 |
||
283 |
// verify what the callee received |
|
284 |
QCOMPARE(MyObject::callArgs.count(), 1); |
|
285 |
QVariant v = MyObject::callArgs.at(0); |
|
286 |
QDBusVariant dv = qdbus_cast<QDBusVariant>(v); |
|
287 |
QCOMPARE(dv.variant().type(), QVariant::String); |
|
288 |
QCOMPARE(dv.variant().toString(), QString("foo")); |
|
289 |
||
290 |
// verify reply |
|
291 |
QCOMPARE(reply.arguments().count(), 1); |
|
292 |
v = reply.arguments().at(0); |
|
293 |
dv = qdbus_cast<QDBusVariant>(v); |
|
294 |
QCOMPARE(dv.variant().type(), QVariant::String); |
|
295 |
QCOMPARE(dv.variant().toString(), QString("foo")); |
|
296 |
} |
|
297 |
||
298 |
void tst_QDBusInterface::invokeMethod() |
|
299 |
{ |
|
300 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
301 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
302 |
TEST_INTERFACE_NAME); |
|
303 |
||
304 |
// make the call without a return type |
|
305 |
MyObject::callCount = 0; |
|
306 |
QDBusVariant arg("foo"); |
|
307 |
QVERIFY(QMetaObject::invokeMethod(&iface, "ping", Q_ARG(QDBusVariant, arg))); |
|
308 |
QCOMPARE(MyObject::callCount, 1); |
|
309 |
||
310 |
// verify what the callee received |
|
311 |
QCOMPARE(MyObject::callArgs.count(), 1); |
|
312 |
QVariant v = MyObject::callArgs.at(0); |
|
313 |
QDBusVariant dv = qdbus_cast<QDBusVariant>(v); |
|
314 |
QCOMPARE(dv.variant().type(), QVariant::String); |
|
315 |
QCOMPARE(dv.variant().toString(), QString("foo")); |
|
316 |
} |
|
317 |
||
318 |
void tst_QDBusInterface::invokeMethodWithReturn() |
|
319 |
{ |
|
320 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
321 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
322 |
TEST_INTERFACE_NAME); |
|
323 |
||
324 |
// make the call without a return type |
|
325 |
MyObject::callCount = 0; |
|
326 |
QDBusVariant arg("foo"); |
|
327 |
QDBusVariant retArg; |
|
328 |
QVERIFY(QMetaObject::invokeMethod(&iface, "ping", Q_RETURN_ARG(QDBusVariant, retArg), Q_ARG(QDBusVariant, arg))); |
|
329 |
QCOMPARE(MyObject::callCount, 1); |
|
330 |
||
331 |
// verify what the callee received |
|
332 |
QCOMPARE(MyObject::callArgs.count(), 1); |
|
333 |
QVariant v = MyObject::callArgs.at(0); |
|
334 |
QDBusVariant dv = qdbus_cast<QDBusVariant>(v); |
|
335 |
QCOMPARE(dv.variant().type(), QVariant::String); |
|
336 |
QCOMPARE(dv.variant().toString(), arg.variant().toString()); |
|
337 |
||
338 |
// verify that we got the reply as expected |
|
339 |
QCOMPARE(retArg.variant(), arg.variant()); |
|
340 |
} |
|
341 |
||
342 |
void tst_QDBusInterface::invokeMethodWithMultiReturn() |
|
343 |
{ |
|
344 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
345 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
346 |
TEST_INTERFACE_NAME); |
|
347 |
||
348 |
// make the call without a return type |
|
349 |
MyObject::callCount = 0; |
|
350 |
QDBusVariant arg("foo"), arg2("bar"); |
|
351 |
QDBusVariant retArg, retArg2; |
|
352 |
QVERIFY(QMetaObject::invokeMethod(&iface, "ping", |
|
353 |
Q_RETURN_ARG(QDBusVariant, retArg), |
|
354 |
Q_ARG(QDBusVariant, arg), |
|
355 |
Q_ARG(QDBusVariant, arg2), |
|
356 |
Q_ARG(QDBusVariant&, retArg2))); |
|
357 |
QCOMPARE(MyObject::callCount, 1); |
|
358 |
||
359 |
// verify what the callee received |
|
360 |
QCOMPARE(MyObject::callArgs.count(), 2); |
|
361 |
QVariant v = MyObject::callArgs.at(0); |
|
362 |
QDBusVariant dv = qdbus_cast<QDBusVariant>(v); |
|
363 |
QCOMPARE(dv.variant().type(), QVariant::String); |
|
364 |
QCOMPARE(dv.variant().toString(), arg.variant().toString()); |
|
365 |
||
366 |
v = MyObject::callArgs.at(1); |
|
367 |
dv = qdbus_cast<QDBusVariant>(v); |
|
368 |
QCOMPARE(dv.variant().type(), QVariant::String); |
|
369 |
QCOMPARE(dv.variant().toString(), arg2.variant().toString()); |
|
370 |
||
371 |
// verify that we got the replies as expected |
|
372 |
QCOMPARE(retArg.variant(), arg.variant()); |
|
373 |
QCOMPARE(retArg2.variant(), arg2.variant()); |
|
374 |
} |
|
375 |
||
376 |
void tst_QDBusInterface::invokeMethodWithComplexReturn() |
|
377 |
{ |
|
378 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
379 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
380 |
TEST_INTERFACE_NAME); |
|
381 |
||
382 |
// make the call without a return type |
|
383 |
MyObject::callCount = 0; |
|
384 |
QList<int> arg = QList<int>() << 42 << -47; |
|
385 |
QList<int> retArg; |
|
386 |
QVERIFY(QMetaObject::invokeMethod(&iface, "ping", Q_RETURN_ARG(QList<int>, retArg), Q_ARG(QList<int>, arg))); |
|
387 |
QCOMPARE(MyObject::callCount, 1); |
|
388 |
||
389 |
// verify what the callee received |
|
390 |
QCOMPARE(MyObject::callArgs.count(), 1); |
|
391 |
QVariant v = MyObject::callArgs.at(0); |
|
392 |
QCOMPARE(v.userType(), qMetaTypeId<QDBusArgument>()); |
|
393 |
QCOMPARE(qdbus_cast<QList<int> >(v), arg); |
|
394 |
||
395 |
// verify that we got the reply as expected |
|
396 |
QCOMPARE(retArg, arg); |
|
397 |
} |
|
398 |
||
399 |
void tst_QDBusInterface::signal() |
|
400 |
{ |
|
401 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
402 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
403 |
TEST_INTERFACE_NAME); |
|
404 |
||
405 |
QString arg = "So long and thanks for all the fish"; |
|
406 |
{ |
|
407 |
Spy spy; |
|
408 |
spy.connect(&iface, SIGNAL(somethingHappened(QString)), SLOT(spySlot(QString))); |
|
409 |
||
410 |
emitSignal(TEST_INTERFACE_NAME, TEST_SIGNAL_NAME, arg); |
|
411 |
QCOMPARE(spy.count, 1); |
|
412 |
QCOMPARE(spy.received, arg); |
|
413 |
} |
|
414 |
||
415 |
QDBusInterface iface2(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
416 |
TEST_INTERFACE_NAME); |
|
417 |
{ |
|
418 |
Spy spy; |
|
419 |
spy.connect(&iface, SIGNAL(somethingHappened(QString)), SLOT(spySlot(QString))); |
|
420 |
spy.connect(&iface2, SIGNAL(somethingHappened(QString)), SLOT(spySlot(QString))); |
|
421 |
||
422 |
emitSignal(TEST_INTERFACE_NAME, TEST_SIGNAL_NAME, arg); |
|
423 |
QCOMPARE(spy.count, 2); |
|
424 |
QCOMPARE(spy.received, arg); |
|
425 |
} |
|
426 |
||
427 |
{ |
|
428 |
Spy spy, spy2; |
|
429 |
spy.connect(&iface, SIGNAL(somethingHappened(QString)), SLOT(spySlot(QString))); |
|
430 |
spy2.connect(&iface2, SIGNAL(somethingHappened(QString)), SLOT(spySlot(QString))); |
|
431 |
||
432 |
emitSignal(TEST_INTERFACE_NAME, TEST_SIGNAL_NAME, arg); |
|
433 |
QCOMPARE(spy.count, 1); |
|
434 |
QCOMPARE(spy.received, arg); |
|
435 |
QCOMPARE(spy2.count, 1); |
|
436 |
QCOMPARE(spy2.received, arg); |
|
437 |
} |
|
438 |
} |
|
439 |
||
440 |
void tst_QDBusInterface::propertyRead() |
|
441 |
{ |
|
442 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
443 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
444 |
TEST_INTERFACE_NAME); |
|
445 |
||
446 |
int arg = obj.m_prop1 = 42; |
|
447 |
MyObject::callCount = 0; |
|
448 |
||
449 |
QVariant v = iface.property("prop1"); |
|
450 |
QVERIFY(v.isValid()); |
|
451 |
QCOMPARE(v.userType(), int(QVariant::Int)); |
|
452 |
QCOMPARE(v.toInt(), arg); |
|
453 |
QCOMPARE(MyObject::callCount, 1); |
|
454 |
} |
|
455 |
||
456 |
void tst_QDBusInterface::propertyWrite() |
|
457 |
{ |
|
458 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
459 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
460 |
TEST_INTERFACE_NAME); |
|
461 |
||
462 |
int arg = 42; |
|
463 |
obj.m_prop1 = 0; |
|
464 |
MyObject::callCount = 0; |
|
465 |
||
466 |
QVERIFY(iface.setProperty("prop1", arg)); |
|
467 |
QCOMPARE(MyObject::callCount, 1); |
|
468 |
QCOMPARE(obj.m_prop1, arg); |
|
469 |
} |
|
470 |
||
471 |
void tst_QDBusInterface::complexPropertyRead() |
|
472 |
{ |
|
473 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
474 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
475 |
TEST_INTERFACE_NAME); |
|
476 |
||
477 |
QList<int> arg = obj.m_complexProp = QList<int>() << 42 << -47; |
|
478 |
MyObject::callCount = 0; |
|
479 |
||
480 |
QVariant v = iface.property("complexProp"); |
|
481 |
QVERIFY(v.isValid()); |
|
482 |
QCOMPARE(v.userType(), qMetaTypeId<QList<int> >()); |
|
483 |
QCOMPARE(v.value<QList<int> >(), arg); |
|
484 |
QCOMPARE(MyObject::callCount, 1); |
|
485 |
} |
|
486 |
||
487 |
void tst_QDBusInterface::complexPropertyWrite() |
|
488 |
{ |
|
489 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
490 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
491 |
TEST_INTERFACE_NAME); |
|
492 |
||
493 |
QList<int> arg = QList<int>() << -47 << 42; |
|
494 |
obj.m_complexProp.clear(); |
|
495 |
MyObject::callCount = 0; |
|
496 |
||
497 |
QVERIFY(iface.setProperty("complexProp", qVariantFromValue(arg))); |
|
498 |
QCOMPARE(MyObject::callCount, 1); |
|
499 |
QCOMPARE(obj.m_complexProp, arg); |
|
500 |
} |
|
501 |
||
502 |
QTEST_MAIN(tst_QDBusInterface) |
|
503 |
||
504 |
#include "tst_qdbusinterface.moc" |
|
505 |