summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestlog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/testlib/qtestlog.cpp')
-rw-r--r--src/testlib/qtestlog.cpp45
1 files changed, 34 insertions, 11 deletions
diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp
index a20082b630..4b6df54e91 100644
--- a/src/testlib/qtestlog.cpp
+++ b/src/testlib/qtestlog.cpp
@@ -24,6 +24,7 @@
#include <QtCore/qbytearray.h>
#include <QtCore/qelapsedtimer.h>
#include <QtCore/qlist.h>
+#include <QtCore/qmutex.h>
#include <QtCore/qvariant.h>
#if QT_CONFIG(regularexpression)
#include <QtCore/QRegularExpression>
@@ -66,10 +67,10 @@ static void saveCoverageTool(const char * appname, bool testfailed, bool install
#endif
}
-static QElapsedTimer elapsedFunctionTime;
-static QElapsedTimer elapsedTotalTime;
+Q_CONSTINIT static QElapsedTimer elapsedFunctionTime;
+Q_CONSTINIT static QElapsedTimer elapsedTotalTime;
-#define FOREACH_TEST_LOGGER for (const auto &logger : qAsConst(*QTest::loggers()))
+#define FOREACH_TEST_LOGGER for (const auto &logger : std::as_const(*QTest::loggers()))
namespace QTest {
@@ -115,7 +116,7 @@ namespace QTest {
// (the space was added automatically by ~QDebug() until Qt 5.3,
// so autotests still might expect it)
if (expected.endsWith(u' '))
- return actual == QStringView{expected}.left(expected.length() - 1);
+ return actual == QStringView{expected}.left(expected.size() - 1);
return false;
}
@@ -138,6 +139,7 @@ namespace QTest {
};
static IgnoreResultList *ignoreResultList = nullptr;
+ Q_CONSTINIT static QBasicMutex mutex;
static std::vector<QVariant> failOnWarningList;
@@ -151,6 +153,8 @@ namespace QTest {
static bool handleIgnoredMessage(QtMsgType type, const QString &message)
{
+ const QMutexLocker mutexLocker(&QTest::mutex);
+
if (!ignoreResultList)
return false;
IgnoreResultList *last = nullptr;
@@ -160,10 +164,8 @@ namespace QTest {
// remove the item from the list
if (last)
last->next = list->next;
- else if (list->next)
- ignoreResultList = list->next;
else
- ignoreResultList = nullptr;
+ ignoreResultList = list->next;
delete list;
return true;
@@ -177,7 +179,7 @@ namespace QTest {
static bool handleFailOnWarning(const QMessageLogContext &context, const QString &message)
{
- // failOnWarnings can be called multiple times per test function, so let
+ // failOnWarning can be called multiple times per test function, so let
// each call cause a failure if required.
for (const auto &pattern : failOnWarningList) {
if (pattern.metaType() == QMetaType::fromType<QString>()) {
@@ -270,6 +272,7 @@ void QTestLog::enterTestData(QTestData *data)
int QTestLog::unhandledIgnoreMessages()
{
+ const QMutexLocker mutexLocker(&QTest::mutex);
int i = 0;
QTest::IgnoreResultList *list = QTest::ignoreResultList;
while (list) {
@@ -290,6 +293,7 @@ void QTestLog::leaveTestFunction()
void QTestLog::printUnhandledIgnoreMessages()
{
+ const QMutexLocker mutexLocker(&QTest::mutex);
QString message;
QTest::IgnoreResultList *list = QTest::ignoreResultList;
while (list) {
@@ -310,10 +314,10 @@ void QTestLog::printUnhandledIgnoreMessages()
void QTestLog::clearIgnoreMessages()
{
+ const QMutexLocker mutexLocker(&QTest::mutex);
QTest::IgnoreResultList::clearList(QTest::ignoreResultList);
}
-
void QTestLog::clearFailOnWarnings()
{
QTest::failOnWarningList.clear();
@@ -321,6 +325,8 @@ void QTestLog::clearFailOnWarnings()
void QTestLog::clearCurrentTestState()
{
+ clearIgnoreMessages();
+ clearFailOnWarnings();
QTest::currentTestState = QTest::Unresolved;
}
@@ -466,10 +472,10 @@ void QTestLog::addSkip(const char *msg, const char *file, int line)
logger->addIncident(QAbstractTestLogger::Skip, msg, file, line);
}
-void QTestLog::addBenchmarkResult(const QBenchmarkResult &result)
+void QTestLog::addBenchmarkResults(const QList<QBenchmarkResult> &results)
{
FOREACH_TEST_LOGGER
- logger->addBenchmarkResult(result);
+ logger->addBenchmarkResults(results);
}
void QTestLog::startLogging()
@@ -554,6 +560,21 @@ bool QTestLog::hasLoggers()
return !QTest::loggers()->empty();
}
+/*!
+ \internal
+
+ Returns true if all loggers support repeated test runs
+*/
+bool QTestLog::isRepeatSupported()
+{
+ FOREACH_TEST_LOGGER {
+ if (!logger->isRepeatSupported())
+ return false;
+ }
+
+ return true;
+}
+
bool QTestLog::loggerUsingStdout()
{
FOREACH_TEST_LOGGER {
@@ -594,6 +615,7 @@ void QTestLog::ignoreMessage(QtMsgType type, const char *msg)
{
QTEST_ASSERT(msg);
+ const QMutexLocker mutexLocker(&QTest::mutex);
QTest::IgnoreResultList::append(QTest::ignoreResultList, type, QString::fromUtf8(msg));
}
@@ -602,6 +624,7 @@ void QTestLog::ignoreMessage(QtMsgType type, const QRegularExpression &expressio
{
QTEST_ASSERT(expression.isValid());
+ const QMutexLocker mutexLocker(&QTest::mutex);
QTest::IgnoreResultList::append(QTest::ignoreResultList, type, QVariant(expression));
}
#endif // QT_CONFIG(regularexpression)