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]

tests for *gettext_l() functions


According to the principle that functionality that is not covered by a test
suffers from bitrot over time, here is a test for the dgettext_l() function.

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

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

--- /dev/null	2003-09-23 19:59:22.000000000 +0200
+++ glibc-20050322/intl/tst-gettext_l.c	2005-03-28 22:33:33.000000000 +0200
@@ -0,0 +1,59 @@
+/* Test the dgettext_l() function.
+   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)
+{
+  const char *s;
+  int result = 0;
+  locale_t loc1, loc2;
+
+  unsetenv ("LANGUAGE");
+  unsetenv ("OUTPUT_CHARSET");
+  textdomain ("codeset");
+  bindtextdomain ("codeset", OBJPFX "domaindir");
+
+  loc1 = newlocale (LC_ALL_MASK, "de_DE.ISO-8859-1", NULL);
+  loc2 = newlocale (LC_ALL_MASK, "de_DE.UTF-8", NULL);
+
+  /* Here we expect output in ISO-8859-1.  */
+  s = dgettext_l ("codeset", "cheese", loc1);
+  if (strcmp (s, "K\344se"))
+    {
+      printf ("call 1 returned: %s\n", s);
+      result = 1;
+    }
+
+  /* Here we expect output in UTF-8.  */
+  s = dgettext_l ("codeset", "cheese", loc2);
+  if (strcmp (s, "K\303\244se"))
+    {
+      printf ("call 2 returned: %s\n", s);
+      result = 1;
+    }
+
+  return result;
+}
--- /dev/null	2003-09-23 19:59:22.000000000 +0200
+++ glibc-20050322/intl/tst-gettext_l.sh	2005-03-28 22:31:17.000000000 +0200
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Test the dgettext_l() function.
+# 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-gettext_l > ${objpfx}tst-gettext_l.out
+
+exit $?
--- glibc-20050322/intl/Makefile.bak4	2005-03-28 16:49:36.000000000 +0200
+++ glibc-20050322/intl/Makefile	2005-03-28 22:35:48.000000000 +0200
@@ -32,7 +32,8 @@
 	     tst-codeset.sh tstcodeset.po \
 	     tst-gettext3.sh \
 	     tst-gettext4.sh tst-gettext4-de.po tst-gettext4-fr.po \
-	     tst-gettext5.sh
+	     tst-gettext5.sh \
+	     tst-gettext_l.sh
 
 include ../Makeconfig
 
@@ -41,6 +42,7 @@
 ifeq ($(have-thread-library),yes)
 test-srcs += $(multithread-test-srcs)
 endif
+test-srcs += tst-gettext_l
 tests = tst-ngettext
 
 before-compile = $(objpfx)msgs.h
@@ -69,6 +71,7 @@
 ifeq ($(have-thread-library),yes)
 tests: $(objpfx)tst-gettext4.out $(objpfx)tst-gettext5.out
 endif
+tests: $(objpfx)tst-gettext_l.out
 ifneq (no,$(PERL))
 tests: $(objpfx)mtrace-tst-gettext
 endif
@@ -90,6 +93,8 @@
 	$(SHELL) -e $< $(common-objpfx) $(common-objpfx)intl/
 $(objpfx)tst-gettext5.out: tst-gettext5.sh $(objpfx)tst-gettext5
 	$(SHELL) -e $< $(common-objpfx) $(common-objpfx)intl/
+$(objpfx)tst-gettext_l.out: tst-gettext_l.sh $(objpfx)tst-gettext_l
+	$(SHELL) -e $< $(common-objpfx) $(common-objpfx)intl/
 endif
 endif
 
@@ -104,6 +109,7 @@
 CFLAGS-tst-gettext3.c = -DOBJPFX=\"$(objpfx)\"
 CFLAGS-tst-gettext4.c = -DOBJPFX=\"$(objpfx)\"
 CFLAGS-tst-gettext5.c = -DOBJPFX=\"$(objpfx)\"
+CFLAGS-tst-gettext_l.c = -DOBJPFX=\"$(objpfx)\"
 
 ifeq ($(have-thread-library),yes)
 ifeq (yes,$(build-shared))
@@ -122,6 +128,7 @@
 $(objpfx)tst-gettext3.out: $(objpfx)tst-gettext.out
 $(objpfx)tst-gettext4.out: $(objpfx)tst-gettext.out
 $(objpfx)tst-gettext5.out: $(objpfx)tst-gettext.out
+$(objpfx)tst-gettext_l.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]