2 # Copyright (C) 2000-2023 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
6 # The GNU C Library is free software; you can redistribute it and/or
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.
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
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, see
18 # <https://www.gnu.org/licenses/>.
20 # Checks that the iconv() implementation (in both directions) for a
21 # stateless encoding agrees with the charmap table.
25 test_program_prefix
=$3
29 # sort is used on the build system.
36 .
/tst-table-charmap.sh \
37 < ..
/localedata
/charmaps
/${charmap:-$charset} \
38 > ${objpfx}tst-
${charset}.charmap.table
39 # When the charset is GB18030, truncate this table because for this encoding,
40 # the charmap contains ranges (<Unnnn>..<Ummmm> notation), which the
41 # tst-table-charmap.sh script does not grok.
42 if test ${charset} = GB18030
; then
43 grep '0x....$' < ${objpfx}tst-
${charset}.charmap.table \
44 > ${objpfx}tst-
${charset}.truncated.table
45 mv ${objpfx}tst-${charset}.truncated.table ${objpfx}tst-${charset}.charmap.table
48 # Precomputed expected differences between the charmap and iconv forward.
49 precomposed
=${charset}.precomposed
51 # Precompute expected differences between the charmap and iconv backward.
52 if test ${charset} = EUC-TW
; then
53 irreversible
=${objpfx}tst-
${charset}.irreversible
54 (grep '^0x8EA1' ${objpfx}tst-
${charset}.charmap.table
55 cat ${charset}.irreversible
58 irreversible
=${charset}.irreversible
61 # iconv in one direction.
62 ${test_program_prefix} \
63 ${objpfx}tst-table-from
${charset} \
64 > ${objpfx}tst-
${charset}.table
66 # iconv in the other direction.
67 ${test_program_prefix} \
68 ${objpfx}tst-table-to
${charset} |
sort \
69 > ${objpfx}tst-
${charset}.inverse.table
71 # Difference between the charmap and iconv backward.
72 diff ${objpfx}tst-${charset}.charmap.table ${objpfx}tst-${charset}.inverse.table | \
73 grep '^[<>]' |
sed -e 's,^. ,,' > ${objpfx}tst-
${charset}.irreversible.table
75 # Check 1: charmap and iconv forward should be identical, except for
76 # precomposed characters.
77 { if test -f ${precomposed}; then
78 cat ${objpfx}tst-${charset}.table ${precomposed} |
sort |
uniq -u
80 cat ${objpfx}tst-
${charset}.table
82 } |
{ if test ${charset} = GB18030
; then grep '0x....$'; else cat; fi; } \
83 > ${objpfx}tst-
${charset}.tmp1.table
84 cmp -s ${objpfx}tst-${charset}.charmap.table ${objpfx}tst-${charset}.tmp1.table ||
87 # Check 2: the difference between the charmap and iconv backward.
88 { if test -f ${irreversible}; then
89 cat ${objpfx}tst-${charset}.charmap.table ${irreversible} |
sort |
uniq -u
91 cat ${objpfx}tst-
${charset}.charmap.table
93 } |
{ if test ${charset} = GB18030
; then grep '0x....$'; else cat; fi; } \
94 > ${objpfx}tst-
${charset}.tmp2c.table
95 cat ${objpfx}tst-
${charset}.inverse.table \
96 |
{ if test ${charset} = GB18030
; then grep '0x....$'; else cat; fi; } \
97 > ${objpfx}tst-
${charset}.tmp2i.table
98 cmp -s ${objpfx}tst-${charset}.tmp2c.table ${objpfx}tst-${charset}.tmp2i.table ||
101 # Check 3: the difference between iconv forward and iconv backward. This is
102 # necessary only for GB18030, because ${objpfx}tst-${charset}.charmap.table
103 # is truncated for this encoding (see above).
104 if test ${charset} = GB18030
; then
105 { if test -f ${irreversible}; then
106 cat ${objpfx}tst-${charset}.table ${irreversible} |
sort |
uniq -u
108 cat ${objpfx}tst-
${charset}.table
110 } > ${objpfx}tst-
${charset}.tmp3.table
111 cmp -s ${objpfx}tst-${charset}.tmp3.table ${objpfx}tst-${charset}.inverse.table ||