author | William Roberts <williamr@symbian.org> |
Thu, 22 Jul 2010 16:41:55 +0100 | |
branch | GCC_SURGE |
changeset 31 | 5daf16870df6 |
parent 30 | 5dc02b23752f |
child 33 | 3e2da88830cd |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
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 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
||
45 |
#include <qobject.h> |
|
46 |
#include <qmetaobject.h> |
|
47 |
#include <qlabel.h> |
|
48 |
||
49 |
//TESTED_CLASS= |
|
50 |
//TESTED_FILES= |
|
51 |
||
52 |
struct MyStruct |
|
53 |
{ |
|
54 |
int i; |
|
55 |
}; |
|
56 |
||
57 |
namespace MyNamespace { |
|
58 |
class MyClass : public QObject |
|
59 |
{ |
|
60 |
Q_OBJECT |
|
61 |
Q_PROPERTY(MyEnum myEnum READ myEnum WRITE setMyEnum) |
|
62 |
Q_PROPERTY(MyFlags myFlags READ myFlags WRITE setMyFlags) |
|
63 |
||
64 |
Q_ENUMS(MyEnum) |
|
65 |
Q_FLAGS(MyFlags) |
|
66 |
public: |
|
67 |
enum MyEnum { |
|
68 |
MyEnum1, |
|
69 |
MyEnum2, |
|
70 |
MyEnum3 |
|
71 |
}; |
|
72 |
||
73 |
enum MyFlag { |
|
74 |
MyFlag1 = 0x01, |
|
75 |
MyFlag2 = 0x02, |
|
76 |
MyFlag3 = 0x04 |
|
77 |
}; |
|
78 |
Q_DECLARE_FLAGS(MyFlags, MyFlag) |
|
79 |
||
80 |
MyEnum myEnum() const { return m_enum; } |
|
81 |
void setMyEnum(MyEnum val) { m_enum = val; } |
|
82 |
||
83 |
MyFlags myFlags() const { return m_flags; } |
|
84 |
void setMyFlags(MyFlags val) { m_flags = val; } |
|
85 |
||
86 |
MyClass(QObject *parent = 0) |
|
87 |
: QObject(parent), |
|
88 |
m_enum(MyEnum1), |
|
89 |
m_flags(MyFlag1|MyFlag2) |
|
90 |
{ } |
|
91 |
private: |
|
92 |
MyEnum m_enum; |
|
93 |
MyFlags m_flags; |
|
94 |
}; |
|
95 |
Q_DECLARE_OPERATORS_FOR_FLAGS(MyClass::MyFlags) |
|
96 |
} |
|
97 |
||
98 |
||
99 |
class tst_QMetaObject : public QObject |
|
100 |
{ |
|
101 |
Q_OBJECT |
|
102 |
Q_ENUMS(EnumType) |
|
103 |
Q_PROPERTY(EnumType value WRITE setValue READ getValue) |
|
104 |
Q_PROPERTY(EnumType value2 WRITE set_value READ get_value) |
|
105 |
Q_PROPERTY(MyStruct value3 WRITE setVal3 READ val3) |
|
106 |
Q_PROPERTY(QList<QVariant> value4 WRITE setVal4 READ val4) |
|
107 |
Q_PROPERTY(QVariantList value5 WRITE setVal5 READ val5) |
|
108 |
Q_PROPERTY(int value6 READ value6 NOTIFY value6Changed) |
|
109 |
Q_PROPERTY(MyStruct value7 READ value7 WRITE setVal7 NOTIFY value7Changed) |
|
110 |
Q_PROPERTY(int value8 READ value8 NOTIFY value8Changed) |
|
111 |
Q_PROPERTY(int value9 READ value9 CONSTANT) |
|
112 |
Q_PROPERTY(int value10 READ value10 FINAL) |
|
113 |
||
114 |
public: |
|
115 |
enum EnumType { EnumType1 }; |
|
116 |
||
117 |
tst_QMetaObject(); |
|
118 |
~tst_QMetaObject(); |
|
119 |
||
120 |
void setValue(EnumType) {} |
|
121 |
EnumType getValue() const { return EnumType1; } |
|
122 |
||
123 |
void set_value(EnumType) {} |
|
124 |
EnumType get_value() const { return EnumType1; } |
|
125 |
||
126 |
void setVal3(MyStruct) {} |
|
127 |
MyStruct val3() const { MyStruct s = {42}; return s; } |
|
128 |
||
129 |
void setVal4(const QList<QVariant> &list) { value4 = list; } |
|
130 |
QList<QVariant> val4() const { return value4; } |
|
131 |
||
132 |
void setVal5(const QVariantList &list) { value5 = list; } |
|
133 |
QVariantList val5() const { return value5; } |
|
134 |
||
135 |
int value6() const { return 1; } |
|
136 |
||
137 |
void setVal7(MyStruct) {} |
|
138 |
MyStruct value7() const { MyStruct s = {42}; return s; } |
|
139 |
||
140 |
int value8() const { return 1; } |
|
141 |
||
142 |
int value9() const { return 1; } |
|
143 |
||
144 |
int value10() const { return 1; } |
|
145 |
||
146 |
QList<QVariant> value4; |
|
147 |
QVariantList value5; |
|
148 |
||
149 |
public slots: |
|
150 |
void initTestCase(); |
|
151 |
void cleanupTestCase(); |
|
152 |
void init(); |
|
153 |
void cleanup(); |
|
154 |
private slots: |
|
155 |
void connectSlotsByName(); |
|
156 |
void invokeMetaMember(); |
|
157 |
void invokeQueuedMetaMember(); |
|
158 |
void invokeCustomTypes(); |
|
159 |
void invokeMetaConstructor(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
160 |
void invokeTypedefTypes(); |
0 | 161 |
void qtMetaObjectInheritance(); |
162 |
void normalizedSignature_data(); |
|
163 |
void normalizedSignature(); |
|
164 |
void normalizedType_data(); |
|
165 |
void normalizedType(); |
|
166 |
void customPropertyType(); |
|
167 |
void checkScope(); |
|
168 |
void propertyNotify(); |
|
169 |
void propertyConstant(); |
|
170 |
void propertyFinal(); |
|
171 |
||
172 |
void stdSet(); |
|
173 |
void classInfo(); |
|
174 |
||
175 |
signals: |
|
176 |
void value6Changed(); |
|
177 |
void value7Changed(const QString &); |
|
178 |
}; |
|
179 |
||
180 |
tst_QMetaObject::tst_QMetaObject() |
|
181 |
{ |
|
182 |
||
183 |
} |
|
184 |
||
185 |
tst_QMetaObject::~tst_QMetaObject() |
|
186 |
{ |
|
187 |
||
188 |
} |
|
189 |
||
190 |
void tst_QMetaObject::initTestCase() |
|
191 |
{ |
|
192 |
} |
|
193 |
||
194 |
void tst_QMetaObject::cleanupTestCase() |
|
195 |
{ |
|
196 |
} |
|
197 |
||
198 |
void tst_QMetaObject::init() |
|
199 |
{ |
|
200 |
} |
|
201 |
||
202 |
void tst_QMetaObject::cleanup() |
|
203 |
{ |
|
204 |
} |
|
205 |
||
206 |
void tst_QMetaObject::stdSet() |
|
207 |
{ |
|
208 |
const QMetaObject *mo = metaObject(); |
|
209 |
||
210 |
QMetaProperty prop = mo->property(mo->indexOfProperty("value")); |
|
211 |
QVERIFY(prop.isValid()); |
|
212 |
QVERIFY(prop.hasStdCppSet()); |
|
213 |
||
214 |
prop = mo->property(mo->indexOfProperty("value2")); |
|
215 |
QVERIFY(prop.isValid()); |
|
216 |
QVERIFY(!prop.hasStdCppSet()); |
|
217 |
} |
|
218 |
||
219 |
class CTestObject: public QObject |
|
220 |
{ |
|
221 |
Q_OBJECT |
|
222 |
||
223 |
public: |
|
224 |
CTestObject(): QObject(), invokeCount1(0), invokeCount2(0) |
|
225 |
{ |
|
226 |
} |
|
227 |
||
228 |
void fire(const QString &name) |
|
229 |
{ |
|
230 |
child = new QObject(this); |
|
231 |
child->setObjectName(name); |
|
232 |
QMetaObject::connectSlotsByName(this); |
|
233 |
delete child; child = 0; |
|
234 |
} |
|
235 |
||
236 |
int invokeCount1; |
|
237 |
int invokeCount2; |
|
238 |
QObject *child; |
|
239 |
||
240 |
public slots: |
|
241 |
void on_child1_destroyed(QObject *obj = 0) { ++invokeCount1; Q_ASSERT(obj && obj == child); } |
|
242 |
void on_child2_destroyed() { ++invokeCount2; } |
|
243 |
}; |
|
244 |
||
245 |
class CTestObjectOverloads: public QObject |
|
246 |
{ |
|
247 |
Q_OBJECT |
|
248 |
||
249 |
public: |
|
250 |
CTestObjectOverloads(): invokeCount1(0), invokeCount2(0) {} |
|
251 |
||
252 |
int invokeCount1; |
|
253 |
int invokeCount2; |
|
254 |
QObject *child; |
|
255 |
||
256 |
void fire(const QString &name) |
|
257 |
{ |
|
258 |
child = new QObject(this); |
|
259 |
child->setObjectName(name); |
|
260 |
QMetaObject::connectSlotsByName(this); |
|
261 |
delete child; child = 0; |
|
262 |
} |
|
263 |
||
264 |
private slots: |
|
265 |
void on_child1_destroyed(QObject *obj) { ++invokeCount1; Q_ASSERT(obj && obj == child); } |
|
266 |
void on_child1_destroyed() { ++invokeCount2; } |
|
267 |
}; |
|
268 |
||
269 |
#define FUNCTION(x) "QMetaObject::" x ": " |
|
270 |
||
271 |
void tst_QMetaObject::connectSlotsByName() |
|
272 |
{ |
|
273 |
CTestObject obj; |
|
274 |
QCOMPARE(obj.invokeCount1, 0); |
|
275 |
QCOMPARE(obj.invokeCount2, 0); |
|
276 |
||
277 |
QTest::ignoreMessage(QtWarningMsg, FUNCTION("connectSlotsByName") "No matching signal for on_child1_destroyed(QObject*)"); |
|
278 |
QTest::ignoreMessage(QtWarningMsg, FUNCTION("connectSlotsByName") "No matching signal for on_child2_destroyed()"); |
|
279 |
obj.fire("bubu"); |
|
280 |
QCOMPARE(obj.invokeCount1, 0); |
|
281 |
QCOMPARE(obj.invokeCount2, 0); |
|
282 |
||
283 |
QTest::ignoreMessage(QtWarningMsg, FUNCTION("connectSlotsByName") "No matching signal for on_child2_destroyed()"); |
|
284 |
obj.fire("child1"); |
|
285 |
QCOMPARE(obj.invokeCount1, 1); |
|
286 |
QCOMPARE(obj.invokeCount2, 0); |
|
287 |
||
288 |
QTest::ignoreMessage(QtWarningMsg, FUNCTION("connectSlotsByName") "No matching signal for on_child1_destroyed(QObject*)"); |
|
289 |
obj.fire("child2"); |
|
290 |
QCOMPARE(obj.invokeCount1, 1); |
|
291 |
QCOMPARE(obj.invokeCount2, 1); |
|
292 |
||
293 |
QTest::ignoreMessage(QtWarningMsg, FUNCTION("connectSlotsByName") "No matching signal for on_child2_destroyed()"); |
|
294 |
obj.fire("child1"); |
|
295 |
QCOMPARE(obj.invokeCount1, 2); |
|
296 |
QCOMPARE(obj.invokeCount2, 1); |
|
297 |
||
298 |
// now test with real overloads |
|
299 |
CTestObjectOverloads obj2; |
|
300 |
obj2.fire("child1"); |
|
301 |
QCOMPARE(obj2.invokeCount1, 1); |
|
302 |
QCOMPARE(obj2.invokeCount2, 1); |
|
303 |
} |
|
304 |
||
305 |
class QtTestObject: public QObject |
|
306 |
{ |
|
307 |
Q_OBJECT |
|
308 |
||
309 |
public: |
|
310 |
QtTestObject(); |
|
311 |
Q_INVOKABLE QtTestObject(QObject *parent); |
|
312 |
||
313 |
public slots: |
|
314 |
void sl0(); |
|
315 |
QString sl1(QString s1); |
|
316 |
void sl2(QString s1, QString s2); |
|
317 |
void sl3(QString s1, QString s2, QString s3); |
|
318 |
void sl4(QString s1, QString s2, QString s3, const QString s4); |
|
319 |
void sl5(QString s1, QString s2, QString s3, QString s4, const QString &s5); |
|
320 |
void sl6(QString s1, QString s2, QString s3, QString s4, const QString s5, QString s6); |
|
321 |
void sl7(QString s1, QString s2, QString s3, QString s4, QString s5, QString s6, QString s7); |
|
322 |
void sl8(QString s1, QString s2, QString s3, QString s4, QString s5, QString s6, QString s7, |
|
323 |
QString s8); |
|
324 |
void sl9(QString s1, QString s2, QString s3, QString s4, QString s5, QString s6, QString s7, |
|
325 |
QString s8, QString s9); |
|
326 |
void sl10(QString s1, QString s2, QString s3, QString s4, QString s5, QString s6, QString s7, |
|
327 |
QString s8, QString s9, QString s10); |
|
328 |
QObject *sl11(); |
|
329 |
const char *sl12(); |
|
330 |
QList<QString> sl13(QList<QString> l1); |
|
331 |
void testSender(); |
|
332 |
||
333 |
void testReference(QString &str); |
|
334 |
||
335 |
void testLongLong(qint64 ll1, quint64 ll2); |
|
336 |
||
337 |
signals: |
|
338 |
void sig0(); |
|
339 |
QString sig1(QString s1); |
|
340 |
||
341 |
protected: |
|
342 |
QtTestObject(QVariant) {} |
|
343 |
private: |
|
344 |
QtTestObject(QVariant, QVariant) {} |
|
345 |
||
346 |
public: |
|
347 |
QString slotResult; |
|
348 |
}; |
|
349 |
||
350 |
QtTestObject::QtTestObject() |
|
351 |
{ |
|
352 |
connect(this, SIGNAL(sig0()), this, SLOT(sl0())); |
|
353 |
connect(this, SIGNAL(sig1(QString)), this, SLOT(sl1(QString))); |
|
354 |
} |
|
355 |
||
356 |
QtTestObject::QtTestObject(QObject *parent) |
|
357 |
: QObject(parent) |
|
358 |
{ |
|
359 |
} |
|
360 |
||
361 |
void QtTestObject::sl0() { slotResult = "sl0"; }; |
|
362 |
QString QtTestObject::sl1(QString s1) { slotResult = "sl1:" + s1; return "yessir"; } |
|
363 |
void QtTestObject::sl2(QString s1, QString s2) { slotResult = "sl2:" + s1 + s2; } |
|
364 |
void QtTestObject::sl3(QString s1, QString s2, QString s3) |
|
365 |
{ slotResult = "sl3:" + s1 + s2 + s3; } |
|
366 |
void QtTestObject::sl4(QString s1, QString s2, QString s3, const QString s4) |
|
367 |
{ slotResult = "sl4:" + s1 + s2 + s3 + s4; } |
|
368 |
void QtTestObject::sl5(QString s1, QString s2, QString s3, QString s4, const QString &s5) |
|
369 |
{ slotResult = "sl5:" + s1 + s2 + s3 + s4 + s5; } |
|
370 |
void QtTestObject::sl6(QString s1, QString s2, QString s3, QString s4, |
|
371 |
const QString s5, QString s6) |
|
372 |
{ slotResult = "sl6:" + s1 + s2 + s3 + s4 + s5 + s6; } |
|
373 |
void QtTestObject::sl7(QString s1, QString s2, QString s3, QString s4, QString s5, |
|
374 |
QString s6, QString s7) |
|
375 |
{ slotResult = "sl7:" + s1 + s2 + s3 + s4 + s5 + s6 + s7; } |
|
376 |
void QtTestObject::sl8(QString s1, QString s2, QString s3, QString s4, QString s5, |
|
377 |
QString s6, QString s7, QString s8) |
|
378 |
{ slotResult = "sl8:" + s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8; } |
|
379 |
void QtTestObject::sl9(QString s1, QString s2, QString s3, QString s4, QString s5, |
|
380 |
QString s6, QString s7, QString s8, QString s9) |
|
381 |
{ slotResult = "sl9:" + s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9; } |
|
382 |
void QtTestObject::sl10(QString s1, QString s2, QString s3, QString s4, QString s5, |
|
383 |
QString s6, QString s7, QString s8, QString s9, QString s10) |
|
384 |
{ slotResult = "sl10:" + s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10; } |
|
385 |
QObject *QtTestObject::sl11() |
|
386 |
{ slotResult = "sl11"; return this; } |
|
387 |
const char *QtTestObject::sl12() |
|
388 |
{ slotResult = "sl12"; return "foo"; } |
|
389 |
QList<QString> QtTestObject::sl13(QList<QString> l1) |
|
390 |
{ slotResult = "sl13"; return l1; } |
|
391 |
void QtTestObject::testReference(QString &str) |
|
392 |
{ slotResult = "testReference:" + str; str = "gotcha"; } |
|
393 |
||
394 |
void QtTestObject::testLongLong(qint64 ll1, quint64 ll2) |
|
395 |
{ slotResult = "testLongLong:" + QString::number(ll1) + "," + QString::number(ll2); } |
|
396 |
||
397 |
void QtTestObject::testSender() |
|
398 |
{ |
|
399 |
slotResult.sprintf("%p", sender()); |
|
400 |
} |
|
401 |
||
402 |
||
403 |
void tst_QMetaObject::invokeMetaMember() |
|
404 |
{ |
|
405 |
QtTestObject obj; |
|
406 |
||
407 |
QString t1("1"); QString t2("2"); QString t3("3"); QString t4("4"); QString t5("5"); |
|
408 |
QString t6("6"); QString t7("7"); QString t8("8"); QString t9("9"); QString t10("X"); |
|
409 |
||
410 |
QVERIFY(!QMetaObject::invokeMethod(0, 0)); |
|
411 |
QVERIFY(!QMetaObject::invokeMethod(0, "sl0")); |
|
412 |
QVERIFY(!QMetaObject::invokeMethod(&obj, 0)); |
|
413 |
||
414 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl0")); |
|
415 |
QCOMPARE(obj.slotResult, QString("sl0")); |
|
416 |
||
417 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl1", Q_ARG(QString, t1))); |
|
418 |
QCOMPARE(obj.slotResult, QString("sl1:1")); |
|
419 |
||
420 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl2", Q_ARG(const QString, t1), Q_ARG(QString, t2))); |
|
421 |
QCOMPARE(obj.slotResult, QString("sl2:12")); |
|
422 |
||
423 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl3", Q_ARG(QString, t1), Q_ARG(QString, t2), Q_ARG(QString, t3))); |
|
424 |
QCOMPARE(obj.slotResult, QString("sl3:123")); |
|
425 |
||
426 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl4", Q_ARG(QString, t1), Q_ARG(QString, t2), Q_ARG(QString, t3), |
|
427 |
Q_ARG(QString, t4))); |
|
428 |
QCOMPARE(obj.slotResult, QString("sl4:1234")); |
|
429 |
||
430 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl5", Q_ARG(QString, t1), Q_ARG(QString, t2), Q_ARG(QString, t3), |
|
431 |
Q_ARG(QString, t4), Q_ARG(QString, "5"))); |
|
432 |
QCOMPARE(obj.slotResult, QString("sl5:12345")); |
|
433 |
||
434 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl6", Q_ARG(QString, t1), Q_ARG(QString, t2), Q_ARG(QString, t3), |
|
435 |
Q_ARG(QString, t4), Q_ARG(QString, t5), Q_ARG(QString, t6))); |
|
436 |
QCOMPARE(obj.slotResult, QString("sl6:123456")); |
|
437 |
||
438 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl7", Q_ARG(QString, t1), Q_ARG(QString, t2), Q_ARG(QString, t3), |
|
439 |
Q_ARG(QString, t4), Q_ARG(QString, t5), Q_ARG(QString, t6), |
|
440 |
Q_ARG(QString, t7))); |
|
441 |
QCOMPARE(obj.slotResult, QString("sl7:1234567")); |
|
442 |
||
443 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl8", Q_ARG(QString, t1), Q_ARG(QString, t2), Q_ARG(QString, t3), |
|
444 |
Q_ARG(QString, t4), Q_ARG(QString, t5), Q_ARG(QString, t6), |
|
445 |
Q_ARG(QString, t7), Q_ARG(QString, t8))); |
|
446 |
QCOMPARE(obj.slotResult, QString("sl8:12345678")); |
|
447 |
||
448 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl9", Q_ARG(QString, t1), Q_ARG(QString, t2), Q_ARG(QString, t3), |
|
449 |
Q_ARG(QString, t4), Q_ARG(QString, t5), Q_ARG(QString, t6), |
|
450 |
Q_ARG(QString, t7), Q_ARG(QString, t8), Q_ARG(QString, t9))); |
|
451 |
QCOMPARE(obj.slotResult, QString("sl9:123456789")); |
|
452 |
||
453 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl11")); |
|
454 |
QCOMPARE(obj.slotResult, QString("sl11")); |
|
455 |
||
456 |
QVERIFY(QMetaObject::invokeMethod(&obj, "testSender")); |
|
457 |
QCOMPARE(obj.slotResult, QString("0x0")); |
|
458 |
||
459 |
QString refStr("whatever"); |
|
460 |
QVERIFY(QMetaObject::invokeMethod(&obj, "testReference", QGenericArgument("QString&", &refStr))); |
|
461 |
QCOMPARE(obj.slotResult, QString("testReference:whatever")); |
|
462 |
QCOMPARE(refStr, QString("gotcha")); |
|
463 |
||
464 |
qint64 ll1 = -1; |
|
465 |
quint64 ll2 = 0; |
|
466 |
QVERIFY(QMetaObject::invokeMethod(&obj, |
|
467 |
"testLongLong", |
|
468 |
Q_ARG(qint64, ll1), |
|
469 |
Q_ARG(quint64, ll2))); |
|
470 |
QCOMPARE(obj.slotResult, QString("testLongLong:-1,0")); |
|
471 |
||
472 |
QString exp; |
|
473 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl1", Q_RETURN_ARG(QString, exp), Q_ARG(QString, "bubu"))); |
|
474 |
QCOMPARE(exp, QString("yessir")); |
|
475 |
QCOMPARE(obj.slotResult, QString("sl1:bubu")); |
|
476 |
||
477 |
QObject *ptr = 0; |
|
478 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl11", Q_RETURN_ARG(QObject*,ptr))); |
|
479 |
QCOMPARE(ptr, (QObject *)&obj); |
|
480 |
QCOMPARE(obj.slotResult, QString("sl11")); |
|
481 |
// try again with a space: |
|
482 |
ptr = 0; |
|
483 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl11", Q_RETURN_ARG(QObject * , ptr))); |
|
484 |
QCOMPARE(ptr, (QObject *)&obj); |
|
485 |
QCOMPARE(obj.slotResult, QString("sl11")); |
|
486 |
||
487 |
const char *ptr2 = 0; |
|
488 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl12", Q_RETURN_ARG(const char*, ptr2))); |
|
489 |
QVERIFY(ptr2 != 0); |
|
490 |
QCOMPARE(obj.slotResult, QString("sl12")); |
|
491 |
// try again with a space: |
|
492 |
ptr2 = 0; |
|
493 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl12", Q_RETURN_ARG(char const * , ptr2))); |
|
494 |
QVERIFY(ptr2 != 0); |
|
495 |
QCOMPARE(obj.slotResult, QString("sl12")); |
|
496 |
||
497 |
// test w/ template args |
|
498 |
QList<QString> returnValue, argument; |
|
499 |
argument << QString("one") << QString("two") << QString("three"); |
|
500 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl13", |
|
501 |
Q_RETURN_ARG(QList<QString>, returnValue), |
|
502 |
Q_ARG(QList<QString>, argument))); |
|
503 |
QCOMPARE(returnValue, argument); |
|
504 |
QCOMPARE(obj.slotResult, QString("sl13")); |
|
505 |
||
506 |
//test signals |
|
507 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sig0")); |
|
508 |
QCOMPARE(obj.slotResult, QString("sl0")); |
|
509 |
||
510 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sig1", Q_ARG(QString, "baba"))); |
|
511 |
QCOMPARE(obj.slotResult, QString("sl1:baba")); |
|
512 |
||
513 |
exp.clear(); |
|
514 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sig1", Q_RETURN_ARG(QString, exp), Q_ARG(QString, "hehe"))); |
|
515 |
QCOMPARE(exp, QString("yessir")); |
|
516 |
QCOMPARE(obj.slotResult, QString("sl1:hehe")); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
517 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
518 |
QTest::ignoreMessage(QtWarningMsg, "QMetaObject::invokeMethod: No such method QtTestObject::doesNotExist()"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
519 |
QVERIFY(!QMetaObject::invokeMethod(&obj, "doesNotExist")); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
520 |
QTest::ignoreMessage(QtWarningMsg, "QMetaObject::invokeMethod: No such method QtTestObject::sl1(QString)(QString)"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
521 |
QVERIFY(!QMetaObject::invokeMethod(&obj, "sl1(QString)", Q_ARG(QString, "arg"))); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
522 |
QTest::ignoreMessage(QtWarningMsg, "QMetaObject::invokeMethod: No such method QtTestObject::sl3(QString)"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
523 |
QVERIFY(!QMetaObject::invokeMethod(&obj, "sl3", Q_ARG(QString, "arg"))); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
524 |
QTest::ignoreMessage(QtWarningMsg, "QMetaObject::invokeMethod: No such method QtTestObject::sl1(QString,QString,QString)"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
525 |
QVERIFY(!QMetaObject::invokeMethod(&obj, "sl1", Q_ARG(QString, "arg"), Q_ARG(QString, "arg"), Q_ARG(QString, "arg"))); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
526 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
527 |
//should not have changed since last test. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
528 |
QCOMPARE(exp, QString("yessir")); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
529 |
QCOMPARE(obj.slotResult, QString("sl1:hehe")); |
0 | 530 |
} |
531 |
||
532 |
void tst_QMetaObject::invokeQueuedMetaMember() |
|
533 |
{ |
|
534 |
QtTestObject obj; |
|
535 |
||
536 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl0", Qt::QueuedConnection)); |
|
537 |
QVERIFY(obj.slotResult.isEmpty()); |
|
538 |
qApp->processEvents(QEventLoop::AllEvents); |
|
539 |
QCOMPARE(obj.slotResult, QString("sl0")); |
|
540 |
obj.slotResult = QString(); |
|
541 |
||
542 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl1", Qt::QueuedConnection, Q_ARG(QString, QString("hallo")))); |
|
543 |
QVERIFY(obj.slotResult.isEmpty()); |
|
544 |
qApp->processEvents(QEventLoop::AllEvents); |
|
545 |
QCOMPARE(obj.slotResult, QString("sl1:hallo")); |
|
546 |
obj.slotResult = QString(); |
|
547 |
||
548 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl9", Qt::QueuedConnection, Q_ARG(QString, "1"), Q_ARG(QString, "2"), |
|
549 |
Q_ARG(QString, "3"), Q_ARG(QString, "4"), Q_ARG(QString, "5"), |
|
550 |
Q_ARG(QString, "6"), Q_ARG(QString, "7"), Q_ARG(QString, "8"), |
|
551 |
Q_ARG(QString, "9"))); |
|
552 |
QVERIFY(obj.slotResult.isEmpty()); |
|
553 |
qApp->processEvents(QEventLoop::AllEvents); |
|
554 |
QCOMPARE(obj.slotResult, QString("sl9:123456789")); |
|
555 |
||
556 |
// signals |
|
557 |
||
558 |
obj.slotResult.clear(); |
|
559 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sig0", Qt::QueuedConnection)); |
|
560 |
QVERIFY(obj.slotResult.isEmpty()); |
|
561 |
qApp->processEvents(QEventLoop::AllEvents); |
|
562 |
QCOMPARE(obj.slotResult, QString("sl0")); |
|
563 |
||
564 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sig1", Qt::QueuedConnection, Q_ARG(QString, "gogo"))); |
|
565 |
qApp->processEvents(QEventLoop::AllEvents); |
|
566 |
QCOMPARE(obj.slotResult, QString("sl1:gogo")); |
|
567 |
||
568 |
QString exp; |
|
569 |
QTest::ignoreMessage(QtWarningMsg, "QMetaMethod::invoke: Unable to invoke methods with return values in queued connections"); |
|
570 |
QVERIFY(!QMetaObject::invokeMethod(&obj, "sig1", Qt::QueuedConnection, Q_RETURN_ARG(QString, exp), |
|
571 |
Q_ARG(QString, "nono"))); |
|
572 |
||
573 |
qint64 ll1 = -1; |
|
574 |
quint64 ll2 = 0; |
|
575 |
QVERIFY(QMetaObject::invokeMethod(&obj, |
|
576 |
"testLongLong", |
|
577 |
Qt::QueuedConnection, |
|
578 |
Q_ARG(qint64, ll1), |
|
579 |
Q_ARG(quint64, ll2))); |
|
580 |
qApp->processEvents(QEventLoop::AllEvents); |
|
581 |
QCOMPARE(obj.slotResult, QString("testLongLong:-1,0")); |
|
582 |
} |
|
583 |
||
584 |
||
585 |
void tst_QMetaObject::qtMetaObjectInheritance() |
|
586 |
{ |
|
587 |
QVERIFY(QObject::staticMetaObject.superClass() == 0); |
|
588 |
QCOMPARE(QLabel::staticMetaObject.indexOfEnumerator("Qt::Alignment"), -1); |
|
589 |
QCOMPARE(QLabel::staticMetaObject.indexOfEnumerator("Alignment"), -1); |
|
590 |
int indexOfAlignment = QLabel::staticMetaObject.indexOfProperty("alignment"); |
|
591 |
QVERIFY(indexOfAlignment != -1); |
|
592 |
QMetaProperty alignment = QLabel::staticMetaObject.property(indexOfAlignment); |
|
593 |
QVERIFY(alignment.isValid()); |
|
594 |
QCOMPARE(alignment.enumerator().name(), "Alignment"); |
|
595 |
} |
|
596 |
||
597 |
struct MyType |
|
598 |
{ |
|
599 |
int i1, i2, i3; |
|
600 |
}; |
|
601 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
602 |
typedef QString CustomString; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
603 |
|
0 | 604 |
class QtTestCustomObject: public QObject |
605 |
{ |
|
606 |
Q_OBJECT |
|
607 |
public: |
|
608 |
QtTestCustomObject(): QObject(), sum(0) {} |
|
609 |
||
610 |
public slots: |
|
611 |
void sl1(MyType myType); |
|
612 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
613 |
signals: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
614 |
void sig_custom(const CustomString &string); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
615 |
|
0 | 616 |
public: |
617 |
int sum; |
|
618 |
}; |
|
619 |
||
620 |
void QtTestCustomObject::sl1(MyType myType) |
|
621 |
{ |
|
622 |
sum = myType.i1 + myType.i2 + myType.i3; |
|
623 |
} |
|
624 |
||
625 |
void tst_QMetaObject::invokeCustomTypes() |
|
626 |
{ |
|
627 |
QtTestCustomObject obj; |
|
628 |
MyType tp = {1, 1, 1}; |
|
629 |
||
630 |
QCOMPARE(obj.sum, 0); |
|
631 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sl1", Q_ARG(MyType, tp))); |
|
632 |
QCOMPARE(obj.sum, 3); |
|
633 |
} |
|
634 |
||
635 |
namespace NamespaceWithConstructibleClass |
|
636 |
{ |
|
637 |
||
638 |
class ConstructibleClass : public QObject |
|
639 |
{ |
|
640 |
Q_OBJECT |
|
641 |
public: |
|
642 |
Q_INVOKABLE ConstructibleClass(QObject *parent = 0) |
|
643 |
: QObject(parent) {} |
|
644 |
}; |
|
645 |
||
646 |
} |
|
647 |
||
648 |
void tst_QMetaObject::invokeMetaConstructor() |
|
649 |
{ |
|
650 |
const QMetaObject *mo = &QtTestObject::staticMetaObject; |
|
651 |
{ |
|
652 |
QObject *obj = mo->newInstance(); |
|
653 |
QVERIFY(obj == 0); |
|
654 |
} |
|
655 |
{ |
|
656 |
QtTestObject obj; |
|
657 |
QObject *obj2 = mo->newInstance(Q_ARG(QObject*, &obj)); |
|
658 |
QVERIFY(obj2 != 0); |
|
659 |
QCOMPARE(obj2->parent(), (QObject*)&obj); |
|
660 |
QVERIFY(qobject_cast<QtTestObject*>(obj2) != 0); |
|
661 |
} |
|
662 |
// class in namespace |
|
663 |
const QMetaObject *nsmo = &NamespaceWithConstructibleClass::ConstructibleClass::staticMetaObject; |
|
664 |
{ |
|
665 |
QtTestObject obj; |
|
666 |
QObject *obj2 = nsmo->newInstance(Q_ARG(QObject*, &obj)); |
|
667 |
QVERIFY(obj2 != 0); |
|
668 |
QCOMPARE(obj2->parent(), (QObject*)&obj); |
|
669 |
QVERIFY(qobject_cast<NamespaceWithConstructibleClass::ConstructibleClass*>(obj2) != 0); |
|
670 |
} |
|
671 |
} |
|
672 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
673 |
void tst_QMetaObject::invokeTypedefTypes() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
674 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
675 |
qRegisterMetaType<CustomString>("CustomString"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
676 |
QtTestCustomObject obj; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
677 |
QSignalSpy spy(&obj, SIGNAL(sig_custom(CustomString))); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
678 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
679 |
QCOMPARE(spy.count(), 0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
680 |
CustomString arg("hello"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
681 |
QVERIFY(QMetaObject::invokeMethod(&obj, "sig_custom", Q_ARG(CustomString, arg))); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
682 |
QCOMPARE(spy.count(), 1); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
683 |
QCOMPARE(spy.at(0).count(), 1); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
684 |
QCOMPARE(spy.at(0).at(0), QVariant(arg)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
685 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
686 |
|
0 | 687 |
void tst_QMetaObject::normalizedSignature_data() |
688 |
{ |
|
689 |
QTest::addColumn<QString>("signature"); |
|
690 |
QTest::addColumn<QString>("result"); |
|
691 |
||
692 |
QTest::newRow("function") << "void foo()" << "void foo()"; |
|
693 |
QTest::newRow("spaces") << " void foo( ) " << "void foo()"; |
|
694 |
QTest::newRow("template args") << " void foo( QMap<a, a>, QList<b>) " |
|
695 |
<< "void foo(QMap<a,a>,QList<b>)"; |
|
696 |
QTest::newRow("rettype") << "QList<int, int> foo()" << "QList<int,int>foo()"; |
|
697 |
QTest::newRow("const rettype") << "const QString *foo()" << "const QString*foo()"; |
|
698 |
QTest::newRow("const ref") << "const QString &foo()" << "const QString&foo()"; |
|
699 |
QTest::newRow("reference") << "QString &foo()" << "QString&foo()"; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
700 |
QTest::newRow("const1") << "void foo(QString const *)" << "void foo(const QString*)"; |
0 | 701 |
QTest::newRow("const2") << "void foo(QString * const)" << "void foo(QString*const)"; |
702 |
QTest::newRow("const3") << "void foo(QString const &)" << "void foo(QString)"; |
|
703 |
QTest::newRow("const4") << "void foo(const int)" << "void foo(int)"; |
|
704 |
QTest::newRow("const5") << "void foo(const int, int const, const int &, int const &)" |
|
705 |
<< "void foo(int,int,int,int)"; |
|
706 |
QTest::newRow("const6") << "void foo(QList<const int>)" << "void foo(QList<const int>)"; |
|
707 |
QTest::newRow("const7") << "void foo(QList<const int*>)" << "void foo(QList<const int*>)"; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
708 |
QTest::newRow("const8") << "void foo(QList<int const*>)" << "void foo(QList<const int*>)"; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
709 |
QTest::newRow("const9") << "void foo(const Foo<Bar>)" << "void foo(Foo<Bar>)"; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
710 |
QTest::newRow("const10") << "void foo(Foo<Bar>const)" << "void foo(Foo<Bar>)"; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
711 |
QTest::newRow("const11") << "void foo(Foo<Bar> *const)" << "void foo(Foo<Bar>*const)"; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
712 |
QTest::newRow("const12") << "void foo(Foo<Bar>const*const *const)" << "void foo(Foo<Bar>*const*const)"; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
713 |
QTest::newRow("const13") << "void foo(const Foo<Bar>&)" << "void foo(Foo<Bar>)"; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
714 |
QTest::newRow("const14") << "void foo(Foo<Bar>const&)" << "void foo(Foo<Bar>)"; |
0 | 715 |
} |
716 |
||
717 |
void tst_QMetaObject::normalizedSignature() |
|
718 |
{ |
|
719 |
QFETCH(QString, signature); |
|
720 |
QFETCH(QString, result); |
|
721 |
||
722 |
QCOMPARE(QString::fromLatin1(QMetaObject::normalizedSignature(signature.toLatin1())), result); |
|
723 |
} |
|
724 |
||
725 |
void tst_QMetaObject::normalizedType_data() |
|
726 |
{ |
|
727 |
QTest::addColumn<QString>("type"); |
|
728 |
QTest::addColumn<QString>("result"); |
|
729 |
||
730 |
QTest::newRow("simple") << "int" << "int"; |
|
731 |
QTest::newRow("white") << " int " << "int"; |
|
732 |
QTest::newRow("const1") << "int const *" << "const int*"; |
|
733 |
QTest::newRow("const2") << "const int *" << "const int*"; |
|
734 |
QTest::newRow("template1") << "QList<int const *>" << "QList<const int*>"; |
|
735 |
QTest::newRow("template2") << "QList<const int *>" << "QList<const int*>"; |
|
736 |
QTest::newRow("template3") << "QMap<QString, int>" << "QMap<QString,int>"; |
|
737 |
QTest::newRow("template4") << "const QMap<QString, int> &" << "QMap<QString,int>"; |
|
738 |
QTest::newRow("template5") << "QList< ::Foo::Bar>" << "QList< ::Foo::Bar>"; |
|
739 |
QTest::newRow("template6") << "QList<::Foo::Bar>" << "QList<::Foo::Bar>"; |
|
740 |
QTest::newRow("template7") << "QList<QList<int> >" << "QList<QList<int> >"; |
|
741 |
QTest::newRow("value1") << "const QString &" << "QString"; |
|
742 |
QTest::newRow("value2") << "QString const &" << "QString"; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
743 |
QTest::newRow("constInName1") << "constconst" << "constconst"; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
744 |
QTest::newRow("constInName2") << "constconst*" << "constconst*"; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
745 |
QTest::newRow("constInName3") << "const constconst&" << "constconst"; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
746 |
QTest::newRow("constInName4") << "constconst const*const" << "constconst*const"; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
747 |
QTest::newRow("class") << "const class foo&" << "foo"; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
748 |
QTest::newRow("struct") << "const struct foo*" << "const foo*"; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
749 |
QTest::newRow("struct2") << "struct foo const*" << "const foo*"; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
750 |
QTest::newRow("enum") << "enum foo" << "foo"; |
0 | 751 |
} |
752 |
||
753 |
void tst_QMetaObject::normalizedType() |
|
754 |
{ |
|
755 |
QFETCH(QString, type); |
|
756 |
QFETCH(QString, result); |
|
757 |
||
758 |
QCOMPARE(QString::fromLatin1(QMetaObject::normalizedType(type.toLatin1())), result); |
|
759 |
} |
|
760 |
||
761 |
void tst_QMetaObject::customPropertyType() |
|
762 |
{ |
|
763 |
QMetaProperty prop = metaObject()->property(metaObject()->indexOfProperty("value3")); |
|
764 |
||
765 |
QCOMPARE(prop.type(), QVariant::UserType); |
|
766 |
QCOMPARE(prop.userType(), 0); |
|
767 |
||
768 |
qRegisterMetaType<MyStruct>("MyStruct"); |
|
769 |
QCOMPARE(prop.userType(), QMetaType::type("MyStruct")); |
|
770 |
||
771 |
prop = metaObject()->property(metaObject()->indexOfProperty("value4")); |
|
772 |
QCOMPARE(prop.type(), QVariant::List); |
|
773 |
||
774 |
prop = metaObject()->property(metaObject()->indexOfProperty("value5")); |
|
775 |
QCOMPARE(prop.type(), QVariant::List); |
|
776 |
} |
|
777 |
||
778 |
void tst_QMetaObject::checkScope() |
|
779 |
{ |
|
780 |
MyNamespace::MyClass obj; |
|
781 |
||
782 |
const QMetaObject *mo = obj.metaObject(); |
|
783 |
QMetaEnum me = mo->enumerator(mo->indexOfEnumerator("MyEnum")); |
|
784 |
QVERIFY(me.isValid()); |
|
785 |
QVERIFY(!me.isFlag()); |
|
786 |
QCOMPARE(QLatin1String(me.scope()), QLatin1String("MyNamespace::MyClass")); |
|
787 |
QCOMPARE(me.keyToValue("MyNamespace::MyClass::MyEnum2"), 1); |
|
788 |
QCOMPARE(me.keyToValue("MyClass::MyEnum2"), -1); |
|
789 |
QCOMPARE(me.keyToValue("MyNamespace::MyEnum2"), -1); |
|
790 |
QCOMPARE(me.keyToValue("MyEnum2"), 1); |
|
791 |
QCOMPARE(me.keyToValue("MyEnum"), -1); |
|
792 |
QCOMPARE(QLatin1String(me.valueToKey(1)), QLatin1String("MyEnum2")); |
|
793 |
||
794 |
QMetaEnum mf = mo->enumerator(mo->indexOfEnumerator("MyFlags")); |
|
795 |
QVERIFY(mf.isValid()); |
|
796 |
QVERIFY(mf.isFlag()); |
|
797 |
QCOMPARE(QLatin1String(mf.scope()), QLatin1String("MyNamespace::MyClass")); |
|
798 |
QCOMPARE(mf.keysToValue("MyNamespace::MyClass::MyFlag2"), 2); |
|
799 |
QCOMPARE(mf.keysToValue("MyClass::MyFlag2"), -1); |
|
800 |
QCOMPARE(mf.keysToValue("MyNamespace::MyFlag2"), -1); |
|
801 |
QCOMPARE(mf.keysToValue("MyFlag2"), 2); |
|
802 |
QCOMPARE(mf.keysToValue("MyFlag"), -1); |
|
803 |
QCOMPARE(QLatin1String(mf.valueToKey(2)), QLatin1String("MyFlag2")); |
|
804 |
QCOMPARE(mf.keysToValue("MyNamespace::MyClass::MyFlag1|MyNamespace::MyClass::MyFlag2"), 3); |
|
805 |
QCOMPARE(mf.keysToValue("MyClass::MyFlag1|MyClass::MyFlag2"), -1); |
|
806 |
QCOMPARE(mf.keysToValue("MyNamespace::MyFlag1|MyNamespace::MyFlag2"), -1); |
|
807 |
QCOMPARE(mf.keysToValue("MyFlag1|MyFlag2"), 3); |
|
808 |
QCOMPARE(mf.keysToValue("MyFlag2|MyFlag2"), 2); |
|
809 |
QCOMPARE(mf.keysToValue("MyFlag1|MyNamespace::MyClass::MyFlag2"), 3); |
|
810 |
QCOMPARE(mf.keysToValue("MyNamespace::MyClass::MyFlag2|MyNamespace::MyClass::MyFlag2"), 2); |
|
811 |
QCOMPARE(QLatin1String(mf.valueToKeys(3)), QLatin1String("MyFlag1|MyFlag2")); |
|
812 |
} |
|
813 |
||
814 |
void tst_QMetaObject::propertyNotify() |
|
815 |
{ |
|
816 |
const QMetaObject *mo = metaObject(); |
|
817 |
||
818 |
QMetaProperty prop = mo->property(mo->indexOfProperty("value6")); |
|
819 |
QVERIFY(prop.isValid()); |
|
820 |
QVERIFY(prop.hasNotifySignal()); |
|
821 |
QMetaMethod signal = prop.notifySignal(); |
|
822 |
QCOMPARE(signal.signature(), "value6Changed()"); |
|
823 |
||
824 |
prop = mo->property(mo->indexOfProperty("value7")); |
|
825 |
QVERIFY(prop.isValid()); |
|
826 |
QVERIFY(prop.hasNotifySignal()); |
|
827 |
signal = prop.notifySignal(); |
|
828 |
QCOMPARE(signal.signature(), "value7Changed(QString)"); |
|
829 |
||
830 |
prop = mo->property(mo->indexOfProperty("value8")); |
|
831 |
QVERIFY(prop.isValid()); |
|
832 |
QVERIFY(!prop.hasNotifySignal()); |
|
833 |
signal = prop.notifySignal(); |
|
834 |
QCOMPARE(signal.signature(), (const char *)0); |
|
835 |
||
836 |
prop = mo->property(mo->indexOfProperty("value")); |
|
837 |
QVERIFY(prop.isValid()); |
|
838 |
QVERIFY(!prop.hasNotifySignal()); |
|
839 |
signal = prop.notifySignal(); |
|
840 |
QCOMPARE(signal.signature(), (const char *)0); |
|
841 |
} |
|
842 |
||
843 |
void tst_QMetaObject::propertyConstant() |
|
844 |
{ |
|
845 |
const QMetaObject *mo = metaObject(); |
|
846 |
||
847 |
QMetaProperty prop = mo->property(mo->indexOfProperty("value8")); |
|
848 |
QVERIFY(prop.isValid()); |
|
849 |
QVERIFY(!prop.isConstant()); |
|
850 |
||
851 |
prop = mo->property(mo->indexOfProperty("value9")); |
|
852 |
QVERIFY(prop.isValid()); |
|
853 |
QVERIFY(prop.isConstant()); |
|
854 |
} |
|
855 |
||
856 |
void tst_QMetaObject::propertyFinal() |
|
857 |
{ |
|
858 |
const QMetaObject *mo = metaObject(); |
|
859 |
||
860 |
QMetaProperty prop = mo->property(mo->indexOfProperty("value10")); |
|
861 |
QVERIFY(prop.isValid()); |
|
862 |
QVERIFY(prop.isFinal()); |
|
863 |
||
864 |
prop = mo->property(mo->indexOfProperty("value9")); |
|
865 |
QVERIFY(prop.isValid()); |
|
866 |
QVERIFY(!prop.isFinal()); |
|
867 |
} |
|
868 |
||
869 |
class ClassInfoTestObjectA : public QObject |
|
870 |
{ |
|
871 |
Q_OBJECT |
|
872 |
Q_CLASSINFO("Author", "Christopher Pike") |
|
873 |
}; |
|
874 |
||
875 |
class ClassInfoTestObjectB : public ClassInfoTestObjectA |
|
876 |
{ |
|
877 |
Q_OBJECT |
|
878 |
}; |
|
879 |
||
880 |
void tst_QMetaObject::classInfo() |
|
881 |
{ |
|
882 |
ClassInfoTestObjectB b; |
|
883 |
int index = b.metaObject()->indexOfClassInfo("Author"); |
|
884 |
QCOMPARE(index, 0); |
|
885 |
QVERIFY(index <= b.metaObject()->classInfoOffset()); |
|
886 |
QCOMPARE(QLatin1String(b.metaObject()->classInfo(index).value()), QLatin1String("Christopher Pike")); |
|
887 |
} |
|
888 |
||
889 |
QTEST_MAIN(tst_QMetaObject) |
|
890 |
#include "tst_qmetaobject.moc" |