diff options
author | jasplin <jo.asplin@nokia.com> | 2011-06-08 15:13:13 (GMT) |
---|---|---|
committer | Rohan McGovern <rohan.mcgovern@nokia.com> | 2011-07-26 04:18:56 (GMT) |
commit | 01575deafb7d26ca2431374e92c6d71de96547c7 (patch) | |
tree | aa8499a652c4abfb5a1ec98e48612b133f0c2fdf /src/testlib | |
parent | 13ea186f3592815899f0cecc07a6094e2360a71e (diff) | |
download | Qt-01575deafb7d26ca2431374e92c6d71de96547c7.zip Qt-01575deafb7d26ca2431374e92c6d71de96547c7.tar.gz Qt-01575deafb7d26ca2431374e92c6d71de96547c7.tar.bz2 |
Added -datatags option to QTestLib
Passing the -datatags option to a QTestLib program prints the available
data tags to standard output.
Data tags for each test function (f() in this case) are printed in
four different ways depending on the presence of local and global
data tags:
Case 1: No tags:
f()
Case 2: Local tags only:
f() local tag 1
f() local tag 2
...
Case 3: Global tags only:
f() __global__ global tag 1
f() __global__ global tag 2
...
Case 4: Local and global tags:
f() local tag 1 __global__ global tag 1
f() local tag 2 __global__ global tag 1
...
f() local tag 1 __global__ global tag 2
f() local tag 2 __global__ global tag 2
...
...
Reviewed-by: Rohan McGovern
Task-number: QTQAINFRA-226
Change-Id: I14de203b586a0085b8efda8e62772711e44677d2
Diffstat (limited to 'src/testlib')
-rw-r--r-- | src/testlib/qtestcase.cpp | 63 | ||||
-rw-r--r-- | src/testlib/qtestlog.cpp | 11 |
2 files changed, 74 insertions, 0 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 023df89..efa0122 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1015,6 +1015,7 @@ static bool isValidSlot(const QMetaMethod &sl) } Q_TESTLIB_EXPORT bool printAvailableFunctions = false; +Q_TESTLIB_EXPORT bool printAvailableTags = false; Q_TESTLIB_EXPORT QStringList testFunctions; Q_TESTLIB_EXPORT QStringList testTags; @@ -1027,6 +1028,60 @@ static void qPrintTestSlots() } } +static void qPrintDataTags() +{ + // Get global data tags: + QTestTable::globalTestTable(); + invokeMethod(QTest::currentTestObject, "initTestCase_data()"); + const QTestTable *gTable = QTestTable::globalTestTable(); + + // Process test functions: + for (int i = 0; i < QTest::currentTestObject->metaObject()->methodCount(); ++i) { + QMetaMethod tf = QTest::currentTestObject->metaObject()->method(i); + if (isValidSlot(tf)) { + const char *slotName = tf.signature(); + + // Retrieve local tags: + QStringList localTags; + QTestTable table; + char member[512]; + char *slot = qstrdup(slotName); + slot[strlen(slot) - 2] = '\0'; + QTest::qt_snprintf(member, 512, "%s_data()", slot); + delete[] slot; + invokeMethod(QTest::currentTestObject, member); + for (int j = 0; j < table.dataCount(); ++j) + localTags << QLatin1String(table.testData(j)->dataTag()); + + // Print all tag combinations: + if (gTable->dataCount() == 0) { + if (localTags.count() == 0) { + // No tags at all, so just print the test function: + printf("%s\n", slotName); + } else { + // Only local tags, so print each of them: + for (int k = 0; k < localTags.size(); ++k) + printf("%s %s\n", slotName, localTags.at(k).toLatin1().data()); + } + } else { + for (int j = 0; j < gTable->dataCount(); ++j) { + if (localTags.count() == 0) { + // Only global tags, so print the current one: + printf("%s __global__ %s\n", slotName, gTable->testData(j)->dataTag()); + } else { + // Local and global tags, so print each of the local ones and + // the current global one: + for (int k = 0; k < localTags.size(); ++k) + printf( + "%s %s __global__ %s\n", slotName, + localTags.at(k).toLatin1().data(), gTable->testData(j)->dataTag()); + } + } + } + } + } +} + static int qToInt(char *str) { char *pEnd; @@ -1043,6 +1098,8 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) const char *testOptions = " options:\n" " -functions : Returns a list of current testfunctions\n" + " -datatags : Returns a list of current data tags.\n" + " A global data tag is preceded by ' __global__ '.\n" " -xunitxml : Outputs results as XML XUnit document\n" " -xml : Outputs results as XML document\n" " -lightxml : Outputs results as stream of XML tags\n" @@ -1094,6 +1151,12 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) qPrintTestSlots(); exit(0); } + } else if (strcmp(argv[i], "-datatags") == 0) { + QTest::printAvailableTags = true; + if (!qml) { + qPrintDataTags(); + exit(0); + } } else if(strcmp(argv[i], "-xunitxml") == 0){ QTestLog::setLogMode(QTestLog::XunitXML); } else if (strcmp(argv[i], "-xml") == 0) { diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp index 8a2d559..03fafe0 100644 --- a/src/testlib/qtestlog.cpp +++ b/src/testlib/qtestlog.cpp @@ -191,6 +191,8 @@ void initLogger() } } +extern Q_TESTLIB_EXPORT bool printAvailableTags; + } QTestLog::QTestLog() @@ -203,6 +205,9 @@ QTestLog::~QTestLog() void QTestLog::enterTestFunction(const char* function) { + if (QTest::printAvailableTags) + return; + QTEST_ASSERT(QTest::testLogger); QTEST_ASSERT(function); @@ -222,6 +227,9 @@ int QTestLog::unhandledIgnoreMessages() void QTestLog::leaveTestFunction() { + if (QTest::printAvailableTags) + return; + QTEST_ASSERT(QTest::testLogger); QTest::IgnoreResultList::clearList(QTest::ignoreResultList); @@ -244,6 +252,9 @@ void QTestLog::printUnhandledIgnoreMessages() void QTestLog::addPass(const char *msg) { + if (QTest::printAvailableTags) + return; + QTEST_ASSERT(QTest::testLogger); QTEST_ASSERT(msg); |