2 * Copyright (c) 2003-2007 Tim Kientzle
3 * Copyright (c) 2011 Michihiro NAKAJIMA
4 * Copyright (c) 2019 Mike Frysinger
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
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.
28 __FBSDID("$FreeBSD$");
33 verify(struct archive *a) {
34 struct archive_entry *ae;
37 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
38 assert((p = archive_entry_pathname_utf8(ae)) != NULL);
39 assertEqualUTF8String(p, "File 1.txt");
41 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
42 assert((p = archive_entry_pathname_utf8(ae)) != NULL);
43 #if defined(__APPLE__)
44 /* Compare NFD string. */
45 assertEqualUTF8String(p, "File 2 - o\xCC\x88.txt");
47 /* Compare NFC string. */
48 assertEqualUTF8String(p, "File 2 - \xC3\xB6.txt");
51 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
52 assert((p = archive_entry_pathname_utf8(ae)) != NULL);
53 #if defined(__APPLE__)
54 /* Compare NFD string. */
55 assertEqualUTF8String(p, "File 3 - a\xCC\x88.txt");
57 /* Compare NFC string. */
58 assertEqualUTF8String(p, "File 3 - \xC3\xA4.txt");
61 /* The CRC of the filename fails, so fall back to CDE. */
62 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
63 assert((p = archive_entry_pathname_utf8(ae)) != NULL);
64 assertEqualUTF8String(p, "File 4 - xx.txt");
66 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
69 DEFINE_TEST(test_read_format_zip_utf8_paths)
71 const char *refname = "test_read_format_zip_7075_utf8_paths.zip";
76 extract_reference_file(refname);
78 if (NULL == setlocale(LC_ALL, "en_US.UTF-8")) {
79 skipping("en_US.UTF-8 locale not available on this system.");
83 /* Verify with seeking reader. */
84 assert((a = archive_read_new()) != NULL);
85 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
86 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
87 assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 10240));
89 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
90 assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
92 /* Verify with streaming reader. */
93 p = slurpfile(&s, "%s", refname);
94 assert((a = archive_read_new()) != NULL);
95 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
96 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
97 assertEqualIntA(a, ARCHIVE_OK, read_open_memory(a, p, s, 31));
99 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
100 assertEqualIntA(a, ARCHIVE_OK, archive_free(a));