2 * VARFORMAT test program
4 * Copyright 1998 Jean-Claude Cote
5 * Copyright 2006 Google (Benjamin Arai)
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/test.h"
40 static HMODULE hOleaut32
;
42 static HRESULT (WINAPI
*pVarFormatNumber
)(LPVARIANT
,int,int,int,int,ULONG
,BSTR
*);
43 static HRESULT (WINAPI
*pVarFormat
)(LPVARIANT
,LPOLESTR
,int,int,ULONG
,BSTR
*);
44 static HRESULT (WINAPI
*pVarWeekdayName
)(int,int,int,ULONG
,BSTR
*);
46 /* Has I8/UI8 data type? */
49 /* Get a conversion function ptr, return if function not available */
50 #define CHECKPTR(func) p##func = (void*)GetProcAddress(hOleaut32, #func); \
51 if (!p##func) { win_skip("function " # func " not available, not testing it\n"); return; }
53 static inline int strcmpW( const WCHAR
*str1
, const WCHAR
*str2
)
55 while (*str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
59 #define FMT_NUMBER(vt,val) \
60 VariantInit(&v); V_VT(&v) = vt; val(&v) = 1; \
61 hres = pVarFormatNumber(&v,2,0,0,0,0,&str); \
62 ok(hres == S_OK, "VarFormatNumber (vt %d): returned %8x\n", vt, hres); \
64 ok(str && strcmpW(str,szResult1) == 0, \
65 "VarFormatNumber (vt %d): string different\n", vt); \
69 static void test_VarFormatNumber(void)
71 static const WCHAR szSrc1
[] = { '1','\0' };
72 static const WCHAR szResult1
[] = { '1','.','0','0','\0' };
73 static const WCHAR szSrc2
[] = { '-','1','\0' };
74 static const WCHAR szResult2
[] = { '(','1','.','0','0',')','\0' };
80 CHECKPTR(VarFormatNumber
);
82 GetLocaleInfoA(LOCALE_USER_DEFAULT
, LOCALE_SDECIMAL
, buff
, ARRAY_SIZE(buff
));
83 if (buff
[0] != '.' || buff
[1])
85 skip("Skipping VarFormatNumber tests as decimal separator is '%s'\n", buff
);
89 FMT_NUMBER(VT_I1
, V_I1
);
90 FMT_NUMBER(VT_UI1
, V_UI1
);
91 FMT_NUMBER(VT_I2
, V_I2
);
92 FMT_NUMBER(VT_UI2
, V_UI2
);
93 FMT_NUMBER(VT_I4
, V_I4
);
94 FMT_NUMBER(VT_UI4
, V_UI4
);
97 FMT_NUMBER(VT_I8
, V_I8
);
98 FMT_NUMBER(VT_UI8
, V_UI8
);
100 FMT_NUMBER(VT_R4
, V_R4
);
101 FMT_NUMBER(VT_R8
, V_R8
);
102 FMT_NUMBER(VT_BOOL
, V_BOOL
);
105 V_BSTR(&v
) = SysAllocString(szSrc1
);
107 hres
= pVarFormatNumber(&v
,2,0,0,0,0,&str
);
108 ok(hres
== S_OK
, "VarFormatNumber (bstr): returned %8x\n", hres
);
110 ok(str
&& strcmpW(str
, szResult1
) == 0, "VarFormatNumber (bstr): string different\n");
111 SysFreeString(V_BSTR(&v
));
114 V_BSTR(&v
) = SysAllocString(szSrc2
);
115 hres
= pVarFormatNumber(&v
,2,0,-1,0,0,&str
);
116 ok(hres
== S_OK
, "VarFormatNumber (bstr): returned %8x\n", hres
);
118 ok(str
&& strcmpW(str
, szResult2
) == 0, "VarFormatNumber (-bstr): string different\n");
119 SysFreeString(V_BSTR(&v
));
123 #define SIGNED_VTBITS (VTBIT_I1|VTBIT_I2|VTBIT_I4|VTBIT_I8|VTBIT_R4|VTBIT_R8)
125 static const char *szVarFmtFail
= "VT %d|0x%04x Format %s: expected 0x%08x, '%s', got 0x%08x, '%s'\n";
126 #define VARFMT(vt,v,val,fmt,ret,str) do { \
128 V_VT(&in) = (vt); v(&in) = val; \
129 if (fmt) MultiByteToWideChar(CP_ACP, 0, fmt, -1, buffW, ARRAY_SIZE(buffW)); \
130 hres = pVarFormat(&in,fmt ? buffW : NULL,fd,fw,flags,&out); \
131 if (SUCCEEDED(hres)) WideCharToMultiByte(CP_ACP, 0, out, -1, buff, sizeof(buff),0,0); \
132 else buff[0] = '\0'; \
133 ok(hres == ret && (FAILED(ret) || !strcmp(buff, str)), \
135 (vt)&VT_TYPEMASK,(vt)&~VT_TYPEMASK,fmt?fmt:"<null>",ret,str,hres,buff); \
136 SysFreeString(out); \
139 typedef struct tagFMTRES
146 static const FMTRES VarFormat_results
[] =
150 { "General Number", "1", "0" },
151 { "Percent", "100.00%", "0.00%" },
152 { "Standard", "1.00", "0.00" },
153 { "Scientific","1.00E+00", "0.00E+00" },
154 { "True/False", "True", "False" },
155 { "On/Off", "On", "Off" },
156 { "Yes/No", "Yes", "No" },
159 { "#.#", "1.", "." },
161 { "00", "01", "00" },
162 { "0.0", "1.0", "0.0" },
163 { "00\\c\\o\\p\\y", "01copy","00copy" },
164 { "\"pos\";\"neg\"", "pos", "pos" },
165 { "\"pos\";\"neg\";\"zero\"","pos", "zero" }
168 typedef struct tagFMTDATERES
175 static const FMTDATERES VarFormat_date_results
[] =
183 { 0.0, "w", "1" }, /* First 7 entries must remain in this order! */
184 { 2.525, "am/pm", "pm" },
185 { 2.525, "AM/PM", "PM" },
186 { 2.525, "A/P", "P" },
187 { 2.525, "a/p", "p" },
190 { 2.525, "dd", "01" },
191 { 2.525, "ddd", "Mon" },
192 { 2.525, "dddd", "Monday" },
193 { 2.525, "mmm", "Jan" },
194 { 2.525, "mmmm", "January" },
196 { 2.525, "yy", "00" },
197 { 2.525, "yyy", "001" },
198 { 2.525, "yyyy", "1900" },
199 { 2.525, "dd mm yyyy hh:mm:ss", "01 01 1900 12:36:00" },
200 { 2.525, "dd mm yyyy mm", "01 01 1900 01" },
201 { 2.525, "dd mm yyyy :mm", "01 01 1900 :01" },
202 { 2.525, "dd mm yyyy hh:mm", "01 01 1900 12:36" },
203 { 2.525, "mm mm", "01 01" },
204 { 2.525, "mm :mm:ss", "01 :01:00" },
205 { 2.525, "mm :ss:mm", "01 :00:01" },
206 { 2.525, "hh:mm :ss:mm", "12:36 :00:01" },
207 { 2.525, "hh:dd :mm:mm", "12:01 :01:01" },
208 { 2.525, "dd:hh :mm:mm", "01:12 :36:01" },
209 { 2.525, "hh :mm:mm", "12 :36:01" },
210 { 2.525, "dd :mm:mm", "01 :01:01" },
211 { 2.525, "dd :mm:nn", "01 :01:36" },
212 { 2.725, "hh:nn:ss A/P", "05:24:00 P" },
213 { 40531.0, "dddd", "Sunday" },
214 { 40531.0, "ddd", "Sun" }
217 /* The following tests require that the time separator is a colon (:) */
218 static const FMTDATERES VarFormat_namedtime_results
[] =
220 { 2.525, "short time", "12:36" },
221 { 2.525, "medium time", "12:36 PM" },
222 { 2.525, "long time", "12:36:00 PM" }
225 #define VNUMFMT(vt,v) \
226 for (i = 0; i < ARRAY_SIZE(VarFormat_results); i++) \
228 VARFMT(vt,v,1,VarFormat_results[i].fmt,S_OK,VarFormat_results[i].one_res); \
229 VARFMT(vt,v,0,VarFormat_results[i].fmt,S_OK,VarFormat_results[i].zero_res); \
231 if ((1 << vt) & SIGNED_VTBITS) \
233 VARFMT(vt,v,-1,"\"pos\";\"neg\"",S_OK,"neg"); \
234 VARFMT(vt,v,-1,"\"pos\";\"neg\";\"zero\"",S_OK,"neg"); \
237 static void test_VarFormat(void)
239 static const WCHAR szTesting
[] = { 't','e','s','t','i','n','g','\0' };
240 static const WCHAR szNum
[] = { '3','9','6','9','7','.','1','1','\0' };
245 VARIANT_BOOL bTrue
= VARIANT_TRUE
, bFalse
= VARIANT_FALSE
;
248 BSTR bstrin
, out
= NULL
;
253 if (PRIMARYLANGID(LANGIDFROMLCID(GetUserDefaultLCID())) != LANG_ENGLISH
)
255 skip("Skipping VarFormat tests for non English language\n");
258 GetLocaleInfoA(LOCALE_USER_DEFAULT
, LOCALE_SDECIMAL
, buff
, ARRAY_SIZE(buff
));
259 if (buff
[0] != '.' || buff
[1])
261 skip("Skipping VarFormat tests as decimal separator is '%s'\n", buff
);
264 GetLocaleInfoA(LOCALE_USER_DEFAULT
, LOCALE_IDIGITS
, buff
, ARRAY_SIZE(buff
));
265 if (buff
[0] != '2' || buff
[1])
267 skip("Skipping VarFormat tests as decimal places is '%s'\n", buff
);
271 VARFMT(VT_BOOL
,V_BOOL
,VARIANT_TRUE
,"True/False",S_OK
,"True");
272 VARFMT(VT_BOOL
,V_BOOL
,VARIANT_FALSE
,"True/False",S_OK
,"False");
281 VNUMFMT(VT_INT
,V_INT
);
282 VNUMFMT(VT_UI1
,V_UI1
);
283 VNUMFMT(VT_UI2
,V_UI2
);
284 VNUMFMT(VT_UI4
,V_UI4
);
287 VNUMFMT(VT_UI8
,V_UI8
);
289 VNUMFMT(VT_UINT
,V_UINT
);
293 /* Reference types are dereferenced */
294 VARFMT(VT_BOOL
|VT_BYREF
,V_BOOLREF
,&bTrue
,"True/False",S_OK
,"True");
295 VARFMT(VT_BOOL
|VT_BYREF
,V_BOOLREF
,&bFalse
,"True/False",S_OK
,"False");
298 for (i
= 0; i
< ARRAY_SIZE(VarFormat_date_results
); i
++)
301 fd
= i
+ 1; /* Test first day */
304 VARFMT(VT_DATE
,V_DATE
,VarFormat_date_results
[i
].val
,
305 VarFormat_date_results
[i
].fmt
,S_OK
,
306 VarFormat_date_results
[i
].res
);
309 /* Named time formats */
310 GetLocaleInfoA(LOCALE_USER_DEFAULT
, LOCALE_STIMEFORMAT
, buff
, ARRAY_SIZE(buff
));
311 if (strcmp(buff
, "h:mm:ss tt"))
313 skip("Skipping named time tests as time format is '%s'\n", buff
);
317 for (i
= 0; i
< ARRAY_SIZE(VarFormat_namedtime_results
); i
++)
320 VARFMT(VT_DATE
,V_DATE
,VarFormat_namedtime_results
[i
].val
,
321 VarFormat_namedtime_results
[i
].fmt
,S_OK
,
322 VarFormat_namedtime_results
[i
].res
);
327 bstrin
= SysAllocString(szTesting
);
328 VARFMT(VT_BSTR
,V_BSTR
,bstrin
,"",S_OK
,"testing");
329 VARFMT(VT_BSTR
,V_BSTR
,bstrin
,"@",S_OK
,"testing");
330 VARFMT(VT_BSTR
,V_BSTR
,bstrin
,"&",S_OK
,"testing");
331 VARFMT(VT_BSTR
,V_BSTR
,bstrin
,"\\x@\\x@",S_OK
,"xtxesting");
332 VARFMT(VT_BSTR
,V_BSTR
,bstrin
,"\\x&\\x&",S_OK
,"xtxesting");
333 VARFMT(VT_BSTR
,V_BSTR
,bstrin
,"@\\x",S_OK
,"txesting");
334 VARFMT(VT_BSTR
,V_BSTR
,bstrin
,"@@@@@@@@",S_OK
," testing");
335 VARFMT(VT_BSTR
,V_BSTR
,bstrin
,"@\\x@@@@@@@",S_OK
," xtesting");
336 VARFMT(VT_BSTR
,V_BSTR
,bstrin
,"&&&&&&&&",S_OK
,"testing");
337 VARFMT(VT_BSTR
,V_BSTR
,bstrin
,"!&&&&&&&",S_OK
,"testing");
338 VARFMT(VT_BSTR
,V_BSTR
,bstrin
,"&&&&&&&!",S_OK
,"testing");
339 VARFMT(VT_BSTR
,V_BSTR
,bstrin
,">&&",S_OK
,"TESTING");
340 VARFMT(VT_BSTR
,V_BSTR
,bstrin
,"<&&",S_OK
,"testing");
341 VARFMT(VT_BSTR
,V_BSTR
,bstrin
,"<&>&",S_OK
,"testing");
342 SysFreeString(bstrin
);
343 bstrin
= SysAllocString(szNum
);
344 todo_wine
VARFMT(VT_BSTR
,V_BSTR
,bstrin
,"hh:mm",S_OK
,"02:38");
345 todo_wine
VARFMT(VT_BSTR
,V_BSTR
,bstrin
,"mm-dd-yy",S_OK
,"09-06-08");
346 SysFreeString(bstrin
);
347 /* Numeric values are converted to strings then output */
348 VARFMT(VT_I1
,V_I1
,1,"<&>&",S_OK
,"1");
351 VARFMT(VT_I4
,V_I4
,1,"#00000000",S_OK
,"00000001");
352 VARFMT(VT_I4
,V_I4
,1,"000###",S_OK
,"000001");
353 VARFMT(VT_I4
,V_I4
,1,"#00##00#0",S_OK
,"00000001");
354 VARFMT(VT_I4
,V_I4
,1,"1#####0000",S_OK
,"10001");
355 VARFMT(VT_I4
,V_I4
,1,"##abcdefghijklmnopqrstuvwxyz",S_OK
,"1abcdefghijklmnopqrstuvwxyz");
356 VARFMT(VT_I4
,V_I4
,100000,"#,###,###,###",S_OK
,"100,000");
357 VARFMT(VT_I4
,V_I4
,1,"0,000,000,000",S_OK
,"0,000,000,001");
358 VARFMT(VT_I4
,V_I4
,123456789,"#,#.#",S_OK
,"123,456,789.");
359 VARFMT(VT_I4
,V_I4
,123456789,"###, ###, ###",S_OK
,"123, 456, 789");
360 VARFMT(VT_I4
,V_I4
,1,"#;-#",S_OK
,"1");
361 VARFMT(VT_I4
,V_I4
,-1,"#;-#",S_OK
,"-1");
362 VARFMT(VT_R8
,V_R8
,1.23456789,"0#.0#0#0#0#0",S_OK
,"01.234567890");
363 VARFMT(VT_R8
,V_R8
,1.2,"0#.0#0#0#0#0",S_OK
,"01.200000000");
364 VARFMT(VT_R8
,V_R8
,9.87654321,"#0.#0#0#0#0#",S_OK
,"9.87654321");
365 VARFMT(VT_R8
,V_R8
,9.8,"#0.#0#0#0#0#",S_OK
,"9.80000000");
366 VARFMT(VT_R8
,V_R8
,0.00000008,"#0.#0#0#0#0#0",S_OK
,"0.0000000800");
367 VARFMT(VT_R8
,V_R8
,0.00010705,"#0.##########",S_OK
,"0.00010705");
368 VARFMT(VT_I4
,V_I4
,17,"#0",S_OK
,"17");
369 VARFMT(VT_I4
,V_I4
,4711,"#0",S_OK
,"4711");
370 VARFMT(VT_I4
,V_I4
,17,"#00",S_OK
,"17");
371 VARFMT(VT_I4
,V_I4
,100,"0##",S_OK
,"100");
372 VARFMT(VT_I4
,V_I4
,17,"#000",S_OK
,"017");
373 VARFMT(VT_I4
,V_I4
,17,"#0.00",S_OK
,"17.00");
374 VARFMT(VT_I4
,V_I4
,17,"#0000.00",S_OK
,"0017.00");
375 VARFMT(VT_I4
,V_I4
,17,"#.00",S_OK
,"17.00");
376 VARFMT(VT_R8
,V_R8
,1.7,"#.00",S_OK
,"1.70");
377 VARFMT(VT_R8
,V_R8
,.17,"#.00",S_OK
,".17");
378 VARFMT(VT_I4
,V_I4
,17,"#3",S_OK
,"173");
379 VARFMT(VT_I4
,V_I4
,17,"#33",S_OK
,"1733");
380 VARFMT(VT_I4
,V_I4
,17,"#3.33",S_OK
,"173.33");
381 VARFMT(VT_I4
,V_I4
,17,"#3333.33",S_OK
,"173333.33");
382 VARFMT(VT_I4
,V_I4
,17,"#.33",S_OK
,"17.33");
383 VARFMT(VT_R8
,V_R8
,.17,"#.33",S_OK
,".33");
384 VARFMT(VT_R8
,V_R8
,1.7,"0.0000E-000",S_OK
,"1.7000E000");
385 VARFMT(VT_R8
,V_R8
,1.7,"0.0000e-1",S_OK
,"1.7000e01");
386 VARFMT(VT_R8
,V_R8
,86.936849,"#0.000000000000e-000",S_OK
,"86.936849000000e000");
387 VARFMT(VT_R8
,V_R8
,1.7,"#0",S_OK
,"2");
388 VARFMT(VT_R8
,V_R8
,1.7,"#.33",S_OK
,"2.33");
389 VARFMT(VT_R8
,V_R8
,1.7,"#3",S_OK
,"23");
390 VARFMT(VT_R8
,V_R8
,1.73245,"0.0000E+000",S_OK
,"1.7325E+000");
391 VARFMT(VT_R8
,V_R8
,9.9999999,"#0.000000",S_OK
,"10.000000");
392 VARFMT(VT_R8
,V_R8
,1.7,"0.0000e+0#",S_OK
,"1.7000e+0");
393 VARFMT(VT_R8
,V_R8
,100.0001e+0,"0.0000E+0",S_OK
,"1.0000E+2");
394 VARFMT(VT_R8
,V_R8
,1000001,"0.0000e+1",S_OK
,"1.0000e+61");
395 VARFMT(VT_R8
,V_R8
,100.0001e+25,"0.0000e+0",S_OK
,"1.0000e+27");
396 VARFMT(VT_R8
,V_R8
,450.0001e+43,"#000.0000e+0",S_OK
,"4500.0010e+42");
397 VARFMT(VT_R8
,V_R8
,0.0001e-11,"##00.0000e-0",S_OK
,"1000.0000e-18");
398 VARFMT(VT_R8
,V_R8
,0.0317e-11,"0000.0000e-0",S_OK
,"3170.0000e-16");
399 VARFMT(VT_R8
,V_R8
,0.0021e-11,"00##.0000e-0",S_OK
,"2100.0000e-17");
400 VARFMT(VT_R8
,V_R8
,1.0001e-27,"##00.0000e-0",S_OK
,"1000.1000e-30");
401 VARFMT(VT_R8
,V_R8
,47.11,".0000E+0",S_OK
,".4711E+2");
402 VARFMT(VT_R8
,V_R8
,3.0401e-13,"#####.####e-0%",S_OK
,"30401.e-15%");
403 VARFMT(VT_R8
,V_R8
,1.57,"0.00",S_OK
,"1.57");
404 VARFMT(VT_R8
,V_R8
,-1.57,"0.00",S_OK
,"-1.57");
405 VARFMT(VT_R8
,V_R8
,-1.57,"#.##",S_OK
,"-1.57");
406 VARFMT(VT_R8
,V_R8
,-0.1,".#",S_OK
,"-.1");
407 VARFMT(VT_R8
,V_R8
,0.099,"#.#",S_OK
,".1");
408 VARFMT(VT_R8
,V_R8
,0.0999,"#.##",S_OK
,".1");
409 VARFMT(VT_R8
,V_R8
,0.099,"#.##",S_OK
,".1");
410 VARFMT(VT_R8
,V_R8
,0.0099,"#.##",S_OK
,".01");
411 VARFMT(VT_R8
,V_R8
,0.0049,"#.##",S_OK
,".");
412 VARFMT(VT_R8
,V_R8
,0.0094,"#.##",S_OK
,".01");
413 VARFMT(VT_R8
,V_R8
,0.00099,"#.##",S_OK
,".");
414 VARFMT(VT_R8
,V_R8
,0.0995,"#.##",S_OK
,".1");
415 VARFMT(VT_R8
,V_R8
,8.0995,"#.##",S_OK
,"8.1");
416 VARFMT(VT_R8
,V_R8
,0.0994,"#.##",S_OK
,".1");
417 VARFMT(VT_R8
,V_R8
,1.00,"#,##0.00",S_OK
,"1.00");
418 VARFMT(VT_R8
,V_R8
,0.0995,"#.###",S_OK
,".1");
421 /* 'out' is not cleared */
423 hres
= pVarFormat(&in
,NULL
,fd
,fw
,flags
,&out
); /* Would crash if out is cleared */
424 ok(hres
== S_OK
, "got %08x\n", hres
);
430 hres
= pVarFormat(&in
,NULL
,fd
,fw
,0,&out
);
431 ok(hres
== S_OK
, "VarFormat failed with 0x%08x\n", hres
);
432 ok(out
== NULL
, "expected NULL formatted string\n");
435 hres
= pVarFormat(&in
,NULL
,fd
,fw
,flags
,NULL
);
436 ok(hres
== E_INVALIDARG
, "Null out: expected E_INVALIDARG, got 0x%08x\n", hres
);
437 hres
= pVarFormat(NULL
,NULL
,fd
,fw
,flags
,&out
);
438 ok(hres
== E_INVALIDARG
, "Null in: expected E_INVALIDARG, got 0x%08x\n", hres
);
440 VARFMT(VT_BOOL
,V_BOOL
,VARIANT_TRUE
,"",E_INVALIDARG
,"");
442 VARFMT(VT_BOOL
,V_BOOL
,VARIANT_TRUE
,"",E_INVALIDARG
,"");
444 VARFMT(VT_BOOL
,V_BOOL
,VARIANT_TRUE
,"",E_INVALIDARG
,"");
446 VARFMT(VT_BOOL
,V_BOOL
,VARIANT_TRUE
,"",E_INVALIDARG
,"");
449 static const char *szVarWdnFail
=
450 "VarWeekdayName (%d, %d, %d, %d, %x): returned %8x, expected %8x\n";
451 #define VARWDN(iWeekday, fAbbrev, iFirstDay, dwFlags, ret, buff, out, freeOut) \
453 hres = pVarWeekdayName(iWeekday, fAbbrev, iFirstDay, dwFlags, &out); \
454 if (SUCCEEDED(hres)) { \
455 WideCharToMultiByte(CP_ACP, 0, out, -1, buff, sizeof(buff), 0, 0); \
456 if (freeOut) SysFreeString(out); \
462 iWeekday, fAbbrev, iFirstDay, dwFlags, &out, hres, ret \
466 #define VARWDN_F(iWeekday, fAbbrev, iFirstDay, dwFlags, ret) \
467 VARWDN(iWeekday, fAbbrev, iFirstDay, dwFlags, ret, buff, out, 1)
469 #define VARWDN_O(iWeekday, fAbbrev, iFirstDay, dwFlags) \
470 VARWDN(iWeekday, fAbbrev, iFirstDay, dwFlags, S_OK, buff, out, 0)
472 static void test_VarWeekdayName(void)
477 int iWeekday
, fAbbrev
, iFirstDay
;
478 BSTR dayNames
[7][2]; /* Monday-Sunday, full/abbr */
479 DWORD defaultFirstDay
;
485 CHECKPTR(VarWeekdayName
);
487 SetLastError(0xdeadbeef);
488 GetLocaleInfoW(LOCALE_USER_DEFAULT
, 0, NULL
, 0);
489 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
491 win_skip("GetLocaleInfoW is not implemented\n");
495 /* Initialize days' names */
496 for (day
= 0; day
<= 6; ++day
)
498 for (fAbbrev
= 0; fAbbrev
<= 1; ++fAbbrev
)
500 localeValue
= fAbbrev
? LOCALE_SABBREVDAYNAME1
: LOCALE_SDAYNAME1
;
502 size
= GetLocaleInfoW(LOCALE_USER_DEFAULT
, localeValue
, NULL
, 0);
503 dayNames
[day
][fAbbrev
] = SysAllocStringLen(NULL
, size
- 1);
504 GetLocaleInfoW(LOCALE_USER_DEFAULT
, localeValue
,
505 dayNames
[day
][fAbbrev
], size
);
509 /* Get the user's first day of week. 0=Monday, .. */
511 LOCALE_USER_DEFAULT
, LOCALE_IFIRSTDAYOFWEEK
| LOCALE_RETURN_NUMBER
,
512 (LPWSTR
)&defaultFirstDay
, sizeof(defaultFirstDay
) / sizeof(WCHAR
));
514 /* Check invalid arguments */
515 VARWDN_F(0, 0, 4, 0, E_INVALIDARG
);
516 VARWDN_F(8, 0, 4, 0, E_INVALIDARG
);
517 VARWDN_F(4, 0, -1, 0, E_INVALIDARG
);
518 VARWDN_F(4, 0, 8, 0, E_INVALIDARG
);
520 hres
= pVarWeekdayName(1, 0, 0, 0, NULL
);
521 ok(E_INVALIDARG
== hres
,
522 "Null pointer: expected E_INVALIDARG, got 0x%08x\n", hres
);
524 /* Check all combinations */
525 for (iWeekday
= 1; iWeekday
<= 7; ++iWeekday
)
527 for (fAbbrev
= 0; fAbbrev
<= 1; ++fAbbrev
)
529 /* 0 = Default, 1 = Sunday, 2 = Monday, .. */
530 for (iFirstDay
= 0; iFirstDay
<= 7; ++iFirstDay
)
532 VARWDN_O(iWeekday
, fAbbrev
, iFirstDay
, 0);
534 firstDay
= defaultFirstDay
;
536 /* Translate from 0=Sunday to 0=Monday in the modulo 7 space */
537 firstDay
= iFirstDay
- 2;
538 day
= (7 + iWeekday
- 1 + firstDay
) % 7;
539 ok(VARCMP_EQ
== VarBstrCmp(out
, dayNames
[day
][fAbbrev
], LOCALE_USER_DEFAULT
, 0),
540 "VarWeekdayName(%d,%d,%d): got wrong dayname: '%s'\n",
541 iWeekday
, fAbbrev
, iFirstDay
, buff
);
548 for (day
= 0; day
<= 6; ++day
)
550 for (fAbbrev
= 0; fAbbrev
<= 1; ++fAbbrev
)
552 SysFreeString(dayNames
[day
][fAbbrev
]);
557 static void test_VarFormatFromTokens(void)
559 static WCHAR number_fmt
[] = {'#','#','#',',','#','#','0','.','0','0',0};
560 static const WCHAR number
[] = {'6',',','9','0',0};
561 static const WCHAR number_us
[] = {'6','9','0','.','0','0',0};
563 static WCHAR date_fmt
[] = {'d','d','-','m','m',0};
564 static const WCHAR date
[] = {'1','2','-','1','1',0};
565 static const WCHAR date_us
[] = {'1','1','-','1','2',0};
567 static WCHAR string_fmt
[] = {'@',0};
568 static const WCHAR string_de
[] = {'1',',','5',0};
569 static const WCHAR string_us
[] = {'1','.','5',0};
577 V_VT(&var
) = VT_BSTR
;
578 V_BSTR(&var
) = SysAllocString(number
);
580 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
581 hres
= VarTokenizeFormatString(number_fmt
, buff
, sizeof(buff
), 1, 1, lcid
, NULL
);
582 ok(hres
== S_OK
, "VarTokenizeFormatString failed: %x\n", hres
);
583 hres
= VarFormatFromTokens(&var
, number_fmt
, buff
, 0, &bstr
, lcid
);
584 ok(hres
== S_OK
, "VarFormatFromTokens failed: %x\n", hres
);
585 ok(!strcmpW(bstr
, number_us
), "incorrectly formatted number: %s\n", wine_dbgstr_w(bstr
));
588 lcid
= MAKELCID(MAKELANGID(LANG_GERMAN
, SUBLANG_GERMAN
), SORT_DEFAULT
);
589 hres
= VarTokenizeFormatString(number_fmt
, buff
, sizeof(buff
), 1, 1, lcid
, NULL
);
590 ok(hres
== S_OK
, "VarTokenizeFormatString failed: %x\n", hres
);
591 hres
= VarFormatFromTokens(&var
, number_fmt
, buff
, 0, &bstr
, lcid
);
592 ok(hres
== S_OK
, "VarFormatFromTokens failed: %x\n", hres
);
593 ok(!strcmpW(bstr
, number
), "incorrectly formatted number: %s\n", wine_dbgstr_w(bstr
));
598 V_VT(&var
) = VT_BSTR
;
599 V_BSTR(&var
) = SysAllocString(date
);
601 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
602 hres
= VarTokenizeFormatString(date_fmt
, buff
, sizeof(buff
), 1, 1, lcid
, NULL
);
603 ok(hres
== S_OK
, "VarTokenizeFormatString failed: %x\n", hres
);
604 hres
= VarFormatFromTokens(&var
, date_fmt
, buff
, 0, &bstr
, lcid
);
605 ok(hres
== S_OK
, "VarFormatFromTokens failed: %x\n", hres
);
606 ok(!strcmpW(bstr
, date_us
), "incorrectly formatted date: %s\n", wine_dbgstr_w(bstr
));
609 lcid
= MAKELCID(MAKELANGID(LANG_GERMAN
, SUBLANG_GERMAN
), SORT_DEFAULT
);
610 hres
= VarTokenizeFormatString(date_fmt
, buff
, sizeof(buff
), 1, 1, lcid
, NULL
);
611 ok(hres
== S_OK
, "VarTokenizeFormatString failed: %x\n", hres
);
612 hres
= VarFormatFromTokens(&var
, date_fmt
, buff
, 0, &bstr
, lcid
);
613 ok(hres
== S_OK
, "VarFormatFromTokens failed: %x\n", hres
);
614 ok(!strcmpW(bstr
, date
), "incorrectly formatted date: %s\n", wine_dbgstr_w(bstr
));
622 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
623 hres
= VarTokenizeFormatString(string_fmt
, buff
, sizeof(buff
), 1, 1, lcid
, NULL
);
624 ok(hres
== S_OK
, "VarTokenizeFormatString failed: %x\n", hres
);
625 hres
= VarFormatFromTokens(&var
, string_fmt
, buff
, 0, &bstr
, lcid
);
626 ok(hres
== S_OK
, "VarFormatFromTokens failed: %x\n", hres
);
627 ok(!strcmpW(bstr
, string_us
), "incorrectly formatted string: %s\n", wine_dbgstr_w(bstr
));
630 lcid
= MAKELCID(MAKELANGID(LANG_GERMAN
, SUBLANG_GERMAN
), SORT_DEFAULT
);
631 hres
= VarTokenizeFormatString(string_fmt
, buff
, sizeof(buff
), 1, 1, lcid
, NULL
);
632 ok(hres
== S_OK
, "VarTokenizeFormatString failed: %x\n", hres
);
633 hres
= VarFormatFromTokens(&var
, string_fmt
, buff
, 0, &bstr
, lcid
);
634 ok(hres
== S_OK
, "VarFormatFromTokens failed: %x\n", hres
);
635 ok(!strcmpW(bstr
, string_de
), "incorrectly formatted string: %s\n", wine_dbgstr_w(bstr
));
639 static void test_GetAltMonthNames(void)
641 LPOLESTR
*str
, *str2
;
644 str
= (void *)0xdeadbeef;
645 hr
= GetAltMonthNames(0, &str
);
646 ok(hr
== S_OK
, "Unexpected return value %08x\n", hr
);
647 ok(str
== NULL
, "Got %p\n", str
);
649 str
= (void *)0xdeadbeef;
650 hr
= GetAltMonthNames(MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
), &str
);
651 ok(hr
== S_OK
, "Unexpected return value %08x\n", hr
);
652 ok(str
== NULL
, "Got %p\n", str
);
655 hr
= GetAltMonthNames(MAKELCID(MAKELANGID(LANG_ARABIC
, SUBLANG_ARABIC_EGYPT
), SORT_DEFAULT
), &str
);
656 ok(hr
== S_OK
, "Unexpected return value %08x\n", hr
);
657 ok(str
!= NULL
, "Got %p\n", str
);
660 hr
= GetAltMonthNames(MAKELCID(MAKELANGID(LANG_ARABIC
, SUBLANG_ARABIC_EGYPT
), SORT_DEFAULT
), &str2
);
661 ok(hr
== S_OK
, "Unexpected return value %08x\n", hr
);
662 ok(str2
== str
, "Got %p\n", str2
);
665 hr
= GetAltMonthNames(MAKELCID(MAKELANGID(LANG_RUSSIAN
, SUBLANG_DEFAULT
), SORT_DEFAULT
), &str
);
666 ok(hr
== S_OK
, "Unexpected return value %08x\n", hr
);
667 ok(str
!= NULL
, "Got %p\n", str
);
670 hr
= GetAltMonthNames(MAKELCID(MAKELANGID(LANG_POLISH
, SUBLANG_DEFAULT
), SORT_DEFAULT
), &str
);
671 ok(hr
== S_OK
, "Unexpected return value %08x\n", hr
);
672 ok(str
!= NULL
, "Got %p\n", str
);
675 START_TEST(varformat
)
677 hOleaut32
= GetModuleHandleA("oleaut32.dll");
679 has_i8
= GetProcAddress(hOleaut32
, "VarI8FromI1") != NULL
;
681 test_VarFormatNumber();
683 test_VarWeekdayName();
684 test_VarFormatFromTokens();
685 test_GetAltMonthNames();