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. */
34 #define INPUT(Str) { Str,
35 #define OUTPUT(Str) Str },
39 const char *catname
[] =
41 [LC_MESSAGES
] = "LC_MESSAGES",
42 [LC_TIME
] = "LC_TIME",
43 [LC_NUMERIC
] = "LC_NUMERIC"
47 static int positive_gettext_test (void);
48 static int negative_gettext_test (void);
49 static int positive_dgettext_test (const char *domain
);
50 static int positive_dcgettext_test (const char *domain
, int category
);
51 static int negative_dcgettext_test (const char *domain
, int category
);
55 main (int argc
, char *argv
[])
62 /* This is the place where the .mo files are placed. */
65 bindtextdomain ("existing-domain", argv
[1]);
66 bindtextdomain ("existing-time-domain", argv
[1]);
67 bindtextdomain ("non-existing-domain", argv
[1]);
70 /* The locale the catalog is created for is "existing-category". Now
71 set the various variables in question to this value and run the
73 setenv ("LANGUAGE", "existing-locale", 1);
74 setenv ("LC_ALL", "non-existing-locale", 1);
75 setenv ("LC_MESSAGES", "non-existing-locale", 1);
76 setenv ("LC_CTYPE", "non-existing-locale", 1);
77 setenv ("LANG", "non-existing-locale", 1);
78 setlocale (LC_CTYPE
, "de_DE.ISO-8859-1");
79 setlocale (LC_MESSAGES
, "de_DE.ISO-8859-1");
80 unsetenv ("OUTPUT_CHARSET");
81 /* This is the name of the existing domain with a catalog for the
82 LC_MESSAGES category. */
83 textdomain ("existing-domain");
84 puts ("test `gettext' with LANGUAGE set");
85 if (positive_gettext_test () != 0)
90 /* This is the name of a non-existing domain with a catalog for the
91 LC_MESSAGES category. We leave this value set for the `dgettext'
92 and `dcgettext' tests. */
93 textdomain ("non-existing-domain");
94 puts ("test `gettext' with LANGUAGE set");
95 if (negative_gettext_test () != 0)
100 puts ("test `dgettext' with LANGUAGE set");
101 if (positive_dgettext_test ("existing-domain") != 0)
107 /* Now the same tests with LC_ALL deciding. */
108 unsetenv ("LANGUAGE");
109 setenv ("LC_ALL", "existing-locale", 1);
110 setlocale (LC_ALL
, "");
111 puts ("test `gettext' with LC_ALL set");
112 /* This is the name of the existing domain with a catalog for the
113 LC_MESSAGES category. */
114 textdomain ("existing-domain");
115 if (positive_gettext_test () != 0)
120 /* This is the name of a non-existing domain with a catalog for the
121 LC_MESSAGES category. We leave this value set for the `dgettext'
122 and `dcgettext' tests. */
123 textdomain ("non-existing-domain");
124 puts ("test `gettext' with LC_ALL deciding");
125 if (negative_gettext_test () != 0)
130 puts ("test `dgettext' with LC_ALL deciding");
131 if (positive_dgettext_test ("existing-domain") != 0)
137 /* Now the same tests with LC_MESSAGES deciding. */
139 setenv ("LC_MESSAGES", "existing-locale", 1);
140 setlocale (LC_MESSAGES
, "");
141 setenv ("LC_TIME", "existing-locale", 1);
142 setlocale (LC_TIME
, "");
143 setenv ("LC_NUMERIC", "non-existing-locale", 1);
144 setlocale (LC_NUMERIC
, "");
145 puts ("test `gettext' with LC_ALL set");
146 /* This is the name of the existing domain with a catalog for the
147 LC_MESSAGES category. */
148 textdomain ("existing-domain");
149 if (positive_gettext_test () != 0)
154 /* This is the name of a non-existing domain with a catalog for the
155 LC_MESSAGES category. We leave this value set for the `dgettext'
156 and `dcgettext' tests. */
157 textdomain ("non-existing-domain");
158 puts ("test `gettext' with LC_xxx deciding");
159 if (negative_gettext_test () != 0)
164 puts ("test `dgettext' with LC_xxx deciding");
165 if (positive_dgettext_test ("existing-domain") != 0)
170 puts ("test `dcgettext' with category == LC_MESSAGES");
171 if (positive_dcgettext_test ("existing-domain", LC_MESSAGES
) != 0)
176 /* Try a different category. For this we also switch the domain. */
177 puts ("test `dcgettext' with LANGUAGE == LC_TIME");
178 if (positive_dcgettext_test ("existing-time-domain", LC_TIME
) != 0)
183 /* This time use a category for which there is no catalog. */
184 puts ("test `dcgettext' with LANGUAGE == LC_NUMERIC");
185 if (negative_dcgettext_test ("existing-domain", LC_NUMERIC
) != 0)
191 /* Now the same tests with LANG deciding. */
192 unsetenv ("LC_MESSAGES");
193 setenv ("LANG", "existing-locale", 1);
194 setlocale (LC_ALL
, "");
195 /* This is the name of the existing domain with a catalog for the
196 LC_MESSAGES category. */
197 textdomain ("existing-domain");
198 puts ("test `gettext' with LANG set");
199 if (positive_gettext_test () != 0)
204 /* This is the name of a non-existing domain with a catalog for the
205 LC_MESSAGES category. We leave this value set for the `dgettext'
206 and `dcgettext' tests. */
207 textdomain ("non-existing-domain");
208 puts ("test `gettext' with LANG set");
209 if (negative_gettext_test () != 0)
214 puts ("test `dgettext' with LANG set");
215 if (positive_dgettext_test ("existing-domain") != 0)
221 setlocale (LC_ALL
, "C");
228 positive_gettext_test (void)
233 for (cnt
= 0; cnt
< sizeof (msgs
) / sizeof (msgs
[0]); ++cnt
)
235 const char *found
= gettext (msgs
[cnt
].msgid
);
237 if (found
== NULL
|| strcmp (found
, msgs
[cnt
].msgstr
) != 0)
239 /* Oops, shouldn't happen. */
241 gettext (\"%s\") failed, returned \"%s\", expected \"%s\"\n",
242 msgs
[cnt
].msgid
, found
, msgs
[cnt
].msgstr
);
252 negative_gettext_test (void)
257 for (cnt
= 0; cnt
< sizeof (msgs
) / sizeof (msgs
[0]); ++cnt
)
259 const char *found
= gettext (msgs
[cnt
].msgid
);
261 if (found
!= msgs
[cnt
].msgid
)
263 /* Oops, shouldn't happen. */
264 printf (" gettext (\"%s\") failed\n", msgs
[cnt
].msgid
);
274 positive_dgettext_test (const char *domain
)
279 for (cnt
= 0; cnt
< sizeof (msgs
) / sizeof (msgs
[0]); ++cnt
)
281 const char *found
= dgettext (domain
, msgs
[cnt
].msgid
);
283 if (found
== NULL
|| strcmp (found
, msgs
[cnt
].msgstr
) != 0)
285 /* Oops, shouldn't happen. */
287 dgettext (\"%s\", \"%s\") failed, returned \"%s\", expected \"%s\"\n",
288 domain
, msgs
[cnt
].msgid
, found
, msgs
[cnt
].msgstr
);
298 positive_dcgettext_test (const char *domain
, int category
)
303 for (cnt
= 0; cnt
< sizeof (msgs
) / sizeof (msgs
[0]); ++cnt
)
305 const char *found
= dcgettext (domain
, msgs
[cnt
].msgid
, category
);
307 if (found
== NULL
|| strcmp (found
, msgs
[cnt
].msgstr
) != 0)
309 /* Oops, shouldn't happen. */
311 dcgettext (\"%s\", \"%s\", %s) failed, returned \"%s\", expected \"%s\"\n",
312 domain
, msgs
[cnt
].msgid
, catname
[category
], found
,
323 negative_dcgettext_test (const char *domain
, int category
)
328 for (cnt
= 0; cnt
< sizeof (msgs
) / sizeof (msgs
[0]); ++cnt
)
330 const char *found
= dcgettext (domain
, msgs
[cnt
].msgid
, category
);
332 if (found
!= msgs
[cnt
].msgid
)
334 /* Oops, shouldn't happen. */
335 printf (" dcgettext (\"%s\", \"%s\", %s) failed\n",
336 domain
, msgs
[cnt
].msgid
, catname
[category
]);