diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2020-09-08 12:10:27 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2020-09-14 09:47:50 +0200 |
commit | 6b43b665a8f359f2310851de2e9560091e9726db (patch) | |
tree | 768d92311c1d56d4f44ff0b1eba6842f7098a12a | |
parent | e926e68f50c9140b373a37f4babca601961c39cb (diff) |
Make QTRY_IMPL() exit its loop if the test fails
Some tests, particularly the asynchronous ones that depend on the
QTRY_*() macros, have call-backs in which a test can fail, but the
macro used to test for failure only returns from the call-back, so the
test doesn't know to fail.
Make sure the QTRY_*() macro gives up if that happens, so that the
test function at least gets control back and can notice that it's
failed. Even if they don't check, they'll fail sooner, where they
might otherwise have been stuck in a loop that would never exit until
the watchdog timer shoots the test down (and Coin ends up with a
debugger back-trace and no output from later tests).
Change-Id: I622a53117de5e97d23dd22e04e5cd20361a54651
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r-- | src/testlib/qtestcase.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index e6a2b01c95..d7c9d43581 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -129,7 +129,7 @@ do {\ #endif // !QT_NO_EXCEPTIONS - +// NB: not do {...} while (0) wrapped, as qt_test_i is accessed after it #define QTRY_LOOP_IMPL(expr, timeoutValue, step) \ if (!(expr)) { \ QTest::qWait(0); \ @@ -154,8 +154,8 @@ do {\ #define QTRY_IMPL(expr, timeout)\ const int qt_test_step = timeout < 350 ? timeout / 7 + 1 : 50; \ const int qt_test_timeoutValue = timeout; \ - { QTRY_LOOP_IMPL((expr), qt_test_timeoutValue, qt_test_step); } \ - QTRY_TIMEOUT_DEBUG_IMPL((expr), qt_test_timeoutValue, qt_test_step)\ + { QTRY_LOOP_IMPL(QTest::currentTestFailed() || (expr), qt_test_timeoutValue, qt_test_step); } \ + QTRY_TIMEOUT_DEBUG_IMPL(QTest::currentTestFailed() || (expr), qt_test_timeoutValue, qt_test_step) // Will try to wait for the expression to become true while allowing event processing #define QTRY_VERIFY_WITH_TIMEOUT(expr, timeout) \ |