#!/bin/sh # Check of --unicode-subst, --byte-subst, --widechar-subst options. set -e iconv=$bindir/iconv is_native=$bindir/is-native options_ascii='--unicode-subst= --byte-subst=<0x%02x> --widechar-subst=<%08x>' options_utf8='--unicode-subst=«U+%04X» --byte-subst=«0x%02x» --widechar-subst=«%08x»' # Test of --byte-subst with an ASCII substitution. cat > tmp-in <<\EOF Böse Bübchen EOF $iconv $options_ascii -f ASCII -t ASCII < tmp-in > tmp-out cat > tmp-ok <<\EOF B<0xc3><0xb6>se B<0xc3><0xbc>bchen EOF cmp -s tmp-out tmp-ok rc1=$? # Test of --byte-subst with a non-ASCII substitution. if $is_native && test "`(locale charmap) 2>/dev/null`" = UTF-8; then cat > tmp-in <<\EOF Böse Bübchen EOF $iconv $options_utf8 -f ASCII -t UTF-8 2>/dev/null < tmp-in > tmp-out cat > tmp-ok <<\EOF B«0xc3»«0xb6»se B«0xc3»«0xbc»bchen EOF cmp -s tmp-out tmp-ok rc2=$? else rc2=0 fi if $is_native && test "`(locale charmap) 2>/dev/null`" = UTF-8; then cat > tmp-in <<\EOF Böse Bübchen EOF $iconv $options_utf8 -f ASCII -t ISO-8859-1 2>/dev/null < tmp-in > tmp-out $iconv -f ISO-8859-1 -t UTF-8 < tmp-out > tmp-out2 cat > tmp-ok <<\EOF B«0xc3»«0xb6»se B«0xc3»«0xbc»bchen EOF cmp -s tmp-out2 tmp-ok rc3=$? else rc3=0 fi # Test of --byte-subst with a very long substitution. cat > tmp-in <<\EOF Böse Bübchen EOF $iconv --byte-subst='<0x%010000x>' -f ASCII -t ASCII < tmp-in > tmp-out # This printf command crashes on Solaris 10. # See . # Likewise on OSF/1 5.1. if printf 'B<0x%010000x><0x%010000x>se B<0x%010000x><0x%010000x>bchen\n' 0xC3 0xB6 0xC3 0xBC > tmp-ok 2>/dev/null; then cmp -s tmp-out tmp-ok rc4=$? else rc4=0 fi # Test of --unicode-subst with an ASCII substitution. cat > tmp-in <<\EOF Böse Bübchen EOF $iconv $options_ascii -f UTF-8 -t ASCII < tmp-in > tmp-out cat > tmp-ok <<\EOF Bse Bbchen EOF cmp -s tmp-out tmp-ok rc5=$? cat > tmp-in <<\EOF Russian (Русский) EOF $iconv $options_ascii -f UTF-8 -t ISO-8859-1 2>/dev/null < tmp-in | $iconv -f ISO-8859-1 -t UTF-8 > tmp-out cat > tmp-ok <<\EOF Russian () EOF cmp -s tmp-out tmp-ok rc6=$? # Test of --unicode-subst with a non-ASCII substitution. if $is_native && test "`(locale charmap) 2>/dev/null`" = UTF-8; then cat > tmp-in <<\EOF Russian (Русский) EOF $iconv $options_utf8 -f UTF-8 -t ISO-8859-1 2>/dev/null < tmp-in > tmp-out $iconv -f ISO-8859-1 -t UTF-8 < tmp-out > tmp-out2 cat > tmp-ok <<\EOF Russian («U+0420»«U+0443»«U+0441»«U+0441»«U+043A»«U+0438»«U+0439») EOF cmp -s tmp-out2 tmp-ok rc7=$? else rc7=0 fi # Test of --unicode-subst with a very long substitution. cat > tmp-in <<\EOF Böse Bübchen EOF $iconv --unicode-subst='' -f UTF-8 -t ASCII < tmp-in > tmp-out # This printf command crashes on Solaris 10. # See . if printf 'Bse Bbchen\n' 0x00F6 0x00FC > tmp-ok 2>/dev/null; then cmp -s tmp-out tmp-ok rc8=$? else rc8=0 fi cat > tmp-in <<\EOF Böse Bübchen EOF $iconv --byte-subst='<0x%010000x>' -f ASCII -t ASCII < tmp-in > tmp-out # This printf command crashes on Solaris 10. # See . # Likewise on OSF/1 5.1. if printf 'B<0x%010000x><0x%010000x>se B<0x%010000x><0x%010000x>bchen\n' 0xC3 0xB6 0xC3 0xBC > tmp-ok 2>/dev/null; then cmp -s tmp-out tmp-ok rc9=$? else rc9=0 fi # Test of --widechar-subst: # wcrtomb() doesn't exist on FreeBSD 4.0 and is broken on MacOS X 10.3. # So far this has been tested only on a glibc system with !__STDC_ISO_10646__. rc10=0 rc11=0 rc12=0 if false && $is_native && test "`(locale charmap) 2>/dev/null`" = UTF-8; then cat > tmp-in <<\EOF Russian (Русский) EOF $iconv -f char -t wchar_t < tmp-in > tmp-inw LC_ALL=C $iconv $options_ascii -f wchar_t -t ASCII < tmp-inw > tmp-out1 LC_ALL=de_DE.ISO-8859-1 $iconv $options_ascii -f wchar_t -t ASCII < tmp-inw > tmp-out2 cat > tmp-ok <<\EOF Russian (<00000420><00000443><00000441><00000441><0000043a><00000438><00000439>) EOF cmp -s tmp-out1 tmp-ok rc10=$? cmp -s tmp-out2 tmp-ok rc11=$? if $is_native && test "`(LC_ALL=de_DE.ISO-8859-1 locale charmap) 2>/dev/null`" = ISO-8859-1; then options_latin1=`echo " $options_utf8" | $iconv -f UTF-8 -t ISO-8859-1` LC_ALL=de_DE.ISO-8859-1 $iconv $options_latin1 -f wchar_t -t UTF-8 < tmp-inw > tmp-out1 cat > tmp-ok <<\EOF Russian («00000420»«00000443»«00000441»«00000441»«0000043a»«00000438»«00000439») EOF cmp -s tmp-out1 tmp-ok rc12=$? fi fi rm -f tmp-in* tmp-out* tmp-ok [ $rc1 -ne 0 ] && exit $rc1 [ $rc2 -ne 0 ] && exit $rc2 [ $rc3 -ne 0 ] && exit $rc3 [ $rc4 -ne 0 ] && exit $rc4 [ $rc5 -ne 0 ] && exit $rc5 [ $rc6 -ne 0 ] && exit $rc6 [ $rc7 -ne 0 ] && exit $rc7 [ $rc8 -ne 0 ] && exit $rc8 [ $rc9 -ne 0 ] && exit $rc9 [ $rc10 -ne 0 ] && exit $rc10 [ $rc11 -ne 0 ] && exit $rc11 [ $rc12 -ne 0 ] && exit $rc12 exit 0