diff options
author | Jason McDonald <jason.mcdonald@nokia.com> | 2012-02-29 15:43:42 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-08 05:31:40 +0100 |
commit | d81b065bb3cea85a98f2299354d05ce440032f1f (patch) | |
tree | 1b6a25357b1f11fd3088357697adcbc18f5ddc30 /src/testlib/qtestcase.cpp | |
parent | 0eb95222acbd73713a934f0e1d2b291e858ec471 (diff) |
testlib: Improve verbose and XPASS output
Previously, verbose (-v2) and XPASS test output showed all QCOMPAREs as
"COMPARE()", making it impossible to see what was compared and difficult
to match the output to the source of a test containing many calls to
QCOMPARE.
This commit changes testlib's internal compare_helper API so that string
representations of the compared expressions are always passed to
QTestResult::compare() when available, and can thus be shown in the
verbose and XPASS output. The XPASS output has also been changed to
state explicitly that the comparison succeeded unexpectedly, bringing it
in line with the XPASS output resulting from a call to QVERIFY.
This commit also changes all calls to compare_helper() to call the
eight-argument version of the function, which simplifies much of the
calling code. The now obsolete four-argument version of
compare_helper() has been changed to output a warning that it is
obsolete. It will be removed once other modules have had some time to
catch up.
The improved XPASS and verbose output is demonstrated by the expectfail
and verbose2 selftests.
Change-Id: I8baa46d5dd30e6c43b26f366c34dc5b64aab5f7c
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r-- | src/testlib/qtestcase.cpp | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index ace080ef94..001a14a121 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -2412,15 +2412,34 @@ QObject *QTest::testObject() */ bool QTest::compare_helper(bool success, const char *msg, const char *file, int line) { + static bool warned = false; + if (!warned) { + warned = true; + QTest::qWarn("QTest::compare_helper(bool, const char *, const char *, int) is obsolete " + "and will soon be removed. Please update your code to use the other " + "version of this function."); + } + return QTestResult::compare(success, msg, file, line); } /*! \internal + This function is called by various specializations of QTest::qCompare + to decide whether to report a failure and to produce verbose test output. + + The failureMsg parameter can be null, in which case a default message + will be output if the compare fails. If the compare succeeds, failureMsg + will not be output. + + If the caller has already passed a failure message showing the compared + values, or if those values cannot be stringified, val1 and val2 can be null. */ -bool QTest::compare_helper(bool success, const char *msg, char *val1, char *val2, - const char *actual, const char *expected, const char *file, int line) +bool QTest::compare_helper(bool success, const char *failureMsg, + char *val1, char *val2, + const char *actual, const char *expected, + const char *file, int line) { - return QTestResult::compare(success, msg, val1, val2, actual, expected, file, line); + return QTestResult::compare(success, failureMsg, val1, val2, actual, expected, file, line); } /*! \fn bool QTest::qCompare<float>(float const &t1, float const &t2, const char *actual, const char *expected, const char *file, int line) @@ -2430,10 +2449,8 @@ template <> Q_TESTLIB_EXPORT bool QTest::qCompare<float>(float const &t1, float const &t2, const char *actual, const char *expected, const char *file, int line) { - return qFuzzyCompare(t1, t2) - ? compare_helper(true, "COMPARE()", file, line) - : compare_helper(false, "Compared floats are not the same (fuzzy compare)", - toString(t1), toString(t2), actual, expected, file, line); + return compare_helper(qFuzzyCompare(t1, t2), "Compared floats are not the same (fuzzy compare)", + toString(t1), toString(t2), actual, expected, file, line); } /*! \fn bool QTest::qCompare<double>(double const &t1, double const &t2, const char *actual, const char *expected, const char *file, int line) @@ -2443,10 +2460,8 @@ template <> Q_TESTLIB_EXPORT bool QTest::qCompare<double>(double const &t1, double const &t2, const char *actual, const char *expected, const char *file, int line) { - return qFuzzyCompare(t1, t2) - ? compare_helper(true, "COMPARE()", file, line) - : compare_helper(false, "Compared doubles are not the same (fuzzy compare)", - toString(t1), toString(t2), actual, expected, file, line); + return compare_helper(qFuzzyCompare(t1, t2), "Compared doubles are not the same (fuzzy compare)", + toString(t1), toString(t2), actual, expected, file, line); } #define TO_STRING_IMPL(TYPE, FORMAT) \ @@ -2499,10 +2514,8 @@ char *QTest::toString(const void *p) bool QTest::compare_string_helper(const char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line) { - return (qstrcmp(t1, t2) == 0) - ? compare_helper(true, "COMPARE()", file, line) - : compare_helper(false, "Compared strings are not the same", - toString(t1), toString(t2), actual, expected, file, line); + return compare_helper(qstrcmp(t1, t2) == 0, "Compared strings are not the same", + toString(t1), toString(t2), actual, expected, file, line); } /*! \fn bool QTest::compare_ptr_helper(const void *t1, const void *t2, const char *actual, const char *expected, const char *file, int line); |