2 * Copyright (c) 2018 Grzegorz Antoniak
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 /* Some tests will want to calculate some CRC32's, and this header can
29 #define __LIBARCHIVE_BUILD
30 #include <archive_crc32.h>
32 #define PROLOGUE(reffile) \
33 struct archive_entry *ae; \
36 (void) a; /* Make the compiler happy if we won't use this variables */ \
37 (void) ae; /* in the test cases. */ \
39 extract_reference_file(reffile); \
40 assert((a = archive_read_new()) != NULL); \
41 assertA(0 == archive_read_support_filter_all(a)); \
42 assertA(0 == archive_read_support_format_all(a)); \
43 assertA(0 == archive_read_open_filename(a, reffile, 10240))
45 #define PROLOGUE_MULTI(reffile) \
46 struct archive_entry *ae; \
52 extract_reference_files(reffile); \
53 assert((a = archive_read_new()) != NULL); \
54 assertA(0 == archive_read_support_filter_all(a)); \
55 assertA(0 == archive_read_support_format_all(a)); \
56 assertA(0 == archive_read_open_filenames(a, reffile, 10240))
60 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); \
61 assertEqualInt(ARCHIVE_OK, archive_read_free(a))
64 int verify_data(const uint8_t* data_ptr, int magic, int size) {
67 /* This is how the test data inside test files was generated;
68 * we are re-generating it here and we check if our re-generated
69 * test data is the same as in the test file. If this test is
70 * failing it's either because there's a bug in the test case,
71 * or the unpacked data is corrupted. */
73 for(i = 0; i < size / 4; ++i) {
75 const signed int* lptr = (const signed int*) &data_ptr[i * 4];
76 signed int val = k * k - 3 * k + (1 + magic);
81 /* *lptr is a value inside unpacked test file, val is the
82 * value that should be in the unpacked test file. */
92 int extract_one(struct archive* a, struct archive_entry* ae, uint32_t crc) {
93 la_ssize_t fsize, bytes_read;
96 uint32_t computed_crc;
98 fsize = archive_entry_size(ae);
103 bytes_read = archive_read_data(a, buf, fsize);
104 if(bytes_read != fsize) {
105 assertEqualInt(bytes_read, fsize);
109 computed_crc = crc32(0, buf, fsize);
110 assertEqualInt(computed_crc, crc);
118 DEFINE_TEST(test_read_format_rar5_stored)
120 const char helloworld_txt[] = "hello libarchive test suite!\n";
121 la_ssize_t file_size = sizeof(helloworld_txt) - 1;
124 PROLOGUE("test_read_format_rar5_stored.rar");
126 assertA(0 == archive_read_next_header(a, &ae));
127 assertEqualString("helloworld.txt", archive_entry_pathname(ae));
128 assertA((int) archive_entry_mtime(ae) > 0);
129 assertA((int) archive_entry_ctime(ae) == 0);
130 assertA((int) archive_entry_atime(ae) == 0);
131 assertEqualInt(file_size, archive_entry_size(ae));
132 assertEqualInt(33188, archive_entry_mode(ae));
133 assertA(file_size == archive_read_data(a, buff, file_size));
134 assertEqualMem(buff, helloworld_txt, file_size);
135 assertEqualInt(archive_entry_is_encrypted(ae), 0);
137 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
142 DEFINE_TEST(test_read_format_rar5_compressed)
144 const int DATA_SIZE = 1200;
145 uint8_t buff[DATA_SIZE];
147 PROLOGUE("test_read_format_rar5_compressed.rar");
149 assertA(0 == archive_read_next_header(a, &ae));
150 assertEqualString("test.bin", archive_entry_pathname(ae));
151 assertA((int) archive_entry_mtime(ae) > 0);
152 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
153 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
154 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
155 verify_data(buff, 0, DATA_SIZE);
160 DEFINE_TEST(test_read_format_rar5_multiple_files)
162 const int DATA_SIZE = 4096;
163 uint8_t buff[DATA_SIZE];
165 PROLOGUE("test_read_format_rar5_multiple_files.rar");
167 /* There should be 4 files inside this test file. Check for their
168 * existence, and also check the contents of those test files. */
170 assertA(0 == archive_read_next_header(a, &ae));
171 assertEqualString("test1.bin", archive_entry_pathname(ae));
172 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
173 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
174 assertA(verify_data(buff, 1, DATA_SIZE));
176 assertA(0 == archive_read_next_header(a, &ae));
177 assertEqualString("test2.bin", archive_entry_pathname(ae));
178 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
179 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
180 assertA(verify_data(buff, 2, DATA_SIZE));
182 assertA(0 == archive_read_next_header(a, &ae));
183 assertEqualString("test3.bin", archive_entry_pathname(ae));
184 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
185 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
186 assertA(verify_data(buff, 3, DATA_SIZE));
188 assertA(0 == archive_read_next_header(a, &ae));
189 assertEqualString("test4.bin", archive_entry_pathname(ae));
190 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
191 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
192 assertA(verify_data(buff, 4, DATA_SIZE));
194 /* There should be no more files in this archive. */
196 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
200 /* This test is really the same as the test above, but it deals with a solid
201 * archive instead of a regular archive. The test solid archive contains the
202 * same set of files as regular test archive, but it's size is 2x smaller,
203 * because solid archives reuse the window buffer from previous compressed
204 * files, so it's able to compress lots of small files more effectively. */
206 DEFINE_TEST(test_read_format_rar5_multiple_files_solid)
208 const int DATA_SIZE = 4096;
209 uint8_t buff[DATA_SIZE];
211 PROLOGUE("test_read_format_rar5_multiple_files_solid.rar");
213 assertA(0 == archive_read_next_header(a, &ae));
214 assertEqualString("test1.bin", archive_entry_pathname(ae));
215 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
216 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
217 assertA(verify_data(buff, 1, DATA_SIZE));
219 assertA(0 == archive_read_next_header(a, &ae));
220 assertEqualString("test2.bin", archive_entry_pathname(ae));
221 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
222 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
223 assertA(verify_data(buff, 2, DATA_SIZE));
225 assertA(0 == archive_read_next_header(a, &ae));
226 assertEqualString("test3.bin", archive_entry_pathname(ae));
227 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
228 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
229 assertA(verify_data(buff, 3, DATA_SIZE));
231 assertA(0 == archive_read_next_header(a, &ae));
232 assertEqualString("test4.bin", archive_entry_pathname(ae));
233 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
234 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
235 assertA(verify_data(buff, 4, DATA_SIZE));
237 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
241 DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all)
243 const char* reffiles[] = {
244 "test_read_format_rar5_multiarchive.part01.rar",
245 "test_read_format_rar5_multiarchive.part02.rar",
246 "test_read_format_rar5_multiarchive.part03.rar",
247 "test_read_format_rar5_multiarchive.part04.rar",
248 "test_read_format_rar5_multiarchive.part05.rar",
249 "test_read_format_rar5_multiarchive.part06.rar",
250 "test_read_format_rar5_multiarchive.part07.rar",
251 "test_read_format_rar5_multiarchive.part08.rar",
255 PROLOGUE_MULTI(reffiles);
256 assertA(0 == archive_read_next_header(a, &ae));
257 assertEqualString("home/antek/temp/build/unrar5/libarchive/bin/bsdcat_test", archive_entry_pathname(ae));
258 assertA(0 == archive_read_next_header(a, &ae));
259 assertEqualString("home/antek/temp/build/unrar5/libarchive/bin/bsdtar_test", archive_entry_pathname(ae));
260 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
264 DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all_but_first)
266 const char* reffiles[] = {
267 "test_read_format_rar5_multiarchive.part01.rar",
268 "test_read_format_rar5_multiarchive.part02.rar",
269 "test_read_format_rar5_multiarchive.part03.rar",
270 "test_read_format_rar5_multiarchive.part04.rar",
271 "test_read_format_rar5_multiarchive.part05.rar",
272 "test_read_format_rar5_multiarchive.part06.rar",
273 "test_read_format_rar5_multiarchive.part07.rar",
274 "test_read_format_rar5_multiarchive.part08.rar",
278 PROLOGUE_MULTI(reffiles);
279 assertA(0 == archive_read_next_header(a, &ae));
280 assertA(0 == extract_one(a, ae, 0x35277473));
281 assertA(0 == archive_read_next_header(a, &ae));
282 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
286 DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all_but_second)
288 const char* reffiles[] = {
289 "test_read_format_rar5_multiarchive.part01.rar",
290 "test_read_format_rar5_multiarchive.part02.rar",
291 "test_read_format_rar5_multiarchive.part03.rar",
292 "test_read_format_rar5_multiarchive.part04.rar",
293 "test_read_format_rar5_multiarchive.part05.rar",
294 "test_read_format_rar5_multiarchive.part06.rar",
295 "test_read_format_rar5_multiarchive.part07.rar",
296 "test_read_format_rar5_multiarchive.part08.rar",
300 PROLOGUE_MULTI(reffiles);
301 assertA(0 == archive_read_next_header(a, &ae));
302 assertA(0 == archive_read_next_header(a, &ae));
303 assertA(0 == extract_one(a, ae, 0xE59665F8));
304 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
308 DEFINE_TEST(test_read_format_rar5_blake2)
310 const la_ssize_t proper_size = 814;
311 uint8_t buf[proper_size];
313 PROLOGUE("test_read_format_rar5_blake2.rar");
314 assertA(0 == archive_read_next_header(a, &ae));
315 assertEqualInt(proper_size, archive_entry_size(ae));
317 /* Should blake2 calculation fail, we'll get a failure return
318 * value from archive_read_data(). */
320 assertA(proper_size == archive_read_data(a, buf, proper_size));
322 /* To be extra pedantic, let's also check crc32 of the poem. */
323 assertEqualInt(crc32(0, buf, proper_size), 0x7E5EC49E);
325 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
329 DEFINE_TEST(test_read_format_rar5_arm_filter)
331 /* This test unpacks a file that uses an ARM filter. The DELTA
332 * and X86 filters are tested implicitly in the "multiarchive_skip"
335 const la_ssize_t proper_size = 90808;
336 uint8_t buf[proper_size];
338 PROLOGUE("test_read_format_rar5_arm.rar");
339 assertA(0 == archive_read_next_header(a, &ae));
340 assertEqualInt(proper_size, archive_entry_size(ae));
341 assertA(proper_size == archive_read_data(a, buf, proper_size));
343 /* Yes, RARv5 unpacker itself should calculate the CRC, but in case
344 * the DONT_FAIL_ON_CRC_ERROR define option is enabled during compilation,
345 * let's still fail the test if the unpacked data is wrong. */
346 assertEqualInt(crc32(0, buf, proper_size), 0x886F91EB);
348 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
352 DEFINE_TEST(test_read_format_rar5_stored_skip_all)
354 const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
357 assertA(0 == archive_read_next_header(a, &ae));
358 assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
359 assertA(0 == archive_read_next_header(a, &ae));
360 assertEqualString("cebula.txt", archive_entry_pathname(ae));
361 assertA(0 == archive_read_next_header(a, &ae));
362 assertEqualString("test.bin", archive_entry_pathname(ae));
363 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
367 DEFINE_TEST(test_read_format_rar5_stored_skip_in_part)
369 const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
372 /* Skip first, extract in part rest. */
375 assertA(0 == archive_read_next_header(a, &ae));
376 assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
377 assertA(0 == archive_read_next_header(a, &ae));
378 assertEqualString("cebula.txt", archive_entry_pathname(ae));
379 assertA(6 == archive_read_data(a, buf, 6));
380 assertEqualInt(0, memcmp(buf, "Cebula", 6));
381 assertA(0 == archive_read_next_header(a, &ae));
382 assertEqualString("test.bin", archive_entry_pathname(ae));
383 assertA(4 == archive_read_data(a, buf, 4));
384 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
388 DEFINE_TEST(test_read_format_rar5_stored_skip_all_but_first)
390 const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
393 /* Extract first, skip rest. */
396 assertA(0 == archive_read_next_header(a, &ae));
397 assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
398 assertA(405 == archive_read_data(a, buf, sizeof(buf)));
399 assertA(0 == archive_read_next_header(a, &ae));
400 assertEqualString("cebula.txt", archive_entry_pathname(ae));
401 assertA(0 == archive_read_next_header(a, &ae));
402 assertEqualString("test.bin", archive_entry_pathname(ae));
403 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
407 DEFINE_TEST(test_read_format_rar5_stored_skip_all_in_part)
409 const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
412 /* Extract in part all */
415 assertA(0 == archive_read_next_header(a, &ae));
416 assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
417 assertA(4 == archive_read_data(a, buf, 4));
418 assertA(0 == archive_read_next_header(a, &ae));
419 assertEqualString("cebula.txt", archive_entry_pathname(ae));
420 assertA(4 == archive_read_data(a, buf, 4));
421 assertA(0 == archive_read_next_header(a, &ae));
422 assertEqualString("test.bin", archive_entry_pathname(ae));
423 assertA(4 == archive_read_data(a, buf, 4));
424 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
428 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all)
430 const char* reffiles[] = {
431 "test_read_format_rar5_multiarchive_solid.part01.rar",
432 "test_read_format_rar5_multiarchive_solid.part02.rar",
433 "test_read_format_rar5_multiarchive_solid.part03.rar",
434 "test_read_format_rar5_multiarchive_solid.part04.rar",
438 PROLOGUE_MULTI(reffiles);
439 assertA(0 == archive_read_next_header(a, &ae));
440 assertEqualString("cebula.txt", archive_entry_pathname(ae));
441 assertA(0 == archive_read_next_header(a, &ae));
442 assertEqualString("test.bin", archive_entry_pathname(ae));
443 assertA(0 == archive_read_next_header(a, &ae));
444 assertEqualString("test1.bin", archive_entry_pathname(ae));
445 assertA(0 == archive_read_next_header(a, &ae));
446 assertEqualString("test2.bin", archive_entry_pathname(ae));
447 assertA(0 == archive_read_next_header(a, &ae));
448 assertEqualString("test3.bin", archive_entry_pathname(ae));
449 assertA(0 == archive_read_next_header(a, &ae));
450 assertEqualString("test4.bin", archive_entry_pathname(ae));
451 assertA(0 == archive_read_next_header(a, &ae));
452 assertEqualString("test5.bin", archive_entry_pathname(ae));
453 assertA(0 == archive_read_next_header(a, &ae));
454 assertEqualString("test6.bin", archive_entry_pathname(ae));
455 assertA(0 == archive_read_next_header(a, &ae));
456 assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
457 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
461 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_first)
463 const char* reffiles[] = {
464 "test_read_format_rar5_multiarchive_solid.part01.rar",
465 "test_read_format_rar5_multiarchive_solid.part02.rar",
466 "test_read_format_rar5_multiarchive_solid.part03.rar",
467 "test_read_format_rar5_multiarchive_solid.part04.rar",
471 PROLOGUE_MULTI(reffiles);
472 assertA(0 == archive_read_next_header(a, &ae));
473 assertEqualString("cebula.txt", archive_entry_pathname(ae));
474 assertA(0 == extract_one(a, ae, 0x7E5EC49E));
475 assertA(0 == archive_read_next_header(a, &ae));
476 assertEqualString("test.bin", archive_entry_pathname(ae));
477 assertA(0 == archive_read_next_header(a, &ae));
478 assertEqualString("test1.bin", archive_entry_pathname(ae));
479 assertA(0 == archive_read_next_header(a, &ae));
480 assertEqualString("test2.bin", archive_entry_pathname(ae));
481 assertA(0 == archive_read_next_header(a, &ae));
482 assertEqualString("test3.bin", archive_entry_pathname(ae));
483 assertA(0 == archive_read_next_header(a, &ae));
484 assertEqualString("test4.bin", archive_entry_pathname(ae));
485 assertA(0 == archive_read_next_header(a, &ae));
486 assertEqualString("test5.bin", archive_entry_pathname(ae));
487 assertA(0 == archive_read_next_header(a, &ae));
488 assertEqualString("test6.bin", archive_entry_pathname(ae));
489 assertA(0 == archive_read_next_header(a, &ae));
490 assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
491 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
495 /* "skip_all_but_scnd" -> am I hitting the test name limit here after
496 * expansion of "scnd" to "second"? */
498 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_scnd)
500 const char* reffiles[] = {
501 "test_read_format_rar5_multiarchive_solid.part01.rar",
502 "test_read_format_rar5_multiarchive_solid.part02.rar",
503 "test_read_format_rar5_multiarchive_solid.part03.rar",
504 "test_read_format_rar5_multiarchive_solid.part04.rar",
508 PROLOGUE_MULTI(reffiles);
509 assertA(0 == archive_read_next_header(a, &ae));
510 assertEqualString("cebula.txt", archive_entry_pathname(ae));
511 assertA(0 == archive_read_next_header(a, &ae));
512 assertEqualString("test.bin", archive_entry_pathname(ae));
513 assertA(0 == extract_one(a, ae, 0x7CCA70CD));
514 assertA(0 == archive_read_next_header(a, &ae));
515 assertEqualString("test1.bin", archive_entry_pathname(ae));
516 assertA(0 == archive_read_next_header(a, &ae));
517 assertEqualString("test2.bin", archive_entry_pathname(ae));
518 assertA(0 == archive_read_next_header(a, &ae));
519 assertEqualString("test3.bin", archive_entry_pathname(ae));
520 assertA(0 == archive_read_next_header(a, &ae));
521 assertEqualString("test4.bin", archive_entry_pathname(ae));
522 assertA(0 == archive_read_next_header(a, &ae));
523 assertEqualString("test5.bin", archive_entry_pathname(ae));
524 assertA(0 == archive_read_next_header(a, &ae));
525 assertEqualString("test6.bin", archive_entry_pathname(ae));
526 assertA(0 == archive_read_next_header(a, &ae));
527 assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
528 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
532 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_third)
534 const char* reffiles[] = {
535 "test_read_format_rar5_multiarchive_solid.part01.rar",
536 "test_read_format_rar5_multiarchive_solid.part02.rar",
537 "test_read_format_rar5_multiarchive_solid.part03.rar",
538 "test_read_format_rar5_multiarchive_solid.part04.rar",
542 PROLOGUE_MULTI(reffiles);
543 assertA(0 == archive_read_next_header(a, &ae));
544 assertEqualString("cebula.txt", archive_entry_pathname(ae));
545 assertA(0 == archive_read_next_header(a, &ae));
546 assertEqualString("test.bin", archive_entry_pathname(ae));
547 assertA(0 == archive_read_next_header(a, &ae));
548 assertEqualString("test1.bin", archive_entry_pathname(ae));
549 assertA(0 == extract_one(a, ae, 0x7E13B2C6));
550 assertA(0 == archive_read_next_header(a, &ae));
551 assertEqualString("test2.bin", archive_entry_pathname(ae));
552 assertA(0 == archive_read_next_header(a, &ae));
553 assertEqualString("test3.bin", archive_entry_pathname(ae));
554 assertA(0 == archive_read_next_header(a, &ae));
555 assertEqualString("test4.bin", archive_entry_pathname(ae));
556 assertA(0 == archive_read_next_header(a, &ae));
557 assertEqualString("test5.bin", archive_entry_pathname(ae));
558 assertA(0 == archive_read_next_header(a, &ae));
559 assertEqualString("test6.bin", archive_entry_pathname(ae));
560 assertA(0 == archive_read_next_header(a, &ae));
561 assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
562 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
566 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_last)
568 const char* reffiles[] = {
569 "test_read_format_rar5_multiarchive_solid.part01.rar",
570 "test_read_format_rar5_multiarchive_solid.part02.rar",
571 "test_read_format_rar5_multiarchive_solid.part03.rar",
572 "test_read_format_rar5_multiarchive_solid.part04.rar",
576 PROLOGUE_MULTI(reffiles);
577 assertA(0 == archive_read_next_header(a, &ae));
578 assertEqualString("cebula.txt", archive_entry_pathname(ae));
579 assertA(0 == archive_read_next_header(a, &ae));
580 assertEqualString("test.bin", archive_entry_pathname(ae));
581 assertA(0 == archive_read_next_header(a, &ae));
582 assertEqualString("test1.bin", archive_entry_pathname(ae));
583 assertA(0 == archive_read_next_header(a, &ae));
584 assertEqualString("test2.bin", archive_entry_pathname(ae));
585 assertA(0 == archive_read_next_header(a, &ae));
586 assertEqualString("test3.bin", archive_entry_pathname(ae));
587 assertA(0 == archive_read_next_header(a, &ae));
588 assertEqualString("test4.bin", archive_entry_pathname(ae));
589 assertA(0 == archive_read_next_header(a, &ae));
590 assertEqualString("test5.bin", archive_entry_pathname(ae));
591 assertA(0 == archive_read_next_header(a, &ae));
592 assertEqualString("test6.bin", archive_entry_pathname(ae));
593 assertA(0 == archive_read_next_header(a, &ae));
594 assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
595 assertA(0 == extract_one(a, ae, 0x886F91EB));
596 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
600 DEFINE_TEST(test_read_format_rar5_solid_skip_all)
602 const char* reffile = "test_read_format_rar5_solid.rar";
607 assertA(0 == archive_read_next_header(a, &ae));
608 assertEqualString("test.bin", archive_entry_pathname(ae));
609 assertA(0 == archive_read_next_header(a, &ae));
610 assertEqualString("test1.bin", archive_entry_pathname(ae));
611 assertA(0 == archive_read_next_header(a, &ae));
612 assertEqualString("test2.bin", archive_entry_pathname(ae));
613 assertA(0 == archive_read_next_header(a, &ae));
614 assertEqualString("test3.bin", archive_entry_pathname(ae));
615 assertA(0 == archive_read_next_header(a, &ae));
616 assertEqualString("test4.bin", archive_entry_pathname(ae));
617 assertA(0 == archive_read_next_header(a, &ae));
618 assertEqualString("test5.bin", archive_entry_pathname(ae));
619 assertA(0 == archive_read_next_header(a, &ae));
620 assertEqualString("test6.bin", archive_entry_pathname(ae));
621 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
625 DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_first)
627 const char* reffile = "test_read_format_rar5_solid.rar";
629 /* Extract first, skip rest */
632 assertA(0 == archive_read_next_header(a, &ae));
633 assertEqualString("test.bin", archive_entry_pathname(ae));
634 assertA(0 == extract_one(a, ae, 0x7CCA70CD));
635 assertA(0 == archive_read_next_header(a, &ae));
636 assertEqualString("test1.bin", archive_entry_pathname(ae));
637 assertA(0 == archive_read_next_header(a, &ae));
638 assertEqualString("test2.bin", archive_entry_pathname(ae));
639 assertA(0 == archive_read_next_header(a, &ae));
640 assertEqualString("test3.bin", archive_entry_pathname(ae));
641 assertA(0 == archive_read_next_header(a, &ae));
642 assertEqualString("test4.bin", archive_entry_pathname(ae));
643 assertA(0 == archive_read_next_header(a, &ae));
644 assertEqualString("test5.bin", archive_entry_pathname(ae));
645 assertA(0 == archive_read_next_header(a, &ae));
646 assertEqualString("test6.bin", archive_entry_pathname(ae));
647 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
651 DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_second)
653 const char* reffile = "test_read_format_rar5_solid.rar";
655 /* Skip first, extract second, skip rest */
658 assertA(0 == archive_read_next_header(a, &ae));
659 assertEqualString("test.bin", archive_entry_pathname(ae));
660 assertA(0 == archive_read_next_header(a, &ae));
661 assertEqualString("test1.bin", archive_entry_pathname(ae));
662 assertA(0 == extract_one(a, ae, 0x7E13B2C6));
663 assertA(0 == archive_read_next_header(a, &ae));
664 assertEqualString("test2.bin", archive_entry_pathname(ae));
665 assertA(0 == archive_read_next_header(a, &ae));
666 assertEqualString("test3.bin", archive_entry_pathname(ae));
667 assertA(0 == archive_read_next_header(a, &ae));
668 assertEqualString("test4.bin", archive_entry_pathname(ae));
669 assertA(0 == archive_read_next_header(a, &ae));
670 assertEqualString("test5.bin", archive_entry_pathname(ae));
671 assertA(0 == archive_read_next_header(a, &ae));
672 assertEqualString("test6.bin", archive_entry_pathname(ae));
673 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
677 DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_last)
679 const char* reffile = "test_read_format_rar5_solid.rar";
681 /* Skip all but last, extract last */
684 assertA(0 == archive_read_next_header(a, &ae));
685 assertEqualString("test.bin", archive_entry_pathname(ae));
686 assertA(0 == archive_read_next_header(a, &ae));
687 assertEqualString("test1.bin", archive_entry_pathname(ae));
688 assertA(0 == archive_read_next_header(a, &ae));
689 assertEqualString("test2.bin", archive_entry_pathname(ae));
690 assertA(0 == archive_read_next_header(a, &ae));
691 assertEqualString("test3.bin", archive_entry_pathname(ae));
692 assertA(0 == archive_read_next_header(a, &ae));
693 assertEqualString("test4.bin", archive_entry_pathname(ae));
694 assertA(0 == archive_read_next_header(a, &ae));
695 assertEqualString("test5.bin", archive_entry_pathname(ae));
696 assertA(0 == archive_read_next_header(a, &ae));
697 assertEqualString("test6.bin", archive_entry_pathname(ae));
698 assertA(0 == extract_one(a, ae, 0x36A448FF));
699 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
703 DEFINE_TEST(test_read_format_rar5_extract_win32)
705 PROLOGUE("test_read_format_rar5_win32.rar");
706 assertA(0 == archive_read_next_header(a, &ae));
707 assertEqualString("test.bin", archive_entry_pathname(ae));
708 assertA(0 == extract_one(a, ae, 0x7CCA70CD));
709 assertA(0 == archive_read_next_header(a, &ae));
710 assertEqualString("test1.bin", archive_entry_pathname(ae));
711 assertA(0 == extract_one(a, ae, 0x7E13B2C6));
712 assertA(0 == archive_read_next_header(a, &ae));
713 assertEqualString("test2.bin", archive_entry_pathname(ae));
714 assertA(0 == extract_one(a, ae, 0xF166AFCB));
715 assertA(0 == archive_read_next_header(a, &ae));
716 assertEqualString("test3.bin", archive_entry_pathname(ae));
717 assertA(0 == extract_one(a, ae, 0x9FB123D9));
718 assertA(0 == archive_read_next_header(a, &ae));
719 assertEqualString("test4.bin", archive_entry_pathname(ae));
720 assertA(0 == extract_one(a, ae, 0x10C43ED4));
721 assertA(0 == archive_read_next_header(a, &ae));
722 assertEqualString("test5.bin", archive_entry_pathname(ae));
723 assertA(0 == extract_one(a, ae, 0xB9D155F2));
724 assertA(0 == archive_read_next_header(a, &ae));
725 assertEqualString("test6.bin", archive_entry_pathname(ae));
726 assertA(0 == extract_one(a, ae, 0x36A448FF));
730 DEFINE_TEST(test_read_format_rar5_block_by_block)
732 /* This test uses strange buffer sizes intentionally. */
734 struct archive_entry *ae;
738 uint32_t computed_crc = 0;
740 extract_reference_file("test_read_format_rar5_compressed.rar");
741 assert((a = archive_read_new()) != NULL);
742 assertA(0 == archive_read_support_filter_all(a));
743 assertA(0 == archive_read_support_format_all(a));
744 assertA(0 == archive_read_open_filename(a, "test_read_format_rar5_compressed.rar", 130));
745 assertA(0 == archive_read_next_header(a, &ae));
746 assertEqualString("test.bin", archive_entry_pathname(ae));
747 assertEqualInt(1200, archive_entry_size(ae));
749 /* File size is 1200 bytes, we're reading it using a buffer of 173 bytes.
750 * Libarchive is configured to use a buffer of 130 bytes. */
753 /* archive_read_data should return one of:
754 * a) 0, if there is no more data to be read,
755 * b) negative value, if there was an error,
756 * c) positive value, meaning how many bytes were read.
759 bytes_read = archive_read_data(a, buf, sizeof(buf));
760 assertA(bytes_read >= 0);
764 computed_crc = crc32(computed_crc, buf, bytes_read);
767 assertEqualInt(computed_crc, 0x7CCA70CD);