diff options
| author | hibby <d@vehibberd.com> | 2026-10-06 21:24:40 +0100 |
|---|---|---|
| committer | hibby <d@vehibberd.com> | 2026-10-06 21:24:40 +0100 |
| commit | c25cbdf6fb6d946175f4335fab77bfea601b56db (patch) | |
| tree | 6f7a94b7b81f999e434f61b73d47e337dfd26bf2 /tests/unit/common/test_decoded_time.cpp | |
| parent | 71f5689252c9f13e70e1c24856904475b2307809 (diff) | |
| parent | 0685fcada9f95fe90f70b387cd7d757da8209624 (diff) | |
Merge tag 'debian/3.2.0_rc1+dfsg-2' into debian/trixie-backportsdebian/trixie-backports
tagging wsjtx 3.2.0~rc1+dfsg-2
Diffstat (limited to 'tests/unit/common/test_decoded_time.cpp')
| -rw-r--r-- | tests/unit/common/test_decoded_time.cpp | 54 |
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" |
