2 * Copyright (c) 2007 Tim Kientzle
3 * Copyright (c) 2012 Michihiro NAKAJIMA
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer
11 * in this position and unchanged.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 __FBSDID("$FreeBSD$");
31 DEFINE_TEST(test_write_filter_gzip_timestamp)
33 struct archive_entry *ae;
36 size_t buffsize, datasize;
41 assert(NULL != (buff = (char *)malloc(buffsize)));
46 assert(NULL != (data = (char *)malloc(datasize)));
51 memset(data, 0, datasize);
53 /* Test1: set "gzip:timestamp" option. */
54 assert((a = archive_write_new()) != NULL);
55 assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
56 r = archive_write_add_filter_gzip(a);
57 if (r != ARCHIVE_OK) {
58 if (canGzip() && r == ARCHIVE_WARN)
61 skipping("gzip writing not supported on this platform");
62 assertEqualInt(ARCHIVE_OK, archive_write_free(a));
68 assertEqualIntA(a, ARCHIVE_OK,
69 archive_write_set_options(a, "gzip:timestamp"));
70 assertEqualIntA(a, ARCHIVE_OK,
71 archive_write_set_bytes_per_block(a, 10));
72 assertEqualInt(ARCHIVE_FILTER_GZIP, archive_filter_code(a, 0));
73 assertEqualString("gzip", archive_filter_name(a, 0));
74 assertEqualIntA(a, ARCHIVE_OK,
75 archive_write_open_memory(a, buff, buffsize, &used1));
76 assert((ae = archive_entry_new()) != NULL);
77 archive_entry_set_filetype(ae, AE_IFREG);
78 archive_entry_set_size(ae, datasize);
79 archive_entry_copy_pathname(ae, "file");
80 assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
81 assertEqualIntA(a, datasize, archive_write_data(a, data, datasize));
82 archive_entry_free(ae);
83 assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
84 assertEqualInt(ARCHIVE_OK, archive_write_free(a));
85 failure("Timestamp should be recorded");
86 assert(memcmp(buff + 4, "\x00\x00\x00\x00", 4) != 0);
88 /* Test2: set "gzip:!timestamp" option. */
89 assert((a = archive_write_new()) != NULL);
90 assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
91 assertEqualIntA(a, (use_prog)?ARCHIVE_WARN:ARCHIVE_OK,
92 archive_write_add_filter_gzip(a));
93 assertEqualIntA(a, ARCHIVE_OK,
94 archive_write_set_options(a, "gzip:!timestamp"));
95 assertEqualIntA(a, ARCHIVE_OK,
96 archive_write_set_bytes_per_block(a, 10));
97 assertEqualInt(ARCHIVE_FILTER_GZIP, archive_filter_code(a, 0));
98 assertEqualString("gzip", archive_filter_name(a, 0));
99 assertEqualIntA(a, ARCHIVE_OK,
100 archive_write_open_memory(a, buff, buffsize, &used1));
101 assert((ae = archive_entry_new()) != NULL);
102 archive_entry_set_filetype(ae, AE_IFREG);
103 archive_entry_set_size(ae, datasize);
104 archive_entry_copy_pathname(ae, "file");
105 assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
106 assertEqualIntA(a, datasize, archive_write_data(a, data, datasize));
107 archive_entry_free(ae);
108 assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
109 assertEqualInt(ARCHIVE_OK, archive_write_free(a));
110 failure("Timestamp should not be recorded");
111 assertEqualMem(buff + 4, "\x00\x00\x00\x00", 4);