]>
Commit | Line | Data |
---|---|---|
b79f74cd | 1 | #!/bin/sh |
2b778ceb | 2 | # Copyright (C) 2000-2021 Free Software Foundation, Inc. |
b79f74cd | 3 | # This file is part of the GNU C Library. |
b79f74cd | 4 | # |
41bdb6e2 | 5 | |
b79f74cd | 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 | ||
b79f74cd 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/>. |
b79f74cd UD |
19 | |
20 | # Checks that the iconv() implementation (in both directions) for a | |
21 | # stateless encoding agrees with the charmap table. | |
22 | ||
23 | common_objpfx=$1 | |
24 | objpfx=$2 | |
740b3dbe | 25 | test_program_prefix=$3 |
e40a0d21 JM |
26 | charset=$4 |
27 | charmap=$5 | |
b79f74cd | 28 | |
8540f6d2 | 29 | # sort is used on the build system. |
b79f74cd UD |
30 | LC_ALL=C |
31 | export LC_ALL | |
32 | ||
33 | set -e | |
34 | ||
35 | # Get the charmap. | |
54399c08 | 36 | ./tst-table-charmap.sh ${charmap:-$charset} \ |
b79f74cd UD |
37 | < ../localedata/charmaps/${charmap:-$charset} \ |
38 | > ${objpfx}tst-${charset}.charmap.table | |
be479a6d UD |
39 | # When the charset is GB18030, truncate this table because for this encoding, |
40 | # the tst-table-from and tst-table-to programs scan the Unicode BMP only. | |
41 | if test ${charset} = GB18030; then | |
42 | grep '0x....$' < ${objpfx}tst-${charset}.charmap.table \ | |
43 | > ${objpfx}tst-${charset}.truncated.table | |
44 | mv ${objpfx}tst-${charset}.truncated.table ${objpfx}tst-${charset}.charmap.table | |
45 | fi | |
b79f74cd | 46 | |
9813858f UD |
47 | # Precomputed expexted differences between the charmap and iconv forward. |
48 | precomposed=${charset}.precomposed | |
49 | ||
50 | # Precompute expected differences between the charmap and iconv backward. | |
b79f74cd UD |
51 | if test ${charset} = EUC-TW; then |
52 | irreversible=${objpfx}tst-${charset}.irreversible | |
289ac9dd UD |
53 | (grep '^0x8EA1' ${objpfx}tst-${charset}.charmap.table |
54 | cat ${charset}.irreversible | |
55 | ) > ${irreversible} | |
b79f74cd UD |
56 | else |
57 | irreversible=${charset}.irreversible | |
58 | fi | |
59 | ||
60 | # iconv in one direction. | |
740b3dbe | 61 | ${test_program_prefix} \ |
b79f74cd UD |
62 | ${objpfx}tst-table-from ${charset} \ |
63 | > ${objpfx}tst-${charset}.table | |
64 | ||
65 | # iconv in the other direction. | |
740b3dbe | 66 | ${test_program_prefix} \ |
b79f74cd UD |
67 | ${objpfx}tst-table-to ${charset} | sort \ |
68 | > ${objpfx}tst-${charset}.inverse.table | |
69 | ||
9813858f UD |
70 | # Difference between the charmap and iconv backward. |
71 | diff ${objpfx}tst-${charset}.charmap.table ${objpfx}tst-${charset}.inverse.table | \ | |
b79f74cd UD |
72 | grep '^[<>]' | sed -e 's,^. ,,' > ${objpfx}tst-${charset}.irreversible.table |
73 | ||
9813858f UD |
74 | # Check 1: charmap and iconv forward should be identical, except for |
75 | # precomposed characters. | |
be479a6d UD |
76 | if test -f ${precomposed}; then |
77 | cat ${objpfx}tst-${charset}.table ${precomposed} | sort | uniq -u \ | |
78 | > ${objpfx}tst-${charset}.tmp.table | |
79 | cmp -s ${objpfx}tst-${charset}.charmap.table ${objpfx}tst-${charset}.tmp.table || | |
601d2942 UD |
80 | exit 1 |
81 | else | |
be479a6d UD |
82 | cmp -s ${objpfx}tst-${charset}.charmap.table ${objpfx}tst-${charset}.table || |
83 | exit 1 | |
601d2942 | 84 | fi |
b79f74cd | 85 | |
9813858f | 86 | # Check 2: the difference between the charmap and iconv backward. |
b79f74cd UD |
87 | if test -f ${irreversible}; then |
88 | cat ${objpfx}tst-${charset}.charmap.table ${irreversible} | sort | uniq -u \ | |
89 | > ${objpfx}tst-${charset}.tmp.table | |
63e18f77 UD |
90 | cmp -s ${objpfx}tst-${charset}.tmp.table ${objpfx}tst-${charset}.inverse.table || |
91 | exit 1 | |
b79f74cd | 92 | else |
9813858f | 93 | cmp -s ${objpfx}tst-${charset}.charmap.table ${objpfx}tst-${charset}.inverse.table || |
63e18f77 | 94 | exit 1 |
b79f74cd UD |
95 | fi |
96 | ||
97 | exit 0 |