path: root/src
diff options
authorThiago Macieira <>2014-01-16 20:37:16 -0800
committerThe Qt Project <>2014-01-22 00:04:16 +0100
commit2d8028d696a86102a7753f9d59fb41f4170181a8 (patch)
tree761a4c67e915fd49d4c342cdaba2772f1097413c /src
parent57d36d3f0cbbf641bb67f7f183edcb52aa15180d (diff)
Fix the alignment for non-ASCII strings
d040681b6f3d03b349e9b9487fe89a611d03ee3c added support for aligning the test results for easier side-by-side comparison of the actual and expected values. However, it didn't take into account multibyte strings. That is, we would see: FAIL! tst_testcase::testcase: Compared values are not the same Actual (QString("é")): F0O Expected (expected) : FOO We use mbstowcs (multibyte string to wide char string) that calculates the length in wide chars of the output string. That's roughly equivalent to QString::fromLocal8Bit(string).toUcs4().size(). Change-Id: Ic2649951c50e05143da32a7fbef00a01e385c542 Reviewed-by: Jason McDonald <>
Diffstat (limited to 'src')
1 files changed, 4 insertions, 2 deletions
diff --git a/src/testlib/qtestresult.cpp b/src/testlib/qtestresult.cpp
index d94b2bf85c..a9abca0ef8 100644
--- a/src/testlib/qtestresult.cpp
+++ b/src/testlib/qtestresult.cpp
@@ -46,8 +46,10 @@
#include <QtTest/qtestdata.h>
#include <QtTest/qtestassert.h>
+#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <wchar.h>
@@ -268,8 +270,8 @@ bool QTestResult::compare(bool success, const char *failureMsg,
if (success && QTest::expectFailMode) {
qsnprintf(msg, 1024, "QCOMPARE(%s, %s) returned TRUE unexpectedly.", actual, expected);
} else if (val1 || val2) {
- size_t len1 = strlen(actual);
- size_t len2 = strlen(expected);
+ size_t len1 = mbstowcs(NULL, actual, 0);
+ size_t len2 = mbstowcs(NULL, expected, 0);
qsnprintf(msg, 1024, "%s\n Actual (%s)%*s %s\n Expected (%s)%*s %s",
actual, qMax(len1, len2) - len1 + 1, ":", val1 ? val1 : "<null>",