testlib: Make QTestResult::verify() more robust.
authorJason McDonald <jason.mcdonald@nokia.com>
Thu, 8 Mar 2012 01:20:41 +0000 (11:20 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 8 Mar 2012 06:30:36 +0000 (07:30 +0100)
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>
src/testlib/qtestresult.cpp

index 231fc8f..cbededf 100644 (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);
 }