diff options
author | Harald Fernengel <harald@trolltech.com> | 2009-08-07 13:08:09 (GMT) |
---|---|---|
committer | Harald Fernengel <harald@trolltech.com> | 2009-08-07 13:10:36 (GMT) |
commit | dfa284220498a1e32ab3133f203bcb41cfa136b7 (patch) | |
tree | e6e8a6cae4b2195313258c5001100e2557c6463e /src/testlib/qtestxunitstreamer.cpp | |
parent | 658c30c214070e8ff05ddaf1cb7b161c1b73f5ce (diff) | |
download | Qt-dfa284220498a1e32ab3133f203bcb41cfa136b7.zip Qt-dfa284220498a1e32ab3133f203bcb41cfa136b7.tar.gz Qt-dfa284220498a1e32ab3133f203bcb41cfa136b7.tar.bz2 |
Refactor QTestCharBuffer a bit
Use a static buffer for small strings, and making it oom safe.
We can now see messages up to 512 bytes even if we run out of memory
(important for OOM tests). Also, testlogging (< 512 bytes per line)
should again work without a single allocation.
Reviewed-By: Rohan McGovern <rohan.mcgovern@nokia.com>
Diffstat (limited to 'src/testlib/qtestxunitstreamer.cpp')
-rw-r--r-- | src/testlib/qtestxunitstreamer.cpp | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/src/testlib/qtestxunitstreamer.cpp b/src/testlib/qtestxunitstreamer.cpp index d5d2631..932b70b 100644 --- a/src/testlib/qtestxunitstreamer.cpp +++ b/src/testlib/qtestxunitstreamer.cpp @@ -73,7 +73,7 @@ void QTestXunitStreamer::indentForElement(const QTestElement* element, char* buf } } -void QTestXunitStreamer::formatStart(const QTestElement *element, char **formatted) const +void QTestXunitStreamer::formatStart(const QTestElement *element, QTestCharBuffer *formatted) const { if(!element || !formatted ) return; @@ -85,8 +85,7 @@ void QTestXunitStreamer::formatStart(const QTestElement *element, char **formatt if (element->elementType() == QTest::LET_Error) { if (element->parentElement()->elementType() == QTest::LET_SystemError) { QTest::qt_asprintf(formatted, "<![CDATA["); - } - else { + } else { QTest::qt_asprintf(formatted, "%s<!--", indent); } return; @@ -95,13 +94,13 @@ void QTestXunitStreamer::formatStart(const QTestElement *element, char **formatt QTest::qt_asprintf(formatted, "%s<%s", indent, element->elementName()); } -void QTestXunitStreamer::formatEnd(const QTestElement *element, char **formatted) const +void QTestXunitStreamer::formatEnd(const QTestElement *element, QTestCharBuffer *formatted) const { - if(!element || !formatted ) + if (!element || !formatted ) return; - if(!element->childElements()){ - QTest::qt_asprintf(formatted, ""); + if (!element->childElements()){ + formatted->data()[0] = '\0'; return; } @@ -111,7 +110,7 @@ void QTestXunitStreamer::formatEnd(const QTestElement *element, char **formatted QTest::qt_asprintf(formatted, "%s</%s>\n", indent, element->elementName()); } -void QTestXunitStreamer::formatAttributes(const QTestElement* element, const QTestElementAttribute *attribute, char **formatted) const +void QTestXunitStreamer::formatAttributes(const QTestElement* element, const QTestElementAttribute *attribute, QTestCharBuffer *formatted) const { if(!attribute || !formatted ) return; @@ -136,15 +135,14 @@ void QTestXunitStreamer::formatAttributes(const QTestElement* element, const QTe if (key) { QTestCharBuffer quotedValue; - QXmlTestLogger::xmlQuote(quotedValue, attribute->value()); + QXmlTestLogger::xmlQuote("edValue, attribute->value()); QTest::qt_asprintf(formatted, " %s=\"%s\"", key, quotedValue.constData()); - } - else { - QTest::qt_asprintf(formatted, ""); + } else { + formatted->data()[0] = '\0'; } } -void QTestXunitStreamer::formatAfterAttributes(const QTestElement *element, char **formatted) const +void QTestXunitStreamer::formatAfterAttributes(const QTestElement *element, QTestCharBuffer *formatted) const { if(!element || !formatted ) return; @@ -153,8 +151,7 @@ void QTestXunitStreamer::formatAfterAttributes(const QTestElement *element, char if (element->elementType() == QTest::LET_Error) { if (element->parentElement()->elementType() == QTest::LET_SystemError) { QTest::qt_asprintf(formatted, "]]>\n"); - } - else { + } else { QTest::qt_asprintf(formatted, " -->\n"); } return; @@ -187,22 +184,22 @@ void QTestXunitStreamer::outputElements(QTestElement *element, bool) const hasChildren = element->childElements(); if(element->elementType() != QTest::LET_Benchmark){ - formatStart(element, buf); - outputString(buf); + formatStart(element, &buf); + outputString(buf.data()); - formatBeforeAttributes(element, buf); - outputString(buf); + formatBeforeAttributes(element, &buf); + outputString(buf.data()); outputElementAttributes(element, element->attributes()); - formatAfterAttributes(element, buf); - outputString(buf); + formatAfterAttributes(element, &buf); + outputString(buf.data()); if(hasChildren) outputElements(element->childElements(), true); - formatEnd(element, buf); - outputString(buf); + formatEnd(element, &buf); + outputString(buf.data()); } element = element->previousElement(); } |