summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qeventdispatcher
diff options
context:
space:
mode:
authorLeander Beernaert <leander.beernaert@qt.io>2020-01-22 13:47:08 +0100
committerLeander Beernaert <leander.beernaert@qt.io>2020-01-24 13:17:33 +0100
commit502d3d6744913899da87acfda5ebdab42c40329e (patch)
tree16658a328503bfd5a62b4fd5d69ffb66e9854b18 /tests/auto/corelib/kernel/qeventdispatcher
parentd1be8b9ceb2c7b20bbe53a07154c79699540ea3d (diff)
parent06bb315beb6c2c398223cfe52cbc7f66e14a8557 (diff)
Merge remote-tracking branch 'origin/dev' into merge-dev
Diffstat (limited to 'tests/auto/corelib/kernel/qeventdispatcher')
-rw-r--r--tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp
index 49c10c6a24..365508024b 100644
--- a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp
+++ b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp
@@ -67,6 +67,7 @@ private slots:
void sendPostedEvents_data();
void sendPostedEvents();
void processEventsOnlySendsQueuedEvents();
+ void eventLoopExit();
};
bool tst_QEventDispatcher::event(QEvent *e)
@@ -314,5 +315,49 @@ void tst_QEventDispatcher::processEventsOnlySendsQueuedEvents()
QCOMPARE(object.eventsReceived, 4);
}
+void tst_QEventDispatcher::eventLoopExit()
+{
+ // This test was inspired by QTBUG-79477. A particular
+ // implementation detail in QCocoaEventDispatcher allowed
+ // QEventLoop::exit() to fail to really exit the event loop.
+ // Thus this test is a part of the dispatcher auto-test.
+
+ // Imitates QApplication::exec():
+ QEventLoop mainLoop;
+ // The test itself is a lambda:
+ QTimer::singleShot(0, [&mainLoop]() {
+ // Two more single shots, both will be posted as events
+ // (zero timeout) and supposed to be processes by the
+ // mainLoop:
+
+ QTimer::singleShot(0, [&mainLoop]() {
+ // wakeUp triggers QCocoaEventDispatcher into incrementing
+ // its 'serialNumber':
+ mainLoop.wakeUp();
+ // QCocoaEventDispatcher::processEvents() will process
+ // posted events and execute the second lambda defined below:
+ QCoreApplication::processEvents();
+ });
+
+ QTimer::singleShot(0, [&mainLoop]() {
+ // With QCocoaEventDispatcher this is executed while in the
+ // processEvents (see above) and would fail to actually
+ // interrupt the loop.
+ mainLoop.exit();
+ });
+ });
+
+ bool timeoutObserved = false;
+ QTimer::singleShot(500, [&timeoutObserved, &mainLoop]() {
+ // In case the QEventLoop::exit above failed, we have to bail out
+ // early, not wasting time:
+ mainLoop.exit();
+ timeoutObserved = true;
+ });
+
+ mainLoop.exec();
+ QVERIFY(!timeoutObserved);
+}
+
QTEST_MAIN(tst_QEventDispatcher)
#include "tst_qeventdispatcher.moc"