From dc5ea809634560e836d2847f42f66beb43db7924 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 10 Jan 2012 10:13:55 +0100 Subject: Tests: Remove duplicate QTRY_VERIFY/QTRY_COMPARE macros in bearer. Introduce QTRY_VERIFY_WITH_TIMEOUT and QTRY_COMPARE_WITH_TIMEOUT to be able to specify a timeout value. Reviewed-by: Jason McDonald Change-Id: Iaeaa4938eb14f2c431537055f626510cba183ce3 Reviewed-by: Friedemann Kleint --- src/testlib/qtestcase.cpp | 41 +++++++++++++++++++++++++++++++---------- src/testlib/qtestcase.h | 16 ++++++++++------ 2 files changed, 41 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index b1bceb771c..8bd836d7f9 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -160,40 +160,61 @@ QT_BEGIN_NAMESPACE \sa QVERIFY(), QTRY_COMPARE(), QTest::toString() */ -/*! \macro QTRY_VERIFY(condition) +/*! \macro QTRY_VERIFY_WITH_TIMEOUT(condition, timeout) \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 + The QTRY_VERIFY_WITH_TIMEOUT() macro is similar to QVERIFY(), but checks the \a condition + repeatedly, until either the condition becomes true or the \a 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 QTRY_VERIFY(), QVERIFY(), QCOMPARE(), QTRY_COMPARE() +*/ + + +/*! \macro QTRY_VERIFY(condition) + + \relates QTest + + Invokes QTRY_VERIFY_WITH_TIMEOUT() with a timeout of 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() + \sa QTRY_VERIFY_WITH_TIMEOUT(), QVERIFY(), QCOMPARE(), QTRY_COMPARE() */ -/*! \macro QTRY_COMPARE(actual, expected) +/*! \macro QTRY_COMPARE_WITH_TIMEOUT(actual, expected, timeout) \relates QTest - The QTRY_COMPARE() macro is similar to QCOMPARE(), but performs the comparison + The QTRY_COMPARE_WITH_TIMEOUT() 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 + are equal or the \a 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 QTRY_COMPARE(), QCOMPARE(), QVERIFY(), QTRY_VERIFY() +*/ + +/*! \macro QTRY_COMPARE(actual, expected) + + \relates QTest + + Invokes QTRY_COMPARE_WITH_TIMEOUT() with a timeout of 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() + \sa QTRY_COMPARE_WITH_TIMEOUT(), QCOMPARE(), QVERIFY(), QTRY_VERIFY() */ /*! \macro QFETCH(type, name) diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index d6409f0441..4537e76920 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -86,33 +86,37 @@ do {\ } while (0) // Will try to wait for the expression to become true while allowing event processing -#define QTRY_VERIFY(__expr) \ +#define QTRY_VERIFY_WITH_TIMEOUT(__expr, __timeout) \ do { \ const int __step = 50; \ - const int __timeout = 5000; \ + const int __timeoutValue = __timeout; \ if (!(__expr)) { \ QTest::qWait(0); \ } \ - for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \ + for (int __i = 0; __i < __timeoutValue && !(__expr); __i+=__step) { \ QTest::qWait(__step); \ } \ QVERIFY(__expr); \ } while (0) +#define QTRY_VERIFY(__expr) QTRY_VERIFY_WITH_TIMEOUT(__expr, 5000) + // Will try to wait for the comparison to become successful while allowing event processing -#define QTRY_COMPARE(__expr, __expected) \ + +#define QTRY_COMPARE_WITH_TIMEOUT(__expr, __expected, __timeout) \ do { \ const int __step = 50; \ - const int __timeout = 5000; \ + const int __timeoutValue = __timeout; \ if ((__expr) != (__expected)) { \ QTest::qWait(0); \ } \ - for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \ + for (int __i = 0; __i < __timeoutValue && ((__expr) != (__expected)); __i+=__step) { \ QTest::qWait(__step); \ } \ QCOMPARE(__expr, __expected); \ } while (0) +#define QTRY_COMPARE(__expr, __expected) QTRY_COMPARE_WITH_TIMEOUT(__expr, __expected, 5000) #ifdef Q_CC_MSVC #define QSKIP(statement) \ -- cgit v1.2.3