author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 01:19:32 +0300 | |
changeset 37 | 758a864f9613 |
parent 25 | e24348a560a6 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
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" |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
73 |
" <method name=\"ping_invokable\" >\n" |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
74 |
" <arg direction=\"in\" type=\"v\" name=\"ping_invokable\" />\n" |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
75 |
" <arg direction=\"out\" type=\"v\" name=\"ping_invokable\" />\n" |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
76 |
" </method>\n" |
0 | 77 |
" <method name=\"ping\" >\n" |
78 |
" <arg direction=\"in\" type=\"v\" name=\"ping1\" />\n" |
|
79 |
" <arg direction=\"in\" type=\"v\" name=\"ping2\" />\n" |
|
80 |
" <arg direction=\"out\" type=\"v\" name=\"pong1\" />\n" |
|
81 |
" <arg direction=\"out\" type=\"v\" name=\"pong2\" />\n" |
|
82 |
" </method>\n" |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
83 |
" <method name=\"ping_invokable\" >\n" |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
84 |
" <arg direction=\"in\" type=\"v\" name=\"ping1_invokable\" />\n" |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
85 |
" <arg direction=\"in\" type=\"v\" name=\"ping2_invokable\" />\n" |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
86 |
" <arg direction=\"out\" type=\"v\" name=\"pong1_invokable\" />\n" |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
87 |
" <arg direction=\"out\" type=\"v\" name=\"pong2_invokable\" />\n" |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
88 |
" </method>\n" |
0 | 89 |
" <method name=\"ping\" >\n" |
90 |
" <arg direction=\"in\" type=\"ai\" name=\"ping\" />\n" |
|
91 |
" <arg direction=\"out\" type=\"ai\" name=\"ping\" />\n" |
|
92 |
" <annotation name=\"com.trolltech.QtDBus.QtTypeName.In0\" value=\"QList<int>\"/>\n" |
|
93 |
" <annotation name=\"com.trolltech.QtDBus.QtTypeName.Out0\" value=\"QList<int>\"/>\n" |
|
94 |
" </method>\n" |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
95 |
" <method name=\"ping_invokable\" >\n" |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
96 |
" <arg direction=\"in\" type=\"ai\" name=\"ping_invokable\" />\n" |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
97 |
" <arg direction=\"out\" type=\"ai\" name=\"ping_invokable\" />\n" |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
98 |
" <annotation name=\"com.trolltech.QtDBus.QtTypeName.In0\" value=\"QList<int>\"/>\n" |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
99 |
" <annotation name=\"com.trolltech.QtDBus.QtTypeName.Out0\" value=\"QList<int>\"/>\n" |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
100 |
" </method>\n" |
0 | 101 |
" </interface>\n" |
102 |
"") |
|
103 |
Q_PROPERTY(int prop1 READ prop1 WRITE setProp1) |
|
104 |
Q_PROPERTY(QList<int> complexProp READ complexProp WRITE setComplexProp) |
|
105 |
||
106 |
public: |
|
107 |
static int callCount; |
|
108 |
static QVariantList callArgs; |
|
109 |
MyObject() |
|
110 |
{ |
|
111 |
QObject *subObject = new QObject(this); |
|
112 |
subObject->setObjectName("subObject"); |
|
113 |
} |
|
114 |
||
115 |
int m_prop1; |
|
116 |
int prop1() const |
|
117 |
{ |
|
118 |
++callCount; |
|
119 |
return m_prop1; |
|
120 |
} |
|
121 |
void setProp1(int value) |
|
122 |
{ |
|
123 |
++callCount; |
|
124 |
m_prop1 = value; |
|
125 |
} |
|
126 |
||
127 |
QList<int> m_complexProp; |
|
128 |
QList<int> complexProp() const |
|
129 |
{ |
|
130 |
++callCount; |
|
131 |
return m_complexProp; |
|
132 |
} |
|
133 |
void setComplexProp(const QList<int> &value) |
|
134 |
{ |
|
135 |
++callCount; |
|
136 |
m_complexProp = value; |
|
137 |
} |
|
138 |
||
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
139 |
Q_INVOKABLE void ping_invokable(QDBusMessage msg) |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
140 |
{ |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
141 |
QDBusConnection sender = QDBusConnection::sender(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
142 |
if (!sender.isConnected()) |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
143 |
exit(1); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
144 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
145 |
++callCount; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
146 |
callArgs = msg.arguments(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
147 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
148 |
msg.setDelayedReply(true); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
149 |
if (!sender.send(msg.createReply(callArgs))) |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
150 |
exit(1); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
151 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
152 |
|
0 | 153 |
public slots: |
154 |
||
155 |
void ping(QDBusMessage msg) |
|
156 |
{ |
|
157 |
QDBusConnection sender = QDBusConnection::sender(); |
|
158 |
if (!sender.isConnected()) |
|
159 |
exit(1); |
|
160 |
||
161 |
++callCount; |
|
162 |
callArgs = msg.arguments(); |
|
163 |
||
164 |
msg.setDelayedReply(true); |
|
165 |
if (!sender.send(msg.createReply(callArgs))) |
|
166 |
exit(1); |
|
167 |
} |
|
168 |
}; |
|
169 |
int MyObject::callCount = 0; |
|
170 |
QVariantList MyObject::callArgs; |
|
171 |
||
172 |
class Spy: public QObject |
|
173 |
{ |
|
174 |
Q_OBJECT |
|
175 |
public: |
|
176 |
QString received; |
|
177 |
int count; |
|
178 |
||
179 |
Spy() : count(0) |
|
180 |
{ } |
|
181 |
||
182 |
public slots: |
|
183 |
void spySlot(const QString& arg) |
|
184 |
{ |
|
185 |
received = arg; |
|
186 |
++count; |
|
187 |
} |
|
188 |
}; |
|
189 |
||
25
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
190 |
class DerivedFromQDBusInterface: public QDBusInterface |
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
191 |
{ |
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
192 |
Q_OBJECT |
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
193 |
public: |
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
194 |
DerivedFromQDBusInterface() |
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
195 |
: QDBusInterface("com.example.Test", "/") |
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
196 |
{} |
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
197 |
|
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
198 |
public slots: |
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
199 |
void method() {} |
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
200 |
}; |
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
201 |
|
0 | 202 |
// helper function |
203 |
void emitSignal(const QString &interface, const QString &name, const QString &arg) |
|
204 |
{ |
|
205 |
QDBusMessage msg = QDBusMessage::createSignal("/", interface, name); |
|
206 |
msg << arg; |
|
207 |
QDBusConnection::sessionBus().send(msg); |
|
208 |
||
209 |
QTest::qWait(1000); |
|
210 |
} |
|
211 |
||
212 |
class tst_QDBusInterface: public QObject |
|
213 |
{ |
|
214 |
Q_OBJECT |
|
215 |
MyObject obj; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
216 |
public slots: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
217 |
void testServiceOwnerChanged(const QString &service) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
218 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
219 |
if (service == "com.example.Test") |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
220 |
QTestEventLoop::instance().exitLoop(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
221 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
222 |
|
0 | 223 |
private slots: |
224 |
void initTestCase(); |
|
225 |
||
226 |
void notConnected(); |
|
227 |
void notValid(); |
|
25
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
228 |
void notValidDerived(); |
0 | 229 |
void invalidAfterServiceOwnerChanged(); |
230 |
void introspect(); |
|
231 |
void callMethod(); |
|
232 |
void invokeMethod(); |
|
233 |
void invokeMethodWithReturn(); |
|
234 |
void invokeMethodWithMultiReturn(); |
|
235 |
void invokeMethodWithComplexReturn(); |
|
236 |
||
237 |
void signal(); |
|
238 |
||
239 |
void propertyRead(); |
|
240 |
void propertyWrite(); |
|
241 |
void complexPropertyRead(); |
|
242 |
void complexPropertyWrite(); |
|
243 |
}; |
|
244 |
||
245 |
void tst_QDBusInterface::initTestCase() |
|
246 |
{ |
|
247 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
248 |
QVERIFY(con.isConnected()); |
|
249 |
QTest::qWait(500); |
|
250 |
||
251 |
con.registerObject("/", &obj, QDBusConnection::ExportAllProperties |
|
252 |
| QDBusConnection::ExportAllSlots |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
253 |
| QDBusConnection::ExportAllInvokables |
0 | 254 |
| QDBusConnection::ExportChildObjects); |
255 |
} |
|
256 |
||
257 |
void tst_QDBusInterface::notConnected() |
|
258 |
{ |
|
259 |
QDBusConnection connection(""); |
|
260 |
QVERIFY(!connection.isConnected()); |
|
261 |
||
262 |
QDBusInterface interface("org.freedesktop.DBus", "/", "org.freedesktop.DBus", |
|
263 |
connection); |
|
264 |
||
265 |
QVERIFY(!interface.isValid()); |
|
25
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
266 |
QVERIFY(!QMetaObject::invokeMethod(&interface, "ListNames", Qt::DirectConnection)); |
0 | 267 |
} |
268 |
||
269 |
void tst_QDBusInterface::notValid() |
|
270 |
{ |
|
271 |
QDBusConnection connection(""); |
|
272 |
QVERIFY(!connection.isConnected()); |
|
273 |
||
274 |
QDBusInterface interface("com.example.Test", QString(), "org.example.Test", |
|
275 |
connection); |
|
276 |
||
277 |
QVERIFY(!interface.isValid()); |
|
25
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
278 |
QVERIFY(!QMetaObject::invokeMethod(&interface, "ListNames", Qt::DirectConnection)); |
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
279 |
} |
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
280 |
|
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
281 |
void tst_QDBusInterface::notValidDerived() |
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
282 |
{ |
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
283 |
DerivedFromQDBusInterface c; |
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
284 |
QVERIFY(!c.isValid()); |
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
285 |
QMetaObject::invokeMethod(&c, "method", Qt::DirectConnection); |
0 | 286 |
} |
287 |
||
288 |
void tst_QDBusInterface::invalidAfterServiceOwnerChanged() |
|
289 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
290 |
// this test is technically the same as tst_QDBusAbstractInterface::followSignal |
0 | 291 |
QDBusConnection conn = QDBusConnection::sessionBus(); |
292 |
QDBusConnectionInterface *connIface = conn.interface(); |
|
293 |
||
294 |
QDBusInterface validInterface(conn.baseService(), "/"); |
|
295 |
QVERIFY(validInterface.isValid()); |
|
296 |
QDBusInterface invalidInterface("com.example.Test", "/"); |
|
297 |
QVERIFY(!invalidInterface.isValid()); |
|
298 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
299 |
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
|
300 |
SLOT(exitLoop())); |
0 | 301 |
QVERIFY(connIface->registerService("com.example.Test") == QDBusConnectionInterface::ServiceRegistered); |
302 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
303 |
QTestEventLoop::instance().enterLoop(5); |
0 | 304 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
305 |
QVERIFY(!QTestEventLoop::instance().timeout()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
306 |
QVERIFY(invalidInterface.isValid()); |
0 | 307 |
} |
308 |
||
309 |
void tst_QDBusInterface::introspect() |
|
310 |
{ |
|
311 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
312 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
313 |
TEST_INTERFACE_NAME); |
|
314 |
||
315 |
const QMetaObject *mo = iface.metaObject(); |
|
316 |
||
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
317 |
QCOMPARE(mo->methodCount() - mo->methodOffset(), 7); |
0 | 318 |
QVERIFY(mo->indexOfSignal(TEST_SIGNAL_NAME "(QString)") != -1); |
319 |
||
320 |
QCOMPARE(mo->propertyCount() - mo->propertyOffset(), 2); |
|
321 |
QVERIFY(mo->indexOfProperty("prop1") != -1); |
|
322 |
QVERIFY(mo->indexOfProperty("complexProp") != -1); |
|
323 |
} |
|
324 |
||
325 |
void tst_QDBusInterface::callMethod() |
|
326 |
{ |
|
327 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
328 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
329 |
TEST_INTERFACE_NAME); |
|
330 |
||
331 |
MyObject::callCount = 0; |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
332 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
333 |
// call a SLOT method |
0 | 334 |
QDBusMessage reply = iface.call("ping", qVariantFromValue(QDBusVariant("foo"))); |
335 |
QCOMPARE(MyObject::callCount, 1); |
|
336 |
QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); |
|
337 |
||
338 |
// verify what the callee received |
|
339 |
QCOMPARE(MyObject::callArgs.count(), 1); |
|
340 |
QVariant v = MyObject::callArgs.at(0); |
|
341 |
QDBusVariant dv = qdbus_cast<QDBusVariant>(v); |
|
342 |
QCOMPARE(dv.variant().type(), QVariant::String); |
|
343 |
QCOMPARE(dv.variant().toString(), QString("foo")); |
|
344 |
||
345 |
// verify reply |
|
346 |
QCOMPARE(reply.arguments().count(), 1); |
|
347 |
v = reply.arguments().at(0); |
|
348 |
dv = qdbus_cast<QDBusVariant>(v); |
|
349 |
QCOMPARE(dv.variant().type(), QVariant::String); |
|
350 |
QCOMPARE(dv.variant().toString(), QString("foo")); |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
351 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
352 |
// call an INVOKABLE method |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
353 |
reply = iface.call("ping_invokable", qVariantFromValue(QDBusVariant("bar"))); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
354 |
QCOMPARE(MyObject::callCount, 2); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
355 |
QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
356 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
357 |
// verify what the callee received |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
358 |
QCOMPARE(MyObject::callArgs.count(), 1); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
359 |
v = MyObject::callArgs.at(0); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
360 |
dv = qdbus_cast<QDBusVariant>(v); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
361 |
QCOMPARE(dv.variant().type(), QVariant::String); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
362 |
QCOMPARE(dv.variant().toString(), QString("bar")); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
363 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
364 |
// verify reply |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
365 |
QCOMPARE(reply.arguments().count(), 1); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
366 |
v = reply.arguments().at(0); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
367 |
dv = qdbus_cast<QDBusVariant>(v); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
368 |
QCOMPARE(dv.variant().type(), QVariant::String); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
369 |
QCOMPARE(dv.variant().toString(), QString("bar")); |
0 | 370 |
} |
371 |
||
372 |
void tst_QDBusInterface::invokeMethod() |
|
373 |
{ |
|
374 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
375 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
376 |
TEST_INTERFACE_NAME); |
|
377 |
||
378 |
MyObject::callCount = 0; |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
379 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
380 |
// make the SLOT call without a return type |
0 | 381 |
QDBusVariant arg("foo"); |
382 |
QVERIFY(QMetaObject::invokeMethod(&iface, "ping", Q_ARG(QDBusVariant, arg))); |
|
383 |
QCOMPARE(MyObject::callCount, 1); |
|
384 |
||
385 |
// verify what the callee received |
|
386 |
QCOMPARE(MyObject::callArgs.count(), 1); |
|
387 |
QVariant v = MyObject::callArgs.at(0); |
|
388 |
QDBusVariant dv = qdbus_cast<QDBusVariant>(v); |
|
389 |
QCOMPARE(dv.variant().type(), QVariant::String); |
|
390 |
QCOMPARE(dv.variant().toString(), QString("foo")); |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
391 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
392 |
// make the INVOKABLE call without a return type |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
393 |
QDBusVariant arg2("bar"); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
394 |
QVERIFY(QMetaObject::invokeMethod(&iface, "ping_invokable", Q_ARG(QDBusVariant, arg2))); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
395 |
QCOMPARE(MyObject::callCount, 2); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
396 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
397 |
// verify what the callee received |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
398 |
QCOMPARE(MyObject::callArgs.count(), 1); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
399 |
v = MyObject::callArgs.at(0); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
400 |
dv = qdbus_cast<QDBusVariant>(v); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
401 |
QCOMPARE(dv.variant().type(), QVariant::String); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
402 |
QCOMPARE(dv.variant().toString(), QString("bar")); |
0 | 403 |
} |
404 |
||
405 |
void tst_QDBusInterface::invokeMethodWithReturn() |
|
406 |
{ |
|
407 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
408 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
409 |
TEST_INTERFACE_NAME); |
|
410 |
||
411 |
MyObject::callCount = 0; |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
412 |
QDBusVariant retArg; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
413 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
414 |
// make the SLOT call without a return type |
0 | 415 |
QDBusVariant arg("foo"); |
416 |
QVERIFY(QMetaObject::invokeMethod(&iface, "ping", Q_RETURN_ARG(QDBusVariant, retArg), Q_ARG(QDBusVariant, arg))); |
|
417 |
QCOMPARE(MyObject::callCount, 1); |
|
418 |
||
419 |
// verify what the callee received |
|
420 |
QCOMPARE(MyObject::callArgs.count(), 1); |
|
421 |
QVariant v = MyObject::callArgs.at(0); |
|
422 |
QDBusVariant dv = qdbus_cast<QDBusVariant>(v); |
|
423 |
QCOMPARE(dv.variant().type(), QVariant::String); |
|
424 |
QCOMPARE(dv.variant().toString(), arg.variant().toString()); |
|
425 |
||
426 |
// verify that we got the reply as expected |
|
427 |
QCOMPARE(retArg.variant(), arg.variant()); |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
428 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
429 |
// make the INVOKABLE call without a return type |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
430 |
QDBusVariant arg2("bar"); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
431 |
QVERIFY(QMetaObject::invokeMethod(&iface, "ping_invokable", Q_RETURN_ARG(QDBusVariant, retArg), Q_ARG(QDBusVariant, arg2))); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
432 |
QCOMPARE(MyObject::callCount, 2); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
433 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
434 |
// verify what the callee received |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
435 |
QCOMPARE(MyObject::callArgs.count(), 1); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
436 |
v = MyObject::callArgs.at(0); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
437 |
dv = qdbus_cast<QDBusVariant>(v); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
438 |
QCOMPARE(dv.variant().type(), QVariant::String); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
439 |
QCOMPARE(dv.variant().toString(), arg2.variant().toString()); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
440 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
441 |
// verify that we got the reply as expected |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
442 |
QCOMPARE(retArg.variant(), arg2.variant()); |
0 | 443 |
} |
444 |
||
445 |
void tst_QDBusInterface::invokeMethodWithMultiReturn() |
|
446 |
{ |
|
447 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
448 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
449 |
TEST_INTERFACE_NAME); |
|
450 |
||
451 |
MyObject::callCount = 0; |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
452 |
QDBusVariant retArg, retArg2; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
453 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
454 |
// make the SLOT call without a return type |
0 | 455 |
QDBusVariant arg("foo"), arg2("bar"); |
456 |
QVERIFY(QMetaObject::invokeMethod(&iface, "ping", |
|
457 |
Q_RETURN_ARG(QDBusVariant, retArg), |
|
458 |
Q_ARG(QDBusVariant, arg), |
|
459 |
Q_ARG(QDBusVariant, arg2), |
|
460 |
Q_ARG(QDBusVariant&, retArg2))); |
|
461 |
QCOMPARE(MyObject::callCount, 1); |
|
462 |
||
463 |
// verify what the callee received |
|
464 |
QCOMPARE(MyObject::callArgs.count(), 2); |
|
465 |
QVariant v = MyObject::callArgs.at(0); |
|
466 |
QDBusVariant dv = qdbus_cast<QDBusVariant>(v); |
|
467 |
QCOMPARE(dv.variant().type(), QVariant::String); |
|
468 |
QCOMPARE(dv.variant().toString(), arg.variant().toString()); |
|
469 |
||
470 |
v = MyObject::callArgs.at(1); |
|
471 |
dv = qdbus_cast<QDBusVariant>(v); |
|
472 |
QCOMPARE(dv.variant().type(), QVariant::String); |
|
473 |
QCOMPARE(dv.variant().toString(), arg2.variant().toString()); |
|
474 |
||
475 |
// verify that we got the replies as expected |
|
476 |
QCOMPARE(retArg.variant(), arg.variant()); |
|
477 |
QCOMPARE(retArg2.variant(), arg2.variant()); |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
478 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
479 |
// make the INVOKABLE call without a return type |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
480 |
QDBusVariant arg3("hello"), arg4("world"); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
481 |
QVERIFY(QMetaObject::invokeMethod(&iface, "ping_invokable", |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
482 |
Q_RETURN_ARG(QDBusVariant, retArg), |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
483 |
Q_ARG(QDBusVariant, arg3), |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
484 |
Q_ARG(QDBusVariant, arg4), |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
485 |
Q_ARG(QDBusVariant&, retArg2))); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
486 |
QCOMPARE(MyObject::callCount, 2); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
487 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
488 |
// verify what the callee received |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
489 |
QCOMPARE(MyObject::callArgs.count(), 2); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
490 |
v = MyObject::callArgs.at(0); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
491 |
dv = qdbus_cast<QDBusVariant>(v); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
492 |
QCOMPARE(dv.variant().type(), QVariant::String); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
493 |
QCOMPARE(dv.variant().toString(), arg3.variant().toString()); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
494 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
495 |
v = MyObject::callArgs.at(1); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
496 |
dv = qdbus_cast<QDBusVariant>(v); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
497 |
QCOMPARE(dv.variant().type(), QVariant::String); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
498 |
QCOMPARE(dv.variant().toString(), arg4.variant().toString()); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
499 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
500 |
// verify that we got the replies as expected |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
501 |
QCOMPARE(retArg.variant(), arg3.variant()); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
502 |
QCOMPARE(retArg2.variant(), arg4.variant()); |
0 | 503 |
} |
504 |
||
505 |
void tst_QDBusInterface::invokeMethodWithComplexReturn() |
|
506 |
{ |
|
507 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
508 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
509 |
TEST_INTERFACE_NAME); |
|
510 |
||
511 |
MyObject::callCount = 0; |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
512 |
QList<int> retArg; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
513 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
514 |
// make the SLOT call without a return type |
0 | 515 |
QList<int> arg = QList<int>() << 42 << -47; |
516 |
QVERIFY(QMetaObject::invokeMethod(&iface, "ping", Q_RETURN_ARG(QList<int>, retArg), Q_ARG(QList<int>, arg))); |
|
517 |
QCOMPARE(MyObject::callCount, 1); |
|
518 |
||
519 |
// verify what the callee received |
|
520 |
QCOMPARE(MyObject::callArgs.count(), 1); |
|
521 |
QVariant v = MyObject::callArgs.at(0); |
|
522 |
QCOMPARE(v.userType(), qMetaTypeId<QDBusArgument>()); |
|
523 |
QCOMPARE(qdbus_cast<QList<int> >(v), arg); |
|
524 |
||
525 |
// verify that we got the reply as expected |
|
526 |
QCOMPARE(retArg, arg); |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
527 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
528 |
// make the INVOKABLE call without a return type |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
529 |
QList<int> arg2 = QList<int>() << 24 << -74; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
530 |
QVERIFY(QMetaObject::invokeMethod(&iface, "ping", Q_RETURN_ARG(QList<int>, retArg), Q_ARG(QList<int>, arg2))); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
531 |
QCOMPARE(MyObject::callCount, 2); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
532 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
533 |
// verify what the callee received |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
534 |
QCOMPARE(MyObject::callArgs.count(), 1); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
535 |
v = MyObject::callArgs.at(0); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
536 |
QCOMPARE(v.userType(), qMetaTypeId<QDBusArgument>()); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
537 |
QCOMPARE(qdbus_cast<QList<int> >(v), arg2); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
538 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
539 |
// verify that we got the reply as expected |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
540 |
QCOMPARE(retArg, arg2); |
0 | 541 |
} |
542 |
||
543 |
void tst_QDBusInterface::signal() |
|
544 |
{ |
|
545 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
546 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
547 |
TEST_INTERFACE_NAME); |
|
548 |
||
549 |
QString arg = "So long and thanks for all the fish"; |
|
550 |
{ |
|
551 |
Spy spy; |
|
552 |
spy.connect(&iface, SIGNAL(somethingHappened(QString)), SLOT(spySlot(QString))); |
|
553 |
||
554 |
emitSignal(TEST_INTERFACE_NAME, TEST_SIGNAL_NAME, arg); |
|
555 |
QCOMPARE(spy.count, 1); |
|
556 |
QCOMPARE(spy.received, arg); |
|
557 |
} |
|
558 |
||
559 |
QDBusInterface iface2(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
560 |
TEST_INTERFACE_NAME); |
|
561 |
{ |
|
562 |
Spy spy; |
|
563 |
spy.connect(&iface, SIGNAL(somethingHappened(QString)), SLOT(spySlot(QString))); |
|
564 |
spy.connect(&iface2, SIGNAL(somethingHappened(QString)), SLOT(spySlot(QString))); |
|
565 |
||
566 |
emitSignal(TEST_INTERFACE_NAME, TEST_SIGNAL_NAME, arg); |
|
567 |
QCOMPARE(spy.count, 2); |
|
568 |
QCOMPARE(spy.received, arg); |
|
569 |
} |
|
570 |
||
571 |
{ |
|
572 |
Spy spy, spy2; |
|
573 |
spy.connect(&iface, SIGNAL(somethingHappened(QString)), SLOT(spySlot(QString))); |
|
574 |
spy2.connect(&iface2, SIGNAL(somethingHappened(QString)), SLOT(spySlot(QString))); |
|
575 |
||
576 |
emitSignal(TEST_INTERFACE_NAME, TEST_SIGNAL_NAME, arg); |
|
577 |
QCOMPARE(spy.count, 1); |
|
578 |
QCOMPARE(spy.received, arg); |
|
579 |
QCOMPARE(spy2.count, 1); |
|
580 |
QCOMPARE(spy2.received, arg); |
|
581 |
} |
|
582 |
} |
|
583 |
||
584 |
void tst_QDBusInterface::propertyRead() |
|
585 |
{ |
|
586 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
587 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
588 |
TEST_INTERFACE_NAME); |
|
589 |
||
590 |
int arg = obj.m_prop1 = 42; |
|
591 |
MyObject::callCount = 0; |
|
592 |
||
593 |
QVariant v = iface.property("prop1"); |
|
594 |
QVERIFY(v.isValid()); |
|
595 |
QCOMPARE(v.userType(), int(QVariant::Int)); |
|
596 |
QCOMPARE(v.toInt(), arg); |
|
597 |
QCOMPARE(MyObject::callCount, 1); |
|
598 |
} |
|
599 |
||
600 |
void tst_QDBusInterface::propertyWrite() |
|
601 |
{ |
|
602 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
603 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
604 |
TEST_INTERFACE_NAME); |
|
605 |
||
606 |
int arg = 42; |
|
607 |
obj.m_prop1 = 0; |
|
608 |
MyObject::callCount = 0; |
|
609 |
||
610 |
QVERIFY(iface.setProperty("prop1", arg)); |
|
611 |
QCOMPARE(MyObject::callCount, 1); |
|
612 |
QCOMPARE(obj.m_prop1, arg); |
|
613 |
} |
|
614 |
||
615 |
void tst_QDBusInterface::complexPropertyRead() |
|
616 |
{ |
|
617 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
618 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
619 |
TEST_INTERFACE_NAME); |
|
620 |
||
621 |
QList<int> arg = obj.m_complexProp = QList<int>() << 42 << -47; |
|
622 |
MyObject::callCount = 0; |
|
623 |
||
624 |
QVariant v = iface.property("complexProp"); |
|
625 |
QVERIFY(v.isValid()); |
|
626 |
QCOMPARE(v.userType(), qMetaTypeId<QList<int> >()); |
|
627 |
QCOMPARE(v.value<QList<int> >(), arg); |
|
628 |
QCOMPARE(MyObject::callCount, 1); |
|
629 |
} |
|
630 |
||
631 |
void tst_QDBusInterface::complexPropertyWrite() |
|
632 |
{ |
|
633 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
634 |
QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), |
|
635 |
TEST_INTERFACE_NAME); |
|
636 |
||
637 |
QList<int> arg = QList<int>() << -47 << 42; |
|
638 |
obj.m_complexProp.clear(); |
|
639 |
MyObject::callCount = 0; |
|
640 |
||
641 |
QVERIFY(iface.setProperty("complexProp", qVariantFromValue(arg))); |
|
642 |
QCOMPARE(MyObject::callCount, 1); |
|
643 |
QCOMPARE(obj.m_complexProp, arg); |
|
644 |
} |
|
645 |
||
646 |
QTEST_MAIN(tst_QDBusInterface) |
|
647 |
||
648 |
#include "tst_qdbusinterface.moc" |
|
649 |