testlib: Make QTestResult::verify() more robust.

The statementStr parameter should always be non-null, so assert if it is
null.  The description parameter can be null in some cases (particularly
when the verify is successful, and thus no error description is going to
be displayed), so tolerate this.

Change-Id: I87b416d5f3b793bc608cd4aca14a4f7fe7527488
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
This commit is contained in:
Jason McDonald 2012-03-08 11:20:41 +10:00 committed by Qt by Nokia
parent 48209e21ec
commit d78fab531a

View File

@ -230,6 +230,8 @@ static bool checkStatement(bool statement, const char *msg, const char *file, in
bool QTestResult::verify(bool statement, const char *statementStr,
const char *description, const char *file, int line)
{
QTEST_ASSERT(statementStr);
char msg[1024];
if (QTestLog::verboseLevel() >= 2) {
@ -240,7 +242,7 @@ bool QTestResult::verify(bool statement, const char *statementStr,
const char * format = QTest::expectFailMode
? "'%s' returned TRUE unexpectedly. (%s)"
: "'%s' returned FALSE. (%s)";
qsnprintf(msg, 1024, format, statementStr, description);
qsnprintf(msg, 1024, format, statementStr, description ? description : "");
return checkStatement(statement, msg, file, line);
}