Initialize Tizen 2.3
[framework/base/tizen-locale.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, write to the Free
20 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 # 02111-1307 USA.
22
23 codir=$1
24 cross_test_wrapper="$2"
25
26 # We use always the same temporary file.
27 temp1=$codir/iconvdata/iconv-test.xxx
28 temp2=$codir/iconvdata/iconv-test.yyy
29
30 trap "rm -f $temp1 $temp2" 1 2 3 15
31
32 # We must tell the iconv(1) program where the modules we want to use can
33 # be found.
34 GCONV_PATH=$codir/iconvdata
35 export GCONV_PATH
36
37 # We have to have some directories in the library path.
38 LIBPATH=$codir:$codir/iconvdata
39
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"
44
45 # Which echo?
46 if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
47   ac_n=-n ac_c= ac_t=
48 else
49   ac_n= ac_c='\c' ac_t=
50 fi
51
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.
58 failed=0
59 exec 5< TESTS
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
63
64   # Expand the variables now.
65   PROG=`eval echo $ICONV`
66
67   if test -n "$targets"; then
68     for t in $targets; do
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; }
74         echo $ac_n "OK$ac_c"
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; }
78           echo $ac_n "/OK$ac_c"
79         fi
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; }
84         echo $ac_n "OK$ac_c"
85         test -s $temp1 &&
86         LC_ALL=C cmp testdata/$from $temp2 > /dev/null 2>&1 ||
87           { echo "/FAILED"; failed=1; continue; }
88         echo "/OK"
89         rm -f $temp1 $temp2
90       fi
91
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; }
101         echo $ac_n "OK$ac_c"
102         LC_ALL=C cmp testdata/suntzus $temp1 ||
103           { echo "/FAILED"; failed=1; continue; }
104         echo "/OK"
105       fi
106       rm -f $temp1
107
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; }
119         echo $ac_n "OK$ac_c"
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"
124         fi
125         echo $ac_n " -> $from $ac_c"
126         $PROG -t ../localedata/charmaps/$from -f ../localedata/charmaps/$tc \
127               -o $temp2 $temp1 ||
128           { if test $? -gt 128; then exit 1; fi
129             echo "FAILED"; failed=1; continue; }
130         echo $ac_n "OK$ac_c"
131         test -s $temp1 &&
132         LC_ALL=C cmp testdata/$from $temp2 > /dev/null 2>&1 ||
133           { echo "/FAILED"; failed=1; continue; }
134         echo "/OK"
135         rm -f $temp1 $temp2
136       fi
137     done
138   fi
139
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; }
146     echo $ac_n "OK$ac_c"
147     LC_ALL=C cmp testdata/suntzus $temp1 ||
148       { echo "/FAILED"; failed=1; continue; }
149     echo "/OK"
150   fi
151 done
152 # Close TESTS.
153 exec 5<&-
154
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.
161 exec 5< TESTS2
162 while read utf8 from filename <&5; do
163   # Ignore empty and comment lines.
164   if test -z "$filename" || test "$utf8" = '#'; then continue; fi
165
166   # Expand the variables now.
167   PROG=`eval echo $ICONV`
168
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; }
175   echo "OK"
176
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; }
185   echo "OK"
186
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; }
192   echo "OK"
193
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; }
199   echo "OK"
200
201 done
202 exec 5<&-
203
204 exit $failed
205 # Local Variables:
206 #  mode:shell-script
207 # End: