summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt14
-rw-r--r--tests/test_bwf_file.cpp354
-rw-r--r--tests/test_emulate_split_transceiver.cpp113
-rw-r--r--tests/test_http_user_agent.cpp33
-rw-r--r--tests/unit/hrd/CMakeLists.txt6
-rw-r--r--tests/unit/hrd/test_hrd_message.cpp168
-rw-r--r--tests/unit/packjt77/CMakeLists.txt6
-rw-r--r--tests/unit/packjt77/test_packjt77_hash_vectors.f9077
8 files changed, 771 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 4b346233..bf086f99 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -21,3 +21,17 @@ include_directories (${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR})
add_executable (test_qt_helpers test_qt_helpers.cpp)
target_link_libraries (test_qt_helpers wsjt_qt Qt5::Test)
add_test (test_qt_helpers test_qt_helpers)
+add_subdirectory (unit/hrd)
+add_subdirectory (unit/packjt77)
+
+add_executable (test_http_user_agent test_http_user_agent.cpp)
+target_link_libraries (test_http_user_agent wsjt_qt Qt5::Test)
+add_test (test_http_user_agent test_http_user_agent)
+
+add_executable (test_emulate_split_transceiver test_emulate_split_transceiver.cpp)
+target_link_libraries (test_emulate_split_transceiver Boost::log wsjt_qt Qt5::Test Qt5::Network Qt5::Widgets)
+add_test (test_emulate_split_transceiver test_emulate_split_transceiver)
+
+add_executable (test_bwf_file test_bwf_file.cpp)
+target_link_libraries (test_bwf_file wsjt_qt wsjt_qtmm Qt5::Test Qt5::Multimedia)
+add_test (test_bwf_file test_bwf_file)
diff --git a/tests/test_bwf_file.cpp b/tests/test_bwf_file.cpp
new file mode 100644
index 00000000..55f42e32
--- /dev/null
+++ b/tests/test_bwf_file.cpp
@@ -0,0 +1,354 @@
+#include <QtTest>
+
+#include <QFile>
+#include <QTemporaryFile>
+#include <QtMultimedia/QAudioFormat>
+
+#include "Audio/BWFFile.hpp"
+
+namespace
+{
+ QByteArray le16 (quint16 value)
+ {
+ QByteArray bytes (2, '\0');
+ bytes[0] = static_cast<char> (value & 0xffu);
+ bytes[1] = static_cast<char> ((value >> 8) & 0xffu);
+ return bytes;
+ }
+
+ QByteArray le32 (quint32 value)
+ {
+ QByteArray bytes (4, '\0');
+ bytes[0] = static_cast<char> (value & 0xffu);
+ bytes[1] = static_cast<char> ((value >> 8) & 0xffu);
+ bytes[2] = static_cast<char> ((value >> 16) & 0xffu);
+ bytes[3] = static_cast<char> ((value >> 24) & 0xffu);
+ return bytes;
+ }
+
+ QByteArray chunk (char const * id, QByteArray const& payload)
+ {
+ QByteArray out;
+ out.append (id, 4);
+ out.append (le32 (static_cast<quint32> (payload.size ())));
+ out.append (payload);
+ if (payload.size () & 1)
+ {
+ out.append ('\0');
+ }
+ return out;
+ }
+
+ QByteArray wave_file (QList<QByteArray> const& chunks)
+ {
+ QByteArray payload {"WAVE", 4};
+ for (auto const& current : chunks)
+ {
+ payload.append (current);
+ }
+
+ QByteArray out;
+ out.append ("RIFF", 4);
+ out.append (le32 (static_cast<quint32> (payload.size ())));
+ out.append (payload);
+ return out;
+ }
+
+ QByteArray fmt_chunk (quint16 channels = 1, quint32 sample_rate = 12000,
+ quint16 bits_per_sample = 16, quint16 block_align = 0,
+ quint32 byte_rate = 0)
+ {
+ if (!block_align)
+ {
+ block_align = static_cast<quint16> (channels * (bits_per_sample / 8u));
+ }
+ if (!byte_rate)
+ {
+ byte_rate = sample_rate * block_align;
+ }
+
+ QByteArray payload;
+ payload.append (le16 (1));
+ payload.append (le16 (channels));
+ payload.append (le32 (sample_rate));
+ payload.append (le32 (byte_rate));
+ payload.append (le16 (block_align));
+ payload.append (le16 (bits_per_sample));
+ return chunk ("fmt ", payload);
+ }
+
+ QByteArray data_chunk (QByteArray const& data = {})
+ {
+ return chunk ("data", data);
+ }
+
+ QByteArray info_list_chunk ()
+ {
+ QByteArray payload {"INFO", 4};
+ payload.append (chunk ("INAM", QByteArray {"wsjtx", 5}));
+ return chunk ("LIST", payload);
+ }
+
+ QByteArray info_list_chunk_with_terminal_pad_outside_size ()
+ {
+ QByteArray payload {"INFO", 4};
+ payload.append ("ISRC", 4);
+ payload.append (le32 (5));
+ payload.append ("K1JT", 5);
+
+ QByteArray out;
+ out.append ("LIST", 4);
+ out.append (le32 (static_cast<quint32> (payload.size ())));
+ out.append (payload);
+ out.append ('\0');
+ return out;
+ }
+
+ QByteArray bare_bext_payload ()
+ {
+ return QByteArray (604, '\0');
+ }
+
+ QAudioFormat default_format ()
+ {
+ QAudioFormat format;
+ format.setByteOrder (QAudioFormat::LittleEndian);
+ format.setChannelCount (1);
+ format.setCodec ("audio/pcm");
+ format.setSampleRate (12000);
+ format.setSampleSize (16);
+ format.setSampleType (QAudioFormat::SignedInt);
+ return format;
+ }
+
+ QString write_temp_file (QByteArray const& data)
+ {
+ QTemporaryFile file;
+ file.setAutoRemove (false);
+ if (!file.open ())
+ {
+ return {};
+ }
+
+ if (file.write (data) != data.size ())
+ {
+ return {};
+ }
+
+ auto const name = file.fileName ();
+ file.close ();
+ return name;
+ }
+}
+
+class TestBWFFile
+ : public QObject
+{
+ Q_OBJECT
+
+private:
+ Q_SLOT void opens_valid_pcm_wave ()
+ {
+ auto const name = write_temp_file (wave_file ({fmt_chunk (), data_chunk ()}));
+ QVERIFY (!name.isEmpty ());
+
+ BWFFile file {default_format (), name};
+ QVERIFY (file.open (QIODevice::ReadOnly));
+ QCOMPARE (file.format ().channelCount (), 1);
+ QCOMPARE (file.format ().sampleRate (), 12000);
+ file.close ();
+ QFile::remove (name);
+ }
+
+ Q_SLOT void opens_valid_list_info_chunk ()
+ {
+ auto const name = write_temp_file (wave_file ({fmt_chunk (), info_list_chunk (), data_chunk ()}));
+ QVERIFY (!name.isEmpty ());
+ BWFFile::InfoDictionary::key_type const inam {{'I', 'N', 'A', 'M'}};
+ QByteArray const expected_name {"wsjtx", 5};
+
+ BWFFile file {default_format (), name};
+ QVERIFY (file.open (QIODevice::ReadOnly));
+ QVERIFY (file.list_info ().contains (inam));
+ QCOMPARE (file.list_info ().value (inam), expected_name);
+ file.close ();
+ QFile::remove (name);
+ }
+
+ Q_SLOT void opens_list_info_with_terminal_subchunk_pad ()
+ {
+ auto const name = write_temp_file (wave_file ({fmt_chunk (), data_chunk (),
+ info_list_chunk_with_terminal_pad_outside_size ()}));
+ QVERIFY (!name.isEmpty ());
+ BWFFile::InfoDictionary::key_type const isrc {{'I', 'S', 'R', 'C'}};
+
+ BWFFile file {default_format (), name};
+ QVERIFY (file.open (QIODevice::ReadOnly));
+ QVERIFY (file.list_info ().contains (isrc));
+ QCOMPARE (file.list_info ().value (isrc), QByteArray ("K1JT", 5));
+ file.close ();
+ QFile::remove (name);
+ }
+
+ Q_SLOT void bext_version_without_chunk_defaults_to_v0 ()
+ {
+ auto const name = write_temp_file (wave_file ({fmt_chunk (), data_chunk ()}));
+ QVERIFY (!name.isEmpty ());
+
+ BWFFile file {default_format (), name};
+ BWFFile const& const_file = file;
+ QVERIFY (file.open (QIODevice::ReadOnly));
+ QCOMPARE (static_cast<int> (const_file.bext_version ()),
+ static_cast<int> (BWFFile::BextVersion::v_0));
+ file.close ();
+ QFile::remove (name);
+ }
+
+ Q_SLOT void bext_fixed_field_getter_stays_bounded ()
+ {
+ QByteArray bext = bare_bext_payload ();
+ bext.replace (0, 256, QByteArray (256, 'B'));
+ auto const name = write_temp_file (wave_file ({fmt_chunk (), chunk ("bext", bext), data_chunk ()}));
+ QVERIFY (!name.isEmpty ());
+
+ BWFFile file {default_format (), name};
+ QVERIFY (file.open (QIODevice::ReadOnly));
+ QCOMPARE (file.bext_description (), QByteArray (256, 'B'));
+ file.close ();
+ QFile::remove (name);
+ }
+
+ Q_SLOT void bext_origination_date_time_stays_bounded ()
+ {
+ QByteArray bext = bare_bext_payload ();
+ bext.replace (320, 10, QByteArray {"2026-04-06", 10});
+ bext.replace (330, 10, QByteArray {"12-34-56ZZ", 10});
+ auto const name = write_temp_file (wave_file ({fmt_chunk (), chunk ("bext", bext), data_chunk ()}));
+ QVERIFY (!name.isEmpty ());
+
+ BWFFile file {default_format (), name};
+ QVERIFY (file.open (QIODevice::ReadOnly));
+ QCOMPARE (file.bext_origination_date_time ().date (), QDate (2026, 4, 6));
+ QCOMPARE (file.bext_origination_date_time ().time (), QTime (12, 34, 56));
+ file.close ();
+ QFile::remove (name);
+ }
+
+ Q_SLOT void bext_origination_date_time_setter_handles_invalid_value ()
+ {
+ QTemporaryFile temp;
+ temp.setAutoRemove (false);
+ QVERIFY (temp.open ());
+ auto const name = temp.fileName ();
+ temp.close ();
+
+ {
+ BWFFile file {default_format (), name};
+ QVERIFY (file.open (QIODevice::WriteOnly));
+ file.bext_origination_date_time ({});
+ file.close ();
+ }
+
+ {
+ BWFFile file {default_format (), name};
+ QVERIFY (file.open (QIODevice::ReadOnly));
+ QVERIFY (!file.bext_origination_date_time ().isValid ());
+ file.close ();
+ }
+
+ QFile::remove (name);
+ }
+
+ Q_SLOT void bext_setter_truncates_without_overread ()
+ {
+ QTemporaryFile temp;
+ temp.setAutoRemove (false);
+ QVERIFY (temp.open ());
+ auto const name = temp.fileName ();
+ temp.close ();
+
+ {
+ BWFFile file {default_format (), name};
+ QVERIFY (file.open (QIODevice::WriteOnly));
+ file.bext_description (QByteArray (300, 'A'));
+ file.close ();
+ }
+
+ {
+ BWFFile file {default_format (), name};
+ QVERIFY (file.open (QIODevice::ReadOnly));
+ QCOMPARE (file.bext_description (), QByteArray (256, 'A'));
+ file.close ();
+ }
+
+ QFile::remove (name);
+ }
+
+ Q_SLOT void rejects_truncated_bext_chunk ()
+ {
+ QByteArray bad_bext;
+ bad_bext.append ("bext", 4);
+ bad_bext.append (le32 (700));
+ bad_bext.append (QByteArray (16, '\0'));
+ auto const name = write_temp_file (wave_file ({fmt_chunk (), bad_bext, data_chunk ()}));
+ QVERIFY (!name.isEmpty ());
+
+ BWFFile file {default_format (), name};
+ QVERIFY (!file.open (QIODevice::ReadOnly));
+ QFile::remove (name);
+ }
+
+ Q_SLOT void rejects_list_info_subchunk_overrun ()
+ {
+ QByteArray payload {"INFO", 4};
+ payload.append ("INAM", 4);
+ payload.append (le32 (8));
+ payload.append ("bad", 3);
+ auto const name = write_temp_file (wave_file ({fmt_chunk (), chunk ("LIST", payload), data_chunk ()}));
+ QVERIFY (!name.isEmpty ());
+
+ BWFFile file {default_format (), name};
+ QVERIFY (!file.open (QIODevice::ReadOnly));
+ QFile::remove (name);
+ }
+
+ Q_SLOT void rejects_short_fmt_chunk ()
+ {
+ QByteArray payload;
+ payload.append (le16 (1));
+ payload.append (le16 (1));
+ auto const name = write_temp_file (wave_file ({chunk ("fmt ", payload), data_chunk ()}));
+ QVERIFY (!name.isEmpty ());
+
+ BWFFile file {default_format (), name};
+ QVERIFY (!file.open (QIODevice::ReadOnly));
+ QFile::remove (name);
+ }
+
+ Q_SLOT void rejects_zero_channel_fmt ()
+ {
+ auto const name = write_temp_file (wave_file ({fmt_chunk (0), data_chunk ()}));
+ QVERIFY (!name.isEmpty ());
+
+ BWFFile file {default_format (), name};
+ QVERIFY (!file.open (QIODevice::ReadOnly));
+ QFile::remove (name);
+ }
+
+ Q_SLOT void tolerates_inconsistent_fmt_rates ()
+ {
+ auto const name = write_temp_file (wave_file ({fmt_chunk (1, 12000, 16, 4, 48000), data_chunk ()}));
+ QVERIFY (!name.isEmpty ());
+
+ BWFFile file {default_format (), name};
+ QVERIFY (file.open (QIODevice::ReadOnly));
+ QCOMPARE (file.format ().sampleRate (), 12000);
+ QCOMPARE (file.format ().sampleSize (), 16);
+ file.close ();
+ QFile::remove (name);
+ }
+};
+
+QTEST_MAIN (TestBWFFile)
+
+#include "test_bwf_file.moc"
diff --git a/tests/test_emulate_split_transceiver.cpp b/tests/test_emulate_split_transceiver.cpp
new file mode 100644
index 00000000..13482b62
--- /dev/null
+++ b/tests/test_emulate_split_transceiver.cpp
@@ -0,0 +1,113 @@
+#include <memory>
+
+#include <QtTest>
+
+#include "Transceiver/EmulateSplitTransceiver.hpp"
+
+class FakeTransceiver final
+ : public Transceiver
+{
+ Q_OBJECT
+
+public:
+ FakeTransceiver ()
+ : Transceiver {nullptr, nullptr}
+ {
+ }
+
+ void set (TransceiverState const& state, unsigned sequence_number) noexcept override
+ {
+ last_state = state;
+ last_sequence_number = sequence_number;
+ }
+
+ void start (unsigned sequence_number) noexcept override
+ {
+ last_sequence_number = sequence_number;
+ }
+
+ void stop () noexcept override {}
+
+ void send_update (TransceiverState const& state, unsigned sequence_number)
+ {
+ Q_EMIT update (state, sequence_number);
+ }
+
+ TransceiverState last_state;
+ unsigned last_sequence_number {0};
+};
+
+class TestEmulateSplitTransceiver : public QObject
+{
+ Q_OBJECT
+
+private:
+ Q_SLOT void fakeSplitDoesNotPublishTransientTxDialAsRxDial ()
+ {
+ auto * raw_fake = new FakeTransceiver;
+ EmulateSplitTransceiver transceiver {nullptr, std::unique_ptr<Transceiver> {raw_fake}};
+ QSignalSpy updates {&transceiver, &Transceiver::update};
+
+ Transceiver::TransceiverState requested;
+ requested.online (true);
+ requested.frequency (7074000);
+ requested.tx_frequency (7072500);
+ requested.split (true);
+ requested.ptt (true);
+
+ transceiver.set (requested, 17);
+
+ QCOMPARE (raw_fake->last_state.frequency (), requested.tx_frequency ());
+ QCOMPARE (raw_fake->last_state.tx_frequency (), Transceiver::Frequency {0});
+ QVERIFY (!raw_fake->last_state.split ());
+
+ Transceiver::TransceiverState wrapped_update;
+ wrapped_update.online (true);
+ wrapped_update.frequency (requested.tx_frequency ());
+ wrapped_update.split (false);
+ wrapped_update.ptt (false);
+
+ raw_fake->send_update (wrapped_update, 17);
+
+ QCOMPARE (updates.size (), 1);
+ auto const published = qvariant_cast<Transceiver::TransceiverState> (updates.takeFirst ().at (0));
+ QCOMPARE (published.frequency (), requested.frequency ());
+ QCOMPARE (published.tx_frequency (), requested.tx_frequency ());
+ QVERIFY (published.split ());
+ QVERIFY (!published.ptt ());
+ }
+
+ Q_SLOT void receiveModeStillFollowsManualRigQsy ()
+ {
+ auto * raw_fake = new FakeTransceiver;
+ EmulateSplitTransceiver transceiver {nullptr, std::unique_ptr<Transceiver> {raw_fake}};
+ QSignalSpy updates {&transceiver, &Transceiver::update};
+
+ Transceiver::TransceiverState requested;
+ requested.online (true);
+ requested.frequency (7074000);
+ requested.tx_frequency (7072500);
+ requested.split (true);
+ requested.ptt (false);
+
+ transceiver.set (requested, 18);
+
+ Transceiver::TransceiverState wrapped_update;
+ wrapped_update.online (true);
+ wrapped_update.frequency (14074000);
+ wrapped_update.split (false);
+ wrapped_update.ptt (false);
+
+ raw_fake->send_update (wrapped_update, 18);
+
+ QCOMPARE (updates.size (), 1);
+ auto const published = qvariant_cast<Transceiver::TransceiverState> (updates.takeFirst ().at (0));
+ QCOMPARE (published.frequency (), wrapped_update.frequency ());
+ QCOMPARE (published.tx_frequency (), requested.tx_frequency ());
+ QVERIFY (published.split ());
+ QVERIFY (!published.ptt ());
+ }
+};
+
+QTEST_MAIN (TestEmulateSplitTransceiver)
+#include "test_emulate_split_transceiver.moc"
diff --git a/tests/test_http_user_agent.cpp b/tests/test_http_user_agent.cpp
new file mode 100644
index 00000000..0bc09ea1
--- /dev/null
+++ b/tests/test_http_user_agent.cpp
@@ -0,0 +1,33 @@
+#include <QtTest>
+
+#include "revision_utils.hpp"
+
+class TestHttpUserAgent final
+ : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void includesApplicationIdentityAndPlatformContext ()
+ {
+ auto const user_agent = http_user_agent ();
+
+ QVERIFY (user_agent.startsWith ("WSJT-X/"));
+ QVERIFY (user_agent.contains (version ()));
+
+ auto const build_revision = revision ();
+ if (!build_revision.isEmpty ())
+ {
+ QVERIFY (user_agent.contains ("_" + build_revision));
+ }
+
+ QVERIFY (user_agent.contains ('('));
+ QVERIFY (user_agent.contains (')'));
+ QVERIFY (!user_agent.contains ('\n'));
+ QVERIFY (!user_agent.contains ('\r'));
+ }
+};
+
+QTEST_GUILESS_MAIN (TestHttpUserAgent)
+
+#include "test_http_user_agent.moc"
diff --git a/tests/unit/hrd/CMakeLists.txt b/tests/unit/hrd/CMakeLists.txt
new file mode 100644
index 00000000..4981b132
--- /dev/null
+++ b/tests/unit/hrd/CMakeLists.txt
@@ -0,0 +1,6 @@
+add_executable (test_hrd_message
+ test_hrd_message.cpp
+ ${CMAKE_SOURCE_DIR}/Transceiver/HRDMessage.cpp
+)
+target_link_libraries (test_hrd_message Qt5::Test)
+add_test (NAME test_hrd_message COMMAND test_hrd_message)
diff --git a/tests/unit/hrd/test_hrd_message.cpp b/tests/unit/hrd/test_hrd_message.cpp
new file mode 100644
index 00000000..741355b4
--- /dev/null
+++ b/tests/unit/hrd/test_hrd_message.cpp
@@ -0,0 +1,168 @@
+#include <QtTest>
+
+#include "Transceiver/HRDMessage.hpp"
+
+namespace
+{
+ quint32 u32le (QByteArray const& bytes, int offset)
+ {
+ return static_cast<quint32> (static_cast<quint8> (bytes[offset]))
+ | (static_cast<quint32> (static_cast<quint8> (bytes[offset + 1])) << 8)
+ | (static_cast<quint32> (static_cast<quint8> (bytes[offset + 2])) << 16)
+ | (static_cast<quint32> (static_cast<quint8> (bytes[offset + 3])) << 24);
+ }
+
+ void write_u32le (QByteArray * bytes, int offset, quint32 value)
+ {
+ (*bytes)[offset] = static_cast<char> (value & 0xffu);
+ (*bytes)[offset + 1] = static_cast<char> ((value >> 8) & 0xffu);
+ (*bytes)[offset + 2] = static_cast<char> ((value >> 16) & 0xffu);
+ (*bytes)[offset + 3] = static_cast<char> ((value >> 24) & 0xffu);
+ }
+}
+
+class TestHRDMessage final
+ : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void buildsBinaryMessage ()
+ {
+ auto const message = HRDMessage::make ("get radio");
+
+ QCOMPARE (u32le (message, 0), static_cast<quint32> (message.size ()));
+ QCOMPARE (u32le (message, 4), quint32 (0x1234ABCD));
+ QCOMPARE (u32le (message, 8), quint32 (0xABCD1234));
+ QCOMPARE (u32le (message, 12), quint32 (0));
+ QCOMPARE (message.size (), HRDMessage::header_size () + (QString {"get radio"}.size () + 1) * 2);
+ QCOMPARE (static_cast<quint8> (message[message.size () - 2]), quint8 (0));
+ QCOMPARE (static_cast<quint8> (message[message.size () - 1]), quint8 (0));
+ }
+
+ void parsesValidMessage ()
+ {
+ auto const parsed = HRDMessage::parse (HRDMessage::make ("FTDX-3000"));
+
+ QVERIFY (parsed.valid);
+ QVERIFY (parsed.complete);
+ QCOMPARE (parsed.payload, QString {"FTDX-3000"});
+ }
+
+ void preservesUtf16Payload ()
+ {
+ QString payload {"Rig "};
+ payload.append (QChar {0x00d8});
+
+ auto const parsed = HRDMessage::parse (HRDMessage::make (payload));
+
+ QVERIFY (parsed.valid);
+ QVERIFY (parsed.complete);
+ QCOMPARE (parsed.payload, payload);
+ }
+
+ void usesDeclaredSizeForPayload ()
+ {
+ auto message = HRDMessage::make ("OK");
+ message.append ("ignored");
+
+ auto const parsed = HRDMessage::parse (message);
+
+ QVERIFY (parsed.valid);
+ QVERIFY (parsed.complete);
+ QCOMPARE (parsed.payload, QString {"OK"});
+ QCOMPARE (parsed.required_size, HRDMessage::make ("OK").size ());
+ }
+
+ void roundTripsEmptyPayload ()
+ {
+ auto const parsed = HRDMessage::parse (HRDMessage::make (""));
+
+ QVERIFY (parsed.valid);
+ QVERIFY (parsed.complete);
+ QCOMPARE (parsed.payload, QString {});
+ }
+
+ void reportsPartialHeader ()
+ {
+ auto const parsed = HRDMessage::parse (HRDMessage::make ("OK").left (8));
+
+ QVERIFY (parsed.valid);
+ QVERIFY (!parsed.complete);
+ QCOMPARE (parsed.required_size, HRDMessage::header_size ());
+ }
+
+ void reportsPartialBody ()
+ {
+ auto const message = HRDMessage::make ("OK");
+ auto const parsed = HRDMessage::parse (message.left (message.size () - 1));
+
+ QVERIFY (parsed.valid);
+ QVERIFY (!parsed.complete);
+ QCOMPARE (parsed.required_size, message.size ());
+ }
+
+ void rejectsInvalidMagic1 ()
+ {
+ auto message = HRDMessage::make ("OK");
+ write_u32le (&message, 4, 0);
+
+ auto const parsed = HRDMessage::parse (message);
+
+ QVERIFY (!parsed.valid);
+ }
+
+ void rejectsInvalidMagic2 ()
+ {
+ auto message = HRDMessage::make ("OK");
+ write_u32le (&message, 8, 0);
+
+ auto const parsed = HRDMessage::parse (message);
+
+ QVERIFY (!parsed.valid);
+ }
+
+ void rejectsHeaderSize ()
+ {
+ auto message = HRDMessage::make ("OK");
+ write_u32le (&message, 0, HRDMessage::header_size () - 1);
+
+ auto const parsed = HRDMessage::parse (message);
+
+ QVERIFY (!parsed.valid);
+ }
+
+ void rejectsOversizedMessage ()
+ {
+ auto message = HRDMessage::make ("OK");
+ write_u32le (&message, 0, HRDMessage::max_message_size () + 1);
+
+ auto const parsed = HRDMessage::parse (message);
+
+ QVERIFY (!parsed.valid);
+ }
+
+ void rejectsOddUtf16Payload ()
+ {
+ auto message = HRDMessage::make ("OK");
+ write_u32le (&message, 0, message.size () - 1);
+
+ auto const parsed = HRDMessage::parse (message);
+
+ QVERIFY (!parsed.valid);
+ }
+
+ void rejectsMissingTerminator ()
+ {
+ auto message = HRDMessage::make ("OK");
+ message[message.size () - 2] = 'X';
+
+ auto const parsed = HRDMessage::parse (message);
+
+ QVERIFY (!parsed.valid);
+ }
+};
+
+QTEST_MAIN (TestHRDMessage)
+
+#include "test_hrd_message.moc"
diff --git a/tests/unit/packjt77/CMakeLists.txt b/tests/unit/packjt77/CMakeLists.txt
new file mode 100644
index 00000000..f4ceff02
--- /dev/null
+++ b/tests/unit/packjt77/CMakeLists.txt
@@ -0,0 +1,6 @@
+add_executable (test_packjt77_hash_vectors
+ test_packjt77_hash_vectors.f90)
+target_include_directories (test_packjt77_hash_vectors PRIVATE ${CMAKE_BINARY_DIR})
+target_link_libraries (test_packjt77_hash_vectors wsjt_fort wsjt_cxx)
+
+add_test (NAME test_packjt77_hash_vectors COMMAND test_packjt77_hash_vectors)
diff --git a/tests/unit/packjt77/test_packjt77_hash_vectors.f90 b/tests/unit/packjt77/test_packjt77_hash_vectors.f90
new file mode 100644
index 00000000..09ea0779
--- /dev/null
+++ b/tests/unit/packjt77/test_packjt77_hash_vectors.f90
@@ -0,0 +1,77 @@
+program test_packjt77_hash_vectors
+
+ use packjt77
+ implicit none
+
+ integer :: ntests
+
+ ntests=0
+
+ call expect_hash_vector('K1ABC', 712, 2851, 2920267)
+ call expect_hash_vector('W9XYZ', 972, 3889, 3982604)
+ call expect_hash_vector('PJ4/K1ABC', 346, 1387, 1420834)
+ call expect_hash_vector('KH1/KH7Z', 201, 806, 825805)
+ call expect_hash_vector('K1JT/P', 959, 3839, 3931158)
+ call expect_hash_vector('W3CCX', 665, 2662, 2726483)
+ call expect_hash_vector('3DA0ABC', 48, 192, 196695)
+ call expect_hash_vector('3XABC', 563, 2254, 2308721)
+ call expect_hash_vector('///////////', 671, 2685, 2749801)
+ call expect_hash_vector('ZZZZZZZZZZZ', 902, 3609, 3695718)
+ call expect_hash_vector('99999999999', 762, 3050, 3123740)
+ call expect_hash_vector('A23456789Z/', 122, 488, 499902)
+ call expect_hash_vector(' ', 0, 0, 0)
+
+ write(*,1000) ntests
+1000 format('packjt77 hash vector tests passed: ',i0)
+
+contains
+
+ subroutine expect_hash_vector(callsign,want10,want12,want22)
+ character(len=*), intent(in) :: callsign
+ integer, intent(in) :: want10, want12, want22
+ character(len=13) :: c13
+ integer :: got10, got12, got22
+ integer :: got10var, got12var, got22var
+
+ c13=' '
+ c13=callsign
+ got10=ihashcall(c13,10)
+ got12=ihashcall(c13,12)
+ got22=ihashcall(c13,22)
+ got10var=ihashcallvar(c13,10)
+ got12var=ihashcallvar(c13,12)
+ got22var=ihashcallvar(c13,22)
+
+ if(got10.ne.want10 .or. got12.ne.want12 .or. got22.ne.want22) then
+ write(*,1010) trim(callsign), got10, got12, got22, want10, want12, want22
+1010 format('Hash vector failure for "',a,'"; got ',i0,1x,i0,1x,i0, &
+ ' wanted ',i0,1x,i0,1x,i0)
+ error stop 1
+ endif
+
+ if(got10var.ne.want10 .or. got12var.ne.want12 .or. got22var.ne.want22) then
+ write(*,1020) trim(callsign), got10var, got12var, got22var, &
+ want10, want12, want22
+1020 format('Var hash vector failure for "',a,'"; got ',i0,1x,i0,1x,i0, &
+ ' wanted ',i0,1x,i0,1x,i0)
+ error stop 1
+ endif
+
+ if(got10.ne.got10var .or. got12.ne.got12var .or. got22.ne.got22var) then
+ write(*,1030) trim(callsign), got10, got12, got22, got10var, got12var, got22var
+1030 format('Hash helper mismatch for "',a,'"; standard ',i0,1x,i0,1x,i0, &
+ ' var ',i0,1x,i0,1x,i0)
+ error stop 1
+ endif
+
+ if(got10.lt.0 .or. got10.gt.1023 .or. got12.lt.0 .or. got12.gt.4095 .or. &
+ got22.lt.0 .or. got22.gt.4194303) then
+ write(*,1040) trim(callsign), got10, got12, got22
+1040 format('Hash range failure for "',a,'"; got ',i0,1x,i0,1x,i0)
+ error stop 1
+ endif
+
+ ntests=ntests+1
+ end subroutine expect_hash_vector
+
+end program test_packjt77_hash_vectors