diff options
| author | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:03 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:03 +0200 |
| commit | 059831534c7e884f0a607ed86b582fd00d821731 (patch) | |
| tree | 76bcb67a78f8aa2654fd34c2ad801a62136b0170 /tests/unit/qmap | |
| parent | d83a420f0517d7fc47aeb288a6a0cf4891784fcc (diff) | |
New upstream version 3.2.0~rc1+dfsgupstream/3.2.0_rc1+dfsg
Diffstat (limited to 'tests/unit/qmap')
| -rw-r--r-- | tests/unit/qmap/CMakeLists.txt | 45 | ||||
| -rw-r--r-- | tests/unit/qmap/test_decode_click_coalescer.cpp | 95 | ||||
| -rw-r--r-- | tests/unit/qmap/test_livecq_parser.cpp | 84 | ||||
| -rw-r--r-- | tests/unit/qmap/test_plotter_initialization.cpp | 127 | ||||
| -rw-r--r-- | tests/unit/qmap/test_qmap_decode_record.cpp | 97 | ||||
| -rw-r--r-- | tests/unit/qmap/test_qmap_ipc.cpp | 98 |
6 files changed, 546 insertions, 0 deletions
diff --git a/tests/unit/qmap/CMakeLists.txt b/tests/unit/qmap/CMakeLists.txt new file mode 100644 index 00000000..0d0b73ac --- /dev/null +++ b/tests/unit/qmap/CMakeLists.txt @@ -0,0 +1,45 @@ +add_executable (test_qmap_livecq_parser + test_livecq_parser.cpp + ${CMAKE_SOURCE_DIR}/qmap/livecq_parser.cpp + ${CMAKE_SOURCE_DIR}/validators/LiveCQCallsign.cpp +) +target_link_libraries (test_qmap_livecq_parser Qt5::Test) +add_test (NAME test_qmap_livecq_parser COMMAND test_qmap_livecq_parser) + +add_executable (test_qmap_plotter_initialization + test_plotter_initialization.cpp + ${CMAKE_SOURCE_DIR}/qmap/decode_click_coalescer.cpp + ${CMAKE_SOURCE_DIR}/qmap/plotter.cpp +) +target_link_libraries (test_qmap_plotter_initialization + wsjt_qt + qmap_impl + ${FFTW3_LIBRARIES} + Qt5::Test + Qt5::Widgets +) +add_test (NAME test_qmap_plotter_initialization COMMAND test_qmap_plotter_initialization) +if (WIN32) + set_tests_properties (test_qmap_plotter_initialization PROPERTIES + ENVIRONMENT "QT_QPA_PLATFORM=windows" + ) +else () + set_tests_properties (test_qmap_plotter_initialization PROPERTIES + ENVIRONMENT "QT_QPA_PLATFORM=offscreen" + ) +endif () + +add_executable (test_qmap_ipc test_qmap_ipc.cpp) +target_link_libraries (test_qmap_ipc Qt5::Test) +add_test (NAME test_qmap_ipc COMMAND test_qmap_ipc) + +add_executable (test_qmap_decode_record test_qmap_decode_record.cpp) +target_link_libraries (test_qmap_decode_record wsjt_qt wsjt_fort_common Qt5::Test) +add_test (NAME test_qmap_decode_record COMMAND test_qmap_decode_record) + +add_executable (test_qmap_decode_click_coalescer + test_decode_click_coalescer.cpp + ${CMAKE_SOURCE_DIR}/qmap/decode_click_coalescer.cpp +) +target_link_libraries (test_qmap_decode_click_coalescer Qt5::Test Qt5::Widgets) +add_test (NAME test_qmap_decode_click_coalescer COMMAND test_qmap_decode_click_coalescer) diff --git a/tests/unit/qmap/test_decode_click_coalescer.cpp b/tests/unit/qmap/test_decode_click_coalescer.cpp new file mode 100644 index 00000000..284aa5e5 --- /dev/null +++ b/tests/unit/qmap/test_decode_click_coalescer.cpp @@ -0,0 +1,95 @@ +#include <QtTest> + +#include "qmap/decode_click_coalescer.h" +#include "qmap/qmap_click_policy.h" + +class TestDecodeClickCoalescer final : public QObject +{ + Q_OBJECT + +private slots: + void disarmsBeforeSingleClick(); + void coalescesUpdatedRecordByIdentity(); + void keepsDifferentRecordsSeparate(); + void protectsDoubleClickWhenDisarmIsOverwritten(); +}; + +namespace +{ + struct DispatchEvent + { + QByteArray row; + DecodeClickGesture gesture; + }; +} + +void TestDecodeClickCoalescer::disarmsBeforeSingleClick() +{ + QList<DispatchEvent> dispatched; + DecodeClickCoalescer coalescer {this, [&dispatched] (QByteArray const& row, + DecodeClickGesture gesture) { + dispatched.append ({row, gesture}); + }, 20}; + + coalescer.press ("K1ABC", "first"); + QCOMPARE (dispatched.size (), 1); + QVERIFY (dispatched.first ().gesture == DecodeClickGesture::Press); + QTRY_COMPARE_WITH_TIMEOUT (dispatched.size (), 2, 100); + QCOMPARE (dispatched.last ().row, QByteArray {"first"}); + QVERIFY (dispatched.last ().gesture == DecodeClickGesture::SingleClick); +} + +void TestDecodeClickCoalescer::coalescesUpdatedRecordByIdentity() +{ + QList<DispatchEvent> dispatched; + DecodeClickCoalescer coalescer {this, [&dispatched] (QByteArray const& row, + DecodeClickGesture gesture) { + dispatched.append ({row, gesture}); + }, 20}; + + coalescer.press ("K1ABC", "old record"); + coalescer.doubleClick ("K1ABC", "new record"); + QCOMPARE (dispatched.size (), 2); + QCOMPARE (dispatched.last ().row, QByteArray {"new record"}); + QVERIFY (dispatched.last ().gesture == DecodeClickGesture::DoubleClick); + QTest::qWait (30); + QCOMPARE (dispatched.size (), 2); +} + +void TestDecodeClickCoalescer::keepsDifferentRecordsSeparate() +{ + QList<DispatchEvent> dispatched; + DecodeClickCoalescer coalescer {this, [&dispatched] (QByteArray const& row, + DecodeClickGesture gesture) { + dispatched.append ({row, gesture}); + }, 20}; + + coalescer.press ("K1ABC", "first"); + coalescer.press ("K2XYZ", "second"); + QCOMPARE (dispatched.size (), 3); + QCOMPARE (dispatched.at (1).row, QByteArray {"first"}); + QVERIFY (dispatched.at (1).gesture == DecodeClickGesture::SingleClick); + QVERIFY (dispatched.last ().gesture == DecodeClickGesture::Press); + QTRY_COMPARE_WITH_TIMEOUT (dispatched.size (), 4, 100); + QCOMPARE (dispatched.last ().row, QByteArray {"second"}); + QVERIFY (dispatched.last ().gesture == DecodeClickGesture::SingleClick); +} + +void TestDecodeClickCoalescer::protectsDoubleClickWhenDisarmIsOverwritten() +{ + auto const failedDoubleClick = qmapClickPolicy (true, false, true, true); + QVERIFY (failedDoubleClick.disarmBeforeQsy); + QVERIFY (!failedDoubleClick.enableAutoTx); + QVERIFY (!failedDoubleClick.restartTransmission); + + auto const acceptedDoubleClick = qmapClickPolicy (true, true, false, true); + QVERIFY (acceptedDoubleClick.enableAutoTx); + QVERIFY (acceptedDoubleClick.restartTransmission); + + auto const failedSingleClick = qmapClickPolicy (false, false, true, false); + QVERIFY (failedSingleClick.disableAutoTx); +} + +QTEST_GUILESS_MAIN (TestDecodeClickCoalescer) + +#include "test_decode_click_coalescer.moc" diff --git a/tests/unit/qmap/test_livecq_parser.cpp b/tests/unit/qmap/test_livecq_parser.cpp new file mode 100644 index 00000000..4f0ff9ea --- /dev/null +++ b/tests/unit/qmap/test_livecq_parser.cpp @@ -0,0 +1,84 @@ +#include <QtTest> + +#include "qmap/livecq_parser.h" + +class TestQMapLiveCQParser final : public QObject +{ + Q_OBJECT + +private slots: + void parsesSupportedLayouts() + { + QMapLiveCQ::Record record; + QVERIFY(QMapLiveCQ::parse( + {"123456", "-10", "0.1", "1234", "-12", "60", "CQ", "N5L", "1200.0"}, + 100, record)); + QCOMPARE(record.callsign, QString {"N5L"}); + QCOMPARE(record.grid, QString {"--"}); + QCOMPARE(record.message, QString {"CQ N5L"}); + QCOMPARE(record.receiveFrequency, 100); + QCOMPARE(record.scheduledFrequency, 1200); + + QVERIFY(QMapLiveCQ::parse( + {"123456", "-10", "0.1", "1234", "-12", "60", "CQ", "N5L", "FN20", "1200.0"}, + 100, record)); + QCOMPARE(record.grid, QString {"FN20"}); + QCOMPARE(record.message, QString {"CQ N5L FN20"}); + + QVERIFY(QMapLiveCQ::parse( + {"123456", "-10", "0.1", "1234", "-12", "60", "CQ", "DX", "N5L", "1200.0"}, + 100, record)); + QCOMPARE(record.callsign, QString {"N5L"}); + QCOMPARE(record.grid, QString {"--"}); + QCOMPARE(record.message, QString {"CQ N5L"}); + + QVERIFY(QMapLiveCQ::parse( + {"123456", "-10", "0.1", "1234", "-12", "60", "CQ", "DX", "N5L", "FN20", "1200.0"}, + 100, record)); + QCOMPARE(record.grid, QString {"FN20"}); + QCOMPARE(record.message, QString {"CQ N5L FN20"}); + } + + void parsesHighFrequencyFraction() + { + QMapLiveCQ::Record record; + QVERIFY(QMapLiveCQ::parse( + {"123456", "-10", "0.1", "1234", "-12", "60", "CQ", "N5L", "1200.750"}, + 100, record)); + QCOMPARE(record.receiveFrequency, -150); + QCOMPARE(record.scheduledFrequency, 1201); + } + + void rejectsMalformedRecordsBeforeIndexing() + { + QMapLiveCQ::Record record; + for (auto const& tokens : { + QStringList {}, + QStringList {"123456", "-10", "0.1", "1234", "-12", "60", "CQ"}, + QStringList {"123456", "-10", "0.1", "1234", "-12", "60", "CQ", "N5L"}, + QStringList {"123456", "-10", "0.1", "1234", "-12", "60", "CQ", "N5L", "FN20", "1200.0", "extra", "too-much"}}) { + QVERIFY(!QMapLiveCQ::parse(tokens, 100, record)); + } + } + + void rejectsMalformedFrequencyAndCalls() + { + QMapLiveCQ::Record record; + for (auto const& frequency : {QString {"1200"}, QString {"1200."}, + QString {"1200.x"}, QString {"1200.0.1"}}) { + QVERIFY(!QMapLiveCQ::parse( + {"123456", "-10", "0.1", "1234", "-12", "60", "CQ", "N5L", frequency}, + 100, record)); + } + QVERIFY(!QMapLiveCQ::parse( + {"123456", "-10", "0.1", "1234", "-12", "60", "CQ", "N5", "1200.0"}, + 100, record)); + QVERIFY(!QMapLiveCQ::parse( + {"123456", "-10", "0.1", "1234", "-12", "60", "CQ", "DX", "N5", "1200.0"}, + 100, record)); + } +}; + +QTEST_APPLESS_MAIN(TestQMapLiveCQParser) + +#include "test_livecq_parser.moc" diff --git a/tests/unit/qmap/test_plotter_initialization.cpp b/tests/unit/qmap/test_plotter_initialization.cpp new file mode 100644 index 00000000..f022a300 --- /dev/null +++ b/tests/unit/qmap/test_plotter_initialization.cpp @@ -0,0 +1,127 @@ +#include <memory> + +#include <QtTest> +#include <QApplication> +#include <QImage> +#include <QMouseEvent> +#include <QSignalSpy> + +#include "qmap/plotter.h" + +class TestablePlotter final : public CPlotter +{ +public: + using CPlotter::mousePressEvent; +}; + +class TestPlotterInitialization final : public QObject +{ + Q_OBJECT + +private slots: + void sizesHiddenPlotter(); + void ignoresOutOfSpanAndControlClicks(); + void paintsLabelsInTwoDSpectrumMode(); +}; + +void TestPlotterInitialization::sizesHiddenPlotter() +{ + // CPlotter embeds a ~12.5 MB m_zwf array as a direct member (qmap/plotter.h), + // so it must be heap-allocated -- a stack-local instance overflows the + // default thread stack. + auto const plotter = std::make_unique<CPlotter> (); + + QVERIFY (!plotter->isVisible ()); + plotter->ensureSized (1000, 280); + + QCOMPARE (plotter->plotWidth (), 1000); + QVERIFY (plotter->centerFreq () >= 0); + QVERIFY (plotter->binsPerPixel () > 0); +} + +void TestPlotterInitialization::ignoresOutOfSpanAndControlClicks() +{ + qRegisterMetaType<DecodeClickGesture> ("DecodeClickGesture"); + auto const plotter = std::make_unique<TestablePlotter> (); + plotter->ensureSized (1000, 280); + plotter->setFsample (96000); + plotter->show (); + QCoreApplication::processEvents (); + plotter->SetStartFreq (100); + plotter->m_fSpan = 100.f; + + QMapDecodeLabel label; + label.callsign = "K1ABC"; + label.receiveFrequencyKHz = 150.; + label.raw = QByteArray (static_cast<int> (QMapDecodeRowSize), 'x'); + plotter->setDecodeLabels ({label}); + + QSignalSpy clicked (plotter.get (), &CPlotter::decodeLabelClicked); + QVERIFY (clicked.isValid ()); + QImage image (plotter->size (), QImage::Format_ARGB32); + image.fill (Qt::transparent); + plotter->render (&image); + QPoint labelPoint; + for (int y = 30; y < 60 && labelPoint.isNull (); ++y) { + for (int x = 0; x < image.width () && labelPoint.isNull (); ++x) { + auto const color = image.pixelColor (x, y); + if (color.red () > 200 && color.green () > 200 && color.blue () < 100) + labelPoint = {x, y}; + } + } + QVERIFY (!labelPoint.isNull ()); + QMouseEvent event {QEvent::MouseButtonPress, QPointF (labelPoint), + Qt::LeftButton, Qt::LeftButton, Qt::NoModifier}; + plotter->mousePressEvent (&event); + QCOMPARE (clicked.size (), 1); + + clicked.clear (); + label.receiveFrequencyKHz = 1000.; + plotter->setDecodeLabels ({label}); + QMouseEvent outOfSpanEvent {QEvent::MouseButtonPress, QPointF (999, 35), + Qt::LeftButton, Qt::LeftButton, Qt::NoModifier}; + plotter->mousePressEvent (&outOfSpanEvent); + QCOMPARE (clicked.size (), 0); + + label.receiveFrequencyKHz = 150.; + plotter->setDecodeLabels ({label}); + QMouseEvent controlEvent {QEvent::MouseButtonPress, + QPointF (labelPoint.x (), labelPoint.y ()), + Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier}; + plotter->mousePressEvent (&controlEvent); + QCOMPARE (clicked.size (), 0); +} + +void TestPlotterInitialization::paintsLabelsInTwoDSpectrumMode() +{ + auto const plotter = std::make_unique<CPlotter> (); + plotter->ensureSized (1000, 280); + plotter->setFsample (96000); + plotter->set2Dspec (true); + plotter->SetStartFreq (100); + + QMapDecodeLabel label; + label.callsign = "K1ABC"; + label.receiveFrequencyKHz = plotter->startFreq () + plotter->m_fSpan / 2.; + plotter->setDecodeLabels ({label}); + plotter->show (); + QCoreApplication::processEvents (); + + QImage image (plotter->size (), QImage::Format_ARGB32); + image.fill (Qt::transparent); + plotter->render (&image); + + int yellowPixels = 0; + for (int y = 30; y < 60; ++y) { + for (int x = 470; x < 530; ++x) { + auto const color = image.pixelColor (x, y); + if (color.red () > 200 && color.green () > 200 && color.blue () < 100) + ++yellowPixels; + } + } + QVERIFY (yellowPixels > 0); +} + +QTEST_MAIN (TestPlotterInitialization) + +#include "test_plotter_initialization.moc" diff --git a/tests/unit/qmap/test_qmap_decode_record.cpp b/tests/unit/qmap/test_qmap_decode_record.cpp new file mode 100644 index 00000000..54b165ec --- /dev/null +++ b/tests/unit/qmap/test_qmap_decode_record.cpp @@ -0,0 +1,97 @@ +#include <QtTest> + +#include "qmap/decode_label.h" +#include "qmap/qmap_decode_record.h" + +namespace +{ + QByteArray makeRow (QByteArray const& message) + { + QByteArray row (static_cast<int> (QMapDecodeRowSize), ' '); + row.replace (0, 6, "123430"); + row.replace (6, 9, " 123.456"); + row.replace (15, 7, " 120.0"); + row.replace (22, 7, " 0.12"); + row.replace (29, 5, " -15"); + row.replace (36, 3, "30A"); + row.replace (41, message.size (), message); + return row; + } +} + +class TestQMapDecodeRecord final : public QObject +{ + Q_OBJECT + +private slots: + void parsesFixedWidthRecord(); + void rejectsMalformedRecord(); + void replacesLabelWithLatestRecord(); + void prunesExpiredLabelsAcrossMidnight(); +}; + +void TestQMapDecodeRecord::parsesFixedWidthRecord() +{ + auto const row = makeRow ("CQ POTA W3SZ/2 FN20"); + auto const record = parseQMapDecodeRecord (row); + + QVERIFY (record); + QCOMPARE (record->raw, row); + QCOMPARE (record->time, QString {"123430"}); + QCOMPARE (record->callsign, QString {"W3SZ/2"}); + QCOMPARE (record->grid, QString {"FN20"}); + QCOMPARE (record->submode, QString {"30A"}); + QCOMPARE (record->receiveFrequencyKHz, 123.456); + QCOMPARE (record->scheduledFrequencyKHz, 120.0); + QCOMPARE (record->snr, -15); + QCOMPARE (record->secondsSinceMidnight, 12 * 3600 + 34 * 60 + 30); + QVERIFY (record->secondHalf); + QVERIFY (record->cq); +} + +void TestQMapDecodeRecord::rejectsMalformedRecord() +{ + QVERIFY (!parseQMapDecodeRecord (QByteArray {"short"})); + + auto row = makeRow ("CQ K1ABC FN42"); + row.replace (0, 6, "256099"); + QVERIFY (!parseQMapDecodeRecord (row)); +} + +void TestQMapDecodeRecord::replacesLabelWithLatestRecord() +{ + auto firstRow = makeRow ("CQ K1ABC FN42"); + auto secondRow = firstRow; + secondRow.replace (6, 9, " 222.333"); + secondRow.replace (29, 5, " -07"); + auto const first = parseQMapDecodeRecord (firstRow); + auto const second = parseQMapDecodeRecord (secondRow); + QVERIFY (first); + QVERIFY (second); + + QList<QMapDecodeLabel> labels; + upsertQMapDecodeLabel (labels, *first); + upsertQMapDecodeLabel (labels, *second); + + QCOMPARE (labels.size (), 1); + QCOMPARE (labels.first ().raw, secondRow); + QCOMPARE (labels.first ().receiveFrequencyKHz, 222.333); + QCOMPARE (labels.first ().snr, -7); +} + +void TestQMapDecodeRecord::prunesExpiredLabelsAcrossMidnight() +{ + auto record = *parseQMapDecodeRecord (makeRow ("CQ K1ABC FN42")); + record.secondsSinceMidnight = 23 * 3600 + 59 * 60; + QList<QMapDecodeLabel> labels {record}; + + pruneQMapDecodeLabels (labels, 60); + QCOMPARE (labels.size (), 1); + + pruneQMapDecodeLabels (labels, 3 * 60 + 1); + QVERIFY (labels.isEmpty ()); +} + +QTEST_GUILESS_MAIN (TestQMapDecodeRecord) + +#include "test_qmap_decode_record.moc" diff --git a/tests/unit/qmap/test_qmap_ipc.cpp b/tests/unit/qmap/test_qmap_ipc.cpp new file mode 100644 index 00000000..61524fbd --- /dev/null +++ b/tests/unit/qmap/test_qmap_ipc.cpp @@ -0,0 +1,98 @@ +#include <QtTest> + +#include <array> +#include <cstring> + +#include "qmap/qmap_ipc.h" + +class TestQMapIpc final : public QObject +{ + Q_OBJECT + +private slots: + void leavesIncompleteBatchPending(); + void acknowledgesCompletedBatch_data(); + void acknowledgesCompletedBatch(); + void decoderPublicationPreservesRequests(); + void reportsMappingCapabilities(); + void clearsOnlyMappedProtocolBytes(); +}; + +void TestQMapIpc::leavesIncompleteBatchPending() +{ + QMapDecodeBlock shared {}; + shared.ndecodes = 3; + + QVERIFY (!acknowledgeQMapDecodeBatch (shared)); + QCOMPARE (shared.ndecodes, 3); +} + +void TestQMapIpc::acknowledgesCompletedBatch_data() +{ + QTest::addColumn<int> ("completion"); + QTest::newRow ("live") << 1; + QTest::newRow ("disk") << 2; +} + +void TestQMapIpc::acknowledgesCompletedBatch() +{ + QFETCH (int, completion); + QMapDecodeBlock shared {}; + shared.ndecodes = 3; + shared.nQDecoderDone = completion; + + QVERIFY (acknowledgeQMapDecodeBatch (shared)); + QCOMPARE (shared.ndecodes, 0); + QCOMPARE (shared.nQDecoderDone, 0); +} + +void TestQMapIpc::decoderPublicationPreservesRequests() +{ + QMapSharedMemory shared {}; + shared.decodes.nWDecoderBusy = 1; + shared.decodes.nWTransmitting = 60; + shared.decodes.kHzRequested = 144; + shared.click.action = QMapClickAction::Select; + std::memset (shared.click.selectedDecode, 'x', sizeof shared.click.selectedDecode); + QMapDecodeBlock publication {}; + publication.ndecodes = 2; + + publishQMapDecodeBlock (shared, publication); + + QCOMPARE (shared.decodes.ndecodes, 2); + QCOMPARE (shared.decodes.nWDecoderBusy, 1); + QCOMPARE (shared.decodes.nWTransmitting, 60); + QCOMPARE (shared.decodes.kHzRequested, 144); + QCOMPARE (shared.click.action, QMapClickAction::Select); + QByteArray const selectedDecode {shared.click.selectedDecode, + static_cast<int> (sizeof shared.click.selectedDecode)}; + QCOMPARE (selectedDecode, QByteArray (static_cast<int> (QMapDecodeRowSize), 'x')); +} + +void TestQMapIpc::reportsMappingCapabilities() +{ + QVERIFY (!qmapDecoderRegionAvailable (qmap_decode_ipc::shared_memory_size - 1)); + QVERIFY (qmapDecoderRegionAvailable (qmap_decode_ipc::shared_memory_size)); + QVERIFY (!qmapClickMailboxAvailable (sizeof (QMapSharedMemory) - 1)); + QVERIFY (qmapClickMailboxAvailable (sizeof (QMapSharedMemory))); + QVERIFY (qmapClickMailboxAvailable (QMapSharedMemorySize)); +} + +void TestQMapIpc::clearsOnlyMappedProtocolBytes() +{ + std::array<unsigned char, QMapSharedMemorySize + 16> bytes; + bytes.fill (0xA5); + + clearQMapSharedMemory (bytes.data (), sizeof (QMapSharedMemory)); + + for (std::size_t i = 0; i < sizeof (QMapSharedMemory); ++i) + QCOMPARE (bytes[i], static_cast<unsigned char> (0)); + for (std::size_t i = sizeof (QMapSharedMemory); i < bytes.size (); ++i) + QCOMPARE (bytes[i], static_cast<unsigned char> (0xA5)); + QCOMPARE (qmapClearLength (0), std::size_t {0}); + QCOMPARE (qmapClearLength (QMapSharedMemorySize + 1), QMapSharedMemorySize); +} + +QTEST_GUILESS_MAIN (TestQMapIpc) + +#include "test_qmap_ipc.moc" |
