diff options
Diffstat (limited to 'qt4/tests/check_dateConversion.cpp')
-rw-r--r-- | qt4/tests/check_dateConversion.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/qt4/tests/check_dateConversion.cpp b/qt4/tests/check_dateConversion.cpp new file mode 100644 index 00000000..214e975a --- /dev/null +++ b/qt4/tests/check_dateConversion.cpp @@ -0,0 +1,105 @@ +#include <QtTest/QtTest> + +Q_DECLARE_METATYPE(QDate) +Q_DECLARE_METATYPE(QTime) + +#define UNSTABLE_POPPLER_QT4 +#include <poppler-qt4.h> + +class TestDateConv: public QObject +{ + Q_OBJECT +private slots: + void checkDates_data(); + void checkDates(); +}; + +void TestDateConv::checkDates_data() +{ + qRegisterMetaType<QDate>("QDate"); + qRegisterMetaType<QTime>("QTime"); + + QTest::addColumn<QByteArray>("input"); + QTest::addColumn<QDate>("day"); + QTest::addColumn<QTime>("time"); + + // This is a typical case - all data provided + QTest::newRow("D:20040101121110") + << QByteArray("D:20040101121110Z") + << QDate( 2004, 1, 1) + << QTime( 12, 11, 10); + + // The D: is strongly recommended, but optional + QTest::newRow("20040101121110") + << QByteArray("20040101121110Z") + << QDate( 2004, 1, 1) + << QTime( 12, 11, 10); + + // Only the year is actually required + QTest::newRow("D:2006") + << QByteArray("D:2006") + << QDate( 2006, 1, 1) + << QTime( 0, 0, 0); + + QTest::newRow("D:200602") + << QByteArray("D:200602") + << QDate( 2006, 2, 1) + << QTime( 0, 0, 0); + + QTest::newRow("D:20060304") + << QByteArray("D:20060304") + << QDate( 2006, 3, 4) + << QTime( 0, 0, 0); + + QTest::newRow("D:2006030405") + << QByteArray("D:2006030405") + << QDate( 2006, 3, 4) + << QTime( 5, 0, 0); + + QTest::newRow("D:200603040512") + << QByteArray("D:200603040512") + << QDate( 2006, 3, 4) + << QTime( 5, 12, 0); + + // If the timezone isn't specified, I assume UTC + QTest::newRow("D:20060304051226") + << QByteArray("D:20060304051226") + << QDate( 2006, 3, 4) + << QTime( 5, 12, 26); + + // Check for real timezone conversions + QTest::newRow("D:20030131115258-04'00'") + << QByteArray("D:20030131115258-04'00'") + << QDate( 2003, 1, 31) + << QTime( 15, 52, 58); + + QTest::newRow("D:20030131115258+05'00'") + << QByteArray("D:20030131115258+05'00'") + << QDate( 2003, 1, 31) + << QTime( 6, 52, 58); + + // There are places that have non-hour offsets + // Yep, that means you Adelaide. + QTest::newRow("D:20030131115258+08'30'") + << QByteArray("D:20030131115258+08'30'") + << QDate( 2003, 1, 31) + << QTime( 3, 22, 58); + + QTest::newRow("D:20030131115258-08'30'") + << QByteArray("D:20030131115258-08'30'") + << QDate( 2003, 1, 31) + << QTime( 20, 22, 58); +} + +void TestDateConv::checkDates() +{ + QFETCH(QByteArray, input); + QFETCH(QDate, day); + QFETCH(QTime, time); + + QCOMPARE( Poppler::convertDate(input.data()), QDateTime(day, time, Qt::UTC) ); +} + +QTEST_MAIN(TestDateConv) +#include "check_dateConversion.moc" + |