1 /* Tests of C and POSIX locale contents.
2 Copyright (C) 2000,01,02 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@redhat.com>, 2000.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
32 run_test (const char *locname
)
44 printf ("localeconv failed for locale %s\n", locname
);
49 #define STRTEST(name, exp) \
51 if (strcmp (lc->name, exp) != 0) \
53 printf (#name " in locale %s wrong (is \"%s\", should be \"%s\")\n",\
54 locname, lc->name, exp); \
58 STRTEST (decimal_point
, ".");
59 STRTEST (thousands_sep
, "");
60 STRTEST (grouping
, "");
61 STRTEST (mon_decimal_point
, "");
62 STRTEST (mon_thousands_sep
, "");
63 STRTEST (mon_grouping
, "");
64 STRTEST (positive_sign
, "");
65 STRTEST (negative_sign
, "");
66 STRTEST (currency_symbol
, "");
67 STRTEST (int_curr_symbol
, "");
69 #define CHARTEST(name, exp) \
71 if (lc->name != exp) \
73 printf (#name " in locale %s wrong (is %d, should be %d)\n", \
74 locname, lc->name, CHAR_MAX); \
78 CHARTEST (frac_digits
, CHAR_MAX
);
79 CHARTEST (p_cs_precedes
, CHAR_MAX
);
80 CHARTEST (n_cs_precedes
, CHAR_MAX
);
81 CHARTEST (p_sep_by_space
, CHAR_MAX
);
82 CHARTEST (n_sep_by_space
, CHAR_MAX
);
83 CHARTEST (p_sign_posn
, CHAR_MAX
);
84 CHARTEST (n_sign_posn
, CHAR_MAX
);
85 CHARTEST (int_frac_digits
, CHAR_MAX
);
86 CHARTEST (int_p_cs_precedes
, CHAR_MAX
);
87 CHARTEST (int_n_cs_precedes
, CHAR_MAX
);
88 CHARTEST (int_p_sep_by_space
, CHAR_MAX
);
89 CHARTEST (int_n_sep_by_space
, CHAR_MAX
);
90 CHARTEST (int_p_sign_posn
, CHAR_MAX
);
91 CHARTEST (int_n_sign_posn
, CHAR_MAX
);
95 #define STRTEST(name, exp) \
96 str = nl_langinfo (name); \
97 if (strcmp (str, exp) != 0) \
99 printf ("nl_langinfo(" #name ") in locale %s wrong " \
100 "(is \"%s\", should be \"%s\")\n", locname, str, exp); \
103 #define WSTRTEST(name, exp) \
104 wstr = (wchar_t *) nl_langinfo (name); \
105 if (wcscmp (wstr, exp) != 0) \
107 printf ("nl_langinfo(" #name ") in locale %s wrong " \
108 "(is \"%S\", should be \"%S\")\n", locname, wstr, exp); \
113 STRTEST (ABDAY_1
, "Sun");
114 STRTEST (ABDAY_2
, "Mon");
115 STRTEST (ABDAY_3
, "Tue");
116 STRTEST (ABDAY_4
, "Wed");
117 STRTEST (ABDAY_5
, "Thu");
118 STRTEST (ABDAY_6
, "Fri");
119 STRTEST (ABDAY_7
, "Sat");
120 STRTEST (DAY_1
, "Sunday");
121 STRTEST (DAY_2
, "Monday");
122 STRTEST (DAY_3
, "Tuesday");
123 STRTEST (DAY_4
, "Wednesday");
124 STRTEST (DAY_5
, "Thursday");
125 STRTEST (DAY_6
, "Friday");
126 STRTEST (DAY_7
, "Saturday");
127 STRTEST (ABMON_1
, "Jan");
128 STRTEST (ABMON_2
, "Feb");
129 STRTEST (ABMON_3
, "Mar");
130 STRTEST (ABMON_4
, "Apr");
131 STRTEST (ABMON_5
, "May");
132 STRTEST (ABMON_6
, "Jun");
133 STRTEST (ABMON_7
, "Jul");
134 STRTEST (ABMON_8
, "Aug");
135 STRTEST (ABMON_9
, "Sep");
136 STRTEST (ABMON_10
, "Oct");
137 STRTEST (ABMON_11
, "Nov");
138 STRTEST (ABMON_12
, "Dec");
139 STRTEST (MON_1
, "January");
140 STRTEST (MON_2
, "February");
141 STRTEST (MON_3
, "March");
142 STRTEST (MON_4
, "April");
143 STRTEST (MON_5
, "May");
144 STRTEST (MON_6
, "June");
145 STRTEST (MON_7
, "July");
146 STRTEST (MON_8
, "August");
147 STRTEST (MON_9
, "September");
148 STRTEST (MON_10
, "October");
149 STRTEST (MON_11
, "November");
150 STRTEST (MON_12
, "December");
151 STRTEST (AM_STR
, "AM");
152 STRTEST (PM_STR
, "PM");
153 STRTEST (D_T_FMT
, "%a %b %e %H:%M:%S %Y");
154 STRTEST (D_FMT
, "%m/%d/%y");
155 STRTEST (T_FMT
, "%H:%M:%S");
156 STRTEST (T_FMT_AMPM
, "%I:%M:%S %p");
158 STRTEST (RADIXCHAR
, ".");
159 STRTEST (THOUSEP
, "");
161 STRTEST (YESEXPR
, "^[yY]");
162 STRTEST (NOEXPR
, "^[nN]");
165 WSTRTEST (_NL_WABDAY_1
, L
"Sun");
166 WSTRTEST (_NL_WABDAY_2
, L
"Mon");
167 WSTRTEST (_NL_WABDAY_3
, L
"Tue");
168 WSTRTEST (_NL_WABDAY_4
, L
"Wed");
169 WSTRTEST (_NL_WABDAY_5
, L
"Thu");
170 WSTRTEST (_NL_WABDAY_6
, L
"Fri");
171 WSTRTEST (_NL_WABDAY_7
, L
"Sat");
172 WSTRTEST (_NL_WDAY_1
, L
"Sunday");
173 WSTRTEST (_NL_WDAY_2
, L
"Monday");
174 WSTRTEST (_NL_WDAY_3
, L
"Tuesday");
175 WSTRTEST (_NL_WDAY_4
, L
"Wednesday");
176 WSTRTEST (_NL_WDAY_5
, L
"Thursday");
177 WSTRTEST (_NL_WDAY_6
, L
"Friday");
178 WSTRTEST (_NL_WDAY_7
, L
"Saturday");
179 WSTRTEST (_NL_WABMON_1
, L
"Jan");
180 WSTRTEST (_NL_WABMON_2
, L
"Feb");
181 WSTRTEST (_NL_WABMON_3
, L
"Mar");
182 WSTRTEST (_NL_WABMON_4
, L
"Apr");
183 WSTRTEST (_NL_WABMON_5
, L
"May");
184 WSTRTEST (_NL_WABMON_6
, L
"Jun");
185 WSTRTEST (_NL_WABMON_7
, L
"Jul");
186 WSTRTEST (_NL_WABMON_8
, L
"Aug");
187 WSTRTEST (_NL_WABMON_9
, L
"Sep");
188 WSTRTEST (_NL_WABMON_10
, L
"Oct");
189 WSTRTEST (_NL_WABMON_11
, L
"Nov");
190 WSTRTEST (_NL_WABMON_12
, L
"Dec");
191 WSTRTEST (_NL_WMON_1
, L
"January");
192 WSTRTEST (_NL_WMON_2
, L
"February");
193 WSTRTEST (_NL_WMON_3
, L
"March");
194 WSTRTEST (_NL_WMON_4
, L
"April");
195 WSTRTEST (_NL_WMON_5
, L
"May");
196 WSTRTEST (_NL_WMON_6
, L
"June");
197 WSTRTEST (_NL_WMON_7
, L
"July");
198 WSTRTEST (_NL_WMON_8
, L
"August");
199 WSTRTEST (_NL_WMON_9
, L
"September");
200 WSTRTEST (_NL_WMON_10
, L
"October");
201 WSTRTEST (_NL_WMON_11
, L
"November");
202 WSTRTEST (_NL_WMON_12
, L
"December");
203 WSTRTEST (_NL_WAM_STR
, L
"AM");
204 WSTRTEST (_NL_WPM_STR
, L
"PM");
205 WSTRTEST (_NL_WD_T_FMT
, L
"%a %b %e %H:%M:%S %Y");
206 WSTRTEST (_NL_WD_FMT
, L
"%m/%d/%y");
207 WSTRTEST (_NL_WT_FMT
, L
"%H:%M:%S");
208 WSTRTEST (_NL_WT_FMT_AMPM
, L
"%I:%M:%S %p");
210 STRTEST (_DATE_FMT
, "%a %b %e %H:%M:%S %Z %Y");
211 WSTRTEST (_NL_W_DATE_FMT
, L
"%a %b %e %H:%M:%S %Z %Y");
213 STRTEST (INT_CURR_SYMBOL
, "");
214 STRTEST (CURRENCY_SYMBOL
, "");
215 STRTEST (MON_DECIMAL_POINT
, "");
216 STRTEST (MON_THOUSANDS_SEP
, "");
217 STRTEST (MON_GROUPING
, "");
218 STRTEST (POSITIVE_SIGN
, "");
219 STRTEST (NEGATIVE_SIGN
, "");
220 STRTEST (GROUPING
, "");
222 STRTEST (YESSTR
, "");
225 /* Test the new locale mechanisms. */
226 loc
= newlocale (LC_ALL
, locname
, NULL
);
229 printf ("cannot create locale object for locale %s\n", locname
);
237 #define STRTEST(name, exp) \
238 str = nl_langinfo_l (name, loc); \
239 if (strcmp (str, exp) != 0) \
241 printf ("nl_langinfo_l(" #name ") in locale %s wrong " \
242 "(is \"%s\", should be \"%s\")\n", locname, str, exp); \
246 #define WSTRTEST(name, exp) \
247 wstr = (wchar_t *) nl_langinfo_l (name, loc); \
248 if (wcscmp (wstr, exp) != 0) \
250 printf ("nl_langinfo_l(" #name ") in locale %s wrong " \
251 "(is \"%S\", should be \"%S\")\n", locname, wstr, exp); \
256 STRTEST (ABDAY_1
, "Sun");
257 STRTEST (ABDAY_2
, "Mon");
258 STRTEST (ABDAY_3
, "Tue");
259 STRTEST (ABDAY_4
, "Wed");
260 STRTEST (ABDAY_5
, "Thu");
261 STRTEST (ABDAY_6
, "Fri");
262 STRTEST (ABDAY_7
, "Sat");
263 STRTEST (DAY_1
, "Sunday");
264 STRTEST (DAY_2
, "Monday");
265 STRTEST (DAY_3
, "Tuesday");
266 STRTEST (DAY_4
, "Wednesday");
267 STRTEST (DAY_5
, "Thursday");
268 STRTEST (DAY_6
, "Friday");
269 STRTEST (DAY_7
, "Saturday");
270 STRTEST (ABMON_1
, "Jan");
271 STRTEST (ABMON_2
, "Feb");
272 STRTEST (ABMON_3
, "Mar");
273 STRTEST (ABMON_4
, "Apr");
274 STRTEST (ABMON_5
, "May");
275 STRTEST (ABMON_6
, "Jun");
276 STRTEST (ABMON_7
, "Jul");
277 STRTEST (ABMON_8
, "Aug");
278 STRTEST (ABMON_9
, "Sep");
279 STRTEST (ABMON_10
, "Oct");
280 STRTEST (ABMON_11
, "Nov");
281 STRTEST (ABMON_12
, "Dec");
282 STRTEST (MON_1
, "January");
283 STRTEST (MON_2
, "February");
284 STRTEST (MON_3
, "March");
285 STRTEST (MON_4
, "April");
286 STRTEST (MON_5
, "May");
287 STRTEST (MON_6
, "June");
288 STRTEST (MON_7
, "July");
289 STRTEST (MON_8
, "August");
290 STRTEST (MON_9
, "September");
291 STRTEST (MON_10
, "October");
292 STRTEST (MON_11
, "November");
293 STRTEST (MON_12
, "December");
294 STRTEST (AM_STR
, "AM");
295 STRTEST (PM_STR
, "PM");
296 STRTEST (D_T_FMT
, "%a %b %e %H:%M:%S %Y");
297 STRTEST (D_FMT
, "%m/%d/%y");
298 STRTEST (T_FMT
, "%H:%M:%S");
299 STRTEST (T_FMT_AMPM
, "%I:%M:%S %p");
301 STRTEST (RADIXCHAR
, ".");
302 STRTEST (THOUSEP
, "");
304 STRTEST (YESEXPR
, "^[yY]");
305 STRTEST (NOEXPR
, "^[nN]");
308 WSTRTEST (_NL_WABDAY_1
, L
"Sun");
309 WSTRTEST (_NL_WABDAY_2
, L
"Mon");
310 WSTRTEST (_NL_WABDAY_3
, L
"Tue");
311 WSTRTEST (_NL_WABDAY_4
, L
"Wed");
312 WSTRTEST (_NL_WABDAY_5
, L
"Thu");
313 WSTRTEST (_NL_WABDAY_6
, L
"Fri");
314 WSTRTEST (_NL_WABDAY_7
, L
"Sat");
315 WSTRTEST (_NL_WDAY_1
, L
"Sunday");
316 WSTRTEST (_NL_WDAY_2
, L
"Monday");
317 WSTRTEST (_NL_WDAY_3
, L
"Tuesday");
318 WSTRTEST (_NL_WDAY_4
, L
"Wednesday");
319 WSTRTEST (_NL_WDAY_5
, L
"Thursday");
320 WSTRTEST (_NL_WDAY_6
, L
"Friday");
321 WSTRTEST (_NL_WDAY_7
, L
"Saturday");
322 WSTRTEST (_NL_WABMON_1
, L
"Jan");
323 WSTRTEST (_NL_WABMON_2
, L
"Feb");
324 WSTRTEST (_NL_WABMON_3
, L
"Mar");
325 WSTRTEST (_NL_WABMON_4
, L
"Apr");
326 WSTRTEST (_NL_WABMON_5
, L
"May");
327 WSTRTEST (_NL_WABMON_6
, L
"Jun");
328 WSTRTEST (_NL_WABMON_7
, L
"Jul");
329 WSTRTEST (_NL_WABMON_8
, L
"Aug");
330 WSTRTEST (_NL_WABMON_9
, L
"Sep");
331 WSTRTEST (_NL_WABMON_10
, L
"Oct");
332 WSTRTEST (_NL_WABMON_11
, L
"Nov");
333 WSTRTEST (_NL_WABMON_12
, L
"Dec");
334 WSTRTEST (_NL_WMON_1
, L
"January");
335 WSTRTEST (_NL_WMON_2
, L
"February");
336 WSTRTEST (_NL_WMON_3
, L
"March");
337 WSTRTEST (_NL_WMON_4
, L
"April");
338 WSTRTEST (_NL_WMON_5
, L
"May");
339 WSTRTEST (_NL_WMON_6
, L
"June");
340 WSTRTEST (_NL_WMON_7
, L
"July");
341 WSTRTEST (_NL_WMON_8
, L
"August");
342 WSTRTEST (_NL_WMON_9
, L
"September");
343 WSTRTEST (_NL_WMON_10
, L
"October");
344 WSTRTEST (_NL_WMON_11
, L
"November");
345 WSTRTEST (_NL_WMON_12
, L
"December");
346 WSTRTEST (_NL_WAM_STR
, L
"AM");
347 WSTRTEST (_NL_WPM_STR
, L
"PM");
348 WSTRTEST (_NL_WD_T_FMT
, L
"%a %b %e %H:%M:%S %Y");
349 WSTRTEST (_NL_WD_FMT
, L
"%m/%d/%y");
350 WSTRTEST (_NL_WT_FMT
, L
"%H:%M:%S");
351 WSTRTEST (_NL_WT_FMT_AMPM
, L
"%I:%M:%S %p");
353 STRTEST (_DATE_FMT
, "%a %b %e %H:%M:%S %Z %Y");
354 WSTRTEST (_NL_W_DATE_FMT
, L
"%a %b %e %H:%M:%S %Z %Y");
356 STRTEST (INT_CURR_SYMBOL
, "");
357 STRTEST (CURRENCY_SYMBOL
, "");
358 STRTEST (MON_DECIMAL_POINT
, "");
359 STRTEST (MON_THOUSANDS_SEP
, "");
360 STRTEST (MON_GROUPING
, "");
361 STRTEST (POSITIVE_SIGN
, "");
362 STRTEST (NEGATIVE_SIGN
, "");
363 STRTEST (GROUPING
, "");
365 STRTEST (YESSTR
, "");
368 /* Character class tests. */
369 for (c
= 0; c
< 128; ++c
)
371 #define CLASSTEST(name) \
372 if (is##name (c) != is##name##_l (c, loc)) \
374 printf ("is%s('\\%o') != is%s_l('\\%o')\n", \
375 #name, c, #name, c); \
391 /* Character mapping tests. */
392 #define MAPTEST(name) \
393 if (to##name (c) != to##name##_l (c, loc)) \
395 printf ("to%s('\\%o') != to%s_l('\\%o'): '\\%o' vs '\\%o'\n", \
396 #name, c, #name, c, \
397 to##name (c), to##name##_l (c, loc)); \
404 /* Character class tests, this time for wide characters. Note that
405 this only works because we know that the internal encoding is
407 for (c
= 0; c
< 128; ++c
)
410 #define CLASSTEST(name) \
411 if (isw##name (c) != isw##name##_l (c, loc)) \
413 printf ("isw%s('\\%o') != isw%s_l('\\%o')\n", \
414 #name, c, #name, c); \
430 /* Character mapping tests. Note that
431 this only works because we know that the internal encoding is
434 #define MAPTEST(name) \
435 if (tow##name (c) != tow##name##_l (c, loc)) \
437 printf ("tow%s('\\%o') != tow%s_l('\\%o'): '\\%o' vs '\\%o'\n",\
438 #name, c, #name, c, \
439 tow##name (c), tow##name##_l (c, loc)); \
458 /* First use the name "C". */
459 if (setlocale (LC_ALL
, "C") == NULL
)
461 puts ("cannot set C locale");
465 result
= run_test ("C");
467 /* Then the name "POSIX". */
468 if (setlocale (LC_ALL
, "POSIX") == NULL
)
470 puts ("cannot set POSIX locale");
474 result
|= run_test ("POSIX");