1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file test_bcj_exact_size.c
4 /// \brief Tests BCJ decoding when the output size is known
6 /// These tests fail with XZ Utils 5.0.3 and earlier.
8 // Author: Lasse Collin
10 // This file has been put into the public domain.
11 // You can do whatever you want with this file.
13 ///////////////////////////////////////////////////////////////////////////////
21 #if !defined(HAVE_ENCODERS) || !defined(HAVE_DECODERS)
22 assert_skip("Encoder or decoder support disabled");
24 if (!lzma_filter_encoder_is_supported(LZMA_FILTER_POWERPC
)
25 || !lzma_filter_decoder_is_supported(
27 assert_skip("PowerPC BCJ encoder and/or decoder "
30 // Something to be compressed
31 const uint8_t in
[16] = "0123456789ABCDEF";
33 // in[] after compression
34 uint8_t compressed
[1024];
35 size_t compressed_size
= 0;
37 // Output buffer for decompressing compressed[]
38 uint8_t out
[sizeof(in
)];
40 // Compress with PowerPC BCJ and LZMA2. PowerPC BCJ is used because
41 // it has fixed 4-byte alignment which makes triggering the potential
43 lzma_options_lzma opt_lzma2
;
44 assert_false(lzma_lzma_preset(&opt_lzma2
, 0));
46 lzma_filter filters
[3] = {
47 { .id
= LZMA_FILTER_POWERPC
, .options
= NULL
},
48 { .id
= LZMA_FILTER_LZMA2
, .options
= &opt_lzma2
},
49 { .id
= LZMA_VLI_UNKNOWN
, .options
= NULL
},
52 assert_lzma_ret(lzma_stream_buffer_encode(
53 filters
, LZMA_CHECK_CRC32
, NULL
,
55 compressed
, &compressed_size
, sizeof(compressed
)),
58 // Decompress so that we won't give more output space than
59 // the Stream will need.
60 lzma_stream strm
= LZMA_STREAM_INIT
;
61 assert_lzma_ret(lzma_stream_decoder(&strm
, 10 << 20, 0), LZMA_OK
);
63 strm
.next_in
= compressed
;
67 if (strm
.total_in
< compressed_size
)
70 const lzma_ret ret
= lzma_code(&strm
, LZMA_RUN
);
71 if (ret
== LZMA_STREAM_END
) {
72 assert_uint_eq(strm
.total_in
, compressed_size
);
73 assert_uint_eq(strm
.total_out
, sizeof(in
));
78 assert_lzma_ret(ret
, LZMA_OK
);
80 if (strm
.total_out
< sizeof(in
))
88 test_empty_block(void)
91 assert_skip("Decoder support disabled");
93 if (!lzma_filter_decoder_is_supported(LZMA_FILTER_POWERPC
))
94 assert_skip("PowerPC BCJ decoder is disabled");
96 // An empty file with one Block using PowerPC BCJ and LZMA2.
98 uint8_t *empty_bcj_lzma2
= tuktest_file_from_srcdir(
99 "files/good-1-empty-bcj-lzma2.xz", &in_size
);
101 // Decompress without giving any output space.
102 uint64_t memlimit
= 1 << 20;
106 assert_lzma_ret(lzma_stream_buffer_decode(&memlimit
, 0, NULL
,
107 empty_bcj_lzma2
, &in_pos
, in_size
, out
, &out_pos
, 0),
109 assert_uint_eq(in_pos
, in_size
);
110 assert_uint_eq(out_pos
, 0);
116 main(int argc
, char **argv
)
118 tuktest_start(argc
, argv
);
120 tuktest_run(test_exact_size
);
121 tuktest_run(test_empty_block
);
123 return tuktest_end();