1 // SPDX-License-Identifier: 0BSD
3 ///////////////////////////////////////////////////////////////////////////////
6 /// \brief Tests functions handling the lzma_index structure
8 /// \todo Implement tests for lzma_file_info_decoder
13 ///////////////////////////////////////////////////////////////////////////////
17 // liblzma internal header file needed for:
21 #include "common/index.h"
24 #define MEMLIMIT (UINT64_C(1) << 20)
27 static uint8_t *decode_buffer
;
28 static size_t decode_buffer_size
= 0;
31 static lzma_index
*decode_test_index
;
35 test_lzma_index_memusage(void)
37 // The return value from lzma_index_memusage is an approximation
38 // of the amount of memory needed for lzma_index for a given
39 // amount of Streams and Blocks. It will be an upperbound,
40 // so this test will mostly sanity check and error check the
43 // The maximum number of Streams should be UINT32_MAX in the
44 // current implementation even though the parameter is lzma_vli.
45 assert_uint_eq(lzma_index_memusage((lzma_vli
)UINT32_MAX
+ 1, 1),
48 // While the number of blocks is lzma_vli, the real maximum value is
49 // much smaller than LZMA_VLI_MAX. Just check that it fails with a
50 // huge but valid VLI and that it succeeds with a smaller one.
51 assert_uint_eq(lzma_index_memusage(1, LZMA_VLI_MAX
/ 5), UINT64_MAX
);
52 assert_uint(lzma_index_memusage(1, LZMA_VLI_MAX
/ 11), <, UINT64_MAX
);
54 // Number of Streams must be non-zero
55 assert_uint_eq(lzma_index_memusage(0, 1), UINT64_MAX
);
57 // Number of Blocks CAN be zero
58 assert_uint(lzma_index_memusage(1, 0), !=, UINT64_MAX
);
60 // Arbitrary values for Stream and Block should work without error
61 // and should always increase
62 uint64_t previous
= 1;
66 // Test 100 different increasing values for Streams and Block
67 for (int i
= 0; i
< 100; i
++) {
68 uint64_t current
= lzma_index_memusage(streams
, blocks
);
69 assert_uint(current
, >, previous
);
75 // Force integer overflow in calculation (should result in an error)
76 assert_uint_eq(lzma_index_memusage(UINT32_MAX
, LZMA_VLI_MAX
),
82 test_lzma_index_memused(void)
84 // Very similar to test_lzma_index_memusage above since
85 // lzma_index_memused is essentially a wrapper for
86 // lzma_index_memusage
87 lzma_index
*idx
= lzma_index_init(NULL
);
88 assert_true(idx
!= NULL
);
90 // Test with empty Index
91 assert_uint(lzma_index_memused(idx
), <, UINT64_MAX
);
93 // Append small Blocks and then test again (should pass).
94 for (lzma_vli i
= 0; i
< 10; i
++)
95 assert_lzma_ret(lzma_index_append(idx
, NULL
,
96 UNPADDED_SIZE_MIN
, 1), LZMA_OK
);
98 assert_uint(lzma_index_memused(idx
), <, UINT64_MAX
);
100 lzma_index_end(idx
, NULL
);
105 test_lzma_index_append(void)
107 // Basic input-output test done here.
108 // Less trivial tests for this function are done throughout
111 // First test with NULL lzma_index
112 assert_lzma_ret(lzma_index_append(NULL
, NULL
, UNPADDED_SIZE_MIN
,
113 1), LZMA_PROG_ERROR
);
115 lzma_index
*idx
= lzma_index_init(NULL
);
116 assert_true(idx
!= NULL
);
118 // Test with invalid Unpadded Size
119 assert_lzma_ret(lzma_index_append(idx
, NULL
,
120 UNPADDED_SIZE_MIN
- 1, 1), LZMA_PROG_ERROR
);
121 assert_lzma_ret(lzma_index_append(idx
, NULL
,
122 UNPADDED_SIZE_MAX
+ 1, 1), LZMA_PROG_ERROR
);
124 // Test with invalid Uncompressed Size
125 assert_lzma_ret(lzma_index_append(idx
, NULL
,
126 UNPADDED_SIZE_MAX
, LZMA_VLI_MAX
+ 1),
129 // Test expected successful Block appends
130 assert_lzma_ret(lzma_index_append(idx
, NULL
, UNPADDED_SIZE_MIN
,
132 assert_lzma_ret(lzma_index_append(idx
, NULL
,
133 UNPADDED_SIZE_MIN
* 2,
135 assert_lzma_ret(lzma_index_append(idx
, NULL
,
136 UNPADDED_SIZE_MIN
* 3,
139 lzma_index_end(idx
, NULL
);
141 // Test compressed .xz file size growing too large. This also tests
142 // a failing assert fixed in ae5c07b22a6b3766b84f409f1b6b5c100469068a.
143 // Should result in LZMA_DATA_ERROR.
144 idx
= lzma_index_init(NULL
);
146 // The calculation for maximum unpadded size is to make room for the
147 // second stream when lzma_index_cat() is called. The
148 // 4 * LZMA_STREAM_HEADER_SIZE is for the header and footer of
149 // both streams. The extra 24 bytes are for the size of the indexes
150 // for both streams. This allows us to maximize the unpadded sum
151 // during the lzma_index_append() call after the indexes have been
153 assert_lzma_ret(lzma_index_append(idx
, NULL
, UNPADDED_SIZE_MAX
154 - ((4 * LZMA_STREAM_HEADER_SIZE
) + 24), 1), LZMA_OK
);
156 lzma_index
*second
= lzma_index_init(NULL
);
157 assert_true(second
!= NULL
);
159 assert_lzma_ret(lzma_index_cat(second
, idx
, NULL
), LZMA_OK
);
161 assert_lzma_ret(lzma_index_append(second
, NULL
, UNPADDED_SIZE_MAX
, 1),
164 lzma_index_end(second
, NULL
);
166 // Test uncompressed size growing too large.
167 // Should result in LZMA_DATA_ERROR.
168 idx
= lzma_index_init(NULL
);
170 assert_lzma_ret(lzma_index_append(idx
, NULL
,
171 UNPADDED_SIZE_MIN
, LZMA_VLI_MAX
), LZMA_OK
);
172 assert_lzma_ret(lzma_index_append(idx
, NULL
,
173 UNPADDED_SIZE_MIN
, 1), LZMA_DATA_ERROR
);
175 lzma_index_end(idx
, NULL
);
177 // Currently not testing for error case when the size of the Index
178 // grows too large to be stored. This was not practical to test for
179 // since too many Blocks needed to be created to cause this.
184 test_lzma_index_stream_flags(void)
186 // Only trivial tests done here testing for basic functionality.
187 // More in-depth testing for this function will be done in
188 // test_lzma_index_checks.
190 // Testing for NULL inputs
191 assert_lzma_ret(lzma_index_stream_flags(NULL
, NULL
),
194 lzma_index
*idx
= lzma_index_init(NULL
);
195 assert_true(idx
!= NULL
);
197 assert_lzma_ret(lzma_index_stream_flags(idx
, NULL
),
200 lzma_stream_flags stream_flags
= {
202 .backward_size
= LZMA_BACKWARD_SIZE_MIN
,
203 .check
= LZMA_CHECK_CRC32
206 assert_lzma_ret(lzma_index_stream_flags(idx
, &stream_flags
),
209 lzma_index_end(idx
, NULL
);
214 test_lzma_index_checks(void)
216 // Tests should still pass, even if some of the check types
218 lzma_index
*idx
= lzma_index_init(NULL
);
219 assert_true(idx
!= NULL
);
221 lzma_stream_flags stream_flags
= {
223 .backward_size
= LZMA_BACKWARD_SIZE_MIN
,
224 .check
= LZMA_CHECK_NONE
227 // First set the check type to None
228 assert_lzma_ret(lzma_index_stream_flags(idx
, &stream_flags
),
230 assert_uint_eq(lzma_index_checks(idx
),
231 LZMA_INDEX_CHECK_MASK_NONE
);
233 // Set the check type to CRC32 and repeat
234 stream_flags
.check
= LZMA_CHECK_CRC32
;
235 assert_lzma_ret(lzma_index_stream_flags(idx
, &stream_flags
),
237 assert_uint_eq(lzma_index_checks(idx
),
238 LZMA_INDEX_CHECK_MASK_CRC32
);
240 // Set the check type to CRC64 and repeat
241 stream_flags
.check
= LZMA_CHECK_CRC64
;
242 assert_lzma_ret(lzma_index_stream_flags(idx
, &stream_flags
),
244 assert_uint_eq(lzma_index_checks(idx
),
245 LZMA_INDEX_CHECK_MASK_CRC64
);
247 // Set the check type to SHA256 and repeat
248 stream_flags
.check
= LZMA_CHECK_SHA256
;
249 assert_lzma_ret(lzma_index_stream_flags(idx
, &stream_flags
),
251 assert_uint_eq(lzma_index_checks(idx
),
252 LZMA_INDEX_CHECK_MASK_SHA256
);
254 // Create second lzma_index and cat to first
255 lzma_index
*second
= lzma_index_init(NULL
);
256 assert_true(second
!= NULL
);
258 // Set the check type to CRC32 for the second lzma_index
259 stream_flags
.check
= LZMA_CHECK_CRC32
;
260 assert_lzma_ret(lzma_index_stream_flags(second
, &stream_flags
),
263 assert_uint_eq(lzma_index_checks(second
),
264 LZMA_INDEX_CHECK_MASK_CRC32
);
266 assert_lzma_ret(lzma_index_cat(idx
, second
, NULL
), LZMA_OK
);
268 // Index should now have both CRC32 and SHA256
269 assert_uint_eq(lzma_index_checks(idx
),
270 LZMA_INDEX_CHECK_MASK_CRC32
|
271 LZMA_INDEX_CHECK_MASK_SHA256
);
273 // Change the check type of the second Stream to SHA256
274 stream_flags
.check
= LZMA_CHECK_SHA256
;
275 assert_lzma_ret(lzma_index_stream_flags(idx
, &stream_flags
),
278 // Index should now have only SHA256
279 assert_uint_eq(lzma_index_checks(idx
),
280 LZMA_INDEX_CHECK_MASK_SHA256
);
282 // Test with a third Stream
283 lzma_index
*third
= lzma_index_init(NULL
);
284 assert_true(third
!= NULL
);
286 stream_flags
.check
= LZMA_CHECK_CRC64
;
287 assert_lzma_ret(lzma_index_stream_flags(third
, &stream_flags
),
290 assert_uint_eq(lzma_index_checks(third
),
291 LZMA_INDEX_CHECK_MASK_CRC64
);
293 assert_lzma_ret(lzma_index_cat(idx
, third
, NULL
), LZMA_OK
);
295 // Index should now have CRC64 and SHA256
296 assert_uint_eq(lzma_index_checks(idx
),
297 LZMA_INDEX_CHECK_MASK_CRC64
|
298 LZMA_INDEX_CHECK_MASK_SHA256
);
300 lzma_index_end(idx
, NULL
);
305 test_lzma_index_stream_padding(void)
307 // Test NULL lzma_index
308 assert_lzma_ret(lzma_index_stream_padding(NULL
, 0),
311 lzma_index
*idx
= lzma_index_init(NULL
);
312 assert_true(idx
!= NULL
);
314 // Test Stream Padding not a multiple of 4
315 assert_lzma_ret(lzma_index_stream_padding(idx
, 3),
318 // Test Stream Padding too large
319 assert_lzma_ret(lzma_index_stream_padding(idx
, LZMA_VLI_MAX
- 3),
322 // Test Stream Padding valid
323 assert_lzma_ret(lzma_index_stream_padding(idx
, 0x1000),
325 assert_lzma_ret(lzma_index_stream_padding(idx
, 4),
327 assert_lzma_ret(lzma_index_stream_padding(idx
, 0),
330 // Test Stream Padding causing the file size to grow too large
331 assert_lzma_ret(lzma_index_append(idx
, NULL
,
332 LZMA_VLI_MAX
- 0x1000, 1), LZMA_OK
);
333 assert_lzma_ret(lzma_index_stream_padding(idx
, 0x1000),
336 lzma_index_end(idx
, NULL
);
341 test_lzma_index_stream_count(void)
343 lzma_index
*idx
= lzma_index_init(NULL
);
344 assert_true(idx
!= NULL
);
346 assert_uint_eq(lzma_index_stream_count(idx
), 1);
348 // Appending Blocks should not change the Stream count value
349 assert_lzma_ret(lzma_index_append(idx
, NULL
, UNPADDED_SIZE_MIN
,
352 assert_uint_eq(lzma_index_stream_count(idx
), 1);
354 // Test with multiple Streams
355 for (uint32_t i
= 0; i
< 100; i
++) {
356 lzma_index
*idx_cat
= lzma_index_init(NULL
);
357 assert_true(idx
!= NULL
);
358 assert_lzma_ret(lzma_index_cat(idx
, idx_cat
, NULL
), LZMA_OK
);
359 assert_uint_eq(lzma_index_stream_count(idx
), i
+ 2);
362 lzma_index_end(idx
, NULL
);
367 test_lzma_index_block_count(void)
369 lzma_index
*idx
= lzma_index_init(NULL
);
370 assert_true(idx
!= NULL
);
372 assert_uint_eq(lzma_index_block_count(idx
), 0);
374 const uint32_t iterations
= 0x1000;
375 for (uint32_t i
= 0; i
< iterations
; i
++) {
376 assert_lzma_ret(lzma_index_append(idx
, NULL
,
377 UNPADDED_SIZE_MIN
, 1), LZMA_OK
);
378 assert_uint_eq(lzma_index_block_count(idx
), i
+ 1);
381 // Create new lzma_index with a few Blocks
382 lzma_index
*second
= lzma_index_init(NULL
);
383 assert_true(second
!= NULL
);
385 assert_lzma_ret(lzma_index_append(second
, NULL
,
386 UNPADDED_SIZE_MIN
, 1), LZMA_OK
);
387 assert_lzma_ret(lzma_index_append(second
, NULL
,
388 UNPADDED_SIZE_MIN
, 1), LZMA_OK
);
389 assert_lzma_ret(lzma_index_append(second
, NULL
,
390 UNPADDED_SIZE_MIN
, 1), LZMA_OK
);
392 assert_uint_eq(lzma_index_block_count(second
), 3);
394 // Concatenate the lzma_indexes together and the result should have
395 // the sum of the two individual counts.
396 assert_lzma_ret(lzma_index_cat(idx
, second
, NULL
), LZMA_OK
);
397 assert_uint_eq(lzma_index_block_count(idx
), iterations
+ 3);
399 assert_lzma_ret(lzma_index_append(idx
, NULL
,
400 UNPADDED_SIZE_MIN
, 1), LZMA_OK
);
402 assert_uint_eq(lzma_index_block_count(idx
), iterations
+ 4);
404 lzma_index_end(idx
, NULL
);
409 test_lzma_index_size(void)
411 lzma_index
*idx
= lzma_index_init(NULL
);
412 assert_true(idx
!= NULL
);
414 // Base size should be:
415 // 1 byte Index Indicator
416 // 1 byte Number of Records
418 // 2 bytes Index Padding
421 assert_uint_eq(lzma_index_size(idx
), 8);
423 assert_lzma_ret(lzma_index_append(idx
, NULL
,
424 UNPADDED_SIZE_MIN
, 1), LZMA_OK
);
426 // New size should be:
427 // 1 byte Index Indicator
428 // 1 byte Number of Records
430 // 0 bytes Index Padding
433 assert_uint_eq(lzma_index_size(idx
), 8);
435 assert_lzma_ret(lzma_index_append(idx
, NULL
,
436 LZMA_VLI_MAX
/ 4, LZMA_VLI_MAX
/ 4), LZMA_OK
);
438 // New size should be:
439 // 1 byte Index Indicator
440 // 1 byte Number of Records
442 // 2 bytes Index Padding
445 assert_uint_eq(lzma_index_size(idx
), 28);
447 lzma_index_end(idx
, NULL
);
452 test_lzma_index_stream_size(void)
454 lzma_index
*idx
= lzma_index_init(NULL
);
455 assert_true(idx
!= NULL
);
457 // Stream size calculated by:
458 // Size of Stream Header (12 bytes)
459 // Size of all Blocks
461 // Size of the Stream Footer (12 bytes)
463 // First test with empty Index
464 // Stream size should be:
465 // Size of Stream Header - 12 bytes
466 // Size of all Blocks - 0 bytes
467 // Size of Index - 8 bytes
468 // Size of Stream Footer - 12 bytes
470 assert_uint_eq(lzma_index_stream_size(idx
), 32);
472 // Next, append a few Blocks and retest
473 assert_lzma_ret(lzma_index_append(idx
, NULL
, 1000, 1), LZMA_OK
);
474 assert_lzma_ret(lzma_index_append(idx
, NULL
, 999, 1), LZMA_OK
);
475 assert_lzma_ret(lzma_index_append(idx
, NULL
, 997, 1), LZMA_OK
);
477 // Stream size should be:
478 // Size of Stream Header - 12 bytes
479 // Size of all Blocks - 3000 bytes [*]
480 // Size of Index - 16 bytes
481 // Size of Stream Footer - 12 bytes
484 // [*] Block size is a multiple of 4 bytes so 999 and 997 get
485 // rounded up to 1000 bytes.
486 assert_uint_eq(lzma_index_stream_size(idx
), 3040);
488 lzma_index
*second
= lzma_index_init(NULL
);
489 assert_true(second
!= NULL
);
491 assert_uint_eq(lzma_index_stream_size(second
), 32);
492 assert_lzma_ret(lzma_index_append(second
, NULL
, 1000, 1), LZMA_OK
);
494 // Stream size should be:
495 // Size of Stream Header - 12 bytes
496 // Size of all Blocks - 1000 bytes
497 // Size of Index - 12 bytes
498 // Size of Stream Footer - 12 bytes
500 assert_uint_eq(lzma_index_stream_size(second
), 1036);
502 assert_lzma_ret(lzma_index_cat(idx
, second
, NULL
), LZMA_OK
);
504 // Stream size should be:
505 // Size of Stream Header - 12 bytes
506 // Size of all Blocks - 4000 bytes
507 // Size of Index - 20 bytes
508 // Size of Stream Footer - 12 bytes
510 assert_uint_eq(lzma_index_stream_size(idx
), 4044);
512 lzma_index_end(idx
, NULL
);
517 test_lzma_index_total_size(void)
519 lzma_index
*idx
= lzma_index_init(NULL
);
520 assert_true(idx
!= NULL
);
522 // First test empty lzma_index.
523 // Result should be 0 since no Blocks have been added.
524 assert_uint_eq(lzma_index_total_size(idx
), 0);
526 // Add a few Blocks and retest after each append
527 assert_lzma_ret(lzma_index_append(idx
, NULL
, 1000, 1), LZMA_OK
);
528 assert_uint_eq(lzma_index_total_size(idx
), 1000);
530 assert_lzma_ret(lzma_index_append(idx
, NULL
, 999, 1), LZMA_OK
);
531 assert_uint_eq(lzma_index_total_size(idx
), 2000);
533 assert_lzma_ret(lzma_index_append(idx
, NULL
, 997, 1), LZMA_OK
);
534 assert_uint_eq(lzma_index_total_size(idx
), 3000);
536 // Create second lzma_index and append Blocks to it.
537 lzma_index
*second
= lzma_index_init(NULL
);
538 assert_true(second
!= NULL
);
540 assert_uint_eq(lzma_index_total_size(second
), 0);
542 assert_lzma_ret(lzma_index_append(second
, NULL
, 100, 1), LZMA_OK
);
543 assert_uint_eq(lzma_index_total_size(second
), 100);
545 assert_lzma_ret(lzma_index_append(second
, NULL
, 100, 1), LZMA_OK
);
546 assert_uint_eq(lzma_index_total_size(second
), 200);
548 // Concatenate the Streams together
549 assert_lzma_ret(lzma_index_cat(idx
, second
, NULL
), LZMA_OK
);
551 // The resulting total size should be the size of all Blocks
553 assert_uint_eq(lzma_index_total_size(idx
), 3200);
555 // Test sizes that aren't multiples of four bytes
556 assert_lzma_ret(lzma_index_append(idx
, NULL
, 11, 1), LZMA_OK
);
557 assert_uint_eq(lzma_index_total_size(idx
), 3212);
559 assert_lzma_ret(lzma_index_append(idx
, NULL
, 11, 1), LZMA_OK
);
560 assert_uint_eq(lzma_index_total_size(idx
), 3224);
562 assert_lzma_ret(lzma_index_append(idx
, NULL
, 9, 1), LZMA_OK
);
563 assert_uint_eq(lzma_index_total_size(idx
), 3236);
565 lzma_index_end(idx
, NULL
);
570 test_lzma_index_file_size(void)
572 lzma_index
*idx
= lzma_index_init(NULL
);
573 assert_true(idx
!= NULL
);
575 // Should be the same as test_lzma_index_stream_size with
576 // only one Stream and no Stream Padding.
577 assert_uint_eq(lzma_index_file_size(idx
), 32);
579 assert_lzma_ret(lzma_index_append(idx
, NULL
, 1000, 1), LZMA_OK
);
580 assert_lzma_ret(lzma_index_append(idx
, NULL
, 999, 1), LZMA_OK
);
581 assert_lzma_ret(lzma_index_append(idx
, NULL
, 997, 1), LZMA_OK
);
583 assert_uint_eq(lzma_index_file_size(idx
), 3040);
585 // Next add Stream Padding
586 assert_lzma_ret(lzma_index_stream_padding(idx
, 1000),
589 assert_uint_eq(lzma_index_file_size(idx
), 4040);
591 // Create second lzma_index.
592 // Very similar to test_lzma_index_stream_size, but
593 // the values should include the headers of the second Stream.
594 lzma_index
*second
= lzma_index_init(NULL
);
595 assert_true(second
!= NULL
);
597 assert_lzma_ret(lzma_index_append(second
, NULL
, 1000, 1), LZMA_OK
);
598 assert_uint_eq(lzma_index_stream_size(second
), 1036);
600 assert_lzma_ret(lzma_index_cat(idx
, second
, NULL
), LZMA_OK
);
602 // .xz file size should be:
603 // Size of 2 Stream Headers - 12 * 2 bytes
604 // Size of all Blocks - 3000 + 1000 bytes
605 // Size of 2 Indexes - 16 + 12 bytes
606 // Size of Stream Padding - 1000 bytes
607 // Size of 2 Stream Footers - 12 * 2 bytes
609 assert_uint_eq(lzma_index_file_size(idx
), 5076);
611 lzma_index_end(idx
, NULL
);
616 test_lzma_index_uncompressed_size(void)
618 lzma_index
*idx
= lzma_index_init(NULL
);
619 assert_true(idx
!= NULL
);
621 // Empty lzma_index should have 0 uncompressed .xz file size.
622 assert_uint_eq(lzma_index_uncompressed_size(idx
), 0);
624 // Append a few small Blocks
625 assert_lzma_ret(lzma_index_append(idx
, NULL
, 1000, 1), LZMA_OK
);
626 assert_lzma_ret(lzma_index_append(idx
, NULL
, 1000, 10), LZMA_OK
);
627 assert_lzma_ret(lzma_index_append(idx
, NULL
, 1000, 100), LZMA_OK
);
629 assert_uint_eq(lzma_index_uncompressed_size(idx
), 111);
631 // Create another lzma_index
632 lzma_index
*second
= lzma_index_init(NULL
);
633 assert_true(second
!= NULL
);
635 // Append a few small Blocks
636 assert_lzma_ret(lzma_index_append(second
, NULL
, 1000, 2), LZMA_OK
);
637 assert_lzma_ret(lzma_index_append(second
, NULL
, 1000, 20), LZMA_OK
);
638 assert_lzma_ret(lzma_index_append(second
, NULL
, 1000, 200), LZMA_OK
);
640 assert_uint_eq(lzma_index_uncompressed_size(second
), 222);
642 // Concatenate second lzma_index to first
643 assert_lzma_ret(lzma_index_cat(idx
, second
, NULL
), LZMA_OK
);
645 // New uncompressed .xz file size should be the sum of the two Streams
646 assert_uint_eq(lzma_index_uncompressed_size(idx
), 333);
648 // Append one more Block to the lzma_index and ensure that
649 // it is properly updated
650 assert_lzma_ret(lzma_index_append(idx
, NULL
, 1000, 111), LZMA_OK
);
651 assert_uint_eq(lzma_index_uncompressed_size(idx
), 444);
653 lzma_index_end(idx
, NULL
);
658 test_lzma_index_iter_init(void)
660 // Testing basic init functionality.
661 // The init function should call rewind on the iterator.
662 lzma_index
*first
= lzma_index_init(NULL
);
663 assert_true(first
!= NULL
);
665 lzma_index
*second
= lzma_index_init(NULL
);
666 assert_true(second
!= NULL
);
668 lzma_index
*third
= lzma_index_init(NULL
);
669 assert_true(third
!= NULL
);
671 assert_lzma_ret(lzma_index_cat(first
, second
, NULL
), LZMA_OK
);
672 assert_lzma_ret(lzma_index_cat(first
, third
, NULL
), LZMA_OK
);
674 lzma_index_iter iter
;
675 lzma_index_iter_init(&iter
, first
);
677 assert_false(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_STREAM
));
678 assert_uint_eq(iter
.stream
.number
, 1);
679 assert_false(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_STREAM
));
680 assert_uint_eq(iter
.stream
.number
, 2);
682 lzma_index_iter_init(&iter
, first
);
684 assert_false(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_STREAM
));
685 assert_false(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_STREAM
));
686 assert_false(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_STREAM
));
687 assert_uint_eq(iter
.stream
.number
, 3);
689 lzma_index_end(first
, NULL
);
694 test_lzma_index_iter_rewind(void)
696 lzma_index
*first
= lzma_index_init(NULL
);
697 assert_true(first
!= NULL
);
699 lzma_index_iter iter
;
700 lzma_index_iter_init(&iter
, first
);
702 // Append 3 Blocks and iterate over each. This is to test
703 // the LZMA_INDEX_ITER_BLOCK mode.
704 for (uint32_t i
= 0; i
< 3; i
++) {
705 assert_lzma_ret(lzma_index_append(first
, NULL
,
706 UNPADDED_SIZE_MIN
, 1), LZMA_OK
);
707 assert_false(lzma_index_iter_next(&iter
,
708 LZMA_INDEX_ITER_BLOCK
));
709 assert_uint_eq(iter
.block
.number_in_file
, i
+ 1);
710 assert_uint_eq(iter
.block
.number_in_stream
, i
+ 1);
713 // Rewind back to the beginning and iterate over the Blocks again
714 lzma_index_iter_rewind(&iter
);
716 // Should be able to re-iterate over the Blocks again.
717 for (uint32_t i
= 0; i
< 3; i
++) {
718 assert_false(lzma_index_iter_next(&iter
,
719 LZMA_INDEX_ITER_BLOCK
));
720 assert_uint_eq(iter
.block
.number_in_file
, i
+ 1);
721 assert_uint_eq(iter
.block
.number_in_stream
, i
+ 1);
724 // Next concatenate two more lzma_indexes, iterate over them,
725 // rewind, and iterate over them again. This is to test
726 // the LZMA_INDEX_ITER_STREAM mode.
727 lzma_index
*second
= lzma_index_init(NULL
);
728 assert_true(second
!= NULL
);
730 lzma_index
*third
= lzma_index_init(NULL
);
731 assert_true(third
!= NULL
);
733 assert_lzma_ret(lzma_index_cat(first
, second
, NULL
), LZMA_OK
);
734 assert_lzma_ret(lzma_index_cat(first
, third
, NULL
), LZMA_OK
);
736 assert_false(lzma_index_iter_next(&iter
,
737 LZMA_INDEX_ITER_STREAM
));
738 assert_false(lzma_index_iter_next(&iter
,
739 LZMA_INDEX_ITER_STREAM
));
741 assert_uint_eq(iter
.stream
.number
, 3);
743 lzma_index_iter_rewind(&iter
);
745 for (uint32_t i
= 0; i
< 3; i
++) {
746 assert_false(lzma_index_iter_next(&iter
,
747 LZMA_INDEX_ITER_STREAM
));
748 assert_uint_eq(iter
.stream
.number
, i
+ 1);
751 lzma_index_end(first
, NULL
);
756 test_lzma_index_iter_next(void)
758 lzma_index
*first
= lzma_index_init(NULL
);
759 assert_true(first
!= NULL
);
761 lzma_index_iter iter
;
762 lzma_index_iter_init(&iter
, first
);
764 // First test bad mode values
765 for (uint32_t i
= LZMA_INDEX_ITER_NONEMPTY_BLOCK
+ 1; i
< 100; i
++)
766 assert_true(lzma_index_iter_next(&iter
, i
));
768 // Test iterating over Blocks
769 assert_lzma_ret(lzma_index_append(first
, NULL
,
770 UNPADDED_SIZE_MIN
, 1), LZMA_OK
);
771 assert_lzma_ret(lzma_index_append(first
, NULL
,
772 UNPADDED_SIZE_MIN
* 2, 10), LZMA_OK
);
773 assert_lzma_ret(lzma_index_append(first
, NULL
,
774 UNPADDED_SIZE_MIN
* 3, 100), LZMA_OK
);
776 // For Blocks, need to verify:
777 // - number_in_file (overall Block number)
778 // - compressed_file_offset
779 // - uncompressed_file_offset
780 // - number_in_stream (Block number relative to current Stream)
781 // - compressed_stream_offset
782 // - uncompressed_stream_offset
783 // - uncompressed_size
787 assert_false(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_BLOCK
));
789 // Verify Block data stored correctly
790 assert_uint_eq(iter
.block
.number_in_file
, 1);
792 // Should start right after the Stream Header
793 assert_uint_eq(iter
.block
.compressed_file_offset
,
794 LZMA_STREAM_HEADER_SIZE
);
795 assert_uint_eq(iter
.block
.uncompressed_file_offset
, 0);
796 assert_uint_eq(iter
.block
.number_in_stream
, 1);
797 assert_uint_eq(iter
.block
.compressed_stream_offset
,
798 LZMA_STREAM_HEADER_SIZE
);
799 assert_uint_eq(iter
.block
.uncompressed_stream_offset
, 0);
800 assert_uint_eq(iter
.block
.unpadded_size
, UNPADDED_SIZE_MIN
);
801 assert_uint_eq(iter
.block
.total_size
, vli_ceil4(UNPADDED_SIZE_MIN
));
803 assert_false(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_BLOCK
));
805 // Verify Block data stored correctly
806 assert_uint_eq(iter
.block
.number_in_file
, 2);
807 assert_uint_eq(iter
.block
.compressed_file_offset
,
808 LZMA_STREAM_HEADER_SIZE
+
809 vli_ceil4(UNPADDED_SIZE_MIN
));
810 assert_uint_eq(iter
.block
.uncompressed_file_offset
, 1);
811 assert_uint_eq(iter
.block
.number_in_stream
, 2);
812 assert_uint_eq(iter
.block
.compressed_stream_offset
,
813 LZMA_STREAM_HEADER_SIZE
+
814 vli_ceil4(UNPADDED_SIZE_MIN
));
815 assert_uint_eq(iter
.block
.uncompressed_stream_offset
, 1);
816 assert_uint_eq(iter
.block
.unpadded_size
, UNPADDED_SIZE_MIN
* 2);
817 assert_uint_eq(iter
.block
.total_size
, vli_ceil4(UNPADDED_SIZE_MIN
* 2));
819 assert_false(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_BLOCK
));
821 // Verify Block data stored correctly
822 assert_uint_eq(iter
.block
.number_in_file
, 3);
823 assert_uint_eq(iter
.block
.compressed_file_offset
,
824 LZMA_STREAM_HEADER_SIZE
+
825 vli_ceil4(UNPADDED_SIZE_MIN
) +
826 vli_ceil4(UNPADDED_SIZE_MIN
* 2));
827 assert_uint_eq(iter
.block
.uncompressed_file_offset
, 11);
828 assert_uint_eq(iter
.block
.number_in_stream
, 3);
829 assert_uint_eq(iter
.block
.compressed_stream_offset
,
830 LZMA_STREAM_HEADER_SIZE
+
831 vli_ceil4(UNPADDED_SIZE_MIN
) +
832 vli_ceil4(UNPADDED_SIZE_MIN
* 2));
833 assert_uint_eq(iter
.block
.uncompressed_stream_offset
, 11);
834 assert_uint_eq(iter
.block
.unpadded_size
, UNPADDED_SIZE_MIN
* 3);
835 assert_uint_eq(iter
.block
.total_size
,
836 vli_ceil4(UNPADDED_SIZE_MIN
* 3));
838 // Only three Blocks were added, so this should return true
839 assert_true(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_BLOCK
));
841 const lzma_vli second_stream_compressed_start
=
842 LZMA_STREAM_HEADER_SIZE
* 2 +
843 vli_ceil4(UNPADDED_SIZE_MIN
) +
844 vli_ceil4(UNPADDED_SIZE_MIN
* 2) +
845 vli_ceil4(UNPADDED_SIZE_MIN
* 3) +
846 lzma_index_size(first
);
847 const lzma_vli second_stream_uncompressed_start
= 1 + 10 + 100;
849 // Test iterating over Streams.
850 // The second Stream will have 0 Blocks
851 lzma_index
*second
= lzma_index_init(NULL
);
852 assert_true(second
!= NULL
);
854 // Set Stream Flags for Stream 2
855 lzma_stream_flags flags
= {
857 .backward_size
= LZMA_BACKWARD_SIZE_MIN
,
858 .check
= LZMA_CHECK_CRC32
861 assert_lzma_ret(lzma_index_stream_flags(second
, &flags
), LZMA_OK
);
863 // The Second stream will have 8 bytes of Stream Padding
864 assert_lzma_ret(lzma_index_stream_padding(second
, 8), LZMA_OK
);
866 const lzma_vli second_stream_index_size
= lzma_index_size(second
);
868 // The third Stream will have 2 Blocks
869 lzma_index
*third
= lzma_index_init(NULL
);
870 assert_true(third
!= NULL
);
872 assert_lzma_ret(lzma_index_append(third
, NULL
, 32, 20), LZMA_OK
);
873 assert_lzma_ret(lzma_index_append(third
, NULL
, 64, 40), LZMA_OK
);
875 const lzma_vli third_stream_index_size
= lzma_index_size(third
);
877 assert_lzma_ret(lzma_index_cat(first
, second
, NULL
), LZMA_OK
);
878 assert_lzma_ret(lzma_index_cat(first
, third
, NULL
), LZMA_OK
);
880 // For Streams, need to verify:
881 // - flags (Stream Flags)
882 // - number (Stream count)
884 // - compressed_offset
885 // - uncompressed_offset
887 // - uncompressed_size
888 // - padding (Stream Padding)
889 assert_false(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_STREAM
));
892 assert_uint_eq(iter
.stream
.flags
->backward_size
,
893 LZMA_BACKWARD_SIZE_MIN
);
894 assert_uint_eq(iter
.stream
.flags
->check
, LZMA_CHECK_CRC32
);
895 assert_uint_eq(iter
.stream
.number
, 2);
896 assert_uint_eq(iter
.stream
.block_count
, 0);
897 assert_uint_eq(iter
.stream
.compressed_offset
,
898 second_stream_compressed_start
);
899 assert_uint_eq(iter
.stream
.uncompressed_offset
,
900 second_stream_uncompressed_start
);
901 assert_uint_eq(iter
.stream
.compressed_size
,
902 LZMA_STREAM_HEADER_SIZE
* 2 +
903 second_stream_index_size
);
904 assert_uint_eq(iter
.stream
.uncompressed_size
, 0);
905 assert_uint_eq(iter
.stream
.padding
, 8);
907 assert_false(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_STREAM
));
910 const lzma_vli third_stream_compressed_start
=
911 second_stream_compressed_start
+
912 LZMA_STREAM_HEADER_SIZE
* 2 +
913 8 + // Stream padding
914 second_stream_index_size
;
915 const lzma_vli third_stream_uncompressed_start
=
916 second_stream_uncompressed_start
;
918 assert_uint_eq(iter
.stream
.number
, 3);
919 assert_uint_eq(iter
.stream
.block_count
, 2);
920 assert_uint_eq(iter
.stream
.compressed_offset
,
921 third_stream_compressed_start
);
922 assert_uint_eq(iter
.stream
.uncompressed_offset
,
923 third_stream_uncompressed_start
);
924 assert_uint_eq(iter
.stream
.compressed_size
,
925 LZMA_STREAM_HEADER_SIZE
* 2 +
926 96 + // Total compressed size
927 third_stream_index_size
);
928 assert_uint_eq(iter
.stream
.uncompressed_size
, 60);
929 assert_uint_eq(iter
.stream
.padding
, 0);
931 assert_true(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_STREAM
));
933 // Even after a failing call to next with ITER_STREAM mode,
934 // should still be able to iterate over the 2 Blocks in
936 assert_false(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_BLOCK
));
938 // Verify both Blocks
940 // Next call to iterate Block should return true because the
941 // first Block can already be read from the earlier *successful*
942 // LZMA_INDEX_ITER_STREAM call; the previous failed call doesn't
943 // modify the iterator.
944 assert_true(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_BLOCK
));
946 // Rewind to test LZMA_INDEX_ITER_ANY
947 lzma_index_iter_rewind(&iter
);
949 // Iterate past the first three Blocks
950 assert_false(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_ANY
));
951 assert_false(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_ANY
));
952 assert_false(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_ANY
));
954 // Iterate past the next Stream
955 assert_false(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_ANY
));
957 // Iterate past the next Stream
958 assert_false(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_ANY
));
959 assert_false(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_ANY
));
961 // Last call should fail
962 assert_true(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_ANY
));
964 // Rewind to test LZMA_INDEX_ITER_NONEMPTY_BLOCK
965 lzma_index_iter_rewind(&iter
);
967 // Iterate past the first three Blocks
968 assert_false(lzma_index_iter_next(&iter
,
969 LZMA_INDEX_ITER_NONEMPTY_BLOCK
));
970 assert_false(lzma_index_iter_next(&iter
,
971 LZMA_INDEX_ITER_NONEMPTY_BLOCK
));
972 assert_false(lzma_index_iter_next(&iter
,
973 LZMA_INDEX_ITER_NONEMPTY_BLOCK
));
975 // Skip past the next Stream which has no Blocks.
976 // We will get to the first Block of the third Stream.
977 assert_false(lzma_index_iter_next(&iter
,
978 LZMA_INDEX_ITER_NONEMPTY_BLOCK
));
980 // Iterate past the second (the last) Block in the third Stream
981 assert_false(lzma_index_iter_next(&iter
,
982 LZMA_INDEX_ITER_NONEMPTY_BLOCK
));
984 // Last call should fail since there is nothing left to iterate over.
985 assert_true(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_ANY
));
987 lzma_index_end(first
, NULL
);
992 test_lzma_index_iter_locate(void)
994 lzma_index
*idx
= lzma_index_init(NULL
);
995 assert_true(idx
!= NULL
);
997 lzma_index_iter iter
;
998 lzma_index_iter_init(&iter
, idx
);
1000 // Cannot locate anything from an empty Index.
1001 assert_true(lzma_index_iter_locate(&iter
, 0));
1002 assert_true(lzma_index_iter_locate(&iter
, 555));
1004 // One empty Record: nothing is found since there's no uncompressed
1006 assert_lzma_ret(lzma_index_append(idx
, NULL
, 16, 0), LZMA_OK
);
1007 assert_true(lzma_index_iter_locate(&iter
, 0));
1009 // Non-empty Record and we can find something.
1010 assert_lzma_ret(lzma_index_append(idx
, NULL
, 32, 5), LZMA_OK
);
1011 assert_false(lzma_index_iter_locate(&iter
, 0));
1012 assert_uint_eq(iter
.block
.total_size
, 32);
1013 assert_uint_eq(iter
.block
.uncompressed_size
, 5);
1014 assert_uint_eq(iter
.block
.compressed_file_offset
,
1015 LZMA_STREAM_HEADER_SIZE
+ 16);
1016 assert_uint_eq(iter
.block
.uncompressed_file_offset
, 0);
1018 // Still cannot find anything past the end.
1019 assert_true(lzma_index_iter_locate(&iter
, 5));
1021 // Add the third Record.
1022 assert_lzma_ret(lzma_index_append(idx
, NULL
, 40, 11), LZMA_OK
);
1024 assert_false(lzma_index_iter_locate(&iter
, 0));
1025 assert_uint_eq(iter
.block
.total_size
, 32);
1026 assert_uint_eq(iter
.block
.uncompressed_size
, 5);
1027 assert_uint_eq(iter
.block
.compressed_file_offset
,
1028 LZMA_STREAM_HEADER_SIZE
+ 16);
1029 assert_uint_eq(iter
.block
.uncompressed_file_offset
, 0);
1031 assert_false(lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_BLOCK
));
1032 assert_uint_eq(iter
.block
.total_size
, 40);
1033 assert_uint_eq(iter
.block
.uncompressed_size
, 11);
1034 assert_uint_eq(iter
.block
.compressed_file_offset
,
1035 LZMA_STREAM_HEADER_SIZE
+ 16 + 32);
1036 assert_uint_eq(iter
.block
.uncompressed_file_offset
, 5);
1038 assert_false(lzma_index_iter_locate(&iter
, 2));
1039 assert_uint_eq(iter
.block
.total_size
, 32);
1040 assert_uint_eq(iter
.block
.uncompressed_size
, 5);
1041 assert_uint_eq(iter
.block
.compressed_file_offset
,
1042 LZMA_STREAM_HEADER_SIZE
+ 16);
1043 assert_uint_eq(iter
.block
.uncompressed_file_offset
, 0);
1045 assert_false(lzma_index_iter_locate(&iter
, 5));
1046 assert_uint_eq(iter
.block
.total_size
, 40);
1047 assert_uint_eq(iter
.block
.uncompressed_size
, 11);
1048 assert_uint_eq(iter
.block
.compressed_file_offset
,
1049 LZMA_STREAM_HEADER_SIZE
+ 16 + 32);
1050 assert_uint_eq(iter
.block
.uncompressed_file_offset
, 5);
1052 assert_false(lzma_index_iter_locate(&iter
, 5 + 11 - 1));
1053 assert_uint_eq(iter
.block
.total_size
, 40);
1054 assert_uint_eq(iter
.block
.uncompressed_size
, 11);
1055 assert_uint_eq(iter
.block
.compressed_file_offset
,
1056 LZMA_STREAM_HEADER_SIZE
+ 16 + 32);
1057 assert_uint_eq(iter
.block
.uncompressed_file_offset
, 5);
1059 assert_true(lzma_index_iter_locate(&iter
, 5 + 11));
1060 assert_true(lzma_index_iter_locate(&iter
, 5 + 15));
1063 lzma_index_end(idx
, NULL
);
1064 idx
= lzma_index_init(NULL
);
1065 assert_true(idx
!= NULL
);
1066 lzma_index_iter_init(&iter
, idx
);
1068 for (uint32_t n
= 4; n
<= 4 * 5555; n
+= 4)
1069 assert_lzma_ret(lzma_index_append(idx
, NULL
, n
+ 7, n
),
1072 assert_uint_eq(lzma_index_block_count(idx
), 5555);
1075 assert_false(lzma_index_iter_locate(&iter
, 0));
1076 assert_uint_eq(iter
.block
.unpadded_size
, 4 + 7);
1077 assert_uint_eq(iter
.block
.total_size
, 4 + 8);
1078 assert_uint_eq(iter
.block
.uncompressed_size
, 4);
1079 assert_uint_eq(iter
.block
.compressed_file_offset
,
1080 LZMA_STREAM_HEADER_SIZE
);
1081 assert_uint_eq(iter
.block
.uncompressed_file_offset
, 0);
1083 assert_false(lzma_index_iter_locate(&iter
, 3));
1084 assert_uint_eq(iter
.block
.unpadded_size
, 4 + 7);
1085 assert_uint_eq(iter
.block
.total_size
, 4 + 8);
1086 assert_uint_eq(iter
.block
.uncompressed_size
, 4);
1087 assert_uint_eq(iter
.block
.compressed_file_offset
,
1088 LZMA_STREAM_HEADER_SIZE
);
1089 assert_uint_eq(iter
.block
.uncompressed_file_offset
, 0);
1092 assert_false(lzma_index_iter_locate(&iter
, 4));
1093 assert_uint_eq(iter
.block
.unpadded_size
, 2 * 4 + 7);
1094 assert_uint_eq(iter
.block
.total_size
, 2 * 4 + 8);
1095 assert_uint_eq(iter
.block
.uncompressed_size
, 2 * 4);
1096 assert_uint_eq(iter
.block
.compressed_file_offset
,
1097 LZMA_STREAM_HEADER_SIZE
+ 4 + 8);
1098 assert_uint_eq(iter
.block
.uncompressed_file_offset
, 4);
1101 assert_false(lzma_index_iter_locate(
1102 &iter
, lzma_index_uncompressed_size(idx
) - 1));
1103 assert_uint_eq(iter
.block
.unpadded_size
, 4 * 5555 + 7);
1104 assert_uint_eq(iter
.block
.total_size
, 4 * 5555 + 8);
1105 assert_uint_eq(iter
.block
.uncompressed_size
, 4 * 5555);
1106 assert_uint_eq(iter
.block
.compressed_file_offset
,
1107 lzma_index_total_size(idx
)
1108 + LZMA_STREAM_HEADER_SIZE
- 4 * 5555 - 8);
1109 assert_uint_eq(iter
.block
.uncompressed_file_offset
,
1110 lzma_index_uncompressed_size(idx
) - 4 * 5555);
1112 // Allocation chunk boundaries. See INDEX_GROUP_SIZE in
1113 // liblzma/common/index.c.
1114 const uint32_t group_multiple
= 256 * 4;
1115 const uint32_t radius
= 8;
1116 const uint32_t start
= group_multiple
- radius
;
1120 for (n
= 1; n
< start
; ++n
) {
1125 while (n
< start
+ 2 * radius
) {
1126 assert_false(lzma_index_iter_locate(&iter
, ubase
+ n
* 4));
1128 assert_uint_eq(iter
.block
.compressed_file_offset
,
1130 + LZMA_STREAM_HEADER_SIZE
);
1131 assert_uint_eq(iter
.block
.uncompressed_file_offset
,
1138 assert_uint_eq(iter
.block
.total_size
, n
* 4 + 8);
1139 assert_uint_eq(iter
.block
.uncompressed_size
, n
* 4);
1142 // Do it also backwards.
1144 assert_false(lzma_index_iter_locate(
1145 &iter
, ubase
+ (n
- 1) * 4));
1147 assert_uint_eq(iter
.block
.total_size
, n
* 4 + 8);
1148 assert_uint_eq(iter
.block
.uncompressed_size
, n
* 4);
1154 assert_uint_eq(iter
.block
.compressed_file_offset
,
1156 + LZMA_STREAM_HEADER_SIZE
);
1157 assert_uint_eq(iter
.block
.uncompressed_file_offset
,
1161 // Test locating in concatenated Index.
1162 lzma_index_end(idx
, NULL
);
1163 idx
= lzma_index_init(NULL
);
1164 assert_true(idx
!= NULL
);
1165 lzma_index_iter_init(&iter
, idx
);
1166 for (n
= 0; n
< group_multiple
; ++n
)
1167 assert_lzma_ret(lzma_index_append(idx
, NULL
, 8, 0),
1170 assert_lzma_ret(lzma_index_append(idx
, NULL
, 16, 1), LZMA_OK
);
1171 assert_false(lzma_index_iter_locate(&iter
, 0));
1172 assert_uint_eq(iter
.block
.total_size
, 16);
1173 assert_uint_eq(iter
.block
.uncompressed_size
, 1);
1174 assert_uint_eq(iter
.block
.compressed_file_offset
,
1175 LZMA_STREAM_HEADER_SIZE
+ group_multiple
* 8);
1176 assert_uint_eq(iter
.block
.uncompressed_file_offset
, 0);
1178 lzma_index_end(idx
, NULL
);
1183 test_lzma_index_cat(void)
1185 // Most complex tests for this function are done in other tests.
1186 // This will mostly test basic functionality.
1188 lzma_index
*dest
= lzma_index_init(NULL
);
1189 assert_true(dest
!= NULL
);
1191 lzma_index
*src
= lzma_index_init(NULL
);
1192 assert_true(src
!= NULL
);
1194 // First test NULL dest or src
1195 assert_lzma_ret(lzma_index_cat(NULL
, NULL
, NULL
), LZMA_PROG_ERROR
);
1196 assert_lzma_ret(lzma_index_cat(dest
, NULL
, NULL
), LZMA_PROG_ERROR
);
1197 assert_lzma_ret(lzma_index_cat(NULL
, src
, NULL
), LZMA_PROG_ERROR
);
1199 // Check for compressed size overflow
1200 assert_lzma_ret(lzma_index_append(dest
, NULL
,
1201 (UNPADDED_SIZE_MAX
/ 2) + 1, 1), LZMA_OK
);
1202 assert_lzma_ret(lzma_index_append(src
, NULL
,
1203 (UNPADDED_SIZE_MAX
/ 2) + 1, 1), LZMA_OK
);
1204 assert_lzma_ret(lzma_index_cat(dest
, src
, NULL
), LZMA_DATA_ERROR
);
1206 lzma_index_end(src
, NULL
);
1207 lzma_index_end(dest
, NULL
);
1209 // Check for uncompressed size overflow
1210 dest
= lzma_index_init(NULL
);
1211 assert_true(dest
!= NULL
);
1213 src
= lzma_index_init(NULL
);
1214 assert_true(src
!= NULL
);
1216 assert_lzma_ret(lzma_index_append(dest
, NULL
,
1217 UNPADDED_SIZE_MIN
, (LZMA_VLI_MAX
/ 2) + 1), LZMA_OK
);
1218 assert_lzma_ret(lzma_index_append(src
, NULL
,
1219 UNPADDED_SIZE_MIN
, (LZMA_VLI_MAX
/ 2) + 1), LZMA_OK
);
1220 assert_lzma_ret(lzma_index_cat(dest
, src
, NULL
), LZMA_DATA_ERROR
);
1222 lzma_index_end(dest
, NULL
);
1223 lzma_index_end(src
, NULL
);
1227 // Helper function for test_lzma_index_dup().
1229 index_is_equal(const lzma_index
*a
, const lzma_index
*b
)
1231 // Compare only the Stream and Block sizes and offsets.
1232 lzma_index_iter ra
, rb
;
1233 lzma_index_iter_init(&ra
, a
);
1234 lzma_index_iter_init(&rb
, b
);
1237 bool reta
= lzma_index_iter_next(&ra
, LZMA_INDEX_ITER_ANY
);
1238 bool retb
= lzma_index_iter_next(&rb
, LZMA_INDEX_ITER_ANY
);
1240 // If both iterators finish at the same time, then the Indexes
1245 if (ra
.stream
.number
!= rb
.stream
.number
1246 || ra
.stream
.block_count
1247 != rb
.stream
.block_count
1248 || ra
.stream
.compressed_offset
1249 != rb
.stream
.compressed_offset
1250 || ra
.stream
.uncompressed_offset
1251 != rb
.stream
.uncompressed_offset
1252 || ra
.stream
.compressed_size
1253 != rb
.stream
.compressed_size
1254 || ra
.stream
.uncompressed_size
1255 != rb
.stream
.uncompressed_size
1256 || ra
.stream
.padding
1257 != rb
.stream
.padding
)
1260 if (ra
.stream
.block_count
== 0)
1263 if (ra
.block
.number_in_file
!= rb
.block
.number_in_file
1264 || ra
.block
.compressed_file_offset
1265 != rb
.block
.compressed_file_offset
1266 || ra
.block
.uncompressed_file_offset
1267 != rb
.block
.uncompressed_file_offset
1268 || ra
.block
.number_in_stream
1269 != rb
.block
.number_in_stream
1270 || ra
.block
.compressed_stream_offset
1271 != rb
.block
.compressed_stream_offset
1272 || ra
.block
.uncompressed_stream_offset
1273 != rb
.block
.uncompressed_stream_offset
1274 || ra
.block
.uncompressed_size
1275 != rb
.block
.uncompressed_size
1276 || ra
.block
.unpadded_size
1277 != rb
.block
.unpadded_size
1278 || ra
.block
.total_size
1279 != rb
.block
.total_size
)
1285 // Allocator that succeeds for the first two allocation but fails the rest.
1287 my_alloc(void *opaque
, size_t a
, size_t b
)
1291 assert_true(SIZE_MAX
/ a
>= b
);
1293 static unsigned count
= 0;
1298 return malloc(a
* b
);
1302 static const lzma_allocator test_index_dup_alloc
= { &my_alloc
, NULL
, NULL
};
1306 test_lzma_index_dup(void)
1308 lzma_index
*idx
= lzma_index_init(NULL
);
1309 assert_true(idx
!= NULL
);
1311 // Test for the bug fix 21515d79d778b8730a434f151b07202d52a04611:
1312 // liblzma: Fix lzma_index_dup() for empty Streams.
1313 assert_lzma_ret(lzma_index_stream_padding(idx
, 4), LZMA_OK
);
1314 lzma_index
*copy
= lzma_index_dup(idx
, NULL
);
1315 assert_true(copy
!= NULL
);
1316 assert_true(index_is_equal(idx
, copy
));
1317 lzma_index_end(copy
, NULL
);
1319 // Test for the bug fix 3bf857edfef51374f6f3fffae3d817f57d3264a0:
1320 // liblzma: Fix a memory leak in error path of lzma_index_dup().
1321 // Use Valgrind to see that there are no leaks.
1322 assert_lzma_ret(lzma_index_append(idx
, NULL
,
1323 UNPADDED_SIZE_MIN
, 10), LZMA_OK
);
1324 assert_lzma_ret(lzma_index_append(idx
, NULL
,
1325 UNPADDED_SIZE_MIN
* 2, 100), LZMA_OK
);
1326 assert_lzma_ret(lzma_index_append(idx
, NULL
,
1327 UNPADDED_SIZE_MIN
* 3, 1000), LZMA_OK
);
1329 assert_true(lzma_index_dup(idx
, &test_index_dup_alloc
) == NULL
);
1331 // Test a few streams and blocks
1332 lzma_index
*second
= lzma_index_init(NULL
);
1333 assert_true(second
!= NULL
);
1335 assert_lzma_ret(lzma_index_stream_padding(second
, 16), LZMA_OK
);
1337 lzma_index
*third
= lzma_index_init(NULL
);
1338 assert_true(third
!= NULL
);
1340 assert_lzma_ret(lzma_index_append(third
, NULL
,
1341 UNPADDED_SIZE_MIN
* 10, 40), LZMA_OK
);
1342 assert_lzma_ret(lzma_index_append(third
, NULL
,
1343 UNPADDED_SIZE_MIN
* 20, 400), LZMA_OK
);
1344 assert_lzma_ret(lzma_index_append(third
, NULL
,
1345 UNPADDED_SIZE_MIN
* 30, 4000), LZMA_OK
);
1347 assert_lzma_ret(lzma_index_cat(idx
, second
, NULL
), LZMA_OK
);
1348 assert_lzma_ret(lzma_index_cat(idx
, third
, NULL
), LZMA_OK
);
1350 copy
= lzma_index_dup(idx
, NULL
);
1351 assert_true(copy
!= NULL
);
1352 assert_true(index_is_equal(idx
, copy
));
1354 lzma_index_end(copy
, NULL
);
1355 lzma_index_end(idx
, NULL
);
1359 #if defined(HAVE_ENCODERS) && defined(HAVE_DECODERS)
1361 verify_index_buffer(const lzma_index
*idx
, const uint8_t *buffer
,
1362 const size_t buffer_size
)
1364 lzma_index_iter iter
;
1365 lzma_index_iter_init(&iter
, idx
);
1367 size_t buffer_pos
= 0;
1369 // Verify Index Indicator
1370 assert_uint_eq(buffer
[buffer_pos
++], 0);
1372 // Get Number of Records
1373 lzma_vli number_of_records
= 0;
1374 lzma_vli block_count
= 0;
1375 assert_lzma_ret(lzma_vli_decode(&number_of_records
, NULL
, buffer
,
1376 &buffer_pos
, buffer_size
), LZMA_OK
);
1378 while (!lzma_index_iter_next(&iter
, LZMA_INDEX_ITER_ANY
)) {
1379 // Verify each Record (Unpadded Size, then Uncompressed Size).
1380 // Verify Unpadded Size.
1381 lzma_vli unpadded_size
, uncompressed_size
;
1382 assert_lzma_ret(lzma_vli_decode(&unpadded_size
,
1383 NULL
, buffer
, &buffer_pos
,
1384 buffer_size
), LZMA_OK
);
1385 assert_uint_eq(unpadded_size
,
1386 iter
.block
.unpadded_size
);
1388 // Verify Uncompressed Size
1389 assert_lzma_ret(lzma_vli_decode(&uncompressed_size
,
1390 NULL
, buffer
, &buffer_pos
,
1391 buffer_size
), LZMA_OK
);
1392 assert_uint_eq(uncompressed_size
,
1393 iter
.block
.uncompressed_size
);
1398 // Verify Number of Records
1399 assert_uint_eq(number_of_records
, block_count
);
1401 // Verify Index Padding
1402 for (; buffer_pos
% 4 != 0; buffer_pos
++)
1403 assert_uint_eq(buffer
[buffer_pos
], 0);
1406 uint32_t crc32
= lzma_crc32(buffer
, buffer_pos
, 0);
1407 assert_uint_eq(read32le(buffer
+ buffer_pos
), crc32
);
1411 // In a few places the Index size is needed as a size_t but lzma_index_size()
1412 // returns lzma_vli.
1414 get_index_size(const lzma_index
*idx
)
1416 const lzma_vli size
= lzma_index_size(idx
);
1417 assert_uint(size
, <, SIZE_MAX
);
1418 return (size_t)size
;
1424 test_lzma_index_encoder(void)
1426 #if !defined(HAVE_ENCODERS) || !defined(HAVE_DECODERS)
1427 assert_skip("Encoder or decoder support disabled");
1429 lzma_index
*idx
= lzma_index_init(NULL
);
1430 assert_true(idx
!= NULL
);
1432 lzma_stream strm
= LZMA_STREAM_INIT
;
1434 // First do basic NULL checks
1435 assert_lzma_ret(lzma_index_encoder(NULL
, NULL
), LZMA_PROG_ERROR
);
1436 assert_lzma_ret(lzma_index_encoder(&strm
, NULL
), LZMA_PROG_ERROR
);
1437 assert_lzma_ret(lzma_index_encoder(NULL
, idx
), LZMA_PROG_ERROR
);
1439 // Append three small Blocks
1440 assert_lzma_ret(lzma_index_append(idx
, NULL
,
1441 UNPADDED_SIZE_MIN
, 10), LZMA_OK
);
1442 assert_lzma_ret(lzma_index_append(idx
, NULL
,
1443 UNPADDED_SIZE_MIN
* 2, 100), LZMA_OK
);
1444 assert_lzma_ret(lzma_index_append(idx
, NULL
,
1445 UNPADDED_SIZE_MIN
* 3, 1000), LZMA_OK
);
1447 // Encode this lzma_index into a buffer
1448 size_t buffer_size
= get_index_size(idx
);
1449 uint8_t *buffer
= tuktest_malloc(buffer_size
);
1451 assert_lzma_ret(lzma_index_encoder(&strm
, idx
), LZMA_OK
);
1453 strm
.avail_out
= buffer_size
;
1454 strm
.next_out
= buffer
;
1456 assert_lzma_ret(lzma_code(&strm
, LZMA_FINISH
), LZMA_STREAM_END
);
1457 assert_uint_eq(strm
.avail_out
, 0);
1461 verify_index_buffer(idx
, buffer
, buffer_size
);
1463 // Test with multiple Streams concatenated into 1 Index
1464 lzma_index
*second
= lzma_index_init(NULL
);
1465 assert_true(second
!= NULL
);
1468 assert_lzma_ret(lzma_index_append(second
, NULL
,
1469 UNPADDED_SIZE_MIN
* 4, 20), LZMA_OK
);
1471 // Include Stream Padding
1472 assert_lzma_ret(lzma_index_stream_padding(second
, 16), LZMA_OK
);
1474 assert_lzma_ret(lzma_index_cat(idx
, second
, NULL
), LZMA_OK
);
1475 buffer_size
= get_index_size(idx
);
1476 buffer
= tuktest_malloc(buffer_size
);
1477 assert_lzma_ret(lzma_index_encoder(&strm
, idx
), LZMA_OK
);
1479 strm
.avail_out
= buffer_size
;
1480 strm
.next_out
= buffer
;
1482 assert_lzma_ret(lzma_code(&strm
, LZMA_FINISH
), LZMA_STREAM_END
);
1483 assert_uint_eq(strm
.avail_out
, 0);
1485 verify_index_buffer(idx
, buffer
, buffer_size
);
1487 lzma_index_end(idx
, NULL
);
1494 generate_index_decode_buffer(void)
1496 #ifdef HAVE_ENCODERS
1497 decode_test_index
= lzma_index_init(NULL
);
1498 assert_true(decode_test_index
!= NULL
);
1501 for (uint32_t i
= 1; i
< 5; i
++)
1502 assert_lzma_ret(lzma_index_append(decode_test_index
, NULL
,
1503 0x1000 * i
, 0x100 * i
), LZMA_OK
);
1505 const size_t size
= (size_t)lzma_index_size(decode_test_index
);
1506 decode_buffer
= tuktest_malloc(size
);
1508 assert_lzma_ret(lzma_index_buffer_encode(decode_test_index
,
1509 decode_buffer
, &decode_buffer_size
, size
), LZMA_OK
);
1510 assert_true(decode_buffer_size
!= 0);
1515 #if defined(HAVE_ENCODERS) && defined(HAVE_DECODERS)
1517 decode_index(const uint8_t *buffer
, const size_t size
, lzma_stream
*strm
,
1518 lzma_ret expected_error
)
1520 strm
->avail_in
= size
;
1521 strm
->next_in
= buffer
;
1522 assert_lzma_ret(lzma_code(strm
, LZMA_FINISH
), expected_error
);
1528 test_lzma_index_decoder(void)
1530 #if !defined(HAVE_ENCODERS) || !defined(HAVE_DECODERS)
1531 assert_skip("Encoder or decoder support disabled");
1533 assert_true(decode_buffer_size
!= 0);
1535 lzma_stream strm
= LZMA_STREAM_INIT
;
1537 assert_lzma_ret(lzma_index_decoder(NULL
, NULL
, MEMLIMIT
),
1539 assert_lzma_ret(lzma_index_decoder(&strm
, NULL
, MEMLIMIT
),
1542 // If the first argument (lzma_stream *strm) is NULL then
1543 // *idx must still become NULL since the API docs say that
1544 // it's done if an error occurs. This was fixed in
1545 // 71eed2520e2eecae89bade9dceea16e56cfa2ea0.
1546 lzma_index
*idx_allocated
= lzma_index_init(NULL
);
1547 lzma_index
*idx
= idx_allocated
;
1548 assert_lzma_ret(lzma_index_decoder(NULL
, &idx
, MEMLIMIT
),
1550 assert_true(idx
== NULL
);
1552 lzma_index_end(idx_allocated
, NULL
);
1553 idx_allocated
= NULL
;
1556 assert_lzma_ret(lzma_index_decoder(&strm
, &idx
, MEMLIMIT
),
1559 decode_index(decode_buffer
, decode_buffer_size
, &strm
,
1562 // Compare results with expected
1563 assert_true(index_is_equal(decode_test_index
, idx
));
1565 lzma_index_end(idx
, NULL
);
1567 // Test again with too low memory limit
1568 assert_lzma_ret(lzma_index_decoder(&strm
, &idx
, 0), LZMA_OK
);
1570 decode_index(decode_buffer
, decode_buffer_size
, &strm
,
1571 LZMA_MEMLIMIT_ERROR
);
1573 uint8_t *corrupt_buffer
= tuktest_malloc(decode_buffer_size
);
1574 memcpy(corrupt_buffer
, decode_buffer
, decode_buffer_size
);
1576 assert_lzma_ret(lzma_index_decoder(&strm
, &idx
, MEMLIMIT
),
1579 // First corrupt the Index Indicator
1580 corrupt_buffer
[0] ^= 1;
1581 decode_index(corrupt_buffer
, decode_buffer_size
, &strm
,
1583 corrupt_buffer
[0] ^= 1;
1585 // Corrupt something in the middle of Index
1586 corrupt_buffer
[decode_buffer_size
/ 2] ^= 1;
1587 assert_lzma_ret(lzma_index_decoder(&strm
, &idx
, MEMLIMIT
),
1589 decode_index(corrupt_buffer
, decode_buffer_size
, &strm
,
1591 corrupt_buffer
[decode_buffer_size
/ 2] ^= 1;
1594 corrupt_buffer
[decode_buffer_size
- 1] ^= 1;
1595 assert_lzma_ret(lzma_index_decoder(&strm
, &idx
, MEMLIMIT
),
1597 decode_index(corrupt_buffer
, decode_buffer_size
, &strm
,
1599 corrupt_buffer
[decode_buffer_size
- 1] ^= 1;
1601 // Corrupt Index Padding by setting it to non-zero
1602 corrupt_buffer
[decode_buffer_size
- 5] ^= 1;
1603 assert_lzma_ret(lzma_index_decoder(&strm
, &idx
, MEMLIMIT
),
1605 decode_index(corrupt_buffer
, decode_buffer_size
, &strm
,
1607 corrupt_buffer
[decode_buffer_size
- 1] ^= 1;
1615 test_lzma_index_buffer_encode(void)
1617 #if !defined(HAVE_ENCODERS) || !defined(HAVE_DECODERS)
1618 assert_skip("Encoder or decoder support disabled");
1620 // These are simpler test than in test_lzma_index_encoder()
1621 // because lzma_index_buffer_encode() is mostly a wrapper
1622 // around lzma_index_encoder() anyway.
1623 lzma_index
*idx
= lzma_index_init(NULL
);
1624 assert_true(idx
!= NULL
);
1626 assert_lzma_ret(lzma_index_append(idx
, NULL
,
1627 UNPADDED_SIZE_MIN
, 10), LZMA_OK
);
1628 assert_lzma_ret(lzma_index_append(idx
, NULL
,
1629 UNPADDED_SIZE_MIN
* 2, 100), LZMA_OK
);
1630 assert_lzma_ret(lzma_index_append(idx
, NULL
,
1631 UNPADDED_SIZE_MIN
* 3, 1000), LZMA_OK
);
1633 size_t buffer_size
= get_index_size(idx
);
1634 uint8_t *buffer
= tuktest_malloc(buffer_size
);
1637 // First test bad arguments
1638 assert_lzma_ret(lzma_index_buffer_encode(NULL
, NULL
, NULL
, 0),
1640 assert_lzma_ret(lzma_index_buffer_encode(idx
, NULL
, NULL
, 0),
1642 assert_lzma_ret(lzma_index_buffer_encode(idx
, buffer
, NULL
, 0),
1644 assert_lzma_ret(lzma_index_buffer_encode(idx
, buffer
, &out_pos
,
1645 0), LZMA_PROG_ERROR
);
1647 assert_lzma_ret(lzma_index_buffer_encode(idx
, buffer
, &out_pos
,
1648 0), LZMA_BUF_ERROR
);
1649 assert_uint_eq(out_pos
, 0);
1650 assert_lzma_ret(lzma_index_buffer_encode(idx
, buffer
, &out_pos
,
1651 1), LZMA_BUF_ERROR
);
1654 assert_lzma_ret(lzma_index_buffer_encode(idx
, buffer
, &out_pos
,
1655 buffer_size
), LZMA_OK
);
1656 assert_uint_eq(out_pos
, buffer_size
);
1659 verify_index_buffer(idx
, buffer
, buffer_size
);
1661 lzma_index_end(idx
, NULL
);
1667 test_lzma_index_buffer_decode(void)
1669 #if !defined(HAVE_ENCODERS) || !defined(HAVE_DECODERS)
1670 assert_skip("Encoder or decoder support disabled");
1672 assert_true(decode_buffer_size
!= 0);
1674 // Simple test since test_lzma_index_decoder() covers most of the
1675 // lzma_index_buffer_decode() code anyway.
1677 // First test NULL checks
1678 assert_lzma_ret(lzma_index_buffer_decode(NULL
, NULL
, NULL
, NULL
,
1679 NULL
, 0), LZMA_PROG_ERROR
);
1681 uint64_t memlimit
= MEMLIMIT
;
1683 lzma_index
*idx_allocated
= lzma_index_init(NULL
);
1684 lzma_index
*idx
= idx_allocated
;
1686 assert_lzma_ret(lzma_index_buffer_decode(&idx
, NULL
, NULL
, NULL
,
1687 NULL
, 0), LZMA_PROG_ERROR
);
1688 assert_true(idx
== NULL
);
1690 idx
= idx_allocated
;
1691 assert_lzma_ret(lzma_index_buffer_decode(&idx
, &memlimit
, NULL
,
1692 NULL
, NULL
, 0), LZMA_PROG_ERROR
);
1693 assert_true(idx
== NULL
);
1695 idx
= idx_allocated
;
1696 assert_lzma_ret(lzma_index_buffer_decode(&idx
, &memlimit
, NULL
,
1697 decode_buffer
, NULL
, 0), LZMA_PROG_ERROR
);
1698 assert_true(idx
== NULL
);
1700 idx
= idx_allocated
;
1701 assert_lzma_ret(lzma_index_buffer_decode(&idx
, &memlimit
, NULL
,
1702 decode_buffer
, NULL
, 0), LZMA_PROG_ERROR
);
1703 assert_true(idx
== NULL
);
1705 idx
= idx_allocated
;
1706 assert_lzma_ret(lzma_index_buffer_decode(&idx
, &memlimit
, NULL
,
1707 decode_buffer
, &in_pos
, 0), LZMA_DATA_ERROR
);
1708 assert_true(idx
== NULL
);
1711 idx
= idx_allocated
;
1712 assert_lzma_ret(lzma_index_buffer_decode(&idx
, &memlimit
, NULL
,
1713 decode_buffer
, &in_pos
, 0), LZMA_PROG_ERROR
);
1714 assert_true(idx
== NULL
);
1716 // Test too short input
1718 idx
= idx_allocated
;
1719 assert_lzma_ret(lzma_index_buffer_decode(&idx
, &memlimit
, NULL
,
1720 decode_buffer
, &in_pos
, decode_buffer_size
- 1),
1722 assert_true(idx
== NULL
);
1724 lzma_index_end(idx_allocated
, NULL
);
1725 idx_allocated
= NULL
;
1727 // Test expected successful decode
1729 assert_lzma_ret(lzma_index_buffer_decode(&idx
, &memlimit
, NULL
,
1730 decode_buffer
, &in_pos
, decode_buffer_size
), LZMA_OK
);
1732 assert_uint_eq(in_pos
, decode_buffer_size
);
1733 assert_true(index_is_equal(decode_test_index
, idx
));
1735 lzma_index_end(idx
, NULL
);
1737 // Test too much input. This won't read past
1738 // the end of the allocated array (decode_buffer_size bytes).
1740 assert_lzma_ret(lzma_index_buffer_decode(&idx
, &memlimit
, NULL
,
1741 decode_buffer
, &in_pos
, decode_buffer_size
+ 16),
1744 assert_uint_eq(in_pos
, decode_buffer_size
);
1745 assert_true(index_is_equal(decode_test_index
, idx
));
1747 lzma_index_end(idx
, NULL
);
1749 // Test too small memlimit
1752 assert_lzma_ret(lzma_index_buffer_decode(&idx
, &memlimit
, NULL
,
1753 decode_buffer
, &in_pos
, decode_buffer_size
),
1754 LZMA_MEMLIMIT_ERROR
);
1755 assert_uint(memlimit
, >, 1);
1756 assert_uint(memlimit
, <, MEMLIMIT
);
1762 main(int argc
, char **argv
)
1764 tuktest_start(argc
, argv
);
1765 generate_index_decode_buffer();
1766 tuktest_run(test_lzma_index_memusage
);
1767 tuktest_run(test_lzma_index_memused
);
1768 tuktest_run(test_lzma_index_append
);
1769 tuktest_run(test_lzma_index_stream_flags
);
1770 tuktest_run(test_lzma_index_checks
);
1771 tuktest_run(test_lzma_index_stream_padding
);
1772 tuktest_run(test_lzma_index_stream_count
);
1773 tuktest_run(test_lzma_index_block_count
);
1774 tuktest_run(test_lzma_index_size
);
1775 tuktest_run(test_lzma_index_stream_size
);
1776 tuktest_run(test_lzma_index_total_size
);
1777 tuktest_run(test_lzma_index_file_size
);
1778 tuktest_run(test_lzma_index_uncompressed_size
);
1779 tuktest_run(test_lzma_index_iter_init
);
1780 tuktest_run(test_lzma_index_iter_rewind
);
1781 tuktest_run(test_lzma_index_iter_next
);
1782 tuktest_run(test_lzma_index_iter_locate
);
1783 tuktest_run(test_lzma_index_cat
);
1784 tuktest_run(test_lzma_index_dup
);
1785 tuktest_run(test_lzma_index_encoder
);
1786 tuktest_run(test_lzma_index_decoder
);
1787 tuktest_run(test_lzma_index_buffer_encode
);
1788 tuktest_run(test_lzma_index_buffer_decode
);
1789 lzma_index_end(decode_test_index
, NULL
);
1790 return tuktest_end();