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>
31 #include <archive_endian.h>
33 #define PROLOGUE(reffile) \
34 struct archive_entry *ae; \
37 (void) a; /* Make the compiler happy if we won't use this variables */ \
38 (void) ae; /* in the test cases. */ \
40 extract_reference_file(reffile); \
41 assert((a = archive_read_new()) != NULL); \
42 assertA(0 == archive_read_support_filter_all(a)); \
43 assertA(0 == archive_read_support_format_all(a)); \
44 assertA(0 == archive_read_open_filename(a, reffile, 10240))
46 #define PROLOGUE_MULTI(reffile) \
47 struct archive_entry *ae; \
53 extract_reference_files(reffile); \
54 assert((a = archive_read_new()) != NULL); \
55 assertA(0 == archive_read_support_filter_all(a)); \
56 assertA(0 == archive_read_support_format_all(a)); \
57 assertA(0 == archive_read_open_filenames(a, reffile, 10240))
61 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); \
62 assertEqualInt(ARCHIVE_OK, archive_read_free(a))
65 int verify_data(const uint8_t* data_ptr, int magic, int size) {
68 /* This is how the test data inside test files was generated;
69 * we are re-generating it here and we check if our re-generated
70 * test data is the same as in the test file. If this test is
71 * failing it's either because there's a bug in the test case,
72 * or the unpacked data is corrupted. */
74 for(i = 0; i < size / 4; ++i) {
76 const signed int* lptr = (const signed int*) &data_ptr[i * 4];
77 signed int val = k * k - 3 * k + (1 + magic);
82 /* *lptr is a value inside unpacked test file, val is the
83 * value that should be in the unpacked test file. */
85 if(archive_le32dec(lptr) != (uint32_t) val)
93 int extract_one(struct archive* a, struct archive_entry* ae, uint32_t crc) {
94 la_ssize_t fsize, bytes_read;
97 uint32_t computed_crc;
99 fsize = (la_ssize_t) archive_entry_size(ae);
104 bytes_read = archive_read_data(a, buf, fsize);
105 if(bytes_read != fsize) {
106 assertEqualInt(bytes_read, fsize);
110 computed_crc = crc32(0, buf, fsize);
111 assertEqualInt(computed_crc, crc);
119 DEFINE_TEST(test_read_format_rar5_stored)
121 const char helloworld_txt[] = "hello libarchive test suite!\n";
122 la_ssize_t file_size = sizeof(helloworld_txt) - 1;
125 PROLOGUE("test_read_format_rar5_stored.rar");
127 assertA(0 == archive_read_next_header(a, &ae));
128 assertEqualString("helloworld.txt", archive_entry_pathname(ae));
129 assertA((int) archive_entry_mtime(ae) > 0);
130 assertA((int) archive_entry_ctime(ae) == 0);
131 assertA((int) archive_entry_atime(ae) == 0);
132 assertEqualInt(file_size, archive_entry_size(ae));
133 assertEqualInt(33188, archive_entry_mode(ae));
134 assertA(file_size == archive_read_data(a, buff, file_size));
135 assertEqualMem(buff, helloworld_txt, file_size);
136 assertEqualInt(archive_entry_is_encrypted(ae), 0);
138 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
143 DEFINE_TEST(test_read_format_rar5_compressed)
145 const int DATA_SIZE = 1200;
148 PROLOGUE("test_read_format_rar5_compressed.rar");
150 assertA(0 == archive_read_next_header(a, &ae));
151 assertEqualString("test.bin", archive_entry_pathname(ae));
152 assertA((int) archive_entry_mtime(ae) > 0);
153 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
154 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
155 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
156 verify_data(buff, 0, DATA_SIZE);
161 DEFINE_TEST(test_read_format_rar5_multiple_files)
163 const int DATA_SIZE = 4096;
166 PROLOGUE("test_read_format_rar5_multiple_files.rar");
168 /* There should be 4 files inside this test file. Check for their
169 * existence, and also check the contents of those test files. */
171 assertA(0 == archive_read_next_header(a, &ae));
172 assertEqualString("test1.bin", archive_entry_pathname(ae));
173 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
174 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
175 assertA(verify_data(buff, 1, DATA_SIZE));
177 assertA(0 == archive_read_next_header(a, &ae));
178 assertEqualString("test2.bin", archive_entry_pathname(ae));
179 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
180 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
181 assertA(verify_data(buff, 2, DATA_SIZE));
183 assertA(0 == archive_read_next_header(a, &ae));
184 assertEqualString("test3.bin", archive_entry_pathname(ae));
185 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
186 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
187 assertA(verify_data(buff, 3, DATA_SIZE));
189 assertA(0 == archive_read_next_header(a, &ae));
190 assertEqualString("test4.bin", archive_entry_pathname(ae));
191 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
192 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
193 assertA(verify_data(buff, 4, DATA_SIZE));
195 /* There should be no more files in this archive. */
197 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
201 /* This test is really the same as the test above, but it deals with a solid
202 * archive instead of a regular archive. The test solid archive contains the
203 * same set of files as regular test archive, but it's size is 2x smaller,
204 * because solid archives reuse the window buffer from previous compressed
205 * files, so it's able to compress lots of small files more effectively. */
207 DEFINE_TEST(test_read_format_rar5_multiple_files_solid)
209 const int DATA_SIZE = 4096;
212 PROLOGUE("test_read_format_rar5_multiple_files_solid.rar");
214 assertA(0 == archive_read_next_header(a, &ae));
215 assertEqualString("test1.bin", archive_entry_pathname(ae));
216 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
217 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
218 assertA(verify_data(buff, 1, DATA_SIZE));
220 assertA(0 == archive_read_next_header(a, &ae));
221 assertEqualString("test2.bin", archive_entry_pathname(ae));
222 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
223 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
224 assertA(verify_data(buff, 2, DATA_SIZE));
226 assertA(0 == archive_read_next_header(a, &ae));
227 assertEqualString("test3.bin", archive_entry_pathname(ae));
228 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
229 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
230 assertA(verify_data(buff, 3, DATA_SIZE));
232 assertA(0 == archive_read_next_header(a, &ae));
233 assertEqualString("test4.bin", archive_entry_pathname(ae));
234 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
235 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
236 assertA(verify_data(buff, 4, DATA_SIZE));
238 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
242 DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all)
244 const char* reffiles[] = {
245 "test_read_format_rar5_multiarchive.part01.rar",
246 "test_read_format_rar5_multiarchive.part02.rar",
247 "test_read_format_rar5_multiarchive.part03.rar",
248 "test_read_format_rar5_multiarchive.part04.rar",
249 "test_read_format_rar5_multiarchive.part05.rar",
250 "test_read_format_rar5_multiarchive.part06.rar",
251 "test_read_format_rar5_multiarchive.part07.rar",
252 "test_read_format_rar5_multiarchive.part08.rar",
256 PROLOGUE_MULTI(reffiles);
257 assertA(0 == archive_read_next_header(a, &ae));
258 assertEqualString("home/antek/temp/build/unrar5/libarchive/bin/bsdcat_test", archive_entry_pathname(ae));
259 assertA(0 == archive_read_next_header(a, &ae));
260 assertEqualString("home/antek/temp/build/unrar5/libarchive/bin/bsdtar_test", archive_entry_pathname(ae));
261 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
265 DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all_but_first)
267 const char* reffiles[] = {
268 "test_read_format_rar5_multiarchive.part01.rar",
269 "test_read_format_rar5_multiarchive.part02.rar",
270 "test_read_format_rar5_multiarchive.part03.rar",
271 "test_read_format_rar5_multiarchive.part04.rar",
272 "test_read_format_rar5_multiarchive.part05.rar",
273 "test_read_format_rar5_multiarchive.part06.rar",
274 "test_read_format_rar5_multiarchive.part07.rar",
275 "test_read_format_rar5_multiarchive.part08.rar",
279 PROLOGUE_MULTI(reffiles);
280 assertA(0 == archive_read_next_header(a, &ae));
281 assertA(0 == extract_one(a, ae, 0x35277473));
282 assertA(0 == archive_read_next_header(a, &ae));
283 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
287 DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all_but_second)
289 const char* reffiles[] = {
290 "test_read_format_rar5_multiarchive.part01.rar",
291 "test_read_format_rar5_multiarchive.part02.rar",
292 "test_read_format_rar5_multiarchive.part03.rar",
293 "test_read_format_rar5_multiarchive.part04.rar",
294 "test_read_format_rar5_multiarchive.part05.rar",
295 "test_read_format_rar5_multiarchive.part06.rar",
296 "test_read_format_rar5_multiarchive.part07.rar",
297 "test_read_format_rar5_multiarchive.part08.rar",
301 PROLOGUE_MULTI(reffiles);
302 assertA(0 == archive_read_next_header(a, &ae));
303 assertA(0 == archive_read_next_header(a, &ae));
304 assertA(0 == extract_one(a, ae, 0xE59665F8));
305 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
309 DEFINE_TEST(test_read_format_rar5_blake2)
311 const la_ssize_t proper_size = 814;
314 PROLOGUE("test_read_format_rar5_blake2.rar");
315 assertA(0 == archive_read_next_header(a, &ae));
316 assertEqualInt(proper_size, archive_entry_size(ae));
318 /* Should blake2 calculation fail, we'll get a failure return
319 * value from archive_read_data(). */
321 assertA(proper_size == archive_read_data(a, buf, proper_size));
323 /* To be extra pedantic, let's also check crc32 of the poem. */
324 assertEqualInt(crc32(0, buf, proper_size), 0x7E5EC49E);
326 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
330 DEFINE_TEST(test_read_format_rar5_arm_filter)
332 /* This test unpacks a file that uses an ARM filter. The DELTA
333 * and X86 filters are tested implicitly in the "multiarchive_skip"
336 const la_ssize_t proper_size = 90808;
339 PROLOGUE("test_read_format_rar5_arm.rar");
340 assertA(0 == archive_read_next_header(a, &ae));
341 assertEqualInt(proper_size, archive_entry_size(ae));
342 assertA(proper_size == archive_read_data(a, buf, proper_size));
344 /* Yes, RARv5 unpacker itself should calculate the CRC, but in case
345 * the DONT_FAIL_ON_CRC_ERROR define option is enabled during compilation,
346 * let's still fail the test if the unpacked data is wrong. */
347 assertEqualInt(crc32(0, buf, proper_size), 0x886F91EB);
349 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
353 DEFINE_TEST(test_read_format_rar5_stored_skip_all)
355 const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
358 assertA(0 == archive_read_next_header(a, &ae));
359 assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
360 assertA(0 == archive_read_next_header(a, &ae));
361 assertEqualString("cebula.txt", archive_entry_pathname(ae));
362 assertA(0 == archive_read_next_header(a, &ae));
363 assertEqualString("test.bin", archive_entry_pathname(ae));
364 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
368 DEFINE_TEST(test_read_format_rar5_stored_skip_in_part)
370 const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
373 /* Skip first, extract in part rest. */
376 assertA(0 == archive_read_next_header(a, &ae));
377 assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
378 assertA(0 == archive_read_next_header(a, &ae));
379 assertEqualString("cebula.txt", archive_entry_pathname(ae));
380 assertA(6 == archive_read_data(a, buf, 6));
381 assertEqualInt(0, memcmp(buf, "Cebula", 6));
382 assertA(0 == archive_read_next_header(a, &ae));
383 assertEqualString("test.bin", archive_entry_pathname(ae));
384 assertA(4 == archive_read_data(a, buf, 4));
385 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
389 DEFINE_TEST(test_read_format_rar5_stored_skip_all_but_first)
391 const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
394 /* Extract first, skip rest. */
397 assertA(0 == archive_read_next_header(a, &ae));
398 assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
399 assertA(405 == archive_read_data(a, buf, sizeof(buf)));
400 assertA(0 == archive_read_next_header(a, &ae));
401 assertEqualString("cebula.txt", archive_entry_pathname(ae));
402 assertA(0 == archive_read_next_header(a, &ae));
403 assertEqualString("test.bin", archive_entry_pathname(ae));
404 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
408 DEFINE_TEST(test_read_format_rar5_stored_skip_all_in_part)
410 const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
413 /* Extract in part all */
416 assertA(0 == archive_read_next_header(a, &ae));
417 assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
418 assertA(4 == archive_read_data(a, buf, 4));
419 assertA(0 == archive_read_next_header(a, &ae));
420 assertEqualString("cebula.txt", archive_entry_pathname(ae));
421 assertA(4 == archive_read_data(a, buf, 4));
422 assertA(0 == archive_read_next_header(a, &ae));
423 assertEqualString("test.bin", archive_entry_pathname(ae));
424 assertA(4 == archive_read_data(a, buf, 4));
425 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
429 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all)
431 const char* reffiles[] = {
432 "test_read_format_rar5_multiarchive_solid.part01.rar",
433 "test_read_format_rar5_multiarchive_solid.part02.rar",
434 "test_read_format_rar5_multiarchive_solid.part03.rar",
435 "test_read_format_rar5_multiarchive_solid.part04.rar",
439 PROLOGUE_MULTI(reffiles);
440 assertA(0 == archive_read_next_header(a, &ae));
441 assertEqualString("cebula.txt", archive_entry_pathname(ae));
442 assertA(0 == archive_read_next_header(a, &ae));
443 assertEqualString("test.bin", archive_entry_pathname(ae));
444 assertA(0 == archive_read_next_header(a, &ae));
445 assertEqualString("test1.bin", archive_entry_pathname(ae));
446 assertA(0 == archive_read_next_header(a, &ae));
447 assertEqualString("test2.bin", archive_entry_pathname(ae));
448 assertA(0 == archive_read_next_header(a, &ae));
449 assertEqualString("test3.bin", archive_entry_pathname(ae));
450 assertA(0 == archive_read_next_header(a, &ae));
451 assertEqualString("test4.bin", archive_entry_pathname(ae));
452 assertA(0 == archive_read_next_header(a, &ae));
453 assertEqualString("test5.bin", archive_entry_pathname(ae));
454 assertA(0 == archive_read_next_header(a, &ae));
455 assertEqualString("test6.bin", archive_entry_pathname(ae));
456 assertA(0 == archive_read_next_header(a, &ae));
457 assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
458 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
462 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_first)
464 const char* reffiles[] = {
465 "test_read_format_rar5_multiarchive_solid.part01.rar",
466 "test_read_format_rar5_multiarchive_solid.part02.rar",
467 "test_read_format_rar5_multiarchive_solid.part03.rar",
468 "test_read_format_rar5_multiarchive_solid.part04.rar",
472 PROLOGUE_MULTI(reffiles);
473 assertA(0 == archive_read_next_header(a, &ae));
474 assertEqualString("cebula.txt", archive_entry_pathname(ae));
475 assertA(0 == extract_one(a, ae, 0x7E5EC49E));
476 assertA(0 == archive_read_next_header(a, &ae));
477 assertEqualString("test.bin", archive_entry_pathname(ae));
478 assertA(0 == archive_read_next_header(a, &ae));
479 assertEqualString("test1.bin", archive_entry_pathname(ae));
480 assertA(0 == archive_read_next_header(a, &ae));
481 assertEqualString("test2.bin", archive_entry_pathname(ae));
482 assertA(0 == archive_read_next_header(a, &ae));
483 assertEqualString("test3.bin", archive_entry_pathname(ae));
484 assertA(0 == archive_read_next_header(a, &ae));
485 assertEqualString("test4.bin", archive_entry_pathname(ae));
486 assertA(0 == archive_read_next_header(a, &ae));
487 assertEqualString("test5.bin", archive_entry_pathname(ae));
488 assertA(0 == archive_read_next_header(a, &ae));
489 assertEqualString("test6.bin", archive_entry_pathname(ae));
490 assertA(0 == archive_read_next_header(a, &ae));
491 assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
492 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
496 /* "skip_all_but_scnd" -> am I hitting the test name limit here after
497 * expansion of "scnd" to "second"? */
499 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_scnd)
501 const char* reffiles[] = {
502 "test_read_format_rar5_multiarchive_solid.part01.rar",
503 "test_read_format_rar5_multiarchive_solid.part02.rar",
504 "test_read_format_rar5_multiarchive_solid.part03.rar",
505 "test_read_format_rar5_multiarchive_solid.part04.rar",
509 PROLOGUE_MULTI(reffiles);
510 assertA(0 == archive_read_next_header(a, &ae));
511 assertEqualString("cebula.txt", archive_entry_pathname(ae));
512 assertA(0 == archive_read_next_header(a, &ae));
513 assertEqualString("test.bin", archive_entry_pathname(ae));
514 assertA(0 == extract_one(a, ae, 0x7CCA70CD));
515 assertA(0 == archive_read_next_header(a, &ae));
516 assertEqualString("test1.bin", archive_entry_pathname(ae));
517 assertA(0 == archive_read_next_header(a, &ae));
518 assertEqualString("test2.bin", archive_entry_pathname(ae));
519 assertA(0 == archive_read_next_header(a, &ae));
520 assertEqualString("test3.bin", archive_entry_pathname(ae));
521 assertA(0 == archive_read_next_header(a, &ae));
522 assertEqualString("test4.bin", archive_entry_pathname(ae));
523 assertA(0 == archive_read_next_header(a, &ae));
524 assertEqualString("test5.bin", archive_entry_pathname(ae));
525 assertA(0 == archive_read_next_header(a, &ae));
526 assertEqualString("test6.bin", archive_entry_pathname(ae));
527 assertA(0 == archive_read_next_header(a, &ae));
528 assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
529 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
533 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_third)
535 const char* reffiles[] = {
536 "test_read_format_rar5_multiarchive_solid.part01.rar",
537 "test_read_format_rar5_multiarchive_solid.part02.rar",
538 "test_read_format_rar5_multiarchive_solid.part03.rar",
539 "test_read_format_rar5_multiarchive_solid.part04.rar",
543 PROLOGUE_MULTI(reffiles);
544 assertA(0 == archive_read_next_header(a, &ae));
545 assertEqualString("cebula.txt", archive_entry_pathname(ae));
546 assertA(0 == archive_read_next_header(a, &ae));
547 assertEqualString("test.bin", archive_entry_pathname(ae));
548 assertA(0 == archive_read_next_header(a, &ae));
549 assertEqualString("test1.bin", archive_entry_pathname(ae));
550 assertA(0 == extract_one(a, ae, 0x7E13B2C6));
551 assertA(0 == archive_read_next_header(a, &ae));
552 assertEqualString("test2.bin", archive_entry_pathname(ae));
553 assertA(0 == archive_read_next_header(a, &ae));
554 assertEqualString("test3.bin", archive_entry_pathname(ae));
555 assertA(0 == archive_read_next_header(a, &ae));
556 assertEqualString("test4.bin", archive_entry_pathname(ae));
557 assertA(0 == archive_read_next_header(a, &ae));
558 assertEqualString("test5.bin", archive_entry_pathname(ae));
559 assertA(0 == archive_read_next_header(a, &ae));
560 assertEqualString("test6.bin", archive_entry_pathname(ae));
561 assertA(0 == archive_read_next_header(a, &ae));
562 assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
563 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
567 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_last)
569 const char* reffiles[] = {
570 "test_read_format_rar5_multiarchive_solid.part01.rar",
571 "test_read_format_rar5_multiarchive_solid.part02.rar",
572 "test_read_format_rar5_multiarchive_solid.part03.rar",
573 "test_read_format_rar5_multiarchive_solid.part04.rar",
577 PROLOGUE_MULTI(reffiles);
578 assertA(0 == archive_read_next_header(a, &ae));
579 assertEqualString("cebula.txt", archive_entry_pathname(ae));
580 assertA(0 == archive_read_next_header(a, &ae));
581 assertEqualString("test.bin", archive_entry_pathname(ae));
582 assertA(0 == archive_read_next_header(a, &ae));
583 assertEqualString("test1.bin", archive_entry_pathname(ae));
584 assertA(0 == archive_read_next_header(a, &ae));
585 assertEqualString("test2.bin", archive_entry_pathname(ae));
586 assertA(0 == archive_read_next_header(a, &ae));
587 assertEqualString("test3.bin", archive_entry_pathname(ae));
588 assertA(0 == archive_read_next_header(a, &ae));
589 assertEqualString("test4.bin", archive_entry_pathname(ae));
590 assertA(0 == archive_read_next_header(a, &ae));
591 assertEqualString("test5.bin", archive_entry_pathname(ae));
592 assertA(0 == archive_read_next_header(a, &ae));
593 assertEqualString("test6.bin", archive_entry_pathname(ae));
594 assertA(0 == archive_read_next_header(a, &ae));
595 assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
596 assertA(0 == extract_one(a, ae, 0x886F91EB));
597 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
601 DEFINE_TEST(test_read_format_rar5_solid_skip_all)
603 const char* reffile = "test_read_format_rar5_solid.rar";
608 assertA(0 == archive_read_next_header(a, &ae));
609 assertEqualString("test.bin", archive_entry_pathname(ae));
610 assertA(0 == archive_read_next_header(a, &ae));
611 assertEqualString("test1.bin", archive_entry_pathname(ae));
612 assertA(0 == archive_read_next_header(a, &ae));
613 assertEqualString("test2.bin", archive_entry_pathname(ae));
614 assertA(0 == archive_read_next_header(a, &ae));
615 assertEqualString("test3.bin", archive_entry_pathname(ae));
616 assertA(0 == archive_read_next_header(a, &ae));
617 assertEqualString("test4.bin", archive_entry_pathname(ae));
618 assertA(0 == archive_read_next_header(a, &ae));
619 assertEqualString("test5.bin", archive_entry_pathname(ae));
620 assertA(0 == archive_read_next_header(a, &ae));
621 assertEqualString("test6.bin", archive_entry_pathname(ae));
622 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
626 DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_first)
628 const char* reffile = "test_read_format_rar5_solid.rar";
630 /* Extract first, skip rest */
633 assertA(0 == archive_read_next_header(a, &ae));
634 assertEqualString("test.bin", archive_entry_pathname(ae));
635 assertA(0 == extract_one(a, ae, 0x7CCA70CD));
636 assertA(0 == archive_read_next_header(a, &ae));
637 assertEqualString("test1.bin", archive_entry_pathname(ae));
638 assertA(0 == archive_read_next_header(a, &ae));
639 assertEqualString("test2.bin", archive_entry_pathname(ae));
640 assertA(0 == archive_read_next_header(a, &ae));
641 assertEqualString("test3.bin", archive_entry_pathname(ae));
642 assertA(0 == archive_read_next_header(a, &ae));
643 assertEqualString("test4.bin", archive_entry_pathname(ae));
644 assertA(0 == archive_read_next_header(a, &ae));
645 assertEqualString("test5.bin", archive_entry_pathname(ae));
646 assertA(0 == archive_read_next_header(a, &ae));
647 assertEqualString("test6.bin", archive_entry_pathname(ae));
648 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
652 DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_second)
654 const char* reffile = "test_read_format_rar5_solid.rar";
656 /* Skip first, extract second, skip rest */
659 assertA(0 == archive_read_next_header(a, &ae));
660 assertEqualString("test.bin", archive_entry_pathname(ae));
661 assertA(0 == archive_read_next_header(a, &ae));
662 assertEqualString("test1.bin", archive_entry_pathname(ae));
663 assertA(0 == extract_one(a, ae, 0x7E13B2C6));
664 assertA(0 == archive_read_next_header(a, &ae));
665 assertEqualString("test2.bin", archive_entry_pathname(ae));
666 assertA(0 == archive_read_next_header(a, &ae));
667 assertEqualString("test3.bin", archive_entry_pathname(ae));
668 assertA(0 == archive_read_next_header(a, &ae));
669 assertEqualString("test4.bin", archive_entry_pathname(ae));
670 assertA(0 == archive_read_next_header(a, &ae));
671 assertEqualString("test5.bin", archive_entry_pathname(ae));
672 assertA(0 == archive_read_next_header(a, &ae));
673 assertEqualString("test6.bin", archive_entry_pathname(ae));
674 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
678 DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_last)
680 const char* reffile = "test_read_format_rar5_solid.rar";
682 /* Skip all but last, extract last */
685 assertA(0 == archive_read_next_header(a, &ae));
686 assertEqualString("test.bin", archive_entry_pathname(ae));
687 assertA(0 == archive_read_next_header(a, &ae));
688 assertEqualString("test1.bin", archive_entry_pathname(ae));
689 assertA(0 == archive_read_next_header(a, &ae));
690 assertEqualString("test2.bin", archive_entry_pathname(ae));
691 assertA(0 == archive_read_next_header(a, &ae));
692 assertEqualString("test3.bin", archive_entry_pathname(ae));
693 assertA(0 == archive_read_next_header(a, &ae));
694 assertEqualString("test4.bin", archive_entry_pathname(ae));
695 assertA(0 == archive_read_next_header(a, &ae));
696 assertEqualString("test5.bin", archive_entry_pathname(ae));
697 assertA(0 == archive_read_next_header(a, &ae));
698 assertEqualString("test6.bin", archive_entry_pathname(ae));
699 assertA(0 == extract_one(a, ae, 0x36A448FF));
700 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
704 DEFINE_TEST(test_read_format_rar5_extract_win32)
706 PROLOGUE("test_read_format_rar5_win32.rar");
707 assertA(0 == archive_read_next_header(a, &ae));
708 assertEqualString("test.bin", archive_entry_pathname(ae));
709 assertA(0 == extract_one(a, ae, 0x7CCA70CD));
710 assertA(0 == archive_read_next_header(a, &ae));
711 assertEqualString("test1.bin", archive_entry_pathname(ae));
712 assertA(0 == extract_one(a, ae, 0x7E13B2C6));
713 assertA(0 == archive_read_next_header(a, &ae));
714 assertEqualString("test2.bin", archive_entry_pathname(ae));
715 assertA(0 == extract_one(a, ae, 0xF166AFCB));
716 assertA(0 == archive_read_next_header(a, &ae));
717 assertEqualString("test3.bin", archive_entry_pathname(ae));
718 assertA(0 == extract_one(a, ae, 0x9FB123D9));
719 assertA(0 == archive_read_next_header(a, &ae));
720 assertEqualString("test4.bin", archive_entry_pathname(ae));
721 assertA(0 == extract_one(a, ae, 0x10C43ED4));
722 assertA(0 == archive_read_next_header(a, &ae));
723 assertEqualString("test5.bin", archive_entry_pathname(ae));
724 assertA(0 == extract_one(a, ae, 0xB9D155F2));
725 assertA(0 == archive_read_next_header(a, &ae));
726 assertEqualString("test6.bin", archive_entry_pathname(ae));
727 assertA(0 == extract_one(a, ae, 0x36A448FF));
731 DEFINE_TEST(test_read_format_rar5_block_by_block)
733 /* This test uses strange buffer sizes intentionally. */
735 struct archive_entry *ae;
739 uint32_t computed_crc = 0;
741 extract_reference_file("test_read_format_rar5_compressed.rar");
742 assert((a = archive_read_new()) != NULL);
743 assertA(0 == archive_read_support_filter_all(a));
744 assertA(0 == archive_read_support_format_all(a));
745 assertA(0 == archive_read_open_filename(a, "test_read_format_rar5_compressed.rar", 130));
746 assertA(0 == archive_read_next_header(a, &ae));
747 assertEqualString("test.bin", archive_entry_pathname(ae));
748 assertEqualInt(1200, archive_entry_size(ae));
750 /* File size is 1200 bytes, we're reading it using a buffer of 173 bytes.
751 * Libarchive is configured to use a buffer of 130 bytes. */
754 /* archive_read_data should return one of:
755 * a) 0, if there is no more data to be read,
756 * b) negative value, if there was an error,
757 * c) positive value, meaning how many bytes were read.
760 bytes_read = archive_read_data(a, buf, sizeof(buf));
761 assertA(bytes_read >= 0);
765 computed_crc = crc32(computed_crc, buf, bytes_read);
768 assertEqualInt(computed_crc, 0x7CCA70CD);