diff options
author | Martin Matuska <mm@FreeBSD.org> | 2020-12-16 22:25:40 +0000 |
---|---|---|
committer | Martin Matuska <mm@FreeBSD.org> | 2020-12-16 22:25:40 +0000 |
commit | 3ad46d07830bba44c479e2d19ce376212e52e9af (patch) | |
tree | dbd7e07db590bf11512996d9378557237a293e39 /contrib/libarchive/libarchive/test/test_archive_string_conversion.c | |
parent | e61d354b85d80126c4833746c22f320c31b68a2b (diff) | |
download | src-3ad46d07830bba44c479e2d19ce376212e52e9af.tar.gz src-3ad46d07830bba44c479e2d19ce376212e52e9af.zip |
MFC r368207,368607:stable/10
MFC r368207:
Update libarchive to 3.5.0
Relevant vendor changes:
Issue #1258: add archive_read_support_filter_by_code()
PR #1347: mtree digest reader support
Issue #1381: skip hardlinks pointing to itself on extraction
PR #1387: fix writing of cpio archives with hardlinks without file type
PR #1388: fix rdev field in cpio format for device nodes
PR #1389: completed support for UTF-8 encoding conversion
PR #1405: more formats in archive_read_support_format_by_code()
PR #1408: fix uninitialized size in rar5_read_data
PR #1409: system extended attribute support
PR #1435: support for decompression of symbolic links in zipx archives
Issue #1456: memory leak after unsuccessful archive_write_open_filename
MFC r368607:
Sync libarchive with vendor.
Vendor changes:
Issue #1461: Unbreak build without lzma
Issue #1462: warc reader: Fix build with gcc11
Issue #1463: Fix code compatibility in test_archive_read_support.c
Issue #1464: Use built-in strnlen on platforms where not available
Issue #1465: warc reader: fix undefined behaviour in deconst() function
Notes
Notes:
svn path=/stable/10/; revision=368708
Diffstat (limited to 'contrib/libarchive/libarchive/test/test_archive_string_conversion.c')
-rw-r--r-- | contrib/libarchive/libarchive/test/test_archive_string_conversion.c | 79 |
1 files changed, 77 insertions, 2 deletions
diff --git a/contrib/libarchive/libarchive/test/test_archive_string_conversion.c b/contrib/libarchive/libarchive/test/test_archive_string_conversion.c index e86f97c8a492..fb5359b6f349 100644 --- a/contrib/libarchive/libarchive/test/test_archive_string_conversion.c +++ b/contrib/libarchive/libarchive/test/test_archive_string_conversion.c @@ -445,7 +445,7 @@ test_archive_string_normalization_nfc(const char *testdata) assertEqualInt(0, archive_mstring_copy_wcs(&mstr, wc_nfc)); assertEqualInt(0, archive_mstring_get_mbs_l( - &mstr, &mp, &mplen, t_sconv8)); + a, &mstr, &mp, &mplen, t_sconv8)); failure("WCS NFC(%s) should be UTF-8 NFC:%d" ,nfc, line); assertEqualUTF8String(utf8_nfc, mp); @@ -695,7 +695,7 @@ test_archive_string_normalization_mac_nfd(const char *testdata) assertEqualInt(0, archive_mstring_copy_wcs( &mstr, wc_nfd)); assertEqualInt(0, archive_mstring_get_mbs_l( - &mstr, &mp, &mplen, t_sconv8)); + a, &mstr, &mp, &mplen, t_sconv8)); failure("WCS NFD(%s) should be UTF-8 NFD:%d" ,nfd, line); assertEqualUTF8String(utf8_nfd, mp); @@ -777,6 +777,80 @@ test_archive_string_canonicalization(void) } +static void +check_string(struct archive *a, struct archive_mstring *mstr, struct archive_string_conv *sc, + const char *exp, const wchar_t *wexp) +{ + /* Do all the tests on a copy so that we can have a clear initial state every time */ + struct archive_mstring mstr2; + const char *p = NULL; + const wchar_t *wp = NULL; + size_t len = 0; + + memset(&mstr2, 0, sizeof(mstr2)); + + archive_mstring_copy(&mstr2, mstr); + assertEqualInt(0, archive_mstring_get_mbs(a, &mstr2, &p)); + assertEqualString(exp, p); + p = NULL; + + archive_mstring_copy(&mstr2, mstr); + assertEqualInt(0, archive_mstring_get_utf8(a, &mstr2, &p)); + assertEqualString(exp, p); + p = NULL; + + archive_mstring_copy(&mstr2, mstr); + assertEqualInt(0, archive_mstring_get_wcs(a, &mstr2, &wp)); + assertEqualWString(wexp, wp); + wp = NULL; + + archive_mstring_copy(&mstr2, mstr); + assertEqualInt(0, archive_mstring_get_mbs_l(a, &mstr2, &p, &len, sc)); + assertEqualString(exp, p); + assertEqualInt(len, strlen(exp)); + p = NULL; + len = 0; + + archive_mstring_clean(&mstr2); +} + +/* + * Make sure no matter what the input encoding is, the string can be + * converted too all the output encodings. + */ +static void +test_archive_string_set_get(void) +{ + struct archive *a; + struct archive_mstring mstr; + struct archive_string_conv *sc; + + setlocale(LC_ALL, "en_US.UTF-8"); + + assert((a = archive_read_new()) != NULL); + memset(&mstr, 0, sizeof(mstr)); + + assertA(NULL != (sc = + archive_string_conversion_to_charset(a, "UTF-8", 1))); + failure("Charset name should be UTF-8"); + assertEqualString("UTF-8", + archive_string_conversion_charset_name(sc)); + + assertEqualInt(0, archive_mstring_copy_mbs(&mstr, "AAA")); + check_string(a, &mstr, sc, "AAA", L"AAA"); + assertEqualInt(4, archive_mstring_copy_utf8(&mstr, "BBBB")); + check_string(a, &mstr, sc, "BBBB", L"BBBB"); + assertEqualInt(0, archive_mstring_copy_wcs(&mstr, L"CCC12")); + check_string(a, &mstr, sc, "CCC12", L"CCC12"); + assertEqualInt(0, archive_mstring_copy_mbs_len_l(&mstr, "DDDD-l", 6, sc)); + check_string(a, &mstr, sc, "DDDD-l", L"DDDD-l"); + assertEqualInt(0, archive_mstring_update_utf8(a, &mstr, "EEEEE---H")); + check_string(a, &mstr, sc, "EEEEE---H", L"EEEEE---H"); + + assertEqualInt(ARCHIVE_OK, archive_read_free(a)); + +} + DEFINE_TEST(test_archive_string_conversion) { static const char reffile[] = "test_archive_string_conversion.txt.Z"; @@ -807,4 +881,5 @@ DEFINE_TEST(test_archive_string_conversion) test_archive_string_normalization_nfc(testdata); test_archive_string_normalization_mac_nfd(testdata); test_archive_string_canonicalization(); + test_archive_string_set_get(); } |