2 * Copyright (c) 2009 Michihiro NAKAJIMA
3 * Copyright (c) 2003-2008 Tim Kientzle
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 * 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.
27 __FBSDID("$FreeBSD$");
30 Execute the following to rebuild the data for this program:
31 tail -n +33 test_compat_lzma.c | /bin/sh
33 # Use lzma command of XZ Utils.
34 name=test_compat_lzma_1
38 dir="$name`date +%Y%m%d%H%M%S`.$USER"
46 echo "f1" > $dir/d1/f1
47 echo "f2" > $dir/d1/f2
48 echo "f3" > $dir/d1/f3
49 (cd $dir; tar cf ../$name.tar f1 f2 f3 d1/f1 d1/f2 d1/f3)
54 mv $name.tar.$zsuffix $name.$ztar_suffix
55 echo "This is unrelated junk data at the end of the file" >> $name.$ztar_suffix
56 uuencode $name.$ztar_suffix $name.$ztar_suffix > $name.$ztar_suffix.uu
57 rm -f $name.$ztar_suffix
61 name=test_compat_lzma_2
62 dir="$name`date +%Y%m%d%H%M%S`.$USER"
65 mv $name.tar.$zsuffix $name.$ztar_suffix
66 uuencode $name.$ztar_suffix $name.$ztar_suffix > $name.$ztar_suffix.uu
67 rm -f $name.$ztar_suffix
69 # Use lzma command of LZMA SDK with option -d12.
71 name=test_compat_lzma_3
72 zcmd=lzmasdk # Change this path to use lzma of LZMA SDK.
73 dir="$name`date +%Y%m%d%H%M%S`.$USER"
75 $zcmd e -d12 $name.tar $name.$ztar_suffix
77 uuencode $name.$ztar_suffix $name.$ztar_suffix > $name.$ztar_suffix.uu
78 rm -f $name.$ztar_suffix
84 * Verify our ability to read sample files compatibly with unlzma.
87 * * unlzma will read multiple lzma streams, concatenating the output
88 * * unlzma will read lzma streams which is made by lzma with option -e,
89 * concatenating the output
91 * Verify our ability to read sample files compatibly with lzma of
93 * * lzma will read lzma streams which is made by lzma with option -d12,
94 * concatenating the output
98 * All of the sample files have the same contents; they're just
99 * compressed in different ways.
102 compat_lzma(const char *name)
104 const char *n[7] = { "f1", "f2", "f3", "d1/f1", "d1/f2", "d1/f3", NULL };
105 struct archive_entry *ae;
109 assert((a = archive_read_new()) != NULL);
110 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
111 r = archive_read_support_filter_lzma(a);
112 if (r == ARCHIVE_WARN) {
113 skipping("lzma reading not fully supported on this platform");
114 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
117 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
118 extract_reference_file(name);
119 assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2));
121 /* Read entries, match up names with list above. */
122 for (i = 0; i < 6; ++i) {
123 failure("Could not read file %d (%s) from %s", i, n[i], name);
124 assertEqualIntA(a, ARCHIVE_OK,
125 archive_read_next_header(a, &ae));
126 assertEqualString(n[i], archive_entry_pathname(ae));
129 /* Verify the end-of-archive. */
130 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
132 /* Verify that the format detection worked. */
133 assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_LZMA);
134 assertEqualString(archive_filter_name(a, 0), "lzma");
135 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR);
137 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
138 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
142 DEFINE_TEST(test_compat_lzma)
144 /* This sample has been added junk datas to its tail. */
145 compat_lzma("test_compat_lzma_1.tlz");
146 /* This sample has been made by lzma with option -e,
147 * the first byte of which is 0x5e.
148 * Not supported in libarchive 2.7.* and earlier */
149 compat_lzma("test_compat_lzma_2.tlz");
150 /* This sample has been made by lzma of LZMA SDK with
151 * option -d12, second byte and third byte of which is
153 * Not supported in libarchive 2.7.* and earlier */
154 compat_lzma("test_compat_lzma_3.tlz");