aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmltimer
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>2015-02-24 17:36:04 +0100
committerFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>2015-02-24 17:36:04 +0100
commitad67ec26d0cbc98e3440dd38bb20eef4da2ee96d (patch)
tree9f8135751df2f995a4f55837ea065a4687245b71 /tests/auto/qml/qqmltimer
parent83a16630c13969e68cd3a5aaab73335ccb0d4414 (diff)
parent20d160d0513a04be187ed851a25b029f47c27b27 (diff)
Merge remote-tracking branch 'origin/5.4' into 5.5
Conflicts: .qmake.conf LICENSE.GPLv2 examples/qml/networkaccessmanagerfactory/view.qml src/qml/jsruntime/qv4runtime.cpp src/qml/jsruntime/qv4stringobject.cpp Change-Id: I5d12f436d60995e51d5c2f59d364e9cbc24f8e32
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 7bb86aa097..17083a4c6a 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"