diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2009-09-03 06:17:05 (GMT) |
---|---|---|
committer | Bradley T. Hughes <bradley.hughes@nokia.com> | 2009-09-04 14:22:16 (GMT) |
commit | 5323b15f50df99722d304c04d1758bb9410ef041 (patch) | |
tree | 5f074722a95e5fe968536326d6719d81455bc226 /tests | |
parent | 1a60fb9506519210edcbfb3fbc400a67a6d26a41 (diff) | |
download | Qt-5323b15f50df99722d304c04d1758bb9410ef041.zip Qt-5323b15f50df99722d304c04d1758bb9410ef041.tar.gz Qt-5323b15f50df99722d304c04d1758bb9410ef041.tar.bz2 |
Fix tst_QTimer::moveToThread() on Windows
We shouldn't fully unregister timers when the event dispatcher is stopped
when a thread exits, since this releases the timerId back to the pool.
Instead, only free the OS resources.
Auto-test included.
Reviewed-by: ogoffart
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qtimer/tst_qtimer.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/auto/qtimer/tst_qtimer.cpp b/tests/auto/qtimer/tst_qtimer.cpp index 57502c7..36fce76 100644 --- a/tests/auto/qtimer/tst_qtimer.cpp +++ b/tests/auto/qtimer/tst_qtimer.cpp @@ -87,6 +87,7 @@ private slots: void restartedTimerFiresTooSoon(); void timerFiresOnlyOncePerProcessEvents_data(); void timerFiresOnlyOncePerProcessEvents(); + void timerIdPersistsAfterThreadExit(); }; class TimerHelper : public QObject @@ -562,5 +563,44 @@ void tst_QTimer::timerFiresOnlyOncePerProcessEvents() QCOMPARE(longSlot.count, 1); } +class TimerIdPersistsAfterThreadExitThread : public QThread +{ +public: + QTimer *timer; + int timerId, returnValue; + + TimerIdPersistsAfterThreadExitThread() + : QThread(), timer(0), timerId(-1), returnValue(-1) + { } + ~TimerIdPersistsAfterThreadExitThread() + { + delete timer; + } + + void run() + { + QEventLoop eventLoop; + timer = new QTimer; + connect(timer, SIGNAL(timeout()), &eventLoop, SLOT(quit())); + timer->start(100); + timerId = timer->timerId(); + returnValue = eventLoop.exec(); + } +}; + +void tst_QTimer::timerIdPersistsAfterThreadExit() +{ + TimerIdPersistsAfterThreadExitThread thread; + thread.start(); + QVERIFY(thread.wait(30000)); + QCOMPARE(thread.returnValue, 0); + + // even though the thread has exited, and the event dispatcher destroyed, the timer is still + // "active", meaning the timer id should NOT be reused (i.e. the event dispatcher should not + // have unregistered it) + int timerId = thread.startTimer(100); + QVERIFY((timerId & 0xffffff) != (thread.timerId & 0xffffff)); +} + QTEST_MAIN(tst_QTimer) #include "tst_qtimer.moc" |