[tor-commits] [tor/master] Replace all uses of test_{str,}eq

nickm at torproject.org nickm at torproject.org
Wed Sep 17 14:31:22 UTC 2014


commit d68465754827d61c8aebd8a5d8af53f13296acf3
Author: Nick Mathewson <nickm at torproject.org>
Date:   Mon Sep 15 21:36:23 2014 -0400

    Replace all uses of test_{str,}eq
---
 src/test/test.c      |    4 ++--
 src/test/test.h      |    3 ---
 src/test/test_addr.c |   50 +++++++++++++++++++++++++-------------------------
 3 files changed, 27 insertions(+), 30 deletions(-)

diff --git a/src/test/test.c b/src/test/test.c
index 516fa42..31224ca 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -761,11 +761,11 @@ test_rend_fns(void)
   } while (0)
 #define CHECK_COUNTRY(country, val) do {                                \
     /* test ipv4 country lookup */                                      \
-    test_streq(country,                                                 \
+    tt_str_op(country, ==,                                              \
                geoip_get_country_name(geoip_get_country_by_ipv4(val))); \
     /* test ipv6 country lookup */                                      \
     SET_TEST_IPV6(val);                                                 \
-    test_streq(country,                                                 \
+    tt_str_op(country, ==,                                              \
                geoip_get_country_name(geoip_get_country_by_ipv6(&in6))); \
   } while (0)
 
diff --git a/src/test/test.h b/src/test/test.h
index 05000c0..c2b333c 100644
--- a/src/test/test.h
+++ b/src/test/test.h
@@ -22,9 +22,6 @@
 #define PRETTY_FUNCTION ""
 #endif
 
-#define test_eq(expr1, expr2) tt_int_op((expr1), ==, (expr2))
-#define test_streq(expr1, expr2) tt_str_op((expr1), ==, (expr2))
-
 /* As test_mem_op, but decodes 'hex' before comparing.  There must be a
  * local char* variable called mem_op_hex_tmp for this to work. */
 #define test_mem_op_hex(expr1, op, hex)                                 \
diff --git a/src/test/test_addr.c b/src/test/test_addr.c
index 8900c46..d319440 100644
--- a/src/test/test_addr.c
+++ b/src/test/test_addr.c
@@ -96,31 +96,31 @@ test_addr_basic(void)
 
 /** Helper: Assert that two strings both decode as IPv6 addresses with
  * tor_inet_pton(), and both decode to the same address. */
-#define test_pton6_same(a,b) STMT_BEGIN                \
-     test_eq(tor_inet_pton(AF_INET6, a, &a1), 1);      \
-     test_eq(tor_inet_pton(AF_INET6, b, &a2), 1);      \
-     test_op_ip6_(&a1,==,&a2,#a,#b);                   \
+#define test_pton6_same(a,b) STMT_BEGIN                 \
+     tt_int_op(tor_inet_pton(AF_INET6, a, &a1), ==, 1); \
+     tt_int_op(tor_inet_pton(AF_INET6, b, &a2), ==, 1); \
+     test_op_ip6_(&a1,==,&a2,#a,#b);                    \
   STMT_END
 
 /** Helper: Assert that <b>a</b> is recognized as a bad IPv6 address by
  * tor_inet_pton(). */
 #define test_pton6_bad(a)                       \
-  test_eq(0, tor_inet_pton(AF_INET6, a, &a1))
+  tt_int_op(0, ==, tor_inet_pton(AF_INET6, a, &a1))
 
 /** Helper: assert that <b>a</b>, when parsed by tor_inet_pton() and displayed
  * with tor_inet_ntop(), yields <b>b</b>. Also assert that <b>b</b> parses to
  * the same value as <b>a</b>. */
-#define test_ntop6_reduces(a,b) STMT_BEGIN                              \
-    test_eq(tor_inet_pton(AF_INET6, a, &a1), 1);                        \
-    test_streq(tor_inet_ntop(AF_INET6, &a1, buf, sizeof(buf)), b);      \
-    test_eq(tor_inet_pton(AF_INET6, b, &a2), 1);                        \
-    test_op_ip6_(&a1, ==, &a2, a, b);                                   \
+#define test_ntop6_reduces(a,b) STMT_BEGIN                          \
+  tt_int_op(tor_inet_pton(AF_INET6, a, &a1), ==, 1);                \
+  tt_str_op(tor_inet_ntop(AF_INET6, &a1, buf, sizeof(buf)), ==, b); \
+  tt_int_op(tor_inet_pton(AF_INET6, b, &a2), ==, 1);     \
+  test_op_ip6_(&a1, ==, &a2, a, b);                      \
   STMT_END
 
 /** Helper: assert that <b>a</b> parses by tor_inet_pton() into a address that
  * passes tor_addr_is_internal() with <b>for_listening</b>. */
 #define test_internal_ip(a,for_listening) STMT_BEGIN           \
-    test_eq(tor_inet_pton(AF_INET6, a, &t1.addr.in6_addr), 1); \
+    tt_int_op(tor_inet_pton(AF_INET6, a, &t1.addr.in6_addr), ==, 1); \
     t1.family = AF_INET6;                                      \
     if (!tor_addr_is_internal(&t1, for_listening))             \
       TT_DIE(("%s was not internal", a));                      \
@@ -129,7 +129,7 @@ test_addr_basic(void)
 /** Helper: assert that <b>a</b> parses by tor_inet_pton() into a address that
  * does not pass tor_addr_is_internal() with <b>for_listening</b>. */
 #define test_external_ip(a,for_listening) STMT_BEGIN           \
-    test_eq(tor_inet_pton(AF_INET6, a, &t1.addr.in6_addr), 1); \
+    tt_int_op(tor_inet_pton(AF_INET6, a, &t1.addr.in6_addr), ==, 1); \
     t1.family = AF_INET6;                                      \
     if (tor_addr_is_internal(&t1, for_listening))              \
       TT_DIE(("%s was not internal", a));                      \
@@ -139,8 +139,8 @@ test_addr_basic(void)
  * tor_inet_pton(), give addresses that compare in the order defined by
  * <b>op</b> with tor_addr_compare(). */
 #define test_addr_compare(a, op, b) STMT_BEGIN                    \
-    test_eq(tor_inet_pton(AF_INET6, a, &t1.addr.in6_addr), 1);    \
-    test_eq(tor_inet_pton(AF_INET6, b, &t2.addr.in6_addr), 1);    \
+    tt_int_op(tor_inet_pton(AF_INET6, a, &t1.addr.in6_addr), ==, 1); \
+    tt_int_op(tor_inet_pton(AF_INET6, b, &t2.addr.in6_addr), ==, 1); \
     t1.family = t2.family = AF_INET6;                             \
     r = tor_addr_compare(&t1,&t2,CMP_SEMANTIC);                   \
     if (!(r op 0))                                                \
@@ -151,8 +151,8 @@ test_addr_basic(void)
  * tor_inet_pton(), give addresses that compare in the order defined by
  * <b>op</b> with tor_addr_compare_masked() with <b>m</b> masked. */
 #define test_addr_compare_masked(a, op, b, m) STMT_BEGIN          \
-    test_eq(tor_inet_pton(AF_INET6, a, &t1.addr.in6_addr), 1);    \
-    test_eq(tor_inet_pton(AF_INET6, b, &t2.addr.in6_addr), 1);    \
+    tt_int_op(tor_inet_pton(AF_INET6, a, &t1.addr.in6_addr), ==, 1);    \
+    tt_int_op(tor_inet_pton(AF_INET6, b, &t2.addr.in6_addr), ==, 1);    \
     t1.family = t2.family = AF_INET6;                             \
     r = tor_addr_compare_masked(&t1,&t2,m,CMP_SEMANTIC);          \
     if (!(r op 0))                                                \
@@ -165,16 +165,16 @@ test_addr_basic(void)
  * as <b>pt1..pt2</b>. */
 #define test_addr_mask_ports_parse(xx, f, ip1, ip2, ip3, ip4, mm, pt1, pt2) \
   STMT_BEGIN                                                                \
-    test_eq(tor_addr_parse_mask_ports(xx, 0, &t1, &mask, &port1, &port2),   \
-            f);                                                             \
+    tt_int_op(tor_addr_parse_mask_ports(xx, 0, &t1, &mask, &port1, &port2),   \
+              ==, f);                                                   \
     p1=tor_inet_ntop(AF_INET6, &t1.addr.in6_addr, bug, sizeof(bug));        \
-    test_eq(htonl(ip1), tor_addr_to_in6_addr32(&t1)[0]);            \
-    test_eq(htonl(ip2), tor_addr_to_in6_addr32(&t1)[1]);            \
-    test_eq(htonl(ip3), tor_addr_to_in6_addr32(&t1)[2]);            \
-    test_eq(htonl(ip4), tor_addr_to_in6_addr32(&t1)[3]);            \
-    test_eq(mask, mm);                                     \
-    test_eq(port1, pt1);                                   \
-    test_eq(port2, pt2);                                   \
+    tt_int_op(htonl(ip1), ==, tor_addr_to_in6_addr32(&t1)[0]);            \
+    tt_int_op(htonl(ip2), ==, tor_addr_to_in6_addr32(&t1)[1]);            \
+    tt_int_op(htonl(ip3), ==, tor_addr_to_in6_addr32(&t1)[2]);            \
+    tt_int_op(htonl(ip4), ==, tor_addr_to_in6_addr32(&t1)[3]);            \
+    tt_int_op(mask, ==, mm);                     \
+    tt_uint_op(port1, ==, pt1);                  \
+    tt_uint_op(port2, ==, pt2);                  \
   STMT_END
 
 /** Run unit tests for IPv6 encoding/decoding/manipulation functions. */





More information about the tor-commits mailing list