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

diff --git a/main.c b/main.c
index 1345e60fa4d788ab5bd1285b0e3415be3c7c80a9..9ff48eeece3de3c83f431604dc468fbd907a1978 100644 (file)
--- a/main.c
+++ b/main.c
@@ -391,6 +391,38 @@ int test_iconv_ignore_ignores_invalid() {
  * It is merely implied, but this should not be an error.
  */
 int test_iconv_untranslatable() {
+  iconv_t cd;
+  const char* fromcode = "UTF-8";
+  const char* tocode = "ASCII";
+
+  printf("%-60s", "iconv() untranslatable input is not an error...");
+  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;
 }