9c2785a23ab335f4a0dcbe276ccf922746b376be
[reactos.git] / rostests / winetests / oleaut32 / vartype.c
1 /*
2 * Low level variant tests
3 *
4 * Copyright 2003 Jon Griffiths
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #define WIN32_NO_STATUS
22 #define _INC_WINDOWS
23 #define COM_NO_WINDOWS_H
24
25 #define CONST_VTABLE
26 #define COBJMACROS
27
28 #include <wine/test.h>
29 #include <winnls.h>
30 #include <objbase.h>
31 #include <oleauto.h>
32 #include <math.h>
33 #include <test_tlb.h>
34
35 #include <initguid.h>
36
37 DEFINE_GUID(UUID_test_struct, 0x4029f190, 0xca4a, 0x4611, 0xae,0xb9,0x67,0x39,0x83,0xcb,0x96,0xdd);
38
39 /* Some Visual C++ versions choke on __uint64 to float conversions.
40 * To fix this you need either VC++ 6.0 plus the processor pack
41 * or Visual C++ >=7.0.
42 */
43 #ifndef _MSC_VER
44 # define HAS_UINT64_TO_FLOAT
45 #else
46 # if _MSC_VER >= 1300
47 # define HAS_UINT64_TO_FLOAT
48 # else
49 # include <malloc.h>
50 # if defined(_mm_free)
51 /* _mm_free is defined if the Processor Pack has been installed */
52 # define HAS_UINT64_TO_FLOAT
53 # endif
54
55 # endif
56 #endif
57
58 static HMODULE hOleaut32;
59
60 /* Get a conversion function ptr, return if function not available */
61 #define CHECKPTR(func) p##func = (void*)GetProcAddress(hOleaut32, #func); \
62 if (!p##func) { \
63 win_skip("function " # func " not available, not testing it\n"); return; }
64
65 /* Has I8/UI8 data type? */
66 static BOOL has_i8;
67 /* Has proper locale conversions? */
68 static BOOL has_locales;
69
70 /* Is vt a type unavailable to ancient versions? */
71 #define IS_MODERN_VTYPE(vt) (vt==VT_VARIANT||vt==VT_DECIMAL|| \
72 vt==VT_I1||vt==VT_UI2||vt==VT_UI4||vt == VT_INT||vt == VT_UINT)
73
74 /* Macros for converting and testing results */
75 #define CONVVARS(typ) HRESULT hres; CONV_TYPE out; typ in
76
77 #define _EXPECT_NO_OUT(res) ok(hres == res, "expected " #res ", got hres=0x%08x\n", hres)
78 #define EXPECT_OVERFLOW _EXPECT_NO_OUT(DISP_E_OVERFLOW)
79 #define EXPECT_MISMATCH _EXPECT_NO_OUT(DISP_E_TYPEMISMATCH)
80 #define EXPECT_BADVAR _EXPECT_NO_OUT(DISP_E_BADVARTYPE)
81 #define EXPECT_INVALID _EXPECT_NO_OUT(E_INVALIDARG)
82 #define EXPECT_LT _EXPECT_NO_OUT(VARCMP_LT)
83 #define EXPECT_GT _EXPECT_NO_OUT(VARCMP_GT)
84 #define EXPECT_EQ _EXPECT_NO_OUT(VARCMP_EQ)
85
86 #define _EXPECTRES(res, x, fs) \
87 ok(hres == S_OK && out == (CONV_TYPE)(x), "expected " #x ", got " fs "; hres=0x%08x\n", out, hres)
88 #define EXPECT(x) EXPECTRES(S_OK, (x))
89 #define EXPECT_DBL(x) \
90 ok(hres == S_OK && fabs(out-(x))<=1e-14*(x), "expected %16.16g, got %16.16g; hres=0x%08x\n", (x), out, hres)
91
92 #define CONVERT(func, val) in = val; hres = p##func(in, &out)
93 #define CONVERTRANGE(func,start,end) for (i = start; i < end; i+=1) { CONVERT(func, i); EXPECT(i); };
94 #define OVERFLOWRANGE(func,start,end) for (i = start; i < end; i+=1) { CONVERT(func, i); EXPECT_OVERFLOW; };
95
96 #define CY_MULTIPLIER 10000
97
98 #define DATE_MIN -657434
99 #define DATE_MAX 2958465
100
101 #define CONVERT_I8(func,hi,lo) in = hi; in = (in << 32) | lo; hres = p##func(in, &out)
102
103 #define CONVERT_CY(func,val) in.int64 = (LONGLONG)(val * CY_MULTIPLIER); hres = p##func(in, &out)
104
105 #define CONVERT_CY64(func,hi,lo) S(in).Hi = hi; S(in).Lo = lo; in.int64 *= CY_MULTIPLIER; hres = p##func(in, &out)
106
107 #define SETDEC(dec, scl, sgn, hi, lo) S(U(dec)).scale = (BYTE)scl; S(U(dec)).sign = (BYTE)sgn; \
108 dec.Hi32 = (ULONG)hi; U1(dec).Lo64 = (ULONG64)lo
109
110 #define SETDEC64(dec, scl, sgn, hi, mid, lo) S(U(dec)).scale = (BYTE)scl; S(U(dec)).sign = (BYTE)sgn; \
111 dec.Hi32 = (ULONG)hi; S1(U1(dec)).Mid32 = mid; S1(U1(dec)).Lo32 = lo;
112
113 #define CONVERT_DEC(func,scl,sgn,hi,lo) SETDEC(in,scl,sgn,hi,lo); hres = p##func(&in, &out)
114
115 #define CONVERT_DEC64(func,scl,sgn,hi,mid,lo) SETDEC64(in,scl,sgn,hi,mid,lo); hres = p##func(&in, &out)
116
117 #define CONVERT_BADDEC(func) \
118 CONVERT_DEC(func,29,0,0,0); EXPECT_INVALID; \
119 CONVERT_DEC(func,0,0x1,0,0); EXPECT_INVALID; \
120 CONVERT_DEC(func,0,0x40,0,0); EXPECT_INVALID; \
121 CONVERT_DEC(func,0,0x7f,0,0); EXPECT_INVALID;
122
123 #define CONVERT_STR(func,str,flags) \
124 SetLastError(0); \
125 if (str) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)/sizeof(WCHAR)); \
126 hres = p##func(str ? buff : NULL,in,flags,&out)
127
128 #define COPYTEST(val, vt, srcval, dstval, srcref, dstref, fs) do { \
129 HRESULT hres; VARIANTARG vSrc, vDst; CONV_TYPE in = val; \
130 VariantInit(&vSrc); VariantInit(&vDst); \
131 V_VT(&vSrc) = vt; srcval = in; \
132 hres = VariantCopy(&vDst, &vSrc); \
133 ok(hres == S_OK && V_VT(&vDst) == vt && dstval == in, \
134 "copy hres 0x%X, type %d, value (" fs ") " fs "\n", hres, V_VT(&vDst), val, dstval); \
135 V_VT(&vSrc) = vt|VT_BYREF; srcref = &in; \
136 hres = VariantCopy(&vDst, &vSrc); \
137 ok(hres == S_OK && V_VT(&vDst) == (vt|VT_BYREF) && dstref == &in, \
138 "ref hres 0x%X, type %d, ref (%p) %p\n", hres, V_VT(&vDst), &in, dstref); \
139 hres = VariantCopyInd(&vDst, &vSrc); \
140 ok(hres == S_OK && V_VT(&vDst) == vt && dstval == in, \
141 "ind hres 0x%X, type %d, value (" fs ") " fs "\n", hres, V_VT(&vDst), val, dstval); \
142 } while(0)
143
144 #define CHANGETYPEEX(typ) hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, typ)
145
146 #define TYPETEST(typ,res,fs) CHANGETYPEEX(typ); \
147 ok(hres == S_OK && V_VT(&vDst) == typ && (CONV_TYPE)res == in, \
148 "hres=0x%X, type=%d (should be %d(" #typ ")), value=" fs " (should be " fs ")\n", \
149 hres, V_VT(&vDst), typ, (CONV_TYPE)res, in);
150 #define TYPETESTI8(typ,res) CHANGETYPEEX(typ); \
151 ok(hres == S_OK && V_VT(&vDst) == typ && (CONV_TYPE)res == in, \
152 "hres=0x%X, type=%d (should be %d(" #typ ")), value=%d (should be 1)\n", \
153 hres, V_VT(&vDst), typ, (int)res);
154 #define BADVAR(typ) CHANGETYPEEX(typ); EXPECT_BADVAR
155 #define MISMATCH(typ) CHANGETYPEEX(typ); EXPECT_MISMATCH
156
157 #define INITIAL_TYPETEST(vt, val, fs) \
158 VariantInit(&vSrc); \
159 VariantInit(&vDst); \
160 V_VT(&vSrc) = vt; \
161 (val(&vSrc)) = in; \
162 TYPETEST(VT_I1, V_I1(&vDst), fs); \
163 TYPETEST(VT_UI2, V_UI2(&vDst), fs); \
164 TYPETEST(VT_UI4, V_UI4(&vDst), fs); \
165 TYPETEST(VT_INT, V_INT(&vDst), fs); \
166 TYPETEST(VT_UINT, V_UINT(&vDst), fs); \
167 TYPETEST(VT_UI1, V_UI1(&vDst), fs); \
168 TYPETEST(VT_I2, V_I2(&vDst), fs); \
169 TYPETEST(VT_I4, V_I4(&vDst), fs); \
170 TYPETEST(VT_R4, V_R4(&vDst), fs); \
171 TYPETEST(VT_R8, V_R8(&vDst), fs); \
172 TYPETEST(VT_DATE, V_DATE(&vDst), fs); \
173 if (has_i8) \
174 { \
175 TYPETEST(VT_I8, V_I8(&vDst), fs); \
176 TYPETEST(VT_UI8, V_UI8(&vDst), fs); \
177 }
178 #define NEGATIVE_TYPETEST(vt, val, fs, vtneg, valneg) \
179 in = -in; \
180 VariantInit(&vSrc); \
181 VariantInit(&vDst); \
182 V_VT(&vSrc) = vt; \
183 (val(&vSrc)) = in; \
184 TYPETEST(vtneg, valneg(&vDst), fs);
185
186 #define INITIAL_TYPETESTI8(vt, val) \
187 VariantInit(&vSrc); \
188 VariantInit(&vDst); \
189 V_VT(&vSrc) = vt; \
190 (val(&vSrc)) = in; \
191 TYPETESTI8(VT_I1, V_I1(&vDst)); \
192 TYPETESTI8(VT_UI1, V_UI1(&vDst)); \
193 TYPETESTI8(VT_I2, V_I2(&vDst)); \
194 TYPETESTI8(VT_UI2, V_UI2(&vDst)); \
195 TYPETESTI8(VT_I4, V_I4(&vDst)); \
196 TYPETESTI8(VT_UI4, V_UI4(&vDst)); \
197 TYPETESTI8(VT_INT, V_INT(&vDst)); \
198 TYPETESTI8(VT_UINT, V_UINT(&vDst)); \
199 TYPETESTI8(VT_R4, V_R4(&vDst)); \
200 TYPETESTI8(VT_R8, V_R8(&vDst)); \
201 TYPETESTI8(VT_DATE, V_DATE(&vDst)); \
202 TYPETESTI8(VT_I8, V_I8(&vDst)); \
203 TYPETESTI8(VT_UI8, V_UI8(&vDst))
204
205 #define COMMON_TYPETEST \
206 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_BOOL); \
207 ok(hres == S_OK && V_VT(&vDst) == VT_BOOL && \
208 (V_BOOL(&vDst) == VARIANT_TRUE || (V_VT(&vSrc) == VT_BOOL && V_BOOL(&vDst) == 1)), \
209 "->VT_BOOL hres=0x%X, type=%d (should be VT_BOOL), value %d (should be VARIANT_TRUE)\n", \
210 hres, V_VT(&vDst), V_BOOL(&vDst)); \
211 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_CY); \
212 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == CY_MULTIPLIER, \
213 "->VT_CY hres=0x%X, type=%d (should be VT_CY), value (%08x,%08x) (should be CY_MULTIPLIER)\n", \
214 hres, V_VT(&vDst), S(V_CY(&vDst)).Hi, S(V_CY(&vDst)).Lo); \
215 if (V_VT(&vSrc) != VT_DATE) \
216 { \
217 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_BSTR); \
218 ok(hres == S_OK && V_VT(&vDst) == VT_BSTR && \
219 V_BSTR(&vDst) && V_BSTR(&vDst)[0] == '1' && V_BSTR(&vDst)[1] == '\0', \
220 "->VT_BSTR hres=0x%X, type=%d (should be VT_BSTR), *bstr='%c'\n", \
221 hres, V_VT(&vDst), V_BSTR(&vDst) ? *V_BSTR(&vDst) : '?'); \
222 } \
223 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_DECIMAL); \
224 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && \
225 S(U(V_DECIMAL(&vDst))).sign == 0 && S(U(V_DECIMAL(&vDst))).scale == 0 && \
226 V_DECIMAL(&vDst).Hi32 == 0 && U1(V_DECIMAL(&vDst)).Lo64 == (ULONGLONG)in, \
227 "->VT_DECIMAL hres=0x%X, type=%d (should be VT_DECIMAL), sign=%d, scale=%d, hi=%u, lo=(%8x %8x),\n", \
228 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign, S(U(V_DECIMAL(&vDst))).scale, \
229 V_DECIMAL(&vDst).Hi32, S1(U1(V_DECIMAL(&vDst))).Mid32, S1(U1(V_DECIMAL(&vDst))).Lo32); \
230 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_EMPTY); \
231 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)); \
232 hres = VariantChangeTypeEx(&vDst, &vSrc, 0, 0, VT_NULL); \
233 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)); \
234 MISMATCH(VT_DISPATCH); \
235 MISMATCH(VT_ERROR); \
236 MISMATCH(VT_UNKNOWN); \
237 MISMATCH(VT_VARIANT); \
238 MISMATCH(VT_RECORD); \
239 BADVAR(VT_VOID); \
240 BADVAR(VT_HRESULT); \
241 BADVAR(VT_SAFEARRAY); \
242 BADVAR(VT_CARRAY); \
243 BADVAR(VT_USERDEFINED); \
244 BADVAR(VT_LPSTR); \
245 BADVAR(VT_LPWSTR); \
246 BADVAR(VT_PTR); \
247 BADVAR(VT_INT_PTR); \
248 BADVAR(VT_UINT_PTR); \
249 BADVAR(VT_FILETIME); \
250 BADVAR(VT_BLOB); \
251 BADVAR(VT_STREAM); \
252 BADVAR(VT_STORAGE); \
253 BADVAR(VT_STREAMED_OBJECT); \
254 BADVAR(VT_STORED_OBJECT); \
255 BADVAR(VT_BLOB_OBJECT); \
256 BADVAR(VT_CF); \
257 BADVAR(VT_CLSID); \
258 BADVAR(VT_BSTR_BLOB)
259
260 #define DEFINE_EXPECT(func) \
261 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
262
263 #define SET_EXPECT(func) \
264 do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
265
266 #define CHECK_EXPECT2(func) \
267 do { \
268 ok(expect_ ##func, "unexpected call " #func "\n"); \
269 called_ ## func = TRUE; \
270 }while(0)
271
272 #define CHECK_EXPECT(func) \
273 do { \
274 CHECK_EXPECT2(func); \
275 expect_ ## func = FALSE; \
276 }while(0)
277
278 #define CHECK_CALLED(func) \
279 do { \
280 ok(called_ ## func, "expected " #func "\n"); \
281 expect_ ## func = called_ ## func = FALSE; \
282 }while(0)
283
284 DEFINE_EXPECT(dispatch_invoke);
285
286 /* Early versions of oleaut32 are missing many functions */
287 static HRESULT (WINAPI *pVarI1FromUI1)(BYTE,signed char*);
288 static HRESULT (WINAPI *pVarI1FromI2)(SHORT,signed char*);
289 static HRESULT (WINAPI *pVarI1FromI4)(LONG,signed char*);
290 static HRESULT (WINAPI *pVarI1FromR4)(FLOAT,signed char*);
291 static HRESULT (WINAPI *pVarI1FromR8)(double,signed char*);
292 static HRESULT (WINAPI *pVarI1FromDate)(DATE,signed char*);
293 static HRESULT (WINAPI *pVarI1FromCy)(CY,signed char*);
294 static HRESULT (WINAPI *pVarI1FromStr)(OLECHAR*,LCID,ULONG,signed char*);
295 static HRESULT (WINAPI *pVarI1FromBool)(VARIANT_BOOL,signed char*);
296 static HRESULT (WINAPI *pVarI1FromUI2)(USHORT,signed char*);
297 static HRESULT (WINAPI *pVarI1FromUI4)(ULONG,signed char*);
298 static HRESULT (WINAPI *pVarI1FromDec)(DECIMAL*,signed char*);
299 static HRESULT (WINAPI *pVarI1FromI8)(LONG64,signed char*);
300 static HRESULT (WINAPI *pVarI1FromUI8)(ULONG64,signed char*);
301 static HRESULT (WINAPI *pVarUI1FromI2)(SHORT,BYTE*);
302 static HRESULT (WINAPI *pVarUI1FromI4)(LONG,BYTE*);
303 static HRESULT (WINAPI *pVarUI1FromR4)(FLOAT,BYTE*);
304 static HRESULT (WINAPI *pVarUI1FromR8)(double,BYTE*);
305 static HRESULT (WINAPI *pVarUI1FromCy)(CY,BYTE*);
306 static HRESULT (WINAPI *pVarUI1FromDate)(DATE,BYTE*);
307 static HRESULT (WINAPI *pVarUI1FromStr)(OLECHAR*,LCID,ULONG,BYTE*);
308 static HRESULT (WINAPI *pVarUI1FromBool)(VARIANT_BOOL,BYTE*);
309 static HRESULT (WINAPI *pVarUI1FromI1)(signed char,BYTE*);
310 static HRESULT (WINAPI *pVarUI1FromUI2)(USHORT,BYTE*);
311 static HRESULT (WINAPI *pVarUI1FromUI4)(ULONG,BYTE*);
312 static HRESULT (WINAPI *pVarUI1FromDec)(DECIMAL*,BYTE*);
313 static HRESULT (WINAPI *pVarUI1FromI8)(LONG64,BYTE*);
314 static HRESULT (WINAPI *pVarUI1FromUI8)(ULONG64,BYTE*);
315 static HRESULT (WINAPI *pVarUI1FromDisp)(IDispatch*,LCID,BYTE*);
316
317 static HRESULT (WINAPI *pVarI2FromUI1)(BYTE,SHORT*);
318 static HRESULT (WINAPI *pVarI2FromI4)(LONG,SHORT*);
319 static HRESULT (WINAPI *pVarI2FromR4)(FLOAT,SHORT*);
320 static HRESULT (WINAPI *pVarI2FromR8)(double,SHORT*);
321 static HRESULT (WINAPI *pVarI2FromCy)(CY,SHORT*);
322 static HRESULT (WINAPI *pVarI2FromDate)(DATE,SHORT*);
323 static HRESULT (WINAPI *pVarI2FromStr)(OLECHAR*,LCID,ULONG,SHORT*);
324 static HRESULT (WINAPI *pVarI2FromBool)(VARIANT_BOOL,SHORT*);
325 static HRESULT (WINAPI *pVarI2FromI1)(signed char,SHORT*);
326 static HRESULT (WINAPI *pVarI2FromUI2)(USHORT,SHORT*);
327 static HRESULT (WINAPI *pVarI2FromUI4)(ULONG,SHORT*);
328 static HRESULT (WINAPI *pVarI2FromDec)(DECIMAL*,SHORT*);
329 static HRESULT (WINAPI *pVarI2FromI8)(LONG64,SHORT*);
330 static HRESULT (WINAPI *pVarI2FromUI8)(ULONG64,SHORT*);
331 static HRESULT (WINAPI *pVarUI2FromUI1)(BYTE,USHORT*);
332 static HRESULT (WINAPI *pVarUI2FromI2)(SHORT,USHORT*);
333 static HRESULT (WINAPI *pVarUI2FromI4)(LONG,USHORT*);
334 static HRESULT (WINAPI *pVarUI2FromR4)(FLOAT,USHORT*);
335 static HRESULT (WINAPI *pVarUI2FromR8)(double,USHORT*);
336 static HRESULT (WINAPI *pVarUI2FromDate)(DATE,USHORT*);
337 static HRESULT (WINAPI *pVarUI2FromCy)(CY,USHORT*);
338 static HRESULT (WINAPI *pVarUI2FromStr)(OLECHAR*,LCID,ULONG,USHORT*);
339 static HRESULT (WINAPI *pVarUI2FromBool)(VARIANT_BOOL,USHORT*);
340 static HRESULT (WINAPI *pVarUI2FromI1)(signed char,USHORT*);
341 static HRESULT (WINAPI *pVarUI2FromUI4)(ULONG,USHORT*);
342 static HRESULT (WINAPI *pVarUI2FromDec)(DECIMAL*,USHORT*);
343 static HRESULT (WINAPI *pVarUI2FromI8)(LONG64,USHORT*);
344 static HRESULT (WINAPI *pVarUI2FromUI8)(ULONG64,USHORT*);
345
346 static HRESULT (WINAPI *pVarI4FromUI1)(BYTE,LONG*);
347 static HRESULT (WINAPI *pVarI4FromI2)(SHORT,LONG*);
348 static HRESULT (WINAPI *pVarI4FromR4)(FLOAT,LONG*);
349 static HRESULT (WINAPI *pVarI4FromR8)(DOUBLE,LONG*);
350 static HRESULT (WINAPI *pVarI4FromCy)(CY,LONG*);
351 static HRESULT (WINAPI *pVarI4FromDate)(DATE,LONG*);
352 static HRESULT (WINAPI *pVarI4FromStr)(OLECHAR*,LCID,ULONG,LONG*);
353 static HRESULT (WINAPI *pVarI4FromBool)(VARIANT_BOOL,LONG*);
354 static HRESULT (WINAPI *pVarI4FromI1)(signed char,LONG*);
355 static HRESULT (WINAPI *pVarI4FromUI2)(USHORT,LONG*);
356 static HRESULT (WINAPI *pVarI4FromUI4)(ULONG,LONG*);
357 static HRESULT (WINAPI *pVarI4FromDec)(DECIMAL*,LONG*);
358 static HRESULT (WINAPI *pVarI4FromI8)(LONG64,LONG*);
359 static HRESULT (WINAPI *pVarI4FromUI8)(ULONG64,LONG*);
360 static HRESULT (WINAPI *pVarUI4FromUI1)(BYTE,ULONG*);
361 static HRESULT (WINAPI *pVarUI4FromI2)(SHORT,ULONG*);
362 static HRESULT (WINAPI *pVarUI4FromI4)(LONG,ULONG*);
363 static HRESULT (WINAPI *pVarUI4FromR4)(FLOAT,ULONG*);
364 static HRESULT (WINAPI *pVarUI4FromR8)(DOUBLE,ULONG*);
365 static HRESULT (WINAPI *pVarUI4FromDate)(DATE,ULONG*);
366 static HRESULT (WINAPI *pVarUI4FromCy)(CY,ULONG*);
367 static HRESULT (WINAPI *pVarUI4FromStr)(OLECHAR*,LCID,ULONG,ULONG*);
368 static HRESULT (WINAPI *pVarUI4FromBool)(VARIANT_BOOL,ULONG*);
369 static HRESULT (WINAPI *pVarUI4FromI1)(signed char,ULONG*);
370 static HRESULT (WINAPI *pVarUI4FromUI2)(USHORT,ULONG*);
371 static HRESULT (WINAPI *pVarUI4FromDec)(DECIMAL*,ULONG*);
372 static HRESULT (WINAPI *pVarUI4FromI8)(LONG64,ULONG*);
373 static HRESULT (WINAPI *pVarUI4FromUI8)(ULONG64,ULONG*);
374
375 static HRESULT (WINAPI *pVarI8FromUI1)(BYTE,LONG64*);
376 static HRESULT (WINAPI *pVarI8FromI2)(SHORT,LONG64*);
377 static HRESULT (WINAPI *pVarI8FromR4)(FLOAT,LONG64*);
378 static HRESULT (WINAPI *pVarI8FromR8)(double,LONG64*);
379 static HRESULT (WINAPI *pVarI8FromCy)(CY,LONG64*);
380 static HRESULT (WINAPI *pVarI8FromDate)(DATE,LONG64*);
381 static HRESULT (WINAPI *pVarI8FromStr)(OLECHAR*,LCID,ULONG,LONG64*);
382 static HRESULT (WINAPI *pVarI8FromBool)(VARIANT_BOOL,LONG64*);
383 static HRESULT (WINAPI *pVarI8FromI1)(signed char,LONG64*);
384 static HRESULT (WINAPI *pVarI8FromUI2)(USHORT,LONG64*);
385 static HRESULT (WINAPI *pVarI8FromUI4)(ULONG,LONG64*);
386 static HRESULT (WINAPI *pVarI8FromDec)(DECIMAL*,LONG64*);
387 static HRESULT (WINAPI *pVarI8FromUI8)(ULONG64,LONG64*);
388 static HRESULT (WINAPI *pVarUI8FromI8)(LONG64,ULONG64*);
389 static HRESULT (WINAPI *pVarUI8FromUI1)(BYTE,ULONG64*);
390 static HRESULT (WINAPI *pVarUI8FromI2)(SHORT,ULONG64*);
391 static HRESULT (WINAPI *pVarUI8FromR4)(FLOAT,ULONG64*);
392 static HRESULT (WINAPI *pVarUI8FromR8)(double,ULONG64*);
393 static HRESULT (WINAPI *pVarUI8FromCy)(CY,ULONG64*);
394 static HRESULT (WINAPI *pVarUI8FromDate)(DATE,ULONG64*);
395 static HRESULT (WINAPI *pVarUI8FromStr)(OLECHAR*,LCID,ULONG,ULONG64*);
396 static HRESULT (WINAPI *pVarUI8FromBool)(VARIANT_BOOL,ULONG64*);
397 static HRESULT (WINAPI *pVarUI8FromI1)(signed char,ULONG64*);
398 static HRESULT (WINAPI *pVarUI8FromUI2)(USHORT,ULONG64*);
399 static HRESULT (WINAPI *pVarUI8FromUI4)(ULONG,ULONG64*);
400 static HRESULT (WINAPI *pVarUI8FromDec)(DECIMAL*,ULONG64*);
401
402 static HRESULT (WINAPI *pVarR4FromUI1)(BYTE,float*);
403 static HRESULT (WINAPI *pVarR4FromI2)(SHORT,float*);
404 static HRESULT (WINAPI *pVarR4FromI4)(LONG,float*);
405 static HRESULT (WINAPI *pVarR4FromR8)(double,float*);
406 static HRESULT (WINAPI *pVarR4FromCy)(CY,float*);
407 static HRESULT (WINAPI *pVarR4FromDate)(DATE,float*);
408 static HRESULT (WINAPI *pVarR4FromStr)(OLECHAR*,LCID,ULONG,float*);
409 static HRESULT (WINAPI *pVarR4FromBool)(VARIANT_BOOL,float*);
410 static HRESULT (WINAPI *pVarR4FromI1)(signed char,float*);
411 static HRESULT (WINAPI *pVarR4FromUI2)(USHORT,float*);
412 static HRESULT (WINAPI *pVarR4FromUI4)(ULONG,float*);
413 static HRESULT (WINAPI *pVarR4FromDec)(DECIMAL*,float*);
414 static HRESULT (WINAPI *pVarR4FromI8)(LONG64,float*);
415 static HRESULT (WINAPI *pVarR4FromUI8)(ULONG64,float*);
416
417 static HRESULT (WINAPI *pVarR8FromUI1)(BYTE,double*);
418 static HRESULT (WINAPI *pVarR8FromI2)(SHORT,double*);
419 static HRESULT (WINAPI *pVarR8FromI4)(LONG,double*);
420 static HRESULT (WINAPI *pVarR8FromR4)(FLOAT,double*);
421 static HRESULT (WINAPI *pVarR8FromCy)(CY,double*);
422 static HRESULT (WINAPI *pVarR8FromDate)(DATE,double*);
423 static HRESULT (WINAPI *pVarR8FromStr)(OLECHAR*,LCID,ULONG,double*);
424 static HRESULT (WINAPI *pVarR8FromBool)(VARIANT_BOOL,double*);
425 static HRESULT (WINAPI *pVarR8FromI1)(signed char,double*);
426 static HRESULT (WINAPI *pVarR8FromUI2)(USHORT,double*);
427 static HRESULT (WINAPI *pVarR8FromUI4)(ULONG,double*);
428 static HRESULT (WINAPI *pVarR8FromDec)(DECIMAL*,double*);
429 static HRESULT (WINAPI *pVarR8FromI8)(LONG64,double*);
430 static HRESULT (WINAPI *pVarR8FromUI8)(ULONG64,double*);
431 static HRESULT (WINAPI *pVarR8Round)(double,int,double*);
432
433 static HRESULT (WINAPI *pVarDateFromUI1)(BYTE,DATE*);
434 static HRESULT (WINAPI *pVarDateFromI2)(SHORT,DATE*);
435 static HRESULT (WINAPI *pVarDateFromI4)(LONG,DATE*);
436 static HRESULT (WINAPI *pVarDateFromR4)(FLOAT,DATE*);
437 static HRESULT (WINAPI *pVarDateFromCy)(CY,DATE*);
438 static HRESULT (WINAPI *pVarDateFromR8)(double,DATE*);
439 static HRESULT (WINAPI *pVarDateFromStr)(OLECHAR*,LCID,ULONG,DATE*);
440 static HRESULT (WINAPI *pVarDateFromBool)(VARIANT_BOOL,DATE*);
441 static HRESULT (WINAPI *pVarDateFromI1)(signed char,DATE*);
442 static HRESULT (WINAPI *pVarDateFromUI2)(USHORT,DATE*);
443 static HRESULT (WINAPI *pVarDateFromUI4)(ULONG,DATE*);
444 static HRESULT (WINAPI *pVarDateFromDec)(DECIMAL*,DATE*);
445 static HRESULT (WINAPI *pVarDateFromI8)(LONG64,DATE*);
446 static HRESULT (WINAPI *pVarDateFromUI8)(ULONG64,DATE*);
447
448 static HRESULT (WINAPI *pVarCyFromUI1)(BYTE,CY*);
449 static HRESULT (WINAPI *pVarCyFromI2)(SHORT,CY*);
450 static HRESULT (WINAPI *pVarCyFromI4)(LONG,CY*);
451 static HRESULT (WINAPI *pVarCyFromR4)(FLOAT,CY*);
452 static HRESULT (WINAPI *pVarCyFromR8)(double,CY*);
453 static HRESULT (WINAPI *pVarCyFromDate)(DATE,CY*);
454 static HRESULT (WINAPI *pVarCyFromBool)(VARIANT_BOOL,CY*);
455 static HRESULT (WINAPI *pVarCyFromI1)(signed char,CY*);
456 static HRESULT (WINAPI *pVarCyFromUI2)(USHORT,CY*);
457 static HRESULT (WINAPI *pVarCyFromUI4)(ULONG,CY*);
458 static HRESULT (WINAPI *pVarCyFromDec)(DECIMAL*,CY*);
459 static HRESULT (WINAPI *pVarCyFromI8)(LONG64,CY*);
460 static HRESULT (WINAPI *pVarCyFromUI8)(ULONG64,CY*);
461 static HRESULT (WINAPI *pVarCyAdd)(const CY,const CY,CY*);
462 static HRESULT (WINAPI *pVarCyMul)(const CY,const CY,CY*);
463 static HRESULT (WINAPI *pVarCyMulI4)(const CY,LONG,CY*);
464 static HRESULT (WINAPI *pVarCySub)(const CY,const CY,CY*);
465 static HRESULT (WINAPI *pVarCyAbs)(const CY,CY*);
466 static HRESULT (WINAPI *pVarCyFix)(const CY,CY*);
467 static HRESULT (WINAPI *pVarCyInt)(const CY,CY*);
468 static HRESULT (WINAPI *pVarCyNeg)(const CY,CY*);
469 static HRESULT (WINAPI *pVarCyRound)(const CY,int,CY*);
470 static HRESULT (WINAPI *pVarCyCmp)(const CY,const CY);
471 static HRESULT (WINAPI *pVarCyCmpR8)(const CY,double);
472 static HRESULT (WINAPI *pVarCyMulI8)(const CY,LONG64,CY*);
473
474 static HRESULT (WINAPI *pVarDecFromUI1)(BYTE,DECIMAL*);
475 static HRESULT (WINAPI *pVarDecFromI2)(SHORT,DECIMAL*);
476 static HRESULT (WINAPI *pVarDecFromI4)(LONG,DECIMAL*);
477 static HRESULT (WINAPI *pVarDecFromI8)(LONG64,DECIMAL*);
478 static HRESULT (WINAPI *pVarDecFromR4)(FLOAT,DECIMAL*);
479 static HRESULT (WINAPI *pVarDecFromR8)(DOUBLE,DECIMAL*);
480 static HRESULT (WINAPI *pVarDecFromDate)(DATE,DECIMAL*);
481 static HRESULT (WINAPI *pVarDecFromStr)(OLECHAR*,LCID,ULONG,DECIMAL*);
482 static HRESULT (WINAPI *pVarDecFromBool)(VARIANT_BOOL,DECIMAL*);
483 static HRESULT (WINAPI *pVarDecFromI1)(signed char,DECIMAL*);
484 static HRESULT (WINAPI *pVarDecFromUI2)(USHORT,DECIMAL*);
485 static HRESULT (WINAPI *pVarDecFromUI4)(ULONG,DECIMAL*);
486 static HRESULT (WINAPI *pVarDecFromUI8)(ULONG64,DECIMAL*);
487 static HRESULT (WINAPI *pVarDecFromCy)(CY,DECIMAL*);
488 static HRESULT (WINAPI *pVarDecAbs)(const DECIMAL*,DECIMAL*);
489 static HRESULT (WINAPI *pVarDecAdd)(const DECIMAL*,const DECIMAL*,DECIMAL*);
490 static HRESULT (WINAPI *pVarDecSub)(const DECIMAL*,const DECIMAL*,DECIMAL*);
491 static HRESULT (WINAPI *pVarDecMul)(const DECIMAL*,const DECIMAL*,DECIMAL*);
492 static HRESULT (WINAPI *pVarDecDiv)(const DECIMAL*,const DECIMAL*,DECIMAL*);
493 static HRESULT (WINAPI *pVarDecCmp)(const DECIMAL*,const DECIMAL*);
494 static HRESULT (WINAPI *pVarDecCmpR8)(const DECIMAL*,double);
495 static HRESULT (WINAPI *pVarDecNeg)(const DECIMAL*,DECIMAL*);
496 static HRESULT (WINAPI *pVarDecRound)(const DECIMAL*,int,DECIMAL*);
497
498 static HRESULT (WINAPI *pVarBoolFromUI1)(BYTE,VARIANT_BOOL*);
499 static HRESULT (WINAPI *pVarBoolFromI2)(SHORT,VARIANT_BOOL*);
500 static HRESULT (WINAPI *pVarBoolFromI4)(LONG,VARIANT_BOOL*);
501 static HRESULT (WINAPI *pVarBoolFromR4)(FLOAT,VARIANT_BOOL*);
502 static HRESULT (WINAPI *pVarBoolFromR8)(DOUBLE,VARIANT_BOOL*);
503 static HRESULT (WINAPI *pVarBoolFromDate)(DATE,VARIANT_BOOL*);
504 static HRESULT (WINAPI *pVarBoolFromCy)(CY,VARIANT_BOOL*);
505 static HRESULT (WINAPI *pVarBoolFromStr)(OLECHAR*,LCID,ULONG,VARIANT_BOOL*);
506 static HRESULT (WINAPI *pVarBoolFromI1)(signed char,VARIANT_BOOL*);
507 static HRESULT (WINAPI *pVarBoolFromUI2)(USHORT,VARIANT_BOOL*);
508 static HRESULT (WINAPI *pVarBoolFromUI4)(ULONG,VARIANT_BOOL*);
509 static HRESULT (WINAPI *pVarBoolFromDec)(DECIMAL*,VARIANT_BOOL*);
510 static HRESULT (WINAPI *pVarBoolFromI8)(LONG64,VARIANT_BOOL*);
511 static HRESULT (WINAPI *pVarBoolFromUI8)(ULONG64,VARIANT_BOOL*);
512
513 static HRESULT (WINAPI *pVarBstrFromR4)(FLOAT,LCID,ULONG,BSTR*);
514 static HRESULT (WINAPI *pVarBstrFromDate)(DATE,LCID,ULONG,BSTR*);
515 static HRESULT (WINAPI *pVarBstrFromCy)(CY,LCID,ULONG,BSTR*);
516 static HRESULT (WINAPI *pVarBstrFromDec)(DECIMAL*,LCID,ULONG,BSTR*);
517 static HRESULT (WINAPI *pVarBstrCmp)(BSTR,BSTR,LCID,ULONG);
518 static HRESULT (WINAPI *pVarBstrCat)(BSTR,BSTR,BSTR*);
519
520 static INT (WINAPI *pSystemTimeToVariantTime)(LPSYSTEMTIME,double*);
521 static void (WINAPI *pClearCustData)(LPCUSTDATA);
522
523 /* Internal representation of a BSTR */
524 typedef struct tagINTERNAL_BSTR
525 {
526 DWORD dwLen;
527 OLECHAR szString[1];
528 } INTERNAL_BSTR, *LPINTERNAL_BSTR;
529
530 typedef struct
531 {
532 IDispatch IDispatch_iface;
533 LONG ref;
534 VARTYPE vt;
535 BOOL bFailInvoke;
536 } DummyDispatch;
537
538 static inline DummyDispatch *impl_from_IDispatch(IDispatch *iface)
539 {
540 return CONTAINING_RECORD(iface, DummyDispatch, IDispatch_iface);
541 }
542
543 static ULONG WINAPI DummyDispatch_AddRef(IDispatch *iface)
544 {
545 DummyDispatch *This = impl_from_IDispatch(iface);
546 return InterlockedIncrement(&This->ref);
547 }
548
549 static ULONG WINAPI DummyDispatch_Release(IDispatch *iface)
550 {
551 DummyDispatch *This = impl_from_IDispatch(iface);
552 return InterlockedDecrement(&This->ref);
553 }
554
555 static HRESULT WINAPI DummyDispatch_QueryInterface(IDispatch *iface,
556 REFIID riid,
557 void** ppvObject)
558 {
559 *ppvObject = NULL;
560
561 if (IsEqualIID(riid, &IID_IDispatch) ||
562 IsEqualIID(riid, &IID_IUnknown))
563 {
564 *ppvObject = iface;
565 IDispatch_AddRef(iface);
566 }
567
568 return *ppvObject ? S_OK : E_NOINTERFACE;
569 }
570
571 static HRESULT WINAPI DummyDispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
572 {
573 ok(0, "Unexpected call\n");
574 return E_NOTIMPL;
575 }
576
577 static HRESULT WINAPI DummyDispatch_GetTypeInfo(IDispatch *iface, UINT tinfo, LCID lcid, ITypeInfo **ti)
578 {
579 ok(0, "Unexpected call\n");
580 return E_NOTIMPL;
581 }
582
583 static HRESULT WINAPI DummyDispatch_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *names,
584 UINT cnames, LCID lcid, DISPID *dispid)
585 {
586 ok(0, "Unexpected call\n");
587 return E_NOTIMPL;
588 }
589
590 static HRESULT WINAPI DummyDispatch_Invoke(IDispatch *iface,
591 DISPID dispid, REFIID riid,
592 LCID lcid, WORD wFlags,
593 DISPPARAMS *params,
594 VARIANT *res,
595 EXCEPINFO *ei,
596 UINT *arg_err)
597 {
598 DummyDispatch *This = impl_from_IDispatch(iface);
599
600 CHECK_EXPECT(dispatch_invoke);
601
602 ok(dispid == DISPID_VALUE, "got dispid %d\n", dispid);
603 ok(IsEqualIID(riid, &IID_NULL), "go riid %s\n", wine_dbgstr_guid(riid));
604 ok(wFlags == DISPATCH_PROPERTYGET, "Flags wrong\n");
605
606 ok(params->rgvarg == NULL, "got %p\n", params->rgvarg);
607 ok(params->rgdispidNamedArgs == NULL, "got %p\n", params->rgdispidNamedArgs);
608 ok(params->cArgs == 0, "got %d\n", params->cArgs);
609 ok(params->cNamedArgs == 0, "got %d\n", params->cNamedArgs);
610
611 ok(res != NULL, "got %p\n", res);
612 ok(V_VT(res) == VT_EMPTY, "got %d\n", V_VT(res));
613 ok(ei == NULL, "got %p\n", ei);
614 ok(arg_err == NULL, "got %p\n", arg_err);
615
616 if (This->bFailInvoke)
617 return E_OUTOFMEMORY;
618
619 V_VT(res) = This->vt;
620 if (This->vt == VT_UI1)
621 V_UI1(res) = 1;
622 else
623 memset(res, 0, sizeof(*res));
624
625 return S_OK;
626 }
627
628 static const IDispatchVtbl DummyDispatch_VTable =
629 {
630 DummyDispatch_QueryInterface,
631 DummyDispatch_AddRef,
632 DummyDispatch_Release,
633 DummyDispatch_GetTypeInfoCount,
634 DummyDispatch_GetTypeInfo,
635 DummyDispatch_GetIDsOfNames,
636 DummyDispatch_Invoke
637 };
638
639 static void init_test_dispatch(LONG ref, VARTYPE vt, DummyDispatch *dispatch)
640 {
641 dispatch->IDispatch_iface.lpVtbl = &DummyDispatch_VTable;
642 dispatch->ref = ref;
643 dispatch->vt = vt;
644 dispatch->bFailInvoke = FALSE;
645 }
646
647 /*
648 * VT_I1/VT_UI1
649 */
650
651 #undef CONV_TYPE
652 #define CONV_TYPE signed char
653 #undef EXPECTRES
654 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%d")
655
656 static void test_VarI1FromI2(void)
657 {
658 CONVVARS(SHORT);
659 int i;
660
661 CHECKPTR(VarI1FromI2);
662 OVERFLOWRANGE(VarI1FromI2, -32768, -128);
663 CONVERTRANGE(VarI1FromI2, -128, 128);
664 OVERFLOWRANGE(VarI1FromI2, 129, 32768);
665 }
666
667 static void test_VarI1FromI4(void)
668 {
669 CONVVARS(LONG);
670 int i;
671
672 CHECKPTR(VarI1FromI4);
673 CONVERT(VarI1FromI4, -129); EXPECT_OVERFLOW;
674 CONVERTRANGE(VarI1FromI4, -128, 128);
675 CONVERT(VarI1FromI4, 128); EXPECT_OVERFLOW;
676 }
677
678 static void test_VarI1FromI8(void)
679 {
680 CONVVARS(LONG64);
681 int i;
682
683 CHECKPTR(VarI1FromI8);
684 CONVERT(VarI1FromI8, -129); EXPECT_OVERFLOW;
685 CONVERTRANGE(VarI1FromI8, -127, 128);
686 CONVERT(VarI1FromI8, 128); EXPECT_OVERFLOW;
687 }
688
689 static void test_VarI1FromUI1(void)
690 {
691 CONVVARS(BYTE);
692 int i;
693
694 CHECKPTR(VarI1FromUI1);
695 CONVERTRANGE(VarI1FromUI1, 0, 127);
696 OVERFLOWRANGE(VarI1FromUI1, 128, 255);
697 }
698
699 static void test_VarI1FromUI2(void)
700 {
701 CONVVARS(USHORT);
702 int i;
703
704 CHECKPTR(VarI1FromUI2);
705 CONVERTRANGE(VarI1FromUI2, 0, 127);
706 OVERFLOWRANGE(VarI1FromUI2, 128, 32768);
707 }
708
709 static void test_VarI1FromUI4(void)
710 {
711 CONVVARS(ULONG);
712 int i;
713
714 CHECKPTR(VarI1FromUI4);
715 CONVERTRANGE(VarI1FromUI4, 0, 127);
716 CONVERT(VarI1FromUI4, 128); EXPECT_OVERFLOW;
717 }
718
719 static void test_VarI1FromUI8(void)
720 {
721 CONVVARS(ULONG64);
722 int i;
723
724 CHECKPTR(VarI1FromUI8);
725 CONVERTRANGE(VarI1FromUI8, 0, 127);
726 CONVERT(VarI1FromUI8, 128); EXPECT_OVERFLOW;
727 }
728
729 static void test_VarI1FromBool(void)
730 {
731 CONVVARS(VARIANT_BOOL);
732 int i;
733
734 CHECKPTR(VarI1FromBool);
735 /* Note that conversions from bool wrap around! */
736 CONVERT(VarI1FromBool, -129); EXPECT(127);
737 CONVERTRANGE(VarI1FromBool, -128, 128);
738 CONVERT(VarI1FromBool, 128); EXPECT(-128);
739 }
740
741 static void test_VarI1FromR4(void)
742 {
743 CONVVARS(FLOAT);
744
745 CHECKPTR(VarI1FromR4);
746 CONVERT(VarI1FromR4, -129.0f); EXPECT_OVERFLOW;
747 CONVERT(VarI1FromR4, -128.51f); EXPECT_OVERFLOW;
748 CONVERT(VarI1FromR4, -128.5f); EXPECT(-128);
749 CONVERT(VarI1FromR4, -128.0f); EXPECT(-128);
750 CONVERT(VarI1FromR4, -1.0f); EXPECT(-1);
751 CONVERT(VarI1FromR4, 0.0f); EXPECT(0);
752 CONVERT(VarI1FromR4, 1.0f); EXPECT(1);
753 CONVERT(VarI1FromR4, 127.0f); EXPECT(127);
754 CONVERT(VarI1FromR4, 127.49f); EXPECT(127);
755 CONVERT(VarI1FromR4, 127.5f); EXPECT_OVERFLOW;
756 CONVERT(VarI1FromR4, 128.0f); EXPECT_OVERFLOW;
757
758 CONVERT(VarI1FromR4, -1.5f); EXPECT(-2);
759 CONVERT(VarI1FromR4, -0.6f); EXPECT(-1);
760 CONVERT(VarI1FromR4, -0.5f); EXPECT(0);
761 CONVERT(VarI1FromR4, -0.4f); EXPECT(0);
762 CONVERT(VarI1FromR4, 0.4f); EXPECT(0);
763 CONVERT(VarI1FromR4, 0.5f); EXPECT(0);
764 CONVERT(VarI1FromR4, 0.6f); EXPECT(1);
765 CONVERT(VarI1FromR4, 1.5f); EXPECT(2);
766 }
767
768 static void test_VarI1FromR8(void)
769 {
770 CONVVARS(DOUBLE);
771
772 CHECKPTR(VarI1FromR8);
773 CONVERT(VarI1FromR8, -129.0); EXPECT_OVERFLOW;
774 CONVERT(VarI1FromR8, -128.51); EXPECT_OVERFLOW;
775 CONVERT(VarI1FromR8, -128.5); EXPECT(-128);
776 CONVERT(VarI1FromR8, -128.0); EXPECT(-128);
777 CONVERT(VarI1FromR8, -1.0); EXPECT(-1);
778 CONVERT(VarI1FromR8, 0.0); EXPECT(0);
779 CONVERT(VarI1FromR8, 1.0); EXPECT(1);
780 CONVERT(VarI1FromR8, 127.0); EXPECT(127);
781 CONVERT(VarI1FromR8, 127.49); EXPECT(127);
782 CONVERT(VarI1FromR8, 127.5); EXPECT_OVERFLOW;
783 CONVERT(VarI1FromR8, 128.0); EXPECT_OVERFLOW;
784
785 CONVERT(VarI1FromR8, -1.5); EXPECT(-2);
786 CONVERT(VarI1FromR8, -0.6); EXPECT(-1);
787 CONVERT(VarI1FromR8, -0.5); EXPECT(0);
788 CONVERT(VarI1FromR8, -0.4); EXPECT(0);
789 CONVERT(VarI1FromR8, 0.4); EXPECT(0);
790 CONVERT(VarI1FromR8, 0.5); EXPECT(0);
791 CONVERT(VarI1FromR8, 0.6); EXPECT(1);
792 CONVERT(VarI1FromR8, 1.5); EXPECT(2);
793 }
794
795 static void test_VarI1FromDate(void)
796 {
797 CONVVARS(DATE);
798
799 CHECKPTR(VarI1FromDate);
800 CONVERT(VarI1FromDate, -129.0); EXPECT_OVERFLOW;
801 CONVERT(VarI1FromDate, -128.0); EXPECT(-128);
802 CONVERT(VarI1FromDate, -1.0); EXPECT(-1);
803 CONVERT(VarI1FromDate, 0.0); EXPECT(0);
804 CONVERT(VarI1FromDate, 1.0); EXPECT(1);
805 CONVERT(VarI1FromDate, 127.0); EXPECT(127);
806 CONVERT(VarI1FromDate, 128.0); EXPECT_OVERFLOW;
807
808 CONVERT(VarI1FromDate, -1.5); EXPECT(-2);
809 CONVERT(VarI1FromDate, -0.6); EXPECT(-1);
810 CONVERT(VarI1FromDate, -0.5); EXPECT(0);
811 CONVERT(VarI1FromDate, -0.4); EXPECT(0);
812 CONVERT(VarI1FromDate, 0.4); EXPECT(0);
813 CONVERT(VarI1FromDate, 0.5); EXPECT(0);
814 CONVERT(VarI1FromDate, 0.6); EXPECT(1);
815 CONVERT(VarI1FromDate, 1.5); EXPECT(2);
816 }
817
818 static void test_VarI1FromCy(void)
819 {
820 CONVVARS(CY);
821
822 CHECKPTR(VarI1FromCy);
823 CONVERT_CY(VarI1FromCy,-129); EXPECT_OVERFLOW;
824 CONVERT_CY(VarI1FromCy,-128); EXPECT(128);
825 CONVERT_CY(VarI1FromCy,-1); EXPECT(-1);
826 CONVERT_CY(VarI1FromCy,0); EXPECT(0);
827 CONVERT_CY(VarI1FromCy,1); EXPECT(1);
828 CONVERT_CY(VarI1FromCy,127); EXPECT(127);
829 CONVERT_CY(VarI1FromCy,128); EXPECT_OVERFLOW;
830
831 CONVERT_CY(VarI1FromCy,-1.5); EXPECT(-2);
832 CONVERT_CY(VarI1FromCy,-0.6); EXPECT(-1);
833 CONVERT_CY(VarI1FromCy,-0.5); EXPECT(0);
834 CONVERT_CY(VarI1FromCy,-0.4); EXPECT(0);
835 CONVERT_CY(VarI1FromCy,0.4); EXPECT(0);
836 CONVERT_CY(VarI1FromCy,0.5); EXPECT(0);
837 CONVERT_CY(VarI1FromCy,0.6); EXPECT(1);
838 CONVERT_CY(VarI1FromCy,1.5); EXPECT(2);
839 }
840
841 static void test_VarI1FromDec(void)
842 {
843 CONVVARS(DECIMAL);
844
845 CHECKPTR(VarI1FromDec);
846
847 CONVERT_BADDEC(VarI1FromDec);
848
849 CONVERT_DEC(VarI1FromDec,0,0x80,0,129); EXPECT_OVERFLOW;
850 CONVERT_DEC(VarI1FromDec,0,0x80,0,128); EXPECT(-128);
851 CONVERT_DEC(VarI1FromDec,0,0x80,0,1); EXPECT(-1);
852 CONVERT_DEC(VarI1FromDec,0,0,0,0); EXPECT(0);
853 CONVERT_DEC(VarI1FromDec,0,0,0,1); EXPECT(1);
854 CONVERT_DEC(VarI1FromDec,0,0,0,127); EXPECT(127);
855 CONVERT_DEC(VarI1FromDec,0,0,0,128); EXPECT_OVERFLOW;
856
857 CONVERT_DEC(VarI1FromDec,2,0x80,0,12800); EXPECT(-128);
858 CONVERT_DEC(VarI1FromDec,2,0,0,12700); EXPECT(127);
859 }
860
861 static void test_VarI1FromStr(void)
862 {
863 CONVVARS(LCID);
864 OLECHAR buff[128];
865
866 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
867
868 CHECKPTR(VarI1FromStr);
869
870 CONVERT_STR(VarI1FromStr,NULL, 0); EXPECT_MISMATCH;
871 CONVERT_STR(VarI1FromStr,"0", 0); EXPECT(0);
872 CONVERT_STR(VarI1FromStr,"-129", 0); EXPECT_OVERFLOW;
873 CONVERT_STR(VarI1FromStr,"-128", 0); EXPECT(-128);
874 CONVERT_STR(VarI1FromStr,"127", 0); EXPECT(127);
875 CONVERT_STR(VarI1FromStr,"128", 0); EXPECT_OVERFLOW;
876
877 CONVERT_STR(VarI1FromStr,"-1.5", LOCALE_NOUSEROVERRIDE); EXPECT(-2);
878 CONVERT_STR(VarI1FromStr,"-0.6", LOCALE_NOUSEROVERRIDE); EXPECT(-1);
879 CONVERT_STR(VarI1FromStr,"-0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
880 CONVERT_STR(VarI1FromStr,"-0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
881 CONVERT_STR(VarI1FromStr,"0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
882 CONVERT_STR(VarI1FromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
883 CONVERT_STR(VarI1FromStr,"0.6", LOCALE_NOUSEROVERRIDE); EXPECT(1);
884 CONVERT_STR(VarI1FromStr,"1.5", LOCALE_NOUSEROVERRIDE); EXPECT(2);
885 }
886
887 static void test_VarI1Copy(void)
888 {
889 COPYTEST(1, VT_I1, V_I1(&vSrc), V_I1(&vDst), V_I1REF(&vSrc), V_I1REF(&vDst), "%d");
890 }
891
892 static void test_VarI1ChangeTypeEx(void)
893 {
894 HRESULT hres;
895 signed char in;
896 VARIANTARG vSrc, vDst;
897
898 in = 1;
899
900 INITIAL_TYPETEST(VT_I1, V_I1, "%d");
901 COMMON_TYPETEST;
902 NEGATIVE_TYPETEST(VT_I1, V_I1, "%d", VT_UI1, V_UI1);
903 }
904
905 #undef CONV_TYPE
906 #define CONV_TYPE BYTE
907
908 static void test_VarUI1FromI1(void)
909 {
910 CONVVARS(signed char);
911 int i;
912
913 CHECKPTR(VarUI1FromI1);
914 OVERFLOWRANGE(VarUI1FromI1, -128, 0);
915 CONVERTRANGE(VarUI1FromI1, 0, 128);
916 }
917
918 static void test_VarUI1FromI2(void)
919 {
920 CONVVARS(SHORT);
921 int i;
922
923 CHECKPTR(VarUI1FromI2);
924 OVERFLOWRANGE(VarUI1FromI2, -32768, 0);
925 CONVERTRANGE(VarUI1FromI2, 0, 256);
926 OVERFLOWRANGE(VarUI1FromI2, 256, 32768);
927 }
928
929 static void test_VarUI1FromI4(void)
930 {
931 CONVVARS(LONG);
932 int i;
933
934 CHECKPTR(VarUI1FromI4);
935 CONVERT(VarUI1FromI4, -1); EXPECT_OVERFLOW;
936 CONVERTRANGE(VarUI1FromI4, 0, 256);
937 CONVERT(VarUI1FromI4, 256); EXPECT_OVERFLOW;
938 }
939
940 static void test_VarUI1FromI8(void)
941 {
942 CONVVARS(LONG64);
943 int i;
944
945 CHECKPTR(VarUI1FromI8);
946 CONVERT(VarUI1FromI8, -1); EXPECT_OVERFLOW;
947 CONVERTRANGE(VarUI1FromI8, 0, 256);
948 CONVERT(VarUI1FromI8, 256); EXPECT_OVERFLOW;
949 }
950
951 static void test_VarUI1FromUI2(void)
952 {
953 CONVVARS(USHORT);
954 int i;
955
956 CHECKPTR(VarUI1FromUI2);
957 CONVERTRANGE(VarUI1FromUI2, 0, 256);
958 OVERFLOWRANGE(VarUI1FromUI2, 256, 65536);
959 }
960
961 static void test_VarUI1FromUI4(void)
962 {
963 CONVVARS(ULONG);
964 int i;
965
966 CHECKPTR(VarUI1FromUI4);
967 CONVERTRANGE(VarUI1FromUI4, 0, 256);
968 CONVERT(VarUI1FromUI4, 256); EXPECT_OVERFLOW;
969 }
970
971 static void test_VarUI1FromUI8(void)
972 {
973 CONVVARS(ULONG64);
974 int i;
975
976 CHECKPTR(VarUI1FromUI8);
977 CONVERTRANGE(VarUI1FromUI8, 0, 256);
978 CONVERT(VarUI1FromUI8, 256); EXPECT_OVERFLOW;
979 }
980
981 static void test_VarUI1FromBool(void)
982 {
983 CONVVARS(VARIANT_BOOL);
984 int i;
985
986 CHECKPTR(VarUI1FromBool);
987 /* Note that conversions from bool overflow! */
988 CONVERT(VarUI1FromBool, -1); EXPECT(255);
989 CONVERTRANGE(VarUI1FromBool, 0, 256);
990 CONVERT(VarUI1FromBool, 256); EXPECT(0);
991 }
992
993 static void test_VarUI1FromR4(void)
994 {
995 CONVVARS(FLOAT);
996
997 CHECKPTR(VarUI1FromR4);
998 CONVERT(VarUI1FromR4, -1.0f); EXPECT_OVERFLOW;
999 CONVERT(VarUI1FromR4, -0.51f); EXPECT_OVERFLOW;
1000 CONVERT(VarUI1FromR4, -0.5f); EXPECT(0);
1001 CONVERT(VarUI1FromR4, 0.0f); EXPECT(0);
1002 CONVERT(VarUI1FromR4, 1.0f); EXPECT(1);
1003 CONVERT(VarUI1FromR4, 255.0f); EXPECT(255);
1004 CONVERT(VarUI1FromR4, 255.49f); EXPECT(255);
1005 CONVERT(VarUI1FromR4, 255.5f); EXPECT_OVERFLOW;
1006 CONVERT(VarUI1FromR4, 256.0f); EXPECT_OVERFLOW;
1007
1008 /* Rounding */
1009 CONVERT(VarUI1FromR4, -1.5f); EXPECT_OVERFLOW;
1010 CONVERT(VarUI1FromR4, -0.6f); EXPECT_OVERFLOW;
1011 CONVERT(VarUI1FromR4, -0.5f); EXPECT(0);
1012 CONVERT(VarUI1FromR4, -0.4f); EXPECT(0);
1013 CONVERT(VarUI1FromR4, 0.4f); EXPECT(0);
1014 CONVERT(VarUI1FromR4, 0.5f); EXPECT(0);
1015 CONVERT(VarUI1FromR4, 0.6f); EXPECT(1);
1016 CONVERT(VarUI1FromR4, 1.5f); EXPECT(2);
1017 }
1018
1019 static void test_VarUI1FromR8(void)
1020 {
1021 CONVVARS(DOUBLE);
1022
1023 CHECKPTR(VarUI1FromR8);
1024 CONVERT(VarUI1FromR8, -1.0); EXPECT_OVERFLOW;
1025 CONVERT(VarUI1FromR8, -0.51); EXPECT_OVERFLOW;
1026 CONVERT(VarUI1FromR8, -0.5); EXPECT(0);
1027 CONVERT(VarUI1FromR8, 0.0); EXPECT(0);
1028 CONVERT(VarUI1FromR8, 1.0); EXPECT(1);
1029 CONVERT(VarUI1FromR8, 255.0); EXPECT(255);
1030 CONVERT(VarUI1FromR8, 255.49); EXPECT(255);
1031 CONVERT(VarUI1FromR8, 255.5); EXPECT_OVERFLOW;
1032 CONVERT(VarUI1FromR8, 256.0); EXPECT_OVERFLOW;
1033
1034 /* Rounding */
1035 CONVERT(VarUI1FromR8, -1.5); EXPECT_OVERFLOW;
1036 CONVERT(VarUI1FromR8, -0.6); EXPECT_OVERFLOW;
1037 CONVERT(VarUI1FromR8, -0.5); EXPECT(0);
1038 CONVERT(VarUI1FromR8, -0.4); EXPECT(0);
1039 CONVERT(VarUI1FromR8, 0.4); EXPECT(0);
1040 CONVERT(VarUI1FromR8, 0.5); EXPECT(0);
1041 CONVERT(VarUI1FromR8, 0.6); EXPECT(1);
1042 CONVERT(VarUI1FromR8, 1.5); EXPECT(2);
1043 }
1044
1045 static void test_VarUI1FromDate(void)
1046 {
1047 CONVVARS(DATE);
1048
1049 CHECKPTR(VarUI1FromDate);
1050 CONVERT(VarUI1FromDate, -1.0); EXPECT_OVERFLOW;
1051 CONVERT(VarUI1FromDate, 0.0); EXPECT(0);
1052 CONVERT(VarUI1FromDate, 1.0); EXPECT(1);
1053 CONVERT(VarUI1FromDate, 255.0); EXPECT(255);
1054 CONVERT(VarUI1FromDate, 256.0); EXPECT_OVERFLOW;
1055
1056 /* Rounding */
1057 CONVERT(VarUI1FromDate, -1.5); EXPECT_OVERFLOW;
1058 CONVERT(VarUI1FromDate, -0.6); EXPECT_OVERFLOW;
1059 CONVERT(VarUI1FromDate, -0.5); EXPECT(0);
1060 CONVERT(VarUI1FromDate, -0.4); EXPECT(0);
1061 CONVERT(VarUI1FromDate, 0.4); EXPECT(0);
1062 CONVERT(VarUI1FromDate, 0.5); EXPECT(0);
1063 CONVERT(VarUI1FromDate, 0.6); EXPECT(1);
1064 CONVERT(VarUI1FromDate, 1.5); EXPECT(2);
1065 }
1066
1067 static void test_VarUI1FromCy(void)
1068 {
1069 CONVVARS(CY);
1070
1071 CHECKPTR(VarUI1FromCy);
1072 CONVERT_CY(VarUI1FromCy,-1); EXPECT_OVERFLOW;
1073 CONVERT_CY(VarUI1FromCy,0); EXPECT(0);
1074 CONVERT_CY(VarUI1FromCy,1); EXPECT(1);
1075 CONVERT_CY(VarUI1FromCy,255); EXPECT(255);
1076 CONVERT_CY(VarUI1FromCy,256); EXPECT_OVERFLOW;
1077
1078 /* Rounding */
1079 CONVERT_CY(VarUI1FromCy,-1.5); EXPECT_OVERFLOW;
1080 CONVERT_CY(VarUI1FromCy,-0.6); EXPECT_OVERFLOW;
1081 CONVERT_CY(VarUI1FromCy,-0.5); EXPECT(0);
1082 CONVERT_CY(VarUI1FromCy,-0.4); EXPECT(0);
1083 CONVERT_CY(VarUI1FromCy,0.4); EXPECT(0);
1084 CONVERT_CY(VarUI1FromCy,0.5); EXPECT(0);
1085 CONVERT_CY(VarUI1FromCy,0.6); EXPECT(1);
1086 CONVERT_CY(VarUI1FromCy,1.5); EXPECT(2);
1087 }
1088
1089 static void test_VarUI1FromDec(void)
1090 {
1091 CONVVARS(DECIMAL);
1092
1093 CHECKPTR(VarUI1FromDec);
1094
1095 CONVERT_BADDEC(VarUI1FromDec);
1096
1097 CONVERT_DEC(VarUI1FromDec,0,0x80,0,1); EXPECT_OVERFLOW;
1098 CONVERT_DEC(VarUI1FromDec,0,0,0,0); EXPECT(0);
1099 CONVERT_DEC(VarUI1FromDec,0,0,0,1); EXPECT(1);
1100 CONVERT_DEC(VarUI1FromDec,0,0,0,255); EXPECT(255);
1101 CONVERT_DEC(VarUI1FromDec,0,0,0,256); EXPECT_OVERFLOW;
1102
1103 CONVERT_DEC(VarUI1FromDec,2,0x80,0,100); EXPECT_OVERFLOW;
1104 CONVERT_DEC(VarUI1FromDec,2,0,0,25500); EXPECT(255);
1105 }
1106
1107 static void test_VarUI1FromStr(void)
1108 {
1109 CONVVARS(LCID);
1110 OLECHAR buff[128];
1111
1112 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1113
1114 CHECKPTR(VarUI1FromStr);
1115
1116 CONVERT_STR(VarUI1FromStr,NULL, 0); EXPECT_MISMATCH;
1117 CONVERT_STR(VarUI1FromStr,"0", 0); EXPECT(0);
1118 CONVERT_STR(VarUI1FromStr,"-1", 0); EXPECT_OVERFLOW;
1119 CONVERT_STR(VarUI1FromStr,"255", 0); EXPECT(255);
1120 CONVERT_STR(VarUI1FromStr,"256", 0); EXPECT_OVERFLOW;
1121
1122 /* Rounding */
1123 CONVERT_STR(VarUI1FromStr,"-1.5", LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
1124 CONVERT_STR(VarUI1FromStr,"-0.6", LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
1125 CONVERT_STR(VarUI1FromStr,"-0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1126 CONVERT_STR(VarUI1FromStr,"-0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1127 CONVERT_STR(VarUI1FromStr,"0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1128 CONVERT_STR(VarUI1FromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1129 CONVERT_STR(VarUI1FromStr,"0.6", LOCALE_NOUSEROVERRIDE); EXPECT(1);
1130 CONVERT_STR(VarUI1FromStr,"1.5", LOCALE_NOUSEROVERRIDE); EXPECT(2);
1131 }
1132
1133 static void test_VarUI1FromDisp(void)
1134 {
1135 DummyDispatch dispatch;
1136 CONVVARS(LCID);
1137 VARIANTARG vSrc, vDst;
1138
1139 CHECKPTR(VarUI1FromDisp);
1140
1141 /* FIXME
1142 * Conversions from IDispatch should get the default 'value' property
1143 * from the IDispatch pointer and return it. The following tests this.
1144 * However, I can't get these tests to return a valid value under native
1145 * oleaut32, regardless of the value returned in response to the Invoke()
1146 * call (early versions of oleaut32 call AddRef/Release, but not Invoke.
1147 * I'm obviously missing something, as these conversions work fine
1148 * when called through VBA on an object to get its default value property.
1149 *
1150 * Should this test be corrected so that it works under native it should be
1151 * generalised and the remaining types checked as well.
1152 */
1153 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1154
1155 VariantInit(&vSrc);
1156 VariantInit(&vDst);
1157
1158 init_test_dispatch(1, VT_UI1, &dispatch);
1159 V_VT(&vSrc) = VT_DISPATCH;
1160 V_DISPATCH(&vSrc) = &dispatch.IDispatch_iface;
1161
1162 SET_EXPECT(dispatch_invoke);
1163 out = 10;
1164 hres = pVarUI1FromDisp(&dispatch.IDispatch_iface, in, &out);
1165 ok(broken(hres == DISP_E_BADVARTYPE) || hres == S_OK, "got 0x%08x\n", hres);
1166 ok(broken(out == 10) || out == 1, "got %d\n", out);
1167 CHECK_CALLED(dispatch_invoke);
1168
1169 SET_EXPECT(dispatch_invoke);
1170 V_VT(&vDst) = VT_EMPTY;
1171 V_UI1(&vDst) = 0;
1172 hres = VariantChangeTypeEx(&vDst, &vSrc, in, 0, VT_UI1);
1173 ok(hres == S_OK, "got 0x%08x\n", hres);
1174 ok(V_VT(&vDst) == VT_UI1, "got %d\n", V_VT(&vDst));
1175 ok(V_UI1(&vDst) == 1, "got %d\n", V_UI1(&vDst));
1176 CHECK_CALLED(dispatch_invoke);
1177
1178 dispatch.bFailInvoke = TRUE;
1179
1180 SET_EXPECT(dispatch_invoke);
1181 out = 10;
1182 hres = pVarUI1FromDisp(&dispatch.IDispatch_iface, in, &out);
1183 ok(hres == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hres);
1184 ok(out == 10, "got %d\n", out);
1185 CHECK_CALLED(dispatch_invoke);
1186
1187 SET_EXPECT(dispatch_invoke);
1188 V_VT(&vDst) = VT_EMPTY;
1189 hres = VariantChangeTypeEx(&vDst, &vSrc, in, 0, VT_UI1);
1190 ok(hres == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hres);
1191 ok(V_VT(&vDst) == VT_EMPTY, "got %d\n", V_VT(&vDst));
1192 CHECK_CALLED(dispatch_invoke);
1193 }
1194
1195 static void test_VarUI1Copy(void)
1196 {
1197 COPYTEST(1, VT_UI1, V_UI1(&vSrc), V_UI1(&vDst), V_UI1REF(&vSrc), V_UI1REF(&vDst), "%d");
1198 }
1199
1200 static void test_VarUI1ChangeTypeEx(void)
1201 {
1202 HRESULT hres;
1203 BYTE in;
1204 VARIANTARG vSrc, vDst;
1205
1206 in = 1;
1207
1208 INITIAL_TYPETEST(VT_UI1, V_UI1, "%d");
1209 COMMON_TYPETEST;
1210 NEGATIVE_TYPETEST(VT_UI1, V_UI1, "%d", VT_I1, V_I1);
1211 }
1212
1213 /*
1214 * VT_I2/VT_UI2
1215 */
1216
1217 #undef CONV_TYPE
1218 #define CONV_TYPE SHORT
1219
1220 static void test_VarI2FromI1(void)
1221 {
1222 CONVVARS(signed char);
1223 int i;
1224
1225 CHECKPTR(VarI2FromI1);
1226 CONVERTRANGE(VarI2FromI1, -128, 128);
1227 }
1228
1229 static void test_VarI2FromI4(void)
1230 {
1231 CONVVARS(LONG);
1232 int i;
1233
1234 CHECKPTR(VarI2FromI4);
1235 CONVERT(VarI2FromI4, -32769); EXPECT_OVERFLOW;
1236 CONVERTRANGE(VarI2FromI4, -32768, 32768);
1237 CONVERT(VarI2FromI4, 32768); EXPECT_OVERFLOW;
1238 }
1239
1240 static void test_VarI2FromI8(void)
1241 {
1242 CONVVARS(LONG64);
1243
1244 CHECKPTR(VarI2FromI8);
1245 CONVERT(VarI2FromI8, -32769); EXPECT_OVERFLOW;
1246 CONVERT(VarI2FromI8, -32768); EXPECT(-32768);
1247 CONVERT(VarI2FromI8, 32767); EXPECT(32767);
1248 CONVERT(VarI2FromI8, 32768); EXPECT_OVERFLOW;
1249 }
1250
1251 static void test_VarI2FromUI1(void)
1252 {
1253 CONVVARS(BYTE);
1254 int i;
1255
1256 CHECKPTR(VarI2FromUI1);
1257 CONVERTRANGE(VarI2FromUI1, 0, 256);
1258 }
1259
1260 static void test_VarI2FromUI2(void)
1261 {
1262 CONVVARS(USHORT);
1263 int i;
1264
1265 CHECKPTR(VarI2FromUI2);
1266 CONVERTRANGE(VarI2FromUI2, 0, 32768);
1267 CONVERT(VarI2FromUI2, 32768); EXPECT_OVERFLOW;
1268 }
1269
1270 static void test_VarI2FromUI4(void)
1271 {
1272 CONVVARS(ULONG);
1273 int i;
1274
1275 CHECKPTR(VarI2FromUI4);
1276 CONVERTRANGE(VarI2FromUI4, 0, 32768);
1277 CONVERT(VarI2FromUI4, 32768); EXPECT_OVERFLOW;
1278 }
1279
1280 static void test_VarI2FromUI8(void)
1281 {
1282 CONVVARS(ULONG64);
1283 int i;
1284
1285 CHECKPTR(VarI2FromUI8);
1286 CONVERTRANGE(VarI2FromUI8, 0, 32768);
1287 CONVERT(VarI2FromUI8, 32768); EXPECT_OVERFLOW;
1288 }
1289
1290 static void test_VarI2FromBool(void)
1291 {
1292 CONVVARS(VARIANT_BOOL);
1293 int i;
1294
1295 CHECKPTR(VarI2FromBool);
1296 CONVERTRANGE(VarI2FromBool, -32768, 32768);
1297 }
1298
1299 static void test_VarI2FromR4(void)
1300 {
1301 CONVVARS(FLOAT);
1302
1303 CHECKPTR(VarI2FromR4);
1304 CONVERT(VarI2FromR4, -32769.0f); EXPECT_OVERFLOW;
1305 CONVERT(VarI2FromR4, -32768.51f); EXPECT_OVERFLOW;
1306 CONVERT(VarI2FromR4, -32768.5f); EXPECT(-32768);
1307 CONVERT(VarI2FromR4, -32768.0f); EXPECT(-32768);
1308 CONVERT(VarI2FromR4, -1.0f); EXPECT(-1);
1309 CONVERT(VarI2FromR4, 0.0f); EXPECT(0);
1310 CONVERT(VarI2FromR4, 1.0f); EXPECT(1);
1311 CONVERT(VarI2FromR4, 32767.0f); EXPECT(32767);
1312 CONVERT(VarI2FromR4, 32767.49f); EXPECT(32767);
1313 CONVERT(VarI2FromR4, 32767.5f); EXPECT_OVERFLOW;
1314 CONVERT(VarI2FromR4, 32768.0f); EXPECT_OVERFLOW;
1315
1316 /* Rounding */
1317 CONVERT(VarI2FromR4, -1.5f); EXPECT(-2);
1318 CONVERT(VarI2FromR4, -0.6f); EXPECT(-1);
1319 CONVERT(VarI2FromR4, -0.5f); EXPECT(0);
1320 CONVERT(VarI2FromR4, -0.4f); EXPECT(0);
1321 CONVERT(VarI2FromR4, 0.4f); EXPECT(0);
1322 CONVERT(VarI2FromR4, 0.5f); EXPECT(0);
1323 CONVERT(VarI2FromR4, 0.6f); EXPECT(1);
1324 CONVERT(VarI2FromR4, 1.5f); EXPECT(2);
1325 }
1326
1327 static void test_VarI2FromR8(void)
1328 {
1329 CONVVARS(DOUBLE);
1330
1331 CHECKPTR(VarI2FromR8);
1332 CONVERT(VarI2FromR8, -32769.0); EXPECT_OVERFLOW;
1333 CONVERT(VarI2FromR8, -32768.51); EXPECT_OVERFLOW;
1334 CONVERT(VarI2FromR8, -32768.5); EXPECT(-32768);
1335 CONVERT(VarI2FromR8, -32768.0); EXPECT(-32768);
1336 CONVERT(VarI2FromR8, -1.0); EXPECT(-1);
1337 CONVERT(VarI2FromR8, 0.0); EXPECT(0);
1338 CONVERT(VarI2FromR8, 1.0); EXPECT(1);
1339 CONVERT(VarI2FromR8, 32767.0); EXPECT(32767);
1340 CONVERT(VarI2FromR8, 32767.49); EXPECT(32767);
1341 CONVERT(VarI2FromR8, 32767.5); EXPECT_OVERFLOW;
1342 CONVERT(VarI2FromR8, 32768.0); EXPECT_OVERFLOW;
1343
1344 /* Rounding */
1345 CONVERT(VarI2FromR8, -1.5); EXPECT(-2);
1346 CONVERT(VarI2FromR8, -0.6); EXPECT(-1);
1347 CONVERT(VarI2FromR8, -0.5); EXPECT(0);
1348 CONVERT(VarI2FromR8, -0.4); EXPECT(0);
1349 CONVERT(VarI2FromR8, 0.4); EXPECT(0);
1350 CONVERT(VarI2FromR8, 0.5); EXPECT(0);
1351 CONVERT(VarI2FromR8, 0.6); EXPECT(1);
1352 CONVERT(VarI2FromR8, 1.5); EXPECT(2);
1353 }
1354
1355 static void test_VarI2FromDate(void)
1356 {
1357 CONVVARS(DATE);
1358
1359 CHECKPTR(VarI2FromDate);
1360 CONVERT(VarI2FromDate, -32769.0); EXPECT_OVERFLOW;
1361 CONVERT(VarI2FromDate, -32768.0); EXPECT(-32768);
1362 CONVERT(VarI2FromDate, -1.0); EXPECT(-1);
1363 CONVERT(VarI2FromDate, 0.0); EXPECT(0);
1364 CONVERT(VarI2FromDate, 1.0); EXPECT(1);
1365 CONVERT(VarI2FromDate, 32767.0); EXPECT(32767);
1366 CONVERT(VarI2FromDate, 32768.0); EXPECT_OVERFLOW;
1367
1368 /* Rounding */
1369 CONVERT(VarI2FromDate, -1.5); EXPECT(-2);
1370 CONVERT(VarI2FromDate, -0.6); EXPECT(-1);
1371 CONVERT(VarI2FromDate, -0.5); EXPECT(0);
1372 CONVERT(VarI2FromDate, -0.4); EXPECT(0);
1373 CONVERT(VarI2FromDate, 0.4); EXPECT(0);
1374 CONVERT(VarI2FromDate, 0.5); EXPECT(0);
1375 CONVERT(VarI2FromDate, 0.6); EXPECT(1);
1376 CONVERT(VarI2FromDate, 1.5); EXPECT(2);
1377 }
1378
1379 static void test_VarI2FromCy(void)
1380 {
1381 CONVVARS(CY);
1382
1383 CHECKPTR(VarI2FromCy);
1384 CONVERT_CY(VarI2FromCy,-32769); EXPECT_OVERFLOW;
1385 CONVERT_CY(VarI2FromCy,-32768); EXPECT(32768);
1386 CONVERT_CY(VarI2FromCy,-1); EXPECT(-1);
1387 CONVERT_CY(VarI2FromCy,0); EXPECT(0);
1388 CONVERT_CY(VarI2FromCy,1); EXPECT(1);
1389 CONVERT_CY(VarI2FromCy,32767); EXPECT(32767);
1390 CONVERT_CY(VarI2FromCy,32768); EXPECT_OVERFLOW;
1391
1392 /* Rounding */
1393 CONVERT_CY(VarI2FromCy,-1.5); EXPECT(-2);
1394 CONVERT_CY(VarI2FromCy,-0.6); EXPECT(-1);
1395 CONVERT_CY(VarI2FromCy,-0.5); EXPECT(0);
1396 CONVERT_CY(VarI2FromCy,-0.4); EXPECT(0);
1397 CONVERT_CY(VarI2FromCy,0.4); EXPECT(0);
1398 CONVERT_CY(VarI2FromCy,0.5); EXPECT(0);
1399 CONVERT_CY(VarI2FromCy,0.6); EXPECT(1);
1400 CONVERT_CY(VarI2FromCy,1.5); EXPECT(2);
1401 }
1402
1403 static void test_VarI2FromDec(void)
1404 {
1405 CONVVARS(DECIMAL);
1406
1407 CHECKPTR(VarI2FromDec);
1408
1409 CONVERT_BADDEC(VarI2FromDec);
1410
1411 CONVERT_DEC(VarI2FromDec,0,0x80,0,32769); EXPECT_OVERFLOW;
1412 CONVERT_DEC(VarI2FromDec,0,0x80,0,32768); EXPECT(-32768);
1413 CONVERT_DEC(VarI2FromDec,0,0x80,0,1); EXPECT(-1);
1414 CONVERT_DEC(VarI2FromDec,0,0,0,0); EXPECT(0);
1415 CONVERT_DEC(VarI2FromDec,0,0,0,1); EXPECT(1);
1416 CONVERT_DEC(VarI2FromDec,0,0,0,32767); EXPECT(32767);
1417 CONVERT_DEC(VarI2FromDec,0,0,0,32768); EXPECT_OVERFLOW;
1418
1419 CONVERT_DEC(VarI2FromDec,2,0x80,0,3276800); EXPECT(-32768);
1420 CONVERT_DEC(VarI2FromDec,2,0,0,3276700); EXPECT(32767);
1421 CONVERT_DEC(VarI2FromDec,2,0,0,3276800); EXPECT_OVERFLOW;
1422 }
1423
1424 static void test_VarI2FromStr(void)
1425 {
1426 CONVVARS(LCID);
1427 OLECHAR buff[128];
1428
1429 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1430
1431 CHECKPTR(VarI2FromStr);
1432
1433 CONVERT_STR(VarI2FromStr,NULL, 0); EXPECT_MISMATCH;
1434 CONVERT_STR(VarI2FromStr,"0", 0); EXPECT(0);
1435 CONVERT_STR(VarI2FromStr,"-32769", 0); EXPECT_OVERFLOW;
1436 CONVERT_STR(VarI2FromStr,"-32768", 0); EXPECT(-32768);
1437 CONVERT_STR(VarI2FromStr,"32767", 0); EXPECT(32767);
1438 CONVERT_STR(VarI2FromStr,"32768", 0); EXPECT_OVERFLOW;
1439
1440 /* Rounding */
1441 CONVERT_STR(VarI2FromStr,"-1.5", LOCALE_NOUSEROVERRIDE); EXPECT(-2);
1442 CONVERT_STR(VarI2FromStr,"-0.6", LOCALE_NOUSEROVERRIDE); EXPECT(-1);
1443 CONVERT_STR(VarI2FromStr,"-0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1444 CONVERT_STR(VarI2FromStr,"-0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1445 CONVERT_STR(VarI2FromStr,"0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1446 CONVERT_STR(VarI2FromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1447 CONVERT_STR(VarI2FromStr,"0.6", LOCALE_NOUSEROVERRIDE); EXPECT(1);
1448 CONVERT_STR(VarI2FromStr,"1.5", LOCALE_NOUSEROVERRIDE); EXPECT(2);
1449 }
1450
1451 static void test_VarI2Copy(void)
1452 {
1453 COPYTEST(1, VT_I2, V_I2(&vSrc), V_I2(&vDst), V_I2REF(&vSrc), V_I2REF(&vDst), "%d");
1454 }
1455
1456 static void test_VarI2ChangeTypeEx(void)
1457 {
1458 HRESULT hres;
1459 SHORT in;
1460 VARIANTARG vSrc, vDst;
1461
1462 in = 1;
1463
1464 INITIAL_TYPETEST(VT_I2, V_I2, "%d");
1465 COMMON_TYPETEST;
1466 NEGATIVE_TYPETEST(VT_I2, V_I2, "%d", VT_UI2, V_UI2);
1467 }
1468
1469 #undef CONV_TYPE
1470 #define CONV_TYPE USHORT
1471
1472 static void test_VarUI2FromI1(void)
1473 {
1474 CONVVARS(signed char);
1475 int i;
1476
1477 CHECKPTR(VarUI2FromI1);
1478 OVERFLOWRANGE(VarUI2FromI1, -128, 0);
1479 CONVERTRANGE(VarUI2FromI1, 0, 128);
1480 }
1481
1482 static void test_VarUI2FromI2(void)
1483 {
1484 CONVVARS(SHORT);
1485 int i;
1486
1487 CHECKPTR(VarUI2FromI2);
1488 OVERFLOWRANGE(VarUI2FromI2, -32768, 0);
1489 CONVERTRANGE(VarUI2FromI2, 0, 32768);
1490 }
1491
1492 static void test_VarUI2FromI4(void)
1493 {
1494 CONVVARS(LONG);
1495 int i;
1496
1497 CHECKPTR(VarUI2FromI4);
1498 OVERFLOWRANGE(VarUI2FromI4, -32768, 0);
1499 CONVERT(VarUI2FromI4, 0); EXPECT(0);
1500 CONVERT(VarUI2FromI4, 65535); EXPECT(65535);
1501 CONVERT(VarUI2FromI4, 65536); EXPECT_OVERFLOW;
1502 }
1503
1504 static void test_VarUI2FromI8(void)
1505 {
1506 CONVVARS(LONG64);
1507 int i;
1508
1509 CHECKPTR(VarUI2FromI8);
1510 OVERFLOWRANGE(VarUI2FromI8, -32768, 0);
1511 CONVERT(VarUI2FromI8, 0); EXPECT(0);
1512 CONVERT(VarUI2FromI8, 65535); EXPECT(65535);
1513 CONVERT(VarUI2FromI8, 65536); EXPECT_OVERFLOW;
1514 }
1515
1516 static void test_VarUI2FromUI1(void)
1517 {
1518 CONVVARS(BYTE);
1519 int i;
1520
1521 CHECKPTR(VarUI2FromUI1);
1522 CONVERTRANGE(VarUI2FromUI1, 0, 256);
1523 }
1524
1525 static void test_VarUI2FromUI4(void)
1526 {
1527 CONVVARS(ULONG);
1528
1529 CHECKPTR(VarUI2FromUI4);
1530 CONVERT(VarUI2FromUI4, 0); EXPECT(0);
1531 CONVERT(VarUI2FromUI4, 65535); EXPECT(65535);
1532 CONVERT(VarUI2FromUI4, 65536); EXPECT_OVERFLOW;
1533 }
1534
1535 static void test_VarUI2FromUI8(void)
1536 {
1537 CONVVARS(ULONG64);
1538
1539 CHECKPTR(VarUI2FromUI8);
1540 CONVERT(VarUI2FromUI8, 0); EXPECT(0);
1541 CONVERT(VarUI2FromUI8, 65535); EXPECT(65535);
1542 CONVERT(VarUI2FromUI8, 65536); EXPECT_OVERFLOW;
1543 }
1544
1545 static void test_VarUI2FromBool(void)
1546 {
1547 CONVVARS(VARIANT_BOOL);
1548 int i;
1549
1550 CHECKPTR(VarUI2FromBool);
1551 CONVERT(VarUI2FromBool, -1); EXPECT(65535); /* Wraps! */
1552 CONVERTRANGE(VarUI2FromBool, 0, 32768);
1553 }
1554
1555 static void test_VarUI2FromR4(void)
1556 {
1557 CONVVARS(FLOAT);
1558
1559 CHECKPTR(VarUI2FromR4);
1560 CONVERT(VarUI2FromR4, -1.0f); EXPECT_OVERFLOW;
1561 CONVERT(VarUI2FromR4, -0.51f); EXPECT_OVERFLOW;
1562 CONVERT(VarUI2FromR4, -0.5f); EXPECT(0);
1563 CONVERT(VarUI2FromR4, 0.0f); EXPECT(0);
1564 CONVERT(VarUI2FromR4, 1.0f); EXPECT(1);
1565 CONVERT(VarUI2FromR4, 65535.0f); EXPECT(65535);
1566 CONVERT(VarUI2FromR4, 65535.49f); EXPECT(65535);
1567 CONVERT(VarUI2FromR4, 65535.5f); EXPECT_OVERFLOW;
1568 CONVERT(VarUI2FromR4, 65536.0f); EXPECT_OVERFLOW;
1569
1570 /* Rounding */
1571 CONVERT(VarUI2FromR4, -1.5f); EXPECT_OVERFLOW;
1572 CONVERT(VarUI2FromR4, -0.6f); EXPECT_OVERFLOW;
1573 CONVERT(VarUI2FromR4, -0.5f); EXPECT(0);
1574 CONVERT(VarUI2FromR4, -0.4f); EXPECT(0);
1575 CONVERT(VarUI2FromR4, 0.4f); EXPECT(0);
1576 CONVERT(VarUI2FromR4, 0.5f); EXPECT(0);
1577 CONVERT(VarUI2FromR4, 0.6f); EXPECT(1);
1578 CONVERT(VarUI2FromR4, 1.5f); EXPECT(2);
1579 }
1580
1581 static void test_VarUI2FromR8(void)
1582 {
1583 CONVVARS(DOUBLE);
1584
1585 CHECKPTR(VarUI2FromR8);
1586 CONVERT(VarUI2FromR8, -1.0); EXPECT_OVERFLOW;
1587 CONVERT(VarUI2FromR8, -0.51); EXPECT_OVERFLOW;
1588 CONVERT(VarUI2FromR8, -0.5); EXPECT(0);
1589 CONVERT(VarUI2FromR8, 0.0); EXPECT(0);
1590 CONVERT(VarUI2FromR8, 1.0); EXPECT(1);
1591 CONVERT(VarUI2FromR8, 65535.0); EXPECT(65535);
1592 CONVERT(VarUI2FromR8, 65535.49); EXPECT(65535);
1593 CONVERT(VarUI2FromR8, 65535.5); EXPECT_OVERFLOW;
1594 CONVERT(VarUI2FromR8, 65536.0); EXPECT_OVERFLOW;
1595
1596 /* Rounding */
1597 CONVERT(VarUI2FromR8, -1.5); EXPECT_OVERFLOW;
1598 CONVERT(VarUI2FromR8, -0.6); EXPECT_OVERFLOW;
1599 CONVERT(VarUI2FromR8, -0.5); EXPECT(0);
1600 CONVERT(VarUI2FromR8, -0.4); EXPECT(0);
1601 CONVERT(VarUI2FromR8, 0.4); EXPECT(0);
1602 CONVERT(VarUI2FromR8, 0.5); EXPECT(0);
1603 CONVERT(VarUI2FromR8, 0.6); EXPECT(1);
1604 CONVERT(VarUI2FromR8, 1.5); EXPECT(2);
1605 }
1606
1607 static void test_VarUI2FromDate(void)
1608 {
1609 CONVVARS(DATE);
1610
1611 CHECKPTR(VarUI2FromDate);
1612 CONVERT(VarUI2FromDate, -1.0); EXPECT_OVERFLOW;
1613 CONVERT(VarUI2FromDate, 0.0); EXPECT(0);
1614 CONVERT(VarUI2FromDate, 1.0); EXPECT(1);
1615 CONVERT(VarUI2FromDate, 65535.0); EXPECT(65535);
1616 CONVERT(VarUI2FromDate, 65536.0); EXPECT_OVERFLOW;
1617
1618 /* Rounding */
1619 CONVERT(VarUI2FromDate, -1.5); EXPECT_OVERFLOW;
1620 CONVERT(VarUI2FromDate, -0.6); EXPECT_OVERFLOW;
1621 CONVERT(VarUI2FromDate, -0.5); EXPECT(0);
1622 CONVERT(VarUI2FromDate, -0.4); EXPECT(0);
1623 CONVERT(VarUI2FromDate, 0.4); EXPECT(0);
1624 CONVERT(VarUI2FromDate, 0.5); EXPECT(0);
1625 CONVERT(VarUI2FromDate, 0.6); EXPECT(1);
1626 CONVERT(VarUI2FromDate, 1.5); EXPECT(2);
1627 }
1628
1629 static void test_VarUI2FromCy(void)
1630 {
1631 CONVVARS(CY);
1632
1633 CHECKPTR(VarUI2FromCy);
1634 CONVERT_CY(VarUI2FromCy,-1); EXPECT_OVERFLOW;
1635 CONVERT_CY(VarUI2FromCy,0); EXPECT(0);
1636 CONVERT_CY(VarUI2FromCy,1); EXPECT(1);
1637 CONVERT_CY(VarUI2FromCy,65535); EXPECT(65535);
1638 CONVERT_CY(VarUI2FromCy,65536); EXPECT_OVERFLOW;
1639
1640 /* Rounding */
1641 CONVERT_CY(VarUI2FromCy,-1.5); EXPECT_OVERFLOW;
1642 CONVERT_CY(VarUI2FromCy,-0.6); EXPECT_OVERFLOW;
1643 CONVERT_CY(VarUI2FromCy,-0.5); EXPECT(0);
1644 CONVERT_CY(VarUI2FromCy,-0.4); EXPECT(0);
1645 CONVERT_CY(VarUI2FromCy,0.4); EXPECT(0);
1646 CONVERT_CY(VarUI2FromCy,0.5); EXPECT(0);
1647 CONVERT_CY(VarUI2FromCy,0.6); EXPECT(1);
1648 CONVERT_CY(VarUI2FromCy,1.5); EXPECT(2);
1649 }
1650
1651 static void test_VarUI2FromDec(void)
1652 {
1653 CONVVARS(DECIMAL);
1654
1655 CHECKPTR(VarUI2FromDec);
1656
1657 CONVERT_BADDEC(VarUI2FromDec);
1658
1659 CONVERT_DEC(VarUI2FromDec,0,0x80,0,1); EXPECT_OVERFLOW;
1660 CONVERT_DEC(VarUI2FromDec,0,0,0,0); EXPECT(0);
1661 CONVERT_DEC(VarUI2FromDec,0,0,0,1); EXPECT(1);
1662 CONVERT_DEC(VarUI2FromDec,0,0,0,65535); EXPECT(65535);
1663 CONVERT_DEC(VarUI2FromDec,0,0,0,65536); EXPECT_OVERFLOW;
1664
1665 CONVERT_DEC(VarUI2FromDec,2,0x80,0,100); EXPECT_OVERFLOW;
1666 CONVERT_DEC(VarUI2FromDec,2,0,0,6553500); EXPECT(65535);
1667 CONVERT_DEC(VarUI2FromDec,2,0,0,6553600); EXPECT_OVERFLOW;
1668 }
1669
1670 static void test_VarUI2FromStr(void)
1671 {
1672 CONVVARS(LCID);
1673 OLECHAR buff[128];
1674
1675 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1676
1677 CHECKPTR(VarUI2FromStr);
1678
1679 CONVERT_STR(VarUI2FromStr,NULL, 0); EXPECT_MISMATCH;
1680 CONVERT_STR(VarUI2FromStr,"0", 0); EXPECT(0);
1681 CONVERT_STR(VarUI2FromStr,"-1", 0); EXPECT_OVERFLOW;
1682 CONVERT_STR(VarUI2FromStr,"65535", 0); EXPECT(65535);
1683 CONVERT_STR(VarUI2FromStr,"65536", 0); EXPECT_OVERFLOW;
1684
1685 /* Rounding */
1686 CONVERT_STR(VarUI2FromStr,"-1.5", LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
1687 CONVERT_STR(VarUI2FromStr,"-0.6", LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
1688 CONVERT_STR(VarUI2FromStr,"-0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1689 CONVERT_STR(VarUI2FromStr,"-0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1690 CONVERT_STR(VarUI2FromStr,"0.4", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1691 CONVERT_STR(VarUI2FromStr,"0.5", LOCALE_NOUSEROVERRIDE); EXPECT(0);
1692 CONVERT_STR(VarUI2FromStr,"0.6", LOCALE_NOUSEROVERRIDE); EXPECT(1);
1693 CONVERT_STR(VarUI2FromStr,"1.5", LOCALE_NOUSEROVERRIDE); EXPECT(2);
1694 }
1695
1696 static void test_VarUI2Copy(void)
1697 {
1698 COPYTEST(1, VT_UI2, V_UI2(&vSrc), V_UI2(&vDst), V_UI2REF(&vSrc), V_UI2REF(&vDst), "%d");
1699 }
1700
1701 static void test_VarUI2ChangeTypeEx(void)
1702 {
1703 HRESULT hres;
1704 USHORT in;
1705 VARIANTARG vSrc, vDst;
1706
1707 in = 1;
1708
1709 INITIAL_TYPETEST(VT_UI2, V_UI2, "%d");
1710 COMMON_TYPETEST;
1711 NEGATIVE_TYPETEST(VT_UI2, V_UI2, "%d", VT_I2, V_I2);
1712 }
1713
1714 /*
1715 * VT_I4/VT_UI4
1716 */
1717
1718 #undef CONV_TYPE
1719 #define CONV_TYPE LONG
1720
1721 static void test_VarI4FromI1(void)
1722 {
1723 CONVVARS(signed char);
1724 int i;
1725
1726 CHECKPTR(VarI4FromI1);
1727 CONVERTRANGE(VarI4FromI1, -128, 128);
1728 }
1729
1730 static void test_VarI4FromI2(void)
1731 {
1732 CONVVARS(SHORT);
1733 int i;
1734
1735 CHECKPTR(VarI4FromI2);
1736 CONVERTRANGE(VarI4FromI2, -32768, 32768);
1737 }
1738
1739 static void test_VarI4FromI8(void)
1740 {
1741 CONVVARS(LONG64);
1742
1743 CHECKPTR(VarI4FromI8);
1744 CHECKPTR(VarI4FromDec);
1745
1746 CONVERT(VarI4FromI8, -1); EXPECT(-1);
1747 CONVERT(VarI4FromI8, 0); EXPECT(0);
1748 CONVERT(VarI4FromI8, 1); EXPECT(1);
1749
1750 CONVERT_I8(VarI4FromI8, -1, 2147483647ul); EXPECT_OVERFLOW;
1751 CONVERT_I8(VarI4FromI8, -1, 2147483648ul); EXPECT(-2147483647 - 1);
1752 CONVERT_I8(VarI4FromI8, 0, 2147483647ul); EXPECT(2147483647);
1753 CONVERT_I8(VarI4FromI8, 0, 2147483648ul); EXPECT_OVERFLOW;
1754 }
1755
1756 static void test_VarI4FromUI1(void)
1757 {
1758 CONVVARS(BYTE);
1759 int i;
1760
1761 CHECKPTR(VarI4FromUI1);
1762 CONVERTRANGE(VarI4FromUI1, 0, 256);
1763 }
1764
1765 static void test_VarI4FromUI2(void)
1766 {
1767 CONVVARS(USHORT);
1768 int i;
1769
1770 CHECKPTR(VarI4FromUI2);
1771 CONVERTRANGE(VarI4FromUI2, 0, 65536);
1772 }
1773
1774 static void test_VarI4FromUI4(void)
1775 {
1776 CONVVARS(ULONG);
1777
1778 CHECKPTR(VarI4FromUI4);
1779 CONVERT(VarI4FromUI4, 0); EXPECT(0);
1780 CONVERT(VarI4FromUI4, 1); EXPECT(1);
1781 CONVERT(VarI4FromUI4, 2147483647); EXPECT(2147483647);
1782 CONVERT(VarI4FromUI4, 2147483648ul); EXPECT_OVERFLOW;
1783 }
1784
1785 static void test_VarI4FromUI8(void)
1786 {
1787 CONVVARS(ULONG64);
1788
1789 CHECKPTR(VarI4FromUI8);
1790 CONVERT(VarI4FromUI8, 0); EXPECT(0);
1791 CONVERT(VarI4FromUI8, 1); EXPECT(1);
1792 CONVERT(VarI4FromUI8, 2147483647); EXPECT(2147483647);
1793 CONVERT(VarI4FromUI8, 2147483648ul); EXPECT_OVERFLOW;
1794 }
1795
1796 static void test_VarI4FromBool(void)
1797 {
1798 CONVVARS(VARIANT_BOOL);
1799 int i;
1800
1801 CHECKPTR(VarI4FromBool);
1802 CONVERTRANGE(VarI4FromBool, -32768, 32768);
1803 }
1804
1805 static void test_VarI4FromR4(void)
1806 {
1807 CONVVARS(FLOAT);
1808
1809 CHECKPTR(VarI4FromR4);
1810
1811 /* min/max values are not exactly representable in a float */
1812 CONVERT(VarI4FromR4, -1.0f); EXPECT(-1);
1813 CONVERT(VarI4FromR4, 0.0f); EXPECT(0);
1814 CONVERT(VarI4FromR4, 1.0f); EXPECT(1);
1815
1816 CONVERT(VarI4FromR4, -1.5f); EXPECT(-2);
1817 CONVERT(VarI4FromR4, -0.6f); EXPECT(-1);
1818 CONVERT(VarI4FromR4, -0.5f); EXPECT(0);
1819 CONVERT(VarI4FromR4, -0.4f); EXPECT(0);
1820 CONVERT(VarI4FromR4, 0.4f); EXPECT(0);
1821 CONVERT(VarI4FromR4, 0.5f); EXPECT(0);
1822 CONVERT(VarI4FromR4, 0.6f); EXPECT(1);
1823 CONVERT(VarI4FromR4, 1.5f); EXPECT(2);
1824 }
1825
1826 static void test_VarI4FromR8(void)
1827 {
1828 CONVVARS(DOUBLE);
1829
1830 CHECKPTR(VarI4FromR8);
1831 CONVERT(VarI4FromR8, -2147483649.0); EXPECT_OVERFLOW;
1832 CONVERT(VarI4FromR8, -2147483648.51); EXPECT_OVERFLOW;
1833 CONVERT(VarI4FromR8, -2147483648.5); EXPECT(-2147483647 - 1);
1834 CONVERT(VarI4FromR8, -2147483648.0); EXPECT(-2147483647 - 1);
1835 CONVERT(VarI4FromR8, -1.0); EXPECT(-1);
1836 CONVERT(VarI4FromR8, 0.0); EXPECT(0);
1837 CONVERT(VarI4FromR8, 1.0); EXPECT(1);
1838 CONVERT(VarI4FromR8, 2147483647.0); EXPECT(2147483647);
1839 CONVERT(VarI4FromR8, 2147483647.49); EXPECT(2147483647);
1840 CONVERT(VarI4FromR8, 2147483647.5); EXPECT_OVERFLOW;
1841 CONVERT(VarI4FromR8, 2147483648.0); EXPECT_OVERFLOW;
1842
1843 CONVERT(VarI4FromR8, -1.5); EXPECT(-2);
1844 CONVERT(VarI4FromR8, -0.6); EXPECT(-1);
1845 CONVERT(VarI4FromR8, -0.5); EXPECT(0);
1846 CONVERT(VarI4FromR8, -0.4); EXPECT(0);
1847 CONVERT(VarI4FromR8, 0.4); EXPECT(0);
1848 CONVERT(VarI4FromR8, 0.5); EXPECT(0);
1849 CONVERT(VarI4FromR8, 0.6); EXPECT(1);
1850 CONVERT(VarI4FromR8, 1.5); EXPECT(2);
1851 }
1852
1853 static void test_VarI4FromDate(void)
1854 {
1855 CONVVARS(DATE);
1856
1857 CHECKPTR(VarI4FromDate);
1858 CONVERT(VarI4FromDate, -2147483649.0); EXPECT_OVERFLOW;
1859 CONVERT(VarI4FromDate, -2147483648.0); EXPECT(-2147483647 - 1);
1860 CONVERT(VarI4FromDate, -1.0); EXPECT(-1);
1861 CONVERT(VarI4FromDate, 0.0); EXPECT(0);
1862 CONVERT(VarI4FromDate, 1.0); EXPECT(1);
1863 CONVERT(VarI4FromDate, 2147483647.0); EXPECT(2147483647);
1864 CONVERT(VarI4FromDate, 2147483648.0); EXPECT_OVERFLOW;
1865
1866 CONVERT(VarI4FromDate, -1.5); EXPECT(-2);
1867 CONVERT(VarI4FromDate, -0.6); EXPECT(-1);
1868 CONVERT(VarI4FromDate, -0.5); EXPECT(0);
1869 CONVERT(VarI4FromDate, -0.4); EXPECT(0);
1870 CONVERT(VarI4FromDate, 0.4); EXPECT(0);
1871 CONVERT(VarI4FromDate, 0.5); EXPECT(0);
1872 CONVERT(VarI4FromDate, 0.6); EXPECT(1);
1873 CONVERT(VarI4FromDate, 1.5); EXPECT(2);
1874 }
1875
1876 static void test_VarI4FromCy(void)
1877 {
1878 CONVVARS(CY);
1879
1880 CHECKPTR(VarI4FromCy);
1881 CONVERT_CY(VarI4FromCy,-1); EXPECT(-1);
1882 CONVERT_CY(VarI4FromCy,0); EXPECT(0);
1883 CONVERT_CY(VarI4FromCy,1); EXPECT(1);
1884
1885 CONVERT_CY64(VarI4FromCy,-1,2147483647ul); EXPECT_OVERFLOW;
1886 CONVERT_CY64(VarI4FromCy,-1,2147483648ul); EXPECT(-2147483647 - 1);
1887 CONVERT_CY64(VarI4FromCy,0,2147483647ul); EXPECT(2147483647ul);
1888 CONVERT_CY64(VarI4FromCy,0,2147483648ul); EXPECT_OVERFLOW;
1889
1890 CONVERT_CY(VarI4FromCy,-1.5); EXPECT(-2);
1891 CONVERT_CY(VarI4FromCy,-0.6); EXPECT(-1);
1892 CONVERT_CY(VarI4FromCy,-0.5); EXPECT(0);
1893 CONVERT_CY(VarI4FromCy,-0.4); EXPECT(0);
1894 CONVERT_CY(VarI4FromCy,0.4); EXPECT(0);
1895 CONVERT_CY(VarI4FromCy,0.5); EXPECT(0);
1896 CONVERT_CY(VarI4FromCy,0.6); EXPECT(1);
1897 CONVERT_CY(VarI4FromCy,1.5); EXPECT(2);
1898 }
1899
1900 static void test_VarI4FromDec(void)
1901 {
1902 CONVVARS(DECIMAL);
1903
1904 CHECKPTR(VarI4FromDec);
1905
1906 CONVERT_BADDEC(VarI4FromDec);
1907
1908 CONVERT_DEC(VarI4FromDec,0,0x80,0,1); EXPECT(-1);
1909 CONVERT_DEC(VarI4FromDec,0,0,0,0); EXPECT(0);
1910 CONVERT_DEC(VarI4FromDec,0,0,0,1); EXPECT(1);
1911
1912 CONVERT_DEC64(VarI4FromDec,0,0x80,0,0,2147483649ul); EXPECT_OVERFLOW;
1913 CONVERT_DEC64(VarI4FromDec,0,0x80,0,0,2147483648ul); EXPECT(-2147483647 - 1);
1914 CONVERT_DEC64(VarI4FromDec,0,0,0,0,2147483647ul); EXPECT(2147483647ul);
1915 CONVERT_DEC64(VarI4FromDec,0,0,0,0,2147483648ul); EXPECT_OVERFLOW;
1916
1917 CONVERT_DEC64(VarI4FromDec,2,0x80,0,50,100); EXPECT_OVERFLOW;
1918 CONVERT_DEC64(VarI4FromDec,2,0x80,0,50,0); EXPECT(-2147483647 - 1);
1919 CONVERT_DEC64(VarI4FromDec,2,0,0,49,4294967196ul); EXPECT(2147483647);
1920 CONVERT_DEC64(VarI4FromDec,2,0,0,50,0); EXPECT_OVERFLOW;
1921 }
1922
1923 static void test_VarI4FromStr(void)
1924 {
1925 CONVVARS(LCID);
1926 OLECHAR buff[128];
1927
1928 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1929
1930 CHECKPTR(VarI4FromStr);
1931
1932 CONVERT_STR(VarI4FromStr,NULL,0); EXPECT_MISMATCH;
1933 CONVERT_STR(VarI4FromStr,"0",0); EXPECT(0);
1934 CONVERT_STR(VarI4FromStr,"-2147483649",0); EXPECT_OVERFLOW;
1935 CONVERT_STR(VarI4FromStr,"-2147483648",0); EXPECT(-2147483647 -1);
1936 CONVERT_STR(VarI4FromStr,"2147483647",0); EXPECT(2147483647);
1937 CONVERT_STR(VarI4FromStr,"2147483648",0); EXPECT_OVERFLOW;
1938
1939 /* Rounding */
1940 CONVERT_STR(VarI4FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECT(-2);
1941 CONVERT_STR(VarI4FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECT(-1);
1942 CONVERT_STR(VarI4FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0);
1943 CONVERT_STR(VarI4FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0);
1944 CONVERT_STR(VarI4FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0);
1945 CONVERT_STR(VarI4FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0);
1946 CONVERT_STR(VarI4FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECT(1);
1947 CONVERT_STR(VarI4FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECT(2);
1948 }
1949
1950 static void test_VarI4Copy(void)
1951 {
1952 COPYTEST(1, VT_I4, V_I4(&vSrc), V_I4(&vDst), V_I4REF(&vSrc), V_I4REF(&vDst), "%d");
1953 }
1954
1955 static void test_VarI4ChangeTypeEx(void)
1956 {
1957 HRESULT hres;
1958 LONG in;
1959 VARIANTARG vSrc, vDst;
1960
1961 in = 1;
1962
1963 INITIAL_TYPETEST(VT_I4, V_I4, "%d");
1964 COMMON_TYPETEST;
1965 NEGATIVE_TYPETEST(VT_I4, V_I4, "%d", VT_UI4, V_UI4);
1966 }
1967
1968 #undef CONV_TYPE
1969 #define CONV_TYPE ULONG
1970 #undef EXPECTRES
1971 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%u")
1972
1973 static void test_VarUI4FromI1(void)
1974 {
1975 CONVVARS(signed char);
1976 int i;
1977
1978 CHECKPTR(VarUI4FromI1);
1979 OVERFLOWRANGE(VarUI4FromI1, -127, 0);
1980 CONVERTRANGE(VarUI4FromI1, 0, 128);
1981 }
1982
1983 static void test_VarUI4FromI2(void)
1984 {
1985 CONVVARS(SHORT);
1986 int i;
1987
1988 CHECKPTR(VarUI4FromI2);
1989 OVERFLOWRANGE(VarUI4FromI2, -32768, 0);
1990 CONVERTRANGE(VarUI4FromI2, 0, 32768);
1991 }
1992
1993 static void test_VarUI4FromUI2(void)
1994 {
1995 CONVVARS(USHORT);
1996 int i;
1997
1998 CHECKPTR(VarUI4FromUI2);
1999 CONVERTRANGE(VarUI4FromUI2, 0, 65536);
2000 }
2001
2002 static void test_VarUI4FromI8(void)
2003 {
2004 CONVVARS(LONG64);
2005
2006 CHECKPTR(VarUI4FromI8);
2007 CONVERT(VarUI4FromI8, -1); EXPECT_OVERFLOW;
2008 CONVERT(VarUI4FromI8, 0); EXPECT(0);
2009 CONVERT(VarUI4FromI8, 1); EXPECT(1);
2010 CONVERT(VarUI4FromI8, 4294967295ul); EXPECT(4294967295ul);
2011 CONVERT_I8(VarUI4FromI8, 1, 0); EXPECT_OVERFLOW;
2012 }
2013
2014 static void test_VarUI4FromUI1(void)
2015 {
2016 CONVVARS(BYTE);
2017 int i;
2018
2019 CHECKPTR(VarUI4FromUI1);
2020 CONVERTRANGE(VarUI4FromUI1, 0, 256);
2021 }
2022
2023 static void test_VarUI4FromI4(void)
2024 {
2025 CONVVARS(int);
2026
2027 CHECKPTR(VarUI4FromI4);
2028 CONVERT(VarUI4FromI4, -1); EXPECT_OVERFLOW;
2029 CONVERT(VarUI4FromI4, 0); EXPECT(0);
2030 CONVERT(VarUI4FromI4, 1); EXPECT(1);
2031 CONVERT(VarUI4FromI4, 2147483647); EXPECT(2147483647);
2032 }
2033
2034 static void test_VarUI4FromUI8(void)
2035 {
2036 CONVVARS(ULONG64);
2037
2038 CHECKPTR(VarUI4FromUI8);
2039 CONVERT(VarUI4FromUI8, 0); EXPECT(0);
2040 CONVERT(VarUI4FromUI8, 1); EXPECT(1);
2041 CONVERT(VarUI4FromI8, 4294967295ul); EXPECT(4294967295ul);
2042 CONVERT_I8(VarUI4FromI8, 1, 0); EXPECT_OVERFLOW;
2043 }
2044
2045 static void test_VarUI4FromBool(void)
2046 {
2047 CONVVARS(VARIANT_BOOL);
2048 int i;
2049
2050 CHECKPTR(VarUI4FromBool);
2051 CONVERTRANGE(VarUI4FromBool, -32768, 32768);
2052 }
2053
2054 static void test_VarUI4FromR4(void)
2055 {
2056 CONVVARS(FLOAT);
2057
2058 CHECKPTR(VarUI4FromR4);
2059 /* We can't test max values as they are not exactly representable in a float */
2060 CONVERT(VarUI4FromR4, -1.0f); EXPECT_OVERFLOW;
2061 CONVERT(VarUI4FromR4, -0.51f); EXPECT_OVERFLOW;
2062 CONVERT(VarUI4FromR4, -0.5f); EXPECT(0);
2063 CONVERT(VarUI4FromR4, 0.0f); EXPECT(0);
2064 CONVERT(VarUI4FromR4, 1.0f); EXPECT(1);
2065
2066 CONVERT(VarUI4FromR4, -1.5f); EXPECT_OVERFLOW;
2067 CONVERT(VarUI4FromR4, -0.6f); EXPECT_OVERFLOW;
2068 CONVERT(VarUI4FromR4, -0.5f); EXPECT(0);
2069 CONVERT(VarUI4FromR4, -0.4f); EXPECT(0);
2070 CONVERT(VarUI4FromR4, 0.4f); EXPECT(0);
2071 CONVERT(VarUI4FromR4, 0.5f); EXPECT(0);
2072 CONVERT(VarUI4FromR4, 0.6f); EXPECT(1);
2073 CONVERT(VarUI4FromR4, 1.5f); EXPECT(2);
2074
2075 }
2076
2077 static void test_VarUI4FromR8(void)
2078 {
2079 CONVVARS(DOUBLE);
2080
2081 CHECKPTR(VarUI4FromR8);
2082 CONVERT(VarUI4FromR8, -1.0); EXPECT_OVERFLOW;
2083 CONVERT(VarUI4FromR4, -0.51f); EXPECT_OVERFLOW;
2084 CONVERT(VarUI4FromR4, -0.5f); EXPECT(0);
2085 CONVERT(VarUI4FromR8, 0.0); EXPECT(0);
2086 CONVERT(VarUI4FromR8, 1.0); EXPECT(1);
2087 CONVERT(VarUI4FromR8, 4294967295.0); EXPECT(4294967295ul);
2088 CONVERT(VarUI4FromR8, 4294967295.49); EXPECT(4294967295ul);
2089 CONVERT(VarUI4FromR8, 4294967295.5); EXPECT_OVERFLOW;
2090 CONVERT(VarUI4FromR8, 4294967296.0); EXPECT_OVERFLOW;
2091
2092 CONVERT(VarUI4FromR8, -1.5); EXPECT_OVERFLOW;
2093 CONVERT(VarUI4FromR8, -0.6); EXPECT_OVERFLOW;
2094 CONVERT(VarUI4FromR8, -0.5); EXPECT(0);
2095 CONVERT(VarUI4FromR8, -0.4); EXPECT(0);
2096 CONVERT(VarUI4FromR8, 0.4); EXPECT(0);
2097 CONVERT(VarUI4FromR8, 0.5); EXPECT(0);
2098 CONVERT(VarUI4FromR8, 0.6); EXPECT(1);
2099 CONVERT(VarUI4FromR8, 1.5); EXPECT(2);
2100 }
2101
2102 static void test_VarUI4FromDate(void)
2103 {
2104 CONVVARS(DOUBLE);
2105
2106 CHECKPTR(VarUI4FromDate);
2107 CONVERT(VarUI4FromDate, -1.0); EXPECT_OVERFLOW;
2108 CONVERT(VarUI4FromDate, 0.0); EXPECT(0);
2109 CONVERT(VarUI4FromDate, 1.0); EXPECT(1);
2110 CONVERT(VarUI4FromDate, 4294967295.0); EXPECT(4294967295ul);
2111 CONVERT(VarUI4FromDate, 4294967296.0); EXPECT_OVERFLOW;
2112
2113 CONVERT(VarUI4FromDate, -1.5); EXPECT_OVERFLOW;
2114 CONVERT(VarUI4FromDate, -0.6); EXPECT_OVERFLOW;
2115 CONVERT(VarUI4FromDate, -0.5); EXPECT(0);
2116 CONVERT(VarUI4FromDate, -0.4); EXPECT(0);
2117 CONVERT(VarUI4FromDate, 0.4); EXPECT(0);
2118 CONVERT(VarUI4FromDate, 0.5); EXPECT(0);
2119 CONVERT(VarUI4FromDate, 0.6); EXPECT(1);
2120 CONVERT(VarUI4FromDate, 1.5); EXPECT(2);
2121 }
2122
2123 static void test_VarUI4FromCy(void)
2124 {
2125 CONVVARS(CY);
2126
2127 CHECKPTR(VarUI4FromCy);
2128 CONVERT_CY(VarUI4FromCy,-1); EXPECT_OVERFLOW;
2129 CONVERT_CY(VarUI4FromCy,0); EXPECT(0);
2130 CONVERT_CY(VarUI4FromCy,1); EXPECT(1);
2131 CONVERT_CY64(VarUI4FromCy,0,4294967295ul); EXPECT(4294967295ul);
2132 CONVERT_CY64(VarUI4FromCy,1,0); EXPECT_OVERFLOW;
2133
2134 CONVERT_CY(VarUI4FromCy,-1.5); EXPECT_OVERFLOW;
2135 CONVERT_CY(VarUI4FromCy,-0.6); EXPECT_OVERFLOW;
2136 CONVERT_CY(VarUI4FromCy,-0.5); EXPECT(0);
2137 CONVERT_CY(VarUI4FromCy,-0.4); EXPECT(0);
2138 CONVERT_CY(VarUI4FromCy,0.4); EXPECT(0);
2139 CONVERT_CY(VarUI4FromCy,0.5); EXPECT(0);
2140 CONVERT_CY(VarUI4FromCy,0.6); EXPECT(1);
2141 CONVERT_CY(VarUI4FromCy,1.5); EXPECT(2);
2142 }
2143
2144 static void test_VarUI4FromDec(void)
2145 {
2146 CONVVARS(DECIMAL);
2147
2148 CHECKPTR(VarUI4FromDec);
2149
2150 CONVERT_BADDEC(VarUI4FromDec);
2151
2152 CONVERT_DEC(VarUI4FromDec,0,0x80,0,1); EXPECT_OVERFLOW;
2153 CONVERT_DEC(VarUI4FromDec,0,0,0,0); EXPECT(0);
2154 CONVERT_DEC(VarUI4FromDec,0,0,0,1); EXPECT(1);
2155 CONVERT_DEC64(VarUI4FromDec,0,0,0,0,4294967295ul); EXPECT(4294967295ul);
2156 CONVERT_DEC64(VarUI4FromDec,0,0,0,1,0); EXPECT_OVERFLOW;
2157
2158 CONVERT_DEC64(VarUI4FromDec,2,0,0,99,4294967196ul); EXPECT(4294967295ul);
2159 CONVERT_DEC64(VarUI4FromDec,2,0,0,100,0); EXPECT_OVERFLOW;
2160 }
2161
2162 static void test_VarUI4FromStr(void)
2163 {
2164 CONVVARS(LCID);
2165 OLECHAR buff[128];
2166
2167 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2168
2169 CHECKPTR(VarUI4FromStr);
2170
2171 CONVERT_STR(VarUI4FromStr,NULL,0); EXPECT_MISMATCH;
2172 CONVERT_STR(VarUI4FromStr,"-1",0); EXPECT_OVERFLOW;
2173 CONVERT_STR(VarUI4FromStr,"0",0); EXPECT(0);
2174 CONVERT_STR(VarUI4FromStr,"4294967295",0); EXPECT(4294967295ul);
2175 CONVERT_STR(VarUI4FromStr,"4294967296",0); EXPECT_OVERFLOW;
2176
2177 /* Rounding */
2178 CONVERT_STR(VarUI4FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
2179 CONVERT_STR(VarUI4FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
2180 CONVERT_STR(VarUI4FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0);
2181 CONVERT_STR(VarUI4FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0);
2182 CONVERT_STR(VarUI4FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0);
2183 CONVERT_STR(VarUI4FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0);
2184 CONVERT_STR(VarUI4FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECT(1);
2185 CONVERT_STR(VarUI4FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECT(2);
2186 }
2187
2188 static void test_VarUI4Copy(void)
2189 {
2190 COPYTEST(1u, VT_UI4, V_UI4(&vSrc), V_UI4(&vDst), V_UI4REF(&vSrc), V_UI4REF(&vDst), "%u");
2191 }
2192
2193 static void test_VarUI4ChangeTypeEx(void)
2194 {
2195 HRESULT hres;
2196 ULONG in;
2197 VARIANTARG vSrc, vDst;
2198
2199 in = 1;
2200
2201 INITIAL_TYPETEST(VT_UI4, V_UI4, "%u");
2202 COMMON_TYPETEST;
2203 NEGATIVE_TYPETEST(VT_UI4, V_UI4, "%u", VT_I4, V_I4);
2204 }
2205
2206 /*
2207 * VT_I8/VT_UI8
2208 */
2209
2210 #undef CONV_TYPE
2211 #define CONV_TYPE LONG64
2212
2213 #define EXPECTI8(x) \
2214 ok((hres == S_OK && out == (CONV_TYPE)(x)), \
2215 "expected " #x "(%u,%u), got (%u,%u); hres=0x%08x\n", \
2216 (ULONG)((LONG64)(x) >> 32), (ULONG)((x) & 0xffffffff), \
2217 (ULONG)(out >> 32), (ULONG)(out & 0xffffffff), hres)
2218
2219 #define EXPECTI864(x,y) \
2220 ok(hres == S_OK && (out >> 32) == (CONV_TYPE)(x) && (out & 0xffffffff) == (CONV_TYPE)(y), \
2221 "expected " #x "(%u,%u), got (%u,%u); hres=0x%08x\n", \
2222 (ULONG)(x), (ULONG)(y), \
2223 (ULONG)(out >> 32), (ULONG)(out & 0xffffffff), hres)
2224
2225 static void test_VarI8FromI1(void)
2226 {
2227 CONVVARS(signed char);
2228 int i;
2229
2230 CHECKPTR(VarI8FromI1);
2231 for (i = -128; i < 128; i++)
2232 {
2233 CONVERT(VarI8FromI1,i); EXPECTI8(i);
2234 }
2235 }
2236
2237 static void test_VarI8FromUI1(void)
2238 {
2239 CONVVARS(BYTE);
2240 int i;
2241
2242 CHECKPTR(VarI8FromUI1);
2243 for (i = 0; i < 256; i++)
2244 {
2245 CONVERT(VarI8FromUI1,i); EXPECTI8(i);
2246 }
2247 }
2248
2249 static void test_VarI8FromI2(void)
2250 {
2251 CONVVARS(SHORT);
2252 int i;
2253
2254 CHECKPTR(VarI8FromI2);
2255 for (i = -32768; i < 32768; i++)
2256 {
2257 CONVERT(VarI8FromI2,i); EXPECTI8(i);
2258 }
2259 }
2260
2261 static void test_VarI8FromUI2(void)
2262 {
2263 CONVVARS(USHORT);
2264 int i;
2265
2266 CHECKPTR(VarI8FromUI2);
2267 for (i = -0; i < 65535; i++)
2268 {
2269 CONVERT(VarI8FromUI2,i); EXPECTI8(i);
2270 }
2271 }
2272
2273 static void test_VarI8FromUI4(void)
2274 {
2275 CONVVARS(ULONG);
2276
2277 CHECKPTR(VarI8FromUI4);
2278 CONVERT(VarI8FromUI4, 0); EXPECTI8(0);
2279 CONVERT(VarI8FromUI4, 1); EXPECTI8(1);
2280 CONVERT(VarI8FromUI4, 4294967295ul); EXPECTI8(4294967295ul);
2281 }
2282
2283 static void test_VarI8FromR4(void)
2284 {
2285 CONVVARS(FLOAT);
2286
2287 CHECKPTR(VarI8FromR4);
2288
2289 CONVERT(VarI8FromR4, -128.0f); EXPECTI8(-128);
2290 CONVERT(VarI8FromR4, -1.0f); EXPECTI8(-1);
2291 CONVERT(VarI8FromR4, 0.0f); EXPECTI8(0);
2292 CONVERT(VarI8FromR4, 1.0f); EXPECTI8(1);
2293 CONVERT(VarI8FromR4, 127.0f); EXPECTI8(127);
2294
2295 CONVERT(VarI8FromR4, -1.5f); EXPECTI8(-2);
2296 CONVERT(VarI8FromR4, -0.6f); EXPECTI8(-1);
2297 CONVERT(VarI8FromR4, -0.5f); EXPECTI8(0);
2298 CONVERT(VarI8FromR4, -0.4f); EXPECTI8(0);
2299 CONVERT(VarI8FromR4, 0.4f); EXPECTI8(0);
2300 CONVERT(VarI8FromR4, 0.5f); EXPECTI8(0);
2301 CONVERT(VarI8FromR4, 0.6f); EXPECTI8(1);
2302 CONVERT(VarI8FromR4, 1.5f); EXPECTI8(2);
2303 }
2304
2305 static void test_VarI8FromR8(void)
2306 {
2307 CONVVARS(DOUBLE);
2308
2309 CHECKPTR(VarI8FromR8);
2310 CONVERT(VarI8FromR8, -128.0); EXPECTI8(-128);
2311 CONVERT(VarI8FromR8, -1.0); EXPECTI8(-1);
2312 CONVERT(VarI8FromR8, 0.0); EXPECTI8(0);
2313 CONVERT(VarI8FromR8, 1.0); EXPECTI8(1);
2314 CONVERT(VarI8FromR8, 127.0); EXPECTI8(127);
2315
2316 CONVERT(VarI8FromR8, -1.5); EXPECTI8(-2);
2317 CONVERT(VarI8FromR8, -0.6); EXPECTI8(-1);
2318 CONVERT(VarI8FromR8, -0.5); EXPECTI8(0);
2319 CONVERT(VarI8FromR8, -0.4); EXPECTI8(0);
2320 CONVERT(VarI8FromR8, 0.4); EXPECTI8(0);
2321 CONVERT(VarI8FromR8, 0.5); EXPECTI8(0);
2322 CONVERT(VarI8FromR8, 0.6); EXPECTI8(1);
2323 CONVERT(VarI8FromR8, 1.5); EXPECTI8(2);
2324 }
2325
2326 static void test_VarI8FromDate(void)
2327 {
2328 CONVVARS(DATE);
2329
2330 CHECKPTR(VarI8FromDate);
2331 CONVERT(VarI8FromDate, -128.0); EXPECTI8(-128);
2332 CONVERT(VarI8FromDate, -1.0); EXPECTI8(-1);
2333 CONVERT(VarI8FromDate, 0.0); EXPECTI8(0);
2334 CONVERT(VarI8FromDate, 1.0); EXPECTI8(1);
2335 CONVERT(VarI8FromDate, 127.0); EXPECTI8(127);
2336
2337 CONVERT(VarI8FromDate, -1.5); EXPECTI8(-2);
2338 CONVERT(VarI8FromDate, -0.6); EXPECTI8(-1);
2339 CONVERT(VarI8FromDate, -0.5); EXPECTI8(0);
2340 CONVERT(VarI8FromDate, -0.4); EXPECTI8(0);
2341 CONVERT(VarI8FromDate, 0.4); EXPECTI8(0);
2342 CONVERT(VarI8FromDate, 0.5); EXPECTI8(0);
2343 CONVERT(VarI8FromDate, 0.6); EXPECTI8(1);
2344 CONVERT(VarI8FromDate, 1.5); EXPECTI8(2);
2345 }
2346
2347 static void test_VarI8FromBool(void)
2348 {
2349 CONVVARS(VARIANT_BOOL);
2350 int i;
2351
2352 CHECKPTR(VarI8FromBool);
2353 for (i = -32768; i < 32768; i++)
2354 {
2355 CONVERT(VarI8FromBool,i); EXPECTI8(i);
2356 }
2357 }
2358
2359 static void test_VarI8FromUI8(void)
2360 {
2361 CONVVARS(ULONG64);
2362
2363 CHECKPTR(VarI8FromUI8);
2364 CONVERT(VarI8FromUI8, 0); EXPECTI8(0);
2365 CONVERT(VarI8FromUI8, 1); EXPECTI8(1);
2366 CONVERT_I8(VarI8FromUI8, 0x7fffffff, 0xffffffff); EXPECTI864(0x7fffffff, 0xffffffff);
2367 CONVERT_I8(VarI8FromUI8, 0x80000000, 0); EXPECT_OVERFLOW;
2368 }
2369
2370 static void test_VarI8FromCy(void)
2371 {
2372 CONVVARS(CY);
2373
2374 CHECKPTR(VarI8FromCy);
2375 CONVERT_CY(VarI8FromCy,-128); EXPECTI8(-129);
2376 CONVERT_CY(VarI8FromCy,-1); EXPECTI8(-2);
2377 CONVERT_CY(VarI8FromCy,0); EXPECTI8(0);
2378 CONVERT_CY(VarI8FromCy,1); EXPECTI8(1);
2379 CONVERT_CY(VarI8FromCy,127); EXPECTI8(127);
2380
2381 CONVERT_CY(VarI8FromCy,-1.5); EXPECTI8(-2);
2382 CONVERT_CY(VarI8FromCy,-0.6); EXPECTI8(-1);
2383 CONVERT_CY(VarI8FromCy,-0.5); EXPECTI8(-1);
2384 CONVERT_CY(VarI8FromCy,-0.4); EXPECTI8(-1);
2385 CONVERT_CY(VarI8FromCy,0.4); EXPECTI8(0);
2386 CONVERT_CY(VarI8FromCy,0.5); EXPECTI8(0);
2387 CONVERT_CY(VarI8FromCy,0.6); EXPECTI8(1);
2388 CONVERT_CY(VarI8FromCy,1.5); EXPECTI8(2);
2389 }
2390
2391 static void test_VarI8FromDec(void)
2392 {
2393 CONVVARS(DECIMAL);
2394
2395 CHECKPTR(VarI8FromDec);
2396
2397 CONVERT_BADDEC(VarI8FromDec);
2398
2399 CONVERT_DEC(VarI8FromDec,0,0x80,0,128); EXPECTI8(-128);
2400 CONVERT_DEC(VarI8FromDec,0,0x80,0,1); EXPECTI8(-1);
2401 CONVERT_DEC(VarI8FromDec,0,0,0,0); EXPECTI8(0);
2402 CONVERT_DEC(VarI8FromDec,0,0,0,1); EXPECTI8(1);
2403 CONVERT_DEC(VarI8FromDec,0,0,0,127); EXPECTI8(127);
2404
2405 CONVERT_DEC(VarI8FromDec,2,0x80,0,12700); EXPECTI8(-127);
2406 CONVERT_DEC(VarI8FromDec,2,0,0,12700); EXPECTI8(127);
2407 }
2408
2409 static void test_VarI8FromStr(void)
2410 {
2411 CONVVARS(LCID);
2412 OLECHAR buff[128];
2413
2414 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2415
2416 CHECKPTR(VarI8FromStr);
2417
2418 CONVERT_STR(VarI8FromStr,NULL,0); EXPECT_MISMATCH;
2419 CONVERT_STR(VarI8FromStr,"0",0); EXPECTI8(0);
2420 CONVERT_STR(VarI8FromStr,"-1",0); EXPECTI8(-1);
2421 CONVERT_STR(VarI8FromStr,"2147483647",0); EXPECTI8(2147483647);
2422
2423 CONVERT_STR(VarI8FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(-2);
2424 CONVERT_STR(VarI8FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECTI8(-1);
2425 CONVERT_STR(VarI8FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2426 CONVERT_STR(VarI8FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2427 CONVERT_STR(VarI8FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2428 CONVERT_STR(VarI8FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2429 CONVERT_STR(VarI8FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECTI8(1);
2430 CONVERT_STR(VarI8FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(2);
2431 }
2432
2433 static void test_VarI8Copy(void)
2434 {
2435 HRESULT hres;
2436 VARIANTARG vSrc, vDst;
2437 LONGLONG in = 1;
2438
2439 if (!has_i8)
2440 {
2441 win_skip("I8 and UI8 data types are not available\n");
2442 return;
2443 }
2444
2445 VariantInit(&vSrc);
2446 VariantInit(&vDst);
2447 V_VT(&vSrc) = VT_I8;
2448 V_I8(&vSrc) = in;
2449 hres = VariantCopy(&vDst, &vSrc);
2450 ok(hres == S_OK && V_VT(&vDst) == VT_I8 && V_I8(&vDst) == in,
2451 "copy hres 0x%X, type %d, value (%x%08x) %x%08x\n",
2452 hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_I8(&vDst) >> 32), (UINT)V_I8(&vDst) );
2453 V_VT(&vSrc) = VT_I8|VT_BYREF;
2454 V_I8REF(&vSrc) = &in;
2455 hres = VariantCopy(&vDst, &vSrc);
2456 ok(hres == S_OK && V_VT(&vDst) == (VT_I8|VT_BYREF) && V_I8REF(&vDst) == &in,
2457 "ref hres 0x%X, type %d, ref (%p) %p\n", hres, V_VT(&vDst), &in, V_I8REF(&vDst));
2458 hres = VariantCopyInd(&vDst, &vSrc);
2459 ok(hres == S_OK && V_VT(&vDst) == VT_I8 && V_I8(&vDst) == in,
2460 "copy hres 0x%X, type %d, value (%x%08x) %x%08x\n",
2461 hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_I8(&vDst) >> 32), (UINT)V_I8(&vDst) );
2462 }
2463
2464 static void test_VarI8ChangeTypeEx(void)
2465 {
2466 HRESULT hres;
2467 LONG64 in;
2468 VARIANTARG vSrc, vDst;
2469
2470 if (!has_i8)
2471 {
2472 win_skip("I8 and UI8 data types are not available\n");
2473 return;
2474 }
2475
2476 in = 1;
2477
2478 INITIAL_TYPETESTI8(VT_I8, V_I8);
2479 COMMON_TYPETEST;
2480 }
2481
2482 /* Adapt the test macros to UI8 */
2483 #undef CONV_TYPE
2484 #define CONV_TYPE ULONG64
2485
2486 static void test_VarUI8FromI1(void)
2487 {
2488 CONVVARS(signed char);
2489 int i;
2490
2491 CHECKPTR(VarUI8FromI1);
2492 for (i = -128; i < 128; i++)
2493 {
2494 CONVERT(VarUI8FromI1,i);
2495 if (i < 0)
2496 EXPECT_OVERFLOW;
2497 else
2498 EXPECTI8(i);
2499 }
2500 }
2501
2502 static void test_VarUI8FromUI1(void)
2503 {
2504 CONVVARS(BYTE);
2505 int i;
2506
2507 CHECKPTR(VarUI8FromUI1);
2508 for (i = 0; i < 256; i++)
2509 {
2510 CONVERT(VarUI8FromUI1,i); EXPECTI8(i);
2511 }
2512 }
2513
2514 static void test_VarUI8FromI2(void)
2515 {
2516 CONVVARS(SHORT);
2517 int i;
2518
2519 CHECKPTR(VarUI8FromI2);
2520 for (i = -32768; i < 32768; i++)
2521 {
2522 CONVERT(VarUI8FromI2,i);
2523 if (i < 0)
2524 EXPECT_OVERFLOW;
2525 else
2526 EXPECTI8(i);
2527 }
2528 }
2529
2530 static void test_VarUI8FromUI2(void)
2531 {
2532 CONVVARS(USHORT);
2533 int i;
2534
2535 CHECKPTR(VarUI8FromUI2);
2536 for (i = 0; i < 65535; i++)
2537 {
2538 CONVERT(VarUI8FromUI2,i); EXPECTI8(i);
2539 }
2540 }
2541
2542 static void test_VarUI8FromUI4(void)
2543 {
2544 CONVVARS(ULONG);
2545
2546 CHECKPTR(VarUI8FromUI4);
2547 CONVERT(VarUI8FromUI4, 0); EXPECTI8(0);
2548 CONVERT(VarUI8FromUI4, 0xffffffff); EXPECTI8(0xffffffff);
2549 }
2550
2551 static void test_VarUI8FromR4(void)
2552 {
2553 CONVVARS(FLOAT);
2554
2555 CHECKPTR(VarUI8FromR4);
2556 CONVERT(VarUI8FromR4, -1.0f); EXPECT_OVERFLOW;
2557 CONVERT(VarUI8FromR4, 0.0f); EXPECTI8(0);
2558 CONVERT(VarUI8FromR4, 1.0f); EXPECTI8(1);
2559 CONVERT(VarUI8FromR4, 255.0f); EXPECTI8(255);
2560
2561 CONVERT(VarUI8FromR4, -1.5f); EXPECT_OVERFLOW;
2562 CONVERT(VarUI8FromR4, -0.6f); EXPECT_OVERFLOW;
2563 CONVERT(VarUI8FromR4, -0.5f); EXPECTI8(0);
2564 CONVERT(VarUI8FromR4, -0.4f); EXPECTI8(0);
2565 CONVERT(VarUI8FromR4, 0.4f); EXPECTI8(0);
2566 CONVERT(VarUI8FromR4, 0.5f); EXPECTI8(0);
2567 CONVERT(VarUI8FromR4, 0.6f); EXPECTI8(1);
2568 CONVERT(VarUI8FromR4, 1.5f); EXPECTI8(2);
2569 }
2570
2571 static void test_VarUI8FromR8(void)
2572 {
2573 CONVVARS(DOUBLE);
2574
2575 CHECKPTR(VarUI8FromR8);
2576 CONVERT(VarUI8FromR8, -1.0); EXPECT_OVERFLOW;
2577 CONVERT(VarUI8FromR8, 0.0); EXPECTI8(0);
2578 CONVERT(VarUI8FromR8, 1.0); EXPECTI8(1);
2579 CONVERT(VarUI8FromR8, 255.0); EXPECTI8(255);
2580
2581 CONVERT(VarUI8FromR8, -1.5); EXPECT_OVERFLOW;
2582 CONVERT(VarUI8FromR8, -0.6); EXPECT_OVERFLOW;
2583 CONVERT(VarUI8FromR8, -0.5); EXPECTI8(0);
2584 CONVERT(VarUI8FromR8, -0.4); EXPECTI8(0);
2585 CONVERT(VarUI8FromR8, 0.4); EXPECTI8(0);
2586 CONVERT(VarUI8FromR8, 0.5); EXPECTI8(0);
2587 CONVERT(VarUI8FromR8, 0.6); EXPECTI8(1);
2588 CONVERT(VarUI8FromR8, 1.5); EXPECTI8(2);
2589 }
2590
2591 static void test_VarUI8FromDate(void)
2592 {
2593 CONVVARS(DATE);
2594
2595 CHECKPTR(VarUI8FromDate);
2596 CONVERT(VarUI8FromDate, -1.0); EXPECT_OVERFLOW;
2597 CONVERT(VarUI8FromDate, 0.0); EXPECTI8(0);
2598 CONVERT(VarUI8FromDate, 1.0); EXPECTI8(1);
2599 CONVERT(VarUI8FromDate, 255.0); EXPECTI8(255);
2600
2601 CONVERT(VarUI8FromDate, -1.5); EXPECT_OVERFLOW;
2602 CONVERT(VarUI8FromDate, -0.6); EXPECT_OVERFLOW;
2603 CONVERT(VarUI8FromDate, -0.5); EXPECTI8(0);
2604 CONVERT(VarUI8FromDate, -0.4); EXPECTI8(0);
2605 CONVERT(VarUI8FromDate, 0.4); EXPECTI8(0);
2606 CONVERT(VarUI8FromDate, 0.5); EXPECTI8(0);
2607 CONVERT(VarUI8FromDate, 0.6); EXPECTI8(1);
2608 CONVERT(VarUI8FromDate, 1.5); EXPECTI8(2);
2609 }
2610
2611 static void test_VarUI8FromBool(void)
2612 {
2613 CONVVARS(VARIANT_BOOL);
2614 int i;
2615
2616 CHECKPTR(VarUI8FromBool);
2617 for (i = -32768; i < 32768; i++)
2618 {
2619 CONVERT(VarUI8FromBool, i); EXPECTI8(i);
2620 }
2621 }
2622
2623 static void test_VarUI8FromI8(void)
2624 {
2625 CONVVARS(LONG64);
2626
2627 CHECKPTR(VarUI8FromI8);
2628 CONVERT(VarUI8FromI8, -1); EXPECT_OVERFLOW;
2629 CONVERT(VarUI8FromI8, 0); EXPECTI8(0);
2630 CONVERT(VarUI8FromI8, 1); EXPECTI8(1);
2631 }
2632
2633 static void test_VarUI8FromCy(void)
2634 {
2635 CONVVARS(CY);
2636
2637 CHECKPTR(VarUI8FromCy);
2638 CONVERT_CY(VarUI8FromCy,-1); EXPECT_OVERFLOW;
2639 CONVERT_CY(VarUI8FromCy,0); EXPECTI8(0);
2640 CONVERT_CY(VarUI8FromCy,1); EXPECTI8(1);
2641 CONVERT_CY(VarUI8FromCy,255); EXPECTI8(255);
2642
2643 CONVERT_CY(VarUI8FromCy,-1.5); EXPECT_OVERFLOW;
2644 CONVERT_CY(VarUI8FromCy,-0.6); EXPECT_OVERFLOW;
2645 CONVERT_CY(VarUI8FromCy,-0.5); EXPECTI8(0);
2646 CONVERT_CY(VarUI8FromCy,-0.4); EXPECTI8(0);
2647 CONVERT_CY(VarUI8FromCy,0.4); EXPECTI8(0);
2648 CONVERT_CY(VarUI8FromCy,0.5); EXPECTI8(0);
2649 CONVERT_CY(VarUI8FromCy,0.6); EXPECTI8(1);
2650 CONVERT_CY(VarUI8FromCy,1.5); EXPECTI8(2);
2651 }
2652
2653 static void test_VarUI8FromDec(void)
2654 {
2655 CONVVARS(DECIMAL);
2656
2657 CHECKPTR(VarUI8FromDec);
2658
2659 CONVERT_BADDEC(VarUI8FromDec);
2660
2661 /* This returns 1 under native; Wine fixes this bug and returns overflow */
2662 if (0)
2663 {
2664 CONVERT_DEC(VarUI8FromDec,0,0x80,0,1);
2665 }
2666
2667 CONVERT_DEC(VarUI8FromDec,0,0,0,0); EXPECTI8(0);
2668 CONVERT_DEC(VarUI8FromDec,0,0,0,1); EXPECTI8(1);
2669 CONVERT_DEC(VarUI8FromDec,0,0,0,255); EXPECTI8(255);
2670
2671 CONVERT_DEC(VarUI8FromDec,2,0x80,0,100); EXPECT_OVERFLOW;
2672 CONVERT_DEC(VarUI8FromDec,2,0,0,25500); EXPECTI8(255);
2673 }
2674
2675 static void test_VarUI8FromStr(void)
2676 {
2677 CONVVARS(LCID);
2678 OLECHAR buff[128];
2679
2680 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2681
2682 CHECKPTR(VarUI8FromStr);
2683
2684 CONVERT_STR(VarUI8FromStr,NULL,0); EXPECT_MISMATCH;
2685 CONVERT_STR(VarUI8FromStr,"0",0); EXPECTI8(0);
2686 CONVERT_STR(VarUI8FromStr,"-1",0); EXPECT_OVERFLOW;
2687 CONVERT_STR(VarUI8FromStr,"2147483647",0); EXPECTI8(2147483647);
2688 CONVERT_STR(VarUI8FromStr,"18446744073709551614",0); EXPECTI864(0xFFFFFFFF,0xFFFFFFFE);
2689 CONVERT_STR(VarUI8FromStr,"18446744073709551615",0); EXPECTI864(0xFFFFFFFF,0xFFFFFFFF);
2690 CONVERT_STR(VarUI8FromStr,"18446744073709551616",0); EXPECT_OVERFLOW;
2691
2692 CONVERT_STR(VarUI8FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
2693 CONVERT_STR(VarUI8FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECT_OVERFLOW;
2694 CONVERT_STR(VarUI8FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2695 CONVERT_STR(VarUI8FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2696 CONVERT_STR(VarUI8FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2697 CONVERT_STR(VarUI8FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(0);
2698 CONVERT_STR(VarUI8FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECTI8(1);
2699 CONVERT_STR(VarUI8FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECTI8(2);
2700 }
2701
2702 static void test_VarUI8Copy(void)
2703 {
2704 HRESULT hres;
2705 VARIANTARG vSrc, vDst;
2706 ULONGLONG in = 1;
2707
2708 if (!has_i8)
2709 {
2710 win_skip("I8 and UI8 data types are not available\n");
2711 return;
2712 }
2713
2714 VariantInit(&vSrc);
2715 VariantInit(&vDst);
2716 V_VT(&vSrc) = VT_UI8;
2717 V_UI8(&vSrc) = in;
2718 hres = VariantCopy(&vDst, &vSrc);
2719 ok(hres == S_OK && V_VT(&vDst) == VT_UI8 && V_UI8(&vDst) == in,
2720 "copy hres 0x%X, type %d, value (%x%08x) %x%08x\n",
2721 hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_UI8(&vDst) >> 32), (UINT)V_UI8(&vDst) );
2722 V_VT(&vSrc) = VT_UI8|VT_BYREF;
2723 V_UI8REF(&vSrc) = &in;
2724 hres = VariantCopy(&vDst, &vSrc);
2725 ok(hres == S_OK && V_VT(&vDst) == (VT_UI8|VT_BYREF) && V_UI8REF(&vDst) == &in,
2726 "ref hres 0x%X, type %d, ref (%p) %p\n", hres, V_VT(&vDst), &in, V_UI8REF(&vDst));
2727 hres = VariantCopyInd(&vDst, &vSrc);
2728 ok(hres == S_OK && V_VT(&vDst) == VT_UI8 && V_UI8(&vDst) == in,
2729 "copy hres 0x%X, type %d, value (%x%08x) %x%08x\n",
2730 hres, V_VT(&vDst), (UINT)(in >> 32), (UINT)in, (UINT)(V_UI8(&vDst) >> 32), (UINT)V_UI8(&vDst) );
2731 }
2732
2733 static void test_VarUI8ChangeTypeEx(void)
2734 {
2735 HRESULT hres;
2736 ULONG64 in;
2737 VARIANTARG vSrc, vDst;
2738
2739 if (!has_i8)
2740 {
2741 win_skip("I8 and UI8 data types are not available\n");
2742 return;
2743 }
2744
2745 in = 1;
2746
2747 INITIAL_TYPETESTI8(VT_UI8, V_UI8);
2748 COMMON_TYPETEST;
2749 }
2750
2751 /*
2752 * VT_R4
2753 */
2754
2755 #undef CONV_TYPE
2756 #define CONV_TYPE float
2757 #undef EXPECTRES
2758 #define EXPECTRES(res, x) _EXPECTRES(res, x, "%15.15f")
2759
2760 static void test_VarR4FromI1(void)
2761 {
2762 CONVVARS(signed char);
2763 int i;
2764
2765 CHECKPTR(VarR4FromI1);
2766 CONVERTRANGE(VarR4FromI1, -128, 128);
2767 }
2768
2769 static void test_VarR4FromUI1(void)
2770 {
2771 CONVVARS(BYTE);
2772 int i;
2773
2774 CHECKPTR(VarR4FromUI1);
2775 CONVERTRANGE(VarR4FromUI1, 0, 256);
2776 }
2777
2778 static void test_VarR4FromI2(void)
2779 {
2780 CONVVARS(SHORT);
2781 int i;
2782
2783 CHECKPTR(VarR4FromI2);
2784 CONVERTRANGE(VarR4FromI2, -32768, 32768);
2785 }
2786
2787 static void test_VarR4FromUI2(void)
2788 {
2789 CONVVARS(USHORT);
2790 int i;
2791
2792 CHECKPTR(VarR4FromUI2);
2793 CONVERTRANGE(VarR4FromUI2, 0, 65536);
2794 }
2795
2796 static void test_VarR4FromI4(void)
2797 {
2798 CONVVARS(int);
2799
2800 CHECKPTR(VarR4FromI4);
2801 CONVERT(VarR4FromI4, -2147483647-1); EXPECT(-2147483648.0f);
2802 CONVERT(VarR4FromI4, -1); EXPECT(-1.0f);
2803 CONVERT(VarR4FromI4, 0); EXPECT(0.0f);
2804 CONVERT(VarR4FromI4, 1); EXPECT(1.0f);
2805 CONVERT(VarR4FromI4, 2147483647); EXPECT(2147483647.0f);
2806 }
2807
2808 static void test_VarR4FromUI4(void)
2809 {
2810 CONVVARS(unsigned int);
2811
2812 CHECKPTR(VarR4FromUI4);
2813 CONVERT(VarR4FromUI4, 0); EXPECT(0.0f);
2814 CONVERT(VarR4FromUI4, 1); EXPECT(1.0f);
2815 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
2816 CONVERT(VarR4FromUI4, 0xffffffff); EXPECT(4294967296.0f);
2817 #endif
2818 }
2819
2820 static void test_VarR4FromR8(void)
2821 {
2822 CONVVARS(FLOAT);
2823
2824 CHECKPTR(VarR4FromR8);
2825 CONVERT(VarR4FromR8, -1.0); EXPECT(-1.0f);
2826 CONVERT(VarR4FromR8, 0.0); EXPECT(0.0f);
2827 CONVERT(VarR4FromR8, 1.0); EXPECT(1.0f);
2828 CONVERT(VarR4FromR8, 1.5); EXPECT(1.5f);
2829
2830 /* Skip rounding tests - no rounding is done */
2831 }
2832
2833 static void test_VarR4FromBool(void)
2834 {
2835 CONVVARS(VARIANT_BOOL);
2836
2837 CHECKPTR(VarR4FromBool);
2838 CONVERT(VarR4FromBool, VARIANT_TRUE); EXPECT(VARIANT_TRUE * 1.0f);
2839 CONVERT(VarR4FromBool, VARIANT_FALSE); EXPECT(VARIANT_FALSE * 1.0f);
2840 }
2841
2842 static void test_VarR4FromCy(void)
2843 {
2844 CONVVARS(CY);
2845
2846 CHECKPTR(VarR4FromCy);
2847 CONVERT_CY(VarR4FromCy,-32768); EXPECT(-32768.0f);
2848 CONVERT_CY(VarR4FromCy,-1); EXPECT(-1.0f);
2849 CONVERT_CY(VarR4FromCy,0); EXPECT(0.0f);
2850 CONVERT_CY(VarR4FromCy,1); EXPECT(1.0f);
2851 CONVERT_CY(VarR4FromCy,32768); EXPECT(32768.0f);
2852
2853 CONVERT_CY(VarR4FromCy,-1.5); EXPECT(-1.5f);
2854 CONVERT_CY(VarR4FromCy,-0.6); EXPECT(-0.6f);
2855 CONVERT_CY(VarR4FromCy,-0.5); EXPECT(-0.5f);
2856 CONVERT_CY(VarR4FromCy,-0.4); EXPECT(-0.4f);
2857 CONVERT_CY(VarR4FromCy,0.4); EXPECT(0.4f);
2858 CONVERT_CY(VarR4FromCy,0.5); EXPECT(0.5f);
2859 CONVERT_CY(VarR4FromCy,0.6); EXPECT(0.6f);
2860 CONVERT_CY(VarR4FromCy,1.5); EXPECT(1.5f);
2861 }
2862
2863 static void test_VarR4FromI8(void)
2864 {
2865 CONVVARS(LONG64);
2866
2867 CHECKPTR(VarR4FromI8);
2868 CONVERT(VarR4FromI8, -1); EXPECT(-1.0f);
2869 CONVERT(VarR4FromI8, 0); EXPECT(0.0f);
2870 CONVERT(VarR4FromI8, 1); EXPECT(1.0f);
2871 }
2872
2873 static void test_VarR4FromUI8(void)
2874 {
2875 CONVVARS(ULONG64);
2876
2877 CHECKPTR(VarR4FromUI8);
2878 CONVERT(VarR4FromUI8, 0); EXPECT(0.0f);
2879 CONVERT(VarR4FromUI8, 1); EXPECT(1.0f);
2880 }
2881
2882 static void test_VarR4FromDec(void)
2883 {
2884 CONVVARS(DECIMAL);
2885
2886 CHECKPTR(VarR4FromDec);
2887
2888 CONVERT_BADDEC(VarR4FromDec);
2889
2890 CONVERT_DEC(VarR4FromDec,0,0x80,0,32768); EXPECT(-32768.0f);
2891 CONVERT_DEC(VarR4FromDec,0,0x80,0,1); EXPECT(-1.0f);
2892 CONVERT_DEC(VarR4FromDec,0,0,0,0); EXPECT(0.0f);
2893 CONVERT_DEC(VarR4FromDec,0,0,0,1); EXPECT(1.0f);
2894 CONVERT_DEC(VarR4FromDec,0,0,0,32767); EXPECT(32767.0f);
2895
2896 CONVERT_DEC(VarR4FromDec,2,0x80,0,3276800); EXPECT(-32768.0f);
2897 CONVERT_DEC(VarR4FromDec,2,0,0,3276700); EXPECT(32767.0f);
2898 CONVERT_DEC(VarR4FromDec,10,0,0,3276700); EXPECT(0.00032767f);
2899
2900 CONVERT_DEC(VarR4FromDec,0,0,1,0); EXPECT(18446744073709551616.0f);
2901 }
2902
2903 static void test_VarR4FromDate(void)
2904 {
2905 CONVVARS(DATE);
2906
2907 CHECKPTR(VarR4FromDate);
2908 CONVERT(VarR4FromDate, -1.0); EXPECT(-1.0f);
2909 CONVERT(VarR4FromDate, 0.0); EXPECT(0.0f);
2910 CONVERT(VarR4FromDate, 1.0); EXPECT(1.0f);
2911 }
2912
2913 static void test_VarR4FromStr(void)
2914 {
2915 CONVVARS(LCID);
2916 OLECHAR buff[128];
2917
2918 in = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
2919
2920 CHECKPTR(VarR4FromStr);
2921
2922 CONVERT_STR(VarR4FromStr,NULL,0); EXPECT_MISMATCH;
2923 CONVERT_STR(VarR4FromStr,"-1", 0); EXPECT(-1.0f);
2924 CONVERT_STR(VarR4FromStr,"0", 0); EXPECT(0.0f);
2925 CONVERT_STR(VarR4FromStr,"1", 0); EXPECT(1.0f);
2926
2927 CONVERT_STR(VarR4FromStr,"-1.5",LOCALE_NOUSEROVERRIDE); EXPECT(-1.5f);
2928 CONVERT_STR(VarR4FromStr,"-0.6",LOCALE_NOUSEROVERRIDE); EXPECT(-0.6f);
2929 CONVERT_STR(VarR4FromStr,"-0.5",LOCALE_NOUSEROVERRIDE); EXPECT(-0.5f);
2930 CONVERT_STR(VarR4FromStr,"-0.4",LOCALE_NOUSEROVERRIDE); EXPECT(-0.4f);
2931 CONVERT_STR(VarR4FromStr,"0.4",LOCALE_NOUSEROVERRIDE); EXPECT(0.4f);
2932 CONVERT_STR(VarR4FromStr,"0.5",LOCALE_NOUSEROVERRIDE); EXPECT(0.5f);
2933 CONVERT_STR(VarR4FromStr,"0.6",LOCALE_NOUSEROVERRIDE); EXPECT(0.6f);
2934 CONVERT_STR(VarR4FromStr,"1.5",LOCALE_NOUSEROVERRIDE); EXPECT(1.5f);
2935 }
2936
2937 static void test_VarR4Copy(void)
2938 {
2939 COPYTEST(77665544.0f, VT_R4, V_R4(&vSrc), V_R4(&vDst), V_R4REF(&vSrc),V_R4REF(&vDst), "%15.15f");
2940 }
2941
2942 static void test_VarR4ChangeTypeEx(void)
2943 {
2944 #ifdef HAS_UINT64_TO_FLOAT
2945 HRESULT hres;
2946 float in;
2947 VARIANTARG vSrc, vDst;
2948
2949 in = 1.0f;
2950
2951 INITIAL_TYPETEST(VT_R4, V_R4, "%f");
2952 COMMON_TYPETEST;
2953 #endif
2954 }
2955
2956 /*
2957 * VT_R8
2958 */
2959
2960 #undef CONV_TYPE
2961 #define CONV_TYPE double
2962
2963 static void test_VarR8FromI1(void)
2964 {
2965 CONVVARS(signed char);
2966 int i;
2967
2968 CHECKPTR(VarR8FromI1);
2969 CONVERTRANGE(VarR8FromI1, -128, 128);
2970 }
2971
2972 static void test_VarR8FromUI1(void)
2973 {
2974 CONVVARS(BYTE);
2975 int i;
2976
2977 CHECKPTR(VarR8FromUI1);
2978 CONVERTRANGE(VarR8FromUI1, 0, 256);
2979 }
2980
2981 static void test_VarR8FromI2(void)
2982 {
2983 CONVVARS(SHORT);
2984 int i;
2985
2986 CHECKPTR(VarR8FromI2);
2987 CONVERTRANGE(VarR8FromI2, -32768, 32768);
2988 }
2989
2990 static void test_VarR8FromUI2(void)
2991 {
2992 CONVVARS(USHORT);
2993 int i;
2994
2995 CHECKPTR(VarR8FromUI2);
2996 CONVERTRANGE(VarR8FromUI2, 0, 65536);
2997 }
2998
2999 static void test_VarR8FromI4(void)
3000 {
3001 CONVVARS(int);
3002
3003 CHECKPTR(VarR8FromI4);
3004 CONVERT(VarR8FromI4, -2147483647-1); EXPECT(-2147483648.0);
3005 CONVERT(VarR8FromI4, -1); EXPECT(-1.0);
3006 CONVERT(VarR8FromI4, 0); EXPECT(0.0);
3007 CONVERT(VarR8FromI4, 1); EXPECT(1.0);
3008 CONVERT(VarR8FromI4, 0x7fffffff); EXPECT(2147483647.0);
3009 }
3010
3011 static void test_VarR8FromUI4(void)
3012 {
3013 CONVVARS(unsigned int);
3014
3015 CHECKPTR(VarR8FromUI4);
3016 CONVERT(VarR8FromUI4, 0); EXPECT(0.0);
3017 CONVERT(VarR8FromUI4, 1); EXPECT(1.0);
3018 CONVERT(VarR8FromUI4, 0xffffffff); EXPECT(4294967295.0);
3019 }
3020
3021 static void test_VarR8FromR4(void)
3022 {
3023 CONVVARS(FLOAT);
3024
3025 CHECKPTR(VarR8FromR4);
3026 CONVERT(VarR8FromR4, -1.0f); EXPECT(-1.0);
3027 CONVERT(VarR8FromR4, 0.0f); EXPECT(0.0);
3028 CONVERT(VarR8FromR4, 1.0f); EXPECT(1.0);
3029 CONVERT(VarR8FromR4, 1.5f); EXPECT(1.5);
3030
3031 /* Skip rounding tests - no rounding is done */
3032 }
3033
3034 static void test_VarR8FromBool(void)
3035 {
3036 CONVVARS(VARIANT_BOOL);
3037
3038 CHECKPTR(VarR8FromBool);
3039 CONVERT(VarR8FromBool, VARIANT_TRUE); EXPECT(VARIANT_TRUE * 1.0);
3040 CONVERT(VarR8FromBool, VARIANT_FALSE); EXPECT(VARIANT_FALSE * 1.0);
3041 }
3042
3043 static void test_VarR8FromCy(void)
3044 {
3045 CONVVARS(CY);
3046
3047 CHECKPTR(VarR8FromCy);
3048 CONVERT_CY(VarR8FromCy,-32769); EXPECT(-32769.0);
3049 CONVERT_CY(VarR8FromCy,-32768); EXPECT(-32768.0);
3050 CONVERT_CY(VarR8FromCy,-1); EXPECT(-1.0);
3051 CONVERT_CY(VarR8FromCy,0); EXPECT(0.0);
3052 CONVERT_CY(VarR8FromCy,1); EXPECT(1.0);
3053 CONVERT_CY(VarR8FromCy,32767); EXPECT(32767.0);
3054 CONVERT_CY(VarR8FromCy,32768); EXPECT(32768.0);
3055
3056 CONVERT_CY(VarR8FromCy,-1.5); EXPECT(-1.5);
3057 CONVERT_CY(VarR8FromCy,-0.6); EXPECT(-0.6);
3058 CONVERT_CY(VarR8FromCy,-0.5); EXPECT(-0.5);
3059 CONVERT_CY(VarR8FromCy,-0.4); EXPECT(-0.4);
3060 CONVERT_CY(VarR8FromCy,0.4); EXPECT(0.4);
3061 CONVERT_CY(VarR8FromCy,0.5); EXPECT(0.5);
3062 CONVERT_CY(VarR8FromCy,0.6); EXPECT(0.6);
3063 CONVERT_CY(VarR8FromCy,1.5); EXPECT(1.5);
3064 }
3065
3066 static void test_VarR8FromI8(void)
3067 {
3068 CONVVARS(LONG64);
3069
3070 CHECKPTR(VarR8FromI8);
3071 CONVERT(VarR8FromI8, -1); EXPECT(-1.0);
3072 CONVERT(VarR8FromI8, 0); EXPECT(0.0);
3073 CONVERT(VarR8FromI8, 1); EXPECT(1.0);
3074 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3075 CONVERT_I8(VarR8FromI8, 0x7fffffff,0xffffffff); EXPECT(9223372036854775808.0);
3076 #endif
3077 }
3078
3079 static void test_VarR8FromUI8(void)
3080 {
3081 CONVVARS(ULONG64);
3082
3083 CHECKPTR(VarR8FromUI8);
3084 CONVERT(VarR8FromUI8, 0); EXPECT(0.0);
3085 CONVERT(VarR8FromUI8, 1); EXPECT(1.0);
3086 #if defined(__i386__) && (defined(_MSC_VER) || defined(__GNUC__))
3087 CONVERT_I8(VarR8FromUI8, 0x80000000,0); EXPECT(9223372036854775808.0);
3088 #endif
3089 }
3090
3091 static void test_VarR8FromDec(void)
3092 {
3093 CONVVARS(DECIMAL);
3094
3095 CHECKPTR(VarR8FromDec);
3096
3097 CONVERT_BADDEC(VarR8FromDec);
3098
3099 CONVERT_DEC(VarR8FromDec,0,0x80,0,32768); EXPECT(-32768.0);
3100 CONVERT_DEC(VarR8FromDec,0,0x80,0,1); EXPECT(-1.0);
3101 CONVERT_DEC(VarR8FromDec,0,0,0,0); EXPECT(0.0);
3102 CONVERT_DEC(VarR8FromDec,0,0,0,1); EXPECT(1.0);
3103 CONVERT_DEC(VarR8FromDec,0,0,0,32767); EXPECT(32767.0);
3104
3105 CONVERT_DEC(VarR8FromDec,2,0x80,0,3276800); EXPECT(-32768.0);
3106 CONVERT_DEC(VarR8FromDec,2,0,0,3276700); EXPECT(32767.0);
3107
3108 CONVERT_DEC(VarR8FromDec,0,0,1,0); EXPECT(18446744073709551616.0);
3109 }
3110
3111 static void test_VarR8FromDate(void)
3112 {
3113