diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2010-02-18 10:31:05 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2010-03-17 10:54:14 (GMT) |
commit | 782a5c8537831143d52df99c434bb1e5420d7113 (patch) | |
tree | 20377517ae20fe5f774e36ddccb872bf0bad4c36 /tests | |
parent | f3d4d5534e2a5e83ca2ec7bddefde08e4343df87 (diff) | |
download | Qt-782a5c8537831143d52df99c434bb1e5420d7113.zip Qt-782a5c8537831143d52df99c434bb1e5420d7113.tar.gz Qt-782a5c8537831143d52df99c434bb1e5420d7113.tar.bz2 |
Initial version of QTimestamp class.
Only the generic, non-monotonic QTime-based version available right now
Task-number: QT-2965
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qtimestamp/qtimestamp.pro | 13 | ||||
-rw-r--r-- | tests/auto/qtimestamp/tst_qtimestamp.cpp | 68 |
2 files changed, 81 insertions, 0 deletions
diff --git a/tests/auto/qtimestamp/qtimestamp.pro b/tests/auto/qtimestamp/qtimestamp.pro new file mode 100644 index 0000000..3a06390 --- /dev/null +++ b/tests/auto/qtimestamp/qtimestamp.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/qtimestamp/tst_qtimestamp.cpp b/tests/auto/qtimestamp/tst_qtimestamp.cpp new file mode 100644 index 0000000..5a0b230 --- /dev/null +++ b/tests/auto/qtimestamp/tst_qtimestamp.cpp @@ -0,0 +1,68 @@ +#include <QtCore/QString> +#include <QtCore/QTime> +#include <QtCore/QTimestamp> +#include <QtTest/QtTest> + +class tst_QTimestamp : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void basics(); + void elapsed(); +}; + +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)); +} + +void tst_QTimestamp::elapsed() +{ + QTimestamp t1; + t1.start(); + + QTest::qWait(100); + 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(50)); + QVERIFY(!t1.hasExpired(500)); + QVERIFY(!t2.hasExpired(0)); + + QVERIFY(!t1.hasExpired(-1)); + QVERIFY(!t2.hasExpired(-1)); +} + +QTEST_MAIN(tst_QTimestamp); + +#include "tst_qtimestamp.moc" |