Skip to content

Commit

Permalink
Merge branch 'unicode-tests' of https://github.com/dunhor/libarchive
Browse files Browse the repository at this point in the history
…into unicode-tests
  • Loading branch information
dunhor committed Jun 21, 2024
2 parents e996004 + e630b07 commit d8039eb
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 30 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,7 @@ libarchive_test_EXTRA_DIST=\
libarchive/test/test_read_format_rar5_arm.rar.uu \
libarchive/test/test_read_format_rar5_blake2.rar.uu \
libarchive/test/test_read_format_rar5_compressed.rar.uu \
libarchive/test/test_read_format_rar5_unicode.rar.uu \
libarchive/test/test_read_format_rar5_different_window_size.rar.uu \
libarchive/test/test_read_format_rar5_different_solid_window_size.rar.uu \
libarchive/test/test_read_format_rar5_distance_overflow.rar.uu \
Expand Down
128 changes: 98 additions & 30 deletions libarchive/test/test_read_format_rar5.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
#include "test.h"

#include <locale.h>

/* Some tests will want to calculate some CRC32's, and this header can
* help. */
#define __LIBARCHIVE_BUILD
Expand Down Expand Up @@ -806,36 +808,6 @@ DEFINE_TEST(test_read_format_rar5_extract_win32)
EPILOGUE();
}

DEFINE_TEST(test_read_format_rar5_unicode)
{
#if !defined(WIN32) || defined(__CYGWIN__)
skipping("Skipping test on non-Windows");
return;
#else
/* Corresponds to the names:
* 👋🌎.txt
* 𝒮𝓎𝓂𝒷𝑜𝓁𝒾𝒸 𝐿𝒾𝓃𝓀.txt
* Ⓗⓐⓡⓓ Ⓛⓘⓝⓚ.txt */
const wchar_t* emoji_name = L"\U0001f44b\U0001f30e.txt";
const wchar_t* italic_name = L"\U0001d4ae\U0001d4ce\U0001d4c2\U0001d4b7\U0001d45c\U0001d4c1\U0001d4be\U0001d4b8 \U0001d43f\U0001d4be\U0001d4c3\U0001d4c0.txt";
const wchar_t* circle_name = L"\u24bd\u24d0\u24e1\u24d3 \u24c1\u24d8\u24dd\u24da.txt";

PROLOGUE("test_read_format_rar5_unicode.rar");
assertA(0 == archive_read_next_header(a, &ae));
assertEqualWString(emoji_name, archive_entry_pathname_w(ae));
assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
assertA(0 == archive_read_next_header(a, &ae));
assertEqualWString(circle_name, archive_entry_pathname_w(ae));
assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
assertEqualWString(emoji_name, archive_entry_hardlink_w(ae));
assertA(0 == archive_read_next_header(a, &ae));
assertEqualWString(italic_name, archive_entry_pathname_w(ae));
assertEqualInt(archive_entry_mode(ae), AE_IFLNK | 0644);
assertEqualWString(emoji_name, archive_entry_symlink_w(ae));
EPILOGUE();
#endif
}

DEFINE_TEST(test_read_format_rar5_block_by_block)
{
/* This test uses strange buffer sizes intentionally. */
Expand Down Expand Up @@ -1406,3 +1378,99 @@ DEFINE_TEST(test_read_format_rar5_read_data_block_uninitialized_offset)

EPILOGUE();
}

DEFINE_TEST(test_read_format_rar5_unicode)
{
PROLOGUE("test_read_format_rar5_unicode.rar");

#if !defined(_WIN32) || defined(__CYGWIN__)
if (NULL == setlocale(LC_ALL, "en_US.UTF-8")) {
skipping("en_US.UTF-8 locale not available on this system.");
EPILOGUE();
return;
}
#endif

/* Script "file.txt" */
assertA(0 == archive_read_next_header(a, &ae));
assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
#if defined(_WIN32) && !defined(__CYGWIN__)
assertEqualWString(L"\U0001d4bb\U0001d4be\U0001d4c1\U0001d452.txt",
archive_entry_pathname_w(ae));
#else
assertEqualString(
"\xf0\x9d\x92\xbb\xf0\x9d\x92\xbe\xf0\x9d\x93\x81\xf0\x9d\x91\x92.txt",
archive_entry_pathname(ae));
#endif

/* Script "hardlink.txt" */
assertA(0 == archive_read_next_header(a, &ae));
assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
#if defined(_WIN32) && !defined(__CYGWIN__)
assertEqualWString(
L"\U0001d4bd\U0001d4b6\U0001d4c7\U0001d4b9\U0001d4c1\U0001d4be\U0001d4c3\U0001d4c0.txt",
archive_entry_pathname_w(ae));
assertEqualWString(L"\U0001d4bb\U0001d4be\U0001d4c1\U0001d452.txt",
archive_entry_hardlink_w(ae));
#else
assertEqualString(
"\xf0\x9d\x92\xbd\xf0\x9d\x92\xb6\xf0\x9d\x93\x87\xf0\x9d\x92\xb9\xf0"
"\x9d\x93\x81\xf0\x9d\x92\xbe\xf0\x9d\x93\x83\xf0\x9d\x93\x80.txt",
archive_entry_pathname(ae));
assertEqualString(
"\xf0\x9d\x92\xbb\xf0\x9d\x92\xbe\xf0\x9d\x93\x81\xf0\x9d\x91\x92.txt",
archive_entry_hardlink(ae));
#endif

/* Script "symlink.txt" */
assertA(0 == archive_read_next_header(a, &ae));
assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
assertEqualInt(AE_SYMLINK_TYPE_FILE, archive_entry_symlink_type(ae));
#if defined(_WIN32) && !defined(__CYGWIN__)
assertEqualWString(
L"\U0001d4c8\U0001d4ce\U0001d4c2\U0001d4c1\U0001d4be\U0001d4c3\U0001d4c0.txt",
archive_entry_pathname_w(ae));
assertEqualWString(L"\U0001d4bb\U0001d4be\U0001d4c1\U0001d452.txt",
archive_entry_symlink_w(ae));
#else
assertEqualString("\xf0\x9d\x93\x88\xf0\x9d\x93\x8e\xf0\x9d\x93\x82\xf0"
"\x9d\x93\x81\xf0\x9d\x92\xbe\xf0\x9d\x93\x83\xf0\x9d\x93\x80.txt",
archive_entry_pathname(ae));
assertEqualString(
"\xf0\x9d\x92\xbb\xf0\x9d\x92\xbe\xf0\x9d\x93\x81\xf0\x9d\x91\x92.txt",
archive_entry_symlink(ae));
#endif

/* Script "dir" */
assertA(0 == archive_read_next_header(a, &ae));
assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
#if defined(_WIN32) && !defined(__CYGWIN__)
assertEqualWString(L"\U0001d4b9\U0001d4be\U0001d4c7",
archive_entry_pathname_w(ae));
#else
assertEqualString("\xf0\x9d\x92\xb9\xf0\x9d\x92\xbe\xf0\x9d\x93\x87",
archive_entry_pathname(ae));
#endif

/* Script "dir_symlink" */
assertA(0 == archive_read_next_header(a, &ae));
assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
assertEqualInt(AE_SYMLINK_TYPE_DIRECTORY, archive_entry_symlink_type(ae));
#if defined(_WIN32) && !defined(__CYGWIN__)
assertEqualWString(
L"\U0001d4b9\U0001d4be\U0001d4c7_\U0001d4c8\U0001d4ce\U0001d4c2\U0001d4c1\U0001d4be\U0001d4c3\U0001d4c0",
archive_entry_pathname_w(ae));
assertEqualWString(L"\U0001d4b9\U0001d4be\U0001d4c7",
archive_entry_symlink_w(ae));
#else
assertEqualString("\xf0\x9d\x92\xb9\xf0\x9d\x92\xbe\xf0\x9d\x93\x87\x5f\xf0"
"\x9d\x93\x88\xf0\x9d\x93\x8e\xf0\x9d\x93\x82\xf0\x9d\x93\x81\xf0\x9d"
"\x92\xbe\xf0\x9d\x93\x83\xf0\x9d\x93\x80", archive_entry_pathname(ae));
assertEqualString("\xf0\x9d\x92\xb9\xf0\x9d\x92\xbe\xf0\x9d\x93\x87",
archive_entry_symlink(ae));
#endif

assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));

EPILOGUE();
}

0 comments on commit d8039eb

Please sign in to comment.