summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-07-21 10:55:17 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-07-22 19:32:39 +0000
commit5f5db1c38b288441d02a68f1a095850b42585e04 (patch)
tree98d6b9522ef3d9a7d11ea6940cac6119737d258b /src
parentc05f2d04f2ac359f486d2be4f0814e0f5b1d0b8f (diff)
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 <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/testlib/qtestcase.cpp44
-rw-r--r--src/testlib/qtestcase.h9
2 files changed, 51 insertions, 2 deletions
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 { \