summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestjunitstreamer.cpp
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-09-08 16:34:19 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-09-10 22:19:45 +0200
commitb8191f41c65a908d0529d235b0200e6de99c34fb (patch)
tree59d750687ba5896cd4638780bb32193a5f563961 /src/testlib/qtestjunitstreamer.cpp
parent4e0082a9cacfdfd0c43e6105274bc0d41dd18801 (diff)
testlib: Replace custom QTestCoreList with std::vector
The custom linked list implementation was implemented using recursion, and as a result didn't handle long lists of test cases, exhausting the stack on e.g. Windows where the default stack is only 1MB. This was the case with e.g. the tst_QChar test that produces 20K test cases. Replacing with a std::vector should do nicely for our use-case. No attempt has been made at further reducing the complexity of QTestElement/QTestCoreElement/QTestElementAttribute. Pick-to: 6.2 Change-Id: Ie295f7cf937ec6abdc4606b6120818551ad285c7 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/testlib/qtestjunitstreamer.cpp')
-rw-r--r--src/testlib/qtestjunitstreamer.cpp55
1 files changed, 20 insertions, 35 deletions
diff --git a/src/testlib/qtestjunitstreamer.cpp b/src/testlib/qtestjunitstreamer.cpp
index d8c73505db3..72ab7d15341 100644
--- a/src/testlib/qtestjunitstreamer.cpp
+++ b/src/testlib/qtestjunitstreamer.cpp
@@ -95,7 +95,7 @@ void QTestJUnitStreamer::formatEnd(const QTestElement *element, QTestCharBuffer
if (!element || !formatted )
return;
- if (!element->childElements()) {
+ if (element->childElements().empty()) {
formatted->data()[0] = '\0';
return;
}
@@ -135,7 +135,7 @@ void QTestJUnitStreamer::formatAfterAttributes(const QTestElement *element, QTes
return;
}
- if (!element->childElements())
+ if (element->childElements().empty())
QTest::qt_asprintf(formatted, "/>\n");
else
QTest::qt_asprintf(formatted, ">\n");
@@ -145,54 +145,39 @@ void QTestJUnitStreamer::output(QTestElement *element) const
{
QTEST_ASSERT(element);
- outputString("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
- outputElements(element);
-}
+ if (!element->parentElement())
+ outputString("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
-void QTestJUnitStreamer::outputElements(QTestElement *element, bool) const
-{
QTestCharBuffer buf;
- bool hasChildren;
-
- // Elements are in reverse order of occurrence, so
- // start from the end and work our way backwards.
- while (element && element->nextElement())
- element = element->nextElement();
- while (element) {
- hasChildren = element->childElements();
+ formatStart(element, &buf);
+ outputString(buf.data());
- formatStart(element, &buf);
- outputString(buf.data());
-
- outputElementAttributes(element, element->attributes());
+ outputElementAttributes(element, element->attributes());
- formatAfterAttributes(element, &buf);
- outputString(buf.data());
+ formatAfterAttributes(element, &buf);
+ outputString(buf.data());
- if (hasChildren)
- outputElements(element->childElements(), true);
+ if (!element->childElements().empty())
+ outputElements(element->childElements());
- formatEnd(element, &buf);
- outputString(buf.data());
+ formatEnd(element, &buf);
+ outputString(buf.data());
+}
- element = element->previousElement();
- }
+void QTestJUnitStreamer::outputElements(const std::vector<QTestElement*> &elements) const
+{
+ for (auto *element : elements)
+ output(element);
}
-void QTestJUnitStreamer::outputElementAttributes(const QTestElement* element, QTestElementAttribute *attribute) const
+void QTestJUnitStreamer::outputElementAttributes(const QTestElement* element, const std::vector<QTestElementAttribute*> &attributes) const
{
QTestCharBuffer buf;
- // Attributes are in reverse order of occurrence, so
- // start from the end and work our way backwards.
- while (attribute && attribute->nextElement())
- attribute = attribute->nextElement();
-
- while (attribute) {
+ for (auto *attribute : attributes) {
formatAttributes(element, attribute, &buf);
outputString(buf.data());
- attribute = attribute->previousElement();
}
}