diff options
author | Daniil Baturin <daniil@baturin.org> | 2013-06-03 13:36:54 -0700 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2013-06-03 13:36:54 -0700 |
commit | 8902fd3ba0a6b8e2d29543f0b54836e0a6537eec (patch) | |
tree | a894ab6f4dc8ecebbf5d89f2564fc1a8a04a4c3b | |
parent | a264db8958c97725c69cefcb2ab2b0967a65a5eb (diff) | |
download | ipaddrcheck-8902fd3ba0a6b8e2d29543f0b54836e0a6537eec.tar.gz ipaddrcheck-8902fd3ba0a6b8e2d29543f0b54836e0a6537eec.zip |
Add unit tests for is_any_host() and is_any_net().
-rw-r--r-- | tests/check_ipaddrcheck.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/check_ipaddrcheck.c b/tests/check_ipaddrcheck.c index 9315bec..8a4a869 100644 --- a/tests/check_ipaddrcheck.c +++ b/tests/check_ipaddrcheck.c @@ -353,8 +353,54 @@ START_TEST (test_is_valid_intf_address) CIDR* good_address_v6 = cidr_from_str(good_address_str_v6); ck_assert_int_eq(is_valid_intf_address(good_address_v6, good_address_str_v6, NO_LOOPBACK), RESULT_SUCCESS); cidr_free(good_address_v6); +} +END_TEST +START_TEST (test_is_any_host) +{ + char* good_address_str_v4 = "192.0.2.1/25"; + CIDR* good_address_v4 = cidr_from_str(good_address_str_v4); + ck_assert_int_eq(is_any_host(good_address_v4), RESULT_SUCCESS); + cidr_free(good_address_v4); + char* good_address_str_v6 = "2001:db8:aff::1/64"; + CIDR* good_address_v6 = cidr_from_str(good_address_str_v6); + ck_assert_int_eq(is_any_host(good_address_v6), RESULT_SUCCESS); + cidr_free(good_address_v6); + + char* bad_address_str_v4 = "192.0.2.0/24"; + CIDR* bad_address_v4 = cidr_from_str(bad_address_str_v4); + ck_assert_int_eq(is_any_host(bad_address_v4), RESULT_FAILURE); + cidr_free(bad_address_v4); + + char* bad_address_str_v6 = "2001:db8::/32"; + CIDR* bad_address_v6 = cidr_from_str(bad_address_str_v6); + ck_assert_int_eq(is_any_host(bad_address_v6), RESULT_FAILURE); + cidr_free(bad_address_v6); +} +END_TEST + +START_TEST (test_is_any_net) +{ + char* good_address_str_v4 = "192.0.2.0/25"; + CIDR* good_address_v4 = cidr_from_str(good_address_str_v4); + ck_assert_int_eq(is_any_net(good_address_v4), RESULT_SUCCESS); + cidr_free(good_address_v4); + + char* good_address_str_v6 = "2001:db8:aff::/64"; + CIDR* good_address_v6 = cidr_from_str(good_address_str_v6); + ck_assert_int_eq(is_any_net(good_address_v6), RESULT_SUCCESS); + cidr_free(good_address_v6); + + char* bad_address_str_v4 = "192.0.2.33/24"; + CIDR* bad_address_v4 = cidr_from_str(bad_address_str_v4); + ck_assert_int_eq(is_any_net(bad_address_v4), RESULT_FAILURE); + cidr_free(bad_address_v4); + + char* bad_address_str_v6 = "2001:db8::1/32"; + CIDR* bad_address_v6 = cidr_from_str(bad_address_str_v6); + ck_assert_int_eq(is_any_net(bad_address_v6), RESULT_FAILURE); + cidr_free(bad_address_v6); } END_TEST @@ -386,6 +432,8 @@ Suite *ipaddrcheck_suite(void) tcase_add_test(tc_core, test_is_ipv6_multicast); tcase_add_test(tc_core, test_is_ipv6_link_local); tcase_add_test(tc_core, test_is_valid_intf_address); + tcase_add_test(tc_core, test_is_any_host); + tcase_add_test(tc_core, test_is_any_net); suite_add_tcase(s, tc_core); |