diff -r 89e065397ea6 -r e24348a560a6 tests/auto/selftests/tst_selftests.cpp --- a/tests/auto/selftests/tst_selftests.cpp Thu May 27 13:40:48 2010 +0300 +++ b/tests/auto/selftests/tst_selftests.cpp Fri Jun 11 14:24:45 2010 +0300 @@ -117,19 +117,26 @@ 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; + 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])); + if (end == -1) { + continue; + } + line.replace(index, end-index + 1, markers[j][1]); } - int end = line.indexOf('"', index + sizeof(marker)); - if (end == -1) { - continue; - } - line.replace(index, end-index, " file=\"__FILE__\""); } return out; @@ -396,7 +403,7 @@ continue; const QString output(QString::fromLatin1(line)); - const QString expected(QString::fromLatin1(exp.at(i)).replace("", QT_VERSION_STR)); + const QString expected(QString::fromLatin1(exp.at(i)).replace("@INSERT_QT_VERSION_HERE@", QT_VERSION_STR)); if (line.contains("ASSERT") && output != expected) { QEXPECT_FAIL("assert", "QTestLib prints out the absolute path.", Continue); @@ -421,7 +428,7 @@ 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) */