2 * Low level variant tests
4 * Copyright 2003 Jon Griffiths
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.
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.
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
24 #include "wine/test.h"
32 DEFINE_GUID(UUID_test_struct
, 0x4029f190, 0xca4a, 0x4611, 0xae,0xb9,0x67,0x39,0x83,0xcb,0x96,0xdd);
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.
39 # define HAS_UINT64_TO_FLOAT
42 # define HAS_UINT64_TO_FLOAT
45 # if defined(_mm_free)
46 /* _mm_free is defined if the Processor Pack has been installed */
47 # define HAS_UINT64_TO_FLOAT
53 static HMODULE hOleaut32
;
55 /* Has I8/UI8 data type? */
57 /* Has proper locale conversions? */
58 static BOOL has_locales
;
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)
64 /* Macros for converting and testing results */
65 #define CONVVARS(typ) HRESULT hres; CONV_TYPE out; typ in
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)
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)
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; };
86 #define CY_MULTIPLIER 10000
88 #define DATE_MIN -657434
89 #define DATE_MAX 2958465
91 #define CONVERT_I8(func,hi,lo) in = hi; in = (in << 32) | lo; hres = func(in, &out)
93 #define CONVERT_CY(func,val) in.int64 = (LONGLONG)(val * CY_MULTIPLIER); hres = func(in, &out)
95 #define CONVERT_CY64(func,hi,lo) S(in).Hi = hi; S(in).Lo = lo; in.int64 *= CY_MULTIPLIER; hres = func(in, &out)
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
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;
103 #define CONVERT_DEC(func,scl,sgn,hi,lo) SETDEC(in,scl,sgn,hi,lo); hres = func(&in, &out)
105 #define CONVERT_DEC64(func,scl,sgn,hi,mid,lo) SETDEC64(in,scl,sgn,hi,mid,lo); hres = func(&in, &out)
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;
113 #define CONVERT_STR(func,str,flags) \
115 if (str) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)/sizeof(WCHAR)); \
116 hres = func(str ? buff : NULL,in,flags,&out)
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 = ∈ \
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); \
134 #define CHANGETYPEEX(typ) hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, typ)
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
147 #define INITIAL_TYPETEST(vt, val, fs) \
148 VariantInit(&vSrc); \
149 VariantInit(&vDst); \
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); \
165 TYPETEST(VT_I8, V_I8(&vDst), fs); \
166 TYPETEST(VT_UI8, V_UI8(&vDst), fs); \
168 #define NEGATIVE_TYPETEST(vt, val, fs, vtneg, valneg) \
170 VariantInit(&vSrc); \
171 VariantInit(&vDst); \
174 TYPETEST(vtneg, valneg(&vDst), fs);
176 #define INITIAL_TYPETESTI8(vt, val) \
177 VariantInit(&vSrc); \
178 VariantInit(&vDst); \
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))
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) \
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) : '?'); \
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); \
230 BADVAR(VT_HRESULT); \
231 BADVAR(VT_SAFEARRAY); \
233 BADVAR(VT_USERDEFINED); \
237 BADVAR(VT_INT_PTR); \
238 BADVAR(VT_UINT_PTR); \
239 BADVAR(VT_FILETIME); \
242 BADVAR(VT_STORAGE); \
243 BADVAR(VT_STREAMED_OBJECT); \
244 BADVAR(VT_STORED_OBJECT); \
245 BADVAR(VT_BLOB_OBJECT); \
250 #define DEFINE_EXPECT(func) \
251 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
253 #define SET_EXPECT(func) \
254 do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
256 #define CHECK_EXPECT2(func) \
258 ok(expect_ ##func, "unexpected call " #func "\n"); \
259 called_ ## func = TRUE; \
262 #define CHECK_EXPECT(func) \
264 CHECK_EXPECT2(func); \
265 expect_ ## func = FALSE; \
268 #define CHECK_CALLED(func) \
270 ok(called_ ## func, "expected " #func "\n"); \
271 expect_ ## func = called_ ## func = FALSE; \
274 DEFINE_EXPECT(dispatch_invoke
);
276 /* Internal representation of a BSTR */
277 typedef struct tagINTERNAL_BSTR
281 } INTERNAL_BSTR
, *LPINTERNAL_BSTR
;
285 IDispatch IDispatch_iface
;
291 static inline DummyDispatch
*impl_from_IDispatch(IDispatch
*iface
)
293 return CONTAINING_RECORD(iface
, DummyDispatch
, IDispatch_iface
);
296 static ULONG WINAPI
DummyDispatch_AddRef(IDispatch
*iface
)
298 DummyDispatch
*This
= impl_from_IDispatch(iface
);
299 return InterlockedIncrement(&This
->ref
);
302 static ULONG WINAPI
DummyDispatch_Release(IDispatch
*iface
)
304 DummyDispatch
*This
= impl_from_IDispatch(iface
);
305 return InterlockedDecrement(&This
->ref
);
308 static HRESULT WINAPI
DummyDispatch_QueryInterface(IDispatch
*iface
,
314 if (IsEqualIID(riid
, &IID_IDispatch
) ||
315 IsEqualIID(riid
, &IID_IUnknown
))
318 IDispatch_AddRef(iface
);
321 return *ppvObject
? S_OK
: E_NOINTERFACE
;
324 static HRESULT WINAPI
DummyDispatch_GetTypeInfoCount(IDispatch
*iface
, UINT
*pctinfo
)
326 ok(0, "Unexpected call\n");
330 static HRESULT WINAPI
DummyDispatch_GetTypeInfo(IDispatch
*iface
, UINT tinfo
, LCID lcid
, ITypeInfo
**ti
)
332 ok(0, "Unexpected call\n");
336 static HRESULT WINAPI
DummyDispatch_GetIDsOfNames(IDispatch
*iface
, REFIID riid
, LPOLESTR
*names
,
337 UINT cnames
, LCID lcid
, DISPID
*dispid
)
339 ok(0, "Unexpected call\n");
343 static HRESULT WINAPI
DummyDispatch_Invoke(IDispatch
*iface
,
344 DISPID dispid
, REFIID riid
,
345 LCID lcid
, WORD wFlags
,
351 DummyDispatch
*This
= impl_from_IDispatch(iface
);
353 CHECK_EXPECT(dispatch_invoke
);
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");
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
);
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
);
369 if (This
->bFailInvoke
)
370 return E_OUTOFMEMORY
;
372 V_VT(res
) = This
->vt
;
373 if (This
->vt
== VT_UI1
)
376 memset(res
, 0, sizeof(*res
));
381 static const IDispatchVtbl DummyDispatch_VTable
=
383 DummyDispatch_QueryInterface
,
384 DummyDispatch_AddRef
,
385 DummyDispatch_Release
,
386 DummyDispatch_GetTypeInfoCount
,
387 DummyDispatch_GetTypeInfo
,
388 DummyDispatch_GetIDsOfNames
,
392 static void init_test_dispatch(LONG ref
, VARTYPE vt
, DummyDispatch
*dispatch
)
394 dispatch
->IDispatch_iface
.lpVtbl
= &DummyDispatch_VTable
;
397 dispatch
->bFailInvoke
= FALSE
;
405 #define CONV_TYPE signed char
407 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%d")
409 static void test_VarI1FromI2(void)
414 OVERFLOWRANGE(VarI1FromI2
, -32768, -128);
415 CONVERTRANGE(VarI1FromI2
, -128, 128);
416 OVERFLOWRANGE(VarI1FromI2
, 129, 32768);
419 static void test_VarI1FromI4(void)
424 CONVERT(VarI1FromI4
, -129); EXPECT_OVERFLOW
;
425 CONVERTRANGE(VarI1FromI4
, -128, 128);
426 CONVERT(VarI1FromI4
, 128); EXPECT_OVERFLOW
;
429 static void test_VarI1FromI8(void)
434 CONVERT(VarI1FromI8
, -129); EXPECT_OVERFLOW
;
435 CONVERTRANGE(VarI1FromI8
, -127, 128);
436 CONVERT(VarI1FromI8
, 128); EXPECT_OVERFLOW
;
439 static void test_VarI1FromUI1(void)
444 CONVERTRANGE(VarI1FromUI1
, 0, 127);
445 OVERFLOWRANGE(VarI1FromUI1
, 128, 255);
448 static void test_VarI1FromUI2(void)
453 CONVERTRANGE(VarI1FromUI2
, 0, 127);
454 OVERFLOWRANGE(VarI1FromUI2
, 128, 32768);
457 static void test_VarI1FromUI4(void)
462 CONVERTRANGE(VarI1FromUI4
, 0, 127);
463 CONVERT(VarI1FromUI4
, 128); EXPECT_OVERFLOW
;
466 static void test_VarI1FromUI8(void)
471 CONVERTRANGE(VarI1FromUI8
, 0, 127);
472 CONVERT(VarI1FromUI8
, 128); EXPECT_OVERFLOW
;
475 static void test_VarI1FromBool(void)
477 CONVVARS(VARIANT_BOOL
);
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);
486 static void test_VarI1FromR4(void)
490 CONVERT(VarI1FromR4
, -129.0f
); EXPECT_OVERFLOW
;
491 CONVERT(VarI1FromR4
, -128.51f
); EXPECT_OVERFLOW
;
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);
499 CONVERT(VarI1FromR4
, 127.5f
); EXPECT_OVERFLOW
;
500 CONVERT(VarI1FromR4
, 128.0f
); EXPECT_OVERFLOW
;
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);
512 static void test_VarI1FromR8(void)
516 CONVERT(VarI1FromR8
, -129.0); EXPECT_OVERFLOW
;
517 CONVERT(VarI1FromR8
, -128.51); EXPECT_OVERFLOW
;
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);
525 CONVERT(VarI1FromR8
, 127.5); EXPECT_OVERFLOW
;
526 CONVERT(VarI1FromR8
, 128.0); EXPECT_OVERFLOW
;
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);
538 static void test_VarI1FromDate(void)
542 CONVERT(VarI1FromDate
, -129.0); EXPECT_OVERFLOW
;
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);
548 CONVERT(VarI1FromDate
, 128.0); EXPECT_OVERFLOW
;
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);
560 static void test_VarI1FromCy(void)
564 CONVERT_CY(VarI1FromCy
,-129); EXPECT_OVERFLOW
;
565 CONVERT_CY(VarI1FromCy
,-128); EXPECT(128);
566 CONVERT_CY(VarI1FromCy
,-1); EXPECT(-1);
567 CONVERT_CY(VarI1FromCy
,0); EXPECT(0);
568 CONVERT_CY(VarI1FromCy
,1); EXPECT(1);
569 CONVERT_CY(VarI1FromCy
,127); EXPECT(127);
570 CONVERT_CY(VarI1FromCy
,128); EXPECT_OVERFLOW
;
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);
582 static void test_VarI1FromDec(void)
586 CONVERT_BADDEC(VarI1FromDec
);
588 CONVERT_DEC(VarI1FromDec
,0,0x80,0,129); EXPECT_OVERFLOW
;
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);
594 CONVERT_DEC(VarI1FromDec
,0,0,0,128); EXPECT_OVERFLOW
;
596 CONVERT_DEC(VarI1FromDec
,2,0x80,0,12800); EXPECT(-128);
597 CONVERT_DEC(VarI1FromDec
,2,0,0,12700); EXPECT(127);
600 static void test_VarI1FromStr(void)
605 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
607 CONVERT_STR(VarI1FromStr
,NULL
, 0); EXPECT_MISMATCH
;
608 CONVERT_STR(VarI1FromStr
,"0", 0); EXPECT(0);
609 CONVERT_STR(VarI1FromStr
,"-129", 0); EXPECT_OVERFLOW
;
610 CONVERT_STR(VarI1FromStr
,"-128", 0); EXPECT(-128);
611 CONVERT_STR(VarI1FromStr
,"127", 0); EXPECT(127);
612 CONVERT_STR(VarI1FromStr
,"128", 0); EXPECT_OVERFLOW
;
614 CONVERT_STR(VarI1FromStr
,"-1.5", LOCALE_NOUSEROVERRIDE
); EXPECT(-2);
615 CONVERT_STR(VarI1FromStr
,"-0.6", LOCALE_NOUSEROVERRIDE
); EXPECT(-1);
616 CONVERT_STR(VarI1FromStr
,"-0.5", LOCALE_NOUSEROVERRIDE
); EXPECT(0);
617 CONVERT_STR(VarI1FromStr
,"-0.4", LOCALE_NOUSEROVERRIDE
); EXPECT(0);
618 CONVERT_STR(VarI1FromStr
,"0.4", LOCALE_NOUSEROVERRIDE
); EXPECT(0);
619 CONVERT_STR(VarI1FromStr
,"0.5", LOCALE_NOUSEROVERRIDE
); EXPECT(0);
620 CONVERT_STR(VarI1FromStr
,"0.6", LOCALE_NOUSEROVERRIDE
); EXPECT(1);
621 CONVERT_STR(VarI1FromStr
,"1.5", LOCALE_NOUSEROVERRIDE
); EXPECT(2);
624 static void test_VarI1Copy(void)
626 COPYTEST(1, VT_I1
, V_I1(&vSrc
), V_I1(&vDst
), V_I1REF(&vSrc
), V_I1REF(&vDst
), "%d");
629 static void test_VarI1ChangeTypeEx(void)
633 VARIANTARG vSrc
, vDst
;
637 INITIAL_TYPETEST(VT_I1
, V_I1
, "%d");
639 NEGATIVE_TYPETEST(VT_I1
, V_I1
, "%d", VT_UI1
, V_UI1
);
643 #define CONV_TYPE BYTE
645 static void test_VarUI1FromI1(void)
647 CONVVARS(signed char);
650 OVERFLOWRANGE(VarUI1FromI1
, -128, 0);
651 CONVERTRANGE(VarUI1FromI1
, 0, 128);
654 static void test_VarUI1FromI2(void)
659 OVERFLOWRANGE(VarUI1FromI2
, -32768, 0);
660 CONVERTRANGE(VarUI1FromI2
, 0, 256);
661 OVERFLOWRANGE(VarUI1FromI2
, 256, 32768);
664 static void test_VarUI1FromI4(void)
669 CONVERT(VarUI1FromI4
, -1); EXPECT_OVERFLOW
;
670 CONVERTRANGE(VarUI1FromI4
, 0, 256);
671 CONVERT(VarUI1FromI4
, 256); EXPECT_OVERFLOW
;
674 static void test_VarUI1FromI8(void)
679 CONVERT(VarUI1FromI8
, -1); EXPECT_OVERFLOW
;
680 CONVERTRANGE(VarUI1FromI8
, 0, 256);
681 CONVERT(VarUI1FromI8
, 256); EXPECT_OVERFLOW
;
684 static void test_VarUI1FromUI2(void)
689 CONVERTRANGE(VarUI1FromUI2
, 0, 256);
690 OVERFLOWRANGE(VarUI1FromUI2
, 256, 65536);
693 static void test_VarUI1FromUI4(void)
698 CONVERTRANGE(VarUI1FromUI4
, 0, 256);
699 CONVERT(VarUI1FromUI4
, 256); EXPECT_OVERFLOW
;
702 static void test_VarUI1FromUI8(void)
707 CONVERTRANGE(VarUI1FromUI8
, 0, 256);
708 CONVERT(VarUI1FromUI8
, 256); EXPECT_OVERFLOW
;
711 static void test_VarUI1FromBool(void)
713 CONVVARS(VARIANT_BOOL
);
716 /* Note that conversions from bool overflow! */
717 CONVERT(VarUI1FromBool
, -1); EXPECT(255);
718 CONVERTRANGE(VarUI1FromBool
, 0, 256);
719 CONVERT(VarUI1FromBool
, 256); EXPECT(0);
722 static void test_VarUI1FromR4(void)
726 CONVERT(VarUI1FromR4
, -1.0f
); EXPECT_OVERFLOW
;
727 CONVERT(VarUI1FromR4
, -0.51f
); EXPECT_OVERFLOW
;
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);
733 CONVERT(VarUI1FromR4
, 255.5f
); EXPECT_OVERFLOW
;
734 CONVERT(VarUI1FromR4
, 256.0f
); EXPECT_OVERFLOW
;
737 CONVERT(VarUI1FromR4
, -1.5f
); EXPECT_OVERFLOW
;
738 CONVERT(VarUI1FromR4
, -0.6f
); EXPECT_OVERFLOW
;
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);
747 static void test_VarUI1FromR8(void)
751 CONVERT(VarUI1FromR8
, -1.0); EXPECT_OVERFLOW
;
752 CONVERT(VarUI1FromR8
, -0.51); EXPECT_OVERFLOW
;
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);
758 CONVERT(VarUI1FromR8
, 255.5); EXPECT_OVERFLOW
;
759 CONVERT(VarUI1FromR8
, 256.0); EXPECT_OVERFLOW
;
762 CONVERT(VarUI1FromR8
, -1.5); EXPECT_OVERFLOW
;
763 CONVERT(VarUI1FromR8
, -0.6); EXPECT_OVERFLOW
;
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);
772 static void test_VarUI1FromDate(void)
776 CONVERT(VarUI1FromDate
, -1.0); EXPECT_OVERFLOW
;
777 CONVERT(VarUI1FromDate
, 0.0); EXPECT(0);
778 CONVERT(VarUI1FromDate
, 1.0); EXPECT(1);
779 CONVERT(VarUI1FromDate
, 255.0); EXPECT(255);
780 CONVERT(VarUI1FromDate
, 256.0); EXPECT_OVERFLOW
;
783 CONVERT(VarUI1FromDate
, -1.5); EXPECT_OVERFLOW
;
784 CONVERT(VarUI1FromDate
, -0.6); EXPECT_OVERFLOW
;
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);
793 static void test_VarUI1FromCy(void)
797 CONVERT_CY(VarUI1FromCy
,-1); EXPECT_OVERFLOW
;
798 CONVERT_CY(VarUI1FromCy
,0); EXPECT(0);
799 CONVERT_CY(VarUI1FromCy
,1); EXPECT(1);
800 CONVERT_CY(VarUI1FromCy
,255); EXPECT(255);
801 CONVERT_CY(VarUI1FromCy
,256); EXPECT_OVERFLOW
;
804 CONVERT_CY(VarUI1FromCy
,-1.5); EXPECT_OVERFLOW
;
805 CONVERT_CY(VarUI1FromCy
,-0.6); EXPECT_OVERFLOW
;
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);
814 static void test_VarUI1FromDec(void)
818 CONVERT_BADDEC(VarUI1FromDec
);
820 CONVERT_DEC(VarUI1FromDec
,0,0x80,0,1); EXPECT_OVERFLOW
;
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);
824 CONVERT_DEC(VarUI1FromDec
,0,0,0,256); EXPECT_OVERFLOW
;
826 CONVERT_DEC(VarUI1FromDec
,2,0x80,0,100); EXPECT_OVERFLOW
;
827 CONVERT_DEC(VarUI1FromDec
,2,0,0,25500); EXPECT(255);
830 static void test_VarUI1FromStr(void)
835 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
837 CONVERT_STR(VarUI1FromStr
,NULL
, 0); EXPECT_MISMATCH
;
838 CONVERT_STR(VarUI1FromStr
,"0", 0); EXPECT(0);
839 CONVERT_STR(VarUI1FromStr
,"-1", 0); EXPECT_OVERFLOW
;
840 CONVERT_STR(VarUI1FromStr
,"255", 0); EXPECT(255);
841 CONVERT_STR(VarUI1FromStr
,"256", 0); EXPECT_OVERFLOW
;
844 CONVERT_STR(VarUI1FromStr
,"-1.5", LOCALE_NOUSEROVERRIDE
); EXPECT_OVERFLOW
;
845 CONVERT_STR(VarUI1FromStr
,"-0.6", LOCALE_NOUSEROVERRIDE
); EXPECT_OVERFLOW
;
846 CONVERT_STR(VarUI1FromStr
,"-0.5", LOCALE_NOUSEROVERRIDE
); EXPECT(0);
847 CONVERT_STR(VarUI1FromStr
,"-0.4", LOCALE_NOUSEROVERRIDE
); EXPECT(0);
848 CONVERT_STR(VarUI1FromStr
,"0.4", LOCALE_NOUSEROVERRIDE
); EXPECT(0);
849 CONVERT_STR(VarUI1FromStr
,"0.5", LOCALE_NOUSEROVERRIDE
); EXPECT(0);
850 CONVERT_STR(VarUI1FromStr
,"0.6", LOCALE_NOUSEROVERRIDE
); EXPECT(1);
851 CONVERT_STR(VarUI1FromStr
,"1.5", LOCALE_NOUSEROVERRIDE
); EXPECT(2);
854 static void test_VarUI1FromDisp(void)
856 DummyDispatch dispatch
;
858 VARIANTARG vSrc
, vDst
;
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.
869 * Should this test be corrected so that it works under native it should be
870 * generalised and the remaining types checked as well.
872 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
877 init_test_dispatch(1, VT_UI1
, &dispatch
);
878 V_VT(&vSrc
) = VT_DISPATCH
;
879 V_DISPATCH(&vSrc
) = &dispatch
.IDispatch_iface
;
881 SET_EXPECT(dispatch_invoke
);
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
);
888 SET_EXPECT(dispatch_invoke
);
889 V_VT(&vDst
) = VT_EMPTY
;
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
);
897 dispatch
.bFailInvoke
= TRUE
;
899 SET_EXPECT(dispatch_invoke
);
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
);
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
);
914 static void test_VarUI1Copy(void)
916 COPYTEST(1, VT_UI1
, V_UI1(&vSrc
), V_UI1(&vDst
), V_UI1REF(&vSrc
), V_UI1REF(&vDst
), "%d");
919 static void test_VarUI1ChangeTypeEx(void)
923 VARIANTARG vSrc
, vDst
;
927 INITIAL_TYPETEST(VT_UI1
, V_UI1
, "%d");
929 NEGATIVE_TYPETEST(VT_UI1
, V_UI1
, "%d", VT_I1
, V_I1
);
937 #define CONV_TYPE SHORT
939 static void test_VarI2FromI1(void)
941 CONVVARS(signed char);
944 CONVERTRANGE(VarI2FromI1
, -128, 128);
947 static void test_VarI2FromI4(void)
952 CONVERT(VarI2FromI4
, -32769); EXPECT_OVERFLOW
;
953 CONVERTRANGE(VarI2FromI4
, -32768, 32768);
954 CONVERT(VarI2FromI4
, 32768); EXPECT_OVERFLOW
;
957 static void test_VarI2FromI8(void)
961 CONVERT(VarI2FromI8
, -32769); EXPECT_OVERFLOW
;
962 CONVERT(VarI2FromI8
, -32768); EXPECT(-32768);
963 CONVERT(VarI2FromI8
, 32767); EXPECT(32767);
964 CONVERT(VarI2FromI8
, 32768); EXPECT_OVERFLOW
;
967 static void test_VarI2FromUI1(void)
972 CONVERTRANGE(VarI2FromUI1
, 0, 256);
975 static void test_VarI2FromUI2(void)
980 CONVERTRANGE(VarI2FromUI2
, 0, 32768);
981 CONVERT(VarI2FromUI2
, 32768); EXPECT_OVERFLOW
;
984 static void test_VarI2FromUI4(void)
989 CONVERTRANGE(VarI2FromUI4
, 0, 32768);
990 CONVERT(VarI2FromUI4
, 32768); EXPECT_OVERFLOW
;
993 static void test_VarI2FromUI8(void)
998 CONVERTRANGE(VarI2FromUI8
, 0, 32768);
999 CONVERT(VarI2FromUI8
, 32768); EXPECT_OVERFLOW
;
1002 static void test_VarI2FromBool(void)
1004 CONVVARS(VARIANT_BOOL
);
1007 CONVERTRANGE(VarI2FromBool
, -32768, 32768);
1010 static void test_VarI2FromR4(void)
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);
1023 CONVERT(VarI2FromR4
, 32767.5f
); EXPECT_OVERFLOW
;
1024 CONVERT(VarI2FromR4
, 32768.0f
); EXPECT_OVERFLOW
;
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);
1037 static void test_VarI2FromR8(void)
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
;
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);
1064 static void test_VarI2FromDate(void)
1068 CONVERT(VarI2FromDate
, -32769.0); EXPECT_OVERFLOW
;
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);
1074 CONVERT(VarI2FromDate
, 32768.0); EXPECT_OVERFLOW
;
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);
1087 static void test_VarI2FromCy(void)
1091 CONVERT_CY(VarI2FromCy
,-32769); EXPECT_OVERFLOW
;
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);
1097 CONVERT_CY(VarI2FromCy
,32768); EXPECT_OVERFLOW
;
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);
1110 static void test_VarI2FromDec(void)
1114 CONVERT_BADDEC(VarI2FromDec
);
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);
1122 CONVERT_DEC(VarI2FromDec
,0,0,0,32768); EXPECT_OVERFLOW
;
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
;
1129 static void test_VarI2FromStr(void)
1134 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
1136 CONVERT_STR(VarI2FromStr
,NULL
, 0); EXPECT_MISMATCH
;
1137 CONVERT_STR(VarI2FromStr
,"0", 0); EXPECT(0);
1138 CONVERT_STR(VarI2FromStr
,"-32769", 0); EXPECT_OVERFLOW
;
1139 CONVERT_STR(VarI2FromStr
,"-32768", 0); EXPECT(-32768);
1140 CONVERT_STR(VarI2FromStr
,"32767", 0); EXPECT(32767);
1141 CONVERT_STR(VarI2FromStr
,"32768", 0); EXPECT_OVERFLOW
;
1144 CONVERT_STR(VarI2FromStr
,"-1.5", LOCALE_NOUSEROVERRIDE
); EXPECT(-2);
1145 CONVERT_STR(VarI2FromStr
,"-0.6", LOCALE_NOUSEROVERRIDE
); EXPECT(-1);
1146 CONVERT_STR(VarI2FromStr
,"-0.5", LOCALE_NOUSEROVERRIDE
); EXPECT(0);
1147 CONVERT_STR(VarI2FromStr
,"-0.4", LOCALE_NOUSEROVERRIDE
); EXPECT(0);
1148 CONVERT_STR(VarI2FromStr
,"0.4", LOCALE_NOUSEROVERRIDE
); EXPECT(0);
1149 CONVERT_STR(VarI2FromStr
,"0.5", LOCALE_NOUSEROVERRIDE
); EXPECT(0);
1150 CONVERT_STR(VarI2FromStr
,"0.6", LOCALE_NOUSEROVERRIDE
); EXPECT(1);
1151 CONVERT_STR(VarI2FromStr
,"1.5", LOCALE_NOUSEROVERRIDE
); EXPECT(2);
1154 static void test_VarI2Copy(void)
1156 COPYTEST(1, VT_I2
, V_I2(&vSrc
), V_I2(&vDst
), V_I2REF(&vSrc
), V_I2REF(&vDst
), "%d");
1159 static void test_VarI2ChangeTypeEx(void)
1163 VARIANTARG vSrc
, vDst
;
1167 INITIAL_TYPETEST(VT_I2
, V_I2
, "%d");
1169 NEGATIVE_TYPETEST(VT_I2
, V_I2
, "%d", VT_UI2
, V_UI2
);
1173 #define CONV_TYPE USHORT
1175 static void test_VarUI2FromI1(void)
1177 CONVVARS(signed char);
1180 OVERFLOWRANGE(VarUI2FromI1
, -128, 0);
1181 CONVERTRANGE(VarUI2FromI1
, 0, 128);
1184 static void test_VarUI2FromI2(void)
1189 OVERFLOWRANGE(VarUI2FromI2
, -32768, 0);
1190 CONVERTRANGE(VarUI2FromI2
, 0, 32768);
1193 static void test_VarUI2FromI4(void)
1198 OVERFLOWRANGE(VarUI2FromI4
, -32768, 0);
1199 CONVERT(VarUI2FromI4
, 0); EXPECT(0);
1200 CONVERT(VarUI2FromI4
, 65535); EXPECT(65535);
1201 CONVERT(VarUI2FromI4
, 65536); EXPECT_OVERFLOW
;
1204 static void test_VarUI2FromI8(void)
1209 OVERFLOWRANGE(VarUI2FromI8
, -32768, 0);
1210 CONVERT(VarUI2FromI8
, 0); EXPECT(0);
1211 CONVERT(VarUI2FromI8
, 65535); EXPECT(65535);
1212 CONVERT(VarUI2FromI8
, 65536); EXPECT_OVERFLOW
;
1215 static void test_VarUI2FromUI1(void)
1220 CONVERTRANGE(VarUI2FromUI1
, 0, 256);
1223 static void test_VarUI2FromUI4(void)
1227 CONVERT(VarUI2FromUI4
, 0); EXPECT(0);
1228 CONVERT(VarUI2FromUI4
, 65535); EXPECT(65535);
1229 CONVERT(VarUI2FromUI4
, 65536); EXPECT_OVERFLOW
;
1232 static void test_VarUI2FromUI8(void)
1236 CONVERT(VarUI2FromUI8
, 0); EXPECT(0);
1237 CONVERT(VarUI2FromUI8
, 65535); EXPECT(65535);
1238 CONVERT(VarUI2FromUI8
, 65536); EXPECT_OVERFLOW
;
1241 static void test_VarUI2FromBool(void)
1243 CONVVARS(VARIANT_BOOL
);
1246 CONVERT(VarUI2FromBool
, -1); EXPECT(65535); /* Wraps! */
1247 CONVERTRANGE(VarUI2FromBool
, 0, 32768);
1250 static void test_VarUI2FromR4(void)
1254 CONVERT(VarUI2FromR4
, -1.0f
); EXPECT_OVERFLOW
;
1255 CONVERT(VarUI2FromR4
, -0.51f
); EXPECT_OVERFLOW
;
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);
1261 CONVERT(VarUI2FromR4
, 65535.5f
); EXPECT_OVERFLOW
;
1262 CONVERT(VarUI2FromR4
, 65536.0f
); EXPECT_OVERFLOW
;
1265 CONVERT(VarUI2FromR4
, -1.5f
); EXPECT_OVERFLOW
;
1266 CONVERT(VarUI2FromR4
, -0.6f
); EXPECT_OVERFLOW
;
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);
1275 static void test_VarUI2FromR8(void)
1279 CONVERT(VarUI2FromR8
, -1.0); EXPECT_OVERFLOW
;
1280 CONVERT(VarUI2FromR8
, -0.51); EXPECT_OVERFLOW
;
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);
1286 CONVERT(VarUI2FromR8
, 65535.5); EXPECT_OVERFLOW
;
1287 CONVERT(VarUI2FromR8
, 65536.0); EXPECT_OVERFLOW
;
1290 CONVERT(VarUI2FromR8
, -1.5); EXPECT_OVERFLOW
;
1291 CONVERT(VarUI2FromR8
, -0.6); EXPECT_OVERFLOW
;
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);
1300 static void test_VarUI2FromDate(void)
1304 CONVERT(VarUI2FromDate
, -1.0); EXPECT_OVERFLOW
;
1305 CONVERT(VarUI2FromDate
, 0.0); EXPECT(0);
1306 CONVERT(VarUI2FromDate
, 1.0); EXPECT(1);
1307 CONVERT(VarUI2FromDate
, 65535.0); EXPECT(65535);
1308 CONVERT(VarUI2FromDate
, 65536.0); EXPECT_OVERFLOW
;
1311 CONVERT(VarUI2FromDate
, -1.5); EXPECT_OVERFLOW
;
1312 CONVERT(VarUI2FromDate
, -0.6); EXPECT_OVERFLOW
;
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);
1321 static void test_VarUI2FromCy(void)
1325 CONVERT_CY(VarUI2FromCy
,-1); EXPECT_OVERFLOW
;
1326 CONVERT_CY(VarUI2FromCy
,0); EXPECT(0);
1327 CONVERT_CY(VarUI2FromCy
,1); EXPECT(1);
1328 CONVERT_CY(VarUI2FromCy
,65535); EXPECT(65535);
1329 CONVERT_CY(VarUI2FromCy
,65536); EXPECT_OVERFLOW
;
1332 CONVERT_CY(VarUI2FromCy
,-1.5); EXPECT_OVERFLOW
;
1333 CONVERT_CY(VarUI2FromCy
,-0.6); EXPECT_OVERFLOW
;
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);
1342 static void test_VarUI2FromDec(void)
1346 CONVERT_BADDEC(VarUI2FromDec
);
1348 CONVERT_DEC(VarUI2FromDec
,0,0x80,0,1); EXPECT_OVERFLOW
;
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);
1352 CONVERT_DEC(VarUI2FromDec
,0,0,0,65536); EXPECT_OVERFLOW
;
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
;
1359 static void test_VarUI2FromStr(void)
1364 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
1366 CONVERT_STR(VarUI2FromStr
,NULL
, 0); EXPECT_MISMATCH
;
1367 CONVERT_STR(VarUI2FromStr
,"0", 0); EXPECT(0);
1368 CONVERT_STR(VarUI2FromStr
,"-1", 0); EXPECT_OVERFLOW
;
1369 CONVERT_STR(VarUI2FromStr
,"65535", 0); EXPECT(65535);
1370 CONVERT_STR(VarUI2FromStr
,"65536", 0); EXPECT_OVERFLOW
;
1373 CONVERT_STR(VarUI2FromStr
,"-1.5", LOCALE_NOUSEROVERRIDE
); EXPECT_OVERFLOW
;
1374 CONVERT_STR(VarUI2FromStr
,"-0.6", LOCALE_NOUSEROVERRIDE
); EXPECT_OVERFLOW
;
1375 CONVERT_STR(VarUI2FromStr
,"-0.5", LOCALE_NOUSEROVERRIDE
); EXPECT(0);
1376 CONVERT_STR(VarUI2FromStr
,"-0.4", LOCALE_NOUSEROVERRIDE
); EXPECT(0);
1377 CONVERT_STR(VarUI2FromStr
,"0.4", LOCALE_NOUSEROVERRIDE
); EXPECT(0);
1378 CONVERT_STR(VarUI2FromStr
,"0.5", LOCALE_NOUSEROVERRIDE
); EXPECT(0);
1379 CONVERT_STR(VarUI2FromStr
,"0.6", LOCALE_NOUSEROVERRIDE
); EXPECT(1);
1380 CONVERT_STR(VarUI2FromStr
,"1.5", LOCALE_NOUSEROVERRIDE
); EXPECT(2);
1383 static void test_VarUI2Copy(void)
1385 COPYTEST(1, VT_UI2
, V_UI2(&vSrc
), V_UI2(&vDst
), V_UI2REF(&vSrc
), V_UI2REF(&vDst
), "%d");
1388 static void test_VarUI2ChangeTypeEx(void)
1392 VARIANTARG vSrc
, vDst
;
1396 INITIAL_TYPETEST(VT_UI2
, V_UI2
, "%d");
1398 NEGATIVE_TYPETEST(VT_UI2
, V_UI2
, "%d", VT_I2
, V_I2
);
1406 #define CONV_TYPE LONG
1408 static void test_VarI4FromI1(void)
1410 CONVVARS(signed char);
1413 CONVERTRANGE(VarI4FromI1
, -128, 128);
1416 static void test_VarI4FromI2(void)
1421 CONVERTRANGE(VarI4FromI2
, -32768, 32768);
1424 static void test_VarI4FromI8(void)
1428 CONVERT(VarI4FromI8
, -1); EXPECT(-1);
1429 CONVERT(VarI4FromI8
, 0); EXPECT(0);
1430 CONVERT(VarI4FromI8
, 1); EXPECT(1);
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
;
1438 static void test_VarI4FromUI1(void)
1443 CONVERTRANGE(VarI4FromUI1
, 0, 256);
1446 static void test_VarI4FromUI2(void)
1451 CONVERTRANGE(VarI4FromUI2
, 0, 65536);
1454 static void test_VarI4FromUI4(void)
1458 CONVERT(VarI4FromUI4
, 0); EXPECT(0);
1459 CONVERT(VarI4FromUI4
, 1); EXPECT(1);
1460 CONVERT(VarI4FromUI4
, 2147483647); EXPECT(2147483647);
1461 CONVERT(VarI4FromUI4
, 2147483648ul); EXPECT_OVERFLOW
;
1464 static void test_VarI4FromUI8(void)
1468 CONVERT(VarI4FromUI8
, 0); EXPECT(0);
1469 CONVERT(VarI4FromUI8
, 1); EXPECT(1);
1470 CONVERT(VarI4FromUI8
, 2147483647); EXPECT(2147483647);
1471 CONVERT(VarI4FromUI8
, 2147483648ul); EXPECT_OVERFLOW
;
1474 static void test_VarI4FromBool(void)
1476 CONVVARS(VARIANT_BOOL
);
1479 CONVERTRANGE(VarI4FromBool
, -32768, 32768);
1482 static void test_VarI4FromR4(void)
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);
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);
1501 static void test_VarI4FromR8(void)
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
;
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);
1527 static void test_VarI4FromDate(void)
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
;
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);
1549 static void test_VarI4FromCy(void)
1553 CONVERT_CY(VarI4FromCy
,-1); EXPECT(-1);
1554 CONVERT_CY(VarI4FromCy
,0); EXPECT(0);
1555 CONVERT_CY(VarI4FromCy
,1); EXPECT(1);
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
;
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);
1572 static void test_VarI4FromDec(void)
1576 CONVERT_BADDEC(VarI4FromDec
);
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);
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
;
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);
1590 CONVERT_DEC64(VarI4FromDec
,2,0,0,50,0); EXPECT_OVERFLOW
;
1593 static void test_VarI4FromStr(void)
1598 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
1600 CONVERT_STR(VarI4FromStr
,NULL
,0); EXPECT_MISMATCH
;
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
;
1608 CONVERT_STR(VarI4FromStr
,"-1.5",LOCALE_NOUSEROVERRIDE
); EXPECT(-2);
1609 CONVERT_STR(VarI4FromStr
,"-0.6",LOCALE_NOUSEROVERRIDE
); EXPECT(-1);
1610 CONVERT_STR(VarI4FromStr
,"-0.5",LOCALE_NOUSEROVERRIDE
); EXPECT(0);
1611 CONVERT_STR(VarI4FromStr
,"-0.4",LOCALE_NOUSEROVERRIDE
); EXPECT(0);
1612 CONVERT_STR(VarI4FromStr
,"0.4",LOCALE_NOUSEROVERRIDE
); EXPECT(0);
1613 CONVERT_STR(VarI4FromStr
,"0.5",LOCALE_NOUSEROVERRIDE
); EXPECT(0);
1614 CONVERT_STR(VarI4FromStr
,"0.6",LOCALE_NOUSEROVERRIDE
); EXPECT(1);
1615 CONVERT_STR(VarI4FromStr
,"1.5",LOCALE_NOUSEROVERRIDE
); EXPECT(2);
1618 static void test_VarI4Copy(void)
1620 COPYTEST(1, VT_I4
, V_I4(&vSrc
), V_I4(&vDst
), V_I4REF(&vSrc
), V_I4REF(&vDst
), "%d");
1623 static void test_VarI4ChangeTypeEx(void)
1627 VARIANTARG vSrc
, vDst
;
1631 INITIAL_TYPETEST(VT_I4
, V_I4
, "%d");
1633 NEGATIVE_TYPETEST(VT_I4
, V_I4
, "%d", VT_UI4
, V_UI4
);
1637 #define CONV_TYPE ULONG
1639 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%u")
1641 static void test_VarUI4FromI1(void)
1643 CONVVARS(signed char);
1646 OVERFLOWRANGE(VarUI4FromI1
, -127, 0);
1647 CONVERTRANGE(VarUI4FromI1
, 0, 128);
1650 static void test_VarUI4FromI2(void)
1655 OVERFLOWRANGE(VarUI4FromI2
, -32768, 0);
1656 CONVERTRANGE(VarUI4FromI2
, 0, 32768);
1659 static void test_VarUI4FromUI2(void)
1664 CONVERTRANGE(VarUI4FromUI2
, 0, 65536);
1667 static void test_VarUI4FromI8(void)
1671 CONVERT(VarUI4FromI8
, -1); EXPECT_OVERFLOW
;
1672 CONVERT(VarUI4FromI8
, 0); EXPECT(0);
1673 CONVERT(VarUI4FromI8
, 1); EXPECT(1);
1674 CONVERT(VarUI4FromI8
, 4294967295ul); EXPECT(4294967295ul);
1675 CONVERT_I8(VarUI4FromI8
, 1, 0); EXPECT_OVERFLOW
;
1678 static void test_VarUI4FromUI1(void)
1683 CONVERTRANGE(VarUI4FromUI1
, 0, 256);
1686 static void test_VarUI4FromI4(void)
1690 CONVERT(VarUI4FromI4
, -1); EXPECT_OVERFLOW
;
1691 CONVERT(VarUI4FromI4
, 0); EXPECT(0);
1692 CONVERT(VarUI4FromI4
, 1); EXPECT(1);
1693 CONVERT(VarUI4FromI4
, 2147483647); EXPECT(2147483647);
1696 static void test_VarUI4FromUI8(void)
1700 CONVERT(VarUI4FromUI8
, 0); EXPECT(0);
1701 CONVERT(VarUI4FromUI8
, 1); EXPECT(1);
1702 CONVERT(VarUI4FromI8
, 4294967295ul); EXPECT(4294967295ul);
1703 CONVERT_I8(VarUI4FromI8
, 1, 0); EXPECT_OVERFLOW
;
1706 static void test_VarUI4FromBool(void)
1708 CONVVARS(VARIANT_BOOL
);
1711 CONVERTRANGE(VarUI4FromBool
, -32768, 32768);
1714 static void test_VarUI4FromR4(void)
1718 /* We can't test max values as they are not exactly representable in a float */
1719 CONVERT(VarUI4FromR4
, -1.0f
); EXPECT_OVERFLOW
;
1720 CONVERT(VarUI4FromR4
, -0.51f
); EXPECT_OVERFLOW
;
1721 CONVERT(VarUI4FromR4
, -0.5f
); EXPECT(0);
1722 CONVERT(VarUI4FromR4
, 0.0f
); EXPECT(0);
1723 CONVERT(VarUI4FromR4
, 1.0f
); EXPECT(1);
1725 CONVERT(VarUI4FromR4
, -1.5f
); EXPECT_OVERFLOW
;
1726 CONVERT(VarUI4FromR4
, -0.6f
); EXPECT_OVERFLOW
;
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);
1736 static void test_VarUI4FromR8(void)
1740 CONVERT(VarUI4FromR8
, -1.0); EXPECT_OVERFLOW
;
1741 CONVERT(VarUI4FromR4
, -0.51f
); EXPECT_OVERFLOW
;
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
;
1750 CONVERT(VarUI4FromR8
, -1.5); EXPECT_OVERFLOW
;
1751 CONVERT(VarUI4FromR8
, -0.6); EXPECT_OVERFLOW
;
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);
1760 static void test_VarUI4FromDate(void)
1764 CONVERT(VarUI4FromDate
, -1.0); EXPECT_OVERFLOW
;
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
;
1770 CONVERT(VarUI4FromDate
, -1.5); EXPECT_OVERFLOW
;
1771 CONVERT(VarUI4FromDate
, -0.6); EXPECT_OVERFLOW
;
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);
1780 static void test_VarUI4FromCy(void)
1784 CONVERT_CY(VarUI4FromCy
,-1); EXPECT_OVERFLOW
;
1785 CONVERT_CY(VarUI4FromCy
,0); EXPECT(0);
1786 CONVERT_CY(VarUI4FromCy
,1); EXPECT(1);
1787 CONVERT_CY64(VarUI4FromCy
,0,4294967295ul); EXPECT(4294967295ul);
1788 CONVERT_CY64(VarUI4FromCy
,1,0); EXPECT_OVERFLOW
;
1790 CONVERT_CY(VarUI4FromCy
,-1.5); EXPECT_OVERFLOW
;
1791 CONVERT_CY(VarUI4FromCy
,-0.6); EXPECT_OVERFLOW
;
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);
1800 static void test_VarUI4FromDec(void)
1804 CONVERT_BADDEC(VarUI4FromDec
);
1806 CONVERT_DEC(VarUI4FromDec
,0,0x80,0,1); EXPECT_OVERFLOW
;
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);
1810 CONVERT_DEC64(VarUI4FromDec
,0,0,0,1,0); EXPECT_OVERFLOW
;
1812 CONVERT_DEC64(VarUI4FromDec
,2,0,0,99,4294967196ul); EXPECT(4294967295ul);
1813 CONVERT_DEC64(VarUI4FromDec
,2,0,0,100,0); EXPECT_OVERFLOW
;
1816 static void test_VarUI4FromStr(void)
1821 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
1823 CONVERT_STR(VarUI4FromStr
,NULL
,0); EXPECT_MISMATCH
;
1824 CONVERT_STR(VarUI4FromStr
,"-1",0); EXPECT_OVERFLOW
;
1825 CONVERT_STR(VarUI4FromStr
,"0",0); EXPECT(0);
1826 CONVERT_STR(VarUI4FromStr
,"4294967295",0); EXPECT(4294967295ul);
1827 CONVERT_STR(VarUI4FromStr
,"4294967296",0); EXPECT_OVERFLOW
;
1830 CONVERT_STR(VarUI4FromStr
,"-1.5",LOCALE_NOUSEROVERRIDE
); EXPECT_OVERFLOW
;
1831 CONVERT_STR(VarUI4FromStr
,"-0.6",LOCALE_NOUSEROVERRIDE
); EXPECT_OVERFLOW
;
1832 CONVERT_STR(VarUI4FromStr
,"-0.5",LOCALE_NOUSEROVERRIDE
); EXPECT(0);
1833 CONVERT_STR(VarUI4FromStr
,"-0.4",LOCALE_NOUSEROVERRIDE
); EXPECT(0);
1834 CONVERT_STR(VarUI4FromStr
,"0.4",LOCALE_NOUSEROVERRIDE
); EXPECT(0);
1835 CONVERT_STR(VarUI4FromStr
,"0.5",LOCALE_NOUSEROVERRIDE
); EXPECT(0);
1836 CONVERT_STR(VarUI4FromStr
,"0.6",LOCALE_NOUSEROVERRIDE
); EXPECT(1);
1837 CONVERT_STR(VarUI4FromStr
,"1.5",LOCALE_NOUSEROVERRIDE
); EXPECT(2);
1840 static void test_VarUI4Copy(void)
1842 COPYTEST(1u, VT_UI4
, V_UI4(&vSrc
), V_UI4(&vDst
), V_UI4REF(&vSrc
), V_UI4REF(&vDst
), "%u");
1845 static void test_VarUI4ChangeTypeEx(void)
1849 VARIANTARG vSrc
, vDst
;
1853 INITIAL_TYPETEST(VT_UI4
, V_UI4
, "%u");
1855 NEGATIVE_TYPETEST(VT_UI4
, V_UI4
, "%u", VT_I4
, V_I4
);
1863 #define CONV_TYPE LONG64
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)
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)
1877 static void test_VarI8FromI1(void)
1879 CONVVARS(signed char);
1882 for (i
= -128; i
< 128; i
++)
1884 CONVERT(VarI8FromI1
,i
); EXPECTI8(i
);
1888 static void test_VarI8FromUI1(void)
1893 for (i
= 0; i
< 256; i
++)
1895 CONVERT(VarI8FromUI1
,i
); EXPECTI8(i
);
1899 static void test_VarI8FromI2(void)
1904 for (i
= -32768; i
< 32768; i
++)
1906 CONVERT(VarI8FromI2
,i
); EXPECTI8(i
);
1910 static void test_VarI8FromUI2(void)
1915 for (i
= -0; i
< 65535; i
++)
1917 CONVERT(VarI8FromUI2
,i
); EXPECTI8(i
);
1921 static void test_VarI8FromUI4(void)
1925 CONVERT(VarI8FromUI4
, 0); EXPECTI8(0);
1926 CONVERT(VarI8FromUI4
, 1); EXPECTI8(1);
1927 CONVERT(VarI8FromUI4
, 4294967295ul); EXPECTI8(4294967295ul);
1930 static void test_VarI8FromR4(void)
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);
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);
1950 static void test_VarI8FromR8(void)
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);
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);
1970 static void test_VarI8FromDate(void)
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);
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);
1990 static void test_VarI8FromBool(void)
1992 CONVVARS(VARIANT_BOOL
);
1995 for (i
= -32768; i
< 32768; i
++)
1997 CONVERT(VarI8FromBool
,i
); EXPECTI8(i
);
2001 static void test_VarI8FromUI8(void)
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
;
2011 static void test_VarI8FromCy(void)
2015 CONVERT_CY(VarI8FromCy
,-128); EXPECTI8(-129);
2016 CONVERT_CY(VarI8FromCy
,-1); EXPECTI8(-2);
2017 CONVERT_CY(VarI8FromCy
,0); EXPECTI8(0);
2018 CONVERT_CY(VarI8FromCy
,1); EXPECTI8(1);
2019 CONVERT_CY(VarI8FromCy
,127); EXPECTI8(127);
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);
2031 static void test_VarI8FromDec(void)
2035 CONVERT_BADDEC(VarI8FromDec
);
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);
2043 CONVERT_DEC(VarI8FromDec
,2,0x80,0,12700); EXPECTI8(-127);
2044 CONVERT_DEC(VarI8FromDec
,2,0,0,12700); EXPECTI8(127);
2047 static void test_VarI8FromStr(void)
2052 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
2054 CONVERT_STR(VarI8FromStr
,NULL
,0); EXPECT_MISMATCH
;
2055 CONVERT_STR(VarI8FromStr
,"0",0); EXPECTI8(0);
2056 CONVERT_STR(VarI8FromStr
,"-1",0); EXPECTI8(-1);
2057 CONVERT_STR(VarI8FromStr
,"2147483647",0); EXPECTI8(2147483647);
2059 CONVERT_STR(VarI8FromStr
,"-1.5",LOCALE_NOUSEROVERRIDE
); EXPECTI8(-2);
2060 CONVERT_STR(VarI8FromStr
,"-0.6",LOCALE_NOUSEROVERRIDE
); EXPECTI8(-1);
2061 CONVERT_STR(VarI8FromStr
,"-0.5",LOCALE_NOUSEROVERRIDE
); EXPECTI8(0);
2062 CONVERT_STR(VarI8FromStr
,"-0.4",LOCALE_NOUSEROVERRIDE
); EXPECTI8(0);
2063 CONVERT_STR(VarI8FromStr
,"0.4",LOCALE_NOUSEROVERRIDE
); EXPECTI8(0);
2064 CONVERT_STR(VarI8FromStr
,"0.5",LOCALE_NOUSEROVERRIDE
); EXPECTI8(0);
2065 CONVERT_STR(VarI8FromStr
,"0.6",LOCALE_NOUSEROVERRIDE
); EXPECTI8(1);
2066 CONVERT_STR(VarI8FromStr
,"1.5",LOCALE_NOUSEROVERRIDE
); EXPECTI8(2);
2069 static void test_VarI8Copy(void)
2072 VARIANTARG vSrc
, vDst
;
2077 win_skip("I8 and UI8 data types are not available\n");
2083 V_VT(&vSrc
) = VT_I8
;
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
) );
2100 static void test_VarI8ChangeTypeEx(void)
2104 VARIANTARG vSrc
, vDst
;
2108 win_skip("I8 and UI8 data types are not available\n");
2114 INITIAL_TYPETESTI8(VT_I8
, V_I8
);
2118 /* Adapt the test macros to UI8 */
2120 #define CONV_TYPE ULONG64
2122 static void test_VarUI8FromI1(void)
2124 CONVVARS(signed char);
2127 for (i
= -128; i
< 128; i
++)
2129 CONVERT(VarUI8FromI1
,i
);
2137 static void test_VarUI8FromUI1(void)
2142 for (i
= 0; i
< 256; i
++)
2144 CONVERT(VarUI8FromUI1
,i
); EXPECTI8(i
);
2148 static void test_VarUI8FromI2(void)
2153 for (i
= -32768; i
< 32768; i
++)
2155 CONVERT(VarUI8FromI2
,i
);
2163 static void test_VarUI8FromUI2(void)
2168 for (i
= 0; i
< 65535; i
++)
2170 CONVERT(VarUI8FromUI2
,i
); EXPECTI8(i
);
2174 static void test_VarUI8FromUI4(void)
2178 CONVERT(VarUI8FromUI4
, 0); EXPECTI8(0);
2179 CONVERT(VarUI8FromUI4
, 0xffffffff); EXPECTI8(0xffffffff);
2182 static void test_VarUI8FromR4(void)
2186 CONVERT(VarUI8FromR4
, -1.0f
); EXPECT_OVERFLOW
;
2187 CONVERT(VarUI8FromR4
, 0.0f
); EXPECTI8(0);
2188 CONVERT(VarUI8FromR4
, 1.0f
); EXPECTI8(1);
2189 CONVERT(VarUI8FromR4
, 255.0f
); EXPECTI8(255);
2191 CONVERT(VarUI8FromR4
, -1.5f
); EXPECT_OVERFLOW
;
2192 CONVERT(VarUI8FromR4
, -0.6f
); EXPECT_OVERFLOW
;
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);
2201 static void test_VarUI8FromR8(void)
2205 CONVERT(VarUI8FromR8
, -1.0); EXPECT_OVERFLOW
;
2206 CONVERT(VarUI8FromR8
, 0.0); EXPECTI8(0);
2207 CONVERT(VarUI8FromR8
, 1.0); EXPECTI8(1);
2208 CONVERT(VarUI8FromR8
, 255.0); EXPECTI8(255);
2210 CONVERT(VarUI8FromR8
, -1.5); EXPECT_OVERFLOW
;
2211 CONVERT(VarUI8FromR8
, -0.6); EXPECT_OVERFLOW
;
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);
2220 static void test_VarUI8FromDate(void)
2224 CONVERT(VarUI8FromDate
, -1.0); EXPECT_OVERFLOW
;
2225 CONVERT(VarUI8FromDate
, 0.0); EXPECTI8(0);
2226 CONVERT(VarUI8FromDate
, 1.0); EXPECTI8(1);
2227 CONVERT(VarUI8FromDate
, 255.0); EXPECTI8(255);
2229 CONVERT(VarUI8FromDate
, -1.5); EXPECT_OVERFLOW
;
2230 CONVERT(VarUI8FromDate
, -0.6); EXPECT_OVERFLOW
;
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);
2239 static void test_VarUI8FromBool(void)
2241 CONVVARS(VARIANT_BOOL
);
2244 for (i
= -32768; i
< 32768; i
++)
2246 CONVERT(VarUI8FromBool
, i
); EXPECTI8(i
);
2250 static void test_VarUI8FromI8(void)
2254 CONVERT(VarUI8FromI8
, -1); EXPECT_OVERFLOW
;
2255 CONVERT(VarUI8FromI8
, 0); EXPECTI8(0);
2256 CONVERT(VarUI8FromI8
, 1); EXPECTI8(1);
2259 static void test_VarUI8FromCy(void)
2263 CONVERT_CY(VarUI8FromCy
,-1); EXPECT_OVERFLOW
;
2264 CONVERT_CY(VarUI8FromCy
,0); EXPECTI8(0);
2265 CONVERT_CY(VarUI8FromCy
,1); EXPECTI8(1);
2266 CONVERT_CY(VarUI8FromCy
,255); EXPECTI8(255);
2268 CONVERT_CY(VarUI8FromCy
,-1.5); EXPECT_OVERFLOW
;
2269 CONVERT_CY(VarUI8FromCy
,-0.6); EXPECT_OVERFLOW
;
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);
2278 static void test_VarUI8FromDec(void)
2282 CONVERT_BADDEC(VarUI8FromDec
);
2284 /* This returns 1 under native; Wine fixes this bug and returns overflow */
2287 CONVERT_DEC(VarUI8FromDec
,0,0x80,0,1);
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);
2294 CONVERT_DEC(VarUI8FromDec
,2,0x80,0,100); EXPECT_OVERFLOW
;
2295 CONVERT_DEC(VarUI8FromDec
,2,0,0,25500); EXPECTI8(255);
2298 static void test_VarUI8FromStr(void)
2303 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
2305 CONVERT_STR(VarUI8FromStr
,NULL
,0); EXPECT_MISMATCH
;
2306 CONVERT_STR(VarUI8FromStr
,"0",0); EXPECTI8(0);
2307 CONVERT_STR(VarUI8FromStr
,"-1",0); EXPECT_OVERFLOW
;
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
;
2313 CONVERT_STR(VarUI8FromStr
,"-1.5",LOCALE_NOUSEROVERRIDE
); EXPECT_OVERFLOW
;
2314 CONVERT_STR(VarUI8FromStr
,"-0.6",LOCALE_NOUSEROVERRIDE
); EXPECT_OVERFLOW
;
2315 CONVERT_STR(VarUI8FromStr
,"-0.5",LOCALE_NOUSEROVERRIDE
); EXPECTI8(0);
2316 CONVERT_STR(VarUI8FromStr
,"-0.4",LOCALE_NOUSEROVERRIDE
); EXPECTI8(0);
2317 CONVERT_STR(VarUI8FromStr
,"0.4",LOCALE_NOUSEROVERRIDE
); EXPECTI8(0);
2318 CONVERT_STR(VarUI8FromStr
,"0.5",LOCALE_NOUSEROVERRIDE
); EXPECTI8(0);
2319 CONVERT_STR(VarUI8FromStr
,"0.6",LOCALE_NOUSEROVERRIDE
); EXPECTI8(1);
2320 CONVERT_STR(VarUI8FromStr
,"1.5",LOCALE_NOUSEROVERRIDE
); EXPECTI8(2);
2323 static void test_VarUI8Copy(void)
2326 VARIANTARG vSrc
, vDst
;
2331 win_skip("I8 and UI8 data types are not available\n");
2337 V_VT(&vSrc
) = VT_UI8
;
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
) );
2354 static void test_VarUI8ChangeTypeEx(void)
2358 VARIANTARG vSrc
, vDst
;
2362 win_skip("I8 and UI8 data types are not available\n");
2368 INITIAL_TYPETESTI8(VT_UI8
, V_UI8
);
2377 #define CONV_TYPE float
2379 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%15.15f")
2381 static void test_VarR4FromI1(void)
2383 CONVVARS(signed char);
2386 CONVERTRANGE(VarR4FromI1
, -128, 128);
2389 static void test_VarR4FromUI1(void)
2394 CONVERTRANGE(VarR4FromUI1
, 0, 256);
2397 static void test_VarR4FromI2(void)
2402 CONVERTRANGE(VarR4FromI2
, -32768, 32768);
2405 static void test_VarR4FromUI2(void)
2410 CONVERTRANGE(VarR4FromUI2
, 0, 65536);
2413 static void test_VarR4FromI4(void)
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
);
2424 static void test_VarR4FromUI4(void)
2426 CONVVARS(unsigned int);
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
);
2435 static void test_VarR4FromR8(void)
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
);
2444 /* Skip rounding tests - no rounding is done */
2447 static void test_VarR4FromBool(void)
2449 CONVVARS(VARIANT_BOOL
);
2451 CONVERT(VarR4FromBool
, VARIANT_TRUE
); EXPECT(VARIANT_TRUE
* 1.0f
);
2452 CONVERT(VarR4FromBool
, VARIANT_FALSE
); EXPECT(VARIANT_FALSE
* 1.0f
);
2455 static void test_VarR4FromCy(void)
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
);
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
);
2475 static void test_VarR4FromI8(void)
2479 CONVERT(VarR4FromI8
, -1); EXPECT(-1.0f
);
2480 CONVERT(VarR4FromI8
, 0); EXPECT(0.0f
);
2481 CONVERT(VarR4FromI8
, 1); EXPECT(1.0f
);
2484 static void test_VarR4FromUI8(void)
2488 CONVERT(VarR4FromUI8
, 0); EXPECT(0.0f
);
2489 CONVERT(VarR4FromUI8
, 1); EXPECT(1.0f
);
2492 static void test_VarR4FromDec(void)
2496 CONVERT_BADDEC(VarR4FromDec
);
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
);
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
);
2508 CONVERT_DEC(VarR4FromDec
,0,0,1,0); EXPECT(18446744073709551616.0f
);
2511 static void test_VarR4FromDate(void)
2515 CONVERT(VarR4FromDate
, -1.0); EXPECT(-1.0f
);
2516 CONVERT(VarR4FromDate
, 0.0); EXPECT(0.0f
);
2517 CONVERT(VarR4FromDate
, 1.0); EXPECT(1.0f
);
2520 static void test_VarR4FromStr(void)
2525 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
2527 CONVERT_STR(VarR4FromStr
,NULL
,0); EXPECT_MISMATCH
;
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
);
2532 CONVERT_STR(VarR4FromStr
,"-1.5",LOCALE_NOUSEROVERRIDE
); EXPECT(-1.5f
);
2533 CONVERT_STR(VarR4FromStr
,"-0.6",LOCALE_NOUSEROVERRIDE
); EXPECT(-0.6f
);
2534 CONVERT_STR(VarR4FromStr
,"-0.5",LOCALE_NOUSEROVERRIDE
); EXPECT(-0.5f
);
2535 CONVERT_STR(VarR4FromStr
,"-0.4",LOCALE_NOUSEROVERRIDE
); EXPECT(-0.4f
);
2536 CONVERT_STR(VarR4FromStr
,"0.4",LOCALE_NOUSEROVERRIDE
); EXPECT(0.4f
);
2537 CONVERT_STR(VarR4FromStr
,"0.5",LOCALE_NOUSEROVERRIDE
); EXPECT(0.5f
);
2538 CONVERT_STR(VarR4FromStr
,"0.6",LOCALE_NOUSEROVERRIDE
); EXPECT(0.6f
);
2539 CONVERT_STR(VarR4FromStr
,"1.5",LOCALE_NOUSEROVERRIDE
); EXPECT(1.5f
);
2542 static void test_VarR4Copy(void)
2544 COPYTEST(77665544.0f
, VT_R4
, V_R4(&vSrc
), V_R4(&vDst
), V_R4REF(&vSrc
),V_R4REF(&vDst
), "%15.15f");
2547 static void test_VarR4ChangeTypeEx(void)
2549 #ifdef HAS_UINT64_TO_FLOAT
2552 VARIANTARG vSrc
, vDst
;
2556 INITIAL_TYPETEST(VT_R4
, V_R4
, "%f");
2566 #define CONV_TYPE double
2568 static void test_VarR8FromI1(void)
2570 CONVVARS(signed char);
2573 CONVERTRANGE(VarR8FromI1
, -128, 128);
2576 static void test_VarR8FromUI1(void)
2581 CONVERTRANGE(VarR8FromUI1
, 0, 256);
2584 static void test_VarR8FromI2(void)
2589 CONVERTRANGE(VarR8FromI2
, -32768, 32768);
2592 static void test_VarR8FromUI2(void)
2597 CONVERTRANGE(VarR8FromUI2
, 0, 65536);
2600 static void test_VarR8FromI4(void)
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);
2611 static void test_VarR8FromUI4(void)
2613 CONVVARS(unsigned int);
2615 CONVERT(VarR8FromUI4
, 0); EXPECT(0.0);
2616 CONVERT(VarR8FromUI4
, 1); EXPECT(1.0);
2617 CONVERT(VarR8FromUI4
, 0xffffffff); EXPECT(4294967295.0);
2620 static void test_VarR8FromR4(void)
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);
2629 /* Skip rounding tests - no rounding is done */
2632 static void test_VarR8FromBool(void)
2634 CONVVARS(VARIANT_BOOL
);
2636 CONVERT(VarR8FromBool
, VARIANT_TRUE
); EXPECT(VARIANT_TRUE
* 1.0);
2637 CONVERT(VarR8FromBool
, VARIANT_FALSE
); EXPECT(VARIANT_FALSE
* 1.0);
2640 static void test_VarR8FromCy(void)
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);
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);
2662 static void test_VarR8FromI8(void)
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);
2674 static void test_VarR8FromUI8(void)
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);
2685 static void test_VarR8FromDec(void)
2689 CONVERT_BADDEC(VarR8FromDec
);
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);
2697 CONVERT_DEC(VarR8FromDec
,2,0x80,0,3276800); EXPECT(-32768.0);
2698 CONVERT_DEC(VarR8FromDec
,2,0,0,3276700); EXPECT(32767.0);
2700 CONVERT_DEC(VarR8FromDec
,0,0,1,0); EXPECT(18446744073709551616.0);
2703 static void test_VarR8FromDate(void)
2707 CONVERT(VarR8FromDate
, -1.0); EXPECT(-1.0);
2708 CONVERT(VarR8FromDate
, -0.0); EXPECT(0.0);
2709 CONVERT(VarR8FromDate
, 1.0); EXPECT(1.0);
2712 static void test_VarR8FromStr(void)
2717 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
2719 CONVERT_STR(VarR8FromStr
,NULL
,0); EXPECT_MISMATCH
;
2720 CONVERT_STR(VarR8FromStr
,"",0); EXPECT_MISMATCH
;
2721 CONVERT_STR(VarR8FromStr
," ",0); EXPECT_MISMATCH
;
2723 CONVERT_STR(VarR8FromStr
,"0",LOCALE_NOUSEROVERRIDE
); EXPECT(0.0);
2724 CONVERT_STR(VarR8FromStr
,"-1.5",LOCALE_NOUSEROVERRIDE
); EXPECT(-1.5);
2725 CONVERT_STR(VarR8FromStr
,"-0.6",LOCALE_NOUSEROVERRIDE
); EXPECT(-0.6);
2726 CONVERT_STR(VarR8FromStr
,"-0.5",LOCALE_NOUSEROVERRIDE
); EXPECT(-0.5);
2727 CONVERT_STR(VarR8FromStr
,"-0.4",LOCALE_NOUSEROVERRIDE
); EXPECT(-0.4);
2728 CONVERT_STR(VarR8FromStr
,"0.4",LOCALE_NOUSEROVERRIDE
); EXPECT(0.4);
2729 CONVERT_STR(VarR8FromStr
,"0.5",LOCALE_NOUSEROVERRIDE
); EXPECT(0.5);
2730 CONVERT_STR(VarR8FromStr
,"0.6",LOCALE_NOUSEROVERRIDE
); EXPECT(0.6);
2731 CONVERT_STR(VarR8FromStr
,"1.5",LOCALE_NOUSEROVERRIDE
); EXPECT(1.5);
2732 CONVERT_STR(VarR8FromStr
,"1e-94938484",LOCALE_NOUSEROVERRIDE
); EXPECT(0);
2734 /* We already have exhaustive tests for number parsing, so skip those tests here */
2737 static void test_VarR8Copy(void)
2739 COPYTEST(77665544.0, VT_R8
, V_R8(&vSrc
), V_R8(&vDst
), V_R8REF(&vSrc
),V_R8REF(&vDst
), "%16.16g");
2742 static void test_VarR8ChangeTypeEx(void)
2744 #ifdef HAS_UINT64_TO_FLOAT
2747 VARIANTARG vSrc
, vDst
;
2751 INITIAL_TYPETEST(VT_R8
, V_R8
, "%g");
2756 #define MATHRND(l, r) left = l; right = r; hres = VarR8Round(left, right, &out)
2758 static void test_VarR8Round(void)
2761 double left
= 0.0, out
;
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
;
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
;
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);
2793 #define CONV_TYPE DATE
2795 static void test_VarDateFromI1(void)
2797 CONVVARS(signed char);
2800 CONVERTRANGE(VarDateFromI1
, -128, 128);
2803 static void test_VarDateFromUI1(void)
2808 CONVERTRANGE(VarDateFromUI1
, 0, 256);
2811 static void test_VarDateFromI2(void)
2816 CONVERTRANGE(VarDateFromI2
, -32768, 32768);
2819 static void test_VarDateFromUI2(void)
2824 CONVERTRANGE(VarDateFromUI2
, 0, 65536);
2827 static void test_VarDateFromI4(void)
2831 CONVERT(VarDateFromI4
, DATE_MIN
-1);
2832 if (hres
!= DISP_E_TYPEMISMATCH
) /* Early versions return this, incorrectly */
2834 CONVERT(VarDateFromI4
, DATE_MIN
); EXPECT(DATE_MIN
);
2835 CONVERT(VarDateFromI4
, -1); EXPECT(-1.0);
2836 CONVERT(VarDateFromI4
, 0); EXPECT(0.0);
2837 CONVERT(VarDateFromI4
, 1); EXPECT(1.0);
2838 CONVERT(VarDateFromI4
, DATE_MAX
); EXPECT(DATE_MAX
);
2839 CONVERT(VarDateFromI4
, DATE_MAX
+1);
2840 if (hres
!= DISP_E_TYPEMISMATCH
) /* Early versions return this, incorrectly */
2844 static void test_VarDateFromUI4(void)
2846 CONVVARS(unsigned int);
2848 CONVERT(VarDateFromUI4
, 0); EXPECT(0.0);
2849 CONVERT(VarDateFromUI4
, 1); EXPECT(1.0);
2850 CONVERT(VarDateFromUI4
, DATE_MAX
); EXPECT(DATE_MAX
);
2851 CONVERT(VarDateFromUI4
, DATE_MAX
+1);
2852 if (hres
!= DISP_E_TYPEMISMATCH
) /* Early versions return this, incorrectly */
2856 static void test_VarDateFromR4(void)
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);
2866 static void test_VarDateFromR8(void)
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);
2876 static void test_VarDateFromBool(void)
2878 CONVVARS(VARIANT_BOOL
);
2880 CONVERT(VarDateFromBool
, VARIANT_TRUE
); EXPECT(VARIANT_TRUE
* 1.0);
2881 CONVERT(VarDateFromBool
, VARIANT_FALSE
); EXPECT(VARIANT_FALSE
* 1.0);
2884 static void test_VarDateFromCy(void)
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);
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);
2906 static void test_VarDateFromI8(void)
2910 CONVERT(VarDateFromI8
, DATE_MIN
-1); EXPECT_OVERFLOW
;
2911 CONVERT(VarDateFromI8
, DATE_MIN
); EXPECT(DATE_MIN
);
2912 CONVERT(VarDateFromI8
, -1); EXPECT(-1.0);
2913 CONVERT(VarDateFromI8
, 0); EXPECT(0.0);
2914 CONVERT(VarDateFromI8
, 1); EXPECT(1.0);
2915 CONVERT(VarDateFromI8
, DATE_MAX
); EXPECT(DATE_MAX
);
2916 CONVERT(VarDateFromI8
, DATE_MAX
+1); EXPECT_OVERFLOW
;
2919 static void test_VarDateFromUI8(void)
2923 CONVERT(VarDateFromUI8
, 0); EXPECT(0.0);
2924 CONVERT(VarDateFromUI8
, 1); EXPECT(1.0);
2925 CONVERT(VarDateFromUI8
, DATE_MAX
); EXPECT(DATE_MAX
);
2926 CONVERT(VarDateFromUI8
, DATE_MAX
+1); EXPECT_OVERFLOW
;
2929 static void test_VarDateFromDec(void)
2933 CONVERT_BADDEC(VarDateFromDec
);
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);
2941 CONVERT_DEC(VarDateFromDec
,2,0x80,0,3276800); EXPECT(-32768.0);
2942 CONVERT_DEC(VarDateFromDec
,2,0,0,3276700); EXPECT(32767.0);
2946 buff[0] = '\0'; out = 0.0; \
2947 if (str) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)/sizeof(WCHAR)); \
2948 hres = VarDateFromStr(str ? buff : NULL,lcid,LOCALE_NOUSEROVERRIDE,&out)
2950 #define MKRELDATE(day,mth) st.wMonth = mth; st.wDay = day; \
2951 SystemTimeToVariantTime(&st,&relative)
2953 static const char * const BadDateStrings
[] =
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 */
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",
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",
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",
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",
2982 "1 2 am 3 4.5.6", "1 2 3 am 4.5.6"
2985 static void test_VarDateFromStr(void)
2993 OLECHAR with_ideographic_spaceW
[] = { '6','/','3','0','/','2','0','1','1',0x3000,
2994 '1',':','2','0',':','3','4',0 };
2996 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
2998 /* Some date formats are relative, so we need to find the current year */
3000 st
.wHour
= st
.wMinute
= st
.wSecond
= st
.wMilliseconds
= 0;
3001 DFS(NULL
); EXPECT_MISMATCH
;
3003 /* Floating point number are not recognised */
3006 EXPECT_DBL(0.0); /* Very old versions accept this string */
3010 /* 1 element - can only be a time, and only if it has am/pm */
3011 DFS("1 am"); EXPECT_DBL(0.04166666666666666);
3013 /* A decimal point is treated as a time separator.
3014 * The following are converted as hours/minutes.
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);
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.
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);
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
);
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);
3086 /* following throws an exception on winME */
3087 DFS("1 2 3.4.5"); MKRELDATE(2,1); relative
+= 0.12783564815; EXPECT_DBL(relative
);
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);
3094 for (i
= 0; i
< sizeof(BadDateStrings
)/sizeof(char*); i
++)
3096 DFS(BadDateStrings
[i
]); EXPECT_MISMATCH
;
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 */
3117 /* test a data with ideographic space */
3119 hres
= VarDateFromStr(with_ideographic_spaceW
, lcid
, LOCALE_NOUSEROVERRIDE
, &out
);
3120 EXPECT_DBL(40724.05594907407);
3122 /* test a non-english data string */
3123 DFS("02.01.1970"); EXPECT_MISMATCH
;
3124 DFS("02.01.1970 00:00:00"); EXPECT_MISMATCH
;
3125 lcid
= MAKELCID(MAKELANGID(LANG_GERMAN
,SUBLANG_GERMAN
),SORT_DEFAULT
);
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);
3132 DFS("02.01.1970 00:00:00"); EXPECT_DBL(25570.0);
3133 lcid
= MAKELCID(MAKELANGID(LANG_SPANISH
,SUBLANG_SPANISH
),SORT_DEFAULT
);
3134 DFS("02.01.1970"); EXPECT_MISMATCH
;
3135 DFS("02.01.1970 00:00:00"); EXPECT_MISMATCH
;
3138 static void test_VarDateCopy(void)
3140 COPYTEST(77665544.0, VT_DATE
, V_DATE(&vSrc
), V_DATE(&vDst
), V_DATEREF(&vSrc
),
3141 V_DATEREF(&vDst
), "%16.16g");
3144 static const char* wtoascii(LPWSTR lpszIn
)
3146 static char buff
[256];
3147 WideCharToMultiByte(CP_ACP
, 0, lpszIn
, -1, buff
, sizeof(buff
), NULL
, NULL
);
3151 static void test_VarDateChangeTypeEx(void)
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' };
3161 VARIANTARG vSrc
, vDst
;
3166 #ifdef HAS_UINT64_TO_FLOAT
3167 INITIAL_TYPETEST(VT_DATE
, V_DATE
, "%g");
3171 V_VT(&vDst
) = VT_EMPTY
;
3172 V_VT(&vSrc
) = VT_DATE
;
3173 V_DATE(&vSrc
) = 25570.0;
3174 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
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
);
3183 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
3186 hres
= VariantChangeTypeEx(&vDst
, &vSrc
, lcid
, VARIANT_NOUSEROVERRIDE
|VARIANT_USE_NLS
, VT_BSTR
);
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
);
3199 #define CONV_TYPE CY
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)
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)
3210 static void test_VarCyFromI1(void)
3212 CONVVARS(signed char);
3215 for (i
= -128; i
< 128; i
++)
3217 CONVERT(VarCyFromI1
,i
); EXPECTCY(i
);
3221 static void test_VarCyFromUI1(void)
3226 for (i
= 0; i
< 256; i
++)
3228 CONVERT(VarCyFromUI1
,i
); EXPECTCY(i
);
3232 static void test_VarCyFromI2(void)
3237 for (i
= -16384; i
< 16384; i
++)
3239 CONVERT(VarCyFromI2
,i
); EXPECTCY(i
);
3243 static void test_VarCyFromUI2(void)
3248 for (i
= 0; i
< 32768; i
++)
3250 CONVERT(VarCyFromUI2
,i
); EXPECTCY(i
);
3254 static void test_VarCyFromI4(void)
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);
3265 static void test_VarCyFromUI4(void)
3267 CONVVARS(unsigned int);
3269 CONVERT(VarCyFromUI4
, 0); EXPECTCY(0);
3270 CONVERT(VarCyFromUI4
, 1); EXPECTCY(1);
3271 CONVERT(VarCyFromUI4
, 0x80000000); EXPECTCY64(5000, 0);
3274 static void test_VarCyFromR4(void)
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);
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);
3305 static void test_VarCyFromR8(void)
3309 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3310 /* Test our rounding is exactly the same. This fails if the special x86
3311 * code is taken out of VarCyFromR8.
3313 CONVERT(VarCyFromR8
, -461168601842738.7904); EXPECTCY64(0xbfffffff, 0xffffff23);
3316 CONVERT(VarCyFromR8
, -4611686018427388416.1); EXPECT_OVERFLOW
;
3317 CONVERT(VarCyFromR8
, -1.0); EXPECTCY(-1);
3318 CONVERT(VarCyFromR8
, -0.0); EXPECTCY(0);
3319 CONVERT(VarCyFromR8
, 1.0); EXPECTCY(1);
3320 CONVERT(VarCyFromR8
, 4611686018427387648.0); EXPECT_OVERFLOW
;
3323 CONVERT(VarCyFromR8
, -1.5f
); EXPECTCY(-1.5);
3324 CONVERT(VarCyFromR8
, -0.6f
); EXPECTCY(-0.6);
3325 CONVERT(VarCyFromR8
, -0.5f
); EXPECTCY(-0.5);
3326 CONVERT(VarCyFromR8
, -0.4f
); EXPECTCY(-0.4);
3327 CONVERT(VarCyFromR8
, 0.4f
); EXPECTCY(0.4);
3328 CONVERT(VarCyFromR8
, 0.5f
); EXPECTCY(0.5);
3329 CONVERT(VarCyFromR8
, 0.6f
); EXPECTCY(0.6);
3330 CONVERT(VarCyFromR8
, 1.5f
); EXPECTCY(1.5);
3331 CONVERT(VarCyFromR8
, 1.00009f
); EXPECTCY(1.0001);
3332 CONVERT(VarCyFromR8
, -1.00001f
); EXPECTCY(-1);
3333 CONVERT(VarCyFromR8
, -1.00005f
); EXPECTCY(-1);
3334 CONVERT(VarCyFromR8
, -0.00009f
); EXPECTCY(-0.0001);
3335 CONVERT(VarCyFromR8
, -0.00005f
); EXPECTCY(0);
3336 CONVERT(VarCyFromR8
, -0.00001f
); EXPECTCY(0);
3337 CONVERT(VarCyFromR8
, 0.00001f
); EXPECTCY(0);
3338 CONVERT(VarCyFromR8
, 0.00005f
); EXPECTCY(0);
3339 CONVERT(VarCyFromR8
, 0.00009f
); EXPECTCY(0.0001);
3340 CONVERT(VarCyFromR8
, -1.00001f
); EXPECTCY(-1);
3341 CONVERT(VarCyFromR8
, -1.00005f
); EXPECTCY(-1);
3342 CONVERT(VarCyFromR8
, -1.00009f
); EXPECTCY(-1.0001);
3345 static void test_VarCyFromBool(void)
3347 CONVVARS(VARIANT_BOOL
);
3350 for (i
= -32768; i
< 32768; i
++)
3352 CONVERT(VarCyFromBool
, i
); EXPECTCY(i
);
3356 static void test_VarCyFromI8(void)
3360 CONVERT_I8(VarCyFromI8
, -214749, 2728163227ul); EXPECT_OVERFLOW
;
3361 CONVERT_I8(VarCyFromI8
, -214749, 2728163228ul); EXPECTCY64(2147483648ul,15808);
3362 CONVERT(VarCyFromI8
, -1); EXPECTCY(-1);
3363 CONVERT(VarCyFromI8
, 0); EXPECTCY(0);
3364 CONVERT(VarCyFromI8
, 1); EXPECTCY(1);
3365 CONVERT_I8(VarCyFromI8
, 214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3366 CONVERT_I8(VarCyFromI8
, 214748, 1566804069); EXPECT_OVERFLOW
;
3369 static void test_VarCyFromUI8(void)
3373 CONVERT(VarCyFromUI8
, 0); EXPECTCY(0);
3374 CONVERT(VarCyFromUI8
, 1); EXPECTCY(1);
3375 CONVERT_I8(VarCyFromUI8
, 214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3376 CONVERT_I8(VarCyFromUI8
, 214748, 1566804069); EXPECTCY64(2147483647ul, 4294961488ul);
3377 CONVERT_I8(VarCyFromUI8
, 214748, 1566804070); EXPECT_OVERFLOW
;
3378 CONVERT_I8(VarCyFromUI8
, 214749, 1566804068); EXPECT_OVERFLOW
;
3381 static void test_VarCyFromDec(void)
3385 CONVERT_BADDEC(VarCyFromDec
);
3387 CONVERT_DEC(VarCyFromDec
,0,0x80,0,1); EXPECTCY(-1);
3388 CONVERT_DEC(VarCyFromDec
,0,0,0,0); EXPECTCY(0);
3389 CONVERT_DEC(VarCyFromDec
,0,0,0,1); EXPECTCY(1);
3391 CONVERT_DEC64(VarCyFromDec
,0,0,0,214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3392 CONVERT_DEC64(VarCyFromDec
,0,0,0,214748, 1566804069); EXPECTCY64(2147483647ul, 4294961488ul);
3393 CONVERT_DEC64(VarCyFromDec
,0,0,0,214748, 1566804070); EXPECT_OVERFLOW
;
3394 CONVERT_DEC64(VarCyFromDec
,0,0,0,214749, 1566804068); EXPECT_OVERFLOW
;
3396 CONVERT_DEC(VarCyFromDec
,2,0,0,100); EXPECTCY(1);
3397 CONVERT_DEC(VarCyFromDec
,2,0x80,0,100); EXPECTCY(-1);
3398 CONVERT_DEC(VarCyFromDec
,2,0x80,0,1); EXPECTCY(-0.01);
3399 CONVERT_DEC(VarCyFromDec
,2,0,0,1); EXPECTCY(0.01);
3400 CONVERT_DEC(VarCyFromDec
,2,0x80,0,1); EXPECTCY(-0.01);
3401 CONVERT_DEC(VarCyFromDec
,2,0,0,999); EXPECTCY(9.99);
3402 CONVERT_DEC(VarCyFromDec
,2,0x80,0,999); EXPECTCY(-9.99);
3403 CONVERT_DEC(VarCyFromDec
,2,0,0,1500); EXPECTCY(15);
3404 CONVERT_DEC(VarCyFromDec
,2,0x80,0,1500); EXPECTCY(-15);
3407 static void test_VarCyFromDate(void)
3411 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3412 CONVERT(VarCyFromR8
, -461168601842738.7904); EXPECTCY64(0xbfffffff, 0xffffff23);
3415 CONVERT(VarCyFromDate
, -1.0); EXPECTCY(-1);
3416 CONVERT(VarCyFromDate
, -0.0); EXPECTCY(0);
3417 CONVERT(VarCyFromDate
, 1.0); EXPECTCY(1);
3418 CONVERT(VarCyFromDate
, -4611686018427388416.1); EXPECT_OVERFLOW
;
3419 CONVERT(VarCyFromDate
, 4611686018427387648.0); EXPECT_OVERFLOW
;
3422 CONVERT(VarCyFromDate
, -1.5f
); EXPECTCY(-1.5);
3423 CONVERT(VarCyFromDate
, -0.6f
); EXPECTCY(-0.6);
3424 CONVERT(VarCyFromDate
, -0.5f
); EXPECTCY(-0.5);
3425 CONVERT(VarCyFromDate
, -0.4f
); EXPECTCY(-0.4);
3426 CONVERT(VarCyFromDate
, 0.4f
); EXPECTCY(0.4);
3427 CONVERT(VarCyFromDate
, 0.5f
); EXPECTCY(0.5);
3428 CONVERT(VarCyFromDate
, 0.6f
); EXPECTCY(0.6);
3429 CONVERT(VarCyFromDate
, 1.5f
); EXPECTCY(1.5);
3430 CONVERT(VarCyFromDate
, 1.00009f
); EXPECTCY(1.0001);
3431 CONVERT(VarCyFromDate
, -1.00001f
); EXPECTCY(-1);
3432 CONVERT(VarCyFromDate
, -1.00005f
); EXPECTCY(-1);
3433 CONVERT(VarCyFromDate
, -0.00009f
); EXPECTCY(-0.0001);
3434 CONVERT(VarCyFromDate
, -0.00005f
); EXPECTCY(0);
3435 CONVERT(VarCyFromDate
, -0.00001f
); EXPECTCY(0);
3436 CONVERT(VarCyFromDate
, 0.00001f
); EXPECTCY(0);
3437 CONVERT(VarCyFromDate
, 0.00005f
); EXPECTCY(0);
3438 CONVERT(VarCyFromDate
, 0.00009f
); EXPECTCY(0.0001);
3439 CONVERT(VarCyFromDate
, -1.00001f
); EXPECTCY(-1);
3440 CONVERT(VarCyFromDate
, -1.00005f
); EXPECTCY(-1);
3441 CONVERT(VarCyFromDate
, -1.00009f
); EXPECTCY(-1.0001);
3444 #define MATHVARS1 HRESULT hres; double left = 0.0; CY cyLeft, out
3445 #define MATHVARS2 MATHVARS1; double right = 0.0; CY cyRight
3446 #define MATH1(func, l) left = (double)l; VarCyFromR8(left, &cyLeft); hres = func(cyLeft, &out)
3447 #define MATH2(func, l, r) left = (double)l; right = (double)r; \
3448 VarCyFromR8(left, &cyLeft); VarCyFromR8(right, &cyRight); \
3449 hres = func(cyLeft, cyRight, &out)
3451 static void test_VarCyAdd(void)
3455 MATH2(VarCyAdd
, 0.5, 0.5); EXPECTCY(1);
3456 MATH2(VarCyAdd
, 0.5, -0.4); EXPECTCY(0.1);
3457 MATH2(VarCyAdd
, 0.5, -0.6); EXPECTCY(-0.1);
3458 MATH2(VarCyAdd
, -0.5, -0.5); EXPECTCY(-1);
3459 MATH2(VarCyAdd
, -922337203685476.0, -922337203685476.0); EXPECT_OVERFLOW
;
3460 MATH2(VarCyAdd
, -922337203685476.0, 922337203685476.0); EXPECTCY(0);
3461 MATH2(VarCyAdd
, 922337203685476.0, -922337203685476.0); EXPECTCY(0);
3462 MATH2(VarCyAdd
, 922337203685476.0, 922337203685476.0); EXPECT_OVERFLOW
;
3465 static void test_VarCyMul(void)
3469 MATH2(VarCyMul
, 534443.0, 0.0); EXPECTCY(0);
3470 MATH2(VarCyMul
, 0.5, 0.5); EXPECTCY(0.25);
3471 MATH2(VarCyMul
, 0.5, -0.4); EXPECTCY(-0.2);
3472 MATH2(VarCyMul
, 0.5, -0.6); EXPECTCY(-0.3);
3473 MATH2(VarCyMul
, -0.5, -0.5); EXPECTCY(0.25);
3474 MATH2(VarCyMul
, 922337203685476.0, 20000); EXPECT_OVERFLOW
;
3477 static void test_VarCySub(void)
3481 MATH2(VarCySub
, 0.5, 0.5); EXPECTCY(0);
3482 MATH2(VarCySub
, 0.5, -0.4); EXPECTCY(0.9);
3483 MATH2(VarCySub
, 0.5, -0.6); EXPECTCY(1.1);
3484 MATH2(VarCySub
, -0.5, -0.5); EXPECTCY(0);
3485 MATH2(VarCySub
, -922337203685476.0, -922337203685476.0); EXPECTCY(0);
3486 MATH2(VarCySub
, -922337203685476.0, 922337203685476.0); EXPECT_OVERFLOW
;
3487 MATH2(VarCySub
, 922337203685476.0, -922337203685476.0); EXPECT_OVERFLOW
;
3488 MATH2(VarCySub
, 922337203685476.0, 922337203685476.0); EXPECTCY(0);
3491 static void test_VarCyAbs(void)
3495 MATH1(VarCyAbs
, 0.5); EXPECTCY(0.5);
3496 MATH1(VarCyAbs
, -0.5); EXPECTCY(0.5);
3497 MATH1(VarCyAbs
, 922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3498 MATH1(VarCyAbs
, -922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3501 static void test_VarCyNeg(void)
3505 MATH1(VarCyNeg
, 0.5); EXPECTCY(-0.5);
3506 MATH1(VarCyNeg
, -0.5); EXPECTCY(0.5);
3507 MATH1(VarCyNeg
, 922337203685476.0); EXPECTCY64(2147483648ul,15808);
3508 MATH1(VarCyNeg
, -922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3511 #define MATHMULI4(l, r) left = l; right = r; VarCyFromR8(left, &cyLeft); \
3512 hres = VarCyMulI4(cyLeft, right, &out)
3514 static void test_VarCyMulI4(void)
3519 MATHMULI4(534443.0, 0); EXPECTCY(0);
3520 MATHMULI4(0.5, 1); EXPECTCY(0.5);
3521 MATHMULI4(0.5, 2); EXPECTCY(1);
3522 MATHMULI4(922337203685476.0, 1); EXPECTCY64(2147483647ul,4294951488ul);
3523 MATHMULI4(922337203685476.0, 2); EXPECT_OVERFLOW
;
3526 #define MATHMULI8(l, r) left = l; right = r; VarCyFromR8(left, &cyLeft); \
3527 hres = VarCyMulI8(cyLeft, right, &out)
3529 static void test_VarCyMulI8(void)
3534 MATHMULI8(534443.0, 0); EXPECTCY(0);
3535 MATHMULI8(0.5, 1); EXPECTCY(0.5);
3536 MATHMULI8(0.5, 2); EXPECTCY(1);
3537 MATHMULI8(922337203685476.0, 1); EXPECTCY64(2147483647ul,4294951488ul);
3538 MATHMULI8(922337203685476.0, 2); EXPECT_OVERFLOW
;
3541 #define MATHCMP(l, r) left = l; right = r; VarCyFromR8(left, &cyLeft); VarCyFromR8(right, &cyRight); \
3542 hres = VarCyCmp(cyLeft, cyRight)
3544 static void test_VarCyCmp(void)
3547 double left
= 0.0, right
= 0.0;
3550 MATHCMP(-1.0, -1.0); EXPECT_EQ
;
3551 MATHCMP(-1.0, 0.0); EXPECT_LT
;
3552 MATHCMP(-1.0, 1.0); EXPECT_LT
;
3553 MATHCMP(-1.0, 2.0); EXPECT_LT
;
3554 MATHCMP(0.0, 1.0); EXPECT_LT
;
3555 MATHCMP(0.0, 0.0); EXPECT_EQ
;
3556 MATHCMP(0.0, -1.0); EXPECT_GT
;
3557 MATHCMP(1.0, -1.0); EXPECT_GT
;
3558 MATHCMP(1.0, 0.0); EXPECT_GT
;
3559 MATHCMP(1.0, 1.0); EXPECT_EQ
;
3560 MATHCMP(1.0, 2.0); EXPECT_LT
;
3563 #define MATHCMPR8(l, r) left = l; right = r; VarCyFromR8(left, &cyLeft); \
3564 hres = VarCyCmpR8(cyLeft, right);
3566 static void test_VarCyCmpR8(void)
3573 MATHCMPR8(-1.0, -1.0); EXPECT_EQ
;
3574 MATHCMPR8(-1.0, 0.0); EXPECT_LT
;
3575 MATHCMPR8(-1.0, 1.0); EXPECT_LT
;
3576 MATHCMPR8(-1.0, 2.0); EXPECT_LT
;
3577 MATHCMPR8(0.0, 1.0); EXPECT_LT
;
3578 MATHCMPR8(0.0, 0.0); EXPECT_EQ
;
3579 MATHCMPR8(0.0, -1.0); EXPECT_GT
;
3580 MATHCMPR8(1.0, -1.0); EXPECT_GT
;
3581 MATHCMPR8(1.0, 0.0); EXPECT_GT
;
3582 MATHCMPR8(1.0, 1.0); EXPECT_EQ
;
3583 MATHCMPR8(1.0, 2.0); EXPECT_LT
;
3587 #define MATHRND(l, r) left = l; right = r; VarCyFromR8(left, &cyLeft); \
3588 hres = VarCyRound(cyLeft, right, &out)
3590 static void test_VarCyRound(void)
3595 MATHRND(0.5432, 5); EXPECTCY(0.5432);
3596 MATHRND(0.5432, 4); EXPECTCY(0.5432);
3597 MATHRND(0.5432, 3); EXPECTCY(0.543);
3598 MATHRND(0.5432, 2); EXPECTCY(0.54);
3599 MATHRND(0.5432, 1); EXPECTCY(0.5);
3600 MATHRND(0.5532, 0); EXPECTCY(1);
3601 MATHRND(0.5532, -1); EXPECT_INVALID
;
3603 MATHRND(0.5568, 5); EXPECTCY(0.5568);
3604 MATHRND(0.5568, 4); EXPECTCY(0.5568);
3605 MATHRND(0.5568, 3); EXPECTCY(0.557);
3606 MATHRND(0.5568, 2); EXPECTCY(0.56);
3607 MATHRND(0.5568, 1); EXPECTCY(0.6);
3608 MATHRND(0.5568, 0); EXPECTCY(1);
3609 MATHRND(0.5568, -1); EXPECT_INVALID
;
3611 MATHRND(0.4999, 0); EXPECTCY(0);
3612 MATHRND(0.5000, 0); EXPECTCY(0);
3613 MATHRND(0.5001, 0); EXPECTCY(1);
3614 MATHRND(1.4999, 0); EXPECTCY(1);
3615 MATHRND(1.5000, 0); EXPECTCY(2);
3616 MATHRND(1.5001, 0); EXPECTCY(2);
3619 #define MATHFIX(l) left = l; VarCyFromR8(left, &cyLeft); \
3620 hres = VarCyFix(cyLeft, &out)
3622 static void test_VarCyFix(void)
3626 MATHFIX(-1.0001); EXPECTCY(-1);
3627 MATHFIX(-1.4999); EXPECTCY(-1);
3628 MATHFIX(-1.5001); EXPECTCY(-1);
3629 MATHFIX(-1.9999); EXPECTCY(-1);
3630 MATHFIX(-0.0001); EXPECTCY(0);
3631 MATHFIX(-0.4999); EXPECTCY(0);
3632 MATHFIX(-0.5001); EXPECTCY(0);
3633 MATHFIX(-0.9999); EXPECTCY(0);
3634 MATHFIX(0.0001); EXPECTCY(0);
3635 MATHFIX(0.4999); EXPECTCY(0);
3636 MATHFIX(0.5001); EXPECTCY(0);
3637 MATHFIX(0.9999); EXPECTCY(0);
3638 MATHFIX(1.0001); EXPECTCY(1);
3639 MATHFIX(1.4999); EXPECTCY(1);
3640 MATHFIX(1.5001); EXPECTCY(1);
3641 MATHFIX(1.9999); EXPECTCY(1);
3644 #define MATHINT(l) left = l; VarCyFromR8(left, &cyLeft); \
3645 hres = VarCyInt(cyLeft, &out)
3647 static void test_VarCyInt(void)
3651 MATHINT(-1.0001); EXPECTCY(-2);
3652 MATHINT(-1.4999); EXPECTCY(-2);
3653 MATHINT(-1.5001); EXPECTCY(-2);
3654 MATHINT(-1.9999); EXPECTCY(-2);
3655 MATHINT(-0.0001); EXPECTCY(-1);
3656 MATHINT(-0.4999); EXPECTCY(-1);
3657 MATHINT(-0.5001); EXPECTCY(-1);
3658 MATHINT(-0.9999); EXPECTCY(-1);
3659 MATHINT(0.0001); EXPECTCY(0);
3660 MATHINT(0.4999); EXPECTCY(0);
3661 MATHINT(0.5001); EXPECTCY(0);
3662 MATHINT(0.9999); EXPECTCY(0);
3663 MATHINT(1.0001); EXPECTCY(1);
3664 MATHINT(1.4999); EXPECTCY(1);
3665 MATHINT(1.5001); EXPECTCY(1);
3666 MATHINT(1.9999); EXPECTCY(1);
3674 #define CONV_TYPE DECIMAL
3676 #define EXPECTDEC(scl, sgn, hi, lo) ok(hres == S_OK && \
3677 S(U(out)).scale == (BYTE)(scl) && S(U(out)).sign == (BYTE)(sgn) && \
3678 out.Hi32 == (ULONG)(hi) && U1(out).Lo64 == (ULONG64)(lo), \
3679 "expected (%d,%d,%d,(%x %x)), got (%d,%d,%d,(%x %x)) hres 0x%08x\n", \
3680 scl, sgn, hi, (LONG)((LONG64)(lo) >> 32), (LONG)((lo) & 0xffffffff), S(U(out)).scale, \
3681 S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres)
3683 #define EXPECTDEC64(scl, sgn, hi, mid, lo) ok(hres == S_OK && \
3684 S(U(out)).scale == (BYTE)(scl) && S(U(out)).sign == (BYTE)(sgn) && \
3685 out.Hi32 == (ULONG)(hi) && S1(U1(out)).Mid32 == (ULONG)(mid) && \
3686 S1(U1(out)).Lo32 == (ULONG)(lo), \
3687 "expected (%d,%d,%d,(%x %x)), got (%d,%d,%d,(%x %x)) hres 0x%08x\n", \
3688 scl, sgn, hi, (LONG)(mid), (LONG)(lo), S(U(out)).scale, \
3689 S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres)
3691 /* expect either a positive or negative zero */
3692 #define EXPECTDECZERO() ok(hres == S_OK && S(U(out)).scale == 0 && \
3693 (S(U(out)).sign == 0 || S(U(out)).sign == 0x80) && out.Hi32 == 0 && U1(out).Lo64 == 0, \
3694 "expected zero, got (%d,%d,%d,(%x %x)) hres 0x%08x\n", \
3695 S(U(out)).scale, S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres)
3697 #define EXPECTDECI if (i < 0) EXPECTDEC(0, 0x80, 0, -i); else EXPECTDEC(0, 0, 0, i)
3699 static void test_VarDecFromI1(void)
3701 CONVVARS(signed char);
3704 for (i
= -128; i
< 128; i
++)
3706 CONVERT(VarDecFromI1
,i
); EXPECTDECI
;
3710 static void test_VarDecFromI2(void)
3715 for (i
= -32768; i
< 32768; i
++)
3717 CONVERT(VarDecFromI2
,i
); EXPECTDECI
;
3721 static void test_VarDecFromI4(void)
3726 for (i
= -32768; i
< 32768; i
++)
3728 CONVERT(VarDecFromI4
,i
); EXPECTDECI
;
3732 static void test_VarDecFromI8(void)
3737 for (i
= -32768; i
< 32768; i
++)
3739 CONVERT(VarDecFromI8
,i
); EXPECTDECI
;
3743 static void test_VarDecFromUI1(void)
3748 for (i
= 0; i
< 256; i
++)
3750 CONVERT(VarDecFromUI1
,i
); EXPECTDECI
;
3754 static void test_VarDecFromUI2(void)
3759 for (i
= 0; i
< 65536; i
++)
3761 CONVERT(VarDecFromUI2
,i
); EXPECTDECI
;
3765 static void test_VarDecFromUI4(void)
3770 for (i
= 0; i
< 65536; i
++)
3772 CONVERT(VarDecFromUI4
,i
); EXPECTDECI
;
3776 static void test_VarDecFromUI8(void)
3781 for (i
= 0; i
< 65536; i
++)
3783 CONVERT(VarDecFromUI8
,i
); EXPECTDECI
;
3787 static void test_VarDecFromBool(void)
3792 /* Test all possible type values. Note that the result is reduced to 0 or -1 */
3793 for (i
= -32768; i
< 0; i
++)
3795 CONVERT(VarDecFromBool
,i
);
3797 EXPECTDEC(0,0x80,0,1);
3803 static void test_VarDecFromR4(void)
3807 CONVERT(VarDecFromR4
,-0.6f
); EXPECTDEC(1,0x80,0,6);
3808 CONVERT(VarDecFromR4
,-0.5f
); EXPECTDEC(1,0x80,0,5);
3809 CONVERT(VarDecFromR4
,-0.4f
); EXPECTDEC(1,0x80,0,4);
3810 CONVERT(VarDecFromR4
,0.0f
); EXPECTDEC(0,0,0,0);
3811 CONVERT(VarDecFromR4
,0.4f
); EXPECTDEC(1,0,0,4);
3812 CONVERT(VarDecFromR4
,0.5f
); EXPECTDEC(1,0,0,5);
3813 CONVERT(VarDecFromR4
,0.6f
); EXPECTDEC(1,0,0,6);
3816 static void test_VarDecFromR8(void)
3820 CONVERT(VarDecFromR8
,-0.6); EXPECTDEC(1,0x80,0,6);
3821 CONVERT(VarDecFromR8
,-0.5); EXPECTDEC(1,0x80,0,5);
3822 CONVERT(VarDecFromR8
,-0.4); EXPECTDEC(1,0x80,0,4);
3823 CONVERT(VarDecFromR8
,0.0); EXPECTDEC(0,0,0,0);
3824 CONVERT(VarDecFromR8
,0.4); EXPECTDEC(1,0,0,4);
3825 CONVERT(VarDecFromR8
,0.5); EXPECTDEC(1,0,0,5);
3826 CONVERT(VarDecFromR8
,0.6); EXPECTDEC(1,0,0,6);
3829 static void test_VarDecFromDate(void)
3833 CONVERT(VarDecFromDate
,-0.6); EXPECTDEC(1,0x80,0,6);
3834 CONVERT(VarDecFromDate
,-0.5); EXPECTDEC(1,0x80,0,5);
3835 CONVERT(VarDecFromDate
,-0.4); EXPECTDEC(1,0x80,0,4);
3836 CONVERT(VarDecFromDate
,0.0); EXPECTDEC(0,0,0,0);
3837 CONVERT(VarDecFromDate
,0.4); EXPECTDEC(1,0,0,4);
3838 CONVERT(VarDecFromDate
,0.5); EXPECTDEC(1,0,0,5);
3839 CONVERT(VarDecFromDate
,0.6); EXPECTDEC(1,0,0,6);
3842 static void test_VarDecFromStr(void)
3847 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
3849 CONVERT_STR(VarDecFromStr
,NULL
,0); EXPECT_MISMATCH
;
3850 CONVERT_STR(VarDecFromStr
,"-1", LOCALE_NOUSEROVERRIDE
); EXPECTDEC(0,0x80,0,1);
3851 CONVERT_STR(VarDecFromStr
,"0", LOCALE_NOUSEROVERRIDE
); EXPECTDEC(0,0,0,0);
3852 CONVERT_STR(VarDecFromStr
,"1", LOCALE_NOUSEROVERRIDE
); EXPECTDEC(0,0,0,1);
3853 CONVERT_STR(VarDecFromStr
,"0.5", LOCALE_NOUSEROVERRIDE
); EXPECTDEC(1,0,0,5);
3854 CONVERT_STR(VarDecFromStr
,"4294967296", LOCALE_NOUSEROVERRIDE
); EXPECTDEC64(0,0,0,1,0);
3855 CONVERT_STR(VarDecFromStr
,"18446744073709551616", LOCALE_NOUSEROVERRIDE
); EXPECTDEC(0,0,1,0);
3856 CONVERT_STR(VarDecFromStr
,"4294967296.0", LOCALE_NOUSEROVERRIDE
); EXPECTDEC64(0,0,0,1,0);
3857 CONVERT_STR(VarDecFromStr
,"18446744073709551616.0", LOCALE_NOUSEROVERRIDE
); EXPECTDEC(0,0,1,0);
3860 static void test_VarDecFromCy(void)
3864 CONVERT_CY(VarDecFromCy
, -1); EXPECTDEC(4,0x80,0,10000);
3865 CONVERT_CY(VarDecFromCy
, 0); EXPECTDEC(4,0,0,0);
3866 CONVERT_CY(VarDecFromCy
, 1); EXPECTDEC(4,0,0,10000);
3867 CONVERT_CY(VarDecFromCy
, 0.5); EXPECTDEC(4,0,0,5000);
3871 #define MATHVARS1 HRESULT hres; DECIMAL l, out
3873 #define MATHVARS2 MATHVARS1; DECIMAL r
3875 #define MATH1(func) hres = func(&l, &out)
3877 #define MATH2(func) hres = func(&l, &r, &out)
3879 #define MATH3(func) hres = func(&l, r)
3881 static void test_VarDecAbs(void)
3885 SETDEC(l
,0,0x80,0,1); MATH1(VarDecAbs
); EXPECTDEC(0,0,0,1);
3886 SETDEC(l
,0,0,0,0); MATH1(VarDecAbs
); EXPECTDEC(0,0,0,0);
3887 SETDEC(l
,0,0x80,0,0); MATH1(VarDecAbs
); EXPECTDEC(0,0,0,0);
3888 SETDEC(l
,0,0,0,1); MATH1(VarDecAbs
); EXPECTDEC(0,0,0,1);
3890 /* Doesn't check for invalid input */
3891 SETDEC(l
,0,0x7f,0,1); MATH1(VarDecAbs
); EXPECTDEC(0,0x7f,0,1);
3892 SETDEC(l
,0,0x80,29,1); MATH1(VarDecAbs
); EXPECTDEC(0,0,29,1);
3895 static void test_VarDecNeg(void)
3899 SETDEC(l
,0,0x80,0,1); MATH1(VarDecNeg
); EXPECTDEC(0,0,0,1);
3900 SETDEC(l
,0,0,0,0); MATH1(VarDecNeg
); EXPECTDEC(0,0x80,0,0); /* '-0'! */
3901 SETDEC(l
,0,0x80,0,0); MATH1(VarDecNeg
); EXPECTDEC(0,0,0,0);
3902 SETDEC(l
,0,0,0,1); MATH1(VarDecNeg
); EXPECTDEC(0,0x80,0,1);
3904 /* Doesn't check for invalid input */
3905 SETDEC(l
,0,0x7f,0,1); MATH1(VarDecNeg
); EXPECTDEC(0,0xff,0,1);
3906 SETDEC(l
,0,0x80,29,1); MATH1(VarDecNeg
); EXPECTDEC(0,0,29,1);
3907 SETDEC(l
,0,0,29,1); MATH1(VarDecNeg
); EXPECTDEC(0,0x80,29,1);
3910 static void test_VarDecAdd(void)
3914 SETDEC(l
,0,0,0,0); SETDEC(r
,0,0,0,0); MATH2(VarDecAdd
); EXPECTDEC(0,0,0,0);
3915 SETDEC(l
,0,0,0,0); SETDEC(r
,0,0x80,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0x80,0,1);
3916 SETDEC(l
,0,0,0,0); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0,0,1);
3918 SETDEC(l
,0,0,0,1); SETDEC(r
,0,0,0,0); MATH2(VarDecAdd
); EXPECTDEC(0,0,0,1);
3919 SETDEC(l
,0,0,0,1); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0,0,2);
3920 SETDEC(l
,0,0,0,1); SETDEC(r
,0,0x80,0,1); MATH2(VarDecAdd
); EXPECTDECZERO();
3921 SETDEC(l
,0,0,0,1); SETDEC(r
,0,0x80,0,2); MATH2(VarDecAdd
); EXPECTDEC(0,0x80,0,1);
3923 SETDEC(l
,0,0x80,0,0); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0,0,1);
3924 SETDEC(l
,0,0x80,0,1); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDECZERO();
3925 SETDEC(l
,0,0x80,0,1); SETDEC(r
,0,0,0,2); MATH2(VarDecAdd
); EXPECTDEC(0,0,0,1);
3926 SETDEC(l
,0,0x80,0,1); SETDEC(r
,0,0x80,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0x80,0,2);
3927 SETDEC(l
,0,0x80,0,2); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0x80,0,1);
3929 SETDEC(l
,0,0,0,0xffffffff); SETDEC(r
,0,0x80,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0,0,0xfffffffe);
3930 SETDEC(l
,0,0,0,0xffffffff); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0,0,(ULONG64
)1 << 32);
3931 SETDEC(l
,0,0,0,0xffffffff); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0,0,(ULONG64
)1 << 32);
3933 SETDEC64(l
,0,0,0,0xffffffff,0); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC64(0,0,0,0xffffffff,1);
3934 SETDEC64(l
,0,0,0,0xffffffff,0); SETDEC(r
,0,0x80,0,1); MATH2(VarDecAdd
);
3935 EXPECTDEC64(0,0,0,0xfffffffe,0xffffffff);
3937 SETDEC64(l
,0,0,0,0xffffffff,0xffffffff); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0,1,0);
3938 SETDEC64(l
,0,0,0,0xffffffff,0xffffffff); SETDEC(r
,0,0x80,0,1); MATH2(VarDecAdd
);
3939 EXPECTDEC64(0,0,0,0xffffffff,0xfffffffe);
3941 SETDEC(l
,0,0,0xffffffff,0); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0,0xffffffff,1);
3942 SETDEC(l
,0,0,0xffffffff,0); SETDEC(r
,0,0x80,0,1); MATH2(VarDecAdd
);
3943 EXPECTDEC64(0,0,0xfffffffe,0xffffffff,0xffffffff);
3945 SETDEC64(l
,0,0,0xffffffff,0xffffffff,0xffffffff);SETDEC(r
,0,0x80,0,1); MATH2(VarDecAdd
);
3946 EXPECTDEC64(0,0,0xffffffff,0xffffffff,0xfffffffe);
3947 SETDEC64(l
,0,0,0xffffffff,0xffffffff,0xffffffff);SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
);
3948 ok(hres
== DISP_E_OVERFLOW
,"Expected overflow, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
3949 S(U(out
)).scale
, S(U(out
)).sign
, out
.Hi32
, S1(U1(out
)).Mid32
, S1(U1(out
)).Lo32
, hres
);
3951 SETDEC64(l
,1,0,0xffffffff,0xffffffff,0xffffffff);SETDEC(r
,1,0,0,1); MATH2(VarDecAdd
);
3952 todo_wine
EXPECTDEC64(0,0,0x19999999,0x99999999,0x9999999A);
3954 SETDEC64(l
,0,0,0xe22ea493,0xb30310a7,0x70000000);SETDEC64(r
,0,0,0xe22ea493,0xb30310a7,0x70000000); MATH2(VarDecAdd
);
3955 ok(hres
== DISP_E_OVERFLOW
,"Expected overflow, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
3956 S(U(out
)).scale
, S(U(out
)).sign
, out
.Hi32
, S1(U1(out
)).Mid32
, S1(U1(out
)).Lo32
, hres
);
3958 SETDEC64(l
,1,0,0xe22ea493,0xb30310a7,0x70000000);SETDEC64(r
,1,0,0xe22ea493,0xb30310a7,0x70000000); MATH2(VarDecAdd
);
3959 todo_wine
EXPECTDEC64(0,0,0x2d3c8750,0xbd670354,0xb0000000);
3961 SETDEC(l
,3,128,0,123456); SETDEC64(r
,0,0,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF);
3962 MATH2(VarDecAdd
); EXPECTDEC64(0,0,-1,0xFFFFFFFF,0xFFFFFF84);
3964 SETDEC(l
,3,0,0,123456); SETDEC64(r
,0,0,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF); MATH2(VarDecAdd
);
3965 ok(hres
== DISP_E_OVERFLOW
,"Expected overflow, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
3966 S(U(out
)).scale
, S(U(out
)).sign
, out
.Hi32
, S1(U1(out
)).Mid32
, S1(U1(out
)).Lo32
, hres
);
3968 SETDEC(l
,4,0,0,123456); SETDEC64(r
,0,0,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF); MATH2(VarDecAdd
);
3969 ok(hres
== DISP_E_OVERFLOW
,"Expected overflow, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
3970 S(U(out
)).scale
, S(U(out
)).sign
, out
.Hi32
, S1(U1(out
)).Mid32
, S1(U1(out
)).Lo32
, hres
);
3972 SETDEC(l
,5,0,0,123456); SETDEC64(r
,0,0,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF); MATH2(VarDecAdd
);
3973 ok(hres
== DISP_E_OVERFLOW
,"Expected overflow, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
3974 S(U(out
)).scale
, S(U(out
)).sign
, out
.Hi32
, S1(U1(out
)).Mid32
, S1(U1(out
)).Lo32
, hres
);
3976 SETDEC(l
,6,0,0,123456); SETDEC64(r
,0,0,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF);
3977 MATH2(VarDecAdd
); EXPECTDEC64(0,0,-1,0xFFFFFFFF,0xFFFFFFFF);
3979 SETDEC(l
,3,128,0,123456); SETDEC64(r
,0,0,0x19999999,0x99999999,0x99999999);
3980 MATH2(VarDecAdd
); EXPECTDEC64(1,0,-1,0xFFFFFFFF,0xFFFFFB27);
3982 SETDEC(l
,3,128,0,123567); SETDEC64(r
,0,0,0x19999999,0x99999999,0x99999999);
3983 MATH2(VarDecAdd
); EXPECTDEC64(1,0,-1,0xFFFFFFFF,0xFFFFFB26);
3985 /* Promotes to the highest scale, so here the results are in the scale of 2 */
3986 SETDEC(l
,2,0,0,0); SETDEC(r
,0,0,0,0); MATH2(VarDecAdd
); EXPECTDEC(2,0,0,0);
3987 SETDEC(l
,2,0,0,100); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC(2,0,0,200);
3990 static void test_VarDecSub(void)
3994 SETDEC(l
,0,0,0,0); SETDEC(r
,0,0,0,0); MATH2(VarDecSub
); EXPECTDECZERO();
3995 SETDEC(l
,0,0,0,0); SETDEC(r
,0,0,0,1); MATH2(VarDecSub
); EXPECTDEC(0,0x80,0,1);
3996 SETDEC(l
,0,0,0,1); SETDEC(r
,0,0,0,1); MATH2(VarDecSub
); EXPECTDECZERO();
3997 SETDEC(l
,0,0,0,1); SETDEC(r
,0,0x80,0,1); MATH2(VarDecSub
); EXPECTDEC(0,0,0,2);
4000 static void test_VarDecMul(void)
4004 SETDEC(l
,0,0,0,0); SETDEC(r
,0,0,0,0); MATH2(VarDecMul
); EXPECTDEC(0,0,0,0);
4005 SETDEC(l
,0,0,0,1); SETDEC(r
,0,0,0,0); MATH2(VarDecMul
); EXPECTDEC(0,0,0,0);
4006 SETDEC(l
,0,0,0,0); SETDEC(r
,0,0,0,1); MATH2(VarDecMul
); EXPECTDEC(0,0,0,0);
4007 SETDEC(l
,0,0,0,1); SETDEC(r
,0,0,0,1); MATH2(VarDecMul
); EXPECTDEC(0,0,0,1);
4008 SETDEC(l
,0,0,0,45000);SETDEC(r
,0,0,0,2); MATH2(VarDecMul
); EXPECTDEC(0,0,0,90000);
4009 SETDEC(l
,0,0,0,2); SETDEC(r
,0,0,0,45000); MATH2(VarDecMul
); EXPECTDEC(0,0,0,90000);
4011 SETDEC(l
,0,0x80,0,2); SETDEC(r
,0,0,0,2); MATH2(VarDecMul
); EXPECTDEC(0,0x80,0,4);
4012 SETDEC(l
,0,0,0,2); SETDEC(r
,0,0x80,0,2); MATH2(VarDecMul
); EXPECTDEC(0,0x80,0,4);
4013 SETDEC(l
,0,0x80,0,2); SETDEC(r
,0,0x80,0,2); MATH2(VarDecMul
); EXPECTDEC(0,0,0,4);
4015 SETDEC(l
,4,0,0,2); SETDEC(r
,0,0,0,2); MATH2(VarDecMul
); EXPECTDEC(4,0,0,4);
4016 SETDEC(l
,0,0,0,2); SETDEC(r
,3,0,0,2); MATH2(VarDecMul
); EXPECTDEC(3,0,0,4);
4017 SETDEC(l
,4,0,0,2); SETDEC(r
,3,0,0,2); MATH2(VarDecMul
); EXPECTDEC(7,0,0,4);
4018 /* this last one shows that native oleaut32 does *not* gratuitously seize opportunities
4019 to reduce the scale if possible - the canonical result for the expected value is (6,0,0,1)
4021 SETDEC(l
,4,0,0,5); SETDEC(r
,3,0,0,2); MATH2(VarDecMul
); EXPECTDEC(7,0,0,10);
4023 SETDEC64(l
,0,0,0,0xFFFFFFFF,0xFFFFFFFF); SETDEC(r
,0,0,0,2); MATH2(VarDecMul
); EXPECTDEC64(0,0,1,0xFFFFFFFF,0xFFFFFFFE);
4024 SETDEC(l
,0,0,0,2); SETDEC64(r
,0,0,0,0xFFFFFFFF,0xFFFFFFFF); MATH2(VarDecMul
); EXPECTDEC64(0,0,1,0xFFFFFFFF,0xFFFFFFFE);
4025 SETDEC(l
,0,0,1,1); SETDEC(r
,0,0,0,0x80000000); MATH2(VarDecMul
); EXPECTDEC(0,0,0x80000000,0x80000000);
4026 SETDEC(l
,0,0,0,0x80000000); SETDEC(r
,0,0,1,1); MATH2(VarDecMul
); EXPECTDEC(0,0,0x80000000,0x80000000);
4028 /* near-overflow, used as a reference */
4029 SETDEC64(l
,0,0,0,0xFFFFFFFF,0xFFFFFFFF); SETDEC(r
,0,0,0,2000000000); MATH2(VarDecMul
);EXPECTDEC64(0,0,1999999999,0xFFFFFFFF,0x88CA6C00);
4030 /* actual overflow - right operand is 10 times the previous value */
4031 SETDEC64(l
,0,0,0,0xFFFFFFFF,0xFFFFFFFF); SETDEC64(r
,0,0,0,4,0xA817C800); MATH2(VarDecMul
);
4032 ok(hres
== DISP_E_OVERFLOW
,"Expected overflow, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
4033 S(U(out
)).scale
, S(U(out
)).sign
, out
.Hi32
, S1(U1(out
)).Mid32
, S1(U1(out
)).Lo32
, hres
);
4034 /* here, native oleaut32 has an opportunity to avert the overflow, by reducing the scale of the result */
4035 SETDEC64(l
,1,0,0,0xFFFFFFFF,0xFFFFFFFF); SETDEC64(r
,0,0,0,4,0xA817C800); MATH2(VarDecMul
);EXPECTDEC64(0,0,1999999999,0xFFFFFFFF,0x88CA6C00);
4037 /* near-overflow, used as a reference */
4038 SETDEC64(l
,0,0,1,0xFFFFFFFF,0xFFFFFFFE); SETDEC(r
,0,0,0,1000000000); MATH2(VarDecMul
);EXPECTDEC64(0,0,1999999999,0xFFFFFFFF,0x88CA6C00);
4039 /* actual overflow - right operand is 10 times the previous value */
4040 SETDEC64(l
,0,0,1,0xFFFFFFFF,0xFFFFFFFE); SETDEC64(r
,0,0,0,2,0x540BE400); MATH2(VarDecMul
);
4041 ok(hres
== DISP_E_OVERFLOW
,"Expected overflow, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
4042 S(U(out
)).scale
, S(U(out
)).sign
, out
.Hi32
, S1(U1(out
)).Mid32
, S1(U1(out
)).Lo32
, hres
);
4043 /* here, native oleaut32 has an opportunity to avert the overflow, by reducing the scale of the result */
4044 SETDEC64(l
,1,0,1,0xFFFFFFFF,0xFFFFFFFE); SETDEC64(r
,0,0,0,2,0x540BE400); MATH2(VarDecMul
);EXPECTDEC64(0,0,1999999999,0xFFFFFFFF,0x88CA6C00);
4046 /* this one shows that native oleaut32 is willing to lose significant digits in order to avert an overflow */
4047 SETDEC64(l
,2,0,0,0xFFFFFFFF,0xFFFFFFFF); SETDEC64(r
,0,0,0,9,0x502F9001); MATH2(VarDecMul
);EXPECTDEC64(1,0,0xee6b2800,0x19999998,0xab2e719a);
4050 static void test_VarDecDiv(void)
4054 /* identity divisions */
4055 SETDEC(l
,0,0,0,0); SETDEC(r
,0,0,0,1); MATH2(VarDecDiv
); EXPECTDEC(0,0,0,0);
4056 SETDEC(l
,0,0,0,1); SETDEC(r
,0,0,0,1); MATH2(VarDecDiv
); EXPECTDEC(0,0,0,1);
4057 SETDEC(l
,1,0,0,1); SETDEC(r
,0,0,0,1); MATH2(VarDecDiv
); EXPECTDEC(1,0,0,1);
4059 /* exact divisions */
4060 SETDEC(l
,0,0,0,45); SETDEC(r
,0,0,0,9); MATH2(VarDecDiv
); EXPECTDEC(0,0,0,5);
4061 SETDEC(l
,1,0,0,45); SETDEC(r
,0,0,0,9); MATH2(VarDecDiv
); EXPECTDEC(1,0,0,5);
4062 SETDEC(l
,0,0,0,45); SETDEC(r
,1,0,0,9); MATH2(VarDecDiv
); EXPECTDEC(0,0,0,50);
4063 SETDEC(l
,1,0,0,45); SETDEC(r
,2,0,0,9); MATH2(VarDecDiv
); EXPECTDEC(0,0,0,50);
4064 /* these last three results suggest that native oleaut32 scales both operands down to zero
4065 before the division, but does not always try to scale the result, even if it is possible -
4066 analogous to multiplication behavior.
4068 SETDEC(l
,1,0,0,45); SETDEC(r
,1,0,0,9); MATH2(VarDecDiv
); EXPECTDEC(0,0,0,5);
4069 SETDEC(l
,2,0,0,450); SETDEC(r
,1,0,0,9); MATH2(VarDecDiv
);
4070 if (S(U(out
)).scale
== 1) EXPECTDEC(1,0,0,50);
4071 else EXPECTDEC(0,0,0,5);
4073 /* inexact divisions */
4074 SETDEC(l
,0,0,0,1); SETDEC(r
,0,0,0,3); MATH2(VarDecDiv
); EXPECTDEC64(28,0,180700362,0x14b700cb,0x05555555);
4075 SETDEC(l
,1,0,0,1); SETDEC(r
,0,0,0,3); MATH2(VarDecDiv
); EXPECTDEC64(28,0,18070036,0x35458014,0x4d555555);
4076 SETDEC(l
,0,0,0,1); SETDEC(r
,1,0,0,3); MATH2(VarDecDiv
); EXPECTDEC64(28,0,1807003620,0xcf2607ee,0x35555555);
4077 SETDEC(l
,1,0,0,1); SETDEC(r
,2,0,0,3); MATH2(VarDecDiv
); EXPECTDEC64(28,0,1807003620,0xcf2607ee,0x35555555);
4078 SETDEC(l
,1,0,0,1); SETDEC(r
,1,0,0,3); MATH2(VarDecDiv
); EXPECTDEC64(28,0,180700362,0x14b700cb,0x05555555);
4079 SETDEC(l
,2,0,0,10); SETDEC(r
,1,0,0,3); MATH2(VarDecDiv
); EXPECTDEC64(28,0,180700362,0x14b700cb,0x05555555);
4081 /* this one shows that native oleaut32 rounds up the result */
4082 SETDEC(l
,0,0,0,2); SETDEC(r
,0,0,0,3); MATH2(VarDecDiv
); EXPECTDEC64(28,0,361400724,0x296e0196,0x0aaaaaab);
4085 SETDEC(l
,0,0x80,0,45); SETDEC(r
,0,0,0,9); MATH2(VarDecDiv
); EXPECTDEC(0,0x80,0,5);
4086 SETDEC(l
,0,0,0,45); SETDEC(r
,0,0x80,0,9); MATH2(VarDecDiv
);EXPECTDEC(0,0x80,0,5);
4087 SETDEC(l
,0,0x80,0,45); SETDEC(r
,0,0x80,0,9); MATH2(VarDecDiv
);EXPECTDEC(0,0,0,5);
4090 SETDEC(l
,0,0,0,0); SETDEC(r
,0,0,0,0); MATH2(VarDecDiv
);/* indeterminate */
4091 ok(hres
== DISP_E_DIVBYZERO
,"Expected division-by-zero, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
4092 S(U(out
)).scale
, S(U(out
)).sign
, out
.Hi32
, S1(U1(out
)).Mid32
, S1(U1(out
)).Lo32
, hres
);
4093 SETDEC(l
,0,0,0,1); SETDEC(r
,0,0,0,0); MATH2(VarDecDiv
);/* division by zero */
4094 ok(hres
== DISP_E_DIVBYZERO
,"Expected division-by-zero, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
4095 S(U(out
)).scale
, S(U(out
)).sign
, out
.Hi32
, S1(U1(out
)).Mid32
, S1(U1(out
)).Lo32
, hres
);
4099 static void test_VarDecCmp(void)
4103 SETDEC(l
,0,0,0,1); SETDEC(out
,0,0,0,1); MATH1(VarDecCmp
); EXPECT_EQ
;
4104 SETDEC(l
,0,0,0,1); SETDEC(out
,0,0,0,0); MATH1(VarDecCmp
); EXPECT_GT
;
4105 SETDEC(l
,0,0,0,1); SETDEC(out
,0,0,-1,-1); MATH1(VarDecCmp
); EXPECT_LT
;
4107 SETDEC(l
,0,0,0,1); SETDEC(out
,0,DECIMAL_NEG
,0,1); MATH1(VarDecCmp
); EXPECT_GT
;
4108 SETDEC(l
,0,0,0,1); SETDEC(out
,0,DECIMAL_NEG
,0,0); MATH1(VarDecCmp
); EXPECT_GT
;
4109 SETDEC(l
,0,0,0,1); SETDEC(out
,0,DECIMAL_NEG
,-1,-1); MATH1(VarDecCmp
); EXPECT_GT
;
4111 SETDEC(l
,0,DECIMAL_NEG
,0,1); SETDEC(out
,0,0,0,1); MATH1(VarDecCmp
); EXPECT_LT
;
4112 SETDEC(l
,0,DECIMAL_NEG
,0,1); SETDEC(out
,0,0,0,0); MATH1(VarDecCmp
); EXPECT_LT
;
4113 SETDEC(l
,0,DECIMAL_NEG
,0,1); SETDEC(out
,0,0,-1,-1); MATH1(VarDecCmp
); EXPECT_LT
;
4115 SETDEC(l
,0,DECIMAL_NEG
,0,1); SETDEC(out
,0,DECIMAL_NEG
,0,1); MATH1(VarDecCmp
); EXPECT_EQ
;
4116 SETDEC(l
,0,DECIMAL_NEG
,0,1); SETDEC(out
,0,DECIMAL_NEG
,0,0); MATH1(VarDecCmp
); EXPECT_LT
;
4117 SETDEC(l
,0,DECIMAL_NEG
,0,1); SETDEC(out
,0,DECIMAL_NEG
,-1,-1); MATH1(VarDecCmp
); EXPECT_GT
;
4119 SETDEC(l
,0,0,0,0); SETDEC(out
,0,0,0,1); MATH1(VarDecCmp
); EXPECT_LT
;
4120 SETDEC(l
,0,0,0,0); SETDEC(out
,0,0,0,0); MATH1(VarDecCmp
); EXPECT_EQ
;
4121 SETDEC(l
,0,0,0,0); SETDEC(out
,0,0,-1,-1); MATH1(VarDecCmp
); EXPECT_LT
;
4123 SETDEC(l
,0,0,0,0); SETDEC(out
,0,DECIMAL_NEG
,0,1); MATH1(VarDecCmp
); EXPECT_GT
;
4124 SETDEC(l
,0,0,0,0); SETDEC(out
,0,DECIMAL_NEG
,0,0); MATH1(VarDecCmp
); EXPECT_EQ
;
4125 SETDEC(l
,0,0,0,0); SETDEC(out
,0,DECIMAL_NEG
,-1,-1); MATH1(VarDecCmp
); EXPECT_GT
;
4127 SETDEC(l
,0,DECIMAL_NEG
,0,0); SETDEC(out
,0,0,0,1); MATH1(VarDecCmp
); EXPECT_LT
;
4128 SETDEC(l
,0,DECIMAL_NEG
,0,0); SETDEC(out
,0,0,0,0); MATH1(VarDecCmp
); EXPECT_EQ
;
4129 SETDEC(l
,0,DECIMAL_NEG
,0,0); SETDEC(out
,0,0,-1,-1); MATH1(VarDecCmp
); EXPECT_LT
;
4131 SETDEC(l
,0,DECIMAL_NEG
,0,0); SETDEC(out
,0,DECIMAL_NEG
,0,1); MATH1(VarDecCmp
); EXPECT_GT
;
4132 SETDEC(l
,0,DECIMAL_NEG
,0,0); SETDEC(out
,0,DECIMAL_NEG
,0,0); MATH1(VarDecCmp
); EXPECT_EQ
;
4133 SETDEC(l
,0,DECIMAL_NEG
,0,0); SETDEC(out
,0,DECIMAL_NEG
,-1,-1); MATH1(VarDecCmp
); EXPECT_GT
;
4135 SETDEC(l
,0,0,-1,-1); SETDEC(out
,0,0,0,1); MATH1(VarDecCmp
); EXPECT_GT
;
4136 SETDEC(l
,0,0,-1,-1); SETDEC(out
,0,0,0,0); MATH1(VarDecCmp
); EXPECT_GT
;
4137 SETDEC(l
,0,0,-1,-1); SETDEC(out
,0,0,-1,-1); MATH1(VarDecCmp
); EXPECT_EQ
;
4139 SETDEC(l
,0,0,-1,-1); SETDEC(out
,0,DECIMAL_NEG
,0,1); MATH1(VarDecCmp
); EXPECT_GT
;
4140 SETDEC(l
,0,0,-1,-1); SETDEC(out
,0,DECIMAL_NEG
,0,0); MATH1(VarDecCmp
); EXPECT_GT
;
4141 SETDEC(l
,0,0,-1,-1); SETDEC(out
,0,DECIMAL_NEG
,-1,-1); MATH1(VarDecCmp
); EXPECT_GT
;
4143 SETDEC(l
,0,DECIMAL_NEG
,-1,-1); SETDEC(out
,0,0,0,1); MATH1(VarDecCmp
); EXPECT_LT
;
4144 SETDEC(l
,0,DECIMAL_NEG
,-1,-1); SETDEC(out
,0,0,0,0); MATH1(VarDecCmp
); EXPECT_LT
;
4145 SETDEC(l
,0,DECIMAL_NEG
,-1,-1); SETDEC(out
,0,0,-1,-1); MATH1(VarDecCmp
); EXPECT_LT
;
4147 SETDEC(l
,0,DECIMAL_NEG
,-1,-1); SETDEC(out
,0,DECIMAL_NEG
,0,1); MATH1(VarDecCmp
); EXPECT_LT
;
4148 SETDEC(l
,0,DECIMAL_NEG
,-1,-1); SETDEC(out
,0,DECIMAL_NEG
,0,0); MATH1(VarDecCmp
); EXPECT_LT
;
4149 SETDEC(l
,0,DECIMAL_NEG
,-1,-1); SETDEC(out
,0,DECIMAL_NEG
,-1,-1); MATH1(VarDecCmp
); EXPECT_EQ
;
4152 SETDEC(out
,0,0,0,1); SETDEC(l
,0,0,0,1); MATH1(VarDecCmp
); EXPECT_EQ
;
4153 SETDEC(out
,0,0,0,1); SETDEC(l
,0,0,0,0); MATH1(VarDecCmp
); EXPECT_LT
;
4154 SETDEC(out
,0,0,0,1); SETDEC(l
,0,0,-1,-1); MATH1(VarDecCmp
); EXPECT_GT
;
4156 SETDEC(out
,0,0,0,1); SETDEC(l
,0,DECIMAL_NEG
,0,1); MATH1(VarDecCmp
); EXPECT_LT
;
4157 SETDEC(out
,0,0,0,1); SETDEC(l
,0,DECIMAL_NEG
,0,0); MATH1(VarDecCmp
); EXPECT_LT
;
4158 SETDEC(out
,0,0,0,1); SETDEC(l
,0,DECIMAL_NEG
,-1,-1); MATH1(VarDecCmp
); EXPECT_LT
;
4160 SETDEC(out
,0,DECIMAL_NEG
,0,1); SETDEC(l
,0,0,0,1); MATH1(VarDecCmp
); EXPECT_GT
;
4161 SETDEC(out
,0,DECIMAL_NEG
,0,1); SETDEC(l
,0,0,0,0); MATH1(VarDecCmp
); EXPECT_GT
;
4162 SETDEC(out
,0,DECIMAL_NEG
,0,1); SETDEC(l
,0,0,-1,-1); MATH1(VarDecCmp
); EXPECT_GT
;
4164 SETDEC(out
,0,DECIMAL_NEG
,0,1); SETDEC(l
,0,DECIMAL_NEG
,0,1); MATH1(VarDecCmp
); EXPECT_EQ
;
4165 SETDEC(out
,0,DECIMAL_NEG
,0,1); SETDEC(l
,0,DECIMAL_NEG
,0,0); MATH1(VarDecCmp
); EXPECT_GT
;
4166 SETDEC(out
,0,DECIMAL_NEG
,0,1); SETDEC(l
,0,DECIMAL_NEG
,-1,-1); MATH1(VarDecCmp
); EXPECT_LT
;
4168 SETDEC(out
,0,0,0,0); SETDEC(l
,0,0,0,1); MATH1(VarDecCmp
); EXPECT_GT
;
4169 SETDEC(out
,0,0,0,0); SETDEC(l
,0,0,0,0); MATH1(VarDecCmp
); EXPECT_EQ
;
4170 SETDEC(out
,0,0,0,0); SETDEC(l
,0,0,-1,-1); MATH1(VarDecCmp
); EXPECT_GT
;
4172 SETDEC(out
,0,0,0,0); SETDEC(l
,0,DECIMAL_NEG
,0,1); MATH1(VarDecCmp
); EXPECT_LT
;
4173 SETDEC(out
,0,0,0,0); SETDEC(l
,0,DECIMAL_NEG
,0,0); MATH1(VarDecCmp
); EXPECT_EQ
;
4174 SETDEC(out
,0,0,0,0); SETDEC(l
,0,DECIMAL_NEG
,-1,-1); MATH1(VarDecCmp
); EXPECT_LT
;
4176 SETDEC(out
,0,DECIMAL_NEG
,0,0); SETDEC(l
,0,0,0,1); MATH1(VarDecCmp
); EXPECT_GT
;
4177 SETDEC(out
,0,DECIMAL_NEG
,0,0); SETDEC(l
,0,0,0,0); MATH1(VarDecCmp
); EXPECT_EQ
;
4178 SETDEC(out
,0,DECIMAL_NEG
,0,0); SETDEC(l
,0,0,-1,-1); MATH1(VarDecCmp
); EXPECT_GT
;
4180 SETDEC(out
,0,DECIMAL_NEG
,0,0); SETDEC(l
,0,DECIMAL_NEG
,0,1); MATH1(VarDecCmp
); EXPECT_LT
;
4181 SETDEC(out
,0,DECIMAL_NEG
,0,0); SETDEC(l
,0,DECIMAL_NEG
,0,0); MATH1(VarDecCmp
); EXPECT_EQ
;
4182 SETDEC(out
,0,DECIMAL_NEG
,0,0); SETDEC(l
,0,DECIMAL_NEG
,-1,-1); MATH1(VarDecCmp
); EXPECT_LT
;
4184 SETDEC(out
,0,0,-1,-1); SETDEC(l
,0,0,0,1); MATH1(VarDecCmp
); EXPECT_LT
;
4185 SETDEC(out
,0,0,-1,-1); SETDEC(l
,0,0,0,0); MATH1(VarDecCmp
); EXPECT_LT
;
4186 SETDEC(out
,0,0,-1,-1); SETDEC(l
,0,0,-1,-1); MATH1(VarDecCmp
); EXPECT_EQ
;
4188 SETDEC(out
,0,0,-1,-1); SETDEC(l
,0,DECIMAL_NEG
,0,1); MATH1(VarDecCmp
); EXPECT_LT
;
4189 SETDEC(out
,0,0,-1,-1); SETDEC(l
,0,DECIMAL_NEG
,0,0); MATH1(VarDecCmp
); EXPECT_LT
;
4190 SETDEC(out
,0,0,-1,-1); SETDEC(l
,0,DECIMAL_NEG
,-1,-1); MATH1(VarDecCmp
); EXPECT_LT
;
4192 SETDEC(out
,0,DECIMAL_NEG
,-1,-1); SETDEC(l
,0,0,0,1); MATH1(VarDecCmp
); EXPECT_GT
;
4193 SETDEC(out
,0,DECIMAL_NEG
,-1,-1); SETDEC(l
,0,0,0,0); MATH1(VarDecCmp
); EXPECT_GT
;
4194 SETDEC(out
,0,DECIMAL_NEG
,-1,-1); SETDEC(l
,0,0,-1,-1); MATH1(VarDecCmp
); EXPECT_GT
;
4196 SETDEC(out
,0,DECIMAL_NEG
,-1,-1); SETDEC(l
,0,DECIMAL_NEG
,0,1); MATH1(VarDecCmp
); EXPECT_GT
;
4197 SETDEC(out
,0,DECIMAL_NEG
,-1,-1); SETDEC(l
,0,DECIMAL_NEG
,0,0); MATH1(VarDecCmp
); EXPECT_GT
;
4198 SETDEC(out
,0,DECIMAL_NEG
,-1,-1); SETDEC(l
,0,DECIMAL_NEG
,-1,-1); MATH1(VarDecCmp
); EXPECT_EQ
;
4200 SETDEC(l
,3,0,0,123456); SETDEC64(out
,0,0,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF);
4201 MATH1(VarDecCmp
); EXPECT_LT
;
4204 static void test_VarDecCmpR8(void)
4210 SETDEC(l
,0,0,0,1); r
= 0.0; MATH3(VarDecCmpR8
); EXPECT_GT
;
4211 SETDEC(l
,0,0,0,1); r
= 0.1; MATH3(VarDecCmpR8
); EXPECT_GT
;
4212 SETDEC(l
,0,0,0,1); r
= -0.1; MATH3(VarDecCmpR8
); EXPECT_GT
;
4214 SETDEC(l
,0,DECIMAL_NEG
,0,1); r
= 0.0; MATH3(VarDecCmpR8
); EXPECT_LT
;
4215 SETDEC(l
,0,DECIMAL_NEG
,0,1); r
= 0.1; MATH3(VarDecCmpR8
); EXPECT_LT
;
4216 SETDEC(l
,0,DECIMAL_NEG
,0,1); r
= -0.1; MATH3(VarDecCmpR8
); EXPECT_LT
;
4218 SETDEC(l
,0,0,0,0); r
= 0.0; MATH3(VarDecCmpR8
); EXPECT_EQ
;
4219 SETDEC(l
,0,0,0,0); r
= 0.1; MATH3(VarDecCmpR8
); EXPECT_LT
;
4220 SETDEC(l
,0,0,0,0); r
= -0.1; MATH3(VarDecCmpR8
); EXPECT_GT
;
4222 SETDEC(l
,0,DECIMAL_NEG
,0,0); r
= 0.0; MATH3(VarDecCmpR8
); EXPECT_EQ
;
4223 SETDEC(l
,0,DECIMAL_NEG
,0,0); r
= 0.1; MATH3(VarDecCmpR8
); EXPECT_LT
;
4224 SETDEC(l
,0,DECIMAL_NEG
,0,0); r
= -0.1; MATH3(VarDecCmpR8
); EXPECT_GT
;
4226 SETDEC(l
,0,0,0,1); r
= DECIMAL_NEG
; MATH3(VarDecCmpR8
); EXPECT_LT
;
4227 SETDEC(l
,0,DECIMAL_NEG
,0,0); r
= DECIMAL_NEG
; MATH3(VarDecCmpR8
); EXPECT_LT
;
4228 SETDEC(l
,0,0,-1,-1); r
= DECIMAL_NEG
; MATH3(VarDecCmpR8
); EXPECT_GT
;
4229 SETDEC(l
,0,DECIMAL_NEG
,-1,-1); r
= DECIMAL_NEG
; MATH3(VarDecCmpR8
); EXPECT_LT
;
4232 #define CLEAR(x) memset(&(x), 0xBB, sizeof(x))
4234 static void test_VarDecRound(void)
4239 CLEAR(out
); SETDEC(l
, 0, 0, 0, 1); hres
= VarDecRound(&l
, 3, &out
); EXPECTDEC(0, 0, 0, 1);
4241 CLEAR(out
); SETDEC(l
, 0, 0, 0, 1); hres
= VarDecRound(&l
, 0, &out
); EXPECTDEC(0, 0, 0, 1);
4242 CLEAR(out
); SETDEC(l
, 1, 0, 0, 1); hres
= VarDecRound(&l
, 0, &out
); EXPECTDEC(0, 0, 0, 0);
4243 CLEAR(out
); SETDEC(l
, 1, 0, 0, 1); hres
= VarDecRound(&l
, 1, &out
); EXPECTDEC(1, 0, 0, 1);
4244 CLEAR(out
); SETDEC(l
, 2, 0, 0, 11); hres
= VarDecRound(&l
, 1, &out
); EXPECTDEC(1, 0, 0, 1);
4245 CLEAR(out
); SETDEC(l
, 2, 0, 0, 15); hres
= VarDecRound(&l
, 1, &out
); EXPECTDEC(1, 0, 0, 2);
4246 CLEAR(out
); SETDEC(l
, 6, 0, 0, 550001); hres
= VarDecRound(&l
, 1, &out
); EXPECTDEC(1, 0, 0, 6);
4248 CLEAR(out
); SETDEC(l
, 0, DECIMAL_NEG
, 0, 1); hres
= VarDecRound(&l
, 0, &out
); EXPECTDEC(0, DECIMAL_NEG
, 0, 1);
4249 CLEAR(out
); SETDEC(l
, 1, DECIMAL_NEG
, 0, 1); hres
= VarDecRound(&l
, 0, &out
); EXPECTDEC(0, DECIMAL_NEG
, 0, 0);
4250 CLEAR(out
); SETDEC(l
, 1, DECIMAL_NEG
, 0, 1); hres
= VarDecRound(&l
, 1, &out
); EXPECTDEC(1, DECIMAL_NEG
, 0, 1);
4251 CLEAR(out
); SETDEC(l
, 2, DECIMAL_NEG
, 0, 11); hres
= VarDecRound(&l
, 1, &out
); EXPECTDEC(1, DECIMAL_NEG
, 0, 1);
4252 CLEAR(out
); SETDEC(l
, 2, DECIMAL_NEG
, 0, 15); hres
= VarDecRound(&l
, 1, &out
); EXPECTDEC(1, DECIMAL_NEG
, 0, 2);
4253 CLEAR(out
); SETDEC(l
, 6, DECIMAL_NEG
, 0, 550001); hres
= VarDecRound(&l
, 1, &out
); EXPECTDEC(1, DECIMAL_NEG
, 0, 6);
4255 CLEAR(out
); SETDEC64(l
, 0, 0, 0xffffffff, 0xffffffff, 0xffffffff); hres
= VarDecRound(&l
, 0, &out
); EXPECTDEC64(0, 0, 0xffffffff, 0xffffffff, 0xffffffff);
4256 CLEAR(out
); SETDEC64(l
, 28, 0, 0xffffffff, 0xffffffff, 0xffffffff); hres
= VarDecRound(&l
, 0, &out
); EXPECTDEC64(0, 0, 0, 0, 8);
4257 CLEAR(out
); SETDEC64(l
, 0, DECIMAL_NEG
, 0xffffffff, 0xffffffff, 0xffffffff); hres
= VarDecRound(&l
, 0, &out
); EXPECTDEC64(0, DECIMAL_NEG
, 0xffffffff, 0xffffffff, 0xffffffff);
4258 CLEAR(out
); SETDEC64(l
, 28, DECIMAL_NEG
, 0xffffffff, 0xffffffff, 0xffffffff); hres
= VarDecRound(&l
, 0, &out
); EXPECTDEC64(0, DECIMAL_NEG
, 0, 0, 8);
4260 CLEAR(out
); SETDEC(l
, 2, 0, 0, 0); hres
= VarDecRound(&l
, 1, &out
); EXPECTDEC(1, 0, 0, 0);
4268 #define CONV_TYPE VARIANT_BOOL
4270 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%d")
4272 #define CONVERTRANGE(func,start,end) for (i = start; i < end; i++) { \
4273 CONVERT(func, i); if (i) { EXPECT(VARIANT_TRUE); } else { EXPECT(VARIANT_FALSE); } }
4275 static void test_VarBoolFromI1(void)
4277 CONVVARS(signed char);
4280 CONVERTRANGE(VarBoolFromI1
, -128, 128);
4283 static void test_VarBoolFromUI1(void)
4288 CONVERTRANGE(VarBoolFromUI1
, 0, 256);
4291 static void test_VarBoolFromI2(void)
4296 CONVERTRANGE(VarBoolFromI2
, -32768, 32768);
4299 static void test_VarBoolFromUI2(void)
4304 CONVERTRANGE(VarBoolFromUI2
, 0, 65536);
4307 static void test_VarBoolFromI4(void)
4311 CONVERT(VarBoolFromI4
, 0x80000000); EXPECT(VARIANT_TRUE
);
4312 CONVERT(VarBoolFromI4
, -1); EXPECT(VARIANT_TRUE
);
4313 CONVERT(VarBoolFromI4
, 0); EXPECT(VARIANT_FALSE
);
4314 CONVERT(VarBoolFromI4
, 1); EXPECT(VARIANT_TRUE
);
4315 CONVERT(VarBoolFromI4
, 0x7fffffff); EXPECT(VARIANT_TRUE
);
4318 static void test_VarBoolFromUI4(void)
4322 CONVERT(VarBoolFromI4
, 0); EXPECT(VARIANT_FALSE
);
4323 CONVERT(VarBoolFromI4
, 1); EXPECT(VARIANT_TRUE
);
4324 CONVERT(VarBoolFromI4
, 0x80000000); EXPECT(VARIANT_TRUE
);
4327 static void test_VarBoolFromR4(void)
4331 CONVERT(VarBoolFromR4
, -1.0f
); EXPECT(VARIANT_TRUE
);
4332 CONVERT(VarBoolFromR4
, 0.0f
); EXPECT(VARIANT_FALSE
);
4333 CONVERT(VarBoolFromR4
, 1.0f
); EXPECT(VARIANT_TRUE
);
4334 CONVERT(VarBoolFromR4
, 1.5f
); EXPECT(VARIANT_TRUE
);
4337 CONVERT(VarBoolFromR4
, -1.5f
); EXPECT(VARIANT_TRUE
);
4338 CONVERT(VarBoolFromR4
, -0.6f
); EXPECT(VARIANT_TRUE
);
4339 CONVERT(VarBoolFromR4
, -0.5f
); EXPECT(VARIANT_TRUE
);
4340 CONVERT(VarBoolFromR4
, -0.4f
); EXPECT(VARIANT_TRUE
);
4341 CONVERT(VarBoolFromR4
, 0.4f
); EXPECT(VARIANT_TRUE
);
4342 CONVERT(VarBoolFromR4
, 0.5f
); EXPECT(VARIANT_TRUE
);
4343 CONVERT(VarBoolFromR4
, 0.6f
); EXPECT(VARIANT_TRUE
);
4344 CONVERT(VarBoolFromR4
, 1.5f
); EXPECT(VARIANT_TRUE
);
4347 static void test_VarBoolFromR8(void)
4351 /* Hopefully we made the point with R4 above that rounding is
4352 * irrelevant, so we'll skip that for R8 and Date
4354 CONVERT(VarBoolFromR8
, -1.0); EXPECT(VARIANT_TRUE
);
4355 CONVERT(VarBoolFromR8
, -0.0); EXPECT(VARIANT_FALSE
);
4356 CONVERT(VarBoolFromR8
, 1.0); EXPECT(VARIANT_TRUE
);
4359 static void test_VarBoolFromCy(void)
4363 CONVERT_CY(VarBoolFromCy
, -32769); EXPECT(VARIANT_TRUE
);
4364 CONVERT_CY(VarBoolFromCy
, -32768); EXPECT(VARIANT_TRUE
);
4365 CONVERT_CY(VarBoolFromCy
, -1); EXPECT(VARIANT_TRUE
);
4366 CONVERT_CY(VarBoolFromCy
, 0); EXPECT(VARIANT_FALSE
);
4367 CONVERT_CY(VarBoolFromCy
, 1); EXPECT(VARIANT_TRUE
);
4368 CONVERT_CY(VarBoolFromCy
, 32767); EXPECT(VARIANT_TRUE
);
4369 CONVERT_CY(VarBoolFromCy
, 32768); EXPECT(VARIANT_TRUE
);
4372 static void test_VarBoolFromI8(void)
4376 CONVERT(VarBoolFromI8
, -1); EXPECT(VARIANT_TRUE
);
4377 CONVERT(VarBoolFromI8
, 0); EXPECT(VARIANT_FALSE
);
4378 CONVERT(VarBoolFromI8
, 1); EXPECT(VARIANT_TRUE
);
4381 static void test_VarBoolFromUI8(void)
4385 CONVERT(VarBoolFromUI8
, 0); EXPECT(VARIANT_FALSE
);
4386 CONVERT(VarBoolFromUI8
, 1); EXPECT(VARIANT_TRUE
);
4389 static void test_VarBoolFromDec(void)
4393 CONVERT_BADDEC(VarBoolFromDec
);
4395 CONVERT_DEC(VarBoolFromDec
,29,0,0,0); EXPECT_INVALID
;
4396 CONVERT_DEC(VarBoolFromDec
,0,0x1,0,0); EXPECT_INVALID
;
4397 CONVERT_DEC(VarBoolFromDec
,0,0x40,0,0); EXPECT_INVALID
;
4398 CONVERT_DEC(VarBoolFromDec
,0,0x7f,0,0); EXPECT_INVALID
;
4400 CONVERT_DEC(VarBoolFromDec
,0,0x80,0,1); EXPECT(VARIANT_TRUE
);
4401 CONVERT_DEC(VarBoolFromDec
,0,0,0,0); EXPECT(VARIANT_FALSE
);
4402 CONVERT_DEC(VarBoolFromDec
,0,0,0,1); EXPECT(VARIANT_TRUE
);
4403 CONVERT_DEC(VarBoolFromDec
,0,0,1,0); EXPECT(VARIANT_TRUE
);
4405 CONVERT_DEC(VarBoolFromDec
,2,0,0,CY_MULTIPLIER
); EXPECT(VARIANT_TRUE
);
4406 CONVERT_DEC(VarBoolFromDec
,2,0x80,0,CY_MULTIPLIER
); EXPECT(VARIANT_TRUE
);
4409 static void test_VarBoolFromDate(void)
4413 CONVERT(VarBoolFromDate
, -1.0); EXPECT(VARIANT_TRUE
);
4414 CONVERT(VarBoolFromDate
, -0.0); EXPECT(VARIANT_FALSE
);
4415 CONVERT(VarBoolFromDate
, 1.0); EXPECT(VARIANT_TRUE
);
4418 static void test_VarBoolFromStr(void)
4423 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
4425 CONVERT_STR(VarBoolFromStr
,NULL
,0);
4426 if (hres
!= E_INVALIDARG
)
4429 /* #FALSE# and #TRUE# Are always accepted */
4430 CONVERT_STR(VarBoolFromStr
,"#FALSE#",0); EXPECT(VARIANT_FALSE
);
4431 CONVERT_STR(VarBoolFromStr
,"#TRUE#",0); EXPECT(VARIANT_TRUE
);
4433 /* Match of #FALSE# and #TRUE# is case sensitive */
4434 CONVERT_STR(VarBoolFromStr
,"#False#",0); EXPECT_MISMATCH
;
4435 /* But match against English is not */
4436 CONVERT_STR(VarBoolFromStr
,"false",0); EXPECT(VARIANT_FALSE
);
4437 CONVERT_STR(VarBoolFromStr
,"False",0); EXPECT(VARIANT_FALSE
);
4438 /* On/Off and yes/no are not acceptable inputs, with any flags set */
4439 CONVERT_STR(VarBoolFromStr
,"On",0xffffffff); EXPECT_MISMATCH
;
4440 CONVERT_STR(VarBoolFromStr
,"Yes",0xffffffff); EXPECT_MISMATCH
;
4442 /* Change the LCID. This doesn't make any difference for text,unless we ask
4443 * to check local boolean text with the VARIANT_LOCALBOOL flag. */
4444 in
= MAKELCID(MAKELANGID(LANG_FRENCH
, SUBLANG_DEFAULT
), SORT_DEFAULT
);
4446 /* #FALSE# and #TRUE# are accepted in all locales */
4447 CONVERT_STR(VarBoolFromStr
,"#FALSE#",0); EXPECT(VARIANT_FALSE
);
4448 CONVERT_STR(VarBoolFromStr
,"#TRUE#",0); EXPECT(VARIANT_TRUE
);
4449 CONVERT_STR(VarBoolFromStr
,"#FALSE#",VARIANT_LOCALBOOL
); EXPECT(VARIANT_FALSE
);
4450 CONVERT_STR(VarBoolFromStr
,"#TRUE#",VARIANT_LOCALBOOL
); EXPECT(VARIANT_TRUE
);
4452 /* English is accepted regardless of the locale */
4453 CONVERT_STR(VarBoolFromStr
,"false",0); EXPECT(VARIANT_FALSE
);
4454 /* And is still not case sensitive */
4455 CONVERT_STR(VarBoolFromStr
,"False",0); EXPECT(VARIANT_FALSE
);
4459 /* French is rejected without VARIANT_LOCALBOOL */
4460 CONVERT_STR(VarBoolFromStr
,"faux",0); EXPECT_MISMATCH
;
4461 /* But accepted if this flag is given */
4462 CONVERT_STR(VarBoolFromStr
,"faux",VARIANT_LOCALBOOL
); EXPECT(VARIANT_FALSE
);
4463 /* Regardless of case - from this we assume locale text comparisons ignore case */
4464 CONVERT_STR(VarBoolFromStr
,"Faux",VARIANT_LOCALBOOL
); EXPECT(VARIANT_FALSE
);
4466 /* Changing the locale prevents the localised text from being compared -
4467 * this demonstrates that only the indicated LCID and English are searched */
4468 in
= MAKELCID(MAKELANGID(LANG_POLISH
, SUBLANG_DEFAULT
), SORT_DEFAULT
);
4469 CONVERT_STR(VarBoolFromStr
,"faux",VARIANT_LOCALBOOL
); EXPECT_MISMATCH
;
4472 /* Numeric strings are read as 0 or non-0 */
4473 CONVERT_STR(VarBoolFromStr
,"0",0); EXPECT(VARIANT_FALSE
);
4474 CONVERT_STR(VarBoolFromStr
,"-1",0); EXPECT(VARIANT_TRUE
);
4475 CONVERT_STR(VarBoolFromStr
,"+1",0); EXPECT(VARIANT_TRUE
);
4479 /* Numeric strings are read as floating point numbers. The line below fails
4480 * because '.' is not a valid decimal separator for Polish numbers */
4481 CONVERT_STR(VarBoolFromStr
,"0.1",LOCALE_NOUSEROVERRIDE
); EXPECT_MISMATCH
;
4484 /* Changing the lcid back to US English reads the r8 correctly */
4485 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
4486 CONVERT_STR(VarBoolFromStr
,"0.1",LOCALE_NOUSEROVERRIDE
); EXPECT(VARIANT_TRUE
);
4489 static void test_VarBoolCopy(void)
4491 COPYTEST(1, VT_BOOL
, V_BOOL(&vSrc
), V_BOOL(&vDst
), V_BOOLREF(&vSrc
), V_BOOLREF(&vDst
), "%d");
4494 #define BOOL_STR(flags, str) hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, flags, VT_BSTR); \
4495 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && \
4496 V_BSTR(&vDst) && !memcmp(V_BSTR(&vDst), str, sizeof(str)), \
4497 "hres=0x%X, type=%d (should be VT_BSTR), *bstr='%c'\n", \
4498 hres, V_VT(&vDst), V_BSTR(&vDst) ? *V_BSTR(&vDst) : '?'); \
4501 static void test_VarBoolChangeTypeEx(void)
4503 static const WCHAR szTrue
[] = { 'T','r','u','e','\0' };
4504 static const WCHAR szFalse
[] = { 'F','a','l','s','e','\0' };
4505 static const WCHAR szFaux
[] = { 'F','a','u','x','\0' };
4508 VARIANTARG vSrc
, vDst
;
4513 INITIAL_TYPETEST(VT_BOOL
, V_BOOL
, "%d");
4516 /* The common tests convert to a number. Try the different flags */
4517 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
4519 V_VT(&vSrc
) = VT_BOOL
;
4522 BOOL_STR(VARIANT_ALPHABOOL
, szTrue
);
4524 BOOL_STR(VARIANT_ALPHABOOL
, szFalse
);
4528 lcid
= MAKELCID(MAKELANGID(LANG_FRENCH
, SUBLANG_DEFAULT
), SORT_DEFAULT
);
4530 /* VARIANT_ALPHABOOL is always English */
4531 BOOL_STR(VARIANT_ALPHABOOL
, szFalse
);
4532 /* VARIANT_LOCALBOOL uses the localised text */
4533 BOOL_STR(VARIANT_LOCALBOOL
, szFaux
);
4534 /* Both flags together acts as VARIANT_LOCALBOOL */
4535 BOOL_STR(VARIANT_ALPHABOOL
|VARIANT_LOCALBOOL
, szFaux
);
4543 static void test_VarBstrFromR4(void)
4545 static const WCHAR szNative
[] = { '6','5','4','3','2','2','.','3','\0' };
4546 static const WCHAR szZero
[] = {'0', '\0'};
4547 static const WCHAR szOneHalf_English
[] = { '0','.','5','\0' }; /* uses period */
4548 static const WCHAR szOneHalf_Spanish
[] = { '0',',','5','\0' }; /* uses comma */
4556 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
4557 lcid_spanish
= MAKELCID(MAKELANGID(LANG_SPANISH
, SUBLANG_SPANISH
), SORT_DEFAULT
);
4559 hres
= VarBstrFromR4(f
, lcid
, 0, &bstr
);
4560 ok(hres
== S_OK
, "got hres 0x%08x\n", hres
);
4564 /* MSDN states that rounding of R4/R8 is dependent on the underlying
4565 * bit pattern of the number and so is architecture dependent. In this
4566 * case Wine returns .2 (which is more correct) and Native returns .3
4568 ok(memcmp(bstr
, szNative
, sizeof(szNative
)) == 0, "string different\n");
4570 SysFreeString(bstr
);
4574 hres
= VarBstrFromR4(f
, lcid
, 0, &bstr
);
4575 ok(hres
== S_OK
, "got hres 0x%08x\n", hres
);
4579 ok(memcmp(bstr
+ 1, szZero
, sizeof(szZero
)) == 0, "negative zero (got %s)\n", wtoascii(bstr
));
4581 ok(memcmp(bstr
, szZero
, sizeof(szZero
)) == 0, "negative zero (got %s)\n", wtoascii(bstr
));
4582 SysFreeString(bstr
);
4585 /* The following tests that lcid is used for decimal separator even without LOCALE_USE_NLS */
4587 hres
= VarBstrFromR4(f
, lcid
, LOCALE_NOUSEROVERRIDE
, &bstr
);
4588 ok(hres
== S_OK
, "got hres 0x%08x\n", hres
);
4591 ok(memcmp(bstr
, szOneHalf_English
, sizeof(szOneHalf_English
)) == 0, "English locale failed (got %s)\n", wtoascii(bstr
));
4592 SysFreeString(bstr
);
4595 hres
= VarBstrFromR4(f
, lcid_spanish
, LOCALE_NOUSEROVERRIDE
, &bstr
);
4596 ok(hres
== S_OK
, "got hres 0x%08x\n", hres
);
4599 ok(memcmp(bstr
, szOneHalf_Spanish
, sizeof(szOneHalf_Spanish
)) == 0, "Spanish locale failed (got %s)\n", wtoascii(bstr
));
4600 SysFreeString(bstr
);
4604 static void _BSTR_DATE(DATE dt
, const char *str
, int line
)
4606 LCID lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
4611 hres
= VarBstrFromDate(dt
, lcid
, LOCALE_NOUSEROVERRIDE
, &bstr
);
4614 WideCharToMultiByte(CP_ACP
, 0, bstr
, -1, buff
, sizeof(buff
), 0, 0);
4615 SysFreeString(bstr
);
4619 ok_(__FILE__
, line
)(hres
== S_OK
&& !strcmp(str
, buff
),
4620 "Expected '%s', got '%s', hres = 0x%08x\n", str
, buff
, hres
);
4623 static void test_VarBstrFromDate(void)
4625 #define BSTR_DATE(dt,str) _BSTR_DATE(dt,str,__LINE__)
4627 BSTR_DATE(0.0, "12:00:00 AM");
4628 BSTR_DATE(3.34, "1/2/1900 8:09:36 AM");
4629 BSTR_DATE(3339.34, "2/20/1909 8:09:36 AM");
4630 BSTR_DATE(365.00, "12/30/1900");
4631 BSTR_DATE(365.25, "12/30/1900 6:00:00 AM");
4632 BSTR_DATE(1461.0, "12/31/1903");
4633 BSTR_DATE(1461.5, "12/31/1903 12:00:00 PM");
4634 BSTR_DATE(-49192.24, "4/24/1765 5:45:36 AM");
4635 BSTR_DATE(-657434.0, "1/1/100");
4636 BSTR_DATE(2958465.0, "12/31/9999");
4641 static void _BSTR_CY(LONG a
, LONG b
, const char *str
, LCID lcid
, int line
)
4650 hr
= VarBstrFromCy(l
, lcid
, LOCALE_NOUSEROVERRIDE
, &bstr
);
4651 ok(hr
== S_OK
, "got hr 0x%08x\n", hr
);
4655 WideCharToMultiByte(CP_ACP
, 0, bstr
, -1, buff
, sizeof(buff
), 0, 0);
4656 SysFreeString(bstr
);
4663 ok_(__FILE__
, line
)(!strcmp(str
, buff
), "Expected '%s', got '%s'\n", str
, buff
);
4667 static void test_VarBstrFromCy(void)
4669 #define BSTR_CY(a, b, str, lcid) _BSTR_CY(a, b, str, lcid, __LINE__)
4673 en_us
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
4674 sp
= MAKELCID(MAKELANGID(LANG_SPANISH
, SUBLANG_DEFAULT
), SORT_DEFAULT
);
4676 BSTR_CY(0, 0, "0", en_us
);
4677 BSTR_CY(0, 10000, "1", en_us
);
4678 BSTR_CY(0, 15000, "1.5", en_us
);
4679 BSTR_CY(0xffffffff, ((15000)^0xffffffff)+1, "-1.5", en_us
);
4680 /* (1 << 32) - 1 / 1000 */
4681 BSTR_CY(0, 0xffffffff, "429496.7295", en_us
);
4682 /* (1 << 32) / 1000 */
4683 BSTR_CY(1, 0, "429496.7296", en_us
);
4684 /* ((1 << 63) - 1)/10000 */
4685 BSTR_CY(0x7fffffff, 0xffffffff, "922337203685477.5807", en_us
);
4686 BSTR_CY(0, 9, "0.0009", en_us
);
4687 BSTR_CY(0, 9, "0,0009", sp
);
4692 static void _BSTR_DEC(BYTE scale
, BYTE sign
, ULONG hi
, ULONG mid
, ULONGLONG lo
, const char *str
,
4693 LCID lcid
, int line
)
4700 SETDEC64(dec
, scale
, sign
, hi
, mid
, lo
);
4701 hr
= VarBstrFromDec(&dec
, lcid
, LOCALE_NOUSEROVERRIDE
, &bstr
);
4702 ok_(__FILE__
, line
)(hr
== S_OK
, "got hr 0x%08x\n", hr
);
4706 WideCharToMultiByte(CP_ACP
, 0, bstr
, -1, buff
, sizeof(buff
), 0, 0);
4707 SysFreeString(bstr
);
4714 ok_(__FILE__
, line
)(!strcmp(str
, buff
), "Expected '%s', got '%s'\n", str
, buff
);
4718 static void test_VarBstrFromDec(void)
4720 #define BSTR_DEC(scale, sign, hi, lo, str, lcid) _BSTR_DEC(scale, sign, hi, 0, lo, str, lcid, __LINE__)
4721 #define BSTR_DEC64(scale, sign, hi, mid, lo, str, lcid) _BSTR_DEC(scale, sign, hi, mid, lo, str, lcid, __LINE__)
4725 en_us
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
4726 sp
= MAKELCID(MAKELANGID(LANG_SPANISH
, SUBLANG_DEFAULT
), SORT_DEFAULT
);
4728 BSTR_DEC(0,0,0,0, "0", en_us
);
4730 BSTR_DEC(0,0,0,1, "1", en_us
);
4731 BSTR_DEC(1,0,0,10, "1", en_us
);
4732 BSTR_DEC(2,0,0,100, "1", en_us
);
4733 BSTR_DEC(3,0,0,1000,"1", en_us
);
4735 BSTR_DEC(1,0,0,15, "1.5", en_us
);
4736 BSTR_DEC(2,0,0,150, "1.5", en_us
);
4737 BSTR_DEC(3,0,0,1500,"1.5", en_us
);
4739 BSTR_DEC(1,0x80,0,15, "-1.5", en_us
);
4742 BSTR_DEC(0,0,0,0xffffffff, "4294967295", en_us
);
4744 BSTR_DEC64(0,0,0,1,0, "4294967296", en_us
);
4746 BSTR_DEC64(0,0,0,0xffffffff,0xffffffff, "18446744073709551615", en_us
);
4748 BSTR_DEC(0,0,1,0, "18446744073709551616", en_us
);
4750 BSTR_DEC64(0,0,0xffffffff,0xffffffff,0xffffffff, "79228162514264337593543950335", en_us
);
4752 BSTR_DEC(10,0,0,1, "0.0000000001", en_us
);
4753 /* ((1 << 96) - 1) * 10^-10 */
4754 BSTR_DEC64(10,0,0xffffffffUL
,0xffffffff,0xffffffff, "7922816251426433759.3543950335", en_us
);
4755 /* ((1 << 96) - 1) * 10^-28 */
4756 BSTR_DEC64(28,0,0xffffffffUL
,0xffffffff,0xffffffff, "7.9228162514264337593543950335", en_us
);
4758 /* check leading zeros and decimal sep. for English locale */
4759 BSTR_DEC(4,0,0,9, "0.0009", en_us
);
4760 BSTR_DEC(5,0,0,90, "0.0009", en_us
);
4761 BSTR_DEC(6,0,0,900, "0.0009", en_us
);
4762 BSTR_DEC(7,0,0,9000, "0.0009", en_us
);
4764 /* check leading zeros and decimal sep. for Spanish locale */
4765 BSTR_DEC(4,0,0,9, "0,0009", sp
);
4766 BSTR_DEC(5,0,0,90, "0,0009", sp
);
4767 BSTR_DEC(6,0,0,900, "0,0009", sp
);
4768 BSTR_DEC(7,0,0,9000, "0,0009", sp
);
4774 #define _VARBSTRCMP(left,right,lcid,flags,result) \
4775 hres = VarBstrCmp(left,right,lcid,flags); \
4776 ok(hres == result, "VarBstrCmp: expected " #result ", got hres=0x%x\n", hres)
4777 #define VARBSTRCMP(left,right,flags,result) \
4778 _VARBSTRCMP(left,right,lcid,flags,result)
4780 static void test_VarBstrCmp(void)
4784 static const WCHAR sz
[] = {'W','u','r','s','c','h','t','\0'};
4785 static const WCHAR szempty
[] = {'\0'};
4786 static const WCHAR sz1
[] = { 'a',0 };
4787 static const WCHAR sz2
[] = { 'A',0 };
4788 static const WCHAR s1
[] = { 'a',0 };
4789 static const WCHAR s2
[] = { 'a',0,'b' };
4790 static const char sb1
[] = {1,0,1};
4791 static const char sb2
[] = {1,0,2};
4792 static const char sbchr0
[] = {0,0};
4793 static const char sbchr00
[] = {0,0,0};
4794 BSTR bstr
, bstrempty
, bstr2
;
4796 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
4797 bstr
= SysAllocString(sz
);
4798 bstrempty
= SysAllocString(szempty
);
4800 /* NULL handling. Yepp, MSDN is totally wrong here */
4801 VARBSTRCMP(NULL
,NULL
,0,VARCMP_EQ
);
4802 VARBSTRCMP(bstr
,NULL
,0,VARCMP_GT
);
4803 VARBSTRCMP(NULL
,bstr
,0,VARCMP_LT
);
4805 /* NULL and empty string comparisons */
4806 VARBSTRCMP(bstrempty
,NULL
,0,VARCMP_EQ
);
4807 VARBSTRCMP(NULL
,bstrempty
,0,VARCMP_EQ
);
4809 SysFreeString(bstr
);
4810 bstr
= SysAllocString(sz1
);
4812 bstr2
= SysAllocString(sz2
);
4813 VARBSTRCMP(bstr
,bstr2
,0,VARCMP_LT
);
4814 VARBSTRCMP(bstr
,bstr2
,NORM_IGNORECASE
,VARCMP_EQ
);
4815 SysFreeString(bstr2
);
4816 /* These two strings are considered equal even though one is
4817 * NULL-terminated and the other not.
4819 bstr2
= SysAllocStringLen(s1
, sizeof(s1
) / sizeof(WCHAR
));
4820 VARBSTRCMP(bstr
,bstr2
,0,VARCMP_EQ
);
4821 SysFreeString(bstr2
);
4823 /* These two strings are not equal */
4824 bstr2
= SysAllocStringLen(s2
, sizeof(s2
) / sizeof(WCHAR
));
4825 VARBSTRCMP(bstr
,bstr2
,0,VARCMP_LT
);
4826 SysFreeString(bstr2
);
4828 SysFreeString(bstr
);
4830 bstr
= SysAllocStringByteLen(sbchr0
, sizeof(sbchr0
));
4831 bstr2
= SysAllocStringByteLen(sbchr00
, sizeof(sbchr00
));
4832 VARBSTRCMP(bstr
,bstrempty
,0,VARCMP_GT
);
4833 VARBSTRCMP(bstrempty
,bstr
,0,VARCMP_LT
);
4834 VARBSTRCMP(bstr2
,bstrempty
,0,VARCMP_GT
);
4835 VARBSTRCMP(bstr2
,bstr
,0,VARCMP_EQ
);
4836 SysFreeString(bstr2
);
4837 SysFreeString(bstr
);
4839 /* When (LCID == 0) it should be a binary comparison
4840 * so these two strings could not match.
4842 bstr
= SysAllocStringByteLen(sb1
, sizeof(sb1
));
4843 bstr2
= SysAllocStringByteLen(sb2
, sizeof(sb2
));
4845 VARBSTRCMP(bstr
,bstr2
,0,VARCMP_LT
);
4846 SysFreeString(bstr2
);
4847 SysFreeString(bstr
);
4849 bstr
= SysAllocStringByteLen(sbchr0
, sizeof(sbchr0
));
4850 bstr2
= SysAllocStringByteLen(sbchr00
, sizeof(sbchr00
));
4851 VARBSTRCMP(bstr
,bstrempty
,0,VARCMP_GT
);
4852 VARBSTRCMP(bstrempty
,bstr
,0,VARCMP_LT
);
4853 VARBSTRCMP(bstr2
,bstrempty
,0,VARCMP_GT
);
4854 VARBSTRCMP(bstr2
,bstr
,0,VARCMP_GT
);
4855 SysFreeString(bstr2
);
4856 SysFreeString(bstr
);
4857 SysFreeString(bstrempty
);
4860 /* Get the internal representation of a BSTR */
4861 static inline LPINTERNAL_BSTR
Get(const BSTR lpszString
)
4863 return lpszString
? (LPINTERNAL_BSTR
)((char*)lpszString
- sizeof(DWORD
)) : NULL
;
4866 static inline BSTR
GetBSTR(const LPINTERNAL_BSTR bstr
)
4868 return (BSTR
)bstr
->szString
;
4871 static void test_SysStringLen(void)
4874 BSTR str
= GetBSTR(&bstr
);
4877 ok (SysStringLen(str
) == 0, "Expected dwLen 0, got %d\n", SysStringLen(str
));
4879 ok (SysStringLen(str
) == 1, "Expected dwLen 1, got %d\n", SysStringLen(str
));
4882 static void test_SysStringByteLen(void)
4885 BSTR str
= GetBSTR(&bstr
);
4888 ok (SysStringByteLen(str
) == 0, "Expected dwLen 0, got %d\n", SysStringByteLen(str
));
4890 ok (SysStringByteLen(str
) == 2, "Expected dwLen 2, got %d\n", SysStringByteLen(str
));
4893 static void test_SysAllocString(void)
4895 const OLECHAR szTest
[5] = { 'T','e','s','t','\0' };
4898 str
= SysAllocString(NULL
);
4899 ok (str
== NULL
, "Expected NULL, got %p\n", str
);
4901 str
= SysAllocString(szTest
);
4902 ok (str
!= NULL
, "Expected non-NULL\n");
4905 LPINTERNAL_BSTR bstr
= Get(str
);
4906 DWORD_PTR p
= (DWORD_PTR
)str
;
4907 int align
= sizeof(void *);
4909 ok (bstr
->dwLen
== 8, "Expected 8, got %d\n", bstr
->dwLen
);
4910 ok (!lstrcmpW(bstr
->szString
, szTest
), "String different\n");
4911 ok ((p
& ~(align
-1)) == p
, "Not aligned to %d\n", align
);
4916 static void test_SysAllocStringLen(void)
4918 const OLECHAR szTest
[5] = { 'T','e','s','t','\0' };
4921 /* Very early native dlls do not limit the size of strings, so skip this test */
4924 str
= SysAllocStringLen(szTest
, 0x80000000);
4925 ok (str
== NULL
, "Expected NULL, got %p\n", str
);
4928 str
= SysAllocStringLen(NULL
, 0);
4929 ok (str
!= NULL
, "Expected non-NULL\n");
4932 LPINTERNAL_BSTR bstr
= Get(str
);
4934 ok (bstr
->dwLen
== 0, "Expected 0, got %d\n", bstr
->dwLen
);
4935 ok (!bstr
->szString
[0], "String not empty\n");
4939 str
= SysAllocStringLen(szTest
, 4);
4940 ok (str
!= NULL
, "Expected non-NULL\n");
4943 LPINTERNAL_BSTR bstr
= Get(str
);
4945 ok (bstr
->dwLen
== 8, "Expected 8, got %d\n", bstr
->dwLen
);
4946 ok (!lstrcmpW(bstr
->szString
, szTest
), "String different\n");
4951 static void test_SysAllocStringByteLen(void)
4953 const OLECHAR szTest
[10] = { 'T','e','s','t','\0' };
4954 const CHAR szTestA
[6] = { 'T','e','s','t','\0','?' };
4959 if (sizeof(void *) == 4) /* not limited to 0x80000000 on Win64 */
4961 str
= SysAllocStringByteLen(szTestA
, 0x80000000);
4962 ok (str
== NULL
, "Expected NULL, got %p\n", str
);
4965 str
= SysAllocStringByteLen(szTestA
, 0xffffffff);
4966 ok (str
== NULL
, "Expected NULL, got %p\n", str
);
4968 str
= SysAllocStringByteLen(NULL
, 0);
4969 ok (str
!= NULL
, "Expected non-NULL\n");
4972 LPINTERNAL_BSTR bstr
= Get(str
);
4974 ok (bstr
->dwLen
== 0, "Expected 0, got %d\n", bstr
->dwLen
);
4975 ok (!bstr
->szString
[0], "String not empty\n");
4979 str
= SysAllocStringByteLen(szTestA
, 4);
4980 ok (str
!= NULL
, "Expected non-NULL\n");
4983 LPINTERNAL_BSTR bstr
= Get(str
);
4985 ok (bstr
->dwLen
== 4, "Expected 4, got %d\n", bstr
->dwLen
);
4986 ok (!lstrcmpA((LPCSTR
)bstr
->szString
, szTestA
), "String different\n");
4990 /* Odd lengths are allocated rounded up, but truncated at the right position */
4991 str
= SysAllocStringByteLen(szTestA
, 3);
4992 ok (str
!= NULL
, "Expected non-NULL\n");
4995 const CHAR szTestTruncA
[4] = { 'T','e','s','\0' };
4996 LPINTERNAL_BSTR bstr
= Get(str
);
4998 ok (bstr
->dwLen
== 3, "Expected 3, got %d\n", bstr
->dwLen
);
4999 ok (!lstrcmpA((LPCSTR
)bstr
->szString
, szTestTruncA
), "String different\n");
5000 ok (!bstr
->szString
[2], "String not terminated\n");
5004 str
= SysAllocStringByteLen((LPCSTR
)szTest
, 8);
5005 ok (str
!= NULL
, "Expected non-NULL\n");
5008 LPINTERNAL_BSTR bstr
= Get(str
);
5010 ok (bstr
->dwLen
== 8, "Expected 8, got %d\n", bstr
->dwLen
);
5011 ok (!lstrcmpW(bstr
->szString
, szTest
), "String different\n");
5015 /* Make sure terminating null is aligned properly */
5016 buf
= HeapAlloc(GetProcessHeap(), 0, 1025);
5017 ok (buf
!= NULL
, "Expected non-NULL\n");
5018 for (i
= 0; i
< 1024; i
++)
5020 LPINTERNAL_BSTR bstr
;
5022 str
= SysAllocStringByteLen(NULL
, i
);
5023 ok (str
!= NULL
, "Expected non-NULL\n");
5025 ok (bstr
->dwLen
== i
, "Expected %d, got %d\n", i
, bstr
->dwLen
);
5026 ok (!bstr
->szString
[(i
+sizeof(WCHAR
)-1)/sizeof(WCHAR
)], "String not terminated\n");
5029 memset(buf
, 0xaa, 1025);
5030 str
= SysAllocStringByteLen(buf
, i
);
5031 ok (str
!= NULL
, "Expected non-NULL\n");
5033 ok (bstr
->dwLen
== i
, "Expected %d, got %d\n", i
, bstr
->dwLen
);
5035 ok (!lstrcmpA((LPCSTR
)bstr
->szString
, buf
), "String different\n");
5036 ok (!bstr
->szString
[(i
+sizeof(WCHAR
)-1)/sizeof(WCHAR
)], "String not terminated\n");
5039 HeapFree(GetProcessHeap(), 0, buf
);
5042 static void test_SysReAllocString(void)
5044 const OLECHAR szTest
[5] = { 'T','e','s','t','\0' };
5045 const OLECHAR szSmaller
[2] = { 'x','\0' };
5046 const OLECHAR szLarger
[7] = { 'L','a','r','g','e','r','\0' };
5049 str
= SysAllocStringLen(szTest
, 4);
5050 ok (str
!= NULL
, "Expected non-NULL\n");
5053 LPINTERNAL_BSTR bstr
;
5057 ok (bstr
->dwLen
== 8, "Expected 8, got %d\n", bstr
->dwLen
);
5058 ok (!lstrcmpW(bstr
->szString
, szTest
), "String different\n");
5060 changed
= SysReAllocString(&str
, szSmaller
);
5061 ok (changed
== 1, "Expected 1, got %d\n", changed
);
5062 /* Vista creates a new string, but older versions reuse the existing string. */
5063 /*ok (str == oldstr, "Created new string\n");*/
5065 ok (bstr
->dwLen
== 2, "Expected 2, got %d\n", bstr
->dwLen
);
5066 ok (!lstrcmpW(bstr
->szString
, szSmaller
), "String different\n");
5068 changed
= SysReAllocString(&str
, szLarger
);
5069 ok (changed
== 1, "Expected 1, got %d\n", changed
);
5070 /* Early versions always make new strings rather than resizing */
5071 /* ok (str == oldstr, "Created new string\n"); */
5073 ok (bstr
->dwLen
== 12, "Expected 12, got %d\n", bstr
->dwLen
);
5074 ok (!lstrcmpW(bstr
->szString
, szLarger
), "String different\n");
5080 static void test_SysReAllocStringLen(void)
5082 const OLECHAR szTest
[5] = { 'T','e','s','t','\0' };
5083 const OLECHAR szSmaller
[2] = { 'x','\0' };
5084 const OLECHAR szLarger
[7] = { 'L','a','r','g','e','r','\0' };
5087 str
= SysAllocStringLen(szTest
, 4);
5088 ok (str
!= NULL
, "Expected non-NULL\n");
5091 LPINTERNAL_BSTR bstr
;
5095 ok (bstr
->dwLen
== 8, "Expected 8, got %d\n", bstr
->dwLen
);
5096 ok (!lstrcmpW(bstr
->szString
, szTest
), "String different\n");
5098 changed
= SysReAllocStringLen(&str
, szSmaller
, 1);
5099 ok (changed
== 1, "Expected 1, got %d\n", changed
);
5100 /* Vista creates a new string, but older versions reuse the existing string. */
5101 /*ok (str == oldstr, "Created new string\n");*/
5103 ok (bstr
->dwLen
== 2, "Expected 2, got %d\n", bstr
->dwLen
);
5104 ok (!lstrcmpW(bstr
->szString
, szSmaller
), "String different\n");
5106 changed
= SysReAllocStringLen(&str
, szLarger
, 6);
5107 ok (changed
== 1, "Expected 1, got %d\n", changed
);
5108 /* Early versions always make new strings rather than resizing */
5109 /* ok (str == oldstr, "Created new string\n"); */
5111 ok (bstr
->dwLen
== 12, "Expected 12, got %d\n", bstr
->dwLen
);
5112 ok (!lstrcmpW(bstr
->szString
, szLarger
), "String different\n");
5114 changed
= SysReAllocStringLen(&str
, str
, 6);
5115 ok (changed
== 1, "Expected 1, got %d\n", changed
);
5120 /* Windows always returns null terminated strings */
5121 str
= SysAllocStringLen(szTest
, 4);
5122 ok (str
!= NULL
, "Expected non-NULL\n");
5125 const int CHUNK_SIZE
= 64;
5126 const int STRING_SIZE
= 24;
5128 changed
= SysReAllocStringLen(&str
, NULL
, CHUNK_SIZE
);
5129 ok (changed
== 1, "Expected 1, got %d\n", changed
);
5130 ok (str
!= NULL
, "Expected non-NULL\n");
5135 /* Filling string */
5136 memset (str
, 0xAB, CHUNK_SIZE
* sizeof (OLECHAR
));
5137 /* Checking null terminator */
5138 changed
= SysReAllocStringLen(&str
, NULL
, STRING_SIZE
);
5139 ok (changed
== 1, "Expected 1, got %d\n", changed
);
5140 ok (str
!= NULL
, "Expected non-NULL\n");
5143 ok (str
== oldstr
, "Expected reuse of the old string memory\n");
5144 ok (str
[STRING_SIZE
] == 0,
5145 "Expected null terminator, got 0x%04X\n", str
[STRING_SIZE
]);
5151 /* Some Windows applications use the same pointer for pbstr and psz */
5152 str
= SysAllocStringLen(szTest
, 4);
5153 ok(str
!= NULL
, "Expected non-NULL\n");
5156 SysReAllocStringLen(&str
, str
, 1000000);
5157 ok(SysStringLen(str
)==1000000, "Incorrect string length\n");
5158 ok(!memcmp(szTest
, str
, 4*sizeof(WCHAR
)), "Incorrect string returned\n");
5164 static void test_BstrCopy(void)
5166 const CHAR szTestA
[6] = { 'T','e','s','t','\0','?' };
5167 const CHAR szTestTruncA
[4] = { 'T','e','s','\0' };
5168 LPINTERNAL_BSTR bstr
;
5173 str
= SysAllocStringByteLen(szTestA
, 3);
5174 ok (str
!= NULL
, "Expected non-NULL\n");
5177 V_VT(&vt1
) = VT_BSTR
;
5179 V_VT(&vt2
) = VT_EMPTY
;
5180 hres
= VariantCopy(&vt2
, &vt1
);
5181 ok (hres
== S_OK
,"Failed to copy binary bstring with hres 0x%08x\n", hres
);
5182 bstr
= Get(V_BSTR(&vt2
));
5183 ok (bstr
->dwLen
== 3, "Expected 3, got %d\n", bstr
->dwLen
);
5184 ok (!lstrcmpA((LPCSTR
)bstr
->szString
, szTestTruncA
), "String different\n");
5190 static void test_VarBstrCat(void)
5192 static const WCHAR sz1
[] = { 'a',0 };
5193 static const WCHAR sz2
[] = { 'b',0 };
5194 static const WCHAR sz1sz2
[] = { 'a','b',0 };
5195 static const WCHAR s1
[] = { 'a',0 };
5196 static const WCHAR s2
[] = { 'b',0 };
5197 static const WCHAR s1s2
[] = { 'a',0,'b',0 };
5198 static const char str1A
[] = "Have ";
5199 static const char str2A
[] = "A Cigar";
5201 BSTR str1
, str2
, res
;
5207 VarBstrCat(NULL
, NULL
, NULL
);
5210 /* Concatenation of two NULL strings works */
5211 ret
= VarBstrCat(NULL
, NULL
, &res
);
5212 ok(ret
== S_OK
, "VarBstrCat failed: %08x\n", ret
);
5213 ok(res
!= NULL
, "Expected a string\n");
5214 ok(SysStringLen(res
) == 0, "Expected a 0-length string\n");
5217 str1
= SysAllocString(sz1
);
5219 /* Concatenation with one NULL arg */
5220 ret
= VarBstrCat(NULL
, str1
, &res
);
5221 ok(ret
== S_OK
, "VarBstrCat failed: %08x\n", ret
);
5222 ok(res
!= NULL
, "Expected a string\n");
5223 ok(SysStringLen(res
) == SysStringLen(str1
), "Unexpected length\n");
5224 ok(!memcmp(res
, sz1
, SysStringLen(str1
)), "Unexpected value\n");
5226 ret
= VarBstrCat(str1
, NULL
, &res
);
5227 ok(ret
== S_OK
, "VarBstrCat failed: %08x\n", ret
);
5228 ok(res
!= NULL
, "Expected a string\n");
5229 ok(SysStringLen(res
) == SysStringLen(str1
), "Unexpected length\n");
5230 ok(!memcmp(res
, sz1
, SysStringLen(str1
)), "Unexpected value\n");
5233 /* Concatenation of two zero-terminated strings */
5234 str2
= SysAllocString(sz2
);
5235 ret
= VarBstrCat(str1
, str2
, &res
);
5236 ok(ret
== S_OK
, "VarBstrCat failed: %08x\n", ret
);
5237 ok(res
!= NULL
, "Expected a string\n");
5238 ok(SysStringLen(res
) == sizeof(sz1sz2
) / sizeof(WCHAR
) - 1,
5239 "Unexpected length\n");
5240 ok(!memcmp(res
, sz1sz2
, sizeof(sz1sz2
)), "Unexpected value\n");
5243 SysFreeString(str2
);
5244 SysFreeString(str1
);
5246 /* Concatenation of two strings with embedded NULLs */
5247 str1
= SysAllocStringLen(s1
, sizeof(s1
) / sizeof(WCHAR
));
5248 str2
= SysAllocStringLen(s2
, sizeof(s2
) / sizeof(WCHAR
));
5250 ret
= VarBstrCat(str1
, str2
, &res
);
5251 ok(ret
== S_OK
, "VarBstrCat failed: %08x\n", ret
);
5252 ok(res
!= NULL
, "Expected a string\n");
5253 ok(SysStringLen(res
) == sizeof(s1s2
) / sizeof(WCHAR
),
5254 "Unexpected length\n");
5255 ok(!memcmp(res
, s1s2
, sizeof(s1s2
)), "Unexpected value\n");
5258 SysFreeString(str2
);
5259 SysFreeString(str1
);
5261 /* Concatenation of ansi BSTRs, both odd byte count not including termination */
5262 str1
= SysAllocStringByteLen(str1A
, sizeof(str1A
)-1);
5263 str2
= SysAllocStringByteLen(str2A
, sizeof(str2A
)-1);
5264 len
= SysStringLen(str1
);
5265 ok(len
== (sizeof(str1A
)-1)/sizeof(WCHAR
), "got length %u\n", len
);
5266 len
= SysStringLen(str2
);
5267 ok(len
== (sizeof(str2A
)-1)/sizeof(WCHAR
), "got length %u\n", len
);
5269 ret
= VarBstrCat(str1
, str2
, &res
);
5270 ok(ret
== S_OK
, "VarBstrCat failed: %08x\n", ret
);
5271 ok(res
!= NULL
, "Expected a string\n");
5272 len
= (sizeof(str1A
) + sizeof(str2A
) - 2)/sizeof(WCHAR
);
5273 ok(SysStringLen(res
) == len
, "got %d, expected %u\n", SysStringLen(res
), len
);
5274 ok(!memcmp(res
, "Have A Cigar", sizeof(str1A
) + sizeof(str2A
) - 1), "got (%s)\n", (char*)res
);
5277 SysFreeString(str2
);
5278 SysFreeString(str1
);
5280 /* Concatenation of ansi BSTRs, both 1 byte length not including termination */
5281 str1
= SysAllocStringByteLen(str1A
, 1);
5282 str2
= SysAllocStringByteLen(str2A
, 1);
5283 len
= SysStringLen(str1
);
5284 ok(len
== 0, "got length %u\n", len
);
5285 len
= SysStringLen(str2
);
5286 ok(len
== 0, "got length %u\n", len
);
5288 ret
= VarBstrCat(str1
, str2
, &res
);
5289 ok(ret
== S_OK
, "VarBstrCat failed: %08x\n", ret
);
5290 ok(res
!= NULL
, "Expected a string\n");
5291 ok(SysStringLen(res
) == 1, "got %d, expected 1\n", SysStringLen(res
));
5292 ok(!memcmp(res
, "HA", 2), "got (%s)\n", (char*)res
);
5295 SysFreeString(str2
);
5296 SysFreeString(str1
);
5301 static void test_IUnknownClear(void)
5308 init_test_dispatch(1, VT_UI1
, &u
);
5309 pu
= (IUnknown
*)&u
.IDispatch_iface
;
5311 /* Test that IUnknown_Release is called on by-value */
5312 V_VT(&v
) = VT_UNKNOWN
;
5313 V_UNKNOWN(&v
) = (IUnknown
*)&u
.IDispatch_iface
;
5314 hres
= VariantClear(&v
);
5315 ok(hres
== S_OK
&& u
.ref
== 0 && V_VT(&v
) == VT_EMPTY
,
5316 "clear unknown: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5317 S_OK
, 0, VT_EMPTY
, hres
, u
.ref
, V_VT(&v
));
5319 /* But not when clearing a by-reference*/
5321 V_VT(&v
) = VT_UNKNOWN
|VT_BYREF
;
5322 V_UNKNOWNREF(&v
) = &pu
;
5323 hres
= VariantClear(&v
);
5324 ok(hres
== S_OK
&& u
.ref
== 1 && V_VT(&v
) == VT_EMPTY
,
5325 "clear dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5326 S_OK
, 1, VT_EMPTY
, hres
, u
.ref
, V_VT(&v
));
5329 static void test_IUnknownCopy(void)
5332 VARIANTARG vSrc
, vDst
;
5336 init_test_dispatch(1, VT_UI1
, &u
);
5337 pu
= (IUnknown
*)&u
.IDispatch_iface
;
5339 /* AddRef is called on by-value copy */
5341 V_VT(&vSrc
) = VT_UNKNOWN
;
5342 V_UNKNOWN(&vSrc
) = pu
;
5343 hres
= VariantCopy(&vDst
, &vSrc
);
5344 ok(hres
== S_OK
&& u
.ref
== 2 && V_VT(&vDst
) == VT_UNKNOWN
,
5345 "copy unknown: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5346 S_OK
, 2, VT_EMPTY
, hres
, u
.ref
, V_VT(&vDst
));
5348 /* AddRef is skipped on copy of by-reference IDispatch */
5351 V_VT(&vSrc
) = VT_UNKNOWN
|VT_BYREF
;
5352 V_UNKNOWNREF(&vSrc
) = &pu
;
5353 hres
= VariantCopy(&vDst
, &vSrc
);
5354 ok(hres
== S_OK
&& u
.ref
== 1 && V_VT(&vDst
) == (VT_UNKNOWN
|VT_BYREF
),
5355 "copy unknown: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5356 S_OK
, 1, VT_DISPATCH
, hres
, u
.ref
, V_VT(&vDst
));
5358 /* AddRef is called copying by-reference IDispatch with indirection */
5361 V_VT(&vSrc
) = VT_UNKNOWN
|VT_BYREF
;
5362 V_UNKNOWNREF(&vSrc
) = &pu
;
5363 hres
= VariantCopyInd(&vDst
, &vSrc
);
5364 ok(hres
== S_OK
&& u
.ref
== 2 && V_VT(&vDst
) == VT_UNKNOWN
,
5365 "copy unknown: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5366 S_OK
, 2, VT_DISPATCH
, hres
, u
.ref
, V_VT(&vDst
));
5368 /* Indirection in place also calls AddRef */
5370 V_VT(&vSrc
) = VT_UNKNOWN
|VT_BYREF
;
5371 V_UNKNOWNREF(&vSrc
) = &pu
;
5372 hres
= VariantCopyInd(&vSrc
, &vSrc
);
5373 ok(hres
== S_OK
&& u
.ref
== 2 && V_VT(&vSrc
) == VT_UNKNOWN
,
5374 "copy unknown: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5375 S_OK
, 2, VT_DISPATCH
, hres
, u
.ref
, V_VT(&vSrc
));
5378 static void test_IUnknownChangeTypeEx(void)
5381 VARIANTARG vSrc
, vDst
;
5387 init_test_dispatch(1, VT_UI1
, &u
);
5388 pu
= (IUnknown
*)&u
.IDispatch_iface
;
5390 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
5392 /* NULL IUnknown -> IDispatch */
5393 V_VT(&vSrc
) = VT_UNKNOWN
;
5394 V_UNKNOWN(&vSrc
) = NULL
;
5396 V_DISPATCH(&vDst
) = (void*)0xdeadbeef;
5397 hres
= VariantChangeTypeEx(&vDst
, &vSrc
, lcid
, 0, VT_DISPATCH
);
5398 ok(hres
== S_OK
&& V_VT(&vDst
) == VT_DISPATCH
&& V_DISPATCH(&vDst
) == NULL
,
5399 "change unk(src,dst): expected 0x%08x,%d,%p, got 0x%08x,%d,%p\n",
5400 S_OK
, VT_DISPATCH
, NULL
, hres
, V_VT(&vDst
), V_DISPATCH(&vDst
));
5402 V_VT(&vSrc
) = VT_UNKNOWN
;
5403 V_UNKNOWN(&vSrc
) = pu
;
5405 /* =>IDispatch in place */
5406 hres
= VariantChangeTypeEx(&vSrc
, &vSrc
, lcid
, 0, VT_DISPATCH
);
5407 ok(hres
== S_OK
&& u
.ref
== 1 &&
5408 V_VT(&vSrc
) == VT_DISPATCH
&& V_DISPATCH(&vSrc
) == (IDispatch
*)pu
,
5409 "change unk(src=src): expected 0x%08x,%d,%d,%p, got 0x%08x,%d,%d,%p\n",
5410 S_OK
, 1, VT_DISPATCH
, pu
, hres
, u
.ref
, V_VT(&vSrc
), V_DISPATCH(&vSrc
));
5414 V_VT(&vSrc
) = VT_UNKNOWN
;
5415 V_UNKNOWN(&vSrc
) = pu
;
5417 hres
= VariantChangeTypeEx(&vDst
, &vSrc
, lcid
, 0, VT_UNKNOWN
);
5418 /* Note vSrc is not cleared, as final refcount is 2 */
5419 ok(hres
== S_OK
&& u
.ref
== 2 &&
5420 V_VT(&vDst
) == VT_UNKNOWN
&& V_UNKNOWN(&vDst
) == pu
,
5421 "change unk(src,dst): expected 0x%08x,%d,%d,%p, got 0x%08x,%d,%d,%p\n",
5422 S_OK
, 2, VT_UNKNOWN
, pu
, hres
, u
.ref
, V_VT(&vDst
), V_UNKNOWN(&vDst
));
5424 /* Can't change unknown to anything else */
5425 for (vt
= 0; vt
<= VT_BSTR_BLOB
; vt
++)
5427 HRESULT hExpected
= DISP_E_BADVARTYPE
;
5429 V_VT(&vSrc
) = VT_UNKNOWN
;
5430 V_UNKNOWN(&vSrc
) = pu
;
5433 if (vt
== VT_UNKNOWN
|| vt
== VT_DISPATCH
|| vt
== VT_EMPTY
|| vt
== VT_NULL
)
5437 if (vt
== VT_I8
|| vt
== VT_UI8
)
5440 hExpected
= DISP_E_TYPEMISMATCH
;
5442 else if (vt
== VT_RECORD
)
5444 hExpected
= DISP_E_TYPEMISMATCH
;
5446 else if (vt
>= VT_I2
&& vt
<= VT_UINT
&& vt
!= (VARTYPE
)15)
5447 hExpected
= DISP_E_TYPEMISMATCH
;
5450 hres
= VariantChangeTypeEx(&vDst
, &vSrc
, lcid
, 0, vt
);
5451 ok(hres
== hExpected
,
5452 "change unk(badvar): vt %d expected 0x%08x, got 0x%08x\n",
5453 vt
, hExpected
, hres
);
5458 static void test_IDispatchClear(void)
5465 init_test_dispatch(1, VT_UI1
, &d
);
5466 pd
= &d
.IDispatch_iface
;
5468 /* As per IUnknown */
5470 V_VT(&v
) = VT_DISPATCH
;
5471 V_DISPATCH(&v
) = pd
;
5472 hres
= VariantClear(&v
);
5473 ok(hres
== S_OK
&& d
.ref
== 0 && V_VT(&v
) == VT_EMPTY
,
5474 "clear dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5475 S_OK
, 0, VT_EMPTY
, hres
, d
.ref
, V_VT(&v
));
5478 V_VT(&v
) = VT_DISPATCH
|VT_BYREF
;
5479 V_DISPATCHREF(&v
) = &pd
;
5480 hres
= VariantClear(&v
);
5481 ok(hres
== S_OK
&& d
.ref
== 1 && V_VT(&v
) == VT_EMPTY
,
5482 "clear dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5483 S_OK
, 1, VT_EMPTY
, hres
, d
.ref
, V_VT(&v
));
5486 static void test_IDispatchCopy(void)
5489 VARIANTARG vSrc
, vDst
;
5493 init_test_dispatch(1, VT_UI1
, &d
);
5494 pd
= &d
.IDispatch_iface
;
5496 /* As per IUnknown */
5499 V_VT(&vSrc
) = VT_DISPATCH
;
5500 V_DISPATCH(&vSrc
) = pd
;
5501 hres
= VariantCopy(&vDst
, &vSrc
);
5502 ok(hres
== S_OK
&& d
.ref
== 2 && V_VT(&vDst
) == VT_DISPATCH
,
5503 "copy dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5504 S_OK
, 2, VT_EMPTY
, hres
, d
.ref
, V_VT(&vDst
));
5508 V_VT(&vSrc
) = VT_DISPATCH
|VT_BYREF
;
5509 V_DISPATCHREF(&vSrc
) = &pd
;
5510 hres
= VariantCopy(&vDst
, &vSrc
);
5511 ok(hres
== S_OK
&& d
.ref
== 1 && V_VT(&vDst
) == (VT_DISPATCH
|VT_BYREF
),
5512 "copy dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5513 S_OK
, 1, VT_DISPATCH
, hres
, d
.ref
, V_VT(&vDst
));
5517 V_VT(&vSrc
) = VT_DISPATCH
|VT_BYREF
;
5518 V_DISPATCHREF(&vSrc
) = &pd
;
5519 hres
= VariantCopyInd(&vDst
, &vSrc
);
5520 ok(hres
== S_OK
&& d
.ref
== 2 && V_VT(&vDst
) == VT_DISPATCH
,
5521 "copy dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5522 S_OK
, 2, VT_DISPATCH
, hres
, d
.ref
, V_VT(&vDst
));
5525 V_VT(&vSrc
) = VT_DISPATCH
|VT_BYREF
;
5526 V_DISPATCHREF(&vSrc
) = &pd
;
5527 hres
= VariantCopyInd(&vSrc
, &vSrc
);
5528 ok(hres
== S_OK
&& d
.ref
== 2 && V_VT(&vSrc
) == VT_DISPATCH
,
5529 "copy dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5530 S_OK
, 2, VT_DISPATCH
, hres
, d
.ref
, V_VT(&vSrc
));
5533 static void test_IDispatchChangeTypeEx(void)
5536 VARIANTARG vSrc
, vDst
;
5541 init_test_dispatch(1, VT_UI1
, &d
);
5542 pd
= &d
.IDispatch_iface
;
5544 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
5546 /* NULL IDispatch -> IUnknown */
5547 V_VT(&vSrc
) = VT_DISPATCH
;
5548 V_DISPATCH(&vSrc
) = NULL
;
5550 V_UNKNOWN(&vDst
) = (void*)0xdeadbeef;
5551 hres
= VariantChangeTypeEx(&vDst
, &vSrc
, lcid
, 0, VT_UNKNOWN
);
5552 ok(hres
== S_OK
&& V_VT(&vDst
) == VT_UNKNOWN
&& V_UNKNOWN(&vDst
) == NULL
,
5553 "change unk(src,dst): expected 0x%08x,%d,%p, got 0x%08x,%d,%p\n",
5554 S_OK
, VT_UNKNOWN
, NULL
, hres
, V_VT(&vDst
), V_UNKNOWN(&vDst
));
5556 V_VT(&vSrc
) = VT_DISPATCH
;
5557 V_DISPATCH(&vSrc
) = pd
;
5559 /* =>IUnknown in place */
5560 hres
= VariantChangeTypeEx(&vSrc
, &vSrc
, lcid
, 0, VT_UNKNOWN
);
5561 ok(hres
== S_OK
&& d
.ref
== 1 &&
5562 V_VT(&vSrc
) == VT_UNKNOWN
&& V_UNKNOWN(&vSrc
) == (IUnknown
*)pd
,
5563 "change disp(src=src): expected 0x%08x,%d,%d,%p, got 0x%08x,%d,%d,%p\n",
5564 S_OK
, 1, VT_UNKNOWN
, pd
, hres
, d
.ref
, V_VT(&vSrc
), V_UNKNOWN(&vSrc
));
5568 V_VT(&vSrc
) = VT_DISPATCH
;
5569 V_DISPATCH(&vSrc
) = pd
;
5571 hres
= VariantChangeTypeEx(&vDst
, &vSrc
, lcid
, 0, VT_UNKNOWN
);
5572 /* Note vSrc is not cleared, as final refcount is 2 */
5573 ok(hres
== S_OK
&& d
.ref
== 2 &&
5574 V_VT(&vDst
) == VT_UNKNOWN
&& V_UNKNOWN(&vDst
) == (IUnknown
*)pd
,
5575 "change disp(src,dst): expected 0x%08x,%d,%d,%p, got 0x%08x,%d,%d,%p\n",
5576 S_OK
, 2, VT_UNKNOWN
, pd
, hres
, d
.ref
, V_VT(&vDst
), V_UNKNOWN(&vDst
));
5578 /* FIXME: Verify that VARIANT_NOVALUEPROP prevents conversion to integral
5579 * types. this requires that the xxxFromDisp tests work first.
5584 static void test_ErrorChangeTypeEx(void)
5587 VARIANTARG vSrc
, vDst
;
5591 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
5593 for (vt
= 0; vt
<= VT_BSTR_BLOB
; vt
++)
5595 HRESULT hExpected
= DISP_E_BADVARTYPE
;
5597 V_VT(&vSrc
) = VT_ERROR
;
5600 hres
= VariantChangeTypeEx(&vDst
, &vSrc
, lcid
, 0, vt
);
5606 if (vt
== VT_I8
|| vt
== VT_UI8
)
5609 hExpected
= DISP_E_TYPEMISMATCH
;
5611 else if (vt
== VT_RECORD
)
5613 hExpected
= DISP_E_TYPEMISMATCH
;
5615 else if (vt
<= VT_UINT
&& vt
!= (VARTYPE
)15)
5616 hExpected
= DISP_E_TYPEMISMATCH
;
5619 ok(hres
== hExpected
,
5620 "change err: vt %d expected 0x%08x, got 0x%08x\n", vt
, hExpected
, hres
);
5625 static void test_EmptyChangeTypeEx(void)
5630 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
5632 for (vt
= VT_EMPTY
; vt
<= VT_BSTR_BLOB
; vt
++)
5634 HRESULT hExpected
, hres
;
5635 VARIANTARG vSrc
, vDst
;
5637 /* skip for undefined types */
5638 if ((vt
== 15) || (vt
> VT_VERSIONED_STREAM
&& vt
< VT_BSTR_BLOB
))
5648 hExpected
= DISP_E_BADVARTYPE
;
5655 hExpected
= DISP_E_TYPEMISMATCH
;
5677 hExpected
= DISP_E_BADVARTYPE
;
5681 V_VT(&vSrc
) = VT_EMPTY
;
5682 memset(&vDst
, 0, sizeof(vDst
));
5683 V_VT(&vDst
) = VT_NULL
;
5685 hres
= VariantChangeTypeEx(&vDst
, &vSrc
, lcid
, 0, vt
);
5686 ok(hres
== hExpected
, "change empty: vt %d expected 0x%08x, got 0x%08x, vt %d\n",
5687 vt
, hExpected
, hres
, V_VT(&vDst
));
5690 ok(V_VT(&vDst
) == vt
, "change empty: vt %d, got %d\n", vt
, V_VT(&vDst
));
5691 VariantClear(&vDst
);
5697 static void test_NullChangeTypeEx(void)
5702 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
5704 for (vt
= VT_EMPTY
; vt
<= VT_BSTR_BLOB
; vt
++)
5706 VARIANTARG vSrc
, vDst
;
5707 HRESULT hExpected
, hres
;
5709 /* skip for undefined types */
5710 if ((vt
== 15) || (vt
> VT_VERSIONED_STREAM
&& vt
< VT_BSTR_BLOB
))
5718 hExpected
= DISP_E_TYPEMISMATCH
;
5720 hExpected
= DISP_E_BADVARTYPE
;
5746 hExpected
= DISP_E_TYPEMISMATCH
;
5749 hExpected
= DISP_E_BADVARTYPE
;
5753 V_VT(&vSrc
) = VT_NULL
;
5754 memset(&vDst
, 0, sizeof(vDst
));
5755 V_VT(&vDst
) = VT_EMPTY
;
5757 hres
= VariantChangeTypeEx(&vDst
, &vSrc
, lcid
, 0, vt
);
5758 ok(hres
== hExpected
, "change null: vt %d expected 0x%08x, got 0x%08x, vt %d\n",
5759 vt
, hExpected
, hres
, V_VT(&vDst
));
5761 /* should work only for VT_NULL -> VT_NULL case */
5763 ok(V_VT(&vDst
) == VT_NULL
, "change null: VT_NULL expected 0x%08x, got 0x%08x, vt %d\n",
5764 hExpected
, hres
, V_VT(&vDst
));
5766 ok(V_VT(&vDst
) == VT_EMPTY
, "change null: vt %d expected 0x%08x, got 0x%08x, vt %d\n",
5767 vt
, hExpected
, hres
, V_VT(&vDst
));
5773 static void test_UintChangeTypeEx(void)
5776 VARIANTARG vSrc
, vDst
;
5779 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
5781 /* Converting a VT_UINT to a VT_INT does not check for overflow */
5782 V_VT(&vDst
) = VT_EMPTY
;
5783 V_VT(&vSrc
) = VT_UINT
;
5785 hres
= VariantChangeTypeEx(&vDst
, &vSrc
, lcid
, 0, VT_I4
);
5786 ok(hres
== S_OK
&& V_VT(&vDst
) == VT_I4
&& V_I4(&vDst
) == -1,
5787 "change uint: Expected %d,0x%08x,%d got %d,0x%08x,%d\n",
5788 VT_I4
, S_OK
, -1, V_VT(&vDst
), hres
, V_I4(&vDst
));
5791 #define NUM_CUST_ITEMS 16
5793 static void test_ClearCustData(void)
5798 ci
.cCustData
= NUM_CUST_ITEMS
;
5799 ci
.prgCustData
= CoTaskMemAlloc( sizeof(CUSTDATAITEM
) * NUM_CUST_ITEMS
);
5800 for (i
= 0; i
< NUM_CUST_ITEMS
; i
++)
5801 VariantInit(&ci
.prgCustData
[i
].varValue
);
5803 ok(!ci
.cCustData
&& !ci
.prgCustData
, "ClearCustData didn't clear fields!\n");
5806 static void test_NullByRef(void)
5813 V_VT(&v1
) = VT_BYREF
|VT_VARIANT
;
5816 hRes
= VariantChangeTypeEx(&v2
, &v1
, 0, 0, VT_I4
);
5817 ok(hRes
== DISP_E_TYPEMISMATCH
, "VariantChangeTypeEx should return DISP_E_TYPEMISMATCH\n");
5820 V_VT(&v1
) = VT_BYREF
|VT_VARIANT
;
5825 hRes
= VariantChangeTypeEx(&v2
, &v1
, 0, 0, VT_VARIANT
);
5826 ok(hRes
== DISP_E_TYPEMISMATCH
, "VariantChangeTypeEx should return DISP_E_TYPEMISMATCH\n");
5827 ok(V_VT(&v2
) == VT_I4
&& V_I4(&v2
) == 123, "VariantChangeTypeEx shouldn't change pvargDest\n");
5829 hRes
= VariantChangeTypeEx(&v2
, &v1
, 0, 0, VT_BYREF
|VT_I4
);
5830 ok(hRes
== DISP_E_TYPEMISMATCH
, "VariantChangeTypeEx should return DISP_E_TYPEMISMATCH\n");
5832 hRes
= VariantChangeTypeEx(&v2
, &v1
, 0, 0, 0x3847);
5833 ok(hRes
== DISP_E_BADVARTYPE
, "VariantChangeTypeEx should return DISP_E_BADVARTYPE\n");
5836 /* Dst Variant should remain unchanged if VariantChangeType cannot convert */
5837 static void test_ChangeType_keep_dst(void)
5841 static const WCHAR testW
[] = {'t','e','s','t',0};
5844 bstr
= SysAllocString(testW
);
5847 V_VT(&v1
) = VT_BSTR
;
5849 hres
= VariantChangeTypeEx(&v1
, &v1
, 0, 0, VT_INT
);
5850 ok(hres
== DISP_E_TYPEMISMATCH
, "VariantChangeTypeEx returns %08x\n", hres
);
5851 ok(V_VT(&v1
) == VT_BSTR
&& V_BSTR(&v1
) == bstr
, "VariantChangeTypeEx changed dst variant\n");
5854 hres
= VariantChangeTypeEx(&v2
, &v1
, 0, 0, VT_INT
);
5855 ok(hres
== DISP_E_TYPEMISMATCH
, "VariantChangeTypeEx returns %08x\n", hres
);
5856 ok(V_VT(&v2
) == VT_INT
&& V_INT(&v2
) == 4, "VariantChangeTypeEx changed dst variant\n");
5857 V_VT(&v2
) = 0xff; /* incorrect variant type */
5858 hres
= VariantChangeTypeEx(&v2
, &v1
, 0, 0, VT_INT
);
5859 ok(hres
== DISP_E_TYPEMISMATCH
, "VariantChangeTypeEx returns %08x\n", hres
);
5860 ok(V_VT(&v2
) == 0xff, "VariantChangeTypeEx changed dst variant\n");
5861 hres
= VariantChangeTypeEx(&v2
, &v1
, 0, 0, VT_BSTR
);
5862 ok(hres
== DISP_E_BADVARTYPE
, "VariantChangeTypeEx returns %08x\n", hres
);
5863 ok(V_VT(&v2
) == 0xff, "VariantChangeTypeEx changed dst variant\n");
5864 SysFreeString(bstr
);
5867 /* This tests assumes an empty cache, so it needs to be ran early in the test. */
5868 static void test_bstr_cache(void)
5870 BSTR str
, str2
, strs
[20];
5873 static const WCHAR testW
[] = {'t','e','s','t',0};
5875 if (GetEnvironmentVariableA("OANOCACHE", NULL
, 0)) {
5876 skip("BSTR cache is disabled, some tests will be skipped.\n");
5880 str
= SysAllocString(testW
);
5881 /* This should put the string into cache */
5883 /* The string is in cache, this won't touch it */
5886 ok(SysStringLen(str
) == 4, "unexpected len\n");
5887 ok(!lstrcmpW(str
, testW
), "string changed\n");
5889 str2
= SysAllocString(testW
);
5890 ok(str
== str2
, "str != str2\n");
5891 SysFreeString(str2
);
5893 /* Fill the bucket with cached entries.
5894 We roll our own, to show that the cache doesn't use
5895 the bstr length field to determine bucket allocation. */
5896 for(i
=0; i
< sizeof(strs
)/sizeof(*strs
); i
++)
5898 DWORD_PTR
*ptr
= CoTaskMemAlloc(64);
5900 strs
[i
] = (BSTR
)(ptr
+ 1);
5902 for(i
=0; i
< sizeof(strs
)/sizeof(*strs
); i
++)
5903 SysFreeString(strs
[i
]);
5905 /* Following allocation will be made from cache */
5906 str
= SysAllocStringLen(NULL
, 24);
5907 ok(str
== strs
[0], "str != strs[0]\n");
5909 /* Smaller buffers may also use larget cached buffers */
5910 str2
= SysAllocStringLen(NULL
, 16);
5911 ok(str2
== strs
[1], "str2 != strs[1]\n");
5914 SysFreeString(str2
);
5916 SysFreeString(str2
);
5919 static void write_typelib(int res_no
, const char *filename
)
5926 file
= CreateFileA( filename
, GENERIC_READ
|GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0 );
5927 ok( file
!= INVALID_HANDLE_VALUE
, "file creation failed\n" );
5928 if (file
== INVALID_HANDLE_VALUE
) return;
5929 res
= FindResourceA( GetModuleHandleA(NULL
), (LPCSTR
)MAKEINTRESOURCE(res_no
), "TYPELIB" );
5930 ok( res
!= 0, "couldn't find resource\n" );
5931 ptr
= LockResource( LoadResource( GetModuleHandleA(NULL
), res
));
5932 WriteFile( file
, ptr
, SizeofResource( GetModuleHandleA(NULL
), res
), &written
, NULL
);
5933 ok( written
== SizeofResource( GetModuleHandleA(NULL
), res
), "couldn't write resource\n" );
5934 CloseHandle( file
);
5937 static const char *create_test_typelib(int res_no
)
5939 static char filename
[MAX_PATH
];
5941 GetTempFileNameA( ".", "tlb", 0, filename
);
5942 write_typelib(res_no
, filename
);
5946 static void test_recinfo(void)
5948 static const WCHAR testW
[] = {'t','e','s','t',0};
5949 static WCHAR teststructW
[] = {'t','e','s','t','_','s','t','r','u','c','t',0};
5950 static WCHAR teststruct2W
[] = {'t','e','s','t','_','s','t','r','u','c','t','2',0};
5951 static WCHAR teststruct3W
[] = {'t','e','s','t','_','s','t','r','u','c','t','3',0};
5952 WCHAR filenameW
[MAX_PATH
], filename2W
[MAX_PATH
];
5953 ITypeInfo
*typeinfo
, *typeinfo2
, *typeinfo3
;
5954 IRecordInfo
*recinfo
, *recinfo2
, *recinfo3
;
5955 struct test_struct teststruct
, testcopy
;
5956 ITypeLib
*typelib
, *typelib2
;
5957 const char *filename
;
5958 DummyDispatch dispatch
;
5966 filename
= create_test_typelib(2);
5967 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, filenameW
, MAX_PATH
);
5968 hr
= LoadTypeLibEx(filenameW
, REGKIND_NONE
, &typelib
);
5969 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
5971 filename
= create_test_typelib(3);
5972 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, filename2W
, MAX_PATH
);
5973 hr
= LoadTypeLibEx(filename2W
, REGKIND_NONE
, &typelib2
);
5974 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
5978 hr
= ITypeLib_FindName(typelib
, teststructW
, 0, &typeinfo
, &memid
, &found
);
5979 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
5980 ok(typeinfo
!= NULL
, "got %p\n", typeinfo
);
5981 hr
= ITypeInfo_GetTypeAttr(typeinfo
, &attr
);
5982 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
5983 ok(IsEqualGUID(&attr
->guid
, &UUID_test_struct
), "got %s\n", wine_dbgstr_guid(&attr
->guid
));
5984 ok(attr
->typekind
== TKIND_RECORD
, "got %d\n", attr
->typekind
);
5988 hr
= ITypeLib_FindName(typelib
, teststruct2W
, 0, &typeinfo2
, &memid
, &found
);
5989 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
5990 ok(typeinfo2
!= NULL
, "got %p\n", typeinfo2
);
5994 hr
= ITypeLib_FindName(typelib2
, teststruct3W
, 0, &typeinfo3
, &memid
, &found
);
5995 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
5996 ok(typeinfo3
!= NULL
, "got %p\n", typeinfo3
);
5998 hr
= GetRecordInfoFromTypeInfo(typeinfo
, &recinfo
);
5999 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
6001 hr
= GetRecordInfoFromTypeInfo(typeinfo2
, &recinfo2
);
6002 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
6004 hr
= GetRecordInfoFromTypeInfo(typeinfo3
, &recinfo3
);
6005 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
6007 /* IsMatchingType, these two records only differ in GUIDs */
6008 ret
= IRecordInfo_IsMatchingType(recinfo
, recinfo2
);
6009 ok(!ret
, "got %d\n", ret
);
6011 /* these two have same GUIDs, but different set of fields */
6012 ret
= IRecordInfo_IsMatchingType(recinfo2
, recinfo3
);
6013 ok(ret
, "got %d\n", ret
);
6015 IRecordInfo_Release(recinfo3
);
6016 ITypeInfo_Release(typeinfo3
);
6017 IRecordInfo_Release(recinfo2
);
6018 ITypeInfo_Release(typeinfo2
);
6021 hr
= IRecordInfo_GetSize(recinfo
, &size
);
6022 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
6023 ok(size
== sizeof(struct test_struct
), "got size %d\n", size
);
6024 ok(attr
->cbSizeInstance
== sizeof(struct test_struct
), "got instance size %d\n", attr
->cbSizeInstance
);
6025 ITypeInfo_ReleaseTypeAttr(typeinfo
, attr
);
6028 teststruct
.hr
= E_FAIL
;
6030 teststruct
.disp
= (void*)0xdeadbeef;
6031 teststruct
.bstr
= (void*)0xdeadbeef;
6033 hr
= IRecordInfo_RecordInit(recinfo
, &teststruct
);
6034 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
6035 ok(teststruct
.hr
== 0, "got 0x%08x\n", teststruct
.hr
);
6036 ok(teststruct
.b
== 0, "got 0x%08x\n", teststruct
.b
);
6037 ok(teststruct
.disp
== NULL
, "got %p\n", teststruct
.disp
);
6038 ok(teststruct
.bstr
== NULL
, "got %p\n", teststruct
.bstr
);
6040 init_test_dispatch(10, VT_UI1
, &dispatch
);
6042 /* RecordCopy(), interface field reference increased */
6043 teststruct
.hr
= S_FALSE
;
6044 teststruct
.b
= VARIANT_TRUE
;
6045 teststruct
.disp
= &dispatch
.IDispatch_iface
;
6046 teststruct
.bstr
= SysAllocString(testW
);
6047 memset(&testcopy
, 0, sizeof(testcopy
));
6048 hr
= IRecordInfo_RecordCopy(recinfo
, &teststruct
, &testcopy
);
6049 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
6050 ok(testcopy
.hr
== S_FALSE
, "got 0x%08x\n", testcopy
.hr
);
6051 ok(testcopy
.b
== VARIANT_TRUE
, "got %d\n", testcopy
.b
);
6052 ok(testcopy
.disp
== teststruct
.disp
, "got %p\n", testcopy
.disp
);
6053 ok(dispatch
.ref
== 11, "got %d\n", dispatch
.ref
);
6054 ok(testcopy
.bstr
!= teststruct
.bstr
, "got %p\n", testcopy
.bstr
);
6055 ok(!lstrcmpW(testcopy
.bstr
, teststruct
.bstr
), "got %s, %s\n", wine_dbgstr_w(testcopy
.bstr
), wine_dbgstr_w(teststruct
.bstr
));
6058 hr
= IRecordInfo_RecordClear(recinfo
, &teststruct
);
6059 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
6060 ok(teststruct
.bstr
== NULL
, "got %p\n", teststruct
.bstr
);
6061 hr
= IRecordInfo_RecordClear(recinfo
, &testcopy
);
6062 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
6063 ok(testcopy
.bstr
== NULL
, "got %p\n", testcopy
.bstr
);
6065 /* now the destination contains the interface pointer */
6066 memset(&testcopy
, 0, sizeof(testcopy
));
6067 testcopy
.disp
= &dispatch
.IDispatch_iface
;
6070 hr
= IRecordInfo_RecordCopy(recinfo
, &teststruct
, &testcopy
);
6071 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
6072 ok(dispatch
.ref
== 9, "got %d\n", dispatch
.ref
);
6074 IRecordInfo_Release(recinfo
);
6076 ITypeInfo_Release(typeinfo
);
6077 ITypeLib_Release(typelib
);
6078 DeleteFileW(filenameW
);
6079 DeleteFileW(filename2W
);
6084 hOleaut32
= GetModuleHandleA("oleaut32.dll");
6086 has_i8
= GetProcAddress(hOleaut32
, "VarI8FromI1") != NULL
;
6087 has_locales
= has_i8
&& GetProcAddress(hOleaut32
, "GetVarConversionLocaleSetting") != NULL
;
6089 trace("LCIDs: System=0x%08x, User=0x%08x\n", GetSystemDefaultLCID(),
6090 GetUserDefaultLCID());
6097 test_VarI1FromUI1();
6098 test_VarI1FromUI2();
6099 test_VarI1FromUI4();
6100 test_VarI1FromUI8();
6101 test_VarI1FromBool();
6104 test_VarI1FromDate();
6106 test_VarI1FromDec();
6107 test_VarI1FromStr();
6108 test_VarUI1FromDisp();
6110 test_VarI1ChangeTypeEx();
6112 test_VarUI1FromI1();
6113 test_VarUI1FromI2();
6114 test_VarUI1FromI4();
6115 test_VarUI1FromI8();
6116 test_VarUI1FromUI2();
6117 test_VarUI1FromUI4();
6118 test_VarUI1FromUI8();
6119 test_VarUI1FromBool();
6120 test_VarUI1FromR4();
6121 test_VarUI1FromR8();
6122 test_VarUI1FromDate();
6123 test_VarUI1FromCy();
6124 test_VarUI1FromDec();
6125 test_VarUI1FromStr();
6127 test_VarUI1ChangeTypeEx();
6132 test_VarI2FromUI1();
6133 test_VarI2FromUI2();
6134 test_VarI2FromUI4();
6135 test_VarI2FromUI8();
6136 test_VarI2FromBool();
6139 test_VarI2FromDate();
6141 test_VarI2FromDec();
6142 test_VarI2FromStr();
6144 test_VarI2ChangeTypeEx();
6146 test_VarUI2FromI1();
6147 test_VarUI2FromI2();
6148 test_VarUI2FromI4();
6149 test_VarUI2FromI8();
6150 test_VarUI2FromUI1();
6151 test_VarUI2FromUI4();
6152 test_VarUI2FromUI8();
6153 test_VarUI2FromBool();
6154 test_VarUI2FromR4();
6155 test_VarUI2FromR8();
6156 test_VarUI2FromDate();
6157 test_VarUI2FromCy();
6158 test_VarUI2FromDec();
6159 test_VarUI2FromStr();
6161 test_VarUI2ChangeTypeEx();
6166 test_VarI4FromUI1();
6167 test_VarI4FromUI2();
6168 test_VarI4FromUI4();
6169 test_VarI4FromUI8();
6170 test_VarI4FromBool();
6173 test_VarI4FromDate();
6175 test_VarI4FromDec();
6176 test_VarI4FromStr();
6178 test_VarI4ChangeTypeEx();
6180 test_VarUI4FromI1();
6181 test_VarUI4FromI2();
6182 test_VarUI4FromUI2();
6183 test_VarUI4FromI8();
6184 test_VarUI4FromUI1();
6185 test_VarUI4FromI4();
6186 test_VarUI4FromUI8();
6187 test_VarUI4FromBool();
6188 test_VarUI4FromR4();
6189 test_VarUI4FromR8();
6190 test_VarUI4FromDate();
6191 test_VarUI4FromCy();
6192 test_VarUI4FromDec();
6193 test_VarUI4FromStr();
6195 test_VarUI4ChangeTypeEx();
6198 test_VarI8FromUI1();
6200 test_VarI8FromUI2();
6201 test_VarI8FromUI4();
6204 test_VarI8FromBool();
6205 test_VarI8FromUI8();
6207 test_VarI8FromDec();
6208 test_VarI8FromDate();
6209 test_VarI8FromStr();
6211 test_VarI8ChangeTypeEx();
6213 test_VarUI8FromI1();
6214 test_VarUI8FromUI1();
6215 test_VarUI8FromI2();
6216 test_VarUI8FromUI2();
6217 test_VarUI8FromUI4();
6218 test_VarUI8FromR4();
6219 test_VarUI8FromR8();
6220 test_VarUI8FromBool();
6221 test_VarUI8FromI8();
6222 test_VarUI8FromCy();
6223 test_VarUI8FromDec();
6224 test_VarUI8FromDate();
6225 test_VarUI8FromStr();
6227 test_VarUI8ChangeTypeEx();
6230 test_VarR4FromUI1();
6232 test_VarR4FromUI2();
6234 test_VarR4FromUI4();
6236 test_VarR4FromBool();
6239 test_VarR4FromUI8();
6240 test_VarR4FromDec();
6241 test_VarR4FromDate();
6242 test_VarR4FromStr();
6244 test_VarR4ChangeTypeEx();
6247 test_VarR8FromUI1();
6249 test_VarR8FromUI2();
6251 test_VarR8FromUI4();
6253 test_VarR8FromBool();
6256 test_VarR8FromUI8();
6257 test_VarR8FromDec();
6258 test_VarR8FromDate();
6259 test_VarR8FromStr();
6261 test_VarR8ChangeTypeEx();
6264 test_VarDateFromI1();
6265 test_VarDateFromUI1();
6266 test_VarDateFromI2();
6267 test_VarDateFromUI2();
6268 test_VarDateFromI4();
6269 test_VarDateFromUI4();
6270 test_VarDateFromR4();
6271 test_VarDateFromR8();
6272 test_VarDateFromBool();
6273 test_VarDateFromCy();
6274 test_VarDateFromI8();
6275 test_VarDateFromUI8();
6276 test_VarDateFromDec();
6277 test_VarDateFromStr();
6279 test_VarDateChangeTypeEx();
6282 test_VarCyFromUI1();
6284 test_VarCyFromUI2();
6286 test_VarCyFromUI4();
6289 test_VarCyFromBool();
6291 test_VarCyFromUI8();
6292 test_VarCyFromDec();
6293 test_VarCyFromDate();
6308 test_VarDecFromI1();
6309 test_VarDecFromI2();
6310 test_VarDecFromI4();
6311 test_VarDecFromI8();
6312 test_VarDecFromUI1();
6313 test_VarDecFromUI2();
6314 test_VarDecFromUI4();
6315 test_VarDecFromUI8();
6316 test_VarDecFromR4();
6317 test_VarDecFromR8();
6318 test_VarDecFromDate();
6319 test_VarDecFromStr();
6320 test_VarDecFromCy();
6321 test_VarDecFromDate();
6322 test_VarDecFromBool();
6334 test_VarBoolFromI1();
6335 test_VarBoolFromUI1();
6336 test_VarBoolFromI2();
6337 test_VarBoolFromUI2();
6338 test_VarBoolFromI4();
6339 test_VarBoolFromUI4();
6340 test_VarBoolFromR4();
6341 test_VarBoolFromR8();
6342 test_VarBoolFromCy();
6343 test_VarBoolFromI8();
6344 test_VarBoolFromUI8();
6345 test_VarBoolFromDec();
6346 test_VarBoolFromDate();
6347 test_VarBoolFromStr();
6349 test_VarBoolChangeTypeEx();
6351 test_VarBstrFromR4();
6352 test_VarBstrFromDate();
6353 test_VarBstrFromCy();
6354 test_VarBstrFromDec();
6356 test_SysStringLen();
6357 test_SysStringByteLen();
6358 test_SysAllocString();
6359 test_SysAllocStringLen();
6360 test_SysAllocStringByteLen();
6361 test_SysReAllocString();
6362 test_SysReAllocStringLen();
6366 test_IUnknownClear();
6367 test_IUnknownCopy();
6368 test_IUnknownChangeTypeEx();
6370 test_IDispatchClear();
6371 test_IDispatchCopy();
6372 test_IDispatchChangeTypeEx();
6374 test_ErrorChangeTypeEx();
6375 test_EmptyChangeTypeEx();
6376 test_NullChangeTypeEx();
6377 test_UintChangeTypeEx();
6379 test_ClearCustData();
6382 test_ChangeType_keep_dst();