summaryrefslogtreecommitdiffstats
path: root/tests/auto/qtimer
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2009-04-08 11:07:33 +0200
committerBradley T. Hughes <bradley.hughes@nokia.com>2009-04-08 11:28:06 +0200
commit74f092408d1a870e2c1e2a49182c8e09f952055d (patch)
treebc3fd9f069ecd84a842650ba028df6d46f850238 /tests/auto/qtimer
parentc131208e59f5b2dd517b00c4539458760b8fd8aa (diff)
Javascript: When there is javascript running then it will spin the CPU at 100%
Zero timers on Windows would continue to fire even after being stopped as long as a new timer was started that reused the pointer address of the zero timer. Fix this by only re-firing zero timers if the zero timer hadn't been stopped (we can check this by looking at the inTimerEvent flag, which is set to false by registerTimer()). Task-number: 247401 Reviewed-by: Denis Dzyubenko Reviewed-by: Prasanth Ullattil
Diffstat (limited to 'tests/auto/qtimer')
-rw-r--r--tests/auto/qtimer/tst_qtimer.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/auto/qtimer/tst_qtimer.cpp b/tests/auto/qtimer/tst_qtimer.cpp
index 527628cc59..bffb4f24da 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"
+\