tizen 2.3.1 release
[framework/base/tizen-locale.git] / iconvdata / tst-table.sh
1 #!/bin/sh
2 # Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
4 # Contributed by Bruno Haible <haible@clisp.cons.org>, 2000.
5 #
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, write to the Free
19 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 # 02111-1307 USA.
21
22 # Checks that the iconv() implementation (in both directions) for a
23 # stateless encoding agrees with the charmap table.
24
25 common_objpfx=$1
26 objpfx=$2
27 cross_test_wrapper="$3"
28 charset=$4
29 charmap=$5
30
31 GCONV_PATH=${common_objpfx}iconvdata
32 export GCONV_PATH
33 LC_ALL=C
34 export LC_ALL
35
36 set -e
37
38 # Get the charmap.
39 ${SHELL} tst-table-charmap.sh ${charmap:-$charset} \
40   < ../localedata/charmaps/${charmap:-$charset} \
41   > ${objpfx}tst-${charset}.charmap.table
42 # When the charset is GB18030, truncate this table because for this encoding,
43 # the tst-table-from and tst-table-to programs scan the Unicode BMP only.
44 if test ${charset} = GB18030; then
45   grep '0x....$' < ${objpfx}tst-${charset}.charmap.table \
46     > ${objpfx}tst-${charset}.truncated.table
47   mv ${objpfx}tst-${charset}.truncated.table ${objpfx}tst-${charset}.charmap.table
48 fi
49
50 # Precomputed expexted differences between the charmap and iconv forward.
51 precomposed=${charset}.precomposed
52
53 # Precompute expected differences between the charmap and iconv backward.
54 if test ${charset} = EUC-TW; then
55   irreversible=${objpfx}tst-${charset}.irreversible
56   (grep '^0x8EA1' ${objpfx}tst-${charset}.charmap.table
57    cat ${charset}.irreversible
58   ) > ${irreversible}
59 else
60   irreversible=${charset}.irreversible
61 fi
62
63 # iconv in one direction.
64 ${cross_test_wrapper} ${common_objpfx}elf/ld.so --library-path $common_objpfx \
65 ${objpfx}tst-table-from ${charset} \
66   > ${objpfx}tst-${charset}.table
67
68 # iconv in the other direction.
69 ${cross_test_wrapper} ${common_objpfx}elf/ld.so --library-path $common_objpfx \
70 ${objpfx}tst-table-to ${charset} | sort \
71   > ${objpfx}tst-${charset}.inverse.table
72
73 # Difference between the charmap and iconv backward.
74 diff ${objpfx}tst-${charset}.charmap.table ${objpfx}tst-${charset}.inverse.table | \
75   grep '^[<>]' | sed -e 's,^. ,,' > ${objpfx}tst-${charset}.irreversible.table
76
77 # Check 1: charmap and iconv forward should be identical, except for
78 # precomposed characters.
79 if test -f ${precomposed}; then
80   cat ${objpfx}tst-${charset}.table ${precomposed} | sort | uniq -u \
81     > ${objpfx}tst-${charset}.tmp.table
82   cmp -s ${objpfx}tst-${charset}.charmap.table ${objpfx}tst-${charset}.tmp.table ||
83   exit 1
84 else
85   cmp -s ${objpfx}tst-${charset}.charmap.table ${objpfx}tst-${charset}.table ||
86   exit 1
87 fi
88
89 # Check 2: the difference between the charmap and iconv backward.
90 if test -f ${irreversible}; then
91   cat ${objpfx}tst-${charset}.charmap.table ${irreversible} | sort | uniq -u \
92     > ${objpfx}tst-${charset}.tmp.table
93   cmp -s ${objpfx}tst-${charset}.tmp.table ${objpfx}tst-${charset}.inverse.table ||
94   exit 1
95 else
96   cmp -s ${objpfx}tst-${charset}.charmap.table ${objpfx}tst-${charset}.inverse.table ||
97   exit 1
98 fi
99
100 exit 0