summaryrefslogtreecommitdiffstats
path: root/src/testlib/qjunittestlogger.cpp
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-07-21 12:04:44 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-07-22 23:23:32 +0200
commit6f2fb55ea115b89ed6b89488220af8467b80f8a1 (patch)
tree6447715afe0121afcc94a30cfda0eef02bcd37f9 /src/testlib/qjunittestlogger.cpp
parent81d83d56728983befa10ddb001c60ca0cd98e8fd (diff)
testlib: Track current test suite in JUnit test logger
Instead of deferring the creation of the test suite until logging stops, we create it up front, matching the logic of adding test elements on test function enter. Change-Id: I78b1ccdfde5493d78ef478d4b3c45d5a49358979 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/testlib/qjunittestlogger.cpp')
-rw-r--r--src/testlib/qjunittestlogger.cpp58
1 files changed, 31 insertions, 27 deletions
diff --git a/src/testlib/qjunittestlogger.cpp b/src/testlib/qjunittestlogger.cpp
index 2d71f7967b..62cbac4164 100644
--- a/src/testlib/qjunittestlogger.cpp
+++ b/src/testlib/qjunittestlogger.cpp
@@ -43,6 +43,7 @@
#include <QtTest/qtestcase.h>
#include <QtTest/private/qtestresult_p.h>
#include <QtTest/private/qbenchmark_p.h>
+#include <QtTest/private/qtestlog_p.h>
#ifdef min // windows.h without NOMINMAX is included by the benchmark headers.
# undef min
@@ -64,7 +65,7 @@ QJUnitTestLogger::QJUnitTestLogger(const char *filename)
QJUnitTestLogger::~QJUnitTestLogger()
{
- delete currentLogElement;
+ Q_ASSERT(!currentTestSuite);
delete logFormatter;
}
@@ -75,25 +76,10 @@ void QJUnitTestLogger::startLogging()
logFormatter = new QTestJUnitStreamer(this);
delete errorLogElement;
errorLogElement = new QTestElement(QTest::LET_SystemError);
-}
-void QJUnitTestLogger::stopLogging()
-{
- QTestElement *iterator = listOfTestcases;
-
- char buf[10];
-
- currentLogElement = new QTestElement(QTest::LET_TestSuite);
- currentLogElement->addAttribute(QTest::AI_Name, QTestResult::currentTestObjectName());
-
- qsnprintf(buf, sizeof(buf), "%i", testCounter);
- currentLogElement->addAttribute(QTest::AI_Tests, buf);
-
- qsnprintf(buf, sizeof(buf), "%i", failureCounter);
- currentLogElement->addAttribute(QTest::AI_Failures, buf);
-
- qsnprintf(buf, sizeof(buf), "%i", errorCounter);
- currentLogElement->addAttribute(QTest::AI_Errors, buf);
+ Q_ASSERT(!currentTestSuite);
+ currentTestSuite = new QTestElement(QTest::LET_TestSuite);
+ currentTestSuite->addAttribute(QTest::AI_Name, QTestResult::currentTestObjectName());
QTestElement *property;
QTestElement *properties = new QTestElement(QTest::LET_Properties);
@@ -113,21 +99,37 @@ void QJUnitTestLogger::stopLogging()
property->addAttribute(QTest::AI_PropertyValue, QLibraryInfo::build());
properties->addLogElement(property);
- currentLogElement->addLogElement(properties);
+ currentTestSuite->addLogElement(properties);
+}
- currentLogElement->addLogElement(iterator);
+void QJUnitTestLogger::stopLogging()
+{
+ char buf[10];
+
+ qsnprintf(buf, sizeof(buf), "%i", testCounter);
+ currentTestSuite->addAttribute(QTest::AI_Tests, buf);
+
+ qsnprintf(buf, sizeof(buf), "%i", failureCounter);
+ currentTestSuite->addAttribute(QTest::AI_Failures, buf);
+
+ qsnprintf(buf, sizeof(buf), "%i", errorCounter);
+ currentTestSuite->addAttribute(QTest::AI_Errors, buf);
- /* For correct indenting, make sure every testcase knows its parent */
- QTestElement* testcase = iterator;
+ currentTestSuite->addLogElement(listOfTestcases);
+
+ // For correct indenting, make sure every testcase knows its parent
+ QTestElement *testcase = listOfTestcases;
while (testcase) {
- testcase->setParent(currentLogElement);
+ testcase->setParent(currentTestSuite);
testcase = testcase->nextElement();
}
- currentLogElement->addLogElement(errorLogElement);
+ currentTestSuite->addLogElement(errorLogElement);
+
+ logFormatter->output(currentTestSuite);
- QTestElement *it = currentLogElement;
- logFormatter->output(it);
+ delete currentTestSuite;
+ currentTestSuite = nullptr;
QAbstractTestLogger::stopLogging();
}
@@ -138,6 +140,8 @@ void QJUnitTestLogger::enterTestFunction(const char *function)
currentLogElement->addAttribute(QTest::AI_Name, function);
currentLogElement->addToList(&listOfTestcases);
+ // The element will be deleted when the suite is deleted
+
++testCounter;
}