testlib: Add private API to add test logger

Allows adding test loggers outside of testlib.

Change-Id: Iabcc780e441de96032a05fc0a386dd52e2f2f404
Reviewed-by: Simon Hausmann <hausmann@gmail.com>
This commit is contained in:
Tor Arne Vestbø 2020-10-30 12:07:58 +01:00
parent 0d3fb3784b
commit d4cd1bf861
3 changed files with 25 additions and 8 deletions

View File

@ -51,7 +51,8 @@
// We mean it.
//
#include <qglobal.h>
#include <QtTest/qttestglobal.h>
#include <stdio.h>
#include <stdlib.h>
@ -60,7 +61,7 @@ QT_BEGIN_NAMESPACE
class QBenchmarkResult;
class QTestData;
class QAbstractTestLogger
class Q_TESTLIB_EXPORT QAbstractTestLogger
{
public:
enum IncidentTypes {
@ -184,7 +185,7 @@ namespace QTest
namespace QTestPrivate
{
enum IdentifierPart { TestObject = 0x1, TestFunction = 0x2, TestDataTag = 0x4, AllParts = 0xFFFF };
void generateTestIdentifier(QTestCharBuffer *identifier, int parts = AllParts);
void Q_TESTLIB_EXPORT generateTestIdentifier(QTestCharBuffer *identifier, int parts = AllParts);
}
QT_END_NAMESPACE

View File

@ -99,7 +99,7 @@ static void saveCoverageTool(const char * appname, bool testfailed, bool install
static QElapsedTimer elapsedFunctionTime;
static QElapsedTimer elapsedTotalTime;
#define FOREACH_TEST_LOGGER for (QAbstractTestLogger *logger : QTest::loggers)
#define FOREACH_TEST_LOGGER for (QAbstractTestLogger *logger : *QTest::loggers())
namespace QTest {
@ -168,7 +168,7 @@ namespace QTest {
static IgnoreResultList *ignoreResultList = nullptr;
static QList<QAbstractTestLogger *> loggers;
Q_GLOBAL_STATIC(QList<QAbstractTestLogger *>, loggers)
static int verbosity = 0;
static int maxWarnings = 2002;
@ -429,7 +429,7 @@ void QTestLog::stopLogging()
logger->stopLogging();
delete logger;
}
QTest::loggers.clear();
QTest::loggers()->clear();
saveCoverageTool(QTestResult::currentAppName(), failCount() != 0, QTestLog::installedTestCoverage());
}
@ -474,12 +474,26 @@ void QTestLog::addLogger(LogMode mode, const char *filename)
}
QTEST_ASSERT(logger);
QTest::loggers.append(logger);
addLogger(logger);
}
/*!
\internal
Adds a new logger to the set of loggers that will be used
to report incidents and messages during testing.
The function takes ownership of the logger.
*/
void QTestLog::addLogger(QAbstractTestLogger *logger)
{
QTEST_ASSERT(logger);
QTest::loggers()->append(logger);
}
int QTestLog::loggerCount()
{
return QTest::loggers.size();
return QTest::loggers()->size();
}
bool QTestLog::loggerUsingStdout()

View File

@ -64,6 +64,7 @@ QT_BEGIN_NAMESPACE
class QBenchmarkResult;
class QRegularExpression;
class QTestData;
class QAbstractTestLogger;
class Q_TESTLIB_EXPORT QTestLog
{
@ -115,6 +116,7 @@ public:
static void stopLogging();
static void addLogger(LogMode mode, const char *filename);
static void addLogger(QAbstractTestLogger *logger);
static int loggerCount();
static bool loggerUsingStdout();