summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
authorJason McDonald <jason.mcdonald@nokia.com>2011-10-18 14:53:23 +1000
committerQt by Nokia <qt-info@nokia.com>2011-10-21 01:20:29 +0200
commit016cd01846539404a0eff1e3823fa2206fe2c9a9 (patch)
tree8971160e64893c8f674f209a49002aa59bfabdb0 /src/testlib
parent296bc328412f0cfec2318d04abd4717a4c70461c (diff)
Remove QTest::SkipMode from qtestlib API.
When the SkipAll mode is used, tests only report a SKIP for the first line of test data and subsequent lines are not reported at all. This behaviour makes it impossible for anything post-processing test results to accurately report test pass- and run- rates because they cannot see how many lines of test data were skipped. This commit removes SkipMode. QSKIPs in regular test functions and data functions are treated the same as SkipSingle, so that every skipped line of local or global test data is reported in the test log. QSKIPs elsewhere are treated the same as SkipAll -- skipping in init() causes the next test function to be skipped entirely, and skipping in initTestCase() or initTestCase_data() causes all test functions to be skipped. This commit only changes qtestlib and the selftests. A further commit will change the autotests to remove the SkipMode parameter from QSKIP calls. Note that the change in expected output for the globaldata selftest is deliberate, as the QSKIP in the skipLocal test function has effectively changed from SkipAll to SkipSingle. Task-number: QTBUG-21851, QTBUG-21652 Change-Id: I7b1c53fe7ca9dde032810b789d967e2a402bbe5d Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com> Reviewed-by: Alex <alex.blasche@nokia.com>
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/qtest_global.h1
-rw-r--r--src/testlib/qtestcase.cpp47
-rw-r--r--src/testlib/qtestcase.h11
3 files changed, 18 insertions, 41 deletions
diff --git a/src/testlib/qtest_global.h b/src/testlib/qtest_global.h
index 974d82a0d5..6789c5938c 100644
--- a/src/testlib/qtest_global.h
+++ b/src/testlib/qtest_global.h
@@ -77,7 +77,6 @@ QT_MODULE(Test)
namespace QTest
{
- enum SkipMode { SkipSingle = 1, SkipAll = 2 };
enum TestFailMode { Abort = 1, Continue = 2 };
int Q_TESTLIB_EXPORT qt_snprintf(char *str, int size, const char *format, ...);
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 451fa5b761..0ff760be38 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -267,23 +267,24 @@ QT_BEGIN_NAMESPACE
\sa QCOMPARE()
*/
-/*! \macro QSKIP(description, mode)
+/*! \macro QSKIP(description)
\relates QTest
The QSKIP() macro stops execution of the test without adding a failure to the
test log. You can use it to skip tests that wouldn't make sense in the current
configuration. The text \a description is appended to the test log and should
- contain an explanation why the test couldn't be executed. \a mode is a QTest::SkipMode
- and describes whether to proceed with the rest of the test data or not.
+ contain an explanation of why the test couldn't be executed.
+
+ If the test is data-driven, each call to QSKIP() will skip only the current row,
+ so an unconditional call to QSKIP will produce one skip message in the test log
+ for each row of test data.
\bold {Note:} This macro can only be used in a test function that is invoked
by the test framework.
Example:
\snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 8
-
- \sa QTest::SkipMode
*/
/*! \macro QEXPECT_FAIL(dataIndex, comment, mode)
@@ -415,22 +416,6 @@ QT_BEGIN_NAMESPACE
{Chapter 5: Writing a Benchmark}{Writing a Benchmark}
*/
-
-
-/*! \enum QTest::SkipMode
-
- This enum describes the modes for skipping tests during execution
- of the test data.
-
- \value SkipSingle Skips the current entry in the test table; continues
- execution of all the other entries in the table.
-
- \value SkipAll Skips all the entries in the test table; the test won't
- be executed further.
-
- \sa QSKIP()
-*/
-
/*! \enum QTest::TestFailMode
This enum describes the modes for handling an expected failure of the
@@ -1469,20 +1454,12 @@ static bool qInvokeTestMethod(const char *slotName, const char *data=0)
QTestResult::setCurrentTestLocation(QTestResult::DataFunc);
QTest::qt_snprintf(member, 512, "%s_data()", slot);
invokeMethod(QTest::currentTestObject, member);
-
- // if we encounter a SkipAll in the _data slot, we skip the whole
- // testfunction, no matter how much global data exists
- if (QTestResult::skipCurrentTest()) {
- QTestResult::setCurrentGlobalTestData(0);
- break;
- }
}
bool foundFunction = false;
if (!QTestResult::skipCurrentTest()) {
int curDataIndex = 0;
const int dataCount = table.dataCount();
- QTestResult::setSkipCurrentTest(false);
// Data tag requested but none available?
if (data && !dataCount) {
@@ -1498,6 +1475,7 @@ static bool qInvokeTestMethod(const char *slotName, const char *data=0)
/* For each entry in the data table, do: */
do {
+ QTestResult::setSkipCurrentTest(false);
if (!data || !qstrcmp(data, table.testData(curDataIndex)->dataTag())) {
foundFunction = true;
QTestDataSetter s(curDataIndex >= dataCount ? static_cast<QTestData *>(0)
@@ -1505,9 +1483,6 @@ static bool qInvokeTestMethod(const char *slotName, const char *data=0)
qInvokeTestMethodDataEntry(slot);
- if (QTestResult::skipCurrentTest())
- // check whether SkipAll was requested
- break;
if (data)
break;
}
@@ -1954,15 +1929,13 @@ bool QTest::qVerify(bool statement, const char *statementStr, const char *descri
return QTestResult::verify(statement, statementStr, description, file, line);
}
-/*! \fn void QTest::qSkip(const char *message, SkipMode mode, const char *file, int line)
+/*! \fn void QTest::qSkip(const char *message, const char *file, int line)
\internal
*/
-void QTest::qSkip(const char *message, QTest::SkipMode mode,
- const char *file, int line)
+void QTest::qSkip(const char *message, const char *file, int line)
{
QTestResult::addSkip(message, file, line);
- if (mode == QTest::SkipAll)
- QTestResult::setSkipCurrentTest(true);
+ QTestResult::setSkipCurrentTest(true);
}
/*! \fn bool QTest::qExpectFail(const char *dataIndex, const char *comment, TestFailMode mode, const char *file, int line)
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h
index 3e0003505a..7ba9fd714b 100644
--- a/src/testlib/qtestcase.h
+++ b/src/testlib/qtestcase.h
@@ -47,6 +47,8 @@
#include <QtCore/qnamespace.h>
#include <QtCore/qmetatype.h>
+#include <string.h>
+
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@@ -110,9 +112,12 @@ do { \
QCOMPARE(__expr, __expected); \
} while (0)
-#define QSKIP(statement, mode) \
+#define QSKIP(statement, ...) \
do {\
- QTest::qSkip(statement, QTest::mode, __FILE__, __LINE__);\
+ if (strcmp(#__VA_ARGS__, "") != 0)\
+ QTest::qWarn("The two argument version of QSKIP is deprecated and will be removed soon. "\
+ "Please update this test by removing the second parameter.", __FILE__, __LINE__);\
+ QTest::qSkip(statement, __FILE__, __LINE__);\
return;\
} while (0)
@@ -162,7 +167,7 @@ namespace QTest
Q_TESTLIB_EXPORT bool qVerify(bool statement, const char *statementStr, const char *description,
const char *file, int line);
Q_TESTLIB_EXPORT void qFail(const char *statementStr, const char *file, int line);
- Q_TESTLIB_EXPORT void qSkip(const char *message, SkipMode mode, const char *file, int line);
+ Q_TESTLIB_EXPORT void qSkip(const char *message, const char *file, int line);
Q_TESTLIB_EXPORT bool qExpectFail(const char *dataIndex, const char *comment, TestFailMode mode,
const char *file, int line);
Q_TESTLIB_EXPORT void qWarn(const char *message, const char *file = 0, int line = 0);