changeset 39258:2c0d93773aca

striconveha, uniconv/*: Avoid test failures on musl libc. * tests/iconvsupport.c: New file. * tests/test-striconveha.c (main): Skip autodetect_jp tests if iconv() does not support the ISO-2022-JP-2 encoding. * tests/uniconv/test-u8-conv-from-enc.c (main): Likewise. * tests/uniconv/test-u8-strconv-from-enc.c (main): Likewise. * tests/uniconv/test-u16-conv-from-enc.c (main): Likewise. * tests/uniconv/test-u16-strconv-from-enc.c (main): Likewise. * tests/uniconv/test-u32-conv-from-enc.c (main): Likewise. * tests/uniconv/test-u32-strconv-from-enc.c (main): Likewise. * modules/striconveha-tests (Files): Add tests/iconvsupport.c. (Makefile.am): Link test-striconveha with iconvsupport.o. * modules/uniconv/u8-conv-from-enc-tests (Files): Add tests/iconvsupport.c. (Makefile.am): Link test-u8-conv-from-enc with iconvsupport.o. * modules/uniconv/u8-strconv-from-enc-tests (Files): Add tests/iconvsupport.c. (Makefile.am): Link test-u8-strconv-from-enc with iconvsupport.o. * modules/uniconv/u16-conv-from-enc-tests (Files): Add tests/iconvsupport.c. (Makefile.am): Link test-u16-conv-from-enc with iconvsupport.o. * modules/uniconv/u16-strconv-from-enc-tests (Files): Add tests/iconvsupport.c. (Makefile.am): Link test-u16-strconv-from-enc with iconvsupport.o. * modules/uniconv/u32-conv-from-enc-tests (Files): Add tests/iconvsupport.c. (Makefile.am): Link test-u32-conv-from-enc with iconvsupport.o. * modules/uniconv/u32-strconv-from-enc-tests (Files): Add tests/iconvsupport.c. (Makefile.am): Link test-u32-strconv-from-enc with iconvsupport.o.
author Bruno Haible <bruno@clisp.org>
date Sat, 24 Feb 2018 15:21:11 +0100
parents e942d3d6f756
children 07d8af8dde81
files ChangeLog modules/striconveha-tests modules/uniconv/u16-conv-from-enc-tests modules/uniconv/u16-strconv-from-enc-tests modules/uniconv/u32-conv-from-enc-tests modules/uniconv/u32-strconv-from-enc-tests modules/uniconv/u8-conv-from-enc-tests modules/uniconv/u8-strconv-from-enc-tests tests/iconvsupport.c tests/test-striconveha.c tests/uniconv/test-u16-conv-from-enc.c tests/uniconv/test-u16-strconv-from-enc.c tests/uniconv/test-u32-conv-from-enc.c tests/uniconv/test-u32-strconv-from-enc.c tests/uniconv/test-u8-conv-from-enc.c tests/uniconv/test-u8-strconv-from-enc.c
diffstat 16 files changed, 553 insertions(+), 442 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Feb 24 12:59:59 2018 +0100
+++ b/ChangeLog	Sat Feb 24 15:21:11 2018 +0100
@@ -1,3 +1,36 @@
+2018-02-24  Bruno Haible  <bruno@clisp.org>
+
+	striconveha, uniconv/*: Avoid test failures on musl libc.
+	* tests/iconvsupport.c: New file.
+	* tests/test-striconveha.c (main): Skip autodetect_jp tests if iconv()
+	does not support the ISO-2022-JP-2 encoding.
+	* tests/uniconv/test-u8-conv-from-enc.c (main): Likewise.
+	* tests/uniconv/test-u8-strconv-from-enc.c (main): Likewise.
+	* tests/uniconv/test-u16-conv-from-enc.c (main): Likewise.
+	* tests/uniconv/test-u16-strconv-from-enc.c (main): Likewise.
+	* tests/uniconv/test-u32-conv-from-enc.c (main): Likewise.
+	* tests/uniconv/test-u32-strconv-from-enc.c (main): Likewise.
+	* modules/striconveha-tests (Files): Add tests/iconvsupport.c.
+	(Makefile.am): Link test-striconveha with iconvsupport.o.
+	* modules/uniconv/u8-conv-from-enc-tests (Files): Add
+	tests/iconvsupport.c.
+	(Makefile.am): Link test-u8-conv-from-enc with iconvsupport.o.
+	* modules/uniconv/u8-strconv-from-enc-tests (Files): Add
+	tests/iconvsupport.c.
+	(Makefile.am): Link test-u8-strconv-from-enc with iconvsupport.o.
+	* modules/uniconv/u16-conv-from-enc-tests (Files): Add
+	tests/iconvsupport.c.
+	(Makefile.am): Link test-u16-conv-from-enc with iconvsupport.o.
+	* modules/uniconv/u16-strconv-from-enc-tests (Files): Add
+	tests/iconvsupport.c.
+	(Makefile.am): Link test-u16-strconv-from-enc with iconvsupport.o.
+	* modules/uniconv/u32-conv-from-enc-tests (Files): Add
+	tests/iconvsupport.c.
+	(Makefile.am): Link test-u32-conv-from-enc with iconvsupport.o.
+	* modules/uniconv/u32-strconv-from-enc-tests (Files): Add
+	tests/iconvsupport.c.
+	(Makefile.am): Link test-u32-strconv-from-enc with iconvsupport.o.
+
 2018-02-24  Bruno Haible  <bruno@clisp.org>
 
 	localename: Add support for musl libc.
--- a/modules/striconveha-tests	Sat Feb 24 12:59:59 2018 +0100
+++ b/modules/striconveha-tests	Sat Feb 24 15:21:11 2018 +0100
@@ -1,5 +1,6 @@
 Files:
 tests/test-striconveha.c
+tests/iconvsupport.c
 tests/macros.h
 
 Depends-on:
@@ -9,5 +10,6 @@
 Makefile.am:
 TESTS += test-striconveha
 check_PROGRAMS += test-striconveha
+test_striconveha_SOURCES = test-striconveha.c iconvsupport.c
 test_striconveha_LDADD = $(LDADD) $(LIBUNISTRING) @LIBICONV@
 
--- a/modules/uniconv/u16-conv-from-enc-tests	Sat Feb 24 12:59:59 2018 +0100
+++ b/modules/uniconv/u16-conv-from-enc-tests	Sat Feb 24 15:21:11 2018 +0100
@@ -1,5 +1,6 @@
 Files:
 tests/uniconv/test-u16-conv-from-enc.c
+tests/iconvsupport.c
 tests/macros.h
 
 Depends-on:
@@ -10,6 +11,6 @@
 Makefile.am:
 TESTS += test-u16-conv-from-enc
 check_PROGRAMS += test-u16-conv-from-enc
-test_u16_conv_from_enc_SOURCES = uniconv/test-u16-conv-from-enc.c
+test_u16_conv_from_enc_SOURCES = uniconv/test-u16-conv-from-enc.c iconvsupport.c
 test_u16_conv_from_enc_LDADD = $(LDADD) $(LIBUNISTRING) @LIBICONV@
 
--- a/modules/uniconv/u16-strconv-from-enc-tests	Sat Feb 24 12:59:59 2018 +0100
+++ b/modules/uniconv/u16-strconv-from-enc-tests	Sat Feb 24 15:21:11 2018 +0100
@@ -1,5 +1,6 @@
 Files:
 tests/uniconv/test-u16-strconv-from-enc.c
+tests/iconvsupport.c
 tests/macros.h
 
 Depends-on:
@@ -10,6 +11,6 @@
 Makefile.am:
 TESTS += test-u16-strconv-from-enc
 check_PROGRAMS += test-u16-strconv-from-enc
-test_u16_strconv_from_enc_SOURCES = uniconv/test-u16-strconv-from-enc.c
+test_u16_strconv_from_enc_SOURCES = uniconv/test-u16-strconv-from-enc.c iconvsupport.c
 test_u16_strconv_from_enc_LDADD = $(LDADD) $(LIBUNISTRING) @LIBICONV@
 
--- a/modules/uniconv/u32-conv-from-enc-tests	Sat Feb 24 12:59:59 2018 +0100
+++ b/modules/uniconv/u32-conv-from-enc-tests	Sat Feb 24 15:21:11 2018 +0100
@@ -1,5 +1,6 @@
 Files:
 tests/uniconv/test-u32-conv-from-enc.c
+tests/iconvsupport.c
 tests/macros.h
 
 Depends-on:
@@ -10,6 +11,6 @@
 Makefile.am:
 TESTS += test-u32-conv-from-enc
 check_PROGRAMS += test-u32-conv-from-enc
-test_u32_conv_from_enc_SOURCES = uniconv/test-u32-conv-from-enc.c
+test_u32_conv_from_enc_SOURCES = uniconv/test-u32-conv-from-enc.c iconvsupport.c
 test_u32_conv_from_enc_LDADD = $(LDADD) $(LIBUNISTRING) @LIBICONV@
 
--- a/modules/uniconv/u32-strconv-from-enc-tests	Sat Feb 24 12:59:59 2018 +0100
+++ b/modules/uniconv/u32-strconv-from-enc-tests	Sat Feb 24 15:21:11 2018 +0100
@@ -1,5 +1,6 @@
 Files:
 tests/uniconv/test-u32-strconv-from-enc.c
+tests/iconvsupport.c
 tests/macros.h
 
 Depends-on:
@@ -10,6 +11,6 @@
 Makefile.am:
 TESTS += test-u32-strconv-from-enc
 check_PROGRAMS += test-u32-strconv-from-enc
-test_u32_strconv_from_enc_SOURCES = uniconv/test-u32-strconv-from-enc.c
+test_u32_strconv_from_enc_SOURCES = uniconv/test-u32-strconv-from-enc.c iconvsupport.c
 test_u32_strconv_from_enc_LDADD = $(LDADD) $(LIBUNISTRING) @LIBICONV@
 
--- a/modules/uniconv/u8-conv-from-enc-tests	Sat Feb 24 12:59:59 2018 +0100
+++ b/modules/uniconv/u8-conv-from-enc-tests	Sat Feb 24 15:21:11 2018 +0100
@@ -1,5 +1,6 @@
 Files:
 tests/uniconv/test-u8-conv-from-enc.c
+tests/iconvsupport.c
 tests/macros.h
 
 Depends-on:
@@ -11,6 +12,6 @@
 Makefile.am:
 TESTS += test-u8-conv-from-enc
 check_PROGRAMS += test-u8-conv-from-enc
-test_u8_conv_from_enc_SOURCES = uniconv/test-u8-conv-from-enc.c
+test_u8_conv_from_enc_SOURCES = uniconv/test-u8-conv-from-enc.c iconvsupport.c
 test_u8_conv_from_enc_LDADD = $(LDADD) $(LIBUNISTRING) @LIBICONV@
 
--- a/modules/uniconv/u8-strconv-from-enc-tests	Sat Feb 24 12:59:59 2018 +0100
+++ b/modules/uniconv/u8-strconv-from-enc-tests	Sat Feb 24 15:21:11 2018 +0100
@@ -1,5 +1,6 @@
 Files:
 tests/uniconv/test-u8-strconv-from-enc.c
+tests/iconvsupport.c
 tests/macros.h
 
 Depends-on:
@@ -10,6 +11,6 @@
 Makefile.am:
 TESTS += test-u8-strconv-from-enc
 check_PROGRAMS += test-u8-strconv-from-enc
-test_u8_strconv_from_enc_SOURCES = uniconv/test-u8-strconv-from-enc.c
+test_u8_strconv_from_enc_SOURCES = uniconv/test-u8-strconv-from-enc.c iconvsupport.c
 test_u8_strconv_from_enc_LDADD = $(LDADD) $(LIBUNISTRING) @LIBICONV@
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/iconvsupport.c	Sat Feb 24 15:21:11 2018 +0100
@@ -0,0 +1,39 @@
+/* Test iconv support.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+extern int iconv_supports_encoding (const char *encoding);
+
+#if HAVE_ICONV
+# include <iconv.h>
+#endif
+
+/* Tests whether iconv() supports a given encoding.  */
+int
+iconv_supports_encoding (const char *encoding)
+{
+#if HAVE_ICONV
+  iconv_t cd = iconv_open ("UTF-8", encoding);
+  if (cd != (iconv_t) -1)
+    {
+      iconv_close (cd);
+      return 1;
+    }
+#endif
+  return 0;
+}
--- a/tests/test-striconveha.c	Sat Feb 24 12:59:59 2018 +0100
+++ b/tests/test-striconveha.c	Sat Feb 24 15:21:11 2018 +0100
@@ -29,6 +29,7 @@
 #include <string.h>
 
 #include "macros.h"
+extern int iconv_supports_encoding (const char *encoding);
 
 /* Magic number for detecting bounds violations.  */
 #define MAGIC 0x1983EFF1
@@ -308,95 +309,98 @@
 
   /* autodetect_jp is only supported when iconv() support ISO-2022-JP-2.  */
 # if defined _LIBICONV_VERSION || !(defined _AIX || defined __sgi || defined __hpux || defined __osf__ || defined __sun)
-  /* Test conversions from autodetect_jp to UTF-8.  */
-  for (h = 0; h < SIZEOF (handlers); h++)
+  if (iconv_supports_encoding ("ISO-2022-JP-2"))
     {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */
-      static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
-      for (o = 0; o < 2; o++)
+      /* Test conversions from autodetect_jp to UTF-8.  */
+      for (h = 0; h < SIZEOF (handlers); h++)
         {
-          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-          char *result = NULL;
-          size_t length = 0;
-          int retval = mem_iconveha (input, strlen (input),
-                                     "autodetect_jp", "UTF-8",
-                                     false, handler,
-                                     offsets,
-                                     &result, &length);
-          ASSERT (retval == 0);
-          ASSERT (length == strlen (expected));
-          ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
-          if (o)
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */
+          static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
+          for (o = 0; o < 2; o++)
             {
-              for (i = 0; i < 10; i++)
-                ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1)));
-              ASSERT (offsets[10] == MAGIC);
-              free (offsets);
+              size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
+              char *result = NULL;
+              size_t length = 0;
+              int retval = mem_iconveha (input, strlen (input),
+                                         "autodetect_jp", "UTF-8",
+                                         false, handler,
+                                         offsets,
+                                         &result, &length);
+              ASSERT (retval == 0);
+              ASSERT (length == strlen (expected));
+              ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
+              if (o)
+                {
+                  for (i = 0; i < 10; i++)
+                    ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1)));
+                  ASSERT (offsets[10] == MAGIC);
+                  free (offsets);
+                }
+              free (result);
             }
-          free (result);
         }
-    }
-  for (h = 0; h < SIZEOF (handlers); h++)
-    {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */
-      static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
-      for (o = 0; o < 2; o++)
+      for (h = 0; h < SIZEOF (handlers); h++)
         {
-          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-          char *result = NULL;
-          size_t length = 0;
-          int retval = mem_iconveha (input, strlen (input),
-                                     "autodetect_jp", "UTF-8",
-                                     false, handler,
-                                     offsets,
-                                     &result, &length);
-          ASSERT (retval == 0);
-          ASSERT (length == strlen (expected));
-          ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
-          if (o)
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */
+          static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
+          for (o = 0; o < 2; o++)
             {
-              for (i = 0; i < 10; i++)
-                ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1)));
-              ASSERT (offsets[10] == MAGIC);
-              free (offsets);
+              size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
+              char *result = NULL;
+              size_t length = 0;
+              int retval = mem_iconveha (input, strlen (input),
+                                         "autodetect_jp", "UTF-8",
+                                         false, handler,
+                                         offsets,
+                                         &result, &length);
+              ASSERT (retval == 0);
+              ASSERT (length == strlen (expected));
+              ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
+              if (o)
+                {
+                  for (i = 0; i < 10; i++)
+                    ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1)));
+                  ASSERT (offsets[10] == MAGIC);
+                  free (offsets);
+                }
+              free (result);
             }
-          free (result);
         }
-    }
-  for (h = 0; h < SIZEOF (handlers); h++)
-    {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */
-      static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
-      for (o = 0; o < 2; o++)
+      for (h = 0; h < SIZEOF (handlers); h++)
         {
-          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-          char *result = NULL;
-          size_t length = 0;
-          int retval = mem_iconveha (input, strlen (input),
-                                     "autodetect_jp", "UTF-8",
-                                     false, handler,
-                                     offsets,
-                                     &result, &length);
-          ASSERT (retval == 0);
-          ASSERT (length == strlen (expected));
-          ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
-          if (o)
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */
+          static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
+          for (o = 0; o < 2; o++)
             {
-              for (i = 0; i < 16; i++)
-                ASSERT (offsets[i] == (i == 0 ? 0 :
-                                       i == 5 ? 3 :
-                                       i == 7 ? 6 :
-                                       i == 9 ? 9 :
-                                       i == 11 ? 12 :
-                                       i == 13 ? 15 :
-                                       (size_t)(-1)));
-              ASSERT (offsets[16] == MAGIC);
-              free (offsets);
+              size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
+              char *result = NULL;
+              size_t length = 0;
+              int retval = mem_iconveha (input, strlen (input),
+                                         "autodetect_jp", "UTF-8",
+                                         false, handler,
+                                         offsets,
+                                         &result, &length);
+              ASSERT (retval == 0);
+              ASSERT (length == strlen (expected));
+              ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
+              if (o)
+                {
+                  for (i = 0; i < 16; i++)
+                    ASSERT (offsets[i] == (i == 0 ? 0 :
+                                           i == 5 ? 3 :
+                                           i == 7 ? 6 :
+                                           i == 9 ? 9 :
+                                           i == 11 ? 12 :
+                                           i == 13 ? 15 :
+                                           (size_t)(-1)));
+                  ASSERT (offsets[16] == MAGIC);
+                  free (offsets);
+                }
+              free (result);
             }
-          free (result);
         }
     }
 # endif
@@ -544,36 +548,39 @@
 
   /* autodetect_jp is only supported when iconv() support ISO-2022-JP-2.  */
 # if defined _LIBICONV_VERSION || !(defined _AIX || defined __sgi || defined __hpux || defined __osf__ || defined __sun)
-  /* Test conversions from autodetect_jp to UTF-8.  */
-  for (h = 0; h < SIZEOF (handlers); h++)
-    {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */
-      static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
-      char *result = str_iconveha (input, "autodetect_jp", "UTF-8", false, handler);
-      ASSERT (result != NULL);
-      ASSERT (strcmp (result, expected) == 0);
-      free (result);
-    }
-  for (h = 0; h < SIZEOF (handlers); h++)
+  if (iconv_supports_encoding ("ISO-2022-JP-2"))
     {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */
-      static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
-      char *result = str_iconveha (input, "autodetect_jp", "UTF-8", false, handler);
-      ASSERT (result != NULL);
-      ASSERT (strcmp (result, expected) == 0);
-      free (result);
-    }
-  for (h = 0; h < SIZEOF (handlers); h++)
-    {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */
-      static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
-      char *result = str_iconveha (input, "autodetect_jp", "UTF-8", false, handler);
-      ASSERT (result != NULL);
-      ASSERT (strcmp (result, expected) == 0);
-      free (result);
+      /* Test conversions from autodetect_jp to UTF-8.  */
+      for (h = 0; h < SIZEOF (handlers); h++)
+        {
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */
+          static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
+          char *result = str_iconveha (input, "autodetect_jp", "UTF-8", false, handler);
+          ASSERT (result != NULL);
+          ASSERT (strcmp (result, expected) == 0);
+          free (result);
+        }
+      for (h = 0; h < SIZEOF (handlers); h++)
+        {
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */
+          static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
+          char *result = str_iconveha (input, "autodetect_jp", "UTF-8", false, handler);
+          ASSERT (result != NULL);
+          ASSERT (strcmp (result, expected) == 0);
+          free (result);
+        }
+      for (h = 0; h < SIZEOF (handlers); h++)
+        {
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */
+          static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
+          char *result = str_iconveha (input, "autodetect_jp", "UTF-8", false, handler);
+          ASSERT (result != NULL);
+          ASSERT (strcmp (result, expected) == 0);
+          free (result);
+        }
     }
 # endif
 
--- a/tests/uniconv/test-u16-conv-from-enc.c	Sat Feb 24 12:59:59 2018 +0100
+++ b/tests/uniconv/test-u16-conv-from-enc.c	Sat Feb 24 15:21:11 2018 +0100
@@ -25,6 +25,7 @@
 
 #include "unistr.h"
 #include "macros.h"
+extern int iconv_supports_encoding (const char *encoding);
 
 /* Magic number for detecting bounds violations.  */
 #define MAGIC 0x1983EFF1
@@ -117,98 +118,101 @@
 
   /* autodetect_jp is only supported when iconv() support ISO-2022-JP-2.  */
 # if defined _LIBICONV_VERSION || !(defined _AIX || defined __sgi || defined __hpux || defined __osf__ || defined __sun)
-  /* Test conversions from autodetect_jp to UTF-16.  */
-  for (h = 0; h < SIZEOF (handlers); h++)
+  if (iconv_supports_encoding ("ISO-2022-JP-2"))
     {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */
-      static const uint16_t expected[] = /* こんにちは */
-        {
-          0x3053, 0x3093, 0x306B, 0x3061, 0x306F
-        };
-      for (o = 0; o < 2; o++)
+      /* Test conversions from autodetect_jp to UTF-16.  */
+      for (h = 0; h < SIZEOF (handlers); h++)
         {
-          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-          size_t length;
-          uint16_t *result = u16_conv_from_encoding ("autodetect_jp", handler,
-                                                     input, strlen (input),
-                                                     offsets,
-                                                     NULL, &length);
-          ASSERT (result != NULL);
-          ASSERT (length == SIZEOF (expected));
-          ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0);
-          if (o)
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */
+          static const uint16_t expected[] = /* こんにちは */
+            {
+              0x3053, 0x3093, 0x306B, 0x3061, 0x306F
+            };
+          for (o = 0; o < 2; o++)
             {
-              for (i = 0; i < 10; i++)
-                ASSERT (offsets[i] == ((i % 2) == 0 ? i / 2 : (size_t)(-1)));
-              ASSERT (offsets[10] == MAGIC);
-              free (offsets);
+              size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
+              size_t length;
+              uint16_t *result = u16_conv_from_encoding ("autodetect_jp", handler,
+                                                         input, strlen (input),
+                                                         offsets,
+                                                         NULL, &length);
+              ASSERT (result != NULL);
+              ASSERT (length == SIZEOF (expected));
+              ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0);
+              if (o)
+                {
+                  for (i = 0; i < 10; i++)
+                    ASSERT (offsets[i] == ((i % 2) == 0 ? i / 2 : (size_t)(-1)));
+                  ASSERT (offsets[10] == MAGIC);
+                  free (offsets);
+                }
+              free (result);
             }
-          free (result);
         }
-    }
-  for (h = 0; h < SIZEOF (handlers); h++)
-    {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */
-      static const uint16_t expected[] = /* こんにちは */
-        {
-          0x3053, 0x3093, 0x306B, 0x3061, 0x306F
-        };
-      for (o = 0; o < 2; o++)
+      for (h = 0; h < SIZEOF (handlers); h++)
         {
-          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-          size_t length;
-          uint16_t *result = u16_conv_from_encoding ("autodetect_jp", handler,
-                                                     input, strlen (input),
-                                                     offsets,
-                                                     NULL, &length);
-          ASSERT (result != NULL);
-          ASSERT (length == SIZEOF (expected));
-          ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0);
-          if (o)
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */
+          static const uint16_t expected[] = /* こんにちは */
+            {
+              0x3053, 0x3093, 0x306B, 0x3061, 0x306F
+            };
+          for (o = 0; o < 2; o++)
             {
-              for (i = 0; i < 10; i++)
-                ASSERT (offsets[i] == ((i % 2) == 0 ? i / 2 : (size_t)(-1)));
-              ASSERT (offsets[10] == MAGIC);
-              free (offsets);
+              size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
+              size_t length;
+              uint16_t *result = u16_conv_from_encoding ("autodetect_jp", handler,
+                                                         input, strlen (input),
+                                                         offsets,
+                                                         NULL, &length);
+              ASSERT (result != NULL);
+              ASSERT (length == SIZEOF (expected));
+              ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0);
+              if (o)
+                {
+                  for (i = 0; i < 10; i++)
+                    ASSERT (offsets[i] == ((i % 2) == 0 ? i / 2 : (size_t)(-1)));
+                  ASSERT (offsets[10] == MAGIC);
+                  free (offsets);
+                }
+              free (result);
             }
-          free (result);
         }
-    }
-  for (h = 0; h < SIZEOF (handlers); h++)
-    {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */
-      static const uint16_t expected[] = /* こんにちは */
+      for (h = 0; h < SIZEOF (handlers); h++)
         {
-          0x3053, 0x3093, 0x306B, 0x3061, 0x306F
-        };
-      for (o = 0; o < 2; o++)
-        {
-          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-          size_t length;
-          uint16_t *result = u16_conv_from_encoding ("autodetect_jp", handler,
-                                                     input, strlen (input),
-                                                     offsets,
-                                                     NULL, &length);
-          ASSERT (result != NULL);
-          ASSERT (length == SIZEOF (expected));
-          ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0);
-          if (o)
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */
+          static const uint16_t expected[] = /* こんにちは */
+            {
+              0x3053, 0x3093, 0x306B, 0x3061, 0x306F
+            };
+          for (o = 0; o < 2; o++)
             {
-              for (i = 0; i < 16; i++)
-                ASSERT (offsets[i] == (i == 0 ? 0 :
-                                       i == 5 ? 1 :
-                                       i == 7 ? 2 :
-                                       i == 9 ? 3 :
-                                       i == 11 ? 4 :
-                                       i == 13 ? 5 :
-                                       (size_t)(-1)));
-              ASSERT (offsets[16] == MAGIC);
-              free (offsets);
+              size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
+              size_t length;
+              uint16_t *result = u16_conv_from_encoding ("autodetect_jp", handler,
+                                                         input, strlen (input),
+                                                         offsets,
+                                                         NULL, &length);
+              ASSERT (result != NULL);
+              ASSERT (length == SIZEOF (expected));
+              ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0);
+              if (o)
+                {
+                  for (i = 0; i < 16; i++)
+                    ASSERT (offsets[i] == (i == 0 ? 0 :
+                                           i == 5 ? 1 :
+                                           i == 7 ? 2 :
+                                           i == 9 ? 3 :
+                                           i == 11 ? 4 :
+                                           i == 13 ? 5 :
+                                           (size_t)(-1)));
+                  ASSERT (offsets[16] == MAGIC);
+                  free (offsets);
+                }
+              free (result);
             }
-          free (result);
         }
     }
 # endif
--- a/tests/uniconv/test-u16-strconv-from-enc.c	Sat Feb 24 12:59:59 2018 +0100
+++ b/tests/uniconv/test-u16-strconv-from-enc.c	Sat Feb 24 15:21:11 2018 +0100
@@ -24,6 +24,7 @@
 
 #include "unistr.h"
 #include "macros.h"
+extern int iconv_supports_encoding (const char *encoding);
 
 int
 main ()
@@ -71,45 +72,48 @@
 
   /* autodetect_jp is only supported when iconv() support ISO-2022-JP-2.  */
 # if defined _LIBICONV_VERSION || !(defined _AIX || defined __sgi || defined __hpux || defined __osf__ || defined __sun)
-  /* Test conversions from autodetect_jp to UTF-16.  */
-  for (h = 0; h < SIZEOF (handlers); h++)
+  if (iconv_supports_encoding ("ISO-2022-JP-2"))
     {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */
-      static const uint16_t expected[] = /* こんにちは */
+      /* Test conversions from autodetect_jp to UTF-16.  */
+      for (h = 0; h < SIZEOF (handlers); h++)
         {
-          0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0
-        };
-      uint16_t *result = u16_strconv_from_encoding (input, "autodetect_jp", handler);
-      ASSERT (result != NULL);
-      ASSERT (u16_strcmp (result, expected) == 0);
-      free (result);
-    }
-  for (h = 0; h < SIZEOF (handlers); h++)
-    {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */
-      static const uint16_t expected[] = /* こんにちは */
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */
+          static const uint16_t expected[] = /* こんにちは */
+            {
+              0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0
+            };
+          uint16_t *result = u16_strconv_from_encoding (input, "autodetect_jp", handler);
+          ASSERT (result != NULL);
+          ASSERT (u16_strcmp (result, expected) == 0);
+          free (result);
+        }
+      for (h = 0; h < SIZEOF (handlers); h++)
         {
-          0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0
-        };
-      uint16_t *result = u16_strconv_from_encoding (input, "autodetect_jp", handler);
-      ASSERT (result != NULL);
-      ASSERT (u16_strcmp (result, expected) == 0);
-      free (result);
-    }
-  for (h = 0; h < SIZEOF (handlers); h++)
-    {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */
-      static const uint16_t expected[] = /* こんにちは */
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */
+          static const uint16_t expected[] = /* こんにちは */
+            {
+              0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0
+            };
+          uint16_t *result = u16_strconv_from_encoding (input, "autodetect_jp", handler);
+          ASSERT (result != NULL);
+          ASSERT (u16_strcmp (result, expected) == 0);
+          free (result);
+        }
+      for (h = 0; h < SIZEOF (handlers); h++)
         {
-          0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0
-        };
-      uint16_t *result = u16_strconv_from_encoding (input, "autodetect_jp", handler);
-      ASSERT (result != NULL);
-      ASSERT (u16_strcmp (result, expected) == 0);
-      free (result);
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */
+          static const uint16_t expected[] = /* こんにちは */
+            {
+              0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0
+            };
+          uint16_t *result = u16_strconv_from_encoding (input, "autodetect_jp", handler);
+          ASSERT (result != NULL);
+          ASSERT (u16_strcmp (result, expected) == 0);
+          free (result);
+        }
     }
 # endif
 
--- a/tests/uniconv/test-u32-conv-from-enc.c	Sat Feb 24 12:59:59 2018 +0100
+++ b/tests/uniconv/test-u32-conv-from-enc.c	Sat Feb 24 15:21:11 2018 +0100
@@ -25,6 +25,7 @@
 
 #include "unistr.h"
 #include "macros.h"
+extern int iconv_supports_encoding (const char *encoding);
 
 /* Magic number for detecting bounds violations.  */
 #define MAGIC 0x1983EFF1
@@ -117,98 +118,101 @@
 
   /* autodetect_jp is only supported when iconv() support ISO-2022-JP-2.  */
 # if defined _LIBICONV_VERSION || !(defined _AIX || defined __sgi || defined __hpux || defined __osf__ || defined __sun)
-  /* Test conversions from autodetect_jp to UTF-16.  */
-  for (h = 0; h < SIZEOF (handlers); h++)
+  if (iconv_supports_encoding ("ISO-2022-JP-2"))
     {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */
-      static const uint32_t expected[] = /* こんにちは */
-        {
-          0x3053, 0x3093, 0x306B, 0x3061, 0x306F
-        };
-      for (o = 0; o < 2; o++)
+      /* Test conversions from autodetect_jp to UTF-16.  */
+      for (h = 0; h < SIZEOF (handlers); h++)
         {
-          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-          size_t length;
-          uint32_t *result = u32_conv_from_encoding ("autodetect_jp", handler,
-                                                     input, strlen (input),
-                                                     offsets,
-                                                     NULL, &length);
-          ASSERT (result != NULL);
-          ASSERT (length == SIZEOF (expected));
-          ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0);
-          if (o)
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */
+          static const uint32_t expected[] = /* こんにちは */
+            {
+              0x3053, 0x3093, 0x306B, 0x3061, 0x306F
+            };
+          for (o = 0; o < 2; o++)
             {
-              for (i = 0; i < 10; i++)
-                ASSERT (offsets[i] == ((i % 2) == 0 ? i / 2 : (size_t)(-1)));
-              ASSERT (offsets[10] == MAGIC);
-              free (offsets);
+              size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
+              size_t length;
+              uint32_t *result = u32_conv_from_encoding ("autodetect_jp", handler,
+                                                         input, strlen (input),
+                                                         offsets,
+                                                         NULL, &length);
+              ASSERT (result != NULL);
+              ASSERT (length == SIZEOF (expected));
+              ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0);
+              if (o)
+                {
+                  for (i = 0; i < 10; i++)
+                    ASSERT (offsets[i] == ((i % 2) == 0 ? i / 2 : (size_t)(-1)));
+                  ASSERT (offsets[10] == MAGIC);
+                  free (offsets);
+                }
+              free (result);
             }
-          free (result);
         }
-    }
-  for (h = 0; h < SIZEOF (handlers); h++)
-    {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */
-      static const uint32_t expected[] = /* こんにちは */
-        {
-          0x3053, 0x3093, 0x306B, 0x3061, 0x306F
-        };
-      for (o = 0; o < 2; o++)
+      for (h = 0; h < SIZEOF (handlers); h++)
         {
-          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-          size_t length;
-          uint32_t *result = u32_conv_from_encoding ("autodetect_jp", handler,
-                                                     input, strlen (input),
-                                                     offsets,
-                                                     NULL, &length);
-          ASSERT (result != NULL);
-          ASSERT (length == SIZEOF (expected));
-          ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0);
-          if (o)
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */
+          static const uint32_t expected[] = /* こんにちは */
+            {
+              0x3053, 0x3093, 0x306B, 0x3061, 0x306F
+            };
+          for (o = 0; o < 2; o++)
             {
-              for (i = 0; i < 10; i++)
-                ASSERT (offsets[i] == ((i % 2) == 0 ? i / 2 : (size_t)(-1)));
-              ASSERT (offsets[10] == MAGIC);
-              free (offsets);
+              size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
+              size_t length;
+              uint32_t *result = u32_conv_from_encoding ("autodetect_jp", handler,
+                                                         input, strlen (input),
+                                                         offsets,
+                                                         NULL, &length);
+              ASSERT (result != NULL);
+              ASSERT (length == SIZEOF (expected));
+              ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0);
+              if (o)
+                {
+                  for (i = 0; i < 10; i++)
+                    ASSERT (offsets[i] == ((i % 2) == 0 ? i / 2 : (size_t)(-1)));
+                  ASSERT (offsets[10] == MAGIC);
+                  free (offsets);
+                }
+              free (result);
             }
-          free (result);
         }
-    }
-  for (h = 0; h < SIZEOF (handlers); h++)
-    {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */
-      static const uint32_t expected[] = /* こんにちは */
+      for (h = 0; h < SIZEOF (handlers); h++)
         {
-          0x3053, 0x3093, 0x306B, 0x3061, 0x306F
-        };
-      for (o = 0; o < 2; o++)
-        {
-          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-          size_t length;
-          uint32_t *result = u32_conv_from_encoding ("autodetect_jp", handler,
-                                                     input, strlen (input),
-                                                     offsets,
-                                                     NULL, &length);
-          ASSERT (result != NULL);
-          ASSERT (length == SIZEOF (expected));
-          ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0);
-          if (o)
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */
+          static const uint32_t expected[] = /* こんにちは */
+            {
+              0x3053, 0x3093, 0x306B, 0x3061, 0x306F
+            };
+          for (o = 0; o < 2; o++)
             {
-              for (i = 0; i < 16; i++)
-                ASSERT (offsets[i] == (i == 0 ? 0 :
-                                       i == 5 ? 1 :
-                                       i == 7 ? 2 :
-                                       i == 9 ? 3 :
-                                       i == 11 ? 4 :
-                                       i == 13 ? 5 :
-                                       (size_t)(-1)));
-              ASSERT (offsets[16] == MAGIC);
-              free (offsets);
+              size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
+              size_t length;
+              uint32_t *result = u32_conv_from_encoding ("autodetect_jp", handler,
+                                                         input, strlen (input),
+                                                         offsets,
+                                                         NULL, &length);
+              ASSERT (result != NULL);
+              ASSERT (length == SIZEOF (expected));
+              ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0);
+              if (o)
+                {
+                  for (i = 0; i < 16; i++)
+                    ASSERT (offsets[i] == (i == 0 ? 0 :
+                                           i == 5 ? 1 :
+                                           i == 7 ? 2 :
+                                           i == 9 ? 3 :
+                                           i == 11 ? 4 :
+                                           i == 13 ? 5 :
+                                           (size_t)(-1)));
+                  ASSERT (offsets[16] == MAGIC);
+                  free (offsets);
+                }
+              free (result);
             }
-          free (result);
         }
     }
 # endif
--- a/tests/uniconv/test-u32-strconv-from-enc.c	Sat Feb 24 12:59:59 2018 +0100
+++ b/tests/uniconv/test-u32-strconv-from-enc.c	Sat Feb 24 15:21:11 2018 +0100
@@ -24,6 +24,7 @@
 
 #include "unistr.h"
 #include "macros.h"
+extern int iconv_supports_encoding (const char *encoding);
 
 int
 main ()
@@ -71,45 +72,48 @@
 
   /* autodetect_jp is only supported when iconv() support ISO-2022-JP-2.  */
 # if defined _LIBICONV_VERSION || !(defined _AIX || defined __sgi || defined __hpux || defined __osf__ || defined __sun)
-  /* Test conversions from autodetect_jp to UTF-16.  */
-  for (h = 0; h < SIZEOF (handlers); h++)
+  if (iconv_supports_encoding ("ISO-2022-JP-2"))
     {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */
-      static const uint32_t expected[] = /* こんにちは */
+      /* Test conversions from autodetect_jp to UTF-16.  */
+      for (h = 0; h < SIZEOF (handlers); h++)
         {
-          0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0
-        };
-      uint32_t *result = u32_strconv_from_encoding (input, "autodetect_jp", handler);
-      ASSERT (result != NULL);
-      ASSERT (u32_strcmp (result, expected) == 0);
-      free (result);
-    }
-  for (h = 0; h < SIZEOF (handlers); h++)
-    {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */
-      static const uint32_t expected[] = /* こんにちは */
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */
+          static const uint32_t expected[] = /* こんにちは */
+            {
+              0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0
+            };
+          uint32_t *result = u32_strconv_from_encoding (input, "autodetect_jp", handler);
+          ASSERT (result != NULL);
+          ASSERT (u32_strcmp (result, expected) == 0);
+          free (result);
+        }
+      for (h = 0; h < SIZEOF (handlers); h++)
         {
-          0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0
-        };
-      uint32_t *result = u32_strconv_from_encoding (input, "autodetect_jp", handler);
-      ASSERT (result != NULL);
-      ASSERT (u32_strcmp (result, expected) == 0);
-      free (result);
-    }
-  for (h = 0; h < SIZEOF (handlers); h++)
-    {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */
-      static const uint32_t expected[] = /* こんにちは */
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */
+          static const uint32_t expected[] = /* こんにちは */
+            {
+              0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0
+            };
+          uint32_t *result = u32_strconv_from_encoding (input, "autodetect_jp", handler);
+          ASSERT (result != NULL);
+          ASSERT (u32_strcmp (result, expected) == 0);
+          free (result);
+        }
+      for (h = 0; h < SIZEOF (handlers); h++)
         {
-          0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0
-        };
-      uint32_t *result = u32_strconv_from_encoding (input, "autodetect_jp", handler);
-      ASSERT (result != NULL);
-      ASSERT (u32_strcmp (result, expected) == 0);
-      free (result);
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */
+          static const uint32_t expected[] = /* こんにちは */
+            {
+              0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0
+            };
+          uint32_t *result = u32_strconv_from_encoding (input, "autodetect_jp", handler);
+          ASSERT (result != NULL);
+          ASSERT (u32_strcmp (result, expected) == 0);
+          free (result);
+        }
     }
 # endif
 
--- a/tests/uniconv/test-u8-conv-from-enc.c	Sat Feb 24 12:59:59 2018 +0100
+++ b/tests/uniconv/test-u8-conv-from-enc.c	Sat Feb 24 15:21:11 2018 +0100
@@ -25,6 +25,7 @@
 
 #include "unistr.h"
 #include "macros.h"
+extern int iconv_supports_encoding (const char *encoding);
 
 /* Magic number for detecting bounds violations.  */
 #define MAGIC 0x1983EFF1
@@ -112,89 +113,92 @@
 
   /* autodetect_jp is only supported when iconv() support ISO-2022-JP-2.  */
 # if defined _LIBICONV_VERSION || !(defined _AIX || defined __sgi || defined __hpux || defined __osf__ || defined __sun)
-  /* Test conversions from autodetect_jp to UTF-8.  */
-  for (h = 0; h < SIZEOF (handlers); h++)
+  if (iconv_supports_encoding ("ISO-2022-JP-2"))
     {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */
-      static const uint8_t expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
-      for (o = 0; o < 2; o++)
+      /* Test conversions from autodetect_jp to UTF-8.  */
+      for (h = 0; h < SIZEOF (handlers); h++)
         {
-          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-          size_t length;
-          uint8_t *result = u8_conv_from_encoding ("autodetect_jp", handler,
-                                                   input, strlen (input),
-                                                   offsets,
-                                                   NULL, &length);
-          ASSERT (result != NULL);
-          ASSERT (length == u8_strlen (expected));
-          ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0);
-          if (o)
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */
+          static const uint8_t expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
+          for (o = 0; o < 2; o++)
             {
-              for (i = 0; i < 10; i++)
-                ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1)));
-              ASSERT (offsets[10] == MAGIC);
-              free (offsets);
+              size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
+              size_t length;
+              uint8_t *result = u8_conv_from_encoding ("autodetect_jp", handler,
+                                                       input, strlen (input),
+                                                       offsets,
+                                                       NULL, &length);
+              ASSERT (result != NULL);
+              ASSERT (length == u8_strlen (expected));
+              ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0);
+              if (o)
+                {
+                  for (i = 0; i < 10; i++)
+                    ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1)));
+                  ASSERT (offsets[10] == MAGIC);
+                  free (offsets);
+                }
+              free (result);
             }
-          free (result);
         }
-    }
-  for (h = 0; h < SIZEOF (handlers); h++)
-    {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */
-      static const uint8_t expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
-      for (o = 0; o < 2; o++)
+      for (h = 0; h < SIZEOF (handlers); h++)
         {
-          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-          size_t length;
-          uint8_t *result = u8_conv_from_encoding ("autodetect_jp", handler,
-                                                   input, strlen (input),
-                                                   offsets,
-                                                   NULL, &length);
-          ASSERT (result != NULL);
-          ASSERT (length == u8_strlen (expected));
-          ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0);
-          if (o)
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */
+          static const uint8_t expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
+          for (o = 0; o < 2; o++)
             {
-              for (i = 0; i < 10; i++)
-                ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1)));
-              ASSERT (offsets[10] == MAGIC);
-              free (offsets);
+              size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
+              size_t length;
+              uint8_t *result = u8_conv_from_encoding ("autodetect_jp", handler,
+                                                       input, strlen (input),
+                                                       offsets,
+                                                       NULL, &length);
+              ASSERT (result != NULL);
+              ASSERT (length == u8_strlen (expected));
+              ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0);
+              if (o)
+                {
+                  for (i = 0; i < 10; i++)
+                    ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1)));
+                  ASSERT (offsets[10] == MAGIC);
+                  free (offsets);
+                }
+              free (result);
             }
-          free (result);
         }
-    }
-  for (h = 0; h < SIZEOF (handlers); h++)
-    {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */
-      static const uint8_t expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
-      for (o = 0; o < 2; o++)
+      for (h = 0; h < SIZEOF (handlers); h++)
         {
-          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-          size_t length;
-          uint8_t *result = u8_conv_from_encoding ("autodetect_jp", handler,
-                                                   input, strlen (input),
-                                                   offsets,
-                                                   NULL, &length);
-          ASSERT (result != NULL);
-          ASSERT (length == u8_strlen (expected));
-          ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0);
-          if (o)
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */
+          static const uint8_t expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
+          for (o = 0; o < 2; o++)
             {
-              for (i = 0; i < 16; i++)
-                ASSERT (offsets[i] == (i == 0 ? 0 :
-                                       i == 5 ? 3 :
-                                       i == 7 ? 6 :
-                                       i == 9 ? 9 :
-                                       i == 11 ? 12 :
-                                       i == 13 ? 15 :
-                                       (size_t)(-1)));
-              ASSERT (offsets[16] == MAGIC);
-              free (offsets);
+              size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
+              size_t length;
+              uint8_t *result = u8_conv_from_encoding ("autodetect_jp", handler,
+                                                       input, strlen (input),
+                                                       offsets,
+                                                       NULL, &length);
+              ASSERT (result != NULL);
+              ASSERT (length == u8_strlen (expected));
+              ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0);
+              if (o)
+                {
+                  for (i = 0; i < 16; i++)
+                    ASSERT (offsets[i] == (i == 0 ? 0 :
+                                           i == 5 ? 3 :
+                                           i == 7 ? 6 :
+                                           i == 9 ? 9 :
+                                           i == 11 ? 12 :
+                                           i == 13 ? 15 :
+                                           (size_t)(-1)));
+                  ASSERT (offsets[16] == MAGIC);
+                  free (offsets);
+                }
+              free (result);
             }
-          free (result);
         }
     }
 # endif
--- a/tests/uniconv/test-u8-strconv-from-enc.c	Sat Feb 24 12:59:59 2018 +0100
+++ b/tests/uniconv/test-u8-strconv-from-enc.c	Sat Feb 24 15:21:11 2018 +0100
@@ -24,6 +24,7 @@
 
 #include "unistr.h"
 #include "macros.h"
+extern int iconv_supports_encoding (const char *encoding);
 
 int
 main ()
@@ -62,36 +63,39 @@
 
   /* autodetect_jp is only supported when iconv() support ISO-2022-JP-2.  */
 # if defined _LIBICONV_VERSION || !(defined _AIX || defined __sgi || defined __hpux || defined __osf__ || defined __sun)
-  /* Test conversions from autodetect_jp to UTF-8.  */
-  for (h = 0; h < SIZEOF (handlers); h++)
-    {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */
-      static const uint8_t expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
-      uint8_t *result = u8_strconv_from_encoding (input, "autodetect_jp", handler);
-      ASSERT (result != NULL);
-      ASSERT (u8_strcmp (result, expected) == 0);
-      free (result);
-    }
-  for (h = 0; h < SIZEOF (handlers); h++)
+  if (iconv_supports_encoding ("ISO-2022-JP-2"))
     {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */
-      static const uint8_t expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
-      uint8_t *result = u8_strconv_from_encoding (input, "autodetect_jp", handler);
-      ASSERT (result != NULL);
-      ASSERT (u8_strcmp (result, expected) == 0);
-      free (result);
-    }
-  for (h = 0; h < SIZEOF (handlers); h++)
-    {
-      enum iconv_ilseq_handler handler = handlers[h];
-      static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */
-      static const uint8_t expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
-      uint8_t *result = u8_strconv_from_encoding (input, "autodetect_jp", handler);
-      ASSERT (result != NULL);
-      ASSERT (u8_strcmp (result, expected) == 0);
-      free (result);
+      /* Test conversions from autodetect_jp to UTF-8.  */
+      for (h = 0; h < SIZEOF (handlers); h++)
+        {
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */
+          static const uint8_t expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
+          uint8_t *result = u8_strconv_from_encoding (input, "autodetect_jp", handler);
+          ASSERT (result != NULL);
+          ASSERT (u8_strcmp (result, expected) == 0);
+          free (result);
+        }
+      for (h = 0; h < SIZEOF (handlers); h++)
+        {
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */
+          static const uint8_t expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
+          uint8_t *result = u8_strconv_from_encoding (input, "autodetect_jp", handler);
+          ASSERT (result != NULL);
+          ASSERT (u8_strcmp (result, expected) == 0);
+          free (result);
+        }
+      for (h = 0; h < SIZEOF (handlers); h++)
+        {
+          enum iconv_ilseq_handler handler = handlers[h];
+          static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */
+          static const uint8_t expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */
+          uint8_t *result = u8_strconv_from_encoding (input, "autodetect_jp", handler);
+          ASSERT (result != NULL);
+          ASSERT (u8_strcmp (result, expected) == 0);
+          free (result);
+        }
     }
 # endif