hamnet70/impl/test/test_ham64.c

60 lines
1.6 KiB
C
Raw Normal View History

/*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Copyright (C) 2024 Thomas Kolb
* Copyright (C) 2024 Simon Ruderich
*/
#include <assert.h>
#include <stdbool.h>
2024-07-01 20:58:20 +02:00
#include <stdio.h>
#include <string.h>
#include <layer2/ham64.h>
bool test_decode(const char *ref, const char *exp_fmt, const char *exp_type, const ham64_t *ham64)
2024-07-01 20:58:20 +02:00
{
char decoded[13] = {0};
2024-07-01 20:58:20 +02:00
char ham64_format_buf[HAM64_FMT_MAX_LEN];
size_t decoded_len = ham64_decode_callsign(ham64, decoded);
ham64_format(ham64, ham64_format_buf);
const char *typestr = ham64_addr_type_to_string(ham64_get_addr_type(ham64));
printf("»%s« → [%u] %s (%s) → [%zd] »%s«\n", ref, ham64->length, ham64_format_buf, typestr, decoded_len, decoded);
return strcmp(ref, decoded) == 0
&& strcmp(exp_fmt, ham64_format_buf) == 0
&& strcmp(exp_type, typestr) == 0;
2024-07-01 20:58:20 +02:00
}
bool test_call(const char *call, const char *exp_fmt)
2024-07-01 20:58:20 +02:00
{
ham64_t ham64;
ham64_encode(call, &ham64);
return test_decode(call, exp_fmt, "CALLSIGN", &ham64);
2024-07-01 20:58:20 +02:00
}
int main(void)
{
char *call1 = "VI2BMARC50-X";
char *call2 = "DL5TKL/T";
char *call3 = "D9K";
ham64_t empty = {{0x0000, 0x0, 0x0, 0x0}, 1};
ham64_t short_1 = {{0x0001, 0x0, 0x0, 0x0}, 1};
ham64_t short_last = {{0x063F, 0x0, 0x0, 0x0}, 1};
ham64_t broadcast = {{0xFFFF, 0x0, 0x0, 0x0}, 1};
assert(test_call(call1, "8B05-0E89-7118-AEC8"));
assert(test_call(call2, "1B00-7EC4-EA60"));
assert(test_call(call3, "1EAB"));
2024-07-01 20:58:20 +02:00
assert(test_decode("", "0000", "EMPTY", &empty));
assert(test_decode("", "0001", "TMP_SHORT", &short_1));
assert(test_decode("", "063F", "TMP_SHORT", &short_last));
assert(test_decode("", "FFFF", "BROADCAST", &broadcast));
2024-07-01 20:58:20 +02:00
}