Move pass/fail/skip counters from QTestResult to QTestLog.
This change will enable further simplification of QTestResult and QTestLog in the future, including removing a circular dependency between the two classes. The "getter" functions in QTestResult are retained for now, but will be removed in a future commit, once QtQuickTest has been changed to call the getters that this commit adds to QTestLog. This commit is adapted from an unfinished change by Henrik Hartz. Change-Id: Ife7f80ac6a4310449a4712e96e0bea6c02139a5a Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
This commit is contained in:
parent
6acdb32561
commit
2ba0d1e550
@ -344,14 +344,14 @@ void QPlainTestLogger::stopLogging()
|
||||
char buf[1024];
|
||||
if (QTestLog::verboseLevel() < 0) {
|
||||
qsnprintf(buf, sizeof(buf), "Totals: %d passed, %d failed, %d skipped\n",
|
||||
QTestResult::passCount(), QTestResult::failCount(),
|
||||
QTestResult::skipCount());
|
||||
QTestLog::passCount(), QTestLog::failCount(),
|
||||
QTestLog::skipCount());
|
||||
} else {
|
||||
qsnprintf(buf, sizeof(buf),
|
||||
"Totals: %d passed, %d failed, %d skipped\n"
|
||||
"********* Finished testing of %s *********\n",
|
||||
QTestResult::passCount(), QTestResult::failCount(),
|
||||
QTestResult::skipCount(), QTestResult::currentTestObjectName());
|
||||
QTestLog::passCount(), QTestLog::failCount(),
|
||||
QTestLog::skipCount(), QTestResult::currentTestObjectName());
|
||||
}
|
||||
outputMessage(buf);
|
||||
|
||||
|
@ -2025,7 +2025,7 @@ int QTest::qExec(QObject *testObject, int argc, char **argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
saveCoverageTool(argv[0], QTestResult::failCount());
|
||||
saveCoverageTool(argv[0], QTestLog::failCount());
|
||||
|
||||
#ifdef QTESTLIB_USE_VALGRIND
|
||||
if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess)
|
||||
@ -2033,7 +2033,7 @@ int QTest::qExec(QObject *testObject, int argc, char **argv)
|
||||
#endif
|
||||
// make sure our exit code is never going above 127
|
||||
// since that could wrap and indicate 0 test fails
|
||||
return qMin(QTestResult::failCount(), 127);
|
||||
return qMin(QTestLog::failCount(), 127);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -58,6 +58,10 @@ QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace QTest {
|
||||
|
||||
int fails = 0;
|
||||
int passes = 0;
|
||||
int skips = 0;
|
||||
|
||||
struct IgnoreResultList
|
||||
{
|
||||
inline IgnoreResultList(QtMsgType tp, const char *message)
|
||||
@ -305,6 +309,8 @@ void QTestLog::addPass(const char *msg)
|
||||
|
||||
QTEST_ASSERT(msg);
|
||||
|
||||
++QTest::passes;
|
||||
|
||||
QTest::TestLoggers::addIncident(QAbstractTestLogger::Pass, msg);
|
||||
}
|
||||
|
||||
@ -312,6 +318,8 @@ void QTestLog::addFail(const char *msg, const char *file, int line)
|
||||
{
|
||||
QTEST_ASSERT(msg);
|
||||
|
||||
++QTest::fails;
|
||||
|
||||
QTest::TestLoggers::addIncident(QAbstractTestLogger::Fail, msg, file, line);
|
||||
}
|
||||
|
||||
@ -328,6 +336,8 @@ void QTestLog::addXPass(const char *msg, const char *file, int line)
|
||||
QTEST_ASSERT(msg);
|
||||
QTEST_ASSERT(file);
|
||||
|
||||
++QTest::fails;
|
||||
|
||||
QTest::TestLoggers::addIncident(QAbstractTestLogger::XPass, msg, file, line);
|
||||
}
|
||||
|
||||
@ -336,6 +346,8 @@ void QTestLog::addSkip(const char *msg, const char *file, int line)
|
||||
QTEST_ASSERT(msg);
|
||||
QTEST_ASSERT(file);
|
||||
|
||||
++QTest::skips;
|
||||
|
||||
QTest::TestLoggers::addMessage(QAbstractTestLogger::Skip, msg, file, line);
|
||||
}
|
||||
|
||||
@ -447,4 +459,26 @@ void QTestLog::setPrintAvailableTagsMode()
|
||||
printAvailableTags = true;
|
||||
}
|
||||
|
||||
int QTestLog::passCount()
|
||||
{
|
||||
return QTest::passes;
|
||||
}
|
||||
|
||||
int QTestLog::failCount()
|
||||
{
|
||||
return QTest::fails;
|
||||
}
|
||||
|
||||
int QTestLog::skipCount()
|
||||
{
|
||||
return QTest::skips;
|
||||
}
|
||||
|
||||
void QTestLog::resetCounters()
|
||||
{
|
||||
QTest::passes = 0;
|
||||
QTest::fails = 0;
|
||||
QTest::skips = 0;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -96,6 +96,12 @@ public:
|
||||
|
||||
static void setPrintAvailableTagsMode();
|
||||
|
||||
static int passCount();
|
||||
static int failCount();
|
||||
static int skipCount();
|
||||
|
||||
static void resetCounters();
|
||||
|
||||
private:
|
||||
QTestLog();
|
||||
~QTestLog();
|
||||
|
@ -62,10 +62,6 @@ namespace QTest
|
||||
static bool skipCurrentTest = false;
|
||||
static QTestResult::TestLocation location = QTestResult::NoWhere;
|
||||
|
||||
static int fails = 0;
|
||||
static int passes = 0;
|
||||
static int skips = 0;
|
||||
|
||||
static const char *expectFailComment = 0;
|
||||
static int expectFailMode = 0;
|
||||
}
|
||||
@ -80,12 +76,10 @@ void QTestResult::reset()
|
||||
QTest::dataFailed = false;
|
||||
QTest::location = QTestResult::NoWhere;
|
||||
|
||||
QTest::fails = 0;
|
||||
QTest::passes = 0;
|
||||
QTest::skips = 0;
|
||||
|
||||
QTest::expectFailComment = 0;
|
||||
QTest::expectFailMode = 0;
|
||||
|
||||
QTestLog::resetCounters();
|
||||
}
|
||||
|
||||
bool QTestResult::currentTestFailed()
|
||||
@ -140,7 +134,6 @@ void QTestResult::finishedCurrentTestFunction()
|
||||
|
||||
if (!QTest::failed && !QTest::skipCurrentTest) {
|
||||
QTestLog::addPass("");
|
||||
++QTest::passes;
|
||||
}
|
||||
QTest::currentTestFunc = 0;
|
||||
QTest::failed = false;
|
||||
@ -211,7 +204,6 @@ static bool checkStatement(bool statement, const char *msg, const char *file, in
|
||||
bool doContinue = (QTest::expectFailMode == QTest::Continue);
|
||||
clearExpectFail();
|
||||
QTest::failed = true;
|
||||
++QTest::fails;
|
||||
return doContinue;
|
||||
}
|
||||
return true;
|
||||
@ -277,7 +269,6 @@ void QTestResult::addFailure(const char *message, const char *file, int line)
|
||||
QTestLog::addFail(message, file, line);
|
||||
QTest::failed = true;
|
||||
QTest::dataFailed = true;
|
||||
++QTest::fails;
|
||||
}
|
||||
|
||||
void QTestResult::addSkip(const char *message, const char *file, int line)
|
||||
@ -285,7 +276,6 @@ void QTestResult::addSkip(const char *message, const char *file, int line)
|
||||
clearExpectFail();
|
||||
|
||||
QTestLog::addSkip(message, file, line);
|
||||
++QTest::skips;
|
||||
}
|
||||
|
||||
QTestResult::TestLocation QTestResult::currentTestLocation()
|
||||
@ -310,17 +300,17 @@ const char *QTestResult::currentTestObjectName()
|
||||
|
||||
int QTestResult::passCount()
|
||||
{
|
||||
return QTest::passes;
|
||||
return QTestLog::passCount();
|
||||
}
|
||||
|
||||
int QTestResult::failCount()
|
||||
{
|
||||
return QTest::fails;
|
||||
return QTestLog::failCount();
|
||||
}
|
||||
|
||||
int QTestResult::skipCount()
|
||||
{
|
||||
return QTest::skips;
|
||||
return QTestLog::skipCount();
|
||||
}
|
||||
|
||||
void QTestResult::ignoreMessage(QtMsgType type, const char *msg)
|
||||
|
Loading…
Reference in New Issue
Block a user