1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include <QtTest>
#include "Network/DecodedTime.hpp"
namespace
{
QDateTime nowUtc()
{
return {QDate {2026, 8, 17}, QTime {12, 34, 56}, Qt::UTC};
}
}
class TestDecodedTime final : public QObject
{
Q_OBJECT
private slots:
void acceptsFourAndSixDigitTimes()
{
auto const fourDigitExpected = QDateTime {QDate {2026, 8, 17}, QTime {12, 34}, Qt::UTC};
QCOMPARE(DecodedTime::spotTime("1234", nowUtc(), 60), fourDigitExpected);
auto const sixDigitExpected = nowUtc();
QCOMPARE(DecodedTime::spotTime("123456", nowUtc(), 60), sixDigitExpected);
}
void preservesMidnightConvention()
{
auto const firstExpected = QDateTime {QDate {2026, 8, 16}, QTime {23, 59}, Qt::UTC};
auto const secondExpected = QDateTime {QDate {2026, 8, 16}, QTime {23, 59, 45}, Qt::UTC};
auto const thirdExpected = QDateTime {QDate {2026, 8, 17}, QTime {23, 59, 30}, Qt::UTC};
QCOMPARE(DecodedTime::spotTime("2359", nowUtc(), 60), firstExpected);
QCOMPARE(DecodedTime::spotTime("235945", nowUtc(), 15), secondExpected);
QCOMPARE(DecodedTime::spotTime("235930", nowUtc(), 15), thirdExpected);
}
void roundsFractionalPeriodForMidnight()
{
auto const expected = QDateTime {QDate {2026, 8, 16}, QTime {23, 59, 52}, Qt::UTC};
QCOMPARE(DecodedTime::spotTime("235952", nowUtc(), 7.5), expected);
}
void rejectsMalformedTimes()
{
for (auto const& encodedTime : {QString {}, QString {"123"}, QString {"1234567"},
QString {"2460"}, QString {"1260"},
QString {"126099"}, QString {"12x4"}}) {
QVERIFY(!DecodedTime::spotTime(encodedTime, nowUtc(), 60).isValid());
}
}
};
QTEST_APPLESS_MAIN(TestDecodedTime)
#include "test_decoded_time.moc"
|