diff options
Diffstat (limited to 'src/testlib')
-rw-r--r-- | src/testlib/qtestlogger.cpp | 29 | ||||
-rw-r--r-- | src/testlib/qtestlogger_p.h | 1 | ||||
-rw-r--r-- | src/testlib/qtestxmlstreamer.cpp | 58 |
3 files changed, 60 insertions, 28 deletions
diff --git a/src/testlib/qtestlogger.cpp b/src/testlib/qtestlogger.cpp index 6c76388..f0be6be 100644 --- a/src/testlib/qtestlogger.cpp +++ b/src/testlib/qtestlogger.cpp @@ -211,10 +211,7 @@ void QTestLogger::addIncident(IncidentTypes type, const char *description, QTest::qt_snprintf(buf, sizeof(buf), "%i", line); failureElement->addAttribute(QTest::AI_Line, buf); failureElement->addAttribute(QTest::AI_Description, description); - const char* tag = QTestResult::currentDataTag(); - if (tag) { - failureElement->addAttribute(QTest::AI_Tag, tag); - } + addTag(failureElement); currentLogElement->addLogElement(failureElement); } @@ -279,6 +276,27 @@ void QTestLogger::addBenchmarkResult(const QBenchmarkResult &result) currentLogElement->addLogElement(benchmarkElement); } +void QTestLogger::addTag(QTestElement* element) +{ + const char *tag = QTestResult::currentDataTag(); + const char *gtag = QTestResult::currentGlobalDataTag(); + const char *filler = (tag && gtag) ? ":" : ""; + if ((!tag || !tag[0]) && (!gtag || !gtag[0])) { + return; + } + + if (!tag) { + tag = ""; + } + if (!gtag) { + gtag = ""; + } + + QTestCharBuffer buf; + QTest::qt_asprintf(&buf, "%s%s%s", gtag, filler, tag); + element->addAttribute(QTest::AI_Tag, buf.constData()); +} + void QTestLogger::addMessage(MessageTypes type, const char *message, const char *file, int line) { QTestElement *errorElement = new QTestElement(QTest::LET_Error); @@ -299,7 +317,7 @@ void QTestLogger::addMessage(MessageTypes type, const char *message, const char break; case QAbstractTestLogger::QWarning: ++qwarnCounter; - typeBuf = "qwarning"; + typeBuf = "qwarn"; break; case QAbstractTestLogger::QFatal: ++qfatalCounter; @@ -320,6 +338,7 @@ void QTestLogger::addMessage(MessageTypes type, const char *message, const char errorElement->addAttribute(QTest::AI_Type, typeBuf); errorElement->addAttribute(QTest::AI_Description, message); + addTag(errorElement); if(file) errorElement->addAttribute(QTest::AI_File, file); diff --git a/src/testlib/qtestlogger_p.h b/src/testlib/qtestlogger_p.h index 31f7d55..bb7a358 100644 --- a/src/testlib/qtestlogger_p.h +++ b/src/testlib/qtestlogger_p.h @@ -83,6 +83,7 @@ class QTestLogger : public QAbstractTestLogger void addIncident(IncidentTypes type, const char *description, const char *file = 0, int line = 0); void addBenchmarkResult(const QBenchmarkResult &result); + void addTag(QTestElement* element); void addMessage(MessageTypes type, const char *message, const char *file = 0, int line = 0); diff --git a/src/testlib/qtestxmlstreamer.cpp b/src/testlib/qtestxmlstreamer.cpp index b9946e5..f63c221 100644 --- a/src/testlib/qtestxmlstreamer.cpp +++ b/src/testlib/qtestxmlstreamer.cpp @@ -111,12 +111,20 @@ void QTestXmlStreamer::formatStart(const QTestElement *element, QTestCharBuffer QXmlTestLogger::xmlQuote("edFile, 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; } @@ -149,7 +157,29 @@ void QTestXmlStreamer::formatEnd(const QTestElement *element, QTestCharBuffer *f return; if (element->elementType() == QTest::LET_TestCase) { - QTest::qt_asprintf(formatted, "</TestFunction>\n"); + 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'; } @@ -157,29 +187,11 @@ void QTestXmlStreamer::formatEnd(const QTestElement *element, QTestCharBuffer *f void QTestXmlStreamer::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("edFile, 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 { - formatted->data()[0] = '\0'; - } - } else { - formatted->data()[0] = '\0'; - } + formatted->data()[0] = '\0'; } void QTestXmlStreamer::output(QTestElement *element) const |