Annotation of embedaddon/libiconv/tests/check-subst, revision 1.1
1.1 ! misho 1: #!/bin/sh
! 2: # Check of --unicode-subst, --byte-subst, --widechar-subst options.
! 3: set -e
! 4: iconv=../src/iconv_no_i18n
! 5: # Make sure the charset.alias file is found.
! 6: CHARSETALIASDIR=../lib
! 7: export CHARSETALIASDIR
! 8:
! 9: options_ascii='--unicode-subst=<U+%04X> --byte-subst=<0x%02x> --widechar-subst=<%08x>'
! 10: options_utf8='--unicode-subst=«U+%04X» --byte-subst=«0x%02x» --widechar-subst=«%08x»'
! 11:
! 12: # Test of --byte-subst with an ASCII substitution.
! 13:
! 14: cat > tmp-in <<\EOF
! 15: Böse Bübchen
! 16: EOF
! 17: $iconv $options_ascii -f ASCII -t ASCII < tmp-in > tmp-out
! 18: cat > tmp-ok <<\EOF
! 19: B<0xc3><0xb6>se B<0xc3><0xbc>bchen
! 20: EOF
! 21: cmp tmp-out tmp-ok
! 22:
! 23: # Test of --byte-subst with a non-ASCII substitution.
! 24:
! 25: if test "`(locale charmap) 2>/dev/null`" = UTF-8; then
! 26: cat > tmp-in <<\EOF
! 27: Böse Bübchen
! 28: EOF
! 29: $iconv $options_utf8 -f ASCII -t UTF-8 2>/dev/null < tmp-in > tmp-out
! 30: cat > tmp-ok <<\EOF
! 31: B«0xc3»«0xb6»se B«0xc3»«0xbc»bchen
! 32: EOF
! 33: cmp tmp-out tmp-ok
! 34: fi
! 35:
! 36: if test "`(locale charmap) 2>/dev/null`" = UTF-8; then
! 37: cat > tmp-in <<\EOF
! 38: Böse Bübchen
! 39: EOF
! 40: $iconv $options_utf8 -f ASCII -t ISO-8859-1 2>/dev/null < tmp-in > tmp-out
! 41: $iconv -f ISO-8859-1 -t UTF-8 < tmp-out > tmp-out2
! 42: cat > tmp-ok <<\EOF
! 43: B«0xc3»«0xb6»se B«0xc3»«0xbc»bchen
! 44: EOF
! 45: cmp tmp-out2 tmp-ok
! 46: fi
! 47:
! 48: # Test of --byte-subst with a very long substitution.
! 49:
! 50: cat > tmp-in <<\EOF
! 51: Böse Bübchen
! 52: EOF
! 53: $iconv --byte-subst='<0x%010000x>' -f ASCII -t ASCII < tmp-in > tmp-out
! 54: # This printf command crashes on Solaris 10.
! 55: 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
! 56: cmp tmp-out tmp-ok
! 57: fi
! 58:
! 59: # Test of --unicode-subst with an ASCII substitution.
! 60:
! 61: cat > tmp-in <<\EOF
! 62: Böse Bübchen
! 63: EOF
! 64: $iconv $options_ascii -f UTF-8 -t ASCII < tmp-in > tmp-out
! 65: cat > tmp-ok <<\EOF
! 66: B<U+00F6>se B<U+00FC>bchen
! 67: EOF
! 68: cmp tmp-out tmp-ok
! 69:
! 70: cat > tmp-in <<\EOF
! 71: Russian (Русский)
! 72: EOF
! 73: $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
! 74: cat > tmp-ok <<\EOF
! 75: Russian (<U+0420><U+0443><U+0441><U+0441><U+043A><U+0438><U+0439>)
! 76: EOF
! 77: cmp tmp-out tmp-ok
! 78:
! 79: # Test of --unicode-subst with a non-ASCII substitution.
! 80:
! 81: if test "`(locale charmap) 2>/dev/null`" = UTF-8; then
! 82: cat > tmp-in <<\EOF
! 83: Russian (Русский)
! 84: EOF
! 85: $iconv $options_utf8 -f UTF-8 -t ISO-8859-1 2>/dev/null < tmp-in > tmp-out
! 86: $iconv -f ISO-8859-1 -t UTF-8 < tmp-out > tmp-out2
! 87: cat > tmp-ok <<\EOF
! 88: Russian («U+0420»«U+0443»«U+0441»«U+0441»«U+043A»«U+0438»«U+0439»)
! 89: EOF
! 90: cmp tmp-out2 tmp-ok
! 91: fi
! 92:
! 93: # Test of --unicode-subst with a very long substitution.
! 94:
! 95: cat > tmp-in <<\EOF
! 96: Böse Bübchen
! 97: EOF
! 98: $iconv --unicode-subst='<U+%010000X>' -f UTF-8 -t ASCII < tmp-in > tmp-out
! 99: # This printf command crashes on Solaris 10.
! 100: if printf 'B<U+%010000X>se B<U+%010000X>bchen\n' 0x00F6 0x00FC > tmp-ok 2>/dev/null; then
! 101: cmp tmp-out tmp-ok
! 102: fi
! 103:
! 104: cat > tmp-in <<\EOF
! 105: Böse Bübchen
! 106: EOF
! 107: $iconv --byte-subst='<0x%010000x>' -f ASCII -t ASCII < tmp-in > tmp-out
! 108: # This printf command crashes on Solaris 10.
! 109: 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
! 110: cmp tmp-out tmp-ok
! 111: fi
! 112:
! 113: # Test of --widechar-subst:
! 114: # wcrtomb() doesn't exist on FreeBSD 4.0 and is broken on MacOS X 10.3.
! 115: # So far this has been tested only on a glibc system with !__STDC_ISO_10646__.
! 116:
! 117: if false && test "`(locale charmap) 2>/dev/null`" = UTF-8; then
! 118: cat > tmp-in <<\EOF
! 119: Russian (Русский)
! 120: EOF
! 121: $iconv -f char -t wchar_t < tmp-in > tmp-inw
! 122: LC_ALL=C $iconv $options_ascii -f wchar_t -t ASCII < tmp-inw > tmp-out1
! 123: LC_ALL=de_DE.ISO-8859-1 $iconv $options_ascii -f wchar_t -t ASCII < tmp-inw > tmp-out2
! 124: cat > tmp-ok <<\EOF
! 125: Russian (<00000420><00000443><00000441><00000441><0000043a><00000438><00000439>)
! 126: EOF
! 127: cmp tmp-out1 tmp-ok
! 128: cmp tmp-out2 tmp-ok
! 129: if test "`(LC_ALL=de_DE.ISO-8859-1 locale charmap) 2>/dev/null`" = ISO-8859-1; then
! 130: options_latin1=`echo " $options_utf8" | $iconv -f UTF-8 -t ISO-8859-1`
! 131: LC_ALL=de_DE.ISO-8859-1 $iconv $options_latin1 -f wchar_t -t UTF-8 < tmp-inw > tmp-out1
! 132: cat > tmp-ok <<\EOF
! 133: Russian («00000420»«00000443»«00000441»«00000441»«0000043a»«00000438»«00000439»)
! 134: EOF
! 135: cmp tmp-out1 tmp-ok
! 136: fi
! 137: fi
! 138:
! 139: rm -f tmp-in* tmp-out* tmp-ok
! 140: exit 0
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>