1 /* Test program, used by the intl-4 test.
2 Copyright (C) 2001, 2005-2006, 2013, 2018 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 <https://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
29 #if USE_SYSTEM_LIBINTL
30 # define xsetenv setenv
31 # include <libintl.h>
32 #else
33 # include "xsetenv.h"
34 /* Make sure we use the included libintl, not the system's one. */
35 # undef _LIBINTL_H
36 # include "libgnuintl.h"
37 #endif
38
39 int
main(int argc,char * argv[])40 main (int argc, char *argv[])
41 {
42 char *s;
43 int result = 0;
44
45 /* Clean up environment. */
46 unsetenv ("LANGUAGE");
47 unsetenv ("LC_ALL");
48 unsetenv ("LC_MESSAGES");
49 unsetenv ("LC_CTYPE");
50 unsetenv ("LANG");
51 unsetenv ("OUTPUT_CHARSET");
52
53 xsetenv ("LC_ALL", argv[1], 1);
54 setlocale (LC_ALL, "");
55 textdomain ("tstprog");
56 bindtextdomain ("tstprog", "in-4");
57
58 /* Here we expect output in ISO-8859-1.
59 Except on Darwin 7 or newer and on BeOS and Haiku, for which
60 locale_charset () always returns "UTF-8" (see localcharset.c). */
61 #if !((defined __APPLE__ && defined __MACH__) || defined __BEOS__ || defined __HAIKU__)
62 s = gettext ("cheese");
63 if (strcmp (s, "K\344se"))
64 {
65 fprintf (stderr, "call 1 returned: %s\n", s);
66 result = 1;
67 }
68 #endif
69
70 bind_textdomain_codeset ("tstprog", "UTF-8");
71
72 /* Here we expect output in UTF-8. */
73 s = gettext ("cheese");
74 if (strcmp (s, "K\303\244se"))
75 {
76 fprintf (stderr, "call 2 returned: %s\n", s);
77 result = 1;
78 }
79
80 bind_textdomain_codeset ("tstprog", "ISO-8859-1");
81
82 /* Here we expect output in ISO-8859-1. */
83 s = gettext ("cheese");
84 if (strcmp (s, "K\344se"))
85 {
86 fprintf (stderr, "call 3 returned: %s\n", s);
87 result = 1;
88 }
89
90 return result;
91 }
92