|
Packit |
08bd4c |
/*-
|
|
Packit |
08bd4c |
* Copyright (c) 2011 Michihiro NAKAJIMA
|
|
Packit |
08bd4c |
* All rights reserved.
|
|
Packit |
08bd4c |
*
|
|
Packit |
08bd4c |
* Redistribution and use in source and binary forms, with or without
|
|
Packit |
08bd4c |
* modification, are permitted provided that the following conditions
|
|
Packit |
08bd4c |
* are met:
|
|
Packit |
08bd4c |
* 1. Redistributions of source code must retain the above copyright
|
|
Packit |
08bd4c |
* notice, this list of conditions and the following disclaimer.
|
|
Packit |
08bd4c |
* 2. Redistributions in binary form must reproduce the above copyright
|
|
Packit |
08bd4c |
* notice, this list of conditions and the following disclaimer in the
|
|
Packit |
08bd4c |
* documentation and/or other materials provided with the distribution.
|
|
Packit |
08bd4c |
*
|
|
Packit |
08bd4c |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
|
Packit |
08bd4c |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
Packit |
08bd4c |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
Packit |
08bd4c |
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
Packit |
08bd4c |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
Packit |
08bd4c |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
Packit |
08bd4c |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
Packit |
08bd4c |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
Packit |
08bd4c |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
Packit |
08bd4c |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
08bd4c |
*/
|
|
Packit |
08bd4c |
#include "test.h"
|
|
Packit |
08bd4c |
__FBSDID("$FreeBSD");
|
|
Packit |
08bd4c |
|
|
Packit |
08bd4c |
#include <locale.h>
|
|
Packit |
08bd4c |
|
|
Packit |
08bd4c |
/*
|
|
Packit |
08bd4c |
* Test "tar:compat-2x" option that enables the string conversion of
|
|
Packit |
08bd4c |
* libarchive 2.x, which made incorrect UTF-8 form filenames for the
|
|
Packit |
08bd4c |
* pax format on some platform the wchar_t of which was not Unicode form.
|
|
Packit |
08bd4c |
* The option is unneeded if people have been using UTF-8 locale during
|
|
Packit |
08bd4c |
* making tar files(in pax format).
|
|
Packit |
08bd4c |
*
|
|
Packit |
08bd4c |
* NOTE: The sample tar file was made with bsdtar 2.x in LANG=KOI8-R on
|
|
Packit |
08bd4c |
* FreeBSD.
|
|
Packit |
08bd4c |
*/
|
|
Packit |
08bd4c |
|
|
Packit |
08bd4c |
DEFINE_TEST(test_compat_pax_libarchive_2x)
|
|
Packit |
08bd4c |
{
|
|
Packit |
08bd4c |
#if (defined(_WIN32) && !defined(__CYGWIN__)) \
|
|
Packit |
08bd4c |
|| defined(__STDC_ISO_10646__) || defined(__APPLE__)
|
|
Packit |
08bd4c |
skipping("This test only for the platform the WCS of which is "
|
|
Packit |
08bd4c |
"not Unicode.");
|
|
Packit |
08bd4c |
#else
|
|
Packit |
08bd4c |
struct archive *a;
|
|
Packit |
08bd4c |
struct archive_entry *ae;
|
|
Packit |
08bd4c |
char c;
|
|
Packit |
08bd4c |
wchar_t wc;
|
|
Packit |
08bd4c |
const char *refname = "test_compat_pax_libarchive_2x.tar.Z";
|
|
Packit |
08bd4c |
|
|
Packit |
08bd4c |
/*
|
|
Packit |
08bd4c |
* Read incorrect format UTF-8 filename in ru_RU.KOI8-R with
|
|
Packit |
08bd4c |
* "tar:compat-2x" option. We should correctly
|
|
Packit |
08bd4c |
* read two filenames.
|
|
Packit |
08bd4c |
*/
|
|
Packit |
08bd4c |
if (NULL == setlocale(LC_ALL, "ru_RU.KOI8-R")) {
|
|
Packit |
08bd4c |
skipping("ru_RU.KOI8-R locale not available on this system.");
|
|
Packit |
08bd4c |
return;
|
|
Packit |
08bd4c |
}
|
|
Packit |
08bd4c |
|
|
Packit |
08bd4c |
/*
|
|
Packit |
08bd4c |
* Test if wchar_t format is the same as FreeBSD wchar_t.
|
|
Packit |
08bd4c |
*/
|
|
Packit |
08bd4c |
assert(-1 != wctomb(NULL, L'\0'));
|
|
Packit |
08bd4c |
wc = (wchar_t)0xd0;
|
|
Packit |
08bd4c |
c = 0;
|
|
Packit |
08bd4c |
if (wctomb(&c, wc) != 1 || (unsigned char)c != 0xd0) {
|
|
Packit |
08bd4c |
skipping("wchar_t format is different on this platform.");
|
|
Packit |
08bd4c |
return;
|
|
Packit |
08bd4c |
}
|
|
Packit |
08bd4c |
|
|
Packit |
08bd4c |
extract_reference_file(refname);
|
|
Packit |
08bd4c |
|
|
Packit |
08bd4c |
assert((a = archive_read_new()) != NULL);
|
|
Packit |
08bd4c |
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
|
|
Packit |
08bd4c |
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
|
|
Packit |
08bd4c |
assertEqualIntA(a, ARCHIVE_OK,
|
|
Packit |
08bd4c |
archive_read_set_options(a, "tar:compat-2x"));
|
|
Packit |
08bd4c |
assertEqualIntA(a, ARCHIVE_OK,
|
|
Packit |
08bd4c |
archive_read_open_filename(a, refname, 10240));
|
|
Packit |
08bd4c |
|
|
Packit |
08bd4c |
/* Verify regular first file. */
|
|
Packit |
08bd4c |
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae);;
|
|
Packit |
08bd4c |
assertEqualString("\xd0\xd2\xc9\xd7\xc5\xd4",
|
|
Packit |
08bd4c |
archive_entry_pathname(ae));
|
|
Packit |
08bd4c |
assertEqualInt(6, archive_entry_size(ae));
|
|
Packit |
08bd4c |
|
|
Packit |
08bd4c |
/* Verify regular second file. */
|
|
Packit |
08bd4c |
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae);;
|
|
Packit |
08bd4c |
assertEqualString("\xf0\xf2\xe9\xf7\xe5\xf4",
|
|
Packit |
08bd4c |
archive_entry_pathname(ae));
|
|
Packit |
08bd4c |
assertEqualInt(6, archive_entry_size(ae));
|
|
Packit |
08bd4c |
|
|
Packit |
08bd4c |
|
|
Packit |
08bd4c |
/* End of archive. */
|
|
Packit |
08bd4c |
assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae);;
|
|
Packit |
08bd4c |
|
|
Packit |
08bd4c |
/* Verify archive format. */
|
|
Packit |
08bd4c |
assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
|
|
Packit |
08bd4c |
assertEqualIntA(a, ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE,
|
|
Packit |
08bd4c |
archive_format(a));
|
|
Packit |
08bd4c |
|
|
Packit |
08bd4c |
/* Close the archive. */
|
|
Packit |
08bd4c |
assertEqualInt(ARCHIVE_OK, archive_read_close(a));
|
|
Packit |
08bd4c |
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
|
|
Packit |
08bd4c |
|
|
Packit |
08bd4c |
/*
|
|
Packit |
08bd4c |
* Without "tar:compat-2x" option.
|
|
Packit |
08bd4c |
* Neither first file name nor second file name can be translated
|
|
Packit |
08bd4c |
* to KOI8-R.
|
|
Packit |
08bd4c |
*/
|
|
Packit |
08bd4c |
assert((a = archive_read_new()) != NULL);
|
|
Packit |
08bd4c |
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
|
|
Packit |
08bd4c |
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
|
|
Packit |
08bd4c |
assertEqualIntA(a, ARCHIVE_OK,
|
|
Packit |
08bd4c |
archive_read_open_filename(a, refname, 10240));
|
|
Packit |
08bd4c |
|
|
Packit |
08bd4c |
/* We cannot correctly read the filename. */
|
|
Packit |
08bd4c |
// This test used to look for WARN here coming from a
|
|
Packit |
08bd4c |
// character-conversion failure. But: Newer iconv tables are
|
|
Packit |
08bd4c |
// more tolerant so we can't always detect the conversion
|
|
Packit |
08bd4c |
// failures.
|
|
Packit |
08bd4c |
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae);;
|
|
Packit |
08bd4c |
assert(strcmp("\xd0\xd2\xc9\xd7\xc5\xd4",
|
|
Packit |
08bd4c |
archive_entry_pathname(ae)) != 0);
|
|
Packit |
08bd4c |
assertEqualInt(6, archive_entry_size(ae));
|
|
Packit |
08bd4c |
|
|
Packit |
08bd4c |
/* We cannot correctly read the filename. */
|
|
Packit |
08bd4c |
// Same here: The test is still valid (it sill verifies that
|
|
Packit |
08bd4c |
// the converted pathname is different), but we can no longer
|
|
Packit |
08bd4c |
// rely on WARN here.
|
|
Packit |
08bd4c |
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae);;
|
|
Packit |
08bd4c |
assert(strcmp("\xf0\xf2\xe9\xf7\xe5\xf4",
|
|
Packit |
08bd4c |
archive_entry_pathname(ae)) != 0);
|
|
Packit |
08bd4c |
assertEqualInt(6, archive_entry_size(ae));
|
|
Packit |
08bd4c |
|
|
Packit |
08bd4c |
|
|
Packit |
08bd4c |
/* End of archive. */
|
|
Packit |
08bd4c |
assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae);;
|
|
Packit |
08bd4c |
|
|
Packit |
08bd4c |
/* Verify archive format. */
|
|
Packit |
08bd4c |
assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
|
|
Packit |
08bd4c |
assertEqualIntA(a, ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE,
|
|
Packit |
08bd4c |
archive_format(a));
|
|
Packit |
08bd4c |
|
|
Packit |
08bd4c |
/* Close the archive. */
|
|
Packit |
08bd4c |
assertEqualInt(ARCHIVE_OK, archive_read_close(a));
|
|
Packit |
08bd4c |
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
|
|
Packit |
08bd4c |
#endif
|
|
Packit |
08bd4c |
}
|