Add unit tests for wildcard, IPv4, IPv6 routerset parsing

Tests changes to enable IPv6 literals in routerset_parse in #17060.
Patch by "teor".
This commit is contained in:
teor (Tim Wilson-Brown) 2015-09-14 20:16:43 +10:00
parent c58b3726d6
commit 99d2869ab5

View File

@ -423,10 +423,10 @@ NS(test_main)(void *arg)
}
#undef NS_SUBMODULE
#define NS_SUBMODULE ASPECT(routerset_parse, policy)
#define NS_SUBMODULE ASPECT(routerset_parse, policy_wildcard)
/*
* Structural test for routerset_parse, when given a valid policy.
* Structural test for routerset_parse, when given a valid wildcard policy.
*/
NS_DECL(addr_policy_t *, router_parse_addr_policy_item_from_string,
@ -466,6 +466,96 @@ NS(router_parse_addr_policy_item_from_string)(const char *s, int assume_action)
return NS(mock_addr_policy);
}
#undef NS_SUBMODULE
#define NS_SUBMODULE ASPECT(routerset_parse, policy_ipv4)
/*
* Structural test for routerset_parse, when given a valid IPv4 address
* literal policy.
*/
NS_DECL(addr_policy_t *, router_parse_addr_policy_item_from_string,
(const char *s, int assume_action));
addr_policy_t *NS(mock_addr_policy);
static void
NS(test_main)(void *arg)
{
routerset_t *set;
const char *s;
int r;
(void)arg;
NS_MOCK(router_parse_addr_policy_item_from_string);
NS(mock_addr_policy) = tor_malloc_zero(sizeof(addr_policy_t));
set = routerset_new();
s = "127.0.0.1";
r = routerset_parse(set, s, "");
tt_int_op(r, OP_EQ, 0);
tt_int_op(smartlist_len(set->policies), OP_NE, 0);
tt_int_op(CALLED(router_parse_addr_policy_item_from_string), OP_EQ, 1);
done:
routerset_free(set);
}
addr_policy_t *
NS(router_parse_addr_policy_item_from_string)(const char *s, int assume_action)
{
(void)s;
(void)assume_action;
CALLED(router_parse_addr_policy_item_from_string)++;
return NS(mock_addr_policy);
}
#undef NS_SUBMODULE
#define NS_SUBMODULE ASPECT(routerset_parse, policy_ipv6)
/*
* Structural test for routerset_parse, when given a valid IPv6 address
* literal policy.
*/
NS_DECL(addr_policy_t *, router_parse_addr_policy_item_from_string,
(const char *s, int assume_action));
addr_policy_t *NS(mock_addr_policy);
static void
NS(test_main)(void *arg)
{
routerset_t *set;
const char *s;
int r;
(void)arg;
NS_MOCK(router_parse_addr_policy_item_from_string);
NS(mock_addr_policy) = tor_malloc_zero(sizeof(addr_policy_t));
set = routerset_new();
s = "::1";
r = routerset_parse(set, s, "");
tt_int_op(r, OP_EQ, 0);
tt_int_op(smartlist_len(set->policies), OP_NE, 0);
tt_int_op(CALLED(router_parse_addr_policy_item_from_string), OP_EQ, 1);
done:
routerset_free(set);
}
addr_policy_t *
NS(router_parse_addr_policy_item_from_string)(const char *s, int assume_action)
{
(void)s;
(void)assume_action;
CALLED(router_parse_addr_policy_item_from_string)++;
return NS(mock_addr_policy);
}
#undef NS_SUBMODULE
#define NS_SUBMODULE ASPECT(routerset_union, source_bad)
@ -2106,7 +2196,9 @@ struct testcase_t routerset_tests[] = {
TEST_CASE_ASPECT(routerset_parse, valid_hexdigest),
TEST_CASE_ASPECT(routerset_parse, valid_nickname),
TEST_CASE_ASPECT(routerset_parse, get_countryname),
TEST_CASE_ASPECT(routerset_parse, policy),
TEST_CASE_ASPECT(routerset_parse, policy_wildcard),
TEST_CASE_ASPECT(routerset_parse, policy_ipv4),
TEST_CASE_ASPECT(routerset_parse, policy_ipv6),
TEST_CASE(routerset_subtract_nodes),
TEST_CASE_ASPECT(routerset_subtract_nodes, null_routerset),
TEST_CASE(routerset_to_string),