summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/qtestcase.cpp72
-rw-r--r--src/testlib/qtestlog.cpp16
-rw-r--r--src/testlib/qtestlog_p.h4
3 files changed, 92 insertions, 0 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 713004da4d..4e0205ccbc 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -1015,6 +1015,71 @@ static void qPrintTestSlots(FILE *stream)
}
}
+static void qPrintDataTags(FILE *stream)
+{
+ // Avoid invoking the actual test functions, and also avoid printing irrelevant output:
+ QTestLog::setPrintAvailableTagsMode();
+
+ // Get global data tags:
+ QTestTable::globalTestTable();
+ invokeMethod(QTest::currentTestObject, "initTestCase_data()");
+ const QTestTable *gTable = QTestTable::globalTestTable();
+
+ const QMetaObject *currTestMetaObj = QTest::currentTestObject->metaObject();
+
+ // Process test functions:
+ for (int i = 0; i < currTestMetaObj->methodCount(); ++i) {
+ QMetaMethod tf = currTestMetaObj->method(i);
+
+ if (isValidSlot(tf)) {
+
+ // Retrieve local tags:
+ QStringList localTags;
+ QTestTable table;
+ char *slot = qstrdup(tf.signature());
+ slot[strlen(slot) - 2] = '\0';
+ QByteArray member;
+ member.resize(qstrlen(slot) + qstrlen("_data()") + 1);
+ QTest::qt_snprintf(member.data(), member.size(), "%s_data()", slot);
+ invokeMethod(QTest::currentTestObject, member.constData());
+ 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:
+ fprintf(stream, "%s %s\n", currTestMetaObj->className(), slot);
+ } else {
+ // Only local tags, so print each of them:
+ for (int k = 0; k < localTags.size(); ++k)
+ fprintf(
+ stream, "%s %s %s\n",
+ currTestMetaObj->className(), slot, 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:
+ fprintf(
+ stream, "%s %s __global__ %s\n",
+ currTestMetaObj->className(), slot, 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)
+ fprintf(
+ stream, "%s %s %s __global__ %s\n", currTestMetaObj->className(), slot,
+ localTags.at(k).toLatin1().data(), gTable->testData(j)->dataTag());
+ }
+ }
+ }
+
+ delete[] slot;
+ }
+ }
+}
+
static int qToInt(char *str)
{
char *pEnd;
@@ -1061,6 +1126,8 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml)
"\n"
" Testing 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"
" -eventdelay ms : Set default delay for mouse and keyboard simulation to ms milliseconds\n"
" -keydelay ms : Set default delay for keyboard simulation to ms milliseconds\n"
" -mousedelay ms : Set default delay for mouse simulation to ms milliseconds\n"
@@ -1111,6 +1178,11 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml)
qPrintTestSlots(stdout);
exit(0);
}
+ } else if (strcmp(argv[i], "-datatags") == 0) {
+ if (!qml) {
+ qPrintDataTags(stdout);
+ exit(0);
+ }
} else if (strcmp(argv[i], "-txt") == 0) {
logFormat = QTestLog::Plain;
} else if (strcmp(argv[i], "-xunitxml") == 0) {
diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp
index 58de622126..0951b9b309 100644
--- a/src/testlib/qtestlog.cpp
+++ b/src/testlib/qtestlog.cpp
@@ -258,6 +258,9 @@ namespace QTest {
void QTestLog::enterTestFunction(const char* function)
{
+ if (printAvailableTags)
+ return;
+
QTEST_ASSERT(function);
QTest::TestLoggers::enterTestFunction(function);
@@ -276,6 +279,9 @@ int QTestLog::unhandledIgnoreMessages()
void QTestLog::leaveTestFunction()
{
+ if (printAvailableTags)
+ return;
+
QTest::IgnoreResultList::clearList(QTest::ignoreResultList);
QTest::TestLoggers::leaveTestFunction();
}
@@ -294,6 +300,9 @@ void QTestLog::printUnhandledIgnoreMessages()
void QTestLog::addPass(const char *msg)
{
+ if (printAvailableTags)
+ return;
+
QTEST_ASSERT(msg);
QTest::TestLoggers::addIncident(QAbstractTestLogger::Pass, msg);
@@ -431,4 +440,11 @@ void QTestLog::setMaxWarnings(int m)
QTest::maxWarnings = m <= 0 ? INT_MAX : m + 2;
}
+bool QTestLog::printAvailableTags = false;
+
+void QTestLog::setPrintAvailableTagsMode()
+{
+ printAvailableTags = true;
+}
+
QT_END_NAMESPACE
diff --git a/src/testlib/qtestlog_p.h b/src/testlib/qtestlog_p.h
index 692a36a4e6..b2aa8c1890 100644
--- a/src/testlib/qtestlog_p.h
+++ b/src/testlib/qtestlog_p.h
@@ -93,9 +93,13 @@ public:
static void setMaxWarnings(int max);
+ static void setPrintAvailableTagsMode();
+
private:
QTestLog();
~QTestLog();
+
+ static bool printAvailableTags;
};
QT_END_NAMESPACE