summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2001-01-23 17:25:58 +0000
committerBruno Haible <bruno@clisp.org>2001-01-23 17:25:58 +0000
commitc044fae28a9d8bf34b5671fa4a359656a1fe5767 (patch)
treede150648d99ef04cfc23924524ce0e67e7569f5d /tests
parent66465dca1a55e2082adb562f2925bd02cb5180e4 (diff)
downloadexternal_gettext-c044fae28a9d8bf34b5671fa4a359656a1fe5767.zip
external_gettext-c044fae28a9d8bf34b5671fa4a359656a1fe5767.tar.gz
external_gettext-c044fae28a9d8bf34b5671fa4a359656a1fe5767.tar.bz2
Rename src/gettextp.c to src/gettext.c, and
move src/setlocale.c to tests/setlocale.c.
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog14
-rw-r--r--tests/Makefile.am25
-rw-r--r--tests/setlocale.c167
-rw-r--r--tests/tstgettext.c3
-rwxr-xr-xtests/xgettext-12
5 files changed, 199 insertions, 12 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 4f24852..64b790f 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,19 @@
2001-01-07 Bruno Haible <haible@clisp.cons.org>
+ * setlocale.c: New file, moved here from ../src.
+ * tstgettext.c: New file.
+ * Makefile.am (TESTS_ENVIRONMENT): Add "." to the PATH.
+ (xg-test1.ok.po): Use src/gettext.c instead of src/gettextp.c.
+ (INCLUDES): Add more dirs.
+ (DEFS): Add defines needed for gettext.c.
+ (LDADD): New variable.
+ (EXTRA_PROGRAMS, all-local, CLEANFILES): Add tstgettext.
+ (tstgettext_SOURCES, tstgettext_LDADD): New variable.
+ (cake_SOURCES): Update.
+ * xgettext-1: Use src/gettext.c instead of src/gettextp.c.
+
+2001-01-07 Bruno Haible <haible@clisp.cons.org>
+
* plural-1-prg.c: Include libgnuintl.h instead of libgettext.h.
2001-01-07 Bruno Haible <haible@clisp.cons.org>
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a7f7d5c..742bf29 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -28,7 +28,7 @@ EXTRA_DIST = $(TESTS) test.mo xg-test1.ok.po
XGETTEXT = ../src/xgettext
-TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir) PATH=../src:$$PATH \
+TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir) PATH=.:../src:$$PATH \
GETTEXT=tstgettext \
XGETTEXT=`echo xgettext|sed '$(transform)'` \
MSGFMT=`echo msgfmt|sed '$(transform)'` \
@@ -38,15 +38,18 @@ TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir) PATH=../src:$$PATH \
$(SHELL)
xg-test1.ok.po: $(top_srcdir)/src/xgettext.c $(top_srcdir)/src/msgfmt.c \
- $(top_srcdir)/src/gettextp.c
+ $(top_srcdir)/src/gettext.c
$(XGETTEXT) -d xg-test1.ok -p $(srcdir) -k_ --omit-header \
$(top_srcdir)/src/xgettext.c $(top_srcdir)/src/msgfmt.c \
- $(top_srcdir)/src/gettextp.c
-
-# An auxiliary program used by the plural-1 test.
-INCLUDES = -I${top_srcdir}/intl
-EXTRA_PROGRAMS = cake
-cake_SOURCES = plural-1-prg.c
-cake_LDADD = ../src/setlocale.o ../intl/libintl.a
-all-local: cake
-CLEANFILES = cake
+ $(top_srcdir)/src/gettext.c
+
+# Two auxiliary programs used by the tests.
+INCLUDES = -I.. -I$(top_srcdir)/lib -I$(top_srcdir)/intl
+DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
+LDADD = ../intl/libintl.a
+EXTRA_PROGRAMS = tstgettext cake
+tstgettext_SOURCES = tstgettext.c setlocale.c
+tstgettext_LDADD = ../lib/libnlsut.a $(LDADD)
+cake_SOURCES = plural-1-prg.c setlocale.c
+all-local: $(EXTRA_PROGRAMS)
+CLEANFILES = $(EXTRA_PROGRAMS)
diff --git a/tests/setlocale.c b/tests/setlocale.c
new file mode 100644
index 0000000..71d2637
--- /dev/null
+++ b/tests/setlocale.c
@@ -0,0 +1,167 @@
+/* Fake setlocale - platform independent, for testing purposes.
+ Copyright (C) 2001 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. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <locale.h>
+#include <string.h>
+
+/* Return string representation of locale CATEGORY. */
+static const char *
+category_to_name (category)
+ int category;
+{
+ const char *retval;
+
+ switch (category)
+ {
+#ifdef LC_COLLATE
+ case LC_COLLATE:
+ retval = "LC_COLLATE";
+ break;
+#endif
+#ifdef LC_CTYPE
+ case LC_CTYPE:
+ retval = "LC_CTYPE";
+ break;
+#endif
+#ifdef LC_MONETARY
+ case LC_MONETARY:
+ retval = "LC_MONETARY";
+ break;
+#endif
+#ifdef LC_NUMERIC
+ case LC_NUMERIC:
+ retval = "LC_NUMERIC";
+ break;
+#endif
+#ifdef LC_TIME
+ case LC_TIME:
+ retval = "LC_TIME";
+ break;
+#endif
+#ifdef LC_MESSAGES
+ case LC_MESSAGES:
+ retval = "LC_MESSAGES";
+ break;
+#endif
+#ifdef LC_RESPONSE
+ case LC_RESPONSE:
+ retval = "LC_RESPONSE";
+ break;
+#endif
+#ifdef LC_ALL
+ case LC_ALL:
+ /* This might not make sense but is perhaps better than any other
+ value. */
+ retval = "LC_ALL";
+ break;
+#endif
+ default:
+ /* If you have a better idea for a default value let me know. */
+ retval = "LC_XXX";
+ }
+
+ return retval;
+}
+
+/* An implementation of setlocale that always succeeds, but doesn't
+ actually change the behaviour of locale dependent functions.
+ Assumes setenv()/putenv() is not called. */
+char *
+setlocale (category, locale)
+ int category;
+ SETLOCALE_CONST char *locale;
+{
+ static char C_string[] = "C";
+ static char *current_locale = C_string;
+ struct list
+ {
+ int category;
+ char *current_locale;
+ struct list *next;
+ };
+ static struct list *facets = NULL;
+ struct list *facetp;
+ char *retval;
+
+ if (locale != NULL)
+ {
+ char *copy;
+
+ copy = (char *) malloc (strlen (locale) + 1);
+ strcpy (copy, locale);
+
+ if (category == LC_ALL)
+ {
+ while ((facetp = facets) != NULL)
+ {
+ facets = facetp->next;
+ free (facetp->current_locale);
+ free (facetp);
+ }
+ if (current_locale != C_string)
+ free (current_locale);
+ current_locale = copy;
+ }
+ else
+ {
+ for (facetp = facets; facetp != NULL; facetp = facetp->next)
+ if (category == facetp->category)
+ {
+ free (facetp->current_locale);
+ facetp->current_locale = copy;
+ break;
+ }
+ if (facetp == NULL)
+ {
+ facetp = (struct list *) malloc (sizeof (struct list));
+ facetp->category = category;
+ facetp->current_locale = copy;
+ facetp->next = facets;
+ facets = facetp;
+ }
+ }
+ }
+
+ retval = current_locale;
+ for (facetp = facets; facetp != NULL; facetp = facetp->next)
+ if (category == facetp->category)
+ {
+ retval = facetp->current_locale;
+ break;
+ }
+
+ if (retval[0] == '\0')
+ {
+ retval = getenv ("LC_ALL");
+ if (retval == NULL || retval[0] == '\0')
+ {
+ retval = getenv (category_to_name (category));
+ if (retval == NULL || retval[0] == '\0')
+ {
+ retval = getenv ("LANG");
+ if (retval == NULL || retval[0] == '\0')
+ retval = "C";
+ }
+ }
+ }
+ return retval;
+}
diff --git a/tests/tstgettext.c b/tests/tstgettext.c
new file mode 100644
index 0000000..98cd74d
--- /dev/null
+++ b/tests/tstgettext.c
@@ -0,0 +1,3 @@
+/* A version of the gettext program that uses the included libintl. */
+#define TESTS
+#include "../src/gettext.c"
diff --git a/tests/xgettext-1 b/tests/xgettext-1
index 84cb1e8..7faaee7 100755
--- a/tests/xgettext-1
+++ b/tests/xgettext-1
@@ -7,7 +7,7 @@ trap 'rm -fr $tmpfiles' 1 2 3 15
tmpfiles="xg-test1.po"
: ${XGETTEXT=xgettext}
${XGETTEXT} -d xg-test1 -k_ --omit-header \
- $top_srcdir/src/xgettext.c $top_srcdir/src/msgfmt.c $top_srcdir/src/gettextp.c
+ $top_srcdir/src/xgettext.c $top_srcdir/src/msgfmt.c $top_srcdir/src/gettext.c
: ${DIFF=diff}
${DIFF} $top_srcdir/tests/xg-test1.ok.po xg-test1.po