author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
#define DBUS_API_SUBJECT_TO_CHANGE |
|
42 |
#include <QtCore/QtCore> |
|
43 |
#include <QtTest/QtTest> |
|
44 |
#include <QtDBus/QtDBus> |
|
45 |
#include <QtDBus/private/qdbusutil_p.h> |
|
46 |
||
47 |
#include "common.h" |
|
48 |
#include <limits> |
|
49 |
||
50 |
static const char serviceName[] = "com.trolltech.autotests.qpong"; |
|
51 |
static const char objectPath[] = "/com/trolltech/qpong"; |
|
52 |
static const char *interfaceName = serviceName; |
|
53 |
||
54 |
class tst_QDBusMarshall: public QObject |
|
55 |
{ |
|
56 |
Q_OBJECT |
|
57 |
||
58 |
public slots: |
|
59 |
void initTestCase(); |
|
60 |
void cleanupTestCase(); |
|
61 |
||
62 |
private slots: |
|
63 |
void sendBasic_data(); |
|
64 |
void sendBasic(); |
|
65 |
||
66 |
void sendVariant_data(); |
|
67 |
void sendVariant(); |
|
68 |
||
69 |
void sendArrays_data(); |
|
70 |
void sendArrays(); |
|
71 |
||
72 |
void sendArrayOfArrays_data(); |
|
73 |
void sendArrayOfArrays(); |
|
74 |
||
75 |
void sendMaps_data(); |
|
76 |
void sendMaps(); |
|
77 |
||
78 |
void sendStructs_data(); |
|
79 |
void sendStructs(); |
|
80 |
||
81 |
void sendComplex_data(); |
|
82 |
void sendComplex(); |
|
83 |
||
84 |
void sendArgument_data(); |
|
85 |
void sendArgument(); |
|
86 |
||
87 |
void sendSignalErrors(); |
|
88 |
void sendCallErrors_data(); |
|
89 |
void sendCallErrors(); |
|
90 |
||
91 |
private: |
|
92 |
QProcess proc; |
|
93 |
}; |
|
94 |
||
95 |
struct UnregisteredType { }; |
|
96 |
Q_DECLARE_METATYPE(UnregisteredType) |
|
97 |
||
98 |
class WaitForQPong: public QObject |
|
99 |
{ |
|
100 |
Q_OBJECT |
|
101 |
public: |
|
102 |
WaitForQPong(); |
|
103 |
bool ok(); |
|
104 |
public Q_SLOTS: |
|
105 |
void ownerChange(const QString &name) |
|
106 |
{ |
|
107 |
if (name == serviceName) |
|
108 |
loop.quit(); |
|
109 |
} |
|
110 |
||
111 |
private: |
|
112 |
QEventLoop loop; |
|
113 |
}; |
|
114 |
||
115 |
WaitForQPong::WaitForQPong() |
|
116 |
{ |
|
117 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
118 |
if (!ok()) { |
|
119 |
connect(con.interface(), SIGNAL(serviceOwnerChanged(QString,QString,QString)), |
|
120 |
SLOT(ownerChange(QString))); |
|
121 |
QTimer::singleShot(2000, &loop, SLOT(quit())); |
|
122 |
loop.exec(); |
|
123 |
} |
|
124 |
} |
|
125 |
||
126 |
bool WaitForQPong::ok() |
|
127 |
{ |
|
128 |
return QDBusConnection::sessionBus().isConnected() && |
|
129 |
QDBusConnection::sessionBus().interface()->isServiceRegistered(serviceName); |
|
130 |
} |
|
131 |
||
132 |
void tst_QDBusMarshall::initTestCase() |
|
133 |
{ |
|
134 |
commonInit(); |
|
135 |
#ifdef Q_OS_WIN |
|
136 |
proc.start("qpong"); |
|
137 |
#else |
|
138 |
proc.start("./qpong/qpong"); |
|
139 |
#endif |
|
140 |
QVERIFY(proc.waitForStarted()); |
|
141 |
||
142 |
WaitForQPong w; |
|
143 |
QVERIFY(w.ok()); |
|
144 |
//QTest::qWait(2000); |
|
145 |
} |
|
146 |
||
147 |
void tst_QDBusMarshall::cleanupTestCase() |
|
148 |
{ |
|
149 |
proc.close(); |
|
150 |
proc.kill(); |
|
151 |
} |
|
152 |
||
153 |
void tst_QDBusMarshall::sendBasic_data() |
|
154 |
{ |
|
155 |
QTest::addColumn<QVariant>("value"); |
|
156 |
QTest::addColumn<QString>("sig"); |
|
157 |
QTest::addColumn<QString>("stringResult"); |
|
158 |
||
159 |
// basic types: |
|
160 |
QTest::newRow("bool") << QVariant(false) << "b" << "false"; |
|
161 |
#if 1 |
|
162 |
QTest::newRow("bool2") << QVariant(true) << "b" << "true"; |
|
163 |
QTest::newRow("byte") << qVariantFromValue(uchar(1)) << "y" << "1"; |
|
164 |
QTest::newRow("int16") << qVariantFromValue(short(2)) << "n" << "2"; |
|
165 |
QTest::newRow("uint16") << qVariantFromValue(ushort(3)) << "q" << "3"; |
|
166 |
QTest::newRow("int") << QVariant(1) << "i" << "1"; |
|
167 |
QTest::newRow("uint") << QVariant(2U) << "u" << "2"; |
|
168 |
QTest::newRow("int64") << QVariant(Q_INT64_C(3)) << "x" << "3"; |
|
169 |
QTest::newRow("uint64") << QVariant(Q_UINT64_C(4)) << "t" << "4"; |
|
170 |
QTest::newRow("double") << QVariant(42.5) << "d" << "42.5"; |
|
171 |
QTest::newRow("string") << QVariant("ping") << "s" << "\"ping\""; |
|
172 |
QTest::newRow("objectpath") << qVariantFromValue(QDBusObjectPath("/org/kde")) << "o" << "[ObjectPath: /org/kde]"; |
|
173 |
QTest::newRow("signature") << qVariantFromValue(QDBusSignature("g")) << "g" << "[Signature: g]"; |
|
174 |
QTest::newRow("emptystring") << QVariant("") << "s" << "\"\""; |
|
175 |
QTest::newRow("nullstring") << QVariant(QString()) << "s" << "\"\""; |
|
176 |
#endif |
|
177 |
} |
|
178 |
||
179 |
void tst_QDBusMarshall::sendVariant_data() |
|
180 |
{ |
|
181 |
sendBasic_data(); |
|
182 |
||
183 |
QTest::newRow("variant") << qVariantFromValue(QDBusVariant(1)) << "v" << "[Variant(int): 1]"; |
|
184 |
||
185 |
QDBusVariant nested(1); |
|
186 |
QTest::newRow("variant-variant") << qVariantFromValue(QDBusVariant(qVariantFromValue(nested))) << "v" |
|
187 |
<< "[Variant(QDBusVariant): [Variant(int): 1]]"; |
|
188 |
} |
|
189 |
||
190 |
void tst_QDBusMarshall::sendArrays_data() |
|
191 |
{ |
|
192 |
QTest::addColumn<QVariant>("value"); |
|
193 |
QTest::addColumn<QString>("sig"); |
|
194 |
QTest::addColumn<QString>("stringResult"); |
|
195 |
||
196 |
// arrays |
|
197 |
QStringList strings; |
|
198 |
QTest::newRow("emptystringlist") << QVariant(strings) << "as" << "{}"; |
|
199 |
strings << "hello" << "world"; |
|
200 |
QTest::newRow("stringlist") << QVariant(strings) << "as" << "{\"hello\", \"world\"}"; |
|
201 |
||
202 |
strings.clear(); |
|
203 |
strings << "" << "" << ""; |
|
204 |
QTest::newRow("list-of-emptystrings") << QVariant(strings) << "as" << "{\"\", \"\", \"\"}"; |
|
205 |
||
206 |
strings.clear(); |
|
207 |
strings << QString() << QString() << QString() << QString(); |
|
208 |
QTest::newRow("list-of-nullstrings") << QVariant(strings) << "as" << "{\"\", \"\", \"\", \"\"}"; |
|
209 |
||
210 |
QByteArray bytearray; |
|
211 |
QTest::newRow("nullbytearray") << QVariant(bytearray) << "ay" << "{}"; |
|
212 |
bytearray = ""; // empty, not null |
|
213 |
QTest::newRow("emptybytearray") << QVariant(bytearray) << "ay" << "{}"; |
|
214 |
bytearray = "foo"; |
|
215 |
QTest::newRow("bytearray") << QVariant(bytearray) << "ay" << "{102, 111, 111}"; |
|
216 |
||
217 |
QList<bool> bools; |
|
218 |
QTest::newRow("emptyboollist") << qVariantFromValue(bools) << "ab" << "[Argument: ab {}]"; |
|
219 |
bools << false << true << false; |
|
220 |
QTest::newRow("boollist") << qVariantFromValue(bools) << "ab" << "[Argument: ab {false, true, false}]"; |
|
221 |
||
222 |
QList<short> shorts; |
|
223 |
QTest::newRow("emptyshortlist") << qVariantFromValue(shorts) << "an" << "[Argument: an {}]"; |
|
224 |
shorts << 42 << -43 << 44 << 45 << -32768 << 32767; |
|
225 |
QTest::newRow("shortlist") << qVariantFromValue(shorts) << "an" |
|
226 |
<< "[Argument: an {42, -43, 44, 45, -32768, 32767}]"; |
|
227 |
||
228 |
QList<ushort> ushorts; |
|
229 |
QTest::newRow("emptyushortlist") << qVariantFromValue(ushorts) << "aq" << "[Argument: aq {}]"; |
|
230 |
ushorts << 12u << 13u << 14u << 15 << 65535; |
|
231 |
QTest::newRow("ushortlist") << qVariantFromValue(ushorts) << "aq" << "[Argument: aq {12, 13, 14, 15, 65535}]"; |
|
232 |
||
233 |
QList<int> ints; |
|
234 |
QTest::newRow("emptyintlist") << qVariantFromValue(ints) << "ai" << "[Argument: ai {}]"; |
|
235 |
ints << 42 << -43 << 44 << 45 << 2147483647 << -2147483647-1; |
|
236 |
QTest::newRow("intlist") << qVariantFromValue(ints) << "ai" << "[Argument: ai {42, -43, 44, 45, 2147483647, -2147483648}]"; |
|
237 |
||
238 |
QList<uint> uints; |
|
239 |
QTest::newRow("emptyuintlist") << qVariantFromValue(uints) << "au" << "[Argument: au {}]"; |
|
240 |
uints << uint(12) << uint(13) << uint(14) << 4294967295U; |
|
241 |
QTest::newRow("uintlist") << qVariantFromValue(uints) << "au" << "[Argument: au {12, 13, 14, 4294967295}]"; |
|
242 |
||
243 |
QList<qlonglong> llints; |
|
244 |
QTest::newRow("emptyllintlist") << qVariantFromValue(llints) << "ax" << "[Argument: ax {}]"; |
|
245 |
llints << Q_INT64_C(99) << Q_INT64_C(-100) |
|
246 |
<< Q_INT64_C(-9223372036854775807)-1 << Q_INT64_C(9223372036854775807); |
|
247 |
QTest::newRow("llintlist") << qVariantFromValue(llints) << "ax" |
|
248 |
<< "[Argument: ax {99, -100, -9223372036854775808, 9223372036854775807}]"; |
|
249 |
||
250 |
QList<qulonglong> ullints; |
|
251 |
QTest::newRow("emptyullintlist") << qVariantFromValue(ullints) << "at" << "[Argument: at {}]"; |
|
252 |
ullints << Q_UINT64_C(66) << Q_UINT64_C(67) |
|
253 |
<< Q_UINT64_C(18446744073709551615); |
|
254 |
QTest::newRow("ullintlist") << qVariantFromValue(ullints) << "at" << "[Argument: at {66, 67, 18446744073709551615}]"; |
|
255 |
||
256 |
QList<double> doubles; |
|
257 |
QTest::newRow("emptydoublelist") << qVariantFromValue(doubles) << "ad" << "[Argument: ad {}]"; |
|
258 |
doubles << 1.2 << 2.2 << 4.4 |
|
259 |
<< -std::numeric_limits<double>::infinity() |
|
260 |
<< std::numeric_limits<double>::infinity() |
|
261 |
<< std::numeric_limits<double>::quiet_NaN(); |
|
262 |
QTest::newRow("doublelist") << qVariantFromValue(doubles) << "ad" << "[Argument: ad {1.2, 2.2, 4.4, -inf, inf, nan}]"; |
|
263 |
||
264 |
QVariantList variants; |
|
265 |
QTest::newRow("emptyvariantlist") << QVariant(variants) << "av" << "[Argument: av {}]"; |
|
266 |
variants << QString("Hello") << QByteArray("World") << 42 << -43.0 << 44U << Q_INT64_C(-45) |
|
267 |
<< Q_UINT64_C(46) << true << qVariantFromValue(short(-47)) |
|
268 |
<< qVariantFromValue(QDBusSignature("av")) |
|
269 |
<< qVariantFromValue(QDBusVariant(qVariantFromValue(QDBusObjectPath("/")))); |
|
270 |
QTest::newRow("variantlist") << QVariant(variants) << "av" |
|
271 |
<< "[Argument: av {[Variant(QString): \"Hello\"], [Variant(QByteArray): {87, 111, 114, 108, 100}], [Variant(int): 42], [Variant(double): -43], [Variant(uint): 44], [Variant(qlonglong): -45], [Variant(qulonglong): 46], [Variant(bool): true], [Variant(short): -47], [Variant: [Signature: av]], [Variant: [Variant: [ObjectPath: /]]]}]"; |
|
272 |
} |
|
273 |
||
274 |
void tst_QDBusMarshall::sendArrayOfArrays_data() |
|
275 |
{ |
|
276 |
QTest::addColumn<QVariant>("value"); |
|
277 |
QTest::addColumn<QString>("sig"); |
|
278 |
QTest::addColumn<QString>("stringResult"); |
|
279 |
||
280 |
// arrays: |
|
281 |
QList<QStringList> strings; |
|
282 |
QTest::newRow("empty-list-of-stringlist") << qVariantFromValue(strings) << "aas" |
|
283 |
<< "[Argument: aas {}]"; |
|
284 |
strings << QStringList(); |
|
285 |
QTest::newRow("list-of-emptystringlist") << qVariantFromValue(strings) << "aas" |
|
286 |
<< "[Argument: aas {{}}]"; |
|
287 |
strings << (QStringList() << "hello" << "world") |
|
288 |
<< (QStringList() << "hi" << "there") |
|
289 |
<< (QStringList() << QString()); |
|
290 |
QTest::newRow("stringlist") << qVariantFromValue(strings) << "aas" |
|
291 |
<< "[Argument: aas {{}, {\"hello\", \"world\"}, {\"hi\", \"there\"}, {\"\"}}]"; |
|
292 |
||
293 |
QList<QByteArray> bytearray; |
|
294 |
QTest::newRow("empty-list-of-bytearray") << qVariantFromValue(bytearray) << "aay" |
|
295 |
<< "[Argument: aay {}]"; |
|
296 |
bytearray << QByteArray(); |
|
297 |
QTest::newRow("list-of-emptybytearray") << qVariantFromValue(bytearray) << "aay" |
|
298 |
<< "[Argument: aay {{}}]"; |
|
299 |
bytearray << "foo" << "bar" << "baz" << "" << QByteArray(); |
|
300 |
QTest::newRow("bytearray") << qVariantFromValue(bytearray) << "aay" |
|
301 |
<< "[Argument: aay {{}, {102, 111, 111}, {98, 97, 114}, {98, 97, 122}, {}, {}}]"; |
|
302 |
||
303 |
QList<QList<bool> > bools; |
|
304 |
QTest::newRow("empty-list-of-boollist") << qVariantFromValue(bools) << "aab" |
|
305 |
<< "[Argument: aab {}]"; |
|
306 |
bools << QList<bool>(); |
|
307 |
QTest::newRow("list-of-emptyboollist") << qVariantFromValue(bools) << "aab" |
|
308 |
<< "[Argument: aab {[Argument: ab {}]}]"; |
|
309 |
bools << (QList<bool>() << false << true) << (QList<bool>() << false) << (QList<bool>()); |
|
310 |
QTest::newRow("boollist") << qVariantFromValue(bools) << "aab" |
|
311 |
<< "[Argument: aab {[Argument: ab {}], [Argument: ab {false, true}], [Argument: ab {false}], [Argument: ab {}]}]"; |
|
312 |
QList<QList<short> > shorts; |
|
313 |
QTest::newRow("empty-list-of-shortlist") << qVariantFromValue(shorts) << "aan" |
|
314 |
<< "[Argument: aan {}]"; |
|
315 |
shorts << QList<short>(); |
|
316 |
QTest::newRow("list-of-emptyshortlist") << qVariantFromValue(shorts) << "aan" |
|
317 |
<< "[Argument: aan {[Argument: an {}]}]"; |
|
318 |
shorts << (QList<short>() << 42 << -43 << 44 << 45) |
|
319 |
<< (QList<short>() << -32768 << 32767) |
|
320 |
<< (QList<short>()); |
|
321 |
QTest::newRow("shortlist") << qVariantFromValue(shorts) << "aan" |
|
322 |
<< "[Argument: aan {[Argument: an {}], [Argument: an {42, -43, 44, 45}], [Argument: an {-32768, 32767}], [Argument: an {}]}]"; |
|
323 |
||
324 |
QList<QList<ushort> > ushorts; |
|
325 |
QTest::newRow("empty-list-of-ushortlist") << qVariantFromValue(ushorts) << "aaq" |
|
326 |
<< "[Argument: aaq {}]"; |
|
327 |
ushorts << QList<ushort>(); |
|
328 |
QTest::newRow("list-of-emptyushortlist") << qVariantFromValue(ushorts) << "aaq" |
|
329 |
<< "[Argument: aaq {[Argument: aq {}]}]"; |
|
330 |
ushorts << (QList<ushort>() << 12u << 13u << 14u << 15) |
|
331 |
<< (QList<ushort>() << 65535) |
|
332 |
<< (QList<ushort>()); |
|
333 |
QTest::newRow("ushortlist") << qVariantFromValue(ushorts) << "aaq" |
|
334 |
<< "[Argument: aaq {[Argument: aq {}], [Argument: aq {12, 13, 14, 15}], [Argument: aq {65535}], [Argument: aq {}]}]"; |
|
335 |
||
336 |
QList<QList<int> > ints; |
|
337 |
QTest::newRow("empty-list-of-intlist") << qVariantFromValue(ints) << "aai" |
|
338 |
<< "[Argument: aai {}]"; |
|
339 |
ints << QList<int>(); |
|
340 |
QTest::newRow("list-of-emptyintlist") << qVariantFromValue(ints) << "aai" |
|
341 |
<< "[Argument: aai {[Argument: ai {}]}]"; |
|
342 |
ints << (QList<int>() << 42 << -43 << 44 << 45) |
|
343 |
<< (QList<int>() << 2147483647 << -2147483647-1) |
|
344 |
<< (QList<int>()); |
|
345 |
QTest::newRow("intlist") << qVariantFromValue(ints) << "aai" |
|
346 |
<< "[Argument: aai {[Argument: ai {}], [Argument: ai {42, -43, 44, 45}], [Argument: ai {2147483647, -2147483648}], [Argument: ai {}]}]"; |
|
347 |
||
348 |
QList<QList<uint> > uints; |
|
349 |
QTest::newRow("empty-list-of-uintlist") << qVariantFromValue(uints) << "aau" |
|
350 |
<< "[Argument: aau {}]"; |
|
351 |
uints << QList<uint>(); |
|
352 |
QTest::newRow("list-of-emptyuintlist") << qVariantFromValue(uints) << "aau" |
|
353 |
<< "[Argument: aau {[Argument: au {}]}]"; |
|
354 |
uints << (QList<uint>() << uint(12) << uint(13) << uint(14)) |
|
355 |
<< (QList<uint>() << 4294967295U) |
|
356 |
<< (QList<uint>()); |
|
357 |
QTest::newRow("uintlist") << qVariantFromValue(uints) << "aau" |
|
358 |
<< "[Argument: aau {[Argument: au {}], [Argument: au {12, 13, 14}], [Argument: au {4294967295}], [Argument: au {}]}]"; |
|
359 |
||
360 |
QList<QList<qlonglong> > llints; |
|
361 |
QTest::newRow("empty-list-of-llintlist") << qVariantFromValue(llints) << "aax" |
|
362 |
<< "[Argument: aax {}]"; |
|
363 |
llints << QList<qlonglong>(); |
|
364 |
QTest::newRow("list-of-emptyllintlist") << qVariantFromValue(llints) << "aax" |
|
365 |
<< "[Argument: aax {[Argument: ax {}]}]"; |
|
366 |
llints << (QList<qlonglong>() << Q_INT64_C(99) << Q_INT64_C(-100)) |
|
367 |
<< (QList<qlonglong>() << Q_INT64_C(-9223372036854775807)-1 << Q_INT64_C(9223372036854775807)) |
|
368 |
<< (QList<qlonglong>()); |
|
369 |
QTest::newRow("llintlist") << qVariantFromValue(llints) << "aax" |
|
370 |
<< "[Argument: aax {[Argument: ax {}], [Argument: ax {99, -100}], [Argument: ax {-9223372036854775808, 9223372036854775807}], [Argument: ax {}]}]"; |
|
371 |
||
372 |
QList<QList<qulonglong> > ullints; |
|
373 |
QTest::newRow("empty-list-of-ullintlist") << qVariantFromValue(ullints) << "aat" |
|
374 |
<< "[Argument: aat {}]"; |
|
375 |
ullints << QList<qulonglong>(); |
|
376 |
QTest::newRow("list-of-emptyullintlist") << qVariantFromValue(ullints) << "aat" |
|
377 |
<< "[Argument: aat {[Argument: at {}]}]"; |
|
378 |
ullints << (QList<qulonglong>() << Q_UINT64_C(66) << Q_UINT64_C(67)) |
|
379 |
<< (QList<qulonglong>() << Q_UINT64_C(18446744073709551615)) |
|
380 |
<< (QList<qulonglong>()); |
|
381 |
QTest::newRow("ullintlist") << qVariantFromValue(ullints) << "aat" |
|
382 |
<< "[Argument: aat {[Argument: at {}], [Argument: at {66, 67}], [Argument: at {18446744073709551615}], [Argument: at {}]}]"; |
|
383 |
||
384 |
QList<QList<double> > doubles; |
|
385 |
QTest::newRow("empty-list-ofdoublelist") << qVariantFromValue(doubles) << "aad" |
|
386 |
<< "[Argument: aad {}]"; |
|
387 |
doubles << QList<double>(); |
|
388 |
QTest::newRow("list-of-emptydoublelist") << qVariantFromValue(doubles) << "aad" |
|
389 |
<< "[Argument: aad {[Argument: ad {}]}]"; |
|
390 |
doubles << (QList<double>() << 1.2 << 2.2 << 4.4) |
|
391 |
<< (QList<double>() << -std::numeric_limits<double>::infinity() |
|
392 |
<< std::numeric_limits<double>::infinity() |
|
393 |
<< std::numeric_limits<double>::quiet_NaN()) |
|
394 |
<< (QList<double>()); |
|
395 |
QTest::newRow("doublelist") << qVariantFromValue(doubles) << "aad" |
|
396 |
<< "[Argument: aad {[Argument: ad {}], [Argument: ad {1.2, 2.2, 4.4}], [Argument: ad {-inf, inf, nan}], [Argument: ad {}]}]"; |
|
397 |
||
398 |
QList<QVariantList> variants; |
|
399 |
QTest::newRow("emptyvariantlist") << qVariantFromValue(variants) << "aav" |
|
400 |
<< "[Argument: aav {}]"; |
|
401 |
variants << QVariantList(); |
|
402 |
QTest::newRow("emptyvariantlist") << qVariantFromValue(variants) << "aav" |
|
403 |
<< "[Argument: aav {[Argument: av {}]}]"; |
|
404 |
variants << (QVariantList() << QString("Hello") << QByteArray("World")) |
|
405 |
<< (QVariantList() << 42 << -43.0 << 44U << Q_INT64_C(-45)) |
|
406 |
<< (QVariantList() << Q_UINT64_C(46) << true << qVariantFromValue(short(-47))); |
|
407 |
QTest::newRow("variantlist") << qVariantFromValue(variants) << "aav" |
|
408 |
<< "[Argument: aav {[Argument: av {}], [Argument: av {[Variant(QString): \"Hello\"], [Variant(QByteArray): {87, 111, 114, 108, 100}]}], [Argument: av {[Variant(int): 42], [Variant(double): -43], [Variant(uint): 44], [Variant(qlonglong): -45]}], [Argument: av {[Variant(qulonglong): 46], [Variant(bool): true], [Variant(short): -47]}]}]"; |
|
409 |
} |
|
410 |
||
411 |
void tst_QDBusMarshall::sendMaps_data() |
|
412 |
{ |
|
413 |
QTest::addColumn<QVariant>("value"); |
|
414 |
QTest::addColumn<QString>("sig"); |
|
415 |
QTest::addColumn<QString>("stringResult"); |
|
416 |
||
417 |
QMap<int, QString> ismap; |
|
418 |
QTest::newRow("empty-is-map") << qVariantFromValue(ismap) << "a{is}" |
|
419 |
<< "[Argument: a{is} {}]"; |
|
420 |
ismap[1] = "a"; |
|
421 |
ismap[2000] = "b"; |
|
422 |
ismap[-47] = "c"; |
|
423 |
QTest::newRow("is-map") << qVariantFromValue(ismap) << "a{is}" |
|
424 |
<< "[Argument: a{is} {-47 = \"c\", 1 = \"a\", 2000 = \"b\"}]"; |
|
425 |
||
426 |
QMap<QString, QString> ssmap; |
|
427 |
QTest::newRow("empty-ss-map") << qVariantFromValue(ssmap) << "a{ss}" |
|
428 |
<< "[Argument: a{ss} {}]"; |
|
429 |
ssmap["a"] = "a"; |
|
430 |
ssmap["c"] = "b"; |
|
431 |
ssmap["b"] = "c"; |
|
432 |
QTest::newRow("ss-map") << qVariantFromValue(ssmap) << "a{ss}" |
|
433 |
<< "[Argument: a{ss} {\"a\" = \"a\", \"b\" = \"c\", \"c\" = \"b\"}]"; |
|
434 |
||
435 |
QVariantMap svmap; |
|
436 |
QTest::newRow("empty-sv-map") << qVariantFromValue(svmap) << "a{sv}" |
|
437 |
<< "[Argument: a{sv} {}]"; |
|
438 |
svmap["a"] = 1; |
|
439 |
svmap["c"] = "b"; |
|
440 |
svmap["b"] = QByteArray("c"); |
|
441 |
svmap["d"] = 42U; |
|
442 |
svmap["e"] = qVariantFromValue(short(-47)); |
|
443 |
svmap["f"] = qVariantFromValue(QDBusVariant(0)); |
|
444 |
QTest::newRow("sv-map1") << qVariantFromValue(svmap) << "a{sv}" |
|
445 |
<< "[Argument: a{sv} {\"a\" = [Variant(int): 1], \"b\" = [Variant(QByteArray): {99}], \"c\" = [Variant(QString): \"b\"], \"d\" = [Variant(uint): 42], \"e\" = [Variant(short): -47], \"f\" = [Variant: [Variant(int): 0]]}]"; |
|
446 |
||
447 |
QMap<QDBusObjectPath, QString> osmap; |
|
448 |
QTest::newRow("empty-os-map") << qVariantFromValue(osmap) << "a{os}" |
|
449 |
<< "[Argument: a{os} {}]"; |
|
450 |
osmap[QDBusObjectPath("/")] = "root"; |
|
451 |
osmap[QDBusObjectPath("/foo")] = "foo"; |
|
452 |
osmap[QDBusObjectPath("/bar/baz")] = "bar and baz"; |
|
453 |
QTest::newRow("os-map") << qVariantFromValue(osmap) << "a{os}" |
|
454 |
<< "[Argument: a{os} {[ObjectPath: /] = \"root\", [ObjectPath: /bar/baz] = \"bar and baz\", [ObjectPath: /foo] = \"foo\"}]"; |
|
455 |
||
456 |
QHash<QDBusSignature, QString> gsmap; |
|
457 |
QTest::newRow("empty-gs-map") << qVariantFromValue(gsmap) << "a{gs}" |
|
458 |
<< "[Argument: a{gs} {}]"; |
|
459 |
gsmap[QDBusSignature("i")] = "int32"; |
|
460 |
gsmap[QDBusSignature("s")] = "string"; |
|
461 |
gsmap[QDBusSignature("a{gs}")] = "array of dict_entry of (signature, string)"; |
|
462 |
QTest::newRow("gs-map") << qVariantFromValue(gsmap) << "a{gs}" |
|
463 |
<< "[Argument: a{gs} {[Signature: a{gs}] = \"array of dict_entry of (signature, string)\", [Signature: i] = \"int32\", [Signature: s] = \"string\"}]"; |
|
464 |
||
465 |
svmap.clear(); |
|
466 |
svmap["ismap"] = qVariantFromValue(ismap); |
|
467 |
svmap["ssmap"] = qVariantFromValue(ssmap); |
|
468 |
svmap["osmap"] = qVariantFromValue(osmap); |
|
469 |
svmap["gsmap"] = qVariantFromValue(gsmap); |
|
470 |
QTest::newRow("sv-map2") << qVariantFromValue(svmap) << "a{sv}" |
|
471 |
<< "[Argument: a{sv} {\"gsmap\" = [Variant: [Argument: a{gs} {[Signature: a{gs}] = \"array of dict_entry of (signature, string)\", [Signature: i] = \"int32\", [Signature: s] = \"string\"}]], \"ismap\" = [Variant: [Argument: a{is} {-47 = \"c\", 1 = \"a\", 2000 = \"b\"}]], \"osmap\" = [Variant: [Argument: a{os} {[ObjectPath: /] = \"root\", [ObjectPath: /bar/baz] = \"bar and baz\", [ObjectPath: /foo] = \"foo\"}]], \"ssmap\" = [Variant: [Argument: a{ss} {\"a\" = \"a\", \"b\" = \"c\", \"c\" = \"b\"}]]}]"; |
|
472 |
} |
|
473 |
||
474 |
void tst_QDBusMarshall::sendStructs_data() |
|
475 |
{ |
|
476 |
QTest::addColumn<QVariant>("value"); |
|
477 |
QTest::addColumn<QString>("sig"); |
|
478 |
QTest::addColumn<QString>("stringResult"); |
|
479 |
||
480 |
QTest::newRow("point") << QVariant(QPoint(1, 2)) << "(ii)" << "[Argument: (ii) 1, 2]"; |
|
481 |
QTest::newRow("pointf") << QVariant(QPointF(1.5, -1.5)) << "(dd)" << "[Argument: (dd) 1.5, -1.5]"; |
|
482 |
||
483 |
QTest::newRow("size") << QVariant(QSize(1, 2)) << "(ii)" << "[Argument: (ii) 1, 2]"; |
|
484 |
QTest::newRow("sizef") << QVariant(QSizeF(1.5, 1.5)) << "(dd)" << "[Argument: (dd) 1.5, 1.5]"; |
|
485 |
||
486 |
QTest::newRow("rect") << QVariant(QRect(1, 2, 3, 4)) << "(iiii)" << "[Argument: (iiii) 1, 2, 3, 4]"; |
|
487 |
QTest::newRow("rectf") << QVariant(QRectF(0.5, 0.5, 1.5, 1.5)) << "(dddd)" << "[Argument: (dddd) 0.5, 0.5, 1.5, 1.5]"; |
|
488 |
||
489 |
QTest::newRow("line") << QVariant(QLine(1, 2, 3, 4)) << "((ii)(ii))" |
|
490 |
<< "[Argument: ((ii)(ii)) [Argument: (ii) 1, 2], [Argument: (ii) 3, 4]]"; |
|
491 |
QTest::newRow("linef") << QVariant(QLineF(0.5, 0.5, 1.5, 1.5)) << "((dd)(dd))" |
|
492 |
<< "[Argument: ((dd)(dd)) [Argument: (dd) 0.5, 0.5], [Argument: (dd) 1.5, 1.5]]"; |
|
493 |
||
494 |
QDate date(2006, 6, 18); |
|
495 |
QTime time(12, 25, 00); // the date I wrote this test on :-) |
|
496 |
QTest::newRow("date") << QVariant(date) << "(iii)" << "[Argument: (iii) 2006, 6, 18]"; |
|
497 |
QTest::newRow("time") << QVariant(time) << "(iiii)" << "[Argument: (iiii) 12, 25, 0, 0]"; |
|
498 |
QTest::newRow("datetime") << QVariant(QDateTime(date, time)) << "((iii)(iiii)i)" |
|
499 |
<< "[Argument: ((iii)(iiii)i) [Argument: (iii) 2006, 6, 18], [Argument: (iiii) 12, 25, 0, 0], 0]"; |
|
500 |
||
501 |
MyStruct ms = { 1, "Hello, World" }; |
|
502 |
QTest::newRow("int-string") << qVariantFromValue(ms) << "(is)" << "[Argument: (is) 1, \"Hello, World\"]"; |
|
503 |
||
504 |
MyVariantMapStruct mvms = { "Hello, World", QVariantMap() }; |
|
505 |
QTest::newRow("string-variantmap") << qVariantFromValue(mvms) << "(sa{sv})" << "[Argument: (sa{sv}) \"Hello, World\", [Argument: a{sv} {}]]"; |
|
506 |
||
507 |
// use only basic types, otherwise comparison will fail |
|
508 |
mvms.map["int"] = 42; |
|
509 |
mvms.map["uint"] = 42u; |
|
510 |
mvms.map["short"] = qVariantFromValue<short>(-47); |
|
511 |
mvms.map["bytearray"] = QByteArray("Hello, world"); |
|
512 |
QTest::newRow("string-variantmap2") << qVariantFromValue(mvms) << "(sa{sv})" << "[Argument: (sa{sv}) \"Hello, World\", [Argument: a{sv} {\"bytearray\" = [Variant(QByteArray): {72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100}], \"int\" = [Variant(int): 42], \"short\" = [Variant(short): -47], \"uint\" = [Variant(uint): 42]}]]"; |
|
513 |
||
514 |
QList<MyVariantMapStruct> list; |
|
515 |
QTest::newRow("empty-list-of-string-variantmap") << qVariantFromValue(list) << "a(sa{sv})" << "[Argument: a(sa{sv}) {}]"; |
|
516 |
list << mvms; |
|
517 |
QTest::newRow("list-of-string-variantmap") << qVariantFromValue(list) << "a(sa{sv})" << "[Argument: a(sa{sv}) {[Argument: (sa{sv}) \"Hello, World\", [Argument: a{sv} {\"bytearray\" = [Variant(QByteArray): {72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100}], \"int\" = [Variant(int): 42], \"short\" = [Variant(short): -47], \"uint\" = [Variant(uint): 42]}]]}]"; |
|
518 |
} |
|
519 |
||
520 |
void tst_QDBusMarshall::sendComplex_data() |
|
521 |
{ |
|
522 |
QTest::addColumn<QVariant>("value"); |
|
523 |
QTest::addColumn<QString>("sig"); |
|
524 |
QTest::addColumn<QString>("stringResult"); |
|
525 |
||
526 |
QList<QDateTime> dtlist; |
|
527 |
QTest::newRow("empty-datetimelist") << qVariantFromValue(dtlist) << "a((iii)(iiii)i)" |
|
528 |
<< "[Argument: a((iii)(iiii)i) {}]"; |
|
529 |
dtlist << QDateTime(); |
|
530 |
QTest::newRow("list-of-emptydatetime") << qVariantFromValue(dtlist) << "a((iii)(iiii)i)" |
|
531 |
<< "[Argument: a((iii)(iiii)i) {[Argument: ((iii)(iiii)i) [Argument: (iii) 0, 0, 0], [Argument: (iiii) -1, -1, -1, -1], 0]}]"; |
|
532 |
dtlist << QDateTime(QDate(1977, 9, 13), QTime(0, 0, 0)) |
|
533 |
<< QDateTime(QDate(2006, 6, 18), QTime(13, 14, 0)); |
|
534 |
QTest::newRow("datetimelist") << qVariantFromValue(dtlist) << "a((iii)(iiii)i)" |
|
535 |
<< "[Argument: a((iii)(iiii)i) {[Argument: ((iii)(iiii)i) [Argument: (iii) 0, 0, 0], [Argument: (iiii) -1, -1, -1, -1], 0], [Argument: ((iii)(iiii)i) [Argument: (iii) 1977, 9, 13], [Argument: (iiii) 0, 0, 0, 0], 0], [Argument: ((iii)(iiii)i) [Argument: (iii) 2006, 6, 18], [Argument: (iiii) 13, 14, 0, 0], 0]}]"; |
|
536 |
||
537 |
QHash<qlonglong, QDateTime> lldtmap; |
|
538 |
QTest::newRow("empty-lldtmap") << qVariantFromValue(lldtmap) << "a{x((iii)(iiii)i)}" |
|
539 |
<< "[Argument: a{x((iii)(iiii)i)} {}]"; |
|
540 |
lldtmap[0] = QDateTime(); |
|
541 |
lldtmap[1] = QDateTime(QDate(1970, 1, 1), QTime(0, 0, 1), Qt::UTC); |
|
542 |
lldtmap[1150629776] = QDateTime(QDate(2006, 6, 18), QTime(11, 22, 56), Qt::UTC); |
|
543 |
QTest::newRow("lldtmap") << qVariantFromValue(lldtmap) << "a{x((iii)(iiii)i)}" |
|
544 |
<< "[Argument: a{x((iii)(iiii)i)} {0 = [Argument: ((iii)(iiii)i) [Argument: (iii) 0, 0, 0], [Argument: (iiii) -1, -1, -1, -1], 0], 1 = [Argument: ((iii)(iiii)i) [Argument: (iii) 1970, 1, 1], [Argument: (iiii) 0, 0, 1, 0], 1], 1150629776 = [Argument: ((iii)(iiii)i) [Argument: (iii) 2006, 6, 18], [Argument: (iiii) 11, 22, 56, 0], 1]}]"; |
|
545 |
||
546 |
||
547 |
QMap<int, QString> ismap; |
|
548 |
ismap[1] = "a"; |
|
549 |
ismap[2000] = "b"; |
|
550 |
ismap[-47] = "c"; |
|
551 |
||
552 |
QMap<QString, QString> ssmap; |
|
553 |
ssmap["a"] = "a"; |
|
554 |
ssmap["c"] = "b"; |
|
555 |
ssmap["b"] = "c"; |
|
556 |
||
557 |
QHash<QDBusSignature, QString> gsmap; |
|
558 |
gsmap[QDBusSignature("i")] = "int32"; |
|
559 |
gsmap[QDBusSignature("s")] = "string"; |
|
560 |
gsmap[QDBusSignature("a{gs}")] = "array of dict_entry of (signature, string)"; |
|
561 |
||
562 |
QVariantMap svmap; |
|
563 |
svmap["a"] = 1; |
|
564 |
svmap["c"] = "b"; |
|
565 |
svmap["b"] = QByteArray("c"); |
|
566 |
svmap["d"] = 42U; |
|
567 |
svmap["e"] = qVariantFromValue(short(-47)); |
|
568 |
svmap["f"] = qVariantFromValue(QDBusVariant(0)); |
|
569 |
svmap["date"] = QDate(1977, 1, 1); |
|
570 |
svmap["time"] = QTime(8, 58, 0); |
|
571 |
svmap["datetime"] = QDateTime(QDate(13, 9, 2008), QTime(8, 59, 31)); |
|
572 |
svmap["pointf"] = QPointF(0.5, -0.5); |
|
573 |
svmap["ismap"] = qVariantFromValue(ismap); |
|
574 |
svmap["ssmap"] = qVariantFromValue(ssmap); |
|
575 |
svmap["gsmap"] = qVariantFromValue(gsmap); |
|
576 |
svmap["dtlist"] = qVariantFromValue(dtlist); |
|
577 |
svmap["lldtmap"] = qVariantFromValue(lldtmap); |
|
578 |
QTest::newRow("sv-map") << qVariantFromValue(svmap) << "a{sv}" |
|
579 |
<< "[Argument: a{sv} {\"a\" = [Variant(int): 1], \"b\" = [Variant(QByteArray): {99}], \"c\" = [Variant(QString): \"b\"], \"d\" = [Variant(uint): 42], \"date\" = [Variant: [Argument: (iii) 1977, 1, 1]], \"datetime\" = [Variant: [Argument: ((iii)(iiii)i) [Argument: (iii) 0, 0, 0], [Argument: (iiii) 8, 59, 31, 0], 0]], \"dtlist\" = [Variant: [Argument: a((iii)(iiii)i) {[Argument: ((iii)(iiii)i) [Argument: (iii) 0, 0, 0], [Argument: (iiii) -1, -1, -1, -1], 0], [Argument: ((iii)(iiii)i) [Argument: (iii) 1977, 9, 13], [Argument: (iiii) 0, 0, 0, 0], 0], [Argument: ((iii)(iiii)i) [Argument: (iii) 2006, 6, 18], [Argument: (iiii) 13, 14, 0, 0], 0]}]], \"e\" = [Variant(short): -47], \"f\" = [Variant: [Variant(int): 0]], \"gsmap\" = [Variant: [Argument: a{gs} {[Signature: a{gs}] = \"array of dict_entry of (signature, string)\", [Signature: i] = \"int32\", [Signature: s] = \"string\"}]], \"ismap\" = [Variant: [Argument: a{is} {-47 = \"c\", 1 = \"a\", 2000 = \"b\"}]], \"lldtmap\" = [Variant: [Argument: a{x((iii)(iiii)i)} {0 = [Argument: ((iii)(iiii)i) [Argument: (iii) 0, 0, 0], [Argument: (iiii) -1, -1, -1, -1], 0], 1 = [Argument: ((iii)(iiii)i) [Argument: (iii) 1970, 1, 1], [Argument: (iiii) 0, 0, 1, 0], 1], 1150629776 = [Argument: ((iii)(iiii)i) [Argument: (iii) 2006, 6, 18], [Argument: (iiii) 11, 22, 56, 0], 1]}]], \"pointf\" = [Variant: [Argument: (dd) 0.5, -0.5]], \"ssmap\" = [Variant: [Argument: a{ss} {\"a\" = \"a\", \"b\" = \"c\", \"c\" = \"b\"}]], \"time\" = [Variant: [Argument: (iiii) 8, 58, 0, 0]]}]"; |
|
580 |
} |
|
581 |
||
582 |
void tst_QDBusMarshall::sendArgument_data() |
|
583 |
{ |
|
584 |
QTest::addColumn<QVariant>("value"); |
|
585 |
QTest::addColumn<QString>("sig"); |
|
586 |
QTest::addColumn<int>("classification"); |
|
587 |
||
588 |
QDBusArgument(); |
|
589 |
QDBusArgument arg; |
|
590 |
||
591 |
arg = QDBusArgument(); |
|
592 |
arg << true; |
|
593 |
QTest::newRow("bool") << qVariantFromValue(arg) << "b" << int(QDBusArgument::BasicType);; |
|
594 |
||
595 |
arg = QDBusArgument(); |
|
596 |
arg << false; |
|
597 |
QTest::newRow("bool2") << qVariantFromValue(arg) << "b" << int(QDBusArgument::BasicType); |
|
598 |
||
599 |
arg = QDBusArgument(); |
|
600 |
arg << uchar(1); |
|
601 |
QTest::newRow("byte") << qVariantFromValue(arg) << "y" << int(QDBusArgument::BasicType); |
|
602 |
||
603 |
arg = QDBusArgument(); |
|
604 |
arg << short(2); |
|
605 |
QTest::newRow("int16") << qVariantFromValue(arg) << "n" << int(QDBusArgument::BasicType); |
|
606 |
||
607 |
arg = QDBusArgument(); |
|
608 |
arg << ushort(3); |
|
609 |
QTest::newRow("uint16") << qVariantFromValue(arg) << "q" << int(QDBusArgument::BasicType); |
|
610 |
||
611 |
arg = QDBusArgument(); |
|
612 |
arg << 1; |
|
613 |
QTest::newRow("int32") << qVariantFromValue(arg) << "i" << int(QDBusArgument::BasicType); |
|
614 |
||
615 |
arg = QDBusArgument(); |
|
616 |
arg << 2U; |
|
617 |
QTest::newRow("uint32") << qVariantFromValue(arg) << "u" << int(QDBusArgument::BasicType); |
|
618 |
||
619 |
arg = QDBusArgument(); |
|
620 |
arg << Q_INT64_C(3); |
|
621 |
QTest::newRow("int64") << qVariantFromValue(arg) << "x" << int(QDBusArgument::BasicType); |
|
622 |
||
623 |
arg = QDBusArgument(); |
|
624 |
arg << Q_UINT64_C(4); |
|
625 |
QTest::newRow("uint64") << qVariantFromValue(arg) << "t" << int(QDBusArgument::BasicType); |
|
626 |
||
627 |
arg = QDBusArgument(); |
|
628 |
arg << 42.5; |
|
629 |
QTest::newRow("double") << qVariantFromValue(arg) << "d" << int(QDBusArgument::BasicType); |
|
630 |
||
631 |
arg = QDBusArgument(); |
|
632 |
arg << QLatin1String("ping"); |
|
633 |
QTest::newRow("string") << qVariantFromValue(arg) << "s" << int(QDBusArgument::BasicType); |
|
634 |
||
635 |
arg = QDBusArgument(); |
|
636 |
arg << QDBusObjectPath("/org/kde"); |
|
637 |
QTest::newRow("objectpath") << qVariantFromValue(arg) << "o" << int(QDBusArgument::BasicType); |
|
638 |
||
639 |
arg = QDBusArgument(); |
|
640 |
arg << QDBusSignature("g"); |
|
641 |
QTest::newRow("signature") << qVariantFromValue(arg) << "g" << int(QDBusArgument::BasicType); |
|
642 |
||
643 |
arg = QDBusArgument(); |
|
644 |
arg << QLatin1String(""); |
|
645 |
QTest::newRow("emptystring") << qVariantFromValue(arg) << "s" << int(QDBusArgument::BasicType); |
|
646 |
||
647 |
arg = QDBusArgument(); |
|
648 |
arg << QString(); |
|
649 |
QTest::newRow("nullstring") << qVariantFromValue(arg) << "s" << int(QDBusArgument::BasicType); |
|
650 |
||
651 |
arg = QDBusArgument(); |
|
652 |
arg << QDBusVariant(1); |
|
653 |
QTest::newRow("variant") << qVariantFromValue(arg) << "v" << int(QDBusArgument::VariantType); |
|
654 |
||
655 |
arg = QDBusArgument(); |
|
656 |
arg << QDBusVariant(qVariantFromValue(QDBusVariant(1))); |
|
657 |
QTest::newRow("variant-variant") << qVariantFromValue(arg) << "v" << int(QDBusArgument::VariantType); |
|
658 |
||
659 |
arg = QDBusArgument(); |
|
660 |
arg.beginArray(QVariant::Int); |
|
661 |
arg << 1 << 2 << 3 << -4; |
|
662 |
arg.endArray(); |
|
663 |
QTest::newRow("array-of-int") << qVariantFromValue(arg) << "ai" << int(QDBusArgument::ArrayType); |
|
664 |
||
665 |
arg = QDBusArgument(); |
|
666 |
arg.beginMap(QVariant::Int, QVariant::UInt); |
|
667 |
arg.beginMapEntry(); |
|
668 |
arg << 1 << 2U; |
|
669 |
arg.endMapEntry(); |
|
670 |
arg.beginMapEntry(); |
|
671 |
arg << 3 << 4U; |
|
672 |
arg.endMapEntry(); |
|
673 |
arg.endMap(); |
|
674 |
QTest::newRow("map") << qVariantFromValue(arg) << "a{iu}" << int(QDBusArgument::MapType); |
|
675 |
||
676 |
arg = QDBusArgument(); |
|
677 |
arg.beginStructure(); |
|
678 |
arg << 1 << 2U << short(-3) << ushort(4) << 5.0 << false; |
|
679 |
arg.endStructure(); |
|
680 |
QTest::newRow("structure") << qVariantFromValue(arg) << "(iunqdb)" << int(QDBusArgument::StructureType); |
|
681 |
||
682 |
#if 0 |
|
683 |
// this is now unsupported |
|
684 |
arg << 1 << 2U << short(-3) << ushort(4) << 5.0 << false; |
|
685 |
QTest::newRow("many-args") << qVariantFromValue(arg) << "(iunqdb)iunqdb"; |
|
686 |
#endif |
|
687 |
} |
|
688 |
||
689 |
void tst_QDBusMarshall::sendBasic() |
|
690 |
{ |
|
691 |
QFETCH(QVariant, value); |
|
692 |
QFETCH(QString, stringResult); |
|
693 |
||
694 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
695 |
||
696 |
QVERIFY(con.isConnected()); |
|
697 |
||
698 |
QDBusMessage msg = QDBusMessage::createMethodCall(serviceName, |
|
699 |
objectPath, interfaceName, "ping"); |
|
700 |
msg << value; |
|
701 |
||
702 |
QDBusMessage reply = con.call(msg); |
|
703 |
//qDebug() << reply; |
|
704 |
||
705 |
QCOMPARE(reply.arguments().count(), msg.arguments().count()); |
|
706 |
QTEST(reply.signature(), "sig"); |
|
707 |
for (int i = 0; i < reply.arguments().count(); ++i) { |
|
708 |
QVERIFY(compare(reply.arguments().at(i), msg.arguments().at(i))); |
|
709 |
//printf("\n! %s\n* %s\n", qPrintable(qDBusArgumentToString(reply.arguments().at(i))), qPrintable(stringResult)); |
|
710 |
QCOMPARE(QDBusUtil::argumentToString(reply.arguments().at(i)), stringResult); |
|
711 |
} |
|
712 |
} |
|
713 |
||
714 |
void tst_QDBusMarshall::sendVariant() |
|
715 |
{ |
|
716 |
QFETCH(QVariant, value); |
|
717 |
||
718 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
719 |
||
720 |
QVERIFY(con.isConnected()); |
|
721 |
||
722 |
QDBusMessage msg = QDBusMessage::createMethodCall(serviceName, |
|
723 |
objectPath, interfaceName, "ping"); |
|
724 |
msg << qVariantFromValue(QDBusVariant(value)); |
|
725 |
||
726 |
QDBusMessage reply = con.call(msg); |
|
727 |
// qDebug() << reply; |
|
728 |
||
729 |
QCOMPARE(reply.arguments().count(), msg.arguments().count()); |
|
730 |
QCOMPARE(reply.signature(), QString("v")); |
|
731 |
for (int i = 0; i < reply.arguments().count(); ++i) |
|
732 |
QVERIFY(compare(reply.arguments().at(i), msg.arguments().at(i))); |
|
733 |
} |
|
734 |
||
735 |
void tst_QDBusMarshall::sendArrays() |
|
736 |
{ |
|
737 |
sendBasic(); |
|
738 |
} |
|
739 |
||
740 |
void tst_QDBusMarshall::sendArrayOfArrays() |
|
741 |
{ |
|
742 |
sendBasic(); |
|
743 |
} |
|
744 |
||
745 |
void tst_QDBusMarshall::sendMaps() |
|
746 |
{ |
|
747 |
sendBasic(); |
|
748 |
} |
|
749 |
||
750 |
void tst_QDBusMarshall::sendStructs() |
|
751 |
{ |
|
752 |
sendBasic(); |
|
753 |
} |
|
754 |
||
755 |
void tst_QDBusMarshall::sendComplex() |
|
756 |
{ |
|
757 |
sendBasic(); |
|
758 |
} |
|
759 |
||
760 |
void tst_QDBusMarshall::sendArgument() |
|
761 |
{ |
|
762 |
QFETCH(QVariant, value); |
|
763 |
QFETCH(QString, sig); |
|
764 |
||
765 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
766 |
||
767 |
QVERIFY(con.isConnected()); |
|
768 |
||
769 |
QDBusMessage msg = QDBusMessage::createMethodCall(serviceName, objectPath, |
|
770 |
interfaceName, "ping"); |
|
771 |
msg << value; |
|
772 |
||
773 |
QDBusMessage reply = con.call(msg); |
|
774 |
||
775 |
// QCOMPARE(reply.arguments().count(), msg.arguments().count()); |
|
776 |
QCOMPARE(reply.signature(), sig); |
|
777 |
// for (int i = 0; i < reply.arguments().count(); ++i) |
|
778 |
// QVERIFY(compare(reply.arguments().at(i), msg.arguments().at(i))); |
|
779 |
||
780 |
// do it again inside a STRUCT now |
|
781 |
QDBusArgument sendArg; |
|
782 |
sendArg.beginStructure(); |
|
783 |
sendArg.appendVariant(value); |
|
784 |
sendArg.endStructure(); |
|
785 |
msg.setArguments(QVariantList() << qVariantFromValue(sendArg)); |
|
786 |
reply = con.call(msg); |
|
787 |
||
788 |
QCOMPARE(reply.signature(), QString("(%1)").arg(sig)); |
|
789 |
QCOMPARE(reply.arguments().at(0).userType(), qMetaTypeId<QDBusArgument>()); |
|
790 |
||
791 |
const QDBusArgument arg = qvariant_cast<QDBusArgument>(reply.arguments().at(0)); |
|
792 |
QCOMPARE(int(arg.currentType()), int(QDBusArgument::StructureType)); |
|
793 |
||
794 |
arg.beginStructure(); |
|
795 |
QVERIFY(!arg.atEnd()); |
|
796 |
QCOMPARE(arg.currentSignature(), sig); |
|
797 |
QTEST(int(arg.currentType()), "classification"); |
|
798 |
||
799 |
QVariant extracted = arg.asVariant(); |
|
800 |
QVERIFY(arg.atEnd()); |
|
801 |
||
802 |
arg.endStructure(); |
|
803 |
QVERIFY(arg.atEnd()); |
|
804 |
QCOMPARE(arg.currentType(), QDBusArgument::UnknownType); |
|
805 |
||
806 |
if (value.type() != QVariant::UserType) |
|
807 |
QCOMPARE(extracted, value); |
|
808 |
} |
|
809 |
||
810 |
void tst_QDBusMarshall::sendSignalErrors() |
|
811 |
{ |
|
812 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
813 |
||
814 |
QVERIFY(con.isConnected()); |
|
815 |
QDBusMessage msg = QDBusMessage::createSignal("/foo", "local.interfaceName", |
|
816 |
"signalName"); |
|
817 |
msg << qVariantFromValue(QDBusObjectPath()); |
|
818 |
||
819 |
QTest::ignoreMessage(QtWarningMsg, "QDBusConnection: error: could not send signal path \"/foo\" interface \"local.interfaceName\" member \"signalName\": Marshalling failed: Invalid object path passed in arguments"); |
|
820 |
QVERIFY(!con.send(msg)); |
|
821 |
||
822 |
msg.setArguments(QVariantList()); |
|
823 |
QDBusObjectPath path; |
|
824 |
||
825 |
QTest::ignoreMessage(QtWarningMsg, "QDBusObjectPath: invalid path \"abc\""); |
|
826 |
path.setPath("abc"); |
|
827 |
msg << qVariantFromValue(path); |
|
828 |
||
829 |
QTest::ignoreMessage(QtWarningMsg, "QDBusConnection: error: could not send signal path \"/foo\" interface \"local.interfaceName\" member \"signalName\": Marshalling failed: Invalid object path passed in arguments"); |
|
830 |
QVERIFY(!con.send(msg)); |
|
831 |
||
832 |
QDBusSignature sig; |
|
833 |
msg.setArguments(QVariantList() << qVariantFromValue(sig)); |
|
834 |
QTest::ignoreMessage(QtWarningMsg, "QDBusConnection: error: could not send signal path \"/foo\" interface \"local.interfaceName\" member \"signalName\": Marshalling failed: Invalid signature passed in arguments"); |
|
835 |
QVERIFY(!con.send(msg)); |
|
836 |
||
837 |
QTest::ignoreMessage(QtWarningMsg, "QDBusSignature: invalid signature \"a\""); |
|
838 |
sig.setSignature("a"); |
|
839 |
msg.setArguments(QVariantList()); |
|
840 |
msg << qVariantFromValue(sig); |
|
841 |
QTest::ignoreMessage(QtWarningMsg, "QDBusConnection: error: could not send signal path \"/foo\" interface \"local.interfaceName\" member \"signalName\": Marshalling failed: Invalid signature passed in arguments"); |
|
842 |
QVERIFY(!con.send(msg)); |
|
843 |
} |
|
844 |
||
845 |
void tst_QDBusMarshall::sendCallErrors_data() |
|
846 |
{ |
|
847 |
QTest::addColumn<QString>("service"); |
|
848 |
QTest::addColumn<QString>("path"); |
|
849 |
QTest::addColumn<QString>("interface"); |
|
850 |
QTest::addColumn<QString>("method"); |
|
851 |
QTest::addColumn<QVariantList>("arguments"); |
|
852 |
QTest::addColumn<QString>("errorName"); |
|
853 |
QTest::addColumn<QString>("errorMsg"); |
|
854 |
QTest::addColumn<QString>("ignoreMsg"); |
|
855 |
||
856 |
// this error comes from the bus server |
|
857 |
QTest::newRow("empty-service") << "" << objectPath << interfaceName << "ping" << QVariantList() |
|
858 |
<< "org.freedesktop.DBus.Error.UnknownMethod" |
|
859 |
<< "Method \"ping\" with signature \"\" on interface \"com.trolltech.autotests.qpong\" doesn't exist\n" << (const char*)0; |
|
860 |
||
861 |
QTest::newRow("invalid-service") << "this isn't valid" << objectPath << interfaceName << "ping" << QVariantList() |
|
862 |
<< "com.trolltech.QtDBus.Error.InvalidService" |
|
863 |
<< "Invalid service name: this isn't valid" << ""; |
|
864 |
||
865 |
QTest::newRow("empty-path") << serviceName << "" << interfaceName << "ping" << QVariantList() |
|
866 |
<< "com.trolltech.QtDBus.Error.InvalidObjectPath" |
|
867 |
<< "Object path cannot be empty" << ""; |
|
868 |
QTest::newRow("invalid-path") << serviceName << "//" << interfaceName << "ping" << QVariantList() |
|
869 |
<< "com.trolltech.QtDBus.Error.InvalidObjectPath" |
|
870 |
<< "Invalid object path: //" << ""; |
|
871 |
||
872 |
// empty interfaces are valid |
|
873 |
QTest::newRow("invalid-interface") << serviceName << objectPath << "this isn't valid" << "ping" << QVariantList() |
|
874 |
<< "com.trolltech.QtDBus.Error.InvalidInterface" |
|
875 |
<< "Invalid interface class: this isn't valid" << ""; |
|
876 |
||
877 |
QTest::newRow("empty-method") << serviceName << objectPath << interfaceName << "" << QVariantList() |
|
878 |
<< "com.trolltech.QtDBus.Error.InvalidMember" |
|
879 |
<< "method name cannot be empty" << ""; |
|
880 |
QTest::newRow("invalid-method") << serviceName << objectPath << interfaceName << "this isn't valid" << QVariantList() |
|
881 |
<< "com.trolltech.QtDBus.Error.InvalidMember" |
|
882 |
<< "Invalid method name: this isn't valid" << ""; |
|
883 |
||
884 |
QTest::newRow("invalid-variant1") << serviceName << objectPath << interfaceName << "ping" |
|
885 |
<< (QVariantList() << QVariant()) |
|
886 |
<< "org.freedesktop.DBus.Error.Failed" |
|
887 |
<< "Marshalling failed: Variant containing QVariant::Invalid passed in arguments" |
|
888 |
<< "QDBusMarshaller: cannot add an invalid QVariant"; |
|
889 |
QTest::newRow("invalid-variant1") << serviceName << objectPath << interfaceName << "ping" |
|
890 |
<< (QVariantList() << qVariantFromValue(QDBusVariant())) |
|
891 |
<< "org.freedesktop.DBus.Error.Failed" |
|
892 |
<< "Marshalling failed: Variant containing QVariant::Invalid passed in arguments" |
|
893 |
<< "QDBusMarshaller: cannot add a null QDBusVariant"; |
|
894 |
||
895 |
QTest::newRow("builtin-unregistered") << serviceName << objectPath << interfaceName << "ping" |
|
896 |
<< (QVariantList() << QLocale::c()) |
|
897 |
<< "org.freedesktop.DBus.Error.Failed" |
|
898 |
<< "Marshalling failed: Unregistered type QLocale passed in arguments" |
|
899 |
<< "QDBusMarshaller: type `QLocale' (18) is not registered with D-BUS. Use qDBusRegisterMetaType to register it"; |
|
900 |
||
901 |
// this type is known to the meta type system, but not registered with D-Bus |
|
902 |
qRegisterMetaType<UnregisteredType>(); |
|
903 |
QTest::newRow("extra-unregistered") << serviceName << objectPath << interfaceName << "ping" |
|
904 |
<< (QVariantList() << qVariantFromValue(UnregisteredType())) |
|
905 |
<< "org.freedesktop.DBus.Error.Failed" |
|
906 |
<< "Marshalling failed: Unregistered type UnregisteredType passed in arguments" |
|
907 |
<< QString("QDBusMarshaller: type `UnregisteredType' (%1) is not registered with D-BUS. Use qDBusRegisterMetaType to register it") |
|
908 |
.arg(qMetaTypeId<UnregisteredType>()); |
|
909 |
} |
|
910 |
||
911 |
void tst_QDBusMarshall::sendCallErrors() |
|
912 |
{ |
|
913 |
QDBusConnection con = QDBusConnection::sessionBus(); |
|
914 |
QVERIFY(con.isConnected()); |
|
915 |
||
916 |
QFETCH(QString, service); |
|
917 |
QFETCH(QString, path); |
|
918 |
QFETCH(QString, interface); |
|
919 |
QFETCH(QString, method); |
|
920 |
QFETCH(QVariantList, arguments); |
|
921 |
QFETCH(QString, errorMsg); |
|
922 |
||
923 |
QFETCH(QString, ignoreMsg); |
|
924 |
if (!ignoreMsg.isEmpty()) |
|
925 |
QTest::ignoreMessage(QtWarningMsg, ignoreMsg.toLatin1()); |
|
926 |
if (!ignoreMsg.isNull()) |
|
927 |
QTest::ignoreMessage(QtWarningMsg, |
|
928 |
QString("QDBusConnection: error: could not send message to service \"%1\" path \"%2\" interface \"%3\" member \"%4\": %5") |
|
929 |
.arg(service, path, interface, method, errorMsg) |
|
930 |
.toLatin1()); |
|
931 |
||
932 |
QDBusMessage msg = QDBusMessage::createMethodCall(service, path, interface, method); |
|
933 |
msg.setArguments(arguments); |
|
934 |
||
935 |
QDBusMessage reply = con.call(msg, QDBus::Block); |
|
936 |
QCOMPARE(reply.type(), QDBusMessage::ErrorMessage); |
|
937 |
QTEST(reply.errorName(), "errorName"); |
|
938 |
QCOMPARE(reply.errorMessage(), errorMsg); |
|
939 |
} |
|
940 |
||
941 |
QTEST_MAIN(tst_QDBusMarshall) |
|
942 |
#include "tst_qdbusmarshall.moc" |