summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRohan McGovern <rohan.mcgovern@nokia.com>2009-07-30 01:15:39 (GMT)
committerRohan McGovern <rohan.mcgovern@nokia.com>2009-07-30 04:54:44 (GMT)
commitc1a90a535206e0a146e13c60d981a855178e69ca (patch)
treebcfce35bebe38e858d99f2fdd91fdf3c4c78f4d5
parent79ed97b8298e3c7e3c7d266c905024affeba7258 (diff)
downloadQt-c1a90a535206e0a146e13c60d981a855178e69ca.zip
Qt-c1a90a535206e0a146e13c60d981a855178e69ca.tar.gz
Qt-c1a90a535206e0a146e13c60d981a855178e69ca.tar.bz2
Convert all testlib loggers to use dynamically allocated strings.
Most log elements in all loggers can now be of (more or less) arbitrary length. Selftests pass and are memcheck-clean. The increase in heap usage seems negligible (it's below the default minimum threshold of massif). Task: 253861 Reviewed-by: Michael Goddard
-rw-r--r--src/testlib/qtestlightxmlstreamer.cpp49
-rw-r--r--src/testlib/qtestxmlstreamer.cpp89
-rw-r--r--src/testlib/qtestxunitstreamer.cpp10
-rw-r--r--src/testlib/qxmltestlogger.cpp96
4 files changed, 112 insertions, 132 deletions
diff --git a/src/testlib/qtestlightxmlstreamer.cpp b/src/testlib/qtestlightxmlstreamer.cpp
index a7e205a..e176201 100644
--- a/src/testlib/qtestlightxmlstreamer.cpp
+++ b/src/testlib/qtestlightxmlstreamer.cpp
@@ -66,54 +66,48 @@ void QTestLightXmlStreamer::formatStart(const QTestElement *element, char **form
switch(element->elementType()){
case QTest::LET_TestCase: {
- char quotedTf[950];
- QXmlTestLogger::xmlQuote(quotedTf, element->attributeValue(QTest::AI_Name),
- sizeof(quotedTf));
+ QTestCharBuffer quotedTf;
+ QXmlTestLogger::xmlQuote(quotedTf, element->attributeValue(QTest::AI_Name));
- QTest::qt_asprintf(formatted, "<TestFunction name=\"%s\">\n", quotedTf);
+ QTest::qt_asprintf(formatted, "<TestFunction name=\"%s\">\n", quotedTf.constData());
break;
}
case QTest::LET_Failure: {
- char cdataDesc[900];
- QXmlTestLogger::xmlCdata(cdataDesc, element->attributeValue(QTest::AI_Description),
- sizeof(cdataDesc));
+ QTestCharBuffer cdataDesc;
+ QXmlTestLogger::xmlCdata(cdataDesc, element->attributeValue(QTest::AI_Description));
QTest::qt_asprintf(formatted, " <Description><![CDATA[%s]]></Description>\n",
- cdataDesc);
+ cdataDesc.constData());
break;
}
case QTest::LET_Error: {
// assuming type and attribute names don't need quoting
- char quotedFile[128];
- char cdataDesc[700];
- QXmlTestLogger::xmlQuote(quotedFile, element->attributeValue(QTest::AI_File),
- sizeof(quotedFile));
- QXmlTestLogger::xmlCdata(cdataDesc, element->attributeValue(QTest::AI_Description),
- sizeof(cdataDesc));
+ QTestCharBuffer quotedFile;
+ QTestCharBuffer cdataDesc;
+ 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",
element->attributeValue(QTest::AI_Type),
element->attributeName(QTest::AI_File),
- quotedFile,
+ quotedFile.constData(),
element->attributeName(QTest::AI_Line),
element->attributeValue(QTest::AI_Line),
- cdataDesc);
+ cdataDesc.constData());
break;
}
case QTest::LET_Benchmark: {
// assuming value and iterations don't need quoting
- char quotedMetric[256];
- char quotedTag[256];
- QXmlTestLogger::xmlQuote(quotedMetric, element->attributeValue(QTest::AI_Metric),
- sizeof(quotedMetric));
- QXmlTestLogger::xmlQuote(quotedTag, element->attributeValue(QTest::AI_Tag),
- sizeof(quotedTag));
+ QTestCharBuffer quotedMetric;
+ QTestCharBuffer quotedTag;
+ QXmlTestLogger::xmlQuote(quotedMetric, element->attributeValue(QTest::AI_Metric));
+ QXmlTestLogger::xmlQuote(quotedTag, element->attributeValue(QTest::AI_Tag));
QTest::qt_asprintf(formatted, "<BenchmarkResult %s=\"%s\" %s=\"%s\" %s=\"%s\" %s=\"%s\" />\n",
element->attributeName(QTest::AI_Metric),
- quotedMetric,
+ quotedMetric.constData(),
element->attributeName(QTest::AI_Tag),
- quotedTag,
+ quotedTag.constData(),
element->attributeName(QTest::AI_Value),
element->attributeValue(QTest::AI_Value),
element->attributeName(QTest::AI_Iterations),
@@ -147,13 +141,12 @@ void QTestLightXmlStreamer::formatBeforeAttributes(const QTestElement *element,
if (element->elementType() == QTest::LET_TestCase && element->attribute(QTest::AI_Result)){
QTestCharBuffer buf;
- char quotedFile[700];
- QXmlTestLogger::xmlQuote(quotedFile, element->attributeValue(QTest::AI_File),
- sizeof(quotedFile));
+ QTestCharBuffer quotedFile;
+ QXmlTestLogger::xmlQuote(quotedFile, element->attributeValue(QTest::AI_File));
QTest::qt_asprintf(buf, "%s=\"%s\" %s=\"%s\"",
element->attributeName(QTest::AI_File),
- quotedFile,
+ quotedFile.constData(),
element->attributeName(QTest::AI_Line),
element->attributeValue(QTest::AI_Line));
diff --git a/src/testlib/qtestxmlstreamer.cpp b/src/testlib/qtestxmlstreamer.cpp
index b9e0a38..1b6e674 100644
--- a/src/testlib/qtestxmlstreamer.cpp
+++ b/src/testlib/qtestxmlstreamer.cpp
@@ -67,79 +67,71 @@ void QTestXmlStreamer::formatStart(const QTestElement *element, char **formatted
switch(element->elementType()){
case QTest::LET_TestCase: {
- char quotedTf[950];
- QXmlTestLogger::xmlQuote(quotedTf, element->attributeValue(QTest::AI_Name),
- sizeof(quotedTf));
+ QTestCharBuffer quotedTf;
+ QXmlTestLogger::xmlQuote(quotedTf, element->attributeValue(QTest::AI_Name));
- QTest::qt_asprintf(formatted, "<TestFunction name=\"%s\">\n", quotedTf);
+ QTest::qt_asprintf(formatted, "<TestFunction name=\"%s\">\n", quotedTf.constData());
break;
}
case QTest::LET_Failure: {
- char cdataDesc[800];
- QXmlTestLogger::xmlCdata(cdataDesc, element->attributeValue(QTest::AI_Description),
- sizeof(cdataDesc));
+ QTestCharBuffer cdataDesc;
+ QXmlTestLogger::xmlCdata(cdataDesc, element->attributeValue(QTest::AI_Description));
- char location[100];
- char quotedFile[70];
- QXmlTestLogger::xmlQuote(quotedFile, element->attributeValue(QTest::AI_File),
- sizeof(quotedFile));
+ QTestCharBuffer location;
+ QTestCharBuffer quotedFile;
+ QXmlTestLogger::xmlQuote(quotedFile, element->attributeValue(QTest::AI_File));
- QTest::qt_snprintf(location, sizeof(location), "%s=\"%s\" %s=\"%s\"",
+ QTest::qt_asprintf(location, "%s=\"%s\" %s=\"%s\"",
element->attributeName(QTest::AI_File),
- quotedFile,
+ quotedFile.constData(),
element->attributeName(QTest::AI_Line),
element->attributeValue(QTest::AI_Line));
if (element->attribute(QTest::AI_Tag)) {
- char cdataTag[100];
- QXmlTestLogger::xmlCdata(cdataTag, element->attributeValue(QTest::AI_Tag),
- sizeof(cdataTag));
+ 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, cdataTag, cdataDesc);
+ 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, cdataDesc);
+ location.constData(), cdataDesc.constData());
}
break;
}
case QTest::LET_Error: {
// assuming type and attribute names don't need quoting
- char quotedFile[128];
- char cdataDesc[700];
- QXmlTestLogger::xmlQuote(quotedFile, element->attributeValue(QTest::AI_File),
- sizeof(quotedFile));
- QXmlTestLogger::xmlCdata(cdataDesc, element->attributeValue(QTest::AI_Description),
- sizeof(cdataDesc));
+ QTestCharBuffer quotedFile;
+ QTestCharBuffer cdataDesc;
+ 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",
element->attributeValue(QTest::AI_Type),
element->attributeName(QTest::AI_File),
- quotedFile,
+ quotedFile.constData(),
element->attributeName(QTest::AI_Line),
element->attributeValue(QTest::AI_Line),
- cdataDesc);
+ cdataDesc.constData());
break;
}
case QTest::LET_Benchmark: {
// assuming value and iterations don't need quoting
- char quotedMetric[256];
- char quotedTag[256];
- QXmlTestLogger::xmlQuote(quotedMetric, element->attributeValue(QTest::AI_Metric),
- sizeof(quotedMetric));
- QXmlTestLogger::xmlQuote(quotedTag, element->attributeValue(QTest::AI_Tag),
- sizeof(quotedTag));
+ QTestCharBuffer quotedMetric;
+ QTestCharBuffer quotedTag;
+ QXmlTestLogger::xmlQuote(quotedMetric, element->attributeValue(QTest::AI_Metric));
+ QXmlTestLogger::xmlQuote(quotedTag, element->attributeValue(QTest::AI_Tag));
QTest::qt_asprintf(formatted, "<BenchmarkResult %s=\"%s\" %s=\"%s\" %s=\"%s\" %s=\"%s\" />\n",
element->attributeName(QTest::AI_Metric),
- quotedMetric,
+ quotedMetric.constData(),
element->attributeName(QTest::AI_Tag),
- quotedTag,
+ quotedTag.constData(),
element->attributeName(QTest::AI_Value),
element->attributeValue(QTest::AI_Value),
element->attributeName(QTest::AI_Iterations),
@@ -169,20 +161,19 @@ void QTestXmlStreamer::formatBeforeAttributes(const QTestElement *element, char
return;
if (element->elementType() == QTest::LET_TestCase && element->attribute(QTest::AI_Result)){
- char buf[900];
- char quotedFile[700];
- QXmlTestLogger::xmlQuote(quotedFile, element->attributeValue(QTest::AI_File),
- sizeof(quotedFile));
+ QTestCharBuffer buf;
+ QTestCharBuffer quotedFile;
+ QXmlTestLogger::xmlQuote(quotedFile, element->attributeValue(QTest::AI_File));
- QTest::qt_snprintf(buf, sizeof(buf), "%s=\"%s\" %s=\"%s\"",
+ QTest::qt_asprintf(buf, "%s=\"%s\" %s=\"%s\"",
element->attributeName(QTest::AI_File),
- quotedFile,
+ 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);
+ element->attributeValue(QTest::AI_Result), buf.constData());
}
else {
QTest::qt_asprintf(formatted, "");
@@ -194,24 +185,24 @@ void QTestXmlStreamer::formatBeforeAttributes(const QTestElement *element, char
void QTestXmlStreamer::output(QTestElement *element) const
{
- char buf[1024];
- char quotedTc[800];
- QXmlTestLogger::xmlQuote(quotedTc, QTestResult::currentTestObjectName(), sizeof(quotedTc));
+ QTestCharBuffer buf;
+ QTestCharBuffer quotedTc;
+ QXmlTestLogger::xmlQuote(quotedTc, QTestResult::currentTestObjectName());
- QTest::qt_snprintf(buf, sizeof(buf), "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<TestCase name=\"%s\">\n",
- quotedTc);
+ QTest::qt_asprintf(buf, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<TestCase name=\"%s\">\n",
+ quotedTc.constData());
outputString(buf);
- QTest::qt_snprintf(buf, sizeof(buf), "<Environment>\n <QtVersion>%s</QtVersion>\n <QTestVersion>%s</QTestVersion>\n",
+ QTest::qt_asprintf(buf, "<Environment>\n <QtVersion>%s</QtVersion>\n <QTestVersion>%s</QTestVersion>\n",
qVersion(), QTEST_VERSION_STR );
outputString(buf);
- QTest::qt_snprintf(buf, sizeof(buf), "</Environment>\n");
+ QTest::qt_asprintf(buf, "</Environment>\n");
outputString(buf);
QTestBasicStreamer::output(element);
- QTest::qt_snprintf(buf, sizeof(buf), "</TestCase>\n");
+ QTest::qt_asprintf(buf, "</TestCase>\n");
outputString(buf);
}
diff --git a/src/testlib/qtestxunitstreamer.cpp b/src/testlib/qtestxunitstreamer.cpp
index f59c0f5..d5d2631 100644
--- a/src/testlib/qtestxunitstreamer.cpp
+++ b/src/testlib/qtestxunitstreamer.cpp
@@ -135,9 +135,9 @@ void QTestXunitStreamer::formatAttributes(const QTestElement* element, const QTe
key = attribute->name();
if (key) {
- char quotedValue[900];
- QXmlTestLogger::xmlQuote(quotedValue, attribute->value(), sizeof(quotedValue));
- QTest::qt_asprintf(formatted, " %s=\"%s\"", key, quotedValue);
+ QTestCharBuffer quotedValue;
+ QXmlTestLogger::xmlQuote(quotedValue, attribute->value());
+ QTest::qt_asprintf(formatted, " %s=\"%s\"", key, quotedValue.constData());
}
else {
QTest::qt_asprintf(formatted, "");
@@ -168,9 +168,7 @@ void QTestXunitStreamer::formatAfterAttributes(const QTestElement *element, char
void QTestXunitStreamer::output(QTestElement *element) const
{
- char buf[1024];
- QTest::qt_snprintf(buf, sizeof(buf), "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
- outputString(buf);
+ outputString("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
QTestBasicStreamer::output(element);
}
diff --git a/src/testlib/qxmltestlogger.cpp b/src/testlib/qxmltestlogger.cpp
index 8fc8dd9..fca7bfc 100644
--- a/src/testlib/qxmltestlogger.cpp
+++ b/src/testlib/qxmltestlogger.cpp
@@ -104,18 +104,18 @@ QXmlTestLogger::~QXmlTestLogger()
void QXmlTestLogger::startLogging()
{
QAbstractTestLogger::startLogging();
- char buf[1024];
+ QTestCharBuffer buf;
if (xmlmode == QXmlTestLogger::Complete) {
- char quotedTc[900];
- xmlQuote(quotedTc, QTestResult::currentTestObjectName(), sizeof(quotedTc));
- QTest::qt_snprintf(buf, sizeof(buf),
+ QTestCharBuffer quotedTc;
+ xmlQuote(quotedTc, QTestResult::currentTestObjectName());
+ QTest::qt_asprintf(buf,
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
- "<TestCase name=\"%s\">\n", quotedTc);
+ "<TestCase name=\"%s\">\n", quotedTc.constData());
outputString(buf);
}
- QTest::qt_snprintf(buf, sizeof(buf),
+ QTest::qt_asprintf(buf,
"<Environment>\n"
" <QtVersion>%s</QtVersion>\n"
" <QTestVersion>"QTEST_VERSION_STR"</QTestVersion>\n"
@@ -134,10 +134,10 @@ void QXmlTestLogger::stopLogging()
void QXmlTestLogger::enterTestFunction(const char *function)
{
- char buf[1024];
- char quotedFunction[950];
- xmlQuote(quotedFunction, function, sizeof(quotedFunction));
- QTest::qt_snprintf(buf, sizeof(buf), "<TestFunction name=\"%s\">\n", quotedFunction);
+ QTestCharBuffer buf;
+ QTestCharBuffer quotedFunction;
+ xmlQuote(quotedFunction, function);
+ QTest::qt_asprintf(buf, "<TestFunction name=\"%s\">\n", quotedFunction.constData());
outputString(buf);
}
@@ -208,51 +208,49 @@ static const char *messageFormatString(bool noDescription, bool noTag)
void QXmlTestLogger::addIncident(IncidentTypes type, const char *description,
const char *file, int line)
{
- // buffer must be large enough to hold all quoted/cdata buffers plus the format string itself
- char buf[5000];
+ QTestCharBuffer buf;
const char *tag = QTestResult::currentDataTag();
const char *gtag = QTestResult::currentGlobalDataTag();
const char *filler = (tag && gtag) ? ":" : "";
const bool notag = QTest::isEmpty(tag) && QTest::isEmpty(gtag);
- char quotedFile[1024];
- char cdataGtag[1024];
- char cdataTag[1024];
- char cdataDescription[1024];
+ QTestCharBuffer quotedFile;
+ QTestCharBuffer cdataGtag;
+ QTestCharBuffer cdataTag;
+ QTestCharBuffer cdataDescription;
- xmlQuote(quotedFile, file, sizeof(quotedFile));
- xmlCdata(cdataGtag, gtag, sizeof(cdataGtag));
- xmlCdata(cdataTag, tag, sizeof(cdataTag));
- xmlCdata(cdataDescription, description, sizeof(cdataDescription));
+ xmlQuote(quotedFile, file);
+ xmlCdata(cdataGtag, gtag);
+ xmlCdata(cdataTag, tag);
+ xmlCdata(cdataDescription, description);
- QTest::qt_snprintf(buf, sizeof(buf),
+ QTest::qt_asprintf(buf,
QTest::incidentFormatString(QTest::isEmpty(description), notag),
QTest::xmlIncidentType2String(type),
- quotedFile, line,
- cdataGtag,
+ quotedFile.constData(), line,
+ cdataGtag.constData(),
filler,
- cdataTag,
- cdataDescription);
+ cdataTag.constData(),
+ cdataDescription.constData());
outputString(buf);
}
void QXmlTestLogger::addBenchmarkResult(const QBenchmarkResult &result)
{
- char buf[1536];
- char quotedMetric[64];
- char quotedTag[1024];
+ QTestCharBuffer buf;
+ QTestCharBuffer quotedMetric;
+ QTestCharBuffer quotedTag;
xmlQuote(quotedMetric,
- QBenchmarkGlobalData::current->measurer->metricText().toAscii().constData(),
- sizeof(quotedMetric));
- xmlQuote(quotedTag, result.context.tag.toAscii().constData(), sizeof(quotedTag));
+ QBenchmarkGlobalData::current->measurer->metricText().toAscii().constData());
+ xmlQuote(quotedTag, result.context.tag.toAscii().constData());
- QTest::qt_snprintf(
- buf, sizeof(buf),
+ QTest::qt_asprintf(
+ buf,
QTest::benchmarkResultFormatString(),
- quotedMetric,
- quotedTag,
+ quotedMetric.constData(),
+ quotedTag.constData(),
QByteArray::number(result.value).constData(), //no 64-bit qt_snprintf support
result.iterations);
outputString(buf);
@@ -261,30 +259,30 @@ void QXmlTestLogger::addBenchmarkResult(const QBenchmarkResult &result)
void QXmlTestLogger::addMessage(MessageTypes type, const char *message,
const char *file, int line)
{
- char buf[5000];
+ QTestCharBuffer buf;
const char *tag = QTestResult::currentDataTag();
const char *gtag = QTestResult::currentGlobalDataTag();
const char *filler = (tag && gtag) ? ":" : "";
const bool notag = QTest::isEmpty(tag) && QTest::isEmpty(gtag);
- char quotedFile[1024];
- char cdataGtag[1024];
- char cdataTag[1024];
- char cdataDescription[1024];
+ QTestCharBuffer quotedFile;
+ QTestCharBuffer cdataGtag;
+ QTestCharBuffer cdataTag;
+ QTestCharBuffer cdataDescription;
- xmlQuote(quotedFile, file, sizeof(quotedFile));
- xmlCdata(cdataGtag, gtag, sizeof(cdataGtag));
- xmlCdata(cdataTag, tag, sizeof(cdataTag));
- xmlCdata(cdataDescription, message, sizeof(cdataDescription));
+ xmlQuote(quotedFile, file);
+ xmlCdata(cdataGtag, gtag);
+ xmlCdata(cdataTag, tag);
+ xmlCdata(cdataDescription, message);
- QTest::qt_snprintf(buf, sizeof(buf),
+ QTest::qt_asprintf(buf,
QTest::messageFormatString(QTest::isEmpty(message), notag),
QTest::xmlMessageType2String(type),
- quotedFile, line,
- cdataGtag,
+ quotedFile.constData(), line,
+ cdataGtag.constData(),
filler,
- cdataTag,
- cdataDescription);
+ cdataTag.constData(),
+ cdataDescription.constData());
outputString(buf);
}