mirror of https://git.tukaani.org/xz.git
Tests: Convert test_block_header to tuktest.
This commit is contained in:
parent
754d39fbeb
commit
faf5ff8899
|
@ -80,7 +80,8 @@ static lzma_filter filters_five[6] = {
|
||||||
static void
|
static void
|
||||||
code(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];
|
lzma_filter filters[LZMA_FILTERS_MAX + 1];
|
||||||
memcrap(filters, sizeof(filters));
|
memcrap(filters, sizeof(filters));
|
||||||
|
@ -89,17 +90,17 @@ code(void)
|
||||||
decoded_options.header_size = known_options.header_size;
|
decoded_options.header_size = known_options.header_size;
|
||||||
decoded_options.check = known_options.check;
|
decoded_options.check = known_options.check;
|
||||||
decoded_options.filters = filters;
|
decoded_options.filters = filters;
|
||||||
expect(lzma_block_header_decode(&decoded_options, NULL, buf)
|
assert_lzma_ret(lzma_block_header_decode(&decoded_options, NULL, buf),
|
||||||
== LZMA_OK);
|
LZMA_OK);
|
||||||
|
|
||||||
expect(known_options.compressed_size
|
assert_uint_eq(decoded_options.compressed_size,
|
||||||
== decoded_options.compressed_size);
|
known_options.compressed_size);
|
||||||
expect(known_options.uncompressed_size
|
assert_uint_eq(decoded_options.uncompressed_size,
|
||||||
== decoded_options.uncompressed_size);
|
known_options.uncompressed_size);
|
||||||
|
|
||||||
for (size_t i = 0; known_options.filters[i].id
|
for (size_t i = 0; known_options.filters[i].id
|
||||||
!= LZMA_VLI_UNKNOWN; ++i)
|
!= 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)
|
for (size_t i = 0; i < LZMA_FILTERS_MAX; ++i)
|
||||||
free(decoded_options.filters[i].options);
|
free(decoded_options.filters[i].options);
|
||||||
|
@ -116,39 +117,44 @@ test1(void)
|
||||||
.filters = NULL,
|
.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;
|
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;
|
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;
|
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.
|
// Some invalid value, which gets ignored.
|
||||||
known_options.check = (lzma_check)(99);
|
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;
|
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.
|
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
|
// 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
|
// a valid VLI, but lzma_block_header_size() is not meant
|
||||||
// to validate it. (lzma_block_header_encode() must validate it.)
|
// to validate it. (lzma_block_header_encode() must validate it.)
|
||||||
known_options.compressed_size = LZMA_VLI_MAX;
|
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.compressed_size = LZMA_VLI_UNKNOWN;
|
||||||
known_options.uncompressed_size = 0;
|
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;
|
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,
|
.filters = filters_four,
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(lzma_block_header_size(&known_options) == LZMA_OK);
|
assert_lzma_ret(lzma_block_header_size(&known_options), LZMA_OK);
|
||||||
code();
|
code();
|
||||||
|
|
||||||
known_options.compressed_size = 123456;
|
known_options.compressed_size = 123456;
|
||||||
known_options.uncompressed_size = 234567;
|
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();
|
code();
|
||||||
|
|
||||||
// We can make the sizes smaller while keeping the header size
|
// We can make the sizes smaller while keeping the header size
|
||||||
|
@ -188,9 +194,10 @@ test3(void)
|
||||||
.filters = filters_one,
|
.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;
|
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];
|
lzma_filter filters[LZMA_FILTERS_MAX + 1];
|
||||||
decoded_options.header_size = known_options.header_size;
|
decoded_options.header_size = known_options.header_size;
|
||||||
|
@ -199,14 +206,14 @@ test3(void)
|
||||||
|
|
||||||
// Wrong size
|
// Wrong size
|
||||||
++buf[0];
|
++buf[0];
|
||||||
expect(lzma_block_header_decode(&decoded_options, NULL, buf)
|
assert_lzma_ret(lzma_block_header_decode(&decoded_options, NULL, buf),
|
||||||
== LZMA_PROG_ERROR);
|
LZMA_PROG_ERROR);
|
||||||
--buf[0];
|
--buf[0];
|
||||||
|
|
||||||
// Wrong CRC32
|
// Wrong CRC32
|
||||||
buf[known_options.header_size - 1] ^= 1;
|
buf[known_options.header_size - 1] ^= 1;
|
||||||
expect(lzma_block_header_decode(&decoded_options, NULL, buf)
|
assert_lzma_ret(lzma_block_header_decode(&decoded_options, NULL, buf),
|
||||||
== LZMA_DATA_ERROR);
|
LZMA_DATA_ERROR);
|
||||||
buf[known_options.header_size - 1] ^= 1;
|
buf[known_options.header_size - 1] ^= 1;
|
||||||
|
|
||||||
// Unsupported filter
|
// Unsupported filter
|
||||||
|
@ -214,28 +221,36 @@ test3(void)
|
||||||
buf[2] ^= 0x1F;
|
buf[2] ^= 0x1F;
|
||||||
write32le(buf + known_options.header_size - 4,
|
write32le(buf + known_options.header_size - 4,
|
||||||
lzma_crc32(buf, known_options.header_size - 4, 0));
|
lzma_crc32(buf, known_options.header_size - 4, 0));
|
||||||
expect(lzma_block_header_decode(&decoded_options, NULL, buf)
|
assert_lzma_ret(lzma_block_header_decode(&decoded_options, NULL, buf),
|
||||||
== LZMA_OPTIONS_ERROR);
|
LZMA_OPTIONS_ERROR);
|
||||||
buf[2] ^= 0x1F;
|
buf[2] ^= 0x1F;
|
||||||
|
|
||||||
// Non-nul Padding
|
// Non-nul Padding
|
||||||
buf[known_options.header_size - 4 - 1] ^= 1;
|
buf[known_options.header_size - 4 - 1] ^= 1;
|
||||||
write32le(buf + known_options.header_size - 4,
|
write32le(buf + known_options.header_size - 4,
|
||||||
lzma_crc32(buf, known_options.header_size - 4, 0));
|
lzma_crc32(buf, known_options.header_size - 4, 0));
|
||||||
expect(lzma_block_header_decode(&decoded_options, NULL, buf)
|
assert_lzma_ret(lzma_block_header_decode(&decoded_options, NULL, buf),
|
||||||
== LZMA_OPTIONS_ERROR);
|
LZMA_OPTIONS_ERROR);
|
||||||
buf[known_options.header_size - 4 - 1] ^= 1;
|
buf[known_options.header_size - 4 - 1] ^= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
extern int
|
||||||
main(void)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
succeed(lzma_lzma_preset(&opt_lzma, 1));
|
tuktest_start(argc, argv);
|
||||||
|
|
||||||
test1();
|
if (!lzma_filter_encoder_is_supported(LZMA_FILTER_X86)
|
||||||
test2();
|
|| !lzma_filter_decoder_is_supported(LZMA_FILTER_X86))
|
||||||
test3();
|
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();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue