Do export the symbol 'locale_charset' (needed by GNU bash).
[libiconv.git] / tests / check-subst
blob1b5f38750fbc745224dd40ba5912c4b9f320f52e
1 #!/bin/sh
2 # Check of --unicode-subst, --byte-subst, --widechar-subst options.
3 set -e
4 iconv=../src/iconv_no_i18n
6 options_ascii='--unicode-subst=<U+%04X> --byte-subst=<0x%02x> --widechar-subst=<%08x>'
7 options_utf8='--unicode-subst=«U+%04X» --byte-subst=«0x%02x» --widechar-subst=«%08x»'
9 # Test of --byte-subst with an ASCII substitution.
11 cat > tmp-in <<\EOF
12 Böse Bübchen
13 EOF
14 $iconv $options_ascii -f ASCII -t ASCII < tmp-in > tmp-out
15 cat > tmp-ok <<\EOF
16 B<0xc3><0xb6>se B<0xc3><0xbc>bchen
17 EOF
18 cmp tmp-out tmp-ok
20 # Test of --byte-subst with a non-ASCII substitution.
22 if test "`(locale charmap) 2>/dev/null`" = UTF-8; then
23 cat > tmp-in <<\EOF
24 Böse Bübchen
25 EOF
26 $iconv $options_utf8 -f ASCII -t UTF-8 2>/dev/null < tmp-in > tmp-out
27 cat > tmp-ok <<\EOF
28 0xc3»«0xb6»se B«0xc3»«0xbc»bchen
29 EOF
30 cmp tmp-out tmp-ok
33 if test "`(locale charmap) 2>/dev/null`" = UTF-8; then
34 cat > tmp-in <<\EOF
35 Böse Bübchen
36 EOF
37 $iconv $options_utf8 -f ASCII -t ISO-8859-1 2>/dev/null < tmp-in > tmp-out
38 $iconv -f ISO-8859-1 -t UTF-8 < tmp-out > tmp-out2
39 cat > tmp-ok <<\EOF
40 0xc3»«0xb6»se B«0xc3»«0xbc»bchen
41 EOF
42 cmp tmp-out2 tmp-ok
45 # Test of --byte-subst with a very long substitution.
47 cat > tmp-in <<\EOF
48 Böse Bübchen
49 EOF
50 $iconv --byte-subst='<0x%010000x>' -f ASCII -t ASCII < tmp-in > tmp-out
51 # This printf command crashes on Solaris 10.
52 # See <http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6550204>.
53 # Likewise on OSF/1 5.1.
54 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
55 cmp tmp-out tmp-ok
58 # Test of --unicode-subst with an ASCII substitution.
60 cat > tmp-in <<\EOF
61 Böse Bübchen
62 EOF
63 $iconv $options_ascii -f UTF-8 -t ASCII < tmp-in > tmp-out
64 cat > tmp-ok <<\EOF
65 B<U+00F6>se B<U+00FC>bchen
66 EOF
67 cmp tmp-out tmp-ok
69 cat > tmp-in <<\EOF
70 Russian (Русский)
71 EOF
72 $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
73 cat > tmp-ok <<\EOF
74 Russian (<U+0420><U+0443><U+0441><U+0441><U+043A><U+0438><U+0439>)
75 EOF
76 cmp tmp-out tmp-ok
78 # Test of --unicode-subst with a non-ASCII substitution.
80 if test "`(locale charmap) 2>/dev/null`" = UTF-8; then
81 cat > tmp-in <<\EOF
82 Russian (Русский)
83 EOF
84 $iconv $options_utf8 -f UTF-8 -t ISO-8859-1 2>/dev/null < tmp-in > tmp-out
85 $iconv -f ISO-8859-1 -t UTF-8 < tmp-out > tmp-out2
86 cat > tmp-ok <<\EOF
87 Russian («U+0420»«U+0443»«U+0441»«U+0441»«U+043A»«U+0438»«U+0439»)
88 EOF
89 cmp tmp-out2 tmp-ok
92 # Test of --unicode-subst with a very long substitution.
94 cat > tmp-in <<\EOF
95 Böse Bübchen
96 EOF
97 $iconv --unicode-subst='<U+%010000X>' -f UTF-8 -t ASCII < tmp-in > tmp-out
98 # This printf command crashes on Solaris 10.
99 # See <http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6550204>.
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
104 cat > tmp-in <<\EOF
105 Böse Bübchen
107 $iconv --byte-subst='<0x%010000x>' -f ASCII -t ASCII < tmp-in > tmp-out
108 # This printf command crashes on Solaris 10.
109 # See <http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6550204>.
110 # Likewise on OSF/1 5.1.
111 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
112 cmp tmp-out tmp-ok
115 # Test of --widechar-subst:
116 # wcrtomb() doesn't exist on FreeBSD 4.0 and is broken on MacOS X 10.3.
117 # So far this has been tested only on a glibc system with !__STDC_ISO_10646__.
119 if false && test "`(locale charmap) 2>/dev/null`" = UTF-8; then
120 cat > tmp-in <<\EOF
121 Russian (Русский)
123 $iconv -f char -t wchar_t < tmp-in > tmp-inw
124 LC_ALL=C $iconv $options_ascii -f wchar_t -t ASCII < tmp-inw > tmp-out1
125 LC_ALL=de_DE.ISO-8859-1 $iconv $options_ascii -f wchar_t -t ASCII < tmp-inw > tmp-out2
126 cat > tmp-ok <<\EOF
127 Russian (<00000420><00000443><00000441><00000441><0000043a><00000438><00000439>)
129 cmp tmp-out1 tmp-ok
130 cmp tmp-out2 tmp-ok
131 if test "`(LC_ALL=de_DE.ISO-8859-1 locale charmap) 2>/dev/null`" = ISO-8859-1; then
132 options_latin1=`echo " $options_utf8" | $iconv -f UTF-8 -t ISO-8859-1`
133 LC_ALL=de_DE.ISO-8859-1 $iconv $options_latin1 -f wchar_t -t UTF-8 < tmp-inw > tmp-out1
134 cat > tmp-ok <<\EOF
135 Russian («00000420»«00000443»«00000441»«00000441»«0000043a»«00000438»«00000439»)
137 cmp tmp-out1 tmp-ok
141 rm -f tmp-in* tmp-out* tmp-ok
142 exit 0