summaryrefslogtreecommitdiffstats
path: root/contrib/libarchive/libarchive/test/test_compat_pax_libarchive_2x.c
diff options
context:
space:
mode:
authormm <mm@FreeBSD.org>2012-02-25 10:58:02 +0000
committermm <mm@FreeBSD.org>2012-02-25 10:58:02 +0000
commit6132589d7bb05bbf0c9033cc9f5cf79bafdc0b0f (patch)
tree117e869a99c6fa7f789c6d9a87cf7eac26ae69e3 /contrib/libarchive/libarchive/test/test_compat_pax_libarchive_2x.c
parent87f7f0cfe8d3d17bc154ca2c0dcd51bca1444006 (diff)
parent2f6e434fe4c652da1969314fa57ae21936cec85d (diff)
downloadFreeBSD-src-6132589d7bb05bbf0c9033cc9f5cf79bafdc0b0f.zip
FreeBSD-src-6132589d7bb05bbf0c9033cc9f5cf79bafdc0b0f.tar.gz
Update libarchive to 3.0.3
Some of new features: - New readers: RAR, LHA/LZH, CAB reader, 7-Zip - New writers: ISO9660, XAR - Improvements to many formats, especially including ISO9660 and Zip - Stackable write filters to write, e.g., tar.gz.uu in a single pass - Exploit seekable input; new "seekable" Zip reader can exploit the Zip Central Directory when it's available; the old "streamable" Zip reader is still fully supported for cases where seeking is not possible. Full release notes available at: https://github.com/libarchive/libarchive/wiki/ReleaseNotes
Diffstat (limited to 'contrib/libarchive/libarchive/test/test_compat_pax_libarchive_2x.c')
-rw-r--r--contrib/libarchive/libarchive/test/test_compat_pax_libarchive_2x.c146
1 files changed, 146 insertions, 0 deletions
diff --git a/contrib/libarchive/libarchive/test/test_compat_pax_libarchive_2x.c b/contrib/libarchive/libarchive/test/test_compat_pax_libarchive_2x.c
new file mode 100644
index 0000000..6ea25e4d
--- /dev/null
+++ b/contrib/libarchive/libarchive/test/test_compat_pax_libarchive_2x.c
@@ -0,0 +1,146 @@
+/*-
+ * Copyright (c) 2011 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD");
+
+#include <locale.h>
+
+/*
+ * Test "tar:compat-2x" option that enables the string conversion of
+ * libarchive 2.x, which made incorrect UTF-8 form filenames for the
+ * pax format on some platform the wchar_t of which was not Unicode form.
+ * The option is unneeded if people have been using UTF-8 locale during
+ * making tar files(in pax format).
+ *
+ * NOTE: The sample tar file was made with bsdtar 2.x in LANG=KOI8-R on
+ * FreeBSD.
+ */
+
+DEFINE_TEST(test_compat_pax_libarchive_2x)
+{
+#if (defined(_WIN32) && !defined(__CYGWIN__)) \
+ || defined(__STDC_ISO_10646__) || defined(__APPLE__)
+ skipping("This test only for the platform the WCS of which is "
+ "not Unicode.");
+#else
+ struct archive *a;
+ struct archive_entry *ae;
+ char c;
+ wchar_t wc;
+ const char *refname = "test_compat_pax_libarchive_2x.tar.Z";
+
+ /*
+ * Read incorrect format UTF-8 filename in ru_RU.KOI8-R with
+ * "tar:compat-2x" option. We should correctly
+ * read two filenames.
+ */
+ if (NULL == setlocale(LC_ALL, "ru_RU.KOI8-R")) {
+ skipping("ru_RU.KOI8-R locale not available on this system.");
+ return;
+ }
+
+ /*
+ * Test if wchar_t format is the same as FreeBSD wchar_t.
+ */
+ assert(-1 != wctomb(NULL, L'\0'));
+ wc = (wchar_t)0xd0;
+ c = 0;
+ if (wctomb(&c, wc) != 1 || (unsigned char)c != 0xd0) {
+ skipping("wchar_t format is different on this platform.");
+ return;
+ }
+
+ extract_reference_file(refname);
+
+ assert((a = archive_read_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_set_options(a, "tar:compat-2x"));
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_open_filename(a, refname, 10240));
+
+ /* Verify regular first file. */
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+ assertEqualString("\xd0\xd2\xc9\xd7\xc5\xd4",
+ archive_entry_pathname(ae));
+ assertEqualInt(6, archive_entry_size(ae));
+
+ /* Verify regular second file. */
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+ assertEqualString("\xf0\xf2\xe9\xf7\xe5\xf4",
+ archive_entry_pathname(ae));
+ assertEqualInt(6, archive_entry_size(ae));
+
+
+ /* End of archive. */
+ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+
+ /* Verify archive format. */
+ assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
+ assertEqualIntA(a, ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE,
+ archive_format(a));
+
+ /* Close the archive. */
+ assertEqualInt(ARCHIVE_OK, archive_read_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+
+ /*
+ * Without "tar:compat-2x" option.
+ * Neither first file name nor second file name can be translated
+ * to KOI8-R.
+ */
+ assert((a = archive_read_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_open_filename(a, refname, 10240));
+
+ /* We cannot correctly read the filename. */
+ assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae));
+ assert(strcmp("\xd0\xd2\xc9\xd7\xc5\xd4",
+ archive_entry_pathname(ae)) != 0);
+ assertEqualInt(6, archive_entry_size(ae));
+
+ /* We cannot correctly read the filename. */
+ assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae));
+ assert(strcmp("\xf0\xf2\xe9\xf7\xe5\xf4",
+ archive_entry_pathname(ae)) != 0);
+ assertEqualInt(6, archive_entry_size(ae));
+
+
+ /* End of archive. */
+ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+
+ /* Verify archive format. */
+ assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
+ assertEqualIntA(a, ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE,
+ archive_format(a));
+
+ /* Close the archive. */
+ assertEqualInt(ARCHIVE_OK, archive_read_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+#endif
+}
OpenPOWER on IntegriCloud