From 5f5db1c38b288441d02a68f1a095850b42585e04 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 21 Jul 2015 10:55:17 +0200 Subject: QTestLib: Add macros QTRY_VERIFY2_WITH_TIMEOUT(), QTRY_VERIFY2(). Add QTRY_VERIFY2_WITH_TIMEOUT() similar to QTRY_VERIFY_WITH_TIMEOUT() except that QTRY_VERIFY2() is used below the loop and QTRY_VERIFY2() based on it. Add tests to cmptest. [ChangeLog][QtTest] Added macros QTRY_VERIFY2_WITH_TIMEOUT(), QTRY_VERIFY2() making it possible to output a message after the timeout has expired. Change-Id: I587e24f3aeb73542dbf3ccb936a16f2e0806555f Reviewed-by: Mitch Curtis --- src/testlib/qtestcase.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++-- src/testlib/qtestcase.h | 9 +++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index fd9d08b267..ae83432eb8 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -247,7 +247,7 @@ static void stackTrace() \note This macro can only be used in a test function that is invoked by the test framework. - \sa QTRY_VERIFY(), QVERIFY(), QCOMPARE(), QTRY_COMPARE() + \sa QTRY_VERIFY(), QTRY_VERIFY2_WITH_TIMEOUT(), QVERIFY(), QCOMPARE(), QTRY_COMPARE() */ @@ -261,7 +261,47 @@ static void stackTrace() \note This macro can only be used in a test function that is invoked by the test framework. - \sa QTRY_VERIFY_WITH_TIMEOUT(), QVERIFY(), QCOMPARE(), QTRY_COMPARE() + \sa QTRY_VERIFY_WITH_TIMEOUT(), QTRY_VERIFY2(), QVERIFY(), QCOMPARE(), QTRY_COMPARE() +*/ + +/*! \macro QTRY_VERIFY2_WITH_TIMEOUT(condition, message, timeout) + \since 5.6 + + \relates QTest + + The QTRY_VERIFY2_WITH_TIMEOUT macro is similar to QTRY_VERIFY_WITH_TIMEOUT() + except that it outputs a verbose \a message when \a condition is still false + after the specified timeout. The \a message is a plain C string. + + Example: + \code + QTRY_VERIFY2_WITH_TIMEOUT(list.size() > 2, QByteArray::number(list.size()).constData(), 10000); + \endcode + + \note This macro can only be used in a test function that is invoked + by the test framework. + + \sa QTRY_VERIFY(), QTRY_VERIFY_WITH_TIMEOUT(), QVERIFY(), QCOMPARE(), QTRY_COMPARE() +*/ + +/*! \macro QTRY_VERIFY2(condition, message) + \since 5.6 + + \relates QTest + + Checks the \a condition by invoking QTRY_VERIFY2_WITH_TIMEOUT() with a timeout + of five seconds. If \a condition is then still false, \a message is output. + The \a message is a plain C string. + + Example: + \code + QTRY_VERIFY2_WITH_TIMEOUT(list.size() > 2, QByteArray::number(list.size()).constData()); + \endcode + + \note This macro can only be used in a test function that is invoked + by the test framework. + + \sa QTRY_VERIFY2_WITH_TIMEOUT(), QTRY_VERIFY2(), QVERIFY(), QCOMPARE(), QTRY_COMPARE() */ /*! \macro QTRY_COMPARE_WITH_TIMEOUT(actual, expected, timeout) diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index 9f3c461cf0..7d2fd2e701 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -158,6 +158,15 @@ do { \ #define QTRY_VERIFY(__expr) QTRY_VERIFY_WITH_TIMEOUT((__expr), 5000) +// Will try to wait for the expression to become true while allowing event processing +#define QTRY_VERIFY2_WITH_TIMEOUT(__expr, __messageExpression, __timeout) \ +do { \ + QTRY_IMPL((__expr), __timeout);\ + QVERIFY2(__expr, __messageExpression); \ +} while (0) + +#define QTRY_VERIFY2(__expr, __messageExpression) QTRY_VERIFY2_WITH_TIMEOUT((__expr), (__messageExpression), 5000) + // Will try to wait for the comparison to become successful while allowing event processing #define QTRY_COMPARE_WITH_TIMEOUT(__expr, __expected, __timeout) \ do { \ -- cgit v1.2.3