ReactOS  0.4.14-dev-583-g2a1ba2c
vartype.c
Go to the documentation of this file.
1 /*
2  * Low level variant tests
3  *
4  * Copyright 2003 Jon Griffiths
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 
21 #define CONST_VTABLE
22 #define COBJMACROS
23 
24 #include "wine/test.h"
25 #include "oleauto.h"
26 #include <math.h>
27 #include <stdio.h>
28 #include "test_tlb.h"
29 
30 #include "initguid.h"
31 
32 DEFINE_GUID(UUID_test_struct, 0x4029f190, 0xca4a, 0x4611, 0xae,0xb9,0x67,0x39,0x83,0xcb,0x96,0xdd);
33 
34 /* Some Visual C++ versions choke on __uint64 to float conversions.
35  * To fix this you need either VC++ 6.0 plus the processor pack
36  * or Visual C++ >=7.0.
37  */
38 #ifndef _MSC_VER
39 # define HAS_UINT64_TO_FLOAT
40 #else
41 # if _MSC_VER >= 1300
42 # define HAS_UINT64_TO_FLOAT
43 # else
44 # include <malloc.h>
45 # if defined(_mm_free)
46 /* _mm_free is defined if the Processor Pack has been installed */
47 # define HAS_UINT64_TO_FLOAT
48 # endif
49 
50 # endif
51 #endif
52 
54 
55 /* Has I8/UI8 data type? */
56 static BOOL has_i8;
57 /* Has proper locale conversions? */
59 
60 /* Is vt a type unavailable to ancient versions? */
61 #define IS_MODERN_VTYPE(vt) (vt==VT_VARIANT||vt==VT_DECIMAL|| \
62  vt==VT_I1||vt==VT_UI2||vt==VT_UI4||vt == VT_INT||vt == VT_UINT)
63 
64 /* Macros for converting and testing results */
65 #define CONVVARS(typ) HRESULT hres; CONV_TYPE out; typ in
66 
67 #define _EXPECT_NO_OUT(res) ok(hres == res, "expected " #res ", got hres=0x%08x\n", hres)
68 #define EXPECT_OVERFLOW _EXPECT_NO_OUT(DISP_E_OVERFLOW)
69 #define EXPECT_MISMATCH _EXPECT_NO_OUT(DISP_E_TYPEMISMATCH)
70 #define EXPECT_BADVAR _EXPECT_NO_OUT(DISP_E_BADVARTYPE)
71 #define EXPECT_INVALID _EXPECT_NO_OUT(E_INVALIDARG)
72 #define EXPECT_LT _EXPECT_NO_OUT(VARCMP_LT)
73 #define EXPECT_GT _EXPECT_NO_OUT(VARCMP_GT)
74 #define EXPECT_EQ _EXPECT_NO_OUT(VARCMP_EQ)
75 
76 #define _EXPECTRES(res, x, fs) \
77  ok(hres == S_OK && out == (CONV_TYPE)(x), "expected " #x ", got " fs "; hres=0x%08x\n", out, hres)
78 #define EXPECT(x) EXPECTRES(S_OK, (x))
79 #define EXPECT_DBL(x) \
80  ok(hres == S_OK && fabs(out-(x))<=1e-14*(x), "expected %16.16g, got %16.16g; hres=0x%08x\n", (x), out, hres)
81 
82 #define CONVERT(func, val) in = val; hres = func(in, &out)
83 #define CONVERTRANGE(func,start,end) for (i = start; i < end; i+=1) { CONVERT(func, i); EXPECT(i); };
84 #define OVERFLOWRANGE(func,start,end) for (i = start; i < end; i+=1) { CONVERT(func, i); EXPECT_OVERFLOW; };
85 
86 #define CY_MULTIPLIER 10000
87 
88 #define DATE_MIN -657434
89 #define DATE_MAX 2958465
90 
91 #define CONVERT_I8(func,hi,lo) in = hi; in = (in << 32) | lo; hres = func(in, &out)
92 
93 #define CONVERT_CY(func,val) in.int64 = (LONGLONG)(val * CY_MULTIPLIER); hres = func(in, &out)
94 
95 #define CONVERT_CY64(func,hi,lo) S(in).Hi = hi; S(in).Lo = lo; in.int64 *= CY_MULTIPLIER; hres = func(in, &out)
96 
97 #define SETDEC(dec, scl, sgn, hi, lo) S(U(dec)).scale = (BYTE)scl; S(U(dec)).sign = (BYTE)sgn; \
98  dec.Hi32 = (ULONG)hi; U1(dec).Lo64 = (ULONG64)lo
99 
100 #define SETDEC64(dec, scl, sgn, hi, mid, lo) S(U(dec)).scale = (BYTE)scl; S(U(dec)).sign = (BYTE)sgn; \
101  dec.Hi32 = (ULONG)hi; S1(U1(dec)).Mid32 = mid; S1(U1(dec)).Lo32 = lo;
102 
103 #define CONVERT_DEC(func,scl,sgn,hi,lo) SETDEC(in,scl,sgn,hi,lo); hres = func(&in, &out)
104 
105 #define CONVERT_DEC64(func,scl,sgn,hi,mid,lo) SETDEC64(in,scl,sgn,hi,mid,lo); hres = func(&in, &out)
106 
107 #define CONVERT_BADDEC(func) \
108  CONVERT_DEC(func,29,0,0,0); EXPECT_INVALID; \
109  CONVERT_DEC(func,0,0x1,0,0); EXPECT_INVALID; \
110  CONVERT_DEC(func,0,0x40,0,0); EXPECT_INVALID; \
111  CONVERT_DEC(func,0,0x7f,0,0); EXPECT_INVALID;
112 
113 #define CONVERT_STR(func,str,flags) \
114  SetLastError(0); \
115  if (str) MultiByteToWideChar(CP_ACP,0,str,-1,buff,ARRAY_SIZE(buff)); \
116  hres = func(str ? buff : NULL,in,flags,&out)
117 
118 #define COPYTEST(val, vt, srcval, dstval, srcref, dstref, fs) do { \
119  HRESULT hres; VARIANTARG vSrc, vDst; CONV_TYPE in = val; \
120  VariantInit(&vSrc); VariantInit(&vDst); \
121  V_VT(&vSrc) = vt; srcval = in; \
122  hres = VariantCopy(&vDst, &vSrc); \
123  ok(hres == S_OK && V_VT(&vDst) == vt && dstval == in, \
124  "copy hres 0x%X, type %d, value (" fs ") " fs "\n", hres, V_VT(&vDst), val, dstval); \
125  V_VT(&vSrc) = vt|VT_BYREF; srcref = &in; \
126  hres = VariantCopy(&vDst, &vSrc); \
127  ok(hres == S_OK && V_VT(&vDst) == (vt|VT_BYREF) && dstref == &in, \
128  "ref hres 0x%X, type %d, ref (%p) %p\n", hres, V_VT(&vDst), &in, dstref); \
129  hres = VariantCopyInd(&vDst, &vSrc); \
130  ok(hres == S_OK && V_VT(&vDst) == vt && dstval == in, \
131  "ind hres 0x%X, type %d, value (" fs ") " fs "\n", hres, V_VT(&vDst), val, dstval); \
132  } while(0)
133 
134 #define CHANGETYPEEX(typ) hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, typ)
135 
136 #define TYPETEST(typ,res,fs) CHANGETYPEEX(typ); \
137  ok(hres == S_OK && V_VT(&vDst) == typ && (CONV_TYPE)res == in, \
138  "hres=0x%X, type=%d (should be %d(" #typ ")), value=" fs " (should be " fs ")\n", \
139  hres, V_VT(&vDst), typ, (CONV_TYPE)res, in);
140 #define TYPETESTI8(typ,res) CHANGETYPEEX(typ); \
141  ok(hres == S_OK && V_VT(&vDst) == typ && (CONV_TYPE)res == in, \
142  "hres=0x%X, type=%d (should be %d(" #typ ")), value=%d (should be 1)\n", \
143  hres, V_VT(&vDst), typ, (int)res);
144 #define BADVAR(typ) CHANGETYPEEX(typ); EXPECT_BADVAR
145 #define MISMATCH(typ) CHANGETYPEEX(typ); EXPECT_MISMATCH
146 
147 #define INITIAL_TYPETEST(vt, val, fs) \
148  VariantInit(&vSrc); \
149  VariantInit(&vDst); \
150  V_VT(&vSrc) = vt; \
151  (val(&vSrc)) = in; \
152  TYPETEST(VT_I1, V_I1(&vDst), fs); \
153  TYPETEST(VT_UI2, V_UI2(&vDst), fs); \
154  TYPETEST(VT_UI4, V_UI4(&vDst), fs); \
155  TYPETEST(VT_INT, V_INT(&vDst), fs); \
156  TYPETEST(VT_UINT, V_UINT(&vDst), fs); \
157  TYPETEST(VT_UI1, V_UI1(&vDst), fs); \
158  TYPETEST(VT_I2, V_I2(&vDst), fs); \
159  TYPETEST(VT_I4, V_I4(&vDst), fs); \
160  TYPETEST(VT_R4, V_R4(&vDst), fs); \
161  TYPETEST(VT_R8, V_R8(&vDst), fs); \
162  TYPETEST(VT_DATE, V_DATE(&vDst), fs); \
163  if (has_i8) \
164  { \
165  TYPETEST(VT_I8, V_I8(&vDst), fs); \
166  TYPETEST(VT_UI8, V_UI8(&vDst), fs); \
167  }
168 #define NEGATIVE_TYPETEST(vt, val, fs, vtneg, valneg) \
169  in = -in; \
170  VariantInit(&vSrc); \
171  VariantInit(&vDst); \
172  V_VT(&vSrc) = vt; \
173  (val(&vSrc)) = in; \
174  TYPETEST(vtneg, valneg(&vDst), fs);
175 
176 #define INITIAL_TYPETESTI8(vt, val) \
177  VariantInit(&vSrc); \
178  VariantInit(&vDst); \
179  V_VT(&vSrc) = vt; \
180  (val(&vSrc)) = in; \
181  TYPETESTI8(VT_I1, V_I1(&vDst)); \
182  TYPETESTI8(VT_UI1, V_UI1(&vDst)); \
183  TYPETESTI8(VT_I2, V_I2(&vDst)); \
184  TYPETESTI8(VT_UI2, V_UI2(&vDst)); \
185  TYPETESTI8(VT_I4, V_I4(&vDst)); \
186  TYPETESTI8(VT_UI4, V_UI4(&vDst)); \
187  TYPETESTI8(VT_INT, V_INT(&vDst)); \
188  TYPETESTI8(VT_UINT, V_UINT(&vDst)); \
189  TYPETESTI8(VT_R4, V_R4(&vDst)); \
190  TYPETESTI8(VT_R8, V_R8(&vDst)); \
191  TYPETESTI8(VT_DATE, V_DATE(&vDst)); \
192  TYPETESTI8(VT_I8, V_I8(&vDst)); \
193  TYPETESTI8(VT_UI8, V_UI8(&vDst))
194 
195 #define COMMON_TYPETEST \
196  hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_BOOL); \
197  ok(hres == S_OK && V_VT(&vDst) == VT_BOOL && \
198  (V_BOOL(&vDst) == VARIANT_TRUE || (V_VT(&vSrc) == VT_BOOL && V_BOOL(&vDst) == 1)), \
199  "->VT_BOOL hres=0x%X, type=%d (should be VT_BOOL), value %d (should be VARIANT_TRUE)\n", \
200  hres, V_VT(&vDst), V_BOOL(&vDst)); \
201  hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_CY); \
202  ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == CY_MULTIPLIER, \
203  "->VT_CY hres=0x%X, type=%d (should be VT_CY), value (%08x,%08x) (should be CY_MULTIPLIER)\n", \
204  hres, V_VT(&vDst), S(V_CY(&vDst)).Hi, S(V_CY(&vDst)).Lo); \
205  if (V_VT(&vSrc) != VT_DATE) \
206  { \
207  hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_BSTR); \
208  ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && \
209  V_BSTR(&vDst) && V_BSTR(&vDst)[0] == '1' && V_BSTR(&vDst)[1] == '\0', \
210  "->VT_BSTR hres=0x%X, type=%d (should be VT_BSTR), *bstr='%c'\n", \
211  hres, V_VT(&vDst), V_BSTR(&vDst) ? *V_BSTR(&vDst) : '?'); \
212  } \
213  hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_DECIMAL); \
214  ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && \
215  S(U(V_DECIMAL(&vDst))).sign == 0 && S(U(V_DECIMAL(&vDst))).scale == 0 && \
216  V_DECIMAL(&vDst).Hi32 == 0 && U1(V_DECIMAL(&vDst)).Lo64 == (ULONGLONG)in, \
217  "->VT_DECIMAL hres=0x%X, type=%d (should be VT_DECIMAL), sign=%d, scale=%d, hi=%u, lo=(%8x %8x),\n", \
218  hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign, S(U(V_DECIMAL(&vDst))).scale, \
219  V_DECIMAL(&vDst).Hi32, S1(U1(V_DECIMAL(&vDst))).Mid32, S1(U1(V_DECIMAL(&vDst))).Lo32); \
220  hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_EMPTY); \
221  ok(hres == S_OK && V_VT(&vDst) == VT_EMPTY, "->VT_EMPTY hres=0x%X, type=%d (should be VT_EMPTY)\n", hres, V_VT(&vDst)); \
222  hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_NULL); \
223  ok(hres == S_OK && V_VT(&vDst) == VT_NULL, "->VT_NULL hres=0x%X, type=%d (should be VT_NULL)\n", hres, V_VT(&vDst)); \
224  MISMATCH(VT_DISPATCH); \
225  MISMATCH(VT_ERROR); \
226  MISMATCH(VT_UNKNOWN); \
227  MISMATCH(VT_VARIANT); \
228  MISMATCH(VT_RECORD); \
229  BADVAR(VT_VOID); \
230  BADVAR(VT_HRESULT); \
231  BADVAR(VT_SAFEARRAY); \
232  BADVAR(VT_CARRAY); \
233  BADVAR(VT_USERDEFINED); \
234  BADVAR(VT_LPSTR); \
235  BADVAR(VT_LPWSTR); \
236  BADVAR(VT_PTR); \
237  BADVAR(VT_INT_PTR); \
238  BADVAR(VT_UINT_PTR); \
239  BADVAR(VT_FILETIME); \
240  BADVAR(VT_BLOB); \
241  BADVAR(VT_STREAM); \
242  BADVAR(VT_STORAGE); \
243  BADVAR(VT_STREAMED_OBJECT); \
244  BADVAR(VT_STORED_OBJECT); \
245  BADVAR(VT_BLOB_OBJECT); \
246  BADVAR(VT_CF); \
247  BADVAR(VT_CLSID); \
248  BADVAR(VT_BSTR_BLOB)
249 
250 #define DEFINE_EXPECT(func) \
251  static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
252 
253 #define SET_EXPECT(func) \
254  do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
255 
256 #define CHECK_EXPECT2(func) \
257  do { \
258  ok(expect_ ##func, "unexpected call " #func "\n"); \
259  called_ ## func = TRUE; \
260  }while(0)
261 
262 #define CHECK_EXPECT(func) \
263  do { \
264  CHECK_EXPECT2(func); \
265  expect_ ## func = FALSE; \
266  }while(0)
267 
268 #define CHECK_CALLED(func) \
269  do { \
270  ok(called_ ## func, "expected " #func "\n"); \
271  expect_ ## func = called_ ## func = FALSE; \
272  }while(0)
273 
274 DEFINE_EXPECT(dispatch_invoke);
275 
276 /* Internal representation of a BSTR */
277 typedef struct tagINTERNAL_BSTR
278 {
282 
283 typedef struct
284 {
285  IDispatch IDispatch_iface;
287  VARTYPE vt;
289 } DummyDispatch;
290 
292 {
293  return CONTAINING_RECORD(iface, DummyDispatch, IDispatch_iface);
294 }
295 
297 {
299  return InterlockedIncrement(&This->ref);
300 }
301 
303 {
305  return InterlockedDecrement(&This->ref);
306 }
307 
309  REFIID riid,
310  void** ppvObject)
311 {
312  *ppvObject = NULL;
313 
314  if (IsEqualIID(riid, &IID_IDispatch) ||
316  {
317  *ppvObject = iface;
318  IDispatch_AddRef(iface);
319  }
320 
321  return *ppvObject ? S_OK : E_NOINTERFACE;
322 }
323 
325 {
326  ok(0, "Unexpected call\n");
327  return E_NOTIMPL;
328 }
329 
331 {
332  ok(0, "Unexpected call\n");
333  return E_NOTIMPL;
334 }
335 
337  UINT cnames, LCID lcid, DISPID *dispid)
338 {
339  ok(0, "Unexpected call\n");
340  return E_NOTIMPL;
341 }
342 
344  DISPID dispid, REFIID riid,
345  LCID lcid, WORD wFlags,
347  VARIANT *res,
348  EXCEPINFO *ei,
349  UINT *arg_err)
350 {
352 
353  CHECK_EXPECT(dispatch_invoke);
354 
355  ok(dispid == DISPID_VALUE, "got dispid %d\n", dispid);
356  ok(IsEqualIID(riid, &IID_NULL), "go riid %s\n", wine_dbgstr_guid(riid));
357  ok(wFlags == DISPATCH_PROPERTYGET, "Flags wrong\n");
358 
359  ok(params->rgvarg == NULL, "got %p\n", params->rgvarg);
360  ok(params->rgdispidNamedArgs == NULL, "got %p\n", params->rgdispidNamedArgs);
361  ok(params->cArgs == 0, "got %d\n", params->cArgs);
362  ok(params->cNamedArgs == 0, "got %d\n", params->cNamedArgs);
363 
364  ok(res != NULL, "got %p\n", res);
365  ok(V_VT(res) == VT_EMPTY, "got %d\n", V_VT(res));
366  ok(ei == NULL, "got %p\n", ei);
367  ok(arg_err == NULL, "got %p\n", arg_err);
368 
369  if (This->bFailInvoke)
370  return E_OUTOFMEMORY;
371 
372  V_VT(res) = This->vt;
373  if (This->vt == VT_UI1)
374  V_UI1(res) = 1;
375  else
376  memset(res, 0, sizeof(*res));
377 
378  return S_OK;
379 }
380 
381 static const IDispatchVtbl DummyDispatch_VTable =
382 {
390 };
391 
393 {
394  dispatch->IDispatch_iface.lpVtbl = &DummyDispatch_VTable;
395  dispatch->ref = ref;
396  dispatch->vt = vt;
397  dispatch->bFailInvoke = FALSE;
398 }
399 
400 /*
401  * VT_I1/VT_UI1
402  */
403 
404 #undef CONV_TYPE
405 #define CONV_TYPE signed char
406 #undef EXPECTRES
407 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%d")
408 
409 static void test_VarI1FromI2(void)
410 {
411  CONVVARS(SHORT);
412  int i;
413 
414  OVERFLOWRANGE(VarI1FromI2, -32768, -128);
415  CONVERTRANGE(VarI1FromI2, -128, 128);
416  OVERFLOWRANGE(VarI1FromI2, 129, 32768);
417 }
418 
419 static void test_VarI1FromI4(void)
420 {
421  CONVVARS(LONG);
422  int i;
423 
425  CONVERTRANGE(VarI1FromI4, -128, 128);
427 }
428 
429 static void test_VarI1FromI8(void)
430 {
431  CONVVARS(LONG64);
432  int i;
433 
435  CONVERTRANGE(VarI1FromI8, -127, 128);
437 }
438 
439 static void test_VarI1FromUI1(void)
440 {
441  CONVVARS(BYTE);
442  int i;
443 
444  CONVERTRANGE(VarI1FromUI1, 0, 127);
445  OVERFLOWRANGE(VarI1FromUI1, 128, 255);
446 }
447 
448 static void test_VarI1FromUI2(void)
449 {
450  CONVVARS(USHORT);
451  int i;
452 
453  CONVERTRANGE(VarI1FromUI2, 0, 127);
454  OVERFLOWRANGE(VarI1FromUI2, 128, 32768);
455 }
456 
457 static void test_VarI1FromUI4(void)
458 {
459  CONVVARS(ULONG);
460  int i;
461 
462  CONVERTRANGE(VarI1FromUI4, 0, 127);
464 }
465 
466 static void test_VarI1FromUI8(void)
467 {
468  CONVVARS(ULONG64);
469  int i;
470 
471  CONVERTRANGE(VarI1FromUI8, 0, 127);
473 }
474 
475 static void test_VarI1FromBool(void)
476 {
478  int i;
479 
480  /* Note that conversions from bool wrap around! */
481  CONVERT(VarI1FromBool, -129); EXPECT(127);
482  CONVERTRANGE(VarI1FromBool, -128, 128);
483  CONVERT(VarI1FromBool, 128); EXPECT(-128);
484 }
485 
486 static void test_VarI1FromR4(void)
487 {
488  CONVVARS(FLOAT);
489 
492  CONVERT(VarI1FromR4, -128.5f); EXPECT(-128);
493  CONVERT(VarI1FromR4, -128.0f); EXPECT(-128);
494  CONVERT(VarI1FromR4, -1.0f); EXPECT(-1);
495  CONVERT(VarI1FromR4, 0.0f); EXPECT(0);
496  CONVERT(VarI1FromR4, 1.0f); EXPECT(1);
497  CONVERT(VarI1FromR4, 127.0f); EXPECT(127);
498  CONVERT(VarI1FromR4, 127.49f); EXPECT(127);
501 
502  CONVERT(VarI1FromR4, -1.5f); EXPECT(-2);
503  CONVERT(VarI1FromR4, -0.6f); EXPECT(-1);
504  CONVERT(VarI1FromR4, -0.5f); EXPECT(0);
505  CONVERT(VarI1FromR4, -0.4f); EXPECT(0);
506  CONVERT(VarI1FromR4, 0.4f); EXPECT(0);
507  CONVERT(VarI1FromR4, 0.5f); EXPECT(0);
508  CONVERT(VarI1FromR4, 0.6f); EXPECT(1);
509  CONVERT(VarI1FromR4, 1.5f); EXPECT(2);
510 }
511 
512 static void test_VarI1FromR8(void)
513 {
514  CONVVARS(DOUBLE);
515 
518  CONVERT(VarI1FromR8, -128.5); EXPECT(-128);
519  CONVERT(VarI1FromR8, -128.0); EXPECT(-128);
520  CONVERT(VarI1FromR8, -1.0); EXPECT(-1);
521  CONVERT(VarI1FromR8, 0.0); EXPECT(0);
522  CONVERT(VarI1FromR8, 1.0); EXPECT(1);
523  CONVERT(VarI1FromR8, 127.0); EXPECT(127);
524  CONVERT(VarI1FromR8, 127.49); EXPECT(127);
527 
528  CONVERT(VarI1FromR8, -1.5); EXPECT(-2);
529  CONVERT(VarI1FromR8, -0.6); EXPECT(-1);
530  CONVERT(VarI1FromR8, -0.5); EXPECT(0);
531  CONVERT(VarI1FromR8, -0.4); EXPECT(0);
532  CONVERT(VarI1FromR8, 0.4); EXPECT(0);
533  CONVERT(VarI1FromR8, 0.5); EXPECT(0);
534  CONVERT(VarI1FromR8, 0.6); EXPECT(1);
535  CONVERT(VarI1FromR8, 1.5); EXPECT(2);
536 }
537 
538 static void test_VarI1FromDate(void)
539 {
540  CONVVARS(DATE);
541 
543  CONVERT(VarI1FromDate, -128.0); EXPECT(-128);
544  CONVERT(VarI1FromDate, -1.0); EXPECT(-1);
545  CONVERT(VarI1FromDate, 0.0); EXPECT(0);
546  CONVERT(VarI1FromDate, 1.0); EXPECT(1);
547  CONVERT(VarI1FromDate, 127.0); EXPECT(127);
549 
550  CONVERT(VarI1FromDate, -1.5); EXPECT(-2);
551  CONVERT(VarI1FromDate, -0.6); EXPECT(-1);
552  CONVERT(VarI1FromDate, -0.5); EXPECT(0);
553  CONVERT(VarI1FromDate, -0.4); EXPECT(0);
554  CONVERT(VarI1FromDate, 0.4); EXPECT(0);
555  CONVERT(VarI1FromDate, 0.5); EXPECT(0);
556  CONVERT(VarI1FromDate, 0.6); EXPECT(1);
557  CONVERT(VarI1FromDate, 1.5); EXPECT(2);
558 }
559 
560 static void test_VarI1FromCy(void)
561 {
562  CONVVARS(CY);
563 
565  CONVERT_CY(VarI1FromCy,-128); EXPECT(128);
566  CONVERT_CY(VarI1FromCy,-1); EXPECT(-1);
569  CONVERT_CY(VarI1FromCy,127); EXPECT(127);
571 
572  CONVERT_CY(VarI1FromCy,-1.5); EXPECT(-2);
573  CONVERT_CY(VarI1FromCy,-0.6); EXPECT(-1);
574  CONVERT_CY(VarI1FromCy,-0.5); EXPECT(0);
575  CONVERT_CY(VarI1FromCy,-0.4); EXPECT(0);
576  CONVERT_CY(VarI1FromCy,0.4); EXPECT(0);
577  CONVERT_CY(VarI1FromCy,0.5); EXPECT(0);
578  CONVERT_CY(VarI1FromCy,0.6); EXPECT(1);
579  CONVERT_CY(VarI1FromCy,1.5); EXPECT(2);
580 }
581 
582 static void test_VarI1FromDec(void)
583 {
584  CONVVARS(DECIMAL);
585 
587 
589  CONVERT_DEC(VarI1FromDec,0,0x80,0,128); EXPECT(-128);
590  CONVERT_DEC(VarI1FromDec,0,0x80,0,1); EXPECT(-1);
591  CONVERT_DEC(VarI1FromDec,0,0,0,0); EXPECT(0);
592  CONVERT_DEC(VarI1FromDec,0,0,0,1); EXPECT(1);
593  CONVERT_DEC(VarI1FromDec,0,0,0,127); EXPECT(127);
595 
596  CONVERT_DEC(VarI1FromDec,2,0x80,0,12800); EXPECT(-128);
597  CONVERT_DEC(VarI1FromDec,2,0,0,12700); EXPECT(127);
598 }
599 
600 static void test_VarI1FromStr(void)
601 {
602  CONVVARS(LCID);
603  OLECHAR buff[128];
604 
606 
608  CONVERT_STR(VarI1FromStr,"0", 0); EXPECT(0);
610  CONVERT_STR(VarI1FromStr,"-128", 0); EXPECT(-128);
611  CONVERT_STR(VarI1FromStr,"127", 0); EXPECT(127);
613 
622 }
623 
624 static void test_VarI1Copy(void)
625 {
626  COPYTEST(1, VT_I1, V_I1(&vSrc), V_I1(&vDst), V_I1REF(&vSrc), V_I1REF(&vDst), "%d");
627 }
628 
629 static void test_VarI1ChangeTypeEx(void)
630 {
631  HRESULT hres;
632  signed char in;
633  VARIANTARG vSrc, vDst;
634 
635  in = 1;
636 
637  INITIAL_TYPETEST(VT_I1, V_I1, "%d");
640 }
641 
642 #undef CONV_TYPE
643 #define CONV_TYPE BYTE
644 
645 static void test_VarUI1FromI1(void)
646 {
647  CONVVARS(signed char);
648  int i;
649 
650  OVERFLOWRANGE(VarUI1FromI1, -128, 0);
651  CONVERTRANGE(VarUI1FromI1, 0, 128);
652 }
653 
654 static void test_VarUI1FromI2(void)
655 {
656  CONVVARS(SHORT);
657  int i;
658 
659  OVERFLOWRANGE(VarUI1FromI2, -32768, 0);
660  CONVERTRANGE(VarUI1FromI2, 0, 256);
661  OVERFLOWRANGE(VarUI1FromI2, 256, 32768);
662 }
663 
664 static void test_VarUI1FromI4(void)
665 {
666  CONVVARS(LONG);
667  int i;
668 
670  CONVERTRANGE(VarUI1FromI4, 0, 256);
672 }
673 
674 static void test_VarUI1FromI8(void)
675 {
676  CONVVARS(LONG64);
677  int i;
678 
680  CONVERTRANGE(VarUI1FromI8, 0, 256);
682 }
683 
684 static void test_VarUI1FromUI2(void)
685 {
686  CONVVARS(USHORT);
687  int i;
688 
689  CONVERTRANGE(VarUI1FromUI2, 0, 256);
690  OVERFLOWRANGE(VarUI1FromUI2, 256, 65536);
691 }
692 
693 static void test_VarUI1FromUI4(void)
694 {
695  CONVVARS(ULONG);
696  int i;
697 
698  CONVERTRANGE(VarUI1FromUI4, 0, 256);
700 }
701 
702 static void test_VarUI1FromUI8(void)
703 {
704  CONVVARS(ULONG64);
705  int i;
706 
707  CONVERTRANGE(VarUI1FromUI8, 0, 256);
709 }
710 
711 static void test_VarUI1FromBool(void)
712 {
714  int i;
715 
716  /* Note that conversions from bool overflow! */
717  CONVERT(VarUI1FromBool, -1); EXPECT(255);
718  CONVERTRANGE(VarUI1FromBool, 0, 256);
719  CONVERT(VarUI1FromBool, 256); EXPECT(0);
720 }
721 
722 static void test_VarUI1FromR4(void)
723 {
724  CONVVARS(FLOAT);
725 
728  CONVERT(VarUI1FromR4, -0.5f); EXPECT(0);
729  CONVERT(VarUI1FromR4, 0.0f); EXPECT(0);
730  CONVERT(VarUI1FromR4, 1.0f); EXPECT(1);
731  CONVERT(VarUI1FromR4, 255.0f); EXPECT(255);
732  CONVERT(VarUI1FromR4, 255.49f); EXPECT(255);
735 
736  /* Rounding */
739  CONVERT(VarUI1FromR4, -0.5f); EXPECT(0);
740  CONVERT(VarUI1FromR4, -0.4f); EXPECT(0);
741  CONVERT(VarUI1FromR4, 0.4f); EXPECT(0);
742  CONVERT(VarUI1FromR4, 0.5f); EXPECT(0);
743  CONVERT(VarUI1FromR4, 0.6f); EXPECT(1);
744  CONVERT(VarUI1FromR4, 1.5f); EXPECT(2);
745 }
746 
747 static void test_VarUI1FromR8(void)
748 {
749  CONVVARS(DOUBLE);
750 
753  CONVERT(VarUI1FromR8, -0.5); EXPECT(0);
754  CONVERT(VarUI1FromR8, 0.0); EXPECT(0);
755  CONVERT(VarUI1FromR8, 1.0); EXPECT(1);
756  CONVERT(VarUI1FromR8, 255.0); EXPECT(255);
757  CONVERT(VarUI1FromR8, 255.49); EXPECT(255);
760 
761  /* Rounding */
764  CONVERT(VarUI1FromR8, -0.5); EXPECT(0);
765  CONVERT(VarUI1FromR8, -0.4); EXPECT(0);
766  CONVERT(VarUI1FromR8, 0.4); EXPECT(0);
767  CONVERT(VarUI1FromR8, 0.5); EXPECT(0);
768  CONVERT(VarUI1FromR8, 0.6); EXPECT(1);
769  CONVERT(VarUI1FromR8, 1.5); EXPECT(2);
770 }
771 
772 static void test_VarUI1FromDate(void)
773 {
774  CONVVARS(DATE);
775 
777  CONVERT(VarUI1FromDate, 0.0); EXPECT(0);
778  CONVERT(VarUI1FromDate, 1.0); EXPECT(1);
779  CONVERT(VarUI1FromDate, 255.0); EXPECT(255);
781 
782  /* Rounding */
785  CONVERT(VarUI1FromDate, -0.5); EXPECT(0);
786  CONVERT(VarUI1FromDate, -0.4); EXPECT(0);
787  CONVERT(VarUI1FromDate, 0.4); EXPECT(0);
788  CONVERT(VarUI1FromDate, 0.5); EXPECT(0);
789  CONVERT(VarUI1FromDate, 0.6); EXPECT(1);
790  CONVERT(VarUI1FromDate, 1.5); EXPECT(2);
791 }
792 
793 static void test_VarUI1FromCy(void)
794 {
795  CONVVARS(CY);
796 
800  CONVERT_CY(VarUI1FromCy,255); EXPECT(255);
802 
803  /* Rounding */
806  CONVERT_CY(VarUI1FromCy,-0.5); EXPECT(0);
807  CONVERT_CY(VarUI1FromCy,-0.4); EXPECT(0);
808  CONVERT_CY(VarUI1FromCy,0.4); EXPECT(0);
809  CONVERT_CY(VarUI1FromCy,0.5); EXPECT(0);
810  CONVERT_CY(VarUI1FromCy,0.6); EXPECT(1);
811  CONVERT_CY(VarUI1FromCy,1.5); EXPECT(2);
812 }
813 
814 static void test_VarUI1FromDec(void)
815 {
816  CONVVARS(DECIMAL);
817 
819 
821  CONVERT_DEC(VarUI1FromDec,0,0,0,0); EXPECT(0);
822  CONVERT_DEC(VarUI1FromDec,0,0,0,1); EXPECT(1);
823  CONVERT_DEC(VarUI1FromDec,0,0,0,255); EXPECT(255);
825 
827  CONVERT_DEC(VarUI1FromDec,2,0,0,25500); EXPECT(255);
828 }
829 
830 static void test_VarUI1FromStr(void)
831 {
832  CONVVARS(LCID);
833  OLECHAR buff[128];
834 
836 
838  CONVERT_STR(VarUI1FromStr,"0", 0); EXPECT(0);
840  CONVERT_STR(VarUI1FromStr,"255", 0); EXPECT(255);
842 
843  /* Rounding */
852 }
853 
854 static void test_VarUI1FromDisp(void)
855 {
857  CONVVARS(LCID);
858  VARIANTARG vSrc, vDst;
859 
860  /* FIXME
861  * Conversions from IDispatch should get the default 'value' property
862  * from the IDispatch pointer and return it. The following tests this.
863  * However, I can't get these tests to return a valid value under native
864  * oleaut32, regardless of the value returned in response to the Invoke()
865  * call (early versions of oleaut32 call AddRef/Release, but not Invoke.
866  * I'm obviously missing something, as these conversions work fine
867  * when called through VBA on an object to get its default value property.
868  *
869  * Should this test be corrected so that it works under native it should be
870  * generalised and the remaining types checked as well.
871  */
873 
874  VariantInit(&vSrc);
875  VariantInit(&vDst);
876 
878  V_VT(&vSrc) = VT_DISPATCH;
879  V_DISPATCH(&vSrc) = &dispatch.IDispatch_iface;
880 
881  SET_EXPECT(dispatch_invoke);
882  out = 10;
883  hres = VarUI1FromDisp(&dispatch.IDispatch_iface, in, &out);
884  ok(broken(hres == DISP_E_BADVARTYPE) || hres == S_OK, "got 0x%08x\n", hres);
885  ok(broken(out == 10) || out == 1, "got %d\n", out);
886  CHECK_CALLED(dispatch_invoke);
887 
888  SET_EXPECT(dispatch_invoke);
889  V_VT(&vDst) = VT_EMPTY;
890  V_UI1(&vDst) = 0;
891  hres = VariantChangeTypeEx(&vDst, &vSrc, in, 0, VT_UI1);
892  ok(hres == S_OK, "got 0x%08x\n", hres);
893  ok(V_VT(&vDst) == VT_UI1, "got %d\n", V_VT(&vDst));
894  ok(V_UI1(&vDst) == 1, "got %d\n", V_UI1(&vDst));
895  CHECK_CALLED(dispatch_invoke);
896 
897  dispatch.bFailInvoke = TRUE;
898 
899  SET_EXPECT(dispatch_invoke);
900  out = 10;
901  hres = VarUI1FromDisp(&dispatch.IDispatch_iface, in, &out);
902  ok(hres == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hres);
903  ok(out == 10, "got %d\n", out);
904  CHECK_CALLED(dispatch_invoke);
905 
906  SET_EXPECT(dispatch_invoke);
907  V_VT(&vDst) = VT_EMPTY;
908  hres = VariantChangeTypeEx(&vDst, &vSrc, in, 0, VT_UI1);
909  ok(hres == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hres);
910  ok(V_VT(&vDst) == VT_EMPTY, "got %d\n", V_VT(&vDst));
911  CHECK_CALLED(dispatch_invoke);
912 }
913 
914 static void test_VarUI1Copy(void)
915 {
916  COPYTEST(1, VT_UI1, V_UI1(&vSrc), V_UI1(&vDst), V_UI1REF(&vSrc), V_UI1REF(&vDst), "%d");
917 }
918 
919 static void test_VarUI1ChangeTypeEx(void)
920 {
921  HRESULT hres;
922  BYTE in;
923  VARIANTARG vSrc, vDst;
924 
925  in = 1;
926 
927  INITIAL_TYPETEST(VT_UI1, V_UI1, "%d");
930 }
931 
932 /*
933  * VT_I2/VT_UI2
934  */
935 
936 #undef CONV_TYPE
937 #define CONV_TYPE SHORT
938 
939 static void test_VarI2FromI1(void)
940 {
941  CONVVARS(signed char);
942  int i;
943 
944  CONVERTRANGE(VarI2FromI1, -128, 128);
945 }
946 
947 static void test_VarI2FromI4(void)
948 {
949  CONVVARS(LONG);
950  int i;
951 
953  CONVERTRANGE(VarI2FromI4, -32768, 32768);
955 }
956 
957 static void test_VarI2FromI8(void)
958 {
959  CONVVARS(LONG64);
960 
962  CONVERT(VarI2FromI8, -32768); EXPECT(-32768);
963  CONVERT(VarI2FromI8, 32767); EXPECT(32767);
965 }
966 
967 static void test_VarI2FromUI1(void)
968 {
969  CONVVARS(BYTE);
970  int i;
971 
972  CONVERTRANGE(VarI2FromUI1, 0, 256);
973 }
974 
975 static void test_VarI2FromUI2(void)
976 {
977  CONVVARS(USHORT);
978  int i;
979 
980  CONVERTRANGE(VarI2FromUI2, 0, 32768);
982 }
983 
984 static void test_VarI2FromUI4(void)
985 {
986  CONVVARS(ULONG);
987  int i;
988 
989  CONVERTRANGE(VarI2FromUI4, 0, 32768);
991 }
992 
993 static void test_VarI2FromUI8(void)
994 {
995  CONVVARS(ULONG64);
996  int i;
997 
998  CONVERTRANGE(VarI2FromUI8, 0, 32768);
1000 }
1001 
1002 static void test_VarI2FromBool(void)
1003 {
1005  int i;
1006 
1007  CONVERTRANGE(VarI2FromBool, -32768, 32768);
1008 }
1009 
1010 static void test_VarI2FromR4(void)
1011 {
1012  CONVVARS(FLOAT);
1013 
1014  CONVERT(VarI2FromR4, -32769.0f); EXPECT_OVERFLOW;
1015  CONVERT(VarI2FromR4, -32768.51f); EXPECT_OVERFLOW;
1016  CONVERT(VarI2FromR4, -32768.5f); EXPECT(-32768);
1017  CONVERT(VarI2FromR4, -32768.0f); EXPECT(-32768);
1018  CONVERT(VarI2FromR4, -1.0f); EXPECT(-1);
1019  CONVERT(VarI2FromR4, 0.0f); EXPECT(0);
1020  CONVERT(VarI2FromR4, 1.0f); EXPECT(1);
1021  CONVERT(VarI2FromR4, 32767.0f); EXPECT(32767);
1022  CONVERT(VarI2FromR4, 32767.49f); EXPECT(32767);
1025 
1026  /* Rounding */
1027  CONVERT(VarI2FromR4, -1.5f); EXPECT(-2);
1028  CONVERT(VarI2FromR4, -0.6f); EXPECT(-1);
1029  CONVERT(VarI2FromR4, -0.5f); EXPECT(0);
1030  CONVERT(VarI2FromR4, -0.4f); EXPECT(0);
1031  CONVERT(VarI2FromR4, 0.4f); EXPECT(0);
1032  CONVERT(VarI2FromR4, 0.5f); EXPECT(0);
1033  CONVERT(VarI2FromR4, 0.6f); EXPECT(1);
1034  CONVERT(VarI2FromR4, 1.5f); EXPECT(2);
1035 }
1036 
1037 static void test_VarI2FromR8(void)
1038 {
1039  CONVVARS(DOUBLE);
1040 
1041  CONVERT(VarI2FromR8, -32769.0); EXPECT_OVERFLOW;
1042  CONVERT(VarI2FromR8, -32768.51); EXPECT_OVERFLOW;
1043  CONVERT(VarI2FromR8, -32768.5); EXPECT(-32768);
1044  CONVERT(VarI2FromR8, -32768.0); EXPECT(-32768);
1045  CONVERT(VarI2FromR8, -1.0); EXPECT(-1);
1046  CONVERT(VarI2FromR8, 0.0); EXPECT(0);
1047  CONVERT(VarI2FromR8, 1.0); EXPECT(1);
1048  CONVERT(VarI2FromR8, 32767.0); EXPECT(32767);
1049  CONVERT(VarI2FromR8, 32767.49); EXPECT(32767);
1050  CONVERT(VarI2FromR8, 32767.5); EXPECT_OVERFLOW;
1051  CONVERT(VarI2FromR8, 32768.0); EXPECT_OVERFLOW;
1052 
1053  /* Rounding */
1054  CONVERT(VarI2FromR8, -1.5); EXPECT(-2);
1055  CONVERT(VarI2FromR8, -0.6); EXPECT(-1);
1056  CONVERT(VarI2FromR8, -0.5); EXPECT(0);
1057  CONVERT(VarI2FromR8, -0.4); EXPECT(0);
1058  CONVERT(VarI2FromR8, 0.4); EXPECT(0);
1059  CONVERT(VarI2FromR8, 0.5); EXPECT(0);
1060  CONVERT(VarI2FromR8, 0.6); EXPECT(1);
1061  CONVERT(VarI2FromR8, 1.5); EXPECT(2);
1062 }
1063 
1064 static void test_VarI2FromDate(void)
1065 {
1066  CONVVARS(DATE);
1067 
1069  CONVERT(VarI2FromDate, -32768.0); EXPECT(-32768);
1070  CONVERT(VarI2FromDate, -1.0); EXPECT(-1);
1071  CONVERT(VarI2FromDate, 0.0); EXPECT(0);
1072  CONVERT(VarI2FromDate, 1.0); EXPECT(1);
1073  CONVERT(VarI2FromDate, 32767.0); EXPECT(32767);
1075 
1076  /* Rounding */
1077  CONVERT(VarI2FromDate, -1.5); EXPECT(-2);
1078  CONVERT(VarI2FromDate, -0.6); EXPECT(-1);
1079  CONVERT(VarI2FromDate, -0.5); EXPECT(0);
1080  CONVERT(VarI2FromDate, -0.4); EXPECT(0);
1081  CONVERT(VarI2FromDate, 0.4); EXPECT(0);
1082  CONVERT(VarI2FromDate, 0.5); EXPECT(0);
1083  CONVERT(VarI2FromDate, 0.6); EXPECT(1);
1084  CONVERT(VarI2FromDate, 1.5); EXPECT(2);
1085 }
1086 
1087 static void test_VarI2FromCy(void)
1088 {
1089  CONVVARS(CY);
1090 
1092  CONVERT_CY(VarI2FromCy,-32768); EXPECT(32768);
1093  CONVERT_CY(VarI2FromCy,-1); EXPECT(-1);
1094  CONVERT_CY(VarI2FromCy,0); EXPECT(0);
1095  CONVERT_CY(VarI2FromCy,1); EXPECT(1);
1096  CONVERT_CY(VarI2FromCy,32767); EXPECT(32767);
1098 
1099  /* Rounding */
1100  CONVERT_CY(VarI2FromCy,-1.5); EXPECT(-2);
1101  CONVERT_CY(VarI2FromCy,-0.6); EXPECT(-1);
1102  CONVERT_CY(VarI2FromCy,-0.5); EXPECT(0);
1103  CONVERT_CY(VarI2FromCy,-0.4); EXPECT(0);
1104  CONVERT_CY(VarI2FromCy,0.4); EXPECT(0);
1105  CONVERT_CY(VarI2FromCy,0.5); EXPECT(0);
1106  CONVERT_CY(VarI2FromCy,0.6); EXPECT(1);
1107  CONVERT_CY(VarI2FromCy,1.5); EXPECT(2);
1108 }
1109 
1110 static void test_VarI2FromDec(void)
1111 {
1112  CONVVARS(DECIMAL);
1113 
1115 
1116  CONVERT_DEC(VarI2FromDec,0,0x80,0,32769); EXPECT_OVERFLOW;
1117  CONVERT_DEC(VarI2FromDec,0,0x80,0,32768); EXPECT(-32768);
1118  CONVERT_DEC(VarI2FromDec,0,0x80,0,1); EXPECT(-1);
1119  CONVERT_DEC(VarI2FromDec,0,0,0,0); EXPECT(0);
1120  CONVERT_DEC(VarI2FromDec,0,0,0,1); EXPECT(1);
1121  CONVERT_DEC(VarI2FromDec,0,0,0,32767); EXPECT(32767);
1123 
1124  CONVERT_DEC(VarI2FromDec,2,0x80,0,3276800); EXPECT(-32768);
1125  CONVERT_DEC(VarI2FromDec,2,0,0,3276700); EXPECT(32767);
1126  CONVERT_DEC(VarI2FromDec,2,0,0,3276800); EXPECT_OVERFLOW;
1127 }
1128 
1129 static void test_VarI2FromStr(void)
1130 {
1131  CONVVARS(LCID);
1132  OLECHAR buff[128];
1133 
1135 
1137  CONVERT_STR(VarI2FromStr,"0", 0); EXPECT(0);
1139  CONVERT_STR(VarI2FromStr,"-32768", 0); EXPECT(-32768);
1140  CONVERT_STR(VarI2FromStr,"32767", 0); EXPECT(32767);
1142 
1143  /* Rounding */
1152 }
1153 
1154 static void test_VarI2Copy(void)
1155 {
1156  COPYTEST(1, VT_I2, V_I2(&vSrc), V_I2(&vDst), V_I2REF(&vSrc), V_I2REF(&vDst), "%d");
1157 }
1158 
1159 static void test_VarI2ChangeTypeEx(void)
1160 {
1161  HRESULT hres;
1162  SHORT in;
1163  VARIANTARG vSrc, vDst;
1164 
1165  in = 1;
1166 
1167  INITIAL_TYPETEST(VT_I2, V_I2, "%d");
1170 }
1171 
1172 #undef CONV_TYPE
1173 #define CONV_TYPE USHORT
1174 
1175 static void test_VarUI2FromI1(void)
1176 {
1177  CONVVARS(signed char);
1178  int i;
1179 
1180  OVERFLOWRANGE(VarUI2FromI1, -128, 0);
1181  CONVERTRANGE(VarUI2FromI1, 0, 128);
1182 }
1183 
1184 static void test_VarUI2FromI2(void)
1185 {
1186  CONVVARS(SHORT);
1187  int i;
1188 
1189  OVERFLOWRANGE(VarUI2FromI2, -32768, 0);
1190  CONVERTRANGE(VarUI2FromI2, 0, 32768);
1191 }
1192 
1193 static void test_VarUI2FromI4(void)
1194 {
1195  CONVVARS(LONG);
1196  int i;
1197 
1198  OVERFLOWRANGE(VarUI2FromI4, -32768, 0);
1199  CONVERT(VarUI2FromI4, 0); EXPECT(0);
1200  CONVERT(VarUI2FromI4, 65535); EXPECT(65535);
1202 }
1203 
1204 static void test_VarUI2FromI8(void)
1205 {
1206  CONVVARS(LONG64);
1207  int i;
1208 
1209  OVERFLOWRANGE(VarUI2FromI8, -32768, 0);
1210  CONVERT(VarUI2FromI8, 0); EXPECT(0);
1211  CONVERT(VarUI2FromI8, 65535); EXPECT(65535);
1213 }
1214 
1215 static void test_VarUI2FromUI1(void)
1216 {
1217  CONVVARS(BYTE);
1218  int i;
1219 
1220  CONVERTRANGE(VarUI2FromUI1, 0, 256);
1221 }
1222 
1223 static void test_VarUI2FromUI4(void)
1224 {
1225  CONVVARS(ULONG);
1226 
1227  CONVERT(VarUI2FromUI4, 0); EXPECT(0);
1228  CONVERT(VarUI2FromUI4, 65535); EXPECT(65535);
1230 }
1231 
1232 static void test_VarUI2FromUI8(void)
1233 {
1234  CONVVARS(ULONG64);
1235 
1236  CONVERT(VarUI2FromUI8, 0); EXPECT(0);
1237  CONVERT(VarUI2FromUI8, 65535); EXPECT(65535);
1239 }
1240 
1241 static void test_VarUI2FromBool(void)
1242 {
1244  int i;
1245 
1246  CONVERT(VarUI2FromBool, -1); EXPECT(65535); /* Wraps! */
1247  CONVERTRANGE(VarUI2FromBool, 0, 32768);
1248 }
1249 
1250 static void test_VarUI2FromR4(void)
1251 {
1252  CONVVARS(FLOAT);
1253 
1256  CONVERT(VarUI2FromR4, -0.5f); EXPECT(0);
1257  CONVERT(VarUI2FromR4, 0.0f); EXPECT(0);
1258  CONVERT(VarUI2FromR4, 1.0f); EXPECT(1);
1259  CONVERT(VarUI2FromR4, 65535.0f); EXPECT(65535);
1260  CONVERT(VarUI2FromR4, 65535.49f); EXPECT(65535);
1263 
1264  /* Rounding */
1267  CONVERT(VarUI2FromR4, -0.5f); EXPECT(0);
1268  CONVERT(VarUI2FromR4, -0.4f); EXPECT(0);
1269  CONVERT(VarUI2FromR4, 0.4f); EXPECT(0);
1270  CONVERT(VarUI2FromR4, 0.5f); EXPECT(0);
1271  CONVERT(VarUI2FromR4, 0.6f); EXPECT(1);
1272  CONVERT(VarUI2FromR4, 1.5f); EXPECT(2);
1273 }
1274 
1275 static void test_VarUI2FromR8(void)
1276 {
1277  CONVVARS(DOUBLE);
1278 
1281  CONVERT(VarUI2FromR8, -0.5); EXPECT(0);
1282  CONVERT(VarUI2FromR8, 0.0); EXPECT(0);
1283  CONVERT(VarUI2FromR8, 1.0); EXPECT(1);
1284  CONVERT(VarUI2FromR8, 65535.0); EXPECT(65535);
1285  CONVERT(VarUI2FromR8, 65535.49); EXPECT(65535);
1288 
1289  /* Rounding */
1292  CONVERT(VarUI2FromR8, -0.5); EXPECT(0);
1293  CONVERT(VarUI2FromR8, -0.4); EXPECT(0);
1294  CONVERT(VarUI2FromR8, 0.4); EXPECT(0);
1295  CONVERT(VarUI2FromR8, 0.5); EXPECT(0);
1296  CONVERT(VarUI2FromR8, 0.6); EXPECT(1);
1297  CONVERT(VarUI2FromR8, 1.5); EXPECT(2);
1298 }
1299 
1300 static void test_VarUI2FromDate(void)
1301 {
1302  CONVVARS(DATE);
1303 
1305  CONVERT(VarUI2FromDate, 0.0); EXPECT(0);
1306  CONVERT(VarUI2FromDate, 1.0); EXPECT(1);
1307  CONVERT(VarUI2FromDate, 65535.0); EXPECT(65535);
1309 
1310  /* Rounding */
1313  CONVERT(VarUI2FromDate, -0.5); EXPECT(0);
1314  CONVERT(VarUI2FromDate, -0.4); EXPECT(0);
1315  CONVERT(VarUI2FromDate, 0.4); EXPECT(0);
1316  CONVERT(VarUI2FromDate, 0.5); EXPECT(0);
1317  CONVERT(VarUI2FromDate, 0.6); EXPECT(1);
1318  CONVERT(VarUI2FromDate, 1.5); EXPECT(2);
1319 }
1320 
1321 static void test_VarUI2FromCy(void)
1322 {
1323  CONVVARS(CY);
1324 
1328  CONVERT_CY(VarUI2FromCy,65535); EXPECT(65535);
1330 
1331  /* Rounding */
1334  CONVERT_CY(VarUI2FromCy,-0.5); EXPECT(0);
1335  CONVERT_CY(VarUI2FromCy,-0.4); EXPECT(0);
1336  CONVERT_CY(VarUI2FromCy,0.4); EXPECT(0);
1337  CONVERT_CY(VarUI2FromCy,0.5); EXPECT(0);
1338  CONVERT_CY(VarUI2FromCy,0.6); EXPECT(1);
1339  CONVERT_CY(VarUI2FromCy,1.5); EXPECT(2);
1340 }
1341 
1342 static void test_VarUI2FromDec(void)
1343 {
1344  CONVVARS(DECIMAL);
1345 
1347 
1349  CONVERT_DEC(VarUI2FromDec,0,0,0,0); EXPECT(0);
1350  CONVERT_DEC(VarUI2FromDec,0,0,0,1); EXPECT(1);
1351  CONVERT_DEC(VarUI2FromDec,0,0,0,65535); EXPECT(65535);
1353 
1354  CONVERT_DEC(VarUI2FromDec,2,0x80,0,100); EXPECT_OVERFLOW;
1355  CONVERT_DEC(VarUI2FromDec,2,0,0,6553500); EXPECT(65535);
1356  CONVERT_DEC(VarUI2FromDec,2,0,0,6553600); EXPECT_OVERFLOW;
1357 }
1358 
1359 static void test_VarUI2FromStr(void)
1360 {
1361  CONVVARS(LCID);
1362  OLECHAR buff[128];
1363 
1365 
1367  CONVERT_STR(VarUI2FromStr,"0", 0); EXPECT(0);
1369  CONVERT_STR(VarUI2FromStr,"65535", 0); EXPECT(65535);
1371 
1372  /* Rounding */
1381 }
1382 
1383 static void test_VarUI2Copy(void)
1384 {
1385  COPYTEST(1, VT_UI2, V_UI2(&vSrc), V_UI2(&vDst), V_UI2REF(&vSrc), V_UI2REF(&vDst), "%d");
1386 }
1387 
1388 static void test_VarUI2ChangeTypeEx(void)
1389 {
1390  HRESULT hres;
1391  USHORT in;
1392  VARIANTARG vSrc, vDst;
1393 
1394  in = 1;
1395 
1396  INITIAL_TYPETEST(VT_UI2, V_UI2, "%d");
1399 }
1400 
1401 /*
1402  * VT_I4/VT_UI4
1403  */
1404 
1405 #undef CONV_TYPE
1406 #define CONV_TYPE LONG
1407 
1408 static void test_VarI4FromI1(void)
1409 {
1410  CONVVARS(signed char);
1411  int i;
1412 
1413  CONVERTRANGE(VarI4FromI1, -128, 128);
1414 }
1415 
1416 static void test_VarI4FromI2(void)
1417 {
1418  CONVVARS(SHORT);
1419  int i;
1420 
1421  CONVERTRANGE(VarI4FromI2, -32768, 32768);
1422 }
1423 
1424 static void test_VarI4FromI8(void)
1425 {
1426  CONVVARS(LONG64);
1427 
1428  CONVERT(VarI4FromI8, -1); EXPECT(-1);
1429  CONVERT(VarI4FromI8, 0); EXPECT(0);
1430  CONVERT(VarI4FromI8, 1); EXPECT(1);
1431 
1432  CONVERT_I8(VarI4FromI8, -1, 2147483647ul); EXPECT_OVERFLOW;
1433  CONVERT_I8(VarI4FromI8, -1, 2147483648ul); EXPECT(-2147483647 - 1);
1434  CONVERT_I8(VarI4FromI8, 0, 2147483647ul); EXPECT(2147483647);
1435  CONVERT_I8(VarI4FromI8, 0, 2147483648ul); EXPECT_OVERFLOW;
1436 }
1437 
1438 static void test_VarI4FromUI1(void)
1439 {
1440  CONVVARS(BYTE);
1441  int i;
1442 
1443  CONVERTRANGE(VarI4FromUI1, 0, 256);
1444 }
1445 
1446 static void test_VarI4FromUI2(void)
1447 {
1448  CONVVARS(USHORT);
1449  int i;
1450 
1451  CONVERTRANGE(VarI4FromUI2, 0, 65536);
1452 }
1453 
1454 static void test_VarI4FromUI4(void)
1455 {
1456  CONVVARS(ULONG);
1457 
1458  CONVERT(VarI4FromUI4, 0); EXPECT(0);
1459  CONVERT(VarI4FromUI4, 1); EXPECT(1);
1460  CONVERT(VarI4FromUI4, 2147483647); EXPECT(2147483647);
1461  CONVERT(VarI4FromUI4, 2147483648ul); EXPECT_OVERFLOW;
1462 }
1463 
1464 static void test_VarI4FromUI8(void)
1465 {
1466  CONVVARS(ULONG64);
1467 
1468  CONVERT(VarI4FromUI8, 0); EXPECT(0);
1469  CONVERT(VarI4FromUI8, 1); EXPECT(1);
1470  CONVERT(VarI4FromUI8, 2147483647); EXPECT(2147483647);
1471  CONVERT(VarI4FromUI8, 2147483648ul); EXPECT_OVERFLOW;
1472 }
1473 
1474 static void test_VarI4FromBool(void)
1475 {
1477  int i;
1478 
1479  CONVERTRANGE(VarI4FromBool, -32768, 32768);
1480 }
1481 
1482 static void test_VarI4FromR4(void)
1483 {
1484  CONVVARS(FLOAT);
1485 
1486  /* min/max values are not exactly representable in a float */
1487  CONVERT(VarI4FromR4, -1.0f); EXPECT(-1);
1488  CONVERT(VarI4FromR4, 0.0f); EXPECT(0);
1489  CONVERT(VarI4FromR4, 1.0f); EXPECT(1);
1490 
1491  CONVERT(VarI4FromR4, -1.5f); EXPECT(-2);
1492  CONVERT(VarI4FromR4, -0.6f); EXPECT(-1);
1493  CONVERT(VarI4FromR4, -0.5f); EXPECT(0);
1494  CONVERT(VarI4FromR4, -0.4f); EXPECT(0);
1495  CONVERT(VarI4FromR4, 0.4f); EXPECT(0);
1496  CONVERT(VarI4FromR4, 0.5f); EXPECT(0);
1497  CONVERT(VarI4FromR4, 0.6f); EXPECT(1);
1498  CONVERT(VarI4FromR4, 1.5f); EXPECT(2);
1499 }
1500 
1501 static void test_VarI4FromR8(void)
1502 {
1503  CONVVARS(DOUBLE);
1504 
1505  CONVERT(VarI4FromR8, -2147483649.0); EXPECT_OVERFLOW;
1506  CONVERT(VarI4FromR8, -2147483648.51); EXPECT_OVERFLOW;
1507  CONVERT(VarI4FromR8, -2147483648.5); EXPECT(-2147483647 - 1);
1508  CONVERT(VarI4FromR8, -2147483648.0); EXPECT(-2147483647 - 1);
1509  CONVERT(VarI4FromR8, -1.0); EXPECT(-1);
1510  CONVERT(VarI4FromR8, 0.0); EXPECT(0);
1511  CONVERT(VarI4FromR8, 1.0); EXPECT(1);
1512  CONVERT(VarI4FromR8, 2147483647.0); EXPECT(2147483647);
1513  CONVERT(VarI4FromR8, 2147483647.49); EXPECT(2147483647);
1514  CONVERT(VarI4FromR8, 2147483647.5); EXPECT_OVERFLOW;
1515  CONVERT(VarI4FromR8, 2147483648.0); EXPECT_OVERFLOW;
1516 
1517  CONVERT(VarI4FromR8, -1.5); EXPECT(-2);
1518  CONVERT(VarI4FromR8, -0.6); EXPECT(-1);
1519  CONVERT(VarI4FromR8, -0.5); EXPECT(0);
1520  CONVERT(VarI4FromR8, -0.4); EXPECT(0);
1521  CONVERT(VarI4FromR8, 0.4); EXPECT(0);
1522  CONVERT(VarI4FromR8, 0.5); EXPECT(0);
1523  CONVERT(VarI4FromR8, 0.6); EXPECT(1);
1524  CONVERT(VarI4FromR8, 1.5); EXPECT(2);
1525 }
1526 
1527 static void test_VarI4FromDate(void)
1528 {
1529  CONVVARS(DATE);
1530 
1531  CONVERT(VarI4FromDate, -2147483649.0); EXPECT_OVERFLOW;
1532  CONVERT(VarI4FromDate, -2147483648.0); EXPECT(-2147483647 - 1);
1533  CONVERT(VarI4FromDate, -1.0); EXPECT(-1);
1534  CONVERT(VarI4FromDate, 0.0); EXPECT(0);
1535  CONVERT(VarI4FromDate, 1.0); EXPECT(1);
1536  CONVERT(VarI4FromDate, 2147483647.0); EXPECT(2147483647);
1537  CONVERT(VarI4FromDate, 2147483648.0); EXPECT_OVERFLOW;
1538 
1539  CONVERT(VarI4FromDate, -1.5); EXPECT(-2);
1540  CONVERT(VarI4FromDate, -0.6); EXPECT(-1);
1541  CONVERT(VarI4FromDate, -0.5); EXPECT(0);
1542  CONVERT(VarI4FromDate, -0.4); EXPECT(0);
1543  CONVERT(VarI4FromDate, 0.4); EXPECT(0);
1544  CONVERT(VarI4FromDate, 0.5); EXPECT(0);
1545  CONVERT(VarI4FromDate, 0.6); EXPECT(1);
1546  CONVERT(VarI4FromDate, 1.5); EXPECT(2);
1547 }
1548 
1549 static void test_VarI4FromCy(void)
1550 {
1551  CONVVARS(CY);
1552 
1553  CONVERT_CY(VarI4FromCy,-1); EXPECT(-1);
1554  CONVERT_CY(VarI4FromCy,0); EXPECT(0);
1555  CONVERT_CY(VarI4FromCy,1); EXPECT(1);
1556 
1557  CONVERT_CY64(VarI4FromCy,-1,2147483647ul); EXPECT_OVERFLOW;
1558  CONVERT_CY64(VarI4FromCy,-1,2147483648ul); EXPECT(-2147483647 - 1);
1559  CONVERT_CY64(VarI4FromCy,0,2147483647ul); EXPECT(2147483647ul);
1560  CONVERT_CY64(VarI4FromCy,0,2147483648ul); EXPECT_OVERFLOW;
1561 
1562  CONVERT_CY(VarI4FromCy,-1.5); EXPECT(-2);
1563  CONVERT_CY(VarI4FromCy,-0.6); EXPECT(-1);
1564  CONVERT_CY(VarI4FromCy,-0.5); EXPECT(0);
1565  CONVERT_CY(VarI4FromCy,-0.4); EXPECT(0);
1566  CONVERT_CY(VarI4FromCy,0.4); EXPECT(0);
1567  CONVERT_CY(VarI4FromCy,0.5); EXPECT(0);
1568  CONVERT_CY(VarI4FromCy,0.6); EXPECT(1);
1569  CONVERT_CY(VarI4FromCy,1.5); EXPECT(2);
1570 }
1571 
1572 static void test_VarI4FromDec(void)
1573 {
1574  CONVVARS(DECIMAL);
1575 
1577 
1578  CONVERT_DEC(VarI4FromDec,0,0x80,0,1); EXPECT(-1);
1579  CONVERT_DEC(VarI4FromDec,0,0,0,0); EXPECT(0);
1580  CONVERT_DEC(VarI4FromDec,0,0,0,1); EXPECT(1);
1581 
1582  CONVERT_DEC64(VarI4FromDec,0,0x80,0,0,2147483649ul); EXPECT_OVERFLOW;
1583  CONVERT_DEC64(VarI4FromDec,0,0x80,0,0,2147483648ul); EXPECT(-2147483647 - 1);
1584  CONVERT_DEC64(VarI4FromDec,0,0,0,0,2147483647ul); EXPECT(2147483647ul);
1585  CONVERT_DEC64(VarI4FromDec,0,0,0,0,2147483648ul); EXPECT_OVERFLOW;
1586 
1587  CONVERT_DEC64(VarI4FromDec,2,0x80,0,50,100); EXPECT_OVERFLOW;
1588  CONVERT_DEC64(VarI4FromDec,2,0x80,0,50,0); EXPECT(-2147483647 - 1);
1589  CONVERT_DEC64(VarI4FromDec,2,0,0,49,4294967196ul); EXPECT(2147483647);
1591 }
1592 
1593 static void test_VarI4FromStr(void)
1594 {
1595  CONVVARS(LCID);
1596  OLECHAR buff[128];
1597 
1599 
1601  CONVERT_STR(VarI4FromStr,"0",0); EXPECT(0);
1602  CONVERT_STR(VarI4FromStr,"-2147483649",0); EXPECT_OVERFLOW;
1603  CONVERT_STR(VarI4FromStr,"-2147483648",0); EXPECT(-2147483647 -1);
1604  CONVERT_STR(VarI4FromStr,"2147483647",0); EXPECT(2147483647);
1605  CONVERT_STR(VarI4FromStr,"2147483648",0); EXPECT_OVERFLOW;
1606 
1607  /* Rounding */
1616 }
1617 
1618 static void test_VarI4Copy(void)
1619 {
1620  COPYTEST(1, VT_I4, V_I4(&vSrc), V_I4(&vDst), V_I4REF(&vSrc), V_I4REF(&vDst), "%d");
1621 }
1622 
1623 static void test_VarI4ChangeTypeEx(void)
1624 {
1625  HRESULT hres;
1626  LONG in;
1627  VARIANTARG vSrc, vDst;
1628 
1629  in = 1;
1630 
1631  INITIAL_TYPETEST(VT_I4, V_I4, "%d");
1634 }
1635 
1636 #undef CONV_TYPE
1637 #define CONV_TYPE ULONG
1638 #undef EXPECTRES
1639 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%u")
1640 
1641 static void test_VarUI4FromI1(void)
1642 {
1643  CONVVARS(signed char);
1644  int i;
1645 
1646  OVERFLOWRANGE(VarUI4FromI1, -127, 0);
1647  CONVERTRANGE(VarUI4FromI1, 0, 128);
1648 }
1649 
1650 static void test_VarUI4FromI2(void)
1651 {
1652  CONVVARS(SHORT);
1653  int i;
1654 
1655  OVERFLOWRANGE(VarUI4FromI2, -32768, 0);
1656  CONVERTRANGE(VarUI4FromI2, 0, 32768);
1657 }
1658 
1659 static void test_VarUI4FromUI2(void)
1660 {
1661  CONVVARS(USHORT);
1662  int i;
1663 
1664  CONVERTRANGE(VarUI4FromUI2, 0, 65536);
1665 }
1666 
1667 static void test_VarUI4FromI8(void)
1668 {
1669  CONVVARS(LONG64);
1670 
1672  CONVERT(VarUI4FromI8, 0); EXPECT(0);
1673  CONVERT(VarUI4FromI8, 1); EXPECT(1);
1674  CONVERT(VarUI4FromI8, 4294967295ul); EXPECT(4294967295ul);
1676 }
1677 
1678 static void test_VarUI4FromUI1(void)
1679 {
1680  CONVVARS(BYTE);
1681  int i;
1682 
1683  CONVERTRANGE(VarUI4FromUI1, 0, 256);
1684 }
1685 
1686 static void test_VarUI4FromI4(void)
1687 {
1688  CONVVARS(int);
1689 
1691  CONVERT(VarUI4FromI4, 0); EXPECT(0);
1692  CONVERT(VarUI4FromI4, 1); EXPECT(1);
1693  CONVERT(VarUI4FromI4, 2147483647); EXPECT(2147483647);
1694 }
1695 
1696 static void test_VarUI4FromUI8(void)
1697 {
1698  CONVVARS(ULONG64);
1699 
1700  CONVERT(VarUI4FromUI8, 0); EXPECT(0);
1701  CONVERT(VarUI4FromUI8, 1); EXPECT(1);
1702  CONVERT(VarUI4FromI8, 4294967295ul); EXPECT(4294967295ul);
1704 }
1705 
1706 static void test_VarUI4FromBool(void)
1707 {
1709  int i;
1710 
1711  CONVERTRANGE(VarUI4FromBool, -32768, 32768);
1712 }
1713 
1714 static void test_VarUI4FromR4(void)
1715 {
1716  CONVVARS(FLOAT);
1717 
1718  /* We can't test max values as they are not exactly representable in a float */
1721  CONVERT(VarUI4FromR4, -0.5f); EXPECT(0);
1722  CONVERT(VarUI4FromR4, 0.0f); EXPECT(0);
1723  CONVERT(VarUI4FromR4, 1.0f); EXPECT(1);
1724 
1727  CONVERT(VarUI4FromR4, -0.5f); EXPECT(0);
1728  CONVERT(VarUI4FromR4, -0.4f); EXPECT(0);
1729  CONVERT(VarUI4FromR4, 0.4f); EXPECT(0);
1730  CONVERT(VarUI4FromR4, 0.5f); EXPECT(0);
1731  CONVERT(VarUI4FromR4, 0.6f); EXPECT(1);
1732  CONVERT(VarUI4FromR4, 1.5f); EXPECT(2);
1733 
1734 }
1735 
1736 static void test_VarUI4FromR8(void)
1737 {
1738  CONVVARS(DOUBLE);
1739 
1742  CONVERT(VarUI4FromR4, -0.5f); EXPECT(0);
1743  CONVERT(VarUI4FromR8, 0.0); EXPECT(0);
1744  CONVERT(VarUI4FromR8, 1.0); EXPECT(1);
1745  CONVERT(VarUI4FromR8, 4294967295.0); EXPECT(4294967295ul);
1746  CONVERT(VarUI4FromR8, 4294967295.49); EXPECT(4294967295ul);
1747  CONVERT(VarUI4FromR8, 4294967295.5); EXPECT_OVERFLOW;
1748  CONVERT(VarUI4FromR8, 4294967296.0); EXPECT_OVERFLOW;
1749 
1752  CONVERT(VarUI4FromR8, -0.5); EXPECT(0);
1753  CONVERT(VarUI4FromR8, -0.4); EXPECT(0);
1754  CONVERT(VarUI4FromR8, 0.4); EXPECT(0);
1755  CONVERT(VarUI4FromR8, 0.5); EXPECT(0);
1756  CONVERT(VarUI4FromR8, 0.6); EXPECT(1);
1757  CONVERT(VarUI4FromR8, 1.5); EXPECT(2);
1758 }
1759 
1760 static void test_VarUI4FromDate(void)
1761 {
1762  CONVVARS(DOUBLE);
1763 
1765  CONVERT(VarUI4FromDate, 0.0); EXPECT(0);
1766  CONVERT(VarUI4FromDate, 1.0); EXPECT(1);
1767  CONVERT(VarUI4FromDate, 4294967295.0); EXPECT(4294967295ul);
1768  CONVERT(VarUI4FromDate, 4294967296.0); EXPECT_OVERFLOW;
1769 
1772  CONVERT(VarUI4FromDate, -0.5); EXPECT(0);
1773  CONVERT(VarUI4FromDate, -0.4); EXPECT(0);
1774  CONVERT(VarUI4FromDate, 0.4); EXPECT(0);
1775  CONVERT(VarUI4FromDate, 0.5); EXPECT(0);
1776  CONVERT(VarUI4FromDate, 0.6); EXPECT(1);
1777  CONVERT(VarUI4FromDate, 1.5); EXPECT(2);
1778 }
1779 
1780 static void test_VarUI4FromCy(void)
1781 {
1782  CONVVARS(CY);
1783 
1787  CONVERT_CY64(VarUI4FromCy,0,4294967295ul); EXPECT(4294967295ul);
1789 
1792  CONVERT_CY(VarUI4FromCy,-0.5); EXPECT(0);
1793  CONVERT_CY(VarUI4FromCy,-0.4); EXPECT(0);
1794  CONVERT_CY(VarUI4FromCy,0.4); EXPECT(0);
1795  CONVERT_CY(VarUI4FromCy,0.5); EXPECT(0);
1796  CONVERT_CY(VarUI4FromCy,0.6); EXPECT(1);
1797  CONVERT_CY(VarUI4FromCy,1.5); EXPECT(2);
1798 }
1799 
1800 static void test_VarUI4FromDec(void)
1801 {
1802  CONVVARS(DECIMAL);
1803 
1805 
1807  CONVERT_DEC(VarUI4FromDec,0,0,0,0); EXPECT(0);
1808  CONVERT_DEC(VarUI4FromDec,0,0,0,1); EXPECT(1);
1809  CONVERT_DEC64(VarUI4FromDec,0,0,0,0,4294967295ul); EXPECT(4294967295ul);
1811 
1812  CONVERT_DEC64(VarUI4FromDec,2,0,0,99,4294967196ul); EXPECT(4294967295ul);
1814 }
1815 
1816 static void test_VarUI4FromStr(void)
1817 {
1818  CONVVARS(LCID);
1819  OLECHAR buff[128];
1820 
1822 
1825  CONVERT_STR(VarUI4FromStr,"0",0); EXPECT(0);
1826  CONVERT_STR(VarUI4FromStr,"4294967295",0); EXPECT(4294967295ul);
1827  CONVERT_STR(VarUI4FromStr,"4294967296",0); EXPECT_OVERFLOW;
1828 
1829  /* Rounding */
1838 }
1839 
1840 static void test_VarUI4Copy(void)
1841 {
1842  COPYTEST(1u, VT_UI4, V_UI4(&vSrc), V_UI4(&vDst), V_UI4REF(&vSrc), V_UI4REF(&vDst), "%u");
1843 }
1844 
1845 static void test_VarUI4ChangeTypeEx(void)
1846 {
1847  HRESULT hres;
1848  ULONG in;
1849  VARIANTARG vSrc, vDst;
1850 
1851  in = 1;
1852 
1853  INITIAL_TYPETEST(VT_UI4, V_UI4, "%u");
1856 }
1857 
1858 /*
1859  * VT_I8/VT_UI8
1860  */
1861 
1862 #undef CONV_TYPE
1863 #define CONV_TYPE LONG64
1864 
1865 #define EXPECTI8(x) \
1866  ok((hres == S_OK && out == (CONV_TYPE)(x)), \
1867  "expected " #x "(%u,%u), got (%u,%u); hres=0x%08x\n", \
1868  (ULONG)((LONG64)(x) >> 32), (ULONG)((x) & 0xffffffff), \
1869  (ULONG)(out >> 32), (ULONG)(out & 0xffffffff), hres)
1870 
1871 #define EXPECTI864(x,y) \
1872  ok(hres == S_OK && (out >> 32) == (CONV_TYPE)(x) && (out & 0xffffffff) == (CONV_TYPE)(y), \
1873  "expected " #x "(%u,%u), got (%u,%u); hres=0x%08x\n", \
1874  (ULONG)(x), (ULONG)(y), \
1875  (ULONG)(out >> 32), (ULONG)(out & 0xffffffff), hres)
1876 
1877 static void test_VarI8FromI1(void)
1878 {
1879  CONVVARS(signed char);
1880  int i;
1881 
1882  for (i = -128; i < 128; i++)
1883  {
1885  }
1886 }
1887 
1888 static void test_VarI8FromUI1(void)
1889 {
1890  CONVVARS(BYTE);
1891  int i;
1892 
1893  for (i = 0; i < 256; i++)
1894  {
1896  }
1897 }
1898 
1899 static void test_VarI8FromI2(void)
1900 {
1901  CONVVARS(SHORT);
1902  int i;
1903 
1904  for (i = -32768; i < 32768; i++)
1905  {
1907  }
1908 }
1909 
1910 static void test_VarI8FromUI2(void)
1911 {
1912  CONVVARS(USHORT);
1913  int i;
1914 
1915  for (i = -0; i < 65535; i++)
1916  {
1918  }
1919 }
1920 
1921 static void test_VarI8FromUI4(void)
1922 {
1923  CONVVARS(ULONG);
1924 
1925  CONVERT(VarI8FromUI4, 0); EXPECTI8(0);
1926  CONVERT(VarI8FromUI4, 1); EXPECTI8(1);
1927  CONVERT(VarI8FromUI4, 4294967295ul); EXPECTI8(4294967295ul);
1928 }
1929 
1930 static void test_VarI8FromR4(void)
1931 {
1932  CONVVARS(FLOAT);
1933 
1934  CONVERT(VarI8FromR4, -128.0f); EXPECTI8(-128);
1935  CONVERT(VarI8FromR4, -1.0f); EXPECTI8(-1);
1936  CONVERT(VarI8FromR4, 0.0f); EXPECTI8(0);
1937  CONVERT(VarI8FromR4, 1.0f); EXPECTI8(1);
1938  CONVERT(VarI8FromR4, 127.0f); EXPECTI8(127);
1939 
1940  CONVERT(VarI8FromR4, -1.5f); EXPECTI8(-2);
1941  CONVERT(VarI8FromR4, -0.6f); EXPECTI8(-1);
1942  CONVERT(VarI8FromR4, -0.5f); EXPECTI8(0);
1943  CONVERT(VarI8FromR4, -0.4f); EXPECTI8(0);
1944  CONVERT(VarI8FromR4, 0.4f); EXPECTI8(0);
1945  CONVERT(VarI8FromR4, 0.5f); EXPECTI8(0);
1946  CONVERT(VarI8FromR4, 0.6f); EXPECTI8(1);
1947  CONVERT(VarI8FromR4, 1.5f); EXPECTI8(2);
1948 }
1949 
1950 static void test_VarI8FromR8(void)
1951 {
1952  CONVVARS(DOUBLE);
1953 
1954  CONVERT(VarI8FromR8, -128.0); EXPECTI8(-128);
1955  CONVERT(VarI8FromR8, -1.0); EXPECTI8(-1);
1956  CONVERT(VarI8FromR8, 0.0); EXPECTI8(0);
1957  CONVERT(VarI8FromR8, 1.0); EXPECTI8(1);
1958  CONVERT(VarI8FromR8, 127.0); EXPECTI8(127);
1959 
1960  CONVERT(VarI8FromR8, -1.5); EXPECTI8(-2);
1961  CONVERT(VarI8FromR8, -0.6); EXPECTI8(-1);
1962  CONVERT(VarI8FromR8, -0.5); EXPECTI8(0);
1963  CONVERT(VarI8FromR8, -0.4); EXPECTI8(0);
1964  CONVERT(VarI8FromR8, 0.4); EXPECTI8(0);
1965  CONVERT(VarI8FromR8, 0.5); EXPECTI8(0);
1966  CONVERT(VarI8FromR8, 0.6); EXPECTI8(1);
1967  CONVERT(VarI8FromR8, 1.5); EXPECTI8(2);
1968 }
1969 
1970 static void test_VarI8FromDate(void)
1971 {
1972  CONVVARS(DATE);
1973 
1974  CONVERT(VarI8FromDate, -128.0); EXPECTI8(-128);
1975  CONVERT(VarI8FromDate, -1.0); EXPECTI8(-1);
1976  CONVERT(VarI8FromDate, 0.0); EXPECTI8(0);
1977  CONVERT(VarI8FromDate, 1.0); EXPECTI8(1);
1978  CONVERT(VarI8FromDate, 127.0); EXPECTI8(127);
1979 
1980  CONVERT(VarI8FromDate, -1.5); EXPECTI8(-2);
1981  CONVERT(VarI8FromDate, -0.6); EXPECTI8(-1);
1982  CONVERT(VarI8FromDate, -0.5); EXPECTI8(0);
1983  CONVERT(VarI8FromDate, -0.4); EXPECTI8(0);
1984  CONVERT(VarI8FromDate, 0.4); EXPECTI8(0);
1985  CONVERT(VarI8FromDate, 0.5); EXPECTI8(0);
1986  CONVERT(VarI8FromDate, 0.6); EXPECTI8(1);
1987  CONVERT(VarI8FromDate, 1.5); EXPECTI8(2);
1988 }
1989 
1990 static void test_VarI8FromBool(void)
1991 {
1993  int i;
1994 
1995  for (i = -32768; i < 32768; i++)
1996  {
1998  }
1999 }
2000 
2001 static void test_VarI8FromUI8(void)
2002 {
2003  CONVVARS(ULONG64);
2004 
2005  CONVERT(VarI8FromUI8, 0); EXPECTI8(0);
2006  CONVERT(VarI8FromUI8, 1); EXPECTI8(1);
2007  CONVERT_I8(VarI8FromUI8, 0x7fffffff, 0xffffffff); EXPECTI864(0x7fffffff, 0xffffffff);
2008  CONVERT_I8(VarI8FromUI8, 0x80000000, 0); EXPECT_OVERFLOW;
2009 }
2010 
2011 static void test_VarI8FromCy(void)
2012 {
2013  CONVVARS(CY);
2014 
2015  CONVERT_CY(VarI8FromCy,-128); EXPECTI8(-129);
2016  CONVERT_CY(VarI8FromCy,-1); EXPECTI8(-2);
2019  CONVERT_CY(VarI8FromCy,127); EXPECTI8(127);
2020 
2021  CONVERT_CY(VarI8FromCy,-1.5); EXPECTI8(-2);
2022  CONVERT_CY(VarI8FromCy,-0.6); EXPECTI8(-1);
2023  CONVERT_CY(VarI8FromCy,-0.5); EXPECTI8(-1);
2024  CONVERT_CY(VarI8FromCy,-0.4); EXPECTI8(-1);
2025  CONVERT_CY(VarI8FromCy,0.4); EXPECTI8(0);
2026  CONVERT_CY(VarI8FromCy,0.5); EXPECTI8(0);
2027  CONVERT_CY(VarI8FromCy,0.6); EXPECTI8(1);
2028  CONVERT_CY(VarI8FromCy,1.5); EXPECTI8(2);
2029 }
2030 
2031 static void test_VarI8FromDec(void)
2032 {
2033  CONVVARS(DECIMAL);
2034 
2036 
2037  CONVERT_DEC(VarI8FromDec,0,0x80,0,128); EXPECTI8(-128);
2038  CONVERT_DEC(VarI8FromDec,0,0x80,0,1); EXPECTI8(-1);
2039  CONVERT_DEC(VarI8FromDec,0,0,0,0); EXPECTI8(0);
2040  CONVERT_DEC(VarI8FromDec,0,0,0,1); EXPECTI8(1);
2041  CONVERT_DEC(VarI8FromDec,0,0,0,127); EXPECTI8(127);
2042 
2043  CONVERT_DEC(VarI8FromDec,2,0x80,0,12700); EXPECTI8(-127);
2044  CONVERT_DEC(VarI8FromDec,2,0,0,12700); EXPECTI8(127);
2045 }
2046 
2047 static void test_VarI8FromStr(void)
2048 {
2049  CONVVARS(LCID);
2050  OLECHAR buff[128];
2051 
2053 
2055  CONVERT_STR(VarI8FromStr,"0",0); EXPECTI8(0);
2056  CONVERT_STR(VarI8FromStr,"-1",0); EXPECTI8(-1);
2057  CONVERT_STR(VarI8FromStr,"2147483647",0); EXPECTI8(2147483647);
2058 
2067 }
2068 
2069 static void test_VarI8Copy(void)
2070 {
2071  HRESULT hres;
2072  VARIANTARG vSrc, vDst;
2073  LONGLONG in = 1;
2074 
2075  if (!has_i8)
2076  {
2077  win_skip("I8 and UI8 data types are not available\n");
2078  return;
2079  }
2080 
2081  VariantInit(&vSrc);
2082  VariantInit(&vDst);
2083  V_VT(&vSrc) = VT_I8;
2084  V_I8(&vSrc) = in;
2085  hres = VariantCopy(&vDst, &vSrc);
2086  ok(hres == S_OK && V_VT(&vDst) == VT_I8 && V_I8(&vDst) == in,
2087  "copy hres 0x%X, type %d, value (%x%08x) %x%08x\n",
2088  hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_I8(&vDst) >> 32), (UINT)V_I8(&vDst) );
2089  V_VT(&vSrc) = VT_I8|VT_BYREF;
2090  V_I8REF(&vSrc) = &in;
2091  hres = VariantCopy(&vDst, &vSrc);
2092  ok(hres == S_OK && V_VT(&vDst) == (VT_I8|VT_BYREF) && V_I8REF(&vDst) == &in,
2093  "ref hres 0x%X, type %d, ref (%p) %p\n", hres, V_VT(&vDst), &in, V_I8REF(&vDst));
2094  hres = VariantCopyInd(&vDst, &vSrc);
2095  ok(hres == S_OK && V_VT(&vDst) == VT_I8 && V_I8(&vDst) == in,
2096  "copy hres 0x%X, type %d, value (%x%08x) %x%08x\n",
2097  hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_I8(&vDst) >> 32), (UINT)V_I8(&vDst) );
2098 }
2099 
2100 static void test_VarI8ChangeTypeEx(void)
2101 {
2102  HRESULT hres;
2103  LONG64 in;
2104  VARIANTARG vSrc, vDst;
2105 
2106  if (!has_i8)
2107  {
2108  win_skip("I8 and UI8 data types are not available\n");
2109  return;
2110  }
2111 
2112  in = 1;
2113 
2116 }
2117 
2118 /* Adapt the test macros to UI8 */
2119 #undef CONV_TYPE
2120 #define CONV_TYPE ULONG64
2121 
2122 static void test_VarUI8FromI1(void)
2123 {
2124  CONVVARS(signed char);
2125  int i;
2126 
2127  for (i = -128; i < 128; i++)
2128  {
2130  if (i < 0)
2132  else
2133  EXPECTI8(i);
2134  }
2135 }
2136 
2137 static void test_VarUI8FromUI1(void)
2138 {
2139  CONVVARS(BYTE);
2140  int i;
2141 
2142  for (i = 0; i < 256; i++)
2143  {
2145  }
2146 }
2147 
2148 static void test_VarUI8FromI2(void)
2149 {
2150  CONVVARS(SHORT);
2151  int i;
2152 
2153  for (i = -32768; i < 32768; i++)
2154  {
2156  if (i < 0)
2158  else
2159  EXPECTI8(i);
2160  }
2161 }
2162 
2163 static void test_VarUI8FromUI2(void)
2164 {
2165  CONVVARS(USHORT);
2166  int i;
2167 
2168  for (i = 0; i < 65535; i++)
2169  {
2171  }
2172 }
2173 
2174 static void test_VarUI8FromUI4(void)
2175 {
2176  CONVVARS(ULONG);
2177 
2178  CONVERT(VarUI8FromUI4, 0); EXPECTI8(0);
2179  CONVERT(VarUI8FromUI4, 0xffffffff); EXPECTI8(0xffffffff);
2180 }
2181 
2182 static void test_VarUI8FromR4(void)
2183 {
2184  CONVVARS(FLOAT);
2185 
2187  CONVERT(VarUI8FromR4, 0.0f); EXPECTI8(0);
2188  CONVERT(VarUI8FromR4, 1.0f); EXPECTI8(1);
2189  CONVERT(VarUI8FromR4, 255.0f); EXPECTI8(255);
2190 
2193  CONVERT(VarUI8FromR4, -0.5f); EXPECTI8(0);
2194  CONVERT(VarUI8FromR4, -0.4f); EXPECTI8(0);
2195  CONVERT(VarUI8FromR4, 0.4f); EXPECTI8(0);
2196  CONVERT(VarUI8FromR4, 0.5f); EXPECTI8(0);
2197  CONVERT(VarUI8FromR4, 0.6f); EXPECTI8(1);
2198  CONVERT(VarUI8FromR4, 1.5f); EXPECTI8(2);
2199 }
2200 
2201 static void test_VarUI8FromR8(void)
2202 {
2203  CONVVARS(DOUBLE);
2204 
2206  CONVERT(VarUI8FromR8, 0.0); EXPECTI8(0);
2207  CONVERT(VarUI8FromR8, 1.0); EXPECTI8(1);
2208  CONVERT(VarUI8FromR8, 255.0); EXPECTI8(255);
2209 
2212  CONVERT(VarUI8FromR8, -0.5); EXPECTI8(0);
2213  CONVERT(VarUI8FromR8, -0.4); EXPECTI8(0);
2214  CONVERT(VarUI8FromR8, 0.4); EXPECTI8(0);
2215  CONVERT(VarUI8FromR8, 0.5); EXPECTI8(0);
2216  CONVERT(VarUI8FromR8, 0.6); EXPECTI8(1);
2217  CONVERT(VarUI8FromR8, 1.5); EXPECTI8(2);
2218 }
2219 
2220 static void test_VarUI8FromDate(void)
2221 {
2222  CONVVARS(DATE);
2223 
2225  CONVERT(VarUI8FromDate, 0.0); EXPECTI8(0);
2226  CONVERT(VarUI8FromDate, 1.0); EXPECTI8(1);
2227  CONVERT(VarUI8FromDate, 255.0); EXPECTI8(255);
2228 
2231  CONVERT(VarUI8FromDate, -0.5); EXPECTI8(0);
2232  CONVERT(VarUI8FromDate, -0.4); EXPECTI8(0);
2233  CONVERT(VarUI8FromDate, 0.4); EXPECTI8(0);
2234  CONVERT(VarUI8FromDate, 0.5); EXPECTI8(0);
2235  CONVERT(VarUI8FromDate, 0.6); EXPECTI8(1);
2236  CONVERT(VarUI8FromDate, 1.5); EXPECTI8(2);
2237 }
2238 
2239 static void test_VarUI8FromBool(void)
2240 {
2242  int i;
2243 
2244  for (i = -32768; i < 32768; i++)
2245  {
2247  }
2248 }
2249 
2250 static void test_VarUI8FromI8(void)
2251 {
2252  CONVVARS(LONG64);
2253 
2255  CONVERT(VarUI8FromI8, 0); EXPECTI8(0);
2256  CONVERT(VarUI8FromI8, 1); EXPECTI8(1);
2257 }
2258 
2259 static void test_VarUI8FromCy(void)
2260 {
2261  CONVVARS(CY);
2262 
2266  CONVERT_CY(VarUI8FromCy,255); EXPECTI8(255);
2267 
2270  CONVERT_CY(VarUI8FromCy,-0.5); EXPECTI8(0);
2271  CONVERT_CY(VarUI8FromCy,-0.4); EXPECTI8(0);
2272  CONVERT_CY(VarUI8FromCy,0.4); EXPECTI8(0);
2273  CONVERT_CY(VarUI8FromCy,0.5); EXPECTI8(0);
2274  CONVERT_CY(VarUI8FromCy,0.6); EXPECTI8(1);
2275  CONVERT_CY(VarUI8FromCy,1.5); EXPECTI8(2);
2276 }
2277 
2278 static void test_VarUI8FromDec(void)
2279 {
2280  CONVVARS(DECIMAL);
2281 
2283 
2284  /* This returns 1 under native; Wine fixes this bug and returns overflow */
2285  if (0)
2286  {
2287  CONVERT_DEC(VarUI8FromDec,0,0x80,0,1);
2288  }
2289 
2290  CONVERT_DEC(VarUI8FromDec,0,0,0,0); EXPECTI8(0);
2291  CONVERT_DEC(VarUI8FromDec,0,0,0,1); EXPECTI8(1);
2292  CONVERT_DEC(VarUI8FromDec,0,0,0,255); EXPECTI8(255);
2293 
2294  CONVERT_DEC(VarUI8FromDec,2,0x80,0,100); EXPECT_OVERFLOW;
2295  CONVERT_DEC(VarUI8FromDec,2,0,0,25500); EXPECTI8(255);
2296 }
2297 
2298 static void test_VarUI8FromStr(void)
2299 {
2300  CONVVARS(LCID);
2301  OLECHAR buff[128];
2302 
2304 
2306  CONVERT_STR(VarUI8FromStr,"0",0); EXPECTI8(0);
2308  CONVERT_STR(VarUI8FromStr,"2147483647",0); EXPECTI8(2147483647);
2309  CONVERT_STR(VarUI8FromStr,"18446744073709551614",0); EXPECTI864(0xFFFFFFFF,0xFFFFFFFE);
2310  CONVERT_STR(VarUI8FromStr,"18446744073709551615",0); EXPECTI864(0xFFFFFFFF,0xFFFFFFFF);
2311  CONVERT_STR(VarUI8FromStr,"18446744073709551616",0); EXPECT_OVERFLOW;
2312 
2321 }
2322 
2323 static void test_VarUI8Copy(void)
2324 {
2325  HRESULT hres;
2326  VARIANTARG vSrc, vDst;
2327  ULONGLONG in = 1;
2328 
2329  if (!has_i8)
2330  {
2331  win_skip("I8 and UI8 data types are not available\n");
2332  return;
2333  }
2334 
2335  VariantInit(&vSrc);
2336  VariantInit(&vDst);
2337  V_VT(&vSrc) = VT_UI8;
2338  V_UI8(&vSrc) = in;
2339  hres = VariantCopy(&vDst, &vSrc);
2340  ok(hres == S_OK && V_VT(&vDst) == VT_UI8 && V_UI8(&vDst) == in,
2341  "copy hres 0x%X, type %d, value (%x%08x) %x%08x\n",
2342  hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_UI8(&vDst) >> 32), (UINT)V_UI8(&vDst) );
2343  V_VT(&vSrc) = VT_UI8|VT_BYREF;
2344  V_UI8REF(&vSrc) = &in;
2345  hres = VariantCopy(&vDst, &vSrc);
2346  ok(hres == S_OK && V_VT(&vDst) == (VT_UI8|VT_BYREF) && V_UI8REF(&vDst) == &in,
2347  "ref hres 0x%X, type %d, ref (%p) %p\n", hres, V_VT(&vDst), &in, V_UI8REF(&vDst));
2348  hres = VariantCopyInd(&vDst, &vSrc);
2349  ok(hres == S_OK && V_VT(&vDst) == VT_UI8 && V_UI8(&vDst) == in,
2350  "copy hres 0x%X, type %d, value (%x%08x) %x%08x\n",
2351  hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_UI8(&vDst) >> 32), (UINT)V_UI8(&vDst) );
2352 }
2353 
2354 static void test_VarUI8ChangeTypeEx(void)
2355 {
2356  HRESULT hres;
2357  ULONG64 in;
2358  VARIANTARG vSrc, vDst;
2359 
2360  if (!has_i8)
2361  {
2362  win_skip("I8 and UI8 data types are not available\n");
2363  return;
2364  }
2365 
2366  in = 1;
2367 
2370 }
2371 
2372 /*
2373  * VT_R4
2374  */
2375 
2376 #undef CONV_TYPE
2377 #define CONV_TYPE float
2378 #undef EXPECTRES
2379 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%15.15f")
2380 
2381 static void test_VarR4FromI1(void)
2382 {
2383  CONVVARS(signed char);
2384  int i;
2385 
2386  CONVERTRANGE(VarR4FromI1, -128, 128);
2387 }
2388 
2389 static void test_VarR4FromUI1(void)
2390 {
2391  CONVVARS(BYTE);
2392  int i;
2393 
2394  CONVERTRANGE(VarR4FromUI1, 0, 256);
2395 }
2396 
2397 static void test_VarR4FromI2(void)
2398 {
2399  CONVVARS(SHORT);
2400  int i;
2401 
2402  CONVERTRANGE(VarR4FromI2, -32768, 32768);
2403 }
2404 
2405 static void test_VarR4FromUI2(void)
2406 {
2407  CONVVARS(USHORT);
2408  int i;
2409 
2410  CONVERTRANGE(VarR4FromUI2, 0, 65536);
2411 }
2412 
2413 static void test_VarR4FromI4(void)
2414 {
2415  CONVVARS(int);
2416 
2417  CONVERT(VarR4FromI4, -2147483647-1); EXPECT(-2147483648.0f);
2418  CONVERT(VarR4FromI4, -1); EXPECT(-1.0f);
2419  CONVERT(VarR4FromI4, 0); EXPECT(0.0f);
2420  CONVERT(VarR4FromI4, 1); EXPECT(1.0f);
2421  CONVERT(VarR4FromI4, 2147483647); EXPECT(2147483647.0f);
2422 }
2423 
2424 static void test_VarR4FromUI4(void)
2425 {
2426  CONVVARS(unsigned int);
2427 
2428  CONVERT(VarR4FromUI4, 0); EXPECT(0.0f);
2429  CONVERT(VarR4FromUI4, 1); EXPECT(1.0f);
2430 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
2431  CONVERT(VarR4FromUI4, 0xffffffff); EXPECT(4294967296.0f);
2432 #endif
2433 }
2434 
2435 static void test_VarR4FromR8(void)
2436 {
2437  CONVVARS(FLOAT);
2438 
2439  CONVERT(VarR4FromR8, -1.0); EXPECT(-1.0f);
2440  CONVERT(VarR4FromR8, 0.0); EXPECT(0.0f);
2441  CONVERT(VarR4FromR8, 1.0); EXPECT(1.0f);
2442  CONVERT(VarR4FromR8, 1.5); EXPECT(1.5f);
2443 
2444  /* Skip rounding tests - no rounding is done */
2445 }
2446 
2447 static void test_VarR4FromBool(void)
2448 {
2450 
2451  CONVERT(VarR4FromBool, VARIANT_TRUE); EXPECT(VARIANT_TRUE * 1.0f);
2452  CONVERT(VarR4FromBool, VARIANT_FALSE); EXPECT(VARIANT_FALSE * 1.0f);
2453 }
2454 
2455 static void test_VarR4FromCy(void)
2456 {
2457  CONVVARS(CY);
2458 
2459  CONVERT_CY(VarR4FromCy,-32768); EXPECT(-32768.0f);
2460  CONVERT_CY(VarR4FromCy,-1); EXPECT(-1.0f);
2461  CONVERT_CY(VarR4FromCy,0); EXPECT(0.0f);
2462  CONVERT_CY(VarR4FromCy,1); EXPECT(1.0f);
2463  CONVERT_CY(VarR4FromCy,32768); EXPECT(32768.0f);
2464 
2465  CONVERT_CY(VarR4FromCy,-1.5); EXPECT(-1.5f);
2466  CONVERT_CY(VarR4FromCy,-0.6); EXPECT(-0.6f);
2467  CONVERT_CY(VarR4FromCy,-0.5); EXPECT(-0.5f);
2468  CONVERT_CY(VarR4FromCy,-0.4); EXPECT(-0.4f);
2469  CONVERT_CY(VarR4FromCy,0.4); EXPECT(0.4f);
2470  CONVERT_CY(VarR4FromCy,0.5); EXPECT(0.5f);
2471  CONVERT_CY(VarR4FromCy,0.6); EXPECT(0.6f);
2472  CONVERT_CY(VarR4FromCy,1.5); EXPECT(1.5f);
2473 }
2474 
2475 static void test_VarR4FromI8(void)
2476 {
2477  CONVVARS(LONG64);
2478 
2479  CONVERT(VarR4FromI8, -1); EXPECT(-1.0f);
2480  CONVERT(VarR4FromI8, 0); EXPECT(0.0f);
2481  CONVERT(VarR4FromI8, 1); EXPECT(1.0f);
2482 }
2483 
2484 static void test_VarR4FromUI8(void)
2485 {
2486  CONVVARS(ULONG64);
2487 
2488  CONVERT(VarR4FromUI8, 0); EXPECT(0.0f);
2489  CONVERT(VarR4FromUI8, 1); EXPECT(1.0f);
2490 }
2491 
2492 static void test_VarR4FromDec(void)
2493 {
2494  CONVVARS(DECIMAL);
2495 
2497 
2498  CONVERT_DEC(VarR4FromDec,0,0x80,0,32768); EXPECT(-32768.0f);
2499  CONVERT_DEC(VarR4FromDec,0,0x80,0,1); EXPECT(-1.0f);
2500  CONVERT_DEC(VarR4FromDec,0,0,0,0); EXPECT(0.0f);
2501  CONVERT_DEC(VarR4FromDec,0,0,0,1); EXPECT(1.0f);
2502  CONVERT_DEC(VarR4FromDec,0,0,0,32767); EXPECT(32767.0f);
2503 
2504  CONVERT_DEC(VarR4FromDec,2,0x80,0,3276800); EXPECT(-32768.0f);
2505  CONVERT_DEC(VarR4FromDec,2,0,0,3276700); EXPECT(32767.0f);
2506  CONVERT_DEC(VarR4FromDec,10,0,0,3276700); EXPECT(0.00032767f);
2507 
2508  CONVERT_DEC(VarR4FromDec,0,0,1,0); EXPECT(18446744073709551616.0f);
2509 }
2510 
2511 static void test_VarR4FromDate(void)
2512 {
2513  CONVVARS(DATE);
2514 
2515  CONVERT(VarR4FromDate, -1.0); EXPECT(-1.0f);
2516  CONVERT(VarR4FromDate, 0.0); EXPECT(0.0f);
2517  CONVERT(VarR4FromDate, 1.0); EXPECT(1.0f);
2518 }
2519 
2520 static void test_VarR4FromStr(void)
2521 {
2522  CONVVARS(LCID);
2523  OLECHAR buff[128];
2524 
2526 
2528  CONVERT_STR(VarR4FromStr,"-1", 0); EXPECT(-1.0f);
2529  CONVERT_STR(VarR4FromStr,"0", 0); EXPECT(0.0f);
2530  CONVERT_STR(VarR4FromStr,"1", 0); EXPECT(1.0f);
2531 
2540 }
2541 
2542 static void test_VarR4Copy(void)
2543 {
2544  COPYTEST(77665544.0f, VT_R4, V_R4(&vSrc), V_R4(&vDst), V_R4REF(&vSrc),V_R4REF(&vDst), "%15.15f");
2545 }
2546 
2547 static void test_VarR4ChangeTypeEx(void)
2548 {
2549 #ifdef HAS_UINT64_TO_FLOAT
2550  HRESULT hres;
2551  float in;
2552  VARIANTARG vSrc, vDst;
2553 
2554  in = 1.0f;
2555 
2556  INITIAL_TYPETEST(VT_R4, V_R4, "%f");
2558 #endif
2559 }
2560 
2561 /*
2562  * VT_R8
2563  */
2564 
2565 #undef CONV_TYPE
2566 #define CONV_TYPE double
2567 
2568 static void test_VarR8FromI1(void)
2569 {
2570  CONVVARS(signed char);
2571  int i;
2572 
2573  CONVERTRANGE(VarR8FromI1, -128, 128);
2574 }
2575 
2576 static void test_VarR8FromUI1(void)
2577 {
2578  CONVVARS(BYTE);
2579  int i;
2580 
2581  CONVERTRANGE(VarR8FromUI1, 0, 256);
2582 }
2583 
2584 static void test_VarR8FromI2(void)
2585 {
2586  CONVVARS(SHORT);
2587  int i;
2588 
2589  CONVERTRANGE(VarR8FromI2, -32768, 32768);
2590 }
2591 
2592 static void test_VarR8FromUI2(void)
2593 {
2594  CONVVARS(USHORT);
2595  int i;
2596 
2597  CONVERTRANGE(VarR8FromUI2, 0, 65536);
2598 }
2599 
2600 static void test_VarR8FromI4(void)
2601 {
2602  CONVVARS(int);
2603 
2604  CONVERT(VarR8FromI4, -2147483647-1); EXPECT(-2147483648.0);
2605  CONVERT(VarR8FromI4, -1); EXPECT(-1.0);
2606  CONVERT(VarR8FromI4, 0); EXPECT(0.0);
2607  CONVERT(VarR8FromI4, 1); EXPECT(1.0);
2608  CONVERT(VarR8FromI4, 0x7fffffff); EXPECT(2147483647.0);
2609 }
2610 
2611 static void test_VarR8FromUI4(void)
2612 {
2613  CONVVARS(unsigned int);
2614 
2615  CONVERT(VarR8FromUI4, 0); EXPECT(0.0);
2616  CONVERT(VarR8FromUI4, 1); EXPECT(1.0);
2617  CONVERT(VarR8FromUI4, 0xffffffff); EXPECT(4294967295.0);
2618 }
2619 
2620 static void test_VarR8FromR4(void)
2621 {
2622  CONVVARS(FLOAT);
2623 
2624  CONVERT(VarR8FromR4, -1.0f); EXPECT(-1.0);
2625  CONVERT(VarR8FromR4, 0.0f); EXPECT(0.0);
2626  CONVERT(VarR8FromR4, 1.0f); EXPECT(1.0);
2627  CONVERT(VarR8FromR4, 1.5f); EXPECT(1.5);
2628 
2629  /* Skip rounding tests - no rounding is done */
2630 }
2631 
2632 static void test_VarR8FromBool(void)
2633 {
2635 
2636  CONVERT(VarR8FromBool, VARIANT_TRUE); EXPECT(VARIANT_TRUE * 1.0);
2637  CONVERT(VarR8FromBool, VARIANT_FALSE); EXPECT(VARIANT_FALSE * 1.0);
2638 }
2639 
2640 static void test_VarR8FromCy(void)
2641 {
2642  CONVVARS(CY);
2643 
2644  CONVERT_CY(VarR8FromCy,-32769); EXPECT(-32769.0);
2645  CONVERT_CY(VarR8FromCy,-32768); EXPECT(-32768.0);
2646  CONVERT_CY(VarR8FromCy,-1); EXPECT(-1.0);
2647  CONVERT_CY(VarR8FromCy,0); EXPECT(0.0);
2648  CONVERT_CY(VarR8FromCy,1); EXPECT(1.0);
2649  CONVERT_CY(VarR8FromCy,32767); EXPECT(32767.0);
2650  CONVERT_CY(VarR8FromCy,32768); EXPECT(32768.0);
2651 
2652  CONVERT_CY(VarR8FromCy,-1.5); EXPECT(-1.5);
2653  CONVERT_CY(VarR8FromCy,-0.6); EXPECT(-0.6);
2654  CONVERT_CY(VarR8FromCy,-0.5); EXPECT(-0.5);
2655  CONVERT_CY(VarR8FromCy,-0.4); EXPECT(-0.4);
2656  CONVERT_CY(VarR8FromCy,0.4); EXPECT(0.4);
2657  CONVERT_CY(VarR8FromCy,0.5); EXPECT(0.5);
2658  CONVERT_CY(VarR8FromCy,0.6); EXPECT(0.6);
2659  CONVERT_CY(VarR8FromCy,1.5); EXPECT(1.5);
2660 }
2661 
2662 static void test_VarR8FromI8(void)
2663 {
2664  CONVVARS(LONG64);
2665 
2666  CONVERT(VarR8FromI8, -1); EXPECT(-1.0);
2667  CONVERT(VarR8FromI8, 0); EXPECT(0.0);
2668  CONVERT(VarR8FromI8, 1); EXPECT(1.0);
2669 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
2670  CONVERT_I8(VarR8FromI8, 0x7fffffff,0xffffffff); EXPECT(9223372036854775808.0);
2671 #endif
2672 }
2673 
2674 static void test_VarR8FromUI8(void)
2675 {
2676  CONVVARS(ULONG64);
2677 
2678  CONVERT(VarR8FromUI8, 0); EXPECT(0.0);
2679  CONVERT(VarR8FromUI8, 1); EXPECT(1.0);
2680 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
2681  CONVERT_I8(VarR8FromUI8, 0x80000000,0); EXPECT(9223372036854775808.0);
2682 #endif
2683 }
2684 
2685 static void test_VarR8FromDec(void)
2686 {
2687  CONVVARS(DECIMAL);
2688 
2690 
2691  CONVERT_DEC(VarR8FromDec,0,0x80,0,32768); EXPECT(-32768.0);
2692  CONVERT_DEC(VarR8FromDec,0,0x80,0,1); EXPECT(-1.0);
2693  CONVERT_DEC(VarR8FromDec,0,0,0,0); EXPECT(0.0);
2694  CONVERT_DEC(VarR8FromDec,0,0,0,1); EXPECT(1.0);
2695  CONVERT_DEC(VarR8FromDec,0,0,0,32767); EXPECT(32767.0);
2696 
2697  CONVERT_DEC(VarR8FromDec,2,0x80,0,3276800); EXPECT(-32768.0);
2698  CONVERT_DEC(VarR8FromDec,2,0,0,3276700); EXPECT(32767.0);
2699 
2700  CONVERT_DEC(VarR8FromDec,0,0,1,0); EXPECT(18446744073709551616.0);
2701 }
2702 
2703 static void test_VarR8FromDate(void)
2704 {
2705  CONVVARS(DATE);
2706 
2707  CONVERT(VarR8FromDate, -1.0); EXPECT(-1.0);
2708  CONVERT(VarR8FromDate, -0.0); EXPECT(0.0);
2709  CONVERT(VarR8FromDate, 1.0); EXPECT(1.0);
2710 }
2711 
2712 static void test_VarR8FromStr(void)
2713 {
2714  CONVVARS(LCID);
2715  OLECHAR buff[128];
2716 
2718 
2722 
2733 
2734  /* We already have exhaustive tests for number parsing, so skip those tests here */
2735 }
2736 
2737 static void test_VarR8Copy(void)
2738 {
2739  COPYTEST(77665544.0, VT_R8, V_R8(&vSrc), V_R8(&vDst), V_R8REF(&vSrc),V_R8REF(&vDst), "%16.16g");
2740 }
2741 
2742 static void test_VarR8ChangeTypeEx(void)
2743 {
2744 #ifdef HAS_UINT64_TO_FLOAT
2745  HRESULT hres;
2746  double in;
2747  VARIANTARG vSrc, vDst;
2748 
2749  in = 1.0;
2750 
2751  INITIAL_TYPETEST(VT_R8, V_R8, "%g");
2753 #endif
2754 }
2755 
2756 #define MATHRND(l, r) left = l; right = r; hres = VarR8Round(left, right, &out)
2757 
2758 static void test_VarR8Round(void)
2759 {
2760  HRESULT hres;
2761  double left = 0.0, out;
2762  int right;
2763 
2764  MATHRND(0.5432, 5); EXPECT(0.5432);
2765  MATHRND(0.5432, 4); EXPECT(0.5432);
2766  MATHRND(0.5432, 3); EXPECT(0.543);
2767  MATHRND(0.5432, 2); EXPECT(0.54);
2768  MATHRND(0.5432, 1); EXPECT(0.5);
2769  MATHRND(0.5532, 0); EXPECT(1);
2770  MATHRND(0.5532, -1); EXPECT_INVALID;
2771 
2772  MATHRND(0.5568, 5); EXPECT(0.5568);
2773  MATHRND(0.5568, 4); EXPECT(0.5568);
2774  MATHRND(0.5568, 3); EXPECT(0.557);
2775  MATHRND(0.5568, 2); EXPECT(0.56);
2776  MATHRND(0.5568, 1); EXPECT(0.6);
2777  MATHRND(0.5568, 0); EXPECT(1);
2778  MATHRND(0.5568, -1); EXPECT_INVALID;
2779 
2780  MATHRND(0.4999, 0); EXPECT(0);
2781  MATHRND(0.5000, 0); EXPECT(0);
2782  MATHRND(0.5001, 0); EXPECT(1);
2783  MATHRND(1.4999, 0); EXPECT(1);
2784  MATHRND(1.5000, 0); EXPECT(2);
2785  MATHRND(1.5001, 0); EXPECT(2);
2786 }
2787 
2788 /*
2789  * VT_DATE
2790  */
2791 
2792 #undef CONV_TYPE
2793 #define CONV_TYPE DATE
2794 
2795 static void test_VarDateFromI1(void)
2796 {
2797  CONVVARS(signed char);
2798  int i;
2799 
2800  CONVERTRANGE(VarDateFromI1, -128, 128);
2801 }
2802 
2803 static void test_VarDateFromUI1(void)
2804 {
2805  CONVVARS(BYTE);
2806  int i;
2807 
2808  CONVERTRANGE(VarDateFromUI1, 0, 256);
2809 }
2810 
2811 static void test_VarDateFromI2(void)
2812 {
2813  CONVVARS(SHORT);
2814  int i;
2815 
2816  CONVERTRANGE(VarDateFromI2, -32768, 32768);
2817 }
2818 
2819 static void test_VarDateFromUI2(void)
2820 {
2821  CONVVARS(USHORT);
2822  int i;
2823 
2824  CONVERTRANGE(VarDateFromUI2, 0, 65536);
2825 }
2826 
2827 static void test_VarDateFromI4(void)
2828 {
2829  CONVVARS(int);
2830 
2832  if (hres != DISP_E_TYPEMISMATCH) /* Early versions return this, incorrectly */
2835  CONVERT(VarDateFromI4, -1); EXPECT(-1.0);
2836  CONVERT(VarDateFromI4, 0); EXPECT(0.0);
2837  CONVERT(VarDateFromI4, 1); EXPECT(1.0);
2840  if (hres != DISP_E_TYPEMISMATCH) /* Early versions return this, incorrectly */
2842 }
2843 
2844 static void test_VarDateFromUI4(void)
2845 {
2846  CONVVARS(unsigned int);
2847 
2848  CONVERT(VarDateFromUI4, 0); EXPECT(0.0);
2849  CONVERT(VarDateFromUI4, 1); EXPECT(1.0);
2852  if (hres != DISP_E_TYPEMISMATCH) /* Early versions return this, incorrectly */
2854 }
2855 
2856 static void test_VarDateFromR4(void)
2857 {
2858  CONVVARS(FLOAT);
2859 
2860  CONVERT(VarDateFromR4, -1.0f); EXPECT(-1.0);
2861  CONVERT(VarDateFromR4, 0.0f); EXPECT(0.0);
2862  CONVERT(VarDateFromR4, 1.0f); EXPECT(1.0);
2863  CONVERT(VarDateFromR4, 1.5f); EXPECT(1.5);
2864 }
2865 
2866 static void test_VarDateFromR8(void)
2867 {
2868  CONVVARS(double);
2869 
2870  CONVERT(VarDateFromR8, -1.0f); EXPECT(-1.0);
2871  CONVERT(VarDateFromR8, 0.0f); EXPECT(0.0);
2872  CONVERT(VarDateFromR8, 1.0f); EXPECT(1.0);
2873  CONVERT(VarDateFromR8, 1.5f); EXPECT(1.5);
2874 }
2875 
2876 static void test_VarDateFromBool(void)
2877 {
2879 
2880  CONVERT(VarDateFromBool, VARIANT_TRUE); EXPECT(VARIANT_TRUE * 1.0);
2881  CONVERT(VarDateFromBool, VARIANT_FALSE); EXPECT(VARIANT_FALSE * 1.0);
2882 }
2883 
2884 static void test_VarDateFromCy(void)
2885 {
2886  CONVVARS(CY);
2887 
2888  CONVERT_CY(VarDateFromCy,-32769); EXPECT(-32769.0);
2889  CONVERT_CY(VarDateFromCy,-32768); EXPECT(-32768.0);
2890  CONVERT_CY(VarDateFromCy,-1); EXPECT(-1.0);
2891  CONVERT_CY(VarDateFromCy,0); EXPECT(0.0);
2892  CONVERT_CY(VarDateFromCy,1); EXPECT(1.0);
2893  CONVERT_CY(VarDateFromCy,32767); EXPECT(32767.0);
2894  CONVERT_CY(VarDateFromCy,32768); EXPECT(32768.0);
2895 
2896  CONVERT_CY(VarDateFromCy,-1.5); EXPECT(-1.5);
2897  CONVERT_CY(VarDateFromCy,-0.6); EXPECT(-0.6);
2898  CONVERT_CY(VarDateFromCy,-0.5); EXPECT(-0.5);
2899  CONVERT_CY(VarDateFromCy,-0.4); EXPECT(-0.4);
2900  CONVERT_CY(VarDateFromCy,0.4); EXPECT(0.4);
2901  CONVERT_CY(VarDateFromCy,0.5); EXPECT(0.5);
2902  CONVERT_CY(VarDateFromCy,0.6); EXPECT(0.6);
2903  CONVERT_CY(VarDateFromCy,1.5); EXPECT(1.5);
2904 }
2905 
2906 static void test_VarDateFromI8(void)
2907 {
2908  CONVVARS(LONG64);
2909 
2912  CONVERT(VarDateFromI8, -1); EXPECT(-1.0);
2913  CONVERT(VarDateFromI8, 0); EXPECT(0.0);
2914  CONVERT(VarDateFromI8, 1); EXPECT(1.0);
2917 }
2918 
2919 static void test_VarDateFromUI8(void)
2920 {
2921  CONVVARS(ULONG64);
2922 
2923  CONVERT(VarDateFromUI8, 0); EXPECT(0.0);
2924  CONVERT(VarDateFromUI8, 1); EXPECT(1.0);
2927 }
2928 
2929 static void test_VarDateFromDec(void)
2930 {
2931  CONVVARS(DECIMAL);
2932 
2934 
2935  CONVERT_DEC(VarDateFromDec,0,0x80,0,32768); EXPECT(-32768.0);
2936  CONVERT_DEC(VarDateFromDec,0,0x80,0,1); EXPECT(-1.0);
2937  CONVERT_DEC(VarDateFromDec,0,0,0,0); EXPECT(0.0);
2938  CONVERT_DEC(VarDateFromDec,0,0,0,1); EXPECT(1.0);
2939  CONVERT_DEC(VarDateFromDec,0,0,0,32767); EXPECT(32767.0);
2940 
2941  CONVERT_DEC(VarDateFromDec,2,0x80,0,3276800); EXPECT(-32768.0);
2942  CONVERT_DEC(VarDateFromDec,2,0,0,3276700); EXPECT(32767.0);
2943 }
2944 
2945 #define DFS(str) \
2946  buff[0] = '\0'; out = 0.0; \
2947  if (str) MultiByteToWideChar(CP_ACP,0,str,-1,buff,ARRAY_SIZE(buff)); \
2948  hres = VarDateFromStr(str ? buff : NULL,lcid,LOCALE_NOUSEROVERRIDE,&out)
2949 
2950 #define MKRELDATE(day,mth) st.wMonth = mth; st.wDay = day; \
2951  SystemTimeToVariantTime(&st,&relative)
2952 
2953 static const char * const BadDateStrings[] =
2954 {
2955  "True", "False", /* Plain text */
2956  "0.", ".0", "-1.1", "1.1-", /* Partial specifications */
2957  "1;2;3", "1*2*3", "1@2@3", "1#2#3", "(1:2)","<1:2>","1|2|3", /* Bad chars */
2958  "0", "1", /* 1 element */
2959  "0.60", "24.00", "0:60", "24:00", "1 2 am", "1 am 2", /* 2 elements */
2960  "1.5 2", "1 5.2", "2 32 3", "1 2 am 3", /* 3 elements */
2961  "1 2.3 4", "1.2.3 4", "1 2.3.4", "1.2 3.4", "1.2.3.4", "1 2 3 4",
2962  "1 am 2 3.4", "1 2 am 3.4", "1.2 3 am 4", "1.2 3 4 am", /* 4 elements */
2963  "1.2.3.4.5", "1.2.3.4 5", "1.2.3 4.5", "1.2 3.4.5", "1.2 3.4 5", "1.2 3 4.5",
2964  "1 2.3.4.5", "1 2.3.4 5", "1 2.3 4.5", "1 2.3 4 5", "1 2 3.4 5", "1 2 3 4 5",
2965  "1.2.3 4 am 5", "1.2.3 4 5 am", "1.2 3 am 4 5",
2966  "1.2 3 4 am 5", "1.2 3 4 5 am", "1 am 2 3.4.5", "1 2 am 3.4.5",
2967  "1 am 2 3 4.5", "1 2 am 3 4.5", "1 2 3 am 4.5", /* 5 elements */
2968  /* 6 elements */
2969  "1.2.3.4.5.6", "1.2.3.4.5 6", "1.2.3.4 5.6", "1.2.3.4 5 6", "1.2.3 4.5.6",
2970  "1.2.3 4.5 6", "1.2.3 4 5.6", "1.2 3.4.5.6", "1.2 3.4.5 6", "1.2 3.4 5.6",
2971  "1.2 3.4 5 6", "1.2 3 4.5.6", "1.2 3 4.5 6", "1.2 3 4 5.6", "1.2 3 4 5 6",
2972  "1 2.3.4.5.6", "1 2.3.4.5 6", "1 2.3.4 5.6", "1 2.3.4 5 6", "1 2.3 4.5.6",
2973 #if 0
2974  /* following throws an exception on winME */
2975  "1 2.3 4.5 6", "1 2.3 4 5.6", "1 2.3 4 5 6", "1 2 3.4.5.6", "1 2 3.4.5 6",
2976 #endif
2977  "1 2 3.4 5.6", "1 2 3.4 5 6", "1 2 3 4.5 6", "1 2 3 4 5.6", "1 2 3 4 5 6",
2978 #if 0
2979  /* following throws an exception on winME */
2980  "1.2.3 4 am 5 6", "1.2.3 4 5 am 6", "1.2.3 4 5 6 am", "1 am 2 3 4.5.6",
2981 #endif
2982  "1 2 am 3 4.5.6", "1 2 3 am 4.5.6"
2983 };
2984 
2985 static void test_VarDateFromStr(void)
2986 {
2987  LCID lcid;
2988  DATE out, relative;
2989  HRESULT hres;
2990  SYSTEMTIME st;
2991  OLECHAR buff[128];
2992  size_t i;
2993  OLECHAR with_ideographic_spaceW[] = { '6','/','3','0','/','2','0','1','1',0x3000,
2994  '1',':','2','0',':','3','4',0 };
2995 
2997 
2998  /* Some date formats are relative, so we need to find the current year */
2999  GetSystemTime(&st);
3000  st.wHour = st.wMinute = st.wSecond = st.wMilliseconds = 0;
3002 
3003  /* Floating point number are not recognised */
3004  DFS("0.0");
3005  if (hres == S_OK)
3006  EXPECT_DBL(0.0); /* Very old versions accept this string */
3007  else
3009 
3010  /* 1 element - can only be a time, and only if it has am/pm */
3011  DFS("1 am"); EXPECT_DBL(0.04166666666666666);
3012  /* 2 elements */
3013  /* A decimal point is treated as a time separator.
3014  * The following are converted as hours/minutes.
3015  */
3016  DFS("0.1"); EXPECT_DBL(0.0006944444444444445);
3017  DFS("0.40"); EXPECT_DBL(0.02777777777777778);
3018  DFS("2.5"); EXPECT_DBL(0.08680555555555555);
3019  /* A colon acts as a decimal point */
3020  DFS("0:1"); EXPECT_DBL(0.0006944444444444445);
3021  DFS("0:20"); EXPECT_DBL(0.01388888888888889);
3022  DFS("0:40"); EXPECT_DBL(0.02777777777777778);
3023  DFS("3:5"); EXPECT_DBL(0.1284722222222222);
3024  /* Check the am/pm limits */
3025  DFS("00:00 AM"); EXPECT_DBL(0.0);
3026  DFS("00:00 a"); EXPECT_DBL(0.0);
3027  DFS("12:59 AM"); EXPECT_DBL(0.04097222222222222);
3028  DFS("12:59 A"); EXPECT_DBL(0.04097222222222222);
3029  DFS("00:00 pm"); EXPECT_DBL(0.5);
3030  DFS("00:00 p"); EXPECT_DBL(0.5);
3031  DFS("12:59 pm"); EXPECT_DBL(0.5409722222222222);
3032  DFS("12:59 p"); EXPECT_DBL(0.5409722222222222);
3033  /* AM/PM is ignored if hours > 12 */
3034  DFS("13:00 AM"); EXPECT_DBL(0.5416666666666666);
3035  DFS("13:00 PM"); EXPECT_DBL(0.5416666666666666);
3036 
3037  /* Space, dash and slash all indicate a date format. */
3038  /* If both numbers are valid month values => month/day of current year */
3039  DFS("1 2"); MKRELDATE(2,1); EXPECT_DBL(relative);
3040  DFS("2 1"); MKRELDATE(1,2); EXPECT_DBL(relative);
3041  /* one number not valid month, is a valid day, other number valid month:
3042  * that number becomes the day.
3043  */
3044  DFS("14 1"); MKRELDATE(14,1); EXPECT_DBL(relative);
3045  DFS("1 14"); EXPECT_DBL(relative);
3046  /* If the numbers can't be day/month, they are assumed to be year/month */
3047  DFS("30 2"); EXPECT_DBL(10990.0);
3048  DFS("2 30"); EXPECT_DBL(10990.0);
3049  DFS("32 49"); EXPECT_MISMATCH; /* Can't be any format */
3050  DFS("0 49"); EXPECT_MISMATCH; /* Can't be any format */
3051  /* If a month name is given the other number is the day */
3052  DFS("Jan 2"); MKRELDATE(2,1); EXPECT_DBL(relative);
3053  DFS("2 Jan"); EXPECT_DBL(relative);
3054  /* Unless it can't be, in which case it becomes the year */
3055  DFS("Jan 35"); EXPECT_DBL(12785.0);
3056  DFS("35 Jan"); EXPECT_DBL(12785.0);
3057  DFS("Jan-35"); EXPECT_DBL(12785.0);
3058  DFS("35-Jan"); EXPECT_DBL(12785.0);
3059  DFS("Jan/35"); EXPECT_DBL(12785.0);
3060  DFS("35/Jan"); EXPECT_DBL(12785.0);
3061  /* 3 elements */
3062  /* 3 numbers and time separator => h:m:s */
3063  DFS("0.1.0"); EXPECT_DBL(0.0006944444444444445);
3064  DFS("1.5.2"); EXPECT_DBL(0.04516203703703704);
3065  /* 3 numbers => picks date giving preference to lcid format */
3066  DFS("1 2 3"); EXPECT_DBL(37623.0);
3067  DFS("14 2 3"); EXPECT_DBL(41673.0);
3068  DFS("2 14 3"); EXPECT_DBL(37666.0);
3069  DFS("2 3 14"); EXPECT_DBL(41673.0);
3070  DFS("32 2 3"); EXPECT_DBL(11722.0);
3071  DFS("2 3 32"); EXPECT_DBL(11722.0);
3072  DFS("1 2 29"); EXPECT_DBL(47120.0);
3073  /* After 30, two digit dates are expected to be in the 1900's */
3074  DFS("1 2 30"); EXPECT_DBL(10960.0);
3075  DFS("1 2 31"); EXPECT_DBL(11325.0);
3076  DFS("3 am 1 2"); MKRELDATE(2,1); relative += 0.125; EXPECT_DBL(relative);
3077  DFS("1 2 3 am"); EXPECT_DBL(relative);
3078 
3079  /* 4 elements -interpreted as 2 digit date & time */
3080  DFS("1.2 3 4"); MKRELDATE(4,3); relative += 0.04305555556; EXPECT_DBL(relative);
3081  DFS("3 4 1.2"); EXPECT_DBL(relative);
3082  /* 5 elements - interpreted as 2 & 3 digit date/times */
3083  DFS("1.2.3 4 5"); MKRELDATE(5,4); relative += 0.04309027778; EXPECT_DBL(relative);
3084  DFS("1.2 3 4 5"); EXPECT_DBL(38415.04305555556);
3085 #if 0
3086  /* following throws an exception on winME */
3087  DFS("1 2 3.4.5"); MKRELDATE(2,1); relative += 0.12783564815; EXPECT_DBL(relative);
3088 #endif
3089  DFS("1 2 3 4.5"); EXPECT_DBL(37623.17013888889);
3090  /* 6 elements - interpreted as 3 digit date/times */
3091  DFS("1.2.3 4 5 6"); EXPECT_DBL(38812.04309027778);
3092  DFS("1 2 3 4.5.6"); EXPECT_DBL(37623.17020833334);
3093 
3094  for (i = 0; i < ARRAY_SIZE(BadDateStrings); i++)
3095  {
3097  }
3098 
3099  /* Some normal-ish strings */
3100  DFS("2 January, 1970"); EXPECT_DBL(25570.0);
3101  DFS("2 January 1970"); EXPECT_DBL(25570.0);
3102  DFS("2 Jan 1970"); EXPECT_DBL(25570.0);
3103  DFS("2/Jan/1970"); EXPECT_DBL(25570.0);
3104  DFS("2-Jan-1970"); EXPECT_DBL(25570.0);
3105  DFS("1 2 1970"); EXPECT_DBL(25570.0);
3106  DFS("1/2/1970"); EXPECT_DBL(25570.0);
3107  DFS("1-2-1970"); EXPECT_DBL(25570.0);
3108  DFS("13-1-1970"); EXPECT_DBL(25581.0);
3109  DFS("1970-1-13"); EXPECT_DBL(25581.0);
3110  DFS("6/30/2011 01:20:34"); EXPECT_DBL(40724.05594907407);
3111  DFS("6/30/2011 01:20:34 AM"); EXPECT_DBL(40724.05594907407);
3112  DFS("6/30/2011 01:20:34 PM"); EXPECT_DBL(40724.55594907407);
3113  DFS("2013-05-14 02:04:12"); EXPECT_DBL(41408.08625000001);
3114  DFS("2013-05-14 02:04:12.017000000"); EXPECT_MISMATCH;
3115  /* Native fails "1999 January 3, 9AM". I consider that a bug in native */
3116 
3117  /* test a data with ideographic space */
3118  out = 0.0;
3119  hres = VarDateFromStr(with_ideographic_spaceW, lcid, LOCALE_NOUSEROVERRIDE, &out);
3120  EXPECT_DBL(40724.05594907407);
3121 
3122  /* test a non-english data string */
3123  DFS("02.01.1970"); EXPECT_MISMATCH;
3124  DFS("02.01.1970 00:00:00"); EXPECT_MISMATCH;
3126  DFS("02.01.1970"); EXPECT_DBL(25570.0);
3127  DFS("02.13.1970"); EXPECT_DBL(25612.0);
3128  DFS("02-13-1970"); EXPECT_DBL(25612.0);
3129  DFS("2020-01-11"); EXPECT_DBL(43841.0);
3130  DFS("2173-10-14"); EXPECT_DBL(100000.0);
3131 
3132  DFS("02.01.1970 00:00:00"); EXPECT_DBL(25570.0);
3134  DFS("02.01.1970"); EXPECT_MISMATCH;
3135  DFS("02.01.1970 00:00:00"); EXPECT_MISMATCH;
3136 }
3137 
3138 static void test_VarDateCopy(void)
3139 {
3140  COPYTEST(77665544.0, VT_DATE, V_DATE(&vSrc), V_DATE(&vDst), V_DATEREF(&vSrc),
3141  V_DATEREF(&vDst), "%16.16g");
3142 }
3143 
3144 static const char* wtoascii(LPWSTR lpszIn)
3145 {
3146  static char buff[256];
3147  WideCharToMultiByte(CP_ACP, 0, lpszIn, -1, buff, sizeof(buff), NULL, NULL);
3148  return buff;
3149 }
3150 
3151 static void test_VarDateChangeTypeEx(void)
3152 {
3153  static const WCHAR sz25570[] = {
3154  '1','/','2','/','1','9','7','0','\0' };
3155  static const WCHAR sz25570_2[] = {
3156  '1','/','2','/','7','0','\0' };
3157  static const WCHAR sz25570Nls[] = {
3158  '1','/','2','/','1','9','7','0',' ','1','2',':','0','0',':','0','0',' ','A','M','\0' };
3159  HRESULT hres;
3160  DATE in;
3161  VARIANTARG vSrc, vDst;
3162  LCID lcid;
3163 
3164  in = 1.0;
3165 
3166 #ifdef HAS_UINT64_TO_FLOAT
3169 #endif
3170 
3171  V_VT(&vDst) = VT_EMPTY;
3172  V_VT(&vSrc) = VT_DATE;
3173  V_DATE(&vSrc) = 25570.0;
3175 
3176  hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, VARIANT_NOUSEROVERRIDE, VT_BSTR);
3177  ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && V_BSTR(&vDst) &&
3178  (!lstrcmpW(V_BSTR(&vDst), sz25570) || !lstrcmpW(V_BSTR(&vDst), sz25570_2)),
3179  "hres=0x%X, type=%d (should be VT_BSTR), *bstr=%s\n",
3180  hres, V_VT(&vDst), V_BSTR(&vDst) ? wtoascii(V_BSTR(&vDst)) : "?");
3181  VariantClear(&vDst);
3182 
3184  if (has_locales)
3185  {
3187  ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && V_BSTR(&vDst) && !lstrcmpW(V_BSTR(&vDst), sz25570Nls),
3188  "hres=0x%X, type=%d (should be VT_BSTR), *bstr=%s\n",
3189  hres, V_VT(&vDst), V_BSTR(&vDst) ? wtoascii(V_BSTR(&vDst)) : "?");
3190  VariantClear(&vDst);
3191  }
3192 }
3193 
3194 /*
3195  * VT_CY
3196  */
3197 
3198 #undef CONV_TYPE
3199 #define CONV_TYPE CY
3200 
3201 #define EXPECTCY(x) \
3202  ok((hres == S_OK && out.int64 == (LONGLONG)(x*CY_MULTIPLIER)), \
3203  "expected " #x "*CY_MULTIPLIER, got (%8x %8x); hres=0x%08x\n", S(out).Hi, S(out).Lo, hres)
3204 
3205 #define EXPECTCY64(x,y) \
3206  ok(hres == S_OK && S(out).Hi == (LONG)x && S(out).Lo == y, \
3207  "expected " #x " " #y " (%u,%u), got (%u,%u); hres=0x%08x\n", \
3208  (ULONG)(x), (ULONG)(y), S(out).Hi, S(out).Lo, hres)
3209 
3210 static void test_VarCyFromI1(void)
3211 {
3212  CONVVARS(signed char);
3213  int i;
3214 
3215  for (i = -128; i < 128; i++)
3216  {
3218  }
3219 }
3220 
3221 static void test_VarCyFromUI1(void)
3222 {
3223  CONVVARS(BYTE);
3224  int i;
3225 
3226  for (i = 0; i < 256; i++)
3227  {
3229  }
3230 }
3231 
3232 static void test_VarCyFromI2(void)
3233 {
3234  CONVVARS(SHORT);
3235  int i;
3236 
3237  for (i = -16384; i < 16384; i++)
3238  {
3240  }
3241 }
3242 
3243 static void test_VarCyFromUI2(void)
3244 {
3245  CONVVARS(int);
3246  int i;
3247 
3248  for (i = 0; i < 32768; i++)
3249  {
3251  }
3252 }
3253 
3254 static void test_VarCyFromI4(void)
3255 {
3256  CONVVARS(int);
3257 
3258  CONVERT(VarCyFromI4, -1); EXPECTCY(-1);
3259  CONVERT(VarCyFromI4, 0); EXPECTCY(0);
3260  CONVERT(VarCyFromI4, 1); EXPECTCY(1);
3261  CONVERT(VarCyFromI4, 0x7fffffff); EXPECTCY64(0x1387, 0xffffd8f0);
3262  CONVERT(VarCyFromI4, 0x80000000); EXPECTCY64(0xffffec78, 0);
3263 }
3264 
3265 static void test_VarCyFromUI4(void)
3266 {
3267  CONVVARS(unsigned int);
3268 
3269  CONVERT(VarCyFromUI4, 0); EXPECTCY(0);
3270  CONVERT(VarCyFromUI4, 1); EXPECTCY(1);
3271  CONVERT(VarCyFromUI4, 0x80000000); EXPECTCY64(5000, 0);
3272 }
3273 
3274 static void test_VarCyFromR4(void)
3275 {
3276  CONVVARS(FLOAT);
3277 
3278  CONVERT(VarCyFromR4, -1.0f); EXPECTCY(-1);
3279  CONVERT(VarCyFromR4, 0.0f); EXPECTCY(0);
3280  CONVERT(VarCyFromR4, 1.0f); EXPECTCY(1);
3281  CONVERT(VarCyFromR4, 1.5f); EXPECTCY(1.5);
3282 
3283  CONVERT(VarCyFromR4, -1.5f); EXPECTCY(-1.5);
3284  CONVERT(VarCyFromR4, -0.6f); EXPECTCY(-0.6);
3285  CONVERT(VarCyFromR4, -0.5f); EXPECTCY(-0.5);
3286  CONVERT(VarCyFromR4, -0.4f); EXPECTCY(-0.4);
3287  CONVERT(VarCyFromR4, 0.4f); EXPECTCY(0.4);
3288  CONVERT(VarCyFromR4, 0.5f); EXPECTCY(0.5);
3289  CONVERT(VarCyFromR4, 0.6f); EXPECTCY(0.6);
3290  CONVERT(VarCyFromR4, 1.5f); EXPECTCY(1.5);
3291  CONVERT(VarCyFromR4, 1.00009f); EXPECTCY(1.0001);
3292  CONVERT(VarCyFromR4, -1.00001f); EXPECTCY(-1);
3293  CONVERT(VarCyFromR4, -1.00005f); EXPECTCY(-1);
3294  CONVERT(VarCyFromR4, -0.00009f); EXPECTCY(-0.0001);
3295  CONVERT(VarCyFromR4, -0.00005f); EXPECTCY(0);
3296  CONVERT(VarCyFromR4, -0.00001f); EXPECTCY(0);
3297  CONVERT(VarCyFromR4, 0.00001f); EXPECTCY(0);
3298  CONVERT(VarCyFromR4, 0.00005f); EXPECTCY(0);
3299  CONVERT(VarCyFromR4, 0.00009f); EXPECTCY(0.0001);
3300  CONVERT(VarCyFromR4, -1.00001f); EXPECTCY(-1);
3301  CONVERT(VarCyFromR4, -1.00005f); EXPECTCY(-1);
3302  CONVERT(VarCyFromR4, -1.00009f); EXPECTCY(-1.0001);
3303 }
3304 
3305 static void test_VarCyFromR8(void)
3306 {
3307  CONVVARS(DOUBLE);
3308 
3309 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3310  /* Test our rounding is exactly the same. This fails if the special x86
3311  * cod