summaryrefslogtreecommitdiffstats
path: root/tests/auto/qelapsedtimer
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2010-02-26 14:02:56 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2010-03-17 10:54:19 (GMT)
commit7f3c9feaaf67ce7e89cd2f9df2155c61a58acaed (patch)
tree226e3222506672a358318955906b859c9ca6b59c /tests/auto/qelapsedtimer
parent21983be486af0d252b8d393ed36b15becb3c8824 (diff)
downloadQt-7f3c9feaaf67ce7e89cd2f9df2155c61a58acaed.zip
Qt-7f3c9feaaf67ce7e89cd2f9df2155c61a58acaed.tar.gz
Qt-7f3c9feaaf67ce7e89cd2f9df2155c61a58acaed.tar.bz2
Rename the files too
Diffstat (limited to 'tests/auto/qelapsedtimer')
-rw-r--r--tests/auto/qelapsedtimer/qelapsedtimer.pro13
-rw-r--r--tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp94
2 files changed, 107 insertions, 0 deletions
diff --git a/tests/auto/qelapsedtimer/qelapsedtimer.pro b/tests/auto/qelapsedtimer/qelapsedtimer.pro
new file mode 100644
index 0000000..3a06390
--- /dev/null
+++ b/tests/auto/qelapsedtimer/qelapsedtimer.pro
@@ -0,0 +1,13 @@
+load(qttest_p4)
+QT -= gui
+
+SOURCES += tst_qtimestamp.cpp
+wince* {
+ DEFINES += SRCDIR=\\\"\\\"
+} else:symbian {
+ # do not define SRCDIR at all
+ TARGET.EPOCHEAPSIZE = 0x100000 0x3000000
+} else {
+ DEFINES += SRCDIR=\\\"$$PWD/\\\"
+}
+
diff --git a/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp b/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp
new file mode 100644
index 0000000..79138ce
--- /dev/null
+++ b/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp
@@ -0,0 +1,94 @@
+#include <QtCore/QString>
+#include <QtCore/QTime>
+#include <QtCore/QTimestamp>
+#include <QtTest/QtTest>
+
+static const int minResolution = 50; // the minimum resolution for the tests
+
+class tst_QTimestamp : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void validity();
+ void basics();
+ void elapsed();
+};
+
+void tst_QTimestamp::validity()
+{
+ QTimestamp t;
+
+ t.invalidate();
+ QVERIFY(!t.isValid());
+
+ t.start();
+ QVERIFY(t.isValid());
+
+ t.invalidate();
+ QVERIFY(!t.isValid());
+}
+
+void tst_QTimestamp::basics()
+{
+ QTimestamp t1;
+ t1.start();
+
+ QCOMPARE(t1, t1);
+ QVERIFY(!(t1 != t1));
+ QVERIFY(!(t1 < t1));
+ QCOMPARE(t1.msecsTo(t1), qint64(0));
+ QCOMPARE(t1.secsTo(t1), qint64(0));
+ QCOMPARE(t1 + 0, t1);
+ QCOMPARE(t1 - 0, t1);
+
+ QTimestamp t2 = t1;
+ t2 += 1000; // so we can use secsTo
+
+ QVERIFY(t1 != t2);
+ QVERIFY(!(t1 == t2));
+ QVERIFY(t1 < t2);
+ QVERIFY(!(t2 < t1));
+ QCOMPARE(t1.msecsTo(t2), qint64(1000));
+ QCOMPARE(t1.secsTo(t2), qint64(1));
+ QCOMPARE(t2 - t1, qint64(1000));
+ QCOMPARE(t1 - t2, qint64(-1000));
+
+ qint64 elapsed = t1.restart();
+ QVERIFY(elapsed < minResolution);
+}
+
+void tst_QTimestamp::elapsed()
+{
+ QTimestamp t1;
+ t1.start();
+
+ QTest::qSleep(4*minResolution);
+ QTimestamp t2;
+ t2.start();
+
+ QVERIFY(t1 != t2);
+ QVERIFY(!(t1 == t2));
+ QVERIFY(t1 < t2);
+ QVERIFY(t1.msecsTo(t2) > 0);
+ // don't check: t1.secsTo(t2)
+ QVERIFY(t1 - t2 < 0);
+
+ QVERIFY(t1.elapsed() > 0);
+ QVERIFY(t1.hasExpired(minResolution));
+ QVERIFY(!t1.hasExpired(8*minResolution));
+ QVERIFY(!t2.hasExpired(minResolution));
+
+ QVERIFY(!t1.hasExpired(-1));
+ QVERIFY(!t2.hasExpired(-1));
+
+ qint64 elapsed = t1.restart();
+ QVERIFY(elapsed > 3*minResolution);
+ QVERIFY(elapsed < 5*minResolution);
+ qint64 diff = t1 - t2;
+ QVERIFY(diff < minResolution);
+}
+
+QTEST_MAIN(tst_QTimestamp);
+
+#include "tst_qtimestamp.moc"