summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestxunitstreamer.cpp
diff options
context:
space:
mode:
authorRohan McGovern <rohan.mcgovern@nokia.com>2009-05-07 04:09:08 (GMT)
committerRohan McGovern <rohan.mcgovern@nokia.com>2009-05-07 04:56:06 (GMT)
commit56335c9891230de3b87d401110b83656381729ac (patch)
treec06fa4ea973c5d81f1161c748560066eae4eccee /src/testlib/qtestxunitstreamer.cpp
parent014b5d404b19ad3d81686ba490eb7dd93efee573 (diff)
downloadQt-56335c9891230de3b87d401110b83656381729ac.zip
Qt-56335c9891230de3b87d401110b83656381729ac.tar.gz
Qt-56335c9891230de3b87d401110b83656381729ac.tar.bz2
Fixed qDebugs within tests being written as "error" tags in the
xunitxml testlog. `error' in xunit causes many xunit processing tools to consider the test as failing. This is different semantics from native testlib XML, where a qDebug is considered a message and not a failure. Change it to put qDebugs under the "system-err" tag when using xunitxml to retain semantic compatibility with testlib XML. Autotest: tst_selftests
Diffstat (limited to 'src/testlib/qtestxunitstreamer.cpp')
-rw-r--r--src/testlib/qtestxunitstreamer.cpp44
1 files changed, 38 insertions, 6 deletions
diff --git a/src/testlib/qtestxunitstreamer.cpp b/src/testlib/qtestxunitstreamer.cpp
index 2d8b7c4..42dc56c 100644
--- a/src/testlib/qtestxunitstreamer.cpp
+++ b/src/testlib/qtestxunitstreamer.cpp
@@ -40,6 +40,17 @@ void QTestXunitStreamer::formatStart(const QTestElement *element, char *formatte
char indent[20];
indentForElement(element, indent, sizeof(indent));
+ // Errors are written as CDATA within system-err, comments elsewhere
+ if (element->elementType() == QTest::LET_Error) {
+ if (element->parentElement()->elementType() == QTest::LET_SystemError) {
+ QTest::qt_snprintf(formatted, 1024, "<![CDATA[");
+ }
+ else {
+ QTest::qt_snprintf(formatted, 1024, "%s<!--", indent);
+ }
+ return;
+ }
+
QTest::qt_snprintf(formatted, 1024, "%s<%s", indent, element->elementName());
}
@@ -59,13 +70,23 @@ void QTestXunitStreamer::formatEnd(const QTestElement *element, char *formatted)
QTest::qt_snprintf(formatted, 1024, "%s</%s>\n", indent, element->elementName());
}
-void QTestXunitStreamer::formatAttributes(const QTestElementAttribute *attribute, char *formatted) const
+void QTestXunitStreamer::formatAttributes(const QTestElement* element, const QTestElementAttribute *attribute, char *formatted) const
{
if(!attribute || !formatted )
return;
QTest::AttributeIndex attrindex = attribute->index();
+ // For errors within system-err, we only want to output `message'
+ if (element && element->elementType() == QTest::LET_Error
+ && element->parentElement()->elementType() == QTest::LET_SystemError) {
+
+ if (attrindex != QTest::AI_Description) return;
+
+ QXmlTestLogger::xmlCdata(formatted, attribute->value(), 1024);
+ return;
+ }
+
char const* key = 0;
if (attrindex == QTest::AI_Description)
key = "message";
@@ -87,10 +108,21 @@ void QTestXunitStreamer::formatAfterAttributes(const QTestElement *element, char
if(!element || !formatted )
return;
- if(!element->childElements())
- QTest::qt_snprintf(formatted, 10, "/>\n");
- else
- QTest::qt_snprintf(formatted, 10, ">\n");
+ // Errors are written as CDATA within system-err, comments elsewhere
+ if (element->elementType() == QTest::LET_Error) {
+ if (element->parentElement()->elementType() == QTest::LET_SystemError) {
+ QTest::qt_snprintf(formatted, 1024, "]]>\n");
+ }
+ else {
+ QTest::qt_snprintf(formatted, 1024, " -->\n");
+ }
+ return;
+ }
+
+ if(!element->childElements())
+ QTest::qt_snprintf(formatted, 10, "/>\n");
+ else
+ QTest::qt_snprintf(formatted, 10, ">\n");
}
void QTestXunitStreamer::output(QTestElement *element) const
@@ -122,7 +154,7 @@ void QTestXunitStreamer::outputElements(QTestElement *element, bool) const
formatBeforeAttributes(element, buf);
outputString(buf);
- outputElementAttributes(element->attributes());
+ outputElementAttributes(element, element->attributes());
formatAfterAttributes(element, buf);
outputString(buf);