]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Add locale CP1251 and CP932 tests to test_pax_filename_encoding.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sun, 10 Apr 2011 11:17:54 +0000 (07:17 -0400)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sun, 10 Apr 2011 11:17:54 +0000 (07:17 -0400)
SVN-Revision: 3197

libarchive/test/test_pax_filename_encoding.c

index 8b1715acea4d38c6e226aae80930146b133dbc9e..4832bfd90cc48b3b09736293a05a79013026172e 100644 (file)
@@ -330,7 +330,7 @@ test_pax_filename_encoding_3(void)
  * Verify that KOI8-R filenames are correctly translated to Unicode and UTF-8.
  */
 static void
-test_pax_filename_encoding_ru_RU()
+test_pax_filename_encoding_KOI8R()
 {
        struct archive *a;
        struct archive_entry *entry;
@@ -372,11 +372,58 @@ test_pax_filename_encoding_ru_RU()
        assertEqualMem(buff + 512, "15 path=\xD0\xBF\xD1\x80\xD0\xB8\x0A", 15);
 }
 
+/*
+ * Verify that KOI8-R filenames are correctly translated to Unicode and UTF-8.
+ */
+static void
+test_pax_filename_encoding_CP1251()
+{
+       struct archive *a;
+       struct archive_entry *entry;
+       char buff[4096];
+       size_t used;
+
+       if (NULL == setlocale(LC_ALL, "Russian_Russia") &&
+           NULL == setlocale(LC_ALL, "ru_RU.CP1251")) {
+               skipping("KOI8-R locale not available on this system.");
+               return;
+       }
+
+       /* Check if the paltform completely supports the string conversion. */
+       a = archive_write_new();
+       assertEqualInt(ARCHIVE_OK, archive_write_set_format_pax(a));
+       if (archive_write_set_options(a, "hdrcharset=UTF-8") != ARCHIVE_OK) {
+               skipping("This system cannot convert character-set"
+                   " from KOI8-R to UTF-8.");
+               archive_write_free(a);
+               return;
+       }
+       archive_write_free(a);
+
+       /* Re-create a write archive object since filenames should be written
+        * in UTF-8 by default. */
+       a = archive_write_new();
+       assertEqualInt(ARCHIVE_OK, archive_write_set_format_pax(a));
+       assertEqualInt(ARCHIVE_OK, archive_write_open_memory(a, buff, sizeof(buff), &used));
+
+       entry = archive_entry_new2(a);
+       archive_entry_set_pathname(entry, "\xef\xf0\xe8");
+       archive_entry_set_filetype(entry, AE_IFREG);
+       archive_entry_set_size(entry, 0);
+       assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry));
+       archive_entry_free(entry);
+       assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+
+       /* Above three characters in KOI8-R should translate to the following
+        * three characters (two bytes each) in UTF-8. */
+       assertEqualMem(buff + 512, "15 path=\xD0\xBF\xD1\x80\xD0\xB8\x0A", 15);
+}
+
 /*
  * Verify that EUC-JP filenames are correctly translated to Unicode and UTF-8.
  */
 static void
-test_pax_filename_encoding_ja_JP()
+test_pax_filename_encoding_EUCJP()
 {
        struct archive *a;
        struct archive_entry *entry;
@@ -419,11 +466,61 @@ test_pax_filename_encoding_ja_JP()
 
 }
 
+/*
+ * Verify that CP932/SJIS filenames are correctly translated to Unicode and UTF-8.
+ */
+static void
+test_pax_filename_encoding_CP932()
+{
+       struct archive *a;
+       struct archive_entry *entry;
+       char buff[4096];
+       size_t used;
+
+       if (NULL == setlocale(LC_ALL, "Japanese_Japan") &&
+           NULL == setlocale(LC_ALL, "ja_JP.SJIS")) {
+               skipping("eucJP locale not available on this system.");
+               return;
+       }
+
+       /* Check if the paltform completely supports the string conversion. */
+       a = archive_write_new();
+       assertEqualInt(ARCHIVE_OK, archive_write_set_format_pax(a));
+       if (archive_write_set_options(a, "hdrcharset=UTF-8") != ARCHIVE_OK) {
+               skipping("This system cannot convert character-set"
+                   " from CP932/SJIS to UTF-8.");
+               archive_write_free(a);
+               return;
+       }
+       archive_write_free(a);
+
+       /* Re-create a write archive object since filenames should be written
+        * in UTF-8 by default. */
+       a = archive_write_new();
+       assertEqualInt(ARCHIVE_OK, archive_write_set_format_pax(a));
+       assertEqualInt(ARCHIVE_OK, archive_write_open_memory(a, buff, sizeof(buff), &used));
+
+       entry = archive_entry_new2(a);
+       archive_entry_set_pathname(entry, "\x95\x5C.txt");
+       /* Check the Unicode version. */
+       archive_entry_set_filetype(entry, AE_IFREG);
+       archive_entry_set_size(entry, 0);
+       assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry));
+       archive_entry_free(entry);
+       assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+
+       /* Check UTF-8 version. */
+       assertEqualMem(buff + 512, "16 path=\xE8\xA1\xA8.txt\x0A", 16);
+
+}
+
 DEFINE_TEST(test_pax_filename_encoding)
 {
        test_pax_filename_encoding_1();
        test_pax_filename_encoding_2();
        test_pax_filename_encoding_3();
-       test_pax_filename_encoding_ru_RU();
-       test_pax_filename_encoding_ja_JP();
+       test_pax_filename_encoding_KOI8R();
+       test_pax_filename_encoding_CP1251();
+       test_pax_filename_encoding_EUCJP();
+       test_pax_filename_encoding_CP932();
 }