summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Alpert <aalpert@rim.com>2012-12-05 12:36:49 -0800
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-12-05 23:42:42 +0100
commit3f6834ae227b30f981d36e87ab2ad6a4f00a784b (patch)
treef208f4cbbcdea1bfe188f52d72e315f6eedc3549
parent6b806a9c8b25a4d0b6dd0618c58f33926ea6d949 (diff)
Stabilize tst_qdeclarativetimer
Use consistent timing on the unified timer instead of qWait Manual cherry-pick of 2ebb2fce87642ef0da8629bdb27164fffbdcdcb9 Change-Id: I76c402081062f7f6849bd421e90bc96f08e8d95a Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
-rw-r--r--tests/auto/declarative/qdeclarativetimer/qdeclarativetimer.pro2
-rw-r--r--tests/auto/declarative/qdeclarativetimer/tst_qdeclarativetimer.cpp62
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());