1 /* Test program, used by the format-c-3 test.
2 Copyright (C) 2002, 2009, 2013, 2018, 2020, 2023 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 #ifdef HAVE_CONFIG_H
18 # include "config.h"
19 #endif
20
21 #include <locale.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #ifdef HAVE_INTTYPES_H
26 # include <inttypes.h>
27 #endif
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 /* Disable the override of setlocale that libgnuintl.h activates on MacOS X
40 and Windows. This test relies on the fake setlocale function in
41 setlocale.c. */
42 #undef setlocale
43 #if defined _WIN32 && !defined __CYGWIN__
44 # define setlocale fake_setlocale
45 extern char *setlocale (int category, const char *locale);
46 #endif
47
48 /* Fallback definition. */
49 #if !defined PRId8
50 # define PRId8 "d"
51 #endif
52
53 int
54 main (int argc, char *argv[])
55 {
56 unsigned char n = 5;
57 const char *s;
58 const char *c1;
59 const char *c2;
60 char buf[100];
61
62 xsetenv ("LC_ALL", argv[1], 1);
63 if (setlocale (LC_ALL, "") == NULL)
64 {
65 fprintf (stderr, "Couldn't set locale.\n");
66 exit (1);
67 }
68
69 textdomain ("fc3");
70 bindtextdomain ("fc3", "fc3-dir");
71
72 if (strcmp (gettext ("the president"), "der Vorsitzende") != 0)
73 {
74 fprintf (stderr, "Simple messages not translated.\n");
75 exit (1);
76 }
77
78 s = gettext ("father of %"PRId8" children");
79 c1 = "Vater von %"; c2 = " Kindern";
80
81 if (!(strlen (s) > strlen (c1) + strlen (c2)
82 && memcmp (s, c1, strlen (c1)) == 0
83 && memcmp (s + strlen (s) - strlen (c2), c2, strlen (c2)) == 0))
84 {
85 fprintf (stderr, "String not translated.\n");
86 exit (1);
87 }
88 if (strchr (s, '<') != NULL || strchr (s, '>') != NULL)
89 {
90 fprintf (stderr, "Translation contains <...> markers.\n");
91 exit (1);
92 }
93 sprintf (buf, s, n);
94 if (strcmp (buf, "Vater von 5 Kindern") != 0)
95 {
96 fprintf (stderr, "printf of translation wrong.\n");
97 exit (1);
98 }
99 return 0;
100 }