d3d8/tests: Use a separate device for alpha_test().
[wine.git] / dlls / oleaut32 / tests / vartype.c
blobea5065fb46571f6c64d0c575b5d44beda26f5c36
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define CONST_VTABLE
22 #define COBJMACROS
24 #include "wine/test.h"
25 #include "oleauto.h"
26 #include <math.h>
27 #include <stdio.h>
28 #include "test_tlb.h"
30 #include "initguid.h"
32 DEFINE_GUID(UUID_test_struct, 0x4029f190, 0xca4a, 0x4611, 0xae,0xb9,0x67,0x39,0x83,0xcb,0x96,0xdd);
34 /* Some Visual C++ versions choke on __uint64 to float conversions.
35 * To fix this you need either VC++ 6.0 plus the processor pack
36 * or Visual C++ >=7.0.
38 #ifndef _MSC_VER
39 # define HAS_UINT64_TO_FLOAT
40 #else
41 # if _MSC_VER >= 1300
42 # define HAS_UINT64_TO_FLOAT
43 # else
44 # include <malloc.h>
45 # if defined(_mm_free)
46 /* _mm_free is defined if the Processor Pack has been installed */
47 # define HAS_UINT64_TO_FLOAT
48 # endif
50 # endif
51 #endif
53 static HMODULE hOleaut32;
55 /* Get a conversion function ptr, return if function not available */
56 #define CHECKPTR(func) p##func = (void*)GetProcAddress(hOleaut32, #func); \
57 if (!p##func) { \
58 win_skip("function " # func " not available, not testing it\n"); return; }
60 /* Has I8/UI8 data type? */
61 static BOOL has_i8;
62 /* Has proper locale conversions? */
63 static BOOL has_locales;
65 /* Is vt a type unavailable to ancient versions? */
66 #define IS_MODERN_VTYPE(vt) (vt==VT_VARIANT||vt==VT_DECIMAL|| \
67 vt==VT_I1||vt==VT_UI2||vt==VT_UI4||vt == VT_INT||vt == VT_UINT)
69 /* Macros for converting and testing results */
70 #define CONVVARS(typ) HRESULT hres; CONV_TYPE out; typ in
72 #define _EXPECT_NO_OUT(res) ok(hres == res, "expected " #res ", got hres=0x%08x\n", hres)
73 #define EXPECT_OVERFLOW _EXPECT_NO_OUT(DISP_E_OVERFLOW)
74 #define EXPECT_MISMATCH _EXPECT_NO_OUT(DISP_E_TYPEMISMATCH)
75 #define EXPECT_BADVAR _EXPECT_NO_OUT(DISP_E_BADVARTYPE)
76 #define EXPECT_INVALID _EXPECT_NO_OUT(E_INVALIDARG)
77 #define EXPECT_LT _EXPECT_NO_OUT(VARCMP_LT)
78 #define EXPECT_GT _EXPECT_NO_OUT(VARCMP_GT)
79 #define EXPECT_EQ _EXPECT_NO_OUT(VARCMP_EQ)
81 #define _EXPECTRES(res, x, fs) \
82 ok(hres == S_OK && out == (CONV_TYPE)(x), "expected " #x ", got " fs "; hres=0x%08x\n", out, hres)
83 #define EXPECT(x) EXPECTRES(S_OK, (x))
84 #define EXPECT_DBL(x) \
85 ok(hres == S_OK && fabs(out-(x))<=1e-14*(x), "expected %16.16g, got %16.16g; hres=0x%08x\n", (x), out, hres)
87 #define CONVERT(func, val) in = val; hres = p##func(in, &out)
88 #define CONVERTRANGE(func,start,end) for (i = start; i < end; i+=1) { CONVERT(func, i); EXPECT(i); };
89 #define OVERFLOWRANGE(func,start,end) for (i = start; i < end; i+=1) { CONVERT(func, i); EXPECT_OVERFLOW; };
91 #define CY_MULTIPLIER 10000
93 #define DATE_MIN -657434
94 #define DATE_MAX 2958465
96 #define CONVERT_I8(func,hi,lo) in = hi; in = (in << 32) | lo; hres = p##func(in, &out)
98 #define CONVERT_CY(func,val) in.int64 = (LONGLONG)(val * CY_MULTIPLIER); hres = p##func(in, &out)
100 #define CONVERT_CY64(func,hi,lo) S(in).Hi = hi; S(in).Lo = lo; in.int64 *= CY_MULTIPLIER; hres = p##func(in, &out)
102 #define SETDEC(dec, scl, sgn, hi, lo) S(U(dec)).scale = (BYTE)scl; S(U(dec)).sign = (BYTE)sgn; \
103 dec.Hi32 = (ULONG)hi; U1(dec).Lo64 = (ULONG64)lo
105 #define SETDEC64(dec, scl, sgn, hi, mid, lo) S(U(dec)).scale = (BYTE)scl; S(U(dec)).sign = (BYTE)sgn; \
106 dec.Hi32 = (ULONG)hi; S1(U1(dec)).Mid32 = mid; S1(U1(dec)).Lo32 = lo;
108 #define CONVERT_DEC(func,scl,sgn,hi,lo) SETDEC(in,scl,sgn,hi,lo); hres = p##func(&in, &out)
110 #define CONVERT_DEC64(func,scl,sgn,hi,mid,lo) SETDEC64(in,scl,sgn,hi,mid,lo); hres = p##func(&in, &out)
112 #define CONVERT_BADDEC(func) \
113 CONVERT_DEC(func,29,0,0,0); EXPECT_INVALID; \
114 CONVERT_DEC(func,0,0x1,0,0); EXPECT_INVALID; \
115 CONVERT_DEC(func,0,0x40,0,0); EXPECT_INVALID; \
116 CONVERT_DEC(func,0,0x7f,0,0); EXPECT_INVALID;
118 #define CONVERT_STR(func,str,flags) \
119 SetLastError(0); \
120 if (str) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)/sizeof(WCHAR)); \
121 hres = p##func(str ? buff : NULL,in,flags,&out)
123 #define COPYTEST(val, vt, srcval, dstval, srcref, dstref, fs) do { \
124 HRESULT hres; VARIANTARG vSrc, vDst; CONV_TYPE in = val; \
125 VariantInit(&vSrc); VariantInit(&vDst); \
126 V_VT(&vSrc) = vt; srcval = in; \
127 hres = VariantCopy(&vDst, &vSrc); \
128 ok(hres == S_OK && V_VT(&vDst) == vt && dstval == in, \
129 "copy hres 0x%X, type %d, value (" fs ") " fs "\n", hres, V_VT(&vDst), val, dstval); \
130 V_VT(&vSrc) = vt|VT_BYREF; srcref = &in; \
131 hres = VariantCopy(&vDst, &vSrc); \
132 ok(hres == S_OK && V_VT(&vDst) == (vt|VT_BYREF) && dstref == &in, \
133 "ref hres 0x%X, type %d, ref (%p) %p\n", hres, V_VT(&vDst), &in, dstref); \
134 hres = VariantCopyInd(&vDst, &vSrc); \
135 ok(hres == S_OK && V_VT(&vDst) == vt && dstval == in, \
136 "ind hres 0x%X, type %d, value (" fs ") " fs "\n", hres, V_VT(&vDst), val, dstval); \
137 } while(0)
139 #define CHANGETYPEEX(typ) hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, typ)
141 #define TYPETEST(typ,res,fs) CHANGETYPEEX(typ); \
142 ok(hres == S_OK && V_VT(&vDst) == typ && (CONV_TYPE)res == in, \
143 "hres=0x%X, type=%d (should be %d(" #typ ")), value=" fs " (should be " fs ")\n", \
144 hres, V_VT(&vDst), typ, (CONV_TYPE)res, in);
145 #define TYPETESTI8(typ,res) CHANGETYPEEX(typ); \
146 ok(hres == S_OK && V_VT(&vDst) == typ && (CONV_TYPE)res == in, \
147 "hres=0x%X, type=%d (should be %d(" #typ ")), value=%d (should be 1)\n", \
148 hres, V_VT(&vDst), typ, (int)res);
149 #define BADVAR(typ) CHANGETYPEEX(typ); EXPECT_BADVAR
150 #define MISMATCH(typ) CHANGETYPEEX(typ); EXPECT_MISMATCH
152 #define INITIAL_TYPETEST(vt, val, fs) \
153 VariantInit(&vSrc); \
154 VariantInit(&vDst); \
155 V_VT(&vSrc) = vt; \
156 (val(&vSrc)) = in; \
157 TYPETEST(VT_I1, V_I1(&vDst), fs); \
158 TYPETEST(VT_UI2, V_UI2(&vDst), fs); \
159 TYPETEST(VT_UI4, V_UI4(&vDst), fs); \
160 TYPETEST(VT_INT, V_INT(&vDst), fs); \
161 TYPETEST(VT_UINT, V_UINT(&vDst), fs); \
162 TYPETEST(VT_UI1, V_UI1(&vDst), fs); \
163 TYPETEST(VT_I2, V_I2(&vDst), fs); \
164 TYPETEST(VT_I4, V_I4(&vDst), fs); \
165 TYPETEST(VT_R4, V_R4(&vDst), fs); \
166 TYPETEST(VT_R8, V_R8(&vDst), fs); \
167 TYPETEST(VT_DATE, V_DATE(&vDst), fs); \
168 if (has_i8) \
170 TYPETEST(VT_I8, V_I8(&vDst), fs); \
171 TYPETEST(VT_UI8, V_UI8(&vDst), fs); \
173 #define NEGATIVE_TYPETEST(vt, val, fs, vtneg, valneg) \
174 in = -in; \
175 VariantInit(&vSrc); \
176 VariantInit(&vDst); \
177 V_VT(&vSrc) = vt; \
178 (val(&vSrc)) = in; \
179 TYPETEST(vtneg, valneg(&vDst), fs);
181 #define INITIAL_TYPETESTI8(vt, val) \
182 VariantInit(&vSrc); \
183 VariantInit(&vDst); \
184 V_VT(&vSrc) = vt; \
185 (val(&vSrc)) = in; \
186 TYPETESTI8(VT_I1, V_I1(&vDst)); \
187 TYPETESTI8(VT_UI1, V_UI1(&vDst)); \
188 TYPETESTI8(VT_I2, V_I2(&vDst)); \
189 TYPETESTI8(VT_UI2, V_UI2(&vDst)); \
190 TYPETESTI8(VT_I4, V_I4(&vDst)); \
191 TYPETESTI8(VT_UI4, V_UI4(&vDst)); \
192 TYPETESTI8(VT_INT, V_INT(&vDst)); \
193 TYPETESTI8(VT_UINT, V_UINT(&vDst)); \
194 TYPETESTI8(VT_R4, V_R4(&vDst)); \
195 TYPETESTI8(VT_R8, V_R8(&vDst)); \
196 TYPETESTI8(VT_DATE, V_DATE(&vDst)); \
197 TYPETESTI8(VT_I8, V_I8(&vDst)); \
198 TYPETESTI8(VT_UI8, V_UI8(&vDst))
200 #define COMMON_TYPETEST \
201 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_BOOL); \
202 ok(hres == S_OK && V_VT(&vDst) == VT_BOOL && \
203 (V_BOOL(&vDst) == VARIANT_TRUE || (V_VT(&vSrc) == VT_BOOL && V_BOOL(&vDst) == 1)), \
204 "->VT_BOOL hres=0x%X, type=%d (should be VT_BOOL), value %d (should be VARIANT_TRUE)\n", \
205 hres, V_VT(&vDst), V_BOOL(&vDst)); \
206 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_CY); \
207 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == CY_MULTIPLIER, \
208 "->VT_CY hres=0x%X, type=%d (should be VT_CY), value (%08x,%08x) (should be CY_MULTIPLIER)\n", \
209 hres, V_VT(&vDst), S(V_CY(&vDst)).Hi, S(V_CY(&vDst)).Lo); \
210 if (V_VT(&vSrc) != VT_DATE) \
212 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_BSTR); \
213 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && \
214 V_BSTR(&vDst) && V_BSTR(&vDst)[0] == '1' && V_BSTR(&vDst)[1] == '\0', \
215 "->VT_BSTR hres=0x%X, type=%d (should be VT_BSTR), *bstr='%c'\n", \
216 hres, V_VT(&vDst), V_BSTR(&vDst) ? *V_BSTR(&vDst) : '?'); \
218 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_DECIMAL); \
219 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && \
220 S(U(V_DECIMAL(&vDst))).sign == 0 && S(U(V_DECIMAL(&vDst))).scale == 0 && \
221 V_DECIMAL(&vDst).Hi32 == 0 && U1(V_DECIMAL(&vDst)).Lo64 == (ULONGLONG)in, \
222 "->VT_DECIMAL hres=0x%X, type=%d (should be VT_DECIMAL), sign=%d, scale=%d, hi=%u, lo=(%8x %8x),\n", \
223 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign, S(U(V_DECIMAL(&vDst))).scale, \
224 V_DECIMAL(&vDst).Hi32, S1(U1(V_DECIMAL(&vDst))).Mid32, S1(U1(V_DECIMAL(&vDst))).Lo32); \
225 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_EMPTY); \
226 ok(hres == S_OK && V_VT(&vDst) == VT_EMPTY, "->VT_EMPTY hres=0x%X, type=%d (should be VT_EMPTY)\n", hres, V_VT(&vDst)); \
227 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_NULL); \
228 ok(hres == S_OK && V_VT(&vDst) == VT_NULL, "->VT_NULL hres=0x%X, type=%d (should be VT_NULL)\n", hres, V_VT(&vDst)); \
229 MISMATCH(VT_DISPATCH); \
230 MISMATCH(VT_ERROR); \
231 MISMATCH(VT_UNKNOWN); \
232 MISMATCH(VT_VARIANT); \
233 MISMATCH(VT_RECORD); \
234 BADVAR(VT_VOID); \
235 BADVAR(VT_HRESULT); \
236 BADVAR(VT_SAFEARRAY); \
237 BADVAR(VT_CARRAY); \
238 BADVAR(VT_USERDEFINED); \
239 BADVAR(VT_LPSTR); \
240 BADVAR(VT_LPWSTR); \
241 BADVAR(VT_PTR); \
242 BADVAR(VT_INT_PTR); \
243 BADVAR(VT_UINT_PTR); \
244 BADVAR(VT_FILETIME); \
245 BADVAR(VT_BLOB); \
246 BADVAR(VT_STREAM); \
247 BADVAR(VT_STORAGE); \
248 BADVAR(VT_STREAMED_OBJECT); \
249 BADVAR(VT_STORED_OBJECT); \
250 BADVAR(VT_BLOB_OBJECT); \
251 BADVAR(VT_CF); \
252 BADVAR(VT_CLSID); \
253 BADVAR(VT_BSTR_BLOB)
255 #define DEFINE_EXPECT(func) \
256 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
258 #define SET_EXPECT(func) \
259 do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
261 #define CHECK_EXPECT2(func) \
262 do { \
263 ok(expect_ ##func, "unexpected call " #func "\n"); \
264 called_ ## func = TRUE; \
265 }while(0)
267 #define CHECK_EXPECT(func) \
268 do { \
269 CHECK_EXPECT2(func); \
270 expect_ ## func = FALSE; \
271 }while(0)
273 #define CHECK_CALLED(func) \
274 do { \
275 ok(called_ ## func, "expected " #func "\n"); \
276 expect_ ## func = called_ ## func = FALSE; \
277 }while(0)
279 DEFINE_EXPECT(dispatch_invoke);
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 *pVarDecMul)(const DECIMAL*,const DECIMAL*,DECIMAL*);
487 static HRESULT (WINAPI *pVarDecDiv)(const DECIMAL*,const DECIMAL*,DECIMAL*);
488 static HRESULT (WINAPI *pVarDecCmp)(const DECIMAL*,const DECIMAL*);
489 static HRESULT (WINAPI *pVarDecCmpR8)(const DECIMAL*,double);
490 static HRESULT (WINAPI *pVarDecNeg)(const DECIMAL*,DECIMAL*);
491 static HRESULT (WINAPI *pVarDecRound)(const DECIMAL*,int,DECIMAL*);
493 static HRESULT (WINAPI *pVarBoolFromUI1)(BYTE,VARIANT_BOOL*);
494 static HRESULT (WINAPI *pVarBoolFromI2)(SHORT,VARIANT_BOOL*);
495 static HRESULT (WINAPI *pVarBoolFromI4)(LONG,VARIANT_BOOL*);
496 static HRESULT (WINAPI *pVarBoolFromR4)(FLOAT,VARIANT_BOOL*);
497 static HRESULT (WINAPI *pVarBoolFromR8)(DOUBLE,VARIANT_BOOL*);
498 static HRESULT (WINAPI *pVarBoolFromDate)(DATE,VARIANT_BOOL*);
499 static HRESULT (WINAPI *pVarBoolFromCy)(CY,VARIANT_BOOL*);
500 static HRESULT (WINAPI *pVarBoolFromStr)(OLECHAR*,LCID,ULONG,VARIANT_BOOL*);
501 static HRESULT (WINAPI *pVarBoolFromI1)(signed char,VARIANT_BOOL*);
502 static HRESULT (WINAPI *pVarBoolFromUI2)(USHORT,VARIANT_BOOL*);
503 static HRESULT (WINAPI *pVarBoolFromUI4)(ULONG,VARIANT_BOOL*);
504 static HRESULT (WINAPI *pVarBoolFromDec)(DECIMAL*,VARIANT_BOOL*);
505 static HRESULT (WINAPI *pVarBoolFromI8)(LONG64,VARIANT_BOOL*);
506 static HRESULT (WINAPI *pVarBoolFromUI8)(ULONG64,VARIANT_BOOL*);
508 static HRESULT (WINAPI *pVarBstrFromR4)(FLOAT,LCID,ULONG,BSTR*);
509 static HRESULT (WINAPI *pVarBstrFromDate)(DATE,LCID,ULONG,BSTR*);
510 static HRESULT (WINAPI *pVarBstrFromCy)(CY,LCID,ULONG,BSTR*);
511 static HRESULT (WINAPI *pVarBstrFromDec)(DECIMAL*,LCID,ULONG,BSTR*);
512 static HRESULT (WINAPI *pVarBstrCmp)(BSTR,BSTR,LCID,ULONG);
513 static HRESULT (WINAPI *pVarBstrCat)(BSTR,BSTR,BSTR*);
515 static INT (WINAPI *pSystemTimeToVariantTime)(LPSYSTEMTIME,double*);
516 static void (WINAPI *pClearCustData)(LPCUSTDATA);
518 /* Internal representation of a BSTR */
519 typedef struct tagINTERNAL_BSTR
521 DWORD dwLen;
522 OLECHAR szString[1];
523 } INTERNAL_BSTR, *LPINTERNAL_BSTR;
525 typedef struct
527 IDispatch IDispatch_iface;
528 LONG ref;
529 VARTYPE vt;
530 BOOL bFailInvoke;
531 } DummyDispatch;
533 static inline DummyDispatch *impl_from_IDispatch(IDispatch *iface)
535 return CONTAINING_RECORD(iface, DummyDispatch, IDispatch_iface);
538 static ULONG WINAPI DummyDispatch_AddRef(IDispatch *iface)
540 DummyDispatch *This = impl_from_IDispatch(iface);
541 return InterlockedIncrement(&This->ref);
544 static ULONG WINAPI DummyDispatch_Release(IDispatch *iface)
546 DummyDispatch *This = impl_from_IDispatch(iface);
547 return InterlockedDecrement(&This->ref);
550 static HRESULT WINAPI DummyDispatch_QueryInterface(IDispatch *iface,
551 REFIID riid,
552 void** ppvObject)
554 *ppvObject = NULL;
556 if (IsEqualIID(riid, &IID_IDispatch) ||
557 IsEqualIID(riid, &IID_IUnknown))
559 *ppvObject = iface;
560 IDispatch_AddRef(iface);
563 return *ppvObject ? S_OK : E_NOINTERFACE;
566 static HRESULT WINAPI DummyDispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
568 ok(0, "Unexpected call\n");
569 return E_NOTIMPL;
572 static HRESULT WINAPI DummyDispatch_GetTypeInfo(IDispatch *iface, UINT tinfo, LCID lcid, ITypeInfo **ti)
574 ok(0, "Unexpected call\n");
575 return E_NOTIMPL;
578 static HRESULT WINAPI DummyDispatch_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *names,
579 UINT cnames, LCID lcid, DISPID *dispid)
581 ok(0, "Unexpected call\n");
582 return E_NOTIMPL;
585 static HRESULT WINAPI DummyDispatch_Invoke(IDispatch *iface,
586 DISPID dispid, REFIID riid,
587 LCID lcid, WORD wFlags,
588 DISPPARAMS *params,
589 VARIANT *res,
590 EXCEPINFO *ei,
591 UINT *arg_err)
593 DummyDispatch *This = impl_from_IDispatch(iface);
595 CHECK_EXPECT(dispatch_invoke);
597 ok(dispid == DISPID_VALUE, "got dispid %d\n", dispid);
598 ok(IsEqualIID(riid, &IID_NULL), "go riid %s\n", wine_dbgstr_guid(riid));
599 ok(wFlags == DISPATCH_PROPERTYGET, "Flags wrong\n");
601 ok(params->rgvarg == NULL, "got %p\n", params->rgvarg);
602 ok(params->rgdispidNamedArgs == NULL, "got %p\n", params->rgdispidNamedArgs);
603 ok(params->cArgs == 0, "got %d\n", params->cArgs);
604 ok(params->cNamedArgs == 0, "got %d\n", params->cNamedArgs);
606 ok(res != NULL, "got %p\n", res);
607 ok(V_VT(res) == VT_EMPTY, "got %d\n", V_VT(res));
608 ok(ei == NULL, "got %p\n", ei);
609 ok(arg_err == NULL, "got %p\n", arg_err);
611 if (This->bFailInvoke)
612 return E_OUTOFMEMORY;
614 V_VT(res) = This->vt;
615 if (This->vt == VT_UI1)
616 V_UI1(res) = 1;
617 else
618 memset(res, 0, sizeof(*res));
620 return S_OK;
623 static const IDispatchVtbl DummyDispatch_VTable =
625 DummyDispatch_QueryInterface,
626 DummyDispatch_AddRef,
627 DummyDispatch_Release,
628 DummyDispatch_GetTypeInfoCount,
629 DummyDispatch_GetTypeInfo,
630 DummyDispatch_GetIDsOfNames,
631 DummyDispatch_Invoke
634 static void init_test_dispatch(LONG ref, VARTYPE vt, DummyDispatch *dispatch)
636 dispatch->IDispatch_iface.lpVtbl = &DummyDispatch_VTable;
637 dispatch->ref = ref;
638 dispatch->vt = vt;
639 dispatch->bFailInvoke = FALSE;
643 * VT_I1/VT_UI1
646 #undef CONV_TYPE
647 #define CONV_TYPE signed char
648 #undef EXPECTRES
649 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%d")
651 static void test_VarI1FromI2(void)
653 CONVVARS(SHORT);
654 int i;
656 CHECKPTR(VarI1FromI2);
657 OVERFLOWRANGE(VarI1FromI2, -32768, -128);
658 CONVERTRANGE(VarI1FromI2, -128, 128);
659 OVERFLOWRANGE(VarI1FromI2, 129, 32768);
662 static void test_VarI1FromI4(void)
664 CONVVARS(LONG);
665 int i;
667 CHECKPTR(VarI1FromI4);
668 CONVERT(VarI1FromI4, -129); EXPECT_OVERFLOW;
669 CONVERTRANGE(VarI1FromI4, -128, 128);
670 CONVERT(VarI1FromI4, 128); EXPECT_OVERFLOW;
673 static void test_VarI1FromI8(void)
675 CONVVARS(LONG64);
676 int i;
678 CHECKPTR(VarI1FromI8);
679 CONVERT(VarI1FromI8, -129); EXPECT_OVERFLOW;
680 CONVERTRANGE(VarI1FromI8, -127, 128);
681 CONVERT(VarI1FromI8, 128); EXPECT_OVERFLOW;
684 static void test_VarI1FromUI1(void)
686 CONVVARS(BYTE);
687 int i;
689 CHECKPTR(VarI1FromUI1);
690 CONVERTRANGE(VarI1FromUI1, 0, 127);
691 OVERFLOWRANGE(VarI1FromUI1, 128, 255);
694 static void test_VarI1FromUI2(void)
696 CONVVARS(USHORT);
697 int i;
699 CHECKPTR(VarI1FromUI2);
700 CONVERTRANGE(VarI1FromUI2, 0, 127);
701 OVERFLOWRANGE(VarI1FromUI2, 128, 32768);
704 static void test_VarI1FromUI4(void)
706 CONVVARS(ULONG);
707 int i;
709 CHECKPTR(VarI1FromUI4);
710 CONVERTRANGE(VarI1FromUI4, 0, 127);
711 CONVERT(VarI1FromUI4, 128); EXPECT_OVERFLOW;
714 static void test_VarI1FromUI8(void)
716 CONVVARS(ULONG64);
717 int i;
719 CHECKPTR(VarI1FromUI8);
720 CONVERTRANGE(VarI1FromUI8, 0, 127);
721 CONVERT(VarI1FromUI8, 128); EXPECT_OVERFLOW;
724 static void test_VarI1FromBool(void)
726 CONVVARS(VARIANT_BOOL);
727 int i;
729 CHECKPTR(VarI1FromBool);
730 /* Note that conversions from bool wrap around! */
731 CONVERT(VarI1FromBool, -129); EXPECT(127);
732 CONVERTRANGE(VarI1FromBool, -128, 128);
733 CONVERT(VarI1FromBool, 128); EXPECT(-128);
736 static void test_VarI1FromR4(void)
738 CONVVARS(FLOAT);
740 CHECKPTR(VarI1FromR4);
741 CONVERT(VarI1FromR4, -129.0f); EXPECT_OVERFLOW;
742 CONVERT(VarI1FromR4, -128.51f); EXPECT_OVERFLOW;
743 CONVERT(VarI1FromR4, -128.5f); EXPECT(-128);
744 CONVERT(VarI1FromR4, -128.0f); EXPECT(-128);
745 CONVERT(VarI1FromR4, -1.0f); EXPECT(-1);
746 CONVERT(VarI1FromR4, 0.0f); EXPECT(0);
747 CONVERT(VarI1FromR4, 1.0f); EXPECT(1);
748 CONVERT(VarI1FromR4, 127.0f); EXPECT(127);
749 CONVERT(VarI1FromR4, 127.49f); EXPECT(127);
750 CONVERT(VarI1FromR4, 127.5f); EXPECT_OVERFLOW;
751 CONVERT(VarI1FromR4, 128.0f); EXPECT_OVERFLOW;
753 CONVERT(VarI1FromR4, -1.5f); EXPECT(-2);
754 CONVERT(VarI1FromR4, -0.6f); EXPECT(-1);
755 CONVERT(VarI1FromR4, -0.5f); EXPECT(0);
756 CONVERT(VarI1FromR4, -0.4f); EXPECT(0);
757 CONVERT(VarI1FromR4, 0.4f); EXPECT(0);
758 CONVERT(VarI1FromR4, 0.5f); EXPECT(0);
759 CONVERT(VarI1FromR4, 0.6f); EXPECT(1);
760 CONVERT(VarI1FromR4, 1.5f); EXPECT(2);
763 static void test_VarI1FromR8(void)
765 CONVVARS(DOUBLE);
767 CHECKPTR(VarI1FromR8);
768 CONVERT(VarI1FromR8, -129.0); EXPECT_OVERFLOW;
769 CONVERT(VarI1FromR8, -128.51); EXPECT_OVERFLOW;
770 CONVERT(VarI1FromR8, -128.5); EXPECT(-128);
771 CONVERT(VarI1FromR8, -128.0); EXPECT(-128);
772 CONVERT(VarI1FromR8, -1.0); EXPECT(-1);
773 CONVERT(VarI1FromR8, 0.0); EXPECT(0);
774 CONVERT(VarI1FromR8, 1.0); EXPECT(1);
775 CONVERT(VarI1FromR8, 127.0); EXPECT(127);
776 CONVERT(VarI1FromR8, 127.49); EXPECT(127);
777 CONVERT(VarI1FromR8, 127.5); EXPECT_OVERFLOW;
778 CONVERT(VarI1FromR8, 128.0); EXPECT_OVERFLOW;
780 CONVERT(VarI1FromR8, -1.5); EXPECT(-2);
781 CONVERT(VarI1FromR8, -0.6); EXPECT(-1);
782 CONVERT(VarI1FromR8, -0.5); EXPECT(0);
783 CONVERT(VarI1FromR8, -0.4); EXPECT(0);
784 CONVERT(VarI1FromR8, 0.4); EXPECT(0);
785 CONVERT(VarI1FromR8, 0.5); EXPECT(0);
786 CONVERT(VarI1FromR8, 0.6); EXPECT(1);
787 CONVERT(VarI1FromR8, 1.5); EXPECT(2);
790 static void test_VarI1FromDate(void)
792 CONVVARS(DATE);
794 CHECKPTR(VarI1FromDate);
795 CONVERT(VarI1FromDate, -129.0); EXPECT_OVERFLOW;
796 CONVERT(VarI1FromDate, -128.0); EXPECT(-128);
797 CONVERT(VarI1FromDate, -1.0); EXPECT(-1);
798 CONVERT(VarI1FromDate, 0.0); EXPECT(0);
799 CONVERT(VarI1FromDate, 1.0); EXPECT(1);
800 CONVERT(VarI1FromDate, 127.0); EXPECT(127);
801 CONVERT(VarI1FromDate, 128.0); EXPECT_OVERFLOW;
803 CONVERT(VarI1FromDate, -1.5); EXPECT(-2);
804 CONVERT(VarI1FromDate, -0.6); EXPECT(-1);
805 CONVERT(VarI1FromDate, -0.5); EXPECT(0);
806 CONVERT(VarI1FromDate, -0.4); EXPECT(0);
807 CONVERT(VarI1FromDate, 0.4); EXPECT(0);
808 CONVERT(VarI1FromDate, 0.5); EXPECT(0);
809 CONVERT(VarI1FromDate, 0.6); EXPECT(1);
810 CONVERT(VarI1FromDate, 1.5); EXPECT(2);
813 static void test_VarI1FromCy(void)
815 CONVVARS(CY);
817 CHECKPTR(VarI1FromCy);
818 CONVERT_CY(VarI1FromCy,-129); EXPECT_OVERFLOW;
819 CONVERT_CY(VarI1FromCy,-128); EXPECT(128);
820 CONVERT_CY(VarI1FromCy,-1); EXPECT(-1);
821 CONVERT_CY(VarI1FromCy,0); EXPECT(0);
822 CONVERT_CY(VarI1FromCy,1); EXPECT(1);
823 CONVERT_CY(VarI1FromCy,127); EXPECT(127);
824 CONVERT_CY(VarI1FromCy,128); EXPECT_OVERFLOW;
826 CONVERT_CY(VarI1FromCy,-1.5); EXPECT(-2);
827 CONVERT_CY(VarI1FromCy,-0.6); EXPECT(-1);
828 CONVERT_CY(VarI1FromCy,-0.5); EXPECT(0);
829 CONVERT_CY(VarI1FromCy,-0.4); EXPECT(0);
830 CONVERT_CY(VarI1FromCy,0.4); EXPECT(0);
831 CONVERT_CY(VarI1FromCy,0.5); EXPECT(0);
832 CONVERT_CY(VarI1FromCy,0.6); EXPECT(1);
833 CONVERT_CY(VarI1FromCy,1.5); EXPECT(2);
836 static void test_VarI1FromDec(void)
838 CONVVARS(DECIMAL);
840 CHECKPTR(VarI1FromDec);
842 CONVERT_BADDEC(VarI1FromDec);
844 CONVERT_DEC(VarI1FromDec,0,0x80,0,129); EXPECT_OVERFLOW;
845 CONVERT_DEC(VarI1FromDec,0,0x80,0,128); EXPECT(-128);
846 CONVERT_DEC(VarI1FromDec,0,0x80,0,1); EXPECT(-1);
847 CONVERT_DEC(VarI1FromDec,0,0,0,0); EXPECT(0);
848 CONVERT_DEC(VarI1FromDec,0,0,0,1); EXPECT(1);
849 CONVERT_DEC(VarI1FromDec,0,0,0,127); EXPECT(127);
850 CONVERT_DEC(VarI1FromDec,0,0,0,128); EXPECT_OVERFLOW;
852 CONVERT_DEC(VarI1FromDec,2,0x80,0,12800); EXPECT(-128);
853 CONVERT_DEC(VarI1FromDec,2,0,0,12700); EXPECT(127);
856 static void test_VarI1FromStr(void)
858 CONVVARS(LCID);
859 OLECHAR buff[128];
861 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
863 CHECKPTR(VarI1FromStr);
865 CONVERT_STR(VarI1FromStr,NULL, 0); EXPECT_MISMATCH;
866 CONVERT_STR(VarI1FromStr,"0", 0); EXPECT(0);
867 CONVERT_STR(VarI1FromStr,"-129", 0); EXPECT_OVERFLOW;
868 CONVERT_STR(VarI1FromStr,"-128", 0); EXPECT(-128);
869 CONVERT_STR(VarI1FromStr,"127", 0); EXPECT(127);
870 CONVERT_STR(VarI1FromStr,"128", 0); EXPECT_OVERFLOW;
872 CONVERT_STR(VarI1FromStr,"-1.5", LOCALE_NOUSEROVERRIDE); EXPECT(-2);
873 CONVERT_STR(VarI1FromStr,"-0.6", LOCALE_NOUSEROVERRIDE); EXPECT(-1);
874 CONVERT_STR(VarI1FromStr,"-0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
875 CONVERT_STR(VarI1FromStr,"-0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
876 CONVERT_STR(VarI1FromStr,"0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
877 CONVERT_STR(VarI1FromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
878 CONVERT_STR(VarI1FromStr,"0.6", LOCALE_NOUSEROVERRIDE); EXPECT(1);
879 CONVERT_STR(VarI1FromStr,"1.5", LOCALE_NOUSEROVERRIDE); EXPECT(2);
882 static void test_VarI1Copy(void)
884 COPYTEST(1, VT_I1, V_I1(&vSrc), V_I1(&vDst), V_I1REF(&vSrc), V_I1REF(&vDst), "%d");
887 static void test_VarI1ChangeTypeEx(void)
889 HRESULT hres;
890 signed char in;
891 VARIANTARG vSrc, vDst;
893 in = 1;
895 INITIAL_TYPETEST(VT_I1, V_I1, "%d");
896 COMMON_TYPETEST;
897 NEGATIVE_TYPETEST(VT_I1, V_I1, "%d", VT_UI1, V_UI1);
900 #undef CONV_TYPE
901 #define CONV_TYPE BYTE
903 static void test_VarUI1FromI1(void)
905 CONVVARS(signed char);
906 int i;
908 CHECKPTR(VarUI1FromI1);
909 OVERFLOWRANGE(VarUI1FromI1, -128, 0);
910 CONVERTRANGE(VarUI1FromI1, 0, 128);
913 static void test_VarUI1FromI2(void)
915 CONVVARS(SHORT);
916 int i;
918 CHECKPTR(VarUI1FromI2);
919 OVERFLOWRANGE(VarUI1FromI2, -32768, 0);
920 CONVERTRANGE(VarUI1FromI2, 0, 256);
921 OVERFLOWRANGE(VarUI1FromI2, 256, 32768);
924 static void test_VarUI1FromI4(void)
926 CONVVARS(LONG);
927 int i;
929 CHECKPTR(VarUI1FromI4);
930 CONVERT(VarUI1FromI4, -1); EXPECT_OVERFLOW;
931 CONVERTRANGE(VarUI1FromI4, 0, 256);
932 CONVERT(VarUI1FromI4, 256); EXPECT_OVERFLOW;
935 static void test_VarUI1FromI8(void)
937 CONVVARS(LONG64);
938 int i;
940 CHECKPTR(VarUI1FromI8);
941 CONVERT(VarUI1FromI8, -1); EXPECT_OVERFLOW;
942 CONVERTRANGE(VarUI1FromI8, 0, 256);
943 CONVERT(VarUI1FromI8, 256); EXPECT_OVERFLOW;
946 static void test_VarUI1FromUI2(void)
948 CONVVARS(USHORT);
949 int i;
951 CHECKPTR(VarUI1FromUI2);
952 CONVERTRANGE(VarUI1FromUI2, 0, 256);
953 OVERFLOWRANGE(VarUI1FromUI2, 256, 65536);
956 static void test_VarUI1FromUI4(void)
958 CONVVARS(ULONG);
959 int i;
961 CHECKPTR(VarUI1FromUI4);
962 CONVERTRANGE(VarUI1FromUI4, 0, 256);
963 CONVERT(VarUI1FromUI4, 256); EXPECT_OVERFLOW;
966 static void test_VarUI1FromUI8(void)
968 CONVVARS(ULONG64);
969 int i;
971 CHECKPTR(VarUI1FromUI8);
972 CONVERTRANGE(VarUI1FromUI8, 0, 256);
973 CONVERT(VarUI1FromUI8, 256); EXPECT_OVERFLOW;
976 static void test_VarUI1FromBool(void)
978 CONVVARS(VARIANT_BOOL);
979 int i;
981 CHECKPTR(VarUI1FromBool);
982 /* Note that conversions from bool overflow! */
983 CONVERT(VarUI1FromBool, -1); EXPECT(255);
984 CONVERTRANGE(VarUI1FromBool, 0, 256);
985 CONVERT(VarUI1FromBool, 256); EXPECT(0);
988 static void test_VarUI1FromR4(void)
990 CONVVARS(FLOAT);
992 CHECKPTR(VarUI1FromR4);
993 CONVERT(VarUI1FromR4, -1.0f); EXPECT_OVERFLOW;
994 CONVERT(VarUI1FromR4, -0.51f); EXPECT_OVERFLOW;
995 CONVERT(VarUI1FromR4, -0.5f); EXPECT(0);
996 CONVERT(VarUI1FromR4, 0.0f); EXPECT(0);
997 CONVERT(VarUI1FromR4, 1.0f); EXPECT(1);
998 CONVERT(VarUI1FromR4, 255.0f); EXPECT(255);
999 CONVERT(VarUI1FromR4, 255.49f); EXPECT(255);
1000 CONVERT(VarUI1FromR4, 255.5f); EXPECT_OVERFLOW;
1001 CONVERT(VarUI1FromR4, 256.0f); EXPECT_OVERFLOW;
1003 /* Rounding */
1004 CONVERT(VarUI1FromR4, -1.5f); EXPECT_OVERFLOW;
1005 CONVERT(VarUI1FromR4, -0.6f); EXPECT_OVERFLOW;
1006 CONVERT(VarUI1FromR4, -0.5f); EXPECT(0);
1007 CONVERT(VarUI1FromR4, -0.4f); EXPECT(0);
1008 CONVERT(VarUI1FromR4, 0.4f); EXPECT(0);
1009 CONVERT(VarUI1FromR4, 0.5f); EXPECT(0);
1010 CONVERT(VarUI1FromR4, 0.6f); EXPECT(1);
1011 CONVERT(VarUI1FromR4, 1.5f); EXPECT(2);
1014 static void test_VarUI1FromR8(void)
1016 CONVVARS(DOUBLE);
1018 CHECKPTR(VarUI1FromR8);
1019 CONVERT(VarUI1FromR8, -1.0); EXPECT_OVERFLOW;
1020 CONVERT(VarUI1FromR8, -0.51); EXPECT_OVERFLOW;
1021 CONVERT(VarUI1FromR8, -0.5); EXPECT(0);
1022 CONVERT(VarUI1FromR8, 0.0); EXPECT(0);
1023 CONVERT(VarUI1FromR8, 1.0); EXPECT(1);
1024 CONVERT(VarUI1FromR8, 255.0); EXPECT(255);
1025 CONVERT(VarUI1FromR8, 255.49); EXPECT(255);
1026 CONVERT(VarUI1FromR8, 255.5); EXPECT_OVERFLOW;
1027 CONVERT(VarUI1FromR8, 256.0); EXPECT_OVERFLOW;
1029 /* Rounding */
1030 CONVERT(VarUI1FromR8, -1.5); EXPECT_OVERFLOW;
1031 CONVERT(VarUI1FromR8, -0.6); EXPECT_OVERFLOW;
1032 CONVERT(VarUI1FromR8, -0.5); EXPECT(0);
1033 CONVERT(VarUI1FromR8, -0.4); EXPECT(0);
1034 CONVERT(VarUI1FromR8, 0.4); EXPECT(0);
1035 CONVERT(VarUI1FromR8, 0.5); EXPECT(0);
1036 CONVERT(VarUI1FromR8, 0.6); EXPECT(1);
1037 CONVERT(VarUI1FromR8, 1.5); EXPECT(2);
1040 static void test_VarUI1FromDate(void)
1042 CONVVARS(DATE);
1044 CHECKPTR(VarUI1FromDate);
1045 CONVERT(VarUI1FromDate, -1.0); EXPECT_OVERFLOW;
1046 CONVERT(VarUI1FromDate, 0.0); EXPECT(0);
1047 CONVERT(VarUI1FromDate, 1.0); EXPECT(1);
1048 CONVERT(VarUI1FromDate, 255.0); EXPECT(255);
1049 CONVERT(VarUI1FromDate, 256.0); EXPECT_OVERFLOW;
1051 /* Rounding */
1052 CONVERT(VarUI1FromDate, -1.5); EXPECT_OVERFLOW;
1053 CONVERT(VarUI1FromDate, -0.6); EXPECT_OVERFLOW;
1054 CONVERT(VarUI1FromDate, -0.5); EXPECT(0);
1055 CONVERT(VarUI1FromDate, -0.4); EXPECT(0);
1056 CONVERT(VarUI1FromDate, 0.4); EXPECT(0);
1057 CONVERT(VarUI1FromDate, 0.5); EXPECT(0);
1058 CONVERT(VarUI1FromDate, 0.6); EXPECT(1);
1059 CONVERT(VarUI1FromDate, 1.5); EXPECT(2);
1062 static void test_VarUI1FromCy(void)
1064 CONVVARS(CY);
1066 CHECKPTR(VarUI1FromCy);
1067 CONVERT_CY(VarUI1FromCy,-1); EXPECT_OVERFLOW;
1068 CONVERT_CY(VarUI1FromCy,0); EXPECT(0);
1069 CONVERT_CY(VarUI1FromCy,1); EXPECT(1);
1070 CONVERT_CY(VarUI1FromCy,255); EXPECT(255);
1071 CONVERT_CY(VarUI1FromCy,256); EXPECT_OVERFLOW;
1073 /* Rounding */
1074 CONVERT_CY(VarUI1FromCy,-1.5); EXPECT_OVERFLOW;
1075 CONVERT_CY(VarUI1FromCy,-0.6); EXPECT_OVERFLOW;
1076 CONVERT_CY(VarUI1FromCy,-0.5); EXPECT(0);
1077 CONVERT_CY(VarUI1FromCy,-0.4); EXPECT(0);
1078 CONVERT_CY(VarUI1FromCy,0.4); EXPECT(0);
1079 CONVERT_CY(VarUI1FromCy,0.5); EXPECT(0);
1080 CONVERT_CY(VarUI1FromCy,0.6); EXPECT(1);
1081 CONVERT_CY(VarUI1FromCy,1.5); EXPECT(2);
1084 static void test_VarUI1FromDec(void)
1086 CONVVARS(DECIMAL);
1088 CHECKPTR(VarUI1FromDec);
1090 CONVERT_BADDEC(VarUI1FromDec);
1092 CONVERT_DEC(VarUI1FromDec,0,0x80,0,1); EXPECT_OVERFLOW;
1093 CONVERT_DEC(VarUI1FromDec,0,0,0,0); EXPECT(0);
1094 CONVERT_DEC(VarUI1FromDec,0,0,0,1); EXPECT(1);
1095 CONVERT_DEC(VarUI1FromDec,0,0,0,255); EXPECT(255);
1096 CONVERT_DEC(VarUI1FromDec,0,0,0,256); EXPECT_OVERFLOW;
1098 CONVERT_DEC(VarUI1FromDec,2,0x80,0,100); EXPECT_OVERFLOW;
1099 CONVERT_DEC(VarUI1FromDec,2,0,0,25500); EXPECT(255);
1102 static void test_VarUI1FromStr(void)
1104 CONVVARS(LCID);
1105 OLECHAR buff[128];
1107 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1109 CHECKPTR(VarUI1FromStr);
1111 CONVERT_STR(VarUI1FromStr,NULL, 0); EXPECT_MISMATCH;
1112 CONVERT_STR(VarUI1FromStr,"0", 0); EXPECT(0);
1113 CONVERT_STR(VarUI1FromStr,"-1", 0); EXPECT_OVERFLOW;
1114 CONVERT_STR(VarUI1FromStr,"255", 0); EXPECT(255);
1115 CONVERT_STR(VarUI1FromStr,"256", 0); EXPECT_OVERFLOW;
1117 /* Rounding */
1118 CONVERT_STR(VarUI1FromStr,"-1.5", LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
1119 CONVERT_STR(VarUI1FromStr,"-0.6", LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
1120 CONVERT_STR(VarUI1FromStr,"-0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1121 CONVERT_STR(VarUI1FromStr,"-0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1122 CONVERT_STR(VarUI1FromStr,"0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1123 CONVERT_STR(VarUI1FromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1124 CONVERT_STR(VarUI1FromStr,"0.6", LOCALE_NOUSEROVERRIDE); EXPECT(1);
1125 CONVERT_STR(VarUI1FromStr,"1.5", LOCALE_NOUSEROVERRIDE); EXPECT(2);
1128 static void test_VarUI1FromDisp(void)
1130 DummyDispatch dispatch;
1131 CONVVARS(LCID);
1132 VARIANTARG vSrc, vDst;
1134 CHECKPTR(VarUI1FromDisp);
1136 /* FIXME
1137 * Conversions from IDispatch should get the default 'value' property
1138 * from the IDispatch pointer and return it. The following tests this.
1139 * However, I can't get these tests to return a valid value under native
1140 * oleaut32, regardless of the value returned in response to the Invoke()
1141 * call (early versions of oleaut32 call AddRef/Release, but not Invoke.
1142 * I'm obviously missing something, as these conversions work fine
1143 * when called through VBA on an object to get its default value property.
1145 * Should this test be corrected so that it works under native it should be
1146 * generalised and the remaining types checked as well.
1148 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1150 VariantInit(&vSrc);
1151 VariantInit(&vDst);
1153 init_test_dispatch(1, VT_UI1, &dispatch);
1154 V_VT(&vSrc) = VT_DISPATCH;
1155 V_DISPATCH(&vSrc) = &dispatch.IDispatch_iface;
1157 SET_EXPECT(dispatch_invoke);
1158 out = 10;
1159 hres = pVarUI1FromDisp(&dispatch.IDispatch_iface, in, &out);
1160 ok(broken(hres == DISP_E_BADVARTYPE) || hres == S_OK, "got 0x%08x\n", hres);
1161 ok(broken(out == 10) || out == 1, "got %d\n", out);
1162 CHECK_CALLED(dispatch_invoke);
1164 SET_EXPECT(dispatch_invoke);
1165 V_VT(&vDst) = VT_EMPTY;
1166 V_UI1(&vDst) = 0;
1167 hres = VariantChangeTypeEx(&vDst, &vSrc, in, 0, VT_UI1);
1168 ok(hres == S_OK, "got 0x%08x\n", hres);
1169 ok(V_VT(&vDst) == VT_UI1, "got %d\n", V_VT(&vDst));
1170 ok(V_UI1(&vDst) == 1, "got %d\n", V_UI1(&vDst));
1171 CHECK_CALLED(dispatch_invoke);
1173 dispatch.bFailInvoke = TRUE;
1175 SET_EXPECT(dispatch_invoke);
1176 out = 10;
1177 hres = pVarUI1FromDisp(&dispatch.IDispatch_iface, in, &out);
1178 ok(hres == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hres);
1179 ok(out == 10, "got %d\n", out);
1180 CHECK_CALLED(dispatch_invoke);
1182 SET_EXPECT(dispatch_invoke);
1183 V_VT(&vDst) = VT_EMPTY;
1184 hres = VariantChangeTypeEx(&vDst, &vSrc, in, 0, VT_UI1);
1185 ok(hres == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hres);
1186 ok(V_VT(&vDst) == VT_EMPTY, "got %d\n", V_VT(&vDst));
1187 CHECK_CALLED(dispatch_invoke);
1190 static void test_VarUI1Copy(void)
1192 COPYTEST(1, VT_UI1, V_UI1(&vSrc), V_UI1(&vDst), V_UI1REF(&vSrc), V_UI1REF(&vDst), "%d");
1195 static void test_VarUI1ChangeTypeEx(void)
1197 HRESULT hres;
1198 BYTE in;
1199 VARIANTARG vSrc, vDst;
1201 in = 1;
1203 INITIAL_TYPETEST(VT_UI1, V_UI1, "%d");
1204 COMMON_TYPETEST;
1205 NEGATIVE_TYPETEST(VT_UI1, V_UI1, "%d", VT_I1, V_I1);
1209 * VT_I2/VT_UI2
1212 #undef CONV_TYPE
1213 #define CONV_TYPE SHORT
1215 static void test_VarI2FromI1(void)
1217 CONVVARS(signed char);
1218 int i;
1220 CHECKPTR(VarI2FromI1);
1221 CONVERTRANGE(VarI2FromI1, -128, 128);
1224 static void test_VarI2FromI4(void)
1226 CONVVARS(LONG);
1227 int i;
1229 CHECKPTR(VarI2FromI4);
1230 CONVERT(VarI2FromI4, -32769); EXPECT_OVERFLOW;
1231 CONVERTRANGE(VarI2FromI4, -32768, 32768);
1232 CONVERT(VarI2FromI4, 32768); EXPECT_OVERFLOW;
1235 static void test_VarI2FromI8(void)
1237 CONVVARS(LONG64);
1239 CHECKPTR(VarI2FromI8);
1240 CONVERT(VarI2FromI8, -32769); EXPECT_OVERFLOW;
1241 CONVERT(VarI2FromI8, -32768); EXPECT(-32768);
1242 CONVERT(VarI2FromI8, 32767); EXPECT(32767);
1243 CONVERT(VarI2FromI8, 32768); EXPECT_OVERFLOW;
1246 static void test_VarI2FromUI1(void)
1248 CONVVARS(BYTE);
1249 int i;
1251 CHECKPTR(VarI2FromUI1);
1252 CONVERTRANGE(VarI2FromUI1, 0, 256);
1255 static void test_VarI2FromUI2(void)
1257 CONVVARS(USHORT);
1258 int i;
1260 CHECKPTR(VarI2FromUI2);
1261 CONVERTRANGE(VarI2FromUI2, 0, 32768);
1262 CONVERT(VarI2FromUI2, 32768); EXPECT_OVERFLOW;
1265 static void test_VarI2FromUI4(void)
1267 CONVVARS(ULONG);
1268 int i;
1270 CHECKPTR(VarI2FromUI4);
1271 CONVERTRANGE(VarI2FromUI4, 0, 32768);
1272 CONVERT(VarI2FromUI4, 32768); EXPECT_OVERFLOW;
1275 static void test_VarI2FromUI8(void)
1277 CONVVARS(ULONG64);
1278 int i;
1280 CHECKPTR(VarI2FromUI8);
1281 CONVERTRANGE(VarI2FromUI8, 0, 32768);
1282 CONVERT(VarI2FromUI8, 32768); EXPECT_OVERFLOW;
1285 static void test_VarI2FromBool(void)
1287 CONVVARS(VARIANT_BOOL);
1288 int i;
1290 CHECKPTR(VarI2FromBool);
1291 CONVERTRANGE(VarI2FromBool, -32768, 32768);
1294 static void test_VarI2FromR4(void)
1296 CONVVARS(FLOAT);
1298 CHECKPTR(VarI2FromR4);
1299 CONVERT(VarI2FromR4, -32769.0f); EXPECT_OVERFLOW;
1300 CONVERT(VarI2FromR4, -32768.51f); EXPECT_OVERFLOW;
1301 CONVERT(VarI2FromR4, -32768.5f); EXPECT(-32768);
1302 CONVERT(VarI2FromR4, -32768.0f); EXPECT(-32768);
1303 CONVERT(VarI2FromR4, -1.0f); EXPECT(-1);
1304 CONVERT(VarI2FromR4, 0.0f); EXPECT(0);
1305 CONVERT(VarI2FromR4, 1.0f); EXPECT(1);
1306 CONVERT(VarI2FromR4, 32767.0f); EXPECT(32767);
1307 CONVERT(VarI2FromR4, 32767.49f); EXPECT(32767);
1308 CONVERT(VarI2FromR4, 32767.5f); EXPECT_OVERFLOW;
1309 CONVERT(VarI2FromR4, 32768.0f); EXPECT_OVERFLOW;
1311 /* Rounding */
1312 CONVERT(VarI2FromR4, -1.5f); EXPECT(-2);
1313 CONVERT(VarI2FromR4, -0.6f); EXPECT(-1);
1314 CONVERT(VarI2FromR4, -0.5f); EXPECT(0);
1315 CONVERT(VarI2FromR4, -0.4f); EXPECT(0);
1316 CONVERT(VarI2FromR4, 0.4f); EXPECT(0);
1317 CONVERT(VarI2FromR4, 0.5f); EXPECT(0);
1318 CONVERT(VarI2FromR4, 0.6f); EXPECT(1);
1319 CONVERT(VarI2FromR4, 1.5f); EXPECT(2);
1322 static void test_VarI2FromR8(void)
1324 CONVVARS(DOUBLE);
1326 CHECKPTR(VarI2FromR8);
1327 CONVERT(VarI2FromR8, -32769.0); EXPECT_OVERFLOW;
1328 CONVERT(VarI2FromR8, -32768.51); EXPECT_OVERFLOW;
1329 CONVERT(VarI2FromR8, -32768.5); EXPECT(-32768);
1330 CONVERT(VarI2FromR8, -32768.0); EXPECT(-32768);
1331 CONVERT(VarI2FromR8, -1.0); EXPECT(-1);
1332 CONVERT(VarI2FromR8, 0.0); EXPECT(0);
1333 CONVERT(VarI2FromR8, 1.0); EXPECT(1);
1334 CONVERT(VarI2FromR8, 32767.0); EXPECT(32767);
1335 CONVERT(VarI2FromR8, 32767.49); EXPECT(32767);
1336 CONVERT(VarI2FromR8, 32767.5); EXPECT_OVERFLOW;
1337 CONVERT(VarI2FromR8, 32768.0); EXPECT_OVERFLOW;
1339 /* Rounding */
1340 CONVERT(VarI2FromR8, -1.5); EXPECT(-2);
1341 CONVERT(VarI2FromR8, -0.6); EXPECT(-1);
1342 CONVERT(VarI2FromR8, -0.5); EXPECT(0);
1343 CONVERT(VarI2FromR8, -0.4); EXPECT(0);
1344 CONVERT(VarI2FromR8, 0.4); EXPECT(0);
1345 CONVERT(VarI2FromR8, 0.5); EXPECT(0);
1346 CONVERT(VarI2FromR8, 0.6); EXPECT(1);
1347 CONVERT(VarI2FromR8, 1.5); EXPECT(2);
1350 static void test_VarI2FromDate(void)
1352 CONVVARS(DATE);
1354 CHECKPTR(VarI2FromDate);
1355 CONVERT(VarI2FromDate, -32769.0); EXPECT_OVERFLOW;
1356 CONVERT(VarI2FromDate, -32768.0); EXPECT(-32768);
1357 CONVERT(VarI2FromDate, -1.0); EXPECT(-1);
1358 CONVERT(VarI2FromDate, 0.0); EXPECT(0);
1359 CONVERT(VarI2FromDate, 1.0); EXPECT(1);
1360 CONVERT(VarI2FromDate, 32767.0); EXPECT(32767);
1361 CONVERT(VarI2FromDate, 32768.0); EXPECT_OVERFLOW;
1363 /* Rounding */
1364 CONVERT(VarI2FromDate, -1.5); EXPECT(-2);
1365 CONVERT(VarI2FromDate, -0.6); EXPECT(-1);
1366 CONVERT(VarI2FromDate, -0.5); EXPECT(0);
1367 CONVERT(VarI2FromDate, -0.4); EXPECT(0);
1368 CONVERT(VarI2FromDate, 0.4); EXPECT(0);
1369 CONVERT(VarI2FromDate, 0.5); EXPECT(0);
1370 CONVERT(VarI2FromDate, 0.6); EXPECT(1);
1371 CONVERT(VarI2FromDate, 1.5); EXPECT(2);
1374 static void test_VarI2FromCy(void)
1376 CONVVARS(CY);
1378 CHECKPTR(VarI2FromCy);
1379 CONVERT_CY(VarI2FromCy,-32769); EXPECT_OVERFLOW;
1380 CONVERT_CY(VarI2FromCy,-32768); EXPECT(32768);
1381 CONVERT_CY(VarI2FromCy,-1); EXPECT(-1);
1382 CONVERT_CY(VarI2FromCy,0); EXPECT(0);
1383 CONVERT_CY(VarI2FromCy,1); EXPECT(1);
1384 CONVERT_CY(VarI2FromCy,32767); EXPECT(32767);
1385 CONVERT_CY(VarI2FromCy,32768); EXPECT_OVERFLOW;
1387 /* Rounding */
1388 CONVERT_CY(VarI2FromCy,-1.5); EXPECT(-2);
1389 CONVERT_CY(VarI2FromCy,-0.6); EXPECT(-1);
1390 CONVERT_CY(VarI2FromCy,-0.5); EXPECT(0);
1391 CONVERT_CY(VarI2FromCy,-0.4); EXPECT(0);
1392 CONVERT_CY(VarI2FromCy,0.4); EXPECT(0);
1393 CONVERT_CY(VarI2FromCy,0.5); EXPECT(0);
1394 CONVERT_CY(VarI2FromCy,0.6); EXPECT(1);
1395 CONVERT_CY(VarI2FromCy,1.5); EXPECT(2);
1398 static void test_VarI2FromDec(void)
1400 CONVVARS(DECIMAL);
1402 CHECKPTR(VarI2FromDec);
1404 CONVERT_BADDEC(VarI2FromDec);
1406 CONVERT_DEC(VarI2FromDec,0,0x80,0,32769); EXPECT_OVERFLOW;
1407 CONVERT_DEC(VarI2FromDec,0,0x80,0,32768); EXPECT(-32768);
1408 CONVERT_DEC(VarI2FromDec,0,0x80,0,1); EXPECT(-1);
1409 CONVERT_DEC(VarI2FromDec,0,0,0,0); EXPECT(0);
1410 CONVERT_DEC(VarI2FromDec,0,0,0,1); EXPECT(1);
1411 CONVERT_DEC(VarI2FromDec,0,0,0,32767); EXPECT(32767);
1412 CONVERT_DEC(VarI2FromDec,0,0,0,32768); EXPECT_OVERFLOW;
1414 CONVERT_DEC(VarI2FromDec,2,0x80,0,3276800); EXPECT(-32768);
1415 CONVERT_DEC(VarI2FromDec,2,0,0,3276700); EXPECT(32767);
1416 CONVERT_DEC(VarI2FromDec,2,0,0,3276800); EXPECT_OVERFLOW;
1419 static void test_VarI2FromStr(void)
1421 CONVVARS(LCID);
1422 OLECHAR buff[128];
1424 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1426 CHECKPTR(VarI2FromStr);
1428 CONVERT_STR(VarI2FromStr,NULL, 0); EXPECT_MISMATCH;
1429 CONVERT_STR(VarI2FromStr,"0", 0); EXPECT(0);
1430 CONVERT_STR(VarI2FromStr,"-32769", 0); EXPECT_OVERFLOW;
1431 CONVERT_STR(VarI2FromStr,"-32768", 0); EXPECT(-32768);
1432 CONVERT_STR(VarI2FromStr,"32767", 0); EXPECT(32767);
1433 CONVERT_STR(VarI2FromStr,"32768", 0); EXPECT_OVERFLOW;
1435 /* Rounding */
1436 CONVERT_STR(VarI2FromStr,"-1.5", LOCALE_NOUSEROVERRIDE); EXPECT(-2);
1437 CONVERT_STR(VarI2FromStr,"-0.6", LOCALE_NOUSEROVERRIDE); EXPECT(-1);
1438 CONVERT_STR(VarI2FromStr,"-0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1439 CONVERT_STR(VarI2FromStr,"-0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1440 CONVERT_STR(VarI2FromStr,"0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1441 CONVERT_STR(VarI2FromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1442 CONVERT_STR(VarI2FromStr,"0.6", LOCALE_NOUSEROVERRIDE); EXPECT(1);
1443 CONVERT_STR(VarI2FromStr,"1.5", LOCALE_NOUSEROVERRIDE); EXPECT(2);
1446 static void test_VarI2Copy(void)
1448 COPYTEST(1, VT_I2, V_I2(&vSrc), V_I2(&vDst), V_I2REF(&vSrc), V_I2REF(&vDst), "%d");
1451 static void test_VarI2ChangeTypeEx(void)
1453 HRESULT hres;
1454 SHORT in;
1455 VARIANTARG vSrc, vDst;
1457 in = 1;
1459 INITIAL_TYPETEST(VT_I2, V_I2, "%d");
1460 COMMON_TYPETEST;
1461 NEGATIVE_TYPETEST(VT_I2, V_I2, "%d", VT_UI2, V_UI2);
1464 #undef CONV_TYPE
1465 #define CONV_TYPE USHORT
1467 static void test_VarUI2FromI1(void)
1469 CONVVARS(signed char);
1470 int i;
1472 CHECKPTR(VarUI2FromI1);
1473 OVERFLOWRANGE(VarUI2FromI1, -128, 0);
1474 CONVERTRANGE(VarUI2FromI1, 0, 128);
1477 static void test_VarUI2FromI2(void)
1479 CONVVARS(SHORT);
1480 int i;
1482 CHECKPTR(VarUI2FromI2);
1483 OVERFLOWRANGE(VarUI2FromI2, -32768, 0);
1484 CONVERTRANGE(VarUI2FromI2, 0, 32768);
1487 static void test_VarUI2FromI4(void)
1489 CONVVARS(LONG);
1490 int i;
1492 CHECKPTR(VarUI2FromI4);
1493 OVERFLOWRANGE(VarUI2FromI4, -32768, 0);
1494 CONVERT(VarUI2FromI4, 0); EXPECT(0);
1495 CONVERT(VarUI2FromI4, 65535); EXPECT(65535);
1496 CONVERT(VarUI2FromI4, 65536); EXPECT_OVERFLOW;
1499 static void test_VarUI2FromI8(void)
1501 CONVVARS(LONG64);
1502 int i;
1504 CHECKPTR(VarUI2FromI8);
1505 OVERFLOWRANGE(VarUI2FromI8, -32768, 0);
1506 CONVERT(VarUI2FromI8, 0); EXPECT(0);
1507 CONVERT(VarUI2FromI8, 65535); EXPECT(65535);
1508 CONVERT(VarUI2FromI8, 65536); EXPECT_OVERFLOW;
1511 static void test_VarUI2FromUI1(void)
1513 CONVVARS(BYTE);
1514 int i;
1516 CHECKPTR(VarUI2FromUI1);
1517 CONVERTRANGE(VarUI2FromUI1, 0, 256);
1520 static void test_VarUI2FromUI4(void)
1522 CONVVARS(ULONG);
1524 CHECKPTR(VarUI2FromUI4);
1525 CONVERT(VarUI2FromUI4, 0); EXPECT(0);
1526 CONVERT(VarUI2FromUI4, 65535); EXPECT(65535);
1527 CONVERT(VarUI2FromUI4, 65536); EXPECT_OVERFLOW;
1530 static void test_VarUI2FromUI8(void)
1532 CONVVARS(ULONG64);
1534 CHECKPTR(VarUI2FromUI8);
1535 CONVERT(VarUI2FromUI8, 0); EXPECT(0);
1536 CONVERT(VarUI2FromUI8, 65535); EXPECT(65535);
1537 CONVERT(VarUI2FromUI8, 65536); EXPECT_OVERFLOW;
1540 static void test_VarUI2FromBool(void)
1542 CONVVARS(VARIANT_BOOL);
1543 int i;
1545 CHECKPTR(VarUI2FromBool);
1546 CONVERT(VarUI2FromBool, -1); EXPECT(65535); /* Wraps! */
1547 CONVERTRANGE(VarUI2FromBool, 0, 32768);
1550 static void test_VarUI2FromR4(void)
1552 CONVVARS(FLOAT);
1554 CHECKPTR(VarUI2FromR4);
1555 CONVERT(VarUI2FromR4, -1.0f); EXPECT_OVERFLOW;
1556 CONVERT(VarUI2FromR4, -0.51f); EXPECT_OVERFLOW;
1557 CONVERT(VarUI2FromR4, -0.5f); EXPECT(0);
1558 CONVERT(VarUI2FromR4, 0.0f); EXPECT(0);
1559 CONVERT(VarUI2FromR4, 1.0f); EXPECT(1);
1560 CONVERT(VarUI2FromR4, 65535.0f); EXPECT(65535);
1561 CONVERT(VarUI2FromR4, 65535.49f); EXPECT(65535);
1562 CONVERT(VarUI2FromR4, 65535.5f); EXPECT_OVERFLOW;
1563 CONVERT(VarUI2FromR4, 65536.0f); EXPECT_OVERFLOW;
1565 /* Rounding */
1566 CONVERT(VarUI2FromR4, -1.5f); EXPECT_OVERFLOW;
1567 CONVERT(VarUI2FromR4, -0.6f); EXPECT_OVERFLOW;
1568 CONVERT(VarUI2FromR4, -0.5f); EXPECT(0);
1569 CONVERT(VarUI2FromR4, -0.4f); EXPECT(0);
1570 CONVERT(VarUI2FromR4, 0.4f); EXPECT(0);
1571 CONVERT(VarUI2FromR4, 0.5f); EXPECT(0);
1572 CONVERT(VarUI2FromR4, 0.6f); EXPECT(1);
1573 CONVERT(VarUI2FromR4, 1.5f); EXPECT(2);
1576 static void test_VarUI2FromR8(void)
1578 CONVVARS(DOUBLE);
1580 CHECKPTR(VarUI2FromR8);
1581 CONVERT(VarUI2FromR8, -1.0); EXPECT_OVERFLOW;
1582 CONVERT(VarUI2FromR8, -0.51); EXPECT_OVERFLOW;
1583 CONVERT(VarUI2FromR8, -0.5); EXPECT(0);
1584 CONVERT(VarUI2FromR8, 0.0); EXPECT(0);
1585 CONVERT(VarUI2FromR8, 1.0); EXPECT(1);
1586 CONVERT(VarUI2FromR8, 65535.0); EXPECT(65535);
1587 CONVERT(VarUI2FromR8, 65535.49); EXPECT(65535);
1588 CONVERT(VarUI2FromR8, 65535.5); EXPECT_OVERFLOW;
1589 CONVERT(VarUI2FromR8, 65536.0); EXPECT_OVERFLOW;
1591 /* Rounding */
1592 CONVERT(VarUI2FromR8, -1.5); EXPECT_OVERFLOW;
1593 CONVERT(VarUI2FromR8, -0.6); EXPECT_OVERFLOW;
1594 CONVERT(VarUI2FromR8, -0.5); EXPECT(0);
1595 CONVERT(VarUI2FromR8, -0.4); EXPECT(0);
1596 CONVERT(VarUI2FromR8, 0.4); EXPECT(0);
1597 CONVERT(VarUI2FromR8, 0.5); EXPECT(0);
1598 CONVERT(VarUI2FromR8, 0.6); EXPECT(1);
1599 CONVERT(VarUI2FromR8, 1.5); EXPECT(2);
1602 static void test_VarUI2FromDate(void)
1604 CONVVARS(DATE);
1606 CHECKPTR(VarUI2FromDate);
1607 CONVERT(VarUI2FromDate, -1.0); EXPECT_OVERFLOW;
1608 CONVERT(VarUI2FromDate, 0.0); EXPECT(0);
1609 CONVERT(VarUI2FromDate, 1.0); EXPECT(1);
1610 CONVERT(VarUI2FromDate, 65535.0); EXPECT(65535);
1611 CONVERT(VarUI2FromDate, 65536.0); EXPECT_OVERFLOW;
1613 /* Rounding */
1614 CONVERT(VarUI2FromDate, -1.5); EXPECT_OVERFLOW;
1615 CONVERT(VarUI2FromDate, -0.6); EXPECT_OVERFLOW;
1616 CONVERT(VarUI2FromDate, -0.5); EXPECT(0);
1617 CONVERT(VarUI2FromDate, -0.4); EXPECT(0);
1618 CONVERT(VarUI2FromDate, 0.4); EXPECT(0);
1619 CONVERT(VarUI2FromDate, 0.5); EXPECT(0);
1620 CONVERT(VarUI2FromDate, 0.6); EXPECT(1);
1621 CONVERT(VarUI2FromDate, 1.5); EXPECT(2);
1624 static void test_VarUI2FromCy(void)
1626 CONVVARS(CY);
1628 CHECKPTR(VarUI2FromCy);
1629 CONVERT_CY(VarUI2FromCy,-1); EXPECT_OVERFLOW;
1630 CONVERT_CY(VarUI2FromCy,0); EXPECT(0);
1631 CONVERT_CY(VarUI2FromCy,1); EXPECT(1);
1632 CONVERT_CY(VarUI2FromCy,65535); EXPECT(65535);
1633 CONVERT_CY(VarUI2FromCy,65536); EXPECT_OVERFLOW;
1635 /* Rounding */
1636 CONVERT_CY(VarUI2FromCy,-1.5); EXPECT_OVERFLOW;
1637 CONVERT_CY(VarUI2FromCy,-0.6); EXPECT_OVERFLOW;
1638 CONVERT_CY(VarUI2FromCy,-0.5); EXPECT(0);
1639 CONVERT_CY(VarUI2FromCy,-0.4); EXPECT(0);
1640 CONVERT_CY(VarUI2FromCy,0.4); EXPECT(0);
1641 CONVERT_CY(VarUI2FromCy,0.5); EXPECT(0);
1642 CONVERT_CY(VarUI2FromCy,0.6); EXPECT(1);
1643 CONVERT_CY(VarUI2FromCy,1.5); EXPECT(2);
1646 static void test_VarUI2FromDec(void)
1648 CONVVARS(DECIMAL);
1650 CHECKPTR(VarUI2FromDec);
1652 CONVERT_BADDEC(VarUI2FromDec);
1654 CONVERT_DEC(VarUI2FromDec,0,0x80,0,1); EXPECT_OVERFLOW;
1655 CONVERT_DEC(VarUI2FromDec,0,0,0,0); EXPECT(0);
1656 CONVERT_DEC(VarUI2FromDec,0,0,0,1); EXPECT(1);
1657 CONVERT_DEC(VarUI2FromDec,0,0,0,65535); EXPECT(65535);
1658 CONVERT_DEC(VarUI2FromDec,0,0,0,65536); EXPECT_OVERFLOW;
1660 CONVERT_DEC(VarUI2FromDec,2,0x80,0,100); EXPECT_OVERFLOW;
1661 CONVERT_DEC(VarUI2FromDec,2,0,0,6553500); EXPECT(65535);
1662 CONVERT_DEC(VarUI2FromDec,2,0,0,6553600); EXPECT_OVERFLOW;
1665 static void test_VarUI2FromStr(void)
1667 CONVVARS(LCID);
1668 OLECHAR buff[128];
1670 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1672 CHECKPTR(VarUI2FromStr);
1674 CONVERT_STR(VarUI2FromStr,NULL, 0); EXPECT_MISMATCH;
1675 CONVERT_STR(VarUI2FromStr,"0", 0); EXPECT(0);
1676 CONVERT_STR(VarUI2FromStr,"-1", 0); EXPECT_OVERFLOW;
1677 CONVERT_STR(VarUI2FromStr,"65535", 0); EXPECT(65535);
1678 CONVERT_STR(VarUI2FromStr,"65536", 0); EXPECT_OVERFLOW;
1680 /* Rounding */
1681 CONVERT_STR(VarUI2FromStr,"-1.5", LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
1682 CONVERT_STR(VarUI2FromStr,"-0.6", LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
1683 CONVERT_STR(VarUI2FromStr,"-0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1684 CONVERT_STR(VarUI2FromStr,"-0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1685 CONVERT_STR(VarUI2FromStr,"0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1686 CONVERT_STR(VarUI2FromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1687 CONVERT_STR(VarUI2FromStr,"0.6", LOCALE_NOUSEROVERRIDE); EXPECT(1);
1688 CONVERT_STR(VarUI2FromStr,"1.5", LOCALE_NOUSEROVERRIDE); EXPECT(2);
1691 static void test_VarUI2Copy(void)
1693 COPYTEST(1, VT_UI2, V_UI2(&vSrc), V_UI2(&vDst), V_UI2REF(&vSrc), V_UI2REF(&vDst), "%d");
1696 static void test_VarUI2ChangeTypeEx(void)
1698 HRESULT hres;
1699 USHORT in;
1700 VARIANTARG vSrc, vDst;
1702 in = 1;
1704 INITIAL_TYPETEST(VT_UI2, V_UI2, "%d");
1705 COMMON_TYPETEST;
1706 NEGATIVE_TYPETEST(VT_UI2, V_UI2, "%d", VT_I2, V_I2);
1710 * VT_I4/VT_UI4
1713 #undef CONV_TYPE
1714 #define CONV_TYPE LONG
1716 static void test_VarI4FromI1(void)
1718 CONVVARS(signed char);
1719 int i;
1721 CHECKPTR(VarI4FromI1);
1722 CONVERTRANGE(VarI4FromI1, -128, 128);
1725 static void test_VarI4FromI2(void)
1727 CONVVARS(SHORT);
1728 int i;
1730 CHECKPTR(VarI4FromI2);
1731 CONVERTRANGE(VarI4FromI2, -32768, 32768);
1734 static void test_VarI4FromI8(void)
1736 CONVVARS(LONG64);
1738 CHECKPTR(VarI4FromI8);
1739 CHECKPTR(VarI4FromDec);
1741 CONVERT(VarI4FromI8, -1); EXPECT(-1);
1742 CONVERT(VarI4FromI8, 0); EXPECT(0);
1743 CONVERT(VarI4FromI8, 1); EXPECT(1);
1745 CONVERT_I8(VarI4FromI8, -1, 2147483647ul); EXPECT_OVERFLOW;
1746 CONVERT_I8(VarI4FromI8, -1, 2147483648ul); EXPECT(-2147483647 - 1);
1747 CONVERT_I8(VarI4FromI8, 0, 2147483647ul); EXPECT(2147483647);
1748 CONVERT_I8(VarI4FromI8, 0, 2147483648ul); EXPECT_OVERFLOW;
1751 static void test_VarI4FromUI1(void)
1753 CONVVARS(BYTE);
1754 int i;
1756 CHECKPTR(VarI4FromUI1);
1757 CONVERTRANGE(VarI4FromUI1, 0, 256);
1760 static void test_VarI4FromUI2(void)
1762 CONVVARS(USHORT);
1763 int i;
1765 CHECKPTR(VarI4FromUI2);
1766 CONVERTRANGE(VarI4FromUI2, 0, 65536);
1769 static void test_VarI4FromUI4(void)
1771 CONVVARS(ULONG);
1773 CHECKPTR(VarI4FromUI4);
1774 CONVERT(VarI4FromUI4, 0); EXPECT(0);
1775 CONVERT(VarI4FromUI4, 1); EXPECT(1);
1776 CONVERT(VarI4FromUI4, 2147483647); EXPECT(2147483647);
1777 CONVERT(VarI4FromUI4, 2147483648ul); EXPECT_OVERFLOW;
1780 static void test_VarI4FromUI8(void)
1782 CONVVARS(ULONG64);
1784 CHECKPTR(VarI4FromUI8);
1785 CONVERT(VarI4FromUI8, 0); EXPECT(0);
1786 CONVERT(VarI4FromUI8, 1); EXPECT(1);
1787 CONVERT(VarI4FromUI8, 2147483647); EXPECT(2147483647);
1788 CONVERT(VarI4FromUI8, 2147483648ul); EXPECT_OVERFLOW;
1791 static void test_VarI4FromBool(void)
1793 CONVVARS(VARIANT_BOOL);
1794 int i;
1796 CHECKPTR(VarI4FromBool);
1797 CONVERTRANGE(VarI4FromBool, -32768, 32768);
1800 static void test_VarI4FromR4(void)
1802 CONVVARS(FLOAT);
1804 CHECKPTR(VarI4FromR4);
1806 /* min/max values are not exactly representable in a float */
1807 CONVERT(VarI4FromR4, -1.0f); EXPECT(-1);
1808 CONVERT(VarI4FromR4, 0.0f); EXPECT(0);
1809 CONVERT(VarI4FromR4, 1.0f); EXPECT(1);
1811 CONVERT(VarI4FromR4, -1.5f); EXPECT(-2);
1812 CONVERT(VarI4FromR4, -0.6f); EXPECT(-1);
1813 CONVERT(VarI4FromR4, -0.5f); EXPECT(0);
1814 CONVERT(VarI4FromR4, -0.4f); EXPECT(0);
1815 CONVERT(VarI4FromR4, 0.4f); EXPECT(0);
1816 CONVERT(VarI4FromR4, 0.5f); EXPECT(0);
1817 CONVERT(VarI4FromR4, 0.6f); EXPECT(1);
1818 CONVERT(VarI4FromR4, 1.5f); EXPECT(2);
1821 static void test_VarI4FromR8(void)
1823 CONVVARS(DOUBLE);
1825 CHECKPTR(VarI4FromR8);
1826 CONVERT(VarI4FromR8, -2147483649.0); EXPECT_OVERFLOW;
1827 CONVERT(VarI4FromR8, -2147483648.51); EXPECT_OVERFLOW;
1828 CONVERT(VarI4FromR8, -2147483648.5); EXPECT(-2147483647 - 1);
1829 CONVERT(VarI4FromR8, -2147483648.0); EXPECT(-2147483647 - 1);
1830 CONVERT(VarI4FromR8, -1.0); EXPECT(-1);
1831 CONVERT(VarI4FromR8, 0.0); EXPECT(0);
1832 CONVERT(VarI4FromR8, 1.0); EXPECT(1);
1833 CONVERT(VarI4FromR8, 2147483647.0); EXPECT(2147483647);
1834 CONVERT(VarI4FromR8, 2147483647.49); EXPECT(2147483647);
1835 CONVERT(VarI4FromR8, 2147483647.5); EXPECT_OVERFLOW;
1836 CONVERT(VarI4FromR8, 2147483648.0); EXPECT_OVERFLOW;
1838 CONVERT(VarI4FromR8, -1.5); EXPECT(-2);
1839 CONVERT(VarI4FromR8, -0.6); EXPECT(-1);
1840 CONVERT(VarI4FromR8, -0.5); EXPECT(0);
1841 CONVERT(VarI4FromR8, -0.4); EXPECT(0);
1842 CONVERT(VarI4FromR8, 0.4); EXPECT(0);
1843 CONVERT(VarI4FromR8, 0.5); EXPECT(0);
1844 CONVERT(VarI4FromR8, 0.6); EXPECT(1);
1845 CONVERT(VarI4FromR8, 1.5); EXPECT(2);
1848 static void test_VarI4FromDate(void)
1850 CONVVARS(DATE);
1852 CHECKPTR(VarI4FromDate);
1853 CONVERT(VarI4FromDate, -2147483649.0); EXPECT_OVERFLOW;
1854 CONVERT(VarI4FromDate, -2147483648.0); EXPECT(-2147483647 - 1);
1855 CONVERT(VarI4FromDate, -1.0); EXPECT(-1);
1856 CONVERT(VarI4FromDate, 0.0); EXPECT(0);
1857 CONVERT(VarI4FromDate, 1.0); EXPECT(1);
1858 CONVERT(VarI4FromDate, 2147483647.0); EXPECT(2147483647);
1859 CONVERT(VarI4FromDate, 2147483648.0); EXPECT_OVERFLOW;
1861 CONVERT(VarI4FromDate, -1.5); EXPECT(-2);
1862 CONVERT(VarI4FromDate, -0.6); EXPECT(-1);
1863 CONVERT(VarI4FromDate, -0.5); EXPECT(0);
1864 CONVERT(VarI4FromDate, -0.4); EXPECT(0);
1865 CONVERT(VarI4FromDate, 0.4); EXPECT(0);
1866 CONVERT(VarI4FromDate, 0.5); EXPECT(0);
1867 CONVERT(VarI4FromDate, 0.6); EXPECT(1);
1868 CONVERT(VarI4FromDate, 1.5); EXPECT(2);
1871 static void test_VarI4FromCy(void)
1873 CONVVARS(CY);
1875 CHECKPTR(VarI4FromCy);
1876 CONVERT_CY(VarI4FromCy,-1); EXPECT(-1);
1877 CONVERT_CY(VarI4FromCy,0); EXPECT(0);
1878 CONVERT_CY(VarI4FromCy,1); EXPECT(1);
1880 CONVERT_CY64(VarI4FromCy,-1,2147483647ul); EXPECT_OVERFLOW;
1881 CONVERT_CY64(VarI4FromCy,-1,2147483648ul); EXPECT(-2147483647 - 1);
1882 CONVERT_CY64(VarI4FromCy,0,2147483647ul); EXPECT(2147483647ul);
1883 CONVERT_CY64(VarI4FromCy,0,2147483648ul); EXPECT_OVERFLOW;
1885 CONVERT_CY(VarI4FromCy,-1.5); EXPECT(-2);
1886 CONVERT_CY(VarI4FromCy,-0.6); EXPECT(-1);
1887 CONVERT_CY(VarI4FromCy,-0.5); EXPECT(0);
1888 CONVERT_CY(VarI4FromCy,-0.4); EXPECT(0);
1889 CONVERT_CY(VarI4FromCy,0.4); EXPECT(0);
1890 CONVERT_CY(VarI4FromCy,0.5); EXPECT(0);
1891 CONVERT_CY(VarI4FromCy,0.6); EXPECT(1);
1892 CONVERT_CY(VarI4FromCy,1.5); EXPECT(2);
1895 static void test_VarI4FromDec(void)
1897 CONVVARS(DECIMAL);
1899 CHECKPTR(VarI4FromDec);
1901 CONVERT_BADDEC(VarI4FromDec);
1903 CONVERT_DEC(VarI4FromDec,0,0x80,0,1); EXPECT(-1);
1904 CONVERT_DEC(VarI4FromDec,0,0,0,0); EXPECT(0);
1905 CONVERT_DEC(VarI4FromDec,0,0,0,1); EXPECT(1);
1907 CONVERT_DEC64(VarI4FromDec,0,0x80,0,0,2147483649ul); EXPECT_OVERFLOW;
1908 CONVERT_DEC64(VarI4FromDec,0,0x80,0,0,2147483648ul); EXPECT(-2147483647 - 1);
1909 CONVERT_DEC64(VarI4FromDec,0,0,0,0,2147483647ul); EXPECT(2147483647ul);
1910 CONVERT_DEC64(VarI4FromDec,0,0,0,0,2147483648ul); EXPECT_OVERFLOW;
1912 CONVERT_DEC64(VarI4FromDec,2,0x80,0,50,100); EXPECT_OVERFLOW;
1913 CONVERT_DEC64(VarI4FromDec,2,0x80,0,50,0); EXPECT(-2147483647 - 1);
1914 CONVERT_DEC64(VarI4FromDec,2,0,0,49,4294967196ul); EXPECT(2147483647);
1915 CONVERT_DEC64(VarI4FromDec,2,0,0,50,0); EXPECT_OVERFLOW;
1918 static void test_VarI4FromStr(void)
1920 CONVVARS(LCID);
1921 OLECHAR buff[128];
1923 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1925 CHECKPTR(VarI4FromStr);
1927 CONVERT_STR(VarI4FromStr,NULL,0); EXPECT_MISMATCH;
1928 CONVERT_STR(VarI4FromStr,"0",0); EXPECT(0);
1929 CONVERT_STR(VarI4FromStr,"-2147483649",0); EXPECT_OVERFLOW;
1930 CONVERT_STR(VarI4FromStr,"-2147483648",0); EXPECT(-2147483647 -1);
1931 CONVERT_STR(VarI4FromStr,"2147483647",0); EXPECT(2147483647);
1932 CONVERT_STR(VarI4FromStr,"2147483648",0); EXPECT_OVERFLOW;
1934 /* Rounding */
1935 CONVERT_STR(VarI4FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECT(-2);
1936 CONVERT_STR(VarI4FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECT(-1);
1937 CONVERT_STR(VarI4FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0);
1938 CONVERT_STR(VarI4FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0);
1939 CONVERT_STR(VarI4FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0);
1940 CONVERT_STR(VarI4FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0);
1941 CONVERT_STR(VarI4FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECT(1);
1942 CONVERT_STR(VarI4FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECT(2);
1945 static void test_VarI4Copy(void)
1947 COPYTEST(1, VT_I4, V_I4(&vSrc), V_I4(&vDst), V_I4REF(&vSrc), V_I4REF(&vDst), "%d");
1950 static void test_VarI4ChangeTypeEx(void)
1952 HRESULT hres;
1953 LONG in;
1954 VARIANTARG vSrc, vDst;
1956 in = 1;
1958 INITIAL_TYPETEST(VT_I4, V_I4, "%d");
1959 COMMON_TYPETEST;
1960 NEGATIVE_TYPETEST(VT_I4, V_I4, "%d", VT_UI4, V_UI4);
1963 #undef CONV_TYPE
1964 #define CONV_TYPE ULONG
1965 #undef EXPECTRES
1966 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%u")
1968 static void test_VarUI4FromI1(void)
1970 CONVVARS(signed char);
1971 int i;
1973 CHECKPTR(VarUI4FromI1);
1974 OVERFLOWRANGE(VarUI4FromI1, -127, 0);
1975 CONVERTRANGE(VarUI4FromI1, 0, 128);
1978 static void test_VarUI4FromI2(void)
1980 CONVVARS(SHORT);
1981 int i;
1983 CHECKPTR(VarUI4FromI2);
1984 OVERFLOWRANGE(VarUI4FromI2, -32768, 0);
1985 CONVERTRANGE(VarUI4FromI2, 0, 32768);
1988 static void test_VarUI4FromUI2(void)
1990 CONVVARS(USHORT);
1991 int i;
1993 CHECKPTR(VarUI4FromUI2);
1994 CONVERTRANGE(VarUI4FromUI2, 0, 65536);
1997 static void test_VarUI4FromI8(void)
1999 CONVVARS(LONG64);
2001 CHECKPTR(VarUI4FromI8);
2002 CONVERT(VarUI4FromI8, -1); EXPECT_OVERFLOW;
2003 CONVERT(VarUI4FromI8, 0); EXPECT(0);
2004 CONVERT(VarUI4FromI8, 1); EXPECT(1);
2005 CONVERT(VarUI4FromI8, 4294967295ul); EXPECT(4294967295ul);
2006 CONVERT_I8(VarUI4FromI8, 1, 0); EXPECT_OVERFLOW;
2009 static void test_VarUI4FromUI1(void)
2011 CONVVARS(BYTE);
2012 int i;
2014 CHECKPTR(VarUI4FromUI1);
2015 CONVERTRANGE(VarUI4FromUI1, 0, 256);
2018 static void test_VarUI4FromI4(void)
2020 CONVVARS(int);
2022 CHECKPTR(VarUI4FromI4);
2023 CONVERT(VarUI4FromI4, -1); EXPECT_OVERFLOW;
2024 CONVERT(VarUI4FromI4, 0); EXPECT(0);
2025 CONVERT(VarUI4FromI4, 1); EXPECT(1);
2026 CONVERT(VarUI4FromI4, 2147483647); EXPECT(2147483647);
2029 static void test_VarUI4FromUI8(void)
2031 CONVVARS(ULONG64);
2033 CHECKPTR(VarUI4FromUI8);
2034 CONVERT(VarUI4FromUI8, 0); EXPECT(0);
2035 CONVERT(VarUI4FromUI8, 1); EXPECT(1);
2036 CONVERT(VarUI4FromI8, 4294967295ul); EXPECT(4294967295ul);
2037 CONVERT_I8(VarUI4FromI8, 1, 0); EXPECT_OVERFLOW;
2040 static void test_VarUI4FromBool(void)
2042 CONVVARS(VARIANT_BOOL);
2043 int i;
2045 CHECKPTR(VarUI4FromBool);
2046 CONVERTRANGE(VarUI4FromBool, -32768, 32768);
2049 static void test_VarUI4FromR4(void)
2051 CONVVARS(FLOAT);
2053 CHECKPTR(VarUI4FromR4);
2054 /* We can't test max values as they are not exactly representable in a float */
2055 CONVERT(VarUI4FromR4, -1.0f); EXPECT_OVERFLOW;
2056 CONVERT(VarUI4FromR4, -0.51f); EXPECT_OVERFLOW;
2057 CONVERT(VarUI4FromR4, -0.5f); EXPECT(0);
2058 CONVERT(VarUI4FromR4, 0.0f); EXPECT(0);
2059 CONVERT(VarUI4FromR4, 1.0f); EXPECT(1);
2061 CONVERT(VarUI4FromR4, -1.5f); EXPECT_OVERFLOW;
2062 CONVERT(VarUI4FromR4, -0.6f); EXPECT_OVERFLOW;
2063 CONVERT(VarUI4FromR4, -0.5f); EXPECT(0);
2064 CONVERT(VarUI4FromR4, -0.4f); EXPECT(0);
2065 CONVERT(VarUI4FromR4, 0.4f); EXPECT(0);
2066 CONVERT(VarUI4FromR4, 0.5f); EXPECT(0);
2067 CONVERT(VarUI4FromR4, 0.6f); EXPECT(1);
2068 CONVERT(VarUI4FromR4, 1.5f); EXPECT(2);
2072 static void test_VarUI4FromR8(void)
2074 CONVVARS(DOUBLE);
2076 CHECKPTR(VarUI4FromR8);
2077 CONVERT(VarUI4FromR8, -1.0); EXPECT_OVERFLOW;
2078 CONVERT(VarUI4FromR4, -0.51f); EXPECT_OVERFLOW;
2079 CONVERT(VarUI4FromR4, -0.5f); EXPECT(0);
2080 CONVERT(VarUI4FromR8, 0.0); EXPECT(0);
2081 CONVERT(VarUI4FromR8, 1.0); EXPECT(1);
2082 CONVERT(VarUI4FromR8, 4294967295.0); EXPECT(4294967295ul);
2083 CONVERT(VarUI4FromR8, 4294967295.49); EXPECT(4294967295ul);
2084 CONVERT(VarUI4FromR8, 4294967295.5); EXPECT_OVERFLOW;
2085 CONVERT(VarUI4FromR8, 4294967296.0); EXPECT_OVERFLOW;
2087 CONVERT(VarUI4FromR8, -1.5); EXPECT_OVERFLOW;
2088 CONVERT(VarUI4FromR8, -0.6); EXPECT_OVERFLOW;
2089 CONVERT(VarUI4FromR8, -0.5); EXPECT(0);
2090 CONVERT(VarUI4FromR8, -0.4); EXPECT(0);
2091 CONVERT(VarUI4FromR8, 0.4); EXPECT(0);
2092 CONVERT(VarUI4FromR8, 0.5); EXPECT(0);
2093 CONVERT(VarUI4FromR8, 0.6); EXPECT(1);
2094 CONVERT(VarUI4FromR8, 1.5); EXPECT(2);
2097 static void test_VarUI4FromDate(void)
2099 CONVVARS(DOUBLE);
2101 CHECKPTR(VarUI4FromDate);
2102 CONVERT(VarUI4FromDate, -1.0); EXPECT_OVERFLOW;
2103 CONVERT(VarUI4FromDate, 0.0); EXPECT(0);
2104 CONVERT(VarUI4FromDate, 1.0); EXPECT(1);
2105 CONVERT(VarUI4FromDate, 4294967295.0); EXPECT(4294967295ul);
2106 CONVERT(VarUI4FromDate, 4294967296.0); EXPECT_OVERFLOW;
2108 CONVERT(VarUI4FromDate, -1.5); EXPECT_OVERFLOW;
2109 CONVERT(VarUI4FromDate, -0.6); EXPECT_OVERFLOW;
2110 CONVERT(VarUI4FromDate, -0.5); EXPECT(0);
2111 CONVERT(VarUI4FromDate, -0.4); EXPECT(0);
2112 CONVERT(VarUI4FromDate, 0.4); EXPECT(0);
2113 CONVERT(VarUI4FromDate, 0.5); EXPECT(0);
2114 CONVERT(VarUI4FromDate, 0.6); EXPECT(1);
2115 CONVERT(VarUI4FromDate, 1.5); EXPECT(2);
2118 static void test_VarUI4FromCy(void)
2120 CONVVARS(CY);
2122 CHECKPTR(VarUI4FromCy);
2123 CONVERT_CY(VarUI4FromCy,-1); EXPECT_OVERFLOW;
2124 CONVERT_CY(VarUI4FromCy,0); EXPECT(0);
2125 CONVERT_CY(VarUI4FromCy,1); EXPECT(1);
2126 CONVERT_CY64(VarUI4FromCy,0,4294967295ul); EXPECT(4294967295ul);
2127 CONVERT_CY64(VarUI4FromCy,1,0); EXPECT_OVERFLOW;
2129 CONVERT_CY(VarUI4FromCy,-1.5); EXPECT_OVERFLOW;
2130 CONVERT_CY(VarUI4FromCy,-0.6); EXPECT_OVERFLOW;
2131 CONVERT_CY(VarUI4FromCy,-0.5); EXPECT(0);
2132 CONVERT_CY(VarUI4FromCy,-0.4); EXPECT(0);
2133 CONVERT_CY(VarUI4FromCy,0.4); EXPECT(0);
2134 CONVERT_CY(VarUI4FromCy,0.5); EXPECT(0);
2135 CONVERT_CY(VarUI4FromCy,0.6); EXPECT(1);
2136 CONVERT_CY(VarUI4FromCy,1.5); EXPECT(2);
2139 static void test_VarUI4FromDec(void)
2141 CONVVARS(DECIMAL);
2143 CHECKPTR(VarUI4FromDec);
2145 CONVERT_BADDEC(VarUI4FromDec);
2147 CONVERT_DEC(VarUI4FromDec,0,0x80,0,1); EXPECT_OVERFLOW;
2148 CONVERT_DEC(VarUI4FromDec,0,0,0,0); EXPECT(0);
2149 CONVERT_DEC(VarUI4FromDec,0,0,0,1); EXPECT(1);
2150 CONVERT_DEC64(VarUI4FromDec,0,0,0,0,4294967295ul); EXPECT(4294967295ul);
2151 CONVERT_DEC64(VarUI4FromDec,0,0,0,1,0); EXPECT_OVERFLOW;
2153 CONVERT_DEC64(VarUI4FromDec,2,0,0,99,4294967196ul); EXPECT(4294967295ul);
2154 CONVERT_DEC64(VarUI4FromDec,2,0,0,100,0); EXPECT_OVERFLOW;
2157 static void test_VarUI4FromStr(void)
2159 CONVVARS(LCID);
2160 OLECHAR buff[128];
2162 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2164 CHECKPTR(VarUI4FromStr);
2166 CONVERT_STR(VarUI4FromStr,NULL,0); EXPECT_MISMATCH;
2167 CONVERT_STR(VarUI4FromStr,"-1",0); EXPECT_OVERFLOW;
2168 CONVERT_STR(VarUI4FromStr,"0",0); EXPECT(0);
2169 CONVERT_STR(VarUI4FromStr,"4294967295",0); EXPECT(4294967295ul);
2170 CONVERT_STR(VarUI4FromStr,"4294967296",0); EXPECT_OVERFLOW;
2172 /* Rounding */
2173 CONVERT_STR(VarUI4FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
2174 CONVERT_STR(VarUI4FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
2175 CONVERT_STR(VarUI4FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0);
2176 CONVERT_STR(VarUI4FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0);
2177 CONVERT_STR(VarUI4FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0);
2178 CONVERT_STR(VarUI4FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0);
2179 CONVERT_STR(VarUI4FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECT(1);
2180 CONVERT_STR(VarUI4FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECT(2);
2183 static void test_VarUI4Copy(void)
2185 COPYTEST(1u, VT_UI4, V_UI4(&vSrc), V_UI4(&vDst), V_UI4REF(&vSrc), V_UI4REF(&vDst), "%u");
2188 static void test_VarUI4ChangeTypeEx(void)
2190 HRESULT hres;
2191 ULONG in;
2192 VARIANTARG vSrc, vDst;
2194 in = 1;
2196 INITIAL_TYPETEST(VT_UI4, V_UI4, "%u");
2197 COMMON_TYPETEST;
2198 NEGATIVE_TYPETEST(VT_UI4, V_UI4, "%u", VT_I4, V_I4);
2202 * VT_I8/VT_UI8
2205 #undef CONV_TYPE
2206 #define CONV_TYPE LONG64
2208 #define EXPECTI8(x) \
2209 ok((hres == S_OK && out == (CONV_TYPE)(x)), \
2210 "expected " #x "(%u,%u), got (%u,%u); hres=0x%08x\n", \
2211 (ULONG)((LONG64)(x) >> 32), (ULONG)((x) & 0xffffffff), \
2212 (ULONG)(out >> 32), (ULONG)(out & 0xffffffff), hres)
2214 #define EXPECTI864(x,y) \
2215 ok(hres == S_OK && (out >> 32) == (CONV_TYPE)(x) && (out & 0xffffffff) == (CONV_TYPE)(y), \
2216 "expected " #x "(%u,%u), got (%u,%u); hres=0x%08x\n", \
2217 (ULONG)(x), (ULONG)(y), \
2218 (ULONG)(out >> 32), (ULONG)(out & 0xffffffff), hres)
2220 static void test_VarI8FromI1(void)
2222 CONVVARS(signed char);
2223 int i;
2225 CHECKPTR(VarI8FromI1);
2226 for (i = -128; i < 128; i++)
2228 CONVERT(VarI8FromI1,i); EXPECTI8(i);
2232 static void test_VarI8FromUI1(void)
2234 CONVVARS(BYTE);
2235 int i;
2237 CHECKPTR(VarI8FromUI1);
2238 for (i = 0; i < 256; i++)
2240 CONVERT(VarI8FromUI1,i); EXPECTI8(i);
2244 static void test_VarI8FromI2(void)
2246 CONVVARS(SHORT);
2247 int i;
2249 CHECKPTR(VarI8FromI2);
2250 for (i = -32768; i < 32768; i++)
2252 CONVERT(VarI8FromI2,i); EXPECTI8(i);
2256 static void test_VarI8FromUI2(void)
2258 CONVVARS(USHORT);
2259 int i;
2261 CHECKPTR(VarI8FromUI2);
2262 for (i = -0; i < 65535; i++)
2264 CONVERT(VarI8FromUI2,i); EXPECTI8(i);
2268 static void test_VarI8FromUI4(void)
2270 CONVVARS(ULONG);
2272 CHECKPTR(VarI8FromUI4);
2273 CONVERT(VarI8FromUI4, 0); EXPECTI8(0);
2274 CONVERT(VarI8FromUI4, 1); EXPECTI8(1);
2275 CONVERT(VarI8FromUI4, 4294967295ul); EXPECTI8(4294967295ul);
2278 static void test_VarI8FromR4(void)
2280 CONVVARS(FLOAT);
2282 CHECKPTR(VarI8FromR4);
2284 CONVERT(VarI8FromR4, -128.0f); EXPECTI8(-128);
2285 CONVERT(VarI8FromR4, -1.0f); EXPECTI8(-1);
2286 CONVERT(VarI8FromR4, 0.0f); EXPECTI8(0);
2287 CONVERT(VarI8FromR4, 1.0f); EXPECTI8(1);
2288 CONVERT(VarI8FromR4, 127.0f); EXPECTI8(127);
2290 CONVERT(VarI8FromR4, -1.5f); EXPECTI8(-2);
2291 CONVERT(VarI8FromR4, -0.6f); EXPECTI8(-1);
2292 CONVERT(VarI8FromR4, -0.5f); EXPECTI8(0);
2293 CONVERT(VarI8FromR4, -0.4f); EXPECTI8(0);
2294 CONVERT(VarI8FromR4, 0.4f); EXPECTI8(0);
2295 CONVERT(VarI8FromR4, 0.5f); EXPECTI8(0);
2296 CONVERT(VarI8FromR4, 0.6f); EXPECTI8(1);
2297 CONVERT(VarI8FromR4, 1.5f); EXPECTI8(2);
2300 static void test_VarI8FromR8(void)
2302 CONVVARS(DOUBLE);
2304 CHECKPTR(VarI8FromR8);
2305 CONVERT(VarI8FromR8, -128.0); EXPECTI8(-128);
2306 CONVERT(VarI8FromR8, -1.0); EXPECTI8(-1);
2307 CONVERT(VarI8FromR8, 0.0); EXPECTI8(0);
2308 CONVERT(VarI8FromR8, 1.0); EXPECTI8(1);
2309 CONVERT(VarI8FromR8, 127.0); EXPECTI8(127);
2311 CONVERT(VarI8FromR8, -1.5); EXPECTI8(-2);
2312 CONVERT(VarI8FromR8, -0.6); EXPECTI8(-1);
2313 CONVERT(VarI8FromR8, -0.5); EXPECTI8(0);
2314 CONVERT(VarI8FromR8, -0.4); EXPECTI8(0);
2315 CONVERT(VarI8FromR8, 0.4); EXPECTI8(0);
2316 CONVERT(VarI8FromR8, 0.5); EXPECTI8(0);
2317 CONVERT(VarI8FromR8, 0.6); EXPECTI8(1);
2318 CONVERT(VarI8FromR8, 1.5); EXPECTI8(2);
2321 static void test_VarI8FromDate(void)
2323 CONVVARS(DATE);
2325 CHECKPTR(VarI8FromDate);
2326 CONVERT(VarI8FromDate, -128.0); EXPECTI8(-128);
2327 CONVERT(VarI8FromDate, -1.0); EXPECTI8(-1);
2328 CONVERT(VarI8FromDate, 0.0); EXPECTI8(0);
2329 CONVERT(VarI8FromDate, 1.0); EXPECTI8(1);
2330 CONVERT(VarI8FromDate, 127.0); EXPECTI8(127);
2332 CONVERT(VarI8FromDate, -1.5); EXPECTI8(-2);
2333 CONVERT(VarI8FromDate, -0.6); EXPECTI8(-1);
2334 CONVERT(VarI8FromDate, -0.5); EXPECTI8(0);
2335 CONVERT(VarI8FromDate, -0.4); EXPECTI8(0);
2336 CONVERT(VarI8FromDate, 0.4); EXPECTI8(0);
2337 CONVERT(VarI8FromDate, 0.5); EXPECTI8(0);
2338 CONVERT(VarI8FromDate, 0.6); EXPECTI8(1);
2339 CONVERT(VarI8FromDate, 1.5); EXPECTI8(2);
2342 static void test_VarI8FromBool(void)
2344 CONVVARS(VARIANT_BOOL);
2345 int i;
2347 CHECKPTR(VarI8FromBool);
2348 for (i = -32768; i < 32768; i++)
2350 CONVERT(VarI8FromBool,i); EXPECTI8(i);
2354 static void test_VarI8FromUI8(void)
2356 CONVVARS(ULONG64);
2358 CHECKPTR(VarI8FromUI8);
2359 CONVERT(VarI8FromUI8, 0); EXPECTI8(0);
2360 CONVERT(VarI8FromUI8, 1); EXPECTI8(1);
2361 CONVERT_I8(VarI8FromUI8, 0x7fffffff, 0xffffffff); EXPECTI864(0x7fffffff, 0xffffffff);
2362 CONVERT_I8(VarI8FromUI8, 0x80000000, 0); EXPECT_OVERFLOW;
2365 static void test_VarI8FromCy(void)
2367 CONVVARS(CY);
2369 CHECKPTR(VarI8FromCy);
2370 CONVERT_CY(VarI8FromCy,-128); EXPECTI8(-129);
2371 CONVERT_CY(VarI8FromCy,-1); EXPECTI8(-2);
2372 CONVERT_CY(VarI8FromCy,0); EXPECTI8(0);
2373 CONVERT_CY(VarI8FromCy,1); EXPECTI8(1);
2374 CONVERT_CY(VarI8FromCy,127); EXPECTI8(127);
2376 CONVERT_CY(VarI8FromCy,-1.5); EXPECTI8(-2);
2377 CONVERT_CY(VarI8FromCy,-0.6); EXPECTI8(-1);
2378 CONVERT_CY(VarI8FromCy,-0.5); EXPECTI8(-1);
2379 CONVERT_CY(VarI8FromCy,-0.4); EXPECTI8(-1);
2380 CONVERT_CY(VarI8FromCy,0.4); EXPECTI8(0);
2381 CONVERT_CY(VarI8FromCy,0.5); EXPECTI8(0);
2382 CONVERT_CY(VarI8FromCy,0.6); EXPECTI8(1);
2383 CONVERT_CY(VarI8FromCy,1.5); EXPECTI8(2);
2386 static void test_VarI8FromDec(void)
2388 CONVVARS(DECIMAL);
2390 CHECKPTR(VarI8FromDec);
2392 CONVERT_BADDEC(VarI8FromDec);
2394 CONVERT_DEC(VarI8FromDec,0,0x80,0,128); EXPECTI8(-128);
2395 CONVERT_DEC(VarI8FromDec,0,0x80,0,1); EXPECTI8(-1);
2396 CONVERT_DEC(VarI8FromDec,0,0,0,0); EXPECTI8(0);
2397 CONVERT_DEC(VarI8FromDec,0,0,0,1); EXPECTI8(1);
2398 CONVERT_DEC(VarI8FromDec,0,0,0,127); EXPECTI8(127);
2400 CONVERT_DEC(VarI8FromDec,2,0x80,0,12700); EXPECTI8(-127);
2401 CONVERT_DEC(VarI8FromDec,2,0,0,12700); EXPECTI8(127);
2404 static void test_VarI8FromStr(void)
2406 CONVVARS(LCID);
2407 OLECHAR buff[128];
2409 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2411 CHECKPTR(VarI8FromStr);
2413 CONVERT_STR(VarI8FromStr,NULL,0); EXPECT_MISMATCH;
2414 CONVERT_STR(VarI8FromStr,"0",0); EXPECTI8(0);
2415 CONVERT_STR(VarI8FromStr,"-1",0); EXPECTI8(-1);
2416 CONVERT_STR(VarI8FromStr,"2147483647",0); EXPECTI8(2147483647);
2418 CONVERT_STR(VarI8FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(-2);
2419 CONVERT_STR(VarI8FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECTI8(-1);
2420 CONVERT_STR(VarI8FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2421 CONVERT_STR(VarI8FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2422 CONVERT_STR(VarI8FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2423 CONVERT_STR(VarI8FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2424 CONVERT_STR(VarI8FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECTI8(1);
2425 CONVERT_STR(VarI8FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(2);
2428 static void test_VarI8Copy(void)
2430 HRESULT hres;
2431 VARIANTARG vSrc, vDst;
2432 LONGLONG in = 1;
2434 if (!has_i8)
2436 win_skip("I8 and UI8 data types are not available\n");
2437 return;
2440 VariantInit(&vSrc);
2441 VariantInit(&vDst);
2442 V_VT(&vSrc) = VT_I8;
2443 V_I8(&vSrc) = in;
2444 hres = VariantCopy(&vDst, &vSrc);
2445 ok(hres == S_OK && V_VT(&vDst) == VT_I8 && V_I8(&vDst) == in,
2446 "copy hres 0x%X, type %d, value (%x%08x) %x%08x\n",
2447 hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_I8(&vDst) >> 32), (UINT)V_I8(&vDst) );
2448 V_VT(&vSrc) = VT_I8|VT_BYREF;
2449 V_I8REF(&vSrc) = &in;
2450 hres = VariantCopy(&vDst, &vSrc);
2451 ok(hres == S_OK && V_VT(&vDst) == (VT_I8|VT_BYREF) && V_I8REF(&vDst) == &in,
2452 "ref hres 0x%X, type %d, ref (%p) %p\n", hres, V_VT(&vDst), &in, V_I8REF(&vDst));
2453 hres = VariantCopyInd(&vDst, &vSrc);
2454 ok(hres == S_OK && V_VT(&vDst) == VT_I8 && V_I8(&vDst) == in,
2455 "copy hres 0x%X, type %d, value (%x%08x) %x%08x\n",
2456 hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_I8(&vDst) >> 32), (UINT)V_I8(&vDst) );
2459 static void test_VarI8ChangeTypeEx(void)
2461 HRESULT hres;
2462 LONG64 in;
2463 VARIANTARG vSrc, vDst;
2465 if (!has_i8)
2467 win_skip("I8 and UI8 data types are not available\n");
2468 return;
2471 in = 1;
2473 INITIAL_TYPETESTI8(VT_I8, V_I8);
2474 COMMON_TYPETEST;
2477 /* Adapt the test macros to UI8 */
2478 #undef CONV_TYPE
2479 #define CONV_TYPE ULONG64
2481 static void test_VarUI8FromI1(void)
2483 CONVVARS(signed char);
2484 int i;
2486 CHECKPTR(VarUI8FromI1);
2487 for (i = -128; i < 128; i++)
2489 CONVERT(VarUI8FromI1,i);
2490 if (i < 0)
2491 EXPECT_OVERFLOW;
2492 else
2493 EXPECTI8(i);
2497 static void test_VarUI8FromUI1(void)
2499 CONVVARS(BYTE);
2500 int i;
2502 CHECKPTR(VarUI8FromUI1);
2503 for (i = 0; i < 256; i++)
2505 CONVERT(VarUI8FromUI1,i); EXPECTI8(i);
2509 static void test_VarUI8FromI2(void)
2511 CONVVARS(SHORT);
2512 int i;
2514 CHECKPTR(VarUI8FromI2);
2515 for (i = -32768; i < 32768; i++)
2517 CONVERT(VarUI8FromI2,i);
2518 if (i < 0)
2519 EXPECT_OVERFLOW;
2520 else
2521 EXPECTI8(i);
2525 static void test_VarUI8FromUI2(void)
2527 CONVVARS(USHORT);
2528 int i;
2530 CHECKPTR(VarUI8FromUI2);
2531 for (i = 0; i < 65535; i++)
2533 CONVERT(VarUI8FromUI2,i); EXPECTI8(i);
2537 static void test_VarUI8FromUI4(void)
2539 CONVVARS(ULONG);
2541 CHECKPTR(VarUI8FromUI4);
2542 CONVERT(VarUI8FromUI4, 0); EXPECTI8(0);
2543 CONVERT(VarUI8FromUI4, 0xffffffff); EXPECTI8(0xffffffff);
2546 static void test_VarUI8FromR4(void)
2548 CONVVARS(FLOAT);
2550 CHECKPTR(VarUI8FromR4);
2551 CONVERT(VarUI8FromR4, -1.0f); EXPECT_OVERFLOW;
2552 CONVERT(VarUI8FromR4, 0.0f); EXPECTI8(0);
2553 CONVERT(VarUI8FromR4, 1.0f); EXPECTI8(1);
2554 CONVERT(VarUI8FromR4, 255.0f); EXPECTI8(255);
2556 CONVERT(VarUI8FromR4, -1.5f); EXPECT_OVERFLOW;
2557 CONVERT(VarUI8FromR4, -0.6f); EXPECT_OVERFLOW;
2558 CONVERT(VarUI8FromR4, -0.5f); EXPECTI8(0);
2559 CONVERT(VarUI8FromR4, -0.4f); EXPECTI8(0);
2560 CONVERT(VarUI8FromR4, 0.4f); EXPECTI8(0);
2561 CONVERT(VarUI8FromR4, 0.5f); EXPECTI8(0);
2562 CONVERT(VarUI8FromR4, 0.6f); EXPECTI8(1);
2563 CONVERT(VarUI8FromR4, 1.5f); EXPECTI8(2);
2566 static void test_VarUI8FromR8(void)
2568 CONVVARS(DOUBLE);
2570 CHECKPTR(VarUI8FromR8);
2571 CONVERT(VarUI8FromR8, -1.0); EXPECT_OVERFLOW;
2572 CONVERT(VarUI8FromR8, 0.0); EXPECTI8(0);
2573 CONVERT(VarUI8FromR8, 1.0); EXPECTI8(1);
2574 CONVERT(VarUI8FromR8, 255.0); EXPECTI8(255);
2576 CONVERT(VarUI8FromR8, -1.5); EXPECT_OVERFLOW;
2577 CONVERT(VarUI8FromR8, -0.6); EXPECT_OVERFLOW;
2578 CONVERT(VarUI8FromR8, -0.5); EXPECTI8(0);
2579 CONVERT(VarUI8FromR8, -0.4); EXPECTI8(0);
2580 CONVERT(VarUI8FromR8, 0.4); EXPECTI8(0);
2581 CONVERT(VarUI8FromR8, 0.5); EXPECTI8(0);
2582 CONVERT(VarUI8FromR8, 0.6); EXPECTI8(1);
2583 CONVERT(VarUI8FromR8, 1.5); EXPECTI8(2);
2586 static void test_VarUI8FromDate(void)
2588 CONVVARS(DATE);
2590 CHECKPTR(VarUI8FromDate);
2591 CONVERT(VarUI8FromDate, -1.0); EXPECT_OVERFLOW;
2592 CONVERT(VarUI8FromDate, 0.0); EXPECTI8(0);
2593 CONVERT(VarUI8FromDate, 1.0); EXPECTI8(1);
2594 CONVERT(VarUI8FromDate, 255.0); EXPECTI8(255);
2596 CONVERT(VarUI8FromDate, -1.5); EXPECT_OVERFLOW;
2597 CONVERT(VarUI8FromDate, -0.6); EXPECT_OVERFLOW;
2598 CONVERT(VarUI8FromDate, -0.5); EXPECTI8(0);
2599 CONVERT(VarUI8FromDate, -0.4); EXPECTI8(0);
2600 CONVERT(VarUI8FromDate, 0.4); EXPECTI8(0);
2601 CONVERT(VarUI8FromDate, 0.5); EXPECTI8(0);
2602 CONVERT(VarUI8FromDate, 0.6); EXPECTI8(1);
2603 CONVERT(VarUI8FromDate, 1.5); EXPECTI8(2);
2606 static void test_VarUI8FromBool(void)
2608 CONVVARS(VARIANT_BOOL);
2609 int i;
2611 CHECKPTR(VarUI8FromBool);
2612 for (i = -32768; i < 32768; i++)
2614 CONVERT(VarUI8FromBool, i); EXPECTI8(i);
2618 static void test_VarUI8FromI8(void)
2620 CONVVARS(LONG64);
2622 CHECKPTR(VarUI8FromI8);
2623 CONVERT(VarUI8FromI8, -1); EXPECT_OVERFLOW;
2624 CONVERT(VarUI8FromI8, 0); EXPECTI8(0);
2625 CONVERT(VarUI8FromI8, 1); EXPECTI8(1);
2628 static void test_VarUI8FromCy(void)
2630 CONVVARS(CY);
2632 CHECKPTR(VarUI8FromCy);
2633 CONVERT_CY(VarUI8FromCy,-1); EXPECT_OVERFLOW;
2634 CONVERT_CY(VarUI8FromCy,0); EXPECTI8(0);
2635 CONVERT_CY(VarUI8FromCy,1); EXPECTI8(1);
2636 CONVERT_CY(VarUI8FromCy,255); EXPECTI8(255);
2638 CONVERT_CY(VarUI8FromCy,-1.5); EXPECT_OVERFLOW;
2639 CONVERT_CY(VarUI8FromCy,-0.6); EXPECT_OVERFLOW;
2640 CONVERT_CY(VarUI8FromCy,-0.5); EXPECTI8(0);
2641 CONVERT_CY(VarUI8FromCy,-0.4); EXPECTI8(0);
2642 CONVERT_CY(VarUI8FromCy,0.4); EXPECTI8(0);
2643 CONVERT_CY(VarUI8FromCy,0.5); EXPECTI8(0);
2644 CONVERT_CY(VarUI8FromCy,0.6); EXPECTI8(1);
2645 CONVERT_CY(VarUI8FromCy,1.5); EXPECTI8(2);
2648 static void test_VarUI8FromDec(void)
2650 CONVVARS(DECIMAL);
2652 CHECKPTR(VarUI8FromDec);
2654 CONVERT_BADDEC(VarUI8FromDec);
2656 /* This returns 1 under native; Wine fixes this bug and returns overflow */
2657 if (0)
2659 CONVERT_DEC(VarUI8FromDec,0,0x80,0,1);
2662 CONVERT_DEC(VarUI8FromDec,0,0,0,0); EXPECTI8(0);
2663 CONVERT_DEC(VarUI8FromDec,0,0,0,1); EXPECTI8(1);
2664 CONVERT_DEC(VarUI8FromDec,0,0,0,255); EXPECTI8(255);
2666 CONVERT_DEC(VarUI8FromDec,2,0x80,0,100); EXPECT_OVERFLOW;
2667 CONVERT_DEC(VarUI8FromDec,2,0,0,25500); EXPECTI8(255);
2670 static void test_VarUI8FromStr(void)
2672 CONVVARS(LCID);
2673 OLECHAR buff[128];
2675 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2677 CHECKPTR(VarUI8FromStr);
2679 CONVERT_STR(VarUI8FromStr,NULL,0); EXPECT_MISMATCH;
2680 CONVERT_STR(VarUI8FromStr,"0",0); EXPECTI8(0);
2681 CONVERT_STR(VarUI8FromStr,"-1",0); EXPECT_OVERFLOW;
2682 CONVERT_STR(VarUI8FromStr,"2147483647",0); EXPECTI8(2147483647);
2683 CONVERT_STR(VarUI8FromStr,"18446744073709551614",0); EXPECTI864(0xFFFFFFFF,0xFFFFFFFE);
2684 CONVERT_STR(VarUI8FromStr,"18446744073709551615",0); EXPECTI864(0xFFFFFFFF,0xFFFFFFFF);
2685 CONVERT_STR(VarUI8FromStr,"18446744073709551616",0); EXPECT_OVERFLOW;
2687 CONVERT_STR(VarUI8FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
2688 CONVERT_STR(VarUI8FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
2689 CONVERT_STR(VarUI8FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2690 CONVERT_STR(VarUI8FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2691 CONVERT_STR(VarUI8FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2692 CONVERT_STR(VarUI8FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2693 CONVERT_STR(VarUI8FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECTI8(1);
2694 CONVERT_STR(VarUI8FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(2);
2697 static void test_VarUI8Copy(void)
2699 HRESULT hres;
2700 VARIANTARG vSrc, vDst;
2701 ULONGLONG in = 1;
2703 if (!has_i8)
2705 win_skip("I8 and UI8 data types are not available\n");
2706 return;
2709 VariantInit(&vSrc);
2710 VariantInit(&vDst);
2711 V_VT(&vSrc) = VT_UI8;
2712 V_UI8(&vSrc) = in;
2713 hres = VariantCopy(&vDst, &vSrc);
2714 ok(hres == S_OK && V_VT(&vDst) == VT_UI8 && V_UI8(&vDst) == in,
2715 "copy hres 0x%X, type %d, value (%x%08x) %x%08x\n",
2716 hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_UI8(&vDst) >> 32), (UINT)V_UI8(&vDst) );
2717 V_VT(&vSrc) = VT_UI8|VT_BYREF;
2718 V_UI8REF(&vSrc) = &in;
2719 hres = VariantCopy(&vDst, &vSrc);
2720 ok(hres == S_OK && V_VT(&vDst) == (VT_UI8|VT_BYREF) && V_UI8REF(&vDst) == &in,
2721 "ref hres 0x%X, type %d, ref (%p) %p\n", hres, V_VT(&vDst), &in, V_UI8REF(&vDst));
2722 hres = VariantCopyInd(&vDst, &vSrc);
2723 ok(hres == S_OK && V_VT(&vDst) == VT_UI8 && V_UI8(&vDst) == in,
2724 "copy hres 0x%X, type %d, value (%x%08x) %x%08x\n",
2725 hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_UI8(&vDst) >> 32), (UINT)V_UI8(&vDst) );
2728 static void test_VarUI8ChangeTypeEx(void)
2730 HRESULT hres;
2731 ULONG64 in;
2732 VARIANTARG vSrc, vDst;
2734 if (!has_i8)
2736 win_skip("I8 and UI8 data types are not available\n");
2737 return;
2740 in = 1;
2742 INITIAL_TYPETESTI8(VT_UI8, V_UI8);
2743 COMMON_TYPETEST;
2747 * VT_R4
2750 #undef CONV_TYPE
2751 #define CONV_TYPE float
2752 #undef EXPECTRES
2753 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%15.15f")
2755 static void test_VarR4FromI1(void)
2757 CONVVARS(signed char);
2758 int i;
2760 CHECKPTR(VarR4FromI1);
2761 CONVERTRANGE(VarR4FromI1, -128, 128);
2764 static void test_VarR4FromUI1(void)
2766 CONVVARS(BYTE);
2767 int i;
2769 CHECKPTR(VarR4FromUI1);
2770 CONVERTRANGE(VarR4FromUI1, 0, 256);
2773 static void test_VarR4FromI2(void)
2775 CONVVARS(SHORT);
2776 int i;
2778 CHECKPTR(VarR4FromI2);
2779 CONVERTRANGE(VarR4FromI2, -32768, 32768);
2782 static void test_VarR4FromUI2(void)
2784 CONVVARS(USHORT);
2785 int i;
2787 CHECKPTR(VarR4FromUI2);
2788 CONVERTRANGE(VarR4FromUI2, 0, 65536);
2791 static void test_VarR4FromI4(void)
2793 CONVVARS(int);
2795 CHECKPTR(VarR4FromI4);
2796 CONVERT(VarR4FromI4, -2147483647-1); EXPECT(-2147483648.0f);
2797 CONVERT(VarR4FromI4, -1); EXPECT(-1.0f);
2798 CONVERT(VarR4FromI4, 0); EXPECT(0.0f);
2799 CONVERT(VarR4FromI4, 1); EXPECT(1.0f);
2800 CONVERT(VarR4FromI4, 2147483647); EXPECT(2147483647.0f);
2803 static void test_VarR4FromUI4(void)
2805 CONVVARS(unsigned int);
2807 CHECKPTR(VarR4FromUI4);
2808 CONVERT(VarR4FromUI4, 0); EXPECT(0.0f);
2809 CONVERT(VarR4FromUI4, 1); EXPECT(1.0f);
2810 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
2811 CONVERT(VarR4FromUI4, 0xffffffff); EXPECT(4294967296.0f);
2812 #endif
2815 static void test_VarR4FromR8(void)
2817 CONVVARS(FLOAT);
2819 CHECKPTR(VarR4FromR8);
2820 CONVERT(VarR4FromR8, -1.0); EXPECT(-1.0f);
2821 CONVERT(VarR4FromR8, 0.0); EXPECT(0.0f);
2822 CONVERT(VarR4FromR8, 1.0); EXPECT(1.0f);
2823 CONVERT(VarR4FromR8, 1.5); EXPECT(1.5f);
2825 /* Skip rounding tests - no rounding is done */
2828 static void test_VarR4FromBool(void)
2830 CONVVARS(VARIANT_BOOL);
2832 CHECKPTR(VarR4FromBool);
2833 CONVERT(VarR4FromBool, VARIANT_TRUE); EXPECT(VARIANT_TRUE * 1.0f);
2834 CONVERT(VarR4FromBool, VARIANT_FALSE); EXPECT(VARIANT_FALSE * 1.0f);
2837 static void test_VarR4FromCy(void)
2839 CONVVARS(CY);
2841 CHECKPTR(VarR4FromCy);
2842 CONVERT_CY(VarR4FromCy,-32768); EXPECT(-32768.0f);
2843 CONVERT_CY(VarR4FromCy,-1); EXPECT(-1.0f);
2844 CONVERT_CY(VarR4FromCy,0); EXPECT(0.0f);
2845 CONVERT_CY(VarR4FromCy,1); EXPECT(1.0f);
2846 CONVERT_CY(VarR4FromCy,32768); EXPECT(32768.0f);
2848 CONVERT_CY(VarR4FromCy,-1.5); EXPECT(-1.5f);
2849 CONVERT_CY(VarR4FromCy,-0.6); EXPECT(-0.6f);
2850 CONVERT_CY(VarR4FromCy,-0.5); EXPECT(-0.5f);
2851 CONVERT_CY(VarR4FromCy,-0.4); EXPECT(-0.4f);
2852 CONVERT_CY(VarR4FromCy,0.4); EXPECT(0.4f);
2853 CONVERT_CY(VarR4FromCy,0.5); EXPECT(0.5f);
2854 CONVERT_CY(VarR4FromCy,0.6); EXPECT(0.6f);
2855 CONVERT_CY(VarR4FromCy,1.5); EXPECT(1.5f);
2858 static void test_VarR4FromI8(void)
2860 CONVVARS(LONG64);
2862 CHECKPTR(VarR4FromI8);
2863 CONVERT(VarR4FromI8, -1); EXPECT(-1.0f);
2864 CONVERT(VarR4FromI8, 0); EXPECT(0.0f);
2865 CONVERT(VarR4FromI8, 1); EXPECT(1.0f);
2868 static void test_VarR4FromUI8(void)
2870 CONVVARS(ULONG64);
2872 CHECKPTR(VarR4FromUI8);
2873 CONVERT(VarR4FromUI8, 0); EXPECT(0.0f);
2874 CONVERT(VarR4FromUI8, 1); EXPECT(1.0f);
2877 static void test_VarR4FromDec(void)
2879 CONVVARS(DECIMAL);
2881 CHECKPTR(VarR4FromDec);
2883 CONVERT_BADDEC(VarR4FromDec);
2885 CONVERT_DEC(VarR4FromDec,0,0x80,0,32768); EXPECT(-32768.0f);
2886 CONVERT_DEC(VarR4FromDec,0,0x80,0,1); EXPECT(-1.0f);
2887 CONVERT_DEC(VarR4FromDec,0,0,0,0); EXPECT(0.0f);
2888 CONVERT_DEC(VarR4FromDec,0,0,0,1); EXPECT(1.0f);
2889 CONVERT_DEC(VarR4FromDec,0,0,0,32767); EXPECT(32767.0f);
2891 CONVERT_DEC(VarR4FromDec,2,0x80,0,3276800); EXPECT(-32768.0f);
2892 CONVERT_DEC(VarR4FromDec,2,0,0,3276700); EXPECT(32767.0f);
2894 CONVERT_DEC(VarR4FromDec,0,0,1,0); EXPECT(18446744073709551616.0f);
2897 static void test_VarR4FromDate(void)
2899 CONVVARS(DATE);
2901 CHECKPTR(VarR4FromDate);
2902 CONVERT(VarR4FromDate, -1.0); EXPECT(-1.0f);
2903 CONVERT(VarR4FromDate, 0.0); EXPECT(0.0f);
2904 CONVERT(VarR4FromDate, 1.0); EXPECT(1.0f);
2907 static void test_VarR4FromStr(void)
2909 CONVVARS(LCID);
2910 OLECHAR buff[128];
2912 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2914 CHECKPTR(VarR4FromStr);
2916 CONVERT_STR(VarR4FromStr,NULL,0); EXPECT_MISMATCH;
2917 CONVERT_STR(VarR4FromStr,"-1", 0); EXPECT(-1.0f);
2918 CONVERT_STR(VarR4FromStr,"0", 0); EXPECT(0.0f);
2919 CONVERT_STR(VarR4FromStr,"1", 0); EXPECT(1.0f);
2921 CONVERT_STR(VarR4FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECT(-1.5f);
2922 CONVERT_STR(VarR4FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECT(-0.6f);
2923 CONVERT_STR(VarR4FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECT(-0.5f);
2924 CONVERT_STR(VarR4FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECT(-0.4f);
2925 CONVERT_STR(VarR4FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0.4f);
2926 CONVERT_STR(VarR4FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0.5f);
2927 CONVERT_STR(VarR4FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECT(0.6f);
2928 CONVERT_STR(VarR4FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECT(1.5f);
2931 static void test_VarR4Copy(void)
2933 COPYTEST(77665544.0f, VT_R4, V_R4(&vSrc), V_R4(&vDst), V_R4REF(&vSrc),V_R4REF(&vDst), "%15.15f");
2936 static void test_VarR4ChangeTypeEx(void)
2938 #ifdef HAS_UINT64_TO_FLOAT
2939 HRESULT hres;
2940 float in;
2941 VARIANTARG vSrc, vDst;
2943 in = 1.0f;
2945 INITIAL_TYPETEST(VT_R4, V_R4, "%f");
2946 COMMON_TYPETEST;
2947 #endif
2951 * VT_R8
2954 #undef CONV_TYPE
2955 #define CONV_TYPE double
2957 static void test_VarR8FromI1(void)
2959 CONVVARS(signed char);
2960 int i;
2962 CHECKPTR(VarR8FromI1);
2963 CONVERTRANGE(VarR8FromI1, -128, 128);
2966 static void test_VarR8FromUI1(void)
2968 CONVVARS(BYTE);
2969 int i;
2971 CHECKPTR(VarR8FromUI1);
2972 CONVERTRANGE(VarR8FromUI1, 0, 256);
2975 static void test_VarR8FromI2(void)
2977 CONVVARS(SHORT);
2978 int i;
2980 CHECKPTR(VarR8FromI2);
2981 CONVERTRANGE(VarR8FromI2, -32768, 32768);
2984 static void test_VarR8FromUI2(void)
2986 CONVVARS(USHORT);
2987 int i;
2989 CHECKPTR(VarR8FromUI2);
2990 CONVERTRANGE(VarR8FromUI2, 0, 65536);
2993 static void test_VarR8FromI4(void)
2995 CONVVARS(int);
2997 CHECKPTR(VarR8FromI4);
2998 CONVERT(VarR8FromI4, -2147483647-1); EXPECT(-2147483648.0);
2999 CONVERT(VarR8FromI4, -1); EXPECT(-1.0);
3000 CONVERT(VarR8FromI4, 0); EXPECT(0.0);
3001 CONVERT(VarR8FromI4, 1); EXPECT(1.0);
3002 CONVERT(VarR8FromI4, 0x7fffffff); EXPECT(2147483647.0);
3005 static void test_VarR8FromUI4(void)
3007 CONVVARS(unsigned int);
3009 CHECKPTR(VarR8FromUI4);
3010 CONVERT(VarR8FromUI4, 0); EXPECT(0.0);
3011 CONVERT(VarR8FromUI4, 1); EXPECT(1.0);
3012 CONVERT(VarR8FromUI4, 0xffffffff); EXPECT(4294967295.0);
3015 static void test_VarR8FromR4(void)
3017 CONVVARS(FLOAT);
3019 CHECKPTR(VarR8FromR4);
3020 CONVERT(VarR8FromR4, -1.0f); EXPECT(-1.0);
3021 CONVERT(VarR8FromR4, 0.0f); EXPECT(0.0);
3022 CONVERT(VarR8FromR4, 1.0f); EXPECT(1.0);
3023 CONVERT(VarR8FromR4, 1.5f); EXPECT(1.5);
3025 /* Skip rounding tests - no rounding is done */
3028 static void test_VarR8FromBool(void)
3030 CONVVARS(VARIANT_BOOL);
3032 CHECKPTR(VarR8FromBool);
3033 CONVERT(VarR8FromBool, VARIANT_TRUE); EXPECT(VARIANT_TRUE * 1.0);
3034 CONVERT(VarR8FromBool, VARIANT_FALSE); EXPECT(VARIANT_FALSE * 1.0);
3037 static void test_VarR8FromCy(void)
3039 CONVVARS(CY);
3041 CHECKPTR(VarR8FromCy);
3042 CONVERT_CY(VarR8FromCy,-32769); EXPECT(-32769.0);
3043 CONVERT_CY(VarR8FromCy,-32768); EXPECT(-32768.0);
3044 CONVERT_CY(VarR8FromCy,-1); EXPECT(-1.0);
3045 CONVERT_CY(VarR8FromCy,0); EXPECT(0.0);
3046 CONVERT_CY(VarR8FromCy,1); EXPECT(1.0);
3047 CONVERT_CY(VarR8FromCy,32767); EXPECT(32767.0);
3048 CONVERT_CY(VarR8FromCy,32768); EXPECT(32768.0);
3050 CONVERT_CY(VarR8FromCy,-1.5); EXPECT(-1.5);
3051 CONVERT_CY(VarR8FromCy,-0.6); EXPECT(-0.6);
3052 CONVERT_CY(VarR8FromCy,-0.5); EXPECT(-0.5);
3053 CONVERT_CY(VarR8FromCy,-0.4); EXPECT(-0.4);
3054 CONVERT_CY(VarR8FromCy,0.4); EXPECT(0.4);
3055 CONVERT_CY(VarR8FromCy,0.5); EXPECT(0.5);
3056 CONVERT_CY(VarR8FromCy,0.6); EXPECT(0.6);
3057 CONVERT_CY(VarR8FromCy,1.5); EXPECT(1.5);
3060 static void test_VarR8FromI8(void)
3062 CONVVARS(LONG64);
3064 CHECKPTR(VarR8FromI8);
3065 CONVERT(VarR8FromI8, -1); EXPECT(-1.0);
3066 CONVERT(VarR8FromI8, 0); EXPECT(0.0);
3067 CONVERT(VarR8FromI8, 1); EXPECT(1.0);
3068 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3069 CONVERT_I8(VarR8FromI8, 0x7fffffff,0xffffffff); EXPECT(9223372036854775808.0);
3070 #endif
3073 static void test_VarR8FromUI8(void)
3075 CONVVARS(ULONG64);
3077 CHECKPTR(VarR8FromUI8);
3078 CONVERT(VarR8FromUI8, 0); EXPECT(0.0);
3079 CONVERT(VarR8FromUI8, 1); EXPECT(1.0);
3080 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3081 CONVERT_I8(VarR8FromUI8, 0x80000000,0); EXPECT(9223372036854775808.0);
3082 #endif
3085 static void test_VarR8FromDec(void)
3087 CONVVARS(DECIMAL);
3089 CHECKPTR(VarR8FromDec);
3091 CONVERT_BADDEC(VarR8FromDec);
3093 CONVERT_DEC(VarR8FromDec,0,0x80,0,32768); EXPECT(-32768.0);
3094 CONVERT_DEC(VarR8FromDec,0,0x80,0,1); EXPECT(-1.0);
3095 CONVERT_DEC(VarR8FromDec,0,0,0,0); EXPECT(0.0);
3096 CONVERT_DEC(VarR8FromDec,0,0,0,1); EXPECT(1.0);
3097 CONVERT_DEC(VarR8FromDec,0,0,0,32767); EXPECT(32767.0);
3099 CONVERT_DEC(VarR8FromDec,2,0x80,0,3276800); EXPECT(-32768.0);
3100 CONVERT_DEC(VarR8FromDec,2,0,0,3276700); EXPECT(32767.0);
3102 CONVERT_DEC(VarR8FromDec,0,0,1,0); EXPECT(18446744073709551616.0);
3105 static void test_VarR8FromDate(void)
3107 CONVVARS(DATE);
3109 CHECKPTR(VarR8FromDate);
3110 CONVERT(VarR8FromDate, -1.0); EXPECT(-1.0);
3111 CONVERT(VarR8FromDate, -0.0); EXPECT(0.0);
3112 CONVERT(VarR8FromDate, 1.0); EXPECT(1.0);
3115 static void test_VarR8FromStr(void)
3117 CONVVARS(LCID);
3118 OLECHAR buff[128];
3120 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
3122 CHECKPTR(VarR8FromStr);
3124 CONVERT_STR(VarR8FromStr,NULL,0); EXPECT_MISMATCH;
3125 CONVERT_STR(VarR8FromStr,"",0); EXPECT_MISMATCH;
3126 CONVERT_STR(VarR8FromStr," ",0); EXPECT_MISMATCH;
3128 CONVERT_STR(VarR8FromStr,"0",LOCALE_NOUSEROVERRIDE); EXPECT(0.0);
3129 CONVERT_STR(VarR8FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECT(-1.5);
3130 CONVERT_STR(VarR8FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECT(-0.6);
3131 CONVERT_STR(VarR8FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECT(-0.5);
3132 CONVERT_STR(VarR8FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECT(-0.4);
3133 CONVERT_STR(VarR8FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0.4);
3134 CONVERT_STR(VarR8FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0.5);
3135 CONVERT_STR(VarR8FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECT(0.6);
3136 CONVERT_STR(VarR8FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECT(1.5);
3138 /* We already have exhaustive tests for number parsing, so skip those tests here */
3141 static void test_VarR8Copy(void)
3143 COPYTEST(77665544.0, VT_R8, V_R8(&vSrc), V_R8(&vDst), V_R8REF(&vSrc),V_R8REF(&vDst), "%16.16g");
3146 static void test_VarR8ChangeTypeEx(void)
3148 #ifdef HAS_UINT64_TO_FLOAT
3149 HRESULT hres;
3150 double in;
3151 VARIANTARG vSrc, vDst;
3153 in = 1.0;
3155 INITIAL_TYPETEST(VT_R8, V_R8, "%g");
3156 COMMON_TYPETEST;
3157 #endif
3160 #define MATHRND(l, r) left = l; right = r; hres = pVarR8Round(left, right, &out)
3162 static void test_VarR8Round(void)
3164 HRESULT hres;
3165 double left = 0.0, out;
3166 int right;
3168 CHECKPTR(VarR8Round);
3169 MATHRND(0.5432, 5); EXPECT(0.5432);
3170 MATHRND(0.5432, 4); EXPECT(0.5432);
3171 MATHRND(0.5432, 3); EXPECT(0.543);
3172 MATHRND(0.5432, 2); EXPECT(0.54);
3173 MATHRND(0.5432, 1); EXPECT(0.5);
3174 MATHRND(0.5532, 0); EXPECT(1);
3175 MATHRND(0.5532, -1); EXPECT_INVALID;
3177 MATHRND(0.5568, 5); EXPECT(0.5568);
3178 MATHRND(0.5568, 4); EXPECT(0.5568);
3179 MATHRND(0.5568, 3); EXPECT(0.557);
3180 MATHRND(0.5568, 2); EXPECT(0.56);
3181 MATHRND(0.5568, 1); EXPECT(0.6);
3182 MATHRND(0.5568, 0); EXPECT(1);
3183 MATHRND(0.5568, -1); EXPECT_INVALID;
3185 MATHRND(0.4999, 0); EXPECT(0);
3186 MATHRND(0.5000, 0); EXPECT(0);
3187 MATHRND(0.5001, 0); EXPECT(1);
3188 MATHRND(1.4999, 0); EXPECT(1);
3189 MATHRND(1.5000, 0); EXPECT(2);
3190 MATHRND(1.5001, 0); EXPECT(2);
3194 * VT_DATE
3197 #undef CONV_TYPE
3198 #define CONV_TYPE DATE
3200 static void test_VarDateFromI1(void)
3202 CONVVARS(signed char);
3203 int i;
3205 CHECKPTR(VarDateFromI1);
3206 CONVERTRANGE(VarDateFromI1, -128, 128);
3209 static void test_VarDateFromUI1(void)
3211 CONVVARS(BYTE);
3212 int i;
3214 CHECKPTR(VarDateFromUI1);
3215 CONVERTRANGE(VarDateFromUI1, 0, 256);
3218 static void test_VarDateFromI2(void)
3220 CONVVARS(SHORT);
3221 int i;
3223 CHECKPTR(VarDateFromI2);
3224 CONVERTRANGE(VarDateFromI2, -32768, 32768);
3227 static void test_VarDateFromUI2(void)
3229 CONVVARS(USHORT);
3230 int i;
3232 CHECKPTR(VarDateFromUI2);
3233 CONVERTRANGE(VarDateFromUI2, 0, 65536);
3236 static void test_VarDateFromI4(void)
3238 CONVVARS(int);
3240 CHECKPTR(VarDateFromI4);
3241 CONVERT(VarDateFromI4, DATE_MIN-1);
3242 if (hres != DISP_E_TYPEMISMATCH) /* Early versions return this, incorrectly */
3243 EXPECT_OVERFLOW;
3244 CONVERT(VarDateFromI4, DATE_MIN); EXPECT(DATE_MIN);
3245 CONVERT(VarDateFromI4, -1); EXPECT(-1.0);
3246 CONVERT(VarDateFromI4, 0); EXPECT(0.0);
3247 CONVERT(VarDateFromI4, 1); EXPECT(1.0);
3248 CONVERT(VarDateFromI4, DATE_MAX); EXPECT(DATE_MAX);
3249 CONVERT(VarDateFromI4, DATE_MAX+1);
3250 if (hres != DISP_E_TYPEMISMATCH) /* Early versions return this, incorrectly */
3251 EXPECT_OVERFLOW;
3254 static void test_VarDateFromUI4(void)
3256 CONVVARS(unsigned int);
3258 CHECKPTR(VarDateFromUI4);
3259 CONVERT(VarDateFromUI4, 0); EXPECT(0.0);
3260 CONVERT(VarDateFromUI4, 1); EXPECT(1.0);
3261 CONVERT(VarDateFromUI4, DATE_MAX); EXPECT(DATE_MAX);
3262 CONVERT(VarDateFromUI4, DATE_MAX+1);
3263 if (hres != DISP_E_TYPEMISMATCH) /* Early versions return this, incorrectly */
3264 EXPECT_OVERFLOW;
3267 static void test_VarDateFromR4(void)
3269 CONVVARS(FLOAT);
3271 CHECKPTR(VarDateFromR4);
3272 CONVERT(VarDateFromR4, -1.0f); EXPECT(-1.0);
3273 CONVERT(VarDateFromR4, 0.0f); EXPECT(0.0);
3274 CONVERT(VarDateFromR4, 1.0f); EXPECT(1.0);
3275 CONVERT(VarDateFromR4, 1.5f); EXPECT(1.5);
3278 static void test_VarDateFromR8(void)
3280 CONVVARS(double);
3282 CHECKPTR(VarDateFromR8);
3283 CONVERT(VarDateFromR8, -1.0f); EXPECT(-1.0);
3284 CONVERT(VarDateFromR8, 0.0f); EXPECT(0.0);
3285 CONVERT(VarDateFromR8, 1.0f); EXPECT(1.0);
3286 CONVERT(VarDateFromR8, 1.5f); EXPECT(1.5);
3289 static void test_VarDateFromBool(void)
3291 CONVVARS(VARIANT_BOOL);
3293 CHECKPTR(VarDateFromBool);
3294 CONVERT(VarDateFromBool, VARIANT_TRUE); EXPECT(VARIANT_TRUE * 1.0);
3295 CONVERT(VarDateFromBool, VARIANT_FALSE); EXPECT(VARIANT_FALSE * 1.0);
3298 static void test_VarDateFromCy(void)
3300 CONVVARS(CY);
3302 CHECKPTR(VarDateFromCy);
3303 CONVERT_CY(VarDateFromCy,-32769); EXPECT(-32769.0);
3304 CONVERT_CY(VarDateFromCy,-32768); EXPECT(-32768.0);
3305 CONVERT_CY(VarDateFromCy,-1); EXPECT(-1.0);
3306 CONVERT_CY(VarDateFromCy,0); EXPECT(0.0);
3307 CONVERT_CY(VarDateFromCy,1); EXPECT(1.0);
3308 CONVERT_CY(VarDateFromCy,32767); EXPECT(32767.0);
3309 CONVERT_CY(VarDateFromCy,32768); EXPECT(32768.0);
3311 CONVERT_CY(VarDateFromCy,-1.5); EXPECT(-1.5);
3312 CONVERT_CY(VarDateFromCy,-0.6); EXPECT(-0.6);
3313 CONVERT_CY(VarDateFromCy,-0.5); EXPECT(-0.5);
3314 CONVERT_CY(VarDateFromCy,-0.4); EXPECT(-0.4);
3315 CONVERT_CY(VarDateFromCy,0.4); EXPECT(0.4);
3316 CONVERT_CY(VarDateFromCy,0.5); EXPECT(0.5);
3317 CONVERT_CY(VarDateFromCy,0.6); EXPECT(0.6);
3318 CONVERT_CY(VarDateFromCy,1.5); EXPECT(1.5);
3321 static void test_VarDateFromI8(void)
3323 CONVVARS(LONG64);
3325 CHECKPTR(VarDateFromI8);
3326 CONVERT(VarDateFromI8, DATE_MIN-1); EXPECT_OVERFLOW;
3327 CONVERT(VarDateFromI8, DATE_MIN); EXPECT(DATE_MIN);
3328 CONVERT(VarDateFromI8, -1); EXPECT(-1.0);
3329 CONVERT(VarDateFromI8, 0); EXPECT(0.0);
3330 CONVERT(VarDateFromI8, 1); EXPECT(1.0);
3331 CONVERT(VarDateFromI8, DATE_MAX); EXPECT(DATE_MAX);
3332 CONVERT(VarDateFromI8, DATE_MAX+1); EXPECT_OVERFLOW;
3335 static void test_VarDateFromUI8(void)
3337 CONVVARS(ULONG64);
3339 CHECKPTR(VarDateFromUI8);
3340 CONVERT(VarDateFromUI8, 0); EXPECT(0.0);
3341 CONVERT(VarDateFromUI8, 1); EXPECT(1.0);
3342 CONVERT(VarDateFromUI8, DATE_MAX); EXPECT(DATE_MAX);
3343 CONVERT(VarDateFromUI8, DATE_MAX+1); EXPECT_OVERFLOW;
3346 static void test_VarDateFromDec(void)
3348 CONVVARS(DECIMAL);
3350 CHECKPTR(VarDateFromDec);
3352 CONVERT_BADDEC(VarDateFromDec);
3354 CONVERT_DEC(VarDateFromDec,0,0x80,0,32768); EXPECT(-32768.0);
3355 CONVERT_DEC(VarDateFromDec,0,0x80,0,1); EXPECT(-1.0);
3356 CONVERT_DEC(VarDateFromDec,0,0,0,0); EXPECT(0.0);
3357 CONVERT_DEC(VarDateFromDec,0,0,0,1); EXPECT(1.0);
3358 CONVERT_DEC(VarDateFromDec,0,0,0,32767); EXPECT(32767.0);
3360 CONVERT_DEC(VarDateFromDec,2,0x80,0,3276800); EXPECT(-32768.0);
3361 CONVERT_DEC(VarDateFromDec,2,0,0,3276700); EXPECT(32767.0);
3364 #define DFS(str) \
3365 buff[0] = '\0'; out = 0.0; \
3366 if (str) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)/sizeof(WCHAR)); \
3367 hres = pVarDateFromStr(str ? buff : NULL,lcid,LOCALE_NOUSEROVERRIDE,&out)
3369 #define MKRELDATE(day,mth) st.wMonth = mth; st.wDay = day; \
3370 pSystemTimeToVariantTime(&st,&relative)
3372 static const char * const BadDateStrings[] =
3374 "True", "False", /* Plain text */
3375 "0.", ".0", "-1.1", "1.1-", /* Partial specifications */
3376 "1;2;3", "1*2*3", "1@2@3", "1#2#3", "(1:2)","<1:2>","1|2|3", /* Bad chars */
3377 "0", "1", /* 1 element */
3378 "0.60", "24.00", "0:60", "24:00", "1 2 am", "1 am 2", /* 2 elements */
3379 "1.5 2", "1 5.2", "2 32 3", "1 2 am 3", /* 3 elements */
3380 "1 2.3 4", "1.2.3 4", "1 2.3.4", "1.2 3.4", "1.2.3.4", "1 2 3 4",
3381 "1 am 2 3.4", "1 2 am 3.4", "1.2 3 am 4", "1.2 3 4 am", /* 4 elements */
3382 "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",
3383 "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",
3384 "1.2.3 4 am 5", "1.2.3 4 5 am", "1.2 3 am 4 5",
3385 "1.2 3 4 am 5", "1.2 3 4 5 am", "1 am 2 3.4.5", "1 2 am 3.4.5",
3386 "1 am 2 3 4.5", "1 2 am 3 4.5", "1 2 3 am 4.5", /* 5 elements */
3387 /* 6 elements */
3388 "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",
3389 "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",
3390 "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",
3391 "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",
3392 #if 0
3393 /* following throws an exception on winME */
3394 "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",
3395 #endif
3396 "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",
3397 #if 0
3398 /* following throws an exception on winME */
3399 "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",
3400 #endif
3401 "1 2 am 3 4.5.6", "1 2 3 am 4.5.6"
3404 static void test_VarDateFromStr(void)
3406 LCID lcid;
3407 DATE out, relative;
3408 HRESULT hres;
3409 SYSTEMTIME st;
3410 OLECHAR buff[128];
3411 size_t i;
3413 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
3415 CHECKPTR(VarDateFromStr);
3416 CHECKPTR(SystemTimeToVariantTime);
3418 /* Some date formats are relative, so we need to find the current year */
3419 GetSystemTime(&st);
3420 st.wHour = st.wMinute = st.wSecond = st.wMilliseconds = 0;
3421 DFS(NULL); EXPECT_MISMATCH;
3423 /* Floating point number are not recognised */
3424 DFS("0.0");
3425 if (hres == S_OK)
3426 EXPECT_DBL(0.0); /* Very old versions accept this string */
3427 else
3428 EXPECT_MISMATCH;
3430 /* 1 element - can only be a time, and only if it has am/pm */
3431 DFS("1 am"); EXPECT_DBL(0.04166666666666666);
3432 /* 2 elements */
3433 /* A decimal point is treated as a time separator.
3434 * The following are converted as hours/minutes.
3436 DFS("0.1"); EXPECT_DBL(0.0006944444444444445);
3437 DFS("0.40"); EXPECT_DBL(0.02777777777777778);
3438 DFS("2.5"); EXPECT_DBL(0.08680555555555555);
3439 /* A colon acts as a decimal point */
3440 DFS("0:1"); EXPECT_DBL(0.0006944444444444445);
3441 DFS("0:20"); EXPECT_DBL(0.01388888888888889);
3442 DFS("0:40"); EXPECT_DBL(0.02777777777777778);
3443 DFS("3:5"); EXPECT_DBL(0.1284722222222222);
3444 /* Check the am/pm limits */
3445 DFS("00:00 AM"); EXPECT_DBL(0.0);
3446 DFS("00:00 a"); EXPECT_DBL(0.0);
3447 DFS("12:59 AM"); EXPECT_DBL(0.04097222222222222);
3448 DFS("12:59 A"); EXPECT_DBL(0.04097222222222222);
3449 DFS("00:00 pm"); EXPECT_DBL(0.5);
3450 DFS("00:00 p"); EXPECT_DBL(0.5);
3451 DFS("12:59 pm"); EXPECT_DBL(0.5409722222222222);
3452 DFS("12:59 p"); EXPECT_DBL(0.5409722222222222);
3453 /* AM/PM is ignored if hours > 12 */
3454 DFS("13:00 AM"); EXPECT_DBL(0.5416666666666666);
3455 DFS("13:00 PM"); EXPECT_DBL(0.5416666666666666);
3457 /* Space, dash and slash all indicate a date format. */
3458 /* If both numbers are valid month values => month/day of current year */
3459 DFS("1 2"); MKRELDATE(2,1); EXPECT_DBL(relative);
3460 DFS("2 1"); MKRELDATE(1,2); EXPECT_DBL(relative);
3461 /* one number not valid month, is a valid day, other number valid month:
3462 * that number becomes the day.
3464 DFS("14 1"); MKRELDATE(14,1); EXPECT_DBL(relative);
3465 DFS("1 14"); EXPECT_DBL(relative);
3466 /* If the numbers can't be day/month, they are assumed to be year/month */
3467 DFS("30 2"); EXPECT_DBL(10990.0);
3468 DFS("2 30"); EXPECT_DBL(10990.0);
3469 DFS("32 49"); EXPECT_MISMATCH; /* Can't be any format */
3470 DFS("0 49"); EXPECT_MISMATCH; /* Can't be any format */
3471 /* If a month name is given the other number is the day */
3472 DFS("Jan 2"); MKRELDATE(2,1); EXPECT_DBL(relative);
3473 DFS("2 Jan"); EXPECT_DBL(relative);
3474 /* Unless it can't be, in which case it becomes the year */
3475 DFS("Jan 35"); EXPECT_DBL(12785.0);
3476 DFS("35 Jan"); EXPECT_DBL(12785.0);
3477 DFS("Jan-35"); EXPECT_DBL(12785.0);
3478 DFS("35-Jan"); EXPECT_DBL(12785.0);
3479 DFS("Jan/35"); EXPECT_DBL(12785.0);
3480 DFS("35/Jan"); EXPECT_DBL(12785.0);
3481 /* 3 elements */
3482 /* 3 numbers and time separator => h:m:s */
3483 DFS("0.1.0"); EXPECT_DBL(0.0006944444444444445);
3484 DFS("1.5.2"); EXPECT_DBL(0.04516203703703704);
3485 /* 3 numbers => picks date giving preference to lcid format */
3486 DFS("1 2 3"); EXPECT_DBL(37623.0);
3487 DFS("14 2 3"); EXPECT_DBL(41673.0);
3488 DFS("2 14 3"); EXPECT_DBL(37666.0);
3489 DFS("2 3 14"); EXPECT_DBL(41673.0);
3490 DFS("32 2 3"); EXPECT_DBL(11722.0);
3491 DFS("2 3 32"); EXPECT_DBL(11722.0);
3492 DFS("1 2 29"); EXPECT_DBL(47120.0);
3493 /* After 30, two digit dates are expected to be in the 1900's */
3494 DFS("1 2 30"); EXPECT_DBL(10960.0);
3495 DFS("1 2 31"); EXPECT_DBL(11325.0);
3496 DFS("3 am 1 2"); MKRELDATE(2,1); relative += 0.125; EXPECT_DBL(relative);
3497 DFS("1 2 3 am"); EXPECT_DBL(relative);
3499 /* 4 elements -interpreted as 2 digit date & time */
3500 DFS("1.2 3 4"); MKRELDATE(4,3); relative += 0.04305555556; EXPECT_DBL(relative);
3501 DFS("3 4 1.2"); EXPECT_DBL(relative);
3502 /* 5 elements - interpreted as 2 & 3 digit date/times */
3503 DFS("1.2.3 4 5"); MKRELDATE(5,4); relative += 0.04309027778; EXPECT_DBL(relative);
3504 DFS("1.2 3 4 5"); EXPECT_DBL(38415.04305555556);
3505 #if 0
3506 /* following throws an exception on winME */
3507 DFS("1 2 3.4.5"); MKRELDATE(2,1); relative += 0.12783564815; EXPECT_DBL(relative);
3508 #endif
3509 DFS("1 2 3 4.5"); EXPECT_DBL(37623.17013888889);
3510 /* 6 elements - interpreted as 3 digit date/times */
3511 DFS("1.2.3 4 5 6"); EXPECT_DBL(38812.04309027778);
3512 DFS("1 2 3 4.5.6"); EXPECT_DBL(37623.17020833334);
3514 for (i = 0; i < sizeof(BadDateStrings)/sizeof(char*); i++)
3516 DFS(BadDateStrings[i]); EXPECT_MISMATCH;
3519 /* Some normal-ish strings */
3520 DFS("2 January, 1970"); EXPECT_DBL(25570.0);
3521 DFS("2 January 1970"); EXPECT_DBL(25570.0);
3522 DFS("2 Jan 1970"); EXPECT_DBL(25570.0);
3523 DFS("2/Jan/1970"); EXPECT_DBL(25570.0);
3524 DFS("2-Jan-1970"); EXPECT_DBL(25570.0);
3525 DFS("1 2 1970"); EXPECT_DBL(25570.0);
3526 DFS("1/2/1970"); EXPECT_DBL(25570.0);
3527 DFS("1-2-1970"); EXPECT_DBL(25570.0);
3528 DFS("13-1-1970"); EXPECT_DBL(25581.0);
3529 DFS("1970-1-13"); EXPECT_DBL(25581.0);
3530 /* Native fails "1999 January 3, 9AM". I consider that a bug in native */
3532 /* test a non-english data string */
3533 DFS("02.01.1970"); EXPECT_MISMATCH;
3534 DFS("02.01.1970 00:00:00"); EXPECT_MISMATCH;
3535 lcid = MAKELCID(MAKELANGID(LANG_GERMAN,SUBLANG_GERMAN),SORT_DEFAULT);
3536 DFS("02.01.1970"); EXPECT_DBL(25570.0);
3537 DFS("02.13.1970"); EXPECT_DBL(25612.0);
3538 DFS("02-13-1970"); EXPECT_DBL(25612.0);
3539 DFS("2020-01-11"); EXPECT_DBL(43841.0);
3540 DFS("2173-10-14"); EXPECT_DBL(100000.0);
3542 DFS("02.01.1970 00:00:00"); EXPECT_DBL(25570.0);
3543 lcid = MAKELCID(MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH),SORT_DEFAULT);
3544 DFS("02.01.1970"); EXPECT_MISMATCH;
3545 DFS("02.01.1970 00:00:00"); EXPECT_MISMATCH;
3548 static void test_VarDateCopy(void)
3550 COPYTEST(77665544.0, VT_DATE, V_DATE(&vSrc), V_DATE(&vDst), V_DATEREF(&vSrc),
3551 V_DATEREF(&vDst), "%16.16g");
3554 static const char* wtoascii(LPWSTR lpszIn)
3556 static char buff[256];
3557 WideCharToMultiByte(CP_ACP, 0, lpszIn, -1, buff, sizeof(buff), NULL, NULL);
3558 return buff;
3561 static void test_VarDateChangeTypeEx(void)
3563 static const WCHAR sz25570[] = {
3564 '1','/','2','/','1','9','7','0','\0' };
3565 static const WCHAR sz25570_2[] = {
3566 '1','/','2','/','7','0','\0' };
3567 static const WCHAR sz25570Nls[] = {
3568 '1','/','2','/','1','9','7','0',' ','1','2',':','0','0',':','0','0',' ','A','M','\0' };
3569 HRESULT hres;
3570 DATE in;
3571 VARIANTARG vSrc, vDst;
3572 LCID lcid;
3574 in = 1.0;
3576 #ifdef HAS_UINT64_TO_FLOAT
3577 INITIAL_TYPETEST(VT_DATE, V_DATE, "%g");
3578 COMMON_TYPETEST;
3579 #endif
3581 V_VT(&vDst) = VT_EMPTY;
3582 V_VT(&vSrc) = VT_DATE;
3583 V_DATE(&vSrc) = 25570.0;
3584 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
3586 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, VARIANT_NOUSEROVERRIDE, VT_BSTR);
3587 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && V_BSTR(&vDst) &&
3588 (!lstrcmpW(V_BSTR(&vDst), sz25570) || !lstrcmpW(V_BSTR(&vDst), sz25570_2)),
3589 "hres=0x%X, type=%d (should be VT_BSTR), *bstr=%s\n",
3590 hres, V_VT(&vDst), V_BSTR(&vDst) ? wtoascii(V_BSTR(&vDst)) : "?");
3591 VariantClear(&vDst);
3593 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
3594 if (has_locales)
3596 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, VARIANT_NOUSEROVERRIDE|VARIANT_USE_NLS, VT_BSTR);
3597 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && V_BSTR(&vDst) && !lstrcmpW(V_BSTR(&vDst), sz25570Nls),
3598 "hres=0x%X, type=%d (should be VT_BSTR), *bstr=%s\n",
3599 hres, V_VT(&vDst), V_BSTR(&vDst) ? wtoascii(V_BSTR(&vDst)) : "?");
3600 VariantClear(&vDst);
3605 * VT_CY
3608 #undef CONV_TYPE
3609 #define CONV_TYPE CY
3611 #define EXPECTCY(x) \
3612 ok((hres == S_OK && out.int64 == (LONGLONG)(x*CY_MULTIPLIER)), \
3613 "expected " #x "*CY_MULTIPLIER, got (%8x %8x); hres=0x%08x\n", S(out).Hi, S(out).Lo, hres)
3615 #define EXPECTCY64(x,y) \
3616 ok(hres == S_OK && S(out).Hi == (LONG)x && S(out).Lo == y, \
3617 "expected " #x " " #y " (%u,%u), got (%u,%u); hres=0x%08x\n", \
3618 (ULONG)(x), (ULONG)(y), S(out).Hi, S(out).Lo, hres)
3620 static void test_VarCyFromI1(void)
3622 CONVVARS(signed char);
3623 int i;
3625 CHECKPTR(VarCyFromI1);
3626 for (i = -128; i < 128; i++)
3628 CONVERT(VarCyFromI1,i); EXPECTCY(i);
3632 static void test_VarCyFromUI1(void)
3634 CONVVARS(BYTE);
3635 int i;
3637 CHECKPTR(VarCyFromUI1);
3638 for (i = 0; i < 256; i++)
3640 CONVERT(VarCyFromUI1,i); EXPECTCY(i);
3644 static void test_VarCyFromI2(void)
3646 CONVVARS(SHORT);
3647 int i;
3649 CHECKPTR(VarCyFromI2);
3650 for (i = -16384; i < 16384; i++)
3652 CONVERT(VarCyFromI2,i); EXPECTCY(i);
3656 static void test_VarCyFromUI2(void)
3658 CONVVARS(int);
3659 int i;
3661 CHECKPTR(VarCyFromUI2);
3662 for (i = 0; i < 32768; i++)
3664 CONVERT(VarCyFromUI2,i); EXPECTCY(i);
3668 static void test_VarCyFromI4(void)
3670 CONVVARS(int);
3672 CHECKPTR(VarCyFromI4);
3673 CONVERT(VarCyFromI4, -1); EXPECTCY(-1);
3674 CONVERT(VarCyFromI4, 0); EXPECTCY(0);
3675 CONVERT(VarCyFromI4, 1); EXPECTCY(1);
3676 CONVERT(VarCyFromI4, 0x7fffffff); EXPECTCY64(0x1387, 0xffffd8f0);
3677 CONVERT(VarCyFromI4, 0x80000000); EXPECTCY64(0xffffec78, 0);
3680 static void test_VarCyFromUI4(void)
3682 CONVVARS(unsigned int);
3684 CHECKPTR(VarCyFromUI4);
3685 CONVERT(VarCyFromUI4, 0); EXPECTCY(0);
3686 CONVERT(VarCyFromUI4, 1); EXPECTCY(1);
3687 CONVERT(VarCyFromUI4, 0x80000000); EXPECTCY64(5000, 0);
3690 static void test_VarCyFromR4(void)
3692 CONVVARS(FLOAT);
3694 CHECKPTR(VarCyFromR4);
3695 CONVERT(VarCyFromR4, -1.0f); EXPECTCY(-1);
3696 CONVERT(VarCyFromR4, 0.0f); EXPECTCY(0);
3697 CONVERT(VarCyFromR4, 1.0f); EXPECTCY(1);
3698 CONVERT(VarCyFromR4, 1.5f); EXPECTCY(1.5);
3700 CONVERT(VarCyFromR4, -1.5f); EXPECTCY(-1.5);
3701 CONVERT(VarCyFromR4, -0.6f); EXPECTCY(-0.6);
3702 CONVERT(VarCyFromR4, -0.5f); EXPECTCY(-0.5);
3703 CONVERT(VarCyFromR4, -0.4f); EXPECTCY(-0.4);
3704 CONVERT(VarCyFromR4, 0.4f); EXPECTCY(0.4);
3705 CONVERT(VarCyFromR4, 0.5f); EXPECTCY(0.5);
3706 CONVERT(VarCyFromR4, 0.6f); EXPECTCY(0.6);
3707 CONVERT(VarCyFromR4, 1.5f); EXPECTCY(1.5);
3708 CONVERT(VarCyFromR4, 1.00009f); EXPECTCY(1.0001);
3709 CONVERT(VarCyFromR4, -1.00001f); EXPECTCY(-1);
3710 CONVERT(VarCyFromR4, -1.00005f); EXPECTCY(-1);
3711 CONVERT(VarCyFromR4, -0.00009f); EXPECTCY(-0.0001);
3712 CONVERT(VarCyFromR4, -0.00005f); EXPECTCY(0);
3713 CONVERT(VarCyFromR4, -0.00001f); EXPECTCY(0);
3714 CONVERT(VarCyFromR4, 0.00001f); EXPECTCY(0);
3715 CONVERT(VarCyFromR4, 0.00005f); EXPECTCY(0);
3716 CONVERT(VarCyFromR4, 0.00009f); EXPECTCY(0.0001);
3717 CONVERT(VarCyFromR4, -1.00001f); EXPECTCY(-1);
3718 CONVERT(VarCyFromR4, -1.00005f); EXPECTCY(-1);
3719 CONVERT(VarCyFromR4, -1.00009f); EXPECTCY(-1.0001);
3722 static void test_VarCyFromR8(void)
3724 CONVVARS(DOUBLE);
3726 CHECKPTR(VarCyFromR8);
3728 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3729 /* Test our rounding is exactly the same. This fails if the special x86
3730 * code is taken out of VarCyFromR8.
3732 CONVERT(VarCyFromR8, -461168601842738.7904); EXPECTCY64(0xbfffffff, 0xffffff23);
3733 #endif
3735 CONVERT(VarCyFromR8, -4611686018427388416.1); EXPECT_OVERFLOW;
3736 CONVERT(VarCyFromR8, -1.0); EXPECTCY(-1);
3737 CONVERT(VarCyFromR8, -0.0); EXPECTCY(0);
3738 CONVERT(VarCyFromR8, 1.0); EXPECTCY(1);
3739 CONVERT(VarCyFromR8, 4611686018427387648.0); EXPECT_OVERFLOW;
3741 /* Rounding */
3742 CONVERT(VarCyFromR8, -1.5f); EXPECTCY(-1.5);
3743 CONVERT(VarCyFromR8, -0.6f); EXPECTCY(-0.6);
3744 CONVERT(VarCyFromR8, -0.5f); EXPECTCY(-0.5);
3745 CONVERT(VarCyFromR8, -0.4f); EXPECTCY(-0.4);
3746 CONVERT(VarCyFromR8, 0.4f); EXPECTCY(0.4);
3747 CONVERT(VarCyFromR8, 0.5f); EXPECTCY(0.5);
3748 CONVERT(VarCyFromR8, 0.6f); EXPECTCY(0.6);
3749 CONVERT(VarCyFromR8, 1.5f); EXPECTCY(1.5);
3750 CONVERT(VarCyFromR8, 1.00009f); EXPECTCY(1.0001);
3751 CONVERT(VarCyFromR8, -1.00001f); EXPECTCY(-1);
3752 CONVERT(VarCyFromR8, -1.00005f); EXPECTCY(-1);
3753 CONVERT(VarCyFromR8, -0.00009f); EXPECTCY(-0.0001);
3754 CONVERT(VarCyFromR8, -0.00005f); EXPECTCY(0);
3755 CONVERT(VarCyFromR8, -0.00001f); EXPECTCY(0);
3756 CONVERT(VarCyFromR8, 0.00001f); EXPECTCY(0);
3757 CONVERT(VarCyFromR8, 0.00005f); EXPECTCY(0);
3758 CONVERT(VarCyFromR8, 0.00009f); EXPECTCY(0.0001);
3759 CONVERT(VarCyFromR8, -1.00001f); EXPECTCY(-1);
3760 CONVERT(VarCyFromR8, -1.00005f); EXPECTCY(-1);
3761 CONVERT(VarCyFromR8, -1.00009f); EXPECTCY(-1.0001);
3764 static void test_VarCyFromBool(void)
3766 CONVVARS(VARIANT_BOOL);
3767 int i;
3769 CHECKPTR(VarCyFromBool);
3770 for (i = -32768; i < 32768; i++)
3772 CONVERT(VarCyFromBool, i); EXPECTCY(i);
3776 static void test_VarCyFromI8(void)
3778 CONVVARS(LONG64);
3780 CHECKPTR(VarCyFromI8);
3781 CONVERT_I8(VarCyFromI8, -214749, 2728163227ul); EXPECT_OVERFLOW;
3782 CONVERT_I8(VarCyFromI8, -214749, 2728163228ul); EXPECTCY64(2147483648ul,15808);
3783 CONVERT(VarCyFromI8, -1); EXPECTCY(-1);
3784 CONVERT(VarCyFromI8, 0); EXPECTCY(0);
3785 CONVERT(VarCyFromI8, 1); EXPECTCY(1);
3786 CONVERT_I8(VarCyFromI8, 214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3787 CONVERT_I8(VarCyFromI8, 214748, 1566804069); EXPECT_OVERFLOW;
3790 static void test_VarCyFromUI8(void)
3792 CONVVARS(ULONG64);
3794 CHECKPTR(VarCyFromUI8);
3795 CONVERT(VarCyFromUI8, 0); EXPECTCY(0);
3796 CONVERT(VarCyFromUI8, 1); EXPECTCY(1);
3797 CONVERT_I8(VarCyFromUI8, 214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3798 CONVERT_I8(VarCyFromUI8, 214748, 1566804069); EXPECTCY64(2147483647ul, 4294961488ul);
3799 CONVERT_I8(VarCyFromUI8, 214748, 1566804070); EXPECT_OVERFLOW;
3800 CONVERT_I8(VarCyFromUI8, 214749, 1566804068); EXPECT_OVERFLOW;
3803 static void test_VarCyFromDec(void)
3805 CONVVARS(DECIMAL);
3807 CHECKPTR(VarCyFromDec);
3809 CONVERT_BADDEC(VarCyFromDec);
3811 CONVERT_DEC(VarCyFromDec,0,0x80,0,1); EXPECTCY(-1);
3812 CONVERT_DEC(VarCyFromDec,0,0,0,0); EXPECTCY(0);
3813 CONVERT_DEC(VarCyFromDec,0,0,0,1); EXPECTCY(1);
3815 CONVERT_DEC64(VarCyFromDec,0,0,0,214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3816 CONVERT_DEC64(VarCyFromDec,0,0,0,214748, 1566804069); EXPECTCY64(2147483647ul, 4294961488ul);
3817 CONVERT_DEC64(VarCyFromDec,0,0,0,214748, 1566804070); EXPECT_OVERFLOW;
3818 CONVERT_DEC64(VarCyFromDec,0,0,0,214749, 1566804068); EXPECT_OVERFLOW;
3820 CONVERT_DEC(VarCyFromDec,2,0,0,100); EXPECTCY(1);
3821 CONVERT_DEC(VarCyFromDec,2,0x80,0,100); EXPECTCY(-1);
3822 CONVERT_DEC(VarCyFromDec,2,0x80,0,1); EXPECTCY(-0.01);
3823 CONVERT_DEC(VarCyFromDec,2,0,0,1); EXPECTCY(0.01);
3824 CONVERT_DEC(VarCyFromDec,2,0x80,0,1); EXPECTCY(-0.01);
3825 CONVERT_DEC(VarCyFromDec,2,0,0,999); EXPECTCY(9.99);
3826 CONVERT_DEC(VarCyFromDec,2,0x80,0,999); EXPECTCY(-9.99);
3827 CONVERT_DEC(VarCyFromDec,2,0,0,1500); EXPECTCY(15);
3828 CONVERT_DEC(VarCyFromDec,2,0x80,0,1500); EXPECTCY(-15);
3831 static void test_VarCyFromDate(void)
3833 CONVVARS(DATE);
3835 CHECKPTR(VarCyFromDate);
3837 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3838 CONVERT(VarCyFromR8, -461168601842738.7904); EXPECTCY64(0xbfffffff, 0xffffff23);
3839 #endif
3841 CONVERT(VarCyFromDate, -1.0); EXPECTCY(-1);
3842 CONVERT(VarCyFromDate, -0.0); EXPECTCY(0);
3843 CONVERT(VarCyFromDate, 1.0); EXPECTCY(1);
3844 CONVERT(VarCyFromDate, -4611686018427388416.1); EXPECT_OVERFLOW;
3845 CONVERT(VarCyFromDate, 4611686018427387648.0); EXPECT_OVERFLOW;
3847 /* Rounding */
3848 CONVERT(VarCyFromDate, -1.5f); EXPECTCY(-1.5);
3849 CONVERT(VarCyFromDate, -0.6f); EXPECTCY(-0.6);
3850 CONVERT(VarCyFromDate, -0.5f); EXPECTCY(-0.5);
3851 CONVERT(VarCyFromDate, -0.4f); EXPECTCY(-0.4);
3852 CONVERT(VarCyFromDate, 0.4f); EXPECTCY(0.4);
3853 CONVERT(VarCyFromDate, 0.5f); EXPECTCY(0.5);
3854 CONVERT(VarCyFromDate, 0.6f); EXPECTCY(0.6);
3855 CONVERT(VarCyFromDate, 1.5f); EXPECTCY(1.5);
3856 CONVERT(VarCyFromDate, 1.00009f); EXPECTCY(1.0001);
3857 CONVERT(VarCyFromDate, -1.00001f); EXPECTCY(-1);
3858 CONVERT(VarCyFromDate, -1.00005f); EXPECTCY(-1);
3859 CONVERT(VarCyFromDate, -0.00009f); EXPECTCY(-0.0001);
3860 CONVERT(VarCyFromDate, -0.00005f); EXPECTCY(0);
3861 CONVERT(VarCyFromDate, -0.00001f); EXPECTCY(0);
3862 CONVERT(VarCyFromDate, 0.00001f); EXPECTCY(0);
3863 CONVERT(VarCyFromDate, 0.00005f); EXPECTCY(0);
3864 CONVERT(VarCyFromDate, 0.00009f); EXPECTCY(0.0001);
3865 CONVERT(VarCyFromDate, -1.00001f); EXPECTCY(-1);
3866 CONVERT(VarCyFromDate, -1.00005f); EXPECTCY(-1);
3867 CONVERT(VarCyFromDate, -1.00009f); EXPECTCY(-1.0001);
3870 #define MATHVARS1 HRESULT hres; double left = 0.0; CY cyLeft, out
3871 #define MATHVARS2 MATHVARS1; double right = 0.0; CY cyRight
3872 #define MATH1(func, l) left = (double)l; pVarCyFromR8(left, &cyLeft); hres = p##func(cyLeft, &out)
3873 #define MATH2(func, l, r) left = (double)l; right = (double)r; \
3874 pVarCyFromR8(left, &cyLeft); pVarCyFromR8(right, &cyRight); \
3875 hres = p##func(cyLeft, cyRight, &out)
3877 static void test_VarCyAdd(void)
3879 MATHVARS2;
3881 CHECKPTR(VarCyAdd);
3882 MATH2(VarCyAdd, 0.5, 0.5); EXPECTCY(1);
3883 MATH2(VarCyAdd, 0.5, -0.4); EXPECTCY(0.1);
3884 MATH2(VarCyAdd, 0.5, -0.6); EXPECTCY(-0.1);
3885 MATH2(VarCyAdd, -0.5, -0.5); EXPECTCY(-1);
3886 MATH2(VarCyAdd, -922337203685476.0, -922337203685476.0); EXPECT_OVERFLOW;
3887 MATH2(VarCyAdd, -922337203685476.0, 922337203685476.0); EXPECTCY(0);
3888 MATH2(VarCyAdd, 922337203685476.0, -922337203685476.0); EXPECTCY(0);
3889 MATH2(VarCyAdd, 922337203685476.0, 922337203685476.0); EXPECT_OVERFLOW;
3892 static void test_VarCyMul(void)
3894 MATHVARS2;
3896 CHECKPTR(VarCyMul);
3897 MATH2(VarCyMul, 534443.0, 0.0); EXPECTCY(0);
3898 MATH2(VarCyMul, 0.5, 0.5); EXPECTCY(0.25);
3899 MATH2(VarCyMul, 0.5, -0.4); EXPECTCY(-0.2);
3900 MATH2(VarCyMul, 0.5, -0.6); EXPECTCY(-0.3);
3901 MATH2(VarCyMul, -0.5, -0.5); EXPECTCY(0.25);
3902 MATH2(VarCyMul, 922337203685476.0, 20000); EXPECT_OVERFLOW;
3905 static void test_VarCySub(void)
3907 MATHVARS2;
3909 CHECKPTR(VarCySub);
3910 MATH2(VarCySub, 0.5, 0.5); EXPECTCY(0);
3911 MATH2(VarCySub, 0.5, -0.4); EXPECTCY(0.9);
3912 MATH2(VarCySub, 0.5, -0.6); EXPECTCY(1.1);
3913 MATH2(VarCySub, -0.5, -0.5); EXPECTCY(0);
3914 MATH2(VarCySub, -922337203685476.0, -922337203685476.0); EXPECTCY(0);
3915 MATH2(VarCySub, -922337203685476.0, 922337203685476.0); EXPECT_OVERFLOW;
3916 MATH2(VarCySub, 922337203685476.0, -922337203685476.0); EXPECT_OVERFLOW;
3917 MATH2(VarCySub, 922337203685476.0, 922337203685476.0); EXPECTCY(0);
3920 static void test_VarCyAbs(void)
3922 MATHVARS1;
3924 CHECKPTR(VarCyAbs);
3925 MATH1(VarCyAbs, 0.5); EXPECTCY(0.5);
3926 MATH1(VarCyAbs, -0.5); EXPECTCY(0.5);
3927 MATH1(VarCyAbs, 922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3928 MATH1(VarCyAbs, -922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3931 static void test_VarCyNeg(void)
3933 MATHVARS1;
3935 CHECKPTR(VarCyNeg);
3936 MATH1(VarCyNeg, 0.5); EXPECTCY(-0.5);
3937 MATH1(VarCyNeg, -0.5); EXPECTCY(0.5);
3938 MATH1(VarCyNeg, 922337203685476.0); EXPECTCY64(2147483648ul,15808);
3939 MATH1(VarCyNeg, -922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3942 #define MATHMULI4(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3943 hres = pVarCyMulI4(cyLeft, right, &out)
3945 static void test_VarCyMulI4(void)
3947 MATHVARS1;
3948 LONG right;
3950 CHECKPTR(VarCyMulI4);
3951 MATHMULI4(534443.0, 0); EXPECTCY(0);
3952 MATHMULI4(0.5, 1); EXPECTCY(0.5);
3953 MATHMULI4(0.5, 2); EXPECTCY(1);
3954 MATHMULI4(922337203685476.0, 1); EXPECTCY64(2147483647ul,4294951488ul);
3955 MATHMULI4(922337203685476.0, 2); EXPECT_OVERFLOW;
3958 #define MATHMULI8(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3959 hres = pVarCyMulI8(cyLeft, right, &out)
3961 static void test_VarCyMulI8(void)
3963 MATHVARS1;
3964 LONG64 right;
3966 CHECKPTR(VarCyMulI8);
3967 MATHMULI8(534443.0, 0); EXPECTCY(0);
3968 MATHMULI8(0.5, 1); EXPECTCY(0.5);
3969 MATHMULI8(0.5, 2); EXPECTCY(1);
3970 MATHMULI8(922337203685476.0, 1); EXPECTCY64(2147483647ul,4294951488ul);
3971 MATHMULI8(922337203685476.0, 2); EXPECT_OVERFLOW;
3974 #define MATHCMP(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); pVarCyFromR8(right, &cyRight); \
3975 hres = pVarCyCmp(cyLeft, cyRight)
3977 static void test_VarCyCmp(void)
3979 HRESULT hres;
3980 double left = 0.0, right = 0.0;
3981 CY cyLeft, cyRight;
3983 CHECKPTR(VarCyCmp);
3984 MATHCMP(-1.0, -1.0); EXPECT_EQ;
3985 MATHCMP(-1.0, 0.0); EXPECT_LT;
3986 MATHCMP(-1.0, 1.0); EXPECT_LT;
3987 MATHCMP(-1.0, 2.0); EXPECT_LT;
3988 MATHCMP(0.0, 1.0); EXPECT_LT;
3989 MATHCMP(0.0, 0.0); EXPECT_EQ;
3990 MATHCMP(0.0, -1.0); EXPECT_GT;
3991 MATHCMP(1.0, -1.0); EXPECT_GT;
3992 MATHCMP(1.0, 0.0); EXPECT_GT;
3993 MATHCMP(1.0, 1.0); EXPECT_EQ;
3994 MATHCMP(1.0, 2.0); EXPECT_LT;
3997 #define MATHCMPR8(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3998 hres = pVarCyCmpR8(cyLeft, right);
4000 static void test_VarCyCmpR8(void)
4002 HRESULT hres;
4003 double left = 0.0;
4004 CY cyLeft;
4005 double right;
4007 CHECKPTR(VarCyCmpR8);
4008 MATHCMPR8(-1.0, -1.0); EXPECT_EQ;
4009 MATHCMPR8(-1.0, 0.0); EXPECT_LT;
4010 MATHCMPR8(-1.0, 1.0); EXPECT_LT;
4011 MATHCMPR8(-1.0, 2.0); EXPECT_LT;
4012 MATHCMPR8(0.0, 1.0); EXPECT_LT;
4013 MATHCMPR8(0.0, 0.0); EXPECT_EQ;
4014 MATHCMPR8(0.0, -1.0); EXPECT_GT;
4015 MATHCMPR8(1.0, -1.0); EXPECT_GT;
4016 MATHCMPR8(1.0, 0.0); EXPECT_GT;
4017 MATHCMPR8(1.0, 1.0); EXPECT_EQ;
4018 MATHCMPR8(1.0, 2.0); EXPECT_LT;
4021 #undef MATHRND
4022 #define MATHRND(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
4023 hres = pVarCyRound(cyLeft, right, &out)
4025 static void test_VarCyRound(void)
4027 MATHVARS1;
4028 int right;
4030 CHECKPTR(VarCyRound);
4031 MATHRND(0.5432, 5); EXPECTCY(0.5432);
4032 MATHRND(0.5432, 4); EXPECTCY(0.5432);
4033 MATHRND(0.5432, 3); EXPECTCY(0.543);
4034 MATHRND(0.5432, 2); EXPECTCY(0.54);
4035 MATHRND(0.5432, 1); EXPECTCY(0.5);
4036 MATHRND(0.5532, 0); EXPECTCY(1);
4037 MATHRND(0.5532, -1); EXPECT_INVALID;
4039 MATHRND(0.5568, 5); EXPECTCY(0.5568);
4040 MATHRND(0.5568, 4); EXPECTCY(0.5568);
4041 MATHRND(0.5568, 3); EXPECTCY(0.557);
4042 MATHRND(0.5568, 2); EXPECTCY(0.56);
4043 MATHRND(0.5568, 1); EXPECTCY(0.6);
4044 MATHRND(0.5568, 0); EXPECTCY(1);
4045 MATHRND(0.5568, -1); EXPECT_INVALID;
4047 MATHRND(0.4999, 0); EXPECTCY(0);
4048 MATHRND(0.5000, 0); EXPECTCY(0);
4049 MATHRND(0.5001, 0); EXPECTCY(1);
4050 MATHRND(1.4999, 0); EXPECTCY(1);
4051 MATHRND(1.5000, 0); EXPECTCY(2);
4052 MATHRND(1.5001, 0); EXPECTCY(2);
4055 #define MATHFIX(l) left = l; pVarCyFromR8(left, &cyLeft); \
4056 hres = pVarCyFix(cyLeft, &out)
4058 static void test_VarCyFix(void)
4060 MATHVARS1;
4062 CHECKPTR(VarCyFix);
4063 MATHFIX(-1.0001); EXPECTCY(-1);
4064 MATHFIX(-1.4999); EXPECTCY(-1);
4065 MATHFIX(-1.5001); EXPECTCY(-1);
4066 MATHFIX(-1.9999); EXPECTCY(-1);
4067 MATHFIX(-0.0001); EXPECTCY(0);
4068 MATHFIX(-0.4999); EXPECTCY(0);
4069 MATHFIX(-0.5001); EXPECTCY(0);
4070 MATHFIX(-0.9999); EXPECTCY(0);
4071 MATHFIX(0.0001); EXPECTCY(0);
4072 MATHFIX(0.4999); EXPECTCY(0);
4073 MATHFIX(0.5001); EXPECTCY(0);
4074 MATHFIX(0.9999); EXPECTCY(0);
4075 MATHFIX(1.0001); EXPECTCY(1);
4076 MATHFIX(1.4999); EXPECTCY(1);
4077 MATHFIX(1.5001); EXPECTCY(1);
4078 MATHFIX(1.9999); EXPECTCY(1);
4081 #define MATHINT(l) left = l; pVarCyFromR8(left, &cyLeft); \
4082 hres = pVarCyInt(cyLeft, &out)
4084 static void test_VarCyInt(void)
4086 MATHVARS1;
4088 CHECKPTR(VarCyInt);
4089 MATHINT(-1.0001); EXPECTCY(-2);
4090 MATHINT(-1.4999); EXPECTCY(-2);
4091 MATHINT(-1.5001); EXPECTCY(-2);
4092 MATHINT(-1.9999); EXPECTCY(-2);
4093 MATHINT(-0.0001); EXPECTCY(-1);
4094 MATHINT(-0.4999); EXPECTCY(-1);
4095 MATHINT(-0.5001); EXPECTCY(-1);
4096 MATHINT(-0.9999); EXPECTCY(-1);
4097 MATHINT(0.0001); EXPECTCY(0);
4098 MATHINT(0.4999); EXPECTCY(0);
4099 MATHINT(0.5001); EXPECTCY(0);
4100 MATHINT(0.9999); EXPECTCY(0);
4101 MATHINT(1.0001); EXPECTCY(1);
4102 MATHINT(1.4999); EXPECTCY(1);
4103 MATHINT(1.5001); EXPECTCY(1);
4104 MATHINT(1.9999); EXPECTCY(1);
4108 * VT_DECIMAL
4111 #undef CONV_TYPE
4112 #define CONV_TYPE DECIMAL
4114 #define EXPECTDEC(scl, sgn, hi, lo) ok(hres == S_OK && \
4115 S(U(out)).scale == (BYTE)(scl) && S(U(out)).sign == (BYTE)(sgn) && \
4116 out.Hi32 == (ULONG)(hi) && U1(out).Lo64 == (ULONG64)(lo), \
4117 "expected (%d,%d,%d,(%x %x)), got (%d,%d,%d,(%x %x)) hres 0x%08x\n", \
4118 scl, sgn, hi, (LONG)((LONG64)(lo) >> 32), (LONG)((lo) & 0xffffffff), S(U(out)).scale, \
4119 S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres)
4121 #define EXPECTDEC64(scl, sgn, hi, mid, lo) ok(hres == S_OK && \
4122 S(U(out)).scale == (BYTE)(scl) && S(U(out)).sign == (BYTE)(sgn) && \
4123 out.Hi32 == (ULONG)(hi) && S1(U1(out)).Mid32 == (ULONG)(mid) && \
4124 S1(U1(out)).Lo32 == (ULONG)(lo), \
4125 "expected (%d,%d,%d,(%x %x)), got (%d,%d,%d,(%x %x)) hres 0x%08x\n", \
4126 scl, sgn, hi, (LONG)(mid), (LONG)(lo), S(U(out)).scale, \
4127 S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres)
4129 /* expect either a positive or negative zero */
4130 #define EXPECTDECZERO() ok(hres == S_OK && S(U(out)).scale == 0 && \
4131 (S(U(out)).sign == 0 || S(U(out)).sign == 0x80) && out.Hi32 == 0 && U1(out).Lo64 == 0, \
4132 "expected zero, got (%d,%d,%d,(%x %x)) hres 0x%08x\n", \
4133 S(U(out)).scale, S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres)
4135 #define EXPECTDECI if (i < 0) EXPECTDEC(0, 0x80, 0, -i); else EXPECTDEC(0, 0, 0, i)
4137 static void test_VarDecFromI1(void)
4139 CONVVARS(signed char);
4140 int i;
4142 CHECKPTR(VarDecFromI1);
4143 for (i = -128; i < 128; i++)
4145 CONVERT(VarDecFromI1,i); EXPECTDECI;
4149 static void test_VarDecFromI2(void)
4151 CONVVARS(SHORT);
4152 int i;
4154 CHECKPTR(VarDecFromI2);
4155 for (i = -32768; i < 32768; i++)
4157 CONVERT(VarDecFromI2,i); EXPECTDECI;
4161 static void test_VarDecFromI4(void)
4163 CONVVARS(LONG);
4164 int i;
4166 CHECKPTR(VarDecFromI4);
4167 for (i = -32768; i < 32768; i++)
4169 CONVERT(VarDecFromI4,i); EXPECTDECI;
4173 static void test_VarDecFromI8(void)
4175 CONVVARS(LONG64);
4176 int i;
4178 CHECKPTR(VarDecFromI8);
4179 for (i = -32768; i < 32768; i++)
4181 CONVERT(VarDecFromI8,i); EXPECTDECI;
4185 static void test_VarDecFromUI1(void)
4187 CONVVARS(BYTE);
4188 int i;
4190 CHECKPTR(VarDecFromUI1);
4191 for (i = 0; i < 256; i++)
4193 CONVERT(VarDecFromUI1,i); EXPECTDECI;
4197 static void test_VarDecFromUI2(void)
4199 CONVVARS(USHORT);
4200 int i;
4202 CHECKPTR(VarDecFromUI2);
4203 for (i = 0; i < 65536; i++)
4205 CONVERT(VarDecFromUI2,i); EXPECTDECI;
4209 static void test_VarDecFromUI4(void)
4211 CONVVARS(ULONG);
4212 int i;
4214 CHECKPTR(VarDecFromUI4);
4215 for (i = 0; i < 65536; i++)
4217 CONVERT(VarDecFromUI4,i); EXPECTDECI;
4221 static void test_VarDecFromUI8(void)
4223 CONVVARS(ULONG64);
4224 int i;
4226 CHECKPTR(VarDecFromUI8);
4227 for (i = 0; i < 65536; i++)
4229 CONVERT(VarDecFromUI8,i); EXPECTDECI;
4233 static void test_VarDecFromBool(void)
4235 CONVVARS(SHORT);
4236 int i;
4238 CHECKPTR(VarDecFromBool);
4239 /* Test all possible type values. Note that the result is reduced to 0 or -1 */
4240 for (i = -32768; i < 0; i++)
4242 CONVERT(VarDecFromBool,i);
4243 if (i)
4244 EXPECTDEC(0,0x80,0,1);
4245 else
4246 EXPECTDEC(0,0,0,0);
4250 static void test_VarDecFromR4(void)
4252 CONVVARS(float);
4254 CHECKPTR(VarDecFromR4);
4256 CONVERT(VarDecFromR4,-0.6f); EXPECTDEC(1,0x80,0,6);
4257 CONVERT(VarDecFromR4,-0.5f); EXPECTDEC(1,0x80,0,5);
4258 CONVERT(VarDecFromR4,-0.4f); EXPECTDEC(1,0x80,0,4);
4259 CONVERT(VarDecFromR4,0.0f); EXPECTDEC(0,0,0,0);
4260 CONVERT(VarDecFromR4,0.4f); EXPECTDEC(1,0,0,4);
4261 CONVERT(VarDecFromR4,0.5f); EXPECTDEC(1,0,0,5);
4262 CONVERT(VarDecFromR4,0.6f); EXPECTDEC(1,0,0,6);
4265 static void test_VarDecFromR8(void)
4267 CONVVARS(double);
4269 CHECKPTR(VarDecFromR8);
4271 CONVERT(VarDecFromR8,-0.6); EXPECTDEC(1,0x80,0,6);
4272 CONVERT(VarDecFromR8,-0.5); EXPECTDEC(1,0x80,0,5);
4273 CONVERT(VarDecFromR8,-0.4); EXPECTDEC(1,0x80,0,4);
4274 CONVERT(VarDecFromR8,0.0); EXPECTDEC(0,0,0,0);
4275 CONVERT(VarDecFromR8,0.4); EXPECTDEC(1,0,0,4);
4276 CONVERT(VarDecFromR8,0.5); EXPECTDEC(1,0,0,5);
4277 CONVERT(VarDecFromR8,0.6); EXPECTDEC(1,0,0,6);
4280 static void test_VarDecFromDate(void)
4282 CONVVARS(DATE);
4284 CHECKPTR(VarDecFromDate);
4286 CONVERT(VarDecFromDate,-0.6); EXPECTDEC(1,0x80,0,6);
4287 CONVERT(VarDecFromDate,-0.5); EXPECTDEC(1,0x80,0,5);
4288 CONVERT(VarDecFromDate,-0.4); EXPECTDEC(1,0x80,0,4);
4289 CONVERT(VarDecFromDate,0.0); EXPECTDEC(0,0,0,0);
4290 CONVERT(VarDecFromDate,0.4); EXPECTDEC(1,0,0,4);
4291 CONVERT(VarDecFromDate,0.5); EXPECTDEC(1,0,0,5);
4292 CONVERT(VarDecFromDate,0.6); EXPECTDEC(1,0,0,6);
4295 static void test_VarDecFromStr(void)
4297 CONVVARS(LCID);
4298 OLECHAR buff[128];
4300 CHECKPTR(VarDecFromStr);
4302 in = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4304 CONVERT_STR(VarDecFromStr,NULL,0); EXPECT_MISMATCH;
4305 CONVERT_STR(VarDecFromStr,"-1", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0x80,0,1);
4306 CONVERT_STR(VarDecFromStr,"0", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0,0,0);
4307 CONVERT_STR(VarDecFromStr,"1", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0,0,1);
4308 CONVERT_STR(VarDecFromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECTDEC(1,0,0,5);
4309 CONVERT_STR(VarDecFromStr,"4294967296", LOCALE_NOUSEROVERRIDE); EXPECTDEC64(0,0,0,1,0);
4310 CONVERT_STR(VarDecFromStr,"18446744073709551616", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0,1,0);
4311 CONVERT_STR(VarDecFromStr,"4294967296.0", LOCALE_NOUSEROVERRIDE); EXPECTDEC64(0,0,0,1,0);
4312 CONVERT_STR(VarDecFromStr,"18446744073709551616.0", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0,1,0);
4315 static void test_VarDecFromCy(void)
4317 CONVVARS(CY);
4319 CHECKPTR(VarDecFromCy);
4321 CONVERT_CY(VarDecFromCy, -1); EXPECTDEC(4,0x80,0,10000);
4322 CONVERT_CY(VarDecFromCy, 0); EXPECTDEC(4,0,0,0);
4323 CONVERT_CY(VarDecFromCy, 1); EXPECTDEC(4,0,0,10000);
4324 CONVERT_CY(VarDecFromCy, 0.5); EXPECTDEC(4,0,0,5000);
4327 #undef MATHVARS1
4328 #define MATHVARS1 HRESULT hres; DECIMAL l, out
4329 #undef MATHVARS2
4330 #define MATHVARS2 MATHVARS1; DECIMAL r
4331 #undef MATH1
4332 #define MATH1(func) hres = p##func(&l, &out)
4333 #undef MATH2
4334 #define MATH2(func) hres = p##func(&l, &r, &out)
4335 #undef MATH3
4336 #define MATH3(func) hres = p##func(&l, r)
4338 static void test_VarDecAbs(void)
4340 MATHVARS1;
4342 CHECKPTR(VarDecAbs);
4343 SETDEC(l,0,0x80,0,1); MATH1(VarDecAbs); EXPECTDEC(0,0,0,1);
4344 SETDEC(l,0,0,0,0); MATH1(VarDecAbs); EXPECTDEC(0,0,0,0);
4345 SETDEC(l,0,0x80,0,0); MATH1(VarDecAbs); EXPECTDEC(0,0,0,0);
4346 SETDEC(l,0,0,0,1); MATH1(VarDecAbs); EXPECTDEC(0,0,0,1);
4348 /* Doesn't check for invalid input */
4349 SETDEC(l,0,0x7f,0,1); MATH1(VarDecAbs); EXPECTDEC(0,0x7f,0,1);
4350 SETDEC(l,0,0x80,29,1); MATH1(VarDecAbs); EXPECTDEC(0,0,29,1);
4353 static void test_VarDecNeg(void)
4355 MATHVARS1;
4357 CHECKPTR(VarDecNeg);
4358 SETDEC(l,0,0x80,0,1); MATH1(VarDecNeg); EXPECTDEC(0,0,0,1);
4359 SETDEC(l,0,0,0,0); MATH1(VarDecNeg); EXPECTDEC(0,0x80,0,0); /* '-0'! */
4360 SETDEC(l,0,0x80,0,0); MATH1(VarDecNeg); EXPECTDEC(0,0,0,0);
4361 SETDEC(l,0,0,0,1); MATH1(VarDecNeg); EXPECTDEC(0,0x80,0,1);
4363 /* Doesn't check for invalid input */
4364 SETDEC(l,0,0x7f,0,1); MATH1(VarDecNeg); EXPECTDEC(0,0xff,0,1);
4365 SETDEC(l,0,0x80,29,1); MATH1(VarDecNeg); EXPECTDEC(0,0,29,1);
4366 SETDEC(l,0,0,29,1); MATH1(VarDecNeg); EXPECTDEC(0,0x80,29,1);
4369 static void test_VarDecAdd(void)
4371 MATHVARS2;
4373 CHECKPTR(VarDecAdd);
4374 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecAdd); EXPECTDEC(0,0,0,0);
4375 SETDEC(l,0,0,0,0); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,1);
4376 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,1);
4378 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,0); MATH2(VarDecAdd); EXPECTDEC(0,0,0,1);
4379 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,2);
4380 SETDEC(l,0,0,0,1); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd); EXPECTDECZERO();
4381 SETDEC(l,0,0,0,1); SETDEC(r,0,0x80,0,2); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,1);
4383 SETDEC(l,0,0x80,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,1);
4384 SETDEC(l,0,0x80,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDECZERO();
4385 SETDEC(l,0,0x80,0,1); SETDEC(r,0,0,0,2); MATH2(VarDecAdd); EXPECTDEC(0,0,0,1);
4386 SETDEC(l,0,0x80,0,1); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,2);
4387 SETDEC(l,0,0x80,0,2); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,1);
4389 SETDEC(l,0,0,0,0xffffffff); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,0xfffffffe);
4390 SETDEC(l,0,0,0,0xffffffff); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,(ULONG64)1 << 32);
4391 SETDEC(l,0,0,0,0xffffffff); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,(ULONG64)1 << 32);
4393 SETDEC64(l,0,0,0,0xffffffff,0); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC64(0,0,0,0xffffffff,1);
4394 SETDEC64(l,0,0,0,0xffffffff,0); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd);
4395 EXPECTDEC64(0,0,0,0xfffffffe,0xffffffff);
4397 SETDEC64(l,0,0,0,0xffffffff,0xffffffff); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,1,0);
4398 SETDEC64(l,0,0,0,0xffffffff,0xffffffff); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd);
4399 EXPECTDEC64(0,0,0,0xffffffff,0xfffffffe);
4401 SETDEC(l,0,0,0xffffffff,0); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0xffffffff,1);
4402 SETDEC(l,0,0,0xffffffff,0); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd);
4403 EXPECTDEC64(0,0,0xfffffffe,0xffffffff,0xffffffff);
4405 SETDEC64(l,0,0,0xffffffff,0xffffffff,0xffffffff);SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd);
4406 EXPECTDEC64(0,0,0xffffffff,0xffffffff,0xfffffffe);
4407 SETDEC64(l,0,0,0xffffffff,0xffffffff,0xffffffff);SETDEC(r,0,0,0,1); MATH2(VarDecAdd);
4408 ok(hres == DISP_E_OVERFLOW,"Expected overflow, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
4409 S(U(out)).scale, S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres);
4411 SETDEC(l,3,128,0,123456); SETDEC64(r,0,0,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF);
4412 MATH2(VarDecAdd); todo_wine EXPECTDEC64(0,0,-1,0xFFFFFFFF,0xFFFFFF84);
4414 /* Promotes to the highest scale, so here the results are in the scale of 2 */
4415 SETDEC(l,2,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecAdd); EXPECTDEC(2,0,0,0);
4416 SETDEC(l,2,0,0,100); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(2,0,0,200);
4419 static void test_VarDecSub(void)
4421 MATHVARS2;
4423 CHECKPTR(VarDecSub);
4424 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecSub); EXPECTDECZERO();
4425 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecSub); EXPECTDEC(0,0x80,0,1);
4426 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecSub); EXPECTDECZERO();
4427 SETDEC(l,0,0,0,1); SETDEC(r,0,0x80,0,1); MATH2(VarDecSub); EXPECTDEC(0,0,0,2);
4430 static void test_VarDecMul(void)
4432 MATHVARS2;
4434 CHECKPTR(VarDecMul);
4435 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecMul); EXPECTDEC(0,0,0,0);
4436 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,0); MATH2(VarDecMul); EXPECTDEC(0,0,0,0);
4437 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecMul); EXPECTDEC(0,0,0,0);
4438 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecMul); EXPECTDEC(0,0,0,1);
4439 SETDEC(l,0,0,0,45000);SETDEC(r,0,0,0,2); MATH2(VarDecMul); EXPECTDEC(0,0,0,90000);
4440 SETDEC(l,0,0,0,2); SETDEC(r,0,0,0,45000); MATH2(VarDecMul); EXPECTDEC(0,0,0,90000);
4442 SETDEC(l,0,0x80,0,2); SETDEC(r,0,0,0,2); MATH2(VarDecMul); EXPECTDEC(0,0x80,0,4);
4443 SETDEC(l,0,0,0,2); SETDEC(r,0,0x80,0,2); MATH2(VarDecMul); EXPECTDEC(0,0x80,0,4);
4444 SETDEC(l,0,0x80,0,2); SETDEC(r,0,0x80,0,2); MATH2(VarDecMul); EXPECTDEC(0,0,0,4);
4446 SETDEC(l,4,0,0,2); SETDEC(r,0,0,0,2); MATH2(VarDecMul); EXPECTDEC(4,0,0,4);
4447 SETDEC(l,0,0,0,2); SETDEC(r,3,0,0,2); MATH2(VarDecMul); EXPECTDEC(3,0,0,4);
4448 SETDEC(l,4,0,0,2); SETDEC(r,3,0,0,2); MATH2(VarDecMul); EXPECTDEC(7,0,0,4);
4449 /* this last one shows that native oleaut32 does *not* gratuitously seize opportunities
4450 to reduce the scale if possible - the canonical result for the expected value is (6,0,0,1)
4452 SETDEC(l,4,0,0,5); SETDEC(r,3,0,0,2); MATH2(VarDecMul); EXPECTDEC(7,0,0,10);
4454 SETDEC64(l,0,0,0,0xFFFFFFFF,0xFFFFFFFF); SETDEC(r,0,0,0,2); MATH2(VarDecMul); EXPECTDEC64(0,0,1,0xFFFFFFFF,0xFFFFFFFE);
4455 SETDEC(l,0,0,0,2); SETDEC64(r,0,0,0,0xFFFFFFFF,0xFFFFFFFF); MATH2(VarDecMul); EXPECTDEC64(0,0,1,0xFFFFFFFF,0xFFFFFFFE);
4456 SETDEC(l,0,0,1,1); SETDEC(r,0,0,0,0x80000000); MATH2(VarDecMul); EXPECTDEC(0,0,0x80000000,0x80000000);
4457 SETDEC(l,0,0,0,0x80000000); SETDEC(r,0,0,1,1); MATH2(VarDecMul); EXPECTDEC(0,0,0x80000000,0x80000000);
4459 /* near-overflow, used as a reference */
4460 SETDEC64(l,0,0,0,0xFFFFFFFF,0xFFFFFFFF); SETDEC(r,0,0,0,2000000000); MATH2(VarDecMul);EXPECTDEC64(0,0,1999999999,0xFFFFFFFF,0x88CA6C00);
4461 /* actual overflow - right operand is 10 times the previous value */
4462 SETDEC64(l,0,0,0,0xFFFFFFFF,0xFFFFFFFF); SETDEC64(r,0,0,0,4,0xA817C800); MATH2(VarDecMul);
4463 ok(hres == DISP_E_OVERFLOW,"Expected overflow, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
4464 S(U(out)).scale, S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres);
4465 /* here, native oleaut32 has an opportunity to avert the overflow, by reducing the scale of the result */
4466 SETDEC64(l,1,0,0,0xFFFFFFFF,0xFFFFFFFF); SETDEC64(r,0,0,0,4,0xA817C800); MATH2(VarDecMul);EXPECTDEC64(0,0,1999999999,0xFFFFFFFF,0x88CA6C00);
4468 /* near-overflow, used as a reference */
4469 SETDEC64(l,0,0,1,0xFFFFFFFF,0xFFFFFFFE); SETDEC(r,0,0,0,1000000000); MATH2(VarDecMul);EXPECTDEC64(0,0,1999999999,0xFFFFFFFF,0x88CA6C00);
4470 /* actual overflow - right operand is 10 times the previous value */
4471 SETDEC64(l,0,0,1,0xFFFFFFFF,0xFFFFFFFE); SETDEC64(r,0,0,0,2,0x540BE400); MATH2(VarDecMul);
4472 ok(hres == DISP_E_OVERFLOW,"Expected overflow, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
4473 S(U(out)).scale, S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres);
4474 /* here, native oleaut32 has an opportunity to avert the overflow, by reducing the scale of the result */
4475 SETDEC64(l,1,0,1,0xFFFFFFFF,0xFFFFFFFE); SETDEC64(r,0,0,0,2,0x540BE400); MATH2(VarDecMul);EXPECTDEC64(0,0,1999999999,0xFFFFFFFF,0x88CA6C00);
4477 /* this one shows that native oleaut32 is willing to lose significant digits in order to avert an overflow */
4478 SETDEC64(l,2,0,0,0xFFFFFFFF,0xFFFFFFFF); SETDEC64(r,0,0,0,9,0x502F9001); MATH2(VarDecMul);EXPECTDEC64(1,0,0xee6b2800,0x19999998,0xab2e719a);
4481 static void test_VarDecDiv(void)
4483 MATHVARS2;
4485 CHECKPTR(VarDecDiv);
4486 /* identity divisions */
4487 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecDiv); EXPECTDEC(0,0,0,0);
4488 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecDiv); EXPECTDEC(0,0,0,1);
4489 SETDEC(l,1,0,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecDiv); EXPECTDEC(1,0,0,1);
4491 /* exact divisions */
4492 SETDEC(l,0,0,0,45); SETDEC(r,0,0,0,9); MATH2(VarDecDiv); EXPECTDEC(0,0,0,5);
4493 SETDEC(l,1,0,0,45); SETDEC(r,0,0,0,9); MATH2(VarDecDiv); EXPECTDEC(1,0,0,5);
4494 SETDEC(l,0,0,0,45); SETDEC(r,1,0,0,9); MATH2(VarDecDiv); EXPECTDEC(0,0,0,50);
4495 SETDEC(l,1,0,0,45); SETDEC(r,2,0,0,9); MATH2(VarDecDiv); EXPECTDEC(0,0,0,50);
4496 /* these last three results suggest that native oleaut32 scales both operands down to zero
4497 before the division, but does not always try to scale the result, even if it is possible -
4498 analogous to multiplication behavior.
4500 SETDEC(l,1,0,0,45); SETDEC(r,1,0,0,9); MATH2(VarDecDiv); EXPECTDEC(0,0,0,5);
4501 SETDEC(l,2,0,0,450); SETDEC(r,1,0,0,9); MATH2(VarDecDiv);
4502 if (S(U(out)).scale == 1) EXPECTDEC(1,0,0,50);
4503 else EXPECTDEC(0,0,0,5);
4505 /* inexact divisions */
4506 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,180700362,0x14b700cb,0x05555555);
4507 SETDEC(l,1,0,0,1); SETDEC(r,0,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,18070036,0x35458014,0x4d555555);
4508 SETDEC(l,0,0,0,1); SETDEC(r,1,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,1807003620,0xcf2607ee,0x35555555);
4509 SETDEC(l,1,0,0,1); SETDEC(r,2,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,1807003620,0xcf2607ee,0x35555555);
4510 SETDEC(l,1,0,0,1); SETDEC(r,1,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,180700362,0x14b700cb,0x05555555);
4511 SETDEC(l,2,0,0,10); SETDEC(r,1,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,180700362,0x14b700cb,0x05555555);
4513 /* this one shows that native oleaut32 rounds up the result */
4514 SETDEC(l,0,0,0,2); SETDEC(r,0,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,361400724,0x296e0196,0x0aaaaaab);
4516 /* sign tests */
4517 SETDEC(l,0,0x80,0,45); SETDEC(r,0,0,0,9); MATH2(VarDecDiv); EXPECTDEC(0,0x80,0,5);
4518 SETDEC(l,0,0,0,45); SETDEC(r,0,0x80,0,9); MATH2(VarDecDiv);EXPECTDEC(0,0x80,0,5);
4519 SETDEC(l,0,0x80,0,45); SETDEC(r,0,0x80,0,9); MATH2(VarDecDiv);EXPECTDEC(0,0,0,5);
4521 /* oddballs */
4522 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecDiv);/* indeterminate */
4523 ok(hres == DISP_E_DIVBYZERO,"Expected division-by-zero, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
4524 S(U(out)).scale, S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres);
4525 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,0); MATH2(VarDecDiv);/* division by zero */
4526 ok(hres == DISP_E_DIVBYZERO,"Expected division-by-zero, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
4527 S(U(out)).scale, S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres);
4531 static void test_VarDecCmp(void)
4533 MATHVARS1;
4535 CHECKPTR(VarDecCmp);
4537 SETDEC(l,0,0,0,1); SETDEC(out,0,0,0,1); MATH1(VarDecCmp); EXPECT_EQ;
4538 SETDEC(l,0,0,0,1); SETDEC(out,0,0,0,0); MATH1(VarDecCmp); EXPECT_GT;
4539 SETDEC(l,0,0,0,1); SETDEC(out,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_LT;
4541 SETDEC(l,0,0,0,1); SETDEC(out,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_GT;
4542 SETDEC(l,0,0,0,1); SETDEC(out,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_GT;
4543 SETDEC(l,0,0,0,1); SETDEC(out,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_GT;
4545 SETDEC(l,0,DECIMAL_NEG,0,1); SETDEC(out,0,0,0,1); MATH1(VarDecCmp); EXPECT_LT;
4546 SETDEC(l,0,DECIMAL_NEG,0,1); SETDEC(out,0,0,0,0); MATH1(VarDecCmp); EXPECT_LT;
4547 SETDEC(l,0,DECIMAL_NEG,0,1); SETDEC(out,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_LT;
4549 SETDEC(l,0,DECIMAL_NEG,0,1); SETDEC(out,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_EQ;
4550 SETDEC(l,0,DECIMAL_NEG,0,1); SETDEC(out,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_LT;
4551 SETDEC(l,0,DECIMAL_NEG,0,1); SETDEC(out,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_GT;
4553 SETDEC(l,0,0,0,0); SETDEC(out,0,0,0,1); MATH1(VarDecCmp); EXPECT_LT;
4554 SETDEC(l,0,0,0,0); SETDEC(out,0,0,0,0); MATH1(VarDecCmp); EXPECT_EQ;
4555 SETDEC(l,0,0,0,0); SETDEC(out,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_LT;
4557 SETDEC(l,0,0,0,0); SETDEC(out,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_GT;
4558 SETDEC(l,0,0,0,0); SETDEC(out,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_EQ;
4559 SETDEC(l,0,0,0,0); SETDEC(out,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_GT;
4561 SETDEC(l,0,DECIMAL_NEG,0,0); SETDEC(out,0,0,0,1); MATH1(VarDecCmp); EXPECT_LT;
4562 SETDEC(l,0,DECIMAL_NEG,0,0); SETDEC(out,0,0,0,0); MATH1(VarDecCmp); EXPECT_EQ;
4563 SETDEC(l,0,DECIMAL_NEG,0,0); SETDEC(out,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_LT;
4565 SETDEC(l,0,DECIMAL_NEG,0,0); SETDEC(out,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_GT;
4566 SETDEC(l,0,DECIMAL_NEG,0,0); SETDEC(out,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_EQ;
4567 SETDEC(l,0,DECIMAL_NEG,0,0); SETDEC(out,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_GT;
4569 SETDEC(l,0,0,-1,-1); SETDEC(out,0,0,0,1); MATH1(VarDecCmp); EXPECT_GT;
4570 SETDEC(l,0,0,-1,-1); SETDEC(out,0,0,0,0); MATH1(VarDecCmp); EXPECT_GT;
4571 SETDEC(l,0,0,-1,-1); SETDEC(out,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_EQ;
4573 SETDEC(l,0,0,-1,-1); SETDEC(out,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_GT;
4574 SETDEC(l,0,0,-1,-1); SETDEC(out,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_GT;
4575 SETDEC(l,0,0,-1,-1); SETDEC(out,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_GT;
4577 SETDEC(l,0,DECIMAL_NEG,-1,-1); SETDEC(out,0,0,0,1); MATH1(VarDecCmp); EXPECT_LT;
4578 SETDEC(l,0,DECIMAL_NEG,-1,-1); SETDEC(out,0,0,0,0); MATH1(VarDecCmp); EXPECT_LT;
4579 SETDEC(l,0,DECIMAL_NEG,-1,-1); SETDEC(out,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_LT;
4581 SETDEC(l,0,DECIMAL_NEG,-1,-1); SETDEC(out,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_LT;
4582 SETDEC(l,0,DECIMAL_NEG,-1,-1); SETDEC(out,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_LT;
4583 SETDEC(l,0,DECIMAL_NEG,-1,-1); SETDEC(out,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_EQ;
4586 SETDEC(out,0,0,0,1); SETDEC(l,0,0,0,1); MATH1(VarDecCmp); EXPECT_EQ;
4587 SETDEC(out,0,0,0,1); SETDEC(l,0,0,0,0); MATH1(VarDecCmp); EXPECT_LT;
4588 SETDEC(out,0,0,0,1); SETDEC(l,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_GT;
4590 SETDEC(out,0,0,0,1); SETDEC(l,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_LT;
4591 SETDEC(out,0,0,0,1); SETDEC(l,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_LT;
4592 SETDEC(out,0,0,0,1); SETDEC(l,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_LT;
4594 SETDEC(out,0,DECIMAL_NEG,0,1); SETDEC(l,0,0,0,1); MATH1(VarDecCmp); EXPECT_GT;
4595 SETDEC(out,0,DECIMAL_NEG,0,1); SETDEC(l,0,0,0,0); MATH1(VarDecCmp); EXPECT_GT;
4596 SETDEC(out,0,DECIMAL_NEG,0,1); SETDEC(l,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_GT;
4598 SETDEC(out,0,DECIMAL_NEG,0,1); SETDEC(l,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_EQ;
4599 SETDEC(out,0,DECIMAL_NEG,0,1); SETDEC(l,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_GT;
4600 SETDEC(out,0,DECIMAL_NEG,0,1); SETDEC(l,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_LT;
4602 SETDEC(out,0,0,0,0); SETDEC(l,0,0,0,1); MATH1(VarDecCmp); EXPECT_GT;
4603 SETDEC(out,0,0,0,0); SETDEC(l,0,0,0,0); MATH1(VarDecCmp); EXPECT_EQ;
4604 SETDEC(out,0,0,0,0); SETDEC(l,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_GT;
4606 SETDEC(out,0,0,0,0); SETDEC(l,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_LT;
4607 SETDEC(out,0,0,0,0); SETDEC(l,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_EQ;
4608 SETDEC(out,0,0,0,0); SETDEC(l,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_LT;
4610 SETDEC(out,0,DECIMAL_NEG,0,0); SETDEC(l,0,0,0,1); MATH1(VarDecCmp); EXPECT_GT;
4611 SETDEC(out,0,DECIMAL_NEG,0,0); SETDEC(l,0,0,0,0); MATH1(VarDecCmp); EXPECT_EQ;
4612 SETDEC(out,0,DECIMAL_NEG,0,0); SETDEC(l,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_GT;
4614 SETDEC(out,0,DECIMAL_NEG,0,0); SETDEC(l,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_LT;
4615 SETDEC(out,0,DECIMAL_NEG,0,0); SETDEC(l,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_EQ;
4616 SETDEC(out,0,DECIMAL_NEG,0,0); SETDEC(l,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_LT;
4618 SETDEC(out,0,0,-1,-1); SETDEC(l,0,0,0,1); MATH1(VarDecCmp); EXPECT_LT;
4619 SETDEC(out,0,0,-1,-1); SETDEC(l,0,0,0,0); MATH1(VarDecCmp); EXPECT_LT;
4620 SETDEC(out,0,0,-1,-1); SETDEC(l,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_EQ;
4622 SETDEC(out,0,0,-1,-1); SETDEC(l,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_LT;
4623 SETDEC(out,0,0,-1,-1); SETDEC(l,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_LT;
4624 SETDEC(out,0,0,-1,-1); SETDEC(l,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_LT;
4626 SETDEC(out,0,DECIMAL_NEG,-1,-1); SETDEC(l,0,0,0,1); MATH1(VarDecCmp); EXPECT_GT;
4627 SETDEC(out,0,DECIMAL_NEG,-1,-1); SETDEC(l,0,0,0,0); MATH1(VarDecCmp); EXPECT_GT;
4628 SETDEC(out,0,DECIMAL_NEG,-1,-1); SETDEC(l,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_GT;
4630 SETDEC(out,0,DECIMAL_NEG,-1,-1); SETDEC(l,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_GT;
4631 SETDEC(out,0,DECIMAL_NEG,-1,-1); SETDEC(l,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_GT;
4632 SETDEC(out,0,DECIMAL_NEG,-1,-1); SETDEC(l,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_EQ;
4634 SETDEC(l,3,0,0,123456); SETDEC64(out,0,0,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF);
4635 MATH1(VarDecCmp); todo_wine EXPECT_LT;
4638 static void test_VarDecCmpR8(void)
4640 HRESULT hres;
4641 DECIMAL l;
4642 double r;
4644 CHECKPTR(VarDecCmpR8);
4646 SETDEC(l,0,0,0,1); r = 0.0; MATH3(VarDecCmpR8); EXPECT_GT;
4647 SETDEC(l,0,0,0,1); r = 0.1; MATH3(VarDecCmpR8); EXPECT_GT;
4648 SETDEC(l,0,0,0,1); r = -0.1; MATH3(VarDecCmpR8); EXPECT_GT;
4650 SETDEC(l,0,DECIMAL_NEG,0,1); r = 0.0; MATH3(VarDecCmpR8); EXPECT_LT;
4651 SETDEC(l,0,DECIMAL_NEG,0,1); r = 0.1; MATH3(VarDecCmpR8); EXPECT_LT;
4652 SETDEC(l,0,DECIMAL_NEG,0,1); r = -0.1; MATH3(VarDecCmpR8); EXPECT_LT;
4654 SETDEC(l,0,0,0,0); r = 0.0; MATH3(VarDecCmpR8); EXPECT_EQ;
4655 SETDEC(l,0,0,0,0); r = 0.1; MATH3(VarDecCmpR8); EXPECT_LT;
4656 SETDEC(l,0,0,0,0); r = -0.1; MATH3(VarDecCmpR8); EXPECT_GT;
4658 SETDEC(l,0,DECIMAL_NEG,0,0); r = 0.0; MATH3(VarDecCmpR8); EXPECT_EQ;
4659 SETDEC(l,0,DECIMAL_NEG,0,0); r = 0.1; MATH3(VarDecCmpR8); EXPECT_LT;
4660 SETDEC(l,0,DECIMAL_NEG,0,0); r = -0.1; MATH3(VarDecCmpR8); EXPECT_GT;
4662 SETDEC(l,0,0,0,1); r = DECIMAL_NEG; MATH3(VarDecCmpR8); EXPECT_LT;
4663 SETDEC(l,0,DECIMAL_NEG,0,0); r = DECIMAL_NEG; MATH3(VarDecCmpR8); EXPECT_LT;
4664 SETDEC(l,0,0,-1,-1); r = DECIMAL_NEG; MATH3(VarDecCmpR8); EXPECT_GT;
4665 SETDEC(l,0,DECIMAL_NEG,-1,-1); r = DECIMAL_NEG; MATH3(VarDecCmpR8); EXPECT_LT;
4668 #define CLEAR(x) memset(&(x), 0xBB, sizeof(x))
4670 static void test_VarDecRound(void)
4672 HRESULT hres;
4673 DECIMAL l, out;
4675 CHECKPTR(VarDecRound);
4677 CLEAR(out); SETDEC(l, 0, 0, 0, 1); hres = pVarDecRound(&l, 3, &out); EXPECTDEC(0, 0, 0, 1);
4679 CLEAR(out); SETDEC(l, 0, 0, 0, 1); hres = pVarDecRound(&l, 0, &out); EXPECTDEC(0, 0, 0, 1);
4680 CLEAR(out); SETDEC(l, 1, 0, 0, 1); hres = pVarDecRound(&l, 0, &out); EXPECTDEC(0, 0, 0, 0);
4681 CLEAR(out); SETDEC(l, 1, 0, 0, 1); hres = pVarDecRound(&l, 1, &out); EXPECTDEC(1, 0, 0, 1);
4682 CLEAR(out); SETDEC(l, 2, 0, 0, 11); hres = pVarDecRound(&l, 1, &out); EXPECTDEC(1, 0, 0, 1);
4683 CLEAR(out); SETDEC(l, 2, 0, 0, 15); hres = pVarDecRound(&l, 1, &out); EXPECTDEC(1, 0, 0, 2);
4684 CLEAR(out); SETDEC(l, 6, 0, 0, 550001); hres = pVarDecRound(&l, 1, &out); EXPECTDEC(1, 0, 0, 6);
4686 CLEAR(out); SETDEC(l, 0, DECIMAL_NEG, 0, 1); hres = pVarDecRound(&l, 0, &out); EXPECTDEC(0, DECIMAL_NEG, 0, 1);
4687 CLEAR(out); SETDEC(l, 1, DECIMAL_NEG, 0, 1); hres = pVarDecRound(&l, 0, &out); EXPECTDEC(0, DECIMAL_NEG, 0, 0);
4688 CLEAR(out); SETDEC(l, 1, DECIMAL_NEG, 0, 1); hres = pVarDecRound(&l, 1, &out); EXPECTDEC(1, DECIMAL_NEG, 0, 1);
4689 CLEAR(out); SETDEC(l, 2, DECIMAL_NEG, 0, 11); hres = pVarDecRound(&l, 1, &out); EXPECTDEC(1, DECIMAL_NEG, 0, 1);
4690 CLEAR(out); SETDEC(l, 2, DECIMAL_NEG, 0, 15); hres = pVarDecRound(&l, 1, &out); EXPECTDEC(1, DECIMAL_NEG, 0, 2);
4691 CLEAR(out); SETDEC(l, 6, DECIMAL_NEG, 0, 550001); hres = pVarDecRound(&l, 1, &out); EXPECTDEC(1, DECIMAL_NEG, 0, 6);
4693 CLEAR(out); SETDEC64(l, 0, 0, 0xffffffff, 0xffffffff, 0xffffffff); hres = pVarDecRound(&l, 0, &out); EXPECTDEC64(0, 0, 0xffffffff, 0xffffffff, 0xffffffff);
4694 CLEAR(out); SETDEC64(l, 28, 0, 0xffffffff, 0xffffffff, 0xffffffff); hres = pVarDecRound(&l, 0, &out); EXPECTDEC64(0, 0, 0, 0, 8);
4695 CLEAR(out); SETDEC64(l, 0, DECIMAL_NEG, 0xffffffff, 0xffffffff, 0xffffffff); hres = pVarDecRound(&l, 0, &out); EXPECTDEC64(0, DECIMAL_NEG, 0xffffffff, 0xffffffff, 0xffffffff);
4696 CLEAR(out); SETDEC64(l, 28, DECIMAL_NEG, 0xffffffff, 0xffffffff, 0xffffffff); hres = pVarDecRound(&l, 0, &out); EXPECTDEC64(0, DECIMAL_NEG, 0, 0, 8);
4698 CLEAR(out); SETDEC(l, 2, 0, 0, 0); hres = pVarDecRound(&l, 1, &out); EXPECTDEC(1, 0, 0, 0);
4702 * VT_BOOL
4705 #undef CONV_TYPE
4706 #define CONV_TYPE VARIANT_BOOL
4707 #undef EXPECTRES
4708 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%d")
4709 #undef CONVERTRANGE
4710 #define CONVERTRANGE(func,start,end) for (i = start; i < end; i++) { \
4711 CONVERT(func, i); if (i) { EXPECT(VARIANT_TRUE); } else { EXPECT(VARIANT_FALSE); } }
4713 static void test_VarBoolFromI1(void)
4715 CONVVARS(signed char);
4716 int i;
4718 CHECKPTR(VarBoolFromI1);
4719 CONVERTRANGE(VarBoolFromI1, -128, 128);
4722 static void test_VarBoolFromUI1(void)
4724 CONVVARS(BYTE);
4725 int i;
4727 CHECKPTR(VarBoolFromUI1);
4728 CONVERTRANGE(VarBoolFromUI1, 0, 256);
4731 static void test_VarBoolFromI2(void)
4733 CONVVARS(SHORT);
4734 int i;
4736 CHECKPTR(VarBoolFromI2);
4737 CONVERTRANGE(VarBoolFromI2, -32768, 32768);
4740 static void test_VarBoolFromUI2(void)
4742 CONVVARS(USHORT);
4743 int i;
4745 CHECKPTR(VarBoolFromUI2);
4746 CONVERTRANGE(VarBoolFromUI2, 0, 65536);
4749 static void test_VarBoolFromI4(void)
4751 CONVVARS(int);
4753 CHECKPTR(VarBoolFromI4);
4754 CONVERT(VarBoolFromI4, 0x80000000); EXPECT(VARIANT_TRUE);
4755 CONVERT(VarBoolFromI4, -1); EXPECT(VARIANT_TRUE);
4756 CONVERT(VarBoolFromI4, 0); EXPECT(VARIANT_FALSE);
4757 CONVERT(VarBoolFromI4, 1); EXPECT(VARIANT_TRUE);
4758 CONVERT(VarBoolFromI4, 0x7fffffff); EXPECT(VARIANT_TRUE);
4761 static void test_VarBoolFromUI4(void)
4763 CONVVARS(ULONG);
4765 CHECKPTR(VarBoolFromUI4);
4766 CONVERT(VarBoolFromI4, 0); EXPECT(VARIANT_FALSE);
4767 CONVERT(VarBoolFromI4, 1); EXPECT(VARIANT_TRUE);
4768 CONVERT(VarBoolFromI4, 0x80000000); EXPECT(VARIANT_TRUE);
4771 static void test_VarBoolFromR4(void)
4773 CONVVARS(FLOAT);
4775 CHECKPTR(VarBoolFromR4);
4776 CONVERT(VarBoolFromR4, -1.0f); EXPECT(VARIANT_TRUE);
4777 CONVERT(VarBoolFromR4, 0.0f); EXPECT(VARIANT_FALSE);
4778 CONVERT(VarBoolFromR4, 1.0f); EXPECT(VARIANT_TRUE);
4779 CONVERT(VarBoolFromR4, 1.5f); EXPECT(VARIANT_TRUE);
4781 /* Rounding */
4782 CONVERT(VarBoolFromR4, -1.5f); EXPECT(VARIANT_TRUE);
4783 CONVERT(VarBoolFromR4, -0.6f); EXPECT(VARIANT_TRUE);
4784 CONVERT(VarBoolFromR4, -0.5f); EXPECT(VARIANT_TRUE);
4785 CONVERT(VarBoolFromR4, -0.4f); EXPECT(VARIANT_TRUE);
4786 CONVERT(VarBoolFromR4, 0.4f); EXPECT(VARIANT_TRUE);
4787 CONVERT(VarBoolFromR4, 0.5f); EXPECT(VARIANT_TRUE);
4788 CONVERT(VarBoolFromR4, 0.6f); EXPECT(VARIANT_TRUE);
4789 CONVERT(VarBoolFromR4, 1.5f); EXPECT(VARIANT_TRUE);
4792 static void test_VarBoolFromR8(void)
4794 CONVVARS(DOUBLE);
4796 /* Hopefully we made the point with R4 above that rounding is
4797 * irrelevant, so we'll skip that for R8 and Date
4799 CHECKPTR(VarBoolFromR8);
4800 CONVERT(VarBoolFromR8, -1.0); EXPECT(VARIANT_TRUE);
4801 CONVERT(VarBoolFromR8, -0.0); EXPECT(VARIANT_FALSE);
4802 CONVERT(VarBoolFromR8, 1.0); EXPECT(VARIANT_TRUE);
4805 static void test_VarBoolFromCy(void)
4807 CONVVARS(CY);
4809 CHECKPTR(VarBoolFromCy);
4810 CONVERT_CY(VarBoolFromCy, -32769); EXPECT(VARIANT_TRUE);
4811 CONVERT_CY(VarBoolFromCy, -32768); EXPECT(VARIANT_TRUE);
4812 CONVERT_CY(VarBoolFromCy, -1); EXPECT(VARIANT_TRUE);
4813 CONVERT_CY(VarBoolFromCy, 0); EXPECT(VARIANT_FALSE);
4814 CONVERT_CY(VarBoolFromCy, 1); EXPECT(VARIANT_TRUE);
4815 CONVERT_CY(VarBoolFromCy, 32767); EXPECT(VARIANT_TRUE);
4816 CONVERT_CY(VarBoolFromCy, 32768); EXPECT(VARIANT_TRUE);
4819 static void test_VarBoolFromI8(void)
4821 CONVVARS(LONG64);
4823 CHECKPTR(VarBoolFromI8);
4824 CONVERT(VarBoolFromI8, -1); EXPECT(VARIANT_TRUE);
4825 CONVERT(VarBoolFromI8, 0); EXPECT(VARIANT_FALSE);
4826 CONVERT(VarBoolFromI8, 1); EXPECT(VARIANT_TRUE);
4829 static void test_VarBoolFromUI8(void)
4831 CONVVARS(ULONG64);
4833 CHECKPTR(VarBoolFromUI8);
4834 CONVERT(VarBoolFromUI8, 0); EXPECT(VARIANT_FALSE);
4835 CONVERT(VarBoolFromUI8, 1); EXPECT(VARIANT_TRUE);
4838 static void test_VarBoolFromDec(void)
4840 CONVVARS(DECIMAL);
4842 CHECKPTR(VarBoolFromDec);
4843 CONVERT_BADDEC(VarBoolFromDec);
4845 CONVERT_DEC(VarBoolFromDec,29,0,0,0); EXPECT_INVALID;
4846 CONVERT_DEC(VarBoolFromDec,0,0x1,0,0); EXPECT_INVALID;
4847 CONVERT_DEC(VarBoolFromDec,0,0x40,0,0); EXPECT_INVALID;
4848 CONVERT_DEC(VarBoolFromDec,0,0x7f,0,0); EXPECT_INVALID;
4850 CONVERT_DEC(VarBoolFromDec,0,0x80,0,1); EXPECT(VARIANT_TRUE);
4851 CONVERT_DEC(VarBoolFromDec,0,0,0,0); EXPECT(VARIANT_FALSE);
4852 CONVERT_DEC(VarBoolFromDec,0,0,0,1); EXPECT(VARIANT_TRUE);
4853 CONVERT_DEC(VarBoolFromDec,0,0,1,0); EXPECT(VARIANT_TRUE);
4855 CONVERT_DEC(VarBoolFromDec,2,0,0,CY_MULTIPLIER); EXPECT(VARIANT_TRUE);
4856 CONVERT_DEC(VarBoolFromDec,2,0x80,0,CY_MULTIPLIER); EXPECT(VARIANT_TRUE);
4859 static void test_VarBoolFromDate(void)
4861 CONVVARS(DATE);
4863 CHECKPTR(VarBoolFromDate);
4864 CONVERT(VarBoolFromDate, -1.0); EXPECT(VARIANT_TRUE);
4865 CONVERT(VarBoolFromDate, -0.0); EXPECT(VARIANT_FALSE);
4866 CONVERT(VarBoolFromDate, 1.0); EXPECT(VARIANT_TRUE);
4869 static void test_VarBoolFromStr(void)
4871 CONVVARS(LCID);
4872 OLECHAR buff[128];
4874 CHECKPTR(VarBoolFromStr);
4876 in = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4878 CONVERT_STR(VarBoolFromStr,NULL,0);
4879 if (hres != E_INVALIDARG)
4880 EXPECT_MISMATCH;
4882 /* #FALSE# and #TRUE# Are always accepted */
4883 CONVERT_STR(VarBoolFromStr,"#FALSE#",0); EXPECT(VARIANT_FALSE);
4884 CONVERT_STR(VarBoolFromStr,"#TRUE#",0); EXPECT(VARIANT_TRUE);
4886 /* Match of #FALSE# and #TRUE# is case sensitive */
4887 CONVERT_STR(VarBoolFromStr,"#False#",0); EXPECT_MISMATCH;
4888 /* But match against English is not */
4889 CONVERT_STR(VarBoolFromStr,"false",0); EXPECT(VARIANT_FALSE);
4890 CONVERT_STR(VarBoolFromStr,"False",0); EXPECT(VARIANT_FALSE);
4891 /* On/Off and yes/no are not acceptable inputs, with any flags set */
4892 CONVERT_STR(VarBoolFromStr,"On",0xffffffff); EXPECT_MISMATCH;
4893 CONVERT_STR(VarBoolFromStr,"Yes",0xffffffff); EXPECT_MISMATCH;
4895 /* Change the LCID. This doesn't make any difference for text,unless we ask
4896 * to check local boolean text with the VARIANT_LOCALBOOL flag. */
4897 in = MAKELCID(MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT), SORT_DEFAULT);
4899 /* #FALSE# and #TRUE# are accepted in all locales */
4900 CONVERT_STR(VarBoolFromStr,"#FALSE#",0); EXPECT(VARIANT_FALSE);
4901 CONVERT_STR(VarBoolFromStr,"#TRUE#",0); EXPECT(VARIANT_TRUE);
4902 CONVERT_STR(VarBoolFromStr,"#FALSE#",VARIANT_LOCALBOOL); EXPECT(VARIANT_FALSE);
4903 CONVERT_STR(VarBoolFromStr,"#TRUE#",VARIANT_LOCALBOOL); EXPECT(VARIANT_TRUE);
4905 /* English is accepted regardless of the locale */
4906 CONVERT_STR(VarBoolFromStr,"false",0); EXPECT(VARIANT_FALSE);
4907 /* And is still not case sensitive */
4908 CONVERT_STR(VarBoolFromStr,"False",0); EXPECT(VARIANT_FALSE);
4910 if (has_locales)
4912 /* French is rejected without VARIANT_LOCALBOOL */
4913 CONVERT_STR(VarBoolFromStr,"faux",0); EXPECT_MISMATCH;
4914 /* But accepted if this flag is given */
4915 CONVERT_STR(VarBoolFromStr,"faux",VARIANT_LOCALBOOL); EXPECT(VARIANT_FALSE);
4916 /* Regardless of case - from this we assume locale text comparisons ignore case */
4917 CONVERT_STR(VarBoolFromStr,"Faux",VARIANT_LOCALBOOL); EXPECT(VARIANT_FALSE);
4919 /* Changing the locale prevents the localised text from being compared -
4920 * this demonstrates that only the indicated LCID and English are searched */
4921 in = MAKELCID(MAKELANGID(LANG_POLISH, SUBLANG_DEFAULT), SORT_DEFAULT);
4922 CONVERT_STR(VarBoolFromStr,"faux",VARIANT_LOCALBOOL); EXPECT_MISMATCH;
4925 /* Numeric strings are read as 0 or non-0 */
4926 CONVERT_STR(VarBoolFromStr,"0",0); EXPECT(VARIANT_FALSE);
4927 CONVERT_STR(VarBoolFromStr,"-1",0); EXPECT(VARIANT_TRUE);
4928 CONVERT_STR(VarBoolFromStr,"+1",0); EXPECT(VARIANT_TRUE);
4930 if (has_locales)
4932 /* Numeric strings are read as floating point numbers. The line below fails
4933 * because '.' is not a valid decimal separator for Polish numbers */
4934 CONVERT_STR(VarBoolFromStr,"0.1",LOCALE_NOUSEROVERRIDE); EXPECT_MISMATCH;
4937 /* Changing the lcid back to US English reads the r8 correctly */
4938 in = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4939 CONVERT_STR(VarBoolFromStr,"0.1",LOCALE_NOUSEROVERRIDE); EXPECT(VARIANT_TRUE);
4942 static void test_VarBoolCopy(void)
4944 COPYTEST(1, VT_BOOL, V_BOOL(&vSrc), V_BOOL(&vDst), V_BOOLREF(&vSrc), V_BOOLREF(&vDst), "%d");
4947 #define BOOL_STR(flags, str) hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, flags, VT_BSTR); \
4948 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && \
4949 V_BSTR(&vDst) && !memcmp(V_BSTR(&vDst), str, sizeof(str)), \
4950 "hres=0x%X, type=%d (should be VT_BSTR), *bstr='%c'\n", \
4951 hres, V_VT(&vDst), V_BSTR(&vDst) ? *V_BSTR(&vDst) : '?'); \
4952 VariantClear(&vDst)
4954 static void test_VarBoolChangeTypeEx(void)
4956 static const WCHAR szTrue[] = { 'T','r','u','e','\0' };
4957 static const WCHAR szFalse[] = { 'F','a','l','s','e','\0' };
4958 static const WCHAR szFaux[] = { 'F','a','u','x','\0' };
4959 HRESULT hres;
4960 VARIANT_BOOL in;
4961 VARIANTARG vSrc, vDst;
4962 LCID lcid;
4964 in = 1;
4966 INITIAL_TYPETEST(VT_BOOL, V_BOOL, "%d");
4967 COMMON_TYPETEST;
4969 /* The common tests convert to a number. Try the different flags */
4970 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4972 V_VT(&vSrc) = VT_BOOL;
4973 V_BOOL(&vSrc) = 1;
4975 BOOL_STR(VARIANT_ALPHABOOL, szTrue);
4976 V_BOOL(&vSrc) = 0;
4977 BOOL_STR(VARIANT_ALPHABOOL, szFalse);
4979 if (has_locales)
4981 lcid = MAKELCID(MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT), SORT_DEFAULT);
4983 /* VARIANT_ALPHABOOL is always English */
4984 BOOL_STR(VARIANT_ALPHABOOL, szFalse);
4985 /* VARIANT_LOCALBOOL uses the localised text */
4986 BOOL_STR(VARIANT_LOCALBOOL, szFaux);
4987 /* Both flags together acts as VARIANT_LOCALBOOL */
4988 BOOL_STR(VARIANT_ALPHABOOL|VARIANT_LOCALBOOL, szFaux);
4993 * BSTR
4996 static void test_VarBstrFromR4(void)
4998 static const WCHAR szNative[] = { '6','5','4','3','2','2','.','3','\0' };
4999 static const WCHAR szZero[] = {'0', '\0'};
5000 static const WCHAR szOneHalf_English[] = { '0','.','5','\0' }; /* uses period */
5001 static const WCHAR szOneHalf_Spanish[] = { '0',',','5','\0' }; /* uses comma */
5002 LCID lcid;
5003 LCID lcid_spanish;
5004 HRESULT hres;
5005 BSTR bstr = NULL;
5007 float f;
5009 CHECKPTR(VarBstrFromR4);
5011 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5012 lcid_spanish = MAKELCID(MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH), SORT_DEFAULT);
5013 f = 654322.23456f;
5014 hres = pVarBstrFromR4(f, lcid, 0, &bstr);
5015 ok(hres == S_OK, "got hres 0x%08x\n", hres);
5016 if (bstr)
5018 todo_wine {
5019 /* MSDN states that rounding of R4/R8 is dependent on the underlying
5020 * bit pattern of the number and so is architecture dependent. In this
5021 * case Wine returns .2 (which is more correct) and Native returns .3
5023 ok(memcmp(bstr, szNative, sizeof(szNative)) == 0, "string different\n");
5025 SysFreeString(bstr);
5028 f = -0.0;
5029 hres = pVarBstrFromR4(f, lcid, 0, &bstr);
5030 ok(hres == S_OK, "got hres 0x%08x\n", hres);
5031 if (bstr)
5033 if (bstr[0] == '-')
5034 ok(memcmp(bstr + 1, szZero, sizeof(szZero)) == 0, "negative zero (got %s)\n", wtoascii(bstr));
5035 else
5036 ok(memcmp(bstr, szZero, sizeof(szZero)) == 0, "negative zero (got %s)\n", wtoascii(bstr));
5037 SysFreeString(bstr);
5040 /* The following tests that lcid is used for decimal separator even without LOCALE_USE_NLS */
5041 f = 0.5;
5042 hres = pVarBstrFromR4(f, lcid, LOCALE_NOUSEROVERRIDE, &bstr);
5043 ok(hres == S_OK, "got hres 0x%08x\n", hres);
5044 if (bstr)
5046 ok(memcmp(bstr, szOneHalf_English, sizeof(szOneHalf_English)) == 0, "English locale failed (got %s)\n", wtoascii(bstr));
5047 SysFreeString(bstr);
5049 f = 0.5;
5050 hres = pVarBstrFromR4(f, lcid_spanish, LOCALE_NOUSEROVERRIDE, &bstr);
5051 ok(hres == S_OK, "got hres 0x%08x\n", hres);
5052 if (bstr)
5054 ok(memcmp(bstr, szOneHalf_Spanish, sizeof(szOneHalf_Spanish)) == 0, "Spanish locale failed (got %s)\n", wtoascii(bstr));
5055 SysFreeString(bstr);
5059 static void _BSTR_DATE(DATE dt, const char *str, int line)
5061 LCID lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
5062 char buff[256];
5063 BSTR bstr = NULL;
5064 HRESULT hres;
5066 hres = pVarBstrFromDate(dt, lcid, LOCALE_NOUSEROVERRIDE, &bstr);
5067 if (bstr)
5069 WideCharToMultiByte(CP_ACP, 0, bstr, -1, buff, sizeof(buff), 0, 0);
5070 SysFreeString(bstr);
5072 else
5073 buff[0] = 0;
5074 ok_(__FILE__, line)(hres == S_OK && !strcmp(str, buff),
5075 "Expected '%s', got '%s', hres = 0x%08x\n", str, buff, hres);
5078 static void test_VarBstrFromDate(void)
5080 #define BSTR_DATE(dt,str) _BSTR_DATE(dt,str,__LINE__)
5082 CHECKPTR(VarBstrFromDate);
5084 BSTR_DATE(0.0, "12:00:00 AM");
5085 BSTR_DATE(3.34, "1/2/1900 8:09:36 AM");
5086 BSTR_DATE(3339.34, "2/20/1909 8:09:36 AM");
5087 BSTR_DATE(365.00, "12/30/1900");
5088 BSTR_DATE(365.25, "12/30/1900 6:00:00 AM");
5089 BSTR_DATE(1461.0, "12/31/1903");
5090 BSTR_DATE(1461.5, "12/31/1903 12:00:00 PM");
5091 BSTR_DATE(-49192.24, "4/24/1765 5:45:36 AM");
5092 BSTR_DATE(-657434.0, "1/1/100");
5093 BSTR_DATE(2958465.0, "12/31/9999");
5095 #undef BSTR_DATE
5098 static void _BSTR_CY(LONG a, LONG b, const char *str, LCID lcid, int line)
5100 HRESULT hr;
5101 BSTR bstr = NULL;
5102 char buff[256];
5103 CY l;
5105 S(l).Lo = b;
5106 S(l).Hi = a;
5107 hr = pVarBstrFromCy(l, lcid, LOCALE_NOUSEROVERRIDE, &bstr);
5108 ok(hr == S_OK, "got hr 0x%08x\n", hr);
5110 if(bstr)
5112 WideCharToMultiByte(CP_ACP, 0, bstr, -1, buff, sizeof(buff), 0, 0);
5113 SysFreeString(bstr);
5115 else
5116 buff[0] = 0;
5118 if(hr == S_OK)
5120 ok_(__FILE__, line)(!strcmp(str, buff), "Expected '%s', got '%s'\n", str, buff);
5124 static void test_VarBstrFromCy(void)
5126 #define BSTR_CY(a, b, str, lcid) _BSTR_CY(a, b, str, lcid, __LINE__)
5128 LCID en_us, sp;
5130 CHECKPTR(VarBstrFromCy);
5132 en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
5133 sp = MAKELCID(MAKELANGID(LANG_SPANISH, SUBLANG_DEFAULT), SORT_DEFAULT);
5135 BSTR_CY(0, 0, "0", en_us);
5136 BSTR_CY(0, 10000, "1", en_us);
5137 BSTR_CY(0, 15000, "1.5", en_us);
5138 BSTR_CY(0xffffffff, ((15000)^0xffffffff)+1, "-1.5", en_us);
5139 /* (1 << 32) - 1 / 1000 */
5140 BSTR_CY(0, 0xffffffff, "429496.7295", en_us);
5141 /* (1 << 32) / 1000 */
5142 BSTR_CY(1, 0, "429496.7296", en_us);
5143 /* ((1 << 63) - 1)/10000 */
5144 BSTR_CY(0x7fffffff, 0xffffffff, "922337203685477.5807", en_us);
5145 BSTR_CY(0, 9, "0.0009", en_us);
5146 BSTR_CY(0, 9, "0,0009", sp);
5148 #undef BSTR_CY
5151 static void _BSTR_DEC(BYTE scale, BYTE sign, ULONG hi, ULONG mid, ULONGLONG lo, const char *str,
5152 LCID lcid, int line)
5154 char buff[256];
5155 HRESULT hr;
5156 BSTR bstr = NULL;
5157 DECIMAL dec;
5159 SETDEC64(dec, scale, sign, hi, mid, lo);
5160 hr = pVarBstrFromDec(&dec, lcid, LOCALE_NOUSEROVERRIDE, &bstr);
5161 ok_(__FILE__, line)(hr == S_OK, "got hr 0x%08x\n", hr);
5163 if(bstr)
5165 WideCharToMultiByte(CP_ACP, 0, bstr, -1, buff, sizeof(buff), 0, 0);
5166 SysFreeString(bstr);
5168 else
5169 buff[0] = 0;
5171 if(hr == S_OK)
5173 ok_(__FILE__, line)(!strcmp(str, buff), "Expected '%s', got '%s'\n", str, buff);
5177 static void test_VarBstrFromDec(void)
5179 #define BSTR_DEC(scale, sign, hi, lo, str, lcid) _BSTR_DEC(scale, sign, hi, 0, lo, str, lcid, __LINE__)
5180 #define BSTR_DEC64(scale, sign, hi, mid, lo, str, lcid) _BSTR_DEC(scale, sign, hi, mid, lo, str, lcid, __LINE__)
5182 LCID en_us, sp;
5184 CHECKPTR(VarBstrFromDec);
5186 en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
5187 sp = MAKELCID(MAKELANGID(LANG_SPANISH, SUBLANG_DEFAULT), SORT_DEFAULT);
5189 BSTR_DEC(0,0,0,0, "0", en_us);
5191 BSTR_DEC(0,0,0,1, "1", en_us);
5192 BSTR_DEC(1,0,0,10, "1", en_us);
5193 BSTR_DEC(2,0,0,100, "1", en_us);
5194 BSTR_DEC(3,0,0,1000,"1", en_us);
5196 BSTR_DEC(1,0,0,15, "1.5", en_us);
5197 BSTR_DEC(2,0,0,150, "1.5", en_us);
5198 BSTR_DEC(3,0,0,1500,"1.5", en_us);
5200 BSTR_DEC(1,0x80,0,15, "-1.5", en_us);
5202 /* (1 << 32) - 1 */
5203 BSTR_DEC(0,0,0,0xffffffff, "4294967295", en_us);
5204 /* (1 << 32) */
5205 BSTR_DEC64(0,0,0,1,0, "4294967296", en_us);
5206 /* (1 << 64) - 1 */
5207 BSTR_DEC64(0,0,0,0xffffffff,0xffffffff, "18446744073709551615", en_us);
5208 /* (1 << 64) */
5209 BSTR_DEC(0,0,1,0, "18446744073709551616", en_us);
5210 /* (1 << 96) - 1 */
5211 BSTR_DEC64(0,0,0xffffffff,0xffffffff,0xffffffff, "79228162514264337593543950335", en_us);
5212 /* 1 * 10^-10 */
5213 BSTR_DEC(10,0,0,1, "0.0000000001", en_us);
5214 /* ((1 << 96) - 1) * 10^-10 */
5215 BSTR_DEC64(10,0,0xffffffffUL,0xffffffff,0xffffffff, "7922816251426433759.3543950335", en_us);
5216 /* ((1 << 96) - 1) * 10^-28 */
5217 BSTR_DEC64(28,0,0xffffffffUL,0xffffffff,0xffffffff, "7.9228162514264337593543950335", en_us);
5219 /* check leading zeros and decimal sep. for English locale */
5220 BSTR_DEC(4,0,0,9, "0.0009", en_us);
5221 BSTR_DEC(5,0,0,90, "0.0009", en_us);
5222 BSTR_DEC(6,0,0,900, "0.0009", en_us);
5223 BSTR_DEC(7,0,0,9000, "0.0009", en_us);
5225 /* check leading zeros and decimal sep. for Spanish locale */
5226 BSTR_DEC(4,0,0,9, "0,0009", sp);
5227 BSTR_DEC(5,0,0,90, "0,0009", sp);
5228 BSTR_DEC(6,0,0,900, "0,0009", sp);
5229 BSTR_DEC(7,0,0,9000, "0,0009", sp);
5231 #undef BSTR_DEC
5232 #undef BSTR_DEC64
5235 #define _VARBSTRCMP(left,right,lcid,flags,result) \
5236 hres = pVarBstrCmp(left,right,lcid,flags); \
5237 ok(hres == result, "VarBstrCmp: expected " #result ", got hres=0x%x\n", hres)
5238 #define VARBSTRCMP(left,right,flags,result) \
5239 _VARBSTRCMP(left,right,lcid,flags,result)
5241 static void test_VarBstrCmp(void)
5243 LCID lcid;
5244 HRESULT hres;
5245 static const WCHAR sz[] = {'W','u','r','s','c','h','t','\0'};
5246 static const WCHAR szempty[] = {'\0'};
5247 static const WCHAR sz1[] = { 'a',0 };
5248 static const WCHAR sz2[] = { 'A',0 };
5249 static const WCHAR s1[] = { 'a',0 };
5250 static const WCHAR s2[] = { 'a',0,'b' };
5251 static const char sb1[] = {1,0,1};
5252 static const char sb2[] = {1,0,2};
5253 static const char sbchr0[] = {0,0};
5254 static const char sbchr00[] = {0,0,0};
5255 BSTR bstr, bstrempty, bstr2;
5257 CHECKPTR(VarBstrCmp);
5259 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
5260 bstr = SysAllocString(sz);
5261 bstrempty = SysAllocString(szempty);
5263 /* NULL handling. Yepp, MSDN is totally wrong here */
5264 VARBSTRCMP(NULL,NULL,0,VARCMP_EQ);
5265 VARBSTRCMP(bstr,NULL,0,VARCMP_GT);
5266 VARBSTRCMP(NULL,bstr,0,VARCMP_LT);
5268 /* NULL and empty string comparisons */
5269 VARBSTRCMP(bstrempty,NULL,0,VARCMP_EQ);
5270 VARBSTRCMP(NULL,bstrempty,0,VARCMP_EQ);
5272 SysFreeString(bstr);
5273 bstr = SysAllocString(sz1);
5275 bstr2 = SysAllocString(sz2);
5276 VARBSTRCMP(bstr,bstr2,0,VARCMP_LT);
5277 VARBSTRCMP(bstr,bstr2,NORM_IGNORECASE,VARCMP_EQ);
5278 SysFreeString(bstr2);
5279 /* These two strings are considered equal even though one is
5280 * NULL-terminated and the other not.
5282 bstr2 = SysAllocStringLen(s1, sizeof(s1) / sizeof(WCHAR));
5283 VARBSTRCMP(bstr,bstr2,0,VARCMP_EQ);
5284 SysFreeString(bstr2);
5286 /* These two strings are not equal */
5287 bstr2 = SysAllocStringLen(s2, sizeof(s2) / sizeof(WCHAR));
5288 VARBSTRCMP(bstr,bstr2,0,VARCMP_LT);
5289 SysFreeString(bstr2);
5291 SysFreeString(bstr);
5293 bstr = SysAllocStringByteLen(sbchr0, sizeof(sbchr0));
5294 bstr2 = SysAllocStringByteLen(sbchr00, sizeof(sbchr00));
5295 VARBSTRCMP(bstr,bstrempty,0,VARCMP_GT);
5296 VARBSTRCMP(bstrempty,bstr,0,VARCMP_LT);
5297 VARBSTRCMP(bstr2,bstrempty,0,VARCMP_GT);
5298 VARBSTRCMP(bstr2,bstr,0,VARCMP_EQ);
5299 SysFreeString(bstr2);
5300 SysFreeString(bstr);
5302 /* When (LCID == 0) it should be a binary comparison
5303 * so these two strings could not match.
5305 bstr = SysAllocStringByteLen(sb1, sizeof(sb1));
5306 bstr2 = SysAllocStringByteLen(sb2, sizeof(sb2));
5307 lcid = 0;
5308 VARBSTRCMP(bstr,bstr2,0,VARCMP_LT);
5309 SysFreeString(bstr2);
5310 SysFreeString(bstr);
5312 bstr = SysAllocStringByteLen(sbchr0, sizeof(sbchr0));
5313 bstr2 = SysAllocStringByteLen(sbchr00, sizeof(sbchr00));
5314 VARBSTRCMP(bstr,bstrempty,0,VARCMP_GT);
5315 VARBSTRCMP(bstrempty,bstr,0,VARCMP_LT);
5316 VARBSTRCMP(bstr2,bstrempty,0,VARCMP_GT);
5317 VARBSTRCMP(bstr2,bstr,0,VARCMP_GT);
5318 SysFreeString(bstr2);
5319 SysFreeString(bstr);
5320 SysFreeString(bstrempty);
5323 /* Get the internal representation of a BSTR */
5324 static inline LPINTERNAL_BSTR Get(const BSTR lpszString)
5326 return lpszString ? (LPINTERNAL_BSTR)((char*)lpszString - sizeof(DWORD)) : NULL;
5329 static inline BSTR GetBSTR(const LPINTERNAL_BSTR bstr)
5331 return (BSTR)bstr->szString;
5334 static void test_SysStringLen(void)
5336 INTERNAL_BSTR bstr;
5337 BSTR str = GetBSTR(&bstr);
5339 bstr.dwLen = 0;
5340 ok (SysStringLen(str) == 0, "Expected dwLen 0, got %d\n", SysStringLen(str));
5341 bstr.dwLen = 2;
5342 ok (SysStringLen(str) == 1, "Expected dwLen 1, got %d\n", SysStringLen(str));
5345 static void test_SysStringByteLen(void)
5347 INTERNAL_BSTR bstr;
5348 BSTR str = GetBSTR(&bstr);
5350 bstr.dwLen = 0;
5351 ok (SysStringByteLen(str) == 0, "Expected dwLen 0, got %d\n", SysStringByteLen(str));
5352 bstr.dwLen = 2;
5353 ok (SysStringByteLen(str) == 2, "Expected dwLen 2, got %d\n", SysStringByteLen(str));
5356 static void test_SysAllocString(void)
5358 const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
5359 BSTR str;
5361 str = SysAllocString(NULL);
5362 ok (str == NULL, "Expected NULL, got %p\n", str);
5364 str = SysAllocString(szTest);
5365 ok (str != NULL, "Expected non-NULL\n");
5366 if (str)
5368 LPINTERNAL_BSTR bstr = Get(str);
5370 ok (bstr->dwLen == 8, "Expected 8, got %d\n", bstr->dwLen);
5371 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
5372 SysFreeString(str);
5376 static void test_SysAllocStringLen(void)
5378 const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
5379 BSTR str;
5381 /* Very early native dlls do not limit the size of strings, so skip this test */
5382 if (0)
5384 str = SysAllocStringLen(szTest, 0x80000000);
5385 ok (str == NULL, "Expected NULL, got %p\n", str);
5388 str = SysAllocStringLen(NULL, 0);
5389 ok (str != NULL, "Expected non-NULL\n");
5390 if (str)
5392 LPINTERNAL_BSTR bstr = Get(str);
5394 ok (bstr->dwLen == 0, "Expected 0, got %d\n", bstr->dwLen);
5395 ok (!bstr->szString[0], "String not empty\n");
5396 SysFreeString(str);
5399 str = SysAllocStringLen(szTest, 4);
5400 ok (str != NULL, "Expected non-NULL\n");
5401 if (str)
5403 LPINTERNAL_BSTR bstr = Get(str);
5405 ok (bstr->dwLen == 8, "Expected 8, got %d\n", bstr->dwLen);
5406 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
5407 SysFreeString(str);
5411 static void test_SysAllocStringByteLen(void)
5413 const OLECHAR szTest[10] = { 'T','e','s','t','\0' };
5414 const CHAR szTestA[6] = { 'T','e','s','t','\0','?' };
5415 BSTR str;
5417 if (sizeof(void *) == 4) /* not limited to 0x80000000 on Win64 */
5419 str = SysAllocStringByteLen(szTestA, 0x80000000);
5420 ok (str == NULL, "Expected NULL, got %p\n", str);
5423 str = SysAllocStringByteLen(szTestA, 0xffffffff);
5424 ok (str == NULL, "Expected NULL, got %p\n", str);
5426 str = SysAllocStringByteLen(NULL, 0);
5427 ok (str != NULL, "Expected non-NULL\n");
5428 if (str)
5430 LPINTERNAL_BSTR bstr = Get(str);
5432 ok (bstr->dwLen == 0, "Expected 0, got %d\n", bstr->dwLen);
5433 ok (!bstr->szString[0], "String not empty\n");
5434 SysFreeString(str);
5437 str = SysAllocStringByteLen(szTestA, 4);
5438 ok (str != NULL, "Expected non-NULL\n");
5439 if (str)
5441 LPINTERNAL_BSTR bstr = Get(str);
5443 ok (bstr->dwLen == 4, "Expected 4, got %d\n", bstr->dwLen);
5444 ok (!lstrcmpA((LPCSTR)bstr->szString, szTestA), "String different\n");
5445 SysFreeString(str);
5448 /* Odd lengths are allocated rounded up, but truncated at the right position */
5449 str = SysAllocStringByteLen(szTestA, 3);
5450 ok (str != NULL, "Expected non-NULL\n");
5451 if (str)
5453 const CHAR szTestTruncA[4] = { 'T','e','s','\0' };
5454 LPINTERNAL_BSTR bstr = Get(str);
5456 ok (bstr->dwLen == 3, "Expected 3, got %d\n", bstr->dwLen);
5457 ok (!lstrcmpA((LPCSTR)bstr->szString, szTestTruncA), "String different\n");
5458 SysFreeString(str);
5461 str = SysAllocStringByteLen((LPCSTR)szTest, 8);
5462 ok (str != NULL, "Expected non-NULL\n");
5463 if (str)
5465 LPINTERNAL_BSTR bstr = Get(str);
5467 ok (bstr->dwLen == 8, "Expected 8, got %d\n", bstr->dwLen);
5468 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
5469 SysFreeString(str);
5473 static void test_SysReAllocString(void)
5475 const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
5476 const OLECHAR szSmaller[2] = { 'x','\0' };
5477 const OLECHAR szLarger[7] = { 'L','a','r','g','e','r','\0' };
5478 BSTR str;
5480 str = SysAllocStringLen(szTest, 4);
5481 ok (str != NULL, "Expected non-NULL\n");
5482 if (str)
5484 LPINTERNAL_BSTR bstr;
5485 int changed;
5487 bstr = Get(str);
5488 ok (bstr->dwLen == 8, "Expected 8, got %d\n", bstr->dwLen);
5489 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
5491 changed = SysReAllocString(&str, szSmaller);
5492 ok (changed == 1, "Expected 1, got %d\n", changed);
5493 /* Vista creates a new string, but older versions reuse the existing string. */
5494 /*ok (str == oldstr, "Created new string\n");*/
5495 bstr = Get(str);
5496 ok (bstr->dwLen == 2, "Expected 2, got %d\n", bstr->dwLen);
5497 ok (!lstrcmpW(bstr->szString, szSmaller), "String different\n");
5499 changed = SysReAllocString(&str, szLarger);
5500 ok (changed == 1, "Expected 1, got %d\n", changed);
5501 /* Early versions always make new strings rather than resizing */
5502 /* ok (str == oldstr, "Created new string\n"); */
5503 bstr = Get(str);
5504 ok (bstr->dwLen == 12, "Expected 12, got %d\n", bstr->dwLen);
5505 ok (!lstrcmpW(bstr->szString, szLarger), "String different\n");
5507 SysFreeString(str);
5511 static void test_SysReAllocStringLen(void)
5513 const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
5514 const OLECHAR szSmaller[2] = { 'x','\0' };
5515 const OLECHAR szLarger[7] = { 'L','a','r','g','e','r','\0' };
5516 BSTR str;
5518 str = SysAllocStringLen(szTest, 4);
5519 ok (str != NULL, "Expected non-NULL\n");
5520 if (str)
5522 LPINTERNAL_BSTR bstr;
5523 int changed;
5525 bstr = Get(str);
5526 ok (bstr->dwLen == 8, "Expected 8, got %d\n", bstr->dwLen);
5527 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
5529 changed = SysReAllocStringLen(&str, szSmaller, 1);
5530 ok (changed == 1, "Expected 1, got %d\n", changed);
5531 /* Vista creates a new string, but older versions reuse the existing string. */
5532 /*ok (str == oldstr, "Created new string\n");*/
5533 bstr = Get(str);
5534 ok (bstr->dwLen == 2, "Expected 2, got %d\n", bstr->dwLen);
5535 ok (!lstrcmpW(bstr->szString, szSmaller), "String different\n");
5537 changed = SysReAllocStringLen(&str, szLarger, 6);
5538 ok (changed == 1, "Expected 1, got %d\n", changed);
5539 /* Early versions always make new strings rather than resizing */
5540 /* ok (str == oldstr, "Created new string\n"); */
5541 bstr = Get(str);
5542 ok (bstr->dwLen == 12, "Expected 12, got %d\n", bstr->dwLen);
5543 ok (!lstrcmpW(bstr->szString, szLarger), "String different\n");
5545 changed = SysReAllocStringLen(&str, str, 6);
5546 ok (changed == 1, "Expected 1, got %d\n", changed);
5548 SysFreeString(str);
5551 /* Windows always returns null terminated strings */
5552 str = SysAllocStringLen(szTest, 4);
5553 ok (str != NULL, "Expected non-NULL\n");
5554 if (str)
5556 const int CHUNK_SIZE = 64;
5557 const int STRING_SIZE = 24;
5558 int changed;
5559 changed = SysReAllocStringLen(&str, NULL, CHUNK_SIZE);
5560 ok (changed == 1, "Expected 1, got %d\n", changed);
5561 ok (str != NULL, "Expected non-NULL\n");
5562 if (str)
5564 BSTR oldstr = str;
5566 /* Filling string */
5567 memset (str, 0xAB, CHUNK_SIZE * sizeof (OLECHAR));
5568 /* Checking null terminator */
5569 changed = SysReAllocStringLen(&str, NULL, STRING_SIZE);
5570 ok (changed == 1, "Expected 1, got %d\n", changed);
5571 ok (str != NULL, "Expected non-NULL\n");
5572 if (str)
5574 ok (str == oldstr, "Expected reuse of the old string memory\n");
5575 ok (str[STRING_SIZE] == 0,
5576 "Expected null terminator, got 0x%04X\n", str[STRING_SIZE]);
5577 SysFreeString(str);
5582 /* Some Windows applications use the same pointer for pbstr and psz */
5583 str = SysAllocStringLen(szTest, 4);
5584 ok(str != NULL, "Expected non-NULL\n");
5585 if(str)
5587 SysReAllocStringLen(&str, str, 1000000);
5588 ok(SysStringLen(str)==1000000, "Incorrect string length\n");
5589 ok(!memcmp(szTest, str, 4*sizeof(WCHAR)), "Incorrect string returned\n");
5591 SysFreeString(str);
5595 static void test_BstrCopy(void)
5597 const CHAR szTestA[6] = { 'T','e','s','t','\0','?' };
5598 const CHAR szTestTruncA[4] = { 'T','e','s','\0' };
5599 LPINTERNAL_BSTR bstr;
5600 BSTR str;
5601 HRESULT hres;
5602 VARIANT vt1, vt2;
5604 str = SysAllocStringByteLen(szTestA, 3);
5605 ok (str != NULL, "Expected non-NULL\n");
5606 if (str)
5608 V_VT(&vt1) = VT_BSTR;
5609 V_BSTR(&vt1) = str;
5610 V_VT(&vt2) = VT_EMPTY;
5611 hres = VariantCopy(&vt2, &vt1);
5612 ok (hres == S_OK,"Failed to copy binary bstring with hres 0x%08x\n", hres);
5613 bstr = Get(V_BSTR(&vt2));
5614 ok (bstr->dwLen == 3, "Expected 3, got %d\n", bstr->dwLen);
5615 ok (!lstrcmpA((LPCSTR)bstr->szString, szTestTruncA), "String different\n");
5616 VariantClear(&vt2);
5617 VariantClear(&vt1);
5621 static void test_VarBstrCat(void)
5623 static const WCHAR sz1[] = { 'a',0 };
5624 static const WCHAR sz2[] = { 'b',0 };
5625 static const WCHAR sz1sz2[] = { 'a','b',0 };
5626 static const WCHAR s1[] = { 'a',0 };
5627 static const WCHAR s2[] = { 'b',0 };
5628 static const WCHAR s1s2[] = { 'a',0,'b',0 };
5629 static const char str1A[] = "Have ";
5630 static const char str2A[] = "A Cigar";
5631 HRESULT ret;
5632 BSTR str1, str2, res;
5633 UINT len;
5635 CHECKPTR(VarBstrCat);
5637 if (0)
5639 /* Crash */
5640 pVarBstrCat(NULL, NULL, NULL);
5643 /* Concatenation of two NULL strings works */
5644 ret = pVarBstrCat(NULL, NULL, &res);
5645 ok(ret == S_OK, "VarBstrCat failed: %08x\n", ret);
5646 ok(res != NULL, "Expected a string\n");
5647 ok(SysStringLen(res) == 0, "Expected a 0-length string\n");
5648 SysFreeString(res);
5650 str1 = SysAllocString(sz1);
5652 /* Concatenation with one NULL arg */
5653 ret = pVarBstrCat(NULL, str1, &res);
5654 ok(ret == S_OK, "VarBstrCat failed: %08x\n", ret);
5655 ok(res != NULL, "Expected a string\n");
5656 ok(SysStringLen(res) == SysStringLen(str1), "Unexpected length\n");
5657 ok(!memcmp(res, sz1, SysStringLen(str1)), "Unexpected value\n");
5658 SysFreeString(res);
5659 ret = pVarBstrCat(str1, NULL, &res);
5660 ok(ret == S_OK, "VarBstrCat failed: %08x\n", ret);
5661 ok(res != NULL, "Expected a string\n");
5662 ok(SysStringLen(res) == SysStringLen(str1), "Unexpected length\n");
5663 ok(!memcmp(res, sz1, SysStringLen(str1)), "Unexpected value\n");
5664 SysFreeString(res);
5666 /* Concatenation of two zero-terminated strings */
5667 str2 = SysAllocString(sz2);
5668 ret = pVarBstrCat(str1, str2, &res);
5669 ok(ret == S_OK, "VarBstrCat failed: %08x\n", ret);
5670 ok(res != NULL, "Expected a string\n");
5671 ok(SysStringLen(res) == sizeof(sz1sz2) / sizeof(WCHAR) - 1,
5672 "Unexpected length\n");
5673 ok(!memcmp(res, sz1sz2, sizeof(sz1sz2)), "Unexpected value\n");
5674 SysFreeString(res);
5676 SysFreeString(str2);
5677 SysFreeString(str1);
5679 /* Concatenation of two strings with embedded NULLs */
5680 str1 = SysAllocStringLen(s1, sizeof(s1) / sizeof(WCHAR));
5681 str2 = SysAllocStringLen(s2, sizeof(s2) / sizeof(WCHAR));
5683 ret = pVarBstrCat(str1, str2, &res);
5684 ok(ret == S_OK, "VarBstrCat failed: %08x\n", ret);
5685 ok(res != NULL, "Expected a string\n");
5686 ok(SysStringLen(res) == sizeof(s1s2) / sizeof(WCHAR),
5687 "Unexpected length\n");
5688 ok(!memcmp(res, s1s2, sizeof(s1s2)), "Unexpected value\n");
5689 SysFreeString(res);
5691 SysFreeString(str2);
5692 SysFreeString(str1);
5694 /* Concatenation of ansi BSTRs, both odd byte count not including termination */
5695 str1 = SysAllocStringByteLen(str1A, sizeof(str1A)-1);
5696 str2 = SysAllocStringByteLen(str2A, sizeof(str2A)-1);
5697 len = SysStringLen(str1);
5698 ok(len == (sizeof(str1A)-1)/sizeof(WCHAR), "got length %u\n", len);
5699 len = SysStringLen(str2);
5700 ok(len == (sizeof(str2A)-1)/sizeof(WCHAR), "got length %u\n", len);
5702 ret = pVarBstrCat(str1, str2, &res);
5703 ok(ret == S_OK, "VarBstrCat failed: %08x\n", ret);
5704 ok(res != NULL, "Expected a string\n");
5705 len = (sizeof(str1A) + sizeof(str2A) - 2)/sizeof(WCHAR);
5706 ok(SysStringLen(res) == len, "got %d, expected %u\n", SysStringLen(res), len);
5707 ok(!memcmp(res, "Have A Cigar", sizeof(str1A) + sizeof(str2A) - 1), "got (%s)\n", (char*)res);
5708 SysFreeString(res);
5710 SysFreeString(str2);
5711 SysFreeString(str1);
5713 /* Concatenation of ansi BSTRs, both 1 byte length not including termination */
5714 str1 = SysAllocStringByteLen(str1A, 1);
5715 str2 = SysAllocStringByteLen(str2A, 1);
5716 len = SysStringLen(str1);
5717 ok(len == 0, "got length %u\n", len);
5718 len = SysStringLen(str2);
5719 ok(len == 0, "got length %u\n", len);
5721 ret = pVarBstrCat(str1, str2, &res);
5722 ok(ret == S_OK, "VarBstrCat failed: %08x\n", ret);
5723 ok(res != NULL, "Expected a string\n");
5724 ok(SysStringLen(res) == 1, "got %d, expected 1\n", SysStringLen(res));
5725 ok(!memcmp(res, "HA", 2), "got (%s)\n", (char*)res);
5726 SysFreeString(res);
5728 SysFreeString(str2);
5729 SysFreeString(str1);
5732 /* IUnknown */
5734 static void test_IUnknownClear(void)
5736 HRESULT hres;
5737 VARIANTARG v;
5738 DummyDispatch u;
5739 IUnknown* pu;
5741 init_test_dispatch(1, VT_UI1, &u);
5742 pu = (IUnknown*)&u.IDispatch_iface;
5744 /* Test that IUnknown_Release is called on by-value */
5745 V_VT(&v) = VT_UNKNOWN;
5746 V_UNKNOWN(&v) = (IUnknown*)&u.IDispatch_iface;
5747 hres = VariantClear(&v);
5748 ok(hres == S_OK && u.ref == 0 && V_VT(&v) == VT_EMPTY,
5749 "clear unknown: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5750 S_OK, 0, VT_EMPTY, hres, u.ref, V_VT(&v));
5752 /* But not when clearing a by-reference*/
5753 u.ref = 1;
5754 V_VT(&v) = VT_UNKNOWN|VT_BYREF;
5755 V_UNKNOWNREF(&v) = &pu;
5756 hres = VariantClear(&v);
5757 ok(hres == S_OK && u.ref == 1 && V_VT(&v) == VT_EMPTY,
5758 "clear dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5759 S_OK, 1, VT_EMPTY, hres, u.ref, V_VT(&v));
5762 static void test_IUnknownCopy(void)
5764 HRESULT hres;
5765 VARIANTARG vSrc, vDst;
5766 DummyDispatch u;
5767 IUnknown* pu;
5769 init_test_dispatch(1, VT_UI1, &u);
5770 pu = (IUnknown*)&u.IDispatch_iface;
5772 /* AddRef is called on by-value copy */
5773 VariantInit(&vDst);
5774 V_VT(&vSrc) = VT_UNKNOWN;
5775 V_UNKNOWN(&vSrc) = pu;
5776 hres = VariantCopy(&vDst, &vSrc);
5777 ok(hres == S_OK && u.ref == 2 && V_VT(&vDst) == VT_UNKNOWN,
5778 "copy unknown: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5779 S_OK, 2, VT_EMPTY, hres, u.ref, V_VT(&vDst));
5781 /* AddRef is skipped on copy of by-reference IDispatch */
5782 VariantInit(&vDst);
5783 u.ref = 1;
5784 V_VT(&vSrc) = VT_UNKNOWN|VT_BYREF;
5785 V_UNKNOWNREF(&vSrc) = &pu;
5786 hres = VariantCopy(&vDst, &vSrc);
5787 ok(hres == S_OK && u.ref == 1 && V_VT(&vDst) == (VT_UNKNOWN|VT_BYREF),
5788 "copy unknown: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5789 S_OK, 1, VT_DISPATCH, hres, u.ref, V_VT(&vDst));
5791 /* AddRef is called copying by-reference IDispatch with indirection */
5792 VariantInit(&vDst);
5793 u.ref = 1;
5794 V_VT(&vSrc) = VT_UNKNOWN|VT_BYREF;
5795 V_UNKNOWNREF(&vSrc) = &pu;
5796 hres = VariantCopyInd(&vDst, &vSrc);
5797 ok(hres == S_OK && u.ref == 2 && V_VT(&vDst) == VT_UNKNOWN,
5798 "copy unknown: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5799 S_OK, 2, VT_DISPATCH, hres, u.ref, V_VT(&vDst));
5801 /* Indirection in place also calls AddRef */
5802 u.ref = 1;
5803 V_VT(&vSrc) = VT_UNKNOWN|VT_BYREF;
5804 V_UNKNOWNREF(&vSrc) = &pu;
5805 hres = VariantCopyInd(&vSrc, &vSrc);
5806 ok(hres == S_OK && u.ref == 2 && V_VT(&vSrc) == VT_UNKNOWN,
5807 "copy unknown: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5808 S_OK, 2, VT_DISPATCH, hres, u.ref, V_VT(&vSrc));
5811 static void test_IUnknownChangeTypeEx(void)
5813 HRESULT hres;
5814 VARIANTARG vSrc, vDst;
5815 LCID lcid;
5816 VARTYPE vt;
5817 DummyDispatch u;
5818 IUnknown* pu;
5820 init_test_dispatch(1, VT_UI1, &u);
5821 pu = (IUnknown*)&u.IDispatch_iface;
5823 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5825 V_VT(&vSrc) = VT_UNKNOWN;
5826 V_UNKNOWN(&vSrc) = pu;
5828 /* =>IDispatch in place */
5829 hres = VariantChangeTypeEx(&vSrc, &vSrc, lcid, 0, VT_DISPATCH);
5830 ok(hres == S_OK && u.ref == 1 &&
5831 V_VT(&vSrc) == VT_DISPATCH && V_DISPATCH(&vSrc) == (IDispatch*)pu,
5832 "change unk(src=src): expected 0x%08x,%d,%d,%p, got 0x%08x,%d,%d,%p\n",
5833 S_OK, 1, VT_DISPATCH, pu, hres, u.ref, V_VT(&vSrc), V_DISPATCH(&vSrc));
5835 /* =>IDispatch */
5836 u.ref = 1;
5837 V_VT(&vSrc) = VT_UNKNOWN;
5838 V_UNKNOWN(&vSrc) = pu;
5839 VariantInit(&vDst);
5840 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, VT_UNKNOWN);
5841 /* Note vSrc is not cleared, as final refcount is 2 */
5842 ok(hres == S_OK && u.ref == 2 &&
5843 V_VT(&vDst) == VT_UNKNOWN && V_UNKNOWN(&vDst) == pu,
5844 "change unk(src,dst): expected 0x%08x,%d,%d,%p, got 0x%08x,%d,%d,%p\n",
5845 S_OK, 2, VT_UNKNOWN, pu, hres, u.ref, V_VT(&vDst), V_UNKNOWN(&vDst));
5847 /* Can't change unknown to anything else */
5848 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
5850 HRESULT hExpected = DISP_E_BADVARTYPE;
5852 V_VT(&vSrc) = VT_UNKNOWN;
5853 V_UNKNOWN(&vSrc) = pu;
5854 VariantInit(&vDst);
5856 if (vt == VT_UNKNOWN || vt == VT_DISPATCH || vt == VT_EMPTY || vt == VT_NULL)
5857 hExpected = S_OK;
5858 else
5860 if (vt == VT_I8 || vt == VT_UI8)
5862 if (has_i8)
5863 hExpected = DISP_E_TYPEMISMATCH;
5865 else if (vt == VT_RECORD)
5867 hExpected = DISP_E_TYPEMISMATCH;
5869 else if (vt >= VT_I2 && vt <= VT_UINT && vt != (VARTYPE)15)
5870 hExpected = DISP_E_TYPEMISMATCH;
5873 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, vt);
5874 ok(hres == hExpected,
5875 "change unk(badvar): vt %d expected 0x%08x, got 0x%08x\n",
5876 vt, hExpected, hres);
5880 /* IDispatch */
5881 static void test_IDispatchClear(void)
5883 HRESULT hres;
5884 VARIANTARG v;
5885 DummyDispatch d;
5886 IDispatch* pd;
5888 init_test_dispatch(1, VT_UI1, &d);
5889 pd = &d.IDispatch_iface;
5891 /* As per IUnknown */
5893 V_VT(&v) = VT_DISPATCH;
5894 V_DISPATCH(&v) = pd;
5895 hres = VariantClear(&v);
5896 ok(hres == S_OK && d.ref == 0 && V_VT(&v) == VT_EMPTY,
5897 "clear dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5898 S_OK, 0, VT_EMPTY, hres, d.ref, V_VT(&v));
5900 d.ref = 1;
5901 V_VT(&v) = VT_DISPATCH|VT_BYREF;
5902 V_DISPATCHREF(&v) = &pd;
5903 hres = VariantClear(&v);
5904 ok(hres == S_OK && d.ref == 1 && V_VT(&v) == VT_EMPTY,
5905 "clear dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5906 S_OK, 1, VT_EMPTY, hres, d.ref, V_VT(&v));
5909 static void test_IDispatchCopy(void)
5911 HRESULT hres;
5912 VARIANTARG vSrc, vDst;
5913 DummyDispatch d;
5914 IDispatch* pd;
5916 init_test_dispatch(1, VT_UI1, &d);
5917 pd = &d.IDispatch_iface;
5919 /* As per IUnknown */
5921 VariantInit(&vDst);
5922 V_VT(&vSrc) = VT_DISPATCH;
5923 V_DISPATCH(&vSrc) = pd;
5924 hres = VariantCopy(&vDst, &vSrc);
5925 ok(hres == S_OK && d.ref == 2 && V_VT(&vDst) == VT_DISPATCH,
5926 "copy dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5927 S_OK, 2, VT_EMPTY, hres, d.ref, V_VT(&vDst));
5929 VariantInit(&vDst);
5930 d.ref = 1;
5931 V_VT(&vSrc) = VT_DISPATCH|VT_BYREF;
5932 V_DISPATCHREF(&vSrc) = &pd;
5933 hres = VariantCopy(&vDst, &vSrc);
5934 ok(hres == S_OK && d.ref == 1 && V_VT(&vDst) == (VT_DISPATCH|VT_BYREF),
5935 "copy dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5936 S_OK, 1, VT_DISPATCH, hres, d.ref, V_VT(&vDst));
5938 VariantInit(&vDst);
5939 d.ref = 1;
5940 V_VT(&vSrc) = VT_DISPATCH|VT_BYREF;
5941 V_DISPATCHREF(&vSrc) = &pd;
5942 hres = VariantCopyInd(&vDst, &vSrc);
5943 ok(hres == S_OK && d.ref == 2 && V_VT(&vDst) == VT_DISPATCH,
5944 "copy dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5945 S_OK, 2, VT_DISPATCH, hres, d.ref, V_VT(&vDst));
5947 d.ref = 1;
5948 V_VT(&vSrc) = VT_DISPATCH|VT_BYREF;
5949 V_DISPATCHREF(&vSrc) = &pd;
5950 hres = VariantCopyInd(&vSrc, &vSrc);
5951 ok(hres == S_OK && d.ref == 2 && V_VT(&vSrc) == VT_DISPATCH,
5952 "copy dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5953 S_OK, 2, VT_DISPATCH, hres, d.ref, V_VT(&vSrc));
5956 static void test_IDispatchChangeTypeEx(void)
5958 HRESULT hres;
5959 VARIANTARG vSrc, vDst;
5960 LCID lcid;
5961 DummyDispatch d;
5962 IDispatch* pd;
5964 init_test_dispatch(1, VT_UI1, &d);
5965 pd = &d.IDispatch_iface;
5967 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5969 V_VT(&vSrc) = VT_DISPATCH;
5970 V_DISPATCH(&vSrc) = pd;
5972 /* =>IUnknown in place */
5973 hres = VariantChangeTypeEx(&vSrc, &vSrc, lcid, 0, VT_UNKNOWN);
5974 ok(hres == S_OK && d.ref == 1 &&
5975 V_VT(&vSrc) == VT_UNKNOWN && V_UNKNOWN(&vSrc) == (IUnknown*)pd,
5976 "change disp(src=src): expected 0x%08x,%d,%d,%p, got 0x%08x,%d,%d,%p\n",
5977 S_OK, 1, VT_UNKNOWN, pd, hres, d.ref, V_VT(&vSrc), V_UNKNOWN(&vSrc));
5979 /* =>IUnknown */
5980 d.ref = 1;
5981 V_VT(&vSrc) = VT_DISPATCH;
5982 V_DISPATCH(&vSrc) = pd;
5983 VariantInit(&vDst);
5984 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, VT_UNKNOWN);
5985 /* Note vSrc is not cleared, as final refcount is 2 */
5986 ok(hres == S_OK && d.ref == 2 &&
5987 V_VT(&vDst) == VT_UNKNOWN && V_UNKNOWN(&vDst) == (IUnknown*)pd,
5988 "change disp(src,dst): expected 0x%08x,%d,%d,%p, got 0x%08x,%d,%d,%p\n",
5989 S_OK, 2, VT_UNKNOWN, pd, hres, d.ref, V_VT(&vDst), V_UNKNOWN(&vDst));
5991 /* FIXME: Verify that VARIANT_NOVALUEPROP prevents conversion to integral
5992 * types. this requires that the xxxFromDisp tests work first.
5996 /* VT_ERROR */
5997 static void test_ErrorChangeTypeEx(void)
5999 HRESULT hres;
6000 VARIANTARG vSrc, vDst;
6001 VARTYPE vt;
6002 LCID lcid;
6004 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
6006 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
6008 HRESULT hExpected = DISP_E_BADVARTYPE;
6010 V_VT(&vSrc) = VT_ERROR;
6011 V_ERROR(&vSrc) = 1;
6012 VariantInit(&vDst);
6013 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, vt);
6015 if (vt == VT_ERROR)
6016 hExpected = S_OK;
6017 else
6019 if (vt == VT_I8 || vt == VT_UI8)
6021 if (has_i8)
6022 hExpected = DISP_E_TYPEMISMATCH;
6024 else if (vt == VT_RECORD)
6026 hExpected = DISP_E_TYPEMISMATCH;
6028 else if (vt <= VT_UINT && vt != (VARTYPE)15)
6029 hExpected = DISP_E_TYPEMISMATCH;
6032 ok(hres == hExpected,
6033 "change err: vt %d expected 0x%08x, got 0x%08x\n", vt, hExpected, hres);
6037 /* VT_EMPTY */
6038 static void test_EmptyChangeTypeEx(void)
6040 VARTYPE vt;
6041 LCID lcid;
6043 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
6045 for (vt = VT_EMPTY; vt <= VT_BSTR_BLOB; vt++)
6047 HRESULT hExpected, hres;
6048 VARIANTARG vSrc, vDst;
6050 /* skip for undefined types */
6051 if ((vt == 15) || (vt > VT_VERSIONED_STREAM && vt < VT_BSTR_BLOB))
6052 continue;
6054 switch (vt)
6056 case VT_I8:
6057 case VT_UI8:
6058 if (has_i8)
6059 hExpected = S_OK;
6060 else
6061 hExpected = DISP_E_BADVARTYPE;
6062 break;
6063 case VT_RECORD:
6064 case VT_VARIANT:
6065 case VT_DISPATCH:
6066 case VT_UNKNOWN:
6067 case VT_ERROR:
6068 hExpected = DISP_E_TYPEMISMATCH;
6069 break;
6070 case VT_EMPTY:
6071 case VT_NULL:
6072 case VT_I2:
6073 case VT_I4:
6074 case VT_R4:
6075 case VT_R8:
6076 case VT_CY:
6077 case VT_DATE:
6078 case VT_BSTR:
6079 case VT_BOOL:
6080 case VT_DECIMAL:
6081 case VT_I1:
6082 case VT_UI1:
6083 case VT_UI2:
6084 case VT_UI4:
6085 case VT_INT:
6086 case VT_UINT:
6087 hExpected = S_OK;
6088 break;
6089 default:
6090 hExpected = DISP_E_BADVARTYPE;
6093 VariantInit(&vSrc);
6094 V_VT(&vSrc) = VT_EMPTY;
6095 memset(&vDst, 0, sizeof(vDst));
6096 V_VT(&vDst) = VT_NULL;
6098 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, vt);
6099 ok(hres == hExpected, "change empty: vt %d expected 0x%08x, got 0x%08x, vt %d\n",
6100 vt, hExpected, hres, V_VT(&vDst));
6101 if (hres == S_OK)
6103 ok(V_VT(&vDst) == vt, "change empty: vt %d, got %d\n", vt, V_VT(&vDst));
6104 VariantClear(&vDst);
6109 /* VT_NULL */
6110 static void test_NullChangeTypeEx(void)
6112 VARTYPE vt;
6113 LCID lcid;
6115 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
6117 for (vt = VT_EMPTY; vt <= VT_BSTR_BLOB; vt++)
6119 VARIANTARG vSrc, vDst;
6120 HRESULT hExpected, hres;
6122 /* skip for undefined types */
6123 if ((vt == 15) || (vt > VT_VERSIONED_STREAM && vt < VT_BSTR_BLOB))
6124 continue;
6126 switch (vt)
6128 case VT_I8:
6129 case VT_UI8:
6130 if (has_i8)
6131 hExpected = DISP_E_TYPEMISMATCH;
6132 else
6133 hExpected = DISP_E_BADVARTYPE;
6134 break;
6135 case VT_NULL:
6136 hExpected = S_OK;
6137 break;
6138 case VT_EMPTY:
6139 case VT_I2:
6140 case VT_I4:
6141 case VT_R4:
6142 case VT_R8:
6143 case VT_CY:
6144 case VT_DATE:
6145 case VT_BSTR:
6146 case VT_DISPATCH:
6147 case VT_ERROR:
6148 case VT_BOOL:
6149 case VT_VARIANT:
6150 case VT_UNKNOWN:
6151 case VT_DECIMAL:
6152 case VT_I1:
6153 case VT_UI1:
6154 case VT_UI2:
6155 case VT_UI4:
6156 case VT_INT:
6157 case VT_UINT:
6158 case VT_RECORD:
6159 hExpected = DISP_E_TYPEMISMATCH;
6160 break;
6161 default:
6162 hExpected = DISP_E_BADVARTYPE;
6165 VariantInit(&vSrc);
6166 V_VT(&vSrc) = VT_NULL;
6167 memset(&vDst, 0, sizeof(vDst));
6168 V_VT(&vDst) = VT_EMPTY;
6170 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, vt);
6171 ok(hres == hExpected, "change null: vt %d expected 0x%08x, got 0x%08x, vt %d\n",
6172 vt, hExpected, hres, V_VT(&vDst));
6174 /* should work only for VT_NULL -> VT_NULL case */
6175 if (hres == S_OK)
6176 ok(V_VT(&vDst) == VT_NULL, "change null: VT_NULL expected 0x%08x, got 0x%08x, vt %d\n",
6177 hExpected, hres, V_VT(&vDst));
6178 else
6179 ok(V_VT(&vDst) == VT_EMPTY, "change null: vt %d expected 0x%08x, got 0x%08x, vt %d\n",
6180 vt, hExpected, hres, V_VT(&vDst));
6185 /* VT_UINT */
6186 static void test_UintChangeTypeEx(void)
6188 HRESULT hres;
6189 VARIANTARG vSrc, vDst;
6190 LCID lcid;
6192 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
6194 /* Converting a VT_UINT to a VT_INT does not check for overflow */
6195 V_VT(&vDst) = VT_EMPTY;
6196 V_VT(&vSrc) = VT_UINT;
6197 V_UI4(&vSrc) = -1;
6198 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, VT_I4);
6199 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == -1,
6200 "change uint: Expected %d,0x%08x,%d got %d,0x%08x,%d\n",
6201 VT_I4, S_OK, -1, V_VT(&vDst), hres, V_I4(&vDst));
6204 #define NUM_CUST_ITEMS 16
6206 static void test_ClearCustData(void)
6208 CUSTDATA ci;
6209 unsigned i;
6211 CHECKPTR(ClearCustData);
6213 ci.cCustData = NUM_CUST_ITEMS;
6214 ci.prgCustData = CoTaskMemAlloc( sizeof(CUSTDATAITEM) * NUM_CUST_ITEMS );
6215 for (i = 0; i < NUM_CUST_ITEMS; i++)
6216 VariantInit(&ci.prgCustData[i].varValue);
6217 pClearCustData(&ci);
6218 ok(!ci.cCustData && !ci.prgCustData, "ClearCustData didn't clear fields!\n");
6221 static void test_NullByRef(void)
6223 VARIANT v1, v2;
6224 HRESULT hRes;
6226 VariantInit(&v1);
6227 VariantInit(&v2);
6228 V_VT(&v1) = VT_BYREF|VT_VARIANT;
6229 V_BYREF(&v1) = 0;
6231 hRes = VariantChangeTypeEx(&v2, &v1, 0, 0, VT_I4);
6232 ok(hRes == DISP_E_TYPEMISMATCH, "VariantChangeTypeEx should return DISP_E_TYPEMISMATCH\n");
6234 VariantClear(&v1);
6235 V_VT(&v1) = VT_BYREF|VT_VARIANT;
6236 V_BYREF(&v1) = 0;
6237 V_VT(&v2) = VT_I4;
6238 V_I4(&v2) = 123;
6240 hRes = VariantChangeTypeEx(&v2, &v1, 0, 0, VT_VARIANT);
6241 ok(hRes == DISP_E_TYPEMISMATCH, "VariantChangeTypeEx should return DISP_E_TYPEMISMATCH\n");
6242 ok(V_VT(&v2) == VT_I4 && V_I4(&v2) == 123, "VariantChangeTypeEx shouldn't change pvargDest\n");
6244 hRes = VariantChangeTypeEx(&v2, &v1, 0, 0, VT_BYREF|VT_I4);
6245 ok(hRes == DISP_E_TYPEMISMATCH, "VariantChangeTypeEx should return DISP_E_TYPEMISMATCH\n");
6247 hRes = VariantChangeTypeEx(&v2, &v1, 0, 0, 0x3847);
6248 ok(hRes == DISP_E_BADVARTYPE, "VariantChangeTypeEx should return DISP_E_BADVARTYPE\n");
6251 /* Dst Variant should remain unchanged if VariantChangeType cannot convert */
6252 static void test_ChangeType_keep_dst(void)
6254 VARIANT v1, v2;
6255 BSTR bstr;
6256 static const WCHAR testW[] = {'t','e','s','t',0};
6257 HRESULT hres;
6259 bstr = SysAllocString(testW);
6260 VariantInit(&v1);
6261 VariantInit(&v2);
6262 V_VT(&v1) = VT_BSTR;
6263 V_BSTR(&v1) = bstr;
6264 hres = VariantChangeTypeEx(&v1, &v1, 0, 0, VT_INT);
6265 ok(hres == DISP_E_TYPEMISMATCH, "VariantChangeTypeEx returns %08x\n", hres);
6266 ok(V_VT(&v1) == VT_BSTR && V_BSTR(&v1) == bstr, "VariantChangeTypeEx changed dst variant\n");
6267 V_VT(&v2) = VT_INT;
6268 V_INT(&v2) = 4;
6269 hres = VariantChangeTypeEx(&v2, &v1, 0, 0, VT_INT);
6270 ok(hres == DISP_E_TYPEMISMATCH, "VariantChangeTypeEx returns %08x\n", hres);
6271 ok(V_VT(&v2) == VT_INT && V_INT(&v2) == 4, "VariantChangeTypeEx changed dst variant\n");
6272 SysFreeString(bstr);
6275 /* This tests assumes an empty cache, so it needs to be ran early in the test. */
6276 static void test_bstr_cache(void)
6278 BSTR str, str2, strs[20];
6279 unsigned i;
6281 static const WCHAR testW[] = {'t','e','s','t',0};
6283 str = SysAllocString(testW);
6284 /* This should put the string into cache */
6285 SysFreeString(str);
6286 /* The string is in cache, this won't touch it */
6287 SysFreeString(str);
6289 ok(SysStringLen(str) == 4, "unexpected len\n");
6290 ok(!lstrcmpW(str, testW), "string changed\n");
6292 str2 = SysAllocString(testW);
6293 ok(str == str2, "str != str2\n");
6294 SysFreeString(str2);
6296 /* Fill the bucket with cached entries. */
6297 for(i=0; i < sizeof(strs)/sizeof(*strs); i++)
6298 strs[i] = SysAllocStringLen(NULL, 24);
6299 for(i=0; i < sizeof(strs)/sizeof(*strs); i++)
6300 SysFreeString(strs[i]);
6302 /* Following allocation will be made from cache */
6303 str = SysAllocStringLen(NULL, 24);
6304 ok(str == strs[0], "str != strs[0]\n");
6306 /* Smaller buffers may also use larget cached buffers */
6307 str2 = SysAllocStringLen(NULL, 16);
6308 ok(str2 == strs[1], "str2 != strs[1]\n");
6310 SysFreeString(str);
6311 SysFreeString(str2);
6312 SysFreeString(str);
6313 SysFreeString(str2);
6316 static void write_typelib(int res_no, const char *filename)
6318 DWORD written;
6319 HANDLE file;
6320 HRSRC res;
6321 void *ptr;
6323 file = CreateFileA( filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 );
6324 ok( file != INVALID_HANDLE_VALUE, "file creation failed\n" );
6325 if (file == INVALID_HANDLE_VALUE) return;
6326 res = FindResourceA( GetModuleHandleA(NULL), (LPCSTR)MAKEINTRESOURCE(res_no), "TYPELIB" );
6327 ok( res != 0, "couldn't find resource\n" );
6328 ptr = LockResource( LoadResource( GetModuleHandleA(NULL), res ));
6329 WriteFile( file, ptr, SizeofResource( GetModuleHandleA(NULL), res ), &written, NULL );
6330 ok( written == SizeofResource( GetModuleHandleA(NULL), res ), "couldn't write resource\n" );
6331 CloseHandle( file );
6334 static const char *create_test_typelib(int res_no)
6336 static char filename[MAX_PATH];
6338 GetTempFileNameA( ".", "tlb", 0, filename );
6339 write_typelib(res_no, filename);
6340 return filename;
6343 static void test_recinfo(void)
6345 static const WCHAR testW[] = {'t','e','s','t',0};
6346 static WCHAR teststructW[] = {'t','e','s','t','_','s','t','r','u','c','t',0};
6347 struct test_struct teststruct, testcopy;
6348 WCHAR filenameW[MAX_PATH];
6349 const char *filename;
6350 IRecordInfo *recinfo;
6351 ITypeInfo *typeinfo;
6352 DummyDispatch dispatch;
6353 ITypeLib *typelib;
6354 TYPEATTR *attr;
6355 MEMBERID memid;
6356 UINT16 found;
6357 HRESULT hr;
6358 ULONG size;
6360 filename = create_test_typelib(2);
6361 MultiByteToWideChar(CP_ACP, 0, filename, -1, filenameW, MAX_PATH);
6362 hr = LoadTypeLibEx(filenameW, REGKIND_NONE, &typelib);
6363 ok(hr == S_OK, "got 0x%08x\n", hr);
6365 typeinfo = NULL;
6366 found = 1;
6367 hr = ITypeLib_FindName(typelib, teststructW, 0, &typeinfo, &memid, &found);
6368 ok(hr == S_OK, "got 0x%08x\n", hr);
6369 ok(typeinfo != NULL, "got %p\n", typeinfo);
6370 hr = ITypeInfo_GetTypeAttr(typeinfo, &attr);
6371 ok(hr == S_OK, "got 0x%08x\n", hr);
6372 ok(IsEqualGUID(&attr->guid, &UUID_test_struct), "got %s\n", wine_dbgstr_guid(&attr->guid));
6373 ok(attr->typekind == TKIND_RECORD, "got %d\n", attr->typekind);
6375 hr = GetRecordInfoFromTypeInfo(typeinfo, &recinfo);
6376 ok(hr == S_OK, "got 0x%08x\n", hr);
6378 size = 0;
6379 hr = IRecordInfo_GetSize(recinfo, &size);
6380 ok(hr == S_OK, "got 0x%08x\n", hr);
6381 ok(size == sizeof(struct test_struct), "got size %d\n", size);
6382 ok(attr->cbSizeInstance == sizeof(struct test_struct), "got instance size %d\n", attr->cbSizeInstance);
6383 ITypeInfo_ReleaseTypeAttr(typeinfo, attr);
6385 /* RecordInit() */
6386 teststruct.hr = E_FAIL;
6387 teststruct.b = 0x1;
6388 teststruct.disp = (void*)0xdeadbeef;
6389 teststruct.bstr = (void*)0xdeadbeef;
6391 hr = IRecordInfo_RecordInit(recinfo, &teststruct);
6392 ok(hr == S_OK, "got 0x%08x\n", hr);
6393 ok(teststruct.hr == 0, "got 0x%08x\n", teststruct.hr);
6394 ok(teststruct.b == 0, "got 0x%08x\n", teststruct.b);
6395 ok(teststruct.disp == NULL, "got %p\n", teststruct.disp);
6396 ok(teststruct.bstr == NULL, "got %p\n", teststruct.bstr);
6398 init_test_dispatch(10, VT_UI1, &dispatch);
6400 /* RecordCopy(), interface field reference increased */
6401 teststruct.hr = S_FALSE;
6402 teststruct.b = VARIANT_TRUE;
6403 teststruct.disp = &dispatch.IDispatch_iface;
6404 teststruct.bstr = SysAllocString(testW);
6405 memset(&testcopy, 0, sizeof(testcopy));
6406 hr = IRecordInfo_RecordCopy(recinfo, &teststruct, &testcopy);
6407 ok(hr == S_OK, "got 0x%08x\n", hr);
6408 ok(testcopy.hr == S_FALSE, "got 0x%08x\n", testcopy.hr);
6409 ok(testcopy.b == VARIANT_TRUE, "got %d\n", testcopy.b);
6410 ok(testcopy.disp == teststruct.disp, "got %p\n", testcopy.disp);
6411 ok(dispatch.ref == 11, "got %d\n", dispatch.ref);
6412 ok(testcopy.bstr != teststruct.bstr, "got %p\n", testcopy.bstr);
6413 ok(!lstrcmpW(testcopy.bstr, teststruct.bstr), "got %s, %s\n", wine_dbgstr_w(testcopy.bstr), wine_dbgstr_w(teststruct.bstr));
6415 /* RecordClear() */
6416 hr = IRecordInfo_RecordClear(recinfo, &teststruct);
6417 ok(hr == S_OK, "got 0x%08x\n", hr);
6418 ok(teststruct.bstr == NULL, "got %p\n", teststruct.bstr);
6419 hr = IRecordInfo_RecordClear(recinfo, &testcopy);
6420 ok(hr == S_OK, "got 0x%08x\n", hr);
6421 ok(testcopy.bstr == NULL, "got %p\n", testcopy.bstr);
6423 /* now destination contains inteface pointer */
6424 memset(&testcopy, 0, sizeof(testcopy));
6425 testcopy.disp = &dispatch.IDispatch_iface;
6426 dispatch.ref = 10;
6428 hr = IRecordInfo_RecordCopy(recinfo, &teststruct, &testcopy);
6429 ok(hr == S_OK, "got 0x%08x\n", hr);
6430 ok(dispatch.ref == 9, "got %d\n", dispatch.ref);
6432 IRecordInfo_Release(recinfo);
6434 ITypeInfo_Release(typeinfo);
6435 ITypeLib_Release(typelib);
6436 DeleteFileA(filename);
6439 START_TEST(vartype)
6441 hOleaut32 = GetModuleHandleA("oleaut32.dll");
6443 has_i8 = GetProcAddress(hOleaut32, "VarI8FromI1") != NULL;
6444 has_locales = has_i8 && GetProcAddress(hOleaut32, "GetVarConversionLocaleSetting") != NULL;
6446 trace("LCIDs: System=0x%08x, User=0x%08x\n", GetSystemDefaultLCID(),
6447 GetUserDefaultLCID());
6449 test_bstr_cache();
6451 test_VarI1FromI2();
6452 test_VarI1FromI4();
6453 test_VarI1FromI8();
6454 test_VarI1FromUI1();
6455 test_VarI1FromUI2();
6456 test_VarI1FromUI4();
6457 test_VarI1FromUI8();
6458 test_VarI1FromBool();
6459 test_VarI1FromR4();
6460 test_VarI1FromR8();
6461 test_VarI1FromDate();
6462 test_VarI1FromCy();
6463 test_VarI1FromDec();
6464 test_VarI1FromStr();
6465 test_VarUI1FromDisp();
6466 test_VarI1Copy();
6467 test_VarI1ChangeTypeEx();
6469 test_VarUI1FromI1();
6470 test_VarUI1FromI2();
6471 test_VarUI1FromI4();
6472 test_VarUI1FromI8();
6473 test_VarUI1FromUI2();
6474 test_VarUI1FromUI4();
6475 test_VarUI1FromUI8();
6476 test_VarUI1FromBool();
6477 test_VarUI1FromR4();
6478 test_VarUI1FromR8();
6479 test_VarUI1FromDate();
6480 test_VarUI1FromCy();
6481 test_VarUI1FromDec();
6482 test_VarUI1FromStr();
6483 test_VarUI1Copy();
6484 test_VarUI1ChangeTypeEx();
6486 test_VarI2FromI1();
6487 test_VarI2FromI4();
6488 test_VarI2FromI8();
6489 test_VarI2FromUI1();
6490 test_VarI2FromUI2();
6491 test_VarI2FromUI4();
6492 test_VarI2FromUI8();
6493 test_VarI2FromBool();
6494 test_VarI2FromR4();
6495 test_VarI2FromR8();
6496 test_VarI2FromDate();
6497 test_VarI2FromCy();
6498 test_VarI2FromDec();
6499 test_VarI2FromStr();
6500 test_VarI2Copy();
6501 test_VarI2ChangeTypeEx();
6503 test_VarUI2FromI1();
6504 test_VarUI2FromI2();
6505 test_VarUI2FromI4();
6506 test_VarUI2FromI8();
6507 test_VarUI2FromUI1();
6508 test_VarUI2FromUI4();
6509 test_VarUI2FromUI8();
6510 test_VarUI2FromBool();
6511 test_VarUI2FromR4();
6512 test_VarUI2FromR8();
6513 test_VarUI2FromDate();
6514 test_VarUI2FromCy();
6515 test_VarUI2FromDec();
6516 test_VarUI2FromStr();
6517 test_VarUI2Copy();
6518 test_VarUI2ChangeTypeEx();
6520 test_VarI4FromI1();
6521 test_VarI4FromI2();
6522 test_VarI4FromI8();
6523 test_VarI4FromUI1();
6524 test_VarI4FromUI2();
6525 test_VarI4FromUI4();
6526 test_VarI4FromUI8();
6527 test_VarI4FromBool();
6528 test_VarI4FromR4();
6529 test_VarI4FromR8();
6530 test_VarI4FromDate();
6531 test_VarI4FromCy();
6532 test_VarI4FromDec();
6533 test_VarI4FromStr();
6534 test_VarI4Copy();
6535 test_VarI4ChangeTypeEx();
6537 test_VarUI4FromI1();
6538 test_VarUI4FromI2();
6539 test_VarUI4FromUI2();
6540 test_VarUI4FromI8();
6541 test_VarUI4FromUI1();
6542 test_VarUI4FromI4();
6543 test_VarUI4FromUI8();
6544 test_VarUI4FromBool();
6545 test_VarUI4FromR4();
6546 test_VarUI4FromR8();
6547 test_VarUI4FromDate();
6548 test_VarUI4FromCy();
6549 test_VarUI4FromDec();
6550 test_VarUI4FromStr();
6551 test_VarUI4Copy();
6552 test_VarUI4ChangeTypeEx();
6554 test_VarI8FromI1();
6555 test_VarI8FromUI1();
6556 test_VarI8FromI2();
6557 test_VarI8FromUI2();
6558 test_VarI8FromUI4();
6559 test_VarI8FromR4();
6560 test_VarI8FromR8();
6561 test_VarI8FromBool();
6562 test_VarI8FromUI8();
6563 test_VarI8FromCy();
6564 test_VarI8FromDec();
6565 test_VarI8FromDate();
6566 test_VarI8FromStr();
6567 test_VarI8Copy();
6568 test_VarI8ChangeTypeEx();
6570 test_VarUI8FromI1();
6571 test_VarUI8FromUI1();
6572 test_VarUI8FromI2();
6573 test_VarUI8FromUI2();
6574 test_VarUI8FromUI4();
6575 test_VarUI8FromR4();
6576 test_VarUI8FromR8();
6577 test_VarUI8FromBool();
6578 test_VarUI8FromI8();
6579 test_VarUI8FromCy();
6580 test_VarUI8FromDec();
6581 test_VarUI8FromDate();
6582 test_VarUI8FromStr();
6583 test_VarUI8Copy();
6584 test_VarUI8ChangeTypeEx();
6586 test_VarR4FromI1();
6587 test_VarR4FromUI1();
6588 test_VarR4FromI2();
6589 test_VarR4FromUI2();
6590 test_VarR4FromI4();
6591 test_VarR4FromUI4();
6592 test_VarR4FromR8();
6593 test_VarR4FromBool();
6594 test_VarR4FromCy();
6595 test_VarR4FromI8();
6596 test_VarR4FromUI8();
6597 test_VarR4FromDec();
6598 test_VarR4FromDate();
6599 test_VarR4FromStr();
6600 test_VarR4Copy();
6601 test_VarR4ChangeTypeEx();
6603 test_VarR8FromI1();
6604 test_VarR8FromUI1();
6605 test_VarR8FromI2();
6606 test_VarR8FromUI2();
6607 test_VarR8FromI4();
6608 test_VarR8FromUI4();
6609 test_VarR8FromR4();
6610 test_VarR8FromBool();
6611 test_VarR8FromCy();
6612 test_VarR8FromI8();
6613 test_VarR8FromUI8();
6614 test_VarR8FromDec();
6615 test_VarR8FromDate();
6616 test_VarR8FromStr();
6617 test_VarR8Copy();
6618 test_VarR8ChangeTypeEx();
6619 test_VarR8Round();
6621 test_VarDateFromI1();
6622 test_VarDateFromUI1();
6623 test_VarDateFromI2();
6624 test_VarDateFromUI2();
6625 test_VarDateFromI4();
6626 test_VarDateFromUI4();
6627 test_VarDateFromR4();
6628 test_VarDateFromR8();
6629 test_VarDateFromBool();
6630 test_VarDateFromCy();
6631 test_VarDateFromI8();
6632 test_VarDateFromUI8();
6633 test_VarDateFromDec();
6634 test_VarDateFromStr();
6635 test_VarDateCopy();
6636 test_VarDateChangeTypeEx();
6638 test_VarCyFromI1();
6639 test_VarCyFromUI1();
6640 test_VarCyFromI2();
6641 test_VarCyFromUI2();
6642 test_VarCyFromI4();
6643 test_VarCyFromUI4();
6644 test_VarCyFromR4();
6645 test_VarCyFromR8();
6646 test_VarCyFromBool();
6647 test_VarCyFromI8();
6648 test_VarCyFromUI8();
6649 test_VarCyFromDec();
6650 test_VarCyFromDate();
6652 test_VarCyAdd();
6653 test_VarCyMul();
6654 test_VarCySub();
6655 test_VarCyAbs();
6656 test_VarCyNeg();
6657 test_VarCyMulI4();
6658 test_VarCyMulI8();
6659 test_VarCyCmp();
6660 test_VarCyCmpR8();
6661 test_VarCyRound();
6662 test_VarCyFix();
6663 test_VarCyInt();
6665 test_VarDecFromI1();
6666 test_VarDecFromI2();
6667 test_VarDecFromI4();
6668 test_VarDecFromI8();
6669 test_VarDecFromUI1();
6670 test_VarDecFromUI2();
6671 test_VarDecFromUI4();
6672 test_VarDecFromUI8();
6673 test_VarDecFromR4();
6674 test_VarDecFromR8();
6675 test_VarDecFromDate();
6676 test_VarDecFromStr();
6677 test_VarDecFromCy();
6678 test_VarDecFromDate();
6679 test_VarDecFromBool();
6681 test_VarDecAbs();
6682 test_VarDecNeg();
6683 test_VarDecAdd();
6684 test_VarDecSub();
6685 test_VarDecCmp();
6686 test_VarDecCmpR8();
6687 test_VarDecMul();
6688 test_VarDecDiv();
6689 test_VarDecRound();
6691 test_VarBoolFromI1();
6692 test_VarBoolFromUI1();
6693 test_VarBoolFromI2();
6694 test_VarBoolFromUI2();
6695 test_VarBoolFromI4();
6696 test_VarBoolFromUI4();
6697 test_VarBoolFromR4();
6698 test_VarBoolFromR8();
6699 test_VarBoolFromCy();
6700 test_VarBoolFromI8();
6701 test_VarBoolFromUI8();
6702 test_VarBoolFromDec();
6703 test_VarBoolFromDate();
6704 test_VarBoolFromStr();
6705 test_VarBoolCopy();
6706 test_VarBoolChangeTypeEx();
6708 test_VarBstrFromR4();
6709 test_VarBstrFromDate();
6710 test_VarBstrFromCy();
6711 test_VarBstrFromDec();
6712 test_VarBstrCmp();
6713 test_SysStringLen();
6714 test_SysStringByteLen();
6715 test_SysAllocString();
6716 test_SysAllocStringLen();
6717 test_SysAllocStringByteLen();
6718 test_SysReAllocString();
6719 test_SysReAllocStringLen();
6720 test_BstrCopy();
6721 test_VarBstrCat();
6723 test_IUnknownClear();
6724 test_IUnknownCopy();
6725 test_IUnknownChangeTypeEx();
6727 test_IDispatchClear();
6728 test_IDispatchCopy();
6729 test_IDispatchChangeTypeEx();
6731 test_ErrorChangeTypeEx();
6732 test_EmptyChangeTypeEx();
6733 test_NullChangeTypeEx();
6734 test_UintChangeTypeEx();
6736 test_ClearCustData();
6738 test_NullByRef();
6739 test_ChangeType_keep_dst();
6741 test_recinfo();