diff options
| author | Christoph Berg <myon@debian.org> | 2026-10-09 14:12:49 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-10-09 14:12:49 +0200 |
| commit | 76956486fa7ef52a51d4e56df1e13a9f19a6c93c (patch) | |
| tree | fe0c394439fdc167d1970372e8998874090854dd /tests/unit/streaming/test_streaming_consumers.cpp | |
| parent | 0685fcada9f95fe90f70b387cd7d757da8209624 (diff) | |
| parent | ffc62c792c9a5196cb4ce7a353287dfe20db6524 (diff) | |
Update upstream source from tag 'upstream/3.3.0_beta1+dfsg'
Update to upstream version '3.3.0~beta1+dfsg'
with Debian dir 85037bbb9376721108594b59b54ead82ac6924a3
Diffstat (limited to 'tests/unit/streaming/test_streaming_consumers.cpp')
| -rw-r--r-- | tests/unit/streaming/test_streaming_consumers.cpp | 199 |
1 files changed, 175 insertions, 24 deletions
diff --git a/tests/unit/streaming/test_streaming_consumers.cpp b/tests/unit/streaming/test_streaming_consumers.cpp index ba605fe1..91ed0e2e 100644 --- a/tests/unit/streaming/test_streaming_consumers.cpp +++ b/tests/unit/streaming/test_streaming_consumers.cpp @@ -1,16 +1,20 @@ #include <limits> +#include <cmath> #include <QJsonDocument> +#include <QFile> #include <QJsonObject> #include <QProcess> #include <QTemporaryDir> #include <QtTest> +#include <QtEndian> namespace { constexpr quint32 Jt9AudioCapacityBytes = 30u * 60u * 12000u * 2u; constexpr quint32 WsprdAudioCapacityBytes = 8u * 114u * 12000u * 2u; -constexpr int Ft4PeriodSamples = 21 * 3456; +// FT4's 7.5 s period at 12 kHz. +constexpr int Ft4PeriodSamples = 90000; constexpr int Jt9TenSecondPeriodSamples = 10 * 12000; struct ProcessResult @@ -158,16 +162,6 @@ ParsedEvents parseEvents (QByteArray const& output) return parsed; } } - if (type == "warning" && - (!event.value ("code").isString () || - event.value ("code").toString ().isEmpty () || - !event.value ("discarded_samples").isDouble () || - event.value ("discarded_samples").toDouble () < 0.0)) - { - parsed.error = QString {"invalid warning event: %1"}.arg ( - QString::fromUtf8 (line)); - return parsed; - } parsed.values.append (event); } return parsed; @@ -244,6 +238,128 @@ class TestStreamingConsumers final : public QObject Q_OBJECT private slots: + void fst4DecodesWaveform_data () + { + QTest::addColumn<QString> ("mode"); + QTest::addColumn<QString> ("path"); + QTest::addColumn<int> ("period"); + QTest::addColumn<QString> ("message"); + QTest::newRow ("fst4-15") << QString {"FST4"} << QString::fromUtf8 (FST4_ENGINE_WAV) + << 15 << QString {"K1ABC W9XYZ FN42"}; + QTest::newRow ("fst4w-120") << QString {"FST4W"} << QString::fromUtf8 (FST4W_ENGINE_WAV) + << 120 << QString {"K1ABC FN42 37"}; + } + + void fst4DecodesWaveform () + { + QFETCH (QString, mode); + QFETCH (QString, path); + QFETCH (int, period); + QFETCH (QString, message); + QFile recording {path}; + QVERIFY2 (recording.open (QIODevice::ReadOnly), qPrintable (recording.errorString ())); + auto const wav = recording.readAll (); + QCOMPARE (wav.size (), 44 + period * 12000 * 2); + QCOMPARE (wav.left (4), QByteArray {"RIFF"}); + QCOMPARE (wav.mid (36, 4), QByteArray {"data"}); + QJsonObject configuration {{"t", "configure"}, {"mode", mode}, {"trperiod", period}, + {"depth_level", 1}, {"nfa", 1300}, {"nfb", 1700}, {"rxfreq", 1500}, + {"noise_blanker_level", 0}, {"utc", "00:15:00"}}; + QTemporaryDir directory; + QVERIFY (directory.isValid ()); + auto const input = sessionHeader () + controlFrame ( + QJsonDocument {configuration}.toJson (QJsonDocument::Compact)) + frame (0x01u, wav.mid (44)); + auto const result = runProcess (QString::fromUtf8 (JT9_EXECUTABLE), + {"-a", directory.path (), "-t", directory.path (), "--stream"}, input, directory.path (), 360000); + verifyCompleted (result, 0); + auto const events = verifyEvents (result); + QCOMPARE (eventsMatching (events.values, "error").size (), 0); + bool found = false; + for (auto const& decode : eventsMatching (events.values, "decode")) + { + QCOMPARE (decode.value ("mode").toString (), QString {"FST4"}); + found |= decode.value ("message").toString ().trimmed () == message; + } + QVERIFY2 (found, result.standardOutput.constData ()); + QCOMPARE (eventsMatching (events.values, "decode_finished").size (), 1); + } + + void fst4PartialEofCompletesOnce () + { + QTemporaryDir directory; + QVERIFY (directory.isValid ()); + auto const input = sessionHeader () + controlFrame ( + R"({"t":"configure","mode":"FST4W","trperiod":120,"depth_level":1,"nutc":15})") + + silentAudioFrame (12001); + auto const result = runProcess (QString::fromUtf8 (JT9_EXECUTABLE), + {"-a", directory.path (), "-t", directory.path (), "--stream"}, input, directory.path ()); + verifyCompleted (result, 0); + auto const events = verifyEvents (result); + QCOMPARE (eventsMatching (events.values, "error").size (), 0); + QCOMPARE (eventsMatching (events.values, "decode").size (), 0); + auto const completions = eventsMatching (events.values, "decode_finished"); + QCOMPARE (completions.size (), 1); + QCOMPARE (completions.first ().value ("period_end").toString (), QString {"001500"}); + } + + void q65DecodesWaveform () + { + QFile recording {QString::fromUtf8 (Q65_ENGINE_WAV)}; + QVERIFY2 (recording.open (QIODevice::ReadOnly), qPrintable (recording.errorString ())); + auto const wav = recording.readAll (); + constexpr quint32 sampleBytes = 15 * 12000 * 2; + QCOMPARE (wav.size (), int (44 + sampleBytes)); + QCOMPARE (wav.left (4), QByteArray {"RIFF"}); + QCOMPARE (wav.mid (8, 8), QByteArray {"WAVEfmt "}); + QCOMPARE (qFromLittleEndian<quint32> (wav.constData () + 16), quint32 (16)); + QCOMPARE (qFromLittleEndian<quint16> (wav.constData () + 20), quint16 (1)); + QCOMPARE (qFromLittleEndian<quint16> (wav.constData () + 22), quint16 (1)); + QCOMPARE (qFromLittleEndian<quint32> (wav.constData () + 24), quint32 (12000)); + QCOMPARE (qFromLittleEndian<quint16> (wav.constData () + 34), quint16 (16)); + QCOMPARE (wav.mid (36, 4), QByteArray {"data"}); + QCOMPARE (qFromLittleEndian<quint32> (wav.constData () + 40), sampleBytes); + + QTemporaryDir directory; + QVERIFY (directory.isValid ()); + auto const input = sessionHeader () + controlFrame ( + R"({"t":"configure","mode":"Q65","trperiod":15,"submode":0,"depth_level":1,"nfa":1300,"nfb":1700,"rxfreq":1500,"utc":"00:15:00"})") + + frame (0x01u, wav.mid (44)) + controlFrame (R"({"t":"halt"})"); + auto const result = runProcess (QString::fromUtf8 (JT9_EXECUTABLE), + {"-a", directory.path (), "-t", directory.path (), "--stream"}, input, directory.path ()); + verifyCompleted (result, 0); + auto const events = verifyEvents (result); + QCOMPARE (eventsMatching (events.values, "error").size (), 0); + auto const decodes = eventsMatching (events.values, "decode"); + QVERIFY2 (!decodes.isEmpty (), result.standardOutput.constData ()); + bool found = false; + for (auto const& decode : decodes) + { + QCOMPARE (decode.value ("mode").toString (), QString {"Q65"}); + QCOMPARE (decode.value ("time").toString (), QString {"001500"}); + found |= decode.value ("message").toString ().trimmed () == "K1ABC W9XYZ FN42"; + } + QVERIFY2 (found, result.standardOutput.constData ()); + auto const completions = eventsMatching (events.values, "decode_finished"); + QCOMPARE (completions.size (), 1); + QCOMPARE (completions.first ().value ("period_end").toString (), QString {"001500"}); + + QFile curves {directory.filePath ("red.dat")}; + QVERIFY2 (curves.open (QIODevice::ReadOnly), qPrintable (curves.errorString ())); + auto const rows = curves.readAll ().trimmed ().split ('\n'); + QVERIFY (rows.size () > 1); + for (auto const& row : rows) + { + auto const values = row.simplified ().split (' '); + QCOMPARE (values.size (), 3); + for (auto const& value : values) + { + bool ok; + auto const number = value.toDouble (&ok); + QVERIFY (ok && std::isfinite (number)); + } + } + } + void jt9RejectsOversizedFrames_data () { QTest::addColumn<quint32> ("declaredLength"); @@ -280,10 +396,8 @@ private slots: verifyCompleted (result, 0); auto const events = verifyEvents (result); QCOMPARE (eventsMatching (events.values, "error", "unknown_mode").size (), 1); - auto const warnings = eventsMatching ( - events.values, "warning", "period_boundary_discard"); - QCOMPARE (warnings.size (), 1); - QCOMPARE (warnings.front ().value ("discarded_samples").toInt (), 2); + // The two samples past the 10 s period open the next period, drained at EOF. + QCOMPARE (eventsMatching (events.values, "decode_finished").size (), 2); } void jt9RejectsOutOfRangeTrperiod_data () @@ -306,22 +420,59 @@ private slots: QCOMPARE (eventsMatching (events.values, "decode").size (), 0); } - void jt9ReportsBoundaryDiscardOnce () + // A straddling frame carries its remainder into the next period. + void jt9CarriesStraddlingFrameIntoNextPeriod () { auto const exact = runJt9 (sessionHeader () + silentAudioFrame (Ft4PeriodSamples), {"--ft4"}); verifyCompleted (exact, 0); auto const exactEvents = verifyEvents (exact); - QCOMPARE (eventsMatching (exactEvents.values, "warning").size (), 0); + QCOMPARE (eventsMatching (exactEvents.values, "decode_finished").size (), 1); - auto const overflow = runJt9 ( + auto const straddle = runJt9 ( sessionHeader () + silentAudioFrame (Ft4PeriodSamples + 2), {"--ft4"}); - verifyCompleted (overflow, 0); - auto const overflowEvents = verifyEvents (overflow); - auto const warnings = eventsMatching ( - overflowEvents.values, "warning", "period_boundary_discard"); - QCOMPARE (warnings.size (), 1); - QCOMPARE (warnings.front ().value ("discarded_samples").toInt (), 2); + verifyCompleted (straddle, 0); + auto const straddleEvents = verifyEvents (straddle); + QCOMPARE (eventsMatching (straddleEvents.values, "decode_finished").size (), 2); + + // The decoder's share alone is not a period; the EOF drain reports it. + auto const decoderOnly = runJt9 ( + sessionHeader () + silentAudioFrame (21 * 3456), {"--ft4"}); + verifyCompleted (decoderOnly, 0); + auto const decoderOnlyEvents = verifyEvents (decoderOnly); + QCOMPARE (eventsMatching (decoderOnlyEvents.values, "decode_finished").size (), 1); + } + + // A configure that changes the period starts a new one; nothing of the + // old period drains at the new length. + void jt9StartsANewPeriodOnATrperiodChange () + { + // Half a 10 s period, a change to 20 s, then exactly one 20 s period. + auto const result = runJt9 ( + sessionHeader () + + controlFrame (R"({"t":"configure","trperiod":10})") + + silentAudioFrame (Jt9TenSecondPeriodSamples / 2) + + controlFrame (R"({"t":"configure","trperiod":20})") + + silentAudioFrame (2 * Jt9TenSecondPeriodSamples), {"-9"}); + verifyCompleted (result, 0); + auto const events = verifyEvents (result); + QCOMPARE (eventsMatching (events.values, "decode_finished").size (), 1); + } + + // Repeating the current configuration mid-period leaves the period alone. + void jt9KeepsThePeriodOnAnUnchangedConfigure () + { + // Half a 10 s period, the same configuration again, then the other half + // plus two samples: one full period, and the two samples open the next. + auto const result = runJt9 ( + sessionHeader () + + controlFrame (R"({"t":"configure","mode":"JT9","trperiod":10})") + + silentAudioFrame (Jt9TenSecondPeriodSamples / 2) + + controlFrame (R"({"t":"configure","mode":"JT9","trperiod":10})") + + silentAudioFrame (Jt9TenSecondPeriodSamples / 2 + 2), {"-9"}); + verifyCompleted (result, 0); + auto const events = verifyEvents (result); + QCOMPARE (eventsMatching (events.values, "decode_finished").size (), 2); } void wsprdRejectsOversizedFrames_data () |
