diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-09-15 21:18:21 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-09-15 21:18:21 -0400 |
commit | 0243895792f937399839464ab5744b35734969a9 (patch) | |
tree | 991b6dbc5dfd1733283b5a07decc003b07879bae /src/test/test_addr.c | |
parent | 0bd220adcb82670893c85b1cc24d64e615855b4f (diff) | |
download | tor-0243895792f937399839464ab5744b35734969a9.tar.gz tor-0243895792f937399839464ab5744b35734969a9.zip |
Use coccinelle scripts to clean up our unit tests
This should get rid of most of the users of the old test_*
functions. Some are in macros and will need manual cleanup, though.
This patch is for 13119, and was automatically generated with these
scripts. The perl scripts are there because coccinelle hates
operators as macro arguments.
------------------------------
s/==,/_X_EQ_,/g;
s/!=,/_X_NE_,/g;
s/<,/_X_LT_,/g;
s/>,/_X_GT_,/g;
s/>=,/_X_GEQ_,/g;
s/<=,/_X_LEQ_,/g;
------------------------------
@@
expression a;
identifier func;
@@
func (...) {
<...
-test_fail_msg
+TT_DIE
(
+(
a
+)
)
...>
}
@@
identifier func;
@@
func (...) {
<...
-test_fail()
+TT_DIE(("Assertion failed."))
...>
}
@@
expression a;
identifier func;
@@
func (...) {
<...
-test_assert
+tt_assert
(a)
...>
}
@@
expression a, b;
identifier func;
@@
func (...) {
<...
-test_eq
+tt_int_op
(a,
+_X_EQ_,
b)
...>
}
@@
expression a, b;
identifier func;
@@
func (...) {
<...
-test_neq
+tt_int_op
(a,
+_X_NEQ_,
b)
...>
}
@@
expression a, b;
identifier func;
@@
func (...) {
<...
-test_streq
+tt_str_op
(a,
+_X_EQ_,
b)
...>
}
@@
expression a, b;
identifier func;
@@
func (...) {
<...
-test_strneq
+tt_str_op
(a,
+_X_NEQ_,
b)
...>
}
@@
expression a, b;
identifier func;
@@
func (...) {
<...
-test_eq_ptr
+tt_ptr_op
(a,
+_X_EQ_,
b)
...>
}
@@
expression a, b;
identifier func;
@@
func() {
<...
-test_neq_ptr
+tt_ptr_op
(a,
+_X_NEQ_,
b)
...>
}
@@
expression a, b, len;
identifier func;
@@
func (...) {
<...
-test_memeq
+tt_mem_op
(a,
+_X_EQ_,
b, len)
...>
}
@@
expression a, b, len;
identifier func;
@@
func (...) {
<...
-test_memneq
+tt_mem_op
(a,
+_X_NEQ_,
b, len)
...>
}
------------------------------
@@
char a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a == b
+a, _X_EQ_, b
)
...>
}
@@
int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a == b
+a, _X_EQ_, b
)
...>
}
@@
long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a == b
+a, _X_EQ_, b
)
...>
}
@@
unsigned int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a == b
+a, _X_EQ_, b
)
...>
}
@@
unsigned long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a == b
+a, _X_EQ_, b
)
...>
}
@@
char a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a != b
+a, _X_NEQ_, b
)
...>
}
@@
int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a != b
+a, _X_NEQ_, b
)
...>
}
@@
long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a != b
+a, _X_NEQ_, b
)
...>
}
@@
unsigned int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a != b
+a, _X_NEQ_, b
)
...>
}
@@
unsigned long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a != b
+a, _X_NEQ_, b
)
...>
}
@@
char a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a >= b
+a, _X_GEQ_, b
)
...>
}
@@
int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a >= b
+a, _X_GEQ_, b
)
...>
}
@@
long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a >= b
+a, _X_GEQ_, b
)
...>
}
@@
unsigned int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a >= b
+a, _X_GEQ_, b
)
...>
}
@@
unsigned long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a >= b
+a, _X_GEQ_, b
)
...>
}
@@
char a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a <= b
+a, _X_LEQ_, b
)
...>
}
@@
int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a <= b
+a, _X_LEQ_, b
)
...>
}
@@
long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a <= b
+a, _X_LEQ_, b
)
...>
}
@@
unsigned int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a <= b
+a, _X_LEQ_, b
)
...>
}
@@
unsigned long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a <= b
+a, _X_LEQ_, b
)
...>
}
@@
char a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a > b
+a, _X_GT_, b
)
...>
}
@@
int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a > b
+a, _X_GT_, b
)
...>
}
@@
long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a > b
+a, _X_GT_, b
)
...>
}
@@
unsigned int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a > b
+a, _X_GT_, b
)
...>
}
@@
unsigned long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a > b
+a, _X_GT_, b
)
...>
}
@@
char a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a < b
+a, _X_LT_, b
)
...>
}
@@
int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a < b
+a, _X_LT_, b
)
...>
}
@@
long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a < b
+a, _X_LT_, b
)
...>
}
@@
unsigned int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a < b
+a, _X_LT_, b
)
...>
}
@@
unsigned long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a < b
+a, _X_LT_, b
)
...>
}
------------------------------
s/_X_NEQ_/!=/g;
s/_X_NE_/!=/g;
s/_X_EQ_/==/g;
s/_X_GT_/>/g;
s/_X_LT_/</g;
s/_X_GEQ_/>=/g;
s/_X_LEQ_/<=/g;
s/test_mem_op\(/tt_mem_op\(/g;
Diffstat (limited to 'src/test/test_addr.c')
-rw-r--r-- | src/test/test_addr.c | 348 |
1 files changed, 174 insertions, 174 deletions
diff --git a/src/test/test_addr.c b/src/test/test_addr.c index 50011e606b..083ae2d061 100644 --- a/src/test/test_addr.c +++ b/src/test/test_addr.c @@ -18,41 +18,41 @@ test_addr_basic(void) /* Test addr_port_lookup */ cp = NULL; u32 = 3; u16 = 3; - test_assert(!addr_port_lookup(LOG_WARN, "1.2.3.4", &cp, &u32, &u16)); - test_streq(cp, "1.2.3.4"); - test_eq(u32, 0x01020304u); - test_eq(u16, 0); + tt_assert(!addr_port_lookup(LOG_WARN, "1.2.3.4", &cp, &u32, &u16)); + tt_str_op(cp,==, "1.2.3.4"); + tt_int_op(u32,==, 0x01020304u); + tt_int_op(u16,==, 0); tor_free(cp); - test_assert(!addr_port_lookup(LOG_WARN, "4.3.2.1:99", &cp, &u32, &u16)); - test_streq(cp, "4.3.2.1"); - test_eq(u32, 0x04030201u); - test_eq(u16, 99); + tt_assert(!addr_port_lookup(LOG_WARN, "4.3.2.1:99", &cp, &u32, &u16)); + tt_str_op(cp,==, "4.3.2.1"); + tt_int_op(u32,==, 0x04030201u); + tt_int_op(u16,==, 99); tor_free(cp); - test_assert(!addr_port_lookup(LOG_WARN, "nonexistent.address:4040", + tt_assert(!addr_port_lookup(LOG_WARN, "nonexistent.address:4040", &cp, NULL, &u16)); - test_streq(cp, "nonexistent.address"); - test_eq(u16, 4040); + tt_str_op(cp,==, "nonexistent.address"); + tt_int_op(u16,==, 4040); tor_free(cp); - test_assert(!addr_port_lookup(LOG_WARN, "localhost:9999", &cp, &u32, &u16)); - test_streq(cp, "localhost"); - test_eq(u32, 0x7f000001u); - test_eq(u16, 9999); + tt_assert(!addr_port_lookup(LOG_WARN, "localhost:9999", &cp, &u32, &u16)); + tt_str_op(cp,==, "localhost"); + tt_int_op(u32,==, 0x7f000001u); + tt_int_op(u16,==, 9999); tor_free(cp); u32 = 3; - test_assert(!addr_port_lookup(LOG_WARN, "localhost", NULL, &u32, &u16)); - test_eq_ptr(cp, NULL); - test_eq(u32, 0x7f000001u); - test_eq(u16, 0); + tt_assert(!addr_port_lookup(LOG_WARN, "localhost", NULL, &u32, &u16)); + tt_ptr_op(cp,==, NULL); + tt_int_op(u32,==, 0x7f000001u); + tt_int_op(u16,==, 0); tor_free(cp); - test_assert(addr_port_lookup(LOG_WARN, "localhost:3", &cp, &u32, NULL)); + tt_assert(addr_port_lookup(LOG_WARN, "localhost:3", &cp, &u32, NULL)); tor_free(cp); - test_eq(0, addr_mask_get_bits(0x0u)); - test_eq(32, addr_mask_get_bits(0xFFFFFFFFu)); - test_eq(16, addr_mask_get_bits(0xFFFF0000u)); - test_eq(31, addr_mask_get_bits(0xFFFFFFFEu)); - test_eq(1, addr_mask_get_bits(0x80000000u)); + tt_int_op(0,==, addr_mask_get_bits(0x0u)); + tt_int_op(32,==, addr_mask_get_bits(0xFFFFFFFFu)); + tt_int_op(16,==, addr_mask_get_bits(0xFFFF0000u)); + tt_int_op(31,==, addr_mask_get_bits(0xFFFFFFFEu)); + tt_int_op(1,==, addr_mask_get_bits(0x80000000u)); /* Test inet_ntop */ { @@ -61,15 +61,15 @@ test_addr_basic(void) struct in_addr in; /* good round trip */ - test_eq(tor_inet_pton(AF_INET, ip, &in), 1); - test_eq_ptr(tor_inet_ntop(AF_INET, &in, tmpbuf, sizeof(tmpbuf)), &tmpbuf); - test_streq(tmpbuf, ip); + tt_int_op(tor_inet_pton(AF_INET, ip, &in),==, 1); + tt_ptr_op(tor_inet_ntop(AF_INET, &in, tmpbuf, sizeof(tmpbuf)),==, &tmpbuf); + tt_str_op(tmpbuf,==, ip); /* just enough buffer length */ - test_streq(tor_inet_ntop(AF_INET, &in, tmpbuf, strlen(ip) + 1), ip); + tt_str_op(tor_inet_ntop(AF_INET, &in, tmpbuf, strlen(ip) + 1),==, ip); /* too short buffer */ - test_eq_ptr(tor_inet_ntop(AF_INET, &in, tmpbuf, strlen(ip)), NULL); + tt_ptr_op(tor_inet_ntop(AF_INET, &in, tmpbuf, strlen(ip)),==, NULL); } done: @@ -199,23 +199,23 @@ test_addr_ip6_helpers(void) const char *ip_ffff = "::ffff:192.168.1.2"; /* good round trip */ - test_eq(tor_inet_pton(AF_INET6, ip, &a1), 1); - test_eq_ptr(tor_inet_ntop(AF_INET6, &a1, buf, sizeof(buf)), &buf); - test_streq(buf, ip); + tt_int_op(tor_inet_pton(AF_INET6, ip, &a1),==, 1); + tt_ptr_op(tor_inet_ntop(AF_INET6, &a1, buf, sizeof(buf)),==, &buf); + tt_str_op(buf,==, ip); /* good round trip - ::ffff:0:0 style */ - test_eq(tor_inet_pton(AF_INET6, ip_ffff, &a2), 1); - test_eq_ptr(tor_inet_ntop(AF_INET6, &a2, buf, sizeof(buf)), &buf); - test_streq(buf, ip_ffff); + tt_int_op(tor_inet_pton(AF_INET6, ip_ffff, &a2),==, 1); + tt_ptr_op(tor_inet_ntop(AF_INET6, &a2, buf, sizeof(buf)),==, &buf); + tt_str_op(buf,==, ip_ffff); /* just long enough buffer (remember \0) */ - test_streq(tor_inet_ntop(AF_INET6, &a1, buf, strlen(ip)+1), ip); - test_streq(tor_inet_ntop(AF_INET6, &a2, buf, strlen(ip_ffff)+1), + tt_str_op(tor_inet_ntop(AF_INET6, &a1, buf, strlen(ip)+1),==, ip); + tt_str_op(tor_inet_ntop(AF_INET6, &a2, buf, strlen(ip_ffff)+1),==, ip_ffff); /* too short buffer (remember \0) */ - test_eq_ptr(tor_inet_ntop(AF_INET6, &a1, buf, strlen(ip)), NULL); - test_eq_ptr(tor_inet_ntop(AF_INET6, &a2, buf, strlen(ip_ffff)), NULL); + tt_ptr_op(tor_inet_ntop(AF_INET6, &a1, buf, strlen(ip)),==, NULL); + tt_ptr_op(tor_inet_ntop(AF_INET6, &a2, buf, strlen(ip_ffff)),==, NULL); } /* ==== Converting to and from sockaddr_t. */ @@ -224,16 +224,16 @@ test_addr_ip6_helpers(void) sin->sin_port = htons(9090); sin->sin_addr.s_addr = htonl(0x7f7f0102); /*127.127.1.2*/ tor_addr_from_sockaddr(&t1, (struct sockaddr *)sin, &port1); - test_eq(tor_addr_family(&t1), AF_INET); - test_eq(tor_addr_to_ipv4h(&t1), 0x7f7f0102); + tt_int_op(tor_addr_family(&t1),==, AF_INET); + tt_int_op(tor_addr_to_ipv4h(&t1),==, 0x7f7f0102); tt_int_op(port1, ==, 9090); memset(&sa_storage, 0, sizeof(sa_storage)); - test_eq(sizeof(struct sockaddr_in), + tt_int_op(sizeof(struct sockaddr_in),==, tor_addr_to_sockaddr(&t1, 1234, (struct sockaddr *)&sa_storage, sizeof(sa_storage))); - test_eq(1234, ntohs(sin->sin_port)); - test_eq(0x7f7f0102, ntohl(sin->sin_addr.s_addr)); + tt_int_op(1234,==, ntohs(sin->sin_port)); + tt_int_op(0x7f7f0102,==, ntohl(sin->sin_addr.s_addr)); memset(&sa_storage, 0, sizeof(sa_storage)); sin6 = (struct sockaddr_in6 *)&sa_storage; @@ -241,37 +241,37 @@ test_addr_ip6_helpers(void) sin6->sin6_port = htons(7070); sin6->sin6_addr.s6_addr[0] = 128; tor_addr_from_sockaddr(&t1, (struct sockaddr *)sin6, &port1); - test_eq(tor_addr_family(&t1), AF_INET6); + tt_int_op(tor_addr_family(&t1),==, AF_INET6); tt_int_op(port1, ==, 7070); p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 0); - test_streq(p1, "8000::"); + tt_str_op(p1,==, "8000::"); memset(&sa_storage, 0, sizeof(sa_storage)); - test_eq(sizeof(struct sockaddr_in6), + tt_int_op(sizeof(struct sockaddr_in6),==, tor_addr_to_sockaddr(&t1, 9999, (struct sockaddr *)&sa_storage, sizeof(sa_storage))); - test_eq(AF_INET6, sin6->sin6_family); - test_eq(9999, ntohs(sin6->sin6_port)); - test_eq(0x80000000, ntohl(S6_ADDR32(sin6->sin6_addr)[0])); + tt_int_op(AF_INET6,==, sin6->sin6_family); + tt_int_op(9999,==, ntohs(sin6->sin6_port)); + tt_int_op(0x80000000,==, ntohl(S6_ADDR32(sin6->sin6_addr)[0])); /* ==== tor_addr_lookup: static cases. (Can't test dns without knowing we * have a good resolver. */ - test_eq(0, tor_addr_lookup("127.128.129.130", AF_UNSPEC, &t1)); - test_eq(AF_INET, tor_addr_family(&t1)); - test_eq(tor_addr_to_ipv4h(&t1), 0x7f808182); + tt_int_op(0,==, tor_addr_lookup("127.128.129.130", AF_UNSPEC, &t1)); + tt_int_op(AF_INET,==, tor_addr_family(&t1)); + tt_int_op(tor_addr_to_ipv4h(&t1),==, 0x7f808182); - test_eq(0, tor_addr_lookup("9000::5", AF_UNSPEC, &t1)); - test_eq(AF_INET6, tor_addr_family(&t1)); - test_eq(0x90, tor_addr_to_in6_addr8(&t1)[0]); - test_assert(tor_mem_is_zero((char*)tor_addr_to_in6_addr8(&t1)+1, 14)); - test_eq(0x05, tor_addr_to_in6_addr8(&t1)[15]); + tt_int_op(0,==, tor_addr_lookup("9000::5", AF_UNSPEC, &t1)); + tt_int_op(AF_INET6,==, tor_addr_family(&t1)); + tt_int_op(0x90,==, tor_addr_to_in6_addr8(&t1)[0]); + tt_assert(tor_mem_is_zero((char*)tor_addr_to_in6_addr8(&t1)+1, 14)); + tt_int_op(0x05,==, tor_addr_to_in6_addr8(&t1)[15]); /* === Test pton: valid af_inet6 */ /* Simple, valid parsing. */ r = tor_inet_pton(AF_INET6, "0102:0304:0506:0708:090A:0B0C:0D0E:0F10", &a1); - test_assert(r==1); - for (i=0;i<16;++i) { test_eq(i+1, (int)a1.s6_addr[i]); } + tt_int_op(r, ==, 1); + for (i=0;i<16;++i) { tt_int_op(i+1,==, (int)a1.s6_addr[i]); } /* ipv4 ending. */ test_pton6_same("0102:0304:0506:0708:090A:0B0C:0D0E:0F10", "0102:0304:0506:0708:090A:0B0C:13.14.15.16"); @@ -311,7 +311,7 @@ test_addr_ip6_helpers(void) "1000:1:0:7::"); /* Bad af param */ - test_eq(tor_inet_pton(AF_UNSPEC, 0, 0), -1); + tt_int_op(tor_inet_pton(AF_UNSPEC, 0, 0),==, -1); /* === Test pton: invalid in6. */ test_pton6_bad("foobar."); @@ -414,10 +414,10 @@ test_addr_ip6_helpers(void) test_addr_compare("0::ffff:5.2.2.1", <, "::ffff:6.0.0.0"); /* XXXX wrong. */ tor_addr_parse_mask_ports("[::ffff:2.3.4.5]", 0, &t1, NULL, NULL, NULL); tor_addr_parse_mask_ports("2.3.4.5", 0, &t2, NULL, NULL, NULL); - test_assert(tor_addr_compare(&t1, &t2, CMP_SEMANTIC) == 0); + tt_assert(tor_addr_compare(&t1, &t2, CMP_SEMANTIC) == 0); tor_addr_parse_mask_ports("[::ffff:2.3.4.4]", 0, &t1, NULL, NULL, NULL); tor_addr_parse_mask_ports("2.3.4.5", 0, &t2, NULL, NULL, NULL); - test_assert(tor_addr_compare(&t1, &t2, CMP_SEMANTIC) < 0); + tt_assert(tor_addr_compare(&t1, &t2, CMP_SEMANTIC) < 0); /* test compare_masked */ test_addr_compare_masked("ffff::", ==, "ffff::0", 128); @@ -426,113 +426,113 @@ test_addr_ip6_helpers(void) test_addr_compare_masked("0::2:2:1", ==, "0::8000:2:1", 80); /* Test undecorated tor_addr_to_str */ - test_eq(AF_INET6, tor_addr_parse(&t1, "[123:45:6789::5005:11]")); + tt_int_op(AF_INET6,==, tor_addr_parse(&t1, "[123:45:6789::5005:11]")); p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 0); - test_streq(p1, "123:45:6789::5005:11"); - test_eq(AF_INET, tor_addr_parse(&t1, "18.0.0.1")); + tt_str_op(p1,==, "123:45:6789::5005:11"); + tt_int_op(AF_INET,==, tor_addr_parse(&t1, "18.0.0.1")); p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 0); - test_streq(p1, "18.0.0.1"); + tt_str_op(p1,==, "18.0.0.1"); /* Test decorated tor_addr_to_str */ - test_eq(AF_INET6, tor_addr_parse(&t1, "[123:45:6789::5005:11]")); + tt_int_op(AF_INET6,==, tor_addr_parse(&t1, "[123:45:6789::5005:11]")); p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 1); - test_streq(p1, "[123:45:6789::5005:11]"); - test_eq(AF_INET, tor_addr_parse(&t1, "18.0.0.1")); + tt_str_op(p1,==, "[123:45:6789::5005:11]"); + tt_int_op(AF_INET,==, tor_addr_parse(&t1, "18.0.0.1")); p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 1); - test_streq(p1, "18.0.0.1"); + tt_str_op(p1,==, "18.0.0.1"); /* Test buffer bounds checking of tor_addr_to_str */ - test_eq(AF_INET6, tor_addr_parse(&t1, "::")); /* 2 + \0 */ - test_eq_ptr(tor_addr_to_str(buf, &t1, 2, 0), NULL); /* too short buf */ - test_streq(tor_addr_to_str(buf, &t1, 3, 0), "::"); - test_eq_ptr(tor_addr_to_str(buf, &t1, 4, 1), NULL); /* too short buf */ - test_streq(tor_addr_to_str(buf, &t1, 5, 1), "[::]"); - - test_eq(AF_INET6, tor_addr_parse(&t1, "2000::1337")); /* 10 + \0 */ - test_eq_ptr(tor_addr_to_str(buf, &t1, 10, 0), NULL); /* too short buf */ - test_streq(tor_addr_to_str(buf, &t1, 11, 0), "2000::1337"); - test_eq_ptr(tor_addr_to_str(buf, &t1, 12, 1), NULL); /* too short buf */ - test_streq(tor_addr_to_str(buf, &t1, 13, 1), "[2000::1337]"); - - test_eq(AF_INET, tor_addr_parse(&t1, "1.2.3.4")); /* 7 + \0 */ - test_eq_ptr(tor_addr_to_str(buf, &t1, 7, 0), NULL); /* too short buf */ - test_streq(tor_addr_to_str(buf, &t1, 8, 0), "1.2.3.4"); - - test_eq(AF_INET, tor_addr_parse(&t1, "255.255.255.255")); /* 15 + \0 */ - test_eq_ptr(tor_addr_to_str(buf, &t1, 15, 0), NULL); /* too short buf */ - test_streq(tor_addr_to_str(buf, &t1, 16, 0), "255.255.255.255"); - test_eq_ptr(tor_addr_to_str(buf, &t1, 15, 1), NULL); /* too short buf */ - test_streq(tor_addr_to_str(buf, &t1, 16, 1), "255.255.255.255"); + tt_int_op(AF_INET6,==, tor_addr_parse(&t1, "::")); /* 2 + \0 */ + tt_ptr_op(tor_addr_to_str(buf, &t1, 2, 0),==, NULL); /* too short buf */ + tt_str_op(tor_addr_to_str(buf, &t1, 3, 0),==, "::"); + tt_ptr_op(tor_addr_to_str(buf, &t1, 4, 1),==, NULL); /* too short buf */ + tt_str_op(tor_addr_to_str(buf, &t1, 5, 1),==, "[::]"); + + tt_int_op(AF_INET6,==, tor_addr_parse(&t1, "2000::1337")); /* 10 + \0 */ + tt_ptr_op(tor_addr_to_str(buf, &t1, 10, 0),==, NULL); /* too short buf */ + tt_str_op(tor_addr_to_str(buf, &t1, 11, 0),==, "2000::1337"); + tt_ptr_op(tor_addr_to_str(buf, &t1, 12, 1),==, NULL); /* too short buf */ + tt_str_op(tor_addr_to_str(buf, &t1, 13, 1),==, "[2000::1337]"); + + tt_int_op(AF_INET,==, tor_addr_parse(&t1, "1.2.3.4")); /* 7 + \0 */ + tt_ptr_op(tor_addr_to_str(buf, &t1, 7, 0),==, NULL); /* too short buf */ + tt_str_op(tor_addr_to_str(buf, &t1, 8, 0),==, "1.2.3.4"); + + tt_int_op(AF_INET,==, tor_addr_parse(&t1, "255.255.255.255")); /* 15 + \0 */ + tt_ptr_op(tor_addr_to_str(buf, &t1, 15, 0),==, NULL); /* too short buf */ + tt_str_op(tor_addr_to_str(buf, &t1, 16, 0),==, "255.255.255.255"); + tt_ptr_op(tor_addr_to_str(buf, &t1, 15, 1),==, NULL); /* too short buf */ + tt_str_op(tor_addr_to_str(buf, &t1, 16, 1),==, "255.255.255.255"); t1.family = AF_UNSPEC; - test_eq_ptr(tor_addr_to_str(buf, &t1, sizeof(buf), 0), NULL); + tt_ptr_op(tor_addr_to_str(buf, &t1, sizeof(buf), 0),==, NULL); /* Test tor_addr_parse_PTR_name */ i = tor_addr_parse_PTR_name(&t1, "Foobar.baz", AF_UNSPEC, 0); - test_eq(0, i); + tt_int_op(0,==, i); i = tor_addr_parse_PTR_name(&t1, "Foobar.baz", AF_UNSPEC, 1); - test_eq(0, i); + tt_int_op(0,==, i); i = tor_addr_parse_PTR_name(&t1, "9999999999999999999999999999.in-addr.arpa", AF_UNSPEC, 1); - test_eq(-1, i); + tt_int_op(-1,==, i); i = tor_addr_parse_PTR_name(&t1, "1.0.168.192.in-addr.arpa", AF_UNSPEC, 1); - test_eq(1, i); - test_eq(tor_addr_family(&t1), AF_INET); + tt_int_op(1,==, i); + tt_int_op(tor_addr_family(&t1),==, AF_INET); p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 1); - test_streq(p1, "192.168.0.1"); + tt_str_op(p1,==, "192.168.0.1"); i = tor_addr_parse_PTR_name(&t1, "192.168.0.99", AF_UNSPEC, 0); - test_eq(0, i); + tt_int_op(0,==, i); i = tor_addr_parse_PTR_name(&t1, "192.168.0.99", AF_UNSPEC, 1); - test_eq(1, i); + tt_int_op(1,==, i); p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 1); - test_streq(p1, "192.168.0.99"); + tt_str_op(p1,==, "192.168.0.99"); memset(&t1, 0, sizeof(t1)); i = tor_addr_parse_PTR_name(&t1, "0.1.2.3.4.5.6.7.8.9.a.b.c.d.e.f." "f.e.e.b.1.e.b.e.e.f.f.e.e.e.d.9." "ip6.ARPA", AF_UNSPEC, 0); - test_eq(1, i); + tt_int_op(1,==, i); p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 1); - test_streq(p1, "[9dee:effe:ebe1:beef:fedc:ba98:7654:3210]"); + tt_str_op(p1,==, "[9dee:effe:ebe1:beef:fedc:ba98:7654:3210]"); /* Failing cases. */ i = tor_addr_parse_PTR_name(&t1, "6.7.8.9.a.b.c.d.e.f." "f.e.e.b.1.e.b.e.e.f.f.e.e.e.d.9." "ip6.ARPA", AF_UNSPEC, 0); - test_eq(i, -1); + tt_int_op(i,==, -1); i = tor_addr_parse_PTR_name(&t1, "6.7.8.9.a.b.c.d.e.f.a.b.c.d.e.f.0." "f.e.e.b.1.e.b.e.e.f.f.e.e.e.d.9." "ip6.ARPA", AF_UNSPEC, 0); - test_eq(i, -1); + tt_int_op(i,==, -1); i = tor_addr_parse_PTR_name(&t1, "6.7.8.9.a.b.c.d.e.f.X.0.0.0.0.9." "f.e.e.b.1.e.b.e.e.f.f.e.e.e.d.9." "ip6.ARPA", AF_UNSPEC, 0); - test_eq(i, -1); + tt_int_op(i,==, -1); i = tor_addr_parse_PTR_name(&t1, "32.1.1.in-addr.arpa", AF_UNSPEC, 0); - test_eq(i, -1); + tt_int_op(i,==, -1); i = tor_addr_parse_PTR_name(&t1, ".in-addr.arpa", AF_UNSPEC, 0); - test_eq(i, -1); + tt_int_op(i,==, -1); i = tor_addr_parse_PTR_name(&t1, "1.2.3.4.5.in-addr.arpa", AF_UNSPEC, 0); - test_eq(i, -1); + tt_int_op(i,==, -1); i = tor_addr_parse_PTR_name(&t1, "1.2.3.4.5.in-addr.arpa", AF_INET6, 0); - test_eq(i, -1); + tt_int_op(i,==, -1); i = tor_addr_parse_PTR_name(&t1, "6.7.8.9.a.b.c.d.e.f.a.b.c.d.e.0." "f.e.e.b.1.e.b.e.e.f.f.e.e.e.d.9." "ip6.ARPA", AF_INET, 0); - test_eq(i, -1); + tt_int_op(i,==, -1); /* === Test tor_addr_to_PTR_name */ @@ -544,19 +544,19 @@ test_addr_ip6_helpers(void) tor_addr_from_sockaddr(&t1, (struct sockaddr *)sin, NULL); /* Check IPv4 PTR - too short buffer */ - test_eq(tor_addr_to_PTR_name(rbuf, 1, &t1), -1); - test_eq(tor_addr_to_PTR_name(rbuf, + tt_int_op(tor_addr_to_PTR_name(rbuf, 1, &t1),==, -1); + tt_int_op(tor_addr_to_PTR_name(rbuf, strlen("3.2.1.127.in-addr.arpa") - 1, - &t1), -1); + &t1),==, -1); /* Check IPv4 PTR - valid addr */ - test_eq(tor_addr_to_PTR_name(rbuf, sizeof(rbuf), &t1), + tt_int_op(tor_addr_to_PTR_name(rbuf, sizeof(rbuf), &t1),==, strlen("3.2.1.127.in-addr.arpa")); - test_streq(rbuf, "3.2.1.127.in-addr.arpa"); + tt_str_op(rbuf,==, "3.2.1.127.in-addr.arpa"); /* Invalid addr family */ t1.family = AF_UNSPEC; - test_eq(tor_addr_to_PTR_name(rbuf, sizeof(rbuf), &t1), -1); + tt_int_op(tor_addr_to_PTR_name(rbuf, sizeof(rbuf), &t1),==, -1); /* Stage IPv6 addr */ memset(&sa_storage, 0, sizeof(sa_storage)); @@ -573,81 +573,81 @@ test_addr_ip6_helpers(void) "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.ip6.arpa"; /* Check IPv6 PTR - too short buffer */ - test_eq(tor_addr_to_PTR_name(rbuf, 0, &t1), -1); - test_eq(tor_addr_to_PTR_name(rbuf, strlen(addr_PTR) - 1, &t1), -1); + tt_int_op(tor_addr_to_PTR_name(rbuf, 0, &t1),==, -1); + tt_int_op(tor_addr_to_PTR_name(rbuf, strlen(addr_PTR) - 1, &t1),==, -1); /* Check IPv6 PTR - valid addr */ - test_eq(tor_addr_to_PTR_name(rbuf, sizeof(rbuf), &t1), + tt_int_op(tor_addr_to_PTR_name(rbuf, sizeof(rbuf), &t1),==, strlen(addr_PTR)); - test_streq(rbuf, addr_PTR); + tt_str_op(rbuf,==, addr_PTR); } /* XXXX turn this into a separate function; it's not all IPv6. */ /* test tor_addr_parse_mask_ports */ test_addr_mask_ports_parse("[::f]/17:47-95", AF_INET6, 0, 0, 0, 0x0000000f, 17, 47, 95); - test_streq(p1, "::f"); + tt_str_op(p1,==, "::f"); //test_addr_parse("[::fefe:4.1.1.7/120]:999-1000"); //test_addr_parse_check("::fefe:401:107", 120, 999, 1000); test_addr_mask_ports_parse("[::ffff:4.1.1.7]/120:443", AF_INET6, 0, 0, 0x0000ffff, 0x04010107, 120, 443, 443); - test_streq(p1, "::ffff:4.1.1.7"); + tt_str_op(p1,==, "::ffff:4.1.1.7"); test_addr_mask_ports_parse("[abcd:2::44a:0]:2-65000", AF_INET6, 0xabcd0002, 0, 0, 0x044a0000, 128, 2, 65000); - test_streq(p1, "abcd:2::44a:0"); + tt_str_op(p1,==, "abcd:2::44a:0"); /* Try some long addresses. */ r=tor_addr_parse_mask_ports("[ffff:1111:1111:1111:1111:1111:1111:1111]", 0, &t1, NULL, NULL, NULL); - test_assert(r == AF_INET6); + tt_assert(r == AF_INET6); r=tor_addr_parse_mask_ports("[ffff:1111:1111:1111:1111:1111:1111:11111]", 0, &t1, NULL, NULL, NULL); - test_assert(r == -1); + tt_int_op(r, ==, -1); r=tor_addr_parse_mask_ports("[ffff:1111:1111:1111:1111:1111:1111:1111:1]", 0, &t1, NULL, NULL, NULL); - test_assert(r == -1); + tt_int_op(r, ==, -1); r=tor_addr_parse_mask_ports( "[ffff:1111:1111:1111:1111:1111:1111:ffff:" "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:" "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:" "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]", 0, &t1, NULL, NULL, NULL); - test_assert(r == -1); + tt_int_op(r, ==, -1); /* Try some failing cases. */ r=tor_addr_parse_mask_ports("[fefef::]/112", 0, &t1, NULL, NULL, NULL); - test_assert(r == -1); + tt_int_op(r, ==, -1); r=tor_addr_parse_mask_ports("[fefe::/112", 0, &t1, NULL, NULL, NULL); - test_assert(r == -1); + tt_int_op(r, ==, -1); r=tor_addr_parse_mask_ports("[fefe::", 0, &t1, NULL, NULL, NULL); - test_assert(r == -1); + tt_int_op(r, ==, -1); r=tor_addr_parse_mask_ports("[fefe::X]", 0, &t1, NULL, NULL, NULL); - test_assert(r == -1); + tt_int_op(r, ==, -1); r=tor_addr_parse_mask_ports("efef::/112", 0, &t1, NULL, NULL, NULL); - test_assert(r == -1); + tt_int_op(r, ==, -1); r=tor_addr_parse_mask_ports("[f:f:f:f:f:f:f:f::]",0,&t1, NULL, NULL, NULL); - test_assert(r == -1); + tt_int_op(r, ==, -1); r=tor_addr_parse_mask_ports("[::f:f:f:f:f:f:f:f]",0,&t1, NULL, NULL, NULL); - test_assert(r == -1); + tt_int_op(r, ==, -1); r=tor_addr_parse_mask_ports("[f:f:f:f:f:f:f:f:f]",0,&t1, NULL, NULL, NULL); - test_assert(r == -1); + tt_int_op(r, ==, -1); r=tor_addr_parse_mask_ports("[f:f:f:f:f::]/fred",0,&t1,&mask, NULL, NULL); - test_assert(r == -1); + tt_int_op(r, ==, -1); r=tor_addr_parse_mask_ports("[f:f:f:f:f::]/255.255.0.0", 0,&t1, NULL, NULL, NULL); - test_assert(r == -1); + tt_int_op(r, ==, -1); /* This one will get rejected because it isn't a pure prefix. */ r=tor_addr_parse_mask_ports("1.1.2.3/255.255.64.0",0,&t1, &mask,NULL,NULL); - test_assert(r == -1); + tt_int_op(r, ==, -1); /* Test for V4-mapped address with mask < 96. (arguably not valid) */ r=tor_addr_parse_mask_ports("[::ffff:1.1.2.2/33]",0,&t1, &mask, NULL, NULL); - test_assert(r == -1); + tt_int_op(r, ==, -1); r=tor_addr_parse_mask_ports("1.1.2.2/33",0,&t1, &mask, NULL, NULL); - test_assert(r == -1); + tt_int_op(r, ==, -1); /* Try extended wildcard addresses with out TAPMP_EXTENDED_STAR*/ r=tor_addr_parse_mask_ports("*4",0,&t1, &mask, NULL, NULL); - test_assert(r == -1); + tt_int_op(r, ==, -1); r=tor_addr_parse_mask_ports("*6",0,&t1, &mask, NULL, NULL); - test_assert(r == -1); + tt_int_op(r, ==, -1); #if 0 /* Try a mask with a wildcard. */ r=tor_addr_parse_mask_ports("*/16",0,&t1, &mask, NULL, NULL); @@ -661,26 +661,26 @@ test_addr_ip6_helpers(void) #endif /* Basic mask tests*/ r=tor_addr_parse_mask_ports("1.1.2.2/31",0,&t1, &mask, NULL, NULL); - test_assert(r == AF_INET); + tt_assert(r == AF_INET); tt_int_op(mask,==,31); tt_int_op(tor_addr_family(&t1),==,AF_INET); tt_int_op(tor_addr_to_ipv4h(&t1),==,0x01010202); r=tor_addr_parse_mask_ports("3.4.16.032:1-2",0,&t1, &mask, &port1, &port2); - test_assert(r == AF_INET); + tt_assert(r == AF_INET); tt_int_op(mask,==,32); tt_int_op(tor_addr_family(&t1),==,AF_INET); tt_int_op(tor_addr_to_ipv4h(&t1),==,0x03041020); - test_assert(port1 == 1); - test_assert(port2 == 2); + tt_assert(port1 == 1); + tt_assert(port2 == 2); r=tor_addr_parse_mask_ports("1.1.2.3/255.255.128.0",0,&t1, &mask,NULL,NULL); - test_assert(r == AF_INET); + tt_assert(r == AF_INET); tt_int_op(mask,==,17); tt_int_op(tor_addr_family(&t1),==,AF_INET); tt_int_op(tor_addr_to_ipv4h(&t1),==,0x01010203); r=tor_addr_parse_mask_ports("[efef::]/112",0,&t1, &mask, &port1, &port2); - test_assert(r == AF_INET6); - test_assert(port1 == 1); - test_assert(port2 == 65535); + tt_assert(r == AF_INET6); + tt_assert(port1 == 1); + tt_assert(port2 == 65535); /* Try regular wildcard behavior without TAPMP_EXTENDED_STAR */ r=tor_addr_parse_mask_ports("*:80-443",0,&t1,&mask,&port1,&port2); tt_int_op(r,==,AF_INET); /* Old users of this always get inet */ @@ -715,11 +715,11 @@ test_addr_ip6_helpers(void) tt_int_op(port2,==,65535); /* make sure inet address lengths >= max */ - test_assert(INET_NTOA_BUF_LEN >= sizeof("255.255.255.255")); - test_assert(TOR_ADDR_BUF_LEN >= + tt_assert(INET_NTOA_BUF_LEN >= sizeof("255.255.255.255")); + tt_assert(TOR_ADDR_BUF_LEN >= sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")); - test_assert(sizeof(tor_addr_t) >= sizeof(struct in6_addr)); + tt_assert(sizeof(tor_addr_t) >= sizeof(struct in6_addr)); /* get interface addresses */ r = get_interface_address6(LOG_DEBUG, AF_INET, &t1); @@ -747,86 +747,86 @@ test_addr_parse(void) r= tor_addr_port_parse(LOG_DEBUG, "192.0.2.1:1234", &addr, &port, -1); - test_assert(r == 0); + tt_int_op(r, ==, 0); tor_addr_to_str(buf, &addr, sizeof(buf), 0); - test_streq(buf, "192.0.2.1"); - test_eq(port, 1234); + tt_str_op(buf,==, "192.0.2.1"); + tt_int_op(port,==, 1234); r= tor_addr_port_parse(LOG_DEBUG, "[::1]:1234", &addr, &port, -1); - test_assert(r == 0); + tt_int_op(r, ==, 0); tor_addr_to_str(buf, &addr, sizeof(buf), 0); - test_streq(buf, "::1"); - test_eq(port, 1234); + tt_str_op(buf,==, "::1"); + tt_int_op(port,==, 1234); /* Domain name. */ r= tor_addr_port_parse(LOG_DEBUG, "torproject.org:1234", &addr, &port, -1); - test_assert(r == -1); + tt_int_op(r, ==, -1); /* Only IP. */ r= tor_addr_port_parse(LOG_DEBUG, "192.0.2.2", &addr, &port, -1); - test_assert(r == -1); + tt_int_op(r, ==, -1); r= tor_addr_port_parse(LOG_DEBUG, "192.0.2.2", &addr, &port, 200); - test_assert(r == 0); + tt_int_op(r, ==, 0); tt_int_op(port,==,200); r= tor_addr_port_parse(LOG_DEBUG, "[::1]", &addr, &port, -1); - test_assert(r == -1); + tt_int_op(r, ==, -1); r= tor_addr_port_parse(LOG_DEBUG, "[::1]", &addr, &port, 400); - test_assert(r == 0); + tt_int_op(r, ==, 0); tt_int_op(port,==,400); /* Bad port. */ r= tor_addr_port_parse(LOG_DEBUG, "192.0.2.2:66666", &addr, &port, -1); - test_assert(r == -1); + tt_int_op(r, ==, -1); r= tor_addr_port_parse(LOG_DEBUG, "192.0.2.2:66666", &addr, &port, 200); - test_assert(r == -1); + tt_int_op(r, ==, -1); /* Only domain name */ r= tor_addr_port_parse(LOG_DEBUG, "torproject.org", &addr, &port, -1); - test_assert(r == -1); + tt_int_op(r, ==, -1); r= tor_addr_port_parse(LOG_DEBUG, "torproject.org", &addr, &port, 200); - test_assert(r == -1); + tt_int_op(r, ==, -1); /* Bad IP address */ r= tor_addr_port_parse(LOG_DEBUG, "192.0.2:1234", &addr, &port, -1); - test_assert(r == -1); + tt_int_op(r, ==, -1); /* Make sure that the default port has lower priority than the real one */ r= tor_addr_port_parse(LOG_DEBUG, "192.0.2.2:1337", &addr, &port, 200); - test_assert(r == 0); + tt_int_op(r, ==, 0); tt_int_op(port,==,1337); r= tor_addr_port_parse(LOG_DEBUG, "[::1]:1369", &addr, &port, 200); - test_assert(r == 0); + tt_int_op(r, ==, 0); tt_int_op(port,==,1369); done: |