Remove pre-2.4 Linux kernel support.
[platform/upstream/glibc.git] / iconvdata / run-iconv-test.sh
1 #! /bin/sh -f
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.
6 #
7
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.
12
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.
17
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with the GNU C Library; if not, see
20 # <http://www.gnu.org/licenses/>.
21
22 codir=$1
23
24 # We use always the same temporary file.
25 temp1=$codir/iconvdata/iconv-test.xxx
26 temp2=$codir/iconvdata/iconv-test.yyy
27
28 trap "rm -f $temp1 $temp2" 1 2 3 15
29
30 # We must tell the iconv(1) program where the modules we want to use can
31 # be found.
32 GCONV_PATH=$codir/iconvdata
33 export GCONV_PATH
34
35 # We have to have some directories in the library path.
36 LIBPATH=$codir:$codir/iconvdata
37
38 # How the start the iconv(1) program.
39 ICONV='$codir/elf/ld.so --library-path $LIBPATH --inhibit-rpath ${from}.so \
40        $codir/iconv/iconv_prog'
41
42 # Which echo?
43 if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
44   ac_n=-n ac_c= ac_t=
45 else
46   ac_n= ac_c='\c' ac_t=
47 fi
48
49 # We read the file named TESTS.  All non-empty lines not starting with
50 # `#' are interpreted as commands.
51 failed=0
52 while read from to subset targets; do
53   # Ignore empty and comment lines.
54   if test -z "$subset" || test "$from" = '#'; then continue; fi
55
56   # Expand the variables now.
57   PROG=`eval echo $ICONV`
58
59   if test -n "$targets"; then
60     for t in $targets; do
61       if test -f testdata/$from; then
62         echo $ac_n "   test data: $from -> $t $ac_c"
63         $PROG -f $from -t $t testdata/$from > $temp1 ||
64           { if test $? -gt 128; then exit 1; fi
65             echo "FAILED"; failed=1; continue; }
66         echo $ac_n "OK$ac_c"
67         if test -s testdata/$from..$t; then
68           LC_ALL=C cmp $temp1 testdata/$from..$t > /dev/null 2>&1 ||
69             { echo "/FAILED"; failed=1; continue; }
70           echo $ac_n "/OK$ac_c"
71         fi
72         echo $ac_n " -> $from $ac_c"
73         $PROG -f $t -t $to -o $temp2 $temp1 ||
74           { if test $? -gt 128; then exit 1; fi
75             echo "FAILED"; failed=1; continue; }
76         echo $ac_n "OK$ac_c"
77         test -s $temp1 &&
78         LC_ALL=C cmp testdata/$from $temp2 > /dev/null 2>&1 ||
79           { echo "/FAILED"; failed=1; continue; }
80         echo "/OK"
81         rm -f $temp1 $temp2
82       fi
83
84       # Now test some bigger text, entirely in ASCII.  If ASCII is no subset
85       # of the coded character set we convert the text to this coded character
86       # set.  Otherwise we convert to all the TARGETS.
87       if test $subset = Y; then
88         echo $ac_n "      suntzu: $from -> $t -> $to $ac_c"
89         $PROG -f $from -t $t testdata/suntzus |
90         $PROG -f $t -t $to > $temp1 ||
91           { if test $? -gt 128; then exit 1; fi
92             echo "FAILED"; failed=1; continue; }
93         echo $ac_n "OK$ac_c"
94         LC_ALL=C cmp testdata/suntzus $temp1 ||
95           { echo "/FAILED"; failed=1; continue; }
96         echo "/OK"
97       fi
98       rm -f $temp1
99
100       # And tests where iconv(1) has to handle charmaps.
101       if test "$t" = UTF8; then tc=UTF-8; else tc="$t"; fi
102       if test -f ../localedata/charmaps/$from &&
103          test -f ../localedata/charmaps/$tc &&
104          test -f testdata/$from &&
105          ! grep '<U....><U....>' ../localedata/charmaps/$from > /dev/null; then
106         echo $ac_n "test charmap: $from -> $t $ac_c"
107         $PROG -f ../localedata/charmaps/$from -t ../localedata/charmaps/$tc \
108               testdata/$from > $temp1 ||
109           { if test $? -gt 128; then exit 1; fi
110             echo "FAILED"; failed=1; continue; }
111         echo $ac_n "OK$ac_c"
112         if test -s testdata/$from..$t; then
113           LC_ALL=C cmp $temp1 testdata/$from..$t > /dev/null 2>&1 ||
114             { echo "/FAILED"; failed=1; continue; }
115           echo $ac_n "/OK$ac_c"
116         fi
117         echo $ac_n " -> $from $ac_c"
118         $PROG -t ../localedata/charmaps/$from -f ../localedata/charmaps/$tc \
119               -o $temp2 $temp1 ||
120           { if test $? -gt 128; then exit 1; fi
121             echo "FAILED"; failed=1; continue; }
122         echo $ac_n "OK$ac_c"
123         test -s $temp1 &&
124         LC_ALL=C cmp testdata/$from $temp2 > /dev/null 2>&1 ||
125           { echo "/FAILED"; failed=1; continue; }
126         echo "/OK"
127         rm -f $temp1 $temp2
128       fi
129     done
130   fi
131
132   if test "$subset" = N; then
133     echo $ac_n "      suntzu: ASCII -> $to -> ASCII $ac_c"
134     $PROG -f ASCII -t $to testdata/suntzus |
135     $PROG -f $to -t ASCII > $temp1 ||
136       { if test $? -gt 128; then exit 1; fi
137         echo "FAILED"; failed=1; continue; }
138     echo $ac_n "OK$ac_c"
139     LC_ALL=C cmp testdata/suntzus $temp1 ||
140       { echo "/FAILED"; failed=1; continue; }
141     echo "/OK"
142   fi
143 done < TESTS
144
145 # We read the file named TESTS2.  All non-empty lines not starting with
146 # `#' are interpreted as commands.
147 while read utf8 from filename; do
148   # Ignore empty and comment lines.
149   if test -z "$filename" || test "$utf8" = '#'; then continue; fi
150
151   # Expand the variables now.
152   PROG=`eval echo $ICONV`
153
154   # Test conversion to the endianness dependent encoding.
155   echo $ac_n "test encoder: $utf8 -> $from $ac_c"
156   $PROG -f $utf8 -t $from < testdata/${filename}..${utf8} > $temp1
157   LC_ALL=C cmp $temp1 testdata/${filename}..${from}.BE > /dev/null 2>&1 ||
158   LC_ALL=C cmp $temp1 testdata/${filename}..${from}.LE > /dev/null 2>&1 ||
159     { echo "/FAILED"; failed=1; continue; }
160   echo "OK"
161
162   # Test conversion from the endianness dependent encoding.
163   echo $ac_n "test decoder: $from -> $utf8 $ac_c"
164   $PROG -f $from -t $utf8 < testdata/${filename}..${from}.BE > $temp1
165   LC_ALL=C cmp $temp1 testdata/${filename}..${utf8} > /dev/null 2>&1 ||
166     { echo "/FAILED"; failed=1; continue; }
167   $PROG -f $from -t $utf8 < testdata/${filename}..${from}.LE > $temp1
168   LC_ALL=C cmp $temp1 testdata/${filename}..${utf8} > /dev/null 2>&1 ||
169     { echo "/FAILED"; failed=1; continue; }
170   echo "OK"
171
172   # Test byte swapping behaviour.
173   echo $ac_n "test non-BOM: ${from}BE -> ${from}LE $ac_c"
174   $PROG -f ${from}BE -t ${from}LE < testdata/${filename}..${from}.BE > $temp1
175   LC_ALL=C cmp $temp1 testdata/${filename}..${from}.LE > /dev/null 2>&1 ||
176     { echo "/FAILED"; failed=1; continue; }
177   echo "OK"
178
179   # Test byte swapping behaviour.
180   echo $ac_n "test non-BOM: ${from}LE -> ${from}BE $ac_c"
181   $PROG -f ${from}LE -t ${from}BE < testdata/${filename}..${from}.LE > $temp1
182   LC_ALL=C cmp $temp1 testdata/${filename}..${from}.BE > /dev/null 2>&1 ||
183     { echo "/FAILED"; failed=1; continue; }
184   echo "OK"
185
186 done < TESTS2
187
188 exit $failed
189 # Local Variables:
190 #  mode:shell-script
191 # End: