ReactOS 0.4.17-dev-357-ga8f14ff
varformat.c
Go to the documentation of this file.
1/*
2 * VARFORMAT test program
3 *
4 * Copyright 1998 Jean-Claude Cote
5 * Copyright 2006 Google (Benjamin Arai)
6 *
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.
11 *
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.
16 *
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
20 */
21
22#include <stdarg.h>
23#include <stdio.h>
24#include <math.h>
25#include <float.h>
26
27#include "windef.h"
28#include "winbase.h"
29#include "winsock2.h"
30#include "wine/test.h"
31#include "winuser.h"
32#include "wingdi.h"
33#include "winnls.h"
34#include "winerror.h"
35#include "winnt.h"
36
37#include "wtypes.h"
38#include "oleauto.h"
39
40#define FMT_NUMBER(vt,val) \
41 VariantInit(&v); V_VT(&v) = vt; val(&v) = 1; \
42 hres = VarFormatNumber(&v,2,0,0,0,0,&str); \
43 ok(hres == S_OK, "VarFormatNumber (vt %d): returned %8lx\n", vt, hres); \
44 if (hres == S_OK) { \
45 ok(str && wcscmp(str,szResult1) == 0, \
46 "VarFormatNumber (vt %d): string different\n", vt); \
47 SysFreeString(str); \
48 }
49
50static void test_VarFormatNumber(void)
51{
52 static const WCHAR szResult1[] = L"1.00";
53 char buff[8];
55 VARIANT v;
56 BSTR str = NULL;
57
59 if (buff[0] != '.' || buff[1])
60 {
61 skip("Skipping VarFormatNumber tests as decimal separator is '%s'\n", buff);
62 return;
63 }
64
76
77 V_VT(&v) = VT_BSTR;
78 V_BSTR(&v) = SysAllocString(L"1");
79
80 hres = VarFormatNumber(&v,2,0,0,0,0,&str);
81 ok(hres == S_OK, "VarFormatNumber (bstr): returned %8lx\n", hres);
82 if (hres == S_OK)
83 ok(str && wcscmp(str, szResult1) == 0, "VarFormatNumber (bstr): string different\n");
86
87 V_BSTR(&v) = SysAllocString(L"-1");
88 hres = VarFormatNumber(&v,2,0,-1,0,0,&str);
89 ok(hres == S_OK, "VarFormatNumber (bstr): returned %8lx\n", hres);
90 if (hres == S_OK)
91 ok(str && wcscmp(str, L"(1.00)") == 0, "VarFormatNumber (-bstr): string different\n");
94}
95
96#define SIGNED_VTBITS (VTBIT_I1|VTBIT_I2|VTBIT_I4|VTBIT_I8|VTBIT_R4|VTBIT_R8)
97
98static const char *szVarFmtFail = "VT %d|0x%04x Format %s: expected 0x%08x, '%s', got 0x%08x, '%s'\n";
99#define VARFMT(vt,v,val,fmt,ret,str) do { \
100 out = NULL; \
101 V_VT(&in) = (vt); v(&in) = val; \
102 if (fmt) MultiByteToWideChar(CP_ACP, 0, fmt, -1, buffW, ARRAY_SIZE(buffW)); \
103 hres = VarFormat(&in,fmt ? buffW : NULL,fd,fw,flags,&out); \
104 if (SUCCEEDED(hres)) WideCharToMultiByte(CP_ACP, 0, out, -1, buff, sizeof(buff),0,0); \
105 else buff[0] = '\0'; \
106 ok(hres == ret && (FAILED(ret) || !strcmp(buff, str)), \
107 szVarFmtFail, \
108 (vt)&VT_TYPEMASK,(vt)&~VT_TYPEMASK,fmt?fmt:"<null>",ret,str,hres,buff); \
109 SysFreeString(out); \
110 } while(0)
111
112typedef struct tagFMTRES
113{
118
119static const FMTRES VarFormat_results[] =
120{
121 { NULL, "1", "0" },
122 { "", "1", "0" },
123 { "General Number", "1", "0" },
124 { "Percent", "100.00%", "0.00%" },
125 { "Standard", "1.00", "0.00" },
126 { "Scientific","1.00E+00", "0.00E+00" },
127 { "True/False", "True", "False" },
128 { "On/Off", "On", "Off" },
129 { "Yes/No", "Yes", "No" },
130 { "#", "1", "" },
131 { "##", "1", "" },
132 { "#.#", "1.", "." },
133 { "0", "1", "0" },
134 { "00", "01", "00" },
135 { "0.0", "1.0", "0.0" },
136 { "00\\c\\o\\p\\y", "01copy","00copy" },
137 { "\"pos\";\"neg\"", "pos", "pos" },
138 { "\"pos\";\"neg\";\"zero\"","pos", "zero" }
139};
140
141typedef struct tagFMTDATERES
142{
147
149{
150 { 0.0, "w", "7" },
151 { 0.0, "w", "6" },
152 { 0.0, "w", "5" },
153 { 0.0, "w", "4" },
154 { 0.0, "w", "3" },
155 { 0.0, "w", "2" },
156 { 0.0, "w", "1" }, /* First 7 entries must remain in this order! */
157 { 2.525, "am/pm", "pm" },
158 { 2.525, "AM/PM", "PM" },
159 { 2.525, "A/P", "P" },
160 { 2.525, "a/p", "p" },
161 { 2.525, "q", "1" },
162 { 2.525, "d", "1" },
163 { 2.525, "dd", "01" },
164 { 2.525, "ddd", "Mon" },
165 { 2.525, "dddd", "Monday" },
166 { 2.525, "mmm", "Jan" },
167 { 2.525, "mmmm", "January" },
168 { 2.525, "y", "1" },
169 { 2.525, "yy", "00" },
170 { 2.525, "yyy", "001" },
171 { 2.525, "yyyy", "1900" },
172 { 2.525, "dd mm yyyy hh:mm:ss", "01 01 1900 12:36:00" },
173 { 2.525, "dd mm yyyy mm", "01 01 1900 01" },
174 { 2.525, "dd mm yyyy :mm", "01 01 1900 :01" },
175 { 2.525, "dd mm yyyy hh:mm", "01 01 1900 12:36" },
176 { 2.525, "mm mm", "01 01" },
177 { 2.525, "mm :mm:ss", "01 :01:00" },
178 { 2.525, "mm :ss:mm", "01 :00:01" },
179 { 2.525, "hh:mm :ss:mm", "12:36 :00:01" },
180 { 2.525, "hh:dd :mm:mm", "12:01 :01:01" },
181 { 2.525, "dd:hh :mm:mm", "01:12 :36:01" },
182 { 2.525, "hh :mm:mm", "12 :36:01" },
183 { 2.525, "dd :mm:mm", "01 :01:01" },
184 { 2.525, "dd :mm:nn", "01 :01:36" },
185 { 2.725, "hh:nn:ss A/P", "05:24:00 P" },
186 { 40531.0, "dddd", "Sunday" },
187 { 40531.0, "ddd", "Sun" }
188};
189
190/* The following tests require that the time separator is a colon (:) */
192{
193 { 2.525, "short time", "12:36" },
194 { 2.525, "medium time", "12:36 PM" },
195 { 2.525, "long time", "12:36:00 PM" }
196};
197
198#define VNUMFMT(vt,v) \
199 for (i = 0; i < ARRAY_SIZE(VarFormat_results); i++) \
200 { \
201 VARFMT(vt,v,1,VarFormat_results[i].fmt,S_OK,VarFormat_results[i].one_res); \
202 VARFMT(vt,v,0,VarFormat_results[i].fmt,S_OK,VarFormat_results[i].zero_res); \
203 } \
204 if ((1 << vt) & SIGNED_VTBITS) \
205 { \
206 VARFMT(vt,v,-1,"\"pos\";\"neg\"",S_OK,"neg"); \
207 VARFMT(vt,v,-1,"\"pos\";\"neg\";\"zero\"",S_OK,"neg"); \
208 }
209
210static void test_VarFormat(void)
211{
212 size_t i;
213 WCHAR buffW[256];
214 char buff[256];
215 VARIANT in;
216 VARIANT_BOOL bTrue = VARIANT_TRUE, bFalse = VARIANT_FALSE;
217 int fd = 0, fw = 0;
218 ULONG flags = 0;
219 BSTR bstrin, out = NULL;
221
223 {
224 skip("Skipping VarFormat tests for non English language\n");
225 return;
226 }
228 if (buff[0] != '.' || buff[1])
229 {
230 skip("Skipping VarFormat tests as decimal separator is '%s'\n", buff);
231 return;
232 }
234 if (buff[0] != '2' || buff[1])
235 {
236 skip("Skipping VarFormat tests as decimal places is '%s'\n", buff);
237 return;
238 }
239
240 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"True/False",S_OK,"True");
241 VARFMT(VT_BOOL,V_BOOL,VARIANT_FALSE,"True/False",S_OK,"False");
242
255
256 /* Reference types are dereferenced */
257 VARFMT(VT_BOOL|VT_BYREF,V_BOOLREF,&bTrue,"True/False",S_OK,"True");
258 VARFMT(VT_BOOL|VT_BYREF,V_BOOLREF,&bFalse,"True/False",S_OK,"False");
259
260 /* Dates */
261 for (i = 0; i < ARRAY_SIZE(VarFormat_date_results); i++)
262 {
263 if (i < 7)
264 fd = i + 1; /* Test first day */
265 else
266 fd = 0;
270 }
271
272 /* Named time formats */
274 if (strcmp(buff, "h:mm:ss tt"))
275 {
276 skip("Skipping named time tests as time format is '%s'\n", buff);
277 }
278 else
279 {
281 {
282 fd = 0;
286 }
287 }
288
289 /* Strings */
290 bstrin = SysAllocString(L"testing");
291 VARFMT(VT_BSTR,V_BSTR,bstrin,"",S_OK,"testing");
292 VARFMT(VT_BSTR,V_BSTR,bstrin,"@",S_OK,"testing");
293 VARFMT(VT_BSTR,V_BSTR,bstrin,"&",S_OK,"testing");
294 VARFMT(VT_BSTR,V_BSTR,bstrin,"\\x@\\x@",S_OK,"xtxesting");
295 VARFMT(VT_BSTR,V_BSTR,bstrin,"\\x&\\x&",S_OK,"xtxesting");
296 VARFMT(VT_BSTR,V_BSTR,bstrin,"@\\x",S_OK,"txesting");
297 VARFMT(VT_BSTR,V_BSTR,bstrin,"@@@@@@@@",S_OK," testing");
298 VARFMT(VT_BSTR,V_BSTR,bstrin,"@\\x@@@@@@@",S_OK," xtesting");
299 VARFMT(VT_BSTR,V_BSTR,bstrin,"&&&&&&&&",S_OK,"testing");
300 VARFMT(VT_BSTR,V_BSTR,bstrin,"!&&&&&&&",S_OK,"testing");
301 VARFMT(VT_BSTR,V_BSTR,bstrin,"&&&&&&&!",S_OK,"testing");
302 VARFMT(VT_BSTR,V_BSTR,bstrin,">&&",S_OK,"TESTING");
303 VARFMT(VT_BSTR,V_BSTR,bstrin,"<&&",S_OK,"testing");
304 VARFMT(VT_BSTR,V_BSTR,bstrin,"<&>&",S_OK,"testing");
305 SysFreeString(bstrin);
306 bstrin = SysAllocString(L"39697.11");
307 VARFMT(VT_BSTR,V_BSTR,bstrin,"hh:mm",S_OK,"02:38");
308 VARFMT(VT_BSTR,V_BSTR,bstrin,"mm-dd-yy",S_OK,"09-06-08");
309 SysFreeString(bstrin);
310 /* Numeric values are converted to strings then output */
311 VARFMT(VT_I1,V_I1,1,"<&>&",S_OK,"1");
312
313 /* Number formats */
314 VARFMT(VT_I4,V_I4,1,"#00000000",S_OK,"00000001");
315 VARFMT(VT_I4,V_I4,1,"000###",S_OK,"000001");
316 VARFMT(VT_I4,V_I4,1,"#00##00#0",S_OK,"00000001");
317 VARFMT(VT_I4,V_I4,1,"1#####0000",S_OK,"10001");
318 VARFMT(VT_I4,V_I4,1,"##abcdefghijklmnopqrstuvwxyz",S_OK,"1abcdefghijklmnopqrstuvwxyz");
319 VARFMT(VT_I4,V_I4,100000,"#,###,###,###",S_OK,"100,000");
320 VARFMT(VT_I4,V_I4,1,"0,000,000,000",S_OK,"0,000,000,001");
321 VARFMT(VT_I4,V_I4,123456789,"#,#.#",S_OK,"123,456,789.");
322 VARFMT(VT_I4,V_I4,123456789,"###, ###, ###",S_OK,"123, 456, 789");
323 VARFMT(VT_I4,V_I4,1,"#;-#",S_OK,"1");
324 VARFMT(VT_I4,V_I4,-1,"#;-#",S_OK,"-1");
325 VARFMT(VT_R8,V_R8,1.23456789,"0#.0#0#0#0#0",S_OK,"01.234567890");
326 VARFMT(VT_R8,V_R8,1.2,"0#.0#0#0#0#0",S_OK,"01.200000000");
327 VARFMT(VT_R8,V_R8,9.87654321,"#0.#0#0#0#0#",S_OK,"9.87654321");
328 VARFMT(VT_R8,V_R8,9.8,"#0.#0#0#0#0#",S_OK,"9.80000000");
329 VARFMT(VT_R8,V_R8,0.00000008,"#0.#0#0#0#0#0",S_OK,"0.0000000800");
330 VARFMT(VT_R8,V_R8,0.00010705,"#0.##########",S_OK,"0.00010705");
331 VARFMT(VT_I4,V_I4,17,"#0",S_OK,"17");
332 VARFMT(VT_I4,V_I4,4711,"#0",S_OK,"4711");
333 VARFMT(VT_I4,V_I4,17,"#00",S_OK,"17");
334 VARFMT(VT_I4,V_I4,100,"0##",S_OK,"100");
335 VARFMT(VT_I4,V_I4,17,"#000",S_OK,"017");
336 VARFMT(VT_I4,V_I4,17,"#0.00",S_OK,"17.00");
337 VARFMT(VT_I4,V_I4,17,"#0000.00",S_OK,"0017.00");
338 VARFMT(VT_I4,V_I4,17,"#.00",S_OK,"17.00");
339 VARFMT(VT_R8,V_R8,1.7,"#.00",S_OK,"1.70");
340 VARFMT(VT_R8,V_R8,.17,"#.00",S_OK,".17");
341 VARFMT(VT_I4,V_I4,17,"#3",S_OK,"173");
342 VARFMT(VT_I4,V_I4,17,"#33",S_OK,"1733");
343 VARFMT(VT_I4,V_I4,17,"#3.33",S_OK,"173.33");
344 VARFMT(VT_I4,V_I4,17,"#3333.33",S_OK,"173333.33");
345 VARFMT(VT_I4,V_I4,17,"#.33",S_OK,"17.33");
346 VARFMT(VT_R8,V_R8,.17,"#.33",S_OK,".33");
347 VARFMT(VT_R8,V_R8,1.7,"0.0000E-000",S_OK,"1.7000E000");
348 VARFMT(VT_R8,V_R8,1.7,"0.0000e-1",S_OK,"1.7000e01");
349 VARFMT(VT_R8,V_R8,86.936849,"#0.000000000000e-000",S_OK,"86.936849000000e000");
350 VARFMT(VT_R8,V_R8,1.7,"#0",S_OK,"2");
351 VARFMT(VT_R8,V_R8,1.7,"#.33",S_OK,"2.33");
352 VARFMT(VT_R8,V_R8,1.7,"#3",S_OK,"23");
353 VARFMT(VT_R8,V_R8,1.73245,"0.0000E+000",S_OK,"1.7325E+000");
354 VARFMT(VT_R8,V_R8,9.9999999,"#0.000000",S_OK,"10.000000");
355 VARFMT(VT_R8,V_R8,1.7,"0.0000e+0#",S_OK,"1.7000e+0");
356 VARFMT(VT_R8,V_R8,100.0001e+0,"0.0000E+0",S_OK,"1.0000E+2");
357 VARFMT(VT_R8,V_R8,1000001,"0.0000e+1",S_OK,"1.0000e+61");
358 VARFMT(VT_R8,V_R8,100.0001e+25,"0.0000e+0",S_OK,"1.0000e+27");
359 VARFMT(VT_R8,V_R8,450.0001e+43,"#000.0000e+0",S_OK,"4500.0010e+42");
360 VARFMT(VT_R8,V_R8,0.0001e-11,"##00.0000e-0",S_OK,"1000.0000e-18");
361 VARFMT(VT_R8,V_R8,0.0317e-11,"0000.0000e-0",S_OK,"3170.0000e-16");
362 VARFMT(VT_R8,V_R8,0.0021e-11,"00##.0000e-0",S_OK,"2100.0000e-17");
363 VARFMT(VT_R8,V_R8,1.0001e-27,"##00.0000e-0",S_OK,"1000.1000e-30");
364 VARFMT(VT_R8,V_R8,47.11,".0000E+0",S_OK,".4711E+2");
365 VARFMT(VT_R8,V_R8,3.0401e-13,"#####.####e-0%",S_OK,"30401.e-15%");
366 VARFMT(VT_R8,V_R8,1.57,"0.00",S_OK,"1.57");
367 VARFMT(VT_R8,V_R8,-1.57,"0.00",S_OK,"-1.57");
368 VARFMT(VT_R8,V_R8,-1.57,"#.##",S_OK,"-1.57");
369 VARFMT(VT_R8,V_R8,-0.1,".#",S_OK,"-.1");
370 VARFMT(VT_R8,V_R8,0.099,"#.#",S_OK,".1");
371 VARFMT(VT_R8,V_R8,0.0999,"#.##",S_OK,".1");
372 VARFMT(VT_R8,V_R8,0.099,"#.##",S_OK,".1");
373 VARFMT(VT_R8,V_R8,0.0099,"#.##",S_OK,".01");
374 VARFMT(VT_R8,V_R8,0.0049,"#.##",S_OK,".");
375 VARFMT(VT_R8,V_R8,0.0094,"#.##",S_OK,".01");
376 VARFMT(VT_R8,V_R8,0.00099,"#.##",S_OK,".");
377 VARFMT(VT_R8,V_R8,0.0995,"#.##",S_OK,".1");
378 VARFMT(VT_R8,V_R8,8.0995,"#.##",S_OK,"8.1");
379 VARFMT(VT_R8,V_R8,0.0994,"#.##",S_OK,".1");
380 VARFMT(VT_R8,V_R8,1.00,"#,##0.00",S_OK,"1.00");
381 VARFMT(VT_R8,V_R8,0.0995,"#.###",S_OK,".1");
382
383
384 /* 'out' is not cleared */
385 out = (BSTR)0x1;
386 hres = VarFormat(&in,NULL,fd,fw,flags,&out); /* Would crash if out is cleared */
387 ok(hres == S_OK, "got %08lx\n", hres);
389 out = NULL;
390
391 /* VT_NULL */
392 V_VT(&in) = VT_NULL;
393 hres = VarFormat(&in,NULL,fd,fw,0,&out);
394 ok(hres == S_OK, "VarFormat failed with 0x%08lx\n", hres);
395 ok(out == NULL, "expected NULL formatted string\n");
396
397 /* Invalid args */
399 ok(hres == E_INVALIDARG, "Null out: expected E_INVALIDARG, got 0x%08lx\n", hres);
401 ok(hres == E_INVALIDARG, "Null in: expected E_INVALIDARG, got 0x%08lx\n", hres);
402 fd = -1;
403 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
404 fd = 8;
405 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
406 fd = 0; fw = -1;
407 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
408 fw = 4;
409 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
410}
411
412static const char *szVarWdnFail =
413 "VarWeekdayName (%d, %d, %d, %d, %x): returned %8x, expected %8x\n";
414#define VARWDN(iWeekday, fAbbrev, iFirstDay, dwFlags, ret, buff, out, freeOut) \
415do { \
416 hres = VarWeekdayName(iWeekday, fAbbrev, iFirstDay, dwFlags, &out); \
417 if (SUCCEEDED(hres)) { \
418 WideCharToMultiByte(CP_ACP, 0, out, -1, buff, sizeof(buff), 0, 0); \
419 if (freeOut) SysFreeString(out); \
420 } else { \
421 buff[0] = '\0'; \
422 } \
423 ok(hres == ret, \
424 szVarWdnFail, \
425 iWeekday, fAbbrev, iFirstDay, dwFlags, &out, hres, ret \
426 ); \
427} while(0)
428
429#define VARWDN_F(iWeekday, fAbbrev, iFirstDay, dwFlags, ret) \
430 VARWDN(iWeekday, fAbbrev, iFirstDay, dwFlags, ret, buff, out, 1)
431
432#define VARWDN_O(iWeekday, fAbbrev, iFirstDay, dwFlags) \
433 VARWDN(iWeekday, fAbbrev, iFirstDay, dwFlags, S_OK, buff, out, 0)
434
435static void test_VarWeekdayName(void)
436{
437 char buff[256];
438 BSTR out = NULL;
440 int iWeekday, fAbbrev, iFirstDay;
441 BSTR dayNames[7][2]; /* Monday-Sunday, full/abbr */
442 DWORD defaultFirstDay;
443 int firstDay;
444 int day;
445 int size;
446 DWORD localeValue;
447
448 SetLastError(0xdeadbeef);
451 {
452 win_skip("GetLocaleInfoW is not implemented\n");
453 return;
454 }
455
456 /* Initialize days' names */
457 for (day = 0; day <= 6; ++day)
458 {
459 for (fAbbrev = 0; fAbbrev <= 1; ++fAbbrev)
460 {
461 localeValue = fAbbrev ? LOCALE_SABBREVDAYNAME1 : LOCALE_SDAYNAME1;
462 localeValue += day;
463 size = GetLocaleInfoW(LOCALE_USER_DEFAULT, localeValue, NULL, 0);
464 dayNames[day][fAbbrev] = SysAllocStringLen(NULL, size - 1);
466 dayNames[day][fAbbrev], size);
467 }
468 }
469
470 /* Get the user's first day of week. 0=Monday, .. */
472 LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK | LOCALE_RETURN_NUMBER,
473 (LPWSTR)&defaultFirstDay, sizeof(defaultFirstDay) / sizeof(WCHAR));
474
475 /* Check invalid arguments */
476 VARWDN_F(0, 0, 4, 0, E_INVALIDARG);
477 VARWDN_F(8, 0, 4, 0, E_INVALIDARG);
478 VARWDN_F(4, 0, -1, 0, E_INVALIDARG);
479 VARWDN_F(4, 0, 8, 0, E_INVALIDARG);
480
481 hres = VarWeekdayName(1, 0, 0, 0, NULL);
483 "Null pointer: expected E_INVALIDARG, got 0x%08lx\n", hres);
484
485 /* Check all combinations */
486 for (iWeekday = 1; iWeekday <= 7; ++iWeekday)
487 {
488 for (fAbbrev = 0; fAbbrev <= 1; ++fAbbrev)
489 {
490 /* 0 = Default, 1 = Sunday, 2 = Monday, .. */
491 for (iFirstDay = 0; iFirstDay <= 7; ++iFirstDay)
492 {
493 VARWDN_O(iWeekday, fAbbrev, iFirstDay, 0);
494 if (iFirstDay == 0)
495 firstDay = defaultFirstDay;
496 else
497 /* Translate from 0=Sunday to 0=Monday in the modulo 7 space */
498 firstDay = iFirstDay - 2;
499 day = (7 + iWeekday - 1 + firstDay) % 7;
500 ok(VARCMP_EQ == VarBstrCmp(out, dayNames[day][fAbbrev], LOCALE_USER_DEFAULT, 0),
501 "VarWeekdayName(%d,%d,%d): got wrong dayname: '%s'\n",
502 iWeekday, fAbbrev, iFirstDay, buff);
504 }
505 }
506 }
507
508 /* Cleanup */
509 for (day = 0; day <= 6; ++day)
510 {
511 for (fAbbrev = 0; fAbbrev <= 1; ++fAbbrev)
512 {
513 SysFreeString(dayNames[day][fAbbrev]);
514 }
515 }
516}
517
519{
520 static WCHAR number_fmt[] = L"###,##0.00";
521 static WCHAR date_fmt[] = L"dd-mm";
522 static WCHAR string_fmt[] = L"@";
523
524 BYTE buff[256];
525 LCID lcid;
526 VARIANT var;
527 BSTR bstr;
529
530 V_VT(&var) = VT_BSTR;
531 V_BSTR(&var) = SysAllocString(L"6,90");
532
534 hres = VarTokenizeFormatString(number_fmt, buff, sizeof(buff), 1, 1, lcid, NULL);
535 ok(hres == S_OK, "VarTokenizeFormatString failed: %lx\n", hres);
536 hres = VarFormatFromTokens(&var, number_fmt, buff, 0, &bstr, lcid);
537 ok(hres == S_OK, "VarFormatFromTokens failed: %lx\n", hres);
538 ok(!wcscmp(bstr, L"690.00"), "incorrectly formatted number: %s\n", wine_dbgstr_w(bstr));
539 SysFreeString(bstr);
540
542 hres = VarTokenizeFormatString(number_fmt, buff, sizeof(buff), 1, 1, lcid, NULL);
543 ok(hres == S_OK, "VarTokenizeFormatString failed: %lx\n", hres);
544 hres = VarFormatFromTokens(&var, number_fmt, buff, 0, &bstr, lcid);
545 ok(hres == S_OK, "VarFormatFromTokens failed: %lx\n", hres);
546 ok(!wcscmp(bstr, L"6,90"), "incorrectly formatted number: %s\n", wine_dbgstr_w(bstr));
547 SysFreeString(bstr);
548
550
551 V_VT(&var) = VT_BSTR;
552 V_BSTR(&var) = SysAllocString(L"12-11");
553
555 hres = VarTokenizeFormatString(date_fmt, buff, sizeof(buff), 1, 1, lcid, NULL);
556 ok(hres == S_OK, "VarTokenizeFormatString failed: %lx\n", hres);
557 hres = VarFormatFromTokens(&var, date_fmt, buff, 0, &bstr, lcid);
558 ok(hres == S_OK, "VarFormatFromTokens failed: %lx\n", hres);
559 ok(!wcscmp(bstr, L"11-12"), "incorrectly formatted date: %s\n", wine_dbgstr_w(bstr));
560 SysFreeString(bstr);
561
563 hres = VarTokenizeFormatString(date_fmt, buff, sizeof(buff), 1, 1, lcid, NULL);
564 ok(hres == S_OK, "VarTokenizeFormatString failed: %lx\n", hres);
565 hres = VarFormatFromTokens(&var, date_fmt, buff, 0, &bstr, lcid);
566 ok(hres == S_OK, "VarFormatFromTokens failed: %lx\n", hres);
567 ok(!wcscmp(bstr, L"12-11"), "incorrectly formatted date: %s\n", wine_dbgstr_w(bstr));
568 SysFreeString(bstr);
569
571
572 V_VT(&var) = VT_R4;
573 V_R4(&var) = 1.5;
574
576 hres = VarTokenizeFormatString(string_fmt, buff, sizeof(buff), 1, 1, lcid, NULL);
577 ok(hres == S_OK, "VarTokenizeFormatString failed: %lx\n", hres);
578 hres = VarFormatFromTokens(&var, string_fmt, buff, 0, &bstr, lcid);
579 ok(hres == S_OK, "VarFormatFromTokens failed: %lx\n", hres);
580 ok(!wcscmp(bstr, L"1.5"), "incorrectly formatted string: %s\n", wine_dbgstr_w(bstr));
581 SysFreeString(bstr);
582
584 hres = VarTokenizeFormatString(string_fmt, buff, sizeof(buff), 1, 1, lcid, NULL);
585 ok(hres == S_OK, "VarTokenizeFormatString failed: %lx\n", hres);
586 hres = VarFormatFromTokens(&var, string_fmt, buff, 0, &bstr, lcid);
587 ok(hres == S_OK, "VarFormatFromTokens failed: %lx\n", hres);
588 ok(!wcscmp(bstr, L"1,5"), "incorrectly formatted string: %s\n", wine_dbgstr_w(bstr));
589 SysFreeString(bstr);
590}
591
592static void test_GetAltMonthNames(void)
593{
594 LPOLESTR *str, *str2;
595 HRESULT hr;
596
597 str = (void *)0xdeadbeef;
598 hr = GetAltMonthNames(0, &str);
599 ok(hr == S_OK, "Unexpected return value %08lx\n", hr);
600 ok(str == NULL, "Got %p\n", str);
601
602 str = (void *)0xdeadbeef;
604 ok(hr == S_OK, "Unexpected return value %08lx\n", hr);
605 ok(str == NULL, "Got %p\n", str);
606
607 str = NULL;
609 ok(hr == S_OK, "Unexpected return value %08lx\n", hr);
610 ok(str != NULL, "Got %p\n", str);
611
612 str2 = NULL;
614 ok(hr == S_OK, "Unexpected return value %08lx\n", hr);
615 ok(str2 == str, "Got %p\n", str2);
616
617 str = NULL;
619 ok(hr == S_OK, "Unexpected return value %08lx\n", hr);
620 ok(str != NULL, "Got %p\n", str);
621
622 str = NULL;
624 ok(hr == S_OK, "Unexpected return value %08lx\n", hr);
625 ok(str != NULL, "Got %p\n", str);
626}
627
628static void test_VarFormatCurrency(void)
629{
630 HRESULT hr;
631 VARIANT in;
632 BSTR str, str2;
633
634 V_CY(&in).int64 = 0;
635 V_VT(&in) = VT_CY;
636 hr = VarFormatCurrency(&in, 3, -2, -2, -2, 0, &str);
637 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
638
639 V_VT(&in) = VT_BSTR;
640 V_BSTR(&in) = str;
641 hr = VarFormatCurrency(&in, 1, -2, -2, -2, 0, &str2);
642 ok(hr == S_OK, "Unexpected hr %#lx for %s\n", hr, wine_dbgstr_w(str));
643 ok(lstrcmpW(str, str2), "Expected different string.\n");
645
646 V_VT(&in) = VT_BSTR | VT_BYREF;
647 V_BSTRREF(&in) = &str;
648 hr = VarFormatCurrency(&in, 1, -2, -2, -2, 0, &str2);
649 ok(hr == S_OK, "Unexpected hr %#lx for %s\n", hr, wine_dbgstr_w(str));
650 ok(lstrcmpW(str, str2), "Expected different string.\n");
651
654
655 V_VT(&in) = VT_BSTR;
656 V_BSTR(&in) = SysAllocString(L"test");
657 hr = VarFormatCurrency(&in, 1, -2, -2, -2, 0, &str2);
658 ok(hr == DISP_E_TYPEMISMATCH, "Unexpected hr %#lx.\n", hr);
660}
661
662static void test_VarFormatDateTime(void)
663{
664 VARIANT in;
665 HRESULT hr;
666 BSTR str;
667
668 V_VT(&in) = VT_NULL;
669 str = (void *)0xdeadbeef;
670 hr = VarFormatDateTime(&in, 0, 0, &str);
671 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
672 ok(!str, "Unexpected out string %p.\n", str);
673}
674
675START_TEST(varformat)
676{
684}
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define ARRAY_SIZE(A)
Definition: main.h:20
#define E_INVALIDARG
Definition: ddrawi.h:101
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
double DATE
Definition: compat.h:2253
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define SetLastError(x)
Definition: compat.h:752
OLECHAR * BSTR
Definition: compat.h:2293
short VARIANT_BOOL
Definition: compat.h:2290
@ VT_UI8
Definition: compat.h:2315
@ VT_BSTR
Definition: compat.h:2303
@ VT_INT
Definition: compat.h:2316
@ VT_R4
Definition: compat.h:2299
@ VT_NULL
Definition: compat.h:2296
@ VT_BYREF
Definition: compat.h:2342
@ VT_UI2
Definition: compat.h:2312
@ VT_R8
Definition: compat.h:2300
@ VT_CY
Definition: compat.h:2301
@ VT_I8
Definition: compat.h:2314
@ VT_I1
Definition: compat.h:2310
@ VT_I4
Definition: compat.h:2298
@ VT_DATE
Definition: compat.h:2302
@ VT_BOOL
Definition: compat.h:2306
@ VT_I2
Definition: compat.h:2297
@ VT_UI4
Definition: compat.h:2313
@ VT_UINT
Definition: compat.h:2317
@ VT_UI1
Definition: compat.h:2311
static DOUBLE day(DOUBLE time)
Definition: date.c:75
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4152
INT WINAPI GetLocaleInfoA(LCID lcid, LCTYPE lctype, LPSTR buffer, INT len)
Definition: locale.c:1609
LCID WINAPI GetUserDefaultLCID(void)
Definition: locale.c:1216
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: locale.c:1675
LCID lcid
Definition: locale.c:5660
_ACRTIMP int __cdecl wcscmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:1977
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3324
HRESULT WINAPI VarTokenizeFormatString(LPOLESTR lpszFormat, LPBYTE rgbTok, int cbTok, int nFirstDay, int nFirstWeek, LCID lcid, int *pcbActual)
Definition: varformat.c:495
HRESULT WINAPI VarFormat(LPVARIANT pVarIn, LPOLESTR lpszFormat, int nFirstDay, int nFirstWeek, ULONG dwFlags, BSTR *pbstrOut)
Definition: varformat.c:2138
HRESULT WINAPI VarFormatFromTokens(LPVARIANT pVarIn, LPOLESTR lpszFormat, LPBYTE rgbTok, ULONG dwFlags, BSTR *pbstrOut, LCID lcid)
Definition: varformat.c:2050
HRESULT WINAPI VarWeekdayName(INT iWeekday, INT fAbbrev, INT iFirstDay, ULONG dwFlags, BSTR *pbstrOut)
Definition: varformat.c:2568
HRESULT WINAPI VarFormatDateTime(LPVARIANT pVarIn, INT nFormat, ULONG dwFlags, BSTR *pbstrOut)
Definition: varformat.c:2190
HRESULT WINAPI VarFormatNumber(LPVARIANT pVarIn, INT nDigits, INT nLeading, INT nParens, INT nGrouping, ULONG dwFlags, BSTR *pbstrOut)
Definition: varformat.c:2241
HRESULT WINAPI VarFormatCurrency(LPVARIANT pVarIn, INT nDigits, INT nLeading, INT nParens, INT nGrouping, ULONG dwFlags, BSTR *pbstrOut)
Definition: varformat.c:2420
HRESULT WINAPI VarBstrCmp(BSTR pbstrLeft, BSTR pbstrRight, LCID lcid, DWORD dwFlags)
Definition: vartype.c:7158
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
const GLdouble * v
Definition: gl.h:2040
GLuint res
Definition: glext.h:9613
GLsizeiptr size
Definition: glext.h:5919
GLuint in
Definition: glext.h:9616
GLbitfield flags
Definition: glext.h:7161
GLuint GLfloat * val
Definition: glext.h:7180
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define S_OK
Definition: intsafe.h:52
#define wine_dbgstr_w
Definition: kernel32.h:34
#define win_skip
Definition: minitest.h:67
const char * var
Definition: shader.c:5666
HRESULT hres
Definition: protocol.c:465
#define VARFMT(vt, v, val, fmt, ret, str)
Definition: varformat.c:99
static const char * szVarWdnFail
Definition: varformat.c:412
static void test_VarFormatFromTokens(void)
Definition: varformat.c:518
static const FMTRES VarFormat_results[]
Definition: varformat.c:119
static void test_VarWeekdayName(void)
Definition: varformat.c:435
static void test_VarFormatDateTime(void)
Definition: varformat.c:662
struct tagFMTRES FMTRES
#define VARWDN_F(iWeekday, fAbbrev, iFirstDay, dwFlags, ret)
Definition: varformat.c:429
static const char * szVarFmtFail
Definition: varformat.c:98
#define VARWDN_O(iWeekday, fAbbrev, iFirstDay, dwFlags)
Definition: varformat.c:432
static void test_VarFormatNumber(void)
Definition: varformat.c:50
static void test_GetAltMonthNames(void)
Definition: varformat.c:592
static const FMTDATERES VarFormat_date_results[]
Definition: varformat.c:148
#define VNUMFMT(vt, v)
Definition: varformat.c:198
#define FMT_NUMBER(vt, val)
Definition: varformat.c:40
static const FMTDATERES VarFormat_namedtime_results[]
Definition: varformat.c:191
struct tagFMTDATERES FMTDATERES
static void test_VarFormat(void)
Definition: varformat.c:210
static void test_VarFormatCurrency(void)
Definition: varformat.c:628
#define LOCALE_USER_DEFAULT
#define SORT_DEFAULT
#define MAKELCID(lgid, srtid)
HRESULT WINAPI GetAltMonthNames(LCID lcid, LPOLESTR **str)
Definition: oleaut.c:1151
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:238
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:271
BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
Definition: oleaut.c:339
#define V_UI1(A)
Definition: oleauto.h:266
#define V_I8(A)
Definition: oleauto.h:249
#define V_BOOL(A)
Definition: oleauto.h:224
#define V_INT(A)
Definition: oleauto.h:251
#define V_BSTRREF(A)
Definition: oleauto.h:227
#define VARCMP_EQ
Definition: oleauto.h:658
#define V_BOOLREF(A)
Definition: oleauto.h:225
#define V_UI2(A)
Definition: oleauto.h:268
#define V_I1(A)
Definition: oleauto.h:243
#define V_VT(A)
Definition: oleauto.h:211
#define V_BSTR(A)
Definition: oleauto.h:226
#define V_I4(A)
Definition: oleauto.h:247
#define V_R4(A)
Definition: oleauto.h:260
#define V_UINT(A)
Definition: oleauto.h:264
#define V_CY(A)
Definition: oleauto.h:229
#define V_UI4(A)
Definition: oleauto.h:270
#define V_R8(A)
Definition: oleauto.h:262
#define V_DATE(A)
Definition: oleauto.h:231
#define V_UI8(A)
Definition: oleauto.h:272
#define V_I2(A)
Definition: oleauto.h:245
short WCHAR
Definition: pedump.c:58
const WCHAR * str
#define MAKELANGID(p, s)
Definition: nls.h:15
#define LANG_POLISH
Definition: nls.h:107
#define LANG_GERMAN
Definition: nls.h:62
#define SUBLANG_GERMAN
Definition: nls.h:251
#define LANG_ENGLISH
Definition: nls.h:52
#define LANGIDFROMLCID(l)
Definition: nls.h:18
#define SUBLANG_DEFAULT
Definition: nls.h:168
#define LANG_RUSSIAN
Definition: nls.h:113
#define LANG_ARABIC
Definition: nls.h:29
DWORD LCID
Definition: nls.h:13
#define PRIMARYLANGID(l)
Definition: nls.h:16
#define SUBLANG_ARABIC_EGYPT
Definition: nls.h:180
#define SUBLANG_ENGLISH_US
Definition: nls.h:222
XML_HIDDEN void xmlParserErrors const char const xmlChar const xmlChar * str2
Definition: parser.h:35
static int fd
Definition: io.c:51
static const char *static const char const char DWORD void DWORD *static const char const char DWORD void DWORD *static const char DWORD DWORD void * buff
Definition: shcore.c:41
Definition: dsound.c:943
LPCSTR fmt
Definition: varformat.c:144
LPCSTR res
Definition: varformat.c:145
LPCSTR one_res
Definition: varformat.c:115
LPCSTR zero_res
Definition: varformat.c:116
LPCSTR fmt
Definition: varformat.c:114
const char * LPCSTR
Definition: typedefs.h:52
uint16_t * LPWSTR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:648
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define DISP_E_TYPEMISMATCH
Definition: winerror.h:3617
#define LOCALE_SDECIMAL
Definition: winnls.h:52
#define LOCALE_SDAYNAME1
Definition: winnls.h:87
#define LOCALE_IDIGITS
Definition: winnls.h:55
#define LOCALE_STIMEFORMAT
Definition: winnls.h:72
#define LOCALE_SABBREVDAYNAME1
Definition: winnls.h:94
#define LOCALE_IFIRSTDAYOFWEEK
Definition: winnls.h:85
unsigned char BYTE
Definition: xxhash.c:193