]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/libarchive/libarchive/test/test_compat_mac.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.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         extract_reference_file(name);
57         assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240));
58
59         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
60         assertEqualString(TESTPATH, archive_entry_pathname(ae));
61         assertEqualInt(1275688109, archive_entry_mtime(ae));
62         assertEqualInt(95594, archive_entry_uid(ae));
63         assertEqualString("kientzle", archive_entry_uname(ae));
64         assertEqualInt(5000, archive_entry_gid(ae));
65         assertEqualString("", archive_entry_gname(ae));
66         assertEqualInt(040755, archive_entry_mode(ae));
67
68         attr = archive_entry_mac_metadata(ae, &attrSize);
69         assert(attr == NULL);
70         assertEqualInt(0, attrSize);
71
72         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
73         assertEqualString(TESTPATH "dir/", archive_entry_pathname(ae));
74         assertEqualInt(1275687611, archive_entry_mtime(ae));
75         assertEqualInt(95594, archive_entry_uid(ae));
76         assertEqualString("kientzle", archive_entry_uname(ae));
77         assertEqualInt(5000, archive_entry_gid(ae));
78         assertEqualString("", archive_entry_gname(ae));
79         assertEqualInt(040755, archive_entry_mode(ae));
80
81         attr = archive_entry_mac_metadata(ae, &attrSize);
82         assert(attr != NULL);
83         assertEqualInt(225, attrSize);
84
85         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
86         assertEqualString(TESTPATH "file", archive_entry_pathname(ae));
87         assertEqualInt(1275687588, archive_entry_mtime(ae));
88         assertEqualInt(95594, archive_entry_uid(ae));
89         assertEqualString("kientzle", archive_entry_uname(ae));
90         assertEqualInt(5000, archive_entry_gid(ae));
91         assertEqualString("", archive_entry_gname(ae));
92         assertEqualInt(0100644, archive_entry_mode(ae));
93
94         attr = archive_entry_mac_metadata(ae, &attrSize);
95         assert(attr != NULL);
96         assertEqualInt(225, attrSize);
97
98         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
99         assertEqualString("dir/", archive_entry_pathname(ae));
100         assertEqualInt(1275688064, archive_entry_mtime(ae));
101         assertEqualInt(95594, archive_entry_uid(ae));
102         assertEqualString("kientzle", archive_entry_uname(ae));
103         assertEqualInt(5000, archive_entry_gid(ae));
104         assertEqualString("", archive_entry_gname(ae));
105         assertEqualInt(040755, archive_entry_mode(ae));
106
107         attr = archive_entry_mac_metadata(ae, &attrSize);
108         assert(attr != NULL);
109         assertEqualInt(225, attrSize);
110         assertEqualMem("\x00\x05\x16\x07\x00\x02\x00\x00Mac OS X", attr, 16);
111
112         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
113         assertEqualString("file", archive_entry_pathname(ae));
114         assertEqualInt(1275625860, archive_entry_mtime(ae));
115         assertEqualInt(95594, archive_entry_uid(ae));
116         assertEqualString("kientzle", archive_entry_uname(ae));
117         assertEqualInt(5000, archive_entry_gid(ae));
118         assertEqualString("", archive_entry_gname(ae));
119         assertEqualInt(0100644, archive_entry_mode(ae));
120
121         attr = archive_entry_mac_metadata(ae, &attrSize);
122         assert(attr != NULL);
123         assertEqualInt(225, attrSize);
124         assertEqualMem("\x00\x05\x16\x07\x00\x02\x00\x00Mac OS X", attr, 16);
125
126         /* Verify the end-of-archive. */
127         assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
128
129         /* Verify that the format detection worked. */
130         assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
131         assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_GNUTAR);
132
133         assertEqualInt(ARCHIVE_OK, archive_read_close(a));
134         assertEqualInt(ARCHIVE_OK, archive_read_free(a));
135 }
136
137 /*
138  * Apple shipped a customized version of bsdtar starting with MacOS 10.6.
139  */
140 static void
141 test_compat_mac_2(void)
142 {
143         char name[] = "test_compat_mac-2.tar.Z";
144         struct archive_entry *ae;
145         struct archive *a;
146         const void *attr;
147         size_t attrSize;
148
149         assert((a = archive_read_new()) != NULL);
150         assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
151         assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
152         extract_reference_file(name);
153         assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240));
154
155         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
156         assertEqualString("./", archive_entry_pathname(ae));
157         assertEqualInt(1303628303, archive_entry_mtime(ae));
158         assertEqualInt(501, archive_entry_uid(ae));
159         assertEqualString("tim", archive_entry_uname(ae));
160         assertEqualInt(20, archive_entry_gid(ae));
161         assertEqualString("staff", archive_entry_gname(ae));
162         assertEqualInt(040755, archive_entry_mode(ae));
163
164         attr = archive_entry_mac_metadata(ae, &attrSize);
165         assert(attr == NULL);
166         assertEqualInt(0, attrSize);
167
168         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
169         assertEqualString("./mydir/", archive_entry_pathname(ae));
170         assertEqualInt(1303628303, archive_entry_mtime(ae));
171         assertEqualInt(501, archive_entry_uid(ae));
172         assertEqualString("tim", archive_entry_uname(ae));
173         assertEqualInt(20, archive_entry_gid(ae));
174         assertEqualString("staff", archive_entry_gname(ae));
175         assertEqualInt(040755, archive_entry_mode(ae));
176
177         attr = archive_entry_mac_metadata(ae, &attrSize);
178         assert(attr != NULL);
179         assertEqualInt(267, attrSize);
180         assertEqualMem("\x00\x05\x16\x07\x00\x02\x00\x00Mac OS X", attr, 16);
181
182         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
183         assertEqualString("./myfile", archive_entry_pathname(ae));
184         assertEqualInt(1303628303, archive_entry_mtime(ae));
185         assertEqualInt(501, archive_entry_uid(ae));
186         assertEqualString("tim", archive_entry_uname(ae));
187         assertEqualInt(20, archive_entry_gid(ae));
188         assertEqualString("staff", archive_entry_gname(ae));
189         assertEqualInt(0100644, archive_entry_mode(ae));
190
191         attr = archive_entry_mac_metadata(ae, &attrSize);
192         assert(attr != NULL);
193         assertEqualInt(267, attrSize);
194         assertEqualMem("\x00\x05\x16\x07\x00\x02\x00\x00Mac OS X", attr, 16);
195
196         /* Verify the end-of-archive. */
197         assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
198
199         /* Verify that the format detection worked. */
200         assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
201         assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR);
202
203         assertEqualInt(ARCHIVE_OK, archive_read_close(a));
204         assertEqualInt(ARCHIVE_OK, archive_read_free(a));
205 }
206
207 DEFINE_TEST(test_compat_mac)
208 {
209         test_compat_mac_1();
210         test_compat_mac_2();
211 }
212