This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

add a new gettext() test


Hi,

Here is a new test for gettext(). It tests that the gettext() results come
out in the correct encoding for locales that differ only in their encoding.

The test fails. Please add it to libc only when you are ready to take the
fix, from my next mail.

Bruno


2005-03-27  Bruno Haible  <bruno@clisp.org>

	* intl/tst-gettext3.c: New file.
	* intl/tst-gettext3.sh: New file.
	* intl/Makefile (distribute): Add tst-gettext3.sh.
	(test-srcs): Add tst-gettext3.
	(tests): Depend on tst-gettext3.out.
	(tst-gettext3.out): New rule.
	(CFLAGS-tst-gettext3.c): New variable.

--- /dev/null	Tue Sep 23 19:59:22 2003
+++ glibc-20050322/intl/tst-gettext3.c	Sun Mar 27 23:32:02 2005
@@ -0,0 +1,60 @@
+/* Test that the gettext() results come out in the correct encoding for
+   locales that differ only in their encoding.
+   Copyright (C) 2001, 2005 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Bruno Haible <bruno@clisp.org>, 2001, 2005.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <libintl.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int
+main (void)
+{
+  char *s;
+  int result = 0;
+
+  unsetenv ("LANGUAGE");
+  unsetenv ("OUTPUT_CHARSET");
+  textdomain ("codeset");
+  bindtextdomain ("codeset", OBJPFX "domaindir");
+
+  setlocale (LC_ALL, "de_DE.ISO-8859-1");
+
+  /* Here we expect output in ISO-8859-1.  */
+  s = gettext ("cheese");
+  if (strcmp (s, "K\344se"))
+    {
+      printf ("call 1 returned: %s\n", s);
+      result = 1;
+    }
+
+  setlocale (LC_ALL, "de_DE.UTF-8");
+
+  /* Here we expect output in UTF-8.  */
+  s = gettext ("cheese");
+  if (strcmp (s, "K\303\244se"))
+    {
+      printf ("call 2 returned: %s\n", s);
+      result = 1;
+    }
+
+  return result;
+}
--- /dev/null	Tue Sep 23 19:59:22 2003
+++ glibc-20050322/intl/tst-gettext3.sh	Sun Mar 27 23:33:15 2005
@@ -0,0 +1,45 @@
+#! /bin/sh
+# Test that the gettext() results come out in the correct encoding for
+# locales that differ only in their encoding.
+# Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+#
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library 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
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, write to the Free
+# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307 USA.
+
+common_objpfx=$1
+objpfx=$2
+
+LC_ALL=C
+export LC_ALL
+
+# Generate the test data.
+test -d ${objpfx}domaindir || mkdir ${objpfx}domaindir
+# Create the domain directories.
+test -d ${objpfx}domaindir/de_DE || mkdir ${objpfx}domaindir/de_DE
+test -d ${objpfx}domaindir/de_DE/LC_MESSAGES || mkdir ${objpfx}domaindir/de_DE/LC_MESSAGES
+# Populate them.
+msgfmt -o ${objpfx}domaindir/de_DE/LC_MESSAGES/codeset.mo tstcodeset.po
+
+GCONV_PATH=${common_objpfx}iconvdata
+export GCONV_PATH
+LOCPATH=${common_objpfx}localedata
+export LOCPATH
+
+${common_objpfx}elf/ld.so --library-path $common_objpfx \
+${objpfx}tst-gettext3 > ${objpfx}tst-gettext3.out
+
+exit $?
--- glibc-20050322/intl/Makefile.bak	Thu Jul  3 21:39:47 2003
+++ glibc-20050322/intl/Makefile	Sun Mar 27 23:27:02 2005
@@ -1,4 +1,4 @@
-# Copyright (C) 1995-2002, 2003 Free Software Foundation, Inc.
+# Copyright (C) 1995-2003, 2005 Free Software Foundation, Inc.
 # This file is part of the GNU C Library.
 
 # The GNU C Library is free software; you can redistribute it and/or
@@ -25,11 +25,14 @@
 	   finddomain loadmsgcat localealias textdomain
 aux =	   l10nflist explodename plural plural-exp hash-string
 distribute = gmo.h gettextP.h hash-string.h loadinfo.h locale.alias \
-	     plural.y plural-exp.h po2test.sed tst-gettext.sh tst-translit.sh \
-	     translit.po tst-gettext2.sh tstlang1.po tstlang2.po tstcodeset.po\
-	     tst-codeset.sh plural-eval.c
+	     plural.y plural-exp.h plural-eval.c po2test.sed \
+	     tst-gettext.sh \
+	     tst-translit.sh translit.po \
+	     tst-gettext2.sh tstlang1.po tstlang2.po \
+	     tst-codeset.sh tstcodeset.po \
+	     tst-gettext3.sh
 
-test-srcs := tst-gettext tst-translit tst-gettext2 tst-codeset
+test-srcs := tst-gettext tst-translit tst-gettext2 tst-codeset tst-gettext3
 tests = tst-ngettext
 
 before-compile = $(objpfx)msgs.h
@@ -56,7 +59,7 @@
 ifeq (yes,$(build-shared))
 ifneq ($(strip $(MSGFMT)),:)
 tests: $(objpfx)tst-translit.out $(objpfx)tst-gettext2.out \
-       $(objpfx)tst-codeset.out
+       $(objpfx)tst-codeset.out $(objpfx)tst-gettext3.out
 ifneq (no,$(PERL))
 tests: $(objpfx)mtrace-tst-gettext
 endif
@@ -72,6 +75,8 @@
 	$(SHELL) -e $< $(common-objpfx) $(common-objpfx)intl/
 $(objpfx)tst-codeset.out: tst-codeset.sh $(objpfx)tst-codeset
 	$(SHELL) -e $< $(common-objpfx) $(common-objpfx)intl/
+$(objpfx)tst-gettext3.out: tst-gettext3.sh $(objpfx)tst-gettext3
+	$(SHELL) -e $< $(common-objpfx) $(common-objpfx)intl/
 endif
 endif
 
@@ -80,13 +85,15 @@
 	LC_ALL=C sed -f $^ > $@
 
 CFLAGS-tst-gettext.c = -DTESTSTRS_H=\"$(objpfx)msgs.h\"
-CFLAGS-tst-gettext2.c = -DOBJPFX=\"$(objpfx)\"
 CFLAGS-tst-translit.c = -DOBJPFX=\"$(objpfx)\"
+CFLAGS-tst-gettext2.c = -DOBJPFX=\"$(objpfx)\"
 CFLAGS-tst-codeset.c = -DOBJPFX=\"$(objpfx)\"
+CFLAGS-tst-gettext3.c = -DOBJPFX=\"$(objpfx)\"
 
 $(objpfx)tst-translit.out: $(objpfx)tst-gettext.out
 $(objpfx)tst-gettext2.out: $(objpfx)tst-gettext.out
 $(objpfx)tst-codeset.out: $(objpfx)tst-gettext.out
+$(objpfx)tst-gettext3.out: $(objpfx)tst-gettext.out
 
 CPPFLAGS += -D'LOCALEDIR="$(msgcatdir)"' \
 	    -D'LOCALE_ALIAS_PATH="$(msgcatdir)"'


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]