From 2ba4923c0591dcc3d5630a7fa9442364490c348b Mon Sep 17 00:00:00 2001 From: Till Adam Date: Sat, 21 Jan 2012 13:44:18 +0100 Subject: [PATCH] Test case for unix dispatcher event loop hang. This test case produces a failure when an attempt to exit an event loop is immediately followed by a nested call to processEvents which resets the interrupted flag that would cause the event loop to be left. This happens when the unix event dispatcher is used, such as on OSX. --- tests/auto/qeventloop/tst_qeventloop.cpp | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-) diff --git a/tests/auto/qeventloop/tst_qeventloop.cpp b/tests/auto/qeventloop/tst_qeventloop.cpp index 3250c77..1bdbf27 100644 --- a/tests/auto/qeventloop/tst_qeventloop.cpp +++ b/tests/auto/qeventloop/tst_qeventloop.cpp @@ -76,6 +76,7 @@ public slots: void exit(); void exit1(); void exit2(); + void exitAndWait(); }; void EventLoopExiter::exit() @@ -87,6 +88,15 @@ void EventLoopExiter::exit1() void EventLoopExiter::exit2() { eventLoop->exit(2); } +void EventLoopExiter::exitAndWait() +{ + eventLoop->exit(42); + // the below will result in a nested processEvents + // which will re-set the "interrupted" flag and + // thus undo the quit() before + QTest::qWait(10); +} + class EventLoopThread : public QThread { Q_OBJECT @@ -214,6 +224,7 @@ private slots: // keep this test last: void nestedLoops(); + void quitWithNestedProcessEvents(); protected: void customEvent(QEvent *e); @@ -536,6 +547,17 @@ void tst_QEventLoop::quit() QCOMPARE(returnCode, 0); } +void tst_QEventLoop::quitWithNestedProcessEvents() +{ + QEventLoop eventLoop; + EventLoopExiter exiter(&eventLoop); + int returnCode; + + QTimer::singleShot(0, &exiter, SLOT(exitAndWait())); + QTimer::singleShot(20, &eventLoop, SLOT(quit())); + returnCode = eventLoop.exec(); + QCOMPARE(returnCode, 42); +} void tst_QEventLoop::nestedLoops() { @@ -916,6 +938,5 @@ void tst_QEventLoop::deliverInDefinedOrder_QTBUG19637() } - QTEST_MAIN(tst_QEventLoop) #include "tst_qeventloop.moc" -- 1.7.7.4