dovecot-2.2: lib-charset: Added UTF-7 state checking unit test.

dovecot at dovecot.org dovecot at dovecot.org
Sun Dec 6 13:10:28 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/74e9e665b8f1
changeset: 19465:74e9e665b8f1
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Dec 06 15:10:10 2015 +0200
description:
lib-charset: Added UTF-7 state checking unit test.
This was an idea of a way to test for a bug in FreeBSD iconv(), but nobody
reported if it did anything. So lets add it here and see.

diffstat:

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

diffs (40 lines):

diff -r 81450c4bfe96 -r 74e9e665b8f1 src/lib-charset/test-charset.c
--- a/src/lib-charset/test-charset.c	Sun Dec 06 14:57:22 2015 +0200
+++ b/src/lib-charset/test-charset.c	Sun Dec 06 15:10:10 2015 +0200
@@ -130,6 +130,28 @@
 	}
 	test_end();
 }
+
+static void test_charset_iconv_utf7_state(void)
+{
+	struct charset_translation *trans;
+	string_t *str = t_str_new(32);
+	unsigned char nextbuf[5+CHARSET_MAX_PENDING_BUF_SIZE+1];
+	size_t size;
+
+	test_begin("charset iconv utf7 state");
+	test_assert(charset_to_utf8_begin("UTF-7", NULL, &trans) == 0);
+	size = 2;
+	test_assert(charset_to_utf8(trans, (const void *)"a+", &size, str) == CHARSET_RET_INCOMPLETE_INPUT);
+	test_assert(strcmp(str_c(str), "a") == 0);
+	test_assert(size == 1);
+	memset(nextbuf, '?', sizeof(nextbuf));
+	memcpy(nextbuf, "+AOQ-", 5);
+	size = sizeof(nextbuf);
+	test_assert(charset_to_utf8(trans, nextbuf, &size, str) == CHARSET_RET_OK);
+	test_assert(strcmp(str_c(str), "a\xC3\xA4???????????") == 0);
+	charset_to_utf8_end(&trans);
+	test_end();
+}
 #endif
 
 int main(void)
@@ -140,6 +162,7 @@
 #ifdef HAVE_ICONV
 		test_charset_iconv,
 		test_charset_iconv_crashes,
+		test_charset_iconv_utf7_state,
 #endif
 		NULL
 	};


More information about the dovecot-cvs mailing list