diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-03-18 15:29:32 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-03-18 15:29:32 -0400 |
commit | a88f3e24eaf2180ac2f374df81b0261661774c5f (patch) | |
tree | a2da83c98d63104d5fc165aa201232f0cadd8c8e /src/test/test_addr.c | |
parent | 67709398b6bb1cea68b8c2a0060b251e8dfa86ee (diff) | |
parent | 2ac66e59f7b32bb7f975803c9d483848e755a08f (diff) | |
download | tor-a88f3e24eaf2180ac2f374df81b0261661774c5f.tar.gz tor-a88f3e24eaf2180ac2f374df81b0261661774c5f.zip |
Merge remote-tracking branch 'origin/maint-0.2.4'
Conflicts:
src/test/test_addr.c
Diffstat (limited to 'src/test/test_addr.c')
-rw-r--r-- | src/test/test_addr.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/test/test_addr.c b/src/test/test_addr.c index f182bca195..106f921c5d 100644 --- a/src/test/test_addr.c +++ b/src/test/test_addr.c @@ -937,6 +937,41 @@ test_addr_sockaddr_to_str(void *arg) tor_free(v); } +static void +test_addr_is_loopback(void *data) +{ + static const struct loopback_item { + const char *name; + int is_loopback; + } loopback_items[] = { + { "::1", 1 }, + { "127.0.0.1", 1 }, + { "127.99.100.101", 1 }, + { "128.99.100.101", 0 }, + { "8.8.8.8", 0 }, + { "0.0.0.0", 0 }, + { "::2", 0 }, + { "::", 0 }, + { "::1.0.0.0", 0 }, + { NULL, 0 } + }; + + int i; + tor_addr_t addr; + (void)data; + + for (i=0; loopback_items[i].name; ++i) { + tt_int_op(tor_addr_parse(&addr, loopback_items[i].name), >=, 0); + tt_int_op(tor_addr_is_loopback(&addr), ==, loopback_items[i].is_loopback); + } + + tor_addr_make_unspec(&addr); + tt_int_op(tor_addr_is_loopback(&addr), ==, 0); + + done: + ; +} + #define ADDR_LEGACY(name) \ { #name, legacy_test_helper, 0, &legacy_setup, test_addr_ ## name } @@ -948,6 +983,7 @@ struct testcase_t addr_tests[] = { { "localname", test_addr_localname, 0, NULL, NULL }, { "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 }, END_OF_TESTCASES }; |