util/tests/auto/moc/tst_moc.cpp
changeset 7 f7bc934e204c
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 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&lt;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 qprivateproperties();
       
   488     void inlineSlotsWithThrowDeclaration();
       
   489     void warnOnPropertyWithoutREAD();
       
   490     void constructors();
       
   491     void typenameWithUnsigned();
       
   492     void warnOnVirtualSignal();
       
   493     void QTBUG5590_dummyProperty();
       
   494 signals:
       
   495     void sigWithUnsignedArg(unsigned foo);
       
   496     void sigWithSignedArg(signed foo);
       
   497     void sigWithConstSignedArg(const signed foo);
       
   498     void sigWithVolatileConstSignedArg(volatile const signed foo);
       
   499     void sigWithCustomType(const MyStruct);
       
   500     void constSignal1() const;
       
   501     void constSignal2(int arg) const;
       
   502 
       
   503 private:
       
   504     bool user1() { return true; };
       
   505     bool user2() { return false; };
       
   506     bool user3() { return false; };
       
   507     bool userFunction(){ return false; };
       
   508 
       
   509 private:
       
   510     QString qtIncludePath;
       
   511 };
       
   512 
       
   513 void tst_Moc::initTestCase()
       
   514 {
       
   515 #if defined(Q_OS_UNIX) && !defined(QT_NO_PROCESS)
       
   516     QProcess proc;
       
   517     proc.start("qmake", QStringList() << "-query" << "QT_INSTALL_HEADERS");
       
   518     QVERIFY(proc.waitForFinished());
       
   519     QCOMPARE(proc.exitCode(), 0);
       
   520     QByteArray output = proc.readAllStandardOutput();
       
   521     QVERIFY(!output.isEmpty());
       
   522     QCOMPARE(proc.readAllStandardError(), QByteArray());
       
   523     qtIncludePath = QString::fromLocal8Bit(output).trimmed();
       
   524     QFileInfo fi(qtIncludePath);
       
   525     QVERIFY(fi.exists());
       
   526     QVERIFY(fi.isDir());
       
   527 #endif
       
   528 }
       
   529 
       
   530 void tst_Moc::slotWithException() throw(MyStruct)
       
   531 {
       
   532     // be happy
       
   533     QVERIFY(true);
       
   534 }
       
   535 
       
   536 void tst_Moc::dontStripNamespaces()
       
   537 {
       
   538     Sender sender;
       
   539     Receiver receiver;
       
   540 
       
   541     connect(&sender, SIGNAL(send(const String::Type &)),
       
   542             &receiver, SLOT(receive(const String::Type &)));
       
   543     connect(&sender, SIGNAL(send(const Int::Type &)),
       
   544             &receiver, SLOT(receive(const Int::Type &)));
       
   545 
       
   546     sender.sendValue(String::Type("Hello"));
       
   547     QCOMPARE(receiver.stringCallCount, 1);
       
   548     QCOMPARE(receiver.intCallCount, 0);
       
   549     sender.sendValue(Int::Type(42));
       
   550     QCOMPARE(receiver.stringCallCount, 1);
       
   551     QCOMPARE(receiver.intCallCount, 1);
       
   552 }
       
   553 
       
   554 
       
   555 void tst_Moc::oldStyleCasts()
       
   556 {
       
   557 #ifdef MOC_CROSS_COMPILED
       
   558     QSKIP("Not tested when cross-compiled", SkipAll);
       
   559 #endif
       
   560 #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
       
   561     QProcess proc;
       
   562     proc.start("moc", QStringList(srcify("/oldstyle-casts.h")));
       
   563     QVERIFY(proc.waitForFinished());
       
   564     QCOMPARE(proc.exitCode(), 0);
       
   565     QByteArray mocOut = proc.readAllStandardOutput();
       
   566     QVERIFY(!mocOut.isEmpty());
       
   567     QCOMPARE(proc.readAllStandardError(), QByteArray());
       
   568 
       
   569     QStringList args;
       
   570     args << "-c" << "-x" << "c++" << "-Wold-style-cast" << "-I" << "."
       
   571          << "-I" << qtIncludePath << "-o" << "/dev/null" << "-";
       
   572     proc.start("gcc", args);
       
   573     QVERIFY(proc.waitForStarted());
       
   574     proc.write(mocOut);
       
   575     proc.closeWriteChannel();
       
   576 
       
   577     QVERIFY(proc.waitForFinished());
       
   578     QCOMPARE(proc.exitCode(), 0);
       
   579     QCOMPARE(QString::fromLocal8Bit(proc.readAllStandardError()), QString());
       
   580 #else
       
   581     QSKIP("Only tested on linux/gcc", SkipAll);
       
   582 #endif
       
   583 }
       
   584 
       
   585 void tst_Moc::warnOnExtraSignalSlotQualifiaction()
       
   586 {
       
   587 #ifdef MOC_CROSS_COMPILED
       
   588     QSKIP("Not tested when cross-compiled", SkipAll);
       
   589 #endif
       
   590 #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
       
   591     QProcess proc;
       
   592     proc.start("moc", QStringList(srcify("extraqualification.h")));
       
   593     QVERIFY(proc.waitForFinished());
       
   594     QCOMPARE(proc.exitCode(), 0);
       
   595     QByteArray mocOut = proc.readAllStandardOutput();
       
   596     QVERIFY(!mocOut.isEmpty());
       
   597     QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError());
       
   598     QCOMPARE(mocWarning, QString(SRCDIR) +
       
   599                 QString("/extraqualification.h:53: Warning: Function declaration Test::badFunctionDeclaration contains extra qualification. Ignoring as signal or slot.\n") +
       
   600                 QString(SRCDIR) + QString("/extraqualification.h:56: Warning: parsemaybe: Function declaration Test::anotherOne contains extra qualification. Ignoring as signal or slot.\n"));
       
   601 #else
       
   602     QSKIP("Only tested on linux/gcc", SkipAll);
       
   603 #endif
       
   604 }
       
   605 
       
   606 void tst_Moc::uLongLong()
       
   607 {
       
   608 #ifndef NOLONGLONG
       
   609     TestClass tst;
       
   610     const QMetaObject *mobj = tst.metaObject();
       
   611     int idx = mobj->indexOfSlot("slotWithULong(ulong)");
       
   612     QVERIFY(idx != -1);
       
   613     idx = mobj->indexOfSlot("slotWithULongLong(unsigned long long)");
       
   614     QVERIFY(idx != -1);
       
   615     idx = mobj->indexOfSlot("slotWithULongLongP(unsigned long long*)");
       
   616     QVERIFY(idx != -1);
       
   617 
       
   618     idx = mobj->indexOfSlot("slotWithLong(long)");
       
   619     QVERIFY(idx != -1);
       
   620     idx = mobj->indexOfSlot("slotWithLongLong(long long)");
       
   621     QVERIFY(idx != -1);
       
   622 #else
       
   623     QSKIP("long long doesn't work on MSVC6 & .NET 2002, also skipped on 2003 due to compiler version issue with moc", SkipAll);
       
   624 #endif
       
   625 }
       
   626 
       
   627 void tst_Moc::inputFileNameWithDotsButNoExtension()
       
   628 {
       
   629 #ifdef MOC_CROSS_COMPILED
       
   630     QSKIP("Not tested when cross-compiled", SkipAll);
       
   631 #endif
       
   632 #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
       
   633     QProcess proc;
       
   634     proc.setWorkingDirectory(QString(SRCDIR) + "/task71021");
       
   635     proc.start("moc", QStringList("../Header"));
       
   636     QVERIFY(proc.waitForFinished());
       
   637     QCOMPARE(proc.exitCode(), 0);
       
   638     QByteArray mocOut = proc.readAllStandardOutput();
       
   639     QVERIFY(!mocOut.isEmpty());
       
   640     QCOMPARE(proc.readAllStandardError(), QByteArray());
       
   641 
       
   642     QStringList args;
       
   643     args << "-c" << "-x" << "c++" << "-I" << ".."
       
   644          << "-I" << qtIncludePath << "-o" << "/dev/null" << "-";
       
   645     proc.start("gcc", args);
       
   646     QVERIFY(proc.waitForStarted());
       
   647     proc.write(mocOut);
       
   648     proc.closeWriteChannel();
       
   649 
       
   650     QVERIFY(proc.waitForFinished());
       
   651     QCOMPARE(QString::fromLocal8Bit(proc.readAllStandardError()), QString());
       
   652     QCOMPARE(proc.exitCode(), 0);
       
   653 #else
       
   654     QSKIP("Only tested on linux/gcc", SkipAll);
       
   655 #endif
       
   656 }
       
   657 
       
   658 void tst_Moc::userProperties()
       
   659 {
       
   660     const QMetaObject *mobj = metaObject();
       
   661     QMetaProperty property = mobj->property(mobj->indexOfProperty("user1"));
       
   662     QVERIFY(property.isValid());
       
   663     QVERIFY(property.isUser());
       
   664 
       
   665     property = mobj->property(mobj->indexOfProperty("user2"));
       
   666     QVERIFY(property.isValid());
       
   667     QVERIFY(!property.isUser());
       
   668 
       
   669     property = mobj->property(mobj->indexOfProperty("user3"));
       
   670     QVERIFY(property.isValid());
       
   671     QVERIFY(!property.isUser(this));
       
   672 }
       
   673 
       
   674 void tst_Moc::supportConstSignals()
       
   675 {
       
   676     QSignalSpy spy1(this, SIGNAL(constSignal1()));
       
   677     QVERIFY(spy1.isEmpty());
       
   678     emit constSignal1();
       
   679     QCOMPARE(spy1.count(), 1);
       
   680 
       
   681     QSignalSpy spy2(this, SIGNAL(constSignal2(int)));
       
   682     QVERIFY(spy2.isEmpty());
       
   683     emit constSignal2(42);
       
   684     QCOMPARE(spy2.count(), 1);
       
   685     QCOMPARE(spy2.at(0).at(0).toInt(), 42);
       
   686 }
       
   687 
       
   688 #include "task87883.h"
       
   689 
       
   690 void tst_Moc::task87883()
       
   691 {
       
   692     QVERIFY(Task87883::staticMetaObject.className());
       
   693 }
       
   694 
       
   695 #include "c-comments.h"
       
   696 
       
   697 void tst_Moc::multilineComments()
       
   698 {
       
   699     QVERIFY(IfdefedClass::staticMetaObject.className());
       
   700 }
       
   701 
       
   702 void tst_Moc::classinfoWithEscapes()
       
   703 {
       
   704     const QMetaObject *mobj = &TestClassinfoWithEscapes::staticMetaObject;
       
   705     QCOMPARE(mobj->methodCount() - mobj->methodOffset(), 1);
       
   706 
       
   707     QMetaMethod mm = mobj->method(mobj->methodOffset());
       
   708     QCOMPARE(mm.signature(), "slotWithAReallyLongName(int)");
       
   709 }
       
   710 
       
   711 void tst_Moc::trNoopInClassInfo()
       
   712 {
       
   713     TestClass t;
       
   714     const QMetaObject *mobj = t.metaObject();
       
   715     QVERIFY(mobj);
       
   716     QCOMPARE(mobj->classInfoCount(), 3);
       
   717     QCOMPARE(mobj->indexOfClassInfo("help"), 0);
       
   718     QCOMPARE(QString(mobj->classInfo(0).value()), QString("Opening this will let you configure something"));
       
   719 }
       
   720 
       
   721 void tst_Moc::ppExpressionEvaluation()
       
   722 {
       
   723     TestClass tst;
       
   724     const QMetaObject *mobj = tst.metaObject();
       
   725     int idx = mobj->indexOfSlot("expressionEvaluationShortcut1()");
       
   726     QVERIFY(idx != -1);
       
   727 
       
   728     idx = mobj->indexOfSlot("expressionEvaluationShortcut2()");
       
   729     QVERIFY(idx != -1);
       
   730 }
       
   731 
       
   732 void tst_Moc::arrayArguments()
       
   733 {
       
   734     TestClass tst;
       
   735     const QMetaObject *mobj = tst.metaObject();
       
   736     QVERIFY(mobj->indexOfSlot("slotWithArray(const double[3])") != -1);
       
   737     QVERIFY(mobj->indexOfSlot("slotWithNamedArray(const double[3])") != -1);
       
   738     QVERIFY(mobj->indexOfSlot("slotWithMultiArray(const double[3][4])") != -1);
       
   739     QVERIFY(mobj->indexOfSignal("signalWithArray(const double[3])") != -1);
       
   740     QVERIFY(mobj->indexOfSignal("signalWithNamedArray(const double[3])") != -1);
       
   741 }
       
   742 
       
   743 void tst_Moc::preprocessorConditionals()
       
   744 {
       
   745     TestClass tst;
       
   746     const QMetaObject *mobj = tst.metaObject();
       
   747     QVERIFY(mobj->indexOfSlot("slotInElse()") != -1);
       
   748     QVERIFY(mobj->indexOfSlot("slotInIf()") != -1);
       
   749     QVERIFY(mobj->indexOfSlot("slotInLastElse()") != -1);
       
   750     QVERIFY(mobj->indexOfSlot("slotInElif()") != -1);
       
   751 }
       
   752 
       
   753 void tst_Moc::blackslashNewlines()
       
   754 {
       
   755     BackslashNewlines tst;
       
   756     const QMetaObject *mobj = tst.metaObject();
       
   757     QVERIFY(mobj->indexOfSlot("works()") != -1);
       
   758     QVERIFY(mobj->indexOfSlot("buggy()") == -1);
       
   759 }
       
   760 
       
   761 void tst_Moc::slotWithSillyConst()
       
   762 {
       
   763     TestClass tst;
       
   764     const QMetaObject *mobj = tst.metaObject();
       
   765     QVERIFY(mobj->indexOfSlot("slotWithSillyConst()") != -1);
       
   766     QVERIFY(mobj->indexOfMethod("slotWithSillyConst2()") != -1);
       
   767     QVERIFY(mobj->indexOfSlot("slotWithVoidStar(void*)") != -1);
       
   768 }
       
   769 
       
   770 void tst_Moc::testExtraData()
       
   771 {
       
   772     const QMetaObject *mobj = &PropertyTestClass::staticMetaObject;
       
   773     QCOMPARE(mobj->enumeratorCount(), 1);
       
   774     QCOMPARE(QByteArray(mobj->enumerator(0).name()), QByteArray("TestEnum"));
       
   775 
       
   776     mobj = &PropertyUseClass::staticMetaObject;
       
   777     const int idx = mobj->indexOfProperty("foo");
       
   778     QVERIFY(idx != -1);
       
   779     const QMetaProperty prop = mobj->property(idx);
       
   780     QVERIFY(prop.isValid());
       
   781     QVERIFY(prop.isEnumType());
       
   782     const QMetaEnum en = prop.enumerator();
       
   783     QCOMPARE(QByteArray(en.name()), QByteArray("TestEnum"));
       
   784 }
       
   785 
       
   786 void tst_Moc::namespaceTypeProperty()
       
   787 {
       
   788     qRegisterMetaType<myNS::Points>("myNS::Points");
       
   789     TestClass tst;
       
   790     QByteArray ba = QByteArray("points");
       
   791     QVariant v = tst.property(ba);
       
   792     QVERIFY(v.isValid());
       
   793     myNS::Points p = qVariantValue<myNS::Points>(v);
       
   794     QCOMPARE(p.p1, 0xBEEF);
       
   795     QCOMPARE(p.p2, 0xBABE);
       
   796     p.p1 = 0xCAFE;
       
   797     p.p2 = 0x1EE7;
       
   798     QVERIFY(tst.setProperty(ba, qVariantFromValue(p)));
       
   799     myNS::Points pp = qVariantValue<myNS::Points>(tst.property(ba));
       
   800     QCOMPARE(p.p1, pp.p1);
       
   801     QCOMPARE(p.p2, pp.p2);
       
   802 }
       
   803 
       
   804 void tst_Moc::slotsWithVoidTemplate()
       
   805 {
       
   806     SlotsWithVoidTemplateTest test;
       
   807     QVERIFY(QObject::connect(&test, SIGNAL(myVoidSignal(void)),
       
   808                              &test, SLOT(dummySlot(void))));
       
   809     QVERIFY(QObject::connect(&test, SIGNAL(mySignal(const TestTemplate<void> &)),
       
   810                              &test, SLOT(anotherSlot(const TestTemplate<void> &))));
       
   811 }
       
   812 
       
   813 void tst_Moc::structQObject()
       
   814 {
       
   815     StructQObject o;
       
   816     QCOMPARE(QByteArray(o.metaObject()->className()), QByteArray("StructQObject"));
       
   817 }
       
   818 
       
   819 #include "namespaced-flags.h"
       
   820 
       
   821 Q_DECLARE_METATYPE(QList<Foo::Bar::Flags>);
       
   822 
       
   823 void tst_Moc::namespacedFlags()
       
   824 {
       
   825     Foo::Baz baz;
       
   826     Foo::Bar bar;
       
   827 
       
   828     bar.setFlags(Foo::Bar::Read | Foo::Bar::Write);
       
   829     QVERIFY(baz.flags() != bar.flags());
       
   830 
       
   831     const QVariant v = bar.property("flags");
       
   832     QVERIFY(v.isValid());
       
   833     QVERIFY(baz.setProperty("flags", v));
       
   834     QVERIFY(baz.flags() == bar.flags());
       
   835 
       
   836     QList<Foo::Bar::Flags> l;
       
   837     l << baz.flags();
       
   838     QVariant v2 = baz.setProperty("flagsList", QVariant::fromValue(l));
       
   839     QCOMPARE(l, baz.flagsList());
       
   840     QCOMPARE(l, qvariant_cast<QList<Foo::Bar::Flags> >(baz.property("flagsList")));
       
   841 }
       
   842 
       
   843 void tst_Moc::warnOnMultipleInheritance()
       
   844 {
       
   845 #ifdef MOC_CROSS_COMPILED
       
   846     QSKIP("Not tested when cross-compiled", SkipAll);
       
   847 #endif
       
   848 #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
       
   849     QProcess proc;
       
   850     QStringList args;
       
   851     args << "-I" << qtIncludePath + "/QtGui"
       
   852          << srcify("warn-on-multiple-qobject-subclasses.h");
       
   853     proc.start("moc", args);
       
   854     QVERIFY(proc.waitForFinished());
       
   855     QCOMPARE(proc.exitCode(), 0);
       
   856     QByteArray mocOut = proc.readAllStandardOutput();
       
   857     QVERIFY(!mocOut.isEmpty());
       
   858     QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError());
       
   859     QCOMPARE(mocWarning, QString(SRCDIR) +
       
   860                 QString("/warn-on-multiple-qobject-subclasses.h:53: Warning: Class Bar inherits from two QObject subclasses QWidget and Foo. This is not supported!\n"));
       
   861 #else
       
   862     QSKIP("Only tested on linux/gcc", SkipAll);
       
   863 #endif
       
   864 }
       
   865 
       
   866 void tst_Moc::forgottenQInterface()
       
   867 {
       
   868 #ifdef MOC_CROSS_COMPILED
       
   869     QSKIP("Not tested when cross-compiled", SkipAll);
       
   870 #endif
       
   871 #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
       
   872     QProcess proc;
       
   873     QStringList args;
       
   874     args << "-I" << qtIncludePath + "/QtCore"
       
   875          << srcify("forgotten-qinterface.h");
       
   876     proc.start("moc", args);
       
   877     QVERIFY(proc.waitForFinished());
       
   878     QCOMPARE(proc.exitCode(), 0);
       
   879     QByteArray mocOut = proc.readAllStandardOutput();
       
   880     QVERIFY(!mocOut.isEmpty());
       
   881     QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError());
       
   882     QCOMPARE(mocWarning, QString(SRCDIR) +
       
   883                 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"));
       
   884 #else
       
   885     QSKIP("Only tested on linux/gcc", SkipAll);
       
   886 #endif
       
   887 }
       
   888 
       
   889 void tst_Moc::os9Newline()
       
   890 {
       
   891 #if !defined(SKIP_NEWLINE_TEST)
       
   892     const QMetaObject &mo = Os9Newlines::staticMetaObject;
       
   893     QVERIFY(mo.indexOfSlot("testSlot()") != -1);
       
   894     QFile f(srcify("os9-newlines.h"));
       
   895     QVERIFY(f.open(QIODevice::ReadOnly)); // no QIODevice::Text!
       
   896     QByteArray data = f.readAll();
       
   897     f.close();
       
   898     QVERIFY(!data.contains('\n'));
       
   899     QVERIFY(data.contains('\r'));
       
   900 #endif
       
   901 }
       
   902 
       
   903 void tst_Moc::winNewline()
       
   904 {
       
   905 #if !defined(SKIP_NEWLINE_TEST)
       
   906     const QMetaObject &mo = WinNewlines::staticMetaObject;
       
   907     QVERIFY(mo.indexOfSlot("testSlot()") != -1);
       
   908     QFile f(srcify("win-newlines.h"));
       
   909     QVERIFY(f.open(QIODevice::ReadOnly)); // no QIODevice::Text!
       
   910     QByteArray data = f.readAll();
       
   911     f.close();
       
   912     for (int i = 0; i < data.count(); ++i) {
       
   913         if (data.at(i) == QLatin1Char('\r')) {
       
   914             QVERIFY(i < data.count() - 1);
       
   915             ++i;
       
   916             QVERIFY(data.at(i) == '\n');
       
   917         } else {
       
   918             QVERIFY(data.at(i) != '\n');
       
   919         }
       
   920     }
       
   921 #endif
       
   922 }
       
   923 
       
   924 void tst_Moc::escapesInStringLiterals()
       
   925 {
       
   926     const QMetaObject &mo = StringLiterals::staticMetaObject;
       
   927     QCOMPARE(mo.classInfoCount(), 3);
       
   928 
       
   929     int idx = mo.indexOfClassInfo("Test");
       
   930     QVERIFY(idx != -1);
       
   931     QMetaClassInfo info = mo.classInfo(idx);
       
   932     QCOMPARE(QByteArray(info.value()),
       
   933              QByteArray("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\x53"));
       
   934 
       
   935     QVERIFY(idx != -1);
       
   936     idx = mo.indexOfClassInfo("Test2");
       
   937     info = mo.classInfo(idx);
       
   938     QCOMPARE(QByteArray(info.value()),
       
   939              QByteArray("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\123"));
       
   940 
       
   941     QVERIFY(idx != -1);
       
   942     idx = mo.indexOfClassInfo("Test3");
       
   943     info = mo.classInfo(idx);
       
   944     QCOMPARE(QByteArray(info.value()),
       
   945              QByteArray("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nb"));
       
   946 }
       
   947 
       
   948 void tst_Moc::frameworkSearchPath()
       
   949 {
       
   950 #ifdef MOC_CROSS_COMPILED
       
   951     QSKIP("Not tested when cross-compiled", SkipAll);
       
   952 #endif
       
   953 #if defined(Q_OS_UNIX) && !defined(QT_NO_PROCESS)
       
   954     QStringList args;
       
   955     args << "-F" << srcify(".")
       
   956          << srcify("interface-from-framework.h")
       
   957          ;
       
   958 
       
   959     QProcess proc;
       
   960     proc.start("moc", args);
       
   961     bool finished = proc.waitForFinished();
       
   962     if (!finished)
       
   963         qWarning("waitForFinished failed. QProcess error: %d", (int)proc.error());
       
   964     QVERIFY(finished);
       
   965     if (proc.exitCode() != 0) {
       
   966         qDebug() << proc.readAllStandardError();
       
   967     }
       
   968     QCOMPARE(proc.exitCode(), 0);
       
   969     QCOMPARE(proc.readAllStandardError(), QByteArray());
       
   970 #else
       
   971     QSKIP("Only tested/relevant on unixy platforms", SkipAll);
       
   972 #endif
       
   973 }
       
   974 
       
   975 void tst_Moc::cstyleEnums()
       
   976 {
       
   977     const QMetaObject &obj = CStyleEnums::staticMetaObject;
       
   978     QCOMPARE(obj.enumeratorCount(), 1);
       
   979     QMetaEnum metaEnum = obj.enumerator(0);
       
   980     QCOMPARE(metaEnum.name(), "Baz");
       
   981     QCOMPARE(metaEnum.keyCount(), 2);
       
   982     QCOMPARE(metaEnum.key(0), "Foo");
       
   983     QCOMPARE(metaEnum.key(1), "Bar");
       
   984 }
       
   985 
       
   986 void tst_Moc::templateGtGt()
       
   987 {
       
   988 #ifdef MOC_CROSS_COMPILED
       
   989     QSKIP("Not tested when cross-compiled", SkipAll);
       
   990 #endif
       
   991 #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
       
   992     QProcess proc;
       
   993     proc.start("moc", QStringList(srcify("template-gtgt.h")));
       
   994     QVERIFY(proc.waitForFinished());
       
   995     QCOMPARE(proc.exitCode(), 0);
       
   996     QByteArray mocOut = proc.readAllStandardOutput();
       
   997     QVERIFY(!mocOut.isEmpty());
       
   998     QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError());
       
   999     QVERIFY(mocWarning.isEmpty());
       
  1000 #else
       
  1001     QSKIP("Only tested on linux/gcc", SkipAll);
       
  1002 #endif
       
  1003 }
       
  1004 
       
  1005 void tst_Moc::defineMacroViaCmdline()
       
  1006 {
       
  1007 #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
       
  1008     QProcess proc;
       
  1009 
       
  1010     QStringList args;
       
  1011     args << "-DFOO";
       
  1012     args << srcify("macro-on-cmdline.h");
       
  1013 
       
  1014     proc.start("moc", args);
       
  1015     QVERIFY(proc.waitForFinished());
       
  1016     QCOMPARE(proc.exitCode(), 0);
       
  1017     QCOMPARE(proc.readAllStandardError(), QByteArray());
       
  1018     QByteArray mocOut = proc.readAllStandardOutput();
       
  1019     QVERIFY(!mocOut.isEmpty());
       
  1020 #else
       
  1021     QSKIP("Only tested on linux/gcc", SkipAll);
       
  1022 #endif
       
  1023 }
       
  1024 
       
  1025 void tst_Moc::invokable()
       
  1026 {
       
  1027     {
       
  1028         const QMetaObject &mobj = InvokableBeforeReturnType::staticMetaObject;
       
  1029         QCOMPARE(mobj.methodCount(), 5);
       
  1030         QVERIFY(mobj.method(4).signature() == QByteArray("foo()"));
       
  1031     }
       
  1032 
       
  1033     {
       
  1034         const QMetaObject &mobj = InvokableBeforeInline::staticMetaObject;
       
  1035         QCOMPARE(mobj.methodCount(), 6);
       
  1036         QVERIFY(mobj.method(4).signature() == QByteArray("foo()"));
       
  1037         QVERIFY(mobj.method(5).signature() == QByteArray("bar()"));
       
  1038     }
       
  1039 }
       
  1040 
       
  1041 void tst_Moc::singleFunctionKeywordSignalAndSlot()
       
  1042 {
       
  1043     {
       
  1044         const QMetaObject &mobj = SingleFunctionKeywordBeforeReturnType::staticMetaObject;
       
  1045         QCOMPARE(mobj.methodCount(), 6);
       
  1046         QVERIFY(mobj.method(4).signature() == QByteArray("mySignal()"));
       
  1047         QVERIFY(mobj.method(5).signature() == QByteArray("mySlot()"));
       
  1048     }
       
  1049 
       
  1050     {
       
  1051         const QMetaObject &mobj = SingleFunctionKeywordBeforeInline::staticMetaObject;
       
  1052         QCOMPARE(mobj.methodCount(), 6);
       
  1053         QVERIFY(mobj.method(4).signature() == QByteArray("mySignal()"));
       
  1054         QVERIFY(mobj.method(5).signature() == QByteArray("mySlot()"));
       
  1055     }
       
  1056 
       
  1057     {
       
  1058         const QMetaObject &mobj = SingleFunctionKeywordAfterInline::staticMetaObject;
       
  1059         QCOMPARE(mobj.methodCount(), 6);
       
  1060         QVERIFY(mobj.method(4).signature() == QByteArray("mySignal()"));
       
  1061         QVERIFY(mobj.method(5).signature() == QByteArray("mySlot()"));
       
  1062     }
       
  1063 }
       
  1064 
       
  1065 #include "qprivateslots.h"
       
  1066 
       
  1067 void tst_Moc::qprivateslots()
       
  1068 {
       
  1069     TestQPrivateSlots tst;
       
  1070     const QMetaObject *mobj = tst.metaObject();
       
  1071     QVERIFY(mobj->indexOfSlot("_q_privateslot()") != -1);
       
  1072     QVERIFY(mobj->indexOfMethod("method1()") != -1); //tast204730
       
  1073 }
       
  1074 
       
  1075 class PrivatePropertyTest : public QObject
       
  1076 {
       
  1077     Q_OBJECT
       
  1078     Q_PROPERTY(int foo READ foo WRITE setFoo);
       
  1079     Q_PRIVATE_PROPERTY(d, int bar READ bar WRITE setBar);
       
  1080     Q_PRIVATE_PROPERTY(PrivatePropertyTest::d, int plop READ plop WRITE setPlop);
       
  1081     Q_PRIVATE_PROPERTY(PrivatePropertyTest::d_func(), int baz READ baz WRITE setBaz);
       
  1082     class MyDPointer {
       
  1083     public:
       
  1084         MyDPointer() : mBar(0), mPlop(0) {}
       
  1085         int bar() { return mBar ; }
       
  1086         void setBar(int value) { mBar = value; }
       
  1087         int plop() { return mPlop ; }
       
  1088         void setPlop(int value) { mPlop = value; }
       
  1089         int baz() { return mBaz ; }
       
  1090         void setBaz(int value) { mBaz = value; }
       
  1091     private:
       
  1092         int mBar;
       
  1093         int mPlop;
       
  1094         int mBaz;
       
  1095     };
       
  1096 public:
       
  1097     PrivatePropertyTest() : mFoo(0), d (new MyDPointer) {}
       
  1098     int foo() { return mFoo ; }
       
  1099     void setFoo(int value) { mFoo = value; }
       
  1100     MyDPointer *d_func() {return d;}
       
  1101 private:
       
  1102     int mFoo;
       
  1103     MyDPointer *d;
       
  1104 };
       
  1105 
       
  1106 
       
  1107 void tst_Moc::qprivateproperties()
       
  1108 {
       
  1109     PrivatePropertyTest test;
       
  1110 
       
  1111     test.setProperty("foo", 1);
       
  1112     QCOMPARE(test.property("foo"), qVariantFromValue(1));
       
  1113 
       
  1114     test.setProperty("bar", 2);
       
  1115     QCOMPARE(test.property("bar"), qVariantFromValue(2));
       
  1116 
       
  1117     test.setProperty("plop", 3);
       
  1118     QCOMPARE(test.property("plop"), qVariantFromValue(3));
       
  1119 
       
  1120     test.setProperty("baz", 4);
       
  1121     QCOMPARE(test.property("baz"), qVariantFromValue(4));
       
  1122 
       
  1123 }
       
  1124 
       
  1125 #include "task189996.h"
       
  1126 
       
  1127 void InlineSlotsWithThrowDeclaration::c() throw() {}
       
  1128 
       
  1129 void tst_Moc::inlineSlotsWithThrowDeclaration()
       
  1130 {
       
  1131     InlineSlotsWithThrowDeclaration tst;
       
  1132     const QMetaObject *mobj = tst.metaObject();
       
  1133     QVERIFY(mobj->indexOfSlot("a()") != -1);
       
  1134     QVERIFY(mobj->indexOfSlot("b()") != -1);
       
  1135     QVERIFY(mobj->indexOfSlot("c()") != -1);
       
  1136     QVERIFY(mobj->indexOfSlot("d()") != -1);
       
  1137     QVERIFY(mobj->indexOfSlot("e()") != -1);
       
  1138 }
       
  1139 
       
  1140 void tst_Moc::warnOnPropertyWithoutREAD()
       
  1141 {
       
  1142 #ifdef MOC_CROSS_COMPILED
       
  1143     QSKIP("Not tested when cross-compiled", SkipAll);
       
  1144 #endif
       
  1145 #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
       
  1146     QProcess proc;
       
  1147     proc.start("moc", QStringList(srcify("warn-on-property-without-read.h")));
       
  1148     QVERIFY(proc.waitForFinished());
       
  1149     QCOMPARE(proc.exitCode(), 0);
       
  1150     QByteArray mocOut = proc.readAllStandardOutput();
       
  1151     QVERIFY(!mocOut.isEmpty());
       
  1152     QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError());
       
  1153     QCOMPARE(mocWarning, QString(SRCDIR) +
       
  1154                 QString("/warn-on-property-without-read.h:46: Warning: Property declaration foo has no READ accessor function. The property will be invalid.\n"));
       
  1155 #else
       
  1156     QSKIP("Only tested on linux/gcc", SkipAll);
       
  1157 #endif
       
  1158 }
       
  1159 
       
  1160 void tst_Moc::constructors()
       
  1161 {
       
  1162     const QMetaObject *mo = &CtorTestClass::staticMetaObject;
       
  1163     QCOMPARE(mo->constructorCount(), 3);
       
  1164     {
       
  1165         QMetaMethod mm = mo->constructor(0);
       
  1166         QCOMPARE(mm.access(), QMetaMethod::Public);
       
  1167         QCOMPARE(mm.methodType(), QMetaMethod::Constructor);
       
  1168         QCOMPARE(mm.signature(), "CtorTestClass(QObject*)");
       
  1169         QCOMPARE(mm.typeName(), "");
       
  1170         QList<QByteArray> paramNames = mm.parameterNames();
       
  1171         QCOMPARE(paramNames.size(), 1);
       
  1172         QCOMPARE(paramNames.at(0), QByteArray("parent"));
       
  1173         QList<QByteArray> paramTypes = mm.parameterTypes();
       
  1174         QCOMPARE(paramTypes.size(), 1);
       
  1175         QCOMPARE(paramTypes.at(0), QByteArray("QObject*"));
       
  1176     }
       
  1177     {
       
  1178         QMetaMethod mm = mo->constructor(1);
       
  1179         QCOMPARE(mm.access(), QMetaMethod::Public);
       
  1180         QCOMPARE(mm.methodType(), QMetaMethod::Constructor);
       
  1181         QCOMPARE(mm.signature(), "CtorTestClass()");
       
  1182         QCOMPARE(mm.typeName(), "");
       
  1183         QCOMPARE(mm.parameterNames().size(), 0);
       
  1184         QCOMPARE(mm.parameterTypes().size(), 0);
       
  1185     }
       
  1186     {
       
  1187         QMetaMethod mm = mo->constructor(2);
       
  1188         QCOMPARE(mm.access(), QMetaMethod::Public);
       
  1189         QCOMPARE(mm.methodType(), QMetaMethod::Constructor);
       
  1190         QCOMPARE(mm.signature(), "CtorTestClass(QString)");
       
  1191         QCOMPARE(mm.typeName(), "");
       
  1192         QList<QByteArray> paramNames = mm.parameterNames();
       
  1193         QCOMPARE(paramNames.size(), 1);
       
  1194         QCOMPARE(paramNames.at(0), QByteArray("str"));
       
  1195         QList<QByteArray> paramTypes = mm.parameterTypes();
       
  1196         QCOMPARE(paramTypes.size(), 1);
       
  1197         QCOMPARE(paramTypes.at(0), QByteArray("QString"));
       
  1198     }
       
  1199 
       
  1200     QCOMPARE(mo->indexOfConstructor("CtorTestClass(QObject*)"), 0);
       
  1201     QCOMPARE(mo->indexOfConstructor("CtorTestClass()"), 1);
       
  1202     QCOMPARE(mo->indexOfConstructor("CtorTestClass(QString)"), 2);
       
  1203     QCOMPARE(mo->indexOfConstructor("CtorTestClass2(QObject*)"), -1);
       
  1204     QCOMPARE(mo->indexOfConstructor("CtorTestClass(float,float)"), -1);
       
  1205 
       
  1206     QObject *o1 = mo->newInstance();
       
  1207     QVERIFY(o1 != 0);
       
  1208     QCOMPARE(o1->parent(), (QObject*)0);
       
  1209     QVERIFY(qobject_cast<CtorTestClass*>(o1) != 0);
       
  1210 
       
  1211     QObject *o2 = mo->newInstance(Q_ARG(QObject*, o1));
       
  1212     QVERIFY(o2 != 0);
       
  1213     QCOMPARE(o2->parent(), o1);
       
  1214 
       
  1215     QString str = QString::fromLatin1("hello");
       
  1216     QObject *o3 = mo->newInstance(Q_ARG(QString, str));
       
  1217     QVERIFY(o3 != 0);
       
  1218     QCOMPARE(qobject_cast<CtorTestClass*>(o3)->m_str, str);
       
  1219 
       
  1220     {
       
  1221         //explicit constructor
       
  1222         QObject *o = QObject::staticMetaObject.newInstance();
       
  1223         QVERIFY(o);
       
  1224         delete o;
       
  1225     }
       
  1226 }
       
  1227 
       
  1228 #include "task234909.h"
       
  1229 
       
  1230 #include "task240368.h"
       
  1231 
       
  1232 void tst_Moc::typenameWithUnsigned()
       
  1233 {
       
  1234     TypenameWithUnsigned tst;
       
  1235     const QMetaObject *mobj = tst.metaObject();
       
  1236     QVERIFY(mobj->indexOfSlot("a(uint)") != -1);
       
  1237     QVERIFY(mobj->indexOfSlot("b(uint)") != -1);
       
  1238     QVERIFY(mobj->indexOfSlot("c(uint*)") != -1);
       
  1239     QVERIFY(mobj->indexOfSlot("d(uint*)") != -1);
       
  1240     QVERIFY(mobj->indexOfSlot("e(uint&)") != -1);
       
  1241     QVERIFY(mobj->indexOfSlot("f(uint&)") != -1);
       
  1242     QVERIFY(mobj->indexOfSlot("g(unsigned1)") != -1);
       
  1243     QVERIFY(mobj->indexOfSlot("h(unsigned1)") != -1);
       
  1244     QVERIFY(mobj->indexOfSlot("i(uint,unsigned1)") != -1);
       
  1245     QVERIFY(mobj->indexOfSlot("j(unsigned1,uint)") != -1);
       
  1246     QVERIFY(mobj->indexOfSlot("k(unsignedQImage)") != -1);
       
  1247     QVERIFY(mobj->indexOfSlot("l(unsignedQImage)") != -1);
       
  1248 }
       
  1249 
       
  1250 
       
  1251 void tst_Moc::warnOnVirtualSignal()
       
  1252 {
       
  1253 #ifdef MOC_CROSS_COMPILED
       
  1254     QSKIP("Not tested when cross-compiled", SkipAll);
       
  1255 #endif
       
  1256 #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
       
  1257     QProcess proc;
       
  1258     proc.start("moc", QStringList(srcify("pure-virtual-signals.h")));
       
  1259     QVERIFY(proc.waitForFinished());
       
  1260     QCOMPARE(proc.exitCode(), 0);
       
  1261     QByteArray mocOut = proc.readAllStandardOutput();
       
  1262     QVERIFY(!mocOut.isEmpty());
       
  1263     QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError());
       
  1264     QCOMPARE(mocWarning, QString(SRCDIR) + QString("/pure-virtual-signals.h:48: Warning: Signals cannot be declared virtual\n") +
       
  1265                          QString(SRCDIR) + QString("/pure-virtual-signals.h:50: Warning: Signals cannot be declared virtual\n"));
       
  1266 #else
       
  1267     QSKIP("Only tested on linux/gcc", SkipAll);
       
  1268 #endif
       
  1269 }
       
  1270 
       
  1271 
       
  1272 class QTBUG5590_DummyObject: public QObject
       
  1273 {
       
  1274     Q_OBJECT
       
  1275     Q_PROPERTY(bool dummy)
       
  1276 };
       
  1277 
       
  1278 class QTBUG5590_PropertyObject: public QTBUG5590_DummyObject
       
  1279 {
       
  1280     Q_OBJECT
       
  1281     Q_PROPERTY(int value READ value WRITE setValue)
       
  1282     Q_PROPERTY(int value2 READ value2 WRITE setValue2)
       
  1283 
       
  1284     public:
       
  1285         QTBUG5590_PropertyObject() :  m_value(85), m_value2(40) { }
       
  1286         int value() const { return m_value; }
       
  1287         void setValue(int value) { m_value = value; }
       
  1288         int value2() const { return m_value2; }
       
  1289         void setValue2(int value) { m_value2 = value; }
       
  1290     private:
       
  1291         int m_value, m_value2;
       
  1292 };
       
  1293 
       
  1294 void tst_Moc::QTBUG5590_dummyProperty()
       
  1295 {
       
  1296     QTBUG5590_PropertyObject o;
       
  1297     QCOMPARE(o.property("value").toInt(), 85);
       
  1298     QCOMPARE(o.property("value2").toInt(), 40);
       
  1299     o.setProperty("value", 32);
       
  1300     QCOMPARE(o.value(), 32);
       
  1301     o.setProperty("value2", 82);
       
  1302     QCOMPARE(o.value2(), 82);
       
  1303 }
       
  1304 
       
  1305 QTEST_APPLESS_MAIN(tst_Moc)
       
  1306 #include "tst_moc.moc"
       
  1307 
       
  1308 
       
  1309