summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
authorJason McDonald <jason.mcdonald@nokia.com>2011-10-17 18:51:44 +1000
committerQt by Nokia <qt-info@nokia.com>2011-10-19 07:23:44 +0200
commitae1810658b75dd0eb0247b0e951ce315c8ce4c86 (patch)
treecbc133fa2b3ba0e476aa375974e71f58d494a2a1 /src/testlib
parent757b0529c42690988f565ca03194900c4d1289f8 (diff)
Move QTRY_VERIFY/QTRY_COMPARE into testlib.
These functions have lived in tests/shared/util.h for a long time, but they really belong in qtestlib. Change-Id: I60d569d002dea220b51563931d8b7aa77a20b98b Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
Diffstat (limited to 'src/testlib')
-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__);\