diff options
author | Liang Qi <liang.qi@qt.io> | 2017-10-17 10:19:31 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-10-17 10:34:24 +0200 |
commit | d0a0a3c0418a0fdd2ed84b2a5f7e6565537715c6 (patch) | |
tree | d6aeb4d51caf30ccf23eadb806a09295cbf679cd /src/testlib | |
parent | 9f405f98a4247cd263b9c5d35659a4ba89e282de (diff) | |
parent | ac35f9c44c0fb3b2f40ae5585c497200b2ba743d (diff) |
Merge remote-tracking branch 'origin/5.10' into dev
Conflicts:
examples/network/fortuneclient/client.cpp
examples/network/fortuneserver/server.cpp
src/platformsupport/platformcompositor/qopenglcompositorbackingstore_p.h
src/plugins/platforms/cocoa/qcocoabackingstore.h
src/plugins/platforms/cocoa/qcocoaintegration.h
src/plugins/platforms/cocoa/qcocoascreen.h
src/plugins/platforms/ios/qiosbackingstore.h
src/plugins/sqldrivers/oci/qsql_oci.cpp
src/widgets/kernel/qwidgetwindow.cpp
Change-Id: Ia6dd2c52d4a691b671cf9a2ffca70deccece8f10
Diffstat (limited to 'src/testlib')
-rw-r--r-- | src/testlib/qtest_network.h | 3 | ||||
-rw-r--r-- | src/testlib/qtestsystem.h | 34 |
2 files changed, 26 insertions, 11 deletions
diff --git a/src/testlib/qtest_network.h b/src/testlib/qtest_network.h index 6f6b4c1b8e..57a37734fc 100644 --- a/src/testlib/qtest_network.h +++ b/src/testlib/qtest_network.h @@ -67,7 +67,8 @@ namespace QTest /*! \internal */ -inline char *toString(const QHostAddress &addr) +template<> +inline char *toString<QHostAddress>(const QHostAddress &addr) { switch (addr.protocol()) { case QAbstractSocket::UnknownNetworkLayerProtocol: diff --git a/src/testlib/qtestsystem.h b/src/testlib/qtestsystem.h index 04c9c574f7..79fe68004e 100644 --- a/src/testlib/qtestsystem.h +++ b/src/testlib/qtestsystem.h @@ -55,9 +55,9 @@ QT_BEGIN_NAMESPACE namespace QTest { template <typename Functor> - static Q_REQUIRED_RESULT bool qWaitFor(Functor predicate, int timeout = 5000) + Q_REQUIRED_RESULT static bool qWaitFor(Functor predicate, int timeout = 5000) { - // We should not spint the event loop in case the predicate is already true, + // We should not spin the event loop in case the predicate is already true, // otherwise we might send new events that invalidate the predicate. if (predicate()) return true; @@ -90,14 +90,27 @@ namespace QTest Q_DECL_UNUSED inline static void qWait(int ms) { + // Ideally this method would be implemented in terms of qWaitFor, with + // a predicate that always returns false, but due to a compiler bug in + // GCC 6 we can't do that. + Q_ASSERT(QCoreApplication::instance()); - auto unconditionalWait = []() { return false; }; - bool timedOut = !qWaitFor(unconditionalWait, ms); - Q_UNUSED(timedOut); + + QDeadlineTimer timer(ms, Qt::PreciseTimer); + int remaining = ms; + do { + QCoreApplication::processEvents(QEventLoop::AllEvents, remaining); + QCoreApplication::sendPostedEvents(Q_NULLPTR, QEvent::DeferredDelete); + 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) + Q_REQUIRED_RESULT inline static bool qWaitForWindowActive(QWindow *window, int timeout = 5000) { bool becameActive = qWaitFor([&]() { return window->isActive(); }, timeout); @@ -118,21 +131,21 @@ namespace QTest return window->isActive(); } - inline static bool qWaitForWindowExposed(QWindow *window, int timeout = 5000) + Q_REQUIRED_RESULT inline static bool qWaitForWindowExposed(QWindow *window, int timeout = 5000) { return qWaitFor([&]() { return window->isExposed(); }, timeout); } #endif #ifdef QT_WIDGETS_LIB - inline static bool qWaitForWindowActive(QWidget *widget, int timeout = 5000) + Q_REQUIRED_RESULT inline static bool qWaitForWindowActive(QWidget *widget, int timeout = 5000) { if (QWindow *window = widget->window()->windowHandle()) return qWaitForWindowActive(window, timeout); return false; } - inline static bool qWaitForWindowExposed(QWidget *widget, int timeout = 5000) + Q_REQUIRED_RESULT inline static bool qWaitForWindowExposed(QWidget *widget, int timeout = 5000) { if (QWindow *window = widget->window()->windowHandle()) return qWaitForWindowExposed(window, timeout); @@ -142,7 +155,8 @@ namespace QTest #if QT_DEPRECATED_SINCE(5, 0) # ifdef QT_WIDGETS_LIB - QT_DEPRECATED inline static bool qWaitForWindowShown(QWidget *widget, int timeout = 5000) + + QT_DEPRECATED Q_REQUIRED_RESULT inline static bool qWaitForWindowShown(QWidget *widget, int timeout = 5000) { return qWaitForWindowExposed(widget, timeout); } |