2 * Copyright (c) 2007 Kai Wang
3 * Copyright (c) 2007 Tim Kientzle
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer
11 * in this position and unchanged.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 __FBSDID("$FreeBSD$");
32 DEFINE_TEST(test_read_format_ar)
35 const char reffile[] = "test_read_format_ar.ar";
36 struct archive_entry *ae;
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, 7));
46 assertA(0 == archive_read_next_header(a, &ae));
47 assertEqualString("//", archive_entry_pathname(ae));
48 assertEqualInt(0, archive_entry_mtime(ae));
49 assertEqualInt(0, archive_entry_uid(ae));
50 assertEqualInt(0, archive_entry_gid(ae));
51 assertEqualInt(0, archive_entry_size(ae));
52 assertEqualInt(archive_entry_is_encrypted(ae), 0);
53 assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
56 assertA(0 == archive_read_next_header(a, &ae));
57 assertEqualString("yyytttsssaaafff.o", archive_entry_pathname(ae));
58 assertEqualInt(1175465652, archive_entry_mtime(ae));
59 assertEqualInt(1001, archive_entry_uid(ae));
60 assertEqualInt(0, archive_entry_gid(ae));
61 assert(8 == archive_entry_size(ae));
62 assertA(8 == archive_read_data(a, buff, 10));
63 assertEqualMem(buff, "55667788", 8);
64 assertEqualInt(archive_entry_is_encrypted(ae), 0);
65 assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
68 assertA(0 == archive_read_next_header(a, &ae));
69 assertEqualString("gghh.o", archive_entry_pathname(ae));
70 assertEqualInt(1175465668, archive_entry_mtime(ae));
71 assertEqualInt(1001, archive_entry_uid(ae));
72 assertEqualInt(0, archive_entry_gid(ae));
73 assert(4 == archive_entry_size(ae));
74 assertA(4 == archive_read_data(a, buff, 10));
75 assertEqualMem(buff, "3333", 4);
76 assertEqualInt(archive_entry_is_encrypted(ae), 0);
77 assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
80 assertA(0 == archive_read_next_header(a, &ae));
81 assertEqualString("hhhhjjjjkkkkllll.o", archive_entry_pathname(ae));
82 assertEqualInt(1175465713, archive_entry_mtime(ae));
83 assertEqualInt(1001, archive_entry_uid(ae));
84 assertEqualInt(0, archive_entry_gid(ae));
85 assert(9 == archive_entry_size(ae));
86 assertA(9 == archive_read_data(a, buff, 9));
87 assertEqualMem(buff, "987654321", 9);
90 assertA(1 == archive_read_next_header(a, &ae));
91 assertEqualInt(4, archive_file_count(a));
92 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
93 assertEqualInt(ARCHIVE_OK, archive_read_free(a));