2 * Low level variant tests
4 * Copyright 2003 Jon Griffiths
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/test.h"
25 /* Some Visual C++ versions choke on __uint64 to float conversions.
26 * To fix this you need either VC++ 6.0 plus the processor pack
27 * or Visual C++ >=7.0.
30 # define HAS_UINT64_TO_FLOAT
33 # define HAS_UINT64_TO_FLOAT
36 # if defined(_mm_free)
37 /* _mm_free is defined if the Processor Pack has been installed */
38 # define HAS_UINT64_TO_FLOAT
44 static HMODULE hOleaut32;
46 /* Get a conversion function ptr, return if function not available */
47 #define CHECKPTR(func) p##func = (void*)GetProcAddress(hOleaut32, #func); \
49 trace("function " # func " not available, not testing it\n"); return; }
51 /* Is a given function exported from oleaut32? */
52 #define HAVE_FUNC(func) ((void*)GetProcAddress(hOleaut32, #func) != NULL)
54 /* Have IRecordInfo data type? */
55 #define HAVE_OLEAUT32_RECORD HAVE_FUNC(SafeArraySetRecordInfo)
56 /* Have DECIMAL data type with new error checking? */
57 #define HAVE_OLEAUT32_DECIMAL HAVE_FUNC(VarDecAdd)
58 /* Have CY data type? */
59 #define HAVE_OLEAUT32_CY HAVE_FUNC(VarCyAdd)
60 /* Have I8/UI8 data type? */
61 #define HAVE_OLEAUT32_I8 HAVE_FUNC(VarI8FromI1)
62 /* Have proper locale conversions? */
63 #define HAVE_OLEAUT32_LOCALES (HAVE_FUNC(GetVarConversionLocaleSetting) && HAVE_OLEAUT32_I8)
64 /* Is this an ancient version with support for only I2/I4/R4/R8/DATE? */
65 #define IS_ANCIENT (!HAVE_FUNC(VarI1FromI2))
66 /* Is vt a type unavailable to ancient versions? */
67 #define IS_MODERN_VTYPE(vt) (vt==VT_VARIANT||vt==VT_DECIMAL|| \
68 vt==VT_I1||vt==VT_UI2||vt==VT_UI4||vt == VT_INT||vt == VT_UINT)
70 /* Macros for converting and testing results */
71 #define CONVVARS(typ) HRESULT hres; CONV_TYPE out; typ in
73 #define _EXPECTRES(res, x, fs) \
74 ok((hres == S_OK && out == (CONV_TYPE)(x)) || ((HRESULT)res != S_OK && hres == (HRESULT)res), \
75 "expected " #x ", got " fs "; hres=0x%08x\n", out, hres)
76 #define EXPECT(x) EXPECTRES(S_OK, (x))
77 #define EXPECT_OVERFLOW EXPECTRES(DISP_E_OVERFLOW, DISP_E_OVERFLOW)
78 #define EXPECT_MISMATCH EXPECTRES(DISP_E_TYPEMISMATCH,DISP_E_TYPEMISMATCH)
79 #define EXPECT_BADVAR EXPECTRES(DISP_E_BADVARTYPE, DISP_E_BADVARTYPE)
80 #define EXPECT_INVALID EXPECTRES(E_INVALIDARG, E_INVALIDARG)
81 #define EXPECT_LT EXPECTRES(VARCMP_LT, VARCMP_LT)
82 #define EXPECT_GT EXPECTRES(VARCMP_GT, VARCMP_GT)
83 #define EXPECT_EQ EXPECTRES(VARCMP_EQ, VARCMP_EQ)
84 #define EXPECT_DBL(x) \
85 ok(hres == S_OK && fabs(out-(x))<=1e-14*(x), "expected %16.16g, got %16.16g; hres=0x%08x\n", (x), out, hres)
87 #define CONVERT(func, val) in = val; hres = p##func(in, &out)
88 #define CONVERTRANGE(func,start,end) for (i = start; i < end; i+=1) { CONVERT(func, i); EXPECT(i); };
89 #define OVERFLOWRANGE(func,start,end) for (i = start; i < end; i+=1) { CONVERT(func, i); EXPECT_OVERFLOW; };
91 #define CY_MULTIPLIER 10000
93 #define DATE_MIN -657434
94 #define DATE_MAX 2958465
96 #define CONVERT_I8(func,hi,lo) in = hi; in = (in << 32) | lo; hres = p##func(in, &out)
98 #define CONVERT_CY(func,val) in.int64 = (LONGLONG)(val * CY_MULTIPLIER); hres = p##func(in, &out)
100 #define CONVERT_CY64(func,hi,lo) S(in).Hi = hi; S(in).Lo = lo; in.int64 *= CY_MULTIPLIER; hres = p##func(in, &out)
102 #define SETDEC(dec, scl, sgn, hi, lo) S(U(dec)).scale = (BYTE)scl; S(U(dec)).sign = (BYTE)sgn; \
103 dec.Hi32 = (ULONG)hi; U1(dec).Lo64 = (ULONG64)lo
105 #define SETDEC64(dec, scl, sgn, hi, mid, lo) S(U(dec)).scale = (BYTE)scl; S(U(dec)).sign = (BYTE)sgn; \
106 dec.Hi32 = (ULONG)hi; S1(U1(dec)).Mid32 = mid; S1(U1(dec)).Lo32 = lo;
108 #define CONVERT_DEC(func,scl,sgn,hi,lo) SETDEC(in,scl,sgn,hi,lo); hres = p##func(&in, &out)
110 #define CONVERT_DEC64(func,scl,sgn,hi,mid,lo) SETDEC64(in,scl,sgn,hi,mid,lo); hres = p##func(&in, &out)
112 #define CONVERT_BADDEC(func) \
113 if (HAVE_OLEAUT32_DECIMAL) \
115 CONVERT_DEC(func,29,0,0,0); EXPECT_INVALID; \
116 CONVERT_DEC(func,0,0x1,0,0); EXPECT_INVALID; \
117 CONVERT_DEC(func,0,0x40,0,0); EXPECT_INVALID; \
118 CONVERT_DEC(func,0,0x7f,0,0); EXPECT_INVALID; \
121 #define CONVERT_STR(func,str,flags) \
123 if (str) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)/sizeof(WCHAR)); \
124 hres = p##func(str ? buff : NULL,in,flags,&out)
126 #define COPYTEST(val, vt, srcval, dstval, srcref, dstref, fs) do { \
127 HRESULT hres; VARIANTARG vSrc, vDst; CONV_TYPE in = val; \
128 VariantInit(&vSrc); VariantInit(&vDst); \
129 V_VT(&vSrc) = vt; srcval = in; \
130 hres = VariantCopy(&vDst, &vSrc); \
131 ok(hres == S_OK && V_VT(&vDst) == vt && dstval == in, \
132 "copy hres 0x%X, type %d, value (" fs ") " fs "\n", hres, V_VT(&vDst), val, dstval); \
133 V_VT(&vSrc) = vt|VT_BYREF; srcref = ∈ \
134 hres = VariantCopy(&vDst, &vSrc); \
135 ok(hres == S_OK && V_VT(&vDst) == (vt|VT_BYREF) && dstref == &in, \
136 "ref hres 0x%X, type %d, ref (%p) %p\n", hres, V_VT(&vDst), &in, dstref); \
137 hres = VariantCopyInd(&vDst, &vSrc); \
138 ok(hres == S_OK && V_VT(&vDst) == vt && dstval == in, \
139 "ind hres 0x%X, type %d, value (" fs ") " fs "\n", hres, V_VT(&vDst), val, dstval); \
142 #define CHANGETYPEEX(typ) hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, typ)
144 #define TYPETEST(typ,res,fs) CHANGETYPEEX(typ); \
145 ok(hres == S_OK && V_VT(&vDst) == typ && (CONV_TYPE)res == in, \
146 "hres=0x%X, type=%d (should be %d(" #typ ")), value=" fs " (should be " fs ")\n", \
147 hres, V_VT(&vDst), typ, (CONV_TYPE)res, in);
148 #define TYPETESTI8(typ,res) CHANGETYPEEX(typ); \
149 ok(hres == S_OK && V_VT(&vDst) == typ && (CONV_TYPE)res == in, \
150 "hres=0x%X, type=%d (should be %d(" #typ ")), value=%d (should be 1)\n", \
151 hres, V_VT(&vDst), typ, (int)res);
152 #define BADVAR(typ) CHANGETYPEEX(typ); out = (CONV_TYPE)hres; EXPECT_BADVAR
153 #define MISMATCH(typ) CHANGETYPEEX(typ); out = (CONV_TYPE)hres; EXPECT_MISMATCH
155 #define INITIAL_TYPETEST(vt, val, fs) \
156 VariantInit(&vSrc); \
157 VariantInit(&vDst); \
161 TYPETEST(VT_I1, V_I1(&vDst), fs); \
162 TYPETEST(VT_UI2, V_UI2(&vDst), fs); \
163 TYPETEST(VT_UI4, V_UI4(&vDst), fs); \
164 TYPETEST(VT_INT, V_INT(&vDst), fs); \
165 TYPETEST(VT_UINT, V_UINT(&vDst), fs); \
167 BADVAR(VT_I1); BADVAR(VT_UI2); BADVAR(VT_UI4); \
168 BADVAR(VT_INT); BADVAR(VT_UINT); \
170 TYPETEST(VT_UI1, V_UI1(&vDst), fs); \
171 TYPETEST(VT_I2, V_I2(&vDst), fs); \
172 TYPETEST(VT_I4, V_I4(&vDst), fs); \
173 TYPETEST(VT_R4, V_R4(&vDst), fs); \
174 TYPETEST(VT_R8, V_R8(&vDst), fs); \
175 TYPETEST(VT_DATE, V_DATE(&vDst), fs); \
176 if (HAVE_OLEAUT32_I8) \
178 TYPETEST(VT_I8, V_I8(&vDst), fs); \
179 TYPETEST(VT_UI8, V_UI8(&vDst), fs); \
181 #define NEGATIVE_TYPETEST(vt, val, fs, vtneg, valneg) \
183 VariantInit(&vSrc); \
184 VariantInit(&vDst); \
188 TYPETEST(vtneg, valneg(&vDst), fs); \
191 #define INITIAL_TYPETESTI8(vt, val) \
192 VariantInit(&vSrc); \
193 VariantInit(&vDst); \
196 TYPETESTI8(VT_I1, V_I1(&vDst)); \
197 TYPETESTI8(VT_UI1, V_UI1(&vDst)); \
198 TYPETESTI8(VT_I2, V_I2(&vDst)); \
199 TYPETESTI8(VT_UI2, V_UI2(&vDst)); \
200 TYPETESTI8(VT_I4, V_I4(&vDst)); \
201 TYPETESTI8(VT_UI4, V_UI4(&vDst)); \
202 TYPETESTI8(VT_INT, V_INT(&vDst)); \
203 TYPETESTI8(VT_UINT, V_UINT(&vDst)); \
204 TYPETESTI8(VT_R4, V_R4(&vDst)); \
205 TYPETESTI8(VT_R8, V_R8(&vDst)); \
206 TYPETESTI8(VT_DATE, V_DATE(&vDst)); \
207 TYPETESTI8(VT_I8, V_I8(&vDst)); \
208 TYPETESTI8(VT_UI8, V_UI8(&vDst))
210 #define COMMON_TYPETEST \
211 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_BOOL); \
212 ok(hres == S_OK && V_VT(&vDst) == VT_BOOL && \
213 (V_BOOL(&vDst) == VARIANT_TRUE || (V_VT(&vSrc) == VT_BOOL && V_BOOL(&vDst) == 1)), \
214 "->VT_BOOL hres=0x%X, type=%d (should be VT_BOOL), value %d (should be VARIANT_TRUE)\n", \
215 hres, V_VT(&vDst), V_BOOL(&vDst)); \
216 if (HAVE_OLEAUT32_CY) \
218 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_CY); \
219 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == CY_MULTIPLIER, \
220 "->VT_CY hres=0x%X, type=%d (should be VT_CY), value (%08x,%08x) (should be CY_MULTIPLIER)\n", \
221 hres, V_VT(&vDst), S(V_CY(&vDst)).Hi, S(V_CY(&vDst)).Lo); \
223 if (V_VT(&vSrc) != VT_DATE) \
225 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_BSTR); \
226 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && \
227 V_BSTR(&vDst) && V_BSTR(&vDst)[0] == '1' && V_BSTR(&vDst)[1] == '\0', \
228 "->VT_BSTR hres=0x%X, type=%d (should be VT_BSTR), *bstr='%c'\n", \
229 hres, V_VT(&vDst), V_BSTR(&vDst) ? *V_BSTR(&vDst) : '?'); \
231 if (HAVE_OLEAUT32_DECIMAL) \
233 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_DECIMAL); \
234 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && \
235 S(U(V_DECIMAL(&vDst))).sign == 0 && S(U(V_DECIMAL(&vDst))).scale == 0 && \
236 V_DECIMAL(&vDst).Hi32 == 0 && U1(V_DECIMAL(&vDst)).Lo64 == (ULONGLONG)in, \
237 "->VT_DECIMAL hres=0x%X, type=%d (should be VT_DECIMAL), sign=%d, scale=%d, hi=%u, lo=(%8x %8x),\n", \
238 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign, S(U(V_DECIMAL(&vDst))).scale, \
239 V_DECIMAL(&vDst).Hi32, S1(U1(V_DECIMAL(&vDst))).Mid32, S1(U1(V_DECIMAL(&vDst))).Lo32); \
241 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_EMPTY); \
242 ok(hres == S_OK && V_VT(&vDst) == VT_EMPTY, "->VT_EMPTY hres=0x%X, type=%d (should be VT_EMPTY)\n", hres, V_VT(&vDst)); \
243 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_NULL); \
244 ok(hres == S_OK && V_VT(&vDst) == VT_NULL, "->VT_NULL hres=0x%X, type=%d (should be VT_NULL)\n", hres, V_VT(&vDst)); \
245 MISMATCH(VT_DISPATCH); \
246 MISMATCH(VT_ERROR); \
247 MISMATCH(VT_UNKNOWN); \
248 if (!IS_ANCIENT) { MISMATCH(VT_VARIANT); } else { BADVAR(VT_VARIANT); } \
249 if (HAVE_OLEAUT32_RECORD) \
251 MISMATCH(VT_RECORD); \
254 BADVAR(VT_HRESULT); \
255 BADVAR(VT_SAFEARRAY); \
257 BADVAR(VT_USERDEFINED); \
261 BADVAR(VT_INT_PTR); \
262 BADVAR(VT_UINT_PTR); \
263 BADVAR(VT_FILETIME); \
266 BADVAR(VT_STORAGE); \
267 BADVAR(VT_STREAMED_OBJECT); \
268 BADVAR(VT_STORED_OBJECT); \
269 BADVAR(VT_BLOB_OBJECT); \
274 /* Early versions of oleaut32 are missing many functions */
275 static HRESULT (WINAPI *pVarI1FromUI1)(BYTE,signed char*);
276 static HRESULT (WINAPI *pVarI1FromI2)(SHORT,signed char*);
277 static HRESULT (WINAPI *pVarI1FromI4)(LONG,signed char*);
278 static HRESULT (WINAPI *pVarI1FromR4)(FLOAT,signed char*);
279 static HRESULT (WINAPI *pVarI1FromR8)(double,signed char*);
280 static HRESULT (WINAPI *pVarI1FromDate)(DATE,signed char*);
281 static HRESULT (WINAPI *pVarI1FromCy)(CY,signed char*);
282 static HRESULT (WINAPI *pVarI1FromStr)(OLECHAR*,LCID,ULONG,signed char*);
283 static HRESULT (WINAPI *pVarI1FromBool)(VARIANT_BOOL,signed char*);
284 static HRESULT (WINAPI *pVarI1FromUI2)(USHORT,signed char*);
285 static HRESULT (WINAPI *pVarI1FromUI4)(ULONG,signed char*);
286 static HRESULT (WINAPI *pVarI1FromDec)(DECIMAL*,signed char*);
287 static HRESULT (WINAPI *pVarI1FromI8)(LONG64,signed char*);
288 static HRESULT (WINAPI *pVarI1FromUI8)(ULONG64,signed char*);
289 static HRESULT (WINAPI *pVarUI1FromI2)(SHORT,BYTE*);
290 static HRESULT (WINAPI *pVarUI1FromI4)(LONG,BYTE*);
291 static HRESULT (WINAPI *pVarUI1FromR4)(FLOAT,BYTE*);
292 static HRESULT (WINAPI *pVarUI1FromR8)(double,BYTE*);
293 static HRESULT (WINAPI *pVarUI1FromCy)(CY,BYTE*);
294 static HRESULT (WINAPI *pVarUI1FromDate)(DATE,BYTE*);
295 static HRESULT (WINAPI *pVarUI1FromStr)(OLECHAR*,LCID,ULONG,BYTE*);
296 static HRESULT (WINAPI *pVarUI1FromBool)(VARIANT_BOOL,BYTE*);
297 static HRESULT (WINAPI *pVarUI1FromI1)(signed char,BYTE*);
298 static HRESULT (WINAPI *pVarUI1FromUI2)(USHORT,BYTE*);
299 static HRESULT (WINAPI *pVarUI1FromUI4)(ULONG,BYTE*);
300 static HRESULT (WINAPI *pVarUI1FromDec)(DECIMAL*,BYTE*);
301 static HRESULT (WINAPI *pVarUI1FromI8)(LONG64,BYTE*);
302 static HRESULT (WINAPI *pVarUI1FromUI8)(ULONG64,BYTE*);
303 static HRESULT (WINAPI *pVarUI1FromDisp)(IDispatch*,LCID,BYTE*);
305 static HRESULT (WINAPI *pVarI2FromUI1)(BYTE,SHORT*);
306 static HRESULT (WINAPI *pVarI2FromI4)(LONG,SHORT*);
307 static HRESULT (WINAPI *pVarI2FromR4)(FLOAT,SHORT*);
308 static HRESULT (WINAPI *pVarI2FromR8)(double,SHORT*);
309 static HRESULT (WINAPI *pVarI2FromCy)(CY,SHORT*);
310 static HRESULT (WINAPI *pVarI2FromDate)(DATE,SHORT*);
311 static HRESULT (WINAPI *pVarI2FromStr)(OLECHAR*,LCID,ULONG,SHORT*);
312 static HRESULT (WINAPI *pVarI2FromBool)(VARIANT_BOOL,SHORT*);
313 static HRESULT (WINAPI *pVarI2FromI1)(signed char,SHORT*);
314 static HRESULT (WINAPI *pVarI2FromUI2)(USHORT,SHORT*);
315 static HRESULT (WINAPI *pVarI2FromUI4)(ULONG,SHORT*);
316 static HRESULT (WINAPI *pVarI2FromDec)(DECIMAL*,SHORT*);
317 static HRESULT (WINAPI *pVarI2FromI8)(LONG64,SHORT*);
318 static HRESULT (WINAPI *pVarI2FromUI8)(ULONG64,SHORT*);
319 static HRESULT (WINAPI *pVarUI2FromUI1)(BYTE,USHORT*);
320 static HRESULT (WINAPI *pVarUI2FromI2)(SHORT,USHORT*);
321 static HRESULT (WINAPI *pVarUI2FromI4)(LONG,USHORT*);
322 static HRESULT (WINAPI *pVarUI2FromR4)(FLOAT,USHORT*);
323 static HRESULT (WINAPI *pVarUI2FromR8)(double,USHORT*);
324 static HRESULT (WINAPI *pVarUI2FromDate)(DATE,USHORT*);
325 static HRESULT (WINAPI *pVarUI2FromCy)(CY,USHORT*);
326 static HRESULT (WINAPI *pVarUI2FromStr)(OLECHAR*,LCID,ULONG,USHORT*);
327 static HRESULT (WINAPI *pVarUI2FromBool)(VARIANT_BOOL,USHORT*);
328 static HRESULT (WINAPI *pVarUI2FromI1)(signed char,USHORT*);
329 static HRESULT (WINAPI *pVarUI2FromUI4)(ULONG,USHORT*);
330 static HRESULT (WINAPI *pVarUI2FromDec)(DECIMAL*,USHORT*);
331 static HRESULT (WINAPI *pVarUI2FromI8)(LONG64,USHORT*);
332 static HRESULT (WINAPI *pVarUI2FromUI8)(ULONG64,USHORT*);
334 static HRESULT (WINAPI *pVarI4FromUI1)(BYTE,LONG*);
335 static HRESULT (WINAPI *pVarI4FromI2)(SHORT,LONG*);
336 static HRESULT (WINAPI *pVarI4FromR4)(FLOAT,LONG*);
337 static HRESULT (WINAPI *pVarI4FromR8)(DOUBLE,LONG*);
338 static HRESULT (WINAPI *pVarI4FromCy)(CY,LONG*);
339 static HRESULT (WINAPI *pVarI4FromDate)(DATE,LONG*);
340 static HRESULT (WINAPI *pVarI4FromStr)(OLECHAR*,LCID,ULONG,LONG*);
341 static HRESULT (WINAPI *pVarI4FromBool)(VARIANT_BOOL,LONG*);
342 static HRESULT (WINAPI *pVarI4FromI1)(signed char,LONG*);
343 static HRESULT (WINAPI *pVarI4FromUI2)(USHORT,LONG*);
344 static HRESULT (WINAPI *pVarI4FromUI4)(ULONG,LONG*);
345 static HRESULT (WINAPI *pVarI4FromDec)(DECIMAL*,LONG*);
346 static HRESULT (WINAPI *pVarI4FromI8)(LONG64,LONG*);
347 static HRESULT (WINAPI *pVarI4FromUI8)(ULONG64,LONG*);
348 static HRESULT (WINAPI *pVarUI4FromUI1)(BYTE,ULONG*);
349 static HRESULT (WINAPI *pVarUI4FromI2)(SHORT,ULONG*);
350 static HRESULT (WINAPI *pVarUI4FromI4)(LONG,ULONG*);
351 static HRESULT (WINAPI *pVarUI4FromR4)(FLOAT,ULONG*);
352 static HRESULT (WINAPI *pVarUI4FromR8)(DOUBLE,ULONG*);
353 static HRESULT (WINAPI *pVarUI4FromDate)(DATE,ULONG*);
354 static HRESULT (WINAPI *pVarUI4FromCy)(CY,ULONG*);
355 static HRESULT (WINAPI *pVarUI4FromStr)(OLECHAR*,LCID,ULONG,ULONG*);
356 static HRESULT (WINAPI *pVarUI4FromBool)(VARIANT_BOOL,ULONG*);
357 static HRESULT (WINAPI *pVarUI4FromI1)(signed char,ULONG*);
358 static HRESULT (WINAPI *pVarUI4FromUI2)(USHORT,ULONG*);
359 static HRESULT (WINAPI *pVarUI4FromDec)(DECIMAL*,ULONG*);
360 static HRESULT (WINAPI *pVarUI4FromI8)(LONG64,ULONG*);
361 static HRESULT (WINAPI *pVarUI4FromUI8)(ULONG64,ULONG*);
363 static HRESULT (WINAPI *pVarI8FromUI1)(BYTE,LONG64*);
364 static HRESULT (WINAPI *pVarI8FromI2)(SHORT,LONG64*);
365 static HRESULT (WINAPI *pVarI8FromR4)(FLOAT,LONG64*);
366 static HRESULT (WINAPI *pVarI8FromR8)(double,LONG64*);
367 static HRESULT (WINAPI *pVarI8FromCy)(CY,LONG64*);
368 static HRESULT (WINAPI *pVarI8FromDate)(DATE,LONG64*);
369 static HRESULT (WINAPI *pVarI8FromStr)(OLECHAR*,LCID,ULONG,LONG64*);
370 static HRESULT (WINAPI *pVarI8FromBool)(VARIANT_BOOL,LONG64*);
371 static HRESULT (WINAPI *pVarI8FromI1)(signed char,LONG64*);
372 static HRESULT (WINAPI *pVarI8FromUI2)(USHORT,LONG64*);
373 static HRESULT (WINAPI *pVarI8FromUI4)(ULONG,LONG64*);
374 static HRESULT (WINAPI *pVarI8FromDec)(DECIMAL*,LONG64*);
375 static HRESULT (WINAPI *pVarI8FromUI8)(ULONG64,LONG64*);
376 static HRESULT (WINAPI *pVarUI8FromI8)(LONG64,ULONG64*);
377 static HRESULT (WINAPI *pVarUI8FromUI1)(BYTE,ULONG64*);
378 static HRESULT (WINAPI *pVarUI8FromI2)(SHORT,ULONG64*);
379 static HRESULT (WINAPI *pVarUI8FromR4)(FLOAT,ULONG64*);
380 static HRESULT (WINAPI *pVarUI8FromR8)(double,ULONG64*);
381 static HRESULT (WINAPI *pVarUI8FromCy)(CY,ULONG64*);
382 static HRESULT (WINAPI *pVarUI8FromDate)(DATE,ULONG64*);
383 static HRESULT (WINAPI *pVarUI8FromStr)(OLECHAR*,LCID,ULONG,ULONG64*);
384 static HRESULT (WINAPI *pVarUI8FromBool)(VARIANT_BOOL,ULONG64*);
385 static HRESULT (WINAPI *pVarUI8FromI1)(signed char,ULONG64*);
386 static HRESULT (WINAPI *pVarUI8FromUI2)(USHORT,ULONG64*);
387 static HRESULT (WINAPI *pVarUI8FromUI4)(ULONG,ULONG64*);
388 static HRESULT (WINAPI *pVarUI8FromDec)(DECIMAL*,ULONG64*);
390 static HRESULT (WINAPI *pVarR4FromUI1)(BYTE,float*);
391 static HRESULT (WINAPI *pVarR4FromI2)(SHORT,float*);
392 static HRESULT (WINAPI *pVarR4FromI4)(LONG,float*);
393 static HRESULT (WINAPI *pVarR4FromR8)(double,float*);
394 static HRESULT (WINAPI *pVarR4FromCy)(CY,float*);
395 static HRESULT (WINAPI *pVarR4FromDate)(DATE,float*);
396 static HRESULT (WINAPI *pVarR4FromStr)(OLECHAR*,LCID,ULONG,float*);
397 static HRESULT (WINAPI *pVarR4FromBool)(VARIANT_BOOL,float*);
398 static HRESULT (WINAPI *pVarR4FromI1)(signed char,float*);
399 static HRESULT (WINAPI *pVarR4FromUI2)(USHORT,float*);
400 static HRESULT (WINAPI *pVarR4FromUI4)(ULONG,float*);
401 static HRESULT (WINAPI *pVarR4FromDec)(DECIMAL*,float*);
402 static HRESULT (WINAPI *pVarR4FromI8)(LONG64,float*);
403 static HRESULT (WINAPI *pVarR4FromUI8)(ULONG64,float*);
405 static HRESULT (WINAPI *pVarR8FromUI1)(BYTE,double*);
406 static HRESULT (WINAPI *pVarR8FromI2)(SHORT,double*);
407 static HRESULT (WINAPI *pVarR8FromI4)(LONG,double*);
408 static HRESULT (WINAPI *pVarR8FromR4)(FLOAT,double*);
409 static HRESULT (WINAPI *pVarR8FromCy)(CY,double*);
410 static HRESULT (WINAPI *pVarR8FromDate)(DATE,double*);
411 static HRESULT (WINAPI *pVarR8FromStr)(OLECHAR*,LCID,ULONG,double*);
412 static HRESULT (WINAPI *pVarR8FromBool)(VARIANT_BOOL,double*);
413 static HRESULT (WINAPI *pVarR8FromI1)(signed char,double*);
414 static HRESULT (WINAPI *pVarR8FromUI2)(USHORT,double*);
415 static HRESULT (WINAPI *pVarR8FromUI4)(ULONG,double*);
416 static HRESULT (WINAPI *pVarR8FromDec)(DECIMAL*,double*);
417 static HRESULT (WINAPI *pVarR8FromI8)(LONG64,double*);
418 static HRESULT (WINAPI *pVarR8FromUI8)(ULONG64,double*);
419 static HRESULT (WINAPI *pVarR8Round)(double,int,double*);
421 static HRESULT (WINAPI *pVarDateFromUI1)(BYTE,DATE*);
422 static HRESULT (WINAPI *pVarDateFromI2)(SHORT,DATE*);
423 static HRESULT (WINAPI *pVarDateFromI4)(LONG,DATE*);
424 static HRESULT (WINAPI *pVarDateFromR4)(FLOAT,DATE*);
425 static HRESULT (WINAPI *pVarDateFromCy)(CY,DATE*);
426 static HRESULT (WINAPI *pVarDateFromR8)(double,DATE*);
427 static HRESULT (WINAPI *pVarDateFromStr)(OLECHAR*,LCID,ULONG,DATE*);
428 static HRESULT (WINAPI *pVarDateFromBool)(VARIANT_BOOL,DATE*);
429 static HRESULT (WINAPI *pVarDateFromI1)(signed char,DATE*);
430 static HRESULT (WINAPI *pVarDateFromUI2)(USHORT,DATE*);
431 static HRESULT (WINAPI *pVarDateFromUI4)(ULONG,DATE*);
432 static HRESULT (WINAPI *pVarDateFromDec)(DECIMAL*,DATE*);
433 static HRESULT (WINAPI *pVarDateFromI8)(LONG64,DATE*);
434 static HRESULT (WINAPI *pVarDateFromUI8)(ULONG64,DATE*);
436 static HRESULT (WINAPI *pVarCyFromUI1)(BYTE,CY*);
437 static HRESULT (WINAPI *pVarCyFromI2)(SHORT,CY*);
438 static HRESULT (WINAPI *pVarCyFromI4)(LONG,CY*);
439 static HRESULT (WINAPI *pVarCyFromR4)(FLOAT,CY*);
440 static HRESULT (WINAPI *pVarCyFromR8)(double,CY*);
441 static HRESULT (WINAPI *pVarCyFromDate)(DATE,CY*);
442 static HRESULT (WINAPI *pVarCyFromBool)(VARIANT_BOOL,CY*);
443 static HRESULT (WINAPI *pVarCyFromI1)(signed char,CY*);
444 static HRESULT (WINAPI *pVarCyFromUI2)(USHORT,CY*);
445 static HRESULT (WINAPI *pVarCyFromUI4)(ULONG,CY*);
446 static HRESULT (WINAPI *pVarCyFromDec)(DECIMAL*,CY*);
447 static HRESULT (WINAPI *pVarCyFromI8)(LONG64,CY*);
448 static HRESULT (WINAPI *pVarCyFromUI8)(ULONG64,CY*);
449 static HRESULT (WINAPI *pVarCyAdd)(const CY,const CY,CY*);
450 static HRESULT (WINAPI *pVarCyMul)(const CY,const CY,CY*);
451 static HRESULT (WINAPI *pVarCyMulI4)(const CY,LONG,CY*);
452 static HRESULT (WINAPI *pVarCySub)(const CY,const CY,CY*);
453 static HRESULT (WINAPI *pVarCyAbs)(const CY,CY*);
454 static HRESULT (WINAPI *pVarCyFix)(const CY,CY*);
455 static HRESULT (WINAPI *pVarCyInt)(const CY,CY*);
456 static HRESULT (WINAPI *pVarCyNeg)(const CY,CY*);
457 static HRESULT (WINAPI *pVarCyRound)(const CY,int,CY*);
458 static HRESULT (WINAPI *pVarCyCmp)(const CY,const CY);
459 static HRESULT (WINAPI *pVarCyCmpR8)(const CY,double);
460 static HRESULT (WINAPI *pVarCyMulI8)(const CY,LONG64,CY*);
462 static HRESULT (WINAPI *pVarDecFromUI1)(BYTE,DECIMAL*);
463 static HRESULT (WINAPI *pVarDecFromI2)(SHORT,DECIMAL*);
464 static HRESULT (WINAPI *pVarDecFromI4)(LONG,DECIMAL*);
465 static HRESULT (WINAPI *pVarDecFromI8)(LONG64,DECIMAL*);
466 static HRESULT (WINAPI *pVarDecFromR4)(FLOAT,DECIMAL*);
467 static HRESULT (WINAPI *pVarDecFromR8)(DOUBLE,DECIMAL*);
468 static HRESULT (WINAPI *pVarDecFromDate)(DATE,DECIMAL*);
469 static HRESULT (WINAPI *pVarDecFromStr)(OLECHAR*,LCID,ULONG,DECIMAL*);
470 static HRESULT (WINAPI *pVarDecFromBool)(VARIANT_BOOL,DECIMAL*);
471 static HRESULT (WINAPI *pVarDecFromI1)(signed char,DECIMAL*);
472 static HRESULT (WINAPI *pVarDecFromUI2)(USHORT,DECIMAL*);
473 static HRESULT (WINAPI *pVarDecFromUI4)(ULONG,DECIMAL*);
474 static HRESULT (WINAPI *pVarDecFromUI8)(ULONG64,DECIMAL*);
475 static HRESULT (WINAPI *pVarDecFromCy)(CY,DECIMAL*);
476 static HRESULT (WINAPI *pVarDecAbs)(const DECIMAL*,DECIMAL*);
477 static HRESULT (WINAPI *pVarDecAdd)(const DECIMAL*,const DECIMAL*,DECIMAL*);
478 static HRESULT (WINAPI *pVarDecSub)(const DECIMAL*,const DECIMAL*,DECIMAL*);
479 static HRESULT (WINAPI *pVarDecMul)(const DECIMAL*,const DECIMAL*,DECIMAL*);
480 static HRESULT (WINAPI *pVarDecDiv)(const DECIMAL*,const DECIMAL*,DECIMAL*);
481 static HRESULT (WINAPI *pVarDecCmp)(const DECIMAL*,const DECIMAL*);
482 static HRESULT (WINAPI *pVarDecNeg)(const DECIMAL*,DECIMAL*);
484 static HRESULT (WINAPI *pVarBoolFromUI1)(BYTE,VARIANT_BOOL*);
485 static HRESULT (WINAPI *pVarBoolFromI2)(SHORT,VARIANT_BOOL*);
486 static HRESULT (WINAPI *pVarBoolFromI4)(LONG,VARIANT_BOOL*);
487 static HRESULT (WINAPI *pVarBoolFromR4)(FLOAT,VARIANT_BOOL*);
488 static HRESULT (WINAPI *pVarBoolFromR8)(DOUBLE,VARIANT_BOOL*);
489 static HRESULT (WINAPI *pVarBoolFromDate)(DATE,VARIANT_BOOL*);
490 static HRESULT (WINAPI *pVarBoolFromCy)(CY,VARIANT_BOOL*);
491 static HRESULT (WINAPI *pVarBoolFromStr)(OLECHAR*,LCID,ULONG,VARIANT_BOOL*);
492 static HRESULT (WINAPI *pVarBoolFromI1)(signed char,VARIANT_BOOL*);
493 static HRESULT (WINAPI *pVarBoolFromUI2)(USHORT,VARIANT_BOOL*);
494 static HRESULT (WINAPI *pVarBoolFromUI4)(ULONG,VARIANT_BOOL*);
495 static HRESULT (WINAPI *pVarBoolFromDec)(DECIMAL*,VARIANT_BOOL*);
496 static HRESULT (WINAPI *pVarBoolFromI8)(LONG64,VARIANT_BOOL*);
497 static HRESULT (WINAPI *pVarBoolFromUI8)(ULONG64,VARIANT_BOOL*);
499 static HRESULT (WINAPI *pVarBstrFromR4)(FLOAT,LCID,ULONG,BSTR*);
500 static HRESULT (WINAPI *pVarBstrFromDate)(DATE,LCID,ULONG,BSTR*);
501 static HRESULT (WINAPI *pVarBstrFromDec)(DECIMAL*,LCID,ULONG,BSTR*);
502 static HRESULT (WINAPI *pVarBstrCmp)(BSTR,BSTR,LCID,ULONG);
504 static INT (WINAPI *pSystemTimeToVariantTime)(LPSYSTEMTIME,double*);
505 static void (WINAPI *pClearCustData)(LPCUSTDATA);
507 /* Internal representation of a BSTR */
508 typedef struct tagINTERNAL_BSTR
512 } INTERNAL_BSTR, *LPINTERNAL_BSTR;
516 const IDispatchVtbl *lpVtbl;
522 static DummyDispatch dispatch;
524 static ULONG WINAPI DummyDispatch_AddRef(LPDISPATCH iface)
526 trace("AddRef(%p)\n", iface);
527 return InterlockedIncrement(&((DummyDispatch*)iface)->ref);
530 static ULONG WINAPI DummyDispatch_Release(LPDISPATCH iface)
532 trace("Release(%p)\n", iface);
533 return InterlockedDecrement(&((DummyDispatch*)iface)->ref);
536 static HRESULT WINAPI DummyDispatch_QueryInterface(LPDISPATCH iface,
540 trace("QueryInterface(%p)\n", iface);
544 if (IsEqualIID(riid, &IID_IDispatch))
546 trace("Asked for IID_IDispatch\n");
549 else if (IsEqualIID(riid, &IID_IUnknown))
551 trace("Asked for IID_IUnknown\n");
556 DummyDispatch_AddRef((IDispatch*)*ppvObject);
560 return E_NOINTERFACE;
563 static HRESULT WINAPI DummyDispatch_Invoke(LPDISPATCH iface,
564 DISPID dispIdMember, REFIID riid,
565 LCID lcid, WORD wFlags,
566 DISPPARAMS *pDispParams,
568 EXCEPINFO *pExcepInfo,
571 trace("Invoke(%p)\n", iface);
572 ok(wFlags == DISPATCH_PROPERTYGET, "Flags wrong\n");
573 ok(pDispParams->cArgs == 0, "Property get has args\n");
575 if (dispatch.bFailInvoke)
576 return E_OUTOFMEMORY;
578 memset(pVarResult, 0, sizeof(*pVarResult));
579 V_VT(pVarResult) = dispatch.vt;
583 static const IDispatchVtbl DummyDispatch_VTable =
585 DummyDispatch_QueryInterface,
586 DummyDispatch_AddRef,
587 DummyDispatch_Release,
594 static DummyDispatch dispatch = { &DummyDispatch_VTable, 1, 0, 0 };
601 #define CONV_TYPE signed char
603 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%d")
605 static void test_VarI1FromI2(void)
610 CHECKPTR(VarI1FromI2);
611 OVERFLOWRANGE(VarI1FromI2, -32768, -128);
612 CONVERTRANGE(VarI1FromI2, -128, 128);
613 OVERFLOWRANGE(VarI1FromI2, 129, 32768);
616 static void test_VarI1FromI4(void)
621 CHECKPTR(VarI1FromI4);
622 CONVERT(VarI1FromI4, -129); EXPECT_OVERFLOW;
623 CONVERTRANGE(VarI1FromI4, -128, 128);
624 CONVERT(VarI1FromI4, 128); EXPECT_OVERFLOW;
627 static void test_VarI1FromI8(void)
632 CHECKPTR(VarI1FromI8);
633 CONVERT(VarI1FromI8, -129); EXPECT_OVERFLOW;
634 CONVERTRANGE(VarI1FromI8, -127, 128);
635 CONVERT(VarI1FromI8, 128); EXPECT_OVERFLOW;
638 static void test_VarI1FromUI1(void)
643 CHECKPTR(VarI1FromUI1);
644 CONVERTRANGE(VarI1FromUI1, 0, 127);
645 OVERFLOWRANGE(VarI1FromUI1, 128, 255);
648 static void test_VarI1FromUI2(void)
653 CHECKPTR(VarI1FromUI2);
654 CONVERTRANGE(VarI1FromUI2, 0, 127);
655 OVERFLOWRANGE(VarI1FromUI2, 128, 32768);
658 static void test_VarI1FromUI4(void)
663 CHECKPTR(VarI1FromUI4);
664 CONVERTRANGE(VarI1FromUI4, 0, 127);
665 CONVERT(VarI1FromUI4, 128); EXPECT_OVERFLOW;
668 static void test_VarI1FromUI8(void)
673 CHECKPTR(VarI1FromUI8);
674 CONVERTRANGE(VarI1FromUI8, 0, 127);
675 CONVERT(VarI1FromUI8, 128); EXPECT_OVERFLOW;
678 static void test_VarI1FromBool(void)
680 CONVVARS(VARIANT_BOOL);
683 CHECKPTR(VarI1FromBool);
684 /* Note that conversions from bool wrap around! */
685 CONVERT(VarI1FromBool, -129); EXPECT(127);
686 CONVERTRANGE(VarI1FromBool, -128, 128);
687 CONVERT(VarI1FromBool, 128); EXPECT(-128);
690 static void test_VarI1FromR4(void)
694 CHECKPTR(VarI1FromR4);
695 CONVERT(VarI1FromR4, -129.0f); EXPECT_OVERFLOW;
696 CONVERT(VarI1FromR4, -128.0f); EXPECT(-128);
697 CONVERT(VarI1FromR4, -1.0f); EXPECT(-1);
698 CONVERT(VarI1FromR4, 0.0f); EXPECT(0);
699 CONVERT(VarI1FromR4, 1.0f); EXPECT(1);
700 CONVERT(VarI1FromR4, 127.0f); EXPECT(127);
701 CONVERT(VarI1FromR4, 128.0f); EXPECT_OVERFLOW;
703 CONVERT(VarI1FromR4, -1.5f); EXPECT(-2);
704 CONVERT(VarI1FromR4, -0.6f); EXPECT(-1);
705 CONVERT(VarI1FromR4, -0.5f); EXPECT(0);
706 CONVERT(VarI1FromR4, -0.4f); EXPECT(0);
707 CONVERT(VarI1FromR4, 0.4f); EXPECT(0);
708 CONVERT(VarI1FromR4, 0.5f); EXPECT(0);
709 CONVERT(VarI1FromR4, 0.6f); EXPECT(1);
710 CONVERT(VarI1FromR4, 1.5f); EXPECT(2);
713 static void test_VarI1FromR8(void)
717 CHECKPTR(VarI1FromR8);
718 CONVERT(VarI1FromR8, -129.0); EXPECT_OVERFLOW;
719 CONVERT(VarI1FromR8, -128.0); EXPECT(-128);
720 CONVERT(VarI1FromR8, -1.0); EXPECT(-1);
721 CONVERT(VarI1FromR8, 0.0); EXPECT(0);
722 CONVERT(VarI1FromR8, 1.0); EXPECT(1);
723 CONVERT(VarI1FromR8, 127.0); EXPECT(127);
724 CONVERT(VarI1FromR8, 128.0); EXPECT_OVERFLOW;
726 CONVERT(VarI1FromR8, -1.5); EXPECT(-2);
727 CONVERT(VarI1FromR8, -0.6); EXPECT(-1);
728 CONVERT(VarI1FromR8, -0.5); EXPECT(0);
729 CONVERT(VarI1FromR8, -0.4); EXPECT(0);
730 CONVERT(VarI1FromR8, 0.4); EXPECT(0);
731 CONVERT(VarI1FromR8, 0.5); EXPECT(0);
732 CONVERT(VarI1FromR8, 0.6); EXPECT(1);
733 CONVERT(VarI1FromR8, 1.5); EXPECT(2);
736 static void test_VarI1FromDate(void)
740 CHECKPTR(VarI1FromDate);
741 CONVERT(VarI1FromDate, -129.0); EXPECT_OVERFLOW;
742 CONVERT(VarI1FromDate, -128.0); EXPECT(-128);
743 CONVERT(VarI1FromDate, -1.0); EXPECT(-1);
744 CONVERT(VarI1FromDate, 0.0); EXPECT(0);
745 CONVERT(VarI1FromDate, 1.0); EXPECT(1);
746 CONVERT(VarI1FromDate, 127.0); EXPECT(127);
747 CONVERT(VarI1FromDate, 128.0); EXPECT_OVERFLOW;
749 CONVERT(VarI1FromDate, -1.5); EXPECT(-2);
750 CONVERT(VarI1FromDate, -0.6); EXPECT(-1);
751 CONVERT(VarI1FromDate, -0.5); EXPECT(0);
752 CONVERT(VarI1FromDate, -0.4); EXPECT(0);
753 CONVERT(VarI1FromDate, 0.4); EXPECT(0);
754 CONVERT(VarI1FromDate, 0.5); EXPECT(0);
755 CONVERT(VarI1FromDate, 0.6); EXPECT(1);
756 CONVERT(VarI1FromDate, 1.5); EXPECT(2);
759 static void test_VarI1FromCy(void)
763 CHECKPTR(VarI1FromCy);
764 CONVERT_CY(VarI1FromCy,-129); EXPECT_OVERFLOW;
765 CONVERT_CY(VarI1FromCy,-128); EXPECT(128);
766 CONVERT_CY(VarI1FromCy,-1); EXPECT(-1);
767 CONVERT_CY(VarI1FromCy,0); EXPECT(0);
768 CONVERT_CY(VarI1FromCy,1); EXPECT(1);
769 CONVERT_CY(VarI1FromCy,127); EXPECT(127);
770 CONVERT_CY(VarI1FromCy,128); EXPECT_OVERFLOW;
772 CONVERT_CY(VarI1FromCy,-1.5); EXPECT(-2);
773 CONVERT_CY(VarI1FromCy,-0.6); EXPECT(-1);
774 CONVERT_CY(VarI1FromCy,-0.5); EXPECT(0);
775 CONVERT_CY(VarI1FromCy,-0.4); EXPECT(0);
776 CONVERT_CY(VarI1FromCy,0.4); EXPECT(0);
777 CONVERT_CY(VarI1FromCy,0.5); EXPECT(0);
778 CONVERT_CY(VarI1FromCy,0.6); EXPECT(1);
779 CONVERT_CY(VarI1FromCy,1.5); EXPECT(2);
782 static void test_VarI1FromDec(void)
786 CHECKPTR(VarI1FromDec);
788 CONVERT_BADDEC(VarI1FromDec);
790 CONVERT_DEC(VarI1FromDec,0,0x80,0,129); EXPECT_OVERFLOW;
791 CONVERT_DEC(VarI1FromDec,0,0x80,0,128); EXPECT(-128);
792 CONVERT_DEC(VarI1FromDec,0,0x80,0,1); EXPECT(-1);
793 CONVERT_DEC(VarI1FromDec,0,0,0,0); EXPECT(0);
794 CONVERT_DEC(VarI1FromDec,0,0,0,1); EXPECT(1);
795 CONVERT_DEC(VarI1FromDec,0,0,0,127); EXPECT(127);
796 CONVERT_DEC(VarI1FromDec,0,0,0,128); EXPECT_OVERFLOW;
798 CONVERT_DEC(VarI1FromDec,2,0x80,0,12800); EXPECT(-128);
799 CONVERT_DEC(VarI1FromDec,2,0,0,12700); EXPECT(127);
802 static void test_VarI1FromStr(void)
807 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
809 CHECKPTR(VarI1FromStr);
811 CONVERT_STR(VarI1FromStr,NULL, 0); EXPECT_MISMATCH;
812 CONVERT_STR(VarI1FromStr,"0", 0); EXPECT(0);
813 CONVERT_STR(VarI1FromStr,"-129", 0); EXPECT_OVERFLOW;
814 CONVERT_STR(VarI1FromStr,"-128", 0); EXPECT(-128);
815 CONVERT_STR(VarI1FromStr,"127", 0); EXPECT(127);
816 CONVERT_STR(VarI1FromStr,"128", 0); EXPECT_OVERFLOW;
818 CONVERT_STR(VarI1FromStr,"-1.5", LOCALE_NOUSEROVERRIDE); EXPECT(-2);
819 CONVERT_STR(VarI1FromStr,"-0.6", LOCALE_NOUSEROVERRIDE); EXPECT(-1);
820 CONVERT_STR(VarI1FromStr,"-0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
821 CONVERT_STR(VarI1FromStr,"-0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
822 CONVERT_STR(VarI1FromStr,"0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
823 CONVERT_STR(VarI1FromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
824 CONVERT_STR(VarI1FromStr,"0.6", LOCALE_NOUSEROVERRIDE); EXPECT(1);
825 CONVERT_STR(VarI1FromStr,"1.5", LOCALE_NOUSEROVERRIDE); EXPECT(2);
828 static void test_VarI1Copy(void)
832 COPYTEST(1, VT_I1, V_I1(&vSrc), V_I1(&vDst), V_I1REF(&vSrc), V_I1REF(&vDst), "%d");
836 static void test_VarI1ChangeTypeEx(void)
839 VARIANTARG vSrc, vDst;
845 INITIAL_TYPETEST(VT_I1, V_I1, "%d");
847 NEGATIVE_TYPETEST(VT_I1, V_I1, "%d", VT_UI1, V_UI1);
852 #define CONV_TYPE BYTE
854 static void test_VarUI1FromI1(void)
856 CONVVARS(signed char);
859 CHECKPTR(VarUI1FromI1);
860 OVERFLOWRANGE(VarUI1FromI1, -128, 0);
861 CONVERTRANGE(VarUI1FromI1, 0, 128);
864 static void test_VarUI1FromI2(void)
869 CHECKPTR(VarUI1FromI2);
870 OVERFLOWRANGE(VarUI1FromI2, -32768, 0);
871 CONVERTRANGE(VarUI1FromI2, 0, 256);
872 OVERFLOWRANGE(VarUI1FromI2, 256, 32768);
875 static void test_VarUI1FromI4(void)
880 CHECKPTR(VarUI1FromI4);
881 CONVERT(VarUI1FromI4, -1); EXPECT_OVERFLOW;
882 CONVERTRANGE(VarUI1FromI4, 0, 256);
883 CONVERT(VarUI1FromI4, 256); EXPECT_OVERFLOW;
886 static void test_VarUI1FromI8(void)
891 CHECKPTR(VarUI1FromI8);
892 CONVERT(VarUI1FromI8, -1); EXPECT_OVERFLOW;
893 CONVERTRANGE(VarUI1FromI8, 0, 256);
894 CONVERT(VarUI1FromI8, 256); EXPECT_OVERFLOW;
897 static void test_VarUI1FromUI2(void)
902 CHECKPTR(VarUI1FromUI2);
903 CONVERTRANGE(VarUI1FromUI2, 0, 256);
904 OVERFLOWRANGE(VarUI1FromUI2, 256, 65536);
907 static void test_VarUI1FromUI4(void)
912 CHECKPTR(VarUI1FromUI4);
913 CONVERTRANGE(VarUI1FromUI4, 0, 256);
914 CONVERT(VarUI1FromUI4, 256); EXPECT_OVERFLOW;
917 static void test_VarUI1FromUI8(void)
922 CHECKPTR(VarUI1FromUI8);
923 CONVERTRANGE(VarUI1FromUI8, 0, 256);
924 CONVERT(VarUI1FromUI8, 256); EXPECT_OVERFLOW;
927 static void test_VarUI1FromBool(void)
929 CONVVARS(VARIANT_BOOL);
932 CHECKPTR(VarUI1FromBool);
933 /* Note that conversions from bool overflow! */
934 CONVERT(VarUI1FromBool, -1); EXPECT(255);
935 CONVERTRANGE(VarUI1FromBool, 0, 256);
936 CONVERT(VarUI1FromBool, 256); EXPECT(0);
939 static void test_VarUI1FromR4(void)
943 CHECKPTR(VarUI1FromR4);
944 CONVERT(VarUI1FromR4, -1.0f); EXPECT_OVERFLOW;
945 CONVERT(VarUI1FromR4, 0.0f); EXPECT(0);
946 CONVERT(VarUI1FromR4, 1.0f); EXPECT(1);
947 CONVERT(VarUI1FromR4, 255.0f); EXPECT(255);
948 CONVERT(VarUI1FromR4, 256.0f); EXPECT_OVERFLOW;
951 CONVERT(VarUI1FromR4, -1.5f); EXPECT_OVERFLOW;
952 CONVERT(VarUI1FromR4, -0.6f); EXPECT_OVERFLOW;
953 CONVERT(VarUI1FromR4, -0.5f); EXPECT(0);
954 CONVERT(VarUI1FromR4, -0.4f); EXPECT(0);
955 CONVERT(VarUI1FromR4, 0.4f); EXPECT(0);
956 CONVERT(VarUI1FromR4, 0.5f); EXPECT(0);
957 CONVERT(VarUI1FromR4, 0.6f); EXPECT(1);
958 CONVERT(VarUI1FromR4, 1.5f); EXPECT(2);
961 static void test_VarUI1FromR8(void)
965 CHECKPTR(VarUI1FromR8);
966 CONVERT(VarUI1FromR8, -1.0); EXPECT_OVERFLOW;
967 CONVERT(VarUI1FromR8, 0.0); EXPECT(0);
968 CONVERT(VarUI1FromR8, 1.0); EXPECT(1);
969 CONVERT(VarUI1FromR8, 255.0); EXPECT(255);
970 CONVERT(VarUI1FromR8, 256.0); EXPECT_OVERFLOW;
973 CONVERT(VarUI1FromR8, -1.5); EXPECT_OVERFLOW;
974 CONVERT(VarUI1FromR8, -0.6); EXPECT_OVERFLOW;
975 CONVERT(VarUI1FromR8, -0.5); EXPECT(0);
976 CONVERT(VarUI1FromR8, -0.4); EXPECT(0);
977 CONVERT(VarUI1FromR8, 0.4); EXPECT(0);
978 CONVERT(VarUI1FromR8, 0.5); EXPECT(0);
979 CONVERT(VarUI1FromR8, 0.6); EXPECT(1);
980 CONVERT(VarUI1FromR8, 1.5); EXPECT(2);
983 static void test_VarUI1FromDate(void)
987 CHECKPTR(VarUI1FromDate);
988 CONVERT(VarUI1FromDate, -1.0); EXPECT_OVERFLOW;
989 CONVERT(VarUI1FromDate, 0.0); EXPECT(0);
990 CONVERT(VarUI1FromDate, 1.0); EXPECT(1);
991 CONVERT(VarUI1FromDate, 255.0); EXPECT(255);
992 CONVERT(VarUI1FromDate, 256.0); EXPECT_OVERFLOW;
995 CONVERT(VarUI1FromDate, -1.5); EXPECT_OVERFLOW;
996 CONVERT(VarUI1FromDate, -0.6); EXPECT_OVERFLOW;
997 CONVERT(VarUI1FromDate, -0.5); EXPECT(0);
998 CONVERT(VarUI1FromDate, -0.4); EXPECT(0);
999 CONVERT(VarUI1FromDate, 0.4); EXPECT(0);
1000 CONVERT(VarUI1FromDate, 0.5); EXPECT(0);
1001 CONVERT(VarUI1FromDate, 0.6); EXPECT(1);
1002 CONVERT(VarUI1FromDate, 1.5); EXPECT(2);
1005 static void test_VarUI1FromCy(void)
1009 CHECKPTR(VarUI1FromCy);
1010 CONVERT_CY(VarUI1FromCy,-1); EXPECT_OVERFLOW;
1011 CONVERT_CY(VarUI1FromCy,0); EXPECT(0);
1012 CONVERT_CY(VarUI1FromCy,1); EXPECT(1);
1013 CONVERT_CY(VarUI1FromCy,255); EXPECT(255);
1014 CONVERT_CY(VarUI1FromCy,256); EXPECT_OVERFLOW;
1017 CONVERT_CY(VarUI1FromCy,-1.5); EXPECT_OVERFLOW;
1018 CONVERT_CY(VarUI1FromCy,-0.6); EXPECT_OVERFLOW;
1019 CONVERT_CY(VarUI1FromCy,-0.5); EXPECT(0);
1020 CONVERT_CY(VarUI1FromCy,-0.4); EXPECT(0);
1021 CONVERT_CY(VarUI1FromCy,0.4); EXPECT(0);
1022 CONVERT_CY(VarUI1FromCy,0.5); EXPECT(0);
1023 CONVERT_CY(VarUI1FromCy,0.6); EXPECT(1);
1024 CONVERT_CY(VarUI1FromCy,1.5); EXPECT(2);
1027 static void test_VarUI1FromDec(void)
1031 CHECKPTR(VarUI1FromDec);
1033 CONVERT_BADDEC(VarUI1FromDec);
1035 CONVERT_DEC(VarUI1FromDec,0,0x80,0,1); EXPECT_OVERFLOW;
1036 CONVERT_DEC(VarUI1FromDec,0,0,0,0); EXPECT(0);
1037 CONVERT_DEC(VarUI1FromDec,0,0,0,1); EXPECT(1);
1038 CONVERT_DEC(VarUI1FromDec,0,0,0,255); EXPECT(255);
1039 CONVERT_DEC(VarUI1FromDec,0,0,0,256); EXPECT_OVERFLOW;
1041 CONVERT_DEC(VarUI1FromDec,2,0x80,0,100); EXPECT_OVERFLOW;
1042 CONVERT_DEC(VarUI1FromDec,2,0,0,25500); EXPECT(255);
1045 static void test_VarUI1FromStr(void)
1050 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1052 CHECKPTR(VarUI1FromStr);
1054 CONVERT_STR(VarUI1FromStr,NULL, 0); EXPECT_MISMATCH;
1055 CONVERT_STR(VarUI1FromStr,"0", 0); EXPECT(0);
1056 CONVERT_STR(VarUI1FromStr,"-1", 0); EXPECT_OVERFLOW;
1057 CONVERT_STR(VarUI1FromStr,"255", 0); EXPECT(255);
1058 CONVERT_STR(VarUI1FromStr,"256", 0); EXPECT_OVERFLOW;
1061 CONVERT_STR(VarUI1FromStr,"-1.5", LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
1062 CONVERT_STR(VarUI1FromStr,"-0.6", LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
1063 CONVERT_STR(VarUI1FromStr,"-0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1064 CONVERT_STR(VarUI1FromStr,"-0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1065 CONVERT_STR(VarUI1FromStr,"0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1066 CONVERT_STR(VarUI1FromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1067 CONVERT_STR(VarUI1FromStr,"0.6", LOCALE_NOUSEROVERRIDE); EXPECT(1);
1068 CONVERT_STR(VarUI1FromStr,"1.5", LOCALE_NOUSEROVERRIDE); EXPECT(2);
1071 static void test_VarUI1FromDisp(void)
1074 VARIANTARG vSrc, vDst;
1076 CHECKPTR(VarUI1FromDisp);
1079 * Conversions from IDispatch should get the default 'value' property
1080 * from the IDispatch pointer and return it. The following tests this.
1081 * However, I can't get these tests to return a valid value under native
1082 * oleaut32, regardless of the value returned in response to the Invoke()
1083 * call (early versions of oleaut32 call AddRef/Release, but not Invoke.
1084 * I'm obviously missing something, as these conversions work fine
1085 * when called through VBA on an object to get its default value property.
1087 * Should this test be corrected so that it works under native it should be
1088 * generalised and the remaining types checked as well.
1090 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1095 V_VT(&vSrc) = VT_DISPATCH;
1096 V_DISPATCH(&vSrc) = (IDispatch*)&dispatch;
1097 dispatch.vt = VT_UI1;
1098 dispatch.bFailInvoke = FALSE;
1100 hres = VarUI1FromDisp((IDispatch*)&dispatch, in, &out);
1101 trace("0x%08x\n", hres);
1103 hres = VariantChangeTypeEx(&vDst, &vSrc, in, 0, VT_UI1);
1104 trace("0x%08x\n", hres);
1106 dispatch.bFailInvoke = TRUE;
1108 hres = VarUI1FromDisp((IDispatch*)&dispatch, in, &out);
1109 trace("0x%08x\n", hres);
1111 hres = VariantChangeTypeEx(&vDst, &vSrc, in, 0, VT_UI1);
1112 trace("0x%08x\n", hres);
1115 static void test_VarUI1Copy(void)
1117 COPYTEST(1, VT_UI1, V_UI1(&vSrc), V_UI1(&vDst), V_UI1REF(&vSrc), V_UI1REF(&vDst), "%d");
1120 static void test_VarUI1ChangeTypeEx(void)
1122 CONVVARS(CONV_TYPE);
1123 VARIANTARG vSrc, vDst;
1127 INITIAL_TYPETEST(VT_UI1, V_UI1, "%d");
1129 NEGATIVE_TYPETEST(VT_UI1, V_UI1, "%d", VT_I1, V_I1);
1137 #define CONV_TYPE SHORT
1139 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%d")
1141 static void test_VarI2FromI1(void)
1143 CONVVARS(signed char);
1146 CHECKPTR(VarI2FromI1);
1147 CONVERTRANGE(VarI2FromI1, -128, 128);
1150 static void test_VarI2FromI4(void)
1155 CHECKPTR(VarI2FromI4);
1156 CONVERT(VarI2FromI4, -32769); EXPECT_OVERFLOW;
1157 CONVERTRANGE(VarI2FromI4, -32768, 32768);
1158 CONVERT(VarI2FromI4, 32768); EXPECT_OVERFLOW;
1161 static void test_VarI2FromI8(void)
1165 CHECKPTR(VarI2FromI8);
1166 CONVERT(VarI2FromI8, -32769); EXPECT_OVERFLOW;
1167 CONVERT(VarI2FromI8, -32768); EXPECT(-32768);
1168 CONVERT(VarI2FromI8, 32767); EXPECT(32767);
1169 CONVERT(VarI2FromI8, 32768); EXPECT_OVERFLOW;
1172 static void test_VarI2FromUI1(void)
1177 CHECKPTR(VarI2FromUI1);
1178 CONVERTRANGE(VarI2FromUI1, 0, 256);
1181 static void test_VarI2FromUI2(void)
1186 CHECKPTR(VarI2FromUI2);
1187 CONVERTRANGE(VarI2FromUI2, 0, 32768);
1188 CONVERT(VarI2FromUI2, 32768); EXPECT_OVERFLOW;
1191 static void test_VarI2FromUI4(void)
1196 CHECKPTR(VarI2FromUI4);
1197 CONVERTRANGE(VarI2FromUI4, 0, 32768);
1198 CONVERT(VarI2FromUI4, 32768); EXPECT_OVERFLOW;
1201 static void test_VarI2FromUI8(void)
1206 CHECKPTR(VarI2FromUI8);
1207 CONVERTRANGE(VarI2FromUI8, 0, 32768);
1208 CONVERT(VarI2FromUI8, 32768); EXPECT_OVERFLOW;
1211 static void test_VarI2FromBool(void)
1213 CONVVARS(VARIANT_BOOL);
1216 CHECKPTR(VarI2FromBool);
1217 CONVERTRANGE(VarI2FromBool, -32768, 32768);
1220 static void test_VarI2FromR4(void)
1224 CHECKPTR(VarI2FromR4);
1225 CONVERT(VarI2FromR4, -32769.0f); EXPECT_OVERFLOW;
1226 CONVERT(VarI2FromR4, -32768.0f); EXPECT(-32768);
1227 CONVERT(VarI2FromR4, -1.0f); EXPECT(-1);
1228 CONVERT(VarI2FromR4, 0.0f); EXPECT(0);
1229 CONVERT(VarI2FromR4, 1.0f); EXPECT(1);
1230 CONVERT(VarI2FromR4, 32767.0f); EXPECT(32767);
1231 CONVERT(VarI2FromR4, 32768.0f); EXPECT_OVERFLOW;
1234 CONVERT(VarI2FromR4, -1.5f); EXPECT(-2);
1235 CONVERT(VarI2FromR4, -0.6f); EXPECT(-1);
1236 CONVERT(VarI2FromR4, -0.5f); EXPECT(0);
1237 CONVERT(VarI2FromR4, -0.4f); EXPECT(0);
1238 CONVERT(VarI2FromR4, 0.4f); EXPECT(0);
1239 CONVERT(VarI2FromR4, 0.5f); EXPECT(0);
1240 CONVERT(VarI2FromR4, 0.6f); EXPECT(1);
1241 CONVERT(VarI2FromR4, 1.5f); EXPECT(2);
1244 static void test_VarI2FromR8(void)
1248 CHECKPTR(VarI2FromR8);
1249 CONVERT(VarI2FromR8, -32769.0); EXPECT_OVERFLOW;
1250 CONVERT(VarI2FromR8, -32768.0); EXPECT(-32768);
1251 CONVERT(VarI2FromR8, -1.0); EXPECT(-1);
1252 CONVERT(VarI2FromR8, 0.0); EXPECT(0);
1253 CONVERT(VarI2FromR8, 1.0); EXPECT(1);
1254 CONVERT(VarI2FromR8, 32767.0); EXPECT(32767);
1255 CONVERT(VarI2FromR8, 32768.0); EXPECT_OVERFLOW;
1258 CONVERT(VarI2FromR8, -1.5); EXPECT(-2);
1259 CONVERT(VarI2FromR8, -0.6); EXPECT(-1);
1260 CONVERT(VarI2FromR8, -0.5); EXPECT(0);
1261 CONVERT(VarI2FromR8, -0.4); EXPECT(0);
1262 CONVERT(VarI2FromR8, 0.4); EXPECT(0);
1263 CONVERT(VarI2FromR8, 0.5); EXPECT(0);
1264 CONVERT(VarI2FromR8, 0.6); EXPECT(1);
1265 CONVERT(VarI2FromR8, 1.5); EXPECT(2);
1268 static void test_VarI2FromDate(void)
1272 CHECKPTR(VarI2FromDate);
1273 CONVERT(VarI2FromDate, -32769.0); EXPECT_OVERFLOW;
1274 CONVERT(VarI2FromDate, -32768.0); EXPECT(-32768);
1275 CONVERT(VarI2FromDate, -1.0); EXPECT(-1);
1276 CONVERT(VarI2FromDate, 0.0); EXPECT(0);
1277 CONVERT(VarI2FromDate, 1.0); EXPECT(1);
1278 CONVERT(VarI2FromDate, 32767.0); EXPECT(32767);
1279 CONVERT(VarI2FromDate, 32768.0); EXPECT_OVERFLOW;
1282 CONVERT(VarI2FromDate, -1.5); EXPECT(-2);
1283 CONVERT(VarI2FromDate, -0.6); EXPECT(-1);
1284 CONVERT(VarI2FromDate, -0.5); EXPECT(0);
1285 CONVERT(VarI2FromDate, -0.4); EXPECT(0);
1286 CONVERT(VarI2FromDate, 0.4); EXPECT(0);
1287 CONVERT(VarI2FromDate, 0.5); EXPECT(0);
1288 CONVERT(VarI2FromDate, 0.6); EXPECT(1);
1289 CONVERT(VarI2FromDate, 1.5); EXPECT(2);
1292 static void test_VarI2FromCy(void)
1296 CHECKPTR(VarI2FromCy);
1297 CONVERT_CY(VarI2FromCy,-32769); EXPECT_OVERFLOW;
1298 CONVERT_CY(VarI2FromCy,-32768); EXPECT(32768);
1299 CONVERT_CY(VarI2FromCy,-1); EXPECT(-1);
1300 CONVERT_CY(VarI2FromCy,0); EXPECT(0);
1301 CONVERT_CY(VarI2FromCy,1); EXPECT(1);
1302 CONVERT_CY(VarI2FromCy,32767); EXPECT(32767);
1303 CONVERT_CY(VarI2FromCy,32768); EXPECT_OVERFLOW;
1306 CONVERT_CY(VarI2FromCy,-1.5); EXPECT(-2);
1307 CONVERT_CY(VarI2FromCy,-0.6); EXPECT(-1);
1308 CONVERT_CY(VarI2FromCy,-0.5); EXPECT(0);
1309 CONVERT_CY(VarI2FromCy,-0.4); EXPECT(0);
1310 CONVERT_CY(VarI2FromCy,0.4); EXPECT(0);
1311 CONVERT_CY(VarI2FromCy,0.5); EXPECT(0);
1312 CONVERT_CY(VarI2FromCy,0.6); EXPECT(1);
1313 CONVERT_CY(VarI2FromCy,1.5); EXPECT(2);
1316 static void test_VarI2FromDec(void)
1320 CHECKPTR(VarI2FromDec);
1322 CONVERT_BADDEC(VarI2FromDec);
1324 CONVERT_DEC(VarI2FromDec,0,0x80,0,32769); EXPECT_OVERFLOW;
1325 CONVERT_DEC(VarI2FromDec,0,0x80,0,32768); EXPECT(-32768);
1326 CONVERT_DEC(VarI2FromDec,0,0x80,0,1); EXPECT(-1);
1327 CONVERT_DEC(VarI2FromDec,0,0,0,0); EXPECT(0);
1328 CONVERT_DEC(VarI2FromDec,0,0,0,1); EXPECT(1);
1329 CONVERT_DEC(VarI2FromDec,0,0,0,32767); EXPECT(32767);
1330 CONVERT_DEC(VarI2FromDec,0,0,0,32768); EXPECT_OVERFLOW;
1332 CONVERT_DEC(VarI2FromDec,2,0x80,0,3276800); EXPECT(-32768);
1333 CONVERT_DEC(VarI2FromDec,2,0,0,3276700); EXPECT(32767);
1334 CONVERT_DEC(VarI2FromDec,2,0,0,3276800); EXPECT_OVERFLOW;
1337 static void test_VarI2FromStr(void)
1342 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1344 CHECKPTR(VarI2FromStr);
1346 CONVERT_STR(VarI2FromStr,NULL, 0); EXPECT_MISMATCH;
1347 CONVERT_STR(VarI2FromStr,"0", 0); EXPECT(0);
1348 CONVERT_STR(VarI2FromStr,"-32769", 0); EXPECT_OVERFLOW;
1349 CONVERT_STR(VarI2FromStr,"-32768", 0); EXPECT(-32768);
1350 CONVERT_STR(VarI2FromStr,"32767", 0); EXPECT(32767);
1351 CONVERT_STR(VarI2FromStr,"32768", 0); EXPECT_OVERFLOW;
1354 CONVERT_STR(VarI2FromStr,"-1.5", LOCALE_NOUSEROVERRIDE); EXPECT(-2);
1355 CONVERT_STR(VarI2FromStr,"-0.6", LOCALE_NOUSEROVERRIDE); EXPECT(-1);
1356 CONVERT_STR(VarI2FromStr,"-0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1357 CONVERT_STR(VarI2FromStr,"-0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1358 CONVERT_STR(VarI2FromStr,"0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1359 CONVERT_STR(VarI2FromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1360 CONVERT_STR(VarI2FromStr,"0.6", LOCALE_NOUSEROVERRIDE); EXPECT(1);
1361 CONVERT_STR(VarI2FromStr,"1.5", LOCALE_NOUSEROVERRIDE); EXPECT(2);
1364 static void test_VarI2Copy(void)
1366 COPYTEST(1, VT_I2, V_I2(&vSrc), V_I2(&vDst), V_I2REF(&vSrc), V_I2REF(&vDst), "%d");
1369 static void test_VarI2ChangeTypeEx(void)
1371 CONVVARS(CONV_TYPE);
1372 VARIANTARG vSrc, vDst;
1376 INITIAL_TYPETEST(VT_I2, V_I2, "%d");
1378 NEGATIVE_TYPETEST(VT_I2, V_I2, "%d", VT_UI2, V_UI2);
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", LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
1591 CONVERT_STR(VarUI2FromStr,"-0.6", LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
1592 CONVERT_STR(VarUI2FromStr,"-0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1593 CONVERT_STR(VarUI2FromStr,"-0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1594 CONVERT_STR(VarUI2FromStr,"0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1595 CONVERT_STR(VarUI2FromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1596 CONVERT_STR(VarUI2FromStr,"0.6", LOCALE_NOUSEROVERRIDE); EXPECT(1);
1597 CONVERT_STR(VarUI2FromStr,"1.5", LOCALE_NOUSEROVERRIDE); 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");
1619 NEGATIVE_TYPETEST(VT_UI2, V_UI2, "%d", VT_I2, V_I2);
1628 #define CONV_TYPE LONG
1630 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%d")
1633 static void test_VarI4FromI1(void)
1635 CONVVARS(signed char);
1638 CHECKPTR(VarI4FromI1);
1639 CONVERTRANGE(VarI4FromI1, -128, 128);
1642 static void test_VarI4FromI2(void)
1647 CHECKPTR(VarI4FromI2);
1648 CONVERTRANGE(VarI4FromI2, -32768, 32768);
1651 static void test_VarI4FromI8(void)
1655 CHECKPTR(VarI4FromI8);
1656 CHECKPTR(VarI4FromDec);
1658 CONVERT(VarI4FromI8, -1); EXPECT(-1);
1659 CONVERT(VarI4FromI8, 0); EXPECT(0);
1660 CONVERT(VarI4FromI8, 1); EXPECT(1);
1662 CONVERT_I8(VarI4FromI8, -1, 2147483647ul); EXPECT_OVERFLOW;
1663 CONVERT_I8(VarI4FromI8, -1, 2147483648ul); EXPECT(-2147483647 - 1);
1664 CONVERT_I8(VarI4FromI8, 0, 2147483647ul); EXPECT(2147483647);
1665 CONVERT_I8(VarI4FromI8, 0, 2147483648ul); EXPECT_OVERFLOW;
1668 static void test_VarI4FromUI1(void)
1673 CHECKPTR(VarI4FromUI1);
1674 CONVERTRANGE(VarI4FromUI1, 0, 256);
1677 static void test_VarI4FromUI2(void)
1682 CHECKPTR(VarI4FromUI2);
1683 CONVERTRANGE(VarI4FromUI2, 0, 65536);
1686 static void test_VarI4FromUI4(void)
1690 CHECKPTR(VarI4FromUI4);
1691 CONVERT(VarI4FromUI4, 0); EXPECT(0);
1692 CONVERT(VarI4FromUI4, 1); EXPECT(1);
1693 CONVERT(VarI4FromUI4, 2147483647); EXPECT(2147483647);
1694 CONVERT(VarI4FromUI4, 2147483648ul); EXPECT_OVERFLOW;
1697 static void test_VarI4FromUI8(void)
1701 CHECKPTR(VarI4FromUI8);
1702 CONVERT(VarI4FromUI8, 0); EXPECT(0);
1703 CONVERT(VarI4FromUI8, 1); EXPECT(1);
1704 CONVERT(VarI4FromUI8, 2147483647); EXPECT(2147483647);
1705 CONVERT(VarI4FromUI8, 2147483648ul); EXPECT_OVERFLOW;
1708 static void test_VarI4FromBool(void)
1710 CONVVARS(VARIANT_BOOL);
1713 CHECKPTR(VarI4FromBool);
1714 CONVERTRANGE(VarI4FromBool, -32768, 32768);
1717 static void test_VarI4FromR4(void)
1721 CHECKPTR(VarI4FromR4);
1723 /* min/max values are not exactly representable in a float */
1724 CONVERT(VarI4FromR4, -1.0f); EXPECT(-1);
1725 CONVERT(VarI4FromR4, 0.0f); EXPECT(0);
1726 CONVERT(VarI4FromR4, 1.0f); EXPECT(1);
1728 CONVERT(VarI4FromR4, -1.5f); EXPECT(-2);
1729 CONVERT(VarI4FromR4, -0.6f); EXPECT(-1);
1730 CONVERT(VarI4FromR4, -0.5f); EXPECT(0);
1731 CONVERT(VarI4FromR4, -0.4f); EXPECT(0);
1732 CONVERT(VarI4FromR4, 0.4f); EXPECT(0);
1733 CONVERT(VarI4FromR4, 0.5f); EXPECT(0);
1734 CONVERT(VarI4FromR4, 0.6f); EXPECT(1);
1735 CONVERT(VarI4FromR4, 1.5f); EXPECT(2);
1738 static void test_VarI4FromR8(void)
1742 CHECKPTR(VarI4FromR8);
1743 CONVERT(VarI4FromR8, -2147483649.0); EXPECT_OVERFLOW;
1744 CONVERT(VarI4FromR8, -2147483648.0); EXPECT(-2147483647 - 1);
1745 CONVERT(VarI4FromR8, -1.0); EXPECT(-1);
1746 CONVERT(VarI4FromR8, 0.0); EXPECT(0);
1747 CONVERT(VarI4FromR8, 1.0); EXPECT(1);
1748 CONVERT(VarI4FromR8, 2147483647.0); EXPECT(2147483647);
1749 CONVERT(VarI4FromR8, 2147483648.0); EXPECT_OVERFLOW;
1751 CONVERT(VarI4FromR8, -1.5); EXPECT(-2);
1752 CONVERT(VarI4FromR8, -0.6); EXPECT(-1);
1753 CONVERT(VarI4FromR8, -0.5); EXPECT(0);
1754 CONVERT(VarI4FromR8, -0.4); EXPECT(0);
1755 CONVERT(VarI4FromR8, 0.4); EXPECT(0);
1756 CONVERT(VarI4FromR8, 0.5); EXPECT(0);
1757 CONVERT(VarI4FromR8, 0.6); EXPECT(1);
1758 CONVERT(VarI4FromR8, 1.5); EXPECT(2);
1761 static void test_VarI4FromDate(void)
1765 CHECKPTR(VarI4FromDate);
1766 CONVERT(VarI4FromDate, -2147483649.0); EXPECT_OVERFLOW;
1767 CONVERT(VarI4FromDate, -2147483648.0); EXPECT(-2147483647 - 1);
1768 CONVERT(VarI4FromDate, -1.0); EXPECT(-1);
1769 CONVERT(VarI4FromDate, 0.0); EXPECT(0);
1770 CONVERT(VarI4FromDate, 1.0); EXPECT(1);
1771 CONVERT(VarI4FromDate, 2147483647.0); EXPECT(2147483647);
1772 CONVERT(VarI4FromDate, 2147483648.0); EXPECT_OVERFLOW;
1774 CONVERT(VarI4FromDate, -1.5); EXPECT(-2);
1775 CONVERT(VarI4FromDate, -0.6); EXPECT(-1);
1776 CONVERT(VarI4FromDate, -0.5); EXPECT(0);
1777 CONVERT(VarI4FromDate, -0.4); EXPECT(0);
1778 CONVERT(VarI4FromDate, 0.4); EXPECT(0);
1779 CONVERT(VarI4FromDate, 0.5); EXPECT(0);
1780 CONVERT(VarI4FromDate, 0.6); EXPECT(1);
1781 CONVERT(VarI4FromDate, 1.5); EXPECT(2);
1784 static void test_VarI4FromCy(void)
1788 CHECKPTR(VarI4FromCy);
1789 CONVERT_CY(VarI4FromCy,-1); EXPECT(-1);
1790 CONVERT_CY(VarI4FromCy,0); EXPECT(0);
1791 CONVERT_CY(VarI4FromCy,1); EXPECT(1);
1793 CONVERT_CY64(VarI4FromCy,-1,2147483647ul); EXPECT_OVERFLOW;
1794 CONVERT_CY64(VarI4FromCy,-1,2147483648ul); EXPECT(-2147483647 - 1);
1795 CONVERT_CY64(VarI4FromCy,0,2147483647ul); EXPECT(2147483647ul);
1796 CONVERT_CY64(VarI4FromCy,0,2147483648ul); EXPECT_OVERFLOW;
1798 CONVERT_CY(VarI4FromCy,-1.5); EXPECT(-2);
1799 CONVERT_CY(VarI4FromCy,-0.6); EXPECT(-1);
1800 CONVERT_CY(VarI4FromCy,-0.5); EXPECT(0);
1801 CONVERT_CY(VarI4FromCy,-0.4); EXPECT(0);
1802 CONVERT_CY(VarI4FromCy,0.4); EXPECT(0);
1803 CONVERT_CY(VarI4FromCy,0.5); EXPECT(0);
1804 CONVERT_CY(VarI4FromCy,0.6); EXPECT(1);
1805 CONVERT_CY(VarI4FromCy,1.5); EXPECT(2);
1808 static void test_VarI4FromDec(void)
1812 CHECKPTR(VarI4FromDec);
1814 CONVERT_BADDEC(VarI4FromDec);
1816 CONVERT_DEC(VarI4FromDec,0,0x80,0,1); EXPECT(-1);
1817 CONVERT_DEC(VarI4FromDec,0,0,0,0); EXPECT(0);
1818 CONVERT_DEC(VarI4FromDec,0,0,0,1); EXPECT(1);
1820 CONVERT_DEC64(VarI4FromDec,0,0x80,0,0,2147483649ul); EXPECT_OVERFLOW;
1821 CONVERT_DEC64(VarI4FromDec,0,0x80,0,0,2147483648ul); EXPECT(-2147483647 - 1);
1822 CONVERT_DEC64(VarI4FromDec,0,0,0,0,2147483647ul); EXPECT(2147483647ul);
1823 CONVERT_DEC64(VarI4FromDec,0,0,0,0,2147483648ul); EXPECT_OVERFLOW;
1825 CONVERT_DEC64(VarI4FromDec,2,0x80,0,50,100); EXPECT_OVERFLOW;
1826 CONVERT_DEC64(VarI4FromDec,2,0x80,0,50,0); EXPECT(-2147483647 - 1);
1827 CONVERT_DEC64(VarI4FromDec,2,0,0,49,4294967196ul); EXPECT(2147483647);
1828 CONVERT_DEC64(VarI4FromDec,2,0,0,50,0); EXPECT_OVERFLOW;
1831 static void test_VarI4FromStr(void)
1836 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1838 CHECKPTR(VarI4FromStr);
1840 CONVERT_STR(VarI4FromStr,NULL,0); EXPECT_MISMATCH;
1841 CONVERT_STR(VarI4FromStr,"0",0); EXPECT(0);
1842 CONVERT_STR(VarI4FromStr,"-2147483649",0); EXPECT_OVERFLOW;
1843 CONVERT_STR(VarI4FromStr,"-2147483648",0); EXPECT(-2147483647 -1);
1844 CONVERT_STR(VarI4FromStr,"2147483647",0); EXPECT(2147483647);
1845 CONVERT_STR(VarI4FromStr,"2147483648",0); EXPECT_OVERFLOW;
1848 CONVERT_STR(VarI4FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECT(-2);
1849 CONVERT_STR(VarI4FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECT(-1);
1850 CONVERT_STR(VarI4FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0);
1851 CONVERT_STR(VarI4FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0);
1852 CONVERT_STR(VarI4FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0);
1853 CONVERT_STR(VarI4FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0);
1854 CONVERT_STR(VarI4FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECT(1);
1855 CONVERT_STR(VarI4FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECT(2);
1858 static void test_VarI4Copy(void)
1860 COPYTEST(1, VT_I4, V_I4(&vSrc), V_I4(&vDst), V_I4REF(&vSrc), V_I4REF(&vDst), "%d");
1863 static void test_VarI4ChangeTypeEx(void)
1865 CONVVARS(CONV_TYPE);
1866 VARIANTARG vSrc, vDst;
1870 INITIAL_TYPETEST(VT_I4, V_I4, "%d");
1872 NEGATIVE_TYPETEST(VT_I4, V_I4, "%d", VT_UI4, V_UI4);
1876 #define CONV_TYPE ULONG
1878 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%u")
1880 static void test_VarUI4FromI1(void)
1882 CONVVARS(signed char);
1885 CHECKPTR(VarUI4FromI1);
1886 OVERFLOWRANGE(VarUI4FromI1, -127, 0);
1887 CONVERTRANGE(VarUI4FromI1, 0, 128);
1890 static void test_VarUI4FromI2(void)
1895 CHECKPTR(VarUI4FromI2);
1896 OVERFLOWRANGE(VarUI4FromI2, -32768, 0);
1897 CONVERTRANGE(VarUI4FromI2, 0, 32768);
1900 static void test_VarUI4FromUI2(void)
1905 CHECKPTR(VarUI4FromUI2);
1906 CONVERTRANGE(VarUI4FromUI2, 0, 65536);
1909 static void test_VarUI4FromI8(void)
1913 CHECKPTR(VarUI4FromI8);
1914 CONVERT(VarUI4FromI8, -1); EXPECT_OVERFLOW;
1915 CONVERT(VarUI4FromI8, 0); EXPECT(0);
1916 CONVERT(VarUI4FromI8, 1); EXPECT(1);
1917 CONVERT(VarUI4FromI8, 4294967295ul); EXPECT(4294967295ul);
1918 CONVERT_I8(VarUI4FromI8, 1, 0); EXPECT_OVERFLOW;
1921 static void test_VarUI4FromUI1(void)
1926 CHECKPTR(VarUI4FromUI1);
1927 CONVERTRANGE(VarUI4FromUI1, 0, 256);
1930 static void test_VarUI4FromI4(void)
1934 CHECKPTR(VarUI4FromI4);
1935 CONVERT(VarUI4FromI4, -1); EXPECT_OVERFLOW;
1936 CONVERT(VarUI4FromI4, 0); EXPECT(0);
1937 CONVERT(VarUI4FromI4, 1); EXPECT(1);
1938 CONVERT(VarUI4FromI4, 2147483647); EXPECT(2147483647);
1941 static void test_VarUI4FromUI8(void)
1945 CHECKPTR(VarUI4FromUI8);
1946 CONVERT(VarUI4FromUI8, 0); EXPECT(0);
1947 CONVERT(VarUI4FromUI8, 1); EXPECT(1);
1948 CONVERT(VarUI4FromI8, 4294967295ul); EXPECT(4294967295ul);
1949 CONVERT_I8(VarUI4FromI8, 1, 0); EXPECT_OVERFLOW;
1952 static void test_VarUI4FromBool(void)
1954 CONVVARS(VARIANT_BOOL);
1957 CHECKPTR(VarUI4FromBool);
1958 CONVERTRANGE(VarUI4FromBool, -32768, 32768);
1961 static void test_VarUI4FromR4(void)
1965 CHECKPTR(VarUI4FromR4);
1966 /* We can't test max values as they are not exactly representable in a float */
1967 CONVERT(VarUI4FromR4, -1.0f); EXPECT_OVERFLOW;
1968 CONVERT(VarUI4FromR4, 0.0f); EXPECT(0);
1969 CONVERT(VarUI4FromR4, 1.0f); EXPECT(1);
1971 CONVERT(VarUI4FromR4, -1.5f); EXPECT_OVERFLOW;
1972 CONVERT(VarUI4FromR4, -0.6f); EXPECT_OVERFLOW;
1973 CONVERT(VarUI4FromR4, -0.5f); EXPECT(0);
1974 CONVERT(VarUI4FromR4, -0.4f); EXPECT(0);
1975 CONVERT(VarUI4FromR4, 0.4f); EXPECT(0);
1976 CONVERT(VarUI4FromR4, 0.5f); EXPECT(0);
1977 CONVERT(VarUI4FromR4, 0.6f); EXPECT(1);
1978 CONVERT(VarUI4FromR4, 1.5f); EXPECT(2);
1982 static void test_VarUI4FromR8(void)
1986 CHECKPTR(VarUI4FromR8);
1987 CONVERT(VarUI4FromR8, -1.0); EXPECT_OVERFLOW;
1988 CONVERT(VarUI4FromR8, 0.0); EXPECT(0);
1989 CONVERT(VarUI4FromR8, 1.0); EXPECT(1);
1990 CONVERT(VarUI4FromR8, 4294967295.0); EXPECT(4294967295ul);
1991 CONVERT(VarUI4FromR8, 4294967296.0); EXPECT_OVERFLOW;
1993 CONVERT(VarUI4FromR8, -1.5); EXPECT_OVERFLOW;
1994 CONVERT(VarUI4FromR8, -0.6); EXPECT_OVERFLOW;
1995 CONVERT(VarUI4FromR8, -0.5); EXPECT(0);
1996 CONVERT(VarUI4FromR8, -0.4); EXPECT(0);
1997 CONVERT(VarUI4FromR8, 0.4); EXPECT(0);
1998 CONVERT(VarUI4FromR8, 0.5); EXPECT(0);
1999 CONVERT(VarUI4FromR8, 0.6); EXPECT(1);
2000 CONVERT(VarUI4FromR8, 1.5); EXPECT(2);
2003 static void test_VarUI4FromDate(void)
2007 CHECKPTR(VarUI4FromDate);
2008 CONVERT(VarUI4FromDate, -1.0); EXPECT_OVERFLOW;
2009 CONVERT(VarUI4FromDate, 0.0); EXPECT(0);
2010 CONVERT(VarUI4FromDate, 1.0); EXPECT(1);
2011 CONVERT(VarUI4FromDate, 4294967295.0); EXPECT(4294967295ul);
2012 CONVERT(VarUI4FromDate, 4294967296.0); EXPECT_OVERFLOW;
2014 CONVERT(VarUI4FromDate, -1.5); EXPECT_OVERFLOW;
2015 CONVERT(VarUI4FromDate, -0.6); EXPECT_OVERFLOW;
2016 CONVERT(VarUI4FromDate, -0.5); EXPECT(0);
2017 CONVERT(VarUI4FromDate, -0.4); EXPECT(0);
2018 CONVERT(VarUI4FromDate, 0.4); EXPECT(0);
2019 CONVERT(VarUI4FromDate, 0.5); EXPECT(0);
2020 CONVERT(VarUI4FromDate, 0.6); EXPECT(1);
2021 CONVERT(VarUI4FromDate, 1.5); EXPECT(2);
2024 static void test_VarUI4FromCy(void)
2028 CHECKPTR(VarUI4FromCy);
2029 CONVERT_CY(VarUI4FromCy,-1); EXPECT_OVERFLOW;
2030 CONVERT_CY(VarUI4FromCy,0); EXPECT(0);
2031 CONVERT_CY(VarUI4FromCy,1); EXPECT(1);
2032 CONVERT_CY64(VarUI4FromCy,0,4294967295ul); EXPECT(4294967295ul);
2033 CONVERT_CY64(VarUI4FromCy,1,0); EXPECT_OVERFLOW;
2035 CONVERT_CY(VarUI4FromCy,-1.5); EXPECT_OVERFLOW;
2036 CONVERT_CY(VarUI4FromCy,-0.6); EXPECT_OVERFLOW;
2037 CONVERT_CY(VarUI4FromCy,-0.5); EXPECT(0);
2038 CONVERT_CY(VarUI4FromCy,-0.4); EXPECT(0);
2039 CONVERT_CY(VarUI4FromCy,0.4); EXPECT(0);
2040 CONVERT_CY(VarUI4FromCy,0.5); EXPECT(0);
2041 CONVERT_CY(VarUI4FromCy,0.6); EXPECT(1);
2042 CONVERT_CY(VarUI4FromCy,1.5); EXPECT(2);
2045 static void test_VarUI4FromDec(void)
2049 CHECKPTR(VarUI4FromDec);
2051 CONVERT_BADDEC(VarUI4FromDec);
2053 CONVERT_DEC(VarUI4FromDec,0,0x80,0,1); EXPECT_OVERFLOW;
2054 CONVERT_DEC(VarUI4FromDec,0,0,0,0); EXPECT(0);
2055 CONVERT_DEC(VarUI4FromDec,0,0,0,1); EXPECT(1);
2056 CONVERT_DEC64(VarUI4FromDec,0,0,0,0,4294967295ul); EXPECT(4294967295ul);
2057 CONVERT_DEC64(VarUI4FromDec,0,0,0,1,0); EXPECT_OVERFLOW;
2059 CONVERT_DEC64(VarUI4FromDec,2,0,0,99,4294967196ul); EXPECT(4294967295ul);
2060 CONVERT_DEC64(VarUI4FromDec,2,0,0,100,0); EXPECT_OVERFLOW;
2063 static void test_VarUI4FromStr(void)
2068 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2070 CHECKPTR(VarUI4FromStr);
2072 CONVERT_STR(VarUI4FromStr,NULL,0); EXPECT_MISMATCH;
2073 CONVERT_STR(VarUI4FromStr,"-1",0); EXPECT_OVERFLOW;
2074 CONVERT_STR(VarUI4FromStr,"0",0); EXPECT(0);
2075 CONVERT_STR(VarUI4FromStr,"4294967295",0); EXPECT(4294967295ul);
2076 CONVERT_STR(VarUI4FromStr,"4294967296",0); EXPECT_OVERFLOW;
2079 CONVERT_STR(VarUI4FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
2080 CONVERT_STR(VarUI4FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
2081 CONVERT_STR(VarUI4FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0);
2082 CONVERT_STR(VarUI4FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0);
2083 CONVERT_STR(VarUI4FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0);
2084 CONVERT_STR(VarUI4FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0);
2085 CONVERT_STR(VarUI4FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECT(1);
2086 CONVERT_STR(VarUI4FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECT(2);
2089 static void test_VarUI4Copy(void)
2093 COPYTEST(1u, VT_UI4, V_UI4(&vSrc), V_UI4(&vDst), V_UI4REF(&vSrc), V_UI4REF(&vDst), "%u");
2097 static void test_VarUI4ChangeTypeEx(void)
2099 CONVVARS(CONV_TYPE);
2100 VARIANTARG vSrc, vDst;
2106 INITIAL_TYPETEST(VT_UI4, V_UI4, "%u");
2108 NEGATIVE_TYPETEST(VT_UI4, V_UI4, "%u", VT_I4, V_I4);
2117 #define CONV_TYPE LONG64
2119 #define EXPECTRES(res, x) \
2120 ok(hres == S_OK || ((HRESULT)res != S_OK && hres == (HRESULT)res), \
2121 "expected hres " #x ", got hres=0x%08x\n", hres)
2123 #define EXPECTI8(x) \
2124 ok((hres == S_OK && out == (CONV_TYPE)(x)), \
2125 "expected " #x "(%u,%u), got (%u,%u); hres=0x%08x\n", \
2126 (ULONG)((LONG64)(x) >> 32), (ULONG)((x) & 0xffffffff), \
2127 (ULONG)(out >> 32), (ULONG)(out & 0xffffffff), hres)
2129 #define EXPECTI864(x,y) \
2130 ok(hres == S_OK && (out >> 32) == (CONV_TYPE)(x) && (out & 0xffffffff) == (CONV_TYPE)(y), \
2131 "expected " #x "(%u,%u), got (%u,%u); hres=0x%08x\n", \
2132 (ULONG)(x), (ULONG)(y), \
2133 (ULONG)(out >> 32), (ULONG)(out & 0xffffffff), hres)
2135 static void test_VarI8FromI1(void)
2137 CONVVARS(signed char);
2140 CHECKPTR(VarI8FromI1);
2141 for (i = -128; i < 128; i++)
2143 CONVERT(VarI8FromI1,i); EXPECTI8(i);
2147 static void test_VarI8FromUI1(void)
2152 CHECKPTR(VarI8FromUI1);
2153 for (i = 0; i < 256; i++)
2155 CONVERT(VarI8FromUI1,i); EXPECTI8(i);
2159 static void test_VarI8FromI2(void)
2164 CHECKPTR(VarI8FromI2);
2165 for (i = -32768; i < 32768; i++)
2167 CONVERT(VarI8FromI2,i); EXPECTI8(i);
2171 static void test_VarI8FromUI2(void)
2176 CHECKPTR(VarI8FromUI2);
2177 for (i = -0; i < 65535; i++)
2179 CONVERT(VarI8FromUI2,i); EXPECTI8(i);
2183 static void test_VarI8FromUI4(void)
2187 CHECKPTR(VarI8FromUI4);
2188 CONVERT(VarI8FromUI4, 0); EXPECTI8(0);
2189 CONVERT(VarI8FromUI4, 1); EXPECTI8(1);
2190 CONVERT(VarI8FromUI4, 4294967295ul); EXPECTI8(4294967295ul);
2193 static void test_VarI8FromR4(void)
2197 CHECKPTR(VarI8FromR4);
2199 CONVERT(VarI8FromR4, -128.0f); EXPECTI8(-128);
2200 CONVERT(VarI8FromR4, -1.0f); EXPECTI8(-1);
2201 CONVERT(VarI8FromR4, 0.0f); EXPECTI8(0);
2202 CONVERT(VarI8FromR4, 1.0f); EXPECTI8(1);
2203 CONVERT(VarI8FromR4, 127.0f); EXPECTI8(127);
2205 CONVERT(VarI8FromR4, -1.5f); EXPECTI8(-2);
2206 CONVERT(VarI8FromR4, -0.6f); EXPECTI8(-1);
2207 CONVERT(VarI8FromR4, -0.5f); EXPECTI8(0);
2208 CONVERT(VarI8FromR4, -0.4f); EXPECTI8(0);
2209 CONVERT(VarI8FromR4, 0.4f); EXPECTI8(0);
2210 CONVERT(VarI8FromR4, 0.5f); EXPECTI8(0);
2211 CONVERT(VarI8FromR4, 0.6f); EXPECTI8(1);
2212 CONVERT(VarI8FromR4, 1.5f); EXPECTI8(2);
2215 static void test_VarI8FromR8(void)
2219 CHECKPTR(VarI8FromR8);
2220 CONVERT(VarI8FromR8, -128.0); EXPECTI8(-128);
2221 CONVERT(VarI8FromR8, -1.0); EXPECTI8(-1);
2222 CONVERT(VarI8FromR8, 0.0); EXPECTI8(0);
2223 CONVERT(VarI8FromR8, 1.0); EXPECTI8(1);
2224 CONVERT(VarI8FromR8, 127.0); EXPECTI8(127);
2226 CONVERT(VarI8FromR8, -1.5); EXPECTI8(-2);
2227 CONVERT(VarI8FromR8, -0.6); EXPECTI8(-1);
2228 CONVERT(VarI8FromR8, -0.5); EXPECTI8(0);
2229 CONVERT(VarI8FromR8, -0.4); EXPECTI8(0);
2230 CONVERT(VarI8FromR8, 0.4); EXPECTI8(0);
2231 CONVERT(VarI8FromR8, 0.5); EXPECTI8(0);
2232 CONVERT(VarI8FromR8, 0.6); EXPECTI8(1);
2233 CONVERT(VarI8FromR8, 1.5); EXPECTI8(2);
2236 static void test_VarI8FromDate(void)
2240 CHECKPTR(VarI8FromDate);
2241 CONVERT(VarI8FromDate, -128.0); EXPECTI8(-128);
2242 CONVERT(VarI8FromDate, -1.0); EXPECTI8(-1);
2243 CONVERT(VarI8FromDate, 0.0); EXPECTI8(0);
2244 CONVERT(VarI8FromDate, 1.0); EXPECTI8(1);
2245 CONVERT(VarI8FromDate, 127.0); EXPECTI8(127);
2247 CONVERT(VarI8FromDate, -1.5); EXPECTI8(-2);
2248 CONVERT(VarI8FromDate, -0.6); EXPECTI8(-1);
2249 CONVERT(VarI8FromDate, -0.5); EXPECTI8(0);
2250 CONVERT(VarI8FromDate, -0.4); EXPECTI8(0);
2251 CONVERT(VarI8FromDate, 0.4); EXPECTI8(0);
2252 CONVERT(VarI8FromDate, 0.5); EXPECTI8(0);
2253 CONVERT(VarI8FromDate, 0.6); EXPECTI8(1);
2254 CONVERT(VarI8FromDate, 1.5); EXPECTI8(2);
2257 static void test_VarI8FromBool(void)
2259 CONVVARS(VARIANT_BOOL);
2262 CHECKPTR(VarI8FromBool);
2263 for (i = -32768; i < 32768; i++)
2265 CONVERT(VarI8FromBool,i); EXPECTI8(i);
2269 static void test_VarI8FromUI8(void)
2273 CHECKPTR(VarI8FromUI8);
2274 CONVERT(VarI8FromUI8, 0); EXPECTI8(0);
2275 CONVERT(VarI8FromUI8, 1); EXPECTI8(1);
2276 CONVERT_I8(VarI8FromUI8, 0x7fffffff, 0xffffffff); EXPECTI864(0x7fffffff, 0xffffffff);
2277 CONVERT_I8(VarI8FromUI8, 0x80000000, 0); EXPECT_OVERFLOW;
2280 static void test_VarI8FromCy(void)
2284 CHECKPTR(VarI8FromCy);
2285 CONVERT_CY(VarI8FromCy,-128); EXPECTI8(-129);
2286 CONVERT_CY(VarI8FromCy,-1); EXPECTI8(-2);
2287 CONVERT_CY(VarI8FromCy,0); EXPECTI8(0);
2288 CONVERT_CY(VarI8FromCy,1); EXPECTI8(1);
2289 CONVERT_CY(VarI8FromCy,127); EXPECTI8(127);
2291 CONVERT_CY(VarI8FromCy,-1.5); EXPECTI8(-2);
2292 CONVERT_CY(VarI8FromCy,-0.6); EXPECTI8(-1);
2293 CONVERT_CY(VarI8FromCy,-0.5); EXPECTI8(-1);
2294 CONVERT_CY(VarI8FromCy,-0.4); EXPECTI8(-1);
2295 CONVERT_CY(VarI8FromCy,0.4); EXPECTI8(0);
2296 CONVERT_CY(VarI8FromCy,0.5); EXPECTI8(0);
2297 CONVERT_CY(VarI8FromCy,0.6); EXPECTI8(1);
2298 CONVERT_CY(VarI8FromCy,1.5); EXPECTI8(2);
2301 static void test_VarI8FromDec(void)
2305 CHECKPTR(VarI8FromDec);
2307 CONVERT_BADDEC(VarI8FromDec);
2309 CONVERT_DEC(VarI8FromDec,0,0x80,0,128); EXPECTI8(-128);
2310 CONVERT_DEC(VarI8FromDec,0,0x80,0,1); EXPECTI8(-1);
2311 CONVERT_DEC(VarI8FromDec,0,0,0,0); EXPECTI8(0);
2312 CONVERT_DEC(VarI8FromDec,0,0,0,1); EXPECTI8(1);
2313 CONVERT_DEC(VarI8FromDec,0,0,0,127); EXPECTI8(127);
2315 CONVERT_DEC(VarI8FromDec,2,0x80,0,12700); EXPECTI8(-127);
2316 CONVERT_DEC(VarI8FromDec,2,0,0,12700); EXPECTI8(127);
2319 static void test_VarI8FromStr(void)
2324 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2326 CHECKPTR(VarI8FromStr);
2328 CONVERT_STR(VarI8FromStr,NULL,0); EXPECT_MISMATCH;
2329 CONVERT_STR(VarI8FromStr,"0",0); EXPECTI8(0);
2330 CONVERT_STR(VarI8FromStr,"-1",0); EXPECTI8(-1);
2331 CONVERT_STR(VarI8FromStr,"2147483647",0); EXPECTI8(2147483647);
2333 CONVERT_STR(VarI8FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(-2);
2334 CONVERT_STR(VarI8FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECTI8(-1);
2335 CONVERT_STR(VarI8FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2336 CONVERT_STR(VarI8FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2337 CONVERT_STR(VarI8FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2338 CONVERT_STR(VarI8FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2339 CONVERT_STR(VarI8FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECTI8(1);
2340 CONVERT_STR(VarI8FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(2);
2343 static void test_VarI8Copy(void)
2346 VARIANTARG vSrc, vDst;
2349 if (!HAVE_OLEAUT32_I8)
2354 V_VT(&vSrc) = VT_I8;
2356 hres = VariantCopy(&vDst, &vSrc);
2357 ok(hres == S_OK && V_VT(&vDst) == VT_I8 && V_I8(&vDst) == in,
2358 "copy hres 0x%X, type %d, value (%x%08x) %x%08x\n",
2359 hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_I8(&vDst) >> 32), (UINT)V_I8(&vDst) );
2360 V_VT(&vSrc) = VT_I8|VT_BYREF;
2361 V_I8REF(&vSrc) = ∈
2362 hres = VariantCopy(&vDst, &vSrc);
2363 ok(hres == S_OK && V_VT(&vDst) == (VT_I8|VT_BYREF) && V_I8REF(&vDst) == &in,
2364 "ref hres 0x%X, type %d, ref (%p) %p\n", hres, V_VT(&vDst), &in, V_I8REF(&vDst));
2365 hres = VariantCopyInd(&vDst, &vSrc);
2366 ok(hres == S_OK && V_VT(&vDst) == VT_I8 && V_I8(&vDst) == in,
2367 "copy hres 0x%X, type %d, value (%x%08x) %x%08x\n",
2368 hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_I8(&vDst) >> 32), (UINT)V_I8(&vDst) );
2371 static void test_VarI8ChangeTypeEx(void)
2373 CONVVARS(CONV_TYPE);
2374 VARIANTARG vSrc, vDst;
2376 if (!HAVE_OLEAUT32_I8)
2381 INITIAL_TYPETESTI8(VT_I8, V_I8);
2385 /* Adapt the test macros to UI8 */
2387 #define CONV_TYPE ULONG64
2389 static void test_VarUI8FromI1(void)
2391 CONVVARS(signed char);
2394 CHECKPTR(VarUI8FromI1);
2395 for (i = -128; i < 128; i++)
2397 CONVERT(VarUI8FromI1,i);
2405 static void test_VarUI8FromUI1(void)
2410 CHECKPTR(VarUI8FromUI1);
2411 for (i = 0; i < 256; i++)
2413 CONVERT(VarUI8FromUI1,i); EXPECTI8(i);
2417 static void test_VarUI8FromI2(void)
2422 CHECKPTR(VarUI8FromI2);
2423 for (i = -32768; i < 32768; i++)
2425 CONVERT(VarUI8FromI2,i);
2433 static void test_VarUI8FromUI2(void)
2438 CHECKPTR(VarUI8FromUI2);
2439 for (i = 0; i < 65535; i++)
2441 CONVERT(VarUI8FromUI2,i); EXPECTI8(i);
2445 static void test_VarUI8FromUI4(void)
2449 CHECKPTR(VarUI8FromUI4);
2450 CONVERT(VarUI8FromUI4, 0); EXPECTI8(0);
2451 CONVERT(VarUI8FromUI4, 0xffffffff); EXPECTI8(0xffffffff);
2454 static void test_VarUI8FromR4(void)
2458 CHECKPTR(VarUI8FromR4);
2459 CONVERT(VarUI8FromR4, -1.0f); EXPECT_OVERFLOW;
2460 CONVERT(VarUI8FromR4, 0.0f); EXPECTI8(0);
2461 CONVERT(VarUI8FromR4, 1.0f); EXPECTI8(1);
2462 CONVERT(VarUI8FromR4, 255.0f); EXPECTI8(255);
2464 CONVERT(VarUI8FromR4, -1.5f); EXPECT_OVERFLOW;
2465 CONVERT(VarUI8FromR4, -0.6f); EXPECT_OVERFLOW;
2466 CONVERT(VarUI8FromR4, -0.5f); EXPECTI8(0);
2467 CONVERT(VarUI8FromR4, -0.4f); EXPECTI8(0);
2468 CONVERT(VarUI8FromR4, 0.4f); EXPECTI8(0);
2469 CONVERT(VarUI8FromR4, 0.5f); EXPECTI8(0);
2470 CONVERT(VarUI8FromR4, 0.6f); EXPECTI8(1);
2471 CONVERT(VarUI8FromR4, 1.5f); EXPECTI8(2);
2474 static void test_VarUI8FromR8(void)
2478 CHECKPTR(VarUI8FromR8);
2479 CONVERT(VarUI8FromR8, -1.0); EXPECT_OVERFLOW;
2480 CONVERT(VarUI8FromR8, 0.0); EXPECTI8(0);
2481 CONVERT(VarUI8FromR8, 1.0); EXPECTI8(1);
2482 CONVERT(VarUI8FromR8, 255.0); EXPECTI8(255);
2484 CONVERT(VarUI8FromR8, -1.5); EXPECT_OVERFLOW;
2485 CONVERT(VarUI8FromR8, -0.6); EXPECT_OVERFLOW;
2486 CONVERT(VarUI8FromR8, -0.5); EXPECTI8(0);
2487 CONVERT(VarUI8FromR8, -0.4); EXPECTI8(0);
2488 CONVERT(VarUI8FromR8, 0.4); EXPECTI8(0);
2489 CONVERT(VarUI8FromR8, 0.5); EXPECTI8(0);
2490 CONVERT(VarUI8FromR8, 0.6); EXPECTI8(1);
2491 CONVERT(VarUI8FromR8, 1.5); EXPECTI8(2);
2494 static void test_VarUI8FromDate(void)
2498 CHECKPTR(VarUI8FromDate);
2499 CONVERT(VarUI8FromDate, -1.0); EXPECT_OVERFLOW;
2500 CONVERT(VarUI8FromDate, 0.0); EXPECTI8(0);
2501 CONVERT(VarUI8FromDate, 1.0); EXPECTI8(1);
2502 CONVERT(VarUI8FromDate, 255.0); EXPECTI8(255);
2504 CONVERT(VarUI8FromDate, -1.5); EXPECT_OVERFLOW;
2505 CONVERT(VarUI8FromDate, -0.6); EXPECT_OVERFLOW;
2506 CONVERT(VarUI8FromDate, -0.5); EXPECTI8(0);
2507 CONVERT(VarUI8FromDate, -0.4); EXPECTI8(0);
2508 CONVERT(VarUI8FromDate, 0.4); EXPECTI8(0);
2509 CONVERT(VarUI8FromDate, 0.5); EXPECTI8(0);
2510 CONVERT(VarUI8FromDate, 0.6); EXPECTI8(1);
2511 CONVERT(VarUI8FromDate, 1.5); EXPECTI8(2);
2514 static void test_VarUI8FromBool(void)
2516 CONVVARS(VARIANT_BOOL);
2519 CHECKPTR(VarUI8FromBool);
2520 CONVERTRANGE(VarUI8FromBool, -32768, 32768);
2523 static void test_VarUI8FromI8(void)
2527 CHECKPTR(VarUI8FromI8);
2528 CONVERT(VarUI8FromI8, -1); EXPECT_OVERFLOW;
2529 CONVERT(VarUI8FromI8, 0); EXPECTI8(0);
2530 CONVERT(VarUI8FromI8, 1); EXPECTI8(1);
2533 static void test_VarUI8FromCy(void)
2537 CHECKPTR(VarUI8FromCy);
2538 CONVERT_CY(VarUI8FromCy,-1); EXPECT_OVERFLOW;
2539 CONVERT_CY(VarUI8FromCy,0); EXPECTI8(0);
2540 CONVERT_CY(VarUI8FromCy,1); EXPECTI8(1);
2541 CONVERT_CY(VarUI8FromCy,255); EXPECTI8(255);
2543 CONVERT_CY(VarUI8FromCy,-1.5); EXPECT_OVERFLOW;
2544 CONVERT_CY(VarUI8FromCy,-0.6); EXPECT_OVERFLOW;
2545 CONVERT_CY(VarUI8FromCy,-0.5); EXPECTI8(0);
2546 CONVERT_CY(VarUI8FromCy,-0.4); EXPECTI8(0);
2547 CONVERT_CY(VarUI8FromCy,0.4); EXPECTI8(0);
2548 CONVERT_CY(VarUI8FromCy,0.5); EXPECTI8(0);
2549 CONVERT_CY(VarUI8FromCy,0.6); EXPECTI8(1);
2550 CONVERT_CY(VarUI8FromCy,1.5); EXPECTI8(2);
2553 static void test_VarUI8FromDec(void)
2557 CHECKPTR(VarUI8FromDec);
2559 CONVERT_BADDEC(VarUI8FromDec);
2562 /* This returns 1 under native; Wine fixes this bug and returns overflow */
2563 CONVERT_DEC(VarUI8FromDec,0,0x80,0,1);
2565 CONVERT_DEC(VarUI8FromDec,0,0,0,0); EXPECTI8(0);
2566 CONVERT_DEC(VarUI8FromDec,0,0,0,1); EXPECTI8(1);
2567 CONVERT_DEC(VarUI8FromDec,0,0,0,255); EXPECTI8(255);
2569 CONVERT_DEC(VarUI8FromDec,2,0x80,0,100); EXPECT_OVERFLOW;
2570 CONVERT_DEC(VarUI8FromDec,2,0,0,25500); EXPECTI8(255);
2573 static void test_VarUI8FromStr(void)
2578 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2580 CHECKPTR(VarUI8FromStr);
2582 CONVERT_STR(VarUI8FromStr,NULL,0); EXPECT_MISMATCH;
2583 CONVERT_STR(VarUI8FromStr,"0",0); EXPECTI8(0);
2584 CONVERT_STR(VarUI8FromStr,"-1",0); EXPECT_OVERFLOW;
2585 CONVERT_STR(VarUI8FromStr,"2147483647",0); EXPECTI8(2147483647);
2587 CONVERT_STR(VarUI8FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
2588 CONVERT_STR(VarUI8FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
2589 CONVERT_STR(VarUI8FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2590 CONVERT_STR(VarUI8FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2591 CONVERT_STR(VarUI8FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2592 CONVERT_STR(VarUI8FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2593 CONVERT_STR(VarUI8FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECTI8(1);
2594 CONVERT_STR(VarUI8FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(2);
2597 static void test_VarUI8Copy(void)
2600 VARIANTARG vSrc, vDst;
2603 if (!HAVE_OLEAUT32_I8)
2608 V_VT(&vSrc) = VT_UI8;
2610 hres = VariantCopy(&vDst, &vSrc);
2611 ok(hres == S_OK && V_VT(&vDst) == VT_UI8 && V_UI8(&vDst) == in,
2612 "copy hres 0x%X, type %d, value (%x%08x) %x%08x\n",
2613 hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_UI8(&vDst) >> 32), (UINT)V_UI8(&vDst) );
2614 V_VT(&vSrc) = VT_UI8|VT_BYREF;
2615 V_UI8REF(&vSrc) = ∈
2616 hres = VariantCopy(&vDst, &vSrc);
2617 ok(hres == S_OK && V_VT(&vDst) == (VT_UI8|VT_BYREF) && V_UI8REF(&vDst) == &in,
2618 "ref hres 0x%X, type %d, ref (%p) %p\n", hres, V_VT(&vDst), &in, V_UI8REF(&vDst));
2619 hres = VariantCopyInd(&vDst, &vSrc);
2620 ok(hres == S_OK && V_VT(&vDst) == VT_UI8 && V_UI8(&vDst) == in,
2621 "copy hres 0x%X, type %d, value (%x%08x) %x%08x\n",
2622 hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_UI8(&vDst) >> 32), (UINT)V_UI8(&vDst) );
2625 static void test_VarUI8ChangeTypeEx(void)
2627 CONVVARS(CONV_TYPE);
2628 VARIANTARG vSrc, vDst;
2630 if (!HAVE_OLEAUT32_I8)
2635 INITIAL_TYPETESTI8(VT_UI8, V_UI8);
2644 #define CONV_TYPE float
2646 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%15.15f")
2648 static void test_VarR4FromI1(void)
2650 CONVVARS(signed char);
2653 CHECKPTR(VarR4FromI1);
2654 CONVERTRANGE(VarR4FromI1, -128, 128);
2657 static void test_VarR4FromUI1(void)
2662 CHECKPTR(VarR4FromUI1);
2663 CONVERTRANGE(VarR4FromUI1, 0, 256);
2666 static void test_VarR4FromI2(void)
2671 CHECKPTR(VarR4FromI2);
2672 CONVERTRANGE(VarR4FromI2, -32768, 32768);
2675 static void test_VarR4FromUI2(void)
2680 CHECKPTR(VarR4FromUI2);
2681 CONVERTRANGE(VarR4FromUI2, 0, 65536);
2684 static void test_VarR4FromI4(void)
2688 CHECKPTR(VarR4FromI4);
2689 CONVERT(VarR4FromI4, -2147483647-1); EXPECT(-2147483648.0f);
2690 CONVERT(VarR4FromI4, -1); EXPECT(-1.0f);
2691 CONVERT(VarR4FromI4, 0); EXPECT(0.0f);
2692 CONVERT(VarR4FromI4, 1); EXPECT(1.0f);
2693 CONVERT(VarR4FromI4, 2147483647); EXPECT(2147483647.0f);
2696 static void test_VarR4FromUI4(void)
2698 CONVVARS(unsigned int);
2700 CHECKPTR(VarR4FromUI4);
2701 CONVERT(VarR4FromUI4, 0); EXPECT(0.0f);
2702 CONVERT(VarR4FromUI4, 1); EXPECT(1.0f);
2703 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
2704 CONVERT(VarR4FromUI4, 0xffffffff); EXPECT(4294967296.0f);
2708 static void test_VarR4FromR8(void)
2712 CHECKPTR(VarR4FromR8);
2713 CONVERT(VarR4FromR8, -1.0); EXPECT(-1.0f);
2714 CONVERT(VarR4FromR8, 0.0); EXPECT(0.0f);
2715 CONVERT(VarR4FromR8, 1.0); EXPECT(1.0f);
2716 CONVERT(VarR4FromR8, 1.5); EXPECT(1.5f);
2718 /* Skip rounding tests - no rounding is done */
2721 static void test_VarR4FromBool(void)
2723 CONVVARS(VARIANT_BOOL);
2725 CHECKPTR(VarR4FromBool);
2726 CONVERT(VarR4FromBool, VARIANT_TRUE); EXPECT(VARIANT_TRUE * 1.0f);
2727 CONVERT(VarR4FromBool, VARIANT_FALSE); EXPECT(VARIANT_FALSE * 1.0f);
2730 static void test_VarR4FromCy(void)
2734 CHECKPTR(VarR4FromCy);
2735 CONVERT_CY(VarR4FromCy,-32768); EXPECT(-32768.0f);
2736 CONVERT_CY(VarR4FromCy,-1); EXPECT(-1.0f);
2737 CONVERT_CY(VarR4FromCy,0); EXPECT(0.0f);
2738 CONVERT_CY(VarR4FromCy,1); EXPECT(1.0f);
2739 CONVERT_CY(VarR4FromCy,32768); EXPECT(32768.0f);
2741 CONVERT_CY(VarR4FromCy,-1.5); EXPECT(-1.5f);
2742 CONVERT_CY(VarR4FromCy,-0.6); EXPECT(-0.6f);
2743 CONVERT_CY(VarR4FromCy,-0.5); EXPECT(-0.5f);
2744 CONVERT_CY(VarR4FromCy,-0.4); EXPECT(-0.4f);
2745 CONVERT_CY(VarR4FromCy,0.4); EXPECT(0.4f);
2746 CONVERT_CY(VarR4FromCy,0.5); EXPECT(0.5f);
2747 CONVERT_CY(VarR4FromCy,0.6); EXPECT(0.6f);
2748 CONVERT_CY(VarR4FromCy,1.5); EXPECT(1.5f);
2751 static void test_VarR4FromI8(void)
2755 CHECKPTR(VarR4FromI8);
2756 CONVERT(VarR4FromI8, -1); EXPECT(-1.0f);
2757 CONVERT(VarR4FromI8, 0); EXPECT(0.0f);
2758 CONVERT(VarR4FromI8, 1); EXPECT(1.0f);
2761 static void test_VarR4FromUI8(void)
2765 CHECKPTR(VarR4FromUI8);
2766 CONVERT(VarR4FromUI8, 0); EXPECT(0.0f);
2767 CONVERT(VarR4FromUI8, 1); EXPECT(1.0f);
2770 static void test_VarR4FromDec(void)
2774 CHECKPTR(VarR4FromDec);
2776 CONVERT_BADDEC(VarR4FromDec);
2778 CONVERT_DEC(VarR4FromDec,0,0x80,0,32768); EXPECT(-32768.0f);
2779 CONVERT_DEC(VarR4FromDec,0,0x80,0,1); EXPECT(-1.0f);
2780 CONVERT_DEC(VarR4FromDec,0,0,0,0); EXPECT(0.0f);
2781 CONVERT_DEC(VarR4FromDec,0,0,0,1); EXPECT(1.0f);
2782 CONVERT_DEC(VarR4FromDec,0,0,0,32767); EXPECT(32767.0f);
2784 CONVERT_DEC(VarR4FromDec,2,0x80,0,3276800); EXPECT(-32768.0f);
2785 CONVERT_DEC(VarR4FromDec,2,0,0,3276700); EXPECT(32767.0f);
2787 CONVERT_DEC(VarR4FromDec,0,0,1,0); EXPECT(18446744073709551616.0f);
2790 static void test_VarR4FromDate(void)
2794 CHECKPTR(VarR4FromDate);
2795 CONVERT(VarR4FromDate, -1.0); EXPECT(-1.0f);
2796 CONVERT(VarR4FromDate, 0.0); EXPECT(0.0f);
2797 CONVERT(VarR4FromDate, 1.0); EXPECT(1.0f);
2800 static void test_VarR4FromStr(void)
2805 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2807 CHECKPTR(VarR4FromStr);
2809 CONVERT_STR(VarR4FromStr,NULL,0); EXPECT_MISMATCH;
2810 CONVERT_STR(VarR4FromStr,"-1", 0); EXPECT(-1.0f);
2811 CONVERT_STR(VarR4FromStr,"0", 0); EXPECT(0.0f);
2812 CONVERT_STR(VarR4FromStr,"1", 0); EXPECT(1.0f);
2814 CONVERT_STR(VarR4FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECT(-1.5f);
2815 CONVERT_STR(VarR4FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECT(-0.6f);
2816 CONVERT_STR(VarR4FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECT(-0.5f);
2817 CONVERT_STR(VarR4FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECT(-0.4f);
2818 CONVERT_STR(VarR4FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0.4f);
2819 CONVERT_STR(VarR4FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0.5f);
2820 CONVERT_STR(VarR4FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECT(0.6f);
2821 CONVERT_STR(VarR4FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECT(1.5f);
2824 static void test_VarR4Copy(void)
2826 COPYTEST(77665544.0f, VT_R4, V_R4(&vSrc), V_R4(&vDst), V_R4REF(&vSrc),V_R4REF(&vDst), "%15.15f");
2829 static void test_VarR4ChangeTypeEx(void)
2831 #ifdef HAS_UINT64_TO_FLOAT
2832 CONVVARS(CONV_TYPE);
2833 VARIANTARG vSrc, vDst;
2837 INITIAL_TYPETEST(VT_R4, V_R4, "%f");
2847 #define CONV_TYPE double
2849 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%15.15f")
2851 static void test_VarR8FromI1(void)
2853 CONVVARS(signed char);
2856 CHECKPTR(VarR8FromI1);
2857 CONVERTRANGE(VarR8FromI1, -128, 128);
2860 static void test_VarR8FromUI1(void)
2865 CHECKPTR(VarR8FromUI1);
2866 CONVERTRANGE(VarR8FromUI1, 0, 256);
2869 static void test_VarR8FromI2(void)
2874 CHECKPTR(VarR8FromI2);
2875 CONVERTRANGE(VarR8FromI2, -32768, 32768);
2878 static void test_VarR8FromUI2(void)
2883 CHECKPTR(VarR8FromUI2);
2884 CONVERTRANGE(VarR8FromUI2, 0, 65536);
2887 static void test_VarR8FromI4(void)
2891 CHECKPTR(VarR8FromI4);
2892 CONVERT(VarR8FromI4, -2147483647-1); EXPECT(-2147483648.0);
2893 CONVERT(VarR8FromI4, -1); EXPECT(-1.0);
2894 CONVERT(VarR8FromI4, 0); EXPECT(0.0);
2895 CONVERT(VarR8FromI4, 1); EXPECT(1.0);
2896 CONVERT(VarR8FromI4, 0x7fffffff); EXPECT(2147483647.0);
2899 static void test_VarR8FromUI4(void)
2901 CONVVARS(unsigned int);
2903 CHECKPTR(VarR8FromUI4);
2904 CONVERT(VarR8FromUI4, 0); EXPECT(0.0);
2905 CONVERT(VarR8FromUI4, 1); EXPECT(1.0);
2906 CONVERT(VarR8FromUI4, 0xffffffff); EXPECT(4294967295.0);
2909 static void test_VarR8FromR4(void)
2913 CHECKPTR(VarR8FromR4);
2914 CONVERT(VarR8FromR4, -1.0f); EXPECT(-1.0);
2915 CONVERT(VarR8FromR4, 0.0f); EXPECT(0.0);
2916 CONVERT(VarR8FromR4, 1.0f); EXPECT(1.0);
2917 CONVERT(VarR8FromR4, 1.5f); EXPECT(1.5);
2919 /* Skip rounding tests - no rounding is done */
2922 static void test_VarR8FromBool(void)
2924 CONVVARS(VARIANT_BOOL);
2926 CHECKPTR(VarR8FromBool);
2927 CONVERT(VarR8FromBool, VARIANT_TRUE); EXPECT(VARIANT_TRUE * 1.0);
2928 CONVERT(VarR8FromBool, VARIANT_FALSE); EXPECT(VARIANT_FALSE * 1.0);
2931 static void test_VarR8FromCy(void)
2935 CHECKPTR(VarR8FromCy);
2936 CONVERT_CY(VarR8FromCy,-32769); EXPECT(-32769.0);
2937 CONVERT_CY(VarR8FromCy,-32768); EXPECT(-32768.0);
2938 CONVERT_CY(VarR8FromCy,-1); EXPECT(-1.0);
2939 CONVERT_CY(VarR8FromCy,0); EXPECT(0.0);
2940 CONVERT_CY(VarR8FromCy,1); EXPECT(1.0);
2941 CONVERT_CY(VarR8FromCy,32767); EXPECT(32767.0);
2942 CONVERT_CY(VarR8FromCy,32768); EXPECT(32768.0);
2944 CONVERT_CY(VarR8FromCy,-1.5); EXPECT(-1.5);
2945 CONVERT_CY(VarR8FromCy,-0.6); EXPECT(-0.6);
2946 CONVERT_CY(VarR8FromCy,-0.5); EXPECT(-0.5);
2947 CONVERT_CY(VarR8FromCy,-0.4); EXPECT(-0.4);
2948 CONVERT_CY(VarR8FromCy,0.4); EXPECT(0.4);
2949 CONVERT_CY(VarR8FromCy,0.5); EXPECT(0.5);
2950 CONVERT_CY(VarR8FromCy,0.6); EXPECT(0.6);
2951 CONVERT_CY(VarR8FromCy,1.5); EXPECT(1.5);
2954 static void test_VarR8FromI8(void)
2958 CHECKPTR(VarR8FromI8);
2959 CONVERT(VarR8FromI8, -1); EXPECT(-1.0);
2960 CONVERT(VarR8FromI8, 0); EXPECT(0.0);
2961 CONVERT(VarR8FromI8, 1); EXPECT(1.0);
2962 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
2963 CONVERT_I8(VarR8FromI8, 0x7fffffff,0xffffffff); EXPECT(9223372036854775808.0);
2967 static void test_VarR8FromUI8(void)
2971 CHECKPTR(VarR8FromUI8);
2972 CONVERT(VarR8FromUI8, 0); EXPECT(0.0);
2973 CONVERT(VarR8FromUI8, 1); EXPECT(1.0);
2974 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
2975 CONVERT_I8(VarR8FromUI8, 0x80000000,0); EXPECT(9223372036854775808.0);
2979 static void test_VarR8FromDec(void)
2983 CHECKPTR(VarR8FromDec);
2985 CONVERT_BADDEC(VarR8FromDec);
2987 CONVERT_DEC(VarR8FromDec,0,0x80,0,32768); EXPECT(-32768.0);
2988 CONVERT_DEC(VarR8FromDec,0,0x80,0,1); EXPECT(-1.0);
2989 CONVERT_DEC(VarR8FromDec,0,0,0,0); EXPECT(0.0);
2990 CONVERT_DEC(VarR8FromDec,0,0,0,1); EXPECT(1.0);
2991 CONVERT_DEC(VarR8FromDec,0,0,0,32767); EXPECT(32767.0);
2993 CONVERT_DEC(VarR8FromDec,2,0x80,0,3276800); EXPECT(-32768.0);
2994 CONVERT_DEC(VarR8FromDec,2,0,0,3276700); EXPECT(32767.0);
2996 CONVERT_DEC(VarR8FromDec,0,0,1,0); EXPECT(18446744073709551616.0);
2999 static void test_VarR8FromDate(void)
3003 CHECKPTR(VarR8FromDate);
3004 CONVERT(VarR8FromDate, -1.0); EXPECT(-1.0);
3005 CONVERT(VarR8FromDate, -0.0); EXPECT(0.0);
3006 CONVERT(VarR8FromDate, 1.0); EXPECT(1.0);
3009 static void test_VarR8FromStr(void)
3014 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
3016 CHECKPTR(VarR8FromStr);
3018 CONVERT_STR(VarR8FromStr,NULL,0); EXPECT_MISMATCH;
3019 CONVERT_STR(VarR8FromStr,"",0); EXPECT_MISMATCH;
3020 CONVERT_STR(VarR8FromStr," ",0); EXPECT_MISMATCH;
3022 CONVERT_STR(VarR8FromStr,"0",LOCALE_NOUSEROVERRIDE); EXPECT(0.0);
3023 CONVERT_STR(VarR8FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECT(-1.5);
3024 CONVERT_STR(VarR8FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECT(-0.6);
3025 CONVERT_STR(VarR8FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECT(-0.5);
3026 CONVERT_STR(VarR8FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECT(-0.4);
3027 CONVERT_STR(VarR8FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0.4);
3028 CONVERT_STR(VarR8FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0.5);
3029 CONVERT_STR(VarR8FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECT(0.6);
3030 CONVERT_STR(VarR8FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECT(1.5);
3032 /* We already have exhaustive tests for number parsing, so skip those tests here */
3035 static void test_VarR8Copy(void)
3037 COPYTEST(77665544.0, VT_R8, V_R8(&vSrc), V_R8(&vDst), V_R8REF(&vSrc),V_R8REF(&vDst), "%16.16g");
3040 static void test_VarR8ChangeTypeEx(void)
3042 #ifdef HAS_UINT64_TO_FLOAT
3043 CONVVARS(CONV_TYPE);
3044 VARIANTARG vSrc, vDst;
3048 INITIAL_TYPETEST(VT_R8, V_R8, "%g");
3053 #define MATHRND(l, r) left = l; right = r; hres = pVarR8Round(left, right, &out)
3055 static void test_VarR8Round(void)
3058 double left = 0.0, out;
3061 CHECKPTR(VarR8Round);
3062 MATHRND(0.5432, 5); EXPECT(0.5432);
3063 MATHRND(0.5432, 4); EXPECT(0.5432);
3064 MATHRND(0.5432, 3); EXPECT(0.543);
3065 MATHRND(0.5432, 2); EXPECT(0.54);
3066 MATHRND(0.5432, 1); EXPECT(0.5);
3067 MATHRND(0.5532, 0); EXPECT(1);
3068 MATHRND(0.5532, -1); EXPECT_INVALID;
3070 MATHRND(0.5568, 5); EXPECT(0.5568);
3071 MATHRND(0.5568, 4); EXPECT(0.5568);
3072 MATHRND(0.5568, 3); EXPECT(0.557);
3073 MATHRND(0.5568, 2); EXPECT(0.56);
3074 MATHRND(0.5568, 1); EXPECT(0.6);
3075 MATHRND(0.5568, 0); EXPECT(1);
3076 MATHRND(0.5568, -1); EXPECT_INVALID;
3078 MATHRND(0.4999, 0); EXPECT(0);
3079 MATHRND(0.5000, 0); EXPECT(0);
3080 MATHRND(0.5001, 0); EXPECT(1);
3081 MATHRND(1.4999, 0); EXPECT(1);
3082 MATHRND(1.5000, 0); EXPECT(2);
3083 MATHRND(1.5001, 0); EXPECT(2);
3091 #define CONV_TYPE DATE
3093 static void test_VarDateFromI1(void)
3095 CONVVARS(signed char);
3098 CHECKPTR(VarDateFromI1);
3099 CONVERTRANGE(VarDateFromI1, -128, 128);
3102 static void test_VarDateFromUI1(void)
3107 CHECKPTR(VarDateFromUI1);
3108 CONVERTRANGE(VarDateFromUI1, 0, 256);
3111 static void test_VarDateFromI2(void)
3116 CHECKPTR(VarDateFromI2);
3117 CONVERTRANGE(VarDateFromI2, -32768, 32768);
3120 static void test_VarDateFromUI2(void)
3125 CHECKPTR(VarDateFromUI2);
3126 CONVERTRANGE(VarDateFromUI2, 0, 65536);
3129 static void test_VarDateFromI4(void)
3133 CHECKPTR(VarDateFromI4);
3134 CONVERT(VarDateFromI4, DATE_MIN-1);
3135 if (hres != DISP_E_TYPEMISMATCH) /* Early versions return this, incorrectly */
3137 CONVERT(VarDateFromI4, DATE_MIN); EXPECT(DATE_MIN);
3138 CONVERT(VarDateFromI4, -1); EXPECT(-1.0);
3139 CONVERT(VarDateFromI4, 0); EXPECT(0.0);
3140 CONVERT(VarDateFromI4, 1); EXPECT(1.0);
3141 CONVERT(VarDateFromI4, DATE_MAX); EXPECT(DATE_MAX);
3142 CONVERT(VarDateFromI4, DATE_MAX+1);
3143 if (hres != DISP_E_TYPEMISMATCH) /* Early versions return this, incorrectly */
3147 static void test_VarDateFromUI4(void)
3149 CONVVARS(unsigned int);
3151 CHECKPTR(VarDateFromUI4);
3152 CONVERT(VarDateFromUI4, 0); EXPECT(0.0);
3153 CONVERT(VarDateFromUI4, 1); EXPECT(1.0);
3154 CONVERT(VarDateFromUI4, DATE_MAX); EXPECT(DATE_MAX);
3155 CONVERT(VarDateFromUI4, DATE_MAX+1);
3156 if (hres != DISP_E_TYPEMISMATCH) /* Early versions return this, incorrectly */
3160 static void test_VarDateFromR4(void)
3164 CHECKPTR(VarDateFromR4);
3165 CONVERT(VarDateFromR4, -1.0f); EXPECT(-1.0);
3166 CONVERT(VarDateFromR4, 0.0f); EXPECT(0.0);
3167 CONVERT(VarDateFromR4, 1.0f); EXPECT(1.0);
3168 CONVERT(VarDateFromR4, 1.5f); EXPECT(1.5);
3171 static void test_VarDateFromR8(void)
3175 CHECKPTR(VarDateFromR8);
3176 CONVERT(VarDateFromR8, -1.0f); EXPECT(-1.0);
3177 CONVERT(VarDateFromR8, 0.0f); EXPECT(0.0);
3178 CONVERT(VarDateFromR8, 1.0f); EXPECT(1.0);
3179 CONVERT(VarDateFromR8, 1.5f); EXPECT(1.5);
3182 static void test_VarDateFromBool(void)
3184 CONVVARS(VARIANT_BOOL);
3186 CHECKPTR(VarDateFromBool);
3187 CONVERT(VarDateFromBool, VARIANT_TRUE); EXPECT(VARIANT_TRUE * 1.0);
3188 CONVERT(VarDateFromBool, VARIANT_FALSE); EXPECT(VARIANT_FALSE * 1.0);
3191 static void test_VarDateFromCy(void)
3195 CHECKPTR(VarDateFromCy);
3196 CONVERT_CY(VarDateFromCy,-32769); EXPECT(-32769.0);
3197 CONVERT_CY(VarDateFromCy,-32768); EXPECT(-32768.0);
3198 CONVERT_CY(VarDateFromCy,-1); EXPECT(-1.0);
3199 CONVERT_CY(VarDateFromCy,0); EXPECT(0.0);
3200 CONVERT_CY(VarDateFromCy,1); EXPECT(1.0);
3201 CONVERT_CY(VarDateFromCy,32767); EXPECT(32767.0);
3202 CONVERT_CY(VarDateFromCy,32768); EXPECT(32768.0);
3204 CONVERT_CY(VarDateFromCy,-1.5); EXPECT(-1.5);
3205 CONVERT_CY(VarDateFromCy,-0.6); EXPECT(-0.6);
3206 CONVERT_CY(VarDateFromCy,-0.5); EXPECT(-0.5);
3207 CONVERT_CY(VarDateFromCy,-0.4); EXPECT(-0.4);
3208 CONVERT_CY(VarDateFromCy,0.4); EXPECT(0.4);
3209 CONVERT_CY(VarDateFromCy,0.5); EXPECT(0.5);
3210 CONVERT_CY(VarDateFromCy,0.6); EXPECT(0.6);
3211 CONVERT_CY(VarDateFromCy,1.5); EXPECT(1.5);
3214 static void test_VarDateFromI8(void)
3218 CHECKPTR(VarDateFromI8);
3219 CONVERT(VarDateFromI8, DATE_MIN-1); EXPECT_OVERFLOW;
3220 CONVERT(VarDateFromI8, DATE_MIN); EXPECT(DATE_MIN);
3221 CONVERT(VarDateFromI8, -1); EXPECT(-1.0);
3222 CONVERT(VarDateFromI8, 0); EXPECT(0.0);
3223 CONVERT(VarDateFromI8, 1); EXPECT(1.0);
3224 CONVERT(VarDateFromI8, DATE_MAX); EXPECT(DATE_MAX);
3225 CONVERT(VarDateFromI8, DATE_MAX+1); EXPECT_OVERFLOW;
3228 static void test_VarDateFromUI8(void)
3232 CHECKPTR(VarDateFromUI8);
3233 CONVERT(VarDateFromUI8, 0); EXPECT(0.0);
3234 CONVERT(VarDateFromUI8, 1); EXPECT(1.0);
3235 CONVERT(VarDateFromUI8, DATE_MAX); EXPECT(DATE_MAX);
3236 CONVERT(VarDateFromUI8, DATE_MAX+1); EXPECT_OVERFLOW;
3239 static void test_VarDateFromDec(void)
3243 CHECKPTR(VarDateFromDec);
3245 CONVERT_BADDEC(VarDateFromDec);
3247 CONVERT_DEC(VarDateFromDec,0,0x80,0,32768); EXPECT(-32768.0);
3248 CONVERT_DEC(VarDateFromDec,0,0x80,0,1); EXPECT(-1.0);
3249 CONVERT_DEC(VarDateFromDec,0,0,0,0); EXPECT(0.0);
3250 CONVERT_DEC(VarDateFromDec,0,0,0,1); EXPECT(1.0);
3251 CONVERT_DEC(VarDateFromDec,0,0,0,32767); EXPECT(32767.0);
3253 CONVERT_DEC(VarDateFromDec,2,0x80,0,3276800); EXPECT(-32768.0);
3254 CONVERT_DEC(VarDateFromDec,2,0,0,3276700); EXPECT(32767.0);
3258 buff[0] = '\0'; out = 0.0; \
3259 if (str) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)/sizeof(WCHAR)); \
3260 hres = pVarDateFromStr(str ? buff : NULL,lcid,LOCALE_NOUSEROVERRIDE,&out)
3262 #define MKRELDATE(day,mth) st.wMonth = mth; st.wDay = day; \
3263 pSystemTimeToVariantTime(&st,&relative)
3265 static const char * const BadDateStrings[] =
3267 "True", "False", /* Plain text */
3268 "0.", ".0", "-1.1", "1.1-", /* Partial specifications */
3269 "1;2;3", "1*2*3", "1@2@3", "1#2#3", "(1:2)","<1:2>","1|2|3", /* Bad chars */
3270 "0", "1", /* 1 element */
3271 "0.60", "24.00", "0:60", "24:00", "1 2 am", "1 am 2", /* 2 elements */
3272 "1.5 2", "1 5.2", "2 32 3", "1 2 am 3", /* 3 elements */
3273 "1 2.3 4", "1.2.3 4", "1 2.3.4", "1.2 3.4", "1.2.3.4", "1 2 3 4",
3274 "1 am 2 3.4", "1 2 am 3.4", "1.2 3 am 4", "1.2 3 4 am", /* 4 elements */
3275 "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",
3276 "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",
3277 "1.2.3 4 am 5", "1.2.3 4 5 am", "1.2 3 am 4 5",
3278 "1.2 3 4 am 5", "1.2 3 4 5 am", "1 am 2 3.4.5", "1 2 am 3.4.5",
3279 "1 am 2 3 4.5", "1 2 am 3 4.5", "1 2 3 am 4.5", /* 5 elements */
3281 "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",
3282 "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",
3283 "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",
3284 "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",
3286 /* following throws an exception on winME */
3287 "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",
3289 "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",
3291 /* following throws an exception on winME */
3292 "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",
3294 "1 2 am 3 4.5.6", "1 2 3 am 4.5.6"
3297 static void test_VarDateFromStr(void)
3306 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
3308 CHECKPTR(VarDateFromStr);
3309 CHECKPTR(SystemTimeToVariantTime);
3311 /* Some date formats are relative, so we need to find the cuurent year */
3313 st.wHour = st.wMinute = st.wSecond = st.wMilliseconds = 0;
3314 DFS(NULL); EXPECT_MISMATCH;
3316 /* Floating point number are not recognised */
3319 EXPECT_DBL(0.0); /* Very old versions accept this string */
3323 /* 1 element - can only be a time, and only if it has am/pm */
3324 DFS("1 am"); EXPECT_DBL(0.04166666666666666);
3326 /* A decimal point is treated as a time separator.
3327 * The following are converted as hours/minutes.
3329 DFS("0.1"); EXPECT_DBL(0.0006944444444444445);
3330 DFS("0.40"); EXPECT_DBL(0.02777777777777778);
3331 DFS("2.5"); EXPECT_DBL(0.08680555555555555);
3332 /* A colon acts as a decimal point */
3333 DFS("0:1"); EXPECT_DBL(0.0006944444444444445);
3334 DFS("0:20"); EXPECT_DBL(0.01388888888888889);
3335 DFS("0:40"); EXPECT_DBL(0.02777777777777778);
3336 DFS("3:5"); EXPECT_DBL(0.1284722222222222);
3337 /* Check the am/pm limits */
3338 DFS("00:00 AM"); EXPECT_DBL(0.0);
3339 DFS("00:00 a"); EXPECT_DBL(0.0);
3340 DFS("12:59 AM"); EXPECT_DBL(0.04097222222222222);
3341 DFS("12:59 A"); EXPECT_DBL(0.04097222222222222);
3342 DFS("00:00 pm"); EXPECT_DBL(0.5);
3343 DFS("00:00 p"); EXPECT_DBL(0.5);
3344 DFS("12:59 pm"); EXPECT_DBL(0.5409722222222222);
3345 DFS("12:59 p"); EXPECT_DBL(0.5409722222222222);
3346 /* AM/PM is ignored if hours > 12 */
3347 DFS("13:00 AM"); EXPECT_DBL(0.5416666666666666);
3348 DFS("13:00 PM"); EXPECT_DBL(0.5416666666666666);
3350 /* Space, dash and slash all indicate a date format. */
3351 /* If both numbers are valid month values => month/day of current year */
3352 DFS("1 2"); MKRELDATE(2,1); EXPECT_DBL(relative);
3353 DFS("2 1"); MKRELDATE(1,2); EXPECT_DBL(relative);
3354 /* one number not valid month, is a valid day, other number valid month:
3355 * that number becomes the day.
3357 DFS("14 1"); MKRELDATE(14,1); EXPECT_DBL(relative);
3358 DFS("1 14"); EXPECT_DBL(relative);
3359 /* If the numbers can't be day/month, they are assumed to be year/month */
3360 DFS("30 2"); EXPECT_DBL(10990.0);
3361 DFS("2 30"); EXPECT_DBL(10990.0);
3362 DFS("32 49"); EXPECT_MISMATCH; /* Can't be any format */
3363 DFS("0 49"); EXPECT_MISMATCH; /* Can't be any format */
3364 /* If a month name is given the other number is the day */
3365 DFS("Jan 2"); MKRELDATE(2,1); EXPECT_DBL(relative);
3366 DFS("2 Jan"); EXPECT_DBL(relative);
3367 /* Unless it can't be, in which case it becomes the year */
3368 DFS("Jan 35"); EXPECT_DBL(12785.0);
3369 DFS("35 Jan"); EXPECT_DBL(12785.0);
3370 DFS("Jan-35"); EXPECT_DBL(12785.0);
3371 DFS("35-Jan"); EXPECT_DBL(12785.0);
3372 DFS("Jan/35"); EXPECT_DBL(12785.0);
3373 DFS("35/Jan"); EXPECT_DBL(12785.0);
3375 /* 3 numbers and time separator => h:m:s */
3376 DFS("0.1.0"); EXPECT_DBL(0.0006944444444444445);
3377 DFS("1.5.2"); EXPECT_DBL(0.04516203703703704);
3378 /* 3 numbers => picks date giving preference to lcid format */
3379 DFS("1 2 3"); EXPECT_DBL(37623.0);
3380 DFS("14 2 3"); EXPECT_DBL(41673.0);
3381 DFS("2 14 3"); EXPECT_DBL(37666.0);
3382 DFS("2 3 14"); EXPECT_DBL(41673.0);
3383 DFS("32 2 3"); EXPECT_DBL(11722.0);
3384 DFS("2 3 32"); EXPECT_DBL(11722.0);
3385 DFS("1 2 29"); EXPECT_DBL(47120.0);
3386 /* After 30, two digit dates are expected to be in the 1900's */
3387 DFS("1 2 30"); EXPECT_DBL(10960.0);
3388 DFS("1 2 31"); EXPECT_DBL(11325.0);
3389 DFS("3 am 1 2"); MKRELDATE(2,1); relative += 0.125; EXPECT_DBL(relative);
3390 DFS("1 2 3 am"); EXPECT_DBL(relative);
3392 /* 4 elements -interpreted as 2 digit date & time */
3393 DFS("1.2 3 4"); MKRELDATE(4,3); relative += 0.04305555556; EXPECT_DBL(relative);
3394 DFS("3 4 1.2"); EXPECT_DBL(relative);
3395 /* 5 elements - interpreted as 2 & 3 digit date/times */
3396 DFS("1.2.3 4 5"); MKRELDATE(5,4); relative += 0.04309027778; EXPECT_DBL(relative);
3397 DFS("1.2 3 4 5"); EXPECT_DBL(38415.04305555556);
3399 /* following throws an exception on winME */
3400 DFS("1 2 3.4.5"); MKRELDATE(2,1); relative += 0.12783564815; EXPECT_DBL(relative);
3402 DFS("1 2 3 4.5"); EXPECT_DBL(37623.17013888889);
3403 /* 6 elements - interpreted as 3 digit date/times */
3404 DFS("1.2.3 4 5 6"); EXPECT_DBL(38812.04309027778);
3405 DFS("1 2 3 4.5.6"); EXPECT_DBL(37623.17020833334);
3407 for (i = 0; i < sizeof(BadDateStrings)/sizeof(char*); i++)
3409 DFS(BadDateStrings[i]); EXPECT_MISMATCH;
3412 /* Some normal-ish strings */
3413 DFS("2 January, 1970"); EXPECT_DBL(25570.0);
3414 DFS("2 January 1970"); EXPECT_DBL(25570.0);
3415 DFS("2 Jan 1970"); EXPECT_DBL(25570.0);
3416 DFS("2/Jan/1970"); EXPECT_DBL(25570.0);
3417 DFS("2-Jan-1970"); EXPECT_DBL(25570.0);
3418 DFS("1 2 1970"); EXPECT_DBL(25570.0);
3419 DFS("1/2/1970"); EXPECT_DBL(25570.0);
3420 DFS("1-2-1970"); EXPECT_DBL(25570.0);
3421 /* Native fails "1999 January 3, 9AM". I consider that a bug in native */
3424 static void test_VarDateCopy(void)
3426 COPYTEST(77665544.0, VT_DATE, V_DATE(&vSrc), V_DATE(&vDst), V_DATEREF(&vSrc),
3427 V_DATEREF(&vDst), "%16.16g");
3430 static const char* wtoascii(LPWSTR lpszIn)
3432 static char buff[256];
3433 WideCharToMultiByte(CP_ACP, 0, lpszIn, -1, buff, sizeof(buff), NULL, NULL);
3437 static void test_VarDateChangeTypeEx(void)
3439 static const WCHAR sz25570[] = {
3440 '1','/','2','/','1','9','7','0','\0' };
3441 static const WCHAR sz25570_2[] = {
3442 '1','/','2','/','7','0','\0' };
3443 static const WCHAR sz25570Nls[] = {
3444 '1','/','2','/','1','9','7','0',' ','1','2',':','0','0',':','0','0',' ','A','M','\0' };
3445 CONVVARS(CONV_TYPE);
3446 VARIANTARG vSrc, vDst;
3451 #ifdef HAS_UINT64_TO_FLOAT
3452 INITIAL_TYPETEST(VT_DATE, V_DATE, "%g");
3456 V_VT(&vDst) = VT_EMPTY;
3457 V_VT(&vSrc) = VT_DATE;
3458 V_DATE(&vSrc) = 25570.0;
3459 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
3461 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, VARIANT_NOUSEROVERRIDE, VT_BSTR);
3462 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && V_BSTR(&vDst) &&
3463 (!lstrcmpW(V_BSTR(&vDst), sz25570) || !lstrcmpW(V_BSTR(&vDst), sz25570_2)),
3464 "hres=0x%X, type=%d (should be VT_BSTR), *bstr=%s\n",
3465 hres, V_VT(&vDst), V_BSTR(&vDst) ? wtoascii(V_BSTR(&vDst)) : "?");
3467 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
3468 if (HAVE_OLEAUT32_LOCALES)
3470 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, VARIANT_NOUSEROVERRIDE|VARIANT_USE_NLS, VT_BSTR);
3471 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && V_BSTR(&vDst) && !lstrcmpW(V_BSTR(&vDst), sz25570Nls),
3472 "hres=0x%X, type=%d (should be VT_BSTR), *bstr=%s\n",
3473 hres, V_VT(&vDst), V_BSTR(&vDst) ? wtoascii(V_BSTR(&vDst)) : "?");
3482 #define CONV_TYPE CY
3484 #define EXPECTRES(res, x) \
3485 ok(hres == S_OK || ((HRESULT)res != S_OK && hres == (HRESULT)res), \
3486 "expected hres " #x ", got hres=0x%08x\n", hres)
3488 #define EXPECTCY(x) \
3489 ok((hres == S_OK && out.int64 == (LONGLONG)(x*CY_MULTIPLIER)), \
3490 "expected " #x "*CY_MULTIPLIER, got (%8x %8x); hres=0x%08x\n", S(out).Hi, S(out).Lo, hres)
3492 #define EXPECTCY64(x,y) \
3493 ok(hres == S_OK && S(out).Hi == (LONG)x && S(out).Lo == y, \
3494 "expected " #x #y "(%u,%u), got (%u,%u); hres=0x%08x\n", \
3495 (ULONG)(x), (ULONG)(y), S(out).Hi, S(out).Lo, hres)
3497 static void test_VarCyFromI1(void)
3499 CONVVARS(signed char);
3502 CHECKPTR(VarCyFromI1);
3503 for (i = -128; i < 128; i++)
3505 CONVERT(VarCyFromI1,i); EXPECTCY(i);
3509 static void test_VarCyFromUI1(void)
3514 CHECKPTR(VarCyFromUI1);
3515 for (i = 0; i < 256; i++)
3517 CONVERT(VarCyFromUI1,i); EXPECTCY(i);
3521 static void test_VarCyFromI2(void)
3526 CHECKPTR(VarCyFromI2);
3527 for (i = -16384; i < 16384; i++)
3529 CONVERT(VarCyFromI2,i); EXPECTCY(i);
3533 static void test_VarCyFromUI2(void)
3538 CHECKPTR(VarCyFromUI2);
3539 for (i = 0; i < 32768; i++)
3541 CONVERT(VarCyFromUI2,i); EXPECTCY(i);
3545 static void test_VarCyFromI4(void)
3549 CHECKPTR(VarCyFromI4);
3550 CONVERT(VarCyFromI4, -1); EXPECTCY(-1);
3551 CONVERT(VarCyFromI4, 0); EXPECTCY(0);
3552 CONVERT(VarCyFromI4, 1); EXPECTCY(1);
3553 CONVERT(VarCyFromI4, 0x7fffffff); EXPECTCY64(0x1387, 0xffffd8f0);
3554 CONVERT(VarCyFromI4, 0x80000000); EXPECTCY64(0xffffec78, 0);
3557 static void test_VarCyFromUI4(void)
3559 CONVVARS(unsigned int);
3561 CHECKPTR(VarCyFromUI4);
3562 CONVERT(VarCyFromUI4, 0); EXPECTCY(0);
3563 CONVERT(VarCyFromUI4, 1); EXPECTCY(1);
3564 CONVERT(VarCyFromUI4, 0x80000000); EXPECTCY64(5000, 0);
3567 static void test_VarCyFromR4(void)
3571 CHECKPTR(VarCyFromR4);
3572 CONVERT(VarCyFromR4, -1.0f); EXPECTCY(-1);
3573 CONVERT(VarCyFromR4, 0.0f); EXPECTCY(0);
3574 CONVERT(VarCyFromR4, 1.0f); EXPECTCY(1);
3575 CONVERT(VarCyFromR4, 1.5f); EXPECTCY(1.5);
3577 CONVERT(VarCyFromR4, -1.5f); EXPECTCY(-1.5);
3578 CONVERT(VarCyFromR4, -0.6f); EXPECTCY(-0.6);
3579 CONVERT(VarCyFromR4, -0.5f); EXPECTCY(-0.5);
3580 CONVERT(VarCyFromR4, -0.4f); EXPECTCY(-0.4);
3581 CONVERT(VarCyFromR4, 0.4f); EXPECTCY(0.4);
3582 CONVERT(VarCyFromR4, 0.5f); EXPECTCY(0.5);
3583 CONVERT(VarCyFromR4, 0.6f); EXPECTCY(0.6);
3584 CONVERT(VarCyFromR4, 1.5f); EXPECTCY(1.5);
3585 CONVERT(VarCyFromR4, 1.00009f); EXPECTCY(1.0001);
3586 CONVERT(VarCyFromR4, -1.00001f); EXPECTCY(-1);
3587 CONVERT(VarCyFromR4, -1.00005f); EXPECTCY(-1);
3588 CONVERT(VarCyFromR4, -0.00009f); EXPECTCY(-0.0001);
3589 CONVERT(VarCyFromR4, -0.00005f); EXPECTCY(0);
3590 CONVERT(VarCyFromR4, -0.00001f); EXPECTCY(0);
3591 CONVERT(VarCyFromR4, 0.00001f); EXPECTCY(0);
3592 CONVERT(VarCyFromR4, 0.00005f); EXPECTCY(0);
3593 CONVERT(VarCyFromR4, 0.00009f); EXPECTCY(0.0001);
3594 CONVERT(VarCyFromR4, -1.00001f); EXPECTCY(-1);
3595 CONVERT(VarCyFromR4, -1.00005f); EXPECTCY(-1);
3596 CONVERT(VarCyFromR4, -1.00009f); EXPECTCY(-1.0001);
3599 static void test_VarCyFromR8(void)
3603 CHECKPTR(VarCyFromR8);
3605 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3606 /* Test our rounding is exactly the same. This fails if the special x86
3607 * code is taken out of VarCyFromR8.
3609 CONVERT(VarCyFromR8, -461168601842738.7904); EXPECTCY64(0xbfffffff, 0xffffff23);
3612 CONVERT(VarCyFromR8, -4611686018427388416.1); EXPECT_OVERFLOW;
3613 CONVERT(VarCyFromR8, -1.0); EXPECTCY(-1);
3614 CONVERT(VarCyFromR8, -0.0); EXPECTCY(0);
3615 CONVERT(VarCyFromR8, 1.0); EXPECTCY(1);
3616 CONVERT(VarCyFromR8, 4611686018427387648.0); EXPECT_OVERFLOW;
3619 CONVERT(VarCyFromR8, -1.5f); EXPECTCY(-1.5);
3620 CONVERT(VarCyFromR8, -0.6f); EXPECTCY(-0.6);
3621 CONVERT(VarCyFromR8, -0.5f); EXPECTCY(-0.5);
3622 CONVERT(VarCyFromR8, -0.4f); EXPECTCY(-0.4);
3623 CONVERT(VarCyFromR8, 0.4f); EXPECTCY(0.4);
3624 CONVERT(VarCyFromR8, 0.5f); EXPECTCY(0.5);
3625 CONVERT(VarCyFromR8, 0.6f); EXPECTCY(0.6);
3626 CONVERT(VarCyFromR8, 1.5f); EXPECTCY(1.5);
3627 CONVERT(VarCyFromR8, 1.00009f); EXPECTCY(1.0001);
3628 CONVERT(VarCyFromR8, -1.00001f); EXPECTCY(-1);
3629 CONVERT(VarCyFromR8, -1.00005f); EXPECTCY(-1);
3630 CONVERT(VarCyFromR8, -0.00009f); EXPECTCY(-0.0001);
3631 CONVERT(VarCyFromR8, -0.00005f); EXPECTCY(0);
3632 CONVERT(VarCyFromR8, -0.00001f); EXPECTCY(0);
3633 CONVERT(VarCyFromR8, 0.00001f); EXPECTCY(0);
3634 CONVERT(VarCyFromR8, 0.00005f); EXPECTCY(0);
3635 CONVERT(VarCyFromR8, 0.00009f); EXPECTCY(0.0001);
3636 CONVERT(VarCyFromR8, -1.00001f); EXPECTCY(-1);
3637 CONVERT(VarCyFromR8, -1.00005f); EXPECTCY(-1);
3638 CONVERT(VarCyFromR8, -1.00009f); EXPECTCY(-1.0001);
3641 static void test_VarCyFromBool(void)
3643 CONVVARS(VARIANT_BOOL);
3646 CHECKPTR(VarCyFromBool);
3647 for (i = -32768; i < 32768; i++)
3649 CONVERT(VarCyFromBool, i); EXPECTCY(i);
3653 static void test_VarCyFromI8(void)
3657 CHECKPTR(VarCyFromI8);
3658 CONVERT_I8(VarCyFromI8, -214749, 2728163227ul); EXPECT_OVERFLOW;
3659 CONVERT_I8(VarCyFromI8, -214749, 2728163228ul); EXPECTCY64(2147483648ul,15808);
3660 CONVERT(VarCyFromI8, -1); EXPECTCY(-1);
3661 CONVERT(VarCyFromI8, 0); EXPECTCY(0);
3662 CONVERT(VarCyFromI8, 1); EXPECTCY(1);
3663 CONVERT_I8(VarCyFromI8, 214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3664 CONVERT_I8(VarCyFromI8, 214748, 1566804069); EXPECT_OVERFLOW;
3667 static void test_VarCyFromUI8(void)
3671 CHECKPTR(VarCyFromUI8);
3672 CONVERT(VarCyFromUI8, 0); EXPECTCY(0);
3673 CONVERT(VarCyFromUI8, 1); EXPECTCY(1);
3674 CONVERT_I8(VarCyFromUI8, 214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3675 CONVERT_I8(VarCyFromUI8, 214748, 1566804069); EXPECT_OVERFLOW;
3678 static void test_VarCyFromDec(void)
3682 CHECKPTR(VarCyFromDec);
3684 CONVERT_BADDEC(VarCyFromDec);
3686 CONVERT_DEC(VarCyFromDec,0,0x80,0,1); EXPECTCY(-1);
3687 CONVERT_DEC(VarCyFromDec,0,0,0,0); EXPECTCY(0);
3688 CONVERT_DEC(VarCyFromDec,0,0,0,1); EXPECTCY(1);
3690 CONVERT_DEC64(VarCyFromDec,0,0,0,214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3691 CONVERT_DEC64(VarCyFromDec,0,0,0,214748, 1566804069); EXPECT_OVERFLOW;
3693 CONVERT_DEC(VarCyFromDec,2,0,0,100); EXPECTCY(1);
3694 CONVERT_DEC(VarCyFromDec,2,0x80,0,100); EXPECTCY(-1);
3695 CONVERT_DEC(VarCyFromDec,2,0x80,0,1); EXPECTCY(-0.01);
3696 CONVERT_DEC(VarCyFromDec,2,0,0,1); EXPECTCY(0.01);
3697 CONVERT_DEC(VarCyFromDec,2,0x80,0,1); EXPECTCY(-0.01);
3698 CONVERT_DEC(VarCyFromDec,2,0,0,999); EXPECTCY(9.99);
3699 CONVERT_DEC(VarCyFromDec,2,0x80,0,999); EXPECTCY(-9.99);
3700 CONVERT_DEC(VarCyFromDec,2,0,0,1500); EXPECTCY(15);
3701 CONVERT_DEC(VarCyFromDec,2,0x80,0,1500); EXPECTCY(-15);
3704 static void test_VarCyFromDate(void)
3708 CHECKPTR(VarCyFromDate);
3710 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3711 CONVERT(VarCyFromR8, -461168601842738.7904); EXPECTCY64(0xbfffffff, 0xffffff23);
3714 CONVERT(VarCyFromDate, -1.0); EXPECTCY(-1);
3715 CONVERT(VarCyFromDate, -0.0); EXPECTCY(0);
3716 CONVERT(VarCyFromDate, 1.0); EXPECTCY(1);
3717 CONVERT(VarCyFromDate, -4611686018427388416.1); EXPECT_OVERFLOW;
3718 CONVERT(VarCyFromDate, 4611686018427387648.0); EXPECT_OVERFLOW;
3721 CONVERT(VarCyFromDate, -1.5f); EXPECTCY(-1.5);
3722 CONVERT(VarCyFromDate, -0.6f); EXPECTCY(-0.6);
3723 CONVERT(VarCyFromDate, -0.5f); EXPECTCY(-0.5);
3724 CONVERT(VarCyFromDate, -0.4f); EXPECTCY(-0.4);
3725 CONVERT(VarCyFromDate, 0.4f); EXPECTCY(0.4);
3726 CONVERT(VarCyFromDate, 0.5f); EXPECTCY(0.5);
3727 CONVERT(VarCyFromDate, 0.6f); EXPECTCY(0.6);
3728 CONVERT(VarCyFromDate, 1.5f); EXPECTCY(1.5);
3729 CONVERT(VarCyFromDate, 1.00009f); EXPECTCY(1.0001);
3730 CONVERT(VarCyFromDate, -1.00001f); EXPECTCY(-1);
3731 CONVERT(VarCyFromDate, -1.00005f); EXPECTCY(-1);
3732 CONVERT(VarCyFromDate, -0.00009f); EXPECTCY(-0.0001);
3733 CONVERT(VarCyFromDate, -0.00005f); EXPECTCY(0);
3734 CONVERT(VarCyFromDate, -0.00001f); EXPECTCY(0);
3735 CONVERT(VarCyFromDate, 0.00001f); EXPECTCY(0);
3736 CONVERT(VarCyFromDate, 0.00005f); EXPECTCY(0);
3737 CONVERT(VarCyFromDate, 0.00009f); EXPECTCY(0.0001);
3738 CONVERT(VarCyFromDate, -1.00001f); EXPECTCY(-1);
3739 CONVERT(VarCyFromDate, -1.00005f); EXPECTCY(-1);
3740 CONVERT(VarCyFromDate, -1.00009f); EXPECTCY(-1.0001);
3743 #define MATHVARS1 HRESULT hres; double left = 0.0; CY cyLeft, out
3744 #define MATHVARS2 MATHVARS1; double right = 0.0; CY cyRight
3745 #define MATH1(func, l) left = (double)l; pVarCyFromR8(left, &cyLeft); hres = p##func(cyLeft, &out)
3746 #define MATH2(func, l, r) left = (double)l; right = (double)r; \
3747 pVarCyFromR8(left, &cyLeft); pVarCyFromR8(right, &cyRight); \
3748 hres = p##func(cyLeft, cyRight, &out)
3750 static void test_VarCyAdd(void)
3755 MATH2(VarCyAdd, 0.5, 0.5); EXPECTCY(1);
3756 MATH2(VarCyAdd, 0.5, -0.4); EXPECTCY(0.1);
3757 MATH2(VarCyAdd, 0.5, -0.6); EXPECTCY(-0.1);
3758 MATH2(VarCyAdd, -0.5, -0.5); EXPECTCY(-1);
3759 MATH2(VarCyAdd, -922337203685476.0, -922337203685476.0); EXPECT_OVERFLOW;
3760 MATH2(VarCyAdd, -922337203685476.0, 922337203685476.0); EXPECTCY(0);
3761 MATH2(VarCyAdd, 922337203685476.0, -922337203685476.0); EXPECTCY(0);
3762 MATH2(VarCyAdd, 922337203685476.0, 922337203685476.0); EXPECT_OVERFLOW;
3765 static void test_VarCyMul(void)
3770 MATH2(VarCyMul, 534443.0, 0.0); EXPECTCY(0);
3771 MATH2(VarCyMul, 0.5, 0.5); EXPECTCY(0.25);
3772 MATH2(VarCyMul, 0.5, -0.4); EXPECTCY(-0.2);
3773 MATH2(VarCyMul, 0.5, -0.6); EXPECTCY(-0.3);
3774 MATH2(VarCyMul, -0.5, -0.5); EXPECTCY(0.25);
3775 MATH2(VarCyMul, 922337203685476.0, 20000); EXPECT_OVERFLOW;
3778 static void test_VarCySub(void)
3783 MATH2(VarCySub, 0.5, 0.5); EXPECTCY(0);
3784 MATH2(VarCySub, 0.5, -0.4); EXPECTCY(0.9);
3785 MATH2(VarCySub, 0.5, -0.6); EXPECTCY(1.1);
3786 MATH2(VarCySub, -0.5, -0.5); EXPECTCY(0);
3787 MATH2(VarCySub, -922337203685476.0, -922337203685476.0); EXPECTCY(0);
3788 MATH2(VarCySub, -922337203685476.0, 922337203685476.0); EXPECT_OVERFLOW;
3789 MATH2(VarCySub, 922337203685476.0, -922337203685476.0); EXPECT_OVERFLOW;
3790 MATH2(VarCySub, 922337203685476.0, 922337203685476.0); EXPECTCY(0);
3793 static void test_VarCyAbs(void)
3798 MATH1(VarCyAbs, 0.5); EXPECTCY(0.5);
3799 MATH1(VarCyAbs, -0.5); EXPECTCY(0.5);
3800 MATH1(VarCyAbs, 922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3801 MATH1(VarCyAbs, -922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3804 static void test_VarCyNeg(void)
3809 MATH1(VarCyNeg, 0.5); EXPECTCY(-0.5);
3810 MATH1(VarCyNeg, -0.5); EXPECTCY(0.5);
3811 MATH1(VarCyNeg, 922337203685476.0); EXPECTCY64(2147483648ul,15808);
3812 MATH1(VarCyNeg, -922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3815 #define MATHMULI4(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3816 hres = pVarCyMulI4(cyLeft, right, &out)
3818 static void test_VarCyMulI4(void)
3823 CHECKPTR(VarCyMulI4);
3824 MATHMULI4(534443.0, 0); EXPECTCY(0);
3825 MATHMULI4(0.5, 1); EXPECTCY(0.5);
3826 MATHMULI4(0.5, 2); EXPECTCY(1);
3827 MATHMULI4(922337203685476.0, 1); EXPECTCY64(2147483647ul,4294951488ul);
3828 MATHMULI4(922337203685476.0, 2); EXPECT_OVERFLOW;
3831 #define MATHMULI8(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3832 hres = pVarCyMulI8(cyLeft, right, &out)
3834 static void test_VarCyMulI8(void)
3839 CHECKPTR(VarCyMulI8);
3840 MATHMULI8(534443.0, 0); EXPECTCY(0);
3841 MATHMULI8(0.5, 1); EXPECTCY(0.5);
3842 MATHMULI8(0.5, 2); EXPECTCY(1);
3843 MATHMULI8(922337203685476.0, 1); EXPECTCY64(2147483647ul,4294951488ul);
3844 MATHMULI8(922337203685476.0, 2); EXPECT_OVERFLOW;
3847 #define MATHCMP(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); pVarCyFromR8(right, &cyRight); \
3848 hres = pVarCyCmp(cyLeft, cyRight); out.int64 = hres
3850 static void test_VarCyCmp(void)
3855 MATHCMP(-1.0, -1.0); EXPECT_EQ;
3856 MATHCMP(-1.0, 0.0); EXPECT_LT;
3857 MATHCMP(-1.0, 1.0); EXPECT_LT;
3858 MATHCMP(-1.0, 2.0); EXPECT_LT;
3859 MATHCMP(0.0, 1.0); EXPECT_LT;
3860 MATHCMP(0.0, 0.0); EXPECT_EQ;
3861 MATHCMP(0.0, -1.0); EXPECT_GT;
3862 MATHCMP(1.0, -1.0); EXPECT_GT;
3863 MATHCMP(1.0, 0.0); EXPECT_GT;
3864 MATHCMP(1.0, 1.0); EXPECT_EQ;
3865 MATHCMP(1.0, 2.0); EXPECT_LT;
3868 #define MATHCMPR8(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3869 hres = pVarCyCmpR8(cyLeft, right); out.int64 = hres
3871 static void test_VarCyCmpR8(void)
3876 CHECKPTR(VarCyCmpR8);
3877 MATHCMPR8(-1.0, -1.0); EXPECT_EQ;
3878 MATHCMPR8(-1.0, 0.0); EXPECT_LT;
3879 MATHCMPR8(-1.0, 1.0); EXPECT_LT;
3880 MATHCMPR8(-1.0, 2.0); EXPECT_LT;
3881 MATHCMPR8(0.0, 1.0); EXPECT_LT;
3882 MATHCMPR8(0.0, 0.0); EXPECT_EQ;
3883 MATHCMPR8(0.0, -1.0); EXPECT_GT;
3884 MATHCMPR8(1.0, -1.0); EXPECT_GT;
3885 MATHCMPR8(1.0, 0.0); EXPECT_GT;
3886 MATHCMPR8(1.0, 1.0); EXPECT_EQ;
3887 MATHCMPR8(1.0, 2.0); EXPECT_LT;
3891 #define MATHRND(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3892 hres = pVarCyRound(cyLeft, right, &out)
3894 static void test_VarCyRound(void)
3899 CHECKPTR(VarCyRound);
3900 MATHRND(0.5432, 5); EXPECTCY(0.5432);
3901 MATHRND(0.5432, 4); EXPECTCY(0.5432);
3902 MATHRND(0.5432, 3); EXPECTCY(0.543);
3903 MATHRND(0.5432, 2); EXPECTCY(0.54);
3904 MATHRND(0.5432, 1); EXPECTCY(0.5);
3905 MATHRND(0.5532, 0); EXPECTCY(1);
3906 MATHRND(0.5532, -1); EXPECT_INVALID;
3908 MATHRND(0.5568, 5); EXPECTCY(0.5568);
3909 MATHRND(0.5568, 4); EXPECTCY(0.5568);
3910 MATHRND(0.5568, 3); EXPECTCY(0.557);
3911 MATHRND(0.5568, 2); EXPECTCY(0.56);
3912 MATHRND(0.5568, 1); EXPECTCY(0.6);
3913 MATHRND(0.5568, 0); EXPECTCY(1);
3914 MATHRND(0.5568, -1); EXPECT_INVALID;
3916 MATHRND(0.4999, 0); EXPECTCY(0);
3917 MATHRND(0.5000, 0); EXPECTCY(0);
3918 MATHRND(0.5001, 0); EXPECTCY(1);
3919 MATHRND(1.4999, 0); EXPECTCY(1);
3920 MATHRND(1.5000, 0); EXPECTCY(2);
3921 MATHRND(1.5001, 0); EXPECTCY(2);
3924 #define MATHFIX(l) left = l; pVarCyFromR8(left, &cyLeft); \
3925 hres = pVarCyFix(cyLeft, &out)
3927 static void test_VarCyFix(void)
3932 MATHFIX(-1.0001); EXPECTCY(-1);
3933 MATHFIX(-1.4999); EXPECTCY(-1);
3934 MATHFIX(-1.5001); EXPECTCY(-1);
3935 MATHFIX(-1.9999); EXPECTCY(-1);
3936 MATHFIX(-0.0001); EXPECTCY(0);
3937 MATHFIX(-0.4999); EXPECTCY(0);
3938 MATHFIX(-0.5001); EXPECTCY(0);
3939 MATHFIX(-0.9999); EXPECTCY(0);
3940 MATHFIX(0.0001); EXPECTCY(0);
3941 MATHFIX(0.4999); EXPECTCY(0);
3942 MATHFIX(0.5001); EXPECTCY(0);
3943 MATHFIX(0.9999); EXPECTCY(0);
3944 MATHFIX(1.0001); EXPECTCY(1);
3945 MATHFIX(1.4999); EXPECTCY(1);
3946 MATHFIX(1.5001); EXPECTCY(1);
3947 MATHFIX(1.9999); EXPECTCY(1);
3950 #define MATHINT(l) left = l; pVarCyFromR8(left, &cyLeft); \
3951 hres = pVarCyInt(cyLeft, &out)
3953 static void test_VarCyInt(void)
3958 MATHINT(-1.0001); EXPECTCY(-2);
3959 MATHINT(-1.4999); EXPECTCY(-2);
3960 MATHINT(-1.5001); EXPECTCY(-2);
3961 MATHINT(-1.9999); EXPECTCY(-2);
3962 MATHINT(-0.0001); EXPECTCY(-1);
3963 MATHINT(-0.4999); EXPECTCY(-1);
3964 MATHINT(-0.5001); EXPECTCY(-1);
3965 MATHINT(-0.9999); EXPECTCY(-1);
3966 MATHINT(0.0001); EXPECTCY(0);
3967 MATHINT(0.4999); EXPECTCY(0);
3968 MATHINT(0.5001); EXPECTCY(0);
3969 MATHINT(0.9999); EXPECTCY(0);
3970 MATHINT(1.0001); EXPECTCY(1);
3971 MATHINT(1.4999); EXPECTCY(1);
3972 MATHINT(1.5001); EXPECTCY(1);
3973 MATHINT(1.9999); EXPECTCY(1);
3981 #define CONV_TYPE DECIMAL
3983 #define EXPECTRES(res, x) \
3984 ok(hres == S_OK || ((HRESULT)res != S_OK && hres == (HRESULT)res), \
3985 "expected hres " #x ", got hres=0x%08x\n", hres)
3987 #define EXPECTDEC(scl, sgn, hi, lo) ok(hres == S_OK && \
3988 S(U(out)).scale == (BYTE)(scl) && S(U(out)).sign == (BYTE)(sgn) && \
3989 out.Hi32 == (ULONG)(hi) && U1(out).Lo64 == (ULONG64)(lo), \
3990 "expected (%d,%d,%d,(%x %x)), got (%d,%d,%d,(%x %x)) hres 0x%08x\n", \
3991 scl, sgn, hi, (LONG)((LONG64)(lo) >> 32), (LONG)((lo) & 0xffffffff), S(U(out)).scale, \
3992 S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres)
3994 #define EXPECTDEC64(scl, sgn, hi, mid, lo) ok(hres == S_OK && \
3995 S(U(out)).scale == (BYTE)(scl) && S(U(out)).sign == (BYTE)(sgn) && \
3996 out.Hi32 == (ULONG)(hi) && S1(U1(out)).Mid32 == (ULONG)(mid) && \
3997 S1(U1(out)).Lo32 == (ULONG)(lo), \
3998 "expected (%d,%d,%d,(%x %x)), got (%d,%d,%d,(%x %x)) hres 0x%08x\n", \
3999 scl, sgn, hi, (LONG)(mid), (LONG)(lo), S(U(out)).scale, \
4000 S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres)
4002 #define EXPECTDECI if (i < 0) EXPECTDEC(0, 0x80, 0, -i); else EXPECTDEC(0, 0, 0, i)
4004 static void test_VarDecFromI1(void)
4006 CONVVARS(signed char);
4009 CHECKPTR(VarDecFromI1);
4010 for (i = -128; i < 128; i++)
4012 CONVERT(VarDecFromI1,i); EXPECTDECI;
4016 static void test_VarDecFromI2(void)
4021 CHECKPTR(VarDecFromI2);
4022 for (i = -32768; i < 32768; i++)
4024 CONVERT(VarDecFromI2,i); EXPECTDECI;
4028 static void test_VarDecFromI4(void)
4033 CHECKPTR(VarDecFromI4);
4034 for (i = -32768; i < 32768; i++)
4036 CONVERT(VarDecFromI4,i); EXPECTDECI;
4040 static void test_VarDecFromI8(void)
4045 CHECKPTR(VarDecFromI8);
4046 for (i = -32768; i < 32768; i++)
4048 CONVERT(VarDecFromI8,i); EXPECTDECI;
4052 static void test_VarDecFromUI1(void)
4057 CHECKPTR(VarDecFromUI1);
4058 for (i = 0; i < 256; i++)
4060 CONVERT(VarDecFromUI1,i); EXPECTDECI;
4064 static void test_VarDecFromUI2(void)
4069 CHECKPTR(VarDecFromUI2);
4070 for (i = 0; i < 65536; i++)
4072 CONVERT(VarDecFromUI2,i); EXPECTDECI;
4076 static void test_VarDecFromUI4(void)
4081 CHECKPTR(VarDecFromUI4);
4082 for (i = 0; i < 65536; i++)
4084 CONVERT(VarDecFromUI4,i); EXPECTDECI;
4088 static void test_VarDecFromUI8(void)
4093 CHECKPTR(VarDecFromUI8);
4094 for (i = 0; i < 65536; i++)
4096 CONVERT(VarDecFromUI8,i); EXPECTDECI;
4100 static void test_VarDecFromBool(void)
4105 CHECKPTR(VarDecFromBool);
4106 /* Test all possible type values. Note that the result is reduced to 0 or -1 */
4107 for (i = -32768; i < 0; i++)
4109 CONVERT(VarDecFromBool,i);
4111 EXPECTDEC(0,0x80,0,1);
4117 static void test_VarDecFromR4(void)
4121 CHECKPTR(VarDecFromR4);
4123 CONVERT(VarDecFromR4,-0.6f); EXPECTDEC(1,0x80,0,6);
4124 CONVERT(VarDecFromR4,-0.5f); EXPECTDEC(1,0x80,0,5);
4125 CONVERT(VarDecFromR4,-0.4f); EXPECTDEC(1,0x80,0,4);
4126 CONVERT(VarDecFromR4,0.0f); EXPECTDEC(0,0,0,0);
4127 CONVERT(VarDecFromR4,0.4f); EXPECTDEC(1,0,0,4);
4128 CONVERT(VarDecFromR4,0.5f); EXPECTDEC(1,0,0,5);
4129 CONVERT(VarDecFromR4,0.6f); EXPECTDEC(1,0,0,6);
4132 static void test_VarDecFromR8(void)
4136 CHECKPTR(VarDecFromR8);
4138 CONVERT(VarDecFromR8,-0.6); EXPECTDEC(1,0x80,0,6);
4139 CONVERT(VarDecFromR8,-0.5); EXPECTDEC(1,0x80,0,5);
4140 CONVERT(VarDecFromR8,-0.4); EXPECTDEC(1,0x80,0,4);
4141 CONVERT(VarDecFromR8,0.0); EXPECTDEC(0,0,0,0);
4142 CONVERT(VarDecFromR8,0.4); EXPECTDEC(1,0,0,4);
4143 CONVERT(VarDecFromR8,0.5); EXPECTDEC(1,0,0,5);
4144 CONVERT(VarDecFromR8,0.6); EXPECTDEC(1,0,0,6);
4147 static void test_VarDecFromDate(void)
4151 CHECKPTR(VarDecFromDate);
4153 CONVERT(VarDecFromDate,-0.6); EXPECTDEC(1,0x80,0,6);
4154 CONVERT(VarDecFromDate,-0.5); EXPECTDEC(1,0x80,0,5);
4155 CONVERT(VarDecFromDate,-0.4); EXPECTDEC(1,0x80,0,4);
4156 CONVERT(VarDecFromDate,0.0); EXPECTDEC(0,0,0,0);
4157 CONVERT(VarDecFromDate,0.4); EXPECTDEC(1,0,0,4);
4158 CONVERT(VarDecFromDate,0.5); EXPECTDEC(1,0,0,5);
4159 CONVERT(VarDecFromDate,0.6); EXPECTDEC(1,0,0,6);
4162 static void test_VarDecFromStr(void)
4167 CHECKPTR(VarDecFromStr);
4169 in = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4171 CONVERT_STR(VarDecFromStr,NULL,0); EXPECT_MISMATCH;
4172 CONVERT_STR(VarDecFromStr,"-1", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0x80,0,1);
4173 CONVERT_STR(VarDecFromStr,"0", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0,0,0);
4174 CONVERT_STR(VarDecFromStr,"1", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0,0,1);
4175 CONVERT_STR(VarDecFromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECTDEC(1,0,0,5);
4176 CONVERT_STR(VarDecFromStr,"4294967296", LOCALE_NOUSEROVERRIDE); EXPECTDEC64(0,0,0,1,0);
4177 CONVERT_STR(VarDecFromStr,"18446744073709551616", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0,1,0);
4178 CONVERT_STR(VarDecFromStr,"4294967296.0", LOCALE_NOUSEROVERRIDE); EXPECTDEC64(0,0,0,1,0);
4179 CONVERT_STR(VarDecFromStr,"18446744073709551616.0", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0,1,0);
4182 static void test_VarDecFromCy(void)
4186 CHECKPTR(VarDecFromCy);
4188 CONVERT_CY(VarDecFromCy, -1); EXPECTDEC(4,0x80,0,10000);
4189 CONVERT_CY(VarDecFromCy, 0); EXPECTDEC(4,0,0,0);
4190 CONVERT_CY(VarDecFromCy, 1); EXPECTDEC(4,0,0,10000);
4191 CONVERT_CY(VarDecFromCy, 0.5); EXPECTDEC(4,0,0,5000);
4195 #define MATHVARS1 HRESULT hres; DECIMAL l, out
4197 #define MATHVARS2 MATHVARS1; DECIMAL r
4199 #define MATH1(func) hres = p##func(&l, &out)
4201 #define MATH2(func) hres = p##func(&l, &r, &out)
4203 static void test_VarDecAbs(void)
4207 CHECKPTR(VarDecAbs);
4208 SETDEC(l,0,0x80,0,1); MATH1(VarDecAbs); EXPECTDEC(0,0,0,1);
4209 SETDEC(l,0,0,0,0); MATH1(VarDecAbs); EXPECTDEC(0,0,0,0);
4210 SETDEC(l,0,0x80,0,0); MATH1(VarDecAbs); EXPECTDEC(0,0,0,0);
4211 SETDEC(l,0,0,0,1); MATH1(VarDecAbs); EXPECTDEC(0,0,0,1);
4213 /* Doesn't check for invalid input */
4214 SETDEC(l,0,0x7f,0,1); MATH1(VarDecAbs); EXPECTDEC(0,0x7f,0,1);
4215 SETDEC(l,0,0x80,29,1); MATH1(VarDecAbs); EXPECTDEC(0,0,29,1);
4218 static void test_VarDecNeg(void)
4222 CHECKPTR(VarDecNeg);
4223 SETDEC(l,0,0x80,0,1); MATH1(VarDecNeg); EXPECTDEC(0,0,0,1);
4224 SETDEC(l,0,0,0,0); MATH1(VarDecNeg); EXPECTDEC(0,0x80,0,0); /* '-0'! */
4225 SETDEC(l,0,0x80,0,0); MATH1(VarDecNeg); EXPECTDEC(0,0,0,0);
4226 SETDEC(l,0,0,0,1); MATH1(VarDecNeg); EXPECTDEC(0,0x80,0,1);
4228 /* Doesn't check for invalid input */
4229 SETDEC(l,0,0x7f,0,1); MATH1(VarDecNeg); EXPECTDEC(0,0xff,0,1);
4230 SETDEC(l,0,0x80,29,1); MATH1(VarDecNeg); EXPECTDEC(0,0,29,1);
4231 SETDEC(l,0,0,29,1); MATH1(VarDecNeg); EXPECTDEC(0,0x80,29,1);
4234 static void test_VarDecAdd(void)
4238 CHECKPTR(VarDecAdd);
4239 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecAdd); EXPECTDEC(0,0,0,0);
4240 SETDEC(l,0,0,0,0); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,1);
4241 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,1);
4243 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,0); MATH2(VarDecAdd); EXPECTDEC(0,0,0,1);
4244 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,2);
4245 SETDEC(l,0,0,0,1); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,0); /* '-0'! */
4246 SETDEC(l,0,0,0,1); SETDEC(r,0,0x80,0,2); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,1);
4248 SETDEC(l,0,0x80,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,1);
4249 SETDEC(l,0,0x80,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,0);
4250 SETDEC(l,0,0x80,0,1); SETDEC(r,0,0,0,2); MATH2(VarDecAdd); EXPECTDEC(0,0,0,1);
4251 SETDEC(l,0,0x80,0,1); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,2);
4252 SETDEC(l,0,0x80,0,2); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,1);
4254 SETDEC(l,0,0,0,0xffffffff); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,0xfffffffe);
4255 SETDEC(l,0,0,0,0xffffffff); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,(ULONG64)1 << 32);
4256 SETDEC(l,0,0,0,0xffffffff); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,(ULONG64)1 << 32);
4258 SETDEC64(l,0,0,0,0xffffffff,0); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC64(0,0,0,0xffffffff,1);
4259 SETDEC64(l,0,0,0,0xffffffff,0); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd);
4260 EXPECTDEC64(0,0,0,0xfffffffe,0xffffffff);
4262 SETDEC64(l,0,0,0,0xffffffff,0xffffffff); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,1,0);
4263 SETDEC64(l,0,0,0,0xffffffff,0xffffffff); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd);
4264 EXPECTDEC64(0,0,0,0xffffffff,0xfffffffe);
4266 SETDEC(l,0,0,0xffffffff,0); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0xffffffff,1);
4267 SETDEC(l,0,0,0xffffffff,0); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd);
4268 EXPECTDEC64(0,0,0xfffffffe,0xffffffff,0xffffffff);
4270 SETDEC64(l,0,0,0xffffffff,0xffffffff,0xffffffff);SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd);
4271 EXPECTDEC64(0,0,0xffffffff,0xffffffff,0xfffffffe);
4272 SETDEC64(l,0,0,0xffffffff,0xffffffff,0xffffffff);SETDEC(r,0,0,0,1); MATH2(VarDecAdd);
4273 ok(hres == DISP_E_OVERFLOW,"Expected overflow, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
4274 S(U(out)).scale, S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres);
4276 /* Promotes to the highest scale, so here the results are in the scale of 2 */
4277 SETDEC(l,2,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecAdd); EXPECTDEC(2,0,0,0);
4278 SETDEC(l,2,0,0,100); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(2,0,0,200);
4281 static void test_VarDecSub(void)
4285 CHECKPTR(VarDecSub);
4286 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecSub); EXPECTDEC(0,0x80,0,0);
4287 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecSub); EXPECTDEC(0,0x80,0,1);
4288 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecSub); EXPECTDEC(0,0x80,0,0);
4289 SETDEC(l,0,0,0,1); SETDEC(r,0,0x80,0,1); MATH2(VarDecSub); EXPECTDEC(0,0,0,2);
4292 static void test_VarDecMul(void)
4296 CHECKPTR(VarDecMul);
4297 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecMul); EXPECTDEC(0,0,0,0);
4298 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,0); MATH2(VarDecMul); EXPECTDEC(0,0,0,0);
4299 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecMul); EXPECTDEC(0,0,0,0);
4300 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecMul); EXPECTDEC(0,0,0,1);
4301 SETDEC(l,0,0,0,45000);SETDEC(r,0,0,0,2); MATH2(VarDecMul); EXPECTDEC(0,0,0,90000);
4302 SETDEC(l,0,0,0,2); SETDEC(r,0,0,0,45000); MATH2(VarDecMul); EXPECTDEC(0,0,0,90000);
4304 SETDEC(l,0,0x80,0,2); SETDEC(r,0,0,0,2); MATH2(VarDecMul); EXPECTDEC(0,0x80,0,4);
4305 SETDEC(l,0,0,0,2); SETDEC(r,0,0x80,0,2); MATH2(VarDecMul); EXPECTDEC(0,0x80,0,4);
4306 SETDEC(l,0,0x80,0,2); SETDEC(r,0,0x80,0,2); MATH2(VarDecMul); EXPECTDEC(0,0,0,4);
4308 SETDEC(l,4,0,0,2); SETDEC(r,0,0,0,2); MATH2(VarDecMul); EXPECTDEC(4,0,0,4);
4309 SETDEC(l,0,0,0,2); SETDEC(r,3,0,0,2); MATH2(VarDecMul); EXPECTDEC(3,0,0,4);
4310 SETDEC(l,4,0,0,2); SETDEC(r,3,0,0,2); MATH2(VarDecMul); EXPECTDEC(7,0,0,4);
4311 /* this last one shows that native oleaut32 does *not* gratuitously seize opportunities
4312 to reduce the scale if possible - the canonical result for the expected value is (6,0,0,1)
4314 SETDEC(l,4,0,0,5); SETDEC(r,3,0,0,2); MATH2(VarDecMul); EXPECTDEC(7,0,0,10);
4316 SETDEC64(l,0,0,0,0xFFFFFFFF,0xFFFFFFFF); SETDEC(r,0,0,0,2); MATH2(VarDecMul); EXPECTDEC64(0,0,1,0xFFFFFFFF,0xFFFFFFFE);
4317 SETDEC(l,0,0,0,2); SETDEC64(r,0,0,0,0xFFFFFFFF,0xFFFFFFFF); MATH2(VarDecMul); EXPECTDEC64(0,0,1,0xFFFFFFFF,0xFFFFFFFE);
4318 SETDEC(l,0,0,1,1); SETDEC(r,0,0,0,0x80000000); MATH2(VarDecMul); EXPECTDEC(0,0,0x80000000,0x80000000);
4319 SETDEC(l,0,0,0,0x80000000); SETDEC(r,0,0,1,1); MATH2(VarDecMul); EXPECTDEC(0,0,0x80000000,0x80000000);
4321 /* near-overflow, used as a reference */
4322 SETDEC64(l,0,0,0,0xFFFFFFFF,0xFFFFFFFF); SETDEC(r,0,0,0,2000000000); MATH2(VarDecMul);EXPECTDEC64(0,0,1999999999,0xFFFFFFFF,0x88CA6C00);
4323 /* actual overflow - right operand is 10 times the previous value */
4324 SETDEC64(l,0,0,0,0xFFFFFFFF,0xFFFFFFFF); SETDEC64(r,0,0,0,4,0xA817C800); MATH2(VarDecMul);
4325 ok(hres == DISP_E_OVERFLOW,"Expected overflow, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
4326 S(U(out)).scale, S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres);
4327 /* here, native oleaut32 has an opportunity to avert the overflow, by reducing the scale of the result */
4328 SETDEC64(l,1,0,0,0xFFFFFFFF,0xFFFFFFFF); SETDEC64(r,0,0,0,4,0xA817C800); MATH2(VarDecMul);EXPECTDEC64(0,0,1999999999,0xFFFFFFFF,0x88CA6C00);
4330 /* near-overflow, used as a reference */
4331 SETDEC64(l,0,0,1,0xFFFFFFFF,0xFFFFFFFE); SETDEC(r,0,0,0,1000000000); MATH2(VarDecMul);EXPECTDEC64(0,0,1999999999,0xFFFFFFFF,0x88CA6C00);
4332 /* actual overflow - right operand is 10 times the previous value */
4333 SETDEC64(l,0,0,1,0xFFFFFFFF,0xFFFFFFFE); SETDEC64(r,0,0,0,2,0x540BE400); MATH2(VarDecMul);
4334 ok(hres == DISP_E_OVERFLOW,"Expected overflow, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
4335 S(U(out)).scale, S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres);
4336 /* here, native oleaut32 has an opportunity to avert the overflow, by reducing the scale of the result */
4337 SETDEC64(l,1,0,1,0xFFFFFFFF,0xFFFFFFFE); SETDEC64(r,0,0,0,2,0x540BE400); MATH2(VarDecMul);EXPECTDEC64(0,0,1999999999,0xFFFFFFFF,0x88CA6C00);
4339 /* this one shows that native oleaut32 is willing to lose significant digits in order to avert an overflow */
4340 SETDEC64(l,2,0,0,0xFFFFFFFF,0xFFFFFFFF); SETDEC64(r,0,0,0,9,0x502F9001); MATH2(VarDecMul);EXPECTDEC64(1,0,0xee6b2800,0x19999998,0xab2e719a);
4343 static void test_VarDecDiv(void)
4347 CHECKPTR(VarDecDiv);
4348 /* identity divisions */
4349 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecDiv); EXPECTDEC(0,0,0,0);
4350 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecDiv); EXPECTDEC(0,0,0,1);
4351 SETDEC(l,1,0,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecDiv); EXPECTDEC(1,0,0,1);
4353 /* exact divisions */
4354 SETDEC(l,0,0,0,45); SETDEC(r,0,0,0,9); MATH2(VarDecDiv); EXPECTDEC(0,0,0,5);
4355 SETDEC(l,1,0,0,45); SETDEC(r,0,0,0,9); MATH2(VarDecDiv); EXPECTDEC(1,0,0,5);
4356 SETDEC(l,0,0,0,45); SETDEC(r,1,0,0,9); MATH2(VarDecDiv); EXPECTDEC(0,0,0,50);
4357 SETDEC(l,1,0,0,45); SETDEC(r,2,0,0,9); MATH2(VarDecDiv); EXPECTDEC(0,0,0,50);
4358 /* these last three results suggest that native oleaut32 scales both operands down to zero
4359 before the division, but does *not* try to scale the result, even if it is possible -
4360 analogous to multiplication behavior
4362 SETDEC(l,1,0,0,45); SETDEC(r,1,0,0,9); MATH2(VarDecDiv); EXPECTDEC(0,0,0,5);
4363 SETDEC(l,2,0,0,450); SETDEC(r,1,0,0,9); MATH2(VarDecDiv); EXPECTDEC(1,0,0,50);
4365 /* inexact divisions */
4366 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,180700362,0x14b700cb,0x05555555);
4367 SETDEC(l,1,0,0,1); SETDEC(r,0,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,18070036,0x35458014,0x4d555555);
4368 SETDEC(l,0,0,0,1); SETDEC(r,1,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,1807003620,0xcf2607ee,0x35555555);
4369 SETDEC(l,1,0,0,1); SETDEC(r,2,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,1807003620,0xcf2607ee,0x35555555);
4370 SETDEC(l,1,0,0,1); SETDEC(r,1,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,180700362,0x14b700cb,0x05555555);
4371 SETDEC(l,2,0,0,10); SETDEC(r,1,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,180700362,0x14b700cb,0x05555555);
4373 /* this one shows that native oleaut32 rounds up the result */
4374 SETDEC(l,0,0,0,2); SETDEC(r,0,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,361400724,0x296e0196,0x0aaaaaab);
4377 SETDEC(l,0,0x80,0,45); SETDEC(r,0,0,0,9); MATH2(VarDecDiv); EXPECTDEC(0,0x80,0,5);
4378 SETDEC(l,0,0,0,45); SETDEC(r,0,0x80,0,9); MATH2(VarDecDiv);EXPECTDEC(0,0x80,0,5);
4379 SETDEC(l,0,0x80,0,45); SETDEC(r,0,0x80,0,9); MATH2(VarDecDiv);EXPECTDEC(0,0,0,5);
4382 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecDiv);/* indeterminate */
4383 ok(hres == DISP_E_DIVBYZERO,"Expected division-by-zero, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
4384 S(U(out)).scale, S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres);
4385 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,0); MATH2(VarDecDiv);/* division by zero */
4386 ok(hres == DISP_E_DIVBYZERO,"Expected division-by-zero, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
4387 S(U(out)).scale, S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres);
4391 static void test_VarDecCmp(void)
4395 CHECKPTR(VarDecCmp);
4396 SETDEC(l,0,0,0,1); SETDEC(out,0,0,0,1); MATH1(VarDecCmp); EXPECT_EQ;
4397 SETDEC(l,0,0,0,1); SETDEC(out,0,0,0,0); MATH1(VarDecCmp); EXPECT_GT;
4398 SETDEC(l,0,0,0,0); SETDEC(out,0,0,0,1); MATH1(VarDecCmp); EXPECT_LT;
4406 #define CONV_TYPE VARIANT_BOOL
4408 #define _EXPECTRES(res, x, fs) \
4409 ok((hres == S_OK && out == (CONV_TYPE)(x)) || ((HRESULT)res != S_OK && hres == (HRESULT)res), \
4410 "expected " #x ", got " fs "; hres=0x%08x\n", out, hres)
4412 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%d")
4414 #define CONVERTRANGE(func,start,end) for (i = start; i < end; i++) { \
4415 CONVERT(func, i); if (i) { EXPECT(VARIANT_TRUE); } else { EXPECT(VARIANT_FALSE); } }
4417 static void test_VarBoolFromI1(void)
4419 CONVVARS(signed char);
4422 CHECKPTR(VarBoolFromI1);
4423 CONVERTRANGE(VarBoolFromI1, -128, 128);
4426 static void test_VarBoolFromUI1(void)
4431 CHECKPTR(VarBoolFromUI1);
4432 CONVERTRANGE(VarBoolFromUI1, 0, 256);
4435 static void test_VarBoolFromI2(void)
4440 CHECKPTR(VarBoolFromI2);
4441 CONVERTRANGE(VarBoolFromI2, -32768, 32768);
4444 static void test_VarBoolFromUI2(void)
4449 CHECKPTR(VarBoolFromUI2);
4450 CONVERTRANGE(VarBoolFromUI2, 0, 65536);
4453 static void test_VarBoolFromI4(void)
4457 CHECKPTR(VarBoolFromI4);
4458 CONVERT(VarBoolFromI4, 0x80000000); EXPECT(VARIANT_TRUE);
4459 CONVERT(VarBoolFromI4, -1); EXPECT(VARIANT_TRUE);
4460 CONVERT(VarBoolFromI4, 0); EXPECT(VARIANT_FALSE);
4461 CONVERT(VarBoolFromI4, 1); EXPECT(VARIANT_TRUE);
4462 CONVERT(VarBoolFromI4, 0x7fffffff); EXPECT(VARIANT_TRUE);
4465 static void test_VarBoolFromUI4(void)
4469 CHECKPTR(VarBoolFromUI4);
4470 CONVERT(VarBoolFromI4, 0); EXPECT(VARIANT_FALSE);
4471 CONVERT(VarBoolFromI4, 1); EXPECT(VARIANT_TRUE);
4472 CONVERT(VarBoolFromI4, 0x80000000); EXPECT(VARIANT_TRUE);
4475 static void test_VarBoolFromR4(void)
4479 CHECKPTR(VarBoolFromR4);
4480 CONVERT(VarBoolFromR4, -1.0f); EXPECT(VARIANT_TRUE);
4481 CONVERT(VarBoolFromR4, 0.0f); EXPECT(VARIANT_FALSE);
4482 CONVERT(VarBoolFromR4, 1.0f); EXPECT(VARIANT_TRUE);
4483 CONVERT(VarBoolFromR4, 1.5f); EXPECT(VARIANT_TRUE);
4486 CONVERT(VarBoolFromR4, -1.5f); EXPECT(VARIANT_TRUE);
4487 CONVERT(VarBoolFromR4, -0.6f); EXPECT(VARIANT_TRUE);
4488 CONVERT(VarBoolFromR4, -0.5f); EXPECT(VARIANT_TRUE);
4489 CONVERT(VarBoolFromR4, -0.4f); EXPECT(VARIANT_TRUE);
4490 CONVERT(VarBoolFromR4, 0.4f); EXPECT(VARIANT_TRUE);
4491 CONVERT(VarBoolFromR4, 0.5f); EXPECT(VARIANT_TRUE);
4492 CONVERT(VarBoolFromR4, 0.6f); EXPECT(VARIANT_TRUE);
4493 CONVERT(VarBoolFromR4, 1.5f); EXPECT(VARIANT_TRUE);
4496 static void test_VarBoolFromR8(void)
4500 /* Hopefully we made the point with R4 above that rounding is
4501 * irrelevant, so we'll skip that for R8 and Date
4503 CHECKPTR(VarBoolFromR8);
4504 CONVERT(VarBoolFromR8, -1.0); EXPECT(VARIANT_TRUE);
4505 CONVERT(VarBoolFromR8, -0.0); EXPECT(VARIANT_FALSE);
4506 CONVERT(VarBoolFromR8, 1.0); EXPECT(VARIANT_TRUE);
4509 static void test_VarBoolFromCy(void)
4513 CHECKPTR(VarBoolFromCy);
4514 CONVERT_CY(VarBoolFromCy, -32769); EXPECT(VARIANT_TRUE);
4515 CONVERT_CY(VarBoolFromCy, -32768); EXPECT(VARIANT_TRUE);
4516 CONVERT_CY(VarBoolFromCy, -1); EXPECT(VARIANT_TRUE);
4517 CONVERT_CY(VarBoolFromCy, 0); EXPECT(VARIANT_FALSE);
4518 CONVERT_CY(VarBoolFromCy, 1); EXPECT(VARIANT_TRUE);
4519 CONVERT_CY(VarBoolFromCy, 32767); EXPECT(VARIANT_TRUE);
4520 CONVERT_CY(VarBoolFromCy, 32768); EXPECT(VARIANT_TRUE);
4523 static void test_VarBoolFromI8(void)
4527 CHECKPTR(VarBoolFromI8);
4528 CONVERT(VarBoolFromI8, -1); EXPECT(VARIANT_TRUE);
4529 CONVERT(VarBoolFromI8, 0); EXPECT(VARIANT_FALSE);
4530 CONVERT(VarBoolFromI8, 1); EXPECT(VARIANT_TRUE);
4533 static void test_VarBoolFromUI8(void)
4537 CHECKPTR(VarBoolFromUI8);
4538 CONVERT(VarBoolFromUI8, 0); EXPECT(VARIANT_FALSE);
4539 CONVERT(VarBoolFromUI8, 1); EXPECT(VARIANT_TRUE);
4542 static void test_VarBoolFromDec(void)
4546 CHECKPTR(VarBoolFromDec);
4547 CONVERT_BADDEC(VarBoolFromDec);
4549 if (HAVE_OLEAUT32_DECIMAL)
4551 /* Early versions of oleaut32 don't catch these errors */
4552 CONVERT_DEC(VarBoolFromDec,29,0,0,0); EXPECT_INVALID;
4553 CONVERT_DEC(VarBoolFromDec,0,0x1,0,0); EXPECT_INVALID;
4554 CONVERT_DEC(VarBoolFromDec,0,0x40,0,0); EXPECT_INVALID;
4555 CONVERT_DEC(VarBoolFromDec,0,0x7f,0,0); EXPECT_INVALID;
4558 CONVERT_DEC(VarBoolFromDec,0,0x80,0,1); EXPECT(VARIANT_TRUE);
4559 CONVERT_DEC(VarBoolFromDec,0,0,0,0); EXPECT(VARIANT_FALSE);
4560 CONVERT_DEC(VarBoolFromDec,0,0,0,1); EXPECT(VARIANT_TRUE);
4561 CONVERT_DEC(VarBoolFromDec,0,0,1,0); EXPECT(VARIANT_TRUE);
4563 CONVERT_DEC(VarBoolFromDec,2,0,0,CY_MULTIPLIER); EXPECT(VARIANT_TRUE);
4564 CONVERT_DEC(VarBoolFromDec,2,0x80,0,CY_MULTIPLIER); EXPECT(VARIANT_TRUE);
4567 static void test_VarBoolFromDate(void)
4571 CHECKPTR(VarBoolFromDate);
4572 CONVERT(VarBoolFromDate, -1.0); EXPECT(VARIANT_TRUE);
4573 CONVERT(VarBoolFromDate, -0.0); EXPECT(VARIANT_FALSE);
4574 CONVERT(VarBoolFromDate, 1.0); EXPECT(VARIANT_TRUE);
4577 static void test_VarBoolFromStr(void)
4582 CHECKPTR(VarBoolFromStr);
4584 in = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4586 CONVERT_STR(VarBoolFromStr,NULL,0);
4587 if (hres != E_INVALIDARG)
4590 /* #FALSE# and #TRUE# Are always accepted */
4591 CONVERT_STR(VarBoolFromStr,"#FALSE#",0); EXPECT(VARIANT_FALSE);
4592 CONVERT_STR(VarBoolFromStr,"#TRUE#",0); EXPECT(VARIANT_TRUE);
4594 /* Match of #FALSE# and #TRUE# is case sensitive */
4595 CONVERT_STR(VarBoolFromStr,"#False#",0); EXPECT_MISMATCH;
4596 /* But match against English is not */
4597 CONVERT_STR(VarBoolFromStr,"false",0); EXPECT(VARIANT_FALSE);
4598 CONVERT_STR(VarBoolFromStr,"False",0); EXPECT(VARIANT_FALSE);
4599 /* On/Off and yes/no are not acceptable inputs, with any flags set */
4600 CONVERT_STR(VarBoolFromStr,"On",0xffffffff); EXPECT_MISMATCH;
4601 CONVERT_STR(VarBoolFromStr,"Yes",0xffffffff); EXPECT_MISMATCH;
4603 /* Change the LCID. This doesn't make any difference for text,unless we ask
4604 * to check local boolean text with the VARIANT_LOCALBOOL flag. */
4605 in = MAKELCID(MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT), SORT_DEFAULT);
4607 /* #FALSE# and #TRUE# are accepted in all locales */
4608 CONVERT_STR(VarBoolFromStr,"#FALSE#",0); EXPECT(VARIANT_FALSE);
4609 CONVERT_STR(VarBoolFromStr,"#TRUE#",0); EXPECT(VARIANT_TRUE);
4610 CONVERT_STR(VarBoolFromStr,"#FALSE#",VARIANT_LOCALBOOL); EXPECT(VARIANT_FALSE);
4611 CONVERT_STR(VarBoolFromStr,"#TRUE#",VARIANT_LOCALBOOL); EXPECT(VARIANT_TRUE);
4613 /* English is accepted regardless of the locale */
4614 CONVERT_STR(VarBoolFromStr,"false",0); EXPECT(VARIANT_FALSE);
4615 /* And is still not case sensitive */
4616 CONVERT_STR(VarBoolFromStr,"False",0); EXPECT(VARIANT_FALSE);
4618 if (HAVE_OLEAUT32_LOCALES)
4620 /* French is rejected without VARIANT_LOCALBOOL */
4621 CONVERT_STR(VarBoolFromStr,"faux",0); EXPECT_MISMATCH;
4622 /* But accepted if this flag is given */
4623 CONVERT_STR(VarBoolFromStr,"faux",VARIANT_LOCALBOOL); EXPECT(VARIANT_FALSE);
4624 /* Regardless of case - from this we assume locale text comparisons ignore case */
4625 CONVERT_STR(VarBoolFromStr,"Faux",VARIANT_LOCALBOOL); EXPECT(VARIANT_FALSE);
4627 /* Changing the locale prevents the localised text from being compared -
4628 * this demonstrates that only the indicated LCID and English are searched */
4629 in = MAKELCID(MAKELANGID(LANG_POLISH, SUBLANG_DEFAULT), SORT_DEFAULT);
4630 CONVERT_STR(VarBoolFromStr,"faux",VARIANT_LOCALBOOL); EXPECT_MISMATCH;
4633 /* Numeric strings are read as 0 or non-0 */
4634 CONVERT_STR(VarBoolFromStr,"0",0); EXPECT(VARIANT_FALSE);
4635 CONVERT_STR(VarBoolFromStr,"-1",0); EXPECT(VARIANT_TRUE);
4636 CONVERT_STR(VarBoolFromStr,"+1",0); EXPECT(VARIANT_TRUE);
4638 if (HAVE_OLEAUT32_LOCALES)
4640 /* Numeric strings are read as floating point numbers. The line below fails
4641 * because '.' is not a valid decimal separator for Polish numbers */
4642 CONVERT_STR(VarBoolFromStr,"0.1",LOCALE_NOUSEROVERRIDE); EXPECT_MISMATCH;
4645 /* Changing the lcid back to US English reads the r8 correctly */
4646 in = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4647 CONVERT_STR(VarBoolFromStr,"0.1",LOCALE_NOUSEROVERRIDE); EXPECT(VARIANT_TRUE);
4650 static void test_VarBoolCopy(void)
4652 COPYTEST(1, VT_BOOL, V_BOOL(&vSrc), V_BOOL(&vDst), V_BOOLREF(&vSrc), V_BOOLREF(&vDst), "%d");
4655 #define BOOL_STR(flags, str) hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, flags, VT_BSTR); \
4656 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && \
4657 V_BSTR(&vDst) && !memcmp(V_BSTR(&vDst), str, sizeof(str)), \
4658 "hres=0x%X, type=%d (should be VT_BSTR), *bstr='%c'\n", \
4659 hres, V_VT(&vDst), V_BSTR(&vDst) ? *V_BSTR(&vDst) : '?')
4661 static void test_VarBoolChangeTypeEx(void)
4663 static const WCHAR szTrue[] = { 'T','r','u','e','\0' };
4664 static const WCHAR szFalse[] = { 'F','a','l','s','e','\0' };
4665 static const WCHAR szFaux[] = { 'F','a','u','x','\0' };
4666 CONVVARS(CONV_TYPE);
4667 VARIANTARG vSrc, vDst;
4672 INITIAL_TYPETEST(VT_BOOL, V_BOOL, "%d");
4675 /* The common tests convert to a number. Try the different flags */
4676 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4678 V_VT(&vSrc) = VT_BOOL;
4683 BOOL_STR(VARIANT_ALPHABOOL, szTrue);
4685 BOOL_STR(VARIANT_ALPHABOOL, szFalse);
4688 if (HAVE_OLEAUT32_LOCALES)
4690 lcid = MAKELCID(MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT), SORT_DEFAULT);
4692 /* VARIANT_ALPHABOOL is always English */
4693 BOOL_STR(VARIANT_ALPHABOOL, szFalse);
4694 /* VARIANT_LOCALBOOL uses the localised text */
4695 BOOL_STR(VARIANT_LOCALBOOL, szFaux);
4696 /* Both flags together acts as VARIANT_LOCALBOOL */
4697 BOOL_STR(VARIANT_ALPHABOOL|VARIANT_LOCALBOOL, szFaux);
4705 static void test_VarBstrFromR4(void)
4707 static const WCHAR szNative[] = { '6','5','4','3','2','2','.','3','\0' };
4708 static const WCHAR szZero[] = {'0', '\0'};
4709 static const WCHAR szOneHalf_English[] = { '0','.','5','\0' }; /* uses period */
4710 static const WCHAR szOneHalf_Spanish[] = { '0',',','5','\0' }; /* uses comma */
4718 CHECKPTR(VarBstrFromR4);
4720 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4721 lcid_spanish = MAKELCID(MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH), SORT_DEFAULT);
4723 hres = pVarBstrFromR4(f, lcid, 0, &bstr);
4724 ok(hres == S_OK, "got hres 0x%08x\n", hres);
4728 /* MSDN states that rounding of R4/R8 is dependent on the underlying
4729 * bit pattern of the number and so is architecture dependent. In this
4730 * case Wine returns .2 (which is more correct) and Native returns .3
4732 ok(memcmp(bstr, szNative, sizeof(szNative)) == 0, "string different\n");
4736 f = -1e-400; /* deliberately cause underflow */
4737 hres = pVarBstrFromR4(f, lcid, 0, &bstr);
4738 ok(hres == S_OK, "got hres 0x%08x\n", hres);
4741 ok(memcmp(bstr, szZero, sizeof(szZero)) == 0, "negative zero (got %s)\n", wtoascii(bstr));
4744 /* The following tests that lcid is used for decimal separator even without LOCALE_USE_NLS */
4746 hres = pVarBstrFromR4(f, lcid, LOCALE_NOUSEROVERRIDE, &bstr);
4747 ok(hres == S_OK, "got hres 0x%08x\n", hres);
4750 ok(memcmp(bstr, szOneHalf_English, sizeof(szOneHalf_English)) == 0, "English locale failed (got %s)\n", wtoascii(bstr));
4753 hres = pVarBstrFromR4(f, lcid_spanish, LOCALE_NOUSEROVERRIDE, &bstr);
4754 ok(hres == S_OK, "got hres 0x%08x\n", hres);
4757 ok(memcmp(bstr, szOneHalf_Spanish, sizeof(szOneHalf_Spanish)) == 0, "Spanish locale failed (got %s)\n", wtoascii(bstr));
4761 #define BSTR_DATE(dt,str) SysFreeString(bstr); bstr = NULL; \
4762 hres = pVarBstrFromDate(dt,lcid,LOCALE_NOUSEROVERRIDE,&bstr); \
4763 if (bstr) WideCharToMultiByte(CP_ACP, 0, bstr, -1, buff, sizeof(buff), 0, 0); \
4765 ok(hres == S_OK && !strcmp(str,buff), "Expected '%s', got '%s', hres = 0x%08x\n", \
4768 static void test_VarBstrFromDate(void)
4775 CHECKPTR(VarBstrFromDate);
4776 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
4778 BSTR_DATE(0.0, "12:00:00 AM");
4779 BSTR_DATE(3.34, "1/2/1900 8:09:36 AM");
4780 BSTR_DATE(3339.34, "2/20/1909 8:09:36 AM");
4781 BSTR_DATE(365.00, "12/30/1900");
4782 BSTR_DATE(365.25, "12/30/1900 6:00:00 AM");
4783 BSTR_DATE(1461.0, "12/31/1903");
4784 BSTR_DATE(1461.5, "12/31/1903 12:00:00 PM");
4787 #define BSTR_DEC(l, a, b, c, d, e) \
4788 SETDEC(l, a,b,c,d);\
4789 hres = VarBstrFromDec(&l, lcid, LOCALE_NOUSEROVERRIDE, &bstr);\
4790 ok(hres == S_OK, "got hres 0x%08x\n", hres);\
4791 if (hres== S_OK && bstr)\
4793 ok(lstrcmpW(bstr, e) == 0, "invalid number (got %s)\n", wtoascii(bstr));\
4796 #define BSTR_DEC64(l, a, b, c, x, d, e) \
4797 SETDEC64(l, a,b,c,x,d);\
4798 hres = VarBstrFromDec(&l, lcid, LOCALE_NOUSEROVERRIDE, &bstr);\
4799 ok(hres == S_OK, "got hres 0x%08x\n", hres);\
4800 if (hres== S_OK && bstr)\
4802 ok(lstrcmpW(bstr, e) == 0, "invalid number (got %s)\n", wtoascii(bstr));\
4805 static void test_VarBstrFromDec(void)
4812 static const WCHAR szZero[] = {'0', '\0'};
4813 static const WCHAR szOne[] = {'1', '\0'};
4814 static const WCHAR szOnePointFive[] = {'1','.','5','\0'};
4815 static const WCHAR szMinusOnePointFive[] = {'-','1','.','5','\0'};
4816 static const WCHAR szBigNum1[] = {'4','2','9','4','9','6','7','2','9','5','\0'}; /* (1 << 32) - 1 */
4817 static const WCHAR szBigNum2[] = {'4','2','9','4','9','6','7','2','9','6','\0'}; /* (1 << 32) */
4818 static const WCHAR szBigNum3[] = {'1','8','4','4','6','7','4','4','0','7','3','7','0','9','5','5','1','6','1','5','\0'}; /* (1 << 64) - 1 */
4819 static const WCHAR szBigNum4[] = {'1','8','4','4','6','7','4','4','0','7','3','7','0','9','5','5','1','6','1','6','\0'}; /* (1 << 64) */
4820 static const WCHAR szBigNum5[] = {'7','9','2','2','8','1','6','2','5','1','4','2','6','4','3','3','7','5','9','3','5','4','3','9','5','0','3','3','5','\0'}; /* (1 << 96) - 1 */
4821 static const WCHAR szBigScale1[] = {'0','.','0','0','0','0','0','0','0','0','0','1','\0'}; /* 1 * 10^-10 */
4822 static const WCHAR szBigScale2[] = {'7','9','2','2','8','1','6','2','5','1','4','2','6','4','3','3','7','5','9','.','3','5','4','3','9','5','0','3','3','5','\0'}; /* ((1 << 96) - 1) * 10^-10 */
4823 static const WCHAR szBigScale3[] = {'7','.','9','2','2','8','1','6','2','5','1','4','2','6','4','3','3','7','5','9','3','5','4','3','9','5','0','3','3','5','\0'}; /* ((1 << 96) - 1) * 10^-28 */
4825 static const WCHAR szSmallNumber_English[] = {'0','.','0','0','0','9','\0'};
4826 static const WCHAR szSmallNumber_Spanish[] = {'0',',','0','0','0','9','\0'};
4828 CHECKPTR(VarBstrFromDec);
4829 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
4832 BSTR_DEC(l, 0,0,0,0, szZero);
4835 BSTR_DEC(l, 0,0,0,1, szOne);
4836 BSTR_DEC(l, 1,0,0,10,szOne);
4837 BSTR_DEC(l, 2,0,0,100,szOne);
4838 BSTR_DEC(l, 3,0,0,1000,szOne);
4840 /* check one point five */
4841 BSTR_DEC(l, 1,0,0,15, szOnePointFive);
4842 BSTR_DEC(l, 2,0,0,150, szOnePointFive);
4843 BSTR_DEC(l, 3,0,0,1500, szOnePointFive);
4845 /* check minus one point five */
4846 BSTR_DEC(l, 1,0x80,0,15, szMinusOnePointFive);
4848 /* check bignum (1) */
4849 BSTR_DEC(l, 0,0,0,0xffffffff, szBigNum1);
4851 /* check bignum (2) */
4852 BSTR_DEC64(l, 0,0,0,1,0, szBigNum2);
4854 /* check bignum (3) */
4855 BSTR_DEC64(l, 0,0,0,0xffffffff,0xffffffff, szBigNum3);
4857 /* check bignum (4) */
4858 BSTR_DEC(l, 0,0,1,0, szBigNum4);
4860 /* check bignum (5) */
4861 BSTR_DEC64(l, 0,0,0xffffffff,0xffffffff,0xffffffff, szBigNum5);
4863 /* check bigscale (1) */
4864 BSTR_DEC(l, 10,0,0,1, szBigScale1);
4866 /* check bigscale (2) */
4867 BSTR_DEC64(l, 10,0,0xffffffffUL,0xffffffff,0xffffffff, szBigScale2);
4869 /* check bigscale (3) */
4870 BSTR_DEC64(l, 28,0,0xffffffffUL,0xffffffff,0xffffffff, szBigScale3);
4872 /* check leading zeros and decimal sep. for English locale */
4873 BSTR_DEC(l, 4,0,0,9, szSmallNumber_English);
4874 BSTR_DEC(l, 5,0,0,90, szSmallNumber_English);
4875 BSTR_DEC(l, 6,0,0,900, szSmallNumber_English);
4876 BSTR_DEC(l, 7,0,0,9000, szSmallNumber_English);
4878 lcid = MAKELCID(MAKELANGID(LANG_SPANISH, SUBLANG_DEFAULT), SORT_DEFAULT);
4880 /* check leading zeros and decimal sep. for Spanish locale */
4881 BSTR_DEC(l, 4,0,0,9, szSmallNumber_Spanish);
4882 BSTR_DEC(l, 5,0,0,90, szSmallNumber_Spanish);
4883 BSTR_DEC(l, 6,0,0,900, szSmallNumber_Spanish);
4884 BSTR_DEC(l, 7,0,0,9000, szSmallNumber_Spanish);
4889 #define _VARBSTRCMP(left,right,lcid,flags,result) \
4890 hres = pVarBstrCmp(left,right,lcid,flags); \
4891 ok(hres == result, "VarBstrCmp: expected " #result ", got hres=0x%x\n", hres)
4892 #define VARBSTRCMP(left,right,flags,result) \
4893 _VARBSTRCMP(left,right,lcid,flags,result)
4895 static void test_VarBstrCmp(void)
4899 static const WCHAR sz[] = {'W','u','r','s','c','h','t','\0'};
4900 static const WCHAR szempty[] = {'\0'};
4901 static const WCHAR sz1[] = { 'a',0 };
4902 static const WCHAR sz2[] = { 'A',0 };
4903 static const WCHAR s1[] = { 'a',0 };
4904 static const WCHAR s2[] = { 'a',0,'b' };
4905 static const char sb1[] = {1,0,1};
4906 static const char sb2[] = {1,0,2};
4907 BSTR bstr, bstrempty, bstr2;
4909 CHECKPTR(VarBstrCmp);
4911 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
4912 bstr = SysAllocString(sz);
4913 bstrempty = SysAllocString(szempty);
4915 /* NULL handling. Yepp, MSDN is totaly wrong here */
4916 VARBSTRCMP(NULL,NULL,0,VARCMP_EQ);
4917 VARBSTRCMP(bstr,NULL,0,VARCMP_GT);
4918 VARBSTRCMP(NULL,bstr,0,VARCMP_LT);
4920 /* NULL and empty string comparisions */
4921 VARBSTRCMP(bstrempty,NULL,0,VARCMP_EQ);
4922 VARBSTRCMP(NULL,bstrempty,0,VARCMP_EQ);
4924 SysFreeString(bstr);
4925 bstr = SysAllocString(sz1);
4927 bstr2 = SysAllocString(sz2);
4928 VARBSTRCMP(bstr,bstr2,0,VARCMP_LT);
4929 VARBSTRCMP(bstr,bstr2,NORM_IGNORECASE,VARCMP_EQ);
4930 SysFreeString(bstr2);
4931 /* These two strings are considered equal even though one is
4932 * NULL-terminated and the other not.
4934 bstr2 = SysAllocStringLen(s1, sizeof(s1) / sizeof(WCHAR));
4935 VARBSTRCMP(bstr,bstr2,0,VARCMP_EQ);
4936 SysFreeString(bstr2);
4938 /* These two strings are not equal */
4939 bstr2 = SysAllocStringLen(s2, sizeof(s2) / sizeof(WCHAR));
4940 VARBSTRCMP(bstr,bstr2,0,VARCMP_LT);
4941 SysFreeString(bstr2);
4943 SysFreeString(bstr);
4945 /* When (LCID == 0) it should be a binary comparison
4946 * so these two strings could not match.
4948 bstr = SysAllocStringByteLen(sb1, sizeof(sb1));
4949 bstr2 = SysAllocStringByteLen(sb2, sizeof(sb2));
4951 VARBSTRCMP(bstr,bstr2,0,VARCMP_LT);
4952 SysFreeString(bstr2);
4953 SysFreeString(bstr);
4956 /* Get the internal representation of a BSTR */
4957 static inline LPINTERNAL_BSTR Get(const BSTR lpszString)
4959 return lpszString ? (LPINTERNAL_BSTR)((char*)lpszString - sizeof(DWORD)) : NULL;
4962 static inline BSTR GetBSTR(const LPINTERNAL_BSTR bstr)
4964 return (BSTR)bstr->szString;
4967 static void test_SysStringLen(void)
4970 BSTR str = GetBSTR(&bstr);
4973 ok (SysStringLen(str) == 0, "Expected dwLen 0, got %d\n", SysStringLen(str));
4975 ok (SysStringLen(str) == 1, "Expected dwLen 1, got %d\n", SysStringLen(str));
4978 static void test_SysStringByteLen(void)
4981 BSTR str = GetBSTR(&bstr);
4984 ok (SysStringByteLen(str) == 0, "Expected dwLen 0, got %d\n", SysStringLen(str));
4986 ok (SysStringByteLen(str) == 2, "Expected dwLen 2, got %d\n", SysStringByteLen(str));
4989 static void test_SysAllocString(void)
4991 const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
4994 str = SysAllocString(NULL);
4995 ok (str == NULL, "Expected NULL, got %p\n", str);
4997 str = SysAllocString(szTest);
4998 ok (str != NULL, "Expected non-NULL\n");
5001 LPINTERNAL_BSTR bstr = Get(str);
5003 ok (bstr->dwLen == 8, "Expected 8, got %d\n", bstr->dwLen);
5004 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
5009 static void test_SysAllocStringLen(void)
5011 const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
5014 /* Very early native dlls do not limit the size of strings, so skip this test */
5016 str = SysAllocStringLen(szTest, 0x80000000);
5018 ok (str == NULL, "Expected NULL, got %p\n", str);
5022 str = SysAllocStringLen(NULL, 0);
5023 ok (str != NULL, "Expected non-NULL\n");
5026 LPINTERNAL_BSTR bstr = Get(str);
5028 ok (bstr->dwLen == 0, "Expected 0, got %d\n", bstr->dwLen);
5029 ok (!bstr->szString[0], "String not empty\n");
5033 str = SysAllocStringLen(szTest, 4);
5034 ok (str != NULL, "Expected non-NULL\n");
5037 LPINTERNAL_BSTR bstr = Get(str);
5039 ok (bstr->dwLen == 8, "Expected 8, got %d\n", bstr->dwLen);
5040 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
5045 static void test_SysAllocStringByteLen(void)
5047 const OLECHAR szTest[10] = { 'T','e','s','t','\0' };
5048 const CHAR szTestA[6] = { 'T','e','s','t','\0','?' };
5051 str = SysAllocStringByteLen(szTestA, 0x80000000);
5052 ok (str == NULL, "Expected NULL, got %p\n", str);
5054 str = SysAllocStringByteLen(NULL, 0);
5055 ok (str != NULL, "Expected non-NULL\n");
5058 LPINTERNAL_BSTR bstr = Get(str);
5060 ok (bstr->dwLen == 0, "Expected 0, got %d\n", bstr->dwLen);
5061 ok (!bstr->szString[0], "String not empty\n");
5065 str = SysAllocStringByteLen(szTestA, 4);
5066 ok (str != NULL, "Expected non-NULL\n");
5069 LPINTERNAL_BSTR bstr = Get(str);
5071 ok (bstr->dwLen == 4, "Expected 4, got %d\n", bstr->dwLen);
5072 ok (!lstrcmpA((LPCSTR)bstr->szString, szTestA), "String different\n");
5076 /* Odd lengths are allocated rounded up, but truncated at the right position */
5077 str = SysAllocStringByteLen(szTestA, 3);
5078 ok (str != NULL, "Expected non-NULL\n");
5081 const CHAR szTestTruncA[4] = { 'T','e','s','\0' };
5082 LPINTERNAL_BSTR bstr = Get(str);
5084 ok (bstr->dwLen == 3, "Expected 3, got %d\n", bstr->dwLen);
5085 ok (!lstrcmpA((LPCSTR)bstr->szString, szTestTruncA), "String different\n");
5089 str = SysAllocStringByteLen((LPCSTR)szTest, 8);
5090 ok (str != NULL, "Expected non-NULL\n");
5093 LPINTERNAL_BSTR bstr = Get(str);
5095 ok (bstr->dwLen == 8, "Expected 8, got %d\n", bstr->dwLen);
5096 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
5101 static void test_SysReAllocString(void)
5103 const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
5104 const OLECHAR szSmaller[2] = { 'x','\0' };
5105 const OLECHAR szLarger[7] = { 'L','a','r','g','e','r','\0' };
5108 str = SysAllocStringLen(szTest, 4);
5109 ok (str != NULL, "Expected non-NULL\n");
5112 LPINTERNAL_BSTR bstr;
5117 ok (bstr->dwLen == 8, "Expected 8, got %d\n", bstr->dwLen);
5118 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
5120 changed = SysReAllocString(&str, szSmaller);
5121 ok (changed == 1, "Expected 1, got %d\n", changed);
5122 ok (str == oldstr, "Created new string\n");
5124 ok (bstr->dwLen == 2, "Expected 2, got %d\n", bstr->dwLen);
5125 ok (!lstrcmpW(bstr->szString, szSmaller), "String different\n");
5128 changed = SysReAllocString(&str, szLarger);
5129 ok (changed == 1, "Expected 1, got %d\n", changed);
5130 /* Early versions always make new strings rather than resizing */
5131 /* ok (str == oldstr, "Created new string\n"); */
5133 ok (bstr->dwLen == 12, "Expected 12, got %d\n", bstr->dwLen);
5134 ok (!lstrcmpW(bstr->szString, szLarger), "String different\n");
5140 static void test_SysReAllocStringLen(void)
5142 const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
5143 const OLECHAR szSmaller[2] = { 'x','\0' };
5144 const OLECHAR szLarger[7] = { 'L','a','r','g','e','r','\0' };
5147 str = SysAllocStringLen(szTest, 4);
5148 ok (str != NULL, "Expected non-NULL\n");
5151 LPINTERNAL_BSTR bstr;
5156 ok (bstr->dwLen == 8, "Expected 8, got %d\n", bstr->dwLen);
5157 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
5159 changed = SysReAllocStringLen(&str, szSmaller, 1);
5160 ok (changed == 1, "Expected 1, got %d\n", changed);
5161 ok (str == oldstr, "Created new string\n");
5163 ok (bstr->dwLen == 2, "Expected 2, got %d\n", bstr->dwLen);
5164 ok (!lstrcmpW(bstr->szString, szSmaller), "String different\n");
5167 changed = SysReAllocStringLen(&str, szLarger, 6);
5168 ok (changed == 1, "Expected 1, got %d\n", changed);
5169 /* Early versions always make new strings rather than resizing */
5170 /* ok (str == oldstr, "Created new string\n"); */
5172 ok (bstr->dwLen == 12, "Expected 12, got %d\n", bstr->dwLen);
5173 ok (!lstrcmpW(bstr->szString, szLarger), "String different\n");
5175 changed = SysReAllocStringLen(&str, str, 6);
5176 ok (changed == 1, "Expected 1, got %d\n", changed);
5182 static void test_BstrCopy(void)
5184 const CHAR szTestA[6] = { 'T','e','s','t','\0','?' };
5185 const CHAR szTestTruncA[4] = { 'T','e','s','\0' };
5186 LPINTERNAL_BSTR bstr;
5191 str = SysAllocStringByteLen(szTestA, 3);
5192 ok (str != NULL, "Expected non-NULL\n");
5195 V_VT(&vt1) = VT_BSTR;
5197 V_VT(&vt2) = VT_EMPTY;
5198 hres = VariantCopy(&vt2, &vt1);
5199 ok (hres == S_OK,"Failed to copy binary bstring with hres 0x%08x\n", hres);
5200 bstr = Get(V_BSTR(&vt2));
5201 ok (bstr->dwLen == 3, "Expected 3, got %d\n", bstr->dwLen);
5202 ok (!lstrcmpA((LPCSTR)bstr->szString, szTestTruncA), "String different\n");
5206 static void test_VarBstrCat(void)
5208 static const WCHAR sz1[] = { 'a',0 };
5209 static const WCHAR sz2[] = { 'b',0 };
5210 static const WCHAR sz1sz2[] = { 'a','b',0 };
5211 static const WCHAR s1[] = { 'a',0 };
5212 static const WCHAR s2[] = { 'b',0 };
5213 static const WCHAR s1s2[] = { 'a',0,'b',0 };
5215 BSTR str1, str2, res;
5218 ret = VarBstrCat(NULL, NULL, NULL);
5221 /* Concatenation of two NULL strings works */
5222 ret = VarBstrCat(NULL, NULL, &res);
5223 ok(ret == S_OK, "VarBstrCat failed: %08x\n", ret);
5224 ok(res != NULL, "Expected a string\n");
5225 ok(SysStringLen(res) == 0, "Expected a 0-length string\n");
5228 str1 = SysAllocString(sz1);
5230 /* Concatenation with one NULL arg */
5231 ret = VarBstrCat(NULL, str1, &res);
5232 ok(ret == S_OK, "VarBstrCat failed: %08x\n", ret);
5233 ok(res != NULL, "Expected a string\n");
5234 ok(SysStringLen(res) == SysStringLen(str1), "Unexpected length\n");
5235 ok(!memcmp(res, sz1, SysStringLen(str1)), "Unexpected value\n");
5237 ret = VarBstrCat(str1, NULL, &res);
5238 ok(ret == S_OK, "VarBstrCat failed: %08x\n", ret);
5239 ok(res != NULL, "Expected a string\n");
5240 ok(SysStringLen(res) == SysStringLen(str1), "Unexpected length\n");
5241 ok(!memcmp(res, sz1, SysStringLen(str1)), "Unexpected value\n");
5244 /* Concatenation of two zero-terminated strings */
5245 str2 = SysAllocString(sz2);
5246 ret = VarBstrCat(str1, str2, &res);
5247 ok(ret == S_OK, "VarBstrCat failed: %08x\n", ret);
5248 ok(res != NULL, "Expected a string\n");
5249 ok(SysStringLen(res) == sizeof(sz1sz2) / sizeof(WCHAR) - 1,
5250 "Unexpected length\n");
5251 ok(!memcmp(res, sz1sz2, sizeof(sz1sz2)), "Unexpected value\n");
5254 SysFreeString(str2);
5255 SysFreeString(str1);
5257 /* Concatenation of two strings with embedded NULLs */
5258 str1 = SysAllocStringLen(s1, sizeof(s1) / sizeof(WCHAR));
5259 str2 = SysAllocStringLen(s2, sizeof(s2) / sizeof(WCHAR));
5261 ret = VarBstrCat(str1, str2, &res);
5262 ok(ret == S_OK, "VarBstrCat failed: %08x\n", ret);
5263 ok(res != NULL, "Expected a string\n");
5264 ok(SysStringLen(res) == sizeof(s1s2) / sizeof(WCHAR),
5265 "Unexpected length\n");
5266 ok(!memcmp(res, s1s2, sizeof(s1s2)), "Unexpected value\n");
5269 SysFreeString(str2);
5270 SysFreeString(str1);
5275 static void test_IUnknownClear(void)
5279 DummyDispatch u = { &DummyDispatch_VTable, 1, VT_UI1, FALSE };
5280 IUnknown* pu = (IUnknown*)&u;
5282 /* Test that IUnknown_Release is called on by-value */
5283 V_VT(&v) = VT_UNKNOWN;
5284 V_UNKNOWN(&v) = (IUnknown*)&u;
5285 hres = VariantClear(&v);
5286 ok(hres == S_OK && u.ref == 0 && V_VT(&v) == VT_EMPTY,
5287 "clear unknown: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5288 S_OK, 0, VT_EMPTY, hres, u.ref, V_VT(&v));
5290 /* But not when clearing a by-reference*/
5292 V_VT(&v) = VT_UNKNOWN|VT_BYREF;
5293 V_UNKNOWNREF(&v) = &pu;
5294 hres = VariantClear(&v);
5295 ok(hres == S_OK && u.ref == 1 && V_VT(&v) == VT_EMPTY,
5296 "clear dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5297 S_OK, 1, VT_EMPTY, hres, u.ref, V_VT(&v));
5300 static void test_IUnknownCopy(void)
5303 VARIANTARG vSrc, vDst;
5304 DummyDispatch u = { &DummyDispatch_VTable, 1, VT_UI1, FALSE };
5305 IUnknown* pu = (IUnknown*)&u;
5307 /* AddRef is called on by-value copy */
5309 V_VT(&vSrc) = VT_UNKNOWN;
5310 V_UNKNOWN(&vSrc) = pu;
5311 hres = VariantCopy(&vDst, &vSrc);
5312 ok(hres == S_OK && u.ref == 2 && V_VT(&vDst) == VT_UNKNOWN,
5313 "copy unknown: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5314 S_OK, 2, VT_EMPTY, hres, u.ref, V_VT(&vDst));
5316 /* AddRef is skipped on copy of by-reference IDispatch */
5319 V_VT(&vSrc) = VT_UNKNOWN|VT_BYREF;
5320 V_UNKNOWNREF(&vSrc) = &pu;
5321 hres = VariantCopy(&vDst, &vSrc);
5322 ok(hres == S_OK && u.ref == 1 && V_VT(&vDst) == (VT_UNKNOWN|VT_BYREF),
5323 "copy unknown: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5324 S_OK, 1, VT_DISPATCH, hres, u.ref, V_VT(&vDst));
5326 /* AddRef is called copying by-reference IDispatch with indirection */
5329 V_VT(&vSrc) = VT_UNKNOWN|VT_BYREF;
5330 V_UNKNOWNREF(&vSrc) = &pu;
5331 hres = VariantCopyInd(&vDst, &vSrc);
5332 ok(hres == S_OK && u.ref == 2 && V_VT(&vDst) == VT_UNKNOWN,
5333 "copy unknown: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5334 S_OK, 2, VT_DISPATCH, hres, u.ref, V_VT(&vDst));
5336 /* Indirection in place also calls AddRef */
5338 V_VT(&vSrc) = VT_UNKNOWN|VT_BYREF;
5339 V_UNKNOWNREF(&vSrc) = &pu;
5340 hres = VariantCopyInd(&vSrc, &vSrc);
5341 ok(hres == S_OK && u.ref == 2 && V_VT(&vSrc) == VT_UNKNOWN,
5342 "copy unknown: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5343 S_OK, 2, VT_DISPATCH, hres, u.ref, V_VT(&vSrc));
5346 static void test_IUnknownChangeTypeEx(void)
5349 VARIANTARG vSrc, vDst;
5352 DummyDispatch u = { &DummyDispatch_VTable, 1, VT_UI1, FALSE };
5353 IUnknown* pu = (IUnknown*)&u;
5355 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5357 V_VT(&vSrc) = VT_UNKNOWN;
5358 V_UNKNOWN(&vSrc) = pu;
5360 /* =>IDispatch in place */
5361 hres = VariantChangeTypeEx(&vSrc, &vSrc, lcid, 0, VT_DISPATCH);
5362 ok(hres == S_OK && u.ref == 1 &&
5363 V_VT(&vSrc) == VT_DISPATCH && V_DISPATCH(&vSrc) == (IDispatch*)pu,
5364 "change unk(src=src): expected 0x%08x,%d,%d,%p, got 0x%08x,%d,%d,%p\n",
5365 S_OK, 1, VT_DISPATCH, pu, hres, u.ref, V_VT(&vSrc), V_DISPATCH(&vSrc));
5369 V_VT(&vSrc) = VT_UNKNOWN;
5370 V_UNKNOWN(&vSrc) = (IUnknown*)pu;
5372 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, VT_UNKNOWN);
5373 /* Note vSrc is not cleared, as final refcount is 2 */
5374 ok(hres == S_OK && u.ref == 2 &&
5375 V_VT(&vDst) == VT_UNKNOWN && V_UNKNOWN(&vDst) == (IUnknown*)pu,
5376 "change unk(src,dst): expected 0x%08x,%d,%d,%p, got 0x%08x,%d,%d,%p\n",
5377 S_OK, 2, VT_UNKNOWN, pu, hres, u.ref, V_VT(&vDst), V_UNKNOWN(&vDst));
5379 /* Can't change unknown to anything else */
5380 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
5382 HRESULT hExpected = DISP_E_BADVARTYPE;
5384 V_VT(&vSrc) = VT_UNKNOWN;
5385 V_UNKNOWN(&vSrc) = (IUnknown*)pu;
5388 if (vt == VT_UNKNOWN || vt == VT_DISPATCH || vt == VT_EMPTY || vt == VT_NULL)
5392 if (vt == VT_I8 || vt == VT_UI8)
5394 if (HAVE_OLEAUT32_I8)
5395 hExpected = DISP_E_TYPEMISMATCH;
5397 else if (vt == VT_RECORD)
5399 if (HAVE_OLEAUT32_RECORD)
5400 hExpected = DISP_E_TYPEMISMATCH;
5402 else if (vt >= VT_I2 && vt <= VT_UINT && vt != (VARTYPE)15)
5403 hExpected = DISP_E_TYPEMISMATCH;
5405 if (IS_ANCIENT && IS_MODERN_VTYPE(vt))
5406 hExpected = DISP_E_BADVARTYPE;
5408 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, vt);
5409 ok(hres == hExpected,
5410 "change unk(badvar): vt %d expected 0x%08x, got 0x%08x\n",
5411 vt, hExpected, hres);
5416 static void test_IDispatchClear(void)
5420 DummyDispatch d = { &DummyDispatch_VTable, 1, VT_UI1, FALSE };
5421 IDispatch* pd = (IDispatch*)&d;
5423 /* As per IUnknown */
5425 V_VT(&v) = VT_DISPATCH;
5426 V_DISPATCH(&v) = pd;
5427 hres = VariantClear(&v);
5428 ok(hres == S_OK && d.ref == 0 && V_VT(&v) == VT_EMPTY,
5429 "clear dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5430 S_OK, 0, VT_EMPTY, hres, d.ref, V_VT(&v));
5433 V_VT(&v) = VT_DISPATCH|VT_BYREF;
5434 V_DISPATCHREF(&v) = &pd;
5435 hres = VariantClear(&v);
5436 ok(hres == S_OK && d.ref == 1 && V_VT(&v) == VT_EMPTY,
5437 "clear dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5438 S_OK, 1, VT_EMPTY, hres, d.ref, V_VT(&v));
5441 static void test_IDispatchCopy(void)
5444 VARIANTARG vSrc, vDst;
5445 DummyDispatch d = { &DummyDispatch_VTable, 1, VT_UI1, FALSE };
5446 IDispatch* pd = (IDispatch*)&d;
5448 /* As per IUnknown */
5451 V_VT(&vSrc) = VT_DISPATCH;
5452 V_DISPATCH(&vSrc) = pd;
5453 hres = VariantCopy(&vDst, &vSrc);
5454 ok(hres == S_OK && d.ref == 2 && V_VT(&vDst) == VT_DISPATCH,
5455 "copy dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5456 S_OK, 2, VT_EMPTY, hres, d.ref, V_VT(&vDst));
5460 V_VT(&vSrc) = VT_DISPATCH|VT_BYREF;
5461 V_DISPATCHREF(&vSrc) = &pd;
5462 hres = VariantCopy(&vDst, &vSrc);
5463 ok(hres == S_OK && d.ref == 1 && V_VT(&vDst) == (VT_DISPATCH|VT_BYREF),
5464 "copy dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5465 S_OK, 1, VT_DISPATCH, hres, d.ref, V_VT(&vDst));
5469 V_VT(&vSrc) = VT_DISPATCH|VT_BYREF;
5470 V_DISPATCHREF(&vSrc) = &pd;
5471 hres = VariantCopyInd(&vDst, &vSrc);
5472 ok(hres == S_OK && d.ref == 2 && V_VT(&vDst) == VT_DISPATCH,
5473 "copy dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5474 S_OK, 2, VT_DISPATCH, hres, d.ref, V_VT(&vDst));
5477 V_VT(&vSrc) = VT_DISPATCH|VT_BYREF;
5478 V_DISPATCHREF(&vSrc) = &pd;
5479 hres = VariantCopyInd(&vSrc, &vSrc);
5480 ok(hres == S_OK && d.ref == 2 && V_VT(&vSrc) == VT_DISPATCH,
5481 "copy dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5482 S_OK, 2, VT_DISPATCH, hres, d.ref, V_VT(&vSrc));
5485 static void test_IDispatchChangeTypeEx(void)
5488 VARIANTARG vSrc, vDst;
5490 DummyDispatch d = { &DummyDispatch_VTable, 1, VT_UI1, FALSE };
5491 IDispatch* pd = (IDispatch*)&d;
5493 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5495 V_VT(&vSrc) = VT_DISPATCH;
5496 V_DISPATCH(&vSrc) = pd;
5498 /* =>IUnknown in place */
5499 hres = VariantChangeTypeEx(&vSrc, &vSrc, lcid, 0, VT_UNKNOWN);
5500 ok(hres == S_OK && d.ref == 1 &&
5501 V_VT(&vSrc) == VT_UNKNOWN && V_UNKNOWN(&vSrc) == (IUnknown*)pd,
5502 "change disp(src=src): expected 0x%08x,%d,%d,%p, got 0x%08x,%d,%d,%p\n",
5503 S_OK, 1, VT_UNKNOWN, pd, hres, d.ref, V_VT(&vSrc), V_UNKNOWN(&vSrc));
5507 V_VT(&vSrc) = VT_DISPATCH;
5508 V_DISPATCH(&vSrc) = pd;
5510 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, VT_UNKNOWN);
5511 /* Note vSrc is not cleared, as final refcount is 2 */
5512 ok(hres == S_OK && d.ref == 2 &&
5513 V_VT(&vDst) == VT_UNKNOWN && V_UNKNOWN(&vDst) == (IUnknown*)pd,
5514 "change disp(src,dst): expected 0x%08x,%d,%d,%p, got 0x%08x,%d,%d,%p\n",
5515 S_OK, 2, VT_UNKNOWN, pd, hres, d.ref, V_VT(&vDst), V_UNKNOWN(&vDst));
5517 /* FIXME: Verify that VARIANT_NOVALUEPROP prevents conversion to integral
5518 * types. this requires that the xxxFromDisp tests work first.
5523 static void test_ErrorChangeTypeEx(void)
5526 VARIANTARG vSrc, vDst;
5530 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5532 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
5534 HRESULT hExpected = DISP_E_BADVARTYPE;
5536 V_VT(&vSrc) = VT_ERROR;
5539 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, vt);
5545 if (vt == VT_I8 || vt == VT_UI8)
5547 if (HAVE_OLEAUT32_I8)
5548 hExpected = DISP_E_TYPEMISMATCH;
5550 else if (vt == VT_RECORD)
5552 if (HAVE_OLEAUT32_RECORD)
5553 hExpected = DISP_E_TYPEMISMATCH;
5555 else if (vt <= VT_UINT && vt != (VARTYPE)15)
5556 hExpected = DISP_E_TYPEMISMATCH;
5558 if (IS_ANCIENT && IS_MODERN_VTYPE(vt))
5559 hExpected = DISP_E_BADVARTYPE;
5561 ok(hres == hExpected,
5562 "change err: vt %d expected 0x%08x, got 0x%08x\n", vt, hExpected, hres);
5567 static void test_EmptyChangeTypeEx(void)
5570 VARIANTARG vSrc, vDst;
5574 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5576 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
5578 HRESULT hExpected = DISP_E_BADVARTYPE;
5581 memset(&vDst, 0, sizeof(vDst));
5582 V_VT(&vDst) = VT_EMPTY;
5584 if (vt == VT_I8 || vt == VT_UI8)
5586 if (HAVE_OLEAUT32_I8)
5589 else if (vt == VT_RECORD)
5591 if (HAVE_OLEAUT32_RECORD)
5592 hExpected = DISP_E_TYPEMISMATCH;
5594 else if (vt == VT_VARIANT || vt == VT_DISPATCH ||
5595 vt == VT_UNKNOWN || vt == VT_ERROR)
5597 hExpected = DISP_E_TYPEMISMATCH;
5599 else if (vt <= VT_UINT && vt != (VARTYPE)15)
5602 if (IS_ANCIENT && IS_MODERN_VTYPE(vt))
5603 hExpected = DISP_E_BADVARTYPE;
5605 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, vt);
5607 ok(hres == hExpected && (hres != S_OK || V_VT(&vDst) == vt),
5608 "change empty: vt %d expected 0x%08x, got 0x%08x, vt %d\n",
5609 vt, hExpected, hres, V_VT(&vDst));
5614 static void test_NullChangeTypeEx(void)
5617 VARIANTARG vSrc, vDst;
5621 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5623 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
5625 HRESULT hExpected = DISP_E_BADVARTYPE;
5628 V_VT(&vSrc) = VT_NULL;
5629 memset(&vDst, 0, sizeof(vDst));
5630 V_VT(&vDst) = VT_EMPTY;
5632 if (vt == VT_I8 || vt == VT_UI8)
5634 if (HAVE_OLEAUT32_I8)
5635 hExpected = DISP_E_TYPEMISMATCH;
5637 else if (vt == VT_RECORD)
5639 if (HAVE_OLEAUT32_RECORD)
5640 hExpected = DISP_E_TYPEMISMATCH;
5642 else if (vt == VT_NULL)
5646 else if (vt == VT_VARIANT || vt == VT_DISPATCH ||
5647 vt == VT_UNKNOWN || vt == VT_ERROR ||
5648 (vt <= VT_UINT && vt != (VARTYPE)15))
5649 hExpected = DISP_E_TYPEMISMATCH;
5651 if (IS_ANCIENT && IS_MODERN_VTYPE(vt))
5652 hExpected = DISP_E_BADVARTYPE;
5654 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, vt);
5656 ok(hres == hExpected && (hres != S_OK || V_VT(&vDst) == vt),
5657 "change null: vt %d expected 0x%08x, got 0x%08x, vt %d\n",
5658 vt, hExpected, hres, V_VT(&vDst));
5664 static void test_UintChangeTypeEx(void)
5667 VARIANTARG vSrc, vDst;
5670 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5672 /* Converting a VT_UINT to a VT_INT does not check for overflow */
5673 V_VT(&vDst) = VT_EMPTY;
5674 V_VT(&vSrc) = VT_UINT;
5676 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, VT_I4);
5677 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == -1,
5678 "change uint: Expected %d,0x%08x,%d got %d,0x%08x,%d\n",
5679 VT_I4, S_OK, -1, V_VT(&vDst), hres, V_I4(&vDst));
5682 #define NUM_CUST_ITEMS 16
5684 static void test_ClearCustData(void)
5686 WCHAR buff[sizeof(CUSTDATAITEM) * NUM_CUST_ITEMS / sizeof(WCHAR)];
5690 CHECKPTR(ClearCustData);
5692 memset(buff, 0, sizeof(buff));
5694 ci.cCustData = NUM_CUST_ITEMS;
5695 /* This is a bit tricky. We use SysAllocStringByteLen to allocate the
5696 * array, since native uses an internal IMalloc interface for allocating
5697 * its memory, while Wine uses HeapAlloc(). Doing this ensures we allocate
5698 * using the correct function whether with native or builtin.
5700 ci.prgCustData = (LPCUSTDATAITEM)SysAllocStringByteLen((LPCSTR)buff, sizeof(buff));
5701 for (i = 0; i < NUM_CUST_ITEMS; i++)
5702 VariantInit(&ci.prgCustData[i].varValue);
5703 pClearCustData(&ci);
5704 ok(!ci.cCustData && !ci.prgCustData, "ClearCustData didn't clear fields!\n");
5707 static void test_NullByRef(void)
5714 V_VT(&v1) = VT_BYREF|VT_VARIANT;
5717 hRes = VariantChangeTypeEx(&v2, &v1, 0, 0, VT_I4);
5718 ok(hRes == DISP_E_TYPEMISMATCH, "VariantChangeTypeEx should return DISP_E_TYPEMISMATCH\n");
5721 V_VT(&v1) = VT_BYREF|VT_VARIANT;
5726 hRes = VariantChangeTypeEx(&v2, &v1, 0, 0, VT_VARIANT);
5727 ok(hRes == DISP_E_TYPEMISMATCH, "VariantChangeTypeEx should return DISP_E_TYPEMISMATCH\n");
5728 ok(V_VT(&v2) == VT_I4 && V_I4(&v2) == 123, "VariantChangeTypeEx shouldn't change pvargDest\n");
5730 hRes = VariantChangeTypeEx(&v2, &v1, 0, 0, VT_BYREF|VT_I4);
5731 ok(hRes == DISP_E_TYPEMISMATCH, "VariantChangeTypeEx should return DISP_E_TYPEMISMATCH\n");
5733 hRes = VariantChangeTypeEx(&v2, &v1, 0, 0, 0x3847);
5734 ok(hRes == DISP_E_BADVARTYPE, "VariantChangeTypeEx should return DISP_E_BADVARTYPE\n");
5737 /* Dst Variant should remain unchanged if VariantChangeType cannot convert */
5738 static void test_ChangeType_keep_dst(void)
5742 static const WCHAR testW[] = {'t','e','s','t',0};
5745 bstr = SysAllocString(testW);
5748 V_VT(&v1) = VT_BSTR;
5750 hres = VariantChangeTypeEx(&v1, &v1, 0, 0, VT_INT);
5751 ok(hres == DISP_E_TYPEMISMATCH, "VariantChangeTypeEx returns %08x\n", hres);
5752 ok(V_VT(&v1) == VT_BSTR && V_BSTR(&v1) == bstr, "VariantChangeTypeEx changed dst variant\n");
5755 hres = VariantChangeTypeEx(&v2, &v1, 0, 0, VT_INT);
5756 ok(hres == DISP_E_TYPEMISMATCH, "VariantChangeTypeEx returns %08x\n", hres);
5757 ok(V_VT(&v2) == VT_INT && V_INT(&v2) == 4, "VariantChangeTypeEx changed dst variant\n");
5758 SysFreeString(bstr);
5763 hOleaut32 = LoadLibraryA("oleaut32.dll");
5764 ok(hOleaut32 != 0, "Failed to load oleaut32.dll\n");
5768 trace("LCID's: System=0x%08x, User=0x%08x\n", GetSystemDefaultLCID(),
5769 GetUserDefaultLCID());
5774 test_VarI1FromUI1();
5775 test_VarI1FromUI2();
5776 test_VarI1FromUI4();
5777 test_VarI1FromUI8();
5778 test_VarI1FromBool();
5781 test_VarI1FromDate();
5783 test_VarI1FromDec();
5784 test_VarI1FromStr();
5785 test_VarUI1FromDisp();
5787 test_VarI1ChangeTypeEx();
5789 test_VarUI1FromI1();
5790 test_VarUI1FromI2();
5791 test_VarUI1FromI4();
5792 test_VarUI1FromI8();
5793 test_VarUI1FromUI2();
5794 test_VarUI1FromUI4();
5795 test_VarUI1FromUI8();
5796 test_VarUI1FromBool();
5797 test_VarUI1FromR4();
5798 test_VarUI1FromR8();
5799 test_VarUI1FromDate();
5800 test_VarUI1FromCy();
5801 test_VarUI1FromDec();
5802 test_VarUI1FromStr();
5804 test_VarUI1ChangeTypeEx();
5809 test_VarI2FromUI1();
5810 test_VarI2FromUI2();
5811 test_VarI2FromUI4();
5812 test_VarI2FromUI8();
5813 test_VarI2FromBool();
5816 test_VarI2FromDate();
5818 test_VarI2FromDec();
5819 test_VarI2FromStr();
5821 test_VarI2ChangeTypeEx();
5823 test_VarUI2FromI1();
5824 test_VarUI2FromI2();
5825 test_VarUI2FromI4();
5826 test_VarUI2FromI8();
5827 test_VarUI2FromUI1();
5828 test_VarUI2FromUI4();
5829 test_VarUI2FromUI8();
5830 test_VarUI2FromBool();
5831 test_VarUI2FromR4();
5832 test_VarUI2FromR8();
5833 test_VarUI2FromDate();
5834 test_VarUI2FromCy();
5835 test_VarUI2FromDec();
5836 test_VarUI2FromStr();
5838 test_VarUI2ChangeTypeEx();
5843 test_VarI4FromUI1();
5844 test_VarI4FromUI2();
5845 test_VarI4FromUI4();
5846 test_VarI4FromUI8();
5847 test_VarI4FromBool();
5850 test_VarI4FromDate();
5852 test_VarI4FromDec();
5853 test_VarI4FromStr();
5855 test_VarI4ChangeTypeEx();
5857 test_VarUI4FromI1();
5858 test_VarUI4FromI2();
5859 test_VarUI4FromUI2();
5860 test_VarUI4FromI8();
5861 test_VarUI4FromUI1();
5862 test_VarUI4FromI4();
5863 test_VarUI4FromUI8();
5864 test_VarUI4FromBool();
5865 test_VarUI4FromR4();
5866 test_VarUI4FromR8();
5867 test_VarUI4FromDate();
5868 test_VarUI4FromCy();
5869 test_VarUI4FromDec();
5870 test_VarUI4FromStr();
5872 test_VarUI4ChangeTypeEx();
5875 test_VarI8FromUI1();
5877 test_VarI8FromUI2();
5878 test_VarI8FromUI4();
5881 test_VarI8FromBool();
5882 test_VarI8FromUI8();
5884 test_VarI8FromDec();
5885 test_VarI8FromDate();
5886 test_VarI8FromStr();
5888 test_VarI8ChangeTypeEx();
5890 test_VarUI8FromI1();
5891 test_VarUI8FromUI1();
5892 test_VarUI8FromI2();
5893 test_VarUI8FromUI2();
5894 test_VarUI8FromUI4();
5895 test_VarUI8FromR4();
5896 test_VarUI8FromR8();
5897 test_VarUI8FromBool();
5898 test_VarUI8FromI8();
5899 test_VarUI8FromCy();
5900 test_VarUI8FromDec();
5901 test_VarUI8FromDate();
5902 test_VarUI8FromStr();
5904 test_VarUI8ChangeTypeEx();
5907 test_VarR4FromUI1();
5909 test_VarR4FromUI2();
5911 test_VarR4FromUI4();
5913 test_VarR4FromBool();
5916 test_VarR4FromUI8();
5917 test_VarR4FromDec();
5918 test_VarR4FromDate();
5919 test_VarR4FromStr();
5921 test_VarR4ChangeTypeEx();
5924 test_VarR8FromUI1();
5926 test_VarR8FromUI2();
5928 test_VarR8FromUI4();
5930 test_VarR8FromBool();
5933 test_VarR8FromUI8();
5934 test_VarR8FromDec();
5935 test_VarR8FromDate();
5936 test_VarR8FromStr();
5938 test_VarR8ChangeTypeEx();
5941 test_VarDateFromI1();
5942 test_VarDateFromUI1();
5943 test_VarDateFromI2();
5944 test_VarDateFromUI2();
5945 test_VarDateFromI4();
5946 test_VarDateFromUI4();
5947 test_VarDateFromR4();
5948 test_VarDateFromR8();
5949 test_VarDateFromBool();
5950 test_VarDateFromCy();
5951 test_VarDateFromI8();
5952 test_VarDateFromUI8();
5953 test_VarDateFromDec();
5954 test_VarDateFromStr();
5956 test_VarDateChangeTypeEx();
5959 test_VarCyFromUI1();
5961 test_VarCyFromUI2();
5963 test_VarCyFromUI4();
5966 test_VarCyFromBool();
5968 test_VarCyFromUI8();
5969 test_VarCyFromDec();
5970 test_VarCyFromDate();
5985 test_VarDecFromI1();
5986 test_VarDecFromI2();
5987 test_VarDecFromI4();
5988 test_VarDecFromI8();
5989 test_VarDecFromUI1();
5990 test_VarDecFromUI2();
5991 test_VarDecFromUI4();
5992 test_VarDecFromUI8();
5993 test_VarDecFromR4();
5994 test_VarDecFromR8();
5995 test_VarDecFromDate();
5996 test_VarDecFromStr();
5997 test_VarDecFromCy();
5998 test_VarDecFromDate();
5999 test_VarDecFromBool();
6009 test_VarBoolFromI1();
6010 test_VarBoolFromUI1();
6011 test_VarBoolFromI2();
6012 test_VarBoolFromUI2();
6013 test_VarBoolFromI4();
6014 test_VarBoolFromUI4();
6015 test_VarBoolFromR4();
6016 test_VarBoolFromR8();
6017 test_VarBoolFromCy();
6018 test_VarBoolFromI8();
6019 test_VarBoolFromUI8();
6020 test_VarBoolFromDec();
6021 test_VarBoolFromDate();
6022 test_VarBoolFromStr();
6024 test_VarBoolChangeTypeEx();
6026 test_VarBstrFromR4();
6027 test_VarBstrFromDate();
6028 test_VarBstrFromDec();
6030 test_SysStringLen();
6031 test_SysStringByteLen();
6032 test_SysAllocString();
6033 test_SysAllocStringLen();
6034 test_SysAllocStringByteLen();
6035 test_SysReAllocString();
6036 test_SysReAllocStringLen();
6040 test_IUnknownClear();
6041 test_IUnknownCopy();
6042 test_IUnknownChangeTypeEx();
6044 test_IDispatchClear();
6045 test_IDispatchCopy();
6046 test_IDispatchChangeTypeEx();
6048 test_ErrorChangeTypeEx();
6049 test_EmptyChangeTypeEx();
6050 test_NullChangeTypeEx();
6051 test_UintChangeTypeEx();
6053 test_ClearCustData();
6056 test_ChangeType_keep_dst();