Mercurial > dovecot > core-2.2
changeset 18784:3468de815591
lib: test-unichar - test invalid utf8 encodings
Chop trailing characters off valid encodings, and watch them fail.
(There's no need to do this on most of the test characters, as they're
truncated to the same byte sequence - only do 1 in 64.)
Signed-off-by: Phil Carmody <phil@dovecot.fi>
author | Phil Carmody <phil@dovecot.fi> |
---|---|
date | Mon, 01 Jun 2015 22:07:44 +0300 |
parents | aa2f464daa66 |
children | 7bd2f9be5493 |
files | src/lib/test-unichar.c |
diffstat | 1 files changed, 17 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/test-unichar.c Mon Jun 01 22:06:44 2015 +0300 +++ b/src/lib/test-unichar.c Mon Jun 01 22:07:44 2015 +0300 @@ -60,6 +60,23 @@ test_assert(uni_utf8_str_is_valid(str_c(str))); test_assert(uni_utf8_get_char(str_c(str), &chr2) > 0); test_assert(chr2 == chr); + + if ((chr & 0x63) == 0) { + unsigned int utf8len = uni_utf8_char_bytes(*str_c(str)); + + /* virtually truncate the byte string */ + while (--utf8len > 0) + test_assert(uni_utf8_get_char_n(str_c(str), utf8len, &chr2) == 0); + + utf8len = uni_utf8_char_bytes(*str_c(str)); + + /* actually truncate the byte stream */ + while (--utf8len > 0) { + str_truncate(str, utf8len); + test_assert(!uni_utf8_str_is_valid(str_c(str))); + test_assert(uni_utf8_get_char(str_c(str), &chr2) == 0); + } + } } test_end();