xref: /netbsd-src/external/gpl2/gettext/dist/gettext-tools/tests/gettext-4-prg.c (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /* Test program, used by the gettext-4 test.
2    Copyright (C) 2001, 2005-2006 Free Software Foundation, Inc.
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2, or (at your option)
7    any later version.
8 
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software Foundation,
16    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
17 
18 /* Contributed to the GNU C Library by
19    Bruno Haible <haible@clisp.cons.org>, 2001.  */
20 
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24 
25 #include <locale.h>
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include "xsetenv.h"
30 
31 /* Make sure we use the included libintl, not the system's one. */
32 #undef _LIBINTL_H
33 #include "libgnuintl.h"
34 
35 int
36 main (int argc, char *argv[])
37 {
38   char *s;
39   int result = 0;
40 
41   /* Clean up environment.  */
42   unsetenv ("LANGUAGE");
43   unsetenv ("LC_ALL");
44   unsetenv ("LC_MESSAGES");
45   unsetenv ("LC_CTYPE");
46   unsetenv ("LANG");
47   unsetenv ("OUTPUT_CHARSET");
48 
49   xsetenv ("LC_ALL", argv[1], 1);
50   setlocale (LC_ALL, "");
51   textdomain ("codeset");
52   bindtextdomain ("codeset", ".");
53 
54   /* Here we expect output in ISO-8859-1.
55      Except on Darwin 7 or newer and on BeOS, for which locale_charset ()
56      always returns "UTF-8" (see config.charset).  */
57 #if !((defined __APPLE__ && defined __MACH__) || defined __BEOS__)
58   s = gettext ("cheese");
59   if (strcmp (s, "K\344se"))
60     {
61       fprintf (stderr, "call 1 returned: %s\n", s);
62       result = 1;
63     }
64 #endif
65 
66   bind_textdomain_codeset ("codeset", "UTF-8");
67 
68   /* Here we expect output in UTF-8.  */
69   s = gettext ("cheese");
70   if (strcmp (s, "K\303\244se"))
71     {
72       fprintf (stderr, "call 2 returned: %s\n", s);
73       result = 1;
74     }
75 
76   bind_textdomain_codeset ("codeset", "ISO-8859-1");
77 
78   /* Here we expect output in ISO-8859-1.  */
79   s = gettext ("cheese");
80   if (strcmp (s, "K\344se"))
81     {
82       fprintf (stderr, "call 3 returned: %s\n", s);
83       result = 1;
84     }
85 
86   return result;
87 }
88