#! /bin/sh

# Test that bind_textdomain_codeset() works.

tmpfiles=""
trap 'rm -fr $tmpfiles' 1 2 3 15

: ${LOCALE_FR=fr_FR}
: ${MSGFMT=../src/msgfmt}
: ${srcdir=.}

errfail () { echo "$@" >&2; exit 1; }

# This test works only on systems that have a traditional french locale
# installed.
# gettext-4.po is actually a German PO file, but only the encoding of the
# locale matters, not the language. configure has already checked whether
# a traditional french locale is installed; no need to check also for a
# traditional german locale.
{ test $LOCALE_FR != none && LC_ALL=$LOCALE_FR ./testlocale; } || {
  if test -f /usr/bin/localedef; then
    echo "Skipping test: no traditional french locale is installed"
  else
    echo "Skipping test: no traditional french locale is supported"
  fi
  exit 77
}

tmpfiles="$tmpfiles gt-4"
test -d gt-4 || mkdir gt-4
test -d gt-4/fr || mkdir gt-4/fr
test -d gt-4/fr/LC_MESSAGES || mkdir gt-4/fr/LC_MESSAGES

${MSGFMT} -o gt-4/fr/LC_MESSAGES/codeset.mo ${srcdir}/gettext-4.po || exit 1

./gettext-4-prg${EXEEXT} $LOCALE_FR || errfail "gettext-4-prg exited with status $?"

rm -fr $tmpfiles

exit 0
