[tor-commits] [tor/master] Use tt_int_op() over tt_assert() and do explicit NULL checks in test_util_gzip().

nickm at torproject.org nickm at torproject.org
Tue Apr 25 12:18:24 UTC 2017


commit a8821d83660c5ed6244e3ad414b348890da93050
Author: Alexander Færøy <ahf at torproject.org>
Date:   Mon Apr 17 14:02:16 2017 +0200

    Use tt_int_op() over tt_assert() and do explicit NULL checks in test_util_gzip().
    
    This patch changes some of the tt_assert() usage in test_util_gzip() to
    use tt_int_op() to get better error messages upon failure.
    
    Additionally we move to use explicit NULL checks.
    
    See https://bugs.torproject.org/21663
---
 src/test/test_util.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/test/test_util.c b/src/test/test_util.c
index 203f9dd..4ad4ffa 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -2257,13 +2257,13 @@ test_util_gzip(void *arg)
 
   tt_assert(!tor_gzip_compress(&buf2, &len1, buf1, strlen(buf1)+1,
                                GZIP_METHOD));
-  tt_assert(buf2);
-  tt_assert(len1 < strlen(buf1));
-  tt_assert(detect_compression_method(buf2, len1) == GZIP_METHOD);
+  tt_assert(buf2 != NULL);
+  tt_int_op(len1, OP_LT, strlen(buf1));
+  tt_int_op(detect_compression_method(buf2, len1), OP_EQ, GZIP_METHOD);
 
   tt_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1,
                                  GZIP_METHOD, 1, LOG_INFO));
-  tt_assert(buf3);
+  tt_assert(buf3 != NULL);
   tt_int_op(strlen(buf1) + 1,OP_EQ, len2);
   tt_str_op(buf1,OP_EQ, buf3);
 
@@ -2273,11 +2273,11 @@ test_util_gzip(void *arg)
   tt_assert(!tor_gzip_compress(&buf2, &len1, buf1, strlen(buf1)+1,
                                  ZLIB_METHOD));
   tt_assert(buf2);
-  tt_assert(detect_compression_method(buf2, len1) == ZLIB_METHOD);
+  tt_int_op(detect_compression_method(buf2, len1), OP_EQ, ZLIB_METHOD);
 
   tt_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1,
                                    ZLIB_METHOD, 1, LOG_INFO));
-  tt_assert(buf3);
+  tt_assert(buf3 != NULL);
   tt_int_op(strlen(buf1) + 1,OP_EQ, len2);
   tt_str_op(buf1,OP_EQ, buf3);
 
@@ -2302,7 +2302,7 @@ test_util_gzip(void *arg)
     tor_strdup("String with low redundancy that won't be compressed much.");
   tt_assert(!tor_gzip_compress(&buf2, &len1, buf1, strlen(buf1)+1,
                                  ZLIB_METHOD));
-  tt_assert(len1>16);
+  tt_int_op(len1, OP_GT, 16);
   /* when we allow an incomplete string, we should succeed.*/
   tt_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1-16,
                                   ZLIB_METHOD, 0, LOG_INFO));
@@ -2314,7 +2314,7 @@ test_util_gzip(void *arg)
   tor_free(buf3);
   tt_assert(tor_gzip_uncompress(&buf3, &len2, buf2, len1-16,
                                  ZLIB_METHOD, 1, LOG_INFO));
-  tt_assert(!buf3);
+  tt_assert(buf3 == NULL);
 
   /* Now, try streaming compression. */
   tor_free(buf1);





More information about the tor-commits mailing list