diff options
author | David Faure <david.faure@kdab.com> | 2013-01-19 11:52:03 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-22 13:29:33 +0100 |
commit | e01b1634048ebf5858b77f2a6541a960babe232c (patch) | |
tree | 92b974e06ba2b4c510c8f814d4a3e888a56aa216 /src/testlib/qtest.h | |
parent | c73dc44606bee960b734c2bc5db22c5400dadb3c (diff) |
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<int>. 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 <macadder1@gmail.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Diffstat (limited to 'src/testlib/qtest.h')
-rw-r--r-- | src/testlib/qtest.h | 23 |
1 files changed, 15 insertions, 8 deletions
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 <typename T> +inline bool qCompare(QList<T> const &t1, QList<T> 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<QString>(t1, t2, actual, expected, file, line); +} + template <typename T> inline bool qCompare(QFlags<T> const &t1, T const &t2, const char *actual, const char *expected, const char *file, int line) |