diff options
Diffstat (limited to 'src/testlib')
-rw-r--r-- | src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp | 20 | ||||
-rw-r--r-- | src/testlib/qtestcase.cpp | 13 | ||||
-rw-r--r-- | src/testlib/qtestcase.qdoc | 99 | ||||
-rw-r--r-- | src/testlib/qtestsystem.h | 103 |
4 files changed, 8 insertions, 227 deletions
diff --git a/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp b/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp index 990b7a38d7..202f87af52 100644 --- a/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp +++ b/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp @@ -177,13 +177,6 @@ namespace MyNamespace { } //! [toString-overload] -//! [17] -int i = 0; -while (myNetworkServerNotResponding() && i++ < 50) - QTest::qWait(250); -//! [17] - - //! [18] MyTestObject test1; QTest::qExec(&test1); @@ -245,11 +238,6 @@ void MyTestClass::cleanup() QTest::qSleep(250); //! [23] -//! [24] -QWidget widget; -widget.show(); -QTest::qWaitForWindowShown(&widget); -//! [24] //! [25] QTouchDevice *dev = QTest::createTouchDevice(); @@ -306,13 +294,5 @@ QTest::keyClick(myWindow, Qt::Key_Escape); QTest::keyClick(myWindow, Qt::Key_Escape, Qt::ShiftModifier, 200); //! [29] -//! [30] -MyObject obj; -obj.startup(); -QTest::qWaitFor([&]() { - return obj.isReady(); -}, 3000); -//! [30] - } diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 7a74afce91..c1b4577157 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -60,6 +60,8 @@ #include <QtCore/qwaitcondition.h> #include <QtCore/qmutex.h> +#include <QtCore/qtestsupport_core.h> + #include <QtTest/private/qtestlog_p.h> #include <QtTest/private/qtesttable_p.h> #include <QtTest/qtestdata.h> @@ -2411,16 +2413,9 @@ bool QTest::currentTestFailed() */ void QTest::qSleep(int ms) { + // ### Qt 6, move to QtCore or remove altogether QTEST_ASSERT(ms > 0); - -#if defined(Q_OS_WINRT) - WaitForSingleObjectEx(GetCurrentThread(), ms, true); -#elif defined(Q_OS_WIN) - Sleep(uint(ms)); -#else - struct timespec ts = { time_t(ms / 1000), (ms % 1000) * 1000 * 1000 }; - nanosleep(&ts, NULL); -#endif + QTestPrivate::qSleep(ms); } /*! \internal diff --git a/src/testlib/qtestcase.qdoc b/src/testlib/qtestcase.qdoc index 9a3c770e31..ad9776f7ec 100644 --- a/src/testlib/qtestcase.qdoc +++ b/src/testlib/qtestcase.qdoc @@ -1112,105 +1112,6 @@ Returns a textual representation of size policy \a sp. */ -/*! \fn void QTest::qWait(int ms) - - Waits for \a ms milliseconds. While waiting, events will be processed and - your test will stay responsive to user interface events or network communication. - - Example: - \snippet code/src_qtestlib_qtestcase.cpp 17 - - The code above will wait until the network server is responding for a - maximum of about 12.5 seconds. - - \sa QTest::qSleep(), QSignalSpy::wait() -*/ - -/*! \fn template <typename Functor> bool QTest::qWaitFor(Functor predicate, int timeout) - - Waits for \a timeout milliseconds or until the \a predicate returns true. - - Returns \c true if the \a predicate returned true at any point, otherwise returns \c false. - - Example: - \snippet code/src_qtestlib_qtestcase.cpp 30 - - The code above will wait for the object to become ready, for a - maximum of three seconds. - - \since 5.10 -*/ - -/*! \fn bool QTest::qWaitForWindowExposed(QWindow *window, int timeout) - \since 5.0 - - Waits for \a timeout milliseconds or until the \a window is exposed. - Returns \c true if \c window is exposed within \a timeout milliseconds, otherwise returns \c false. - - This is mainly useful for asynchronous systems like X11, where a window will be mapped to screen some - time after being asked to show itself on the screen. - - Note that a window that is mapped to screen may still not be considered exposed if the window client - area is completely covered by other windows, or if the window is otherwise not visible. This function - will then time out when waiting for such a window. - - \sa QTest::qWaitForWindowActive(), QWindow::isExposed() -*/ - -/*! \fn bool QTest::qWaitForWindowActive(QWindow *window, int timeout) - \since 5.0 - - Waits for \a timeout milliseconds or until the \a window is active. - - Returns \c true if \c window is active within \a timeout milliseconds, otherwise returns \c false. - - \sa QTest::qWaitForWindowExposed(), QWindow::isActive() -*/ - -/*! \fn bool QTest::qWaitForWindowExposed(QWidget *widget, int timeout) - \since 5.0 - - Waits for \a timeout milliseconds or until the \a widget's window is exposed. - Returns \c true if \c widget's window is exposed within \a timeout milliseconds, otherwise returns \c false. - - This is mainly useful for asynchronous systems like X11, where a window will be mapped to screen some - time after being asked to show itself on the screen. - - Note that a window that is mapped to screen may still not be considered exposed if the window client - area is completely covered by other windows, or if the window is otherwise not visible. This function - will then time out when waiting for such a window. - - A specific configuration where this happens is when using QGLWidget as a viewport widget on macOS: - The viewport widget gets the expose event, not the parent widget. - - \sa QTest::qWaitForWindowActive() -*/ - -/*! \fn bool QTest::qWaitForWindowActive(QWidget *widget, int timeout) - \since 5.0 - - Waits for \a timeout milliseconds or until the \a widget's window is active. - - Returns \c true if \c widget's window is active within \a timeout milliseconds, otherwise returns \c false. - - \sa QTest::qWaitForWindowExposed(), QWidget::isActiveWindow() -*/ - -/*! \fn bool QTest::qWaitForWindowShown(QWidget *widget, int timeout) - \since 5.0 - \deprecated - - Waits for \a timeout milliseconds or until the \a widget's window is exposed. - Returns \c true if \c widget's window is exposed within \a timeout milliseconds, otherwise returns \c false. - - This function does the same as qWaitForWindowExposed(). - - Example: - \snippet code/src_qtestlib_qtestcase.cpp 24 - - \sa QTest::qWaitForWindowActive(), QTest::qWaitForWindowExposed() -*/ - /*! \fn QTouchDevice *QTest::createTouchDevice(QTouchDevice::DeviceType devType = QTouchDevice::TouchScreen) \since 5.8 diff --git a/src/testlib/qtestsystem.h b/src/testlib/qtestsystem.h index df62b392d4..7a73bbb5d2 100644 --- a/src/testlib/qtestsystem.h +++ b/src/testlib/qtestsystem.h @@ -41,111 +41,16 @@ #define QTESTSYSTEM_H #include <QtTest/qtestcase.h> -#include <QtCore/qcoreapplication.h> -#include <QtCore/qdeadlinetimer.h> -#ifdef QT_GUI_LIB -# include <QtGui/QWindow> -#endif -#ifdef QT_WIDGETS_LIB -# include <QtWidgets/QWidget> -#endif - -QT_BEGIN_NAMESPACE - -namespace QTest -{ - template <typename Functor> - Q_REQUIRED_RESULT static bool qWaitFor(Functor predicate, int timeout = 5000) - { - // 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; - - // qWait() is expected to spin the event loop, even when called with a small - // timeout like 1ms, so we we can't use a simple while-loop here based on - // the deadline timer not having timed out. Use do-while instead. - - int remaining = timeout; - QDeadlineTimer deadline(remaining, Qt::PreciseTimer); - - do { - QCoreApplication::processEvents(QEventLoop::AllEvents, remaining); - QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); - - remaining = deadline.remainingTime(); - if (remaining > 0) - QTest::qSleep(qMin(10, remaining)); - - if (predicate()) - return true; - - remaining = deadline.remainingTime(); - } while (remaining > 0); - - return predicate(); // Last chance - } - - 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()); - - 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); - } +#include <QtCore/qtestsupport_core.h> #ifdef QT_GUI_LIB - Q_REQUIRED_RESULT inline static bool qWaitForWindowActive(QWindow *window, int timeout = 5000) - { - return qWaitFor([&]() { return window->isActive(); }, timeout); - } - - Q_REQUIRED_RESULT inline static bool qWaitForWindowExposed(QWindow *window, int timeout = 5000) - { - return qWaitFor([&]() { return window->isExposed(); }, timeout); - } +# include <QtGui/qtestsupport_gui.h> #endif - #ifdef QT_WIDGETS_LIB - Q_REQUIRED_RESULT inline static bool qWaitForWindowActive(QWidget *widget, int timeout = 5000) - { - if (QWindow *window = widget->window()->windowHandle()) - return qWaitForWindowActive(window, timeout); - return false; - } - - Q_REQUIRED_RESULT inline static bool qWaitForWindowExposed(QWidget *widget, int timeout = 5000) - { - if (QWindow *window = widget->window()->windowHandle()) - return qWaitForWindowExposed(window, timeout); - return false; - } +# include <QtWidgets/qtestsupport_widgets.h> #endif -#if QT_DEPRECATED_SINCE(5, 0) -# ifdef QT_WIDGETS_LIB - - QT_DEPRECATED Q_REQUIRED_RESULT inline static bool qWaitForWindowShown(QWidget *widget, int timeout = 5000) - { - return qWaitForWindowExposed(widget, timeout); - } -# endif // QT_WIDGETS_LIB -#endif // QT_DEPRECATED_SINCE(5, 0) -} - +QT_BEGIN_NAMESPACE QT_END_NAMESPACE #endif |