#include <QtQml/private/qqmltimer_p.h>
#include <QtQuick/qquickitem.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_qqmltimer : public QObject
{
tst_qqmltimer();
private slots:
+ void initTestCase();
void notRepeating();
void notRepeatingStart();
void repeat();
}
};
-#define TIMEOUT_TIMEOUT 200
-
tst_qqmltimer::tst_qqmltimer()
{
}
+void tst_qqmltimer::initTestCase()
+{
+ QUnifiedTimer::instance()->setConsistentTiming(true);
+}
+
void tst_qqmltimer::notRepeating()
{
QQmlEngine engine;
QQmlComponent component(&engine);
- component.setData(QByteArray("import QtQuick 2.0\nTimer { interval: 100; running: true }"), QUrl::fromLocalFile(""));
+ component.setData(QByteArray("import QtQml 2.0\nTimer { interval: 100; running: true }"), QUrl::fromLocalFile(""));
QQmlTimer *timer = qobject_cast<QQmlTimer*>(component.create());
QVERIFY(timer != 0);
QVERIFY(timer->isRunning());
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);
}
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);
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);
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);
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());
), QUrl::fromLocalFile(""));
QObject *item = component.create();
QVERIFY(item != 0);
- QTest::qWait(TIMEOUT_TIMEOUT);
+ consistentWait(200);
QCOMPARE(item->property("ok").toBool(), true);
delete item;
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());
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());
connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout()));
QCOMPARE(helper.count, 0);
- QTest::qWait(600);
+ consistentWait(600);
QCOMPARE(helper.count, 1);
QVERIFY(timer->isRunning());
- QTest::qWait(600);
+ consistentWait(600);
QCOMPARE(helper.count, 2);
QVERIFY(timer->isRunning());
}
connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout()));
QCOMPARE(helper.count, 0);
- QTest::qWait(600);
+ consistentWait(600);
QCOMPARE(helper.count, 1);
QVERIFY(timer->property("ok").toBool());
QVERIFY(timer->isRunning());
- QTest::qWait(600);
+ consistentWait(600);
QCOMPARE(helper.count, 2);
QVERIFY(timer->property("ok").toBool());
QVERIFY(timer->isRunning());