]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Test that on glibc systems, gettext() works right even with intermediate
authorBruno Haible <bruno@clisp.org>
Fri, 29 Apr 2005 17:42:01 +0000 (17:42 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:12:31 +0000 (12:12 +0200)
setlocale() calls.

gettext-tools/tests/gettext-3 [new file with mode: 0755]
gettext-tools/tests/gettext-3-1.po [new file with mode: 0644]
gettext-tools/tests/gettext-3-2.po [new file with mode: 0644]
gettext-tools/tests/gettext-3-prg.c [new file with mode: 0644]

diff --git a/gettext-tools/tests/gettext-3 b/gettext-tools/tests/gettext-3
new file mode 100755 (executable)
index 0000000..b45f5ce
--- /dev/null
@@ -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 <<EOF > 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 (file)
index 0000000..c411ce1
--- /dev/null
@@ -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 (file)
index 0000000..d1606c8
--- /dev/null
@@ -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 (file)
index 0000000..6fa68df
--- /dev/null
@@ -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 <kukuk@suse.de> and Andreas Jaeger <aj@suse.de>, 2000.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <locale.h>
+#include <stdlib.h>
+#include <stdio.h>
+#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;
+}