1 /*-
2  * Copyright (c) 2011-2012 Michihiro NAKAJIMA
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 
26 
27 #include "test.h"
28 
29 static void
30 test_basic(const char *compression_type)
31 {
32 	char filedata[64];
33 	struct archive_entry *ae;
34 	struct archive *a;
35 	size_t used;
36 	size_t buffsize = 1000;
37 	char *buff;
38 
39 	buff = malloc(buffsize);
40 
41 	/* Create a new archive in memory. */
42 	assert((a = archive_write_new()) != NULL);
43 	assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_7zip(a));
44 	if (compression_type != NULL &&
45 	    ARCHIVE_OK != archive_write_set_format_option(a, "7zip",
46 	    "compression", compression_type)) {
47 		skipping("%s writing not fully supported on this platform",
48 		   compression_type);
49 		assertEqualInt(ARCHIVE_OK, archive_write_free(a));
50 		free(buff);
51 		return;
52 	}
53 	assertEqualIntA(a, ARCHIVE_OK, archive_write_add_filter_none(a));
54 	assertEqualIntA(a, ARCHIVE_OK,
55 	    archive_write_open_memory(a, buff, buffsize, &used));
56 
57 	/*
58 	 * Write an empty file to it.
59 	 */
60 	assert((ae = archive_entry_new()) != NULL);
61 	archive_entry_set_mtime(ae, 1, 10);
62 	assertEqualInt(1, archive_entry_mtime(ae));
63 	assertEqualInt(10, archive_entry_mtime_nsec(ae));
64 	archive_entry_copy_pathname(ae, "empty");
65 	assertEqualString("empty", archive_entry_pathname(ae));
66 	archive_entry_set_mode(ae, AE_IFREG | 0755);
67 	assertEqualInt((AE_IFREG | 0755), archive_entry_mode(ae));
68 
69 	assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae));
70 	archive_entry_free(ae);
71 
72 	/*
73 	 * Write another empty file to it.
74 	 */
75 	assert((ae = archive_entry_new()) != NULL);
76 	archive_entry_set_mtime(ae, 1, 10);
77 	assertEqualInt(1, archive_entry_mtime(ae));
78 	assertEqualInt(10, archive_entry_mtime_nsec(ae));
79 	archive_entry_copy_pathname(ae, "empty2");
80 	assertEqualString("empty2", archive_entry_pathname(ae));
81 	archive_entry_set_mode(ae, AE_IFREG | 0444);
82 	assertEqualInt((AE_IFREG | 0444), archive_entry_mode(ae));
83 
84 	assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae));
85 	archive_entry_free(ae);
86 
87 	/*
88 	 * Write a file to it.
89 	 */
90 	assert((ae = archive_entry_new()) != NULL);
91 	archive_entry_set_mtime(ae, 1, 100);
92 	assertEqualInt(1, archive_entry_mtime(ae));
93 	assertEqualInt(100, archive_entry_mtime_nsec(ae));
94 	archive_entry_copy_pathname(ae, "file");
95 	assertEqualString("file", archive_entry_pathname(ae));
96 	archive_entry_set_mode(ae, AE_IFREG | 0755);
97 	assertEqualInt((AE_IFREG | 0755), archive_entry_mode(ae));
98 	archive_entry_set_size(ae, 8);
99 
100 	assertEqualInt(0, archive_write_header(a, ae));
101 	archive_entry_free(ae);
102 	assertEqualInt(8, archive_write_data(a, "12345678", 9));
103 	assertEqualInt(0, archive_write_data(a, "1", 1));
104 
105 	/*
106 	 * Write another file to it.
107 	 */
108 	assert((ae = archive_entry_new()) != NULL);
109 	archive_entry_set_mtime(ae, 1, 10);
110 	assertEqualInt(1, archive_entry_mtime(ae));
111 	assertEqualInt(10, archive_entry_mtime_nsec(ae));
112 	archive_entry_copy_pathname(ae, "file2");
113 	assertEqualString("file2", archive_entry_pathname(ae));
114 	archive_entry_set_mode(ae, AE_IFREG | 0755);
115 	assertEqualInt((AE_IFREG | 0755), archive_entry_mode(ae));
116 	archive_entry_set_size(ae, 4);
117 
118 	assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae));
119 	archive_entry_free(ae);
120 	assertEqualInt(4, archive_write_data(a, "1234", 5));
121 
122 	/*
123 	 * Write a symbolic file to it.
124 	 */
125 	assert((ae = archive_entry_new()) != NULL);
126 	archive_entry_set_mtime(ae, 1, 10);
127 	assertEqualInt(1, archive_entry_mtime(ae));
128 	assertEqualInt(10, archive_entry_mtime_nsec(ae));
129 	archive_entry_copy_pathname(ae, "symbolic");
130 	archive_entry_copy_symlink(ae, "file1");
131 	assertEqualString("symbolic", archive_entry_pathname(ae));
132 	archive_entry_set_mode(ae, AE_IFLNK | 0755);
133 	assertEqualInt((AE_IFLNK | 0755), archive_entry_mode(ae));
134 
135 	assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae));
136 	archive_entry_free(ae);
137 
138 	/*
139 	 * Write a directory to it.
140 	 */
141 	assert((ae = archive_entry_new()) != NULL);
142 	archive_entry_set_mtime(ae, 11, 100);
143 	archive_entry_copy_pathname(ae, "dir");
144 	archive_entry_set_mode(ae, AE_IFDIR | 0755);
145 	archive_entry_set_size(ae, 512);
146 
147 	assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
148 	failure("size should be zero so that applications know not to write");
149 	assertEqualInt(0, archive_entry_size(ae));
150 	archive_entry_free(ae);
151 	assertEqualIntA(a, 0, archive_write_data(a, "12345678", 9));
152 
153 	/*
154 	 * Write a sub directory to it.
155 	 */
156 	assert((ae = archive_entry_new()) != NULL);
157 	archive_entry_set_mtime(ae, 11, 200);
158 	archive_entry_copy_pathname(ae, "dir/subdir");
159 	archive_entry_set_mode(ae, AE_IFDIR | 0755);
160 	archive_entry_set_size(ae, 512);
161 
162 	assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
163 	failure("size should be zero so that applications know not to write");
164 	assertEqualInt(0, archive_entry_size(ae));
165 	archive_entry_free(ae);
166 	assertEqualIntA(a, 0, archive_write_data(a, "12345678", 9));
167 
168 	/*
169 	 * Write a sub sub-directory to it.
170 	 */
171 	assert((ae = archive_entry_new()) != NULL);
172 	archive_entry_set_mtime(ae, 11, 300);
173 	archive_entry_copy_pathname(ae, "dir/subdir/subdir");
174 	archive_entry_set_mode(ae, AE_IFDIR | 0755);
175 	archive_entry_set_size(ae, 512);
176 
177 	assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
178 	failure("size should be zero so that applications know not to write");
179 	assertEqualInt(0, archive_entry_size(ae));
180 	archive_entry_free(ae);
181 	assertEqualIntA(a, 0, archive_write_data(a, "12345678", 9));
182 
183 	/* Close out the archive. */
184 	assertEqualInt(ARCHIVE_OK, archive_write_close(a));
185 	assertEqualInt(ARCHIVE_OK, archive_write_free(a));
186 
187 	/* Verify the initial header. */
188 	assertEqualMem(buff, "\x37\x7a\xbc\xaf\x27\x1c\x00\x03", 8);
189 
190 	/*
191 	 * Now, read the data back.
192 	 */
193 	/* With the test memory reader -- seeking mode. */
194 	assert((a = archive_read_new()) != NULL);
195 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
196 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
197 	assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, buff, used, 7));
198 
199 	/*
200 	 * Read and verify first file.
201 	 */
202 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
203 	assertEqualInt(1, archive_entry_mtime(ae));
204 	assertEqualInt(100, archive_entry_mtime_nsec(ae));
205 	assertEqualInt(0, archive_entry_atime(ae));
206 	assertEqualInt(0, archive_entry_ctime(ae));
207 	assertEqualString("file", archive_entry_pathname(ae));
208 	assertEqualInt(AE_IFREG | 0755, archive_entry_mode(ae));
209 	assertEqualInt(8, archive_entry_size(ae));
210 	assertEqualIntA(a, 8,
211 	    archive_read_data(a, filedata, sizeof(filedata)));
212 	assertEqualMem(filedata, "12345678", 8);
213 
214 
215 	/*
216 	 * Read the second file back.
217 	 */
218 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
219 	assertEqualInt(1, archive_entry_mtime(ae));
220 	assertEqualInt(0, archive_entry_mtime_nsec(ae));
221 	assertEqualInt(0, archive_entry_atime(ae));
222 	assertEqualInt(0, archive_entry_ctime(ae));
223 	assertEqualString("file2", archive_entry_pathname(ae));
224 	assertEqualInt(AE_IFREG | 0755, archive_entry_mode(ae));
225 	assertEqualInt(4, archive_entry_size(ae));
226 	assertEqualIntA(a, 4,
227 	    archive_read_data(a, filedata, sizeof(filedata)));
228 	assertEqualMem(filedata, "1234", 4);
229 
230 	/*
231 	 * Read and verify a symbolic file.
232 	 */
233 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
234 	assertEqualInt(1, archive_entry_mtime(ae));
235 	assertEqualInt(0, archive_entry_mtime_nsec(ae));
236 	assertEqualInt(0, archive_entry_atime(ae));
237 	assertEqualInt(0, archive_entry_ctime(ae));
238 	assertEqualString("symbolic", archive_entry_pathname(ae));
239 	assertEqualString("file1", archive_entry_symlink(ae));
240 	assertEqualInt(AE_IFLNK | 0755, archive_entry_mode(ae));
241 	assertEqualInt(0, archive_entry_size(ae));
242 
243 	/*
244 	 * Read and verify an empty file.
245 	 */
246 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
247 	assertEqualInt(1, archive_entry_mtime(ae));
248 	assertEqualInt(0, archive_entry_mtime_nsec(ae));
249 	assertEqualInt(0, archive_entry_atime(ae));
250 	assertEqualInt(0, archive_entry_ctime(ae));
251 	assertEqualString("empty", archive_entry_pathname(ae));
252 	assertEqualInt(AE_IFREG | 0755, archive_entry_mode(ae));
253 	assertEqualInt(0, archive_entry_size(ae));
254 
255 	/*
256 	 * Read and verify an empty file.
257 	 */
258 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
259 	assertEqualInt(1, archive_entry_mtime(ae));
260 	assertEqualInt(0, archive_entry_mtime_nsec(ae));
261 	assertEqualInt(0, archive_entry_atime(ae));
262 	assertEqualInt(0, archive_entry_ctime(ae));
263 	assertEqualString("empty2", archive_entry_pathname(ae));
264 	assertEqualInt(AE_IFREG | 0444, archive_entry_mode(ae));
265 	assertEqualInt(0, archive_entry_size(ae));
266 
267 	/*
268 	 * Read the sub sub-dir entry back.
269 	 */
270 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
271 	assertEqualInt(11, archive_entry_mtime(ae));
272 	assertEqualInt(300, archive_entry_mtime_nsec(ae));
273 	assertEqualInt(0, archive_entry_atime(ae));
274 	assertEqualInt(0, archive_entry_ctime(ae));
275 	assertEqualString("dir/subdir/subdir/", archive_entry_pathname(ae));
276 	assertEqualInt(AE_IFDIR | 0755, archive_entry_mode(ae));
277 	assertEqualInt(0, archive_entry_size(ae));
278 	assertEqualIntA(a, 0, archive_read_data(a, filedata, 10));
279 
280 	/*
281 	 * Read the sub dir entry back.
282 	 */
283 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
284 	assertEqualInt(11, archive_entry_mtime(ae));
285 	assertEqualInt(200, archive_entry_mtime_nsec(ae));
286 	assertEqualInt(0, archive_entry_atime(ae));
287 	assertEqualInt(0, archive_entry_ctime(ae));
288 	assertEqualString("dir/subdir/", archive_entry_pathname(ae));
289 	assertEqualInt(AE_IFDIR | 0755, archive_entry_mode(ae));
290 	assertEqualInt(0, archive_entry_size(ae));
291 	assertEqualIntA(a, 0, archive_read_data(a, filedata, 10));
292 
293 	/*
294 	 * Read the dir entry back.
295 	 */
296 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
297 	assertEqualInt(11, archive_entry_mtime(ae));
298 	assertEqualInt(100, archive_entry_mtime_nsec(ae));
299 	assertEqualInt(0, archive_entry_atime(ae));
300 	assertEqualInt(0, archive_entry_ctime(ae));
301 	assertEqualString("dir/", archive_entry_pathname(ae));
302 	assertEqualInt(AE_IFDIR | 0755, archive_entry_mode(ae));
303 	assertEqualInt(0, archive_entry_size(ae));
304 	assertEqualIntA(a, 0, archive_read_data(a, filedata, 10));
305 
306 	/* Verify the end of the archive. */
307 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
308 
309 	/* Verify archive format. */
310 	assertEqualIntA(a, ARCHIVE_FILTER_NONE, archive_filter_code(a, 0));
311 	assertEqualIntA(a, ARCHIVE_FORMAT_7ZIP, archive_format(a));
312 
313 	assertEqualInt(ARCHIVE_OK, archive_read_close(a));
314 	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
315 
316 	free(buff);
317 }
318 
319 static void
320 test_basic2(const char *compression_type)
321 {
322 	char filedata[64];
323 	struct archive_entry *ae;
324 	struct archive *a;
325 	size_t used;
326 	size_t buffsize = 1000;
327 	char *buff;
328 
329 	buff = malloc(buffsize);
330 
331 	/* Create a new archive in memory. */
332 	assert((a = archive_write_new()) != NULL);
333 	assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_7zip(a));
334 	if (compression_type != NULL &&
335 	    ARCHIVE_OK != archive_write_set_format_option(a, "7zip",
336 	    "compression", compression_type)) {
337 		skipping("%s writing not fully supported on this platform",
338 		   compression_type);
339 		assertEqualInt(ARCHIVE_OK, archive_write_free(a));
340 		free(buff);
341 		return;
342 	}
343 	assertEqualIntA(a, ARCHIVE_OK, archive_write_add_filter_none(a));
344 	assertEqualIntA(a, ARCHIVE_OK,
345 	    archive_write_open_memory(a, buff, buffsize, &used));
346 
347 	/*
348 	 * Write a file to it.
349 	 */
350 	assert((ae = archive_entry_new()) != NULL);
351 	archive_entry_set_mtime(ae, 1, 100);
352 	assertEqualInt(1, archive_entry_mtime(ae));
353 	assertEqualInt(100, archive_entry_mtime_nsec(ae));
354 	archive_entry_copy_pathname(ae, "file");
355 	assertEqualString("file", archive_entry_pathname(ae));
356 	archive_entry_set_mode(ae, AE_IFREG | 0755);
357 	assertEqualInt((AE_IFREG | 0755), archive_entry_mode(ae));
358 	archive_entry_set_size(ae, 8);
359 
360 	assertEqualInt(0, archive_write_header(a, ae));
361 	archive_entry_free(ae);
362 	assertEqualInt(8, archive_write_data(a, "12345678", 9));
363 	assertEqualInt(0, archive_write_data(a, "1", 1));
364 
365 	/*
366 	 * Write another file to it.
367 	 */
368 	assert((ae = archive_entry_new()) != NULL);
369 	archive_entry_set_mtime(ae, 1, 10);
370 	assertEqualInt(1, archive_entry_mtime(ae));
371 	assertEqualInt(10, archive_entry_mtime_nsec(ae));
372 	archive_entry_copy_pathname(ae, "file2");
373 	assertEqualString("file2", archive_entry_pathname(ae));
374 	archive_entry_set_mode(ae, AE_IFREG | 0755);
375 	assertEqualInt((AE_IFREG | 0755), archive_entry_mode(ae));
376 	archive_entry_set_size(ae, 4);
377 
378 	assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae));
379 	archive_entry_free(ae);
380 	assertEqualInt(4, archive_write_data(a, "1234", 5));
381 
382 	/*
383 	 * Write a directory to it.
384 	 */
385 	assert((ae = archive_entry_new()) != NULL);
386 	archive_entry_set_mtime(ae, 11, 100);
387 	archive_entry_copy_pathname(ae, "dir");
388 	archive_entry_set_mode(ae, AE_IFDIR | 0755);
389 	archive_entry_set_size(ae, 512);
390 
391 	assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
392 	failure("size should be zero so that applications know not to write");
393 	assertEqualInt(0, archive_entry_size(ae));
394 	archive_entry_free(ae);
395 	assertEqualIntA(a, 0, archive_write_data(a, "12345678", 9));
396 
397 	/*
398 	 * Write a sub directory to it.
399 	 */
400 	assert((ae = archive_entry_new()) != NULL);
401 	archive_entry_set_mtime(ae, 11, 200);
402 	archive_entry_copy_pathname(ae, "dir/subdir");
403 	archive_entry_set_mode(ae, AE_IFDIR | 0755);
404 	archive_entry_set_size(ae, 512);
405 
406 	assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
407 	failure("size should be zero so that applications know not to write");
408 	assertEqualInt(0, archive_entry_size(ae));
409 	archive_entry_free(ae);
410 	assertEqualIntA(a, 0, archive_write_data(a, "12345678", 9));
411 
412 	/*
413 	 * Write a sub sub-directory to it.
414 	 */
415 	assert((ae = archive_entry_new()) != NULL);
416 	archive_entry_set_mtime(ae, 11, 300);
417 	archive_entry_copy_pathname(ae, "dir/subdir/subdir");
418 	archive_entry_set_mode(ae, AE_IFDIR | 0755);
419 	archive_entry_set_size(ae, 512);
420 
421 	assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
422 	failure("size should be zero so that applications know not to write");
423 	assertEqualInt(0, archive_entry_size(ae));
424 	archive_entry_free(ae);
425 	assertEqualIntA(a, 0, archive_write_data(a, "12345678", 9));
426 
427 	/* Close out the archive. */
428 	assertEqualInt(ARCHIVE_OK, archive_write_close(a));
429 	assertEqualInt(ARCHIVE_OK, archive_write_free(a));
430 
431 	/* Verify the initial header. */
432 	assertEqualMem(buff, "\x37\x7a\xbc\xaf\x27\x1c\x00\x03", 8);
433 
434 	/*
435 	 * Now, read the data back.
436 	 */
437 	/* With the test memory reader -- seeking mode. */
438 	assert((a = archive_read_new()) != NULL);
439 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
440 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
441 	assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, buff, used, 7));
442 
443 	/*
444 	 * Read and verify first file.
445 	 */
446 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
447 	assertEqualInt(1, archive_entry_mtime(ae));
448 	assertEqualInt(100, archive_entry_mtime_nsec(ae));
449 	assertEqualInt(0, archive_entry_atime(ae));
450 	assertEqualInt(0, archive_entry_ctime(ae));
451 	assertEqualString("file", archive_entry_pathname(ae));
452 	assertEqualInt(AE_IFREG | 0755, archive_entry_mode(ae));
453 	assertEqualInt(8, archive_entry_size(ae));
454 	assertEqualIntA(a, 8,
455 	    archive_read_data(a, filedata, sizeof(filedata)));
456 	assertEqualMem(filedata, "12345678", 8);
457 
458 
459 	/*
460 	 * Read the second file back.
461 	 */
462 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
463 	assertEqualInt(1, archive_entry_mtime(ae));
464 	assertEqualInt(0, archive_entry_mtime_nsec(ae));
465 	assertEqualInt(0, archive_entry_atime(ae));
466 	assertEqualInt(0, archive_entry_ctime(ae));
467 	assertEqualString("file2", archive_entry_pathname(ae));
468 	assertEqualInt(AE_IFREG | 0755, archive_entry_mode(ae));
469 	assertEqualInt(4, archive_entry_size(ae));
470 	assertEqualIntA(a, 4,
471 	    archive_read_data(a, filedata, sizeof(filedata)));
472 	assertEqualMem(filedata, "1234", 4);
473 
474 	/*
475 	 * Read the sub sub-dir entry back.
476 	 */
477 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
478 	assertEqualInt(11, archive_entry_mtime(ae));
479 	assertEqualInt(300, archive_entry_mtime_nsec(ae));
480 	assertEqualInt(0, archive_entry_atime(ae));
481 	assertEqualInt(0, archive_entry_ctime(ae));
482 	assertEqualString("dir/subdir/subdir/", archive_entry_pathname(ae));
483 	assertEqualInt(AE_IFDIR | 0755, archive_entry_mode(ae));
484 	assertEqualInt(0, archive_entry_size(ae));
485 	assertEqualIntA(a, 0, archive_read_data(a, filedata, 10));
486 
487 	/*
488 	 * Read the sub dir entry back.
489 	 */
490 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
491 	assertEqualInt(11, archive_entry_mtime(ae));
492 	assertEqualInt(200, archive_entry_mtime_nsec(ae));
493 	assertEqualInt(0, archive_entry_atime(ae));
494 	assertEqualInt(0, archive_entry_ctime(ae));
495 	assertEqualString("dir/subdir/", archive_entry_pathname(ae));
496 	assertEqualInt(AE_IFDIR | 0755, archive_entry_mode(ae));
497 	assertEqualInt(0, archive_entry_size(ae));
498 	assertEqualIntA(a, 0, archive_read_data(a, filedata, 10));
499 
500 	/*
501 	 * Read the dir entry back.
502 	 */
503 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
504 	assertEqualInt(11, archive_entry_mtime(ae));
505 	assertEqualInt(100, archive_entry_mtime_nsec(ae));
506 	assertEqualInt(0, archive_entry_atime(ae));
507 	assertEqualInt(0, archive_entry_ctime(ae));
508 	assertEqualString("dir/", archive_entry_pathname(ae));
509 	assertEqualInt(AE_IFDIR | 0755, archive_entry_mode(ae));
510 	assertEqualInt(0, archive_entry_size(ae));
511 	assertEqualIntA(a, 0, archive_read_data(a, filedata, 10));
512 
513 	/* Verify the end of the archive. */
514 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
515 
516 	/* Verify archive format. */
517 	assertEqualIntA(a, ARCHIVE_FILTER_NONE, archive_filter_code(a, 0));
518 	assertEqualIntA(a, ARCHIVE_FORMAT_7ZIP, archive_format(a));
519 
520 	assertEqualInt(ARCHIVE_OK, archive_read_close(a));
521 	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
522 
523 	free(buff);
524 }
525 
526 DEFINE_TEST(test_write_format_7zip)
527 {
528 	/* Test that making a 7-Zip archive file by default compression
529 	 * in whatever compressions are supported on the running platform. */
530 	test_basic(NULL);
531 	/* Test that making a 7-Zip archive file without empty files. */
532 	test_basic2(NULL);
533 }
534 
535 DEFINE_TEST(test_write_format_7zip_basic_bzip2)
536 {
537 	/* Test that making a 7-Zip archive file with bzip2 compression. */
538 	test_basic("bzip2");
539 }
540 
541 DEFINE_TEST(test_write_format_7zip_basic_copy)
542 {
543 	/* Test that making a 7-Zip archive file without compression. */
544 	test_basic("copy");
545 }
546 
547 DEFINE_TEST(test_write_format_7zip_basic_deflate)
548 {
549 	/* Test that making a 7-Zip archive file with deflate compression. */
550 	test_basic("deflate");
551 }
552 
553 DEFINE_TEST(test_write_format_7zip_basic_lzma1)
554 {
555 	/* Test that making a 7-Zip archive file with lzma1 compression. */
556 	test_basic("lzma1");
557 }
558 
559 DEFINE_TEST(test_write_format_7zip_basic_lzma2)
560 {
561 	/* Test that making a 7-Zip archive file with lzma2 compression. */
562 	test_basic("lzma2");
563 }
564 
565 DEFINE_TEST(test_write_format_7zip_basic_ppmd)
566 {
567 	/* Test that making a 7-Zip archive file with PPMd compression. */
568 	test_basic("ppmd");
569 }
570