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_set_format)
122 struct archive_entry *ae;
123 const char reffile[] = "test_read_format_rar5_stored.rar";
125 extract_reference_file(reffile);
126 assert((a = archive_read_new()) != NULL);
127 assertA(0 == archive_read_support_filter_all(a));
128 assertA(0 == archive_read_set_format(a, ARCHIVE_FORMAT_RAR_V5));
129 assertA(0 == archive_read_open_filename(a, reffile, 10240));
130 assertA(0 == archive_read_next_header(a, &ae));
134 DEFINE_TEST(test_read_format_rar5_stored)
136 const char helloworld_txt[] = "hello libarchive test suite!\n";
137 la_ssize_t file_size = sizeof(helloworld_txt) - 1;
140 PROLOGUE("test_read_format_rar5_stored.rar");
142 assertA(0 == archive_read_next_header(a, &ae));
143 assertEqualString("helloworld.txt", archive_entry_pathname(ae));
144 assertA((int) archive_entry_mtime(ae) > 0);
145 assertA((int) archive_entry_ctime(ae) == 0);
146 assertA((int) archive_entry_atime(ae) == 0);
147 assertEqualInt(file_size, archive_entry_size(ae));
148 assertEqualInt(33188, archive_entry_mode(ae));
149 assertA(file_size == archive_read_data(a, buff, file_size));
150 assertEqualMem(buff, helloworld_txt, file_size);
151 assertEqualInt(archive_entry_is_encrypted(ae), 0);
153 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
158 DEFINE_TEST(test_read_format_rar5_compressed)
160 const int DATA_SIZE = 1200;
163 PROLOGUE("test_read_format_rar5_compressed.rar");
165 assertA(0 == archive_read_next_header(a, &ae));
166 assertEqualString("test.bin", archive_entry_pathname(ae));
167 assertA((int) archive_entry_mtime(ae) > 0);
168 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
169 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
170 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
171 verify_data(buff, 0, DATA_SIZE);
176 DEFINE_TEST(test_read_format_rar5_multiple_files)
178 const int DATA_SIZE = 4096;
181 PROLOGUE("test_read_format_rar5_multiple_files.rar");
183 /* There should be 4 files inside this test file. Check for their
184 * existence, and also check the contents of those test files. */
186 assertA(0 == archive_read_next_header(a, &ae));
187 assertEqualString("test1.bin", archive_entry_pathname(ae));
188 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
189 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
190 assertA(verify_data(buff, 1, DATA_SIZE));
192 assertA(0 == archive_read_next_header(a, &ae));
193 assertEqualString("test2.bin", archive_entry_pathname(ae));
194 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
195 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
196 assertA(verify_data(buff, 2, DATA_SIZE));
198 assertA(0 == archive_read_next_header(a, &ae));
199 assertEqualString("test3.bin", archive_entry_pathname(ae));
200 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
201 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
202 assertA(verify_data(buff, 3, DATA_SIZE));
204 assertA(0 == archive_read_next_header(a, &ae));
205 assertEqualString("test4.bin", archive_entry_pathname(ae));
206 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
207 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
208 assertA(verify_data(buff, 4, DATA_SIZE));
210 /* There should be no more files in this archive. */
212 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
216 /* This test is really the same as the test above, but it deals with a solid
217 * archive instead of a regular archive. The test solid archive contains the
218 * same set of files as regular test archive, but it's size is 2x smaller,
219 * because solid archives reuse the window buffer from previous compressed
220 * files, so it's able to compress lots of small files more effectively. */
222 DEFINE_TEST(test_read_format_rar5_multiple_files_solid)
224 const int DATA_SIZE = 4096;
227 PROLOGUE("test_read_format_rar5_multiple_files_solid.rar");
229 assertA(0 == archive_read_next_header(a, &ae));
230 assertEqualString("test1.bin", archive_entry_pathname(ae));
231 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
232 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
233 assertA(verify_data(buff, 1, DATA_SIZE));
235 assertA(0 == archive_read_next_header(a, &ae));
236 assertEqualString("test2.bin", archive_entry_pathname(ae));
237 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
238 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
239 assertA(verify_data(buff, 2, DATA_SIZE));
241 assertA(0 == archive_read_next_header(a, &ae));
242 assertEqualString("test3.bin", archive_entry_pathname(ae));
243 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
244 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
245 assertA(verify_data(buff, 3, DATA_SIZE));
247 assertA(0 == archive_read_next_header(a, &ae));
248 assertEqualString("test4.bin", archive_entry_pathname(ae));
249 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
250 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
251 assertA(verify_data(buff, 4, DATA_SIZE));
253 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
257 DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all)
259 const char* reffiles[] = {
260 "test_read_format_rar5_multiarchive.part01.rar",
261 "test_read_format_rar5_multiarchive.part02.rar",
262 "test_read_format_rar5_multiarchive.part03.rar",
263 "test_read_format_rar5_multiarchive.part04.rar",
264 "test_read_format_rar5_multiarchive.part05.rar",
265 "test_read_format_rar5_multiarchive.part06.rar",
266 "test_read_format_rar5_multiarchive.part07.rar",
267 "test_read_format_rar5_multiarchive.part08.rar",
271 PROLOGUE_MULTI(reffiles);
272 assertA(0 == archive_read_next_header(a, &ae));
273 assertEqualString("home/antek/temp/build/unrar5/libarchive/bin/bsdcat_test", archive_entry_pathname(ae));
274 assertA(0 == archive_read_next_header(a, &ae));
275 assertEqualString("home/antek/temp/build/unrar5/libarchive/bin/bsdtar_test", archive_entry_pathname(ae));
276 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
280 DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all_but_first)
282 const char* reffiles[] = {
283 "test_read_format_rar5_multiarchive.part01.rar",
284 "test_read_format_rar5_multiarchive.part02.rar",
285 "test_read_format_rar5_multiarchive.part03.rar",
286 "test_read_format_rar5_multiarchive.part04.rar",
287 "test_read_format_rar5_multiarchive.part05.rar",
288 "test_read_format_rar5_multiarchive.part06.rar",
289 "test_read_format_rar5_multiarchive.part07.rar",
290 "test_read_format_rar5_multiarchive.part08.rar",
294 PROLOGUE_MULTI(reffiles);
295 assertA(0 == archive_read_next_header(a, &ae));
296 assertA(0 == extract_one(a, ae, 0x35277473));
297 assertA(0 == archive_read_next_header(a, &ae));
298 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
302 DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all_but_second)
304 const char* reffiles[] = {
305 "test_read_format_rar5_multiarchive.part01.rar",
306 "test_read_format_rar5_multiarchive.part02.rar",
307 "test_read_format_rar5_multiarchive.part03.rar",
308 "test_read_format_rar5_multiarchive.part04.rar",
309 "test_read_format_rar5_multiarchive.part05.rar",
310 "test_read_format_rar5_multiarchive.part06.rar",
311 "test_read_format_rar5_multiarchive.part07.rar",
312 "test_read_format_rar5_multiarchive.part08.rar",
316 PROLOGUE_MULTI(reffiles);
317 assertA(0 == archive_read_next_header(a, &ae));
318 assertA(0 == archive_read_next_header(a, &ae));
319 assertA(0 == extract_one(a, ae, 0xE59665F8));
320 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
324 DEFINE_TEST(test_read_format_rar5_blake2)
326 const la_ssize_t proper_size = 814;
329 PROLOGUE("test_read_format_rar5_blake2.rar");
330 assertA(0 == archive_read_next_header(a, &ae));
331 assertEqualInt(proper_size, archive_entry_size(ae));
333 /* Should blake2 calculation fail, we'll get a failure return
334 * value from archive_read_data(). */
336 assertA(proper_size == archive_read_data(a, buf, proper_size));
338 /* To be extra pedantic, let's also check crc32 of the poem. */
339 assertEqualInt(crc32(0, buf, proper_size), 0x7E5EC49E);
341 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
345 DEFINE_TEST(test_read_format_rar5_arm_filter)
347 /* This test unpacks a file that uses an ARM filter. The DELTA
348 * and X86 filters are tested implicitly in the "multiarchive_skip"
351 const la_ssize_t proper_size = 90808;
354 PROLOGUE("test_read_format_rar5_arm.rar");
355 assertA(0 == archive_read_next_header(a, &ae));
356 assertEqualInt(proper_size, archive_entry_size(ae));
357 assertA(proper_size == archive_read_data(a, buf, proper_size));
359 /* Yes, RARv5 unpacker itself should calculate the CRC, but in case
360 * the DONT_FAIL_ON_CRC_ERROR define option is enabled during compilation,
361 * let's still fail the test if the unpacked data is wrong. */
362 assertEqualInt(crc32(0, buf, proper_size), 0x886F91EB);
364 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
368 DEFINE_TEST(test_read_format_rar5_stored_skip_all)
370 const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
373 assertA(0 == archive_read_next_header(a, &ae));
374 assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
375 assertA(0 == archive_read_next_header(a, &ae));
376 assertEqualString("cebula.txt", archive_entry_pathname(ae));
377 assertA(0 == archive_read_next_header(a, &ae));
378 assertEqualString("test.bin", archive_entry_pathname(ae));
379 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
383 DEFINE_TEST(test_read_format_rar5_stored_skip_in_part)
385 const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
388 /* Skip first, extract in part rest. */
391 assertA(0 == archive_read_next_header(a, &ae));
392 assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
393 assertA(0 == archive_read_next_header(a, &ae));
394 assertEqualString("cebula.txt", archive_entry_pathname(ae));
395 assertA(6 == archive_read_data(a, buf, 6));
396 assertEqualInt(0, memcmp(buf, "Cebula", 6));
397 assertA(0 == archive_read_next_header(a, &ae));
398 assertEqualString("test.bin", archive_entry_pathname(ae));
399 assertA(4 == archive_read_data(a, buf, 4));
400 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
404 DEFINE_TEST(test_read_format_rar5_stored_skip_all_but_first)
406 const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
409 /* Extract first, skip rest. */
412 assertA(0 == archive_read_next_header(a, &ae));
413 assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
414 assertA(405 == archive_read_data(a, buf, sizeof(buf)));
415 assertA(0 == archive_read_next_header(a, &ae));
416 assertEqualString("cebula.txt", archive_entry_pathname(ae));
417 assertA(0 == archive_read_next_header(a, &ae));
418 assertEqualString("test.bin", archive_entry_pathname(ae));
419 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
423 DEFINE_TEST(test_read_format_rar5_stored_skip_all_in_part)
425 const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
428 /* Extract in part all */
431 assertA(0 == archive_read_next_header(a, &ae));
432 assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
433 assertA(4 == archive_read_data(a, buf, 4));
434 assertA(0 == archive_read_next_header(a, &ae));
435 assertEqualString("cebula.txt", archive_entry_pathname(ae));
436 assertA(4 == archive_read_data(a, buf, 4));
437 assertA(0 == archive_read_next_header(a, &ae));
438 assertEqualString("test.bin", archive_entry_pathname(ae));
439 assertA(4 == archive_read_data(a, buf, 4));
440 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
444 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_extr_all)
446 const char* reffiles[] = {
447 "test_read_format_rar5_multiarchive_solid.part01.rar",
448 "test_read_format_rar5_multiarchive_solid.part02.rar",
449 "test_read_format_rar5_multiarchive_solid.part03.rar",
450 "test_read_format_rar5_multiarchive_solid.part04.rar",
454 PROLOGUE_MULTI(reffiles);
455 assertA(0 == archive_read_next_header(a, &ae));
456 assertEqualString("cebula.txt", archive_entry_pathname(ae));
457 assertA(0 == extract_one(a, ae, 0x7E5EC49E));
459 assertA(0 == archive_read_next_header(a, &ae));
460 assertEqualString("test.bin", archive_entry_pathname(ae));
461 assertA(0 == extract_one(a, ae, 0x7cca70cd));
463 assertA(0 == archive_read_next_header(a, &ae));
464 assertEqualString("test1.bin", archive_entry_pathname(ae));
465 assertA(0 == extract_one(a, ae, 0x7e13b2c6));
467 assertA(0 == archive_read_next_header(a, &ae));
468 assertEqualString("test2.bin", archive_entry_pathname(ae));
469 assertA(0 == extract_one(a, ae, 0xf166afcb));
471 assertA(0 == archive_read_next_header(a, &ae));
472 assertEqualString("test3.bin", archive_entry_pathname(ae));
473 assertA(0 == extract_one(a, ae, 0x9fb123d9));
475 assertA(0 == archive_read_next_header(a, &ae));
476 assertEqualString("test4.bin", archive_entry_pathname(ae));
477 assertA(0 == extract_one(a, ae, 0x10c43ed4));
479 assertA(0 == archive_read_next_header(a, &ae));
480 assertEqualString("test5.bin", archive_entry_pathname(ae));
481 assertA(0 == extract_one(a, ae, 0xb9d155f2));
483 assertA(0 == archive_read_next_header(a, &ae));
484 assertEqualString("test6.bin", archive_entry_pathname(ae));
485 assertA(0 == extract_one(a, ae, 0x36a448ff));
487 assertA(0 == archive_read_next_header(a, &ae));
488 assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
489 assertA(0 == extract_one(a, ae, 0x886F91EB));
491 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
495 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all)
497 const char* reffiles[] = {
498 "test_read_format_rar5_multiarchive_solid.part01.rar",
499 "test_read_format_rar5_multiarchive_solid.part02.rar",
500 "test_read_format_rar5_multiarchive_solid.part03.rar",
501 "test_read_format_rar5_multiarchive_solid.part04.rar",
505 PROLOGUE_MULTI(reffiles);
506 assertA(0 == archive_read_next_header(a, &ae));
507 assertEqualString("cebula.txt", archive_entry_pathname(ae));
508 assertA(0 == archive_read_next_header(a, &ae));
509 assertEqualString("test.bin", archive_entry_pathname(ae));
510 assertA(0 == archive_read_next_header(a, &ae));
511 assertEqualString("test1.bin", archive_entry_pathname(ae));
512 assertA(0 == archive_read_next_header(a, &ae));
513 assertEqualString("test2.bin", archive_entry_pathname(ae));
514 assertA(0 == archive_read_next_header(a, &ae));
515 assertEqualString("test3.bin", archive_entry_pathname(ae));
516 assertA(0 == archive_read_next_header(a, &ae));
517 assertEqualString("test4.bin", archive_entry_pathname(ae));
518 assertA(0 == archive_read_next_header(a, &ae));
519 assertEqualString("test5.bin", archive_entry_pathname(ae));
520 assertA(0 == archive_read_next_header(a, &ae));
521 assertEqualString("test6.bin", archive_entry_pathname(ae));
522 assertA(0 == archive_read_next_header(a, &ae));
523 assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
524 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
528 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_first)
530 const char* reffiles[] = {
531 "test_read_format_rar5_multiarchive_solid.part01.rar",
532 "test_read_format_rar5_multiarchive_solid.part02.rar",
533 "test_read_format_rar5_multiarchive_solid.part03.rar",
534 "test_read_format_rar5_multiarchive_solid.part04.rar",
538 PROLOGUE_MULTI(reffiles);
539 assertA(0 == archive_read_next_header(a, &ae));
540 assertEqualString("cebula.txt", archive_entry_pathname(ae));
541 assertA(0 == extract_one(a, ae, 0x7E5EC49E));
542 assertA(0 == archive_read_next_header(a, &ae));
543 assertEqualString("test.bin", archive_entry_pathname(ae));
544 assertA(0 == archive_read_next_header(a, &ae));
545 assertEqualString("test1.bin", archive_entry_pathname(ae));
546 assertA(0 == archive_read_next_header(a, &ae));
547 assertEqualString("test2.bin", archive_entry_pathname(ae));
548 assertA(0 == archive_read_next_header(a, &ae));
549 assertEqualString("test3.bin", archive_entry_pathname(ae));
550 assertA(0 == archive_read_next_header(a, &ae));
551 assertEqualString("test4.bin", archive_entry_pathname(ae));
552 assertA(0 == archive_read_next_header(a, &ae));
553 assertEqualString("test5.bin", archive_entry_pathname(ae));
554 assertA(0 == archive_read_next_header(a, &ae));
555 assertEqualString("test6.bin", archive_entry_pathname(ae));
556 assertA(0 == archive_read_next_header(a, &ae));
557 assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
558 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
562 /* "skip_all_but_scnd" -> am I hitting the test name limit here after
563 * expansion of "scnd" to "second"? */
565 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_scnd)
567 const char* reffiles[] = {
568 "test_read_format_rar5_multiarchive_solid.part01.rar",
569 "test_read_format_rar5_multiarchive_solid.part02.rar",
570 "test_read_format_rar5_multiarchive_solid.part03.rar",
571 "test_read_format_rar5_multiarchive_solid.part04.rar",
575 PROLOGUE_MULTI(reffiles);
576 assertA(0 == archive_read_next_header(a, &ae));
577 assertEqualString("cebula.txt", archive_entry_pathname(ae));
578 assertA(0 == archive_read_next_header(a, &ae));
579 assertEqualString("test.bin", archive_entry_pathname(ae));
580 assertA(0 == extract_one(a, ae, 0x7CCA70CD));
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(ARCHIVE_EOF == archive_read_next_header(a, &ae));
599 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_third)
601 const char* reffiles[] = {
602 "test_read_format_rar5_multiarchive_solid.part01.rar",
603 "test_read_format_rar5_multiarchive_solid.part02.rar",
604 "test_read_format_rar5_multiarchive_solid.part03.rar",
605 "test_read_format_rar5_multiarchive_solid.part04.rar",
609 PROLOGUE_MULTI(reffiles);
610 assertA(0 == archive_read_next_header(a, &ae));
611 assertEqualString("cebula.txt", archive_entry_pathname(ae));
612 assertA(0 == archive_read_next_header(a, &ae));
613 assertEqualString("test.bin", archive_entry_pathname(ae));
614 assertA(0 == archive_read_next_header(a, &ae));
615 assertEqualString("test1.bin", archive_entry_pathname(ae));
616 assertA(0 == extract_one(a, ae, 0x7E13B2C6));
617 assertA(0 == archive_read_next_header(a, &ae));
618 assertEqualString("test2.bin", archive_entry_pathname(ae));
619 assertA(0 == archive_read_next_header(a, &ae));
620 assertEqualString("test3.bin", archive_entry_pathname(ae));
621 assertA(0 == archive_read_next_header(a, &ae));
622 assertEqualString("test4.bin", archive_entry_pathname(ae));
623 assertA(0 == archive_read_next_header(a, &ae));
624 assertEqualString("test5.bin", archive_entry_pathname(ae));
625 assertA(0 == archive_read_next_header(a, &ae));
626 assertEqualString("test6.bin", archive_entry_pathname(ae));
627 assertA(0 == archive_read_next_header(a, &ae));
628 assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
629 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
633 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_last)
635 const char* reffiles[] = {
636 "test_read_format_rar5_multiarchive_solid.part01.rar",
637 "test_read_format_rar5_multiarchive_solid.part02.rar",
638 "test_read_format_rar5_multiarchive_solid.part03.rar",
639 "test_read_format_rar5_multiarchive_solid.part04.rar",
643 PROLOGUE_MULTI(reffiles);
644 assertA(0 == archive_read_next_header(a, &ae));
645 assertEqualString("cebula.txt", archive_entry_pathname(ae));
646 assertA(0 == archive_read_next_header(a, &ae));
647 assertEqualString("test.bin", archive_entry_pathname(ae));
648 assertA(0 == archive_read_next_header(a, &ae));
649 assertEqualString("test1.bin", archive_entry_pathname(ae));
650 assertA(0 == archive_read_next_header(a, &ae));
651 assertEqualString("test2.bin", archive_entry_pathname(ae));
652 assertA(0 == archive_read_next_header(a, &ae));
653 assertEqualString("test3.bin", archive_entry_pathname(ae));
654 assertA(0 == archive_read_next_header(a, &ae));
655 assertEqualString("test4.bin", archive_entry_pathname(ae));
656 assertA(0 == archive_read_next_header(a, &ae));
657 assertEqualString("test5.bin", archive_entry_pathname(ae));
658 assertA(0 == archive_read_next_header(a, &ae));
659 assertEqualString("test6.bin", archive_entry_pathname(ae));
660 assertA(0 == archive_read_next_header(a, &ae));
661 assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
662 assertA(0 == extract_one(a, ae, 0x886F91EB));
663 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
667 DEFINE_TEST(test_read_format_rar5_solid_skip_all)
669 const char* reffile = "test_read_format_rar5_solid.rar";
674 assertA(0 == archive_read_next_header(a, &ae));
675 assertEqualString("test.bin", archive_entry_pathname(ae));
676 assertA(0 == archive_read_next_header(a, &ae));
677 assertEqualString("test1.bin", archive_entry_pathname(ae));
678 assertA(0 == archive_read_next_header(a, &ae));
679 assertEqualString("test2.bin", archive_entry_pathname(ae));
680 assertA(0 == archive_read_next_header(a, &ae));
681 assertEqualString("test3.bin", archive_entry_pathname(ae));
682 assertA(0 == archive_read_next_header(a, &ae));
683 assertEqualString("test4.bin", archive_entry_pathname(ae));
684 assertA(0 == archive_read_next_header(a, &ae));
685 assertEqualString("test5.bin", archive_entry_pathname(ae));
686 assertA(0 == archive_read_next_header(a, &ae));
687 assertEqualString("test6.bin", archive_entry_pathname(ae));
688 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
692 DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_first)
694 const char* reffile = "test_read_format_rar5_solid.rar";
696 /* Extract first, skip rest */
699 assertA(0 == archive_read_next_header(a, &ae));
700 assertEqualString("test.bin", archive_entry_pathname(ae));
701 assertA(0 == extract_one(a, ae, 0x7CCA70CD));
702 assertA(0 == archive_read_next_header(a, &ae));
703 assertEqualString("test1.bin", archive_entry_pathname(ae));
704 assertA(0 == archive_read_next_header(a, &ae));
705 assertEqualString("test2.bin", archive_entry_pathname(ae));
706 assertA(0 == archive_read_next_header(a, &ae));
707 assertEqualString("test3.bin", archive_entry_pathname(ae));
708 assertA(0 == archive_read_next_header(a, &ae));
709 assertEqualString("test4.bin", archive_entry_pathname(ae));
710 assertA(0 == archive_read_next_header(a, &ae));
711 assertEqualString("test5.bin", archive_entry_pathname(ae));
712 assertA(0 == archive_read_next_header(a, &ae));
713 assertEqualString("test6.bin", archive_entry_pathname(ae));
714 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
718 DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_second)
720 const char* reffile = "test_read_format_rar5_solid.rar";
722 /* Skip first, extract second, skip rest */
725 assertA(0 == archive_read_next_header(a, &ae));
726 assertEqualString("test.bin", archive_entry_pathname(ae));
727 assertA(0 == archive_read_next_header(a, &ae));
728 assertEqualString("test1.bin", archive_entry_pathname(ae));
729 assertA(0 == extract_one(a, ae, 0x7E13B2C6));
730 assertA(0 == archive_read_next_header(a, &ae));
731 assertEqualString("test2.bin", archive_entry_pathname(ae));
732 assertA(0 == archive_read_next_header(a, &ae));
733 assertEqualString("test3.bin", archive_entry_pathname(ae));
734 assertA(0 == archive_read_next_header(a, &ae));
735 assertEqualString("test4.bin", archive_entry_pathname(ae));
736 assertA(0 == archive_read_next_header(a, &ae));
737 assertEqualString("test5.bin", archive_entry_pathname(ae));
738 assertA(0 == archive_read_next_header(a, &ae));
739 assertEqualString("test6.bin", archive_entry_pathname(ae));
740 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
744 DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_last)
746 const char* reffile = "test_read_format_rar5_solid.rar";
748 /* Skip all but last, extract last */
751 assertA(0 == archive_read_next_header(a, &ae));
752 assertEqualString("test.bin", archive_entry_pathname(ae));
753 assertA(0 == archive_read_next_header(a, &ae));
754 assertEqualString("test1.bin", archive_entry_pathname(ae));
755 assertA(0 == archive_read_next_header(a, &ae));
756 assertEqualString("test2.bin", archive_entry_pathname(ae));
757 assertA(0 == archive_read_next_header(a, &ae));
758 assertEqualString("test3.bin", archive_entry_pathname(ae));
759 assertA(0 == archive_read_next_header(a, &ae));
760 assertEqualString("test4.bin", archive_entry_pathname(ae));
761 assertA(0 == archive_read_next_header(a, &ae));
762 assertEqualString("test5.bin", archive_entry_pathname(ae));
763 assertA(0 == archive_read_next_header(a, &ae));
764 assertEqualString("test6.bin", archive_entry_pathname(ae));
765 assertA(0 == extract_one(a, ae, 0x36A448FF));
766 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
770 DEFINE_TEST(test_read_format_rar5_extract_win32)
772 PROLOGUE("test_read_format_rar5_win32.rar");
773 assertA(0 == archive_read_next_header(a, &ae));
774 assertEqualString("testdir", archive_entry_pathname(ae));
775 assertEqualInt(archive_entry_mode(ae), AE_IFDIR | 0755);
776 assertA(0 == extract_one(a, ae, 0));
777 assertA(0 == archive_read_next_header(a, &ae));
778 assertEqualString("test.bin", archive_entry_pathname(ae));
779 assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
780 assertA(0 == extract_one(a, ae, 0x7CCA70CD));
781 assertA(0 == archive_read_next_header(a, &ae));
782 assertEqualString("test1.bin", archive_entry_pathname(ae));
783 assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
784 assertA(0 == extract_one(a, ae, 0x7E13B2C6));
785 assertA(0 == archive_read_next_header(a, &ae));
787 assertEqualString("test2.bin", archive_entry_pathname(ae));
788 assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0444);
789 assertA(0 == extract_one(a, ae, 0xF166AFCB));
790 assertA(0 == archive_read_next_header(a, &ae));
791 assertEqualString("test3.bin", archive_entry_pathname(ae));
792 assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
793 assertA(0 == extract_one(a, ae, 0x9FB123D9));
794 assertA(0 == archive_read_next_header(a, &ae));
795 assertEqualString("test4.bin", archive_entry_pathname(ae));
796 assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
797 assertA(0 == extract_one(a, ae, 0x10C43ED4));
798 assertA(0 == archive_read_next_header(a, &ae));
799 assertEqualString("test5.bin", archive_entry_pathname(ae));
800 assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
801 assertA(0 == extract_one(a, ae, 0xB9D155F2));
802 assertA(0 == archive_read_next_header(a, &ae));
803 assertEqualString("test6.bin", archive_entry_pathname(ae));
804 assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
805 assertA(0 == extract_one(a, ae, 0x36A448FF));
809 DEFINE_TEST(test_read_format_rar5_block_by_block)
811 /* This test uses strange buffer sizes intentionally. */
813 struct archive_entry *ae;
817 uint32_t computed_crc = 0;
819 extract_reference_file("test_read_format_rar5_compressed.rar");
820 assert((a = archive_read_new()) != NULL);
821 assertA(0 == archive_read_support_filter_all(a));
822 assertA(0 == archive_read_support_format_all(a));
823 assertA(0 == archive_read_open_filename(a, "test_read_format_rar5_compressed.rar", 130));
824 assertA(0 == archive_read_next_header(a, &ae));
825 assertEqualString("test.bin", archive_entry_pathname(ae));
826 assertEqualInt(1200, archive_entry_size(ae));
828 /* File size is 1200 bytes, we're reading it using a buffer of 173 bytes.
829 * Libarchive is configured to use a buffer of 130 bytes. */
832 /* archive_read_data should return one of:
833 * a) 0, if there is no more data to be read,
834 * b) negative value, if there was an error,
835 * c) positive value, meaning how many bytes were read.
838 bytes_read = archive_read_data(a, buf, sizeof(buf));
839 assertA(bytes_read >= 0);
843 computed_crc = crc32(computed_crc, buf, bytes_read);
846 assertEqualInt(computed_crc, 0x7CCA70CD);
850 DEFINE_TEST(test_read_format_rar5_owner)
852 const int DATA_SIZE = 5;
855 PROLOGUE("test_read_format_rar5_owner.rar");
857 assertA(0 == archive_read_next_header(a, &ae));
858 assertEqualString("root.txt", archive_entry_pathname(ae));
859 assertEqualString("root", archive_entry_uname(ae));
860 assertEqualString("wheel", archive_entry_gname(ae));
861 assertA((int) archive_entry_mtime(ae) > 0);
862 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
863 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
865 assertA(0 == archive_read_next_header(a, &ae));
866 assertEqualString("nobody.txt", archive_entry_pathname(ae));
867 assertEqualString("nobody", archive_entry_uname(ae));
868 assertEqualString("nogroup", archive_entry_gname(ae));
869 assertA((int) archive_entry_mtime(ae) > 0);
870 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
871 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
873 assertA(0 == archive_read_next_header(a, &ae));
874 assertEqualString("numeric.txt", archive_entry_pathname(ae));
875 assertEqualInt(9999, archive_entry_uid(ae));
876 assertEqualInt(8888, archive_entry_gid(ae));
877 assertA((int) archive_entry_mtime(ae) > 0);
878 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
879 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
881 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
886 DEFINE_TEST(test_read_format_rar5_symlink)
888 const int DATA_SIZE = 5;
891 PROLOGUE("test_read_format_rar5_symlink.rar");
893 assertA(0 == archive_read_next_header(a, &ae));
894 assertEqualString("file.txt", archive_entry_pathname(ae));
895 assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
896 assertA((int) archive_entry_mtime(ae) > 0);
897 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
898 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
900 assertA(0 == archive_read_next_header(a, &ae));
901 assertEqualString("symlink.txt", archive_entry_pathname(ae));
902 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
903 assertEqualString("file.txt", archive_entry_symlink(ae));
904 assertEqualInt(AE_SYMLINK_TYPE_FILE, archive_entry_symlink_type(ae));
905 assertA(0 == archive_read_data(a, NULL, archive_entry_size(ae)));
907 assertA(0 == archive_read_next_header(a, &ae));
908 assertEqualString("dirlink", archive_entry_pathname(ae));
909 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
910 assertEqualString("dir", archive_entry_symlink(ae));
911 assertEqualInt(AE_SYMLINK_TYPE_DIRECTORY, archive_entry_symlink_type(ae));
912 assertA(0 == archive_read_data(a, NULL, archive_entry_size(ae)));
914 assertA(0 == archive_read_next_header(a, &ae));
915 assertEqualString("dir", archive_entry_pathname(ae));
916 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
917 assertA(0 == archive_read_data(a, NULL, archive_entry_size(ae)));
919 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
924 DEFINE_TEST(test_read_format_rar5_hardlink)
926 const int DATA_SIZE = 5;
929 PROLOGUE("test_read_format_rar5_hardlink.rar");
931 assertA(0 == archive_read_next_header(a, &ae));
932 assertEqualString("file.txt", archive_entry_pathname(ae));
933 assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
934 assertA((int) archive_entry_mtime(ae) > 0);
935 assertEqualInt(DATA_SIZE, archive_entry_size(ae));
936 assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
938 assertA(0 == archive_read_next_header(a, &ae));
939 assertEqualString("hardlink.txt", archive_entry_pathname(ae));
940 assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
941 assertEqualString("file.txt", archive_entry_hardlink(ae));
942 assertA(0 == archive_read_data(a, NULL, archive_entry_size(ae)));
944 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
949 DEFINE_TEST(test_read_format_rar5_extra_field_version)
951 PROLOGUE("test_read_format_rar5_extra_field_version.rar");
953 assertA(0 == archive_read_next_header(a, &ae));
954 assertEqualString("bin/2to3;1", archive_entry_pathname(ae));
955 assertA(0 == extract_one(a, ae, 0xF24181B7));
957 assertA(0 == archive_read_next_header(a, &ae));
958 assertEqualString("bin/2to3", archive_entry_pathname(ae));
959 assertA(0 == extract_one(a, ae, 0xF24181B7));
961 assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
966 DEFINE_TEST(test_read_format_rar5_readtables_overflow)
970 PROLOGUE("test_read_format_rar5_readtables_overflow.rar");
972 assertA(0 == archive_read_next_header(a, &ae));
973 /* This archive is invalid. However, processing it shouldn't cause any
974 * buffer overflow errors during reading rar5 tables. */
975 assertA(archive_read_data(a, buf, sizeof(buf)) <= 0);
977 /* This test only cares about not returning success here. */
978 assertA(ARCHIVE_OK != archive_read_next_header(a, &ae));
983 DEFINE_TEST(test_read_format_rar5_leftshift1)
987 PROLOGUE("test_read_format_rar5_leftshift1.rar");
989 assertA(0 == archive_read_next_header(a, &ae));
990 /* This archive is invalid. However, processing it shouldn't cause any
991 * errors related to undefined operations when using -fsanitize. */
992 assertA(archive_read_data(a, buf, sizeof(buf)) <= 0);
994 /* This test only cares about not returning success here. */
995 assertA(ARCHIVE_OK != archive_read_next_header(a, &ae));
1000 DEFINE_TEST(test_read_format_rar5_leftshift2)
1004 PROLOGUE("test_read_format_rar5_leftshift2.rar");
1006 assertA(0 == archive_read_next_header(a, &ae));
1008 /* This archive is invalid. However, processing it shouldn't cause any
1009 * errors related to undefined operations when using -fsanitize. */
1010 assertA(archive_read_data(a, buf, sizeof(buf)) <= 0);
1012 /* This test only cares about not returning success here. */
1013 assertA(ARCHIVE_OK != archive_read_next_header(a, &ae));
1018 DEFINE_TEST(test_read_format_rar5_truncated_huff)
1022 PROLOGUE("test_read_format_rar5_truncated_huff.rar");
1024 assertA(0 == archive_read_next_header(a, &ae));
1026 /* This archive is invalid. However, processing it shouldn't cause any
1027 * errors related to undefined operations when using -fsanitize. */
1028 assertA(archive_read_data(a, buf, sizeof(buf)) <= 0);
1030 /* This test only cares about not returning success here. */
1031 assertA(ARCHIVE_OK != archive_read_next_header(a, &ae));
1036 DEFINE_TEST(test_read_format_rar5_invalid_dict_reference)
1040 PROLOGUE("test_read_format_rar5_invalid_dict_reference.rar");
1042 /* This test should fail on parsing the header. */
1043 assertA(archive_read_next_header(a, &ae) != ARCHIVE_OK);
1045 /* This archive is invalid. However, processing it shouldn't cause any
1046 * errors related to buffer underflow when using -fsanitize. */
1047 assertA(archive_read_data(a, buf, sizeof(buf)) <= 0);
1049 /* This test only cares about not returning success here. */
1050 assertA(ARCHIVE_OK != archive_read_next_header(a, &ae));
1055 DEFINE_TEST(test_read_format_rar5_distance_overflow)
1059 PROLOGUE("test_read_format_rar5_distance_overflow.rar");
1061 assertA(0 == archive_read_next_header(a, &ae));
1063 /* This archive is invalid. However, processing it shouldn't cause any
1064 * errors related to variable overflows when using -fsanitize. */
1065 assertA(archive_read_data(a, buf, sizeof(buf)) <= 0);
1067 /* This test only cares about not returning success here. */
1068 assertA(ARCHIVE_OK != archive_read_next_header(a, &ae));
1073 DEFINE_TEST(test_read_format_rar5_nonempty_dir_stream)
1077 PROLOGUE("test_read_format_rar5_nonempty_dir_stream.rar");
1079 assertA(0 == archive_read_next_header(a, &ae));
1081 /* This archive is invalid. However, processing it shouldn't cause any
1082 * errors related to buffer overflows when using -fsanitize. */
1083 assertA(archive_read_data(a, buf, sizeof(buf)) <= 0);
1085 /* This test only cares about not returning success here. */
1086 assertA(ARCHIVE_OK != archive_read_next_header(a, &ae));
1091 DEFINE_TEST(test_read_format_rar5_fileattr)
1093 unsigned long set, clear, flag;
1097 PROLOGUE("test_read_format_rar5_fileattr.rar");
1099 assertA(0 == archive_read_next_header(a, &ae));
1100 assertEqualInt(archive_entry_mode(ae), 0444 | AE_IFREG);
1101 assertEqualString("readonly.txt", archive_entry_pathname(ae));
1102 assertEqualString("rdonly", archive_entry_fflags_text(ae));
1103 archive_entry_fflags(ae, &set, &clear);
1104 #if defined(__FreeBSD__)
1106 #elif defined(_WIN32) && !defined(CYGWIN)
1107 flag = FILE_ATTRIBUTE_READONLY;
1109 assertEqualInt(flag, set & flag);
1111 assertA(0 == archive_read_next_header(a, &ae));
1112 assertEqualInt(archive_entry_mode(ae), 0644 | AE_IFREG);
1113 assertEqualString("hidden.txt", archive_entry_pathname(ae));
1114 assertEqualString("hidden", archive_entry_fflags_text(ae));
1115 archive_entry_fflags(ae, &set, &clear);
1116 #if defined(__FreeBSD__)
1118 #elif defined(_WIN32) && !defined(CYGWIN)
1119 flag = FILE_ATTRIBUTE_HIDDEN;
1121 assertEqualInt(flag, set & flag);
1123 assertA(0 == archive_read_next_header(a, &ae));
1124 assertEqualInt(archive_entry_mode(ae), 0644 | AE_IFREG);
1125 assertEqualString("system.txt", archive_entry_pathname(ae));
1126 assertEqualString("system", archive_entry_fflags_text(ae));
1127 archive_entry_fflags(ae, &set, &clear);
1128 #if defined(__FreeBSD__)
1130 #elif defined(_WIN32) && !defined(CYGWIN)
1131 flag = FILE_ATTRIBUTE_SYSTEM;
1133 assertEqualInt(flag, set & flag);
1135 assertA(0 == archive_read_next_header(a, &ae));
1136 assertEqualInt(archive_entry_mode(ae), 0444 | AE_IFREG);
1137 assertEqualString("ro_hidden.txt", archive_entry_pathname(ae));
1138 assertEqualString("rdonly,hidden", archive_entry_fflags_text(ae));
1139 archive_entry_fflags(ae, &set, &clear);
1140 #if defined(__FreeBSD__)
1141 flag = UF_READONLY | UF_HIDDEN;
1142 #elif defined(_WIN32) && !defined(CYGWIN)
1143 flag = FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN;
1145 assertEqualInt(flag, set & flag);
1147 assertA(0 == archive_read_next_header(a, &ae));
1148 assertEqualInt(archive_entry_mode(ae), 0555 | AE_IFDIR);
1149 assertEqualString("dir_readonly", archive_entry_pathname(ae));
1150 assertEqualString("rdonly", archive_entry_fflags_text(ae));
1151 archive_entry_fflags(ae, &set, &clear);
1152 #if defined(__FreeBSD__)
1154 #elif defined(_WIN32) && !defined(CYGWIN)
1155 flag = FILE_ATTRIBUTE_READONLY;
1157 assertEqualInt(flag, set & flag);
1159 assertA(0 == archive_read_next_header(a, &ae));
1160 assertEqualInt(archive_entry_mode(ae), 0755 | AE_IFDIR);
1161 assertEqualString("dir_hidden", archive_entry_pathname(ae));
1162 assertEqualString("hidden", archive_entry_fflags_text(ae));
1163 archive_entry_fflags(ae, &set, &clear);
1164 #if defined(__FreeBSD__)
1166 #elif defined(_WIN32) && !defined(CYGWIN)
1167 flag = FILE_ATTRIBUTE_HIDDEN;
1169 assertEqualInt(flag, set & flag);
1171 assertA(0 == archive_read_next_header(a, &ae));
1172 assertEqualInt(archive_entry_mode(ae), 0755 | AE_IFDIR);
1173 assertEqualString("dir_system", archive_entry_pathname(ae));
1174 assertEqualString("system", archive_entry_fflags_text(ae));
1175 archive_entry_fflags(ae, &set, &clear);
1176 #if defined(__FreeBSD__)
1178 #elif defined(_WIN32) && !defined(CYGWIN)
1179 flag = FILE_ATTRIBUTE_SYSTEM;
1181 assertEqualInt(flag, set & flag);
1183 assertA(0 == archive_read_next_header(a, &ae));
1184 assertEqualInt(archive_entry_mode(ae), 0555 | AE_IFDIR);
1185 assertEqualString("dir_rohidden", archive_entry_pathname(ae));
1186 assertEqualString("rdonly,hidden", archive_entry_fflags_text(ae));
1187 archive_entry_fflags(ae, &set, &clear);
1188 #if defined(__FreeBSD__)
1189 flag = UF_READONLY | UF_HIDDEN;
1190 #elif defined(_WIN32) && !defined(CYGWIN)
1191 flag = FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN;
1193 assertEqualInt(flag, set & flag);