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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "wine/test.h"
22 #include "wine/unicode.h"
26 /* Some Visual C++ versions choke on __uint64 to float conversions.
27 * To fix this you need either VC++ 6.0 plus the processor pack
28 * or Visual C++ >=7.0.
31 # define HAS_UINT64_TO_FLOAT
34 # define HAS_UINT64_TO_FLOAT
37 # if defined(_mm_free)
38 /* _mm_free is defined if the Processor Pack has been installed */
39 # define HAS_UINT64_TO_FLOAT
45 static HMODULE hOleaut32
;
47 #ifdef NONAMELESSUNION
54 #ifdef NONAMELESSSTRUCT
62 /* Get a conversion function ptr, return if function not available */
63 #define CHECKPTR(func) p##func = (void*)GetProcAddress(hOleaut32, #func); \
65 trace("function " # func " not available, not testing it\n"); return; }
67 /* Is a given function exported from oleaut32? */
68 #define HAVE_FUNC(func) ((void*)GetProcAddress(hOleaut32, #func) != NULL)
70 /* Have IRecordInfo data type? */
71 #define HAVE_OLEAUT32_RECORD HAVE_FUNC(SafeArraySetRecordInfo)
72 /* Have DECIMAL data type with new error checking? */
73 #define HAVE_OLEAUT32_DECIMAL HAVE_FUNC(VarDecAdd)
74 /* Have CY data type? */
75 #define HAVE_OLEAUT32_CY HAVE_FUNC(VarCyAdd)
76 /* Have I8/UI8 data type? */
77 #define HAVE_OLEAUT32_I8 HAVE_FUNC(VarI8FromI1)
78 /* Have proper locale conversions? */
79 #define HAVE_OLEAUT32_LOCALES (HAVE_FUNC(GetVarConversionLocaleSetting) && HAVE_OLEAUT32_I8)
80 /* Is this an ancient version with support for only I2/I4/R4/R8/DATE? */
81 #define IS_ANCIENT (!HAVE_FUNC(VarI1FromI2))
82 /* Is vt a type unavailable to ancient versions? */
83 #define IS_MODERN_VTYPE(vt) (vt==VT_VARIANT||vt==VT_DECIMAL|| \
84 vt==VT_I1||vt==VT_UI2||vt==VT_UI4||vt == VT_INT||vt == VT_UINT)
86 /* Macros for converting and testing results */
87 #define CONVVARS(typ) HRESULT hres; CONV_TYPE out; typ in
89 #define _EXPECTRES(res, x, fs) \
90 ok((hres == S_OK && out == (CONV_TYPE)(x)) || ((HRESULT)res != S_OK && hres == (HRESULT)res), \
91 "expected " #x ", got " fs "; hres=0x%08lx\n", out, hres)
92 #define EXPECT(x) EXPECTRES(S_OK, (x))
93 #define EXPECT_OVERFLOW EXPECTRES(DISP_E_OVERFLOW, DISP_E_OVERFLOW)
94 #define EXPECT_MISMATCH EXPECTRES(DISP_E_TYPEMISMATCH,DISP_E_TYPEMISMATCH)
95 #define EXPECT_BADVAR EXPECTRES(DISP_E_BADVARTYPE, DISP_E_BADVARTYPE)
96 #define EXPECT_INVALID EXPECTRES(E_INVALIDARG, E_INVALIDARG)
97 #define EXPECT_LT EXPECTRES(VARCMP_LT, VARCMP_LT)
98 #define EXPECT_GT EXPECTRES(VARCMP_GT, VARCMP_GT)
99 #define EXPECT_EQ EXPECTRES(VARCMP_EQ, VARCMP_EQ)
100 #define EXPECT_DBL(x) \
101 ok(hres == S_OK && fabs(out-(x))<1e-14, "expected " #x ", got %16.16g; hres=0x%08lx\n", out, hres)
103 #define CONVERT(func, val) in = val; hres = p##func(in, &out)
104 #define CONVERTRANGE(func,start,end) for (i = start; i < end; i+=1) { CONVERT(func, i); EXPECT(i); };
105 #define OVERFLOWRANGE(func,start,end) for (i = start; i < end; i+=1) { CONVERT(func, i); EXPECT_OVERFLOW; };
107 #define CY_MULTIPLIER 10000
109 #define DATE_MIN -657434
110 #define DATE_MAX 2958465
112 #define CONVERT_I8(func,hi,lo) in = hi; in = (in << 32) | lo; hres = p##func(in, &out)
114 #define CONVERT_CY(func,val) in.int64 = (LONGLONG)(val * CY_MULTIPLIER); hres = p##func(in, &out)
116 #define CONVERT_CY64(func,hi,lo) S(in).Hi = hi; S(in).Lo = lo; in.int64 *= CY_MULTIPLIER; hres = p##func(in, &out)
118 #define SETDEC(dec, scl, sgn, hi, lo) S(U(dec)).scale = (BYTE)scl; S(U(dec)).sign = (BYTE)sgn; \
119 dec.Hi32 = (ULONG)hi; U1(dec).Lo64 = (ULONG64)lo
121 #define SETDEC64(dec, scl, sgn, hi, mid, lo) S(U(dec)).scale = (BYTE)scl; S(U(dec)).sign = (BYTE)sgn; \
122 dec.Hi32 = (ULONG)hi; S1(U1(dec)).Mid32 = mid; S1(U1(dec)).Lo32 = lo;
124 #define CONVERT_DEC(func,scl,sgn,hi,lo) SETDEC(in,scl,sgn,hi,lo); hres = p##func(&in, &out)
126 #define CONVERT_DEC64(func,scl,sgn,hi,mid,lo) SETDEC64(in,scl,sgn,hi,mid,lo); hres = p##func(&in, &out)
128 #define CONVERT_BADDEC(func) \
129 if (HAVE_OLEAUT32_DECIMAL) \
131 CONVERT_DEC(func,29,0,0,0); EXPECT_INVALID; \
132 CONVERT_DEC(func,0,0x1,0,0); EXPECT_INVALID; \
133 CONVERT_DEC(func,0,0x40,0,0); EXPECT_INVALID; \
134 CONVERT_DEC(func,0,0x7f,0,0); EXPECT_INVALID; \
137 #define CONVERT_STR(func,str,flags) \
139 if (str) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)); \
140 hres = p##func(str ? buff : NULL,in,flags,&out)
142 #define COPYTEST(val, vt, srcval, dstval, srcref, dstref, fs) do { \
143 HRESULT hres; VARIANTARG vSrc, vDst; CONV_TYPE in = val; \
144 VariantInit(&vSrc); VariantInit(&vDst); \
145 V_VT(&vSrc) = vt; srcval = in; \
146 hres = VariantCopy(&vDst, &vSrc); \
147 ok(hres == S_OK && V_VT(&vDst) == vt && dstval == in, \
148 "copy hres 0x%lX, type %d, value (" fs ") " fs "\n", hres, V_VT(&vDst), val, dstval); \
149 V_VT(&vSrc) = vt|VT_BYREF; srcref = ∈ \
150 hres = VariantCopy(&vDst, &vSrc); \
151 ok(hres == S_OK && V_VT(&vDst) == (vt|VT_BYREF) && dstref == &in, \
152 "ref hres 0x%lX, type %d, ref (%p) %p\n", hres, V_VT(&vDst), &in, dstref); \
153 hres = VariantCopyInd(&vDst, &vSrc); \
154 ok(hres == S_OK && V_VT(&vDst) == vt && dstval == in, \
155 "ind hres 0x%lX, type %d, value (" fs ") " fs "\n", hres, V_VT(&vDst), val, dstval); \
158 #define CHANGETYPEEX(typ) hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, typ)
160 #define TYPETEST(typ,res,fs) CHANGETYPEEX(typ); \
161 ok(hres == S_OK && V_VT(&vDst) == typ && (CONV_TYPE)res == in, \
162 "hres=0x%lX, type=%d (should be %d(" #typ ")), value=" fs " (should be 1)\n", \
163 hres, V_VT(&vDst), typ, (CONV_TYPE)res);
164 #define TYPETESTI8(typ,res) CHANGETYPEEX(typ); \
165 ok(hres == S_OK && V_VT(&vDst) == typ && (CONV_TYPE)res == in, \
166 "hres=0x%lX, type=%d (should be %d(" #typ ")), value=%d (should be 1)\n", \
167 hres, V_VT(&vDst), typ, (int)res);
168 #define BADVAR(typ) CHANGETYPEEX(typ); out = (CONV_TYPE)hres; EXPECT_BADVAR
169 #define MISMATCH(typ) CHANGETYPEEX(typ); out = (CONV_TYPE)hres; EXPECT_MISMATCH
171 #define INITIAL_TYPETEST(vt, val, fs) \
172 VariantInit(&vSrc); \
173 VariantInit(&vDst); \
177 TYPETEST(VT_I1, V_I1(&vDst), fs); \
178 TYPETEST(VT_UI2, V_UI2(&vDst), fs); \
179 TYPETEST(VT_UI4, V_UI4(&vDst), fs); \
180 TYPETEST(VT_INT, V_INT(&vDst), fs); \
181 TYPETEST(VT_UINT, V_UINT(&vDst), fs); \
183 BADVAR(VT_I1); BADVAR(VT_UI2); BADVAR(VT_UI4); \
184 BADVAR(VT_INT); BADVAR(VT_UINT); \
186 TYPETEST(VT_UI1, V_UI1(&vDst), fs); \
187 TYPETEST(VT_I2, V_I2(&vDst), fs); \
188 TYPETEST(VT_I4, V_I4(&vDst), fs); \
189 TYPETEST(VT_R4, V_R4(&vDst), fs); \
190 TYPETEST(VT_R8, V_R8(&vDst), fs); \
191 TYPETEST(VT_DATE, V_DATE(&vDst), fs); \
192 if (HAVE_OLEAUT32_I8) \
194 TYPETEST(VT_I8, V_I8(&vDst), fs); \
195 TYPETEST(VT_UI8, V_UI8(&vDst), fs); \
198 #define INITIAL_TYPETESTI8(vt, val) \
199 VariantInit(&vSrc); \
200 VariantInit(&vDst); \
203 TYPETESTI8(VT_I1, V_I1(&vDst)); \
204 TYPETESTI8(VT_UI1, V_UI1(&vDst)); \
205 TYPETESTI8(VT_I2, V_I2(&vDst)); \
206 TYPETESTI8(VT_UI2, V_UI2(&vDst)); \
207 TYPETESTI8(VT_I4, V_I4(&vDst)); \
208 TYPETESTI8(VT_UI4, V_UI4(&vDst)); \
209 TYPETESTI8(VT_INT, V_INT(&vDst)); \
210 TYPETESTI8(VT_UINT, V_UINT(&vDst)); \
211 TYPETESTI8(VT_R4, V_R4(&vDst)); \
212 TYPETESTI8(VT_R8, V_R8(&vDst)); \
213 TYPETESTI8(VT_DATE, V_DATE(&vDst)); \
214 TYPETESTI8(VT_I8, V_I8(&vDst)); \
215 TYPETESTI8(VT_UI8, V_UI8(&vDst))
217 #define COMMON_TYPETEST \
218 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_BOOL); \
219 ok(hres == S_OK && V_VT(&vDst) == VT_BOOL && \
220 (V_BOOL(&vDst) == VARIANT_TRUE || (V_VT(&vSrc) == VT_BOOL && V_BOOL(&vDst) == 1)), \
221 "->VT_BOOL hres=0x%lX, type=%d (should be VT_BOOL), value %d (should be VARIANT_TRUE)\n", \
222 hres, V_VT(&vDst), V_BOOL(&vDst)); \
223 if (HAVE_OLEAUT32_CY) \
225 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_CY); \
226 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == CY_MULTIPLIER, \
227 "->VT_CY hres=0x%lX, type=%d (should be VT_CY), value (%08lx,%08lx) (should be CY_MULTIPLIER)\n", \
228 hres, V_VT(&vDst), S(V_CY(&vDst)).Hi, S(V_CY(&vDst)).Lo); \
230 if (V_VT(&vSrc) != VT_DATE) \
232 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_BSTR); \
233 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && \
234 V_BSTR(&vDst) && V_BSTR(&vDst)[0] == '1' && V_BSTR(&vDst)[1] == '\0', \
235 "->VT_BSTR hres=0x%lX, type=%d (should be VT_BSTR), *bstr='%c'\n", \
236 hres, V_VT(&vDst), V_BSTR(&vDst) ? *V_BSTR(&vDst) : '?'); \
238 if (HAVE_OLEAUT32_DECIMAL) \
240 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_DECIMAL); \
241 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && \
242 S(U(V_DECIMAL(&vDst))).sign == 0 && S(U(V_DECIMAL(&vDst))).scale == 0 && \
243 V_DECIMAL(&vDst).Hi32 == 0 && U1(V_DECIMAL(&vDst)).Lo64 == (ULONGLONG)in, \
244 "->VT_DECIMAL hres=0x%lX, type=%d (should be VT_DECIMAL), sign=%d, scale=%d, hi=%lu, lo=(%8lx %8lx),\n", \
245 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign, S(U(V_DECIMAL(&vDst))).scale, \
246 V_DECIMAL(&vDst).Hi32, S1(U1(V_DECIMAL(&vDst))).Mid32, S1(U1(V_DECIMAL(&vDst))).Lo32); \
248 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_EMPTY); \
249 ok(hres == S_OK && V_VT(&vDst) == VT_EMPTY, "->VT_EMPTY hres=0x%lX, type=%d (should be VT_EMPTY)\n", hres, V_VT(&vDst)); \
250 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_NULL); \
251 ok(hres == S_OK && V_VT(&vDst) == VT_NULL, "->VT_NULL hres=0x%lX, type=%d (should be VT_NULL)\n", hres, V_VT(&vDst)); \
252 MISMATCH(VT_DISPATCH); \
253 MISMATCH(VT_ERROR); \
254 MISMATCH(VT_UNKNOWN); \
255 if (!IS_ANCIENT) { MISMATCH(VT_VARIANT); } else { BADVAR(VT_VARIANT); } \
256 if (HAVE_OLEAUT32_RECORD) \
258 MISMATCH(VT_RECORD); \
261 BADVAR(VT_HRESULT); \
262 BADVAR(VT_SAFEARRAY); \
264 BADVAR(VT_USERDEFINED); \
268 BADVAR(VT_INT_PTR); \
269 BADVAR(VT_UINT_PTR); \
270 BADVAR(VT_FILETIME); \
273 BADVAR(VT_STORAGE); \
274 BADVAR(VT_STREAMED_OBJECT); \
275 BADVAR(VT_STORED_OBJECT); \
276 BADVAR(VT_BLOB_OBJECT); \
281 /* Early versions of oleaut32 are missing many functions */
282 static HRESULT (WINAPI
*pVarI1FromUI1
)(BYTE
,signed char*);
283 static HRESULT (WINAPI
*pVarI1FromI2
)(SHORT
,signed char*);
284 static HRESULT (WINAPI
*pVarI1FromI4
)(LONG
,signed char*);
285 static HRESULT (WINAPI
*pVarI1FromR4
)(FLOAT
,signed char*);
286 static HRESULT (WINAPI
*pVarI1FromR8
)(double,signed char*);
287 static HRESULT (WINAPI
*pVarI1FromDate
)(DATE
,signed char*);
288 static HRESULT (WINAPI
*pVarI1FromCy
)(CY
,signed char*);
289 static HRESULT (WINAPI
*pVarI1FromStr
)(OLECHAR
*,LCID
,ULONG
,signed char*);
290 static HRESULT (WINAPI
*pVarI1FromBool
)(VARIANT_BOOL
,signed char*);
291 static HRESULT (WINAPI
*pVarI1FromUI2
)(USHORT
,signed char*);
292 static HRESULT (WINAPI
*pVarI1FromUI4
)(ULONG
,signed char*);
293 static HRESULT (WINAPI
*pVarI1FromDec
)(DECIMAL
*,signed char*);
294 static HRESULT (WINAPI
*pVarI1FromI8
)(LONG64
,signed char*);
295 static HRESULT (WINAPI
*pVarI1FromUI8
)(ULONG64
,signed char*);
296 static HRESULT (WINAPI
*pVarUI1FromI2
)(SHORT
,BYTE
*);
297 static HRESULT (WINAPI
*pVarUI1FromI4
)(LONG
,BYTE
*);
298 static HRESULT (WINAPI
*pVarUI1FromR4
)(FLOAT
,BYTE
*);
299 static HRESULT (WINAPI
*pVarUI1FromR8
)(double,BYTE
*);
300 static HRESULT (WINAPI
*pVarUI1FromCy
)(CY
,BYTE
*);
301 static HRESULT (WINAPI
*pVarUI1FromDate
)(DATE
,BYTE
*);
302 static HRESULT (WINAPI
*pVarUI1FromStr
)(OLECHAR
*,LCID
,ULONG
,BYTE
*);
303 static HRESULT (WINAPI
*pVarUI1FromBool
)(VARIANT_BOOL
,BYTE
*);
304 static HRESULT (WINAPI
*pVarUI1FromI1
)(signed char,BYTE
*);
305 static HRESULT (WINAPI
*pVarUI1FromUI2
)(USHORT
,BYTE
*);
306 static HRESULT (WINAPI
*pVarUI1FromUI4
)(ULONG
,BYTE
*);
307 static HRESULT (WINAPI
*pVarUI1FromDec
)(DECIMAL
*,BYTE
*);
308 static HRESULT (WINAPI
*pVarUI1FromI8
)(LONG64
,BYTE
*);
309 static HRESULT (WINAPI
*pVarUI1FromUI8
)(ULONG64
,BYTE
*);
310 static HRESULT (WINAPI
*pVarUI1FromDisp
)(IDispatch
*,LCID
,BYTE
*);
312 static HRESULT (WINAPI
*pVarI2FromUI1
)(BYTE
,SHORT
*);
313 static HRESULT (WINAPI
*pVarI2FromI4
)(LONG
,SHORT
*);
314 static HRESULT (WINAPI
*pVarI2FromR4
)(FLOAT
,SHORT
*);
315 static HRESULT (WINAPI
*pVarI2FromR8
)(double,SHORT
*);
316 static HRESULT (WINAPI
*pVarI2FromCy
)(CY
,SHORT
*);
317 static HRESULT (WINAPI
*pVarI2FromDate
)(DATE
,SHORT
*);
318 static HRESULT (WINAPI
*pVarI2FromStr
)(OLECHAR
*,LCID
,ULONG
,SHORT
*);
319 static HRESULT (WINAPI
*pVarI2FromBool
)(VARIANT_BOOL
,SHORT
*);
320 static HRESULT (WINAPI
*pVarI2FromI1
)(signed char,SHORT
*);
321 static HRESULT (WINAPI
*pVarI2FromUI2
)(USHORT
,SHORT
*);
322 static HRESULT (WINAPI
*pVarI2FromUI4
)(ULONG
,SHORT
*);
323 static HRESULT (WINAPI
*pVarI2FromDec
)(DECIMAL
*,SHORT
*);
324 static HRESULT (WINAPI
*pVarI2FromI8
)(LONG64
,SHORT
*);
325 static HRESULT (WINAPI
*pVarI2FromUI8
)(ULONG64
,SHORT
*);
326 static HRESULT (WINAPI
*pVarUI2FromUI1
)(BYTE
,USHORT
*);
327 static HRESULT (WINAPI
*pVarUI2FromI2
)(SHORT
,USHORT
*);
328 static HRESULT (WINAPI
*pVarUI2FromI4
)(LONG
,USHORT
*);
329 static HRESULT (WINAPI
*pVarUI2FromR4
)(FLOAT
,USHORT
*);
330 static HRESULT (WINAPI
*pVarUI2FromR8
)(double,USHORT
*);
331 static HRESULT (WINAPI
*pVarUI2FromDate
)(DATE
,USHORT
*);
332 static HRESULT (WINAPI
*pVarUI2FromCy
)(CY
,USHORT
*);
333 static HRESULT (WINAPI
*pVarUI2FromStr
)(OLECHAR
*,LCID
,ULONG
,USHORT
*);
334 static HRESULT (WINAPI
*pVarUI2FromBool
)(VARIANT_BOOL
,USHORT
*);
335 static HRESULT (WINAPI
*pVarUI2FromI1
)(signed char,USHORT
*);
336 static HRESULT (WINAPI
*pVarUI2FromUI4
)(ULONG
,USHORT
*);
337 static HRESULT (WINAPI
*pVarUI2FromDec
)(DECIMAL
*,USHORT
*);
338 static HRESULT (WINAPI
*pVarUI2FromI8
)(LONG64
,USHORT
*);
339 static HRESULT (WINAPI
*pVarUI2FromUI8
)(ULONG64
,USHORT
*);
341 static HRESULT (WINAPI
*pVarI4FromUI1
)(BYTE
,LONG
*);
342 static HRESULT (WINAPI
*pVarI4FromI2
)(SHORT
,LONG
*);
343 static HRESULT (WINAPI
*pVarI4FromR4
)(FLOAT
,LONG
*);
344 static HRESULT (WINAPI
*pVarI4FromR8
)(DOUBLE
,LONG
*);
345 static HRESULT (WINAPI
*pVarI4FromCy
)(CY
,LONG
*);
346 static HRESULT (WINAPI
*pVarI4FromDate
)(DATE
,LONG
*);
347 static HRESULT (WINAPI
*pVarI4FromStr
)(OLECHAR
*,LCID
,ULONG
,LONG
*);
348 static HRESULT (WINAPI
*pVarI4FromBool
)(VARIANT_BOOL
,LONG
*);
349 static HRESULT (WINAPI
*pVarI4FromI1
)(signed char,LONG
*);
350 static HRESULT (WINAPI
*pVarI4FromUI2
)(USHORT
,LONG
*);
351 static HRESULT (WINAPI
*pVarI4FromUI4
)(ULONG
,LONG
*);
352 static HRESULT (WINAPI
*pVarI4FromDec
)(DECIMAL
*,LONG
*);
353 static HRESULT (WINAPI
*pVarI4FromI8
)(LONG64
,LONG
*);
354 static HRESULT (WINAPI
*pVarI4FromUI8
)(ULONG64
,LONG
*);
355 static HRESULT (WINAPI
*pVarUI4FromUI1
)(BYTE
,ULONG
*);
356 static HRESULT (WINAPI
*pVarUI4FromI2
)(SHORT
,ULONG
*);
357 static HRESULT (WINAPI
*pVarUI4FromI4
)(LONG
,ULONG
*);
358 static HRESULT (WINAPI
*pVarUI4FromR4
)(FLOAT
,ULONG
*);
359 static HRESULT (WINAPI
*pVarUI4FromR8
)(DOUBLE
,ULONG
*);
360 static HRESULT (WINAPI
*pVarUI4FromDate
)(DATE
,ULONG
*);
361 static HRESULT (WINAPI
*pVarUI4FromCy
)(CY
,ULONG
*);
362 static HRESULT (WINAPI
*pVarUI4FromStr
)(OLECHAR
*,LCID
,ULONG
,ULONG
*);
363 static HRESULT (WINAPI
*pVarUI4FromBool
)(VARIANT_BOOL
,ULONG
*);
364 static HRESULT (WINAPI
*pVarUI4FromI1
)(signed char,ULONG
*);
365 static HRESULT (WINAPI
*pVarUI4FromUI2
)(USHORT
,ULONG
*);
366 static HRESULT (WINAPI
*pVarUI4FromDec
)(DECIMAL
*,ULONG
*);
367 static HRESULT (WINAPI
*pVarUI4FromI8
)(LONG64
,ULONG
*);
368 static HRESULT (WINAPI
*pVarUI4FromUI8
)(ULONG64
,ULONG
*);
370 static HRESULT (WINAPI
*pVarI8FromUI1
)(BYTE
,LONG64
*);
371 static HRESULT (WINAPI
*pVarI8FromI2
)(SHORT
,LONG64
*);
372 static HRESULT (WINAPI
*pVarI8FromR4
)(FLOAT
,LONG64
*);
373 static HRESULT (WINAPI
*pVarI8FromR8
)(double,LONG64
*);
374 static HRESULT (WINAPI
*pVarI8FromCy
)(CY
,LONG64
*);
375 static HRESULT (WINAPI
*pVarI8FromDate
)(DATE
,LONG64
*);
376 static HRESULT (WINAPI
*pVarI8FromStr
)(OLECHAR
*,LCID
,ULONG
,LONG64
*);
377 static HRESULT (WINAPI
*pVarI8FromBool
)(VARIANT_BOOL
,LONG64
*);
378 static HRESULT (WINAPI
*pVarI8FromI1
)(signed char,LONG64
*);
379 static HRESULT (WINAPI
*pVarI8FromUI2
)(USHORT
,LONG64
*);
380 static HRESULT (WINAPI
*pVarI8FromUI4
)(ULONG
,LONG64
*);
381 static HRESULT (WINAPI
*pVarI8FromDec
)(DECIMAL
*,LONG64
*);
382 static HRESULT (WINAPI
*pVarI8FromUI8
)(ULONG64
,LONG64
*);
383 static HRESULT (WINAPI
*pVarUI8FromI8
)(LONG64
,ULONG64
*);
384 static HRESULT (WINAPI
*pVarUI8FromUI1
)(BYTE
,ULONG64
*);
385 static HRESULT (WINAPI
*pVarUI8FromI2
)(SHORT
,ULONG64
*);
386 static HRESULT (WINAPI
*pVarUI8FromR4
)(FLOAT
,ULONG64
*);
387 static HRESULT (WINAPI
*pVarUI8FromR8
)(double,ULONG64
*);
388 static HRESULT (WINAPI
*pVarUI8FromCy
)(CY
,ULONG64
*);
389 static HRESULT (WINAPI
*pVarUI8FromDate
)(DATE
,ULONG64
*);
390 static HRESULT (WINAPI
*pVarUI8FromStr
)(OLECHAR
*,LCID
,ULONG
,ULONG64
*);
391 static HRESULT (WINAPI
*pVarUI8FromBool
)(VARIANT_BOOL
,ULONG64
*);
392 static HRESULT (WINAPI
*pVarUI8FromI1
)(signed char,ULONG64
*);
393 static HRESULT (WINAPI
*pVarUI8FromUI2
)(USHORT
,ULONG64
*);
394 static HRESULT (WINAPI
*pVarUI8FromUI4
)(ULONG
,ULONG64
*);
395 static HRESULT (WINAPI
*pVarUI8FromDec
)(DECIMAL
*,ULONG64
*);
397 static HRESULT (WINAPI
*pVarR4FromUI1
)(BYTE
,float*);
398 static HRESULT (WINAPI
*pVarR4FromI2
)(SHORT
,float*);
399 static HRESULT (WINAPI
*pVarR4FromI4
)(LONG
,float*);
400 static HRESULT (WINAPI
*pVarR4FromR8
)(double,float*);
401 static HRESULT (WINAPI
*pVarR4FromCy
)(CY
,float*);
402 static HRESULT (WINAPI
*pVarR4FromDate
)(DATE
,float*);
403 static HRESULT (WINAPI
*pVarR4FromStr
)(OLECHAR
*,LCID
,ULONG
,float*);
404 static HRESULT (WINAPI
*pVarR4FromBool
)(VARIANT_BOOL
,float*);
405 static HRESULT (WINAPI
*pVarR4FromI1
)(signed char,float*);
406 static HRESULT (WINAPI
*pVarR4FromUI2
)(USHORT
,float*);
407 static HRESULT (WINAPI
*pVarR4FromUI4
)(ULONG
,float*);
408 static HRESULT (WINAPI
*pVarR4FromDec
)(DECIMAL
*,float*);
409 static HRESULT (WINAPI
*pVarR4FromI8
)(LONG64
,float*);
410 static HRESULT (WINAPI
*pVarR4FromUI8
)(ULONG64
,float*);
412 static HRESULT (WINAPI
*pVarR8FromUI1
)(BYTE
,double*);
413 static HRESULT (WINAPI
*pVarR8FromI2
)(SHORT
,double*);
414 static HRESULT (WINAPI
*pVarR8FromI4
)(LONG
,double*);
415 static HRESULT (WINAPI
*pVarR8FromR4
)(FLOAT
,double*);
416 static HRESULT (WINAPI
*pVarR8FromCy
)(CY
,double*);
417 static HRESULT (WINAPI
*pVarR8FromDate
)(DATE
,double*);
418 static HRESULT (WINAPI
*pVarR8FromStr
)(OLECHAR
*,LCID
,ULONG
,double*);
419 static HRESULT (WINAPI
*pVarR8FromBool
)(VARIANT_BOOL
,double*);
420 static HRESULT (WINAPI
*pVarR8FromI1
)(signed char,double*);
421 static HRESULT (WINAPI
*pVarR8FromUI2
)(USHORT
,double*);
422 static HRESULT (WINAPI
*pVarR8FromUI4
)(ULONG
,double*);
423 static HRESULT (WINAPI
*pVarR8FromDec
)(DECIMAL
*,double*);
424 static HRESULT (WINAPI
*pVarR8FromI8
)(LONG64
,double*);
425 static HRESULT (WINAPI
*pVarR8FromUI8
)(ULONG64
,double*);
426 static HRESULT (WINAPI
*pVarR8Round
)(double,int,double*);
428 static HRESULT (WINAPI
*pVarDateFromUI1
)(BYTE
,DATE
*);
429 static HRESULT (WINAPI
*pVarDateFromI2
)(SHORT
,DATE
*);
430 static HRESULT (WINAPI
*pVarDateFromI4
)(LONG
,DATE
*);
431 static HRESULT (WINAPI
*pVarDateFromR4
)(FLOAT
,DATE
*);
432 static HRESULT (WINAPI
*pVarDateFromCy
)(CY
,DATE
*);
433 static HRESULT (WINAPI
*pVarDateFromR8
)(double,DATE
*);
434 static HRESULT (WINAPI
*pVarDateFromStr
)(OLECHAR
*,LCID
,ULONG
,DATE
*);
435 static HRESULT (WINAPI
*pVarDateFromBool
)(VARIANT_BOOL
,DATE
*);
436 static HRESULT (WINAPI
*pVarDateFromI1
)(signed char,DATE
*);
437 static HRESULT (WINAPI
*pVarDateFromUI2
)(USHORT
,DATE
*);
438 static HRESULT (WINAPI
*pVarDateFromUI4
)(ULONG
,DATE
*);
439 static HRESULT (WINAPI
*pVarDateFromDec
)(DECIMAL
*,DATE
*);
440 static HRESULT (WINAPI
*pVarDateFromI8
)(LONG64
,DATE
*);
441 static HRESULT (WINAPI
*pVarDateFromUI8
)(ULONG64
,DATE
*);
443 static HRESULT (WINAPI
*pVarCyFromUI1
)(BYTE
,CY
*);
444 static HRESULT (WINAPI
*pVarCyFromI2
)(SHORT
,CY
*);
445 static HRESULT (WINAPI
*pVarCyFromI4
)(LONG
,CY
*);
446 static HRESULT (WINAPI
*pVarCyFromR4
)(FLOAT
,CY
*);
447 static HRESULT (WINAPI
*pVarCyFromR8
)(double,CY
*);
448 static HRESULT (WINAPI
*pVarCyFromDate
)(DATE
,CY
*);
449 static HRESULT (WINAPI
*pVarCyFromBool
)(VARIANT_BOOL
,CY
*);
450 static HRESULT (WINAPI
*pVarCyFromI1
)(signed char,CY
*);
451 static HRESULT (WINAPI
*pVarCyFromUI2
)(USHORT
,CY
*);
452 static HRESULT (WINAPI
*pVarCyFromUI4
)(ULONG
,CY
*);
453 static HRESULT (WINAPI
*pVarCyFromDec
)(DECIMAL
*,CY
*);
454 static HRESULT (WINAPI
*pVarCyFromI8
)(LONG64
,CY
*);
455 static HRESULT (WINAPI
*pVarCyFromUI8
)(ULONG64
,CY
*);
456 static HRESULT (WINAPI
*pVarCyAdd
)(const CY
,const CY
,CY
*);
457 static HRESULT (WINAPI
*pVarCyMul
)(const CY
,const CY
,CY
*);
458 static HRESULT (WINAPI
*pVarCyMulI4
)(const CY
,LONG
,CY
*);
459 static HRESULT (WINAPI
*pVarCySub
)(const CY
,const CY
,CY
*);
460 static HRESULT (WINAPI
*pVarCyAbs
)(const CY
,CY
*);
461 static HRESULT (WINAPI
*pVarCyFix
)(const CY
,CY
*);
462 static HRESULT (WINAPI
*pVarCyInt
)(const CY
,CY
*);
463 static HRESULT (WINAPI
*pVarCyNeg
)(const CY
,CY
*);
464 static HRESULT (WINAPI
*pVarCyRound
)(const CY
,int,CY
*);
465 static HRESULT (WINAPI
*pVarCyCmp
)(const CY
,const CY
);
466 static HRESULT (WINAPI
*pVarCyCmpR8
)(const CY
,double);
467 static HRESULT (WINAPI
*pVarCyMulI8
)(const CY
,LONG64
,CY
*);
469 static HRESULT (WINAPI
*pVarDecFromUI1
)(BYTE
,DECIMAL
*);
470 static HRESULT (WINAPI
*pVarDecFromI2
)(SHORT
,DECIMAL
*);
471 static HRESULT (WINAPI
*pVarDecFromI4
)(LONG
,DECIMAL
*);
472 static HRESULT (WINAPI
*pVarDecFromI8
)(LONG64
,DECIMAL
*);
473 static HRESULT (WINAPI
*pVarDecFromR4
)(FLOAT
,DECIMAL
*);
474 static HRESULT (WINAPI
*pVarDecFromR8
)(DOUBLE
,DECIMAL
*);
475 static HRESULT (WINAPI
*pVarDecFromDate
)(DATE
,DECIMAL
*);
476 static HRESULT (WINAPI
*pVarDecFromStr
)(OLECHAR
*,LCID
,ULONG
,DECIMAL
*);
477 static HRESULT (WINAPI
*pVarDecFromBool
)(VARIANT_BOOL
,DECIMAL
*);
478 static HRESULT (WINAPI
*pVarDecFromI1
)(signed char,DECIMAL
*);
479 static HRESULT (WINAPI
*pVarDecFromUI2
)(USHORT
,DECIMAL
*);
480 static HRESULT (WINAPI
*pVarDecFromUI4
)(ULONG
,DECIMAL
*);
481 static HRESULT (WINAPI
*pVarDecFromUI8
)(ULONG64
,DECIMAL
*);
482 static HRESULT (WINAPI
*pVarDecFromCy
)(CY
,DECIMAL
*);
483 static HRESULT (WINAPI
*pVarDecAbs
)(const DECIMAL
*,DECIMAL
*);
484 static HRESULT (WINAPI
*pVarDecAdd
)(const DECIMAL
*,const DECIMAL
*,DECIMAL
*);
485 static HRESULT (WINAPI
*pVarDecSub
)(const DECIMAL
*,const DECIMAL
*,DECIMAL
*);
486 static HRESULT (WINAPI
*pVarDecCmp
)(const DECIMAL
*,const DECIMAL
*);
487 static HRESULT (WINAPI
*pVarDecNeg
)(const DECIMAL
*,DECIMAL
*);
489 static HRESULT (WINAPI
*pVarBoolFromUI1
)(BYTE
,VARIANT_BOOL
*);
490 static HRESULT (WINAPI
*pVarBoolFromI2
)(SHORT
,VARIANT_BOOL
*);
491 static HRESULT (WINAPI
*pVarBoolFromI4
)(LONG
,VARIANT_BOOL
*);
492 static HRESULT (WINAPI
*pVarBoolFromR4
)(FLOAT
,VARIANT_BOOL
*);
493 static HRESULT (WINAPI
*pVarBoolFromR8
)(DOUBLE
,VARIANT_BOOL
*);
494 static HRESULT (WINAPI
*pVarBoolFromDate
)(DATE
,VARIANT_BOOL
*);
495 static HRESULT (WINAPI
*pVarBoolFromCy
)(CY
,VARIANT_BOOL
*);
496 static HRESULT (WINAPI
*pVarBoolFromStr
)(OLECHAR
*,LCID
,ULONG
,VARIANT_BOOL
*);
497 static HRESULT (WINAPI
*pVarBoolFromI1
)(signed char,VARIANT_BOOL
*);
498 static HRESULT (WINAPI
*pVarBoolFromUI2
)(USHORT
,VARIANT_BOOL
*);
499 static HRESULT (WINAPI
*pVarBoolFromUI4
)(ULONG
,VARIANT_BOOL
*);
500 static HRESULT (WINAPI
*pVarBoolFromDec
)(DECIMAL
*,VARIANT_BOOL
*);
501 static HRESULT (WINAPI
*pVarBoolFromI8
)(LONG64
,VARIANT_BOOL
*);
502 static HRESULT (WINAPI
*pVarBoolFromUI8
)(ULONG64
,VARIANT_BOOL
*);
504 static HRESULT (WINAPI
*pVarBstrFromR4
)(FLOAT
,LCID
,ULONG
,BSTR
*);
505 static HRESULT (WINAPI
*pVarBstrFromDate
)(DATE
,LCID
,ULONG
,BSTR
*);
507 static INT (WINAPI
*pSystemTimeToVariantTime
)(LPSYSTEMTIME
,double*);
508 static void (WINAPI
*pClearCustData
)(LPCUSTDATA
);
510 /* Internal representation of a BSTR */
511 typedef struct tagINTERNAL_BSTR
515 } INTERNAL_BSTR
, *LPINTERNAL_BSTR
;
519 IDispatchVtbl
*lpVtbl
;
525 static DummyDispatch dispatch
;
527 static ULONG WINAPI
DummyDispatch_AddRef(LPDISPATCH iface
)
529 trace("AddRef(%p)\n", iface
);
530 return ++((DummyDispatch
*)iface
)->ref
;
533 static ULONG WINAPI
DummyDispatch_Release(LPDISPATCH iface
)
535 trace("Release(%p)\n", iface
);
536 return ((DummyDispatch
*)iface
)->ref
--;
539 static HRESULT WINAPI
DummyDispatch_QueryInterface(LPDISPATCH iface
,
543 trace("QueryInterface(%p)\n", iface
);
547 if (IsEqualIID(riid
, &IID_IDispatch
))
549 trace("Asked for IID_IDispatch\n");
552 else if (IsEqualIID(riid
, &IID_IUnknown
))
554 trace("Asked for IID_IUnknown\n");
559 DummyDispatch_AddRef((IDispatch
*)*ppvObject
);
563 return E_NOINTERFACE
;
566 static HRESULT WINAPI
DummyDispatch_Invoke(LPDISPATCH iface
,
567 DISPID dispIdMember
, REFIID riid
,
568 LCID lcid
, WORD wFlags
,
569 DISPPARAMS
*pDispParams
,
571 EXCEPINFO
*pExcepInfo
,
574 trace("Invoke(%p)\n", iface
);
575 ok(wFlags
== DISPATCH_PROPERTYGET
, "Flags wrong\n");
576 ok(pDispParams
->cArgs
== 0, "Property get has args\n");
578 if (dispatch
.bFailInvoke
)
579 return E_OUTOFMEMORY
;
581 memset(pVarResult
, 0, sizeof(*pVarResult
));
582 V_VT(pVarResult
) = dispatch
.vt
;
586 static IDispatchVtbl DummyDispatch_VTable
=
588 DummyDispatch_QueryInterface
,
589 DummyDispatch_AddRef
,
590 DummyDispatch_Release
,
597 static DummyDispatch dispatch
= { &DummyDispatch_VTable
, 1, 0, 0 };
604 #define CONV_TYPE signed char
606 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%d")
608 static void test_VarI1FromI2(void)
613 CHECKPTR(VarI1FromI2
);
614 OVERFLOWRANGE(VarI1FromI2
, -32768, -128);
615 CONVERTRANGE(VarI1FromI2
, -128, 128);
616 OVERFLOWRANGE(VarI1FromI2
, 129, 32768);
619 static void test_VarI1FromI4(void)
624 CHECKPTR(VarI1FromI4
);
625 CONVERT(VarI1FromI4
, -129); EXPECT_OVERFLOW
;
626 CONVERTRANGE(VarI1FromI4
, -128, 128);
627 CONVERT(VarI1FromI4
, 128); EXPECT_OVERFLOW
;
630 static void test_VarI1FromI8(void)
635 CHECKPTR(VarI1FromI8
);
636 CONVERT(VarI1FromI8
, -129); EXPECT_OVERFLOW
;
637 CONVERTRANGE(VarI1FromI8
, -127, 128);
638 CONVERT(VarI1FromI8
, 128); EXPECT_OVERFLOW
;
641 static void test_VarI1FromUI1(void)
646 CHECKPTR(VarI1FromUI1
);
647 CONVERTRANGE(VarI1FromUI1
, 0, 127);
648 OVERFLOWRANGE(VarI1FromUI1
, 128, 255);
651 static void test_VarI1FromUI2(void)
656 CHECKPTR(VarI1FromUI2
);
657 CONVERTRANGE(VarI1FromUI2
, 0, 127);
658 OVERFLOWRANGE(VarI1FromUI2
, 128, 32768);
661 static void test_VarI1FromUI4(void)
666 CHECKPTR(VarI1FromUI4
);
667 CONVERTRANGE(VarI1FromUI4
, 0, 127);
668 CONVERT(VarI1FromUI4
, 128); EXPECT_OVERFLOW
;
671 static void test_VarI1FromUI8(void)
676 CHECKPTR(VarI1FromUI8
);
677 CONVERTRANGE(VarI1FromUI8
, 0, 127);
678 CONVERT(VarI1FromUI8
, 128); EXPECT_OVERFLOW
;
681 static void test_VarI1FromBool(void)
683 CONVVARS(VARIANT_BOOL
);
686 CHECKPTR(VarI1FromBool
);
687 /* Note that conversions from bool wrap around! */
688 CONVERT(VarI1FromBool
, -129); EXPECT(127);
689 CONVERTRANGE(VarI1FromBool
, -128, 128);
690 CONVERT(VarI1FromBool
, 128); EXPECT(-128);
693 static void test_VarI1FromR4(void)
697 CHECKPTR(VarI1FromR4
);
698 CONVERT(VarI1FromR4
, -129.0f
); EXPECT_OVERFLOW
;
699 CONVERT(VarI1FromR4
, -128.0f
); EXPECT(-128);
700 CONVERT(VarI1FromR4
, -1.0f
); EXPECT(-1);
701 CONVERT(VarI1FromR4
, 0.0f
); EXPECT(0);
702 CONVERT(VarI1FromR4
, 1.0f
); EXPECT(1);
703 CONVERT(VarI1FromR4
, 127.0f
); EXPECT(127);
704 CONVERT(VarI1FromR4
, 128.0f
); EXPECT_OVERFLOW
;
706 CONVERT(VarI1FromR4
, -1.5f
); EXPECT(-2);
707 CONVERT(VarI1FromR4
, -0.6f
); EXPECT(-1);
708 CONVERT(VarI1FromR4
, -0.5f
); EXPECT(0);
709 CONVERT(VarI1FromR4
, -0.4f
); EXPECT(0);
710 CONVERT(VarI1FromR4
, 0.4f
); EXPECT(0);
711 CONVERT(VarI1FromR4
, 0.5f
); EXPECT(0);
712 CONVERT(VarI1FromR4
, 0.6f
); EXPECT(1);
713 CONVERT(VarI1FromR4
, 1.5f
); EXPECT(2);
716 static void test_VarI1FromR8(void)
720 CHECKPTR(VarI1FromR8
);
721 CONVERT(VarI1FromR8
, -129.0); EXPECT_OVERFLOW
;
722 CONVERT(VarI1FromR8
, -128.0); EXPECT(-128);
723 CONVERT(VarI1FromR8
, -1.0); EXPECT(-1);
724 CONVERT(VarI1FromR8
, 0.0); EXPECT(0);
725 CONVERT(VarI1FromR8
, 1.0); EXPECT(1);
726 CONVERT(VarI1FromR8
, 127.0); EXPECT(127);
727 CONVERT(VarI1FromR8
, 128.0); EXPECT_OVERFLOW
;
729 CONVERT(VarI1FromR8
, -1.5); EXPECT(-2);
730 CONVERT(VarI1FromR8
, -0.6); EXPECT(-1);
731 CONVERT(VarI1FromR8
, -0.5); EXPECT(0);
732 CONVERT(VarI1FromR8
, -0.4); EXPECT(0);
733 CONVERT(VarI1FromR8
, 0.4); EXPECT(0);
734 CONVERT(VarI1FromR8
, 0.5); EXPECT(0);
735 CONVERT(VarI1FromR8
, 0.6); EXPECT(1);
736 CONVERT(VarI1FromR8
, 1.5); EXPECT(2);
739 static void test_VarI1FromDate(void)
743 CHECKPTR(VarI1FromDate
);
744 CONVERT(VarI1FromDate
, -129.0); EXPECT_OVERFLOW
;
745 CONVERT(VarI1FromDate
, -128.0); EXPECT(-128);
746 CONVERT(VarI1FromDate
, -1.0); EXPECT(-1);
747 CONVERT(VarI1FromDate
, 0.0); EXPECT(0);
748 CONVERT(VarI1FromDate
, 1.0); EXPECT(1);
749 CONVERT(VarI1FromDate
, 127.0); EXPECT(127);
750 CONVERT(VarI1FromDate
, 128.0); EXPECT_OVERFLOW
;
752 CONVERT(VarI1FromDate
, -1.5); EXPECT(-2);
753 CONVERT(VarI1FromDate
, -0.6); EXPECT(-1);
754 CONVERT(VarI1FromDate
, -0.5); EXPECT(0);
755 CONVERT(VarI1FromDate
, -0.4); EXPECT(0);
756 CONVERT(VarI1FromDate
, 0.4); EXPECT(0);
757 CONVERT(VarI1FromDate
, 0.5); EXPECT(0);
758 CONVERT(VarI1FromDate
, 0.6); EXPECT(1);
759 CONVERT(VarI1FromDate
, 1.5); EXPECT(2);
762 static void test_VarI1FromCy(void)
766 CHECKPTR(VarI1FromCy
);
767 CONVERT_CY(VarI1FromCy
,-129); EXPECT_OVERFLOW
;
768 CONVERT_CY(VarI1FromCy
,-128); EXPECT(128);
769 CONVERT_CY(VarI1FromCy
,-1); EXPECT(-1);
770 CONVERT_CY(VarI1FromCy
,0); EXPECT(0);
771 CONVERT_CY(VarI1FromCy
,1); EXPECT(1);
772 CONVERT_CY(VarI1FromCy
,127); EXPECT(127);
773 CONVERT_CY(VarI1FromCy
,128); EXPECT_OVERFLOW
;
775 CONVERT_CY(VarI1FromCy
,-1.5); EXPECT(-2);
776 CONVERT_CY(VarI1FromCy
,-0.6); EXPECT(-1);
777 CONVERT_CY(VarI1FromCy
,-0.5); EXPECT(0);
778 CONVERT_CY(VarI1FromCy
,-0.4); EXPECT(0);
779 CONVERT_CY(VarI1FromCy
,0.4); EXPECT(0);
780 CONVERT_CY(VarI1FromCy
,0.5); EXPECT(0);
781 CONVERT_CY(VarI1FromCy
,0.6); EXPECT(1);
782 CONVERT_CY(VarI1FromCy
,1.5); EXPECT(2);
785 static void test_VarI1FromDec(void)
789 CHECKPTR(VarI1FromDec
);
791 CONVERT_BADDEC(VarI1FromDec
);
793 CONVERT_DEC(VarI1FromDec
,0,0x80,0,129); EXPECT_OVERFLOW
;
794 CONVERT_DEC(VarI1FromDec
,0,0x80,0,128); EXPECT(-128);
795 CONVERT_DEC(VarI1FromDec
,0,0x80,0,1); EXPECT(-1);
796 CONVERT_DEC(VarI1FromDec
,0,0,0,0); EXPECT(0);
797 CONVERT_DEC(VarI1FromDec
,0,0,0,1); EXPECT(1);
798 CONVERT_DEC(VarI1FromDec
,0,0,0,127); EXPECT(127);
799 CONVERT_DEC(VarI1FromDec
,0,0,0,128); EXPECT_OVERFLOW
;
801 CONVERT_DEC(VarI1FromDec
,2,0x80,0,12800); EXPECT(-128);
802 CONVERT_DEC(VarI1FromDec
,2,0,0,12700); EXPECT(127);
805 static void test_VarI1FromStr(void)
810 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
812 CHECKPTR(VarI1FromStr
);
814 CONVERT_STR(VarI1FromStr
,NULL
, 0); EXPECT_MISMATCH
;
815 CONVERT_STR(VarI1FromStr
,"0", 0); EXPECT(0);
816 CONVERT_STR(VarI1FromStr
,"-129", 0); EXPECT_OVERFLOW
;
817 CONVERT_STR(VarI1FromStr
,"-128", 0); EXPECT(-128);
818 CONVERT_STR(VarI1FromStr
,"127", 0); EXPECT(127);
819 CONVERT_STR(VarI1FromStr
,"128", 0); EXPECT_OVERFLOW
;
821 CONVERT_STR(VarI1FromStr
,"-1.5", 0); EXPECT(-2);
822 CONVERT_STR(VarI1FromStr
,"-0.6", 0); EXPECT(-1);
823 CONVERT_STR(VarI1FromStr
,"-0.5", 0); EXPECT(0);
824 CONVERT_STR(VarI1FromStr
,"-0.4", 0); EXPECT(0);
825 CONVERT_STR(VarI1FromStr
,"0.4", 0); EXPECT(0);
826 CONVERT_STR(VarI1FromStr
,"0.5", 0); EXPECT(0);
827 CONVERT_STR(VarI1FromStr
,"0.6", 0); EXPECT(1);
828 CONVERT_STR(VarI1FromStr
,"1.5", 0); EXPECT(2);
831 static void test_VarI1Copy(void)
835 COPYTEST(1, VT_I1
, V_I1(&vSrc
), V_I1(&vDst
), V_I1REF(&vSrc
), V_I1REF(&vDst
), "%d");
839 static void test_VarI1ChangeTypeEx(void)
842 VARIANTARG vSrc
, vDst
;
848 INITIAL_TYPETEST(VT_I1
, V_I1
, "%d");
854 #define CONV_TYPE BYTE
856 static void test_VarUI1FromI1(void)
858 CONVVARS(signed char);
861 CHECKPTR(VarUI1FromI1
);
862 OVERFLOWRANGE(VarUI1FromI1
, -128, 0);
863 CONVERTRANGE(VarUI1FromI1
, 0, 128);
866 static void test_VarUI1FromI2(void)
871 CHECKPTR(VarUI1FromI2
);
872 OVERFLOWRANGE(VarUI1FromI2
, -32768, 0);
873 CONVERTRANGE(VarUI1FromI2
, 0, 256);
874 OVERFLOWRANGE(VarUI1FromI2
, 256, 32768);
877 static void test_VarUI1FromI4(void)
882 CHECKPTR(VarUI1FromI4
);
883 CONVERT(VarUI1FromI4
, -1); EXPECT_OVERFLOW
;
884 CONVERTRANGE(VarUI1FromI4
, 0, 256);
885 CONVERT(VarUI1FromI4
, 256); EXPECT_OVERFLOW
;
888 static void test_VarUI1FromI8(void)
893 CHECKPTR(VarUI1FromI8
);
894 CONVERT(VarUI1FromI8
, -1); EXPECT_OVERFLOW
;
895 CONVERTRANGE(VarUI1FromI8
, 0, 256);
896 CONVERT(VarUI1FromI8
, 256); EXPECT_OVERFLOW
;
899 static void test_VarUI1FromUI2(void)
904 CHECKPTR(VarUI1FromUI2
);
905 CONVERTRANGE(VarUI1FromUI2
, 0, 256);
906 OVERFLOWRANGE(VarUI1FromUI2
, 256, 65536);
909 static void test_VarUI1FromUI4(void)
914 CHECKPTR(VarUI1FromUI4
);
915 CONVERTRANGE(VarUI1FromUI4
, 0, 256);
916 CONVERT(VarUI1FromUI4
, 256); EXPECT_OVERFLOW
;
919 static void test_VarUI1FromUI8(void)
924 CHECKPTR(VarUI1FromUI8
);
925 CONVERTRANGE(VarUI1FromUI8
, 0, 256);
926 CONVERT(VarUI1FromUI8
, 256); EXPECT_OVERFLOW
;
929 static void test_VarUI1FromBool(void)
931 CONVVARS(VARIANT_BOOL
);
934 CHECKPTR(VarUI1FromBool
);
935 /* Note that conversions from bool overflow! */
936 CONVERT(VarUI1FromBool
, -1); EXPECT(255);
937 CONVERTRANGE(VarUI1FromBool
, 0, 256);
938 CONVERT(VarUI1FromBool
, 256); EXPECT(0);
941 static void test_VarUI1FromR4(void)
945 CHECKPTR(VarUI1FromR4
);
946 CONVERT(VarUI1FromR4
, -1.0f
); EXPECT_OVERFLOW
;
947 CONVERT(VarUI1FromR4
, 0.0f
); EXPECT(0);
948 CONVERT(VarUI1FromR4
, 1.0f
); EXPECT(1);
949 CONVERT(VarUI1FromR4
, 255.0f
); EXPECT(255);
950 CONVERT(VarUI1FromR4
, 256.0f
); EXPECT_OVERFLOW
;
953 CONVERT(VarUI1FromR4
, -1.5f
); EXPECT_OVERFLOW
;
954 CONVERT(VarUI1FromR4
, -0.6f
); EXPECT_OVERFLOW
;
955 CONVERT(VarUI1FromR4
, -0.5f
); EXPECT(0);
956 CONVERT(VarUI1FromR4
, -0.4f
); EXPECT(0);
957 CONVERT(VarUI1FromR4
, 0.4f
); EXPECT(0);
958 CONVERT(VarUI1FromR4
, 0.5f
); EXPECT(0);
959 CONVERT(VarUI1FromR4
, 0.6f
); EXPECT(1);
960 CONVERT(VarUI1FromR4
, 1.5f
); EXPECT(2);
963 static void test_VarUI1FromR8(void)
967 CHECKPTR(VarUI1FromR8
);
968 CONVERT(VarUI1FromR8
, -1.0); EXPECT_OVERFLOW
;
969 CONVERT(VarUI1FromR8
, 0.0); EXPECT(0);
970 CONVERT(VarUI1FromR8
, 1.0); EXPECT(1);
971 CONVERT(VarUI1FromR8
, 255.0); EXPECT(255);
972 CONVERT(VarUI1FromR8
, 256.0); EXPECT_OVERFLOW
;
975 CONVERT(VarUI1FromR8
, -1.5); EXPECT_OVERFLOW
;
976 CONVERT(VarUI1FromR8
, -0.6); EXPECT_OVERFLOW
;
977 CONVERT(VarUI1FromR8
, -0.5); EXPECT(0);
978 CONVERT(VarUI1FromR8
, -0.4); EXPECT(0);
979 CONVERT(VarUI1FromR8
, 0.4); EXPECT(0);
980 CONVERT(VarUI1FromR8
, 0.5); EXPECT(0);
981 CONVERT(VarUI1FromR8
, 0.6); EXPECT(1);
982 CONVERT(VarUI1FromR8
, 1.5); EXPECT(2);
985 static void test_VarUI1FromDate(void)
989 CHECKPTR(VarUI1FromDate
);
990 CONVERT(VarUI1FromDate
, -1.0); EXPECT_OVERFLOW
;
991 CONVERT(VarUI1FromDate
, 0.0); EXPECT(0);
992 CONVERT(VarUI1FromDate
, 1.0); EXPECT(1);
993 CONVERT(VarUI1FromDate
, 255.0); EXPECT(255);
994 CONVERT(VarUI1FromDate
, 256.0); EXPECT_OVERFLOW
;
997 CONVERT(VarUI1FromDate
, -1.5); EXPECT_OVERFLOW
;
998 CONVERT(VarUI1FromDate
, -0.6); EXPECT_OVERFLOW
;
999 CONVERT(VarUI1FromDate
, -0.5); EXPECT(0);
1000 CONVERT(VarUI1FromDate
, -0.4); EXPECT(0);
1001 CONVERT(VarUI1FromDate
, 0.4); EXPECT(0);
1002 CONVERT(VarUI1FromDate
, 0.5); EXPECT(0);
1003 CONVERT(VarUI1FromDate
, 0.6); EXPECT(1);
1004 CONVERT(VarUI1FromDate
, 1.5); EXPECT(2);
1007 static void test_VarUI1FromCy(void)
1011 CHECKPTR(VarUI1FromCy
);
1012 CONVERT_CY(VarUI1FromCy
,-1); EXPECT_OVERFLOW
;
1013 CONVERT_CY(VarUI1FromCy
,0); EXPECT(0);
1014 CONVERT_CY(VarUI1FromCy
,1); EXPECT(1);
1015 CONVERT_CY(VarUI1FromCy
,255); EXPECT(255);
1016 CONVERT_CY(VarUI1FromCy
,256); EXPECT_OVERFLOW
;
1019 CONVERT_CY(VarUI1FromCy
,-1.5); EXPECT_OVERFLOW
;
1020 CONVERT_CY(VarUI1FromCy
,-0.6); EXPECT_OVERFLOW
;
1021 CONVERT_CY(VarUI1FromCy
,-0.5); EXPECT(0);
1022 CONVERT_CY(VarUI1FromCy
,-0.4); EXPECT(0);
1023 CONVERT_CY(VarUI1FromCy
,0.4); EXPECT(0);
1024 CONVERT_CY(VarUI1FromCy
,0.5); EXPECT(0);
1025 CONVERT_CY(VarUI1FromCy
,0.6); EXPECT(1);
1026 CONVERT_CY(VarUI1FromCy
,1.5); EXPECT(2);
1029 static void test_VarUI1FromDec(void)
1033 CHECKPTR(VarUI1FromDec
);
1035 CONVERT_BADDEC(VarUI1FromDec
);
1037 CONVERT_DEC(VarUI1FromDec
,0,0x80,0,1); EXPECT_OVERFLOW
;
1038 CONVERT_DEC(VarUI1FromDec
,0,0,0,0); EXPECT(0);
1039 CONVERT_DEC(VarUI1FromDec
,0,0,0,1); EXPECT(1);
1040 CONVERT_DEC(VarUI1FromDec
,0,0,0,255); EXPECT(255);
1041 CONVERT_DEC(VarUI1FromDec
,0,0,0,256); EXPECT_OVERFLOW
;
1043 CONVERT_DEC(VarUI1FromDec
,2,0x80,0,100); EXPECT_OVERFLOW
;
1044 CONVERT_DEC(VarUI1FromDec
,2,0,0,25500); EXPECT(255);
1047 static void test_VarUI1FromStr(void)
1052 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
1054 CHECKPTR(VarUI1FromStr
);
1056 CONVERT_STR(VarUI1FromStr
,NULL
, 0); EXPECT_MISMATCH
;
1057 CONVERT_STR(VarUI1FromStr
,"0", 0); EXPECT(0);
1058 CONVERT_STR(VarUI1FromStr
,"-1", 0); EXPECT_OVERFLOW
;
1059 CONVERT_STR(VarUI1FromStr
,"255", 0); EXPECT(255);
1060 CONVERT_STR(VarUI1FromStr
,"256", 0); EXPECT_OVERFLOW
;
1063 CONVERT_STR(VarUI1FromStr
,"-1.5", 0); EXPECT_OVERFLOW
;
1064 CONVERT_STR(VarUI1FromStr
,"-0.6", 0); EXPECT_OVERFLOW
;
1065 CONVERT_STR(VarUI1FromStr
,"-0.5", 0); EXPECT(0);
1066 CONVERT_STR(VarUI1FromStr
,"-0.4", 0); EXPECT(0);
1067 CONVERT_STR(VarUI1FromStr
,"0.4", 0); EXPECT(0);
1068 CONVERT_STR(VarUI1FromStr
,"0.5", 0); EXPECT(0);
1069 CONVERT_STR(VarUI1FromStr
,"0.6", 0); EXPECT(1);
1070 CONVERT_STR(VarUI1FromStr
,"1.5", 0); EXPECT(2);
1073 static void test_VarUI1FromDisp(void)
1076 VARIANTARG vSrc
, vDst
;
1078 CHECKPTR(VarUI1FromDisp
);
1081 * Conversions from IDispatch should get the default 'value' property
1082 * from the IDispatch pointer and return it. The following tests this.
1083 * However, I can't get these tests to return a valid value under native
1084 * oleaut32, regardless of the value returned in response to the Invoke()
1085 * call (early versions of oleaut32 call AddRef/Release, but not Invoke.
1086 * I'm obviously missing something, as these conversions work fine
1087 * when called through VBA on an object to get its default value property.
1089 * Should this test be corrected so that it works under native it should be
1090 * generalised and the remaining types checked as well.
1092 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
1097 V_VT(&vSrc
) = VT_DISPATCH
;
1098 V_DISPATCH(&vSrc
) = (IDispatch
*)&dispatch
;
1099 dispatch
.vt
= VT_UI1
;
1100 dispatch
.bFailInvoke
= FALSE
;
1102 hres
= VarUI1FromDisp((IDispatch
*)&dispatch
, in
, &out
);
1103 trace("0x%08lx\n", hres
);
1105 hres
= VariantChangeTypeEx(&vDst
, &vSrc
, in
, 0, VT_UI1
);
1106 trace("0x%08lx\n", hres
);
1108 dispatch
.bFailInvoke
= TRUE
;
1110 hres
= VarUI1FromDisp((IDispatch
*)&dispatch
, in
, &out
);
1111 trace("0x%08lx\n", hres
);
1113 hres
= VariantChangeTypeEx(&vDst
, &vSrc
, in
, 0, VT_UI1
);
1114 trace("0x%08lx\n", hres
);
1117 static void test_VarUI1Copy(void)
1119 COPYTEST(1, VT_UI1
, V_UI1(&vSrc
), V_UI1(&vDst
), V_UI1REF(&vSrc
), V_UI1REF(&vDst
), "%d");
1122 static void test_VarUI1ChangeTypeEx(void)
1124 CONVVARS(CONV_TYPE
);
1125 VARIANTARG vSrc
, vDst
;
1129 INITIAL_TYPETEST(VT_UI1
, V_UI1
, "%d");
1138 #define CONV_TYPE SHORT
1140 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%d")
1142 static void test_VarI2FromI1(void)
1144 CONVVARS(signed char);
1147 CHECKPTR(VarI2FromI1
);
1148 CONVERTRANGE(VarI2FromI1
, -128, 128);
1151 static void test_VarI2FromI4(void)
1156 CHECKPTR(VarI2FromI4
);
1157 CONVERT(VarI2FromI4
, -32769); EXPECT_OVERFLOW
;
1158 CONVERTRANGE(VarI2FromI4
, -32768, 32768);
1159 CONVERT(VarI2FromI4
, 32768); EXPECT_OVERFLOW
;
1162 static void test_VarI2FromI8(void)
1166 CHECKPTR(VarI2FromI8
);
1167 CONVERT(VarI2FromI8
, -32769); EXPECT_OVERFLOW
;
1168 CONVERT(VarI2FromI8
, -32768); EXPECT(-32768);
1169 CONVERT(VarI2FromI8
, 32767); EXPECT(32767);
1170 CONVERT(VarI2FromI8
, 32768); EXPECT_OVERFLOW
;
1173 static void test_VarI2FromUI1(void)
1178 CHECKPTR(VarI2FromUI1
);
1179 CONVERTRANGE(VarI2FromUI1
, 0, 256);
1182 static void test_VarI2FromUI2(void)
1187 CHECKPTR(VarI2FromUI2
);
1188 CONVERTRANGE(VarI2FromUI2
, 0, 32768);
1189 CONVERT(VarI2FromUI2
, 32768); EXPECT_OVERFLOW
;
1192 static void test_VarI2FromUI4(void)
1197 CHECKPTR(VarI2FromUI4
);
1198 CONVERTRANGE(VarI2FromUI4
, 0, 32768);
1199 CONVERT(VarI2FromUI4
, 32768); EXPECT_OVERFLOW
;
1202 static void test_VarI2FromUI8(void)
1207 CHECKPTR(VarI2FromUI8
);
1208 CONVERTRANGE(VarI2FromUI8
, 0, 32768);
1209 CONVERT(VarI2FromUI8
, 32768); EXPECT_OVERFLOW
;
1212 static void test_VarI2FromBool(void)
1214 CONVVARS(VARIANT_BOOL
);
1217 CHECKPTR(VarI2FromBool
);
1218 CONVERTRANGE(VarI2FromBool
, -32768, 32768);
1221 static void test_VarI2FromR4(void)
1225 CHECKPTR(VarI2FromR4
);
1226 CONVERT(VarI2FromR4
, -32769.0f
); EXPECT_OVERFLOW
;
1227 CONVERT(VarI2FromR4
, -32768.0f
); EXPECT(-32768);
1228 CONVERT(VarI2FromR4
, -1.0f
); EXPECT(-1);
1229 CONVERT(VarI2FromR4
, 0.0f
); EXPECT(0);
1230 CONVERT(VarI2FromR4
, 1.0f
); EXPECT(1);
1231 CONVERT(VarI2FromR4
, 32767.0f
); EXPECT(32767);
1232 CONVERT(VarI2FromR4
, 32768.0f
); EXPECT_OVERFLOW
;
1235 CONVERT(VarI2FromR4
, -1.5f
); EXPECT(-2);
1236 CONVERT(VarI2FromR4
, -0.6f
); EXPECT(-1);
1237 CONVERT(VarI2FromR4
, -0.5f
); EXPECT(0);
1238 CONVERT(VarI2FromR4
, -0.4f
); EXPECT(0);
1239 CONVERT(VarI2FromR4
, 0.4f
); EXPECT(0);
1240 CONVERT(VarI2FromR4
, 0.5f
); EXPECT(0);
1241 CONVERT(VarI2FromR4
, 0.6f
); EXPECT(1);
1242 CONVERT(VarI2FromR4
, 1.5f
); EXPECT(2);
1245 static void test_VarI2FromR8(void)
1249 CHECKPTR(VarI2FromR8
);
1250 CONVERT(VarI2FromR8
, -32769.0); EXPECT_OVERFLOW
;
1251 CONVERT(VarI2FromR8
, -32768.0); EXPECT(-32768);
1252 CONVERT(VarI2FromR8
, -1.0); EXPECT(-1);
1253 CONVERT(VarI2FromR8
, 0.0); EXPECT(0);
1254 CONVERT(VarI2FromR8
, 1.0); EXPECT(1);
1255 CONVERT(VarI2FromR8
, 32767.0); EXPECT(32767);
1256 CONVERT(VarI2FromR8
, 32768.0); EXPECT_OVERFLOW
;
1259 CONVERT(VarI2FromR8
, -1.5); EXPECT(-2);
1260 CONVERT(VarI2FromR8
, -0.6); EXPECT(-1);
1261 CONVERT(VarI2FromR8
, -0.5); EXPECT(0);
1262 CONVERT(VarI2FromR8
, -0.4); EXPECT(0);
1263 CONVERT(VarI2FromR8
, 0.4); EXPECT(0);
1264 CONVERT(VarI2FromR8
, 0.5); EXPECT(0);
1265 CONVERT(VarI2FromR8
, 0.6); EXPECT(1);
1266 CONVERT(VarI2FromR8
, 1.5); EXPECT(2);
1269 static void test_VarI2FromDate(void)
1273 CHECKPTR(VarI2FromDate
);
1274 CONVERT(VarI2FromDate
, -32769.0); EXPECT_OVERFLOW
;
1275 CONVERT(VarI2FromDate
, -32768.0); EXPECT(-32768);
1276 CONVERT(VarI2FromDate
, -1.0); EXPECT(-1);
1277 CONVERT(VarI2FromDate
, 0.0); EXPECT(0);
1278 CONVERT(VarI2FromDate
, 1.0); EXPECT(1);
1279 CONVERT(VarI2FromDate
, 32767.0); EXPECT(32767);
1280 CONVERT(VarI2FromDate
, 32768.0); EXPECT_OVERFLOW
;
1283 CONVERT(VarI2FromDate
, -1.5); EXPECT(-2);
1284 CONVERT(VarI2FromDate
, -0.6); EXPECT(-1);
1285 CONVERT(VarI2FromDate
, -0.5); EXPECT(0);
1286 CONVERT(VarI2FromDate
, -0.4); EXPECT(0);
1287 CONVERT(VarI2FromDate
, 0.4); EXPECT(0);
1288 CONVERT(VarI2FromDate
, 0.5); EXPECT(0);
1289 CONVERT(VarI2FromDate
, 0.6); EXPECT(1);
1290 CONVERT(VarI2FromDate
, 1.5); EXPECT(2);
1293 static void test_VarI2FromCy(void)
1297 CHECKPTR(VarI2FromCy
);
1298 CONVERT_CY(VarI2FromCy
,-32769); EXPECT_OVERFLOW
;
1299 CONVERT_CY(VarI2FromCy
,-32768); EXPECT(32768);
1300 CONVERT_CY(VarI2FromCy
,-1); EXPECT(-1);
1301 CONVERT_CY(VarI2FromCy
,0); EXPECT(0);
1302 CONVERT_CY(VarI2FromCy
,1); EXPECT(1);
1303 CONVERT_CY(VarI2FromCy
,32767); EXPECT(32767);
1304 CONVERT_CY(VarI2FromCy
,32768); EXPECT_OVERFLOW
;
1307 CONVERT_CY(VarI2FromCy
,-1.5); EXPECT(-2);
1308 CONVERT_CY(VarI2FromCy
,-0.6); EXPECT(-1);
1309 CONVERT_CY(VarI2FromCy
,-0.5); EXPECT(0);
1310 CONVERT_CY(VarI2FromCy
,-0.4); EXPECT(0);
1311 CONVERT_CY(VarI2FromCy
,0.4); EXPECT(0);
1312 CONVERT_CY(VarI2FromCy
,0.5); EXPECT(0);
1313 CONVERT_CY(VarI2FromCy
,0.6); EXPECT(1);
1314 CONVERT_CY(VarI2FromCy
,1.5); EXPECT(2);
1317 static void test_VarI2FromDec(void)
1321 CHECKPTR(VarI2FromDec
);
1323 CONVERT_BADDEC(VarI2FromDec
);
1325 CONVERT_DEC(VarI2FromDec
,0,0x80,0,32769); EXPECT_OVERFLOW
;
1326 CONVERT_DEC(VarI2FromDec
,0,0x80,0,32768); EXPECT(-32768);
1327 CONVERT_DEC(VarI2FromDec
,0,0x80,0,1); EXPECT(-1);
1328 CONVERT_DEC(VarI2FromDec
,0,0,0,0); EXPECT(0);
1329 CONVERT_DEC(VarI2FromDec
,0,0,0,1); EXPECT(1);
1330 CONVERT_DEC(VarI2FromDec
,0,0,0,32767); EXPECT(32767);
1331 CONVERT_DEC(VarI2FromDec
,0,0,0,32768); EXPECT_OVERFLOW
;
1333 CONVERT_DEC(VarI2FromDec
,2,0x80,0,3276800); EXPECT(-32768);
1334 CONVERT_DEC(VarI2FromDec
,2,0,0,3276700); EXPECT(32767);
1335 CONVERT_DEC(VarI2FromDec
,2,0,0,3276800); EXPECT_OVERFLOW
;
1338 static void test_VarI2FromStr(void)
1343 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
1345 CHECKPTR(VarI2FromStr
);
1347 CONVERT_STR(VarI2FromStr
,NULL
, 0); EXPECT_MISMATCH
;
1348 CONVERT_STR(VarI2FromStr
,"0", 0); EXPECT(0);
1349 CONVERT_STR(VarI2FromStr
,"-32769", 0); EXPECT_OVERFLOW
;
1350 CONVERT_STR(VarI2FromStr
,"-32768", 0); EXPECT(-32768);
1351 CONVERT_STR(VarI2FromStr
,"32767", 0); EXPECT(32767);
1352 CONVERT_STR(VarI2FromStr
,"32768", 0); EXPECT_OVERFLOW
;
1355 CONVERT_STR(VarI2FromStr
,"-1.5", 0); EXPECT(-2);
1356 CONVERT_STR(VarI2FromStr
,"-0.6", 0); EXPECT(-1);
1357 CONVERT_STR(VarI2FromStr
,"-0.5", 0); EXPECT(0);
1358 CONVERT_STR(VarI2FromStr
,"-0.4", 0); EXPECT(0);
1359 CONVERT_STR(VarI2FromStr
,"0.4", 0); EXPECT(0);
1360 CONVERT_STR(VarI2FromStr
,"0.5", 0); EXPECT(0);
1361 CONVERT_STR(VarI2FromStr
,"0.6", 0); EXPECT(1);
1362 CONVERT_STR(VarI2FromStr
,"1.5", 0); EXPECT(2);
1365 static void test_VarI2Copy(void)
1367 COPYTEST(1, VT_I2
, V_I2(&vSrc
), V_I2(&vDst
), V_I2REF(&vSrc
), V_I2REF(&vDst
), "%d");
1370 static void test_VarI2ChangeTypeEx(void)
1372 CONVVARS(CONV_TYPE
);
1373 VARIANTARG vSrc
, vDst
;
1377 INITIAL_TYPETEST(VT_I2
, V_I2
, "%d");
1382 #define CONV_TYPE USHORT
1384 static void test_VarUI2FromI1(void)
1386 CONVVARS(signed char);
1389 CHECKPTR(VarUI2FromI1
);
1390 OVERFLOWRANGE(VarUI2FromI1
, -128, 0);
1391 CONVERTRANGE(VarUI2FromI1
, 0, 128);
1394 static void test_VarUI2FromI2(void)
1399 CHECKPTR(VarUI2FromI2
);
1400 OVERFLOWRANGE(VarUI2FromI2
, -32768, 0);
1401 CONVERTRANGE(VarUI2FromI2
, 0, 32768);
1404 static void test_VarUI2FromI4(void)
1409 CHECKPTR(VarUI2FromI4
);
1410 OVERFLOWRANGE(VarUI2FromI4
, -32768, 0);
1411 CONVERT(VarUI2FromI4
, 0); EXPECT(0);
1412 CONVERT(VarUI2FromI4
, 65535); EXPECT(65535);
1413 CONVERT(VarUI2FromI4
, 65536); EXPECT_OVERFLOW
;
1416 static void test_VarUI2FromI8(void)
1421 CHECKPTR(VarUI2FromI8
);
1422 OVERFLOWRANGE(VarUI2FromI8
, -32768, 0);
1423 CONVERT(VarUI2FromI8
, 0); EXPECT(0);
1424 CONVERT(VarUI2FromI8
, 65535); EXPECT(65535);
1425 CONVERT(VarUI2FromI8
, 65536); EXPECT_OVERFLOW
;
1428 static void test_VarUI2FromUI1(void)
1433 CHECKPTR(VarUI2FromUI1
);
1434 CONVERTRANGE(VarUI2FromUI1
, 0, 256);
1437 static void test_VarUI2FromUI4(void)
1441 CHECKPTR(VarUI2FromUI4
);
1442 CONVERT(VarUI2FromUI4
, 0); EXPECT(0);
1443 CONVERT(VarUI2FromUI4
, 65535); EXPECT(65535);
1444 CONVERT(VarUI2FromUI4
, 65536); EXPECT_OVERFLOW
;
1447 static void test_VarUI2FromUI8(void)
1451 CHECKPTR(VarUI2FromUI8
);
1452 CONVERT(VarUI2FromUI8
, 0); EXPECT(0);
1453 CONVERT(VarUI2FromUI8
, 65535); EXPECT(65535);
1454 CONVERT(VarUI2FromUI8
, 65536); EXPECT_OVERFLOW
;
1457 static void test_VarUI2FromBool(void)
1459 CONVVARS(VARIANT_BOOL
);
1462 CHECKPTR(VarUI2FromBool
);
1463 CONVERT(VarUI2FromBool
, -1); EXPECT(65535); /* Wraps! */
1464 CONVERTRANGE(VarUI2FromBool
, 0, 32768);
1467 static void test_VarUI2FromR4(void)
1471 CHECKPTR(VarUI2FromR4
);
1472 CONVERT(VarUI2FromR4
, -1.0f
); EXPECT_OVERFLOW
;
1473 CONVERT(VarUI2FromR4
, 0.0f
); EXPECT(0);
1474 CONVERT(VarUI2FromR4
, 1.0f
); EXPECT(1);
1475 CONVERT(VarUI2FromR4
, 65535.0f
); EXPECT(65535);
1476 CONVERT(VarUI2FromR4
, 65536.0f
); EXPECT_OVERFLOW
;
1479 CONVERT(VarUI2FromR4
, -1.5f
); EXPECT_OVERFLOW
;
1480 CONVERT(VarUI2FromR4
, -0.6f
); EXPECT_OVERFLOW
;
1481 CONVERT(VarUI2FromR4
, -0.5f
); EXPECT(0);
1482 CONVERT(VarUI2FromR4
, -0.4f
); EXPECT(0);
1483 CONVERT(VarUI2FromR4
, 0.4f
); EXPECT(0);
1484 CONVERT(VarUI2FromR4
, 0.5f
); EXPECT(0);
1485 CONVERT(VarUI2FromR4
, 0.6f
); EXPECT(1);
1486 CONVERT(VarUI2FromR4
, 1.5f
); EXPECT(2);
1489 static void test_VarUI2FromR8(void)
1493 CHECKPTR(VarUI2FromR8
);
1494 CONVERT(VarUI2FromR8
, -1.0); EXPECT_OVERFLOW
;
1495 CONVERT(VarUI2FromR8
, 0.0); EXPECT(0);
1496 CONVERT(VarUI2FromR8
, 1.0); EXPECT(1);
1497 CONVERT(VarUI2FromR8
, 65535.0); EXPECT(65535);
1498 CONVERT(VarUI2FromR8
, 65536.0); EXPECT_OVERFLOW
;
1501 CONVERT(VarUI2FromR8
, -1.5); EXPECT_OVERFLOW
;
1502 CONVERT(VarUI2FromR8
, -0.6); EXPECT_OVERFLOW
;
1503 CONVERT(VarUI2FromR8
, -0.5); EXPECT(0);
1504 CONVERT(VarUI2FromR8
, -0.4); EXPECT(0);
1505 CONVERT(VarUI2FromR8
, 0.4); EXPECT(0);
1506 CONVERT(VarUI2FromR8
, 0.5); EXPECT(0);
1507 CONVERT(VarUI2FromR8
, 0.6); EXPECT(1);
1508 CONVERT(VarUI2FromR8
, 1.5); EXPECT(2);
1511 static void test_VarUI2FromDate(void)
1515 CHECKPTR(VarUI2FromDate
);
1516 CONVERT(VarUI2FromDate
, -1.0); EXPECT_OVERFLOW
;
1517 CONVERT(VarUI2FromDate
, 0.0); EXPECT(0);
1518 CONVERT(VarUI2FromDate
, 1.0); EXPECT(1);
1519 CONVERT(VarUI2FromDate
, 65535.0); EXPECT(65535);
1520 CONVERT(VarUI2FromDate
, 65536.0); EXPECT_OVERFLOW
;
1523 CONVERT(VarUI2FromDate
, -1.5); EXPECT_OVERFLOW
;
1524 CONVERT(VarUI2FromDate
, -0.6); EXPECT_OVERFLOW
;
1525 CONVERT(VarUI2FromDate
, -0.5); EXPECT(0);
1526 CONVERT(VarUI2FromDate
, -0.4); EXPECT(0);
1527 CONVERT(VarUI2FromDate
, 0.4); EXPECT(0);
1528 CONVERT(VarUI2FromDate
, 0.5); EXPECT(0);
1529 CONVERT(VarUI2FromDate
, 0.6); EXPECT(1);
1530 CONVERT(VarUI2FromDate
, 1.5); EXPECT(2);
1533 static void test_VarUI2FromCy(void)
1537 CHECKPTR(VarUI2FromCy
);
1538 CONVERT_CY(VarUI2FromCy
,-1); EXPECT_OVERFLOW
;
1539 CONVERT_CY(VarUI2FromCy
,0); EXPECT(0);
1540 CONVERT_CY(VarUI2FromCy
,1); EXPECT(1);
1541 CONVERT_CY(VarUI2FromCy
,65535); EXPECT(65535);
1542 CONVERT_CY(VarUI2FromCy
,65536); EXPECT_OVERFLOW
;
1545 CONVERT_CY(VarUI2FromCy
,-1.5); EXPECT_OVERFLOW
;
1546 CONVERT_CY(VarUI2FromCy
,-0.6); EXPECT_OVERFLOW
;
1547 CONVERT_CY(VarUI2FromCy
,-0.5); EXPECT(0);
1548 CONVERT_CY(VarUI2FromCy
,-0.4); EXPECT(0);
1549 CONVERT_CY(VarUI2FromCy
,0.4); EXPECT(0);
1550 CONVERT_CY(VarUI2FromCy
,0.5); EXPECT(0);
1551 CONVERT_CY(VarUI2FromCy
,0.6); EXPECT(1);
1552 CONVERT_CY(VarUI2FromCy
,1.5); EXPECT(2);
1555 static void test_VarUI2FromDec(void)
1559 CHECKPTR(VarUI2FromDec
);
1561 CONVERT_BADDEC(VarUI2FromDec
);
1563 CONVERT_DEC(VarUI2FromDec
,0,0x80,0,1); EXPECT_OVERFLOW
;
1564 CONVERT_DEC(VarUI2FromDec
,0,0,0,0); EXPECT(0);
1565 CONVERT_DEC(VarUI2FromDec
,0,0,0,1); EXPECT(1);
1566 CONVERT_DEC(VarUI2FromDec
,0,0,0,65535); EXPECT(65535);
1567 CONVERT_DEC(VarUI2FromDec
,0,0,0,65536); EXPECT_OVERFLOW
;
1569 CONVERT_DEC(VarUI2FromDec
,2,0x80,0,100); EXPECT_OVERFLOW
;
1570 CONVERT_DEC(VarUI2FromDec
,2,0,0,6553500); EXPECT(65535);
1571 CONVERT_DEC(VarUI2FromDec
,2,0,0,6553600); EXPECT_OVERFLOW
;
1574 static void test_VarUI2FromStr(void)
1579 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
1581 CHECKPTR(VarUI2FromStr
);
1583 CONVERT_STR(VarUI2FromStr
,NULL
, 0); EXPECT_MISMATCH
;
1584 CONVERT_STR(VarUI2FromStr
,"0", 0); EXPECT(0);
1585 CONVERT_STR(VarUI2FromStr
,"-1", 0); EXPECT_OVERFLOW
;
1586 CONVERT_STR(VarUI2FromStr
,"65535", 0); EXPECT(65535);
1587 CONVERT_STR(VarUI2FromStr
,"65536", 0); EXPECT_OVERFLOW
;
1590 CONVERT_STR(VarUI2FromStr
,"-1.5", 0); EXPECT_OVERFLOW
;
1591 CONVERT_STR(VarUI2FromStr
,"-0.6", 0); EXPECT_OVERFLOW
;
1592 CONVERT_STR(VarUI2FromStr
,"-0.5", 0); EXPECT(0);
1593 CONVERT_STR(VarUI2FromStr
,"-0.4", 0); EXPECT(0);
1594 CONVERT_STR(VarUI2FromStr
,"0.4", 0); EXPECT(0);
1595 CONVERT_STR(VarUI2FromStr
,"0.5", 0); EXPECT(0);
1596 CONVERT_STR(VarUI2FromStr
,"0.6", 0); EXPECT(1);
1597 CONVERT_STR(VarUI2FromStr
,"1.5", 0); EXPECT(2);
1600 static void test_VarUI2Copy(void)
1604 COPYTEST(1, VT_UI2
, V_UI2(&vSrc
), V_UI2(&vDst
), V_UI2REF(&vSrc
), V_UI2REF(&vDst
), "%d");
1608 static void test_VarUI2ChangeTypeEx(void)
1610 CONVVARS(CONV_TYPE
);
1611 VARIANTARG vSrc
, vDst
;
1617 INITIAL_TYPETEST(VT_UI2
, V_UI2
, "%d");
1627 #define CONV_TYPE LONG
1629 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%ld")
1632 static void test_VarI4FromI1(void)
1634 CONVVARS(signed char);
1637 CHECKPTR(VarI4FromI1
);
1638 CONVERTRANGE(VarI4FromI1
, -128, 128);
1641 static void test_VarI4FromI2(void)
1646 CHECKPTR(VarI4FromI2
);
1647 CONVERTRANGE(VarI4FromI2
, -32768, 32768);
1650 static void test_VarI4FromI8(void)
1654 CHECKPTR(VarI4FromI8
);
1655 CHECKPTR(VarI4FromDec
);
1657 CONVERT(VarI4FromI8
, -1); EXPECT(-1);
1658 CONVERT(VarI4FromI8
, 0); EXPECT(0);
1659 CONVERT(VarI4FromI8
, 1); EXPECT(1);
1661 CONVERT_I8(VarI4FromI8
, -1, 2147483647ul); EXPECT_OVERFLOW
;
1662 CONVERT_I8(VarI4FromI8
, -1, 2147483648ul); EXPECT(-2147483647 - 1);
1663 CONVERT_I8(VarI4FromI8
, 0, 2147483647ul); EXPECT(2147483647);
1664 CONVERT_I8(VarI4FromI8
, 0, 2147483648ul); EXPECT_OVERFLOW
;
1667 static void test_VarI4FromUI1(void)
1672 CHECKPTR(VarI4FromUI1
);
1673 CONVERTRANGE(VarI4FromUI1
, 0, 256);
1676 static void test_VarI4FromUI2(void)
1681 CHECKPTR(VarI4FromUI2
);
1682 CONVERTRANGE(VarI4FromUI2
, 0, 65536);
1685 static void test_VarI4FromUI4(void)
1689 CHECKPTR(VarI4FromUI4
);
1690 CONVERT(VarI4FromUI4
, 0); EXPECT(0);
1691 CONVERT(VarI4FromUI4
, 1); EXPECT(1);
1692 CONVERT(VarI4FromUI4
, 2147483647); EXPECT(2147483647);
1693 CONVERT(VarI4FromUI4
, 2147483648ul); EXPECT_OVERFLOW
;
1696 static void test_VarI4FromUI8(void)
1700 CHECKPTR(VarI4FromUI8
);
1701 CONVERT(VarI4FromUI8
, 0); EXPECT(0);
1702 CONVERT(VarI4FromUI8
, 1); EXPECT(1);
1703 CONVERT(VarI4FromUI8
, 2147483647); EXPECT(2147483647);
1704 CONVERT(VarI4FromUI8
, 2147483648ul); EXPECT_OVERFLOW
;
1707 static void test_VarI4FromBool(void)
1709 CONVVARS(VARIANT_BOOL
);
1712 CHECKPTR(VarI4FromBool
);
1713 CONVERTRANGE(VarI4FromBool
, -32768, 32768);
1716 static void test_VarI4FromR4(void)
1720 CHECKPTR(VarI4FromR4
);
1722 /* min/max values are not exactly representable in a float */
1723 CONVERT(VarI4FromR4
, -1.0f
); EXPECT(-1);
1724 CONVERT(VarI4FromR4
, 0.0f
); EXPECT(0);
1725 CONVERT(VarI4FromR4
, 1.0f
); EXPECT(1);
1727 CONVERT(VarI4FromR4
, -1.5f
); EXPECT(-2);
1728 CONVERT(VarI4FromR4
, -0.6f
); EXPECT(-1);
1729 CONVERT(VarI4FromR4
, -0.5f
); EXPECT(0);
1730 CONVERT(VarI4FromR4
, -0.4f
); EXPECT(0);
1731 CONVERT(VarI4FromR4
, 0.4f
); EXPECT(0);
1732 CONVERT(VarI4FromR4
, 0.5f
); EXPECT(0);
1733 CONVERT(VarI4FromR4
, 0.6f
); EXPECT(1);
1734 CONVERT(VarI4FromR4
, 1.5f
); EXPECT(2);
1737 static void test_VarI4FromR8(void)
1741 CHECKPTR(VarI4FromR8
);
1742 CONVERT(VarI4FromR8
, -2147483649.0); EXPECT_OVERFLOW
;
1743 CONVERT(VarI4FromR8
, -2147483648.0); EXPECT(-2147483647 - 1);
1744 CONVERT(VarI4FromR8
, -1.0); EXPECT(-1);
1745 CONVERT(VarI4FromR8
, 0.0); EXPECT(0);
1746 CONVERT(VarI4FromR8
, 1.0); EXPECT(1);
1747 CONVERT(VarI4FromR8
, 2147483647.0); EXPECT(2147483647);
1748 CONVERT(VarI4FromR8
, 2147483648.0); EXPECT_OVERFLOW
;
1750 CONVERT(VarI4FromR8
, -1.5); EXPECT(-2);
1751 CONVERT(VarI4FromR8
, -0.6); EXPECT(-1);
1752 CONVERT(VarI4FromR8
, -0.5); EXPECT(0);
1753 CONVERT(VarI4FromR8
, -0.4); EXPECT(0);
1754 CONVERT(VarI4FromR8
, 0.4); EXPECT(0);
1755 CONVERT(VarI4FromR8
, 0.5); EXPECT(0);
1756 CONVERT(VarI4FromR8
, 0.6); EXPECT(1);
1757 CONVERT(VarI4FromR8
, 1.5); EXPECT(2);
1760 static void test_VarI4FromDate(void)
1764 CHECKPTR(VarI4FromDate
);
1765 CONVERT(VarI4FromDate
, -2147483649.0); EXPECT_OVERFLOW
;
1766 CONVERT(VarI4FromDate
, -2147483648.0); EXPECT(-2147483647 - 1);
1767 CONVERT(VarI4FromDate
, -1.0); EXPECT(-1);
1768 CONVERT(VarI4FromDate
, 0.0); EXPECT(0);
1769 CONVERT(VarI4FromDate
, 1.0); EXPECT(1);
1770 CONVERT(VarI4FromDate
, 2147483647.0); EXPECT(2147483647);
1771 CONVERT(VarI4FromDate
, 2147483648.0); EXPECT_OVERFLOW
;
1773 CONVERT(VarI4FromDate
, -1.5); EXPECT(-2);
1774 CONVERT(VarI4FromDate
, -0.6); EXPECT(-1);
1775 CONVERT(VarI4FromDate
, -0.5); EXPECT(0);
1776 CONVERT(VarI4FromDate
, -0.4); EXPECT(0);
1777 CONVERT(VarI4FromDate
, 0.4); EXPECT(0);
1778 CONVERT(VarI4FromDate
, 0.5); EXPECT(0);
1779 CONVERT(VarI4FromDate
, 0.6); EXPECT(1);
1780 CONVERT(VarI4FromDate
, 1.5); EXPECT(2);
1783 static void test_VarI4FromCy(void)
1787 CHECKPTR(VarI4FromCy
);
1788 CONVERT_CY(VarI4FromCy
,-1); EXPECT(-1);
1789 CONVERT_CY(VarI4FromCy
,0); EXPECT(0);
1790 CONVERT_CY(VarI4FromCy
,1); EXPECT(1);
1792 CONVERT_CY64(VarI4FromCy
,-1,2147483647ul); EXPECT_OVERFLOW
;
1793 CONVERT_CY64(VarI4FromCy
,-1,2147483648ul); EXPECT(-2147483647 - 1);
1794 CONVERT_CY64(VarI4FromCy
,0,2147483647ul); EXPECT(2147483647ul);
1795 CONVERT_CY64(VarI4FromCy
,0,2147483648ul); EXPECT_OVERFLOW
;
1797 CONVERT_CY(VarI4FromCy
,-1.5); EXPECT(-2);
1798 CONVERT_CY(VarI4FromCy
,-0.6); EXPECT(-1);
1799 CONVERT_CY(VarI4FromCy
,-0.5); EXPECT(0);
1800 CONVERT_CY(VarI4FromCy
,-0.4); EXPECT(0);
1801 CONVERT_CY(VarI4FromCy
,0.4); EXPECT(0);
1802 CONVERT_CY(VarI4FromCy
,0.5); EXPECT(0);
1803 CONVERT_CY(VarI4FromCy
,0.6); EXPECT(1);
1804 CONVERT_CY(VarI4FromCy
,1.5); EXPECT(2);
1807 static void test_VarI4FromDec(void)
1811 CHECKPTR(VarI4FromDec
);
1813 CONVERT_BADDEC(VarI4FromDec
);
1815 CONVERT_DEC(VarI4FromDec
,0,0x80,0,1); EXPECT(-1);
1816 CONVERT_DEC(VarI4FromDec
,0,0,0,0); EXPECT(0);
1817 CONVERT_DEC(VarI4FromDec
,0,0,0,1); EXPECT(1);
1819 CONVERT_DEC64(VarI4FromDec
,0,0x80,0,0,2147483649ul); EXPECT_OVERFLOW
;
1820 CONVERT_DEC64(VarI4FromDec
,0,0x80,0,0,2147483648ul); EXPECT(-2147483647 - 1);
1821 CONVERT_DEC64(VarI4FromDec
,0,0,0,0,2147483647ul); EXPECT(2147483647ul);
1822 CONVERT_DEC64(VarI4FromDec
,0,0,0,0,2147483648ul); EXPECT_OVERFLOW
;
1824 CONVERT_DEC64(VarI4FromDec
,2,0x80,0,50,100); EXPECT_OVERFLOW
;
1825 CONVERT_DEC64(VarI4FromDec
,2,0x80,0,50,0); EXPECT(-2147483647 - 1);
1826 CONVERT_DEC64(VarI4FromDec
,2,0,0,49,4294967196ul); EXPECT(2147483647);
1827 CONVERT_DEC64(VarI4FromDec
,2,0,0,50,0); EXPECT_OVERFLOW
;
1830 static void test_VarI4FromStr(void)
1835 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
1837 CHECKPTR(VarI4FromStr
);
1839 CONVERT_STR(VarI4FromStr
,NULL
,0); EXPECT_MISMATCH
;
1840 CONVERT_STR(VarI4FromStr
,"0",0); EXPECT(0);
1841 CONVERT_STR(VarI4FromStr
,"-2147483649",0); EXPECT_OVERFLOW
;
1842 CONVERT_STR(VarI4FromStr
,"-2147483648",0); EXPECT(-2147483647 -1);
1843 CONVERT_STR(VarI4FromStr
,"2147483647",0); EXPECT(2147483647);
1844 CONVERT_STR(VarI4FromStr
,"2147483648",0); EXPECT_OVERFLOW
;
1847 CONVERT_STR(VarI4FromStr
,"-1.5",0); EXPECT(-2);
1848 CONVERT_STR(VarI4FromStr
,"-0.6",0); EXPECT(-1);
1849 CONVERT_STR(VarI4FromStr
,"-0.5",0); EXPECT(0);
1850 CONVERT_STR(VarI4FromStr
,"-0.4",0); EXPECT(0);
1851 CONVERT_STR(VarI4FromStr
,"0.4",0); EXPECT(0);
1852 CONVERT_STR(VarI4FromStr
,"0.5",0); EXPECT(0);
1853 CONVERT_STR(VarI4FromStr
,"0.6",0); EXPECT(1);
1854 CONVERT_STR(VarI4FromStr
,"1.5",0); EXPECT(2);
1857 static void test_VarI4Copy(void)
1859 COPYTEST(1l, VT_I4
, V_I4(&vSrc
), V_I4(&vDst
), V_I4REF(&vSrc
), V_I4REF(&vDst
), "%ld");
1862 static void test_VarI4ChangeTypeEx(void)
1864 CONVVARS(CONV_TYPE
);
1865 VARIANTARG vSrc
, vDst
;
1869 INITIAL_TYPETEST(VT_I4
, V_I4
, "%ld");
1874 #define CONV_TYPE ULONG
1876 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%lu")
1878 static void test_VarUI4FromI1(void)
1880 CONVVARS(signed char);
1883 CHECKPTR(VarUI4FromI1
);
1884 OVERFLOWRANGE(VarUI4FromI1
, -127, 0);
1885 CONVERTRANGE(VarUI4FromI1
, 0, 128);
1888 static void test_VarUI4FromI2(void)
1893 CHECKPTR(VarUI4FromI2
);
1894 OVERFLOWRANGE(VarUI4FromI2
, -32768, 0);
1895 CONVERTRANGE(VarUI4FromI2
, 0, 32768);
1898 static void test_VarUI4FromUI2(void)
1903 CHECKPTR(VarUI4FromUI2
);
1904 CONVERTRANGE(VarUI4FromUI2
, 0, 65536);
1907 static void test_VarUI4FromI8(void)
1911 CHECKPTR(VarUI4FromI8
);
1912 CONVERT(VarUI4FromI8
, -1); EXPECT_OVERFLOW
;
1913 CONVERT(VarUI4FromI8
, 0); EXPECT(0);
1914 CONVERT(VarUI4FromI8
, 1); EXPECT(1);
1915 CONVERT(VarUI4FromI8
, 4294967295ul); EXPECT(4294967295ul);
1916 CONVERT_I8(VarUI4FromI8
, 1, 0); EXPECT_OVERFLOW
;
1919 static void test_VarUI4FromUI1(void)
1924 CHECKPTR(VarUI4FromUI1
);
1925 CONVERTRANGE(VarUI4FromUI1
, 0, 256);
1928 static void test_VarUI4FromI4(void)
1932 CHECKPTR(VarUI4FromI4
);
1933 CONVERT(VarUI4FromI4
, -1); EXPECT_OVERFLOW
;
1934 CONVERT(VarUI4FromI4
, 0); EXPECT(0);
1935 CONVERT(VarUI4FromI4
, 1); EXPECT(1);
1936 CONVERT(VarUI4FromI4
, 2147483647); EXPECT(2147483647);
1939 static void test_VarUI4FromUI8(void)
1943 CHECKPTR(VarUI4FromUI8
);
1944 CONVERT(VarUI4FromUI8
, 0); EXPECT(0);
1945 CONVERT(VarUI4FromUI8
, 1); EXPECT(1);
1946 CONVERT(VarUI4FromI8
, 4294967295ul); EXPECT(4294967295ul);
1947 CONVERT_I8(VarUI4FromI8
, 1, 0); EXPECT_OVERFLOW
;
1950 static void test_VarUI4FromBool(void)
1952 CONVVARS(VARIANT_BOOL
);
1955 CHECKPTR(VarUI4FromBool
);
1956 CONVERTRANGE(VarUI4FromBool
, -32768, 32768);
1959 static void test_VarUI4FromR4(void)
1963 CHECKPTR(VarUI4FromR4
);
1964 /* We can't test max values as they are not exactly representable in a float */
1965 CONVERT(VarUI4FromR4
, -1.0f
); EXPECT_OVERFLOW
;
1966 CONVERT(VarUI4FromR4
, 0.0f
); EXPECT(0);
1967 CONVERT(VarUI4FromR4
, 1.0f
); EXPECT(1);
1969 CONVERT(VarUI4FromR4
, -1.5f
); EXPECT_OVERFLOW
;
1970 CONVERT(VarUI4FromR4
, -0.6f
); EXPECT_OVERFLOW
;
1971 CONVERT(VarUI4FromR4
, -0.5f
); EXPECT(0);
1972 CONVERT(VarUI4FromR4
, -0.4f
); EXPECT(0);
1973 CONVERT(VarUI4FromR4
, 0.4f
); EXPECT(0);
1974 CONVERT(VarUI4FromR4
, 0.5f
); EXPECT(0);
1975 CONVERT(VarUI4FromR4
, 0.6f
); EXPECT(1);
1976 CONVERT(VarUI4FromR4
, 1.5f
); EXPECT(2);
1980 static void test_VarUI4FromR8(void)
1984 CHECKPTR(VarUI4FromR8
);
1985 CONVERT(VarUI4FromR8
, -1.0); EXPECT_OVERFLOW
;
1986 CONVERT(VarUI4FromR8
, 0.0); EXPECT(0);
1987 CONVERT(VarUI4FromR8
, 1.0); EXPECT(1);
1988 CONVERT(VarUI4FromR8
, 4294967295.0); EXPECT(4294967295ul);
1989 CONVERT(VarUI4FromR8
, 4294967296.0); EXPECT_OVERFLOW
;
1991 CONVERT(VarUI4FromR8
, -1.5); EXPECT_OVERFLOW
;
1992 CONVERT(VarUI4FromR8
, -0.6); EXPECT_OVERFLOW
;
1993 CONVERT(VarUI4FromR8
, -0.5); EXPECT(0);
1994 CONVERT(VarUI4FromR8
, -0.4); EXPECT(0);
1995 CONVERT(VarUI4FromR8
, 0.4); EXPECT(0);
1996 CONVERT(VarUI4FromR8
, 0.5); EXPECT(0);
1997 CONVERT(VarUI4FromR8
, 0.6); EXPECT(1);
1998 CONVERT(VarUI4FromR8
, 1.5); EXPECT(2);
2001 static void test_VarUI4FromDate(void)
2005 CHECKPTR(VarUI4FromDate
);
2006 CONVERT(VarUI4FromDate
, -1.0); EXPECT_OVERFLOW
;
2007 CONVERT(VarUI4FromDate
, 0.0); EXPECT(0);
2008 CONVERT(VarUI4FromDate
, 1.0); EXPECT(1);
2009 CONVERT(VarUI4FromDate
, 4294967295.0); EXPECT(4294967295ul);
2010 CONVERT(VarUI4FromDate
, 4294967296.0); EXPECT_OVERFLOW
;
2012 CONVERT(VarUI4FromDate
, -1.5); EXPECT_OVERFLOW
;
2013 CONVERT(VarUI4FromDate
, -0.6); EXPECT_OVERFLOW
;
2014 CONVERT(VarUI4FromDate
, -0.5); EXPECT(0);
2015 CONVERT(VarUI4FromDate
, -0.4); EXPECT(0);
2016 CONVERT(VarUI4FromDate
, 0.4); EXPECT(0);
2017 CONVERT(VarUI4FromDate
, 0.5); EXPECT(0);
2018 CONVERT(VarUI4FromDate
, 0.6); EXPECT(1);
2019 CONVERT(VarUI4FromDate
, 1.5); EXPECT(2);
2022 static void test_VarUI4FromCy(void)
2026 CHECKPTR(VarUI4FromCy
);
2027 CONVERT_CY(VarUI4FromCy
,-1); EXPECT_OVERFLOW
;
2028 CONVERT_CY(VarUI4FromCy
,0); EXPECT(0);
2029 CONVERT_CY(VarUI4FromCy
,1); EXPECT(1);
2030 CONVERT_CY64(VarUI4FromCy
,0,4294967295ul); EXPECT(4294967295ul);
2031 CONVERT_CY64(VarUI4FromCy
,1,0); EXPECT_OVERFLOW
;
2033 CONVERT_CY(VarUI4FromCy
,-1.5); EXPECT_OVERFLOW
;
2034 CONVERT_CY(VarUI4FromCy
,-0.6); EXPECT_OVERFLOW
;
2035 CONVERT_CY(VarUI4FromCy
,-0.5); EXPECT(0);
2036 CONVERT_CY(VarUI4FromCy
,-0.4); EXPECT(0);
2037 CONVERT_CY(VarUI4FromCy
,0.4); EXPECT(0);
2038 CONVERT_CY(VarUI4FromCy
,0.5); EXPECT(0);
2039 CONVERT_CY(VarUI4FromCy
,0.6); EXPECT(1);
2040 CONVERT_CY(VarUI4FromCy
,1.5); EXPECT(2);
2043 static void test_VarUI4FromDec(void)
2047 CHECKPTR(VarUI4FromDec
);
2049 CONVERT_BADDEC(VarUI4FromDec
);
2051 CONVERT_DEC(VarUI4FromDec
,0,0x80,0,1); EXPECT_OVERFLOW
;
2052 CONVERT_DEC(VarUI4FromDec
,0,0,0,0); EXPECT(0);
2053 CONVERT_DEC(VarUI4FromDec
,0,0,0,1); EXPECT(1);
2054 CONVERT_DEC64(VarUI4FromDec
,0,0,0,0,4294967295ul); EXPECT(4294967295ul);
2055 CONVERT_DEC64(VarUI4FromDec
,0,0,0,1,0); EXPECT_OVERFLOW
;
2057 CONVERT_DEC64(VarUI4FromDec
,2,0,0,99,4294967196ul); EXPECT(4294967295ul);
2058 CONVERT_DEC64(VarUI4FromDec
,2,0,0,100,0); EXPECT_OVERFLOW
;
2061 static void test_VarUI4FromStr(void)
2066 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
2068 CHECKPTR(VarUI4FromStr
);
2070 CONVERT_STR(VarUI4FromStr
,NULL
,0); EXPECT_MISMATCH
;
2071 CONVERT_STR(VarUI4FromStr
,"-1",0); EXPECT_OVERFLOW
;
2072 CONVERT_STR(VarUI4FromStr
,"0",0); EXPECT(0);
2073 CONVERT_STR(VarUI4FromStr
,"4294967295",0); EXPECT(4294967295ul);
2074 CONVERT_STR(VarUI4FromStr
,"4294967296",0); EXPECT_OVERFLOW
;
2077 CONVERT_STR(VarUI4FromStr
,"-1.5",0); EXPECT_OVERFLOW
;
2078 CONVERT_STR(VarUI4FromStr
,"-0.6",0); EXPECT_OVERFLOW
;
2079 CONVERT_STR(VarUI4FromStr
,"-0.5",0); EXPECT(0);
2080 CONVERT_STR(VarUI4FromStr
,"-0.4",0); EXPECT(0);
2081 CONVERT_STR(VarUI4FromStr
,"0.4",0); EXPECT(0);
2082 CONVERT_STR(VarUI4FromStr
,"0.5",0); EXPECT(0);
2083 CONVERT_STR(VarUI4FromStr
,"0.6",0); EXPECT(1);
2084 CONVERT_STR(VarUI4FromStr
,"1.5",0); EXPECT(2);
2087 static void test_VarUI4Copy(void)
2091 COPYTEST(1ul, VT_UI4
, V_UI4(&vSrc
), V_UI4(&vDst
), V_UI4REF(&vSrc
), V_UI4REF(&vDst
), "%lu");
2095 static void test_VarUI4ChangeTypeEx(void)
2097 CONVVARS(CONV_TYPE
);
2098 VARIANTARG vSrc
, vDst
;
2104 INITIAL_TYPETEST(VT_UI4
, V_UI4
, "%lu");
2114 #define CONV_TYPE LONG64
2116 #define EXPECTRES(res, x) \
2117 ok(hres == S_OK || ((HRESULT)res != S_OK && hres == (HRESULT)res), \
2118 "expected hres " #x ", got hres=0x%08lx\n", hres)
2120 #define EXPECTI8(x) \
2121 ok((hres == S_OK && out == (CONV_TYPE)(x)), \
2122 "expected " #x "(%lu,%lu), got (%lu,%lu); hres=0x%08lx\n", \
2123 (ULONG)((LONG64)(x) >> 32), (ULONG)((x) & 0xffffffff), \
2124 (ULONG)(out >> 32), (ULONG)(out & 0xffffffff), hres)
2126 #define EXPECTI864(x,y) \
2127 ok(hres == S_OK && (out >> 32) == (CONV_TYPE)(x) && (out & 0xffffffff) == (CONV_TYPE)(y), \
2128 "expected " #x "(%lu,%lu), got (%lu,%lu); hres=0x%08lx\n", \
2129 (ULONG)(x), (ULONG)(y), \
2130 (ULONG)(out >> 32), (ULONG)(out & 0xffffffff), hres)
2132 static void test_VarI8FromI1(void)
2134 CONVVARS(signed char);
2137 CHECKPTR(VarI8FromI1
);
2138 for (i
= -128; i
< 128; i
++)
2140 CONVERT(VarI8FromI1
,i
); EXPECTI8(i
);
2144 static void test_VarI8FromUI1(void)
2149 CHECKPTR(VarI8FromUI1
);
2150 for (i
= 0; i
< 256; i
++)
2152 CONVERT(VarI8FromUI1
,i
); EXPECTI8(i
);
2156 static void test_VarI8FromI2(void)
2161 CHECKPTR(VarI8FromI2
);
2162 for (i
= -32768; i
< 32768; i
++)
2164 CONVERT(VarI8FromI2
,i
); EXPECTI8(i
);
2168 static void test_VarI8FromUI2(void)
2173 CHECKPTR(VarI8FromUI2
);
2174 for (i
= -0; i
< 65535; i
++)
2176 CONVERT(VarI8FromUI2
,i
); EXPECTI8(i
);
2180 static void test_VarI8FromUI4(void)
2184 CHECKPTR(VarI8FromUI4
);
2185 CONVERT(VarI8FromUI4
, 0); EXPECTI8(0);
2186 CONVERT(VarI8FromUI4
, 1); EXPECTI8(1);
2187 CONVERT(VarI8FromUI4
, 4294967295ul); EXPECTI8(4294967295ul);
2190 static void test_VarI8FromR4(void)
2194 CHECKPTR(VarI8FromR4
);
2196 CONVERT(VarI8FromR4
, -128.0f
); EXPECTI8(-128);
2197 CONVERT(VarI8FromR4
, -1.0f
); EXPECTI8(-1);
2198 CONVERT(VarI8FromR4
, 0.0f
); EXPECTI8(0);
2199 CONVERT(VarI8FromR4
, 1.0f
); EXPECTI8(1);
2200 CONVERT(VarI8FromR4
, 127.0f
); EXPECTI8(127);
2202 CONVERT(VarI8FromR4
, -1.5f
); EXPECTI8(-2);
2203 CONVERT(VarI8FromR4
, -0.6f
); EXPECTI8(-1);
2204 CONVERT(VarI8FromR4
, -0.5f
); EXPECTI8(0);
2205 CONVERT(VarI8FromR4
, -0.4f
); EXPECTI8(0);
2206 CONVERT(VarI8FromR4
, 0.4f
); EXPECTI8(0);
2207 CONVERT(VarI8FromR4
, 0.5f
); EXPECTI8(0);
2208 CONVERT(VarI8FromR4
, 0.6f
); EXPECTI8(1);
2209 CONVERT(VarI8FromR4
, 1.5f
); EXPECTI8(2);
2212 static void test_VarI8FromR8(void)
2216 CHECKPTR(VarI8FromR8
);
2217 CONVERT(VarI8FromR8
, -128.0); EXPECTI8(-128);
2218 CONVERT(VarI8FromR8
, -1.0); EXPECTI8(-1);
2219 CONVERT(VarI8FromR8
, 0.0); EXPECTI8(0);
2220 CONVERT(VarI8FromR8
, 1.0); EXPECTI8(1);
2221 CONVERT(VarI8FromR8
, 127.0); EXPECTI8(127);
2223 CONVERT(VarI8FromR8
, -1.5); EXPECTI8(-2);
2224 CONVERT(VarI8FromR8
, -0.6); EXPECTI8(-1);
2225 CONVERT(VarI8FromR8
, -0.5); EXPECTI8(0);
2226 CONVERT(VarI8FromR8
, -0.4); EXPECTI8(0);
2227 CONVERT(VarI8FromR8
, 0.4); EXPECTI8(0);
2228 CONVERT(VarI8FromR8
, 0.5); EXPECTI8(0);
2229 CONVERT(VarI8FromR8
, 0.6); EXPECTI8(1);
2230 CONVERT(VarI8FromR8
, 1.5); EXPECTI8(2);
2233 static void test_VarI8FromDate(void)
2237 CHECKPTR(VarI8FromDate
);
2238 CONVERT(VarI8FromDate
, -128.0); EXPECTI8(-128);
2239 CONVERT(VarI8FromDate
, -1.0); EXPECTI8(-1);
2240 CONVERT(VarI8FromDate
, 0.0); EXPECTI8(0);
2241 CONVERT(VarI8FromDate
, 1.0); EXPECTI8(1);
2242 CONVERT(VarI8FromDate
, 127.0); EXPECTI8(127);
2244 CONVERT(VarI8FromDate
, -1.5); EXPECTI8(-2);
2245 CONVERT(VarI8FromDate
, -0.6); EXPECTI8(-1);
2246 CONVERT(VarI8FromDate
, -0.5); EXPECTI8(0);
2247 CONVERT(VarI8FromDate
, -0.4); EXPECTI8(0);
2248 CONVERT(VarI8FromDate
, 0.4); EXPECTI8(0);
2249 CONVERT(VarI8FromDate
, 0.5); EXPECTI8(0);
2250 CONVERT(VarI8FromDate
, 0.6); EXPECTI8(1);
2251 CONVERT(VarI8FromDate
, 1.5); EXPECTI8(2);
2254 static void test_VarI8FromBool(void)
2256 CONVVARS(VARIANT_BOOL
);
2259 CHECKPTR(VarI8FromBool
);
2260 for (i
= -32768; i
< 32768; i
++)
2262 CONVERT(VarI8FromBool
,i
); EXPECTI8(i
);
2266 static void test_VarI8FromUI8(void)
2270 CHECKPTR(VarI8FromUI8
);
2271 CONVERT(VarI8FromUI8
, 0); EXPECTI8(0);
2272 CONVERT(VarI8FromUI8
, 1); EXPECTI8(1);
2273 CONVERT_I8(VarI8FromUI8
, 0x7fffffff, 0xffffffff); EXPECTI864(0x7fffffff, 0xffffffff);
2274 CONVERT_I8(VarI8FromUI8
, 0x80000000, 0); EXPECT_OVERFLOW
;
2277 static void test_VarI8FromCy(void)
2281 CHECKPTR(VarI8FromCy
);
2282 CONVERT_CY(VarI8FromCy
,-128); EXPECTI8(-129);
2283 CONVERT_CY(VarI8FromCy
,-1); EXPECTI8(-2);
2284 CONVERT_CY(VarI8FromCy
,0); EXPECTI8(0);
2285 CONVERT_CY(VarI8FromCy
,1); EXPECTI8(1);
2286 CONVERT_CY(VarI8FromCy
,127); EXPECTI8(127);
2288 CONVERT_CY(VarI8FromCy
,-1.5); EXPECTI8(-2);
2289 CONVERT_CY(VarI8FromCy
,-0.6); EXPECTI8(-1);
2290 CONVERT_CY(VarI8FromCy
,-0.5); EXPECTI8(-1);
2291 CONVERT_CY(VarI8FromCy
,-0.4); EXPECTI8(-1);
2292 CONVERT_CY(VarI8FromCy
,0.4); EXPECTI8(0);
2293 CONVERT_CY(VarI8FromCy
,0.5); EXPECTI8(0);
2294 CONVERT_CY(VarI8FromCy
,0.6); EXPECTI8(1);
2295 CONVERT_CY(VarI8FromCy
,1.5); EXPECTI8(2);
2298 static void test_VarI8FromDec(void)
2302 CHECKPTR(VarI8FromDec
);
2304 CONVERT_BADDEC(VarI8FromDec
);
2306 CONVERT_DEC(VarI8FromDec
,0,0x80,0,128); EXPECTI8(-128);
2307 CONVERT_DEC(VarI8FromDec
,0,0x80,0,1); EXPECTI8(-1);
2308 CONVERT_DEC(VarI8FromDec
,0,0,0,0); EXPECTI8(0);
2309 CONVERT_DEC(VarI8FromDec
,0,0,0,1); EXPECTI8(1);
2310 CONVERT_DEC(VarI8FromDec
,0,0,0,127); EXPECTI8(127);
2312 CONVERT_DEC(VarI8FromDec
,2,0x80,0,12700); EXPECTI8(-127);
2313 CONVERT_DEC(VarI8FromDec
,2,0,0,12700); EXPECTI8(127);
2316 static void test_VarI8FromStr(void)
2321 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
2323 CHECKPTR(VarI8FromStr
);
2325 CONVERT_STR(VarI8FromStr
,NULL
,0); EXPECT_MISMATCH
;
2326 CONVERT_STR(VarI8FromStr
,"0",0); EXPECTI8(0);
2327 CONVERT_STR(VarI8FromStr
,"-1",0); EXPECTI8(-1);
2328 CONVERT_STR(VarI8FromStr
,"2147483647",0); EXPECTI8(2147483647);
2330 CONVERT_STR(VarI8FromStr
,"-1.5",0); EXPECTI8(-2);
2331 CONVERT_STR(VarI8FromStr
,"-0.6",0); EXPECTI8(-1);
2332 CONVERT_STR(VarI8FromStr
,"-0.5",0); EXPECTI8(0);
2333 CONVERT_STR(VarI8FromStr
,"-0.4",0); EXPECTI8(0);
2334 CONVERT_STR(VarI8FromStr
,"0.4",0); EXPECTI8(0);
2335 CONVERT_STR(VarI8FromStr
,"0.5",0); EXPECTI8(0);
2336 CONVERT_STR(VarI8FromStr
,"0.6",0); EXPECTI8(1);
2337 CONVERT_STR(VarI8FromStr
,"1.5",0); EXPECTI8(2);
2340 static void test_VarI8Copy(void)
2342 if (!HAVE_OLEAUT32_I8
)
2345 COPYTEST(1, VT_I8
, ((int)V_I8(&vSrc
)), ((int)V_I8(&vDst
)), V_I8REF(&vSrc
), V_I8REF(&vDst
), "%d");
2348 static void test_VarI8ChangeTypeEx(void)
2350 CONVVARS(CONV_TYPE
);
2351 VARIANTARG vSrc
, vDst
;
2353 if (!HAVE_OLEAUT32_I8
)
2358 INITIAL_TYPETESTI8(VT_I8
, V_I8
);
2362 /* Adapt the test macros to UI8 */
2364 #define CONV_TYPE ULONG64
2366 static void test_VarUI8FromI1(void)
2368 CONVVARS(signed char);
2371 CHECKPTR(VarUI8FromI1
);
2372 for (i
= -128; i
< 128; i
++)
2374 CONVERT(VarUI8FromI1
,i
);
2382 static void test_VarUI8FromUI1(void)
2387 CHECKPTR(VarUI8FromUI1
);
2388 for (i
= 0; i
< 256; i
++)
2390 CONVERT(VarUI8FromUI1
,i
); EXPECTI8(i
);
2394 static void test_VarUI8FromI2(void)
2399 CHECKPTR(VarUI8FromI2
);
2400 for (i
= -32768; i
< 32768; i
++)
2402 CONVERT(VarUI8FromI2
,i
);
2410 static void test_VarUI8FromUI2(void)
2415 CHECKPTR(VarUI8FromUI2
);
2416 for (i
= 0; i
< 65535; i
++)
2418 CONVERT(VarUI8FromUI2
,i
); EXPECTI8(i
);
2422 static void test_VarUI8FromUI4(void)
2426 CHECKPTR(VarUI8FromUI4
);
2427 CONVERT(VarUI8FromUI4
, 0); EXPECTI8(0);
2428 CONVERT(VarUI8FromUI4
, 0xffffffff); EXPECTI8(0xffffffff);
2431 static void test_VarUI8FromR4(void)
2435 CHECKPTR(VarUI8FromR4
);
2436 CONVERT(VarUI8FromR4
, -1.0f
); EXPECT_OVERFLOW
;
2437 CONVERT(VarUI8FromR4
, 0.0f
); EXPECTI8(0);
2438 CONVERT(VarUI8FromR4
, 1.0f
); EXPECTI8(1);
2439 CONVERT(VarUI8FromR4
, 255.0f
); EXPECTI8(255);
2441 CONVERT(VarUI8FromR4
, -1.5f
); EXPECT_OVERFLOW
;
2442 CONVERT(VarUI8FromR4
, -0.6f
); EXPECT_OVERFLOW
;
2443 CONVERT(VarUI8FromR4
, -0.5f
); EXPECTI8(0);
2444 CONVERT(VarUI8FromR4
, -0.4f
); EXPECTI8(0);
2445 CONVERT(VarUI8FromR4
, 0.4f
); EXPECTI8(0);
2446 CONVERT(VarUI8FromR4
, 0.5f
); EXPECTI8(0);
2447 CONVERT(VarUI8FromR4
, 0.6f
); EXPECTI8(1);
2448 CONVERT(VarUI8FromR4
, 1.5f
); EXPECTI8(2);
2451 static void test_VarUI8FromR8(void)
2455 CHECKPTR(VarUI8FromR8
);
2456 CONVERT(VarUI8FromR8
, -1.0); EXPECT_OVERFLOW
;
2457 CONVERT(VarUI8FromR8
, 0.0); EXPECTI8(0);
2458 CONVERT(VarUI8FromR8
, 1.0); EXPECTI8(1);
2459 CONVERT(VarUI8FromR8
, 255.0); EXPECTI8(255);
2461 CONVERT(VarUI8FromR8
, -1.5); EXPECT_OVERFLOW
;
2462 CONVERT(VarUI8FromR8
, -0.6); EXPECT_OVERFLOW
;
2463 CONVERT(VarUI8FromR8
, -0.5); EXPECTI8(0);
2464 CONVERT(VarUI8FromR8
, -0.4); EXPECTI8(0);
2465 CONVERT(VarUI8FromR8
, 0.4); EXPECTI8(0);
2466 CONVERT(VarUI8FromR8
, 0.5); EXPECTI8(0);
2467 CONVERT(VarUI8FromR8
, 0.6); EXPECTI8(1);
2468 CONVERT(VarUI8FromR8
, 1.5); EXPECTI8(2);
2471 static void test_VarUI8FromDate(void)
2475 CHECKPTR(VarUI8FromDate
);
2476 CONVERT(VarUI8FromDate
, -1.0); EXPECT_OVERFLOW
;
2477 CONVERT(VarUI8FromDate
, 0.0); EXPECTI8(0);
2478 CONVERT(VarUI8FromDate
, 1.0); EXPECTI8(1);
2479 CONVERT(VarUI8FromDate
, 255.0); EXPECTI8(255);
2481 CONVERT(VarUI8FromDate
, -1.5); EXPECT_OVERFLOW
;
2482 CONVERT(VarUI8FromDate
, -0.6); EXPECT_OVERFLOW
;
2483 CONVERT(VarUI8FromDate
, -0.5); EXPECTI8(0);
2484 CONVERT(VarUI8FromDate
, -0.4); EXPECTI8(0);
2485 CONVERT(VarUI8FromDate
, 0.4); EXPECTI8(0);
2486 CONVERT(VarUI8FromDate
, 0.5); EXPECTI8(0);
2487 CONVERT(VarUI8FromDate
, 0.6); EXPECTI8(1);
2488 CONVERT(VarUI8FromDate
, 1.5); EXPECTI8(2);
2491 static void test_VarUI8FromBool(void)
2493 CONVVARS(VARIANT_BOOL
);
2496 CHECKPTR(VarUI8FromBool
);
2497 CONVERTRANGE(VarUI8FromBool
, -32768, 32768);
2500 static void test_VarUI8FromI8(void)
2504 CHECKPTR(VarUI8FromI8
);
2505 CONVERT(VarUI8FromI8
, -1); EXPECT_OVERFLOW
;
2506 CONVERT(VarUI8FromI8
, 0); EXPECTI8(0);
2507 CONVERT(VarUI8FromI8
, 1); EXPECTI8(1);
2510 static void test_VarUI8FromCy(void)
2514 CHECKPTR(VarUI8FromCy
);
2515 CONVERT_CY(VarUI8FromCy
,-1); EXPECT_OVERFLOW
;
2516 CONVERT_CY(VarUI8FromCy
,0); EXPECTI8(0);
2517 CONVERT_CY(VarUI8FromCy
,1); EXPECTI8(1);
2518 CONVERT_CY(VarUI8FromCy
,255); EXPECTI8(255);
2520 CONVERT_CY(VarUI8FromCy
,-1.5); EXPECT_OVERFLOW
;
2521 CONVERT_CY(VarUI8FromCy
,-0.6); EXPECT_OVERFLOW
;
2522 CONVERT_CY(VarUI8FromCy
,-0.5); EXPECTI8(0);
2523 CONVERT_CY(VarUI8FromCy
,-0.4); EXPECTI8(0);
2524 CONVERT_CY(VarUI8FromCy
,0.4); EXPECTI8(0);
2525 CONVERT_CY(VarUI8FromCy
,0.5); EXPECTI8(0);
2526 CONVERT_CY(VarUI8FromCy
,0.6); EXPECTI8(1);
2527 CONVERT_CY(VarUI8FromCy
,1.5); EXPECTI8(2);
2530 static void test_VarUI8FromDec(void)
2534 CHECKPTR(VarUI8FromDec
);
2536 CONVERT_BADDEC(VarUI8FromDec
);
2539 /* This returns 1 under native; Wine fixes this bug and returns overflow */
2540 CONVERT_DEC(VarUI8FromDec
,0,0x80,0,1);
2542 CONVERT_DEC(VarUI8FromDec
,0,0,0,0); EXPECTI8(0);
2543 CONVERT_DEC(VarUI8FromDec
,0,0,0,1); EXPECTI8(1);
2544 CONVERT_DEC(VarUI8FromDec
,0,0,0,255); EXPECTI8(255);
2546 CONVERT_DEC(VarUI8FromDec
,2,0x80,0,100); EXPECT_OVERFLOW
;
2547 CONVERT_DEC(VarUI8FromDec
,2,0,0,25500); EXPECTI8(255);
2550 static void test_VarUI8FromStr(void)
2555 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
2557 CHECKPTR(VarUI8FromStr
);
2559 CONVERT_STR(VarUI8FromStr
,NULL
,0); EXPECT_MISMATCH
;
2560 CONVERT_STR(VarUI8FromStr
,"0",0); EXPECTI8(0);
2561 CONVERT_STR(VarUI8FromStr
,"-1",0); EXPECT_OVERFLOW
;
2562 CONVERT_STR(VarUI8FromStr
,"2147483647",0); EXPECTI8(2147483647);
2564 CONVERT_STR(VarUI8FromStr
,"-1.5",0); EXPECT_OVERFLOW
;
2565 CONVERT_STR(VarUI8FromStr
,"-0.6",0); EXPECT_OVERFLOW
;
2566 CONVERT_STR(VarUI8FromStr
,"-0.5",0); EXPECTI8(0);
2567 CONVERT_STR(VarUI8FromStr
,"-0.4",0); EXPECTI8(0);
2568 CONVERT_STR(VarUI8FromStr
,"0.4",0); EXPECTI8(0);
2569 CONVERT_STR(VarUI8FromStr
,"0.5",0); EXPECTI8(0);
2570 CONVERT_STR(VarUI8FromStr
,"0.6",0); EXPECTI8(1);
2571 CONVERT_STR(VarUI8FromStr
,"1.5",0); EXPECTI8(2);
2574 static void test_VarUI8Copy(void)
2576 if (!HAVE_OLEAUT32_I8
)
2579 COPYTEST(1, VT_UI8
, ((unsigned)V_UI8(&vSrc
)), ((unsigned)V_I8(&vDst
)),
2580 V_UI8REF(&vSrc
), V_UI8REF(&vDst
), "%u");
2583 static void test_VarUI8ChangeTypeEx(void)
2585 CONVVARS(CONV_TYPE
);
2586 VARIANTARG vSrc
, vDst
;
2588 if (!HAVE_OLEAUT32_I8
)
2593 INITIAL_TYPETESTI8(VT_UI8
, V_UI8
);
2602 #define CONV_TYPE float
2604 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%15.15f")
2606 static void test_VarR4FromI1(void)
2608 CONVVARS(signed char);
2611 CHECKPTR(VarR4FromI1
);
2612 CONVERTRANGE(VarR4FromI1
, -128, 128);
2615 static void test_VarR4FromUI1(void)
2620 CHECKPTR(VarR4FromUI1
);
2621 CONVERTRANGE(VarR4FromUI1
, 0, 256);
2624 static void test_VarR4FromI2(void)
2629 CHECKPTR(VarR4FromI2
);
2630 CONVERTRANGE(VarR4FromI2
, -32768, 32768);
2633 static void test_VarR4FromUI2(void)
2638 CHECKPTR(VarR4FromUI2
);
2639 CONVERTRANGE(VarR4FromUI2
, 0, 65536);
2642 static void test_VarR4FromI4(void)
2646 CHECKPTR(VarR4FromI4
);
2647 CONVERT(VarR4FromI4
, -2147483647-1); EXPECT(-2147483648.0f
);
2648 CONVERT(VarR4FromI4
, -1); EXPECT(-1.0f
);
2649 CONVERT(VarR4FromI4
, 0); EXPECT(0.0f
);
2650 CONVERT(VarR4FromI4
, 1); EXPECT(1.0f
);
2651 CONVERT(VarR4FromI4
, 2147483647); EXPECT(2147483647.0f
);
2654 static void test_VarR4FromUI4(void)
2656 CONVVARS(unsigned int);
2658 CHECKPTR(VarR4FromUI4
);
2659 CONVERT(VarR4FromUI4
, 0); EXPECT(0.0f
);
2660 CONVERT(VarR4FromUI4
, 1); EXPECT(1.0f
);
2661 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
2662 CONVERT(VarR4FromUI4
, 0xffffffff); EXPECT(4294967296.0f
);
2666 static void test_VarR4FromR8(void)
2670 CHECKPTR(VarR4FromR8
);
2671 CONVERT(VarR4FromR8
, -1.0); EXPECT(-1.0f
);
2672 CONVERT(VarR4FromR8
, 0.0); EXPECT(0.0f
);
2673 CONVERT(VarR4FromR8
, 1.0); EXPECT(1.0f
);
2674 CONVERT(VarR4FromR8
, 1.5); EXPECT(1.5f
);
2676 /* Skip rounding tests - no rounding is done */
2679 static void test_VarR4FromBool(void)
2681 CONVVARS(VARIANT_BOOL
);
2683 CHECKPTR(VarR4FromBool
);
2684 CONVERT(VarR4FromBool
, VARIANT_TRUE
); EXPECT(VARIANT_TRUE
* 1.0f
);
2685 CONVERT(VarR4FromBool
, VARIANT_FALSE
); EXPECT(VARIANT_FALSE
* 1.0f
);
2688 static void test_VarR4FromCy(void)
2692 CHECKPTR(VarR4FromCy
);
2693 CONVERT_CY(VarR4FromCy
,-32768); EXPECT(-32768.0f
);
2694 CONVERT_CY(VarR4FromCy
,-1); EXPECT(-1.0f
);
2695 CONVERT_CY(VarR4FromCy
,0); EXPECT(0.0f
);
2696 CONVERT_CY(VarR4FromCy
,1); EXPECT(1.0f
);
2697 CONVERT_CY(VarR4FromCy
,32768); EXPECT(32768.0f
);
2699 CONVERT_CY(VarR4FromCy
,-1.5); EXPECT(-1.5f
);
2700 CONVERT_CY(VarR4FromCy
,-0.6); EXPECT(-0.6f
);
2701 CONVERT_CY(VarR4FromCy
,-0.5); EXPECT(-0.5f
);
2702 CONVERT_CY(VarR4FromCy
,-0.4); EXPECT(-0.4f
);
2703 CONVERT_CY(VarR4FromCy
,0.4); EXPECT(0.4f
);
2704 CONVERT_CY(VarR4FromCy
,0.5); EXPECT(0.5f
);
2705 CONVERT_CY(VarR4FromCy
,0.6); EXPECT(0.6f
);
2706 CONVERT_CY(VarR4FromCy
,1.5); EXPECT(1.5f
);
2709 static void test_VarR4FromI8(void)
2713 CHECKPTR(VarR4FromI8
);
2714 CONVERT(VarR4FromI8
, -1); EXPECT(-1.0f
);
2715 CONVERT(VarR4FromI8
, 0); EXPECT(0.0f
);
2716 CONVERT(VarR4FromI8
, 1); EXPECT(1.0f
);
2719 static void test_VarR4FromUI8(void)
2723 CHECKPTR(VarR4FromUI8
);
2724 CONVERT(VarR4FromUI8
, 0); EXPECT(0.0f
);
2725 CONVERT(VarR4FromUI8
, 1); EXPECT(1.0f
);
2728 static void test_VarR4FromDec(void)
2732 CHECKPTR(VarR4FromDec
);
2734 CONVERT_BADDEC(VarR4FromDec
);
2736 CONVERT_DEC(VarR4FromDec
,0,0x80,0,32768); EXPECT(-32768.0f
);
2737 CONVERT_DEC(VarR4FromDec
,0,0x80,0,1); EXPECT(-1.0f
);
2738 CONVERT_DEC(VarR4FromDec
,0,0,0,0); EXPECT(0.0f
);
2739 CONVERT_DEC(VarR4FromDec
,0,0,0,1); EXPECT(1.0f
);
2740 CONVERT_DEC(VarR4FromDec
,0,0,0,32767); EXPECT(32767.0f
);
2742 CONVERT_DEC(VarR4FromDec
,2,0x80,0,3276800); EXPECT(-32768.0f
);
2743 CONVERT_DEC(VarR4FromDec
,2,0,0,3276700); EXPECT(32767.0f
);
2746 static void test_VarR4FromDate(void)
2750 CHECKPTR(VarR4FromDate
);
2751 CONVERT(VarR4FromDate
, -1.0); EXPECT(-1.0f
);
2752 CONVERT(VarR4FromDate
, 0.0); EXPECT(0.0f
);
2753 CONVERT(VarR4FromDate
, 1.0); EXPECT(1.0f
);
2756 static void test_VarR4FromStr(void)
2761 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
2763 CHECKPTR(VarR4FromStr
);
2765 CONVERT_STR(VarR4FromStr
,NULL
,0); EXPECT_MISMATCH
;
2766 CONVERT_STR(VarR4FromStr
,"-1", 0); EXPECT(-1.0f
);
2767 CONVERT_STR(VarR4FromStr
,"0", 0); EXPECT(0.0f
);
2768 CONVERT_STR(VarR4FromStr
,"1", 0); EXPECT(1.0f
);
2770 CONVERT_STR(VarR4FromStr
,"-1.5",0); EXPECT(-1.5f
);
2771 CONVERT_STR(VarR4FromStr
,"-0.6",0); EXPECT(-0.6f
);
2772 CONVERT_STR(VarR4FromStr
,"-0.5",0); EXPECT(-0.5f
);
2773 CONVERT_STR(VarR4FromStr
,"-0.4",0); EXPECT(-0.4f
);
2774 CONVERT_STR(VarR4FromStr
,"0.4",0); EXPECT(0.4f
);
2775 CONVERT_STR(VarR4FromStr
,"0.5",0); EXPECT(0.5f
);
2776 CONVERT_STR(VarR4FromStr
,"0.6",0); EXPECT(0.6f
);
2777 CONVERT_STR(VarR4FromStr
,"1.5",0); EXPECT(1.5f
);
2780 static void test_VarR4Copy(void)
2782 COPYTEST(77665544.0f
, VT_R4
, V_R4(&vSrc
), V_R4(&vDst
), V_R4REF(&vSrc
),V_R4REF(&vDst
), "%15.15f");
2785 static void test_VarR4ChangeTypeEx(void)
2787 #ifdef HAS_UINT64_TO_FLOAT
2788 CONVVARS(CONV_TYPE
);
2789 VARIANTARG vSrc
, vDst
;
2793 INITIAL_TYPETEST(VT_R4
, V_R4
, "%f");
2803 #define CONV_TYPE double
2805 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%15.15f")
2807 static void test_VarR8FromI1(void)
2809 CONVVARS(signed char);
2812 CHECKPTR(VarR8FromI1
);
2813 CONVERTRANGE(VarR8FromI1
, -128, 128);
2816 static void test_VarR8FromUI1(void)
2821 CHECKPTR(VarR8FromUI1
);
2822 CONVERTRANGE(VarR8FromUI1
, 0, 256);
2825 static void test_VarR8FromI2(void)
2830 CHECKPTR(VarR8FromI2
);
2831 CONVERTRANGE(VarR8FromI2
, -32768, 32768);
2834 static void test_VarR8FromUI2(void)
2839 CHECKPTR(VarR8FromUI2
);
2840 CONVERTRANGE(VarR8FromUI2
, 0, 65536);
2843 static void test_VarR8FromI4(void)
2847 CHECKPTR(VarR8FromI4
);
2848 CONVERT(VarR8FromI4
, -2147483647-1); EXPECT(-2147483648.0);
2849 CONVERT(VarR8FromI4
, -1); EXPECT(-1.0);
2850 CONVERT(VarR8FromI4
, 0); EXPECT(0.0);
2851 CONVERT(VarR8FromI4
, 1); EXPECT(1.0);
2852 CONVERT(VarR8FromI4
, 0x7fffffff); EXPECT(2147483647.0);
2855 static void test_VarR8FromUI4(void)
2857 CONVVARS(unsigned int);
2859 CHECKPTR(VarR8FromUI4
);
2860 CONVERT(VarR8FromUI4
, 0); EXPECT(0.0);
2861 CONVERT(VarR8FromUI4
, 1); EXPECT(1.0);
2862 CONVERT(VarR8FromUI4
, 0xffffffff); EXPECT(4294967295.0);
2865 static void test_VarR8FromR4(void)
2869 CHECKPTR(VarR8FromR4
);
2870 CONVERT(VarR8FromR4
, -1.0f
); EXPECT(-1.0);
2871 CONVERT(VarR8FromR4
, 0.0f
); EXPECT(0.0);
2872 CONVERT(VarR8FromR4
, 1.0f
); EXPECT(1.0);
2873 CONVERT(VarR8FromR4
, 1.5f
); EXPECT(1.5);
2875 /* Skip rounding tests - no rounding is done */
2878 static void test_VarR8FromBool(void)
2880 CONVVARS(VARIANT_BOOL
);
2882 CHECKPTR(VarR8FromBool
);
2883 CONVERT(VarR8FromBool
, VARIANT_TRUE
); EXPECT(VARIANT_TRUE
* 1.0);
2884 CONVERT(VarR8FromBool
, VARIANT_FALSE
); EXPECT(VARIANT_FALSE
* 1.0);
2887 static void test_VarR8FromCy(void)
2891 CHECKPTR(VarR8FromCy
);
2892 CONVERT_CY(VarR8FromCy
,-32769); EXPECT(-32769.0);
2893 CONVERT_CY(VarR8FromCy
,-32768); EXPECT(-32768.0);
2894 CONVERT_CY(VarR8FromCy
,-1); EXPECT(-1.0);
2895 CONVERT_CY(VarR8FromCy
,0); EXPECT(0.0);
2896 CONVERT_CY(VarR8FromCy
,1); EXPECT(1.0);
2897 CONVERT_CY(VarR8FromCy
,32767); EXPECT(32767.0);
2898 CONVERT_CY(VarR8FromCy
,32768); EXPECT(32768.0);
2900 CONVERT_CY(VarR8FromCy
,-1.5); EXPECT(-1.5);
2901 CONVERT_CY(VarR8FromCy
,-0.6); EXPECT(-0.6);
2902 CONVERT_CY(VarR8FromCy
,-0.5); EXPECT(-0.5);
2903 CONVERT_CY(VarR8FromCy
,-0.4); EXPECT(-0.4);
2904 CONVERT_CY(VarR8FromCy
,0.4); EXPECT(0.4);
2905 CONVERT_CY(VarR8FromCy
,0.5); EXPECT(0.5);
2906 CONVERT_CY(VarR8FromCy
,0.6); EXPECT(0.6);
2907 CONVERT_CY(VarR8FromCy
,1.5); EXPECT(1.5);
2910 static void test_VarR8FromI8(void)
2914 CHECKPTR(VarR8FromI8
);
2915 CONVERT(VarR8FromI8
, -1); EXPECT(-1.0);
2916 CONVERT(VarR8FromI8
, 0); EXPECT(0.0);
2917 CONVERT(VarR8FromI8
, 1); EXPECT(1.0);
2918 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
2919 CONVERT_I8(VarR8FromI8
, 0x7fffffff,0xffffffff); EXPECT(9223372036854775808.0);
2923 static void test_VarR8FromUI8(void)
2927 CHECKPTR(VarR8FromUI8
);
2928 CONVERT(VarR8FromUI8
, 0); EXPECT(0.0);
2929 CONVERT(VarR8FromUI8
, 1); EXPECT(1.0);
2930 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
2931 CONVERT_I8(VarR8FromUI8
, 0x80000000,0); EXPECT(9223372036854775808.0);
2935 static void test_VarR8FromDec(void)
2939 CHECKPTR(VarR8FromDec
);
2941 CONVERT_BADDEC(VarR8FromDec
);
2943 CONVERT_DEC(VarR8FromDec
,0,0x80,0,32768); EXPECT(-32768.0);
2944 CONVERT_DEC(VarR8FromDec
,0,0x80,0,1); EXPECT(-1.0);
2945 CONVERT_DEC(VarR8FromDec
,0,0,0,0); EXPECT(0.0);
2946 CONVERT_DEC(VarR8FromDec
,0,0,0,1); EXPECT(1.0);
2947 CONVERT_DEC(VarR8FromDec
,0,0,0,32767); EXPECT(32767.0);
2949 CONVERT_DEC(VarR8FromDec
,2,0x80,0,3276800); EXPECT(-32768.0);
2950 CONVERT_DEC(VarR8FromDec
,2,0,0,3276700); EXPECT(32767.0);
2953 static void test_VarR8FromDate(void)
2957 CHECKPTR(VarR8FromDate
);
2958 CONVERT(VarR8FromDate
, -1.0); EXPECT(-1.0);
2959 CONVERT(VarR8FromDate
, -0.0); EXPECT(0.0);
2960 CONVERT(VarR8FromDate
, 1.0); EXPECT(1.0);
2963 static void test_VarR8FromStr(void)
2968 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
2970 CHECKPTR(VarR8FromStr
);
2972 CONVERT_STR(VarR8FromStr
,NULL
,0); EXPECT_MISMATCH
;
2973 CONVERT_STR(VarR8FromStr
,"",0); EXPECT_MISMATCH
;
2974 CONVERT_STR(VarR8FromStr
," ",0); EXPECT_MISMATCH
;
2976 CONVERT_STR(VarR8FromStr
,"0",0); EXPECT(0.0);
2977 CONVERT_STR(VarR8FromStr
,"-1.5",0); EXPECT(-1.5);
2978 CONVERT_STR(VarR8FromStr
,"-0.6",0); EXPECT(-0.6);
2979 CONVERT_STR(VarR8FromStr
,"-0.5",0); EXPECT(-0.5);
2980 CONVERT_STR(VarR8FromStr
,"-0.4",0); EXPECT(-0.4);
2981 CONVERT_STR(VarR8FromStr
,"0.4",0); EXPECT(0.4);
2982 CONVERT_STR(VarR8FromStr
,"0.5",0); EXPECT(0.5);
2983 CONVERT_STR(VarR8FromStr
,"0.6",0); EXPECT(0.6);
2984 CONVERT_STR(VarR8FromStr
,"1.5",0); EXPECT(1.5);
2986 /* We already have exhaustive tests for number parsing, so skip those tests here */
2989 static void test_VarR8Copy(void)
2991 COPYTEST(77665544.0, VT_R8
, V_R8(&vSrc
), V_R8(&vDst
), V_R8REF(&vSrc
),V_R8REF(&vDst
), "%16.16g");
2994 static void test_VarR8ChangeTypeEx(void)
2996 #ifdef HAS_UINT64_TO_FLOAT
2997 CONVVARS(CONV_TYPE
);
2998 VARIANTARG vSrc
, vDst
;
3002 INITIAL_TYPETEST(VT_R8
, V_R8
, "%g");
3007 #define MATHRND(l, r) left = l; right = r; hres = pVarR8Round(left, right, &out)
3009 static void test_VarR8Round(void)
3012 double left
= 0.0, out
;
3015 CHECKPTR(VarR8Round
);
3016 MATHRND(0.5432, 5); EXPECT(0.5432);
3017 MATHRND(0.5432, 4); EXPECT(0.5432);
3018 MATHRND(0.5432, 3); EXPECT(0.543);
3019 MATHRND(0.5432, 2); EXPECT(0.54);
3020 MATHRND(0.5432, 1); EXPECT(0.5);
3021 MATHRND(0.5532, 0); EXPECT(1);
3022 MATHRND(0.5532, -1); EXPECT_INVALID
;
3024 MATHRND(0.5568, 5); EXPECT(0.5568);
3025 MATHRND(0.5568, 4); EXPECT(0.5568);
3026 MATHRND(0.5568, 3); EXPECT(0.557);
3027 MATHRND(0.5568, 2); EXPECT(0.56);
3028 MATHRND(0.5568, 1); EXPECT(0.6);
3029 MATHRND(0.5568, 0); EXPECT(1);
3030 MATHRND(0.5568, -1); EXPECT_INVALID
;
3032 MATHRND(0.4999, 0); EXPECT(0);
3033 MATHRND(0.5000, 0); EXPECT(0);
3034 MATHRND(0.5001, 0); EXPECT(1);
3035 MATHRND(1.4999, 0); EXPECT(1);
3036 MATHRND(1.5000, 0); EXPECT(2);
3037 MATHRND(1.5001, 0); EXPECT(2);
3045 #define CONV_TYPE DATE
3047 static void test_VarDateFromI1(void)
3049 CONVVARS(signed char);
3052 CHECKPTR(VarDateFromI1
);
3053 CONVERTRANGE(VarDateFromI1
, -128, 128);
3056 static void test_VarDateFromUI1(void)
3061 CHECKPTR(VarDateFromUI1
);
3062 CONVERTRANGE(VarDateFromUI1
, 0, 256);
3065 static void test_VarDateFromI2(void)
3070 CHECKPTR(VarDateFromI2
);
3071 CONVERTRANGE(VarDateFromI2
, -32768, 32768);
3074 static void test_VarDateFromUI2(void)
3079 CHECKPTR(VarDateFromUI2
);
3080 CONVERTRANGE(VarDateFromUI2
, 0, 65536);
3083 static void test_VarDateFromI4(void)
3087 CHECKPTR(VarDateFromI4
);
3088 CONVERT(VarDateFromI4
, DATE_MIN
-1);
3089 if (hres
!= DISP_E_TYPEMISMATCH
) /* Early versions return this, incorrectly */
3091 CONVERT(VarDateFromI4
, DATE_MIN
); EXPECT(DATE_MIN
);
3092 CONVERT(VarDateFromI4
, -1); EXPECT(-1.0);
3093 CONVERT(VarDateFromI4
, 0); EXPECT(0.0);
3094 CONVERT(VarDateFromI4
, 1); EXPECT(1.0);
3095 CONVERT(VarDateFromI4
, DATE_MAX
); EXPECT(DATE_MAX
);
3096 CONVERT(VarDateFromI4
, DATE_MAX
+1);
3097 if (hres
!= DISP_E_TYPEMISMATCH
) /* Early versions return this, incorrectly */
3101 static void test_VarDateFromUI4(void)
3103 CONVVARS(unsigned int);
3105 CHECKPTR(VarDateFromUI4
);
3106 CONVERT(VarDateFromUI4
, 0); EXPECT(0.0);
3107 CONVERT(VarDateFromUI4
, 1); EXPECT(1.0);
3108 CONVERT(VarDateFromUI4
, DATE_MAX
); EXPECT(DATE_MAX
);
3109 CONVERT(VarDateFromUI4
, DATE_MAX
+1);
3110 if (hres
!= DISP_E_TYPEMISMATCH
) /* Early versions return this, incorrectly */
3114 static void test_VarDateFromR4(void)
3118 CHECKPTR(VarDateFromR4
);
3119 CONVERT(VarDateFromR4
, -1.0f
); EXPECT(-1.0);
3120 CONVERT(VarDateFromR4
, 0.0f
); EXPECT(0.0);
3121 CONVERT(VarDateFromR4
, 1.0f
); EXPECT(1.0);
3122 CONVERT(VarDateFromR4
, 1.5f
); EXPECT(1.5);
3125 static void test_VarDateFromR8(void)
3129 CHECKPTR(VarDateFromR8
);
3130 CONVERT(VarDateFromR8
, -1.0f
); EXPECT(-1.0);
3131 CONVERT(VarDateFromR8
, 0.0f
); EXPECT(0.0);
3132 CONVERT(VarDateFromR8
, 1.0f
); EXPECT(1.0);
3133 CONVERT(VarDateFromR8
, 1.5f
); EXPECT(1.5);
3136 static void test_VarDateFromBool(void)
3138 CONVVARS(VARIANT_BOOL
);
3140 CHECKPTR(VarDateFromBool
);
3141 CONVERT(VarDateFromBool
, VARIANT_TRUE
); EXPECT(VARIANT_TRUE
* 1.0);
3142 CONVERT(VarDateFromBool
, VARIANT_FALSE
); EXPECT(VARIANT_FALSE
* 1.0);
3145 static void test_VarDateFromCy(void)
3149 CHECKPTR(VarDateFromCy
);
3150 CONVERT_CY(VarDateFromCy
,-32769); EXPECT(-32769.0);
3151 CONVERT_CY(VarDateFromCy
,-32768); EXPECT(-32768.0);
3152 CONVERT_CY(VarDateFromCy
,-1); EXPECT(-1.0);
3153 CONVERT_CY(VarDateFromCy
,0); EXPECT(0.0);
3154 CONVERT_CY(VarDateFromCy
,1); EXPECT(1.0);
3155 CONVERT_CY(VarDateFromCy
,32767); EXPECT(32767.0);
3156 CONVERT_CY(VarDateFromCy
,32768); EXPECT(32768.0);
3158 CONVERT_CY(VarDateFromCy
,-1.5); EXPECT(-1.5);
3159 CONVERT_CY(VarDateFromCy
,-0.6); EXPECT(-0.6);
3160 CONVERT_CY(VarDateFromCy
,-0.5); EXPECT(-0.5);
3161 CONVERT_CY(VarDateFromCy
,-0.4); EXPECT(-0.4);
3162 CONVERT_CY(VarDateFromCy
,0.4); EXPECT(0.4);
3163 CONVERT_CY(VarDateFromCy
,0.5); EXPECT(0.5);
3164 CONVERT_CY(VarDateFromCy
,0.6); EXPECT(0.6);
3165 CONVERT_CY(VarDateFromCy
,1.5); EXPECT(1.5);
3168 static void test_VarDateFromI8(void)
3172 CHECKPTR(VarDateFromI8
);
3173 CONVERT(VarDateFromI8
, DATE_MIN
-1); EXPECT_OVERFLOW
;
3174 CONVERT(VarDateFromI8
, DATE_MIN
); EXPECT(DATE_MIN
);
3175 CONVERT(VarDateFromI8
, -1); EXPECT(-1.0);
3176 CONVERT(VarDateFromI8
, 0); EXPECT(0.0);
3177 CONVERT(VarDateFromI8
, 1); EXPECT(1.0);
3178 CONVERT(VarDateFromI8
, DATE_MAX
); EXPECT(DATE_MAX
);
3179 CONVERT(VarDateFromI8
, DATE_MAX
+1); EXPECT_OVERFLOW
;
3182 static void test_VarDateFromUI8(void)
3186 CHECKPTR(VarDateFromUI8
);
3187 CONVERT(VarDateFromUI8
, 0); EXPECT(0.0);
3188 CONVERT(VarDateFromUI8
, 1); EXPECT(1.0);
3189 CONVERT(VarDateFromUI8
, DATE_MAX
); EXPECT(DATE_MAX
);
3190 CONVERT(VarDateFromUI8
, DATE_MAX
+1); EXPECT_OVERFLOW
;
3193 static void test_VarDateFromDec(void)
3197 CHECKPTR(VarDateFromDec
);
3199 CONVERT_BADDEC(VarDateFromDec
);
3201 CONVERT_DEC(VarDateFromDec
,0,0x80,0,32768); EXPECT(-32768.0);
3202 CONVERT_DEC(VarDateFromDec
,0,0x80,0,1); EXPECT(-1.0);
3203 CONVERT_DEC(VarDateFromDec
,0,0,0,0); EXPECT(0.0);
3204 CONVERT_DEC(VarDateFromDec
,0,0,0,1); EXPECT(1.0);
3205 CONVERT_DEC(VarDateFromDec
,0,0,0,32767); EXPECT(32767.0);
3207 CONVERT_DEC(VarDateFromDec
,2,0x80,0,3276800); EXPECT(-32768.0);
3208 CONVERT_DEC(VarDateFromDec
,2,0,0,3276700); EXPECT(32767.0);
3212 buff[0] = '\0'; out = 0.0; \
3213 if (str) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)); \
3214 hres = pVarDateFromStr(str ? buff : NULL,lcid,LOCALE_NOUSEROVERRIDE,&out)
3216 #define MKRELDATE(day,mth) st.wMonth = mth; st.wDay = day; \
3217 pSystemTimeToVariantTime(&st,&relative)
3219 static const char *BadDateStrings
[] =
3221 "True", "False", /* Plain text */
3222 "0.", ".0", "-1.1", "1.1-", /* Partial specifications */
3223 "1;2;3", "1*2*3", "1@2@3", "1#2#3", "(1:2)","<1:2>","1|2|3", /* Bad chars */
3224 "0", "1", /* 1 element */
3225 "0.60", "24.00", "0:60", "24:00", "1 2 am", "1 am 2", /* 2 elements */
3226 "1.5 2", "1 5.2", "2 32 3", "1 2 am 3", /* 3 elements */
3227 "1 2.3 4", "1.2.3 4", "1 2.3.4", "1.2 3.4", "1.2.3.4", "1 2 3 4",
3228 "1 am 2 3.4", "1 2 am 3.4", "1.2 3 am 4", "1.2 3 4 am", /* 4 elements */
3229 "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",
3230 "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",
3231 "1.2.3 4 am 5", "1.2.3 4 5 am", "1.2 3 am 4 5",
3232 "1.2 3 4 am 5", "1.2 3 4 5 am", "1 am 2 3.4.5", "1 2 am 3.4.5",
3233 "1 am 2 3 4.5", "1 2 am 3 4.5", "1 2 3 am 4.5", /* 5 elements */
3235 "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",
3236 "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",
3237 "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",
3238 "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",
3239 "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",
3240 "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",
3241 "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",
3242 "1 2 am 3 4.5.6", "1 2 3 am 4.5.6"
3245 static void test_VarDateFromStr(void)
3254 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
3256 CHECKPTR(VarDateFromStr
);
3257 CHECKPTR(SystemTimeToVariantTime
);
3259 /* Some date formats are relative, so we need to find the cuurent year */
3261 st
.wHour
= st
.wMinute
= st
.wSecond
= st
.wMilliseconds
= 0;
3262 DFS(NULL
); EXPECT_MISMATCH
;
3264 /* Floating point number are not recognised */
3267 EXPECT_DBL(0.0); /* Very old versions accept this string */
3271 /* 1 element - can only be a time, and only if it has am/pm */
3272 DFS("1 am"); EXPECT_DBL(0.04166666666666666);
3274 /* A decimal point is treated as a time separator.
3275 * The following are converted as hours/minutes.
3277 DFS("0.1"); EXPECT_DBL(0.0006944444444444445);
3278 DFS("0.40"); EXPECT_DBL(0.02777777777777778);
3279 DFS("2.5"); EXPECT_DBL(0.08680555555555555);
3280 /* A colon acts as a decimal point */
3281 DFS("0:1"); EXPECT_DBL(0.0006944444444444445);
3282 DFS("0:20"); EXPECT_DBL(0.01388888888888889);
3283 DFS("0:40"); EXPECT_DBL(0.02777777777777778);
3284 DFS("3:5"); EXPECT_DBL(0.1284722222222222);
3285 /* Check the am/pm limits */
3286 DFS("00:00 AM"); EXPECT_DBL(0.0);
3287 DFS("00:00 a"); EXPECT_DBL(0.0);
3288 DFS("12:59 AM"); EXPECT_DBL(0.04097222222222222);
3289 DFS("12:59 A"); EXPECT_DBL(0.04097222222222222);
3290 DFS("00:00 pm"); EXPECT_DBL(0.5);
3291 DFS("00:00 p"); EXPECT_DBL(0.5);
3292 DFS("12:59 pm"); EXPECT_DBL(0.5409722222222222);
3293 DFS("12:59 p"); EXPECT_DBL(0.5409722222222222);
3294 /* AM/PM is ignored if hours > 12 */
3295 DFS("13:00 AM"); EXPECT_DBL(0.5416666666666666);
3296 DFS("13:00 PM"); EXPECT_DBL(0.5416666666666666);
3298 /* Space, dash and slash all indicate a date format. */
3299 /* If both numbers are valid month values => month/day of current year */
3300 DFS("1 2"); MKRELDATE(2,1); EXPECT_DBL(relative
);
3301 DFS("2 1"); MKRELDATE(1,2); EXPECT_DBL(relative
);
3302 /* one number not valid month, is a valid day, other number valid month:
3303 * that number becomes the day.
3305 DFS("14 1"); MKRELDATE(14,1); EXPECT_DBL(relative
);
3306 DFS("1 14"); EXPECT_DBL(relative
);
3307 /* If the numbers can't be day/month, they are assumed to be year/month */
3308 DFS("30 2"); EXPECT_DBL(10990.0);
3309 DFS("2 30"); EXPECT_DBL(10990.0);
3310 DFS("32 49"); EXPECT_MISMATCH
; /* Can't be any format */
3311 DFS("0 49"); EXPECT_MISMATCH
; /* Can't be any format */
3312 /* If a month name is given the other number is the day */
3313 DFS("Jan 2"); MKRELDATE(2,1); EXPECT_DBL(relative
);
3314 DFS("2 Jan"); EXPECT_DBL(relative
);
3315 /* Unless it can't be, in which case it becomes the year */
3316 DFS("Jan 35"); EXPECT_DBL(12785.0);
3317 DFS("35 Jan"); EXPECT_DBL(12785.0);
3318 DFS("Jan-35"); EXPECT_DBL(12785.0);
3319 DFS("35-Jan"); EXPECT_DBL(12785.0);
3320 DFS("Jan/35"); EXPECT_DBL(12785.0);
3321 DFS("35/Jan"); EXPECT_DBL(12785.0);
3323 /* 3 numbers and time separator => h:m:s */
3324 DFS("0.1.0"); EXPECT_DBL(0.0006944444444444445);
3325 DFS("1.5.2"); EXPECT_DBL(0.04516203703703704);
3326 /* 3 numbers => picks date giving preference to lcid format */
3327 DFS("1 2 3"); EXPECT_DBL(37623.0);
3328 DFS("14 2 3"); EXPECT_DBL(41673.0);
3329 DFS("2 14 3"); EXPECT_DBL(37666.0);
3330 DFS("2 3 14"); EXPECT_DBL(41673.0);
3331 DFS("32 2 3"); EXPECT_DBL(11722.0);
3332 DFS("2 3 32"); EXPECT_DBL(11722.0);
3333 DFS("1 2 29"); EXPECT_DBL(47120.0);
3334 /* After 30, two digit dates are expected to be in the 1900's */
3335 DFS("1 2 30"); EXPECT_DBL(10960.0);
3336 DFS("1 2 31"); EXPECT_DBL(11325.0);
3337 DFS("3 am 1 2"); MKRELDATE(2,1); relative
+= 0.125; EXPECT_DBL(relative
);
3338 DFS("1 2 3 am"); EXPECT_DBL(relative
);
3340 /* 4 elements -interpreted as 2 digit date & time */
3341 DFS("1.2 3 4"); MKRELDATE(4,3); relative
+= 0.04305555556; EXPECT_DBL(relative
);
3342 DFS("3 4 1.2"); EXPECT_DBL(relative
);
3343 /* 5 elements - interpreted as 2 & 3 digit date/times */
3344 DFS("1.2.3 4 5"); MKRELDATE(5,4); relative
+= 0.04309027778; EXPECT_DBL(relative
);
3345 DFS("1.2 3 4 5"); EXPECT_DBL(38415.04305555556);
3346 DFS("1 2 3.4.5"); MKRELDATE(2,1); relative
+= 0.12783564815; EXPECT_DBL(relative
);
3347 DFS("1 2 3 4.5"); EXPECT_DBL(37623.17013888889);
3348 /* 6 elements - interpreted as 3 digit date/times */
3349 DFS("1.2.3 4 5 6"); EXPECT_DBL(38812.04309027778);
3350 DFS("1 2 3 4.5.6"); EXPECT_DBL(37623.17020833334);
3352 for (i
= 0; i
< sizeof(BadDateStrings
)/sizeof(char*); i
++)
3354 DFS(BadDateStrings
[i
]); EXPECT_MISMATCH
;
3357 /* Some normal-ish strings */
3358 DFS("2 January, 1970"); EXPECT_DBL(25570.0);
3359 DFS("2 January 1970"); EXPECT_DBL(25570.0);
3360 DFS("2 Jan 1970"); EXPECT_DBL(25570.0);
3361 DFS("2/Jan/1970"); EXPECT_DBL(25570.0);
3362 DFS("2-Jan-1970"); EXPECT_DBL(25570.0);
3363 DFS("1 2 1970"); EXPECT_DBL(25570.0);
3364 DFS("1/2/1970"); EXPECT_DBL(25570.0);
3365 DFS("1-2-1970"); EXPECT_DBL(25570.0);
3366 /* Native fails "1999 January 3, 9AM". I consider that a bug in native */
3369 static void test_VarDateCopy(void)
3371 COPYTEST(77665544.0, VT_DATE
, V_DATE(&vSrc
), V_DATE(&vDst
), V_DATEREF(&vSrc
),
3372 V_DATEREF(&vDst
), "%16.16g");
3375 static const char* wtoascii(LPWSTR lpszIn
)
3377 static char buff
[256];
3378 WideCharToMultiByte(CP_ACP
, 0, lpszIn
, -1, buff
, sizeof(buff
), NULL
, NULL
);
3382 #define DATE_STR(flags, str) hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, flags, VT_BSTR); \
3383 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && \
3384 V_BSTR(&vDst) && !strcmpW(V_BSTR(&vDst), str), \
3385 "hres=0x%lX, type=%d (should be VT_BSTR), *bstr=%s\n", \
3386 hres, V_VT(&vDst), V_BSTR(&vDst) ? wtoascii(V_BSTR(&vDst)) : "?")
3388 static void test_VarDateChangeTypeEx(void)
3390 static const WCHAR sz25570
[] = {
3391 '1','/','2','/','1','9','7','0','\0' };
3392 static const WCHAR sz25570Nls
[] = {
3393 '1','/','2','/','1','9','7','0',' ','1','2',':','0','0',':','0','0',' ','A','M','\0' };
3394 CONVVARS(CONV_TYPE
);
3395 VARIANTARG vSrc
, vDst
;
3400 #ifdef HAS_UINT64_TO_FLOAT
3401 INITIAL_TYPETEST(VT_DATE
, V_DATE
, "%g");
3405 V_VT(&vDst
) = VT_EMPTY
;
3406 V_VT(&vSrc
) = VT_DATE
;
3407 V_DATE(&vSrc
) = 25570.0;
3408 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
3409 DATE_STR(VARIANT_NOUSEROVERRIDE
, sz25570
);
3411 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
3412 if (HAVE_OLEAUT32_LOCALES
)
3414 DATE_STR(VARIANT_NOUSEROVERRIDE
|VARIANT_USE_NLS
, sz25570Nls
);
3423 #define CONV_TYPE CY
3425 #define EXPECTRES(res, x) \
3426 ok(hres == S_OK || ((HRESULT)res != S_OK && hres == (HRESULT)res), \
3427 "expected hres " #x ", got hres=0x%08lx\n", hres)
3429 #define EXPECTCY(x) \
3430 ok((hres == S_OK && out.int64 == (LONGLONG)(x*CY_MULTIPLIER)), \
3431 "expected " #x "*CY_MULTIPLIER, got (%8lx %8lx); hres=0x%08lx\n", S(out).Hi, S(out).Lo, hres)
3433 #define EXPECTCY64(x,y) \
3434 ok(hres == S_OK && S(out).Hi == (long)x && S(out).Lo == y, \
3435 "expected " #x #y "(%lu,%lu), got (%lu,%lu); hres=0x%08lx\n", \
3436 (ULONG)(x), (ULONG)(y), S(out).Hi, S(out).Lo, hres)
3438 static void test_VarCyFromI1(void)
3440 CONVVARS(signed char);
3443 CHECKPTR(VarCyFromI1
);
3444 for (i
= -128; i
< 128; i
++)
3446 CONVERT(VarCyFromI1
,i
); EXPECTCY(i
);
3450 static void test_VarCyFromUI1(void)
3455 CHECKPTR(VarCyFromUI1
);
3456 for (i
= 0; i
< 256; i
++)
3458 CONVERT(VarCyFromUI1
,i
); EXPECTCY(i
);
3462 static void test_VarCyFromI2(void)
3467 CHECKPTR(VarCyFromI2
);
3468 for (i
= -16384; i
< 16384; i
++)
3470 CONVERT(VarCyFromI2
,i
); EXPECTCY(i
);
3474 static void test_VarCyFromUI2(void)
3479 CHECKPTR(VarCyFromUI2
);
3480 for (i
= 0; i
< 32768; i
++)
3482 CONVERT(VarCyFromUI2
,i
); EXPECTCY(i
);
3486 static void test_VarCyFromI4(void)
3490 CHECKPTR(VarCyFromI4
);
3491 CONVERT(VarCyFromI4
, -1); EXPECTCY(-1);
3492 CONVERT(VarCyFromI4
, 0); EXPECTCY(0);
3493 CONVERT(VarCyFromI4
, 1); EXPECTCY(1);
3494 CONVERT(VarCyFromI4
, 0x7fffffff); EXPECTCY64(0x1387, 0xffffd8f0);
3495 CONVERT(VarCyFromI4
, 0x80000000); EXPECTCY64(0xffffec78, 0);
3498 static void test_VarCyFromUI4(void)
3500 CONVVARS(unsigned int);
3502 CHECKPTR(VarCyFromUI4
);
3503 CONVERT(VarCyFromUI4
, 0); EXPECTCY(0);
3504 CONVERT(VarCyFromUI4
, 1); EXPECTCY(1);
3505 CONVERT(VarCyFromUI4
, 0x80000000); EXPECTCY64(5000, 0);
3508 static void test_VarCyFromR4(void)
3512 CHECKPTR(VarCyFromR4
);
3513 CONVERT(VarCyFromR4
, -1.0f
); EXPECTCY(-1);
3514 CONVERT(VarCyFromR4
, 0.0f
); EXPECTCY(0);
3515 CONVERT(VarCyFromR4
, 1.0f
); EXPECTCY(1);
3516 CONVERT(VarCyFromR4
, 1.5f
); EXPECTCY(1.5);
3518 CONVERT(VarCyFromR4
, -1.5f
); EXPECTCY(-1.5);
3519 CONVERT(VarCyFromR4
, -0.6f
); EXPECTCY(-0.6);
3520 CONVERT(VarCyFromR4
, -0.5f
); EXPECTCY(-0.5);
3521 CONVERT(VarCyFromR4
, -0.4f
); EXPECTCY(-0.4);
3522 CONVERT(VarCyFromR4
, 0.4f
); EXPECTCY(0.4);
3523 CONVERT(VarCyFromR4
, 0.5f
); EXPECTCY(0.5);
3524 CONVERT(VarCyFromR4
, 0.6f
); EXPECTCY(0.6);
3525 CONVERT(VarCyFromR4
, 1.5f
); EXPECTCY(1.5);
3526 CONVERT(VarCyFromR4
, 1.00009f
); EXPECTCY(1.0001);
3527 CONVERT(VarCyFromR4
, -1.00001f
); EXPECTCY(-1);
3528 CONVERT(VarCyFromR4
, -1.00005f
); EXPECTCY(-1);
3529 CONVERT(VarCyFromR4
, -0.00009f
); EXPECTCY(-0.0001);
3530 CONVERT(VarCyFromR4
, -0.00005f
); EXPECTCY(0);
3531 CONVERT(VarCyFromR4
, -0.00001f
); EXPECTCY(0);
3532 CONVERT(VarCyFromR4
, 0.00001f
); EXPECTCY(0);
3533 CONVERT(VarCyFromR4
, 0.00005f
); EXPECTCY(0);
3534 CONVERT(VarCyFromR4
, 0.00009f
); EXPECTCY(0.0001);
3535 CONVERT(VarCyFromR4
, -1.00001f
); EXPECTCY(-1);
3536 CONVERT(VarCyFromR4
, -1.00005f
); EXPECTCY(-1);
3537 CONVERT(VarCyFromR4
, -1.00009f
); EXPECTCY(-1.0001);
3540 static void test_VarCyFromR8(void)
3544 CHECKPTR(VarCyFromR8
);
3546 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3547 /* Test our rounding is exactly the same. This fails if the special x86
3548 * code is taken out of VarCyFromR8.
3550 CONVERT(VarCyFromR8
, -461168601842738.7904); EXPECTCY64(0xbfffffff, 0xffffff23);
3553 CONVERT(VarCyFromR8
, -4611686018427388416.1); EXPECT_OVERFLOW
;
3554 CONVERT(VarCyFromR8
, -1.0); EXPECTCY(-1);
3555 CONVERT(VarCyFromR8
, -0.0); EXPECTCY(0);
3556 CONVERT(VarCyFromR8
, 1.0); EXPECTCY(1);
3557 CONVERT(VarCyFromR8
, 4611686018427387648.0); EXPECT_OVERFLOW
;
3560 CONVERT(VarCyFromR8
, -1.5f
); EXPECTCY(-1.5);
3561 CONVERT(VarCyFromR8
, -0.6f
); EXPECTCY(-0.6);
3562 CONVERT(VarCyFromR8
, -0.5f
); EXPECTCY(-0.5);
3563 CONVERT(VarCyFromR8
, -0.4f
); EXPECTCY(-0.4);
3564 CONVERT(VarCyFromR8
, 0.4f
); EXPECTCY(0.4);
3565 CONVERT(VarCyFromR8
, 0.5f
); EXPECTCY(0.5);
3566 CONVERT(VarCyFromR8
, 0.6f
); EXPECTCY(0.6);
3567 CONVERT(VarCyFromR8
, 1.5f
); EXPECTCY(1.5);
3568 CONVERT(VarCyFromR8
, 1.00009f
); EXPECTCY(1.0001);
3569 CONVERT(VarCyFromR8
, -1.00001f
); EXPECTCY(-1);
3570 CONVERT(VarCyFromR8
, -1.00005f
); EXPECTCY(-1);
3571 CONVERT(VarCyFromR8
, -0.00009f
); EXPECTCY(-0.0001);
3572 CONVERT(VarCyFromR8
, -0.00005f
); EXPECTCY(0);
3573 CONVERT(VarCyFromR8
, -0.00001f
); EXPECTCY(0);
3574 CONVERT(VarCyFromR8
, 0.00001f
); EXPECTCY(0);
3575 CONVERT(VarCyFromR8
, 0.00005f
); EXPECTCY(0);
3576 CONVERT(VarCyFromR8
, 0.00009f
); EXPECTCY(0.0001);
3577 CONVERT(VarCyFromR8
, -1.00001f
); EXPECTCY(-1);
3578 CONVERT(VarCyFromR8
, -1.00005f
); EXPECTCY(-1);
3579 CONVERT(VarCyFromR8
, -1.00009f
); EXPECTCY(-1.0001);
3582 static void test_VarCyFromBool(void)
3584 CONVVARS(VARIANT_BOOL
);
3587 CHECKPTR(VarCyFromBool
);
3588 for (i
= -32768; i
< 32768; i
++)
3590 CONVERT(VarCyFromBool
, i
); EXPECTCY(i
);
3594 static void test_VarCyFromI8(void)
3598 CHECKPTR(VarCyFromI8
);
3599 CONVERT_I8(VarCyFromI8
, -214749, 2728163227ul); EXPECT_OVERFLOW
;
3600 CONVERT_I8(VarCyFromI8
, -214749, 2728163228ul); EXPECTCY64(2147483648ul,15808);
3601 CONVERT(VarCyFromI8
, -1); EXPECTCY(-1);
3602 CONVERT(VarCyFromI8
, 0); EXPECTCY(0);
3603 CONVERT(VarCyFromI8
, 1); EXPECTCY(1);
3604 CONVERT_I8(VarCyFromI8
, 214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3605 CONVERT_I8(VarCyFromI8
, 214748, 1566804069); EXPECT_OVERFLOW
;
3608 static void test_VarCyFromUI8(void)
3612 CHECKPTR(VarCyFromUI8
);
3613 CONVERT(VarCyFromUI8
, 0); EXPECTCY(0);
3614 CONVERT(VarCyFromUI8
, 1); EXPECTCY(1);
3615 CONVERT_I8(VarCyFromUI8
, 214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3616 CONVERT_I8(VarCyFromUI8
, 214748, 1566804069); EXPECT_OVERFLOW
;
3619 static void test_VarCyFromDec(void)
3623 CHECKPTR(VarCyFromDec
);
3625 CONVERT_BADDEC(VarCyFromDec
);
3627 CONVERT_DEC(VarCyFromDec
,0,0x80,0,1); EXPECTCY(-1);
3628 CONVERT_DEC(VarCyFromDec
,0,0,0,0); EXPECTCY(0);
3629 CONVERT_DEC(VarCyFromDec
,0,0,0,1); EXPECTCY(1);
3631 CONVERT_DEC64(VarCyFromDec
,0,0,0,214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3632 CONVERT_DEC64(VarCyFromDec
,0,0,0,214748, 1566804069); EXPECT_OVERFLOW
;
3634 CONVERT_DEC(VarCyFromDec
,2,0,0,100); EXPECTCY(1);
3635 CONVERT_DEC(VarCyFromDec
,2,0x80,0,100); EXPECTCY(-1);
3636 CONVERT_DEC(VarCyFromDec
,2,0x80,0,1); EXPECTCY(-0.01);
3637 CONVERT_DEC(VarCyFromDec
,2,0,0,1); EXPECTCY(0.01);
3638 CONVERT_DEC(VarCyFromDec
,2,0x80,0,1); EXPECTCY(-0.01);
3639 CONVERT_DEC(VarCyFromDec
,2,0,0,999); EXPECTCY(9.99);
3640 CONVERT_DEC(VarCyFromDec
,2,0x80,0,999); EXPECTCY(-9.99);
3641 CONVERT_DEC(VarCyFromDec
,2,0,0,1500); EXPECTCY(15);
3642 CONVERT_DEC(VarCyFromDec
,2,0x80,0,1500); EXPECTCY(-15);
3645 static void test_VarCyFromDate(void)
3649 CHECKPTR(VarCyFromDate
);
3651 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3652 CONVERT(VarCyFromR8
, -461168601842738.7904); EXPECTCY64(0xbfffffff, 0xffffff23);
3655 CONVERT(VarCyFromDate
, -1.0); EXPECTCY(-1);
3656 CONVERT(VarCyFromDate
, -0.0); EXPECTCY(0);
3657 CONVERT(VarCyFromDate
, 1.0); EXPECTCY(1);
3658 CONVERT(VarCyFromDate
, -4611686018427388416.1); EXPECT_OVERFLOW
;
3659 CONVERT(VarCyFromDate
, 4611686018427387648.0); EXPECT_OVERFLOW
;
3662 CONVERT(VarCyFromDate
, -1.5f
); EXPECTCY(-1.5);
3663 CONVERT(VarCyFromDate
, -0.6f
); EXPECTCY(-0.6);
3664 CONVERT(VarCyFromDate
, -0.5f
); EXPECTCY(-0.5);
3665 CONVERT(VarCyFromDate
, -0.4f
); EXPECTCY(-0.4);
3666 CONVERT(VarCyFromDate
, 0.4f
); EXPECTCY(0.4);
3667 CONVERT(VarCyFromDate
, 0.5f
); EXPECTCY(0.5);
3668 CONVERT(VarCyFromDate
, 0.6f
); EXPECTCY(0.6);
3669 CONVERT(VarCyFromDate
, 1.5f
); EXPECTCY(1.5);
3670 CONVERT(VarCyFromDate
, 1.00009f
); EXPECTCY(1.0001);
3671 CONVERT(VarCyFromDate
, -1.00001f
); EXPECTCY(-1);
3672 CONVERT(VarCyFromDate
, -1.00005f
); EXPECTCY(-1);
3673 CONVERT(VarCyFromDate
, -0.00009f
); EXPECTCY(-0.0001);
3674 CONVERT(VarCyFromDate
, -0.00005f
); EXPECTCY(0);
3675 CONVERT(VarCyFromDate
, -0.00001f
); EXPECTCY(0);
3676 CONVERT(VarCyFromDate
, 0.00001f
); EXPECTCY(0);
3677 CONVERT(VarCyFromDate
, 0.00005f
); EXPECTCY(0);
3678 CONVERT(VarCyFromDate
, 0.00009f
); EXPECTCY(0.0001);
3679 CONVERT(VarCyFromDate
, -1.00001f
); EXPECTCY(-1);
3680 CONVERT(VarCyFromDate
, -1.00005f
); EXPECTCY(-1);
3681 CONVERT(VarCyFromDate
, -1.00009f
); EXPECTCY(-1.0001);
3684 #define MATHVARS1 HRESULT hres; double left = 0.0; CY cyLeft, out
3685 #define MATHVARS2 MATHVARS1; double right = 0.0; CY cyRight
3686 #define MATH1(func, l) left = (double)l; pVarCyFromR8(left, &cyLeft); hres = p##func(cyLeft, &out)
3687 #define MATH2(func, l, r) left = (double)l; right = (double)r; \
3688 pVarCyFromR8(left, &cyLeft); pVarCyFromR8(right, &cyRight); \
3689 hres = p##func(cyLeft, cyRight, &out)
3691 static void test_VarCyAdd(void)
3696 MATH2(VarCyAdd
, 0.5, 0.5); EXPECTCY(1);
3697 MATH2(VarCyAdd
, 0.5, -0.4); EXPECTCY(0.1);
3698 MATH2(VarCyAdd
, 0.5, -0.6); EXPECTCY(-0.1);
3699 MATH2(VarCyAdd
, -0.5, -0.5); EXPECTCY(-1);
3700 MATH2(VarCyAdd
, -922337203685476.0, -922337203685476.0); EXPECT_OVERFLOW
;
3701 MATH2(VarCyAdd
, -922337203685476.0, 922337203685476.0); EXPECTCY(0);
3702 MATH2(VarCyAdd
, 922337203685476.0, -922337203685476.0); EXPECTCY(0);
3703 MATH2(VarCyAdd
, 922337203685476.0, 922337203685476.0); EXPECT_OVERFLOW
;
3706 static void test_VarCyMul(void)
3711 MATH2(VarCyMul
, 534443.0, 0.0); EXPECTCY(0);
3712 MATH2(VarCyMul
, 0.5, 0.5); EXPECTCY(0.25);
3713 MATH2(VarCyMul
, 0.5, -0.4); EXPECTCY(-0.2);
3714 MATH2(VarCyMul
, 0.5, -0.6); EXPECTCY(-0.3);
3715 MATH2(VarCyMul
, -0.5, -0.5); EXPECTCY(0.25);
3716 MATH2(VarCyMul
, 922337203685476.0, 20000); EXPECT_OVERFLOW
;
3719 static void test_VarCySub(void)
3724 MATH2(VarCySub
, 0.5, 0.5); EXPECTCY(0);
3725 MATH2(VarCySub
, 0.5, -0.4); EXPECTCY(0.9);
3726 MATH2(VarCySub
, 0.5, -0.6); EXPECTCY(1.1);
3727 MATH2(VarCySub
, -0.5, -0.5); EXPECTCY(0);
3728 MATH2(VarCySub
, -922337203685476.0, -922337203685476.0); EXPECTCY(0);
3729 MATH2(VarCySub
, -922337203685476.0, 922337203685476.0); EXPECT_OVERFLOW
;
3730 MATH2(VarCySub
, 922337203685476.0, -922337203685476.0); EXPECT_OVERFLOW
;
3731 MATH2(VarCySub
, 922337203685476.0, 922337203685476.0); EXPECTCY(0);
3734 static void test_VarCyAbs(void)
3739 MATH1(VarCyAbs
, 0.5); EXPECTCY(0.5);
3740 MATH1(VarCyAbs
, -0.5); EXPECTCY(0.5);
3741 MATH1(VarCyAbs
, 922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3742 MATH1(VarCyAbs
, -922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3745 static void test_VarCyNeg(void)
3750 MATH1(VarCyNeg
, 0.5); EXPECTCY(-0.5);
3751 MATH1(VarCyNeg
, -0.5); EXPECTCY(0.5);
3752 MATH1(VarCyNeg
, 922337203685476.0); EXPECTCY64(2147483648ul,15808);
3753 MATH1(VarCyNeg
, -922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3756 #define MATHMULI4(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3757 hres = pVarCyMulI4(cyLeft, right, &out)
3759 static void test_VarCyMulI4(void)
3764 CHECKPTR(VarCyMulI4
);
3765 MATHMULI4(534443.0, 0); EXPECTCY(0);
3766 MATHMULI4(0.5, 1); EXPECTCY(0.5);
3767 MATHMULI4(0.5, 2); EXPECTCY(1);
3768 MATHMULI4(922337203685476.0, 1); EXPECTCY64(2147483647ul,4294951488ul);
3769 MATHMULI4(922337203685476.0, 2); EXPECT_OVERFLOW
;
3772 #define MATHMULI8(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3773 hres = pVarCyMulI8(cyLeft, right, &out)
3775 static void test_VarCyMulI8(void)
3780 CHECKPTR(VarCyMulI8
);
3781 MATHMULI8(534443.0, 0); EXPECTCY(0);
3782 MATHMULI8(0.5, 1); EXPECTCY(0.5);
3783 MATHMULI8(0.5, 2); EXPECTCY(1);
3784 MATHMULI8(922337203685476.0, 1); EXPECTCY64(2147483647ul,4294951488ul);
3785 MATHMULI8(922337203685476.0, 2); EXPECT_OVERFLOW
;
3788 #define MATHCMP(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); pVarCyFromR8(right, &cyRight); \
3789 hres = pVarCyCmp(cyLeft, cyRight); out.int64 = hres
3791 static void test_VarCyCmp(void)
3796 MATHCMP(-1.0, -1.0); EXPECT_EQ
;
3797 MATHCMP(-1.0, 0.0); EXPECT_LT
;
3798 MATHCMP(-1.0, 1.0); EXPECT_LT
;
3799 MATHCMP(-1.0, 2.0); EXPECT_LT
;
3800 MATHCMP(0.0, 1.0); EXPECT_LT
;
3801 MATHCMP(0.0, 0.0); EXPECT_EQ
;
3802 MATHCMP(0.0, -1.0); EXPECT_GT
;
3803 MATHCMP(1.0, -1.0); EXPECT_GT
;
3804 MATHCMP(1.0, 0.0); EXPECT_GT
;
3805 MATHCMP(1.0, 1.0); EXPECT_EQ
;
3806 MATHCMP(1.0, 2.0); EXPECT_LT
;
3809 #define MATHCMPR8(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3810 hres = pVarCyCmpR8(cyLeft, right); out.int64 = hres
3812 static void test_VarCyCmpR8(void)
3817 CHECKPTR(VarCyCmpR8
);
3818 MATHCMPR8(-1.0, -1.0); EXPECT_EQ
;
3819 MATHCMPR8(-1.0, 0.0); EXPECT_LT
;
3820 MATHCMPR8(-1.0, 1.0); EXPECT_LT
;
3821 MATHCMPR8(-1.0, 2.0); EXPECT_LT
;
3822 MATHCMPR8(0.0, 1.0); EXPECT_LT
;
3823 MATHCMPR8(0.0, 0.0); EXPECT_EQ
;
3824 MATHCMPR8(0.0, -1.0); EXPECT_GT
;
3825 MATHCMPR8(1.0, -1.0); EXPECT_GT
;
3826 MATHCMPR8(1.0, 0.0); EXPECT_GT
;
3827 MATHCMPR8(1.0, 1.0); EXPECT_EQ
;
3828 MATHCMPR8(1.0, 2.0); EXPECT_LT
;
3832 #define MATHRND(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3833 hres = pVarCyRound(cyLeft, right, &out)
3835 static void test_VarCyRound(void)
3840 CHECKPTR(VarCyRound
);
3841 MATHRND(0.5432, 5); EXPECTCY(0.5432);
3842 MATHRND(0.5432, 4); EXPECTCY(0.5432);
3843 MATHRND(0.5432, 3); EXPECTCY(0.543);
3844 MATHRND(0.5432, 2); EXPECTCY(0.54);
3845 MATHRND(0.5432, 1); EXPECTCY(0.5);
3846 MATHRND(0.5532, 0); EXPECTCY(1);
3847 MATHRND(0.5532, -1); EXPECT_INVALID
;
3849 MATHRND(0.5568, 5); EXPECTCY(0.5568);
3850 MATHRND(0.5568, 4); EXPECTCY(0.5568);
3851 MATHRND(0.5568, 3); EXPECTCY(0.557);
3852 MATHRND(0.5568, 2); EXPECTCY(0.56);
3853 MATHRND(0.5568, 1); EXPECTCY(0.6);
3854 MATHRND(0.5568, 0); EXPECTCY(1);
3855 MATHRND(0.5568, -1); EXPECT_INVALID
;
3857 MATHRND(0.4999, 0); EXPECTCY(0);
3858 MATHRND(0.5000, 0); EXPECTCY(0);
3859 MATHRND(0.5001, 0); EXPECTCY(1);
3860 MATHRND(1.4999, 0); EXPECTCY(1);
3861 MATHRND(1.5000, 0); EXPECTCY(2);
3862 MATHRND(1.5001, 0); EXPECTCY(2);
3865 #define MATHFIX(l) left = l; pVarCyFromR8(left, &cyLeft); \
3866 hres = pVarCyFix(cyLeft, &out)
3868 static void test_VarCyFix(void)
3873 MATHFIX(-1.0001); EXPECTCY(-1);
3874 MATHFIX(-1.4999); EXPECTCY(-1);
3875 MATHFIX(-1.5001); EXPECTCY(-1);
3876 MATHFIX(-1.9999); EXPECTCY(-1);
3877 MATHFIX(-0.0001); EXPECTCY(0);
3878 MATHFIX(-0.4999); EXPECTCY(0);
3879 MATHFIX(-0.5001); EXPECTCY(0);
3880 MATHFIX(-0.9999); EXPECTCY(0);
3881 MATHFIX(0.0001); EXPECTCY(0);
3882 MATHFIX(0.4999); EXPECTCY(0);
3883 MATHFIX(0.5001); EXPECTCY(0);
3884 MATHFIX(0.9999); EXPECTCY(0);
3885 MATHFIX(1.0001); EXPECTCY(1);
3886 MATHFIX(1.4999); EXPECTCY(1);
3887 MATHFIX(1.5001); EXPECTCY(1);
3888 MATHFIX(1.9999); EXPECTCY(1);
3891 #define MATHINT(l) left = l; pVarCyFromR8(left, &cyLeft); \
3892 hres = pVarCyInt(cyLeft, &out)
3894 static void test_VarCyInt(void)
3899 MATHINT(-1.0001); EXPECTCY(-2);
3900 MATHINT(-1.4999); EXPECTCY(-2);
3901 MATHINT(-1.5001); EXPECTCY(-2);
3902 MATHINT(-1.9999); EXPECTCY(-2);
3903 MATHINT(-0.0001); EXPECTCY(-1);
3904 MATHINT(-0.4999); EXPECTCY(-1);
3905 MATHINT(-0.5001); EXPECTCY(-1);
3906 MATHINT(-0.9999); EXPECTCY(-1);
3907 MATHINT(0.0001); EXPECTCY(0);
3908 MATHINT(0.4999); EXPECTCY(0);
3909 MATHINT(0.5001); EXPECTCY(0);
3910 MATHINT(0.9999); EXPECTCY(0);
3911 MATHINT(1.0001); EXPECTCY(1);
3912 MATHINT(1.4999); EXPECTCY(1);
3913 MATHINT(1.5001); EXPECTCY(1);
3914 MATHINT(1.9999); EXPECTCY(1);
3922 #define CONV_TYPE DECIMAL
3924 #define EXPECTRES(res, x) \
3925 ok(hres == S_OK || ((HRESULT)res != S_OK && hres == (HRESULT)res), \
3926 "expected hres " #x ", got hres=0x%08lx\n", hres)
3928 #define EXPECTDEC(scl, sgn, hi, lo) ok(hres == S_OK && \
3929 S(U(out)).scale == (BYTE)(scl) && S(U(out)).sign == (BYTE)(sgn) && \
3930 out.Hi32 == (ULONG)(hi) && U1(out).Lo64 == (ULONG64)(lo), \
3931 "expected (%d,%d,%d,(%lx %lx)), got (%d,%d,%ld,(%lx %lx)) hres 0x%08lx\n", \
3932 scl, sgn, hi, (LONG)((LONG64)(lo) >> 32), (LONG)((lo) & 0xffffffff), S(U(out)).scale, \
3933 S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres)
3935 #define EXPECTDEC64(scl, sgn, hi, mid, lo) ok(hres == S_OK && \
3936 S(U(out)).scale == (BYTE)(scl) && S(U(out)).sign == (BYTE)(sgn) && \
3937 out.Hi32 == (ULONG)(hi) && S1(U1(out)).Mid32 == (ULONG)(mid) && \
3938 S1(U1(out)).Lo32 == (ULONG)(lo), \
3939 "expected (%d,%d,%d,(%lx %lx)), got (%d,%d,%ld,(%lx %lx)) hres 0x%08lx\n", \
3940 scl, sgn, hi, (LONG)(mid), (LONG)(lo), S(U(out)).scale, \
3941 S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres)
3943 #define EXPECTDECI if (i < 0) EXPECTDEC(0, 0x80, 0, -i); else EXPECTDEC(0, 0, 0, i)
3945 static void test_VarDecFromI1(void)
3947 CONVVARS(signed char);
3950 CHECKPTR(VarDecFromI1
);
3951 for (i
= -128; i
< 128; i
++)
3953 CONVERT(VarDecFromI1
,i
); EXPECTDECI
;
3957 static void test_VarDecFromI2(void)
3962 CHECKPTR(VarDecFromI2
);
3963 for (i
= -32768; i
< 32768; i
++)
3965 CONVERT(VarDecFromI2
,i
); EXPECTDECI
;
3969 static void test_VarDecFromI4(void)
3974 CHECKPTR(VarDecFromI4
);
3975 for (i
= -32768; i
< 32768; i
++)
3977 CONVERT(VarDecFromI4
,i
); EXPECTDECI
;
3981 static void test_VarDecFromI8(void)
3986 CHECKPTR(VarDecFromI8
);
3987 for (i
= -32768; i
< 32768; i
++)
3989 CONVERT(VarDecFromI8
,i
); EXPECTDECI
;
3993 static void test_VarDecFromUI1(void)
3998 CHECKPTR(VarDecFromUI1
);
3999 for (i
= 0; i
< 256; i
++)
4001 CONVERT(VarDecFromUI1
,i
); EXPECTDECI
;
4005 static void test_VarDecFromUI2(void)
4010 CHECKPTR(VarDecFromUI2
);
4011 for (i
= 0; i
< 65536; i
++)
4013 CONVERT(VarDecFromUI2
,i
); EXPECTDECI
;
4017 static void test_VarDecFromUI4(void)
4022 CHECKPTR(VarDecFromUI4
);
4023 for (i
= 0; i
< 65536; i
++)
4025 CONVERT(VarDecFromUI4
,i
); EXPECTDECI
;
4029 static void test_VarDecFromUI8(void)
4034 CHECKPTR(VarDecFromUI8
);
4035 for (i
= 0; i
< 65536; i
++)
4037 CONVERT(VarDecFromUI8
,i
); EXPECTDECI
;
4041 static void test_VarDecFromBool(void)
4046 CHECKPTR(VarDecFromBool
);
4047 /* Test all possible type values. Note that the result is reduced to 0 or -1 */
4048 for (i
= -32768; i
< 0; i
++)
4050 CONVERT(VarDecFromBool
,i
);
4052 EXPECTDEC(0,0x80,0,1);
4058 static void test_VarDecFromR4(void)
4062 CHECKPTR(VarDecFromR4
);
4064 CONVERT(VarDecFromR4
,-0.6f
); EXPECTDEC(1,0x80,0,6);
4065 CONVERT(VarDecFromR4
,-0.5f
); EXPECTDEC(1,0x80,0,5);
4066 CONVERT(VarDecFromR4
,-0.4f
); EXPECTDEC(1,0x80,0,4);
4067 CONVERT(VarDecFromR4
,0.0f
); EXPECTDEC(0,0,0,0);
4068 CONVERT(VarDecFromR4
,0.4f
); EXPECTDEC(1,0,0,4);
4069 CONVERT(VarDecFromR4
,0.5f
); EXPECTDEC(1,0,0,5);
4070 CONVERT(VarDecFromR4
,0.6f
); EXPECTDEC(1,0,0,6);
4073 static void test_VarDecFromR8(void)
4077 CHECKPTR(VarDecFromR8
);
4079 CONVERT(VarDecFromR8
,-0.6); EXPECTDEC(1,0x80,0,6);
4080 CONVERT(VarDecFromR8
,-0.5); EXPECTDEC(1,0x80,0,5);
4081 CONVERT(VarDecFromR8
,-0.4); EXPECTDEC(1,0x80,0,4);
4082 CONVERT(VarDecFromR8
,0.0); EXPECTDEC(0,0,0,0);
4083 CONVERT(VarDecFromR8
,0.4); EXPECTDEC(1,0,0,4);
4084 CONVERT(VarDecFromR8
,0.5); EXPECTDEC(1,0,0,5);
4085 CONVERT(VarDecFromR8
,0.6); EXPECTDEC(1,0,0,6);
4088 static void test_VarDecFromDate(void)
4092 CHECKPTR(VarDecFromDate
);
4094 CONVERT(VarDecFromDate
,-0.6); EXPECTDEC(1,0x80,0,6);
4095 CONVERT(VarDecFromDate
,-0.5); EXPECTDEC(1,0x80,0,5);
4096 CONVERT(VarDecFromDate
,-0.4); EXPECTDEC(1,0x80,0,4);
4097 CONVERT(VarDecFromDate
,0.0); EXPECTDEC(0,0,0,0);
4098 CONVERT(VarDecFromDate
,0.4); EXPECTDEC(1,0,0,4);
4099 CONVERT(VarDecFromDate
,0.5); EXPECTDEC(1,0,0,5);
4100 CONVERT(VarDecFromDate
,0.6); EXPECTDEC(1,0,0,6);
4103 static void test_VarDecFromStr(void)
4108 CHECKPTR(VarDecFromStr
);
4110 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
4112 CONVERT_STR(VarDecFromStr
,NULL
,0); EXPECT_MISMATCH
;
4113 CONVERT_STR(VarDecFromStr
,"-1", LOCALE_NOUSEROVERRIDE
); EXPECTDEC(0,0x80,0,1);
4114 CONVERT_STR(VarDecFromStr
,"0", LOCALE_NOUSEROVERRIDE
); EXPECTDEC(0,0,0,0);
4115 CONVERT_STR(VarDecFromStr
,"1", LOCALE_NOUSEROVERRIDE
); EXPECTDEC(0,0,0,1);
4116 CONVERT_STR(VarDecFromStr
,"0.5", LOCALE_NOUSEROVERRIDE
); EXPECTDEC(1,0,0,5);
4119 static void test_VarDecFromCy(void)
4123 CHECKPTR(VarDecFromCy
);
4125 CONVERT_CY(VarDecFromCy
, -1); EXPECTDEC(4,0x80,0,10000);
4126 CONVERT_CY(VarDecFromCy
, 0); EXPECTDEC(4,0,0,0);
4127 CONVERT_CY(VarDecFromCy
, 1); EXPECTDEC(4,0,0,10000);
4128 CONVERT_CY(VarDecFromCy
, 0.5); EXPECTDEC(4,0,0,5000);
4132 #define MATHVARS1 HRESULT hres; DECIMAL l, out
4134 #define MATHVARS2 MATHVARS1; DECIMAL r
4136 #define MATH1(func) hres = p##func(&l, &out)
4138 #define MATH2(func) hres = p##func(&l, &r, &out)
4140 static void test_VarDecAbs(void)
4144 CHECKPTR(VarDecAbs
);
4145 SETDEC(l
,0,0x80,0,1); MATH1(VarDecAbs
); EXPECTDEC(0,0,0,1);
4146 SETDEC(l
,0,0,0,0); MATH1(VarDecAbs
); EXPECTDEC(0,0,0,0);
4147 SETDEC(l
,0,0x80,0,0); MATH1(VarDecAbs
); EXPECTDEC(0,0,0,0);
4148 SETDEC(l
,0,0,0,1); MATH1(VarDecAbs
); EXPECTDEC(0,0,0,1);
4150 /* Doesn't check for invalid input */
4151 SETDEC(l
,0,0x7f,0,1); MATH1(VarDecAbs
); EXPECTDEC(0,0x7f,0,1);
4152 SETDEC(l
,0,0x80,29,1); MATH1(VarDecAbs
); EXPECTDEC(0,0,29,1);
4155 static void test_VarDecNeg(void)
4159 CHECKPTR(VarDecNeg
);
4160 SETDEC(l
,0,0x80,0,1); MATH1(VarDecNeg
); EXPECTDEC(0,0,0,1);
4161 SETDEC(l
,0,0,0,0); MATH1(VarDecNeg
); EXPECTDEC(0,0x80,0,0); /* '-0'! */
4162 SETDEC(l
,0,0x80,0,0); MATH1(VarDecNeg
); EXPECTDEC(0,0,0,0);
4163 SETDEC(l
,0,0,0,1); MATH1(VarDecNeg
); EXPECTDEC(0,0x80,0,1);
4165 /* Doesn't check for invalid input */
4166 SETDEC(l
,0,0x7f,0,1); MATH1(VarDecNeg
); EXPECTDEC(0,0xff,0,1);
4167 SETDEC(l
,0,0x80,29,1); MATH1(VarDecNeg
); EXPECTDEC(0,0,29,1);
4168 SETDEC(l
,0,0,29,1); MATH1(VarDecNeg
); EXPECTDEC(0,0x80,29,1);
4171 static void test_VarDecAdd(void)
4175 CHECKPTR(VarDecAdd
);
4176 SETDEC(l
,0,0,0,0); SETDEC(r
,0,0,0,0); MATH2(VarDecAdd
); EXPECTDEC(0,0,0,0);
4177 SETDEC(l
,0,0,0,0); SETDEC(r
,0,0x80,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0x80,0,1);
4178 SETDEC(l
,0,0,0,0); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0,0,1);
4180 SETDEC(l
,0,0,0,1); SETDEC(r
,0,0,0,0); MATH2(VarDecAdd
); EXPECTDEC(0,0,0,1);
4181 SETDEC(l
,0,0,0,1); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0,0,2);
4182 SETDEC(l
,0,0,0,1); SETDEC(r
,0,0x80,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0x80,0,0); /* '-0'! */
4183 SETDEC(l
,0,0,0,1); SETDEC(r
,0,0x80,0,2); MATH2(VarDecAdd
); EXPECTDEC(0,0x80,0,1);
4185 SETDEC(l
,0,0x80,0,0); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0,0,1);
4186 SETDEC(l
,0,0x80,0,1); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0,0,0);
4187 SETDEC(l
,0,0x80,0,1); SETDEC(r
,0,0,0,2); MATH2(VarDecAdd
); EXPECTDEC(0,0,0,1);
4188 SETDEC(l
,0,0x80,0,1); SETDEC(r
,0,0x80,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0x80,0,2);
4189 SETDEC(l
,0,0x80,0,2); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0x80,0,1);
4191 SETDEC(l
,0,0,0,0xffffffff); SETDEC(r
,0,0x80,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0,0,0xfffffffe);
4192 SETDEC(l
,0,0,0,0xffffffff); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0,0,(ULONG64
)1 << 32);
4193 SETDEC(l
,0,0,0,0xffffffff); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0,0,(ULONG64
)1 << 32);
4195 SETDEC64(l
,0,0,0,0xffffffff,0); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC64(0,0,0,0xffffffff,1);
4196 SETDEC64(l
,0,0,0,0xffffffff,0); SETDEC(r
,0,0x80,0,1); MATH2(VarDecAdd
);
4197 EXPECTDEC64(0,0,0,0xfffffffe,0xffffffff);
4199 SETDEC64(l
,0,0,0,0xffffffff,0xffffffff); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0,1,0);
4200 SETDEC64(l
,0,0,0,0xffffffff,0xffffffff); SETDEC(r
,0,0x80,0,1); MATH2(VarDecAdd
);
4201 EXPECTDEC64(0,0,0,0xffffffff,0xfffffffe);
4203 SETDEC(l
,0,0,0xffffffff,0); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC(0,0,0xffffffff,1);
4204 SETDEC(l
,0,0,0xffffffff,0); SETDEC(r
,0,0x80,0,1); MATH2(VarDecAdd
);
4205 EXPECTDEC64(0,0,0xfffffffe,0xffffffff,0xffffffff);
4207 SETDEC64(l
,0,0,0xffffffff,0xffffffff,0xffffffff);SETDEC(r
,0,0x80,0,1); MATH2(VarDecAdd
);
4208 EXPECTDEC64(0,0,0xffffffff,0xffffffff,0xfffffffe);
4209 SETDEC64(l
,0,0,0xffffffff,0xffffffff,0xffffffff);SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
);
4210 ok(hres
== DISP_E_OVERFLOW
,"Expected overflow, got (%d,%d,%ld,(%8lx,%8lx)x) hres 0x%08lx\n",
4211 S(U(out
)).scale
, S(U(out
)).sign
, out
.Hi32
, S1(U1(out
)).Mid32
, S1(U1(out
)).Lo32
, hres
);
4213 /* Promotes to the highest scale, so here the results are in the scale of 2 */
4214 SETDEC(l
,2,0,0,0); SETDEC(r
,0,0,0,0); MATH2(VarDecAdd
); EXPECTDEC(2,0,0,0);
4215 SETDEC(l
,2,0,0,100); SETDEC(r
,0,0,0,1); MATH2(VarDecAdd
); EXPECTDEC(2,0,0,200);
4218 static void test_VarDecSub(void)
4222 CHECKPTR(VarDecSub
);
4223 SETDEC(l
,0,0,0,0); SETDEC(r
,0,0,0,0); MATH2(VarDecSub
); EXPECTDEC(0,0x80,0,0);
4224 SETDEC(l
,0,0,0,0); SETDEC(r
,0,0,0,1); MATH2(VarDecSub
); EXPECTDEC(0,0x80,0,1);
4225 SETDEC(l
,0,0,0,1); SETDEC(r
,0,0,0,1); MATH2(VarDecSub
); EXPECTDEC(0,0x80,0,0);
4226 SETDEC(l
,0,0,0,1); SETDEC(r
,0,0x80,0,1); MATH2(VarDecSub
); EXPECTDEC(0,0,0,2);
4229 static void test_VarDecCmp(void)
4233 CHECKPTR(VarDecCmp
);
4234 SETDEC(l
,0,0,0,1); SETDEC(out
,0,0,0,1); MATH1(VarDecCmp
); EXPECT_EQ
;
4235 SETDEC(l
,0,0,0,1); SETDEC(out
,0,0,0,0); MATH1(VarDecCmp
); EXPECT_GT
;
4236 SETDEC(l
,0,0,0,0); SETDEC(out
,0,0,0,1); MATH1(VarDecCmp
); EXPECT_LT
;
4244 #define CONV_TYPE VARIANT_BOOL
4246 #define _EXPECTRES(res, x, fs) \
4247 ok((hres == S_OK && out == (CONV_TYPE)(x)) || ((HRESULT)res != S_OK && hres == (HRESULT)res), \
4248 "expected " #x ", got " fs "; hres=0x%08lx\n", out, hres)
4250 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%d")
4252 #define CONVERTRANGE(func,start,end) for (i = start; i < end; i++) { \
4253 CONVERT(func, i); if (i) { EXPECT(VARIANT_TRUE); } else { EXPECT(VARIANT_FALSE); } }
4255 static void test_VarBoolFromI1(void)
4257 CONVVARS(signed char);
4260 CHECKPTR(VarBoolFromI1
);
4261 CONVERTRANGE(VarBoolFromI1
, -128, 128);
4264 static void test_VarBoolFromUI1(void)
4269 CHECKPTR(VarBoolFromUI1
);
4270 CONVERTRANGE(VarBoolFromUI1
, 0, 256);
4273 static void test_VarBoolFromI2(void)
4278 CHECKPTR(VarBoolFromI2
);
4279 CONVERTRANGE(VarBoolFromI2
, -32768, 32768);
4282 static void test_VarBoolFromUI2(void)
4287 CHECKPTR(VarBoolFromUI2
);
4288 CONVERTRANGE(VarBoolFromUI2
, 0, 65536);
4291 static void test_VarBoolFromI4(void)
4295 CHECKPTR(VarBoolFromI4
);
4296 CONVERT(VarBoolFromI4
, 0x80000000); EXPECT(VARIANT_TRUE
);
4297 CONVERT(VarBoolFromI4
, -1); EXPECT(VARIANT_TRUE
);
4298 CONVERT(VarBoolFromI4
, 0); EXPECT(VARIANT_FALSE
);
4299 CONVERT(VarBoolFromI4
, 1); EXPECT(VARIANT_TRUE
);
4300 CONVERT(VarBoolFromI4
, 0x7fffffff); EXPECT(VARIANT_TRUE
);
4303 static void test_VarBoolFromUI4(void)
4307 CHECKPTR(VarBoolFromUI4
);
4308 CONVERT(VarBoolFromI4
, 0); EXPECT(VARIANT_FALSE
);
4309 CONVERT(VarBoolFromI4
, 1); EXPECT(VARIANT_TRUE
);
4310 CONVERT(VarBoolFromI4
, 0x80000000); EXPECT(VARIANT_TRUE
);
4313 static void test_VarBoolFromR4(void)
4317 CHECKPTR(VarBoolFromR4
);
4318 CONVERT(VarBoolFromR4
, -1.0f
); EXPECT(VARIANT_TRUE
);
4319 CONVERT(VarBoolFromR4
, 0.0f
); EXPECT(VARIANT_FALSE
);
4320 CONVERT(VarBoolFromR4
, 1.0f
); EXPECT(VARIANT_TRUE
);
4321 CONVERT(VarBoolFromR4
, 1.5f
); EXPECT(VARIANT_TRUE
);
4324 CONVERT(VarBoolFromR4
, -1.5f
); EXPECT(VARIANT_TRUE
);
4325 CONVERT(VarBoolFromR4
, -0.6f
); EXPECT(VARIANT_TRUE
);
4326 CONVERT(VarBoolFromR4
, -0.5f
); EXPECT(VARIANT_TRUE
);
4327 CONVERT(VarBoolFromR4
, -0.4f
); EXPECT(VARIANT_TRUE
);
4328 CONVERT(VarBoolFromR4
, 0.4f
); EXPECT(VARIANT_TRUE
);
4329 CONVERT(VarBoolFromR4
, 0.5f
); EXPECT(VARIANT_TRUE
);
4330 CONVERT(VarBoolFromR4
, 0.6f
); EXPECT(VARIANT_TRUE
);
4331 CONVERT(VarBoolFromR4
, 1.5f
); EXPECT(VARIANT_TRUE
);
4334 static void test_VarBoolFromR8(void)
4338 /* Hopefully we made the point with R4 above that rounding is
4339 * irrelevant, so we'll skip that for R8 and Date
4341 CHECKPTR(VarBoolFromR8
);
4342 CONVERT(VarBoolFromR8
, -1.0); EXPECT(VARIANT_TRUE
);
4343 CONVERT(VarBoolFromR8
, -0.0); EXPECT(VARIANT_FALSE
);
4344 CONVERT(VarBoolFromR8
, 1.0); EXPECT(VARIANT_TRUE
);
4347 static void test_VarBoolFromCy(void)
4351 CHECKPTR(VarBoolFromCy
);
4352 CONVERT_CY(VarBoolFromCy
, -32769); EXPECT(VARIANT_TRUE
);
4353 CONVERT_CY(VarBoolFromCy
, -32768); EXPECT(VARIANT_TRUE
);
4354 CONVERT_CY(VarBoolFromCy
, -1); EXPECT(VARIANT_TRUE
);
4355 CONVERT_CY(VarBoolFromCy
, 0); EXPECT(VARIANT_FALSE
);
4356 CONVERT_CY(VarBoolFromCy
, 1); EXPECT(VARIANT_TRUE
);
4357 CONVERT_CY(VarBoolFromCy
, 32767); EXPECT(VARIANT_TRUE
);
4358 CONVERT_CY(VarBoolFromCy
, 32768); EXPECT(VARIANT_TRUE
);
4361 static void test_VarBoolFromI8(void)
4365 CHECKPTR(VarBoolFromI8
);
4366 CONVERT(VarBoolFromI8
, -1); EXPECT(VARIANT_TRUE
);
4367 CONVERT(VarBoolFromI8
, 0); EXPECT(VARIANT_FALSE
);
4368 CONVERT(VarBoolFromI8
, 1); EXPECT(VARIANT_TRUE
);
4371 static void test_VarBoolFromUI8(void)
4375 CHECKPTR(VarBoolFromUI8
);
4376 CONVERT(VarBoolFromUI8
, 0); EXPECT(VARIANT_FALSE
);
4377 CONVERT(VarBoolFromUI8
, 1); EXPECT(VARIANT_TRUE
);
4380 static void test_VarBoolFromDec(void)
4384 CHECKPTR(VarBoolFromDec
);
4385 CONVERT_BADDEC(VarBoolFromDec
);
4387 if (HAVE_OLEAUT32_DECIMAL
)
4389 /* Early versions of oleaut32 don't catch these errors */
4390 CONVERT_DEC(VarBoolFromDec
,29,0,0,0); EXPECT_INVALID
;
4391 CONVERT_DEC(VarBoolFromDec
,0,0x1,0,0); EXPECT_INVALID
;
4392 CONVERT_DEC(VarBoolFromDec
,0,0x40,0,0); EXPECT_INVALID
;
4393 CONVERT_DEC(VarBoolFromDec
,0,0x7f,0,0); EXPECT_INVALID
;
4396 CONVERT_DEC(VarBoolFromDec
,0,0x80,0,1); EXPECT(VARIANT_TRUE
);
4397 CONVERT_DEC(VarBoolFromDec
,0,0,0,0); EXPECT(VARIANT_FALSE
);
4398 CONVERT_DEC(VarBoolFromDec
,0,0,0,1); EXPECT(VARIANT_TRUE
);
4399 CONVERT_DEC(VarBoolFromDec
,0,0,1,0); EXPECT(VARIANT_TRUE
);
4401 CONVERT_DEC(VarBoolFromDec
,2,0,0,CY_MULTIPLIER
); EXPECT(VARIANT_TRUE
);
4402 CONVERT_DEC(VarBoolFromDec
,2,0x80,0,CY_MULTIPLIER
); EXPECT(VARIANT_TRUE
);
4405 static void test_VarBoolFromDate(void)
4409 CHECKPTR(VarBoolFromDate
);
4410 CONVERT(VarBoolFromDate
, -1.0); EXPECT(VARIANT_TRUE
);
4411 CONVERT(VarBoolFromDate
, -0.0); EXPECT(VARIANT_FALSE
);
4412 CONVERT(VarBoolFromDate
, 1.0); EXPECT(VARIANT_TRUE
);
4415 static void test_VarBoolFromStr(void)
4420 CHECKPTR(VarBoolFromStr
);
4422 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
4424 CONVERT_STR(VarBoolFromStr
,NULL
,0);
4425 if (hres
!= E_INVALIDARG
)
4428 /* #FALSE# and #TRUE# Are always accepted */
4429 CONVERT_STR(VarBoolFromStr
,"#FALSE#",0); EXPECT(VARIANT_FALSE
);
4430 CONVERT_STR(VarBoolFromStr
,"#TRUE#",0); EXPECT(VARIANT_TRUE
);
4432 /* Match of #FALSE# and #TRUE# is case sensitive */
4433 CONVERT_STR(VarBoolFromStr
,"#False#",0); EXPECT_MISMATCH
;
4434 /* But match against English is not */
4435 CONVERT_STR(VarBoolFromStr
,"false",0); EXPECT(VARIANT_FALSE
);
4436 CONVERT_STR(VarBoolFromStr
,"False",0); EXPECT(VARIANT_FALSE
);
4437 /* On/Off and yes/no are not acceptable inputs, with any flags set */
4438 CONVERT_STR(VarBoolFromStr
,"On",0xffffffff); EXPECT_MISMATCH
;
4439 CONVERT_STR(VarBoolFromStr
,"Yes",0xffffffff); EXPECT_MISMATCH
;
4441 /* Change the LCID. This doesn't make any difference for text,unless we ask
4442 * to check local boolean text with the VARIANT_LOCALBOOL flag. */
4443 in
= MAKELCID(MAKELANGID(LANG_FRENCH
, SUBLANG_DEFAULT
), SORT_DEFAULT
);
4445 /* #FALSE# and #TRUE# are accepted in all locales */
4446 CONVERT_STR(VarBoolFromStr
,"#FALSE#",0); EXPECT(VARIANT_FALSE
);
4447 CONVERT_STR(VarBoolFromStr
,"#TRUE#",0); EXPECT(VARIANT_TRUE
);
4448 CONVERT_STR(VarBoolFromStr
,"#FALSE#",VARIANT_LOCALBOOL
); EXPECT(VARIANT_FALSE
);
4449 CONVERT_STR(VarBoolFromStr
,"#TRUE#",VARIANT_LOCALBOOL
); EXPECT(VARIANT_TRUE
);
4451 /* English is accepted regardless of the locale */
4452 CONVERT_STR(VarBoolFromStr
,"false",0); EXPECT(VARIANT_FALSE
);
4453 /* And is still not case sensitive */
4454 CONVERT_STR(VarBoolFromStr
,"False",0); EXPECT(VARIANT_FALSE
);
4456 if (HAVE_OLEAUT32_LOCALES
)
4458 /* French is rejected without VARIANT_LOCALBOOL */
4459 CONVERT_STR(VarBoolFromStr
,"faux",0); EXPECT_MISMATCH
;
4460 /* But accepted if this flag is given */
4461 CONVERT_STR(VarBoolFromStr
,"faux",VARIANT_LOCALBOOL
); EXPECT(VARIANT_FALSE
);
4462 /* Regardless of case - from this we assume locale text comparasons ignore case */
4463 CONVERT_STR(VarBoolFromStr
,"Faux",VARIANT_LOCALBOOL
); EXPECT(VARIANT_FALSE
);
4465 /* Changing the locale prevents the localised text from being compared -
4466 * this demonstrates that only the indicated LCID and English are searched */
4467 in
= MAKELCID(MAKELANGID(LANG_POLISH
, SUBLANG_DEFAULT
), SORT_DEFAULT
);
4468 CONVERT_STR(VarBoolFromStr
,"faux",VARIANT_LOCALBOOL
); EXPECT_MISMATCH
;
4471 /* Numeric strings are read as 0 or non-0 */
4472 CONVERT_STR(VarBoolFromStr
,"0",0); EXPECT(VARIANT_FALSE
);
4473 CONVERT_STR(VarBoolFromStr
,"-1",0); EXPECT(VARIANT_TRUE
);
4474 CONVERT_STR(VarBoolFromStr
,"+1",0); EXPECT(VARIANT_TRUE
);
4476 if (HAVE_OLEAUT32_LOCALES
)
4478 /* Numeric strings are read as floating point numbers. The line below fails
4479 * because '.' is not a valid decimal separator for Polish numbers */
4480 CONVERT_STR(VarBoolFromStr
,"0.1",0); EXPECT_MISMATCH
;
4483 /* Changing the lcid back to US English reads the r8 correctly */
4484 in
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
4485 CONVERT_STR(VarBoolFromStr
,"0.1",0); EXPECT(VARIANT_TRUE
);
4488 static void test_VarBoolCopy(void)
4490 COPYTEST(1, VT_BOOL
, V_BOOL(&vSrc
), V_BOOL(&vDst
), V_BOOLREF(&vSrc
), V_BOOLREF(&vDst
), "%d");
4493 #define BOOL_STR(flags, str) hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, flags, VT_BSTR); \
4494 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && \
4495 V_BSTR(&vDst) && !memcmp(V_BSTR(&vDst), str, sizeof(str)), \
4496 "hres=0x%lX, type=%d (should be VT_BSTR), *bstr='%c'\n", \
4497 hres, V_VT(&vDst), V_BSTR(&vDst) ? *V_BSTR(&vDst) : '?')
4499 static void test_VarBoolChangeTypeEx(void)
4501 static const WCHAR szTrue
[] = { 'T','r','u','e','\0' };
4502 static const WCHAR szFalse
[] = { 'F','a','l','s','e','\0' };
4503 static const WCHAR szFaux
[] = { 'F','a','u','x','\0' };
4504 CONVVARS(CONV_TYPE
);
4505 VARIANTARG vSrc
, vDst
;
4510 INITIAL_TYPETEST(VT_BOOL
, V_BOOL
, "%d");
4513 /* The common tests convert to a number. Try the different flags */
4514 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
4516 V_VT(&vSrc
) = VT_BOOL
;
4521 BOOL_STR(VARIANT_ALPHABOOL
, szTrue
);
4523 BOOL_STR(VARIANT_ALPHABOOL
, szFalse
);
4526 if (HAVE_OLEAUT32_LOCALES
)
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' };
4552 CHECKPTR(VarBstrFromR4
);
4554 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
4556 hres
= pVarBstrFromR4(f
, lcid
, 0, &bstr
);
4557 ok(hres
== S_OK
, "got hres 0x%08lx\n", hres
);
4561 /* MSDN states that rounding of R4/R8 is dependent on the underlying
4562 * bit pattern of the number and so is architecture dependent. In this
4563 * case Wine returns .2 (which is more correct) and Native returns .3
4565 ok(memcmp(bstr
, szNative
, sizeof(szNative
)) == 0, "string different\n");
4570 #define BSTR_DATE(dt,str) SysFreeString(bstr); bstr = NULL; \
4571 hres = pVarBstrFromDate(dt,lcid,LOCALE_NOUSEROVERRIDE,&bstr); \
4572 if (bstr) WideCharToMultiByte(CP_ACP, 0, bstr, -1, buff, sizeof(buff), 0, 0); \
4574 ok(hres == S_OK && !strcmp(str,buff), "Expected '%s', got '%s', hres = 0x%08lx\n", \
4577 static void test_VarBstrFromDate(void)
4584 CHECKPTR(VarBstrFromDate
);
4585 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
4587 BSTR_DATE(0.0, "12:00:00 AM");
4588 BSTR_DATE(3.34, "1/2/1900 8:09:36 AM");
4589 BSTR_DATE(3339.34, "2/20/1909 8:09:36 AM");
4590 BSTR_DATE(365.00, "12/30/1900");
4591 BSTR_DATE(365.25, "12/30/1900 6:00:00 AM");
4592 BSTR_DATE(1461.0, "12/31/1903");
4593 BSTR_DATE(1461.5, "12/31/1903 12:00:00 PM");
4596 /* Get the internal representation of a BSTR */
4597 static inline LPINTERNAL_BSTR
Get(const BSTR lpszString
)
4599 return lpszString
? (LPINTERNAL_BSTR
)((char*)lpszString
- sizeof(DWORD
)) : NULL
;
4602 static inline BSTR
GetBSTR(const LPINTERNAL_BSTR bstr
)
4604 return (BSTR
)bstr
->szString
;
4607 static void test_SysStringLen()
4610 BSTR str
= GetBSTR(&bstr
);
4613 ok (SysStringLen(str
) == 0, "Expected dwLen 0, got %d\n", SysStringLen(str
));
4615 ok (SysStringLen(str
) == 1, "Expected dwLen 1, got %d\n", SysStringLen(str
));
4618 static void test_SysStringByteLen()
4621 BSTR str
= GetBSTR(&bstr
);
4624 ok (SysStringByteLen(str
) == 0, "Expected dwLen 0, got %d\n", SysStringLen(str
));
4626 ok (SysStringByteLen(str
) == 2, "Expected dwLen 2, got %d\n", SysStringByteLen(str
));
4629 static void test_SysAllocString()
4631 const OLECHAR szTest
[5] = { 'T','e','s','t','\0' };
4634 str
= SysAllocString(NULL
);
4635 ok (str
== NULL
, "Expected NULL, got %p\n", str
);
4637 str
= SysAllocString(szTest
);
4638 ok (str
!= NULL
, "Expected non-NULL\n");
4641 LPINTERNAL_BSTR bstr
= Get(str
);
4643 ok (bstr
->dwLen
== 8, "Expected 8, got %ld\n", bstr
->dwLen
);
4644 ok (!lstrcmpW(bstr
->szString
, szTest
), "String different\n");
4649 static void test_SysAllocStringLen()
4651 const OLECHAR szTest
[5] = { 'T','e','s','t','\0' };
4654 /* Very early native dlls do not limit the size of strings, so skip this test */
4656 str
= SysAllocStringLen(szTest
, 0x80000000);
4658 ok (str
== NULL
, "Expected NULL, got %p\n", str
);
4662 str
= SysAllocStringLen(NULL
, 0);
4663 ok (str
!= NULL
, "Expected non-NULL\n");
4666 LPINTERNAL_BSTR bstr
= Get(str
);
4668 ok (bstr
->dwLen
== 0, "Expected 0, got %ld\n", bstr
->dwLen
);
4669 ok (!bstr
->szString
[0], "String not empty\n");
4673 str
= SysAllocStringLen(szTest
, 4);
4674 ok (str
!= NULL
, "Expected non-NULL\n");
4677 LPINTERNAL_BSTR bstr
= Get(str
);
4679 ok (bstr
->dwLen
== 8, "Expected 8, got %ld\n", bstr
->dwLen
);
4680 ok (!lstrcmpW(bstr
->szString
, szTest
), "String different\n");
4685 static void test_SysAllocStringByteLen()
4687 const OLECHAR szTest
[10] = { 'T','e','s','t','\0' };
4688 const CHAR szTestA
[6] = { 'T','e','s','t','\0','?' };
4691 str
= SysAllocStringByteLen(szTestA
, 0x80000000);
4692 ok (str
== NULL
, "Expected NULL, got %p\n", str
);
4694 str
= SysAllocStringByteLen(NULL
, 0);
4695 ok (str
!= NULL
, "Expected non-NULL\n");
4698 LPINTERNAL_BSTR bstr
= Get(str
);
4700 ok (bstr
->dwLen
== 0, "Expected 0, got %ld\n", bstr
->dwLen
);
4701 ok (!bstr
->szString
[0], "String not empty\n");
4705 str
= SysAllocStringByteLen(szTestA
, 4);
4706 ok (str
!= NULL
, "Expected non-NULL\n");
4709 LPINTERNAL_BSTR bstr
= Get(str
);
4711 ok (bstr
->dwLen
== 4, "Expected 4, got %ld\n", bstr
->dwLen
);
4712 ok (!lstrcmpA((LPCSTR
)bstr
->szString
, szTestA
), "String different\n");
4716 /* Odd lengths are allocated rounded up, but truncated at the right position */
4717 str
= SysAllocStringByteLen(szTestA
, 3);
4718 ok (str
!= NULL
, "Expected non-NULL\n");
4721 const CHAR szTestTruncA
[4] = { 'T','e','s','\0' };
4722 LPINTERNAL_BSTR bstr
= Get(str
);
4724 ok (bstr
->dwLen
== 3, "Expected 3, got %ld\n", bstr
->dwLen
);
4725 ok (!lstrcmpA((LPCSTR
)bstr
->szString
, szTestTruncA
), "String different\n");
4729 str
= SysAllocStringByteLen((LPCSTR
)szTest
, 8);
4730 ok (str
!= NULL
, "Expected non-NULL\n");
4733 LPINTERNAL_BSTR bstr
= Get(str
);
4735 ok (bstr
->dwLen
== 8, "Expected 8, got %ld\n", bstr
->dwLen
);
4736 ok (!lstrcmpW(bstr
->szString
, szTest
), "String different\n");
4741 static void test_SysReAllocString()
4743 const OLECHAR szTest
[5] = { 'T','e','s','t','\0' };
4744 const OLECHAR szSmaller
[2] = { 'x','\0' };
4745 const OLECHAR szLarger
[7] = { 'L','a','r','g','e','r','\0' };
4748 str
= SysAllocStringLen(szTest
, 4);
4749 ok (str
!= NULL
, "Expected non-NULL\n");
4752 LPINTERNAL_BSTR bstr
;
4757 ok (bstr
->dwLen
== 8, "Expected 8, got %ld\n", bstr
->dwLen
);
4758 ok (!lstrcmpW(bstr
->szString
, szTest
), "String different\n");
4760 changed
= SysReAllocString(&str
, szSmaller
);
4761 ok (changed
== 1, "Expected 1, got %d\n", changed
);
4762 ok (str
== oldstr
, "Created new string\n");
4764 ok (bstr
->dwLen
== 2, "Expected 2, got %ld\n", bstr
->dwLen
);
4765 ok (!lstrcmpW(bstr
->szString
, szSmaller
), "String different\n");
4768 changed
= SysReAllocString(&str
, szLarger
);
4769 ok (changed
== 1, "Expected 1, got %d\n", changed
);
4770 /* Early versions always make new strings rather than resizing */
4771 /* ok (str == oldstr, "Created new string\n"); */
4773 ok (bstr
->dwLen
== 12, "Expected 12, got %ld\n", bstr
->dwLen
);
4774 ok (!lstrcmpW(bstr
->szString
, szLarger
), "String different\n");
4780 static void test_SysReAllocStringLen()
4782 const OLECHAR szTest
[5] = { 'T','e','s','t','\0' };
4783 const OLECHAR szSmaller
[2] = { 'x','\0' };
4784 const OLECHAR szLarger
[7] = { 'L','a','r','g','e','r','\0' };
4787 str
= SysAllocStringLen(szTest
, 4);
4788 ok (str
!= NULL
, "Expected non-NULL\n");
4791 LPINTERNAL_BSTR bstr
;
4796 ok (bstr
->dwLen
== 8, "Expected 8, got %ld\n", bstr
->dwLen
);
4797 ok (!lstrcmpW(bstr
->szString
, szTest
), "String different\n");
4799 changed
= SysReAllocStringLen(&str
, szSmaller
, 1);
4800 ok (changed
== 1, "Expected 1, got %d\n", changed
);
4801 ok (str
== oldstr
, "Created new string\n");
4803 ok (bstr
->dwLen
== 2, "Expected 2, got %ld\n", bstr
->dwLen
);
4804 ok (!lstrcmpW(bstr
->szString
, szSmaller
), "String different\n");
4807 changed
= SysReAllocStringLen(&str
, szLarger
, 6);
4808 ok (changed
== 1, "Expected 1, got %d\n", changed
);
4809 /* Early versions always make new strings rather than resizing */
4810 /* ok (str == oldstr, "Created new string\n"); */
4812 ok (bstr
->dwLen
== 12, "Expected 12, got %ld\n", bstr
->dwLen
);
4813 ok (!lstrcmpW(bstr
->szString
, szLarger
), "String different\n");
4819 static void test_BstrCopy()
4821 const CHAR szTestA
[6] = { 'T','e','s','t','\0','?' };
4822 const CHAR szTestTruncA
[4] = { 'T','e','s','\0' };
4823 LPINTERNAL_BSTR bstr
;
4828 str
= SysAllocStringByteLen(szTestA
, 3);
4829 ok (str
!= NULL
, "Expected non-NULL\n");
4832 V_VT(&vt1
) = VT_BSTR
;
4834 V_VT(&vt2
) = VT_EMPTY
;
4835 hres
= VariantCopy(&vt2
, &vt1
);
4836 ok (hres
== S_OK
,"Failed to copy binary bstring with hres 0x%08lx\n", hres
);
4837 bstr
= Get(V_BSTR(&vt2
));
4838 ok (bstr
->dwLen
== 3, "Expected 3, got %ld\n", bstr
->dwLen
);
4839 ok (!lstrcmpA((LPCSTR
)bstr
->szString
, szTestTruncA
), "String different\n");
4845 static void test_IUnknownClear(void)
4849 DummyDispatch u
= { &DummyDispatch_VTable
, 1, VT_UI1
, FALSE
};
4850 IUnknown
* pu
= (IUnknown
*)&u
;
4852 /* Test that IUnknown_Release is called on by-value */
4853 V_VT(&v
) = VT_UNKNOWN
;
4854 V_UNKNOWN(&v
) = (IUnknown
*)&u
;
4855 hres
= VariantClear(&v
);
4856 ok(hres
== S_OK
&& u
.ref
== 0 && V_VT(&v
) == VT_EMPTY
,
4857 "clear unknown: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4858 S_OK
, 0, VT_EMPTY
, hres
, u
.ref
, V_VT(&v
));
4860 /* But not when clearing a by-reference*/
4862 V_VT(&v
) = VT_UNKNOWN
|VT_BYREF
;
4863 V_UNKNOWNREF(&v
) = &pu
;
4864 hres
= VariantClear(&v
);
4865 ok(hres
== S_OK
&& u
.ref
== 1 && V_VT(&v
) == VT_EMPTY
,
4866 "clear dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4867 S_OK
, 1, VT_EMPTY
, hres
, u
.ref
, V_VT(&v
));
4870 static void test_IUnknownCopy(void)
4873 VARIANTARG vSrc
, vDst
;
4874 DummyDispatch u
= { &DummyDispatch_VTable
, 1, VT_UI1
, FALSE
};
4875 IUnknown
* pu
= (IUnknown
*)&u
;
4877 /* AddRef is called on by-value copy */
4879 V_VT(&vSrc
) = VT_UNKNOWN
;
4880 V_UNKNOWN(&vSrc
) = pu
;
4881 hres
= VariantCopy(&vDst
, &vSrc
);
4882 ok(hres
== S_OK
&& u
.ref
== 2 && V_VT(&vDst
) == VT_UNKNOWN
,
4883 "copy unknown: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4884 S_OK
, 2, VT_EMPTY
, hres
, u
.ref
, V_VT(&vDst
));
4886 /* AddRef is skipped on copy of by-reference IDispatch */
4889 V_VT(&vSrc
) = VT_UNKNOWN
|VT_BYREF
;
4890 V_UNKNOWNREF(&vSrc
) = &pu
;
4891 hres
= VariantCopy(&vDst
, &vSrc
);
4892 ok(hres
== S_OK
&& u
.ref
== 1 && V_VT(&vDst
) == (VT_UNKNOWN
|VT_BYREF
),
4893 "copy unknown: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4894 S_OK
, 1, VT_DISPATCH
, hres
, u
.ref
, V_VT(&vDst
));
4896 /* AddRef is called copying by-reference IDispatch with indirection */
4899 V_VT(&vSrc
) = VT_UNKNOWN
|VT_BYREF
;
4900 V_UNKNOWNREF(&vSrc
) = &pu
;
4901 hres
= VariantCopyInd(&vDst
, &vSrc
);
4902 ok(hres
== S_OK
&& u
.ref
== 2 && V_VT(&vDst
) == VT_UNKNOWN
,
4903 "copy unknown: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4904 S_OK
, 2, VT_DISPATCH
, hres
, u
.ref
, V_VT(&vDst
));
4906 /* Indirection in place also calls AddRef */
4908 V_VT(&vSrc
) = VT_UNKNOWN
|VT_BYREF
;
4909 V_UNKNOWNREF(&vSrc
) = &pu
;
4910 hres
= VariantCopyInd(&vSrc
, &vSrc
);
4911 ok(hres
== S_OK
&& u
.ref
== 2 && V_VT(&vSrc
) == VT_UNKNOWN
,
4912 "copy unknown: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4913 S_OK
, 2, VT_DISPATCH
, hres
, u
.ref
, V_VT(&vSrc
));
4916 static void test_IUnknownChangeTypeEx(void)
4919 VARIANTARG vSrc
, vDst
;
4922 DummyDispatch u
= { &DummyDispatch_VTable
, 1, VT_UI1
, FALSE
};
4923 IUnknown
* pu
= (IUnknown
*)&u
;
4925 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
4927 V_VT(&vSrc
) = VT_UNKNOWN
;
4928 V_UNKNOWN(&vSrc
) = pu
;
4930 /* =>IDispatch in place */
4931 hres
= VariantChangeTypeEx(&vSrc
, &vSrc
, lcid
, 0, VT_DISPATCH
);
4932 ok(hres
== S_OK
&& u
.ref
== 1 &&
4933 V_VT(&vSrc
) == VT_DISPATCH
&& V_DISPATCH(&vSrc
) == (IDispatch
*)pu
,
4934 "change unk(src=src): expected 0x%08lx,%d,%d,%p, got 0x%08lx,%ld,%d,%p\n",
4935 S_OK
, 1, VT_DISPATCH
, pu
, hres
, u
.ref
, V_VT(&vSrc
), V_DISPATCH(&vSrc
));
4939 V_VT(&vSrc
) = VT_UNKNOWN
;
4940 V_UNKNOWN(&vSrc
) = (IUnknown
*)pu
;
4942 hres
= VariantChangeTypeEx(&vDst
, &vSrc
, lcid
, 0, VT_UNKNOWN
);
4943 /* Note vSrc is not cleared, as final refcount is 2 */
4944 ok(hres
== S_OK
&& u
.ref
== 2 &&
4945 V_VT(&vDst
) == VT_UNKNOWN
&& V_UNKNOWN(&vDst
) == (IUnknown
*)pu
,
4946 "change unk(src,dst): expected 0x%08lx,%d,%d,%p, got 0x%08lx,%ld,%d,%p\n",
4947 S_OK
, 2, VT_UNKNOWN
, pu
, hres
, u
.ref
, V_VT(&vDst
), V_UNKNOWN(&vDst
));
4949 /* Can't change unknown to anything else */
4950 for (vt
= 0; vt
<= VT_BSTR_BLOB
; vt
++)
4952 HRESULT hExpected
= DISP_E_BADVARTYPE
;
4954 V_VT(&vSrc
) = VT_UNKNOWN
;
4955 V_UNKNOWN(&vSrc
) = (IUnknown
*)pu
;
4958 if (vt
== VT_UNKNOWN
|| vt
== VT_DISPATCH
|| vt
== VT_EMPTY
|| vt
== VT_NULL
)
4962 if (vt
== VT_I8
|| vt
== VT_UI8
)
4964 if (HAVE_OLEAUT32_I8
)
4965 hExpected
= DISP_E_TYPEMISMATCH
;
4967 else if (vt
== VT_RECORD
)
4969 if (HAVE_OLEAUT32_RECORD
)
4970 hExpected
= DISP_E_TYPEMISMATCH
;
4972 else if (vt
>= VT_I2
&& vt
<= VT_UINT
&& vt
!= (VARTYPE
)15)
4973 hExpected
= DISP_E_TYPEMISMATCH
;
4975 if (IS_ANCIENT
&& IS_MODERN_VTYPE(vt
))
4976 hExpected
= DISP_E_BADVARTYPE
;
4978 hres
= VariantChangeTypeEx(&vDst
, &vSrc
, lcid
, 0, vt
);
4979 ok(hres
== hExpected
,
4980 "change unk(badvar): vt %d expected 0x%08lx, got 0x%08lx\n",
4981 vt
, hExpected
, hres
);
4986 static void test_IDispatchClear(void)
4990 DummyDispatch d
= { &DummyDispatch_VTable
, 1, VT_UI1
, FALSE
};
4991 IDispatch
* pd
= (IDispatch
*)&d
;
4993 /* As per IUnknown */
4995 V_VT(&v
) = VT_DISPATCH
;
4996 V_DISPATCH(&v
) = pd
;
4997 hres
= VariantClear(&v
);
4998 ok(hres
== S_OK
&& d
.ref
== 0 && V_VT(&v
) == VT_EMPTY
,
4999 "clear dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
5000 S_OK
, 0, VT_EMPTY
, hres
, d
.ref
, V_VT(&v
));
5003 V_VT(&v
) = VT_DISPATCH
|VT_BYREF
;
5004 V_DISPATCHREF(&v
) = &pd
;
5005 hres
= VariantClear(&v
);
5006 ok(hres
== S_OK
&& d
.ref
== 1 && V_VT(&v
) == VT_EMPTY
,
5007 "clear dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
5008 S_OK
, 1, VT_EMPTY
, hres
, d
.ref
, V_VT(&v
));
5011 static void test_IDispatchCopy(void)
5014 VARIANTARG vSrc
, vDst
;
5015 DummyDispatch d
= { &DummyDispatch_VTable
, 1, VT_UI1
, FALSE
};
5016 IDispatch
* pd
= (IDispatch
*)&d
;
5018 /* As per IUnknown */
5021 V_VT(&vSrc
) = VT_DISPATCH
;
5022 V_DISPATCH(&vSrc
) = pd
;
5023 hres
= VariantCopy(&vDst
, &vSrc
);
5024 ok(hres
== S_OK
&& d
.ref
== 2 && V_VT(&vDst
) == VT_DISPATCH
,
5025 "copy dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
5026 S_OK
, 2, VT_EMPTY
, hres
, d
.ref
, V_VT(&vDst
));
5030 V_VT(&vSrc
) = VT_DISPATCH
|VT_BYREF
;
5031 V_DISPATCHREF(&vSrc
) = &pd
;
5032 hres
= VariantCopy(&vDst
, &vSrc
);
5033 ok(hres
== S_OK
&& d
.ref
== 1 && V_VT(&vDst
) == (VT_DISPATCH
|VT_BYREF
),
5034 "copy dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
5035 S_OK
, 1, VT_DISPATCH
, hres
, d
.ref
, V_VT(&vDst
));
5039 V_VT(&vSrc
) = VT_DISPATCH
|VT_BYREF
;
5040 V_DISPATCHREF(&vSrc
) = &pd
;
5041 hres
= VariantCopyInd(&vDst
, &vSrc
);
5042 ok(hres
== S_OK
&& d
.ref
== 2 && V_VT(&vDst
) == VT_DISPATCH
,
5043 "copy dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
5044 S_OK
, 2, VT_DISPATCH
, hres
, d
.ref
, V_VT(&vDst
));
5047 V_VT(&vSrc
) = VT_DISPATCH
|VT_BYREF
;
5048 V_DISPATCHREF(&vSrc
) = &pd
;
5049 hres
= VariantCopyInd(&vSrc
, &vSrc
);
5050 ok(hres
== S_OK
&& d
.ref
== 2 && V_VT(&vSrc
) == VT_DISPATCH
,
5051 "copy dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
5052 S_OK
, 2, VT_DISPATCH
, hres
, d
.ref
, V_VT(&vSrc
));
5055 static void test_IDispatchChangeTypeEx(void)
5058 VARIANTARG vSrc
, vDst
;
5060 DummyDispatch d
= { &DummyDispatch_VTable
, 1, VT_UI1
, FALSE
};
5061 IDispatch
* pd
= (IDispatch
*)&d
;
5063 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
5065 V_VT(&vSrc
) = VT_DISPATCH
;
5066 V_DISPATCH(&vSrc
) = pd
;
5068 /* =>IUnknown in place */
5069 hres
= VariantChangeTypeEx(&vSrc
, &vSrc
, lcid
, 0, VT_UNKNOWN
);
5070 ok(hres
== S_OK
&& d
.ref
== 1 &&
5071 V_VT(&vSrc
) == VT_UNKNOWN
&& V_UNKNOWN(&vSrc
) == (IUnknown
*)pd
,
5072 "change disp(src=src): expected 0x%08lx,%d,%d,%p, got 0x%08lx,%ld,%d,%p\n",
5073 S_OK
, 1, VT_UNKNOWN
, pd
, hres
, d
.ref
, V_VT(&vSrc
), V_UNKNOWN(&vSrc
));
5077 V_VT(&vSrc
) = VT_DISPATCH
;
5078 V_DISPATCH(&vSrc
) = pd
;
5080 hres
= VariantChangeTypeEx(&vDst
, &vSrc
, lcid
, 0, VT_UNKNOWN
);
5081 /* Note vSrc is not cleared, as final refcount is 2 */
5082 ok(hres
== S_OK
&& d
.ref
== 2 &&
5083 V_VT(&vDst
) == VT_UNKNOWN
&& V_UNKNOWN(&vDst
) == (IUnknown
*)pd
,
5084 "change disp(src,dst): expected 0x%08lx,%d,%d,%p, got 0x%08lx,%ld,%d,%p\n",
5085 S_OK
, 2, VT_UNKNOWN
, pd
, hres
, d
.ref
, V_VT(&vDst
), V_UNKNOWN(&vDst
));
5087 /* FIXME: Verify that VARIANT_NOVALUEPROP prevents conversion to integral
5088 * types. this requires that the xxxFromDisp tests work first.
5093 static void test_ErrorChangeTypeEx(void)
5096 VARIANTARG vSrc
, vDst
;
5100 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
5102 for (vt
= 0; vt
<= VT_BSTR_BLOB
; vt
++)
5104 HRESULT hExpected
= DISP_E_BADVARTYPE
;
5106 V_VT(&vSrc
) = VT_ERROR
;
5109 hres
= VariantChangeTypeEx(&vDst
, &vSrc
, lcid
, 0, vt
);
5115 if (vt
== VT_I8
|| vt
== VT_UI8
)
5117 if (HAVE_OLEAUT32_I8
)
5118 hExpected
= DISP_E_TYPEMISMATCH
;
5120 else if (vt
== VT_RECORD
)
5122 if (HAVE_OLEAUT32_RECORD
)
5123 hExpected
= DISP_E_TYPEMISMATCH
;
5125 else if (vt
<= VT_UINT
&& vt
!= (VARTYPE
)15)
5126 hExpected
= DISP_E_TYPEMISMATCH
;
5128 if (IS_ANCIENT
&& IS_MODERN_VTYPE(vt
))
5129 hExpected
= DISP_E_BADVARTYPE
;
5131 ok(hres
== hExpected
,
5132 "change err: vt %d expected 0x%08lx, got 0x%08lx\n", vt
, hExpected
, hres
);
5137 static void test_EmptyChangeTypeEx(void)
5140 VARIANTARG vSrc
, vDst
;
5144 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
5146 for (vt
= 0; vt
<= VT_BSTR_BLOB
; vt
++)
5148 HRESULT hExpected
= DISP_E_BADVARTYPE
;
5151 memset(&vDst
, 0, sizeof(vDst
));
5152 V_VT(&vDst
) = VT_EMPTY
;
5154 if (vt
== VT_I8
|| vt
== VT_UI8
)
5156 if (HAVE_OLEAUT32_I8
)
5159 else if (vt
== VT_RECORD
)
5161 if (HAVE_OLEAUT32_RECORD
)
5162 hExpected
= DISP_E_TYPEMISMATCH
;
5164 else if (vt
== VT_VARIANT
|| vt
== VT_DISPATCH
||
5165 vt
== VT_UNKNOWN
|| vt
== VT_ERROR
)
5167 hExpected
= DISP_E_TYPEMISMATCH
;
5169 else if (vt
<= VT_UINT
&& vt
!= (VARTYPE
)15)
5172 if (IS_ANCIENT
&& IS_MODERN_VTYPE(vt
))
5173 hExpected
= DISP_E_BADVARTYPE
;
5175 hres
= VariantChangeTypeEx(&vDst
, &vSrc
, lcid
, 0, vt
);
5177 ok(hres
== hExpected
&& (hres
!= S_OK
|| V_VT(&vDst
) == vt
),
5178 "change empty: vt %d expected 0x%08lx, got 0x%08lx, vt %d\n",
5179 vt
, hExpected
, hres
, V_VT(&vDst
));
5184 static void test_NullChangeTypeEx(void)
5187 VARIANTARG vSrc
, vDst
;
5191 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
5193 for (vt
= 0; vt
<= VT_BSTR_BLOB
; vt
++)
5195 HRESULT hExpected
= DISP_E_BADVARTYPE
;
5198 V_VT(&vSrc
) = VT_NULL
;
5199 memset(&vDst
, 0, sizeof(vDst
));
5200 V_VT(&vDst
) = VT_EMPTY
;
5202 if (vt
== VT_I8
|| vt
== VT_UI8
)
5204 if (HAVE_OLEAUT32_I8
)
5205 hExpected
= DISP_E_TYPEMISMATCH
;
5207 else if (vt
== VT_RECORD
)
5209 if (HAVE_OLEAUT32_RECORD
)
5210 hExpected
= DISP_E_TYPEMISMATCH
;
5212 else if (vt
== VT_NULL
)
5216 else if (vt
== VT_VARIANT
|| vt
== VT_DISPATCH
||
5217 vt
== VT_UNKNOWN
|| vt
== VT_ERROR
||
5218 (vt
<= VT_UINT
&& vt
!= (VARTYPE
)15))
5219 hExpected
= DISP_E_TYPEMISMATCH
;
5221 if (IS_ANCIENT
&& IS_MODERN_VTYPE(vt
))
5222 hExpected
= DISP_E_BADVARTYPE
;
5224 hres
= VariantChangeTypeEx(&vDst
, &vSrc
, lcid
, 0, vt
);
5226 ok(hres
== hExpected
&& (hres
!= S_OK
|| V_VT(&vDst
) == vt
),
5227 "change null: vt %d expected 0x%08lx, got 0x%08lx, vt %d\n",
5228 vt
, hExpected
, hres
, V_VT(&vDst
));
5234 static void test_UintChangeTypeEx(void)
5237 VARIANTARG vSrc
, vDst
;
5240 lcid
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
5242 /* Converting a VT_UINT to a VT_INT does not check for overflow */
5243 V_VT(&vDst
) = VT_EMPTY
;
5244 V_VT(&vSrc
) = VT_UINT
;
5246 hres
= VariantChangeTypeEx(&vDst
, &vSrc
, lcid
, 0, VT_I4
);
5247 ok(hres
== S_OK
&& V_VT(&vDst
) == VT_I4
&& V_I4(&vDst
) == -1,
5248 "change uint: Expected %d,0x%08lx,%d got %d,0x%08lx,%ld\n",
5249 VT_I4
, S_OK
, -1, V_VT(&vDst
), hres
, V_I4(&vDst
));
5252 #define NUM_CUST_ITEMS 16
5254 static void test_ClearCustData(void)
5256 WCHAR buff
[sizeof(CUSTDATAITEM
) * NUM_CUST_ITEMS
/ sizeof(WCHAR
)];
5260 CHECKPTR(ClearCustData
);
5262 memset(buff
, 0, sizeof(buff
));
5264 ci
.cCustData
= NUM_CUST_ITEMS
;
5265 /* This is a bit tricky. We use SysAllocStringByteLen to allocate the
5266 * array, since native uses an internal IMalloc interface for allocating
5267 * its memory, while Wine uses HeapAlloc(). Doing this ensures we allocate
5268 * using the correct function whether with native or builtin.
5270 ci
.prgCustData
= (LPCUSTDATAITEM
)SysAllocStringByteLen((LPCSTR
)buff
, sizeof(buff
));
5271 for (i
= 0; i
< NUM_CUST_ITEMS
; i
++)
5272 VariantInit(&ci
.prgCustData
[i
].varValue
);
5273 pClearCustData(&ci
);
5274 ok(!ci
.cCustData
&& !ci
.prgCustData
, "ClearCustData didn't clear fields!\n");
5277 static void test_NullByRef()
5284 V_VT(&v1
) = VT_BYREF
|VT_VARIANT
;
5287 hRes
= VariantChangeTypeEx(&v2
, &v1
, 0, 0, VT_I4
);
5288 ok(hRes
== DISP_E_TYPEMISMATCH
, "VariantChangeTypeEx should return DISP_E_TYPEMISMATCH\n");
5291 V_VT(&v1
) = VT_BYREF
|VT_VARIANT
;
5296 hRes
= VariantChangeTypeEx(&v2
, &v1
, 0, 0, VT_VARIANT
);
5297 ok(hRes
== DISP_E_TYPEMISMATCH
, "VariantChangeTypeEx should return DISP_E_TYPEMISMATCH\n");
5298 ok(V_VT(&v2
) == VT_I4
&& V_I4(&v2
) == 123, "VariantChangeTypeEx shouldn't change pvargDest\n");
5300 hRes
= VariantChangeTypeEx(&v2
, &v1
, 0, 0, VT_BYREF
|VT_I4
);
5301 ok(hRes
== DISP_E_TYPEMISMATCH
, "VariantChangeTypeEx should return DISP_E_TYPEMISMATCH\n");
5303 hRes
= VariantChangeTypeEx(&v2
, &v1
, 0, 0, 0x3847);
5304 ok(hRes
== DISP_E_BADVARTYPE
, "VariantChangeTypeEx should return DISP_E_BADVARTYPE\n");
5309 hOleaut32
= LoadLibraryA("oleaut32.dll");
5310 ok(hOleaut32
!= 0, "Failed to load oleaut32.dll\n");
5314 trace("LCID's: System=0x%08lx, User=0x%08lx\n", GetSystemDefaultLCID(),
5315 GetUserDefaultLCID());
5320 test_VarI1FromUI1();
5321 test_VarI1FromUI2();
5322 test_VarI1FromUI4();
5323 test_VarI1FromUI8();
5324 test_VarI1FromBool();
5327 test_VarI1FromDate();
5329 test_VarI1FromDec();
5330 test_VarI1FromStr();
5331 test_VarUI1FromDisp();
5333 test_VarI1ChangeTypeEx();
5335 test_VarUI1FromI1();
5336 test_VarUI1FromI2();
5337 test_VarUI1FromI4();
5338 test_VarUI1FromI8();
5339 test_VarUI1FromUI2();
5340 test_VarUI1FromUI4();
5341 test_VarUI1FromUI8();
5342 test_VarUI1FromBool();
5343 test_VarUI1FromR4();
5344 test_VarUI1FromR8();
5345 test_VarUI1FromDate();
5346 test_VarUI1FromCy();
5347 test_VarUI1FromDec();
5348 test_VarUI1FromStr();
5350 test_VarUI1ChangeTypeEx();
5355 test_VarI2FromUI1();
5356 test_VarI2FromUI2();
5357 test_VarI2FromUI4();
5358 test_VarI2FromUI8();
5359 test_VarI2FromBool();
5362 test_VarI2FromDate();
5364 test_VarI2FromDec();
5365 test_VarI2FromStr();
5367 test_VarI2ChangeTypeEx();
5369 test_VarUI2FromI1();
5370 test_VarUI2FromI2();
5371 test_VarUI2FromI4();
5372 test_VarUI2FromI8();
5373 test_VarUI2FromUI1();
5374 test_VarUI2FromUI4();
5375 test_VarUI2FromUI8();
5376 test_VarUI2FromBool();
5377 test_VarUI2FromR4();
5378 test_VarUI2FromR8();
5379 test_VarUI2FromDate();
5380 test_VarUI2FromCy();
5381 test_VarUI2FromDec();
5382 test_VarUI2FromStr();
5384 test_VarUI2ChangeTypeEx();
5389 test_VarI4FromUI1();
5390 test_VarI4FromUI2();
5391 test_VarI4FromUI4();
5392 test_VarI4FromUI8();
5393 test_VarI4FromBool();
5396 test_VarI4FromDate();
5398 test_VarI4FromDec();
5399 test_VarI4FromStr();
5401 test_VarI4ChangeTypeEx();
5403 test_VarUI4FromI1();
5404 test_VarUI4FromI2();
5405 test_VarUI4FromUI2();
5406 test_VarUI4FromI8();
5407 test_VarUI4FromUI1();
5408 test_VarUI4FromI4();
5409 test_VarUI4FromUI8();
5410 test_VarUI4FromBool();
5411 test_VarUI4FromR4();
5412 test_VarUI4FromR8();
5413 test_VarUI4FromDate();
5414 test_VarUI4FromCy();
5415 test_VarUI4FromDec();
5416 test_VarUI4FromStr();
5418 test_VarUI4ChangeTypeEx();
5421 test_VarI8FromUI1();
5423 test_VarI8FromUI2();
5424 test_VarI8FromUI4();
5427 test_VarI8FromBool();
5428 test_VarI8FromUI8();
5430 test_VarI8FromDec();
5431 test_VarI8FromDate();
5432 test_VarI8FromStr();
5434 test_VarI8ChangeTypeEx();
5436 test_VarUI8FromI1();
5437 test_VarUI8FromUI1();
5438 test_VarUI8FromI2();
5439 test_VarUI8FromUI2();
5440 test_VarUI8FromUI4();
5441 test_VarUI8FromR4();
5442 test_VarUI8FromR8();
5443 test_VarUI8FromBool();
5444 test_VarUI8FromI8();
5445 test_VarUI8FromCy();
5446 test_VarUI8FromDec();
5447 test_VarUI8FromDate();
5448 test_VarUI8FromStr();
5450 test_VarUI8ChangeTypeEx();
5453 test_VarR4FromUI1();
5455 test_VarR4FromUI2();
5457 test_VarR4FromUI4();
5459 test_VarR4FromBool();
5462 test_VarR4FromUI8();
5463 test_VarR4FromDec();
5464 test_VarR4FromDate();
5465 test_VarR4FromStr();
5467 test_VarR4ChangeTypeEx();
5470 test_VarR8FromUI1();
5472 test_VarR8FromUI2();
5474 test_VarR8FromUI4();
5476 test_VarR8FromBool();
5479 test_VarR8FromUI8();
5480 test_VarR8FromDec();
5481 test_VarR8FromDate();
5482 test_VarR8FromStr();
5484 test_VarR8ChangeTypeEx();
5487 test_VarDateFromI1();
5488 test_VarDateFromUI1();
5489 test_VarDateFromI2();
5490 test_VarDateFromUI2();
5491 test_VarDateFromI4();
5492 test_VarDateFromUI4();
5493 test_VarDateFromR4();
5494 test_VarDateFromR8();
5495 test_VarDateFromBool();
5496 test_VarDateFromCy();
5497 test_VarDateFromI8();
5498 test_VarDateFromUI8();
5499 test_VarDateFromDec();
5500 test_VarDateFromStr();
5502 test_VarDateChangeTypeEx();
5505 test_VarCyFromUI1();
5507 test_VarCyFromUI2();
5509 test_VarCyFromUI4();
5512 test_VarCyFromBool();
5514 test_VarCyFromUI8();
5515 test_VarCyFromDec();
5516 test_VarCyFromDate();
5531 test_VarDecFromI1();
5532 test_VarDecFromI2();
5533 test_VarDecFromI4();
5534 test_VarDecFromI8();
5535 test_VarDecFromUI1();
5536 test_VarDecFromUI2();
5537 test_VarDecFromUI4();
5538 test_VarDecFromUI8();
5539 test_VarDecFromR4();
5540 test_VarDecFromR8();
5541 test_VarDecFromDate();
5542 test_VarDecFromStr();
5543 test_VarDecFromCy();
5544 test_VarDecFromDate();
5545 test_VarDecFromBool();
5553 test_VarBoolFromI1();
5554 test_VarBoolFromUI1();
5555 test_VarBoolFromI2();
5556 test_VarBoolFromUI2();
5557 test_VarBoolFromI4();
5558 test_VarBoolFromUI4();
5559 test_VarBoolFromR4();
5560 test_VarBoolFromR8();
5561 test_VarBoolFromCy();
5562 test_VarBoolFromI8();
5563 test_VarBoolFromUI8();
5564 test_VarBoolFromDec();
5565 test_VarBoolFromDate();
5566 test_VarBoolFromStr();
5568 test_VarBoolChangeTypeEx();
5570 test_VarBstrFromR4();
5571 test_VarBstrFromDate();
5572 test_SysStringLen();
5573 test_SysStringByteLen();
5574 test_SysAllocString();
5575 test_SysAllocStringLen();
5576 test_SysAllocStringByteLen();
5577 test_SysReAllocString();
5578 test_SysReAllocStringLen();
5581 test_IUnknownClear();
5582 test_IUnknownCopy();
5583 test_IUnknownChangeTypeEx();
5585 test_IDispatchClear();
5586 test_IDispatchCopy();
5587 test_IDispatchChangeTypeEx();
5589 test_ErrorChangeTypeEx();
5590 test_EmptyChangeTypeEx();
5591 test_NullChangeTypeEx();
5592 test_UintChangeTypeEx();
5594 test_ClearCustData();