Mercurial > dovecot > core-2.2
changeset 19465:74e9e665b8f1
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.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 06 Dec 2015 15:10:10 +0200 |
parents | 81450c4bfe96 |
children | 6fda0b88e6fe |
files | src/lib-charset/test-charset.c |
diffstat | 1 files changed, 23 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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 };