1 /*
2 * Copyright (c) 2003-2018
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
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.
14 *
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.
25 */
26 #include "test.h"
27
DEFINE_TEST(test_7zip_filename_encoding_UTF16_win)28 DEFINE_TEST(test_7zip_filename_encoding_UTF16_win)
29 {
30 #if !defined(_WIN32) || defined(__CYGWIN__)
31 skipping("This test is meant to verify unicode string handling"
32 " on Windows with UTF-16 names");
33 return;
34 #else
35 struct archive *a;
36 struct archive_entry *entry;
37 char buff[4096];
38 size_t used;
39
40 /*
41 * Don't call setlocale because we're verifying that the '_w' functions
42 * work as expected
43 */
44
45 a = archive_write_new();
46 assertEqualInt(ARCHIVE_OK, archive_write_set_format_7zip(a));
47 assertEqualInt(ARCHIVE_OK,
48 archive_write_open_memory(a, buff, sizeof(buff), &used));
49
50 /* Part 1: file */
51 entry = archive_entry_new2(a);
52 archive_entry_copy_pathname_w(entry, L"\u8868.txt");
53 archive_entry_set_filetype(entry, AE_IFREG);
54 archive_entry_set_size(entry, 0);
55 assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry));
56
57 /* Part 2: directory */
58 archive_entry_clear(entry);
59 archive_entry_copy_pathname_w(entry, L"\u8868");
60 archive_entry_set_filetype(entry, AE_IFDIR);
61 archive_entry_set_size(entry, 0);
62 assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry));
63
64 /* Part 3: symlink */
65 archive_entry_clear(entry);
66 archive_entry_set_pathname(entry, "link.txt");
67 archive_entry_copy_symlink_w(entry, L"\u8868.txt");
68 archive_entry_set_filetype(entry, AE_IFLNK);
69 archive_entry_set_symlink_type(entry, AE_SYMLINK_TYPE_FILE);
70 archive_entry_set_size(entry, 0);
71 assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry));
72
73 /* NOTE: 7zip does not support hardlinks */
74
75 archive_entry_free(entry);
76 assertEqualInt(ARCHIVE_OK, archive_write_free(a));
77
78 /* Ensure that the archive contents can be read properly */
79 /* NOTE: 7zip file contents are not in the order we wrote them! */
80 a = archive_read_new();
81 archive_read_support_format_all(a);
82 archive_read_support_filter_all(a);
83 assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, buff, used, 7));
84
85 /* Read part 3: symlink */
86 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &entry));
87 assertEqualWString(L"\u8868.txt", archive_entry_symlink_w(entry));
88
89 /* Read part 1: file */
90 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &entry));
91 assertEqualWString(L"\u8868.txt", archive_entry_pathname_w(entry));
92
93 /* Read part 2: directory */
94 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &entry));
95 /* NOTE: Trailing slash added automatically for us */
96 assertEqualWString(L"\u8868/", archive_entry_pathname_w(entry));
97
98 archive_read_free(a);
99 #endif
100 }