diff options
author | George Kadianakis <desnacked@riseup.net> | 2012-11-28 00:24:58 +0200 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-11-27 22:18:08 -0500 |
commit | 6f21d2e49657ada264cace9da7cf6945b4fc073d (patch) | |
tree | b31176e1421128aa2b5a270abb8ff9e4a560e4cc /src/test/test_addr.c | |
parent | f88c3038697b00f50b2da12f46fc76ee0e20d646 (diff) | |
download | tor-6f21d2e49657ada264cace9da7cf6945b4fc073d.tar.gz tor-6f21d2e49657ada264cace9da7cf6945b4fc073d.zip |
Introduce tor_addr_port_parse() and use it to parse ServerTransportListenAddr.
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 0dcc0174a8..065ca58fe3 100644 --- a/src/test/test_addr.c +++ b/src/test/test_addr.c @@ -623,12 +623,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 }; |