diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-11-27 22:18:16 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-11-27 22:18:16 -0500 |
commit | 190c1d4981e5751aabd3d894095851c830f1d570 (patch) | |
tree | a832d932339382cb7f43fb33a255d7507e037c2e /src/test/test_addr.c | |
parent | 267c0e5aa14deeb2ca0d7997b4ef5a5c2bbf5fd4 (diff) | |
parent | 6f21d2e49657ada264cace9da7cf6945b4fc073d (diff) | |
download | tor-190c1d4981e5751aabd3d894095851c830f1d570.tar.gz tor-190c1d4981e5751aabd3d894095851c830f1d570.zip |
Merge branch 'bug7013_take2_squashed'
Diffstat (limited to 'src/test/test_addr.c')
-rw-r--r-- | src/test/test_addr.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/test/test_addr.c b/src/test/test_addr.c index 6d0fe5afdf..586ceb6102 100644 --- a/src/test/test_addr.c +++ b/src/test/test_addr.c @@ -721,12 +721,65 @@ test_addr_ip6_helpers(void) ; } +/** Test tor_addr_port_parse(). */ +static void +test_addr_parse(void) +{ + int r; + tor_addr_t addr; + char buf[TOR_ADDR_BUF_LEN]; + uint16_t port = 0; + + /* Correct call. */ + r= tor_addr_port_parse(LOG_DEBUG, + "192.0.2.1:1234", + &addr, &port); + test_assert(r == 0); + tor_addr_to_str(buf, &addr, sizeof(buf), 0); + test_streq(buf, "192.0.2.1"); + test_eq(port, 1234); + + /* Domain name. */ + r= tor_addr_port_parse(LOG_DEBUG, + "torproject.org:1234", + &addr, &port); + test_assert(r == -1); + + /* Only IP. */ + r= tor_addr_port_parse(LOG_DEBUG, + "192.0.2.2", + &addr, &port); + test_assert(r == -1); + + /* Bad port. */ + r= tor_addr_port_parse(LOG_DEBUG, + "192.0.2.2:66666", + &addr, &port); + test_assert(r == -1); + + /* Only domain name */ + r= tor_addr_port_parse(LOG_DEBUG, + "torproject.org", + &addr, &port); + test_assert(r == -1); + + /* Bad IP address */ + r= tor_addr_port_parse(LOG_DEBUG, + "192.0.2:1234", + &addr, &port); + test_assert(r == -1); + + done: + ; +} + #define ADDR_LEGACY(name) \ { #name, legacy_test_helper, 0, &legacy_setup, test_addr_ ## name } struct testcase_t addr_tests[] = { ADDR_LEGACY(basic), ADDR_LEGACY(ip6_helpers), + ADDR_LEGACY(parse), END_OF_TESTCASES }; |