2 * Copyright (c) 2011 Michihiro NAKAJIMA
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.
31 * Test "tar:compat-2x" option that enables the string conversion of
32 * libarchive 2.x, which made incorrect UTF-8 form filenames for the
33 * pax format on some platform the wchar_t of which was not Unicode form.
34 * The option is unneeded if people have been using UTF-8 locale during
35 * making tar files(in pax format).
37 * NOTE: The sample tar file was made with bsdtar 2.x in LANG=KOI8-R on
41 DEFINE_TEST(test_compat_pax_libarchive_2x)
43 #if (defined(_WIN32) && !defined(__CYGWIN__)) \
44 || defined(__STDC_ISO_10646__) || defined(__APPLE__)
45 skipping("This test only for the platform the WCS of which is "
49 struct archive_entry *ae;
52 const char *refname = "test_compat_pax_libarchive_2x.tar.Z";
55 * Read incorrect format UTF-8 filename in ru_RU.KOI8-R with
56 * "tar:compat-2x" option. We should correctly
59 if (NULL == setlocale(LC_ALL, "ru_RU.KOI8-R")) {
60 skipping("ru_RU.KOI8-R locale not available on this system.");
65 * Test if wchar_t format is the same as FreeBSD wchar_t.
67 assert(-1 != wctomb(NULL, L'\0'));
70 if (wctomb(&c, wc) != 1 || (unsigned char)c != 0xd0) {
71 skipping("wchar_t format is different on this platform.");
75 extract_reference_file(refname);
77 assert((a = archive_read_new()) != NULL);
78 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
79 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
80 assertEqualIntA(a, ARCHIVE_OK,
81 archive_read_set_options(a, "tar:compat-2x"));
82 assertEqualIntA(a, ARCHIVE_OK,
83 archive_read_open_filename(a, refname, 10240));
85 /* Verify regular first file. */
86 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
87 assertEqualString("\xd0\xd2\xc9\xd7\xc5\xd4",
88 archive_entry_pathname(ae));
89 assertEqualInt(6, archive_entry_size(ae));
91 /* Verify regular second file. */
92 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
93 assertEqualString("\xf0\xf2\xe9\xf7\xe5\xf4",
94 archive_entry_pathname(ae));
95 assertEqualInt(6, archive_entry_size(ae));
99 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
101 /* Verify archive format. */
102 assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
103 assertEqualIntA(a, ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE,
106 /* Close the archive. */
107 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
108 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
111 * Without "tar:compat-2x" option.
112 * Neither first file name nor second file name can be translated
115 assert((a = archive_read_new()) != NULL);
116 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
117 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
118 assertEqualIntA(a, ARCHIVE_OK,
119 archive_read_open_filename(a, refname, 10240));
121 /* We cannot correctly read the filename. */
122 assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae));
123 assert(strcmp("\xd0\xd2\xc9\xd7\xc5\xd4",
124 archive_entry_pathname(ae)) != 0);
125 assertEqualInt(6, archive_entry_size(ae));
127 /* We cannot correctly read the filename. */
128 assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae));
129 assert(strcmp("\xf0\xf2\xe9\xf7\xe5\xf4",
130 archive_entry_pathname(ae)) != 0);
131 assertEqualInt(6, archive_entry_size(ae));
134 /* End of archive. */
135 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
137 /* Verify archive format. */
138 assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
139 assertEqualIntA(a, ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE,
142 /* Close the archive. */
143 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
144 assertEqualInt(ARCHIVE_OK, archive_read_free(a));