diff options
author | Kevin Murray <spam@kdmurray.id.au> | 2014-03-03 12:16:36 +1100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-03-03 09:58:01 -0500 |
commit | 4deae59e1cc5f259c7e22d7f7a294ad46e5e0b21 (patch) | |
tree | e904c85d5534db6f8503d6d437ba083800b9d371 /src/test/test_addr.c | |
parent | 1afa52349cfc2ccc968e0d33b549a6eff4fc4127 (diff) | |
download | tor-4deae59e1cc5f259c7e22d7f7a294ad46e5e0b21.tar.gz tor-4deae59e1cc5f259c7e22d7f7a294ad46e5e0b21.zip |
add test for tor_addr_make_null
Signed-off-by: Kevin Murray <spam@kdmurray.id.au>
Diffstat (limited to 'src/test/test_addr.c')
-rw-r--r-- | src/test/test_addr.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/test/test_addr.c b/src/test/test_addr.c index 79ddd95090..f921343979 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 }; |