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