test: unit: add test for M17 Callsign class

This commit is contained in:
Ryan Turner 2025-10-22 14:43:43 -05:00 committed by Silvano Seva
parent fdbe3f2583
commit edbe038329
4 changed files with 98 additions and 0 deletions

View File

@ -121,6 +121,8 @@ jobs:
run: meson test -C build "M17 Golay Unit Test" run: meson test -C build "M17 Golay Unit Test"
- name: M17 RRC Test - name: M17 RRC Test
run: meson test -C build "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 - name: Codeplug Test
run: meson test -C build "Codeplug Test" run: meson test -C build "Codeplug Test"
- name: minmea Conversion Test - name: minmea Conversion Test

View File

@ -1058,6 +1058,10 @@ m17_viterbi_test = executable('m17_viterbi_test',
sources : unit_test_src + ['tests/unit/M17_viterbi.cpp'], sources : unit_test_src + ['tests/unit/M17_viterbi.cpp'],
kwargs : unit_test_opts) 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', m17_demodulator_test = executable('m17_demodulator_test',
sources: unit_test_src + ['tests/unit/M17_demodulator.cpp'], sources: unit_test_src + ['tests/unit/M17_demodulator.cpp'],
kwargs: unit_test_opts) 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 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 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 RRC Test', m17_rrc_test)
test('M17 Callsign Unit Test', m17_callsign_test)
test('Codeplug Test', cps_test) test('Codeplug Test', cps_test)
## test('Linux InputStream Test', linux_inputStream_test) ## test('Linux InputStream Test', linux_inputStream_test)
## test('Sine Test', sine_test) ## test('Sine Test', sine_test)

View File

@ -92,6 +92,7 @@ platform/targets/linux/emulator/sdl_engine.h
platform/targets/ttwrplus/pmu.h platform/targets/ttwrplus/pmu.h
tests/platform/mic_test.c tests/platform/mic_test.c
tests/platform/codec2_encode_test.c tests/platform/codec2_encode_test.c
tests/unit/M17_callsign.cpp
EOF EOF
) )

View File

@ -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 <http://www.gnu.org/licenses/> *
***************************************************************************/
#include <cstdio>
#include <cstdint>
#include <cstring>
#include <array>
#include <algorithm>
#include <iostream>
#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;
}