Update.
[glibc.git] / iconvdata / tst-table.sh
blobfb427034eb1f573aca14211ee014006ecb396b97
1 #!/bin/sh
2 # Copyright (C) 2000, 2001 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
4 # Contributed by Bruno Haible <haible@clisp.cons.org>, 2000.
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.
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.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with the GNU C Library; if not, write to the Free
19 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 # 02111-1307 USA.
22 # Checks that the iconv() implementation (in both directions) for a
23 # stateless encoding agrees with the charmap table.
25 common_objpfx=$1
26 objpfx=$2
27 charset=$3
28 charmap=$4
30 GCONV_PATH=${common_objpfx}iconvdata
31 export GCONV_PATH
32 LC_ALL=C
33 export LC_ALL
35 set -e
37 # Get the charmap.
38 ${SHELL} tst-table-charmap.sh ${charmap:-$charset} \
39 < ../localedata/charmaps/${charmap:-$charset} \
40 > ${objpfx}tst-${charset}.charmap.table
42 # Precompute expected differences between the two iconv directions.
43 if test ${charset} = EUC-TW; then
44 irreversible=${objpfx}tst-${charset}.irreversible
45 (grep '^0x8EA1' ${objpfx}tst-${charset}.charmap.table
46 cat ${charset}.irreversible
47 ) > ${irreversible}
48 else
49 irreversible=${charset}.irreversible
52 # iconv in one direction.
53 ${common_objpfx}elf/ld.so --library-path $common_objpfx \
54 ${objpfx}tst-table-from ${charset} \
55 > ${objpfx}tst-${charset}.table
57 # iconv in the other direction.
58 ${common_objpfx}elf/ld.so --library-path $common_objpfx \
59 ${objpfx}tst-table-to ${charset} | sort \
60 > ${objpfx}tst-${charset}.inverse.table
62 # Difference between the two iconv directions.
63 diff ${objpfx}tst-${charset}.table ${objpfx}tst-${charset}.inverse.table | \
64 grep '^[<>]' | sed -e 's,^. ,,' > ${objpfx}tst-${charset}.irreversible.table
66 # Check 1: charmap and iconv forward should be identical.
67 if test ${charset} = GB18030; then
68 grep '0x....$' < ${objpfx}tst-${charset}.charmap.table \
69 > ${objpfx}tst-${charset}.truncated.table
70 cmp -s ${objpfx}tst-${charset}.truncated.table ${objpfx}tst-${charset}.table ||
71 exit 1
72 else
73 cmp -s ${objpfx}tst-${charset}.charmap.table ${objpfx}tst-${charset}.table ||
74 exit 1
77 # Check 2: the difference between the two iconv directions.
78 if test -f ${irreversible}; then
79 cat ${objpfx}tst-${charset}.charmap.table ${irreversible} | sort | uniq -u \
80 > ${objpfx}tst-${charset}.tmp.table
81 cmp -s ${objpfx}tst-${charset}.tmp.table ${objpfx}tst-${charset}.inverse.table ||
82 exit 1
83 else
84 cmp -s ${objpfx}tst-${charset}.table ${objpfx}tst-${charset}.inverse.table ||
85 exit 1
88 exit 0