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_read_format_cab_filename_CP932_eucJP(const char *refname)
34 struct archive_entry *ae;
37 * Read CAB filename in ja_JP.eucJP with "hdrcharset=CP932" option.
39 if (NULL == setlocale(LC_ALL, "ja_JP.eucJP")) {
40 skipping("ja_JP.eucJP locale not available on this system.");
44 assert((a = archive_read_new()) != NULL);
45 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
46 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
47 if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=CP932")) {
48 skipping("This system cannot convert character-set"
49 " from CP932 to eucJP.");
52 assertEqualIntA(a, ARCHIVE_OK,
53 archive_read_open_filename(a, refname, 10240));
55 /* Verify regular file. */
56 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
58 "\xc9\xbd\xa4\xc0\xa4\xe8\x2f\xb4\xc1\xbb\xfa\x2e\x74\x78\x74",
59 archive_entry_pathname(ae));
60 assertEqualInt(5, archive_entry_size(ae));
62 /* Verify regular file. */
63 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
65 "\xc9\xbd\xa4\xc0\xa4\xe8\x2f\xb0\xec\xcd\xf7\xc9\xbd\x2e\x74\x78\x74",
66 archive_entry_pathname(ae));
67 assertEqualInt(5, archive_entry_size(ae));
71 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
73 /* Verify archive format. */
74 assertEqualIntA(a, ARCHIVE_FILTER_NONE, archive_filter_code(a, 0));
75 assertEqualIntA(a, ARCHIVE_FORMAT_CAB, archive_format(a));
77 /* Close the archive. */
79 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
80 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
84 test_read_format_cab_filename_CP932_UTF8(const char *refname)
87 struct archive_entry *ae;
90 * Read CAB filename in en_US.UTF-8 with "hdrcharset=CP932" option.
92 if (NULL == setlocale(LC_ALL, "en_US.UTF-8")) {
93 skipping("en_US.UTF-8 locale not available on this system.");
97 assert((a = archive_read_new()) != NULL);
98 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
99 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
100 if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=CP932")) {
101 skipping("This system cannot convert character-set"
102 " from CP932 to UTF-8.");
105 assertEqualIntA(a, ARCHIVE_OK,
106 archive_read_open_filename(a, refname, 10240));
108 /* Verify regular file. */
109 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
110 #if defined(__APPLE__)
111 /* Compare NFD string. */
112 assertEqualUTF8String(
113 "\xe8\xa1\xa8\xe3\x81\x9f\xe3\x82\x99\xe3\x82\x88\x2f"
114 "\xe6\xbc\xa2\xe5\xad\x97\x2e\x74\x78\x74",
115 archive_entry_pathname(ae));
116 assertEqualInt(5, archive_entry_size(ae));
118 /* Compare NFC string. */
119 assertEqualUTF8String(
120 "\xe8\xa1\xa8\xe3\x81\xa0\xe3\x82\x88\x2f"
121 "\xe6\xbc\xa2\xe5\xad\x97\x2e\x74\x78\x74",
122 archive_entry_pathname(ae));
123 assertEqualInt(5, archive_entry_size(ae));
126 /* Verify regular file. */
127 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
128 #if defined(__APPLE__)
129 /* Compare NFD string. */
130 assertEqualUTF8String(
131 "\xe8\xa1\xa8\xe3\x81\x9f\xe3\x82\x99\xe3\x82\x88\x2f"
132 "\xe4\xb8\x80\xe8\xa6\xa7\xe8\xa1\xa8\x2e\x74\x78\x74",
133 archive_entry_pathname(ae));
135 /* Compare NFC string. */
136 assertEqualUTF8String(
137 "\xe8\xa1\xa8\xe3\x81\xa0\xe3\x82\x88\x2f"
138 "\xe4\xb8\x80\xe8\xa6\xa7\xe8\xa1\xa8\x2e\x74\x78\x74",
139 archive_entry_pathname(ae));
141 assertEqualInt(5, archive_entry_size(ae));
144 /* End of archive. */
145 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
147 /* Verify archive format. */
148 assertEqualIntA(a, ARCHIVE_FILTER_NONE, archive_filter_code(a, 0));
149 assertEqualIntA(a, ARCHIVE_FORMAT_CAB, archive_format(a));
151 /* Close the archive. */
153 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
154 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
157 DEFINE_TEST(test_read_format_cab_filename)
159 const char *refname = "test_read_format_cab_filename_cp932.cab";
161 extract_reference_file(refname);
162 test_read_format_cab_filename_CP932_eucJP(refname);
163 test_read_format_cab_filename_CP932_UTF8(refname);