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];
39 * GetUserDefaultLangID
43 void TestGetLocaleInfoA()
47 char buffer[BUFFER_SIZE], Expected[BUFFER_SIZE];
49 strcpy(Expected, "Monday");
50 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT );
51 ok (lcid == 0x409, "wrong LCID calculated");
53 strcpy(Expected, "xxxxx");
54 memset( buffer, 'x', sizeof (buffer)/sizeof(buffer[0]) );
55 ret = GetLocaleInfoA(lcid, LOCALE_SDAYNAME1, buffer, 0);
56 cmp = strncmp (buffer, Expected, strlen(Expected));
57 ok (cmp == 0, "GetLocaleInfoA got %s instead of %s", buffer, Expected);
58 eq (ret, strlen("Monday") + 1, "GetLocaleInfoA with len=0", "%d");
60 strcpy(Expected, "Monxx");
61 memset( buffer, 'x', sizeof (buffer)/sizeof(buffer[0]) );
62 ret = GetLocaleInfoA(lcid, LOCALE_SDAYNAME1, buffer, 3);
63 cmp = strncmp (buffer, Expected, strlen(Expected));
64 ok (cmp == 0, "GetLocaleInfoA got %s instead of %s", buffer, Expected);
65 eq (ret, 0, "GetLocaleInfoA with len = 3", "%d");
67 strcpy(Expected, "Monday");
68 memset( buffer, 'x', sizeof (buffer)/sizeof(buffer[0]) );
69 ret = GetLocaleInfoA(lcid, LOCALE_SDAYNAME1, buffer, 10);
70 /* We check also presence of '\0' */
71 cmp = strncmp (buffer, Expected, strlen(Expected) + 1);
72 ok (cmp == 0, "GetLocaleInfoA got %s instead of %s", buffer, Expected);
73 eq (ret, strlen(Expected)+1, "GetLocaleInfoA with len = 10", "%d" );
75 /* We check the whole buffer with strncmp */
76 memset( Expected, 'x', sizeof (Expected)/sizeof(Expected[0]) );
77 strcpy(Expected, "Monday");
78 memset( buffer, 'x', sizeof (buffer)/sizeof(buffer[0]) );
79 ret = GetLocaleInfoA(lcid, LOCALE_SDAYNAME1, buffer, BUFFER_SIZE);
80 cmp = strncmp (buffer, Expected, BUFFER_SIZE);
81 ok (cmp == 0, "GetLocaleInfoA got %s instead of %s", buffer, Expected);
82 eq (ret, strlen(Expected)+1, "GetLocaleInfoA with len = 10", "%d" );
87 void TestGetTimeFormatA()
91 char buffer[BUFFER_SIZE], format[BUFFER_SIZE], Expected[BUFFER_SIZE];
94 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT );
95 strcpy(format, "tt HH':'mm'@'ss");
98 /* fill curtime with dummy data */
99 memset(&curtime, 2, sizeof(SYSTEMTIME));
100 ret = GetTimeFormatA(lcid, TIME_FORCE24HOURFORMAT, &curtime, format, buffer, sizeof(buffer));
101 error = GetLastError ();
102 ok (ret == 0, "GetTimeFormat should fail on dummy data");
103 eq (error, ERROR_INVALID_PARAMETER, "GetTimeFormat GetLastError()", "%d");
106 strcpy(Expected, "AM 08:56@13");
107 curtime.wHour = 8; curtime.wMinute = 56;
108 curtime.wSecond = 13; curtime.wMilliseconds = 22;
109 ret = GetTimeFormatA(lcid, TIME_FORCE24HOURFORMAT, &curtime, format, buffer, sizeof(buffer));
110 cmp = strncmp (Expected, buffer, strlen(Expected)+1);
111 ok (cmp == 0, "GetTimeFormat got %s instead of %s", buffer, Expected);
112 eq (ret, strlen(Expected)+1, "GetTimeFormat", "%d");
114 /* test with too small buffers */
115 memset(buffer, 'x', sizeof (buffer)/sizeof(buffer[0]) );
116 strcpy(Expected, "xxxx");
117 ret = GetTimeFormatA(lcid, TIME_FORCE24HOURFORMAT, &curtime, format, buffer, 0);
118 cmp = strncmp (Expected, buffer, 4);
119 ok (cmp == 0, "GetTimeFormat with len=0 got %s instead of %s", buffer, Expected);
120 todo_wine { eq (ret, 12, "GetTimeFormat with len=0", "%d"); }
122 memset(buffer, 'x', sizeof (buffer)/sizeof(buffer[0]) );
123 strcpy(Expected, "AMxx");
124 ret = GetTimeFormatA(lcid, TIME_FORCE24HOURFORMAT, &curtime, format, buffer, 2);
125 cmp = strncmp (Expected, buffer, 4);
126 todo_wine { ok (cmp == 0, "GetTimeFormat with len=2 got %s instead of %s", buffer, Expected); }
127 eq (ret, 0, "GetTimeFormat with len=2", "%d");
130 void TestGetDateFormatA()
134 char buffer[BUFFER_SIZE], format[BUFFER_SIZE], Expected[BUFFER_SIZE];
137 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT );
138 strcpy(format, "ddd',' MMM dd yy");
141 /* fill curtime with dummy data */
142 memset(&curtime, 2, sizeof(SYSTEMTIME));
143 memset(buffer, 'x', sizeof (buffer)/sizeof(buffer[0]) );
144 ret = GetDateFormatA(lcid, 0, &curtime, format, buffer, sizeof(buffer));
145 error = GetLastError ();
146 ok (ret== 0, "GetDateFormat should fail on dummy data");
147 eq (error, ERROR_INVALID_PARAMETER, "GetDateFormat", "%d");
150 strcpy(Expected, "Sat, May 04 02");
151 memset(buffer, 'x', sizeof (buffer)/sizeof(buffer[0]) );
152 curtime.wYear = 2002;
155 curtime.wDayOfWeek = 3;
156 ret = GetDateFormatA(lcid, 0, &curtime, format, buffer, sizeof(buffer));
157 cmp = strncmp (Expected, buffer, strlen(Expected)+1);
158 todo_wine { ok (cmp == 0, "GetDateFormat got %s instead of %s", buffer, Expected); }
159 eq (ret, strlen(Expected)+1, "GetDateFormat", "%d");
161 /* test format with "'" */
162 memset(buffer, 'x', sizeof (buffer)/sizeof(buffer[0]) );
163 strcpy(format, "ddd',' MMM dd ''''yy");
164 strcpy(Expected, "Sat, May 04 '02");
165 ret = GetDateFormatA(lcid, 0, &curtime, format, buffer, sizeof(buffer));
166 cmp = strncmp (Expected, buffer, strlen(Expected)+1);
167 todo_wine { ok (cmp == 0, "GetDateFormat got %s instead of %s", buffer, Expected); }
168 eq (ret, (strlen(Expected)+1), "GetDateFormat", "%d");
170 /* test with too small buffers */
171 memset(buffer, 'x', sizeof (buffer)/sizeof(buffer[0]) );
172 strcpy(Expected, "xxxx");
173 ret = GetDateFormatA(lcid, 0, &curtime, format, buffer, 0);
174 cmp = strncmp (Expected, buffer, 4);
175 ok (cmp == 0, "GetDateFormat got %s instead of %s", buffer, Expected);
176 todo_wine { eq (ret, 16, "GetDateFormat with len=0", "%d"); }
178 memset(buffer, 'x', sizeof (buffer)/sizeof(buffer[0]) );
179 strcpy(Expected, "Saxx");
180 ret = GetDateFormatA(lcid, 0, &curtime, format, buffer, 2);
181 cmp = strncmp (Expected, buffer, 4);
182 todo_wine { ok (cmp == 0, "GetDateFormat got %s instead of %s", buffer, Expected); }
183 eq (ret, 0, "GetDateFormat with len=2", "%d");
187 void TestGetCurrencyFormat()
190 char buffer[BUFFER_SIZE], Expected[BUFFER_SIZE], format[BUFFER_SIZE];
193 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT );
195 lcid = MAKELCID(MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT), SORT_DEFAULT );
198 memset( buffer, 'x', sizeof (buffer)/sizeof(buffer[0]) );
199 ret = GetCurrencyFormatA(lcid, 0, "23,65", NULL, buffer, sizeof(buffer));
200 error = GetLastError ();
201 cmp = strncmp ("xxxx", buffer, 4);
203 ok (cmp == 0, "GetCurrencyFormat should fail with ','");
204 eq (ret, 0, "GetCurrencyFormat with ','", "%d");
205 eq (error, ERROR_INVALID_PARAMETER, "GetCurrencyFormat", "%d");
207 memset(Expected, 'x', sizeof (Expected)/sizeof(Expected[0]) );
208 strcpy (Expected, "$23.53");
209 strcpy (format, "23.53");
210 memset( buffer, 'x', sizeof (buffer)/sizeof(buffer[0]) );
211 ret = GetCurrencyFormatA(lcid, 0, format, NULL, buffer, 0);
212 cmp = strncmp ("xxx", buffer, 3);
213 ok (cmp == 0, "GetCurrencyFormat with 0 buffer size");
214 eq (ret, strlen(Expected)+1, "GetCurrencyFormat with len=0", "%d");
216 memset( buffer, 'x', sizeof (buffer)/sizeof(buffer[0]) );
217 ret = GetCurrencyFormatA(lcid, 0, format, NULL, buffer, 2);
218 cmp = strncmp ("$2xx", buffer, 4);
219 ok (cmp == 0, "GetCurrencyFormat got %s instead of %s", buffer, Expected);
220 eq (ret, 0, "GetCurrencyFormat with len=2", "%d");
222 /* We check the whole buffer with strncmp */
223 memset( buffer, 'x', sizeof (buffer)/sizeof(buffer[0]) );
224 ret = GetCurrencyFormatA(lcid, 0, format, NULL, buffer, sizeof(buffer));
225 cmp = strncmp (Expected, buffer, BUFFER_SIZE);
226 ok (cmp == 0, "GetCurrencyFormat got %s instead of %s", buffer, Expected);
227 eq (ret, strlen(Expected)+1, "GetCurrencyFormat","%d");
232 void TestGetNumberFormat()
235 char buffer[BUFFER_SIZE], Expected[BUFFER_SIZE], input[BUFFER_SIZE];
238 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT );
240 memset( buffer, 'x', sizeof (buffer)/sizeof(buffer[0]) );
241 ret = GetNumberFormatA(lcid, 0, "23,65", NULL, buffer, sizeof(buffer));
242 error = GetLastError ();
243 cmp = strncmp ("xxx", buffer, 3);
244 ok (cmp == 0, "GetCurrencyFormat");
245 ok (ret == 0, "GetNumberFormat should return 0");
246 eq (error, ERROR_INVALID_PARAMETER, "GetNumberFormat", "%d");
248 strcpy(input, "2353");
249 strcpy(Expected, "2,353.00");
250 memset( buffer, 'x', sizeof (buffer)/sizeof(buffer[0]) );
251 ret = GetNumberFormatA(lcid, 0, input, NULL, buffer, 0);
252 cmp = strncmp ("xxx", buffer, 3);
253 ok (cmp == 0, "GetNumberFormat with len=0 got %s instead of %s", buffer, "xxx");
254 eq (ret, strlen(Expected)+1, "GetNumberFormat", "%d");
256 strcpy(Expected, "2,xx");
257 memset( buffer, 'x', sizeof (buffer)/sizeof(buffer[0]) );
258 ret = GetNumberFormatA(lcid, 0, input, NULL, buffer, 2);
259 cmp = strncmp (Expected, buffer, 4);
260 ok (cmp == 0, "GetNumberFormat with len=2 got %s instead of %s", buffer, Expected);
261 eq (ret, 0, "GetNumberFormat", "%d");
263 /* We check the whole buffer with strncmp */
264 memset(Expected, 'x', sizeof (Expected)/sizeof(Expected[0]) );
265 strcpy(Expected, "2,353.00");
266 memset( buffer, 'x', sizeof (buffer)/sizeof(buffer[0]) );
267 ret = GetNumberFormatA(lcid, 0, input, NULL, buffer, sizeof(buffer));
268 cmp = strncmp (Expected, buffer, BUFFER_SIZE);
269 ok (cmp == 0, "GetNumberFormat got %s instead of %s", buffer, Expected);
270 eq (ret, strlen(Expected)+1, "GetNumberFormat", "%d");
274 /* Callback function used by TestEnumTimeFormats */
275 BOOL CALLBACK EnumTimeFormatsProc(char * lpTimeFormatString)
277 trace("%s\n", lpTimeFormatString);
278 strcpy(GlobalBuffer, lpTimeFormatString);
285 void TestEnumTimeFormats()
289 char Expected[BUFFER_SIZE];
291 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT );
292 memset( GlobalBuffer, 'x', sizeof (GlobalBuffer)/sizeof(GlobalBuffer[0]) );
293 strcpy(Expected, "h:mm:ss tt");
294 ret = EnumTimeFormatsA(EnumTimeFormatsProc, lcid, 0);
296 eq (ret, 1, "EnumTimeFormats should return 1", "%d");
297 ok (strncmp (GlobalBuffer, Expected, strlen(Expected)) == 0,
298 "EnumTimeFormats failed");
299 ok (ret == 1, "EnumTimeFormats should return 1");
303 void TestCompareStringA()
307 char buffer1[BUFFER_SIZE], buffer2[BUFFER_SIZE];
309 lcid = MAKELCID(MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT), SORT_DEFAULT );
311 strcpy(buffer1, "Salut"); strcpy(buffer2, "Salute");
312 ret = CompareStringA(lcid, NORM_IGNORECASE, buffer1, -1, buffer2, -1);
313 ok (ret== 1, "CompareStringA (st1=%s str2=%s) expected result=1", buffer1, buffer2);
315 strcpy(buffer1, "Salut"); strcpy(buffer2, "saLuT");
316 ret = CompareStringA(lcid, NORM_IGNORECASE, buffer1, -1, buffer2, -1);
317 ok (ret== 2, "CompareStringA (st1=%s str2=%s) expected result=2", buffer1, buffer2);
319 strcpy(buffer1, "Salut"); strcpy(buffer2, "hola");
320 ret = CompareStringA(lcid, NORM_IGNORECASE, buffer1, -1, buffer2, -1);
321 ok (ret== 3, "CompareStringA (st1=%s str2=%s) expected result=3", buffer1, buffer2);
323 strcpy(buffer1, "héhé"); strcpy(buffer2, "hèhè");
324 ret = CompareStringA(lcid, NORM_IGNORECASE, buffer1, -1, buffer2, -1);
325 ok (ret== 1, "CompareStringA (st1=%s str2=%s) expected result=1", buffer1, buffer2);
327 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT );
329 strcpy(buffer1, "héhé"); strcpy(buffer2, "hèhè");
330 ret = CompareStringA(lcid, NORM_IGNORECASE, buffer1, -1, buffer2, -1);
331 ok (ret== 1, "CompareStringA (st1=%s str2=%s) expected result=1", buffer1, buffer2);
333 ret = CompareStringA(lcid, NORM_IGNORECASE, buffer1, -1, buffer2, 0);
334 ok (ret== 3, "CompareStringA (st1=%s str2=%s) expected result=3", buffer1, buffer2);
341 TestEnumTimeFormats();
343 TestGetLocaleInfoA();
344 TestGetTimeFormatA();
345 TestGetDateFormatA();
346 TestGetNumberFormat();
347 TestGetCurrencyFormat();
348 TestCompareStringA();