2 * Copyright (c) 2008, 2010 Michihiro NAKAJIMA
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.
29 Execute the following command to rebuild the data for this program:
30 tail -n +32 test_read_format_lha.c | /bin/sh
34 # How to make test data.
36 # Temporary directory.
43 # Make contents of a lha archive.
48 cat > ${base}/file1 << END
54 cat > ${base}/file2 << END
65 # Set up a file mode, owner and group.
67 (cd ${base}/dir2; ln -s ../file1 symlink1)
68 (cd ${base}/dir2; ln -s ../file2 symlink2)
69 (cd ${base}; chown ${owner}:${group} dir file1 file2)
70 (cd ${base}; chown -h ${owner}:${group} dir2 dir2/symlink1 dir2/symlink2)
71 (cd ${base}; chmod 0750 dir)
72 (cd ${base}; chmod 0755 dir2)
73 (cd ${base}; chmod 0755 dir2/symlink1 dir2/symlink2)
74 (cd ${base}; chmod 0644 file1)
75 (cd ${base}; chmod 0666 file2)
76 TZ=utc touch -afhm -t 197001030000.02 ${base}/dir2/symlink1 ${base}/dir2/symlink2
77 TZ=utc touch -afhm -t 197001020000.01 ${base}/dir ${base}/dir2
78 TZ=utc touch -afhm -t 197001020000.01 ${base}/file1 ${base}/file2
80 # Make several lha archives.
82 # Make a lha archive with header level 0
83 lha0=test_read_format_lha_header0.lzh
84 (cd ${base}; lha c0q ${lha0} dir file1 file2 dir2)
85 # Make a lha archive with header level 1
86 lha1=test_read_format_lha_header1.lzh
87 (cd ${base}; lha c1q ${lha1} dir file1 file2 dir2)
88 # Make a lha archive with header level 2
89 lha2=test_read_format_lha_header2.lzh
90 (cd ${base}; lha c2q ${lha2} dir file1 file2 dir2)
91 # Make a lha archive with -lh6- compression mode
92 lha3=test_read_format_lha_lh6.lzh
93 (cd ${base}; lha co6q ${lha3} dir file1 file2 dir2)
94 # Make a lha archive with -lh7- compression mode
95 lha4=test_read_format_lha_lh7.lzh
96 (cd ${base}; lha co7q ${lha4} dir file1 file2 dir2)
97 # Make a lha archive with -lh0- no compression
98 lha5=test_read_format_lha_lh0.lzh
99 (cd ${base}; lha czq ${lha5} dir file1 file2 dir2)
100 # make a lha archive with junk data
101 lha6=test_read_format_lha_withjunk.lzh
102 (cd ${base}; cp ${lha2} ${lha6}; echo "junk data!!!!" >> ${lha6})
104 uuencode ${base}/${lha0} ${lha0} > ${lha0}.uu
105 uuencode ${base}/${lha1} ${lha1} > ${lha1}.uu
106 uuencode ${base}/${lha2} ${lha2} > ${lha2}.uu
107 uuencode ${base}/${lha3} ${lha3} > ${lha3}.uu
108 uuencode ${base}/${lha4} ${lha4} > ${lha4}.uu
109 uuencode ${base}/${lha5} ${lha5} > ${lha5}.uu
110 uuencode ${base}/${lha6} ${lha5} > ${lha5}.uu
111 uuencode ${base}/${lha6} ${lha6} > ${lha6}.uu
113 # Finish making test data.
117 static const char file1[] = {
123 #define file1_size (sizeof(file1)-1)
124 static const char file2[] = {
133 #define file2_size (sizeof(file2)-1)
136 verify(const char *refname, int posix)
138 struct archive_entry *ae;
151 extract_reference_file(refname);
152 assert((a = archive_read_new()) != NULL);
153 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
154 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
155 assertEqualIntA(a, ARCHIVE_OK,
156 archive_read_open_filename(a, refname, 10240));
158 /* Verify directory1. */
159 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
161 assertEqualInt((AE_IFDIR | 0750), archive_entry_mode(ae));
163 assertEqualInt((AE_IFDIR | 0755), archive_entry_mode(ae));
164 assertEqualString("dir/", archive_entry_pathname(ae));
165 assertEqualInt(86401, archive_entry_mtime(ae));
166 assertEqualInt(uid, archive_entry_uid(ae));
167 assertEqualInt(gid, archive_entry_gid(ae));
168 assertEqualInt(0, archive_entry_size(ae));
169 assertEqualIntA(a, ARCHIVE_EOF,
170 archive_read_data_block(a, &pv, &s, &o));
171 assertEqualInt(s, 0);
173 /* Verify directory2. */
174 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
175 assertEqualInt((AE_IFDIR | 0755), archive_entry_mode(ae));
176 assertEqualString("dir2/", archive_entry_pathname(ae));
177 assertEqualInt(86401, archive_entry_mtime(ae));
178 assertEqualInt(uid, archive_entry_uid(ae));
179 assertEqualInt(gid, archive_entry_gid(ae));
180 assertEqualInt(0, archive_entry_size(ae));
181 assertEqualIntA(a, ARCHIVE_EOF,
182 archive_read_data_block(a, &pv, &s, &o));
183 assertEqualInt(s, 0);
186 /* Verify symbolic link file1. */
187 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
188 assertEqualInt((AE_IFLNK | 0755), archive_entry_mode(ae));
189 assertEqualString("dir2/symlink1", archive_entry_pathname(ae));
190 assertEqualString("../file1", archive_entry_symlink(ae));
191 assertEqualInt(172802, archive_entry_mtime(ae));
192 assertEqualInt(uid, archive_entry_uid(ae));
193 assertEqualInt(gid, archive_entry_gid(ae));
194 assertEqualInt(0, archive_entry_size(ae));
196 /* Verify symbolic link file2. */
197 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
198 assertEqualInt((AE_IFLNK | 0755), archive_entry_mode(ae));
199 assertEqualString("dir2/symlink2", archive_entry_pathname(ae));
200 assertEqualString("../file2", archive_entry_symlink(ae));
201 assertEqualInt(172802, archive_entry_mtime(ae));
202 assertEqualInt(uid, archive_entry_uid(ae));
203 assertEqualInt(gid, archive_entry_gid(ae));
204 assertEqualInt(0, archive_entry_size(ae));
207 /* Verify regular file1. */
208 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
209 assertEqualInt((AE_IFREG | 0644), archive_entry_mode(ae));
210 assertEqualString("file1", archive_entry_pathname(ae));
211 assertEqualInt(86401, archive_entry_mtime(ae));
212 assertEqualInt(uid, archive_entry_uid(ae));
213 assertEqualInt(gid, archive_entry_gid(ae));
214 assertEqualInt(file1_size, archive_entry_size(ae));
215 assertEqualInt(file1_size, archive_read_data(a, buff, file1_size));
216 assertEqualMem(buff, file1, file1_size);
218 /* Verify regular file2. */
219 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
221 assertEqualInt((AE_IFREG | 0666), archive_entry_mode(ae));
223 assertEqualInt((AE_IFREG | 0644), archive_entry_mode(ae));
224 assertEqualString("file2", archive_entry_pathname(ae));
225 assertEqualInt(86401, archive_entry_mtime(ae));
226 assertEqualInt(uid, archive_entry_uid(ae));
227 assertEqualInt(gid, archive_entry_gid(ae));
228 assertEqualInt(file2_size, archive_entry_size(ae));
229 assertEqualInt(file2_size, archive_read_data(a, buff, file2_size));
230 assertEqualMem(buff, file2, file2_size);
232 /* Verify the number of files read. */
234 assertEqualInt(6, archive_file_count(a));
236 assertEqualInt(4, archive_file_count(a));
239 /* End of archive. */
240 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
242 /* Verify the number of files read. */
244 assertEqualInt(6, archive_file_count(a));
246 assertEqualInt(4, archive_file_count(a));
249 /* Verify archive format. */
250 assertEqualIntA(a, ARCHIVE_FILTER_NONE, archive_filter_code(a, 0));
251 assertEqualIntA(a, ARCHIVE_FORMAT_LHA, archive_format(a));
253 /* Close the archive. */
254 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
255 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
258 DEFINE_TEST(test_read_format_lha)
260 /* Verify Header level 0 */
261 verify("test_read_format_lha_header0.lzh", 1);
262 /* Verify Header level 1 */
263 verify("test_read_format_lha_header1.lzh", 1);
264 /* Verify Header level 2 */
265 verify("test_read_format_lha_header2.lzh", 1);
266 /* Verify Header level 3
267 * This test data can be made in Windows only. */
268 verify("test_read_format_lha_header3.lzh", 0);
269 /* Verify compression mode -lh6- */
270 verify("test_read_format_lha_lh6.lzh", 1);
271 /* Verify compression mode -lh7- */
272 verify("test_read_format_lha_lh7.lzh", 1);
273 /* Verify no compression -lh0- */
274 verify("test_read_format_lha_lh0.lzh", 1);
275 /* Verify an lha file with junk data. */
276 verify("test_read_format_lha_withjunk.lzh", 1);