1#include <QtTest/QTest>
2
3Q_DECLARE_METATYPE(QDate)
4Q_DECLARE_METATYPE(QTime)
5
6#include <poppler-qt6.h>
7
8class TestDateConv : public QObject
9{
10 Q_OBJECT
11public:
12 explicit TestDateConv(QObject *parent = nullptr) : QObject(parent) { }
13
14private slots:
15 void initTestCase();
16 void checkDates_data();
17 void checkDates();
18 void checkInvalidDates_data();
19 void checkInvalidDates();
20};
21
22void TestDateConv::initTestCase()
23{
24 qRegisterMetaType<QDate>(typeName: "QDate");
25 qRegisterMetaType<QTime>(typeName: "QTime");
26}
27
28void TestDateConv::checkDates_data()
29{
30 QTest::addColumn<QByteArray>(name: "input");
31 QTest::addColumn<QDate>(name: "day");
32 QTest::addColumn<QTime>(name: "time");
33
34 // This is a typical case - all data provided
35 QTest::newRow(dataTag: "D:20040101121110") << QByteArray("D:20040101121110Z") << QDate(2004, 1, 1) << QTime(12, 11, 10);
36
37 // The D: is strongly recommended, but optional
38 QTest::newRow(dataTag: "20040101121110") << QByteArray("20040101121110Z") << QDate(2004, 1, 1) << QTime(12, 11, 10);
39
40 // Only the year is actually required
41 QTest::newRow(dataTag: "D:2006") << QByteArray("D:2006") << QDate(2006, 1, 1) << QTime(0, 0, 0);
42
43 QTest::newRow(dataTag: "D:200602") << QByteArray("D:200602") << QDate(2006, 2, 1) << QTime(0, 0, 0);
44
45 QTest::newRow(dataTag: "D:20060304") << QByteArray("D:20060304") << QDate(2006, 3, 4) << QTime(0, 0, 0);
46
47 QTest::newRow(dataTag: "D:2006030405") << QByteArray("D:2006030405") << QDate(2006, 3, 4) << QTime(5, 0, 0);
48
49 QTest::newRow(dataTag: "D:200603040512") << QByteArray("D:200603040512") << QDate(2006, 3, 4) << QTime(5, 12, 0);
50
51 // If the timezone isn't specified, I assume UTC
52 QTest::newRow(dataTag: "D:20060304051226") << QByteArray("D:20060304051226") << QDate(2006, 3, 4) << QTime(5, 12, 26);
53
54 // Check for real timezone conversions
55 QTest::newRow(dataTag: "D:20030131115258-04'00'") << QByteArray("D:20030131115258-04'00'") << QDate(2003, 1, 31) << QTime(15, 52, 58);
56
57 QTest::newRow(dataTag: "D:20030131115258+05'00'") << QByteArray("D:20030131115258+05'00'") << QDate(2003, 1, 31) << QTime(6, 52, 58);
58
59 // There are places that have non-hour offsets
60 // Yep, that means you Adelaide.
61 QTest::newRow(dataTag: "D:20030131115258+08'30'") << QByteArray("D:20030131115258+08'30'") << QDate(2003, 1, 31) << QTime(3, 22, 58);
62
63 QTest::newRow(dataTag: "D:20030131115258-08'30'") << QByteArray("D:20030131115258-08'30'") << QDate(2003, 1, 31) << QTime(20, 22, 58);
64}
65
66void TestDateConv::checkDates()
67{
68 QFETCH(QByteArray, input);
69 QFETCH(QDate, day);
70 QFETCH(QTime, time);
71
72 QCOMPARE(Poppler::convertDate(input.constData()), QDateTime(day, time, Qt::UTC));
73}
74
75void TestDateConv::checkInvalidDates_data()
76{
77 QTest::addColumn<QByteArray>(name: "input");
78
79 // Null data
80 QTest::newRow(dataTag: "Null data") << QByteArray();
81
82 // Empty data
83 QTest::newRow(dataTag: "Empty data") << QByteArray("");
84
85 // Empty data
86 QTest::newRow(dataTag: "One character") << QByteArray("D");
87
88 // Empty data
89 QTest::newRow(dataTag: "'D:'") << QByteArray("D:");
90
91 // Empty data
92 QTest::newRow(dataTag: "Not a date") << QByteArray("D:IAmNotAValidDate");
93}
94
95void TestDateConv::checkInvalidDates()
96{
97 QFETCH(QByteArray, input);
98
99 QCOMPARE(Poppler::convertDate(input.constData()), QDateTime());
100}
101
102QTEST_GUILESS_MAIN(TestDateConv)
103
104#include "check_dateConversion.moc"
105

source code of poppler/qt6/tests/check_dateConversion.cpp