aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/test/test_addr.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/test/test_addr.c b/src/test/test_addr.c
index 79ddd9509..f92134397 100644
--- a/src/test/test_addr.c
+++ b/src/test/test_addr.c
@@ -971,6 +971,28 @@ test_addr_is_loopback(void *data)
;
}
+void
+test_addr_make_null(void *data)
+{
+ tor_addr_t *addr = tor_malloc(sizeof(*addr));
+ tor_addr_t *zeros = tor_calloc(1, sizeof(*addr));
+ /* Ensure that before tor_addr_make_null, addr != 0's */
+ memset(addr, 1, sizeof(*addr));
+ tt_int_op(memcmp(addr, zeros, sizeof(*addr)), !=, 0);
+ /* Test with AF == AF_INET */
+ zeros->family = AF_INET;
+ tor_addr_make_null(addr, AF_INET);
+ tt_int_op(memcmp(addr, zeros, sizeof(*addr)), ==, 0);
+ /* Test with AF == AF_INET6 */
+ memset(addr, 1, sizeof(*addr));
+ zeros->family = AF_INET6;
+ tor_addr_make_null(addr, AF_INET6);
+ tt_int_op(memcmp(addr, zeros, sizeof(*addr)), ==, 0);
+ done:
+ tor_free(addr);
+ tor_free(zeros);
+}
+
#define ADDR_LEGACY(name) \
{ #name, legacy_test_helper, 0, &legacy_setup, test_addr_ ## name }
@@ -983,6 +1005,7 @@ struct testcase_t addr_tests[] = {
{ "dup_ip", test_addr_dup_ip, 0, NULL, NULL },
{ "sockaddr_to_str", test_addr_sockaddr_to_str, 0, NULL, NULL },
{ "is_loopback", test_addr_is_loopback, 0, NULL, NULL },
+ { "make_null", test_addr_make_null, 0, NULL, NULL },
END_OF_TESTCASES
};