From e01b1634048ebf5858b77f2a6541a960babe232c Mon Sep 17 00:00:00 2001 From: David Faure Date: Sat, 19 Jan 2013 11:52:03 +0100 Subject: QTestLib: improve output when comparing lists fails. Only QStringList was handled before, now any QList is handled. A specialization for QStringList is still needed though, due to the way template matching works. Example with QList. Before: FAIL! : tst_QTextCodec::threadSafety() Compared values are not the same Loc: [../tst_qtextcodec.cpp(2057)] After: FAIL! : tst_QTextCodec::threadSafety() Compared lists differ at index 0. Actual (res2.toList()): '0' Expected (mibList): '3' Loc: [../tst_qtextcodec.cpp(2057)] Change-Id: If0fdec3236ddb78a679ee549aba569ef5571c395 Reviewed-by: Jason McDonald Reviewed-by: Friedemann Kleint --- src/testlib/qtest.h | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/testlib/qtest.h') diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h index a38b65671b..4b4ca191fc 100644 --- a/src/testlib/qtest.h +++ b/src/testlib/qtest.h @@ -186,9 +186,9 @@ inline bool qCompare(QLatin1String const &t1, QString const &t2, const char *act return qCompare(QString(t1), t2, actual, expected, file, line); } -template<> -inline bool qCompare(QStringList const &t1, QStringList const &t2, - const char *actual, const char *expected, const char *file, int line) +template +inline bool qCompare(QList const &t1, QList const &t2, const char *actual, const char *expected, + const char *file, int line) { char msg[1024]; msg[0] = '\0'; @@ -196,23 +196,30 @@ inline bool qCompare(QStringList const &t1, QStringList const &t2, const int actualSize = t1.count(); const int expectedSize = t2.count(); if (actualSize != expectedSize) { - qsnprintf(msg, sizeof(msg), "Compared QStringLists have different sizes.\n" + qsnprintf(msg, sizeof(msg), "Compared lists have different sizes.\n" " Actual (%s) size: '%d'\n" " Expected (%s) size: '%d'", actual, actualSize, expected, expectedSize); isOk = false; } for (int i = 0; isOk && i < actualSize; ++i) { - if (t1.at(i) != t2.at(i)) { - qsnprintf(msg, sizeof(msg), "Compared QStringLists differ at index %d.\n" + if (!(t1.at(i) == t2.at(i))) { + qsnprintf(msg, sizeof(msg), "Compared lists differ at index %d.\n" " Actual (%s): '%s'\n" - " Expected (%s): '%s'", i, actual, t1.at(i).toLatin1().constData(), - expected, t2.at(i).toLatin1().constData()); + " Expected (%s): '%s'", i, actual, toString(t1.at(i)), + expected, toString(t2.at(i))); isOk = false; } } return compare_helper(isOk, msg, 0, 0, actual, expected, file, line); } +template <> +inline bool qCompare(QStringList const &t1, QStringList const &t2, const char *actual, const char *expected, + const char *file, int line) +{ + return qCompare(t1, t2, actual, expected, file, line); +} + template inline bool qCompare(QFlags const &t1, T const &t2, const char *actual, const char *expected, const char *file, int line) -- cgit v1.2.3