aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_address.c
diff options
context:
space:
mode:
authorrl1987 <rl1987@sdf.lonestar.org>2015-02-22 17:04:22 +0200
committerNick Mathewson <nickm@torproject.org>2015-03-31 14:37:01 -0400
commit6af471f3944a91646db8b7ea0a915ed2f87cd705 (patch)
treef04a08cbdcfd6976756ccc6c1a64b461b5efcc10 /src/test/test_address.c
parenta13f944314d7f2a71cc4d28546d88ebfe34aaf49 (diff)
downloadtor-6af471f3944a91646db8b7ea0a915ed2f87cd705.tar.gz
tor-6af471f3944a91646db8b7ea0a915ed2f87cd705.zip
Rework the black box test, like Yawning and nickm suggested.
Diffstat (limited to 'src/test/test_address.c')
-rw-r--r--src/test/test_address.c53
1 files changed, 31 insertions, 22 deletions
diff --git a/src/test/test_address.c b/src/test/test_address.c
index 57bd70cf18..a2193e1da7 100644
--- a/src/test/test_address.c
+++ b/src/test/test_address.c
@@ -473,42 +473,51 @@ smartlist_contain_tor_addr(smartlist_t *smartlist, tor_addr_t *tor_addr)
static void
test_address_udp_socket_trick_blackbox(void *arg)
{
- smartlist_t *all_addrs;
- tor_addr_t *addr4;
- tor_addr_t *addr6;
- int retval;
+ /* We want get_interface_address6_via_udp_socket_hack() to yield
+ * the same valid address that get_interface_address6() returns.
+ * If the latter is unable to find a valid address, we want
+ * _hack() to fail and return-1.
+ *
+ * Furthermore, we want _hack() never to crash, even if
+ * get_interface_addresses_raw() is returning NULL.
+ */
+
+ tor_addr_t addr4;
+ tor_addr_t addr4_to_check;
+ tor_addr_t addr6;
+ tor_addr_t addr6_to_check;
+ int retval, retval_reference;
(void)arg;
- addr4 = tor_malloc(sizeof(tor_addr_t));
- addr6 = tor_malloc(sizeof(tor_addr_t));
-
- all_addrs = get_interface_addresses_raw(LOG_DEBUG);
+ retval_reference = get_interface_address6(LOG_DEBUG,AF_INET,&addr4);
retval = get_interface_address6_via_udp_socket_hack(LOG_DEBUG,
- AF_INET,addr4);
-
- tt_assert(all_addrs);
- tt_assert(retval == 0);
+ AF_INET,
+ &addr4_to_check);
- tt_assert(smartlist_contain_tor_addr(all_addrs,addr4));
+ tt_int_op(retval,==,retval_reference);
+ tt_assert( (retval == -1 && retval_reference == -1) ||
+ (tor_addr_compare(&addr4,&addr4_to_check,CMP_EXACT) == 0) );
-#if 0
+ retval_reference = get_interface_address6(LOG_DEBUG,AF_INET6,&addr6);
retval = get_interface_address6_via_udp_socket_hack(LOG_DEBUG,
- AF_INET6,addr6);
+ AF_INET6,
+ &addr6_to_check);
- tt_assert(smartlist_contain_tor_addr(all_addrs,addr6));
-#endif
+ tt_int_op(retval,==,retval_reference);
+ tt_assert( (retval == -1 && retval_reference == -1) ||
+ (tor_addr_compare(&addr6,&addr6_to_check,CMP_EXACT) == 0) );
+
+ /* When family is neither AF_INET nor AF_INET6, we want _hack to
+ * fail and return -1.
+ */
retval = get_interface_address6_via_udp_socket_hack(LOG_DEBUG,
- AF_CCITT,addr4);
+ AF_CCITT,&addr4);
tt_assert(retval == -1);
done:
- tor_free(addr4);
- tor_free(addr6);
- SMARTLIST_FOREACH(all_addrs, tor_addr_t *, t, tor_free(t));
- smartlist_free(all_addrs);
return;
}