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_gtar_filename_eucJP_UTF8(const char *refname)
34 struct archive_entry *ae;
37 * Read eucJP filename in en_US.UTF-8 with "hdrcharset=eucJP" option.
39 if (NULL == setlocale(LC_ALL, "en_US.UTF-8")) {
40 skipping("en_US.UTF-8 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=eucJP")) {
48 skipping("This system cannot convert character-set"
49 " from eucJP to UTF-8.");
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));
57 assertEqualString("\xe6\xbc\xa2\xe5\xad\x97.txt",
58 archive_entry_pathname(ae));
59 assertEqualInt(8, archive_entry_size(ae));
61 /* Verify regular file. */
62 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
63 assertEqualString("\xe8\xa1\xa8.txt", archive_entry_pathname(ae));
64 assertEqualInt(4, archive_entry_size(ae));
68 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
70 /* Verify archive format. */
71 assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
72 assertEqualIntA(a, ARCHIVE_FORMAT_TAR_GNUTAR, archive_format(a));
74 /* Close the archive. */
75 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
77 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
81 test_read_format_gtar_filename_CP866_KOI8R(const char *refname)
84 struct archive_entry *ae;
87 * Read CP866 filename in ru_RU.KOI8-R with "hdrcharset=CP866" option.
89 if (NULL == setlocale(LC_ALL, "Russian_Russia.20866") &&
90 NULL == setlocale(LC_ALL, "ru_RU.KOI8-R")) {
91 skipping("ru_RU.KOI8-R locale not available on this system.");
95 assert((a = archive_read_new()) != NULL);
96 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
97 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
98 if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=CP866")) {
99 skipping("This system cannot convert character-set"
100 " from CP866 to KOI8-R.");
103 assertEqualIntA(a, ARCHIVE_OK,
104 archive_read_open_filename(a, refname, 10240));
106 /* Verify regular file. */
107 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
108 assertEqualString("\xf0\xf2\xe9\xf7\xe5\xf4",
109 archive_entry_pathname(ae));
110 assertEqualInt(6, archive_entry_size(ae));
112 /* Verify regular file. */
113 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
114 assertEqualString("\xd0\xd2\xc9\xd7\xc5\xd4",
115 archive_entry_pathname(ae));
116 assertEqualInt(6, archive_entry_size(ae));
119 /* End of archive. */
120 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
122 /* Verify archive format. */
123 assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
124 assertEqualIntA(a, ARCHIVE_FORMAT_TAR_GNUTAR, archive_format(a));
126 /* Close the archive. */
127 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
129 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
133 test_read_format_gtar_filename_CP866_UTF8(const char *refname)
136 struct archive_entry *ae;
139 * Read CP866 filename in en_US.UTF-8 with "hdrcharset=CP866" option.
141 if (NULL == setlocale(LC_ALL, "en_US.UTF-8")) {
142 skipping("en_US.UTF-8 locale not available on this system.");
146 assert((a = archive_read_new()) != NULL);
147 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
148 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
149 if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=CP866")) {
150 skipping("This system cannot convert character-set"
151 " from CP866 to UTF-8.");
154 assertEqualIntA(a, ARCHIVE_OK,
155 archive_read_open_filename(a, refname, 10240));
157 /* Verify regular file. */
158 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
159 assertEqualString("\xd0\x9f\xd0\xa0\xd0\x98\xd0\x92\xd0\x95\xd0\xa2",
160 archive_entry_pathname(ae));
161 assertEqualInt(6, archive_entry_size(ae));
163 /* Verify regular file. */
164 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
165 assertEqualString("\xd0\xbf\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82",
166 archive_entry_pathname(ae));
167 assertEqualInt(6, archive_entry_size(ae));
170 /* End of archive. */
171 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
173 /* Verify archive format. */
174 assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
175 assertEqualIntA(a, ARCHIVE_FORMAT_TAR_GNUTAR, archive_format(a));
177 /* Close the archive. */
178 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
180 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
184 test_read_format_gtar_filename_KOI8R_CP866(const char *refname)
187 struct archive_entry *ae;
190 * Read KOI8-R filename in ru_RU.CP866 with "hdrcharset=KOI8-R" option.
192 if (NULL == setlocale(LC_ALL, "Russian_Russia.866") &&
193 NULL == setlocale(LC_ALL, "ru_RU.CP866")) {
194 skipping("ru_RU.CP866 locale not available on this system.");
198 assert((a = archive_read_new()) != NULL);
199 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
200 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
201 if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=KOI8-R")) {
202 skipping("This system cannot convert character-set"
203 " from KOI8-R to CP866.");
206 assertEqualIntA(a, ARCHIVE_OK,
207 archive_read_open_filename(a, refname, 10240));
209 /* Verify regular file. */
210 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
211 assertEqualString("\xaf\xe0\xa8\xa2\xa5\xe2",
212 archive_entry_pathname(ae));
213 assertEqualInt(6, archive_entry_size(ae));
215 /* Verify regular file. */
216 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
217 assertEqualString("\x8f\x90\x88\x82\x85\x92",
218 archive_entry_pathname(ae));
219 assertEqualInt(6, archive_entry_size(ae));
222 /* End of archive. */
223 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
225 /* Verify archive format. */
226 assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
227 assertEqualIntA(a, ARCHIVE_FORMAT_TAR_GNUTAR, archive_format(a));
229 /* Close the archive. */
230 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
232 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
236 test_read_format_gtar_filename_KOI8R_UTF8(const char *refname)
239 struct archive_entry *ae;
242 * Read KOI8-R filename in en_US.UTF-8 with "hdrcharset=KOI8-R" option.
244 if (NULL == setlocale(LC_ALL, "en_US.UTF-8")) {
245 skipping("en_US.UTF-8 locale not available on this system.");
249 assert((a = archive_read_new()) != NULL);
250 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
251 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
252 if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=KOI8-R")) {
253 skipping("This system cannot convert character-set"
254 " from KOI8-R to UTF-8.");
257 assertEqualIntA(a, ARCHIVE_OK,
258 archive_read_open_filename(a, refname, 10240));
260 /* Verify regular file. */
261 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
262 assertEqualString("\xd0\xbf\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82",
263 archive_entry_pathname(ae));
264 assertEqualInt(6, archive_entry_size(ae));
266 /* Verify regular file. */
267 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
268 assertEqualString("\xd0\x9f\xd0\xa0\xd0\x98\xd0\x92\xd0\x95\xd0\xa2",
269 archive_entry_pathname(ae));
270 assertEqualInt(6, archive_entry_size(ae));
273 /* End of archive. */
274 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
276 /* Verify archive format. */
277 assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
278 assertEqualIntA(a, ARCHIVE_FORMAT_TAR_GNUTAR, archive_format(a));
280 /* Close the archive. */
281 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
283 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
287 test_read_format_gtar_filename_eucJP_CP932(const char *refname)
290 struct archive_entry *ae;
293 * Read eucJP filename in CP932/SJIS with "hdrcharset=eucJP" option.
295 if (NULL == setlocale(LC_ALL, "Japanese_Japan") &&
296 NULL == setlocale(LC_ALL, "ja_JP.SJIS")) {
297 skipping("CP932 locale not available on this system.");
301 assert((a = archive_read_new()) != NULL);
302 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
303 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
304 if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=eucJP")) {
305 skipping("This system cannot convert character-set"
309 assertEqualIntA(a, ARCHIVE_OK,
310 archive_read_open_filename(a, refname, 10240));
312 /* Verify regular file. */
313 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
314 assertEqualString("\x8a\xbf\x8e\x9a.txt", archive_entry_pathname(ae));
315 assertEqualInt(8, archive_entry_size(ae));
317 /* Verify regular file. */
318 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
319 assertEqualString("\x95\x5c.txt", archive_entry_pathname(ae));
320 assertEqualInt(4, archive_entry_size(ae));
323 /* End of archive. */
324 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
326 /* Verify archive format. */
327 assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
328 assertEqualIntA(a, ARCHIVE_FORMAT_TAR_GNUTAR, archive_format(a));
330 /* Close the archive. */
331 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
333 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
337 test_read_format_gtar_filename_CP866_CP1251(const char *refname)
340 struct archive_entry *ae;
343 * Read CP866 filename in CP1251 with "hdrcharset=CP866" option.
345 if (NULL == setlocale(LC_ALL, "Russian_Russia") &&
346 NULL == setlocale(LC_ALL, "ru_RU.CP1251")) {
347 skipping("CP1251 locale not available on this system.");
351 assert((a = archive_read_new()) != NULL);
352 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
353 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
354 if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=CP866")) {
355 skipping("This system cannot convert character-set"
356 " from CP866 to CP1251.");
359 assertEqualIntA(a, ARCHIVE_OK,
360 archive_read_open_filename(a, refname, 10240));
362 /* Verify regular file. */
363 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
364 assertEqualString("\xcf\xd0\xc8\xc2\xc5\xd2",
365 archive_entry_pathname(ae));
366 assertEqualInt(6, archive_entry_size(ae));
368 /* Verify regular file. */
369 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
370 assertEqualString("\xef\xf0\xe8\xe2\xe5\xf2",
371 archive_entry_pathname(ae));
372 assertEqualInt(6, archive_entry_size(ae));
375 /* End of archive. */
376 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
378 /* Verify archive format. */
379 assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
380 assertEqualIntA(a, ARCHIVE_FORMAT_TAR_GNUTAR, archive_format(a));
382 /* Close the archive. */
383 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
385 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
389 * This test only for Windows platform because other archiver
390 * applications on Windows translate CP1251 filenames into CP866
391 * filenames and store it in the gtar file and so we should read
392 * it by default on Windows.
395 test_read_format_gtar_filename_CP866_CP1251_win(const char *refname)
398 struct archive_entry *ae;
401 * Read CP866 filename in CP1251 without "hdrcharset=CP866" option.
403 if (NULL == setlocale(LC_ALL, "Russian_Russia")) {
404 skipping("Russian_Russia locale not available on this system.");
408 assert((a = archive_read_new()) != NULL);
409 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
410 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
411 assertEqualIntA(a, ARCHIVE_OK,
412 archive_read_open_filename(a, refname, 10240));
414 /* Verify regular file. */
415 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
416 assertEqualString("\xcf\xd0\xc8\xc2\xc5\xd2",
417 archive_entry_pathname(ae));
418 assertEqualInt(6, archive_entry_size(ae));
420 /* Verify regular file. */
421 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
422 assertEqualString("\xef\xf0\xe8\xe2\xe5\xf2",
423 archive_entry_pathname(ae));
424 assertEqualInt(6, archive_entry_size(ae));
427 /* End of archive. */
428 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
430 /* Verify archive format. */
431 assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
432 assertEqualIntA(a, ARCHIVE_FORMAT_TAR_GNUTAR, archive_format(a));
434 /* Close the archive. */
435 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
436 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
440 test_read_format_gtar_filename_KOI8R_CP1251(const char *refname)
443 struct archive_entry *ae;
446 * Read KOI8-R filename in CP1251 with "hdrcharset=KOI8-R" option.
448 if (NULL == setlocale(LC_ALL, "Russian_Russia") &&
449 NULL == setlocale(LC_ALL, "ru_RU.CP1251")) {
450 skipping("CP1251 locale not available on this system.");
454 assert((a = archive_read_new()) != NULL);
455 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
456 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
457 if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=KOI8-R")) {
458 skipping("This system cannot convert character-set"
459 " from KOI8-R to CP1251.");
462 assertEqualIntA(a, ARCHIVE_OK,
463 archive_read_open_filename(a, refname, 10240));
465 /* Verify regular file. */
466 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
467 assertEqualString("\xef\xf0\xe8\xe2\xe5\xf2",
468 archive_entry_pathname(ae));
469 assertEqualInt(6, archive_entry_size(ae));
471 /* Verify regular file. */
472 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
473 assertEqualString("\xcf\xd0\xc8\xc2\xc5\xd2",
474 archive_entry_pathname(ae));
475 assertEqualInt(6, archive_entry_size(ae));
478 /* End of archive. */
479 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
481 /* Verify archive format. */
482 assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
483 assertEqualIntA(a, ARCHIVE_FORMAT_TAR_GNUTAR, archive_format(a));
485 /* Close the archive. */
486 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
488 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
492 DEFINE_TEST(test_read_format_gtar_filename)
494 const char *refname1 = "test_read_format_gtar_filename_eucjp.tar.Z";
495 const char *refname2 = "test_read_format_gtar_filename_cp866.tar.Z";
496 const char *refname3 = "test_read_format_gtar_filename_koi8r.tar.Z";
498 extract_reference_file(refname1);
499 test_read_format_gtar_filename_eucJP_UTF8(refname1);
500 test_read_format_gtar_filename_eucJP_CP932(refname1);
502 extract_reference_file(refname2);
503 test_read_format_gtar_filename_CP866_KOI8R(refname2);
504 test_read_format_gtar_filename_CP866_UTF8(refname2);
505 test_read_format_gtar_filename_CP866_CP1251(refname2);
506 test_read_format_gtar_filename_CP866_CP1251_win(refname2);
508 extract_reference_file(refname3);
509 test_read_format_gtar_filename_KOI8R_CP866(refname3);
510 test_read_format_gtar_filename_KOI8R_UTF8(refname3);
511 test_read_format_gtar_filename_KOI8R_CP1251(refname3);