#include #include #include #include #include bool test_decode(const char *ref, const char *exp_fmt, const char *exp_type, const ham64_t *ham64) { char decoded[13] = {0}; 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; } bool test_call(const char *call, const char *exp_fmt) { ham64_t ham64; ham64_encode(call, &ham64); return test_decode(call, exp_fmt, "CALLSIGN", &ham64); } 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")); 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)); }