mirror of https://git.tukaani.org/xz.git
Tests: Convert test_bcj_exact_size to tuktest.
The compress() and decompress() functions were merged because the later depends on the former so they need to be a single test case.
This commit is contained in:
parent
96da21470f
commit
754d39fbeb
|
@ -15,25 +15,24 @@
|
||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
|
|
||||||
|
|
||||||
/// Something to be compressed
|
|
||||||
static const uint8_t in[16] = "0123456789ABCDEF";
|
|
||||||
|
|
||||||
/// in[] after compression
|
|
||||||
static uint8_t compressed[1024];
|
|
||||||
static size_t compressed_size = 0;
|
|
||||||
|
|
||||||
/// Output buffer for decompressing compressed[]
|
|
||||||
static uint8_t out[sizeof(in)];
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
compress(void)
|
test_exact_size(void)
|
||||||
{
|
{
|
||||||
|
// Something to be compressed
|
||||||
|
const uint8_t in[16] = "0123456789ABCDEF";
|
||||||
|
|
||||||
|
// in[] after compression
|
||||||
|
uint8_t compressed[1024];
|
||||||
|
size_t compressed_size = 0;
|
||||||
|
|
||||||
|
// Output buffer for decompressing compressed[]
|
||||||
|
uint8_t out[sizeof(in)];
|
||||||
|
|
||||||
// Compress with PowerPC BCJ and LZMA2. PowerPC BCJ is used because
|
// Compress with PowerPC BCJ and LZMA2. PowerPC BCJ is used because
|
||||||
// it has fixed 4-byte alignment which makes triggering the potential
|
// it has fixed 4-byte alignment which makes triggering the potential
|
||||||
// bug easy.
|
// bug easy.
|
||||||
lzma_options_lzma opt_lzma2;
|
lzma_options_lzma opt_lzma2;
|
||||||
succeed(lzma_lzma_preset(&opt_lzma2, 0));
|
assert_false(lzma_lzma_preset(&opt_lzma2, 0));
|
||||||
|
|
||||||
lzma_filter filters[3] = {
|
lzma_filter filters[3] = {
|
||||||
{ .id = LZMA_FILTER_POWERPC, .options = NULL },
|
{ .id = LZMA_FILTER_POWERPC, .options = NULL },
|
||||||
|
@ -41,18 +40,16 @@ compress(void)
|
||||||
{ .id = LZMA_VLI_UNKNOWN, .options = NULL },
|
{ .id = LZMA_VLI_UNKNOWN, .options = NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(lzma_stream_buffer_encode(filters, LZMA_CHECK_CRC32, NULL,
|
assert_lzma_ret(lzma_stream_buffer_encode(
|
||||||
|
filters, LZMA_CHECK_CRC32, NULL,
|
||||||
in, sizeof(in),
|
in, sizeof(in),
|
||||||
compressed, &compressed_size, sizeof(compressed))
|
compressed, &compressed_size, sizeof(compressed)),
|
||||||
== LZMA_OK);
|
LZMA_OK);
|
||||||
}
|
|
||||||
|
|
||||||
|
// Decompress so that we won't give more output space than
|
||||||
static void
|
// the Stream will need.
|
||||||
decompress(void)
|
|
||||||
{
|
|
||||||
lzma_stream strm = LZMA_STREAM_INIT;
|
lzma_stream strm = LZMA_STREAM_INIT;
|
||||||
expect(lzma_stream_decoder(&strm, 10 << 20, 0) == LZMA_OK);
|
assert_lzma_ret(lzma_stream_decoder(&strm, 10 << 20, 0), LZMA_OK);
|
||||||
|
|
||||||
strm.next_in = compressed;
|
strm.next_in = compressed;
|
||||||
strm.next_out = out;
|
strm.next_out = out;
|
||||||
|
@ -63,13 +60,13 @@ decompress(void)
|
||||||
|
|
||||||
const lzma_ret ret = lzma_code(&strm, LZMA_RUN);
|
const lzma_ret ret = lzma_code(&strm, LZMA_RUN);
|
||||||
if (ret == LZMA_STREAM_END) {
|
if (ret == LZMA_STREAM_END) {
|
||||||
expect(strm.total_in == compressed_size);
|
assert_uint_eq(strm.total_in, compressed_size);
|
||||||
expect(strm.total_out == sizeof(in));
|
assert_uint_eq(strm.total_out, sizeof(in));
|
||||||
lzma_end(&strm);
|
lzma_end(&strm);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(ret == LZMA_OK);
|
assert_lzma_ret(ret, LZMA_OK);
|
||||||
|
|
||||||
if (strm.total_out < sizeof(in))
|
if (strm.total_out < sizeof(in))
|
||||||
strm.avail_out = 1;
|
strm.avail_out = 1;
|
||||||
|
@ -78,7 +75,7 @@ decompress(void)
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
decompress_empty(void)
|
test_empty_block(void)
|
||||||
{
|
{
|
||||||
// An empty file with one Block using PowerPC BCJ and LZMA2.
|
// An empty file with one Block using PowerPC BCJ and LZMA2.
|
||||||
static const uint8_t empty_bcj_lzma2[] = {
|
static const uint8_t empty_bcj_lzma2[] = {
|
||||||
|
@ -93,21 +90,31 @@ decompress_empty(void)
|
||||||
|
|
||||||
// Decompress without giving any output space.
|
// Decompress without giving any output space.
|
||||||
uint64_t memlimit = 1 << 20;
|
uint64_t memlimit = 1 << 20;
|
||||||
|
uint8_t out[1];
|
||||||
size_t in_pos = 0;
|
size_t in_pos = 0;
|
||||||
size_t out_pos = 0;
|
size_t out_pos = 0;
|
||||||
expect(lzma_stream_buffer_decode(&memlimit, 0, NULL,
|
assert_lzma_ret(lzma_stream_buffer_decode(&memlimit, 0, NULL,
|
||||||
empty_bcj_lzma2, &in_pos, sizeof(empty_bcj_lzma2),
|
empty_bcj_lzma2, &in_pos, sizeof(empty_bcj_lzma2),
|
||||||
out, &out_pos, 0) == LZMA_OK);
|
out, &out_pos, 0),
|
||||||
expect(in_pos == sizeof(empty_bcj_lzma2));
|
LZMA_OK);
|
||||||
expect(out_pos == 0);
|
assert_uint_eq(in_pos, sizeof(empty_bcj_lzma2));
|
||||||
|
assert_uint_eq(out_pos, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern int
|
extern int
|
||||||
main(void)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
compress();
|
tuktest_start(argc, argv);
|
||||||
decompress();
|
|
||||||
decompress_empty();
|
if (!lzma_filter_encoder_is_supported(LZMA_FILTER_POWERPC)
|
||||||
return 0;
|
|| !lzma_filter_decoder_is_supported(
|
||||||
|
LZMA_FILTER_POWERPC))
|
||||||
|
tuktest_early_skip("PowerPC BCJ encoder and/or decoder "
|
||||||
|
"is disabled");
|
||||||
|
|
||||||
|
tuktest_run(test_exact_size);
|
||||||
|
tuktest_run(test_empty_block);
|
||||||
|
|
||||||
|
return tuktest_end();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue