[tor-commits] [tor/master] Add routerset_contains_router() test

nickm at torproject.org nickm at torproject.org
Wed Jun 24 17:41:07 UTC 2020


commit c3c7ef5125fe1db59f6017390e6b068b1faaad27
Author: Neel Chauhan <neel at neelc.org>
Date:   Mon Jun 22 11:51:01 2020 -0700

    Add routerset_contains_router() test
---
 src/test/test_routerset.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 55 insertions(+), 1 deletion(-)

diff --git a/src/test/test_routerset.c b/src/test/test_routerset.c
index 892ac6e21..7601d5ba0 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 },





More information about the tor-commits mailing list