summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
authorJason McDonald <jason.mcdonald@nokia.com>2011-12-14 16:36:10 +1000
committerQt by Nokia <qt-info@nokia.com>2011-12-15 01:57:48 +0100
commitc45f9c7761a9016ff20c8c427cb5c84aba56bc57 (patch)
tree9ee6abb95e7635d8637d49b9c430467cba42b803 /src/testlib
parentf54916697a361549256330b35029d5251d3e1407 (diff)
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 <rohan.mcgovern@nokia.com>
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/qtest.h13
1 files changed, 7 insertions, 6 deletions
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());