2 * Very basic unit test for locale functions
3 * Test run on win2K (French)
5 * Copyright (c) 2002 YASAR Mehmet
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/test.h"
27 #define eq(received, expected, label, type) \
28 ok((received) == (expected), "%s: got " type " instead of " type, (label),(received),(expected))
30 #define BUFFER_SIZE 50
31 /* Buffer used by callback function */
32 char GlobalBuffer
[BUFFER_SIZE
];
33 #define COUNTOF(x) (sizeof(x)/sizeof(x)[0])
40 * GetUserDefaultLangID
44 void TestGetLocaleInfoA()
48 char buffer
[BUFFER_SIZE
], Expected
[BUFFER_SIZE
];
50 strcpy(Expected
, "Monday");
51 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
52 ok (lcid
== 0x409, "wrong LCID calculated");
54 strcpy(Expected
, "xxxxx");
55 memset( buffer
, 'x', sizeof (buffer
)/sizeof(buffer
[0]) );
56 ret
= GetLocaleInfoA(lcid
, LOCALE_SDAYNAME1
, buffer
, 0);
57 cmp
= strncmp (buffer
, Expected
, strlen(Expected
));
58 ok (cmp
== 0, "GetLocaleInfoA got %s instead of %s", buffer
, Expected
);
59 eq (ret
, strlen("Monday") + 1, "GetLocaleInfoA with len=0", "%d");
61 strcpy(Expected
, "Monxx");
62 memset( buffer
, 'x', sizeof (buffer
)/sizeof(buffer
[0]) );
63 ret
= GetLocaleInfoA(lcid
, LOCALE_SDAYNAME1
, buffer
, 3);
64 cmp
= strncmp (buffer
, Expected
, strlen(Expected
));
65 ok (cmp
== 0, "GetLocaleInfoA got %s instead of %s", buffer
, Expected
);
66 eq (ret
, 0, "GetLocaleInfoA with len = 3", "%d");
68 strcpy(Expected
, "Monday");
69 memset( buffer
, 'x', sizeof (buffer
)/sizeof(buffer
[0]) );
70 ret
= GetLocaleInfoA(lcid
, LOCALE_SDAYNAME1
, buffer
, 10);
71 /* We check also presence of '\0' */
72 cmp
= strncmp (buffer
, Expected
, strlen(Expected
) + 1);
73 ok (cmp
== 0, "GetLocaleInfoA got %s instead of %s", buffer
, Expected
);
74 eq (ret
, strlen(Expected
)+1, "GetLocaleInfoA with len = 10", "%d" );
76 /* We check the whole buffer with strncmp */
77 memset( Expected
, 'x', sizeof (Expected
)/sizeof(Expected
[0]) );
78 strcpy(Expected
, "Monday");
79 memset( buffer
, 'x', sizeof (buffer
)/sizeof(buffer
[0]) );
80 ret
= GetLocaleInfoA(lcid
, LOCALE_SDAYNAME1
, buffer
, BUFFER_SIZE
);
81 cmp
= strncmp (buffer
, Expected
, BUFFER_SIZE
);
82 ok (cmp
== 0, "GetLocaleInfoA got %s instead of %s", buffer
, Expected
);
83 eq (ret
, strlen(Expected
)+1, "GetLocaleInfoA with len = 10", "%d" );
88 void TestGetTimeFormatA()
92 char buffer
[BUFFER_SIZE
], format
[BUFFER_SIZE
], Expected
[BUFFER_SIZE
];
95 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
96 strcpy(format
, "tt HH':'mm'@'ss");
99 /* fill curtime with dummy data */
100 memset(&curtime
, 2, sizeof(SYSTEMTIME
));
101 ret
= GetTimeFormatA(lcid
, TIME_FORCE24HOURFORMAT
, &curtime
, format
, buffer
, sizeof(buffer
));
102 error
= GetLastError ();
103 ok (ret
== 0, "GetTimeFormat should fail on dummy data");
104 eq (error
, ERROR_INVALID_PARAMETER
, "GetTimeFormat GetLastError()", "%d");
107 strcpy(Expected
, "AM 08:56@13");
108 curtime
.wHour
= 8; curtime
.wMinute
= 56;
109 curtime
.wSecond
= 13; curtime
.wMilliseconds
= 22;
110 ret
= GetTimeFormatA(lcid
, TIME_FORCE24HOURFORMAT
, &curtime
, format
, buffer
, sizeof(buffer
));
111 cmp
= strncmp (Expected
, buffer
, strlen(Expected
)+1);
112 ok (cmp
== 0, "GetTimeFormat got %s instead of %s", buffer
, Expected
);
113 eq (ret
, strlen(Expected
)+1, "GetTimeFormat", "%d");
115 /* test with too small buffers */
116 memset(buffer
, 'x', sizeof (buffer
)/sizeof(buffer
[0]) );
117 strcpy(Expected
, "xxxx");
118 ret
= GetTimeFormatA(lcid
, TIME_FORCE24HOURFORMAT
, &curtime
, format
, buffer
, 0);
119 cmp
= strncmp (Expected
, buffer
, 4);
120 ok (cmp
== 0, "GetTimeFormat with len=0 got %s instead of %s", buffer
, Expected
);
121 todo_wine
{ eq (ret
, 12, "GetTimeFormat with len=0", "%d"); }
123 memset(buffer
, 'x', sizeof (buffer
)/sizeof(buffer
[0]) );
124 strcpy(Expected
, "AMxx");
125 ret
= GetTimeFormatA(lcid
, TIME_FORCE24HOURFORMAT
, &curtime
, format
, buffer
, 2);
126 cmp
= strncmp (Expected
, buffer
, 4);
127 todo_wine
{ ok (cmp
== 0, "GetTimeFormat with len=2 got %s instead of %s", buffer
, Expected
); }
128 eq (ret
, 0, "GetTimeFormat with len=2", "%d");
131 void TestGetDateFormatA()
135 char buffer
[BUFFER_SIZE
], format
[BUFFER_SIZE
], Expected
[BUFFER_SIZE
];
138 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
139 strcpy(format
, "ddd',' MMM dd yy");
142 /* fill curtime with dummy data */
143 memset(&curtime
, 2, sizeof(SYSTEMTIME
));
144 memset(buffer
, 'x', sizeof (buffer
)/sizeof(buffer
[0]) );
145 ret
= GetDateFormatA(lcid
, 0, &curtime
, format
, buffer
, sizeof(buffer
));
146 error
= GetLastError ();
147 ok (ret
== 0, "GetDateFormat should fail on dummy data");
148 eq (error
, ERROR_INVALID_PARAMETER
, "GetDateFormat", "%d");
151 strcpy(Expected
, "Sat, May 04 02");
152 memset(buffer
, 'x', sizeof (buffer
)/sizeof(buffer
[0]) );
153 curtime
.wYear
= 2002;
156 curtime
.wDayOfWeek
= 3;
157 ret
= GetDateFormatA(lcid
, 0, &curtime
, format
, buffer
, sizeof(buffer
));
158 cmp
= strncmp (Expected
, buffer
, strlen(Expected
)+1);
159 todo_wine
{ ok (cmp
== 0, "GetDateFormat got %s instead of %s", buffer
, Expected
); }
160 eq (ret
, strlen(Expected
)+1, "GetDateFormat", "%d");
162 /* test format with "'" */
163 memset(buffer
, 'x', sizeof (buffer
)/sizeof(buffer
[0]) );
164 strcpy(format
, "ddd',' MMM dd ''''yy");
165 strcpy(Expected
, "Sat, May 04 '02");
166 ret
= GetDateFormatA(lcid
, 0, &curtime
, format
, buffer
, sizeof(buffer
));
167 cmp
= strncmp (Expected
, buffer
, strlen(Expected
)+1);
168 todo_wine
{ ok (cmp
== 0, "GetDateFormat got %s instead of %s", buffer
, Expected
); }
169 eq (ret
, (strlen(Expected
)+1), "GetDateFormat", "%d");
171 /* test with too small buffers */
172 memset(buffer
, 'x', sizeof (buffer
)/sizeof(buffer
[0]) );
173 strcpy(Expected
, "xxxx");
174 ret
= GetDateFormatA(lcid
, 0, &curtime
, format
, buffer
, 0);
175 cmp
= strncmp (Expected
, buffer
, 4);
176 ok (cmp
== 0, "GetDateFormat got %s instead of %s", buffer
, Expected
);
177 todo_wine
{ eq (ret
, 16, "GetDateFormat with len=0", "%d"); }
179 memset(buffer
, 'x', sizeof (buffer
)/sizeof(buffer
[0]) );
180 strcpy(Expected
, "Saxx");
181 ret
= GetDateFormatA(lcid
, 0, &curtime
, format
, buffer
, 2);
182 cmp
= strncmp (Expected
, buffer
, 4);
183 todo_wine
{ ok (cmp
== 0, "GetDateFormat got %s instead of %s", buffer
, Expected
); }
184 eq (ret
, 0, "GetDateFormat with len=2", "%d");
187 void TestGetDateFormatW()
191 WCHAR buffer
[BUFFER_SIZE
], format
[BUFFER_SIZE
], Expected
[BUFFER_SIZE
];
194 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
198 /* 1a If flags is not zero then format must be null. */
199 ret
= GetDateFormatW (LOCALE_SYSTEM_DEFAULT
, DATE_LONGDATE
, NULL
, format
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
200 error
= ret
? 0 : GetLastError();
201 ok (ret
== 0 && error
== ERROR_INVALID_FLAGS
, "GetDateFormatW allowed flags and format");
203 /* 1b The buffer can only be null if the count is zero */
204 /* For the record other bad pointers result in a page fault (Win98) */
205 ret
= GetDateFormatW (LOCALE_SYSTEM_DEFAULT
, 0, NULL
, format
, NULL
, sizeof(buffer
)/sizeof(buffer
[0]));
206 error
= ret
? 0 : GetLastError();
207 ok (ret
== 0 && error
== ERROR_INVALID_PARAMETER
, "GetDateFormatW did not detect null buffer pointer.");
208 ret
= GetDateFormatW (LOCALE_SYSTEM_DEFAULT
, 0, NULL
, format
, NULL
, 0);
209 error
= ret
? 0 : GetLastError();
210 ok (ret
!= 0 && error
== 0, "GetDateFormatW did not permit null buffer pointer when counting.");
212 /* 1c An incorrect day of week is corrected. */
213 curtime
.wYear
= 2002;
216 curtime
.wDayOfWeek
= 5; /* should be 3 - Wednesday */
220 curtime
.wMilliseconds
= 234;
221 MultiByteToWideChar (CP_ACP
, 0, "dddd d MMMM yyyy", -1, format
, COUNTOF(format
));
222 ret
= GetDateFormatW (lcid
, 0, &curtime
, format
, buffer
, COUNTOF(buffer
));
223 error
= ret
? 0 : GetLastError();
224 MultiByteToWideChar (CP_ACP
, 0, "Wednesday 23 October 2002", -1, Expected
, COUNTOF(Expected
));
225 cmp
= ret
? lstrcmpW (buffer
, Expected
) : 2;
226 ok (ret
== lstrlenW(Expected
)+1 && error
== 0 && cmp
== 0, "Day of week correction failed\n");
228 /* 1d Invalid year, month or day results in error */
230 /* 1e Insufficient space results in error */
232 /* 2. Standard behaviour */
233 /* 1c is a reasonable test */
235 /* 3. Replicated undocumented behaviour */
236 /* e.g. unexepected characters are retained. */
240 void TestGetCurrencyFormat()
243 char buffer
[BUFFER_SIZE
], Expected
[BUFFER_SIZE
], format
[BUFFER_SIZE
];
246 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
248 lcid
= MAKELCID(MAKELANGID(LANG_FRENCH
, SUBLANG_DEFAULT
), SORT_DEFAULT
);
251 memset( buffer
, 'x', sizeof (buffer
)/sizeof(buffer
[0]) );
252 ret
= GetCurrencyFormatA(lcid
, 0, "23,65", NULL
, buffer
, sizeof(buffer
));
253 error
= GetLastError ();
254 cmp
= strncmp ("xxxx", buffer
, 4);
256 ok (cmp
== 0, "GetCurrencyFormat should fail with ','");
257 eq (ret
, 0, "GetCurrencyFormat with ','", "%d");
258 eq (error
, ERROR_INVALID_PARAMETER
, "GetCurrencyFormat", "%d");
260 memset(Expected
, 'x', sizeof (Expected
)/sizeof(Expected
[0]) );
261 strcpy (Expected
, "$23.53");
262 strcpy (format
, "23.53");
263 memset( buffer
, 'x', sizeof (buffer
)/sizeof(buffer
[0]) );
264 ret
= GetCurrencyFormatA(lcid
, 0, format
, NULL
, buffer
, 0);
265 cmp
= strncmp ("xxx", buffer
, 3);
266 ok (cmp
== 0, "GetCurrencyFormat with 0 buffer size");
267 eq (ret
, strlen(Expected
)+1, "GetCurrencyFormat with len=0", "%d");
269 memset( buffer
, 'x', sizeof (buffer
)/sizeof(buffer
[0]) );
270 ret
= GetCurrencyFormatA(lcid
, 0, format
, NULL
, buffer
, 2);
271 cmp
= strncmp ("$2xx", buffer
, 4);
272 ok (cmp
== 0, "GetCurrencyFormat got %s instead of %s", buffer
, Expected
);
273 eq (ret
, 0, "GetCurrencyFormat with len=2", "%d");
275 /* We check the whole buffer with strncmp */
276 memset( buffer
, 'x', sizeof (buffer
)/sizeof(buffer
[0]) );
277 ret
= GetCurrencyFormatA(lcid
, 0, format
, NULL
, buffer
, sizeof(buffer
));
278 cmp
= strncmp (Expected
, buffer
, BUFFER_SIZE
);
279 ok (cmp
== 0, "GetCurrencyFormat got %s instead of %s", buffer
, Expected
);
280 eq (ret
, strlen(Expected
)+1, "GetCurrencyFormat","%d");
285 void TestGetNumberFormat()
288 char buffer
[BUFFER_SIZE
], Expected
[BUFFER_SIZE
], input
[BUFFER_SIZE
];
291 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
293 memset( buffer
, 'x', sizeof (buffer
)/sizeof(buffer
[0]) );
294 ret
= GetNumberFormatA(lcid
, 0, "23,65", NULL
, buffer
, sizeof(buffer
));
295 error
= GetLastError ();
296 cmp
= strncmp ("xxx", buffer
, 3);
297 ok (cmp
== 0, "GetCurrencyFormat");
298 ok (ret
== 0, "GetNumberFormat should return 0");
299 eq (error
, ERROR_INVALID_PARAMETER
, "GetNumberFormat", "%d");
301 strcpy(input
, "2353");
302 strcpy(Expected
, "2,353.00");
303 memset( buffer
, 'x', sizeof (buffer
)/sizeof(buffer
[0]) );
304 ret
= GetNumberFormatA(lcid
, 0, input
, NULL
, buffer
, 0);
305 cmp
= strncmp ("xxx", buffer
, 3);
306 ok (cmp
== 0, "GetNumberFormat with len=0 got %s instead of %s", buffer
, "xxx");
307 eq (ret
, strlen(Expected
)+1, "GetNumberFormat", "%d");
309 strcpy(Expected
, "2,xx");
310 memset( buffer
, 'x', sizeof (buffer
)/sizeof(buffer
[0]) );
311 ret
= GetNumberFormatA(lcid
, 0, input
, NULL
, buffer
, 2);
312 cmp
= strncmp (Expected
, buffer
, 4);
313 ok (cmp
== 0, "GetNumberFormat with len=2 got %s instead of %s", buffer
, Expected
);
314 eq (ret
, 0, "GetNumberFormat", "%d");
316 /* We check the whole buffer with strncmp */
317 memset(Expected
, 'x', sizeof (Expected
)/sizeof(Expected
[0]) );
318 strcpy(Expected
, "2,353.00");
319 memset( buffer
, 'x', sizeof (buffer
)/sizeof(buffer
[0]) );
320 ret
= GetNumberFormatA(lcid
, 0, input
, NULL
, buffer
, sizeof(buffer
));
321 cmp
= strncmp (Expected
, buffer
, BUFFER_SIZE
);
322 ok (cmp
== 0, "GetNumberFormat got %s instead of %s", buffer
, Expected
);
323 eq (ret
, strlen(Expected
)+1, "GetNumberFormat", "%d");
327 /* Callback function used by TestEnumTimeFormats */
328 BOOL CALLBACK
EnumTimeFormatsProc(char * lpTimeFormatString
)
330 trace("%s\n", lpTimeFormatString
);
331 strcpy(GlobalBuffer
, lpTimeFormatString
);
338 void TestEnumTimeFormats()
342 char Expected
[BUFFER_SIZE
];
344 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
345 memset( GlobalBuffer
, 'x', sizeof (GlobalBuffer
)/sizeof(GlobalBuffer
[0]) );
346 strcpy(Expected
, "h:mm:ss tt");
347 ret
= EnumTimeFormatsA(EnumTimeFormatsProc
, lcid
, 0);
349 eq (ret
, 1, "EnumTimeFormats should return 1", "%d");
350 ok (strncmp (GlobalBuffer
, Expected
, strlen(Expected
)) == 0,
351 "EnumTimeFormats failed");
352 ok (ret
== 1, "EnumTimeFormats should return 1");
356 void TestCompareStringA()
360 char buffer1
[BUFFER_SIZE
], buffer2
[BUFFER_SIZE
];
362 lcid
= MAKELCID(MAKELANGID(LANG_FRENCH
, SUBLANG_DEFAULT
), SORT_DEFAULT
);
364 strcpy(buffer1
, "Salut"); strcpy(buffer2
, "Salute");
365 ret
= CompareStringA(lcid
, NORM_IGNORECASE
, buffer1
, -1, buffer2
, -1);
366 ok (ret
== 1, "CompareStringA (st1=%s str2=%s) expected result=1", buffer1
, buffer2
);
368 strcpy(buffer1
, "Salut"); strcpy(buffer2
, "saLuT");
369 ret
= CompareStringA(lcid
, NORM_IGNORECASE
, buffer1
, -1, buffer2
, -1);
370 ok (ret
== 2, "CompareStringA (st1=%s str2=%s) expected result=2", buffer1
, buffer2
);
372 strcpy(buffer1
, "Salut"); strcpy(buffer2
, "hola");
373 ret
= CompareStringA(lcid
, NORM_IGNORECASE
, buffer1
, -1, buffer2
, -1);
374 ok (ret
== 3, "CompareStringA (st1=%s str2=%s) expected result=3", buffer1
, buffer2
);
376 strcpy(buffer1
, "héhé"); strcpy(buffer2
, "hèhè");
377 ret
= CompareStringA(lcid
, NORM_IGNORECASE
, buffer1
, -1, buffer2
, -1);
378 ok (ret
== 1, "CompareStringA (st1=%s str2=%s) expected result=1", buffer1
, buffer2
);
380 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
382 strcpy(buffer1
, "héhé"); strcpy(buffer2
, "hèhè");
383 ret
= CompareStringA(lcid
, NORM_IGNORECASE
, buffer1
, -1, buffer2
, -1);
384 ok (ret
== 1, "CompareStringA (st1=%s str2=%s) expected result=1", buffer1
, buffer2
);
386 ret
= CompareStringA(lcid
, NORM_IGNORECASE
, buffer1
, -1, buffer2
, 0);
387 ok (ret
== 3, "CompareStringA (st1=%s str2=%s) expected result=3", buffer1
, buffer2
);
394 TestEnumTimeFormats();
396 TestGetLocaleInfoA();
397 TestGetTimeFormatA();
398 TestGetDateFormatA();
399 TestGetDateFormatW();
400 TestGetNumberFormat();
401 TestGetCurrencyFormat();
402 TestCompareStringA();