diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2022-06-02 20:31:03 +0300 |
---|---|---|
committer | Lasse Collin <lasse.collin@tukaani.org> | 2022-06-02 20:45:05 +0300 |
commit | faf5ff8899d539b4dcd2a7e5280cb820a4746c86 (patch) | |
tree | 1aabdae809875df03277ce846c1a85a1da089864 /tests | |
parent | Tests: Convert test_bcj_exact_size to tuktest. (diff) | |
download | xz-faf5ff8899d539b4dcd2a7e5280cb820a4746c86.tar.xz |
Tests: Convert test_block_header to tuktest.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_block_header.c | 89 |
1 files changed, 52 insertions, 37 deletions
diff --git a/tests/test_block_header.c b/tests/test_block_header.c index 373a8077..2f0184ac 100644 --- a/tests/test_block_header.c +++ b/tests/test_block_header.c @@ -80,7 +80,8 @@ static lzma_filter filters_five[6] = { static void code(void) { - expect(lzma_block_header_encode(&known_options, buf) == LZMA_OK); + assert_lzma_ret(lzma_block_header_encode(&known_options, buf), + LZMA_OK); lzma_filter filters[LZMA_FILTERS_MAX + 1]; memcrap(filters, sizeof(filters)); @@ -89,17 +90,17 @@ code(void) decoded_options.header_size = known_options.header_size; decoded_options.check = known_options.check; decoded_options.filters = filters; - expect(lzma_block_header_decode(&decoded_options, NULL, buf) - == LZMA_OK); + assert_lzma_ret(lzma_block_header_decode(&decoded_options, NULL, buf), + LZMA_OK); - expect(known_options.compressed_size - == decoded_options.compressed_size); - expect(known_options.uncompressed_size - == decoded_options.uncompressed_size); + assert_uint_eq(decoded_options.compressed_size, + known_options.compressed_size); + assert_uint_eq(decoded_options.uncompressed_size, + known_options.uncompressed_size); for (size_t i = 0; known_options.filters[i].id != LZMA_VLI_UNKNOWN; ++i) - expect(known_options.filters[i].id == filters[i].id); + assert_uint_eq(filters[i].id, known_options.filters[i].id); for (size_t i = 0; i < LZMA_FILTERS_MAX; ++i) free(decoded_options.filters[i].options); @@ -116,39 +117,44 @@ test1(void) .filters = NULL, }; - expect(lzma_block_header_size(&known_options) == LZMA_PROG_ERROR); + assert_lzma_ret(lzma_block_header_size(&known_options), + LZMA_PROG_ERROR); known_options.filters = filters_none; - expect(lzma_block_header_size(&known_options) == LZMA_PROG_ERROR); + assert_lzma_ret(lzma_block_header_size(&known_options), + LZMA_PROG_ERROR); known_options.filters = filters_five; - expect(lzma_block_header_size(&known_options) == LZMA_PROG_ERROR); + assert_lzma_ret(lzma_block_header_size(&known_options), + LZMA_PROG_ERROR); known_options.filters = filters_one; - expect(lzma_block_header_size(&known_options) == LZMA_OK); + assert_lzma_ret(lzma_block_header_size(&known_options), LZMA_OK); // Some invalid value, which gets ignored. known_options.check = (lzma_check)(99); - expect(lzma_block_header_size(&known_options) == LZMA_OK); + assert_lzma_ret(lzma_block_header_size(&known_options), LZMA_OK); known_options.compressed_size = 5; - expect(lzma_block_header_size(&known_options) == LZMA_OK); + assert_lzma_ret(lzma_block_header_size(&known_options), LZMA_OK); known_options.compressed_size = 0; // Cannot be zero. - expect(lzma_block_header_size(&known_options) == LZMA_PROG_ERROR); + assert_lzma_ret(lzma_block_header_size(&known_options), + LZMA_PROG_ERROR); // LZMA_VLI_MAX is too big to keep the total size of the Block // a valid VLI, but lzma_block_header_size() is not meant // to validate it. (lzma_block_header_encode() must validate it.) known_options.compressed_size = LZMA_VLI_MAX; - expect(lzma_block_header_size(&known_options) == LZMA_OK); + assert_lzma_ret(lzma_block_header_size(&known_options), LZMA_OK); known_options.compressed_size = LZMA_VLI_UNKNOWN; known_options.uncompressed_size = 0; - expect(lzma_block_header_size(&known_options) == LZMA_OK); + assert_lzma_ret(lzma_block_header_size(&known_options), LZMA_OK); known_options.uncompressed_size = LZMA_VLI_MAX + 1; - expect(lzma_block_header_size(&known_options) == LZMA_PROG_ERROR); + assert_lzma_ret(lzma_block_header_size(&known_options), + LZMA_PROG_ERROR); } @@ -162,12 +168,12 @@ test2(void) .filters = filters_four, }; - expect(lzma_block_header_size(&known_options) == LZMA_OK); + assert_lzma_ret(lzma_block_header_size(&known_options), LZMA_OK); code(); known_options.compressed_size = 123456; known_options.uncompressed_size = 234567; - expect(lzma_block_header_size(&known_options) == LZMA_OK); + assert_lzma_ret(lzma_block_header_size(&known_options), LZMA_OK); code(); // We can make the sizes smaller while keeping the header size @@ -188,9 +194,10 @@ test3(void) .filters = filters_one, }; - expect(lzma_block_header_size(&known_options) == LZMA_OK); + assert_lzma_ret(lzma_block_header_size(&known_options), LZMA_OK); known_options.header_size += 4; - expect(lzma_block_header_encode(&known_options, buf) == LZMA_OK); + assert_lzma_ret(lzma_block_header_encode(&known_options, buf), + LZMA_OK); lzma_filter filters[LZMA_FILTERS_MAX + 1]; decoded_options.header_size = known_options.header_size; @@ -199,14 +206,14 @@ test3(void) // Wrong size ++buf[0]; - expect(lzma_block_header_decode(&decoded_options, NULL, buf) - == LZMA_PROG_ERROR); + assert_lzma_ret(lzma_block_header_decode(&decoded_options, NULL, buf), + LZMA_PROG_ERROR); --buf[0]; // Wrong CRC32 buf[known_options.header_size - 1] ^= 1; - expect(lzma_block_header_decode(&decoded_options, NULL, buf) - == LZMA_DATA_ERROR); + assert_lzma_ret(lzma_block_header_decode(&decoded_options, NULL, buf), + LZMA_DATA_ERROR); buf[known_options.header_size - 1] ^= 1; // Unsupported filter @@ -214,28 +221,36 @@ test3(void) buf[2] ^= 0x1F; write32le(buf + known_options.header_size - 4, lzma_crc32(buf, known_options.header_size - 4, 0)); - expect(lzma_block_header_decode(&decoded_options, NULL, buf) - == LZMA_OPTIONS_ERROR); + assert_lzma_ret(lzma_block_header_decode(&decoded_options, NULL, buf), + LZMA_OPTIONS_ERROR); buf[2] ^= 0x1F; // Non-nul Padding buf[known_options.header_size - 4 - 1] ^= 1; write32le(buf + known_options.header_size - 4, lzma_crc32(buf, known_options.header_size - 4, 0)); - expect(lzma_block_header_decode(&decoded_options, NULL, buf) - == LZMA_OPTIONS_ERROR); + assert_lzma_ret(lzma_block_header_decode(&decoded_options, NULL, buf), + LZMA_OPTIONS_ERROR); buf[known_options.header_size - 4 - 1] ^= 1; } -int -main(void) +extern int +main(int argc, char **argv) { - succeed(lzma_lzma_preset(&opt_lzma, 1)); + tuktest_start(argc, argv); - test1(); - test2(); - test3(); + if (!lzma_filter_encoder_is_supported(LZMA_FILTER_X86) + || !lzma_filter_decoder_is_supported(LZMA_FILTER_X86)) + tuktest_early_skip("x86 BCJ encoder and/or decoder " + "is disabled"); - return 0; + if (lzma_lzma_preset(&opt_lzma, 1)) + tuktest_error("lzma_lzma_preset() failed"); + + tuktest_run(test1); + tuktest_run(test2); + tuktest_run(test3); + + return tuktest_end(); } |