2 * Copyright (c) 2011 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 * 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.
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.
26 __FBSDID("$FreeBSD$");
29 * Verify that the various archive_read_support_* functions
30 * return appropriate errors when invoked on the wrong kind of
34 typedef struct archive *constructor(void);
35 typedef int enabler(struct archive *);
36 typedef int destructor(struct archive *);
38 static int format_code = 0;
39 static int format_code_enabler(struct archive *a)
41 return archive_read_support_format_by_code(a, format_code);
44 static int format_code_setter(struct archive *a)
46 return archive_read_set_format(a, format_code);
50 test_success(constructor new_, enabler enable_, destructor free_)
52 struct archive *a = new_();
53 int result = enable_(a);
54 if (result == ARCHIVE_WARN) {
55 assert(NULL != archive_error_string(a));
56 assertEqualIntA(a, -1, archive_errno(a));
58 assertEqualIntA(a, ARCHIVE_OK, result);
59 assert(NULL == archive_error_string(a));
60 assertEqualIntA(a, 0, archive_errno(a));
66 test_failure(constructor new_, enabler enable_, destructor free_)
68 struct archive *a = new_();
69 assertEqualIntA(a, ARCHIVE_FATAL, enable_(a));
70 assert(NULL != archive_error_string(a));
71 assertEqualIntA(a, -1, archive_errno(a));
76 test_filter_or_format(enabler enable)
78 test_success(archive_read_new, enable, archive_read_free);
79 test_failure(archive_write_new, enable, archive_write_free);
80 test_failure(archive_read_disk_new, enable, archive_read_free);
81 test_failure(archive_write_disk_new, enable, archive_write_free);
84 DEFINE_TEST(test_archive_read_support)
86 test_filter_or_format(archive_read_support_format_7zip);
87 test_filter_or_format(archive_read_support_format_all);
88 test_filter_or_format(archive_read_support_format_ar);
89 test_filter_or_format(archive_read_support_format_cab);
90 test_filter_or_format(archive_read_support_format_cpio);
91 test_filter_or_format(archive_read_support_format_empty);
92 test_filter_or_format(archive_read_support_format_iso9660);
93 test_filter_or_format(archive_read_support_format_lha);
94 test_filter_or_format(archive_read_support_format_mtree);
95 test_filter_or_format(archive_read_support_format_tar);
96 test_filter_or_format(archive_read_support_format_xar);
97 test_filter_or_format(archive_read_support_format_zip);
99 int format_codes[] = {
101 ARCHIVE_FORMAT_CPIO_POSIX,
102 ARCHIVE_FORMAT_CPIO_BIN_LE,
103 ARCHIVE_FORMAT_CPIO_BIN_BE,
104 ARCHIVE_FORMAT_CPIO_SVR4_NOCRC,
105 ARCHIVE_FORMAT_CPIO_SVR4_CRC,
106 ARCHIVE_FORMAT_CPIO_AFIO_LARGE,
108 ARCHIVE_FORMAT_TAR_USTAR,
109 ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE,
110 ARCHIVE_FORMAT_TAR_PAX_RESTRICTED,
111 ARCHIVE_FORMAT_TAR_GNUTAR,
112 ARCHIVE_FORMAT_ISO9660,
113 ARCHIVE_FORMAT_ISO9660_ROCKRIDGE,
115 ARCHIVE_FORMAT_EMPTY,
117 ARCHIVE_FORMAT_AR_GNU,
118 ARCHIVE_FORMAT_AR_BSD,
119 ARCHIVE_FORMAT_MTREE,
127 ARCHIVE_FORMAT_RAR_V5,
129 for (unsigned i = 0; i < sizeof(format_codes) / sizeof(int); i++) {
130 format_code = format_codes[i];
131 test_filter_or_format(format_code_enabler);
132 test_filter_or_format(format_code_setter);
135 test_filter_or_format(archive_read_support_filter_all);
136 test_filter_or_format(archive_read_support_filter_bzip2);
137 test_filter_or_format(archive_read_support_filter_compress);
138 test_filter_or_format(archive_read_support_filter_gzip);
139 test_filter_or_format(archive_read_support_filter_lzip);
140 test_filter_or_format(archive_read_support_filter_lzma);
141 test_filter_or_format(archive_read_support_filter_none);
142 test_filter_or_format(archive_read_support_filter_rpm);
143 test_filter_or_format(archive_read_support_filter_uu);
144 test_filter_or_format(archive_read_support_filter_xz);