From 4d520cd01007f0133ca197c07d9d8eb0ad2c5d82 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 28 Apr 2010 12:27:55 +0200 Subject: tst_selftests: replace a line number with __LINE__ in XML too --- tests/auto/selftests/tst_selftests.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/tests/auto/selftests/tst_selftests.cpp b/tests/auto/selftests/tst_selftests.cpp index 0ef000c..b824fd3 100644 --- a/tests/auto/selftests/tst_selftests.cpp +++ b/tests/auto/selftests/tst_selftests.cpp @@ -117,19 +117,26 @@ static QList splitLines(QByteArray ba) ba.replace('\r', ""); QList out = ba.split('\n'); - // Replace any ` file="..."' in XML with a generic location. - static const char marker[] = " file=\""; + // Replace any ` file="..."' or ` line="..."' in XML with a generic location. + static const char *markers[][2] = { + { " file=\"", " file=\"__FILE__\"" }, + { " line=\"", " line=\"__LINE__\"" } + }; + static const int markerCount = sizeof markers / sizeof markers[0]; + for (int i = 0; i < out.size(); ++i) { QByteArray& line = out[i]; - int index = line.indexOf(marker); - if (index == -1) { - continue; - } - int end = line.indexOf('"', index + sizeof(marker)); - if (end == -1) { - continue; + for (int j = 0; j < markerCount; ++j) { + int index = line.indexOf(markers[j][0]); + if (index == -1) { + continue; + } + int end = line.indexOf('"', index + strlen(markers[j][0]) + 1); + if (end == -1) { + continue; + } + line.replace(index, end-index, markers[j][1]); } - line.replace(index, end-index, " file=\"__FILE__\""); } return out; -- cgit v0.12 From 13adf589a053186e9f678c9f09b02213246e4cbe Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 28 Apr 2010 12:55:37 +0200 Subject: tst_selftest: parse benchlib results in XML format too --- tests/auto/selftests/tst_selftests.cpp | 68 +++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/tests/auto/selftests/tst_selftests.cpp b/tests/auto/selftests/tst_selftests.cpp index b824fd3..0be4e22 100644 --- a/tests/auto/selftests/tst_selftests.cpp +++ b/tests/auto/selftests/tst_selftests.cpp @@ -428,7 +428,7 @@ void tst_Selftests::doRunSubTest(QString const& subdir, QString const& logger, Q Are we expecting this line to be a benchmark result? If so, don't do a literal comparison, since results have some natural variance. */ - if (benchmark) { + if (benchmark || line.startsWith(" + if (!line.endsWith("/>")) { + if (error) *error = "unterminated XML"; + return out; + } + + QString unit = extractXmlAttribute(line, " metric=\""); + QString sTotal = extractXmlAttribute(line, " value=\""); + QString sIterations = extractXmlAttribute(line, " iterations=\""); + if (unit.isNull() || sTotal.isNull() || sIterations.isNull()) { + if (error) *error = "XML snippet did not contain all required values"; + return out; + } + + bool ok; +#if QT_VERSION >= 0x040700 + // Qt 4.7 uses floating point + double total = sTotal.toDouble(&ok); + if (!ok) { + if (error) *error = sTotal + " is not a valid number"; + return out; + } + double iterations = sIterations.toDouble(&ok); + if (!ok) { + if (error) *error = sIterations + " is not a valid number"; + return out; + } +#else + qlonglong total = sTotal.toLongLong(&ok); + if (!ok) { + if (error) *error = sTotal + " is not a valid integer"; + return out; + } + qlonglong iterations = sIterations.toLongLong(&ok); + if (!ok) { + if (error) *error = sIterations + " is not a valid integer"; + return out; + } +#endif + + out.unit = unit; + out.total = total; + out.iterations = iterations; + return out; + } + // Text result + /* This code avoids using a QRegExp because QRegExp might be broken. */ /* Sample format: 4,000 msec per iteration (total: 4000, iterations: 1) */ -- cgit v0.12