1 /*-
2 * Copyright (c) 2007 Kai Wang
3 * Copyright (c) 2007 Tim Kientzle
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
15 *
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.
26 */
27
28 #include "test.h"
29
DEFINE_TEST(test_read_format_ar)30 DEFINE_TEST(test_read_format_ar)
31 {
32 char buff[64];
33 const char reffile[] = "test_read_format_ar.ar";
34 struct archive_entry *ae;
35 struct archive *a;
36
37 extract_reference_file(reffile);
38 assert((a = archive_read_new()) != NULL);
39 assertA(0 == archive_read_support_filter_all(a));
40 assertA(0 == archive_read_support_format_all(a));
41 assertA(0 == archive_read_open_filename(a, reffile, 7));
42
43 /* Filename table. */
44 assertA(0 == archive_read_next_header(a, &ae));
45 assertEqualString("//", archive_entry_pathname(ae));
46 assertEqualInt(0, archive_entry_mtime(ae));
47 assertEqualInt(0, archive_entry_uid(ae));
48 assertEqualInt(0, archive_entry_gid(ae));
49 assertEqualInt(0, archive_entry_size(ae));
50 assertEqualInt(archive_entry_is_encrypted(ae), 0);
51 assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
52
53 /* First Entry */
54 assertA(0 == archive_read_next_header(a, &ae));
55 assertEqualString("yyytttsssaaafff.o", archive_entry_pathname(ae));
56 assertEqualInt(1175465652, archive_entry_mtime(ae));
57 assertEqualInt(1001, archive_entry_uid(ae));
58 assertEqualInt(0, archive_entry_gid(ae));
59 assert(8 == archive_entry_size(ae));
60 assertA(8 == archive_read_data(a, buff, 10));
61 assertEqualMem(buff, "55667788", 8);
62 assertEqualInt(archive_entry_is_encrypted(ae), 0);
63 assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
64
65 /* Second Entry */
66 assertA(0 == archive_read_next_header(a, &ae));
67 assertEqualString("gghh.o", archive_entry_pathname(ae));
68 assertEqualInt(1175465668, archive_entry_mtime(ae));
69 assertEqualInt(1001, archive_entry_uid(ae));
70 assertEqualInt(0, archive_entry_gid(ae));
71 assert(4 == archive_entry_size(ae));
72 assertA(4 == archive_read_data(a, buff, 10));
73 assertEqualMem(buff, "3333", 4);
74 assertEqualInt(archive_entry_is_encrypted(ae), 0);
75 assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
76
77 /* Third Entry */
78 assertA(0 == archive_read_next_header(a, &ae));
79 assertEqualString("hhhhjjjjkkkkllll.o", archive_entry_pathname(ae));
80 assertEqualInt(1175465713, archive_entry_mtime(ae));
81 assertEqualInt(1001, archive_entry_uid(ae));
82 assertEqualInt(0, archive_entry_gid(ae));
83 assert(9 == archive_entry_size(ae));
84 assertA(9 == archive_read_data(a, buff, 9));
85 assertEqualMem(buff, "987654321", 9);
86
87 /* Test EOF */
88 assertA(1 == archive_read_next_header(a, &ae));
89 assertEqualInt(4, archive_file_count(a));
90 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
91 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
92 }
93