summaryrefslogtreecommitdiffstats
path: root/tests/auto/selftests/tst_selftests.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2010-04-29 07:54:44 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2010-04-29 07:54:44 (GMT)
commitdcaad8949ea1c1782d27b038f08e9a728c8e3fe5 (patch)
tree3cb49a22f79c5952de4e913146659990d614cd64 /tests/auto/selftests/tst_selftests.cpp
parent917e4e3284a568eecfca26365cc0a545d0f4eb70 (diff)
parent6940070adb45d67a0a9186205a4914a0a6c14135 (diff)
downloadQt-dcaad8949ea1c1782d27b038f08e9a728c8e3fe5.zip
Qt-dcaad8949ea1c1782d27b038f08e9a728c8e3fe5.tar.gz
Qt-dcaad8949ea1c1782d27b038f08e9a728c8e3fe5.tar.bz2
Merge remote branch 'origin/4.6' into qt-4.7-from-4.6
All EGL-related changes from 4.6 were discarded. Conflicts: src/gui/egl/egl.pri src/gui/egl/qegl.cpp src/gui/egl/qegl_p.h src/gui/egl/qegl_stub.cpp src/gui/egl/qeglproperties_p.h src/gui/egl/qeglproperties_stub.cpp src/gui/gui.pro src/multimedia/multimedia/audio/qaudioinput_win32_p.h src/s60installs/bwins/QtGuiu.def src/s60installs/eabi/QtGuiu.def
Diffstat (limited to 'tests/auto/selftests/tst_selftests.cpp')
-rw-r--r--tests/auto/selftests/tst_selftests.cpp97
1 files changed, 85 insertions, 12 deletions
diff --git a/tests/auto/selftests/tst_selftests.cpp b/tests/auto/selftests/tst_selftests.cpp
index cc73d21..0cff2fd 100644
--- a/tests/auto/selftests/tst_selftests.cpp
+++ b/tests/auto/selftests/tst_selftests.cpp
@@ -117,19 +117,26 @@ static QList<QByteArray> splitLines(QByteArray ba)
ba.replace('\r', "");
QList<QByteArray> 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;
@@ -396,7 +403,7 @@ void tst_Selftests::doRunSubTest(QString const& subdir, QString const& logger, Q
continue;
const QString output(QString::fromLatin1(line));
- const QString expected(QString::fromLatin1(exp.at(i)).replace("<INSERT_QT_VERSION_HERE>", 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 @@ 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("<BenchmarkResult")) {
QString error;
BenchmarkResult actualResult = BenchmarkResult::parse(output, &error);
@@ -451,6 +458,22 @@ void tst_Selftests::runSubTest()
doRunSubTest(subdir, logger, arguments);
}
+// attribute must contain ="
+QString extractXmlAttribute(const QString &line, const char *attribute)
+{
+ int index = line.indexOf(attribute);
+ if (index == -1)
+ return QString();
+ int end = line.indexOf('"', index + strlen(attribute));
+ if (end == -1)
+ return QString();
+
+ QString result = line.mid(index + strlen(attribute), end - index - strlen(attribute));
+ if (result.isEmpty())
+ return ""; // ensure empty but not null
+ return result;
+}
+
/* Parse line into the BenchmarkResult it represents. */
BenchmarkResult BenchmarkResult::parse(QString const& line, QString* error)
{
@@ -464,6 +487,56 @@ BenchmarkResult BenchmarkResult::parse(QString const& line, QString* error)
return out;
}
+ if (line.startsWith("<BenchmarkResult ")) {
+ // XML result
+ // format:
+ // <BenchmarkResult metric="$unit" tag="$tag" value="$total" iterations="$iterations" />
+ 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: 4,000, iterations: 1) */