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_pt.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_pt.c')
-rw-r--r-- | src/test/test_pt.c | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/src/test/test_pt.c b/src/test/test_pt.c index 0737ff4892..aa616abf3e 100644 --- a/src/test/test_pt.c +++ b/src/test/test_pt.c @@ -39,63 +39,63 @@ test_pt_parsing(void) /* incomplete cmethod */ strlcpy(line,"CMETHOD trebuchet",sizeof(line)); - test_assert(parse_cmethod_line(line, mp) < 0); + tt_assert(parse_cmethod_line(line, mp) < 0); reset_mp(mp); /* wrong proxy type */ strlcpy(line,"CMETHOD trebuchet dog 127.0.0.1:1999",sizeof(line)); - test_assert(parse_cmethod_line(line, mp) < 0); + tt_assert(parse_cmethod_line(line, mp) < 0); reset_mp(mp); /* wrong addrport */ strlcpy(line,"CMETHOD trebuchet socks4 abcd",sizeof(line)); - test_assert(parse_cmethod_line(line, mp) < 0); + tt_assert(parse_cmethod_line(line, mp) < 0); reset_mp(mp); /* correct line */ strlcpy(line,"CMETHOD trebuchet socks5 127.0.0.1:1999",sizeof(line)); - test_assert(parse_cmethod_line(line, mp) == 0); - test_assert(smartlist_len(mp->transports) == 1); + tt_assert(parse_cmethod_line(line, mp) == 0); + tt_assert(smartlist_len(mp->transports) == 1); transport = smartlist_get(mp->transports, 0); /* test registered address of transport */ tor_addr_parse(&test_addr, "127.0.0.1"); - test_assert(tor_addr_eq(&test_addr, &transport->addr)); + tt_assert(tor_addr_eq(&test_addr, &transport->addr)); /* test registered port of transport */ - test_assert(transport->port == 1999); + tt_assert(transport->port == 1999); /* test registered SOCKS version of transport */ - test_assert(transport->socks_version == PROXY_SOCKS5); + tt_assert(transport->socks_version == PROXY_SOCKS5); /* test registered name of transport */ - test_streq(transport->name, "trebuchet"); + tt_str_op(transport->name,==, "trebuchet"); reset_mp(mp); /* incomplete smethod */ strlcpy(line,"SMETHOD trebuchet",sizeof(line)); - test_assert(parse_smethod_line(line, mp) < 0); + tt_assert(parse_smethod_line(line, mp) < 0); reset_mp(mp); /* wrong addr type */ strlcpy(line,"SMETHOD trebuchet abcd",sizeof(line)); - test_assert(parse_smethod_line(line, mp) < 0); + tt_assert(parse_smethod_line(line, mp) < 0); reset_mp(mp); /* cowwect */ strlcpy(line,"SMETHOD trebuchy 127.0.0.2:2999",sizeof(line)); - test_assert(parse_smethod_line(line, mp) == 0); - test_assert(smartlist_len(mp->transports) == 1); + tt_assert(parse_smethod_line(line, mp) == 0); + tt_assert(smartlist_len(mp->transports) == 1); transport = smartlist_get(mp->transports, 0); /* test registered address of transport */ tor_addr_parse(&test_addr, "127.0.0.2"); - test_assert(tor_addr_eq(&test_addr, &transport->addr)); + tt_assert(tor_addr_eq(&test_addr, &transport->addr)); /* test registered port of transport */ - test_assert(transport->port == 2999); + tt_assert(transport->port == 2999); /* test registered name of transport */ - test_streq(transport->name, "trebuchy"); + tt_str_op(transport->name,==, "trebuchy"); reset_mp(mp); @@ -103,7 +103,7 @@ test_pt_parsing(void) strlcpy(line,"SMETHOD trebuchet 127.0.0.1:9999 " "ARGS:counterweight=3,sling=snappy", sizeof(line)); - test_assert(parse_smethod_line(line, mp) == 0); + tt_assert(parse_smethod_line(line, mp) == 0); tt_int_op(1, ==, smartlist_len(mp->transports)); { const transport_t *transport = smartlist_get(mp->transports, 0); @@ -118,15 +118,15 @@ test_pt_parsing(void) /* unsupported version */ strlcpy(line,"VERSION 666",sizeof(line)); - test_assert(parse_version(line, mp) < 0); + tt_assert(parse_version(line, mp) < 0); /* incomplete VERSION */ strlcpy(line,"VERSION ",sizeof(line)); - test_assert(parse_version(line, mp) < 0); + tt_assert(parse_version(line, mp) < 0); /* correct VERSION */ strlcpy(line,"VERSION 1",sizeof(line)); - test_assert(parse_version(line, mp) == 0); + tt_assert(parse_version(line, mp) == 0); done: reset_mp(mp); @@ -201,32 +201,32 @@ test_pt_protocol(void) strlcpy(line,"VERSION 1",sizeof(line)); handle_proxy_line(line, mp); - test_assert(mp->conf_state == PT_PROTO_ACCEPTING_METHODS); + tt_assert(mp->conf_state == PT_PROTO_ACCEPTING_METHODS); strlcpy(line,"VERSION 1",sizeof(line)); handle_proxy_line(line, mp); - test_assert(mp->conf_state == PT_PROTO_BROKEN); + tt_assert(mp->conf_state == PT_PROTO_BROKEN); reset_mp(mp); strlcpy(line,"CMETHOD trebuchet socks5 127.0.0.1:1999",sizeof(line)); handle_proxy_line(line, mp); - test_assert(mp->conf_state == PT_PROTO_BROKEN); + tt_assert(mp->conf_state == PT_PROTO_BROKEN); reset_mp(mp); /* correct protocol run: */ strlcpy(line,"VERSION 1",sizeof(line)); handle_proxy_line(line, mp); - test_assert(mp->conf_state == PT_PROTO_ACCEPTING_METHODS); + tt_assert(mp->conf_state == PT_PROTO_ACCEPTING_METHODS); strlcpy(line,"CMETHOD trebuchet socks5 127.0.0.1:1999",sizeof(line)); handle_proxy_line(line, mp); - test_assert(mp->conf_state == PT_PROTO_ACCEPTING_METHODS); + tt_assert(mp->conf_state == PT_PROTO_ACCEPTING_METHODS); strlcpy(line,"CMETHODS DONE",sizeof(line)); handle_proxy_line(line, mp); - test_assert(mp->conf_state == PT_PROTO_CONFIGURED); + tt_assert(mp->conf_state == PT_PROTO_CONFIGURED); done: reset_mp(mp); @@ -378,19 +378,19 @@ test_pt_configure_proxy(void *arg) for (i = 0 ; i < 5 ; i++) { retval = configure_proxy(mp); /* retval should be zero because proxy hasn't finished configuring yet */ - test_assert(retval == 0); + tt_int_op(retval, ==, 0); /* check the number of registered transports */ - test_assert(smartlist_len(mp->transports) == i+1); + tt_assert(smartlist_len(mp->transports) == i+1); /* check that the mp is still waiting for transports */ - test_assert(mp->conf_state == PT_PROTO_ACCEPTING_METHODS); + tt_assert(mp->conf_state == PT_PROTO_ACCEPTING_METHODS); } /* this last configure_proxy() should finalize the proxy configuration. */ retval = configure_proxy(mp); /* retval should be 1 since the proxy finished configuring */ - test_assert(retval == 1); + tt_int_op(retval, ==, 1); /* check the mp state */ - test_assert(mp->conf_state == PT_PROTO_COMPLETED); + tt_assert(mp->conf_state == PT_PROTO_COMPLETED); tt_int_op(controlevent_n, ==, 5); tt_int_op(controlevent_event, ==, EVENT_TRANSPORT_LAUNCHED); @@ -416,7 +416,7 @@ test_pt_configure_proxy(void *arg) /* Get the bindaddr for "mock1" and check it against the bindaddr that the mocked tor_get_lines_from_handle() generated. */ transport_in_state = get_transport_in_state_by_name("mock1"); - test_assert(transport_in_state); + tt_assert(transport_in_state); smartlist_split_string(transport_info_sl, transport_in_state->value, NULL, 0, 0); name_of_transport = smartlist_get(transport_info_sl, 0); @@ -468,7 +468,7 @@ test_get_pt_proxy_uri(void *arg) ret = tor_addr_port_lookup(options->Socks4Proxy, &options->Socks4ProxyAddr, &options->Socks4ProxyPort); - tt_assert(ret == 0); + tt_int_op(ret, ==, 0); uri = get_pt_proxy_uri(); tt_str_op(uri, ==, "socks4a://192.0.2.1:1080"); tor_free(uri); @@ -479,7 +479,7 @@ test_get_pt_proxy_uri(void *arg) ret = tor_addr_port_lookup(options->Socks5Proxy, &options->Socks5ProxyAddr, &options->Socks5ProxyPort); - tt_assert(ret == 0); + tt_int_op(ret, ==, 0); uri = get_pt_proxy_uri(); tt_str_op(uri, ==, "socks5://192.0.2.1:1080"); tor_free(uri); @@ -499,7 +499,7 @@ test_get_pt_proxy_uri(void *arg) ret = tor_addr_port_lookup(options->HTTPSProxy, &options->HTTPSProxyAddr, &options->HTTPSProxyPort); - tt_assert(ret == 0); + tt_int_op(ret, ==, 0); uri = get_pt_proxy_uri(); tt_str_op(uri, ==, "http://192.0.2.1:80"); tor_free(uri); @@ -517,7 +517,7 @@ test_get_pt_proxy_uri(void *arg) ret = tor_addr_port_lookup(options->Socks4Proxy, &options->Socks4ProxyAddr, &options->Socks4ProxyPort); - tt_assert(ret == 0); + tt_int_op(ret, ==, 0); uri = get_pt_proxy_uri(); tt_str_op(uri, ==, "socks4a://[2001:db8::1]:1080"); tor_free(uri); |