Fix the alignment for non-ASCII strings
d040681b6f 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 <macadder1@gmail.com>
bb10
parent
57d36d3f0c
commit
2d8028d696
|
|
@ -46,8 +46,10 @@
|
|||
#include <QtTest/qtestdata.h>
|
||||
#include <QtTest/qtestassert.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -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",
|
||||
failureMsg,
|
||||
actual, qMax(len1, len2) - len1 + 1, ":", val1 ? val1 : "<null>",
|
||||
|
|
|
|||
Loading…
Reference in New Issue