summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/testlib/qtestcase.cpp40
-rw-r--r--src/testlib/qtestcase.h28
2 files changed, 66 insertions, 2 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index c579e0f11f..451fa5b761 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -109,7 +109,7 @@ QT_BEGIN_NAMESPACE
Example:
\snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 0
- \sa QCOMPARE()
+ \sa QCOMPARE(), QTRY_VERIFY()
*/
/*! \macro QVERIFY2(condition, message)
@@ -159,7 +159,43 @@ QT_BEGIN_NAMESPACE
Example:
\snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 2
- \sa QVERIFY(), QTest::toString()
+ \sa QVERIFY(), QTRY_COMPARE(), QTest::toString()
+*/
+
+/*! \macro QTRY_VERIFY(condition)
+
+ \relates QTest
+
+ The QTRY_VERIFY() macro is similar to QVERIFY(), but checks the \a condition
+ repeatedly, until either the condition becomes true or a maximum timeout is
+ reached. Between each evaluation, events will be processed. If the timeout
+ is reached, a failure is recorded in the test log and the test won't be
+ executed further.
+
+ The timeout is fixed at five seconds.
+
+ \note This macro can only be used in a test function that is invoked
+ by the test framework.
+
+ \sa QVERIFY(), QCOMPARE(), QTRY_COMPARE()
+*/
+
+/*! \macro QTRY_COMPARE(actual, expected)
+
+ \relates QTest
+
+ The QTRY_COMPARE() macro is similar to QCOMPARE(), but performs the comparison
+ of the \a actual and \a expected values repeatedly, until either the two values
+ are equal or a maximum timeout is reached. Between each comparison, events
+ will be processed. If the timeout is reached, a failure is recorded in the
+ test log and the test won't be executed further.
+
+ The timeout is fixed at five seconds.
+
+ \note This macro can only be used in a test function that is invoked
+ by the test framework.
+
+ \sa QCOMPARE(), QVERIFY(), QTRY_VERIFY()
*/
/*! \macro QFETCH(type, name)
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h
index b3ac5f0c4f..642be0bc96 100644
--- a/src/testlib/qtestcase.h
+++ b/src/testlib/qtestcase.h
@@ -82,6 +82,34 @@ do {\
return;\
} while (0)
+// Will try to wait for the expression to become true while allowing event processing
+#define QTRY_VERIFY(__expr) \
+do { \
+ const int __step = 50; \
+ const int __timeout = 5000; \
+ if (!(__expr)) { \
+ QTest::qWait(0); \
+ } \
+ for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \
+ QTest::qWait(__step); \
+ } \
+ QVERIFY(__expr); \
+} while (0)
+
+// Will try to wait for the comparison to become successful while allowing event processing
+#define QTRY_COMPARE(__expr, __expected) \
+do { \
+ const int __step = 50; \
+ const int __timeout = 5000; \
+ if ((__expr) != (__expected)) { \
+ QTest::qWait(0); \
+ } \
+ for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \
+ QTest::qWait(__step); \
+ } \
+ QCOMPARE(__expr, __expected); \
+} while (0)
+
#define QSKIP(statement, mode) \
do {\
QTest::qSkip(statement, QTest::mode, __FILE__, __LINE__);\