Skip to content

Commit

Permalink
Expand test verification some more
Browse files Browse the repository at this point in the history
  • Loading branch information
kientzle committed Jul 7, 2024
1 parent c641286 commit 8677c0f
Showing 1 changed file with 43 additions and 15 deletions.
58 changes: 43 additions & 15 deletions libarchive/test/test_pax_filename_encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,9 @@ DEFINE_TEST(test_pax_filename_encoding_UTF16_win)
}
archive_write_free(a);

/* Create a new archive handle with default charset handling */
/*
* Create a new archive handle with default charset handling
*/
a = archive_write_new();
assertEqualInt(ARCHIVE_OK, archive_write_set_format_pax(a));
assertEqualInt(ARCHIVE_OK,
Expand Down Expand Up @@ -649,28 +651,54 @@ DEFINE_TEST(test_pax_filename_encoding_UTF16_win)
archive_entry_free(entry);
assertEqualInt(ARCHIVE_OK, archive_write_free(a));

/* Verify the bytes of the file directly to ensure the
* filenames were encoded the way we expect. */
/*
* Examine the bytes to ensure the filenames ended up UTF-8
* encoded as we expect.
*/

p = buff + 0; /* First header */
assertEqualString(p + 0, "\xE4\xBD\xA0\xE5\xA5\xBD.txt");
assertEqualInt(p[156], '0'); /* Regular file */
/* Part 1: file */
p = buff + 0;
assertEqualString(p + 0, "PaxHeader/\xE4\xBD\xA0\xE5\xA5\xBD.txt"); /* File name */
assertEqualInt(p[156], 'x'); /* Pax extension header */
p += 512; /* Pax extension body */
assertEqualString(p + 0, "19 path=\xE4\xBD\xA0\xE5\xA5\xBD.txt\n");
p += 512; /* Ustar header */
assertEqualString(p + 0, "\xE4\xBD\xA0\xE5\xA5\xBD.txt"); /* File name */
assertEqualInt(p[156], '0');

p += 512; /* Second header */
assertEqualString(p + 0, "\xD0\xBF\xD1\x80\xD0\xB8/");
/* Part 2: directory */
p += 512; /* Pax extension header */
assertEqualString(p + 0, "PaxHeader/\xD0\xBF\xD1\x80\xD0\xB8/"); /* File name */
assertEqualInt(p[156], 'x');
p += 512; /* Pax extension body */
assertEqualString(p + 0, "16 path=\xD0\xBF\xD1\x80\xD0\xB8/\n");
p += 512; /* Ustar header */
assertEqualString(p + 0, "\xD0\xBF\xD1\x80\xD0\xB8/"); /* File name */
assertEqualInt(p[156], '5'); /* directory */

p += 512; /* Third header */
assertEqualString(p + 0, "\xE5\x86\x8D\xE8\xA7\x81.txt");
/* Part 3: symlink */
p += 512; /* Pax Extension Header */
assertEqualString(p + 0, "PaxHeader/\xE5\x86\x8D\xE8\xA7\x81.txt - GHI"); /* File name */
p += 512; /* Pax extension body */
assertEqualString(p + 0, "16 path=\n");
p += 512; /* Ustar header */
assertEqualString(p + 0, "\xE5\x86\x8D\xE8\xA7\x81.txt - GHI"); /* File name */
assertEqualInt(p[156], '2'); /* symlink */
assertEqualString(p + 157, "\xE6\x99\x9A\xE5\xAE\x89.txt"); /* link name */
assertEqualString(p + 157, "\xE6\x99\x9A\xE5\xAE\x89.txt - JKL"); /* link name */

p += 512; /* Fourth header */
assertEqualString(p + 0, "\xE6\x99\x9A\xE5\xAE\x89.txt");
/* Part 4: hardlink */
p += 512; /* Pax extension header */
assertEqualString(p + 0, "\xE6\x99\x9A\xE5\xAE\x89.txt - MNO"); /* File name */
p += 512; /* Pax extension body */
assertEqualString(p + 0, "16 path=\n");
p += 512; /* Ustar header */
assertEqualString(p + 0, "\xE6\x99\x9A\xE5\xAE\x89.txt - MNO"); /* File name */
assertEqualInt(p[156], '1'); /* hard link */
assertEqualString(p + 157, "\xE6\x99\x9A\xE5\xAE\x89.txt"); /* link name */
assertEqualString(p + 157, "\xE6\x99\x9A\xE5\xAE\x89.txt - PQR"); /* link name */

/* Ensure that the names round trip properly */
/*
* Read back the archive to see if we get the original names
*/
a = archive_read_new();
archive_read_support_format_all(a);
archive_read_support_filter_all(a);
Expand Down

0 comments on commit 8677c0f

Please sign in to comment.