From: Michihiro NAKAJIMA Date: Sun, 10 Apr 2011 11:17:54 +0000 (-0400) Subject: Add locale CP1251 and CP932 tests to test_pax_filename_encoding. X-Git-Tag: v3.0.0a~489 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d5e248a002036771ca508dbd653f804be25bfe0;p=thirdparty%2Flibarchive.git Add locale CP1251 and CP932 tests to test_pax_filename_encoding. SVN-Revision: 3197 --- diff --git a/libarchive/test/test_pax_filename_encoding.c b/libarchive/test/test_pax_filename_encoding.c index 8b1715ace..4832bfd90 100644 --- a/libarchive/test/test_pax_filename_encoding.c +++ b/libarchive/test/test_pax_filename_encoding.c @@ -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(); }