summaryrefslogtreecommitdiffstats
path: root/tests/auto/moc/tst_moc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/moc/tst_moc.cpp')
-rw-r--r--tests/auto/moc/tst_moc.cpp265
1 files changed, 263 insertions, 2 deletions
diff --git a/tests/auto/moc/tst_moc.cpp b/tests/auto/moc/tst_moc.cpp
index 3e15bde..203f0ae 100644
--- a/tests/auto/moc/tst_moc.cpp
+++ b/tests/auto/moc/tst_moc.cpp
@@ -493,6 +493,12 @@ private slots:
void QTBUG5590_dummyProperty();
void QTBUG12260_defaultTemplate();
void notifyError();
+ void QTBUG17635_invokableAndProperty();
+ void revisions();
+ void warnings_data();
+ void warnings();
+
+
signals:
void sigWithUnsignedArg(unsigned foo);
void sigWithSignedArg(signed foo);
@@ -507,6 +513,7 @@ private:
bool user2() { return false; };
bool user3() { return false; };
bool userFunction(){ return false; };
+ template <class T> void revisions_T();
private:
QString qtIncludePath;
@@ -1384,9 +1391,263 @@ void tst_Moc::notifyError()
#endif
}
+class QTBUG_17635_InvokableAndProperty : public QObject
+{
+ Q_OBJECT
+public:
+ Q_PROPERTY(int numberOfEggs READ numberOfEggs)
+ Q_PROPERTY(int numberOfChickens READ numberOfChickens)
+ Q_INVOKABLE QString getEgg(int index) { return QString::fromLatin1("Egg"); }
+ Q_INVOKABLE QString getChicken(int index) { return QString::fromLatin1("Chicken"); }
+ int numberOfEggs() { return 2; }
+ int numberOfChickens() { return 4; }
+};
-QTEST_APPLESS_MAIN(tst_Moc)
-#include "tst_moc.moc"
+void tst_Moc::QTBUG17635_invokableAndProperty()
+{
+ //Moc used to fail parsing Q_INVOKABLE if they were dirrectly following a Q_PROPERTY;
+ QTBUG_17635_InvokableAndProperty mc;
+ QString val;
+ QMetaObject::invokeMethod(&mc, "getEgg", Q_RETURN_ARG(QString, val), Q_ARG(int, 10));
+ QCOMPARE(val, QString::fromLatin1("Egg"));
+ QMetaObject::invokeMethod(&mc, "getChicken", Q_RETURN_ARG(QString, val), Q_ARG(int, 10));
+ QCOMPARE(val, QString::fromLatin1("Chicken"));
+ QVERIFY(mc.metaObject()->indexOfProperty("numberOfEggs") != -1);
+ QVERIFY(mc.metaObject()->indexOfProperty("numberOfChickens") != -1);
+}
+
+// If changed, update VersionTestNotify below
+class VersionTest : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int prop1 READ foo)
+ Q_PROPERTY(int prop2 READ foo REVISION 2)
+ Q_ENUMS(TestEnum);
+
+public:
+ int foo() const { return 0; }
+
+ Q_INVOKABLE void method1() {}
+ Q_INVOKABLE Q_REVISION(4) void method2() {}
+
+ enum TestEnum { One, Two };
+
+public slots:
+ void slot1() {}
+ Q_REVISION(3) void slot2() {}
+
+signals:
+ void signal1();
+ Q_REVISION(5) void signal2();
+
+public slots Q_REVISION(6):
+ void slot3() {}
+ void slot4() {}
+
+signals Q_REVISION(7):
+ void signal3();
+ void signal4();
+};
+
+// If changed, update VersionTest above
+class VersionTestNotify : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int prop1 READ foo NOTIFY fooChanged)
+ Q_PROPERTY(int prop2 READ foo REVISION 2)
+ Q_ENUMS(TestEnum);
+
+public:
+ int foo() const { return 0; }
+
+ Q_INVOKABLE void method1() {}
+ Q_INVOKABLE Q_REVISION(4) void method2() {}
+
+ enum TestEnum { One, Two };
+
+public slots:
+ void slot1() {}
+ Q_REVISION(3) void slot2() {}
+
+signals:
+ void fooChanged();
+ void signal1();
+ Q_REVISION(5) void signal2();
+public slots Q_REVISION(6):
+ void slot3() {}
+ void slot4() {}
+signals Q_REVISION(7):
+ void signal3();
+ void signal4();
+};
+
+template <class T>
+void tst_Moc::revisions_T()
+{
+ int idx = T::staticMetaObject.indexOfProperty("prop1");
+ QVERIFY(T::staticMetaObject.property(idx).revision() == 0);
+ idx = T::staticMetaObject.indexOfProperty("prop2");
+ QVERIFY(T::staticMetaObject.property(idx).revision() == 2);
+
+ idx = T::staticMetaObject.indexOfMethod("method1()");
+ QVERIFY(T::staticMetaObject.method(idx).revision() == 0);
+ idx = T::staticMetaObject.indexOfMethod("method2()");
+ QVERIFY(T::staticMetaObject.method(idx).revision() == 4);
+
+ idx = T::staticMetaObject.indexOfSlot("slot1()");
+ QVERIFY(T::staticMetaObject.method(idx).revision() == 0);
+ idx = T::staticMetaObject.indexOfSlot("slot2()");
+ QVERIFY(T::staticMetaObject.method(idx).revision() == 3);
+
+ idx = T::staticMetaObject.indexOfSlot("slot3()");
+ QVERIFY(T::staticMetaObject.method(idx).revision() == 6);
+ idx = T::staticMetaObject.indexOfSlot("slot4()");
+ QVERIFY(T::staticMetaObject.method(idx).revision() == 6);
+
+ idx = T::staticMetaObject.indexOfSignal("signal1()");
+ QVERIFY(T::staticMetaObject.method(idx).revision() == 0);
+ idx = T::staticMetaObject.indexOfSignal("signal2()");
+ QVERIFY(T::staticMetaObject.method(idx).revision() == 5);
+
+ idx = T::staticMetaObject.indexOfSignal("signal3()");
+ QVERIFY(T::staticMetaObject.method(idx).revision() == 7);
+ idx = T::staticMetaObject.indexOfSignal("signal4()");
+ QVERIFY(T::staticMetaObject.method(idx).revision() == 7);
+
+ idx = T::staticMetaObject.indexOfEnumerator("TestEnum");
+ QCOMPARE(T::staticMetaObject.enumerator(idx).keyCount(), 2);
+ QCOMPARE(T::staticMetaObject.enumerator(idx).key(0), "One");
+}
+
+// test using both class that has properties with and without NOTIFY signals
+void tst_Moc::revisions()
+{
+ revisions_T<VersionTest>();
+ revisions_T<VersionTestNotify>();
+}
+
+void tst_Moc::warnings_data()
+{
+ QTest::addColumn<QByteArray>("input");
+ QTest::addColumn<QStringList>("args");
+ QTest::addColumn<int>("exitCode");
+ QTest::addColumn<QString>("expectedStdOut");
+ QTest::addColumn<QString>("expectedStdErr");
+
+ // empty input should result in "no relevant classes" note
+ QTest::newRow("No relevant classes")
+ << QByteArray(" ")
+ << QStringList()
+ << 0
+ << QString()
+ << QString("standard input:0: Note: No relevant classes found. No output generated.");
+
+ // passing "-nn" should suppress "no relevant classes" note
+ QTest::newRow("-nn")
+ << QByteArray(" ")
+ << (QStringList() << "-nn")
+ << 0
+ << QString()
+ << QString();
+
+ // passing "-nw" should also suppress "no relevant classes" note
+ QTest::newRow("-nw")
+ << QByteArray(" ")
+ << (QStringList() << "-nw")
+ << 0
+ << QString()
+ << QString();
+
+ // This should output a warning
+ QTest::newRow("Invalid property warning")
+ << QByteArray("class X : public QObject { Q_OBJECT Q_PROPERTY(int x) };")
+ << QStringList()
+ << 0
+ << QString("IGNORE_ALL_STDOUT")
+ << QString("standard input:1: Warning: Property declaration x has no READ accessor function. The property will be invalid.");
+
+ // Passing "-nn" should NOT suppress the warning
+ QTest::newRow("Invalid property warning")
+ << QByteArray("class X : public QObject { Q_OBJECT Q_PROPERTY(int x) };")
+ << (QStringList() << "-nn")
+ << 0
+ << QString("IGNORE_ALL_STDOUT")
+ << QString("standard input:1: Warning: Property declaration x has no READ accessor function. The property will be invalid.");
+
+ // Passing "-nw" should suppress the warning
+ QTest::newRow("Invalid property warning")
+ << QByteArray("class X : public QObject { Q_OBJECT Q_PROPERTY(int x) };")
+ << (QStringList() << "-nw")
+ << 0
+ << QString("IGNORE_ALL_STDOUT")
+ << QString();
+
+ // This should output an error
+ QTest::newRow("Does not inherit QObject")
+ << QByteArray("class X { Q_OBJECT };")
+ << QStringList()
+ << 1
+ << QString()
+ << QString("standard input:1: Error: Class contains Q_OBJECT macro but does not inherit from QObject");
+
+ // "-nn" should not suppress the error
+ QTest::newRow("Does not inherit QObject with -nn")
+ << QByteArray("class X { Q_OBJECT };")
+ << (QStringList() << "-nn")
+ << 1
+ << QString()
+ << QString("standard input:1: Error: Class contains Q_OBJECT macro but does not inherit from QObject");
+
+ // "-nw" should not suppress the error
+ QTest::newRow("Does not inherit QObject with -nn")
+ << QByteArray("class X { Q_OBJECT };")
+ << (QStringList() << "-nw")
+ << 1
+ << QString()
+ << QString("standard input:1: Error: Class contains Q_OBJECT macro but does not inherit from QObject");
+}
+
+void tst_Moc::warnings()
+{
+#ifdef MOC_CROSS_COMPILED
+ QSKIP("Not tested when cross-compiled", SkipAll);
+#endif
+
+ QFETCH(QByteArray, input);
+ QFETCH(QStringList, args);
+ QFETCH(int, exitCode);
+ QFETCH(QString, expectedStdOut);
+ QFETCH(QString, expectedStdErr);
+
+#ifdef Q_CC_MSVC
+ // for some reasons, moc compiled with MSVC uses a different output format
+ QRegExp lineNumberRe(":(\\d+):");
+ lineNumberRe.setMinimal(true);
+ expectedStdErr.replace(lineNumberRe, "(\\1):");
+#endif
+
+ QProcess proc;
+ proc.start("moc", args);
+ QVERIFY(proc.waitForStarted());
+
+ QCOMPARE(proc.write(input), qint64(input.size()));
+
+ proc.closeWriteChannel();
+
+ QVERIFY(proc.waitForFinished());
+
+ QCOMPARE(proc.exitCode(), exitCode);
+ QCOMPARE(proc.exitStatus(), QProcess::NormalExit);
+
+ // magic value "IGNORE_ALL_STDOUT" ignores stdout
+ if (expectedStdOut != "IGNORE_ALL_STDOUT")
+ QCOMPARE(QString::fromLocal8Bit(proc.readAllStandardOutput()).trimmed(), expectedStdOut);
+ QCOMPARE(QString::fromLocal8Bit(proc.readAllStandardError()).trimmed(), expectedStdErr);
+
+ }
+
+QTEST_APPLESS_MAIN(tst_Moc)
+#include "tst_moc.moc"