diff options
author | Gunnar Sletta <gunnar@trolltech.com> | 2009-04-17 07:23:47 (GMT) |
---|---|---|
committer | Gunnar Sletta <gunnar@trolltech.com> | 2009-04-17 07:23:47 (GMT) |
commit | 58f8796ae4d9dcb9e741d2a07c87e6b82a2a4d9b (patch) | |
tree | 5f265a6f87cabef61dd763aab3d76e200d8d67a3 /tests/auto/qtimer | |
parent | ac7484e36bfab69473278d7268cf37f7c69abfd2 (diff) | |
parent | d43d33eb3121519d0025ad433d5c186365c47ef6 (diff) | |
download | Qt-58f8796ae4d9dcb9e741d2a07c87e6b82a2a4d9b.zip Qt-58f8796ae4d9dcb9e741d2a07c87e6b82a2a4d9b.tar.gz Qt-58f8796ae4d9dcb9e741d2a07c87e6b82a2a4d9b.tar.bz2 |
Merge branch 'qt/main'
Conflicts:
src/opengl/opengl.pro
Diffstat (limited to 'tests/auto/qtimer')
-rw-r--r-- | tests/auto/qtimer/tst_qtimer.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/auto/qtimer/tst_qtimer.cpp b/tests/auto/qtimer/tst_qtimer.cpp index 527628c..bffb4f2 100644 --- a/tests/auto/qtimer/tst_qtimer.cpp +++ b/tests/auto/qtimer/tst_qtimer.cpp @@ -83,6 +83,7 @@ private slots: void recurringTimer(); void deleteLaterOnQTimer(); // long name, don't want to shadow QObject::deleteLater() void moveToThread(); + void restartedTimerFiresTooSoon(); }; class TimerHelper : public QObject @@ -416,5 +417,69 @@ void tst_QTimer::moveToThread() QVERIFY((ti3.timerId() & 0xffffff) != (ti1.timerId() & 0xffffff)); } +class RestartedTimerFiresTooSoonObject : public QObject +{ + Q_OBJECT + +public: + QBasicTimer m_timer; + + int m_interval; + QTime m_startedTime; + QEventLoop eventLoop; + + inline RestartedTimerFiresTooSoonObject() + : QObject(), m_interval(0) + { } + + void timerFired() + { + static int interval = 1000; + + m_interval = interval; + m_startedTime.start(); + m_timer.start(interval, this); + + // alternate between single-shot and 1 sec + interval = interval ? 0 : 1000; + } + + void timerEvent(QTimerEvent* ev) + { + if (ev->timerId() != m_timer.timerId()) + return; + + m_timer.stop(); + + QTime now = QTime::currentTime(); + int elapsed = m_startedTime.elapsed(); + + if (elapsed < m_interval / 2) { + // severely too early! + m_timer.stop(); + eventLoop.exit(-1); + return; + } + + timerFired(); + + // don't do this forever + static int count = 0; + if (count++ > 20) { + m_timer.stop(); + eventLoop.quit(); + return; + } + } +}; + +void tst_QTimer::restartedTimerFiresTooSoon() +{ + RestartedTimerFiresTooSoonObject object; + object.timerFired(); + QVERIFY(object.eventLoop.exec() == 0); +} + QTEST_MAIN(tst_QTimer) #include "tst_qtimer.moc" +\ |