]> gitweb.michael.orlitzky.com - iconv-quirks.git/commitdiff
main.c: add test_translit_does_not_fail_on_untranslatable()
authorMichael Orlitzky <michael@orlitzky.com>
Mon, 6 Jul 2026 16:57:06 +0000 (12:57 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Mon, 6 Jul 2026 16:57:06 +0000 (12:57 -0400)
main.c

diff --git a/main.c b/main.c
index 21f1628131f60ed0640b7998cca5bd727101fa3b..763f831ff511919e0130eb6ea07c034ad2d603e5 100644 (file)
--- 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();
   }