From: Bruno Haible Date: Fri, 29 Apr 2005 17:42:01 +0000 (+0000) Subject: Test that on glibc systems, gettext() works right even with intermediate X-Git-Tag: v0.15~550 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a11457526f4aa6a0d51b2a910301fcda23da178f;p=thirdparty%2Fgettext.git Test that on glibc systems, gettext() works right even with intermediate setlocale() calls. --- diff --git a/gettext-tools/tests/gettext-3 b/gettext-tools/tests/gettext-3 new file mode 100755 index 000000000..b45f5cecd --- /dev/null +++ b/gettext-tools/tests/gettext-3 @@ -0,0 +1,44 @@ +#! /bin/sh + +# Test that on glibc systems, gettext() works right even with intermediate +# setlocale() calls. + +tmpfiles="" +trap 'rm -fr $tmpfiles' 1 2 3 15 + +# This test works only on glibc systems. +grep '@GLIBC2@.*yes' ../config.status >/dev/null || exit 77 + +# This test works only on systems that have a de_DE and fr_FR locale installed. +LC_ALL=de_DE ./testlocale || exit 77 +LC_ALL=fr_FR ./testlocale || 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/tstlang.mo ${top_srcdir}/tests/gettext-3-1.po +${MSGFMT} -o fr_FR/LC_MESSAGES/tstlang.mo ${top_srcdir}/tests/gettext-3-2.po + +tmpfiles="$tmpfiles gt-3.ok" +cat < gt-3.ok +String1 - Lang1: 1st string +String2 - Lang1: 2nd string +String1 - Lang2: 1st string +String2 - Lang2: 2nd string +String1 - First string for testing. +String2 - Another string for testing. +EOF + +tmpfiles="$tmpfiles gt-3.out" +./gettext-3-prg > gt-3.out || exit 1 + +: ${DIFF=diff} +${DIFF} gt-3.ok gt-3.out || exit 1 + +rm -fr $tmpfiles + +exit 0 diff --git a/gettext-tools/tests/gettext-3-1.po b/gettext-tools/tests/gettext-3-1.po new file mode 100644 index 000000000..c411ce116 --- /dev/null +++ b/gettext-tools/tests/gettext-3-1.po @@ -0,0 +1,13 @@ +msgid "" +msgstr "" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=US-ASCII\n" +"Content-Transfer-Encoding: 7-bit\n" + +#: tst-gettext2.c:33 +msgid "First string for testing." +msgstr "Lang1: 1st string" + +#: tst-gettext2.c:34 +msgid "Another string for testing." +msgstr "Lang1: 2nd string" diff --git a/gettext-tools/tests/gettext-3-2.po b/gettext-tools/tests/gettext-3-2.po new file mode 100644 index 000000000..d1606c8ed --- /dev/null +++ b/gettext-tools/tests/gettext-3-2.po @@ -0,0 +1,13 @@ +msgid "" +msgstr "" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=US-ASCII\n" +"Content-Transfer-Encoding: 7-bit\n" + +#: tst-gettext2.c:33 +msgid "First string for testing." +msgstr "Lang2: 1st string" + +#: tst-gettext2.c:34 +msgid "Another string for testing." +msgstr "Lang2: 2nd string" diff --git a/gettext-tools/tests/gettext-3-prg.c b/gettext-tools/tests/gettext-3-prg.c new file mode 100644 index 000000000..6fa68df40 --- /dev/null +++ b/gettext-tools/tests/gettext-3-prg.c @@ -0,0 +1,82 @@ +/* Test program, used by the gettext-3 test. + Copyright (C) 2000, 2005 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* Contributed to the GNU C Library by + Thorsten Kukuk and Andreas Jaeger , 2000. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include "setenv.h" + +/* Make sure we use the included libintl, not the system's one. */ +#undef _LIBINTL_H +#include "libgnuintl.h" + +#define N_(string) string + +struct data_t +{ + const char *selection; + const char *description; +}; + +struct data_t strings[] = +{ + { "String1", N_("First string for testing.") }, + { "String2", N_("Another string for testing.") } +}; +const int data_cnt = sizeof (strings) / sizeof (strings[0]); + +const char *lang[] = { "de_DE", "fr_FR", "ll_CC" }; +const int lang_cnt = sizeof (lang) / sizeof (lang[0]); + +int +main (void) +{ + int i; + + /* Clean up environment. */ + unsetenv ("LANGUAGE"); + unsetenv ("LC_ALL"); + unsetenv ("LC_MESSAGES"); + unsetenv ("LC_CTYPE"); + unsetenv ("LANG"); + unsetenv ("OUTPUT_CHARSET"); + + textdomain ("tstlang"); + + for (i = 0; i < lang_cnt; ++i) + { + int j; + + if (setlocale (LC_ALL, lang[i]) == NULL) + setlocale (LC_ALL, "C"); + + bindtextdomain ("tstlang", "."); + + for (j = 0; j < data_cnt; ++j) + printf ("%s - %s\n", strings[j].selection, + gettext (strings[j].description)); + } + + return 0; +}