From 059831534c7e884f0a607ed86b582fd00d821731 Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Sat, 26 Sep 2026 23:24:03 +0200 Subject: New upstream version 3.2.0~rc1+dfsg --- tests/unit/common/test_decoded_time.cpp | 54 +++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/unit/common/test_decoded_time.cpp (limited to 'tests/unit/common/test_decoded_time.cpp') 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 + +#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" -- cgit v1.2.3