diff options
| author | Christoph Berg <myon@debian.org> | 2026-10-09 14:12:35 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-10-09 14:12:35 +0200 |
| commit | ffc62c792c9a5196cb4ce7a353287dfe20db6524 (patch) | |
| tree | 1269efa852935b183daae4bb33a58d1b4d2ffb53 /tests/unit/jtty/test_jtty_messages.cpp | |
| parent | 059831534c7e884f0a607ed86b582fd00d821731 (diff) | |
New upstream version 3.3.0~beta1+dfsgupstream/3.3.0_beta1+dfsg
Diffstat (limited to 'tests/unit/jtty/test_jtty_messages.cpp')
| -rw-r--r-- | tests/unit/jtty/test_jtty_messages.cpp | 294 |
1 files changed, 230 insertions, 64 deletions
diff --git a/tests/unit/jtty/test_jtty_messages.cpp b/tests/unit/jtty/test_jtty_messages.cpp index 7c38dfa4..033966e4 100644 --- a/tests/unit/jtty/test_jtty_messages.cpp +++ b/tests/unit/jtty/test_jtty_messages.cpp @@ -86,10 +86,10 @@ private slots: QCOMPARE (int {movedDefault.atoms.at (0).subtype}, static_cast<int> (Jtty::CallAction::Call)); - auto const unknownPlaceholder = Jtty::compileNativeMacro ( + auto const knownSnrPlaceholder = Jtty::compileNativeMacro ( 8, QString {"599 %R"}, context); - QCOMPARE (unknownPlaceholder.status, Jtty::NativeMacroStatus::LiteralFallback); - QCOMPARE (unknownPlaceholder.text, QString {"599 %R"}); + QCOMPARE (knownSnrPlaceholder.status, Jtty::NativeMacroStatus::LiteralFallback); + QCOMPARE (knownSnrPlaceholder.text, QString {"599 -10"}); auto const editedLegacyCase = Jtty::compileNativeMacro ( 2, QString {"%h 599 %n"}, context); @@ -480,7 +480,7 @@ private slots: static_cast<int> (Jtty::ExchangeRole::FieldOnly)); } - void configuredSubsquareProducesGrid4WithoutChangingLiteralExpansion () + void configuredSubsquareProducesGrid4InBothNativeAndLiteralExpansion () { Jtty::NativeMacroContext const context { QString {"K1ABC"}, QString {"W9XYZ"}, 1, @@ -492,7 +492,7 @@ private slots: auto const literal = Jtty::compileNativeMacro (QString {"GRID %G"}, context); QCOMPARE (literal.status, Jtty::NativeMacroStatus::LiteralFallback); - QCOMPARE (literal.text, QString {"GRID fn42ab"}); + QCOMPARE (literal.text, QString {"GRID FN42"}); } void invalidGridIsRejected_data () @@ -537,7 +537,7 @@ private slots: Jtty::NativeExchangeProfile::RttyRoundup, QString {" dx "}, QString {"fn42"}}; auto const compiled = Jtty::compileNativeMacro (QString {"TEST %E %G"}, context); QCOMPARE (compiled.status, Jtty::NativeMacroStatus::LiteralFallback); - QCOMPARE (compiled.text, QString {"TEST 007 fn42"}); + QCOMPARE (compiled.text, QString {"TEST 007 FN42"}); QVERIFY (compiled.error.isEmpty ()); } @@ -546,34 +546,34 @@ private slots: QTest::addColumn<QString> ("message"); QTest::addColumn<QString> ("expected"); QTest::addColumn<bool> ("substituted"); - QTest::addColumn<bool> ("truncated"); QTest::newRow ("empty") << QString {} << QString {} - << false << false; + << false; QTest::newRow ("supported") << QString {"CQ KA1ABC CQ"} << QString {"CQ KA1ABC CQ"} - << false << false; + << false; QTest::newRow ("lowercase-preserved") << QString {"cq ka1abc cq"} << QString {"cq ka1abc cq"} - << false << false; + << false; QTest::newRow ("tab") << QString {"HELLO\tWORLD"} << QString {"HELLO#WORLD"} - << true << false; - QTest::newRow ("cr-lf") << QString {"HELLO\r\nWORLD"} << QString {"HELLO##WORLD"} - << true << false; + << true; + // '\n'/'\r' are now forced segment boundaries, not unsupported characters. + QTest::newRow ("cr-lf") << QString {"HELLO\r\nWORLD"} << QString {"HELLO\n\nWORLD"} + << false; QTest::newRow ("nul") << (QString {"A"} + QChar::Null + QString {"B"}) << QString {"A B"} - << true << false; + << true; QTest::newRow ("display-space-marker") << QString {"A~B"} << QString {"A B"} - << true << false; + << true; QTest::newRow ("exactly-80") << QString (80, QLatin1Char {'A'}) << QString (80, QLatin1Char {'A'}) - << false << false; - QTest::newRow ("truncated") << QString (81, QLatin1Char {'A'}) << QString (80, QLatin1Char {'A'}) - << false << true; + << false; + QTest::newRow ("long-input-preserved") << QString (81, QLatin1Char {'A'}) << QString (81, QLatin1Char {'A'}) + << false; QTest::newRow ("unsupported-past-limit") << (QString (80, QLatin1Char {'A'}) + QString {"\t"}) - << QString (80, QLatin1Char {'A'}) - << false << true; - QTest::newRow ("substitution-and-truncation") + << (QString (80, QLatin1Char {'A'}) + QString {"#"}) + << true; + QTest::newRow ("substitution-preserves-suffix") << (QString (79, QLatin1Char {'A'}) + QString {"\tB"}) - << (QString (79, QLatin1Char {'A'}) + QString {"#"}) - << true << true; + << (QString (79, QLatin1Char {'A'}) + QString {"#B"}) + << true; } void prepareTransmitText () @@ -581,72 +581,113 @@ private slots: QFETCH (QString, message); QFETCH (QString, expected); QFETCH (bool, substituted); - QFETCH (bool, truncated); auto const prepared = Jtty::prepareTransmitText (message); QCOMPARE (prepared.text, expected); QCOMPARE (prepared.substituted, substituted); - QCOMPARE (prepared.truncated, truncated); - QCOMPARE (prepared.changed (), substituted || truncated); - } - - void withChainedSpacing_data () - { - QTest::addColumn<QString> ("message"); - QTest::addColumn<bool> ("isChained"); - QTest::addColumn<QString> ("expected"); - - QTest::newRow ("not-chained-unchanged") << QString {"CQ KA1ABC CQ"} << false - << QString {"CQ KA1ABC CQ"}; - QTest::newRow ("chained-gets-leading-space") << QString {"TU DE KA1ABC"} << true - << QString {" TU DE KA1ABC"}; - QTest::newRow ("not-chained-empty-stays-empty") << QString {} << false << QString {}; - QTest::newRow ("chained-at-max-length-drops-last-char") - << QString (Jtty::maxTransmitLength, QLatin1Char {'A'}) << true - << (QString {" "} + QString (Jtty::maxTransmitLength - 1, QLatin1Char {'A'})); - } - - void withChainedSpacing () - { - QFETCH (QString, message); - QFETCH (bool, isChained); - QFETCH (QString, expected); - - QCOMPARE (Jtty::withChainedSpacing (message, isChained), expected); } void transmitFrame_data () { QTest::addColumn<QString> ("message"); - QTest::addColumn<bool> ("isChained"); QTest::addColumn<QString> ("expected"); auto const padded = [] (QString const& text) { return text + QString (Jtty::maxTransmitLength - text.size (), QLatin1Char {' '}); }; - QTest::newRow ("not-chained-padded-to-width") - << QString {"CQ KA1ABC CQ"} << false << padded (QString {"CQ KA1ABC CQ"}); - QTest::newRow ("chained-prefixed-and-padded") - << QString {"TU K1ABC CQ"} << true << padded (QString {" TU K1ABC CQ"}); - QTest::newRow ("chained-at-max-length-stays-exact") - << QString (Jtty::maxTransmitLength, QLatin1Char {'A'}) << true - << (QString {" "} + QString (Jtty::maxTransmitLength - 1, QLatin1Char {'A'})); - QTest::newRow ("empty-not-chained-all-spaces") - << QString {} << false << QString (Jtty::maxTransmitLength, QLatin1Char {' '}); + QTest::newRow ("padded-to-width") + << QString {"CQ KA1ABC CQ"} << padded (QString {"CQ KA1ABC CQ"}); + QTest::newRow ("at-max-length-stays-exact") + << QString (Jtty::maxTransmitLength, QLatin1Char {'A'}) + << QString (Jtty::maxTransmitLength, QLatin1Char {'A'}); + QTest::newRow ("empty-all-spaces") + << QString {} << QString (Jtty::maxTransmitLength, QLatin1Char {' '}); + QTest::newRow ("oversized-rejected") + << QString (Jtty::maxTransmitLength + 1, QLatin1Char {'A'}) << QString {}; } void transmitFrame () { QFETCH (QString, message); - QFETCH (bool, isChained); QFETCH (QString, expected); - QString const frame = Jtty::transmitFrame (message, isChained); + QString const frame = Jtty::transmitFrame (message); QCOMPARE (frame, expected); - QCOMPARE (frame.size (), Jtty::maxTransmitLength); + QCOMPARE (frame.size (), message.size () > Jtty::maxTransmitLength + ? 0 : Jtty::maxTransmitLength); + } + + void transmitSegmentsCoverCompleteInput_data () + { + QTest::addColumn<QString> ("source"); + QTest::addColumn<int> ("firstLength"); + QTest::addColumn<int> ("segmentCount"); + + QTest::newRow ("79-characters") << QString (79, QLatin1Char {'A'}) << 79 << 1; + QTest::newRow ("80-characters") << QString (80, QLatin1Char {'A'}) << 80 << 1; + QTest::newRow ("81-characters") << QString (81, QLatin1Char {'A'}) << 80 << 2; + QTest::newRow ("word-boundary") + << (QString (70, QLatin1Char {'A'}) + QString {" WORDS CONTINUE"}) << 77 << 2; + QTest::newRow ("space-at-capacity") + << (QString (79, QLatin1Char {'A'}) + QString {" SUFFIX"}) << 80 << 2; + QTest::newRow ("space-after-capacity") + << (QString {"FIRST "} + QString (74, QLatin1Char {'A'}) + QString {" SUFFIX"}) + << 80 << 2; + QTest::newRow ("leading-space-before-long-token") + << (QString {" "} + QString (160, QLatin1Char {'A'})) << 80 << 3; + QTest::newRow ("many-spaces") << QString (200, QLatin1Char {' '}) << 80 << 3; + QTest::newRow ("substitution-after-first-segment") + << (QString (80, QLatin1Char {'A'}) + QString {"\tSUFFIX"}) << 80 << 2; + } + + void transmitSegmentsCoverCompleteInput () + { + QFETCH (QString, source); + QFETCH (int, firstLength); + QFETCH (int, segmentCount); + + QString const prepared = Jtty::prepareTransmitText (source).text; + QString reconstructed; + int offset {0}; + int count {0}; + while (offset < prepared.size ()) { + auto const segment = Jtty::nextTransmitTextSegment (prepared, offset); + QCOMPARE (segment.offset, offset); + QVERIFY (segment.length > 0); + QVERIFY (segment.length <= Jtty::maxTransmitLength); + QCOMPARE (segment.text, prepared.mid (offset, segment.length)); + if (count == 0) QCOMPARE (segment.length, firstLength); + reconstructed += segment.text; + offset += segment.length; + ++count; + } + QCOMPARE (count, segmentCount); + QCOMPARE (reconstructed, prepared); + } + + void transmitSegmentRetryRetainsSourceOffset () + { + QString const source {"PREFIX FIRST SECOND THIRD SUFFIX"}; + auto const initial = Jtty::nextTransmitTextSegment (source, 7, 19); + QCOMPARE (initial.text, QString {"FIRST SECOND THIRD "}); + auto const retry = Jtty::nextTransmitTextSegment (source, initial.offset, 12); + QCOMPARE (retry.offset, initial.offset); + QCOMPARE (retry.text, QString {"FIRST SECOND"}); + auto const next = Jtty::nextTransmitTextSegment (source, retry.offset + retry.length); + QCOMPARE (retry.text + next.text, source.mid (7)); + } + + void transmitSegmentEmptyAndInvalidRanges () + { + QVERIFY (Jtty::nextTransmitTextSegment (QString {}, 0).text.isEmpty ()); + QVERIFY (Jtty::nextTransmitTextSegment (QString {"ABC"}, -1).text.isEmpty ()); + QVERIFY (Jtty::nextTransmitTextSegment (QString {"ABC"}, 3).text.isEmpty ()); + QVERIFY (Jtty::nextTransmitTextSegment (QString {"ABC"}, 0, 0).text.isEmpty ()); + QCOMPARE (Jtty::nextTransmitTextSegment (QString (100, QLatin1Char {'A'}), 0, 100).length, + Jtty::maxTransmitLength); } void wavCaptureValid_data () @@ -746,6 +787,13 @@ private slots: QCOMPARE (Jtty::jttyLineTimeLabel (QDateTime {}), QString {}); } + void formatJttyTxLineLeavesSnrColumnBlank () + { + QCOMPARE (Jtty::formatJttyTxLine (1500.f, QString {"CQ K1ABC CQ"}), + QString {"1500 CQ K1ABC CQ"}); + QCOMPARE (Jtty::formatJttyTxLine (1500.4f, QString {}), QString {"1500 "}); + } + void parseDecodeLine_data () { QTest::addColumn<QString> ("line"); @@ -816,6 +864,39 @@ private slots: QCOMPARE (Jtty::wrapMessage (text), expected); } + void formatJttyDecodeLine_data () + { + QTest::addColumn<float> ("frequency"); + QTest::addColumn<int> ("snr"); + QTest::addColumn<QString> ("message"); + QTest::addColumn<QString> ("expected"); + + QTest::newRow ("negative-two-digit-snr") + << 1513.f << -10 << QString {"CQ VA7TTO CQ"} + << QString {"1513 -10 CQ VA7TTO CQ"}; + QTest::newRow ("positive-snr-no-forced-sign") + << 1500.f << 5 << QString {"K1ABC W9XYZ"} + << QString {"1500 5 K1ABC W9XYZ"}; + QTest::newRow ("three-digit-frequency-padded") + << 500.f << 0 << QString {"HELLO"} + << QString {" 500 0 HELLO"}; + QTest::newRow ("multi-digit-snr") + << 1500.f << -100 << QString {"WEAK"} + << QString {"1500 -100 WEAK"}; + QTest::newRow ("empty-message-omits-snr") + << 1500.f << -10 << QString {} << QString {"1500"}; + } + + void formatJttyDecodeLine () + { + QFETCH (float, frequency); + QFETCH (int, snr); + QFETCH (QString, message); + QFETCH (QString, expected); + + QCOMPARE (Jtty::formatJttyDecodeLine (frequency, snr, message), expected); + } + void compareMessagesTracksMessageSemantics () { auto const unchanged = Jtty::compareMessages ( @@ -932,6 +1013,91 @@ private slots: QVERIFY (!Jtty::shouldApplyToQsoHistory (false, 1505.f, 1500.f, 5.f)); QVERIFY (Jtty::shouldApplyToQsoHistory (true, 1510.f, 1500.f, 5.f)); } + + void snrFormattingHasLeadingSignAndZeroPad () + { + QCOMPARE (Jtty::formatSnr (-10), QString {"-10"}); + QCOMPARE (Jtty::formatSnr (5), QString {"+05"}); + QCOMPARE (Jtty::formatSnr (-5), QString {"-05"}); + QCOMPARE (Jtty::formatSnr (0), QString {"+00"}); + QCOMPARE (Jtty::formatSnr (100), QString {"+100"}); + } + + void ft8StyleTemplatesMatchSpec () + { + QCOMPARE (Jtty::ft8StyleMacroTemplate (1), QString {"%H %M %G"}); + QCOMPARE (Jtty::ft8StyleMacroTemplate (2), QString {"%H %M %R"}); + QCOMPARE (Jtty::ft8StyleMacroTemplate (3), QString {"%H %M R%R"}); + QCOMPARE (Jtty::ft8StyleMacroTemplate (4), QString {"%H %M RRR"}); + QCOMPARE (Jtty::ft8StyleMacroTemplate (5), QString {"%H %M 73"}); + QCOMPARE (Jtty::ft8StyleMacroTemplate (6), QString {"CQ %M %G"}); + QVERIFY (Jtty::ft8StyleMacroTemplate (7).isEmpty ()); + QVERIFY (Jtty::ft8StyleMacroTemplate (8).isEmpty ()); + } + + void ft8StyleLiteralExpansionSubstitutesGridAndSnr () + { + // %G's own truncate-to-4 behavior for extended subsquare grids is covered + // separately by configuredSubsquareProducesGrid4InBothNativeAndLiteralExpansion; + // a plain 4-char grid here keeps this test focused on the %R substitution. + Jtty::NativeMacroContext context {QString {"K1ABC"}, QString {"W9XYZ"}, 0}; + context.grid = QStringLiteral ("FN20"); + context.snr = -7; + + QCOMPARE (Jtty::expandLiteralMacro (Jtty::ft8StyleMacroTemplate (1), context), + QString {"W9XYZ K1ABC FN20"}); + QCOMPARE (Jtty::expandLiteralMacro (Jtty::ft8StyleMacroTemplate (2), context), + QString {"W9XYZ K1ABC -07"}); + QCOMPARE (Jtty::expandLiteralMacro (Jtty::ft8StyleMacroTemplate (3), context), + QString {"W9XYZ K1ABC R-07"}); + QCOMPARE (Jtty::expandLiteralMacro (Jtty::ft8StyleMacroTemplate (6), context), + QString {"CQ K1ABC FN20"}); + } + + void messageStyleHelpersDistinguishContestAndFt8 () + { + QCOMPARE (Jtty::messageStyleSettingsKey (Jtty::MessageStyle::Contest, 3), + QString {"JTTY_msg3"}); + QCOMPARE (Jtty::messageStyleSettingsKey (Jtty::MessageStyle::Ft8, 3), + QString {"JTTY_FT8_msg3"}); + QCOMPARE (Jtty::messageStyleDefaultTemplate (Jtty::MessageStyle::Contest, 1), + Jtty::nativeMacroTemplate (1)); + QCOMPARE (Jtty::messageStyleDefaultTemplate (Jtty::MessageStyle::Ft8, 1), + Jtty::ft8StyleMacroTemplate (1)); + } + + void fillerTextIsRecognizedStandalone () + { + QVERIFY (Jtty::isJttyFillerText (Jtty::jttyFillerText)); + QVERIFY (Jtty::isJttyFillerText (QStringLiteral ("<<<<<"))); + QVERIFY (!Jtty::isJttyFillerText (QString {})); + QVERIFY (!Jtty::isJttyFillerText (QStringLiteral ("FOX"))); + QVERIFY (!Jtty::isJttyFillerText (QStringLiteral ("FOX <<<<<"))); + } + + void fillerStripLeavesRealTextUnaffected () + { + QCOMPARE (Jtty::stripJttyFillerText (QStringLiteral ("FOX JUMPED OVER")), + QStringLiteral ("FOX JUMPED OVER")); + } + + void fillerStripRemovesEmbeddedRunRegardlessOfSpacing () + { + // Squished with no separator, as a receiver could decode if neither side's own packing added a boundary space. + QCOMPARE (Jtty::stripJttyFillerText (QStringLiteral ("OVER<<<<< <<<<<THE")), + QStringLiteral ("OVER THE")); + // Normally spaced. + QCOMPARE (Jtty::stripJttyFillerText (QStringLiteral ("OVER <<<<< <<<<< THE")), + QStringLiteral ("OVER THE")); + // Only the first filler frame has arrived so far (message still growing). + QCOMPARE (Jtty::stripJttyFillerText (QStringLiteral ("OVER <<<<<")), + QStringLiteral ("OVER")); + } + + void fillerStripOfPureFillerIsEmpty () + { + QVERIFY (Jtty::stripJttyFillerText (Jtty::jttyFillerText).isEmpty ()); + } }; QTEST_MAIN (TestJttyMessages) |
