diff options
| author | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:28 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:28 +0200 |
| commit | 69344560ea394c06ca94acac46a2e4c3e8b7b229 (patch) | |
| tree | ebc98370a697a9bbd6b973a14fa5113c475c6db7 /tests/unit/qmap/test_qmap_ipc.cpp | |
| parent | 3e9d10a67671d0bd5c7b8c3ca8088f1818322eff (diff) | |
| parent | 059831534c7e884f0a607ed86b582fd00d821731 (diff) | |
Update upstream source from tag 'upstream/3.2.0_rc1+dfsg'
Update to upstream version '3.2.0~rc1+dfsg'
with Debian dir dbff457fd2c3616d5c77b863c7bfb2186ed86047
Diffstat (limited to 'tests/unit/qmap/test_qmap_ipc.cpp')
| -rw-r--r-- | tests/unit/qmap/test_qmap_ipc.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
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" |
