1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include "srunner.h"
#include "netcfg.h"
START_TEST(test_inet_mton_v4_24)
{
struct in_addr addr;
uint8_t expected[] = { 0xff, 0xff, 0xff, 0 };
inet_mton(AF_INET, 24, &addr);
ck_assert_msg (memcmp(expected, &(addr.s_addr), 4) == 0,
"Mask address wasn't 24 bits");
}
END_TEST
START_TEST(test_inet_mton_v4_22)
{
struct in_addr addr;
uint8_t expected[] = { 0xff, 0xff, 0xfc, 0 };
inet_mton(AF_INET, 22, &addr);
ck_assert_msg (memcmp(expected, &(addr.s_addr), 4) == 0,
"Mask address wasn't 22 bits");
}
END_TEST
START_TEST(test_inet_mton_v6_64)
{
struct in6_addr addr;
uint8_t expected[] = { 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff,
0, 0, 0, 0, 0, 0, 0, 0 };
inet_mton(AF_INET6, 64, &addr);
ck_assert_msg (memcmp(expected, addr.s6_addr, 16) == 0,
"Mask address wasn't 64 bits");
}
END_TEST
START_TEST(test_inet_mton_v6_60)
{
struct in6_addr addr;
uint8_t expected[] = { 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xf0,
0, 0, 0, 0, 0, 0, 0, 0 };
inet_mton(AF_INET6, 60, &addr);
ck_assert_msg (memcmp(expected, addr.s6_addr, 16) == 0,
"Mask address wasn't 60 bits");
}
END_TEST
Suite *test_inet_mton_suite (void)
{
Suite *s = suite_create ("inet_mton");
TCase *tc = tcase_create ("inet_mton");
tcase_add_test (tc, test_inet_mton_v4_24);
tcase_add_test (tc, test_inet_mton_v4_22);
tcase_add_test (tc, test_inet_mton_v6_64);
tcase_add_test (tc, test_inet_mton_v6_60);
suite_add_tcase (s, tc);
return s;
}
|