From aea68c93ae437a761584719f0f1ca93eaf6f7484 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 22 Nov 2012 11:03:39 +0100 Subject: Proper macro replacment and branch evaluation Correclty replace macros according to the C++ standard. Use the correct replacement method also to evaluate With this moc correctly processes boost headers. Task-number: QTBUG-27546 Change-Id: I001b3054c5fcdc34d46cfa53d1387bd19436f361 Reviewed-by: Olivier Goffart --- tests/auto/tools/moc/parse-defines.h | 22 +++++++++++++++++++++- tests/auto/tools/moc/tst_moc.cpp | 19 +++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/tools/moc/parse-defines.h b/tests/auto/tools/moc/parse-defines.h index eb47253587..60415ac69a 100644 --- a/tests/auto/tools/moc/parse-defines.h +++ b/tests/auto/tools/moc/parse-defines.h @@ -52,6 +52,7 @@ #define PD_CLASSNAME ParseDefine #define PD_STRINGIFY(a) #a +#define PD_XSTRINGIFY(a) PD_STRINGIFY(a) #define PD_SCOPED_STRING(a, b) PD_STRINGIFY(a) "::" PD_STRINGIFY(b) #define PD_DEFINE1(a,b) a##b #define PD_DEFINE2(a,b) a comb##b @@ -81,7 +82,8 @@ class PD_CLASSNAME : public QObject { Q_OBJECT Q_CLASSINFO("TestString", PD_STRINGIFY(PD_CLASSNAME)) - PD_CLASSINFO("TestString2", "TestValue") + Q_CLASSINFO("TestString2", PD_XSTRINGIFY(PD_CLASSNAME)) + PD_CLASSINFO("TestString3", "TestValue") public: PD_CLASSNAME() {} @@ -108,6 +110,24 @@ public slots: PD_VARARGEXT(void vararg5, int) {} PD_VARARGEXT(void vararg6, int, int) {} #endif + +#define OUTERFUNCTION(x) x +#define INNERFUNCTION(x) OUTERFUNCTION(x) +#define INNER INNERFUNCTION + + void INNERFUNCTION(INNERFUNCTION)(int) {} + void OUTERFUNCTION(INNERFUNCTION)(inner_expanded(int)) {} + void expanded_method OUTERFUNCTION(INNER)((int)) {} + +#undef INNERFUNCTION + +#define cond1() 0x1 +#define cond2() 0x2 + +#if !(cond1() & cond2()) + void conditionSlot() {} +#endif + }; #undef QString diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index d861b84e00..e3ed473978 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -2752,19 +2752,34 @@ void tst_Moc::parseDefines() QVERIFY(index != -1); #endif + index = mo->indexOfSlot("INNERFUNCTION(int)"); + QVERIFY(index != -1); + index = mo->indexOfSlot("inner_expanded(int)"); + QVERIFY(index != -1); + index = mo->indexOfSlot("expanded_method(int)"); + QVERIFY(index != -1); + + index = mo->indexOfSlot("conditionSlot()"); + QVERIFY(index != -1); + int count = 0; for (int i = 0; i < mo->classInfoCount(); ++i) { QMetaClassInfo mci = mo->classInfo(i); if (!qstrcmp(mci.name(), "TestString")) { ++count; - QVERIFY(!qstrcmp(mci.value(), "ParseDefine")); + QVERIFY(!qstrcmp(mci.value(), "PD_CLASSNAME")); } if (!qstrcmp(mci.name(), "TestString2")) { + ++count; + qDebug() << mci.value(); + QVERIFY(!qstrcmp(mci.value(), "ParseDefine")); + } + if (!qstrcmp(mci.name(), "TestString3")) { ++count; QVERIFY(!qstrcmp(mci.value(), "TestValue")); } } - QVERIFY(count == 2); + QVERIFY(count == 3); } void tst_Moc::preprocessorOnly() -- cgit v1.2.3