1
0
Fork 0
mirror of https://git.tukaani.org/xz.git synced 2024-04-04 12:36:23 +02:00

Tests: Fix compilation issues.

test_bcj_exact_size, test_check, test_hardware, and test_index will
all now compile and skip properly if encoders or decoders are disabled.

Also fixed a small typo (disabed -> disabled).

Thanks to Sebastian Andrzej Siewior.
This commit is contained in:
Jia Tan 2022-10-05 23:54:12 +08:00 committed by Lasse Collin
parent 7dcabeec63
commit 8496331895
6 changed files with 56 additions and 9 deletions

View file

@ -18,6 +18,15 @@
static void
test_exact_size(void)
{
#if !defined(HAVE_ENCODERS) || !defined(HAVE_DECODERS)
assert_skip("Encoder or decoder support disabled");
#else
if (!lzma_filter_encoder_is_supported(LZMA_FILTER_POWERPC)
|| !lzma_filter_decoder_is_supported(
LZMA_FILTER_POWERPC))
assert_skip("PowerPC BCJ encoder and/or decoder "
"is disabled");
// Something to be compressed
const uint8_t in[16] = "0123456789ABCDEF";
@ -71,12 +80,16 @@ test_exact_size(void)
if (strm.total_out < sizeof(in))
strm.avail_out = 1;
}
#endif
}
static void
test_empty_block(void)
{
#ifndef HAVE_DECODERS
assert_skip("Decoder support disabled");
#else
// An empty file with one Block using PowerPC BCJ and LZMA2.
size_t in_size;
uint8_t *empty_bcj_lzma2 = tuktest_file_from_srcdir(
@ -92,6 +105,7 @@ test_empty_block(void)
LZMA_OK);
assert_uint_eq(in_pos, in_size);
assert_uint_eq(out_pos, 0);
#endif
}
@ -100,12 +114,6 @@ main(int argc, char **argv)
{
tuktest_start(argc, argv);
if (!lzma_filter_encoder_is_supported(LZMA_FILTER_POWERPC)
|| !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);

View file

@ -157,6 +157,9 @@ test_lzma_check_size(void)
static void
test_lzma_get_check_st(void)
{
#ifndef HAVE_DECODERS
assert_skip("Decoder support disabled");
#else
const uint32_t flags = LZMA_TELL_ANY_CHECK |
LZMA_TELL_UNSUPPORTED_CHECK |
LZMA_TELL_NO_CHECK;
@ -230,6 +233,7 @@ test_lzma_get_check_st(void)
#endif
lzma_end(&strm);
#endif
}
@ -237,7 +241,9 @@ static void
test_lzma_get_check_mt(void)
{
#ifndef MYTHREAD_ENABLED
assert_skip("Threading support disabed");
assert_skip("Threading support disabled");
#elif !defined(HAVE_DECODERS)
assert_skip("Decoder support disabled");
#else
const uint32_t flags = LZMA_TELL_ANY_CHECK |
LZMA_TELL_UNSUPPORTED_CHECK |

View file

@ -32,7 +32,7 @@ static void
test_lzma_cputhreads(void)
{
#ifndef MYTHREAD_ENABLED
assert_skip("Threading support disabed");
assert_skip("Threading support disabled");
#else
if (lzma_cputhreads() == 0)
assert_skip("Could not determine cpu core count");

View file

@ -211,6 +211,7 @@ test_read(lzma_index *i)
static void
test_code(lzma_index *i)
{
#if defined(HAVE_ENCODERS) && defined(HAVE_DECODERS)
const size_t alloc_size = 128 * 1024;
uint8_t *buf = malloc(alloc_size);
expect(buf != NULL);
@ -275,6 +276,9 @@ test_code(lzma_index *i)
lzma_index_end(d, NULL);
free(buf);
#else
(void)i;
#endif
}
@ -633,6 +637,7 @@ test_locate(void)
static void
test_corrupt(void)
{
#if defined(HAVE_ENCODERS) && defined(HAVE_DECODERS)
const size_t alloc_size = 128 * 1024;
uint8_t *buf = malloc(alloc_size);
expect(buf != NULL);
@ -668,6 +673,7 @@ test_corrupt(void)
lzma_end(&strm);
free(buf);
#endif
}

View file

@ -26,6 +26,9 @@ static uint8_t out[8192];
static void
test_memlimit_stream_decoder(void)
{
#ifndef HAVE_DECODERS
assert_skip("Decoder support disabled");
#else
lzma_stream strm = LZMA_STREAM_INIT;
assert_lzma_ret(lzma_stream_decoder(&strm, MEMLIMIT_TOO_LOW, 0),
LZMA_OK);
@ -48,6 +51,7 @@ test_memlimit_stream_decoder(void)
assert_lzma_ret(lzma_code(&strm, LZMA_FINISH), LZMA_STREAM_END);
lzma_end(&strm);
#endif
}
@ -55,7 +59,9 @@ static void
test_memlimit_stream_decoder_mt(void)
{
#ifndef MYTHREAD_ENABLED
assert_skip("Threading support disabed");
assert_skip("Threading support disabled");
#elif !defined(HAVE_DECODERS)
assert_skip("Decoder support disabled");
#else
lzma_stream strm = LZMA_STREAM_INIT;
lzma_mt mt = {
@ -90,6 +96,9 @@ test_memlimit_stream_decoder_mt(void)
static void
test_memlimit_alone_decoder(void)
{
#ifndef HAVE_DECODERS
assert_skip("Decoder support disabled");
#else
size_t alone_size;
uint8_t *alone_buf = tuktest_file_from_srcdir(
"files/good-unknown_size-with_eopm.lzma", &alone_size);
@ -112,12 +121,16 @@ test_memlimit_alone_decoder(void)
assert_lzma_ret(lzma_code(&strm, LZMA_FINISH), LZMA_STREAM_END);
lzma_end(&strm);
#endif
}
static void
test_memlimit_auto_decoder(void)
{
#ifndef HAVE_DECODERS
assert_skip("Decoder support disabled");
#else
lzma_stream strm = LZMA_STREAM_INIT;
assert_lzma_ret(lzma_auto_decoder(&strm, MEMLIMIT_TOO_LOW, 0),
LZMA_OK);
@ -137,6 +150,7 @@ test_memlimit_auto_decoder(void)
assert_lzma_ret(lzma_code(&strm, LZMA_FINISH), LZMA_STREAM_END);
lzma_end(&strm);
#endif
}

View file

@ -70,6 +70,7 @@ test_lzma_vli_size(void)
}
#ifdef HAVE_ENCODERS
// Helper function for test_lzma_vli_encode
// Encodes an input VLI and compares against a pre-computed value
static void
@ -108,11 +109,15 @@ encode_multi_call_mode(lzma_vli input, const uint8_t *expected,
assert_uint_eq(vli_pos, expected_len);
assert_array_eq(out, expected, expected_len);
}
#endif
static void
test_lzma_vli_encode(void)
{
#ifndef HAVE_ENCODERS
assert_skip("Encoder support disabled");
#else
size_t vli_pos = 0;
uint8_t out[LZMA_VLI_BYTES_MAX];
uint8_t zeros[LZMA_VLI_BYTES_MAX];
@ -189,9 +194,11 @@ test_lzma_vli_encode(void)
sizeof(eight_bytes));
encode_multi_call_mode(nine_byte_value, nine_bytes,
sizeof(nine_bytes));
#endif
}
#ifdef HAVE_DECODERS
static void
decode_single_call_mode(const uint8_t *input, uint32_t input_len,
lzma_vli expected)
@ -227,10 +234,15 @@ decode_multi_call_mode(const uint8_t *input, uint32_t input_len,
assert_uint_eq(vli_pos, input_len);
assert_uint_eq(out, expected);
}
#endif
static void
test_lzma_vli_decode(void)
{
#ifndef HAVE_DECODERS
assert_skip("Decoder support disabled");
#else
lzma_vli out = 0;
size_t in_pos = 0;
@ -295,6 +307,7 @@ test_lzma_vli_decode(void)
eight_byte_value);
decode_multi_call_mode(nine_bytes, sizeof(nine_bytes),
nine_byte_value);
#endif
}