From: Timo Sirainen Date: Sun, 6 Dec 2015 13:10:10 +0000 (+0200) Subject: lib-charset: Added UTF-7 state checking unit test. X-Git-Tag: 2.2.20~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8a0ef83121a9ae375448efb2e1f08e136bf04e22;p=thirdparty%2Fdovecot%2Fcore.git 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. --- diff --git a/src/lib-charset/test-charset.c b/src/lib-charset/test-charset.c index b82539375f..36d214704d 100644 --- a/src/lib-charset/test-charset.c +++ b/src/lib-charset/test-charset.c @@ -130,6 +130,28 @@ static void test_charset_iconv_crashes(void) } 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 @@ int main(void) #ifdef HAVE_ICONV test_charset_iconv, test_charset_iconv_crashes, + test_charset_iconv_utf7_state, #endif NULL };