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