From 218f0ca3b08674f7c0ce88123341955940eaf117 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 16 Sep 2011 14:42:51 +1000 Subject: Improve compliance with Qt coding guidelines * Use C++ comment delimiters consistently * Use a space after control flow keywords * Don't nest "else if" blocks unnecessarily * Follow indenting rules * Added comments describing some internal functions Change-Id: I72fd1eaf5c5f3130945fbd2b64fa59e19ad2913d Reviewed-on: http://codereview.qt-project.org/5049 Reviewed-by: Rohan McGovern --- tests/auto/testlib/selftests/tst_selftests.cpp | 108 +++++++++++-------------- 1 file changed, 48 insertions(+), 60 deletions(-) (limited to 'tests/auto/testlib/selftests') diff --git a/tests/auto/testlib/selftests/tst_selftests.cpp b/tests/auto/testlib/selftests/tst_selftests.cpp index 138e47927f..e0642627a3 100644 --- a/tests/auto/testlib/selftests/tst_selftests.cpp +++ b/tests/auto/testlib/selftests/tst_selftests.cpp @@ -39,7 +39,6 @@ ** ****************************************************************************/ - #include #include #include @@ -79,14 +78,12 @@ inline bool qCompare { // First make sure the iterations and unit match. if (r1.iterations != r2.iterations || r1.unit != r2.unit) { - /* Nope - compare whole string for best failure message */ + // Nope - compare whole string for best failure message return qCompare(r1.toString(), r2.toString(), actual, expected, file, line); } - /* - Now check the value. Some variance is allowed, and how much depends on the - measured unit. - */ + // Now check the value. Some variance is allowed, and how much depends on + // the measured unit. qreal variance = 0.; if (r1.unit == "msec") { variance = 0.1; @@ -98,7 +95,7 @@ inline bool qCompare variance = 0.001; } if (variance == 0.) { - /* No variance allowed - compare whole string */ + // No variance allowed - compare whole string return qCompare(r1.toString(), r2.toString(), actual, expected, file, line); } @@ -106,12 +103,15 @@ inline bool qCompare return compare_helper(true, "COMPARE()", file, line); } - /* Whoops, didn't match. Compare the whole string for the most useful failure message. */ + // Whoops, didn't match. Compare the whole string for the most useful failure message. return qCompare(r1.toString(), r2.toString(), actual, expected, file, line); } } QT_END_NAMESPACE +// Split the passed block of text into an array of lines, replacing any +// filenames and line numbers with generic markers to avoid failing the test +// due to compiler-specific behaviour. static QList splitLines(QByteArray ba) { ba.replace('\r', ""); @@ -142,6 +142,9 @@ static QList splitLines(QByteArray ba) return out; } +// Load the expected test output for the nominated test (subdir) and logger +// as an array of lines. If there is no expected output file, return an +// empty array. static QList expectedResult(const QString &subdir, const QString &logger) { QString suffix = logger; @@ -329,8 +332,7 @@ void tst_Selftests::doRunSubTest(QString const& subdir, QString const& logger, Q QByteArray out; if (logfile.isEmpty()) { out = proc.readAllStandardOutput(); - } - else { + } else { QFile file(logfile); if (file.open(QIODevice::ReadOnly)) out = file.readAll(); @@ -338,18 +340,16 @@ void tst_Selftests::doRunSubTest(QString const& subdir, QString const& logger, Q const QByteArray err(proc.readAllStandardError()); - /* - Some tests may output unpredictable strings to stderr, which we'll ignore. - - For instance, uncaught exceptions on Windows might say (depending on Windows - version and JIT debugger settings): - "This application has requested the Runtime to terminate it in an unusual way. - Please contact the application's support team for more information." - - Also, tests which use valgrind may generate warnings if the toolchain is - newer than the valgrind version, such that valgrind can't understand the - debug information on the binary. - */ + // Some tests may output unpredictable strings to stderr, which we'll ignore. + // + // For instance, uncaught exceptions on Windows might say (depending on Windows + // version and JIT debugger settings): + // "This application has requested the Runtime to terminate it in an unusual way. + // Please contact the application's support team for more information." + // + // Also, tests which use valgrind may generate warnings if the toolchain is + // newer than the valgrind version, such that valgrind can't understand the + // debug information on the binary. if (subdir != QLatin1String("exceptionthrow") && subdir != QLatin1String("fetchbogus") && subdir != QLatin1String("xunit") @@ -365,8 +365,8 @@ void tst_Selftests::doRunSubTest(QString const& subdir, QString const& logger, Q do { exp = expectedResult(subdir + QString("_%1").arg(i++), logger); if (exp.count()) - expArr += exp; - } while(exp.count()); + expArr += exp; + } while (exp.count()); for (int j = 0; j < expArr.count(); ++j) { if (res.count() == expArr.at(j).count()) { @@ -426,36 +426,26 @@ void tst_Selftests::doRunSubTest(QString const& subdir, QString const& logger, Q QEXPECT_FAIL("assert xunitxml", msg, Continue); } - /* On some platforms we compile without RTTI, and as a result we never throw an exception. */ - if(expected.startsWith(QLatin1String("FAIL! : tst_Exception::throwException() Caught unhandled exce")) && expected != output) + if (expected.startsWith(QLatin1String("FAIL! : tst_Exception::throwException() Caught unhandled exce")) && expected != output) + // On some platforms we compile without RTTI, and as a result we never throw an exception. QCOMPARE(output.simplified(), QString::fromLatin1("tst_Exception::throwException()").simplified()); - else - { - if(output != expected && qstrcmp(QTest::currentDataTag(), "subtest") == 0) - { - /* The floating point formatting differs between platforms, so let's just skip it. */ + else if (output != expected && qstrcmp(QTest::currentDataTag(), "subtest") == 0) + // The floating point formatting differs between platforms, so let's just skip it. continue; - } - else { - /* - 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 || line.startsWith(" 4000 */ + // 4,000 -> 4000 sFirstNumber.remove(','); - /* Should now be parseable as floating point */ + // Should now be parseable as floating point bool ok; double firstNumber = sFirstNumber.toDouble(&ok); if (!ok) { @@ -558,7 +546,7 @@ BenchmarkResult BenchmarkResult::parse(QString const& line, QString* error) return out; } - /* Remaining: msec per iteration (total: 4000, iterations: 1) */ + // Remaining: msec per iteration (total: 4000, iterations: 1) static const char periterbit[] = " per iteration (total: "; QString unit; while (!remaining.startsWith(periterbit) && !remaining.isEmpty()) { @@ -572,7 +560,7 @@ BenchmarkResult BenchmarkResult::parse(QString const& line, QString* error) remaining = remaining.mid(sizeof(periterbit)-1); - /* Remaining: 4,000, iterations: 1) */ + // Remaining: 4,000, iterations: 1) static const char itersbit[] = ", iterations: "; QString sTotal; while (!remaining.startsWith(itersbit) && !remaining.isEmpty()) { @@ -586,7 +574,7 @@ BenchmarkResult BenchmarkResult::parse(QString const& line, QString* error) remaining = remaining.mid(sizeof(itersbit)-1); - /* 4,000 -> 4000 */ + // 4,000 -> 4000 sTotal.remove(','); double total = sTotal.toDouble(&ok); @@ -595,7 +583,7 @@ BenchmarkResult BenchmarkResult::parse(QString const& line, QString* error) return out; } - /* Remaining: 1) */ + // Remaining: 1) QString sIters; while (remaining != QLatin1String(")") && !remaining.isEmpty()) { sIters += remaining.at(0); -- cgit v1.2.3