1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
43 #include <QtTest/QtTest>
46 #include <qmetaobject.h>
48 class tst_QMetaMethod : public QObject
59 struct CustomType { };
60 Q_DECLARE_METATYPE(CustomType)
62 struct CustomUnregisteredType { };
64 Q_DECLARE_METATYPE(QMetaMethod::Access)
65 Q_DECLARE_METATYPE(QMetaMethod::MethodType)
67 class MethodTestObject : public QObject
71 Q_INVOKABLE MethodTestObject();
72 Q_INVOKABLE MethodTestObject(int constructorIntArg);
73 Q_INVOKABLE MethodTestObject(qreal constructorQRealArg);
74 Q_INVOKABLE MethodTestObject(const QString &constructorQStringArg);
75 Q_INVOKABLE MethodTestObject(CustomType constructorCustomTypeArg);
76 Q_INVOKABLE MethodTestObject(CustomUnregisteredType constructorCustomUnregisteredTypeArg);
77 Q_INVOKABLE MethodTestObject(bool boolArg, int intArg, uint uintArg,
78 qlonglong longlongArg, qulonglong ulonglongArg,
79 double doubleArg, long longArg, short shortArg,
80 char charArg, ulong ulongArg, ushort ushortArg,
81 uchar ucharArg, float floatArg);
82 Q_INVOKABLE MethodTestObject(bool, int);
84 Q_INVOKABLE void voidInvokable();
85 Q_INVOKABLE void voidInvokableInt(int voidInvokableIntArg);
86 Q_INVOKABLE void voidInvokableQReal(qreal voidInvokableQRealArg);
87 Q_INVOKABLE void voidInvokableQString(const QString &voidInvokableQStringArg);
88 Q_INVOKABLE void voidInvokableCustomType(CustomType voidInvokableCustomTypeArg);
89 Q_INVOKABLE void voidInvokableCustomUnregisteredType(CustomUnregisteredType voidInvokableCustomUnregisteredTypeArg);
90 Q_INVOKABLE bool boolInvokable();
91 Q_INVOKABLE qreal qrealInvokable();
92 Q_INVOKABLE QString qstringInvokable();
93 Q_INVOKABLE CustomType customTypeInvokable();
94 Q_INVOKABLE CustomUnregisteredType customUnregisteredTypeInvokable();
95 Q_INVOKABLE QVariant qvariantInvokableBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat(
96 bool boolArg, int intArg, uint uintArg, qlonglong longlongArg, qulonglong ulonglongArg, double doubleArg,
97 long longArg, short shortArg, char charArg, ulong ulongArg, ushort ushortArg, uchar ucharArg, float floatArg);
98 Q_INVOKABLE void voidInvokableNoParameterNames(bool, int);
101 void voidSlotInt(int voidSlotIntArg);
102 void voidSlotQReal(qreal voidSlotQRealArg);
103 void voidSlotQString(const QString &voidSlotQStringArg);
104 void voidSlotCustomType(CustomType voidSlotCustomTypeArg);
105 void voidSlotCustomUnregisteredType(CustomUnregisteredType voidSlotCustomUnregisteredTypeArg);
108 QString qstringSlot();
109 CustomType customTypeSlot();
110 CustomUnregisteredType customUnregisteredTypeSlot();
111 QVariant qvariantSlotBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat(
112 bool boolArg, int intArg, uint uintArg, qlonglong longlongArg, qulonglong ulonglongArg, double doubleArg,
113 long longArg, short shortArg, char charArg, ulong ulongArg, ushort ushortArg, uchar ucharArg, float floatArg);
114 void voidSlotNoParameterNames(bool, int);
117 void voidSignalInt(int voidSignalIntArg);
118 void voidSignalQReal(qreal voidSignalQRealArg);
119 void voidSignalQString(const QString &voidSignalQStringArg);
120 void voidSignalCustomType(CustomType voidSignalCustomTypeArg);
121 void voidSignalCustomUnregisteredType(CustomUnregisteredType voidSignalCustomUnregisteredTypeArg);
124 QString qstringSignal();
125 CustomType customTypeSignal();
126 CustomUnregisteredType customUnregisteredTypeSignal();
127 QVariant qvariantSignalBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat(
128 bool boolArg, int intArg, uint uintArg, qlonglong longlongArg, qulonglong ulonglongArg, double doubleArg,
129 long longArg, short shortArg, char charArg, ulong ulongArg, ushort ushortArg, uchar ucharArg, float floatArg);
130 void voidSignalNoParameterNames(bool, int);
133 MethodTestObject::MethodTestObject() {}
134 MethodTestObject::MethodTestObject(int) {}
135 MethodTestObject::MethodTestObject(qreal) {}
136 MethodTestObject::MethodTestObject(const QString &) {}
137 MethodTestObject::MethodTestObject(CustomType) {}
138 MethodTestObject::MethodTestObject(CustomUnregisteredType) {}
139 MethodTestObject::MethodTestObject(bool, int, uint, qlonglong, qulonglong,
140 double, long, short, char, ulong, ushort,
142 MethodTestObject::MethodTestObject(bool, int) {}
144 void MethodTestObject::voidInvokable() {}
145 void MethodTestObject::voidInvokableInt(int) {}
146 void MethodTestObject::voidInvokableQReal(qreal) {}
147 void MethodTestObject::voidInvokableQString(const QString &) {}
148 void MethodTestObject::voidInvokableCustomType(CustomType) {}
149 void MethodTestObject::voidInvokableCustomUnregisteredType(CustomUnregisteredType) {}
150 bool MethodTestObject::boolInvokable() { return true; }
151 qreal MethodTestObject::qrealInvokable() { return 1.0; }
152 QString MethodTestObject::qstringInvokable() { return QString(); }
153 CustomType MethodTestObject::customTypeInvokable() { return CustomType(); }
154 CustomUnregisteredType MethodTestObject::customUnregisteredTypeInvokable()
156 return CustomUnregisteredType();
158 QVariant MethodTestObject::qvariantInvokableBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat(
159 bool, int, uint, qlonglong, qulonglong, double, long, short, char, ulong, ushort, uchar, float)
163 void MethodTestObject::voidInvokableNoParameterNames(bool, int) {}
165 void MethodTestObject::voidSlot() {}
166 void MethodTestObject::voidSlotInt(int) {}
167 void MethodTestObject::voidSlotQReal(qreal) {}
168 void MethodTestObject::voidSlotQString(const QString &) {}
169 void MethodTestObject::voidSlotCustomType(CustomType) {}
170 void MethodTestObject::voidSlotCustomUnregisteredType(CustomUnregisteredType) {}
171 bool MethodTestObject::boolSlot() { return true; }
172 qreal MethodTestObject::qrealSlot() { return 1.0; }
173 QString MethodTestObject::qstringSlot() { return QString(); }
174 CustomType MethodTestObject::customTypeSlot() { return CustomType(); }
175 CustomUnregisteredType MethodTestObject::customUnregisteredTypeSlot()
177 return CustomUnregisteredType();
179 QVariant MethodTestObject::qvariantSlotBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat(
180 bool, int, uint, qlonglong, qulonglong, double, long, short, char, ulong, ushort, uchar, float)
184 void MethodTestObject::voidSlotNoParameterNames(bool, int) {}
186 void tst_QMetaMethod::method_data()
188 QTest::addColumn<QByteArray>("signature");
189 QTest::addColumn<int>("returnType");
190 QTest::addColumn<QByteArray>("returnTypeName");
191 QTest::addColumn<QList<int> >("parameterTypes");
192 QTest::addColumn<QList<QByteArray> >("parameterTypeNames");
193 QTest::addColumn<QList<QByteArray> >("parameterNames");
194 QTest::addColumn<QMetaMethod::Access>("access");
195 QTest::addColumn<QMetaMethod::MethodType>("methodType");
197 QTest::newRow("voidSignal")
198 << QByteArray("voidSignal()")
199 << int(QMetaType::Void) << QByteArray("")
201 << (QList<QByteArray>())
202 << (QList<QByteArray>())
203 << QMetaMethod::Protected
204 << QMetaMethod::Signal;
206 QTest::newRow("voidInvokable")
207 << QByteArray("voidInvokable()")
208 << int(QMetaType::Void) << QByteArray("")
210 << (QList<QByteArray>())
211 << (QList<QByteArray>())
212 << QMetaMethod::Public
213 << QMetaMethod::Method;
215 QTest::newRow("voidSlot")
216 << QByteArray("voidSlot()")
217 << int(QMetaType::Void) << QByteArray("")
219 << (QList<QByteArray>())
220 << (QList<QByteArray>())
221 << QMetaMethod::Public
222 << QMetaMethod::Slot;
224 QTest::newRow("MethodTestObject()")
225 << QByteArray("MethodTestObject()")
226 << int(QMetaType::UnknownType) << QByteArray("")
228 << (QList<QByteArray>())
229 << (QList<QByteArray>())
230 << QMetaMethod::Public
231 << QMetaMethod::Constructor;
233 QTest::newRow("voidSignalInt")
234 << QByteArray("voidSignalInt(int)")
235 << int(QMetaType::Void) << QByteArray("")
236 << (QList<int>() << int(QMetaType::Int))
237 << (QList<QByteArray>() << QByteArray("int"))
238 << (QList<QByteArray>() << QByteArray("voidSignalIntArg"))
239 << QMetaMethod::Protected
240 << QMetaMethod::Signal;
242 QTest::newRow("voidInvokableInt")
243 << QByteArray("voidInvokableInt(int)")
244 << int(QMetaType::Void) << QByteArray("")
245 << (QList<int>() << int(QMetaType::Int))
246 << (QList<QByteArray>() << QByteArray("int"))
247 << (QList<QByteArray>() << QByteArray("voidInvokableIntArg"))
248 << QMetaMethod::Public
249 << QMetaMethod::Method;
251 QTest::newRow("voidSlotInt")
252 << QByteArray("voidSlotInt(int)")
253 << int(QMetaType::Void) << QByteArray("")
254 << (QList<int>() << int(QMetaType::Int))
255 << (QList<QByteArray>() << QByteArray("int"))
256 << (QList<QByteArray>() << QByteArray("voidSlotIntArg"))
257 << QMetaMethod::Public
258 << QMetaMethod::Slot;
260 QTest::newRow("MethodTestObject(int)")
261 << QByteArray("MethodTestObject(int)")
262 << int(QMetaType::UnknownType) << QByteArray("")
263 << (QList<int>() << int(QMetaType::Int))
264 << (QList<QByteArray>() << QByteArray("int"))
265 << (QList<QByteArray>() << QByteArray("constructorIntArg"))
266 << QMetaMethod::Public
267 << QMetaMethod::Constructor;
269 QTest::newRow("voidSignalQReal")
270 << QByteArray("voidSignalQReal(qreal)")
271 << int(QMetaType::Void) << QByteArray("")
272 << (QList<int>() << qMetaTypeId<qreal>())
273 << (QList<QByteArray>() << QByteArray("qreal"))
274 << (QList<QByteArray>() << QByteArray("voidSignalQRealArg"))
275 << QMetaMethod::Protected
276 << QMetaMethod::Signal;
278 QTest::newRow("voidInvokableQReal")
279 << QByteArray("voidInvokableQReal(qreal)")
280 << int(QMetaType::Void) << QByteArray("")
281 << (QList<int>() << qMetaTypeId<qreal>())
282 << (QList<QByteArray>() << QByteArray("qreal"))
283 << (QList<QByteArray>() << QByteArray("voidInvokableQRealArg"))
284 << QMetaMethod::Public
285 << QMetaMethod::Method;
287 QTest::newRow("voidSlotQReal")
288 << QByteArray("voidSlotQReal(qreal)")
289 << int(QMetaType::Void) << QByteArray("")
290 << (QList<int>() << qMetaTypeId<qreal>())
291 << (QList<QByteArray>() << QByteArray("qreal"))
292 << (QList<QByteArray>() << QByteArray("voidSlotQRealArg"))
293 << QMetaMethod::Public
294 << QMetaMethod::Slot;
296 QTest::newRow("MethodTestObject(qreal)")
297 << QByteArray("MethodTestObject(qreal)")
298 << int(QMetaType::UnknownType) << QByteArray("")
299 << (QList<int>() << qMetaTypeId<qreal>())
300 << (QList<QByteArray>() << QByteArray("qreal"))
301 << (QList<QByteArray>() << QByteArray("constructorQRealArg"))
302 << QMetaMethod::Public
303 << QMetaMethod::Constructor;
305 QTest::newRow("voidSignalQString")
306 << QByteArray("voidSignalQString(QString)")
307 << int(QMetaType::Void) << QByteArray("")
308 << (QList<int>() << int(QMetaType::QString))
309 << (QList<QByteArray>() << QByteArray("QString"))
310 << (QList<QByteArray>() << QByteArray("voidSignalQStringArg"))
311 << QMetaMethod::Protected
312 << QMetaMethod::Signal;
314 QTest::newRow("voidInvokableQString")
315 << QByteArray("voidInvokableQString(QString)")
316 << int(QMetaType::Void) << QByteArray("")
317 << (QList<int>() << int(QMetaType::QString))
318 << (QList<QByteArray>() << QByteArray("QString"))
319 << (QList<QByteArray>() << QByteArray("voidInvokableQStringArg"))
320 << QMetaMethod::Public
321 << QMetaMethod::Method;
323 QTest::newRow("voidSlotQString")
324 << QByteArray("voidSlotQString(QString)")
325 << int(QMetaType::Void) << QByteArray("")
326 << (QList<int>() << int(QMetaType::QString))
327 << (QList<QByteArray>() << QByteArray("QString"))
328 << (QList<QByteArray>() << QByteArray("voidSlotQStringArg"))
329 << QMetaMethod::Public
330 << QMetaMethod::Slot;
332 QTest::newRow("MethodTestObject(QString)")
333 << QByteArray("MethodTestObject(QString)")
334 << int(QMetaType::UnknownType) << QByteArray("")
335 << (QList<int>() << int(QMetaType::QString))
336 << (QList<QByteArray>() << QByteArray("QString"))
337 << (QList<QByteArray>() << QByteArray("constructorQStringArg"))
338 << QMetaMethod::Public
339 << QMetaMethod::Constructor;
341 QTest::newRow("voidSignalCustomType")
342 << QByteArray("voidSignalCustomType(CustomType)")
343 << int(QMetaType::Void) << QByteArray("")
344 << (QList<int>() << qMetaTypeId<CustomType>())
345 << (QList<QByteArray>() << QByteArray("CustomType"))
346 << (QList<QByteArray>() << QByteArray("voidSignalCustomTypeArg"))
347 << QMetaMethod::Protected
348 << QMetaMethod::Signal;
350 QTest::newRow("voidInvokableCustomType")
351 << QByteArray("voidInvokableCustomType(CustomType)")
352 << int(QMetaType::Void) << QByteArray("")
353 << (QList<int>() << qMetaTypeId<CustomType>())
354 << (QList<QByteArray>() << QByteArray("CustomType"))
355 << (QList<QByteArray>() << QByteArray("voidInvokableCustomTypeArg"))
356 << QMetaMethod::Public
357 << QMetaMethod::Method;
359 QTest::newRow("voidSlotCustomType")
360 << QByteArray("voidSlotCustomType(CustomType)")
361 << int(QMetaType::Void) << QByteArray("")
362 << (QList<int>() << qMetaTypeId<CustomType>())
363 << (QList<QByteArray>() << QByteArray("CustomType"))
364 << (QList<QByteArray>() << QByteArray("voidSlotCustomTypeArg"))
365 << QMetaMethod::Public
366 << QMetaMethod::Slot;
368 QTest::newRow("MethodTestObject(CustomType)")
369 << QByteArray("MethodTestObject(CustomType)")
370 << int(QMetaType::UnknownType) << QByteArray("")
371 << (QList<int>() << qMetaTypeId<CustomType>())
372 << (QList<QByteArray>() << QByteArray("CustomType"))
373 << (QList<QByteArray>() << QByteArray("constructorCustomTypeArg"))
374 << QMetaMethod::Public
375 << QMetaMethod::Constructor;
377 QTest::newRow("voidSignalCustomUnregisteredType")
378 << QByteArray("voidSignalCustomUnregisteredType(CustomUnregisteredType)")
379 << int(QMetaType::Void) << QByteArray("")
380 << (QList<int>() << 0)
381 << (QList<QByteArray>() << QByteArray("CustomUnregisteredType"))
382 << (QList<QByteArray>() << QByteArray("voidSignalCustomUnregisteredTypeArg"))
383 << QMetaMethod::Protected
384 << QMetaMethod::Signal;
386 QTest::newRow("voidInvokableCustomUnregisteredType")
387 << QByteArray("voidInvokableCustomUnregisteredType(CustomUnregisteredType)")
388 << int(QMetaType::Void) << QByteArray("")
389 << (QList<int>() << 0)
390 << (QList<QByteArray>() << QByteArray("CustomUnregisteredType"))
391 << (QList<QByteArray>() << QByteArray("voidInvokableCustomUnregisteredTypeArg"))
392 << QMetaMethod::Public
393 << QMetaMethod::Method;
395 QTest::newRow("voidSlotCustomUnregisteredType")
396 << QByteArray("voidSlotCustomUnregisteredType(CustomUnregisteredType)")
397 << int(QMetaType::Void) << QByteArray("")
398 << (QList<int>() << 0)
399 << (QList<QByteArray>() << QByteArray("CustomUnregisteredType"))
400 << (QList<QByteArray>() << QByteArray("voidSlotCustomUnregisteredTypeArg"))
401 << QMetaMethod::Public
402 << QMetaMethod::Slot;
404 QTest::newRow("MethodTestObject(CustomUnregisteredType)")
405 << QByteArray("MethodTestObject(CustomUnregisteredType)")
406 << int(QMetaType::UnknownType) << QByteArray("")
407 << (QList<int>() << 0)
408 << (QList<QByteArray>() << QByteArray("CustomUnregisteredType"))
409 << (QList<QByteArray>() << QByteArray("constructorCustomUnregisteredTypeArg"))
410 << QMetaMethod::Public
411 << QMetaMethod::Constructor;
413 QTest::newRow("boolSignal")
414 << QByteArray("boolSignal()")
415 << int(QMetaType::Bool) << QByteArray("bool")
417 << (QList<QByteArray>())
418 << (QList<QByteArray>())
419 << QMetaMethod::Protected
420 << QMetaMethod::Signal;
422 QTest::newRow("boolInvokable")
423 << QByteArray("boolInvokable()")
424 << int(QMetaType::Bool) << QByteArray("bool")
426 << (QList<QByteArray>())
427 << (QList<QByteArray>())
428 << QMetaMethod::Public
429 << QMetaMethod::Method;
431 QTest::newRow("boolSlot")
432 << QByteArray("boolSlot()")
433 << int(QMetaType::Bool) << QByteArray("bool")
435 << (QList<QByteArray>())
436 << (QList<QByteArray>())
437 << QMetaMethod::Public
438 << QMetaMethod::Slot;
440 QTest::newRow("qrealSignal")
441 << QByteArray("qrealSignal()")
442 << int(QMetaType::QReal) << QByteArray("qreal")
444 << (QList<QByteArray>())
445 << (QList<QByteArray>())
446 << QMetaMethod::Protected
447 << QMetaMethod::Signal;
449 QTest::newRow("qrealInvokable")
450 << QByteArray("qrealInvokable()")
451 << int(QMetaType::QReal) << QByteArray("qreal")
453 << (QList<QByteArray>())
454 << (QList<QByteArray>())
455 << QMetaMethod::Public
456 << QMetaMethod::Method;
458 QTest::newRow("qrealSlot")
459 << QByteArray("qrealSlot()")
460 << int(QMetaType::QReal) << QByteArray("qreal")
462 << (QList<QByteArray>())
463 << (QList<QByteArray>())
464 << QMetaMethod::Public
465 << QMetaMethod::Slot;
467 QTest::newRow("qstringSignal")
468 << QByteArray("qstringSignal()")
469 << int(QMetaType::QString) << QByteArray("QString")
471 << (QList<QByteArray>())
472 << (QList<QByteArray>())
473 << QMetaMethod::Protected
474 << QMetaMethod::Signal;
476 QTest::newRow("qstringInvokable")
477 << QByteArray("qstringInvokable()")
478 << int(QMetaType::QString) << QByteArray("QString")
480 << (QList<QByteArray>())
481 << (QList<QByteArray>())
482 << QMetaMethod::Public
483 << QMetaMethod::Method;
485 QTest::newRow("qstringSlot")
486 << QByteArray("qstringSlot()")
487 << int(QMetaType::QString) << QByteArray("QString")
489 << (QList<QByteArray>())
490 << (QList<QByteArray>())
491 << QMetaMethod::Public
492 << QMetaMethod::Slot;
495 QList<int> parameterTypes = QList<int>()
496 << int(QMetaType::Bool) << int(QMetaType::Int) << int(QMetaType::UInt)
497 << int(QMetaType::LongLong) << int(QMetaType::ULongLong) << int(QMetaType::Double)
498 << int(QMetaType::Long) << int(QMetaType::Short) << int(QMetaType::Char)
499 << int(QMetaType::ULong) << int(QMetaType::UShort) << int(QMetaType::UChar)
500 << int(QMetaType::Float);
501 QList<QByteArray> parameterTypeNames = QList<QByteArray>()
502 << QByteArray("bool") << QByteArray("int") << QByteArray("uint")
503 << QByteArray("qlonglong") << QByteArray("qulonglong") << QByteArray("double")
504 << QByteArray("long") << QByteArray("short") << QByteArray("char") << QByteArray("ulong")
505 << QByteArray("ushort") << QByteArray("uchar") << QByteArray("float");
506 QList<QByteArray> parameterNames = QList<QByteArray>()
507 << QByteArray("boolArg") << QByteArray("intArg") << QByteArray("uintArg")
508 << QByteArray("longlongArg") << QByteArray("ulonglongArg") << QByteArray("doubleArg")
509 << QByteArray("longArg") << QByteArray("shortArg") << QByteArray("charArg")
510 << QByteArray("ulongArg") << QByteArray("ushortArg") << QByteArray("ucharArg")
511 << QByteArray("floatArg");
513 QTest::newRow("qvariantSignalBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat")
514 << QByteArray("qvariantSignalBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat("
515 "bool,int,uint,qlonglong,qulonglong,double,long,short,char,ulong,ushort,uchar,float)")
516 << int(QMetaType::QVariant) << QByteArray("QVariant")
517 << parameterTypes << parameterTypeNames << parameterNames
518 << QMetaMethod::Protected
519 << QMetaMethod::Signal;
521 QTest::newRow("qvariantInvokableBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat")
522 << QByteArray("qvariantInvokableBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat("
523 "bool,int,uint,qlonglong,qulonglong,double,long,short,char,ulong,ushort,uchar,float)")
524 << int(QMetaType::QVariant) << QByteArray("QVariant")
525 << parameterTypes << parameterTypeNames << parameterNames
526 << QMetaMethod::Public
527 << QMetaMethod::Method;
529 QTest::newRow("qvariantSlotBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat")
530 << QByteArray("qvariantSlotBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat("
531 "bool,int,uint,qlonglong,qulonglong,double,long,short,char,ulong,ushort,uchar,float)")
532 << int(QMetaType::QVariant) << QByteArray("QVariant")
533 << parameterTypes << parameterTypeNames << parameterNames
534 << QMetaMethod::Public
535 << QMetaMethod::Slot;
537 QTest::newRow("MethodTestObject(bool,int,uint,qlonglong,qulonglong,double,long,short,char,ulong,ushort,uchar,float)")
538 << QByteArray("MethodTestObject(bool,int,uint,qlonglong,qulonglong,double,long,short,char,ulong,ushort,uchar,float)")
539 << int(QMetaType::UnknownType) << QByteArray("")
540 << parameterTypes << parameterTypeNames << parameterNames
541 << QMetaMethod::Public
542 << QMetaMethod::Constructor;
545 QTest::newRow("voidSignalNoParameterNames")
546 << QByteArray("voidSignalNoParameterNames(bool,int)")
547 << int(QMetaType::Void) << QByteArray("")
548 << (QList<int>() << int(QMetaType::Bool) << int(QMetaType::Int))
549 << (QList<QByteArray>() << QByteArray("bool") << QByteArray("int"))
550 << (QList<QByteArray>() << QByteArray("") << QByteArray(""))
551 << QMetaMethod::Protected
552 << QMetaMethod::Signal;
554 QTest::newRow("voidInvokableNoParameterNames")
555 << QByteArray("voidInvokableNoParameterNames(bool,int)")
556 << int(QMetaType::Void) << QByteArray("")
557 << (QList<int>() << int(QMetaType::Bool) << int(QMetaType::Int))
558 << (QList<QByteArray>() << QByteArray("bool") << QByteArray("int"))
559 << (QList<QByteArray>() << QByteArray("") << QByteArray(""))
560 << QMetaMethod::Public
561 << QMetaMethod::Method;
563 QTest::newRow("voidSlotNoParameterNames")
564 << QByteArray("voidSlotNoParameterNames(bool,int)")
565 << int(QMetaType::Void) << QByteArray("")
566 << (QList<int>() << int(QMetaType::Bool) << int(QMetaType::Int))
567 << (QList<QByteArray>() << QByteArray("bool") << QByteArray("int"))
568 << (QList<QByteArray>() << QByteArray("") << QByteArray(""))
569 << QMetaMethod::Public
570 << QMetaMethod::Slot;
572 QTest::newRow("MethodTestObject(bool,int)")
573 << QByteArray("MethodTestObject(bool,int)")
574 << int(QMetaType::UnknownType) << QByteArray("")
575 << (QList<int>() << int(QMetaType::Bool) << int(QMetaType::Int))
576 << (QList<QByteArray>() << QByteArray("bool") << QByteArray("int"))
577 << (QList<QByteArray>() << QByteArray("") << QByteArray(""))
578 << QMetaMethod::Public
579 << QMetaMethod::Constructor;
582 void tst_QMetaMethod::method()
584 QFETCH(QByteArray, signature);
585 QFETCH(int, returnType);
586 QFETCH(QByteArray, returnTypeName);
587 QFETCH(QList<int>, parameterTypes);
588 QFETCH(QList<QByteArray>, parameterTypeNames);
589 QFETCH(QList<QByteArray>, parameterNames);
590 QFETCH(QMetaMethod::MethodType, methodType);
591 QFETCH(QMetaMethod::Access, access);
593 QVERIFY(parameterTypes.size() == parameterTypeNames.size());
594 QVERIFY(parameterTypes.size() == parameterNames.size());
596 const QMetaObject *mo = &MethodTestObject::staticMetaObject;
597 int index = (methodType == QMetaMethod::Constructor)
598 ? mo->indexOfConstructor(signature) : mo->indexOfMethod(signature);
599 QVERIFY(index != -1);
600 QMetaMethod method = (methodType == QMetaMethod::Constructor)
601 ? mo->constructor(index) : mo->method(index);
602 QVERIFY(method.isValid());
603 QCOMPARE(method.methodType(), methodType);
604 QCOMPARE(method.access(), access);
606 QVERIFY(!method.methodSignature().isEmpty());
607 if (method.methodSignature() != signature) {
608 // QMetaMethod should always produce a semantically equivalent signature
609 int signatureIndex = (methodType == QMetaMethod::Constructor)
610 ? mo->indexOfConstructor(method.methodSignature())
611 : mo->indexOfMethod(method.methodSignature());
612 QCOMPARE(signatureIndex, index);
615 QByteArray computedName = signature.left(signature.indexOf('('));
616 QCOMPARE(method.name(), computedName);
618 QCOMPARE(method.tag(), "");
619 QCOMPARE(method.returnType(), returnType);
620 if (QByteArray(method.typeName()) != returnTypeName) {
621 // QMetaMethod should always produce a semantically equivalent typename
622 QCOMPARE(QMetaType::type(method.typeName()), QMetaType::type(returnTypeName));
625 if (method.parameterTypes() != parameterTypeNames) {
626 // QMetaMethod should always produce semantically equivalent typenames
627 QList<QByteArray> actualTypeNames = method.parameterTypes();
628 QCOMPARE(actualTypeNames.size(), parameterTypeNames.size());
629 for (int i = 0; i < parameterTypeNames.size(); ++i) {
630 QCOMPARE(QMetaType::type(actualTypeNames.at(i)),
631 QMetaType::type(parameterTypeNames.at(i)));
634 QCOMPARE(method.parameterNames(), parameterNames);
636 QCOMPARE(method.parameterCount(), parameterTypes.size());
637 for (int i = 0; i < parameterTypes.size(); ++i)
638 QCOMPARE(method.parameterType(i), parameterTypes.at(i));
641 QVector<int> actualParameterTypes(parameterTypes.size());
642 method.getParameterTypes(actualParameterTypes.data());
643 for (int i = 0; i < parameterTypes.size(); ++i)
644 QCOMPARE(actualParameterTypes.at(i), parameterTypes.at(i));
648 QCOMPARE(method.parameterType(-1), 0);
649 QCOMPARE(method.parameterType(parameterTypes.size()), 0);
652 void tst_QMetaMethod::invalidMethod()
655 QVERIFY(!method.isValid());
657 QMetaMethod method2 = staticMetaObject.method(staticMetaObject.methodCount());
658 QVERIFY(!method2.isValid());
660 QMetaMethod method3 = staticMetaObject.method(-1);
661 QVERIFY(!method3.isValid());
664 QTEST_MAIN(tst_QMetaMethod)
665 #include "tst_qmetamethod.moc"