test_read_format_rar5.c revision 342361
1/*-
2 * Copyright (c) 2018 Grzegorz Antoniak
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
13 *
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.
24 */
25#include "test.h"
26
27/* Some tests will want to calculate some CRC32's, and this header can
28 * help. */
29#define __LIBARCHIVE_BUILD
30#include <archive_crc32.h>
31
32#define PROLOGUE(reffile) \
33    struct archive_entry *ae; \
34    struct archive *a; \
35    \
36    (void) a;  /* Make the compiler happy if we won't use this variables */ \
37    (void) ae; /* in the test cases. */ \
38    \
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))
44
45#define PROLOGUE_MULTI(reffile) \
46    struct archive_entry *ae; \
47    struct archive *a; \
48    \
49    (void) a; \
50    (void) ae; \
51    \
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))
57
58
59#define EPILOGUE() \
60    assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); \
61    assertEqualInt(ARCHIVE_OK, archive_read_free(a))
62
63static
64int verify_data(const uint8_t* data_ptr, int magic, int size) {
65    int i = 0;
66
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. */
72
73    for(i = 0; i < size / 4; ++i) {
74        const int k = i + 1;
75        const signed int* lptr = (const signed int*) &data_ptr[i * 4];
76        signed int val = k * k - 3 * k + (1 + magic);
77
78        if(val < 0)
79            val = 0;
80
81        /* *lptr is a value inside unpacked test file, val is the
82         * value that should be in the unpacked test file. */
83
84        if(*lptr != val)
85            return 0;
86    }
87
88    return 1;
89}
90
91static
92int extract_one(struct archive* a, struct archive_entry* ae, uint32_t crc) {
93    la_ssize_t fsize, read;
94    uint8_t* buf;
95    int ret = 1;
96    uint32_t computed_crc;
97
98    fsize = archive_entry_size(ae);
99    buf = malloc(fsize);
100    if(buf == NULL)
101        return 1;
102
103    read = archive_read_data(a, buf, fsize);
104    if(read != fsize) {
105        assertEqualInt(read, fsize);
106        goto fn_exit;
107    }
108
109    computed_crc = crc32(0, buf, fsize);
110    assertEqualInt(computed_crc, crc);
111    ret = 0;
112
113fn_exit:
114    free(buf);
115    return ret;
116}
117
118DEFINE_TEST(test_read_format_rar5_stored)
119{
120    const char helloworld_txt[] = "hello libarchive test suite!\n";
121    la_ssize_t file_size = sizeof(helloworld_txt) - 1;
122    char buff[64];
123
124    PROLOGUE("test_read_format_rar5_stored.rar");
125
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);
136
137    assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
138
139    EPILOGUE();
140}
141
142DEFINE_TEST(test_read_format_rar5_compressed)
143{
144    const int DATA_SIZE = 1200;
145    uint8_t buff[DATA_SIZE];
146
147    PROLOGUE("test_read_format_rar5_compressed.rar");
148
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);
156
157    EPILOGUE();
158}
159
160DEFINE_TEST(test_read_format_rar5_multiple_files)
161{
162    const int DATA_SIZE = 4096;
163    uint8_t buff[DATA_SIZE];
164
165    PROLOGUE("test_read_format_rar5_multiple_files.rar");
166
167    /* There should be 4 files inside this test file. Check for their
168     * existence, and also check the contents of those test files. */
169
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));
175
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));
181
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));
187
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));
193
194    /* There should be no more files in this archive. */
195
196    assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
197    EPILOGUE();
198}
199
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. */
205
206DEFINE_TEST(test_read_format_rar5_multiple_files_solid)
207{
208    const int DATA_SIZE = 4096;
209    uint8_t buff[DATA_SIZE];
210
211    PROLOGUE("test_read_format_rar5_multiple_files_solid.rar");
212
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));
218
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));
224
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));
230
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));
236
237    assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
238    EPILOGUE();
239}
240
241DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all)
242{
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",
252        NULL
253    };
254
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));
261    EPILOGUE();
262}
263
264DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all_but_first)
265{
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",
275        NULL
276    };
277
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));
283    EPILOGUE();
284}
285
286DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all_but_second)
287{
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",
297        NULL
298    };
299
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));
305    EPILOGUE();
306}
307
308DEFINE_TEST(test_read_format_rar5_blake2)
309{
310    const la_ssize_t proper_size = 814;
311    uint8_t buf[proper_size];
312
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));
316
317    /* Should blake2 calculation fail, we'll get a failure return
318     * value from archive_read_data(). */
319
320    assertA(proper_size == archive_read_data(a, buf, proper_size));
321
322    /* To be extra pedantic, let's also check crc32 of the poem. */
323    assertEqualInt(crc32(0, buf, proper_size), 0x7E5EC49E);
324
325    assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
326    EPILOGUE();
327}
328
329DEFINE_TEST(test_read_format_rar5_arm_filter)
330{
331    /* This test unpacks a file that uses an ARM filter. The DELTA
332     * and X86 filters are tested implicitly in the "multiarchive_skip"
333     * test. */
334
335    const la_ssize_t proper_size = 90808;
336    uint8_t buf[proper_size];
337
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));
342
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);
347
348    assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
349    EPILOGUE();
350}
351
352DEFINE_TEST(test_read_format_rar5_stored_skip_all)
353{
354    const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
355
356    PROLOGUE(fname);
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));
364    EPILOGUE();
365}
366
367DEFINE_TEST(test_read_format_rar5_stored_skip_in_part)
368{
369    const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
370    char buf[6];
371
372    /* Skip first, extract in part rest. */
373
374    PROLOGUE(fname);
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));
385    EPILOGUE();
386}
387
388DEFINE_TEST(test_read_format_rar5_stored_skip_all_but_first)
389{
390    const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
391    char buf[405];
392
393    /* Extract first, skip rest. */
394
395    PROLOGUE(fname);
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));
404    EPILOGUE();
405}
406
407DEFINE_TEST(test_read_format_rar5_stored_skip_all_in_part)
408{
409    const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
410    char buf[4];
411
412    /* Extract in part all */
413
414    PROLOGUE(fname);
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));
425    EPILOGUE();
426}
427
428DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all)
429{
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",
435        NULL
436    };
437
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));
458    EPILOGUE();
459}
460
461DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_first)
462{
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",
468        NULL
469    };
470
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));
492    EPILOGUE();
493}
494
495/* "skip_all_but_scnd" -> am I hitting the test name limit here after
496 * expansion of "scnd" to "second"? */
497
498DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_scnd)
499{
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",
505        NULL
506    };
507
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));
529    EPILOGUE();
530}
531
532DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_third)
533{
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",
539        NULL
540    };
541
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));
563    EPILOGUE();
564}
565
566DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_last)
567{
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",
573        NULL
574    };
575
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));
597    EPILOGUE();
598}
599
600DEFINE_TEST(test_read_format_rar5_solid_skip_all)
601{
602    const char* reffile = "test_read_format_rar5_solid.rar";
603
604    /* Skip all */
605
606    PROLOGUE(reffile);
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));
622    EPILOGUE();
623}
624
625DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_first)
626{
627    const char* reffile = "test_read_format_rar5_solid.rar";
628
629    /* Extract first, skip rest */
630
631    PROLOGUE(reffile);
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));
648    EPILOGUE();
649}
650
651DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_second)
652{
653    const char* reffile = "test_read_format_rar5_solid.rar";
654
655    /* Skip first, extract second, skip rest */
656
657    PROLOGUE(reffile);
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));
674    EPILOGUE();
675}
676
677DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_last)
678{
679    const char* reffile = "test_read_format_rar5_solid.rar";
680
681    /* Skip all but last, extract last */
682
683    PROLOGUE(reffile);
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));
700    EPILOGUE();
701}
702
703DEFINE_TEST(test_read_format_rar5_extract_win32)
704{
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));
727    EPILOGUE();
728}
729