diff options
Diffstat (limited to 'tests/auto/declarative')
-rw-r--r-- | tests/auto/declarative/qdeclarativetimer/qdeclarativetimer.pro | 2 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativetimer/tst_qdeclarativetimer.cpp | 62 |
2 files changed, 40 insertions, 24 deletions
diff --git a/tests/auto/declarative/qdeclarativetimer/qdeclarativetimer.pro b/tests/auto/declarative/qdeclarativetimer/qdeclarativetimer.pro index 4f15073a..35260dca 100644 --- a/tests/auto/declarative/qdeclarativetimer/qdeclarativetimer.pro +++ b/tests/auto/declarative/qdeclarativetimer/qdeclarativetimer.pro @@ -2,7 +2,7 @@ CONFIG += testcase TARGET = tst_qdeclarativetimer QT += testlib -contains(QT_CONFIG,declarative): QT += declarative declarative-private gui +contains(QT_CONFIG,declarative): QT += declarative declarative-private gui core-private macx:CONFIG -= app_bundle SOURCES += tst_qdeclarativetimer.cpp diff --git a/tests/auto/declarative/qdeclarativetimer/tst_qdeclarativetimer.cpp b/tests/auto/declarative/qdeclarativetimer/tst_qdeclarativetimer.cpp index decd2c34..58c27f3f 100644 --- a/tests/auto/declarative/qdeclarativetimer/tst_qdeclarativetimer.cpp +++ b/tests/auto/declarative/qdeclarativetimer/tst_qdeclarativetimer.cpp @@ -45,6 +45,18 @@ #include <private/qdeclarativetimer_p.h> #include <QtDeclarative/qdeclarativeitem.h> #include <QDebug> +#include <QtCore/QPauseAnimation> +#include <private/qabstractanimation_p.h> + +void consistentWait(int ms) +{ + //Use animations for timing, because we enabled consistentTiming + //This function will qWait for >= ms worth of consistent timing to elapse + QPauseAnimation waitTimer(ms); + waitTimer.start(); + while (waitTimer.state() == QAbstractAnimation::Running) + QTest::qWait(20); +} class tst_qdeclarativetimer : public QObject { @@ -53,6 +65,7 @@ public: tst_qdeclarativetimer(); private slots: + void initTestCase(); void notRepeating(); void notRepeatingStart(); void repeat(); @@ -80,12 +93,15 @@ public slots: } }; -#define TIMEOUT_TIMEOUT 200 - tst_qdeclarativetimer::tst_qdeclarativetimer() { } +void tst_qdeclarativetimer::initTestCase() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + void tst_qdeclarativetimer::notRepeating() { QDeclarativeEngine engine; @@ -100,9 +116,10 @@ void tst_qdeclarativetimer::notRepeating() TimerHelper helper; connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout())); - QTest::qWait(TIMEOUT_TIMEOUT); + + consistentWait(200); QCOMPARE(helper.count, 1); - QTest::qWait(TIMEOUT_TIMEOUT); + consistentWait(200); QCOMPARE(helper.count, 1); QVERIFY(timer->isRunning() == false); } @@ -119,13 +136,13 @@ void tst_qdeclarativetimer::notRepeatingStart() TimerHelper helper; connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout())); - QTest::qWait(TIMEOUT_TIMEOUT); + consistentWait(200); QCOMPARE(helper.count, 0); timer->start(); - QTest::qWait(TIMEOUT_TIMEOUT); + consistentWait(200); QCOMPARE(helper.count, 1); - QTest::qWait(TIMEOUT_TIMEOUT); + consistentWait(200); QCOMPARE(helper.count, 1); QVERIFY(timer->isRunning() == false); @@ -144,18 +161,18 @@ void tst_qdeclarativetimer::repeat() connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout())); QCOMPARE(helper.count, 0); - QTest::qWait(TIMEOUT_TIMEOUT); + consistentWait(200); QVERIFY(helper.count > 0); int oldCount = helper.count; - QTest::qWait(TIMEOUT_TIMEOUT); + consistentWait(200); QVERIFY(helper.count > oldCount); QVERIFY(timer->isRunning()); oldCount = helper.count; timer->stop(); - QTest::qWait(TIMEOUT_TIMEOUT); + consistentWait(200); QVERIFY(helper.count == oldCount); QVERIFY(timer->isRunning() == false); @@ -185,12 +202,11 @@ void tst_qdeclarativetimer::triggeredOnStart() TimerHelper helper; connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout())); - QTest::qWait(1); + consistentWait(1); QCOMPARE(helper.count, 1); - - QTest::qWait(TIMEOUT_TIMEOUT); + consistentWait(200); QCOMPARE(helper.count, 2); - QTest::qWait(TIMEOUT_TIMEOUT); + consistentWait(200); QCOMPARE(helper.count, 2); QVERIFY(timer->isRunning() == false); @@ -219,13 +235,13 @@ void tst_qdeclarativetimer::triggeredOnStartRepeat() TimerHelper helper; connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout())); - QTest::qWait(1); + consistentWait(1); QCOMPARE(helper.count, 1); - QTest::qWait(TIMEOUT_TIMEOUT); + consistentWait(200); QVERIFY(helper.count > 1); int oldCount = helper.count; - QTest::qWait(TIMEOUT_TIMEOUT); + consistentWait(200); QVERIFY(helper.count > oldCount); QVERIFY(timer->isRunning()); @@ -245,7 +261,7 @@ void tst_qdeclarativetimer::noTriggerIfNotRunning() ), QUrl::fromLocalFile("")); QObject *item = component.create(); QVERIFY(item != 0); - QTest::qWait(TIMEOUT_TIMEOUT); + consistentWait(200); QCOMPARE(item->property("ok").toBool(), true); delete item; @@ -263,12 +279,12 @@ void tst_qdeclarativetimer::changeDuration() connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout())); QCOMPARE(helper.count, 0); - QTest::qWait(500); + consistentWait(500); QCOMPARE(helper.count, 2); timer->setInterval(500); - QTest::qWait(600); + consistentWait(600); QCOMPARE(helper.count, 3); QVERIFY(timer->isRunning()); @@ -299,14 +315,14 @@ void tst_qdeclarativetimer::restart() connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout())); QCOMPARE(helper.count, 0); - QTest::qWait(600); + consistentWait(600); QCOMPARE(helper.count, 1); - QTest::qWait(300); + consistentWait(300); timer->restart(); - QTest::qWait(700); + consistentWait(700); QCOMPARE(helper.count, 2); QVERIFY(timer->isRunning()); |