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_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
assertA(0 == archive_write_set_format_ustar(a));
55
assertA(0 == archive_write_set_compression_compress(a));
56
assertA(0 == archive_write_open_memory(a, buff, buffsize, &used));
58
for (i = 0; i < 100; i++) {
59
sprintf(path, "file%03d", i);
60
assert((ae = archive_entry_new()) != NULL);
61
archive_entry_copy_pathname(ae, path);
62
archive_entry_set_size(ae, datasize);
63
archive_entry_set_filetype(ae, AE_IFREG);
64
assertA(0 == archive_write_header(a, ae));
65
assertA(datasize == (size_t)archive_write_data(a, data, datasize));
66
archive_entry_free(ae);
70
archive_write_close(a);
71
#if ARCHIVE_VERSION_NUMBER < 2000000
72
archive_write_finish(a);
74
assert(0 == archive_write_finish(a));
78
* Now, read the data back.
80
assert((a = archive_read_new()) != NULL);
81
assertA(0 == archive_read_support_format_all(a));
82
assertA(0 == archive_read_support_compression_all(a));
83
assertA(0 == archive_read_open_memory(a, buff, used));
86
for (i = 0; i < 100; i++) {
87
sprintf(path, "file%03d", i);
88
if (!assertEqualInt(0, archive_read_next_header(a, &ae)))
90
assertEqualString(path, archive_entry_pathname(ae));
91
assertEqualInt((int)datasize, archive_entry_size(ae));
93
assert(0 == archive_read_close(a));
94
#if ARCHIVE_VERSION_NUMBER < 2000000
95
archive_read_finish(a);
97
assert(0 == archive_read_finish(a));