Imported Upstream version 0.18.1.1
[platform/upstream/gettext.git] / gettext-tools / tests / gettext-4-prg.c
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 3 of the License, or
7    (at your option) 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, see <http://www.gnu.org/licenses/>.  */
16
17 /* Contributed to the GNU C Library by
18    Bruno Haible <haible@clisp.cons.org>, 2001.  */
19
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23
24 #include <locale.h>
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include "xsetenv.h"
29
30 /* Make sure we use the included libintl, not the system's one. */
31 #undef _LIBINTL_H
32 #include "libgnuintl.h"
33
34 int
35 main (int argc, char *argv[])
36 {
37   char *s;
38   int result = 0;
39
40   /* Clean up environment.  */
41   unsetenv ("LANGUAGE");
42   unsetenv ("LC_ALL");
43   unsetenv ("LC_MESSAGES");
44   unsetenv ("LC_CTYPE");
45   unsetenv ("LANG");
46   unsetenv ("OUTPUT_CHARSET");
47
48   xsetenv ("LC_ALL", argv[1], 1);
49   setlocale (LC_ALL, "");
50   textdomain ("codeset");
51   bindtextdomain ("codeset", ".");
52
53   /* Here we expect output in ISO-8859-1.
54      Except on Darwin 7 or newer and on BeOS, for which locale_charset ()
55      always returns "UTF-8" (see config.charset).  */
56 #if !((defined __APPLE__ && defined __MACH__) || defined __BEOS__)
57   s = gettext ("cheese");
58   if (strcmp (s, "K\344se"))
59     {
60       fprintf (stderr, "call 1 returned: %s\n", s);
61       result = 1;
62     }
63 #endif
64
65   bind_textdomain_codeset ("codeset", "UTF-8");
66
67   /* Here we expect output in UTF-8.  */
68   s = gettext ("cheese");
69   if (strcmp (s, "K\303\244se"))
70     {
71       fprintf (stderr, "call 2 returned: %s\n", s);
72       result = 1;
73     }
74
75   bind_textdomain_codeset ("codeset", "ISO-8859-1");
76
77   /* Here we expect output in ISO-8859-1.  */
78   s = gettext ("cheese");
79   if (strcmp (s, "K\344se"))
80     {
81       fprintf (stderr, "call 3 returned: %s\n", s);
82       result = 1;
83     }
84
85   return result;
86 }