aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_routerset.c
diff options
context:
space:
mode:
authorNeel Chauhan <neel@neelc.org>2020-06-22 11:51:01 -0700
committerNick Mathewson <nickm@torproject.org>2020-06-24 13:38:27 -0400
commitc3c7ef5125fe1db59f6017390e6b068b1faaad27 (patch)
tree56a6d13d25bec529d13eac16b1caa0104be5af32 /src/test/test_routerset.c
parent6209939e864e5bfb951cb0406c24a85c27a7811a (diff)
downloadtor-c3c7ef5125fe1db59f6017390e6b068b1faaad27.tar.gz
tor-c3c7ef5125fe1db59f6017390e6b068b1faaad27.zip
Add routerset_contains_router() test
Diffstat (limited to 'src/test/test_routerset.c')
-rw-r--r--src/test/test_routerset.c56
1 files changed, 55 insertions, 1 deletions
diff --git a/src/test/test_routerset.c b/src/test/test_routerset.c
index 892ac6e210..7601d5ba0f 100644
--- a/src/test/test_routerset.c
+++ b/src/test/test_routerset.c
@@ -1417,12 +1417,62 @@ test_rset_contains_router(void *arg)
ri.nickname = (char *)nickname;
r = routerset_contains_router(set, &ri, country);
-
tt_int_op(r, OP_EQ, 4);
+
done:
routerset_free(set);
}
+static void
+test_rset_contains_router_ipv4(void *arg)
+{
+ routerset_t *set;
+ routerinfo_t ri;
+ country_t country = 1;
+ int r;
+ const char *s;
+ (void) arg;
+
+ /* IPv4 address test. */
+ memset(&ri, 0, sizeof(ri));
+ set = routerset_new();
+ s = "10.0.0.1";
+ r = routerset_parse(set, s, "");
+ ri.addr = htonl(0x0a000001); /* 10.0.0.1 */
+ ri.or_port = 1234;
+
+ r = routerset_contains_router(set, &ri, country);
+ tt_int_op(r, OP_EQ, 3);
+
+ done:
+ routerset_free(set);
+}
+
+static void
+test_rset_contains_router_ipv6(void *arg)
+{
+ routerset_t *set;
+ routerinfo_t ri;
+ country_t country = 1;
+ int r;
+ const char *s;
+ (void) arg;
+
+ /* IPv6 address test. */
+ memset(&ri, 0, sizeof(ri));
+ set = routerset_new();
+ s = "2600::1";
+ r = routerset_parse(set, s, "");
+ tor_addr_parse(&ri.ipv6_addr, "2600::1");
+ ri.ipv6_orport = 12345;
+
+ r = routerset_contains_router(set, &ri, country);
+ tt_int_op(r, OP_EQ, 3);
+
+ done:
+ routerset_free(set);
+}
+
/*
* Functional test for routerset_contains_routerstatus.
*/
@@ -2144,6 +2194,10 @@ struct testcase_t routerset_tests[] = {
{ "contains_extendinfo", test_rset_contains_extendinfo,
TT_FORK, NULL, NULL },
{ "contains_router", test_rset_contains_router, TT_FORK, NULL, NULL },
+ { "contains_router_ipv4", test_rset_contains_router_ipv4,
+ TT_FORK, NULL, NULL },
+ { "contains_router_ipv6", test_rset_contains_router_ipv6,
+ TT_FORK, NULL, NULL },
{ "contains_routerstatus", test_rset_contains_routerstatus,
TT_FORK, NULL, NULL },
{ "contains_none", test_rset_contains_none, TT_FORK, NULL, NULL },