2 * Copyright (c) 2007 Tim Kientzle
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 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 __FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_compress.c 189308 2009-03-03 17:02:51Z kientzle $");
31 * A basic exercise of compress reading and writing.
33 * TODO: Add a reference file and make sure we can decompress that.
36 DEFINE_TEST(test_write_filter_compress)
38 struct archive_entry *ae;
41 size_t buffsize, datasize;
47 assert(NULL != (buff = (char *)malloc(buffsize)));
50 assert(NULL != (data = (char *)malloc(datasize)));
51 memset(data, 0, datasize);
53 assert((a = archive_write_new()) != NULL);
54 assertEqualIntA(a, ARCHIVE_OK,
55 archive_write_set_format_ustar(a));
56 assertEqualIntA(a, ARCHIVE_OK,
57 archive_write_add_filter_compress(a));
58 assertEqualIntA(a, ARCHIVE_OK,
59 archive_write_open_memory(a, buff, buffsize, &used));
61 for (i = 0; i < 100; i++) {
62 sprintf(path, "file%03d", i);
63 assert((ae = archive_entry_new()) != NULL);
64 archive_entry_copy_pathname(ae, path);
65 archive_entry_set_size(ae, datasize);
66 archive_entry_set_filetype(ae, AE_IFREG);
67 assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
68 assertEqualInt(datasize,
69 archive_write_data(a, data, datasize));
70 archive_entry_free(ae);
73 assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
74 assertEqualInt(ARCHIVE_OK, archive_write_free(a));
77 * Now, read the data back.
79 assert((a = archive_read_new()) != NULL);
80 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
81 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
82 assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used));
85 for (i = 0; i < 100; i++) {
86 sprintf(path, "file%03d", i);
87 if (!assertEqualInt(0, archive_read_next_header(a, &ae)))
89 assertEqualString(path, archive_entry_pathname(ae));
90 assertEqualInt((int)datasize, archive_entry_size(ae));
92 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
93 assertEqualInt(ARCHIVE_OK, archive_read_free(a));