|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
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 |
|
44 #include <QtTest/QtTest> |
|
45 #include <stdio.h> |
|
46 #include <qobject.h> |
|
47 |
|
48 #include "using-namespaces.h" |
|
49 #include "assign-namespace.h" |
|
50 #include "no-keywords.h" |
|
51 #include "single_function_keyword.h" |
|
52 #include "backslash-newlines.h" |
|
53 #include "slots-with-void-template.h" |
|
54 #include "pure-virtual-signals.h" |
|
55 #include "qinvokable.h" |
|
56 // msvc and friends crap out on it |
|
57 #if !defined(Q_CC_GNU) || defined(Q_OS_IRIX) || defined(Q_OS_WIN) |
|
58 #define SKIP_NEWLINE_TEST |
|
59 #endif |
|
60 #if !defined(SKIP_NEWLINE_TEST) |
|
61 #include "os9-newlines.h" |
|
62 // msvc and friends crap out on this file too, |
|
63 // it seems to contain Mac 9 EOLs, and not windows EOLs. |
|
64 #include "win-newlines.h" |
|
65 #endif |
|
66 #include "escapes-in-string-literals.h" |
|
67 #include "cstyle-enums.h" |
|
68 |
|
69 |
|
70 #if defined(PARSE_BOOST) |
|
71 #include "parse-boost.h" |
|
72 #endif |
|
73 |
|
74 // No such thing as "long long" in Microsoft's compiler 13.0 and before |
|
75 #if defined Q_CC_MSVC && _MSC_VER <= 1310 |
|
76 # define NOLONGLONG |
|
77 #endif |
|
78 |
|
79 QT_USE_NAMESPACE |
|
80 |
|
81 struct MyStruct {}; |
|
82 struct MyStruct2 {}; |
|
83 |
|
84 struct SuperClass {}; |
|
85 |
|
86 // Try to avoid inserting for instance a comment with a quote between the following line and the Q_OBJECT |
|
87 // That will make the test give a false positive. |
|
88 const char* test_multiple_number_of_escapes = "\\\""; |
|
89 namespace MyNamespace |
|
90 { |
|
91 class TestSuperClass : public QObject |
|
92 { |
|
93 Q_OBJECT |
|
94 public: |
|
95 inline TestSuperClass() {} |
|
96 }; |
|
97 } |
|
98 |
|
99 namespace String |
|
100 { |
|
101 typedef QString Type; |
|
102 } |
|
103 |
|
104 namespace Int |
|
105 { |
|
106 typedef int Type; |
|
107 } |
|
108 |
|
109 typedef struct { |
|
110 int doNotConfuseMoc; |
|
111 } OldStyleCStruct; |
|
112 |
|
113 class Sender : public QObject |
|
114 { |
|
115 Q_OBJECT |
|
116 |
|
117 public: |
|
118 void sendValue(const String::Type& value) |
|
119 { |
|
120 emit send(value); |
|
121 } |
|
122 void sendValue(const Int::Type& value) |
|
123 { |
|
124 emit send(value); |
|
125 } |
|
126 |
|
127 signals: |
|
128 void send(const String::Type&); |
|
129 void send(const Int::Type&); |
|
130 }; |
|
131 |
|
132 class Receiver : public QObject |
|
133 { |
|
134 Q_OBJECT |
|
135 public: |
|
136 Receiver() : stringCallCount(0), intCallCount(0) {} |
|
137 |
|
138 int stringCallCount; |
|
139 int intCallCount; |
|
140 |
|
141 public slots: |
|
142 void receive(const String::Type&) { stringCallCount++; } |
|
143 void receive(const Int::Type&) { intCallCount++; } |
|
144 }; |
|
145 |
|
146 #define MACRO_WITH_POSSIBLE_COMPILER_SPECIFIC_ATTRIBUTES |
|
147 |
|
148 #define DONT_CONFUSE_MOC(klass) klass |
|
149 #define DONT_CONFUSE_MOC_EVEN_MORE(klass, dummy, dummy2) klass |
|
150 |
|
151 Q_DECLARE_METATYPE(MyStruct) |
|
152 Q_DECLARE_METATYPE(MyStruct*) |
|
153 |
|
154 namespace myNS { |
|
155 struct Points |
|
156 { |
|
157 Points() : p1(0xBEEF), p2(0xBABE) { } |
|
158 int p1, p2; |
|
159 }; |
|
160 } |
|
161 |
|
162 Q_DECLARE_METATYPE(myNS::Points) |
|
163 |
|
164 class TestClassinfoWithEscapes: public QObject |
|
165 { |
|
166 Q_OBJECT |
|
167 Q_CLASSINFO("escaped", "\"bar\"") |
|
168 Q_CLASSINFO("\"escaped\"", "foo") |
|
169 public slots: |
|
170 void slotWithAReallyLongName(int) |
|
171 { } |
|
172 }; |
|
173 |
|
174 struct ForwardDeclaredStruct; |
|
175 |
|
176 struct StructQObject : public QObject |
|
177 { |
|
178 Q_OBJECT |
|
179 public: |
|
180 void foo(struct ForwardDeclaredStruct *); |
|
181 }; |
|
182 |
|
183 void StructQObject::foo(struct ForwardDeclaredStruct *) |
|
184 { |
|
185 struct Inner { |
|
186 bool field; |
|
187 }; |
|
188 |
|
189 struct Inner unusedVariable; |
|
190 } |
|
191 |
|
192 class TestClass : public MyNamespace::TestSuperClass, public DONT_CONFUSE_MOC(MyStruct), |
|
193 public DONT_CONFUSE_MOC_EVEN_MORE(MyStruct2, dummy, ignored) |
|
194 { |
|
195 Q_OBJECT |
|
196 Q_CLASSINFO("help", QT_TR_NOOP("Opening this will let you configure something")) |
|
197 Q_PROPERTY(short int shortIntProperty READ shortIntProperty) |
|
198 Q_PROPERTY(unsigned short int unsignedShortIntProperty READ unsignedShortIntProperty) |
|
199 Q_PROPERTY(signed short int signedShortIntProperty READ signedShortIntProperty) |
|
200 Q_PROPERTY(long int longIntProperty READ longIntProperty) |
|
201 Q_PROPERTY(unsigned long int unsignedLongIntProperty READ unsignedLongIntProperty) |
|
202 Q_PROPERTY(signed long int signedLongIntProperty READ signedLongIntProperty) |
|
203 Q_PROPERTY(long double longDoubleProperty READ longDoubleProperty) |
|
204 Q_PROPERTY(myNS::Points points READ points WRITE setPoints) |
|
205 |
|
206 Q_CLASSINFO("Multi" |
|
207 "line", |
|
208 "" |
|
209 "This is a " |
|
210 "multiline Q_CLASSINFO" |
|
211 "") |
|
212 |
|
213 // a really really long string that we have to cut into pieces in the generated stringdata |
|
214 // table, otherwise msvc craps out |
|
215 Q_CLASSINFO("D-Bus Introspection", "" |
|
216 " <interface name=\"org.kde.KCookieServer\" >\n" |
|
217 " <method name=\"findCookies\" >\n" |
|
218 " <arg direction=\"in\" type=\"s\" name=\"url\" />\n" |
|
219 " <arg direction=\"in\" type=\"x\" name=\"windowId\" />\n" |
|
220 " <arg direction=\"out\" type=\"s\" name=\"cookies\" />\n" |
|
221 " </method>\n" |
|
222 " <method name=\"findDomains\" >\n" |
|
223 " <arg direction=\"out\" type=\"as\" name=\"domains\" />\n" |
|
224 " </method>\n" |
|
225 " <method name=\"findCookies\" >\n" |
|
226 " <arg direction=\"in\" type=\"ai\" name=\"fields\" />\n" |
|
227 " <arg direction=\"in\" type=\"s\" name=\"domain\" />\n" |
|
228 " <arg direction=\"in\" type=\"s\" name=\"fqdn\" />\n" |
|
229 " <arg direction=\"in\" type=\"s\" name=\"path\" />\n" |
|
230 " <arg direction=\"in\" type=\"s\" name=\"name\" />\n" |
|
231 " <arg direction=\"out\" type=\"as\" name=\"cookies\" />\n" |
|
232 " <annotation value=\"QList<int>\" name=\"com.trolltech.QtDBus.QtTypeName.In0\" />\n" |
|
233 " </method>\n" |
|
234 " <method name=\"findDOMCookies\" >\n" |
|
235 " <arg direction=\"in\" type=\"s\" name=\"url\" />\n" |
|
236 " <arg direction=\"in\" type=\"x\" name=\"windowId\" />\n" |
|
237 " <arg direction=\"out\" type=\"s\" name=\"cookies\" />\n" |
|
238 " </method>\n" |
|
239 " <method name=\"addCookies\" >\n" |
|
240 " <arg direction=\"in\" type=\"s\" name=\"url\" />\n" |
|
241 " <arg direction=\"in\" type=\"ay\" name=\"cookieHeader\" />\n" |
|
242 " <arg direction=\"in\" type=\"x\" name=\"windowId\" />\n" |
|
243 " </method>\n" |
|
244 " <method name=\"deleteCookie\" >\n" |
|
245 " <arg direction=\"in\" type=\"s\" name=\"domain\" />\n" |
|
246 " <arg direction=\"in\" type=\"s\" name=\"fqdn\" />\n" |
|
247 " <arg direction=\"in\" type=\"s\" name=\"path\" />\n" |
|
248 " <arg direction=\"in\" type=\"s\" name=\"name\" />\n" |
|
249 " </method>\n" |
|
250 " <method name=\"deleteCookiesFromDomain\" >\n" |
|
251 " <arg direction=\"in\" type=\"s\" name=\"domain\" />\n" |
|
252 " </method>\n" |
|
253 " <method name=\"deleteSessionCookies\" >\n" |
|
254 " <arg direction=\"in\" type=\"x\" name=\"windowId\" />\n" |
|
255 " </method>\n" |
|
256 " <method name=\"deleteSessionCookiesFor\" >\n" |
|
257 " <arg direction=\"in\" type=\"s\" name=\"fqdn\" />\n" |
|
258 " <arg direction=\"in\" type=\"x\" name=\"windowId\" />\n" |
|
259 " </method>\n" |
|
260 " <method name=\"deleteAllCookies\" />\n" |
|
261 " <method name=\"addDOMCookies\" >\n" |
|
262 " <arg direction=\"in\" type=\"s\" name=\"url\" />\n" |
|
263 " <arg direction=\"in\" type=\"ay\" name=\"cookieHeader\" />\n" |
|
264 " <arg direction=\"in\" type=\"x\" name=\"windowId\" />\n" |
|
265 " </method>\n" |
|
266 " <method name=\"setDomainAdvice\" >\n" |
|
267 " <arg direction=\"in\" type=\"s\" name=\"url\" />\n" |
|
268 " <arg direction=\"in\" type=\"s\" name=\"advice\" />\n" |
|
269 " </method>\n" |
|
270 " <method name=\"getDomainAdvice\" >\n" |
|
271 " <arg direction=\"in\" type=\"s\" name=\"url\" />\n" |
|
272 " <arg direction=\"out\" type=\"s\" name=\"advice\" />\n" |
|
273 " </method>\n" |
|
274 " <method name=\"reloadPolicy\" />\n" |
|
275 " <method name=\"shutdown\" />\n" |
|
276 " </interface>\n" |
|
277 "") |
|
278 |
|
279 public: |
|
280 inline TestClass() {} |
|
281 |
|
282 private slots: |
|
283 inline void dummy1() MACRO_WITH_POSSIBLE_COMPILER_SPECIFIC_ATTRIBUTES {} |
|
284 inline void dummy2() MACRO_WITH_POSSIBLE_COMPILER_SPECIFIC_ATTRIBUTES const {} |
|
285 inline void dummy3() const MACRO_WITH_POSSIBLE_COMPILER_SPECIFIC_ATTRIBUTES {} |
|
286 |
|
287 #ifndef NOLONGLONG |
|
288 void slotWithULongLong(unsigned long long) {} |
|
289 void slotWithULongLongP(unsigned long long*) {} |
|
290 void slotWithULong(unsigned long) {} |
|
291 void slotWithLongLong(long long) {} |
|
292 void slotWithLong(long) {} |
|
293 #endif |
|
294 |
|
295 void slotWithColonColonType(::Int::Type) {} |
|
296 |
|
297 TestClass &slotWithReferenceReturnType() { return *this; } |
|
298 |
|
299 #if (0 && 1) || 1 |
|
300 void expressionEvaluationShortcut1() {} |
|
301 #endif |
|
302 #if (1 || 0) && 0 |
|
303 #else |
|
304 void expressionEvaluationShortcut2() {} |
|
305 #endif |
|
306 |
|
307 public slots: |
|
308 void slotWithArray(const double[3]) {} |
|
309 void slotWithNamedArray(const double namedArray[3]) {} |
|
310 void slotWithMultiArray(const double[3][4]) {} |
|
311 |
|
312 short int shortIntProperty() { return 0; } |
|
313 unsigned short int unsignedShortIntProperty() { return 0; } |
|
314 signed short int signedShortIntProperty() { return 0; } |
|
315 long int longIntProperty() { return 0; } |
|
316 unsigned long int unsignedLongIntProperty() { return 0; } |
|
317 signed long int signedLongIntProperty() { return 0; } |
|
318 long double longDoubleProperty() { return 0.0; } |
|
319 |
|
320 myNS::Points points() { return m_points; } |
|
321 void setPoints(myNS::Points points) { m_points = points; } |
|
322 |
|
323 signals: |
|
324 void signalWithArray(const double[3]); |
|
325 void signalWithNamedArray(const double namedArray[3]); |
|
326 |
|
327 private slots: |
|
328 // for tst_Moc::preprocessorConditionals |
|
329 #if 0 |
|
330 void invalidSlot() {} |
|
331 #else |
|
332 void slotInElse() {} |
|
333 #endif |
|
334 |
|
335 #if 1 |
|
336 void slotInIf() {} |
|
337 #else |
|
338 void invalidSlot() {} |
|
339 #endif |
|
340 |
|
341 #if 0 |
|
342 void invalidSlot() {} |
|
343 #elif 0 |
|
344 #else |
|
345 void slotInLastElse() {} |
|
346 #endif |
|
347 |
|
348 #if 0 |
|
349 void invalidSlot() {} |
|
350 #elif 1 |
|
351 void slotInElif() {} |
|
352 #else |
|
353 void invalidSlot() {} |
|
354 #endif |
|
355 |
|
356 |
|
357 friend class Receiver; // task #85783 |
|
358 signals: |
|
359 friend class Sender; // task #85783 |
|
360 |
|
361 public slots: |
|
362 void const slotWithSillyConst() {} |
|
363 |
|
364 public: |
|
365 Q_INVOKABLE void const slotWithSillyConst2() {} |
|
366 |
|
367 // that one however should be fine |
|
368 public slots: |
|
369 void slotWithVoidStar(void *) {} |
|
370 |
|
371 private: |
|
372 myNS::Points m_points; |
|
373 |
|
374 private slots: |
|
375 inline virtual void blub1() {} |
|
376 virtual inline void blub2() {} |
|
377 }; |
|
378 |
|
379 class PropertyTestClass : public QObject |
|
380 { |
|
381 Q_OBJECT |
|
382 public: |
|
383 |
|
384 enum TestEnum { One, Two, Three }; |
|
385 |
|
386 Q_ENUMS(TestEnum) |
|
387 }; |
|
388 |
|
389 class PropertyUseClass : public QObject |
|
390 { |
|
391 Q_OBJECT |
|
392 Q_PROPERTY(PropertyTestClass::TestEnum foo READ foo) |
|
393 public: |
|
394 |
|
395 inline PropertyTestClass::TestEnum foo() const { return PropertyTestClass::One; } |
|
396 }; |
|
397 |
|
398 #if defined(Q_MOC_RUN) |
|
399 // Task #119503 |
|
400 #define _TASK_119503 |
|
401 #if !_TASK_119503 |
|
402 #endif |
|
403 #endif |
|
404 |
|
405 static QString srcify(const char *path) |
|
406 { |
|
407 #ifndef Q_OS_IRIX |
|
408 return QString(SRCDIR) + QLatin1Char('/') + QLatin1String(path); |
|
409 #else |
|
410 return QString(QLatin1String(path)); |
|
411 #endif |
|
412 } |
|
413 |
|
414 class CtorTestClass : public QObject |
|
415 { |
|
416 Q_OBJECT |
|
417 public: |
|
418 Q_INVOKABLE CtorTestClass(QObject *parent = 0); |
|
419 |
|
420 CtorTestClass(int foo); |
|
421 |
|
422 inline Q_INVOKABLE CtorTestClass(const QString &str) |
|
423 { m_str = str; } |
|
424 |
|
425 QString m_str; |
|
426 |
|
427 protected: |
|
428 CtorTestClass(int foo, int bar, int baz); |
|
429 private: |
|
430 CtorTestClass(float, float) {} |
|
431 }; |
|
432 |
|
433 CtorTestClass::CtorTestClass(QObject *parent) |
|
434 : QObject(parent) {} |
|
435 |
|
436 CtorTestClass::CtorTestClass(int, int, int) {} |
|
437 |
|
438 |
|
439 class tst_Moc : public QObject |
|
440 { |
|
441 Q_OBJECT |
|
442 |
|
443 Q_PROPERTY(bool user1 READ user1 USER true ) |
|
444 Q_PROPERTY(bool user2 READ user2 USER false) |
|
445 Q_PROPERTY(bool user3 READ user3 USER userFunction()) |
|
446 |
|
447 public: |
|
448 inline tst_Moc() {} |
|
449 |
|
450 private slots: |
|
451 void initTestCase(); |
|
452 |
|
453 void slotWithException() throw(MyStruct); |
|
454 void dontStripNamespaces(); |
|
455 void oldStyleCasts(); |
|
456 void warnOnExtraSignalSlotQualifiaction(); |
|
457 void uLongLong(); |
|
458 void inputFileNameWithDotsButNoExtension(); |
|
459 void userProperties(); |
|
460 void supportConstSignals(); |
|
461 void task87883(); |
|
462 void multilineComments(); |
|
463 void classinfoWithEscapes(); |
|
464 void trNoopInClassInfo(); |
|
465 void ppExpressionEvaluation(); |
|
466 void arrayArguments(); |
|
467 void preprocessorConditionals(); |
|
468 void blackslashNewlines(); |
|
469 void slotWithSillyConst(); |
|
470 void testExtraData(); |
|
471 void namespaceTypeProperty(); |
|
472 void slotsWithVoidTemplate(); |
|
473 void structQObject(); |
|
474 void namespacedFlags(); |
|
475 void warnOnMultipleInheritance(); |
|
476 void forgottenQInterface(); |
|
477 void os9Newline(); |
|
478 void winNewline(); |
|
479 void escapesInStringLiterals(); |
|
480 void frameworkSearchPath(); |
|
481 void cstyleEnums(); |
|
482 void defineMacroViaCmdline(); |
|
483 void invokable(); |
|
484 void singleFunctionKeywordSignalAndSlot(); |
|
485 void templateGtGt(); |
|
486 void qprivateslots(); |
|
487 void inlineSlotsWithThrowDeclaration(); |
|
488 void warnOnPropertyWithoutREAD(); |
|
489 void constructors(); |
|
490 void typenameWithUnsigned(); |
|
491 void warnOnVirtualSignal(); |
|
492 |
|
493 signals: |
|
494 void sigWithUnsignedArg(unsigned foo); |
|
495 void sigWithSignedArg(signed foo); |
|
496 void sigWithConstSignedArg(const signed foo); |
|
497 void sigWithVolatileConstSignedArg(volatile const signed foo); |
|
498 void sigWithCustomType(const MyStruct); |
|
499 void constSignal1() const; |
|
500 void constSignal2(int arg) const; |
|
501 |
|
502 private: |
|
503 bool user1() { return true; }; |
|
504 bool user2() { return false; }; |
|
505 bool user3() { return false; }; |
|
506 bool userFunction(){ return false; }; |
|
507 |
|
508 private: |
|
509 QString qtIncludePath; |
|
510 }; |
|
511 |
|
512 void tst_Moc::initTestCase() |
|
513 { |
|
514 #if defined(Q_OS_UNIX) && !defined(QT_NO_PROCESS) |
|
515 QProcess proc; |
|
516 proc.start("qmake", QStringList() << "-query" << "QT_INSTALL_HEADERS"); |
|
517 QVERIFY(proc.waitForFinished()); |
|
518 QCOMPARE(proc.exitCode(), 0); |
|
519 QByteArray output = proc.readAllStandardOutput(); |
|
520 QVERIFY(!output.isEmpty()); |
|
521 QCOMPARE(proc.readAllStandardError(), QByteArray()); |
|
522 qtIncludePath = QString::fromLocal8Bit(output).trimmed(); |
|
523 QFileInfo fi(qtIncludePath); |
|
524 QVERIFY(fi.exists()); |
|
525 QVERIFY(fi.isDir()); |
|
526 #endif |
|
527 } |
|
528 |
|
529 void tst_Moc::slotWithException() throw(MyStruct) |
|
530 { |
|
531 // be happy |
|
532 QVERIFY(true); |
|
533 } |
|
534 |
|
535 void tst_Moc::dontStripNamespaces() |
|
536 { |
|
537 Sender sender; |
|
538 Receiver receiver; |
|
539 |
|
540 connect(&sender, SIGNAL(send(const String::Type &)), |
|
541 &receiver, SLOT(receive(const String::Type &))); |
|
542 connect(&sender, SIGNAL(send(const Int::Type &)), |
|
543 &receiver, SLOT(receive(const Int::Type &))); |
|
544 |
|
545 sender.sendValue(String::Type("Hello")); |
|
546 QCOMPARE(receiver.stringCallCount, 1); |
|
547 QCOMPARE(receiver.intCallCount, 0); |
|
548 sender.sendValue(Int::Type(42)); |
|
549 QCOMPARE(receiver.stringCallCount, 1); |
|
550 QCOMPARE(receiver.intCallCount, 1); |
|
551 } |
|
552 |
|
553 |
|
554 void tst_Moc::oldStyleCasts() |
|
555 { |
|
556 #ifdef MOC_CROSS_COMPILED |
|
557 QSKIP("Not tested when cross-compiled", SkipAll); |
|
558 #endif |
|
559 #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) |
|
560 QProcess proc; |
|
561 proc.start("moc", QStringList(srcify("/oldstyle-casts.h"))); |
|
562 QVERIFY(proc.waitForFinished()); |
|
563 QCOMPARE(proc.exitCode(), 0); |
|
564 QByteArray mocOut = proc.readAllStandardOutput(); |
|
565 QVERIFY(!mocOut.isEmpty()); |
|
566 QCOMPARE(proc.readAllStandardError(), QByteArray()); |
|
567 |
|
568 QStringList args; |
|
569 args << "-c" << "-x" << "c++" << "-Wold-style-cast" << "-I" << "." |
|
570 << "-I" << qtIncludePath << "-o" << "/dev/null" << "-"; |
|
571 proc.start("gcc", args); |
|
572 QVERIFY(proc.waitForStarted()); |
|
573 proc.write(mocOut); |
|
574 proc.closeWriteChannel(); |
|
575 |
|
576 QVERIFY(proc.waitForFinished()); |
|
577 QCOMPARE(proc.exitCode(), 0); |
|
578 QCOMPARE(QString::fromLocal8Bit(proc.readAllStandardError()), QString()); |
|
579 #else |
|
580 QSKIP("Only tested on linux/gcc", SkipAll); |
|
581 #endif |
|
582 } |
|
583 |
|
584 void tst_Moc::warnOnExtraSignalSlotQualifiaction() |
|
585 { |
|
586 #ifdef MOC_CROSS_COMPILED |
|
587 QSKIP("Not tested when cross-compiled", SkipAll); |
|
588 #endif |
|
589 #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) |
|
590 QProcess proc; |
|
591 proc.start("moc", QStringList(srcify("extraqualification.h"))); |
|
592 QVERIFY(proc.waitForFinished()); |
|
593 QCOMPARE(proc.exitCode(), 0); |
|
594 QByteArray mocOut = proc.readAllStandardOutput(); |
|
595 QVERIFY(!mocOut.isEmpty()); |
|
596 QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError()); |
|
597 QCOMPARE(mocWarning, QString(SRCDIR) + |
|
598 QString("/extraqualification.h:53: Warning: Function declaration Test::badFunctionDeclaration contains extra qualification. Ignoring as signal or slot.\n") + |
|
599 QString(SRCDIR) + QString("/extraqualification.h:56: Warning: parsemaybe: Function declaration Test::anotherOne contains extra qualification. Ignoring as signal or slot.\n")); |
|
600 #else |
|
601 QSKIP("Only tested on linux/gcc", SkipAll); |
|
602 #endif |
|
603 } |
|
604 |
|
605 void tst_Moc::uLongLong() |
|
606 { |
|
607 #ifndef NOLONGLONG |
|
608 TestClass tst; |
|
609 const QMetaObject *mobj = tst.metaObject(); |
|
610 int idx = mobj->indexOfSlot("slotWithULong(ulong)"); |
|
611 QVERIFY(idx != -1); |
|
612 idx = mobj->indexOfSlot("slotWithULongLong(unsigned long long)"); |
|
613 QVERIFY(idx != -1); |
|
614 idx = mobj->indexOfSlot("slotWithULongLongP(unsigned long long*)"); |
|
615 QVERIFY(idx != -1); |
|
616 |
|
617 idx = mobj->indexOfSlot("slotWithLong(long)"); |
|
618 QVERIFY(idx != -1); |
|
619 idx = mobj->indexOfSlot("slotWithLongLong(long long)"); |
|
620 QVERIFY(idx != -1); |
|
621 #else |
|
622 QSKIP("long long doesn't work on MSVC6 & .NET 2002, also skipped on 2003 due to compiler version issue with moc", SkipAll); |
|
623 #endif |
|
624 } |
|
625 |
|
626 void tst_Moc::inputFileNameWithDotsButNoExtension() |
|
627 { |
|
628 #ifdef MOC_CROSS_COMPILED |
|
629 QSKIP("Not tested when cross-compiled", SkipAll); |
|
630 #endif |
|
631 #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) |
|
632 QProcess proc; |
|
633 proc.setWorkingDirectory(QString(SRCDIR) + "/task71021"); |
|
634 proc.start("moc", QStringList("../Header")); |
|
635 QVERIFY(proc.waitForFinished()); |
|
636 QCOMPARE(proc.exitCode(), 0); |
|
637 QByteArray mocOut = proc.readAllStandardOutput(); |
|
638 QVERIFY(!mocOut.isEmpty()); |
|
639 QCOMPARE(proc.readAllStandardError(), QByteArray()); |
|
640 |
|
641 QStringList args; |
|
642 args << "-c" << "-x" << "c++" << "-I" << ".." |
|
643 << "-I" << qtIncludePath << "-o" << "/dev/null" << "-"; |
|
644 proc.start("gcc", args); |
|
645 QVERIFY(proc.waitForStarted()); |
|
646 proc.write(mocOut); |
|
647 proc.closeWriteChannel(); |
|
648 |
|
649 QVERIFY(proc.waitForFinished()); |
|
650 QCOMPARE(QString::fromLocal8Bit(proc.readAllStandardError()), QString()); |
|
651 QCOMPARE(proc.exitCode(), 0); |
|
652 #else |
|
653 QSKIP("Only tested on linux/gcc", SkipAll); |
|
654 #endif |
|
655 } |
|
656 |
|
657 void tst_Moc::userProperties() |
|
658 { |
|
659 const QMetaObject *mobj = metaObject(); |
|
660 QMetaProperty property = mobj->property(mobj->indexOfProperty("user1")); |
|
661 QVERIFY(property.isValid()); |
|
662 QVERIFY(property.isUser()); |
|
663 |
|
664 property = mobj->property(mobj->indexOfProperty("user2")); |
|
665 QVERIFY(property.isValid()); |
|
666 QVERIFY(!property.isUser()); |
|
667 |
|
668 property = mobj->property(mobj->indexOfProperty("user3")); |
|
669 QVERIFY(property.isValid()); |
|
670 QVERIFY(!property.isUser(this)); |
|
671 } |
|
672 |
|
673 void tst_Moc::supportConstSignals() |
|
674 { |
|
675 QSignalSpy spy1(this, SIGNAL(constSignal1())); |
|
676 QVERIFY(spy1.isEmpty()); |
|
677 emit constSignal1(); |
|
678 QCOMPARE(spy1.count(), 1); |
|
679 |
|
680 QSignalSpy spy2(this, SIGNAL(constSignal2(int))); |
|
681 QVERIFY(spy2.isEmpty()); |
|
682 emit constSignal2(42); |
|
683 QCOMPARE(spy2.count(), 1); |
|
684 QCOMPARE(spy2.at(0).at(0).toInt(), 42); |
|
685 } |
|
686 |
|
687 #include "task87883.h" |
|
688 |
|
689 void tst_Moc::task87883() |
|
690 { |
|
691 QVERIFY(Task87883::staticMetaObject.className()); |
|
692 } |
|
693 |
|
694 #include "c-comments.h" |
|
695 |
|
696 void tst_Moc::multilineComments() |
|
697 { |
|
698 QVERIFY(IfdefedClass::staticMetaObject.className()); |
|
699 } |
|
700 |
|
701 void tst_Moc::classinfoWithEscapes() |
|
702 { |
|
703 const QMetaObject *mobj = &TestClassinfoWithEscapes::staticMetaObject; |
|
704 QCOMPARE(mobj->methodCount() - mobj->methodOffset(), 1); |
|
705 |
|
706 QMetaMethod mm = mobj->method(mobj->methodOffset()); |
|
707 QCOMPARE(mm.signature(), "slotWithAReallyLongName(int)"); |
|
708 } |
|
709 |
|
710 void tst_Moc::trNoopInClassInfo() |
|
711 { |
|
712 TestClass t; |
|
713 const QMetaObject *mobj = t.metaObject(); |
|
714 QVERIFY(mobj); |
|
715 QCOMPARE(mobj->classInfoCount(), 3); |
|
716 QCOMPARE(mobj->indexOfClassInfo("help"), 0); |
|
717 QCOMPARE(QString(mobj->classInfo(0).value()), QString("Opening this will let you configure something")); |
|
718 } |
|
719 |
|
720 void tst_Moc::ppExpressionEvaluation() |
|
721 { |
|
722 TestClass tst; |
|
723 const QMetaObject *mobj = tst.metaObject(); |
|
724 int idx = mobj->indexOfSlot("expressionEvaluationShortcut1()"); |
|
725 QVERIFY(idx != -1); |
|
726 |
|
727 idx = mobj->indexOfSlot("expressionEvaluationShortcut2()"); |
|
728 QVERIFY(idx != -1); |
|
729 } |
|
730 |
|
731 void tst_Moc::arrayArguments() |
|
732 { |
|
733 TestClass tst; |
|
734 const QMetaObject *mobj = tst.metaObject(); |
|
735 QVERIFY(mobj->indexOfSlot("slotWithArray(const double[3])") != -1); |
|
736 QVERIFY(mobj->indexOfSlot("slotWithNamedArray(const double[3])") != -1); |
|
737 QVERIFY(mobj->indexOfSlot("slotWithMultiArray(const double[3][4])") != -1); |
|
738 QVERIFY(mobj->indexOfSignal("signalWithArray(const double[3])") != -1); |
|
739 QVERIFY(mobj->indexOfSignal("signalWithNamedArray(const double[3])") != -1); |
|
740 } |
|
741 |
|
742 void tst_Moc::preprocessorConditionals() |
|
743 { |
|
744 TestClass tst; |
|
745 const QMetaObject *mobj = tst.metaObject(); |
|
746 QVERIFY(mobj->indexOfSlot("slotInElse()") != -1); |
|
747 QVERIFY(mobj->indexOfSlot("slotInIf()") != -1); |
|
748 QVERIFY(mobj->indexOfSlot("slotInLastElse()") != -1); |
|
749 QVERIFY(mobj->indexOfSlot("slotInElif()") != -1); |
|
750 } |
|
751 |
|
752 void tst_Moc::blackslashNewlines() |
|
753 { |
|
754 BackslashNewlines tst; |
|
755 const QMetaObject *mobj = tst.metaObject(); |
|
756 QVERIFY(mobj->indexOfSlot("works()") != -1); |
|
757 QVERIFY(mobj->indexOfSlot("buggy()") == -1); |
|
758 } |
|
759 |
|
760 void tst_Moc::slotWithSillyConst() |
|
761 { |
|
762 TestClass tst; |
|
763 const QMetaObject *mobj = tst.metaObject(); |
|
764 QVERIFY(mobj->indexOfSlot("slotWithSillyConst()") != -1); |
|
765 QVERIFY(mobj->indexOfMethod("slotWithSillyConst2()") != -1); |
|
766 QVERIFY(mobj->indexOfSlot("slotWithVoidStar(void*)") != -1); |
|
767 } |
|
768 |
|
769 void tst_Moc::testExtraData() |
|
770 { |
|
771 const QMetaObject *mobj = &PropertyTestClass::staticMetaObject; |
|
772 QCOMPARE(mobj->enumeratorCount(), 1); |
|
773 QCOMPARE(QByteArray(mobj->enumerator(0).name()), QByteArray("TestEnum")); |
|
774 |
|
775 mobj = &PropertyUseClass::staticMetaObject; |
|
776 const int idx = mobj->indexOfProperty("foo"); |
|
777 QVERIFY(idx != -1); |
|
778 const QMetaProperty prop = mobj->property(idx); |
|
779 QVERIFY(prop.isValid()); |
|
780 QVERIFY(prop.isEnumType()); |
|
781 const QMetaEnum en = prop.enumerator(); |
|
782 QCOMPARE(QByteArray(en.name()), QByteArray("TestEnum")); |
|
783 } |
|
784 |
|
785 void tst_Moc::namespaceTypeProperty() |
|
786 { |
|
787 qRegisterMetaType<myNS::Points>("myNS::Points"); |
|
788 TestClass tst; |
|
789 QByteArray ba = QByteArray("points"); |
|
790 QVariant v = tst.property(ba); |
|
791 QVERIFY(v.isValid()); |
|
792 myNS::Points p = qVariantValue<myNS::Points>(v); |
|
793 QCOMPARE(p.p1, 0xBEEF); |
|
794 QCOMPARE(p.p2, 0xBABE); |
|
795 p.p1 = 0xCAFE; |
|
796 p.p2 = 0x1EE7; |
|
797 QVERIFY(tst.setProperty(ba, qVariantFromValue(p))); |
|
798 myNS::Points pp = qVariantValue<myNS::Points>(tst.property(ba)); |
|
799 QCOMPARE(p.p1, pp.p1); |
|
800 QCOMPARE(p.p2, pp.p2); |
|
801 } |
|
802 |
|
803 void tst_Moc::slotsWithVoidTemplate() |
|
804 { |
|
805 SlotsWithVoidTemplateTest test; |
|
806 QVERIFY(QObject::connect(&test, SIGNAL(myVoidSignal(void)), |
|
807 &test, SLOT(dummySlot(void)))); |
|
808 QVERIFY(QObject::connect(&test, SIGNAL(mySignal(const TestTemplate<void> &)), |
|
809 &test, SLOT(anotherSlot(const TestTemplate<void> &)))); |
|
810 } |
|
811 |
|
812 void tst_Moc::structQObject() |
|
813 { |
|
814 StructQObject o; |
|
815 QCOMPARE(QByteArray(o.metaObject()->className()), QByteArray("StructQObject")); |
|
816 } |
|
817 |
|
818 #include "namespaced-flags.h" |
|
819 |
|
820 void tst_Moc::namespacedFlags() |
|
821 { |
|
822 Foo::Baz baz; |
|
823 Foo::Bar bar; |
|
824 |
|
825 bar.setFlags(Foo::Bar::Read | Foo::Bar::Write); |
|
826 QVERIFY(baz.flags() != bar.flags()); |
|
827 |
|
828 const QVariant v = bar.property("flags"); |
|
829 QVERIFY(v.isValid()); |
|
830 QVERIFY(baz.setProperty("flags", v)); |
|
831 QVERIFY(baz.flags() == bar.flags()); |
|
832 } |
|
833 |
|
834 void tst_Moc::warnOnMultipleInheritance() |
|
835 { |
|
836 #ifdef MOC_CROSS_COMPILED |
|
837 QSKIP("Not tested when cross-compiled", SkipAll); |
|
838 #endif |
|
839 #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) |
|
840 QProcess proc; |
|
841 QStringList args; |
|
842 args << "-I" << qtIncludePath + "/QtGui" |
|
843 << srcify("warn-on-multiple-qobject-subclasses.h"); |
|
844 proc.start("moc", args); |
|
845 QVERIFY(proc.waitForFinished()); |
|
846 QCOMPARE(proc.exitCode(), 0); |
|
847 QByteArray mocOut = proc.readAllStandardOutput(); |
|
848 QVERIFY(!mocOut.isEmpty()); |
|
849 QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError()); |
|
850 QCOMPARE(mocWarning, QString(SRCDIR) + |
|
851 QString("/warn-on-multiple-qobject-subclasses.h:53: Warning: Class Bar inherits from two QObject subclasses QWidget and Foo. This is not supported!\n")); |
|
852 #else |
|
853 QSKIP("Only tested on linux/gcc", SkipAll); |
|
854 #endif |
|
855 } |
|
856 |
|
857 void tst_Moc::forgottenQInterface() |
|
858 { |
|
859 #ifdef MOC_CROSS_COMPILED |
|
860 QSKIP("Not tested when cross-compiled", SkipAll); |
|
861 #endif |
|
862 #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) |
|
863 QProcess proc; |
|
864 QStringList args; |
|
865 args << "-I" << qtIncludePath + "/QtCore" |
|
866 << srcify("forgotten-qinterface.h"); |
|
867 proc.start("moc", args); |
|
868 QVERIFY(proc.waitForFinished()); |
|
869 QCOMPARE(proc.exitCode(), 0); |
|
870 QByteArray mocOut = proc.readAllStandardOutput(); |
|
871 QVERIFY(!mocOut.isEmpty()); |
|
872 QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError()); |
|
873 QCOMPARE(mocWarning, QString(SRCDIR) + |
|
874 QString("/forgotten-qinterface.h:55: Warning: Class Test implements the interface MyInterface but does not list it in Q_INTERFACES. qobject_cast to MyInterface will not work!\n")); |
|
875 #else |
|
876 QSKIP("Only tested on linux/gcc", SkipAll); |
|
877 #endif |
|
878 } |
|
879 |
|
880 void tst_Moc::os9Newline() |
|
881 { |
|
882 #if !defined(SKIP_NEWLINE_TEST) |
|
883 const QMetaObject &mo = Os9Newlines::staticMetaObject; |
|
884 QVERIFY(mo.indexOfSlot("testSlot()") != -1); |
|
885 QFile f(srcify("os9-newlines.h")); |
|
886 QVERIFY(f.open(QIODevice::ReadOnly)); // no QIODevice::Text! |
|
887 QByteArray data = f.readAll(); |
|
888 f.close(); |
|
889 QVERIFY(!data.contains('\n')); |
|
890 QVERIFY(data.contains('\r')); |
|
891 #endif |
|
892 } |
|
893 |
|
894 void tst_Moc::winNewline() |
|
895 { |
|
896 #if !defined(SKIP_NEWLINE_TEST) |
|
897 const QMetaObject &mo = WinNewlines::staticMetaObject; |
|
898 QVERIFY(mo.indexOfSlot("testSlot()") != -1); |
|
899 QFile f(srcify("win-newlines.h")); |
|
900 QVERIFY(f.open(QIODevice::ReadOnly)); // no QIODevice::Text! |
|
901 QByteArray data = f.readAll(); |
|
902 f.close(); |
|
903 for (int i = 0; i < data.count(); ++i) { |
|
904 if (data.at(i) == QLatin1Char('\r')) { |
|
905 QVERIFY(i < data.count() - 1); |
|
906 ++i; |
|
907 QVERIFY(data.at(i) == '\n'); |
|
908 } else { |
|
909 QVERIFY(data.at(i) != '\n'); |
|
910 } |
|
911 } |
|
912 #endif |
|
913 } |
|
914 |
|
915 void tst_Moc::escapesInStringLiterals() |
|
916 { |
|
917 const QMetaObject &mo = StringLiterals::staticMetaObject; |
|
918 QCOMPARE(mo.classInfoCount(), 3); |
|
919 |
|
920 int idx = mo.indexOfClassInfo("Test"); |
|
921 QVERIFY(idx != -1); |
|
922 QMetaClassInfo info = mo.classInfo(idx); |
|
923 QCOMPARE(QByteArray(info.value()), |
|
924 QByteArray("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\x53")); |
|
925 |
|
926 QVERIFY(idx != -1); |
|
927 idx = mo.indexOfClassInfo("Test2"); |
|
928 info = mo.classInfo(idx); |
|
929 QCOMPARE(QByteArray(info.value()), |
|
930 QByteArray("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\123")); |
|
931 |
|
932 QVERIFY(idx != -1); |
|
933 idx = mo.indexOfClassInfo("Test3"); |
|
934 info = mo.classInfo(idx); |
|
935 QCOMPARE(QByteArray(info.value()), |
|
936 QByteArray("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nb")); |
|
937 } |
|
938 |
|
939 void tst_Moc::frameworkSearchPath() |
|
940 { |
|
941 #ifdef MOC_CROSS_COMPILED |
|
942 QSKIP("Not tested when cross-compiled", SkipAll); |
|
943 #endif |
|
944 #if defined(Q_OS_UNIX) && !defined(QT_NO_PROCESS) |
|
945 QStringList args; |
|
946 args << "-F" << srcify(".") |
|
947 << srcify("interface-from-framework.h") |
|
948 ; |
|
949 |
|
950 QProcess proc; |
|
951 proc.start("moc", args); |
|
952 bool finished = proc.waitForFinished(); |
|
953 if (!finished) |
|
954 qWarning("waitForFinished failed. QProcess error: %d", (int)proc.error()); |
|
955 QVERIFY(finished); |
|
956 if (proc.exitCode() != 0) { |
|
957 qDebug() << proc.readAllStandardError(); |
|
958 } |
|
959 QCOMPARE(proc.exitCode(), 0); |
|
960 QCOMPARE(proc.readAllStandardError(), QByteArray()); |
|
961 #else |
|
962 QSKIP("Only tested/relevant on unixy platforms", SkipAll); |
|
963 #endif |
|
964 } |
|
965 |
|
966 void tst_Moc::cstyleEnums() |
|
967 { |
|
968 const QMetaObject &obj = CStyleEnums::staticMetaObject; |
|
969 QCOMPARE(obj.enumeratorCount(), 1); |
|
970 QMetaEnum metaEnum = obj.enumerator(0); |
|
971 QCOMPARE(metaEnum.name(), "Baz"); |
|
972 QCOMPARE(metaEnum.keyCount(), 2); |
|
973 QCOMPARE(metaEnum.key(0), "Foo"); |
|
974 QCOMPARE(metaEnum.key(1), "Bar"); |
|
975 } |
|
976 |
|
977 void tst_Moc::templateGtGt() |
|
978 { |
|
979 #ifdef MOC_CROSS_COMPILED |
|
980 QSKIP("Not tested when cross-compiled", SkipAll); |
|
981 #endif |
|
982 #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) |
|
983 QProcess proc; |
|
984 proc.start("moc", QStringList(srcify("template-gtgt.h"))); |
|
985 QVERIFY(proc.waitForFinished()); |
|
986 QCOMPARE(proc.exitCode(), 0); |
|
987 QByteArray mocOut = proc.readAllStandardOutput(); |
|
988 QVERIFY(!mocOut.isEmpty()); |
|
989 QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError()); |
|
990 QVERIFY(mocWarning.isEmpty()); |
|
991 #else |
|
992 QSKIP("Only tested on linux/gcc", SkipAll); |
|
993 #endif |
|
994 } |
|
995 |
|
996 void tst_Moc::defineMacroViaCmdline() |
|
997 { |
|
998 #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) |
|
999 QProcess proc; |
|
1000 |
|
1001 QStringList args; |
|
1002 args << "-DFOO"; |
|
1003 args << srcify("macro-on-cmdline.h"); |
|
1004 |
|
1005 proc.start("moc", args); |
|
1006 QVERIFY(proc.waitForFinished()); |
|
1007 QCOMPARE(proc.exitCode(), 0); |
|
1008 QCOMPARE(proc.readAllStandardError(), QByteArray()); |
|
1009 QByteArray mocOut = proc.readAllStandardOutput(); |
|
1010 QVERIFY(!mocOut.isEmpty()); |
|
1011 #else |
|
1012 QSKIP("Only tested on linux/gcc", SkipAll); |
|
1013 #endif |
|
1014 } |
|
1015 |
|
1016 void tst_Moc::invokable() |
|
1017 { |
|
1018 { |
|
1019 const QMetaObject &mobj = InvokableBeforeReturnType::staticMetaObject; |
|
1020 QCOMPARE(mobj.methodCount(), 5); |
|
1021 QVERIFY(mobj.method(4).signature() == QByteArray("foo()")); |
|
1022 } |
|
1023 |
|
1024 { |
|
1025 const QMetaObject &mobj = InvokableBeforeInline::staticMetaObject; |
|
1026 QCOMPARE(mobj.methodCount(), 6); |
|
1027 QVERIFY(mobj.method(4).signature() == QByteArray("foo()")); |
|
1028 QVERIFY(mobj.method(5).signature() == QByteArray("bar()")); |
|
1029 } |
|
1030 } |
|
1031 |
|
1032 void tst_Moc::singleFunctionKeywordSignalAndSlot() |
|
1033 { |
|
1034 { |
|
1035 const QMetaObject &mobj = SingleFunctionKeywordBeforeReturnType::staticMetaObject; |
|
1036 QCOMPARE(mobj.methodCount(), 6); |
|
1037 QVERIFY(mobj.method(4).signature() == QByteArray("mySignal()")); |
|
1038 QVERIFY(mobj.method(5).signature() == QByteArray("mySlot()")); |
|
1039 } |
|
1040 |
|
1041 { |
|
1042 const QMetaObject &mobj = SingleFunctionKeywordBeforeInline::staticMetaObject; |
|
1043 QCOMPARE(mobj.methodCount(), 6); |
|
1044 QVERIFY(mobj.method(4).signature() == QByteArray("mySignal()")); |
|
1045 QVERIFY(mobj.method(5).signature() == QByteArray("mySlot()")); |
|
1046 } |
|
1047 |
|
1048 { |
|
1049 const QMetaObject &mobj = SingleFunctionKeywordAfterInline::staticMetaObject; |
|
1050 QCOMPARE(mobj.methodCount(), 6); |
|
1051 QVERIFY(mobj.method(4).signature() == QByteArray("mySignal()")); |
|
1052 QVERIFY(mobj.method(5).signature() == QByteArray("mySlot()")); |
|
1053 } |
|
1054 } |
|
1055 |
|
1056 #include "qprivateslots.h" |
|
1057 |
|
1058 void tst_Moc::qprivateslots() |
|
1059 { |
|
1060 TestQPrivateSlots tst; |
|
1061 const QMetaObject *mobj = tst.metaObject(); |
|
1062 QVERIFY(mobj->indexOfSlot("_q_privateslot()") != -1); |
|
1063 QVERIFY(mobj->indexOfMethod("method1()") != -1); //tast204730 |
|
1064 } |
|
1065 |
|
1066 #include "task189996.h" |
|
1067 |
|
1068 void InlineSlotsWithThrowDeclaration::c() throw() {} |
|
1069 |
|
1070 void tst_Moc::inlineSlotsWithThrowDeclaration() |
|
1071 { |
|
1072 InlineSlotsWithThrowDeclaration tst; |
|
1073 const QMetaObject *mobj = tst.metaObject(); |
|
1074 QVERIFY(mobj->indexOfSlot("a()") != -1); |
|
1075 QVERIFY(mobj->indexOfSlot("b()") != -1); |
|
1076 QVERIFY(mobj->indexOfSlot("c()") != -1); |
|
1077 QVERIFY(mobj->indexOfSlot("d()") != -1); |
|
1078 QVERIFY(mobj->indexOfSlot("e()") != -1); |
|
1079 } |
|
1080 |
|
1081 void tst_Moc::warnOnPropertyWithoutREAD() |
|
1082 { |
|
1083 #ifdef MOC_CROSS_COMPILED |
|
1084 QSKIP("Not tested when cross-compiled", SkipAll); |
|
1085 #endif |
|
1086 #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) |
|
1087 QProcess proc; |
|
1088 proc.start("moc", QStringList(srcify("warn-on-property-without-read.h"))); |
|
1089 QVERIFY(proc.waitForFinished()); |
|
1090 QCOMPARE(proc.exitCode(), 0); |
|
1091 QByteArray mocOut = proc.readAllStandardOutput(); |
|
1092 QVERIFY(!mocOut.isEmpty()); |
|
1093 QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError()); |
|
1094 QCOMPARE(mocWarning, QString(SRCDIR) + |
|
1095 QString("/warn-on-property-without-read.h:46: Warning: Property declaration foo has no READ accessor function. The property will be invalid.\n")); |
|
1096 #else |
|
1097 QSKIP("Only tested on linux/gcc", SkipAll); |
|
1098 #endif |
|
1099 } |
|
1100 |
|
1101 void tst_Moc::constructors() |
|
1102 { |
|
1103 const QMetaObject *mo = &CtorTestClass::staticMetaObject; |
|
1104 QCOMPARE(mo->constructorCount(), 3); |
|
1105 { |
|
1106 QMetaMethod mm = mo->constructor(0); |
|
1107 QCOMPARE(mm.access(), QMetaMethod::Public); |
|
1108 QCOMPARE(mm.methodType(), QMetaMethod::Constructor); |
|
1109 QCOMPARE(mm.signature(), "CtorTestClass(QObject*)"); |
|
1110 QCOMPARE(mm.typeName(), ""); |
|
1111 QList<QByteArray> paramNames = mm.parameterNames(); |
|
1112 QCOMPARE(paramNames.size(), 1); |
|
1113 QCOMPARE(paramNames.at(0), QByteArray("parent")); |
|
1114 QList<QByteArray> paramTypes = mm.parameterTypes(); |
|
1115 QCOMPARE(paramTypes.size(), 1); |
|
1116 QCOMPARE(paramTypes.at(0), QByteArray("QObject*")); |
|
1117 } |
|
1118 { |
|
1119 QMetaMethod mm = mo->constructor(1); |
|
1120 QCOMPARE(mm.access(), QMetaMethod::Public); |
|
1121 QCOMPARE(mm.methodType(), QMetaMethod::Constructor); |
|
1122 QCOMPARE(mm.signature(), "CtorTestClass()"); |
|
1123 QCOMPARE(mm.typeName(), ""); |
|
1124 QCOMPARE(mm.parameterNames().size(), 0); |
|
1125 QCOMPARE(mm.parameterTypes().size(), 0); |
|
1126 } |
|
1127 { |
|
1128 QMetaMethod mm = mo->constructor(2); |
|
1129 QCOMPARE(mm.access(), QMetaMethod::Public); |
|
1130 QCOMPARE(mm.methodType(), QMetaMethod::Constructor); |
|
1131 QCOMPARE(mm.signature(), "CtorTestClass(QString)"); |
|
1132 QCOMPARE(mm.typeName(), ""); |
|
1133 QList<QByteArray> paramNames = mm.parameterNames(); |
|
1134 QCOMPARE(paramNames.size(), 1); |
|
1135 QCOMPARE(paramNames.at(0), QByteArray("str")); |
|
1136 QList<QByteArray> paramTypes = mm.parameterTypes(); |
|
1137 QCOMPARE(paramTypes.size(), 1); |
|
1138 QCOMPARE(paramTypes.at(0), QByteArray("QString")); |
|
1139 } |
|
1140 |
|
1141 QCOMPARE(mo->indexOfConstructor("CtorTestClass(QObject*)"), 0); |
|
1142 QCOMPARE(mo->indexOfConstructor("CtorTestClass()"), 1); |
|
1143 QCOMPARE(mo->indexOfConstructor("CtorTestClass(QString)"), 2); |
|
1144 QCOMPARE(mo->indexOfConstructor("CtorTestClass2(QObject*)"), -1); |
|
1145 QCOMPARE(mo->indexOfConstructor("CtorTestClass(float,float)"), -1); |
|
1146 |
|
1147 QObject *o1 = mo->newInstance(); |
|
1148 QVERIFY(o1 != 0); |
|
1149 QCOMPARE(o1->parent(), (QObject*)0); |
|
1150 QVERIFY(qobject_cast<CtorTestClass*>(o1) != 0); |
|
1151 |
|
1152 QObject *o2 = mo->newInstance(Q_ARG(QObject*, o1)); |
|
1153 QVERIFY(o2 != 0); |
|
1154 QCOMPARE(o2->parent(), o1); |
|
1155 |
|
1156 QString str = QString::fromLatin1("hello"); |
|
1157 QObject *o3 = mo->newInstance(Q_ARG(QString, str)); |
|
1158 QVERIFY(o3 != 0); |
|
1159 QCOMPARE(qobject_cast<CtorTestClass*>(o3)->m_str, str); |
|
1160 |
|
1161 { |
|
1162 //explicit constructor |
|
1163 QObject *o = QObject::staticMetaObject.newInstance(); |
|
1164 QVERIFY(o); |
|
1165 delete o; |
|
1166 } |
|
1167 } |
|
1168 |
|
1169 #include "task234909.h" |
|
1170 |
|
1171 #include "task240368.h" |
|
1172 |
|
1173 void tst_Moc::typenameWithUnsigned() |
|
1174 { |
|
1175 TypenameWithUnsigned tst; |
|
1176 const QMetaObject *mobj = tst.metaObject(); |
|
1177 QVERIFY(mobj->indexOfSlot("a(uint)") != -1); |
|
1178 QVERIFY(mobj->indexOfSlot("b(uint)") != -1); |
|
1179 QVERIFY(mobj->indexOfSlot("c(uint*)") != -1); |
|
1180 QVERIFY(mobj->indexOfSlot("d(uint*)") != -1); |
|
1181 QVERIFY(mobj->indexOfSlot("e(uint&)") != -1); |
|
1182 QVERIFY(mobj->indexOfSlot("f(uint&)") != -1); |
|
1183 QVERIFY(mobj->indexOfSlot("g(unsigned1)") != -1); |
|
1184 QVERIFY(mobj->indexOfSlot("h(unsigned1)") != -1); |
|
1185 QVERIFY(mobj->indexOfSlot("i(uint,unsigned1)") != -1); |
|
1186 QVERIFY(mobj->indexOfSlot("j(unsigned1,uint)") != -1); |
|
1187 QVERIFY(mobj->indexOfSlot("k(unsignedQImage)") != -1); |
|
1188 QVERIFY(mobj->indexOfSlot("l(unsignedQImage)") != -1); |
|
1189 } |
|
1190 |
|
1191 |
|
1192 void tst_Moc::warnOnVirtualSignal() |
|
1193 { |
|
1194 #ifdef MOC_CROSS_COMPILED |
|
1195 QSKIP("Not tested when cross-compiled", SkipAll); |
|
1196 #endif |
|
1197 #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) |
|
1198 QProcess proc; |
|
1199 proc.start("moc", QStringList(srcify("pure-virtual-signals.h"))); |
|
1200 QVERIFY(proc.waitForFinished()); |
|
1201 QCOMPARE(proc.exitCode(), 0); |
|
1202 QByteArray mocOut = proc.readAllStandardOutput(); |
|
1203 QVERIFY(!mocOut.isEmpty()); |
|
1204 QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError()); |
|
1205 QCOMPARE(mocWarning, QString(SRCDIR) + QString("/pure-virtual-signals.h:48: Warning: Signals cannot be declared virtual\n") + |
|
1206 QString(SRCDIR) + QString("/pure-virtual-signals.h:50: Warning: Signals cannot be declared virtual\n")); |
|
1207 #else |
|
1208 QSKIP("Only tested on linux/gcc", SkipAll); |
|
1209 #endif |
|
1210 } |
|
1211 |
|
1212 QTEST_APPLESS_MAIN(tst_Moc) |
|
1213 #include "tst_moc.moc" |
|
1214 |
|
1215 |
|
1216 |