aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2012-01-10 10:28:11 +1000
committerQt by Nokia <qt-info@nokia.com>2012-01-12 09:33:32 +0100
commit521aa7f562a5f215de09e3f37168f6a6d0ce5543 (patch)
treefeaa4b1cdd8dc799b876ff2218434b8ad0cfe7f6 /tests/auto
parent21e6e0e6aa72ab6051eaadd5fbda29c795ca8c8e (diff)
Fix restarting timer from onTriggered handler.
Set the running property to false before calling the triggered handler when a timer finishes so it does not appear to still be running and can be restarted by setting the running property to true. Task-number: QTBUG-22004 Change-Id: I840efa30f5b7ad7d0cda96803d4898be3f390705 Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qtquick2/qdeclarativetimer/tst_qdeclarativetimer.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/auto/qtquick2/qdeclarativetimer/tst_qdeclarativetimer.cpp b/tests/auto/qtquick2/qdeclarativetimer/tst_qdeclarativetimer.cpp
index 6582f0fb48..b7045a1317 100644
--- a/tests/auto/qtquick2/qdeclarativetimer/tst_qdeclarativetimer.cpp
+++ b/tests/auto/qtquick2/qdeclarativetimer/tst_qdeclarativetimer.cpp
@@ -61,6 +61,8 @@ private slots:
void triggeredOnStartRepeat();
void changeDuration();
void restart();
+ void restartFromTriggered();
+ void runningFromTriggered();
void parentProperty();
};
@@ -314,6 +316,63 @@ void tst_qdeclarativetimer::restart()
delete timer;
}
+void tst_qdeclarativetimer::restartFromTriggered()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine);
+ component.setData(QByteArray("import QtQuick 2.0\nTimer { "
+ "interval: 500; "
+ "repeat: false; "
+ "running: true; "
+ "onTriggered: restart()"
+ " }"), QUrl::fromLocalFile(""));
+ QScopedPointer<QObject> object(component.create());
+ QDeclarativeTimer *timer = qobject_cast<QDeclarativeTimer*>(object.data());
+ QVERIFY(timer != 0);
+
+ TimerHelper helper;
+ connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout()));
+ QCOMPARE(helper.count, 0);
+
+ QTest::qWait(600);
+ QCOMPARE(helper.count, 1);
+ QVERIFY(timer->isRunning());
+
+ QTest::qWait(600);
+ QCOMPARE(helper.count, 2);
+ QVERIFY(timer->isRunning());
+}
+
+void tst_qdeclarativetimer::runningFromTriggered()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine);
+ component.setData(QByteArray("import QtQuick 2.0\nTimer { "
+ "property bool ok: false; "
+ "interval: 500; "
+ "repeat: false; "
+ "running: true; "
+ "onTriggered: { ok = !running; running = true }"
+ " }"), QUrl::fromLocalFile(""));
+ QScopedPointer<QObject> object(component.create());
+ QDeclarativeTimer *timer = qobject_cast<QDeclarativeTimer*>(object.data());
+ QVERIFY(timer != 0);
+
+ TimerHelper helper;
+ connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout()));
+ QCOMPARE(helper.count, 0);
+
+ QTest::qWait(600);
+ QCOMPARE(helper.count, 1);
+ QVERIFY(timer->property("ok").toBool());
+ QVERIFY(timer->isRunning());
+
+ QTest::qWait(600);
+ QCOMPARE(helper.count, 2);
+ QVERIFY(timer->property("ok").toBool());
+ QVERIFY(timer->isRunning());
+}
+
void tst_qdeclarativetimer::parentProperty()
{
QDeclarativeEngine engine;