f3529ebaf3bfdd53ec4fc9f2700d01cd5fd99718
[platform/upstream/gettext.git] / gettext-tools / tests / format-c-5-prg.c
1 /* Test program, used by the format-c-5 test.
2    Copyright (C) 2004, 2006, 2010, 2015 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 #include "xsetenv.h"
26
27 /* For %Id to work, we need the real setlocale(), not the fake one. */
28 #if !(__GLIBC__ >= 2 && !defined __UCLIBC__)
29 # include "setlocale.c"
30 #endif
31
32 /* Make sure we use the included libintl, not the system's one. */
33 #undef _LIBINTL_H
34 #include "libgnuintl.h"
35
36 #define _(string) gettext (string)
37
38 int
39 main (int argc, char *argv[])
40 {
41   int n = 5;
42   const char *en;
43   const char *s;
44   const char *expected_translation;
45   const char *expected_result;
46   char buf[100];
47
48   xsetenv ("LC_ALL", argv[1], 1);
49   if (setlocale (LC_ALL, "") == NULL)
50     /* Couldn't set locale.  */
51     exit (77);
52
53   textdomain ("fc5");
54   bindtextdomain ("fc5", ".");
55
56   s = gettext ("father of %d children");
57   en = "father of %d children";
58 #if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) && !defined __UCLIBC__
59   expected_translation = "Vater von %Id Kindern";
60   expected_result = "Vater von \xdb\xb5 Kindern";
61 #else
62   expected_translation = "Vater von %d Kindern";
63   expected_result = "Vater von 5 Kindern";
64 #endif
65
66   if (strcmp (s, en) == 0)
67     {
68       fprintf (stderr, "String untranslated.\n");
69       exit (1);
70     }
71   if (strcmp (s, expected_translation) != 0)
72     {
73       fprintf (stderr, "String incorrectly translated.\n");
74       exit (1);
75     }
76   sprintf (buf, s, n);
77   if (strcmp (buf, expected_result) != 0)
78     {
79       fprintf (stderr, "printf of translation wrong.\n");
80       exit (1);
81     }
82   return 0;
83 }