diff options
author | John-Mark Bell <jmb@netsurf-browser.org> | 2013-01-13 02:05:46 +0000 |
---|---|---|
committer | John-Mark Bell <jmb@netsurf-browser.org> | 2013-01-13 02:05:46 +0000 |
commit | 9c8a4ff7e117ba052b2957c7e3f2e8751e8f8970 (patch) | |
tree | ab5e21285a92db1f77e57741c1be20b1acdbd958 /test | |
parent | 23deb46db03c3e7a2884a49edcf882d933315e70 (diff) | |
download | iconv-9c8a4ff7e117ba052b2957c7e3f2e8751e8f8970.tar.gz iconv-9c8a4ff7e117ba052b2957c7e3f2e8751e8f8970.tar.bz2 |
Transliteration fixes:
* Clear any substitution if codec reset has been requested.
* Don't report memory exhaustion when failing to allocate space
for the test conversion in translit_try_sequence: there's
nothing the caller can do, so treat it as if the substitution
cannot be converted to the target character set.
* Correctly report success if we run out of input immediately
following a flush of a substitution.
Additional tests for transliteration.
Diffstat (limited to 'test')
-rw-r--r-- | test/translit.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/translit.c b/test/translit.c index 8f17889..240f5e2 100644 --- a/test/translit.c +++ b/test/translit.c @@ -20,7 +20,15 @@ typedef struct translit_testcase { } translit_testcase; static const translit_testcase tests[] = { + /* Trivial */ { "iso-8859-1//TRANSLIT", "\xe2\x80\x93", "-" }, + /* Multi-character replacements */ + { "iso-8859-2//TRANSLIT", "\xc2\xa9", "(c)" }, + { "iso-8859-3//TRANSLIT", "\xc2\xab", "<<" }, + /* Multiple choices */ + { "iso-8859-4//TRANSLIT", "\xef\xac\x85", "st" }, + /* Default fallback */ + { "iso-8859-1//TRANSLIT", "\xef\xac\x87", "?" }, { NULL, NULL, NULL } }; @@ -53,6 +61,50 @@ static void run_tests(void) } } +static void test_translit_buffer_boundary(void) +{ + iconv_t cd; + char out[128]; + char *inp = (char *) "\xc2\xa9", *outp = out; + size_t inlen = strlen(inp), outlen; + size_t read; + + cd = iconv_open("iso-8859-2//TRANSLIT", "utf-8"); + assert(cd != (iconv_t) -1); + + outlen = 1; + read = iconv(cd, &inp, &inlen, &outp, &outlen); + assert(read == (size_t) -1); + assert(errno == E2BIG); + + /* Expect ( to appear in output */ + assert(outlen == 0); + assert(out[0] == '('); + + /* Try to write next output character */ + outlen = 1; + read = iconv(cd, &inp, &inlen, &outp, &outlen); + assert(read == (size_t) -1); + assert(errno == E2BIG); + + /* Expect "(c" in output */ + assert(outlen == 0); + assert(out[0] == '('); + assert(out[1] == 'c'); + + /* Flush through last character */ + outlen = 1; + read = iconv(cd, &inp, &inlen, &outp, &outlen); + assert(read == 0); + + /* Expect "(c)" in output, and all input read */ + assert(outlen == 0); + assert(memcmp(out, "(c)", 3) == 0); + assert(inlen == 0); + + iconv_close(cd); +} + int main(int argc, char **argv) { const char *ucpath; @@ -84,6 +136,7 @@ int main(int argc, char **argv) assert(iconv_initialise(aliases) == 1); run_tests(); + test_translit_buffer_boundary(); iconv_finalise(); |