]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/libarchive/libarchive/test/test_compat_mac.c
MFC r299529,r299540,r299576,r299896:
[FreeBSD/stable/10.git] / contrib / libarchive / libarchive / test / test_compat_mac.c
1 /*-
2  * Copyright (c) 2003-2010 Tim Kientzle
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 __FBSDID("$FreeBSD$");
27
28 /* The sample has some files in a directory with a very long name. */
29 #define TESTPATH "abcdefghijklmnopqrstuvwxyz/"  \
30         "abcdefghijklmnopqrstuvwxyz/"   \
31         "abcdefghijklmnopqrstuvwxyz/"   \
32         "abcdefghijklmnopqrstuvwxyz/"   \
33         "abcdefghijklmnopqrstuvwxyz/"   \
34         "abcdefghijklmnopqrstuvwxyz/"   \
35         "abcdefghijklmnopqrstuvwxyz/"
36
37 static void test_compat_mac_1(void);
38 static void test_compat_mac_2(void);
39
40 /*
41  * Apple shipped an extended version of GNU tar with Mac OS X 10.5
42  * and earlier.
43  */
44 static void
45 test_compat_mac_1(void)
46 {
47         char name[] = "test_compat_mac-1.tar.Z";
48         struct archive_entry *ae;
49         struct archive *a;
50         const void *attr;
51         size_t attrSize;
52
53         assert((a = archive_read_new()) != NULL);
54         assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
55         assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
56         assertEqualIntA(a, ARCHIVE_OK, archive_read_set_options(a, "mac-ext"));
57         extract_reference_file(name);
58         assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240));
59
60         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
61         assertEqualString(TESTPATH, archive_entry_pathname(ae));
62         assertEqualInt(1275688109, archive_entry_mtime(ae));
63         assertEqualInt(95594, archive_entry_uid(ae));
64         assertEqualString("kientzle", archive_entry_uname(ae));
65         assertEqualInt(5000, archive_entry_gid(ae));
66         assertEqualString("", archive_entry_gname(ae));
67         assertEqualInt(040755, archive_entry_mode(ae));
68
69         attr = archive_entry_mac_metadata(ae, &attrSize);
70         assert(attr == NULL);
71         assertEqualInt(0, attrSize);
72
73         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
74         assertEqualString(TESTPATH "dir/", archive_entry_pathname(ae));
75         assertEqualInt(1275687611, archive_entry_mtime(ae));
76         assertEqualInt(95594, archive_entry_uid(ae));
77         assertEqualString("kientzle", archive_entry_uname(ae));
78         assertEqualInt(5000, archive_entry_gid(ae));
79         assertEqualString("", archive_entry_gname(ae));
80         assertEqualInt(040755, archive_entry_mode(ae));
81
82         attr = archive_entry_mac_metadata(ae, &attrSize);
83         assert(attr != NULL);
84         assertEqualInt(225, attrSize);
85
86         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
87         assertEqualString(TESTPATH "file", archive_entry_pathname(ae));
88         assertEqualInt(1275687588, archive_entry_mtime(ae));
89         assertEqualInt(95594, archive_entry_uid(ae));
90         assertEqualString("kientzle", archive_entry_uname(ae));
91         assertEqualInt(5000, archive_entry_gid(ae));
92         assertEqualString("", archive_entry_gname(ae));
93         assertEqualInt(0100644, archive_entry_mode(ae));
94
95         attr = archive_entry_mac_metadata(ae, &attrSize);
96         assert(attr != NULL);
97         assertEqualInt(225, attrSize);
98
99         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
100         assertEqualString("dir/", archive_entry_pathname(ae));
101         assertEqualInt(1275688064, archive_entry_mtime(ae));
102         assertEqualInt(95594, archive_entry_uid(ae));
103         assertEqualString("kientzle", archive_entry_uname(ae));
104         assertEqualInt(5000, archive_entry_gid(ae));
105         assertEqualString("", archive_entry_gname(ae));
106         assertEqualInt(040755, archive_entry_mode(ae));
107
108         attr = archive_entry_mac_metadata(ae, &attrSize);
109         assert(attr != NULL);
110         assertEqualInt(225, attrSize);
111         assertEqualMem("\x00\x05\x16\x07\x00\x02\x00\x00Mac OS X", attr, 16);
112
113         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
114         assertEqualString("file", archive_entry_pathname(ae));
115         assertEqualInt(1275625860, archive_entry_mtime(ae));
116         assertEqualInt(95594, archive_entry_uid(ae));
117         assertEqualString("kientzle", archive_entry_uname(ae));
118         assertEqualInt(5000, archive_entry_gid(ae));
119         assertEqualString("", archive_entry_gname(ae));
120         assertEqualInt(0100644, archive_entry_mode(ae));
121
122         attr = archive_entry_mac_metadata(ae, &attrSize);
123         assert(attr != NULL);
124         assertEqualInt(225, attrSize);
125         assertEqualMem("\x00\x05\x16\x07\x00\x02\x00\x00Mac OS X", attr, 16);
126
127         /* Verify the end-of-archive. */
128         assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
129
130         /* Verify that the format detection worked. */
131         assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
132         assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_GNUTAR);
133
134         assertEqualInt(ARCHIVE_OK, archive_read_close(a));
135         assertEqualInt(ARCHIVE_OK, archive_read_free(a));
136 }
137
138 /*
139  * Apple shipped a customized version of bsdtar starting with MacOS 10.6.
140  */
141 static void
142 test_compat_mac_2(void)
143 {
144         char name[] = "test_compat_mac-2.tar.Z";
145         struct archive_entry *ae;
146         struct archive *a;
147         const void *attr;
148         size_t attrSize;
149
150         assert((a = archive_read_new()) != NULL);
151         assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
152         assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
153         assertEqualIntA(a, ARCHIVE_OK, archive_read_set_options(a, "mac-ext"));
154         extract_reference_file(name);
155         assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240));
156
157         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
158         assertEqualString("./", archive_entry_pathname(ae));
159         assertEqualInt(1303628303, archive_entry_mtime(ae));
160         assertEqualInt(501, archive_entry_uid(ae));
161         assertEqualString("tim", archive_entry_uname(ae));
162         assertEqualInt(20, archive_entry_gid(ae));
163         assertEqualString("staff", archive_entry_gname(ae));
164         assertEqualInt(040755, archive_entry_mode(ae));
165
166         attr = archive_entry_mac_metadata(ae, &attrSize);
167         assert(attr == NULL);
168         assertEqualInt(0, attrSize);
169
170         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
171         assertEqualString("./mydir/", archive_entry_pathname(ae));
172         assertEqualInt(1303628303, archive_entry_mtime(ae));
173         assertEqualInt(501, archive_entry_uid(ae));
174         assertEqualString("tim", archive_entry_uname(ae));
175         assertEqualInt(20, archive_entry_gid(ae));
176         assertEqualString("staff", archive_entry_gname(ae));
177         assertEqualInt(040755, archive_entry_mode(ae));
178
179         attr = archive_entry_mac_metadata(ae, &attrSize);
180         assert(attr != NULL);
181         assertEqualInt(267, attrSize);
182         assertEqualMem("\x00\x05\x16\x07\x00\x02\x00\x00Mac OS X", attr, 16);
183
184         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
185         assertEqualString("./myfile", archive_entry_pathname(ae));
186         assertEqualInt(1303628303, archive_entry_mtime(ae));
187         assertEqualInt(501, archive_entry_uid(ae));
188         assertEqualString("tim", archive_entry_uname(ae));
189         assertEqualInt(20, archive_entry_gid(ae));
190         assertEqualString("staff", archive_entry_gname(ae));
191         assertEqualInt(0100644, archive_entry_mode(ae));
192
193         attr = archive_entry_mac_metadata(ae, &attrSize);
194         assert(attr != NULL);
195         assertEqualInt(267, attrSize);
196         assertEqualMem("\x00\x05\x16\x07\x00\x02\x00\x00Mac OS X", attr, 16);
197
198         /* Verify the end-of-archive. */
199         assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
200
201         /* Verify that the format detection worked. */
202         assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
203         assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR);
204
205         assertEqualInt(ARCHIVE_OK, archive_read_close(a));
206         assertEqualInt(ARCHIVE_OK, archive_read_free(a));
207 }
208
209 DEFINE_TEST(test_compat_mac)
210 {
211         test_compat_mac_1();
212         test_compat_mac_2();
213 }
214