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 128
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 /* HTMLKit and "Font xplorer lite" expect GetLocaleInfoA to
55 * partially fill the buffer even if it is too short. See bug 637.
57 strcpy(Expected, "xxxxx");
58 memset( buffer, 'x', sizeof(buffer) );
59 ret = GetLocaleInfoA(lcid, LOCALE_SDAYNAME1, buffer, 0);
60 cmp = strncmp (buffer, Expected, strlen(Expected));
61 ok (cmp == 0, "GetLocaleInfoA got %s instead of %s", buffer, Expected);
62 eq (ret, lstrlenA("Monday") + 1, "GetLocaleInfoA with len=0", "%d");
64 strcpy(Expected, "Monxx");
65 memset( buffer, 'x', sizeof(buffer) );
66 ret = GetLocaleInfoA(lcid, LOCALE_SDAYNAME1, buffer, 3);
67 cmp = strncmp (buffer, Expected, strlen(Expected));
68 ok (cmp == 0, "GetLocaleInfoA got %s instead of %s", buffer, Expected);
69 eq (ret, 0, "GetLocaleInfoA with len = 3", "%d");
71 strcpy(Expected, "Monday");
72 memset( buffer, 'x', sizeof(buffer) );
73 ret = GetLocaleInfoA(lcid, LOCALE_SDAYNAME1, buffer, 10);
74 /* We check also presence of '\0' */
75 cmp = strncmp (buffer, Expected, strlen(Expected) + 1);
76 ok (cmp == 0, "GetLocaleInfoA got %s instead of %s", buffer, Expected);
77 eq (ret, lstrlenA(Expected)+1, "GetLocaleInfoA with len = 10", "%d" );
79 /* We check the whole buffer with strncmp */
80 memset( Expected, 'x', sizeof(Expected) );
81 strcpy(Expected, "Monday");
82 memset( buffer, 'x', sizeof(buffer) );
83 ret = GetLocaleInfoA(lcid, LOCALE_SDAYNAME1, buffer, BUFFER_SIZE);
84 cmp = strncmp (buffer, Expected, BUFFER_SIZE);
85 ok (cmp == 0, "GetLocaleInfoA got %s instead of %s", buffer, Expected);
86 eq (ret, lstrlenA(Expected)+1, "GetLocaleInfoA with len = 10", "%d" );
91 void TestGetTimeFormatA()
95 char buffer[BUFFER_SIZE], format[BUFFER_SIZE], Expected[BUFFER_SIZE];
98 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT );
99 strcpy(format, "tt HH':'mm'@'ss");
101 /* fill curtime with dummy data */
102 memset(&curtime, 2, sizeof(SYSTEMTIME));
103 memset(buffer, '0', sizeof(buffer));
104 ret = GetTimeFormatA(lcid, TIME_FORCE24HOURFORMAT, &curtime, format, buffer, COUNTOF(buffer));
105 error = GetLastError ();
106 ok (ret == 0, "GetTimeFormat should fail on dummy data");
107 eq (error, ERROR_INVALID_PARAMETER, "GetTimeFormat GetLastError()", "%d");
108 SetLastError(NO_ERROR); /* clear out the last error */
110 /* test that we can correctly produce the expected output, not a very */
111 /* demanding test ;-) */
112 strcpy(Expected, "AM 08:56@13");
113 curtime.wHour = 8; curtime.wMinute = 56;
114 curtime.wSecond = 13; curtime.wMilliseconds = 22;
115 memset(buffer, '0', sizeof(buffer));
116 ret = GetTimeFormatA(lcid, TIME_FORCE24HOURFORMAT, &curtime, format, buffer, COUNTOF(buffer));
117 cmp = strncmp (Expected, buffer, strlen(Expected)+1);
118 ok (cmp == 0, "GetTimeFormat got %s instead of %s", buffer, Expected);
119 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
121 /* check that the size reported by the above call is accuate */
122 memset(buffer, 'x', sizeof(buffer));
123 ret = GetTimeFormatA(lcid, TIME_FORCE24HOURFORMAT, &curtime, format, buffer, ret);
124 ok(ret==lstrlenA(Expected)+1 && GetLastError()==0,
125 "GetTimeFormat(right size): ret=%d error=%ld\n",ret,GetLastError());
126 ok(buffer[0] != 'x',"GetTimeFormat(right size): buffer=[%s]\n",buffer);
128 /* test failure due to insufficent buffer */
129 ret = GetTimeFormatA(lcid, TIME_FORCE24HOURFORMAT, &curtime, format, buffer, 2);
130 ok(ret==0 && GetLastError()==ERROR_INSUFFICIENT_BUFFER,
131 "GetTimeFormat(len=2): ret=%d error=%ld", ret, GetLastError());
133 /* test with too small buffers */
135 memset(buffer, '0', sizeof(buffer));
136 ret = GetTimeFormatA(lcid, TIME_FORCE24HOURFORMAT, &curtime, format, NULL, 0);
137 ok(ret==lstrlenA(Expected)+1 && GetLastError()==0,
138 "GetTimeFormat(len=0): ret=%d error=%ld\n",ret,GetLastError());
140 /************************************/
141 /* test out TIME_NOMINUTESORSECONDS */
142 strcpy(Expected, "8 AM");
143 memset(buffer, '0', sizeof(buffer));
144 ret = GetTimeFormatA(lcid, TIME_NOMINUTESORSECONDS, &curtime, NULL, buffer, sizeof(buffer));
145 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
146 ok (cmp == 0, "GetTimeFormat got '%s' instead of '%s'", buffer, Expected);
147 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
149 /* test out TIME_NOMINUTESORSECONDS with complex format strings */
150 strcpy(Expected, "4");
151 memset(buffer, '0', sizeof(buffer));
152 ret = GetTimeFormatA(lcid, TIME_NOMINUTESORSECONDS, &curtime, "m1s2m3s4", buffer, sizeof(buffer));
153 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
154 ok (cmp == 0, "GetTimeFormat got '%s' instead of '%s'", buffer, Expected);
155 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
158 /************************************/
159 /* test out TIME_NOSECONDS */
160 strcpy(Expected, "8:56 AM");
161 ret = GetTimeFormatA(lcid, TIME_NOSECONDS, &curtime, NULL, buffer, sizeof(buffer));
162 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
163 ok (cmp == 0, "GetTimeFormat got '%s' instead of '%s'", buffer, Expected);
164 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
166 /* test out TIME_NOSECONDS with a format string of "h:m:s tt" */
167 strcpy(Expected, "8:56 AM");
168 memset(buffer, '0', sizeof(buffer));
169 ret = GetTimeFormatA(lcid, TIME_NOSECONDS, &curtime, "h:m:s tt", buffer, sizeof(buffer));
170 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
171 ok (cmp == 0, "GetTimeFormat got '%s' instead of '%s'", buffer, Expected);
172 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
174 /* test out TIME_NOSECONDS a strange format string of multiple delimiters "h@:m@:s tt" */
175 /* expected behavior is to turn "hD1D2...mD3D4...sD5D6...tt" and turn this into */
176 /* "hD1D2...mD3D4...tt" */
177 strcpy(Expected, "8.@:56.@:AM");
178 memset(buffer, '0', sizeof(buffer));
179 ret = GetTimeFormatA(lcid, TIME_NOSECONDS, &curtime, "h.@:m.@:s.@:tt", buffer, sizeof(buffer));
180 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
181 ok (cmp == 0, "GetTimeFormat got '%s' instead of '%s'", buffer, Expected);
182 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
184 /* test out TIME_NOSECONDS with an string of "1s2s3s4" */
185 /* expect to see only "3" */
186 strcpy(Expected, "3");
187 memset(buffer, '0', sizeof(buffer));
188 ret = GetTimeFormatA(lcid, TIME_NOSECONDS, &curtime, "s1s2s3", buffer, sizeof(buffer));
189 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
190 ok (cmp == 0, "GetTimeFormat got '%s' instead of '%s'", buffer, Expected);
191 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
193 /************************/
194 /* Test out time marker */
195 /* test out time marker(AM/PM) behavior */
196 strcpy(Expected, "A/AM");
197 memset(buffer, '0', sizeof(buffer));
198 ret = GetTimeFormatA(lcid, 0, &curtime, "t/tt", buffer, sizeof(buffer));
199 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
200 ok (cmp == 0, "GetTimeFormat got '%s' instead of %s", buffer, Expected);
201 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
203 /* time marker testing part 2 */
205 strcpy(Expected, "P/PM");
206 memset(buffer, '0', sizeof(buffer));
207 ret = GetTimeFormatA(lcid, 0, &curtime, "t/tt", buffer, sizeof(buffer));
208 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
209 ok (cmp == 0, "GetTimeFormat got '%s' instead of %s", buffer, Expected);
210 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
212 /******************************/
213 /* test out TIME_NOTIMEMARKER */
214 /* NOTE: TIME_NOTIMEMARKER elminates all text around any time marker */
215 /* formatting character until the previous or next formatting character */
216 strcpy(Expected, "156");
217 memset(buffer, '0', sizeof(buffer));
218 ret = GetTimeFormatA(lcid, TIME_NOTIMEMARKER, &curtime, "h1t2tt3m", buffer, sizeof(buffer));
219 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
220 ok (cmp == 0, "GetTimeFormat got '%s' instead of %s", buffer, Expected);
221 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
223 /***********************************/
224 /* test out TIME_FORCE24HOURFORMAT */
225 strcpy(Expected, "13:56:13 PM");
226 memset(buffer, '0', sizeof(buffer));
227 ret = GetTimeFormatA(lcid, TIME_FORCE24HOURFORMAT, &curtime, "h:m:s tt", buffer, sizeof(buffer));
228 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
229 ok (cmp == 0, "GetTimeFormat got '%s' instead of %s", buffer, Expected);
230 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
232 /* check to confirm that unlike what msdn documentation suggests, the time marker */
233 /* is not added under TIME_FORCE24HOURFORMAT */
234 strcpy(Expected, "13:56:13");
235 memset(buffer, '0', sizeof(buffer));
236 ret = GetTimeFormatA(lcid, TIME_FORCE24HOURFORMAT, &curtime, "h:m:s", buffer, sizeof(buffer));
237 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
238 ok (cmp == 0, "GetTimeFormat got '%s' instead of %s", buffer, Expected);
239 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
242 /*********************************************/
243 /* test advanced formatting of GetTimeFormat */
245 /* test for 24 hour conversion and for leading zero */
246 /* NOTE: we do not test the "hh or HH" case since hours is two digits */
247 /* "h hh H HH m mm s ss t tt" */
248 curtime.wHour = 14; /* change this to 14 or 2pm */
251 strcpy(Expected, "2 02 14 14 5 05 3 03 P PM");
252 memset(buffer, '0', sizeof(buffer));
253 ret = GetTimeFormatA(lcid, 0, &curtime, "h hh H HH m mm s ss t tt",
254 buffer, sizeof(buffer));
255 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
256 ok (cmp == 0, "GetTimeFormat got '%s' instead of '%s'", buffer, Expected);
257 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
259 /* complete testing on the advanced formatting by testing "hh" and "HH" */
260 /* 0 hour is 12 o'clock or 00 hundred hours */
262 strcpy(Expected, "12/0/12/00");
263 memset(buffer, '0', sizeof(buffer));
264 ret = GetTimeFormatA(lcid, 0, &curtime, "h/H/hh/HH", buffer, sizeof(buffer));
265 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
266 ok (cmp == 0, "GetTimeFormat got '%s' instead of '%s'", buffer, Expected);
267 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
269 /* test for LOCALE_NOUSEROVERRIDE set, lpFormat must be NULL */
270 strcpy(Expected, "0:5:3 AM");
271 memset(buffer, '0', sizeof(buffer));
272 ret = GetTimeFormatA(lcid, LOCALE_NOUSEROVERRIDE, &curtime, "h:m:s tt", buffer, sizeof(buffer));
273 /* NOTE: we expect this to FAIL */
274 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
275 ok (ret == 0, "GetTimeFormat succeeded instead of failing for LOCALE_NOUSEROVERRIDE and a non-null lpFormat\n");
277 /* try to convert formatting strings with more than two letters */
278 /* "h:hh:hhh:H:HH:HHH:m:mm:mmm:M:MM:MMM:s:ss:sss:S:SS:SSS" */
279 /* NOTE: we expect any letter for which there is an upper case value */
280 /* we should expect to see a replacement. For letters that DO NOT */
281 /* have upper case values we expect to see NO REPLACEMENT */
282 curtime.wHour = 8; curtime.wMinute = 56;
283 curtime.wSecond = 13; curtime.wMilliseconds = 22;
284 strcpy(Expected, "8:08:08 8:08:08 56:56:56 M:MM:MMM 13:13:13 S:SS:SSS");
285 memset(buffer, '0', sizeof(buffer));
286 ret = GetTimeFormatA(lcid, 0, &curtime, "h:hh:hhh H:HH:HHH m:mm:mmm M:MM:MMM s:ss:sss S:SS:SSS", buffer, sizeof(buffer));
287 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
288 ok (cmp == 0, "GetTimeFormat got '%s' instead of '%s'", buffer, Expected);
289 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
291 /* test that if the size of the buffer is zero that the buffer is not modified */
292 /* and that the number of necessary characters is returned */
293 /* NOTE: The count includes the terminating null. */
294 strcpy(buffer, "THIS SHOULD NOT BE MODIFIED");
295 strcpy(Expected, "THIS SHOULD NOT BE MODIFIED");
296 ret = GetTimeFormatA(lcid, 0, &curtime, "h", buffer, 0);
297 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
298 ok (cmp == 0, "GetTimeFormat got '%s' instead of '%s'", buffer, Expected);
299 eq (ret, 2, "GetTimeFormat", "%d"); /* we expect to require two characters of space from "h" */
301 /* test that characters in single quotation marks are ignored and left in */
302 /* the same location in the output string */
303 strcpy(Expected, "8 h 8 H 08 HH 56 m 13 s A t AM tt");
304 memset(buffer, '0', sizeof(buffer));
305 ret = GetTimeFormatA(lcid, 0, &curtime, "h 'h' H 'H' HH 'HH' m 'm' s 's' t 't' tt 'tt'", buffer, sizeof(buffer));
306 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
307 ok (cmp == 0, "GetTimeFormat got '%s' instead of '%s'", buffer, Expected);
308 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
310 /* test the printing of the single quotation marks when */
311 /* we use an invalid formatting string of "'''" instead of "''''" */
312 strcpy(Expected, "'");
313 memset(buffer, '0', sizeof(buffer));
314 ret = GetTimeFormatA(lcid, 0, &curtime, "'''", buffer, sizeof(buffer));
315 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
316 ok (cmp == 0, "GetTimeFormat got '%s' instead of '%s'", buffer, Expected);
317 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
319 /* test that msdn suggested single quotation usage works as expected */
320 strcpy(Expected, "'");
321 memset(buffer, '0', sizeof(buffer));
322 ret = GetTimeFormatA(lcid, 0, &curtime, "''''", buffer, sizeof(buffer));
323 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
324 ok (cmp == 0, "GetTimeFormat got '%s' instead of '%s'", buffer, Expected);
325 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
327 /* test for more normal use of single quotation mark */
328 strcpy(Expected, "08");
329 memset(buffer, '0', sizeof(buffer));
330 ret = GetTimeFormatA(lcid, 0, &curtime, "''HHHHHH", buffer, sizeof(buffer));
331 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
332 ok (cmp == 0, "GetTimeFormat got '%s' instead of '%s'", buffer, Expected);
333 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
335 /* and test for normal use of the single quotation mark */
336 strcpy(Expected, "'HHHHHH");
337 memset(buffer, '0', sizeof(buffer));
338 ret = GetTimeFormatA(lcid, 0, &curtime, "'''HHHHHH'", buffer, sizeof(buffer));
339 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
340 ok (cmp == 0, "GetTimeFormat got '%s' instead of '%s'", buffer, Expected);
341 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
343 /* test for more odd use of the single quotation mark */
344 strcpy(Expected, "'HHHHHH");
345 memset(buffer, '0', sizeof(buffer));
346 ret = GetTimeFormatA(lcid, 0, &curtime, "'''HHHHHH", buffer, sizeof(buffer));
347 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
348 ok (cmp == 0, "GetTimeFormat got '%s' instead of '%s'", buffer, Expected);
349 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
351 /* test that with TIME_NOTIMEMARKER that even if something is defined */
352 /* as a literal we drop it before and after the markers until the next */
353 /* formatting character */
354 strcpy(Expected, "");
355 memset(buffer, '0', sizeof(buffer));
356 ret = GetTimeFormatA(lcid, TIME_NOTIMEMARKER, &curtime, "'123'tt", buffer, sizeof(buffer));
357 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
358 ok (cmp == 0, "GetTimeFormat got '%s' instead of '%s'", buffer, Expected);
359 eq (ret, lstrlenA(Expected)+1, "GetTimeFormat", "%d");
361 /* test for expected return and error value when we have a */
362 /* non-null format and LOCALE_NOUSEROVERRIDE for flags */
363 SetLastError(NO_ERROR); /* reset last error value */
364 memset(buffer, '0', sizeof(buffer));
365 ret = GetTimeFormatA(lcid, LOCALE_NOUSEROVERRIDE, &curtime, "'123'tt", buffer, sizeof(buffer));
366 error = GetLastError();
367 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
368 ok ((ret == 0) && (error == ERROR_INVALID_FLAGS), "GetTimeFormat got ret of '%d' and error of '%d'", ret, error);
370 /* test that invalid time values result in ERROR_INVALID_PARAMETER */
371 /* and a return value of 0 */
373 SetLastError(NO_ERROR); /* reset last error value */
374 memset(buffer, '0', sizeof(buffer));
375 ret = GetTimeFormatA(lcid, 0, &curtime, "'123'tt", buffer, sizeof(buffer));
376 error = GetLastError();
377 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
378 ok ((ret == 0) && (error == ERROR_INVALID_PARAMETER), "GetTimeFormat got ret of '%d' and error of '%d'", ret, error);
380 /* test that invalid information in the date section of the current time */
381 /* doesn't result in an error since GetTimeFormat() should ignore this information */
382 curtime.wHour = 12; /* valid wHour */
383 curtime.wMonth = 60; /* very invalid wMonth */
384 strcpy(Expected, "12:56:13");
385 SetLastError(NO_ERROR); /* reset last error value */
386 ret = GetTimeFormatA(lcid, 0, &curtime, "h:m:s", buffer, sizeof(buffer));
387 error = GetLastError();
388 cmp = strncmp(buffer, Expected, BUFFER_SIZE);
389 ok ((ret == lstrlenA(Expected)+1) && (error == NO_ERROR), "GetTimeFormat got ret of '%d' and error of '%d' and a buffer of '%s'", ret, error, buffer);
392 void TestGetDateFormatA()
396 char buffer[BUFFER_SIZE], format[BUFFER_SIZE], Expected[BUFFER_SIZE];
399 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT );
400 strcpy(format, "ddd',' MMM dd yy");
402 /* test for failure on dummy data */
403 memset(&curtime, 2, sizeof(SYSTEMTIME));
404 memset(buffer, '0', sizeof(buffer));
405 SetLastError(NO_ERROR);
406 ret = GetDateFormatA(lcid, 0, &curtime, format, buffer, COUNTOF(buffer));
407 error = GetLastError ();
408 ok(ret == 0, "GetDateFormat should fail on dummy data");
409 eq(error, ERROR_INVALID_PARAMETER, "GetDateFormat", "%d");
411 /* test for a simple case of date conversion */
413 strcpy(Expected, "Sat, May 04 02");
414 curtime.wYear = 2002;
417 curtime.wDayOfWeek = 3;
418 memset(buffer, 0, sizeof(buffer));
419 ret = GetDateFormatA(lcid, 0, &curtime, format, buffer, COUNTOF(buffer));
420 cmp = strncmp (Expected, buffer, strlen(Expected)+1);
421 ok (cmp == 0, "GetDateFormat got %s instead of %s", buffer, Expected);
422 /* Uncomment the below when todo_wine is removed */
423 /* eq (ret, lstrlenA(Expected)+1, "GetDateFormat", "%d"); */
426 /* test format with "'" */
428 strcpy(format, "ddd',' MMM dd ''''yy");
429 strcpy(Expected, "Sat, May 04 '02");
430 memset(buffer, 0, sizeof(buffer));
431 ret = GetDateFormatA(lcid, 0, &curtime, format, buffer, COUNTOF(buffer));
432 cmp = strncmp (Expected, buffer, strlen(Expected)+1);
433 ok (cmp == 0, "GetDateFormat got %s instead of %s", buffer, Expected);
434 /* Uncomment the below when todo_wine is removed */
435 /* eq (ret, lstrlenA(Expected)+1, "GetDateFormat", "%d"); */
438 /* test for success with dummy time data */
441 memset(buffer, 0, sizeof(buffer));
442 ret = GetDateFormatA(lcid, 0, &curtime, format, buffer, COUNTOF(buffer));
443 cmp = strncmp (Expected, buffer, strlen(Expected)+1);
444 ok (cmp == 0, "GetDateFormat got %s instead of %s", buffer, Expected);
445 /* Uncomment the below when the todo_wine is removed */
446 /* eq (ret, lstrlenA(Expected)+1, "GetDateFormat", "%d"); */
449 /* test that we retrieve the expected size for the necessary output of this string */
450 SetLastError(NO_ERROR);
451 memset(buffer, 0, sizeof(buffer));
452 ret = GetDateFormatA(lcid, 0, &curtime, format, NULL, 0);
453 ok(ret==lstrlenA(Expected)+1 && GetLastError() == 0,
454 "GetDateFormat(len=0): ret=%d error=%ld buffer='%s', expected NO_ERROR(0)\n",ret,GetLastError(), buffer);
456 /* test that the expected size matches the actual required size by passing */
457 /* in the expected size */
458 memset(buffer, '0', sizeof(buffer));
459 ret = GetDateFormatA(lcid, 0, &curtime, format, buffer, ret);
460 ok(ret==lstrlenA(Expected)+1 && GetLastError()==0,
461 "GetDateFormat(right size): ret=%d error=%ld, buffer = '%s'\n",ret,GetLastError(), buffer);
462 ok(buffer[0]!='x',"GetDateFormat(right size): buffer=[%s]\n",buffer);
464 /* test that a buffer shorter than the necessary size results in ERROR_INSUFFICIENT_BUFFER */
465 ret = GetDateFormatA(lcid, 0, &curtime, format, buffer, 2);
466 ok(ret==0 && GetLastError()==ERROR_INSUFFICIENT_BUFFER,
467 "GetDateFormat(len=2): ret=%d error=%ld", ret, GetLastError());
469 /* test for default behavior being DATE_SHORTDATE */
471 strcpy(Expected, "5/4/02");
472 memset(buffer, '0', sizeof(buffer));
473 ret = GetDateFormat(lcid, 0, &curtime, NULL, buffer, sizeof(buffer));
474 cmp = strncmp (Expected, buffer, strlen(Expected)+1);
475 ok (cmp == 0, "GetDateFormat got '%s' instead of '%s'", buffer, Expected);
476 eq (ret, lstrlenA(Expected)+1, "GetDateFormat", "%d");
481 /* test for expected DATE_LONGDATE behavior with null format */
482 strcpy(Expected, "Saturday, May 04, 2002");
483 memset(buffer, '0', sizeof(buffer));
484 ret = GetDateFormat(lcid, DATE_LONGDATE, &curtime, NULL, buffer, sizeof(buffer));
485 cmp = strncmp (Expected, buffer, strlen(Expected)+1);
486 ok (cmp == 0, "GetDateFormat got '%s' instead of '%s'", buffer, Expected);
487 eq (ret, lstrlenA(Expected)+1, "GetDateFormat", "%d");
490 /* test for expected DATE_YEARMONTH behavior with null format */
491 /* NT4 returns ERROR_INVALID_FLAGS for DATE_YEARMONTH */
493 strcpy(Expected, "");
495 SetLastError(NO_ERROR);
496 memset(buffer, '0', sizeof(buffer));
497 ret = GetDateFormat(lcid, DATE_YEARMONTH, &curtime, NULL, buffer, sizeof(buffer));
498 error = GetLastError();
499 cmp = strncmp (Expected, buffer, strlen(Expected)+1);
500 ok (ret == 0 && (error == ERROR_INVALID_FLAGS), "GetDateFormat check DATE_YEARMONTH with null format expected ERROR_INVALID_FLAGS got return of '%d' and error of '%d'", ret, error);
503 /* Test that using invalid DATE_* flags results in the correct error */
504 /* and return values */
505 strcpy(format, "m/d/y");
506 strcpy(Expected, "Saturday May 2002");
507 SetLastError(NO_ERROR);
508 memset(buffer, '0', sizeof(buffer));
509 ret = GetDateFormat(lcid, DATE_YEARMONTH | DATE_SHORTDATE | DATE_LONGDATE, &curtime, format, buffer, sizeof(buffer));
510 error = GetLastError();
511 cmp = strncmp (Expected, buffer, strlen(Expected)+1);
512 ok ((ret == 0) && (error == ERROR_INVALID_FLAGS), "GetDateFormat checking for mutually exclusive flags got '%s' instead of '%s', got error of %d, expected ERROR_INVALID_FLAGS", buffer, Expected, error);
515 void TestGetDateFormatW()
519 WCHAR buffer[BUFFER_SIZE], format[BUFFER_SIZE], Expected[BUFFER_SIZE];
522 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT );
526 /* 1a If flags is not zero then format must be null. */
527 ret = GetDateFormatW (LOCALE_SYSTEM_DEFAULT, DATE_LONGDATE, NULL, format, buffer, COUNTOF(buffer));
528 if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
530 error = ret ? 0 : GetLastError();
531 ok (ret == 0 && error == ERROR_INVALID_FLAGS, "GetDateFormatW allowed flags and format");
533 /* 1b The buffer can only be null if the count is zero */
534 /* For the record other bad pointers result in a page fault (Win98) */
535 ret = GetDateFormatW (lcid, 0, NULL, format, NULL, COUNTOF(buffer));
536 error = ret ? 0 : GetLastError();
537 ok (ret == 0 && error == ERROR_INVALID_PARAMETER, "GetDateFormatW did not detect null buffer pointer.");
538 ret = GetDateFormatW (lcid, 0, NULL, format, NULL, 0);
539 error = ret ? 0 : GetLastError();
540 ok (ret != 0 && error == 0, "GetDateFormatW did not permit null buffer pointer when counting.");
542 /* 1c An incorrect day of week is corrected. */
543 curtime.wYear = 2002;
546 curtime.wDayOfWeek = 5; /* should be 3 - Wednesday */
550 curtime.wMilliseconds = 234;
551 MultiByteToWideChar (CP_ACP, 0, "dddd d MMMM yyyy", -1, format, COUNTOF(format));
552 ret = GetDateFormatW (lcid, 0, &curtime, format, buffer, COUNTOF(buffer));
553 error = ret ? 0 : GetLastError();
554 MultiByteToWideChar (CP_ACP, 0, "Wednesday 23 October 2002", -1, Expected, COUNTOF(Expected));
555 cmp = ret ? lstrcmpW (buffer, Expected) : 2;
556 ok (ret == lstrlenW(Expected)+1 && error == 0 && cmp == 0, "Day of week correction failed\n");
560 void TestGetCurrencyFormat()
563 char buffer[BUFFER_SIZE], Expected[BUFFER_SIZE], format[BUFFER_SIZE];
566 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT );
568 lcid = MAKELCID(MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT), SORT_DEFAULT );
571 memset( buffer, 'x', sizeof(buffer) );
572 ret = GetCurrencyFormatA(lcid, 0, "23,65", NULL, buffer, COUNTOF(buffer));
573 error = GetLastError ();
574 cmp = strncmp ("xxxx", buffer, 4);
576 ok (cmp == 0, "GetCurrencyFormat should fail with ','");
577 eq (ret, 0, "GetCurrencyFormat with ','", "%d");
578 eq (error, ERROR_INVALID_PARAMETER, "GetCurrencyFormat", "%d");
580 /* We check the whole buffer with strncmp */
581 strcpy (Expected, "$23.53");
582 strcpy (format, "23.53");
583 memset( buffer, 'x', sizeof(buffer) );
584 ret = GetCurrencyFormatA(lcid, 0, format, NULL, buffer, COUNTOF(buffer));
585 cmp = strncmp (Expected, buffer, BUFFER_SIZE);
586 ok (cmp == 0, "GetCurrencyFormatA got %s instead of %s", buffer, Expected);
587 eq (ret, lstrlenA(Expected)+1, "GetCurrencyFormatA","%d");
589 /* Test too small buffers */
591 ret = GetCurrencyFormatA(lcid, 0, format, NULL, NULL, 0);
592 ok(ret==lstrlenA(Expected)+1 && GetLastError()==0,
593 "GetCurrencyFormatA(size=0): ret=%d error=%ld", ret, GetLastError());
595 memset( buffer, 'x', sizeof(buffer) );
596 ret = GetCurrencyFormatA(lcid, 0, format, NULL, buffer, ret);
597 ok(strcmp(buffer,Expected)==0,
598 "GetCurrencyFormatA(right size): got [%s] instead of [%s]", buffer, Expected);
599 eq (ret, lstrlenA(Expected)+1, "GetCurrencyFormatA(right size)", "%d");
601 ret = GetCurrencyFormatA(lcid, 0, format, NULL, buffer, 2);
602 ok(ret==0 && GetLastError()==ERROR_INSUFFICIENT_BUFFER,
603 "GetCurrencyFormatA(size=2): ret=%d error=%ld", ret, GetLastError());
607 void TestGetNumberFormat()
610 char buffer[BUFFER_SIZE], Expected[BUFFER_SIZE], input[BUFFER_SIZE];
614 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT );
616 memset( buffer, 'x', sizeof(buffer) );
617 ret = GetNumberFormatA(lcid, 0, "23,65", NULL, buffer, COUNTOF(buffer));
618 error = GetLastError ();
619 cmp = strncmp ("xxx", buffer, 3);
620 ok (cmp == 0, "GetNumberFormat");
621 ok (ret == 0, "GetNumberFormat should return 0");
622 eq (error, ERROR_INVALID_PARAMETER, "GetNumberFormat", "%d");
624 strcpy(input, "2353");
625 strcpy(Expected, "2,353.00");
627 ret = GetNumberFormatA(lcid, 0, input, NULL, NULL, 0);
628 ok(ret==lstrlenA(Expected)+1 && GetLastError()==0,
629 "GetNumberFormatA(size=0): ret=%d error=%ld", ret, GetLastError());
631 memset( buffer, 'x', sizeof(buffer) );
632 ret = GetNumberFormatA(lcid, 0, input, NULL, buffer, ret);
633 ok(strcmp(buffer,Expected)==0,
634 "GetNumberFormatA(right size): got [%s] instead of [%s]", buffer, Expected);
635 eq(ret, lstrlenA(Expected)+1, "GetNumberFormat", "%d");
637 ret = GetNumberFormatA(lcid, 0, input, NULL, buffer, 2);
638 ok(ret==0 && GetLastError()==ERROR_INSUFFICIENT_BUFFER,
639 "GetNumberFormatA(size=2): ret=%d error=%ld", ret, GetLastError());
641 /* We check the whole buffer with strncmp */
642 memset(Expected, 'x', sizeof(Expected) );
643 strcpy(Expected, "2,353.00");
644 memset( buffer, 'x', sizeof(buffer) );
645 ret = GetNumberFormatA(lcid, 0, input, NULL, buffer, COUNTOF(buffer));
646 cmp = strncmp (Expected, buffer, BUFFER_SIZE);
647 ok (cmp == 0, "GetNumberFormat got %s instead of %s", buffer, Expected);
648 eq (ret, lstrlenA(Expected)+1, "GetNumberFormat", "%d");
650 /* If the number of decimals is zero there should be no decimal
652 * If the grouping size is zero there should be no grouping symbol
654 format.NumDigits = 0;
655 format.LeadingZero = 0;
657 format.NegativeOrder = 0;
658 format.lpDecimalSep = ".";
659 format.lpThousandSep = ",";
660 strcpy (Expected, "123456789");
661 memset( buffer, 'x', sizeof(buffer) );
662 ret = GetNumberFormatA (0, 0, "123456789.0", &format, buffer, COUNTOF(buffer));
663 cmp = strncmp (Expected, buffer, sizeof(buffer));
664 ok (cmp == 0, "GetNumberFormat got %s instead of %s", buffer, Expected);
669 /* Callback function used by TestEnumTimeFormats */
670 BOOL CALLBACK EnumTimeFormatsProc(char * lpTimeFormatString)
672 trace("%s\n", lpTimeFormatString);
673 strcpy(GlobalBuffer, lpTimeFormatString);
680 void TestEnumTimeFormats()
684 char Expected[BUFFER_SIZE];
686 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT );
687 memset( GlobalBuffer, 'x', sizeof(GlobalBuffer) );
688 strcpy(Expected, "h:mm:ss tt");
689 ret = EnumTimeFormatsA(EnumTimeFormatsProc, lcid, 0);
691 eq (ret, 1, "EnumTimeFormats should return 1", "%d");
692 ok (strncmp (GlobalBuffer, Expected, strlen(Expected)) == 0,
693 "EnumTimeFormats failed");
694 ok (ret == 1, "EnumTimeFormats should return 1");
698 void TestCompareStringA()
702 char buffer1[BUFFER_SIZE], buffer2[BUFFER_SIZE];
704 lcid = MAKELCID(MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT), SORT_DEFAULT );
706 strcpy(buffer1, "Salut"); strcpy(buffer2, "Salute");
707 ret = CompareStringA(lcid, NORM_IGNORECASE, buffer1, -1, buffer2, -1);
708 ok (ret== 1, "CompareStringA (st1=%s str2=%s) expected result=1", buffer1, buffer2);
710 strcpy(buffer1, "Salut"); strcpy(buffer2, "saLuT");
711 ret = CompareStringA(lcid, NORM_IGNORECASE, buffer1, -1, buffer2, -1);
712 ok (ret== 2, "CompareStringA (st1=%s str2=%s) expected result=2", buffer1, buffer2);
714 strcpy(buffer1, "Salut"); strcpy(buffer2, "hola");
715 ret = CompareStringA(lcid, NORM_IGNORECASE, buffer1, -1, buffer2, -1);
716 ok (ret== 3, "CompareStringA (st1=%s str2=%s) expected result=3", buffer1, buffer2);
718 strcpy(buffer1, "héhé"); strcpy(buffer2, "hèhè");
719 ret = CompareStringA(lcid, NORM_IGNORECASE, buffer1, -1, buffer2, -1);
720 ok (ret== 1, "CompareStringA (st1=%s str2=%s) expected result=1", buffer1, buffer2);
722 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT );
724 strcpy(buffer1, "héhé"); strcpy(buffer2, "hèhè");
725 ret = CompareStringA(lcid, NORM_IGNORECASE, buffer1, -1, buffer2, -1);
726 ok (ret== 1, "CompareStringA (st1=%s str2=%s) expected result=1", buffer1, buffer2);
728 ret = CompareStringA(lcid, NORM_IGNORECASE, buffer1, -1, buffer2, 0);
729 ok (ret== 3, "CompareStringA (st1=%s str2=%s) expected result=3", buffer1, buffer2);
736 TestEnumTimeFormats();
738 TestGetLocaleInfoA();
739 TestGetTimeFormatA();
740 TestGetDateFormatA();
741 TestGetDateFormatW();
742 TestGetNumberFormat();
743 TestGetCurrencyFormat();
744 TestCompareStringA();