summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-10-06 23:53:01 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-10-06 23:53:01 (GMT)
commit5584feca163e91588f08b0aa1f3ae2817cd90823 (patch)
treefbded9f372f8ae6a0887e00202cbaf896176c56b /tests
parent2d7ad6196158a6138c946a5d26eefe9ac32f0773 (diff)
downloadQt-5584feca163e91588f08b0aa1f3ae2817cd90823.zip
Qt-5584feca163e91588f08b0aa1f3ae2817cd90823.tar.gz
Qt-5584feca163e91588f08b0aa1f3ae2817cd90823.tar.bz2
Auto tests for QmlTimer
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/declarative.pro5
-rw-r--r--tests/auto/declarative/qmltimer/qmltimer.pro5
-rw-r--r--tests/auto/declarative/qmltimer/tst_qmltimer.cpp141
3 files changed, 150 insertions, 1 deletions
diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro
index 4724278..f2ddbb7 100644
--- a/tests/auto/declarative/declarative.pro
+++ b/tests/auto/declarative/declarative.pro
@@ -7,13 +7,16 @@ SUBDIRS += datetimeformatter \
pathview \
qfxtext \
qfxtextedit \
- simplecanvasitem \
repeater \
qmllanguage \
qmlecmascript \
qmlmetaproperty \
qmllist \
qmllistaccessor \
+ qmltimer \
+ qfxloader \
+ qfxwebview \
+ states \
visual
# Tests which should run in Pulse
diff --git a/tests/auto/declarative/qmltimer/qmltimer.pro b/tests/auto/declarative/qmltimer/qmltimer.pro
new file mode 100644
index 0000000..e7edd96
--- /dev/null
+++ b/tests/auto/declarative/qmltimer/qmltimer.pro
@@ -0,0 +1,5 @@
+load(qttest_p4)
+contains(QT_CONFIG,declarative): QT += declarative gui
+SOURCES += tst_qmltimer.cpp
+
+DEFINES += SRCDIR=\\\"$$PWD\\\"
diff --git a/tests/auto/declarative/qmltimer/tst_qmltimer.cpp b/tests/auto/declarative/qmltimer/tst_qmltimer.cpp
new file mode 100644
index 0000000..15b558f
--- /dev/null
+++ b/tests/auto/declarative/qmltimer/tst_qmltimer.cpp
@@ -0,0 +1,141 @@
+#include <qtest.h>
+#include <QtDeclarative/qmlengine.h>
+#include <QtDeclarative/qmlcomponent.h>
+#include <QtDeclarative/qmltimer.h>
+
+class tst_qmltimer : public QObject
+{
+ Q_OBJECT
+public:
+ tst_qmltimer();
+
+private slots:
+ void notRepeating();
+ void notRepeatingStart();
+ void repeat();
+ void triggeredOnStart();
+ void triggeredOnStartRepeat();
+};
+
+class TimerHelper : public QObject
+{
+ Q_OBJECT
+public:
+ TimerHelper() : QObject(), count(0)
+ {
+ }
+
+ int count;
+
+public slots:
+ void timeout() {
+ ++count;
+ }
+};
+
+#if defined(Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86)
+// Increase wait as emulator startup can cause unexpected delays
+#define TIMEOUT_TIMEOUT 2000
+#else
+#define TIMEOUT_TIMEOUT 200
+#endif
+
+tst_qmltimer::tst_qmltimer()
+{
+}
+
+void tst_qmltimer::notRepeating()
+{
+ QmlEngine engine;
+ QmlComponent component(&engine, QByteArray("import Qt 4.6\nTimer { interval: 100; running: true }"), QUrl("file://"));
+ QmlTimer *timer = qobject_cast<QmlTimer*>(component.create());
+ QVERIFY(timer != 0);
+
+ TimerHelper helper;
+ connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout()));
+
+ QTest::qWait(TIMEOUT_TIMEOUT);
+ QCOMPARE(helper.count, 1);
+ QTest::qWait(TIMEOUT_TIMEOUT);
+ QCOMPARE(helper.count, 1);
+}
+
+void tst_qmltimer::notRepeatingStart()
+{
+ QmlEngine engine;
+ QmlComponent component(&engine, QByteArray("import Qt 4.6\nTimer { interval: 100 }"), QUrl("file://"));
+ QmlTimer *timer = qobject_cast<QmlTimer*>(component.create());
+ QVERIFY(timer != 0);
+
+ TimerHelper helper;
+ connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout()));
+
+ QTest::qWait(TIMEOUT_TIMEOUT);
+ QCOMPARE(helper.count, 0);
+
+ timer->start();
+ QTest::qWait(TIMEOUT_TIMEOUT);
+ QCOMPARE(helper.count, 1);
+ QTest::qWait(TIMEOUT_TIMEOUT);
+ QCOMPARE(helper.count, 1);
+}
+
+void tst_qmltimer::repeat()
+{
+ QmlEngine engine;
+ QmlComponent component(&engine, QByteArray("import Qt 4.6\nTimer { interval: 100; repeat: true; running: true }"), QUrl("file://"));
+ QmlTimer *timer = qobject_cast<QmlTimer*>(component.create());
+ QVERIFY(timer != 0);
+
+ TimerHelper helper;
+ connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout()));
+ QCOMPARE(helper.count, 0);
+
+ QTest::qWait(TIMEOUT_TIMEOUT);
+ QVERIFY(helper.count > 0);
+ int oldCount = helper.count;
+
+ QTest::qWait(TIMEOUT_TIMEOUT);
+ QVERIFY(helper.count > oldCount);
+}
+
+void tst_qmltimer::triggeredOnStart()
+{
+ QmlEngine engine;
+ QmlComponent component(&engine, QByteArray("import Qt 4.6\nTimer { interval: 100; running: true; triggeredOnStart: true }"), QUrl("file://"));
+ QmlTimer *timer = qobject_cast<QmlTimer*>(component.create());
+ QVERIFY(timer != 0);
+
+ TimerHelper helper;
+ connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout()));
+ QTest::qWait(1);
+ QCOMPARE(helper.count, 1);
+
+ QTest::qWait(TIMEOUT_TIMEOUT);
+ QCOMPARE(helper.count, 2);
+ QTest::qWait(TIMEOUT_TIMEOUT);
+ QCOMPARE(helper.count, 2);
+}
+
+void tst_qmltimer::triggeredOnStartRepeat()
+{
+ QmlEngine engine;
+ QmlComponent component(&engine, QByteArray("import Qt 4.6\nTimer { interval: 100; running: true; triggeredOnStart: true; repeat: true }"), QUrl("file://"));
+ QmlTimer *timer = qobject_cast<QmlTimer*>(component.create());
+ QVERIFY(timer != 0);
+
+ TimerHelper helper;
+ connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout()));
+ QTest::qWait(1);
+ QCOMPARE(helper.count, 1);
+
+ QTest::qWait(TIMEOUT_TIMEOUT);
+ QVERIFY(helper.count > 1);
+ int oldCount = helper.count;
+ QTest::qWait(TIMEOUT_TIMEOUT);
+ QVERIFY(helper.count > oldCount);
+}
+
+QTEST_MAIN(tst_qmltimer)
+
+#include "tst_qmltimer.moc"