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 ("LC_CTYPE", "non-existing-locale", 1);
72 setenv ("LANG", "non-existing-locale", 1);
73 unsetenv ("OUTPUT_CHARSET");
74 /* This is the name of the existing domain with a catalog for the
75 LC_MESSAGES category. */
76 textdomain ("existing-domain");
77 puts ("test `gettext' with LANGUAGE set");
78 if (positive_gettext_test () != 0)
83 /* This is the name of a non-existing domain with a catalog for the
84 LC_MESSAGES category. We leave this value set for the `dgettext'
85 and `dcgettext' tests. */
86 textdomain ("non-existing-domain");
87 puts ("test `gettext' with LANGUAGE set");
88 if (negative_gettext_test () != 0)
93 puts ("test `dgettext' with LANGUAGE set");
94 if (positive_dgettext_test ("existing-domain") != 0)
100 /* Now the same tests with LC_ALL deciding. */
101 unsetenv ("LANGUAGE");
102 setenv ("LC_ALL", "existing-locale", 1);
103 puts ("test `gettext' with LC_ALL set");
104 /* This is the name of the existing domain with a catalog for the
105 LC_MESSAGES category. */
106 textdomain ("existing-domain");
107 if (positive_gettext_test () != 0)
112 /* This is the name of a non-existing domain with a catalog for the
113 LC_MESSAGES category. We leave this value set for the `dgettext'
114 and `dcgettext' tests. */
115 textdomain ("non-existing-domain");
116 puts ("test `gettext' with LANGUAGE set");
117 if (negative_gettext_test () != 0)
122 puts ("test `dgettext' with LANGUAGE set");
123 if (positive_dgettext_test ("existing-domain") != 0)
129 /* Now the same tests with LC_MESSAGES deciding. */
131 setenv ("LC_MESSAGES", "existing-locale", 1);
132 setenv ("LC_TIME", "existing-locale", 1);
133 setenv ("LC_NUMERIC", "non-existing-locale", 1);
134 puts ("test `gettext' with LC_ALL set");
135 /* This is the name of the existing domain with a catalog for the
136 LC_MESSAGES category. */
137 textdomain ("existing-domain");
138 if (positive_gettext_test () != 0)
143 /* This is the name of a non-existing domain with a catalog for the
144 LC_MESSAGES category. We leave this value set for the `dgettext'
145 and `dcgettext' tests. */
146 textdomain ("non-existing-domain");
147 puts ("test `gettext' with LANGUAGE set");
148 if (negative_gettext_test () != 0)
153 puts ("test `dgettext' with LANGUAGE set");
154 if (positive_dgettext_test ("existing-domain") != 0)
159 puts ("test `dcgettext' with LANGUAGE set (LC_MESSAGES)");
160 if (positive_dcgettext_test ("existing-domain", LC_MESSAGES
) != 0)
165 /* Try a different category. For this we also switch the domain. */
166 puts ("test `dcgettext' with LANGUAGE set (LC_TIME)");
167 if (positive_dcgettext_test ("existing-time-domain", LC_TIME
) != 0)
172 /* This time use a category for which there is no catalog. */
173 puts ("test `dcgettext' with LANGUAGE set (LC_NUMERIC)");
174 if (negative_dcgettext_test ("existing-domain", LC_NUMERIC
) != 0)
180 /* Now the same tests with LANG deciding. */
181 unsetenv ("LC_MESSAGES");
182 setenv ("LANG", "existing-locale", 1);
183 /* This is the name of the existing domain with a catalog for the
184 LC_MESSAGES category. */
185 textdomain ("existing-domain");
186 puts ("test `gettext' with LC_ALL set");
187 if (positive_gettext_test () != 0)
192 /* This is the name of a non-existing domain with a catalog for the
193 LC_MESSAGES category. We leave this value set for the `dgettext'
194 and `dcgettext' tests. */
195 textdomain ("non-existing-domain");
196 puts ("test `gettext' with LANGUAGE set");
197 if (negative_gettext_test () != 0)
202 puts ("test `dgettext' with LANGUAGE set");
203 if (positive_dgettext_test ("existing-domain") != 0)
214 positive_gettext_test (void)
219 for (cnt
= 0; cnt
< sizeof (msgs
) / sizeof (msgs
[0]); ++cnt
)
221 const char *found
= gettext (msgs
[cnt
].msgid
);
223 if (found
== NULL
|| strcmp (found
, msgs
[cnt
].msgstr
) != 0)
225 /* Oops, shouldn't happen. */
226 printf (" gettext (\"%s\") failed, returned \"%s\"\n",
227 msgs
[cnt
].msgid
, found
);
237 negative_gettext_test (void)
242 for (cnt
= 0; cnt
< sizeof (msgs
) / sizeof (msgs
[0]); ++cnt
)
244 const char *found
= gettext (msgs
[cnt
].msgid
);
246 if (found
!= msgs
[cnt
].msgid
)
248 /* Oops, shouldn't happen. */
249 printf (" gettext (\"%s\") failed\n", msgs
[cnt
].msgid
);
259 positive_dgettext_test (const char *domain
)
264 for (cnt
= 0; cnt
< sizeof (msgs
) / sizeof (msgs
[0]); ++cnt
)
266 const char *found
= dgettext (domain
, msgs
[cnt
].msgid
);
268 if (found
== NULL
|| strcmp (found
, msgs
[cnt
].msgstr
) != 0)
270 /* Oops, shouldn't happen. */
271 printf (" dgettext (\"%s\", \"%s\") failed, returned \"%s\"\n",
272 domain
, msgs
[cnt
].msgid
, found
);
282 positive_dcgettext_test (const char *domain
, int category
)
287 for (cnt
= 0; cnt
< sizeof (msgs
) / sizeof (msgs
[0]); ++cnt
)
289 const char *found
= dcgettext (domain
, msgs
[cnt
].msgid
, category
);
291 if (found
== NULL
|| strcmp (found
, msgs
[cnt
].msgstr
) != 0)
293 /* Oops, shouldn't happen. */
294 printf (" dcgettext (\"%s\", \"%s\", %s) failed, returned \"%s\"\n",
295 domain
, msgs
[cnt
].msgid
, catname
[category
], found
);
305 negative_dcgettext_test (const char *domain
, int category
)
310 for (cnt
= 0; cnt
< sizeof (msgs
) / sizeof (msgs
[0]); ++cnt
)
312 const char *found
= dcgettext (domain
, msgs
[cnt
].msgid
, category
);
314 if (found
!= msgs
[cnt
].msgid
)
316 /* Oops, shouldn't happen. */
317 printf (" dcgettext (\"%s\", \"%s\", %s) failed\n",
318 domain
, msgs
[cnt
].msgid
, catname
[category
]);