diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-01-18 15:14:45 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-01-25 16:40:57 +0000 |
commit | 374a173d1417a9f8c313088420cb1b792fe45977 (patch) | |
tree | 5c26669f1acdac1ed2ee72ef0e7dc114f5f8219d /src/testlib | |
parent | d3671555cc013df266a33a256100610d30681dfd (diff) |
Improve QTest::qWait() precision and switch to QDeadlineTimer
Do not wait up to the timeout ms after already having waited several
times. At the same time upgrade to using the QDeadlineTimer which
is designed for this purpose.
Change-Id: Iaf5e4f4655605d5143ce91040c6eb6706752e504
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/testlib')
-rw-r--r-- | src/testlib/qtestsystem.h | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/testlib/qtestsystem.h b/src/testlib/qtestsystem.h index 4973412f9b..b38cd2bdb4 100644 --- a/src/testlib/qtestsystem.h +++ b/src/testlib/qtestsystem.h @@ -42,7 +42,7 @@ #include <QtTest/qtestcase.h> #include <QtCore/qcoreapplication.h> -#include <QtCore/qelapsedtimer.h> +#include <QtCore/qdeadlinetimer.h> #ifdef QT_GUI_LIB # include <QtGui/QWindow> #endif @@ -58,27 +58,29 @@ namespace QTest { Q_ASSERT(QCoreApplication::instance()); - QElapsedTimer timer; - timer.start(); + QDeadlineTimer timer(ms); + int remaining = ms; do { - QCoreApplication::processEvents(QEventLoop::AllEvents, ms); + QCoreApplication::processEvents(QEventLoop::AllEvents, remaining); QCoreApplication::sendPostedEvents(Q_NULLPTR, QEvent::DeferredDelete); - QTest::qSleep(10); - } while (timer.elapsed() < ms); + remaining = timer.remainingTime(); + if (remaining <= 0) + break; + QTest::qSleep(qMin(10, remaining)); + remaining = timer.remainingTime(); + } while (remaining > 0); } #ifdef QT_GUI_LIB inline static bool qWaitForWindowActive(QWindow *window, int timeout = 5000) { - QElapsedTimer timer; - timer.start(); - while (!window->isActive()) { - int remaining = timeout - int(timer.elapsed()); - if (remaining <= 0) - break; + QDeadlineTimer timer(timeout); + int remaining = timeout; + while (!window->isActive() && remaining > 0) { QCoreApplication::processEvents(QEventLoop::AllEvents, remaining); QCoreApplication::sendPostedEvents(Q_NULLPTR, QEvent::DeferredDelete); QTest::qSleep(10); + remaining = timer.remainingTime(); } // Try ensuring the platform window receives the real position. // (i.e. that window->pos() reflects reality) @@ -99,15 +101,13 @@ namespace QTest inline static bool qWaitForWindowExposed(QWindow *window, int timeout = 5000) { - QElapsedTimer timer; - timer.start(); - while (!window->isExposed()) { - int remaining = timeout - int(timer.elapsed()); - if (remaining <= 0) - break; + QDeadlineTimer timer(timeout); + int remaining = timeout; + while (!window->isExposed() && remaining > 0) { QCoreApplication::processEvents(QEventLoop::AllEvents, remaining); QCoreApplication::sendPostedEvents(Q_NULLPTR, QEvent::DeferredDelete); QTest::qSleep(10); + remaining = timer.remainingTime(); } return window->isExposed(); } |