1 /* Test of the gettext functions.
2 Copyright (C) 2000 Free Software Foundation, Inc.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>, 2000.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
32 #define INPUT(Str) { Str,
33 #define OUTPUT(Str) Str },
37 const char *catname[] =
39 [LC_MESSAGES] = "LC_MESSAGES",
40 [LC_TIME] = "LC_TIME",
41 [LC_NUMERIC] = "LC_NUMERIC"
45 static int positive_gettext_test (void);
46 static int negative_gettext_test (void);
47 static int positive_dgettext_test (const char *domain);
48 static int positive_dcgettext_test (const char *domain, int category);
49 static int negative_dcgettext_test (const char *domain, int category);
53 main (int argc, char *argv[])
57 /* This is the place where the .mo files are placed. */
60 bindtextdomain ("existing-domain", argv[1]);
61 bindtextdomain ("existing-time-domain", argv[1]);
62 bindtextdomain ("non-existing-domain", argv[1]);
65 /* The locale the catalog is created for is "existing-category". Now
66 set the various variables in question to this value and run the
68 setenv ("LANGUAGE", "existing-locale", 1);
69 setenv ("LC_ALL", "non-existing-locale", 1);
70 setenv ("LC_MESSAGES", "non-existing-locale", 1);
71 setenv ("LANG", "non-existing-locale", 1);
72 /* This is the name of the existing domain with a catalog for the
73 LC_MESSAGES category. */
74 textdomain ("existing-domain");
75 puts ("test `gettext' with LANGUAGE set");
76 if (positive_gettext_test () != 0)
81 /* This is the name of a non-existing domain with a catalog for the
82 LC_MESSAGES category. We leave this value set for the `dgettext'
83 and `dcgettext' tests. */
84 textdomain ("non-existing-domain");
85 puts ("test `gettext' with LANGUAGE set");
86 if (negative_gettext_test () != 0)
91 puts ("test `dgettext' with LANGUAGE set");
92 if (positive_dgettext_test ("existing-domain") != 0)
98 /* Now the same tests with LC_ALL deciding. */
99 unsetenv ("LANGUAGE");
100 setenv ("LC_ALL", "existing-locale", 1);
101 puts ("test `gettext' with LC_ALL set");
102 /* This is the name of the existing domain with a catalog for the
103 LC_MESSAGES category. */
104 textdomain ("existing-domain");
105 if (positive_gettext_test () != 0)
110 /* This is the name of a non-existing domain with a catalog for the
111 LC_MESSAGES category. We leave this value set for the `dgettext'
112 and `dcgettext' tests. */
113 textdomain ("non-existing-domain");
114 puts ("test `gettext' with LANGUAGE set");
115 if (negative_gettext_test () != 0)
120 puts ("test `dgettext' with LANGUAGE set");
121 if (positive_dgettext_test ("existing-domain") != 0)
127 /* Now the same tests with LC_MESSAGES deciding. */
129 setenv ("LC_MESSAGES", "existing-locale", 1);
130 setenv ("LC_TIME", "existing-locale", 1);
131 setenv ("LC_NUMERIC", "non-existing-locale", 1);
132 puts ("test `gettext' with LC_ALL set");
133 /* This is the name of the existing domain with a catalog for the
134 LC_MESSAGES category. */
135 textdomain ("existing-domain");
136 if (positive_gettext_test () != 0)
141 /* This is the name of a non-existing domain with a catalog for the
142 LC_MESSAGES category. We leave this value set for the `dgettext'
143 and `dcgettext' tests. */
144 textdomain ("non-existing-domain");
145 puts ("test `gettext' with LANGUAGE set");
146 if (negative_gettext_test () != 0)
151 puts ("test `dgettext' with LANGUAGE set");
152 if (positive_dgettext_test ("existing-domain") != 0)
157 puts ("test `dcgettext' with LANGUAGE set (LC_MESSAGES)");
158 if (positive_dcgettext_test ("existing-domain", LC_MESSAGES) != 0)
163 /* Try a different category. For this we also switch the domain. */
164 puts ("test `dcgettext' with LANGUAGE set (LC_TIME)");
165 if (positive_dcgettext_test ("existing-time-domain", LC_TIME) != 0)
170 /* This time use a category for which there is no catalog. */
171 puts ("test `dcgettext' with LANGUAGE set (LC_NUMERIC)");
172 if (negative_dcgettext_test ("existing-domain", LC_NUMERIC) != 0)
178 /* Now the same tests with LANG deciding. */
179 unsetenv ("LC_MESSAGES");
180 setenv ("LANG", "existing-locale", 1);
181 /* This is the name of the existing domain with a catalog for the
182 LC_MESSAGES category. */
183 textdomain ("existing-domain");
184 puts ("test `gettext' with LC_ALL set");
185 if (positive_gettext_test () != 0)
190 /* This is the name of a non-existing domain with a catalog for the
191 LC_MESSAGES category. We leave this value set for the `dgettext'
192 and `dcgettext' tests. */
193 textdomain ("non-existing-domain");
194 puts ("test `gettext' with LANGUAGE set");
195 if (negative_gettext_test () != 0)
200 puts ("test `dgettext' with LANGUAGE set");
201 if (positive_dgettext_test ("existing-domain") != 0)
212 positive_gettext_test (void)
217 for (cnt = 0; cnt < sizeof (msgs) / sizeof (msgs[0]); ++cnt)
219 const char *found = gettext (msgs[cnt].msgid);
221 if (found == NULL || strcmp (found, msgs[cnt].msgstr) != 0)
223 /* Oops, shouldn't happen. */
224 printf (" gettext (\"%s\") failed, returned \"%s\"\n",
225 msgs[cnt].msgid, found);
235 negative_gettext_test (void)
240 for (cnt = 0; cnt < sizeof (msgs) / sizeof (msgs[0]); ++cnt)
242 const char *found = gettext (msgs[cnt].msgid);
244 if (found != msgs[cnt].msgid)
246 /* Oops, shouldn't happen. */
247 printf (" gettext (\"%s\") failed\n", msgs[cnt].msgid);
257 positive_dgettext_test (const char *domain)
262 for (cnt = 0; cnt < sizeof (msgs) / sizeof (msgs[0]); ++cnt)
264 const char *found = dgettext (domain, msgs[cnt].msgid);
266 if (found == NULL || strcmp (found, msgs[cnt].msgstr) != 0)
268 /* Oops, shouldn't happen. */
269 printf (" dgettext (\"%s\", \"%s\") failed, returned \"%s\"\n",
270 domain, msgs[cnt].msgid, found);
280 positive_dcgettext_test (const char *domain, int category)
285 for (cnt = 0; cnt < sizeof (msgs) / sizeof (msgs[0]); ++cnt)
287 const char *found = dcgettext (domain, msgs[cnt].msgid, category);
289 if (found == NULL || strcmp (found, msgs[cnt].msgstr) != 0)
291 /* Oops, shouldn't happen. */
292 printf (" dcgettext (\"%s\", \"%s\", %s) failed, returned \"%s\"\n",
293 domain, msgs[cnt].msgid, catname[category], found);
303 negative_dcgettext_test (const char *domain, int category)
308 for (cnt = 0; cnt < sizeof (msgs) / sizeof (msgs[0]); ++cnt)
310 const char *found = dcgettext (domain, msgs[cnt].msgid, category);
312 if (found != msgs[cnt].msgid)
314 /* Oops, shouldn't happen. */
315 printf (" dcgettext (\"%s\", \"%s\", %s) failed\n",
316 domain, msgs[cnt].msgid, catname[category]);