From c45f9c7761a9016ff20c8c427cb5c84aba56bc57 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Wed, 14 Dec 2011 16:36:10 +1000 Subject: Improve QCOMPARE for QStringList After establishing that both lists are the same size, there is no need to calculate the minimum of the list sizes. Also, use sizeof() instead of hard-coded values when calling qsnprintf(). Change-Id: I2396cf3f941770229e1cef6422aeddbe549c51fc Reviewed-by: Rohan McGovern --- src/testlib/qtest.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/testlib/qtest.h') diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h index 6bce44686d..e4b5a21a7f 100644 --- a/src/testlib/qtest.h +++ b/src/testlib/qtest.h @@ -194,16 +194,17 @@ inline bool qCompare(QStringList const &t1, QStringList const &t2, char msg[1024]; msg[0] = '\0'; bool isOk = true; - if (t1.count() != t2.count()) { - qsnprintf(msg, 1024, "Compared QStringLists have different sizes.\n" + const int actualSize = t1.count(); + const int expectedSize = t2.count(); + if (actualSize != expectedSize) { + qsnprintf(msg, sizeof(msg), "Compared QStringLists have different sizes.\n" " Actual (%s) size : '%d'\n" - " Expected (%s) size: '%d'", actual, t1.count(), expected, t2.count()); + " Expected (%s) size: '%d'", actual, actualSize, expected, expectedSize); isOk = false; } - const int min = qMin(t1.count(), t2.count()); - for (int i = 0; isOk && i < min; ++i) { + for (int i = 0; isOk && i < actualSize; ++i) { if (t1.at(i) != t2.at(i)) { - qsnprintf(msg, 1024, "Compared QStringLists differ at index %d.\n" + qsnprintf(msg, sizeof(msg), "Compared QStringLists 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()); -- cgit v1.2.3