summaryrefslogtreecommitdiff
path: root/lib/util/charset
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2011-03-31 10:28:36 +1100
committerAndrew Bartlett <abartlet@samba.org>2011-03-31 10:53:24 +1100
commit7fe9bb8c8410ce47c6256e2430905988ca3429a0 (patch)
tree715c666404ff362aaff03870cb6480c259c7969a /lib/util/charset
parentd4f3a380e429b9b8a4960a11995846c2b0f8c85d (diff)
downloadsamba-7fe9bb8c8410ce47c6256e2430905988ca3429a0.tar.gz
samba-7fe9bb8c8410ce47c6256e2430905988ca3429a0.tar.bz2
samba-7fe9bb8c8410ce47c6256e2430905988ca3429a0.zip
lib/util/charset Add tests for strlen_m_ext() and convert_string_talloc()
This convers a few more cases for convert_string_talloc() and introduces tests for strlen_m_ext() across complex multibyte strings. Andrew Bartlett
Diffstat (limited to 'lib/util/charset')
-rw-r--r--lib/util/charset/tests/convert_string.c89
1 files changed, 87 insertions, 2 deletions
diff --git a/lib/util/charset/tests/convert_string.c b/lib/util/charset/tests/convert_string.c
index d57491caf5..5c7bdcb1da 100644
--- a/lib/util/charset/tests/convert_string.c
+++ b/lib/util/charset/tests/convert_string.c
@@ -180,6 +180,25 @@ static bool test_gd_iso8859_cp850(struct torture_context *tctx)
(void *)&gd_output.data, &gd_output.length),
"conversion from (dos charset) ISO8859-1 to UTF16LE");
torture_assert_data_blob_equal(tctx, gd_output, gd_utf16le, "conversion from (dos charset) ISO8859-1 to UTF16LE");
+ torture_assert_int_equal(tctx,
+ strlen_m_ext_handle(iconv_handle,
+ (const char *)gd_iso8859_1.data,
+ CH_DOS, CH_UTF16LE),
+ gd_output.length / 2,
+ "checking strlen_m_ext of round trip conversion of UTF16 latin charset greek to display charset UTF8 and back again");
+
+ torture_assert(tctx, convert_string_talloc_handle(tctx, iconv_handle,
+ CH_DOS, CH_UTF8,
+ gd_iso8859_1.data, gd_iso8859_1.length,
+ (void *)&gd_output.data, &gd_output.length),
+ "conversion from (dos charset) ISO8859-1 to UTF8");
+ torture_assert_data_blob_equal(tctx, gd_output, gd_utf8, "conversion from (dos charset) ISO8859-1 to UTF8");
+ torture_assert_int_equal(tctx,
+ strlen_m_ext_handle(iconv_handle,
+ (const char *)gd_iso8859_1.data,
+ CH_DOS, CH_UTF8),
+ gd_output.length,
+ "checking strlen_m_ext of conversion from (dos charset) ISO8859-1 to UTF8");
return true;
}
@@ -292,6 +311,41 @@ static bool test_plato_cp850_utf8(struct torture_context *tctx)
torture_assert(tctx, iconv_handle, "creating iconv handle");
torture_assert(tctx, convert_string_talloc_handle(tctx, iconv_handle,
+ CH_UTF8, CH_UTF16LE,
+ plato_utf8.data, plato_utf8.length,
+ (void *)&plato_output.data, &plato_output.length),
+ "conversion of UTF8 ancient greek to UTF16 failed");
+ torture_assert_data_blob_equal(tctx, plato_output, plato_utf16le, "conversion from UTF8 to UTF16LE incorrect");
+
+ torture_assert_int_equal(tctx,
+ strlen_m_ext_handle(iconv_handle,
+ (const char *)plato_utf8.data,
+ CH_UTF8, CH_UTF16LE),
+ plato_output.length / 2,
+ "checking strlen_m_ext of conversion of UTF8 to UTF16LE");
+
+ torture_assert(tctx, convert_string_talloc_handle(tctx, iconv_handle,
+ CH_UTF16LE, CH_UTF8,
+ plato_output.data, plato_output.length,
+ (void *)&plato_output2.data, &plato_output2.length),
+ "conversion of UTF8 ancient greek to UTF16 failed");
+ torture_assert_data_blob_equal(tctx, plato_output2, plato_utf8, "conversion from UTF8 to UTF16LE incorrect");
+
+ torture_assert(tctx, convert_string_talloc_handle(tctx, iconv_handle,
+ CH_UTF8, CH_UTF8,
+ plato_utf8.data, plato_utf8.length,
+ (void *)&plato_output.data, &plato_output.length),
+ "conversion of UTF8 to UTF8");
+ torture_assert_data_blob_equal(tctx, plato_output, plato_utf8,
+ "conversion of UTF8 to UTF8");
+ torture_assert_int_equal(tctx,
+ strlen_m_ext_handle(iconv_handle,
+ (const char *)plato_utf8.data,
+ CH_UTF8, CH_UTF8),
+ plato_output.length,
+ "checking strlen_m_ext of conversion of UTF8 to UTF8");
+
+ torture_assert(tctx, convert_string_talloc_handle(tctx, iconv_handle,
CH_UTF8, CH_DOS,
plato_utf8.data, plato_utf8.length,
(void *)&plato_output.data, &plato_output.length) == false,
@@ -322,8 +376,13 @@ static bool test_plato_cp850_utf8(struct torture_context *tctx)
plato_utf16le.data, plato_utf16le.length,
(void *)&plato_output.data, &plato_output.length),
"conversion of UTF16 ancient greek to unix charset UTF8 failed");
- torture_assert_data_blob_equal(tctx, plato_output, plato_utf8, "conversion from UTF16LE to (unix charset) CP850 incorrect");
-
+ torture_assert_data_blob_equal(tctx, plato_output, plato_utf8, "conversion from UTF16LE to (unix charset) UTF8 incorrect");
+ torture_assert(tctx, convert_string_talloc_handle(tctx, iconv_handle,
+ CH_UTF16LE, CH_UTF8,
+ plato_utf16le.data, plato_utf16le.length,
+ (void *)&plato_output.data, &plato_output.length),
+ "conversion of UTF16 ancient greek to UTF8 failed");
+ torture_assert_data_blob_equal(tctx, plato_output, plato_utf8, "conversion from UTF16LE to UTF8 incorrect");
torture_assert(tctx, convert_string_talloc_handle(tctx, iconv_handle,
CH_UTF16LE, CH_DISPLAY,
plato_utf16le.data, plato_utf16le.length,
@@ -338,6 +397,26 @@ static bool test_plato_cp850_utf8(struct torture_context *tctx)
"round trip conversion of UTF16 ancient greek to display charset UTF8 and back again failed");
torture_assert_data_blob_equal(tctx, plato_output2, plato_utf16le,
"round trip conversion of UTF16 ancient greek to display charset UTF8 and back again failed");
+ torture_assert_int_equal(tctx,
+ strlen_m_ext_handle(iconv_handle,
+ (const char *)plato_output.data,
+ CH_DISPLAY, CH_UTF16LE),
+ plato_output2.length / 2,
+ "checking strlen_m_ext of round trip conversion of UTF16 latin charset greek to display charset UTF8 and back again");
+
+ torture_assert(tctx, convert_string_talloc_handle(tctx, iconv_handle,
+ CH_DISPLAY, CH_UTF8,
+ plato_output.data, plato_output.length,
+ (void *)&plato_output2.data, &plato_output2.length),
+ "conversion of display charset UTF8 to UTF8");
+ torture_assert_data_blob_equal(tctx, plato_output2, plato_utf8,
+ "conversion of display charset UTF8 to UTF8");
+ torture_assert_int_equal(tctx,
+ strlen_m_ext_handle(iconv_handle,
+ (const char *)plato_output.data,
+ CH_DISPLAY, CH_UTF8),
+ plato_output2.length,
+ "checking strlen_m_ext of conversion of display charset UTF8 to UTF8");
return true;
}
@@ -402,6 +481,12 @@ static bool test_plato_latin_cp850_utf8(struct torture_context *tctx)
"round trip conversion of UTF16 latin charset greek to display charset UTF8 and back again failed");
torture_assert_data_blob_equal(tctx, plato_latin_output2, plato_latin_utf16le,
"round trip conversion of UTF16 latin charset greek to display charset UTF8 and back again failed");
+ torture_assert_int_equal(tctx,
+ strlen_m_ext_handle(iconv_handle,
+ (const char *)plato_latin_output.data,
+ CH_DISPLAY, CH_UTF16LE),
+ plato_latin_output2.length / 2,
+ "checking strlen_m_ext of round trip conversion of UTF16 latin charset greek to display charset UTF8 and back again");
return true;
}