diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e612a009..a397880d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -121,6 +121,8 @@ jobs: run: meson test -C build "M17 Golay Unit Test" - name: M17 RRC Test run: meson test -C build "M17 RRC Test" + - name: M17 Callsign Unit Test + run: meson test -C build "M17 Callsign Unit Test" - name: Codeplug Test run: meson test -C build "Codeplug Test" - name: minmea Conversion Test diff --git a/meson.build b/meson.build index 2867d53f..1f85f8a2 100644 --- a/meson.build +++ b/meson.build @@ -1058,6 +1058,10 @@ m17_viterbi_test = executable('m17_viterbi_test', sources : unit_test_src + ['tests/unit/M17_viterbi.cpp'], kwargs : unit_test_opts) +m17_callsign_test = executable('m17_callsign_test', + sources : unit_test_src + ['tests/unit/M17_callsign.cpp'], + kwargs : unit_test_opts) + m17_demodulator_test = executable('m17_demodulator_test', sources: unit_test_src + ['tests/unit/M17_demodulator.cpp'], kwargs: unit_test_opts) @@ -1090,6 +1094,7 @@ test('M17 Golay Unit Test', m17_golay_test) test('M17 Viterbi Unit Test', m17_viterbi_test) ## test('M17 Demodulator Test', m17_demodulator_test) # Skipped for now as this test no longer works after an M17 refactor test('M17 RRC Test', m17_rrc_test) +test('M17 Callsign Unit Test', m17_callsign_test) test('Codeplug Test', cps_test) ## test('Linux InputStream Test', linux_inputStream_test) ## test('Sine Test', sine_test) diff --git a/scripts/clang_format.sh b/scripts/clang_format.sh index 55f4e80d..21f7cc8c 100755 --- a/scripts/clang_format.sh +++ b/scripts/clang_format.sh @@ -92,6 +92,7 @@ platform/targets/linux/emulator/sdl_engine.h platform/targets/ttwrplus/pmu.h tests/platform/mic_test.c tests/platform/codec2_encode_test.c +tests/unit/M17_callsign.cpp EOF ) diff --git a/tests/unit/M17_callsign.cpp b/tests/unit/M17_callsign.cpp new file mode 100644 index 00000000..bd5217f0 --- /dev/null +++ b/tests/unit/M17_callsign.cpp @@ -0,0 +1,90 @@ +/*************************************************************************** + * Copyright (C) 2021 - 2025 by Federico Amedeo Izzo IU2NUO, * + * Niccolò Izzo IU2KIN * + * Frederik Saraci IU2NRO * + * Silvano Seva IU2KWO * + * * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, see * + ***************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include "protocols/M17/Callsign.hpp" +#include "protocols/M17/M17Datatypes.hpp" + +using namespace std; + +int test_encode_ab1cd() +{ + const char callsign[] = "AB1CD"; + M17::call_t expected = { 0x00, 0x00, 0x00, 0x9f, 0xdd, 0x51 }; + + M17::Callsign test = M17::Callsign(callsign); + M17::call_t actual = test; + if (equal(begin(actual), end(actual), begin(expected), end(expected))) { + return 0; + } else { + return -1; + } +} + +int test_encode_empty() +{ + const char callsign[] = ""; + M17::call_t expected = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + + M17::Callsign test = M17::Callsign(callsign); + M17::call_t actual = test; + if (equal(begin(actual), end(actual), begin(expected), end(expected))) { + return 0; + } else { + return -1; + } +} + +int test_decode_ab1cd() +{ + M17::call_t callsign = { 0x00, 0x00, 0x00, 0x9f, 0xdd, 0x51 }; + + M17::Callsign test = M17::Callsign(callsign); + const char expected[] = "AB1CD"; + const char *actual = test; + if (strcmp(expected, actual) == 0) { + return 0; + } else { + return -1; + } +} + +int main() +{ + if (test_encode_ab1cd()) { + printf("Error in encoding callsign ab1cd!\n"); + return -1; + } + if (test_encode_empty()) { + printf("Error in encoding empty callsign !\n"); + return -1; + } + if (test_decode_ab1cd()) { + printf("Error in decoding callsign ab1cd!\n"); + return -1; + } + return 0; +}