File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / libiconv / tests / check-subst
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue May 29 09:29:43 2012 UTC (12 years, 1 month ago) by misho
Branches: libiconv, MAIN
CVS tags: v1_14p0, v1_14, HEAD
libiconv v1.14

    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: # See <http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6550204>.
   56: # Likewise on OSF/1 5.1.
   57: 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
   58:   cmp tmp-out tmp-ok
   59: fi
   60: 
   61: # Test of --unicode-subst with an ASCII substitution.
   62: 
   63: cat > tmp-in <<\EOF
   64: Böse Bübchen
   65: EOF
   66: $iconv $options_ascii -f UTF-8 -t ASCII < tmp-in > tmp-out
   67: cat > tmp-ok <<\EOF
   68: B<U+00F6>se B<U+00FC>bchen
   69: EOF
   70: cmp tmp-out tmp-ok
   71: 
   72: cat > tmp-in <<\EOF
   73: Russian (Русский)
   74: EOF
   75: $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
   76: cat > tmp-ok <<\EOF
   77: Russian (<U+0420><U+0443><U+0441><U+0441><U+043A><U+0438><U+0439>)
   78: EOF
   79: cmp tmp-out tmp-ok
   80: 
   81: # Test of --unicode-subst with a non-ASCII substitution.
   82: 
   83: if test "`(locale charmap) 2>/dev/null`" = UTF-8; then
   84:   cat > tmp-in <<\EOF
   85: Russian (Русский)
   86: EOF
   87:   $iconv $options_utf8 -f UTF-8 -t ISO-8859-1 2>/dev/null < tmp-in > tmp-out
   88:   $iconv -f ISO-8859-1 -t UTF-8 < tmp-out > tmp-out2
   89:   cat > tmp-ok <<\EOF
   90: Russian («U+0420»«U+0443»«U+0441»«U+0441»«U+043A»«U+0438»«U+0439»)
   91: EOF
   92:   cmp tmp-out2 tmp-ok
   93: fi
   94: 
   95: # Test of --unicode-subst with a very long substitution.
   96: 
   97: cat > tmp-in <<\EOF
   98: Böse Bübchen
   99: EOF
  100: $iconv --unicode-subst='<U+%010000X>' -f UTF-8 -t ASCII < tmp-in > tmp-out
  101: # This printf command crashes on Solaris 10.
  102: # See <http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6550204>.
  103: if printf 'B<U+%010000X>se B<U+%010000X>bchen\n' 0x00F6 0x00FC > tmp-ok 2>/dev/null; then
  104:   cmp tmp-out tmp-ok
  105: fi
  106: 
  107: cat > tmp-in <<\EOF
  108: Böse Bübchen
  109: EOF
  110: $iconv --byte-subst='<0x%010000x>' -f ASCII -t ASCII < tmp-in > tmp-out
  111: # This printf command crashes on Solaris 10.
  112: # See <http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6550204>.
  113: # Likewise on OSF/1 5.1.
  114: 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
  115:   cmp tmp-out tmp-ok
  116: fi
  117: 
  118: # Test of --widechar-subst:
  119: # wcrtomb() doesn't exist on FreeBSD 4.0 and is broken on MacOS X 10.3.
  120: # So far this has been tested only on a glibc system with !__STDC_ISO_10646__.
  121: 
  122: if false && test "`(locale charmap) 2>/dev/null`" = UTF-8; then
  123:   cat > tmp-in <<\EOF
  124: Russian (Русский)
  125: EOF
  126:   $iconv -f char -t wchar_t < tmp-in > tmp-inw
  127:   LC_ALL=C                $iconv $options_ascii -f wchar_t -t ASCII < tmp-inw > tmp-out1
  128:   LC_ALL=de_DE.ISO-8859-1 $iconv $options_ascii -f wchar_t -t ASCII < tmp-inw > tmp-out2
  129:   cat > tmp-ok <<\EOF
  130: Russian (<00000420><00000443><00000441><00000441><0000043a><00000438><00000439>)
  131: EOF
  132:   cmp tmp-out1 tmp-ok
  133:   cmp tmp-out2 tmp-ok
  134:   if test "`(LC_ALL=de_DE.ISO-8859-1 locale charmap) 2>/dev/null`" = ISO-8859-1; then
  135:     options_latin1=`echo " $options_utf8" | $iconv -f UTF-8 -t ISO-8859-1`
  136:     LC_ALL=de_DE.ISO-8859-1 $iconv $options_latin1 -f wchar_t -t UTF-8 < tmp-inw > tmp-out1
  137:     cat > tmp-ok <<\EOF
  138: Russian («00000420»«00000443»«00000441»«00000441»«0000043a»«00000438»«00000439»)
  139: EOF
  140:     cmp tmp-out1 tmp-ok
  141:   fi
  142: fi
  143: 
  144: rm -f tmp-in* tmp-out* tmp-ok
  145: exit 0

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>