ReactOS 0.4.15-dev-8419-g7f0e8a3
varformat.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include <math.h>
#include <float.h>
#include "windef.h"
#include "winbase.h"
#include "winsock2.h"
#include "wine/test.h"
#include "winuser.h"
#include "wingdi.h"
#include "winnls.h"
#include "winerror.h"
#include "winnt.h"
#include "wtypes.h"
#include "oleauto.h"
Include dependency graph for varformat.c:

Go to the source code of this file.

Classes

struct  tagFMTRES
 
struct  tagFMTDATERES
 

Macros

#define CHECKPTR(func)
 
#define FMT_NUMBER(vt, val)
 
#define SIGNED_VTBITS   (VTBIT_I1|VTBIT_I2|VTBIT_I4|VTBIT_I8|VTBIT_R4|VTBIT_R8)
 
#define VARFMT(vt, v, val, fmt, ret, str)
 
#define VNUMFMT(vt, v)
 
#define VARWDN(iWeekday, fAbbrev, iFirstDay, dwFlags, ret, buff, out, freeOut)
 
#define VARWDN_F(iWeekday, fAbbrev, iFirstDay, dwFlags, ret)    VARWDN(iWeekday, fAbbrev, iFirstDay, dwFlags, ret, buff, out, 1)
 
#define VARWDN_O(iWeekday, fAbbrev, iFirstDay, dwFlags)    VARWDN(iWeekday, fAbbrev, iFirstDay, dwFlags, S_OK, buff, out, 0)
 

Typedefs

typedef struct tagFMTRES FMTRES
 
typedef struct tagFMTDATERES FMTDATERES
 

Functions

static HRESULT (WINAPI *pVarBstrCmp)(BSTR
 
static int strcmpW (const WCHAR *str1, const WCHAR *str2)
 
static void test_VarFormatNumber (void)
 
static void test_VarFormat (void)
 
static void test_VarWeekdayName (void)
 
static void test_VarFormatFromTokens (void)
 
static void test_GetAltMonthNames (void)
 
 START_TEST (varformat)
 

Variables

static HMODULE hOleaut32
 
static BSTR
 
static LCID
 
static ULONG
 
static int
 
static BSTR *static LPOLESTR
 
static BSTR *static BSTR *static BSTR *static BOOL has_i8
 
static const charszVarFmtFail = "VT %d|0x%04x Format %s: expected 0x%08x, '%s', got 0x%08x, '%s'\n"
 
static const FMTRES VarFormat_results []
 
static const FMTDATERES VarFormat_date_results []
 
static const FMTDATERES VarFormat_namedtime_results []
 
static const charszVarWdnFail
 

Macro Definition Documentation

◆ CHECKPTR

#define CHECKPTR (   func)
Value:
if (!p##func) { win_skip("function " # func " not available, not testing it\n"); return; }
#define GetProcAddress(x, y)
Definition: compat.h:753
GLenum func
Definition: glext.h:6028
GLfloat GLfloat p
Definition: glext.h:8902
static HMODULE hOleaut32
Definition: varformat.c:40
#define win_skip
Definition: test.h:163

Definition at line 51 of file varformat.c.

◆ FMT_NUMBER

#define FMT_NUMBER (   vt,
  val 
)
Value:
VariantInit(&v); V_VT(&v) = vt; val(&v) = 1; \
hres = pVarFormatNumber(&v,2,0,0,0,0,&str); \
ok(hres == S_OK, "VarFormatNumber (vt %d): returned %8x\n", vt, hres); \
if (hres == S_OK) { \
ok(str && strcmpW(str,szResult1) == 0, \
"VarFormatNumber (vt %d): string different\n", vt); \
SysFreeString(str); \
}
static REFPROPVARIANT PROPVAR_CHANGE_FLAGS VARTYPE vt
Definition: suminfo.c:86
const GLdouble * v
Definition: gl.h:2040
GLuint GLfloat * val
Definition: glext.h:7180
#define S_OK
Definition: intsafe.h:52
HRESULT hres
Definition: protocol.c:465
#define V_VT(A)
Definition: oleauto.h:211
#define strcmpW(s1, s2)
Definition: unicode.h:44
const WCHAR * str
void WINAPI VariantInit(VARIANTARG *pVarg)
Definition: variant.c:568

Definition at line 60 of file varformat.c.

◆ SIGNED_VTBITS

Definition at line 124 of file varformat.c.

◆ VARFMT

#define VARFMT (   vt,
  v,
  val,
  fmt,
  ret,
  str 
)
Value:
do { \
out = NULL; \
V_VT(&in) = (vt); v(&in) = val; \
if (fmt) MultiByteToWideChar(CP_ACP, 0, fmt, -1, buffW, ARRAY_SIZE(buffW)); \
hres = pVarFormat(&in,fmt ? buffW : NULL,fd,fw,flags,&out); \
if (SUCCEEDED(hres)) WideCharToMultiByte(CP_ACP, 0, out, -1, buff, sizeof(buff),0,0); \
else buff[0] = '\0'; \
ok(hres == ret && (FAILED(ret) || !strcmp(buff, str)), \
SysFreeString(out); \
} while(0)
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ARRAY_SIZE(A)
Definition: main.h:33
#define NULL
Definition: types.h:112
#define CP_ACP
Definition: compat.h:109
#define WideCharToMultiByte
Definition: compat.h:111
#define MultiByteToWideChar
Definition: compat.h:110
@ VT_TYPEMASK
Definition: compat.h:2346
static unsigned char buff[32768]
Definition: fatten.c:17
GLuint in
Definition: glext.h:9616
GLbitfield flags
Definition: glext.h:7161
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
static const char * szVarFmtFail
Definition: varformat.c:126
static FILE * out
Definition: regtests2xml.c:44
static int fd
Definition: io.c:51
Definition: dsound.c:943
int ret

Definition at line 127 of file varformat.c.

◆ VARWDN

#define VARWDN (   iWeekday,
  fAbbrev,
  iFirstDay,
  dwFlags,
  ret,
  buff,
  out,
  freeOut 
)
Value:
do { \
hres = pVarWeekdayName(iWeekday, fAbbrev, iFirstDay, dwFlags, &out); \
if (SUCCEEDED(hres)) { \
WideCharToMultiByte(CP_ACP, 0, out, -1, buff, sizeof(buff), 0, 0); \
if (freeOut) SysFreeString(out); \
} else { \
buff[0] = '\0'; \
} \
ok(hres == ret, \
iWeekday, fAbbrev, iFirstDay, dwFlags, &out, hres, ret \
); \
} while(0)
static const char * szVarWdnFail
Definition: varformat.c:450
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:271
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176

Definition at line 452 of file varformat.c.

◆ VARWDN_F

#define VARWDN_F (   iWeekday,
  fAbbrev,
  iFirstDay,
  dwFlags,
  ret 
)     VARWDN(iWeekday, fAbbrev, iFirstDay, dwFlags, ret, buff, out, 1)

Definition at line 467 of file varformat.c.

◆ VARWDN_O

#define VARWDN_O (   iWeekday,
  fAbbrev,
  iFirstDay,
  dwFlags 
)     VARWDN(iWeekday, fAbbrev, iFirstDay, dwFlags, S_OK, buff, out, 0)

Definition at line 470 of file varformat.c.

◆ VNUMFMT

#define VNUMFMT (   vt,
  v 
)
Value:
for (i = 0; i < ARRAY_SIZE(VarFormat_results); i++) \
{ \
VARFMT(vt,v,1,VarFormat_results[i].fmt,S_OK,VarFormat_results[i].one_res); \
VARFMT(vt,v,0,VarFormat_results[i].fmt,S_OK,VarFormat_results[i].zero_res); \
} \
if ((1 << vt) & SIGNED_VTBITS) \
{ \
VARFMT(vt,v,-1,"\"pos\";\"neg\"",S_OK,"neg"); \
VARFMT(vt,v,-1,"\"pos\";\"neg\";\"zero\"",S_OK,"neg"); \
}
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
static const FMTRES VarFormat_results[]
Definition: varformat.c:147
#define SIGNED_VTBITS
Definition: varformat.c:124

Definition at line 226 of file varformat.c.

Typedef Documentation

◆ FMTDATERES

◆ FMTRES

Function Documentation

◆ HRESULT()

static HRESULT ( WINAPI pVarBstrCmp)
static

◆ START_TEST()

START_TEST ( varformat  )

Definition at line 679 of file varformat.c.

680{
681 hOleaut32 = GetModuleHandleA("oleaut32.dll");
682
683 has_i8 = GetProcAddress(hOleaut32, "VarI8FromI1") != NULL;
684
690}
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
static void test_VarFormatFromTokens(void)
Definition: varformat.c:561
static BSTR *static BSTR *static BSTR *static BOOL has_i8
Definition: varformat.c:48
static void test_VarWeekdayName(void)
Definition: varformat.c:473
static void test_VarFormatNumber(void)
Definition: varformat.c:70
static void test_GetAltMonthNames(void)
Definition: varformat.c:643
static void test_VarFormat(void)
Definition: varformat.c:238

◆ strcmpW()

static int strcmpW ( const WCHAR str1,
const WCHAR str2 
)
inlinestatic

Definition at line 54 of file varformat.c.

55{
56 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
57 return *str1 - *str2;
58}

◆ test_GetAltMonthNames()

static void test_GetAltMonthNames ( void  )
static

Definition at line 643 of file varformat.c.

644{
645 LPOLESTR *str, *str2;
646 HRESULT hr;
647
648 str = (void *)0xdeadbeef;
649 hr = GetAltMonthNames(0, &str);
650 ok(hr == S_OK, "Unexpected return value %08x\n", hr);
651 ok(str == NULL, "Got %p\n", str);
652
653 str = (void *)0xdeadbeef;
655 ok(hr == S_OK, "Unexpected return value %08x\n", hr);
656 ok(str == NULL, "Got %p\n", str);
657
658 str = NULL;
660 ok(hr == S_OK, "Unexpected return value %08x\n", hr);
661 ok(str != NULL, "Got %p\n", str);
662
663 str2 = NULL;
665 ok(hr == S_OK, "Unexpected return value %08x\n", hr);
666 ok(str2 == str, "Got %p\n", str2);
667
668 str = NULL;
670 ok(hr == S_OK, "Unexpected return value %08x\n", hr);
671 ok(str != NULL, "Got %p\n", str);
672
673 str = NULL;
675 ok(hr == S_OK, "Unexpected return value %08x\n", hr);
676 ok(str != NULL, "Got %p\n", str);
677}
#define ok(value,...)
Definition: atltest.h:57
static BSTR *static LPOLESTR
Definition: varformat.c:44
#define SORT_DEFAULT
#define MAKELCID(lgid, srtid)
HRESULT WINAPI GetAltMonthNames(LCID lcid, LPOLESTR **str)
Definition: oleaut.c:1151
#define MAKELANGID(p, s)
Definition: nls.h:15
#define LANG_POLISH
Definition: nls.h:107
#define LANG_ENGLISH
Definition: nls.h:52
#define SUBLANG_DEFAULT
Definition: nls.h:168
#define LANG_RUSSIAN
Definition: nls.h:113
#define LANG_ARABIC
Definition: nls.h:29
#define SUBLANG_ARABIC_EGYPT
Definition: nls.h:180
#define SUBLANG_ENGLISH_US
Definition: nls.h:222
HRESULT hr
Definition: shlfolder.c:183

Referenced by START_TEST().

◆ test_VarFormat()

static void test_VarFormat ( void  )
static

Definition at line 238 of file varformat.c.

239{
240 static const WCHAR szTesting[] = { 't','e','s','t','i','n','g','\0' };
241 static const WCHAR szNum[] = { '3','9','6','9','7','.','1','1','\0' };
242 size_t i;
243 WCHAR buffW[256];
244 char buff[256];
245 VARIANT in;
246 VARIANT_BOOL bTrue = VARIANT_TRUE, bFalse = VARIANT_FALSE;
247 int fd = 0, fw = 0;
248 ULONG flags = 0;
249 BSTR bstrin, out = NULL;
251
253
255 {
256 skip("Skipping VarFormat tests for non English language\n");
257 return;
258 }
260 if (buff[0] != '.' || buff[1])
261 {
262 skip("Skipping VarFormat tests as decimal separator is '%s'\n", buff);
263 return;
264 }
266 if (buff[0] != '2' || buff[1])
267 {
268 skip("Skipping VarFormat tests as decimal places is '%s'\n", buff);
269 return;
270 }
271
272 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"True/False",S_OK,"True");
273 VARFMT(VT_BOOL,V_BOOL,VARIANT_FALSE,"True/False",S_OK,"False");
274
278 if (has_i8)
279 {
281 }
286 if (has_i8)
287 {
289 }
293
294 /* Reference types are dereferenced */
295 VARFMT(VT_BOOL|VT_BYREF,V_BOOLREF,&bTrue,"True/False",S_OK,"True");
296 VARFMT(VT_BOOL|VT_BYREF,V_BOOLREF,&bFalse,"True/False",S_OK,"False");
297
298 /* Dates */
299 for (i = 0; i < ARRAY_SIZE(VarFormat_date_results); i++)
300 {
301 if (i < 7)
302 fd = i + 1; /* Test first day */
303 else
304 fd = 0;
308 }
309
310 /* Named time formats */
312 if (strcmp(buff, "h:mm:ss tt"))
313 {
314 skip("Skipping named time tests as time format is '%s'\n", buff);
315 }
316 else
317 {
319 {
320 fd = 0;
324 }
325 }
326
327 /* Strings */
328 bstrin = SysAllocString(szTesting);
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,"&",S_OK,"testing");
332 VARFMT(VT_BSTR,V_BSTR,bstrin,"\\x@\\x@",S_OK,"xtxesting");
333 VARFMT(VT_BSTR,V_BSTR,bstrin,"\\x&\\x&",S_OK,"xtxesting");
334 VARFMT(VT_BSTR,V_BSTR,bstrin,"@\\x",S_OK,"txesting");
335 VARFMT(VT_BSTR,V_BSTR,bstrin,"@@@@@@@@",S_OK," testing");
336 VARFMT(VT_BSTR,V_BSTR,bstrin,"@\\x@@@@@@@",S_OK," xtesting");
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 VARFMT(VT_BSTR,V_BSTR,bstrin,"<&>&",S_OK,"testing");
343 SysFreeString(bstrin);
344 bstrin = SysAllocString(szNum);
345 todo_wine VARFMT(VT_BSTR,V_BSTR,bstrin,"hh:mm",S_OK,"02:38");
346 todo_wine VARFMT(VT_BSTR,V_BSTR,bstrin,"mm-dd-yy",S_OK,"09-06-08");
347 SysFreeString(bstrin);
348 /* Numeric values are converted to strings then output */
349 VARFMT(VT_I1,V_I1,1,"<&>&",S_OK,"1");
350
351 /* Number formats */
352 VARFMT(VT_I4,V_I4,1,"#00000000",S_OK,"00000001");
353 VARFMT(VT_I4,V_I4,1,"000###",S_OK,"000001");
354 VARFMT(VT_I4,V_I4,1,"#00##00#0",S_OK,"00000001");
355 VARFMT(VT_I4,V_I4,1,"1#####0000",S_OK,"10001");
356 VARFMT(VT_I4,V_I4,1,"##abcdefghijklmnopqrstuvwxyz",S_OK,"1abcdefghijklmnopqrstuvwxyz");
357 VARFMT(VT_I4,V_I4,100000,"#,###,###,###",S_OK,"100,000");
358 VARFMT(VT_I4,V_I4,1,"0,000,000,000",S_OK,"0,000,000,001");
359 VARFMT(VT_I4,V_I4,123456789,"#,#.#",S_OK,"123,456,789.");
360 VARFMT(VT_I4,V_I4,123456789,"###, ###, ###",S_OK,"123, 456, 789");
361 VARFMT(VT_I4,V_I4,1,"#;-#",S_OK,"1");
362 VARFMT(VT_I4,V_I4,-1,"#;-#",S_OK,"-1");
363 VARFMT(VT_R8,V_R8,1.23456789,"0#.0#0#0#0#0",S_OK,"01.234567890");
364 VARFMT(VT_R8,V_R8,1.2,"0#.0#0#0#0#0",S_OK,"01.200000000");
365 VARFMT(VT_R8,V_R8,9.87654321,"#0.#0#0#0#0#",S_OK,"9.87654321");
366 VARFMT(VT_R8,V_R8,9.8,"#0.#0#0#0#0#",S_OK,"9.80000000");
367 VARFMT(VT_R8,V_R8,0.00000008,"#0.#0#0#0#0#0",S_OK,"0.0000000800");
368 VARFMT(VT_R8,V_R8,0.00010705,"#0.##########",S_OK,"0.00010705");
369 VARFMT(VT_I4,V_I4,17,"#0",S_OK,"17");
370 VARFMT(VT_I4,V_I4,4711,"#0",S_OK,"4711");
371 VARFMT(VT_I4,V_I4,17,"#00",S_OK,"17");
372 VARFMT(VT_I4,V_I4,100,"0##",S_OK,"100");
373 VARFMT(VT_I4,V_I4,17,"#000",S_OK,"017");
374 VARFMT(VT_I4,V_I4,17,"#0.00",S_OK,"17.00");
375 VARFMT(VT_I4,V_I4,17,"#0000.00",S_OK,"0017.00");
376 VARFMT(VT_I4,V_I4,17,"#.00",S_OK,"17.00");
377 VARFMT(VT_R8,V_R8,1.7,"#.00",S_OK,"1.70");
378 VARFMT(VT_R8,V_R8,.17,"#.00",S_OK,".17");
379 VARFMT(VT_I4,V_I4,17,"#3",S_OK,"173");
380 VARFMT(VT_I4,V_I4,17,"#33",S_OK,"1733");
381 VARFMT(VT_I4,V_I4,17,"#3.33",S_OK,"173.33");
382 VARFMT(VT_I4,V_I4,17,"#3333.33",S_OK,"173333.33");
383 VARFMT(VT_I4,V_I4,17,"#.33",S_OK,"17.33");
384 VARFMT(VT_R8,V_R8,.17,"#.33",S_OK,".33");
385 VARFMT(VT_R8,V_R8,1.7,"0.0000E-000",S_OK,"1.7000E000");
386 VARFMT(VT_R8,V_R8,1.7,"0.0000e-1",S_OK,"1.7000e01");
387 VARFMT(VT_R8,V_R8,86.936849,"#0.000000000000e-000",S_OK,"86.936849000000e000");
388 VARFMT(VT_R8,V_R8,1.7,"#0",S_OK,"2");
389 VARFMT(VT_R8,V_R8,1.7,"#.33",S_OK,"2.33");
390 VARFMT(VT_R8,V_R8,1.7,"#3",S_OK,"23");
391 VARFMT(VT_R8,V_R8,1.73245,"0.0000E+000",S_OK,"1.7325E+000");
392 VARFMT(VT_R8,V_R8,9.9999999,"#0.000000",S_OK,"10.000000");
393 VARFMT(VT_R8,V_R8,1.7,"0.0000e+0#",S_OK,"1.7000e+0");
394 VARFMT(VT_R8,V_R8,100.0001e+0,"0.0000E+0",S_OK,"1.0000E+2");
395 VARFMT(VT_R8,V_R8,1000001,"0.0000e+1",S_OK,"1.0000e+61");
396 VARFMT(VT_R8,V_R8,100.0001e+25,"0.0000e+0",S_OK,"1.0000e+27");
397 VARFMT(VT_R8,V_R8,450.0001e+43,"#000.0000e+0",S_OK,"4500.0010e+42");
398 VARFMT(VT_R8,V_R8,0.0001e-11,"##00.0000e-0",S_OK,"1000.0000e-18");
399 VARFMT(VT_R8,V_R8,0.0317e-11,"0000.0000e-0",S_OK,"3170.0000e-16");
400 VARFMT(VT_R8,V_R8,0.0021e-11,"00##.0000e-0",S_OK,"2100.0000e-17");
401 VARFMT(VT_R8,V_R8,1.0001e-27,"##00.0000e-0",S_OK,"1000.1000e-30");
402 VARFMT(VT_R8,V_R8,47.11,".0000E+0",S_OK,".4711E+2");
403 VARFMT(VT_R8,V_R8,3.0401e-13,"#####.####e-0%",S_OK,"30401.e-15%");
404 VARFMT(VT_R8,V_R8,1.57,"0.00",S_OK,"1.57");
405 VARFMT(VT_R8,V_R8,-1.57,"0.00",S_OK,"-1.57");
406 VARFMT(VT_R8,V_R8,-1.57,"#.##",S_OK,"-1.57");
407 VARFMT(VT_R8,V_R8,-0.1,".#",S_OK,"-.1");
408 VARFMT(VT_R8,V_R8,0.099,"#.#",S_OK,".1");
409 VARFMT(VT_R8,V_R8,0.0999,"#.##",S_OK,".1");
410 VARFMT(VT_R8,V_R8,0.099,"#.##",S_OK,".1");
411 VARFMT(VT_R8,V_R8,0.0099,"#.##",S_OK,".01");
412 VARFMT(VT_R8,V_R8,0.0049,"#.##",S_OK,".");
413 VARFMT(VT_R8,V_R8,0.0094,"#.##",S_OK,".01");
414 VARFMT(VT_R8,V_R8,0.00099,"#.##",S_OK,".");
415 VARFMT(VT_R8,V_R8,0.0995,"#.##",S_OK,".1");
416 VARFMT(VT_R8,V_R8,8.0995,"#.##",S_OK,"8.1");
417 VARFMT(VT_R8,V_R8,0.0994,"#.##",S_OK,".1");
418 VARFMT(VT_R8,V_R8,1.00,"#,##0.00",S_OK,"1.00");
419 VARFMT(VT_R8,V_R8,0.0995,"#.###",S_OK,".1");
420
421
422 /* 'out' is not cleared */
423 out = (BSTR)0x1;
424 hres = pVarFormat(&in,NULL,fd,fw,flags,&out); /* Would crash if out is cleared */
425 ok(hres == S_OK, "got %08x\n", hres);
427 out = NULL;
428
429 /* VT_NULL */
430 V_VT(&in) = VT_NULL;
431 hres = pVarFormat(&in,NULL,fd,fw,0,&out);
432 ok(hres == S_OK, "VarFormat failed with 0x%08x\n", hres);
433 ok(out == NULL, "expected NULL formatted string\n");
434
435 /* Invalid args */
436 hres = pVarFormat(&in,NULL,fd,fw,flags,NULL);
437 ok(hres == E_INVALIDARG, "Null out: expected E_INVALIDARG, got 0x%08x\n", hres);
438 hres = pVarFormat(NULL,NULL,fd,fw,flags,&out);
439 ok(hres == E_INVALIDARG, "Null in: expected E_INVALIDARG, got 0x%08x\n", hres);
440 fd = -1;
441 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
442 fd = 8;
443 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
444 fd = 0; fw = -1;
445 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
446 fw = 4;
447 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
448}
#define skip(...)
Definition: atltest.h:64
#define E_INVALIDARG
Definition: ddrawi.h:101
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_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
INT WINAPI GetLocaleInfoA(LCID lcid, LCTYPE lctype, LPSTR buffer, INT len)
Definition: locale.c:1599
LCID WINAPI GetUserDefaultLCID(void)
Definition: locale.c:1210
HRESULT WINAPI VarFormat(LPVARIANT pVarIn, LPOLESTR lpszFormat, int nFirstDay, int nFirstWeek, ULONG dwFlags, BSTR *pbstrOut)
Definition: varformat.c:2138
GLuint res
Definition: glext.h:9613
#define todo_wine
Definition: custom.c:79
#define VARFMT(vt, v, val, fmt, ret, str)
Definition: varformat.c:127
static BSTR
Definition: varformat.c:42
static const FMTDATERES VarFormat_date_results[]
Definition: varformat.c:176
#define VNUMFMT(vt, v)
Definition: varformat.c:226
static const FMTDATERES VarFormat_namedtime_results[]
Definition: varformat.c:219
#define CHECKPTR(func)
Definition: varformat.c:51
#define LOCALE_USER_DEFAULT
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:238
#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_BOOLREF(A)
Definition: oleauto.h:225
#define V_UI2(A)
Definition: oleauto.h:268
#define V_I1(A)
Definition: oleauto.h:243
#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_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
#define LANGIDFROMLCID(l)
Definition: nls.h:18
#define PRIMARYLANGID(l)
Definition: nls.h:16
uint32_t ULONG
Definition: typedefs.h:59
#define V_INT(x)
Definition: webchild.h:78
#define LOCALE_SDECIMAL
Definition: winnls.h:42
#define LOCALE_IDIGITS
Definition: winnls.h:45
#define LOCALE_STIMEFORMAT
Definition: winnls.h:62
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ test_VarFormatFromTokens()

static void test_VarFormatFromTokens ( void  )
static

Definition at line 561 of file varformat.c.

562{
563 static WCHAR number_fmt[] = {'#','#','#',',','#','#','0','.','0','0',0};
564 static const WCHAR number[] = {'6',',','9','0',0};
565 static const WCHAR number_us[] = {'6','9','0','.','0','0',0};
566
567 static WCHAR date_fmt[] = {'d','d','-','m','m',0};
568 static const WCHAR date[] = {'1','2','-','1','1',0};
569 static const WCHAR date_us[] = {'1','1','-','1','2',0};
570
571 static WCHAR string_fmt[] = {'@',0};
572 static const WCHAR string_de[] = {'1',',','5',0};
573 static const WCHAR string_us[] = {'1','.','5',0};
574
575 BYTE buff[256];
576 LCID lcid;
577 VARIANT var;
578 BSTR bstr;
580
581 V_VT(&var) = VT_BSTR;
583
585 hres = VarTokenizeFormatString(number_fmt, buff, sizeof(buff), 1, 1, lcid, NULL);
586 ok(hres == S_OK, "VarTokenizeFormatString failed: %x\n", hres);
587 hres = VarFormatFromTokens(&var, number_fmt, buff, 0, &bstr, lcid);
588 ok(hres == S_OK, "VarFormatFromTokens failed: %x\n", hres);
589 ok(!strcmpW(bstr, number_us), "incorrectly formatted number: %s\n", wine_dbgstr_w(bstr));
590 SysFreeString(bstr);
591
593 hres = VarTokenizeFormatString(number_fmt, buff, sizeof(buff), 1, 1, lcid, NULL);
594 ok(hres == S_OK, "VarTokenizeFormatString failed: %x\n", hres);
595 hres = VarFormatFromTokens(&var, number_fmt, buff, 0, &bstr, lcid);
596 ok(hres == S_OK, "VarFormatFromTokens failed: %x\n", hres);
597 ok(!strcmpW(bstr, number), "incorrectly formatted number: %s\n", wine_dbgstr_w(bstr));
598 SysFreeString(bstr);
599
601
602 V_VT(&var) = VT_BSTR;
604
606 hres = VarTokenizeFormatString(date_fmt, buff, sizeof(buff), 1, 1, lcid, NULL);
607 ok(hres == S_OK, "VarTokenizeFormatString failed: %x\n", hres);
608 hres = VarFormatFromTokens(&var, date_fmt, buff, 0, &bstr, lcid);
609 ok(hres == S_OK, "VarFormatFromTokens failed: %x\n", hres);
610 ok(!strcmpW(bstr, date_us), "incorrectly formatted date: %s\n", wine_dbgstr_w(bstr));
611 SysFreeString(bstr);
612
614 hres = VarTokenizeFormatString(date_fmt, buff, sizeof(buff), 1, 1, lcid, NULL);
615 ok(hres == S_OK, "VarTokenizeFormatString failed: %x\n", hres);
616 hres = VarFormatFromTokens(&var, date_fmt, buff, 0, &bstr, lcid);
617 ok(hres == S_OK, "VarFormatFromTokens failed: %x\n", hres);
618 ok(!strcmpW(bstr, date), "incorrectly formatted date: %s\n", wine_dbgstr_w(bstr));
619 SysFreeString(bstr);
620
622
623 V_VT(&var) = VT_R4;
624 V_R4(&var) = 1.5;
625
627 hres = VarTokenizeFormatString(string_fmt, buff, sizeof(buff), 1, 1, lcid, NULL);
628 ok(hres == S_OK, "VarTokenizeFormatString failed: %x\n", hres);
629 hres = VarFormatFromTokens(&var, string_fmt, buff, 0, &bstr, lcid);
630 ok(hres == S_OK, "VarFormatFromTokens failed: %x\n", hres);
631 ok(!strcmpW(bstr, string_us), "incorrectly formatted string: %s\n", wine_dbgstr_w(bstr));
632 SysFreeString(bstr);
633
635 hres = VarTokenizeFormatString(string_fmt, buff, sizeof(buff), 1, 1, lcid, NULL);
636 ok(hres == S_OK, "VarTokenizeFormatString failed: %x\n", hres);
637 hres = VarFormatFromTokens(&var, string_fmt, buff, 0, &bstr, lcid);
638 ok(hres == S_OK, "VarFormatFromTokens failed: %x\n", hres);
639 ok(!strcmpW(bstr, string_de), "incorrectly formatted string: %s\n", wine_dbgstr_w(bstr));
640 SysFreeString(bstr);
641}
HRESULT WINAPI VarTokenizeFormatString(LPOLESTR lpszFormat, LPBYTE rgbTok, int cbTok, int nFirstDay, int nFirstWeek, LCID lcid, int *pcbActual)
Definition: varformat.c:495
HRESULT WINAPI VarFormatFromTokens(LPVARIANT pVarIn, LPOLESTR lpszFormat, LPBYTE rgbTok, ULONG dwFlags, BSTR *pbstrOut, LCID lcid)
Definition: varformat.c:2050
#define wine_dbgstr_w
Definition: kernel32.h:34
__u16 date
Definition: mkdosfs.c:8
const char * var
Definition: shader.c:5666
static unsigned int number
Definition: dsound.c:1479
#define LANG_GERMAN
Definition: nls.h:62
#define SUBLANG_GERMAN
Definition: nls.h:251
DWORD LCID
Definition: nls.h:13
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:648
unsigned char BYTE
Definition: xxhash.c:193

Referenced by START_TEST().

◆ test_VarFormatNumber()

static void test_VarFormatNumber ( void  )
static

Definition at line 70 of file varformat.c.

71{
72 static const WCHAR szSrc1[] = { '1','\0' };
73 static const WCHAR szResult1[] = { '1','.','0','0','\0' };
74 static const WCHAR szSrc2[] = { '-','1','\0' };
75 static const WCHAR szResult2[] = { '(','1','.','0','0',')','\0' };
76 char buff[8];
78 VARIANT v;
79 BSTR str = NULL;
80
82
84 if (buff[0] != '.' || buff[1])
85 {
86 skip("Skipping VarFormatNumber tests as decimal separator is '%s'\n", buff);
87 return;
88 }
89
96 if (has_i8)
97 {
100 }
104
105 V_VT(&v) = VT_BSTR;
106 V_BSTR(&v) = SysAllocString(szSrc1);
107
108 hres = pVarFormatNumber(&v,2,0,0,0,0,&str);
109 ok(hres == S_OK, "VarFormatNumber (bstr): returned %8x\n", hres);
110 if (hres == S_OK)
111 ok(str && strcmpW(str, szResult1) == 0, "VarFormatNumber (bstr): string different\n");
114
115 V_BSTR(&v) = SysAllocString(szSrc2);
116 hres = pVarFormatNumber(&v,2,0,-1,0,0,&str);
117 ok(hres == S_OK, "VarFormatNumber (bstr): returned %8x\n", hres);
118 if (hres == S_OK)
119 ok(str && strcmpW(str, szResult2) == 0, "VarFormatNumber (-bstr): string different\n");
122}
HRESULT WINAPI VarFormatNumber(LPVARIANT pVarIn, INT nDigits, INT nLeading, INT nParens, INT nGrouping, ULONG dwFlags, BSTR *pbstrOut)
Definition: varformat.c:2241
#define FMT_NUMBER(vt, val)
Definition: varformat.c:60

Referenced by START_TEST().

◆ test_VarWeekdayName()

static void test_VarWeekdayName ( void  )
static

Definition at line 473 of file varformat.c.

474{
475 char buff[256];
476 BSTR out = NULL;
478 int iWeekday, fAbbrev, iFirstDay;
479 BSTR dayNames[7][2]; /* Monday-Sunday, full/abbr */
480 DWORD defaultFirstDay;
481 int firstDay;
482 int day;
483 int size;
484 DWORD localeValue;
485
487
488 SetLastError(0xdeadbeef);
491 {
492 win_skip("GetLocaleInfoW is not implemented\n");
493 return;
494 }
495
496 /* Initialize days' names */
497 for (day = 0; day <= 6; ++day)
498 {
499 for (fAbbrev = 0; fAbbrev <= 1; ++fAbbrev)
500 {
501 localeValue = fAbbrev ? LOCALE_SABBREVDAYNAME1 : LOCALE_SDAYNAME1;
502 localeValue += day;
503 size = GetLocaleInfoW(LOCALE_USER_DEFAULT, localeValue, NULL, 0);
504 dayNames[day][fAbbrev] = SysAllocStringLen(NULL, size - 1);
506 dayNames[day][fAbbrev], size);
507 }
508 }
509
510 /* Get the user's first day of week. 0=Monday, .. */
512 LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK | LOCALE_RETURN_NUMBER,
513 (LPWSTR)&defaultFirstDay, sizeof(defaultFirstDay) / sizeof(WCHAR));
514
515 /* Check invalid arguments */
516 VARWDN_F(0, 0, 4, 0, E_INVALIDARG);
517 VARWDN_F(8, 0, 4, 0, E_INVALIDARG);
518 VARWDN_F(4, 0, -1, 0, E_INVALIDARG);
519 VARWDN_F(4, 0, 8, 0, E_INVALIDARG);
520
521 hres = pVarWeekdayName(1, 0, 0, 0, NULL);
523 "Null pointer: expected E_INVALIDARG, got 0x%08x\n", hres);
524
525 /* Check all combinations */
526 pVarBstrCmp = (void*)GetProcAddress(hOleaut32, "VarBstrCmp");
527 if (pVarBstrCmp)
528 for (iWeekday = 1; iWeekday <= 7; ++iWeekday)
529 {
530 for (fAbbrev = 0; fAbbrev <= 1; ++fAbbrev)
531 {
532 /* 0 = Default, 1 = Sunday, 2 = Monday, .. */
533 for (iFirstDay = 0; iFirstDay <= 7; ++iFirstDay)
534 {
535 VARWDN_O(iWeekday, fAbbrev, iFirstDay, 0);
536 if (iFirstDay == 0)
537 firstDay = defaultFirstDay;
538 else
539 /* Translate from 0=Sunday to 0=Monday in the modulo 7 space */
540 firstDay = iFirstDay - 2;
541 day = (7 + iWeekday - 1 + firstDay) % 7;
542 ok(VARCMP_EQ == pVarBstrCmp(out, dayNames[day][fAbbrev],
544 "VarWeekdayName(%d,%d,%d): got wrong dayname: '%s'\n",
545 iWeekday, fAbbrev, iFirstDay, buff);
547 }
548 }
549 }
550
551 /* Cleanup */
552 for (day = 0; day <= 6; ++day)
553 {
554 for (fAbbrev = 0; fAbbrev <= 1; ++fAbbrev)
555 {
556 SysFreeString(dayNames[day][fAbbrev]);
557 }
558 }
559}
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define SetLastError(x)
Definition: compat.h:752
static DOUBLE day(DOUBLE time)
Definition: date.c:117
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: locale.c:1665
HRESULT WINAPI VarWeekdayName(INT iWeekday, INT fAbbrev, INT iFirstDay, ULONG dwFlags, BSTR *pbstrOut)
Definition: varformat.c:2568
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
#define VARWDN_F(iWeekday, fAbbrev, iFirstDay, dwFlags, ret)
Definition: varformat.c:467
#define VARWDN_O(iWeekday, fAbbrev, iFirstDay, dwFlags)
Definition: varformat.c:470
BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
Definition: oleaut.c:339
#define VARCMP_EQ
Definition: oleauto.h:658
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define LOCALE_SDAYNAME1
Definition: winnls.h:77
#define LOCALE_SABBREVDAYNAME1
Definition: winnls.h:84
#define LOCALE_IFIRSTDAYOFWEEK
Definition: winnls.h:75
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by START_TEST().

Variable Documentation

◆ BSTR

Definition at line 42 of file varformat.c.

Referenced by test_VarFormat().

◆ has_i8

BSTR *static BSTR *static BSTR* static BOOL has_i8
static

Definition at line 48 of file varformat.c.

Referenced by START_TEST(), test_VarFormat(), and test_VarFormatNumber().

◆ hOleaut32

HMODULE hOleaut32
static

Definition at line 40 of file varformat.c.

Referenced by START_TEST(), and test_VarWeekdayName().

◆ int

BSTR *static BSTR *static int

Definition at line 43 of file varformat.c.

◆ LCID

Definition at line 42 of file varformat.c.

◆ LPOLESTR

BSTR *static LPOLESTR

Definition at line 44 of file varformat.c.

◆ szVarFmtFail

const char* szVarFmtFail = "VT %d|0x%04x Format %s: expected 0x%08x, '%s', got 0x%08x, '%s'\n"
static

Definition at line 126 of file varformat.c.

◆ szVarWdnFail

const char* szVarWdnFail
static
Initial value:
=
"VarWeekdayName (%d, %d, %d, %d, %x): returned %8x, expected %8x\n"

Definition at line 450 of file varformat.c.

◆ ULONG

BSTR *static BSTR *static ULONG

Definition at line 42 of file varformat.c.

◆ VarFormat_date_results

const FMTDATERES VarFormat_date_results[]
static

Definition at line 176 of file varformat.c.

Referenced by test_VarFormat().

◆ VarFormat_namedtime_results

const FMTDATERES VarFormat_namedtime_results[]
static
Initial value:
=
{
{ 2.525, "short time", "12:36" },
{ 2.525, "medium time", "12:36 PM" },
{ 2.525, "long time", "12:36:00 PM" }
}

Definition at line 219 of file varformat.c.

Referenced by test_VarFormat().

◆ VarFormat_results

const FMTRES VarFormat_results[]
static
Initial value:
=
{
{ NULL, "1", "0" },
{ "", "1", "0" },
{ "General Number", "1", "0" },
{ "Percent", "100.00%", "0.00%" },
{ "Standard", "1.00", "0.00" },
{ "Scientific","1.00E+00", "0.00E+00" },
{ "True/False", "True", "False" },
{ "On/Off", "On", "Off" },
{ "Yes/No", "Yes", "No" },
{ "#", "1", "" },
{ "##", "1", "" },
{ "#.#", "1.", "." },
{ "0", "1", "0" },
{ "00", "01", "00" },
{ "0.0", "1.0", "0.0" },
{ "00\\c\\o\\p\\y", "01copy","00copy" },
{ "\"pos\";\"neg\"", "pos", "pos" },
{ "\"pos\";\"neg\";\"zero\"","pos", "zero" }
}

Definition at line 147 of file varformat.c.