aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmltimer
diff options
context:
space:
mode:
authorTroels Nilsson <nilsson.troels@gmail.com>2015-01-21 14:18:35 +0100
committerLars Knoll <lars.knoll@digia.com>2015-02-11 18:36:10 +0000
commitc6f0e3967992780e7786d6bdd90b21149009f2fd (patch)
tree47b29cc8cbc8166889bbc060cbb22e65d140f0c5 /tests/auto/qml/qqmltimer
parent890082091b93dae1df895eda92bbb64675d29fbc (diff)
Fix QML Timer running not being updated together with triggered signal
The running property of the QML Timer should be updated at the same time as the triggered signal is emitted, otherwise code like e.g. the following: if (qmlTimer.running) { qmlTimer.stop() } doesn't work as expected. In addition if the timer is stopped or restarted between posting the QEvent_Triggered event and receiving it, the triggered event should not be emitted. This avoids the issue of stopped timers still emitting the triggered signal which can potentially cause problems in existing code. Task-number: QTBUG-44026 Change-Id: Ia14d80d152967d09adc1586467715b2e1c6662cc Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'tests/auto/qml/qqmltimer')
-rw-r--r--tests/auto/qml/qqmltimer/tst_qqmltimer.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmltimer/tst_qqmltimer.cpp b/tests/auto/qml/qqmltimer/tst_qqmltimer.cpp
index 3d24bcb715..b1e4bcab72 100644
--- a/tests/auto/qml/qqmltimer/tst_qqmltimer.cpp
+++ b/tests/auto/qml/qqmltimer/tst_qqmltimer.cpp
@@ -50,6 +50,23 @@ void consistentWait(int ms)
QTest::qWait(20);
}
+void eventLoopWait(int ms)
+{
+ // QTest::qWait() always calls sendPostedEvents before exiting, so we can't use it to stop
+ // between an event is posted and it is received; But we can use an event loop instead
+
+ QPauseAnimation waitTimer(ms);
+ waitTimer.start();
+ while (waitTimer.state() == QAbstractAnimation::Running)
+ {
+ QTimer timer;
+ QEventLoop eventLoop;
+ timer.start(0);
+ timer.connect(&timer, &QTimer::timeout, &eventLoop, &QEventLoop::quit);
+ eventLoop.exec();
+ }
+}
+
class tst_qqmltimer : public QObject
{
Q_OBJECT
@@ -69,6 +86,8 @@ private slots:
void restartFromTriggered();
void runningFromTriggered();
void parentProperty();
+ void stopWhenEventPosted();
+ void restartWhenEventPosted();
};
class TimerHelper : public QObject
@@ -396,6 +415,51 @@ void tst_qqmltimer::parentProperty()
delete timer;
}
+void tst_qqmltimer::stopWhenEventPosted()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.setData(QByteArray("import QtQml 2.0\nTimer { interval: 200; running: true }"), QUrl::fromLocalFile(""));
+ QQmlTimer *timer = qobject_cast<QQmlTimer*>(component.create());
+
+ TimerHelper helper;
+ connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout()));
+ QCOMPARE(helper.count, 0);
+
+ eventLoopWait(200);
+ QCOMPARE(helper.count, 0);
+ QVERIFY(timer->isRunning());
+ timer->stop();
+ QVERIFY(!timer->isRunning());
+
+ consistentWait(300);
+ QCOMPARE(helper.count, 0);
+}
+
+
+void tst_qqmltimer::restartWhenEventPosted()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.setData(QByteArray("import QtQml 2.0\nTimer { interval: 200; running: true }"), QUrl::fromLocalFile(""));
+ QQmlTimer *timer = qobject_cast<QQmlTimer*>(component.create());
+
+ TimerHelper helper;
+ connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout()));
+ QCOMPARE(helper.count, 0);
+
+ eventLoopWait(200);
+ QCOMPARE(helper.count, 0);
+ timer->restart();
+
+ consistentWait(100);
+ QCOMPARE(helper.count, 0);
+ QVERIFY(timer->isRunning());
+
+ consistentWait(200);
+ QCOMPARE(helper.count, 1);
+}
+
QTEST_MAIN(tst_qqmltimer)
#include "tst_qqmltimer.moc"