From: Timo Sirainen Date: Mon, 7 Sep 2015 21:33:21 +0000 (+0300) Subject: lib-charset: Updated test-charset unit test to check for iconv() E2BIG result X-Git-Tag: 2.2.19.rc1~75 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f9291653e3d42d630b9212ceb9290c974e51597a;p=thirdparty%2Fdovecot%2Fcore.git lib-charset: Updated test-charset unit test to check for iconv() E2BIG result --- diff --git a/src/lib-charset/test-charset.c b/src/lib-charset/test-charset.c index 6d04af73ed..ba97be51c8 100644 --- a/src/lib-charset/test-charset.c +++ b/src/lib-charset/test-charset.c @@ -25,7 +25,7 @@ static void test_charset_utf8_common(const char *input_charset) { "p\xC3\xA4\xC3", "p\xC3\xA4", CHARSET_RET_INCOMPLETE_INPUT }, { "p\xC3\xA4\xC3""a", "p\xC3\xA4"UNICODE_REPLACEMENT_CHAR_UTF8"a", CHARSET_RET_INVALID_INPUT } }; - string_t *str = t_str_new(128); + string_t *src, *str = t_str_new(256); enum charset_result result; unsigned int i; @@ -36,6 +36,18 @@ static void test_charset_utf8_common(const char *input_charset) test_assert_idx(strcmp(tests[i].output, str_c(str)) == 0, i); test_assert_idx(result == tests[i].result, i); } + /* check that E2BIG handling works. We assume that iconv() is called + with 8192 byte buffer (tmpbuf[8192]) */ + src = str_new(default_pool, 16384); + for (i = 0; i < 8190; i++) + str_append_c(src, 'a' + i % ('z'-'a'+1)); + for (i = 0; i < 256; i++) { + str_truncate(str, 0); + str_append_c(src, 'A' + i % ('Z'-'A'+1)); + test_assert_idx(charset_to_utf8_str(input_charset, NULL, + str_c(src), str, &result) == 0, i); + } + str_free(&src); } static void test_charset_utf8(void)