diff options
author | axis <qt-info@nokia.com> | 2009-05-19 14:18:28 (GMT) |
---|---|---|
committer | axis <qt-info@nokia.com> | 2009-05-19 14:18:28 (GMT) |
commit | e6419c7bb5fe384aa475c3a2e75781d5a0d77862 (patch) | |
tree | 0a527aafeb715930f21a7b589dc9abebb7e2d31b /tests | |
parent | d7fda9c7aef17ed79fd656f197fb179acb4ec54a (diff) | |
parent | a1db305f482de2d24797b8f99a752e49e80fa392 (diff) | |
download | Qt-e6419c7bb5fe384aa475c3a2e75781d5a0d77862.zip Qt-e6419c7bb5fe384aa475c3a2e75781d5a0d77862.tar.gz Qt-e6419c7bb5fe384aa475c3a2e75781d5a0d77862.tar.bz2 |
Merge branch 'eventDispatcherFixes'
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qtimer/tst_qtimer.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/auto/qtimer/tst_qtimer.cpp b/tests/auto/qtimer/tst_qtimer.cpp index cde2765..0051a9b 100644 --- a/tests/auto/qtimer/tst_qtimer.cpp +++ b/tests/auto/qtimer/tst_qtimer.cpp @@ -84,6 +84,8 @@ private slots: void deleteLaterOnQTimer(); // long name, don't want to shadow QObject::deleteLater() void moveToThread(); void restartedTimerFiresTooSoon(); + void timerFiresOnlyOncePerProcessEvents_data(); + void timerFiresOnlyOncePerProcessEvents(); }; class TimerHelper : public QObject @@ -480,6 +482,55 @@ void tst_QTimer::restartedTimerFiresTooSoon() QVERIFY(object.eventLoop.exec() == 0); } +class LongLastingSlotClass : public QObject +{ + Q_OBJECT + +public: + LongLastingSlotClass(QTimer *timer) : count(0), timer(timer) {} + +public slots: + void longLastingSlot() + { + // Don't use timers for this, because we are testing them. + QTime time; + time.start(); + while (time.elapsed() < 200) { + for (int c = 0; c < 100000; c++) {} // Mindless looping. + } + if (++count >= 2) { + timer->stop(); + } + } + +public: + int count; + QTimer *timer; +}; + +void tst_QTimer::timerFiresOnlyOncePerProcessEvents_data() +{ + QTest::addColumn<int>("interval"); + QTest::newRow("zero timer") << 0; + QTest::newRow("non-zero timer") << 10; +} + +void tst_QTimer::timerFiresOnlyOncePerProcessEvents() +{ + QFETCH(int, interval); + + QTimer t; + LongLastingSlotClass longSlot(&t); + t.start(interval); + connect(&t, SIGNAL(timeout()), &longSlot, SLOT(longLastingSlot())); + // Loop because there may be other events pending. + while (longSlot.count == 0) { + QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents); + } + + QCOMPARE(longSlot.count, 1); +} + QTEST_MAIN(tst_QTimer) #include "tst_qtimer.moc" \ |