Get rid of the non-standard ICOM_VFIELD macro.
[wine.git] / dlls / oleaut32 / tests / vartype.c
blobce5429ea938dae7370608585e3fa4f85c57b2299
1 /*
2 * Low level variant tests
4 * Copyright 2003 Jon Griffiths
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #define NONAMELESSUNION
21 #define NONAMELESSSTRUCT
22 #include "wine/test.h"
23 #include "wine/unicode.h"
24 #include "oleauto.h"
25 #include <math.h>
27 static HMODULE hOleaut32;
29 /* Get a conversion function ptr, return if function not available */
30 #define CHECKPTR(func) p##func = (void*)GetProcAddress(hOleaut32, #func); \
31 if (!p##func) { \
32 trace("function " # func " not available, not testing it\n"); return; }
34 /* Is a given function exported from oleaut32? */
35 #define HAVE_FUNC(func) ((void*)GetProcAddress(hOleaut32, #func) != NULL)
37 /* Have IRecordInfo data type? */
38 #define HAVE_OLEAUT32_RECORD HAVE_FUNC(SafeArraySetRecordInfo)
39 /* Have DECIMAL data type with new error checking? */
40 #define HAVE_OLEAUT32_DECIMAL HAVE_FUNC(VarDecAdd)
41 /* Have CY data type? */
42 #define HAVE_OLEAUT32_CY HAVE_FUNC(VarCyAdd)
43 /* Have I8/UI8 data type? */
44 #define HAVE_OLEAUT32_I8 HAVE_FUNC(VarI8FromI1)
45 /* Have proper locale conversions? */
46 #define HAVE_OLEAUT32_LOCALES (HAVE_FUNC(GetVarConversionLocaleSetting) && HAVE_OLEAUT32_I8)
47 /* Is this an ancient version with support for only I2/I4/R4/R8/DATE? */
48 #define IS_ANCIENT (!HAVE_FUNC(VarI1FromI2))
49 /* Is vt a type unavailable to ancient versions? */
50 #define IS_MODERN_VTYPE(vt) (vt==VT_VARIANT||vt==VT_DECIMAL|| \
51 vt==VT_I1||vt==VT_UI2||vt==VT_UI4||vt == VT_INT||vt == VT_UINT)
53 /* Macros for converting and testing results */
54 #define CONVVARS(typ) HRESULT hres; CONV_TYPE out; typ in
56 #define _EXPECTRES(res, x, fs) \
57 ok((hres == S_OK && out == (CONV_TYPE)(x)) || ((HRESULT)res != S_OK && hres == (HRESULT)res), \
58 "expected " #x ", got " fs "; hres=0x%08lx\n", out, hres)
59 #define EXPECT(x) EXPECTRES(S_OK, (x))
60 #define EXPECT_OVERFLOW EXPECTRES(DISP_E_OVERFLOW, DISP_E_OVERFLOW)
61 #define EXPECT_MISMATCH EXPECTRES(DISP_E_TYPEMISMATCH,DISP_E_TYPEMISMATCH)
62 #define EXPECT_BADVAR EXPECTRES(DISP_E_BADVARTYPE, DISP_E_BADVARTYPE)
63 #define EXPECT_INVALID EXPECTRES(E_INVALIDARG, E_INVALIDARG)
64 #define EXPECT_LT EXPECTRES(VARCMP_LT, VARCMP_LT)
65 #define EXPECT_GT EXPECTRES(VARCMP_GT, VARCMP_GT)
66 #define EXPECT_EQ EXPECTRES(VARCMP_EQ, VARCMP_EQ)
67 #define EXPECT_DBL(x) \
68 ok(hres == S_OK && fabs(out-(x))<1e-14, "expected " #x ", got %16.16g; hres=0x%08lx\n", out, hres)
70 #define CONVERT(func, val) in = val; hres = p##func(in, &out)
71 #define CONVERTRANGE(func,start,end) for (i = start; i < end; i+=1) { CONVERT(func, i); EXPECT(i); };
72 #define OVERFLOWRANGE(func,start,end) for (i = start; i < end; i+=1) { CONVERT(func, i); EXPECT_OVERFLOW; };
74 #define CY_MULTIPLIER 10000
76 #define DATE_MIN -657434
77 #define DATE_MAX 2958465
79 #define CONVERT_I8(func,hi,lo) in = hi; in = (in << 32) | lo; hres = p##func(in, &out)
81 #define CONVERT_CY(func,val) in.int64 = (LONGLONG)(val * CY_MULTIPLIER); hres = p##func(in, &out)
83 #define CONVERT_CY64(func,hi,lo) in.s.Hi = hi; in.s.Lo = lo; in.int64 *= CY_MULTIPLIER; hres = p##func(in, &out)
85 #define SETDEC(dec, scl, sgn, hi, lo) dec.u.s.scale = (BYTE)scl; dec.u.s.sign = (BYTE)sgn; \
86 dec.Hi32 = (ULONG)hi; dec.u1.Lo64 = (ULONG64)lo
88 #define SETDEC64(dec, scl, sgn, hi, mid, lo) dec.u.s.scale = (BYTE)scl; dec.u.s.sign = (BYTE)sgn; \
89 dec.Hi32 = (ULONG)hi; dec.u1.s1.Mid32 = mid; dec.u1.s1.Lo32 = lo;
91 #define CONVERT_DEC(func,scl,sgn,hi,lo) SETDEC(in,scl,sgn,hi,lo); hres = p##func(&in, &out)
93 #define CONVERT_DEC64(func,scl,sgn,hi,mid,lo) SETDEC64(in,scl,sgn,hi,mid,lo); hres = p##func(&in, &out)
95 #define CONVERT_BADDEC(func) \
96 if (HAVE_OLEAUT32_DECIMAL) \
97 { \
98 CONVERT_DEC(func,29,0,0,0); EXPECT_INVALID; \
99 CONVERT_DEC(func,0,0x1,0,0); EXPECT_INVALID; \
100 CONVERT_DEC(func,0,0x40,0,0); EXPECT_INVALID; \
101 CONVERT_DEC(func,0,0x7f,0,0); EXPECT_INVALID; \
104 #define CONVERT_STR(func,str,flags) \
105 SetLastError(0); \
106 if (str) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)); \
107 hres = p##func(str ? buff : NULL,in,flags,&out)
109 #define COPYTEST(val, vt, srcval, dstval, srcref, dstref, fs) do { \
110 HRESULT hres; VARIANTARG vSrc, vDst; CONV_TYPE in = val; \
111 VariantInit(&vSrc); VariantInit(&vDst); \
112 V_VT(&vSrc) = vt; srcval = in; \
113 hres = VariantCopy(&vDst, &vSrc); \
114 ok(hres == S_OK && V_VT(&vDst) == vt && dstval == in, \
115 "copy hres 0x%lX, type %d, value (" fs ") " fs "\n", hres, V_VT(&vDst), val, dstval); \
116 V_VT(&vSrc) = vt|VT_BYREF; srcref = &in; \
117 hres = VariantCopy(&vDst, &vSrc); \
118 ok(hres == S_OK && V_VT(&vDst) == (vt|VT_BYREF) && dstref == &in, \
119 "ref hres 0x%lX, type %d, ref (%p) %p\n", hres, V_VT(&vDst), &in, dstref); \
120 hres = VariantCopyInd(&vDst, &vSrc); \
121 ok(hres == S_OK && V_VT(&vDst) == vt && dstval == in, \
122 "ind hres 0x%lX, type %d, value (" fs ") " fs "\n", hres, V_VT(&vDst), val, dstval); \
123 } while(0)
125 #define CHANGETYPEEX(typ) hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, typ)
127 #define TYPETEST(typ,res,fs) CHANGETYPEEX(typ); \
128 ok(hres == S_OK && V_VT(&vDst) == typ && (CONV_TYPE)res == in, \
129 "hres=0x%lX, type=%d (should be %d(" #typ ")), value=" fs " (should be 1)\n", \
130 hres, V_VT(&vDst), typ, (CONV_TYPE)res);
131 #define TYPETESTI8(typ,res) CHANGETYPEEX(typ); \
132 ok(hres == S_OK && V_VT(&vDst) == typ && (CONV_TYPE)res == in, \
133 "hres=0x%lX, type=%d (should be %d(" #typ ")), value=%d (should be 1)\n", \
134 hres, V_VT(&vDst), typ, (int)res);
135 #define BADVAR(typ) CHANGETYPEEX(typ); out = (CONV_TYPE)hres; EXPECT_BADVAR
136 #define MISMATCH(typ) CHANGETYPEEX(typ); out = (CONV_TYPE)hres; EXPECT_MISMATCH
138 #define INITIAL_TYPETEST(vt, val, fs) \
139 VariantInit(&vSrc); \
140 VariantInit(&vDst); \
141 V_VT(&vSrc) = vt; \
142 (val(&vSrc)) = in; \
143 if (!IS_ANCIENT) { \
144 TYPETEST(VT_I1, V_I1(&vDst), fs); \
145 TYPETEST(VT_UI2, V_UI2(&vDst), fs); \
146 TYPETEST(VT_UI4, V_UI4(&vDst), fs); \
147 TYPETEST(VT_INT, V_INT(&vDst), fs); \
148 TYPETEST(VT_UINT, V_UINT(&vDst), fs); \
149 } else { \
150 BADVAR(VT_I1); BADVAR(VT_UI2); BADVAR(VT_UI4); \
151 BADVAR(VT_INT); BADVAR(VT_UINT); \
153 TYPETEST(VT_UI1, V_UI1(&vDst), fs); \
154 TYPETEST(VT_I2, V_I2(&vDst), fs); \
155 TYPETEST(VT_I4, V_I4(&vDst), fs); \
156 TYPETEST(VT_R4, V_R4(&vDst), fs); \
157 TYPETEST(VT_R8, V_R8(&vDst), fs); \
158 TYPETEST(VT_DATE, V_DATE(&vDst), fs); \
159 if (HAVE_OLEAUT32_I8) \
161 TYPETEST(VT_I8, V_I8(&vDst), fs); \
162 TYPETEST(VT_UI8, V_UI8(&vDst), fs); \
165 #define INITIAL_TYPETESTI8(vt, val) \
166 VariantInit(&vSrc); \
167 VariantInit(&vDst); \
168 V_VT(&vSrc) = vt; \
169 (val(&vSrc)) = in; \
170 TYPETESTI8(VT_I1, V_I1(&vDst)); \
171 TYPETESTI8(VT_UI1, V_UI1(&vDst)); \
172 TYPETESTI8(VT_I2, V_I2(&vDst)); \
173 TYPETESTI8(VT_UI2, V_UI2(&vDst)); \
174 TYPETESTI8(VT_I4, V_I4(&vDst)); \
175 TYPETESTI8(VT_UI4, V_UI4(&vDst)); \
176 TYPETESTI8(VT_INT, V_INT(&vDst)); \
177 TYPETESTI8(VT_UINT, V_UINT(&vDst)); \
178 TYPETESTI8(VT_R4, V_R4(&vDst)); \
179 TYPETESTI8(VT_R8, V_R8(&vDst)); \
180 TYPETESTI8(VT_DATE, V_DATE(&vDst)); \
181 TYPETESTI8(VT_I8, V_I8(&vDst)); \
182 TYPETESTI8(VT_UI8, V_UI8(&vDst))
184 #define COMMON_TYPETEST \
185 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_BOOL); \
186 ok(hres == S_OK && V_VT(&vDst) == VT_BOOL && \
187 (V_BOOL(&vDst) == VARIANT_TRUE || (V_VT(&vSrc) == VT_BOOL && V_BOOL(&vDst) == 1)), \
188 "->VT_BOOL hres=0x%lX, type=%d (should be VT_BOOL), value %d (should be VARIANT_TRUE)\n", \
189 hres, V_VT(&vDst), V_BOOL(&vDst)); \
190 if (HAVE_OLEAUT32_CY) \
192 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_CY); \
193 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == CY_MULTIPLIER, \
194 "->VT_CY hres=0x%lX, type=%d (should be VT_CY), value (%08lx,%08lx) (should be CY_MULTIPLIER)\n", \
195 hres, V_VT(&vDst), V_CY(&vDst).s.Hi, V_CY(&vDst).s.Lo); \
197 if (V_VT(&vSrc) != VT_DATE) \
199 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_BSTR); \
200 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && \
201 V_BSTR(&vDst) && V_BSTR(&vDst)[0] == '1' && V_BSTR(&vDst)[1] == '\0', \
202 "->VT_BSTR hres=0x%lX, type=%d (should be VT_BSTR), *bstr='%c'\n", \
203 hres, V_VT(&vDst), V_BSTR(&vDst) ? *V_BSTR(&vDst) : '?'); \
205 if (HAVE_OLEAUT32_DECIMAL) \
207 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_DECIMAL); \
208 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && \
209 V_DECIMAL(&vDst).u.s.sign == 0 && V_DECIMAL(&vDst).u.s.scale == 0 && \
210 V_DECIMAL(&vDst).Hi32 == 0 && V_DECIMAL(&vDst).u1.Lo64 == (ULONGLONG)in, \
211 "->VT_DECIMAL hres=0x%lX, type=%d (should be VT_DECIMAL), sign=%d, scale=%d, hi=%lu, lo=(%8lx %8lx),\n", \
212 hres, V_VT(&vDst), V_DECIMAL(&vDst).u.s.sign, V_DECIMAL(&vDst).u.s.scale, \
213 V_DECIMAL(&vDst).Hi32, V_DECIMAL(&vDst).u1.s1.Mid32, V_DECIMAL(&vDst).u1.s1.Lo32); \
215 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_EMPTY); \
216 ok(hres == S_OK && V_VT(&vDst) == VT_EMPTY, "->VT_EMPTY hres=0x%lX, type=%d (should be VT_EMPTY)\n", hres, V_VT(&vDst)); \
217 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_NULL); \
218 ok(hres == S_OK && V_VT(&vDst) == VT_NULL, "->VT_NULL hres=0x%lX, type=%d (should be VT_NULL)\n", hres, V_VT(&vDst)); \
219 MISMATCH(VT_DISPATCH); \
220 MISMATCH(VT_ERROR); \
221 MISMATCH(VT_UNKNOWN); \
222 if (!IS_ANCIENT) { MISMATCH(VT_VARIANT); } else { BADVAR(VT_VARIANT); } \
223 if (HAVE_OLEAUT32_RECORD) \
225 MISMATCH(VT_RECORD); \
227 BADVAR(VT_VOID); \
228 BADVAR(VT_HRESULT); \
229 BADVAR(VT_SAFEARRAY); \
230 BADVAR(VT_CARRAY); \
231 BADVAR(VT_USERDEFINED); \
232 BADVAR(VT_LPSTR); \
233 BADVAR(VT_LPWSTR); \
234 BADVAR(VT_PTR); \
235 BADVAR(VT_INT_PTR); \
236 BADVAR(VT_UINT_PTR); \
237 BADVAR(VT_FILETIME); \
238 BADVAR(VT_BLOB); \
239 BADVAR(VT_STREAM); \
240 BADVAR(VT_STORAGE); \
241 BADVAR(VT_STREAMED_OBJECT); \
242 BADVAR(VT_STORED_OBJECT); \
243 BADVAR(VT_BLOB_OBJECT); \
244 BADVAR(VT_CF); \
245 BADVAR(VT_CLSID); \
246 BADVAR(VT_BSTR_BLOB)
248 /* Early versions of oleaut32 are missing many functions */
249 static HRESULT (WINAPI *pVarI1FromUI1)(BYTE,signed char*);
250 static HRESULT (WINAPI *pVarI1FromI2)(SHORT,signed char*);
251 static HRESULT (WINAPI *pVarI1FromI4)(LONG,signed char*);
252 static HRESULT (WINAPI *pVarI1FromR4)(FLOAT,signed char*);
253 static HRESULT (WINAPI *pVarI1FromR8)(double,signed char*);
254 static HRESULT (WINAPI *pVarI1FromDate)(DATE,signed char*);
255 static HRESULT (WINAPI *pVarI1FromCy)(CY,signed char*);
256 static HRESULT (WINAPI *pVarI1FromStr)(OLECHAR*,LCID,ULONG,signed char*);
257 static HRESULT (WINAPI *pVarI1FromBool)(VARIANT_BOOL,signed char*);
258 static HRESULT (WINAPI *pVarI1FromUI2)(USHORT,signed char*);
259 static HRESULT (WINAPI *pVarI1FromUI4)(ULONG,signed char*);
260 static HRESULT (WINAPI *pVarI1FromDec)(DECIMAL*,signed char*);
261 static HRESULT (WINAPI *pVarI1FromI8)(LONG64,signed char*);
262 static HRESULT (WINAPI *pVarI1FromUI8)(ULONG64,signed char*);
263 static HRESULT (WINAPI *pVarUI1FromI2)(SHORT,BYTE*);
264 static HRESULT (WINAPI *pVarUI1FromI4)(LONG,BYTE*);
265 static HRESULT (WINAPI *pVarUI1FromR4)(FLOAT,BYTE*);
266 static HRESULT (WINAPI *pVarUI1FromR8)(double,BYTE*);
267 static HRESULT (WINAPI *pVarUI1FromCy)(CY,BYTE*);
268 static HRESULT (WINAPI *pVarUI1FromDate)(DATE,BYTE*);
269 static HRESULT (WINAPI *pVarUI1FromStr)(OLECHAR*,LCID,ULONG,BYTE*);
270 static HRESULT (WINAPI *pVarUI1FromBool)(VARIANT_BOOL,BYTE*);
271 static HRESULT (WINAPI *pVarUI1FromI1)(signed char,BYTE*);
272 static HRESULT (WINAPI *pVarUI1FromUI2)(USHORT,BYTE*);
273 static HRESULT (WINAPI *pVarUI1FromUI4)(ULONG,BYTE*);
274 static HRESULT (WINAPI *pVarUI1FromDec)(DECIMAL*,BYTE*);
275 static HRESULT (WINAPI *pVarUI1FromI8)(LONG64,BYTE*);
276 static HRESULT (WINAPI *pVarUI1FromUI8)(ULONG64,BYTE*);
277 static HRESULT (WINAPI *pVarUI1FromDisp)(IDispatch*,LCID,BYTE*);
279 static HRESULT (WINAPI *pVarI2FromUI1)(BYTE,SHORT*);
280 static HRESULT (WINAPI *pVarI2FromI4)(LONG,SHORT*);
281 static HRESULT (WINAPI *pVarI2FromR4)(FLOAT,SHORT*);
282 static HRESULT (WINAPI *pVarI2FromR8)(double,SHORT*);
283 static HRESULT (WINAPI *pVarI2FromCy)(CY,SHORT*);
284 static HRESULT (WINAPI *pVarI2FromDate)(DATE,SHORT*);
285 static HRESULT (WINAPI *pVarI2FromStr)(OLECHAR*,LCID,ULONG,SHORT*);
286 static HRESULT (WINAPI *pVarI2FromBool)(VARIANT_BOOL,SHORT*);
287 static HRESULT (WINAPI *pVarI2FromI1)(signed char,SHORT*);
288 static HRESULT (WINAPI *pVarI2FromUI2)(USHORT,SHORT*);
289 static HRESULT (WINAPI *pVarI2FromUI4)(ULONG,SHORT*);
290 static HRESULT (WINAPI *pVarI2FromDec)(DECIMAL*,SHORT*);
291 static HRESULT (WINAPI *pVarI2FromI8)(LONG64,SHORT*);
292 static HRESULT (WINAPI *pVarI2FromUI8)(ULONG64,SHORT*);
293 static HRESULT (WINAPI *pVarUI2FromUI1)(BYTE,USHORT*);
294 static HRESULT (WINAPI *pVarUI2FromI2)(SHORT,USHORT*);
295 static HRESULT (WINAPI *pVarUI2FromI4)(LONG,USHORT*);
296 static HRESULT (WINAPI *pVarUI2FromR4)(FLOAT,USHORT*);
297 static HRESULT (WINAPI *pVarUI2FromR8)(double,USHORT*);
298 static HRESULT (WINAPI *pVarUI2FromDate)(DATE,USHORT*);
299 static HRESULT (WINAPI *pVarUI2FromCy)(CY,USHORT*);
300 static HRESULT (WINAPI *pVarUI2FromStr)(OLECHAR*,LCID,ULONG,USHORT*);
301 static HRESULT (WINAPI *pVarUI2FromBool)(VARIANT_BOOL,USHORT*);
302 static HRESULT (WINAPI *pVarUI2FromI1)(signed char,USHORT*);
303 static HRESULT (WINAPI *pVarUI2FromUI4)(ULONG,USHORT*);
304 static HRESULT (WINAPI *pVarUI2FromDec)(DECIMAL*,USHORT*);
305 static HRESULT (WINAPI *pVarUI2FromI8)(LONG64,USHORT*);
306 static HRESULT (WINAPI *pVarUI2FromUI8)(ULONG64,USHORT*);
308 static HRESULT (WINAPI *pVarI4FromUI1)(BYTE,LONG*);
309 static HRESULT (WINAPI *pVarI4FromI2)(SHORT,LONG*);
310 static HRESULT (WINAPI *pVarI4FromR4)(FLOAT,LONG*);
311 static HRESULT (WINAPI *pVarI4FromR8)(DOUBLE,LONG*);
312 static HRESULT (WINAPI *pVarI4FromCy)(CY,LONG*);
313 static HRESULT (WINAPI *pVarI4FromDate)(DATE,LONG*);
314 static HRESULT (WINAPI *pVarI4FromStr)(OLECHAR*,LCID,ULONG,LONG*);
315 static HRESULT (WINAPI *pVarI4FromBool)(VARIANT_BOOL,LONG*);
316 static HRESULT (WINAPI *pVarI4FromI1)(signed char,LONG*);
317 static HRESULT (WINAPI *pVarI4FromUI2)(USHORT,LONG*);
318 static HRESULT (WINAPI *pVarI4FromUI4)(ULONG,LONG*);
319 static HRESULT (WINAPI *pVarI4FromDec)(DECIMAL*,LONG*);
320 static HRESULT (WINAPI *pVarI4FromI8)(LONG64,LONG*);
321 static HRESULT (WINAPI *pVarI4FromUI8)(ULONG64,LONG*);
322 static HRESULT (WINAPI *pVarUI4FromUI1)(BYTE,ULONG*);
323 static HRESULT (WINAPI *pVarUI4FromI2)(SHORT,ULONG*);
324 static HRESULT (WINAPI *pVarUI4FromI4)(LONG,ULONG*);
325 static HRESULT (WINAPI *pVarUI4FromR4)(FLOAT,ULONG*);
326 static HRESULT (WINAPI *pVarUI4FromR8)(DOUBLE,ULONG*);
327 static HRESULT (WINAPI *pVarUI4FromDate)(DATE,ULONG*);
328 static HRESULT (WINAPI *pVarUI4FromCy)(CY,ULONG*);
329 static HRESULT (WINAPI *pVarUI4FromStr)(OLECHAR*,LCID,ULONG,ULONG*);
330 static HRESULT (WINAPI *pVarUI4FromBool)(VARIANT_BOOL,ULONG*);
331 static HRESULT (WINAPI *pVarUI4FromI1)(signed char,ULONG*);
332 static HRESULT (WINAPI *pVarUI4FromUI2)(USHORT,ULONG*);
333 static HRESULT (WINAPI *pVarUI4FromDec)(DECIMAL*,ULONG*);
334 static HRESULT (WINAPI *pVarUI4FromI8)(LONG64,ULONG*);
335 static HRESULT (WINAPI *pVarUI4FromUI8)(ULONG64,ULONG*);
337 static HRESULT (WINAPI *pVarI8FromUI1)(BYTE,LONG64*);
338 static HRESULT (WINAPI *pVarI8FromI2)(SHORT,LONG64*);
339 static HRESULT (WINAPI *pVarI8FromR4)(FLOAT,LONG64*);
340 static HRESULT (WINAPI *pVarI8FromR8)(double,LONG64*);
341 static HRESULT (WINAPI *pVarI8FromCy)(CY,LONG64*);
342 static HRESULT (WINAPI *pVarI8FromDate)(DATE,LONG64*);
343 static HRESULT (WINAPI *pVarI8FromStr)(OLECHAR*,LCID,ULONG,LONG64*);
344 static HRESULT (WINAPI *pVarI8FromBool)(VARIANT_BOOL,LONG64*);
345 static HRESULT (WINAPI *pVarI8FromI1)(signed char,LONG64*);
346 static HRESULT (WINAPI *pVarI8FromUI2)(USHORT,LONG64*);
347 static HRESULT (WINAPI *pVarI8FromUI4)(ULONG,LONG64*);
348 static HRESULT (WINAPI *pVarI8FromDec)(DECIMAL*,LONG64*);
349 static HRESULT (WINAPI *pVarI8FromUI8)(ULONG64,LONG64*);
350 static HRESULT (WINAPI *pVarUI8FromI8)(LONG64,ULONG64*);
351 static HRESULT (WINAPI *pVarUI8FromUI1)(BYTE,ULONG64*);
352 static HRESULT (WINAPI *pVarUI8FromI2)(SHORT,ULONG64*);
353 static HRESULT (WINAPI *pVarUI8FromR4)(FLOAT,ULONG64*);
354 static HRESULT (WINAPI *pVarUI8FromR8)(double,ULONG64*);
355 static HRESULT (WINAPI *pVarUI8FromCy)(CY,ULONG64*);
356 static HRESULT (WINAPI *pVarUI8FromDate)(DATE,ULONG64*);
357 static HRESULT (WINAPI *pVarUI8FromStr)(OLECHAR*,LCID,ULONG,ULONG64*);
358 static HRESULT (WINAPI *pVarUI8FromBool)(VARIANT_BOOL,ULONG64*);
359 static HRESULT (WINAPI *pVarUI8FromI1)(signed char,ULONG64*);
360 static HRESULT (WINAPI *pVarUI8FromUI2)(USHORT,ULONG64*);
361 static HRESULT (WINAPI *pVarUI8FromUI4)(ULONG,ULONG64*);
362 static HRESULT (WINAPI *pVarUI8FromDec)(DECIMAL*,ULONG64*);
364 static HRESULT (WINAPI *pVarR4FromUI1)(BYTE,float*);
365 static HRESULT (WINAPI *pVarR4FromI2)(SHORT,float*);
366 static HRESULT (WINAPI *pVarR4FromI4)(LONG,float*);
367 static HRESULT (WINAPI *pVarR4FromR8)(double,float*);
368 static HRESULT (WINAPI *pVarR4FromCy)(CY,float*);
369 static HRESULT (WINAPI *pVarR4FromDate)(DATE,float*);
370 static HRESULT (WINAPI *pVarR4FromStr)(OLECHAR*,LCID,ULONG,float*);
371 static HRESULT (WINAPI *pVarR4FromBool)(VARIANT_BOOL,float*);
372 static HRESULT (WINAPI *pVarR4FromI1)(signed char,float*);
373 static HRESULT (WINAPI *pVarR4FromUI2)(USHORT,float*);
374 static HRESULT (WINAPI *pVarR4FromUI4)(ULONG,float*);
375 static HRESULT (WINAPI *pVarR4FromDec)(DECIMAL*,float*);
376 static HRESULT (WINAPI *pVarR4FromI8)(LONG64,float*);
377 static HRESULT (WINAPI *pVarR4FromUI8)(ULONG64,float*);
379 static HRESULT (WINAPI *pVarR8FromUI1)(BYTE,double*);
380 static HRESULT (WINAPI *pVarR8FromI2)(SHORT,double*);
381 static HRESULT (WINAPI *pVarR8FromI4)(LONG,double*);
382 static HRESULT (WINAPI *pVarR8FromR4)(FLOAT,double*);
383 static HRESULT (WINAPI *pVarR8FromCy)(CY,double*);
384 static HRESULT (WINAPI *pVarR8FromDate)(DATE,double*);
385 static HRESULT (WINAPI *pVarR8FromStr)(OLECHAR*,LCID,ULONG,double*);
386 static HRESULT (WINAPI *pVarR8FromBool)(VARIANT_BOOL,double*);
387 static HRESULT (WINAPI *pVarR8FromI1)(signed char,double*);
388 static HRESULT (WINAPI *pVarR8FromUI2)(USHORT,double*);
389 static HRESULT (WINAPI *pVarR8FromUI4)(ULONG,double*);
390 static HRESULT (WINAPI *pVarR8FromDec)(DECIMAL*,double*);
391 static HRESULT (WINAPI *pVarR8FromI8)(LONG64,double*);
392 static HRESULT (WINAPI *pVarR8FromUI8)(ULONG64,double*);
393 static HRESULT (WINAPI *pVarR8Round)(double,int,double*);
395 static HRESULT (WINAPI *pVarDateFromUI1)(BYTE,DATE*);
396 static HRESULT (WINAPI *pVarDateFromI2)(SHORT,DATE*);
397 static HRESULT (WINAPI *pVarDateFromI4)(LONG,DATE*);
398 static HRESULT (WINAPI *pVarDateFromR4)(FLOAT,DATE*);
399 static HRESULT (WINAPI *pVarDateFromCy)(CY,DATE*);
400 static HRESULT (WINAPI *pVarDateFromR8)(double,DATE*);
401 static HRESULT (WINAPI *pVarDateFromStr)(OLECHAR*,LCID,ULONG,DATE*);
402 static HRESULT (WINAPI *pVarDateFromBool)(VARIANT_BOOL,DATE*);
403 static HRESULT (WINAPI *pVarDateFromI1)(signed char,DATE*);
404 static HRESULT (WINAPI *pVarDateFromUI2)(USHORT,DATE*);
405 static HRESULT (WINAPI *pVarDateFromUI4)(ULONG,DATE*);
406 static HRESULT (WINAPI *pVarDateFromDec)(DECIMAL*,DATE*);
407 static HRESULT (WINAPI *pVarDateFromI8)(LONG64,DATE*);
408 static HRESULT (WINAPI *pVarDateFromUI8)(ULONG64,DATE*);
410 static HRESULT (WINAPI *pVarCyFromUI1)(BYTE,CY*);
411 static HRESULT (WINAPI *pVarCyFromI2)(SHORT,CY*);
412 static HRESULT (WINAPI *pVarCyFromI4)(LONG,CY*);
413 static HRESULT (WINAPI *pVarCyFromR4)(FLOAT,CY*);
414 static HRESULT (WINAPI *pVarCyFromR8)(double,CY*);
415 static HRESULT (WINAPI *pVarCyFromDate)(DATE,CY*);
416 static HRESULT (WINAPI *pVarCyFromBool)(VARIANT_BOOL,CY*);
417 static HRESULT (WINAPI *pVarCyFromI1)(signed char,CY*);
418 static HRESULT (WINAPI *pVarCyFromUI2)(USHORT,CY*);
419 static HRESULT (WINAPI *pVarCyFromUI4)(ULONG,CY*);
420 static HRESULT (WINAPI *pVarCyFromDec)(DECIMAL*,CY*);
421 static HRESULT (WINAPI *pVarCyFromI8)(LONG64,CY*);
422 static HRESULT (WINAPI *pVarCyFromUI8)(ULONG64,CY*);
423 static HRESULT (WINAPI *pVarCyAdd)(const CY,const CY,CY*);
424 static HRESULT (WINAPI *pVarCyMul)(const CY,const CY,CY*);
425 static HRESULT (WINAPI *pVarCyMulI4)(const CY,LONG,CY*);
426 static HRESULT (WINAPI *pVarCySub)(const CY,const CY,CY*);
427 static HRESULT (WINAPI *pVarCyAbs)(const CY,CY*);
428 static HRESULT (WINAPI *pVarCyFix)(const CY,CY*);
429 static HRESULT (WINAPI *pVarCyInt)(const CY,CY*);
430 static HRESULT (WINAPI *pVarCyNeg)(const CY,CY*);
431 static HRESULT (WINAPI *pVarCyRound)(const CY,int,CY*);
432 static HRESULT (WINAPI *pVarCyCmp)(const CY,const CY);
433 static HRESULT (WINAPI *pVarCyCmpR8)(const CY,double);
434 static HRESULT (WINAPI *pVarCyMulI8)(const CY,LONG64,CY*);
436 static HRESULT (WINAPI *pVarDecFromUI1)(BYTE,DECIMAL*);
437 static HRESULT (WINAPI *pVarDecFromI2)(SHORT,DECIMAL*);
438 static HRESULT (WINAPI *pVarDecFromI4)(LONG,DECIMAL*);
439 static HRESULT (WINAPI *pVarDecFromI8)(LONG64,DECIMAL*);
440 static HRESULT (WINAPI *pVarDecFromR4)(FLOAT,DECIMAL*);
441 static HRESULT (WINAPI *pVarDecFromR8)(DOUBLE,DECIMAL*);
442 static HRESULT (WINAPI *pVarDecFromDate)(DATE,DECIMAL*);
443 static HRESULT (WINAPI *pVarDecFromStr)(OLECHAR*,LCID,ULONG,DECIMAL*);
444 static HRESULT (WINAPI *pVarDecFromBool)(VARIANT_BOOL,DECIMAL*);
445 static HRESULT (WINAPI *pVarDecFromI1)(signed char,DECIMAL*);
446 static HRESULT (WINAPI *pVarDecFromUI2)(USHORT,DECIMAL*);
447 static HRESULT (WINAPI *pVarDecFromUI4)(ULONG,DECIMAL*);
448 static HRESULT (WINAPI *pVarDecFromUI8)(ULONG64,DECIMAL*);
449 static HRESULT (WINAPI *pVarDecFromCy)(CY,DECIMAL*);
450 static HRESULT (WINAPI *pVarDecAbs)(const DECIMAL*,DECIMAL*);
451 static HRESULT (WINAPI *pVarDecAdd)(const DECIMAL*,const DECIMAL*,DECIMAL*);
452 static HRESULT (WINAPI *pVarDecSub)(const DECIMAL*,const DECIMAL*,DECIMAL*);
453 static HRESULT (WINAPI *pVarDecCmp)(const DECIMAL*,const DECIMAL*);
454 static HRESULT (WINAPI *pVarDecNeg)(const DECIMAL*,DECIMAL*);
456 static HRESULT (WINAPI *pVarBoolFromUI1)(BYTE,VARIANT_BOOL*);
457 static HRESULT (WINAPI *pVarBoolFromI2)(SHORT,VARIANT_BOOL*);
458 static HRESULT (WINAPI *pVarBoolFromI4)(LONG,VARIANT_BOOL*);
459 static HRESULT (WINAPI *pVarBoolFromR4)(FLOAT,VARIANT_BOOL*);
460 static HRESULT (WINAPI *pVarBoolFromR8)(DOUBLE,VARIANT_BOOL*);
461 static HRESULT (WINAPI *pVarBoolFromDate)(DATE,VARIANT_BOOL*);
462 static HRESULT (WINAPI *pVarBoolFromCy)(CY,VARIANT_BOOL*);
463 static HRESULT (WINAPI *pVarBoolFromStr)(OLECHAR*,LCID,ULONG,VARIANT_BOOL*);
464 static HRESULT (WINAPI *pVarBoolFromI1)(signed char,VARIANT_BOOL*);
465 static HRESULT (WINAPI *pVarBoolFromUI2)(USHORT,VARIANT_BOOL*);
466 static HRESULT (WINAPI *pVarBoolFromUI4)(ULONG,VARIANT_BOOL*);
467 static HRESULT (WINAPI *pVarBoolFromDec)(DECIMAL*,VARIANT_BOOL*);
468 static HRESULT (WINAPI *pVarBoolFromI8)(LONG64,VARIANT_BOOL*);
469 static HRESULT (WINAPI *pVarBoolFromUI8)(ULONG64,VARIANT_BOOL*);
471 static HRESULT (WINAPI *pVarBstrFromR4)(FLOAT,LCID,ULONG,BSTR*);
472 static HRESULT (WINAPI *pVarBstrFromDate)(DATE,LCID,ULONG,BSTR*);
474 static INT (WINAPI *pSystemTimeToVariantTime)(LPSYSTEMTIME,double*);
475 static void (WINAPI *pClearCustData)(LPCUSTDATA);
477 /* Internal representation of a BSTR */
478 typedef struct tagINTERNAL_BSTR
480 DWORD dwLen;
481 OLECHAR szString[1];
482 } INTERNAL_BSTR, *LPINTERNAL_BSTR;
484 typedef struct
486 IDispatchVtbl *lpVtbl;
487 ULONG ref;
488 VARTYPE vt;
489 BOOL bFailInvoke;
490 } DummyDispatch;
492 static DummyDispatch dispatch;
494 static ULONG WINAPI DummyDispatch_AddRef(LPDISPATCH iface)
496 trace("AddRef(%p)\n", iface);
497 return ++((DummyDispatch*)iface)->ref;
500 static ULONG WINAPI DummyDispatch_Release(LPDISPATCH iface)
502 trace("Release(%p)\n", iface);
503 return ((DummyDispatch*)iface)->ref--;
506 static HRESULT WINAPI DummyDispatch_QueryInterface(LPDISPATCH iface,
507 REFIID riid,
508 void** ppvObject)
510 trace("QueryInterface(%p)\n", iface);
511 if (ppvObject)
513 *ppvObject = NULL;
514 if (IsEqualIID(riid, &IID_IDispatch))
516 trace("Asked for IID_IDispatch\n");
517 *ppvObject = iface;
519 else if (IsEqualIID(riid, &IID_IUnknown))
521 trace("Asked for IID_IUnknown\n");
522 *ppvObject = iface;
524 if (*ppvObject)
526 DummyDispatch_AddRef((IDispatch*)*ppvObject);
527 return S_OK;
530 return E_NOINTERFACE;
533 static HRESULT WINAPI DummyDispatch_Invoke(LPDISPATCH iface,
534 DISPID dispIdMember, REFIID riid,
535 LCID lcid, WORD wFlags,
536 DISPPARAMS *pDispParams,
537 VARIANT *pVarResult,
538 EXCEPINFO *pExcepInfo,
539 UINT *puArgErr)
541 trace("Invoke(%p)\n", iface);
542 ok(wFlags == DISPATCH_PROPERTYGET, "Flags wrong\n");
543 ok(pDispParams->cArgs == 0, "Property get has args\n");
545 if (dispatch.bFailInvoke)
546 return E_OUTOFMEMORY;
548 memset(pVarResult, 0, sizeof(*pVarResult));
549 V_VT(pVarResult) = dispatch.vt;
550 return S_OK;
553 static ICOM_VTABLE(IDispatch) DummyDispatch_VTable =
555 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
556 DummyDispatch_QueryInterface,
557 DummyDispatch_AddRef,
558 DummyDispatch_Release,
559 NULL,
560 NULL,
561 NULL,
562 DummyDispatch_Invoke
565 static DummyDispatch dispatch = { &DummyDispatch_VTable, 1, 0, 0 };
568 * VT_I1/VT_UI1
571 #undef CONV_TYPE
572 #define CONV_TYPE signed char
573 #undef EXPECTRES
574 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%d")
576 static void test_VarI1FromI2(void)
578 CONVVARS(SHORT);
579 int i;
581 CHECKPTR(VarI1FromI2);
582 OVERFLOWRANGE(VarI1FromI2, -32768, -128);
583 CONVERTRANGE(VarI1FromI2, -128, 128);
584 OVERFLOWRANGE(VarI1FromI2, 129, 32768);
587 static void test_VarI1FromI4(void)
589 CONVVARS(LONG);
590 int i;
592 CHECKPTR(VarI1FromI4);
593 CONVERT(VarI1FromI4, -129); EXPECT_OVERFLOW;
594 CONVERTRANGE(VarI1FromI4, -128, 128);
595 CONVERT(VarI1FromI4, 128); EXPECT_OVERFLOW;
598 static void test_VarI1FromI8(void)
600 CONVVARS(LONG64);
601 int i;
603 CHECKPTR(VarI1FromI8);
604 CONVERT(VarI1FromI8, -129); EXPECT_OVERFLOW;
605 CONVERTRANGE(VarI1FromI8, -127, 128);
606 CONVERT(VarI1FromI8, 128); EXPECT_OVERFLOW;
609 static void test_VarI1FromUI1(void)
611 CONVVARS(BYTE);
612 int i;
614 CHECKPTR(VarI1FromUI1);
615 CONVERTRANGE(VarI1FromUI1, 0, 127);
616 OVERFLOWRANGE(VarI1FromUI1, 128, 255);
619 static void test_VarI1FromUI2(void)
621 CONVVARS(USHORT);
622 int i;
624 CHECKPTR(VarI1FromUI2);
625 CONVERTRANGE(VarI1FromUI2, 0, 127);
626 OVERFLOWRANGE(VarI1FromUI2, 128, 32768);
629 static void test_VarI1FromUI4(void)
631 CONVVARS(ULONG);
632 int i;
634 CHECKPTR(VarI1FromUI4);
635 CONVERTRANGE(VarI1FromUI4, 0, 127);
636 CONVERT(VarI1FromUI4, 128); EXPECT_OVERFLOW;
639 static void test_VarI1FromUI8(void)
641 CONVVARS(ULONG64);
642 int i;
644 CHECKPTR(VarI1FromUI8);
645 CONVERTRANGE(VarI1FromUI8, 0, 127);
646 CONVERT(VarI1FromUI8, 128); EXPECT_OVERFLOW;
649 static void test_VarI1FromBool(void)
651 CONVVARS(VARIANT_BOOL);
652 int i;
654 CHECKPTR(VarI1FromBool);
655 /* Note that conversions from bool wrap around! */
656 CONVERT(VarI1FromBool, -129); EXPECT(127);
657 CONVERTRANGE(VarI1FromBool, -128, 128);
658 CONVERT(VarI1FromBool, 128); EXPECT(-128);
661 static void test_VarI1FromR4(void)
663 CONVVARS(FLOAT);
665 CHECKPTR(VarI1FromR4);
666 CONVERT(VarI1FromR4, -129.0f); EXPECT_OVERFLOW;
667 CONVERT(VarI1FromR4, -128.0f); EXPECT(-128);
668 CONVERT(VarI1FromR4, -1.0f); EXPECT(-1);
669 CONVERT(VarI1FromR4, 0.0f); EXPECT(0);
670 CONVERT(VarI1FromR4, 1.0f); EXPECT(1);
671 CONVERT(VarI1FromR4, 127.0f); EXPECT(127);
672 CONVERT(VarI1FromR4, 128.0f); EXPECT_OVERFLOW;
674 CONVERT(VarI1FromR4, -1.5f); EXPECT(-2);
675 CONVERT(VarI1FromR4, -0.6f); EXPECT(-1);
676 CONVERT(VarI1FromR4, -0.5f); EXPECT(0);
677 CONVERT(VarI1FromR4, -0.4f); EXPECT(0);
678 CONVERT(VarI1FromR4, 0.4f); EXPECT(0);
679 CONVERT(VarI1FromR4, 0.5f); EXPECT(0);
680 CONVERT(VarI1FromR4, 0.6f); EXPECT(1);
681 CONVERT(VarI1FromR4, 1.5f); EXPECT(2);
684 static void test_VarI1FromR8(void)
686 CONVVARS(DOUBLE);
688 CHECKPTR(VarI1FromR8);
689 CONVERT(VarI1FromR8, -129.0); EXPECT_OVERFLOW;
690 CONVERT(VarI1FromR8, -128.0); EXPECT(-128);
691 CONVERT(VarI1FromR8, -1.0); EXPECT(-1);
692 CONVERT(VarI1FromR8, 0.0); EXPECT(0);
693 CONVERT(VarI1FromR8, 1.0); EXPECT(1);
694 CONVERT(VarI1FromR8, 127.0); EXPECT(127);
695 CONVERT(VarI1FromR8, 128.0); EXPECT_OVERFLOW;
697 CONVERT(VarI1FromR8, -1.5); EXPECT(-2);
698 CONVERT(VarI1FromR8, -0.6); EXPECT(-1);
699 CONVERT(VarI1FromR8, -0.5); EXPECT(0);
700 CONVERT(VarI1FromR8, -0.4); EXPECT(0);
701 CONVERT(VarI1FromR8, 0.4); EXPECT(0);
702 CONVERT(VarI1FromR8, 0.5); EXPECT(0);
703 CONVERT(VarI1FromR8, 0.6); EXPECT(1);
704 CONVERT(VarI1FromR8, 1.5); EXPECT(2);
707 static void test_VarI1FromDate(void)
709 CONVVARS(DATE);
711 CHECKPTR(VarI1FromDate);
712 CONVERT(VarI1FromDate, -129.0); EXPECT_OVERFLOW;
713 CONVERT(VarI1FromDate, -128.0); EXPECT(-128);
714 CONVERT(VarI1FromDate, -1.0); EXPECT(-1);
715 CONVERT(VarI1FromDate, 0.0); EXPECT(0);
716 CONVERT(VarI1FromDate, 1.0); EXPECT(1);
717 CONVERT(VarI1FromDate, 127.0); EXPECT(127);
718 CONVERT(VarI1FromDate, 128.0); EXPECT_OVERFLOW;
720 CONVERT(VarI1FromDate, -1.5); EXPECT(-2);
721 CONVERT(VarI1FromDate, -0.6); EXPECT(-1);
722 CONVERT(VarI1FromDate, -0.5); EXPECT(0);
723 CONVERT(VarI1FromDate, -0.4); EXPECT(0);
724 CONVERT(VarI1FromDate, 0.4); EXPECT(0);
725 CONVERT(VarI1FromDate, 0.5); EXPECT(0);
726 CONVERT(VarI1FromDate, 0.6); EXPECT(1);
727 CONVERT(VarI1FromDate, 1.5); EXPECT(2);
730 static void test_VarI1FromCy(void)
732 CONVVARS(CY);
734 CHECKPTR(VarI1FromCy);
735 CONVERT_CY(VarI1FromCy,-129); EXPECT_OVERFLOW;
736 CONVERT_CY(VarI1FromCy,-128); EXPECT(128);
737 CONVERT_CY(VarI1FromCy,-1); EXPECT(-1);
738 CONVERT_CY(VarI1FromCy,0); EXPECT(0);
739 CONVERT_CY(VarI1FromCy,1); EXPECT(1);
740 CONVERT_CY(VarI1FromCy,127); EXPECT(127);
741 CONVERT_CY(VarI1FromCy,128); EXPECT_OVERFLOW;
743 CONVERT_CY(VarI1FromCy,-1.5); EXPECT(-2);
744 CONVERT_CY(VarI1FromCy,-0.6); EXPECT(-1);
745 CONVERT_CY(VarI1FromCy,-0.5); EXPECT(0);
746 CONVERT_CY(VarI1FromCy,-0.4); EXPECT(0);
747 CONVERT_CY(VarI1FromCy,0.4); EXPECT(0);
748 CONVERT_CY(VarI1FromCy,0.5); EXPECT(0);
749 CONVERT_CY(VarI1FromCy,0.6); EXPECT(1);
750 CONVERT_CY(VarI1FromCy,1.5); EXPECT(2);
753 static void test_VarI1FromDec(void)
755 CONVVARS(DECIMAL);
757 CHECKPTR(VarI1FromDec);
759 CONVERT_BADDEC(VarI1FromDec);
761 CONVERT_DEC(VarI1FromDec,0,0x80,0,129); EXPECT_OVERFLOW;
762 CONVERT_DEC(VarI1FromDec,0,0x80,0,128); EXPECT(-128);
763 CONVERT_DEC(VarI1FromDec,0,0x80,0,1); EXPECT(-1);
764 CONVERT_DEC(VarI1FromDec,0,0,0,0); EXPECT(0);
765 CONVERT_DEC(VarI1FromDec,0,0,0,1); EXPECT(1);
766 CONVERT_DEC(VarI1FromDec,0,0,0,127); EXPECT(127);
767 CONVERT_DEC(VarI1FromDec,0,0,0,128); EXPECT_OVERFLOW;
769 CONVERT_DEC(VarI1FromDec,2,0x80,0,12800); EXPECT(-128);
770 CONVERT_DEC(VarI1FromDec,2,0,0,12700); EXPECT(127);
773 static void test_VarI1FromStr(void)
775 CONVVARS(LCID);
776 OLECHAR buff[128];
778 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
780 CHECKPTR(VarI1FromStr);
782 CONVERT_STR(VarI1FromStr,NULL, 0); EXPECT_MISMATCH;
783 CONVERT_STR(VarI1FromStr,"0", 0); EXPECT(0);
784 CONVERT_STR(VarI1FromStr,"-129", 0); EXPECT_OVERFLOW;
785 CONVERT_STR(VarI1FromStr,"-128", 0); EXPECT(-128);
786 CONVERT_STR(VarI1FromStr,"127", 0); EXPECT(127);
787 CONVERT_STR(VarI1FromStr,"128", 0); EXPECT_OVERFLOW;
789 CONVERT_STR(VarI1FromStr,"-1.5", 0); EXPECT(-2);
790 CONVERT_STR(VarI1FromStr,"-0.6", 0); EXPECT(-1);
791 CONVERT_STR(VarI1FromStr,"-0.5", 0); EXPECT(0);
792 CONVERT_STR(VarI1FromStr,"-0.4", 0); EXPECT(0);
793 CONVERT_STR(VarI1FromStr,"0.4", 0); EXPECT(0);
794 CONVERT_STR(VarI1FromStr,"0.5", 0); EXPECT(0);
795 CONVERT_STR(VarI1FromStr,"0.6", 0); EXPECT(1);
796 CONVERT_STR(VarI1FromStr,"1.5", 0); EXPECT(2);
799 static void test_VarI1Copy(void)
801 if (!IS_ANCIENT)
803 COPYTEST(1, VT_I1, V_I1(&vSrc), V_I1(&vDst), V_I1REF(&vSrc), V_I1REF(&vDst), "%d");
807 static void test_VarI1ChangeTypeEx(void)
809 CONVVARS(CONV_TYPE);
810 VARIANTARG vSrc, vDst;
812 in = 1;
814 if (!IS_ANCIENT)
816 INITIAL_TYPETEST(VT_I1, V_I1, "%d");
817 COMMON_TYPETEST;
821 #undef CONV_TYPE
822 #define CONV_TYPE BYTE
824 static void test_VarUI1FromI1(void)
826 CONVVARS(signed char);
827 int i;
829 CHECKPTR(VarUI1FromI1);
830 OVERFLOWRANGE(VarUI1FromI1, -128, 0);
831 CONVERTRANGE(VarUI1FromI1, 0, 128);
834 static void test_VarUI1FromI2(void)
836 CONVVARS(SHORT);
837 int i;
839 CHECKPTR(VarUI1FromI2);
840 OVERFLOWRANGE(VarUI1FromI2, -32768, 0);
841 CONVERTRANGE(VarUI1FromI2, 0, 256);
842 OVERFLOWRANGE(VarUI1FromI2, 256, 32768);
845 static void test_VarUI1FromI4(void)
847 CONVVARS(LONG);
848 int i;
850 CHECKPTR(VarUI1FromI4);
851 CONVERT(VarUI1FromI4, -1); EXPECT_OVERFLOW;
852 CONVERTRANGE(VarUI1FromI4, 0, 256);
853 CONVERT(VarUI1FromI4, 256); EXPECT_OVERFLOW;
856 static void test_VarUI1FromI8(void)
858 CONVVARS(LONG64);
859 int i;
861 CHECKPTR(VarUI1FromI8);
862 CONVERT(VarUI1FromI8, -1); EXPECT_OVERFLOW;
863 CONVERTRANGE(VarUI1FromI8, 0, 256);
864 CONVERT(VarUI1FromI8, 256); EXPECT_OVERFLOW;
867 static void test_VarUI1FromUI2(void)
869 CONVVARS(USHORT);
870 int i;
872 CHECKPTR(VarUI1FromUI2);
873 CONVERTRANGE(VarUI1FromUI2, 0, 256);
874 OVERFLOWRANGE(VarUI1FromUI2, 256, 65536);
877 static void test_VarUI1FromUI4(void)
879 CONVVARS(ULONG);
880 int i;
882 CHECKPTR(VarUI1FromUI4);
883 CONVERTRANGE(VarUI1FromUI4, 0, 256);
884 CONVERT(VarUI1FromUI4, 256); EXPECT_OVERFLOW;
887 static void test_VarUI1FromUI8(void)
889 CONVVARS(ULONG64);
890 int i;
892 CHECKPTR(VarUI1FromUI8);
893 CONVERTRANGE(VarUI1FromUI8, 0, 256);
894 CONVERT(VarUI1FromUI8, 256); EXPECT_OVERFLOW;
897 static void test_VarUI1FromBool(void)
899 CONVVARS(VARIANT_BOOL);
900 int i;
902 CHECKPTR(VarUI1FromBool);
903 /* Note that conversions from bool overflow! */
904 CONVERT(VarUI1FromBool, -1); EXPECT(255);
905 CONVERTRANGE(VarUI1FromBool, 0, 256);
906 CONVERT(VarUI1FromBool, 256); EXPECT(0);
909 static void test_VarUI1FromR4(void)
911 CONVVARS(FLOAT);
913 CHECKPTR(VarUI1FromR4);
914 CONVERT(VarUI1FromR4, -1.0f); EXPECT_OVERFLOW;
915 CONVERT(VarUI1FromR4, 0.0f); EXPECT(0);
916 CONVERT(VarUI1FromR4, 1.0f); EXPECT(1);
917 CONVERT(VarUI1FromR4, 255.0f); EXPECT(255);
918 CONVERT(VarUI1FromR4, 256.0f); EXPECT_OVERFLOW;
920 /* Rounding */
921 CONVERT(VarUI1FromR4, -1.5f); EXPECT_OVERFLOW;
922 CONVERT(VarUI1FromR4, -0.6f); EXPECT_OVERFLOW;
923 CONVERT(VarUI1FromR4, -0.5f); EXPECT(0);
924 CONVERT(VarUI1FromR4, -0.4f); EXPECT(0);
925 CONVERT(VarUI1FromR4, 0.4f); EXPECT(0);
926 CONVERT(VarUI1FromR4, 0.5f); EXPECT(0);
927 CONVERT(VarUI1FromR4, 0.6f); EXPECT(1);
928 CONVERT(VarUI1FromR4, 1.5f); EXPECT(2);
931 static void test_VarUI1FromR8(void)
933 CONVVARS(DOUBLE);
935 CHECKPTR(VarUI1FromR8);
936 CONVERT(VarUI1FromR8, -1.0); EXPECT_OVERFLOW;
937 CONVERT(VarUI1FromR8, 0.0); EXPECT(0);
938 CONVERT(VarUI1FromR8, 1.0); EXPECT(1);
939 CONVERT(VarUI1FromR8, 255.0); EXPECT(255);
940 CONVERT(VarUI1FromR8, 256.0); EXPECT_OVERFLOW;
942 /* Rounding */
943 CONVERT(VarUI1FromR8, -1.5); EXPECT_OVERFLOW;
944 CONVERT(VarUI1FromR8, -0.6); EXPECT_OVERFLOW;
945 CONVERT(VarUI1FromR8, -0.5); EXPECT(0);
946 CONVERT(VarUI1FromR8, -0.4); EXPECT(0);
947 CONVERT(VarUI1FromR8, 0.4); EXPECT(0);
948 CONVERT(VarUI1FromR8, 0.5); EXPECT(0);
949 CONVERT(VarUI1FromR8, 0.6); EXPECT(1);
950 CONVERT(VarUI1FromR8, 1.5); EXPECT(2);
953 static void test_VarUI1FromDate(void)
955 CONVVARS(DATE);
957 CHECKPTR(VarUI1FromDate);
958 CONVERT(VarUI1FromDate, -1.0); EXPECT_OVERFLOW;
959 CONVERT(VarUI1FromDate, 0.0); EXPECT(0);
960 CONVERT(VarUI1FromDate, 1.0); EXPECT(1);
961 CONVERT(VarUI1FromDate, 255.0); EXPECT(255);
962 CONVERT(VarUI1FromDate, 256.0); EXPECT_OVERFLOW;
964 /* Rounding */
965 CONVERT(VarUI1FromDate, -1.5); EXPECT_OVERFLOW;
966 CONVERT(VarUI1FromDate, -0.6); EXPECT_OVERFLOW;
967 CONVERT(VarUI1FromDate, -0.5); EXPECT(0);
968 CONVERT(VarUI1FromDate, -0.4); EXPECT(0);
969 CONVERT(VarUI1FromDate, 0.4); EXPECT(0);
970 CONVERT(VarUI1FromDate, 0.5); EXPECT(0);
971 CONVERT(VarUI1FromDate, 0.6); EXPECT(1);
972 CONVERT(VarUI1FromDate, 1.5); EXPECT(2);
975 static void test_VarUI1FromCy(void)
977 CONVVARS(CY);
979 CHECKPTR(VarUI1FromCy);
980 CONVERT_CY(VarUI1FromCy,-1); EXPECT_OVERFLOW;
981 CONVERT_CY(VarUI1FromCy,0); EXPECT(0);
982 CONVERT_CY(VarUI1FromCy,1); EXPECT(1);
983 CONVERT_CY(VarUI1FromCy,255); EXPECT(255);
984 CONVERT_CY(VarUI1FromCy,256); EXPECT_OVERFLOW;
986 /* Rounding */
987 CONVERT_CY(VarUI1FromCy,-1.5); EXPECT_OVERFLOW;
988 CONVERT_CY(VarUI1FromCy,-0.6); EXPECT_OVERFLOW;
989 CONVERT_CY(VarUI1FromCy,-0.5); EXPECT(0);
990 CONVERT_CY(VarUI1FromCy,-0.4); EXPECT(0);
991 CONVERT_CY(VarUI1FromCy,0.4); EXPECT(0);
992 CONVERT_CY(VarUI1FromCy,0.5); EXPECT(0);
993 CONVERT_CY(VarUI1FromCy,0.6); EXPECT(1);
994 CONVERT_CY(VarUI1FromCy,1.5); EXPECT(2);
997 static void test_VarUI1FromDec(void)
999 CONVVARS(DECIMAL);
1001 CHECKPTR(VarUI1FromDec);
1003 CONVERT_BADDEC(VarUI1FromDec);
1005 CONVERT_DEC(VarUI1FromDec,0,0x80,0,1); EXPECT_OVERFLOW;
1006 CONVERT_DEC(VarUI1FromDec,0,0,0,0); EXPECT(0);
1007 CONVERT_DEC(VarUI1FromDec,0,0,0,1); EXPECT(1);
1008 CONVERT_DEC(VarUI1FromDec,0,0,0,255); EXPECT(255);
1009 CONVERT_DEC(VarUI1FromDec,0,0,0,256); EXPECT_OVERFLOW;
1011 CONVERT_DEC(VarUI1FromDec,2,0x80,0,100); EXPECT_OVERFLOW;
1012 CONVERT_DEC(VarUI1FromDec,2,0,0,25500); EXPECT(255);
1015 static void test_VarUI1FromStr(void)
1017 CONVVARS(LCID);
1018 OLECHAR buff[128];
1020 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1022 CHECKPTR(VarUI1FromStr);
1024 CONVERT_STR(VarUI1FromStr,NULL, 0); EXPECT_MISMATCH;
1025 CONVERT_STR(VarUI1FromStr,"0", 0); EXPECT(0);
1026 CONVERT_STR(VarUI1FromStr,"-1", 0); EXPECT_OVERFLOW;
1027 CONVERT_STR(VarUI1FromStr,"255", 0); EXPECT(255);
1028 CONVERT_STR(VarUI1FromStr,"256", 0); EXPECT_OVERFLOW;
1030 /* Rounding */
1031 CONVERT_STR(VarUI1FromStr,"-1.5", 0); EXPECT_OVERFLOW;
1032 CONVERT_STR(VarUI1FromStr,"-0.6", 0); EXPECT_OVERFLOW;
1033 CONVERT_STR(VarUI1FromStr,"-0.5", 0); EXPECT(0);
1034 CONVERT_STR(VarUI1FromStr,"-0.4", 0); EXPECT(0);
1035 CONVERT_STR(VarUI1FromStr,"0.4", 0); EXPECT(0);
1036 CONVERT_STR(VarUI1FromStr,"0.5", 0); EXPECT(0);
1037 CONVERT_STR(VarUI1FromStr,"0.6", 0); EXPECT(1);
1038 CONVERT_STR(VarUI1FromStr,"1.5", 0); EXPECT(2);
1041 static void test_VarUI1FromDisp(void)
1043 CONVVARS(LCID);
1044 VARIANTARG vSrc, vDst;
1046 CHECKPTR(VarUI1FromDisp);
1048 /* FIXME
1049 * Conversions from IDispatch should get the default 'value' property
1050 * from the IDispatch pointer and return it. The following tests this.
1051 * However, I can't get these tests to return a valid value under native
1052 * oleaut32, regardless of the value returned in response to the Invoke()
1053 * call (early versions of oleaut32 call AddRef/Release, but not Invoke.
1054 * I'm obviously missing something, as these conversions work fine
1055 * when called through VBA on an object to get its default value property.
1057 * Should this test be corrected so that it works under native it should be
1058 * generalised and the remaining types checked as well.
1060 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1062 VariantInit(&vSrc);
1063 VariantInit(&vDst);
1065 V_VT(&vSrc) = VT_DISPATCH;
1066 V_DISPATCH(&vSrc) = (IDispatch*)&dispatch;
1067 dispatch.vt = VT_UI1;
1068 dispatch.bFailInvoke = FALSE;
1070 hres = VarUI1FromDisp((IDispatch*)&dispatch, in, &out);
1071 trace("0x%08lx\n", hres);
1073 hres = VariantChangeTypeEx(&vDst, &vSrc, in, 0, VT_UI1);
1074 trace("0x%08lx\n", hres);
1076 dispatch.bFailInvoke = TRUE;
1078 hres = VarUI1FromDisp((IDispatch*)&dispatch, in, &out);
1079 trace("0x%08lx\n", hres);
1081 hres = VariantChangeTypeEx(&vDst, &vSrc, in, 0, VT_UI1);
1082 trace("0x%08lx\n", hres);
1085 static void test_VarUI1Copy(void)
1087 COPYTEST(1, VT_UI1, V_UI1(&vSrc), V_UI1(&vDst), V_UI1REF(&vSrc), V_UI1REF(&vDst), "%d");
1090 static void test_VarUI1ChangeTypeEx(void)
1092 CONVVARS(CONV_TYPE);
1093 VARIANTARG vSrc, vDst;
1095 in = 1;
1097 INITIAL_TYPETEST(VT_UI1, V_UI1, "%d");
1098 COMMON_TYPETEST;
1102 * VT_I2/VT_UI2
1105 #undef CONV_TYPE
1106 #define CONV_TYPE SHORT
1107 #undef EXPECTRES
1108 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%d")
1110 static void test_VarI2FromI1(void)
1112 CONVVARS(signed char);
1113 int i;
1115 CHECKPTR(VarI2FromI1);
1116 CONVERTRANGE(VarI2FromI1, -128, 128);
1119 static void test_VarI2FromI4(void)
1121 CONVVARS(LONG);
1122 int i;
1124 CHECKPTR(VarI2FromI4);
1125 CONVERT(VarI2FromI4, -32769); EXPECT_OVERFLOW;
1126 CONVERTRANGE(VarI2FromI4, -32768, 32768);
1127 CONVERT(VarI2FromI4, 32768); EXPECT_OVERFLOW;
1130 static void test_VarI2FromI8(void)
1132 CONVVARS(LONG64);
1134 CHECKPTR(VarI2FromI8);
1135 CONVERT(VarI2FromI8, -32769); EXPECT_OVERFLOW;
1136 CONVERT(VarI2FromI8, -32768); EXPECT(-32768);
1137 CONVERT(VarI2FromI8, 32767); EXPECT(32767);
1138 CONVERT(VarI2FromI8, 32768); EXPECT_OVERFLOW;
1141 static void test_VarI2FromUI1(void)
1143 CONVVARS(BYTE);
1144 int i;
1146 CHECKPTR(VarI2FromUI1);
1147 CONVERTRANGE(VarI2FromUI1, 0, 256);
1150 static void test_VarI2FromUI2(void)
1152 CONVVARS(USHORT);
1153 int i;
1155 CHECKPTR(VarI2FromUI2);
1156 CONVERTRANGE(VarI2FromUI2, 0, 32768);
1157 CONVERT(VarI2FromUI2, 32768); EXPECT_OVERFLOW;
1160 static void test_VarI2FromUI4(void)
1162 CONVVARS(ULONG);
1163 int i;
1165 CHECKPTR(VarI2FromUI4);
1166 CONVERTRANGE(VarI2FromUI4, 0, 32768);
1167 CONVERT(VarI2FromUI4, 32768); EXPECT_OVERFLOW;
1170 static void test_VarI2FromUI8(void)
1172 CONVVARS(ULONG64);
1173 int i;
1175 CHECKPTR(VarI2FromUI8);
1176 CONVERTRANGE(VarI2FromUI8, 0, 32768);
1177 CONVERT(VarI2FromUI8, 32768); EXPECT_OVERFLOW;
1180 static void test_VarI2FromBool(void)
1182 CONVVARS(VARIANT_BOOL);
1183 int i;
1185 CHECKPTR(VarI2FromBool);
1186 CONVERTRANGE(VarI2FromBool, -32768, 32768);
1189 static void test_VarI2FromR4(void)
1191 CONVVARS(FLOAT);
1193 CHECKPTR(VarI2FromR4);
1194 CONVERT(VarI2FromR4, -32769.0f); EXPECT_OVERFLOW;
1195 CONVERT(VarI2FromR4, -32768.0f); EXPECT(-32768);
1196 CONVERT(VarI2FromR4, -1.0f); EXPECT(-1);
1197 CONVERT(VarI2FromR4, 0.0f); EXPECT(0);
1198 CONVERT(VarI2FromR4, 1.0f); EXPECT(1);
1199 CONVERT(VarI2FromR4, 32767.0f); EXPECT(32767);
1200 CONVERT(VarI2FromR4, 32768.0f); EXPECT_OVERFLOW;
1202 /* Rounding */
1203 CONVERT(VarI2FromR4, -1.5f); EXPECT(-2);
1204 CONVERT(VarI2FromR4, -0.6f); EXPECT(-1);
1205 CONVERT(VarI2FromR4, -0.5f); EXPECT(0);
1206 CONVERT(VarI2FromR4, -0.4f); EXPECT(0);
1207 CONVERT(VarI2FromR4, 0.4f); EXPECT(0);
1208 CONVERT(VarI2FromR4, 0.5f); EXPECT(0);
1209 CONVERT(VarI2FromR4, 0.6f); EXPECT(1);
1210 CONVERT(VarI2FromR4, 1.5f); EXPECT(2);
1213 static void test_VarI2FromR8(void)
1215 CONVVARS(DOUBLE);
1217 CHECKPTR(VarI2FromR8);
1218 CONVERT(VarI2FromR8, -32769.0); EXPECT_OVERFLOW;
1219 CONVERT(VarI2FromR8, -32768.0); EXPECT(-32768);
1220 CONVERT(VarI2FromR8, -1.0); EXPECT(-1);
1221 CONVERT(VarI2FromR8, 0.0); EXPECT(0);
1222 CONVERT(VarI2FromR8, 1.0); EXPECT(1);
1223 CONVERT(VarI2FromR8, 32767.0); EXPECT(32767);
1224 CONVERT(VarI2FromR8, 32768.0); EXPECT_OVERFLOW;
1226 /* Rounding */
1227 CONVERT(VarI2FromR8, -1.5); EXPECT(-2);
1228 CONVERT(VarI2FromR8, -0.6); EXPECT(-1);
1229 CONVERT(VarI2FromR8, -0.5); EXPECT(0);
1230 CONVERT(VarI2FromR8, -0.4); EXPECT(0);
1231 CONVERT(VarI2FromR8, 0.4); EXPECT(0);
1232 CONVERT(VarI2FromR8, 0.5); EXPECT(0);
1233 CONVERT(VarI2FromR8, 0.6); EXPECT(1);
1234 CONVERT(VarI2FromR8, 1.5); EXPECT(2);
1237 static void test_VarI2FromDate(void)
1239 CONVVARS(DATE);
1241 CHECKPTR(VarI2FromDate);
1242 CONVERT(VarI2FromDate, -32769.0); EXPECT_OVERFLOW;
1243 CONVERT(VarI2FromDate, -32768.0); EXPECT(-32768);
1244 CONVERT(VarI2FromDate, -1.0); EXPECT(-1);
1245 CONVERT(VarI2FromDate, 0.0); EXPECT(0);
1246 CONVERT(VarI2FromDate, 1.0); EXPECT(1);
1247 CONVERT(VarI2FromDate, 32767.0); EXPECT(32767);
1248 CONVERT(VarI2FromDate, 32768.0); EXPECT_OVERFLOW;
1250 /* Rounding */
1251 CONVERT(VarI2FromDate, -1.5); EXPECT(-2);
1252 CONVERT(VarI2FromDate, -0.6); EXPECT(-1);
1253 CONVERT(VarI2FromDate, -0.5); EXPECT(0);
1254 CONVERT(VarI2FromDate, -0.4); EXPECT(0);
1255 CONVERT(VarI2FromDate, 0.4); EXPECT(0);
1256 CONVERT(VarI2FromDate, 0.5); EXPECT(0);
1257 CONVERT(VarI2FromDate, 0.6); EXPECT(1);
1258 CONVERT(VarI2FromDate, 1.5); EXPECT(2);
1261 static void test_VarI2FromCy(void)
1263 CONVVARS(CY);
1265 CHECKPTR(VarI2FromCy);
1266 CONVERT_CY(VarI2FromCy,-32769); EXPECT_OVERFLOW;
1267 CONVERT_CY(VarI2FromCy,-32768); EXPECT(32768);
1268 CONVERT_CY(VarI2FromCy,-1); EXPECT(-1);
1269 CONVERT_CY(VarI2FromCy,0); EXPECT(0);
1270 CONVERT_CY(VarI2FromCy,1); EXPECT(1);
1271 CONVERT_CY(VarI2FromCy,32767); EXPECT(32767);
1272 CONVERT_CY(VarI2FromCy,32768); EXPECT_OVERFLOW;
1274 /* Rounding */
1275 CONVERT_CY(VarI2FromCy,-1.5); EXPECT(-2);
1276 CONVERT_CY(VarI2FromCy,-0.6); EXPECT(-1);
1277 CONVERT_CY(VarI2FromCy,-0.5); EXPECT(0);
1278 CONVERT_CY(VarI2FromCy,-0.4); EXPECT(0);
1279 CONVERT_CY(VarI2FromCy,0.4); EXPECT(0);
1280 CONVERT_CY(VarI2FromCy,0.5); EXPECT(0);
1281 CONVERT_CY(VarI2FromCy,0.6); EXPECT(1);
1282 CONVERT_CY(VarI2FromCy,1.5); EXPECT(2);
1285 static void test_VarI2FromDec(void)
1287 CONVVARS(DECIMAL);
1289 CHECKPTR(VarI2FromDec);
1291 CONVERT_BADDEC(VarI2FromDec);
1293 CONVERT_DEC(VarI2FromDec,0,0x80,0,32769); EXPECT_OVERFLOW;
1294 CONVERT_DEC(VarI2FromDec,0,0x80,0,32768); EXPECT(-32768);
1295 CONVERT_DEC(VarI2FromDec,0,0x80,0,1); EXPECT(-1);
1296 CONVERT_DEC(VarI2FromDec,0,0,0,0); EXPECT(0);
1297 CONVERT_DEC(VarI2FromDec,0,0,0,1); EXPECT(1);
1298 CONVERT_DEC(VarI2FromDec,0,0,0,32767); EXPECT(32767);
1299 CONVERT_DEC(VarI2FromDec,0,0,0,32768); EXPECT_OVERFLOW;
1301 CONVERT_DEC(VarI2FromDec,2,0x80,0,3276800); EXPECT(-32768);
1302 CONVERT_DEC(VarI2FromDec,2,0,0,3276700); EXPECT(32767);
1303 CONVERT_DEC(VarI2FromDec,2,0,0,3276800); EXPECT_OVERFLOW;
1306 static void test_VarI2FromStr(void)
1308 CONVVARS(LCID);
1309 OLECHAR buff[128];
1311 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1313 CHECKPTR(VarI2FromStr);
1315 CONVERT_STR(VarI2FromStr,NULL, 0); EXPECT_MISMATCH;
1316 CONVERT_STR(VarI2FromStr,"0", 0); EXPECT(0);
1317 CONVERT_STR(VarI2FromStr,"-32769", 0); EXPECT_OVERFLOW;
1318 CONVERT_STR(VarI2FromStr,"-32768", 0); EXPECT(-32768);
1319 CONVERT_STR(VarI2FromStr,"32767", 0); EXPECT(32767);
1320 CONVERT_STR(VarI2FromStr,"32768", 0); EXPECT_OVERFLOW;
1322 /* Rounding */
1323 CONVERT_STR(VarI2FromStr,"-1.5", 0); EXPECT(-2);
1324 CONVERT_STR(VarI2FromStr,"-0.6", 0); EXPECT(-1);
1325 CONVERT_STR(VarI2FromStr,"-0.5", 0); EXPECT(0);
1326 CONVERT_STR(VarI2FromStr,"-0.4", 0); EXPECT(0);
1327 CONVERT_STR(VarI2FromStr,"0.4", 0); EXPECT(0);
1328 CONVERT_STR(VarI2FromStr,"0.5", 0); EXPECT(0);
1329 CONVERT_STR(VarI2FromStr,"0.6", 0); EXPECT(1);
1330 CONVERT_STR(VarI2FromStr,"1.5", 0); EXPECT(2);
1333 static void test_VarI2Copy(void)
1335 COPYTEST(1, VT_I2, V_I2(&vSrc), V_I2(&vDst), V_I2REF(&vSrc), V_I2REF(&vDst), "%d");
1338 static void test_VarI2ChangeTypeEx(void)
1340 CONVVARS(CONV_TYPE);
1341 VARIANTARG vSrc, vDst;
1343 in = 1;
1345 INITIAL_TYPETEST(VT_I2, V_I2, "%d");
1346 COMMON_TYPETEST;
1349 #undef CONV_TYPE
1350 #define CONV_TYPE USHORT
1352 static void test_VarUI2FromI1(void)
1354 CONVVARS(signed char);
1355 int i;
1357 CHECKPTR(VarUI2FromI1);
1358 OVERFLOWRANGE(VarUI2FromI1, -128, 0);
1359 CONVERTRANGE(VarUI2FromI1, 0, 128);
1362 static void test_VarUI2FromI2(void)
1364 CONVVARS(SHORT);
1365 int i;
1367 CHECKPTR(VarUI2FromI2);
1368 OVERFLOWRANGE(VarUI2FromI2, -32768, 0);
1369 CONVERTRANGE(VarUI2FromI2, 0, 32768);
1372 static void test_VarUI2FromI4(void)
1374 CONVVARS(LONG);
1375 int i;
1377 CHECKPTR(VarUI2FromI4);
1378 OVERFLOWRANGE(VarUI2FromI4, -32768, 0);
1379 CONVERT(VarUI2FromI4, 0); EXPECT(0);
1380 CONVERT(VarUI2FromI4, 65535); EXPECT(65535);
1381 CONVERT(VarUI2FromI4, 65536); EXPECT_OVERFLOW;
1384 static void test_VarUI2FromI8(void)
1386 CONVVARS(LONG64);
1387 int i;
1389 CHECKPTR(VarUI2FromI8);
1390 OVERFLOWRANGE(VarUI2FromI8, -32768, 0);
1391 CONVERT(VarUI2FromI8, 0); EXPECT(0);
1392 CONVERT(VarUI2FromI8, 65535); EXPECT(65535);
1393 CONVERT(VarUI2FromI8, 65536); EXPECT_OVERFLOW;
1396 static void test_VarUI2FromUI1(void)
1398 CONVVARS(BYTE);
1399 int i;
1401 CHECKPTR(VarUI2FromUI1);
1402 CONVERTRANGE(VarUI2FromUI1, 0, 256);
1405 static void test_VarUI2FromUI4(void)
1407 CONVVARS(ULONG);
1409 CHECKPTR(VarUI2FromUI4);
1410 CONVERT(VarUI2FromUI4, 0); EXPECT(0);
1411 CONVERT(VarUI2FromUI4, 65535); EXPECT(65535);
1412 CONVERT(VarUI2FromUI4, 65536); EXPECT_OVERFLOW;
1415 static void test_VarUI2FromUI8(void)
1417 CONVVARS(ULONG64);
1419 CHECKPTR(VarUI2FromUI8);
1420 CONVERT(VarUI2FromUI8, 0); EXPECT(0);
1421 CONVERT(VarUI2FromUI8, 65535); EXPECT(65535);
1422 CONVERT(VarUI2FromUI8, 65536); EXPECT_OVERFLOW;
1425 static void test_VarUI2FromBool(void)
1427 CONVVARS(VARIANT_BOOL);
1428 int i;
1430 CHECKPTR(VarUI2FromBool);
1431 CONVERT(VarUI2FromBool, -1); EXPECT(65535); /* Wraps! */
1432 CONVERTRANGE(VarUI2FromBool, 0, 32768);
1435 static void test_VarUI2FromR4(void)
1437 CONVVARS(FLOAT);
1439 CHECKPTR(VarUI2FromR4);
1440 CONVERT(VarUI2FromR4, -1.0f); EXPECT_OVERFLOW;
1441 CONVERT(VarUI2FromR4, 0.0f); EXPECT(0);
1442 CONVERT(VarUI2FromR4, 1.0f); EXPECT(1);
1443 CONVERT(VarUI2FromR4, 65535.0f); EXPECT(65535);
1444 CONVERT(VarUI2FromR4, 65536.0f); EXPECT_OVERFLOW;
1446 /* Rounding */
1447 CONVERT(VarUI2FromR4, -1.5f); EXPECT_OVERFLOW;
1448 CONVERT(VarUI2FromR4, -0.6f); EXPECT_OVERFLOW;
1449 CONVERT(VarUI2FromR4, -0.5f); EXPECT(0);
1450 CONVERT(VarUI2FromR4, -0.4f); EXPECT(0);
1451 CONVERT(VarUI2FromR4, 0.4f); EXPECT(0);
1452 CONVERT(VarUI2FromR4, 0.5f); EXPECT(0);
1453 CONVERT(VarUI2FromR4, 0.6f); EXPECT(1);
1454 CONVERT(VarUI2FromR4, 1.5f); EXPECT(2);
1457 static void test_VarUI2FromR8(void)
1459 CONVVARS(DOUBLE);
1461 CHECKPTR(VarUI2FromR8);
1462 CONVERT(VarUI2FromR8, -1.0); EXPECT_OVERFLOW;
1463 CONVERT(VarUI2FromR8, 0.0); EXPECT(0);
1464 CONVERT(VarUI2FromR8, 1.0); EXPECT(1);
1465 CONVERT(VarUI2FromR8, 65535.0); EXPECT(65535);
1466 CONVERT(VarUI2FromR8, 65536.0); EXPECT_OVERFLOW;
1468 /* Rounding */
1469 CONVERT(VarUI2FromR8, -1.5); EXPECT_OVERFLOW;
1470 CONVERT(VarUI2FromR8, -0.6); EXPECT_OVERFLOW;
1471 CONVERT(VarUI2FromR8, -0.5); EXPECT(0);
1472 CONVERT(VarUI2FromR8, -0.4); EXPECT(0);
1473 CONVERT(VarUI2FromR8, 0.4); EXPECT(0);
1474 CONVERT(VarUI2FromR8, 0.5); EXPECT(0);
1475 CONVERT(VarUI2FromR8, 0.6); EXPECT(1);
1476 CONVERT(VarUI2FromR8, 1.5); EXPECT(2);
1479 static void test_VarUI2FromDate(void)
1481 CONVVARS(DATE);
1483 CHECKPTR(VarUI2FromDate);
1484 CONVERT(VarUI2FromDate, -1.0); EXPECT_OVERFLOW;
1485 CONVERT(VarUI2FromDate, 0.0); EXPECT(0);
1486 CONVERT(VarUI2FromDate, 1.0); EXPECT(1);
1487 CONVERT(VarUI2FromDate, 65535.0); EXPECT(65535);
1488 CONVERT(VarUI2FromDate, 65536.0); EXPECT_OVERFLOW;
1490 /* Rounding */
1491 CONVERT(VarUI2FromDate, -1.5); EXPECT_OVERFLOW;
1492 CONVERT(VarUI2FromDate, -0.6); EXPECT_OVERFLOW;
1493 CONVERT(VarUI2FromDate, -0.5); EXPECT(0);
1494 CONVERT(VarUI2FromDate, -0.4); EXPECT(0);
1495 CONVERT(VarUI2FromDate, 0.4); EXPECT(0);
1496 CONVERT(VarUI2FromDate, 0.5); EXPECT(0);
1497 CONVERT(VarUI2FromDate, 0.6); EXPECT(1);
1498 CONVERT(VarUI2FromDate, 1.5); EXPECT(2);
1501 static void test_VarUI2FromCy(void)
1503 CONVVARS(CY);
1505 CHECKPTR(VarUI2FromCy);
1506 CONVERT_CY(VarUI2FromCy,-1); EXPECT_OVERFLOW;
1507 CONVERT_CY(VarUI2FromCy,0); EXPECT(0);
1508 CONVERT_CY(VarUI2FromCy,1); EXPECT(1);
1509 CONVERT_CY(VarUI2FromCy,65535); EXPECT(65535);
1510 CONVERT_CY(VarUI2FromCy,65536); EXPECT_OVERFLOW;
1512 /* Rounding */
1513 CONVERT_CY(VarUI2FromCy,-1.5); EXPECT_OVERFLOW;
1514 CONVERT_CY(VarUI2FromCy,-0.6); EXPECT_OVERFLOW;
1515 CONVERT_CY(VarUI2FromCy,-0.5); EXPECT(0);
1516 CONVERT_CY(VarUI2FromCy,-0.4); EXPECT(0);
1517 CONVERT_CY(VarUI2FromCy,0.4); EXPECT(0);
1518 CONVERT_CY(VarUI2FromCy,0.5); EXPECT(0);
1519 CONVERT_CY(VarUI2FromCy,0.6); EXPECT(1);
1520 CONVERT_CY(VarUI2FromCy,1.5); EXPECT(2);
1523 static void test_VarUI2FromDec(void)
1525 CONVVARS(DECIMAL);
1527 CHECKPTR(VarUI2FromDec);
1529 CONVERT_BADDEC(VarUI2FromDec);
1531 CONVERT_DEC(VarUI2FromDec,0,0x80,0,1); EXPECT_OVERFLOW;
1532 CONVERT_DEC(VarUI2FromDec,0,0,0,0); EXPECT(0);
1533 CONVERT_DEC(VarUI2FromDec,0,0,0,1); EXPECT(1);
1534 CONVERT_DEC(VarUI2FromDec,0,0,0,65535); EXPECT(65535);
1535 CONVERT_DEC(VarUI2FromDec,0,0,0,65536); EXPECT_OVERFLOW;
1537 CONVERT_DEC(VarUI2FromDec,2,0x80,0,100); EXPECT_OVERFLOW;
1538 CONVERT_DEC(VarUI2FromDec,2,0,0,6553500); EXPECT(65535);
1539 CONVERT_DEC(VarUI2FromDec,2,0,0,6553600); EXPECT_OVERFLOW;
1542 static void test_VarUI2FromStr(void)
1544 CONVVARS(LCID);
1545 OLECHAR buff[128];
1547 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1549 CHECKPTR(VarUI2FromStr);
1551 CONVERT_STR(VarUI2FromStr,NULL, 0); EXPECT_MISMATCH;
1552 CONVERT_STR(VarUI2FromStr,"0", 0); EXPECT(0);
1553 CONVERT_STR(VarUI2FromStr,"-1", 0); EXPECT_OVERFLOW;
1554 CONVERT_STR(VarUI2FromStr,"65535", 0); EXPECT(65535);
1555 CONVERT_STR(VarUI2FromStr,"65536", 0); EXPECT_OVERFLOW;
1557 /* Rounding */
1558 CONVERT_STR(VarUI2FromStr,"-1.5", 0); EXPECT_OVERFLOW;
1559 CONVERT_STR(VarUI2FromStr,"-0.6", 0); EXPECT_OVERFLOW;
1560 CONVERT_STR(VarUI2FromStr,"-0.5", 0); EXPECT(0);
1561 CONVERT_STR(VarUI2FromStr,"-0.4", 0); EXPECT(0);
1562 CONVERT_STR(VarUI2FromStr,"0.4", 0); EXPECT(0);
1563 CONVERT_STR(VarUI2FromStr,"0.5", 0); EXPECT(0);
1564 CONVERT_STR(VarUI2FromStr,"0.6", 0); EXPECT(1);
1565 CONVERT_STR(VarUI2FromStr,"1.5", 0); EXPECT(2);
1568 static void test_VarUI2Copy(void)
1570 if (!IS_ANCIENT)
1572 COPYTEST(1, VT_UI2, V_UI2(&vSrc), V_UI2(&vDst), V_UI2REF(&vSrc), V_UI2REF(&vDst), "%d");
1576 static void test_VarUI2ChangeTypeEx(void)
1578 CONVVARS(CONV_TYPE);
1579 VARIANTARG vSrc, vDst;
1581 in = 1;
1583 if (!IS_ANCIENT)
1585 INITIAL_TYPETEST(VT_UI2, V_UI2, "%d");
1586 COMMON_TYPETEST;
1591 * VT_I4/VT_UI4
1594 #undef CONV_TYPE
1595 #define CONV_TYPE LONG
1596 #undef EXPECTRES
1597 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%ld")
1600 static void test_VarI4FromI1(void)
1602 CONVVARS(signed char);
1603 int i;
1605 CHECKPTR(VarI4FromI1);
1606 CONVERTRANGE(VarI4FromI1, -128, 128);
1609 static void test_VarI4FromI2(void)
1611 CONVVARS(SHORT);
1612 int i;
1614 CHECKPTR(VarI4FromI2);
1615 CONVERTRANGE(VarI4FromI2, -32768, 32768);
1618 static void test_VarI4FromI8(void)
1620 CONVVARS(LONG64);
1622 CHECKPTR(VarI4FromI8);
1623 CHECKPTR(VarI4FromDec);
1625 CONVERT(VarI4FromI8, -1); EXPECT(-1);
1626 CONVERT(VarI4FromI8, 0); EXPECT(0);
1627 CONVERT(VarI4FromI8, 1); EXPECT(1);
1629 CONVERT_I8(VarI4FromI8, -1, 2147483647ul); EXPECT_OVERFLOW;
1630 CONVERT_I8(VarI4FromI8, -1, 2147483648ul); EXPECT(-2147483647 - 1);
1631 CONVERT_I8(VarI4FromI8, 0, 2147483647ul); EXPECT(2147483647);
1632 CONVERT_I8(VarI4FromI8, 0, 2147483648ul); EXPECT_OVERFLOW;
1635 static void test_VarI4FromUI1(void)
1637 CONVVARS(BYTE);
1638 int i;
1640 CHECKPTR(VarI4FromUI1);
1641 CONVERTRANGE(VarI4FromUI1, 0, 256);
1644 static void test_VarI4FromUI2(void)
1646 CONVVARS(USHORT);
1647 int i;
1649 CHECKPTR(VarI4FromUI2);
1650 CONVERTRANGE(VarI4FromUI2, 0, 65536);
1653 static void test_VarI4FromUI4(void)
1655 CONVVARS(ULONG);
1657 CHECKPTR(VarI4FromUI4);
1658 CONVERT(VarI4FromUI4, 0); EXPECT(0);
1659 CONVERT(VarI4FromUI4, 1); EXPECT(1);
1660 CONVERT(VarI4FromUI4, 2147483647); EXPECT(2147483647);
1661 CONVERT(VarI4FromUI4, 2147483648ul); EXPECT_OVERFLOW;
1664 static void test_VarI4FromUI8(void)
1666 CONVVARS(ULONG64);
1668 CHECKPTR(VarI4FromUI8);
1669 CONVERT(VarI4FromUI8, 0); EXPECT(0);
1670 CONVERT(VarI4FromUI8, 1); EXPECT(1);
1671 CONVERT(VarI4FromUI8, 2147483647); EXPECT(2147483647);
1672 CONVERT(VarI4FromUI8, 2147483648ul); EXPECT_OVERFLOW;
1675 static void test_VarI4FromBool(void)
1677 CONVVARS(VARIANT_BOOL);
1678 int i;
1680 CHECKPTR(VarI4FromBool);
1681 CONVERTRANGE(VarI4FromBool, -32768, 32768);
1684 static void test_VarI4FromR4(void)
1686 CONVVARS(FLOAT);
1688 CHECKPTR(VarI4FromR4);
1690 /* min/max values are not exactly representable in a float */
1691 CONVERT(VarI4FromR4, -1.0f); EXPECT(-1);
1692 CONVERT(VarI4FromR4, 0.0f); EXPECT(0);
1693 CONVERT(VarI4FromR4, 1.0f); EXPECT(1);
1695 CONVERT(VarI4FromR4, -1.5f); EXPECT(-2);
1696 CONVERT(VarI4FromR4, -0.6f); EXPECT(-1);
1697 CONVERT(VarI4FromR4, -0.5f); EXPECT(0);
1698 CONVERT(VarI4FromR4, -0.4f); EXPECT(0);
1699 CONVERT(VarI4FromR4, 0.4f); EXPECT(0);
1700 CONVERT(VarI4FromR4, 0.5f); EXPECT(0);
1701 CONVERT(VarI4FromR4, 0.6f); EXPECT(1);
1702 CONVERT(VarI4FromR4, 1.5f); EXPECT(2);
1705 static void test_VarI4FromR8(void)
1707 CONVVARS(DOUBLE);
1709 CHECKPTR(VarI4FromR8);
1710 CONVERT(VarI4FromR8, -2147483649.0); EXPECT_OVERFLOW;
1711 CONVERT(VarI4FromR8, -2147483648.0); EXPECT(-2147483647 - 1);
1712 CONVERT(VarI4FromR8, -1.0); EXPECT(-1);
1713 CONVERT(VarI4FromR8, 0.0); EXPECT(0);
1714 CONVERT(VarI4FromR8, 1.0); EXPECT(1);
1715 CONVERT(VarI4FromR8, 2147483647.0); EXPECT(2147483647);
1716 CONVERT(VarI4FromR8, 2147483648.0); EXPECT_OVERFLOW;
1718 CONVERT(VarI4FromR8, -1.5); EXPECT(-2);
1719 CONVERT(VarI4FromR8, -0.6); EXPECT(-1);
1720 CONVERT(VarI4FromR8, -0.5); EXPECT(0);
1721 CONVERT(VarI4FromR8, -0.4); EXPECT(0);
1722 CONVERT(VarI4FromR8, 0.4); EXPECT(0);
1723 CONVERT(VarI4FromR8, 0.5); EXPECT(0);
1724 CONVERT(VarI4FromR8, 0.6); EXPECT(1);
1725 CONVERT(VarI4FromR8, 1.5); EXPECT(2);
1728 static void test_VarI4FromDate(void)
1730 CONVVARS(DATE);
1732 CHECKPTR(VarI4FromDate);
1733 CONVERT(VarI4FromDate, -2147483649.0); EXPECT_OVERFLOW;
1734 CONVERT(VarI4FromDate, -2147483648.0); EXPECT(-2147483647 - 1);
1735 CONVERT(VarI4FromDate, -1.0); EXPECT(-1);
1736 CONVERT(VarI4FromDate, 0.0); EXPECT(0);
1737 CONVERT(VarI4FromDate, 1.0); EXPECT(1);
1738 CONVERT(VarI4FromDate, 2147483647.0); EXPECT(2147483647);
1739 CONVERT(VarI4FromDate, 2147483648.0); EXPECT_OVERFLOW;
1741 CONVERT(VarI4FromDate, -1.5); EXPECT(-2);
1742 CONVERT(VarI4FromDate, -0.6); EXPECT(-1);
1743 CONVERT(VarI4FromDate, -0.5); EXPECT(0);
1744 CONVERT(VarI4FromDate, -0.4); EXPECT(0);
1745 CONVERT(VarI4FromDate, 0.4); EXPECT(0);
1746 CONVERT(VarI4FromDate, 0.5); EXPECT(0);
1747 CONVERT(VarI4FromDate, 0.6); EXPECT(1);
1748 CONVERT(VarI4FromDate, 1.5); EXPECT(2);
1751 static void test_VarI4FromCy(void)
1753 CONVVARS(CY);
1755 CHECKPTR(VarI4FromCy);
1756 CONVERT_CY(VarI4FromCy,-1); EXPECT(-1);
1757 CONVERT_CY(VarI4FromCy,0); EXPECT(0);
1758 CONVERT_CY(VarI4FromCy,1); EXPECT(1);
1760 CONVERT_CY64(VarI4FromCy,-1,2147483647ul); EXPECT_OVERFLOW;
1761 CONVERT_CY64(VarI4FromCy,-1,2147483648ul); EXPECT(-2147483647 - 1);
1762 CONVERT_CY64(VarI4FromCy,0,2147483647ul); EXPECT(2147483647ul);
1763 CONVERT_CY64(VarI4FromCy,0,2147483648ul); EXPECT_OVERFLOW;
1765 CONVERT_CY(VarI4FromCy,-1.5); EXPECT(-2);
1766 CONVERT_CY(VarI4FromCy,-0.6); EXPECT(-1);
1767 CONVERT_CY(VarI4FromCy,-0.5); EXPECT(0);
1768 CONVERT_CY(VarI4FromCy,-0.4); EXPECT(0);
1769 CONVERT_CY(VarI4FromCy,0.4); EXPECT(0);
1770 CONVERT_CY(VarI4FromCy,0.5); EXPECT(0);
1771 CONVERT_CY(VarI4FromCy,0.6); EXPECT(1);
1772 CONVERT_CY(VarI4FromCy,1.5); EXPECT(2);
1775 static void test_VarI4FromDec(void)
1777 CONVVARS(DECIMAL);
1779 CHECKPTR(VarI4FromDec);
1781 CONVERT_BADDEC(VarI4FromDec);
1783 CONVERT_DEC(VarI4FromDec,0,0x80,0,1); EXPECT(-1);
1784 CONVERT_DEC(VarI4FromDec,0,0,0,0); EXPECT(0);
1785 CONVERT_DEC(VarI4FromDec,0,0,0,1); EXPECT(1);
1787 CONVERT_DEC64(VarI4FromDec,0,0x80,0,0,2147483649ul); EXPECT_OVERFLOW;
1788 CONVERT_DEC64(VarI4FromDec,0,0x80,0,0,2147483648ul); EXPECT(-2147483647 - 1);
1789 CONVERT_DEC64(VarI4FromDec,0,0,0,0,2147483647ul); EXPECT(2147483647ul);
1790 CONVERT_DEC64(VarI4FromDec,0,0,0,0,2147483648ul); EXPECT_OVERFLOW;
1792 CONVERT_DEC64(VarI4FromDec,2,0x80,0,50,100); EXPECT_OVERFLOW;
1793 CONVERT_DEC64(VarI4FromDec,2,0x80,0,50,0); EXPECT(-2147483647 - 1);
1794 CONVERT_DEC64(VarI4FromDec,2,0,0,49,4294967196ul); EXPECT(2147483647);
1795 CONVERT_DEC64(VarI4FromDec,2,0,0,50,0); EXPECT_OVERFLOW;
1798 static void test_VarI4FromStr(void)
1800 CONVVARS(LCID);
1801 OLECHAR buff[128];
1803 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1805 CHECKPTR(VarI4FromStr);
1807 CONVERT_STR(VarI4FromStr,NULL,0); EXPECT_MISMATCH;
1808 CONVERT_STR(VarI4FromStr,"0",0); EXPECT(0);
1809 CONVERT_STR(VarI4FromStr,"-2147483649",0); EXPECT_OVERFLOW;
1810 CONVERT_STR(VarI4FromStr,"-2147483648",0); EXPECT(-2147483647 -1);
1811 CONVERT_STR(VarI4FromStr,"2147483647",0); EXPECT(2147483647);
1812 CONVERT_STR(VarI4FromStr,"2147483648",0); EXPECT_OVERFLOW;
1814 /* Rounding */
1815 CONVERT_STR(VarI4FromStr,"-1.5",0); EXPECT(-2);
1816 CONVERT_STR(VarI4FromStr,"-0.6",0); EXPECT(-1);
1817 CONVERT_STR(VarI4FromStr,"-0.5",0); EXPECT(0);
1818 CONVERT_STR(VarI4FromStr,"-0.4",0); EXPECT(0);
1819 CONVERT_STR(VarI4FromStr,"0.4",0); EXPECT(0);
1820 CONVERT_STR(VarI4FromStr,"0.5",0); EXPECT(0);
1821 CONVERT_STR(VarI4FromStr,"0.6",0); EXPECT(1);
1822 CONVERT_STR(VarI4FromStr,"1.5",0); EXPECT(2);
1825 static void test_VarI4Copy(void)
1827 COPYTEST(1l, VT_I4, V_I4(&vSrc), V_I4(&vDst), V_I4REF(&vSrc), V_I4REF(&vDst), "%ld");
1830 static void test_VarI4ChangeTypeEx(void)
1832 CONVVARS(CONV_TYPE);
1833 VARIANTARG vSrc, vDst;
1835 in = 1;
1837 INITIAL_TYPETEST(VT_I4, V_I4, "%ld");
1838 COMMON_TYPETEST;
1841 #undef CONV_TYPE
1842 #define CONV_TYPE ULONG
1843 #undef EXPECTRES
1844 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%lu")
1846 static void test_VarUI4FromI1(void)
1848 CONVVARS(signed char);
1849 int i;
1851 CHECKPTR(VarUI4FromI1);
1852 OVERFLOWRANGE(VarUI4FromI1, -127, 0);
1853 CONVERTRANGE(VarUI4FromI1, 0, 128);
1856 static void test_VarUI4FromI2(void)
1858 CONVVARS(SHORT);
1859 int i;
1861 CHECKPTR(VarUI4FromI2);
1862 OVERFLOWRANGE(VarUI4FromI2, -32768, 0);
1863 CONVERTRANGE(VarUI4FromI2, 0, 32768);
1866 static void test_VarUI4FromUI2(void)
1868 CONVVARS(USHORT);
1869 int i;
1871 CHECKPTR(VarUI4FromUI2);
1872 CONVERTRANGE(VarUI4FromUI2, 0, 65536);
1875 static void test_VarUI4FromI8(void)
1877 CONVVARS(LONG64);
1879 CHECKPTR(VarUI4FromI8);
1880 CONVERT(VarUI4FromI8, -1); EXPECT_OVERFLOW;
1881 CONVERT(VarUI4FromI8, 0); EXPECT(0);
1882 CONVERT(VarUI4FromI8, 1); EXPECT(1);
1883 CONVERT(VarUI4FromI8, 4294967295ul); EXPECT(4294967295ul);
1884 CONVERT_I8(VarUI4FromI8, 1, 0); EXPECT_OVERFLOW;
1887 static void test_VarUI4FromUI1(void)
1889 CONVVARS(BYTE);
1890 int i;
1892 CHECKPTR(VarUI4FromUI1);
1893 CONVERTRANGE(VarUI4FromUI1, 0, 256);
1896 static void test_VarUI4FromI4(void)
1898 CONVVARS(int);
1900 CHECKPTR(VarUI4FromI4);
1901 CONVERT(VarUI4FromI4, -1); EXPECT_OVERFLOW;
1902 CONVERT(VarUI4FromI4, 0); EXPECT(0);
1903 CONVERT(VarUI4FromI4, 1); EXPECT(1);
1904 CONVERT(VarUI4FromI4, 2147483647); EXPECT(2147483647);
1907 static void test_VarUI4FromUI8(void)
1909 CONVVARS(ULONG64);
1911 CHECKPTR(VarUI4FromUI8);
1912 CONVERT(VarUI4FromUI8, 0); EXPECT(0);
1913 CONVERT(VarUI4FromUI8, 1); EXPECT(1);
1914 CONVERT(VarUI4FromI8, 4294967295ul); EXPECT(4294967295ul);
1915 CONVERT_I8(VarUI4FromI8, 1, 0); EXPECT_OVERFLOW;
1918 static void test_VarUI4FromBool(void)
1920 CONVVARS(VARIANT_BOOL);
1921 int i;
1923 CHECKPTR(VarUI4FromBool);
1924 CONVERTRANGE(VarUI4FromBool, -32768, 32768);
1927 static void test_VarUI4FromR4(void)
1929 CONVVARS(FLOAT);
1931 CHECKPTR(VarUI4FromR4);
1932 /* We can't test max values as they are not exactly representable in a float */
1933 CONVERT(VarUI4FromR4, -1.0f); EXPECT_OVERFLOW;
1934 CONVERT(VarUI4FromR4, 0.0f); EXPECT(0);
1935 CONVERT(VarUI4FromR4, 1.0f); EXPECT(1);
1937 CONVERT(VarUI4FromR4, -1.5f); EXPECT_OVERFLOW;
1938 CONVERT(VarUI4FromR4, -0.6f); EXPECT_OVERFLOW;
1939 CONVERT(VarUI4FromR4, -0.5f); EXPECT(0);
1940 CONVERT(VarUI4FromR4, -0.4f); EXPECT(0);
1941 CONVERT(VarUI4FromR4, 0.4f); EXPECT(0);
1942 CONVERT(VarUI4FromR4, 0.5f); EXPECT(0);
1943 CONVERT(VarUI4FromR4, 0.6f); EXPECT(1);
1944 CONVERT(VarUI4FromR4, 1.5f); EXPECT(2);
1948 static void test_VarUI4FromR8(void)
1950 CONVVARS(DOUBLE);
1952 CHECKPTR(VarUI4FromR8);
1953 CONVERT(VarUI4FromR8, -1.0); EXPECT_OVERFLOW;
1954 CONVERT(VarUI4FromR8, 0.0); EXPECT(0);
1955 CONVERT(VarUI4FromR8, 1.0); EXPECT(1);
1956 CONVERT(VarUI4FromR8, 4294967295.0); EXPECT(4294967295ul);
1957 CONVERT(VarUI4FromR8, 4294967296.0); EXPECT_OVERFLOW;
1959 CONVERT(VarUI4FromR8, -1.5); EXPECT_OVERFLOW;
1960 CONVERT(VarUI4FromR8, -0.6); EXPECT_OVERFLOW;
1961 CONVERT(VarUI4FromR8, -0.5); EXPECT(0);
1962 CONVERT(VarUI4FromR8, -0.4); EXPECT(0);
1963 CONVERT(VarUI4FromR8, 0.4); EXPECT(0);
1964 CONVERT(VarUI4FromR8, 0.5); EXPECT(0);
1965 CONVERT(VarUI4FromR8, 0.6); EXPECT(1);
1966 CONVERT(VarUI4FromR8, 1.5); EXPECT(2);
1969 static void test_VarUI4FromDate(void)
1971 CONVVARS(DOUBLE);
1973 CHECKPTR(VarUI4FromDate);
1974 CONVERT(VarUI4FromDate, -1.0); EXPECT_OVERFLOW;
1975 CONVERT(VarUI4FromDate, 0.0); EXPECT(0);
1976 CONVERT(VarUI4FromDate, 1.0); EXPECT(1);
1977 CONVERT(VarUI4FromDate, 4294967295.0); EXPECT(4294967295ul);
1978 CONVERT(VarUI4FromDate, 4294967296.0); EXPECT_OVERFLOW;
1980 CONVERT(VarUI4FromDate, -1.5); EXPECT_OVERFLOW;
1981 CONVERT(VarUI4FromDate, -0.6); EXPECT_OVERFLOW;
1982 CONVERT(VarUI4FromDate, -0.5); EXPECT(0);
1983 CONVERT(VarUI4FromDate, -0.4); EXPECT(0);
1984 CONVERT(VarUI4FromDate, 0.4); EXPECT(0);
1985 CONVERT(VarUI4FromDate, 0.5); EXPECT(0);
1986 CONVERT(VarUI4FromDate, 0.6); EXPECT(1);
1987 CONVERT(VarUI4FromDate, 1.5); EXPECT(2);
1990 static void test_VarUI4FromCy(void)
1992 CONVVARS(CY);
1994 CHECKPTR(VarUI4FromCy);
1995 CONVERT_CY(VarUI4FromCy,-1); EXPECT_OVERFLOW;
1996 CONVERT_CY(VarUI4FromCy,0); EXPECT(0);
1997 CONVERT_CY(VarUI4FromCy,1); EXPECT(1);
1998 CONVERT_CY64(VarUI4FromCy,0,4294967295ul); EXPECT(4294967295ul);
1999 CONVERT_CY64(VarUI4FromCy,1,0); EXPECT_OVERFLOW;
2001 CONVERT_CY(VarUI4FromCy,-1.5); EXPECT_OVERFLOW;
2002 CONVERT_CY(VarUI4FromCy,-0.6); EXPECT_OVERFLOW;
2003 CONVERT_CY(VarUI4FromCy,-0.5); EXPECT(0);
2004 CONVERT_CY(VarUI4FromCy,-0.4); EXPECT(0);
2005 CONVERT_CY(VarUI4FromCy,0.4); EXPECT(0);
2006 CONVERT_CY(VarUI4FromCy,0.5); EXPECT(0);
2007 CONVERT_CY(VarUI4FromCy,0.6); EXPECT(1);
2008 CONVERT_CY(VarUI4FromCy,1.5); EXPECT(2);
2011 static void test_VarUI4FromDec(void)
2013 CONVVARS(DECIMAL);
2015 CHECKPTR(VarUI4FromDec);
2017 CONVERT_BADDEC(VarUI4FromDec);
2019 CONVERT_DEC(VarUI4FromDec,0,0x80,0,1); EXPECT_OVERFLOW;
2020 CONVERT_DEC(VarUI4FromDec,0,0,0,0); EXPECT(0);
2021 CONVERT_DEC(VarUI4FromDec,0,0,0,1); EXPECT(1);
2022 CONVERT_DEC64(VarUI4FromDec,0,0,0,0,4294967295ul); EXPECT(4294967295ul);
2023 CONVERT_DEC64(VarUI4FromDec,0,0,0,1,0); EXPECT_OVERFLOW;
2025 CONVERT_DEC64(VarUI4FromDec,2,0,0,99,4294967196ul); EXPECT(4294967295ul);
2026 CONVERT_DEC64(VarUI4FromDec,2,0,0,100,0); EXPECT_OVERFLOW;
2029 static void test_VarUI4FromStr(void)
2031 CONVVARS(LCID);
2032 OLECHAR buff[128];
2034 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2036 CHECKPTR(VarUI4FromStr);
2038 CONVERT_STR(VarUI4FromStr,NULL,0); EXPECT_MISMATCH;
2039 CONVERT_STR(VarUI4FromStr,"-1",0); EXPECT_OVERFLOW;
2040 CONVERT_STR(VarUI4FromStr,"0",0); EXPECT(0);
2041 CONVERT_STR(VarUI4FromStr,"4294967295",0); EXPECT(4294967295ul);
2042 CONVERT_STR(VarUI4FromStr,"4294967296",0); EXPECT_OVERFLOW;
2044 /* Rounding */
2045 CONVERT_STR(VarUI4FromStr,"-1.5",0); EXPECT_OVERFLOW;
2046 CONVERT_STR(VarUI4FromStr,"-0.6",0); EXPECT_OVERFLOW;
2047 CONVERT_STR(VarUI4FromStr,"-0.5",0); EXPECT(0);
2048 CONVERT_STR(VarUI4FromStr,"-0.4",0); EXPECT(0);
2049 CONVERT_STR(VarUI4FromStr,"0.4",0); EXPECT(0);
2050 CONVERT_STR(VarUI4FromStr,"0.5",0); EXPECT(0);
2051 CONVERT_STR(VarUI4FromStr,"0.6",0); EXPECT(1);
2052 CONVERT_STR(VarUI4FromStr,"1.5",0); EXPECT(2);
2055 static void test_VarUI4Copy(void)
2057 if (!IS_ANCIENT)
2059 COPYTEST(1ul, VT_UI4, V_UI4(&vSrc), V_UI4(&vDst), V_UI4REF(&vSrc), V_UI4REF(&vDst), "%lu");
2063 static void test_VarUI4ChangeTypeEx(void)
2065 CONVVARS(CONV_TYPE);
2066 VARIANTARG vSrc, vDst;
2068 in = 1;
2070 if (!IS_ANCIENT)
2072 INITIAL_TYPETEST(VT_UI4, V_UI4, "%lu");
2073 COMMON_TYPETEST;
2078 * VT_I8/VT_UI8
2081 #undef CONV_TYPE
2082 #define CONV_TYPE LONG64
2083 #undef EXPECTRES
2084 #define EXPECTRES(res, x) \
2085 ok(hres == S_OK || ((HRESULT)res != S_OK && hres == (HRESULT)res), \
2086 "expected hres " #x ", got hres=0x%08lx\n", hres)
2088 #define EXPECTI8(x) \
2089 ok((hres == S_OK && out == (CONV_TYPE)(x)), \
2090 "expected " #x "(%lu,%lu), got (%lu,%lu); hres=0x%08lx\n", \
2091 (ULONG)((LONG64)(x) >> 32), (ULONG)((x) & 0xffffffff), \
2092 (ULONG)(out >> 32), (ULONG)(out & 0xffffffff), hres)
2094 #define EXPECTI864(x,y) \
2095 ok(hres == S_OK && (out >> 32) == (CONV_TYPE)(x) && (out & 0xffffffff) == (CONV_TYPE)(y), \
2096 "expected " #x "(%lu,%lu), got (%lu,%lu); hres=0x%08lx\n", \
2097 (ULONG)(x), (ULONG)(y), \
2098 (ULONG)(out >> 32), (ULONG)(out & 0xffffffff), hres)
2100 static void test_VarI8FromI1(void)
2102 CONVVARS(signed char);
2103 int i;
2105 CHECKPTR(VarI8FromI1);
2106 for (i = -128; i < 128; i++)
2108 CONVERT(VarI8FromI1,i); EXPECTI8(i);
2112 static void test_VarI8FromUI1(void)
2114 CONVVARS(BYTE);
2115 int i;
2117 CHECKPTR(VarI8FromUI1);
2118 for (i = 0; i < 256; i++)
2120 CONVERT(VarI8FromUI1,i); EXPECTI8(i);
2124 static void test_VarI8FromI2(void)
2126 CONVVARS(SHORT);
2127 int i;
2129 CHECKPTR(VarI8FromI2);
2130 for (i = -32768; i < 32768; i++)
2132 CONVERT(VarI8FromI2,i); EXPECTI8(i);
2136 static void test_VarI8FromUI2(void)
2138 CONVVARS(USHORT);
2139 int i;
2141 CHECKPTR(VarI8FromUI2);
2142 for (i = -0; i < 65535; i++)
2144 CONVERT(VarI8FromUI2,i); EXPECTI8(i);
2148 static void test_VarI8FromUI4(void)
2150 CONVVARS(ULONG);
2152 CHECKPTR(VarI8FromUI4);
2153 CONVERT(VarI8FromUI4, 0); EXPECTI8(0);
2154 CONVERT(VarI8FromUI4, 1); EXPECTI8(1);
2155 CONVERT(VarI8FromUI4, 4294967295ul); EXPECTI8(4294967295ul);
2158 static void test_VarI8FromR4(void)
2160 CONVVARS(FLOAT);
2162 CHECKPTR(VarI8FromR4);
2164 CONVERT(VarI8FromR4, -128.0f); EXPECTI8(-128);
2165 CONVERT(VarI8FromR4, -1.0f); EXPECTI8(-1);
2166 CONVERT(VarI8FromR4, 0.0f); EXPECTI8(0);
2167 CONVERT(VarI8FromR4, 1.0f); EXPECTI8(1);
2168 CONVERT(VarI8FromR4, 127.0f); EXPECTI8(127);
2170 CONVERT(VarI8FromR4, -1.5f); EXPECTI8(-2);
2171 CONVERT(VarI8FromR4, -0.6f); EXPECTI8(-1);
2172 CONVERT(VarI8FromR4, -0.5f); EXPECTI8(0);
2173 CONVERT(VarI8FromR4, -0.4f); EXPECTI8(0);
2174 CONVERT(VarI8FromR4, 0.4f); EXPECTI8(0);
2175 CONVERT(VarI8FromR4, 0.5f); EXPECTI8(0);
2176 CONVERT(VarI8FromR4, 0.6f); EXPECTI8(1);
2177 CONVERT(VarI8FromR4, 1.5f); EXPECTI8(2);
2180 static void test_VarI8FromR8(void)
2182 CONVVARS(DOUBLE);
2184 CHECKPTR(VarI8FromR8);
2185 CONVERT(VarI8FromR8, -128.0); EXPECTI8(-128);
2186 CONVERT(VarI8FromR8, -1.0); EXPECTI8(-1);
2187 CONVERT(VarI8FromR8, 0.0); EXPECTI8(0);
2188 CONVERT(VarI8FromR8, 1.0); EXPECTI8(1);
2189 CONVERT(VarI8FromR8, 127.0); EXPECTI8(127);
2191 CONVERT(VarI8FromR8, -1.5); EXPECTI8(-2);
2192 CONVERT(VarI8FromR8, -0.6); EXPECTI8(-1);
2193 CONVERT(VarI8FromR8, -0.5); EXPECTI8(0);
2194 CONVERT(VarI8FromR8, -0.4); EXPECTI8(0);
2195 CONVERT(VarI8FromR8, 0.4); EXPECTI8(0);
2196 CONVERT(VarI8FromR8, 0.5); EXPECTI8(0);
2197 CONVERT(VarI8FromR8, 0.6); EXPECTI8(1);
2198 CONVERT(VarI8FromR8, 1.5); EXPECTI8(2);
2201 static void test_VarI8FromDate(void)
2203 CONVVARS(DATE);
2205 CHECKPTR(VarI8FromDate);
2206 CONVERT(VarI8FromDate, -128.0); EXPECTI8(-128);
2207 CONVERT(VarI8FromDate, -1.0); EXPECTI8(-1);
2208 CONVERT(VarI8FromDate, 0.0); EXPECTI8(0);
2209 CONVERT(VarI8FromDate, 1.0); EXPECTI8(1);
2210 CONVERT(VarI8FromDate, 127.0); EXPECTI8(127);
2212 CONVERT(VarI8FromDate, -1.5); EXPECTI8(-2);
2213 CONVERT(VarI8FromDate, -0.6); EXPECTI8(-1);
2214 CONVERT(VarI8FromDate, -0.5); EXPECTI8(0);
2215 CONVERT(VarI8FromDate, -0.4); EXPECTI8(0);
2216 CONVERT(VarI8FromDate, 0.4); EXPECTI8(0);
2217 CONVERT(VarI8FromDate, 0.5); EXPECTI8(0);
2218 CONVERT(VarI8FromDate, 0.6); EXPECTI8(1);
2219 CONVERT(VarI8FromDate, 1.5); EXPECTI8(2);
2222 static void test_VarI8FromBool(void)
2224 CONVVARS(VARIANT_BOOL);
2225 int i;
2227 CHECKPTR(VarI8FromBool);
2228 for (i = -32768; i < 32768; i++)
2230 CONVERT(VarI8FromBool,i); EXPECTI8(i);
2234 static void test_VarI8FromUI8(void)
2236 CONVVARS(ULONG64);
2238 CHECKPTR(VarI8FromUI8);
2239 CONVERT(VarI8FromUI8, 0); EXPECTI8(0);
2240 CONVERT(VarI8FromUI8, 1); EXPECTI8(1);
2241 CONVERT_I8(VarI8FromUI8, 0x7fffffff, 0xffffffff); EXPECTI864(0x7fffffff, 0xffffffff);
2242 CONVERT_I8(VarI8FromUI8, 0x80000000, 0); EXPECT_OVERFLOW;
2245 static void test_VarI8FromCy(void)
2247 CONVVARS(CY);
2249 CHECKPTR(VarI8FromCy);
2250 CONVERT_CY(VarI8FromCy,-128); EXPECTI8(-129);
2251 CONVERT_CY(VarI8FromCy,-1); EXPECTI8(-2);
2252 CONVERT_CY(VarI8FromCy,0); EXPECTI8(0);
2253 CONVERT_CY(VarI8FromCy,1); EXPECTI8(1);
2254 CONVERT_CY(VarI8FromCy,127); EXPECTI8(127);
2256 CONVERT_CY(VarI8FromCy,-1.5); EXPECTI8(-2);
2257 CONVERT_CY(VarI8FromCy,-0.6); EXPECTI8(-1);
2258 CONVERT_CY(VarI8FromCy,-0.5); EXPECTI8(-1);
2259 CONVERT_CY(VarI8FromCy,-0.4); EXPECTI8(-1);
2260 CONVERT_CY(VarI8FromCy,0.4); EXPECTI8(0);
2261 CONVERT_CY(VarI8FromCy,0.5); EXPECTI8(0);
2262 CONVERT_CY(VarI8FromCy,0.6); EXPECTI8(1);
2263 CONVERT_CY(VarI8FromCy,1.5); EXPECTI8(2);
2266 static void test_VarI8FromDec(void)
2268 CONVVARS(DECIMAL);
2270 CHECKPTR(VarI8FromDec);
2272 CONVERT_BADDEC(VarI8FromDec);
2274 CONVERT_DEC(VarI8FromDec,0,0x80,0,128); EXPECTI8(-128);
2275 CONVERT_DEC(VarI8FromDec,0,0x80,0,1); EXPECTI8(-1);
2276 CONVERT_DEC(VarI8FromDec,0,0,0,0); EXPECTI8(0);
2277 CONVERT_DEC(VarI8FromDec,0,0,0,1); EXPECTI8(1);
2278 CONVERT_DEC(VarI8FromDec,0,0,0,127); EXPECTI8(127);
2280 CONVERT_DEC(VarI8FromDec,2,0x80,0,12700); EXPECTI8(-127);
2281 CONVERT_DEC(VarI8FromDec,2,0,0,12700); EXPECTI8(127);
2284 static void test_VarI8FromStr(void)
2286 CONVVARS(LCID);
2287 OLECHAR buff[128];
2289 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2291 CHECKPTR(VarI8FromStr);
2293 CONVERT_STR(VarI8FromStr,NULL,0); EXPECT_MISMATCH;
2294 CONVERT_STR(VarI8FromStr,"0",0); EXPECTI8(0);
2295 CONVERT_STR(VarI8FromStr,"-1",0); EXPECTI8(-1);
2296 CONVERT_STR(VarI8FromStr,"2147483647",0); EXPECTI8(2147483647);
2298 CONVERT_STR(VarI8FromStr,"-1.5",0); EXPECTI8(-2);
2299 CONVERT_STR(VarI8FromStr,"-0.6",0); EXPECTI8(-1);
2300 CONVERT_STR(VarI8FromStr,"-0.5",0); EXPECTI8(0);
2301 CONVERT_STR(VarI8FromStr,"-0.4",0); EXPECTI8(0);
2302 CONVERT_STR(VarI8FromStr,"0.4",0); EXPECTI8(0);
2303 CONVERT_STR(VarI8FromStr,"0.5",0); EXPECTI8(0);
2304 CONVERT_STR(VarI8FromStr,"0.6",0); EXPECTI8(1);
2305 CONVERT_STR(VarI8FromStr,"1.5",0); EXPECTI8(2);
2308 static void test_VarI8Copy(void)
2310 if (!HAVE_OLEAUT32_I8)
2311 return;
2313 COPYTEST(1, VT_I8, ((int)V_I8(&vSrc)), ((int)V_I8(&vDst)), V_I8REF(&vSrc), V_I8REF(&vDst), "%d");
2316 static void test_VarI8ChangeTypeEx(void)
2318 CONVVARS(CONV_TYPE);
2319 VARIANTARG vSrc, vDst;
2321 if (!HAVE_OLEAUT32_I8)
2322 return;
2324 in = 1;
2326 INITIAL_TYPETESTI8(VT_I8, V_I8);
2327 COMMON_TYPETEST;
2330 /* Adapt the test macros to UI8 */
2331 #undef CONV_TYPE
2332 #define CONV_TYPE ULONG64
2334 static void test_VarUI8FromI1(void)
2336 CONVVARS(signed char);
2337 int i;
2339 CHECKPTR(VarUI8FromI1);
2340 for (i = -128; i < 128; i++)
2342 CONVERT(VarUI8FromI1,i);
2343 if (i < 0)
2344 EXPECT_OVERFLOW;
2345 else
2346 EXPECTI8(i);
2350 static void test_VarUI8FromUI1(void)
2352 CONVVARS(BYTE);
2353 int i;
2355 CHECKPTR(VarUI8FromUI1);
2356 for (i = 0; i < 256; i++)
2358 CONVERT(VarUI8FromUI1,i); EXPECTI8(i);
2362 static void test_VarUI8FromI2(void)
2364 CONVVARS(SHORT);
2365 int i;
2367 CHECKPTR(VarUI8FromI2);
2368 for (i = -32768; i < 32768; i++)
2370 CONVERT(VarUI8FromI2,i);
2371 if (i < 0)
2372 EXPECT_OVERFLOW;
2373 else
2374 EXPECTI8(i);
2378 static void test_VarUI8FromUI2(void)
2380 CONVVARS(USHORT);
2381 int i;
2383 CHECKPTR(VarUI8FromUI2);
2384 for (i = 0; i < 65535; i++)
2386 CONVERT(VarUI8FromUI2,i); EXPECTI8(i);
2390 static void test_VarUI8FromUI4(void)
2392 CONVVARS(ULONG);
2394 CHECKPTR(VarUI8FromUI4);
2395 CONVERT(VarUI8FromUI4, 0); EXPECTI8(0);
2396 CONVERT(VarUI8FromUI4, 0xffffffff); EXPECTI8(0xffffffff);
2399 static void test_VarUI8FromR4(void)
2401 CONVVARS(FLOAT);
2403 CHECKPTR(VarUI8FromR4);
2404 CONVERT(VarUI8FromR4, -1.0f); EXPECT_OVERFLOW;
2405 CONVERT(VarUI8FromR4, 0.0f); EXPECTI8(0);
2406 CONVERT(VarUI8FromR4, 1.0f); EXPECTI8(1);
2407 CONVERT(VarUI8FromR4, 255.0f); EXPECTI8(255);
2409 CONVERT(VarUI8FromR4, -1.5f); EXPECT_OVERFLOW;
2410 CONVERT(VarUI8FromR4, -0.6f); EXPECT_OVERFLOW;
2411 CONVERT(VarUI8FromR4, -0.5f); EXPECTI8(0);
2412 CONVERT(VarUI8FromR4, -0.4f); EXPECTI8(0);
2413 CONVERT(VarUI8FromR4, 0.4f); EXPECTI8(0);
2414 CONVERT(VarUI8FromR4, 0.5f); EXPECTI8(0);
2415 CONVERT(VarUI8FromR4, 0.6f); EXPECTI8(1);
2416 CONVERT(VarUI8FromR4, 1.5f); EXPECTI8(2);
2419 static void test_VarUI8FromR8(void)
2421 CONVVARS(DOUBLE);
2423 CHECKPTR(VarUI8FromR8);
2424 CONVERT(VarUI8FromR8, -1.0); EXPECT_OVERFLOW;
2425 CONVERT(VarUI8FromR8, 0.0); EXPECTI8(0);
2426 CONVERT(VarUI8FromR8, 1.0); EXPECTI8(1);
2427 CONVERT(VarUI8FromR8, 255.0); EXPECTI8(255);
2429 CONVERT(VarUI8FromR8, -1.5); EXPECT_OVERFLOW;
2430 CONVERT(VarUI8FromR8, -0.6); EXPECT_OVERFLOW;
2431 CONVERT(VarUI8FromR8, -0.5); EXPECTI8(0);
2432 CONVERT(VarUI8FromR8, -0.4); EXPECTI8(0);
2433 CONVERT(VarUI8FromR8, 0.4); EXPECTI8(0);
2434 CONVERT(VarUI8FromR8, 0.5); EXPECTI8(0);
2435 CONVERT(VarUI8FromR8, 0.6); EXPECTI8(1);
2436 CONVERT(VarUI8FromR8, 1.5); EXPECTI8(2);
2439 static void test_VarUI8FromDate(void)
2441 CONVVARS(DATE);
2443 CHECKPTR(VarUI8FromDate);
2444 CONVERT(VarUI8FromDate, -1.0); EXPECT_OVERFLOW;
2445 CONVERT(VarUI8FromDate, 0.0); EXPECTI8(0);
2446 CONVERT(VarUI8FromDate, 1.0); EXPECTI8(1);
2447 CONVERT(VarUI8FromDate, 255.0); EXPECTI8(255);
2449 CONVERT(VarUI8FromDate, -1.5); EXPECT_OVERFLOW;
2450 CONVERT(VarUI8FromDate, -0.6); EXPECT_OVERFLOW;
2451 CONVERT(VarUI8FromDate, -0.5); EXPECTI8(0);
2452 CONVERT(VarUI8FromDate, -0.4); EXPECTI8(0);
2453 CONVERT(VarUI8FromDate, 0.4); EXPECTI8(0);
2454 CONVERT(VarUI8FromDate, 0.5); EXPECTI8(0);
2455 CONVERT(VarUI8FromDate, 0.6); EXPECTI8(1);
2456 CONVERT(VarUI8FromDate, 1.5); EXPECTI8(2);
2459 static void test_VarUI8FromBool(void)
2461 CONVVARS(VARIANT_BOOL);
2462 int i;
2464 CHECKPTR(VarUI8FromBool);
2465 CONVERTRANGE(VarUI8FromBool, -32768, 32768);
2468 static void test_VarUI8FromI8(void)
2470 CONVVARS(LONG64);
2472 CHECKPTR(VarUI8FromI8);
2473 CONVERT(VarUI8FromI8, -1); EXPECT_OVERFLOW;
2474 CONVERT(VarUI8FromI8, 0); EXPECTI8(0);
2475 CONVERT(VarUI8FromI8, 1); EXPECTI8(1);
2478 static void test_VarUI8FromCy(void)
2480 CONVVARS(CY);
2482 CHECKPTR(VarUI8FromCy);
2483 CONVERT_CY(VarUI8FromCy,-1); EXPECT_OVERFLOW;
2484 CONVERT_CY(VarUI8FromCy,0); EXPECTI8(0);
2485 CONVERT_CY(VarUI8FromCy,1); EXPECTI8(1);
2486 CONVERT_CY(VarUI8FromCy,255); EXPECTI8(255);
2488 CONVERT_CY(VarUI8FromCy,-1.5); EXPECT_OVERFLOW;
2489 CONVERT_CY(VarUI8FromCy,-0.6); EXPECT_OVERFLOW;
2490 CONVERT_CY(VarUI8FromCy,-0.5); EXPECTI8(0);
2491 CONVERT_CY(VarUI8FromCy,-0.4); EXPECTI8(0);
2492 CONVERT_CY(VarUI8FromCy,0.4); EXPECTI8(0);
2493 CONVERT_CY(VarUI8FromCy,0.5); EXPECTI8(0);
2494 CONVERT_CY(VarUI8FromCy,0.6); EXPECTI8(1);
2495 CONVERT_CY(VarUI8FromCy,1.5); EXPECTI8(2);
2498 static void test_VarUI8FromDec(void)
2500 CONVVARS(DECIMAL);
2502 CHECKPTR(VarUI8FromDec);
2504 CONVERT_BADDEC(VarUI8FromDec);
2506 #if 0
2507 /* This returns 1 under native; Wine fixes this bug and returns overflow */
2508 CONVERT_DEC(VarUI8FromDec,0,0x80,0,1);
2509 #endif
2510 CONVERT_DEC(VarUI8FromDec,0,0,0,0); EXPECTI8(0);
2511 CONVERT_DEC(VarUI8FromDec,0,0,0,1); EXPECTI8(1);
2512 CONVERT_DEC(VarUI8FromDec,0,0,0,255); EXPECTI8(255);
2514 CONVERT_DEC(VarUI8FromDec,2,0x80,0,100); EXPECT_OVERFLOW;
2515 CONVERT_DEC(VarUI8FromDec,2,0,0,25500); EXPECTI8(255);
2518 static void test_VarUI8FromStr(void)
2520 CONVVARS(LCID);
2521 OLECHAR buff[128];
2523 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2525 CHECKPTR(VarUI8FromStr);
2527 CONVERT_STR(VarUI8FromStr,NULL,0); EXPECT_MISMATCH;
2528 CONVERT_STR(VarUI8FromStr,"0",0); EXPECTI8(0);
2529 CONVERT_STR(VarUI8FromStr,"-1",0); EXPECT_OVERFLOW;
2530 CONVERT_STR(VarUI8FromStr,"2147483647",0); EXPECTI8(2147483647);
2532 CONVERT_STR(VarUI8FromStr,"-1.5",0); EXPECT_OVERFLOW;
2533 CONVERT_STR(VarUI8FromStr,"-0.6",0); EXPECT_OVERFLOW;
2534 CONVERT_STR(VarUI8FromStr,"-0.5",0); EXPECTI8(0);
2535 CONVERT_STR(VarUI8FromStr,"-0.4",0); EXPECTI8(0);
2536 CONVERT_STR(VarUI8FromStr,"0.4",0); EXPECTI8(0);
2537 CONVERT_STR(VarUI8FromStr,"0.5",0); EXPECTI8(0);
2538 CONVERT_STR(VarUI8FromStr,"0.6",0); EXPECTI8(1);
2539 CONVERT_STR(VarUI8FromStr,"1.5",0); EXPECTI8(2);
2542 static void test_VarUI8Copy(void)
2544 if (!HAVE_OLEAUT32_I8)
2545 return;
2547 COPYTEST(1, VT_UI8, ((unsigned)V_UI8(&vSrc)), ((unsigned)V_I8(&vDst)),
2548 V_UI8REF(&vSrc), V_UI8REF(&vDst), "%u");
2551 static void test_VarUI8ChangeTypeEx(void)
2553 CONVVARS(CONV_TYPE);
2554 VARIANTARG vSrc, vDst;
2556 if (!HAVE_OLEAUT32_I8)
2557 return;
2559 in = 1;
2561 INITIAL_TYPETESTI8(VT_UI8, V_UI8);
2562 COMMON_TYPETEST;
2566 * VT_R4
2569 #undef CONV_TYPE
2570 #define CONV_TYPE float
2571 #undef EXPECTRES
2572 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%15.15f")
2574 static void test_VarR4FromI1(void)
2576 CONVVARS(signed char);
2577 int i;
2579 CHECKPTR(VarR4FromI1);
2580 CONVERTRANGE(VarR4FromI1, -128, 128);
2583 static void test_VarR4FromUI1(void)
2585 CONVVARS(BYTE);
2586 int i;
2588 CHECKPTR(VarR4FromUI1);
2589 CONVERTRANGE(VarR4FromUI1, 0, 256);
2592 static void test_VarR4FromI2(void)
2594 CONVVARS(SHORT);
2595 int i;
2597 CHECKPTR(VarR4FromI2);
2598 CONVERTRANGE(VarR4FromI2, -32768, 32768);
2601 static void test_VarR4FromUI2(void)
2603 CONVVARS(USHORT);
2604 int i;
2606 CHECKPTR(VarR4FromUI2);
2607 CONVERTRANGE(VarR4FromUI2, 0, 65536);
2610 static void test_VarR4FromI4(void)
2612 CONVVARS(int);
2614 CHECKPTR(VarR4FromI4);
2615 CONVERT(VarR4FromI4, -2147483647-1); EXPECT(-2147483648.0f);
2616 CONVERT(VarR4FromI4, -1); EXPECT(-1.0f);
2617 CONVERT(VarR4FromI4, 0); EXPECT(0.0f);
2618 CONVERT(VarR4FromI4, 1); EXPECT(1.0f);
2619 CONVERT(VarR4FromI4, 2147483647); EXPECT(2147483647.0f);
2622 static void test_VarR4FromUI4(void)
2624 CONVVARS(unsigned int);
2626 CHECKPTR(VarR4FromUI4);
2627 CONVERT(VarR4FromUI4, 0); EXPECT(0.0f);
2628 CONVERT(VarR4FromUI4, 1); EXPECT(1.0f);
2629 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
2630 CONVERT(VarR4FromUI4, 0xffffffff); EXPECT(4294967296.0f);
2631 #endif
2634 static void test_VarR4FromR8(void)
2636 CONVVARS(FLOAT);
2638 CHECKPTR(VarR4FromR8);
2639 CONVERT(VarR4FromR8, -1.0); EXPECT(-1.0f);
2640 CONVERT(VarR4FromR8, 0.0); EXPECT(0.0f);
2641 CONVERT(VarR4FromR8, 1.0); EXPECT(1.0f);
2642 CONVERT(VarR4FromR8, 1.5); EXPECT(1.5f);
2644 /* Skip rounding tests - no rounding is done */
2647 static void test_VarR4FromBool(void)
2649 CONVVARS(VARIANT_BOOL);
2651 CHECKPTR(VarR4FromBool);
2652 CONVERT(VarR4FromBool, VARIANT_TRUE); EXPECT(VARIANT_TRUE * 1.0f);
2653 CONVERT(VarR4FromBool, VARIANT_FALSE); EXPECT(VARIANT_FALSE * 1.0f);
2656 static void test_VarR4FromCy(void)
2658 CONVVARS(CY);
2660 CHECKPTR(VarR4FromCy);
2661 CONVERT_CY(VarR4FromCy,-32768); EXPECT(-32768.0f);
2662 CONVERT_CY(VarR4FromCy,-1); EXPECT(-1.0f);
2663 CONVERT_CY(VarR4FromCy,0); EXPECT(0.0f);
2664 CONVERT_CY(VarR4FromCy,1); EXPECT(1.0f);
2665 CONVERT_CY(VarR4FromCy,32768); EXPECT(32768.0f);
2667 CONVERT_CY(VarR4FromCy,-1.5); EXPECT(-1.5f);
2668 CONVERT_CY(VarR4FromCy,-0.6); EXPECT(-0.6f);
2669 CONVERT_CY(VarR4FromCy,-0.5); EXPECT(-0.5f);
2670 CONVERT_CY(VarR4FromCy,-0.4); EXPECT(-0.4f);
2671 CONVERT_CY(VarR4FromCy,0.4); EXPECT(0.4f);
2672 CONVERT_CY(VarR4FromCy,0.5); EXPECT(0.5f);
2673 CONVERT_CY(VarR4FromCy,0.6); EXPECT(0.6f);
2674 CONVERT_CY(VarR4FromCy,1.5); EXPECT(1.5f);
2677 static void test_VarR4FromI8(void)
2679 CONVVARS(LONG64);
2681 CHECKPTR(VarR4FromI8);
2682 CONVERT(VarR4FromI8, -1); EXPECT(-1.0f);
2683 CONVERT(VarR4FromI8, 0); EXPECT(0.0f);
2684 CONVERT(VarR4FromI8, 1); EXPECT(1.0f);
2687 static void test_VarR4FromUI8(void)
2689 CONVVARS(ULONG64);
2691 CHECKPTR(VarR4FromUI8);
2692 CONVERT(VarR4FromUI8, 0); EXPECT(0.0f);
2693 CONVERT(VarR4FromUI8, 1); EXPECT(1.0f);
2696 static void test_VarR4FromDec(void)
2698 CONVVARS(DECIMAL);
2700 CHECKPTR(VarR4FromDec);
2702 CONVERT_BADDEC(VarR4FromDec);
2704 CONVERT_DEC(VarR4FromDec,0,0x80,0,32768); EXPECT(-32768.0f);
2705 CONVERT_DEC(VarR4FromDec,0,0x80,0,1); EXPECT(-1.0f);
2706 CONVERT_DEC(VarR4FromDec,0,0,0,0); EXPECT(0.0f);
2707 CONVERT_DEC(VarR4FromDec,0,0,0,1); EXPECT(1.0f);
2708 CONVERT_DEC(VarR4FromDec,0,0,0,32767); EXPECT(32767.0f);
2710 CONVERT_DEC(VarR4FromDec,2,0x80,0,3276800); EXPECT(-32768.0f);
2711 CONVERT_DEC(VarR4FromDec,2,0,0,3276700); EXPECT(32767.0f);
2714 static void test_VarR4FromDate(void)
2716 CONVVARS(DATE);
2718 CHECKPTR(VarR4FromDate);
2719 CONVERT(VarR4FromDate, -1.0); EXPECT(-1.0f);
2720 CONVERT(VarR4FromDate, 0.0); EXPECT(0.0f);
2721 CONVERT(VarR4FromDate, 1.0); EXPECT(1.0f);
2724 static void test_VarR4FromStr(void)
2726 CONVVARS(LCID);
2727 OLECHAR buff[128];
2729 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2731 CHECKPTR(VarR4FromStr);
2733 CONVERT_STR(VarR4FromStr,NULL,0); EXPECT_MISMATCH;
2734 CONVERT_STR(VarR4FromStr,"-1", 0); EXPECT(-1.0f);
2735 CONVERT_STR(VarR4FromStr,"0", 0); EXPECT(0.0f);
2736 CONVERT_STR(VarR4FromStr,"1", 0); EXPECT(1.0f);
2738 CONVERT_STR(VarR4FromStr,"-1.5",0); EXPECT(-1.5f);
2739 CONVERT_STR(VarR4FromStr,"-0.6",0); EXPECT(-0.6f);
2740 CONVERT_STR(VarR4FromStr,"-0.5",0); EXPECT(-0.5f);
2741 CONVERT_STR(VarR4FromStr,"-0.4",0); EXPECT(-0.4f);
2742 CONVERT_STR(VarR4FromStr,"0.4",0); EXPECT(0.4f);
2743 CONVERT_STR(VarR4FromStr,"0.5",0); EXPECT(0.5f);
2744 CONVERT_STR(VarR4FromStr,"0.6",0); EXPECT(0.6f);
2745 CONVERT_STR(VarR4FromStr,"1.5",0); EXPECT(1.5f);
2748 static void test_VarR4Copy(void)
2750 COPYTEST(77665544.0f, VT_R4, V_R4(&vSrc), V_R4(&vDst), V_R4REF(&vSrc),V_R4REF(&vDst), "%15.15f");
2753 static void test_VarR4ChangeTypeEx(void)
2755 CONVVARS(CONV_TYPE);
2756 VARIANTARG vSrc, vDst;
2758 in = 1.0f;
2760 INITIAL_TYPETEST(VT_R4, V_R4, "%f");
2761 COMMON_TYPETEST;
2765 * VT_R8
2768 #undef CONV_TYPE
2769 #define CONV_TYPE double
2770 #undef EXPECTRES
2771 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%15.15f")
2773 static void test_VarR8FromI1(void)
2775 CONVVARS(signed char);
2776 int i;
2778 CHECKPTR(VarR8FromI1);
2779 CONVERTRANGE(VarR8FromI1, -128, 128);
2782 static void test_VarR8FromUI1(void)
2784 CONVVARS(BYTE);
2785 int i;
2787 CHECKPTR(VarR8FromUI1);
2788 CONVERTRANGE(VarR8FromUI1, 0, 256);
2791 static void test_VarR8FromI2(void)
2793 CONVVARS(SHORT);
2794 int i;
2796 CHECKPTR(VarR8FromI2);
2797 CONVERTRANGE(VarR8FromI2, -32768, 32768);
2800 static void test_VarR8FromUI2(void)
2802 CONVVARS(USHORT);
2803 int i;
2805 CHECKPTR(VarR8FromUI2);
2806 CONVERTRANGE(VarR8FromUI2, 0, 65536);
2809 static void test_VarR8FromI4(void)
2811 CONVVARS(int);
2813 CHECKPTR(VarR8FromI4);
2814 CONVERT(VarR8FromI4, -2147483647-1); EXPECT(-2147483648.0);
2815 CONVERT(VarR8FromI4, -1); EXPECT(-1.0);
2816 CONVERT(VarR8FromI4, 0); EXPECT(0.0);
2817 CONVERT(VarR8FromI4, 1); EXPECT(1.0);
2818 CONVERT(VarR8FromI4, 0x7fffffff); EXPECT(2147483647.0);
2821 static void test_VarR8FromUI4(void)
2823 CONVVARS(unsigned int);
2825 CHECKPTR(VarR8FromUI4);
2826 CONVERT(VarR8FromUI4, 0); EXPECT(0.0);
2827 CONVERT(VarR8FromUI4, 1); EXPECT(1.0);
2828 CONVERT(VarR8FromUI4, 0xffffffff); EXPECT(4294967295.0);
2831 static void test_VarR8FromR4(void)
2833 CONVVARS(FLOAT);
2835 CHECKPTR(VarR8FromR4);
2836 CONVERT(VarR8FromR4, -1.0f); EXPECT(-1.0);
2837 CONVERT(VarR8FromR4, 0.0f); EXPECT(0.0);
2838 CONVERT(VarR8FromR4, 1.0f); EXPECT(1.0);
2839 CONVERT(VarR8FromR4, 1.5f); EXPECT(1.5);
2841 /* Skip rounding tests - no rounding is done */
2844 static void test_VarR8FromBool(void)
2846 CONVVARS(VARIANT_BOOL);
2848 CHECKPTR(VarR8FromBool);
2849 CONVERT(VarR8FromBool, VARIANT_TRUE); EXPECT(VARIANT_TRUE * 1.0);
2850 CONVERT(VarR8FromBool, VARIANT_FALSE); EXPECT(VARIANT_FALSE * 1.0);
2853 static void test_VarR8FromCy(void)
2855 CONVVARS(CY);
2857 CHECKPTR(VarR8FromCy);
2858 CONVERT_CY(VarR8FromCy,-32769); EXPECT(-32769.0);
2859 CONVERT_CY(VarR8FromCy,-32768); EXPECT(-32768.0);
2860 CONVERT_CY(VarR8FromCy,-1); EXPECT(-1.0);
2861 CONVERT_CY(VarR8FromCy,0); EXPECT(0.0);
2862 CONVERT_CY(VarR8FromCy,1); EXPECT(1.0);
2863 CONVERT_CY(VarR8FromCy,32767); EXPECT(32767.0);
2864 CONVERT_CY(VarR8FromCy,32768); EXPECT(32768.0);
2866 CONVERT_CY(VarR8FromCy,-1.5); EXPECT(-1.5);
2867 CONVERT_CY(VarR8FromCy,-0.6); EXPECT(-0.6);
2868 CONVERT_CY(VarR8FromCy,-0.5); EXPECT(-0.5);
2869 CONVERT_CY(VarR8FromCy,-0.4); EXPECT(-0.4);
2870 CONVERT_CY(VarR8FromCy,0.4); EXPECT(0.4);
2871 CONVERT_CY(VarR8FromCy,0.5); EXPECT(0.5);
2872 CONVERT_CY(VarR8FromCy,0.6); EXPECT(0.6);
2873 CONVERT_CY(VarR8FromCy,1.5); EXPECT(1.5);
2876 static void test_VarR8FromI8(void)
2878 CONVVARS(LONG64);
2880 CHECKPTR(VarR8FromI8);
2881 CONVERT(VarR8FromI8, -1); EXPECT(-1.0);
2882 CONVERT(VarR8FromI8, 0); EXPECT(0.0);
2883 CONVERT(VarR8FromI8, 1); EXPECT(1.0);
2884 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
2885 CONVERT_I8(VarR8FromI8, 0x7fffffff,0xffffffff); EXPECT(9223372036854775808.0);
2886 #endif
2889 static void test_VarR8FromUI8(void)
2891 CONVVARS(ULONG64);
2893 CHECKPTR(VarR8FromUI8);
2894 CONVERT(VarR8FromUI8, 0); EXPECT(0.0);
2895 CONVERT(VarR8FromUI8, 1); EXPECT(1.0);
2896 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
2897 CONVERT_I8(VarR8FromUI8, 0x80000000,0); EXPECT(9223372036854775808.0);
2898 #endif
2901 static void test_VarR8FromDec(void)
2903 CONVVARS(DECIMAL);
2905 CHECKPTR(VarR8FromDec);
2907 CONVERT_BADDEC(VarR8FromDec);
2909 CONVERT_DEC(VarR8FromDec,0,0x80,0,32768); EXPECT(-32768.0);
2910 CONVERT_DEC(VarR8FromDec,0,0x80,0,1); EXPECT(-1.0);
2911 CONVERT_DEC(VarR8FromDec,0,0,0,0); EXPECT(0.0);
2912 CONVERT_DEC(VarR8FromDec,0,0,0,1); EXPECT(1.0);
2913 CONVERT_DEC(VarR8FromDec,0,0,0,32767); EXPECT(32767.0);
2915 CONVERT_DEC(VarR8FromDec,2,0x80,0,3276800); EXPECT(-32768.0);
2916 CONVERT_DEC(VarR8FromDec,2,0,0,3276700); EXPECT(32767.0);
2919 static void test_VarR8FromDate(void)
2921 CONVVARS(DATE);
2923 CHECKPTR(VarR8FromDate);
2924 CONVERT(VarR8FromDate, -1.0); EXPECT(-1.0);
2925 CONVERT(VarR8FromDate, -0.0); EXPECT(0.0);
2926 CONVERT(VarR8FromDate, 1.0); EXPECT(1.0);
2929 static void test_VarR8FromStr(void)
2931 CONVVARS(LCID);
2932 OLECHAR buff[128];
2934 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2936 CHECKPTR(VarR8FromStr);
2938 CONVERT_STR(VarR8FromStr,NULL,0); EXPECT_MISMATCH;
2939 CONVERT_STR(VarR8FromStr,"",0); EXPECT_MISMATCH;
2940 CONVERT_STR(VarR8FromStr," ",0); EXPECT_MISMATCH;
2942 CONVERT_STR(VarR8FromStr,"0",0); EXPECT(0.0);
2943 CONVERT_STR(VarR8FromStr,"-1.5",0); EXPECT(-1.5);
2944 CONVERT_STR(VarR8FromStr,"-0.6",0); EXPECT(-0.6);
2945 CONVERT_STR(VarR8FromStr,"-0.5",0); EXPECT(-0.5);
2946 CONVERT_STR(VarR8FromStr,"-0.4",0); EXPECT(-0.4);
2947 CONVERT_STR(VarR8FromStr,"0.4",0); EXPECT(0.4);
2948 CONVERT_STR(VarR8FromStr,"0.5",0); EXPECT(0.5);
2949 CONVERT_STR(VarR8FromStr,"0.6",0); EXPECT(0.6);
2950 CONVERT_STR(VarR8FromStr,"1.5",0); EXPECT(1.5);
2952 /* We already have exhaustive tests for number parsing, so skip those tests here */
2955 static void test_VarR8Copy(void)
2957 COPYTEST(77665544.0, VT_R8, V_R8(&vSrc), V_R8(&vDst), V_R8REF(&vSrc),V_R8REF(&vDst), "%16.16g");
2960 static void test_VarR8ChangeTypeEx(void)
2962 CONVVARS(CONV_TYPE);
2963 VARIANTARG vSrc, vDst;
2965 in = 1.0;
2967 INITIAL_TYPETEST(VT_R8, V_R8, "%g");
2968 COMMON_TYPETEST;
2971 #define MATHRND(l, r) left = l; right = r; hres = pVarR8Round(left, right, &out)
2973 static void test_VarR8Round(void)
2975 HRESULT hres;
2976 double left = 0.0, out;
2977 int right;
2979 CHECKPTR(VarR8Round);
2980 MATHRND(0.5432, 5); EXPECT(0.5432);
2981 MATHRND(0.5432, 4); EXPECT(0.5432);
2982 MATHRND(0.5432, 3); EXPECT(0.543);
2983 MATHRND(0.5432, 2); EXPECT(0.54);
2984 MATHRND(0.5432, 1); EXPECT(0.5);
2985 MATHRND(0.5532, 0); EXPECT(1);
2986 MATHRND(0.5532, -1); EXPECT_INVALID;
2988 MATHRND(0.5568, 5); EXPECT(0.5568);
2989 MATHRND(0.5568, 4); EXPECT(0.5568);
2990 MATHRND(0.5568, 3); EXPECT(0.557);
2991 MATHRND(0.5568, 2); EXPECT(0.56);
2992 MATHRND(0.5568, 1); EXPECT(0.6);
2993 MATHRND(0.5568, 0); EXPECT(1);
2994 MATHRND(0.5568, -1); EXPECT_INVALID;
2996 MATHRND(0.4999, 0); EXPECT(0);
2997 MATHRND(0.5000, 0); EXPECT(0);
2998 MATHRND(0.5001, 0); EXPECT(1);
2999 MATHRND(1.4999, 0); EXPECT(1);
3000 MATHRND(1.5000, 0); EXPECT(2);
3001 MATHRND(1.5001, 0); EXPECT(2);
3005 * VT_DATE
3008 #undef CONV_TYPE
3009 #define CONV_TYPE DATE
3011 static void test_VarDateFromI1(void)
3013 CONVVARS(signed char);
3014 int i;
3016 CHECKPTR(VarDateFromI1);
3017 CONVERTRANGE(VarDateFromI1, -128, 128);
3020 static void test_VarDateFromUI1(void)
3022 CONVVARS(BYTE);
3023 int i;
3025 CHECKPTR(VarDateFromUI1);
3026 CONVERTRANGE(VarDateFromUI1, 0, 256);
3029 static void test_VarDateFromI2(void)
3031 CONVVARS(SHORT);
3032 int i;
3034 CHECKPTR(VarDateFromI2);
3035 CONVERTRANGE(VarDateFromI2, -32768, 32768);
3038 static void test_VarDateFromUI2(void)
3040 CONVVARS(USHORT);
3041 int i;
3043 CHECKPTR(VarDateFromUI2);
3044 CONVERTRANGE(VarDateFromUI2, 0, 65536);
3047 static void test_VarDateFromI4(void)
3049 CONVVARS(int);
3051 CHECKPTR(VarDateFromI4);
3052 CONVERT(VarDateFromI4, DATE_MIN-1);
3053 if (hres != DISP_E_TYPEMISMATCH) /* Early versions return this, incorrectly */
3054 EXPECT_OVERFLOW;
3055 CONVERT(VarDateFromI4, DATE_MIN); EXPECT(DATE_MIN);
3056 CONVERT(VarDateFromI4, -1); EXPECT(-1.0);
3057 CONVERT(VarDateFromI4, 0); EXPECT(0.0);
3058 CONVERT(VarDateFromI4, 1); EXPECT(1.0);
3059 CONVERT(VarDateFromI4, DATE_MAX); EXPECT(DATE_MAX);
3060 CONVERT(VarDateFromI4, DATE_MAX+1);
3061 if (hres != DISP_E_TYPEMISMATCH) /* Early versions return this, incorrectly */
3062 EXPECT_OVERFLOW;
3065 static void test_VarDateFromUI4(void)
3067 CONVVARS(unsigned int);
3069 CHECKPTR(VarDateFromUI4);
3070 CONVERT(VarDateFromUI4, 0); EXPECT(0.0);
3071 CONVERT(VarDateFromUI4, 1); EXPECT(1.0);
3072 CONVERT(VarDateFromUI4, DATE_MAX); EXPECT(DATE_MAX);
3073 CONVERT(VarDateFromUI4, DATE_MAX+1);
3074 if (hres != DISP_E_TYPEMISMATCH) /* Early versions return this, incorrectly */
3075 EXPECT_OVERFLOW;
3078 static void test_VarDateFromR4(void)
3080 CONVVARS(FLOAT);
3082 CHECKPTR(VarDateFromR4);
3083 CONVERT(VarDateFromR4, -1.0f); EXPECT(-1.0);
3084 CONVERT(VarDateFromR4, 0.0f); EXPECT(0.0);
3085 CONVERT(VarDateFromR4, 1.0f); EXPECT(1.0);
3086 CONVERT(VarDateFromR4, 1.5f); EXPECT(1.5);
3089 static void test_VarDateFromR8(void)
3091 CONVVARS(double);
3093 CHECKPTR(VarDateFromR8);
3094 CONVERT(VarDateFromR8, -1.0f); EXPECT(-1.0);
3095 CONVERT(VarDateFromR8, 0.0f); EXPECT(0.0);
3096 CONVERT(VarDateFromR8, 1.0f); EXPECT(1.0);
3097 CONVERT(VarDateFromR8, 1.5f); EXPECT(1.5);
3100 static void test_VarDateFromBool(void)
3102 CONVVARS(VARIANT_BOOL);
3104 CHECKPTR(VarDateFromBool);
3105 CONVERT(VarDateFromBool, VARIANT_TRUE); EXPECT(VARIANT_TRUE * 1.0);
3106 CONVERT(VarDateFromBool, VARIANT_FALSE); EXPECT(VARIANT_FALSE * 1.0);
3109 static void test_VarDateFromCy(void)
3111 CONVVARS(CY);
3113 CHECKPTR(VarDateFromCy);
3114 CONVERT_CY(VarDateFromCy,-32769); EXPECT(-32769.0);
3115 CONVERT_CY(VarDateFromCy,-32768); EXPECT(-32768.0);
3116 CONVERT_CY(VarDateFromCy,-1); EXPECT(-1.0);
3117 CONVERT_CY(VarDateFromCy,0); EXPECT(0.0);
3118 CONVERT_CY(VarDateFromCy,1); EXPECT(1.0);
3119 CONVERT_CY(VarDateFromCy,32767); EXPECT(32767.0);
3120 CONVERT_CY(VarDateFromCy,32768); EXPECT(32768.0);
3122 CONVERT_CY(VarDateFromCy,-1.5); EXPECT(-1.5);
3123 CONVERT_CY(VarDateFromCy,-0.6); EXPECT(-0.6);
3124 CONVERT_CY(VarDateFromCy,-0.5); EXPECT(-0.5);
3125 CONVERT_CY(VarDateFromCy,-0.4); EXPECT(-0.4);
3126 CONVERT_CY(VarDateFromCy,0.4); EXPECT(0.4);
3127 CONVERT_CY(VarDateFromCy,0.5); EXPECT(0.5);
3128 CONVERT_CY(VarDateFromCy,0.6); EXPECT(0.6);
3129 CONVERT_CY(VarDateFromCy,1.5); EXPECT(1.5);
3132 static void test_VarDateFromI8(void)
3134 CONVVARS(LONG64);
3136 CHECKPTR(VarDateFromI8);
3137 CONVERT(VarDateFromI8, DATE_MIN-1); EXPECT_OVERFLOW;
3138 CONVERT(VarDateFromI8, DATE_MIN); EXPECT(DATE_MIN);
3139 CONVERT(VarDateFromI8, -1); EXPECT(-1.0);
3140 CONVERT(VarDateFromI8, 0); EXPECT(0.0);
3141 CONVERT(VarDateFromI8, 1); EXPECT(1.0);
3142 CONVERT(VarDateFromI8, DATE_MAX); EXPECT(DATE_MAX);
3143 CONVERT(VarDateFromI8, DATE_MAX+1); EXPECT_OVERFLOW;
3146 static void test_VarDateFromUI8(void)
3148 CONVVARS(ULONG64);
3150 CHECKPTR(VarDateFromUI8);
3151 CONVERT(VarDateFromUI8, 0); EXPECT(0.0);
3152 CONVERT(VarDateFromUI8, 1); EXPECT(1.0);
3153 CONVERT(VarDateFromUI8, DATE_MAX); EXPECT(DATE_MAX);
3154 CONVERT(VarDateFromUI8, DATE_MAX+1); EXPECT_OVERFLOW;
3157 static void test_VarDateFromDec(void)
3159 CONVVARS(DECIMAL);
3161 CHECKPTR(VarDateFromDec);
3163 CONVERT_BADDEC(VarDateFromDec);
3165 CONVERT_DEC(VarDateFromDec,0,0x80,0,32768); EXPECT(-32768.0);
3166 CONVERT_DEC(VarDateFromDec,0,0x80,0,1); EXPECT(-1.0);
3167 CONVERT_DEC(VarDateFromDec,0,0,0,0); EXPECT(0.0);
3168 CONVERT_DEC(VarDateFromDec,0,0,0,1); EXPECT(1.0);
3169 CONVERT_DEC(VarDateFromDec,0,0,0,32767); EXPECT(32767.0);
3171 CONVERT_DEC(VarDateFromDec,2,0x80,0,3276800); EXPECT(-32768.0);
3172 CONVERT_DEC(VarDateFromDec,2,0,0,3276700); EXPECT(32767.0);
3175 #define DFS(str) \
3176 buff[0] = '\0'; out = 0.0; \
3177 if (str) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)); \
3178 hres = pVarDateFromStr(str ? buff : NULL,lcid,LOCALE_NOUSEROVERRIDE,&out)
3180 #define MKRELDATE(day,mth) st.wMonth = mth; st.wDay = day; \
3181 pSystemTimeToVariantTime(&st,&relative)
3183 static const char *BadDateStrings[] =
3185 "True", "False", /* Plain text */
3186 "0.", ".0", "-1.1", "1.1-", /* Partial specifications */
3187 "1;2;3", "1*2*3", "1@2@3", "1#2#3", "(1:2)","<1:2>","1|2|3", /* Bad chars */
3188 "0", "1", /* 1 element */
3189 "0.60", "24.00", "0:60", "24:00", "1 2 am", "1 am 2", /* 2 elements */
3190 "1.5 2", "1 5.2", "2 32 3", "1 2 am 3", /* 3 elements */
3191 "1 2.3 4", "1.2.3 4", "1 2.3.4", "1.2 3.4", "1.2.3.4", "1 2 3 4",
3192 "1 am 2 3.4", "1 2 am 3.4", "1.2 3 am 4", "1.2 3 4 am", /* 4 elements */
3193 "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",
3194 "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",
3195 "1.2.3 4 am 5", "1.2.3 4 5 am", "1.2 3 am 4 5",
3196 "1.2 3 4 am 5", "1.2 3 4 5 am", "1 am 2 3.4.5", "1 2 am 3.4.5",
3197 "1 am 2 3 4.5", "1 2 am 3 4.5", "1 2 3 am 4.5", /* 5 elements */
3198 /* 6 elements */
3199 "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",
3200 "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",
3201 "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",
3202 "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",
3203 "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",
3204 "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",
3205 "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",
3206 "1 2 am 3 4.5.6", "1 2 3 am 4.5.6"
3209 static void test_VarDateFromStr(void)
3211 LCID lcid;
3212 DATE out, relative;
3213 HRESULT hres;
3214 SYSTEMTIME st;
3215 OLECHAR buff[128];
3216 size_t i;
3218 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
3220 CHECKPTR(VarDateFromStr);
3221 CHECKPTR(SystemTimeToVariantTime);
3223 /* Some date formats are relative, so we need to find the cuurent year */
3224 GetSystemTime(&st);
3225 st.wHour = st.wMinute = st.wSecond = st.wMilliseconds = 0;
3226 DFS(NULL); EXPECT_MISMATCH;
3228 /* Floating point number are not recognised */
3229 DFS("0.0");
3230 if (hres == S_OK)
3231 EXPECT_DBL(0.0); /* Very old versions accept this string */
3232 else
3233 EXPECT_MISMATCH;
3235 /* 1 element - can only be a time, and only if it has am/pm */
3236 DFS("1 am"); EXPECT_DBL(0.04166666666666666);
3237 /* 2 elements */
3238 /* A decimal point is treated as a time separator.
3239 * The following are converted as hours/minutes.
3241 DFS("0.1"); EXPECT_DBL(0.0006944444444444445);
3242 DFS("0.40"); EXPECT_DBL(0.02777777777777778);
3243 DFS("2.5"); EXPECT_DBL(0.08680555555555555);
3244 /* A colon acts as a decimal point */
3245 DFS("0:1"); EXPECT_DBL(0.0006944444444444445);
3246 DFS("0:20"); EXPECT_DBL(0.01388888888888889);
3247 DFS("0:40"); EXPECT_DBL(0.02777777777777778);
3248 DFS("3:5"); EXPECT_DBL(0.1284722222222222);
3249 /* Check the am/pm limits */
3250 DFS("00:00 AM"); EXPECT_DBL(0.0);
3251 DFS("00:00 a"); EXPECT_DBL(0.0);
3252 DFS("12:59 AM"); EXPECT_DBL(0.04097222222222222);
3253 DFS("12:59 A"); EXPECT_DBL(0.04097222222222222);
3254 DFS("00:00 pm"); EXPECT_DBL(0.5);
3255 DFS("00:00 p"); EXPECT_DBL(0.5);
3256 DFS("12:59 pm"); EXPECT_DBL(0.5409722222222222);
3257 DFS("12:59 p"); EXPECT_DBL(0.5409722222222222);
3258 /* AM/PM is ignored if hours > 12 */
3259 DFS("13:00 AM"); EXPECT_DBL(0.5416666666666666);
3260 DFS("13:00 PM"); EXPECT_DBL(0.5416666666666666);
3262 /* Space, dash and slash all indicate a date format. */
3263 /* If both numbers are valid month values => month/day of current year */
3264 DFS("1 2"); MKRELDATE(2,1); EXPECT_DBL(relative);
3265 DFS("2 1"); MKRELDATE(1,2); EXPECT_DBL(relative);
3266 /* one number not valid month, is a valid day, other number valid month:
3267 * that number becomes the day.
3269 DFS("14 1"); MKRELDATE(14,1); EXPECT_DBL(relative);
3270 DFS("1 14"); EXPECT_DBL(relative);
3271 /* If the numbers can't be day/month, they are assumed to be year/month */
3272 DFS("30 2"); EXPECT_DBL(10990.0);
3273 DFS("2 30"); EXPECT_DBL(10990.0);
3274 DFS("32 49"); EXPECT_MISMATCH; /* Can't be any format */
3275 DFS("0 49"); EXPECT_MISMATCH; /* Can't be any format */
3276 /* If a month name is given the other number is the day */
3277 DFS("Jan 2"); MKRELDATE(2,1); EXPECT_DBL(relative);
3278 DFS("2 Jan"); EXPECT_DBL(relative);
3279 /* Unless it can't be, in which case it becomes the year */
3280 DFS("Jan 35"); EXPECT_DBL(12785.0);
3281 DFS("35 Jan"); EXPECT_DBL(12785.0);
3282 DFS("Jan-35"); EXPECT_DBL(12785.0);
3283 DFS("35-Jan"); EXPECT_DBL(12785.0);
3284 DFS("Jan/35"); EXPECT_DBL(12785.0);
3285 DFS("35/Jan"); EXPECT_DBL(12785.0);
3286 /* 3 elements */
3287 /* 3 numbers and time separator => h:m:s */
3288 DFS("0.1.0"); EXPECT_DBL(0.0006944444444444445);
3289 DFS("1.5.2"); EXPECT_DBL(0.04516203703703704);
3290 /* 3 numbers => picks date giving preference to lcid format */
3291 DFS("1 2 3"); EXPECT_DBL(37623.0);
3292 DFS("14 2 3"); EXPECT_DBL(41673.0);
3293 DFS("2 14 3"); EXPECT_DBL(37666.0);
3294 DFS("2 3 14"); EXPECT_DBL(41673.0);
3295 DFS("32 2 3"); EXPECT_DBL(11722.0);
3296 DFS("2 3 32"); EXPECT_DBL(11722.0);
3297 DFS("1 2 29"); EXPECT_DBL(47120.0);
3298 /* After 30, two digit dates are expected to be in the 1900's */
3299 DFS("1 2 30"); EXPECT_DBL(10960.0);
3300 DFS("1 2 31"); EXPECT_DBL(11325.0);
3301 DFS("3 am 1 2"); MKRELDATE(2,1); relative += 0.125; EXPECT_DBL(relative);
3302 DFS("1 2 3 am"); EXPECT_DBL(relative);
3304 /* 4 elements -interpreted as 2 digit date & time */
3305 DFS("1.2 3 4"); MKRELDATE(4,3); relative += 0.04305555556; EXPECT_DBL(relative);
3306 DFS("3 4 1.2"); EXPECT_DBL(relative);
3307 /* 5 elements - interpreted as 2 & 3 digit date/times */
3308 DFS("1.2.3 4 5"); MKRELDATE(5,4); relative += 0.04309027778; EXPECT_DBL(relative);
3309 DFS("1.2 3 4 5"); EXPECT_DBL(38415.04305555556);
3310 DFS("1 2 3.4.5"); MKRELDATE(2,1); relative += 0.12783564815; EXPECT_DBL(relative);
3311 DFS("1 2 3 4.5"); EXPECT_DBL(37623.17013888889);
3312 /* 6 elements - interpreted as 3 digit date/times */
3313 DFS("1.2.3 4 5 6"); EXPECT_DBL(38812.04309027778);
3314 DFS("1 2 3 4.5.6"); EXPECT_DBL(37623.17020833334);
3316 for (i = 0; i < sizeof(BadDateStrings)/sizeof(char*); i++)
3318 DFS(BadDateStrings[i]); EXPECT_MISMATCH;
3321 /* Some normal-ish strings */
3322 DFS("2 January, 1970"); EXPECT_DBL(25570.0);
3323 DFS("2 January 1970"); EXPECT_DBL(25570.0);
3324 DFS("2 Jan 1970"); EXPECT_DBL(25570.0);
3325 DFS("2/Jan/1970"); EXPECT_DBL(25570.0);
3326 DFS("2-Jan-1970"); EXPECT_DBL(25570.0);
3327 DFS("1 2 1970"); EXPECT_DBL(25570.0);
3328 DFS("1/2/1970"); EXPECT_DBL(25570.0);
3329 DFS("1-2-1970"); EXPECT_DBL(25570.0);
3330 /* Native fails "1999 January 3, 9AM". I consider that a bug in native */
3333 static void test_VarDateCopy(void)
3335 COPYTEST(77665544.0, VT_DATE, V_DATE(&vSrc), V_DATE(&vDst), V_DATEREF(&vSrc),
3336 V_DATEREF(&vDst), "%16.16g");
3339 static const char* wtoascii(LPWSTR lpszIn)
3341 static char buff[256];
3342 WideCharToMultiByte(CP_ACP, 0, lpszIn, -1, buff, sizeof(buff), NULL, NULL);
3343 return buff;
3346 #define DATE_STR(flags, str) hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, flags, VT_BSTR); \
3347 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && \
3348 V_BSTR(&vDst) && !strcmpW(V_BSTR(&vDst), str), \
3349 "hres=0x%lX, type=%d (should be VT_BSTR), *bstr=%s\n", \
3350 hres, V_VT(&vDst), V_BSTR(&vDst) ? wtoascii(V_BSTR(&vDst)) : "?")
3352 static void test_VarDateChangeTypeEx(void)
3354 static const WCHAR sz25570[] = {
3355 '1','/','2','/','1','9','7','0','\0' };
3356 static const WCHAR sz25570Nls[] = {
3357 '1','/','2','/','1','9','7','0',' ','1','2',':','0','0',':','0','0',' ','A','M','\0' };
3358 CONVVARS(CONV_TYPE);
3359 VARIANTARG vSrc, vDst;
3360 LCID lcid;
3362 in = 1.0;
3364 INITIAL_TYPETEST(VT_DATE, V_DATE, "%g");
3365 COMMON_TYPETEST;
3367 V_VT(&vDst) = VT_EMPTY;
3368 V_VT(&vSrc) = VT_DATE;
3369 V_DATE(&vSrc) = 25570.0;
3370 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
3371 DATE_STR(VARIANT_NOUSEROVERRIDE, sz25570);
3373 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
3374 if (HAVE_OLEAUT32_LOCALES)
3376 DATE_STR(VARIANT_NOUSEROVERRIDE|VARIANT_USE_NLS, sz25570Nls);
3381 * VT_CY
3384 #undef CONV_TYPE
3385 #define CONV_TYPE CY
3386 #undef EXPECTRES
3387 #define EXPECTRES(res, x) \
3388 ok(hres == S_OK || ((HRESULT)res != S_OK && hres == (HRESULT)res), \
3389 "expected hres " #x ", got hres=0x%08lx\n", hres)
3391 #define EXPECTCY(x) \
3392 ok((hres == S_OK && out.int64 == (LONGLONG)(x*CY_MULTIPLIER)), \
3393 "expected " #x "*CY_MULTIPLIER, got (%8lx %8lx); hres=0x%08lx\n", out.s.Hi, out.s.Lo, hres)
3395 #define EXPECTCY64(x,y) \
3396 ok(hres == S_OK && out.s.Hi == (long)x && out.s.Lo == y, \
3397 "expected " #x #y "(%lu,%lu), got (%lu,%lu); hres=0x%08lx\n", \
3398 (ULONG)(x), (ULONG)(y), out.s.Hi, out.s.Lo, hres)
3400 static void test_VarCyFromI1(void)
3402 CONVVARS(signed char);
3403 int i;
3405 CHECKPTR(VarCyFromI1);
3406 for (i = -128; i < 128; i++)
3408 CONVERT(VarCyFromI1,i); EXPECTCY(i);
3412 static void test_VarCyFromUI1(void)
3414 CONVVARS(BYTE);
3415 int i;
3417 CHECKPTR(VarCyFromUI1);
3418 for (i = 0; i < 256; i++)
3420 CONVERT(VarCyFromUI1,i); EXPECTCY(i);
3424 static void test_VarCyFromI2(void)
3426 CONVVARS(SHORT);
3427 int i;
3429 CHECKPTR(VarCyFromI2);
3430 for (i = -16384; i < 16384; i++)
3432 CONVERT(VarCyFromI2,i); EXPECTCY(i);
3436 static void test_VarCyFromUI2(void)
3438 CONVVARS(int);
3439 int i;
3441 CHECKPTR(VarCyFromUI2);
3442 for (i = 0; i < 32768; i++)
3444 CONVERT(VarCyFromUI2,i); EXPECTCY(i);
3448 static void test_VarCyFromI4(void)
3450 CONVVARS(int);
3452 CHECKPTR(VarCyFromI4);
3453 CONVERT(VarCyFromI4, -1); EXPECTCY(-1);
3454 CONVERT(VarCyFromI4, 0); EXPECTCY(0);
3455 CONVERT(VarCyFromI4, 1); EXPECTCY(1);
3456 CONVERT(VarCyFromI4, 0x7fffffff); EXPECTCY64(0x1387, 0xffffd8f0);
3457 CONVERT(VarCyFromI4, 0x80000000); EXPECTCY64(0xffffec78, 0);
3460 static void test_VarCyFromUI4(void)
3462 CONVVARS(unsigned int);
3464 CHECKPTR(VarCyFromUI4);
3465 CONVERT(VarCyFromUI4, 0); EXPECTCY(0);
3466 CONVERT(VarCyFromUI4, 1); EXPECTCY(1);
3467 CONVERT(VarCyFromUI4, 0x80000000); EXPECTCY64(5000, 0);
3470 static void test_VarCyFromR4(void)
3472 CONVVARS(FLOAT);
3474 CHECKPTR(VarCyFromR4);
3475 CONVERT(VarCyFromR4, -1.0f); EXPECTCY(-1);
3476 CONVERT(VarCyFromR4, 0.0f); EXPECTCY(0);
3477 CONVERT(VarCyFromR4, 1.0f); EXPECTCY(1);
3478 CONVERT(VarCyFromR4, 1.5f); EXPECTCY(1.5);
3480 CONVERT(VarCyFromR4, -1.5f); EXPECTCY(-1.5);
3481 CONVERT(VarCyFromR4, -0.6f); EXPECTCY(-0.6);
3482 CONVERT(VarCyFromR4, -0.5f); EXPECTCY(-0.5);
3483 CONVERT(VarCyFromR4, -0.4f); EXPECTCY(-0.4);
3484 CONVERT(VarCyFromR4, 0.4f); EXPECTCY(0.4);
3485 CONVERT(VarCyFromR4, 0.5f); EXPECTCY(0.5);
3486 CONVERT(VarCyFromR4, 0.6f); EXPECTCY(0.6);
3487 CONVERT(VarCyFromR4, 1.5f); EXPECTCY(1.5);
3488 CONVERT(VarCyFromR4, 1.00009f); EXPECTCY(1.0001);
3489 CONVERT(VarCyFromR4, -1.00001f); EXPECTCY(-1);
3490 CONVERT(VarCyFromR4, -1.00005f); EXPECTCY(-1);
3491 CONVERT(VarCyFromR4, -0.00009f); EXPECTCY(-0.0001);
3492 CONVERT(VarCyFromR4, -0.00005f); EXPECTCY(0);
3493 CONVERT(VarCyFromR4, -0.00001f); EXPECTCY(0);
3494 CONVERT(VarCyFromR4, 0.00001f); EXPECTCY(0);
3495 CONVERT(VarCyFromR4, 0.00005f); EXPECTCY(0);
3496 CONVERT(VarCyFromR4, 0.00009f); EXPECTCY(0.0001);
3497 CONVERT(VarCyFromR4, -1.00001f); EXPECTCY(-1);
3498 CONVERT(VarCyFromR4, -1.00005f); EXPECTCY(-1);
3499 CONVERT(VarCyFromR4, -1.00009f); EXPECTCY(-1.0001);
3502 static void test_VarCyFromR8(void)
3504 CONVVARS(DOUBLE);
3506 CHECKPTR(VarCyFromR8);
3508 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3509 /* Test our rounding is exactly the same. This fails if the special x86
3510 * code is taken out of VarCyFromR8.
3512 CONVERT(VarCyFromR8, -461168601842738.7904); EXPECTCY64(0xbfffffff, 0xffffff23);
3513 #endif
3515 CONVERT(VarCyFromR8, -4611686018427388416.1); EXPECT_OVERFLOW;
3516 CONVERT(VarCyFromR8, -1.0); EXPECTCY(-1);
3517 CONVERT(VarCyFromR8, -0.0); EXPECTCY(0);
3518 CONVERT(VarCyFromR8, 1.0); EXPECTCY(1);
3519 CONVERT(VarCyFromR8, 4611686018427387648.0); EXPECT_OVERFLOW;
3521 /* Rounding */
3522 CONVERT(VarCyFromR8, -1.5f); EXPECTCY(-1.5);
3523 CONVERT(VarCyFromR8, -0.6f); EXPECTCY(-0.6);
3524 CONVERT(VarCyFromR8, -0.5f); EXPECTCY(-0.5);
3525 CONVERT(VarCyFromR8, -0.4f); EXPECTCY(-0.4);
3526 CONVERT(VarCyFromR8, 0.4f); EXPECTCY(0.4);
3527 CONVERT(VarCyFromR8, 0.5f); EXPECTCY(0.5);
3528 CONVERT(VarCyFromR8, 0.6f); EXPECTCY(0.6);
3529 CONVERT(VarCyFromR8, 1.5f); EXPECTCY(1.5);
3530 CONVERT(VarCyFromR8, 1.00009f); EXPECTCY(1.0001);
3531 CONVERT(VarCyFromR8, -1.00001f); EXPECTCY(-1);
3532 CONVERT(VarCyFromR8, -1.00005f); EXPECTCY(-1);
3533 CONVERT(VarCyFromR8, -0.00009f); EXPECTCY(-0.0001);
3534 CONVERT(VarCyFromR8, -0.00005f); EXPECTCY(0);
3535 CONVERT(VarCyFromR8, -0.00001f); EXPECTCY(0);
3536 CONVERT(VarCyFromR8, 0.00001f); EXPECTCY(0);
3537 CONVERT(VarCyFromR8, 0.00005f); EXPECTCY(0);
3538 CONVERT(VarCyFromR8, 0.00009f); EXPECTCY(0.0001);
3539 CONVERT(VarCyFromR8, -1.00001f); EXPECTCY(-1);
3540 CONVERT(VarCyFromR8, -1.00005f); EXPECTCY(-1);
3541 CONVERT(VarCyFromR8, -1.00009f); EXPECTCY(-1.0001);
3544 static void test_VarCyFromBool(void)
3546 CONVVARS(VARIANT_BOOL);
3547 int i;
3549 CHECKPTR(VarCyFromBool);
3550 for (i = -32768; i < 32768; i++)
3552 CONVERT(VarCyFromBool, i); EXPECTCY(i);
3556 static void test_VarCyFromI8(void)
3558 CONVVARS(LONG64);
3560 CHECKPTR(VarCyFromI8);
3561 CONVERT_I8(VarCyFromI8, -214749, 2728163227ul); EXPECT_OVERFLOW;
3562 CONVERT_I8(VarCyFromI8, -214749, 2728163228ul); EXPECTCY64(2147483648ul,15808);
3563 CONVERT(VarCyFromI8, -1); EXPECTCY(-1);
3564 CONVERT(VarCyFromI8, 0); EXPECTCY(0);
3565 CONVERT(VarCyFromI8, 1); EXPECTCY(1);
3566 CONVERT_I8(VarCyFromI8, 214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3567 CONVERT_I8(VarCyFromI8, 214748, 1566804069); EXPECT_OVERFLOW;
3570 static void test_VarCyFromUI8(void)
3572 CONVVARS(ULONG64);
3574 CHECKPTR(VarCyFromUI8);
3575 CONVERT(VarCyFromUI8, 0); EXPECTCY(0);
3576 CONVERT(VarCyFromUI8, 1); EXPECTCY(1);
3577 CONVERT_I8(VarCyFromUI8, 214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3578 CONVERT_I8(VarCyFromUI8, 214748, 1566804069); EXPECT_OVERFLOW;
3581 static void test_VarCyFromDec(void)
3583 CONVVARS(DECIMAL);
3585 CHECKPTR(VarCyFromDec);
3587 CONVERT_BADDEC(VarCyFromDec);
3589 CONVERT_DEC(VarCyFromDec,0,0x80,0,1); EXPECTCY(-1);
3590 CONVERT_DEC(VarCyFromDec,0,0,0,0); EXPECTCY(0);
3591 CONVERT_DEC(VarCyFromDec,0,0,0,1); EXPECTCY(1);
3593 CONVERT_DEC64(VarCyFromDec,0,0,0,214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3594 CONVERT_DEC64(VarCyFromDec,0,0,0,214748, 1566804069); EXPECT_OVERFLOW;
3596 CONVERT_DEC(VarCyFromDec,2,0,0,100); EXPECTCY(1);
3597 CONVERT_DEC(VarCyFromDec,2,0x80,0,100); EXPECTCY(-1);
3598 CONVERT_DEC(VarCyFromDec,2,0x80,0,1); EXPECTCY(-0.01);
3599 CONVERT_DEC(VarCyFromDec,2,0,0,1); EXPECTCY(0.01);
3600 CONVERT_DEC(VarCyFromDec,2,0x80,0,1); EXPECTCY(-0.01);
3601 CONVERT_DEC(VarCyFromDec,2,0,0,999); EXPECTCY(9.99);
3602 CONVERT_DEC(VarCyFromDec,2,0x80,0,999); EXPECTCY(-9.99);
3603 CONVERT_DEC(VarCyFromDec,2,0,0,1500); EXPECTCY(15);
3604 CONVERT_DEC(VarCyFromDec,2,0x80,0,1500); EXPECTCY(-15);
3607 static void test_VarCyFromDate(void)
3609 CONVVARS(DATE);
3611 CHECKPTR(VarCyFromDate);
3613 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3614 CONVERT(VarCyFromR8, -461168601842738.7904); EXPECTCY64(0xbfffffff, 0xffffff23);
3615 #endif
3617 CONVERT(VarCyFromDate, -1.0); EXPECTCY(-1);
3618 CONVERT(VarCyFromDate, -0.0); EXPECTCY(0);
3619 CONVERT(VarCyFromDate, 1.0); EXPECTCY(1);
3620 CONVERT(VarCyFromDate, -4611686018427388416.1); EXPECT_OVERFLOW;
3621 CONVERT(VarCyFromDate, 4611686018427387648.0); EXPECT_OVERFLOW;
3623 /* Rounding */
3624 CONVERT(VarCyFromDate, -1.5f); EXPECTCY(-1.5);
3625 CONVERT(VarCyFromDate, -0.6f); EXPECTCY(-0.6);
3626 CONVERT(VarCyFromDate, -0.5f); EXPECTCY(-0.5);
3627 CONVERT(VarCyFromDate, -0.4f); EXPECTCY(-0.4);
3628 CONVERT(VarCyFromDate, 0.4f); EXPECTCY(0.4);
3629 CONVERT(VarCyFromDate, 0.5f); EXPECTCY(0.5);
3630 CONVERT(VarCyFromDate, 0.6f); EXPECTCY(0.6);
3631 CONVERT(VarCyFromDate, 1.5f); EXPECTCY(1.5);
3632 CONVERT(VarCyFromDate, 1.00009f); EXPECTCY(1.0001);
3633 CONVERT(VarCyFromDate, -1.00001f); EXPECTCY(-1);
3634 CONVERT(VarCyFromDate, -1.00005f); EXPECTCY(-1);
3635 CONVERT(VarCyFromDate, -0.00009f); EXPECTCY(-0.0001);
3636 CONVERT(VarCyFromDate, -0.00005f); EXPECTCY(0);
3637 CONVERT(VarCyFromDate, -0.00001f); EXPECTCY(0);
3638 CONVERT(VarCyFromDate, 0.00001f); EXPECTCY(0);
3639 CONVERT(VarCyFromDate, 0.00005f); EXPECTCY(0);
3640 CONVERT(VarCyFromDate, 0.00009f); EXPECTCY(0.0001);
3641 CONVERT(VarCyFromDate, -1.00001f); EXPECTCY(-1);
3642 CONVERT(VarCyFromDate, -1.00005f); EXPECTCY(-1);
3643 CONVERT(VarCyFromDate, -1.00009f); EXPECTCY(-1.0001);
3646 #define MATHVARS1 HRESULT hres; double left = 0.0; CY cyLeft, out
3647 #define MATHVARS2 MATHVARS1; double right = 0.0; CY cyRight
3648 #define MATH1(func, l) left = (double)l; pVarCyFromR8(left, &cyLeft); hres = p##func(cyLeft, &out)
3649 #define MATH2(func, l, r) left = (double)l; right = (double)r; \
3650 pVarCyFromR8(left, &cyLeft); pVarCyFromR8(right, &cyRight); \
3651 hres = p##func(cyLeft, cyRight, &out)
3653 static void test_VarCyAdd(void)
3655 MATHVARS2;
3657 CHECKPTR(VarCyAdd);
3658 MATH2(VarCyAdd, 0.5, 0.5); EXPECTCY(1);
3659 MATH2(VarCyAdd, 0.5, -0.4); EXPECTCY(0.1);
3660 MATH2(VarCyAdd, 0.5, -0.6); EXPECTCY(-0.1);
3661 MATH2(VarCyAdd, -0.5, -0.5); EXPECTCY(-1);
3662 MATH2(VarCyAdd, -922337203685476.0, -922337203685476.0); EXPECT_OVERFLOW;
3663 MATH2(VarCyAdd, -922337203685476.0, 922337203685476.0); EXPECTCY(0);
3664 MATH2(VarCyAdd, 922337203685476.0, -922337203685476.0); EXPECTCY(0);
3665 MATH2(VarCyAdd, 922337203685476.0, 922337203685476.0); EXPECT_OVERFLOW;
3668 static void test_VarCyMul(void)
3670 MATHVARS2;
3672 CHECKPTR(VarCyMul);
3673 MATH2(VarCyMul, 534443.0, 0.0); EXPECTCY(0);
3674 MATH2(VarCyMul, 0.5, 0.5); EXPECTCY(0.25);
3675 MATH2(VarCyMul, 0.5, -0.4); EXPECTCY(-0.2);
3676 MATH2(VarCyMul, 0.5, -0.6); EXPECTCY(-0.3);
3677 MATH2(VarCyMul, -0.5, -0.5); EXPECTCY(0.25);
3678 MATH2(VarCyMul, 922337203685476.0, 20000); EXPECT_OVERFLOW;
3681 static void test_VarCySub(void)
3683 MATHVARS2;
3685 CHECKPTR(VarCySub);
3686 MATH2(VarCySub, 0.5, 0.5); EXPECTCY(0);
3687 MATH2(VarCySub, 0.5, -0.4); EXPECTCY(0.9);
3688 MATH2(VarCySub, 0.5, -0.6); EXPECTCY(1.1);
3689 MATH2(VarCySub, -0.5, -0.5); EXPECTCY(0);
3690 MATH2(VarCySub, -922337203685476.0, -922337203685476.0); EXPECTCY(0);
3691 MATH2(VarCySub, -922337203685476.0, 922337203685476.0); EXPECT_OVERFLOW;
3692 MATH2(VarCySub, 922337203685476.0, -922337203685476.0); EXPECT_OVERFLOW;
3693 MATH2(VarCySub, 922337203685476.0, 922337203685476.0); EXPECTCY(0);
3696 static void test_VarCyAbs(void)
3698 MATHVARS1;
3700 CHECKPTR(VarCyAbs);
3701 MATH1(VarCyAbs, 0.5); EXPECTCY(0.5);
3702 MATH1(VarCyAbs, -0.5); EXPECTCY(0.5);
3703 MATH1(VarCyAbs, 922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3704 MATH1(VarCyAbs, -922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3707 static void test_VarCyNeg(void)
3709 MATHVARS1;
3711 CHECKPTR(VarCyNeg);
3712 MATH1(VarCyNeg, 0.5); EXPECTCY(-0.5);
3713 MATH1(VarCyNeg, -0.5); EXPECTCY(0.5);
3714 MATH1(VarCyNeg, 922337203685476.0); EXPECTCY64(2147483648ul,15808);
3715 MATH1(VarCyNeg, -922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3718 #define MATHMULI4(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3719 hres = pVarCyMulI4(cyLeft, right, &out)
3721 static void test_VarCyMulI4(void)
3723 MATHVARS1;
3724 LONG right;
3726 CHECKPTR(VarCyMulI4);
3727 MATHMULI4(534443.0, 0); EXPECTCY(0);
3728 MATHMULI4(0.5, 1); EXPECTCY(0.5);
3729 MATHMULI4(0.5, 2); EXPECTCY(1);
3730 MATHMULI4(922337203685476.0, 1); EXPECTCY64(2147483647ul,4294951488ul);
3731 MATHMULI4(922337203685476.0, 2); EXPECT_OVERFLOW;
3734 #define MATHMULI8(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3735 hres = pVarCyMulI8(cyLeft, right, &out)
3737 static void test_VarCyMulI8(void)
3739 MATHVARS1;
3740 LONG64 right;
3742 CHECKPTR(VarCyMulI8);
3743 MATHMULI8(534443.0, 0); EXPECTCY(0);
3744 MATHMULI8(0.5, 1); EXPECTCY(0.5);
3745 MATHMULI8(0.5, 2); EXPECTCY(1);
3746 MATHMULI8(922337203685476.0, 1); EXPECTCY64(2147483647ul,4294951488ul);
3747 MATHMULI8(922337203685476.0, 2); EXPECT_OVERFLOW;
3750 #define MATHCMP(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); pVarCyFromR8(right, &cyRight); \
3751 hres = pVarCyCmp(cyLeft, cyRight); out.int64 = hres
3753 static void test_VarCyCmp(void)
3755 MATHVARS2;
3757 CHECKPTR(VarCyCmp);
3758 MATHCMP(-1.0, -1.0); EXPECT_EQ;
3759 MATHCMP(-1.0, 0.0); EXPECT_LT;
3760 MATHCMP(-1.0, 1.0); EXPECT_LT;
3761 MATHCMP(-1.0, 2.0); EXPECT_LT;
3762 MATHCMP(0.0, 1.0); EXPECT_LT;
3763 MATHCMP(0.0, 0.0); EXPECT_EQ;
3764 MATHCMP(0.0, -1.0); EXPECT_GT;
3765 MATHCMP(1.0, -1.0); EXPECT_GT;
3766 MATHCMP(1.0, 0.0); EXPECT_GT;
3767 MATHCMP(1.0, 1.0); EXPECT_EQ;
3768 MATHCMP(1.0, 2.0); EXPECT_LT;
3771 #define MATHCMPR8(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3772 hres = pVarCyCmpR8(cyLeft, right); out.int64 = hres
3774 static void test_VarCyCmpR8(void)
3776 MATHVARS1;
3777 double right;
3779 CHECKPTR(VarCyCmpR8);
3780 MATHCMPR8(-1.0, -1.0); EXPECT_EQ;
3781 MATHCMPR8(-1.0, 0.0); EXPECT_LT;
3782 MATHCMPR8(-1.0, 1.0); EXPECT_LT;
3783 MATHCMPR8(-1.0, 2.0); EXPECT_LT;
3784 MATHCMPR8(0.0, 1.0); EXPECT_LT;
3785 MATHCMPR8(0.0, 0.0); EXPECT_EQ;
3786 MATHCMPR8(0.0, -1.0); EXPECT_GT;
3787 MATHCMPR8(1.0, -1.0); EXPECT_GT;
3788 MATHCMPR8(1.0, 0.0); EXPECT_GT;
3789 MATHCMPR8(1.0, 1.0); EXPECT_EQ;
3790 MATHCMPR8(1.0, 2.0); EXPECT_LT;
3793 #undef MATHRND
3794 #define MATHRND(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3795 hres = pVarCyRound(cyLeft, right, &out)
3797 static void test_VarCyRound(void)
3799 MATHVARS1;
3800 int right;
3802 CHECKPTR(VarCyRound);
3803 MATHRND(0.5432, 5); EXPECTCY(0.5432);
3804 MATHRND(0.5432, 4); EXPECTCY(0.5432);
3805 MATHRND(0.5432, 3); EXPECTCY(0.543);
3806 MATHRND(0.5432, 2); EXPECTCY(0.54);
3807 MATHRND(0.5432, 1); EXPECTCY(0.5);
3808 MATHRND(0.5532, 0); EXPECTCY(1);
3809 MATHRND(0.5532, -1); EXPECT_INVALID;
3811 MATHRND(0.5568, 5); EXPECTCY(0.5568);
3812 MATHRND(0.5568, 4); EXPECTCY(0.5568);
3813 MATHRND(0.5568, 3); EXPECTCY(0.557);
3814 MATHRND(0.5568, 2); EXPECTCY(0.56);
3815 MATHRND(0.5568, 1); EXPECTCY(0.6);
3816 MATHRND(0.5568, 0); EXPECTCY(1);
3817 MATHRND(0.5568, -1); EXPECT_INVALID;
3819 MATHRND(0.4999, 0); EXPECTCY(0);
3820 MATHRND(0.5000, 0); EXPECTCY(0);
3821 MATHRND(0.5001, 0); EXPECTCY(1);
3822 MATHRND(1.4999, 0); EXPECTCY(1);
3823 MATHRND(1.5000, 0); EXPECTCY(2);
3824 MATHRND(1.5001, 0); EXPECTCY(2);
3827 #define MATHFIX(l) left = l; pVarCyFromR8(left, &cyLeft); \
3828 hres = pVarCyFix(cyLeft, &out)
3830 static void test_VarCyFix(void)
3832 MATHVARS1;
3834 CHECKPTR(VarCyFix);
3835 MATHFIX(-1.0001); EXPECTCY(-1);
3836 MATHFIX(-1.4999); EXPECTCY(-1);
3837 MATHFIX(-1.5001); EXPECTCY(-1);
3838 MATHFIX(-1.9999); EXPECTCY(-1);
3839 MATHFIX(-0.0001); EXPECTCY(0);
3840 MATHFIX(-0.4999); EXPECTCY(0);
3841 MATHFIX(-0.5001); EXPECTCY(0);
3842 MATHFIX(-0.9999); EXPECTCY(0);
3843 MATHFIX(0.0001); EXPECTCY(0);
3844 MATHFIX(0.4999); EXPECTCY(0);
3845 MATHFIX(0.5001); EXPECTCY(0);
3846 MATHFIX(0.9999); EXPECTCY(0);
3847 MATHFIX(1.0001); EXPECTCY(1);
3848 MATHFIX(1.4999); EXPECTCY(1);
3849 MATHFIX(1.5001); EXPECTCY(1);
3850 MATHFIX(1.9999); EXPECTCY(1);
3853 #define MATHINT(l) left = l; pVarCyFromR8(left, &cyLeft); \
3854 hres = pVarCyInt(cyLeft, &out)
3856 static void test_VarCyInt(void)
3858 MATHVARS1;
3860 CHECKPTR(VarCyInt);
3861 MATHINT(-1.0001); EXPECTCY(-2);
3862 MATHINT(-1.4999); EXPECTCY(-2);
3863 MATHINT(-1.5001); EXPECTCY(-2);
3864 MATHINT(-1.9999); EXPECTCY(-2);
3865 MATHINT(-0.0001); EXPECTCY(-1);
3866 MATHINT(-0.4999); EXPECTCY(-1);
3867 MATHINT(-0.5001); EXPECTCY(-1);
3868 MATHINT(-0.9999); EXPECTCY(-1);
3869 MATHINT(0.0001); EXPECTCY(0);
3870 MATHINT(0.4999); EXPECTCY(0);
3871 MATHINT(0.5001); EXPECTCY(0);
3872 MATHINT(0.9999); EXPECTCY(0);
3873 MATHINT(1.0001); EXPECTCY(1);
3874 MATHINT(1.4999); EXPECTCY(1);
3875 MATHINT(1.5001); EXPECTCY(1);
3876 MATHINT(1.9999); EXPECTCY(1);
3880 * VT_DECIMAL
3883 #undef CONV_TYPE
3884 #define CONV_TYPE DECIMAL
3885 #undef EXPECTRES
3886 #define EXPECTRES(res, x) \
3887 ok(hres == S_OK || ((HRESULT)res != S_OK && hres == (HRESULT)res), \
3888 "expected hres " #x ", got hres=0x%08lx\n", hres)
3890 #define EXPECTDEC(scl, sgn, hi, lo) ok(hres == S_OK && \
3891 out.u.s.scale == (BYTE)(scl) && out.u.s.sign == (BYTE)(sgn) && \
3892 out.Hi32 == (ULONG)(hi) && out.u1.Lo64 == (ULONG64)(lo), \
3893 "expected (%d,%d,%d,(%lx %lx)), got (%d,%d,%ld,(%lx %lx)) hres 0x%08lx\n", \
3894 scl, sgn, hi, (LONG)((LONG64)(lo) >> 32), (LONG)((lo) & 0xffffffff), out.u.s.scale, \
3895 out.u.s.sign, out.Hi32, out.u1.s1.Mid32, out.u1.s1.Lo32, hres)
3897 #define EXPECTDEC64(scl, sgn, hi, mid, lo) ok(hres == S_OK && \
3898 out.u.s.scale == (BYTE)(scl) && out.u.s.sign == (BYTE)(sgn) && \
3899 out.Hi32 == (ULONG)(hi) && out.u1.s1.Mid32 == (ULONG)(mid) && \
3900 out.u1.s1.Lo32 == (ULONG)(lo), \
3901 "expected (%d,%d,%d,(%lx %lx)), got (%d,%d,%ld,(%lx %lx)) hres 0x%08lx\n", \
3902 scl, sgn, hi, (LONG)(mid), (LONG)(lo), out.u.s.scale, \
3903 out.u.s.sign, out.Hi32, out.u1.s1.Mid32, out.u1.s1.Lo32, hres)
3905 #define EXPECTDECI if (i < 0) EXPECTDEC(0, 0x80, 0, -i); else EXPECTDEC(0, 0, 0, i)
3907 static void test_VarDecFromI1(void)
3909 CONVVARS(signed char);
3910 int i;
3912 CHECKPTR(VarDecFromI1);
3913 for (i = -128; i < 128; i++)
3915 CONVERT(VarDecFromI1,i); EXPECTDECI;
3919 static void test_VarDecFromI2(void)
3921 CONVVARS(SHORT);
3922 int i;
3924 CHECKPTR(VarDecFromI2);
3925 for (i = -32768; i < 32768; i++)
3927 CONVERT(VarDecFromI2,i); EXPECTDECI;
3931 static void test_VarDecFromI4(void)
3933 CONVVARS(LONG);
3934 int i;
3936 CHECKPTR(VarDecFromI4);
3937 for (i = -32768; i < 32768; i++)
3939 CONVERT(VarDecFromI4,i); EXPECTDECI;
3943 static void test_VarDecFromI8(void)
3945 CONVVARS(LONG64);
3946 int i;
3948 CHECKPTR(VarDecFromI8);
3949 for (i = -32768; i < 32768; i++)
3951 CONVERT(VarDecFromI8,i); EXPECTDECI;
3955 static void test_VarDecFromUI1(void)
3957 CONVVARS(BYTE);
3958 int i;
3960 CHECKPTR(VarDecFromUI1);
3961 for (i = 0; i < 256; i++)
3963 CONVERT(VarDecFromUI1,i); EXPECTDECI;
3967 static void test_VarDecFromUI2(void)
3969 CONVVARS(USHORT);
3970 int i;
3972 CHECKPTR(VarDecFromUI2);
3973 for (i = 0; i < 65536; i++)
3975 CONVERT(VarDecFromUI2,i); EXPECTDECI;
3979 static void test_VarDecFromUI4(void)
3981 CONVVARS(ULONG);
3982 int i;
3984 CHECKPTR(VarDecFromUI4);
3985 for (i = 0; i < 65536; i++)
3987 CONVERT(VarDecFromUI4,i); EXPECTDECI;
3991 static void test_VarDecFromUI8(void)
3993 CONVVARS(ULONG64);
3994 int i;
3996 CHECKPTR(VarDecFromUI8);
3997 for (i = 0; i < 65536; i++)
3999 CONVERT(VarDecFromUI8,i); EXPECTDECI;
4003 static void test_VarDecFromBool(void)
4005 CONVVARS(SHORT);
4006 int i;
4008 CHECKPTR(VarDecFromBool);
4009 /* Test all possible type values. Note that the result is reduced to 0 or -1 */
4010 for (i = -32768; i < 0; i++)
4012 CONVERT(VarDecFromBool,i);
4013 if (i)
4014 EXPECTDEC(0,0x80,0,1);
4015 else
4016 EXPECTDEC(0,0,0,0);
4020 static void test_VarDecFromR4(void)
4022 CONVVARS(float);
4024 CHECKPTR(VarDecFromR4);
4026 CONVERT(VarDecFromR4,-0.6f); EXPECTDEC(1,0x80,0,6);
4027 CONVERT(VarDecFromR4,-0.5f); EXPECTDEC(1,0x80,0,5);
4028 CONVERT(VarDecFromR4,-0.4f); EXPECTDEC(1,0x80,0,4);
4029 CONVERT(VarDecFromR4,0.0f); EXPECTDEC(0,0,0,0);
4030 CONVERT(VarDecFromR4,0.4f); EXPECTDEC(1,0,0,4);
4031 CONVERT(VarDecFromR4,0.5f); EXPECTDEC(1,0,0,5);
4032 CONVERT(VarDecFromR4,0.6f); EXPECTDEC(1,0,0,6);
4035 static void test_VarDecFromR8(void)
4037 CONVVARS(double);
4039 CHECKPTR(VarDecFromR8);
4041 CONVERT(VarDecFromR8,-0.6); EXPECTDEC(1,0x80,0,6);
4042 CONVERT(VarDecFromR8,-0.5); EXPECTDEC(1,0x80,0,5);
4043 CONVERT(VarDecFromR8,-0.4); EXPECTDEC(1,0x80,0,4);
4044 CONVERT(VarDecFromR8,0.0); EXPECTDEC(0,0,0,0);
4045 CONVERT(VarDecFromR8,0.4); EXPECTDEC(1,0,0,4);
4046 CONVERT(VarDecFromR8,0.5); EXPECTDEC(1,0,0,5);
4047 CONVERT(VarDecFromR8,0.6); EXPECTDEC(1,0,0,6);
4050 static void test_VarDecFromDate(void)
4052 CONVVARS(DATE);
4054 CHECKPTR(VarDecFromDate);
4056 CONVERT(VarDecFromDate,-0.6); EXPECTDEC(1,0x80,0,6);
4057 CONVERT(VarDecFromDate,-0.5); EXPECTDEC(1,0x80,0,5);
4058 CONVERT(VarDecFromDate,-0.4); EXPECTDEC(1,0x80,0,4);
4059 CONVERT(VarDecFromDate,0.0); EXPECTDEC(0,0,0,0);
4060 CONVERT(VarDecFromDate,0.4); EXPECTDEC(1,0,0,4);
4061 CONVERT(VarDecFromDate,0.5); EXPECTDEC(1,0,0,5);
4062 CONVERT(VarDecFromDate,0.6); EXPECTDEC(1,0,0,6);
4065 static void test_VarDecFromStr(void)
4067 CONVVARS(LCID);
4068 OLECHAR buff[128];
4070 CHECKPTR(VarDecFromStr);
4072 in = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4074 CONVERT_STR(VarDecFromStr,NULL,0); EXPECT_MISMATCH;
4075 CONVERT_STR(VarDecFromStr,"-1", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0x80,0,1);
4076 CONVERT_STR(VarDecFromStr,"0", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0,0,0);
4077 CONVERT_STR(VarDecFromStr,"1", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0,0,1);
4078 CONVERT_STR(VarDecFromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECTDEC(1,0,0,5);
4081 static void test_VarDecFromCy(void)
4083 CONVVARS(CY);
4085 CHECKPTR(VarDecFromCy);
4087 CONVERT_CY(VarDecFromCy, -1); EXPECTDEC(4,0x80,0,10000);
4088 CONVERT_CY(VarDecFromCy, 0); EXPECTDEC(4,0,0,0);
4089 CONVERT_CY(VarDecFromCy, 1); EXPECTDEC(4,0,0,10000);
4090 CONVERT_CY(VarDecFromCy, 0.5); EXPECTDEC(4,0,0,5000);
4093 #undef MATHVARS1
4094 #define MATHVARS1 HRESULT hres; DECIMAL l, out
4095 #undef MATHVARS2
4096 #define MATHVARS2 MATHVARS1; DECIMAL r
4097 #undef MATH1
4098 #define MATH1(func) hres = p##func(&l, &out)
4099 #undef MATH2
4100 #define MATH2(func) hres = p##func(&l, &r, &out)
4102 static void test_VarDecAbs(void)
4104 MATHVARS1;
4106 CHECKPTR(VarDecAbs);
4107 SETDEC(l,0,0x80,0,1); MATH1(VarDecAbs); EXPECTDEC(0,0,0,1);
4108 SETDEC(l,0,0,0,0); MATH1(VarDecAbs); EXPECTDEC(0,0,0,0);
4109 SETDEC(l,0,0x80,0,0); MATH1(VarDecAbs); EXPECTDEC(0,0,0,0);
4110 SETDEC(l,0,0,0,1); MATH1(VarDecAbs); EXPECTDEC(0,0,0,1);
4112 /* Doesn't check for invalid input */
4113 SETDEC(l,0,0x7f,0,1); MATH1(VarDecAbs); EXPECTDEC(0,0x7f,0,1);
4114 SETDEC(l,0,0x80,29,1); MATH1(VarDecAbs); EXPECTDEC(0,0,29,1);
4117 static void test_VarDecNeg(void)
4119 MATHVARS1;
4121 CHECKPTR(VarDecNeg);
4122 SETDEC(l,0,0x80,0,1); MATH1(VarDecNeg); EXPECTDEC(0,0,0,1);
4123 SETDEC(l,0,0,0,0); MATH1(VarDecNeg); EXPECTDEC(0,0x80,0,0); /* '-0'! */
4124 SETDEC(l,0,0x80,0,0); MATH1(VarDecNeg); EXPECTDEC(0,0,0,0);
4125 SETDEC(l,0,0,0,1); MATH1(VarDecNeg); EXPECTDEC(0,0x80,0,1);
4127 /* Doesn't check for invalid input */
4128 SETDEC(l,0,0x7f,0,1); MATH1(VarDecNeg); EXPECTDEC(0,0xff,0,1);
4129 SETDEC(l,0,0x80,29,1); MATH1(VarDecNeg); EXPECTDEC(0,0,29,1);
4130 SETDEC(l,0,0,29,1); MATH1(VarDecNeg); EXPECTDEC(0,0x80,29,1);
4133 static void test_VarDecAdd(void)
4135 MATHVARS2;
4137 CHECKPTR(VarDecAdd);
4138 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecAdd); EXPECTDEC(0,0,0,0);
4139 SETDEC(l,0,0,0,0); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,1);
4140 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,1);
4142 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,0); MATH2(VarDecAdd); EXPECTDEC(0,0,0,1);
4143 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,2);
4144 SETDEC(l,0,0,0,1); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,0); /* '-0'! */
4145 SETDEC(l,0,0,0,1); SETDEC(r,0,0x80,0,2); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,1);
4147 SETDEC(l,0,0x80,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,1);
4148 SETDEC(l,0,0x80,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,0);
4149 SETDEC(l,0,0x80,0,1); SETDEC(r,0,0,0,2); MATH2(VarDecAdd); EXPECTDEC(0,0,0,1);
4150 SETDEC(l,0,0x80,0,1); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,2);
4151 SETDEC(l,0,0x80,0,2); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,1);
4153 SETDEC(l,0,0,0,0xffffffff); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,0xfffffffe);
4154 SETDEC(l,0,0,0,0xffffffff); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,(ULONG64)1 << 32);
4155 SETDEC(l,0,0,0,0xffffffff); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,(ULONG64)1 << 32);
4157 SETDEC64(l,0,0,0,0xffffffff,0); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC64(0,0,0,0xffffffff,1);
4158 SETDEC64(l,0,0,0,0xffffffff,0); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd);
4159 EXPECTDEC64(0,0,0,0xfffffffe,0xffffffff);
4161 SETDEC64(l,0,0,0,0xffffffff,0xffffffff); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,1,0);
4162 SETDEC64(l,0,0,0,0xffffffff,0xffffffff); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd);
4163 EXPECTDEC64(0,0,0,0xffffffff,0xfffffffe);
4165 SETDEC(l,0,0,0xffffffff,0); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0xffffffff,1);
4166 SETDEC(l,0,0,0xffffffff,0); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd);
4167 EXPECTDEC64(0,0,0xfffffffe,0xffffffff,0xffffffff);
4169 SETDEC64(l,0,0,0xffffffff,0xffffffff,0xffffffff);SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd);
4170 EXPECTDEC64(0,0,0xffffffff,0xffffffff,0xfffffffe);
4171 SETDEC64(l,0,0,0xffffffff,0xffffffff,0xffffffff);SETDEC(r,0,0,0,1); MATH2(VarDecAdd);
4172 ok(hres == DISP_E_OVERFLOW,"Expected overflow, got (%d,%d,%ld,(%8lx,%8lx)x) hres 0x%08lx\n",
4173 out.u.s.scale, out.u.s.sign, out.Hi32, out.u1.s1.Mid32, out.u1.s1.Lo32, hres);
4175 /* Promotes to the highest scale, so here the results are in the scale of 2 */
4176 SETDEC(l,2,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecAdd); EXPECTDEC(2,0,0,0);
4177 SETDEC(l,2,0,0,100); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(2,0,0,200);
4180 static void test_VarDecSub(void)
4182 MATHVARS2;
4184 CHECKPTR(VarDecSub);
4185 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecSub); EXPECTDEC(0,0x80,0,0);
4186 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecSub); EXPECTDEC(0,0x80,0,1);
4187 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecSub); EXPECTDEC(0,0x80,0,0);
4188 SETDEC(l,0,0,0,1); SETDEC(r,0,0x80,0,1); MATH2(VarDecSub); EXPECTDEC(0,0,0,2);
4191 static void test_VarDecCmp(void)
4193 MATHVARS1;
4195 CHECKPTR(VarDecCmp);
4196 SETDEC(l,0,0,0,1); SETDEC(out,0,0,0,1); MATH1(VarDecCmp); EXPECT_EQ;
4197 SETDEC(l,0,0,0,1); SETDEC(out,0,0,0,0); MATH1(VarDecCmp); EXPECT_GT;
4198 SETDEC(l,0,0,0,0); SETDEC(out,0,0,0,1); MATH1(VarDecCmp); EXPECT_LT;
4202 * VT_BOOL
4205 #undef CONV_TYPE
4206 #define CONV_TYPE VARIANT_BOOL
4207 #undef _EXPECTRES
4208 #define _EXPECTRES(res, x, fs) \
4209 ok((hres == S_OK && out == (CONV_TYPE)(x)) || ((HRESULT)res != S_OK && hres == (HRESULT)res), \
4210 "expected " #x ", got " fs "; hres=0x%08lx\n", out, hres)
4211 #undef EXPECTRES
4212 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%d")
4213 #undef CONVERTRANGE
4214 #define CONVERTRANGE(func,start,end) for (i = start; i < end; i++) { \
4215 CONVERT(func, i); if (i) { EXPECT(VARIANT_TRUE); } else { EXPECT(VARIANT_FALSE); } }
4217 static void test_VarBoolFromI1(void)
4219 CONVVARS(signed char);
4220 int i;
4222 CHECKPTR(VarBoolFromI1);
4223 CONVERTRANGE(VarBoolFromI1, -128, 128);
4226 static void test_VarBoolFromUI1(void)
4228 CONVVARS(BYTE);
4229 int i;
4231 CHECKPTR(VarBoolFromUI1);
4232 CONVERTRANGE(VarBoolFromUI1, 0, 256);
4235 static void test_VarBoolFromI2(void)
4237 CONVVARS(SHORT);
4238 int i;
4240 CHECKPTR(VarBoolFromI2);
4241 CONVERTRANGE(VarBoolFromI2, -32768, 32768);
4244 static void test_VarBoolFromUI2(void)
4246 CONVVARS(USHORT);
4247 int i;
4249 CHECKPTR(VarBoolFromUI2);
4250 CONVERTRANGE(VarBoolFromUI2, 0, 65536);
4253 static void test_VarBoolFromI4(void)
4255 CONVVARS(int);
4257 CHECKPTR(VarBoolFromI4);
4258 CONVERT(VarBoolFromI4, 0x80000000); EXPECT(VARIANT_TRUE);
4259 CONVERT(VarBoolFromI4, -1); EXPECT(VARIANT_TRUE);
4260 CONVERT(VarBoolFromI4, 0); EXPECT(VARIANT_FALSE);
4261 CONVERT(VarBoolFromI4, 1); EXPECT(VARIANT_TRUE);
4262 CONVERT(VarBoolFromI4, 0x7fffffff); EXPECT(VARIANT_TRUE);
4265 static void test_VarBoolFromUI4(void)
4267 CONVVARS(ULONG);
4269 CHECKPTR(VarBoolFromUI4);
4270 CONVERT(VarBoolFromI4, 0); EXPECT(VARIANT_FALSE);
4271 CONVERT(VarBoolFromI4, 1); EXPECT(VARIANT_TRUE);
4272 CONVERT(VarBoolFromI4, 0x80000000); EXPECT(VARIANT_TRUE);
4275 static void test_VarBoolFromR4(void)
4277 CONVVARS(FLOAT);
4279 CHECKPTR(VarBoolFromR4);
4280 CONVERT(VarBoolFromR4, -1.0f); EXPECT(VARIANT_TRUE);
4281 CONVERT(VarBoolFromR4, 0.0f); EXPECT(VARIANT_FALSE);
4282 CONVERT(VarBoolFromR4, 1.0f); EXPECT(VARIANT_TRUE);
4283 CONVERT(VarBoolFromR4, 1.5f); EXPECT(VARIANT_TRUE);
4285 /* Rounding */
4286 CONVERT(VarBoolFromR4, -1.5f); EXPECT(VARIANT_TRUE);
4287 CONVERT(VarBoolFromR4, -0.6f); EXPECT(VARIANT_TRUE);
4288 CONVERT(VarBoolFromR4, -0.5f); EXPECT(VARIANT_TRUE);
4289 CONVERT(VarBoolFromR4, -0.4f); EXPECT(VARIANT_TRUE);
4290 CONVERT(VarBoolFromR4, 0.4f); EXPECT(VARIANT_TRUE);
4291 CONVERT(VarBoolFromR4, 0.5f); EXPECT(VARIANT_TRUE);
4292 CONVERT(VarBoolFromR4, 0.6f); EXPECT(VARIANT_TRUE);
4293 CONVERT(VarBoolFromR4, 1.5f); EXPECT(VARIANT_TRUE);
4296 static void test_VarBoolFromR8(void)
4298 CONVVARS(DOUBLE);
4300 /* Hopefully we made the point with R4 above that rounding is
4301 * irrelevant, so we'll skip that for R8 and Date
4303 CHECKPTR(VarBoolFromR8);
4304 CONVERT(VarBoolFromR8, -1.0); EXPECT(VARIANT_TRUE);
4305 CONVERT(VarBoolFromR8, -0.0); EXPECT(VARIANT_FALSE);
4306 CONVERT(VarBoolFromR8, 1.0); EXPECT(VARIANT_TRUE);
4309 static void test_VarBoolFromCy(void)
4311 CONVVARS(CY);
4313 CHECKPTR(VarBoolFromCy);
4314 CONVERT_CY(VarBoolFromCy, -32769); EXPECT(VARIANT_TRUE);
4315 CONVERT_CY(VarBoolFromCy, -32768); EXPECT(VARIANT_TRUE);
4316 CONVERT_CY(VarBoolFromCy, -1); EXPECT(VARIANT_TRUE);
4317 CONVERT_CY(VarBoolFromCy, 0); EXPECT(VARIANT_FALSE);
4318 CONVERT_CY(VarBoolFromCy, 1); EXPECT(VARIANT_TRUE);
4319 CONVERT_CY(VarBoolFromCy, 32767); EXPECT(VARIANT_TRUE);
4320 CONVERT_CY(VarBoolFromCy, 32768); EXPECT(VARIANT_TRUE);
4323 static void test_VarBoolFromI8(void)
4325 CONVVARS(LONG64);
4327 CHECKPTR(VarBoolFromI8);
4328 CONVERT(VarBoolFromI8, -1); EXPECT(VARIANT_TRUE);
4329 CONVERT(VarBoolFromI8, 0); EXPECT(VARIANT_FALSE);
4330 CONVERT(VarBoolFromI8, 1); EXPECT(VARIANT_TRUE);
4333 static void test_VarBoolFromUI8(void)
4335 CONVVARS(ULONG64);
4337 CHECKPTR(VarBoolFromUI8);
4338 CONVERT(VarBoolFromUI8, 0); EXPECT(VARIANT_FALSE);
4339 CONVERT(VarBoolFromUI8, 1); EXPECT(VARIANT_TRUE);
4342 static void test_VarBoolFromDec(void)
4344 CONVVARS(DECIMAL);
4346 CHECKPTR(VarBoolFromDec);
4347 CONVERT_BADDEC(VarBoolFromDec);
4349 if (HAVE_OLEAUT32_DECIMAL)
4351 /* Early versions of oleaut32 don't catch these errors */
4352 CONVERT_DEC(VarBoolFromDec,29,0,0,0); EXPECT_INVALID;
4353 CONVERT_DEC(VarBoolFromDec,0,0x1,0,0); EXPECT_INVALID;
4354 CONVERT_DEC(VarBoolFromDec,0,0x40,0,0); EXPECT_INVALID;
4355 CONVERT_DEC(VarBoolFromDec,0,0x7f,0,0); EXPECT_INVALID;
4358 CONVERT_DEC(VarBoolFromDec,0,0x80,0,1); EXPECT(VARIANT_TRUE);
4359 CONVERT_DEC(VarBoolFromDec,0,0,0,0); EXPECT(VARIANT_FALSE);
4360 CONVERT_DEC(VarBoolFromDec,0,0,0,1); EXPECT(VARIANT_TRUE);
4361 CONVERT_DEC(VarBoolFromDec,0,0,1,0); EXPECT(VARIANT_TRUE);
4363 CONVERT_DEC(VarBoolFromDec,2,0,0,CY_MULTIPLIER); EXPECT(VARIANT_TRUE);
4364 CONVERT_DEC(VarBoolFromDec,2,0x80,0,CY_MULTIPLIER); EXPECT(VARIANT_TRUE);
4367 static void test_VarBoolFromDate(void)
4369 CONVVARS(DATE);
4371 CHECKPTR(VarBoolFromDate);
4372 CONVERT(VarBoolFromDate, -1.0); EXPECT(VARIANT_TRUE);
4373 CONVERT(VarBoolFromDate, -0.0); EXPECT(VARIANT_FALSE);
4374 CONVERT(VarBoolFromDate, 1.0); EXPECT(VARIANT_TRUE);
4377 static void test_VarBoolFromStr(void)
4379 CONVVARS(LCID);
4380 OLECHAR buff[128];
4382 CHECKPTR(VarBoolFromStr);
4384 in = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4386 CONVERT_STR(VarBoolFromStr,NULL,0);
4387 if (hres != E_INVALIDARG)
4388 EXPECT_MISMATCH;
4390 /* #FALSE# and #TRUE# Are always accepted */
4391 CONVERT_STR(VarBoolFromStr,"#FALSE#",0); EXPECT(VARIANT_FALSE);
4392 CONVERT_STR(VarBoolFromStr,"#TRUE#",0); EXPECT(VARIANT_TRUE);
4394 /* Match of #FALSE# and #TRUE# is case sensitive */
4395 CONVERT_STR(VarBoolFromStr,"#False#",0); EXPECT_MISMATCH;
4396 /* But match against English is not */
4397 CONVERT_STR(VarBoolFromStr,"false",0); EXPECT(VARIANT_FALSE);
4398 CONVERT_STR(VarBoolFromStr,"False",0); EXPECT(VARIANT_FALSE);
4399 /* On/Off and yes/no are not acceptable inputs, with any flags set */
4400 CONVERT_STR(VarBoolFromStr,"On",0xffffffff); EXPECT_MISMATCH;
4401 CONVERT_STR(VarBoolFromStr,"Yes",0xffffffff); EXPECT_MISMATCH;
4403 /* Change the LCID. This doesn't make any difference for text,unless we ask
4404 * to check local boolean text with the VARIANT_LOCALBOOL flag. */
4405 in = MAKELCID(MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT), SORT_DEFAULT);
4407 /* #FALSE# and #TRUE# are accepted in all locales */
4408 CONVERT_STR(VarBoolFromStr,"#FALSE#",0); EXPECT(VARIANT_FALSE);
4409 CONVERT_STR(VarBoolFromStr,"#TRUE#",0); EXPECT(VARIANT_TRUE);
4410 CONVERT_STR(VarBoolFromStr,"#FALSE#",VARIANT_LOCALBOOL); EXPECT(VARIANT_FALSE);
4411 CONVERT_STR(VarBoolFromStr,"#TRUE#",VARIANT_LOCALBOOL); EXPECT(VARIANT_TRUE);
4413 /* English is accepted regardless of the locale */
4414 CONVERT_STR(VarBoolFromStr,"false",0); EXPECT(VARIANT_FALSE);
4415 /* And is still not case sensitive */
4416 CONVERT_STR(VarBoolFromStr,"False",0); EXPECT(VARIANT_FALSE);
4418 if (HAVE_OLEAUT32_LOCALES)
4420 /* French is rejected without VARIANT_LOCALBOOL */
4421 CONVERT_STR(VarBoolFromStr,"faux",0); EXPECT_MISMATCH;
4422 /* But accepted if this flag is given */
4423 CONVERT_STR(VarBoolFromStr,"faux",VARIANT_LOCALBOOL); EXPECT(VARIANT_FALSE);
4424 /* Regardless of case - from this we assume locale text comparasons ignore case */
4425 CONVERT_STR(VarBoolFromStr,"Faux",VARIANT_LOCALBOOL); EXPECT(VARIANT_FALSE);
4427 /* Changing the locale prevents the localised text from being compared -
4428 * this demonstrates that only the indicated LCID and English are searched */
4429 in = MAKELCID(MAKELANGID(LANG_POLISH, SUBLANG_DEFAULT), SORT_DEFAULT);
4430 CONVERT_STR(VarBoolFromStr,"faux",VARIANT_LOCALBOOL); EXPECT_MISMATCH;
4433 /* Numeric strings are read as 0 or non-0 */
4434 CONVERT_STR(VarBoolFromStr,"0",0); EXPECT(VARIANT_FALSE);
4435 CONVERT_STR(VarBoolFromStr,"-1",0); EXPECT(VARIANT_TRUE);
4436 CONVERT_STR(VarBoolFromStr,"+1",0); EXPECT(VARIANT_TRUE);
4438 if (HAVE_OLEAUT32_LOCALES)
4440 /* Numeric strings are read as floating point numbers. The line below fails
4441 * because '.' is not a valid decimal separator for Polish numbers */
4442 CONVERT_STR(VarBoolFromStr,"0.1",0); EXPECT_MISMATCH;
4445 /* Changing the lcid back to US English reads the r8 correctly */
4446 in = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4447 CONVERT_STR(VarBoolFromStr,"0.1",0); EXPECT(VARIANT_TRUE);
4450 static void test_VarBoolCopy(void)
4452 COPYTEST(1, VT_BOOL, V_BOOL(&vSrc), V_BOOL(&vDst), V_BOOLREF(&vSrc), V_BOOLREF(&vDst), "%d");
4455 #define BOOL_STR(flags, str) hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, flags, VT_BSTR); \
4456 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && \
4457 V_BSTR(&vDst) && !memcmp(V_BSTR(&vDst), str, sizeof(str)), \
4458 "hres=0x%lX, type=%d (should be VT_BSTR), *bstr='%c'\n", \
4459 hres, V_VT(&vDst), V_BSTR(&vDst) ? *V_BSTR(&vDst) : '?')
4461 static void test_VarBoolChangeTypeEx(void)
4463 static const WCHAR szTrue[] = { 'T','r','u','e','\0' };
4464 static const WCHAR szFalse[] = { 'F','a','l','s','e','\0' };
4465 static const WCHAR szFaux[] = { 'F','a','u','x','\0' };
4466 CONVVARS(CONV_TYPE);
4467 VARIANTARG vSrc, vDst;
4468 LCID lcid;
4470 in = 1;
4472 INITIAL_TYPETEST(VT_BOOL, V_BOOL, "%d");
4473 COMMON_TYPETEST;
4475 /* The common tests convert to a number. Try the different flags */
4476 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4478 V_VT(&vSrc) = VT_BOOL;
4479 V_BOOL(&vSrc) = 1;
4481 if (!IS_ANCIENT)
4483 BOOL_STR(VARIANT_ALPHABOOL, szTrue);
4484 V_BOOL(&vSrc) = 0;
4485 BOOL_STR(VARIANT_ALPHABOOL, szFalse);
4488 if (HAVE_OLEAUT32_LOCALES)
4490 lcid = MAKELCID(MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT), SORT_DEFAULT);
4492 /* VARIANT_ALPHABOOL is always English */
4493 BOOL_STR(VARIANT_ALPHABOOL, szFalse);
4494 /* VARIANT_LOCALBOOL uses the localised text */
4495 BOOL_STR(VARIANT_LOCALBOOL, szFaux);
4496 /* Both flags together acts as VARIANT_LOCALBOOL */
4497 BOOL_STR(VARIANT_ALPHABOOL|VARIANT_LOCALBOOL, szFaux);
4502 * BSTR
4505 static void test_VarBstrFromR4(void)
4507 static const WCHAR szNative[] = { '6','5','4','3','2','2','.','3','\0' };
4508 LCID lcid;
4509 HRESULT hres;
4510 BSTR bstr = NULL;
4512 float f;
4514 CHECKPTR(VarBstrFromR4);
4516 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4517 f = 654322.23456,
4518 hres = pVarBstrFromR4(f, lcid, 0, &bstr);
4519 ok(hres == S_OK, "got hres 0x%08lx\n", hres);
4520 if (bstr)
4522 todo_wine {
4523 /* MSDN states that rounding of R4/R8 is dependent on the underlying
4524 * bit pattern of the number and so is architecture dependent. In this
4525 * case Wine returns .2 (which is more correct) and Native returns .3
4527 ok(memcmp(bstr, szNative, sizeof(szNative)) == 0, "string different\n");
4532 #define BSTR_DATE(dt,str) SysFreeString(bstr); bstr = NULL; \
4533 hres = pVarBstrFromDate(dt,lcid,LOCALE_NOUSEROVERRIDE,&bstr); \
4534 if (bstr) WideCharToMultiByte(CP_ACP, 0, bstr, -1, buff, sizeof(buff), 0, 0); \
4535 else buff[0] = 0; \
4536 ok(hres == S_OK && !strcmp(str,buff), "Expected '%s', got '%s', hres = 0x%08lx\n", \
4537 str, buff, hres)
4539 static void test_VarBstrFromDate(void)
4541 char buff[256];
4542 LCID lcid;
4543 HRESULT hres;
4544 BSTR bstr = NULL;
4546 CHECKPTR(VarBstrFromDate);
4547 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
4549 BSTR_DATE(0.0, "12:00:00 AM");
4550 BSTR_DATE(3.34, "1/2/1900 8:09:36 AM");
4551 BSTR_DATE(3339.34, "2/20/1909 8:09:36 AM");
4552 BSTR_DATE(365.00, "12/30/1900");
4553 BSTR_DATE(365.25, "12/30/1900 6:00:00 AM");
4554 BSTR_DATE(1461.0, "12/31/1903");
4555 BSTR_DATE(1461.5, "12/31/1903 12:00:00 PM");
4558 /* Get the internal representation of a BSTR */
4559 static inline LPINTERNAL_BSTR Get(const BSTR lpszString)
4561 return lpszString ? (LPINTERNAL_BSTR)((char*)lpszString - sizeof(DWORD)) : NULL;
4564 static inline BSTR GetBSTR(const LPINTERNAL_BSTR bstr)
4566 return (BSTR)bstr->szString;
4569 static void test_SysStringLen()
4571 INTERNAL_BSTR bstr;
4572 BSTR str = GetBSTR(&bstr);
4574 bstr.dwLen = 0;
4575 ok (SysStringLen(str) == 0, "Expected dwLen 0, got %d\n", SysStringLen(str));
4576 bstr.dwLen = 2;
4577 ok (SysStringLen(str) == 1, "Expected dwLen 1, got %d\n", SysStringLen(str));
4580 static void test_SysStringByteLen()
4582 INTERNAL_BSTR bstr;
4583 BSTR str = GetBSTR(&bstr);
4585 bstr.dwLen = 0;
4586 ok (SysStringByteLen(str) == 0, "Expected dwLen 0, got %d\n", SysStringLen(str));
4587 bstr.dwLen = 2;
4588 ok (SysStringByteLen(str) == 2, "Expected dwLen 2, got %d\n", SysStringByteLen(str));
4591 static void test_SysAllocString()
4593 const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
4594 BSTR str;
4596 str = SysAllocString(NULL);
4597 ok (str == NULL, "Expected NULL, got %p\n", str);
4599 str = SysAllocString(szTest);
4600 ok (str != NULL, "Expected non-NULL\n");
4601 if (str)
4603 LPINTERNAL_BSTR bstr = Get(str);
4605 ok (bstr->dwLen == 8, "Expected 8, got %ld\n", bstr->dwLen);
4606 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
4607 SysFreeString(str);
4611 static void test_SysAllocStringLen()
4613 const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
4614 BSTR str;
4616 /* Very early native dlls do not limit the size of strings, so skip this test */
4617 #if 0
4618 str = SysAllocStringLen(szTest, 0x80000000);
4619 todo_wine {
4620 ok (str == NULL, "Expected NULL, got %p\n", str);
4622 #endif
4624 str = SysAllocStringLen(NULL, 0);
4625 ok (str != NULL, "Expected non-NULL\n");
4626 if (str)
4628 LPINTERNAL_BSTR bstr = Get(str);
4630 ok (bstr->dwLen == 0, "Expected 0, got %ld\n", bstr->dwLen);
4631 ok (!bstr->szString[0], "String not empty\n");
4632 SysFreeString(str);
4635 str = SysAllocStringLen(szTest, 4);
4636 ok (str != NULL, "Expected non-NULL\n");
4637 if (str)
4639 LPINTERNAL_BSTR bstr = Get(str);
4641 ok (bstr->dwLen == 8, "Expected 8, got %ld\n", bstr->dwLen);
4642 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
4643 SysFreeString(str);
4647 static void test_SysAllocStringByteLen()
4649 const OLECHAR szTest[10] = { 'T','e','s','t','\0' };
4650 const CHAR szTestA[6] = { 'T','e','s','t','\0','?' };
4651 BSTR str;
4653 str = SysAllocStringByteLen(szTestA, 0x80000000);
4654 ok (str == NULL, "Expected NULL, got %p\n", str);
4656 str = SysAllocStringByteLen(NULL, 0);
4657 ok (str != NULL, "Expected non-NULL\n");
4658 if (str)
4660 LPINTERNAL_BSTR bstr = Get(str);
4662 ok (bstr->dwLen == 0, "Expected 0, got %ld\n", bstr->dwLen);
4663 ok (!bstr->szString[0], "String not empty\n");
4664 SysFreeString(str);
4667 str = SysAllocStringByteLen(szTestA, 4);
4668 ok (str != NULL, "Expected non-NULL\n");
4669 if (str)
4671 LPINTERNAL_BSTR bstr = Get(str);
4673 ok (bstr->dwLen == 4, "Expected 4, got %ld\n", bstr->dwLen);
4674 ok (!lstrcmpA((LPCSTR)bstr->szString, szTestA), "String different\n");
4675 SysFreeString(str);
4678 /* Odd lengths are allocated rounded up, but truncated at the right position */
4679 str = SysAllocStringByteLen(szTestA, 3);
4680 ok (str != NULL, "Expected non-NULL\n");
4681 if (str)
4683 const CHAR szTestTruncA[4] = { 'T','e','s','\0' };
4684 LPINTERNAL_BSTR bstr = Get(str);
4686 ok (bstr->dwLen == 3, "Expected 3, got %ld\n", bstr->dwLen);
4687 ok (!lstrcmpA((LPCSTR)bstr->szString, szTestTruncA), "String different\n");
4688 SysFreeString(str);
4691 str = SysAllocStringByteLen((LPCSTR)szTest, 8);
4692 ok (str != NULL, "Expected non-NULL\n");
4693 if (str)
4695 LPINTERNAL_BSTR bstr = Get(str);
4697 ok (bstr->dwLen == 8, "Expected 8, got %ld\n", bstr->dwLen);
4698 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
4699 SysFreeString(str);
4703 static void test_SysReAllocString()
4705 const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
4706 const OLECHAR szSmaller[2] = { 'x','\0' };
4707 const OLECHAR szLarger[7] = { 'L','a','r','g','e','r','\0' };
4708 BSTR str;
4710 str = SysAllocStringLen(szTest, 4);
4711 ok (str != NULL, "Expected non-NULL\n");
4712 if (str)
4714 LPINTERNAL_BSTR bstr;
4715 BSTR oldstr = str;
4716 int changed;
4718 bstr = Get(str);
4719 ok (bstr->dwLen == 8, "Expected 8, got %ld\n", bstr->dwLen);
4720 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
4722 changed = SysReAllocString(&str, szSmaller);
4723 ok (changed == 1, "Expected 1, got %d\n", changed);
4724 ok (str == oldstr, "Created new string\n");
4725 bstr = Get(str);
4726 ok (bstr->dwLen == 2, "Expected 2, got %ld\n", bstr->dwLen);
4727 ok (!lstrcmpW(bstr->szString, szSmaller), "String different\n");
4729 oldstr = str;
4730 changed = SysReAllocString(&str, szLarger);
4731 ok (changed == 1, "Expected 1, got %d\n", changed);
4732 /* Early versions always make new strings rather than resizing */
4733 /* ok (str == oldstr, "Created new string\n"); */
4734 bstr = Get(str);
4735 ok (bstr->dwLen == 12, "Expected 12, got %ld\n", bstr->dwLen);
4736 ok (!lstrcmpW(bstr->szString, szLarger), "String different\n");
4738 SysFreeString(str);
4742 static void test_SysReAllocStringLen()
4744 const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
4745 const OLECHAR szSmaller[2] = { 'x','\0' };
4746 const OLECHAR szLarger[7] = { 'L','a','r','g','e','r','\0' };
4747 BSTR str;
4749 str = SysAllocStringLen(szTest, 4);
4750 ok (str != NULL, "Expected non-NULL\n");
4751 if (str)
4753 LPINTERNAL_BSTR bstr;
4754 BSTR oldstr = str;
4755 int changed;
4757 bstr = Get(str);
4758 ok (bstr->dwLen == 8, "Expected 8, got %ld\n", bstr->dwLen);
4759 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
4761 changed = SysReAllocStringLen(&str, szSmaller, 1);
4762 ok (changed == 1, "Expected 1, got %d\n", changed);
4763 ok (str == oldstr, "Created new string\n");
4764 bstr = Get(str);
4765 ok (bstr->dwLen == 2, "Expected 2, got %ld\n", bstr->dwLen);
4766 ok (!lstrcmpW(bstr->szString, szSmaller), "String different\n");
4768 oldstr = str;
4769 changed = SysReAllocStringLen(&str, szLarger, 6);
4770 ok (changed == 1, "Expected 1, got %d\n", changed);
4771 /* Early versions always make new strings rather than resizing */
4772 /* ok (str == oldstr, "Created new string\n"); */
4773 bstr = Get(str);
4774 ok (bstr->dwLen == 12, "Expected 12, got %ld\n", bstr->dwLen);
4775 ok (!lstrcmpW(bstr->szString, szLarger), "String different\n");
4777 SysFreeString(str);
4781 static void test_BstrCopy()
4783 const CHAR szTestA[6] = { 'T','e','s','t','\0','?' };
4784 const CHAR szTestTruncA[4] = { 'T','e','s','\0' };
4785 LPINTERNAL_BSTR bstr;
4786 BSTR str;
4787 HRESULT hres;
4788 VARIANT vt1, vt2;
4790 str = SysAllocStringByteLen(szTestA, 3);
4791 ok (str != NULL, "Expected non-NULL\n");
4792 if (str)
4794 V_VT(&vt1) = VT_BSTR;
4795 V_BSTR(&vt1) = str;
4796 V_VT(&vt2) = VT_EMPTY;
4797 hres = VariantCopy(&vt2, &vt1);
4798 ok (hres == S_OK,"Failed to copy binary bstring with hres 0x%08lx\n", hres);
4799 bstr = Get(V_BSTR(&vt2));
4800 ok (bstr->dwLen == 3, "Expected 3, got %ld\n", bstr->dwLen);
4801 ok (!lstrcmpA((LPCSTR)bstr->szString, szTestTruncA), "String different\n");
4805 /* IUnknown */
4807 static void test_IUnknownClear(void)
4809 HRESULT hres;
4810 VARIANTARG v;
4811 DummyDispatch u = { &DummyDispatch_VTable, 1, VT_UI1, FALSE };
4812 IUnknown* pu = (IUnknown*)&u;
4814 /* Test that IUnknown_Release is called on by-value */
4815 V_VT(&v) = VT_UNKNOWN;
4816 V_UNKNOWN(&v) = (IUnknown*)&u;
4817 hres = VariantClear(&v);
4818 ok(hres == S_OK && u.ref == 0 && V_VT(&v) == VT_EMPTY,
4819 "clear unknown: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4820 S_OK, 0, VT_EMPTY, hres, u.ref, V_VT(&v));
4822 /* But not when clearing a by-reference*/
4823 u.ref = 1;
4824 V_VT(&v) = VT_UNKNOWN|VT_BYREF;
4825 V_UNKNOWNREF(&v) = &pu;
4826 hres = VariantClear(&v);
4827 ok(hres == S_OK && u.ref == 1 && V_VT(&v) == VT_EMPTY,
4828 "clear dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4829 S_OK, 1, VT_EMPTY, hres, u.ref, V_VT(&v));
4832 static void test_IUnknownCopy(void)
4834 HRESULT hres;
4835 VARIANTARG vSrc, vDst;
4836 DummyDispatch u = { &DummyDispatch_VTable, 1, VT_UI1, FALSE };
4837 IUnknown* pu = (IUnknown*)&u;
4839 /* AddRef is called on by-value copy */
4840 VariantInit(&vDst);
4841 V_VT(&vSrc) = VT_UNKNOWN;
4842 V_UNKNOWN(&vSrc) = pu;
4843 hres = VariantCopy(&vDst, &vSrc);
4844 ok(hres == S_OK && u.ref == 2 && V_VT(&vDst) == VT_UNKNOWN,
4845 "copy unknown: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4846 S_OK, 2, VT_EMPTY, hres, u.ref, V_VT(&vDst));
4848 /* AddRef is skipped on copy of by-reference IDispatch */
4849 VariantInit(&vDst);
4850 u.ref = 1;
4851 V_VT(&vSrc) = VT_UNKNOWN|VT_BYREF;
4852 V_UNKNOWNREF(&vSrc) = &pu;
4853 hres = VariantCopy(&vDst, &vSrc);
4854 ok(hres == S_OK && u.ref == 1 && V_VT(&vDst) == (VT_UNKNOWN|VT_BYREF),
4855 "copy unknown: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4856 S_OK, 1, VT_DISPATCH, hres, u.ref, V_VT(&vDst));
4858 /* AddRef is called copying by-reference IDispatch with indirection */
4859 VariantInit(&vDst);
4860 u.ref = 1;
4861 V_VT(&vSrc) = VT_UNKNOWN|VT_BYREF;
4862 V_UNKNOWNREF(&vSrc) = &pu;
4863 hres = VariantCopyInd(&vDst, &vSrc);
4864 ok(hres == S_OK && u.ref == 2 && V_VT(&vDst) == VT_UNKNOWN,
4865 "copy unknown: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4866 S_OK, 2, VT_DISPATCH, hres, u.ref, V_VT(&vDst));
4868 /* Indirection in place also calls AddRef */
4869 u.ref = 1;
4870 V_VT(&vSrc) = VT_UNKNOWN|VT_BYREF;
4871 V_UNKNOWNREF(&vSrc) = &pu;
4872 hres = VariantCopyInd(&vSrc, &vSrc);
4873 ok(hres == S_OK && u.ref == 2 && V_VT(&vSrc) == VT_UNKNOWN,
4874 "copy unknown: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4875 S_OK, 2, VT_DISPATCH, hres, u.ref, V_VT(&vSrc));
4878 static void test_IUnknownChangeTypeEx(void)
4880 HRESULT hres;
4881 VARIANTARG vSrc, vDst;
4882 LCID lcid;
4883 VARTYPE vt;
4884 DummyDispatch u = { &DummyDispatch_VTable, 1, VT_UI1, FALSE };
4885 IUnknown* pu = (IUnknown*)&u;
4887 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4889 V_VT(&vSrc) = VT_UNKNOWN;
4890 V_UNKNOWN(&vSrc) = pu;
4892 /* =>IDispatch in place */
4893 hres = VariantChangeTypeEx(&vSrc, &vSrc, lcid, 0, VT_DISPATCH);
4894 ok(hres == S_OK && u.ref == 1 &&
4895 V_VT(&vSrc) == VT_DISPATCH && V_DISPATCH(&vSrc) == (IDispatch*)pu,
4896 "change unk(src=src): expected 0x%08lx,%d,%d,%p, got 0x%08lx,%ld,%d,%p\n",
4897 S_OK, 1, VT_DISPATCH, pu, hres, u.ref, V_VT(&vSrc), V_DISPATCH(&vSrc));
4899 /* =>IDispatch */
4900 u.ref = 1;
4901 V_VT(&vSrc) = VT_UNKNOWN;
4902 V_UNKNOWN(&vSrc) = (IUnknown*)pu;
4903 VariantInit(&vDst);
4904 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, VT_UNKNOWN);
4905 /* Note vSrc is not cleared, as final refcount is 2 */
4906 ok(hres == S_OK && u.ref == 2 &&
4907 V_VT(&vDst) == VT_UNKNOWN && V_UNKNOWN(&vDst) == (IUnknown*)pu,
4908 "change unk(src,dst): expected 0x%08lx,%d,%d,%p, got 0x%08lx,%ld,%d,%p\n",
4909 S_OK, 2, VT_UNKNOWN, pu, hres, u.ref, V_VT(&vDst), V_UNKNOWN(&vDst));
4911 /* Can't change unknown to anything else */
4912 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
4914 HRESULT hExpected = DISP_E_BADVARTYPE;
4916 V_VT(&vSrc) = VT_UNKNOWN;
4917 V_UNKNOWN(&vSrc) = (IUnknown*)pu;
4918 VariantInit(&vDst);
4920 if (vt == VT_UNKNOWN || vt == VT_DISPATCH || vt == VT_EMPTY || vt == VT_NULL)
4921 hExpected = S_OK;
4922 else
4924 if (vt == VT_I8 || vt == VT_UI8)
4926 if (HAVE_OLEAUT32_I8)
4927 hExpected = DISP_E_TYPEMISMATCH;
4929 else if (vt == VT_RECORD)
4931 if (HAVE_OLEAUT32_RECORD)
4932 hExpected = DISP_E_TYPEMISMATCH;
4934 else if (vt >= VT_I2 && vt <= VT_UINT && vt != (VARTYPE)15)
4935 hExpected = DISP_E_TYPEMISMATCH;
4937 if (IS_ANCIENT && IS_MODERN_VTYPE(vt))
4938 hExpected = DISP_E_BADVARTYPE;
4940 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, vt);
4941 ok(hres == hExpected,
4942 "change unk(badvar): vt %d expected 0x%08lx, got 0x%08lx\n",
4943 vt, hExpected, hres);
4947 /* IDispatch */
4948 static void test_IDispatchClear(void)
4950 HRESULT hres;
4951 VARIANTARG v;
4952 DummyDispatch d = { &DummyDispatch_VTable, 1, VT_UI1, FALSE };
4953 IDispatch* pd = (IDispatch*)&d;
4955 /* As per IUnknown */
4957 V_VT(&v) = VT_DISPATCH;
4958 V_DISPATCH(&v) = pd;
4959 hres = VariantClear(&v);
4960 ok(hres == S_OK && d.ref == 0 && V_VT(&v) == VT_EMPTY,
4961 "clear dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4962 S_OK, 0, VT_EMPTY, hres, d.ref, V_VT(&v));
4964 d.ref = 1;
4965 V_VT(&v) = VT_DISPATCH|VT_BYREF;
4966 V_DISPATCHREF(&v) = &pd;
4967 hres = VariantClear(&v);
4968 ok(hres == S_OK && d.ref == 1 && V_VT(&v) == VT_EMPTY,
4969 "clear dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4970 S_OK, 1, VT_EMPTY, hres, d.ref, V_VT(&v));
4973 static void test_IDispatchCopy(void)
4975 HRESULT hres;
4976 VARIANTARG vSrc, vDst;
4977 DummyDispatch d = { &DummyDispatch_VTable, 1, VT_UI1, FALSE };
4978 IDispatch* pd = (IDispatch*)&d;
4980 /* As per IUnknown */
4982 VariantInit(&vDst);
4983 V_VT(&vSrc) = VT_DISPATCH;
4984 V_DISPATCH(&vSrc) = pd;
4985 hres = VariantCopy(&vDst, &vSrc);
4986 ok(hres == S_OK && d.ref == 2 && V_VT(&vDst) == VT_DISPATCH,
4987 "copy dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4988 S_OK, 2, VT_EMPTY, hres, d.ref, V_VT(&vDst));
4990 VariantInit(&vDst);
4991 d.ref = 1;
4992 V_VT(&vSrc) = VT_DISPATCH|VT_BYREF;
4993 V_DISPATCHREF(&vSrc) = &pd;
4994 hres = VariantCopy(&vDst, &vSrc);
4995 ok(hres == S_OK && d.ref == 1 && V_VT(&vDst) == (VT_DISPATCH|VT_BYREF),
4996 "copy dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4997 S_OK, 1, VT_DISPATCH, hres, d.ref, V_VT(&vDst));
4999 VariantInit(&vDst);
5000 d.ref = 1;
5001 V_VT(&vSrc) = VT_DISPATCH|VT_BYREF;
5002 V_DISPATCHREF(&vSrc) = &pd;
5003 hres = VariantCopyInd(&vDst, &vSrc);
5004 ok(hres == S_OK && d.ref == 2 && V_VT(&vDst) == VT_DISPATCH,
5005 "copy dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
5006 S_OK, 2, VT_DISPATCH, hres, d.ref, V_VT(&vDst));
5008 d.ref = 1;
5009 V_VT(&vSrc) = VT_DISPATCH|VT_BYREF;
5010 V_DISPATCHREF(&vSrc) = &pd;
5011 hres = VariantCopyInd(&vSrc, &vSrc);
5012 ok(hres == S_OK && d.ref == 2 && V_VT(&vSrc) == VT_DISPATCH,
5013 "copy dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
5014 S_OK, 2, VT_DISPATCH, hres, d.ref, V_VT(&vSrc));
5017 static void test_IDispatchChangeTypeEx(void)
5019 HRESULT hres;
5020 VARIANTARG vSrc, vDst;
5021 LCID lcid;
5022 DummyDispatch d = { &DummyDispatch_VTable, 1, VT_UI1, FALSE };
5023 IDispatch* pd = (IDispatch*)&d;
5025 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5027 V_VT(&vSrc) = VT_DISPATCH;
5028 V_DISPATCH(&vSrc) = pd;
5030 /* =>IUnknown in place */
5031 hres = VariantChangeTypeEx(&vSrc, &vSrc, lcid, 0, VT_UNKNOWN);
5032 ok(hres == S_OK && d.ref == 1 &&
5033 V_VT(&vSrc) == VT_UNKNOWN && V_UNKNOWN(&vSrc) == (IUnknown*)pd,
5034 "change disp(src=src): expected 0x%08lx,%d,%d,%p, got 0x%08lx,%ld,%d,%p\n",
5035 S_OK, 1, VT_UNKNOWN, pd, hres, d.ref, V_VT(&vSrc), V_UNKNOWN(&vSrc));
5037 /* =>IUnknown */
5038 d.ref = 1;
5039 V_VT(&vSrc) = VT_DISPATCH;
5040 V_DISPATCH(&vSrc) = pd;
5041 VariantInit(&vDst);
5042 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, VT_UNKNOWN);
5043 /* Note vSrc is not cleared, as final refcount is 2 */
5044 ok(hres == S_OK && d.ref == 2 &&
5045 V_VT(&vDst) == VT_UNKNOWN && V_UNKNOWN(&vDst) == (IUnknown*)pd,
5046 "change disp(src,dst): expected 0x%08lx,%d,%d,%p, got 0x%08lx,%ld,%d,%p\n",
5047 S_OK, 2, VT_UNKNOWN, pd, hres, d.ref, V_VT(&vDst), V_UNKNOWN(&vDst));
5049 /* FIXME: Verify that VARIANT_NOVALUEPROP prevents conversion to integral
5050 * types. this requires that the xxxFromDisp tests work first.
5054 /* VT_ERROR */
5055 static void test_ErrorChangeTypeEx(void)
5057 HRESULT hres;
5058 VARIANTARG vSrc, vDst;
5059 VARTYPE vt;
5060 LCID lcid;
5062 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5064 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
5066 HRESULT hExpected = DISP_E_BADVARTYPE;
5068 V_VT(&vSrc) = VT_ERROR;
5069 V_ERROR(&vSrc) = 1;
5070 VariantInit(&vDst);
5071 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, vt);
5073 if (vt == VT_ERROR)
5074 hExpected = S_OK;
5075 else
5077 if (vt == VT_I8 || vt == VT_UI8)
5079 if (HAVE_OLEAUT32_I8)
5080 hExpected = DISP_E_TYPEMISMATCH;
5082 else if (vt == VT_RECORD)
5084 if (HAVE_OLEAUT32_RECORD)
5085 hExpected = DISP_E_TYPEMISMATCH;
5087 else if (vt <= VT_UINT && vt != (VARTYPE)15)
5088 hExpected = DISP_E_TYPEMISMATCH;
5090 if (IS_ANCIENT && IS_MODERN_VTYPE(vt))
5091 hExpected = DISP_E_BADVARTYPE;
5093 ok(hres == hExpected,
5094 "change err: vt %d expected 0x%08lx, got 0x%08lx\n", vt, hExpected, hres);
5098 /* VT_EMPTY */
5099 static void test_EmptyChangeTypeEx(void)
5101 HRESULT hres;
5102 VARIANTARG vSrc, vDst;
5103 VARTYPE vt;
5104 LCID lcid;
5106 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5108 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
5110 HRESULT hExpected = DISP_E_BADVARTYPE;
5112 VariantInit(&vSrc);
5113 memset(&vDst, 0, sizeof(vDst));
5114 V_VT(&vDst) = VT_EMPTY;
5116 if (vt == VT_I8 || vt == VT_UI8)
5118 if (HAVE_OLEAUT32_I8)
5119 hExpected = S_OK;
5121 else if (vt == VT_RECORD)
5123 if (HAVE_OLEAUT32_RECORD)
5124 hExpected = DISP_E_TYPEMISMATCH;
5126 else if (vt == VT_VARIANT || vt == VT_DISPATCH ||
5127 vt == VT_UNKNOWN || vt == VT_ERROR)
5129 hExpected = DISP_E_TYPEMISMATCH;
5131 else if (vt <= VT_UINT && vt != (VARTYPE)15)
5132 hExpected = S_OK;
5134 if (IS_ANCIENT && IS_MODERN_VTYPE(vt))
5135 hExpected = DISP_E_BADVARTYPE;
5137 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, vt);
5139 ok(hres == hExpected && (hres != S_OK || V_VT(&vDst) == vt),
5140 "change empty: vt %d expected 0x%08lx, got 0x%08lx, vt %d\n",
5141 vt, hExpected, hres, V_VT(&vDst));
5145 /* VT_NULL */
5146 static void test_NullChangeTypeEx(void)
5148 HRESULT hres;
5149 VARIANTARG vSrc, vDst;
5150 VARTYPE vt;
5151 LCID lcid;
5153 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5155 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
5157 HRESULT hExpected = DISP_E_BADVARTYPE;
5159 VariantInit(&vSrc);
5160 V_VT(&vSrc) = VT_NULL;
5161 memset(&vDst, 0, sizeof(vDst));
5162 V_VT(&vDst) = VT_EMPTY;
5164 if (vt == VT_I8 || vt == VT_UI8)
5166 if (HAVE_OLEAUT32_I8)
5167 hExpected = DISP_E_TYPEMISMATCH;
5169 else if (vt == VT_RECORD)
5171 if (HAVE_OLEAUT32_RECORD)
5172 hExpected = DISP_E_TYPEMISMATCH;
5174 else if (vt == VT_NULL)
5176 hExpected = S_OK;
5178 else if (vt == VT_VARIANT || vt == VT_DISPATCH ||
5179 vt == VT_UNKNOWN || vt == VT_ERROR ||
5180 (vt <= VT_UINT && vt != (VARTYPE)15))
5181 hExpected = DISP_E_TYPEMISMATCH;
5183 if (IS_ANCIENT && IS_MODERN_VTYPE(vt))
5184 hExpected = DISP_E_BADVARTYPE;
5186 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, vt);
5188 ok(hres == hExpected && (hres != S_OK || V_VT(&vDst) == vt),
5189 "change null: vt %d expected 0x%08lx, got 0x%08lx, vt %d\n",
5190 vt, hExpected, hres, V_VT(&vDst));
5195 /* VT_UINT */
5196 static void test_UintChangeTypeEx(void)
5198 HRESULT hres;
5199 VARIANTARG vSrc, vDst;
5200 LCID lcid;
5202 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5204 /* Converting a VT_UINT to a VT_INT does not check for overflow */
5205 V_VT(&vDst) = VT_EMPTY;
5206 V_VT(&vSrc) = VT_UINT;
5207 V_UI4(&vSrc) = -1;
5208 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, VT_I4);
5209 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == -1,
5210 "change uint: Expected %d,0x%08lx,%d got %d,0x%08lx,%ld\n",
5211 VT_I4, S_OK, -1, V_VT(&vDst), hres, V_I4(&vDst));
5214 #define NUM_CUST_ITEMS 16
5216 static void test_ClearCustData(void)
5218 WCHAR buff[sizeof(CUSTDATAITEM) * NUM_CUST_ITEMS / sizeof(WCHAR)];
5219 CUSTDATA ci;
5220 unsigned i;
5222 CHECKPTR(ClearCustData);
5224 memset(buff, 0, sizeof(buff));
5226 ci.cCustData = NUM_CUST_ITEMS;
5227 /* This is a bit tricky. We use SysAllocStringByteLen to allocate the
5228 * array, since native uses an internal IMalloc interface for allocating
5229 * its memory, while Wine uses HeapAlloc(). Doing this ensures we allocate
5230 * using the correct function whether with native or builtin.
5232 ci.prgCustData = (LPCUSTDATAITEM)SysAllocStringByteLen((LPCSTR)buff, sizeof(buff));
5233 for (i = 0; i < NUM_CUST_ITEMS; i++)
5234 VariantInit(&ci.prgCustData[i].varValue);
5235 pClearCustData(&ci);
5236 ok(!ci.cCustData && !ci.prgCustData, "ClearCustData didn't clear fields!\n");
5241 START_TEST(vartype)
5243 hOleaut32 = LoadLibraryA("oleaut32.dll");
5244 ok(hOleaut32 != 0, "Failed to load oleaut32.dll\n");
5245 if (!hOleaut32)
5246 return;
5248 trace("LCID's: System=0x%08lx, User=0x%08lx\n", GetSystemDefaultLCID(),
5249 GetUserDefaultLCID());
5251 test_VarI1FromI2();
5252 test_VarI1FromI4();
5253 test_VarI1FromI8();
5254 test_VarI1FromUI1();
5255 test_VarI1FromUI2();
5256 test_VarI1FromUI4();
5257 test_VarI1FromUI8();
5258 test_VarI1FromBool();
5259 test_VarI1FromR4();
5260 test_VarI1FromR8();
5261 test_VarI1FromDate();
5262 test_VarI1FromCy();
5263 test_VarI1FromDec();
5264 test_VarI1FromStr();
5265 test_VarUI1FromDisp();
5266 test_VarI1Copy();
5267 test_VarI1ChangeTypeEx();
5269 test_VarUI1FromI1();
5270 test_VarUI1FromI2();
5271 test_VarUI1FromI4();
5272 test_VarUI1FromI8();
5273 test_VarUI1FromUI2();
5274 test_VarUI1FromUI4();
5275 test_VarUI1FromUI8();
5276 test_VarUI1FromBool();
5277 test_VarUI1FromR4();
5278 test_VarUI1FromR8();
5279 test_VarUI1FromDate();
5280 test_VarUI1FromCy();
5281 test_VarUI1FromDec();
5282 test_VarUI1FromStr();
5283 test_VarUI1Copy();
5284 test_VarUI1ChangeTypeEx();
5286 test_VarI2FromI1();
5287 test_VarI2FromI4();
5288 test_VarI2FromI8();
5289 test_VarI2FromUI1();
5290 test_VarI2FromUI2();
5291 test_VarI2FromUI4();
5292 test_VarI2FromUI8();
5293 test_VarI2FromBool();
5294 test_VarI2FromR4();
5295 test_VarI2FromR8();
5296 test_VarI2FromDate();
5297 test_VarI2FromCy();
5298 test_VarI2FromDec();
5299 test_VarI2FromStr();
5300 test_VarI2Copy();
5301 test_VarI2ChangeTypeEx();
5303 test_VarUI2FromI1();
5304 test_VarUI2FromI2();
5305 test_VarUI2FromI4();
5306 test_VarUI2FromI8();
5307 test_VarUI2FromUI1();
5308 test_VarUI2FromUI4();
5309 test_VarUI2FromUI8();
5310 test_VarUI2FromBool();
5311 test_VarUI2FromR4();
5312 test_VarUI2FromR8();
5313 test_VarUI2FromDate();
5314 test_VarUI2FromCy();
5315 test_VarUI2FromDec();
5316 test_VarUI2FromStr();
5317 test_VarUI2Copy();
5318 test_VarUI2ChangeTypeEx();
5320 test_VarI4FromI1();
5321 test_VarI4FromI2();
5322 test_VarI4FromI8();
5323 test_VarI4FromUI1();
5324 test_VarI4FromUI2();
5325 test_VarI4FromUI4();
5326 test_VarI4FromUI8();
5327 test_VarI4FromBool();
5328 test_VarI4FromR4();
5329 test_VarI4FromR8();
5330 test_VarI4FromDate();
5331 test_VarI4FromCy();
5332 test_VarI4FromDec();
5333 test_VarI4FromStr();
5334 test_VarI4Copy();
5335 test_VarI4ChangeTypeEx();
5337 test_VarUI4FromI1();
5338 test_VarUI4FromI2();
5339 test_VarUI4FromUI2();
5340 test_VarUI4FromI8();
5341 test_VarUI4FromUI1();
5342 test_VarUI4FromI4();
5343 test_VarUI4FromUI8();
5344 test_VarUI4FromBool();
5345 test_VarUI4FromR4();
5346 test_VarUI4FromR8();
5347 test_VarUI4FromDate();
5348 test_VarUI4FromCy();
5349 test_VarUI4FromDec();
5350 test_VarUI4FromStr();
5351 test_VarUI4Copy();
5352 test_VarUI4ChangeTypeEx();
5354 test_VarI8FromI1();
5355 test_VarI8FromUI1();
5356 test_VarI8FromI2();
5357 test_VarI8FromUI2();
5358 test_VarI8FromUI4();
5359 test_VarI8FromR4();
5360 test_VarI8FromR8();
5361 test_VarI8FromBool();
5362 test_VarI8FromUI8();
5363 test_VarI8FromCy();
5364 test_VarI8FromDec();
5365 test_VarI8FromDate();
5366 test_VarI8FromStr();
5367 test_VarI8Copy();
5368 test_VarI8ChangeTypeEx();
5370 test_VarUI8FromI1();
5371 test_VarUI8FromUI1();
5372 test_VarUI8FromI2();
5373 test_VarUI8FromUI2();
5374 test_VarUI8FromUI4();
5375 test_VarUI8FromR4();
5376 test_VarUI8FromR8();
5377 test_VarUI8FromBool();
5378 test_VarUI8FromI8();
5379 test_VarUI8FromCy();
5380 test_VarUI8FromDec();
5381 test_VarUI8FromDate();
5382 test_VarUI8FromStr();
5383 test_VarUI8Copy();
5384 test_VarUI8ChangeTypeEx();
5386 test_VarR4FromI1();
5387 test_VarR4FromUI1();
5388 test_VarR4FromI2();
5389 test_VarR4FromUI2();
5390 test_VarR4FromI4();
5391 test_VarR4FromUI4();
5392 test_VarR4FromR8();
5393 test_VarR4FromBool();
5394 test_VarR4FromCy();
5395 test_VarR4FromI8();
5396 test_VarR4FromUI8();
5397 test_VarR4FromDec();
5398 test_VarR4FromDate();
5399 test_VarR4FromStr();
5400 test_VarR4Copy();
5401 test_VarR4ChangeTypeEx();
5403 test_VarR8FromI1();
5404 test_VarR8FromUI1();
5405 test_VarR8FromI2();
5406 test_VarR8FromUI2();
5407 test_VarR8FromI4();
5408 test_VarR8FromUI4();
5409 test_VarR8FromR4();
5410 test_VarR8FromBool();
5411 test_VarR8FromCy();
5412 test_VarR8FromI8();
5413 test_VarR8FromUI8();
5414 test_VarR8FromDec();
5415 test_VarR8FromDate();
5416 test_VarR8FromStr();
5417 test_VarR8Copy();
5418 test_VarR8ChangeTypeEx();
5419 test_VarR8Round();
5421 test_VarDateFromI1();
5422 test_VarDateFromUI1();
5423 test_VarDateFromI2();
5424 test_VarDateFromUI2();
5425 test_VarDateFromI4();
5426 test_VarDateFromUI4();
5427 test_VarDateFromR4();
5428 test_VarDateFromR8();
5429 test_VarDateFromBool();
5430 test_VarDateFromCy();
5431 test_VarDateFromI8();
5432 test_VarDateFromUI8();
5433 test_VarDateFromDec();
5434 test_VarDateFromStr();
5435 test_VarDateCopy();
5436 test_VarDateChangeTypeEx();
5438 test_VarCyFromI1();
5439 test_VarCyFromUI1();
5440 test_VarCyFromI2();
5441 test_VarCyFromUI2();
5442 test_VarCyFromI4();
5443 test_VarCyFromUI4();
5444 test_VarCyFromR4();
5445 test_VarCyFromR8();
5446 test_VarCyFromBool();
5447 test_VarCyFromI8();
5448 test_VarCyFromUI8();
5449 test_VarCyFromDec();
5450 test_VarCyFromDate();
5452 test_VarCyAdd();
5453 test_VarCyMul();
5454 test_VarCySub();
5455 test_VarCyAbs();
5456 test_VarCyNeg();
5457 test_VarCyMulI4();
5458 test_VarCyMulI8();
5459 test_VarCyCmp();
5460 test_VarCyCmpR8();
5461 test_VarCyRound();
5462 test_VarCyFix();
5463 test_VarCyInt();
5465 test_VarDecFromI1();
5466 test_VarDecFromI2();
5467 test_VarDecFromI4();
5468 test_VarDecFromI8();
5469 test_VarDecFromUI1();
5470 test_VarDecFromUI2();
5471 test_VarDecFromUI4();
5472 test_VarDecFromUI8();
5473 test_VarDecFromR4();
5474 test_VarDecFromR8();
5475 test_VarDecFromDate();
5476 test_VarDecFromStr();
5477 test_VarDecFromCy();
5478 test_VarDecFromDate();
5479 test_VarDecFromBool();
5481 test_VarDecAbs();
5482 test_VarDecNeg();
5483 test_VarDecAdd();
5484 test_VarDecSub();
5485 test_VarDecCmp();
5487 test_VarBoolFromI1();
5488 test_VarBoolFromUI1();
5489 test_VarBoolFromI2();
5490 test_VarBoolFromUI2();
5491 test_VarBoolFromI4();
5492 test_VarBoolFromUI4();
5493 test_VarBoolFromR4();
5494 test_VarBoolFromR8();
5495 test_VarBoolFromCy();
5496 test_VarBoolFromI8();
5497 test_VarBoolFromUI8();
5498 test_VarBoolFromDec();
5499 test_VarBoolFromDate();
5500 test_VarBoolFromStr();
5501 test_VarBoolCopy();
5502 test_VarBoolChangeTypeEx();
5504 test_VarBstrFromR4();
5505 test_VarBstrFromDate();
5506 test_SysStringLen();
5507 test_SysStringByteLen();
5508 test_SysAllocString();
5509 test_SysAllocStringLen();
5510 test_SysAllocStringByteLen();
5511 test_SysReAllocString();
5512 test_SysReAllocStringLen();
5513 test_BstrCopy();
5515 test_IUnknownClear();
5516 test_IUnknownCopy();
5517 test_IUnknownChangeTypeEx();
5519 test_IDispatchClear();
5520 test_IDispatchCopy();
5521 test_IDispatchChangeTypeEx();
5523 test_ErrorChangeTypeEx();
5524 test_EmptyChangeTypeEx();
5525 test_NullChangeTypeEx();
5526 test_UintChangeTypeEx();
5528 test_ClearCustData();