commit 4deae59e1cc5f259c7e22d7f7a294ad46e5e0b21
Author: Kevin Murray <spam(a)kdmurray.id.au>
Date: Mon Mar 3 12:16:36 2014 +1100
add test for tor_addr_make_null
Signed-off-by: Kevin Murray <spam(a)kdmurray.id.au>
---
src/test/test_addr.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/src/test/test_addr.c b/src/test/test_addr.c
index 79ddd95..f921343 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
};