]>
Commit | Line | Data |
---|---|---|
480bc727 UD |
1 | #! /bin/sh -f |
2 | # Run available iconv(1) tests. | |
568035b7 | 3 | # Copyright (C) 1998-2013 Free Software Foundation, Inc. |
480bc727 UD |
4 | # This file is part of the GNU C Library. |
5 | # Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. | |
41bdb6e2 | 6 | |
480bc727 | 7 | # The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
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 | ||
480bc727 UD |
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 | |
41bdb6e2 AJ |
15 | # Lesser General Public License for more details. |
16 | ||
17 | # You should have received a copy of the GNU Lesser General Public | |
59ba27a6 PE |
18 | # License along with the GNU C Library; if not, see |
19 | # <http://www.gnu.org/licenses/>. | |
480bc727 | 20 | |
57c69bef DL |
21 | set -e |
22 | ||
480bc727 | 23 | codir=$1 |
cc1290d0 | 24 | test_wrapper="$2" |
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 | ||
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 | ||
298f2566 UD |
37 | # We have to have some directories in the library path. |
38 | LIBPATH=$codir:$codir/iconvdata | |
39 | ||
480bc727 | 40 | # How the start the iconv(1) program. |
b0a01055 | 41 | ICONV='$codir/elf/ld.so --library-path $LIBPATH --inhibit-rpath ${from}.so \ |
310930c1 | 42 | $codir/iconv/iconv_prog' |
cc1290d0 | 43 | ICONV="$test_wrapper $ICONV" |
480bc727 | 44 | |
822078f6 UD |
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 | ||
480bc727 UD |
52 | # We read the file named TESTS. All non-empty lines not starting with |
53 | # `#' are interpreted as commands. | |
5aa8ff62 UD |
54 | failed=0 |
55 | while read from to subset targets; do | |
480bc727 | 56 | # Ignore empty and comment lines. |
3b7caeac | 57 | if test -z "$subset" || test "$from" = '#'; then continue; fi |
480bc727 | 58 | |
310930c1 UD |
59 | # Expand the variables now. |
60 | PROG=`eval echo $ICONV` | |
61 | ||
3b7caeac UD |
62 | if test -n "$targets"; then |
63 | for t in $targets; do | |
64 | if test -f testdata/$from; then | |
93693c4d | 65 | echo $ac_n " test data: $from -> $t $ac_c" |
6fb54a22 | 66 | $PROG -f $from -t $t testdata/$from < /dev/null > $temp1 || |
3b7caeac | 67 | { if test $? -gt 128; then exit 1; fi |
93693c4d | 68 | echo "FAILED"; failed=1; continue; } |
3b7caeac UD |
69 | echo $ac_n "OK$ac_c" |
70 | if test -s testdata/$from..$t; then | |
82ae2712 | 71 | LC_ALL=C cmp $temp1 testdata/$from..$t > /dev/null 2>&1 || |
3b7caeac UD |
72 | { echo "/FAILED"; failed=1; continue; } |
73 | echo $ac_n "/OK$ac_c" | |
74 | fi | |
75 | echo $ac_n " -> $from $ac_c" | |
6fb54a22 | 76 | $PROG -f $t -t $to -o $temp2 $temp1 < /dev/null || |
3b7caeac | 77 | { if test $? -gt 128; then exit 1; fi |
93693c4d | 78 | echo "FAILED"; failed=1; continue; } |
3b7caeac | 79 | echo $ac_n "OK$ac_c" |
82ae2712 UD |
80 | test -s $temp1 && |
81 | LC_ALL=C cmp testdata/$from $temp2 > /dev/null 2>&1 || | |
3b7caeac UD |
82 | { echo "/FAILED"; failed=1; continue; } |
83 | echo "/OK" | |
84 | rm -f $temp1 $temp2 | |
85 | fi | |
86 | ||
87 | # Now test some bigger text, entirely in ASCII. If ASCII is no subset | |
88 | # of the coded character set we convert the text to this coded character | |
89 | # set. Otherwise we convert to all the TARGETS. | |
90 | if test $subset = Y; then | |
93693c4d | 91 | echo $ac_n " suntzu: $from -> $t -> $to $ac_c" |
6fb54a22 | 92 | $PROG -f $from -t $t testdata/suntzus < /dev/null | |
3b7caeac UD |
93 | $PROG -f $t -t $to > $temp1 || |
94 | { if test $? -gt 128; then exit 1; fi | |
93693c4d | 95 | echo "FAILED"; failed=1; continue; } |
3b7caeac | 96 | echo $ac_n "OK$ac_c" |
82ae2712 | 97 | LC_ALL=C cmp testdata/suntzus $temp1 || |
93693c4d | 98 | { echo "/FAILED"; failed=1; continue; } |
3b7caeac UD |
99 | echo "/OK" |
100 | fi | |
101 | rm -f $temp1 | |
93693c4d UD |
102 | |
103 | # And tests where iconv(1) has to handle charmaps. | |
104 | if test "$t" = UTF8; then tc=UTF-8; else tc="$t"; fi | |
105 | if test -f ../localedata/charmaps/$from && | |
106 | test -f ../localedata/charmaps/$tc && | |
faaa6f62 UD |
107 | test -f testdata/$from && |
108 | ! grep '<U....><U....>' ../localedata/charmaps/$from > /dev/null; then | |
93693c4d UD |
109 | echo $ac_n "test charmap: $from -> $t $ac_c" |
110 | $PROG -f ../localedata/charmaps/$from -t ../localedata/charmaps/$tc \ | |
6fb54a22 | 111 | testdata/$from < /dev/null > $temp1 || |
93693c4d UD |
112 | { if test $? -gt 128; then exit 1; fi |
113 | echo "FAILED"; failed=1; continue; } | |
114 | echo $ac_n "OK$ac_c" | |
115 | if test -s testdata/$from..$t; then | |
82ae2712 | 116 | LC_ALL=C cmp $temp1 testdata/$from..$t > /dev/null 2>&1 || |
93693c4d UD |
117 | { echo "/FAILED"; failed=1; continue; } |
118 | echo $ac_n "/OK$ac_c" | |
119 | fi | |
120 | echo $ac_n " -> $from $ac_c" | |
121 | $PROG -t ../localedata/charmaps/$from -f ../localedata/charmaps/$tc \ | |
6fb54a22 | 122 | -o $temp2 $temp1 < /dev/null || |
93693c4d UD |
123 | { if test $? -gt 128; then exit 1; fi |
124 | echo "FAILED"; failed=1; continue; } | |
125 | echo $ac_n "OK$ac_c" | |
82ae2712 UD |
126 | test -s $temp1 && |
127 | LC_ALL=C cmp testdata/$from $temp2 > /dev/null 2>&1 || | |
93693c4d UD |
128 | { echo "/FAILED"; failed=1; continue; } |
129 | echo "/OK" | |
130 | rm -f $temp1 $temp2 | |
131 | fi | |
3b7caeac UD |
132 | done |
133 | fi | |
134 | ||
c8d49f05 | 135 | if test "$subset" = N; then |
b721a2c0 | 136 | echo $ac_n " suntzu: ASCII -> $to -> ASCII $ac_c" |
6fb54a22 | 137 | $PROG -f ASCII -t $to testdata/suntzus < /dev/null | |
3b7caeac | 138 | $PROG -f $to -t ASCII > $temp1 || |
813bb1f1 | 139 | { if test $? -gt 128; then exit 1; fi |
93693c4d | 140 | echo "FAILED"; failed=1; continue; } |
822078f6 | 141 | echo $ac_n "OK$ac_c" |
82ae2712 | 142 | LC_ALL=C cmp testdata/suntzus $temp1 || |
93693c4d | 143 | { echo "/FAILED"; failed=1; continue; } |
822078f6 | 144 | echo "/OK" |
3b7caeac | 145 | fi |
480bc727 UD |
146 | done < TESTS |
147 | ||
b721a2c0 UD |
148 | # We read the file named TESTS2. All non-empty lines not starting with |
149 | # `#' are interpreted as commands. | |
150 | while read utf8 from filename; do | |
151 | # Ignore empty and comment lines. | |
152 | if test -z "$filename" || test "$utf8" = '#'; then continue; fi | |
153 | ||
154 | # Expand the variables now. | |
155 | PROG=`eval echo $ICONV` | |
156 | ||
157 | # Test conversion to the endianness dependent encoding. | |
158 | echo $ac_n "test encoder: $utf8 -> $from $ac_c" | |
159 | $PROG -f $utf8 -t $from < testdata/${filename}..${utf8} > $temp1 | |
82ae2712 UD |
160 | LC_ALL=C cmp $temp1 testdata/${filename}..${from}.BE > /dev/null 2>&1 || |
161 | LC_ALL=C cmp $temp1 testdata/${filename}..${from}.LE > /dev/null 2>&1 || | |
b721a2c0 UD |
162 | { echo "/FAILED"; failed=1; continue; } |
163 | echo "OK" | |
164 | ||
165 | # Test conversion from the endianness dependent encoding. | |
166 | echo $ac_n "test decoder: $from -> $utf8 $ac_c" | |
167 | $PROG -f $from -t $utf8 < testdata/${filename}..${from}.BE > $temp1 | |
82ae2712 | 168 | LC_ALL=C cmp $temp1 testdata/${filename}..${utf8} > /dev/null 2>&1 || |
b721a2c0 UD |
169 | { echo "/FAILED"; failed=1; continue; } |
170 | $PROG -f $from -t $utf8 < testdata/${filename}..${from}.LE > $temp1 | |
82ae2712 | 171 | LC_ALL=C cmp $temp1 testdata/${filename}..${utf8} > /dev/null 2>&1 || |
b721a2c0 UD |
172 | { echo "/FAILED"; failed=1; continue; } |
173 | echo "OK" | |
174 | ||
175 | # Test byte swapping behaviour. | |
176 | echo $ac_n "test non-BOM: ${from}BE -> ${from}LE $ac_c" | |
177 | $PROG -f ${from}BE -t ${from}LE < testdata/${filename}..${from}.BE > $temp1 | |
82ae2712 | 178 | LC_ALL=C cmp $temp1 testdata/${filename}..${from}.LE > /dev/null 2>&1 || |
b721a2c0 UD |
179 | { echo "/FAILED"; failed=1; continue; } |
180 | echo "OK" | |
181 | ||
182 | # Test byte swapping behaviour. | |
183 | echo $ac_n "test non-BOM: ${from}LE -> ${from}BE $ac_c" | |
184 | $PROG -f ${from}LE -t ${from}BE < testdata/${filename}..${from}.LE > $temp1 | |
82ae2712 | 185 | LC_ALL=C cmp $temp1 testdata/${filename}..${from}.BE > /dev/null 2>&1 || |
b721a2c0 UD |
186 | { echo "/FAILED"; failed=1; continue; } |
187 | echo "OK" | |
188 | ||
189 | done < TESTS2 | |
190 | ||
5aa8ff62 | 191 | exit $failed |
480bc727 UD |
192 | # Local Variables: |
193 | # mode:shell-script | |
194 | # End: |