]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Added a test case on lha with UTF-16 filenames.
authorClaybird <claybird.without.wing@gmail.com>
Mon, 4 Nov 2019 06:01:26 +0000 (15:01 +0900)
committerClaybird <claybird.without.wing@gmail.com>
Wed, 6 Nov 2019 11:34:31 +0000 (20:34 +0900)
Makefile.am
libarchive/test/CMakeLists.txt
libarchive/test/test_read_format_lha_filename_utf16.c [new file with mode: 0644]
libarchive/test/test_read_format_lha_filename_utf16.lzh.uu [new file with mode: 0644]

index 03805b4b9142e5f337489d936e49fbc817ab4240..be865cca2c970451554a78ac50f53702b0e54e4d 100644 (file)
@@ -488,6 +488,7 @@ libarchive_test_SOURCES= \
        libarchive/test/test_read_format_lha.c \
        libarchive/test/test_read_format_lha_bugfix_0.c \
        libarchive/test/test_read_format_lha_filename.c \
+       libarchive/test/test_read_format_lha_filename_utf16.c \
        libarchive/test/test_read_format_mtree.c \
        libarchive/test/test_read_format_mtree_crash747.c \
        libarchive/test/test_read_format_pax_bz2.c \
index 2f451d2a06498b5a5953e0bebb81c3d279ad5422..b25892565bd785603d783f3109ccdd4f0c7bd832 100644 (file)
@@ -141,6 +141,7 @@ IF(ENABLE_TEST)
     test_read_format_lha.c
     test_read_format_lha_bugfix_0.c
     test_read_format_lha_filename.c
+    test_read_format_lha_filename_utf16.c
     test_read_format_mtree.c
     test_read_format_mtree_crash747.c
     test_read_format_pax_bz2.c
diff --git a/libarchive/test/test_read_format_lha_filename_utf16.c b/libarchive/test/test_read_format_lha_filename_utf16.c
new file mode 100644 (file)
index 0000000..b2729fb
--- /dev/null
@@ -0,0 +1,97 @@
+/*-
+ * Copyright (c) 2019 Claybird
+ * 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>
+
+static void
+test_read_format_lha_filename_UTF16_UTF8(const char *refname)
+{
+       struct archive *a;
+       struct archive_entry *ae;
+
+       /*
+        * Read LHA filename in en_US.UTF-8.
+        */
+       if (NULL == setlocale(LC_ALL, "en_US.UTF-8")) {
+               skipping("en_US.UTF-8 locale not available on this system.");
+               return;
+       }
+       /*
+        * Create a read object only for a test that platform support
+        * a character-set conversion because we can read a character-set
+        * of filenames from the header of an lha archive file and so we
+        * want to test that it works well. 
+        */
+       assert((a = archive_read_new()) != NULL);
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+       if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=UTF-16")) {
+               assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+               skipping("This system cannot convert character-set"
+                   " from UTF-16 to UTF-8.");
+               return;
+       }
+       assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+       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));
+
+       /* Verify regular file. */
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+       assertEqualString("\xc3\x9c\xc3\x96\xc3\x84\xc3\xbc\xc3\xb6\xc3\xa4/"
+           "\xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c.txt",
+           archive_entry_pathname(ae));
+       assertEqualInt(12, archive_entry_size(ae));
+
+       /* Verify directory. */
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+       assertEqualString("\xc3\x9c\xc3\x96\xc3\x84\xc3\xbc\xc3\xb6\xc3\xa4/",
+           archive_entry_pathname(ae));
+       assertEqualInt(0, archive_entry_size(ae));
+
+       /* End of archive. */
+       assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+
+       /* Verify archive format. */
+       assertEqualIntA(a, ARCHIVE_FILTER_NONE, archive_filter_code(a, 0));
+       assertEqualIntA(a, ARCHIVE_FORMAT_LHA, archive_format(a));
+
+       /* Close the archive. */
+       assertEqualInt(ARCHIVE_OK, archive_read_close(a));
+       assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+}
+
+DEFINE_TEST(test_read_format_lha_filename_UTF16)
+{
+       /* A sample file was created with Unlha32.dll. */
+       const char *refname = "test_read_format_lha_filename_utf16.lzh";
+       extract_reference_file(refname);
+
+       test_read_format_lha_filename_UTF16_UTF8(refname);
+}
+
diff --git a/libarchive/test/test_read_format_lha_filename_utf16.lzh.uu b/libarchive/test/test_read_format_lha_filename_utf16.lzh.uu
new file mode 100644 (file)
index 0000000..6ca1313
--- /dev/null
@@ -0,0 +1,9 @@
+begin 644 test_read_format_lha_filename_utf16.lzh\r
+M@0`M;&@P+0P````,````L/5872`"IW%-!P!&I`,```T``5]?7U]?7RYT>'0*\r
+M``)?7U]?7U__%P!$Y`#V`/P`Q`#6`-P`+@!T`'@`=``1`$7<`-8`Q`#\`/8`\r
+MY`#__QL`078S<F.15=4!]0V8@I%5U0'U#9B"D575`08```\:!P``PZ3#ML.\\r
+MPX3#EL.<90`M;&AD+0``````````PX"D72`"``!-!P!&I`,```,``0H``E]?\r
+M7U]?7_\%`$`0`!$`1=P`U@#$`/P`]@#D`/__&P!!FDHB>9B"U0$H^DQ_F(+5\r
+2`2CZ3'^8@M4!!@``GW<'````\r
+`\r
+end\r