tests/auto/qtimer/tst_qtimer.cpp
changeset 37 758a864f9613
parent 30 5dc02b23752f
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
    84     void timerFiresOnlyOncePerProcessEvents_data();
    84     void timerFiresOnlyOncePerProcessEvents_data();
    85     void timerFiresOnlyOncePerProcessEvents();
    85     void timerFiresOnlyOncePerProcessEvents();
    86     void timerIdPersistsAfterThreadExit();
    86     void timerIdPersistsAfterThreadExit();
    87     void cancelLongTimer();
    87     void cancelLongTimer();
    88     void singleShotStaticFunctionZeroTimeout();
    88     void singleShotStaticFunctionZeroTimeout();
       
    89     void recurseOnTimeoutAndStopTimer();
    89 };
    90 };
    90 
    91 
    91 class TimerHelper : public QObject
    92 class TimerHelper : public QObject
    92 {
    93 {
    93     Q_OBJECT
    94     Q_OBJECT
   158     QCOMPARE(helper.count, 1);
   159     QCOMPARE(helper.count, 1);
   159     QTest::qWait(500);
   160     QTest::qWait(500);
   160     QCOMPARE(helper.count, 1);
   161     QCOMPARE(helper.count, 1);
   161 }
   162 }
   162 
   163 
   163 #if defined(Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86)
   164 #if defined(Q_OS_SYMBIAN)
   164 // Increase wait as emulator startup can cause unexpected delays
   165 // Increase wait as emulator startup can cause unexpected delays, and
       
   166 // on hardware there are sometimes spikes right after process startup.
   165 #define TIMEOUT_TIMEOUT 2000
   167 #define TIMEOUT_TIMEOUT 2000
   166 #else
   168 #else
   167 #define TIMEOUT_TIMEOUT 200
   169 #define TIMEOUT_TIMEOUT 200
   168 #endif
   170 #endif
   169 
   171 
   621     QCOMPARE(helper.count, 1);
   623     QCOMPARE(helper.count, 1);
   622     QTest::qWait(500);
   624     QTest::qWait(500);
   623     QCOMPARE(helper.count, 1);
   625     QCOMPARE(helper.count, 1);
   624 }
   626 }
   625 
   627 
       
   628 class RecursOnTimeoutAndStopTimerTimer : public QObject
       
   629 {
       
   630     Q_OBJECT
       
   631 
       
   632 public:
       
   633     QTimer *one;
       
   634     QTimer *two;
       
   635 
       
   636 public slots:
       
   637     void onetrigger()
       
   638     {
       
   639         QCoreApplication::processEvents();
       
   640     }
       
   641 
       
   642     void twotrigger()
       
   643     {
       
   644         one->stop();
       
   645     }
       
   646 };
       
   647 
       
   648 void tst_QTimer::recurseOnTimeoutAndStopTimer()
       
   649 {
       
   650     QEventLoop eventLoop;
       
   651     QTimer::singleShot(1000, &eventLoop, SLOT(quit()));
       
   652 
       
   653     RecursOnTimeoutAndStopTimerTimer t;
       
   654     t.one = new QTimer(&t);
       
   655     t.two = new QTimer(&t);
       
   656 
       
   657     QObject::connect(t.one, SIGNAL(timeout()), &t, SLOT(onetrigger()));
       
   658     QObject::connect(t.two, SIGNAL(timeout()), &t, SLOT(twotrigger()));
       
   659 
       
   660     t.two->setSingleShot(true);
       
   661 
       
   662     t.one->start();
       
   663     t.two->start();
       
   664 
       
   665     (void) eventLoop.exec();
       
   666 
       
   667     QVERIFY(!t.one->isActive());
       
   668     QVERIFY(!t.two->isActive());
       
   669 }
       
   670 
   626 QTEST_MAIN(tst_QTimer)
   671 QTEST_MAIN(tst_QTimer)
   627 #include "tst_qtimer.moc"
   672 #include "tst_qtimer.moc"