From: Michael Orlitzky Date: Mon, 6 Jul 2026 16:57:06 +0000 (-0400) Subject: main.c: add test_translit_does_not_fail_on_untranslatable() X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=4fe9d6b8e2bcc45cb619bef59cf7484e3fad32d8;p=iconv-quirks.git main.c: add test_translit_does_not_fail_on_untranslatable() --- diff --git a/main.c b/main.c index 21f1628..763f831 100644 --- a/main.c +++ b/main.c @@ -426,6 +426,46 @@ static int test_iconv_untranslatable() { return SUCCESS; } +/* Repeat test_iconv_untranslatable(), but with //TRANSLIT. + * The "right answer" is implementation-defined, but we should + * at least not fail. + */ +static int test_translit_does_not_fail_on_untranslatable() { + iconv_t cd; + const char* fromcode = "UTF-8"; + const char* tocode = "ASCII//TRANSLIT"; + + printf("%-60s", "iconv() with //TRANSLIT does not fail..."); + if (_my_iconv_open(&cd, tocode, fromcode) == FAILURE) { + printf("ERROR (iconv_open)\n"); + return FAILURE; + } + + size_t insize = 2, outsize = 8; + char inbuf[2] = {0xC3, 0x96}; // ü + char outbuf[8] = {0}; + char* inptr = inbuf; + char* outptr = outbuf; + + size_t result = iconv(cd, &inptr, &insize, &outptr, &outsize); + + if (result == (size_t)(-1)) { + int saved_errno = errno; // iconv_close() clobbers it + + if (_my_iconv_close(&cd) == FAILURE) { + printf("ERROR (iconv_close)\n"); + } + else { + printf("FAIL (%s)\n", ERRNO_STR(saved_errno)); + } + + return FAILURE; + } + + printf("OK (outbuf=%s)\n", outbuf); + return SUCCESS; +} + int main(int argc, char** argv) { int result = SUCCESS; @@ -465,7 +505,7 @@ int main(int argc, char** argv) { } if (translit == SUCCESS) { - //result |= test_translit_does_not_fail_on_untranslatable(); + result |= test_translit_does_not_fail_on_untranslatable(); //result |= test_translit_fails_on_incomplete_multibyte(); }