diff options
Diffstat (limited to 'tests/unit/jtty')
| -rw-r--r-- | tests/unit/jtty/jtty_cpp_n1mm_smoke.cpp | 37 | ||||
| -rw-r--r-- | tests/unit/jtty/test_jtty_messages.cpp | 48 | ||||
| -rw-r--r-- | tests/unit/jtty/test_jtty_structured_decode.f90 | 29 |
3 files changed, 114 insertions, 0 deletions
diff --git a/tests/unit/jtty/jtty_cpp_n1mm_smoke.cpp b/tests/unit/jtty/jtty_cpp_n1mm_smoke.cpp index c2b3b45b..25fa54b0 100644 --- a/tests/unit/jtty/jtty_cpp_n1mm_smoke.cpp +++ b/tests/unit/jtty/jtty_cpp_n1mm_smoke.cpp @@ -80,3 +80,40 @@ extern "C" int jtty_cpp_rtty_smoke (int tones[], int* nsym) } return status; } + +extern "C" int jtty_cpp_rtty_line_refused () +{ + // 80 characters; RTTY Roundup writes the serial as 005, which makes it 81. + QString const line = QString (73, QLatin1Char {'A'}) + QStringLiteral (" 599 05"); + auto encodesWith = [] (Jtty::NativeExchangeProfile exchange) { + return [profile = static_cast<int> (exchange)] (QString const& text) { + auto frame = Jtty::transmitFrame (text).toLatin1 (); + std::array<int, 16 * 59> tones {}; + std::array<int, 16> frameStarts {}; + int symbols {}; + int const isFinal = 0; + genjtty_profile_ (frame.data (), &profile, tones.data (), &symbols, + frameStarts.data (), &isFinal, frame.size ()); + return symbols > 0; + }; + }; + auto const rtty = Jtty::encodeTransmitLine (line, encodesWith (Jtty::NativeExchangeProfile::RttyRoundup)); + auto const none = Jtty::encodeTransmitLine (line, encodesWith (Jtty::NativeExchangeProfile::None)); + return !rtty && none && none->size () == 1; +} + +extern "C" int jtty_cpp_rtty_line_tones (int tones[], int* nsym) +{ + // 79 characters; with the serial written as 005 it is exactly 80. + QString const line = QString (72, QLatin1Char {'A'}) + QStringLiteral (" 599 05"); + int const profile = static_cast<int> (Jtty::NativeExchangeProfile::RttyRoundup); + auto encode = [&] (QString const& text, int isFinal) { + auto frame = Jtty::transmitFrame (text).toLatin1 (); + std::array<int, 16> frameStarts {}; + *nsym = 0; + genjtty_profile_ (frame.data (), &profile, tones, nsym, frameStarts.data (), &isFinal, frame.size ()); + return *nsym > 0; + }; + auto const segments = Jtty::encodeTransmitLine (line, [&] (QString const& text) { return encode (text, 0); }); + return segments && segments->size () == 1 && encode (segments->front ().text, 1); +} diff --git a/tests/unit/jtty/test_jtty_messages.cpp b/tests/unit/jtty/test_jtty_messages.cpp index 033966e4..f877e1a0 100644 --- a/tests/unit/jtty/test_jtty_messages.cpp +++ b/tests/unit/jtty/test_jtty_messages.cpp @@ -2,6 +2,16 @@ #include "widgets/JttyMessages.hpp" +namespace +{ + // 121 characters: two transmit segments. + QString longLine () + { + return QStringLiteral ("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG AND KEEPS RUNNING ACROSS THE FIELD" + " UNTIL IT REACHES THE OLD BARN BY THE RIVER"); + } +} + class TestJttyMessages final : public QObject { @@ -690,6 +700,44 @@ private slots: Jtty::maxTransmitLength); } + void encodeTransmitLineRefusesRatherThanShortens () + { + QString const line = QString (73, QLatin1Char {'A'}) + QStringLiteral (" 599 05"); + QStringList attempts; + auto const encoded = Jtty::encodeTransmitLine (line, [&] (QString const& text) { + attempts << text; + return text.size () < line.size (); + }); + QVERIFY (!encoded); + QCOMPARE (attempts, QStringList {line}); + + QStringList cuts; + auto const laterSegmentFails = Jtty::encodeTransmitLine (longLine (), [&] (QString const& text) { + cuts << text; + return cuts.size () < 2; + }); + QVERIFY (!laterSegmentFails); + QCOMPARE (cuts.size (), 2); + QCOMPARE (cuts.join (QString {}), longLine ()); + } + + void encodeTransmitLineKeepsTheSegmentCuts () + { + QString const line = longLine (); + QStringList attempts; + auto const encoded = Jtty::encodeTransmitLine (line, [&] (QString const& text) { + attempts << text; + return true; + }); + QVERIFY (encoded); + QCOMPARE (encoded->size (), 2); + QCOMPARE (attempts, (QStringList {encoded->at (0).text, encoded->at (1).text})); + QCOMPARE (encoded->at (0).text + encoded->at (1).text, line); + auto const blank = Jtty::encodeTransmitLine (QString (5, QLatin1Char {' '}), + [] (QString const&) { return false; }); + QVERIFY (blank && blank->isEmpty ()); + } + void wavCaptureValid_data () { QTest::addColumn<qint32> ("k0"); diff --git a/tests/unit/jtty/test_jtty_structured_decode.f90 b/tests/unit/jtty/test_jtty_structured_decode.f90 index 6a55a816..56f9256a 100644 --- a/tests/unit/jtty/test_jtty_structured_decode.f90 +++ b/tests/unit/jtty/test_jtty_structured_decode.f90 @@ -37,6 +37,15 @@ program test_jtty_structured_decode integer(c_int), intent(out) :: tones(*),nsym integer(c_int) :: status end function jtty_cpp_rtty_smoke + function jtty_cpp_rtty_line_refused() result(refused) bind(C) + import :: c_int + integer(c_int) :: refused + end function jtty_cpp_rtty_line_refused + function jtty_cpp_rtty_line_tones(tones,nsym) result(planned) bind(C) + import :: c_int + integer(c_int), intent(out) :: tones(*),nsym + integer(c_int) :: planned + end function jtty_cpp_rtty_line_tones subroutine genjtty_atoms(atoms,natoms,itone,nsym) use jtty_mod, only: jtty_source_atom type(jtty_source_atom), intent(in) :: atoms(:) @@ -63,6 +72,9 @@ program test_jtty_structured_decode call decode_cpp_compiled_n1mm(failures) call decode_compact_text(failures) call decode_profile_text(failures) + call expect(jtty_cpp_rtty_line_refused().eq.1, & + 'an RTTY line whose serial does not fit is refused, not split',failures) + call decode_accepted_rtty_line(failures) if(failures.ne.0) then write(*,'(a,i0)') 'test_jtty_structured_decode: failures=',failures @@ -351,6 +363,23 @@ contains deallocate(pcm,wave,complex_wave) end subroutine decode_waveform + subroutine decode_accepted_rtty_line(count) + integer, intent(inout) :: count + integer(c_int) :: tones(MAX_FRAMES*frame_symbols),nsymbols + character(len=80) :: expected + + expected=repeat('A',72)//' 599 005' + call expect(jtty_cpp_rtty_line_tones(tones,nsymbols).eq.1, & + 'the longest RTTY line that fits is one segment',count) + if(nsymbols.le.0) return + call decode_waveform(tones,int(nsymbols)) + call expect(npending.ge.1,'the accepted RTTY line produces updates',count) + if(npending.lt.1) return + call expect(trim(normalized(pending_updates(npending)%decoded)).eq.trim(expected) .and. & + pending_updates(npending)%complete .and. nactive.eq.0, & + 'the accepted RTTY line arrives whole, serial included',count) + end subroutine decode_accepted_rtty_line + function normalized(value) result(result_value) character(len=*), intent(in) :: value character(len=80) :: result_value |
