2 # Run available iconv(1) tests.
3 # Copyright (C) 1998-2002, 2005, 2006, 2008 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
5 # Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
8 # The GNU C Library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
13 # The GNU C Library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with the GNU C Library; if not, write to the Free
20 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 cross_test_wrapper="$2"
26 # We use always the same temporary file.
27 temp1=$codir/iconvdata/iconv-test.xxx
28 temp2=$codir/iconvdata/iconv-test.yyy
30 trap "rm -f $temp1 $temp2" 1 2 3 15
32 # We must tell the iconv(1) program where the modules we want to use can
34 GCONV_PATH=$codir/iconvdata
37 # We have to have some directories in the library path.
38 LIBPATH=$codir:$codir/iconvdata
40 # How the start the iconv(1) program.
41 ICONV='$codir/elf/ld.so --library-path $LIBPATH --inhibit-rpath ${from}.so \
42 $codir/iconv/iconv_prog'
43 ICONV="$cross_test_wrapper $ICONV"
46 if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
52 # We read the file named TESTS. All non-empty lines not starting with
53 # `#' are interpreted as commands.
54 # Avoid reading from stdin, since the while loop's body inherits that;
55 # if cross_test_wrapper is a program like ssh that reads its input
56 # even if the program running on the remote side doesn't, it will
57 # steal input from the loop.
60 while read from to subset targets <&5; do
61 # Ignore empty and comment lines.
62 if test -z "$subset" || test "$from" = '#'; then continue; fi
64 # Expand the variables now.
65 PROG=`eval echo $ICONV`
67 if test -n "$targets"; then
69 if test -f testdata/$from; then
70 echo $ac_n " test data: $from -> $t $ac_c"
71 $PROG -f $from -t $t testdata/$from > $temp1 ||
72 { if test $? -gt 128; then exit 1; fi
73 echo "FAILED"; failed=1; continue; }
75 if test -s testdata/$from..$t; then
76 LC_ALL=C cmp $temp1 testdata/$from..$t > /dev/null 2>&1 ||
77 { echo "/FAILED"; failed=1; continue; }
80 echo $ac_n " -> $from $ac_c"
81 $PROG -f $t -t $to -o $temp2 $temp1 ||
82 { if test $? -gt 128; then exit 1; fi
83 echo "FAILED"; failed=1; continue; }
86 LC_ALL=C cmp testdata/$from $temp2 > /dev/null 2>&1 ||
87 { echo "/FAILED"; failed=1; continue; }
92 # Now test some bigger text, entirely in ASCII. If ASCII is no subset
93 # of the coded character set we convert the text to this coded character
94 # set. Otherwise we convert to all the TARGETS.
95 if test $subset = Y; then
96 echo $ac_n " suntzu: $from -> $t -> $to $ac_c"
97 $PROG -f $from -t $t testdata/suntzus |
98 $PROG -f $t -t $to > $temp1 ||
99 { if test $? -gt 128; then exit 1; fi
100 echo "FAILED"; failed=1; continue; }
102 LC_ALL=C cmp testdata/suntzus $temp1 ||
103 { echo "/FAILED"; failed=1; continue; }
108 # And tests where iconv(1) has to handle charmaps.
109 if test "$t" = UTF8; then tc=UTF-8; else tc="$t"; fi
110 if test -f ../localedata/charmaps/$from &&
111 test -f ../localedata/charmaps/$tc &&
112 test -f testdata/$from &&
113 ! grep '<U....><U....>' ../localedata/charmaps/$from > /dev/null; then
114 echo $ac_n "test charmap: $from -> $t $ac_c"
115 $PROG -f ../localedata/charmaps/$from -t ../localedata/charmaps/$tc \
116 testdata/$from > $temp1 ||
117 { if test $? -gt 128; then exit 1; fi
118 echo "FAILED"; failed=1; continue; }
120 if test -s testdata/$from..$t; then
121 LC_ALL=C cmp $temp1 testdata/$from..$t > /dev/null 2>&1 ||
122 { echo "/FAILED"; failed=1; continue; }
123 echo $ac_n "/OK$ac_c"
125 echo $ac_n " -> $from $ac_c"
126 $PROG -t ../localedata/charmaps/$from -f ../localedata/charmaps/$tc \
128 { if test $? -gt 128; then exit 1; fi
129 echo "FAILED"; failed=1; continue; }
132 LC_ALL=C cmp testdata/$from $temp2 > /dev/null 2>&1 ||
133 { echo "/FAILED"; failed=1; continue; }
140 if test "$subset" = N; then
141 echo $ac_n " suntzu: ASCII -> $to -> ASCII $ac_c"
142 $PROG -f ASCII -t $to testdata/suntzus |
143 $PROG -f $to -t ASCII > $temp1 ||
144 { if test $? -gt 128; then exit 1; fi
145 echo "FAILED"; failed=1; continue; }
147 LC_ALL=C cmp testdata/suntzus $temp1 ||
148 { echo "/FAILED"; failed=1; continue; }
155 # We read the file named TESTS2. All non-empty lines not starting with
156 # `#' are interpreted as commands.
157 # Avoid reading from stdin, since the while loop's body inherits that;
158 # if cross_test_wrapper is a program like ssh that reads its input
159 # even if the program running on the remote side doesn't, it will
160 # steal input from the loop.
162 while read utf8 from filename <&5; do
163 # Ignore empty and comment lines.
164 if test -z "$filename" || test "$utf8" = '#'; then continue; fi
166 # Expand the variables now.
167 PROG=`eval echo $ICONV`
169 # Test conversion to the endianness dependent encoding.
170 echo $ac_n "test encoder: $utf8 -> $from $ac_c"
171 $PROG -f $utf8 -t $from < testdata/${filename}..${utf8} > $temp1
172 LC_ALL=C cmp $temp1 testdata/${filename}..${from}.BE > /dev/null 2>&1 ||
173 LC_ALL=C cmp $temp1 testdata/${filename}..${from}.LE > /dev/null 2>&1 ||
174 { echo "/FAILED"; failed=1; continue; }
177 # Test conversion from the endianness dependent encoding.
178 echo $ac_n "test decoder: $from -> $utf8 $ac_c"
179 $PROG -f $from -t $utf8 < testdata/${filename}..${from}.BE > $temp1
180 LC_ALL=C cmp $temp1 testdata/${filename}..${utf8} > /dev/null 2>&1 ||
181 { echo "/FAILED"; failed=1; continue; }
182 $PROG -f $from -t $utf8 < testdata/${filename}..${from}.LE > $temp1
183 LC_ALL=C cmp $temp1 testdata/${filename}..${utf8} > /dev/null 2>&1 ||
184 { echo "/FAILED"; failed=1; continue; }
187 # Test byte swapping behaviour.
188 echo $ac_n "test non-BOM: ${from}BE -> ${from}LE $ac_c"
189 $PROG -f ${from}BE -t ${from}LE < testdata/${filename}..${from}.BE > $temp1
190 LC_ALL=C cmp $temp1 testdata/${filename}..${from}.LE > /dev/null 2>&1 ||
191 { echo "/FAILED"; failed=1; continue; }
194 # Test byte swapping behaviour.
195 echo $ac_n "test non-BOM: ${from}LE -> ${from}BE $ac_c"
196 $PROG -f ${from}LE -t ${from}BE < testdata/${filename}..${from}.LE > $temp1
197 LC_ALL=C cmp $temp1 testdata/${filename}..${from}.BE > /dev/null 2>&1 ||
198 { echo "/FAILED"; failed=1; continue; }