]>
Commit | Line | Data |
---|---|---|
48d0341c | 1 | #!/bin/sh -f |
480bc727 | 2 | # Run available iconv(1) tests. |
dff8da6b | 3 | # Copyright (C) 1998-2024 Free Software Foundation, Inc. |
480bc727 | 4 | # This file is part of the GNU C Library. |
41bdb6e2 | 5 | |
480bc727 | 6 | # The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
7 | # modify it under the terms of the GNU Lesser General Public |
8 | # License as published by the Free Software Foundation; either | |
9 | # version 2.1 of the License, or (at your option) any later version. | |
10 | ||
480bc727 UD |
11 | # The GNU C Library is distributed in the hope that it will be useful, |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 AJ |
14 | # Lesser General Public License for more details. |
15 | ||
16 | # You should have received a copy of the GNU Lesser General Public | |
59ba27a6 | 17 | # License along with the GNU C Library; if not, see |
5a82c748 | 18 | # <https://www.gnu.org/licenses/>. |
480bc727 | 19 | |
57c69bef DL |
20 | set -e |
21 | ||
480bc727 | 22 | codir=$1 |
8540f6d2 JM |
23 | test_wrapper_env="$2" |
24 | run_program_env="$3" | |
480bc727 UD |
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 | ||
298f2566 UD |
32 | # We have to have some directories in the library path. |
33 | LIBPATH=$codir:$codir/iconvdata | |
34 | ||
480bc727 | 35 | # How the start the iconv(1) program. |
b0a01055 | 36 | ICONV='$codir/elf/ld.so --library-path $LIBPATH --inhibit-rpath ${from}.so \ |
310930c1 | 37 | $codir/iconv/iconv_prog' |
8540f6d2 | 38 | ICONV="$test_wrapper_env $run_program_env $ICONV" |
480bc727 | 39 | |
822078f6 UD |
40 | # Which echo? |
41 | if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then | |
42 | ac_n=-n ac_c= ac_t= | |
43 | else | |
44 | ac_n= ac_c='\c' ac_t= | |
45 | fi | |
46 | ||
480bc727 UD |
47 | # We read the file named TESTS. All non-empty lines not starting with |
48 | # `#' are interpreted as commands. | |
5aa8ff62 UD |
49 | failed=0 |
50 | while read from to subset targets; do | |
480bc727 | 51 | # Ignore empty and comment lines. |
3b7caeac | 52 | if test -z "$subset" || test "$from" = '#'; then continue; fi |
480bc727 | 53 | |
310930c1 UD |
54 | # Expand the variables now. |
55 | PROG=`eval echo $ICONV` | |
56 | ||
3b7caeac UD |
57 | if test -n "$targets"; then |
58 | for t in $targets; do | |
59 | if test -f testdata/$from; then | |
93693c4d | 60 | echo $ac_n " test data: $from -> $t $ac_c" |
6fb54a22 | 61 | $PROG -f $from -t $t testdata/$from < /dev/null > $temp1 || |
3b7caeac | 62 | { if test $? -gt 128; then exit 1; fi |
93693c4d | 63 | echo "FAILED"; failed=1; continue; } |
3b7caeac UD |
64 | echo $ac_n "OK$ac_c" |
65 | if test -s testdata/$from..$t; then | |
82ae2712 | 66 | LC_ALL=C cmp $temp1 testdata/$from..$t > /dev/null 2>&1 || |
3b7caeac UD |
67 | { echo "/FAILED"; failed=1; continue; } |
68 | echo $ac_n "/OK$ac_c" | |
69 | fi | |
70 | echo $ac_n " -> $from $ac_c" | |
6fb54a22 | 71 | $PROG -f $t -t $to -o $temp2 $temp1 < /dev/null || |
3b7caeac | 72 | { if test $? -gt 128; then exit 1; fi |
93693c4d | 73 | echo "FAILED"; failed=1; continue; } |
3b7caeac | 74 | echo $ac_n "OK$ac_c" |
82ae2712 UD |
75 | test -s $temp1 && |
76 | LC_ALL=C cmp testdata/$from $temp2 > /dev/null 2>&1 || | |
3b7caeac UD |
77 | { echo "/FAILED"; failed=1; continue; } |
78 | echo "/OK" | |
79 | rm -f $temp1 $temp2 | |
80 | fi | |
81 | ||
82 | # Now test some bigger text, entirely in ASCII. If ASCII is no subset | |
83 | # of the coded character set we convert the text to this coded character | |
84 | # set. Otherwise we convert to all the TARGETS. | |
85 | if test $subset = Y; then | |
93693c4d | 86 | echo $ac_n " suntzu: $from -> $t -> $to $ac_c" |
6fb54a22 | 87 | $PROG -f $from -t $t testdata/suntzus < /dev/null | |
3b7caeac UD |
88 | $PROG -f $t -t $to > $temp1 || |
89 | { if test $? -gt 128; then exit 1; fi | |
93693c4d | 90 | echo "FAILED"; failed=1; continue; } |
3b7caeac | 91 | echo $ac_n "OK$ac_c" |
82ae2712 | 92 | LC_ALL=C cmp testdata/suntzus $temp1 || |
93693c4d | 93 | { echo "/FAILED"; failed=1; continue; } |
3b7caeac UD |
94 | echo "/OK" |
95 | fi | |
96 | rm -f $temp1 | |
93693c4d UD |
97 | |
98 | # And tests where iconv(1) has to handle charmaps. | |
99 | if test "$t" = UTF8; then tc=UTF-8; else tc="$t"; fi | |
100 | if test -f ../localedata/charmaps/$from && | |
101 | test -f ../localedata/charmaps/$tc && | |
faaa6f62 UD |
102 | test -f testdata/$from && |
103 | ! grep '<U....><U....>' ../localedata/charmaps/$from > /dev/null; then | |
93693c4d UD |
104 | echo $ac_n "test charmap: $from -> $t $ac_c" |
105 | $PROG -f ../localedata/charmaps/$from -t ../localedata/charmaps/$tc \ | |
6fb54a22 | 106 | testdata/$from < /dev/null > $temp1 || |
93693c4d UD |
107 | { if test $? -gt 128; then exit 1; fi |
108 | echo "FAILED"; failed=1; continue; } | |
109 | echo $ac_n "OK$ac_c" | |
110 | if test -s testdata/$from..$t; then | |
82ae2712 | 111 | LC_ALL=C cmp $temp1 testdata/$from..$t > /dev/null 2>&1 || |
93693c4d UD |
112 | { echo "/FAILED"; failed=1; continue; } |
113 | echo $ac_n "/OK$ac_c" | |
114 | fi | |
115 | echo $ac_n " -> $from $ac_c" | |
116 | $PROG -t ../localedata/charmaps/$from -f ../localedata/charmaps/$tc \ | |
6fb54a22 | 117 | -o $temp2 $temp1 < /dev/null || |
93693c4d UD |
118 | { if test $? -gt 128; then exit 1; fi |
119 | echo "FAILED"; failed=1; continue; } | |
120 | echo $ac_n "OK$ac_c" | |
82ae2712 UD |
121 | test -s $temp1 && |
122 | LC_ALL=C cmp testdata/$from $temp2 > /dev/null 2>&1 || | |
93693c4d UD |
123 | { echo "/FAILED"; failed=1; continue; } |
124 | echo "/OK" | |
125 | rm -f $temp1 $temp2 | |
126 | fi | |
3b7caeac UD |
127 | done |
128 | fi | |
129 | ||
c8d49f05 | 130 | if test "$subset" = N; then |
b721a2c0 | 131 | echo $ac_n " suntzu: ASCII -> $to -> ASCII $ac_c" |
6fb54a22 | 132 | $PROG -f ASCII -t $to testdata/suntzus < /dev/null | |
3b7caeac | 133 | $PROG -f $to -t ASCII > $temp1 || |
813bb1f1 | 134 | { if test $? -gt 128; then exit 1; fi |
93693c4d | 135 | echo "FAILED"; failed=1; continue; } |
822078f6 | 136 | echo $ac_n "OK$ac_c" |
82ae2712 | 137 | LC_ALL=C cmp testdata/suntzus $temp1 || |
93693c4d | 138 | { echo "/FAILED"; failed=1; continue; } |
822078f6 | 139 | echo "/OK" |
3b7caeac | 140 | fi |
480bc727 UD |
141 | done < TESTS |
142 | ||
b721a2c0 UD |
143 | # We read the file named TESTS2. All non-empty lines not starting with |
144 | # `#' are interpreted as commands. | |
145 | while read utf8 from filename; do | |
146 | # Ignore empty and comment lines. | |
147 | if test -z "$filename" || test "$utf8" = '#'; then continue; fi | |
148 | ||
149 | # Expand the variables now. | |
150 | PROG=`eval echo $ICONV` | |
151 | ||
152 | # Test conversion to the endianness dependent encoding. | |
153 | echo $ac_n "test encoder: $utf8 -> $from $ac_c" | |
154 | $PROG -f $utf8 -t $from < testdata/${filename}..${utf8} > $temp1 | |
82ae2712 UD |
155 | LC_ALL=C cmp $temp1 testdata/${filename}..${from}.BE > /dev/null 2>&1 || |
156 | LC_ALL=C cmp $temp1 testdata/${filename}..${from}.LE > /dev/null 2>&1 || | |
b721a2c0 UD |
157 | { echo "/FAILED"; failed=1; continue; } |
158 | echo "OK" | |
159 | ||
160 | # Test conversion from the endianness dependent encoding. | |
161 | echo $ac_n "test decoder: $from -> $utf8 $ac_c" | |
162 | $PROG -f $from -t $utf8 < testdata/${filename}..${from}.BE > $temp1 | |
82ae2712 | 163 | LC_ALL=C cmp $temp1 testdata/${filename}..${utf8} > /dev/null 2>&1 || |
b721a2c0 UD |
164 | { echo "/FAILED"; failed=1; continue; } |
165 | $PROG -f $from -t $utf8 < testdata/${filename}..${from}.LE > $temp1 | |
82ae2712 | 166 | LC_ALL=C cmp $temp1 testdata/${filename}..${utf8} > /dev/null 2>&1 || |
b721a2c0 UD |
167 | { echo "/FAILED"; failed=1; continue; } |
168 | echo "OK" | |
169 | ||
170 | # Test byte swapping behaviour. | |
171 | echo $ac_n "test non-BOM: ${from}BE -> ${from}LE $ac_c" | |
172 | $PROG -f ${from}BE -t ${from}LE < testdata/${filename}..${from}.BE > $temp1 | |
82ae2712 | 173 | LC_ALL=C cmp $temp1 testdata/${filename}..${from}.LE > /dev/null 2>&1 || |
b721a2c0 UD |
174 | { echo "/FAILED"; failed=1; continue; } |
175 | echo "OK" | |
176 | ||
177 | # Test byte swapping behaviour. | |
178 | echo $ac_n "test non-BOM: ${from}LE -> ${from}BE $ac_c" | |
179 | $PROG -f ${from}LE -t ${from}BE < testdata/${filename}..${from}.LE > $temp1 | |
82ae2712 | 180 | LC_ALL=C cmp $temp1 testdata/${filename}..${from}.BE > /dev/null 2>&1 || |
b721a2c0 UD |
181 | { echo "/FAILED"; failed=1; continue; } |
182 | echo "OK" | |
183 | ||
184 | done < TESTS2 | |
185 | ||
41488498 FW |
186 | # Check for crashes in decoders. |
187 | printf '\016\377\377\377\377\377\377\377' > $temp1 | |
188 | for from in $iconv_modules ; do | |
189 | echo $ac_n "test decoder $from $ac_c" | |
190 | PROG=`eval echo $ICONV` | |
7d81e8d6 | 191 | if $PROG -f $from -t UTF8 < $temp1 >/dev/null 2>&1 ; then |
41488498 FW |
192 | : # fall through |
193 | else | |
194 | status=$? | |
195 | if test $status -gt 1 ; then | |
196 | echo "/FAILED" | |
197 | failed=1 | |
198 | continue | |
199 | fi | |
200 | fi | |
201 | echo "OK" | |
202 | done | |
203 | ||
5aa8ff62 | 204 | exit $failed |
480bc727 UD |
205 | # Local Variables: |
206 | # mode:shell-script | |
207 | # End: |