mshtml: Added IHTMLTableRow::align property implementation.
[wine.git] / dlls / oleaut32 / tests / vartype.c
blob61ad45ebe6ee32cc7c81b6a24bc2c621531c36dd
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.0f); EXPECT(-128);
743 CONVERT(VarI1FromR4, -1.0f); EXPECT(-1);
744 CONVERT(VarI1FromR4, 0.0f); EXPECT(0);
745 CONVERT(VarI1FromR4, 1.0f); EXPECT(1);
746 CONVERT(VarI1FromR4, 127.0f); EXPECT(127);
747 CONVERT(VarI1FromR4, 128.0f); EXPECT_OVERFLOW;
749 CONVERT(VarI1FromR4, -1.5f); EXPECT(-2);
750 CONVERT(VarI1FromR4, -0.6f); EXPECT(-1);
751 CONVERT(VarI1FromR4, -0.5f); EXPECT(0);
752 CONVERT(VarI1FromR4, -0.4f); EXPECT(0);
753 CONVERT(VarI1FromR4, 0.4f); EXPECT(0);
754 CONVERT(VarI1FromR4, 0.5f); EXPECT(0);
755 CONVERT(VarI1FromR4, 0.6f); EXPECT(1);
756 CONVERT(VarI1FromR4, 1.5f); EXPECT(2);
759 static void test_VarI1FromR8(void)
761 CONVVARS(DOUBLE);
763 CHECKPTR(VarI1FromR8);
764 CONVERT(VarI1FromR8, -129.0); EXPECT_OVERFLOW;
765 CONVERT(VarI1FromR8, -128.0); EXPECT(-128);
766 CONVERT(VarI1FromR8, -1.0); EXPECT(-1);
767 CONVERT(VarI1FromR8, 0.0); EXPECT(0);
768 CONVERT(VarI1FromR8, 1.0); EXPECT(1);
769 CONVERT(VarI1FromR8, 127.0); EXPECT(127);
770 CONVERT(VarI1FromR8, 128.0); EXPECT_OVERFLOW;
772 CONVERT(VarI1FromR8, -1.5); EXPECT(-2);
773 CONVERT(VarI1FromR8, -0.6); EXPECT(-1);
774 CONVERT(VarI1FromR8, -0.5); EXPECT(0);
775 CONVERT(VarI1FromR8, -0.4); EXPECT(0);
776 CONVERT(VarI1FromR8, 0.4); EXPECT(0);
777 CONVERT(VarI1FromR8, 0.5); EXPECT(0);
778 CONVERT(VarI1FromR8, 0.6); EXPECT(1);
779 CONVERT(VarI1FromR8, 1.5); EXPECT(2);
782 static void test_VarI1FromDate(void)
784 CONVVARS(DATE);
786 CHECKPTR(VarI1FromDate);
787 CONVERT(VarI1FromDate, -129.0); EXPECT_OVERFLOW;
788 CONVERT(VarI1FromDate, -128.0); EXPECT(-128);
789 CONVERT(VarI1FromDate, -1.0); EXPECT(-1);
790 CONVERT(VarI1FromDate, 0.0); EXPECT(0);
791 CONVERT(VarI1FromDate, 1.0); EXPECT(1);
792 CONVERT(VarI1FromDate, 127.0); EXPECT(127);
793 CONVERT(VarI1FromDate, 128.0); EXPECT_OVERFLOW;
795 CONVERT(VarI1FromDate, -1.5); EXPECT(-2);
796 CONVERT(VarI1FromDate, -0.6); EXPECT(-1);
797 CONVERT(VarI1FromDate, -0.5); EXPECT(0);
798 CONVERT(VarI1FromDate, -0.4); EXPECT(0);
799 CONVERT(VarI1FromDate, 0.4); EXPECT(0);
800 CONVERT(VarI1FromDate, 0.5); EXPECT(0);
801 CONVERT(VarI1FromDate, 0.6); EXPECT(1);
802 CONVERT(VarI1FromDate, 1.5); EXPECT(2);
805 static void test_VarI1FromCy(void)
807 CONVVARS(CY);
809 CHECKPTR(VarI1FromCy);
810 CONVERT_CY(VarI1FromCy,-129); EXPECT_OVERFLOW;
811 CONVERT_CY(VarI1FromCy,-128); EXPECT(128);
812 CONVERT_CY(VarI1FromCy,-1); EXPECT(-1);
813 CONVERT_CY(VarI1FromCy,0); EXPECT(0);
814 CONVERT_CY(VarI1FromCy,1); EXPECT(1);
815 CONVERT_CY(VarI1FromCy,127); EXPECT(127);
816 CONVERT_CY(VarI1FromCy,128); EXPECT_OVERFLOW;
818 CONVERT_CY(VarI1FromCy,-1.5); EXPECT(-2);
819 CONVERT_CY(VarI1FromCy,-0.6); EXPECT(-1);
820 CONVERT_CY(VarI1FromCy,-0.5); EXPECT(0);
821 CONVERT_CY(VarI1FromCy,-0.4); EXPECT(0);
822 CONVERT_CY(VarI1FromCy,0.4); EXPECT(0);
823 CONVERT_CY(VarI1FromCy,0.5); EXPECT(0);
824 CONVERT_CY(VarI1FromCy,0.6); EXPECT(1);
825 CONVERT_CY(VarI1FromCy,1.5); EXPECT(2);
828 static void test_VarI1FromDec(void)
830 CONVVARS(DECIMAL);
832 CHECKPTR(VarI1FromDec);
834 CONVERT_BADDEC(VarI1FromDec);
836 CONVERT_DEC(VarI1FromDec,0,0x80,0,129); EXPECT_OVERFLOW;
837 CONVERT_DEC(VarI1FromDec,0,0x80,0,128); EXPECT(-128);
838 CONVERT_DEC(VarI1FromDec,0,0x80,0,1); EXPECT(-1);
839 CONVERT_DEC(VarI1FromDec,0,0,0,0); EXPECT(0);
840 CONVERT_DEC(VarI1FromDec,0,0,0,1); EXPECT(1);
841 CONVERT_DEC(VarI1FromDec,0,0,0,127); EXPECT(127);
842 CONVERT_DEC(VarI1FromDec,0,0,0,128); EXPECT_OVERFLOW;
844 CONVERT_DEC(VarI1FromDec,2,0x80,0,12800); EXPECT(-128);
845 CONVERT_DEC(VarI1FromDec,2,0,0,12700); EXPECT(127);
848 static void test_VarI1FromStr(void)
850 CONVVARS(LCID);
851 OLECHAR buff[128];
853 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
855 CHECKPTR(VarI1FromStr);
857 CONVERT_STR(VarI1FromStr,NULL, 0); EXPECT_MISMATCH;
858 CONVERT_STR(VarI1FromStr,"0", 0); EXPECT(0);
859 CONVERT_STR(VarI1FromStr,"-129", 0); EXPECT_OVERFLOW;
860 CONVERT_STR(VarI1FromStr,"-128", 0); EXPECT(-128);
861 CONVERT_STR(VarI1FromStr,"127", 0); EXPECT(127);
862 CONVERT_STR(VarI1FromStr,"128", 0); EXPECT_OVERFLOW;
864 CONVERT_STR(VarI1FromStr,"-1.5", LOCALE_NOUSEROVERRIDE); EXPECT(-2);
865 CONVERT_STR(VarI1FromStr,"-0.6", LOCALE_NOUSEROVERRIDE); EXPECT(-1);
866 CONVERT_STR(VarI1FromStr,"-0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
867 CONVERT_STR(VarI1FromStr,"-0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
868 CONVERT_STR(VarI1FromStr,"0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
869 CONVERT_STR(VarI1FromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
870 CONVERT_STR(VarI1FromStr,"0.6", LOCALE_NOUSEROVERRIDE); EXPECT(1);
871 CONVERT_STR(VarI1FromStr,"1.5", LOCALE_NOUSEROVERRIDE); EXPECT(2);
874 static void test_VarI1Copy(void)
876 COPYTEST(1, VT_I1, V_I1(&vSrc), V_I1(&vDst), V_I1REF(&vSrc), V_I1REF(&vDst), "%d");
879 static void test_VarI1ChangeTypeEx(void)
881 HRESULT hres;
882 signed char in;
883 VARIANTARG vSrc, vDst;
885 in = 1;
887 INITIAL_TYPETEST(VT_I1, V_I1, "%d");
888 COMMON_TYPETEST;
889 NEGATIVE_TYPETEST(VT_I1, V_I1, "%d", VT_UI1, V_UI1);
892 #undef CONV_TYPE
893 #define CONV_TYPE BYTE
895 static void test_VarUI1FromI1(void)
897 CONVVARS(signed char);
898 int i;
900 CHECKPTR(VarUI1FromI1);
901 OVERFLOWRANGE(VarUI1FromI1, -128, 0);
902 CONVERTRANGE(VarUI1FromI1, 0, 128);
905 static void test_VarUI1FromI2(void)
907 CONVVARS(SHORT);
908 int i;
910 CHECKPTR(VarUI1FromI2);
911 OVERFLOWRANGE(VarUI1FromI2, -32768, 0);
912 CONVERTRANGE(VarUI1FromI2, 0, 256);
913 OVERFLOWRANGE(VarUI1FromI2, 256, 32768);
916 static void test_VarUI1FromI4(void)
918 CONVVARS(LONG);
919 int i;
921 CHECKPTR(VarUI1FromI4);
922 CONVERT(VarUI1FromI4, -1); EXPECT_OVERFLOW;
923 CONVERTRANGE(VarUI1FromI4, 0, 256);
924 CONVERT(VarUI1FromI4, 256); EXPECT_OVERFLOW;
927 static void test_VarUI1FromI8(void)
929 CONVVARS(LONG64);
930 int i;
932 CHECKPTR(VarUI1FromI8);
933 CONVERT(VarUI1FromI8, -1); EXPECT_OVERFLOW;
934 CONVERTRANGE(VarUI1FromI8, 0, 256);
935 CONVERT(VarUI1FromI8, 256); EXPECT_OVERFLOW;
938 static void test_VarUI1FromUI2(void)
940 CONVVARS(USHORT);
941 int i;
943 CHECKPTR(VarUI1FromUI2);
944 CONVERTRANGE(VarUI1FromUI2, 0, 256);
945 OVERFLOWRANGE(VarUI1FromUI2, 256, 65536);
948 static void test_VarUI1FromUI4(void)
950 CONVVARS(ULONG);
951 int i;
953 CHECKPTR(VarUI1FromUI4);
954 CONVERTRANGE(VarUI1FromUI4, 0, 256);
955 CONVERT(VarUI1FromUI4, 256); EXPECT_OVERFLOW;
958 static void test_VarUI1FromUI8(void)
960 CONVVARS(ULONG64);
961 int i;
963 CHECKPTR(VarUI1FromUI8);
964 CONVERTRANGE(VarUI1FromUI8, 0, 256);
965 CONVERT(VarUI1FromUI8, 256); EXPECT_OVERFLOW;
968 static void test_VarUI1FromBool(void)
970 CONVVARS(VARIANT_BOOL);
971 int i;
973 CHECKPTR(VarUI1FromBool);
974 /* Note that conversions from bool overflow! */
975 CONVERT(VarUI1FromBool, -1); EXPECT(255);
976 CONVERTRANGE(VarUI1FromBool, 0, 256);
977 CONVERT(VarUI1FromBool, 256); EXPECT(0);
980 static void test_VarUI1FromR4(void)
982 CONVVARS(FLOAT);
984 CHECKPTR(VarUI1FromR4);
985 CONVERT(VarUI1FromR4, -1.0f); EXPECT_OVERFLOW;
986 CONVERT(VarUI1FromR4, 0.0f); EXPECT(0);
987 CONVERT(VarUI1FromR4, 1.0f); EXPECT(1);
988 CONVERT(VarUI1FromR4, 255.0f); EXPECT(255);
989 CONVERT(VarUI1FromR4, 256.0f); EXPECT_OVERFLOW;
991 /* Rounding */
992 CONVERT(VarUI1FromR4, -1.5f); EXPECT_OVERFLOW;
993 CONVERT(VarUI1FromR4, -0.6f); EXPECT_OVERFLOW;
994 CONVERT(VarUI1FromR4, -0.5f); EXPECT(0);
995 CONVERT(VarUI1FromR4, -0.4f); EXPECT(0);
996 CONVERT(VarUI1FromR4, 0.4f); EXPECT(0);
997 CONVERT(VarUI1FromR4, 0.5f); EXPECT(0);
998 CONVERT(VarUI1FromR4, 0.6f); EXPECT(1);
999 CONVERT(VarUI1FromR4, 1.5f); EXPECT(2);
1002 static void test_VarUI1FromR8(void)
1004 CONVVARS(DOUBLE);
1006 CHECKPTR(VarUI1FromR8);
1007 CONVERT(VarUI1FromR8, -1.0); EXPECT_OVERFLOW;
1008 CONVERT(VarUI1FromR8, 0.0); EXPECT(0);
1009 CONVERT(VarUI1FromR8, 1.0); EXPECT(1);
1010 CONVERT(VarUI1FromR8, 255.0); EXPECT(255);
1011 CONVERT(VarUI1FromR8, 256.0); EXPECT_OVERFLOW;
1013 /* Rounding */
1014 CONVERT(VarUI1FromR8, -1.5); EXPECT_OVERFLOW;
1015 CONVERT(VarUI1FromR8, -0.6); EXPECT_OVERFLOW;
1016 CONVERT(VarUI1FromR8, -0.5); EXPECT(0);
1017 CONVERT(VarUI1FromR8, -0.4); EXPECT(0);
1018 CONVERT(VarUI1FromR8, 0.4); EXPECT(0);
1019 CONVERT(VarUI1FromR8, 0.5); EXPECT(0);
1020 CONVERT(VarUI1FromR8, 0.6); EXPECT(1);
1021 CONVERT(VarUI1FromR8, 1.5); EXPECT(2);
1024 static void test_VarUI1FromDate(void)
1026 CONVVARS(DATE);
1028 CHECKPTR(VarUI1FromDate);
1029 CONVERT(VarUI1FromDate, -1.0); EXPECT_OVERFLOW;
1030 CONVERT(VarUI1FromDate, 0.0); EXPECT(0);
1031 CONVERT(VarUI1FromDate, 1.0); EXPECT(1);
1032 CONVERT(VarUI1FromDate, 255.0); EXPECT(255);
1033 CONVERT(VarUI1FromDate, 256.0); EXPECT_OVERFLOW;
1035 /* Rounding */
1036 CONVERT(VarUI1FromDate, -1.5); EXPECT_OVERFLOW;
1037 CONVERT(VarUI1FromDate, -0.6); EXPECT_OVERFLOW;
1038 CONVERT(VarUI1FromDate, -0.5); EXPECT(0);
1039 CONVERT(VarUI1FromDate, -0.4); EXPECT(0);
1040 CONVERT(VarUI1FromDate, 0.4); EXPECT(0);
1041 CONVERT(VarUI1FromDate, 0.5); EXPECT(0);
1042 CONVERT(VarUI1FromDate, 0.6); EXPECT(1);
1043 CONVERT(VarUI1FromDate, 1.5); EXPECT(2);
1046 static void test_VarUI1FromCy(void)
1048 CONVVARS(CY);
1050 CHECKPTR(VarUI1FromCy);
1051 CONVERT_CY(VarUI1FromCy,-1); EXPECT_OVERFLOW;
1052 CONVERT_CY(VarUI1FromCy,0); EXPECT(0);
1053 CONVERT_CY(VarUI1FromCy,1); EXPECT(1);
1054 CONVERT_CY(VarUI1FromCy,255); EXPECT(255);
1055 CONVERT_CY(VarUI1FromCy,256); EXPECT_OVERFLOW;
1057 /* Rounding */
1058 CONVERT_CY(VarUI1FromCy,-1.5); EXPECT_OVERFLOW;
1059 CONVERT_CY(VarUI1FromCy,-0.6); EXPECT_OVERFLOW;
1060 CONVERT_CY(VarUI1FromCy,-0.5); EXPECT(0);
1061 CONVERT_CY(VarUI1FromCy,-0.4); EXPECT(0);
1062 CONVERT_CY(VarUI1FromCy,0.4); EXPECT(0);
1063 CONVERT_CY(VarUI1FromCy,0.5); EXPECT(0);
1064 CONVERT_CY(VarUI1FromCy,0.6); EXPECT(1);
1065 CONVERT_CY(VarUI1FromCy,1.5); EXPECT(2);
1068 static void test_VarUI1FromDec(void)
1070 CONVVARS(DECIMAL);
1072 CHECKPTR(VarUI1FromDec);
1074 CONVERT_BADDEC(VarUI1FromDec);
1076 CONVERT_DEC(VarUI1FromDec,0,0x80,0,1); EXPECT_OVERFLOW;
1077 CONVERT_DEC(VarUI1FromDec,0,0,0,0); EXPECT(0);
1078 CONVERT_DEC(VarUI1FromDec,0,0,0,1); EXPECT(1);
1079 CONVERT_DEC(VarUI1FromDec,0,0,0,255); EXPECT(255);
1080 CONVERT_DEC(VarUI1FromDec,0,0,0,256); EXPECT_OVERFLOW;
1082 CONVERT_DEC(VarUI1FromDec,2,0x80,0,100); EXPECT_OVERFLOW;
1083 CONVERT_DEC(VarUI1FromDec,2,0,0,25500); EXPECT(255);
1086 static void test_VarUI1FromStr(void)
1088 CONVVARS(LCID);
1089 OLECHAR buff[128];
1091 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1093 CHECKPTR(VarUI1FromStr);
1095 CONVERT_STR(VarUI1FromStr,NULL, 0); EXPECT_MISMATCH;
1096 CONVERT_STR(VarUI1FromStr,"0", 0); EXPECT(0);
1097 CONVERT_STR(VarUI1FromStr,"-1", 0); EXPECT_OVERFLOW;
1098 CONVERT_STR(VarUI1FromStr,"255", 0); EXPECT(255);
1099 CONVERT_STR(VarUI1FromStr,"256", 0); EXPECT_OVERFLOW;
1101 /* Rounding */
1102 CONVERT_STR(VarUI1FromStr,"-1.5", LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
1103 CONVERT_STR(VarUI1FromStr,"-0.6", LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
1104 CONVERT_STR(VarUI1FromStr,"-0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1105 CONVERT_STR(VarUI1FromStr,"-0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1106 CONVERT_STR(VarUI1FromStr,"0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1107 CONVERT_STR(VarUI1FromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1108 CONVERT_STR(VarUI1FromStr,"0.6", LOCALE_NOUSEROVERRIDE); EXPECT(1);
1109 CONVERT_STR(VarUI1FromStr,"1.5", LOCALE_NOUSEROVERRIDE); EXPECT(2);
1112 static void test_VarUI1FromDisp(void)
1114 DummyDispatch dispatch;
1115 CONVVARS(LCID);
1116 VARIANTARG vSrc, vDst;
1118 CHECKPTR(VarUI1FromDisp);
1120 /* FIXME
1121 * Conversions from IDispatch should get the default 'value' property
1122 * from the IDispatch pointer and return it. The following tests this.
1123 * However, I can't get these tests to return a valid value under native
1124 * oleaut32, regardless of the value returned in response to the Invoke()
1125 * call (early versions of oleaut32 call AddRef/Release, but not Invoke.
1126 * I'm obviously missing something, as these conversions work fine
1127 * when called through VBA on an object to get its default value property.
1129 * Should this test be corrected so that it works under native it should be
1130 * generalised and the remaining types checked as well.
1132 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1134 VariantInit(&vSrc);
1135 VariantInit(&vDst);
1137 init_test_dispatch(1, VT_UI1, &dispatch);
1138 V_VT(&vSrc) = VT_DISPATCH;
1139 V_DISPATCH(&vSrc) = &dispatch.IDispatch_iface;
1141 SET_EXPECT(dispatch_invoke);
1142 out = 10;
1143 hres = pVarUI1FromDisp(&dispatch.IDispatch_iface, in, &out);
1144 ok(broken(hres == DISP_E_BADVARTYPE) || hres == S_OK, "got 0x%08x\n", hres);
1145 ok(broken(out == 10) || out == 1, "got %d\n", out);
1146 CHECK_CALLED(dispatch_invoke);
1148 SET_EXPECT(dispatch_invoke);
1149 V_VT(&vDst) = VT_EMPTY;
1150 V_UI1(&vDst) = 0;
1151 hres = VariantChangeTypeEx(&vDst, &vSrc, in, 0, VT_UI1);
1152 ok(hres == S_OK, "got 0x%08x\n", hres);
1153 ok(V_VT(&vDst) == VT_UI1, "got %d\n", V_VT(&vDst));
1154 ok(V_UI1(&vDst) == 1, "got %d\n", V_UI1(&vDst));
1155 CHECK_CALLED(dispatch_invoke);
1157 dispatch.bFailInvoke = TRUE;
1159 SET_EXPECT(dispatch_invoke);
1160 out = 10;
1161 hres = pVarUI1FromDisp(&dispatch.IDispatch_iface, in, &out);
1162 ok(hres == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hres);
1163 ok(out == 10, "got %d\n", out);
1164 CHECK_CALLED(dispatch_invoke);
1166 SET_EXPECT(dispatch_invoke);
1167 V_VT(&vDst) = VT_EMPTY;
1168 hres = VariantChangeTypeEx(&vDst, &vSrc, in, 0, VT_UI1);
1169 ok(hres == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hres);
1170 ok(V_VT(&vDst) == VT_EMPTY, "got %d\n", V_VT(&vDst));
1171 CHECK_CALLED(dispatch_invoke);
1174 static void test_VarUI1Copy(void)
1176 COPYTEST(1, VT_UI1, V_UI1(&vSrc), V_UI1(&vDst), V_UI1REF(&vSrc), V_UI1REF(&vDst), "%d");
1179 static void test_VarUI1ChangeTypeEx(void)
1181 HRESULT hres;
1182 BYTE in;
1183 VARIANTARG vSrc, vDst;
1185 in = 1;
1187 INITIAL_TYPETEST(VT_UI1, V_UI1, "%d");
1188 COMMON_TYPETEST;
1189 NEGATIVE_TYPETEST(VT_UI1, V_UI1, "%d", VT_I1, V_I1);
1193 * VT_I2/VT_UI2
1196 #undef CONV_TYPE
1197 #define CONV_TYPE SHORT
1199 static void test_VarI2FromI1(void)
1201 CONVVARS(signed char);
1202 int i;
1204 CHECKPTR(VarI2FromI1);
1205 CONVERTRANGE(VarI2FromI1, -128, 128);
1208 static void test_VarI2FromI4(void)
1210 CONVVARS(LONG);
1211 int i;
1213 CHECKPTR(VarI2FromI4);
1214 CONVERT(VarI2FromI4, -32769); EXPECT_OVERFLOW;
1215 CONVERTRANGE(VarI2FromI4, -32768, 32768);
1216 CONVERT(VarI2FromI4, 32768); EXPECT_OVERFLOW;
1219 static void test_VarI2FromI8(void)
1221 CONVVARS(LONG64);
1223 CHECKPTR(VarI2FromI8);
1224 CONVERT(VarI2FromI8, -32769); EXPECT_OVERFLOW;
1225 CONVERT(VarI2FromI8, -32768); EXPECT(-32768);
1226 CONVERT(VarI2FromI8, 32767); EXPECT(32767);
1227 CONVERT(VarI2FromI8, 32768); EXPECT_OVERFLOW;
1230 static void test_VarI2FromUI1(void)
1232 CONVVARS(BYTE);
1233 int i;
1235 CHECKPTR(VarI2FromUI1);
1236 CONVERTRANGE(VarI2FromUI1, 0, 256);
1239 static void test_VarI2FromUI2(void)
1241 CONVVARS(USHORT);
1242 int i;
1244 CHECKPTR(VarI2FromUI2);
1245 CONVERTRANGE(VarI2FromUI2, 0, 32768);
1246 CONVERT(VarI2FromUI2, 32768); EXPECT_OVERFLOW;
1249 static void test_VarI2FromUI4(void)
1251 CONVVARS(ULONG);
1252 int i;
1254 CHECKPTR(VarI2FromUI4);
1255 CONVERTRANGE(VarI2FromUI4, 0, 32768);
1256 CONVERT(VarI2FromUI4, 32768); EXPECT_OVERFLOW;
1259 static void test_VarI2FromUI8(void)
1261 CONVVARS(ULONG64);
1262 int i;
1264 CHECKPTR(VarI2FromUI8);
1265 CONVERTRANGE(VarI2FromUI8, 0, 32768);
1266 CONVERT(VarI2FromUI8, 32768); EXPECT_OVERFLOW;
1269 static void test_VarI2FromBool(void)
1271 CONVVARS(VARIANT_BOOL);
1272 int i;
1274 CHECKPTR(VarI2FromBool);
1275 CONVERTRANGE(VarI2FromBool, -32768, 32768);
1278 static void test_VarI2FromR4(void)
1280 CONVVARS(FLOAT);
1282 CHECKPTR(VarI2FromR4);
1283 CONVERT(VarI2FromR4, -32769.0f); EXPECT_OVERFLOW;
1284 CONVERT(VarI2FromR4, -32768.0f); EXPECT(-32768);
1285 CONVERT(VarI2FromR4, -1.0f); EXPECT(-1);
1286 CONVERT(VarI2FromR4, 0.0f); EXPECT(0);
1287 CONVERT(VarI2FromR4, 1.0f); EXPECT(1);
1288 CONVERT(VarI2FromR4, 32767.0f); EXPECT(32767);
1289 CONVERT(VarI2FromR4, 32768.0f); EXPECT_OVERFLOW;
1291 /* Rounding */
1292 CONVERT(VarI2FromR4, -1.5f); EXPECT(-2);
1293 CONVERT(VarI2FromR4, -0.6f); EXPECT(-1);
1294 CONVERT(VarI2FromR4, -0.5f); EXPECT(0);
1295 CONVERT(VarI2FromR4, -0.4f); EXPECT(0);
1296 CONVERT(VarI2FromR4, 0.4f); EXPECT(0);
1297 CONVERT(VarI2FromR4, 0.5f); EXPECT(0);
1298 CONVERT(VarI2FromR4, 0.6f); EXPECT(1);
1299 CONVERT(VarI2FromR4, 1.5f); EXPECT(2);
1302 static void test_VarI2FromR8(void)
1304 CONVVARS(DOUBLE);
1306 CHECKPTR(VarI2FromR8);
1307 CONVERT(VarI2FromR8, -32769.0); EXPECT_OVERFLOW;
1308 CONVERT(VarI2FromR8, -32768.0); EXPECT(-32768);
1309 CONVERT(VarI2FromR8, -1.0); EXPECT(-1);
1310 CONVERT(VarI2FromR8, 0.0); EXPECT(0);
1311 CONVERT(VarI2FromR8, 1.0); EXPECT(1);
1312 CONVERT(VarI2FromR8, 32767.0); EXPECT(32767);
1313 CONVERT(VarI2FromR8, 32768.0); EXPECT_OVERFLOW;
1315 /* Rounding */
1316 CONVERT(VarI2FromR8, -1.5); EXPECT(-2);
1317 CONVERT(VarI2FromR8, -0.6); EXPECT(-1);
1318 CONVERT(VarI2FromR8, -0.5); EXPECT(0);
1319 CONVERT(VarI2FromR8, -0.4); EXPECT(0);
1320 CONVERT(VarI2FromR8, 0.4); EXPECT(0);
1321 CONVERT(VarI2FromR8, 0.5); EXPECT(0);
1322 CONVERT(VarI2FromR8, 0.6); EXPECT(1);
1323 CONVERT(VarI2FromR8, 1.5); EXPECT(2);
1326 static void test_VarI2FromDate(void)
1328 CONVVARS(DATE);
1330 CHECKPTR(VarI2FromDate);
1331 CONVERT(VarI2FromDate, -32769.0); EXPECT_OVERFLOW;
1332 CONVERT(VarI2FromDate, -32768.0); EXPECT(-32768);
1333 CONVERT(VarI2FromDate, -1.0); EXPECT(-1);
1334 CONVERT(VarI2FromDate, 0.0); EXPECT(0);
1335 CONVERT(VarI2FromDate, 1.0); EXPECT(1);
1336 CONVERT(VarI2FromDate, 32767.0); EXPECT(32767);
1337 CONVERT(VarI2FromDate, 32768.0); EXPECT_OVERFLOW;
1339 /* Rounding */
1340 CONVERT(VarI2FromDate, -1.5); EXPECT(-2);
1341 CONVERT(VarI2FromDate, -0.6); EXPECT(-1);
1342 CONVERT(VarI2FromDate, -0.5); EXPECT(0);
1343 CONVERT(VarI2FromDate, -0.4); EXPECT(0);
1344 CONVERT(VarI2FromDate, 0.4); EXPECT(0);
1345 CONVERT(VarI2FromDate, 0.5); EXPECT(0);
1346 CONVERT(VarI2FromDate, 0.6); EXPECT(1);
1347 CONVERT(VarI2FromDate, 1.5); EXPECT(2);
1350 static void test_VarI2FromCy(void)
1352 CONVVARS(CY);
1354 CHECKPTR(VarI2FromCy);
1355 CONVERT_CY(VarI2FromCy,-32769); EXPECT_OVERFLOW;
1356 CONVERT_CY(VarI2FromCy,-32768); EXPECT(32768);
1357 CONVERT_CY(VarI2FromCy,-1); EXPECT(-1);
1358 CONVERT_CY(VarI2FromCy,0); EXPECT(0);
1359 CONVERT_CY(VarI2FromCy,1); EXPECT(1);
1360 CONVERT_CY(VarI2FromCy,32767); EXPECT(32767);
1361 CONVERT_CY(VarI2FromCy,32768); EXPECT_OVERFLOW;
1363 /* Rounding */
1364 CONVERT_CY(VarI2FromCy,-1.5); EXPECT(-2);
1365 CONVERT_CY(VarI2FromCy,-0.6); EXPECT(-1);
1366 CONVERT_CY(VarI2FromCy,-0.5); EXPECT(0);
1367 CONVERT_CY(VarI2FromCy,-0.4); EXPECT(0);
1368 CONVERT_CY(VarI2FromCy,0.4); EXPECT(0);
1369 CONVERT_CY(VarI2FromCy,0.5); EXPECT(0);
1370 CONVERT_CY(VarI2FromCy,0.6); EXPECT(1);
1371 CONVERT_CY(VarI2FromCy,1.5); EXPECT(2);
1374 static void test_VarI2FromDec(void)
1376 CONVVARS(DECIMAL);
1378 CHECKPTR(VarI2FromDec);
1380 CONVERT_BADDEC(VarI2FromDec);
1382 CONVERT_DEC(VarI2FromDec,0,0x80,0,32769); EXPECT_OVERFLOW;
1383 CONVERT_DEC(VarI2FromDec,0,0x80,0,32768); EXPECT(-32768);
1384 CONVERT_DEC(VarI2FromDec,0,0x80,0,1); EXPECT(-1);
1385 CONVERT_DEC(VarI2FromDec,0,0,0,0); EXPECT(0);
1386 CONVERT_DEC(VarI2FromDec,0,0,0,1); EXPECT(1);
1387 CONVERT_DEC(VarI2FromDec,0,0,0,32767); EXPECT(32767);
1388 CONVERT_DEC(VarI2FromDec,0,0,0,32768); EXPECT_OVERFLOW;
1390 CONVERT_DEC(VarI2FromDec,2,0x80,0,3276800); EXPECT(-32768);
1391 CONVERT_DEC(VarI2FromDec,2,0,0,3276700); EXPECT(32767);
1392 CONVERT_DEC(VarI2FromDec,2,0,0,3276800); EXPECT_OVERFLOW;
1395 static void test_VarI2FromStr(void)
1397 CONVVARS(LCID);
1398 OLECHAR buff[128];
1400 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1402 CHECKPTR(VarI2FromStr);
1404 CONVERT_STR(VarI2FromStr,NULL, 0); EXPECT_MISMATCH;
1405 CONVERT_STR(VarI2FromStr,"0", 0); EXPECT(0);
1406 CONVERT_STR(VarI2FromStr,"-32769", 0); EXPECT_OVERFLOW;
1407 CONVERT_STR(VarI2FromStr,"-32768", 0); EXPECT(-32768);
1408 CONVERT_STR(VarI2FromStr,"32767", 0); EXPECT(32767);
1409 CONVERT_STR(VarI2FromStr,"32768", 0); EXPECT_OVERFLOW;
1411 /* Rounding */
1412 CONVERT_STR(VarI2FromStr,"-1.5", LOCALE_NOUSEROVERRIDE); EXPECT(-2);
1413 CONVERT_STR(VarI2FromStr,"-0.6", LOCALE_NOUSEROVERRIDE); EXPECT(-1);
1414 CONVERT_STR(VarI2FromStr,"-0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1415 CONVERT_STR(VarI2FromStr,"-0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1416 CONVERT_STR(VarI2FromStr,"0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1417 CONVERT_STR(VarI2FromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1418 CONVERT_STR(VarI2FromStr,"0.6", LOCALE_NOUSEROVERRIDE); EXPECT(1);
1419 CONVERT_STR(VarI2FromStr,"1.5", LOCALE_NOUSEROVERRIDE); EXPECT(2);
1422 static void test_VarI2Copy(void)
1424 COPYTEST(1, VT_I2, V_I2(&vSrc), V_I2(&vDst), V_I2REF(&vSrc), V_I2REF(&vDst), "%d");
1427 static void test_VarI2ChangeTypeEx(void)
1429 HRESULT hres;
1430 SHORT in;
1431 VARIANTARG vSrc, vDst;
1433 in = 1;
1435 INITIAL_TYPETEST(VT_I2, V_I2, "%d");
1436 COMMON_TYPETEST;
1437 NEGATIVE_TYPETEST(VT_I2, V_I2, "%d", VT_UI2, V_UI2);
1440 #undef CONV_TYPE
1441 #define CONV_TYPE USHORT
1443 static void test_VarUI2FromI1(void)
1445 CONVVARS(signed char);
1446 int i;
1448 CHECKPTR(VarUI2FromI1);
1449 OVERFLOWRANGE(VarUI2FromI1, -128, 0);
1450 CONVERTRANGE(VarUI2FromI1, 0, 128);
1453 static void test_VarUI2FromI2(void)
1455 CONVVARS(SHORT);
1456 int i;
1458 CHECKPTR(VarUI2FromI2);
1459 OVERFLOWRANGE(VarUI2FromI2, -32768, 0);
1460 CONVERTRANGE(VarUI2FromI2, 0, 32768);
1463 static void test_VarUI2FromI4(void)
1465 CONVVARS(LONG);
1466 int i;
1468 CHECKPTR(VarUI2FromI4);
1469 OVERFLOWRANGE(VarUI2FromI4, -32768, 0);
1470 CONVERT(VarUI2FromI4, 0); EXPECT(0);
1471 CONVERT(VarUI2FromI4, 65535); EXPECT(65535);
1472 CONVERT(VarUI2FromI4, 65536); EXPECT_OVERFLOW;
1475 static void test_VarUI2FromI8(void)
1477 CONVVARS(LONG64);
1478 int i;
1480 CHECKPTR(VarUI2FromI8);
1481 OVERFLOWRANGE(VarUI2FromI8, -32768, 0);
1482 CONVERT(VarUI2FromI8, 0); EXPECT(0);
1483 CONVERT(VarUI2FromI8, 65535); EXPECT(65535);
1484 CONVERT(VarUI2FromI8, 65536); EXPECT_OVERFLOW;
1487 static void test_VarUI2FromUI1(void)
1489 CONVVARS(BYTE);
1490 int i;
1492 CHECKPTR(VarUI2FromUI1);
1493 CONVERTRANGE(VarUI2FromUI1, 0, 256);
1496 static void test_VarUI2FromUI4(void)
1498 CONVVARS(ULONG);
1500 CHECKPTR(VarUI2FromUI4);
1501 CONVERT(VarUI2FromUI4, 0); EXPECT(0);
1502 CONVERT(VarUI2FromUI4, 65535); EXPECT(65535);
1503 CONVERT(VarUI2FromUI4, 65536); EXPECT_OVERFLOW;
1506 static void test_VarUI2FromUI8(void)
1508 CONVVARS(ULONG64);
1510 CHECKPTR(VarUI2FromUI8);
1511 CONVERT(VarUI2FromUI8, 0); EXPECT(0);
1512 CONVERT(VarUI2FromUI8, 65535); EXPECT(65535);
1513 CONVERT(VarUI2FromUI8, 65536); EXPECT_OVERFLOW;
1516 static void test_VarUI2FromBool(void)
1518 CONVVARS(VARIANT_BOOL);
1519 int i;
1521 CHECKPTR(VarUI2FromBool);
1522 CONVERT(VarUI2FromBool, -1); EXPECT(65535); /* Wraps! */
1523 CONVERTRANGE(VarUI2FromBool, 0, 32768);
1526 static void test_VarUI2FromR4(void)
1528 CONVVARS(FLOAT);
1530 CHECKPTR(VarUI2FromR4);
1531 CONVERT(VarUI2FromR4, -1.0f); EXPECT_OVERFLOW;
1532 CONVERT(VarUI2FromR4, 0.0f); EXPECT(0);
1533 CONVERT(VarUI2FromR4, 1.0f); EXPECT(1);
1534 CONVERT(VarUI2FromR4, 65535.0f); EXPECT(65535);
1535 CONVERT(VarUI2FromR4, 65536.0f); EXPECT_OVERFLOW;
1537 /* Rounding */
1538 CONVERT(VarUI2FromR4, -1.5f); EXPECT_OVERFLOW;
1539 CONVERT(VarUI2FromR4, -0.6f); EXPECT_OVERFLOW;
1540 CONVERT(VarUI2FromR4, -0.5f); EXPECT(0);
1541 CONVERT(VarUI2FromR4, -0.4f); EXPECT(0);
1542 CONVERT(VarUI2FromR4, 0.4f); EXPECT(0);
1543 CONVERT(VarUI2FromR4, 0.5f); EXPECT(0);
1544 CONVERT(VarUI2FromR4, 0.6f); EXPECT(1);
1545 CONVERT(VarUI2FromR4, 1.5f); EXPECT(2);
1548 static void test_VarUI2FromR8(void)
1550 CONVVARS(DOUBLE);
1552 CHECKPTR(VarUI2FromR8);
1553 CONVERT(VarUI2FromR8, -1.0); EXPECT_OVERFLOW;
1554 CONVERT(VarUI2FromR8, 0.0); EXPECT(0);
1555 CONVERT(VarUI2FromR8, 1.0); EXPECT(1);
1556 CONVERT(VarUI2FromR8, 65535.0); EXPECT(65535);
1557 CONVERT(VarUI2FromR8, 65536.0); EXPECT_OVERFLOW;
1559 /* Rounding */
1560 CONVERT(VarUI2FromR8, -1.5); EXPECT_OVERFLOW;
1561 CONVERT(VarUI2FromR8, -0.6); EXPECT_OVERFLOW;
1562 CONVERT(VarUI2FromR8, -0.5); EXPECT(0);
1563 CONVERT(VarUI2FromR8, -0.4); EXPECT(0);
1564 CONVERT(VarUI2FromR8, 0.4); EXPECT(0);
1565 CONVERT(VarUI2FromR8, 0.5); EXPECT(0);
1566 CONVERT(VarUI2FromR8, 0.6); EXPECT(1);
1567 CONVERT(VarUI2FromR8, 1.5); EXPECT(2);
1570 static void test_VarUI2FromDate(void)
1572 CONVVARS(DATE);
1574 CHECKPTR(VarUI2FromDate);
1575 CONVERT(VarUI2FromDate, -1.0); EXPECT_OVERFLOW;
1576 CONVERT(VarUI2FromDate, 0.0); EXPECT(0);
1577 CONVERT(VarUI2FromDate, 1.0); EXPECT(1);
1578 CONVERT(VarUI2FromDate, 65535.0); EXPECT(65535);
1579 CONVERT(VarUI2FromDate, 65536.0); EXPECT_OVERFLOW;
1581 /* Rounding */
1582 CONVERT(VarUI2FromDate, -1.5); EXPECT_OVERFLOW;
1583 CONVERT(VarUI2FromDate, -0.6); EXPECT_OVERFLOW;
1584 CONVERT(VarUI2FromDate, -0.5); EXPECT(0);
1585 CONVERT(VarUI2FromDate, -0.4); EXPECT(0);
1586 CONVERT(VarUI2FromDate, 0.4); EXPECT(0);
1587 CONVERT(VarUI2FromDate, 0.5); EXPECT(0);
1588 CONVERT(VarUI2FromDate, 0.6); EXPECT(1);
1589 CONVERT(VarUI2FromDate, 1.5); EXPECT(2);
1592 static void test_VarUI2FromCy(void)
1594 CONVVARS(CY);
1596 CHECKPTR(VarUI2FromCy);
1597 CONVERT_CY(VarUI2FromCy,-1); EXPECT_OVERFLOW;
1598 CONVERT_CY(VarUI2FromCy,0); EXPECT(0);
1599 CONVERT_CY(VarUI2FromCy,1); EXPECT(1);
1600 CONVERT_CY(VarUI2FromCy,65535); EXPECT(65535);
1601 CONVERT_CY(VarUI2FromCy,65536); EXPECT_OVERFLOW;
1603 /* Rounding */
1604 CONVERT_CY(VarUI2FromCy,-1.5); EXPECT_OVERFLOW;
1605 CONVERT_CY(VarUI2FromCy,-0.6); EXPECT_OVERFLOW;
1606 CONVERT_CY(VarUI2FromCy,-0.5); EXPECT(0);
1607 CONVERT_CY(VarUI2FromCy,-0.4); EXPECT(0);
1608 CONVERT_CY(VarUI2FromCy,0.4); EXPECT(0);
1609 CONVERT_CY(VarUI2FromCy,0.5); EXPECT(0);
1610 CONVERT_CY(VarUI2FromCy,0.6); EXPECT(1);
1611 CONVERT_CY(VarUI2FromCy,1.5); EXPECT(2);
1614 static void test_VarUI2FromDec(void)
1616 CONVVARS(DECIMAL);
1618 CHECKPTR(VarUI2FromDec);
1620 CONVERT_BADDEC(VarUI2FromDec);
1622 CONVERT_DEC(VarUI2FromDec,0,0x80,0,1); EXPECT_OVERFLOW;
1623 CONVERT_DEC(VarUI2FromDec,0,0,0,0); EXPECT(0);
1624 CONVERT_DEC(VarUI2FromDec,0,0,0,1); EXPECT(1);
1625 CONVERT_DEC(VarUI2FromDec,0,0,0,65535); EXPECT(65535);
1626 CONVERT_DEC(VarUI2FromDec,0,0,0,65536); EXPECT_OVERFLOW;
1628 CONVERT_DEC(VarUI2FromDec,2,0x80,0,100); EXPECT_OVERFLOW;
1629 CONVERT_DEC(VarUI2FromDec,2,0,0,6553500); EXPECT(65535);
1630 CONVERT_DEC(VarUI2FromDec,2,0,0,6553600); EXPECT_OVERFLOW;
1633 static void test_VarUI2FromStr(void)
1635 CONVVARS(LCID);
1636 OLECHAR buff[128];
1638 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1640 CHECKPTR(VarUI2FromStr);
1642 CONVERT_STR(VarUI2FromStr,NULL, 0); EXPECT_MISMATCH;
1643 CONVERT_STR(VarUI2FromStr,"0", 0); EXPECT(0);
1644 CONVERT_STR(VarUI2FromStr,"-1", 0); EXPECT_OVERFLOW;
1645 CONVERT_STR(VarUI2FromStr,"65535", 0); EXPECT(65535);
1646 CONVERT_STR(VarUI2FromStr,"65536", 0); EXPECT_OVERFLOW;
1648 /* Rounding */
1649 CONVERT_STR(VarUI2FromStr,"-1.5", LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
1650 CONVERT_STR(VarUI2FromStr,"-0.6", LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
1651 CONVERT_STR(VarUI2FromStr,"-0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1652 CONVERT_STR(VarUI2FromStr,"-0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1653 CONVERT_STR(VarUI2FromStr,"0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1654 CONVERT_STR(VarUI2FromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1655 CONVERT_STR(VarUI2FromStr,"0.6", LOCALE_NOUSEROVERRIDE); EXPECT(1);
1656 CONVERT_STR(VarUI2FromStr,"1.5", LOCALE_NOUSEROVERRIDE); EXPECT(2);
1659 static void test_VarUI2Copy(void)
1661 COPYTEST(1, VT_UI2, V_UI2(&vSrc), V_UI2(&vDst), V_UI2REF(&vSrc), V_UI2REF(&vDst), "%d");
1664 static void test_VarUI2ChangeTypeEx(void)
1666 HRESULT hres;
1667 USHORT in;
1668 VARIANTARG vSrc, vDst;
1670 in = 1;
1672 INITIAL_TYPETEST(VT_UI2, V_UI2, "%d");
1673 COMMON_TYPETEST;
1674 NEGATIVE_TYPETEST(VT_UI2, V_UI2, "%d", VT_I2, V_I2);
1678 * VT_I4/VT_UI4
1681 #undef CONV_TYPE
1682 #define CONV_TYPE LONG
1684 static void test_VarI4FromI1(void)
1686 CONVVARS(signed char);
1687 int i;
1689 CHECKPTR(VarI4FromI1);
1690 CONVERTRANGE(VarI4FromI1, -128, 128);
1693 static void test_VarI4FromI2(void)
1695 CONVVARS(SHORT);
1696 int i;
1698 CHECKPTR(VarI4FromI2);
1699 CONVERTRANGE(VarI4FromI2, -32768, 32768);
1702 static void test_VarI4FromI8(void)
1704 CONVVARS(LONG64);
1706 CHECKPTR(VarI4FromI8);
1707 CHECKPTR(VarI4FromDec);
1709 CONVERT(VarI4FromI8, -1); EXPECT(-1);
1710 CONVERT(VarI4FromI8, 0); EXPECT(0);
1711 CONVERT(VarI4FromI8, 1); EXPECT(1);
1713 CONVERT_I8(VarI4FromI8, -1, 2147483647ul); EXPECT_OVERFLOW;
1714 CONVERT_I8(VarI4FromI8, -1, 2147483648ul); EXPECT(-2147483647 - 1);
1715 CONVERT_I8(VarI4FromI8, 0, 2147483647ul); EXPECT(2147483647);
1716 CONVERT_I8(VarI4FromI8, 0, 2147483648ul); EXPECT_OVERFLOW;
1719 static void test_VarI4FromUI1(void)
1721 CONVVARS(BYTE);
1722 int i;
1724 CHECKPTR(VarI4FromUI1);
1725 CONVERTRANGE(VarI4FromUI1, 0, 256);
1728 static void test_VarI4FromUI2(void)
1730 CONVVARS(USHORT);
1731 int i;
1733 CHECKPTR(VarI4FromUI2);
1734 CONVERTRANGE(VarI4FromUI2, 0, 65536);
1737 static void test_VarI4FromUI4(void)
1739 CONVVARS(ULONG);
1741 CHECKPTR(VarI4FromUI4);
1742 CONVERT(VarI4FromUI4, 0); EXPECT(0);
1743 CONVERT(VarI4FromUI4, 1); EXPECT(1);
1744 CONVERT(VarI4FromUI4, 2147483647); EXPECT(2147483647);
1745 CONVERT(VarI4FromUI4, 2147483648ul); EXPECT_OVERFLOW;
1748 static void test_VarI4FromUI8(void)
1750 CONVVARS(ULONG64);
1752 CHECKPTR(VarI4FromUI8);
1753 CONVERT(VarI4FromUI8, 0); EXPECT(0);
1754 CONVERT(VarI4FromUI8, 1); EXPECT(1);
1755 CONVERT(VarI4FromUI8, 2147483647); EXPECT(2147483647);
1756 CONVERT(VarI4FromUI8, 2147483648ul); EXPECT_OVERFLOW;
1759 static void test_VarI4FromBool(void)
1761 CONVVARS(VARIANT_BOOL);
1762 int i;
1764 CHECKPTR(VarI4FromBool);
1765 CONVERTRANGE(VarI4FromBool, -32768, 32768);
1768 static void test_VarI4FromR4(void)
1770 CONVVARS(FLOAT);
1772 CHECKPTR(VarI4FromR4);
1774 /* min/max values are not exactly representable in a float */
1775 CONVERT(VarI4FromR4, -1.0f); EXPECT(-1);
1776 CONVERT(VarI4FromR4, 0.0f); EXPECT(0);
1777 CONVERT(VarI4FromR4, 1.0f); EXPECT(1);
1779 CONVERT(VarI4FromR4, -1.5f); EXPECT(-2);
1780 CONVERT(VarI4FromR4, -0.6f); EXPECT(-1);
1781 CONVERT(VarI4FromR4, -0.5f); EXPECT(0);
1782 CONVERT(VarI4FromR4, -0.4f); EXPECT(0);
1783 CONVERT(VarI4FromR4, 0.4f); EXPECT(0);
1784 CONVERT(VarI4FromR4, 0.5f); EXPECT(0);
1785 CONVERT(VarI4FromR4, 0.6f); EXPECT(1);
1786 CONVERT(VarI4FromR4, 1.5f); EXPECT(2);
1789 static void test_VarI4FromR8(void)
1791 CONVVARS(DOUBLE);
1793 CHECKPTR(VarI4FromR8);
1794 CONVERT(VarI4FromR8, -2147483649.0); EXPECT_OVERFLOW;
1795 CONVERT(VarI4FromR8, -2147483648.0); EXPECT(-2147483647 - 1);
1796 CONVERT(VarI4FromR8, -1.0); EXPECT(-1);
1797 CONVERT(VarI4FromR8, 0.0); EXPECT(0);
1798 CONVERT(VarI4FromR8, 1.0); EXPECT(1);
1799 CONVERT(VarI4FromR8, 2147483647.0); EXPECT(2147483647);
1800 CONVERT(VarI4FromR8, 2147483648.0); EXPECT_OVERFLOW;
1802 CONVERT(VarI4FromR8, -1.5); EXPECT(-2);
1803 CONVERT(VarI4FromR8, -0.6); EXPECT(-1);
1804 CONVERT(VarI4FromR8, -0.5); EXPECT(0);
1805 CONVERT(VarI4FromR8, -0.4); EXPECT(0);
1806 CONVERT(VarI4FromR8, 0.4); EXPECT(0);
1807 CONVERT(VarI4FromR8, 0.5); EXPECT(0);
1808 CONVERT(VarI4FromR8, 0.6); EXPECT(1);
1809 CONVERT(VarI4FromR8, 1.5); EXPECT(2);
1812 static void test_VarI4FromDate(void)
1814 CONVVARS(DATE);
1816 CHECKPTR(VarI4FromDate);
1817 CONVERT(VarI4FromDate, -2147483649.0); EXPECT_OVERFLOW;
1818 CONVERT(VarI4FromDate, -2147483648.0); EXPECT(-2147483647 - 1);
1819 CONVERT(VarI4FromDate, -1.0); EXPECT(-1);
1820 CONVERT(VarI4FromDate, 0.0); EXPECT(0);
1821 CONVERT(VarI4FromDate, 1.0); EXPECT(1);
1822 CONVERT(VarI4FromDate, 2147483647.0); EXPECT(2147483647);
1823 CONVERT(VarI4FromDate, 2147483648.0); EXPECT_OVERFLOW;
1825 CONVERT(VarI4FromDate, -1.5); EXPECT(-2);
1826 CONVERT(VarI4FromDate, -0.6); EXPECT(-1);
1827 CONVERT(VarI4FromDate, -0.5); EXPECT(0);
1828 CONVERT(VarI4FromDate, -0.4); EXPECT(0);
1829 CONVERT(VarI4FromDate, 0.4); EXPECT(0);
1830 CONVERT(VarI4FromDate, 0.5); EXPECT(0);
1831 CONVERT(VarI4FromDate, 0.6); EXPECT(1);
1832 CONVERT(VarI4FromDate, 1.5); EXPECT(2);
1835 static void test_VarI4FromCy(void)
1837 CONVVARS(CY);
1839 CHECKPTR(VarI4FromCy);
1840 CONVERT_CY(VarI4FromCy,-1); EXPECT(-1);
1841 CONVERT_CY(VarI4FromCy,0); EXPECT(0);
1842 CONVERT_CY(VarI4FromCy,1); EXPECT(1);
1844 CONVERT_CY64(VarI4FromCy,-1,2147483647ul); EXPECT_OVERFLOW;
1845 CONVERT_CY64(VarI4FromCy,-1,2147483648ul); EXPECT(-2147483647 - 1);
1846 CONVERT_CY64(VarI4FromCy,0,2147483647ul); EXPECT(2147483647ul);
1847 CONVERT_CY64(VarI4FromCy,0,2147483648ul); EXPECT_OVERFLOW;
1849 CONVERT_CY(VarI4FromCy,-1.5); EXPECT(-2);
1850 CONVERT_CY(VarI4FromCy,-0.6); EXPECT(-1);
1851 CONVERT_CY(VarI4FromCy,-0.5); EXPECT(0);
1852 CONVERT_CY(VarI4FromCy,-0.4); EXPECT(0);
1853 CONVERT_CY(VarI4FromCy,0.4); EXPECT(0);
1854 CONVERT_CY(VarI4FromCy,0.5); EXPECT(0);
1855 CONVERT_CY(VarI4FromCy,0.6); EXPECT(1);
1856 CONVERT_CY(VarI4FromCy,1.5); EXPECT(2);
1859 static void test_VarI4FromDec(void)
1861 CONVVARS(DECIMAL);
1863 CHECKPTR(VarI4FromDec);
1865 CONVERT_BADDEC(VarI4FromDec);
1867 CONVERT_DEC(VarI4FromDec,0,0x80,0,1); EXPECT(-1);
1868 CONVERT_DEC(VarI4FromDec,0,0,0,0); EXPECT(0);
1869 CONVERT_DEC(VarI4FromDec,0,0,0,1); EXPECT(1);
1871 CONVERT_DEC64(VarI4FromDec,0,0x80,0,0,2147483649ul); EXPECT_OVERFLOW;
1872 CONVERT_DEC64(VarI4FromDec,0,0x80,0,0,2147483648ul); EXPECT(-2147483647 - 1);
1873 CONVERT_DEC64(VarI4FromDec,0,0,0,0,2147483647ul); EXPECT(2147483647ul);
1874 CONVERT_DEC64(VarI4FromDec,0,0,0,0,2147483648ul); EXPECT_OVERFLOW;
1876 CONVERT_DEC64(VarI4FromDec,2,0x80,0,50,100); EXPECT_OVERFLOW;
1877 CONVERT_DEC64(VarI4FromDec,2,0x80,0,50,0); EXPECT(-2147483647 - 1);
1878 CONVERT_DEC64(VarI4FromDec,2,0,0,49,4294967196ul); EXPECT(2147483647);
1879 CONVERT_DEC64(VarI4FromDec,2,0,0,50,0); EXPECT_OVERFLOW;
1882 static void test_VarI4FromStr(void)
1884 CONVVARS(LCID);
1885 OLECHAR buff[128];
1887 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1889 CHECKPTR(VarI4FromStr);
1891 CONVERT_STR(VarI4FromStr,NULL,0); EXPECT_MISMATCH;
1892 CONVERT_STR(VarI4FromStr,"0",0); EXPECT(0);
1893 CONVERT_STR(VarI4FromStr,"-2147483649",0); EXPECT_OVERFLOW;
1894 CONVERT_STR(VarI4FromStr,"-2147483648",0); EXPECT(-2147483647 -1);
1895 CONVERT_STR(VarI4FromStr,"2147483647",0); EXPECT(2147483647);
1896 CONVERT_STR(VarI4FromStr,"2147483648",0); EXPECT_OVERFLOW;
1898 /* Rounding */
1899 CONVERT_STR(VarI4FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECT(-2);
1900 CONVERT_STR(VarI4FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECT(-1);
1901 CONVERT_STR(VarI4FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0);
1902 CONVERT_STR(VarI4FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0);
1903 CONVERT_STR(VarI4FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0);
1904 CONVERT_STR(VarI4FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0);
1905 CONVERT_STR(VarI4FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECT(1);
1906 CONVERT_STR(VarI4FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECT(2);
1909 static void test_VarI4Copy(void)
1911 COPYTEST(1, VT_I4, V_I4(&vSrc), V_I4(&vDst), V_I4REF(&vSrc), V_I4REF(&vDst), "%d");
1914 static void test_VarI4ChangeTypeEx(void)
1916 HRESULT hres;
1917 LONG in;
1918 VARIANTARG vSrc, vDst;
1920 in = 1;
1922 INITIAL_TYPETEST(VT_I4, V_I4, "%d");
1923 COMMON_TYPETEST;
1924 NEGATIVE_TYPETEST(VT_I4, V_I4, "%d", VT_UI4, V_UI4);
1927 #undef CONV_TYPE
1928 #define CONV_TYPE ULONG
1929 #undef EXPECTRES
1930 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%u")
1932 static void test_VarUI4FromI1(void)
1934 CONVVARS(signed char);
1935 int i;
1937 CHECKPTR(VarUI4FromI1);
1938 OVERFLOWRANGE(VarUI4FromI1, -127, 0);
1939 CONVERTRANGE(VarUI4FromI1, 0, 128);
1942 static void test_VarUI4FromI2(void)
1944 CONVVARS(SHORT);
1945 int i;
1947 CHECKPTR(VarUI4FromI2);
1948 OVERFLOWRANGE(VarUI4FromI2, -32768, 0);
1949 CONVERTRANGE(VarUI4FromI2, 0, 32768);
1952 static void test_VarUI4FromUI2(void)
1954 CONVVARS(USHORT);
1955 int i;
1957 CHECKPTR(VarUI4FromUI2);
1958 CONVERTRANGE(VarUI4FromUI2, 0, 65536);
1961 static void test_VarUI4FromI8(void)
1963 CONVVARS(LONG64);
1965 CHECKPTR(VarUI4FromI8);
1966 CONVERT(VarUI4FromI8, -1); EXPECT_OVERFLOW;
1967 CONVERT(VarUI4FromI8, 0); EXPECT(0);
1968 CONVERT(VarUI4FromI8, 1); EXPECT(1);
1969 CONVERT(VarUI4FromI8, 4294967295ul); EXPECT(4294967295ul);
1970 CONVERT_I8(VarUI4FromI8, 1, 0); EXPECT_OVERFLOW;
1973 static void test_VarUI4FromUI1(void)
1975 CONVVARS(BYTE);
1976 int i;
1978 CHECKPTR(VarUI4FromUI1);
1979 CONVERTRANGE(VarUI4FromUI1, 0, 256);
1982 static void test_VarUI4FromI4(void)
1984 CONVVARS(int);
1986 CHECKPTR(VarUI4FromI4);
1987 CONVERT(VarUI4FromI4, -1); EXPECT_OVERFLOW;
1988 CONVERT(VarUI4FromI4, 0); EXPECT(0);
1989 CONVERT(VarUI4FromI4, 1); EXPECT(1);
1990 CONVERT(VarUI4FromI4, 2147483647); EXPECT(2147483647);
1993 static void test_VarUI4FromUI8(void)
1995 CONVVARS(ULONG64);
1997 CHECKPTR(VarUI4FromUI8);
1998 CONVERT(VarUI4FromUI8, 0); EXPECT(0);
1999 CONVERT(VarUI4FromUI8, 1); EXPECT(1);
2000 CONVERT(VarUI4FromI8, 4294967295ul); EXPECT(4294967295ul);
2001 CONVERT_I8(VarUI4FromI8, 1, 0); EXPECT_OVERFLOW;
2004 static void test_VarUI4FromBool(void)
2006 CONVVARS(VARIANT_BOOL);
2007 int i;
2009 CHECKPTR(VarUI4FromBool);
2010 CONVERTRANGE(VarUI4FromBool, -32768, 32768);
2013 static void test_VarUI4FromR4(void)
2015 CONVVARS(FLOAT);
2017 CHECKPTR(VarUI4FromR4);
2018 /* We can't test max values as they are not exactly representable in a float */
2019 CONVERT(VarUI4FromR4, -1.0f); EXPECT_OVERFLOW;
2020 CONVERT(VarUI4FromR4, 0.0f); EXPECT(0);
2021 CONVERT(VarUI4FromR4, 1.0f); EXPECT(1);
2023 CONVERT(VarUI4FromR4, -1.5f); EXPECT_OVERFLOW;
2024 CONVERT(VarUI4FromR4, -0.6f); EXPECT_OVERFLOW;
2025 CONVERT(VarUI4FromR4, -0.5f); EXPECT(0);
2026 CONVERT(VarUI4FromR4, -0.4f); EXPECT(0);
2027 CONVERT(VarUI4FromR4, 0.4f); EXPECT(0);
2028 CONVERT(VarUI4FromR4, 0.5f); EXPECT(0);
2029 CONVERT(VarUI4FromR4, 0.6f); EXPECT(1);
2030 CONVERT(VarUI4FromR4, 1.5f); EXPECT(2);
2034 static void test_VarUI4FromR8(void)
2036 CONVVARS(DOUBLE);
2038 CHECKPTR(VarUI4FromR8);
2039 CONVERT(VarUI4FromR8, -1.0); EXPECT_OVERFLOW;
2040 CONVERT(VarUI4FromR8, 0.0); EXPECT(0);
2041 CONVERT(VarUI4FromR8, 1.0); EXPECT(1);
2042 CONVERT(VarUI4FromR8, 4294967295.0); EXPECT(4294967295ul);
2043 CONVERT(VarUI4FromR8, 4294967296.0); EXPECT_OVERFLOW;
2045 CONVERT(VarUI4FromR8, -1.5); EXPECT_OVERFLOW;
2046 CONVERT(VarUI4FromR8, -0.6); EXPECT_OVERFLOW;
2047 CONVERT(VarUI4FromR8, -0.5); EXPECT(0);
2048 CONVERT(VarUI4FromR8, -0.4); EXPECT(0);
2049 CONVERT(VarUI4FromR8, 0.4); EXPECT(0);
2050 CONVERT(VarUI4FromR8, 0.5); EXPECT(0);
2051 CONVERT(VarUI4FromR8, 0.6); EXPECT(1);
2052 CONVERT(VarUI4FromR8, 1.5); EXPECT(2);
2055 static void test_VarUI4FromDate(void)
2057 CONVVARS(DOUBLE);
2059 CHECKPTR(VarUI4FromDate);
2060 CONVERT(VarUI4FromDate, -1.0); EXPECT_OVERFLOW;
2061 CONVERT(VarUI4FromDate, 0.0); EXPECT(0);
2062 CONVERT(VarUI4FromDate, 1.0); EXPECT(1);
2063 CONVERT(VarUI4FromDate, 4294967295.0); EXPECT(4294967295ul);
2064 CONVERT(VarUI4FromDate, 4294967296.0); EXPECT_OVERFLOW;
2066 CONVERT(VarUI4FromDate, -1.5); EXPECT_OVERFLOW;
2067 CONVERT(VarUI4FromDate, -0.6); EXPECT_OVERFLOW;
2068 CONVERT(VarUI4FromDate, -0.5); EXPECT(0);
2069 CONVERT(VarUI4FromDate, -0.4); EXPECT(0);
2070 CONVERT(VarUI4FromDate, 0.4); EXPECT(0);
2071 CONVERT(VarUI4FromDate, 0.5); EXPECT(0);
2072 CONVERT(VarUI4FromDate, 0.6); EXPECT(1);
2073 CONVERT(VarUI4FromDate, 1.5); EXPECT(2);
2076 static void test_VarUI4FromCy(void)
2078 CONVVARS(CY);
2080 CHECKPTR(VarUI4FromCy);
2081 CONVERT_CY(VarUI4FromCy,-1); EXPECT_OVERFLOW;
2082 CONVERT_CY(VarUI4FromCy,0); EXPECT(0);
2083 CONVERT_CY(VarUI4FromCy,1); EXPECT(1);
2084 CONVERT_CY64(VarUI4FromCy,0,4294967295ul); EXPECT(4294967295ul);
2085 CONVERT_CY64(VarUI4FromCy,1,0); EXPECT_OVERFLOW;
2087 CONVERT_CY(VarUI4FromCy,-1.5); EXPECT_OVERFLOW;
2088 CONVERT_CY(VarUI4FromCy,-0.6); EXPECT_OVERFLOW;
2089 CONVERT_CY(VarUI4FromCy,-0.5); EXPECT(0);
2090 CONVERT_CY(VarUI4FromCy,-0.4); EXPECT(0);
2091 CONVERT_CY(VarUI4FromCy,0.4); EXPECT(0);
2092 CONVERT_CY(VarUI4FromCy,0.5); EXPECT(0);
2093 CONVERT_CY(VarUI4FromCy,0.6); EXPECT(1);
2094 CONVERT_CY(VarUI4FromCy,1.5); EXPECT(2);
2097 static void test_VarUI4FromDec(void)
2099 CONVVARS(DECIMAL);
2101 CHECKPTR(VarUI4FromDec);
2103 CONVERT_BADDEC(VarUI4FromDec);
2105 CONVERT_DEC(VarUI4FromDec,0,0x80,0,1); EXPECT_OVERFLOW;
2106 CONVERT_DEC(VarUI4FromDec,0,0,0,0); EXPECT(0);
2107 CONVERT_DEC(VarUI4FromDec,0,0,0,1); EXPECT(1);
2108 CONVERT_DEC64(VarUI4FromDec,0,0,0,0,4294967295ul); EXPECT(4294967295ul);
2109 CONVERT_DEC64(VarUI4FromDec,0,0,0,1,0); EXPECT_OVERFLOW;
2111 CONVERT_DEC64(VarUI4FromDec,2,0,0,99,4294967196ul); EXPECT(4294967295ul);
2112 CONVERT_DEC64(VarUI4FromDec,2,0,0,100,0); EXPECT_OVERFLOW;
2115 static void test_VarUI4FromStr(void)
2117 CONVVARS(LCID);
2118 OLECHAR buff[128];
2120 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2122 CHECKPTR(VarUI4FromStr);
2124 CONVERT_STR(VarUI4FromStr,NULL,0); EXPECT_MISMATCH;
2125 CONVERT_STR(VarUI4FromStr,"-1",0); EXPECT_OVERFLOW;
2126 CONVERT_STR(VarUI4FromStr,"0",0); EXPECT(0);
2127 CONVERT_STR(VarUI4FromStr,"4294967295",0); EXPECT(4294967295ul);
2128 CONVERT_STR(VarUI4FromStr,"4294967296",0); EXPECT_OVERFLOW;
2130 /* Rounding */
2131 CONVERT_STR(VarUI4FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
2132 CONVERT_STR(VarUI4FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
2133 CONVERT_STR(VarUI4FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0);
2134 CONVERT_STR(VarUI4FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0);
2135 CONVERT_STR(VarUI4FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0);
2136 CONVERT_STR(VarUI4FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0);
2137 CONVERT_STR(VarUI4FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECT(1);
2138 CONVERT_STR(VarUI4FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECT(2);
2141 static void test_VarUI4Copy(void)
2143 COPYTEST(1u, VT_UI4, V_UI4(&vSrc), V_UI4(&vDst), V_UI4REF(&vSrc), V_UI4REF(&vDst), "%u");
2146 static void test_VarUI4ChangeTypeEx(void)
2148 HRESULT hres;
2149 ULONG in;
2150 VARIANTARG vSrc, vDst;
2152 in = 1;
2154 INITIAL_TYPETEST(VT_UI4, V_UI4, "%u");
2155 COMMON_TYPETEST;
2156 NEGATIVE_TYPETEST(VT_UI4, V_UI4, "%u", VT_I4, V_I4);
2160 * VT_I8/VT_UI8
2163 #undef CONV_TYPE
2164 #define CONV_TYPE LONG64
2166 #define EXPECTI8(x) \
2167 ok((hres == S_OK && out == (CONV_TYPE)(x)), \
2168 "expected " #x "(%u,%u), got (%u,%u); hres=0x%08x\n", \
2169 (ULONG)((LONG64)(x) >> 32), (ULONG)((x) & 0xffffffff), \
2170 (ULONG)(out >> 32), (ULONG)(out & 0xffffffff), hres)
2172 #define EXPECTI864(x,y) \
2173 ok(hres == S_OK && (out >> 32) == (CONV_TYPE)(x) && (out & 0xffffffff) == (CONV_TYPE)(y), \
2174 "expected " #x "(%u,%u), got (%u,%u); hres=0x%08x\n", \
2175 (ULONG)(x), (ULONG)(y), \
2176 (ULONG)(out >> 32), (ULONG)(out & 0xffffffff), hres)
2178 static void test_VarI8FromI1(void)
2180 CONVVARS(signed char);
2181 int i;
2183 CHECKPTR(VarI8FromI1);
2184 for (i = -128; i < 128; i++)
2186 CONVERT(VarI8FromI1,i); EXPECTI8(i);
2190 static void test_VarI8FromUI1(void)
2192 CONVVARS(BYTE);
2193 int i;
2195 CHECKPTR(VarI8FromUI1);
2196 for (i = 0; i < 256; i++)
2198 CONVERT(VarI8FromUI1,i); EXPECTI8(i);
2202 static void test_VarI8FromI2(void)
2204 CONVVARS(SHORT);
2205 int i;
2207 CHECKPTR(VarI8FromI2);
2208 for (i = -32768; i < 32768; i++)
2210 CONVERT(VarI8FromI2,i); EXPECTI8(i);
2214 static void test_VarI8FromUI2(void)
2216 CONVVARS(USHORT);
2217 int i;
2219 CHECKPTR(VarI8FromUI2);
2220 for (i = -0; i < 65535; i++)
2222 CONVERT(VarI8FromUI2,i); EXPECTI8(i);
2226 static void test_VarI8FromUI4(void)
2228 CONVVARS(ULONG);
2230 CHECKPTR(VarI8FromUI4);
2231 CONVERT(VarI8FromUI4, 0); EXPECTI8(0);
2232 CONVERT(VarI8FromUI4, 1); EXPECTI8(1);
2233 CONVERT(VarI8FromUI4, 4294967295ul); EXPECTI8(4294967295ul);
2236 static void test_VarI8FromR4(void)
2238 CONVVARS(FLOAT);
2240 CHECKPTR(VarI8FromR4);
2242 CONVERT(VarI8FromR4, -128.0f); EXPECTI8(-128);
2243 CONVERT(VarI8FromR4, -1.0f); EXPECTI8(-1);
2244 CONVERT(VarI8FromR4, 0.0f); EXPECTI8(0);
2245 CONVERT(VarI8FromR4, 1.0f); EXPECTI8(1);
2246 CONVERT(VarI8FromR4, 127.0f); EXPECTI8(127);
2248 CONVERT(VarI8FromR4, -1.5f); EXPECTI8(-2);
2249 CONVERT(VarI8FromR4, -0.6f); EXPECTI8(-1);
2250 CONVERT(VarI8FromR4, -0.5f); EXPECTI8(0);
2251 CONVERT(VarI8FromR4, -0.4f); EXPECTI8(0);
2252 CONVERT(VarI8FromR4, 0.4f); EXPECTI8(0);
2253 CONVERT(VarI8FromR4, 0.5f); EXPECTI8(0);
2254 CONVERT(VarI8FromR4, 0.6f); EXPECTI8(1);
2255 CONVERT(VarI8FromR4, 1.5f); EXPECTI8(2);
2258 static void test_VarI8FromR8(void)
2260 CONVVARS(DOUBLE);
2262 CHECKPTR(VarI8FromR8);
2263 CONVERT(VarI8FromR8, -128.0); EXPECTI8(-128);
2264 CONVERT(VarI8FromR8, -1.0); EXPECTI8(-1);
2265 CONVERT(VarI8FromR8, 0.0); EXPECTI8(0);
2266 CONVERT(VarI8FromR8, 1.0); EXPECTI8(1);
2267 CONVERT(VarI8FromR8, 127.0); EXPECTI8(127);
2269 CONVERT(VarI8FromR8, -1.5); EXPECTI8(-2);
2270 CONVERT(VarI8FromR8, -0.6); EXPECTI8(-1);
2271 CONVERT(VarI8FromR8, -0.5); EXPECTI8(0);
2272 CONVERT(VarI8FromR8, -0.4); EXPECTI8(0);
2273 CONVERT(VarI8FromR8, 0.4); EXPECTI8(0);
2274 CONVERT(VarI8FromR8, 0.5); EXPECTI8(0);
2275 CONVERT(VarI8FromR8, 0.6); EXPECTI8(1);
2276 CONVERT(VarI8FromR8, 1.5); EXPECTI8(2);
2279 static void test_VarI8FromDate(void)
2281 CONVVARS(DATE);
2283 CHECKPTR(VarI8FromDate);
2284 CONVERT(VarI8FromDate, -128.0); EXPECTI8(-128);
2285 CONVERT(VarI8FromDate, -1.0); EXPECTI8(-1);
2286 CONVERT(VarI8FromDate, 0.0); EXPECTI8(0);
2287 CONVERT(VarI8FromDate, 1.0); EXPECTI8(1);
2288 CONVERT(VarI8FromDate, 127.0); EXPECTI8(127);
2290 CONVERT(VarI8FromDate, -1.5); EXPECTI8(-2);
2291 CONVERT(VarI8FromDate, -0.6); EXPECTI8(-1);
2292 CONVERT(VarI8FromDate, -0.5); EXPECTI8(0);
2293 CONVERT(VarI8FromDate, -0.4); EXPECTI8(0);
2294 CONVERT(VarI8FromDate, 0.4); EXPECTI8(0);
2295 CONVERT(VarI8FromDate, 0.5); EXPECTI8(0);
2296 CONVERT(VarI8FromDate, 0.6); EXPECTI8(1);
2297 CONVERT(VarI8FromDate, 1.5); EXPECTI8(2);
2300 static void test_VarI8FromBool(void)
2302 CONVVARS(VARIANT_BOOL);
2303 int i;
2305 CHECKPTR(VarI8FromBool);
2306 for (i = -32768; i < 32768; i++)
2308 CONVERT(VarI8FromBool,i); EXPECTI8(i);
2312 static void test_VarI8FromUI8(void)
2314 CONVVARS(ULONG64);
2316 CHECKPTR(VarI8FromUI8);
2317 CONVERT(VarI8FromUI8, 0); EXPECTI8(0);
2318 CONVERT(VarI8FromUI8, 1); EXPECTI8(1);
2319 CONVERT_I8(VarI8FromUI8, 0x7fffffff, 0xffffffff); EXPECTI864(0x7fffffff, 0xffffffff);
2320 CONVERT_I8(VarI8FromUI8, 0x80000000, 0); EXPECT_OVERFLOW;
2323 static void test_VarI8FromCy(void)
2325 CONVVARS(CY);
2327 CHECKPTR(VarI8FromCy);
2328 CONVERT_CY(VarI8FromCy,-128); EXPECTI8(-129);
2329 CONVERT_CY(VarI8FromCy,-1); EXPECTI8(-2);
2330 CONVERT_CY(VarI8FromCy,0); EXPECTI8(0);
2331 CONVERT_CY(VarI8FromCy,1); EXPECTI8(1);
2332 CONVERT_CY(VarI8FromCy,127); EXPECTI8(127);
2334 CONVERT_CY(VarI8FromCy,-1.5); EXPECTI8(-2);
2335 CONVERT_CY(VarI8FromCy,-0.6); EXPECTI8(-1);
2336 CONVERT_CY(VarI8FromCy,-0.5); EXPECTI8(-1);
2337 CONVERT_CY(VarI8FromCy,-0.4); EXPECTI8(-1);
2338 CONVERT_CY(VarI8FromCy,0.4); EXPECTI8(0);
2339 CONVERT_CY(VarI8FromCy,0.5); EXPECTI8(0);
2340 CONVERT_CY(VarI8FromCy,0.6); EXPECTI8(1);
2341 CONVERT_CY(VarI8FromCy,1.5); EXPECTI8(2);
2344 static void test_VarI8FromDec(void)
2346 CONVVARS(DECIMAL);
2348 CHECKPTR(VarI8FromDec);
2350 CONVERT_BADDEC(VarI8FromDec);
2352 CONVERT_DEC(VarI8FromDec,0,0x80,0,128); EXPECTI8(-128);
2353 CONVERT_DEC(VarI8FromDec,0,0x80,0,1); EXPECTI8(-1);
2354 CONVERT_DEC(VarI8FromDec,0,0,0,0); EXPECTI8(0);
2355 CONVERT_DEC(VarI8FromDec,0,0,0,1); EXPECTI8(1);
2356 CONVERT_DEC(VarI8FromDec,0,0,0,127); EXPECTI8(127);
2358 CONVERT_DEC(VarI8FromDec,2,0x80,0,12700); EXPECTI8(-127);
2359 CONVERT_DEC(VarI8FromDec,2,0,0,12700); EXPECTI8(127);
2362 static void test_VarI8FromStr(void)
2364 CONVVARS(LCID);
2365 OLECHAR buff[128];
2367 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2369 CHECKPTR(VarI8FromStr);
2371 CONVERT_STR(VarI8FromStr,NULL,0); EXPECT_MISMATCH;
2372 CONVERT_STR(VarI8FromStr,"0",0); EXPECTI8(0);
2373 CONVERT_STR(VarI8FromStr,"-1",0); EXPECTI8(-1);
2374 CONVERT_STR(VarI8FromStr,"2147483647",0); EXPECTI8(2147483647);
2376 CONVERT_STR(VarI8FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(-2);
2377 CONVERT_STR(VarI8FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECTI8(-1);
2378 CONVERT_STR(VarI8FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2379 CONVERT_STR(VarI8FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2380 CONVERT_STR(VarI8FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2381 CONVERT_STR(VarI8FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2382 CONVERT_STR(VarI8FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECTI8(1);
2383 CONVERT_STR(VarI8FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(2);
2386 static void test_VarI8Copy(void)
2388 HRESULT hres;
2389 VARIANTARG vSrc, vDst;
2390 LONGLONG in = 1;
2392 if (!has_i8)
2394 win_skip("I8 and UI8 data types are not available\n");
2395 return;
2398 VariantInit(&vSrc);
2399 VariantInit(&vDst);
2400 V_VT(&vSrc) = VT_I8;
2401 V_I8(&vSrc) = in;
2402 hres = VariantCopy(&vDst, &vSrc);
2403 ok(hres == S_OK && V_VT(&vDst) == VT_I8 && V_I8(&vDst) == in,
2404 "copy hres 0x%X, type %d, value (%x%08x) %x%08x\n",
2405 hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_I8(&vDst) >> 32), (UINT)V_I8(&vDst) );
2406 V_VT(&vSrc) = VT_I8|VT_BYREF;
2407 V_I8REF(&vSrc) = &in;
2408 hres = VariantCopy(&vDst, &vSrc);
2409 ok(hres == S_OK && V_VT(&vDst) == (VT_I8|VT_BYREF) && V_I8REF(&vDst) == &in,
2410 "ref hres 0x%X, type %d, ref (%p) %p\n", hres, V_VT(&vDst), &in, V_I8REF(&vDst));
2411 hres = VariantCopyInd(&vDst, &vSrc);
2412 ok(hres == S_OK && V_VT(&vDst) == VT_I8 && V_I8(&vDst) == in,
2413 "copy hres 0x%X, type %d, value (%x%08x) %x%08x\n",
2414 hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_I8(&vDst) >> 32), (UINT)V_I8(&vDst) );
2417 static void test_VarI8ChangeTypeEx(void)
2419 HRESULT hres;
2420 LONG64 in;
2421 VARIANTARG vSrc, vDst;
2423 if (!has_i8)
2425 win_skip("I8 and UI8 data types are not available\n");
2426 return;
2429 in = 1;
2431 INITIAL_TYPETESTI8(VT_I8, V_I8);
2432 COMMON_TYPETEST;
2435 /* Adapt the test macros to UI8 */
2436 #undef CONV_TYPE
2437 #define CONV_TYPE ULONG64
2439 static void test_VarUI8FromI1(void)
2441 CONVVARS(signed char);
2442 int i;
2444 CHECKPTR(VarUI8FromI1);
2445 for (i = -128; i < 128; i++)
2447 CONVERT(VarUI8FromI1,i);
2448 if (i < 0)
2449 EXPECT_OVERFLOW;
2450 else
2451 EXPECTI8(i);
2455 static void test_VarUI8FromUI1(void)
2457 CONVVARS(BYTE);
2458 int i;
2460 CHECKPTR(VarUI8FromUI1);
2461 for (i = 0; i < 256; i++)
2463 CONVERT(VarUI8FromUI1,i); EXPECTI8(i);
2467 static void test_VarUI8FromI2(void)
2469 CONVVARS(SHORT);
2470 int i;
2472 CHECKPTR(VarUI8FromI2);
2473 for (i = -32768; i < 32768; i++)
2475 CONVERT(VarUI8FromI2,i);
2476 if (i < 0)
2477 EXPECT_OVERFLOW;
2478 else
2479 EXPECTI8(i);
2483 static void test_VarUI8FromUI2(void)
2485 CONVVARS(USHORT);
2486 int i;
2488 CHECKPTR(VarUI8FromUI2);
2489 for (i = 0; i < 65535; i++)
2491 CONVERT(VarUI8FromUI2,i); EXPECTI8(i);
2495 static void test_VarUI8FromUI4(void)
2497 CONVVARS(ULONG);
2499 CHECKPTR(VarUI8FromUI4);
2500 CONVERT(VarUI8FromUI4, 0); EXPECTI8(0);
2501 CONVERT(VarUI8FromUI4, 0xffffffff); EXPECTI8(0xffffffff);
2504 static void test_VarUI8FromR4(void)
2506 CONVVARS(FLOAT);
2508 CHECKPTR(VarUI8FromR4);
2509 CONVERT(VarUI8FromR4, -1.0f); EXPECT_OVERFLOW;
2510 CONVERT(VarUI8FromR4, 0.0f); EXPECTI8(0);
2511 CONVERT(VarUI8FromR4, 1.0f); EXPECTI8(1);
2512 CONVERT(VarUI8FromR4, 255.0f); EXPECTI8(255);
2514 CONVERT(VarUI8FromR4, -1.5f); EXPECT_OVERFLOW;
2515 CONVERT(VarUI8FromR4, -0.6f); EXPECT_OVERFLOW;
2516 CONVERT(VarUI8FromR4, -0.5f); EXPECTI8(0);
2517 CONVERT(VarUI8FromR4, -0.4f); EXPECTI8(0);
2518 CONVERT(VarUI8FromR4, 0.4f); EXPECTI8(0);
2519 CONVERT(VarUI8FromR4, 0.5f); EXPECTI8(0);
2520 CONVERT(VarUI8FromR4, 0.6f); EXPECTI8(1);
2521 CONVERT(VarUI8FromR4, 1.5f); EXPECTI8(2);
2524 static void test_VarUI8FromR8(void)
2526 CONVVARS(DOUBLE);
2528 CHECKPTR(VarUI8FromR8);
2529 CONVERT(VarUI8FromR8, -1.0); EXPECT_OVERFLOW;
2530 CONVERT(VarUI8FromR8, 0.0); EXPECTI8(0);
2531 CONVERT(VarUI8FromR8, 1.0); EXPECTI8(1);
2532 CONVERT(VarUI8FromR8, 255.0); EXPECTI8(255);
2534 CONVERT(VarUI8FromR8, -1.5); EXPECT_OVERFLOW;
2535 CONVERT(VarUI8FromR8, -0.6); EXPECT_OVERFLOW;
2536 CONVERT(VarUI8FromR8, -0.5); EXPECTI8(0);
2537 CONVERT(VarUI8FromR8, -0.4); EXPECTI8(0);
2538 CONVERT(VarUI8FromR8, 0.4); EXPECTI8(0);
2539 CONVERT(VarUI8FromR8, 0.5); EXPECTI8(0);
2540 CONVERT(VarUI8FromR8, 0.6); EXPECTI8(1);
2541 CONVERT(VarUI8FromR8, 1.5); EXPECTI8(2);
2544 static void test_VarUI8FromDate(void)
2546 CONVVARS(DATE);
2548 CHECKPTR(VarUI8FromDate);
2549 CONVERT(VarUI8FromDate, -1.0); EXPECT_OVERFLOW;
2550 CONVERT(VarUI8FromDate, 0.0); EXPECTI8(0);
2551 CONVERT(VarUI8FromDate, 1.0); EXPECTI8(1);
2552 CONVERT(VarUI8FromDate, 255.0); EXPECTI8(255);
2554 CONVERT(VarUI8FromDate, -1.5); EXPECT_OVERFLOW;
2555 CONVERT(VarUI8FromDate, -0.6); EXPECT_OVERFLOW;
2556 CONVERT(VarUI8FromDate, -0.5); EXPECTI8(0);
2557 CONVERT(VarUI8FromDate, -0.4); EXPECTI8(0);
2558 CONVERT(VarUI8FromDate, 0.4); EXPECTI8(0);
2559 CONVERT(VarUI8FromDate, 0.5); EXPECTI8(0);
2560 CONVERT(VarUI8FromDate, 0.6); EXPECTI8(1);
2561 CONVERT(VarUI8FromDate, 1.5); EXPECTI8(2);
2564 static void test_VarUI8FromBool(void)
2566 CONVVARS(VARIANT_BOOL);
2567 int i;
2569 CHECKPTR(VarUI8FromBool);
2570 for (i = -32768; i < 32768; i++)
2572 CONVERT(VarUI8FromBool, i); EXPECTI8(i);
2576 static void test_VarUI8FromI8(void)
2578 CONVVARS(LONG64);
2580 CHECKPTR(VarUI8FromI8);
2581 CONVERT(VarUI8FromI8, -1); EXPECT_OVERFLOW;
2582 CONVERT(VarUI8FromI8, 0); EXPECTI8(0);
2583 CONVERT(VarUI8FromI8, 1); EXPECTI8(1);
2586 static void test_VarUI8FromCy(void)
2588 CONVVARS(CY);
2590 CHECKPTR(VarUI8FromCy);
2591 CONVERT_CY(VarUI8FromCy,-1); EXPECT_OVERFLOW;
2592 CONVERT_CY(VarUI8FromCy,0); EXPECTI8(0);
2593 CONVERT_CY(VarUI8FromCy,1); EXPECTI8(1);
2594 CONVERT_CY(VarUI8FromCy,255); EXPECTI8(255);
2596 CONVERT_CY(VarUI8FromCy,-1.5); EXPECT_OVERFLOW;
2597 CONVERT_CY(VarUI8FromCy,-0.6); EXPECT_OVERFLOW;
2598 CONVERT_CY(VarUI8FromCy,-0.5); EXPECTI8(0);
2599 CONVERT_CY(VarUI8FromCy,-0.4); EXPECTI8(0);
2600 CONVERT_CY(VarUI8FromCy,0.4); EXPECTI8(0);
2601 CONVERT_CY(VarUI8FromCy,0.5); EXPECTI8(0);
2602 CONVERT_CY(VarUI8FromCy,0.6); EXPECTI8(1);
2603 CONVERT_CY(VarUI8FromCy,1.5); EXPECTI8(2);
2606 static void test_VarUI8FromDec(void)
2608 CONVVARS(DECIMAL);
2610 CHECKPTR(VarUI8FromDec);
2612 CONVERT_BADDEC(VarUI8FromDec);
2614 /* This returns 1 under native; Wine fixes this bug and returns overflow */
2615 if (0)
2617 CONVERT_DEC(VarUI8FromDec,0,0x80,0,1);
2620 CONVERT_DEC(VarUI8FromDec,0,0,0,0); EXPECTI8(0);
2621 CONVERT_DEC(VarUI8FromDec,0,0,0,1); EXPECTI8(1);
2622 CONVERT_DEC(VarUI8FromDec,0,0,0,255); EXPECTI8(255);
2624 CONVERT_DEC(VarUI8FromDec,2,0x80,0,100); EXPECT_OVERFLOW;
2625 CONVERT_DEC(VarUI8FromDec,2,0,0,25500); EXPECTI8(255);
2628 static void test_VarUI8FromStr(void)
2630 CONVVARS(LCID);
2631 OLECHAR buff[128];
2633 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2635 CHECKPTR(VarUI8FromStr);
2637 CONVERT_STR(VarUI8FromStr,NULL,0); EXPECT_MISMATCH;
2638 CONVERT_STR(VarUI8FromStr,"0",0); EXPECTI8(0);
2639 CONVERT_STR(VarUI8FromStr,"-1",0); EXPECT_OVERFLOW;
2640 CONVERT_STR(VarUI8FromStr,"2147483647",0); EXPECTI8(2147483647);
2641 CONVERT_STR(VarUI8FromStr,"18446744073709551614",0); EXPECTI864(0xFFFFFFFF,0xFFFFFFFE);
2642 CONVERT_STR(VarUI8FromStr,"18446744073709551615",0); EXPECTI864(0xFFFFFFFF,0xFFFFFFFF);
2643 CONVERT_STR(VarUI8FromStr,"18446744073709551616",0); EXPECT_OVERFLOW;
2645 CONVERT_STR(VarUI8FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
2646 CONVERT_STR(VarUI8FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
2647 CONVERT_STR(VarUI8FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2648 CONVERT_STR(VarUI8FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2649 CONVERT_STR(VarUI8FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2650 CONVERT_STR(VarUI8FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2651 CONVERT_STR(VarUI8FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECTI8(1);
2652 CONVERT_STR(VarUI8FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(2);
2655 static void test_VarUI8Copy(void)
2657 HRESULT hres;
2658 VARIANTARG vSrc, vDst;
2659 ULONGLONG in = 1;
2661 if (!has_i8)
2663 win_skip("I8 and UI8 data types are not available\n");
2664 return;
2667 VariantInit(&vSrc);
2668 VariantInit(&vDst);
2669 V_VT(&vSrc) = VT_UI8;
2670 V_UI8(&vSrc) = in;
2671 hres = VariantCopy(&vDst, &vSrc);
2672 ok(hres == S_OK && V_VT(&vDst) == VT_UI8 && V_UI8(&vDst) == in,
2673 "copy hres 0x%X, type %d, value (%x%08x) %x%08x\n",
2674 hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_UI8(&vDst) >> 32), (UINT)V_UI8(&vDst) );
2675 V_VT(&vSrc) = VT_UI8|VT_BYREF;
2676 V_UI8REF(&vSrc) = &in;
2677 hres = VariantCopy(&vDst, &vSrc);
2678 ok(hres == S_OK && V_VT(&vDst) == (VT_UI8|VT_BYREF) && V_UI8REF(&vDst) == &in,
2679 "ref hres 0x%X, type %d, ref (%p) %p\n", hres, V_VT(&vDst), &in, V_UI8REF(&vDst));
2680 hres = VariantCopyInd(&vDst, &vSrc);
2681 ok(hres == S_OK && V_VT(&vDst) == VT_UI8 && V_UI8(&vDst) == in,
2682 "copy hres 0x%X, type %d, value (%x%08x) %x%08x\n",
2683 hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_UI8(&vDst) >> 32), (UINT)V_UI8(&vDst) );
2686 static void test_VarUI8ChangeTypeEx(void)
2688 HRESULT hres;
2689 ULONG64 in;
2690 VARIANTARG vSrc, vDst;
2692 if (!has_i8)
2694 win_skip("I8 and UI8 data types are not available\n");
2695 return;
2698 in = 1;
2700 INITIAL_TYPETESTI8(VT_UI8, V_UI8);
2701 COMMON_TYPETEST;
2705 * VT_R4
2708 #undef CONV_TYPE
2709 #define CONV_TYPE float
2710 #undef EXPECTRES
2711 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%15.15f")
2713 static void test_VarR4FromI1(void)
2715 CONVVARS(signed char);
2716 int i;
2718 CHECKPTR(VarR4FromI1);
2719 CONVERTRANGE(VarR4FromI1, -128, 128);
2722 static void test_VarR4FromUI1(void)
2724 CONVVARS(BYTE);
2725 int i;
2727 CHECKPTR(VarR4FromUI1);
2728 CONVERTRANGE(VarR4FromUI1, 0, 256);
2731 static void test_VarR4FromI2(void)
2733 CONVVARS(SHORT);
2734 int i;
2736 CHECKPTR(VarR4FromI2);
2737 CONVERTRANGE(VarR4FromI2, -32768, 32768);
2740 static void test_VarR4FromUI2(void)
2742 CONVVARS(USHORT);
2743 int i;
2745 CHECKPTR(VarR4FromUI2);
2746 CONVERTRANGE(VarR4FromUI2, 0, 65536);
2749 static void test_VarR4FromI4(void)
2751 CONVVARS(int);
2753 CHECKPTR(VarR4FromI4);
2754 CONVERT(VarR4FromI4, -2147483647-1); EXPECT(-2147483648.0f);
2755 CONVERT(VarR4FromI4, -1); EXPECT(-1.0f);
2756 CONVERT(VarR4FromI4, 0); EXPECT(0.0f);
2757 CONVERT(VarR4FromI4, 1); EXPECT(1.0f);
2758 CONVERT(VarR4FromI4, 2147483647); EXPECT(2147483647.0f);
2761 static void test_VarR4FromUI4(void)
2763 CONVVARS(unsigned int);
2765 CHECKPTR(VarR4FromUI4);
2766 CONVERT(VarR4FromUI4, 0); EXPECT(0.0f);
2767 CONVERT(VarR4FromUI4, 1); EXPECT(1.0f);
2768 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
2769 CONVERT(VarR4FromUI4, 0xffffffff); EXPECT(4294967296.0f);
2770 #endif
2773 static void test_VarR4FromR8(void)
2775 CONVVARS(FLOAT);
2777 CHECKPTR(VarR4FromR8);
2778 CONVERT(VarR4FromR8, -1.0); EXPECT(-1.0f);
2779 CONVERT(VarR4FromR8, 0.0); EXPECT(0.0f);
2780 CONVERT(VarR4FromR8, 1.0); EXPECT(1.0f);
2781 CONVERT(VarR4FromR8, 1.5); EXPECT(1.5f);
2783 /* Skip rounding tests - no rounding is done */
2786 static void test_VarR4FromBool(void)
2788 CONVVARS(VARIANT_BOOL);
2790 CHECKPTR(VarR4FromBool);
2791 CONVERT(VarR4FromBool, VARIANT_TRUE); EXPECT(VARIANT_TRUE * 1.0f);
2792 CONVERT(VarR4FromBool, VARIANT_FALSE); EXPECT(VARIANT_FALSE * 1.0f);
2795 static void test_VarR4FromCy(void)
2797 CONVVARS(CY);
2799 CHECKPTR(VarR4FromCy);
2800 CONVERT_CY(VarR4FromCy,-32768); EXPECT(-32768.0f);
2801 CONVERT_CY(VarR4FromCy,-1); EXPECT(-1.0f);
2802 CONVERT_CY(VarR4FromCy,0); EXPECT(0.0f);
2803 CONVERT_CY(VarR4FromCy,1); EXPECT(1.0f);
2804 CONVERT_CY(VarR4FromCy,32768); EXPECT(32768.0f);
2806 CONVERT_CY(VarR4FromCy,-1.5); EXPECT(-1.5f);
2807 CONVERT_CY(VarR4FromCy,-0.6); EXPECT(-0.6f);
2808 CONVERT_CY(VarR4FromCy,-0.5); EXPECT(-0.5f);
2809 CONVERT_CY(VarR4FromCy,-0.4); EXPECT(-0.4f);
2810 CONVERT_CY(VarR4FromCy,0.4); EXPECT(0.4f);
2811 CONVERT_CY(VarR4FromCy,0.5); EXPECT(0.5f);
2812 CONVERT_CY(VarR4FromCy,0.6); EXPECT(0.6f);
2813 CONVERT_CY(VarR4FromCy,1.5); EXPECT(1.5f);
2816 static void test_VarR4FromI8(void)
2818 CONVVARS(LONG64);
2820 CHECKPTR(VarR4FromI8);
2821 CONVERT(VarR4FromI8, -1); EXPECT(-1.0f);
2822 CONVERT(VarR4FromI8, 0); EXPECT(0.0f);
2823 CONVERT(VarR4FromI8, 1); EXPECT(1.0f);
2826 static void test_VarR4FromUI8(void)
2828 CONVVARS(ULONG64);
2830 CHECKPTR(VarR4FromUI8);
2831 CONVERT(VarR4FromUI8, 0); EXPECT(0.0f);
2832 CONVERT(VarR4FromUI8, 1); EXPECT(1.0f);
2835 static void test_VarR4FromDec(void)
2837 CONVVARS(DECIMAL);
2839 CHECKPTR(VarR4FromDec);
2841 CONVERT_BADDEC(VarR4FromDec);
2843 CONVERT_DEC(VarR4FromDec,0,0x80,0,32768); EXPECT(-32768.0f);
2844 CONVERT_DEC(VarR4FromDec,0,0x80,0,1); EXPECT(-1.0f);
2845 CONVERT_DEC(VarR4FromDec,0,0,0,0); EXPECT(0.0f);
2846 CONVERT_DEC(VarR4FromDec,0,0,0,1); EXPECT(1.0f);
2847 CONVERT_DEC(VarR4FromDec,0,0,0,32767); EXPECT(32767.0f);
2849 CONVERT_DEC(VarR4FromDec,2,0x80,0,3276800); EXPECT(-32768.0f);
2850 CONVERT_DEC(VarR4FromDec,2,0,0,3276700); EXPECT(32767.0f);
2852 CONVERT_DEC(VarR4FromDec,0,0,1,0); EXPECT(18446744073709551616.0f);
2855 static void test_VarR4FromDate(void)
2857 CONVVARS(DATE);
2859 CHECKPTR(VarR4FromDate);
2860 CONVERT(VarR4FromDate, -1.0); EXPECT(-1.0f);
2861 CONVERT(VarR4FromDate, 0.0); EXPECT(0.0f);
2862 CONVERT(VarR4FromDate, 1.0); EXPECT(1.0f);
2865 static void test_VarR4FromStr(void)
2867 CONVVARS(LCID);
2868 OLECHAR buff[128];
2870 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2872 CHECKPTR(VarR4FromStr);
2874 CONVERT_STR(VarR4FromStr,NULL,0); EXPECT_MISMATCH;
2875 CONVERT_STR(VarR4FromStr,"-1", 0); EXPECT(-1.0f);
2876 CONVERT_STR(VarR4FromStr,"0", 0); EXPECT(0.0f);
2877 CONVERT_STR(VarR4FromStr,"1", 0); EXPECT(1.0f);
2879 CONVERT_STR(VarR4FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECT(-1.5f);
2880 CONVERT_STR(VarR4FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECT(-0.6f);
2881 CONVERT_STR(VarR4FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECT(-0.5f);
2882 CONVERT_STR(VarR4FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECT(-0.4f);
2883 CONVERT_STR(VarR4FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0.4f);
2884 CONVERT_STR(VarR4FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0.5f);
2885 CONVERT_STR(VarR4FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECT(0.6f);
2886 CONVERT_STR(VarR4FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECT(1.5f);
2889 static void test_VarR4Copy(void)
2891 COPYTEST(77665544.0f, VT_R4, V_R4(&vSrc), V_R4(&vDst), V_R4REF(&vSrc),V_R4REF(&vDst), "%15.15f");
2894 static void test_VarR4ChangeTypeEx(void)
2896 #ifdef HAS_UINT64_TO_FLOAT
2897 HRESULT hres;
2898 float in;
2899 VARIANTARG vSrc, vDst;
2901 in = 1.0f;
2903 INITIAL_TYPETEST(VT_R4, V_R4, "%f");
2904 COMMON_TYPETEST;
2905 #endif
2909 * VT_R8
2912 #undef CONV_TYPE
2913 #define CONV_TYPE double
2915 static void test_VarR8FromI1(void)
2917 CONVVARS(signed char);
2918 int i;
2920 CHECKPTR(VarR8FromI1);
2921 CONVERTRANGE(VarR8FromI1, -128, 128);
2924 static void test_VarR8FromUI1(void)
2926 CONVVARS(BYTE);
2927 int i;
2929 CHECKPTR(VarR8FromUI1);
2930 CONVERTRANGE(VarR8FromUI1, 0, 256);
2933 static void test_VarR8FromI2(void)
2935 CONVVARS(SHORT);
2936 int i;
2938 CHECKPTR(VarR8FromI2);
2939 CONVERTRANGE(VarR8FromI2, -32768, 32768);
2942 static void test_VarR8FromUI2(void)
2944 CONVVARS(USHORT);
2945 int i;
2947 CHECKPTR(VarR8FromUI2);
2948 CONVERTRANGE(VarR8FromUI2, 0, 65536);
2951 static void test_VarR8FromI4(void)
2953 CONVVARS(int);
2955 CHECKPTR(VarR8FromI4);
2956 CONVERT(VarR8FromI4, -2147483647-1); EXPECT(-2147483648.0);
2957 CONVERT(VarR8FromI4, -1); EXPECT(-1.0);
2958 CONVERT(VarR8FromI4, 0); EXPECT(0.0);
2959 CONVERT(VarR8FromI4, 1); EXPECT(1.0);
2960 CONVERT(VarR8FromI4, 0x7fffffff); EXPECT(2147483647.0);
2963 static void test_VarR8FromUI4(void)
2965 CONVVARS(unsigned int);
2967 CHECKPTR(VarR8FromUI4);
2968 CONVERT(VarR8FromUI4, 0); EXPECT(0.0);
2969 CONVERT(VarR8FromUI4, 1); EXPECT(1.0);
2970 CONVERT(VarR8FromUI4, 0xffffffff); EXPECT(4294967295.0);
2973 static void test_VarR8FromR4(void)
2975 CONVVARS(FLOAT);
2977 CHECKPTR(VarR8FromR4);
2978 CONVERT(VarR8FromR4, -1.0f); EXPECT(-1.0);
2979 CONVERT(VarR8FromR4, 0.0f); EXPECT(0.0);
2980 CONVERT(VarR8FromR4, 1.0f); EXPECT(1.0);
2981 CONVERT(VarR8FromR4, 1.5f); EXPECT(1.5);
2983 /* Skip rounding tests - no rounding is done */
2986 static void test_VarR8FromBool(void)
2988 CONVVARS(VARIANT_BOOL);
2990 CHECKPTR(VarR8FromBool);
2991 CONVERT(VarR8FromBool, VARIANT_TRUE); EXPECT(VARIANT_TRUE * 1.0);
2992 CONVERT(VarR8FromBool, VARIANT_FALSE); EXPECT(VARIANT_FALSE * 1.0);
2995 static void test_VarR8FromCy(void)
2997 CONVVARS(CY);
2999 CHECKPTR(VarR8FromCy);
3000 CONVERT_CY(VarR8FromCy,-32769); EXPECT(-32769.0);
3001 CONVERT_CY(VarR8FromCy,-32768); EXPECT(-32768.0);
3002 CONVERT_CY(VarR8FromCy,-1); EXPECT(-1.0);
3003 CONVERT_CY(VarR8FromCy,0); EXPECT(0.0);
3004 CONVERT_CY(VarR8FromCy,1); EXPECT(1.0);
3005 CONVERT_CY(VarR8FromCy,32767); EXPECT(32767.0);
3006 CONVERT_CY(VarR8FromCy,32768); EXPECT(32768.0);
3008 CONVERT_CY(VarR8FromCy,-1.5); EXPECT(-1.5);
3009 CONVERT_CY(VarR8FromCy,-0.6); EXPECT(-0.6);
3010 CONVERT_CY(VarR8FromCy,-0.5); EXPECT(-0.5);
3011 CONVERT_CY(VarR8FromCy,-0.4); EXPECT(-0.4);
3012 CONVERT_CY(VarR8FromCy,0.4); EXPECT(0.4);
3013 CONVERT_CY(VarR8FromCy,0.5); EXPECT(0.5);
3014 CONVERT_CY(VarR8FromCy,0.6); EXPECT(0.6);
3015 CONVERT_CY(VarR8FromCy,1.5); EXPECT(1.5);
3018 static void test_VarR8FromI8(void)
3020 CONVVARS(LONG64);
3022 CHECKPTR(VarR8FromI8);
3023 CONVERT(VarR8FromI8, -1); EXPECT(-1.0);
3024 CONVERT(VarR8FromI8, 0); EXPECT(0.0);
3025 CONVERT(VarR8FromI8, 1); EXPECT(1.0);
3026 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3027 CONVERT_I8(VarR8FromI8, 0x7fffffff,0xffffffff); EXPECT(9223372036854775808.0);
3028 #endif
3031 static void test_VarR8FromUI8(void)
3033 CONVVARS(ULONG64);
3035 CHECKPTR(VarR8FromUI8);
3036 CONVERT(VarR8FromUI8, 0); EXPECT(0.0);
3037 CONVERT(VarR8FromUI8, 1); EXPECT(1.0);
3038 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3039 CONVERT_I8(VarR8FromUI8, 0x80000000,0); EXPECT(9223372036854775808.0);
3040 #endif
3043 static void test_VarR8FromDec(void)
3045 CONVVARS(DECIMAL);
3047 CHECKPTR(VarR8FromDec);
3049 CONVERT_BADDEC(VarR8FromDec);
3051 CONVERT_DEC(VarR8FromDec,0,0x80,0,32768); EXPECT(-32768.0);
3052 CONVERT_DEC(VarR8FromDec,0,0x80,0,1); EXPECT(-1.0);
3053 CONVERT_DEC(VarR8FromDec,0,0,0,0); EXPECT(0.0);
3054 CONVERT_DEC(VarR8FromDec,0,0,0,1); EXPECT(1.0);
3055 CONVERT_DEC(VarR8FromDec,0,0,0,32767); EXPECT(32767.0);
3057 CONVERT_DEC(VarR8FromDec,2,0x80,0,3276800); EXPECT(-32768.0);
3058 CONVERT_DEC(VarR8FromDec,2,0,0,3276700); EXPECT(32767.0);
3060 CONVERT_DEC(VarR8FromDec,0,0,1,0); EXPECT(18446744073709551616.0);
3063 static void test_VarR8FromDate(void)
3065 CONVVARS(DATE);
3067 CHECKPTR(VarR8FromDate);
3068 CONVERT(VarR8FromDate, -1.0); EXPECT(-1.0);
3069 CONVERT(VarR8FromDate, -0.0); EXPECT(0.0);
3070 CONVERT(VarR8FromDate, 1.0); EXPECT(1.0);
3073 static void test_VarR8FromStr(void)
3075 CONVVARS(LCID);
3076 OLECHAR buff[128];
3078 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
3080 CHECKPTR(VarR8FromStr);
3082 CONVERT_STR(VarR8FromStr,NULL,0); EXPECT_MISMATCH;
3083 CONVERT_STR(VarR8FromStr,"",0); EXPECT_MISMATCH;
3084 CONVERT_STR(VarR8FromStr," ",0); EXPECT_MISMATCH;
3086 CONVERT_STR(VarR8FromStr,"0",LOCALE_NOUSEROVERRIDE); EXPECT(0.0);
3087 CONVERT_STR(VarR8FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECT(-1.5);
3088 CONVERT_STR(VarR8FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECT(-0.6);
3089 CONVERT_STR(VarR8FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECT(-0.5);
3090 CONVERT_STR(VarR8FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECT(-0.4);
3091 CONVERT_STR(VarR8FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0.4);
3092 CONVERT_STR(VarR8FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0.5);
3093 CONVERT_STR(VarR8FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECT(0.6);
3094 CONVERT_STR(VarR8FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECT(1.5);
3096 /* We already have exhaustive tests for number parsing, so skip those tests here */
3099 static void test_VarR8Copy(void)
3101 COPYTEST(77665544.0, VT_R8, V_R8(&vSrc), V_R8(&vDst), V_R8REF(&vSrc),V_R8REF(&vDst), "%16.16g");
3104 static void test_VarR8ChangeTypeEx(void)
3106 #ifdef HAS_UINT64_TO_FLOAT
3107 HRESULT hres;
3108 double in;
3109 VARIANTARG vSrc, vDst;
3111 in = 1.0;
3113 INITIAL_TYPETEST(VT_R8, V_R8, "%g");
3114 COMMON_TYPETEST;
3115 #endif
3118 #define MATHRND(l, r) left = l; right = r; hres = pVarR8Round(left, right, &out)
3120 static void test_VarR8Round(void)
3122 HRESULT hres;
3123 double left = 0.0, out;
3124 int right;
3126 CHECKPTR(VarR8Round);
3127 MATHRND(0.5432, 5); EXPECT(0.5432);
3128 MATHRND(0.5432, 4); EXPECT(0.5432);
3129 MATHRND(0.5432, 3); EXPECT(0.543);
3130 MATHRND(0.5432, 2); EXPECT(0.54);
3131 MATHRND(0.5432, 1); EXPECT(0.5);
3132 MATHRND(0.5532, 0); EXPECT(1);
3133 MATHRND(0.5532, -1); EXPECT_INVALID;
3135 MATHRND(0.5568, 5); EXPECT(0.5568);
3136 MATHRND(0.5568, 4); EXPECT(0.5568);
3137 MATHRND(0.5568, 3); EXPECT(0.557);
3138 MATHRND(0.5568, 2); EXPECT(0.56);
3139 MATHRND(0.5568, 1); EXPECT(0.6);
3140 MATHRND(0.5568, 0); EXPECT(1);
3141 MATHRND(0.5568, -1); EXPECT_INVALID;
3143 MATHRND(0.4999, 0); EXPECT(0);
3144 MATHRND(0.5000, 0); EXPECT(0);
3145 MATHRND(0.5001, 0); EXPECT(1);
3146 MATHRND(1.4999, 0); EXPECT(1);
3147 MATHRND(1.5000, 0); EXPECT(2);
3148 MATHRND(1.5001, 0); EXPECT(2);
3152 * VT_DATE
3155 #undef CONV_TYPE
3156 #define CONV_TYPE DATE
3158 static void test_VarDateFromI1(void)
3160 CONVVARS(signed char);
3161 int i;
3163 CHECKPTR(VarDateFromI1);
3164 CONVERTRANGE(VarDateFromI1, -128, 128);
3167 static void test_VarDateFromUI1(void)
3169 CONVVARS(BYTE);
3170 int i;
3172 CHECKPTR(VarDateFromUI1);
3173 CONVERTRANGE(VarDateFromUI1, 0, 256);
3176 static void test_VarDateFromI2(void)
3178 CONVVARS(SHORT);
3179 int i;
3181 CHECKPTR(VarDateFromI2);
3182 CONVERTRANGE(VarDateFromI2, -32768, 32768);
3185 static void test_VarDateFromUI2(void)
3187 CONVVARS(USHORT);
3188 int i;
3190 CHECKPTR(VarDateFromUI2);
3191 CONVERTRANGE(VarDateFromUI2, 0, 65536);
3194 static void test_VarDateFromI4(void)
3196 CONVVARS(int);
3198 CHECKPTR(VarDateFromI4);
3199 CONVERT(VarDateFromI4, DATE_MIN-1);
3200 if (hres != DISP_E_TYPEMISMATCH) /* Early versions return this, incorrectly */
3201 EXPECT_OVERFLOW;
3202 CONVERT(VarDateFromI4, DATE_MIN); EXPECT(DATE_MIN);
3203 CONVERT(VarDateFromI4, -1); EXPECT(-1.0);
3204 CONVERT(VarDateFromI4, 0); EXPECT(0.0);
3205 CONVERT(VarDateFromI4, 1); EXPECT(1.0);
3206 CONVERT(VarDateFromI4, DATE_MAX); EXPECT(DATE_MAX);
3207 CONVERT(VarDateFromI4, DATE_MAX+1);
3208 if (hres != DISP_E_TYPEMISMATCH) /* Early versions return this, incorrectly */
3209 EXPECT_OVERFLOW;
3212 static void test_VarDateFromUI4(void)
3214 CONVVARS(unsigned int);
3216 CHECKPTR(VarDateFromUI4);
3217 CONVERT(VarDateFromUI4, 0); EXPECT(0.0);
3218 CONVERT(VarDateFromUI4, 1); EXPECT(1.0);
3219 CONVERT(VarDateFromUI4, DATE_MAX); EXPECT(DATE_MAX);
3220 CONVERT(VarDateFromUI4, DATE_MAX+1);
3221 if (hres != DISP_E_TYPEMISMATCH) /* Early versions return this, incorrectly */
3222 EXPECT_OVERFLOW;
3225 static void test_VarDateFromR4(void)
3227 CONVVARS(FLOAT);
3229 CHECKPTR(VarDateFromR4);
3230 CONVERT(VarDateFromR4, -1.0f); EXPECT(-1.0);
3231 CONVERT(VarDateFromR4, 0.0f); EXPECT(0.0);
3232 CONVERT(VarDateFromR4, 1.0f); EXPECT(1.0);
3233 CONVERT(VarDateFromR4, 1.5f); EXPECT(1.5);
3236 static void test_VarDateFromR8(void)
3238 CONVVARS(double);
3240 CHECKPTR(VarDateFromR8);
3241 CONVERT(VarDateFromR8, -1.0f); EXPECT(-1.0);
3242 CONVERT(VarDateFromR8, 0.0f); EXPECT(0.0);
3243 CONVERT(VarDateFromR8, 1.0f); EXPECT(1.0);
3244 CONVERT(VarDateFromR8, 1.5f); EXPECT(1.5);
3247 static void test_VarDateFromBool(void)
3249 CONVVARS(VARIANT_BOOL);
3251 CHECKPTR(VarDateFromBool);
3252 CONVERT(VarDateFromBool, VARIANT_TRUE); EXPECT(VARIANT_TRUE * 1.0);
3253 CONVERT(VarDateFromBool, VARIANT_FALSE); EXPECT(VARIANT_FALSE * 1.0);
3256 static void test_VarDateFromCy(void)
3258 CONVVARS(CY);
3260 CHECKPTR(VarDateFromCy);
3261 CONVERT_CY(VarDateFromCy,-32769); EXPECT(-32769.0);
3262 CONVERT_CY(VarDateFromCy,-32768); EXPECT(-32768.0);
3263 CONVERT_CY(VarDateFromCy,-1); EXPECT(-1.0);
3264 CONVERT_CY(VarDateFromCy,0); EXPECT(0.0);
3265 CONVERT_CY(VarDateFromCy,1); EXPECT(1.0);
3266 CONVERT_CY(VarDateFromCy,32767); EXPECT(32767.0);
3267 CONVERT_CY(VarDateFromCy,32768); EXPECT(32768.0);
3269 CONVERT_CY(VarDateFromCy,-1.5); EXPECT(-1.5);
3270 CONVERT_CY(VarDateFromCy,-0.6); EXPECT(-0.6);
3271 CONVERT_CY(VarDateFromCy,-0.5); EXPECT(-0.5);
3272 CONVERT_CY(VarDateFromCy,-0.4); EXPECT(-0.4);
3273 CONVERT_CY(VarDateFromCy,0.4); EXPECT(0.4);
3274 CONVERT_CY(VarDateFromCy,0.5); EXPECT(0.5);
3275 CONVERT_CY(VarDateFromCy,0.6); EXPECT(0.6);
3276 CONVERT_CY(VarDateFromCy,1.5); EXPECT(1.5);
3279 static void test_VarDateFromI8(void)
3281 CONVVARS(LONG64);
3283 CHECKPTR(VarDateFromI8);
3284 CONVERT(VarDateFromI8, DATE_MIN-1); EXPECT_OVERFLOW;
3285 CONVERT(VarDateFromI8, DATE_MIN); EXPECT(DATE_MIN);
3286 CONVERT(VarDateFromI8, -1); EXPECT(-1.0);
3287 CONVERT(VarDateFromI8, 0); EXPECT(0.0);
3288 CONVERT(VarDateFromI8, 1); EXPECT(1.0);
3289 CONVERT(VarDateFromI8, DATE_MAX); EXPECT(DATE_MAX);
3290 CONVERT(VarDateFromI8, DATE_MAX+1); EXPECT_OVERFLOW;
3293 static void test_VarDateFromUI8(void)
3295 CONVVARS(ULONG64);
3297 CHECKPTR(VarDateFromUI8);
3298 CONVERT(VarDateFromUI8, 0); EXPECT(0.0);
3299 CONVERT(VarDateFromUI8, 1); EXPECT(1.0);
3300 CONVERT(VarDateFromUI8, DATE_MAX); EXPECT(DATE_MAX);
3301 CONVERT(VarDateFromUI8, DATE_MAX+1); EXPECT_OVERFLOW;
3304 static void test_VarDateFromDec(void)
3306 CONVVARS(DECIMAL);
3308 CHECKPTR(VarDateFromDec);
3310 CONVERT_BADDEC(VarDateFromDec);
3312 CONVERT_DEC(VarDateFromDec,0,0x80,0,32768); EXPECT(-32768.0);
3313 CONVERT_DEC(VarDateFromDec,0,0x80,0,1); EXPECT(-1.0);
3314 CONVERT_DEC(VarDateFromDec,0,0,0,0); EXPECT(0.0);
3315 CONVERT_DEC(VarDateFromDec,0,0,0,1); EXPECT(1.0);
3316 CONVERT_DEC(VarDateFromDec,0,0,0,32767); EXPECT(32767.0);
3318 CONVERT_DEC(VarDateFromDec,2,0x80,0,3276800); EXPECT(-32768.0);
3319 CONVERT_DEC(VarDateFromDec,2,0,0,3276700); EXPECT(32767.0);
3322 #define DFS(str) \
3323 buff[0] = '\0'; out = 0.0; \
3324 if (str) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)/sizeof(WCHAR)); \
3325 hres = pVarDateFromStr(str ? buff : NULL,lcid,LOCALE_NOUSEROVERRIDE,&out)
3327 #define MKRELDATE(day,mth) st.wMonth = mth; st.wDay = day; \
3328 pSystemTimeToVariantTime(&st,&relative)
3330 static const char * const BadDateStrings[] =
3332 "True", "False", /* Plain text */
3333 "0.", ".0", "-1.1", "1.1-", /* Partial specifications */
3334 "1;2;3", "1*2*3", "1@2@3", "1#2#3", "(1:2)","<1:2>","1|2|3", /* Bad chars */
3335 "0", "1", /* 1 element */
3336 "0.60", "24.00", "0:60", "24:00", "1 2 am", "1 am 2", /* 2 elements */
3337 "1.5 2", "1 5.2", "2 32 3", "1 2 am 3", /* 3 elements */
3338 "1 2.3 4", "1.2.3 4", "1 2.3.4", "1.2 3.4", "1.2.3.4", "1 2 3 4",
3339 "1 am 2 3.4", "1 2 am 3.4", "1.2 3 am 4", "1.2 3 4 am", /* 4 elements */
3340 "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",
3341 "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",
3342 "1.2.3 4 am 5", "1.2.3 4 5 am", "1.2 3 am 4 5",
3343 "1.2 3 4 am 5", "1.2 3 4 5 am", "1 am 2 3.4.5", "1 2 am 3.4.5",
3344 "1 am 2 3 4.5", "1 2 am 3 4.5", "1 2 3 am 4.5", /* 5 elements */
3345 /* 6 elements */
3346 "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",
3347 "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",
3348 "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",
3349 "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",
3350 #if 0
3351 /* following throws an exception on winME */
3352 "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",
3353 #endif
3354 "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",
3355 #if 0
3356 /* following throws an exception on winME */
3357 "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",
3358 #endif
3359 "1 2 am 3 4.5.6", "1 2 3 am 4.5.6"
3362 static void test_VarDateFromStr(void)
3364 LCID lcid;
3365 DATE out, relative;
3366 HRESULT hres;
3367 SYSTEMTIME st;
3368 OLECHAR buff[128];
3369 size_t i;
3371 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
3373 CHECKPTR(VarDateFromStr);
3374 CHECKPTR(SystemTimeToVariantTime);
3376 /* Some date formats are relative, so we need to find the current year */
3377 GetSystemTime(&st);
3378 st.wHour = st.wMinute = st.wSecond = st.wMilliseconds = 0;
3379 DFS(NULL); EXPECT_MISMATCH;
3381 /* Floating point number are not recognised */
3382 DFS("0.0");
3383 if (hres == S_OK)
3384 EXPECT_DBL(0.0); /* Very old versions accept this string */
3385 else
3386 EXPECT_MISMATCH;
3388 /* 1 element - can only be a time, and only if it has am/pm */
3389 DFS("1 am"); EXPECT_DBL(0.04166666666666666);
3390 /* 2 elements */
3391 /* A decimal point is treated as a time separator.
3392 * The following are converted as hours/minutes.
3394 DFS("0.1"); EXPECT_DBL(0.0006944444444444445);
3395 DFS("0.40"); EXPECT_DBL(0.02777777777777778);
3396 DFS("2.5"); EXPECT_DBL(0.08680555555555555);
3397 /* A colon acts as a decimal point */
3398 DFS("0:1"); EXPECT_DBL(0.0006944444444444445);
3399 DFS("0:20"); EXPECT_DBL(0.01388888888888889);
3400 DFS("0:40"); EXPECT_DBL(0.02777777777777778);
3401 DFS("3:5"); EXPECT_DBL(0.1284722222222222);
3402 /* Check the am/pm limits */
3403 DFS("00:00 AM"); EXPECT_DBL(0.0);
3404 DFS("00:00 a"); EXPECT_DBL(0.0);
3405 DFS("12:59 AM"); EXPECT_DBL(0.04097222222222222);
3406 DFS("12:59 A"); EXPECT_DBL(0.04097222222222222);
3407 DFS("00:00 pm"); EXPECT_DBL(0.5);
3408 DFS("00:00 p"); EXPECT_DBL(0.5);
3409 DFS("12:59 pm"); EXPECT_DBL(0.5409722222222222);
3410 DFS("12:59 p"); EXPECT_DBL(0.5409722222222222);
3411 /* AM/PM is ignored if hours > 12 */
3412 DFS("13:00 AM"); EXPECT_DBL(0.5416666666666666);
3413 DFS("13:00 PM"); EXPECT_DBL(0.5416666666666666);
3415 /* Space, dash and slash all indicate a date format. */
3416 /* If both numbers are valid month values => month/day of current year */
3417 DFS("1 2"); MKRELDATE(2,1); EXPECT_DBL(relative);
3418 DFS("2 1"); MKRELDATE(1,2); EXPECT_DBL(relative);
3419 /* one number not valid month, is a valid day, other number valid month:
3420 * that number becomes the day.
3422 DFS("14 1"); MKRELDATE(14,1); EXPECT_DBL(relative);
3423 DFS("1 14"); EXPECT_DBL(relative);
3424 /* If the numbers can't be day/month, they are assumed to be year/month */
3425 DFS("30 2"); EXPECT_DBL(10990.0);
3426 DFS("2 30"); EXPECT_DBL(10990.0);
3427 DFS("32 49"); EXPECT_MISMATCH; /* Can't be any format */
3428 DFS("0 49"); EXPECT_MISMATCH; /* Can't be any format */
3429 /* If a month name is given the other number is the day */
3430 DFS("Jan 2"); MKRELDATE(2,1); EXPECT_DBL(relative);
3431 DFS("2 Jan"); EXPECT_DBL(relative);
3432 /* Unless it can't be, in which case it becomes the year */
3433 DFS("Jan 35"); EXPECT_DBL(12785.0);
3434 DFS("35 Jan"); EXPECT_DBL(12785.0);
3435 DFS("Jan-35"); EXPECT_DBL(12785.0);
3436 DFS("35-Jan"); EXPECT_DBL(12785.0);
3437 DFS("Jan/35"); EXPECT_DBL(12785.0);
3438 DFS("35/Jan"); EXPECT_DBL(12785.0);
3439 /* 3 elements */
3440 /* 3 numbers and time separator => h:m:s */
3441 DFS("0.1.0"); EXPECT_DBL(0.0006944444444444445);
3442 DFS("1.5.2"); EXPECT_DBL(0.04516203703703704);
3443 /* 3 numbers => picks date giving preference to lcid format */
3444 DFS("1 2 3"); EXPECT_DBL(37623.0);
3445 DFS("14 2 3"); EXPECT_DBL(41673.0);
3446 DFS("2 14 3"); EXPECT_DBL(37666.0);
3447 DFS("2 3 14"); EXPECT_DBL(41673.0);
3448 DFS("32 2 3"); EXPECT_DBL(11722.0);
3449 DFS("2 3 32"); EXPECT_DBL(11722.0);
3450 DFS("1 2 29"); EXPECT_DBL(47120.0);
3451 /* After 30, two digit dates are expected to be in the 1900's */
3452 DFS("1 2 30"); EXPECT_DBL(10960.0);
3453 DFS("1 2 31"); EXPECT_DBL(11325.0);
3454 DFS("3 am 1 2"); MKRELDATE(2,1); relative += 0.125; EXPECT_DBL(relative);
3455 DFS("1 2 3 am"); EXPECT_DBL(relative);
3457 /* 4 elements -interpreted as 2 digit date & time */
3458 DFS("1.2 3 4"); MKRELDATE(4,3); relative += 0.04305555556; EXPECT_DBL(relative);
3459 DFS("3 4 1.2"); EXPECT_DBL(relative);
3460 /* 5 elements - interpreted as 2 & 3 digit date/times */
3461 DFS("1.2.3 4 5"); MKRELDATE(5,4); relative += 0.04309027778; EXPECT_DBL(relative);
3462 DFS("1.2 3 4 5"); EXPECT_DBL(38415.04305555556);
3463 #if 0
3464 /* following throws an exception on winME */
3465 DFS("1 2 3.4.5"); MKRELDATE(2,1); relative += 0.12783564815; EXPECT_DBL(relative);
3466 #endif
3467 DFS("1 2 3 4.5"); EXPECT_DBL(37623.17013888889);
3468 /* 6 elements - interpreted as 3 digit date/times */
3469 DFS("1.2.3 4 5 6"); EXPECT_DBL(38812.04309027778);
3470 DFS("1 2 3 4.5.6"); EXPECT_DBL(37623.17020833334);
3472 for (i = 0; i < sizeof(BadDateStrings)/sizeof(char*); i++)
3474 DFS(BadDateStrings[i]); EXPECT_MISMATCH;
3477 /* Some normal-ish strings */
3478 DFS("2 January, 1970"); EXPECT_DBL(25570.0);
3479 DFS("2 January 1970"); EXPECT_DBL(25570.0);
3480 DFS("2 Jan 1970"); EXPECT_DBL(25570.0);
3481 DFS("2/Jan/1970"); EXPECT_DBL(25570.0);
3482 DFS("2-Jan-1970"); EXPECT_DBL(25570.0);
3483 DFS("1 2 1970"); EXPECT_DBL(25570.0);
3484 DFS("1/2/1970"); EXPECT_DBL(25570.0);
3485 DFS("1-2-1970"); EXPECT_DBL(25570.0);
3486 DFS("13-1-1970"); EXPECT_DBL(25581.0);
3487 DFS("1970-1-13"); EXPECT_DBL(25581.0);
3488 /* Native fails "1999 January 3, 9AM". I consider that a bug in native */
3490 /* test a non-english data string */
3491 DFS("02.01.1970"); EXPECT_MISMATCH;
3492 DFS("02.01.1970 00:00:00"); EXPECT_MISMATCH;
3493 lcid = MAKELCID(MAKELANGID(LANG_GERMAN,SUBLANG_GERMAN),SORT_DEFAULT);
3494 DFS("02.01.1970"); EXPECT_DBL(25570.0);
3495 DFS("02.13.1970"); EXPECT_DBL(25612.0);
3496 DFS("02-13-1970"); EXPECT_DBL(25612.0);
3497 DFS("2020-01-11"); EXPECT_DBL(43841.0);
3498 DFS("2173-10-14"); EXPECT_DBL(100000.0);
3500 DFS("02.01.1970 00:00:00"); EXPECT_DBL(25570.0);
3501 lcid = MAKELCID(MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH),SORT_DEFAULT);
3502 DFS("02.01.1970"); EXPECT_MISMATCH;
3503 DFS("02.01.1970 00:00:00"); EXPECT_MISMATCH;
3506 static void test_VarDateCopy(void)
3508 COPYTEST(77665544.0, VT_DATE, V_DATE(&vSrc), V_DATE(&vDst), V_DATEREF(&vSrc),
3509 V_DATEREF(&vDst), "%16.16g");
3512 static const char* wtoascii(LPWSTR lpszIn)
3514 static char buff[256];
3515 WideCharToMultiByte(CP_ACP, 0, lpszIn, -1, buff, sizeof(buff), NULL, NULL);
3516 return buff;
3519 static void test_VarDateChangeTypeEx(void)
3521 static const WCHAR sz25570[] = {
3522 '1','/','2','/','1','9','7','0','\0' };
3523 static const WCHAR sz25570_2[] = {
3524 '1','/','2','/','7','0','\0' };
3525 static const WCHAR sz25570Nls[] = {
3526 '1','/','2','/','1','9','7','0',' ','1','2',':','0','0',':','0','0',' ','A','M','\0' };
3527 HRESULT hres;
3528 DATE in;
3529 VARIANTARG vSrc, vDst;
3530 LCID lcid;
3532 in = 1.0;
3534 #ifdef HAS_UINT64_TO_FLOAT
3535 INITIAL_TYPETEST(VT_DATE, V_DATE, "%g");
3536 COMMON_TYPETEST;
3537 #endif
3539 V_VT(&vDst) = VT_EMPTY;
3540 V_VT(&vSrc) = VT_DATE;
3541 V_DATE(&vSrc) = 25570.0;
3542 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
3544 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, VARIANT_NOUSEROVERRIDE, VT_BSTR);
3545 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && V_BSTR(&vDst) &&
3546 (!lstrcmpW(V_BSTR(&vDst), sz25570) || !lstrcmpW(V_BSTR(&vDst), sz25570_2)),
3547 "hres=0x%X, type=%d (should be VT_BSTR), *bstr=%s\n",
3548 hres, V_VT(&vDst), V_BSTR(&vDst) ? wtoascii(V_BSTR(&vDst)) : "?");
3549 VariantClear(&vDst);
3551 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
3552 if (has_locales)
3554 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, VARIANT_NOUSEROVERRIDE|VARIANT_USE_NLS, VT_BSTR);
3555 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && V_BSTR(&vDst) && !lstrcmpW(V_BSTR(&vDst), sz25570Nls),
3556 "hres=0x%X, type=%d (should be VT_BSTR), *bstr=%s\n",
3557 hres, V_VT(&vDst), V_BSTR(&vDst) ? wtoascii(V_BSTR(&vDst)) : "?");
3558 VariantClear(&vDst);
3563 * VT_CY
3566 #undef CONV_TYPE
3567 #define CONV_TYPE CY
3569 #define EXPECTCY(x) \
3570 ok((hres == S_OK && out.int64 == (LONGLONG)(x*CY_MULTIPLIER)), \
3571 "expected " #x "*CY_MULTIPLIER, got (%8x %8x); hres=0x%08x\n", S(out).Hi, S(out).Lo, hres)
3573 #define EXPECTCY64(x,y) \
3574 ok(hres == S_OK && S(out).Hi == (LONG)x && S(out).Lo == y, \
3575 "expected " #x " " #y " (%u,%u), got (%u,%u); hres=0x%08x\n", \
3576 (ULONG)(x), (ULONG)(y), S(out).Hi, S(out).Lo, hres)
3578 static void test_VarCyFromI1(void)
3580 CONVVARS(signed char);
3581 int i;
3583 CHECKPTR(VarCyFromI1);
3584 for (i = -128; i < 128; i++)
3586 CONVERT(VarCyFromI1,i); EXPECTCY(i);
3590 static void test_VarCyFromUI1(void)
3592 CONVVARS(BYTE);
3593 int i;
3595 CHECKPTR(VarCyFromUI1);
3596 for (i = 0; i < 256; i++)
3598 CONVERT(VarCyFromUI1,i); EXPECTCY(i);
3602 static void test_VarCyFromI2(void)
3604 CONVVARS(SHORT);
3605 int i;
3607 CHECKPTR(VarCyFromI2);
3608 for (i = -16384; i < 16384; i++)
3610 CONVERT(VarCyFromI2,i); EXPECTCY(i);
3614 static void test_VarCyFromUI2(void)
3616 CONVVARS(int);
3617 int i;
3619 CHECKPTR(VarCyFromUI2);
3620 for (i = 0; i < 32768; i++)
3622 CONVERT(VarCyFromUI2,i); EXPECTCY(i);
3626 static void test_VarCyFromI4(void)
3628 CONVVARS(int);
3630 CHECKPTR(VarCyFromI4);
3631 CONVERT(VarCyFromI4, -1); EXPECTCY(-1);
3632 CONVERT(VarCyFromI4, 0); EXPECTCY(0);
3633 CONVERT(VarCyFromI4, 1); EXPECTCY(1);
3634 CONVERT(VarCyFromI4, 0x7fffffff); EXPECTCY64(0x1387, 0xffffd8f0);
3635 CONVERT(VarCyFromI4, 0x80000000); EXPECTCY64(0xffffec78, 0);
3638 static void test_VarCyFromUI4(void)
3640 CONVVARS(unsigned int);
3642 CHECKPTR(VarCyFromUI4);
3643 CONVERT(VarCyFromUI4, 0); EXPECTCY(0);
3644 CONVERT(VarCyFromUI4, 1); EXPECTCY(1);
3645 CONVERT(VarCyFromUI4, 0x80000000); EXPECTCY64(5000, 0);
3648 static void test_VarCyFromR4(void)
3650 CONVVARS(FLOAT);
3652 CHECKPTR(VarCyFromR4);
3653 CONVERT(VarCyFromR4, -1.0f); EXPECTCY(-1);
3654 CONVERT(VarCyFromR4, 0.0f); EXPECTCY(0);
3655 CONVERT(VarCyFromR4, 1.0f); EXPECTCY(1);
3656 CONVERT(VarCyFromR4, 1.5f); EXPECTCY(1.5);
3658 CONVERT(VarCyFromR4, -1.5f); EXPECTCY(-1.5);
3659 CONVERT(VarCyFromR4, -0.6f); EXPECTCY(-0.6);
3660 CONVERT(VarCyFromR4, -0.5f); EXPECTCY(-0.5);
3661 CONVERT(VarCyFromR4, -0.4f); EXPECTCY(-0.4);
3662 CONVERT(VarCyFromR4, 0.4f); EXPECTCY(0.4);
3663 CONVERT(VarCyFromR4, 0.5f); EXPECTCY(0.5);
3664 CONVERT(VarCyFromR4, 0.6f); EXPECTCY(0.6);
3665 CONVERT(VarCyFromR4, 1.5f); EXPECTCY(1.5);
3666 CONVERT(VarCyFromR4, 1.00009f); EXPECTCY(1.0001);
3667 CONVERT(VarCyFromR4, -1.00001f); EXPECTCY(-1);
3668 CONVERT(VarCyFromR4, -1.00005f); EXPECTCY(-1);
3669 CONVERT(VarCyFromR4, -0.00009f); EXPECTCY(-0.0001);
3670 CONVERT(VarCyFromR4, -0.00005f); EXPECTCY(0);
3671 CONVERT(VarCyFromR4, -0.00001f); EXPECTCY(0);
3672 CONVERT(VarCyFromR4, 0.00001f); EXPECTCY(0);
3673 CONVERT(VarCyFromR4, 0.00005f); EXPECTCY(0);
3674 CONVERT(VarCyFromR4, 0.00009f); EXPECTCY(0.0001);
3675 CONVERT(VarCyFromR4, -1.00001f); EXPECTCY(-1);
3676 CONVERT(VarCyFromR4, -1.00005f); EXPECTCY(-1);
3677 CONVERT(VarCyFromR4, -1.00009f); EXPECTCY(-1.0001);
3680 static void test_VarCyFromR8(void)
3682 CONVVARS(DOUBLE);
3684 CHECKPTR(VarCyFromR8);
3686 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3687 /* Test our rounding is exactly the same. This fails if the special x86
3688 * code is taken out of VarCyFromR8.
3690 CONVERT(VarCyFromR8, -461168601842738.7904); EXPECTCY64(0xbfffffff, 0xffffff23);
3691 #endif
3693 CONVERT(VarCyFromR8, -4611686018427388416.1); EXPECT_OVERFLOW;
3694 CONVERT(VarCyFromR8, -1.0); EXPECTCY(-1);
3695 CONVERT(VarCyFromR8, -0.0); EXPECTCY(0);
3696 CONVERT(VarCyFromR8, 1.0); EXPECTCY(1);
3697 CONVERT(VarCyFromR8, 4611686018427387648.0); EXPECT_OVERFLOW;
3699 /* Rounding */
3700 CONVERT(VarCyFromR8, -1.5f); EXPECTCY(-1.5);
3701 CONVERT(VarCyFromR8, -0.6f); EXPECTCY(-0.6);
3702 CONVERT(VarCyFromR8, -0.5f); EXPECTCY(-0.5);
3703 CONVERT(VarCyFromR8, -0.4f); EXPECTCY(-0.4);
3704 CONVERT(VarCyFromR8, 0.4f); EXPECTCY(0.4);
3705 CONVERT(VarCyFromR8, 0.5f); EXPECTCY(0.5);
3706 CONVERT(VarCyFromR8, 0.6f); EXPECTCY(0.6);
3707 CONVERT(VarCyFromR8, 1.5f); EXPECTCY(1.5);
3708 CONVERT(VarCyFromR8, 1.00009f); EXPECTCY(1.0001);
3709 CONVERT(VarCyFromR8, -1.00001f); EXPECTCY(-1);
3710 CONVERT(VarCyFromR8, -1.00005f); EXPECTCY(-1);
3711 CONVERT(VarCyFromR8, -0.00009f); EXPECTCY(-0.0001);
3712 CONVERT(VarCyFromR8, -0.00005f); EXPECTCY(0);
3713 CONVERT(VarCyFromR8, -0.00001f); EXPECTCY(0);
3714 CONVERT(VarCyFromR8, 0.00001f); EXPECTCY(0);
3715 CONVERT(VarCyFromR8, 0.00005f); EXPECTCY(0);
3716 CONVERT(VarCyFromR8, 0.00009f); EXPECTCY(0.0001);
3717 CONVERT(VarCyFromR8, -1.00001f); EXPECTCY(-1);
3718 CONVERT(VarCyFromR8, -1.00005f); EXPECTCY(-1);
3719 CONVERT(VarCyFromR8, -1.00009f); EXPECTCY(-1.0001);
3722 static void test_VarCyFromBool(void)
3724 CONVVARS(VARIANT_BOOL);
3725 int i;
3727 CHECKPTR(VarCyFromBool);
3728 for (i = -32768; i < 32768; i++)
3730 CONVERT(VarCyFromBool, i); EXPECTCY(i);
3734 static void test_VarCyFromI8(void)
3736 CONVVARS(LONG64);
3738 CHECKPTR(VarCyFromI8);
3739 CONVERT_I8(VarCyFromI8, -214749, 2728163227ul); EXPECT_OVERFLOW;
3740 CONVERT_I8(VarCyFromI8, -214749, 2728163228ul); EXPECTCY64(2147483648ul,15808);
3741 CONVERT(VarCyFromI8, -1); EXPECTCY(-1);
3742 CONVERT(VarCyFromI8, 0); EXPECTCY(0);
3743 CONVERT(VarCyFromI8, 1); EXPECTCY(1);
3744 CONVERT_I8(VarCyFromI8, 214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3745 CONVERT_I8(VarCyFromI8, 214748, 1566804069); EXPECT_OVERFLOW;
3748 static void test_VarCyFromUI8(void)
3750 CONVVARS(ULONG64);
3752 CHECKPTR(VarCyFromUI8);
3753 CONVERT(VarCyFromUI8, 0); EXPECTCY(0);
3754 CONVERT(VarCyFromUI8, 1); EXPECTCY(1);
3755 CONVERT_I8(VarCyFromUI8, 214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3756 CONVERT_I8(VarCyFromUI8, 214748, 1566804069); EXPECTCY64(2147483647ul, 4294961488ul);
3757 CONVERT_I8(VarCyFromUI8, 214748, 1566804070); EXPECT_OVERFLOW;
3758 CONVERT_I8(VarCyFromUI8, 214749, 1566804068); EXPECT_OVERFLOW;
3761 static void test_VarCyFromDec(void)
3763 CONVVARS(DECIMAL);
3765 CHECKPTR(VarCyFromDec);
3767 CONVERT_BADDEC(VarCyFromDec);
3769 CONVERT_DEC(VarCyFromDec,0,0x80,0,1); EXPECTCY(-1);
3770 CONVERT_DEC(VarCyFromDec,0,0,0,0); EXPECTCY(0);
3771 CONVERT_DEC(VarCyFromDec,0,0,0,1); EXPECTCY(1);
3773 CONVERT_DEC64(VarCyFromDec,0,0,0,214748, 1566804068); EXPECTCY64(2147483647ul, 4294951488ul);
3774 CONVERT_DEC64(VarCyFromDec,0,0,0,214748, 1566804069); EXPECTCY64(2147483647ul, 4294961488ul);
3775 CONVERT_DEC64(VarCyFromDec,0,0,0,214748, 1566804070); EXPECT_OVERFLOW;
3776 CONVERT_DEC64(VarCyFromDec,0,0,0,214749, 1566804068); EXPECT_OVERFLOW;
3778 CONVERT_DEC(VarCyFromDec,2,0,0,100); EXPECTCY(1);
3779 CONVERT_DEC(VarCyFromDec,2,0x80,0,100); EXPECTCY(-1);
3780 CONVERT_DEC(VarCyFromDec,2,0x80,0,1); EXPECTCY(-0.01);
3781 CONVERT_DEC(VarCyFromDec,2,0,0,1); EXPECTCY(0.01);
3782 CONVERT_DEC(VarCyFromDec,2,0x80,0,1); EXPECTCY(-0.01);
3783 CONVERT_DEC(VarCyFromDec,2,0,0,999); EXPECTCY(9.99);
3784 CONVERT_DEC(VarCyFromDec,2,0x80,0,999); EXPECTCY(-9.99);
3785 CONVERT_DEC(VarCyFromDec,2,0,0,1500); EXPECTCY(15);
3786 CONVERT_DEC(VarCyFromDec,2,0x80,0,1500); EXPECTCY(-15);
3789 static void test_VarCyFromDate(void)
3791 CONVVARS(DATE);
3793 CHECKPTR(VarCyFromDate);
3795 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3796 CONVERT(VarCyFromR8, -461168601842738.7904); EXPECTCY64(0xbfffffff, 0xffffff23);
3797 #endif
3799 CONVERT(VarCyFromDate, -1.0); EXPECTCY(-1);
3800 CONVERT(VarCyFromDate, -0.0); EXPECTCY(0);
3801 CONVERT(VarCyFromDate, 1.0); EXPECTCY(1);
3802 CONVERT(VarCyFromDate, -4611686018427388416.1); EXPECT_OVERFLOW;
3803 CONVERT(VarCyFromDate, 4611686018427387648.0); EXPECT_OVERFLOW;
3805 /* Rounding */
3806 CONVERT(VarCyFromDate, -1.5f); EXPECTCY(-1.5);
3807 CONVERT(VarCyFromDate, -0.6f); EXPECTCY(-0.6);
3808 CONVERT(VarCyFromDate, -0.5f); EXPECTCY(-0.5);
3809 CONVERT(VarCyFromDate, -0.4f); EXPECTCY(-0.4);
3810 CONVERT(VarCyFromDate, 0.4f); EXPECTCY(0.4);
3811 CONVERT(VarCyFromDate, 0.5f); EXPECTCY(0.5);
3812 CONVERT(VarCyFromDate, 0.6f); EXPECTCY(0.6);
3813 CONVERT(VarCyFromDate, 1.5f); EXPECTCY(1.5);
3814 CONVERT(VarCyFromDate, 1.00009f); EXPECTCY(1.0001);
3815 CONVERT(VarCyFromDate, -1.00001f); EXPECTCY(-1);
3816 CONVERT(VarCyFromDate, -1.00005f); EXPECTCY(-1);
3817 CONVERT(VarCyFromDate, -0.00009f); EXPECTCY(-0.0001);
3818 CONVERT(VarCyFromDate, -0.00005f); EXPECTCY(0);
3819 CONVERT(VarCyFromDate, -0.00001f); EXPECTCY(0);
3820 CONVERT(VarCyFromDate, 0.00001f); EXPECTCY(0);
3821 CONVERT(VarCyFromDate, 0.00005f); EXPECTCY(0);
3822 CONVERT(VarCyFromDate, 0.00009f); EXPECTCY(0.0001);
3823 CONVERT(VarCyFromDate, -1.00001f); EXPECTCY(-1);
3824 CONVERT(VarCyFromDate, -1.00005f); EXPECTCY(-1);
3825 CONVERT(VarCyFromDate, -1.00009f); EXPECTCY(-1.0001);
3828 #define MATHVARS1 HRESULT hres; double left = 0.0; CY cyLeft, out
3829 #define MATHVARS2 MATHVARS1; double right = 0.0; CY cyRight
3830 #define MATH1(func, l) left = (double)l; pVarCyFromR8(left, &cyLeft); hres = p##func(cyLeft, &out)
3831 #define MATH2(func, l, r) left = (double)l; right = (double)r; \
3832 pVarCyFromR8(left, &cyLeft); pVarCyFromR8(right, &cyRight); \
3833 hres = p##func(cyLeft, cyRight, &out)
3835 static void test_VarCyAdd(void)
3837 MATHVARS2;
3839 CHECKPTR(VarCyAdd);
3840 MATH2(VarCyAdd, 0.5, 0.5); EXPECTCY(1);
3841 MATH2(VarCyAdd, 0.5, -0.4); EXPECTCY(0.1);
3842 MATH2(VarCyAdd, 0.5, -0.6); EXPECTCY(-0.1);
3843 MATH2(VarCyAdd, -0.5, -0.5); EXPECTCY(-1);
3844 MATH2(VarCyAdd, -922337203685476.0, -922337203685476.0); EXPECT_OVERFLOW;
3845 MATH2(VarCyAdd, -922337203685476.0, 922337203685476.0); EXPECTCY(0);
3846 MATH2(VarCyAdd, 922337203685476.0, -922337203685476.0); EXPECTCY(0);
3847 MATH2(VarCyAdd, 922337203685476.0, 922337203685476.0); EXPECT_OVERFLOW;
3850 static void test_VarCyMul(void)
3852 MATHVARS2;
3854 CHECKPTR(VarCyMul);
3855 MATH2(VarCyMul, 534443.0, 0.0); EXPECTCY(0);
3856 MATH2(VarCyMul, 0.5, 0.5); EXPECTCY(0.25);
3857 MATH2(VarCyMul, 0.5, -0.4); EXPECTCY(-0.2);
3858 MATH2(VarCyMul, 0.5, -0.6); EXPECTCY(-0.3);
3859 MATH2(VarCyMul, -0.5, -0.5); EXPECTCY(0.25);
3860 MATH2(VarCyMul, 922337203685476.0, 20000); EXPECT_OVERFLOW;
3863 static void test_VarCySub(void)
3865 MATHVARS2;
3867 CHECKPTR(VarCySub);
3868 MATH2(VarCySub, 0.5, 0.5); EXPECTCY(0);
3869 MATH2(VarCySub, 0.5, -0.4); EXPECTCY(0.9);
3870 MATH2(VarCySub, 0.5, -0.6); EXPECTCY(1.1);
3871 MATH2(VarCySub, -0.5, -0.5); EXPECTCY(0);
3872 MATH2(VarCySub, -922337203685476.0, -922337203685476.0); EXPECTCY(0);
3873 MATH2(VarCySub, -922337203685476.0, 922337203685476.0); EXPECT_OVERFLOW;
3874 MATH2(VarCySub, 922337203685476.0, -922337203685476.0); EXPECT_OVERFLOW;
3875 MATH2(VarCySub, 922337203685476.0, 922337203685476.0); EXPECTCY(0);
3878 static void test_VarCyAbs(void)
3880 MATHVARS1;
3882 CHECKPTR(VarCyAbs);
3883 MATH1(VarCyAbs, 0.5); EXPECTCY(0.5);
3884 MATH1(VarCyAbs, -0.5); EXPECTCY(0.5);
3885 MATH1(VarCyAbs, 922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3886 MATH1(VarCyAbs, -922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3889 static void test_VarCyNeg(void)
3891 MATHVARS1;
3893 CHECKPTR(VarCyNeg);
3894 MATH1(VarCyNeg, 0.5); EXPECTCY(-0.5);
3895 MATH1(VarCyNeg, -0.5); EXPECTCY(0.5);
3896 MATH1(VarCyNeg, 922337203685476.0); EXPECTCY64(2147483648ul,15808);
3897 MATH1(VarCyNeg, -922337203685476.0); EXPECTCY64(2147483647ul,4294951488ul);
3900 #define MATHMULI4(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3901 hres = pVarCyMulI4(cyLeft, right, &out)
3903 static void test_VarCyMulI4(void)
3905 MATHVARS1;
3906 LONG right;
3908 CHECKPTR(VarCyMulI4);
3909 MATHMULI4(534443.0, 0); EXPECTCY(0);
3910 MATHMULI4(0.5, 1); EXPECTCY(0.5);
3911 MATHMULI4(0.5, 2); EXPECTCY(1);
3912 MATHMULI4(922337203685476.0, 1); EXPECTCY64(2147483647ul,4294951488ul);
3913 MATHMULI4(922337203685476.0, 2); EXPECT_OVERFLOW;
3916 #define MATHMULI8(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3917 hres = pVarCyMulI8(cyLeft, right, &out)
3919 static void test_VarCyMulI8(void)
3921 MATHVARS1;
3922 LONG64 right;
3924 CHECKPTR(VarCyMulI8);
3925 MATHMULI8(534443.0, 0); EXPECTCY(0);
3926 MATHMULI8(0.5, 1); EXPECTCY(0.5);
3927 MATHMULI8(0.5, 2); EXPECTCY(1);
3928 MATHMULI8(922337203685476.0, 1); EXPECTCY64(2147483647ul,4294951488ul);
3929 MATHMULI8(922337203685476.0, 2); EXPECT_OVERFLOW;
3932 #define MATHCMP(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); pVarCyFromR8(right, &cyRight); \
3933 hres = pVarCyCmp(cyLeft, cyRight)
3935 static void test_VarCyCmp(void)
3937 HRESULT hres;
3938 double left = 0.0, right = 0.0;
3939 CY cyLeft, cyRight;
3941 CHECKPTR(VarCyCmp);
3942 MATHCMP(-1.0, -1.0); EXPECT_EQ;
3943 MATHCMP(-1.0, 0.0); EXPECT_LT;
3944 MATHCMP(-1.0, 1.0); EXPECT_LT;
3945 MATHCMP(-1.0, 2.0); EXPECT_LT;
3946 MATHCMP(0.0, 1.0); EXPECT_LT;
3947 MATHCMP(0.0, 0.0); EXPECT_EQ;
3948 MATHCMP(0.0, -1.0); EXPECT_GT;
3949 MATHCMP(1.0, -1.0); EXPECT_GT;
3950 MATHCMP(1.0, 0.0); EXPECT_GT;
3951 MATHCMP(1.0, 1.0); EXPECT_EQ;
3952 MATHCMP(1.0, 2.0); EXPECT_LT;
3955 #define MATHCMPR8(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3956 hres = pVarCyCmpR8(cyLeft, right);
3958 static void test_VarCyCmpR8(void)
3960 HRESULT hres;
3961 double left = 0.0;
3962 CY cyLeft;
3963 double right;
3965 CHECKPTR(VarCyCmpR8);
3966 MATHCMPR8(-1.0, -1.0); EXPECT_EQ;
3967 MATHCMPR8(-1.0, 0.0); EXPECT_LT;
3968 MATHCMPR8(-1.0, 1.0); EXPECT_LT;
3969 MATHCMPR8(-1.0, 2.0); EXPECT_LT;
3970 MATHCMPR8(0.0, 1.0); EXPECT_LT;
3971 MATHCMPR8(0.0, 0.0); EXPECT_EQ;
3972 MATHCMPR8(0.0, -1.0); EXPECT_GT;
3973 MATHCMPR8(1.0, -1.0); EXPECT_GT;
3974 MATHCMPR8(1.0, 0.0); EXPECT_GT;
3975 MATHCMPR8(1.0, 1.0); EXPECT_EQ;
3976 MATHCMPR8(1.0, 2.0); EXPECT_LT;
3979 #undef MATHRND
3980 #define MATHRND(l, r) left = l; right = r; pVarCyFromR8(left, &cyLeft); \
3981 hres = pVarCyRound(cyLeft, right, &out)
3983 static void test_VarCyRound(void)
3985 MATHVARS1;
3986 int right;
3988 CHECKPTR(VarCyRound);
3989 MATHRND(0.5432, 5); EXPECTCY(0.5432);
3990 MATHRND(0.5432, 4); EXPECTCY(0.5432);
3991 MATHRND(0.5432, 3); EXPECTCY(0.543);
3992 MATHRND(0.5432, 2); EXPECTCY(0.54);
3993 MATHRND(0.5432, 1); EXPECTCY(0.5);
3994 MATHRND(0.5532, 0); EXPECTCY(1);
3995 MATHRND(0.5532, -1); EXPECT_INVALID;
3997 MATHRND(0.5568, 5); EXPECTCY(0.5568);
3998 MATHRND(0.5568, 4); EXPECTCY(0.5568);
3999 MATHRND(0.5568, 3); EXPECTCY(0.557);
4000 MATHRND(0.5568, 2); EXPECTCY(0.56);
4001 MATHRND(0.5568, 1); EXPECTCY(0.6);
4002 MATHRND(0.5568, 0); EXPECTCY(1);
4003 MATHRND(0.5568, -1); EXPECT_INVALID;
4005 MATHRND(0.4999, 0); EXPECTCY(0);
4006 MATHRND(0.5000, 0); EXPECTCY(0);
4007 MATHRND(0.5001, 0); EXPECTCY(1);
4008 MATHRND(1.4999, 0); EXPECTCY(1);
4009 MATHRND(1.5000, 0); EXPECTCY(2);
4010 MATHRND(1.5001, 0); EXPECTCY(2);
4013 #define MATHFIX(l) left = l; pVarCyFromR8(left, &cyLeft); \
4014 hres = pVarCyFix(cyLeft, &out)
4016 static void test_VarCyFix(void)
4018 MATHVARS1;
4020 CHECKPTR(VarCyFix);
4021 MATHFIX(-1.0001); EXPECTCY(-1);
4022 MATHFIX(-1.4999); EXPECTCY(-1);
4023 MATHFIX(-1.5001); EXPECTCY(-1);
4024 MATHFIX(-1.9999); EXPECTCY(-1);
4025 MATHFIX(-0.0001); EXPECTCY(0);
4026 MATHFIX(-0.4999); EXPECTCY(0);
4027 MATHFIX(-0.5001); EXPECTCY(0);
4028 MATHFIX(-0.9999); EXPECTCY(0);
4029 MATHFIX(0.0001); EXPECTCY(0);
4030 MATHFIX(0.4999); EXPECTCY(0);
4031 MATHFIX(0.5001); EXPECTCY(0);
4032 MATHFIX(0.9999); EXPECTCY(0);
4033 MATHFIX(1.0001); EXPECTCY(1);
4034 MATHFIX(1.4999); EXPECTCY(1);
4035 MATHFIX(1.5001); EXPECTCY(1);
4036 MATHFIX(1.9999); EXPECTCY(1);
4039 #define MATHINT(l) left = l; pVarCyFromR8(left, &cyLeft); \
4040 hres = pVarCyInt(cyLeft, &out)
4042 static void test_VarCyInt(void)
4044 MATHVARS1;
4046 CHECKPTR(VarCyInt);
4047 MATHINT(-1.0001); EXPECTCY(-2);
4048 MATHINT(-1.4999); EXPECTCY(-2);
4049 MATHINT(-1.5001); EXPECTCY(-2);
4050 MATHINT(-1.9999); EXPECTCY(-2);
4051 MATHINT(-0.0001); EXPECTCY(-1);
4052 MATHINT(-0.4999); EXPECTCY(-1);
4053 MATHINT(-0.5001); EXPECTCY(-1);
4054 MATHINT(-0.9999); EXPECTCY(-1);
4055 MATHINT(0.0001); EXPECTCY(0);
4056 MATHINT(0.4999); EXPECTCY(0);
4057 MATHINT(0.5001); EXPECTCY(0);
4058 MATHINT(0.9999); EXPECTCY(0);
4059 MATHINT(1.0001); EXPECTCY(1);
4060 MATHINT(1.4999); EXPECTCY(1);
4061 MATHINT(1.5001); EXPECTCY(1);
4062 MATHINT(1.9999); EXPECTCY(1);
4066 * VT_DECIMAL
4069 #undef CONV_TYPE
4070 #define CONV_TYPE DECIMAL
4072 #define EXPECTDEC(scl, sgn, hi, lo) ok(hres == S_OK && \
4073 S(U(out)).scale == (BYTE)(scl) && S(U(out)).sign == (BYTE)(sgn) && \
4074 out.Hi32 == (ULONG)(hi) && U1(out).Lo64 == (ULONG64)(lo), \
4075 "expected (%d,%d,%d,(%x %x)), got (%d,%d,%d,(%x %x)) hres 0x%08x\n", \
4076 scl, sgn, hi, (LONG)((LONG64)(lo) >> 32), (LONG)((lo) & 0xffffffff), S(U(out)).scale, \
4077 S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres)
4079 #define EXPECTDEC64(scl, sgn, hi, mid, lo) ok(hres == S_OK && \
4080 S(U(out)).scale == (BYTE)(scl) && S(U(out)).sign == (BYTE)(sgn) && \
4081 out.Hi32 == (ULONG)(hi) && S1(U1(out)).Mid32 == (ULONG)(mid) && \
4082 S1(U1(out)).Lo32 == (ULONG)(lo), \
4083 "expected (%d,%d,%d,(%x %x)), got (%d,%d,%d,(%x %x)) hres 0x%08x\n", \
4084 scl, sgn, hi, (LONG)(mid), (LONG)(lo), S(U(out)).scale, \
4085 S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres)
4087 /* expect either a positive or negative zero */
4088 #define EXPECTDECZERO() ok(hres == S_OK && S(U(out)).scale == 0 && \
4089 (S(U(out)).sign == 0 || S(U(out)).sign == 0x80) && out.Hi32 == 0 && U1(out).Lo64 == 0, \
4090 "expected zero, got (%d,%d,%d,(%x %x)) hres 0x%08x\n", \
4091 S(U(out)).scale, S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres)
4093 #define EXPECTDECI if (i < 0) EXPECTDEC(0, 0x80, 0, -i); else EXPECTDEC(0, 0, 0, i)
4095 static void test_VarDecFromI1(void)
4097 CONVVARS(signed char);
4098 int i;
4100 CHECKPTR(VarDecFromI1);
4101 for (i = -128; i < 128; i++)
4103 CONVERT(VarDecFromI1,i); EXPECTDECI;
4107 static void test_VarDecFromI2(void)
4109 CONVVARS(SHORT);
4110 int i;
4112 CHECKPTR(VarDecFromI2);
4113 for (i = -32768; i < 32768; i++)
4115 CONVERT(VarDecFromI2,i); EXPECTDECI;
4119 static void test_VarDecFromI4(void)
4121 CONVVARS(LONG);
4122 int i;
4124 CHECKPTR(VarDecFromI4);
4125 for (i = -32768; i < 32768; i++)
4127 CONVERT(VarDecFromI4,i); EXPECTDECI;
4131 static void test_VarDecFromI8(void)
4133 CONVVARS(LONG64);
4134 int i;
4136 CHECKPTR(VarDecFromI8);
4137 for (i = -32768; i < 32768; i++)
4139 CONVERT(VarDecFromI8,i); EXPECTDECI;
4143 static void test_VarDecFromUI1(void)
4145 CONVVARS(BYTE);
4146 int i;
4148 CHECKPTR(VarDecFromUI1);
4149 for (i = 0; i < 256; i++)
4151 CONVERT(VarDecFromUI1,i); EXPECTDECI;
4155 static void test_VarDecFromUI2(void)
4157 CONVVARS(USHORT);
4158 int i;
4160 CHECKPTR(VarDecFromUI2);
4161 for (i = 0; i < 65536; i++)
4163 CONVERT(VarDecFromUI2,i); EXPECTDECI;
4167 static void test_VarDecFromUI4(void)
4169 CONVVARS(ULONG);
4170 int i;
4172 CHECKPTR(VarDecFromUI4);
4173 for (i = 0; i < 65536; i++)
4175 CONVERT(VarDecFromUI4,i); EXPECTDECI;
4179 static void test_VarDecFromUI8(void)
4181 CONVVARS(ULONG64);
4182 int i;
4184 CHECKPTR(VarDecFromUI8);
4185 for (i = 0; i < 65536; i++)
4187 CONVERT(VarDecFromUI8,i); EXPECTDECI;
4191 static void test_VarDecFromBool(void)
4193 CONVVARS(SHORT);
4194 int i;
4196 CHECKPTR(VarDecFromBool);
4197 /* Test all possible type values. Note that the result is reduced to 0 or -1 */
4198 for (i = -32768; i < 0; i++)
4200 CONVERT(VarDecFromBool,i);
4201 if (i)
4202 EXPECTDEC(0,0x80,0,1);
4203 else
4204 EXPECTDEC(0,0,0,0);
4208 static void test_VarDecFromR4(void)
4210 CONVVARS(float);
4212 CHECKPTR(VarDecFromR4);
4214 CONVERT(VarDecFromR4,-0.6f); EXPECTDEC(1,0x80,0,6);
4215 CONVERT(VarDecFromR4,-0.5f); EXPECTDEC(1,0x80,0,5);
4216 CONVERT(VarDecFromR4,-0.4f); EXPECTDEC(1,0x80,0,4);
4217 CONVERT(VarDecFromR4,0.0f); EXPECTDEC(0,0,0,0);
4218 CONVERT(VarDecFromR4,0.4f); EXPECTDEC(1,0,0,4);
4219 CONVERT(VarDecFromR4,0.5f); EXPECTDEC(1,0,0,5);
4220 CONVERT(VarDecFromR4,0.6f); EXPECTDEC(1,0,0,6);
4223 static void test_VarDecFromR8(void)
4225 CONVVARS(double);
4227 CHECKPTR(VarDecFromR8);
4229 CONVERT(VarDecFromR8,-0.6); EXPECTDEC(1,0x80,0,6);
4230 CONVERT(VarDecFromR8,-0.5); EXPECTDEC(1,0x80,0,5);
4231 CONVERT(VarDecFromR8,-0.4); EXPECTDEC(1,0x80,0,4);
4232 CONVERT(VarDecFromR8,0.0); EXPECTDEC(0,0,0,0);
4233 CONVERT(VarDecFromR8,0.4); EXPECTDEC(1,0,0,4);
4234 CONVERT(VarDecFromR8,0.5); EXPECTDEC(1,0,0,5);
4235 CONVERT(VarDecFromR8,0.6); EXPECTDEC(1,0,0,6);
4238 static void test_VarDecFromDate(void)
4240 CONVVARS(DATE);
4242 CHECKPTR(VarDecFromDate);
4244 CONVERT(VarDecFromDate,-0.6); EXPECTDEC(1,0x80,0,6);
4245 CONVERT(VarDecFromDate,-0.5); EXPECTDEC(1,0x80,0,5);
4246 CONVERT(VarDecFromDate,-0.4); EXPECTDEC(1,0x80,0,4);
4247 CONVERT(VarDecFromDate,0.0); EXPECTDEC(0,0,0,0);
4248 CONVERT(VarDecFromDate,0.4); EXPECTDEC(1,0,0,4);
4249 CONVERT(VarDecFromDate,0.5); EXPECTDEC(1,0,0,5);
4250 CONVERT(VarDecFromDate,0.6); EXPECTDEC(1,0,0,6);
4253 static void test_VarDecFromStr(void)
4255 CONVVARS(LCID);
4256 OLECHAR buff[128];
4258 CHECKPTR(VarDecFromStr);
4260 in = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4262 CONVERT_STR(VarDecFromStr,NULL,0); EXPECT_MISMATCH;
4263 CONVERT_STR(VarDecFromStr,"-1", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0x80,0,1);
4264 CONVERT_STR(VarDecFromStr,"0", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0,0,0);
4265 CONVERT_STR(VarDecFromStr,"1", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0,0,1);
4266 CONVERT_STR(VarDecFromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECTDEC(1,0,0,5);
4267 CONVERT_STR(VarDecFromStr,"4294967296", LOCALE_NOUSEROVERRIDE); EXPECTDEC64(0,0,0,1,0);
4268 CONVERT_STR(VarDecFromStr,"18446744073709551616", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0,1,0);
4269 CONVERT_STR(VarDecFromStr,"4294967296.0", LOCALE_NOUSEROVERRIDE); EXPECTDEC64(0,0,0,1,0);
4270 CONVERT_STR(VarDecFromStr,"18446744073709551616.0", LOCALE_NOUSEROVERRIDE); EXPECTDEC(0,0,1,0);
4273 static void test_VarDecFromCy(void)
4275 CONVVARS(CY);
4277 CHECKPTR(VarDecFromCy);
4279 CONVERT_CY(VarDecFromCy, -1); EXPECTDEC(4,0x80,0,10000);
4280 CONVERT_CY(VarDecFromCy, 0); EXPECTDEC(4,0,0,0);
4281 CONVERT_CY(VarDecFromCy, 1); EXPECTDEC(4,0,0,10000);
4282 CONVERT_CY(VarDecFromCy, 0.5); EXPECTDEC(4,0,0,5000);
4285 #undef MATHVARS1
4286 #define MATHVARS1 HRESULT hres; DECIMAL l, out
4287 #undef MATHVARS2
4288 #define MATHVARS2 MATHVARS1; DECIMAL r
4289 #undef MATH1
4290 #define MATH1(func) hres = p##func(&l, &out)
4291 #undef MATH2
4292 #define MATH2(func) hres = p##func(&l, &r, &out)
4293 #undef MATH3
4294 #define MATH3(func) hres = p##func(&l, r)
4296 static void test_VarDecAbs(void)
4298 MATHVARS1;
4300 CHECKPTR(VarDecAbs);
4301 SETDEC(l,0,0x80,0,1); MATH1(VarDecAbs); EXPECTDEC(0,0,0,1);
4302 SETDEC(l,0,0,0,0); MATH1(VarDecAbs); EXPECTDEC(0,0,0,0);
4303 SETDEC(l,0,0x80,0,0); MATH1(VarDecAbs); EXPECTDEC(0,0,0,0);
4304 SETDEC(l,0,0,0,1); MATH1(VarDecAbs); EXPECTDEC(0,0,0,1);
4306 /* Doesn't check for invalid input */
4307 SETDEC(l,0,0x7f,0,1); MATH1(VarDecAbs); EXPECTDEC(0,0x7f,0,1);
4308 SETDEC(l,0,0x80,29,1); MATH1(VarDecAbs); EXPECTDEC(0,0,29,1);
4311 static void test_VarDecNeg(void)
4313 MATHVARS1;
4315 CHECKPTR(VarDecNeg);
4316 SETDEC(l,0,0x80,0,1); MATH1(VarDecNeg); EXPECTDEC(0,0,0,1);
4317 SETDEC(l,0,0,0,0); MATH1(VarDecNeg); EXPECTDEC(0,0x80,0,0); /* '-0'! */
4318 SETDEC(l,0,0x80,0,0); MATH1(VarDecNeg); EXPECTDEC(0,0,0,0);
4319 SETDEC(l,0,0,0,1); MATH1(VarDecNeg); EXPECTDEC(0,0x80,0,1);
4321 /* Doesn't check for invalid input */
4322 SETDEC(l,0,0x7f,0,1); MATH1(VarDecNeg); EXPECTDEC(0,0xff,0,1);
4323 SETDEC(l,0,0x80,29,1); MATH1(VarDecNeg); EXPECTDEC(0,0,29,1);
4324 SETDEC(l,0,0,29,1); MATH1(VarDecNeg); EXPECTDEC(0,0x80,29,1);
4327 static void test_VarDecAdd(void)
4329 MATHVARS2;
4331 CHECKPTR(VarDecAdd);
4332 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecAdd); EXPECTDEC(0,0,0,0);
4333 SETDEC(l,0,0,0,0); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,1);
4334 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,1);
4336 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,0); MATH2(VarDecAdd); EXPECTDEC(0,0,0,1);
4337 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,2);
4338 SETDEC(l,0,0,0,1); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd); EXPECTDECZERO();
4339 SETDEC(l,0,0,0,1); SETDEC(r,0,0x80,0,2); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,1);
4341 SETDEC(l,0,0x80,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,1);
4342 SETDEC(l,0,0x80,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDECZERO();
4343 SETDEC(l,0,0x80,0,1); SETDEC(r,0,0,0,2); MATH2(VarDecAdd); EXPECTDEC(0,0,0,1);
4344 SETDEC(l,0,0x80,0,1); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,2);
4345 SETDEC(l,0,0x80,0,2); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0x80,0,1);
4347 SETDEC(l,0,0,0,0xffffffff); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,0xfffffffe);
4348 SETDEC(l,0,0,0,0xffffffff); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,(ULONG64)1 << 32);
4349 SETDEC(l,0,0,0,0xffffffff); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0,(ULONG64)1 << 32);
4351 SETDEC64(l,0,0,0,0xffffffff,0); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC64(0,0,0,0xffffffff,1);
4352 SETDEC64(l,0,0,0,0xffffffff,0); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd);
4353 EXPECTDEC64(0,0,0,0xfffffffe,0xffffffff);
4355 SETDEC64(l,0,0,0,0xffffffff,0xffffffff); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,1,0);
4356 SETDEC64(l,0,0,0,0xffffffff,0xffffffff); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd);
4357 EXPECTDEC64(0,0,0,0xffffffff,0xfffffffe);
4359 SETDEC(l,0,0,0xffffffff,0); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(0,0,0xffffffff,1);
4360 SETDEC(l,0,0,0xffffffff,0); SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd);
4361 EXPECTDEC64(0,0,0xfffffffe,0xffffffff,0xffffffff);
4363 SETDEC64(l,0,0,0xffffffff,0xffffffff,0xffffffff);SETDEC(r,0,0x80,0,1); MATH2(VarDecAdd);
4364 EXPECTDEC64(0,0,0xffffffff,0xffffffff,0xfffffffe);
4365 SETDEC64(l,0,0,0xffffffff,0xffffffff,0xffffffff);SETDEC(r,0,0,0,1); MATH2(VarDecAdd);
4366 ok(hres == DISP_E_OVERFLOW,"Expected overflow, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
4367 S(U(out)).scale, S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres);
4369 SETDEC(l,3,128,0,123456); SETDEC64(r,0,0,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF);
4370 MATH2(VarDecAdd); todo_wine EXPECTDEC64(0,0,-1,0xFFFFFFFF,0xFFFFFF84);
4372 /* Promotes to the highest scale, so here the results are in the scale of 2 */
4373 SETDEC(l,2,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecAdd); EXPECTDEC(2,0,0,0);
4374 SETDEC(l,2,0,0,100); SETDEC(r,0,0,0,1); MATH2(VarDecAdd); EXPECTDEC(2,0,0,200);
4377 static void test_VarDecSub(void)
4379 MATHVARS2;
4381 CHECKPTR(VarDecSub);
4382 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecSub); EXPECTDECZERO();
4383 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecSub); EXPECTDEC(0,0x80,0,1);
4384 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecSub); EXPECTDECZERO();
4385 SETDEC(l,0,0,0,1); SETDEC(r,0,0x80,0,1); MATH2(VarDecSub); EXPECTDEC(0,0,0,2);
4388 static void test_VarDecMul(void)
4390 MATHVARS2;
4392 CHECKPTR(VarDecMul);
4393 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecMul); EXPECTDEC(0,0,0,0);
4394 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,0); MATH2(VarDecMul); EXPECTDEC(0,0,0,0);
4395 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecMul); EXPECTDEC(0,0,0,0);
4396 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecMul); EXPECTDEC(0,0,0,1);
4397 SETDEC(l,0,0,0,45000);SETDEC(r,0,0,0,2); MATH2(VarDecMul); EXPECTDEC(0,0,0,90000);
4398 SETDEC(l,0,0,0,2); SETDEC(r,0,0,0,45000); MATH2(VarDecMul); EXPECTDEC(0,0,0,90000);
4400 SETDEC(l,0,0x80,0,2); SETDEC(r,0,0,0,2); MATH2(VarDecMul); EXPECTDEC(0,0x80,0,4);
4401 SETDEC(l,0,0,0,2); SETDEC(r,0,0x80,0,2); MATH2(VarDecMul); EXPECTDEC(0,0x80,0,4);
4402 SETDEC(l,0,0x80,0,2); SETDEC(r,0,0x80,0,2); MATH2(VarDecMul); EXPECTDEC(0,0,0,4);
4404 SETDEC(l,4,0,0,2); SETDEC(r,0,0,0,2); MATH2(VarDecMul); EXPECTDEC(4,0,0,4);
4405 SETDEC(l,0,0,0,2); SETDEC(r,3,0,0,2); MATH2(VarDecMul); EXPECTDEC(3,0,0,4);
4406 SETDEC(l,4,0,0,2); SETDEC(r,3,0,0,2); MATH2(VarDecMul); EXPECTDEC(7,0,0,4);
4407 /* this last one shows that native oleaut32 does *not* gratuitously seize opportunities
4408 to reduce the scale if possible - the canonical result for the expected value is (6,0,0,1)
4410 SETDEC(l,4,0,0,5); SETDEC(r,3,0,0,2); MATH2(VarDecMul); EXPECTDEC(7,0,0,10);
4412 SETDEC64(l,0,0,0,0xFFFFFFFF,0xFFFFFFFF); SETDEC(r,0,0,0,2); MATH2(VarDecMul); EXPECTDEC64(0,0,1,0xFFFFFFFF,0xFFFFFFFE);
4413 SETDEC(l,0,0,0,2); SETDEC64(r,0,0,0,0xFFFFFFFF,0xFFFFFFFF); MATH2(VarDecMul); EXPECTDEC64(0,0,1,0xFFFFFFFF,0xFFFFFFFE);
4414 SETDEC(l,0,0,1,1); SETDEC(r,0,0,0,0x80000000); MATH2(VarDecMul); EXPECTDEC(0,0,0x80000000,0x80000000);
4415 SETDEC(l,0,0,0,0x80000000); SETDEC(r,0,0,1,1); MATH2(VarDecMul); EXPECTDEC(0,0,0x80000000,0x80000000);
4417 /* near-overflow, used as a reference */
4418 SETDEC64(l,0,0,0,0xFFFFFFFF,0xFFFFFFFF); SETDEC(r,0,0,0,2000000000); MATH2(VarDecMul);EXPECTDEC64(0,0,1999999999,0xFFFFFFFF,0x88CA6C00);
4419 /* actual overflow - right operand is 10 times the previous value */
4420 SETDEC64(l,0,0,0,0xFFFFFFFF,0xFFFFFFFF); SETDEC64(r,0,0,0,4,0xA817C800); MATH2(VarDecMul);
4421 ok(hres == DISP_E_OVERFLOW,"Expected overflow, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
4422 S(U(out)).scale, S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres);
4423 /* here, native oleaut32 has an opportunity to avert the overflow, by reducing the scale of the result */
4424 SETDEC64(l,1,0,0,0xFFFFFFFF,0xFFFFFFFF); SETDEC64(r,0,0,0,4,0xA817C800); MATH2(VarDecMul);EXPECTDEC64(0,0,1999999999,0xFFFFFFFF,0x88CA6C00);
4426 /* near-overflow, used as a reference */
4427 SETDEC64(l,0,0,1,0xFFFFFFFF,0xFFFFFFFE); SETDEC(r,0,0,0,1000000000); MATH2(VarDecMul);EXPECTDEC64(0,0,1999999999,0xFFFFFFFF,0x88CA6C00);
4428 /* actual overflow - right operand is 10 times the previous value */
4429 SETDEC64(l,0,0,1,0xFFFFFFFF,0xFFFFFFFE); SETDEC64(r,0,0,0,2,0x540BE400); MATH2(VarDecMul);
4430 ok(hres == DISP_E_OVERFLOW,"Expected overflow, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
4431 S(U(out)).scale, S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres);
4432 /* here, native oleaut32 has an opportunity to avert the overflow, by reducing the scale of the result */
4433 SETDEC64(l,1,0,1,0xFFFFFFFF,0xFFFFFFFE); SETDEC64(r,0,0,0,2,0x540BE400); MATH2(VarDecMul);EXPECTDEC64(0,0,1999999999,0xFFFFFFFF,0x88CA6C00);
4435 /* this one shows that native oleaut32 is willing to lose significant digits in order to avert an overflow */
4436 SETDEC64(l,2,0,0,0xFFFFFFFF,0xFFFFFFFF); SETDEC64(r,0,0,0,9,0x502F9001); MATH2(VarDecMul);EXPECTDEC64(1,0,0xee6b2800,0x19999998,0xab2e719a);
4439 static void test_VarDecDiv(void)
4441 MATHVARS2;
4443 CHECKPTR(VarDecDiv);
4444 /* identity divisions */
4445 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,1); MATH2(VarDecDiv); EXPECTDEC(0,0,0,0);
4446 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecDiv); EXPECTDEC(0,0,0,1);
4447 SETDEC(l,1,0,0,1); SETDEC(r,0,0,0,1); MATH2(VarDecDiv); EXPECTDEC(1,0,0,1);
4449 /* exact divisions */
4450 SETDEC(l,0,0,0,45); SETDEC(r,0,0,0,9); MATH2(VarDecDiv); EXPECTDEC(0,0,0,5);
4451 SETDEC(l,1,0,0,45); SETDEC(r,0,0,0,9); MATH2(VarDecDiv); EXPECTDEC(1,0,0,5);
4452 SETDEC(l,0,0,0,45); SETDEC(r,1,0,0,9); MATH2(VarDecDiv); EXPECTDEC(0,0,0,50);
4453 SETDEC(l,1,0,0,45); SETDEC(r,2,0,0,9); MATH2(VarDecDiv); EXPECTDEC(0,0,0,50);
4454 /* these last three results suggest that native oleaut32 scales both operands down to zero
4455 before the division, but does not always try to scale the result, even if it is possible -
4456 analogous to multiplication behavior.
4458 SETDEC(l,1,0,0,45); SETDEC(r,1,0,0,9); MATH2(VarDecDiv); EXPECTDEC(0,0,0,5);
4459 SETDEC(l,2,0,0,450); SETDEC(r,1,0,0,9); MATH2(VarDecDiv);
4460 if (S(U(out)).scale == 1) EXPECTDEC(1,0,0,50);
4461 else EXPECTDEC(0,0,0,5);
4463 /* inexact divisions */
4464 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,180700362,0x14b700cb,0x05555555);
4465 SETDEC(l,1,0,0,1); SETDEC(r,0,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,18070036,0x35458014,0x4d555555);
4466 SETDEC(l,0,0,0,1); SETDEC(r,1,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,1807003620,0xcf2607ee,0x35555555);
4467 SETDEC(l,1,0,0,1); SETDEC(r,2,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,1807003620,0xcf2607ee,0x35555555);
4468 SETDEC(l,1,0,0,1); SETDEC(r,1,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,180700362,0x14b700cb,0x05555555);
4469 SETDEC(l,2,0,0,10); SETDEC(r,1,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,180700362,0x14b700cb,0x05555555);
4471 /* this one shows that native oleaut32 rounds up the result */
4472 SETDEC(l,0,0,0,2); SETDEC(r,0,0,0,3); MATH2(VarDecDiv); EXPECTDEC64(28,0,361400724,0x296e0196,0x0aaaaaab);
4474 /* sign tests */
4475 SETDEC(l,0,0x80,0,45); SETDEC(r,0,0,0,9); MATH2(VarDecDiv); EXPECTDEC(0,0x80,0,5);
4476 SETDEC(l,0,0,0,45); SETDEC(r,0,0x80,0,9); MATH2(VarDecDiv);EXPECTDEC(0,0x80,0,5);
4477 SETDEC(l,0,0x80,0,45); SETDEC(r,0,0x80,0,9); MATH2(VarDecDiv);EXPECTDEC(0,0,0,5);
4479 /* oddballs */
4480 SETDEC(l,0,0,0,0); SETDEC(r,0,0,0,0); MATH2(VarDecDiv);/* indeterminate */
4481 ok(hres == DISP_E_DIVBYZERO,"Expected division-by-zero, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
4482 S(U(out)).scale, S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres);
4483 SETDEC(l,0,0,0,1); SETDEC(r,0,0,0,0); MATH2(VarDecDiv);/* division by zero */
4484 ok(hres == DISP_E_DIVBYZERO,"Expected division-by-zero, got (%d,%d,%d,(%8x,%8x)x) hres 0x%08x\n",
4485 S(U(out)).scale, S(U(out)).sign, out.Hi32, S1(U1(out)).Mid32, S1(U1(out)).Lo32, hres);
4489 static void test_VarDecCmp(void)
4491 MATHVARS1;
4493 CHECKPTR(VarDecCmp);
4495 SETDEC(l,0,0,0,1); SETDEC(out,0,0,0,1); MATH1(VarDecCmp); EXPECT_EQ;
4496 SETDEC(l,0,0,0,1); SETDEC(out,0,0,0,0); MATH1(VarDecCmp); EXPECT_GT;
4497 SETDEC(l,0,0,0,1); SETDEC(out,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_LT;
4499 SETDEC(l,0,0,0,1); SETDEC(out,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_GT;
4500 SETDEC(l,0,0,0,1); SETDEC(out,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_GT;
4501 SETDEC(l,0,0,0,1); SETDEC(out,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_GT;
4503 SETDEC(l,0,DECIMAL_NEG,0,1); SETDEC(out,0,0,0,1); MATH1(VarDecCmp); EXPECT_LT;
4504 SETDEC(l,0,DECIMAL_NEG,0,1); SETDEC(out,0,0,0,0); MATH1(VarDecCmp); EXPECT_LT;
4505 SETDEC(l,0,DECIMAL_NEG,0,1); SETDEC(out,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_LT;
4507 SETDEC(l,0,DECIMAL_NEG,0,1); SETDEC(out,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_EQ;
4508 SETDEC(l,0,DECIMAL_NEG,0,1); SETDEC(out,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_LT;
4509 SETDEC(l,0,DECIMAL_NEG,0,1); SETDEC(out,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_GT;
4511 SETDEC(l,0,0,0,0); SETDEC(out,0,0,0,1); MATH1(VarDecCmp); EXPECT_LT;
4512 SETDEC(l,0,0,0,0); SETDEC(out,0,0,0,0); MATH1(VarDecCmp); EXPECT_EQ;
4513 SETDEC(l,0,0,0,0); SETDEC(out,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_LT;
4515 SETDEC(l,0,0,0,0); SETDEC(out,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_GT;
4516 SETDEC(l,0,0,0,0); SETDEC(out,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_EQ;
4517 SETDEC(l,0,0,0,0); SETDEC(out,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_GT;
4519 SETDEC(l,0,DECIMAL_NEG,0,0); SETDEC(out,0,0,0,1); MATH1(VarDecCmp); EXPECT_LT;
4520 SETDEC(l,0,DECIMAL_NEG,0,0); SETDEC(out,0,0,0,0); MATH1(VarDecCmp); EXPECT_EQ;
4521 SETDEC(l,0,DECIMAL_NEG,0,0); SETDEC(out,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_LT;
4523 SETDEC(l,0,DECIMAL_NEG,0,0); SETDEC(out,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_GT;
4524 SETDEC(l,0,DECIMAL_NEG,0,0); SETDEC(out,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_EQ;
4525 SETDEC(l,0,DECIMAL_NEG,0,0); SETDEC(out,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_GT;
4527 SETDEC(l,0,0,-1,-1); SETDEC(out,0,0,0,1); MATH1(VarDecCmp); EXPECT_GT;
4528 SETDEC(l,0,0,-1,-1); SETDEC(out,0,0,0,0); MATH1(VarDecCmp); EXPECT_GT;
4529 SETDEC(l,0,0,-1,-1); SETDEC(out,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_EQ;
4531 SETDEC(l,0,0,-1,-1); SETDEC(out,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_GT;
4532 SETDEC(l,0,0,-1,-1); SETDEC(out,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_GT;
4533 SETDEC(l,0,0,-1,-1); SETDEC(out,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_GT;
4535 SETDEC(l,0,DECIMAL_NEG,-1,-1); SETDEC(out,0,0,0,1); MATH1(VarDecCmp); EXPECT_LT;
4536 SETDEC(l,0,DECIMAL_NEG,-1,-1); SETDEC(out,0,0,0,0); MATH1(VarDecCmp); EXPECT_LT;
4537 SETDEC(l,0,DECIMAL_NEG,-1,-1); SETDEC(out,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_LT;
4539 SETDEC(l,0,DECIMAL_NEG,-1,-1); SETDEC(out,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_LT;
4540 SETDEC(l,0,DECIMAL_NEG,-1,-1); SETDEC(out,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_LT;
4541 SETDEC(l,0,DECIMAL_NEG,-1,-1); SETDEC(out,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_EQ;
4544 SETDEC(out,0,0,0,1); SETDEC(l,0,0,0,1); MATH1(VarDecCmp); EXPECT_EQ;
4545 SETDEC(out,0,0,0,1); SETDEC(l,0,0,0,0); MATH1(VarDecCmp); EXPECT_LT;
4546 SETDEC(out,0,0,0,1); SETDEC(l,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_GT;
4548 SETDEC(out,0,0,0,1); SETDEC(l,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_LT;
4549 SETDEC(out,0,0,0,1); SETDEC(l,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_LT;
4550 SETDEC(out,0,0,0,1); SETDEC(l,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_LT;
4552 SETDEC(out,0,DECIMAL_NEG,0,1); SETDEC(l,0,0,0,1); MATH1(VarDecCmp); EXPECT_GT;
4553 SETDEC(out,0,DECIMAL_NEG,0,1); SETDEC(l,0,0,0,0); MATH1(VarDecCmp); EXPECT_GT;
4554 SETDEC(out,0,DECIMAL_NEG,0,1); SETDEC(l,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_GT;
4556 SETDEC(out,0,DECIMAL_NEG,0,1); SETDEC(l,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_EQ;
4557 SETDEC(out,0,DECIMAL_NEG,0,1); SETDEC(l,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_GT;
4558 SETDEC(out,0,DECIMAL_NEG,0,1); SETDEC(l,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_LT;
4560 SETDEC(out,0,0,0,0); SETDEC(l,0,0,0,1); MATH1(VarDecCmp); EXPECT_GT;
4561 SETDEC(out,0,0,0,0); SETDEC(l,0,0,0,0); MATH1(VarDecCmp); EXPECT_EQ;
4562 SETDEC(out,0,0,0,0); SETDEC(l,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_GT;
4564 SETDEC(out,0,0,0,0); SETDEC(l,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_LT;
4565 SETDEC(out,0,0,0,0); SETDEC(l,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_EQ;
4566 SETDEC(out,0,0,0,0); SETDEC(l,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_LT;
4568 SETDEC(out,0,DECIMAL_NEG,0,0); SETDEC(l,0,0,0,1); MATH1(VarDecCmp); EXPECT_GT;
4569 SETDEC(out,0,DECIMAL_NEG,0,0); SETDEC(l,0,0,0,0); MATH1(VarDecCmp); EXPECT_EQ;
4570 SETDEC(out,0,DECIMAL_NEG,0,0); SETDEC(l,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_GT;
4572 SETDEC(out,0,DECIMAL_NEG,0,0); SETDEC(l,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_LT;
4573 SETDEC(out,0,DECIMAL_NEG,0,0); SETDEC(l,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_EQ;
4574 SETDEC(out,0,DECIMAL_NEG,0,0); SETDEC(l,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_LT;
4576 SETDEC(out,0,0,-1,-1); SETDEC(l,0,0,0,1); MATH1(VarDecCmp); EXPECT_LT;
4577 SETDEC(out,0,0,-1,-1); SETDEC(l,0,0,0,0); MATH1(VarDecCmp); EXPECT_LT;
4578 SETDEC(out,0,0,-1,-1); SETDEC(l,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_EQ;
4580 SETDEC(out,0,0,-1,-1); SETDEC(l,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_LT;
4581 SETDEC(out,0,0,-1,-1); SETDEC(l,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_LT;
4582 SETDEC(out,0,0,-1,-1); SETDEC(l,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_LT;
4584 SETDEC(out,0,DECIMAL_NEG,-1,-1); SETDEC(l,0,0,0,1); MATH1(VarDecCmp); EXPECT_GT;
4585 SETDEC(out,0,DECIMAL_NEG,-1,-1); SETDEC(l,0,0,0,0); MATH1(VarDecCmp); EXPECT_GT;
4586 SETDEC(out,0,DECIMAL_NEG,-1,-1); SETDEC(l,0,0,-1,-1); MATH1(VarDecCmp); EXPECT_GT;
4588 SETDEC(out,0,DECIMAL_NEG,-1,-1); SETDEC(l,0,DECIMAL_NEG,0,1); MATH1(VarDecCmp); EXPECT_GT;
4589 SETDEC(out,0,DECIMAL_NEG,-1,-1); SETDEC(l,0,DECIMAL_NEG,0,0); MATH1(VarDecCmp); EXPECT_GT;
4590 SETDEC(out,0,DECIMAL_NEG,-1,-1); SETDEC(l,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_EQ;
4592 SETDEC(l,3,0,0,123456); SETDEC64(out,0,0,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF);
4593 MATH1(VarDecCmp); todo_wine EXPECT_LT;
4596 static void test_VarDecCmpR8(void)
4598 HRESULT hres;
4599 DECIMAL l;
4600 double r;
4602 CHECKPTR(VarDecCmpR8);
4604 SETDEC(l,0,0,0,1); r = 0.0; MATH3(VarDecCmpR8); EXPECT_GT;
4605 SETDEC(l,0,0,0,1); r = 0.1; MATH3(VarDecCmpR8); EXPECT_GT;
4606 SETDEC(l,0,0,0,1); r = -0.1; MATH3(VarDecCmpR8); EXPECT_GT;
4608 SETDEC(l,0,DECIMAL_NEG,0,1); r = 0.0; MATH3(VarDecCmpR8); EXPECT_LT;
4609 SETDEC(l,0,DECIMAL_NEG,0,1); r = 0.1; MATH3(VarDecCmpR8); EXPECT_LT;
4610 SETDEC(l,0,DECIMAL_NEG,0,1); r = -0.1; MATH3(VarDecCmpR8); EXPECT_LT;
4612 SETDEC(l,0,0,0,0); r = 0.0; MATH3(VarDecCmpR8); EXPECT_EQ;
4613 SETDEC(l,0,0,0,0); r = 0.1; MATH3(VarDecCmpR8); EXPECT_LT;
4614 SETDEC(l,0,0,0,0); r = -0.1; MATH3(VarDecCmpR8); EXPECT_GT;
4616 SETDEC(l,0,DECIMAL_NEG,0,0); r = 0.0; MATH3(VarDecCmpR8); EXPECT_EQ;
4617 SETDEC(l,0,DECIMAL_NEG,0,0); r = 0.1; MATH3(VarDecCmpR8); EXPECT_LT;
4618 SETDEC(l,0,DECIMAL_NEG,0,0); r = -0.1; MATH3(VarDecCmpR8); EXPECT_GT;
4620 SETDEC(l,0,0,0,1); r = DECIMAL_NEG; MATH3(VarDecCmpR8); EXPECT_LT;
4621 SETDEC(l,0,DECIMAL_NEG,0,0); r = DECIMAL_NEG; MATH3(VarDecCmpR8); EXPECT_LT;
4622 SETDEC(l,0,0,-1,-1); r = DECIMAL_NEG; MATH3(VarDecCmpR8); EXPECT_GT;
4623 SETDEC(l,0,DECIMAL_NEG,-1,-1); r = DECIMAL_NEG; MATH3(VarDecCmpR8); EXPECT_LT;
4626 #define CLEAR(x) memset(&(x), 0xBB, sizeof(x))
4628 static void test_VarDecRound(void)
4630 HRESULT hres;
4631 DECIMAL l, out;
4633 CHECKPTR(VarDecRound);
4635 CLEAR(out); SETDEC(l, 0, 0, 0, 1); hres = pVarDecRound(&l, 3, &out); EXPECTDEC(0, 0, 0, 1);
4637 CLEAR(out); SETDEC(l, 0, 0, 0, 1); hres = pVarDecRound(&l, 0, &out); EXPECTDEC(0, 0, 0, 1);
4638 CLEAR(out); SETDEC(l, 1, 0, 0, 1); hres = pVarDecRound(&l, 0, &out); EXPECTDEC(0, 0, 0, 0);
4639 CLEAR(out); SETDEC(l, 1, 0, 0, 1); hres = pVarDecRound(&l, 1, &out); EXPECTDEC(1, 0, 0, 1);
4640 CLEAR(out); SETDEC(l, 2, 0, 0, 11); hres = pVarDecRound(&l, 1, &out); EXPECTDEC(1, 0, 0, 1);
4641 CLEAR(out); SETDEC(l, 2, 0, 0, 15); hres = pVarDecRound(&l, 1, &out); EXPECTDEC(1, 0, 0, 2);
4642 CLEAR(out); SETDEC(l, 6, 0, 0, 550001); hres = pVarDecRound(&l, 1, &out); EXPECTDEC(1, 0, 0, 6);
4644 CLEAR(out); SETDEC(l, 0, DECIMAL_NEG, 0, 1); hres = pVarDecRound(&l, 0, &out); EXPECTDEC(0, DECIMAL_NEG, 0, 1);
4645 CLEAR(out); SETDEC(l, 1, DECIMAL_NEG, 0, 1); hres = pVarDecRound(&l, 0, &out); EXPECTDEC(0, DECIMAL_NEG, 0, 0);
4646 CLEAR(out); SETDEC(l, 1, DECIMAL_NEG, 0, 1); hres = pVarDecRound(&l, 1, &out); EXPECTDEC(1, DECIMAL_NEG, 0, 1);
4647 CLEAR(out); SETDEC(l, 2, DECIMAL_NEG, 0, 11); hres = pVarDecRound(&l, 1, &out); EXPECTDEC(1, DECIMAL_NEG, 0, 1);
4648 CLEAR(out); SETDEC(l, 2, DECIMAL_NEG, 0, 15); hres = pVarDecRound(&l, 1, &out); EXPECTDEC(1, DECIMAL_NEG, 0, 2);
4649 CLEAR(out); SETDEC(l, 6, DECIMAL_NEG, 0, 550001); hres = pVarDecRound(&l, 1, &out); EXPECTDEC(1, DECIMAL_NEG, 0, 6);
4651 CLEAR(out); SETDEC64(l, 0, 0, 0xffffffff, 0xffffffff, 0xffffffff); hres = pVarDecRound(&l, 0, &out); EXPECTDEC64(0, 0, 0xffffffff, 0xffffffff, 0xffffffff);
4652 CLEAR(out); SETDEC64(l, 28, 0, 0xffffffff, 0xffffffff, 0xffffffff); hres = pVarDecRound(&l, 0, &out); EXPECTDEC64(0, 0, 0, 0, 8);
4653 CLEAR(out); SETDEC64(l, 0, DECIMAL_NEG, 0xffffffff, 0xffffffff, 0xffffffff); hres = pVarDecRound(&l, 0, &out); EXPECTDEC64(0, DECIMAL_NEG, 0xffffffff, 0xffffffff, 0xffffffff);
4654 CLEAR(out); SETDEC64(l, 28, DECIMAL_NEG, 0xffffffff, 0xffffffff, 0xffffffff); hres = pVarDecRound(&l, 0, &out); EXPECTDEC64(0, DECIMAL_NEG, 0, 0, 8);
4656 CLEAR(out); SETDEC(l, 2, 0, 0, 0); hres = pVarDecRound(&l, 1, &out); EXPECTDEC(1, 0, 0, 0);
4660 * VT_BOOL
4663 #undef CONV_TYPE
4664 #define CONV_TYPE VARIANT_BOOL
4665 #undef EXPECTRES
4666 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%d")
4667 #undef CONVERTRANGE
4668 #define CONVERTRANGE(func,start,end) for (i = start; i < end; i++) { \
4669 CONVERT(func, i); if (i) { EXPECT(VARIANT_TRUE); } else { EXPECT(VARIANT_FALSE); } }
4671 static void test_VarBoolFromI1(void)
4673 CONVVARS(signed char);
4674 int i;
4676 CHECKPTR(VarBoolFromI1);
4677 CONVERTRANGE(VarBoolFromI1, -128, 128);
4680 static void test_VarBoolFromUI1(void)
4682 CONVVARS(BYTE);
4683 int i;
4685 CHECKPTR(VarBoolFromUI1);
4686 CONVERTRANGE(VarBoolFromUI1, 0, 256);
4689 static void test_VarBoolFromI2(void)
4691 CONVVARS(SHORT);
4692 int i;
4694 CHECKPTR(VarBoolFromI2);
4695 CONVERTRANGE(VarBoolFromI2, -32768, 32768);
4698 static void test_VarBoolFromUI2(void)
4700 CONVVARS(USHORT);
4701 int i;
4703 CHECKPTR(VarBoolFromUI2);
4704 CONVERTRANGE(VarBoolFromUI2, 0, 65536);
4707 static void test_VarBoolFromI4(void)
4709 CONVVARS(int);
4711 CHECKPTR(VarBoolFromI4);
4712 CONVERT(VarBoolFromI4, 0x80000000); EXPECT(VARIANT_TRUE);
4713 CONVERT(VarBoolFromI4, -1); EXPECT(VARIANT_TRUE);
4714 CONVERT(VarBoolFromI4, 0); EXPECT(VARIANT_FALSE);
4715 CONVERT(VarBoolFromI4, 1); EXPECT(VARIANT_TRUE);
4716 CONVERT(VarBoolFromI4, 0x7fffffff); EXPECT(VARIANT_TRUE);
4719 static void test_VarBoolFromUI4(void)
4721 CONVVARS(ULONG);
4723 CHECKPTR(VarBoolFromUI4);
4724 CONVERT(VarBoolFromI4, 0); EXPECT(VARIANT_FALSE);
4725 CONVERT(VarBoolFromI4, 1); EXPECT(VARIANT_TRUE);
4726 CONVERT(VarBoolFromI4, 0x80000000); EXPECT(VARIANT_TRUE);
4729 static void test_VarBoolFromR4(void)
4731 CONVVARS(FLOAT);
4733 CHECKPTR(VarBoolFromR4);
4734 CONVERT(VarBoolFromR4, -1.0f); EXPECT(VARIANT_TRUE);
4735 CONVERT(VarBoolFromR4, 0.0f); EXPECT(VARIANT_FALSE);
4736 CONVERT(VarBoolFromR4, 1.0f); EXPECT(VARIANT_TRUE);
4737 CONVERT(VarBoolFromR4, 1.5f); EXPECT(VARIANT_TRUE);
4739 /* Rounding */
4740 CONVERT(VarBoolFromR4, -1.5f); EXPECT(VARIANT_TRUE);
4741 CONVERT(VarBoolFromR4, -0.6f); EXPECT(VARIANT_TRUE);
4742 CONVERT(VarBoolFromR4, -0.5f); EXPECT(VARIANT_TRUE);
4743 CONVERT(VarBoolFromR4, -0.4f); EXPECT(VARIANT_TRUE);
4744 CONVERT(VarBoolFromR4, 0.4f); EXPECT(VARIANT_TRUE);
4745 CONVERT(VarBoolFromR4, 0.5f); EXPECT(VARIANT_TRUE);
4746 CONVERT(VarBoolFromR4, 0.6f); EXPECT(VARIANT_TRUE);
4747 CONVERT(VarBoolFromR4, 1.5f); EXPECT(VARIANT_TRUE);
4750 static void test_VarBoolFromR8(void)
4752 CONVVARS(DOUBLE);
4754 /* Hopefully we made the point with R4 above that rounding is
4755 * irrelevant, so we'll skip that for R8 and Date
4757 CHECKPTR(VarBoolFromR8);
4758 CONVERT(VarBoolFromR8, -1.0); EXPECT(VARIANT_TRUE);
4759 CONVERT(VarBoolFromR8, -0.0); EXPECT(VARIANT_FALSE);
4760 CONVERT(VarBoolFromR8, 1.0); EXPECT(VARIANT_TRUE);
4763 static void test_VarBoolFromCy(void)
4765 CONVVARS(CY);
4767 CHECKPTR(VarBoolFromCy);
4768 CONVERT_CY(VarBoolFromCy, -32769); EXPECT(VARIANT_TRUE);
4769 CONVERT_CY(VarBoolFromCy, -32768); EXPECT(VARIANT_TRUE);
4770 CONVERT_CY(VarBoolFromCy, -1); EXPECT(VARIANT_TRUE);
4771 CONVERT_CY(VarBoolFromCy, 0); EXPECT(VARIANT_FALSE);
4772 CONVERT_CY(VarBoolFromCy, 1); EXPECT(VARIANT_TRUE);
4773 CONVERT_CY(VarBoolFromCy, 32767); EXPECT(VARIANT_TRUE);
4774 CONVERT_CY(VarBoolFromCy, 32768); EXPECT(VARIANT_TRUE);
4777 static void test_VarBoolFromI8(void)
4779 CONVVARS(LONG64);
4781 CHECKPTR(VarBoolFromI8);
4782 CONVERT(VarBoolFromI8, -1); EXPECT(VARIANT_TRUE);
4783 CONVERT(VarBoolFromI8, 0); EXPECT(VARIANT_FALSE);
4784 CONVERT(VarBoolFromI8, 1); EXPECT(VARIANT_TRUE);
4787 static void test_VarBoolFromUI8(void)
4789 CONVVARS(ULONG64);
4791 CHECKPTR(VarBoolFromUI8);
4792 CONVERT(VarBoolFromUI8, 0); EXPECT(VARIANT_FALSE);
4793 CONVERT(VarBoolFromUI8, 1); EXPECT(VARIANT_TRUE);
4796 static void test_VarBoolFromDec(void)
4798 CONVVARS(DECIMAL);
4800 CHECKPTR(VarBoolFromDec);
4801 CONVERT_BADDEC(VarBoolFromDec);
4803 CONVERT_DEC(VarBoolFromDec,29,0,0,0); EXPECT_INVALID;
4804 CONVERT_DEC(VarBoolFromDec,0,0x1,0,0); EXPECT_INVALID;
4805 CONVERT_DEC(VarBoolFromDec,0,0x40,0,0); EXPECT_INVALID;
4806 CONVERT_DEC(VarBoolFromDec,0,0x7f,0,0); EXPECT_INVALID;
4808 CONVERT_DEC(VarBoolFromDec,0,0x80,0,1); EXPECT(VARIANT_TRUE);
4809 CONVERT_DEC(VarBoolFromDec,0,0,0,0); EXPECT(VARIANT_FALSE);
4810 CONVERT_DEC(VarBoolFromDec,0,0,0,1); EXPECT(VARIANT_TRUE);
4811 CONVERT_DEC(VarBoolFromDec,0,0,1,0); EXPECT(VARIANT_TRUE);
4813 CONVERT_DEC(VarBoolFromDec,2,0,0,CY_MULTIPLIER); EXPECT(VARIANT_TRUE);
4814 CONVERT_DEC(VarBoolFromDec,2,0x80,0,CY_MULTIPLIER); EXPECT(VARIANT_TRUE);
4817 static void test_VarBoolFromDate(void)
4819 CONVVARS(DATE);
4821 CHECKPTR(VarBoolFromDate);
4822 CONVERT(VarBoolFromDate, -1.0); EXPECT(VARIANT_TRUE);
4823 CONVERT(VarBoolFromDate, -0.0); EXPECT(VARIANT_FALSE);
4824 CONVERT(VarBoolFromDate, 1.0); EXPECT(VARIANT_TRUE);
4827 static void test_VarBoolFromStr(void)
4829 CONVVARS(LCID);
4830 OLECHAR buff[128];
4832 CHECKPTR(VarBoolFromStr);
4834 in = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4836 CONVERT_STR(VarBoolFromStr,NULL,0);
4837 if (hres != E_INVALIDARG)
4838 EXPECT_MISMATCH;
4840 /* #FALSE# and #TRUE# Are always accepted */
4841 CONVERT_STR(VarBoolFromStr,"#FALSE#",0); EXPECT(VARIANT_FALSE);
4842 CONVERT_STR(VarBoolFromStr,"#TRUE#",0); EXPECT(VARIANT_TRUE);
4844 /* Match of #FALSE# and #TRUE# is case sensitive */
4845 CONVERT_STR(VarBoolFromStr,"#False#",0); EXPECT_MISMATCH;
4846 /* But match against English is not */
4847 CONVERT_STR(VarBoolFromStr,"false",0); EXPECT(VARIANT_FALSE);
4848 CONVERT_STR(VarBoolFromStr,"False",0); EXPECT(VARIANT_FALSE);
4849 /* On/Off and yes/no are not acceptable inputs, with any flags set */
4850 CONVERT_STR(VarBoolFromStr,"On",0xffffffff); EXPECT_MISMATCH;
4851 CONVERT_STR(VarBoolFromStr,"Yes",0xffffffff); EXPECT_MISMATCH;
4853 /* Change the LCID. This doesn't make any difference for text,unless we ask
4854 * to check local boolean text with the VARIANT_LOCALBOOL flag. */
4855 in = MAKELCID(MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT), SORT_DEFAULT);
4857 /* #FALSE# and #TRUE# are accepted in all locales */
4858 CONVERT_STR(VarBoolFromStr,"#FALSE#",0); EXPECT(VARIANT_FALSE);
4859 CONVERT_STR(VarBoolFromStr,"#TRUE#",0); EXPECT(VARIANT_TRUE);
4860 CONVERT_STR(VarBoolFromStr,"#FALSE#",VARIANT_LOCALBOOL); EXPECT(VARIANT_FALSE);
4861 CONVERT_STR(VarBoolFromStr,"#TRUE#",VARIANT_LOCALBOOL); EXPECT(VARIANT_TRUE);
4863 /* English is accepted regardless of the locale */
4864 CONVERT_STR(VarBoolFromStr,"false",0); EXPECT(VARIANT_FALSE);
4865 /* And is still not case sensitive */
4866 CONVERT_STR(VarBoolFromStr,"False",0); EXPECT(VARIANT_FALSE);
4868 if (has_locales)
4870 /* French is rejected without VARIANT_LOCALBOOL */
4871 CONVERT_STR(VarBoolFromStr,"faux",0); EXPECT_MISMATCH;
4872 /* But accepted if this flag is given */
4873 CONVERT_STR(VarBoolFromStr,"faux",VARIANT_LOCALBOOL); EXPECT(VARIANT_FALSE);
4874 /* Regardless of case - from this we assume locale text comparisons ignore case */
4875 CONVERT_STR(VarBoolFromStr,"Faux",VARIANT_LOCALBOOL); EXPECT(VARIANT_FALSE);
4877 /* Changing the locale prevents the localised text from being compared -
4878 * this demonstrates that only the indicated LCID and English are searched */
4879 in = MAKELCID(MAKELANGID(LANG_POLISH, SUBLANG_DEFAULT), SORT_DEFAULT);
4880 CONVERT_STR(VarBoolFromStr,"faux",VARIANT_LOCALBOOL); EXPECT_MISMATCH;
4883 /* Numeric strings are read as 0 or non-0 */
4884 CONVERT_STR(VarBoolFromStr,"0",0); EXPECT(VARIANT_FALSE);
4885 CONVERT_STR(VarBoolFromStr,"-1",0); EXPECT(VARIANT_TRUE);
4886 CONVERT_STR(VarBoolFromStr,"+1",0); EXPECT(VARIANT_TRUE);
4888 if (has_locales)
4890 /* Numeric strings are read as floating point numbers. The line below fails
4891 * because '.' is not a valid decimal separator for Polish numbers */
4892 CONVERT_STR(VarBoolFromStr,"0.1",LOCALE_NOUSEROVERRIDE); EXPECT_MISMATCH;
4895 /* Changing the lcid back to US English reads the r8 correctly */
4896 in = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4897 CONVERT_STR(VarBoolFromStr,"0.1",LOCALE_NOUSEROVERRIDE); EXPECT(VARIANT_TRUE);
4900 static void test_VarBoolCopy(void)
4902 COPYTEST(1, VT_BOOL, V_BOOL(&vSrc), V_BOOL(&vDst), V_BOOLREF(&vSrc), V_BOOLREF(&vDst), "%d");
4905 #define BOOL_STR(flags, str) hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, flags, VT_BSTR); \
4906 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && \
4907 V_BSTR(&vDst) && !memcmp(V_BSTR(&vDst), str, sizeof(str)), \
4908 "hres=0x%X, type=%d (should be VT_BSTR), *bstr='%c'\n", \
4909 hres, V_VT(&vDst), V_BSTR(&vDst) ? *V_BSTR(&vDst) : '?'); \
4910 VariantClear(&vDst)
4912 static void test_VarBoolChangeTypeEx(void)
4914 static const WCHAR szTrue[] = { 'T','r','u','e','\0' };
4915 static const WCHAR szFalse[] = { 'F','a','l','s','e','\0' };
4916 static const WCHAR szFaux[] = { 'F','a','u','x','\0' };
4917 HRESULT hres;
4918 VARIANT_BOOL in;
4919 VARIANTARG vSrc, vDst;
4920 LCID lcid;
4922 in = 1;
4924 INITIAL_TYPETEST(VT_BOOL, V_BOOL, "%d");
4925 COMMON_TYPETEST;
4927 /* The common tests convert to a number. Try the different flags */
4928 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4930 V_VT(&vSrc) = VT_BOOL;
4931 V_BOOL(&vSrc) = 1;
4933 BOOL_STR(VARIANT_ALPHABOOL, szTrue);
4934 V_BOOL(&vSrc) = 0;
4935 BOOL_STR(VARIANT_ALPHABOOL, szFalse);
4937 if (has_locales)
4939 lcid = MAKELCID(MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT), SORT_DEFAULT);
4941 /* VARIANT_ALPHABOOL is always English */
4942 BOOL_STR(VARIANT_ALPHABOOL, szFalse);
4943 /* VARIANT_LOCALBOOL uses the localised text */
4944 BOOL_STR(VARIANT_LOCALBOOL, szFaux);
4945 /* Both flags together acts as VARIANT_LOCALBOOL */
4946 BOOL_STR(VARIANT_ALPHABOOL|VARIANT_LOCALBOOL, szFaux);
4951 * BSTR
4954 static void test_VarBstrFromR4(void)
4956 static const WCHAR szNative[] = { '6','5','4','3','2','2','.','3','\0' };
4957 static const WCHAR szZero[] = {'0', '\0'};
4958 static const WCHAR szOneHalf_English[] = { '0','.','5','\0' }; /* uses period */
4959 static const WCHAR szOneHalf_Spanish[] = { '0',',','5','\0' }; /* uses comma */
4960 LCID lcid;
4961 LCID lcid_spanish;
4962 HRESULT hres;
4963 BSTR bstr = NULL;
4965 float f;
4967 CHECKPTR(VarBstrFromR4);
4969 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
4970 lcid_spanish = MAKELCID(MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH), SORT_DEFAULT);
4971 f = 654322.23456f;
4972 hres = pVarBstrFromR4(f, lcid, 0, &bstr);
4973 ok(hres == S_OK, "got hres 0x%08x\n", hres);
4974 if (bstr)
4976 todo_wine {
4977 /* MSDN states that rounding of R4/R8 is dependent on the underlying
4978 * bit pattern of the number and so is architecture dependent. In this
4979 * case Wine returns .2 (which is more correct) and Native returns .3
4981 ok(memcmp(bstr, szNative, sizeof(szNative)) == 0, "string different\n");
4983 SysFreeString(bstr);
4986 f = -0.0;
4987 hres = pVarBstrFromR4(f, lcid, 0, &bstr);
4988 ok(hres == S_OK, "got hres 0x%08x\n", hres);
4989 if (bstr)
4991 if (bstr[0] == '-')
4992 ok(memcmp(bstr + 1, szZero, sizeof(szZero)) == 0, "negative zero (got %s)\n", wtoascii(bstr));
4993 else
4994 ok(memcmp(bstr, szZero, sizeof(szZero)) == 0, "negative zero (got %s)\n", wtoascii(bstr));
4995 SysFreeString(bstr);
4998 /* The following tests that lcid is used for decimal separator even without LOCALE_USE_NLS */
4999 f = 0.5;
5000 hres = pVarBstrFromR4(f, lcid, LOCALE_NOUSEROVERRIDE, &bstr);
5001 ok(hres == S_OK, "got hres 0x%08x\n", hres);
5002 if (bstr)
5004 ok(memcmp(bstr, szOneHalf_English, sizeof(szOneHalf_English)) == 0, "English locale failed (got %s)\n", wtoascii(bstr));
5005 SysFreeString(bstr);
5007 f = 0.5;
5008 hres = pVarBstrFromR4(f, lcid_spanish, LOCALE_NOUSEROVERRIDE, &bstr);
5009 ok(hres == S_OK, "got hres 0x%08x\n", hres);
5010 if (bstr)
5012 ok(memcmp(bstr, szOneHalf_Spanish, sizeof(szOneHalf_Spanish)) == 0, "Spanish locale failed (got %s)\n", wtoascii(bstr));
5013 SysFreeString(bstr);
5017 static void _BSTR_DATE(DATE dt, const char *str, int line)
5019 LCID lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
5020 char buff[256];
5021 BSTR bstr = NULL;
5022 HRESULT hres;
5024 hres = pVarBstrFromDate(dt, lcid, LOCALE_NOUSEROVERRIDE, &bstr);
5025 if (bstr)
5027 WideCharToMultiByte(CP_ACP, 0, bstr, -1, buff, sizeof(buff), 0, 0);
5028 SysFreeString(bstr);
5030 else
5031 buff[0] = 0;
5032 ok_(__FILE__, line)(hres == S_OK && !strcmp(str, buff),
5033 "Expected '%s', got '%s', hres = 0x%08x\n", str, buff, hres);
5036 static void test_VarBstrFromDate(void)
5038 #define BSTR_DATE(dt,str) _BSTR_DATE(dt,str,__LINE__)
5040 CHECKPTR(VarBstrFromDate);
5042 BSTR_DATE(0.0, "12:00:00 AM");
5043 BSTR_DATE(3.34, "1/2/1900 8:09:36 AM");
5044 BSTR_DATE(3339.34, "2/20/1909 8:09:36 AM");
5045 BSTR_DATE(365.00, "12/30/1900");
5046 BSTR_DATE(365.25, "12/30/1900 6:00:00 AM");
5047 BSTR_DATE(1461.0, "12/31/1903");
5048 BSTR_DATE(1461.5, "12/31/1903 12:00:00 PM");
5049 BSTR_DATE(-49192.24, "4/24/1765 5:45:36 AM");
5050 BSTR_DATE(-657434.0, "1/1/100");
5051 BSTR_DATE(2958465.0, "12/31/9999");
5053 #undef BSTR_DATE
5056 static void _BSTR_CY(LONG a, LONG b, const char *str, LCID lcid, int line)
5058 HRESULT hr;
5059 BSTR bstr = NULL;
5060 char buff[256];
5061 CY l;
5063 S(l).Lo = b;
5064 S(l).Hi = a;
5065 hr = pVarBstrFromCy(l, lcid, LOCALE_NOUSEROVERRIDE, &bstr);
5066 ok(hr == S_OK, "got hr 0x%08x\n", hr);
5068 if(bstr)
5070 WideCharToMultiByte(CP_ACP, 0, bstr, -1, buff, sizeof(buff), 0, 0);
5071 SysFreeString(bstr);
5073 else
5074 buff[0] = 0;
5076 if(hr == S_OK)
5078 ok_(__FILE__, line)(!strcmp(str, buff), "Expected '%s', got '%s'\n", str, buff);
5082 static void test_VarBstrFromCy(void)
5084 #define BSTR_CY(a, b, str, lcid) _BSTR_CY(a, b, str, lcid, __LINE__)
5086 LCID en_us, sp;
5088 CHECKPTR(VarBstrFromCy);
5090 en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
5091 sp = MAKELCID(MAKELANGID(LANG_SPANISH, SUBLANG_DEFAULT), SORT_DEFAULT);
5093 BSTR_CY(0, 0, "0", en_us);
5094 BSTR_CY(0, 10000, "1", en_us);
5095 BSTR_CY(0, 15000, "1.5", en_us);
5096 BSTR_CY(0xffffffff, ((15000)^0xffffffff)+1, "-1.5", en_us);
5097 /* (1 << 32) - 1 / 1000 */
5098 BSTR_CY(0, 0xffffffff, "429496.7295", en_us);
5099 /* (1 << 32) / 1000 */
5100 BSTR_CY(1, 0, "429496.7296", en_us);
5101 /* ((1 << 63) - 1)/10000 */
5102 BSTR_CY(0x7fffffff, 0xffffffff, "922337203685477.5807", en_us);
5103 BSTR_CY(0, 9, "0.0009", en_us);
5104 BSTR_CY(0, 9, "0,0009", sp);
5106 #undef BSTR_CY
5109 static void _BSTR_DEC(BYTE scale, BYTE sign, ULONG hi, ULONG mid, ULONGLONG lo, const char *str,
5110 LCID lcid, int line)
5112 char buff[256];
5113 HRESULT hr;
5114 BSTR bstr = NULL;
5115 DECIMAL dec;
5117 SETDEC64(dec, scale, sign, hi, mid, lo);
5118 hr = pVarBstrFromDec(&dec, lcid, LOCALE_NOUSEROVERRIDE, &bstr);
5119 ok_(__FILE__, line)(hr == S_OK, "got hr 0x%08x\n", hr);
5121 if(bstr)
5123 WideCharToMultiByte(CP_ACP, 0, bstr, -1, buff, sizeof(buff), 0, 0);
5124 SysFreeString(bstr);
5126 else
5127 buff[0] = 0;
5129 if(hr == S_OK)
5131 ok_(__FILE__, line)(!strcmp(str, buff), "Expected '%s', got '%s'\n", str, buff);
5135 static void test_VarBstrFromDec(void)
5137 #define BSTR_DEC(scale, sign, hi, lo, str, lcid) _BSTR_DEC(scale, sign, hi, 0, lo, str, lcid, __LINE__)
5138 #define BSTR_DEC64(scale, sign, hi, mid, lo, str, lcid) _BSTR_DEC(scale, sign, hi, mid, lo, str, lcid, __LINE__)
5140 LCID en_us, sp;
5142 CHECKPTR(VarBstrFromDec);
5144 en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
5145 sp = MAKELCID(MAKELANGID(LANG_SPANISH, SUBLANG_DEFAULT), SORT_DEFAULT);
5147 BSTR_DEC(0,0,0,0, "0", en_us);
5149 BSTR_DEC(0,0,0,1, "1", en_us);
5150 BSTR_DEC(1,0,0,10, "1", en_us);
5151 BSTR_DEC(2,0,0,100, "1", en_us);
5152 BSTR_DEC(3,0,0,1000,"1", en_us);
5154 BSTR_DEC(1,0,0,15, "1.5", en_us);
5155 BSTR_DEC(2,0,0,150, "1.5", en_us);
5156 BSTR_DEC(3,0,0,1500,"1.5", en_us);
5158 BSTR_DEC(1,0x80,0,15, "-1.5", en_us);
5160 /* (1 << 32) - 1 */
5161 BSTR_DEC(0,0,0,0xffffffff, "4294967295", en_us);
5162 /* (1 << 32) */
5163 BSTR_DEC64(0,0,0,1,0, "4294967296", en_us);
5164 /* (1 << 64) - 1 */
5165 BSTR_DEC64(0,0,0,0xffffffff,0xffffffff, "18446744073709551615", en_us);
5166 /* (1 << 64) */
5167 BSTR_DEC(0,0,1,0, "18446744073709551616", en_us);
5168 /* (1 << 96) - 1 */
5169 BSTR_DEC64(0,0,0xffffffff,0xffffffff,0xffffffff, "79228162514264337593543950335", en_us);
5170 /* 1 * 10^-10 */
5171 BSTR_DEC(10,0,0,1, "0.0000000001", en_us);
5172 /* ((1 << 96) - 1) * 10^-10 */
5173 BSTR_DEC64(10,0,0xffffffffUL,0xffffffff,0xffffffff, "7922816251426433759.3543950335", en_us);
5174 /* ((1 << 96) - 1) * 10^-28 */
5175 BSTR_DEC64(28,0,0xffffffffUL,0xffffffff,0xffffffff, "7.9228162514264337593543950335", en_us);
5177 /* check leading zeros and decimal sep. for English locale */
5178 BSTR_DEC(4,0,0,9, "0.0009", en_us);
5179 BSTR_DEC(5,0,0,90, "0.0009", en_us);
5180 BSTR_DEC(6,0,0,900, "0.0009", en_us);
5181 BSTR_DEC(7,0,0,9000, "0.0009", en_us);
5183 /* check leading zeros and decimal sep. for Spanish locale */
5184 BSTR_DEC(4,0,0,9, "0,0009", sp);
5185 BSTR_DEC(5,0,0,90, "0,0009", sp);
5186 BSTR_DEC(6,0,0,900, "0,0009", sp);
5187 BSTR_DEC(7,0,0,9000, "0,0009", sp);
5189 #undef BSTR_DEC
5190 #undef BSTR_DEC64
5193 #define _VARBSTRCMP(left,right,lcid,flags,result) \
5194 hres = pVarBstrCmp(left,right,lcid,flags); \
5195 ok(hres == result, "VarBstrCmp: expected " #result ", got hres=0x%x\n", hres)
5196 #define VARBSTRCMP(left,right,flags,result) \
5197 _VARBSTRCMP(left,right,lcid,flags,result)
5199 static void test_VarBstrCmp(void)
5201 LCID lcid;
5202 HRESULT hres;
5203 static const WCHAR sz[] = {'W','u','r','s','c','h','t','\0'};
5204 static const WCHAR szempty[] = {'\0'};
5205 static const WCHAR sz1[] = { 'a',0 };
5206 static const WCHAR sz2[] = { 'A',0 };
5207 static const WCHAR s1[] = { 'a',0 };
5208 static const WCHAR s2[] = { 'a',0,'b' };
5209 static const char sb1[] = {1,0,1};
5210 static const char sb2[] = {1,0,2};
5211 static const char sbchr0[] = {0,0};
5212 static const char sbchr00[] = {0,0,0};
5213 BSTR bstr, bstrempty, bstr2;
5215 CHECKPTR(VarBstrCmp);
5217 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
5218 bstr = SysAllocString(sz);
5219 bstrempty = SysAllocString(szempty);
5221 /* NULL handling. Yepp, MSDN is totally wrong here */
5222 VARBSTRCMP(NULL,NULL,0,VARCMP_EQ);
5223 VARBSTRCMP(bstr,NULL,0,VARCMP_GT);
5224 VARBSTRCMP(NULL,bstr,0,VARCMP_LT);
5226 /* NULL and empty string comparisons */
5227 VARBSTRCMP(bstrempty,NULL,0,VARCMP_EQ);
5228 VARBSTRCMP(NULL,bstrempty,0,VARCMP_EQ);
5230 SysFreeString(bstr);
5231 bstr = SysAllocString(sz1);
5233 bstr2 = SysAllocString(sz2);
5234 VARBSTRCMP(bstr,bstr2,0,VARCMP_LT);
5235 VARBSTRCMP(bstr,bstr2,NORM_IGNORECASE,VARCMP_EQ);
5236 SysFreeString(bstr2);
5237 /* These two strings are considered equal even though one is
5238 * NULL-terminated and the other not.
5240 bstr2 = SysAllocStringLen(s1, sizeof(s1) / sizeof(WCHAR));
5241 VARBSTRCMP(bstr,bstr2,0,VARCMP_EQ);
5242 SysFreeString(bstr2);
5244 /* These two strings are not equal */
5245 bstr2 = SysAllocStringLen(s2, sizeof(s2) / sizeof(WCHAR));
5246 VARBSTRCMP(bstr,bstr2,0,VARCMP_LT);
5247 SysFreeString(bstr2);
5249 SysFreeString(bstr);
5251 bstr = SysAllocStringByteLen(sbchr0, sizeof(sbchr0));
5252 bstr2 = SysAllocStringByteLen(sbchr00, sizeof(sbchr00));
5253 VARBSTRCMP(bstr,bstrempty,0,VARCMP_GT);
5254 VARBSTRCMP(bstrempty,bstr,0,VARCMP_LT);
5255 VARBSTRCMP(bstr2,bstrempty,0,VARCMP_GT);
5256 VARBSTRCMP(bstr2,bstr,0,VARCMP_EQ);
5257 SysFreeString(bstr2);
5258 SysFreeString(bstr);
5260 /* When (LCID == 0) it should be a binary comparison
5261 * so these two strings could not match.
5263 bstr = SysAllocStringByteLen(sb1, sizeof(sb1));
5264 bstr2 = SysAllocStringByteLen(sb2, sizeof(sb2));
5265 lcid = 0;
5266 VARBSTRCMP(bstr,bstr2,0,VARCMP_LT);
5267 SysFreeString(bstr2);
5268 SysFreeString(bstr);
5270 bstr = SysAllocStringByteLen(sbchr0, sizeof(sbchr0));
5271 bstr2 = SysAllocStringByteLen(sbchr00, sizeof(sbchr00));
5272 VARBSTRCMP(bstr,bstrempty,0,VARCMP_GT);
5273 VARBSTRCMP(bstrempty,bstr,0,VARCMP_LT);
5274 VARBSTRCMP(bstr2,bstrempty,0,VARCMP_GT);
5275 VARBSTRCMP(bstr2,bstr,0,VARCMP_GT);
5276 SysFreeString(bstr2);
5277 SysFreeString(bstr);
5278 SysFreeString(bstrempty);
5281 /* Get the internal representation of a BSTR */
5282 static inline LPINTERNAL_BSTR Get(const BSTR lpszString)
5284 return lpszString ? (LPINTERNAL_BSTR)((char*)lpszString - sizeof(DWORD)) : NULL;
5287 static inline BSTR GetBSTR(const LPINTERNAL_BSTR bstr)
5289 return (BSTR)bstr->szString;
5292 static void test_SysStringLen(void)
5294 INTERNAL_BSTR bstr;
5295 BSTR str = GetBSTR(&bstr);
5297 bstr.dwLen = 0;
5298 ok (SysStringLen(str) == 0, "Expected dwLen 0, got %d\n", SysStringLen(str));
5299 bstr.dwLen = 2;
5300 ok (SysStringLen(str) == 1, "Expected dwLen 1, got %d\n", SysStringLen(str));
5303 static void test_SysStringByteLen(void)
5305 INTERNAL_BSTR bstr;
5306 BSTR str = GetBSTR(&bstr);
5308 bstr.dwLen = 0;
5309 ok (SysStringByteLen(str) == 0, "Expected dwLen 0, got %d\n", SysStringByteLen(str));
5310 bstr.dwLen = 2;
5311 ok (SysStringByteLen(str) == 2, "Expected dwLen 2, got %d\n", SysStringByteLen(str));
5314 static void test_SysAllocString(void)
5316 const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
5317 BSTR str;
5319 str = SysAllocString(NULL);
5320 ok (str == NULL, "Expected NULL, got %p\n", str);
5322 str = SysAllocString(szTest);
5323 ok (str != NULL, "Expected non-NULL\n");
5324 if (str)
5326 LPINTERNAL_BSTR bstr = Get(str);
5328 ok (bstr->dwLen == 8, "Expected 8, got %d\n", bstr->dwLen);
5329 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
5330 SysFreeString(str);
5334 static void test_SysAllocStringLen(void)
5336 const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
5337 BSTR str;
5339 /* Very early native dlls do not limit the size of strings, so skip this test */
5340 if (0)
5342 str = SysAllocStringLen(szTest, 0x80000000);
5343 ok (str == NULL, "Expected NULL, got %p\n", str);
5346 str = SysAllocStringLen(NULL, 0);
5347 ok (str != NULL, "Expected non-NULL\n");
5348 if (str)
5350 LPINTERNAL_BSTR bstr = Get(str);
5352 ok (bstr->dwLen == 0, "Expected 0, got %d\n", bstr->dwLen);
5353 ok (!bstr->szString[0], "String not empty\n");
5354 SysFreeString(str);
5357 str = SysAllocStringLen(szTest, 4);
5358 ok (str != NULL, "Expected non-NULL\n");
5359 if (str)
5361 LPINTERNAL_BSTR bstr = Get(str);
5363 ok (bstr->dwLen == 8, "Expected 8, got %d\n", bstr->dwLen);
5364 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
5365 SysFreeString(str);
5369 static void test_SysAllocStringByteLen(void)
5371 const OLECHAR szTest[10] = { 'T','e','s','t','\0' };
5372 const CHAR szTestA[6] = { 'T','e','s','t','\0','?' };
5373 BSTR str;
5375 if (sizeof(void *) == 4) /* not limited to 0x80000000 on Win64 */
5377 str = SysAllocStringByteLen(szTestA, 0x80000000);
5378 ok (str == NULL, "Expected NULL, got %p\n", str);
5381 str = SysAllocStringByteLen(szTestA, 0xffffffff);
5382 ok (str == NULL, "Expected NULL, got %p\n", str);
5384 str = SysAllocStringByteLen(NULL, 0);
5385 ok (str != NULL, "Expected non-NULL\n");
5386 if (str)
5388 LPINTERNAL_BSTR bstr = Get(str);
5390 ok (bstr->dwLen == 0, "Expected 0, got %d\n", bstr->dwLen);
5391 ok (!bstr->szString[0], "String not empty\n");
5392 SysFreeString(str);
5395 str = SysAllocStringByteLen(szTestA, 4);
5396 ok (str != NULL, "Expected non-NULL\n");
5397 if (str)
5399 LPINTERNAL_BSTR bstr = Get(str);
5401 ok (bstr->dwLen == 4, "Expected 4, got %d\n", bstr->dwLen);
5402 ok (!lstrcmpA((LPCSTR)bstr->szString, szTestA), "String different\n");
5403 SysFreeString(str);
5406 /* Odd lengths are allocated rounded up, but truncated at the right position */
5407 str = SysAllocStringByteLen(szTestA, 3);
5408 ok (str != NULL, "Expected non-NULL\n");
5409 if (str)
5411 const CHAR szTestTruncA[4] = { 'T','e','s','\0' };
5412 LPINTERNAL_BSTR bstr = Get(str);
5414 ok (bstr->dwLen == 3, "Expected 3, got %d\n", bstr->dwLen);
5415 ok (!lstrcmpA((LPCSTR)bstr->szString, szTestTruncA), "String different\n");
5416 SysFreeString(str);
5419 str = SysAllocStringByteLen((LPCSTR)szTest, 8);
5420 ok (str != NULL, "Expected non-NULL\n");
5421 if (str)
5423 LPINTERNAL_BSTR bstr = Get(str);
5425 ok (bstr->dwLen == 8, "Expected 8, got %d\n", bstr->dwLen);
5426 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
5427 SysFreeString(str);
5431 static void test_SysReAllocString(void)
5433 const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
5434 const OLECHAR szSmaller[2] = { 'x','\0' };
5435 const OLECHAR szLarger[7] = { 'L','a','r','g','e','r','\0' };
5436 BSTR str;
5438 str = SysAllocStringLen(szTest, 4);
5439 ok (str != NULL, "Expected non-NULL\n");
5440 if (str)
5442 LPINTERNAL_BSTR bstr;
5443 int changed;
5445 bstr = Get(str);
5446 ok (bstr->dwLen == 8, "Expected 8, got %d\n", bstr->dwLen);
5447 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
5449 changed = SysReAllocString(&str, szSmaller);
5450 ok (changed == 1, "Expected 1, got %d\n", changed);
5451 /* Vista creates a new string, but older versions reuse the existing string. */
5452 /*ok (str == oldstr, "Created new string\n");*/
5453 bstr = Get(str);
5454 ok (bstr->dwLen == 2, "Expected 2, got %d\n", bstr->dwLen);
5455 ok (!lstrcmpW(bstr->szString, szSmaller), "String different\n");
5457 changed = SysReAllocString(&str, szLarger);
5458 ok (changed == 1, "Expected 1, got %d\n", changed);
5459 /* Early versions always make new strings rather than resizing */
5460 /* ok (str == oldstr, "Created new string\n"); */
5461 bstr = Get(str);
5462 ok (bstr->dwLen == 12, "Expected 12, got %d\n", bstr->dwLen);
5463 ok (!lstrcmpW(bstr->szString, szLarger), "String different\n");
5465 SysFreeString(str);
5469 static void test_SysReAllocStringLen(void)
5471 const OLECHAR szTest[5] = { 'T','e','s','t','\0' };
5472 const OLECHAR szSmaller[2] = { 'x','\0' };
5473 const OLECHAR szLarger[7] = { 'L','a','r','g','e','r','\0' };
5474 BSTR str;
5476 str = SysAllocStringLen(szTest, 4);
5477 ok (str != NULL, "Expected non-NULL\n");
5478 if (str)
5480 LPINTERNAL_BSTR bstr;
5481 int changed;
5483 bstr = Get(str);
5484 ok (bstr->dwLen == 8, "Expected 8, got %d\n", bstr->dwLen);
5485 ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
5487 changed = SysReAllocStringLen(&str, szSmaller, 1);
5488 ok (changed == 1, "Expected 1, got %d\n", changed);
5489 /* Vista creates a new string, but older versions reuse the existing string. */
5490 /*ok (str == oldstr, "Created new string\n");*/
5491 bstr = Get(str);
5492 ok (bstr->dwLen == 2, "Expected 2, got %d\n", bstr->dwLen);
5493 ok (!lstrcmpW(bstr->szString, szSmaller), "String different\n");
5495 changed = SysReAllocStringLen(&str, szLarger, 6);
5496 ok (changed == 1, "Expected 1, got %d\n", changed);
5497 /* Early versions always make new strings rather than resizing */
5498 /* ok (str == oldstr, "Created new string\n"); */
5499 bstr = Get(str);
5500 ok (bstr->dwLen == 12, "Expected 12, got %d\n", bstr->dwLen);
5501 ok (!lstrcmpW(bstr->szString, szLarger), "String different\n");
5503 changed = SysReAllocStringLen(&str, str, 6);
5504 ok (changed == 1, "Expected 1, got %d\n", changed);
5506 SysFreeString(str);
5509 /* Windows always returns null terminated strings */
5510 str = SysAllocStringLen(szTest, 4);
5511 ok (str != NULL, "Expected non-NULL\n");
5512 if (str)
5514 const int CHUNK_SIZE = 64;
5515 const int STRING_SIZE = 24;
5516 int changed;
5517 changed = SysReAllocStringLen(&str, NULL, CHUNK_SIZE);
5518 ok (changed == 1, "Expected 1, got %d\n", changed);
5519 ok (str != NULL, "Expected non-NULL\n");
5520 if (str)
5522 BSTR oldstr = str;
5524 /* Filling string */
5525 memset (str, 0xAB, CHUNK_SIZE * sizeof (OLECHAR));
5526 /* Checking null terminator */
5527 changed = SysReAllocStringLen(&str, NULL, STRING_SIZE);
5528 ok (changed == 1, "Expected 1, got %d\n", changed);
5529 ok (str != NULL, "Expected non-NULL\n");
5530 if (str)
5532 ok (str == oldstr, "Expected reuse of the old string memory\n");
5533 ok (str[STRING_SIZE] == 0,
5534 "Expected null terminator, got 0x%04X\n", str[STRING_SIZE]);
5535 SysFreeString(str);
5540 /* Some Windows applications use the same pointer for pbstr and psz */
5541 str = SysAllocStringLen(szTest, 4);
5542 ok(str != NULL, "Expected non-NULL\n");
5543 if(str)
5545 SysReAllocStringLen(&str, str, 1000000);
5546 ok(SysStringLen(str)==1000000, "Incorrect string length\n");
5547 ok(!memcmp(szTest, str, 4*sizeof(WCHAR)), "Incorrect string returned\n");
5549 SysFreeString(str);
5553 static void test_BstrCopy(void)
5555 const CHAR szTestA[6] = { 'T','e','s','t','\0','?' };
5556 const CHAR szTestTruncA[4] = { 'T','e','s','\0' };
5557 LPINTERNAL_BSTR bstr;
5558 BSTR str;
5559 HRESULT hres;
5560 VARIANT vt1, vt2;
5562 str = SysAllocStringByteLen(szTestA, 3);
5563 ok (str != NULL, "Expected non-NULL\n");
5564 if (str)
5566 V_VT(&vt1) = VT_BSTR;
5567 V_BSTR(&vt1) = str;
5568 V_VT(&vt2) = VT_EMPTY;
5569 hres = VariantCopy(&vt2, &vt1);
5570 ok (hres == S_OK,"Failed to copy binary bstring with hres 0x%08x\n", hres);
5571 bstr = Get(V_BSTR(&vt2));
5572 ok (bstr->dwLen == 3, "Expected 3, got %d\n", bstr->dwLen);
5573 ok (!lstrcmpA((LPCSTR)bstr->szString, szTestTruncA), "String different\n");
5574 VariantClear(&vt2);
5575 VariantClear(&vt1);
5579 static void test_VarBstrCat(void)
5581 static const WCHAR sz1[] = { 'a',0 };
5582 static const WCHAR sz2[] = { 'b',0 };
5583 static const WCHAR sz1sz2[] = { 'a','b',0 };
5584 static const WCHAR s1[] = { 'a',0 };
5585 static const WCHAR s2[] = { 'b',0 };
5586 static const WCHAR s1s2[] = { 'a',0,'b',0 };
5587 static const char str1A[] = "Have ";
5588 static const char str2A[] = "A Cigar";
5589 HRESULT ret;
5590 BSTR str1, str2, res;
5591 UINT len;
5593 CHECKPTR(VarBstrCat);
5595 if (0)
5597 /* Crash */
5598 pVarBstrCat(NULL, NULL, NULL);
5601 /* Concatenation of two NULL strings works */
5602 ret = pVarBstrCat(NULL, NULL, &res);
5603 ok(ret == S_OK, "VarBstrCat failed: %08x\n", ret);
5604 ok(res != NULL, "Expected a string\n");
5605 ok(SysStringLen(res) == 0, "Expected a 0-length string\n");
5606 SysFreeString(res);
5608 str1 = SysAllocString(sz1);
5610 /* Concatenation with one NULL arg */
5611 ret = pVarBstrCat(NULL, str1, &res);
5612 ok(ret == S_OK, "VarBstrCat failed: %08x\n", ret);
5613 ok(res != NULL, "Expected a string\n");
5614 ok(SysStringLen(res) == SysStringLen(str1), "Unexpected length\n");
5615 ok(!memcmp(res, sz1, SysStringLen(str1)), "Unexpected value\n");
5616 SysFreeString(res);
5617 ret = pVarBstrCat(str1, NULL, &res);
5618 ok(ret == S_OK, "VarBstrCat failed: %08x\n", ret);
5619 ok(res != NULL, "Expected a string\n");
5620 ok(SysStringLen(res) == SysStringLen(str1), "Unexpected length\n");
5621 ok(!memcmp(res, sz1, SysStringLen(str1)), "Unexpected value\n");
5622 SysFreeString(res);
5624 /* Concatenation of two zero-terminated strings */
5625 str2 = SysAllocString(sz2);
5626 ret = pVarBstrCat(str1, str2, &res);
5627 ok(ret == S_OK, "VarBstrCat failed: %08x\n", ret);
5628 ok(res != NULL, "Expected a string\n");
5629 ok(SysStringLen(res) == sizeof(sz1sz2) / sizeof(WCHAR) - 1,
5630 "Unexpected length\n");
5631 ok(!memcmp(res, sz1sz2, sizeof(sz1sz2)), "Unexpected value\n");
5632 SysFreeString(res);
5634 SysFreeString(str2);
5635 SysFreeString(str1);
5637 /* Concatenation of two strings with embedded NULLs */
5638 str1 = SysAllocStringLen(s1, sizeof(s1) / sizeof(WCHAR));
5639 str2 = SysAllocStringLen(s2, sizeof(s2) / sizeof(WCHAR));
5641 ret = pVarBstrCat(str1, str2, &res);
5642 ok(ret == S_OK, "VarBstrCat failed: %08x\n", ret);
5643 ok(res != NULL, "Expected a string\n");
5644 ok(SysStringLen(res) == sizeof(s1s2) / sizeof(WCHAR),
5645 "Unexpected length\n");
5646 ok(!memcmp(res, s1s2, sizeof(s1s2)), "Unexpected value\n");
5647 SysFreeString(res);
5649 SysFreeString(str2);
5650 SysFreeString(str1);
5652 /* Concatenation of ansi BSTRs, both odd byte count not including termination */
5653 str1 = SysAllocStringByteLen(str1A, sizeof(str1A)-1);
5654 str2 = SysAllocStringByteLen(str2A, sizeof(str2A)-1);
5655 len = SysStringLen(str1);
5656 ok(len == (sizeof(str1A)-1)/sizeof(WCHAR), "got length %u\n", len);
5657 len = SysStringLen(str2);
5658 ok(len == (sizeof(str2A)-1)/sizeof(WCHAR), "got length %u\n", len);
5660 ret = pVarBstrCat(str1, str2, &res);
5661 ok(ret == S_OK, "VarBstrCat failed: %08x\n", ret);
5662 ok(res != NULL, "Expected a string\n");
5663 len = (sizeof(str1A) + sizeof(str2A) - 2)/sizeof(WCHAR);
5664 ok(SysStringLen(res) == len, "got %d, expected %u\n", SysStringLen(res), len);
5665 ok(!memcmp(res, "Have A Cigar", sizeof(str1A) + sizeof(str2A) - 1), "got (%s)\n", (char*)res);
5666 SysFreeString(res);
5668 SysFreeString(str2);
5669 SysFreeString(str1);
5671 /* Concatenation of ansi BSTRs, both 1 byte length not including termination */
5672 str1 = SysAllocStringByteLen(str1A, 1);
5673 str2 = SysAllocStringByteLen(str2A, 1);
5674 len = SysStringLen(str1);
5675 ok(len == 0, "got length %u\n", len);
5676 len = SysStringLen(str2);
5677 ok(len == 0, "got length %u\n", len);
5679 ret = pVarBstrCat(str1, str2, &res);
5680 ok(ret == S_OK, "VarBstrCat failed: %08x\n", ret);
5681 ok(res != NULL, "Expected a string\n");
5682 ok(SysStringLen(res) == 1, "got %d, expected 1\n", SysStringLen(res));
5683 ok(!memcmp(res, "HA", 2), "got (%s)\n", (char*)res);
5684 SysFreeString(res);
5686 SysFreeString(str2);
5687 SysFreeString(str1);
5690 /* IUnknown */
5692 static void test_IUnknownClear(void)
5694 HRESULT hres;
5695 VARIANTARG v;
5696 DummyDispatch u;
5697 IUnknown* pu;
5699 init_test_dispatch(1, VT_UI1, &u);
5700 pu = (IUnknown*)&u.IDispatch_iface;
5702 /* Test that IUnknown_Release is called on by-value */
5703 V_VT(&v) = VT_UNKNOWN;
5704 V_UNKNOWN(&v) = (IUnknown*)&u.IDispatch_iface;
5705 hres = VariantClear(&v);
5706 ok(hres == S_OK && u.ref == 0 && V_VT(&v) == VT_EMPTY,
5707 "clear unknown: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5708 S_OK, 0, VT_EMPTY, hres, u.ref, V_VT(&v));
5710 /* But not when clearing a by-reference*/
5711 u.ref = 1;
5712 V_VT(&v) = VT_UNKNOWN|VT_BYREF;
5713 V_UNKNOWNREF(&v) = &pu;
5714 hres = VariantClear(&v);
5715 ok(hres == S_OK && u.ref == 1 && V_VT(&v) == VT_EMPTY,
5716 "clear dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5717 S_OK, 1, VT_EMPTY, hres, u.ref, V_VT(&v));
5720 static void test_IUnknownCopy(void)
5722 HRESULT hres;
5723 VARIANTARG vSrc, vDst;
5724 DummyDispatch u;
5725 IUnknown* pu;
5727 init_test_dispatch(1, VT_UI1, &u);
5728 pu = (IUnknown*)&u.IDispatch_iface;
5730 /* AddRef is called on by-value copy */
5731 VariantInit(&vDst);
5732 V_VT(&vSrc) = VT_UNKNOWN;
5733 V_UNKNOWN(&vSrc) = pu;
5734 hres = VariantCopy(&vDst, &vSrc);
5735 ok(hres == S_OK && u.ref == 2 && V_VT(&vDst) == VT_UNKNOWN,
5736 "copy unknown: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5737 S_OK, 2, VT_EMPTY, hres, u.ref, V_VT(&vDst));
5739 /* AddRef is skipped on copy of by-reference IDispatch */
5740 VariantInit(&vDst);
5741 u.ref = 1;
5742 V_VT(&vSrc) = VT_UNKNOWN|VT_BYREF;
5743 V_UNKNOWNREF(&vSrc) = &pu;
5744 hres = VariantCopy(&vDst, &vSrc);
5745 ok(hres == S_OK && u.ref == 1 && V_VT(&vDst) == (VT_UNKNOWN|VT_BYREF),
5746 "copy unknown: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5747 S_OK, 1, VT_DISPATCH, hres, u.ref, V_VT(&vDst));
5749 /* AddRef is called copying by-reference IDispatch with indirection */
5750 VariantInit(&vDst);
5751 u.ref = 1;
5752 V_VT(&vSrc) = VT_UNKNOWN|VT_BYREF;
5753 V_UNKNOWNREF(&vSrc) = &pu;
5754 hres = VariantCopyInd(&vDst, &vSrc);
5755 ok(hres == S_OK && u.ref == 2 && V_VT(&vDst) == VT_UNKNOWN,
5756 "copy unknown: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5757 S_OK, 2, VT_DISPATCH, hres, u.ref, V_VT(&vDst));
5759 /* Indirection in place also calls AddRef */
5760 u.ref = 1;
5761 V_VT(&vSrc) = VT_UNKNOWN|VT_BYREF;
5762 V_UNKNOWNREF(&vSrc) = &pu;
5763 hres = VariantCopyInd(&vSrc, &vSrc);
5764 ok(hres == S_OK && u.ref == 2 && V_VT(&vSrc) == VT_UNKNOWN,
5765 "copy unknown: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5766 S_OK, 2, VT_DISPATCH, hres, u.ref, V_VT(&vSrc));
5769 static void test_IUnknownChangeTypeEx(void)
5771 HRESULT hres;
5772 VARIANTARG vSrc, vDst;
5773 LCID lcid;
5774 VARTYPE vt;
5775 DummyDispatch u;
5776 IUnknown* pu;
5778 init_test_dispatch(1, VT_UI1, &u);
5779 pu = (IUnknown*)&u.IDispatch_iface;
5781 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5783 V_VT(&vSrc) = VT_UNKNOWN;
5784 V_UNKNOWN(&vSrc) = pu;
5786 /* =>IDispatch in place */
5787 hres = VariantChangeTypeEx(&vSrc, &vSrc, lcid, 0, VT_DISPATCH);
5788 ok(hres == S_OK && u.ref == 1 &&
5789 V_VT(&vSrc) == VT_DISPATCH && V_DISPATCH(&vSrc) == (IDispatch*)pu,
5790 "change unk(src=src): expected 0x%08x,%d,%d,%p, got 0x%08x,%d,%d,%p\n",
5791 S_OK, 1, VT_DISPATCH, pu, hres, u.ref, V_VT(&vSrc), V_DISPATCH(&vSrc));
5793 /* =>IDispatch */
5794 u.ref = 1;
5795 V_VT(&vSrc) = VT_UNKNOWN;
5796 V_UNKNOWN(&vSrc) = pu;
5797 VariantInit(&vDst);
5798 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, VT_UNKNOWN);
5799 /* Note vSrc is not cleared, as final refcount is 2 */
5800 ok(hres == S_OK && u.ref == 2 &&
5801 V_VT(&vDst) == VT_UNKNOWN && V_UNKNOWN(&vDst) == pu,
5802 "change unk(src,dst): expected 0x%08x,%d,%d,%p, got 0x%08x,%d,%d,%p\n",
5803 S_OK, 2, VT_UNKNOWN, pu, hres, u.ref, V_VT(&vDst), V_UNKNOWN(&vDst));
5805 /* Can't change unknown to anything else */
5806 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
5808 HRESULT hExpected = DISP_E_BADVARTYPE;
5810 V_VT(&vSrc) = VT_UNKNOWN;
5811 V_UNKNOWN(&vSrc) = pu;
5812 VariantInit(&vDst);
5814 if (vt == VT_UNKNOWN || vt == VT_DISPATCH || vt == VT_EMPTY || vt == VT_NULL)
5815 hExpected = S_OK;
5816 else
5818 if (vt == VT_I8 || vt == VT_UI8)
5820 if (has_i8)
5821 hExpected = DISP_E_TYPEMISMATCH;
5823 else if (vt == VT_RECORD)
5825 hExpected = DISP_E_TYPEMISMATCH;
5827 else if (vt >= VT_I2 && vt <= VT_UINT && vt != (VARTYPE)15)
5828 hExpected = DISP_E_TYPEMISMATCH;
5831 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, vt);
5832 ok(hres == hExpected,
5833 "change unk(badvar): vt %d expected 0x%08x, got 0x%08x\n",
5834 vt, hExpected, hres);
5838 /* IDispatch */
5839 static void test_IDispatchClear(void)
5841 HRESULT hres;
5842 VARIANTARG v;
5843 DummyDispatch d;
5844 IDispatch* pd;
5846 init_test_dispatch(1, VT_UI1, &d);
5847 pd = &d.IDispatch_iface;
5849 /* As per IUnknown */
5851 V_VT(&v) = VT_DISPATCH;
5852 V_DISPATCH(&v) = pd;
5853 hres = VariantClear(&v);
5854 ok(hres == S_OK && d.ref == 0 && V_VT(&v) == VT_EMPTY,
5855 "clear dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5856 S_OK, 0, VT_EMPTY, hres, d.ref, V_VT(&v));
5858 d.ref = 1;
5859 V_VT(&v) = VT_DISPATCH|VT_BYREF;
5860 V_DISPATCHREF(&v) = &pd;
5861 hres = VariantClear(&v);
5862 ok(hres == S_OK && d.ref == 1 && V_VT(&v) == VT_EMPTY,
5863 "clear dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5864 S_OK, 1, VT_EMPTY, hres, d.ref, V_VT(&v));
5867 static void test_IDispatchCopy(void)
5869 HRESULT hres;
5870 VARIANTARG vSrc, vDst;
5871 DummyDispatch d;
5872 IDispatch* pd;
5874 init_test_dispatch(1, VT_UI1, &d);
5875 pd = &d.IDispatch_iface;
5877 /* As per IUnknown */
5879 VariantInit(&vDst);
5880 V_VT(&vSrc) = VT_DISPATCH;
5881 V_DISPATCH(&vSrc) = pd;
5882 hres = VariantCopy(&vDst, &vSrc);
5883 ok(hres == S_OK && d.ref == 2 && V_VT(&vDst) == VT_DISPATCH,
5884 "copy dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5885 S_OK, 2, VT_EMPTY, hres, d.ref, V_VT(&vDst));
5887 VariantInit(&vDst);
5888 d.ref = 1;
5889 V_VT(&vSrc) = VT_DISPATCH|VT_BYREF;
5890 V_DISPATCHREF(&vSrc) = &pd;
5891 hres = VariantCopy(&vDst, &vSrc);
5892 ok(hres == S_OK && d.ref == 1 && V_VT(&vDst) == (VT_DISPATCH|VT_BYREF),
5893 "copy dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5894 S_OK, 1, VT_DISPATCH, hres, d.ref, V_VT(&vDst));
5896 VariantInit(&vDst);
5897 d.ref = 1;
5898 V_VT(&vSrc) = VT_DISPATCH|VT_BYREF;
5899 V_DISPATCHREF(&vSrc) = &pd;
5900 hres = VariantCopyInd(&vDst, &vSrc);
5901 ok(hres == S_OK && d.ref == 2 && V_VT(&vDst) == VT_DISPATCH,
5902 "copy dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5903 S_OK, 2, VT_DISPATCH, hres, d.ref, V_VT(&vDst));
5905 d.ref = 1;
5906 V_VT(&vSrc) = VT_DISPATCH|VT_BYREF;
5907 V_DISPATCHREF(&vSrc) = &pd;
5908 hres = VariantCopyInd(&vSrc, &vSrc);
5909 ok(hres == S_OK && d.ref == 2 && V_VT(&vSrc) == VT_DISPATCH,
5910 "copy dispatch: expected 0x%08x, %d, %d, got 0x%08x, %d, %d\n",
5911 S_OK, 2, VT_DISPATCH, hres, d.ref, V_VT(&vSrc));
5914 static void test_IDispatchChangeTypeEx(void)
5916 HRESULT hres;
5917 VARIANTARG vSrc, vDst;
5918 LCID lcid;
5919 DummyDispatch d;
5920 IDispatch* pd;
5922 init_test_dispatch(1, VT_UI1, &d);
5923 pd = &d.IDispatch_iface;
5925 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5927 V_VT(&vSrc) = VT_DISPATCH;
5928 V_DISPATCH(&vSrc) = pd;
5930 /* =>IUnknown in place */
5931 hres = VariantChangeTypeEx(&vSrc, &vSrc, lcid, 0, VT_UNKNOWN);
5932 ok(hres == S_OK && d.ref == 1 &&
5933 V_VT(&vSrc) == VT_UNKNOWN && V_UNKNOWN(&vSrc) == (IUnknown*)pd,
5934 "change disp(src=src): expected 0x%08x,%d,%d,%p, got 0x%08x,%d,%d,%p\n",
5935 S_OK, 1, VT_UNKNOWN, pd, hres, d.ref, V_VT(&vSrc), V_UNKNOWN(&vSrc));
5937 /* =>IUnknown */
5938 d.ref = 1;
5939 V_VT(&vSrc) = VT_DISPATCH;
5940 V_DISPATCH(&vSrc) = pd;
5941 VariantInit(&vDst);
5942 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, VT_UNKNOWN);
5943 /* Note vSrc is not cleared, as final refcount is 2 */
5944 ok(hres == S_OK && d.ref == 2 &&
5945 V_VT(&vDst) == VT_UNKNOWN && V_UNKNOWN(&vDst) == (IUnknown*)pd,
5946 "change disp(src,dst): expected 0x%08x,%d,%d,%p, got 0x%08x,%d,%d,%p\n",
5947 S_OK, 2, VT_UNKNOWN, pd, hres, d.ref, V_VT(&vDst), V_UNKNOWN(&vDst));
5949 /* FIXME: Verify that VARIANT_NOVALUEPROP prevents conversion to integral
5950 * types. this requires that the xxxFromDisp tests work first.
5954 /* VT_ERROR */
5955 static void test_ErrorChangeTypeEx(void)
5957 HRESULT hres;
5958 VARIANTARG vSrc, vDst;
5959 VARTYPE vt;
5960 LCID lcid;
5962 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
5964 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
5966 HRESULT hExpected = DISP_E_BADVARTYPE;
5968 V_VT(&vSrc) = VT_ERROR;
5969 V_ERROR(&vSrc) = 1;
5970 VariantInit(&vDst);
5971 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, vt);
5973 if (vt == VT_ERROR)
5974 hExpected = S_OK;
5975 else
5977 if (vt == VT_I8 || vt == VT_UI8)
5979 if (has_i8)
5980 hExpected = DISP_E_TYPEMISMATCH;
5982 else if (vt == VT_RECORD)
5984 hExpected = DISP_E_TYPEMISMATCH;
5986 else if (vt <= VT_UINT && vt != (VARTYPE)15)
5987 hExpected = DISP_E_TYPEMISMATCH;
5990 ok(hres == hExpected,
5991 "change err: vt %d expected 0x%08x, got 0x%08x\n", vt, hExpected, hres);
5995 /* VT_EMPTY */
5996 static void test_EmptyChangeTypeEx(void)
5998 VARTYPE vt;
5999 LCID lcid;
6001 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
6003 for (vt = VT_EMPTY; vt <= VT_BSTR_BLOB; vt++)
6005 HRESULT hExpected, hres;
6006 VARIANTARG vSrc, vDst;
6008 /* skip for undefined types */
6009 if ((vt == 15) || (vt > VT_VERSIONED_STREAM && vt < VT_BSTR_BLOB))
6010 continue;
6012 switch (vt)
6014 case VT_I8:
6015 case VT_UI8:
6016 if (has_i8)
6017 hExpected = S_OK;
6018 else
6019 hExpected = DISP_E_BADVARTYPE;
6020 break;
6021 case VT_RECORD:
6022 case VT_VARIANT:
6023 case VT_DISPATCH:
6024 case VT_UNKNOWN:
6025 case VT_ERROR:
6026 hExpected = DISP_E_TYPEMISMATCH;
6027 break;
6028 case VT_EMPTY:
6029 case VT_NULL:
6030 case VT_I2:
6031 case VT_I4:
6032 case VT_R4:
6033 case VT_R8:
6034 case VT_CY:
6035 case VT_DATE:
6036 case VT_BSTR:
6037 case VT_BOOL:
6038 case VT_DECIMAL:
6039 case VT_I1:
6040 case VT_UI1:
6041 case VT_UI2:
6042 case VT_UI4:
6043 case VT_INT:
6044 case VT_UINT:
6045 hExpected = S_OK;
6046 break;
6047 default:
6048 hExpected = DISP_E_BADVARTYPE;
6051 VariantInit(&vSrc);
6052 V_VT(&vSrc) = VT_EMPTY;
6053 memset(&vDst, 0, sizeof(vDst));
6054 V_VT(&vDst) = VT_NULL;
6056 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, vt);
6057 ok(hres == hExpected, "change empty: vt %d expected 0x%08x, got 0x%08x, vt %d\n",
6058 vt, hExpected, hres, V_VT(&vDst));
6059 if (hres == S_OK)
6061 ok(V_VT(&vDst) == vt, "change empty: vt %d, got %d\n", vt, V_VT(&vDst));
6062 VariantClear(&vDst);
6067 /* VT_NULL */
6068 static void test_NullChangeTypeEx(void)
6070 VARTYPE vt;
6071 LCID lcid;
6073 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
6075 for (vt = VT_EMPTY; vt <= VT_BSTR_BLOB; vt++)
6077 VARIANTARG vSrc, vDst;
6078 HRESULT hExpected, hres;
6080 /* skip for undefined types */
6081 if ((vt == 15) || (vt > VT_VERSIONED_STREAM && vt < VT_BSTR_BLOB))
6082 continue;
6084 switch (vt)
6086 case VT_I8:
6087 case VT_UI8:
6088 if (has_i8)
6089 hExpected = DISP_E_TYPEMISMATCH;
6090 else
6091 hExpected = DISP_E_BADVARTYPE;
6092 break;
6093 case VT_NULL:
6094 hExpected = S_OK;
6095 break;
6096 case VT_EMPTY:
6097 case VT_I2:
6098 case VT_I4:
6099 case VT_R4:
6100 case VT_R8:
6101 case VT_CY:
6102 case VT_DATE:
6103 case VT_BSTR:
6104 case VT_DISPATCH:
6105 case VT_ERROR:
6106 case VT_BOOL:
6107 case VT_VARIANT:
6108 case VT_UNKNOWN:
6109 case VT_DECIMAL:
6110 case VT_I1:
6111 case VT_UI1:
6112 case VT_UI2:
6113 case VT_UI4:
6114 case VT_INT:
6115 case VT_UINT:
6116 case VT_RECORD:
6117 hExpected = DISP_E_TYPEMISMATCH;
6118 break;
6119 default:
6120 hExpected = DISP_E_BADVARTYPE;
6123 VariantInit(&vSrc);
6124 V_VT(&vSrc) = VT_NULL;
6125 memset(&vDst, 0, sizeof(vDst));
6126 V_VT(&vDst) = VT_EMPTY;
6128 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, vt);
6129 ok(hres == hExpected, "change null: vt %d expected 0x%08x, got 0x%08x, vt %d\n",
6130 vt, hExpected, hres, V_VT(&vDst));
6132 /* should work only for VT_NULL -> VT_NULL case */
6133 if (hres == S_OK)
6134 ok(V_VT(&vDst) == VT_NULL, "change null: VT_NULL expected 0x%08x, got 0x%08x, vt %d\n",
6135 hExpected, hres, V_VT(&vDst));
6136 else
6137 ok(V_VT(&vDst) == VT_EMPTY, "change null: vt %d expected 0x%08x, got 0x%08x, vt %d\n",
6138 vt, hExpected, hres, V_VT(&vDst));
6143 /* VT_UINT */
6144 static void test_UintChangeTypeEx(void)
6146 HRESULT hres;
6147 VARIANTARG vSrc, vDst;
6148 LCID lcid;
6150 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
6152 /* Converting a VT_UINT to a VT_INT does not check for overflow */
6153 V_VT(&vDst) = VT_EMPTY;
6154 V_VT(&vSrc) = VT_UINT;
6155 V_UI4(&vSrc) = -1;
6156 hres = VariantChangeTypeEx(&vDst, &vSrc, lcid, 0, VT_I4);
6157 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == -1,
6158 "change uint: Expected %d,0x%08x,%d got %d,0x%08x,%d\n",
6159 VT_I4, S_OK, -1, V_VT(&vDst), hres, V_I4(&vDst));
6162 #define NUM_CUST_ITEMS 16
6164 static void test_ClearCustData(void)
6166 CUSTDATA ci;
6167 unsigned i;
6169 CHECKPTR(ClearCustData);
6171 ci.cCustData = NUM_CUST_ITEMS;
6172 ci.prgCustData = CoTaskMemAlloc( sizeof(CUSTDATAITEM) * NUM_CUST_ITEMS );
6173 for (i = 0; i < NUM_CUST_ITEMS; i++)
6174 VariantInit(&ci.prgCustData[i].varValue);
6175 pClearCustData(&ci);
6176 ok(!ci.cCustData && !ci.prgCustData, "ClearCustData didn't clear fields!\n");
6179 static void test_NullByRef(void)
6181 VARIANT v1, v2;
6182 HRESULT hRes;
6184 VariantInit(&v1);
6185 VariantInit(&v2);
6186 V_VT(&v1) = VT_BYREF|VT_VARIANT;
6187 V_BYREF(&v1) = 0;
6189 hRes = VariantChangeTypeEx(&v2, &v1, 0, 0, VT_I4);
6190 ok(hRes == DISP_E_TYPEMISMATCH, "VariantChangeTypeEx should return DISP_E_TYPEMISMATCH\n");
6192 VariantClear(&v1);
6193 V_VT(&v1) = VT_BYREF|VT_VARIANT;
6194 V_BYREF(&v1) = 0;
6195 V_VT(&v2) = VT_I4;
6196 V_I4(&v2) = 123;
6198 hRes = VariantChangeTypeEx(&v2, &v1, 0, 0, VT_VARIANT);
6199 ok(hRes == DISP_E_TYPEMISMATCH, "VariantChangeTypeEx should return DISP_E_TYPEMISMATCH\n");
6200 ok(V_VT(&v2) == VT_I4 && V_I4(&v2) == 123, "VariantChangeTypeEx shouldn't change pvargDest\n");
6202 hRes = VariantChangeTypeEx(&v2, &v1, 0, 0, VT_BYREF|VT_I4);
6203 ok(hRes == DISP_E_TYPEMISMATCH, "VariantChangeTypeEx should return DISP_E_TYPEMISMATCH\n");
6205 hRes = VariantChangeTypeEx(&v2, &v1, 0, 0, 0x3847);
6206 ok(hRes == DISP_E_BADVARTYPE, "VariantChangeTypeEx should return DISP_E_BADVARTYPE\n");
6209 /* Dst Variant should remain unchanged if VariantChangeType cannot convert */
6210 static void test_ChangeType_keep_dst(void)
6212 VARIANT v1, v2;
6213 BSTR bstr;
6214 static const WCHAR testW[] = {'t','e','s','t',0};
6215 HRESULT hres;
6217 bstr = SysAllocString(testW);
6218 VariantInit(&v1);
6219 VariantInit(&v2);
6220 V_VT(&v1) = VT_BSTR;
6221 V_BSTR(&v1) = bstr;
6222 hres = VariantChangeTypeEx(&v1, &v1, 0, 0, VT_INT);
6223 ok(hres == DISP_E_TYPEMISMATCH, "VariantChangeTypeEx returns %08x\n", hres);
6224 ok(V_VT(&v1) == VT_BSTR && V_BSTR(&v1) == bstr, "VariantChangeTypeEx changed dst variant\n");
6225 V_VT(&v2) = VT_INT;
6226 V_INT(&v2) = 4;
6227 hres = VariantChangeTypeEx(&v2, &v1, 0, 0, VT_INT);
6228 ok(hres == DISP_E_TYPEMISMATCH, "VariantChangeTypeEx returns %08x\n", hres);
6229 ok(V_VT(&v2) == VT_INT && V_INT(&v2) == 4, "VariantChangeTypeEx changed dst variant\n");
6230 SysFreeString(bstr);
6233 /* This tests assumes an empty cache, so it needs to be ran early in the test. */
6234 static void test_bstr_cache(void)
6236 BSTR str, str2, strs[20];
6237 unsigned i;
6239 static const WCHAR testW[] = {'t','e','s','t',0};
6241 str = SysAllocString(testW);
6242 /* This should put the string into cache */
6243 SysFreeString(str);
6244 /* The string is in cache, this won't touch it */
6245 SysFreeString(str);
6247 ok(SysStringLen(str) == 4, "unexpected len\n");
6248 ok(!lstrcmpW(str, testW), "string changed\n");
6250 str2 = SysAllocString(testW);
6251 ok(str == str2, "str != str2\n");
6252 SysFreeString(str2);
6254 /* Fill the bucket with cached entries. */
6255 for(i=0; i < sizeof(strs)/sizeof(*strs); i++)
6256 strs[i] = SysAllocStringLen(NULL, 24);
6257 for(i=0; i < sizeof(strs)/sizeof(*strs); i++)
6258 SysFreeString(strs[i]);
6260 /* Following allocation will be made from cache */
6261 str = SysAllocStringLen(NULL, 24);
6262 ok(str == strs[0], "str != strs[0]\n");
6264 /* Smaller buffers may also use larget cached buffers */
6265 str2 = SysAllocStringLen(NULL, 16);
6266 ok(str2 == strs[1], "str2 != strs[1]\n");
6268 SysFreeString(str);
6269 SysFreeString(str2);
6270 SysFreeString(str);
6271 SysFreeString(str2);
6274 static void write_typelib(int res_no, const char *filename)
6276 DWORD written;
6277 HANDLE file;
6278 HRSRC res;
6279 void *ptr;
6281 file = CreateFileA( filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 );
6282 ok( file != INVALID_HANDLE_VALUE, "file creation failed\n" );
6283 if (file == INVALID_HANDLE_VALUE) return;
6284 res = FindResourceA( GetModuleHandleA(NULL), (LPCSTR)MAKEINTRESOURCE(res_no), "TYPELIB" );
6285 ok( res != 0, "couldn't find resource\n" );
6286 ptr = LockResource( LoadResource( GetModuleHandleA(NULL), res ));
6287 WriteFile( file, ptr, SizeofResource( GetModuleHandleA(NULL), res ), &written, NULL );
6288 ok( written == SizeofResource( GetModuleHandleA(NULL), res ), "couldn't write resource\n" );
6289 CloseHandle( file );
6292 static const char *create_test_typelib(int res_no)
6294 static char filename[MAX_PATH];
6296 GetTempFileNameA( ".", "tlb", 0, filename );
6297 write_typelib(res_no, filename);
6298 return filename;
6301 static void test_recinfo(void)
6303 static const WCHAR testW[] = {'t','e','s','t',0};
6304 static WCHAR teststructW[] = {'t','e','s','t','_','s','t','r','u','c','t',0};
6305 struct test_struct teststruct, testcopy;
6306 WCHAR filenameW[MAX_PATH];
6307 const char *filename;
6308 IRecordInfo *recinfo;
6309 ITypeInfo *typeinfo;
6310 DummyDispatch dispatch;
6311 ITypeLib *typelib;
6312 TYPEATTR *attr;
6313 MEMBERID memid;
6314 UINT16 found;
6315 HRESULT hr;
6316 ULONG size;
6318 filename = create_test_typelib(2);
6319 MultiByteToWideChar(CP_ACP, 0, filename, -1, filenameW, MAX_PATH);
6320 hr = LoadTypeLibEx(filenameW, REGKIND_NONE, &typelib);
6321 ok(hr == S_OK, "got 0x%08x\n", hr);
6323 typeinfo = NULL;
6324 found = 1;
6325 hr = ITypeLib_FindName(typelib, teststructW, 0, &typeinfo, &memid, &found);
6326 ok(hr == S_OK, "got 0x%08x\n", hr);
6327 ok(typeinfo != NULL, "got %p\n", typeinfo);
6328 hr = ITypeInfo_GetTypeAttr(typeinfo, &attr);
6329 ok(hr == S_OK, "got 0x%08x\n", hr);
6330 ok(IsEqualGUID(&attr->guid, &UUID_test_struct), "got %s\n", wine_dbgstr_guid(&attr->guid));
6331 ok(attr->typekind == TKIND_RECORD, "got %d\n", attr->typekind);
6333 hr = GetRecordInfoFromTypeInfo(typeinfo, &recinfo);
6334 ok(hr == S_OK, "got 0x%08x\n", hr);
6336 size = 0;
6337 hr = IRecordInfo_GetSize(recinfo, &size);
6338 ok(hr == S_OK, "got 0x%08x\n", hr);
6339 ok(size == sizeof(struct test_struct), "got size %d\n", size);
6340 ok(attr->cbSizeInstance == sizeof(struct test_struct), "got instance size %d\n", attr->cbSizeInstance);
6341 ITypeInfo_ReleaseTypeAttr(typeinfo, attr);
6343 /* RecordInit() */
6344 teststruct.hr = E_FAIL;
6345 teststruct.b = 0x1;
6346 teststruct.disp = (void*)0xdeadbeef;
6347 teststruct.bstr = (void*)0xdeadbeef;
6349 hr = IRecordInfo_RecordInit(recinfo, &teststruct);
6350 ok(hr == S_OK, "got 0x%08x\n", hr);
6351 ok(teststruct.hr == 0, "got 0x%08x\n", teststruct.hr);
6352 ok(teststruct.b == 0, "got 0x%08x\n", teststruct.b);
6353 ok(teststruct.disp == NULL, "got %p\n", teststruct.disp);
6354 ok(teststruct.bstr == NULL, "got %p\n", teststruct.bstr);
6356 init_test_dispatch(10, VT_UI1, &dispatch);
6358 /* RecordCopy(), interface field reference increased */
6359 teststruct.hr = S_FALSE;
6360 teststruct.b = VARIANT_TRUE;
6361 teststruct.disp = &dispatch.IDispatch_iface;
6362 teststruct.bstr = SysAllocString(testW);
6363 memset(&testcopy, 0, sizeof(testcopy));
6364 hr = IRecordInfo_RecordCopy(recinfo, &teststruct, &testcopy);
6365 ok(hr == S_OK, "got 0x%08x\n", hr);
6366 ok(testcopy.hr == S_FALSE, "got 0x%08x\n", testcopy.hr);
6367 ok(testcopy.b == VARIANT_TRUE, "got %d\n", testcopy.b);
6368 ok(testcopy.disp == teststruct.disp, "got %p\n", testcopy.disp);
6369 ok(dispatch.ref == 11, "got %d\n", dispatch.ref);
6370 ok(testcopy.bstr != teststruct.bstr, "got %p\n", testcopy.bstr);
6371 ok(!lstrcmpW(testcopy.bstr, teststruct.bstr), "got %s, %s\n", wine_dbgstr_w(testcopy.bstr), wine_dbgstr_w(teststruct.bstr));
6373 /* RecordClear() */
6374 hr = IRecordInfo_RecordClear(recinfo, &teststruct);
6375 ok(hr == S_OK, "got 0x%08x\n", hr);
6376 ok(teststruct.bstr == NULL, "got %p\n", teststruct.bstr);
6377 hr = IRecordInfo_RecordClear(recinfo, &testcopy);
6378 ok(hr == S_OK, "got 0x%08x\n", hr);
6379 ok(testcopy.bstr == NULL, "got %p\n", testcopy.bstr);
6381 /* now destination contains inteface pointer */
6382 memset(&testcopy, 0, sizeof(testcopy));
6383 testcopy.disp = &dispatch.IDispatch_iface;
6384 dispatch.ref = 10;
6386 hr = IRecordInfo_RecordCopy(recinfo, &teststruct, &testcopy);
6387 ok(hr == S_OK, "got 0x%08x\n", hr);
6388 ok(dispatch.ref == 9, "got %d\n", dispatch.ref);
6390 IRecordInfo_Release(recinfo);
6392 ITypeInfo_Release(typeinfo);
6393 ITypeLib_Release(typelib);
6394 DeleteFileA(filename);
6397 START_TEST(vartype)
6399 hOleaut32 = GetModuleHandleA("oleaut32.dll");
6401 has_i8 = GetProcAddress(hOleaut32, "VarI8FromI1") != NULL;
6402 has_locales = has_i8 && GetProcAddress(hOleaut32, "GetVarConversionLocaleSetting") != NULL;
6404 trace("LCIDs: System=0x%08x, User=0x%08x\n", GetSystemDefaultLCID(),
6405 GetUserDefaultLCID());
6407 test_bstr_cache();
6409 test_VarI1FromI2();
6410 test_VarI1FromI4();
6411 test_VarI1FromI8();
6412 test_VarI1FromUI1();
6413 test_VarI1FromUI2();
6414 test_VarI1FromUI4();
6415 test_VarI1FromUI8();
6416 test_VarI1FromBool();
6417 test_VarI1FromR4();
6418 test_VarI1FromR8();
6419 test_VarI1FromDate();
6420 test_VarI1FromCy();
6421 test_VarI1FromDec();
6422 test_VarI1FromStr();
6423 test_VarUI1FromDisp();
6424 test_VarI1Copy();
6425 test_VarI1ChangeTypeEx();
6427 test_VarUI1FromI1();
6428 test_VarUI1FromI2();
6429 test_VarUI1FromI4();
6430 test_VarUI1FromI8();
6431 test_VarUI1FromUI2();
6432 test_VarUI1FromUI4();
6433 test_VarUI1FromUI8();
6434 test_VarUI1FromBool();
6435 test_VarUI1FromR4();
6436 test_VarUI1FromR8();
6437 test_VarUI1FromDate();
6438 test_VarUI1FromCy();
6439 test_VarUI1FromDec();
6440 test_VarUI1FromStr();
6441 test_VarUI1Copy();
6442 test_VarUI1ChangeTypeEx();
6444 test_VarI2FromI1();
6445 test_VarI2FromI4();
6446 test_VarI2FromI8();
6447 test_VarI2FromUI1();
6448 test_VarI2FromUI2();
6449 test_VarI2FromUI4();
6450 test_VarI2FromUI8();
6451 test_VarI2FromBool();
6452 test_VarI2FromR4();
6453 test_VarI2FromR8();
6454 test_VarI2FromDate();
6455 test_VarI2FromCy();
6456 test_VarI2FromDec();
6457 test_VarI2FromStr();
6458 test_VarI2Copy();
6459 test_VarI2ChangeTypeEx();
6461 test_VarUI2FromI1();
6462 test_VarUI2FromI2();
6463 test_VarUI2FromI4();
6464 test_VarUI2FromI8();
6465 test_VarUI2FromUI1();
6466 test_VarUI2FromUI4();
6467 test_VarUI2FromUI8();
6468 test_VarUI2FromBool();
6469 test_VarUI2FromR4();
6470 test_VarUI2FromR8();
6471 test_VarUI2FromDate();
6472 test_VarUI2FromCy();
6473 test_VarUI2FromDec();
6474 test_VarUI2FromStr();
6475 test_VarUI2Copy();
6476 test_VarUI2ChangeTypeEx();
6478 test_VarI4FromI1();
6479 test_VarI4FromI2();
6480 test_VarI4FromI8();
6481 test_VarI4FromUI1();
6482 test_VarI4FromUI2();
6483 test_VarI4FromUI4();
6484 test_VarI4FromUI8();
6485 test_VarI4FromBool();
6486 test_VarI4FromR4();
6487 test_VarI4FromR8();
6488 test_VarI4FromDate();
6489 test_VarI4FromCy();
6490 test_VarI4FromDec();
6491 test_VarI4FromStr();
6492 test_VarI4Copy();
6493 test_VarI4ChangeTypeEx();
6495 test_VarUI4FromI1();
6496 test_VarUI4FromI2();
6497 test_VarUI4FromUI2();
6498 test_VarUI4FromI8();
6499 test_VarUI4FromUI1();
6500 test_VarUI4FromI4();
6501 test_VarUI4FromUI8();
6502 test_VarUI4FromBool();
6503 test_VarUI4FromR4();
6504 test_VarUI4FromR8();
6505 test_VarUI4FromDate();
6506 test_VarUI4FromCy();
6507 test_VarUI4FromDec();
6508 test_VarUI4FromStr();
6509 test_VarUI4Copy();
6510 test_VarUI4ChangeTypeEx();
6512 test_VarI8FromI1();
6513 test_VarI8FromUI1();
6514 test_VarI8FromI2();
6515 test_VarI8FromUI2();
6516 test_VarI8FromUI4();
6517 test_VarI8FromR4();
6518 test_VarI8FromR8();
6519 test_VarI8FromBool();
6520 test_VarI8FromUI8();
6521 test_VarI8FromCy();
6522 test_VarI8FromDec();
6523 test_VarI8FromDate();
6524 test_VarI8FromStr();
6525 test_VarI8Copy();
6526 test_VarI8ChangeTypeEx();
6528 test_VarUI8FromI1();
6529 test_VarUI8FromUI1();
6530 test_VarUI8FromI2();
6531 test_VarUI8FromUI2();
6532 test_VarUI8FromUI4();
6533 test_VarUI8FromR4();
6534 test_VarUI8FromR8();
6535 test_VarUI8FromBool();
6536 test_VarUI8FromI8();
6537 test_VarUI8FromCy();
6538 test_VarUI8FromDec();
6539 test_VarUI8FromDate();
6540 test_VarUI8FromStr();
6541 test_VarUI8Copy();
6542 test_VarUI8ChangeTypeEx();
6544 test_VarR4FromI1();
6545 test_VarR4FromUI1();
6546 test_VarR4FromI2();
6547 test_VarR4FromUI2();
6548 test_VarR4FromI4();
6549 test_VarR4FromUI4();
6550 test_VarR4FromR8();
6551 test_VarR4FromBool();
6552 test_VarR4FromCy();
6553 test_VarR4FromI8();
6554 test_VarR4FromUI8();
6555 test_VarR4FromDec();
6556 test_VarR4FromDate();
6557 test_VarR4FromStr();
6558 test_VarR4Copy();
6559 test_VarR4ChangeTypeEx();
6561 test_VarR8FromI1();
6562 test_VarR8FromUI1();
6563 test_VarR8FromI2();
6564 test_VarR8FromUI2();
6565 test_VarR8FromI4();
6566 test_VarR8FromUI4();
6567 test_VarR8FromR4();
6568 test_VarR8FromBool();
6569 test_VarR8FromCy();
6570 test_VarR8FromI8();
6571 test_VarR8FromUI8();
6572 test_VarR8FromDec();
6573 test_VarR8FromDate();
6574 test_VarR8FromStr();
6575 test_VarR8Copy();
6576 test_VarR8ChangeTypeEx();
6577 test_VarR8Round();
6579 test_VarDateFromI1();
6580 test_VarDateFromUI1();
6581 test_VarDateFromI2();
6582 test_VarDateFromUI2();
6583 test_VarDateFromI4();
6584 test_VarDateFromUI4();
6585 test_VarDateFromR4();
6586 test_VarDateFromR8();
6587 test_VarDateFromBool();
6588 test_VarDateFromCy();
6589 test_VarDateFromI8();
6590 test_VarDateFromUI8();
6591 test_VarDateFromDec();
6592 test_VarDateFromStr();
6593 test_VarDateCopy();
6594 test_VarDateChangeTypeEx();
6596 test_VarCyFromI1();
6597 test_VarCyFromUI1();
6598 test_VarCyFromI2();
6599 test_VarCyFromUI2();
6600 test_VarCyFromI4();
6601 test_VarCyFromUI4();
6602 test_VarCyFromR4();
6603 test_VarCyFromR8();
6604 test_VarCyFromBool();
6605 test_VarCyFromI8();
6606 test_VarCyFromUI8();
6607 test_VarCyFromDec();
6608 test_VarCyFromDate();
6610 test_VarCyAdd();
6611 test_VarCyMul();
6612 test_VarCySub();
6613 test_VarCyAbs();
6614 test_VarCyNeg();
6615 test_VarCyMulI4();
6616 test_VarCyMulI8();
6617 test_VarCyCmp();
6618 test_VarCyCmpR8();
6619 test_VarCyRound();
6620 test_VarCyFix();
6621 test_VarCyInt();
6623 test_VarDecFromI1();
6624 test_VarDecFromI2();
6625 test_VarDecFromI4();
6626 test_VarDecFromI8();
6627 test_VarDecFromUI1();
6628 test_VarDecFromUI2();
6629 test_VarDecFromUI4();
6630 test_VarDecFromUI8();
6631 test_VarDecFromR4();
6632 test_VarDecFromR8();
6633 test_VarDecFromDate();
6634 test_VarDecFromStr();
6635 test_VarDecFromCy();
6636 test_VarDecFromDate();
6637 test_VarDecFromBool();
6639 test_VarDecAbs();
6640 test_VarDecNeg();
6641 test_VarDecAdd();
6642 test_VarDecSub();
6643 test_VarDecCmp();
6644 test_VarDecCmpR8();
6645 test_VarDecMul();
6646 test_VarDecDiv();
6647 test_VarDecRound();
6649 test_VarBoolFromI1();
6650 test_VarBoolFromUI1();
6651 test_VarBoolFromI2();
6652 test_VarBoolFromUI2();
6653 test_VarBoolFromI4();
6654 test_VarBoolFromUI4();
6655 test_VarBoolFromR4();
6656 test_VarBoolFromR8();
6657 test_VarBoolFromCy();
6658 test_VarBoolFromI8();
6659 test_VarBoolFromUI8();
6660 test_VarBoolFromDec();
6661 test_VarBoolFromDate();
6662 test_VarBoolFromStr();
6663 test_VarBoolCopy();
6664 test_VarBoolChangeTypeEx();
6666 test_VarBstrFromR4();
6667 test_VarBstrFromDate();
6668 test_VarBstrFromCy();
6669 test_VarBstrFromDec();
6670 test_VarBstrCmp();
6671 test_SysStringLen();
6672 test_SysStringByteLen();
6673 test_SysAllocString();
6674 test_SysAllocStringLen();
6675 test_SysAllocStringByteLen();
6676 test_SysReAllocString();
6677 test_SysReAllocStringLen();
6678 test_BstrCopy();
6679 test_VarBstrCat();
6681 test_IUnknownClear();
6682 test_IUnknownCopy();
6683 test_IUnknownChangeTypeEx();
6685 test_IDispatchClear();
6686 test_IDispatchCopy();
6687 test_IDispatchChangeTypeEx();
6689 test_ErrorChangeTypeEx();
6690 test_EmptyChangeTypeEx();
6691 test_NullChangeTypeEx();
6692 test_UintChangeTypeEx();
6694 test_ClearCustData();
6696 test_NullByRef();
6697 test_ChangeType_keep_dst();
6699 test_recinfo();