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:
parent
0d3fb3784b
commit
d4cd1bf861
@ -51,7 +51,8 @@
|
|||||||
// We mean it.
|
// We mean it.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <qglobal.h>
|
#include <QtTest/qttestglobal.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
class QBenchmarkResult;
|
class QBenchmarkResult;
|
||||||
class QTestData;
|
class QTestData;
|
||||||
|
|
||||||
class QAbstractTestLogger
|
class Q_TESTLIB_EXPORT QAbstractTestLogger
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum IncidentTypes {
|
enum IncidentTypes {
|
||||||
@ -184,7 +185,7 @@ namespace QTest
|
|||||||
namespace QTestPrivate
|
namespace QTestPrivate
|
||||||
{
|
{
|
||||||
enum IdentifierPart { TestObject = 0x1, TestFunction = 0x2, TestDataTag = 0x4, AllParts = 0xFFFF };
|
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
|
QT_END_NAMESPACE
|
||||||
|
@ -99,7 +99,7 @@ static void saveCoverageTool(const char * appname, bool testfailed, bool install
|
|||||||
static QElapsedTimer elapsedFunctionTime;
|
static QElapsedTimer elapsedFunctionTime;
|
||||||
static QElapsedTimer elapsedTotalTime;
|
static QElapsedTimer elapsedTotalTime;
|
||||||
|
|
||||||
#define FOREACH_TEST_LOGGER for (QAbstractTestLogger *logger : QTest::loggers)
|
#define FOREACH_TEST_LOGGER for (QAbstractTestLogger *logger : *QTest::loggers())
|
||||||
|
|
||||||
namespace QTest {
|
namespace QTest {
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ namespace QTest {
|
|||||||
|
|
||||||
static IgnoreResultList *ignoreResultList = nullptr;
|
static IgnoreResultList *ignoreResultList = nullptr;
|
||||||
|
|
||||||
static QList<QAbstractTestLogger *> loggers;
|
Q_GLOBAL_STATIC(QList<QAbstractTestLogger *>, loggers)
|
||||||
|
|
||||||
static int verbosity = 0;
|
static int verbosity = 0;
|
||||||
static int maxWarnings = 2002;
|
static int maxWarnings = 2002;
|
||||||
@ -429,7 +429,7 @@ void QTestLog::stopLogging()
|
|||||||
logger->stopLogging();
|
logger->stopLogging();
|
||||||
delete logger;
|
delete logger;
|
||||||
}
|
}
|
||||||
QTest::loggers.clear();
|
QTest::loggers()->clear();
|
||||||
saveCoverageTool(QTestResult::currentAppName(), failCount() != 0, QTestLog::installedTestCoverage());
|
saveCoverageTool(QTestResult::currentAppName(), failCount() != 0, QTestLog::installedTestCoverage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -474,12 +474,26 @@ void QTestLog::addLogger(LogMode mode, const char *filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QTEST_ASSERT(logger);
|
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()
|
int QTestLog::loggerCount()
|
||||||
{
|
{
|
||||||
return QTest::loggers.size();
|
return QTest::loggers()->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QTestLog::loggerUsingStdout()
|
bool QTestLog::loggerUsingStdout()
|
||||||
|
@ -64,6 +64,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
class QBenchmarkResult;
|
class QBenchmarkResult;
|
||||||
class QRegularExpression;
|
class QRegularExpression;
|
||||||
class QTestData;
|
class QTestData;
|
||||||
|
class QAbstractTestLogger;
|
||||||
|
|
||||||
class Q_TESTLIB_EXPORT QTestLog
|
class Q_TESTLIB_EXPORT QTestLog
|
||||||
{
|
{
|
||||||
@ -115,6 +116,7 @@ public:
|
|||||||
static void stopLogging();
|
static void stopLogging();
|
||||||
|
|
||||||
static void addLogger(LogMode mode, const char *filename);
|
static void addLogger(LogMode mode, const char *filename);
|
||||||
|
static void addLogger(QAbstractTestLogger *logger);
|
||||||
|
|
||||||
static int loggerCount();
|
static int loggerCount();
|
||||||
static bool loggerUsingStdout();
|
static bool loggerUsingStdout();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user