mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2024-11-25 08:48:31 -05:00
tests: Module tests for common.c
Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
56a1180153
commit
2eb64ea437
@ -85,6 +85,15 @@ static int printf_encode_decode_tests(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (printf_decode(bin, 3, "abcde") != 2)
|
||||
errors++;
|
||||
|
||||
if (printf_decode(bin, 3, "\\xa") != 1 || bin[0] != 10)
|
||||
errors++;
|
||||
|
||||
if (printf_decode(bin, 3, "\\a") != 1 || bin[0] != 'a')
|
||||
errors++;
|
||||
|
||||
if (errors) {
|
||||
wpa_printf(MSG_ERROR, "%d printf test(s) failed", errors);
|
||||
return -1;
|
||||
@ -324,6 +333,77 @@ static int base64_tests(void)
|
||||
}
|
||||
|
||||
|
||||
static int common_tests(void)
|
||||
{
|
||||
char buf[3];
|
||||
u8 addr[ETH_ALEN] = { 1, 2, 3, 4, 5, 6 };
|
||||
u8 bin[3];
|
||||
int errors = 0;
|
||||
struct wpa_freq_range_list ranges;
|
||||
|
||||
wpa_printf(MSG_INFO, "common tests");
|
||||
|
||||
if (hwaddr_mask_txt(buf, 3, addr, addr) != -1)
|
||||
errors++;
|
||||
|
||||
if (wpa_scnprintf(buf, 0, "hello") != 0 ||
|
||||
wpa_scnprintf(buf, 3, "hello") != 2)
|
||||
errors++;
|
||||
|
||||
if (wpa_snprintf_hex(buf, 0, addr, ETH_ALEN) != 0 ||
|
||||
wpa_snprintf_hex(buf, 3, addr, ETH_ALEN) != 2)
|
||||
errors++;
|
||||
|
||||
if (merge_byte_arrays(bin, 3, addr, ETH_ALEN, NULL, 0) != 3 ||
|
||||
merge_byte_arrays(bin, 3, NULL, 0, addr, ETH_ALEN) != 3)
|
||||
errors++;
|
||||
|
||||
if (dup_binstr(NULL, 0) != NULL)
|
||||
errors++;
|
||||
|
||||
if (freq_range_list_includes(NULL, 0) != 0)
|
||||
errors++;
|
||||
|
||||
os_memset(&ranges, 0, sizeof(ranges));
|
||||
if (freq_range_list_parse(&ranges, "") != 0 ||
|
||||
freq_range_list_includes(&ranges, 0) != 0 ||
|
||||
freq_range_list_str(&ranges) != NULL)
|
||||
errors++;
|
||||
|
||||
if (utf8_unescape(NULL, 0, buf, sizeof(buf)) != 0 ||
|
||||
utf8_unescape("a", 1, NULL, 0) != 0 ||
|
||||
utf8_unescape("a\\", 2, buf, sizeof(buf)) != 0 ||
|
||||
utf8_unescape("abcde", 5, buf, sizeof(buf)) != 0 ||
|
||||
utf8_unescape("abc", 3, buf, 3) != 3)
|
||||
errors++;
|
||||
|
||||
if (utf8_unescape("a", 0, buf, sizeof(buf)) != 1 || buf[0] != 'a')
|
||||
errors++;
|
||||
|
||||
if (utf8_unescape("\\b", 2, buf, sizeof(buf)) != 1 || buf[0] != 'b')
|
||||
errors++;
|
||||
|
||||
if (utf8_escape(NULL, 0, buf, sizeof(buf)) != 0 ||
|
||||
utf8_escape("a", 1, NULL, 0) != 0 ||
|
||||
utf8_escape("abcde", 5, buf, sizeof(buf)) != 0 ||
|
||||
utf8_escape("a\\bcde", 6, buf, sizeof(buf)) != 0 ||
|
||||
utf8_escape("ab\\cde", 6, buf, sizeof(buf)) != 0 ||
|
||||
utf8_escape("abc\\de", 6, buf, sizeof(buf)) != 0 ||
|
||||
utf8_escape("abc", 3, buf, 3) != 3)
|
||||
errors++;
|
||||
|
||||
if (utf8_escape("a", 0, buf, sizeof(buf)) != 1 || buf[0] != 'a')
|
||||
errors++;
|
||||
|
||||
if (errors) {
|
||||
wpa_printf(MSG_ERROR, "%d common test(s) failed", errors);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int utils_module_tests(void)
|
||||
{
|
||||
int ret = 0;
|
||||
@ -335,6 +415,7 @@ int utils_module_tests(void)
|
||||
trace_tests() < 0 ||
|
||||
bitfield_tests() < 0 ||
|
||||
base64_tests() < 0 ||
|
||||
common_tests() < 0 ||
|
||||
int_array_tests() < 0)
|
||||
ret = -1;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user