mirror of https://git.tukaani.org/xz.git
Tests: test_index: Check cases that aren't a multiple of 4 bytes
(cherry picked from commit ad2654010d
)
This commit is contained in:
parent
b0d3b86ecf
commit
e083e95dbf
|
@ -465,15 +465,18 @@ test_lzma_index_stream_size(void)
|
||||||
|
|
||||||
// Next, append a few Blocks and retest
|
// Next, append a few Blocks and retest
|
||||||
assert_lzma_ret(lzma_index_append(idx, NULL, 1000, 1), LZMA_OK);
|
assert_lzma_ret(lzma_index_append(idx, NULL, 1000, 1), LZMA_OK);
|
||||||
assert_lzma_ret(lzma_index_append(idx, NULL, 1000, 1), LZMA_OK);
|
assert_lzma_ret(lzma_index_append(idx, NULL, 999, 1), LZMA_OK);
|
||||||
assert_lzma_ret(lzma_index_append(idx, NULL, 1000, 1), LZMA_OK);
|
assert_lzma_ret(lzma_index_append(idx, NULL, 997, 1), LZMA_OK);
|
||||||
|
|
||||||
// Stream size should be:
|
// Stream size should be:
|
||||||
// Size of Stream Header - 12 bytes
|
// Size of Stream Header - 12 bytes
|
||||||
// Size of all Blocks - 3000 bytes
|
// Size of all Blocks - 3000 bytes [*]
|
||||||
// Size of Index - 16 bytes
|
// Size of Index - 16 bytes
|
||||||
// Size of Stream Footer - 12 bytes
|
// Size of Stream Footer - 12 bytes
|
||||||
// Total: 3040 bytes
|
// Total: 3040 bytes
|
||||||
|
//
|
||||||
|
// [*] Block size is a multiple of 4 bytes so 999 and 997 get
|
||||||
|
// rounded up to 1000 bytes.
|
||||||
assert_uint_eq(lzma_index_stream_size(idx), 3040);
|
assert_uint_eq(lzma_index_stream_size(idx), 3040);
|
||||||
|
|
||||||
lzma_index *second = lzma_index_init(NULL);
|
lzma_index *second = lzma_index_init(NULL);
|
||||||
|
@ -518,10 +521,10 @@ test_lzma_index_total_size(void)
|
||||||
assert_lzma_ret(lzma_index_append(idx, NULL, 1000, 1), LZMA_OK);
|
assert_lzma_ret(lzma_index_append(idx, NULL, 1000, 1), LZMA_OK);
|
||||||
assert_uint_eq(lzma_index_total_size(idx), 1000);
|
assert_uint_eq(lzma_index_total_size(idx), 1000);
|
||||||
|
|
||||||
assert_lzma_ret(lzma_index_append(idx, NULL, 1000, 1), LZMA_OK);
|
assert_lzma_ret(lzma_index_append(idx, NULL, 999, 1), LZMA_OK);
|
||||||
assert_uint_eq(lzma_index_total_size(idx), 2000);
|
assert_uint_eq(lzma_index_total_size(idx), 2000);
|
||||||
|
|
||||||
assert_lzma_ret(lzma_index_append(idx, NULL, 1000, 1), LZMA_OK);
|
assert_lzma_ret(lzma_index_append(idx, NULL, 997, 1), LZMA_OK);
|
||||||
assert_uint_eq(lzma_index_total_size(idx), 3000);
|
assert_uint_eq(lzma_index_total_size(idx), 3000);
|
||||||
|
|
||||||
// Create second lzma_index and append Blocks to it.
|
// Create second lzma_index and append Blocks to it.
|
||||||
|
@ -543,6 +546,16 @@ test_lzma_index_total_size(void)
|
||||||
// from both Streams
|
// from both Streams
|
||||||
assert_uint_eq(lzma_index_total_size(idx), 3200);
|
assert_uint_eq(lzma_index_total_size(idx), 3200);
|
||||||
|
|
||||||
|
// Test sizes that aren't multiples of four bytes
|
||||||
|
assert_lzma_ret(lzma_index_append(idx, NULL, 11, 1), LZMA_OK);
|
||||||
|
assert_uint_eq(lzma_index_total_size(idx), 3212);
|
||||||
|
|
||||||
|
assert_lzma_ret(lzma_index_append(idx, NULL, 11, 1), LZMA_OK);
|
||||||
|
assert_uint_eq(lzma_index_total_size(idx), 3224);
|
||||||
|
|
||||||
|
assert_lzma_ret(lzma_index_append(idx, NULL, 9, 1), LZMA_OK);
|
||||||
|
assert_uint_eq(lzma_index_total_size(idx), 3236);
|
||||||
|
|
||||||
lzma_index_end(idx, NULL);
|
lzma_index_end(idx, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -558,8 +571,8 @@ test_lzma_index_file_size(void)
|
||||||
assert_uint_eq(lzma_index_file_size(idx), 32);
|
assert_uint_eq(lzma_index_file_size(idx), 32);
|
||||||
|
|
||||||
assert_lzma_ret(lzma_index_append(idx, NULL, 1000, 1), LZMA_OK);
|
assert_lzma_ret(lzma_index_append(idx, NULL, 1000, 1), LZMA_OK);
|
||||||
assert_lzma_ret(lzma_index_append(idx, NULL, 1000, 1), LZMA_OK);
|
assert_lzma_ret(lzma_index_append(idx, NULL, 999, 1), LZMA_OK);
|
||||||
assert_lzma_ret(lzma_index_append(idx, NULL, 1000, 1), LZMA_OK);
|
assert_lzma_ret(lzma_index_append(idx, NULL, 997, 1), LZMA_OK);
|
||||||
|
|
||||||
assert_uint_eq(lzma_index_file_size(idx), 3040);
|
assert_uint_eq(lzma_index_file_size(idx), 3040);
|
||||||
|
|
||||||
|
@ -1045,13 +1058,14 @@ test_lzma_index_iter_locate(void)
|
||||||
lzma_index_iter_init(&iter, idx);
|
lzma_index_iter_init(&iter, idx);
|
||||||
|
|
||||||
for (uint32_t n = 4; n <= 4 * 5555; n += 4)
|
for (uint32_t n = 4; n <= 4 * 5555; n += 4)
|
||||||
assert_lzma_ret(lzma_index_append(idx, NULL, n + 8, n),
|
assert_lzma_ret(lzma_index_append(idx, NULL, n + 7, n),
|
||||||
LZMA_OK);
|
LZMA_OK);
|
||||||
|
|
||||||
assert_uint_eq(lzma_index_block_count(idx), 5555);
|
assert_uint_eq(lzma_index_block_count(idx), 5555);
|
||||||
|
|
||||||
// First Record
|
// First Record
|
||||||
assert_false(lzma_index_iter_locate(&iter, 0));
|
assert_false(lzma_index_iter_locate(&iter, 0));
|
||||||
|
assert_uint_eq(iter.block.unpadded_size, 4 + 7);
|
||||||
assert_uint_eq(iter.block.total_size, 4 + 8);
|
assert_uint_eq(iter.block.total_size, 4 + 8);
|
||||||
assert_uint_eq(iter.block.uncompressed_size, 4);
|
assert_uint_eq(iter.block.uncompressed_size, 4);
|
||||||
assert_uint_eq(iter.block.compressed_file_offset,
|
assert_uint_eq(iter.block.compressed_file_offset,
|
||||||
|
@ -1059,6 +1073,7 @@ test_lzma_index_iter_locate(void)
|
||||||
assert_uint_eq(iter.block.uncompressed_file_offset, 0);
|
assert_uint_eq(iter.block.uncompressed_file_offset, 0);
|
||||||
|
|
||||||
assert_false(lzma_index_iter_locate(&iter, 3));
|
assert_false(lzma_index_iter_locate(&iter, 3));
|
||||||
|
assert_uint_eq(iter.block.unpadded_size, 4 + 7);
|
||||||
assert_uint_eq(iter.block.total_size, 4 + 8);
|
assert_uint_eq(iter.block.total_size, 4 + 8);
|
||||||
assert_uint_eq(iter.block.uncompressed_size, 4);
|
assert_uint_eq(iter.block.uncompressed_size, 4);
|
||||||
assert_uint_eq(iter.block.compressed_file_offset,
|
assert_uint_eq(iter.block.compressed_file_offset,
|
||||||
|
@ -1067,6 +1082,7 @@ test_lzma_index_iter_locate(void)
|
||||||
|
|
||||||
// Second Record
|
// Second Record
|
||||||
assert_false(lzma_index_iter_locate(&iter, 4));
|
assert_false(lzma_index_iter_locate(&iter, 4));
|
||||||
|
assert_uint_eq(iter.block.unpadded_size, 2 * 4 + 7);
|
||||||
assert_uint_eq(iter.block.total_size, 2 * 4 + 8);
|
assert_uint_eq(iter.block.total_size, 2 * 4 + 8);
|
||||||
assert_uint_eq(iter.block.uncompressed_size, 2 * 4);
|
assert_uint_eq(iter.block.uncompressed_size, 2 * 4);
|
||||||
assert_uint_eq(iter.block.compressed_file_offset,
|
assert_uint_eq(iter.block.compressed_file_offset,
|
||||||
|
@ -1076,6 +1092,7 @@ test_lzma_index_iter_locate(void)
|
||||||
// Last Record
|
// Last Record
|
||||||
assert_false(lzma_index_iter_locate(
|
assert_false(lzma_index_iter_locate(
|
||||||
&iter, lzma_index_uncompressed_size(idx) - 1));
|
&iter, lzma_index_uncompressed_size(idx) - 1));
|
||||||
|
assert_uint_eq(iter.block.unpadded_size, 4 * 5555 + 7);
|
||||||
assert_uint_eq(iter.block.total_size, 4 * 5555 + 8);
|
assert_uint_eq(iter.block.total_size, 4 * 5555 + 8);
|
||||||
assert_uint_eq(iter.block.uncompressed_size, 4 * 5555);
|
assert_uint_eq(iter.block.uncompressed_size, 4 * 5555);
|
||||||
assert_uint_eq(iter.block.compressed_file_offset,
|
assert_uint_eq(iter.block.compressed_file_offset,
|
||||||
|
|
Loading…
Reference in New Issue