test_read_format_gtar_filename.c revision 231200
18876Srgrimes/*-
24Srgrimes * Copyright (c) 2011 Michihiro NAKAJIMA
34Srgrimes * All rights reserved.
44Srgrimes *
58876Srgrimes * Redistribution and use in source and binary forms, with or without
64Srgrimes * modification, are permitted provided that the following conditions
74Srgrimes * are met:
84Srgrimes * 1. Redistributions of source code must retain the above copyright
94Srgrimes *    notice, this list of conditions and the following disclaimer.
104Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
118876Srgrimes *    notice, this list of conditions and the following disclaimer in the
128876Srgrimes *    documentation and/or other materials provided with the distribution.
134Srgrimes *
144Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
158876Srgrimes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
164Srgrimes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
178876Srgrimes * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
184Srgrimes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
194Srgrimes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
204Srgrimes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
214Srgrimes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
228876Srgrimes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
234Srgrimes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
244Srgrimes */
254Srgrimes#include "test.h"
2612720Sphk__FBSDID("$FreeBSD");
274Srgrimes
28623Srgrimes#include <locale.h>
294Srgrimes
304Srgrimesstatic void
314Srgrimestest_read_format_gtar_filename_eucJP_UTF8(const char *refname)
324Srgrimes{
334Srgrimes	struct archive *a;
342056Swollman	struct archive_entry *ae;
352056Swollman
362056Swollman	/*
3712662Sdg	 * Read eucJP filename in en_US.UTF-8 with "hdrcharset=eucJP" option.
3812662Sdg	 */
3912662Sdg	if (NULL == setlocale(LC_ALL, "en_US.UTF-8")) {
4012662Sdg		skipping("en_US.UTF-8 locale not available on this system.");
4112662Sdg		return;
4212662Sdg	}
432056Swollman
444Srgrimes	assert((a = archive_read_new()) != NULL);
454Srgrimes	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
464Srgrimes	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
474Srgrimes	if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=eucJP")) {
484Srgrimes		skipping("This system cannot convert character-set"
494Srgrimes		    " from eucJP to UTF-8.");
504Srgrimes		goto cleanup;
514Srgrimes	}
524Srgrimes	assertEqualIntA(a, ARCHIVE_OK,
534Srgrimes	    archive_read_open_filename(a, refname, 10240));
5412515Sphk
554Srgrimes	/* Verify regular file. */
564Srgrimes	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
5712720Sphk	assertEqualString("\xe6\xbc\xa2\xe5\xad\x97.txt",
5812515Sphk	    archive_entry_pathname(ae));
5912515Sphk	assertEqualInt(8, archive_entry_size(ae));
6012515Sphk
614Srgrimes	/* Verify regular file. */
6212515Sphk	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
6312515Sphk	assertEqualString("\xe8\xa1\xa8.txt", archive_entry_pathname(ae));
6412515Sphk	assertEqualInt(4, archive_entry_size(ae));
6512515Sphk
6612515Sphk
6712515Sphk	/* End of archive. */
6812515Sphk	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
6912515Sphk
7012515Sphk	/* Verify archive format. */
7112515Sphk	assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
7212515Sphk	assertEqualIntA(a, ARCHIVE_FORMAT_TAR_GNUTAR, archive_format(a));
7312473Sbde
7412515Sphk	/* Close the archive. */
754Srgrimes	assertEqualInt(ARCHIVE_OK, archive_read_close(a));
764Srgrimescleanup:
774Srgrimes	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
784Srgrimes}
794Srgrimes
804Srgrimesstatic void
814Srgrimestest_read_format_gtar_filename_CP866_KOI8R(const char *refname)
824Srgrimes{
834Srgrimes	struct archive *a;
844Srgrimes	struct archive_entry *ae;
854Srgrimes
864Srgrimes	/*
874Srgrimes	 * Read CP866 filename in ru_RU.KOI8-R with "hdrcharset=CP866" option.
884Srgrimes	 */
894Srgrimes	if (NULL == setlocale(LC_ALL, "Russian_Russia.20866") &&
904Srgrimes	    NULL == setlocale(LC_ALL, "ru_RU.KOI8-R")) {
914Srgrimes		skipping("ru_RU.KOI8-R locale not available on this system.");
924Srgrimes		return;
934Srgrimes	}
944Srgrimes
954Srgrimes	assert((a = archive_read_new()) != NULL);
964Srgrimes	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
974Srgrimes	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
984Srgrimes	if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=CP866")) {
994Srgrimes		skipping("This system cannot convert character-set"
1004Srgrimes		    " from CP866 to KOI8-R.");
1014Srgrimes		goto cleanup;
10212515Sphk	}
1034Srgrimes	assertEqualIntA(a, ARCHIVE_OK,
1044Srgrimes	    archive_read_open_filename(a, refname, 10240));
1054Srgrimes
1064Srgrimes	/* Verify regular file. */
1074Srgrimes	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
1084Srgrimes	assertEqualString("\xf0\xf2\xe9\xf7\xe5\xf4",
1094Srgrimes	    archive_entry_pathname(ae));
1104Srgrimes	assertEqualInt(6, archive_entry_size(ae));
1114Srgrimes
1124Srgrimes	/* Verify regular file. */
1134Srgrimes	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
1144Srgrimes	assertEqualString("\xd0\xd2\xc9\xd7\xc5\xd4",
1154Srgrimes	    archive_entry_pathname(ae));
1164Srgrimes	assertEqualInt(6, archive_entry_size(ae));
1174Srgrimes
1184Srgrimes
1194Srgrimes	/* End of archive. */
1204Srgrimes	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
1214Srgrimes
1224Srgrimes	/* Verify archive format. */
1234Srgrimes	assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
1244Srgrimes	assertEqualIntA(a, ARCHIVE_FORMAT_TAR_GNUTAR, archive_format(a));
1254Srgrimes
1264Srgrimes	/* Close the archive. */
1274Srgrimes	assertEqualInt(ARCHIVE_OK, archive_read_close(a));
1284Srgrimescleanup:
1294Srgrimes	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
1304Srgrimes}
1314Srgrimes
1324Srgrimesstatic void
1334Srgrimestest_read_format_gtar_filename_CP866_UTF8(const char *refname)
1344Srgrimes{
1354Srgrimes	struct archive *a;
1364Srgrimes	struct archive_entry *ae;
1374Srgrimes
1384Srgrimes	/*
1394Srgrimes	 * Read CP866 filename in en_US.UTF-8 with "hdrcharset=CP866" option.
1404Srgrimes	 */
1414Srgrimes	if (NULL == setlocale(LC_ALL, "en_US.UTF-8")) {
1424Srgrimes		skipping("en_US.UTF-8 locale not available on this system.");
1434Srgrimes		return;
1444Srgrimes	}
14512515Sphk
1464Srgrimes	assert((a = archive_read_new()) != NULL);
1474Srgrimes	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
1484Srgrimes	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
1494Srgrimes	if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=CP866")) {
1504Srgrimes		skipping("This system cannot convert character-set"
1514Srgrimes		    " from CP866 to UTF-8.");
1524Srgrimes		goto cleanup;
1534Srgrimes	}
1544Srgrimes	assertEqualIntA(a, ARCHIVE_OK,
1554Srgrimes	    archive_read_open_filename(a, refname, 10240));
1564Srgrimes
1574Srgrimes	/* Verify regular file. */
1584Srgrimes	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
1594Srgrimes	assertEqualString("\xd0\x9f\xd0\xa0\xd0\x98\xd0\x92\xd0\x95\xd0\xa2",
1604Srgrimes	    archive_entry_pathname(ae));
1614Srgrimes	assertEqualInt(6, archive_entry_size(ae));
1624Srgrimes
1634Srgrimes	/* Verify regular file. */
1644Srgrimes	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
1654Srgrimes	assertEqualString("\xd0\xbf\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82",
1664Srgrimes	    archive_entry_pathname(ae));
16712515Sphk	assertEqualInt(6, archive_entry_size(ae));
1684Srgrimes
1694Srgrimes
1704Srgrimes	/* End of archive. */
1714Srgrimes	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
1724Srgrimes
1734Srgrimes	/* Verify archive format. */
1744Srgrimes	assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
1754Srgrimes	assertEqualIntA(a, ARCHIVE_FORMAT_TAR_GNUTAR, archive_format(a));
1764Srgrimes
1774Srgrimes	/* Close the archive. */
1784Srgrimes	assertEqualInt(ARCHIVE_OK, archive_read_close(a));
1794Srgrimescleanup:
1804Srgrimes	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
1814Srgrimes}
1824Srgrimes
1834Srgrimesstatic void
1844Srgrimestest_read_format_gtar_filename_KOI8R_CP866(const char *refname)
1854Srgrimes{
1864Srgrimes	struct archive *a;
1874Srgrimes	struct archive_entry *ae;
1884Srgrimes
1894Srgrimes	/*
1904Srgrimes	 * Read KOI8-R filename in ru_RU.CP866 with "hdrcharset=KOI8-R" option.
1914Srgrimes	 */
19212473Sbde	if (NULL == setlocale(LC_ALL, "Russian_Russia.866") &&
1934Srgrimes	    NULL == setlocale(LC_ALL, "ru_RU.CP866")) {
1944Srgrimes		skipping("ru_RU.CP866 locale not available on this system.");
1954Srgrimes		return;
1964Srgrimes	}
1974Srgrimes
1984Srgrimes	assert((a = archive_read_new()) != NULL);
1994Srgrimes	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
2004Srgrimes	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
2014Srgrimes	if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=KOI8-R")) {
2024Srgrimes		skipping("This system cannot convert character-set"
2034Srgrimes		    " from KOI8-R to CP866.");
20412473Sbde		goto cleanup;
2054Srgrimes	}
2064Srgrimes	assertEqualIntA(a, ARCHIVE_OK,
2074Srgrimes	    archive_read_open_filename(a, refname, 10240));
2084Srgrimes
2094Srgrimes	/* Verify regular file. */
2104Srgrimes	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
2114Srgrimes	assertEqualString("\xaf\xe0\xa8\xa2\xa5\xe2",
2124Srgrimes	    archive_entry_pathname(ae));
2134Srgrimes	assertEqualInt(6, archive_entry_size(ae));
2144Srgrimes
2154Srgrimes	/* Verify regular file. */
2164Srgrimes	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
2174Srgrimes	assertEqualString("\x8f\x90\x88\x82\x85\x92",
2184Srgrimes	    archive_entry_pathname(ae));
2194Srgrimes	assertEqualInt(6, archive_entry_size(ae));
2204Srgrimes
2214Srgrimes
22212473Sbde	/* End of archive. */
22312473Sbde	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
22412473Sbde
22512473Sbde	/* Verify archive format. */
22612473Sbde	assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
2274Srgrimes	assertEqualIntA(a, ARCHIVE_FORMAT_TAR_GNUTAR, archive_format(a));
2284Srgrimes
2294Srgrimes	/* Close the archive. */
2304Srgrimes	assertEqualInt(ARCHIVE_OK, archive_read_close(a));
2314Srgrimescleanup:
2324Srgrimes	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
2334Srgrimes}
2344Srgrimes
2354Srgrimesstatic void
2364Srgrimestest_read_format_gtar_filename_KOI8R_UTF8(const char *refname)
2374Srgrimes{
2384Srgrimes	struct archive *a;
2394Srgrimes	struct archive_entry *ae;
2404Srgrimes
2414Srgrimes	/*
2424Srgrimes	 * Read KOI8-R filename in en_US.UTF-8 with "hdrcharset=KOI8-R" option.
2434Srgrimes	 */
2444Srgrimes	if (NULL == setlocale(LC_ALL, "en_US.UTF-8")) {
2454Srgrimes		skipping("en_US.UTF-8 locale not available on this system.");
2464Srgrimes		return;
2474Srgrimes	}
2484Srgrimes
2494Srgrimes	assert((a = archive_read_new()) != NULL);
2504Srgrimes	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
2514Srgrimes	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
2524Srgrimes	if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=KOI8-R")) {
2534Srgrimes		skipping("This system cannot convert character-set"
2544Srgrimes		    " from KOI8-R to UTF-8.");
25512515Sphk		goto cleanup;
25612515Sphk	}
2574Srgrimes	assertEqualIntA(a, ARCHIVE_OK,
2584Srgrimes	    archive_read_open_filename(a, refname, 10240));
2594Srgrimes
2604Srgrimes	/* Verify regular file. */
2614Srgrimes	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
2624Srgrimes	assertEqualString("\xd0\xbf\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82",
2634Srgrimes	    archive_entry_pathname(ae));
2644Srgrimes	assertEqualInt(6, archive_entry_size(ae));
2654Srgrimes
2664Srgrimes	/* Verify regular file. */
2674Srgrimes	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
2684Srgrimes	assertEqualString("\xd0\x9f\xd0\xa0\xd0\x98\xd0\x92\xd0\x95\xd0\xa2",
2694Srgrimes	    archive_entry_pathname(ae));
2704Srgrimes	assertEqualInt(6, archive_entry_size(ae));
2714Srgrimes
2724Srgrimes
2734Srgrimes	/* End of archive. */
2744Srgrimes	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
2754Srgrimes
2764Srgrimes	/* Verify archive format. */
2774Srgrimes	assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
2784Srgrimes	assertEqualIntA(a, ARCHIVE_FORMAT_TAR_GNUTAR, archive_format(a));
2794Srgrimes
2804Srgrimes	/* Close the archive. */
2814Srgrimes	assertEqualInt(ARCHIVE_OK, archive_read_close(a));
2824Srgrimescleanup:
2834Srgrimes	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
2844Srgrimes}
2854Srgrimes
2864Srgrimesstatic void
2874Srgrimestest_read_format_gtar_filename_eucJP_CP932(const char *refname)
2884Srgrimes{
2894Srgrimes	struct archive *a;
29012515Sphk	struct archive_entry *ae;
291
292	/*
293	 * Read eucJP filename in CP932/SJIS with "hdrcharset=eucJP" option.
294	 */
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.");
298		return;
299	}
300
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"
306		    " from eucJP.");
307		goto cleanup;
308	}
309	assertEqualIntA(a, ARCHIVE_OK,
310	    archive_read_open_filename(a, refname, 10240));
311
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));
316
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));
321
322
323	/* End of archive. */
324	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
325
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));
329
330	/* Close the archive. */
331	assertEqualInt(ARCHIVE_OK, archive_read_close(a));
332cleanup:
333	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
334}
335
336static void
337test_read_format_gtar_filename_CP866_CP1251(const char *refname)
338{
339	struct archive *a;
340	struct archive_entry *ae;
341
342	/*
343	 * Read CP866 filename in CP1251 with "hdrcharset=CP866" option.
344	 */
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.");
348		return;
349	}
350
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.");
357		goto cleanup;
358	}
359	assertEqualIntA(a, ARCHIVE_OK,
360	    archive_read_open_filename(a, refname, 10240));
361
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));
367
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));
373
374
375	/* End of archive. */
376	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
377
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));
381
382	/* Close the archive. */
383	assertEqualInt(ARCHIVE_OK, archive_read_close(a));
384cleanup:
385	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
386}
387
388/*
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.
393 */
394static void
395test_read_format_gtar_filename_CP866_CP1251_win(const char *refname)
396{
397	struct archive *a;
398	struct archive_entry *ae;
399
400	/*
401	 * Read CP866 filename in CP1251 without "hdrcharset=CP866" option.
402	 */
403	if (NULL == setlocale(LC_ALL, "Russian_Russia")) {
404		skipping("Russian_Russia locale not available on this system.");
405		return;
406	}
407
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));
413
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));
419
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));
425
426
427	/* End of archive. */
428	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
429
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));
433
434	/* Close the archive. */
435	assertEqualInt(ARCHIVE_OK, archive_read_close(a));
436	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
437}
438
439static void
440test_read_format_gtar_filename_KOI8R_CP1251(const char *refname)
441{
442	struct archive *a;
443	struct archive_entry *ae;
444
445	/*
446	 * Read KOI8-R filename in CP1251 with "hdrcharset=KOI8-R" option.
447	 */
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.");
451		return;
452	}
453
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.");
460		goto cleanup;
461	}
462	assertEqualIntA(a, ARCHIVE_OK,
463	    archive_read_open_filename(a, refname, 10240));
464
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));
470
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));
476
477
478	/* End of archive. */
479	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
480
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));
484
485	/* Close the archive. */
486	assertEqualInt(ARCHIVE_OK, archive_read_close(a));
487cleanup:
488	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
489}
490
491
492DEFINE_TEST(test_read_format_gtar_filename)
493{
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";
497
498	extract_reference_file(refname1);
499	test_read_format_gtar_filename_eucJP_UTF8(refname1);
500	test_read_format_gtar_filename_eucJP_CP932(refname1);
501
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);
507
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);
512}
513