dovecot-2.2: lib-charset: Run iconv unit tests by giving iconv()...

dovecot at dovecot.org dovecot at dovecot.org
Mon Oct 19 21:24:20 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/5bba7529d5d7
changeset: 19314:5bba7529d5d7
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Oct 20 00:23:56 2015 +0300
description:
lib-charset: Run iconv unit tests by giving iconv() new data 1 byte at a time.

diffstat:

 src/lib-charset/test-charset.c |  17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diffs (35 lines):

diff -r 56d08de919a1 -r 5bba7529d5d7 src/lib-charset/test-charset.c
--- a/src/lib-charset/test-charset.c	Mon Oct 19 14:29:10 2015 +0300
+++ b/src/lib-charset/test-charset.c	Tue Oct 20 00:23:56 2015 +0300
@@ -69,7 +69,9 @@
 		{ "ISO-8859-1", "p\xE4\xE4", "pää", CHARSET_RET_OK }
 	};
 	string_t *str = t_str_new(128);
+	struct charset_translation *trans;
 	enum charset_result result;
+	size_t pos, left, limit, len;
 	unsigned int i;
 
 	test_begin("charset iconv");
@@ -79,6 +81,21 @@
 						    tests[i].input, str, &result) == 0, i);
 		test_assert_idx(strcmp(tests[i].output, str_c(str)) == 0, i);
 		test_assert_idx(result == tests[i].result, i);
+
+		str_truncate(str, 0);
+		test_assert_idx(charset_to_utf8_begin(tests[i].charset, NULL, &trans) == 0, i);
+		len = strlen(tests[i].input);
+		for (pos = 0, limit = 1; limit <= len; pos += left, limit++) {
+			left = limit - pos;
+			result = charset_to_utf8(trans, (const void *)(tests[i].input + pos),
+						 &left, str);
+			if (result != CHARSET_RET_INCOMPLETE_INPUT &&
+			    result != CHARSET_RET_OK)
+				break;
+		}
+		test_assert_idx(strcmp(tests[i].output, str_c(str)) == 0, i);
+		test_assert_idx(result == tests[i].result, i);
+		charset_to_utf8_end(&trans);
 	}
 	/* Use //IGNORE just to force handling to be done by iconv
 	   instead of our own UTF-8 routines. */


More information about the dovecot-cvs mailing list