summaryrefslogtreecommitdiff
path: root/tests/unit/common/test_decoded_time.cpp
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2026-09-26 23:24:28 +0200
committerChristoph Berg <myon@debian.org>2026-09-26 23:24:28 +0200
commit69344560ea394c06ca94acac46a2e4c3e8b7b229 (patch)
treeebc98370a697a9bbd6b973a14fa5113c475c6db7 /tests/unit/common/test_decoded_time.cpp
parent3e9d10a67671d0bd5c7b8c3ca8088f1818322eff (diff)
parent059831534c7e884f0a607ed86b582fd00d821731 (diff)
Update upstream source from tag 'upstream/3.2.0_rc1+dfsg'
Update to upstream version '3.2.0~rc1+dfsg' with Debian dir dbff457fd2c3616d5c77b863c7bfb2186ed86047
Diffstat (limited to 'tests/unit/common/test_decoded_time.cpp')
-rw-r--r--tests/unit/common/test_decoded_time.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/unit/common/test_decoded_time.cpp b/tests/unit/common/test_decoded_time.cpp
new file mode 100644
index 00000000..e6115823
--- /dev/null
+++ b/tests/unit/common/test_decoded_time.cpp
@@ -0,0 +1,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"