Commit b2e7c356 authored by Nick Mathewson's avatar Nick Mathewson 🎨
Browse files

Prefer tt_assert in unit tests, not tor_assert

parent 2fd56030
o Code simplifications and refactoring (tests):
- Use tt_assert, not tor_assert, for checking for test failures.
This makes the unit tests more able to go on in the event that
one of them fails.
......@@ -630,7 +630,7 @@ test_crypto_aes_iv(void)
crypto_free_cipher_env(cipher);
cipher = NULL;
test_eq(encrypted_size, 16 + 4095);
tor_assert(encrypted_size > 0); /* This is obviously true, since 4111 is
tt_assert(encrypted_size > 0); /* This is obviously true, since 4111 is
* greater than 0, but its truth is not
* obvious to all analysis tools. */
cipher = crypto_create_init_cipher(key1, 0);
......@@ -639,7 +639,7 @@ test_crypto_aes_iv(void)
crypto_free_cipher_env(cipher);
cipher = NULL;
test_eq(decrypted_size, 4095);
tor_assert(decrypted_size > 0);
tt_assert(decrypted_size > 0);
test_memeq(plain, decrypted1, 4095);
/* Encrypt a second time (with a new random initialization vector). */
cipher = crypto_create_init_cipher(key1, 1);
......@@ -648,14 +648,14 @@ test_crypto_aes_iv(void)
crypto_free_cipher_env(cipher);
cipher = NULL;
test_eq(encrypted_size, 16 + 4095);
tor_assert(encrypted_size > 0);
tt_assert(encrypted_size > 0);
cipher = crypto_create_init_cipher(key1, 0);
decrypted_size = crypto_cipher_decrypt_with_iv(cipher, decrypted2, 4095,
encrypted2, encrypted_size);
crypto_free_cipher_env(cipher);
cipher = NULL;
test_eq(decrypted_size, 4095);
tor_assert(decrypted_size > 0);
tt_assert(decrypted_size > 0);
test_memeq(plain, decrypted2, 4095);
test_memneq(encrypted1, encrypted2, encrypted_size);
/* Decrypt with the wrong key. */
......@@ -680,14 +680,14 @@ test_crypto_aes_iv(void)
crypto_free_cipher_env(cipher);
cipher = NULL;
test_eq(encrypted_size, 16 + 1);
tor_assert(encrypted_size > 0);
tt_assert(encrypted_size > 0);
cipher = crypto_create_init_cipher(key1, 0);
decrypted_size = crypto_cipher_decrypt_with_iv(cipher, decrypted1, 1,
encrypted1, encrypted_size);
crypto_free_cipher_env(cipher);
cipher = NULL;
test_eq(decrypted_size, 1);
tor_assert(decrypted_size > 0);
tt_assert(decrypted_size > 0);
test_memeq(plain_1, decrypted1, 1);
/* Special length case: 15. */
cipher = crypto_create_init_cipher(key1, 1);
......@@ -696,14 +696,14 @@ test_crypto_aes_iv(void)
crypto_free_cipher_env(cipher);
cipher = NULL;
test_eq(encrypted_size, 16 + 15);
tor_assert(encrypted_size > 0);
tt_assert(encrypted_size > 0);
cipher = crypto_create_init_cipher(key1, 0);
decrypted_size = crypto_cipher_decrypt_with_iv(cipher, decrypted1, 15,
encrypted1, encrypted_size);
crypto_free_cipher_env(cipher);
cipher = NULL;
test_eq(decrypted_size, 15);
tor_assert(decrypted_size > 0);
tt_assert(decrypted_size > 0);
test_memeq(plain_15, decrypted1, 15);
/* Special length case: 16. */
cipher = crypto_create_init_cipher(key1, 1);
......@@ -712,14 +712,14 @@ test_crypto_aes_iv(void)
crypto_free_cipher_env(cipher);
cipher = NULL;
test_eq(encrypted_size, 16 + 16);
tor_assert(encrypted_size > 0);
tt_assert(encrypted_size > 0);
cipher = crypto_create_init_cipher(key1, 0);
decrypted_size = crypto_cipher_decrypt_with_iv(cipher, decrypted1, 16,
encrypted1, encrypted_size);
crypto_free_cipher_env(cipher);
cipher = NULL;
test_eq(decrypted_size, 16);
tor_assert(decrypted_size > 0);
tt_assert(decrypted_size > 0);
test_memeq(plain_16, decrypted1, 16);
/* Special length case: 17. */
cipher = crypto_create_init_cipher(key1, 1);
......@@ -728,12 +728,12 @@ test_crypto_aes_iv(void)
crypto_free_cipher_env(cipher);
cipher = NULL;
test_eq(encrypted_size, 16 + 17);
tor_assert(encrypted_size > 0);
tt_assert(encrypted_size > 0);
cipher = crypto_create_init_cipher(key1, 0);
decrypted_size = crypto_cipher_decrypt_with_iv(cipher, decrypted1, 17,
encrypted1, encrypted_size);
test_eq(decrypted_size, 17);
tor_assert(decrypted_size > 0);
tt_assert(decrypted_size > 0);
test_memeq(plain_17, decrypted1, 17);
done:
......
......@@ -1169,10 +1169,10 @@ test_dir_v3_networkstatus(void)
/* Extract a detached signature from con3. */
detached_text1 = get_detached_sigs(con3, con_md3);
tor_assert(detached_text1);
tt_assert(detached_text1);
/* Try to parse it. */
dsig1 = networkstatus_parse_detached_signatures(detached_text1, NULL);
tor_assert(dsig1);
tt_assert(dsig1);
/* Are parsed values as expected? */
test_eq(dsig1->valid_after, con3->valid_after);
......
......@@ -376,7 +376,7 @@ test_util_strmisc(void)
/* Test memmem and memstr */
{
const char *haystack = "abcde";
tor_assert(!tor_memmem(haystack, 5, "ef", 2));
tt_assert(!tor_memmem(haystack, 5, "ef", 2));
test_eq_ptr(tor_memmem(haystack, 5, "cd", 2), haystack + 2);
test_eq_ptr(tor_memmem(haystack, 5, "cde", 3), haystack + 2);
haystack = "ababcad";
......@@ -640,26 +640,26 @@ test_util_gzip(void)
tor_strdup("String with low redundancy that won't be compressed much.");
test_assert(!tor_gzip_compress(&buf2, &len1, buf1, strlen(buf1)+1,
ZLIB_METHOD));
tor_assert(len1>16);
tt_assert(len1>16);
/* when we allow an incomplete string, we should succeed.*/
tor_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1-16,
tt_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1-16,
ZLIB_METHOD, 0, LOG_INFO));
buf3[len2]='\0';
tor_assert(len2 > 5);
tor_assert(!strcmpstart(buf1, buf3));
tt_assert(len2 > 5);
tt_assert(!strcmpstart(buf1, buf3));
/* when we demand a complete string, this must fail. */
tor_free(buf3);
tor_assert(tor_gzip_uncompress(&buf3, &len2, buf2, len1-16,
tt_assert(tor_gzip_uncompress(&buf3, &len2, buf2, len1-16,
ZLIB_METHOD, 1, LOG_INFO));
tor_assert(!buf3);
tt_assert(!buf3);
/* Now, try streaming compression. */
tor_free(buf1);
tor_free(buf2);
tor_free(buf3);
state = tor_zlib_new(1, ZLIB_METHOD);
tor_assert(state);
tt_assert(state);
cp1 = buf1 = tor_malloc(1024);
len1 = 1024;
ccp2 = "ABCDEFGHIJABCDEFGHIJ";
......@@ -676,7 +676,7 @@ test_util_gzip(void)
test_eq(len2, 0);
test_assert(cp1 > cp2); /* Make sure we really added something. */
tor_assert(!tor_gzip_uncompress(&buf3, &len2, buf1, 1024-len1,
tt_assert(!tor_gzip_uncompress(&buf3, &len2, buf1, 1024-len1,
ZLIB_METHOD, 1, LOG_WARN));
test_streq(buf3, "ABCDEFGHIJABCDEFGHIJ"); /*Make sure it compressed right.*/
......@@ -1397,7 +1397,7 @@ run_util_spawn_background(const char *argv[], const char *expected_out,
/* Check stdout */
pos = read_all(stdout_pipe, stdout_buf, sizeof(stdout_buf) - 1, 0);
tor_assert(pos >= 0);
tt_assert(pos >= 0);
stdout_buf[pos] = '\0';
tt_int_op(pos, ==, strlen(expected_out));
tt_str_op(stdout_buf, ==, expected_out);
......@@ -1412,7 +1412,7 @@ run_util_spawn_background(const char *argv[], const char *expected_out,
/* Check stderr */
pos = read_all(stderr_pipe, stderr_buf, sizeof(stderr_buf) - 1, 0);
tor_assert(pos >= 0);
tt_assert(pos >= 0);
stderr_buf[pos] = '\0';
tt_int_op(pos, ==, strlen(expected_err));
tt_str_op(stderr_buf, ==, expected_err);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment