diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-04-08 08:15:25 +0200 |
---|---|---|
committer | Daan De Meyer <daan.j.demeyer@gmail.com> | 2023-04-11 09:14:34 +0200 |
commit | bfeaa62dbc9d2a436e2d3413386ba38f48b5d502 (patch) | |
tree | b94d4d38673ccdbc0f3a3b714ced0e92b4cb8737 /src/test/test-compress.c | |
parent | Merge pull request #27206 from yuwata/udev-rename (diff) | |
download | systemd-bfeaa62dbc9d2a436e2d3413386ba38f48b5d502.tar.xz systemd-bfeaa62dbc9d2a436e2d3413386ba38f48b5d502.zip |
compress: replace compress_blob() with compress_blob_explicit()
And make compress_xyz() return 0 on success, as we know which compression
algorithm is used when calling compress_blob().
Follow-up for 2360352ef02548723ac0c8eaf5ff6905eb9eeca5.
Diffstat (limited to '')
-rw-r--r-- | src/test/test-compress.c | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/src/test/test-compress.c b/src/test/test-compress.c index f5ec47cb3c..18f8ce3b35 100644 --- a/src/test/test-compress.c +++ b/src/test/test-compress.c @@ -46,7 +46,6 @@ typedef int (decompress_stream_t)(int fdf, int fdt, uint64_t max_size); #if HAVE_COMPRESSION _unused_ static void test_compress_decompress( - int flag, const char *compression, compress_blob_t compress, decompress_blob_t decompress, @@ -67,7 +66,7 @@ _unused_ static void test_compress_decompress( log_info_errno(r, "compression failed: %m"); assert_se(may_fail); } else { - assert_se(r == flag); + assert_se(r >= 0); r = decompress(compressed, csize, (void **) &decompressed, &csize, 0); assert_se(r == 0); @@ -120,7 +119,7 @@ _unused_ static void test_decompress_startswith(const char *compression, assert_se(compressed2); r = compress(data, data_len, compressed, BUFSIZE_2, &csize); } - assert_se(r > 0); + assert_se(r >= 0); len = strlen(data); @@ -151,7 +150,7 @@ _unused_ static void test_decompress_startswith_short(const char *compression, log_info("/* %s with %s */", __func__, compression); r = compress(TEXT, sizeof TEXT, buf, sizeof buf, &csize); - assert_se(r > 0); + assert_se(r >= 0); for (size_t i = 1; i < strlen(TEXT); i++) { _cleanup_free_ void *buf2 = NULL; @@ -163,8 +162,7 @@ _unused_ static void test_decompress_startswith_short(const char *compression, } } -_unused_ static void test_compress_stream(int flag, - const char *compression, +_unused_ static void test_compress_stream(const char *compression, const char *cat, compress_stream_t compress, decompress_stream_t decompress, @@ -195,7 +193,7 @@ _unused_ static void test_compress_stream(int flag, assert_se((dst = mkostemp_safe(pattern)) >= 0); - assert_se(compress(src, dst, -1, &uncompressed_size) == flag); + assert_se(compress(src, dst, -1, &uncompressed_size) >= 0); if (cat) { assert_se(asprintf(&cmd, "%s %s | diff %s -", cat, pattern, srcfile) > 0); @@ -293,11 +291,9 @@ int main(int argc, char *argv[]) { random_bytes(data + 7, sizeof(data) - 7); #if HAVE_XZ - test_compress_decompress(COMPRESSION_XZ, "XZ", - compress_blob_xz, decompress_blob_xz, + test_compress_decompress("XZ", compress_blob_xz, decompress_blob_xz, text, sizeof(text), false); - test_compress_decompress(COMPRESSION_XZ, "XZ", - compress_blob_xz, decompress_blob_xz, + test_compress_decompress("XZ", compress_blob_xz, decompress_blob_xz, data, sizeof(data), true); test_decompress_startswith("XZ", @@ -310,7 +306,7 @@ int main(int argc, char *argv[]) { compress_blob_xz, decompress_startswith_xz, huge, HUGE_SIZE, true); - test_compress_stream(COMPRESSION_XZ, "XZ", "xzcat", + test_compress_stream("XZ", "xzcat", compress_stream_xz, decompress_stream_xz, srcfile); test_decompress_startswith_short("XZ", compress_blob_xz, decompress_startswith_xz); @@ -320,11 +316,9 @@ int main(int argc, char *argv[]) { #endif #if HAVE_LZ4 - test_compress_decompress(COMPRESSION_LZ4, "LZ4", - compress_blob_lz4, decompress_blob_lz4, + test_compress_decompress("LZ4", compress_blob_lz4, decompress_blob_lz4, text, sizeof(text), false); - test_compress_decompress(COMPRESSION_LZ4, "LZ4", - compress_blob_lz4, decompress_blob_lz4, + test_compress_decompress("LZ4", compress_blob_lz4, decompress_blob_lz4, data, sizeof(data), true); test_decompress_startswith("LZ4", @@ -337,7 +331,7 @@ int main(int argc, char *argv[]) { compress_blob_lz4, decompress_startswith_lz4, huge, HUGE_SIZE, true); - test_compress_stream(COMPRESSION_LZ4, "LZ4", "lz4cat", + test_compress_stream("LZ4", "lz4cat", compress_stream_lz4, decompress_stream_lz4, srcfile); test_lz4_decompress_partial(); @@ -349,11 +343,9 @@ int main(int argc, char *argv[]) { #endif #if HAVE_ZSTD - test_compress_decompress(COMPRESSION_ZSTD, "ZSTD", - compress_blob_zstd, decompress_blob_zstd, + test_compress_decompress("ZSTD", compress_blob_zstd, decompress_blob_zstd, text, sizeof(text), false); - test_compress_decompress(COMPRESSION_ZSTD, "ZSTD", - compress_blob_zstd, decompress_blob_zstd, + test_compress_decompress("ZSTD", compress_blob_zstd, decompress_blob_zstd, data, sizeof(data), true); test_decompress_startswith("ZSTD", @@ -366,7 +358,7 @@ int main(int argc, char *argv[]) { compress_blob_zstd, decompress_startswith_zstd, huge, HUGE_SIZE, true); - test_compress_stream(COMPRESSION_ZSTD, "ZSTD", "zstdcat", + test_compress_stream("ZSTD", "zstdcat", compress_stream_zstd, decompress_stream_zstd, srcfile); test_decompress_startswith_short("ZSTD", compress_blob_zstd, decompress_startswith_zstd); |