Added YUV routines needed for v4l driver, and in the future possibly
[wine/gsoc-2012-control.git] / dlls / oleaut32 / tests / vartype.c
blob32a6ce9d017458fbedf905e6b9e3a30306dd3ac1
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
21 #include "wine/test.h"
22 #include "wine/unicode.h"
23 #include "oleauto.h"
24 #include <math.h>
26 /* Some Visual C++ versions choke on __uint64 to float conversions.
27 * To fix this you need either VC++ 6.0 plus the processor pack
28 * or Visual C++ >=7.0.
30 #ifndef _MSC_VER
31 # define HAS_UINT64_TO_FLOAT
32 #else
33 # if _MSC_VER >= 1300
34 # define HAS_UINT64_TO_FLOAT
35 # else
36 # include <malloc.h>
37 # if defined(_mm_free)
38 /* _mm_free is defined if the Processor Pack has been installed */
39 # define HAS_UINT64_TO_FLOAT
40 # endif
42 # endif
43 #endif
45 static HMODULE hOleaut32;
47 #ifdef NONAMELESSUNION
48 # define U(x) (x).u
49 # define U1(x) (x).u1
50 #else
51 # define U(x) (x)
52 # define U1(x) (x)
53 #endif
54 #ifdef NONAMELESSSTRUCT
55 # define S(x) (x).s
56 # define S1(x) (x).s1
57 #else
58 # define S(x) (x)
59 # define S1(x) (x)
60 #endif
62 /* Get a conversion function ptr, return if function not available */
63 #define CHECKPTR(func) p##func = (void*)GetProcAddress(hOleaut32, #func); \
64 if (!p##func) { \
65 trace("function " # func " not available, not testing it\n"); return; }
67 /* Is a given function exported from oleaut32? */
68 #define HAVE_FUNC(func) ((void*)GetProcAddress(hOleaut32, #func) != NULL)
70 /* Have IRecordInfo data type? */
71 #define HAVE_OLEAUT32_RECORD HAVE_FUNC(SafeArraySetRecordInfo)
72 /* Have DECIMAL data type with new error checking? */
73 #define HAVE_OLEAUT32_DECIMAL HAVE_FUNC(VarDecAdd)
74 /* Have CY data type? */
75 #define HAVE_OLEAUT32_CY HAVE_FUNC(VarCyAdd)
76 /* Have I8/UI8 data type? */
77 #define HAVE_OLEAUT32_I8 HAVE_FUNC(VarI8FromI1)
78 /* Have proper locale conversions? */
79 #define HAVE_OLEAUT32_LOCALES (HAVE_FUNC(GetVarConversionLocaleSetting) && HAVE_OLEAUT32_I8)
80 /* Is this an ancient version with support for only I2/I4/R4/R8/DATE? */
81 #define IS_ANCIENT (!HAVE_FUNC(VarI1FromI2))
82 /* Is vt a type unavailable to ancient versions? */
83 #define IS_MODERN_VTYPE(vt) (vt==VT_VARIANT||vt==VT_DECIMAL|| \
84 vt==VT_I1||vt==VT_UI2||vt==VT_UI4||vt == VT_INT||vt == VT_UINT)
86 /* Macros for converting and testing results */
87 #define CONVVARS(typ) HRESULT hres; CONV_TYPE out; typ in
89 #define _EXPECTRES(res, x, fs) \
90 ok((hres == S_OK && out == (CONV_TYPE)(x)) || ((HRESULT)res != S_OK && hres == (HRESULT)res), \
91 "expected " #x ", got " fs "; hres=0x%08lx\n", out, hres)
92 #define EXPECT(x) EXPECTRES(S_OK, (x))
93 #define EXPECT_OVERFLOW EXPECTRES(DISP_E_OVERFLOW, DISP_E_OVERFLOW)
94 #define EXPECT_MISMATCH EXPECTRES(DISP_E_TYPEMISMATCH,DISP_E_TYPEMISMATCH)
95 #define EXPECT_BADVAR EXPECTRES(DISP_E_BADVARTYPE, DISP_E_BADVARTYPE)
96 #define EXPECT_INVALID EXPECTRES(E_INVALIDARG, E_INVALIDARG)
97 #define EXPECT_LT EXPECTRES(VARCMP_LT, VARCMP_LT)
98 #define EXPECT_GT EXPECTRES(VARCMP_GT, VARCMP_GT)
99 #define EXPECT_EQ EXPECTRES(VARCMP_EQ, VARCMP_EQ)
100 #define EXPECT_DBL(x) \
101 ok(hres == S_OK && fabs(out-(x))<1e-14, "expected " #x ", got %16.16g; hres=0x%08lx\n", out, hres)
103 #define CONVERT(func, val) in = val; hres = p##func(in, &out)
104 #define CONVERTRANGE(func,start,end) for (i = start; i < end; i+=1) { CONVERT(func, i); EXPECT(i); };
105 #define OVERFLOWRANGE(func,start,end) for (i = start; i < end; i+=1) { CONVERT(func, i); EXPECT_OVERFLOW; };
107 #define CY_MULTIPLIER 10000
109 #define DATE_MIN -657434
110 #define DATE_MAX 2958465
112 #define CONVERT_I8(func,hi,lo) in = hi; in = (in << 32) | lo; hres = p##func(in, &out)
114 #define CONVERT_CY(func,val) in.int64 = (LONGLONG)(val * CY_MULTIPLIER); hres = p##func(in, &out)
116 #define CONVERT_CY64(func,hi,lo) S(in).Hi = hi; S(in).Lo = lo; in.int64 *= CY_MULTIPLIER; hres = p##func(in, &out)
118 #define SETDEC(dec, scl, sgn, hi, lo) S(U(dec)).scale = (BYTE)scl; S(U(dec)).sign = (BYTE)sgn; \
119 dec.Hi32 = (ULONG)hi; U1(dec).Lo64 = (ULONG64)lo
121 #define SETDEC64(dec, scl, sgn, hi, mid, lo) S(U(dec)).scale = (BYTE)scl; S(U(dec)).sign = (BYTE)sgn; \
122 dec.Hi32 = (ULONG)hi; S1(U1(dec)).Mid32 = mid; S1(U1(dec)).Lo32 = lo;
124 #define CONVERT_DEC(func,scl,sgn,hi,lo) SETDEC(in,scl,sgn,hi,lo); hres = p##func(&in, &out)
126 #define CONVERT_DEC64(func,scl,sgn,hi,mid,lo) SETDEC64(in,scl,sgn,hi,mid,lo); hres = p##func(&in, &out)
128 #define CONVERT_BADDEC(func) \
129 if (HAVE_OLEAUT32_DECIMAL) \
131 CONVERT_DEC(func,29,0,0,0); EXPECT_INVALID; \
132 CONVERT_DEC(func,0,0x1,0,0); EXPECT_INVALID; \
133 CONVERT_DEC(func,0,0x40,0,0); EXPECT_INVALID; \
134 CONVERT_DEC(func,0,0x7f,0,0); EXPECT_INVALID; \
137 #define CONVERT_STR(func,str,flags) \
138 SetLastError(0); \
139 if (str) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)); \
140 hres = p##func(str ? buff : NULL,in,flags,&out)
142 #define COPYTEST(val, vt, srcval, dstval, srcref, dstref, fs) do { \
143 HRESULT hres; VARIANTARG vSrc, vDst; CONV_TYPE in = val; \
144 VariantInit(&vSrc); VariantInit(&vDst); \
145 V_VT(&vSrc) = vt; srcval = in; \
146 hres = VariantCopy(&vDst, &vSrc); \
147 ok(hres == S_OK && V_VT(&vDst) == vt && dstval == in, \
148 "copy hres 0x%lX, type %d, value (" fs ") " fs "\n", hres, V_VT(&vDst), val, dstval); \
149 V_VT(&vSrc) = vt|VT_BYREF; srcref = &in; \
150 hres = VariantCopy(&vDst, &vSrc); \
151 ok(hres == S_OK && V_VT(&vDst) == (vt|VT_BYREF) && dstref == &in, \
152 "ref hres 0x%lX, type %d, ref (%p) %p\n", hres, V_VT(&vDst), &in, dstref); \
153 hres = VariantCopyInd(&vDst, &vSrc); \
154 ok(hres == S_OK && V_VT(&vDst) == vt && dstval == in, \
155 "ind hres 0x%lX, type %d, value (" fs ") " fs "\n", hres, V_VT(&vDst), val, dstval); \
156 } while(0)
158 #define CHANGETYPEEX(typ) hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, typ)
160 #define TYPETEST(typ,res,fs) CHANGETYPEEX(typ); \
161 ok(hres == S_OK && V_VT(&vDst) == typ && (CONV_TYPE)res == in, \
162 "hres=0x%lX, type=%d (should be %d(" #typ ")), value=" fs " (should be 1)\n", \
163 hres, V_VT(&vDst), typ, (CONV_TYPE)res);
164 #define TYPETESTI8(typ,res) CHANGETYPEEX(typ); \
165 ok(hres == S_OK && V_VT(&vDst) == typ && (CONV_TYPE)res == in, \
166 "hres=0x%lX, type=%d (should be %d(" #typ ")), value=%d (should be 1)\n", \
167 hres, V_VT(&vDst), typ, (int)res);
168 #define BADVAR(typ) CHANGETYPEEX(typ); out = (CONV_TYPE)hres; EXPECT_BADVAR
169 #define MISMATCH(typ) CHANGETYPEEX(typ); out = (CONV_TYPE)hres; EXPECT_MISMATCH
171 #define INITIAL_TYPETEST(vt, val, fs) \
172 VariantInit(&vSrc); \
173 VariantInit(&vDst); \
174 V_VT(&vSrc) = vt; \
175 (val(&vSrc)) = in; \
176 if (!IS_ANCIENT) { \
177 TYPETEST(VT_I1, V_I1(&vDst), fs); \
178 TYPETEST(VT_UI2, V_UI2(&vDst), fs); \
179 TYPETEST(VT_UI4, V_UI4(&vDst), fs); \
180 TYPETEST(VT_INT, V_INT(&vDst), fs); \
181 TYPETEST(VT_UINT, V_UINT(&vDst), fs); \
182 } else { \
183 BADVAR(VT_I1); BADVAR(VT_UI2); BADVAR(VT_UI4); \
184 BADVAR(VT_INT); BADVAR(VT_UINT); \
186 TYPETEST(VT_UI1, V_UI1(&vDst), fs); \
187 TYPETEST(VT_I2, V_I2(&vDst), fs); \
188 TYPETEST(VT_I4, V_I4(&vDst), fs); \
189 TYPETEST(VT_R4, V_R4(&vDst), fs); \
190 TYPETEST(VT_R8, V_R8(&vDst), fs); \
191 TYPETEST(VT_DATE, V_DATE(&vDst), fs); \
192 if (HAVE_OLEAUT32_I8) \
194 TYPETEST(VT_I8, V_I8(&vDst), fs); \
195 TYPETEST(VT_UI8, V_UI8(&vDst), fs); \
198 #define INITIAL_TYPETESTI8(vt, val) \
199 VariantInit(&vSrc); \
200 VariantInit(&vDst); \
201 V_VT(&vSrc) = vt; \
202 (val(&vSrc)) = in; \
203 TYPETESTI8(VT_I1, V_I1(&vDst)); \
204 TYPETESTI8(VT_UI1, V_UI1(&vDst)); \
205 TYPETESTI8(VT_I2, V_I2(&vDst)); \
206 TYPETESTI8(VT_UI2, V_UI2(&vDst)); \
207 TYPETESTI8(VT_I4, V_I4(&vDst)); \
208 TYPETESTI8(VT_UI4, V_UI4(&vDst)); \
209 TYPETESTI8(VT_INT, V_INT(&vDst)); \
210 TYPETESTI8(VT_UINT, V_UINT(&vDst)); \
211 TYPETESTI8(VT_R4, V_R4(&vDst)); \
212 TYPETESTI8(VT_R8, V_R8(&vDst)); \
213 TYPETESTI8(VT_DATE, V_DATE(&vDst)); \
214 TYPETESTI8(VT_I8, V_I8(&vDst)); \
215 TYPETESTI8(VT_UI8, V_UI8(&vDst))
217 #define COMMON_TYPETEST \
218 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_BOOL); \
219 ok(hres == S_OK && V_VT(&vDst) == VT_BOOL && \
220 (V_BOOL(&vDst) == VARIANT_TRUE || (V_VT(&vSrc) == VT_BOOL && V_BOOL(&vDst) == 1)), \
221 "->VT_BOOL hres=0x%lX, type=%d (should be VT_BOOL), value %d (should be VARIANT_TRUE)\n", \
222 hres, V_VT(&vDst), V_BOOL(&vDst)); \
223 if (HAVE_OLEAUT32_CY) \
225 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_CY); \
226 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == CY_MULTIPLIER, \
227 "->VT_CY hres=0x%lX, type=%d (should be VT_CY), value (%08lx,%08lx) (should be CY_MULTIPLIER)\n", \
228 hres, V_VT(&vDst), S(V_CY(&vDst)).Hi, S(V_CY(&vDst)).Lo); \
230 if (V_VT(&vSrc) != VT_DATE) \
232 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_BSTR); \
233 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && \
234 V_BSTR(&vDst) && V_BSTR(&vDst)[0] == '1' && V_BSTR(&vDst)[1] == '\0', \
235 "->VT_BSTR hres=0x%lX, type=%d (should be VT_BSTR), *bstr='%c'\n", \
236 hres, V_VT(&vDst), V_BSTR(&vDst) ? *V_BSTR(&vDst) : '?'); \
238 if (HAVE_OLEAUT32_DECIMAL) \
240 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_DECIMAL); \
241 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && \
242 S(U(V_DECIMAL(&vDst))).sign == 0 && S(U(V_DECIMAL(&vDst))).scale == 0 && \
243 V_DECIMAL(&vDst).Hi32 == 0 && U1(V_DECIMAL(&vDst)).Lo64 == (ULONGLONG)in, \
244 "->VT_DECIMAL hres=0x%lX, type=%d (should be VT_DECIMAL), sign=%d, scale=%d, hi=%lu, lo=(%8lx %8lx),\n", \
245 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign, S(U(V_DECIMAL(&vDst))).scale, \
246 V_DECIMAL(&vDst).Hi32, S1(U1(V_DECIMAL(&vDst))).Mid32, S1(U1(V_DECIMAL(&vDst))).Lo32); \
248 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_EMPTY); \
249 ok(hres == S_OK && V_VT(&vDst) == VT_EMPTY, "->VT_EMPTY hres=0x%lX, type=%d (should be VT_EMPTY)\n", hres, V_VT(&vDst)); \
250 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_NULL); \
251 ok(hres == S_OK && V_VT(&vDst) == VT_NULL, "->VT_NULL hres=0x%lX, type=%d (should be VT_NULL)\n", hres, V_VT(&vDst)); \
252 MISMATCH(VT_DISPATCH); \
253 MISMATCH(VT_ERROR); \
254 MISMATCH(VT_UNKNOWN); \
255 if (!IS_ANCIENT) { MISMATCH(VT_VARIANT); } else { BADVAR(VT_VARIANT); } \
256 if (HAVE_OLEAUT32_RECORD) \
258 MISMATCH(VT_RECORD); \
260 BADVAR(VT_VOID); \
261 BADVAR(VT_HRESULT); \
262 BADVAR(VT_SAFEARRAY); \
263 BADVAR(VT_CARRAY); \
264 BADVAR(VT_USERDEFINED); \
265 BADVAR(VT_LPSTR); \
266 BADVAR(VT_LPWSTR); \
267 BADVAR(VT_PTR); \
268 BADVAR(VT_INT_PTR); \
269 BADVAR(VT_UINT_PTR); \
270 BADVAR(VT_FILETIME); \
271 BADVAR(VT_BLOB); \
272 BADVAR(VT_STREAM); \
273 BADVAR(VT_STORAGE); \
274 BADVAR(VT_STREAMED_OBJECT); \
275 BADVAR(VT_STORED_OBJECT); \
276 BADVAR(VT_BLOB_OBJECT); \
277 BADVAR(VT_CF); \
278 BADVAR(VT_CLSID); \
279 BADVAR(VT_BSTR_BLOB)
281 /* Early versions of oleaut32 are missing many functions */
282 static HRESULT (WINAPI *pVarI1FromUI1)(BYTE,signed char*);
283 static HRESULT (WINAPI *pVarI1FromI2)(SHORT,signed char*);
284 static HRESULT (WINAPI *pVarI1FromI4)(LONG,signed char*);
285 static HRESULT (WINAPI *pVarI1FromR4)(FLOAT,signed char*);
286 static HRESULT (WINAPI *pVarI1FromR8)(double,signed char*);
287 static HRESULT (WINAPI *pVarI1FromDate)(DATE,signed char*);
288 static HRESULT (WINAPI *pVarI1FromCy)(CY,signed char*);
289 static HRESULT (WINAPI *pVarI1FromStr)(OLECHAR*,LCID,ULONG,signed char*);
290 static HRESULT (WINAPI *pVarI1FromBool)(VARIANT_BOOL,signed char*);
291 static HRESULT (WINAPI *pVarI1FromUI2)(USHORT,signed char*);
292 static HRESULT (WINAPI *pVarI1FromUI4)(ULONG,signed char*);
293 static HRESULT (WINAPI *pVarI1FromDec)(DECIMAL*,signed char*);
294 static HRESULT (WINAPI *pVarI1FromI8)(LONG64,signed char*);
295 static HRESULT (WINAPI *pVarI1FromUI8)(ULONG64,signed char*);
296 static HRESULT (WINAPI *pVarUI1FromI2)(SHORT,BYTE*);
297 static HRESULT (WINAPI *pVarUI1FromI4)(LONG,BYTE*);
298 static HRESULT (WINAPI *pVarUI1FromR4)(FLOAT,BYTE*);
299 static HRESULT (WINAPI *pVarUI1FromR8)(double,BYTE*);
300 static HRESULT (WINAPI *pVarUI1FromCy)(CY,BYTE*);
301 static HRESULT (WINAPI *pVarUI1FromDate)(DATE,BYTE*);
302 static HRESULT (WINAPI *pVarUI1FromStr)(OLECHAR*,LCID,ULONG,BYTE*);
303 static HRESULT (WINAPI *pVarUI1FromBool)(VARIANT_BOOL,BYTE*);
304 static HRESULT (WINAPI *pVarUI1FromI1)(signed char,BYTE*);
305 static HRESULT (WINAPI *pVarUI1FromUI2)(USHORT,BYTE*);
306 static HRESULT (WINAPI *pVarUI1FromUI4)(ULONG,BYTE*);
307 static HRESULT (WINAPI *pVarUI1FromDec)(DECIMAL*,BYTE*);
308 static HRESULT (WINAPI *pVarUI1FromI8)(LONG64,BYTE*);
309 static HRESULT (WINAPI *pVarUI1FromUI8)(ULONG64,BYTE*);
310 static HRESULT (WINAPI *pVarUI1FromDisp)(IDispatch*,LCID,BYTE*);
312 static HRESULT (WINAPI *pVarI2FromUI1)(BYTE,SHORT*);
313 static HRESULT (WINAPI *pVarI2FromI4)(LONG,SHORT*);
314 static HRESULT (WINAPI *pVarI2FromR4)(FLOAT,SHORT*);
315 static HRESULT (WINAPI *pVarI2FromR8)(double,SHORT*);
316 static HRESULT (WINAPI *pVarI2FromCy)(CY,SHORT*);
317 static HRESULT (WINAPI *pVarI2FromDate)(DATE,SHORT*);
318 static HRESULT (WINAPI *pVarI2FromStr)(OLECHAR*,LCID,ULONG,SHORT*);
319 static HRESULT (WINAPI *pVarI2FromBool)(VARIANT_BOOL,SHORT*);
320 static HRESULT (WINAPI *pVarI2FromI1)(signed char,SHORT*);
321 static HRESULT (WINAPI *pVarI2FromUI2)(USHORT,SHORT*);
322 static HRESULT (WINAPI *pVarI2FromUI4)(ULONG,SHORT*);
323 static HRESULT (WINAPI *pVarI2FromDec)(DECIMAL*,SHORT*);
324 static HRESULT (WINAPI *pVarI2FromI8)(LONG64,SHORT*);
325 static HRESULT (WINAPI *pVarI2FromUI8)(ULONG64,SHORT*);
326 static HRESULT (WINAPI *pVarUI2FromUI1)(BYTE,USHORT*);
327 static HRESULT (WINAPI *pVarUI2FromI2)(SHORT,USHORT*);
328 static HRESULT (WINAPI *pVarUI2FromI4)(LONG,USHORT*);
329 static HRESULT (WINAPI *pVarUI2FromR4)(FLOAT,USHORT*);
330 static HRESULT (WINAPI *pVarUI2FromR8)(double,USHORT*);
331 static HRESULT (WINAPI *pVarUI2FromDate)(DATE,USHORT*);
332 static HRESULT (WINAPI *pVarUI2FromCy)(CY,USHORT*);
333 static HRESULT (WINAPI *pVarUI2FromStr)(OLECHAR*,LCID,ULONG,USHORT*);
334 static HRESULT (WINAPI *pVarUI2FromBool)(VARIANT_BOOL,USHORT*);
335 static HRESULT (WINAPI *pVarUI2FromI1)(signed char,USHORT*);
336 static HRESULT (WINAPI *pVarUI2FromUI4)(ULONG,USHORT*);
337 static HRESULT (WINAPI *pVarUI2FromDec)(DECIMAL*,USHORT*);
338 static HRESULT (WINAPI *pVarUI2FromI8)(LONG64,USHORT*);
339 static HRESULT (WINAPI *pVarUI2FromUI8)(ULONG64,USHORT*);
341 static HRESULT (WINAPI *pVarI4FromUI1)(BYTE,LONG*);
342 static HRESULT (WINAPI *pVarI4FromI2)(SHORT,LONG*);
343 static HRESULT (WINAPI *pVarI4FromR4)(FLOAT,LONG*);
344 static HRESULT (WINAPI *pVarI4FromR8)(DOUBLE,LONG*);
345 static HRESULT (WINAPI *pVarI4FromCy)(CY,LONG*);
346 static HRESULT (WINAPI *pVarI4FromDate)(DATE,LONG*);
347 static HRESULT (WINAPI *pVarI4FromStr)(OLECHAR*,LCID,ULONG,LONG*);
348 static HRESULT (WINAPI *pVarI4FromBool)(VARIANT_BOOL,LONG*);
349 static HRESULT (WINAPI *pVarI4FromI1)(signed char,LONG*);
350 static HRESULT (WINAPI *pVarI4FromUI2)(USHORT,LONG*);
351 static HRESULT (WINAPI *pVarI4FromUI4)(ULONG,LONG*);
352 static HRESULT (WINAPI *pVarI4FromDec)(DECIMAL*,LONG*);
353 static HRESULT (WINAPI *pVarI4FromI8)(LONG64,LONG*);
354 static HRESULT (WINAPI *pVarI4FromUI8)(ULONG64,LONG*);
355 static HRESULT (WINAPI *pVarUI4FromUI1)(BYTE,ULONG*);
356 static HRESULT (WINAPI *pVarUI4FromI2)(SHORT,ULONG*);
357 static HRESULT (WINAPI *pVarUI4FromI4)(LONG,ULONG*);
358 static HRESULT (WINAPI *pVarUI4FromR4)(FLOAT,ULONG*);
359 static HRESULT (WINAPI *pVarUI4FromR8)(DOUBLE,ULONG*);
360 static HRESULT (WINAPI *pVarUI4FromDate)(DATE,ULONG*);
361 static HRESULT (WINAPI *pVarUI4FromCy)(CY,ULONG*);
362 static HRESULT (WINAPI *pVarUI4FromStr)(OLECHAR*,LCID,ULONG,ULONG*);
363 static HRESULT (WINAPI *pVarUI4FromBool)(VARIANT_BOOL,ULONG*);
364 static HRESULT (WINAPI *pVarUI4FromI1)(signed char,ULONG*);
365 static HRESULT (WINAPI *pVarUI4FromUI2)(USHORT,ULONG*);
366 static HRESULT (WINAPI *pVarUI4FromDec)(DECIMAL*,ULONG*);
367 static HRESULT (WINAPI *pVarUI4FromI8)(LONG64,ULONG*);
368 static HRESULT (WINAPI *pVarUI4FromUI8)(ULONG64,ULONG*);
370 static HRESULT (WINAPI *pVarI8FromUI1)(BYTE,LONG64*);
371 static HRESULT (WINAPI *pVarI8FromI2)(SHORT,LONG64*);
372 static HRESULT (WINAPI *pVarI8FromR4)(FLOAT,LONG64*);
373 static HRESULT (WINAPI *pVarI8FromR8)(double,LONG64*);
374 static HRESULT (WINAPI *pVarI8FromCy)(CY,LONG64*);
375 static HRESULT (WINAPI *pVarI8FromDate)(DATE,LONG64*);
376 static HRESULT (WINAPI *pVarI8FromStr)(OLECHAR*,LCID,ULONG,LONG64*);
377 static HRESULT (WINAPI *pVarI8FromBool)(VARIANT_BOOL,LONG64*);
378 static HRESULT (WINAPI *pVarI8FromI1)(signed char,LONG64*);
379 static HRESULT (WINAPI *pVarI8FromUI2)(USHORT,LONG64*);
380 static HRESULT (WINAPI *pVarI8FromUI4)(ULONG,LONG64*);
381 static HRESULT (WINAPI *pVarI8FromDec)(DECIMAL*,LONG64*);
382 static HRESULT (WINAPI *pVarI8FromUI8)(ULONG64,LONG64*);
383 static HRESULT (WINAPI *pVarUI8FromI8)(LONG64,ULONG64*);
384 static HRESULT (WINAPI *pVarUI8FromUI1)(BYTE,ULONG64*);
385 static HRESULT (WINAPI *pVarUI8FromI2)(SHORT,ULONG64*);
386 static HRESULT (WINAPI *pVarUI8FromR4)(FLOAT,ULONG64*);
387 static HRESULT (WINAPI *pVarUI8FromR8)(double,ULONG64*);
388 static HRESULT (WINAPI *pVarUI8FromCy)(CY,ULONG64*);
389 static HRESULT (WINAPI *pVarUI8FromDate)(DATE,ULONG64*);
390 static HRESULT (WINAPI *pVarUI8FromStr)(OLECHAR*,LCID,ULONG,ULONG64*);
391 static HRESULT (WINAPI *pVarUI8FromBool)(VARIANT_BOOL,ULONG64*);
392 static HRESULT (WINAPI *pVarUI8FromI1)(signed char,ULONG64*);
393 static HRESULT (WINAPI *pVarUI8FromUI2)(USHORT,ULONG64*);
394 static HRESULT (WINAPI *pVarUI8FromUI4)(ULONG,ULONG64*);
395 static HRESULT (WINAPI *pVarUI8FromDec)(DECIMAL*,ULONG64*);
397 static HRESULT (WINAPI *pVarR4FromUI1)(BYTE,float*);
398 static HRESULT (WINAPI *pVarR4FromI2)(SHORT,float*);
399 static HRESULT (WINAPI *pVarR4FromI4)(LONG,float*);
400 static HRESULT (WINAPI *pVarR4FromR8)(double,float*);
401 static HRESULT (WINAPI *pVarR4FromCy)(CY,float*);
402 static HRESULT (WINAPI *pVarR4FromDate)(DATE,float*);
403 static HRESULT (WINAPI *pVarR4FromStr)(OLECHAR*,LCID,ULONG,float*);
404 static HRESULT (WINAPI *pVarR4FromBool)(VARIANT_BOOL,float*);
405 static HRESULT (WINAPI *pVarR4FromI1)(signed char,float*);
406 static HRESULT (WINAPI *pVarR4FromUI2)(USHORT,float*);
407 static HRESULT (WINAPI *pVarR4FromUI4)(ULONG,float*);
408 static HRESULT (WINAPI *pVarR4FromDec)(DECIMAL*,float*);
409 static HRESULT (WINAPI *pVarR4FromI8)(LONG64,float*);
410 static HRESULT (WINAPI *pVarR4FromUI8)(ULONG64,float*);
412 static HRESULT (WINAPI *pVarR8FromUI1)(BYTE,double*);
413 static HRESULT (WINAPI *pVarR8FromI2)(SHORT,double*);
414 static HRESULT (WINAPI *pVarR8FromI4)(LONG,double*);
415 static HRESULT (WINAPI *pVarR8FromR4)(FLOAT,double*);
416 static HRESULT (WINAPI *pVarR8FromCy)(CY,double*);
417 static HRESULT (WINAPI *pVarR8FromDate)(DATE,double*);
418 static HRESULT (WINAPI *pVarR8FromStr)(OLECHAR*,LCID,ULONG,double*);
419 static HRESULT (WINAPI *pVarR8FromBool)(VARIANT_BOOL,double*);
420 static HRESULT (WINAPI *pVarR8FromI1)(signed char,double*);
421 static HRESULT (WINAPI *pVarR8FromUI2)(USHORT,double*);
422 static HRESULT (WINAPI *pVarR8FromUI4)(ULONG,double*);
423 static HRESULT (WINAPI *pVarR8FromDec)(DECIMAL*,double*);
424 static HRESULT (WINAPI *pVarR8FromI8)(LONG64,double*);
425 static HRESULT (WINAPI *pVarR8FromUI8)(ULONG64,double*);
426 static HRESULT (WINAPI *pVarR8Round)(double,int,double*);
428 static HRESULT (WINAPI *pVarDateFromUI1)(BYTE,DATE*);
429 static HRESULT (WINAPI *pVarDateFromI2)(SHORT,DATE*);
430 static HRESULT (WINAPI *pVarDateFromI4)(LONG,DATE*);
431 static HRESULT (WINAPI *pVarDateFromR4)(FLOAT,DATE*);
432 static HRESULT (WINAPI *pVarDateFromCy)(CY,DATE*);
433 static HRESULT (WINAPI *pVarDateFromR8)(double,DATE*);
434 static HRESULT (WINAPI *pVarDateFromStr)(OLECHAR*,LCID,ULONG,DATE*);
435 static HRESULT (WINAPI *pVarDateFromBool)(VARIANT_BOOL,DATE*);
436 static HRESULT (WINAPI *pVarDateFromI1)(signed char,DATE*);
437 static HRESULT (WINAPI *pVarDateFromUI2)(USHORT,DATE*);
438 static HRESULT (WINAPI *pVarDateFromUI4)(ULONG,DATE*);
439 static HRESULT (WINAPI *pVarDateFromDec)(DECIMAL*,DATE*);
440 static HRESULT (WINAPI *pVarDateFromI8)(LONG64,DATE*);
441 static HRESULT (WINAPI *pVarDateFromUI8)(ULONG64,DATE*);
443 static HRESULT (WINAPI *pVarCyFromUI1)(BYTE,CY*);
444 static HRESULT (WINAPI *pVarCyFromI2)(SHORT,CY*);
445 static HRESULT (WINAPI *pVarCyFromI4)(LONG,CY*);
446 static HRESULT (WINAPI *pVarCyFromR4)(FLOAT,CY*);
447 static HRESULT (WINAPI *pVarCyFromR8)(double,CY*);
448 static HRESULT (WINAPI *pVarCyFromDate)(DATE,CY*);
449 static HRESULT (WINAPI *pVarCyFromBool)(VARIANT_BOOL,CY*);
450 static HRESULT (WINAPI *pVarCyFromI1)(signed char,CY*);
451 static HRESULT (WINAPI *pVarCyFromUI2)(USHORT,CY*);
452 static HRESULT (WINAPI *pVarCyFromUI4)(ULONG,CY*);
453 static HRESULT (WINAPI *pVarCyFromDec)(DECIMAL*,CY*);
454 static HRESULT (WINAPI *pVarCyFromI8)(LONG64,CY*);
455 static HRESULT (WINAPI *pVarCyFromUI8)(ULONG64,CY*);
456 static HRESULT (WINAPI *pVarCyAdd)(const CY,const CY,CY*);
457 static HRESULT (WINAPI *pVarCyMul)(const CY,const CY,CY*);
458 static HRESULT (WINAPI *pVarCyMulI4)(const CY,LONG,CY*);
459 static HRESULT (WINAPI *pVarCySub)(const CY,const CY,CY*);
460 static HRESULT (WINAPI *pVarCyAbs)(const CY,CY*);
461 static HRESULT (WINAPI *pVarCyFix)(const CY,CY*);
462 static HRESULT (WINAPI *pVarCyInt)(const CY,CY*);
463 static HRESULT (WINAPI *pVarCyNeg)(const CY,CY*);
464 static HRESULT (WINAPI *pVarCyRound)(const CY,int,CY*);
465 static HRESULT (WINAPI *pVarCyCmp)(const CY,const CY);
466 static HRESULT (WINAPI *pVarCyCmpR8)(const CY,double);
467 static HRESULT (WINAPI *pVarCyMulI8)(const CY,LONG64,CY*);
469 static HRESULT (WINAPI *pVarDecFromUI1)(BYTE,DECIMAL*);
470 static HRESULT (WINAPI *pVarDecFromI2)(SHORT,DECIMAL*);
471 static HRESULT (WINAPI *pVarDecFromI4)(LONG,DECIMAL*);
472 static HRESULT (WINAPI *pVarDecFromI8)(LONG64,DECIMAL*);
473 static HRESULT (WINAPI *pVarDecFromR4)(FLOAT,DECIMAL*);
474 static HRESULT (WINAPI *pVarDecFromR8)(DOUBLE,DECIMAL*);
475 static HRESULT (WINAPI *pVarDecFromDate)(DATE,DECIMAL*);
476 static HRESULT (WINAPI *pVarDecFromStr)(OLECHAR*,LCID,ULONG,DECIMAL*);
477 static HRESULT (WINAPI *pVarDecFromBool)(VARIANT_BOOL,DECIMAL*);
478 static HRESULT (WINAPI *pVarDecFromI1)(signed char,DECIMAL*);
479 static HRESULT (WINAPI *pVarDecFromUI2)(USHORT,DECIMAL*);
480 static HRESULT (WINAPI *pVarDecFromUI4)(ULONG,DECIMAL*);
481 static HRESULT (WINAPI *pVarDecFromUI8)(ULONG64,DECIMAL*);
482 static HRESULT (WINAPI *pVarDecFromCy)(CY,DECIMAL*);
483 static HRESULT (WINAPI *pVarDecAbs)(const DECIMAL*,DECIMAL*);
484 static HRESULT (WINAPI *pVarDecAdd)(const DECIMAL*,const DECIMAL*,DECIMAL*);
485 static HRESULT (WINAPI *pVarDecSub)(const DECIMAL*,const DECIMAL*,DECIMAL*);
486 static HRESULT (WINAPI *pVarDecCmp)(const DECIMAL*,const DECIMAL*);
487 static HRESULT (WINAPI *pVarDecNeg)(const DECIMAL*,DECIMAL*);
489 static HRESULT (WINAPI *pVarBoolFromUI1)(BYTE,VARIANT_BOOL*);
490 static HRESULT (WINAPI *pVarBoolFromI2)(SHORT,VARIANT_BOOL*);
491 static HRESULT (WINAPI *pVarBoolFromI4)(LONG,VARIANT_BOOL*);
492 static HRESULT (WINAPI *pVarBoolFromR4)(FLOAT,VARIANT_BOOL*);
493 static HRESULT (WINAPI *pVarBoolFromR8)(DOUBLE,VARIANT_BOOL*);
494 static HRESULT (WINAPI *pVarBoolFromDate)(DATE,VARIANT_BOOL*);
495 static HRESULT (WINAPI *pVarBoolFromCy)(CY,VARIANT_BOOL*);
496 static HRESULT (WINAPI *pVarBoolFromStr)(OLECHAR*,LCID,ULONG,VARIANT_BOOL*);
497 static HRESULT (WINAPI *pVarBoolFromI1)(signed char,VARIANT_BOOL*);
498 static HRESULT (WINAPI *pVarBoolFromUI2)(USHORT,VARIANT_BOOL*);
499 static HRESULT (WINAPI *pVarBoolFromUI4)(ULONG,VARIANT_BOOL*);
500 static HRESULT (WINAPI *pVarBoolFromDec)(DECIMAL*,VARIANT_BOOL*);
501 static HRESULT (WINAPI *pVarBoolFromI8)(LONG64,VARIANT_BOOL*);
502 static HRESULT (WINAPI *pVarBoolFromUI8)(ULONG64,VARIANT_BOOL*);
504 static HRESULT (WINAPI *pVarBstrFromR4)(FLOAT,LCID,ULONG,BSTR*);
505 static HRESULT (WINAPI *pVarBstrFromDate)(DATE,LCID,ULONG,BSTR*);
507 static INT (WINAPI *pSystemTimeToVariantTime)(LPSYSTEMTIME,double*);
508 static void (WINAPI *pClearCustData)(LPCUSTDATA);
510 /* Internal representation of a BSTR */
511 typedef struct tagINTERNAL_BSTR
513 DWORD dwLen;
514 OLECHAR szString[1];
515 } INTERNAL_BSTR, *LPINTERNAL_BSTR;
517 typedef struct
519 IDispatchVtbl *lpVtbl;
520 ULONG ref;
521 VARTYPE vt;
522 BOOL bFailInvoke;
523 } DummyDispatch;
525 static DummyDispatch dispatch;
527 static ULONG WINAPI DummyDispatch_AddRef(LPDISPATCH iface)
529 trace("AddRef(%p)\n", iface);
530 return InterlockedIncrement(&((DummyDispatch*)iface)->ref);
533 static ULONG WINAPI DummyDispatch_Release(LPDISPATCH iface)
535 trace("Release(%p)\n", iface);
536 return InterlockedDecrement(&((DummyDispatch*)iface)->ref);
539 static HRESULT WINAPI DummyDispatch_QueryInterface(LPDISPATCH iface,
540 REFIID riid,
541 void** ppvObject)
543 trace("QueryInterface(%p)\n", iface);
544 if (ppvObject)
546 *ppvObject = NULL;
547 if (IsEqualIID(riid, &IID_IDispatch))
549 trace("Asked for IID_IDispatch\n");
550 *ppvObject = iface;
552 else if (IsEqualIID(riid, &IID_IUnknown))
554 trace("Asked for IID_IUnknown\n");
555 *ppvObject = iface;
557 if (*ppvObject)
559 DummyDispatch_AddRef((IDispatch*)*ppvObject);
560 return S_OK;
563 return E_NOINTERFACE;
566 static HRESULT WINAPI DummyDispatch_Invoke(LPDISPATCH iface,
567 DISPID dispIdMember, REFIID riid,
568 LCID lcid, WORD wFlags,
569 DISPPARAMS *pDispParams,
570 VARIANT *pVarResult,
571 EXCEPINFO *pExcepInfo,
572 UINT *puArgErr)
574 trace("Invoke(%p)\n", iface);
575 ok(wFlags == DISPATCH_PROPERTYGET, "Flags wrong\n");
576 ok(pDispParams->cArgs == 0, "Property get has args\n");
578 if (dispatch.bFailInvoke)
579 return E_OUTOFMEMORY;
581 memset(pVarResult, 0, sizeof(*pVarResult));
582 V_VT(pVarResult) = dispatch.vt;
583 return S_OK;
586 static IDispatchVtbl DummyDispatch_VTable =
588 DummyDispatch_QueryInterface,
589 DummyDispatch_AddRef,
590 DummyDispatch_Release,
591 NULL,
592 NULL,
593 NULL,
594 DummyDispatch_Invoke
597 static DummyDispatch dispatch = { &DummyDispatch_VTable, 1, 0, 0 };
600 * VT_I1/VT_UI1
603 #undef CONV_TYPE
604 #define CONV_TYPE signed char
605 #undef EXPECTRES
606 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%d")
608 static void test_VarI1FromI2(void)
610 CONVVARS(SHORT);
611 int i;
613 CHECKPTR(VarI1FromI2);
614 OVERFLOWRANGE(VarI1FromI2, -32768, -128);
615 CONVERTRANGE(VarI1FromI2, -128, 128);
616 OVERFLOWRANGE(VarI1FromI2, 129, 32768);
619 static void test_VarI1FromI4(void)
621 CONVVARS(LONG);
622 int i;
624 CHECKPTR(VarI1FromI4);
625 CONVERT(VarI1FromI4, -129); EXPECT_OVERFLOW;
626 CONVERTRANGE(VarI1FromI4, -128, 128);
627 CONVERT(VarI1FromI4, 128); EXPECT_OVERFLOW;
630 static void test_VarI1FromI8(void)
632 CONVVARS(LONG64);
633 int i;
635 CHECKPTR(VarI1FromI8);
636 CONVERT(VarI1FromI8, -129); EXPECT_OVERFLOW;
637 CONVERTRANGE(VarI1FromI8, -127, 128);
638 CONVERT(VarI1FromI8, 128); EXPECT_OVERFLOW;
641 static void test_VarI1FromUI1(void)
643 CONVVARS(BYTE);
644 int i;
646 CHECKPTR(VarI1FromUI1);
647 CONVERTRANGE(VarI1FromUI1, 0, 127);
648 OVERFLOWRANGE(VarI1FromUI1, 128, 255);
651 static void test_VarI1FromUI2(void)
653 CONVVARS(USHORT);
654 int i;
656 CHECKPTR(VarI1FromUI2);
657 CONVERTRANGE(VarI1FromUI2, 0, 127);
658 OVERFLOWRANGE(VarI1FromUI2, 128, 32768);
661 static void test_VarI1FromUI4(void)
663 CONVVARS(ULONG);
664 int i;
666 CHECKPTR(VarI1FromUI4);
667 CONVERTRANGE(VarI1FromUI4, 0, 127);
668 CONVERT(VarI1FromUI4, 128); EXPECT_OVERFLOW;
671 static void test_VarI1FromUI8(void)
673 CONVVARS(ULONG64);
674 int i;
676 CHECKPTR(VarI1FromUI8);
677 CONVERTRANGE(VarI1FromUI8, 0, 127);
678 CONVERT(VarI1FromUI8, 128); EXPECT_OVERFLOW;
681 static void test_VarI1FromBool(void)
683 CONVVARS(VARIANT_BOOL);
684 int i;
686 CHECKPTR(VarI1FromBool);
687 /* Note that conversions from bool wrap around! */
688 CONVERT(VarI1FromBool, -129); EXPECT(127);
689 CONVERTRANGE(VarI1FromBool, -128, 128);
690 CONVERT(VarI1FromBool, 128); EXPECT(-128);
693 static void test_VarI1FromR4(void)
695 CONVVARS(FLOAT);
697 CHECKPTR(VarI1FromR4);
698 CONVERT(VarI1FromR4, -129.0f); EXPECT_OVERFLOW;
699 CONVERT(VarI1FromR4, -128.0f); EXPECT(-128);
700 CONVERT(VarI1FromR4, -1.0f); EXPECT(-1);
701 CONVERT(VarI1FromR4, 0.0f); EXPECT(0);
702 CONVERT(VarI1FromR4, 1.0f); EXPECT(1);
703 CONVERT(VarI1FromR4, 127.0f); EXPECT(127);
704 CONVERT(VarI1FromR4, 128.0f); EXPECT_OVERFLOW;
706 CONVERT(VarI1FromR4, -1.5f); EXPECT(-2);
707 CONVERT(VarI1FromR4, -0.6f); EXPECT(-1);
708 CONVERT(VarI1FromR4, -0.5f); EXPECT(0);
709 CONVERT(VarI1FromR4, -0.4f); EXPECT(0);
710 CONVERT(VarI1FromR4, 0.4f); EXPECT(0);
711 CONVERT(VarI1FromR4, 0.5f); EXPECT(0);
712 CONVERT(VarI1FromR4, 0.6f); EXPECT(1);
713 CONVERT(VarI1FromR4, 1.5f); EXPECT(2);
716 static void test_VarI1FromR8(void)
718 CONVVARS(DOUBLE);
720 CHECKPTR(VarI1FromR8);
721 CONVERT(VarI1FromR8, -129.0); EXPECT_OVERFLOW;
722 CONVERT(VarI1FromR8, -128.0); EXPECT(-128);
723 CONVERT(VarI1FromR8, -1.0); EXPECT(-1);
724 CONVERT(VarI1FromR8, 0.0); EXPECT(0);
725 CONVERT(VarI1FromR8, 1.0); EXPECT(1);
726 CONVERT(VarI1FromR8, 127.0); EXPECT(127);
727 CONVERT(VarI1FromR8, 128.0); EXPECT_OVERFLOW;
729 CONVERT(VarI1FromR8, -1.5); EXPECT(-2);
730 CONVERT(VarI1FromR8, -0.6); EXPECT(-1);
731 CONVERT(VarI1FromR8, -0.5); EXPECT(0);
732 CONVERT(VarI1FromR8, -0.4); EXPECT(0);
733 CONVERT(VarI1FromR8, 0.4); EXPECT(0);
734 CONVERT(VarI1FromR8, 0.5); EXPECT(0);
735 CONVERT(VarI1FromR8, 0.6); EXPECT(1);
736 CONVERT(VarI1FromR8, 1.5); EXPECT(2);
739 static void test_VarI1FromDate(void)
741 CONVVARS(DATE);
743 CHECKPTR(VarI1FromDate);
744 CONVERT(VarI1FromDate, -129.0); EXPECT_OVERFLOW;
745 CONVERT(VarI1FromDate, -128.0); EXPECT(-128);
746 CONVERT(VarI1FromDate, -1.0); EXPECT(-1);
747 CONVERT(VarI1FromDate, 0.0); EXPECT(0);
748 CONVERT(VarI1FromDate, 1.0); EXPECT(1);
749 CONVERT(VarI1FromDate, 127.0); EXPECT(127);
750 CONVERT(VarI1FromDate, 128.0); EXPECT_OVERFLOW;
752 CONVERT(VarI1FromDate, -1.5); EXPECT(-2);
753 CONVERT(VarI1FromDate, -0.6); EXPECT(-1);
754 CONVERT(VarI1FromDate, -0.5); EXPECT(0);
755 CONVERT(VarI1FromDate, -0.4); EXPECT(0);
756 CONVERT(VarI1FromDate, 0.4); EXPECT(0);
757 CONVERT(VarI1FromDate, 0.5); EXPECT(0);
758 CONVERT(VarI1FromDate, 0.6); EXPECT(1);
759 CONVERT(VarI1FromDate, 1.5); EXPECT(2);
762 static void test_VarI1FromCy(void)
764 CONVVARS(CY);
766 CHECKPTR(VarI1FromCy);
767 CONVERT_CY(VarI1FromCy,-129); EXPECT_OVERFLOW;
768 CONVERT_CY(VarI1FromCy,-128); EXPECT(128);
769 CONVERT_CY(VarI1FromCy,-1); EXPECT(-1);
770 CONVERT_CY(VarI1FromCy,0); EXPECT(0);
771 CONVERT_CY(VarI1FromCy,1); EXPECT(1);
772 CONVERT_CY(VarI1FromCy,127); EXPECT(127);
773 CONVERT_CY(VarI1FromCy,128); EXPECT_OVERFLOW;
775 CONVERT_CY(VarI1FromCy,-1.5); EXPECT(-2);
776 CONVERT_CY(VarI1FromCy,-0.6); EXPECT(-1);
777 CONVERT_CY(VarI1FromCy,-0.5); EXPECT(0);
778 CONVERT_CY(VarI1FromCy,-0.4); EXPECT(0);
779 CONVERT_CY(VarI1FromCy,0.4); EXPECT(0);
780 CONVERT_CY(VarI1FromCy,0.5); EXPECT(0);
781 CONVERT_CY(VarI1FromCy,0.6); EXPECT(1);
782 CONVERT_CY(VarI1FromCy,1.5); EXPECT(2);
785 static void test_VarI1FromDec(void)
787 CONVVARS(DECIMAL);
789 CHECKPTR(VarI1FromDec);
791 CONVERT_BADDEC(VarI1FromDec);
793 CONVERT_DEC(VarI1FromDec,0,0x80,0,129); EXPECT_OVERFLOW;
794 CONVERT_DEC(VarI1FromDec,0,0x80,0,128); EXPECT(-128);
795 CONVERT_DEC(VarI1FromDec,0,0x80,0,1); EXPECT(-1);
796 CONVERT_DEC(VarI1FromDec,0,0,0,0); EXPECT(0);
797 CONVERT_DEC(VarI1FromDec,0,0,0,1); EXPECT(1);
798 CONVERT_DEC(VarI1FromDec,0,0,0,127); EXPECT(127);
799 CONVERT_DEC(VarI1FromDec,0,0,0,128); EXPECT_OVERFLOW;
801 CONVERT_DEC(VarI1FromDec,2,0x80,0,12800); EXPECT(-128);
802 CONVERT_DEC(VarI1FromDec,2,0,0,12700); EXPECT(127);
805 static void test_VarI1FromStr(void)
807 CONVVARS(LCID);
808 OLECHAR buff[128];
810 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
812 CHECKPTR(VarI1FromStr);
814 CONVERT_STR(VarI1FromStr,NULL, 0); EXPECT_MISMATCH;
815 CONVERT_STR(VarI1FromStr,"0", 0); EXPECT(0);
816 CONVERT_STR(VarI1FromStr,"-129", 0); EXPECT_OVERFLOW;
817 CONVERT_STR(VarI1FromStr,"-128", 0); EXPECT(-128);
818 CONVERT_STR(VarI1FromStr,"127", 0); EXPECT(127);
819 CONVERT_STR(VarI1FromStr,"128", 0); EXPECT_OVERFLOW;
821 CONVERT_STR(VarI1FromStr,"-1.5", 0); EXPECT(-2);
822 CONVERT_STR(VarI1FromStr,"-0.6", 0); EXPECT(-1);
823 CONVERT_STR(VarI1FromStr,"-0.5", 0); EXPECT(0);
824 CONVERT_STR(VarI1FromStr,"-0.4", 0); EXPECT(0);
825 CONVERT_STR(VarI1FromStr,"0.4", 0); EXPECT(0);
826 CONVERT_STR(VarI1FromStr,"0.5", 0); EXPECT(0);
827 CONVERT_STR(VarI1FromStr,"0.6", 0); EXPECT(1);
828 CONVERT_STR(VarI1FromStr,"1.5", 0); EXPECT(2);
831 static void test_VarI1Copy(void)
833 if (!IS_ANCIENT)
835 COPYTEST(1, VT_I1, V_I1(&vSrc), V_I1(&vDst), V_I1REF(&vSrc), V_I1REF(&vDst), "%d");
839 static void test_VarI1ChangeTypeEx(void)
841 CONVVARS(CONV_TYPE);
842 VARIANTARG vSrc, vDst;
844 in = 1;
846 if (!IS_ANCIENT)
848 INITIAL_TYPETEST(VT_I1, V_I1, "%d");
849 COMMON_TYPETEST;
853 #undef CONV_TYPE
854 #define CONV_TYPE BYTE
856 static void test_VarUI1FromI1(void)
858 CONVVARS(signed char);
859 int i;
861 CHECKPTR(VarUI1FromI1);
862 OVERFLOWRANGE(VarUI1FromI1, -128, 0);
863 CONVERTRANGE(VarUI1FromI1, 0, 128);
866 static void test_VarUI1FromI2(void)
868 CONVVARS(SHORT);
869 int i;
871 CHECKPTR(VarUI1FromI2);
872 OVERFLOWRANGE(VarUI1FromI2, -32768, 0);
873 CONVERTRANGE(VarUI1FromI2, 0, 256);
874 OVERFLOWRANGE(VarUI1FromI2, 256, 32768);
877 static void test_VarUI1FromI4(void)
879 CONVVARS(LONG);
880 int i;
882 CHECKPTR(VarUI1FromI4);
883 CONVERT(VarUI1FromI4, -1); EXPECT_OVERFLOW;
884 CONVERTRANGE(VarUI1FromI4, 0, 256);
885 CONVERT(VarUI1FromI4, 256); EXPECT_OVERFLOW;
888 static void test_VarUI1FromI8(void)
890 CONVVARS(LONG64);
891 int i;
893 CHECKPTR(VarUI1FromI8);
894 CONVERT(VarUI1FromI8, -1); EXPECT_OVERFLOW;
895 CONVERTRANGE(VarUI1FromI8, 0, 256);
896 CONVERT(VarUI1FromI8, 256); EXPECT_OVERFLOW;
899 static void test_VarUI1FromUI2(void)
901 CONVVARS(USHORT);
902 int i;
904 CHECKPTR(VarUI1FromUI2);
905 CONVERTRANGE(VarUI1FromUI2, 0, 256);
906 OVERFLOWRANGE(VarUI1FromUI2, 256, 65536);
909 static void test_VarUI1FromUI4(void)
911 CONVVARS(ULONG);
912 int i;
914 CHECKPTR(VarUI1FromUI4);
915 CONVERTRANGE(VarUI1FromUI4, 0, 256);
916 CONVERT(VarUI1FromUI4, 256); EXPECT_OVERFLOW;
919 static void test_VarUI1FromUI8(void)
921 CONVVARS(ULONG64);
922 int i;
924 CHECKPTR(VarUI1FromUI8);
925 CONVERTRANGE(VarUI1FromUI8, 0, 256);
926 CONVERT(VarUI1FromUI8, 256); EXPECT_OVERFLOW;
929 static void test_VarUI1FromBool(void)
931 CONVVARS(VARIANT_BOOL);
932 int i;
934 CHECKPTR(VarUI1FromBool);
935 /* Note that conversions from bool overflow! */
936 CONVERT(VarUI1FromBool, -1); EXPECT(255);
937 CONVERTRANGE(VarUI1FromBool, 0, 256);
938 CONVERT(VarUI1FromBool, 256); EXPECT(0);
941 static void test_VarUI1FromR4(void)
943 CONVVARS(FLOAT);
945 CHECKPTR(VarUI1FromR4);
946 CONVERT(VarUI1FromR4, -1.0f); EXPECT_OVERFLOW;
947 CONVERT(VarUI1FromR4, 0.0f); EXPECT(0);
948 CONVERT(VarUI1FromR4, 1.0f); EXPECT(1);
949 CONVERT(VarUI1FromR4, 255.0f); EXPECT(255);
950 CONVERT(VarUI1FromR4, 256.0f); EXPECT_OVERFLOW;
952 /* Rounding */
953 CONVERT(VarUI1FromR4, -1.5f); EXPECT_OVERFLOW;
954 CONVERT(VarUI1FromR4, -0.6f); EXPECT_OVERFLOW;
955 CONVERT(VarUI1FromR4, -0.5f); EXPECT(0);
956 CONVERT(VarUI1FromR4, -0.4f); EXPECT(0);
957 CONVERT(VarUI1FromR4, 0.4f); EXPECT(0);
958 CONVERT(VarUI1FromR4, 0.5f); EXPECT(0);
959 CONVERT(VarUI1FromR4, 0.6f); EXPECT(1);
960 CONVERT(VarUI1FromR4, 1.5f); EXPECT(2);
963 static void test_VarUI1FromR8(void)
965 CONVVARS(DOUBLE);
967 CHECKPTR(VarUI1FromR8);
968 CONVERT(VarUI1FromR8, -1.0); EXPECT_OVERFLOW;
969 CONVERT(VarUI1FromR8, 0.0); EXPECT(0);
970 CONVERT(VarUI1FromR8, 1.0); EXPECT(1);
971 CONVERT(VarUI1FromR8, 255.0); EXPECT(255);
972 CONVERT(VarUI1FromR8, 256.0); EXPECT_OVERFLOW;
974 /* Rounding */
975 CONVERT(VarUI1FromR8, -1.5); EXPECT_OVERFLOW;
976 CONVERT(VarUI1FromR8, -0.6); EXPECT_OVERFLOW;
977 CONVERT(VarUI1FromR8, -0.5); EXPECT(0);
978 CONVERT(VarUI1FromR8, -0.4); EXPECT(0);
979 CONVERT(VarUI1FromR8, 0.4); EXPECT(0);
980 CONVERT(VarUI1FromR8, 0.5); EXPECT(0);
981 CONVERT(VarUI1FromR8, 0.6); EXPECT(1);
982 CONVERT(VarUI1FromR8, 1.5); EXPECT(2);
985 static void test_VarUI1FromDate(void)
987 CONVVARS(DATE);
989 CHECKPTR(VarUI1FromDate);
990 CONVERT(VarUI1FromDate, -1.0); EXPECT_OVERFLOW;
991 CONVERT(VarUI1FromDate, 0.0); EXPECT(0);
992 CONVERT(VarUI1FromDate, 1.0); EXPECT(1);
993 CONVERT(VarUI1FromDate, 255.0); EXPECT(255);
994 CONVERT(VarUI1FromDate, 256.0); EXPECT_OVERFLOW;
996 /* Rounding */
997 CONVERT(VarUI1FromDate, -1.5); EXPECT_OVERFLOW;
998 CONVERT(VarUI1FromDate, -0.6); EXPECT_OVERFLOW;
999 CONVERT(VarUI1FromDate, -0.5); EXPECT(0);
1000 CONVERT(VarUI1FromDate, -0.4); EXPECT(0);
1001 CONVERT(VarUI1FromDate, 0.4); EXPECT(0);
1002 CONVERT(VarUI1FromDate, 0.5); EXPECT(0);
1003 CONVERT(VarUI1FromDate, 0.6); EXPECT(1);
1004 CONVERT(VarUI1FromDate, 1.5); EXPECT(2);
1007 static void test_VarUI1FromCy(void)
1009 CONVVARS(CY);
1011 CHECKPTR(VarUI1FromCy);
1012 CONVERT_CY(VarUI1FromCy,-1); EXPECT_OVERFLOW;
1013 CONVERT_CY(VarUI1FromCy,0); EXPECT(0);
1014 CONVERT_CY(VarUI1FromCy,1); EXPECT(1);
1015 CONVERT_CY(VarUI1FromCy,255); EXPECT(255);
1016 CONVERT_CY(VarUI1FromCy,256); EXPECT_OVERFLOW;
1018 /* Rounding */
1019 CONVERT_CY(VarUI1FromCy,-1.5); EXPECT_OVERFLOW;
1020 CONVERT_CY(VarUI1FromCy,-0.6); EXPECT_OVERFLOW;
1021 CONVERT_CY(VarUI1FromCy,-0.5); EXPECT(0);
1022 CONVERT_CY(VarUI1FromCy,-0.4); EXPECT(0);
1023 CONVERT_CY(VarUI1FromCy,0.4); EXPECT(0);
1024 CONVERT_CY(VarUI1FromCy,0.5); EXPECT(0);
1025 CONVERT_CY(VarUI1FromCy,0.6); EXPECT(1);
1026 CONVERT_CY(VarUI1FromCy,1.5); EXPECT(2);
1029 static void test_VarUI1FromDec(void)
1031 CONVVARS(DECIMAL);
1033 CHECKPTR(VarUI1FromDec);
1035 CONVERT_BADDEC(VarUI1FromDec);
1037 CONVERT_DEC(VarUI1FromDec,0,0x80,0,1); EXPECT_OVERFLOW;
1038 CONVERT_DEC(VarUI1FromDec,0,0,0,0); EXPECT(0);
1039 CONVERT_DEC(VarUI1FromDec,0,0,0,1); EXPECT(1);
1040 CONVERT_DEC(VarUI1FromDec,0,0,0,255); EXPECT(255);
1041 CONVERT_DEC(VarUI1FromDec,0,0,0,256); EXPECT_OVERFLOW;
1043 CONVERT_DEC(VarUI1FromDec,2,0x80,0,100); EXPECT_OVERFLOW;
1044 CONVERT_DEC(VarUI1FromDec,2,0,0,25500); EXPECT(255);
1047 static void test_VarUI1FromStr(void)
1049 CONVVARS(LCID);
1050 OLECHAR buff[128];
1052 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1054 CHECKPTR(VarUI1FromStr);
1056 CONVERT_STR(VarUI1FromStr,NULL, 0); EXPECT_MISMATCH;
1057 CONVERT_STR(VarUI1FromStr,"0", 0); EXPECT(0);
1058 CONVERT_STR(VarUI1FromStr,"-1", 0); EXPECT_OVERFLOW;
1059 CONVERT_STR(VarUI1FromStr,"255", 0); EXPECT(255);
1060 CONVERT_STR(VarUI1FromStr,"256", 0); EXPECT_OVERFLOW;
1062 /* Rounding */
1063 CONVERT_STR(VarUI1FromStr,"-1.5", 0); EXPECT_OVERFLOW;
1064 CONVERT_STR(VarUI1FromStr,"-0.6", 0); EXPECT_OVERFLOW;
1065 CONVERT_STR(VarUI1FromStr,"-0.5", 0); EXPECT(0);
1066 CONVERT_STR(VarUI1FromStr,"-0.4", 0); EXPECT(0);
1067 CONVERT_STR(VarUI1FromStr,"0.4", 0); EXPECT(0);
1068 CONVERT_STR(VarUI1FromStr,"0.5", 0); EXPECT(0);
1069 CONVERT_STR(VarUI1FromStr,"0.6", 0); EXPECT(1);
1070 CONVERT_STR(VarUI1FromStr,"1.5", 0); EXPECT(2);
1073 static void test_VarUI1FromDisp(void)
1075 CONVVARS(LCID);
1076 VARIANTARG vSrc, vDst;
1078 CHECKPTR(VarUI1FromDisp);
1080 /* FIXME
1081 * Conversions from IDispatch should get the default 'value' property
1082 * from the IDispatch pointer and return it. The following tests this.
1083 * However, I can't get these tests to return a valid value under native
1084 * oleaut32, regardless of the value returned in response to the Invoke()
1085 * call (early versions of oleaut32 call AddRef/Release, but not Invoke.
1086 * I'm obviously missing something, as these conversions work fine
1087 * when called through VBA on an object to get its default value property.
1089 * Should this test be corrected so that it works under native it should be
1090 * generalised and the remaining types checked as well.
1092 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1094 VariantInit(&vSrc);
1095 VariantInit(&vDst);
1097 V_VT(&vSrc) = VT_DISPATCH;
1098 V_DISPATCH(&vSrc) = (IDispatch*)&dispatch;
1099 dispatch.vt = VT_UI1;
1100 dispatch.bFailInvoke = FALSE;
1102 hres = VarUI1FromDisp((IDispatch*)&dispatch, in, &out);
1103 trace("0x%08lx\n", hres);
1105 hres = VariantChangeTypeEx(&vDst, &vSrc, in, 0, VT_UI1);
1106 trace("0x%08lx\n", hres);
1108 dispatch.bFailInvoke = TRUE;
1110 hres = VarUI1FromDisp((IDispatch*)&dispatch, in, &out);
1111 trace("0x%08lx\n", hres);
1113 hres = VariantChangeTypeEx(&vDst, &vSrc, in, 0, VT_UI1);
1114 trace("0x%08lx\n", hres);
1117 static void test_VarUI1Copy(void)
1119 COPYTEST(1, VT_UI1, V_UI1(&vSrc), V_UI1(&vDst), V_UI1REF(&vSrc), V_UI1REF(&vDst), "%d");
1122 static void test_VarUI1ChangeTypeEx(void)
1124 CONVVARS(CONV_TYPE);
1125 VARIANTARG vSrc, vDst;
1127 in = 1;
1129 INITIAL_TYPETEST(VT_UI1, V_UI1, "%d");
1130 COMMON_TYPETEST;
1134 * VT_I2/VT_UI2
1137 #undef CONV_TYPE
1138 #define CONV_TYPE SHORT
1139 #undef EXPECTRES
1140 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%d")
1142 static void test_VarI2FromI1(void)
1144 CONVVARS(signed char);
1145 int i;
1147 CHECKPTR(VarI2FromI1);
1148 CONVERTRANGE(VarI2FromI1, -128, 128);
1151 static void test_VarI2FromI4(void)
1153 CONVVARS(LONG);
1154 int i;
1156 CHECKPTR(VarI2FromI4);
1157 CONVERT(VarI2FromI4, -32769); EXPECT_OVERFLOW;
1158 CONVERTRANGE(VarI2FromI4, -32768, 32768);
1159 CONVERT(VarI2FromI4, 32768); EXPECT_OVERFLOW;
1162 static void test_VarI2FromI8(void)
1164 CONVVARS(LONG64);
1166 CHECKPTR(VarI2FromI8);
1167 CONVERT(VarI2FromI8, -32769); EXPECT_OVERFLOW;
1168 CONVERT(VarI2FromI8, -32768); EXPECT(-32768);
1169 CONVERT(VarI2FromI8, 32767); EXPECT(32767);
1170 CONVERT(VarI2FromI8, 32768); EXPECT_OVERFLOW;
1173 static void test_VarI2FromUI1(void)
1175 CONVVARS(BYTE);
1176 int i;
1178 CHECKPTR(VarI2FromUI1);
1179 CONVERTRANGE(VarI2FromUI1, 0, 256);
1182 static void test_VarI2FromUI2(void)
1184 CONVVARS(USHORT);
1185 int i;
1187 CHECKPTR(VarI2FromUI2);
1188 CONVERTRANGE(VarI2FromUI2, 0, 32768);
1189 CONVERT(VarI2FromUI2, 32768); EXPECT_OVERFLOW;
1192 static void test_VarI2FromUI4(void)
1194 CONVVARS(ULONG);
1195 int i;
1197 CHECKPTR(VarI2FromUI4);
1198 CONVERTRANGE(VarI2FromUI4, 0, 32768);
1199 CONVERT(VarI2FromUI4, 32768); EXPECT_OVERFLOW;
1202 static void test_VarI2FromUI8(void)
1204 CONVVARS(ULONG64);
1205 int i;
1207 CHECKPTR(VarI2FromUI8);
1208 CONVERTRANGE(VarI2FromUI8, 0, 32768);
1209 CONVERT(VarI2FromUI8, 32768); EXPECT_OVERFLOW;
1212 static void test_VarI2FromBool(void)
1214 CONVVARS(VARIANT_BOOL);
1215 int i;
1217 CHECKPTR(VarI2FromBool);
1218 CONVERTRANGE(VarI2FromBool, -32768, 32768);
1221 static void test_VarI2FromR4(void)
1223 CONVVARS(FLOAT);
1225 CHECKPTR(VarI2FromR4);
1226 CONVERT(VarI2FromR4, -32769.0f); EXPECT_OVERFLOW;
1227 CONVERT(VarI2FromR4, -32768.0f); EXPECT(-32768);
1228 CONVERT(VarI2FromR4, -1.0f); EXPECT(-1);
1229 CONVERT(VarI2FromR4, 0.0f); EXPECT(0);
1230 CONVERT(VarI2FromR4, 1.0f); EXPECT(1);
1231 CONVERT(VarI2FromR4, 32767.0f); EXPECT(32767);
1232 CONVERT(VarI2FromR4, 32768.0f); EXPECT_OVERFLOW;
1234 /* Rounding */
1235 CONVERT(VarI2FromR4, -1.5f); EXPECT(-2);
1236 CONVERT(VarI2FromR4, -0.6f); EXPECT(-1);
1237 CONVERT(VarI2FromR4, -0.5f); EXPECT(0);
1238 CONVERT(VarI2FromR4, -0.4f); EXPECT(0);
1239 CONVERT(VarI2FromR4, 0.4f); EXPECT(0);
1240 CONVERT(VarI2FromR4, 0.5f); EXPECT(0);
1241 CONVERT(VarI2FromR4, 0.6f); EXPECT(1);
1242 CONVERT(VarI2FromR4, 1.5f); EXPECT(2);
1245 static void test_VarI2FromR8(void)
1247 CONVVARS(DOUBLE);
1249 CHECKPTR(VarI2FromR8);
1250 CONVERT(VarI2FromR8, -32769.0); EXPECT_OVERFLOW;
1251 CONVERT(VarI2FromR8, -32768.0); EXPECT(-32768);
1252 CONVERT(VarI2FromR8, -1.0); EXPECT(-1);
1253 CONVERT(VarI2FromR8, 0.0); EXPECT(0);
1254 CONVERT(VarI2FromR8, 1.0); EXPECT(1);
1255 CONVERT(VarI2FromR8, 32767.0); EXPECT(32767);
1256 CONVERT(VarI2FromR8, 32768.0); EXPECT_OVERFLOW;
1258 /* Rounding */
1259 CONVERT(VarI2FromR8, -1.5); EXPECT(-2);
1260 CONVERT(VarI2FromR8, -0.6); EXPECT(-1);
1261 CONVERT(VarI2FromR8, -0.5); EXPECT(0);
1262 CONVERT(VarI2FromR8, -0.4); EXPECT(0);
1263 CONVERT(VarI2FromR8, 0.4); EXPECT(0);
1264 CONVERT(VarI2FromR8, 0.5); EXPECT(0);
1265 CONVERT(VarI2FromR8, 0.6); EXPECT(1);
1266 CONVERT(VarI2FromR8, 1.5); EXPECT(2);
1269 static void test_VarI2FromDate(void)
1271 CONVVARS(DATE);
1273 CHECKPTR(VarI2FromDate);
1274 CONVERT(VarI2FromDate, -32769.0); EXPECT_OVERFLOW;
1275 CONVERT(VarI2FromDate, -32768.0); EXPECT(-32768);
1276 CONVERT(VarI2FromDate, -1.0); EXPECT(-1);
1277 CONVERT(VarI2FromDate, 0.0); EXPECT(0);
1278 CONVERT(VarI2FromDate, 1.0); EXPECT(1);
1279 CONVERT(VarI2FromDate, 32767.0); EXPECT(32767);
1280 CONVERT(VarI2FromDate, 32768.0); EXPECT_OVERFLOW;
1282 /* Rounding */
1283 CONVERT(VarI2FromDate, -1.5); EXPECT(-2);
1284 CONVERT(VarI2FromDate, -0.6); EXPECT(-1);
1285 CONVERT(VarI2FromDate, -0.5); EXPECT(0);
1286 CONVERT(VarI2FromDate, -0.4); EXPECT(0);
1287 CONVERT(VarI2FromDate, 0.4); EXPECT(0);
1288 CONVERT(VarI2FromDate, 0.5); EXPECT(0);
1289 CONVERT(VarI2FromDate, 0.6); EXPECT(1);
1290 CONVERT(VarI2FromDate, 1.5); EXPECT(2);
1293 static void test_VarI2FromCy(void)
1295 CONVVARS(CY);
1297 CHECKPTR(VarI2FromCy);
1298 CONVERT_CY(VarI2FromCy,-32769); EXPECT_OVERFLOW;
1299 CONVERT_CY(VarI2FromCy,-32768); EXPECT(32768);
1300 CONVERT_CY(VarI2FromCy,-1); EXPECT(-1);
1301 CONVERT_CY(VarI2FromCy,0); EXPECT(0);
1302 CONVERT_CY(VarI2FromCy,1); EXPECT(1);
1303 CONVERT_CY(VarI2FromCy,32767); EXPECT(32767);
1304 CONVERT_CY(VarI2FromCy,32768); EXPECT_OVERFLOW;
1306 /* Rounding */
1307 CONVERT_CY(VarI2FromCy,-1.5); EXPECT(-2);
1308 CONVERT_CY(VarI2FromCy,-0.6); EXPECT(-1);
1309 CONVERT_CY(VarI2FromCy,-0.5); EXPECT(0);
1310 CONVERT_CY(VarI2FromCy,-0.4); EXPECT(0);
1311 CONVERT_CY(VarI2FromCy,0.4); EXPECT(0);
1312 CONVERT_CY(VarI2FromCy,0.5); EXPECT(0);
1313 CONVERT_CY(VarI2FromCy,0.6); EXPECT(1);
1314 CONVERT_CY(VarI2FromCy,1.5); EXPECT(2);
1317 static void test_VarI2FromDec(void)
1319 CONVVARS(DECIMAL);
1321 CHECKPTR(VarI2FromDec);
1323 CONVERT_BADDEC(VarI2FromDec);
1325 CONVERT_DEC(VarI2FromDec,0,0x80,0,32769); EXPECT_OVERFLOW;
1326 CONVERT_DEC(VarI2FromDec,0,0x80,0,32768); EXPECT(-32768);
1327 CONVERT_DEC(VarI2FromDec,0,0x80,0,1); EXPECT(-1);
1328 CONVERT_DEC(VarI2FromDec,0,0,0,0); EXPECT(0);
1329 CONVERT_DEC(VarI2FromDec,0,0,0,1); EXPECT(1);
1330 CONVERT_DEC(VarI2FromDec,0,0,0,32767); EXPECT(32767);
1331 CONVERT_DEC(VarI2FromDec,0,0,0,32768); EXPECT_OVERFLOW;
1333 CONVERT_DEC(VarI2FromDec,2,0x80,0,3276800); EXPECT(-32768);
1334 CONVERT_DEC(VarI2FromDec,2,0,0,3276700); EXPECT(32767);
1335 CONVERT_DEC(VarI2FromDec,2,0,0,3276800); EXPECT_OVERFLOW;
1338 static void test_VarI2FromStr(void)
1340 CONVVARS(LCID);
1341 OLECHAR buff[128];
1343 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1345 CHECKPTR(VarI2FromStr);
1347 CONVERT_STR(VarI2FromStr,NULL, 0); EXPECT_MISMATCH;
1348 CONVERT_STR(VarI2FromStr,"0", 0); EXPECT(0);
1349 CONVERT_STR(VarI2FromStr,"-32769", 0); EXPECT_OVERFLOW;
1350 CONVERT_STR(VarI2FromStr,"-32768", 0); EXPECT(-32768);
1351 CONVERT_STR(VarI2FromStr,"32767", 0); EXPECT(32767);
1352 CONVERT_STR(VarI2FromStr,"32768", 0); EXPECT_OVERFLOW;
1354 /* Rounding */
1355 CONVERT_STR(VarI2FromStr,"-1.5", 0); EXPECT(-2);
1356 CONVERT_STR(VarI2FromStr,"-0.6", 0); EXPECT(-1);
1357 CONVERT_STR(VarI2FromStr,"-0.5", 0); EXPECT(0);
1358 CONVERT_STR(VarI2FromStr,"-0.4", 0); EXPECT(0);
1359 CONVERT_STR(VarI2FromStr,"0.4", 0); EXPECT(0);
1360 CONVERT_STR(VarI2FromStr,"0.5", 0); EXPECT(0);
1361 CONVERT_STR(VarI2FromStr,"0.6", 0); EXPECT(1);
1362 CONVERT_STR(VarI2FromStr,"1.5", 0); EXPECT(2);
1365 static void test_VarI2Copy(void)
1367 COPYTEST(1, VT_I2, V_I2(&vSrc), V_I2(&vDst), V_I2REF(&vSrc), V_I2REF(&vDst), "%d");
1370 static void test_VarI2ChangeTypeEx(void)
1372 CONVVARS(CONV_TYPE);
1373 VARIANTARG vSrc, vDst;
1375 in = 1;
1377 INITIAL_TYPETEST(VT_I2, V_I2, "%d");
1378 COMMON_TYPETEST;
1381 #undef CONV_TYPE
1382 #define CONV_TYPE USHORT
1384 static void test_VarUI2FromI1(void)
1386 CONVVARS(signed char);
1387 int i;
1389 CHECKPTR(VarUI2FromI1);
1390 OVERFLOWRANGE(VarUI2FromI1, -128, 0);
1391 CONVERTRANGE(VarUI2FromI1, 0, 128);
1394 static void test_VarUI2FromI2(void)
1396 CONVVARS(SHORT);
1397 int i;
1399 CHECKPTR(VarUI2FromI2);
1400 OVERFLOWRANGE(VarUI2FromI2, -32768, 0);
1401 CONVERTRANGE(VarUI2FromI2, 0, 32768);
1404 static void test_VarUI2FromI4(void)
1406 CONVVARS(LONG);
1407 int i;
1409 CHECKPTR(VarUI2FromI4);
1410 OVERFLOWRANGE(VarUI2FromI4, -32768, 0);
1411 CONVERT(VarUI2FromI4, 0); EXPECT(0);
1412 CONVERT(VarUI2FromI4, 65535); EXPECT(65535);
1413 CONVERT(VarUI2FromI4, 65536); EXPECT_OVERFLOW;
1416 static void test_VarUI2FromI8(void)
1418 CONVVARS(LONG64);
1419 int i;
1421 CHECKPTR(VarUI2FromI8);
1422 OVERFLOWRANGE(VarUI2FromI8, -32768, 0);
1423 CONVERT(VarUI2FromI8, 0); EXPECT(0);
1424 CONVERT(VarUI2FromI8, 65535); EXPECT(65535);
1425 CONVERT(VarUI2FromI8, 65536); EXPECT_OVERFLOW;
1428 static void test_VarUI2FromUI1(void)
1430 CONVVARS(BYTE);
1431 int i;
1433 CHECKPTR(VarUI2FromUI1);
1434 CONVERTRANGE(VarUI2FromUI1, 0, 256);
1437 static void test_VarUI2FromUI4(void)
1439 CONVVARS(ULONG);
1441 CHECKPTR(VarUI2FromUI4);
1442 CONVERT(VarUI2FromUI4, 0); EXPECT(0);
1443 CONVERT(VarUI2FromUI4, 65535); EXPECT(65535);
1444 CONVERT(VarUI2FromUI4, 65536); EXPECT_OVERFLOW;
1447 static void test_VarUI2FromUI8(void)
1449 CONVVARS(ULONG64);
1451 CHECKPTR(VarUI2FromUI8);
1452 CONVERT(VarUI2FromUI8, 0); EXPECT(0);
1453 CONVERT(VarUI2FromUI8, 65535); EXPECT(65535);
1454 CONVERT(VarUI2FromUI8, 65536); EXPECT_OVERFLOW;
1457 static void test_VarUI2FromBool(void)
1459 CONVVARS(VARIANT_BOOL);
1460 int i;
1462 CHECKPTR(VarUI2FromBool);
1463 CONVERT(VarUI2FromBool, -1); EXPECT(65535); /* Wraps! */
1464 CONVERTRANGE(VarUI2FromBool, 0, 32768);
1467 static void test_VarUI2FromR4(void)
1469 CONVVARS(FLOAT);
1471 CHECKPTR(VarUI2FromR4);
1472 CONVERT(VarUI2FromR4, -1.0f); EXPECT_OVERFLOW;
1473 CONVERT(VarUI2FromR4, 0.0f); EXPECT(0);
1474 CONVERT(VarUI2FromR4, 1.0f); EXPECT(1);
1475 CONVERT(VarUI2FromR4, 65535.0f); EXPECT(65535);
1476 CONVERT(VarUI2FromR4, 65536.0f); EXPECT_OVERFLOW;
1478 /* Rounding */
1479 CONVERT(VarUI2FromR4, -1.5f); EXPECT_OVERFLOW;
1480 CONVERT(VarUI2FromR4, -0.6f); EXPECT_OVERFLOW;
1481 CONVERT(VarUI2FromR4, -0.5f); EXPECT(0);
1482 CONVERT(VarUI2FromR4, -0.4f); EXPECT(0);
1483 CONVERT(VarUI2FromR4, 0.4f); EXPECT(0);
1484 CONVERT(VarUI2FromR4, 0.5f); EXPECT(0);
1485 CONVERT(VarUI2FromR4, 0.6f); EXPECT(1);
1486 CONVERT(VarUI2FromR4, 1.5f); EXPECT(2);
1489 static void test_VarUI2FromR8(void)
1491 CONVVARS(DOUBLE);
1493 CHECKPTR(VarUI2FromR8);
1494 CONVERT(VarUI2FromR8, -1.0); EXPECT_OVERFLOW;
1495 CONVERT(VarUI2FromR8, 0.0); EXPECT(0);
1496 CONVERT(VarUI2FromR8, 1.0); EXPECT(1);
1497 CONVERT(VarUI2FromR8, 65535.0); EXPECT(65535);
1498 CONVERT(VarUI2FromR8, 65536.0); EXPECT_OVERFLOW;
1500 /* Rounding */
1501 CONVERT(VarUI2FromR8, -1.5); EXPECT_OVERFLOW;
1502 CONVERT(VarUI2FromR8, -0.6); EXPECT_OVERFLOW;
1503 CONVERT(VarUI2FromR8, -0.5); EXPECT(0);
1504 CONVERT(VarUI2FromR8, -0.4); EXPECT(0);
1505 CONVERT(VarUI2FromR8, 0.4); EXPECT(0);
1506 CONVERT(VarUI2FromR8, 0.5); EXPECT(0);
1507 CONVERT(VarUI2FromR8, 0.6); EXPECT(1);
1508 CONVERT(VarUI2FromR8, 1.5); EXPECT(2);
1511 static void test_VarUI2FromDate(void)
1513 CONVVARS(DATE);
1515 CHECKPTR(VarUI2FromDate);
1516 CONVERT(VarUI2FromDate, -1.0); EXPECT_OVERFLOW;
1517 CONVERT(VarUI2FromDate, 0.0); EXPECT(0);
1518 CONVERT(VarUI2FromDate, 1.0); EXPECT(1);
1519 CONVERT(VarUI2FromDate, 65535.0); EXPECT(65535);
1520 CONVERT(VarUI2FromDate, 65536.0); EXPECT_OVERFLOW;
1522 /* Rounding */
1523 CONVERT(VarUI2FromDate, -1.5); EXPECT_OVERFLOW;
1524 CONVERT(VarUI2FromDate, -0.6); EXPECT_OVERFLOW;
1525 CONVERT(VarUI2FromDate, -0.5); EXPECT(0);
1526 CONVERT(VarUI2FromDate, -0.4); EXPECT(0);
1527 CONVERT(VarUI2FromDate, 0.4); EXPECT(0);
1528 CONVERT(VarUI2FromDate, 0.5); EXPECT(0);
1529 CONVERT(VarUI2FromDate, 0.6); EXPECT(1);
1530 CONVERT(VarUI2FromDate, 1.5); EXPECT(2);
1533 static void test_VarUI2FromCy(void)
1535 CONVVARS(CY);
1537 CHECKPTR(VarUI2FromCy);
1538 CONVERT_CY(VarUI2FromCy,-1); EXPECT_OVERFLOW;
1539 CONVERT_CY(VarUI2FromCy,0); EXPECT(0);
1540 CONVERT_CY(VarUI2FromCy,1); EXPECT(1);
1541 CONVERT_CY(VarUI2FromCy,65535); EXPECT(65535);
1542 CONVERT_CY(VarUI2FromCy,65536); EXPECT_OVERFLOW;
1544 /* Rounding */
1545 CONVERT_CY(VarUI2FromCy,-1.5); EXPECT_OVERFLOW;
1546 CONVERT_CY(VarUI2FromCy,-0.6); EXPECT_OVERFLOW;
1547 CONVERT_CY(VarUI2FromCy,-0.5); EXPECT(0);
1548 CONVERT_CY(VarUI2FromCy,-0.4); EXPECT(0);
1549 CONVERT_CY(VarUI2FromCy,0.4); EXPECT(0);
1550 CONVERT_CY(VarUI2FromCy,0.5); EXPECT(0);
1551 CONVERT_CY(VarUI2FromCy,0.6); EXPECT(1);
1552 CONVERT_CY(VarUI2FromCy,1.5); EXPECT(2);
1555 static void test_VarUI2FromDec(void)
1557 CONVVARS(DECIMAL);
1559 CHECKPTR(VarUI2FromDec);
1561 CONVERT_BADDEC(VarUI2FromDec);
1563 CONVERT_DEC(VarUI2FromDec,0,0x80,0,1); EXPECT_OVERFLOW;
1564 CONVERT_DEC(VarUI2FromDec,0,0,0,0); EXPECT(0);
1565 CONVERT_DEC(VarUI2FromDec,0,0,0,1); EXPECT(1);
1566 CONVERT_DEC(VarUI2FromDec,0,0,0,65535); EXPECT(65535);
1567 CONVERT_DEC(VarUI2FromDec,0,0,0,65536); EXPECT_OVERFLOW;
1569 CONVERT_DEC(VarUI2FromDec,2,0x80,0,100); EXPECT_OVERFLOW;
1570 CONVERT_DEC(VarUI2FromDec,2,0,0,6553500); EXPECT(65535);
1571 CONVERT_DEC(VarUI2FromDec,2,0,0,6553600); EXPECT_OVERFLOW;
1574 static void test_VarUI2FromStr(void)
1576 CONVVARS(LCID);
1577 OLECHAR buff[128];
1579 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1581 CHECKPTR(VarUI2FromStr);
1583 CONVERT_STR(VarUI2FromStr,NULL, 0); EXPECT_MISMATCH;
1584 CONVERT_STR(VarUI2FromStr,"0", 0); EXPECT(0);
1585 CONVERT_STR(VarUI2FromStr,"-1", 0); EXPECT_OVERFLOW;
1586 CONVERT_STR(VarUI2FromStr,"65535", 0); EXPECT(65535);
1587 CONVERT_STR(VarUI2FromStr,"65536", 0); EXPECT_OVERFLOW;
1589 /* Rounding */
1590 CONVERT_STR(VarUI2FromStr,"-1.5", 0); EXPECT_OVERFLOW;
1591 CONVERT_STR(VarUI2FromStr,"-0.6", 0); EXPECT_OVERFLOW;
1592 CONVERT_STR(VarUI2FromStr,"-0.5", 0); EXPECT(0);
1593 CONVERT_STR(VarUI2FromStr,"-0.4", 0); EXPECT(0);
1594 CONVERT_STR(VarUI2FromStr,"0.4", 0); EXPECT(0);
1595 CONVERT_STR(VarUI2FromStr,"0.5", 0); EXPECT(0);
1596 CONVERT_STR(VarUI2FromStr,"0.6", 0); EXPECT(1);
1597 CONVERT_STR(VarUI2FromStr,"1.5", 0); EXPECT(2);
1600 static void test_VarUI2Copy(void)
1602 if (!IS_ANCIENT)
1604 COPYTEST(1, VT_UI2, V_UI2(&vSrc), V_UI2(&vDst), V_UI2REF(&vSrc), V_UI2REF(&vDst), "%d");
1608 static void test_VarUI2ChangeTypeEx(void)
1610 CONVVARS(CONV_TYPE);
1611 VARIANTARG vSrc, vDst;
1613 in = 1;
1615 if (!IS_ANCIENT)
1617 INITIAL_TYPETEST(VT_UI2, V_UI2, "%d");
1618 COMMON_TYPETEST;
1623 * VT_I4/VT_UI4
1626 #undef CONV_TYPE
1627 #define CONV_TYPE LONG
1628 #undef EXPECTRES
1629 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%ld")
1632 static void test_VarI4FromI1(void)
1634 CONVVARS(signed char);
1635 int i;
1637 CHECKPTR(VarI4FromI1);
1638 CONVERTRANGE(VarI4FromI1, -128, 128);
1641 static void test_VarI4FromI2(void)
1643 CONVVARS(SHORT);
1644 int i;
1646 CHECKPTR(VarI4FromI2);
1647 CONVERTRANGE(VarI4FromI2, -32768, 32768);
1650 static void test_VarI4FromI8(void)
1652 CONVVARS(LONG64);
1654 CHECKPTR(VarI4FromI8);
1655 CHECKPTR(VarI4FromDec);
1657 CONVERT(VarI4FromI8, -1); EXPECT(-1);
1658 CONVERT(VarI4FromI8, 0); EXPECT(0);
1659 CONVERT(VarI4FromI8, 1); EXPECT(1);
1661 CONVERT_I8(VarI4FromI8, -1, 2147483647ul); EXPECT_OVERFLOW;
1662 CONVERT_I8(VarI4FromI8, -1, 2147483648ul); EXPECT(-2147483647 - 1);
1663 CONVERT_I8(VarI4FromI8, 0, 2147483647ul); EXPECT(2147483647);
1664 CONVERT_I8(VarI4FromI8, 0, 2147483648ul); EXPECT_OVERFLOW;
1667 static void test_VarI4FromUI1(void)
1669 CONVVARS(BYTE);
1670 int i;
1672 CHECKPTR(VarI4FromUI1);
1673 CONVERTRANGE(VarI4FromUI1, 0, 256);
1676 static void test_VarI4FromUI2(void)
1678 CONVVARS(USHORT);
1679 int i;
1681 CHECKPTR(VarI4FromUI2);
1682 CONVERTRANGE(VarI4FromUI2, 0, 65536);
1685 static void test_VarI4FromUI4(void)
1687 CONVVARS(ULONG);
1689 CHECKPTR(VarI4FromUI4);
1690 CONVERT(VarI4FromUI4, 0); EXPECT(0);
1691 CONVERT(VarI4FromUI4, 1); EXPECT(1);
1692 CONVERT(VarI4FromUI4, 2147483647); EXPECT(2147483647);
1693 CONVERT(VarI4FromUI4, 2147483648ul); EXPECT_OVERFLOW;
1696 static void test_VarI4FromUI8(void)
1698 CONVVARS(ULONG64);
1700 CHECKPTR(VarI4FromUI8);
1701 CONVERT(VarI4FromUI8, 0); EXPECT(0);
1702 CONVERT(VarI4FromUI8, 1); EXPECT(1);
1703 CONVERT(VarI4FromUI8, 2147483647); EXPECT(2147483647);
1704 CONVERT(VarI4FromUI8, 2147483648ul); EXPECT_OVERFLOW;
1707 static void test_VarI4FromBool(void)
1709 CONVVARS(VARIANT_BOOL);
1710 int i;
1712 CHECKPTR(VarI4FromBool);
1713 CONVERTRANGE(VarI4FromBool, -32768, 32768);
1716 static void test_VarI4FromR4(void)
1718 CONVVARS(FLOAT);
1720 CHECKPTR(VarI4FromR4);
1722 /* min/max values are not exactly representable in a float */
1723 CONVERT(VarI4FromR4, -1.0f); EXPECT(-1);
1724 CONVERT(VarI4FromR4, 0.0f); EXPECT(0);
1725 CONVERT(VarI4FromR4, 1.0f); EXPECT(1);
1727 CONVERT(VarI4FromR4, -1.5f); EXPECT(-2);
1728 CONVERT(VarI4FromR4, -0.6f); EXPECT(-1);
1729 CONVERT(VarI4FromR4, -0.5f); EXPECT(0);
1730 CONVERT(VarI4FromR4, -0.4f); EXPECT(0);
1731 CONVERT(VarI4FromR4, 0.4f); EXPECT(0);
1732 CONVERT(VarI4FromR4, 0.5f); EXPECT(0);
1733 CONVERT(VarI4FromR4, 0.6f); EXPECT(1);
1734 CONVERT(VarI4FromR4, 1.5f); EXPECT(2);
1737 static void test_VarI4FromR8(void)
1739 CONVVARS(DOUBLE);
1741 CHECKPTR(VarI4FromR8);
1742 CONVERT(VarI4FromR8, -2147483649.0); EXPECT_OVERFLOW;
1743 CONVERT(VarI4FromR8, -2147483648.0); EXPECT(-2147483647 - 1);
1744 CONVERT(VarI4FromR8, -1.0); EXPECT(-1);
1745 CONVERT(VarI4FromR8, 0.0); EXPECT(0);
1746 CONVERT(VarI4FromR8, 1.0); EXPECT(1);
1747 CONVERT(VarI4FromR8, 2147483647.0); EXPECT(2147483647);
1748 CONVERT(VarI4FromR8, 2147483648.0); EXPECT_OVERFLOW;
1750 CONVERT(VarI4FromR8, -1.5); EXPECT(-2);
1751 CONVERT(VarI4FromR8, -0.6); EXPECT(-1);
1752 CONVERT(VarI4FromR8, -0.5); EXPECT(0);
1753 CONVERT(VarI4FromR8, -0.4); EXPECT(0);
1754 CONVERT(VarI4FromR8, 0.4); EXPECT(0);
1755 CONVERT(VarI4FromR8, 0.5); EXPECT(0);
1756 CONVERT(VarI4FromR8, 0.6); EXPECT(1);
1757 CONVERT(VarI4FromR8, 1.5); EXPECT(2);
1760 static void test_VarI4FromDate(void)
1762 CONVVARS(DATE);
1764 CHECKPTR(VarI4FromDate);
1765 CONVERT(VarI4FromDate, -2147483649.0); EXPECT_OVERFLOW;
1766 CONVERT(VarI4FromDate, -2147483648.0); EXPECT(-2147483647 - 1);
1767 CONVERT(VarI4FromDate, -1.0); EXPECT(-1);
1768 CONVERT(VarI4FromDate, 0.0); EXPECT(0);
1769 CONVERT(VarI4FromDate, 1.0); EXPECT(1);
1770 CONVERT(VarI4FromDate, 2147483647.0); EXPECT(2147483647);
1771 CONVERT(VarI4FromDate, 2147483648.0); EXPECT_OVERFLOW;
1773 CONVERT(VarI4FromDate, -1.5); EXPECT(-2);
1774 CONVERT(VarI4FromDate, -0.6); EXPECT(-1);
1775 CONVERT(VarI4FromDate, -0.5); EXPECT(0);
1776 CONVERT(VarI4FromDate, -0.4); EXPECT(0);
1777 CONVERT(VarI4FromDate, 0.4); EXPECT(0);
1778 CONVERT(VarI4FromDate, 0.5); EXPECT(0);
1779 CONVERT(VarI4FromDate, 0.6); EXPECT(1);
1780 CONVERT(VarI4FromDate, 1.5); EXPECT(2);
1783 static void test_VarI4FromCy(void)
1785 CONVVARS(CY);
1787 CHECKPTR(VarI4FromCy);
1788 CONVERT_CY(VarI4FromCy,-1); EXPECT(-1);
1789 CONVERT_CY(VarI4FromCy,0); EXPECT(0);
1790 CONVERT_CY(VarI4FromCy,1); EXPECT(1);
1792 CONVERT_CY64(VarI4FromCy,-1,2147483647ul); EXPECT_OVERFLOW;
1793 CONVERT_CY64(VarI4FromCy,-1,2147483648ul); EXPECT(-2147483647 - 1);
1794 CONVERT_CY64(VarI4FromCy,0,2147483647ul); EXPECT(2147483647ul);
1795 CONVERT_CY64(VarI4FromCy,0,2147483648ul); EXPECT_OVERFLOW;
1797 CONVERT_CY(VarI4FromCy,-1.5); EXPECT(-2);
1798 CONVERT_CY(VarI4FromCy,-0.6); EXPECT(-1);
1799 CONVERT_CY(VarI4FromCy,-0.5); EXPECT(0);
1800 CONVERT_CY(VarI4FromCy,-0.4); EXPECT(0);
1801 CONVERT_CY(VarI4FromCy,0.4); EXPECT(0);
1802 CONVERT_CY(VarI4FromCy,0.5); EXPECT(0);
1803 CONVERT_CY(VarI4FromCy,0.6); EXPECT(1);
1804 CONVERT_CY(VarI4FromCy,1.5); EXPECT(2);
1807 static void test_VarI4FromDec(void)
1809 CONVVARS(DECIMAL);
1811 CHECKPTR(VarI4FromDec);
1813 CONVERT_BADDEC(VarI4FromDec);
1815 CONVERT_DEC(VarI4FromDec,0,0x80,0,1); EXPECT(-1);
1816 CONVERT_DEC(VarI4FromDec,0,0,0,0); EXPECT(0);
1817 CONVERT_DEC(VarI4FromDec,0,0,0,1); EXPECT(1);
1819 CONVERT_DEC64(VarI4FromDec,0,0x80,0,0,2147483649ul); EXPECT_OVERFLOW;
1820 CONVERT_DEC64(VarI4FromDec,0,0x80,0,0,2147483648ul); EXPECT(-2147483647 - 1);
1821 CONVERT_DEC64(VarI4FromDec,0,0,0,0,2147483647ul); EXPECT(2147483647ul);
1822 CONVERT_DEC64(VarI4FromDec,0,0,0,0,2147483648ul); EXPECT_OVERFLOW;
1824 CONVERT_DEC64(VarI4FromDec,2,0x80,0,50,100); EXPECT_OVERFLOW;
1825 CONVERT_DEC64(VarI4FromDec,2,0x80,0,50,0); EXPECT(-2147483647 - 1);
1826 CONVERT_DEC64(VarI4FromDec,2,0,0,49,4294967196ul); EXPECT(2147483647);
1827 CONVERT_DEC64(VarI4FromDec,2,0,0,50,0); EXPECT_OVERFLOW;
1830 static void test_VarI4FromStr(void)
1832 CONVVARS(LCID);
1833 OLECHAR buff[128];
1835 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1837 CHECKPTR(VarI4FromStr);
1839 CONVERT_STR(VarI4FromStr,NULL,0); EXPECT_MISMATCH;
1840 CONVERT_STR(VarI4FromStr,"0",0); EXPECT(0);
1841 CONVERT_STR(VarI4FromStr,"-2147483649",0); EXPECT_OVERFLOW;
1842 CONVERT_STR(VarI4FromStr,"-2147483648",0); EXPECT(-2147483647 -1);
1843 CONVERT_STR(VarI4FromStr,"2147483647",0); EXPECT(2147483647);
1844 CONVERT_STR(VarI4FromStr,"2147483648",0); EXPECT_OVERFLOW;
1846 /* Rounding */
1847 CONVERT_STR(VarI4FromStr,"-1.5",0); EXPECT(-2);
1848 CONVERT_STR(VarI4FromStr,"-0.6",0); EXPECT(-1);
1849 CONVERT_STR(VarI4FromStr,"-0.5",0); EXPECT(0);
1850 CONVERT_STR(VarI4FromStr,"-0.4",0); EXPECT(0);
1851 CONVERT_STR(VarI4FromStr,"0.4",0); EXPECT(0);
1852 CONVERT_STR(VarI4FromStr,"0.5",0); EXPECT(0);
1853 CONVERT_STR(VarI4FromStr,"0.6",0); EXPECT(1);
1854 CONVERT_STR(VarI4FromStr,"1.5",0); EXPECT(2);
1857 static void test_VarI4Copy(void)
1859 COPYTEST(1l, VT_I4, V_I4(&vSrc), V_I4(&vDst), V_I4REF(&vSrc), V_I4REF(&vDst), "%ld");
1862 static void test_VarI4ChangeTypeEx(void)
1864 CONVVARS(CONV_TYPE);
1865 VARIANTARG vSrc, vDst;
1867 in = 1;
1869 INITIAL_TYPETEST(VT_I4, V_I4, "%ld");
1870 COMMON_TYPETEST;
1873 #undef CONV_TYPE
1874 #define CONV_TYPE ULONG
1875 #undef EXPECTRES
1876 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%lu")
1878 static void test_VarUI4FromI1(void)
1880 CONVVARS(signed char);
1881 int i;
1883 CHECKPTR(VarUI4FromI1);
1884 OVERFLOWRANGE(VarUI4FromI1, -127, 0);
1885 CONVERTRANGE(VarUI4FromI1, 0, 128);
1888 static void test_VarUI4FromI2(void)
1890 CONVVARS(SHORT);
1891 int i;
1893 CHECKPTR(VarUI4FromI2);
1894 OVERFLOWRANGE(VarUI4FromI2, -32768, 0);
1895 CONVERTRANGE(VarUI4FromI2, 0, 32768);
1898 static void test_VarUI4FromUI2(void)
1900 CONVVARS(USHORT);
1901 int i;
1903 CHECKPTR(VarUI4FromUI2);
1904 CONVERTRANGE(VarUI4FromUI2, 0, 65536);
1907 static void test_VarUI4FromI8(void)
1909 CONVVARS(LONG64);
1911 CHECKPTR(VarUI4FromI8);
1912 CONVERT(VarUI4FromI8, -1); EXPECT_OVERFLOW;
1913 CONVERT(VarUI4FromI8, 0); EXPECT(0);
1914 CONVERT(VarUI4FromI8, 1); EXPECT(1);
1915 CONVERT(VarUI4FromI8, 4294967295ul); EXPECT(4294967295ul);
1916 CONVERT_I8(VarUI4FromI8, 1, 0); EXPECT_OVERFLOW;
1919 static void test_VarUI4FromUI1(void)
1921 CONVVARS(BYTE);
1922 int i;
1924 CHECKPTR(VarUI4FromUI1);
1925 CONVERTRANGE(VarUI4FromUI1, 0, 256);
1928 static void test_VarUI4FromI4(void)
1930 CONVVARS(int);
1932 CHECKPTR(VarUI4FromI4);
1933 CONVERT(VarUI4FromI4, -1); EXPECT_OVERFLOW;
1934 CONVERT(VarUI4FromI4, 0); EXPECT(0);
1935 CONVERT(VarUI4FromI4, 1); EXPECT(1);
1936 CONVERT(VarUI4FromI4, 2147483647); EXPECT(2147483647);
1939 static void test_VarUI4FromUI8(void)
1941 CONVVARS(ULONG64);
1943 CHECKPTR(VarUI4FromUI8);
1944 CONVERT(VarUI4FromUI8, 0); EXPECT(0);
1945 CONVERT(VarUI4FromUI8, 1); EXPECT(1);
1946 CONVERT(VarUI4FromI8, 4294967295ul); EXPECT(4294967295ul);
1947 CONVERT_I8(VarUI4FromI8, 1, 0); EXPECT_OVERFLOW;
1950 static void test_VarUI4FromBool(void)
1952 CONVVARS(VARIANT_BOOL);
1953 int i;
1955 CHECKPTR(VarUI4FromBool);
1956 CONVERTRANGE(VarUI4FromBool, -32768, 32768);
1959 static void test_VarUI4FromR4(void)
1961 CONVVARS(FLOAT);
1963 CHECKPTR(VarUI4FromR4);
1964 /* We can't test max values as they are not exactly representable in a float */
1965 CONVERT(VarUI4FromR4, -1.0f); EXPECT_OVERFLOW;
1966 CONVERT(VarUI4FromR4, 0.0f); EXPECT(0);
1967 CONVERT(VarUI4FromR4, 1.0f); EXPECT(1);
1969 CONVERT(VarUI4FromR4, -1.5f); EXPECT_OVERFLOW;
1970 CONVERT(VarUI4FromR4, -0.6f); EXPECT_OVERFLOW;
1971 CONVERT(VarUI4FromR4, -0.5f); EXPECT(0);
1972 CONVERT(VarUI4FromR4, -0.4f); EXPECT(0);
1973 CONVERT(VarUI4FromR4, 0.4f); EXPECT(0);
1974 CONVERT(VarUI4FromR4, 0.5f); EXPECT(0);
1975 CONVERT(VarUI4FromR4, 0.6f); EXPECT(1);
1976 CONVERT(VarUI4FromR4, 1.5f); EXPECT(2);
1980 static void test_VarUI4FromR8(void)
1982 CONVVARS(DOUBLE);
1984 CHECKPTR(VarUI4FromR8);
1985 CONVERT(VarUI4FromR8, -1.0); EXPECT_OVERFLOW;
1986 CONVERT(VarUI4FromR8, 0.0); EXPECT(0);
1987 CONVERT(VarUI4FromR8, 1.0); EXPECT(1);
1988 CONVERT(VarUI4FromR8, 4294967295.0); EXPECT(4294967295ul);
1989 CONVERT(VarUI4FromR8, 4294967296.0); EXPECT_OVERFLOW;
1991 CONVERT(VarUI4FromR8, -1.5); EXPECT_OVERFLOW;
1992 CONVERT(VarUI4FromR8, -0.6); EXPECT_OVERFLOW;
1993 CONVERT(VarUI4FromR8, -0.5); EXPECT(0);
1994 CONVERT(VarUI4FromR8, -0.4); EXPECT(0);
1995 CONVERT(VarUI4FromR8, 0.4); EXPECT(0);
1996 CONVERT(VarUI4FromR8, 0.5); EXPECT(0);
1997 CONVERT(VarUI4FromR8, 0.6); EXPECT(1);
1998 CONVERT(VarUI4FromR8, 1.5); EXPECT(2);
2001 static void test_VarUI4FromDate(void)
2003 CONVVARS(DOUBLE);
2005 CHECKPTR(VarUI4FromDate);
2006 CONVERT(VarUI4FromDate, -1.0); EXPECT_OVERFLOW;
2007 CONVERT(VarUI4FromDate, 0.0); EXPECT(0);
2008 CONVERT(VarUI4FromDate, 1.0); EXPECT(1);
2009 CONVERT(VarUI4FromDate, 4294967295.0); EXPECT(4294967295ul);
2010 CONVERT(VarUI4FromDate, 4294967296.0); EXPECT_OVERFLOW;
2012 CONVERT(VarUI4FromDate, -1.5); EXPECT_OVERFLOW;
2013 CONVERT(VarUI4FromDate, -0.6); EXPECT_OVERFLOW;
2014 CONVERT(VarUI4FromDate, -0.5); EXPECT(0);
2015 CONVERT(VarUI4FromDate, -0.4); EXPECT(0);
2016 CONVERT(VarUI4FromDate, 0.4); EXPECT(0);
2017 CONVERT(VarUI4FromDate, 0.5); EXPECT(0);
2018 CONVERT(VarUI4FromDate, 0.6); EXPECT(1);
2019 CONVERT(VarUI4FromDate, 1.5); EXPECT(2);
2022 static void test_VarUI4FromCy(void)
2024 CONVVARS(CY);
2026 CHECKPTR(VarUI4FromCy);
2027 CONVERT_CY(VarUI4FromCy,-1); EXPECT_OVERFLOW;
2028 CONVERT_CY(VarUI4FromCy,0); EXPECT(0);
2029 CONVERT_CY(VarUI4FromCy,1); EXPECT(1);
2030 CONVERT_CY64(VarUI4FromCy,0,4294967295ul); EXPECT(4294967295ul);
2031 CONVERT_CY64(VarUI4FromCy,1,0); EXPECT_OVERFLOW;
2033 CONVERT_CY(VarUI4FromCy,-1.5); EXPECT_OVERFLOW;
2034 CONVERT_CY(VarUI4FromCy,-0.6); EXPECT_OVERFLOW;
2035 CONVERT_CY(VarUI4FromCy,-0.5); EXPECT(0);
2036 CONVERT_CY(VarUI4FromCy,-0.4); EXPECT(0);
2037 CONVERT_CY(VarUI4FromCy,0.4); EXPECT(0);
2038 CONVERT_CY(VarUI4FromCy,0.5); EXPECT(0);
2039 CONVERT_CY(VarUI4FromCy,0.6); EXPECT(1);
2040 CONVERT_CY(VarUI4FromCy,1.5); EXPECT(2);
2043 static void test_VarUI4FromDec(void)
2045 CONVVARS(DECIMAL);
2047 CHECKPTR(VarUI4FromDec);
2049 CONVERT_BADDEC(VarUI4FromDec);
2051 CONVERT_DEC(VarUI4FromDec,0,0x80,0,1); EXPECT_OVERFLOW;
2052 CONVERT_DEC(VarUI4FromDec,0,0,0,0); EXPECT(0);
2053 CONVERT_DEC(VarUI4FromDec,0,0,0,1); EXPECT(1);
2054 CONVERT_DEC64(VarUI4FromDec,0,0,0,0,4294967295ul); EXPECT(4294967295ul);
2055 CONVERT_DEC64(VarUI4FromDec,0,0,0,1,0); EXPECT_OVERFLOW;
2057 CONVERT_DEC64(VarUI4FromDec,2,0,0,99,4294967196ul); EXPECT(4294967295ul);
2058 CONVERT_DEC64(VarUI4FromDec,2,0,0,100,0); EXPECT_OVERFLOW;
2061 static void test_VarUI4FromStr(void)
2063 CONVVARS(LCID);
2064 OLECHAR buff[128];
2066 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2068 CHECKPTR(VarUI4FromStr);
2070 CONVERT_STR(VarUI4FromStr,NULL,0); EXPECT_MISMATCH;
2071 CONVERT_STR(VarUI4FromStr,"-1",0); EXPECT_OVERFLOW;
2072 CONVERT_STR(VarUI4FromStr,"0",0); EXPECT(0);
2073 CONVERT_STR(VarUI4FromStr,"4294967295",0); EXPECT(4294967295ul);
2074 CONVERT_STR(VarUI4FromStr,"4294967296",0); EXPECT_OVERFLOW;
2076 /* Rounding */
2077 CONVERT_STR(VarUI4FromStr,"-1.5",0); EXPECT_OVERFLOW;
2078 CONVERT_STR(VarUI4FromStr,"-0.6",0); EXPECT_OVERFLOW;
2079 CONVERT_STR(VarUI4FromStr,"-0.5",0); EXPECT(0);
2080 CONVERT_STR(VarUI4FromStr,"-0.4",0); EXPECT(0);
2081 CONVERT_STR(VarUI4FromStr,"0.4",0); EXPECT(0);
2082 CONVERT_STR(VarUI4FromStr,"0.5",0); EXPECT(0);
2083 CONVERT_STR(VarUI4FromStr,"0.6",0); EXPECT(1);
2084 CONVERT_STR(VarUI4FromStr,"1.5",0); EXPECT(2);
2087 static void test_VarUI4Copy(void)
2089 if (!IS_ANCIENT)
2091 COPYTEST(1ul, VT_UI4, V_UI4(&vSrc), V_UI4(&vDst), V_UI4REF(&vSrc), V_UI4REF(&vDst), "%lu");
2095 static void test_VarUI4ChangeTypeEx(void)
2097 CONVVARS(CONV_TYPE);
2098 VARIANTARG vSrc, vDst;
2100 in = 1;
2102 if (!IS_ANCIENT)
2104 INITIAL_TYPETEST(VT_UI4, V_UI4, "%lu");
2105 COMMON_TYPETEST;
2110 * VT_I8/VT_UI8
2113 #undef CONV_TYPE
2114 #define CONV_TYPE LONG64
2115 #undef EXPECTRES
2116 #define EXPECTRES(res, x) \
2117 ok(hres == S_OK || ((HRESULT)res != S_OK && hres == (HRESULT)res), \
2118 "expected hres " #x ", got hres=0x%08lx\n", hres)
2120 #define EXPECTI8(x) \
2121 ok((hres == S_OK && out == (CONV_TYPE)(x)), \
2122 "expected " #x "(%lu,%lu), got (%lu,%lu); hres=0x%08lx\n", \
2123 (ULONG)((LONG64)(x) >> 32), (ULONG)((x) & 0xffffffff), \
2124 (ULONG)(out >> 32), (ULONG)(out & 0xffffffff), hres)
2126 #define EXPECTI864(x,y) \
2127 ok(hres == S_OK && (out >> 32) == (CONV_TYPE)(x) && (out & 0xffffffff) == (CONV_TYPE)(y), \
2128 "expected " #x "(%lu,%lu), got (%lu,%lu); hres=0x%08lx\n", \
2129 (ULONG)(x), (ULONG)(y), \
2130 (ULONG)(out >> 32), (ULONG)(out & 0xffffffff), hres)
2132 static void test_VarI8FromI1(void)
2134 CONVVARS(signed char);
2135 int i;
2137 CHECKPTR(VarI8FromI1);
2138 for (i = -128; i < 128; i++)
2140 CONVERT(VarI8FromI1,i); EXPECTI8(i);
2144 static void test_VarI8FromUI1(void)
2146 CONVVARS(BYTE);
2147 int i;
2149 CHECKPTR(VarI8FromUI1);
2150 for (i = 0; i < 256; i++)
2152 CONVERT(VarI8FromUI1,i); EXPECTI8(i);
2156 static void test_VarI8FromI2(void)
2158 CONVVARS(SHORT);
2159 int i;
2161 CHECKPTR(VarI8FromI2);
2162 for (i = -32768; i < 32768; i++)
2164 CONVERT(VarI8FromI2,i); EXPECTI8(i);
2168 static void test_VarI8FromUI2(void)
2170 CONVVARS(USHORT);
2171 int i;
2173 CHECKPTR(VarI8FromUI2);
2174 for (i = -0; i < 65535; i++)
2176 CONVERT(VarI8FromUI2,i); EXPECTI8(i);
2180 static void test_VarI8FromUI4(void)
2182 CONVVARS(ULONG);
2184 CHECKPTR(VarI8FromUI4);
2185 CONVERT(VarI8FromUI4, 0); EXPECTI8(0);
2186 CONVERT(VarI8FromUI4, 1); EXPECTI8(1);
2187 CONVERT(VarI8FromUI4, 4294967295ul); EXPECTI8(4294967295ul);
2190 static void test_VarI8FromR4(void)
2192 CONVVARS(FLOAT);
2194 CHECKPTR(VarI8FromR4);
2196 CONVERT(VarI8FromR4, -128.0f); EXPECTI8(-128);
2197 CONVERT(VarI8FromR4, -1.0f); EXPECTI8(-1);
2198 CONVERT(VarI8FromR4, 0.0f); EXPECTI8(0);
2199 CONVERT(VarI8FromR4, 1.0f); EXPECTI8(1);
2200 CONVERT(VarI8FromR4, 127.0f); EXPECTI8(127);
2202 CONVERT(VarI8FromR4, -1.5f); EXPECTI8(-2);
2203 CONVERT(VarI8FromR4, -0.6f); EXPECTI8(-1);
2204 CONVERT(VarI8FromR4, -0.5f); EXPECTI8(0);
2205 CONVERT(VarI8FromR4, -0.4f); EXPECTI8(0);
2206 CONVERT(VarI8FromR4, 0.4f); EXPECTI8(0);
2207 CONVERT(VarI8FromR4, 0.5f); EXPECTI8(0);
2208 CONVERT(VarI8FromR4, 0.6f); EXPECTI8(1);
2209 CONVERT(VarI8FromR4, 1.5f); EXPECTI8(2);
2212 static void test_VarI8FromR8(void)
2214 CONVVARS(DOUBLE);
2216 CHECKPTR(VarI8FromR8);
2217 CONVERT(VarI8FromR8, -128.0); EXPECTI8(-128);
2218 CONVERT(VarI8FromR8, -1.0); EXPECTI8(-1);
2219 CONVERT(VarI8FromR8, 0.0); EXPECTI8(0);
2220 CONVERT(VarI8FromR8, 1.0); EXPECTI8(1);
2221 CONVERT(VarI8FromR8, 127.0); EXPECTI8(127);
2223 CONVERT(VarI8FromR8, -1.5); EXPECTI8(-2);
2224 CONVERT(VarI8FromR8, -0.6); EXPECTI8(-1);
2225 CONVERT(VarI8FromR8, -0.5); EXPECTI8(0);
2226 CONVERT(VarI8FromR8, -0.4); EXPECTI8(0);
2227 CONVERT(VarI8FromR8, 0.4); EXPECTI8(0);
2228 CONVERT(VarI8FromR8, 0.5); EXPECTI8(0);
2229 CONVERT(VarI8FromR8, 0.6); EXPECTI8(1);
2230 CONVERT(VarI8FromR8, 1.5); EXPECTI8(2);
2233 static void test_VarI8FromDate(void)
2235 CONVVARS(DATE);
2237 CHECKPTR(VarI8FromDate);
2238 CONVERT(VarI8FromDate, -128.0); EXPECTI8(-128);
2239 CONVERT(VarI8FromDate, -1.0); EXPECTI8(-1);
2240 CONVERT(VarI8FromDate, 0.0); EXPECTI8(0);
2241 CONVERT(VarI8FromDate, 1.0); EXPECTI8(1);
2242 CONVERT(VarI8FromDate, 127.0); EXPECTI8(127);
2244 CONVERT(VarI8FromDate, -1.5); EXPECTI8(-2);
2245 CONVERT(VarI8FromDate, -0.6); EXPECTI8(-1);
2246 CONVERT(VarI8FromDate, -0.5); EXPECTI8(0);
2247 CONVERT(VarI8FromDate, -0.4); EXPECTI8(0);
2248 CONVERT(VarI8FromDate, 0.4); EXPECTI8(0);
2249 CONVERT(VarI8FromDate, 0.5); EXPECTI8(0);
2250 CONVERT(VarI8FromDate, 0.6); EXPECTI8(1);
2251 CONVERT(VarI8FromDate, 1.5); EXPECTI8(2);
2254 static void test_VarI8FromBool(void)
2256 CONVVARS(VARIANT_BOOL);
2257 int i;
2259 CHECKPTR(VarI8FromBool);
2260 for (i = -32768; i < 32768; i++)
2262 CONVERT(VarI8FromBool,i); EXPECTI8(i);
2266 static void test_VarI8FromUI8(void)
2268 CONVVARS(ULONG64);
2270 CHECKPTR(VarI8FromUI8);
2271 CONVERT(VarI8FromUI8, 0); EXPECTI8(0);
2272 CONVERT(VarI8FromUI8, 1); EXPECTI8(1);
2273 CONVERT_I8(VarI8FromUI8, 0x7fffffff, 0xffffffff); EXPECTI864(0x7fffffff, 0xffffffff);
2274 CONVERT_I8(VarI8FromUI8, 0x80000000, 0); EXPECT_OVERFLOW;
2277 static void test_VarI8FromCy(void)
2279 CONVVARS(CY);
2281 CHECKPTR(VarI8FromCy);
2282 CONVERT_CY(VarI8FromCy,-128); EXPECTI8(-129);
2283 CONVERT_CY(VarI8FromCy,-1); EXPECTI8(-2);
2284 CONVERT_CY(VarI8FromCy,0); EXPECTI8(0);
2285 CONVERT_CY(VarI8FromCy,1); EXPECTI8(1);
2286 CONVERT_CY(VarI8FromCy,127); EXPECTI8(127);
2288 CONVERT_CY(VarI8FromCy,-1.5); EXPECTI8(-2);
2289 CONVERT_CY(VarI8FromCy,-0.6); EXPECTI8(-1);
2290 CONVERT_CY(VarI8FromCy,-0.5); EXPECTI8(-1);
2291 CONVERT_CY(VarI8FromCy,-0.4); EXPECTI8(-1);
2292 CONVERT_CY(VarI8FromCy,0.4); EXPECTI8(0);
2293 CONVERT_CY(VarI8FromCy,0.5); EXPECTI8(0);
2294 CONVERT_CY(VarI8FromCy,0.6); EXPECTI8(1);
2295 CONVERT_CY(VarI8FromCy,1.5); EXPECTI8(2);
2298 static void test_VarI8FromDec(void)
2300 CONVVARS(DECIMAL);
2302 CHECKPTR(VarI8FromDec);
2304 CONVERT_BADDEC(VarI8FromDec);
2306 CONVERT_DEC(VarI8FromDec,0,0x80,0,128); EXPECTI8(-128);
2307 CONVERT_DEC(VarI8FromDec,0,0x80,0,1); EXPECTI8(-1);
2308 CONVERT_DEC(VarI8FromDec,0,0,0,0); EXPECTI8(0);
2309 CONVERT_DEC(VarI8FromDec,0,0,0,1); EXPECTI8(1);
2310 CONVERT_DEC(VarI8FromDec,0,0,0,127); EXPECTI8(127);
2312 CONVERT_DEC(VarI8FromDec,2,0x80,0,12700); EXPECTI8(-127);
2313 CONVERT_DEC(VarI8FromDec,2,0,0,12700); EXPECTI8(127);
2316 static void test_VarI8FromStr(void)
2318 CONVVARS(LCID);
2319 OLECHAR buff[128];
2321 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2323 CHECKPTR(VarI8FromStr);
2325 CONVERT_STR(VarI8FromStr,NULL,0); EXPECT_MISMATCH;
2326 CONVERT_STR(VarI8FromStr,"0",0); EXPECTI8(0);
2327 CONVERT_STR(VarI8FromStr,"-1",0); EXPECTI8(-1);
2328 CONVERT_STR(VarI8FromStr,"2147483647",0); EXPECTI8(2147483647);
2330 CONVERT_STR(VarI8FromStr,"-1.5",0); EXPECTI8(-2);
2331 CONVERT_STR(VarI8FromStr,"-0.6",0); EXPECTI8(-1);
2332 CONVERT_STR(VarI8FromStr,"-0.5",0); EXPECTI8(0);
2333 CONVERT_STR(VarI8FromStr,"-0.4",0); EXPECTI8(0);
2334 CONVERT_STR(VarI8FromStr,"0.4",0); EXPECTI8(0);
2335 CONVERT_STR(VarI8FromStr,"0.5",0); EXPECTI8(0);
2336 CONVERT_STR(VarI8FromStr,"0.6",0); EXPECTI8(1);
2337 CONVERT_STR(VarI8FromStr,"1.5",0); EXPECTI8(2);
2340 static void test_VarI8Copy(void)
2342 HRESULT hres;
2343 VARIANTARG vSrc, vDst;
2344 LONGLONG in = 1;
2346 if (!HAVE_OLEAUT32_I8)
2347 return;
2349 VariantInit(&vSrc);
2350 VariantInit(&vDst);
2351 V_VT(&vSrc) = VT_I8;
2352 V_I8(&vSrc) = in;
2353 hres = VariantCopy(&vDst, &vSrc);
2354 ok(hres == S_OK && V_VT(&vDst) == VT_I8 && V_I8(&vDst) == in,
2355 "copy hres 0x%lX, type %d, value (%x%08x) %x%08x\n",
2356 hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_I8(&vDst) >> 32), (UINT)V_I8(&vDst) );
2357 V_VT(&vSrc) = VT_I8|VT_BYREF;
2358 V_I8REF(&vSrc) = &in;
2359 hres = VariantCopy(&vDst, &vSrc);
2360 ok(hres == S_OK && V_VT(&vDst) == (VT_I8|VT_BYREF) && V_I8REF(&vDst) == &in,
2361 "ref hres 0x%lX, type %d, ref (%p) %p\n", hres, V_VT(&vDst), &in, V_I8REF(&vDst));
2362 hres = VariantCopyInd(&vDst, &vSrc);
2363 ok(hres == S_OK && V_VT(&vDst) == VT_I8 && V_I8(&vDst) == in,
2364 "copy hres 0x%lX, type %d, value (%x%08x) %x%08x\n",
2365 hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_I8(&vDst) >> 32), (UINT)V_I8(&vDst) );
2368 static void test_VarI8ChangeTypeEx(void)
2370 CONVVARS(CONV_TYPE);
2371 VARIANTARG vSrc, vDst;
2373 if (!HAVE_OLEAUT32_I8)
2374 return;
2376 in = 1;
2378 INITIAL_TYPETESTI8(VT_I8, V_I8);
2379 COMMON_TYPETEST;
2382 /* Adapt the test macros to UI8 */
2383 #undef CONV_TYPE
2384 #define CONV_TYPE ULONG64
2386 static void test_VarUI8FromI1(void)
2388 CONVVARS(signed char);
2389 int i;
2391 CHECKPTR(VarUI8FromI1);
2392 for (i = -128; i < 128; i++)
2394 CONVERT(VarUI8FromI1,i);
2395 if (i < 0)
2396 EXPECT_OVERFLOW;
2397 else
2398 EXPECTI8(i);
2402 static void test_VarUI8FromUI1(void)
2404 CONVVARS(BYTE);
2405 int i;
2407 CHECKPTR(VarUI8FromUI1);
2408 for (i = 0; i < 256; i++)
2410 CONVERT(VarUI8FromUI1,i); EXPECTI8(i);
2414 static void test_VarUI8FromI2(void)
2416 CONVVARS(SHORT);
2417 int i;
2419 CHECKPTR(VarUI8FromI2);
2420 for (i = -32768; i < 32768; i++)
2422 CONVERT(VarUI8FromI2,i);
2423 if (i < 0)
2424 EXPECT_OVERFLOW;
2425 else
2426 EXPECTI8(i);
2430 static void test_VarUI8FromUI2(void)
2432 CONVVARS(USHORT);
2433 int i;
2435 CHECKPTR(VarUI8FromUI2);
2436 for (i = 0; i < 65535; i++)
2438 CONVERT(VarUI8FromUI2,i); EXPECTI8(i);
2442 static void test_VarUI8FromUI4(void)
2444 CONVVARS(ULONG);
2446 CHECKPTR(VarUI8FromUI4);
2447 CONVERT(VarUI8FromUI4, 0); EXPECTI8(0);
2448 CONVERT(VarUI8FromUI4, 0xffffffff); EXPECTI8(0xffffffff);
2451 static void test_VarUI8FromR4(void)
2453 CONVVARS(FLOAT);
2455 CHECKPTR(VarUI8FromR4);
2456 CONVERT(VarUI8FromR4, -1.0f); EXPECT_OVERFLOW;
2457 CONVERT(VarUI8FromR4, 0.0f); EXPECTI8(0);
2458 CONVERT(VarUI8FromR4, 1.0f); EXPECTI8(1);
2459 CONVERT(VarUI8FromR4, 255.0f); EXPECTI8(255);
2461 CONVERT(VarUI8FromR4, -1.5f); EXPECT_OVERFLOW;
2462 CONVERT(VarUI8FromR4, -0.6f); EXPECT_OVERFLOW;
2463 CONVERT(VarUI8FromR4, -0.5f); EXPECTI8(0);
2464 CONVERT(VarUI8FromR4, -0.4f); EXPECTI8(0);
2465 CONVERT(VarUI8FromR4, 0.4f); EXPECTI8(0);
2466 CONVERT(VarUI8FromR4, 0.5f); EXPECTI8(0);
2467 CONVERT(VarUI8FromR4, 0.6f); EXPECTI8(1);
2468 CONVERT(VarUI8FromR4, 1.5f); EXPECTI8(2);
2471 static void test_VarUI8FromR8(void)
2473 CONVVARS(DOUBLE);
2475 CHECKPTR(VarUI8FromR8);
2476 CONVERT(VarUI8FromR8, -1.0); EXPECT_OVERFLOW;
2477 CONVERT(VarUI8FromR8, 0.0); EXPECTI8(0);
2478 CONVERT(VarUI8FromR8, 1.0); EXPECTI8(1);
2479 CONVERT(VarUI8FromR8, 255.0); EXPECTI8(255);
2481 CONVERT(VarUI8FromR8, -1.5); EXPECT_OVERFLOW;
2482 CONVERT(VarUI8FromR8, -0.6); EXPECT_OVERFLOW;
2483 CONVERT(VarUI8FromR8, -0.5); EXPECTI8(0);
2484 CONVERT(VarUI8FromR8, -0.4); EXPECTI8(0);
2485 CONVERT(VarUI8FromR8, 0.4); EXPECTI8(0);
2486 CONVERT(VarUI8FromR8, 0.5); EXPECTI8(0);
2487 CONVERT(VarUI8FromR8, 0.6); EXPECTI8(1);
2488 CONVERT(VarUI8FromR8, 1.5); EXPECTI8(2);
2491 static void test_VarUI8FromDate(void)
2493 CONVVARS(DATE);
2495 CHECKPTR(VarUI8FromDate);
2496 CONVERT(VarUI8FromDate, -1.0); EXPECT_OVERFLOW;
2497 CONVERT(VarUI8FromDate, 0.0); EXPECTI8(0);
2498 CONVERT(VarUI8FromDate, 1.0); EXPECTI8(1);
2499 CONVERT(VarUI8FromDate, 255.0); EXPECTI8(255);
2501 CONVERT(VarUI8FromDate, -1.5); EXPECT_OVERFLOW;
2502 CONVERT(VarUI8FromDate, -0.6); EXPECT_OVERFLOW;
2503 CONVERT(VarUI8FromDate, -0.5); EXPECTI8(0);
2504 CONVERT(VarUI8FromDate, -0.4); EXPECTI8(0);
2505 CONVERT(VarUI8FromDate, 0.4); EXPECTI8(0);
2506 CONVERT(VarUI8FromDate, 0.5); EXPECTI8(0);
2507 CONVERT(VarUI8FromDate, 0.6); EXPECTI8(1);
2508 CONVERT(VarUI8FromDate, 1.5); EXPECTI8(2);
2511 static void test_VarUI8FromBool(void)
2513 CONVVARS(VARIANT_BOOL);
2514 int i;
2516 CHECKPTR(VarUI8FromBool);
2517 CONVERTRANGE(VarUI8FromBool, -32768, 32768);
2520 static void test_VarUI8FromI8(void)
2522 CONVVARS(LONG64);
2524 CHECKPTR(VarUI8FromI8);
2525 CONVERT(VarUI8FromI8, -1); EXPECT_OVERFLOW;
2526 CONVERT(VarUI8FromI8, 0); EXPECTI8(0);
2527 CONVERT(VarUI8FromI8, 1); EXPECTI8(1);
2530 static void test_VarUI8FromCy(void)
2532 CONVVARS(CY);
2534 CHECKPTR(VarUI8FromCy);
2535 CONVERT_CY(VarUI8FromCy,-1); EXPECT_OVERFLOW;
2536 CONVERT_CY(VarUI8FromCy,0); EXPECTI8(0);
2537 CONVERT_CY(VarUI8FromCy,1); EXPECTI8(1);
2538 CONVERT_CY(VarUI8FromCy,255); EXPECTI8(255);
2540 CONVERT_CY(VarUI8FromCy,-1.5); EXPECT_OVERFLOW;
2541 CONVERT_CY(VarUI8FromCy,-0.6); EXPECT_OVERFLOW;
2542 CONVERT_CY(VarUI8FromCy,-0.5); EXPECTI8(0);
2543 CONVERT_CY(VarUI8FromCy,-0.4); EXPECTI8(0);
2544 CONVERT_CY(VarUI8FromCy,0.4); EXPECTI8(0);
2545 CONVERT_CY(VarUI8FromCy,0.5); EXPECTI8(0);
2546 CONVERT_CY(VarUI8FromCy,0.6); EXPECTI8(1);
2547 CONVERT_CY(VarUI8FromCy,1.5); EXPECTI8(2);
2550 static void test_VarUI8FromDec(void)
2552 CONVVARS(DECIMAL);
2554 CHECKPTR(VarUI8FromDec);
2556 CONVERT_BADDEC(VarUI8FromDec);
2558 #if 0
2559 /* This returns 1 under native; Wine fixes this bug and returns overflow */
2560 CONVERT_DEC(VarUI8FromDec,0,0x80,0,1);
2561 #endif
2562 CONVERT_DEC(VarUI8FromDec,0,0,0,0); EXPECTI8(0);
2563 CONVERT_DEC(VarUI8FromDec,0,0,0,1); EXPECTI8(1);
2564 CONVERT_DEC(VarUI8FromDec,0,0,0,255); EXPECTI8(255);
2566 CONVERT_DEC(VarUI8FromDec,2,0x80,0,100); EXPECT_OVERFLOW;
2567 CONVERT_DEC(VarUI8FromDec,2,0,0,25500); EXPECTI8(255);
2570 static void test_VarUI8FromStr(void)
2572 CONVVARS(LCID);
2573 OLECHAR buff[128];
2575 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2577 CHECKPTR(VarUI8FromStr);
2579 CONVERT_STR(VarUI8FromStr,NULL,0); EXPECT_MISMATCH;
2580 CONVERT_STR(VarUI8FromStr,"0",0); EXPECTI8(0);
2581 CONVERT_STR(VarUI8FromStr,"-1",0); EXPECT_OVERFLOW;
2582 CONVERT_STR(VarUI8FromStr,"2147483647",0); EXPECTI8(2147483647);
2584 CONVERT_STR(VarUI8FromStr,"-1.5",0); EXPECT_OVERFLOW;
2585 CONVERT_STR(VarUI8FromStr,"-0.6",0); EXPECT_OVERFLOW;
2586 CONVERT_STR(VarUI8FromStr,"-0.5",0); EXPECTI8(0);
2587 CONVERT_STR(VarUI8FromStr,"-0.4",0); EXPECTI8(0);
2588 CONVERT_STR(VarUI8FromStr,"0.4",0); EXPECTI8(0);
2589 CONVERT_STR(VarUI8FromStr,"0.5",0); EXPECTI8(0);
2590 CONVERT_STR(VarUI8FromStr,"0.6",0); EXPECTI8(1);
2591 CONVERT_STR(VarUI8FromStr,"1.5",0); EXPECTI8(2);
2594 static void test_VarUI8Copy(void)
2596 HRESULT hres;
2597 VARIANTARG vSrc, vDst;
2598 ULONGLONG in = 1;
2600 if (!HAVE_OLEAUT32_I8)
2601 return;
2603 VariantInit(&vSrc);
2604 VariantInit(&vDst);
2605 V_VT(&vSrc) = VT_UI8;
2606 V_UI8(&vSrc) = in;
2607 hres = VariantCopy(&vDst, &vSrc);
2608 ok(hres == S_OK && V_VT(&vDst) == VT_UI8 && V_UI8(&vDst) == in,
2609 "copy hres 0x%lX, type %d, value (%x%08x) %x%08x\n",
2610 hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_UI8(&vDst) >> 32), (UINT)V_UI8(&vDst) );
2611 V_VT(&vSrc) = VT_UI8|VT_BYREF;
2612 V_UI8REF(&vSrc) = &in;
2613 hres = VariantCopy(&vDst, &vSrc);
2614 ok(hres == S_OK && V_VT(&vDst) == (VT_UI8|VT_BYREF) && V_UI8REF(&vDst) == &in,
2615 "ref hres 0x%lX, type %d, ref (%p) %p\n", hres, V_VT(&vDst), &in, V_UI8REF(&vDst));
2616 hres = VariantCopyInd(&vDst, &vSrc);
2617 ok(hres == S_OK && V_VT(&vDst) == VT_UI8 && V_UI8(&vDst) == in,
2618 "copy hres 0x%lX, type %d, value (%x%08x) %x%08x\n",
2619 hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_UI8(&vDst) >> 32), (UINT)V_UI8(&vDst) );
2622 static void test_VarUI8ChangeTypeEx(void)
2624 CONVVARS(CONV_TYPE);
2625 VARIANTARG vSrc, vDst;
2627 if (!HAVE_OLEAUT32_I8)
2628 return;
2630 in = 1;
2632 INITIAL_TYPETESTI8(VT_UI8, V_UI8);
2633 COMMON_TYPETEST;
2637 * VT_R4
2640 #undef CONV_TYPE
2641 #define CONV_TYPE float
2642 #undef EXPECTRES
2643 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%15.15f")
2645 static void test_VarR4FromI1(void)
2647 CONVVARS(signed char);
2648 int i;
2650 CHECKPTR(VarR4FromI1);
2651 CONVERTRANGE(VarR4FromI1, -128, 128);
2654 static void test_VarR4FromUI1(void)
2656 CONVVARS(BYTE);
2657 int i;
2659 CHECKPTR(VarR4FromUI1);
2660 CONVERTRANGE(VarR4FromUI1, 0, 256);
2663 static void test_VarR4FromI2(void)
2665 CONVVARS(SHORT);
2666 int i;
2668 CHECKPTR(VarR4FromI2);
2669 CONVERTRANGE(VarR4FromI2, -32768, 32768);
2672 static void test_VarR4FromUI2(void)
2674 CONVVARS(USHORT);
2675 int i;
2677 CHECKPTR(VarR4FromUI2);
2678 CONVERTRANGE(VarR4FromUI2, 0, 65536);
2681 static void test_VarR4FromI4(void)
2683 CONVVARS(int);
2685 CHECKPTR(VarR4FromI4);
2686 CONVERT(VarR4FromI4, -2147483647-1); EXPECT(-2147483648.0f);
2687 CONVERT(VarR4FromI4, -1); EXPECT(-1.0f);
2688 CONVERT(VarR4FromI4, 0); EXPECT(0.0f);
2689 CONVERT(VarR4FromI4, 1); EXPECT(1.0f);
2690 CONVERT(VarR4FromI4, 2147483647); EXPECT(2147483647.0f);
2693 static void test_VarR4FromUI4(void)
2695 CONVVARS(unsigned int);
2697 CHECKPTR(VarR4FromUI4);
2698 CONVERT(VarR4FromUI4, 0); EXPECT(0.0f);
2699 CONVERT(VarR4FromUI4, 1); EXPECT(1.0f);
2700 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
2701 CONVERT(VarR4FromUI4, 0xffffffff); EXPECT(4294967296.0f);
2702 #endif
2705 static void test_VarR4FromR8(void)
2707 CONVVARS(FLOAT);
2709 CHECKPTR(VarR4FromR8);
2710 CONVERT(VarR4FromR8, -1.0); EXPECT(-1.0f);
2711 CONVERT(VarR4FromR8, 0.0); EXPECT(0.0f);
2712 CONVERT(VarR4FromR8, 1.0); EXPECT(1.0f);
2713 CONVERT(VarR4FromR8, 1.5); EXPECT(1.5f);
2715 /* Skip rounding tests - no rounding is done */
2718 static void test_VarR4FromBool(void)
2720 CONVVARS(VARIANT_BOOL);
2722 CHECKPTR(VarR4FromBool);
2723 CONVERT(VarR4FromBool, VARIANT_TRUE); EXPECT(VARIANT_TRUE * 1.0f);
2724 CONVERT(VarR4FromBool, VARIANT_FALSE); EXPECT(VARIANT_FALSE * 1.0f);
2727 static void test_VarR4FromCy(void)
2729 CONVVARS(CY);
2731 CHECKPTR(VarR4FromCy);
2732 CONVERT_CY(VarR4FromCy,-32768); EXPECT(-32768.0f);
2733 CONVERT_CY(VarR4FromCy,-1); EXPECT(-1.0f);
2734 CONVERT_CY(VarR4FromCy,0); EXPECT(0.0f);
2735 CONVERT_CY(VarR4FromCy,1); EXPECT(1.0f);
2736 CONVERT_CY(VarR4FromCy,32768); EXPECT(32768.0f);
2738 CONVERT_CY(VarR4FromCy,-1.5); EXPECT(-1.5f);
2739 CONVERT_CY(VarR4FromCy,-0.6); EXPECT(-0.6f);
2740 CONVERT_CY(VarR4FromCy,-0.5); EXPECT(-0.5f);
2741 CONVERT_CY(VarR4FromCy,-0.4); EXPECT(-0.4f);
2742 CONVERT_CY(VarR4FromCy,0.4); EXPECT(0.4f);
2743 CONVERT_CY(VarR4FromCy,0.5); EXPECT(0.5f);
2744 CONVERT_CY(VarR4FromCy,0.6); EXPECT(0.6f);
2745 CONVERT_CY(VarR4FromCy,1.5); EXPECT(1.5f);
2748 static void test_VarR4FromI8(void)
2750 CONVVARS(LONG64);
2752 CHECKPTR(VarR4FromI8);
2753 CONVERT(VarR4FromI8, -1); EXPECT(-1.0f);
2754 CONVERT(VarR4FromI8, 0); EXPECT(0.0f);
2755 CONVERT(VarR4FromI8, 1); EXPECT(1.0f);
2758 static void test_VarR4FromUI8(void)
2760 CONVVARS(ULONG64);
2762 CHECKPTR(VarR4FromUI8);
2763 CONVERT(VarR4FromUI8, 0); EXPECT(0.0f);
2764 CONVERT(VarR4FromUI8, 1); EXPECT(1.0f);
2767 static void test_VarR4FromDec(void)
2769 CONVVARS(DECIMAL);
2771 CHECKPTR(VarR4FromDec);
2773 CONVERT_BADDEC(VarR4FromDec);
2775 CONVERT_DEC(VarR4FromDec,0,0x80,0,32768); EXPECT(-32768.0f);
2776 CONVERT_DEC(VarR4FromDec,0,0x80,0,1); EXPECT(-1.0f);
2777 CONVERT_DEC(VarR4FromDec,0,0,0,0); EXPECT(0.0f);
2778 CONVERT_DEC(VarR4FromDec,0,0,0,1); EXPECT(1.0f);
2779 CONVERT_DEC(VarR4FromDec,0,0,0,32767); EXPECT(32767.0f);
2781 CONVERT_DEC(VarR4FromDec,2,0x80,0,3276800); EXPECT(-32768.0f);
2782 CONVERT_DEC(VarR4FromDec,2,0,0,3276700); EXPECT(32767.0f);
2785 static void test_VarR4FromDate(void)
2787 CONVVARS(DATE);
2789 CHECKPTR(VarR4FromDate);
2790 CONVERT(VarR4FromDate, -1.0); EXPECT(-1.0f);
2791 CONVERT(VarR4FromDate, 0.0); EXPECT(0.0f);
2792 CONVERT(VarR4FromDate, 1.0); EXPECT(1.0f);
2795 static void test_VarR4FromStr(void)
2797 CONVVARS(LCID);
2798 OLECHAR buff[128];
2800 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2802 CHECKPTR(VarR4FromStr);
2804 CONVERT_STR(VarR4FromStr,NULL,0); EXPECT_MISMATCH;
2805 CONVERT_STR(VarR4FromStr,"-1", 0); EXPECT(-1.0f);
2806 CONVERT_STR(VarR4FromStr,"0", 0); EXPECT(0.0f);
2807 CONVERT_STR(VarR4FromStr,"1", 0); EXPECT(1.0f);
2809 CONVERT_STR(VarR4FromStr,"-1.5",0); EXPECT(-1.5f);
2810 CONVERT_STR(VarR4FromStr,"-0.6",0); EXPECT(-0.6f);
2811 CONVERT_STR(VarR4FromStr,"-0.5",0); EXPECT(-0.5f);
2812 CONVERT_STR(VarR4FromStr,"-0.4",0); EXPECT(-0.4f);
2813 CONVERT_STR(VarR4FromStr,"0.4",0); EXPECT(0.4f);
2814 CONVERT_STR(VarR4FromStr,"0.5",0); EXPECT(0.5f);
2815 CONVERT_STR(VarR4FromStr,"0.6",0); EXPECT(0.6f);
2816 CONVERT_STR(VarR4FromStr,"1.5",0); EXPECT(1.5f);
2819 static void test_VarR4Copy(void)
2821 COPYTEST(77665544.0f, VT_R4, V_R4(&vSrc), V_R4(&vDst), V_R4REF(&vSrc),V_R4REF(&vDst), "%15.15f");
2824 static void test_VarR4ChangeTypeEx(void)
2826 #ifdef HAS_UINT64_TO_FLOAT
2827 CONVVARS(CONV_TYPE);
2828 VARIANTARG vSrc, vDst;
2830 in = 1.0f;
2832 INITIAL_TYPETEST(VT_R4, V_R4, "%f");
2833 COMMON_TYPETEST;
2834 #endif
2838 * VT_R8
2841 #undef CONV_TYPE
2842 #define CONV_TYPE double
2843 #undef EXPECTRES
2844 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%15.15f")
2846 static void test_VarR8FromI1(void)
2848 CONVVARS(signed char);
2849 int i;
2851 CHECKPTR(VarR8FromI1);
2852 CONVERTRANGE(VarR8FromI1, -128, 128);
2855 static void test_VarR8FromUI1(void)
2857 CONVVARS(BYTE);
2858 int i;
2860 CHECKPTR(VarR8FromUI1);
2861 CONVERTRANGE(VarR8FromUI1, 0, 256);
2864 static void test_VarR8FromI2(void)
2866 CONVVARS(SHORT);
2867 int i;
2869 CHECKPTR(VarR8FromI2);
2870 CONVERTRANGE(VarR8FromI2, -32768, 32768);
2873 static void test_VarR8FromUI2(void)
2875 CONVVARS(USHORT);
2876 int i;
2878 CHECKPTR(VarR8FromUI2);
2879 CONVERTRANGE(VarR8FromUI2, 0, 65536);
2882 static void test_VarR8FromI4(void)
2884 CONVVARS(int);
2886 CHECKPTR(VarR8FromI4);
2887 CONVERT(VarR8FromI4, -2147483647-1); EXPECT(-2147483648.0);
2888 CONVERT(VarR8FromI4, -1); EXPECT(-1.0);
2889 CONVERT(VarR8FromI4, 0); EXPECT(0.0);
2890 CONVERT(VarR8FromI4, 1); EXPECT(1.0);
2891 CONVERT(VarR8FromI4, 0x7fffffff); EXPECT(2147483647.0);
2894 static void test_VarR8FromUI4(void)
2896 CONVVARS(unsigned int);
2898 CHECKPTR(VarR8FromUI4);
2899 CONVERT(VarR8FromUI4, 0); EXPECT(0.0);
2900 CONVERT(VarR8FromUI4, 1); EXPECT(1.0);
2901 CONVERT(VarR8FromUI4, 0xffffffff); EXPECT(4294967295.0);
2904 static void test_VarR8FromR4(void)
2906 CONVVARS(FLOAT);
2908 CHECKPTR(VarR8FromR4);
2909 CONVERT(VarR8FromR4, -1.0f); EXPECT(-1.0);
2910 CONVERT(VarR8FromR4, 0.0f); EXPECT(0.0);
2911 CONVERT(VarR8FromR4, 1.0f); EXPECT(1.0);
2912 CONVERT(VarR8FromR4, 1.5f); EXPECT(1.5);
2914 /* Skip rounding tests - no rounding is done */
2917 static void test_VarR8FromBool(void)
2919 CONVVARS(VARIANT_BOOL);
2921 CHECKPTR(VarR8FromBool);
2922 CONVERT(VarR8FromBool, VARIANT_TRUE); EXPECT(VARIANT_TRUE * 1.0);
2923 CONVERT(VarR8FromBool, VARIANT_FALSE); EXPECT(VARIANT_FALSE * 1.0);
2926 static void test_VarR8FromCy(void)
2928 CONVVARS(CY);
2930 CHECKPTR(VarR8FromCy);
2931 CONVERT_CY(VarR8FromCy,-32769); EXPECT(-32769.0);
2932 CONVERT_CY(VarR8FromCy,-32768); EXPECT(-32768.0);
2933 CONVERT_CY(VarR8FromCy,-1); EXPECT(-1.0);
2934 CONVERT_CY(VarR8FromCy,0); EXPECT(0.0);
2935 CONVERT_CY(VarR8FromCy,1); EXPECT(1.0);
2936 CONVERT_CY(VarR8FromCy,32767); EXPECT(32767.0);
2937 CONVERT_CY(VarR8FromCy,32768); EXPECT(32768.0);
2939 CONVERT_CY(VarR8FromCy,-1.5); EXPECT(-1.5);
2940 CONVERT_CY(VarR8FromCy,-0.6); EXPECT(-0.6);
2941 CONVERT_CY(VarR8FromCy,-0.5); EXPECT(-0.5);
2942 CONVERT_CY(VarR8FromCy,-0.4); EXPECT(-0.4);
2943 CONVERT_CY(VarR8FromCy,0.4); EXPECT(0.4);
2944 CONVERT_CY(VarR8FromCy,0.5); EXPECT(0.5);
2945 CONVERT_CY(VarR8FromCy,0.6); EXPECT(0.6);
2946 CONVERT_CY(VarR8FromCy,1.5); EXPECT(1.5);
2949 static void test_VarR8FromI8(void)
2951 CONVVARS(LONG64);
2953 CHECKPTR(VarR8FromI8);
2954 CONVERT(VarR8FromI8, -1); EXPECT(-1.0);
2955 CONVERT(VarR8FromI8, 0); EXPECT(0.0);
2956 CONVERT(VarR8FromI8, 1); EXPECT(1.0);
2957 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
2958 CONVERT_I8(VarR8FromI8, 0x7fffffff,0xffffffff); EXPECT(9223372036854775808.0);
2959 #endif
2962 static void test_VarR8FromUI8(void)
2964 CONVVARS(ULONG64);
2966 CHECKPTR(VarR8FromUI8);
2967 CONVERT(VarR8FromUI8, 0); EXPECT(0.0);
2968 CONVERT(VarR8FromUI8, 1); EXPECT(1.0);
2969 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
2970 CONVERT_I8(VarR8FromUI8, 0x80000000,0); EXPECT(9223372036854775808.0);
2971 #endif
2974 static void test_VarR8FromDec(void)
2976 CONVVARS(DECIMAL);
2978 CHECKPTR(VarR8FromDec);
2980 CONVERT_BADDEC(VarR8FromDec);
2982 CONVERT_DEC(VarR8FromDec,0,0x80,0,32768); EXPECT(-32768.0);
2983 CONVERT_DEC(VarR8FromDec,0,0x80,0,1); EXPECT(-1.0);
2984 CONVERT_DEC(VarR8FromDec,0,0,0,0); EXPECT(0.0);
2985 CONVERT_DEC(VarR8FromDec,0,0,0,1); EXPECT(1.0);
2986 CONVERT_DEC(VarR8FromDec,0,0,0,32767); EXPECT(32767.0);
2988 CONVERT_DEC(VarR8FromDec,2,0x80,0,3276800); EXPECT(-32768.0);
2989 CONVERT_DEC(VarR8FromDec,2,0,0,3276700); EXPECT(32767.0);
2992 static void test_VarR8FromDate(void)
2994 CONVVARS(DATE);
2996 CHECKPTR(VarR8FromDate);
2997 CONVERT(VarR8FromDate, -1.0); EXPECT(-1.0);
2998 CONVERT(VarR8FromDate, -0.0); EXPECT(0.0);
2999 CONVERT(VarR8FromDate, 1.0); EXPECT(1.0);
3002 static void test_VarR8FromStr(void)
3004 CONVVARS(LCID);
3005 OLECHAR buff[128];
3007 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
3009 CHECKPTR(VarR8FromStr);
3011 CONVERT_STR(VarR8FromStr,NULL,0); EXPECT_MISMATCH;
3012 CONVERT_STR(VarR8FromStr,"",0); EXPECT_MISMATCH;
3013 CONVERT_STR(VarR8FromStr," ",0); EXPECT_MISMATCH;
3015 CONVERT_STR(VarR8FromStr,"0",0); EXPECT(0.0);
3016 CONVERT_STR(VarR8FromStr,"-1.5",0); EXPECT(-1.5);
3017 CONVERT_STR(VarR8FromStr,"-0.6",0); EXPECT(-0.6);
3018 CONVERT_STR(VarR8FromStr,"-0.5",0); EXPECT(-0.5);
3019 CONVERT_STR(VarR8FromStr,"-0.4",0); EXPECT(-0.4);
3020 CONVERT_STR(VarR8FromStr,"0.4",0); EXPECT(0.4);
3021 CONVERT_STR(VarR8FromStr,"0.5",0); EXPECT(0.5);
3022 CONVERT_STR(VarR8FromStr,"0.6",0); EXPECT(0.6);
3023 CONVERT_STR(VarR8FromStr,"1.5",0); EXPECT(1.5);
3025 /* We already have exhaustive tests for number parsing, so skip those tests here */
3028 static void test_VarR8Copy(void)
3030 COPYTEST(77665544.0, VT_R8, V_R8(&vSrc), V_R8(&vDst), V_R8REF(&vSrc),V_R8REF(&vDst), "%16.16g");
3033 static void test_VarR8ChangeTypeEx(void)
3035 #ifdef HAS_UINT64_TO_FLOAT
3036 CONVVARS(CONV_TYPE);
3037 VARIANTARG vSrc, vDst;
3039 in = 1.0;
3041 INITIAL_TYPETEST(VT_R8, V_R8, "%g");
3042 COMMON_TYPETEST;
3043 #endif
3046 #define MATHRND(l, r) left = l; right = r; hres = pVarR8Round(left, right, &out)
3048 static void test_VarR8Round(void)
3050 HRESULT hres;
3051 double left = 0.0, out;
3052 int right;
3054 CHECKPTR(VarR8Round);
3055 MATHRND(0.5432, 5); EXPECT(0.5432);
3056 MATHRND(0.5432, 4); EXPECT(0.5432);
3057 MATHRND(0.5432, 3); EXPECT(0.543);
3058 MATHRND(0.5432, 2); EXPECT(0.54);
3059 MATHRND(0.5432, 1); EXPECT(0.5);
3060 MATHRND(0.5532, 0); EXPECT(1);
3061 MATHRND(0.5532, -1); EXPECT_INVALID;
3063 MATHRND(0.5568, 5); EXPECT(0.5568);
3064 MATHRND(0.5568, 4); EXPECT(0.5568);
3065 MATHRND(0.5568, 3); EXPECT(0.557);
3066 MATHRND(0.5568, 2); EXPECT(0.56);
3067 MATHRND(0.5568, 1); EXPECT(0.6);
3068 MATHRND(0.5568, 0); EXPECT(1);
3069 MATHRND(0.5568, -1); EXPECT_INVALID;
3071 MATHRND(0.4999, 0); EXPECT(0);
3072 MATHRND(0.5000, 0); EXPECT(0);
3073 MATHRND(0.5001, 0); EXPECT(1);
3074 MATHRND(1.4999, 0); EXPECT(1);
3075 MATHRND(1.5000, 0); EXPECT(2);
3076 MATHRND(1.5001, 0); EXPECT(2);
3080 * VT_DATE
3083 #undef CONV_TYPE
3084 #define CONV_TYPE DATE
3086 static void test_VarDateFromI1(void)
3088 CONVVARS(signed char);
3089 int i;
3091 CHECKPTR(VarDateFromI1);
3092 CONVERTRANGE(VarDateFromI1, -128, 128);
3095 static void test_VarDateFromUI1(void)
3097 CONVVARS(BYTE);
3098 int i;
3100 CHECKPTR(VarDateFromUI1);
3101 CONVERTRANGE(VarDateFromUI1, 0, 256);
3104 static void test_VarDateFromI2(void)
3106 CONVVARS(SHORT);
3107 int i;
3109 CHECKPTR(VarDateFromI2);
3110 CONVERTRANGE(VarDateFromI2, -32768, 32768);
3113 static void test_VarDateFromUI2(void)
3115 CONVVARS(USHORT);
3116 int i;
3118 CHECKPTR(VarDateFromUI2);
3119 CONVERTRANGE(VarDateFromUI2, 0, 65536);
3122 static void test_VarDateFromI4(void)
3124 CONVVARS(int);
3126 CHECKPTR(VarDateFromI4);
3127 CONVERT(VarDateFromI4, DATE_MIN-1);
3128 if (hres != DISP_E_TYPEMISMATCH) /* Early versions return this, incorrectly */
3129 EXPECT_OVERFLOW;
3130 CONVERT(VarDateFromI4, DATE_MIN); EXPECT(DATE_MIN);
3131 CONVERT(VarDateFromI4, -1); EXPECT(-1.0);
3132 CONVERT(VarDateFromI4, 0); EXPECT(0.0);
3133 CONVERT(VarDateFromI4, 1); EXPECT(1.0);
3134 CONVERT(VarDateFromI4, DATE_MAX); EXPECT(DATE_MAX);
3135 CONVERT(VarDateFromI4, DATE_MAX+1);
3136 if (hres != DISP_E_TYPEMISMATCH) /* Early versions return this, incorrectly */
3137 EXPECT_OVERFLOW;
3140 static void test_VarDateFromUI4(void)
3142 CONVVARS(unsigned int);
3144 CHECKPTR(VarDateFromUI4);
3145 CONVERT(VarDateFromUI4, 0); EXPECT(0.0);
3146 CONVERT(VarDateFromUI4, 1); EXPECT(1.0);
3147 CONVERT(VarDateFromUI4, DATE_MAX); EXPECT(DATE_MAX);
3148 CONVERT(VarDateFromUI4, DATE_MAX+1);
3149 if (hres != DISP_E_TYPEMISMATCH) /* Early versions return this, incorrectly */
3150 EXPECT_OVERFLOW;
3153 static void test_VarDateFromR4(void)
3155 CONVVARS(FLOAT);
3157 CHECKPTR(VarDateFromR4);
3158 CONVERT(VarDateFromR4, -1.0f); EXPECT(-1.0);
3159 CONVERT(VarDateFromR4, 0.0f); EXPECT(0.0);
3160 CONVERT(VarDateFromR4, 1.0f); EXPECT(1.0);
3161 CONVERT(VarDateFromR4, 1.5f); EXPECT(1.5);
3164 static void test_VarDateFromR8(void)
3166 CONVVARS(double);
3168 CHECKPTR(VarDateFromR8);
3169 CONVERT(VarDateFromR8, -1.0f); EXPECT(-1.0);
3170 CONVERT(VarDateFromR8, 0.0f); EXPECT(0.0);
3171 CONVERT(VarDateFromR8, 1.0f); EXPECT(1.0);
3172 CONVERT(VarDateFromR8, 1.5f); EXPECT(1.5);
3175 static void test_VarDateFromBool(void)
3177 CONVVARS(VARIANT_BOOL);
3179 CHECKPTR(VarDateFromBool);
3180 CONVERT(VarDateFromBool, VARIANT_TRUE); EXPECT(VARIANT_TRUE * 1.0);
3181 CONVERT(VarDateFromBool, VARIANT_FALSE); EXPECT(VARIANT_FALSE * 1.0);
3184 static void test_VarDateFromCy(void)
3186 CONVVARS(CY);
3188 CHECKPTR(VarDateFromCy);
3189 CONVERT_CY(VarDateFromCy,-32769); EXPECT(-32769.0);
3190 CONVERT_CY(VarDateFromCy,-32768); EXPECT(-32768.0);
3191 CONVERT_CY(VarDateFromCy,-1); EXPECT(-1.0);
3192 CONVERT_CY(VarDateFromCy,0); EXPECT(0.0);
3193 CONVERT_CY(VarDateFromCy,1); EXPECT(1.0);
3194 CONVERT_CY(VarDateFromCy,32767); EXPECT(32767.0);
3195 CONVERT_CY(VarDateFromCy,32768); EXPECT(32768.0);
3197 CONVERT_CY(VarDateFromCy,-1.5); EXPECT(-1.5);
3198 CONVERT_CY(VarDateFromCy,-0.6); EXPECT(-0.6);
3199 CONVERT_CY(VarDateFromCy,-0.5); EXPECT(-0.5);
3200 CONVERT_CY(VarDateFromCy,-0.4); EXPECT(-0.4);
3201 CONVERT_CY(VarDateFromCy,0.4); EXPECT(0.4);
3202 CONVERT_CY(VarDateFromCy,0.5); EXPECT(0.5);
3203 CONVERT_CY(VarDateFromCy,0.6); EXPECT(0.6);
3204 CONVERT_CY(VarDateFromCy,1.5); EXPECT(1.5);
3207 static void test_VarDateFromI8(void)
3209 CONVVARS(LONG64);
3211 CHECKPTR(VarDateFromI8);
3212 CONVERT(VarDateFromI8, DATE_MIN-1); EXPECT_OVERFLOW;
3213 CONVERT(VarDateFromI8, DATE_MIN); EXPECT(DATE_MIN);
3214 CONVERT(VarDateFromI8, -1); EXPECT(-1.0);
3215 CONVERT(VarDateFromI8, 0); EXPECT(0.0);
3216 CONVERT(VarDateFromI8, 1); EXPECT(1.0);
3217 CONVERT(VarDateFromI8, DATE_MAX); EXPECT(DATE_MAX);
3218 CONVERT(VarDateFromI8, DATE_MAX+1); EXPECT_OVERFLOW;
3221 static void test_VarDateFromUI8(void)
3223 CONVVARS(ULONG64);
3225 CHECKPTR(VarDateFromUI8);
3226 CONVERT(VarDateFromUI8, 0); EXPECT(0.0);
3227 CONVERT(VarDateFromUI8, 1); EXPECT(1.0);
3228 CONVERT(VarDateFromUI8, DATE_MAX); EXPECT(DATE_MAX);
3229 CONVERT(VarDateFromUI8, DATE_MAX+1); EXPECT_OVERFLOW;
3232 static void test_VarDateFromDec(void)
3234 CONVVARS(DECIMAL);
3236 CHECKPTR(VarDateFromDec);
3238 CONVERT_BADDEC(VarDateFromDec);
3240 CONVERT_DEC(VarDateFromDec,0,0x80,0,32768); EXPECT(-32768.0);
3241 CONVERT_DEC(VarDateFromDec,0,0x80,0,1); EXPECT(-1.0);
3242 CONVERT_DEC(VarDateFromDec,0,0,0,0); EXPECT(0.0);
3243 CONVERT_DEC(VarDateFromDec,0,0,0,1); EXPECT(1.0);
3244 CONVERT_DEC(VarDateFromDec,0,0,0,32767); EXPECT(32767.0);
3246 CONVERT_DEC(VarDateFromDec,2,0x80,0,3276800); EXPECT(-32768.0);
3247 CONVERT_DEC(VarDateFromDec,2,0,0,3276700); EXPECT(32767.0);
3250 #define DFS(str) \
3251 buff[0] = '\0'; out = 0.0; \
3252 if (str) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)); \
3253 hres = pVarDateFromStr(str ? buff : NULL,lcid,LOCALE_NOUSEROVERRIDE,&out)
3255 #define MKRELDATE(day,mth) st.wMonth = mth; st.wDay = day; \
3256 pSystemTimeToVariantTime(&st,&relative)
3258 static const char *BadDateStrings[] =
3260 "True", "False", /* Plain text */
3261 "0.", ".0", "-1.1", "1.1-", /* Partial specifications */
3262 "1;2;3", "1*2*3", "1@2@3", "1#2#3", "(1:2)","<1:2>","1|2|3", /* Bad chars */
3263 "0", "1", /* 1 element */
3264 "0.60", "24.00", "0:60", "24:00", "1 2 am", "1 am 2", /* 2 elements */
3265 "1.5 2", "1 5.2", "2 32 3", "1 2 am 3", /* 3 elements */
3266 "1 2.3 4", "1.2.3 4", "1 2.3.4", "1.2 3.4", "1.2.3.4", "1 2 3 4",
3267 "1 am 2 3.4", "1 2 am 3.4", "1.2 3 am 4", "1.2 3 4 am", /* 4 elements */
3268 "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",
3269 "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",
3270 "1.2.3 4 am 5", "1.2.3 4 5 am", "1.2 3 am 4 5",
3271 "1.2 3 4 am 5", "1.2 3 4 5 am", "1 am 2 3.4.5", "1 2 am 3.4.5",
3272 "1 am 2 3 4.5", "1 2 am 3 4.5", "1 2 3 am 4.5", /* 5 elements */
3273 /* 6 elements */
3274 "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",
3275 "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",
3276 "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",
3277 "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",
3278 "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",
3279 "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",
3280 "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",
3281 "1 2 am 3 4.5.6", "1 2 3 am 4.5.6"
3284 static void test_VarDateFromStr(void)
3286 LCID lcid;
3287 DATE out, relative;
3288 HRESULT hres;
3289 SYSTEMTIME st;
3290 OLECHAR buff[128];
3291 size_t i;
3293 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
3295 CHECKPTR(VarDateFromStr);
3296 CHECKPTR(SystemTimeToVariantTime);
3298 /* Some date formats are relative, so we need to find the cuurent year */
3299 GetSystemTime(&st);
3300 st.wHour = st.wMinute = st.wSecond = st.wMilliseconds = 0;
3301 DFS(NULL); EXPECT_MISMATCH;
3303 /* Floating point number are not recognised */
3304 DFS("0.0");
3305 if (hres == S_OK)
3306 EXPECT_DBL(0.0); /* Very old versions accept this string */
3307 else
3308 EXPECT_MISMATCH;
3310 /* 1 element - can only be a time, and only if it has am/pm */
3311 DFS("1 am"); EXPECT_DBL(0.04166666666666666);
3312 /* 2 elements */
3313 /* A decimal point is treated as a time separator.
3314 * The following are converted as hours/minutes.
3316 DFS("0.1"); EXPECT_DBL(0.0006944444444444445);
3317 DFS("0.40"); EXPECT_DBL(0.02777777777777778);
3318 DFS("2.5"); EXPECT_DBL(0.08680555555555555);
3319 /* A colon acts as a decimal point */
3320 DFS("0:1"); EXPECT_DBL(0.0006944444444444445);
3321 DFS("0:20"); EXPECT_DBL(0.01388888888888889);
3322 DFS("0:40"); EXPECT_DBL(0.02777777777777778);
3323 DFS("3:5"); EXPECT_DBL(0.1284722222222222);
3324 /* Check the am/pm limits */
3325 DFS("00:00 AM"); EXPECT_DBL(0.0);
3326 DFS("00:00 a"); EXPECT_DBL(0.0);
3327 DFS("12:59 AM"); EXPECT_DBL(0.04097222222222222);
3328 DFS("12:59 A"); EXPECT_DBL(0.04097222222222222);
3329 DFS("00:00 pm"); EXPECT_DBL(0.5);
3330 DFS("00:00 p"); EXPECT_DBL(0.5);
3331 DFS("12:59 pm"); EXPECT_DBL(0.5409722222222222);
3332 DFS("12:59 p"); EXPECT_DBL(0.5409722222222222);
3333 /* AM/PM is ignored if hours > 12 */
3334 DFS("13:00 AM"); EXPECT_DBL(0.5416666666666666);
3335 DFS("13:00 PM"); EXPECT_DBL(0.5416666666666666);
3337 /* Space, dash and slash all indicate a date format. */
3338 /* If both numbers are valid month values => month/day of current year */
3339 DFS("1 2"); MKRELDATE(2,1); EXPECT_DBL(relative);
3340 DFS("2 1"); MKRELDATE(1,2); EXPECT_DBL(relative);
3341 /* one number not valid month, is a valid day, other number valid month:
3342 * that number becomes the day.
3344 DFS("14 1"); MKRELDATE(14,1); EXPECT_DBL(relative);
3345 DFS("1 14"); EXPECT_DBL(relative);
3346 /* If the numbers can't be day/month, they are assumed to be year/month */
3347 DFS("30 2"); EXPECT_DBL(10990.0);
3348 DFS("2 30"); EXPECT_DBL(10990.0);
3349 DFS("32 49"); EXPECT_MISMATCH; /* Can't be any format */
3350 DFS("0 49"); EXPECT_MISMATCH; /* Can't be any format */
3351 /* If a month name is given the other number is the day */
3352 DFS("Jan 2"); MKRELDATE(2,1); EXPECT_DBL(relative);
3353 DFS("2 Jan"); EXPECT_DBL(relative);
3354 /* Unless it can't be, in which case it becomes the year */
3355 DFS("Jan 35"); EXPECT_DBL(12785.0);
3356 DFS("35 Jan"); EXPECT_DBL(12785.0);
3357 DFS("Jan-35"); EXPECT_DBL(12785.0);
3358 DFS("35-Jan"); EXPECT_DBL(12785.0);
3359 DFS("Jan/35"); EXPECT_DBL(12785.0);
3360 DFS("35/Jan"); EXPECT_DBL(12785.0);
3361 /* 3 elements */
3362 /* 3 numbers and time separator => h:m:s */
3363 DFS("0.1.0"); EXPECT_DBL(0.0006944444444444445);
3364 DFS("1.5.2"); EXPECT_DBL(0.04516203703703704);
3365 /* 3 numbers => picks date giving preference to lcid format */
3366 DFS("1 2 3"); EXPECT_DBL(37623.0);
3367 DFS("14 2 3"); EXPECT_DBL(41673.0);
3368 DFS("2 14 3"); EXPECT_DBL(37666.0);
3369 DFS("2 3 14"); EXPECT_DBL(41673.0);
3370 DFS("32 2 3"); EXPECT_DBL(11722.0);
3371 DFS("2 3 32"); EXPECT_DBL(11722.0);
3372 DFS("1 2 29"); EXPECT_DBL(47120.0);
3373 /* After 30, two digit dates are expected to be in the 1900's */
3374 DFS("1 2 30"); EXPECT_DBL(10960.0);
3375 DFS("1 2 31"); EXPECT_DBL(11325.0);
3376 DFS("3 am 1 2"); MKRELDATE(2,1); relative += 0.125; EXPECT_DBL(relative);
3377 DFS("1 2 3 am"); EXPECT_DBL(relative);
3379 /* 4 elements -interpreted as 2 digit date & time */
3380 DFS("1.2 3 4"); MKRELDATE(4,3); relative += 0.04305555556; EXPECT_DBL(relative);
3381 DFS("3 4 1.2"); EXPECT_DBL(relative);
3382 /* 5 elements - interpreted as 2 & 3 digit date/times */
3383 DFS("1.2.3 4 5"); MKRELDATE(5,4); relative += 0.04309027778; EXPECT_DBL(relative);
3384 DFS("1.2 3 4 5"); EXPECT_DBL(38415.04305555556);
3385 DFS("1 2 3.4.5"); MKRELDATE(2,1); relative += 0.12783564815; EXPECT_DBL(relative);
3386 DFS("1 2 3 4.5"); EXPECT_DBL(37623.17013888889);
3387 /* 6 elements - interpreted as 3 digit date/times */
3388 DFS("1.2.3 4 5 6"); EXPECT_DBL(38812.04309027778);
3389 DFS("1 2 3 4.5.6"); EXPECT_DBL(37623.17020833334);
3391 for (i = 0; i < sizeof(BadDateStrings)/sizeof(char*); i++)
3393 DFS(BadDateStrings[i]); EXPECT_MISMATCH;
3396 /* Some normal-ish strings */
3397 DFS("2 January, 1970"); EXPECT_DBL(25570.0);
3398 DFS("2 January 1970"); EXPECT_DBL(25570.0);
3399 DFS("2 Jan 1970"); EXPECT_DBL(25570.0);
3400 DFS("2/Jan/1970"); EXPECT_DBL(25570.0);
3401 DFS("2-Jan-1970"); EXPECT_DBL(25570.0);
3402 DFS("1 2 1970"); EXPECT_DBL(25570.0);
3403 DFS("1/2/1970"); EXPECT_DBL(25570.0);
3404 DFS("1-2-1970"); EXPECT_DBL(25570.0);
3405 /* Native fails "1999 January 3, 9AM". I consider that a bug in native */
3408 static void test_VarDateCopy(void)
3410 COPYTEST(77665544.0, VT_DATE, V_DATE(&vSrc), V_DATE(&vDst), V_DATEREF(&vSrc),
3411 V_DATEREF(&vDst), "%16.16g");
3414 static const char* wtoascii(LPWSTR lpszIn)
3416 static char buff[256];
3417 WideCharToMultiByte(CP_ACP, 0, lpszIn, -1, buff, sizeof(buff), NULL, NULL);
3418 return buff;
3421 static void test_VarDateChangeTypeEx(void)
3423 static const WCHAR sz25570[] = {
3424 '1','/','2','/','1','9','7','0','\0' };
3425 static const WCHAR sz25570_2[] = {
3426 '1','/','2','/','7','0','\0' };
3427 static const WCHAR sz25570Nls[] = {
3428 '1','/','2','/','1','9','7','0',' ','1','2',':','0','0',':','0','0',' ','A','M','\0' };
3429 CONVVARS(CONV_TYPE);
3430 VARIANTARG vSrc, vDst;
3431 LCID lcid;
3433 in = 1.0;
3435 #ifdef HAS_UINT64_TO_FLOAT
3436 INITIAL_TYPETEST(VT_DATE, V_DATE, "%g");
3437 COMMON_TYPETEST;
3438 #endif
3440 V_VT(&vDst) = VT_EMPTY;
3441 V_VT(&vSrc) = VT_DATE;
3442 V_DATE(&vSrc) = 25570.0;
3443 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
3445 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, VARIANT_NOUSEROVERRIDE, VT_BSTR);
3446 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && V_BSTR(&vDst) &&
3447 (!strcmpW(V_BSTR(&vDst), sz25570) || !strcmpW(V_BSTR(&vDst), sz25570_2)),
3448 "hres=0x%lX, type=%d (should be VT_BSTR), *bstr=%s\n",
3449 hres, V_VT(&vDst), V_BSTR(&vDst) ? wtoascii(V_BSTR(&vDst)) : "?");
3451 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
3452 if (HAVE_OLEAUT32_LOCALES)
3454 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, VARIANT_NOUSEROVERRIDE|VARIANT_USE_NLS, VT_BSTR);
3455 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && V_BSTR(&vDst) && !strcmpW(V_BSTR(&vDst), sz25570Nls),
3456 "hres=0x%lX, type=%d (should be VT_BSTR), *bstr=%s\n",
3457 hres, V_VT(&vDst), V_BSTR(&vDst) ? wtoascii(V_BSTR(&vDst)) : "?");
3462 * VT_CY
3465 #undef CONV_TYPE
3466 #define CONV_TYPE CY
3467 #undef EXPECTRES
3468 #define EXPECTRES(res, x) \
3469 ok(hres == S_OK || ((HRESULT)res != S_OK && hres == (HRESULT)res), \
3470 "expected hres " #x ", got hres=0x%08lx\n", hres)
3472 #define EXPECTCY(x) \
3473 ok((hres == S_OK && out.int64 == (LONGLONG)(x*CY_MULTIPLIER)), \
3474 "expected " #x "*CY_MULTIPLIER, got (%8lx %8lx); hres=0x%08lx\n", S(out).Hi, S(out).Lo, hres)
3476 #define EXPECTCY64(x,y) \
3477 ok(hres == S_OK && S(out).Hi == (long)x && S(out).Lo == y, \
3478 "expected " #x #y "(%lu,%lu), got (%lu,%lu); hres=0x%08lx\n", \
3479 (ULONG)(x), (ULONG)(y), S(out).Hi, S(out).Lo, hres)
3481 static void test_VarCyFromI1(void)
3483 CONVVARS(signed char);
3484 int i;
3486 CHECKPTR(VarCyFromI1);
3487 for (i = -128; i < 128; i++)
3489 CONVERT(VarCyFromI1,i); EXPECTCY(i);
3493 static void test_VarCyFromUI1(void)
3495 CONVVARS(BYTE);
3496 int i;
3498 CHECKPTR(VarCyFromUI1);
3499 for (i = 0; i < 256; i++)
3501 CONVERT(VarCyFromUI1,i); EXPECTCY(i);
3505 static void test_VarCyFromI2(void)
3507 CONVVARS(SHORT);
3508 int i;
3510 CHECKPTR(VarCyFromI2);
3511 for (i = -16384; i < 16384; i++)
3513 CONVERT(VarCyFromI2,i); EXPECTCY(i);
3517 static void test_VarCyFromUI2(void)
3519 CONVVARS(int);
3520 int i;
3522 CHECKPTR(VarCyFromUI2);
3523 for (i = 0; i < 32768; i++)
3525 CONVERT(VarCyFromUI2,i); EXPECTCY(i);
3529 static void test_VarCyFromI4(void)
3531 CONVVARS(int);
3533 CHECKPTR(VarCyFromI4);
3534 CONVERT(VarCyFromI4, -1); EXPECTCY(-1);
3535 CONVERT(VarCyFromI4, 0); EXPECTCY(0);
3536 CONVERT(VarCyFromI4, 1); EXPECTCY(1);
3537 CONVERT(VarCyFromI4, 0x7fffffff); EXPECTCY64(0x1387, 0xffffd8f0);
3538 CONVERT(VarCyFromI4, 0x80000000); EXPECTCY64(0xffffec78, 0);
3541 static void test_VarCyFromUI4(void)
3543 CONVVARS(unsigned int);
3545 CHECKPTR(VarCyFromUI4);
3546 CONVERT(VarCyFromUI4, 0); EXPECTCY(0);
3547 CONVERT(VarCyFromUI4, 1); EXPECTCY(1);
3548 CONVERT(VarCyFromUI4, 0x80000000); EXPECTCY64(5000, 0);
3551 static void test_VarCyFromR4(void)
3553 CONVVARS(FLOAT);
3555 CHECKPTR(VarCyFromR4);
3556 CONVERT(VarCyFromR4, -1.0f); EXPECTCY(-1);
3557 CONVERT(VarCyFromR4, 0.0f); EXPECTCY(0);
3558 CONVERT(VarCyFromR4, 1.0f); EXPECTCY(1);
3559 CONVERT(VarCyFromR4, 1.5f); EXPECTCY(1.5);
3561 CONVERT(VarCyFromR4, -1.5f); EXPECTCY(-1.5);
3562 CONVERT(VarCyFromR4, -0.6f); EXPECTCY(-0.6);
3563 CONVERT(VarCyFromR4, -0.5f); EXPECTCY(-0.5);
3564 CONVERT(VarCyFromR4, -0.4f); EXPECTCY(-0.4);
3565 CONVERT(VarCyFromR4, 0.4f); EXPECTCY(0.4);
3566 CONVERT(VarCyFromR4, 0.5f); EXPECTCY(0.5);
3567 CONVERT(VarCyFromR4, 0.6f); EXPECTCY(0.6);
3568 CONVERT(VarCyFromR4, 1.5f); EXPECTCY(1.5);
3569 CONVERT(VarCyFromR4, 1.00009f); EXPECTCY(1.0001);
3570 CONVERT(VarCyFromR4, -1.00001f); EXPECTCY(-1);
3571 CONVERT(VarCyFromR4, -1.00005f); EXPECTCY(-1);
3572 CONVERT(VarCyFromR4, -0.00009f); EXPECTCY(-0.0001);
3573 CONVERT(VarCyFromR4, -0.00005f); EXPECTCY(0);
3574 CONVERT(VarCyFromR4, -0.00001f); EXPECTCY(0);
3575 CONVERT(VarCyFromR4, 0.00001f); EXPECTCY(0);
3576 CONVERT(VarCyFromR4, 0.00005f); EXPECTCY(0);
3577 CONVERT(VarCyFromR4, 0.00009f); EXPECTCY(0.0001);
3578 CONVERT(VarCyFromR4, -1.00001f); EXPECTCY(-1);
3579 CONVERT(VarCyFromR4, -1.00005f); EXPECTCY(-1);
3580 CONVERT(VarCyFromR4, -1.00009f); EXPECTCY(-1.0001);
3583 static void test_VarCyFromR8(void)
3585 CONVVARS(DOUBLE);
3587 CHECKPTR(VarCyFromR8);
3589 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3590 /* Test our rounding is exactly the same. This fails if the special x86
3591 * code is taken out of VarCyFromR8.
3593 CONVERT(VarCyFromR8, -461168601842738.7904); EXPECTCY64(0xbfffffff, 0xffffff23);
3594 #endif
3596 CONVERT(VarCyFromR8, -4611686018427388416.1); EXPECT_OVERFLOW;
3597 CONVERT(VarCyFromR8, -1.0); EXPECTCY(-1);
3598 CONVERT(VarCyFromR8, -0.0); EXPECTCY(0);
3599 CONVERT(VarCyFromR8, 1.0); EXPECTCY(1);
3600 CONVERT(VarCyFromR8, 4611686018427387648.0); EXPECT_OVERFLOW;
3602 /* Rounding */
3603 CONVERT(VarCyFromR8, -1.5f); EXPECTCY(-1.5);
3604 CONVERT(VarCyFromR8, -0.6f); EXPECTCY(-0.6);
3605 CONVERT(VarCyFromR8, -0.5f); EXPECTCY(-0.5);
3606 CONVERT(VarCyFromR8, -0.4f); EXPECTCY(-0.4);
3607 CONVERT(VarCyFromR8, 0.4f); EXPECTCY(0.4);
3608 CONVERT(VarCyFromR8, 0.5f); EXPECTCY(0.5);
3609 CONVERT(VarCyFromR8, 0.6f); EXPECTCY(0.6);
3610 CONVERT(VarCyFromR8, 1.5f); EXPECTCY(1.5);
3611 CONVERT(VarCyFromR8, 1.00009f); EXPECTCY(1.0001);
3612 CONVERT(VarCyFromR8, -1.00001f); EXPECTCY(-1);
3613 CONVERT(VarCyFromR8, -1.00005f); EXPECTCY(-1);
3614 CONVERT(VarCyFromR8, -0.00009f); EXPECTCY(-0.0001);
3615 CONVERT(VarCyFromR8, -0.00005f); EXPECTCY(0);
3616 CONVERT(VarCyFromR8, -0.00001f); EXPECTCY(0);
3617 CONVERT(VarCyFromR8, 0.00001f); EXPECTCY(0);
3618 CONVERT(VarCyFromR8, 0.00005f); EXPECTCY(0);
3619 CONVERT(VarCyFromR8, 0.00009f); EXPECTCY(0.0001);
3620 CONVERT(VarCyFromR8, -1.00001f); EXPECTCY(-1);
3621 CONVERT(VarCyFromR8, -1.00005f); EXPECTCY(-1);
3622 CONVERT(VarCyFromR8, -1.00009f); EXPECTCY(-1.0001);
3625 static void test_VarCyFromBool(void)
3627 CONVVARS(VARIANT_BOOL);
3628 int i;
3630 CHECKPTR(VarCyFromBool);
3631 for (i = -32768; i < 32768; i++)
3633 CONVERT(VarCyFromBool, i); EXPECTCY(i);
3637 static void test_VarCyFromI8(void)
3639 CONVVARS(LONG64);
3641 CHECKPTR(VarCyFromI8);
3642 CONVERT_I8(VarCyFromI8, -214749, 2728163227ul); EXPECT_OVERFLOW;
3643 CONVERT_I8(VarCyFromI8, -214749, 2728163228ul); EXPECTCY64(2147483648ul,15808);
3644 CONVERT(VarCyFromI8, -1); EXPECTCY(-1);
3645 CONVERT(VarCyFromI8, 0); EXPECTCY(0);
3646 CONVERT(VarCyFromI8, 1); EXPECTCY(1);
3647 CONVERT_I8(VarCyFromI8, 214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3648 CONVERT_I8(VarCyFromI8, 214748, 1566804069); EXPECT_OVERFLOW;
3651 static void test_VarCyFromUI8(void)
3653 CONVVARS(ULONG64);
3655 CHECKPTR(VarCyFromUI8);
3656 CONVERT(VarCyFromUI8, 0); EXPECTCY(0);
3657 CONVERT(VarCyFromUI8, 1); EXPECTCY(1);
3658 CONVERT_I8(VarCyFromUI8, 214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3659 CONVERT_I8(VarCyFromUI8, 214748, 1566804069); EXPECT_OVERFLOW;
3662 static void test_VarCyFromDec(void)
3664 CONVVARS(DECIMAL);
3666 CHECKPTR(VarCyFromDec);
3668 CONVERT_BADDEC(VarCyFromDec);
3670 CONVERT_DEC(VarCyFromDec,0,0x80,0,1); EXPECTCY(-1);
3671 CONVERT_DEC(VarCyFromDec,0,0,0,0); EXPECTCY(0);
3672 CONVERT_DEC(VarCyFromDec,0,0,0,1); EXPECTCY(1);
3674 CONVERT_DEC64(VarCyFromDec,0,0,0,214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3675 CONVERT_DEC64(VarCyFromDec,0,0,0,214748, 1566804069); EXPECT_OVERFLOW;
3677 CONVERT_DEC(VarCyFromDec,2,0,0,100); EXPECTCY(1);
3678 CONVERT_DEC(VarCyFromDec,2,0x80,0,100); EXPECTCY(-1);
3679 CONVERT_DEC(VarCyFromDec,2,0x80,0,1); EXPECTCY(-0.01);
3680 CONVERT_DEC(VarCyFromDec,2,0,0,1); EXPECTCY(0.01);
3681 CONVERT_DEC(VarCyFromDec,2,0x80,0,1); EXPECTCY(-0.01);
3682 CONVERT_DEC(VarCyFromDec,2,0,0,999); EXPECTCY(9.99);
3683 CONVERT_DEC(VarCyFromDec,2,0x80,0,999); EXPECTCY(-9.99);
3684 CONVERT_DEC(VarCyFromDec,2,0,0,1500); EXPECTCY(15);
3685 CONVERT_DEC(VarCyFromDec,2,0x80,0,1500); EXPECTCY(-15);
3688 static void test_VarCyFromDate(void)
3690 CONVVARS(DATE);
3692 CHECKPTR(VarCyFromDate);
3694 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3695 CONVERT(VarCyFromR8, -461168601842738.7904); EXPECTCY64(0xbfffffff, 0xffffff23);
3696 #endif
3698 CONVERT(VarCyFromDate, -1.0); EXPECTCY(-1);
3699 CONVERT(VarCyFromDate, -0.0); EXPECTCY(0);
3700 CONVERT(VarCyFromDate, 1.0); EXPECTCY(1);
3701 CONVERT(VarCyFromDate, -4611686018427388416.1); EXPECT_OVERFLOW;
3702 CONVERT(VarCyFromDate, 4611686018427387648.0); EXPECT_OVERFLOW;
3704 /* Rounding */
3705 CONVERT(VarCyFromDate, -1.5f); EXPECTCY(-1.5);
3706 CONVERT(VarCyFromDate, -0.6f); EXPECTCY(-0.6);
3707 CONVERT(VarCyFromDate, -0.5f); EXPECTCY(-0.5);
3708 CONVERT(VarCyFromDate, -0.4f); EXPECTCY(-0.4);
3709 CONVERT(VarCyFromDate, 0.4f); EXPECTCY(0.4);
3710 CONVERT(VarCyFromDate, 0.5f); EXPECTCY(0.5);
3711 CONVERT(VarCyFromDate, 0.6f); EXPECTCY(0.6);
3712 CONVERT(VarCyFromDate, 1.5f); EXPECTCY(1.5);
3713 CONVERT(VarCyFromDate, 1.00009f); EXPECTCY(1.0001);
3714 CONVERT(VarCyFromDate, -1.00001f); EXPECTCY(-1);
3715 CONVERT(VarCyFromDate, -1.00005f); EXPECTCY(-1);
3716 CONVERT(VarCyFromDate, -0.00009f); EXPECTCY(-0.0001);
3717 CONVERT(VarCyFromDate, -0.00005f); EXPECTCY(0);
3718 CONVERT(VarCyFromDate, -0.00001f); EXPECTCY(0);
3719 CONVERT(VarCyFromDate, 0.00001f); EXPECTCY(0);
3720 CONVERT(VarCyFromDate, 0.00005f); EXPECTCY(0);
3721 CONVERT(VarCyFromDate, 0.00009f); EXPECTCY(0.0001);
3722 CONVERT(VarCyFromDate, -1.00001f); EXPECTCY(-1);
3723 CONVERT(VarCyFromDate, -1.00005f); EXPECTCY(-1);
3724 CONVERT(VarCyFromDate, -1.00009f); EXPECTCY(-1.0001);
3727 #define MATHVARS1 HRESULT hres; double left = 0.0; CY cyLeft, out
3728 #define MATHVARS2 MATHVARS1; double right = 0.0; CY cyRight
3729 #define MATH1(func, l) left = (double)l; pVarCyFromR8(left, &cyLeft); hres = p##func(cyLeft, &out)
3730 #define MATH2(func, l, r) left = (double)l; right = (double)r; \
3731 pVarCyFromR8(left, &cyLeft); pVarCyFromR8(right, &cyRight); \
3732 hres = p##func(cyLeft, cyRight, &out)
3734 static void test_VarCyAdd(void)
3736 MATHVARS2;
3738 CHECKPTR(VarCyAdd);
3739 MATH2(VarCyAdd, 0.5, 0.5); EXPECTCY(1);
3740 MATH2(VarCyAdd, 0.5, -0.4); EXPECTCY(0.1);
3741 MATH2(VarCyAdd, 0.5, -0.6); EXPECTCY(-0.1);
3742 MATH2(VarCyAdd, -0.5, -0.5); EXPECTCY(-1);
3743 MATH2(VarCyAdd, -922337203685476.0, -922337203685476.0); EXPECT_OVERFLOW;
3744 MATH2(VarCyAdd, -922337203685476.0, 922337203685476.0); EXPECTCY(0);
3745 MATH2(VarCyAdd, 922337203685476.0, -922337203685476.0); EXPECTCY(0);
3746 MATH2(VarCyAdd, 922337203685476.0, 922337203685476.0); EXPECT_OVERFLOW;
3749 static void test_VarCyMul(void)
3751 MATHVARS2;
3753 CHECKPTR(VarCyMul);
3754 MATH2(VarCyMul, 534443.0, 0.0); EXPECTCY(0);
3755 MATH2(VarCyMul, 0.5, 0.5); EXPECTCY(0.25);
3756 MATH2(VarCyMul, 0.5, -0.4); EXPECTCY(-0.2);
3757 MATH2(VarCyMul, 0.5, -0.6); EXPECTCY(-0.3);
3758 MATH2(VarCyMul, -0.5, -0.5); EXPECTCY(0.25);
3759 MATH2(VarCyMul, 922337203685476.0, 20000); EXPECT_OVERFLOW;
3762 static void test_VarCySub(void)
3764 MATHVARS2;
3766 CHECKPTR(VarCySub);
3767 MATH2(VarCySub, 0.5, 0.5); EXPECTCY(0);
3768 MATH2(VarCySub, 0.5, -0.4); EXPECTCY(0.9);
3769 MATH2(VarCySub, 0.5, -0.6); EXPECTCY(1.1);
3770 MATH2(VarCySub, -0.5, -0.5); EXPECTCY(0);
3771 MATH2(VarCySub, -922337203685476.0, -922337203685476.0); EXPECTCY(0);
3772 MATH2(VarCySub, -922337203685476.0, 922337203685476.0); EXPECT_OVERFLOW;
3773 MATH2(VarCySub, 922337203685476.0, -922337203685476.0); EXPECT_OVERFLOW;
3774 MATH2(VarCySub, 922337203685476.0, 922337203685476.0); EXPECTCY(0);
3777 static void test_VarCyAbs(void)
3779 MATHVARS1;
3781 CHECKPTR(VarCyAbs);
3782 MATH1(VarCyAbs, 0.5); EXPECTCY(0.5);
3783 MATH1(VarCyAbs, -0.5); EXPECTCY(0.5);
3784 MATH1(VarCyAbs, 922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3785 MATH1(VarCyAbs, -922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3788 static void test_VarCyNeg(void)
3790 MATHVARS1;
3792 CHECKPTR(VarCyNeg);
3793 MATH1(VarCyNeg, 0.5); EXPECTCY(-0.5);
3794 MATH1(VarCyNeg, -0.5); EXPECTCY(0.5);
3795 MATH1(VarCyNeg, 922337203685476.0); EXPECTCY64(2147483648ul,15808);
3796 MATH1(VarCyNeg, -922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3799 #define MATHMULI4(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3800 hres = pVarCyMulI4(cyLeft, right, &out)
3802 static void test_VarCyMulI4(void)
3804 MATHVARS1;
3805 LONG right;
3807 CHECKPTR(VarCyMulI4);
3808 MATHMULI4(534443.0, 0); EXPECTCY(0);
3809 MATHMULI4(0.5, 1); EXPECTCY(0.5);
3810 MATHMULI4(0.5, 2); EXPECTCY(1);
3811 MATHMULI4(922337203685476.0, 1); EXPECTCY64(2147483647ul,4294951488ul);
3812 MATHMULI4(922337203685476.0, 2); EXPECT_OVERFLOW;
3815 #define MATHMULI8(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3816 hres = pVarCyMulI8(cyLeft, right, &out)
3818 static void test_VarCyMulI8(void)
3820 MATHVARS1;
3821 LONG64 right;
3823 CHECKPTR(VarCyMulI8);
3824 MATHMULI8(534443.0, 0); EXPECTCY(0);
3825 MATHMULI8(0.5, 1); EXPECTCY(0.5);
3826 MATHMULI8(0.5, 2); EXPECTCY(1);
3827 MATHMULI8(922337203685476.0, 1); EXPECTCY64(2147483647ul,4294951488ul);
3828 MATHMULI8(922337203685476.0, 2); EXPECT_OVERFLOW;
3831 #define MATHCMP(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); pVarCyFromR8(right, &cyRight); \
3832 hres = pVarCyCmp(cyLeft, cyRight); out.int64 = hres
3834 static void test_VarCyCmp(void)
3836 MATHVARS2;
3838 CHECKPTR(VarCyCmp);
3839 MATHCMP(-1.0, -1.0); EXPECT_EQ;
3840 MATHCMP(-1.0, 0.0); EXPECT_LT;
3841 MATHCMP(-1.0, 1.0); EXPECT_LT;
3842 MATHCMP(-1.0, 2.0); EXPECT_LT;
3843 MATHCMP(0.0, 1.0); EXPECT_LT;
3844 MATHCMP(0.0, 0.0); EXPECT_EQ;
3845 MATHCMP(0.0, -1.0); EXPECT_GT;
3846 MATHCMP(1.0, -1.0); EXPECT_GT;
3847 MATHCMP(1.0, 0.0); EXPECT_GT;
3848 MATHCMP(1.0, 1.0); EXPECT_EQ;
3849 MATHCMP(1.0, 2.0); EXPECT_LT;
3852 #define MATHCMPR8(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3853 hres = pVarCyCmpR8(cyLeft, right); out.int64 = hres
3855 static void test_VarCyCmpR8(void)
3857 MATHVARS1;
3858 double right;
3860 CHECKPTR(VarCyCmpR8);
3861 MATHCMPR8(-1.0, -1.0); EXPECT_EQ;
3862 MATHCMPR8(-1.0, 0.0); EXPECT_LT;
3863 MATHCMPR8(-1.0, 1.0); EXPECT_LT;
3864 MATHCMPR8(-1.0, 2.0); EXPECT_LT;
3865 MATHCMPR8(0.0, 1.0); EXPECT_LT;
3866 MATHCMPR8(0.0, 0.0); EXPECT_EQ;
3867 MATHCMPR8(0.0, -1.0); EXPECT_GT;
3868 MATHCMPR8(1.0, -1.0); EXPECT_GT;
3869 MATHCMPR8(1.0, 0.0); EXPECT_GT;
3870 MATHCMPR8(1.0, 1.0); EXPECT_EQ;
3871 MATHCMPR8(1.0, 2.0); EXPECT_LT;
3874 #undef MATHRND
3875 #define MATHRND(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3876 hres = pVarCyRound(cyLeft, right, &out)
3878 static void test_VarCyRound(void)
3880 MATHVARS1;
3881 int right;
3883 CHECKPTR(VarCyRound);
3884 MATHRND(0.5432, 5); EXPECTCY(0.5432);
3885 MATHRND(0.5432, 4); EXPECTCY(0.5432);
3886 MATHRND(0.5432, 3); EXPECTCY(0.543);
3887 MATHRND(0.5432, 2); EXPECTCY(0.54);
3888 MATHRND(0.5432, 1); EXPECTCY(0.5);
3889 MATHRND(0.5532, 0); EXPECTCY(1);
3890 MATHRND(0.5532, -1); EXPECT_INVALID;
3892 MATHRND(0.5568, 5); EXPECTCY(0.5568);
3893 MATHRND(0.5568, 4); EXPECTCY(0.5568);
3894 MATHRND(0.5568, 3); EXPECTCY(0.557);
3895 MATHRND(0.5568, 2); EXPECTCY(0.56);
3896 MATHRND(0.5568, 1); EXPECTCY(0.6);
3897 MATHRND(0.5568, 0); EXPECTCY(1);
3898 MATHRND(0.5568, -1); EXPECT_INVALID;
3900 MATHRND(0.4999, 0); EXPECTCY(0);
3901 MATHRND(0.5000, 0); EXPECTCY(0);
3902 MATHRND(0.5001, 0); EXPECTCY(1);
3903 MATHRND(1.4999, 0); EXPECTCY(1);
3904 MATHRND(1.5000, 0); EXPECTCY(2);
3905 MATHRND(1.5001, 0); EXPECTCY(2);
3908 #define MATHFIX(l) left = l; pVarCyFromR8(left, &cyLeft); \
3909 hres = pVarCyFix(cyLeft, &out)
3911 static void test_VarCyFix(void)
3913 MATHVARS1;
3915 CHECKPTR(VarCyFix);
3916 MATHFIX(-1.0001); EXPECTCY(-1);
3917 MATHFIX(-1.4999); EXPECTCY(-1);
3918 MATHFIX(-1.5001); EXPECTCY(-1);
3919 MATHFIX(-1.9999); EXPECTCY(-1);
3920 MATHFIX(-0.0001); EXPECTCY(0);
3921 MATHFIX(-0.4999); EXPECTCY(0);
3922 MATHFIX(-0.5001); EXPECTCY(0);
3923 MATHFIX(-0.9999); EXPECTCY(0);
3924 MATHFIX(0.0001); EXPECTCY(0);
3925 MATHFIX(0.4999); EXPECTCY(0);
3926 MATHFIX(0.5001); EXPECTCY(0);
3927 MATHFIX(0.9999); EXPECTCY(0);
3928 MATHFIX(1.0001); EXPECTCY(1);
3929 MATHFIX(1.4999); EXPECTCY(1);
3930 MATHFIX(1.5001); EXPECTCY(1);
3931 MATHFIX(1.9999); EXPECTCY(1);
3934 #define MATHINT(l) left = l; pVarCyFromR8(left, &cyLeft); \
3935 hres = pVarCyInt(cyLeft, &out)
3937 static void test_VarCyInt(void)
3939 MATHVARS1;
3941 CHECKPTR(VarCyInt);
3942 MATHINT(-1.0001); EXPECTCY(-2);
3943 MATHINT(-1.4999); EXPECTCY(-2);
3944 MATHINT(-1.5001); EXPECTCY(-2);
3945 MATHINT(-1.9999); EXPECTCY(-2);
3946 MATHINT(-0.0001); EXPECTCY(-1);
3947 MATHINT(-0.4999); EXPECTCY(-1);
3948 MATHINT(-0.5001); EXPECTCY(-1);
3949 MATHINT(-0.9999); EXPECTCY(-1);
3950 MATHINT(0.0001); EXPECTCY(0);
3951 MATHINT(0.4999); EXPECTCY(0);
3952 MATHINT(0.5001); EXPECTCY(0);
3953 MATHINT(0.9999); EXPECTCY(0);
3954 MATHINT(1.0001); EXPECTCY(1);
3955 MATHINT(1.4999); EXPECTCY(1);
3956 MATHINT(1.5001); EXPECTCY(1);
3957 MATHINT(1.9999); EXPECTCY(1);
3961 * VT_DECIMAL
3964 #undef CONV_TYPE
3965 #define CONV_TYPE DECIMAL
3966 #undef EXPECTRES
3967 #define EXPECTRES(res, x) \
3968 ok(hres == S_OK || ((HRESULT)res != S_OK && hres == (HRESULT)res), \
3969 "expected hres " #x ", got hres=0x%08lx\n", hres)
3971 #define EXPECTDEC(scl, sgn, hi, lo) ok(hres == S_OK && \
3972 S(U(out)).scale == (BYTE)(scl) && S(U(out)).sign == (BYTE)(sgn) && \
3973 out.Hi32 == (ULONG)(hi) && U1(out).Lo64 == (ULONG64)(lo), \
3974 "expected (%d,%d,%d,(%lx %lx)), got (%d,%d,%ld,(%lx %lx)) hres 0x%08lx\n", \
3975 scl, sgn, hi, (LONG)((LONG64)(lo) >> 32), (LONG)((lo) & 0xffffffff), S(U(out)).scale, \
3976 S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres)
3978 #define EXPECTDEC64(scl, sgn, hi, mid, lo) ok(hres == S_OK && \
3979 S(U(out)).scale == (BYTE)(scl) && S(U(out)).sign == (BYTE)(sgn) && \
3980 out.Hi32 == (ULONG)(hi) && S1(U1(out)).Mid32 == (ULONG)(mid) && \
3981 S1(U1(out)).Lo32 == (ULONG)(lo), \
3982 "expected (%d,%d,%d,(%lx %lx)), got (%d,%d,%ld,(%lx %lx)) hres 0x%08lx\n", \
3983 scl, sgn, hi, (LONG)(mid), (LONG)(lo), S(U(out)).scale, \
3984 S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres)
3986 #define EXPECTDECI if (i < 0) EXPECTDEC(0, 0x80, 0, -i); else EXPECTDEC(0, 0, 0, i)
3988 static void test_VarDecFromI1(void)
3990 CONVVARS(signed char);
3991 int i;
3993 CHECKPTR(VarDecFromI1);
3994 for (i = -128; i < 128; i++)
3996 CONVERT(VarDecFromI1,i); EXPECTDECI;
4000 static void test_VarDecFromI2(void)
4002 CONVVARS(SHORT);
4003 int i;
4005 CHECKPTR(VarDecFromI2);
4006 for (i = -32768; i < 32768; i++)
4008 CONVERT(VarDecFromI2,i); EXPECTDECI;
4012 static void test_VarDecFromI4(void)
4014 CONVVARS(LONG);
4015 int i;
4017 CHECKPTR(VarDecFromI4);
4018 for (i = -32768; i < 32768; i++)
4020 CONVERT(VarDecFromI4,i); EXPECTDECI;
4024 static void test_VarDecFromI8(void)
4026 CONVVARS(LONG64);
4027 int i;
4029 CHECKPTR(VarDecFromI8);
4030 for (i = -32768; i < 32768; i++)
4032 CONVERT(VarDecFromI8,i); EXPECTDECI;
4036 static void test_VarDecFromUI1(void)
4038 CONVVARS(BYTE);
4039 int i;
4041 CHECKPTR(VarDecFromUI1);
4042 for (i = 0; i < 256; i++)
4044 CONVERT(VarDecFromUI1,i); EXPECTDECI;
4048 static void test_VarDecFromUI2(void)
4050 CONVVARS(USHORT);
4051 int i;
4053 CHECKPTR(VarDecFromUI2);
4054 for (i = 0; i < 65536; i++)
4056 CONVERT(VarDecFromUI2,i); EXPECTDECI;
4060 static void test_VarDecFromUI4(void)
4062 CONVVARS(ULONG);
4063 int i;
4065 CHECKPTR(VarDecFromUI4);
4066 for (i = 0; i < 65536; i++)
4068 CONVERT(VarDecFromUI4,i); EXPECTDECI;
4072 static void test_VarDecFromUI8(void)
4074 CONVVARS(ULONG64);
4075 int i;
4077 CHECKPTR(VarDecFromUI8);
4078 for (i = 0; i < 65536; i++)
4080 CONVERT(VarDecFromUI8,i); EXPECTDECI;
4084 static void test_VarDecFromBool(void)
4086 CONVVARS(SHORT);
4087 int i;
4089 CHECKPTR(VarDecFromBool);
4090 /* Test all possible type values. Note that the result is reduced to 0 or -1 */
4091 for (i = -32768; i < 0; i++)
4093 CONVERT(VarDecFromBool,i);
4094 if (i)
4095 EXPECTDEC(0,0x80,0,1);
4096 else
4097 EXPECTDEC(0,0,0,0);
4101 static void test_VarDecFromR4(void)
4103 CONVVARS(float);
4105 CHECKPTR(VarDecFromR4);
4107 CONVERT(VarDecFromR4,-0.6f); EXPECTDEC(1,0x80,0,6);
4108 CONVERT(VarDecFromR4,-0.5f); EXPECTDEC(1,0x80,0,5);
4109 CONVERT(VarDecFromR4,-0.4f); EXPECTDEC(1,0x80,0,4);
4110 CONVERT(VarDecFromR4,0.0f); EXPECTDEC(0,0,0,0);
4111 CONVERT(VarDecFromR4,0.4f); EXPECTDEC(1,0,0,4);
4112 CONVERT(VarDecFromR4,0.5f); EXPECTDEC(1,0,0,5);
4113 CONVERT(VarDecFromR4,0.6f); EXPECTDEC(1,0,0,6);
4116 static void test_VarDecFromR8(void)
4118 CONVVARS(double);
4120 CHECKPTR(VarDecFromR8);
4122 CONVERT(VarDecFromR8,-0.6); EXPECTDEC(1,0x80,0,6);
4123 CONVERT(VarDecFromR8,-0.5); EXPECTDEC(1,0x80,0,5);
4124 CONVERT(VarDecFromR8,-0.4); EXPECTDEC(1,0x80,0,4);
4125 CONVERT(VarDecFromR8,0.0); EXPECTDEC(0,0,0,0);
4126 CONVERT(VarDecFromR8,0.4); EXPECTDEC(1,0,0,4);
4127 CONVERT(VarDecFromR8,0.5); EXPECTDEC(1,0,0,5);
4128 CONVERT(VarDecFromR8,0.6); EXPECTDEC(1,0,0,6);
4131 static void test_VarDecFromDate(void)
4133 CONVVARS(DATE);
4135 CHECKPTR(VarDecFromDate);
4137 CONVERT(VarDecFromDate,-0.6); EXPECTDEC(1,0x80,0,6);
4138 CONVERT(VarDecFromDate,-0.5); EXPECTDEC(1,0x80,0,5);
4139 CONVERT(VarDecFromDate,-0.4); EXPECTDEC(1,0x80,0,4);
4140 CONVERT(VarDecFromDate,0.0); EXPECTDEC(0,0,0,0);
4141 CONVERT(VarDecFromDate,0.4); EXPECTDEC(1,0,0,4);
4142 CONVERT(VarDecFromDate,0.5); EXPECTDEC(1,0,0,5);
4143 CONVERT(VarDecFromDate,0.6); EXPECTDEC(1,0,0,6);
4146 static void test_VarDecFromStr(void)
4148 CONVVARS(LCID);
4149 OLECHAR buff[128];
4151 CHECKPTR(VarDecFromStr);
4153 in = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4155 CONVERT_STR(VarDecFromStr,NULL,0); EXPECT_MISMATCH;
4156 CONVERT_STR(VarDecFromStr,"-1", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0x80,0,1);
4157 CONVERT_STR(VarDecFromStr,"0", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0,0,0);
4158 CONVERT_STR(VarDecFromStr,"1", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0,0,1);
4159 CONVERT_STR(VarDecFromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECTDEC(1,0,0,5);
4162 static void test_VarDecFromCy(void)
4164 CONVVARS(CY);
4166 CHECKPTR(VarDecFromCy);
4168 CONVERT_CY(VarDecFromCy, -1); EXPECTDEC(4,0x80,0,10000);
4169 CONVERT_CY(VarDecFromCy, 0); EXPECTDEC(4,0,0,0);
4170 CONVERT_CY(VarDecFromCy, 1); EXPECTDEC(4,0,0,10000);
4171 CONVERT_CY(VarDecFromCy, 0.5); EXPECTDEC(4,0,0,5000);
4174 #undef MATHVARS1
4175 #define MATHVARS1 HRESULT hres; DECIMAL l, out
4176 #undef MATHVARS2
4177 #define MATHVARS2 MATHVARS1; DECIMAL r
4178 #undef MATH1
4179 #define MATH1(func) hres = p##func(&l, &out)
4180 #undef MATH2
4181 #define MATH2(func) hres = p##func(&l, &r, &out)
4183 static void test_VarDecAbs(void)
4185 MATHVARS1;
4187 CHECKPTR(VarDecAbs);
4188 SETDEC(l,0,0x80,0,1); MATH1(VarDecAbs); EXPECTDEC(0,0,0,1);
4189 SETDEC(l,0,0,0,0); MATH1(VarDecAbs); EXPECTDEC(0,0,0,0);
4190 SETDEC(l,0,0x80,0,0); MATH1(VarDecAbs); EXPECTDEC(0,0,0,0);
4191 SETDEC(l,0,0,0,1); MATH1(VarDecAbs); EXPECTDEC(0,0,0,1);
4193 /* Doesn't check for invalid input */
4194 SETDEC(l,0,0x7f,0,1); MATH1(VarDecAbs); EXPECTDEC(0,0x7f,0,1);
4195 SETDEC(l,0,0x80,29,1); MATH1(VarDecAbs); EXPECTDEC(0,0,29,1);
4198 static void test_VarDecNeg(void)
4200 MATHVARS1;
4202 CHECKPTR(VarDecNeg);
4203 SETDEC(l,0,0x80,0,1); MATH1(VarDecNeg); EXPECTDEC(0,0,0,1);
4204 SETDEC(l,0,0,0,0); MATH1(VarDecNeg); EXPECTDEC(0,0x80,0,0); /* '-0'! */
4205 SETDEC(l,0,0x80,0,0); MATH1(VarDecNeg); EXPECTDEC(0,0,0,0);
4206 SETDEC(l,0,0,0,1); MATH1(VarDecNeg); EXPECTDEC(0,0x80,0,1);
4208 /* Doesn't check for invalid input */
4209 SETDEC(l,0,0x7f,0,1); MATH1(VarDecNeg); EXPECTDEC(0,0xff,0,1);
4210 SETDEC(l,0,0x80,29,1); MATH1(VarDecNeg); EXPECTDEC(0,0,29,1);
4211 SETDEC(l,0,0,29,1); MATH1(VarDecNeg); EXPECTDEC(0,0x80,29,1);
4214 static void test_VarDecAdd(void)
4216 MATHVARS2;
4218 CHECKPTR(VarDecAdd);
4219 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecAdd); EXPECTDEC(0,0,0,0);
4220 SETDEC(l,0,0,0,0); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,1);
4221 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,1);
4223 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,0); MATH2(VarDecAdd); EXPECTDEC(0,0,0,1);
4224 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,2);
4225 SETDEC(l,0,0,0,1); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,0); /* '-0'! */
4226 SETDEC(l,0,0,0,1); SETDEC(r,0,0x80,0,2); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,1);
4228 SETDEC(l,0,0x80,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,1);
4229 SETDEC(l,0,0x80,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,0);
4230 SETDEC(l,0,0x80,0,1); SETDEC(r,0,0,0,2); MATH2(VarDecAdd); EXPECTDEC(0,0,0,1);
4231 SETDEC(l,0,0x80,0,1); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,2);
4232 SETDEC(l,0,0x80,0,2); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,1);
4234 SETDEC(l,0,0,0,0xffffffff); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,0xfffffffe);
4235 SETDEC(l,0,0,0,0xffffffff); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,(ULONG64)1 << 32);
4236 SETDEC(l,0,0,0,0xffffffff); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,(ULONG64)1 << 32);
4238 SETDEC64(l,0,0,0,0xffffffff,0); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC64(0,0,0,0xffffffff,1);
4239 SETDEC64(l,0,0,0,0xffffffff,0); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd);
4240 EXPECTDEC64(0,0,0,0xfffffffe,0xffffffff);
4242 SETDEC64(l,0,0,0,0xffffffff,0xffffffff); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,1,0);
4243 SETDEC64(l,0,0,0,0xffffffff,0xffffffff); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd);
4244 EXPECTDEC64(0,0,0,0xffffffff,0xfffffffe);
4246 SETDEC(l,0,0,0xffffffff,0); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0xffffffff,1);
4247 SETDEC(l,0,0,0xffffffff,0); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd);
4248 EXPECTDEC64(0,0,0xfffffffe,0xffffffff,0xffffffff);
4250 SETDEC64(l,0,0,0xffffffff,0xffffffff,0xffffffff);SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd);
4251 EXPECTDEC64(0,0,0xffffffff,0xffffffff,0xfffffffe);
4252 SETDEC64(l,0,0,0xffffffff,0xffffffff,0xffffffff);SETDEC(r,0,0,0,1); MATH2(VarDecAdd);
4253 ok(hres == DISP_E_OVERFLOW,"Expected overflow, got (%d,%d,%ld,(%8lx,%8lx)x) hres 0x%08lx\n",
4254 S(U(out)).scale, S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres);
4256 /* Promotes to the highest scale, so here the results are in the scale of 2 */
4257 SETDEC(l,2,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecAdd); EXPECTDEC(2,0,0,0);
4258 SETDEC(l,2,0,0,100); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(2,0,0,200);
4261 static void test_VarDecSub(void)
4263 MATHVARS2;
4265 CHECKPTR(VarDecSub);
4266 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecSub); EXPECTDEC(0,0x80,0,0);
4267 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecSub); EXPECTDEC(0,0x80,0,1);
4268 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecSub); EXPECTDEC(0,0x80,0,0);
4269 SETDEC(l,0,0,0,1); SETDEC(r,0,0x80,0,1); MATH2(VarDecSub); EXPECTDEC(0,0,0,2);
4272 static void test_VarDecCmp(void)
4274 MATHVARS1;
4276 CHECKPTR(VarDecCmp);
4277 SETDEC(l,0,0,0,1); SETDEC(out,0,0,0,1); MATH1(VarDecCmp); EXPECT_EQ;
4278 SETDEC(l,0,0,0,1); SETDEC(out,0,0,0,0); MATH1(VarDecCmp); EXPECT_GT;
4279 SETDEC(l,0,0,0,0); SETDEC(out,0,0,0,1); MATH1(VarDecCmp); EXPECT_LT;
4283 * VT_BOOL
4286 #undef CONV_TYPE
4287 #define CONV_TYPE VARIANT_BOOL
4288 #undef _EXPECTRES
4289 #define _EXPECTRES(res, x, fs) \
4290 ok((hres == S_OK && out == (CONV_TYPE)(x)) || ((HRESULT)res != S_OK && hres == (HRESULT)res), \
4291 "expected " #x ", got " fs "; hres=0x%08lx\n", out, hres)
4292 #undef EXPECTRES
4293 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%d")
4294 #undef CONVERTRANGE
4295 #define CONVERTRANGE(func,start,end) for (i = start; i < end; i++) { \
4296 CONVERT(func, i); if (i) { EXPECT(VARIANT_TRUE); } else { EXPECT(VARIANT_FALSE); } }
4298 static void test_VarBoolFromI1(void)
4300 CONVVARS(signed char);
4301 int i;
4303 CHECKPTR(VarBoolFromI1);
4304 CONVERTRANGE(VarBoolFromI1, -128, 128);
4307 static void test_VarBoolFromUI1(void)
4309 CONVVARS(BYTE);
4310 int i;
4312 CHECKPTR(VarBoolFromUI1);
4313 CONVERTRANGE(VarBoolFromUI1, 0, 256);
4316 static void test_VarBoolFromI2(void)
4318 CONVVARS(SHORT);
4319 int i;
4321 CHECKPTR(VarBoolFromI2);
4322 CONVERTRANGE(VarBoolFromI2, -32768, 32768);
4325 static void test_VarBoolFromUI2(void)
4327 CONVVARS(USHORT);
4328 int i;
4330 CHECKPTR(VarBoolFromUI2);
4331 CONVERTRANGE(VarBoolFromUI2, 0, 65536);
4334 static void test_VarBoolFromI4(void)
4336 CONVVARS(int);
4338 CHECKPTR(VarBoolFromI4);
4339 CONVERT(VarBoolFromI4, 0x80000000); EXPECT(VARIANT_TRUE);
4340 CONVERT(VarBoolFromI4, -1); EXPECT(VARIANT_TRUE);
4341 CONVERT(VarBoolFromI4, 0); EXPECT(VARIANT_FALSE);
4342 CONVERT(VarBoolFromI4, 1); EXPECT(VARIANT_TRUE);
4343 CONVERT(VarBoolFromI4, 0x7fffffff); EXPECT(VARIANT_TRUE);
4346 static void test_VarBoolFromUI4(void)
4348 CONVVARS(ULONG);
4350 CHECKPTR(VarBoolFromUI4);
4351 CONVERT(VarBoolFromI4, 0); EXPECT(VARIANT_FALSE);
4352 CONVERT(VarBoolFromI4, 1); EXPECT(VARIANT_TRUE);
4353 CONVERT(VarBoolFromI4, 0x80000000); EXPECT(VARIANT_TRUE);
4356 static void test_VarBoolFromR4(void)
4358 CONVVARS(FLOAT);
4360 CHECKPTR(VarBoolFromR4);
4361 CONVERT(VarBoolFromR4, -1.0f); EXPECT(VARIANT_TRUE);
4362 CONVERT(VarBoolFromR4, 0.0f); EXPECT(VARIANT_FALSE);
4363 CONVERT(VarBoolFromR4, 1.0f); EXPECT(VARIANT_TRUE);
4364 CONVERT(VarBoolFromR4, 1.5f); EXPECT(VARIANT_TRUE);
4366 /* Rounding */
4367 CONVERT(VarBoolFromR4, -1.5f); EXPECT(VARIANT_TRUE);
4368 CONVERT(VarBoolFromR4, -0.6f); EXPECT(VARIANT_TRUE);
4369 CONVERT(VarBoolFromR4, -0.5f); EXPECT(VARIANT_TRUE);
4370 CONVERT(VarBoolFromR4, -0.4f); EXPECT(VARIANT_TRUE);
4371 CONVERT(VarBoolFromR4, 0.4f); EXPECT(VARIANT_TRUE);
4372 CONVERT(VarBoolFromR4, 0.5f); EXPECT(VARIANT_TRUE);
4373 CONVERT(VarBoolFromR4, 0.6f); EXPECT(VARIANT_TRUE);
4374 CONVERT(VarBoolFromR4, 1.5f); EXPECT(VARIANT_TRUE);
4377 static void test_VarBoolFromR8(void)
4379 CONVVARS(DOUBLE);
4381 /* Hopefully we made the point with R4 above that rounding is
4382 * irrelevant, so we'll skip that for R8 and Date
4384 CHECKPTR(VarBoolFromR8);
4385 CONVERT(VarBoolFromR8, -1.0); EXPECT(VARIANT_TRUE);
4386 CONVERT(VarBoolFromR8, -0.0); EXPECT(VARIANT_FALSE);
4387 CONVERT(VarBoolFromR8, 1.0); EXPECT(VARIANT_TRUE);
4390 static void test_VarBoolFromCy(void)
4392 CONVVARS(CY);
4394 CHECKPTR(VarBoolFromCy);
4395 CONVERT_CY(VarBoolFromCy, -32769); EXPECT(VARIANT_TRUE);
4396 CONVERT_CY(VarBoolFromCy, -32768); EXPECT(VARIANT_TRUE);
4397 CONVERT_CY(VarBoolFromCy, -1); EXPECT(VARIANT_TRUE);
4398 CONVERT_CY(VarBoolFromCy, 0); EXPECT(VARIANT_FALSE);
4399 CONVERT_CY(VarBoolFromCy, 1); EXPECT(VARIANT_TRUE);
4400 CONVERT_CY(VarBoolFromCy, 32767); EXPECT(VARIANT_TRUE);
4401 CONVERT_CY(VarBoolFromCy, 32768); EXPECT(VARIANT_TRUE);
4404 static void test_VarBoolFromI8(void)
4406 CONVVARS(LONG64);
4408 CHECKPTR(VarBoolFromI8);
4409 CONVERT(VarBoolFromI8, -1); EXPECT(VARIANT_TRUE);
4410 CONVERT(VarBoolFromI8, 0); EXPECT(VARIANT_FALSE);
4411 CONVERT(VarBoolFromI8, 1); EXPECT(VARIANT_TRUE);
4414 static void test_VarBoolFromUI8(void)
4416 CONVVARS(ULONG64);
4418 CHECKPTR(VarBoolFromUI8);
4419 CONVERT(VarBoolFromUI8, 0); EXPECT(VARIANT_FALSE);
4420 CONVERT(VarBoolFromUI8, 1); EXPECT(VARIANT_TRUE);
4423 static void test_VarBoolFromDec(void)
4425 CONVVARS(DECIMAL);
4427 CHECKPTR(VarBoolFromDec);
4428 CONVERT_BADDEC(VarBoolFromDec);
4430 if (HAVE_OLEAUT32_DECIMAL)
4432 /* Early versions of oleaut32 don't catch these errors */
4433 CONVERT_DEC(VarBoolFromDec,29,0,0,0); EXPECT_INVALID;
4434 CONVERT_DEC(VarBoolFromDec,0,0x1,0,0); EXPECT_INVALID;
4435 CONVERT_DEC(VarBoolFromDec,0,0x40,0,0); EXPECT_INVALID;
4436 CONVERT_DEC(VarBoolFromDec,0,0x7f,0,0); EXPECT_INVALID;
4439 CONVERT_DEC(VarBoolFromDec,0,0x80,0,1); EXPECT(VARIANT_TRUE);
4440 CONVERT_DEC(VarBoolFromDec,0,0,0,0); EXPECT(VARIANT_FALSE);
4441 CONVERT_DEC(VarBoolFromDec,0,0,0,1); EXPECT(VARIANT_TRUE);
4442 CONVERT_DEC(VarBoolFromDec,0,0,1,0); EXPECT(VARIANT_TRUE);
4444 CONVERT_DEC(VarBoolFromDec,2,0,0,CY_MULTIPLIER); EXPECT(VARIANT_TRUE);
4445 CONVERT_DEC(VarBoolFromDec,2,0x80,0,CY_MULTIPLIER); EXPECT(VARIANT_TRUE);
4448 static void test_VarBoolFromDate(void)
4450 CONVVARS(DATE);
4452 CHECKPTR(VarBoolFromDate);
4453 CONVERT(VarBoolFromDate, -1.0); EXPECT(VARIANT_TRUE);
4454 CONVERT(VarBoolFromDate, -0.0); EXPECT(VARIANT_FALSE);
4455 CONVERT(VarBoolFromDate, 1.0); EXPECT(VARIANT_TRUE);
4458 static void test_VarBoolFromStr(void)
4460 CONVVARS(LCID);
4461 OLECHAR buff[128];
4463 CHECKPTR(VarBoolFromStr);
4465 in = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4467 CONVERT_STR(VarBoolFromStr,NULL,0);
4468 if (hres != E_INVALIDARG)
4469 EXPECT_MISMATCH;
4471 /* #FALSE# and #TRUE# Are always accepted */
4472 CONVERT_STR(VarBoolFromStr,"#FALSE#",0); EXPECT(VARIANT_FALSE);
4473 CONVERT_STR(VarBoolFromStr,"#TRUE#",0); EXPECT(VARIANT_TRUE);
4475 /* Match of #FALSE# and #TRUE# is case sensitive */
4476 CONVERT_STR(VarBoolFromStr,"#False#",0); EXPECT_MISMATCH;
4477 /* But match against English is not */
4478 CONVERT_STR(VarBoolFromStr,"false",0); EXPECT(VARIANT_FALSE);
4479 CONVERT_STR(VarBoolFromStr,"False",0); EXPECT(VARIANT_FALSE);
4480 /* On/Off and yes/no are not acceptable inputs, with any flags set */
4481 CONVERT_STR(VarBoolFromStr,"On",0xffffffff); EXPECT_MISMATCH;
4482 CONVERT_STR(VarBoolFromStr,"Yes",0xffffffff); EXPECT_MISMATCH;
4484 /* Change the LCID. This doesn't make any difference for text,unless we ask
4485 * to check local boolean text with the VARIANT_LOCALBOOL flag. */
4486 in = MAKELCID(MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT), SORT_DEFAULT);
4488 /* #FALSE# and #TRUE# are accepted in all locales */
4489 CONVERT_STR(VarBoolFromStr,"#FALSE#",0); EXPECT(VARIANT_FALSE);
4490 CONVERT_STR(VarBoolFromStr,"#TRUE#",0); EXPECT(VARIANT_TRUE);
4491 CONVERT_STR(VarBoolFromStr,"#FALSE#",VARIANT_LOCALBOOL); EXPECT(VARIANT_FALSE);
4492 CONVERT_STR(VarBoolFromStr,"#TRUE#",VARIANT_LOCALBOOL); EXPECT(VARIANT_TRUE);
4494 /* English is accepted regardless of the locale */
4495 CONVERT_STR(VarBoolFromStr,"false",0); EXPECT(VARIANT_FALSE);
4496 /* And is still not case sensitive */
4497 CONVERT_STR(VarBoolFromStr,"False",0); EXPECT(VARIANT_FALSE);
4499 if (HAVE_OLEAUT32_LOCALES)
4501 /* French is rejected without VARIANT_LOCALBOOL */
4502 CONVERT_STR(VarBoolFromStr,"faux",0); EXPECT_MISMATCH;
4503 /* But accepted if this flag is given */
4504 CONVERT_STR(VarBoolFromStr,"faux",VARIANT_LOCALBOOL); EXPECT(VARIANT_FALSE);
4505 /* Regardless of case - from this we assume locale text comparisons ignore case */
4506 CONVERT_STR(VarBoolFromStr,"Faux",VARIANT_LOCALBOOL); EXPECT(VARIANT_FALSE);
4508 /* Changing the locale prevents the localised text from being compared -
4509 * this demonstrates that only the indicated LCID and English are searched */
4510 in = MAKELCID(MAKELANGID(LANG_POLISH, SUBLANG_DEFAULT), SORT_DEFAULT);
4511 CONVERT_STR(VarBoolFromStr,"faux",VARIANT_LOCALBOOL); EXPECT_MISMATCH;
4514 /* Numeric strings are read as 0 or non-0 */
4515 CONVERT_STR(VarBoolFromStr,"0",0); EXPECT(VARIANT_FALSE);
4516 CONVERT_STR(VarBoolFromStr,"-1",0); EXPECT(VARIANT_TRUE);
4517 CONVERT_STR(VarBoolFromStr,"+1",0); EXPECT(VARIANT_TRUE);
4519 if (HAVE_OLEAUT32_LOCALES)
4521 /* Numeric strings are read as floating point numbers. The line below fails
4522 * because '.' is not a valid decimal separator for Polish numbers */
4523 CONVERT_STR(VarBoolFromStr,"0.1",0); EXPECT_MISMATCH;
4526 /* Changing the lcid back to US English reads the r8 correctly */
4527 in = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4528 CONVERT_STR(VarBoolFromStr,"0.1",0); EXPECT(VARIANT_TRUE);
4531 static void test_VarBoolCopy(void)
4533 COPYTEST(1, VT_BOOL, V_BOOL(&vSrc), V_BOOL(&vDst), V_BOOLREF(&vSrc), V_BOOLREF(&vDst), "%d");
4536 #define BOOL_STR(flags, str) hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, flags, VT_BSTR); \
4537 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && \
4538 V_BSTR(&vDst) && !memcmp(V_BSTR(&vDst), str, sizeof(str)), \
4539 "hres=0x%lX, type=%d (should be VT_BSTR), *bstr='%c'\n", \
4540 hres, V_VT(&vDst), V_BSTR(&vDst) ? *V_BSTR(&vDst) : '?')
4542 static void test_VarBoolChangeTypeEx(void)
4544 static const WCHAR szTrue[] = { 'T','r','u','e','\0' };
4545 static const WCHAR szFalse[] = { 'F','a','l','s','e','\0' };
4546 static const WCHAR szFaux[] = { 'F','a','u','x','\0' };
4547 CONVVARS(CONV_TYPE);
4548 VARIANTARG vSrc, vDst;
4549 LCID lcid;
4551 in = 1;
4553 INITIAL_TYPETEST(VT_BOOL, V_BOOL, "%d");
4554 COMMON_TYPETEST;
4556 /* The common tests convert to a number. Try the different flags */
4557 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4559 V_VT(&vSrc) = VT_BOOL;
4560 V_BOOL(&vSrc) = 1;
4562 if (!IS_ANCIENT)
4564 BOOL_STR(VARIANT_ALPHABOOL, szTrue);
4565 V_BOOL(&vSrc) = 0;
4566 BOOL_STR(VARIANT_ALPHABOOL, szFalse);
4569 if (HAVE_OLEAUT32_LOCALES)
4571 lcid = MAKELCID(MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT), SORT_DEFAULT);
4573 /* VARIANT_ALPHABOOL is always English */
4574 BOOL_STR(VARIANT_ALPHABOOL, szFalse);
4575 /* VARIANT_LOCALBOOL uses the localised text */
4576 BOOL_STR(VARIANT_LOCALBOOL, szFaux);
4577 /* Both flags together acts as VARIANT_LOCALBOOL */
4578 BOOL_STR(VARIANT_ALPHABOOL|VARIANT_LOCALBOOL, szFaux);
4583 * BSTR
4586 static void test_VarBstrFromR4(void)
4588 static const WCHAR szNative[] = { '6','5','4','3','2','2','.','3','\0' };
4589 LCID lcid;
4590 HRESULT hres;
4591 BSTR bstr = NULL;
4593 float f;
4595 CHECKPTR(VarBstrFromR4);
4597 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4598 f = 654322.23456f;
4599 hres = pVarBstrFromR4(f, lcid, 0, &bstr);
4600 ok(hres == S_OK, "got hres 0x%08lx\n", hres);
4601 if (bstr)
4603 todo_wine {
4604 /* MSDN states that rounding of R4/R8 is dependent on the underlying
4605 * bit pattern of the number and so is architecture dependent. In this
4606 * case Wine returns .2 (which is more correct) and Native returns .3
4608 ok(memcmp(bstr, szNative, sizeof(szNative)) == 0, "string different\n");
4613 #define BSTR_DATE(dt,str) SysFreeString(bstr); bstr = NULL; \
4614 hres = pVarBstrFromDate(dt,lcid,LOCALE_NOUSEROVERRIDE,&bstr); \
4615 if (bstr) WideCharToMultiByte(CP_ACP, 0, bstr, -1, buff, sizeof(buff), 0, 0); \
4616 else buff[0] = 0; \
4617 ok(hres == S_OK && !strcmp(str,buff), "Expected '%s', got '%s', hres = 0x%08lx\n", \
4618 str, buff, hres)
4620 static void test_VarBstrFromDate(void)
4622 char buff[256];
4623 LCID lcid;
4624 HRESULT hres;
4625 BSTR bstr = NULL;
4627 CHECKPTR(VarBstrFromDate);
4628 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
4630 BSTR_DATE(0.0, "12:00:00 AM");
4631 BSTR_DATE(3.34, "1/2/1900 8:09:36 AM");
4632 BSTR_DATE(3339.34, "2/20/1909 8:09:36 AM");
4633 BSTR_DATE(365.00, "12/30/1900");
4634 BSTR_DATE(365.25, "12/30/1900 6:00:00 AM");
4635 BSTR_DATE(1461.0, "12/31/1903");
4636 BSTR_DATE(1461.5, "12/31/1903 12:00:00 PM");
4639 /* Get the internal representation of a BSTR */
4640 static inline LPINTERNAL_BSTR Get(const BSTR lpszString)
4642 return lpszString ? (LPINTERNAL_BSTR)((char*)lpszString - sizeof(DWORD)) : NULL;
4645 static inline BSTR GetBSTR(const LPINTERNAL_BSTR bstr)
4647 return (BSTR)bstr->szString;
4650 static void test_SysStringLen()
4652 INTERNAL_BSTR bstr;
4653 BSTR str = GetBSTR(&bstr);
4655 bstr.dwLen = 0;
4656 ok (SysStringLen(str) == 0, "Expected dwLen 0, got %d\n", SysStringLen(str));
4657 bstr.dwLen = 2;
4658 ok (SysStringLen(str) == 1, "Expected dwLen 1, got %d\n", SysStringLen(str));
4661 static void test_SysStringByteLen()
4663 INTERNAL_BSTR bstr;
4664 BSTR str = GetBSTR(&bstr);
4666 bstr.dwLen = 0;
4667 ok (SysStringByteLen(str) == 0, "Expected dwLen 0, got %d\n", SysStringLen(str));
4668 bstr.dwLen = 2;
4669 ok (SysStringByteLen(str) == 2, "Expected dwLen 2, got %d\n", SysStringByteLen(str));
4672 static void test_SysAllocString()
4674 const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
4675 BSTR str;
4677 str = SysAllocString(NULL);
4678 ok (str == NULL, "Expected NULL, got %p\n", str);
4680 str = SysAllocString(szTest);
4681 ok (str != NULL, "Expected non-NULL\n");
4682 if (str)
4684 LPINTERNAL_BSTR bstr = Get(str);
4686 ok (bstr->dwLen == 8, "Expected 8, got %ld\n", bstr->dwLen);
4687 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
4688 SysFreeString(str);
4692 static void test_SysAllocStringLen()
4694 const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
4695 BSTR str;
4697 /* Very early native dlls do not limit the size of strings, so skip this test */
4698 #if 0
4699 str = SysAllocStringLen(szTest, 0x80000000);
4700 todo_wine {
4701 ok (str == NULL, "Expected NULL, got %p\n", str);
4703 #endif
4705 str = SysAllocStringLen(NULL, 0);
4706 ok (str != NULL, "Expected non-NULL\n");
4707 if (str)
4709 LPINTERNAL_BSTR bstr = Get(str);
4711 ok (bstr->dwLen == 0, "Expected 0, got %ld\n", bstr->dwLen);
4712 ok (!bstr->szString[0], "String not empty\n");
4713 SysFreeString(str);
4716 str = SysAllocStringLen(szTest, 4);
4717 ok (str != NULL, "Expected non-NULL\n");
4718 if (str)
4720 LPINTERNAL_BSTR bstr = Get(str);
4722 ok (bstr->dwLen == 8, "Expected 8, got %ld\n", bstr->dwLen);
4723 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
4724 SysFreeString(str);
4728 static void test_SysAllocStringByteLen()
4730 const OLECHAR szTest[10] = { 'T','e','s','t','\0' };
4731 const CHAR szTestA[6] = { 'T','e','s','t','\0','?' };
4732 BSTR str;
4734 str = SysAllocStringByteLen(szTestA, 0x80000000);
4735 ok (str == NULL, "Expected NULL, got %p\n", str);
4737 str = SysAllocStringByteLen(NULL, 0);
4738 ok (str != NULL, "Expected non-NULL\n");
4739 if (str)
4741 LPINTERNAL_BSTR bstr = Get(str);
4743 ok (bstr->dwLen == 0, "Expected 0, got %ld\n", bstr->dwLen);
4744 ok (!bstr->szString[0], "String not empty\n");
4745 SysFreeString(str);
4748 str = SysAllocStringByteLen(szTestA, 4);
4749 ok (str != NULL, "Expected non-NULL\n");
4750 if (str)
4752 LPINTERNAL_BSTR bstr = Get(str);
4754 ok (bstr->dwLen == 4, "Expected 4, got %ld\n", bstr->dwLen);
4755 ok (!lstrcmpA((LPCSTR)bstr->szString, szTestA), "String different\n");
4756 SysFreeString(str);
4759 /* Odd lengths are allocated rounded up, but truncated at the right position */
4760 str = SysAllocStringByteLen(szTestA, 3);
4761 ok (str != NULL, "Expected non-NULL\n");
4762 if (str)
4764 const CHAR szTestTruncA[4] = { 'T','e','s','\0' };
4765 LPINTERNAL_BSTR bstr = Get(str);
4767 ok (bstr->dwLen == 3, "Expected 3, got %ld\n", bstr->dwLen);
4768 ok (!lstrcmpA((LPCSTR)bstr->szString, szTestTruncA), "String different\n");
4769 SysFreeString(str);
4772 str = SysAllocStringByteLen((LPCSTR)szTest, 8);
4773 ok (str != NULL, "Expected non-NULL\n");
4774 if (str)
4776 LPINTERNAL_BSTR bstr = Get(str);
4778 ok (bstr->dwLen == 8, "Expected 8, got %ld\n", bstr->dwLen);
4779 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
4780 SysFreeString(str);
4784 static void test_SysReAllocString()
4786 const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
4787 const OLECHAR szSmaller[2] = { 'x','\0' };
4788 const OLECHAR szLarger[7] = { 'L','a','r','g','e','r','\0' };
4789 BSTR str;
4791 str = SysAllocStringLen(szTest, 4);
4792 ok (str != NULL, "Expected non-NULL\n");
4793 if (str)
4795 LPINTERNAL_BSTR bstr;
4796 BSTR oldstr = str;
4797 int changed;
4799 bstr = Get(str);
4800 ok (bstr->dwLen == 8, "Expected 8, got %ld\n", bstr->dwLen);
4801 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
4803 changed = SysReAllocString(&str, szSmaller);
4804 ok (changed == 1, "Expected 1, got %d\n", changed);
4805 ok (str == oldstr, "Created new string\n");
4806 bstr = Get(str);
4807 ok (bstr->dwLen == 2, "Expected 2, got %ld\n", bstr->dwLen);
4808 ok (!lstrcmpW(bstr->szString, szSmaller), "String different\n");
4810 oldstr = str;
4811 changed = SysReAllocString(&str, szLarger);
4812 ok (changed == 1, "Expected 1, got %d\n", changed);
4813 /* Early versions always make new strings rather than resizing */
4814 /* ok (str == oldstr, "Created new string\n"); */
4815 bstr = Get(str);
4816 ok (bstr->dwLen == 12, "Expected 12, got %ld\n", bstr->dwLen);
4817 ok (!lstrcmpW(bstr->szString, szLarger), "String different\n");
4819 SysFreeString(str);
4823 static void test_SysReAllocStringLen()
4825 const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
4826 const OLECHAR szSmaller[2] = { 'x','\0' };
4827 const OLECHAR szLarger[7] = { 'L','a','r','g','e','r','\0' };
4828 BSTR str;
4830 str = SysAllocStringLen(szTest, 4);
4831 ok (str != NULL, "Expected non-NULL\n");
4832 if (str)
4834 LPINTERNAL_BSTR bstr;
4835 BSTR oldstr = str;
4836 int changed;
4838 bstr = Get(str);
4839 ok (bstr->dwLen == 8, "Expected 8, got %ld\n", bstr->dwLen);
4840 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
4842 changed = SysReAllocStringLen(&str, szSmaller, 1);
4843 ok (changed == 1, "Expected 1, got %d\n", changed);
4844 ok (str == oldstr, "Created new string\n");
4845 bstr = Get(str);
4846 ok (bstr->dwLen == 2, "Expected 2, got %ld\n", bstr->dwLen);
4847 ok (!lstrcmpW(bstr->szString, szSmaller), "String different\n");
4849 oldstr = str;
4850 changed = SysReAllocStringLen(&str, szLarger, 6);
4851 ok (changed == 1, "Expected 1, got %d\n", changed);
4852 /* Early versions always make new strings rather than resizing */
4853 /* ok (str == oldstr, "Created new string\n"); */
4854 bstr = Get(str);
4855 ok (bstr->dwLen == 12, "Expected 12, got %ld\n", bstr->dwLen);
4856 ok (!lstrcmpW(bstr->szString, szLarger), "String different\n");
4858 SysFreeString(str);
4862 static void test_BstrCopy()
4864 const CHAR szTestA[6] = { 'T','e','s','t','\0','?' };
4865 const CHAR szTestTruncA[4] = { 'T','e','s','\0' };
4866 LPINTERNAL_BSTR bstr;
4867 BSTR str;
4868 HRESULT hres;
4869 VARIANT vt1, vt2;
4871 str = SysAllocStringByteLen(szTestA, 3);
4872 ok (str != NULL, "Expected non-NULL\n");
4873 if (str)
4875 V_VT(&vt1) = VT_BSTR;
4876 V_BSTR(&vt1) = str;
4877 V_VT(&vt2) = VT_EMPTY;
4878 hres = VariantCopy(&vt2, &vt1);
4879 ok (hres == S_OK,"Failed to copy binary bstring with hres 0x%08lx\n", hres);
4880 bstr = Get(V_BSTR(&vt2));
4881 ok (bstr->dwLen == 3, "Expected 3, got %ld\n", bstr->dwLen);
4882 ok (!lstrcmpA((LPCSTR)bstr->szString, szTestTruncA), "String different\n");
4886 /* IUnknown */
4888 static void test_IUnknownClear(void)
4890 HRESULT hres;
4891 VARIANTARG v;
4892 DummyDispatch u = { &DummyDispatch_VTable, 1, VT_UI1, FALSE };
4893 IUnknown* pu = (IUnknown*)&u;
4895 /* Test that IUnknown_Release is called on by-value */
4896 V_VT(&v) = VT_UNKNOWN;
4897 V_UNKNOWN(&v) = (IUnknown*)&u;
4898 hres = VariantClear(&v);
4899 ok(hres == S_OK && u.ref == 0 && V_VT(&v) == VT_EMPTY,
4900 "clear unknown: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4901 S_OK, 0, VT_EMPTY, hres, u.ref, V_VT(&v));
4903 /* But not when clearing a by-reference*/
4904 u.ref = 1;
4905 V_VT(&v) = VT_UNKNOWN|VT_BYREF;
4906 V_UNKNOWNREF(&v) = &pu;
4907 hres = VariantClear(&v);
4908 ok(hres == S_OK && u.ref == 1 && V_VT(&v) == VT_EMPTY,
4909 "clear dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4910 S_OK, 1, VT_EMPTY, hres, u.ref, V_VT(&v));
4913 static void test_IUnknownCopy(void)
4915 HRESULT hres;
4916 VARIANTARG vSrc, vDst;
4917 DummyDispatch u = { &DummyDispatch_VTable, 1, VT_UI1, FALSE };
4918 IUnknown* pu = (IUnknown*)&u;
4920 /* AddRef is called on by-value copy */
4921 VariantInit(&vDst);
4922 V_VT(&vSrc) = VT_UNKNOWN;
4923 V_UNKNOWN(&vSrc) = pu;
4924 hres = VariantCopy(&vDst, &vSrc);
4925 ok(hres == S_OK && u.ref == 2 && V_VT(&vDst) == VT_UNKNOWN,
4926 "copy unknown: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4927 S_OK, 2, VT_EMPTY, hres, u.ref, V_VT(&vDst));
4929 /* AddRef is skipped on copy of by-reference IDispatch */
4930 VariantInit(&vDst);
4931 u.ref = 1;
4932 V_VT(&vSrc) = VT_UNKNOWN|VT_BYREF;
4933 V_UNKNOWNREF(&vSrc) = &pu;
4934 hres = VariantCopy(&vDst, &vSrc);
4935 ok(hres == S_OK && u.ref == 1 && V_VT(&vDst) == (VT_UNKNOWN|VT_BYREF),
4936 "copy unknown: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4937 S_OK, 1, VT_DISPATCH, hres, u.ref, V_VT(&vDst));
4939 /* AddRef is called copying by-reference IDispatch with indirection */
4940 VariantInit(&vDst);
4941 u.ref = 1;
4942 V_VT(&vSrc) = VT_UNKNOWN|VT_BYREF;
4943 V_UNKNOWNREF(&vSrc) = &pu;
4944 hres = VariantCopyInd(&vDst, &vSrc);
4945 ok(hres == S_OK && u.ref == 2 && V_VT(&vDst) == VT_UNKNOWN,
4946 "copy unknown: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4947 S_OK, 2, VT_DISPATCH, hres, u.ref, V_VT(&vDst));
4949 /* Indirection in place also calls AddRef */
4950 u.ref = 1;
4951 V_VT(&vSrc) = VT_UNKNOWN|VT_BYREF;
4952 V_UNKNOWNREF(&vSrc) = &pu;
4953 hres = VariantCopyInd(&vSrc, &vSrc);
4954 ok(hres == S_OK && u.ref == 2 && V_VT(&vSrc) == VT_UNKNOWN,
4955 "copy unknown: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
4956 S_OK, 2, VT_DISPATCH, hres, u.ref, V_VT(&vSrc));
4959 static void test_IUnknownChangeTypeEx(void)
4961 HRESULT hres;
4962 VARIANTARG vSrc, vDst;
4963 LCID lcid;
4964 VARTYPE vt;
4965 DummyDispatch u = { &DummyDispatch_VTable, 1, VT_UI1, FALSE };
4966 IUnknown* pu = (IUnknown*)&u;
4968 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4970 V_VT(&vSrc) = VT_UNKNOWN;
4971 V_UNKNOWN(&vSrc) = pu;
4973 /* =>IDispatch in place */
4974 hres = VariantChangeTypeEx(&vSrc, &vSrc, lcid, 0, VT_DISPATCH);
4975 ok(hres == S_OK && u.ref == 1 &&
4976 V_VT(&vSrc) == VT_DISPATCH && V_DISPATCH(&vSrc) == (IDispatch*)pu,
4977 "change unk(src=src): expected 0x%08lx,%d,%d,%p, got 0x%08lx,%ld,%d,%p\n",
4978 S_OK, 1, VT_DISPATCH, pu, hres, u.ref, V_VT(&vSrc), V_DISPATCH(&vSrc));
4980 /* =>IDispatch */
4981 u.ref = 1;
4982 V_VT(&vSrc) = VT_UNKNOWN;
4983 V_UNKNOWN(&vSrc) = (IUnknown*)pu;
4984 VariantInit(&vDst);
4985 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, VT_UNKNOWN);
4986 /* Note vSrc is not cleared, as final refcount is 2 */
4987 ok(hres == S_OK && u.ref == 2 &&
4988 V_VT(&vDst) == VT_UNKNOWN && V_UNKNOWN(&vDst) == (IUnknown*)pu,
4989 "change unk(src,dst): expected 0x%08lx,%d,%d,%p, got 0x%08lx,%ld,%d,%p\n",
4990 S_OK, 2, VT_UNKNOWN, pu, hres, u.ref, V_VT(&vDst), V_UNKNOWN(&vDst));
4992 /* Can't change unknown to anything else */
4993 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
4995 HRESULT hExpected = DISP_E_BADVARTYPE;
4997 V_VT(&vSrc) = VT_UNKNOWN;
4998 V_UNKNOWN(&vSrc) = (IUnknown*)pu;
4999 VariantInit(&vDst);
5001 if (vt == VT_UNKNOWN || vt == VT_DISPATCH || vt == VT_EMPTY || vt == VT_NULL)
5002 hExpected = S_OK;
5003 else
5005 if (vt == VT_I8 || vt == VT_UI8)
5007 if (HAVE_OLEAUT32_I8)
5008 hExpected = DISP_E_TYPEMISMATCH;
5010 else if (vt == VT_RECORD)
5012 if (HAVE_OLEAUT32_RECORD)
5013 hExpected = DISP_E_TYPEMISMATCH;
5015 else if (vt >= VT_I2 && vt <= VT_UINT && vt != (VARTYPE)15)
5016 hExpected = DISP_E_TYPEMISMATCH;
5018 if (IS_ANCIENT && IS_MODERN_VTYPE(vt))
5019 hExpected = DISP_E_BADVARTYPE;
5021 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, vt);
5022 ok(hres == hExpected,
5023 "change unk(badvar): vt %d expected 0x%08lx, got 0x%08lx\n",
5024 vt, hExpected, hres);
5028 /* IDispatch */
5029 static void test_IDispatchClear(void)
5031 HRESULT hres;
5032 VARIANTARG v;
5033 DummyDispatch d = { &DummyDispatch_VTable, 1, VT_UI1, FALSE };
5034 IDispatch* pd = (IDispatch*)&d;
5036 /* As per IUnknown */
5038 V_VT(&v) = VT_DISPATCH;
5039 V_DISPATCH(&v) = pd;
5040 hres = VariantClear(&v);
5041 ok(hres == S_OK && d.ref == 0 && V_VT(&v) == VT_EMPTY,
5042 "clear dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
5043 S_OK, 0, VT_EMPTY, hres, d.ref, V_VT(&v));
5045 d.ref = 1;
5046 V_VT(&v) = VT_DISPATCH|VT_BYREF;
5047 V_DISPATCHREF(&v) = &pd;
5048 hres = VariantClear(&v);
5049 ok(hres == S_OK && d.ref == 1 && V_VT(&v) == VT_EMPTY,
5050 "clear dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
5051 S_OK, 1, VT_EMPTY, hres, d.ref, V_VT(&v));
5054 static void test_IDispatchCopy(void)
5056 HRESULT hres;
5057 VARIANTARG vSrc, vDst;
5058 DummyDispatch d = { &DummyDispatch_VTable, 1, VT_UI1, FALSE };
5059 IDispatch* pd = (IDispatch*)&d;
5061 /* As per IUnknown */
5063 VariantInit(&vDst);
5064 V_VT(&vSrc) = VT_DISPATCH;
5065 V_DISPATCH(&vSrc) = pd;
5066 hres = VariantCopy(&vDst, &vSrc);
5067 ok(hres == S_OK && d.ref == 2 && V_VT(&vDst) == VT_DISPATCH,
5068 "copy dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
5069 S_OK, 2, VT_EMPTY, hres, d.ref, V_VT(&vDst));
5071 VariantInit(&vDst);
5072 d.ref = 1;
5073 V_VT(&vSrc) = VT_DISPATCH|VT_BYREF;
5074 V_DISPATCHREF(&vSrc) = &pd;
5075 hres = VariantCopy(&vDst, &vSrc);
5076 ok(hres == S_OK && d.ref == 1 && V_VT(&vDst) == (VT_DISPATCH|VT_BYREF),
5077 "copy dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
5078 S_OK, 1, VT_DISPATCH, hres, d.ref, V_VT(&vDst));
5080 VariantInit(&vDst);
5081 d.ref = 1;
5082 V_VT(&vSrc) = VT_DISPATCH|VT_BYREF;
5083 V_DISPATCHREF(&vSrc) = &pd;
5084 hres = VariantCopyInd(&vDst, &vSrc);
5085 ok(hres == S_OK && d.ref == 2 && V_VT(&vDst) == VT_DISPATCH,
5086 "copy dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
5087 S_OK, 2, VT_DISPATCH, hres, d.ref, V_VT(&vDst));
5089 d.ref = 1;
5090 V_VT(&vSrc) = VT_DISPATCH|VT_BYREF;
5091 V_DISPATCHREF(&vSrc) = &pd;
5092 hres = VariantCopyInd(&vSrc, &vSrc);
5093 ok(hres == S_OK && d.ref == 2 && V_VT(&vSrc) == VT_DISPATCH,
5094 "copy dispatch: expected 0x%08lx, %d, %d, got 0x%08lx, %ld, %d\n",
5095 S_OK, 2, VT_DISPATCH, hres, d.ref, V_VT(&vSrc));
5098 static void test_IDispatchChangeTypeEx(void)
5100 HRESULT hres;
5101 VARIANTARG vSrc, vDst;
5102 LCID lcid;
5103 DummyDispatch d = { &DummyDispatch_VTable, 1, VT_UI1, FALSE };
5104 IDispatch* pd = (IDispatch*)&d;
5106 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5108 V_VT(&vSrc) = VT_DISPATCH;
5109 V_DISPATCH(&vSrc) = pd;
5111 /* =>IUnknown in place */
5112 hres = VariantChangeTypeEx(&vSrc, &vSrc, lcid, 0, VT_UNKNOWN);
5113 ok(hres == S_OK && d.ref == 1 &&
5114 V_VT(&vSrc) == VT_UNKNOWN && V_UNKNOWN(&vSrc) == (IUnknown*)pd,
5115 "change disp(src=src): expected 0x%08lx,%d,%d,%p, got 0x%08lx,%ld,%d,%p\n",
5116 S_OK, 1, VT_UNKNOWN, pd, hres, d.ref, V_VT(&vSrc), V_UNKNOWN(&vSrc));
5118 /* =>IUnknown */
5119 d.ref = 1;
5120 V_VT(&vSrc) = VT_DISPATCH;
5121 V_DISPATCH(&vSrc) = pd;
5122 VariantInit(&vDst);
5123 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, VT_UNKNOWN);
5124 /* Note vSrc is not cleared, as final refcount is 2 */
5125 ok(hres == S_OK && d.ref == 2 &&
5126 V_VT(&vDst) == VT_UNKNOWN && V_UNKNOWN(&vDst) == (IUnknown*)pd,
5127 "change disp(src,dst): expected 0x%08lx,%d,%d,%p, got 0x%08lx,%ld,%d,%p\n",
5128 S_OK, 2, VT_UNKNOWN, pd, hres, d.ref, V_VT(&vDst), V_UNKNOWN(&vDst));
5130 /* FIXME: Verify that VARIANT_NOVALUEPROP prevents conversion to integral
5131 * types. this requires that the xxxFromDisp tests work first.
5135 /* VT_ERROR */
5136 static void test_ErrorChangeTypeEx(void)
5138 HRESULT hres;
5139 VARIANTARG vSrc, vDst;
5140 VARTYPE vt;
5141 LCID lcid;
5143 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5145 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
5147 HRESULT hExpected = DISP_E_BADVARTYPE;
5149 V_VT(&vSrc) = VT_ERROR;
5150 V_ERROR(&vSrc) = 1;
5151 VariantInit(&vDst);
5152 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, vt);
5154 if (vt == VT_ERROR)
5155 hExpected = S_OK;
5156 else
5158 if (vt == VT_I8 || vt == VT_UI8)
5160 if (HAVE_OLEAUT32_I8)
5161 hExpected = DISP_E_TYPEMISMATCH;
5163 else if (vt == VT_RECORD)
5165 if (HAVE_OLEAUT32_RECORD)
5166 hExpected = DISP_E_TYPEMISMATCH;
5168 else if (vt <= VT_UINT && vt != (VARTYPE)15)
5169 hExpected = DISP_E_TYPEMISMATCH;
5171 if (IS_ANCIENT && IS_MODERN_VTYPE(vt))
5172 hExpected = DISP_E_BADVARTYPE;
5174 ok(hres == hExpected,
5175 "change err: vt %d expected 0x%08lx, got 0x%08lx\n", vt, hExpected, hres);
5179 /* VT_EMPTY */
5180 static void test_EmptyChangeTypeEx(void)
5182 HRESULT hres;
5183 VARIANTARG vSrc, vDst;
5184 VARTYPE vt;
5185 LCID lcid;
5187 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5189 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
5191 HRESULT hExpected = DISP_E_BADVARTYPE;
5193 VariantInit(&vSrc);
5194 memset(&vDst, 0, sizeof(vDst));
5195 V_VT(&vDst) = VT_EMPTY;
5197 if (vt == VT_I8 || vt == VT_UI8)
5199 if (HAVE_OLEAUT32_I8)
5200 hExpected = S_OK;
5202 else if (vt == VT_RECORD)
5204 if (HAVE_OLEAUT32_RECORD)
5205 hExpected = DISP_E_TYPEMISMATCH;
5207 else if (vt == VT_VARIANT || vt == VT_DISPATCH ||
5208 vt == VT_UNKNOWN || vt == VT_ERROR)
5210 hExpected = DISP_E_TYPEMISMATCH;
5212 else if (vt <= VT_UINT && vt != (VARTYPE)15)
5213 hExpected = S_OK;
5215 if (IS_ANCIENT && IS_MODERN_VTYPE(vt))
5216 hExpected = DISP_E_BADVARTYPE;
5218 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, vt);
5220 ok(hres == hExpected && (hres != S_OK || V_VT(&vDst) == vt),
5221 "change empty: vt %d expected 0x%08lx, got 0x%08lx, vt %d\n",
5222 vt, hExpected, hres, V_VT(&vDst));
5226 /* VT_NULL */
5227 static void test_NullChangeTypeEx(void)
5229 HRESULT hres;
5230 VARIANTARG vSrc, vDst;
5231 VARTYPE vt;
5232 LCID lcid;
5234 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5236 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
5238 HRESULT hExpected = DISP_E_BADVARTYPE;
5240 VariantInit(&vSrc);
5241 V_VT(&vSrc) = VT_NULL;
5242 memset(&vDst, 0, sizeof(vDst));
5243 V_VT(&vDst) = VT_EMPTY;
5245 if (vt == VT_I8 || vt == VT_UI8)
5247 if (HAVE_OLEAUT32_I8)
5248 hExpected = DISP_E_TYPEMISMATCH;
5250 else if (vt == VT_RECORD)
5252 if (HAVE_OLEAUT32_RECORD)
5253 hExpected = DISP_E_TYPEMISMATCH;
5255 else if (vt == VT_NULL)
5257 hExpected = S_OK;
5259 else if (vt == VT_VARIANT || vt == VT_DISPATCH ||
5260 vt == VT_UNKNOWN || vt == VT_ERROR ||
5261 (vt <= VT_UINT && vt != (VARTYPE)15))
5262 hExpected = DISP_E_TYPEMISMATCH;
5264 if (IS_ANCIENT && IS_MODERN_VTYPE(vt))
5265 hExpected = DISP_E_BADVARTYPE;
5267 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, vt);
5269 ok(hres == hExpected && (hres != S_OK || V_VT(&vDst) == vt),
5270 "change null: vt %d expected 0x%08lx, got 0x%08lx, vt %d\n",
5271 vt, hExpected, hres, V_VT(&vDst));
5276 /* VT_UINT */
5277 static void test_UintChangeTypeEx(void)
5279 HRESULT hres;
5280 VARIANTARG vSrc, vDst;
5281 LCID lcid;
5283 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5285 /* Converting a VT_UINT to a VT_INT does not check for overflow */
5286 V_VT(&vDst) = VT_EMPTY;
5287 V_VT(&vSrc) = VT_UINT;
5288 V_UI4(&vSrc) = -1;
5289 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, VT_I4);
5290 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == -1,
5291 "change uint: Expected %d,0x%08lx,%d got %d,0x%08lx,%ld\n",
5292 VT_I4, S_OK, -1, V_VT(&vDst), hres, V_I4(&vDst));
5295 #define NUM_CUST_ITEMS 16
5297 static void test_ClearCustData(void)
5299 WCHAR buff[sizeof(CUSTDATAITEM) * NUM_CUST_ITEMS / sizeof(WCHAR)];
5300 CUSTDATA ci;
5301 unsigned i;
5303 CHECKPTR(ClearCustData);
5305 memset(buff, 0, sizeof(buff));
5307 ci.cCustData = NUM_CUST_ITEMS;
5308 /* This is a bit tricky. We use SysAllocStringByteLen to allocate the
5309 * array, since native uses an internal IMalloc interface for allocating
5310 * its memory, while Wine uses HeapAlloc(). Doing this ensures we allocate
5311 * using the correct function whether with native or builtin.
5313 ci.prgCustData = (LPCUSTDATAITEM)SysAllocStringByteLen((LPCSTR)buff, sizeof(buff));
5314 for (i = 0; i < NUM_CUST_ITEMS; i++)
5315 VariantInit(&ci.prgCustData[i].varValue);
5316 pClearCustData(&ci);
5317 ok(!ci.cCustData && !ci.prgCustData, "ClearCustData didn't clear fields!\n");
5320 static void test_NullByRef()
5322 VARIANT v1, v2;
5323 HRESULT hRes;
5325 VariantClear(&v1);
5326 VariantClear(&v2);
5327 V_VT(&v1) = VT_BYREF|VT_VARIANT;
5328 V_BYREF(&v1) = 0;
5330 hRes = VariantChangeTypeEx(&v2, &v1, 0, 0, VT_I4);
5331 ok(hRes == DISP_E_TYPEMISMATCH, "VariantChangeTypeEx should return DISP_E_TYPEMISMATCH\n");
5333 VariantClear(&v1);
5334 V_VT(&v1) = VT_BYREF|VT_VARIANT;
5335 V_BYREF(&v1) = 0;
5336 V_VT(&v2) = VT_I4;
5337 V_I4(&v2) = 123;
5339 hRes = VariantChangeTypeEx(&v2, &v1, 0, 0, VT_VARIANT);
5340 ok(hRes == DISP_E_TYPEMISMATCH, "VariantChangeTypeEx should return DISP_E_TYPEMISMATCH\n");
5341 ok(V_VT(&v2) == VT_I4 && V_I4(&v2) == 123, "VariantChangeTypeEx shouldn't change pvargDest\n");
5343 hRes = VariantChangeTypeEx(&v2, &v1, 0, 0, VT_BYREF|VT_I4);
5344 ok(hRes == DISP_E_TYPEMISMATCH, "VariantChangeTypeEx should return DISP_E_TYPEMISMATCH\n");
5346 hRes = VariantChangeTypeEx(&v2, &v1, 0, 0, 0x3847);
5347 ok(hRes == DISP_E_BADVARTYPE, "VariantChangeTypeEx should return DISP_E_BADVARTYPE\n");
5350 /* Dst Variant should remain unchanged if VariantChangeType cannot convert */
5351 static void test_ChangeType_keep_dst()
5353 VARIANT v1, v2;
5354 BSTR bstr;
5355 WCHAR testW[] = {'t','e','s','t',0};
5356 HRESULT hres;
5358 bstr = SysAllocString(testW);
5359 VariantClear(&v1);
5360 VariantClear(&v2);
5361 V_VT(&v1) = VT_BSTR;
5362 V_BSTR(&v1) = bstr;
5363 hres = VariantChangeTypeEx(&v1, &v1, 0, 0, VT_INT);
5364 ok(hres == DISP_E_TYPEMISMATCH, "VariantChangeTypeEx returns %08lx\n", hres);
5365 ok(V_VT(&v1) == VT_BSTR && V_BSTR(&v1) == bstr, "VariantChangeTypeEx changed dst variant\n");
5366 V_VT(&v2) = VT_INT;
5367 V_INT(&v2) = 4;
5368 hres = VariantChangeTypeEx(&v2, &v1, 0, 0, VT_INT);
5369 ok(hres == DISP_E_TYPEMISMATCH, "VariantChangeTypeEx returns %08lx\n", hres);
5370 ok(V_VT(&v2) == VT_INT && V_INT(&v2) == 4, "VariantChangeTypeEx changed dst variant\n");
5371 SysFreeString(bstr);
5374 START_TEST(vartype)
5376 hOleaut32 = LoadLibraryA("oleaut32.dll");
5377 ok(hOleaut32 != 0, "Failed to load oleaut32.dll\n");
5378 if (!hOleaut32)
5379 return;
5381 trace("LCID's: System=0x%08lx, User=0x%08lx\n", GetSystemDefaultLCID(),
5382 GetUserDefaultLCID());
5384 test_VarI1FromI2();
5385 test_VarI1FromI4();
5386 test_VarI1FromI8();
5387 test_VarI1FromUI1();
5388 test_VarI1FromUI2();
5389 test_VarI1FromUI4();
5390 test_VarI1FromUI8();
5391 test_VarI1FromBool();
5392 test_VarI1FromR4();
5393 test_VarI1FromR8();
5394 test_VarI1FromDate();
5395 test_VarI1FromCy();
5396 test_VarI1FromDec();
5397 test_VarI1FromStr();
5398 test_VarUI1FromDisp();
5399 test_VarI1Copy();
5400 test_VarI1ChangeTypeEx();
5402 test_VarUI1FromI1();
5403 test_VarUI1FromI2();
5404 test_VarUI1FromI4();
5405 test_VarUI1FromI8();
5406 test_VarUI1FromUI2();
5407 test_VarUI1FromUI4();
5408 test_VarUI1FromUI8();
5409 test_VarUI1FromBool();
5410 test_VarUI1FromR4();
5411 test_VarUI1FromR8();
5412 test_VarUI1FromDate();
5413 test_VarUI1FromCy();
5414 test_VarUI1FromDec();
5415 test_VarUI1FromStr();
5416 test_VarUI1Copy();
5417 test_VarUI1ChangeTypeEx();
5419 test_VarI2FromI1();
5420 test_VarI2FromI4();
5421 test_VarI2FromI8();
5422 test_VarI2FromUI1();
5423 test_VarI2FromUI2();
5424 test_VarI2FromUI4();
5425 test_VarI2FromUI8();
5426 test_VarI2FromBool();
5427 test_VarI2FromR4();
5428 test_VarI2FromR8();
5429 test_VarI2FromDate();
5430 test_VarI2FromCy();
5431 test_VarI2FromDec();
5432 test_VarI2FromStr();
5433 test_VarI2Copy();
5434 test_VarI2ChangeTypeEx();
5436 test_VarUI2FromI1();
5437 test_VarUI2FromI2();
5438 test_VarUI2FromI4();
5439 test_VarUI2FromI8();
5440 test_VarUI2FromUI1();
5441 test_VarUI2FromUI4();
5442 test_VarUI2FromUI8();
5443 test_VarUI2FromBool();
5444 test_VarUI2FromR4();
5445 test_VarUI2FromR8();
5446 test_VarUI2FromDate();
5447 test_VarUI2FromCy();
5448 test_VarUI2FromDec();
5449 test_VarUI2FromStr();
5450 test_VarUI2Copy();
5451 test_VarUI2ChangeTypeEx();
5453 test_VarI4FromI1();
5454 test_VarI4FromI2();
5455 test_VarI4FromI8();
5456 test_VarI4FromUI1();
5457 test_VarI4FromUI2();
5458 test_VarI4FromUI4();
5459 test_VarI4FromUI8();
5460 test_VarI4FromBool();
5461 test_VarI4FromR4();
5462 test_VarI4FromR8();
5463 test_VarI4FromDate();
5464 test_VarI4FromCy();
5465 test_VarI4FromDec();
5466 test_VarI4FromStr();
5467 test_VarI4Copy();
5468 test_VarI4ChangeTypeEx();
5470 test_VarUI4FromI1();
5471 test_VarUI4FromI2();
5472 test_VarUI4FromUI2();
5473 test_VarUI4FromI8();
5474 test_VarUI4FromUI1();
5475 test_VarUI4FromI4();
5476 test_VarUI4FromUI8();
5477 test_VarUI4FromBool();
5478 test_VarUI4FromR4();
5479 test_VarUI4FromR8();
5480 test_VarUI4FromDate();
5481 test_VarUI4FromCy();
5482 test_VarUI4FromDec();
5483 test_VarUI4FromStr();
5484 test_VarUI4Copy();
5485 test_VarUI4ChangeTypeEx();
5487 test_VarI8FromI1();
5488 test_VarI8FromUI1();
5489 test_VarI8FromI2();
5490 test_VarI8FromUI2();
5491 test_VarI8FromUI4();
5492 test_VarI8FromR4();
5493 test_VarI8FromR8();
5494 test_VarI8FromBool();
5495 test_VarI8FromUI8();
5496 test_VarI8FromCy();
5497 test_VarI8FromDec();
5498 test_VarI8FromDate();
5499 test_VarI8FromStr();
5500 test_VarI8Copy();
5501 test_VarI8ChangeTypeEx();
5503 test_VarUI8FromI1();
5504 test_VarUI8FromUI1();
5505 test_VarUI8FromI2();
5506 test_VarUI8FromUI2();
5507 test_VarUI8FromUI4();
5508 test_VarUI8FromR4();
5509 test_VarUI8FromR8();
5510 test_VarUI8FromBool();
5511 test_VarUI8FromI8();
5512 test_VarUI8FromCy();
5513 test_VarUI8FromDec();
5514 test_VarUI8FromDate();
5515 test_VarUI8FromStr();
5516 test_VarUI8Copy();
5517 test_VarUI8ChangeTypeEx();
5519 test_VarR4FromI1();
5520 test_VarR4FromUI1();
5521 test_VarR4FromI2();
5522 test_VarR4FromUI2();
5523 test_VarR4FromI4();
5524 test_VarR4FromUI4();
5525 test_VarR4FromR8();
5526 test_VarR4FromBool();
5527 test_VarR4FromCy();
5528 test_VarR4FromI8();
5529 test_VarR4FromUI8();
5530 test_VarR4FromDec();
5531 test_VarR4FromDate();
5532 test_VarR4FromStr();
5533 test_VarR4Copy();
5534 test_VarR4ChangeTypeEx();
5536 test_VarR8FromI1();
5537 test_VarR8FromUI1();
5538 test_VarR8FromI2();
5539 test_VarR8FromUI2();
5540 test_VarR8FromI4();
5541 test_VarR8FromUI4();
5542 test_VarR8FromR4();
5543 test_VarR8FromBool();
5544 test_VarR8FromCy();
5545 test_VarR8FromI8();
5546 test_VarR8FromUI8();
5547 test_VarR8FromDec();
5548 test_VarR8FromDate();
5549 test_VarR8FromStr();
5550 test_VarR8Copy();
5551 test_VarR8ChangeTypeEx();
5552 test_VarR8Round();
5554 test_VarDateFromI1();
5555 test_VarDateFromUI1();
5556 test_VarDateFromI2();
5557 test_VarDateFromUI2();
5558 test_VarDateFromI4();
5559 test_VarDateFromUI4();
5560 test_VarDateFromR4();
5561 test_VarDateFromR8();
5562 test_VarDateFromBool();
5563 test_VarDateFromCy();
5564 test_VarDateFromI8();
5565 test_VarDateFromUI8();
5566 test_VarDateFromDec();
5567 test_VarDateFromStr();
5568 test_VarDateCopy();
5569 test_VarDateChangeTypeEx();
5571 test_VarCyFromI1();
5572 test_VarCyFromUI1();
5573 test_VarCyFromI2();
5574 test_VarCyFromUI2();
5575 test_VarCyFromI4();
5576 test_VarCyFromUI4();
5577 test_VarCyFromR4();
5578 test_VarCyFromR8();
5579 test_VarCyFromBool();
5580 test_VarCyFromI8();
5581 test_VarCyFromUI8();
5582 test_VarCyFromDec();
5583 test_VarCyFromDate();
5585 test_VarCyAdd();
5586 test_VarCyMul();
5587 test_VarCySub();
5588 test_VarCyAbs();
5589 test_VarCyNeg();
5590 test_VarCyMulI4();
5591 test_VarCyMulI8();
5592 test_VarCyCmp();
5593 test_VarCyCmpR8();
5594 test_VarCyRound();
5595 test_VarCyFix();
5596 test_VarCyInt();
5598 test_VarDecFromI1();
5599 test_VarDecFromI2();
5600 test_VarDecFromI4();
5601 test_VarDecFromI8();
5602 test_VarDecFromUI1();
5603 test_VarDecFromUI2();
5604 test_VarDecFromUI4();
5605 test_VarDecFromUI8();
5606 test_VarDecFromR4();
5607 test_VarDecFromR8();
5608 test_VarDecFromDate();
5609 test_VarDecFromStr();
5610 test_VarDecFromCy();
5611 test_VarDecFromDate();
5612 test_VarDecFromBool();
5614 test_VarDecAbs();
5615 test_VarDecNeg();
5616 test_VarDecAdd();
5617 test_VarDecSub();
5618 test_VarDecCmp();
5620 test_VarBoolFromI1();
5621 test_VarBoolFromUI1();
5622 test_VarBoolFromI2();
5623 test_VarBoolFromUI2();
5624 test_VarBoolFromI4();
5625 test_VarBoolFromUI4();
5626 test_VarBoolFromR4();
5627 test_VarBoolFromR8();
5628 test_VarBoolFromCy();
5629 test_VarBoolFromI8();
5630 test_VarBoolFromUI8();
5631 test_VarBoolFromDec();
5632 test_VarBoolFromDate();
5633 test_VarBoolFromStr();
5634 test_VarBoolCopy();
5635 test_VarBoolChangeTypeEx();
5637 test_VarBstrFromR4();
5638 test_VarBstrFromDate();
5639 test_SysStringLen();
5640 test_SysStringByteLen();
5641 test_SysAllocString();
5642 test_SysAllocStringLen();
5643 test_SysAllocStringByteLen();
5644 test_SysReAllocString();
5645 test_SysReAllocStringLen();
5646 test_BstrCopy();
5648 test_IUnknownClear();
5649 test_IUnknownCopy();
5650 test_IUnknownChangeTypeEx();
5652 test_IDispatchClear();
5653 test_IDispatchCopy();
5654 test_IDispatchChangeTypeEx();
5656 test_ErrorChangeTypeEx();
5657 test_EmptyChangeTypeEx();
5658 test_NullChangeTypeEx();
5659 test_UintChangeTypeEx();
5661 test_ClearCustData();
5663 test_NullByRef();
5664 test_ChangeType_keep_dst();