summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2010-02-18 18:47:10 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2010-03-17 10:54:16 (GMT)
commit8c9446cd2058fde086df92f6b7d97e4770cf8dc6 (patch)
tree8118b5640a7495ccd53ff323983c1edfe67e2fe5 /tests
parent49d949b644b94fbd6c1946ffddcc1b8675ffa9ef (diff)
downloadQt-8c9446cd2058fde086df92f6b7d97e4770cf8dc6.zip
Qt-8c9446cd2058fde086df92f6b7d97e4770cf8dc6.tar.gz
Qt-8c9446cd2058fde086df92f6b7d97e4770cf8dc6.tar.bz2
Add a qtimestamp.cpp with some common functions.
Had to add invalidate() and isValid() functions because that's what QUnifiedTimer expects (QAbstractAnimation). Also move restart() to each implementation for efficiency. Task-number: QT-2965
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qtimestamp/tst_qtimestamp.cpp34
1 files changed, 30 insertions, 4 deletions
diff --git a/tests/auto/qtimestamp/tst_qtimestamp.cpp b/tests/auto/qtimestamp/tst_qtimestamp.cpp
index 5a0b230..ab1e959 100644
--- a/tests/auto/qtimestamp/tst_qtimestamp.cpp
+++ b/tests/auto/qtimestamp/tst_qtimestamp.cpp
@@ -3,15 +3,32 @@
#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;
@@ -36,6 +53,9 @@ void tst_QTimestamp::basics()
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()
@@ -43,7 +63,7 @@ void tst_QTimestamp::elapsed()
QTimestamp t1;
t1.start();
- QTest::qWait(100);
+ QTest::qWait(4*minResolution);
QTimestamp t2;
t2.start();
@@ -55,12 +75,18 @@ void tst_QTimestamp::elapsed()
QVERIFY(t1 - t2 < 0);
QVERIFY(t1.elapsed() > 0);
- QVERIFY(t1.hasExpired(50));
- QVERIFY(!t1.hasExpired(500));
- QVERIFY(!t2.hasExpired(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);