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
This commit is contained in:
Alexander Færøy 2017-04-17 14:02:16 +02:00
parent b081a7ed21
commit a8821d8366
No known key found for this signature in database
GPG Key ID: E15081D5D3C3DB53

View File

@ -2257,13 +2257,13 @@ test_util_gzip(void *arg)
tt_assert(!tor_gzip_compress(&buf2, &len1, buf1, strlen(buf1)+1, tt_assert(!tor_gzip_compress(&buf2, &len1, buf1, strlen(buf1)+1,
GZIP_METHOD)); GZIP_METHOD));
tt_assert(buf2); tt_assert(buf2 != NULL);
tt_assert(len1 < strlen(buf1)); tt_int_op(len1, OP_LT, strlen(buf1));
tt_assert(detect_compression_method(buf2, len1) == GZIP_METHOD); tt_int_op(detect_compression_method(buf2, len1), OP_EQ, GZIP_METHOD);
tt_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1, tt_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1,
GZIP_METHOD, 1, LOG_INFO)); GZIP_METHOD, 1, LOG_INFO));
tt_assert(buf3); tt_assert(buf3 != NULL);
tt_int_op(strlen(buf1) + 1,OP_EQ, len2); tt_int_op(strlen(buf1) + 1,OP_EQ, len2);
tt_str_op(buf1,OP_EQ, buf3); 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, tt_assert(!tor_gzip_compress(&buf2, &len1, buf1, strlen(buf1)+1,
ZLIB_METHOD)); ZLIB_METHOD));
tt_assert(buf2); 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, tt_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1,
ZLIB_METHOD, 1, LOG_INFO)); ZLIB_METHOD, 1, LOG_INFO));
tt_assert(buf3); tt_assert(buf3 != NULL);
tt_int_op(strlen(buf1) + 1,OP_EQ, len2); tt_int_op(strlen(buf1) + 1,OP_EQ, len2);
tt_str_op(buf1,OP_EQ, buf3); 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."); tor_strdup("String with low redundancy that won't be compressed much.");
tt_assert(!tor_gzip_compress(&buf2, &len1, buf1, strlen(buf1)+1, tt_assert(!tor_gzip_compress(&buf2, &len1, buf1, strlen(buf1)+1,
ZLIB_METHOD)); ZLIB_METHOD));
tt_assert(len1>16); tt_int_op(len1, OP_GT, 16);
/* when we allow an incomplete string, we should succeed.*/ /* when we allow an incomplete string, we should succeed.*/
tt_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1-16, tt_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1-16,
ZLIB_METHOD, 0, LOG_INFO)); ZLIB_METHOD, 0, LOG_INFO));
@ -2314,7 +2314,7 @@ test_util_gzip(void *arg)
tor_free(buf3); tor_free(buf3);
tt_assert(tor_gzip_uncompress(&buf3, &len2, buf2, len1-16, tt_assert(tor_gzip_uncompress(&buf3, &len2, buf2, len1-16,
ZLIB_METHOD, 1, LOG_INFO)); ZLIB_METHOD, 1, LOG_INFO));
tt_assert(!buf3); tt_assert(buf3 == NULL);
/* Now, try streaming compression. */ /* Now, try streaming compression. */
tor_free(buf1); tor_free(buf1);