Blame iconvdata/tst-table.sh

Packit 6c4009
#!/bin/sh
Packit 6c4009
# Copyright (C) 2000-2018 Free Software Foundation, Inc.
Packit 6c4009
# This file is part of the GNU C Library.
Packit 6c4009
# Contributed by Bruno Haible <haible@clisp.cons.org>, 2000.
Packit 6c4009
#
Packit 6c4009
Packit 6c4009
# The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
# modify it under the terms of the GNU Lesser General Public
Packit 6c4009
# License as published by the Free Software Foundation; either
Packit 6c4009
# version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
# The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
# Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
# You should have received a copy of the GNU Lesser General Public
Packit 6c4009
# License along with the GNU C Library; if not, see
Packit 6c4009
# <http://www.gnu.org/licenses/>.
Packit 6c4009
Packit 6c4009
# Checks that the iconv() implementation (in both directions) for a
Packit 6c4009
# stateless encoding agrees with the charmap table.
Packit 6c4009
Packit 6c4009
common_objpfx=$1
Packit 6c4009
objpfx=$2
Packit 6c4009
test_program_prefix=$3
Packit 6c4009
charset=$4
Packit 6c4009
charmap=$5
Packit 6c4009
Packit 6c4009
# sort is used on the build system.
Packit 6c4009
LC_ALL=C
Packit 6c4009
export LC_ALL
Packit 6c4009
Packit 6c4009
set -e
Packit 6c4009
Packit 6c4009
# Get the charmap.
Packit 6c4009
./tst-table-charmap.sh ${charmap:-$charset} \
Packit 6c4009
  < ../localedata/charmaps/${charmap:-$charset} \
Packit 6c4009
  > ${objpfx}tst-${charset}.charmap.table
Packit 6c4009
# When the charset is GB18030, truncate this table because for this encoding,
Packit 6c4009
# the tst-table-from and tst-table-to programs scan the Unicode BMP only.
Packit 6c4009
if test ${charset} = GB18030; then
Packit 6c4009
  grep '0x....$' < ${objpfx}tst-${charset}.charmap.table \
Packit 6c4009
    > ${objpfx}tst-${charset}.truncated.table
Packit 6c4009
  mv ${objpfx}tst-${charset}.truncated.table ${objpfx}tst-${charset}.charmap.table
Packit 6c4009
fi
Packit 6c4009
Packit 6c4009
# Precomputed expexted differences between the charmap and iconv forward.
Packit 6c4009
precomposed=${charset}.precomposed
Packit 6c4009
Packit 6c4009
# Precompute expected differences between the charmap and iconv backward.
Packit 6c4009
if test ${charset} = EUC-TW; then
Packit 6c4009
  irreversible=${objpfx}tst-${charset}.irreversible
Packit 6c4009
  (grep '^0x8EA1' ${objpfx}tst-${charset}.charmap.table
Packit 6c4009
   cat ${charset}.irreversible
Packit 6c4009
  ) > ${irreversible}
Packit 6c4009
else
Packit 6c4009
  irreversible=${charset}.irreversible
Packit 6c4009
fi
Packit 6c4009
Packit 6c4009
# iconv in one direction.
Packit 6c4009
${test_program_prefix} \
Packit 6c4009
${objpfx}tst-table-from ${charset} \
Packit 6c4009
  > ${objpfx}tst-${charset}.table
Packit 6c4009
Packit 6c4009
# iconv in the other direction.
Packit 6c4009
${test_program_prefix} \
Packit 6c4009
${objpfx}tst-table-to ${charset} | sort \
Packit 6c4009
  > ${objpfx}tst-${charset}.inverse.table
Packit 6c4009
Packit 6c4009
# Difference between the charmap and iconv backward.
Packit 6c4009
diff ${objpfx}tst-${charset}.charmap.table ${objpfx}tst-${charset}.inverse.table | \
Packit 6c4009
  grep '^[<>]' | sed -e 's,^. ,,' > ${objpfx}tst-${charset}.irreversible.table
Packit 6c4009
Packit 6c4009
# Check 1: charmap and iconv forward should be identical, except for
Packit 6c4009
# precomposed characters.
Packit 6c4009
if test -f ${precomposed}; then
Packit 6c4009
  cat ${objpfx}tst-${charset}.table ${precomposed} | sort | uniq -u \
Packit 6c4009
    > ${objpfx}tst-${charset}.tmp.table
Packit 6c4009
  cmp -s ${objpfx}tst-${charset}.charmap.table ${objpfx}tst-${charset}.tmp.table ||
Packit 6c4009
  exit 1
Packit 6c4009
else
Packit 6c4009
  cmp -s ${objpfx}tst-${charset}.charmap.table ${objpfx}tst-${charset}.table ||
Packit 6c4009
  exit 1
Packit 6c4009
fi
Packit 6c4009
Packit 6c4009
# Check 2: the difference between the charmap and iconv backward.
Packit 6c4009
if test -f ${irreversible}; then
Packit 6c4009
  cat ${objpfx}tst-${charset}.charmap.table ${irreversible} | sort | uniq -u \
Packit 6c4009
    > ${objpfx}tst-${charset}.tmp.table
Packit 6c4009
  cmp -s ${objpfx}tst-${charset}.tmp.table ${objpfx}tst-${charset}.inverse.table ||
Packit 6c4009
  exit 1
Packit 6c4009
else
Packit 6c4009
  cmp -s ${objpfx}tst-${charset}.charmap.table ${objpfx}tst-${charset}.inverse.table ||
Packit 6c4009
  exit 1
Packit 6c4009
fi
Packit 6c4009
Packit 6c4009
exit 0