Fix auto test failure output on QNX

On QNX mbstowcs does not ignore last parameter (max) when first (dest)
is NULL. Set it to sufficiently large value to yield proper results on
QNX. Other platforms (standard libraries) will ignore this value anyway.

Change-Id: Ie4695254d45082e151a052bf16de684af3b1ba1e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Bernd Weimer 2014-05-15 15:04:49 +02:00 committed by The Qt Project
parent 71006cf04c
commit 43d4fecde5

View File

@ -49,7 +49,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
static const char *currentAppName = 0;
@ -257,10 +256,11 @@ bool QTestResult::compare(bool success, const char *failureMsg,
QTEST_ASSERT(expected);
QTEST_ASSERT(actual);
char msg[1024];
const size_t maxMsgLen = 1024;
char msg[maxMsgLen];
if (QTestLog::verboseLevel() >= 2) {
qsnprintf(msg, 1024, "QCOMPARE(%s, %s)", actual, expected);
qsnprintf(msg, maxMsgLen, "QCOMPARE(%s, %s)", actual, expected);
QTestLog::info(msg, file, line);
}
@ -268,16 +268,17 @@ bool QTestResult::compare(bool success, const char *failureMsg,
failureMsg = "Compared values are not the same";
if (success && QTest::expectFailMode) {
qsnprintf(msg, 1024, "QCOMPARE(%s, %s) returned TRUE unexpectedly.", actual, expected);
qsnprintf(msg, maxMsgLen,
"QCOMPARE(%s, %s) returned TRUE unexpectedly.", actual, expected);
} else if (val1 || val2) {
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",
size_t len1 = mbstowcs(NULL, actual, maxMsgLen); // Last parameter is not ignored on QNX
size_t len2 = mbstowcs(NULL, expected, maxMsgLen); // (result is never larger than this).
qsnprintf(msg, maxMsgLen, "%s\n Actual (%s)%*s %s\n Expected (%s)%*s %s",
failureMsg,
actual, qMax(len1, len2) - len1 + 1, ":", val1 ? val1 : "<null>",
expected, qMax(len1, len2) - len2 + 1, ":", val2 ? val2 : "<null>");
} else
qsnprintf(msg, 1024, "%s", failureMsg);
qsnprintf(msg, maxMsgLen, "%s", failureMsg);
delete [] val1;
delete [] val2;