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