summaryrefslogtreecommitdiff
path: root/lib/util/charset/tests/iconv.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2008-10-31 15:41:34 +1100
committerAndrew Tridgell <tridge@samba.org>2008-10-31 15:41:34 +1100
commit55d55d9d9b881b2ec09fa76515cdd1cf6f0e2442 (patch)
treeb676358946045bc2271c1c75254ecaac21eb72b9 /lib/util/charset/tests/iconv.c
parent5ecccac1c34f58019b195f6838f57366faa3575d (diff)
downloadsamba-55d55d9d9b881b2ec09fa76515cdd1cf6f0e2442.tar.gz
samba-55d55d9d9b881b2ec09fa76515cdd1cf6f0e2442.tar.bz2
samba-55d55d9d9b881b2ec09fa76515cdd1cf6f0e2442.zip
finished adding UTF16_MUNGED charset
Changed the approach for the charset to go via utf16, which makes a bit more sense to read. Added a testsuiite for UTF16_MUNGED as part of LOCAL-ICONV
Diffstat (limited to 'lib/util/charset/tests/iconv.c')
-rw-r--r--lib/util/charset/tests/iconv.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/util/charset/tests/iconv.c b/lib/util/charset/tests/iconv.c
index 40e223b28f..1facea6136 100644
--- a/lib/util/charset/tests/iconv.c
+++ b/lib/util/charset/tests/iconv.c
@@ -398,10 +398,65 @@ static bool test_random_5m(struct torture_context *tctx)
return true;
}
+
+static bool test_string2key(struct torture_context *tctx)
+{
+ uint16_t *buf;
+ char *dest = NULL;
+ TALLOC_CTX *mem_ctx = talloc_new(tctx);
+ ssize_t ret;
+ size_t len = (random()%1000)+1;
+ const uint16_t in1[10] = { 'a', 0xd805, 'b', 0xdcf0, 'c', 0, 'd', 'e', 'f', 'g' };
+ uint8_t le1[20];
+ uint8_t *munged1;
+ uint8_t *out1;
+ int i;
+ const char *correct = "a\357\277\275b\357\277\275c\001defg";
+
+ buf = talloc_size(mem_ctx, len*2);
+ generate_random_buffer((uint8_t *)buf, len*2);
+
+ torture_comment(tctx, "converting random buffer\n");
+
+ ret = convert_string_talloc(mem_ctx, CH_UTF16MUNGED, CH_UTF8, (void *)buf, len*2, (void**)&dest);
+ if (ret == -1) {
+ torture_fail(tctx, "Failed to convert random buffer\n");
+ }
+
+ for (i=0;i<10;i++) {
+ SSVAL(&le1[2*i], 0, in1[i]);
+ }
+
+ torture_comment(tctx, "converting fixed buffer to UTF16\n");
+
+ ret = convert_string_talloc(mem_ctx, CH_UTF16MUNGED, CH_UTF16, (void *)le1, 20, (void**)&munged1);
+ if (ret == -1) {
+ torture_fail(tctx, "Failed to convert fixed buffer to UTF16_MUNGED\n");
+ }
+
+ torture_assert(tctx, ret == 20, "conversion should give 20 bytes\n");
+
+ torture_comment(tctx, "converting fixed buffer to UTF8\n");
+
+ ret = convert_string_talloc(mem_ctx, CH_UTF16MUNGED, CH_UTF8, (void *)le1, 20, (void**)&out1);
+ if (ret == -1) {
+ torture_fail(tctx, "Failed to convert fixed buffer to UTF8\n");
+ }
+
+ torture_assert(tctx, strcmp(correct, out1) == 0, "conversion gave incorrect result\n");
+
+ talloc_free(mem_ctx);
+
+ return true;
+}
+
struct torture_suite *torture_local_iconv(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite = torture_suite_create(mem_ctx, "ICONV");
+ torture_suite_add_simple_test(suite, "string2key",
+ test_string2key);
+
torture_suite_add_simple_test(suite, "next_codepoint()",
test_next_codepoint);
@@ -410,6 +465,9 @@ struct torture_suite *torture_local_iconv(TALLOC_CTX *mem_ctx)
torture_suite_add_simple_test(suite, "5M random UTF-16LE sequences",
test_random_5m);
+
+ torture_suite_add_simple_test(suite, "string2key",
+ test_string2key);
return suite;
}