diff options
Diffstat (limited to 'src/testlib')
-rw-r--r-- | src/testlib/qtestbasicstreamer.cpp | 8 | ||||
-rw-r--r-- | src/testlib/qtestbasicstreamer.h | 4 | ||||
-rw-r--r-- | src/testlib/qtestcoreelement.h | 3 | ||||
-rw-r--r-- | src/testlib/qtestelementattribute.h | 3 | ||||
-rw-r--r-- | src/testlib/qtestlogger.cpp | 13 | ||||
-rw-r--r-- | src/testlib/qtestlogger_p.h | 1 | ||||
-rw-r--r-- | src/testlib/qtestxunitstreamer.cpp | 44 | ||||
-rw-r--r-- | src/testlib/qtestxunitstreamer.h | 2 | ||||
-rw-r--r-- | src/testlib/qxmltestlogger.cpp | 4 |
9 files changed, 66 insertions, 16 deletions
diff --git a/src/testlib/qtestbasicstreamer.cpp b/src/testlib/qtestbasicstreamer.cpp index b133aae..35574d5 100644 --- a/src/testlib/qtestbasicstreamer.cpp +++ b/src/testlib/qtestbasicstreamer.cpp @@ -55,7 +55,7 @@ void QTestBasicStreamer::formatAfterAttributes(const QTestElement *element, char QTest::qt_snprintf(formatted, 10, ""); } -void QTestBasicStreamer::formatAttributes(const QTestElementAttribute *attribute, char *formatted) const +void QTestBasicStreamer::formatAttributes(const QTestElement *, const QTestElementAttribute *attribute, char *formatted) const { if(!attribute || !formatted ) return; @@ -90,7 +90,7 @@ void QTestBasicStreamer::outputElements(QTestElement *element, bool) const formatBeforeAttributes(element, buf); outputString(buf); - outputElementAttributes(element->attributes()); + outputElementAttributes(element, element->attributes()); formatAfterAttributes(element, buf); outputString(buf); @@ -105,11 +105,11 @@ void QTestBasicStreamer::outputElements(QTestElement *element, bool) const } } -void QTestBasicStreamer::outputElementAttributes(QTestElementAttribute *attribute) const +void QTestBasicStreamer::outputElementAttributes(const QTestElement* element, QTestElementAttribute *attribute) const { char buf[1024]; while(attribute){ - formatAttributes(attribute, buf); + formatAttributes(element, attribute, buf); outputString(buf); attribute = attribute->nextElement(); } diff --git a/src/testlib/qtestbasicstreamer.h b/src/testlib/qtestbasicstreamer.h index cfd6b94..5a6b0b6 100644 --- a/src/testlib/qtestbasicstreamer.h +++ b/src/testlib/qtestbasicstreamer.h @@ -30,9 +30,9 @@ class QTestBasicStreamer virtual void formatEnd(const QTestElement *element = 0, char *formatted = 0) const; virtual void formatBeforeAttributes(const QTestElement *element = 0, char *formatted = 0) const; virtual void formatAfterAttributes(const QTestElement *element = 0, char *formatted = 0) const; - virtual void formatAttributes(const QTestElementAttribute *attribute = 0, char *formatted = 0) const; + virtual void formatAttributes(const QTestElement *element = 0, const QTestElementAttribute *attribute = 0, char *formatted = 0) const; virtual void outputElements(QTestElement *element, bool isChildElement = false) const; - virtual void outputElementAttributes(QTestElementAttribute *attribute) const; + virtual void outputElementAttributes(const QTestElement *element, QTestElementAttribute *attribute) const; private: const QTestLogger *testLogger; diff --git a/src/testlib/qtestcoreelement.h b/src/testlib/qtestcoreelement.h index ea05c19..63c4efa 100644 --- a/src/testlib/qtestcoreelement.h +++ b/src/testlib/qtestcoreelement.h @@ -90,7 +90,8 @@ const char *QTestCoreElement<ElementType>::elementName() const "error", "testcase", "testsuite", - "benchmark" + "benchmark", + "system-err" }; if(type != QTest::LET_Undefined) diff --git a/src/testlib/qtestelementattribute.h b/src/testlib/qtestelementattribute.h index 2e23cd9..ccbe8e4 100644 --- a/src/testlib/qtestelementattribute.h +++ b/src/testlib/qtestelementattribute.h @@ -37,7 +37,8 @@ namespace QTest { LET_Error = 3, LET_TestCase = 4, LET_TestSuite = 5, - LET_Benchmark = 6 + LET_Benchmark = 6, + LET_SystemError = 7 }; } diff --git a/src/testlib/qtestlogger.cpp b/src/testlib/qtestlogger.cpp index a1a6d52..ffc73ae 100644 --- a/src/testlib/qtestlogger.cpp +++ b/src/testlib/qtestlogger.cpp @@ -14,7 +14,7 @@ QT_BEGIN_NAMESPACE QTestLogger::QTestLogger(int fm) - :listOfTestcases(0), currentLogElement(0), + :listOfTestcases(0), currentLogElement(0), errorLogElement(0), logFormatter(0), format( (TestLoggerFormat)fm ), filelogger(new QTestFileLogger), testCounter(0), passCounter(0), failureCounter(0), errorCounter(0), @@ -49,6 +49,8 @@ void QTestLogger::startLogging() break; }case TLF_XunitXml:{ logFormatter = new QTestXunitStreamer; + delete errorLogElement; + errorLogElement = new QTestElement(QTest::LET_SystemError); filelogger->init(); break; } @@ -101,6 +103,8 @@ void QTestLogger::stopLogging() testcase = testcase->nextElement(); } + currentLogElement->addLogElement(errorLogElement); + QTestElement *it = currentLogElement; logFormatter->output(it); }else{ @@ -276,6 +280,13 @@ void QTestLogger::addMessage(MessageTypes type, const char *message, const char currentLogElement->addLogElement(errorElement); ++errorCounter; + + // Also add the message to the system error log (i.e. stderr), if one exists + if (errorLogElement) { + QTestElement *systemErrorElement = new QTestElement(QTest::LET_Error); + systemErrorElement->addAttribute(QTest::AI_Description, message); + errorLogElement->addLogElement(systemErrorElement); + } } void QTestLogger::setLogFormat(TestLoggerFormat fm) diff --git a/src/testlib/qtestlogger_p.h b/src/testlib/qtestlogger_p.h index 3badb1d..f695069 100644 --- a/src/testlib/qtestlogger_p.h +++ b/src/testlib/qtestlogger_p.h @@ -52,6 +52,7 @@ class QTestLogger : public QAbstractTestLogger private: QTestElement *listOfTestcases; QTestElement *currentLogElement; + QTestElement *errorLogElement; QTestBasicStreamer *logFormatter; TestLoggerFormat format; QTestFileLogger *filelogger; 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); diff --git a/src/testlib/qtestxunitstreamer.h b/src/testlib/qtestxunitstreamer.h index 1ce9576..a6554af 100644 --- a/src/testlib/qtestxunitstreamer.h +++ b/src/testlib/qtestxunitstreamer.h @@ -16,7 +16,7 @@ class QTestXunitStreamer: public QTestBasicStreamer void formatStart(const QTestElement *element = 0, char *formatted = 0) const; void formatEnd(const QTestElement *element = 0, char *formatted = 0) const; void formatAfterAttributes(const QTestElement *element = 0, char *formatted = 0) const; - void formatAttributes(const QTestElementAttribute *attribute = 0, char *formatted = 0) const; + void formatAttributes(const QTestElement *element = 0, const QTestElementAttribute *attribute = 0, char *formatted = 0) const; void output(QTestElement *element) const; void outputElements(QTestElement *element, bool isChildElement = false) const; diff --git a/src/testlib/qxmltestlogger.cpp b/src/testlib/qxmltestlogger.cpp index ec9a5d2..0606ced 100644 --- a/src/testlib/qxmltestlogger.cpp +++ b/src/testlib/qxmltestlogger.cpp @@ -325,6 +325,10 @@ void QXmlTestLogger::xmlQuote(char* dest, char const* src, size_t n) MAP_ENTITY('"', """); MAP_ENTITY('&', "&"); + // not strictly necessary, but allows handling of comments without + // having to explicitly look for `--' + MAP_ENTITY('-', "-"); + #undef MAP_ENTITY case 0: |