diff options
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r-- | src/test/test_util.c | 111 |
1 files changed, 103 insertions, 8 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c index dec1d526c8..a861f15ab1 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -2255,8 +2255,15 @@ test_util_compress_impl(compress_method_t method) tt_assert(!tor_compress(&buf2, &len1, buf1, strlen(buf1)+1, method)); tt_assert(buf2 != NULL); - tt_int_op(len1, OP_LT, strlen(buf1)); - tt_int_op(detect_compression_method(buf2, len1), OP_EQ, method); + if (method == NO_METHOD) { + // The identity transform doesn't actually compress, and it isn't + // detectable as "the identity transform." + tt_int_op(len1, OP_EQ, strlen(buf1)+1); + tt_int_op(detect_compression_method(buf2, len1), OP_EQ, UNKNOWN_METHOD); + } else { + tt_int_op(len1, OP_LT, strlen(buf1)); + tt_int_op(detect_compression_method(buf2, len1), OP_EQ, method); + } tt_assert(!tor_uncompress(&buf3, &len2, buf2, len1, method, 1, LOG_INFO)); tt_assert(buf3 != NULL); @@ -2300,11 +2307,14 @@ test_util_compress_impl(compress_method_t method) tt_assert(fast_memeq(buf1, buf3, len2)); tt_int_op(buf3[len2], OP_EQ, 0); - /* when we demand a complete output, this must fail. */ + /* when we demand a complete output from a real compression method, this + * must fail. */ tor_free(buf3); - tt_assert(tor_uncompress(&buf3, &len2, buf2, len1-16, - method, 1, LOG_INFO)); - tt_assert(buf3 == NULL); + if (method != NO_METHOD) { + tt_assert(tor_uncompress(&buf3, &len2, buf2, len1-16, + method, 1, LOG_INFO)); + tt_assert(buf3 == NULL); + } done: tor_free(buf1); @@ -2337,7 +2347,11 @@ test_util_compress_stream_impl(compress_method_t method, tt_int_op(tor_compress_process(state, &cp1, &len1, &ccp2, &len2, 1), OP_EQ, TOR_COMPRESS_DONE); tt_int_op(0, OP_EQ, len2); - tt_assert(cp1 > cp2); /* Make sure we really added something. */ + if (method == NO_METHOD) { + tt_ptr_op(cp1, OP_EQ, cp2); + } else { + tt_assert(cp1 > cp2); /* Make sure we really added something. */ + } tt_assert(!tor_uncompress(&buf3, &len2, buf1, 1024-len1, method, 1, LOG_WARN)); @@ -5717,6 +5731,85 @@ test_util_htonll(void *arg) ; } +static void +test_util_get_unquoted_path(void *arg) +{ + (void)arg; + + char *r; + + r = get_unquoted_path("\""); // " + tt_ptr_op(r, OP_EQ, NULL); + tor_free(r); + + r = get_unquoted_path("\"\"\""); // """ + tt_ptr_op(r, OP_EQ, NULL); + tor_free(r); + + r = get_unquoted_path("\\\""); // \" + tt_ptr_op(r, OP_EQ, NULL); + tor_free(r); + + r = get_unquoted_path("\\\"\\\""); // \"\" + tt_ptr_op(r, OP_EQ, NULL); + tor_free(r); + + r = get_unquoted_path("A\\B\\C\""); // A\B\C" + tt_ptr_op(r, OP_EQ, NULL); + tor_free(r); + + r = get_unquoted_path("\"A\\B\\C"); // "A\B\C + tt_ptr_op(r, OP_EQ, NULL); + tor_free(r); + + r = get_unquoted_path("\"A\\B\"C\""); // "A\B"C" + tt_ptr_op(r, OP_EQ, NULL); + tor_free(r); + + r = get_unquoted_path("A\\B\"C"); // A\B"C + tt_ptr_op(r, OP_EQ, NULL); + tor_free(r); + + r = get_unquoted_path(""); + tt_str_op(r, OP_EQ, ""); + tor_free(r); + + r = get_unquoted_path("\"\""); // "" + tt_str_op(r, OP_EQ, ""); + tor_free(r); + + r = get_unquoted_path("A\\B\\C"); // A\B\C + tt_str_op(r, OP_EQ, "A\\B\\C"); // A\B\C + tor_free(r); + + r = get_unquoted_path("\"A\\B\\C\""); // "A\B\C" + tt_str_op(r, OP_EQ, "A\\B\\C"); // A\B\C + tor_free(r); + + r = get_unquoted_path("\"\\\""); // "\" + tt_str_op(r, OP_EQ, "\\"); // \ /* comment to prevent line continuation */ + tor_free(r); + + r = get_unquoted_path("\"\\\"\""); // "\"" + tt_str_op(r, OP_EQ, "\""); // " + tor_free(r); + + r = get_unquoted_path("\"A\\B\\C\\\"\""); // "A\B\C\"" + tt_str_op(r, OP_EQ, "A\\B\\C\""); // A\B\C" + tor_free(r); + + r = get_unquoted_path("A\\B\\\"C"); // A\B\"C + tt_str_op(r, OP_EQ, "A\\B\"C"); // A\B"C + tor_free(r); + + r = get_unquoted_path("\"A\\B\\\"C\""); // "A\B\"C" + tt_str_op(r, OP_EQ, "A\\B\"C"); // A\B"C + tor_free(r); + + done: + ; +} + #define UTIL_LEGACY(name) \ { #name, test_util_ ## name , 0, NULL, NULL } @@ -5753,8 +5846,9 @@ struct testcase_t util_tests[] = { UTIL_LEGACY(pow2), COMPRESS(zlib, "deflate"), COMPRESS(gzip, "gzip"), - COMPRESS(lzma, "x-lzma"), + COMPRESS(lzma, "x-tor-lzma"), COMPRESS(zstd, "x-zstd"), + COMPRESS(none, "identity"), UTIL_TEST(gzip_compression_bomb, TT_FORK), UTIL_LEGACY(datadir), UTIL_LEGACY(memarea), @@ -5818,6 +5912,7 @@ struct testcase_t util_tests[] = { UTIL_TEST(monotonic_time, 0), UTIL_TEST(monotonic_time_ratchet, TT_FORK), UTIL_TEST(htonll, 0), + UTIL_TEST(get_unquoted_path, 0), END_OF_TESTCASES }; |