ReactOS 0.4.17-dev-444-g71ee754
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 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 void test_VarFormatNumber (void)
 
static void test_VarFormat (void)
 
static void test_VarWeekdayName (void)
 
static void test_VarFormatFromTokens (void)
 
static void test_GetAltMonthNames (void)
 
static void test_VarFormatCurrency (void)
 
static void test_VarFormatDateTime (void)
 
 START_TEST (varformat)
 

Variables

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

◆ FMT_NUMBER

#define FMT_NUMBER (   vt,
  val 
)
Value:
VariantInit(&v); V_VT(&v) = vt; val(&v) = 1; \
hres = VarFormatNumber(&v,2,0,0,0,0,&str); \
ok(hres == S_OK, "VarFormatNumber (vt %d): returned %8lx\n", vt, hres); \
if (hres == S_OK) { \
ok(str && wcscmp(str,szResult1) == 0, \
"VarFormatNumber (vt %d): string different\n", vt); \
SysFreeString(str); \
}
static REFPROPVARIANT PROPVAR_CHANGE_FLAGS VARTYPE vt
Definition: suminfo.c:91
_ACRTIMP int __cdecl wcscmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:1977
HRESULT WINAPI VarFormatNumber(LPVARIANT pVarIn, INT nDigits, INT nLeading, INT nParens, INT nGrouping, ULONG dwFlags, BSTR *pbstrOut)
Definition: varformat.c:2241
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
const WCHAR * str
void WINAPI VariantInit(VARIANTARG *pVarg)
Definition: variant.c:568

Definition at line 40 of file varformat.c.

◆ SIGNED_VTBITS

Definition at line 96 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 = VarFormat(&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)
#define ARRAY_SIZE(A)
Definition: main.h:20
#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
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3324
HRESULT WINAPI VarFormat(LPVARIANT pVarIn, LPOLESTR lpszFormat, int nFirstDay, int nFirstWeek, ULONG dwFlags, BSTR *pbstrOut)
Definition: varformat.c:2138
return ret
Definition: mutex.c:146
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:98
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
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383

Definition at line 99 of file varformat.c.

◆ VARWDN

#define VARWDN (   iWeekday,
  fAbbrev,
  iFirstDay,
  dwFlags,
  ret,
  buff,
  out,
  freeOut 
)
Value:
do { \
hres = VarWeekdayName(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)
HRESULT WINAPI VarWeekdayName(INT iWeekday, INT fAbbrev, INT iFirstDay, ULONG dwFlags, BSTR *pbstrOut)
Definition: varformat.c:2568
static const char * szVarWdnFail
Definition: varformat.c:412
_In_ LPWSTR _In_ DWORD _In_ DWORD _In_ DWORD dwFlags
Definition: netsh.h:141
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:271

Definition at line 414 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 429 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 432 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:119
#define SIGNED_VTBITS
Definition: varformat.c:96

Definition at line 198 of file varformat.c.

Typedef Documentation

◆ FMTDATERES

◆ FMTRES

Function Documentation

◆ START_TEST()

START_TEST ( varformat  )

Definition at line 675 of file varformat.c.

676{
684}
static void test_VarFormatFromTokens(void)
Definition: varformat.c:518
static void test_VarWeekdayName(void)
Definition: varformat.c:435
static void test_VarFormatDateTime(void)
Definition: varformat.c:662
static void test_VarFormatNumber(void)
Definition: varformat.c:50
static void test_GetAltMonthNames(void)
Definition: varformat.c:592
static void test_VarFormat(void)
Definition: varformat.c:210
static void test_VarFormatCurrency(void)
Definition: varformat.c:628

◆ test_GetAltMonthNames()

static void test_GetAltMonthNames ( void  )
static

Definition at line 592 of file varformat.c.

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}
#define ok(value,...)
Definition: atltest.h:57
HRESULT hr
Definition: delayimp.cpp:582
#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
XML_HIDDEN void xmlParserErrors const char const xmlChar const xmlChar * str2
Definition: parser.h:35

Referenced by START_TEST().

◆ test_VarFormat()

static void test_VarFormat ( void  )
static

Definition at line 210 of file varformat.c.

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}
#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:1609
LCID WINAPI GetUserDefaultLCID(void)
Definition: locale.c:1216
#define L(x)
Definition: resources.c:13
GLuint res
Definition: glext.h:9613
#define VARFMT(vt, v, val, fmt, ret, str)
Definition: varformat.c:99
static const FMTDATERES VarFormat_date_results[]
Definition: varformat.c:148
#define VNUMFMT(vt, v)
Definition: varformat.c:198
static const FMTDATERES VarFormat_namedtime_results[]
Definition: varformat.c:191
#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_INT(A)
Definition: oleauto.h:251
#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
short WCHAR
Definition: pedump.c:58
#define LANGIDFROMLCID(l)
Definition: nls.h:18
#define PRIMARYLANGID(l)
Definition: nls.h:16
uint32_t ULONG
Definition: typedefs.h:59
#define LOCALE_SDECIMAL
Definition: winnls.h:52
#define LOCALE_IDIGITS
Definition: winnls.h:55
#define LOCALE_STIMEFORMAT
Definition: winnls.h:72

Referenced by START_TEST().

◆ test_VarFormatCurrency()

static void test_VarFormatCurrency ( void  )
static

Definition at line 628 of file varformat.c.

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}
@ VT_CY
Definition: compat.h:2301
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4152
HRESULT WINAPI VarFormatCurrency(LPVARIANT pVarIn, INT nDigits, INT nLeading, INT nParens, INT nGrouping, ULONG dwFlags, BSTR *pbstrOut)
Definition: varformat.c:2420
#define wine_dbgstr_w
Definition: kernel32.h:34
#define V_BSTRREF(A)
Definition: oleauto.h:227
#define V_CY(A)
Definition: oleauto.h:229
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:648
#define DISP_E_TYPEMISMATCH
Definition: winerror.h:3617

Referenced by START_TEST().

◆ test_VarFormatDateTime()

static void test_VarFormatDateTime ( void  )
static

Definition at line 662 of file varformat.c.

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}
HRESULT WINAPI VarFormatDateTime(LPVARIANT pVarIn, INT nFormat, ULONG dwFlags, BSTR *pbstrOut)
Definition: varformat.c:2190

Referenced by START_TEST().

◆ test_VarFormatFromTokens()

static void test_VarFormatFromTokens ( void  )
static

Definition at line 518 of file varformat.c.

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}
LCID lcid
Definition: locale.c:5660
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
const char * var
Definition: shader.c:5666
#define LANG_GERMAN
Definition: nls.h:62
#define SUBLANG_GERMAN
Definition: nls.h:251
DWORD LCID
Definition: nls.h:13
unsigned char BYTE
Definition: xxhash.c:193

Referenced by START_TEST().

◆ test_VarFormatNumber()

static void test_VarFormatNumber ( void  )
static

Definition at line 50 of file varformat.c.

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}
#define FMT_NUMBER(vt, val)
Definition: varformat.c:40

Referenced by START_TEST().

◆ test_VarWeekdayName()

static void test_VarWeekdayName ( void  )
static

Definition at line 435 of file varformat.c.

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}
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define SetLastError(x)
Definition: compat.h:752
static DOUBLE day(DOUBLE time)
Definition: date.c:75
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: locale.c:1675
HRESULT WINAPI VarBstrCmp(BSTR pbstrLeft, BSTR pbstrRight, LCID lcid, DWORD dwFlags)
Definition: vartype.c:7158
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
#define win_skip
Definition: minitest.h:67
#define VARWDN_F(iWeekday, fAbbrev, iFirstDay, dwFlags, ret)
Definition: varformat.c:429
#define VARWDN_O(iWeekday, fAbbrev, iFirstDay, dwFlags)
Definition: varformat.c:432
BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
Definition: oleaut.c:339
#define VARCMP_EQ
Definition: oleauto.h:658
uint16_t * LPWSTR
Definition: typedefs.h:56
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define LOCALE_SDAYNAME1
Definition: winnls.h:87
#define LOCALE_SABBREVDAYNAME1
Definition: winnls.h:94
#define LOCALE_IFIRSTDAYOFWEEK
Definition: winnls.h:85

Referenced by START_TEST().

Variable Documentation

◆ szVarFmtFail

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

Definition at line 98 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 412 of file varformat.c.

◆ VarFormat_date_results

const FMTDATERES VarFormat_date_results[]
static

Definition at line 148 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 191 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 119 of file varformat.c.