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.
This commit is contained in:
Nick Mathewson 2012-11-02 14:32:05 -04:00
parent 1bfda600c3
commit 4458fd0cd8
5 changed files with 14 additions and 13 deletions

View File

@ -1,2 +1,3 @@
o Minor bugfixes:
- Compile on win64 using mingw64. Fixes bug 7260; patches from "yayooo".

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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. */