From dfae14dbfef4bf2dbfd149f47bdcc0c69c759e47 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Mon, 6 Jul 2026 20:59:11 -0400 Subject: [PATCH] main.c: extend test_nid_drops_untranslatable to support "//IGNORE" --- main.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/main.c b/main.c index a89191c..6fd81e3 100644 --- a/main.c +++ b/main.c @@ -435,7 +435,7 @@ static int test_translit_does_not_fail_on_untranslatable() { const char* fromcode = "UTF-8"; const char* tocode = "ASCII//TRANSLIT"; - printf("%-60s", "iconv() with //TRANSLIT does not fail..."); + printf("%-60s", "iconv() //TRANSLIT does not fail..."); if (_my_iconv_open(&cd, tocode, fromcode) == FAILURE) { printf("ERROR (iconv_open)\n"); return FAILURE; @@ -466,12 +466,27 @@ static int test_translit_does_not_fail_on_untranslatable() { return SUCCESS; } -static int test_nid_drops_untranslatable() { +/* If iconv() encounters a character in the input buffer that is + * valid, but for which an identical character does not exist in the + * output codeset [and] if either the //IGNORE or the + * //NON_IDENTICAL_DISCARD indicator suffix was specified when the + * conversion descriptor cd was opened, the character shall be + * discarded but shall still be counted in the return value of the + * iconv() call. + * + * (The above implies that this is not an error condition, since the + * return value is -1 for an error.) + */ +static int test_iconv_suffix_drops_untranslatable(char* suffix) { iconv_t cd; const char* fromcode = "UTF-8"; - const char* tocode = "ASCII//NON_IDENTICAL_DISCARD"; + char* tocode = malloc(strlen(fromcode) + strlen(suffix) + 1); + sprintf(tocode, "ASCII%s", suffix); + + char msg[59]; + snprintf(msg, 59, "iconv() %s drops untranslatable...", suffix); + printf("%-60s", msg); - printf("%-60s", "iconv() with //NON_IDENTICAL_DISCARD discards..."); if (_my_iconv_open(&cd, tocode, fromcode) == FAILURE) { printf("ERROR (iconv_open)\n"); return FAILURE; @@ -541,7 +556,7 @@ int main(int argc, char** argv) { if (ignore == SUCCESS) { result |= test_iconv_ignore_ignores_invalid(); - //result |= test_iconv_ignore_ignores_untranslatable(); + result |= test_iconv_suffix_drops_untranslatable("//IGNORE"); //result |= test_iconv_ignore_does_not_ignore_incomplete_multibyte(); } @@ -551,7 +566,7 @@ int main(int argc, char** argv) { } if (non_identical_discard == SUCCESS) { - result |= test_nid_drops_untranslatable(); + result |= test_iconv_suffix_drops_untranslatable("//NON_IDENTICAL_DISCARD"); //result |= test_nid_fails_on_incomplete_multibyte(); } -- 2.53.0