Imported Upstream version 0.18.3.2
[platform/upstream/gettext.git] / gettext-tools / tests / format-c-4-prg.c
1 /* Test program, used by the format-c-4 test.
2    Copyright (C) 2002, 2009 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 #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 #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 /* Disable the override of setlocale that libgnuintl.h activates on MacOS X
35    and Windows.  This test relies on the fake setlocale function in
36    setlocale.c.  */
37 #undef setlocale
38
39 #define _(string) gettext (string)
40
41 /* Fallback definition.  */
42 #if !defined PRId8 || PRI_MACROS_BROKEN
43 # undef PRId8
44 # define PRId8 "d"
45 #endif
46
47 int
48 main (int argc, char *argv[])
49 {
50   unsigned char n = 5;
51   const char *s;
52   const char *c1;
53   const char *c2;
54   char buf[100];
55
56   xsetenv ("LC_ALL", argv[1], 1);
57   if (setlocale (LC_ALL, "") == NULL)
58     {
59       fprintf (stderr, "Couldn't set locale.\n");
60       exit (1);
61     }
62
63   textdomain ("fc4");
64   bindtextdomain ("fc4", "fc4-dir");
65
66   s = ngettext ("father of %"PRId8" child", "father of %"PRId8" children", n);
67   c1 = "Vater von %"; c2 = " Kindern";
68
69   if (!(strlen (s) > strlen (c1) + strlen (c2)
70         && memcmp (s, c1, strlen (c1)) == 0
71         && memcmp (s + strlen (s) - strlen (c2), c2, strlen (c2)) == 0))
72     {
73       fprintf (stderr, "String not translated.\n");
74       exit (1);
75     }
76   if (strchr (s, '<') != NULL || strchr (s, '>') != NULL)
77     {
78       fprintf (stderr, "Translation contains <...> markers.\n");
79       exit (1);
80     }
81   sprintf (buf, s, n);
82   if (strcmp (buf, "Vater von 5 Kindern") != 0)
83     {
84       fprintf (stderr, "printf of translation wrong.\n");
85       exit (1);
86     }
87   return 0;
88 }