]> gitweb.michael.orlitzky.com - iconv-quirks.git/commitdiff
main.c: extend test_nid_drops_untranslatable to support "//IGNORE"
authorMichael Orlitzky <michael@orlitzky.com>
Tue, 7 Jul 2026 00:59:11 +0000 (20:59 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Tue, 7 Jul 2026 01:00:10 +0000 (21:00 -0400)
main.c

diff --git a/main.c b/main.c
index a89191cccbda01f7bcb65b409297a9d0a5e343e5..6fd81e31041d385051bf068e36eb4e64f2e478b4 100644 (file)
--- 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();
   }