1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the test suite of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | #include <qcoreapplication.h> |
29 | #include <qmetatype.h> |
30 | #include <QtTest/QtTest> |
31 | |
32 | #include <QtDBus/QtDBus> |
33 | #include <private/qdbusmetaobject_p.h> |
34 | |
35 | class tst_QDBusMetaObject: public QObject |
36 | { |
37 | Q_OBJECT |
38 | |
39 | QHash<QString, QDBusMetaObject *> map; |
40 | public slots: |
41 | void init(); |
42 | |
43 | private slots: |
44 | void initTestCase(); |
45 | void types_data(); |
46 | void types(); |
47 | void methods_data(); |
48 | void methods(); |
49 | void _signals_data(); |
50 | void _signals(); |
51 | void properties_data(); |
52 | void properties(); |
53 | }; |
54 | |
55 | typedef QPair<QString,QString> StringPair; |
56 | |
57 | struct Struct1 { }; // (s) |
58 | struct Struct4 // (ssa(ss)sayasx) |
59 | { |
60 | QString m1; |
61 | QString m2; |
62 | QList<StringPair> m3; |
63 | QString m4; |
64 | QByteArray m5; |
65 | QStringList m6; |
66 | qlonglong m7; |
67 | }; |
68 | |
69 | Q_DECLARE_METATYPE(Struct1) |
70 | Q_DECLARE_METATYPE(Struct4) |
71 | Q_DECLARE_METATYPE(StringPair) |
72 | |
73 | Q_DECLARE_METATYPE(const QMetaObject*) |
74 | |
75 | QT_BEGIN_NAMESPACE |
76 | QDBusArgument &operator<<(QDBusArgument &arg, const Struct1 &) |
77 | { |
78 | arg.beginStructure(); |
79 | arg << QString(); |
80 | arg.endStructure(); |
81 | return arg; |
82 | } |
83 | |
84 | QDBusArgument &operator<<(QDBusArgument &arg, const StringPair &s) |
85 | { |
86 | arg.beginStructure(); |
87 | arg << s.first << s.second; |
88 | arg.endStructure(); |
89 | return arg; |
90 | } |
91 | |
92 | QDBusArgument &operator<<(QDBusArgument &arg, const Struct4 &s) |
93 | { |
94 | arg.beginStructure(); |
95 | arg << s.m1 << s.m2 << s.m3 << s.m4 << s.m5 << s.m6 << s.m7; |
96 | arg.endStructure(); |
97 | return arg; |
98 | } |
99 | |
100 | const QDBusArgument &operator>>(const QDBusArgument &arg, Struct1 &) |
101 | { return arg; } |
102 | const QDBusArgument &operator>>(const QDBusArgument &arg, Struct4 &) |
103 | { return arg; } |
104 | const QDBusArgument &operator>>(const QDBusArgument &arg, StringPair &) |
105 | { return arg; } |
106 | QT_END_NAMESPACE |
107 | |
108 | void tst_QDBusMetaObject::initTestCase() |
109 | { |
110 | qDBusRegisterMetaType<Struct1>(); |
111 | qDBusRegisterMetaType<Struct4>(); |
112 | qDBusRegisterMetaType<StringPair>(); |
113 | |
114 | qDBusRegisterMetaType<QList<Struct1> >(); |
115 | qDBusRegisterMetaType<QList<Struct4> >(); |
116 | } |
117 | |
118 | void tst_QDBusMetaObject::init() |
119 | { |
120 | qDeleteAll(c: map); |
121 | map.clear(); |
122 | } |
123 | |
124 | // test classes |
125 | class TypesTest1: public QObject |
126 | { |
127 | Q_OBJECT |
128 | |
129 | signals: |
130 | void signal(uchar); |
131 | }; |
132 | const char TypesTest1_xml[] = |
133 | "<signal name=\"signal\"><arg type=\"y\"/></signal>" ; |
134 | |
135 | class TypesTest2: public QObject |
136 | { |
137 | Q_OBJECT |
138 | |
139 | signals: |
140 | void signal(bool); |
141 | }; |
142 | const char TypesTest2_xml[] = |
143 | "<signal name=\"signal\"><arg type=\"b\"/></signal>" ; |
144 | |
145 | class TypesTest3: public QObject |
146 | { |
147 | Q_OBJECT |
148 | |
149 | signals: |
150 | void signal(short); |
151 | }; |
152 | const char TypesTest3_xml[] = |
153 | "<signal name=\"signal\"><arg type=\"n\"/></signal>" ; |
154 | |
155 | class TypesTest4: public QObject |
156 | { |
157 | Q_OBJECT |
158 | |
159 | signals: |
160 | void signal(ushort); |
161 | }; |
162 | const char TypesTest4_xml[] = |
163 | "<signal name=\"signal\"><arg type=\"q\"/></signal>" ; |
164 | |
165 | class TypesTest5: public QObject |
166 | { |
167 | Q_OBJECT |
168 | |
169 | signals: |
170 | void signal(int); |
171 | }; |
172 | const char TypesTest5_xml[] = |
173 | "<signal name=\"signal\"><arg type=\"i\"/></signal>" ; |
174 | |
175 | class TypesTest6: public QObject |
176 | { |
177 | Q_OBJECT |
178 | |
179 | signals: |
180 | void signal(uint); |
181 | }; |
182 | const char TypesTest6_xml[] = |
183 | "<signal name=\"signal\"><arg type=\"u\"/></signal>" ; |
184 | |
185 | class TypesTest7: public QObject |
186 | { |
187 | Q_OBJECT |
188 | |
189 | signals: |
190 | void signal(qlonglong); |
191 | }; |
192 | const char TypesTest7_xml[] = |
193 | "<signal name=\"signal\"><arg type=\"x\"/></signal>" ; |
194 | |
195 | class TypesTest8: public QObject |
196 | { |
197 | Q_OBJECT |
198 | |
199 | signals: |
200 | void signal(qulonglong); |
201 | }; |
202 | const char TypesTest8_xml[] = |
203 | "<signal name=\"signal\"><arg type=\"t\"/></signal>" ; |
204 | |
205 | class TypesTest9: public QObject |
206 | { |
207 | Q_OBJECT |
208 | |
209 | signals: |
210 | void signal(double); |
211 | }; |
212 | const char TypesTest9_xml[] = |
213 | "<signal name=\"signal\"><arg type=\"d\"/></signal>" ; |
214 | |
215 | class TypesTest10: public QObject |
216 | { |
217 | Q_OBJECT |
218 | |
219 | signals: |
220 | void signal(QString); |
221 | }; |
222 | const char TypesTest10_xml[] = |
223 | "<signal name=\"signal\"><arg type=\"s\"/></signal>" ; |
224 | |
225 | class TypesTest11: public QObject |
226 | { |
227 | Q_OBJECT |
228 | |
229 | signals: |
230 | void signal(QDBusObjectPath); |
231 | }; |
232 | const char TypesTest11_xml[] = |
233 | "<signal name=\"signal\"><arg type=\"o\"/></signal>" ; |
234 | |
235 | class TypesTest12: public QObject |
236 | { |
237 | Q_OBJECT |
238 | |
239 | signals: |
240 | void signal(QDBusSignature); |
241 | }; |
242 | const char TypesTest12_xml[] = |
243 | "<signal name=\"signal\"><arg type=\"g\"/></signal>" ; |
244 | |
245 | class TypesTest13: public QObject |
246 | { |
247 | Q_OBJECT |
248 | |
249 | signals: |
250 | void signal(QDBusVariant); |
251 | }; |
252 | const char TypesTest13_xml[] = |
253 | "<signal name=\"signal\"><arg type=\"v\"/></signal>" ; |
254 | |
255 | class TypesTest14: public QObject |
256 | { |
257 | Q_OBJECT |
258 | |
259 | signals: |
260 | void signal(QStringList); |
261 | }; |
262 | const char TypesTest14_xml[] = |
263 | "<signal name=\"signal\"><arg type=\"as\"/></signal>" ; |
264 | |
265 | class TypesTest15: public QObject |
266 | { |
267 | Q_OBJECT |
268 | |
269 | signals: |
270 | void signal(QByteArray); |
271 | }; |
272 | const char TypesTest15_xml[] = |
273 | "<signal name=\"signal\"><arg type=\"ay\"/></signal>" ; |
274 | |
275 | class TypesTest16: public QObject |
276 | { |
277 | Q_OBJECT |
278 | |
279 | signals: |
280 | void signal(StringPair); |
281 | }; |
282 | const char TypesTest16_xml[] = |
283 | "<signal name=\"signal\"><arg type=\"(ss)\"/>" |
284 | "<annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"StringPair\"></signal>" ; |
285 | |
286 | class TypesTest17: public QObject |
287 | { |
288 | Q_OBJECT |
289 | |
290 | signals: |
291 | void signal(Struct1); |
292 | }; |
293 | const char TypesTest17_xml[] = |
294 | "<signal name=\"signal\"><arg type=\"(s)\"/>" |
295 | "<annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"Struct1\"></signal>" ; |
296 | |
297 | class TypesTest18: public QObject |
298 | { |
299 | Q_OBJECT |
300 | |
301 | signals: |
302 | void signal(Struct4); |
303 | }; |
304 | const char TypesTest18_xml[] = |
305 | "<signal name=\"signal\"><arg type=\"(ssa(ss)sayasx)\"/>" |
306 | "<annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"Struct4\"></signal>" ; |
307 | |
308 | class TypesTest19: public QObject |
309 | { |
310 | Q_OBJECT |
311 | |
312 | signals: |
313 | void signal(QVariantList); |
314 | }; |
315 | const char TypesTest19_xml[] = |
316 | "<signal name=\"signal\"><arg type=\"av\"/>" |
317 | "<annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"QVariantList\"></signal>" ; |
318 | |
319 | class TypesTest20: public QObject |
320 | { |
321 | Q_OBJECT |
322 | |
323 | signals: |
324 | void signal(QVariantMap); |
325 | }; |
326 | const char TypesTest20_xml[] = |
327 | "<signal name=\"signal\"><arg type=\"a{sv}\"/>" |
328 | "<annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"QVariantMap\"></signal>" ; |
329 | const char TypesTest20_oldxml[] = |
330 | "<signal name=\"signal\"><arg type=\"a{sv}\"/>" |
331 | "<annotation name=\"com.trolltech.QtDBus.QtTypeName.Out0\" value=\"QVariantMap\"></signal>" ; |
332 | |
333 | |
334 | void tst_QDBusMetaObject::types_data() |
335 | { |
336 | QTest::addColumn<const QMetaObject *>(name: "metaobject" ); |
337 | QTest::addColumn<QString>(name: "xml" ); |
338 | |
339 | QTest::newRow(dataTag: "byte" ) << &TypesTest1::staticMetaObject << QString(TypesTest1_xml); |
340 | QTest::newRow(dataTag: "bool" ) << &TypesTest2::staticMetaObject << QString(TypesTest2_xml); |
341 | QTest::newRow(dataTag: "short" ) << &TypesTest3::staticMetaObject << QString(TypesTest3_xml); |
342 | QTest::newRow(dataTag: "ushort" ) << &TypesTest4::staticMetaObject << QString(TypesTest4_xml); |
343 | QTest::newRow(dataTag: "int" ) << &TypesTest5::staticMetaObject << QString(TypesTest5_xml); |
344 | QTest::newRow(dataTag: "uint" ) << &TypesTest6::staticMetaObject << QString(TypesTest6_xml); |
345 | QTest::newRow(dataTag: "qlonglong" ) << &TypesTest7::staticMetaObject << QString(TypesTest7_xml); |
346 | QTest::newRow(dataTag: "qulonglong" ) << &TypesTest8::staticMetaObject << QString(TypesTest8_xml); |
347 | QTest::newRow(dataTag: "double" ) << &TypesTest9::staticMetaObject << QString(TypesTest9_xml); |
348 | QTest::newRow(dataTag: "QString" ) << &TypesTest10::staticMetaObject << QString(TypesTest10_xml); |
349 | QTest::newRow(dataTag: "QDBusObjectPath" ) << &TypesTest11::staticMetaObject << QString(TypesTest11_xml); |
350 | QTest::newRow(dataTag: "QDBusSignature" ) << &TypesTest12::staticMetaObject << QString(TypesTest12_xml); |
351 | QTest::newRow(dataTag: "QDBusVariant" ) << &TypesTest13::staticMetaObject << QString(TypesTest13_xml); |
352 | QTest::newRow(dataTag: "QStringList" ) << &TypesTest14::staticMetaObject << QString(TypesTest14_xml); |
353 | QTest::newRow(dataTag: "QByteArray" ) << &TypesTest15::staticMetaObject << QString(TypesTest15_xml); |
354 | QTest::newRow(dataTag: "StringPair" ) << &TypesTest16::staticMetaObject << QString(TypesTest16_xml); |
355 | QTest::newRow(dataTag: "Struct1" ) << &TypesTest17::staticMetaObject << QString(TypesTest17_xml); |
356 | QTest::newRow(dataTag: "Struct4" ) << &TypesTest18::staticMetaObject << QString(TypesTest18_xml); |
357 | QTest::newRow(dataTag: "QVariantList" ) << &TypesTest19::staticMetaObject << QString(TypesTest19_xml); |
358 | QTest::newRow(dataTag: "QVariantMap" ) << &TypesTest20::staticMetaObject << QString(TypesTest20_xml); |
359 | QTest::newRow(dataTag: "QVariantMap-oldannotation" ) << &TypesTest20::staticMetaObject << QString(TypesTest20_oldxml); |
360 | } |
361 | |
362 | void tst_QDBusMetaObject::types() |
363 | { |
364 | QFETCH(const QMetaObject*, metaobject); |
365 | QFETCH(QString, xml); |
366 | |
367 | // add the rest of the XML tags |
368 | xml = QString("<node><interface name=\"local.Interface\">%1</interface></node>" ) |
369 | .arg(a: xml); |
370 | |
371 | QDBusError error; |
372 | |
373 | const QScopedPointer<QDBusMetaObject> result(QDBusMetaObject::createMetaObject(interface: "local.Interface" , xml, map, error)); |
374 | QVERIFY2(result, qPrintable(error.message())); |
375 | |
376 | QCOMPARE(result->enumeratorCount(), 0); |
377 | QCOMPARE(result->classInfoCount(), 0); |
378 | |
379 | // compare the meta objects |
380 | QCOMPARE(result->methodCount() - result->methodOffset(), |
381 | metaobject->methodCount() - metaobject->methodOffset()); |
382 | QCOMPARE(result->propertyCount() - result->propertyOffset(), |
383 | metaobject->propertyCount() - metaobject->propertyOffset()); |
384 | |
385 | for (int i = metaobject->methodOffset(); i < metaobject->methodCount(); ++i) { |
386 | QMetaMethod expected = metaobject->method(index: i); |
387 | |
388 | int methodIdx = result->indexOfMethod(method: expected.methodSignature().constData()); |
389 | QVERIFY(methodIdx != -1); |
390 | QMetaMethod constructed = result->method(index: methodIdx); |
391 | |
392 | QCOMPARE(int(constructed.access()), int(expected.access())); |
393 | QCOMPARE(int(constructed.methodType()), int(expected.methodType())); |
394 | QCOMPARE(constructed.name(), expected.name()); |
395 | QCOMPARE(constructed.parameterCount(), expected.parameterCount()); |
396 | QCOMPARE(constructed.parameterNames(), expected.parameterNames()); |
397 | QCOMPARE(constructed.parameterTypes(), expected.parameterTypes()); |
398 | for (int j = 0; j < constructed.parameterCount(); ++j) |
399 | QCOMPARE(constructed.parameterType(j), expected.parameterType(j)); |
400 | QCOMPARE(constructed.tag(), expected.tag()); |
401 | QCOMPARE(constructed.typeName(), expected.typeName()); |
402 | QCOMPARE(constructed.returnType(), expected.returnType()); |
403 | } |
404 | |
405 | for (int i = metaobject->propertyOffset(); i < metaobject->propertyCount(); ++i) { |
406 | QMetaProperty expected = metaobject->property(index: i); |
407 | |
408 | int propIdx = result->indexOfProperty(name: expected.name()); |
409 | QVERIFY(propIdx != -1); |
410 | QMetaProperty constructed = result->property(index: propIdx); |
411 | |
412 | QCOMPARE(constructed.isDesignable(), expected.isDesignable()); |
413 | QCOMPARE(constructed.isEditable(), expected.isEditable()); |
414 | QCOMPARE(constructed.isEnumType(), expected.isEnumType()); |
415 | QCOMPARE(constructed.isFlagType(), expected.isFlagType()); |
416 | QCOMPARE(constructed.isReadable(), expected.isReadable()); |
417 | QCOMPARE(constructed.isResettable(), expected.isResettable()); |
418 | QCOMPARE(constructed.isScriptable(), expected.isScriptable()); |
419 | QCOMPARE(constructed.isStored(), expected.isStored()); |
420 | QCOMPARE(constructed.isUser(), expected.isUser()); |
421 | QCOMPARE(constructed.isWritable(), expected.isWritable()); |
422 | QCOMPARE(constructed.typeName(), expected.typeName()); |
423 | QCOMPARE(constructed.type(), expected.type()); |
424 | QCOMPARE(constructed.userType(), expected.userType()); |
425 | } |
426 | } |
427 | |
428 | class MethodTest1: public QObject |
429 | { |
430 | Q_OBJECT |
431 | |
432 | public slots: |
433 | void method() { } |
434 | }; |
435 | const char MethodTest1_xml[] = |
436 | "<method name=\"method\" />" ; |
437 | |
438 | class MethodTest2: public QObject |
439 | { |
440 | Q_OBJECT |
441 | |
442 | public slots: |
443 | void method(int) { } |
444 | }; |
445 | const char MethodTest2_xml[] = |
446 | "<method name=\"method\"><arg direction=\"in\" type=\"i\"/></method>" ; |
447 | |
448 | class MethodTest3: public QObject |
449 | { |
450 | Q_OBJECT |
451 | |
452 | public slots: |
453 | void method(int input0) { Q_UNUSED(input0); } |
454 | }; |
455 | const char MethodTest3_xml[] = |
456 | "<method name=\"method\"><arg direction=\"in\" type=\"i\" name=\"input0\"/></method>" ; |
457 | |
458 | class MethodTest4: public QObject |
459 | { |
460 | Q_OBJECT |
461 | |
462 | public slots: |
463 | int method() { return 0; } |
464 | }; |
465 | const char MethodTest4_xml[] = |
466 | "<method name=\"method\"><arg direction=\"out\" type=\"i\"/></method>" ; |
467 | const char MethodTest4_xml2[] = |
468 | "<method name=\"method\"><arg direction=\"out\" type=\"i\" name=\"thisShouldNeverBeSeen\"/></method>" ; |
469 | |
470 | class MethodTest5: public QObject |
471 | { |
472 | Q_OBJECT |
473 | |
474 | public slots: |
475 | int method(int input0) { return input0; } |
476 | }; |
477 | const char MethodTest5_xml[] = |
478 | "<method name=\"method\">" |
479 | "<arg direction=\"in\" type=\"i\" name=\"input0\"/>" |
480 | "<arg direction=\"out\" type=\"i\"/>" |
481 | "</method>" ; |
482 | |
483 | class MethodTest6: public QObject |
484 | { |
485 | Q_OBJECT |
486 | |
487 | public slots: |
488 | int method(int input0, int input1) { Q_UNUSED(input0); return input1; } |
489 | }; |
490 | const char MethodTest6_xml[] = |
491 | "<method name=\"method\">" |
492 | "<arg direction=\"in\" type=\"i\" name=\"input0\"/>" |
493 | "<arg direction=\"out\" type=\"i\"/>" |
494 | "<arg direction=\"in\" type=\"i\" name=\"input1\"/>" |
495 | "</method>" ; |
496 | |
497 | class MethodTest7: public QObject |
498 | { |
499 | Q_OBJECT |
500 | |
501 | public slots: |
502 | int method(int input0, int input1, int &output1) { output1 = input1; return input0; } |
503 | }; |
504 | const char MethodTest7_xml[] = |
505 | "<method name=\"method\">" |
506 | "<arg direction=\"in\" type=\"i\" name=\"input0\"/>" |
507 | "<arg direction=\"in\" type=\"i\" name=\"input1\"/>" |
508 | "<arg direction=\"out\" type=\"i\"/>" |
509 | "<arg direction=\"out\" type=\"i\" name=\"output1\"/>" |
510 | "</method>" ; |
511 | |
512 | class MethodTest8: public QObject |
513 | { |
514 | Q_OBJECT |
515 | |
516 | public slots: |
517 | int method(int input0, int input1, int &output1, int &output2) { output1 = output2 = input1; return input0; } |
518 | }; |
519 | const char MethodTest8_xml[] = |
520 | "<method name=\"method\">" |
521 | "<arg direction=\"in\" type=\"i\" name=\"input0\"/>" |
522 | "<arg direction=\"in\" type=\"i\" name=\"input1\"/>" |
523 | "<arg direction=\"out\" type=\"i\"/>" |
524 | "<arg direction=\"out\" type=\"i\" name=\"output1\"/>" |
525 | "<arg direction=\"out\" type=\"i\" name=\"output2\"/>" |
526 | "</method>" ; |
527 | |
528 | class MethodTest9: public QObject |
529 | { |
530 | Q_OBJECT |
531 | |
532 | public slots: |
533 | Q_NOREPLY void method(int) { } |
534 | }; |
535 | const char MethodTest9_xml[] = |
536 | "<method name=\"method\">" |
537 | "<arg direction=\"in\" type=\"i\"/>" |
538 | "<annotation name=\"org.freedesktop.DBus.Method.NoReply\" value=\"true\"/>" |
539 | "</method>" ; |
540 | |
541 | void tst_QDBusMetaObject::methods_data() |
542 | { |
543 | QTest::addColumn<const QMetaObject *>(name: "metaobject" ); |
544 | QTest::addColumn<QString>(name: "xml" ); |
545 | |
546 | QTest::newRow(dataTag: "void-void" ) << &MethodTest1::staticMetaObject << QString(MethodTest1_xml); |
547 | QTest::newRow(dataTag: "void-int" ) << &MethodTest2::staticMetaObject << QString(MethodTest2_xml); |
548 | QTest::newRow(dataTag: "void-int-with-name" ) << &MethodTest3::staticMetaObject << QString(MethodTest3_xml); |
549 | QTest::newRow(dataTag: "int-void" ) << &MethodTest4::staticMetaObject << QString(MethodTest4_xml); |
550 | QTest::newRow(dataTag: "int-void2" ) << &MethodTest4::staticMetaObject << QString(MethodTest4_xml2); |
551 | QTest::newRow(dataTag: "int-int" ) << &MethodTest5::staticMetaObject << QString(MethodTest5_xml); |
552 | QTest::newRow(dataTag: "int-int,int" ) << &MethodTest6::staticMetaObject << QString(MethodTest6_xml); |
553 | QTest::newRow(dataTag: "int,int-int,int" ) << &MethodTest7::staticMetaObject << QString(MethodTest7_xml); |
554 | QTest::newRow(dataTag: "int,int,int-int,int" ) << &MethodTest8::staticMetaObject << QString(MethodTest8_xml); |
555 | QTest::newRow(dataTag: "Q_ASYNC" ) << &MethodTest9::staticMetaObject << QString(MethodTest9_xml); |
556 | } |
557 | |
558 | void tst_QDBusMetaObject::methods() |
559 | { |
560 | types(); |
561 | } |
562 | |
563 | class SignalTest1: public QObject |
564 | { |
565 | Q_OBJECT |
566 | |
567 | signals: |
568 | void signal(); |
569 | }; |
570 | const char SignalTest1_xml[] = |
571 | "<signal name=\"signal\" />" ; |
572 | |
573 | class SignalTest2: public QObject |
574 | { |
575 | Q_OBJECT |
576 | |
577 | signals: |
578 | void signal(int); |
579 | }; |
580 | const char SignalTest2_xml[] = |
581 | "<signal name=\"signal\"><arg type=\"i\"/></signal>" ; |
582 | |
583 | class SignalTest3: public QObject |
584 | { |
585 | Q_OBJECT |
586 | |
587 | signals: |
588 | void signal(int output0); |
589 | }; |
590 | const char SignalTest3_xml[] = |
591 | "<signal name=\"signal\"><arg type=\"i\" name=\"output0\"/></signal>" ; |
592 | |
593 | class SignalTest4: public QObject |
594 | { |
595 | Q_OBJECT |
596 | |
597 | signals: |
598 | void signal(int output0, int); |
599 | }; |
600 | const char SignalTest4_xml[] = |
601 | "<signal name=\"signal\"><arg type=\"i\" name=\"output0\"/><arg type=\"i\"/></signal>" ; |
602 | |
603 | void tst_QDBusMetaObject::_signals_data() |
604 | { |
605 | QTest::addColumn<const QMetaObject *>(name: "metaobject" ); |
606 | QTest::addColumn<QString>(name: "xml" ); |
607 | |
608 | QTest::newRow(dataTag: "empty" ) << &SignalTest1::staticMetaObject << QString(SignalTest1_xml); |
609 | QTest::newRow(dataTag: "int" ) << &SignalTest2::staticMetaObject << QString(SignalTest2_xml); |
610 | QTest::newRow(dataTag: "int output0" ) << &SignalTest3::staticMetaObject << QString(SignalTest3_xml); |
611 | QTest::newRow(dataTag: "int output0,int" ) << &SignalTest4::staticMetaObject << QString(SignalTest4_xml); |
612 | } |
613 | |
614 | void tst_QDBusMetaObject::_signals() |
615 | { |
616 | types(); |
617 | } |
618 | |
619 | class PropertyTest1: public QObject |
620 | { |
621 | Q_OBJECT |
622 | Q_PROPERTY(int property READ property) |
623 | public: |
624 | int property() { return 0; } |
625 | void setProperty(int) { } |
626 | }; |
627 | const char PropertyTest1_xml[] = |
628 | "<property name=\"property\" type=\"i\" access=\"read\"/>" ; |
629 | |
630 | class PropertyTest2: public QObject |
631 | { |
632 | Q_OBJECT |
633 | Q_PROPERTY(int property READ property WRITE setProperty) |
634 | public: |
635 | int property() { return 0; } |
636 | void setProperty(int) { } |
637 | }; |
638 | const char PropertyTest2_xml[] = |
639 | "<property name=\"property\" type=\"i\" access=\"readwrite\"/>" ; |
640 | |
641 | class PropertyTest3: public QObject |
642 | { |
643 | Q_OBJECT |
644 | Q_PROPERTY(int property WRITE setProperty) |
645 | public: |
646 | int property() { return 0; } |
647 | void setProperty(int) { } |
648 | }; |
649 | const char PropertyTest3_xml[] = |
650 | "<property name=\"property\" type=\"i\" access=\"write\"/>" ; |
651 | |
652 | class PropertyTest4: public QObject |
653 | { |
654 | Q_OBJECT |
655 | Q_PROPERTY(Struct1 property WRITE setProperty) |
656 | public: |
657 | Struct1 property() { return Struct1(); } |
658 | void setProperty(Struct1) { } |
659 | }; |
660 | const char PropertyTest4_xml[] = |
661 | "<property name=\"property\" type=\"(s)\" access=\"write\">" |
662 | "<annotation name=\"org.qtproject.QtDBus.QtTypeName\" value=\"Struct1\"/>" |
663 | "</property>" ; |
664 | |
665 | class PropertyTest_b: public QObject |
666 | { |
667 | Q_OBJECT |
668 | Q_PROPERTY(bool property READ property WRITE setProperty) |
669 | public: |
670 | bool property() { return false; } |
671 | void setProperty(bool) { } |
672 | }; |
673 | const char PropertyTest_b_xml[] = |
674 | "<property name=\"property\" type=\"b\" access=\"readwrite\"/>" ; |
675 | |
676 | class PropertyTest_y: public QObject |
677 | { |
678 | Q_OBJECT |
679 | Q_PROPERTY(uchar property READ property WRITE setProperty) |
680 | public: |
681 | uchar property() { return 0; } |
682 | void setProperty(uchar) { } |
683 | }; |
684 | const char PropertyTest_y_xml[] = |
685 | "<property name=\"property\" type=\"y\" access=\"readwrite\"/>" ; |
686 | |
687 | class PropertyTest_n: public QObject |
688 | { |
689 | Q_OBJECT |
690 | Q_PROPERTY(short property READ property WRITE setProperty) |
691 | public: |
692 | short property() { return 0; } |
693 | void setProperty(short) { } |
694 | }; |
695 | const char PropertyTest_n_xml[] = |
696 | "<property name=\"property\" type=\"n\" access=\"readwrite\"/>" ; |
697 | |
698 | class PropertyTest_q: public QObject |
699 | { |
700 | Q_OBJECT |
701 | Q_PROPERTY(ushort property READ property WRITE setProperty) |
702 | public: |
703 | ushort property() { return 0; } |
704 | void setProperty(ushort) { } |
705 | }; |
706 | const char PropertyTest_q_xml[] = |
707 | "<property name=\"property\" type=\"q\" access=\"readwrite\"/>" ; |
708 | |
709 | class PropertyTest_u: public QObject |
710 | { |
711 | Q_OBJECT |
712 | Q_PROPERTY(uint property READ property WRITE setProperty) |
713 | public: |
714 | uint property() { return 0; } |
715 | void setProperty(uint) { } |
716 | }; |
717 | const char PropertyTest_u_xml[] = |
718 | "<property name=\"property\" type=\"u\" access=\"readwrite\"/>" ; |
719 | |
720 | class PropertyTest_x: public QObject |
721 | { |
722 | Q_OBJECT |
723 | Q_PROPERTY(qlonglong property READ property WRITE setProperty) |
724 | public: |
725 | qlonglong property() { return 0; } |
726 | void setProperty(qlonglong) { } |
727 | }; |
728 | const char PropertyTest_x_xml[] = |
729 | "<property name=\"property\" type=\"x\" access=\"readwrite\"/>" ; |
730 | |
731 | class PropertyTest_t: public QObject |
732 | { |
733 | Q_OBJECT |
734 | Q_PROPERTY(qulonglong property READ property WRITE setProperty) |
735 | public: |
736 | qulonglong property() { return 0; } |
737 | void setProperty(qulonglong) { } |
738 | }; |
739 | const char PropertyTest_t_xml[] = |
740 | "<property name=\"property\" type=\"t\" access=\"readwrite\"/>" ; |
741 | |
742 | class PropertyTest_d: public QObject |
743 | { |
744 | Q_OBJECT |
745 | Q_PROPERTY(double property READ property WRITE setProperty) |
746 | public: |
747 | double property() { return 0; } |
748 | void setProperty(double) { } |
749 | }; |
750 | const char PropertyTest_d_xml[] = |
751 | "<property name=\"property\" type=\"d\" access=\"readwrite\"/>" ; |
752 | |
753 | class PropertyTest_s: public QObject |
754 | { |
755 | Q_OBJECT |
756 | Q_PROPERTY(QString property READ property WRITE setProperty) |
757 | public: |
758 | QString property() { return QString(); } |
759 | void setProperty(QString) { } |
760 | }; |
761 | const char PropertyTest_s_xml[] = |
762 | "<property name=\"property\" type=\"s\" access=\"readwrite\"/>" ; |
763 | |
764 | class PropertyTest_v: public QObject |
765 | { |
766 | Q_OBJECT |
767 | Q_PROPERTY(QDBusVariant property READ property WRITE setProperty) |
768 | public: |
769 | QDBusVariant property() { return QDBusVariant(); } |
770 | void setProperty(QDBusVariant) { } |
771 | }; |
772 | const char PropertyTest_v_xml[] = |
773 | "<property name=\"property\" type=\"v\" access=\"readwrite\"/>" ; |
774 | |
775 | class PropertyTest_o: public QObject |
776 | { |
777 | Q_OBJECT |
778 | Q_PROPERTY(QDBusObjectPath property READ property WRITE setProperty) |
779 | public: |
780 | QDBusObjectPath property() { return QDBusObjectPath(); } |
781 | void setProperty(QDBusObjectPath) { } |
782 | }; |
783 | const char PropertyTest_o_xml[] = |
784 | "<property name=\"property\" type=\"o\" access=\"readwrite\"/>" ; |
785 | |
786 | class PropertyTest_g: public QObject |
787 | { |
788 | Q_OBJECT |
789 | Q_PROPERTY(QDBusSignature property READ property WRITE setProperty) |
790 | public: |
791 | QDBusSignature property() { return QDBusSignature(); } |
792 | void setProperty(QDBusSignature) { } |
793 | }; |
794 | const char PropertyTest_g_xml[] = |
795 | "<property name=\"property\" type=\"g\" access=\"readwrite\"/>" ; |
796 | |
797 | class PropertyTest_h: public QObject |
798 | { |
799 | Q_OBJECT |
800 | Q_PROPERTY(QDBusUnixFileDescriptor property READ property WRITE setProperty) |
801 | public: |
802 | QDBusUnixFileDescriptor property() { return QDBusUnixFileDescriptor(); } |
803 | void setProperty(QDBusUnixFileDescriptor) { } |
804 | }; |
805 | const char PropertyTest_h_xml[] = |
806 | "<property name=\"property\" type=\"h\" access=\"readwrite\"/>" ; |
807 | |
808 | class PropertyTest_ay: public QObject |
809 | { |
810 | Q_OBJECT |
811 | Q_PROPERTY(QByteArray property READ property WRITE setProperty) |
812 | public: |
813 | QByteArray property() { return QByteArray(); } |
814 | void setProperty(QByteArray) { } |
815 | }; |
816 | const char PropertyTest_ay_xml[] = |
817 | "<property name=\"property\" type=\"ay\" access=\"readwrite\"/>" ; |
818 | |
819 | class PropertyTest_as: public QObject |
820 | { |
821 | Q_OBJECT |
822 | Q_PROPERTY(QStringList property READ property WRITE setProperty) |
823 | public: |
824 | QStringList property() { return QStringList(); } |
825 | void setProperty(QStringList) { } |
826 | }; |
827 | const char PropertyTest_as_xml[] = |
828 | "<property name=\"property\" type=\"as\" access=\"readwrite\"/>" ; |
829 | |
830 | class PropertyTest_av: public QObject |
831 | { |
832 | Q_OBJECT |
833 | Q_PROPERTY(QVariantList property READ property WRITE setProperty) |
834 | public: |
835 | QVariantList property() { return QVariantList(); } |
836 | void setProperty(QVariantList) { } |
837 | }; |
838 | const char PropertyTest_av_xml[] = |
839 | "<property name=\"property\" type=\"av\" access=\"readwrite\"/>" ; |
840 | |
841 | class PropertyTest_ao: public QObject |
842 | { |
843 | Q_OBJECT |
844 | Q_PROPERTY(QList<QDBusObjectPath> property READ property WRITE setProperty) |
845 | public: |
846 | QList<QDBusObjectPath> property() { return QList<QDBusObjectPath>(); } |
847 | void setProperty(QList<QDBusObjectPath>) { } |
848 | }; |
849 | const char PropertyTest_ao_xml[] = |
850 | "<property name=\"property\" type=\"ao\" access=\"readwrite\"/>" ; |
851 | |
852 | class PropertyTest_ag: public QObject |
853 | { |
854 | Q_OBJECT |
855 | Q_PROPERTY(QList<QDBusSignature> property READ property WRITE setProperty) |
856 | public: |
857 | QList<QDBusSignature> property() { return QList<QDBusSignature>(); } |
858 | void setProperty(QList<QDBusSignature>) { } |
859 | }; |
860 | const char PropertyTest_ag_xml[] = |
861 | "<property name=\"property\" type=\"ag\" access=\"readwrite\"/>" ; |
862 | |
863 | void tst_QDBusMetaObject::properties_data() |
864 | { |
865 | QTest::addColumn<const QMetaObject *>(name: "metaobject" ); |
866 | QTest::addColumn<QString>(name: "xml" ); |
867 | |
868 | QTest::newRow(dataTag: "read" ) << &PropertyTest1::staticMetaObject << QString(PropertyTest1_xml); |
869 | QTest::newRow(dataTag: "readwrite" ) << &PropertyTest2::staticMetaObject << QString(PropertyTest2_xml); |
870 | QTest::newRow(dataTag: "write" ) << &PropertyTest3::staticMetaObject << QString(PropertyTest3_xml); |
871 | QTest::newRow(dataTag: "customtype" ) << &PropertyTest4::staticMetaObject << QString(PropertyTest4_xml); |
872 | |
873 | QTest::newRow(dataTag: "bool" ) << &PropertyTest_b::staticMetaObject << QString(PropertyTest_b_xml); |
874 | QTest::newRow(dataTag: "byte" ) << &PropertyTest_y::staticMetaObject << QString(PropertyTest_y_xml); |
875 | QTest::newRow(dataTag: "short" ) << &PropertyTest_n::staticMetaObject << QString(PropertyTest_n_xml); |
876 | QTest::newRow(dataTag: "ushort" ) << &PropertyTest_q::staticMetaObject << QString(PropertyTest_q_xml); |
877 | QTest::newRow(dataTag: "uint" ) << &PropertyTest_u::staticMetaObject << QString(PropertyTest_u_xml); |
878 | QTest::newRow(dataTag: "qlonglong" ) << &PropertyTest_x::staticMetaObject << QString(PropertyTest_x_xml); |
879 | QTest::newRow(dataTag: "qulonglong" ) << &PropertyTest_t::staticMetaObject << QString(PropertyTest_t_xml); |
880 | QTest::newRow(dataTag: "double" ) << &PropertyTest_d::staticMetaObject << QString(PropertyTest_d_xml); |
881 | QTest::newRow(dataTag: "QString" ) << &PropertyTest_s::staticMetaObject << QString(PropertyTest_s_xml); |
882 | QTest::newRow(dataTag: "QDBusVariant" ) << &PropertyTest_v::staticMetaObject << QString(PropertyTest_v_xml); |
883 | QTest::newRow(dataTag: "QDBusObjectPath" ) << &PropertyTest_o::staticMetaObject << QString(PropertyTest_o_xml); |
884 | QTest::newRow(dataTag: "QDBusSignature" ) << &PropertyTest_g::staticMetaObject << QString(PropertyTest_g_xml); |
885 | QTest::newRow(dataTag: "QDBusUnixFileDescriptor" ) << &PropertyTest_h::staticMetaObject << QString(PropertyTest_h_xml); |
886 | QTest::newRow(dataTag: "QByteArray" ) << &PropertyTest_ay::staticMetaObject << QString(PropertyTest_ay_xml); |
887 | QTest::newRow(dataTag: "QStringList" ) << &PropertyTest_as::staticMetaObject << QString(PropertyTest_as_xml); |
888 | QTest::newRow(dataTag: "QVariantList" ) << &PropertyTest_av::staticMetaObject << QString(PropertyTest_av_xml); |
889 | QTest::newRow(dataTag: "QList<QDBusObjectPath>" ) << &PropertyTest_ao::staticMetaObject << QString(PropertyTest_ao_xml); |
890 | QTest::newRow(dataTag: "QList<QDBusSignature>" ) << &PropertyTest_ag::staticMetaObject << QString(PropertyTest_ag_xml); |
891 | } |
892 | |
893 | void tst_QDBusMetaObject::properties() |
894 | { |
895 | types(); |
896 | } |
897 | |
898 | |
899 | QTEST_MAIN(tst_QDBusMetaObject) |
900 | #include "tst_qdbusmetaobject.moc" |
901 | |