[tor-commits] [tor/master] In the unit tests, use "test_eq_ptr" and "test_neq_ptr" consistently

nickm at torproject.org nickm at torproject.org
Fri Dec 7 19:16:51 UTC 2012


commit 4458fd0cd8fa259f0ee8195e1aa86d5b7c6f8919
Author: Nick Mathewson <nickm at torproject.org>
Date:   Fri Nov 2 14:32:05 2012 -0400

    In the unit tests, use "test_eq_ptr" and "test_neq_ptr" consistently
    
    This is part of what's needed to build without warnings on mingw64:
    it was warning about the cast from void* to long that happened in
    the places we were using test_{n,}eq on pointers.
    
    The alternative here would have been to broaden tt_int_op to accept
    a long long or an intptr_t, but that's less correct (since pointers
    aren't integers), and would hurt the portability of tinytest a
    little.
    
    Fixes part of 7260.
---
 changes/bug7260            |    1 +
 src/test/test_addr.c       |    2 +-
 src/test/test_containers.c |    8 ++++----
 src/test/test_crypto.c     |    6 +++---
 src/test/test_util.c       |   10 +++++-----
 5 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/changes/bug7260 b/changes/bug7260
index f174461..8eb54c3 100644
--- a/changes/bug7260
+++ b/changes/bug7260
@@ -1,2 +1,3 @@
   o Minor bugfixes:
     - Compile on win64 using mingw64. Fixes bug 7260; patches from "yayooo".
+
diff --git a/src/test/test_addr.c b/src/test/test_addr.c
index 0dcc017..343ec6d 100644
--- a/src/test/test_addr.c
+++ b/src/test/test_addr.c
@@ -38,7 +38,7 @@ test_addr_basic(void)
   tor_free(cp);
   u32 = 3;
   test_assert(!addr_port_lookup(LOG_WARN, "localhost", NULL, &u32, &u16));
-  test_eq(cp, NULL);
+  test_eq_ptr(cp, NULL);
   test_eq(u32, 0x7f000001u);
   test_eq(u16, 0);
   tor_free(cp);
diff --git a/src/test/test_containers.c b/src/test/test_containers.c
index 399ef8e..580c577 100644
--- a/src/test/test_containers.c
+++ b/src/test/test_containers.c
@@ -266,7 +266,7 @@ test_container_smartlist_strings(void)
   SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
   smartlist_clear(sl);
   cp_alloc = smartlist_pop_last(sl);
-  test_eq(cp_alloc, NULL);
+  test_eq_ptr(cp_alloc, NULL);
 
   /* Test uniq() */
   smartlist_split_string(sl,
@@ -677,12 +677,12 @@ test_container_strmap(void)
   test_eq(strmap_size(map), 0);
   test_assert(strmap_isempty(map));
   v = strmap_set(map, "K1", (void*)99);
-  test_eq(v, NULL);
+  test_eq_ptr(v, NULL);
   test_assert(!strmap_isempty(map));
   v = strmap_set(map, "K2", (void*)101);
-  test_eq(v, NULL);
+  test_eq_ptr(v, NULL);
   v = strmap_set(map, "K1", (void*)100);
-  test_eq(v, (void*)99);
+  test_eq_ptr(v, (void*)99);
   test_eq_ptr(strmap_get(map,"K1"), (void*)100);
   test_eq_ptr(strmap_get(map,"K2"), (void*)101);
   test_eq_ptr(strmap_get(map,"K-not-there"), NULL);
diff --git a/src/test/test_crypto.c b/src/test/test_crypto.c
index fd983de..ed1da39 100644
--- a/src/test/test_crypto.c
+++ b/src/test/test_crypto.c
@@ -119,9 +119,9 @@ test_crypto_aes(void *arg)
   memset(data2, 0, 1024);
   memset(data3, 0, 1024);
   env1 = crypto_cipher_new(NULL);
-  test_neq(env1, 0);
+  test_neq_ptr(env1, 0);
   env2 = crypto_cipher_new(crypto_cipher_get_key(env1));
-  test_neq(env2, 0);
+  test_neq_ptr(env2, 0);
 
   /* Try encrypting 512 chars. */
   crypto_cipher_encrypt(env1, data2, data1, 512);
@@ -152,7 +152,7 @@ test_crypto_aes(void *arg)
 
   memset(data3, 0, 1024);
   env2 = crypto_cipher_new(crypto_cipher_get_key(env1));
-  test_neq(env2, 0);
+  test_neq_ptr(env2, NULL);
   for (j = 0; j < 1024-16; j += 17) {
     crypto_cipher_encrypt(env2, data3+j, data1+j, 17);
   }
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 04ca42d..02a00d0 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -1005,7 +1005,7 @@ test_util_strmisc(void)
     const char *s = "abcdefghijklmnopqrstuvwxyz";
     cp = tor_strndup(s, 30);
     test_streq(cp, s); /* same string, */
-    test_neq(cp, s); /* but different pointers. */
+    test_neq_ptr(cp, s); /* but different pointers. */
     tor_free(cp);
 
     cp = tor_strndup(s, 5);
@@ -1015,7 +1015,7 @@ test_util_strmisc(void)
     s = "a\0b\0c\0d\0e\0";
     cp = tor_memdup(s,10);
     test_memeq(cp, s, 10); /* same ram, */
-    test_neq(cp, s); /* but different pointers. */
+    test_neq_ptr(cp, s); /* but different pointers. */
     tor_free(cp);
   }
 
@@ -1495,7 +1495,7 @@ test_util_mmap(void)
   /* Now a zero-length file. */
   write_str_to_file(fname1, "", 1);
   mapping = tor_mmap_file(fname1);
-  test_eq(mapping, NULL);
+  test_eq_ptr(mapping, NULL);
   test_eq(ERANGE, errno);
   unlink(fname1);
 
@@ -1889,7 +1889,7 @@ test_util_memarea(void)
   /* Make sure we don't overalign. */
   p1 = memarea_alloc(area, 1);
   p2 = memarea_alloc(area, 1);
-  test_eq(p1+sizeof(void*), p2);
+  test_eq_ptr(p1+sizeof(void*), p2);
   {
     malloced_ptr = tor_malloc(64);
     test_assert(!memarea_owns_ptr(area, malloced_ptr));
@@ -1934,7 +1934,7 @@ test_util_memarea(void)
 
   memarea_clear(area);
   p1 = memarea_alloc(area, 1);
-  test_eq(p1, p1_orig);
+  test_eq_ptr(p1, p1_orig);
   memarea_clear(area);
 
   /* Check for running over an area's size. */





More information about the tor-commits mailing list