Update.
[platform/upstream/glibc.git] / iconvdata / run-iconv-test.sh
1 #! /bin/sh -f
2 # Run available iconv(1) tests.
3 # Copyright (C) 1998, 1999, 2000, 2001 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 # The GNU C Library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Library General Public License as
9 # published by the Free Software Foundation; either version 2 of the
10 # License, or (at your option) any later version.
11 #
12 # The GNU C Library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Library General Public License for more details.
16 #
17 # You should have received a copy of the GNU Library General Public
18 # License along with the GNU C Library; see the file COPYING.LIB.  If not,
19 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 # Boston, MA 02111-1307, USA.
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"
66             failed=1
67             continue
68           }
69         echo $ac_n "OK$ac_c"
70         if test -s testdata/$from..$t; then
71           cmp $temp1 testdata/$from..$t > /dev/null 2>&1 ||
72             { echo "/FAILED"; failed=1; continue; }
73           echo $ac_n "/OK$ac_c"
74         fi
75         echo $ac_n " -> $from $ac_c"
76         $PROG -f $t -t $to -o $temp2 $temp1 ||
77           { if test $? -gt 128; then exit 1; fi
78             echo "FAILED"
79             failed=1
80             continue
81           }
82         echo $ac_n "OK$ac_c"
83         test -s $temp1 && cmp testdata/$from $temp2 > /dev/null 2>&1 ||
84           { echo "/FAILED"; failed=1; continue; }
85         echo "/OK"
86         rm -f $temp1 $temp2
87       fi
88
89       # Now test some bigger text, entirely in ASCII.  If ASCII is no subset
90       # of the coded character set we convert the text to this coded character
91       # set.  Otherwise we convert to all the TARGETS.
92       if test $subset = Y; then
93         echo $ac_n "   suntzu: $from -> $t -> $to $ac_c"
94         $PROG -f $from -t $t testdata/suntzus |
95         $PROG -f $t -t $to > $temp1 ||
96           { if test $? -gt 128; then exit 1; fi
97             echo "FAILED"
98             failed=1
99             continue
100           }
101         echo $ac_n "OK$ac_c"
102         cmp testdata/suntzus $temp1 ||
103           { echo "/FAILED";
104             failed=1; continue; }
105         echo "/OK"
106       fi
107       rm -f $temp1
108     done
109   fi
110
111   if test "$subset" != Y; then
112     echo $ac_n "   suntzu: ASCII -> $to -> ASCII $ac_c"
113     $PROG -f ASCII -t $to testdata/suntzus |
114     $PROG -f $to -t ASCII > $temp1 ||
115       { if test $? -gt 128; then exit 1; fi
116         echo "FAILED"
117         failed=1
118         continue
119       }
120     echo $ac_n "OK$ac_c"
121     cmp testdata/suntzus $temp1 ||
122       { echo "/FAILED";
123         failed=1; continue; }
124     echo "/OK"
125   fi
126 done < TESTS
127
128 exit $failed
129 # Local Variables:
130 #  mode:shell-script
131 # End: