Skip to content

Commit

Permalink
Tests: test_lzip_decoder: Tweak coding style and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Larhzu committed Apr 19, 2024
1 parent 38be573 commit 86fc4ee
Showing 1 changed file with 28 additions and 30 deletions.
58 changes: 28 additions & 30 deletions tests/test_lzip_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ basic_lzip_decode(const char *src, const uint32_t expected_crc)

strm.next_in = data;
strm.next_out = output_buffer;
strm.avail_out = DECODE_CHUNK_SIZE;
strm.avail_out = sizeof(output_buffer);

// Feed 1 byte at a time to the decoder to look for any bugs
// when switching between decoding sequences
Expand All @@ -59,7 +59,7 @@ basic_lzip_decode(const char *src, const uint32_t expected_crc)
(size_t)(strm.next_out - output_buffer),
checksum);
strm.next_out = output_buffer;
strm.avail_out = DECODE_CHUNK_SIZE;
strm.avail_out = sizeof(output_buffer);
}
}

Expand Down Expand Up @@ -124,9 +124,9 @@ trailing_helper(const char *src, const uint32_t expected_data_checksum,
uint8_t output_buffer[DECODE_CHUNK_SIZE];

strm.next_in = data;
strm.next_out = output_buffer;
strm.avail_in = file_size;
strm.avail_out = DECODE_CHUNK_SIZE;
strm.next_out = output_buffer;
strm.avail_out = sizeof(output_buffer);

lzma_ret ret = LZMA_OK;
while (ret == LZMA_OK) {
Expand All @@ -136,7 +136,7 @@ trailing_helper(const char *src, const uint32_t expected_data_checksum,
(size_t)(strm.next_out - output_buffer),
checksum);
strm.next_out = output_buffer;
strm.avail_out = DECODE_CHUNK_SIZE;
strm.avail_out = sizeof(output_buffer);
}
}

Expand Down Expand Up @@ -179,7 +179,7 @@ decode_expect_error(const char *src, lzma_ret expected_error)
do {
// Discard output since we are only looking for errors
strm.next_out = output_buffer;
strm.avail_out = DECODE_CHUNK_SIZE;
strm.avail_out = sizeof(output_buffer);
if (strm.avail_in == 0)
ret = lzma_code(&strm, LZMA_FINISH);
else
Expand Down Expand Up @@ -227,21 +227,20 @@ test_concatenated(void)
// First test a file with one v0 member and one v1 member
// The first member should contain "Hello\n" and
// the second member should contain "World!\n"

lzma_stream strm = LZMA_STREAM_INIT;
size_t file_size;
uint8_t *v0_v1 = tuktest_file_from_srcdir("files/good-2-v0-v1.lz",
&file_size);
&file_size);

assert_lzma_ret(lzma_lzip_decoder(&strm, MEMLIMIT,
LZMA_CONCATENATED), LZMA_OK);

uint8_t output_buffer[DECODE_CHUNK_SIZE];

strm.avail_in = file_size;
strm.next_in = v0_v1;
strm.avail_out = DECODE_CHUNK_SIZE;
strm.avail_in = file_size;
strm.next_out = output_buffer;
strm.avail_out = sizeof(output_buffer);

assert_lzma_ret(lzma_code(&strm, LZMA_FINISH), LZMA_STREAM_END);

Expand All @@ -252,15 +251,15 @@ test_concatenated(void)

// The second file contains one v1 member and one v2 member
uint8_t *v1_v0 = tuktest_file_from_srcdir("files/good-2-v1-v0.lz",
&file_size);
&file_size);

assert_lzma_ret(lzma_lzip_decoder(&strm, MEMLIMIT,
LZMA_CONCATENATED), LZMA_OK);

strm.avail_in = file_size;
strm.next_in = v1_v0;
strm.avail_out = DECODE_CHUNK_SIZE;
strm.avail_in = file_size;
strm.next_out = output_buffer;
strm.avail_out = sizeof(output_buffer);

assert_lzma_ret(lzma_code(&strm, LZMA_FINISH), LZMA_STREAM_END);

Expand All @@ -270,15 +269,15 @@ test_concatenated(void)

// The third file contains 2 v1 members
uint8_t *v1_v1 = tuktest_file_from_srcdir("files/good-2-v1-v1.lz",
&file_size);
&file_size);

assert_lzma_ret(lzma_lzip_decoder(&strm, MEMLIMIT,
LZMA_CONCATENATED), LZMA_OK);

strm.avail_in = file_size;
strm.next_in = v1_v1;
strm.avail_out = DECODE_CHUNK_SIZE;
strm.avail_in = file_size;
strm.next_out = output_buffer;
strm.avail_out = sizeof(output_buffer);

assert_lzma_ret(lzma_code(&strm, LZMA_FINISH), LZMA_STREAM_END);

Expand All @@ -304,21 +303,21 @@ test_crc(void)

uint8_t output_buffer[DECODE_CHUNK_SIZE];

strm.avail_in = file_size;
strm.next_in = data;
strm.avail_out = DECODE_CHUNK_SIZE;
strm.avail_in = file_size;
strm.next_out = output_buffer;
strm.avail_out = sizeof(output_buffer);

assert_lzma_ret(lzma_code(&strm, LZMA_FINISH), LZMA_DATA_ERROR);

// Test ignoring the checksum value - should decode successfully
assert_lzma_ret(lzma_lzip_decoder(&strm, MEMLIMIT,
LZMA_CONCATENATED | LZMA_IGNORE_CHECK), LZMA_OK);

strm.avail_in = file_size;
strm.next_in = data;
strm.avail_out = DECODE_CHUNK_SIZE;
strm.avail_in = file_size;
strm.next_out = output_buffer;
strm.avail_out = sizeof(output_buffer);

assert_lzma_ret(lzma_code(&strm, LZMA_FINISH), LZMA_STREAM_END);
assert_uint_eq(strm.total_in, file_size);
Expand All @@ -327,10 +326,10 @@ test_crc(void)
assert_lzma_ret(lzma_lzip_decoder(&strm, MEMLIMIT,
LZMA_CONCATENATED | LZMA_TELL_ANY_CHECK), LZMA_OK);

strm.avail_in = file_size;
strm.next_in = data;
strm.avail_out = DECODE_CHUNK_SIZE;
strm.avail_in = file_size;
strm.next_out = output_buffer;
strm.avail_out = sizeof(output_buffer);

assert_lzma_ret(lzma_code(&strm, LZMA_FINISH), LZMA_GET_CHECK);
assert_uint_eq(lzma_get_check(&strm), LZMA_CHECK_CRC32);
Expand All @@ -356,7 +355,7 @@ test_invalid_magic_bytes(void)
strm.next_in = lzip_id_string;
strm.avail_in = sizeof(lzip_id_string);
strm.next_out = output_buffer;
strm.avail_out = DECODE_CHUNK_SIZE;
strm.avail_out = sizeof(output_buffer);

assert_lzma_ret(lzma_code(&strm, LZMA_RUN),
LZMA_FORMAT_ERROR);
Expand All @@ -382,10 +381,10 @@ test_invalid_version(void)
static void
test_invalid_dictionary_size(void)
{
// First file has too small dictionary size field
// The first file has a too small dictionary size field.
decode_expect_error("files/bad-1-v1-dict-1.lz", LZMA_DATA_ERROR);

// Second file has too large dictionary size field
// The second file has a too large dictionary size field.
decode_expect_error("files/bad-1-v1-dict-2.lz", LZMA_DATA_ERROR);
}

Expand Down Expand Up @@ -415,7 +414,7 @@ static void
test_invalid_memlimit(void)
{
// A very low memlimit should prevent decoding.
// Should be able to update the memlimit after failing
// It should be possible to update the memlimit after the error.
size_t file_size;
uint8_t *data = tuktest_file_from_srcdir("files/good-1-v1.lz",
&file_size);
Expand All @@ -429,12 +428,12 @@ test_invalid_memlimit(void)
strm.next_in = data;
strm.avail_in = file_size;
strm.next_out = output_buffer;
strm.avail_out = DECODE_CHUNK_SIZE;
strm.avail_out = sizeof(output_buffer);

assert_lzma_ret(lzma_code(&strm, LZMA_FINISH), LZMA_MEMLIMIT_ERROR);

// Up the memlimit so decoding can continue.
// First only increase by a small amount and expect an error
// Up the memlimit so that decoding can continue.
// First only increase by a small amount and expect an error.
assert_lzma_ret(lzma_memlimit_set(&strm, 100), LZMA_MEMLIMIT_ERROR);
assert_lzma_ret(lzma_memlimit_set(&strm, MEMLIMIT), LZMA_OK);

Expand Down Expand Up @@ -473,5 +472,4 @@ main(int argc, char **argv)
tuktest_run(test_invalid_memlimit);
return tuktest_end();
#endif

}

0 comments on commit 86fc4ee

Please sign in to comment.