summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestjunitstreamer.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-09-30 12:50:05 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2021-11-30 12:26:08 +0100
commitb9f7add531ceab2590e2b24dec7b495950f9870a (patch)
treebc6854cf33ec4847317b05edb5201fa4ed426605 /src/testlib/qtestjunitstreamer.cpp
parent78a6e730075c1262f25b2ac2df098c7aa1184ca8 (diff)
Verify returns from QXmlTestLogger's xmlQuote() and xmlCdata()
Using partially-converted text would lead to invalid XML, so don't use the buffer contents if the return is zero. As a result, QTestJUnitStreamer::formatEnd() needs to return some indication of whether *it* succeeded, so change it to forward their int returns; and, as it's in fact only used internally by the streamer, make it private. Make these functions [[nodiscard]] so that further uses of them will be discouraged from ignoring the possibility of failure. Make the public versions return bool so that they can correctly succeed on empty input. Assert various conditions we can infer to save work we don't need to do. Change-Id: I899bad23d1dfbd05fc725de269def4ce213dbc5a Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/testlib/qtestjunitstreamer.cpp')
-rw-r--r--src/testlib/qtestjunitstreamer.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/testlib/qtestjunitstreamer.cpp b/src/testlib/qtestjunitstreamer.cpp
index 72ab7d1534..3e67e5c4bf 100644
--- a/src/testlib/qtestjunitstreamer.cpp
+++ b/src/testlib/qtestjunitstreamer.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtTest module of the Qt Toolkit.
@@ -106,23 +106,26 @@ void QTestJUnitStreamer::formatEnd(const QTestElement *element, QTestCharBuffer
QTest::qt_asprintf(formatted, "%s</%s>\n", indent, element->elementName());
}
-void QTestJUnitStreamer::formatAttributes(const QTestElement* element, const QTestElementAttribute *attribute, QTestCharBuffer *formatted) const
+bool QTestJUnitStreamer::formatAttributes(const QTestElement* element,
+ const QTestElementAttribute *attribute,
+ QTestCharBuffer *formatted) const
{
if (!attribute || !formatted )
- return;
+ return false;
QTest::AttributeIndex attrindex = attribute->index();
if (element && element->elementType() == QTest::LET_Text) {
QTEST_ASSERT(attrindex == QTest::AI_Value);
- QXmlTestLogger::xmlCdata(formatted, attribute->value());
- return;
+ return QXmlTestLogger::xmlCdata(formatted, attribute->value());
}
QTestCharBuffer quotedValue;
- QXmlTestLogger::xmlQuote(&quotedValue, attribute->value());
- QTest::qt_asprintf(formatted, " %s=\"%s\"",
- attribute->name(), quotedValue.constData());
+ if (QXmlTestLogger::xmlQuote(&quotedValue, attribute->value())) {
+ return QTest::qt_asprintf(formatted, " %s=\"%s\"",
+ attribute->name(), quotedValue.constData()) != 0;
+ }
+ return false;
}
void QTestJUnitStreamer::formatAfterAttributes(const QTestElement *element, QTestCharBuffer *formatted) const
@@ -176,8 +179,8 @@ void QTestJUnitStreamer::outputElementAttributes(const QTestElement* element, co
QTestCharBuffer buf;
for (auto *attribute : attributes) {
- formatAttributes(element, attribute, &buf);
- outputString(buf.data());
+ if (formatAttributes(element, attribute, &buf))
+ outputString(buf.data());
}
}