Mercurial > dovecot > core-2.2
changeset 19314:5bba7529d5d7
lib-charset: Run iconv unit tests by giving iconv() new data 1 byte at a time.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 20 Oct 2015 00:23:56 +0300 |
parents | 56d08de919a1 |
children | 0f5e58361c48 |
files | src/lib-charset/test-charset.c |
diffstat | 1 files changed, 17 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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. */