#! /bin/sh

# Test that on glibc systems, gettext() in multithreaded applications works
# correctly if different threads operate in different locales with the same
# encoding.

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

# This test works only on glibc systems.
grep '@GLIBC2@.*yes' ../config.status >/dev/null || {
  echo "Skipping test: not a glibc system"
  exit 77
}

# This test works only on systems that have a de_DE and fr_FR locale installed.
LC_ALL=de_DE ./testlocale || {
  if test -f /usr/bin/localedef; then
    echo "Skipping test: locale de_DE not installed"
  else
    echo "Skipping test: locale de_DE not supported"
  fi
  exit 77
}
LC_ALL=fr_FR ./testlocale || {
  if test -f /usr/bin/localedef; then
    echo "Skipping test: locale fr_FR not installed"
  else
    echo "Skipping test: locale fr_FR not supported"
  fi
  exit 77
}

tmpfiles="$tmpfiles de_DE fr_FR"
test -d de_DE || mkdir de_DE
test -d de_DE/LC_MESSAGES || mkdir de_DE/LC_MESSAGES
test -d fr_FR || mkdir fr_FR
test -d fr_FR/LC_MESSAGES || mkdir fr_FR/LC_MESSAGES

: ${MSGFMT=msgfmt}
${MSGFMT} -o de_DE/LC_MESSAGES/tstthread.mo ${top_srcdir}/tests/gettext-6-1.po
${MSGFMT} -o fr_FR/LC_MESSAGES/tstthread.mo ${top_srcdir}/tests/gettext-6-2.po

tmpfiles="$tmpfiles gt-6.ok"
cat <<EOF > gt-6.ok
Schönheit
beauté
Schönheit
beauté
EOF

tmpfiles="$tmpfiles gt-6.out"
./gettext-6-prg > gt-6.out
case $? in
  0) ;;
  77)
    echo "Skipping test: not a glibc 2.3 system"
    rm -fr $tmpfiles; exit 77
    ;;
esac

: ${DIFF=diff}
${DIFF} gt-6.ok gt-6.out || exit 1

rm -fr $tmpfiles

exit 0
