test_ham64: apply improvements by rudi_s
This commit is contained in:
parent
9a151e0cbb
commit
212da1f78e
|
@ -1,13 +1,13 @@
|
|||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <layer2/ham64.h>
|
||||
|
||||
bool test_decode(const char *ref, const ham64_t *ham64)
|
||||
bool test_decode(const char *ref, const char *exp_fmt, const char *exp_type, const ham64_t *ham64)
|
||||
{
|
||||
char decoded[13];
|
||||
decoded[12] = 0;
|
||||
char decoded[13] = {0};
|
||||
|
||||
char ham64_format_buf[HAM64_FMT_MAX_LEN];
|
||||
|
||||
|
@ -17,15 +17,17 @@ bool test_decode(const char *ref, const ham64_t *ham64)
|
|||
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;
|
||||
return strcmp(ref, decoded) == 0
|
||||
&& strcmp(exp_fmt, ham64_format_buf) == 0
|
||||
&& strcmp(exp_type, typestr) == 0;
|
||||
}
|
||||
|
||||
bool test_call(const char *call)
|
||||
bool test_call(const char *call, const char *exp_fmt)
|
||||
{
|
||||
ham64_t ham64;
|
||||
|
||||
ham64_encode(call, &ham64);
|
||||
return test_decode(call, &ham64);
|
||||
return test_decode(call, exp_fmt, "CALLSIGN", &ham64);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
@ -39,12 +41,12 @@ int main(void)
|
|||
ham64_t short_last = {{0x063F, 0x0, 0x0, 0x0}, 1};
|
||||
ham64_t broadcast = {{0xFFFF, 0x0, 0x0, 0x0}, 1};
|
||||
|
||||
test_call(call1);
|
||||
test_call(call2);
|
||||
test_call(call3);
|
||||
assert(test_call(call1, "8B05-0E89-7118-AEC8"));
|
||||
assert(test_call(call2, "1B00-7EC4-EA60"));
|
||||
assert(test_call(call3, "1EAB"));
|
||||
|
||||
test_decode("", &empty);
|
||||
test_decode("", &short_1);
|
||||
test_decode("", &short_last);
|
||||
test_decode("", &broadcast);
|
||||
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));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue