summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason McDonald <jason.mcdonald@nokia.com>2011-08-31 12:52:27 +1000
committerQt by Nokia <qt-info@nokia.com>2011-08-31 07:40:06 +0200
commit21776e926074a572316dfb4e3346423f3111d7f7 (patch)
treea4a3de01cb736edc563dc5023aab0f6f8f0089c3 /src
parentb94eba6899e4162ce2b5a98b5603289e8ec2f66e (diff)
Fix errors in lightxml test logger
The newer test logger did not produce the same light XML output as the logger that it replaced. In particular, it did not output the <DataTag> tag and it incorrectly nested a <Message> tag inside the <Incident> tag when a fatal error occured in a test. Unfortunately, it appears that the expected lightxml output for the selftests was produced by running tests using the newer logger, while the selftests did not use the older lightxml logger. Thus the errors were not detected by the selftests. This commit adds the older lightxml logger to the selftests, updates the expected test data accordingly, and modifies the newer lightxml logger to behave correctly. This last item is achieved by making the lightxml streamer copy most of the code from the xml streamer -- lightxml output is supposed to be same as xml, except for the omission of the root and <TestCase> tags. Change-Id: Ie6e1f69dd6000df2b9d0c5c8e2109fe7bbff3956 Reviewed-on: http://codereview.qt.nokia.com/3902 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/testlib/qtestlightxmlstreamer.cpp88
1 files changed, 60 insertions, 28 deletions
diff --git a/src/testlib/qtestlightxmlstreamer.cpp b/src/testlib/qtestlightxmlstreamer.cpp
index 892c0fd64e..4aba2a2bf8 100644
--- a/src/testlib/qtestlightxmlstreamer.cpp
+++ b/src/testlib/qtestlightxmlstreamer.cpp
@@ -77,9 +77,32 @@ void QTestLightXmlStreamer::formatStart(const QTestElement *element, QTestCharBu
QTestCharBuffer cdataDesc;
QXmlTestLogger::xmlCdata(&cdataDesc, element->attributeValue(QTest::AI_Description));
- QTest::qt_asprintf(formatted, " <Description><![CDATA[%s]]></Description>\n",
- cdataDesc.constData());
- break;
+ QTestCharBuffer location;
+ QTestCharBuffer quotedFile;
+ QXmlTestLogger::xmlQuote(&quotedFile, element->attributeValue(QTest::AI_File));
+
+ QTest::qt_asprintf(&location, "%s=\"%s\" %s=\"%s\"",
+ element->attributeName(QTest::AI_File),
+ quotedFile.constData(),
+ element->attributeName(QTest::AI_Line),
+ element->attributeValue(QTest::AI_Line));
+
+ if (element->attribute(QTest::AI_Tag)) {
+ QTestCharBuffer cdataTag;
+ QXmlTestLogger::xmlCdata(&cdataTag, element->attributeValue(QTest::AI_Tag));
+ QTest::qt_asprintf(formatted, "<Incident type=\"%s\" %s>\n"
+ " <DataTag><![CDATA[%s]]></DataTag>\n"
+ " <Description><![CDATA[%s]]></Description>\n"
+ "</Incident>\n", element->attributeValue(QTest::AI_Result),
+ location.constData(), cdataTag.constData(), cdataDesc.constData());
+ }
+ else {
+ QTest::qt_asprintf(formatted, "<Incident type=\"%s\" %s>\n"
+ " <Description><![CDATA[%s]]></Description>\n"
+ "</Incident>\n", element->attributeValue(QTest::AI_Result),
+ location.constData(), cdataDesc.constData());
+ }
+ break;
}
case QTest::LET_Error: {
// assuming type and attribute names don't need quoting
@@ -88,12 +111,20 @@ void QTestLightXmlStreamer::formatStart(const QTestElement *element, QTestCharBu
QXmlTestLogger::xmlQuote(&quotedFile, element->attributeValue(QTest::AI_File));
QXmlTestLogger::xmlCdata(&cdataDesc, element->attributeValue(QTest::AI_Description));
- QTest::qt_asprintf(formatted, "<Message type=\"%s\" %s=\"%s\" %s=\"%s\">\n <Description><![CDATA[%s]]></Description>\n</Message>\n",
+ QTestCharBuffer tagbuf;
+ if (element->attribute(QTest::AI_Tag)) {
+ QTestCharBuffer cdataTag;
+ QXmlTestLogger::xmlCdata(&cdataTag, element->attributeValue(QTest::AI_Tag));
+ QTest::qt_asprintf(&tagbuf, " <DataTag><![CDATA[%s]]></DataTag>\n", cdataTag.constData());
+ }
+
+ QTest::qt_asprintf(formatted, "<Message type=\"%s\" %s=\"%s\" %s=\"%s\">\n%s <Description><![CDATA[%s]]></Description>\n</Message>\n",
element->attributeValue(QTest::AI_Type),
element->attributeName(QTest::AI_File),
quotedFile.constData(),
element->attributeName(QTest::AI_Line),
element->attributeValue(QTest::AI_Line),
+ tagbuf.constData(),
cdataDesc.constData());
break;
}
@@ -126,10 +157,29 @@ void QTestLightXmlStreamer::formatEnd(const QTestElement *element, QTestCharBuff
return;
if (element->elementType() == QTest::LET_TestCase) {
- if( element->attribute(QTest::AI_Result) && element->childElements())
- QTest::qt_asprintf(formatted, "</Incident>\n</TestFunction>\n");
- else
+ bool failed = false;
+ for (QTestElement* child = element->childElements(); child; child = child->nextElement()) {
+ if ( child->elementType() == QTest::LET_Failure
+ && child->attribute(QTest::AI_Result)
+ && ( !strcmp(child->attributeValue(QTest::AI_Result), "fail")
+ || !strcmp(child->attributeValue(QTest::AI_Result), "xpass"))
+ )
+ {
+ failed = true;
+ break;
+ }
+ }
+
+ // For passing functions, no Incident has been output yet.
+ // For failing functions, we already output one.
+ // Please note: we are outputting "pass" even if there was an xfail etc.
+ // This is by design (arguably bad design, but dangerous to change now!)
+ if (element->attribute(QTest::AI_Result) && !failed) {
+ QTest::qt_asprintf(formatted, "<Incident type=\"pass\" file=\"\" line=\"0\" />\n</TestFunction>\n");
+ }
+ else {
QTest::qt_asprintf(formatted, "</TestFunction>\n");
+ }
} else {
formatted->data()[0] = '\0';
}
@@ -137,29 +187,11 @@ void QTestLightXmlStreamer::formatEnd(const QTestElement *element, QTestCharBuff
void QTestLightXmlStreamer::formatBeforeAttributes(const QTestElement *element, QTestCharBuffer *formatted) const
{
- if(!element || !formatted)
+ Q_UNUSED(element);
+ if (!formatted)
return;
- if (element->elementType() == QTest::LET_TestCase && element->attribute(QTest::AI_Result)) {
- QTestCharBuffer buf;
- QTestCharBuffer quotedFile;
- QXmlTestLogger::xmlQuote(&quotedFile, element->attributeValue(QTest::AI_File));
-
- QTest::qt_asprintf(&buf, "%s=\"%s\" %s=\"%s\"",
- element->attributeName(QTest::AI_File),
- quotedFile.constData(),
- element->attributeName(QTest::AI_Line),
- element->attributeValue(QTest::AI_Line));
-
- if( !element->childElements() )
- QTest::qt_asprintf(formatted, "<Incident type=\"%s\" %s />\n",
- element->attributeValue(QTest::AI_Result), buf.constData());
- else
- QTest::qt_asprintf(formatted, "<Incident type=\"%s\" %s>\n",
- element->attributeValue(QTest::AI_Result), buf.constData());
- } else {
- formatted->data()[0] = '\0';
- }
+ formatted->data()[0] = '\0';
}
void QTestLightXmlStreamer::output(QTestElement *element) const