Add AppDefaults app selection to control panel
[wine/gsoc-2012-control.git] / dlls / oleaut32 / tests / vartest.c
blob1ac09cd4ae3ee30df4ea2ac9e8276f2c2607d9f9
1 /*
2 * VARIANT test program
4 * Copyright 1998 Jean-Claude Cote
5 * Copyright 2006 Google (Benjamin Arai)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include <math.h>
25 #include <float.h>
27 #define CONST_VTABLE
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winsock.h"
32 #include "wine/test.h"
33 #include "winuser.h"
34 #include "wingdi.h"
35 #include "winnls.h"
36 #include "winerror.h"
37 #include "winnt.h"
39 #include "wtypes.h"
40 #include "oleauto.h"
42 static HMODULE hOleaut32;
44 static HRESULT (WINAPI *pVarUdateFromDate)(DATE,ULONG,UDATE*);
45 static HRESULT (WINAPI *pVarDateFromUdate)(UDATE*,ULONG,DATE*);
46 static INT (WINAPI *pSystemTimeToVariantTime)(LPSYSTEMTIME,double*);
47 static INT (WINAPI *pVariantTimeToSystemTime)(double,LPSYSTEMTIME);
48 static INT (WINAPI *pDosDateTimeToVariantTime)(USHORT,USHORT,double*);
49 static INT (WINAPI *pVariantTimeToDosDateTime)(double,USHORT*,USHORT *);
51 static const WCHAR sz12[] = {'1','2','\0'};
52 /* the strings are localized */
53 static WCHAR sz12_false[32];
54 static WCHAR sz12_true[32];
56 /* Get a conversion function ptr, return if function not available */
57 #define CHECKPTR(func) p##func = (void*)GetProcAddress(hOleaut32, #func); \
58 if (!p##func) { win_skip("function " # func " not available, not testing it\n"); return; }
60 /* Have IRecordInfo data type? */
61 static int HAVE_OLEAUT32_RECORD = 0;
62 /* Have I8/UI8 data type? */
63 static int HAVE_OLEAUT32_I8 = 0;
64 /* Is this an ancient version with support for only I2/I4/R4/R8/DATE? */
65 static int IS_ANCIENT = 0;
67 /* When comparing floating point values we cannot expect an exact match
68 * because the rounding errors depend on the exact algorithm.
70 #define EQ_DOUBLE(a,b) (fabs((a)-(b)) / (1.0+fabs(a)+fabs(b)) < 1e-14)
71 #define EQ_FLOAT(a,b) (fabs((a)-(b)) / (1.0+fabs(a)+fabs(b)) < 1e-7)
73 #define SKIPTESTS(a) if((a > VT_CLSID+10) && (a < VT_BSTR_BLOB-10)) continue
75 /* Allow our test macros to work for VT_NULL and VT_EMPTY too */
76 #define V_EMPTY(v) V_I4(v)
77 #define V_NULL(v) V_I4(v)
79 /* Size constraints for overflow tests */
80 #define I1_MAX 0x7f
81 #define I1_MIN ((-I1_MAX)-1)
82 #define UI1_MAX 0xff
83 #define UI1_MIN 0
84 #define I2_MAX 0x7fff
85 #define I2_MIN ((-I2_MAX)-1)
86 #define UI2_MAX 0xffff
87 #define UI2_MIN 0
88 #define I4_MAX 0x7fffffff
89 #define I4_MIN ((-I4_MAX)-1)
90 #define UI4_MAX 0xffffffff
91 #define UI4_MIN 0
92 #define I8_MAX (((LONGLONG)I4_MAX << 32) | UI4_MAX)
93 #define I8_MIN ((-I8_MAX)-1)
94 #define UI8_MAX (((ULONGLONG)UI4_MAX << 32) | UI4_MAX)
95 #define UI8_MIN 0
96 #define DATE_MAX 2958465
97 #define DATE_MIN -657434
98 #define R4_MAX FLT_MAX
99 #define R4_MIN FLT_MIN
100 #define R8_MAX DBL_MAX
101 #define R8_MIN DBL_MIN
103 static void init(void)
105 BSTR bstr;
106 HRESULT res;
108 res = VarBstrFromBool(VARIANT_TRUE, LANG_USER_DEFAULT, VAR_LOCALBOOL, &bstr);
109 ok(res == S_OK && (lstrlenW(bstr) > 0),
110 "Expected localized string for 'True'\n");
111 /* lstrcpyW / lstrcatW do not work on win95 */
112 memcpy(sz12_true, sz12, sizeof(sz12));
113 if (bstr) memcpy(&sz12_true[2], bstr, SysStringByteLen(bstr) + sizeof(WCHAR));
114 SysFreeString(bstr);
116 res = VarBstrFromBool(VARIANT_FALSE, LANG_USER_DEFAULT, VAR_LOCALBOOL, &bstr);
117 ok(res == S_OK && (lstrlenW(bstr) > 0),
118 "Expected localized string for 'False'\n");
119 memcpy(sz12_false, sz12, sizeof(sz12));
120 if (bstr) memcpy(&sz12_false[2], bstr, SysStringByteLen(bstr) + sizeof(WCHAR));
121 SysFreeString(bstr);
123 hOleaut32 = GetModuleHandle("oleaut32.dll");
125 /* Is a given function exported from oleaut32? */
126 #define HAVE_FUNC(func) ((void*)GetProcAddress(hOleaut32, #func) != NULL)
128 HAVE_OLEAUT32_I8 = HAVE_FUNC(VarI8FromI1);
129 if (!HAVE_OLEAUT32_I8)
130 skip("No support for I8 and UI8 data types\n");
132 HAVE_OLEAUT32_RECORD = HAVE_FUNC(SafeArraySetRecordInfo);
133 IS_ANCIENT = (!HAVE_FUNC(VarI1FromI2));
135 #undef HAVE_FUNC
138 /* Functions to set a DECIMAL */
139 static void setdec(DECIMAL* dec, BYTE scl, BYTE sgn, ULONG hi32, ULONG64 lo64)
141 S(U(*dec)).scale = scl;
142 S(U(*dec)).sign = sgn;
143 dec->Hi32 = hi32;
144 U1(*dec).Lo64 = lo64;
147 static void setdec64(DECIMAL* dec, BYTE scl, BYTE sgn, ULONG hi32, ULONG mid32, ULONG lo32)
149 S(U(*dec)).scale = scl;
150 S(U(*dec)).sign = sgn;
151 dec->Hi32 = hi32;
152 S1(U1(*dec)).Mid32 = mid32;
153 S1(U1(*dec)).Lo32 = lo32;
156 static inline int strcmpW( const WCHAR *str1, const WCHAR *str2 )
158 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
159 return *str1 - *str2;
162 /* return the string text of a given variant type */
163 static char vtstr_buffer[16][256];
164 static int vtstr_current=0;
165 static const char *vtstr(int x)
167 switch(x) {
168 #define CASE(vt) case VT_##vt: return #vt
169 CASE(EMPTY);
170 CASE(NULL);
171 CASE(I2);
172 CASE(I4);
173 CASE(R4);
174 CASE(R8);
175 CASE(CY);
176 CASE(DATE);
177 CASE(BSTR);
178 CASE(DISPATCH);
179 CASE(ERROR);
180 CASE(BOOL);
181 CASE(VARIANT);
182 CASE(UNKNOWN);
183 CASE(DECIMAL);
184 CASE(I1);
185 CASE(UI1);
186 CASE(UI2);
187 CASE(UI4);
188 CASE(I8);
189 CASE(UI8);
190 CASE(INT);
191 CASE(UINT);
192 CASE(VOID);
193 CASE(HRESULT);
194 CASE(PTR);
195 CASE(SAFEARRAY);
196 CASE(CARRAY);
197 CASE(USERDEFINED);
198 CASE(LPSTR);
199 CASE(LPWSTR);
200 CASE(RECORD);
201 CASE(INT_PTR);
202 CASE(UINT_PTR);
203 CASE(FILETIME);
204 CASE(BLOB);
205 CASE(STREAM);
206 CASE(STORAGE);
207 CASE(STREAMED_OBJECT);
208 CASE(STORED_OBJECT);
209 CASE(BLOB_OBJECT);
210 CASE(CF);
211 CASE(CLSID);
212 CASE(VERSIONED_STREAM);
213 CASE(VECTOR);
214 CASE(ARRAY);
215 CASE(BYREF);
216 CASE(RESERVED);
217 CASE(ILLEGAL);
218 #undef CASE
220 case 0xfff:
221 return "VT_BSTR_BLOB/VT_ILLEGALMASKED/VT_TYPEMASK";
223 default:
224 vtstr_current %= sizeof(vtstr_buffer)/sizeof(*vtstr_buffer);
225 sprintf(vtstr_buffer[vtstr_current], "unknown variant type %d", x);
226 return vtstr_buffer[vtstr_current++];
230 static const char *variantstr( const VARIANT *var )
232 vtstr_current %= sizeof(vtstr_buffer)/sizeof(*vtstr_buffer);
233 switch(V_VT(var))
235 case VT_I1:
236 sprintf( vtstr_buffer[vtstr_current], "VT_I1(%d)", V_I1(var) ); break;
237 case VT_I2:
238 sprintf( vtstr_buffer[vtstr_current], "VT_I2(%d)", V_I2(var) ); break;
239 case VT_I4:
240 sprintf( vtstr_buffer[vtstr_current], "VT_I4(%d)", V_I4(var) ); break;
241 case VT_INT:
242 sprintf( vtstr_buffer[vtstr_current], "VT_INT(%d)", V_INT(var) ); break;
243 case VT_I8:
244 sprintf( vtstr_buffer[vtstr_current], "VT_I8(%x%08x)", (UINT)(V_I8(var) >> 32), (UINT)V_I8(var) ); break;
245 case VT_UI8:
246 sprintf( vtstr_buffer[vtstr_current], "VT_UI8(%x%08x)", (UINT)(V_UI8(var) >> 32), (UINT)V_UI8(var) ); break;
247 case VT_R4:
248 sprintf( vtstr_buffer[vtstr_current], "VT_R4(%g)", V_R4(var) ); break;
249 case VT_R8:
250 sprintf( vtstr_buffer[vtstr_current], "VT_R8(%g)", V_R8(var) ); break;
251 case VT_UI1:
252 sprintf( vtstr_buffer[vtstr_current], "VT_UI1(%u)", V_UI1(var) ); break;
253 case VT_UI2:
254 sprintf( vtstr_buffer[vtstr_current], "VT_UI2(%u)", V_UI2(var) ); break;
255 case VT_UI4:
256 sprintf( vtstr_buffer[vtstr_current], "VT_UI4(%u)", V_UI4(var) ); break;
257 case VT_UINT:
258 sprintf( vtstr_buffer[vtstr_current], "VT_UINT(%d)", V_UINT(var) ); break;
259 case VT_CY:
260 sprintf( vtstr_buffer[vtstr_current], "VT_CY(%x%08x)", S(V_CY(var)).Hi, S(V_CY(var)).Lo ); break;
261 case VT_DATE:
262 sprintf( vtstr_buffer[vtstr_current], "VT_DATE(%g)", V_DATE(var) ); break;
263 default:
264 return vtstr(V_VT(var));
266 return vtstr_buffer[vtstr_current++];
269 static BOOL is_expected_variant( const VARIANT *result, const VARIANT *expected )
271 if (V_VT(result) != V_VT(expected)) return FALSE;
272 switch(V_VT(expected))
274 case VT_EMPTY:
275 case VT_NULL:
276 return TRUE;
278 #define CASE(vt) case VT_##vt: return (V_##vt(result) == V_##vt(expected))
279 CASE(BOOL);
280 CASE(I1);
281 CASE(UI1);
282 CASE(I2);
283 CASE(UI2);
284 CASE(I4);
285 CASE(UI4);
286 CASE(I8);
287 CASE(UI8);
288 CASE(INT);
289 CASE(UINT);
290 #undef CASE
292 case VT_DATE:
293 return EQ_FLOAT(V_DATE(result), V_DATE(expected));
294 case VT_R4:
295 return EQ_FLOAT(V_R4(result), V_R4(expected));
296 case VT_R8:
297 return EQ_FLOAT(V_R8(result), V_R8(expected));
298 case VT_CY:
299 return (V_CY(result).int64 == V_CY(expected).int64);
300 case VT_BSTR:
301 return !lstrcmpW( V_BSTR(result), V_BSTR(expected) );
302 case VT_DECIMAL:
303 return !memcmp( &V_DECIMAL(result), &V_DECIMAL(expected), sizeof(DECIMAL) );
304 default:
305 ok(0, "unhandled variant type %s\n",vtstr(V_VT(expected)));
306 return 0;
310 static void test_var_call1( int line, HRESULT (WINAPI *func)(LPVARIANT,LPVARIANT),
311 VARIANT *arg, VARIANT *expected )
313 VARIANT old_arg = *arg;
314 VARIANT result;
315 HRESULT hres;
317 memset( &result, 0, sizeof(result) );
318 hres = func( arg, &result );
319 ok_(__FILE__,line)( hres == S_OK, "wrong result %x\n", hres );
320 if (hres == S_OK)
321 ok_(__FILE__,line)( is_expected_variant( &result, expected ),
322 "got %s expected %s\n", variantstr(&result), variantstr(expected) );
323 ok_(__FILE__,line)( is_expected_variant( arg, &old_arg ), "Modified argument %s / %s\n",
324 variantstr(&old_arg), variantstr(arg));
325 VariantClear( &result );
328 static void test_var_call2( int line, HRESULT (WINAPI *func)(LPVARIANT,LPVARIANT,LPVARIANT),
329 VARIANT *left, VARIANT *right, VARIANT *expected )
331 VARIANT old_left = *left, old_right = *right;
332 VARIANT result;
333 HRESULT hres;
335 memset( &result, 0, sizeof(result) );
336 hres = func( left, right, &result );
337 ok_(__FILE__,line)( hres == S_OK, "wrong result %x\n", hres );
338 if (hres == S_OK)
339 ok_(__FILE__,line)( is_expected_variant( &result, expected ),
340 "got %s expected %s\n", variantstr(&result), variantstr(expected) );
341 ok_(__FILE__,line)( is_expected_variant( left, &old_left ), "Modified left argument %s / %s\n",
342 variantstr(&old_left), variantstr(left));
343 ok_(__FILE__,line)( is_expected_variant( right, &old_right ), "Modified right argument %s / %s\n",
344 variantstr(&old_right), variantstr(right));
345 VariantClear( &result );
348 static int strcmp_wa(const WCHAR *strw, const char *stra)
350 WCHAR buf[512];
351 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(buf[0]));
352 return lstrcmpW(strw, buf);
355 #define test_bstr_var(a,b) _test_bstr_var(__LINE__,a,b)
356 static void _test_bstr_var(unsigned line, const VARIANT *v, const char *str)
358 ok_(__FILE__,line)(V_VT(v) == VT_BSTR, "unexpected vt=%d\n", V_VT(v));
359 if(V_VT(v) == VT_BSTR)
360 ok(!strcmp_wa(V_BSTR(v), str), "v=%s, expected %s\n", wine_dbgstr_w(V_BSTR(v)), str);
363 static void test_VariantInit(void)
365 VARIANTARG v1, v2;
367 /* Test that VariantInit() only sets the type */
368 memset(&v1, -1, sizeof(v1));
369 v2 = v1;
370 V_VT(&v2) = VT_EMPTY;
371 VariantInit(&v1);
372 ok(!memcmp(&v1, &v2, sizeof(v1)), "VariantInit() set extra fields\n");
375 /* All possible combinations of extra V_VT() flags */
376 static const VARTYPE ExtraFlags[16] =
379 VT_VECTOR,
380 VT_ARRAY,
381 VT_BYREF,
382 VT_RESERVED,
383 VT_VECTOR|VT_ARRAY,
384 VT_VECTOR|VT_BYREF,
385 VT_VECTOR|VT_RESERVED,
386 VT_VECTOR|VT_ARRAY|VT_BYREF,
387 VT_VECTOR|VT_ARRAY|VT_RESERVED,
388 VT_VECTOR|VT_BYREF|VT_RESERVED,
389 VT_VECTOR|VT_ARRAY|VT_BYREF|VT_RESERVED,
390 VT_ARRAY|VT_BYREF,
391 VT_ARRAY|VT_RESERVED,
392 VT_ARRAY|VT_BYREF|VT_RESERVED,
393 VT_BYREF|VT_RESERVED,
396 /* Determine if a vt is valid for VariantClear() */
397 static int IsValidVariantClearVT(VARTYPE vt, VARTYPE extraFlags)
399 int ret = 0;
401 /* Only the following flags/types are valid */
402 if ((vt <= VT_LPWSTR || vt == VT_RECORD || vt == VT_CLSID) &&
403 vt != (VARTYPE)15 &&
404 (vt < (VARTYPE)24 || vt > (VARTYPE)31) &&
405 (!(extraFlags & (VT_BYREF|VT_ARRAY)) || vt > VT_NULL) &&
406 (extraFlags == 0 || extraFlags == VT_BYREF || extraFlags == VT_ARRAY ||
407 extraFlags == (VT_ARRAY|VT_BYREF)))
408 ret = 1; /* ok */
410 if ((vt == VT_RECORD && !HAVE_OLEAUT32_RECORD) ||
411 ((vt == VT_I8 || vt == VT_UI8) && !HAVE_OLEAUT32_I8))
412 ret = 0; /* Old versions of oleaut32 */
413 return ret;
416 typedef struct
418 IUnknown IUnknown_iface;
419 LONG ref;
420 LONG events;
421 } test_VariantClearImpl;
423 static inline test_VariantClearImpl *impl_from_IUnknown(IUnknown *iface)
425 return CONTAINING_RECORD(iface, test_VariantClearImpl, IUnknown_iface);
428 static HRESULT WINAPI VC_QueryInterface(LPUNKNOWN iface,REFIID riid,LPVOID *ppobj)
430 test_VariantClearImpl *This = impl_from_IUnknown(iface);
431 This->events |= 0x1;
432 return E_NOINTERFACE;
435 static ULONG WINAPI VC_AddRef(LPUNKNOWN iface) {
436 test_VariantClearImpl *This = impl_from_IUnknown(iface);
437 This->events |= 0x2;
438 return InterlockedIncrement(&This->ref);
441 static ULONG WINAPI VC_Release(LPUNKNOWN iface) {
442 test_VariantClearImpl *This = impl_from_IUnknown(iface);
443 /* static class, won't be freed */
444 This->events |= 0x4;
445 return InterlockedDecrement(&This->ref);
448 static const IUnknownVtbl test_VariantClear_vtbl = {
449 VC_QueryInterface,
450 VC_AddRef,
451 VC_Release,
454 static test_VariantClearImpl test_myVariantClearImpl = {{&test_VariantClear_vtbl}, 1, 0};
456 static void test_VariantClear(void)
458 HRESULT hres;
459 VARIANTARG v;
460 VARIANT v2;
461 size_t i;
462 LONG i4;
463 IUnknown *punk;
465 /* Crashes: Native does not test input for NULL, so neither does Wine */
466 if (0)
467 VariantClear(NULL);
469 /* Only the type field is set, to VT_EMPTY */
470 V_VT(&v) = VT_UI4;
471 V_UI4(&v) = ~0u;
472 hres = VariantClear(&v);
473 ok((hres == S_OK && V_VT(&v) == VT_EMPTY) ||
474 (IS_ANCIENT && hres == DISP_E_BADVARTYPE && V_VT(&v) == VT_UI4),
475 "VariantClear: Type set to %d, res %08x\n", V_VT(&v), hres);
476 ok(V_UI4(&v) == ~0u, "VariantClear: Overwrote value\n");
478 /* Test all possible V_VT values.
479 * Also demonstrates that null pointers in 'v' are not dereferenced.
480 * Individual variant tests should test VariantClear() with non-NULL values.
482 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
484 VARTYPE vt;
486 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
488 HRESULT hExpected = DISP_E_BADVARTYPE;
490 SKIPTESTS(vt);
492 memset(&v, 0, sizeof(v));
493 V_VT(&v) = vt | ExtraFlags[i];
495 hres = VariantClear(&v);
497 if (IsValidVariantClearVT(vt, ExtraFlags[i]))
498 hExpected = S_OK;
500 ok(hres == hExpected, "VariantClear: expected 0x%X, got 0x%X for vt %d | 0x%X\n",
501 hExpected, hres, vt, ExtraFlags[i]);
505 /* Some BYREF tests with non-NULL ptrs */
507 /* VARIANT BYREF */
508 V_VT(&v2) = VT_I4;
509 V_I4(&v2) = 0x1234;
510 V_VT(&v) = VT_VARIANT | VT_BYREF;
511 V_VARIANTREF(&v) = &v2;
513 hres = VariantClear(&v);
514 ok(hres == S_OK, "ret %08x\n", hres);
515 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
516 ok(V_VARIANTREF(&v) == &v2, "variant ref %p\n", V_VARIANTREF(&v2));
517 ok(V_VT(&v2) == VT_I4, "vt %04x\n", V_VT(&v2));
518 ok(V_I4(&v2) == 0x1234, "i4 %04x\n", V_I4(&v2));
520 /* I4 BYREF */
521 i4 = 0x4321;
522 V_VT(&v) = VT_I4 | VT_BYREF;
523 V_I4REF(&v) = &i4;
525 hres = VariantClear(&v);
526 ok(hres == S_OK, "ret %08x\n", hres);
527 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
528 ok(V_I4REF(&v) == &i4, "i4 ref %p\n", V_I4REF(&v2));
529 ok(i4 == 0x4321, "i4 changed %08x\n", i4);
532 /* UNKNOWN */
533 V_VT(&v) = VT_UNKNOWN;
534 V_UNKNOWN(&v) = &test_myVariantClearImpl.IUnknown_iface;
535 test_myVariantClearImpl.events = 0;
536 hres = VariantClear(&v);
537 ok(hres == S_OK, "ret %08x\n", hres);
538 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
539 ok(V_UNKNOWN(&v) == &test_myVariantClearImpl.IUnknown_iface, "unknown %p\n", V_UNKNOWN(&v));
540 /* Check that Release got called, but nothing else */
541 ok(test_myVariantClearImpl.events == 0x4, "Unexpected call. events %08x\n", test_myVariantClearImpl.events);
543 /* UNKNOWN BYREF */
544 punk = &test_myVariantClearImpl.IUnknown_iface;
545 V_VT(&v) = VT_UNKNOWN | VT_BYREF;
546 V_UNKNOWNREF(&v) = &punk;
547 test_myVariantClearImpl.events = 0;
548 hres = VariantClear(&v);
549 ok(hres == S_OK, "ret %08x\n", hres);
550 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
551 ok(V_UNKNOWNREF(&v) == &punk, "unknown ref %p\n", V_UNKNOWNREF(&v));
552 /* Check that nothing got called */
553 ok(test_myVariantClearImpl.events == 0, "Unexpected call. events %08x\n", test_myVariantClearImpl.events);
555 /* DISPATCH */
556 V_VT(&v) = VT_DISPATCH;
557 V_DISPATCH(&v) = (IDispatch*)&test_myVariantClearImpl;
558 test_myVariantClearImpl.events = 0;
559 hres = VariantClear(&v);
560 ok(hres == S_OK, "ret %08x\n", hres);
561 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
562 ok(V_DISPATCH(&v) == (IDispatch*)&test_myVariantClearImpl, "dispatch %p\n", V_DISPATCH(&v));
563 /* Check that Release got called, but nothing else */
564 ok(test_myVariantClearImpl.events == 0x4, "Unexpected call. events %08x\n", test_myVariantClearImpl.events);
566 /* DISPATCH BYREF */
567 punk = &test_myVariantClearImpl.IUnknown_iface;
568 V_VT(&v) = VT_DISPATCH | VT_BYREF;
569 V_DISPATCHREF(&v) = (IDispatch**)&punk;
570 test_myVariantClearImpl.events = 0;
571 hres = VariantClear(&v);
572 ok(hres == S_OK, "ret %08x\n", hres);
573 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
574 ok(V_DISPATCHREF(&v) == (IDispatch**)&punk, "dispatch ref %p\n", V_DISPATCHREF(&v));
575 /* Check that nothing got called */
576 ok(test_myVariantClearImpl.events == 0, "Unexpected call. events %08x\n", test_myVariantClearImpl.events);
579 static void test_VariantCopy(void)
581 VARIANTARG vSrc, vDst;
582 VARTYPE vt;
583 size_t i;
584 HRESULT hres, hExpected;
586 /* Establish that the failure/other cases are dealt with. Individual tests
587 * for each type should verify that data is copied correctly, references
588 * are updated, etc.
591 /* vSrc == vDst */
592 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
594 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
596 SKIPTESTS(vt);
598 memset(&vSrc, 0, sizeof(vSrc));
599 V_VT(&vSrc) = vt | ExtraFlags[i];
601 hExpected = DISP_E_BADVARTYPE;
602 /* src is allowed to be a VT_CLSID */
603 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
604 hExpected = S_OK;
606 hres = VariantCopy(&vSrc, &vSrc);
608 ok(hres == hExpected,
609 "Copy(src==dst): expected 0x%X, got 0x%X for src==dest vt %d|0x%X\n",
610 hExpected, hres, vt, ExtraFlags[i]);
614 /* Test that if VariantClear() fails on dest, the function fails. This also
615 * shows that dest is in fact cleared and not just overwritten
617 memset(&vSrc, 0, sizeof(vSrc));
618 V_VT(&vSrc) = VT_UI1;
620 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
622 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
624 SKIPTESTS(vt);
626 hExpected = DISP_E_BADVARTYPE;
628 memset(&vDst, 0, sizeof(vDst));
629 V_VT(&vDst) = vt | ExtraFlags[i];
631 if (IsValidVariantClearVT(vt, ExtraFlags[i]))
632 hExpected = S_OK;
634 hres = VariantCopy(&vDst, &vSrc);
636 ok(hres == hExpected,
637 "Copy(bad dst): expected 0x%X, got 0x%X for dest vt %d|0x%X\n",
638 hExpected, hres, vt, ExtraFlags[i]);
639 if (hres == S_OK)
640 ok(V_VT(&vDst) == VT_UI1,
641 "Copy(bad dst): expected vt = VT_UI1, got %d\n", V_VT(&vDst));
645 /* Test that VariantClear() checks vSrc for validity before copying */
646 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
648 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
650 SKIPTESTS(vt);
652 hExpected = DISP_E_BADVARTYPE;
654 memset(&vDst, 0, sizeof(vDst));
655 V_VT(&vDst) = VT_EMPTY;
657 memset(&vSrc, 0, sizeof(vSrc));
658 V_VT(&vSrc) = vt | ExtraFlags[i];
660 /* src is allowed to be a VT_CLSID */
661 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
662 hExpected = S_OK;
664 hres = VariantCopy(&vDst, &vSrc);
666 ok(hres == hExpected,
667 "Copy(bad src): expected 0x%X, got 0x%X for src vt %d|0x%X\n",
668 hExpected, hres, vt, ExtraFlags[i]);
669 if (hres == S_OK)
671 ok(V_VT(&vDst) == (vt|ExtraFlags[i]),
672 "Copy(bad src): expected vt = %d, got %d\n",
673 vt | ExtraFlags[i], V_VT(&vDst));
674 VariantClear(&vDst);
679 /* Test that copying a NULL BSTR results in an empty BSTR */
680 memset(&vDst, 0, sizeof(vDst));
681 V_VT(&vDst) = VT_EMPTY;
682 memset(&vSrc, 0, sizeof(vSrc));
683 V_VT(&vSrc) = VT_BSTR;
684 hres = VariantCopy(&vDst, &vSrc);
685 ok(hres == S_OK, "Copy(NULL BSTR): Failed to copy a NULL BSTR\n");
686 if (hres == S_OK)
688 ok((V_VT(&vDst) == VT_BSTR) && V_BSTR(&vDst),
689 "Copy(NULL BSTR): should have non-NULL result\n");
690 if ((V_VT(&vDst) == VT_BSTR) && V_BSTR(&vDst))
692 ok(*V_BSTR(&vDst) == 0, "Copy(NULL BSTR): result not empty\n");
694 VariantClear(&vDst);
698 /* Determine if a vt is valid for VariantCopyInd() */
699 static int IsValidVariantCopyIndVT(VARTYPE vt, VARTYPE extraFlags)
701 int ret = 0;
703 if ((extraFlags & VT_ARRAY) ||
704 (vt > VT_NULL && vt != (VARTYPE)15 && vt < VT_VOID &&
705 !(extraFlags & (VT_VECTOR|VT_RESERVED))))
707 ret = 1; /* ok */
709 return ret;
712 static void test_VariantCopyInd(void)
714 VARIANTARG vSrc, vDst, vRef, vRef2;
715 VARTYPE vt;
716 size_t i;
717 BYTE buffer[64];
718 HRESULT hres, hExpected;
720 memset(buffer, 0, sizeof(buffer));
722 /* vSrc == vDst */
723 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
725 if (ExtraFlags[i] & VT_ARRAY)
726 continue; /* Native crashes on NULL safearray */
728 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
730 SKIPTESTS(vt);
732 memset(&vSrc, 0, sizeof(vSrc));
733 V_VT(&vSrc) = vt | ExtraFlags[i];
735 hExpected = DISP_E_BADVARTYPE;
736 if (!(ExtraFlags[i] & VT_BYREF))
738 /* if src is not by-reference, acts as VariantCopy() */
739 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
740 hExpected = S_OK;
742 else
744 if (vt == VT_SAFEARRAY || vt == VT_BSTR || vt == VT_UNKNOWN ||
745 vt == VT_DISPATCH || vt == VT_RECORD)
746 continue; /* Need valid ptrs for deep copies */
748 V_BYREF(&vSrc) = &buffer;
749 hExpected = E_INVALIDARG;
751 if ((vt == VT_I8 || vt == VT_UI8) &&
752 ExtraFlags[i] == VT_BYREF)
754 if (HAVE_OLEAUT32_I8)
755 hExpected = S_OK; /* Only valid if I8 is a known type */
757 else if (IsValidVariantCopyIndVT(vt, ExtraFlags[i]))
758 hExpected = S_OK;
761 hres = VariantCopyInd(&vSrc, &vSrc);
763 ok(hres == hExpected,
764 "CopyInd(src==dst): expected 0x%X, got 0x%X for src==dst vt %d|0x%X\n",
765 hExpected, hres, vt, ExtraFlags[i]);
769 /* Bad dest */
770 memset(&vSrc, 0, sizeof(vSrc));
771 V_VT(&vSrc) = VT_UI1|VT_BYREF;
772 V_BYREF(&vSrc) = &buffer;
774 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
776 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
778 SKIPTESTS(vt);
780 memset(&vDst, 0, sizeof(vDst));
781 V_VT(&vDst) = vt | ExtraFlags[i];
783 hExpected = DISP_E_BADVARTYPE;
785 if (IsValidVariantClearVT(vt, ExtraFlags[i]))
786 hExpected = S_OK;
788 hres = VariantCopyInd(&vDst, &vSrc);
790 ok(hres == hExpected,
791 "CopyInd(bad dst): expected 0x%X, got 0x%X for dst vt %d|0x%X\n",
792 hExpected, hres, vt, ExtraFlags[i]);
793 if (hres == S_OK)
794 ok(V_VT(&vDst) == VT_UI1,
795 "CopyInd(bad dst): expected vt = VT_UI1, got %d\n", V_VT(&vDst));
799 /* bad src */
800 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
802 if (ExtraFlags[i] & VT_ARRAY)
803 continue; /* Native crashes on NULL safearray */
805 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
807 SKIPTESTS(vt);
809 memset(&vDst, 0, sizeof(vDst));
810 V_VT(&vDst) = VT_EMPTY;
812 memset(&vSrc, 0, sizeof(vSrc));
813 V_VT(&vSrc) = vt | ExtraFlags[i];
815 hExpected = DISP_E_BADVARTYPE;
816 if (!(ExtraFlags[i] & VT_BYREF))
818 /* if src is not by-reference, acts as VariantCopy() */
819 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
820 hExpected = S_OK;
822 else
824 if (vt == VT_SAFEARRAY || vt == VT_BSTR || vt == VT_UNKNOWN ||
825 vt == VT_DISPATCH || vt == VT_RECORD)
826 continue; /* Need valid ptrs for deep copies, see vartype.c */
828 V_BYREF(&vSrc) = &buffer;
830 hExpected = E_INVALIDARG;
832 if ((vt == VT_I8 || vt == VT_UI8) &&
833 ExtraFlags[i] == VT_BYREF)
835 if (HAVE_OLEAUT32_I8)
836 hExpected = S_OK; /* Only valid if I8 is a known type */
838 else if (IsValidVariantCopyIndVT(vt, ExtraFlags[i]))
839 hExpected = S_OK;
842 hres = VariantCopyInd(&vDst, &vSrc);
844 ok(hres == hExpected,
845 "CopyInd(bad src): expected 0x%X, got 0x%X for src vt %d|0x%X\n",
846 hExpected, hres, vt, ExtraFlags[i]);
847 if (hres == S_OK)
849 if (vt == VT_VARIANT && ExtraFlags[i] == VT_BYREF)
851 /* Type of vDst should be the type of the referenced variant.
852 * Since we set the buffer to all zeros, its type should be
853 * VT_EMPTY.
855 ok(V_VT(&vDst) == VT_EMPTY,
856 "CopyInd(bad src): expected dst vt = VT_EMPTY, got %d|0x%X\n",
857 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK);
859 else
861 ok(V_VT(&vDst) == (vt|(ExtraFlags[i] & ~VT_BYREF)),
862 "CopyInd(bad src): expected dst vt = %d|0x%X, got %d|0x%X\n",
863 vt, ExtraFlags[i] & ~VT_BYREF,
864 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK);
866 VariantClear(&vDst);
871 /* By-reference variants are dereferenced */
872 V_VT(&vRef) = VT_UI1;
873 V_UI1(&vRef) = 0x77;
874 V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
875 V_VARIANTREF(&vSrc) = &vRef;
876 VariantInit(&vDst);
878 hres = VariantCopyInd(&vDst, &vSrc);
879 ok(hres == S_OK, "VariantCopyInd failed: 0x%08x\n", hres);
880 ok(V_VT(&vDst) == VT_UI1 && V_UI1(&vDst) == 0x77,
881 "CopyInd(deref): expected dst vt = VT_UI1, val 0x77, got %d|0x%X, 0x%2X\n",
882 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK, V_UI1(&vDst));
884 /* By-reference variant to a by-reference type succeeds */
885 V_VT(&vRef) = VT_UI1|VT_BYREF;
886 V_UI1REF(&vRef) = buffer; buffer[0] = 0x88;
887 V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
888 V_VARIANTREF(&vSrc) = &vRef;
889 VariantInit(&vDst);
891 hres = VariantCopyInd(&vDst, &vSrc);
892 ok(hres == S_OK, "VariantCopyInd failed: 0x%08x\n", hres);
893 ok(V_VT(&vDst) == VT_UI1 && V_UI1(&vDst) == 0x88,
894 "CopyInd(deref): expected dst vt = VT_UI1, val 0x77, got %d|0x%X, 0x%2X\n",
895 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK, V_UI1(&vDst));
897 /* But a by-reference variant to a by-reference variant fails */
898 V_VT(&vRef2) = VT_UI1;
899 V_UI1(&vRef2) = 0x77;
900 V_VT(&vRef) = VT_VARIANT|VT_BYREF;
901 V_VARIANTREF(&vRef) = &vRef2;
902 V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
903 V_VARIANTREF(&vSrc) = &vRef;
904 VariantInit(&vDst);
906 hres = VariantCopyInd(&vDst, &vSrc);
907 ok(hres == E_INVALIDARG,
908 "CopyInd(ref->ref): expected E_INVALIDARG, got 0x%08x\n", hres);
911 static HRESULT (WINAPI *pVarParseNumFromStr)(OLECHAR*,LCID,ULONG,NUMPARSE*,BYTE*);
913 /* Macros for converting and testing the result of VarParseNumFromStr */
914 #define FAILDIG 255
916 static HRESULT convert_str( const char *str, INT dig, ULONG flags,
917 NUMPARSE *np, BYTE rgb[128], LCID lcid )
919 OLECHAR buff[128];
920 MultiByteToWideChar( CP_ACP,0, str, -1, buff, sizeof(buff)/sizeof(WCHAR) );
921 memset( rgb, FAILDIG, 128 );
922 memset( np, 255, sizeof(*np) );
923 np->cDig = dig;
924 np->dwInFlags = flags;
925 return pVarParseNumFromStr( buff, lcid, LOCALE_NOUSEROVERRIDE, np, rgb);
928 static void expect_NumFromStr( int line, HRESULT hres, NUMPARSE *np, INT a, ULONG b, ULONG c,
929 INT d, INT e, INT f )
931 if (hres == (HRESULT)S_OK)
933 ok_(__FILE__,line)(np->cDig == a, "Expected cDig = %d, got %d\n", a, np->cDig);
934 ok_(__FILE__,line)(np->dwInFlags == b, "Expected dwInFlags = 0x%x, got 0x%x\n", b, np->dwInFlags);
935 ok_(__FILE__,line)(np->dwOutFlags == c, "Expected dwOutFlags = 0x%x, got 0x%x\n", c, np->dwOutFlags);
936 ok_(__FILE__,line)(np->cchUsed == d, "Expected cchUsed = %d, got %d\n", d, np->cchUsed);
937 ok_(__FILE__,line)(np->nBaseShift == e, "Expected nBaseShift = %d, got %d\n", e, np->nBaseShift);
938 ok_(__FILE__,line)(np->nPwr10 == f, "Expected nPwr10 = %d, got %d\n", f, np->nPwr10);
942 #define CONVERTN(str,dig,flags) hres = convert_str( str, dig, flags, &np, rgb, lcid )
943 #define CONVERT(str,flags) CONVERTN(str,sizeof(rgb),flags)
944 #define EXPECT(a,b,c,d,e,f) expect_NumFromStr( __LINE__, hres, &np, a, b, c, d, e, f )
945 #define EXPECTRGB(a,b) ok(rgb[a] == b, "Digit[%d], expected %d, got %d\n", a, b, rgb[a])
946 #define EXPECTFAIL ok(hres == (HRESULT)DISP_E_TYPEMISMATCH, "Call succeeded, hres = %08x\n", hres)
947 #define EXPECT2(a,b) EXPECTRGB(0,a); EXPECTRGB(1,b)
949 static void test_VarParseNumFromStr(void)
951 HRESULT hres;
952 /* Ensure all tests are using the same locale characters for '$', ',' etc */
953 LCID lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
954 NUMPARSE np;
955 BYTE rgb[128];
957 /** No flags **/
959 CHECKPTR(VarParseNumFromStr);
961 /* Consume a single digit */
962 CONVERT("7", 0);
963 EXPECT(1,0,0,1,0,0);
964 EXPECT2(7,FAILDIG);
966 /* cDig is not literal digits - zeros are suppressed and nPwr10 is increased */
967 CONVERT("10", 0);
968 EXPECT(1,0,0,2,0,1);
969 /* Note: Win32 writes the trailing zeros if they are within cDig's limits,
970 * but then excludes them from the returned cDig count.
971 * In our implementation we don't bother writing them at all.
973 EXPECTRGB(0, 1);
975 /* if cDig is too small and numbers follow, sets INEXACT */
976 CONVERTN("11",1, 0);
977 EXPECT(1,0,NUMPRS_INEXACT,2,0,1);
978 EXPECT2(1,FAILDIG);
980 /* Strips leading zeros */
981 CONVERT("01", 0);
982 EXPECT(1,0,0,2,0,0);
983 EXPECT2(1,FAILDIG);
985 /* Strips leading zeros */
986 CONVERTN("01",1, 0);
987 EXPECT(1,0,0,2,0,0);
988 EXPECT2(1,FAILDIG);
991 /* Fails on non digits */
992 CONVERT("a", 0);
993 EXPECTFAIL;
994 EXPECTRGB(0,FAILDIG);
996 /** NUMPRS_LEADING_WHITE/NUMPRS_TRAILING_WHITE **/
998 /* Without flag, fails on whitespace */
999 CONVERT(" 0", 0);
1000 EXPECTFAIL;
1001 EXPECTRGB(0,FAILDIG);
1004 /* With flag, consumes whitespace */
1005 CONVERT(" 0", NUMPRS_LEADING_WHITE);
1006 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
1007 EXPECT2(0,FAILDIG);
1009 /* Test TAB once, then assume it acts as space for all cases */
1010 CONVERT("\t0", NUMPRS_LEADING_WHITE);
1011 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
1012 EXPECT2(0,FAILDIG);
1015 /* Doesn't pick up trailing whitespace without flag */
1016 CONVERT("0 ", 0);
1017 EXPECT(1,0,0,1,0,0);
1018 EXPECT2(0,FAILDIG);
1020 /* With flag, consumes trailing whitespace */
1021 CONVERT("0 ", NUMPRS_TRAILING_WHITE);
1022 EXPECT(1,NUMPRS_TRAILING_WHITE,NUMPRS_TRAILING_WHITE,2,0,0);
1023 EXPECT2(0,FAILDIG);
1025 /* Leading flag only consumes leading */
1026 CONVERT(" 0 ", NUMPRS_LEADING_WHITE);
1027 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
1028 EXPECT2(0,FAILDIG);
1030 /* Both flags consumes both */
1031 CONVERT(" 0 ", NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE);
1032 EXPECT(1,NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE,NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE,3,0,0);
1033 EXPECT2(0,FAILDIG);
1035 /** NUMPRS_LEADING_PLUS/NUMPRS_TRAILING_PLUS **/
1037 /* Without flag, fails on + */
1038 CONVERT("+0", 0);
1039 EXPECTFAIL;
1040 EXPECTRGB(0,FAILDIG);
1042 /* With flag, consumes + */
1043 CONVERT("+0", NUMPRS_LEADING_PLUS);
1044 EXPECT(1,NUMPRS_LEADING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
1045 EXPECT2(0,FAILDIG);
1047 /* Without flag, doesn't consume trailing + */
1048 CONVERT("0+", 0);
1049 EXPECT(1,0,0,1,0,0);
1050 EXPECT2(0,FAILDIG);
1052 /* With flag, consumes trailing + */
1053 CONVERT("0+", NUMPRS_TRAILING_PLUS);
1054 EXPECT(1,NUMPRS_TRAILING_PLUS,NUMPRS_TRAILING_PLUS,2,0,0);
1055 EXPECT2(0,FAILDIG);
1057 /* With leading flag, doesn't consume trailing + */
1058 CONVERT("+0+", NUMPRS_LEADING_PLUS);
1059 EXPECT(1,NUMPRS_LEADING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
1060 EXPECT2(0,FAILDIG);
1062 /* Trailing + doesn't get consumed if we specify both (unlike whitespace) */
1063 CONVERT("+0+", NUMPRS_LEADING_PLUS|NUMPRS_TRAILING_PLUS);
1064 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_TRAILING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
1065 EXPECT2(0,FAILDIG);
1067 /** NUMPRS_LEADING_MINUS/NUMPRS_TRAILING_MINUS **/
1069 /* Without flag, fails on - */
1070 CONVERT("-0", 0);
1071 EXPECTFAIL;
1072 EXPECTRGB(0,FAILDIG);
1074 /* With flag, consumes - */
1075 CONVERT("-0", NUMPRS_LEADING_MINUS);
1076 EXPECT(1,NUMPRS_LEADING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
1077 EXPECT2(0,FAILDIG);
1079 /* Without flag, doesn't consume trailing - */
1080 CONVERT("0-", 0);
1081 EXPECT(1,0,0,1,0,0);
1082 EXPECT2(0,FAILDIG);
1084 /* With flag, consumes trailing - */
1085 CONVERT("0-", NUMPRS_TRAILING_MINUS);
1086 EXPECT(1,NUMPRS_TRAILING_MINUS,NUMPRS_NEG|NUMPRS_TRAILING_MINUS,2,0,0);
1087 EXPECT2(0,FAILDIG);
1089 /* With leading flag, doesn't consume trailing - */
1090 CONVERT("-0-", NUMPRS_LEADING_MINUS);
1091 EXPECT(1,NUMPRS_LEADING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
1092 EXPECT2(0,FAILDIG);
1094 /* Trailing - doesn't get consumed if we specify both (unlike whitespace) */
1095 CONVERT("-0-", NUMPRS_LEADING_MINUS|NUMPRS_TRAILING_MINUS);
1096 EXPECT(1,NUMPRS_LEADING_MINUS|NUMPRS_TRAILING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
1097 EXPECT2(0,FAILDIG);
1099 /** NUMPRS_HEX_OCT **/
1101 /* Could be hex, octal or decimal - With flag reads as decimal */
1102 CONVERT("0", NUMPRS_HEX_OCT);
1103 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
1104 EXPECT2(0,FAILDIG);
1106 /* Doesn't recognise hex in .asm syntax */
1107 CONVERT("0h", NUMPRS_HEX_OCT);
1108 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
1109 EXPECT2(0,FAILDIG);
1111 /* Doesn't fail with valid leading string but no digits */
1112 CONVERT("0x", NUMPRS_HEX_OCT);
1113 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
1114 EXPECT2(0,FAILDIG);
1116 /* Doesn't recognise hex format numbers at all! */
1117 CONVERT("0x0", NUMPRS_HEX_OCT);
1118 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
1119 EXPECT2(0,FAILDIG);
1121 /* Doesn't recognise plain hex digits either */
1122 CONVERT("FE", NUMPRS_HEX_OCT);
1123 EXPECTFAIL;
1124 EXPECTRGB(0,FAILDIG);
1126 /* Octal */
1127 CONVERT("0100", NUMPRS_HEX_OCT);
1128 EXPECT(1,NUMPRS_HEX_OCT,0,4,0,2);
1129 EXPECTRGB(0,1);
1130 EXPECTRGB(1,0);
1131 EXPECTRGB(2,0);
1132 EXPECTRGB(3,FAILDIG);
1134 /* VB hex */
1135 CONVERT("&HF800", NUMPRS_HEX_OCT);
1136 EXPECT(4,NUMPRS_HEX_OCT,0x40,6,4,0);
1137 EXPECTRGB(0,15);
1138 EXPECTRGB(1,8);
1139 EXPECTRGB(2,0);
1140 EXPECTRGB(3,0);
1141 EXPECTRGB(4,FAILDIG);
1143 /* VB hex lower case and leading zero */
1144 CONVERT("&h0abcdef", NUMPRS_HEX_OCT);
1145 EXPECT(6,NUMPRS_HEX_OCT,0x40,9,4,0);
1146 EXPECTRGB(0,10);
1147 EXPECTRGB(1,11);
1148 EXPECTRGB(2,12);
1149 EXPECTRGB(3,13);
1150 EXPECTRGB(4,14);
1151 EXPECTRGB(5,15);
1152 EXPECTRGB(6,FAILDIG);
1154 /* VB oct */
1155 CONVERT("&O300", NUMPRS_HEX_OCT);
1156 EXPECT(3,NUMPRS_HEX_OCT,0x40,5,3,0);
1157 EXPECTRGB(0,3);
1158 EXPECTRGB(1,0);
1159 EXPECTRGB(2,0);
1160 EXPECTRGB(3,FAILDIG);
1162 /* VB oct lower case and leading zero */
1163 CONVERT("&o0777", NUMPRS_HEX_OCT);
1164 EXPECT(3,NUMPRS_HEX_OCT,0x40,6,3,0);
1165 EXPECTRGB(0,7);
1166 EXPECTRGB(1,7);
1167 EXPECTRGB(2,7);
1168 EXPECTRGB(3,FAILDIG);
1170 /* VB oct char bigger than 7 */
1171 CONVERT("&o128", NUMPRS_HEX_OCT);
1173 Native versions 2.x of oleaut32 allow this to succeed: later versions and Wine don't
1174 EXPECTFAIL;
1175 EXPECTRGB(0,FAILDIG);
1177 /** NUMPRS_PARENS **/
1179 /* Empty parens = error */
1180 CONVERT("()", NUMPRS_PARENS);
1181 EXPECTFAIL;
1182 EXPECTRGB(0,FAILDIG);
1184 /* With flag, trailing parens not consumed */
1185 CONVERT("0()", NUMPRS_PARENS);
1186 EXPECT(1,NUMPRS_PARENS,0,1,0,0);
1187 EXPECT2(0,FAILDIG);
1189 /* With flag, Number in parens made negative and parens consumed */
1190 CONVERT("(0)", NUMPRS_PARENS);
1191 EXPECT(1,NUMPRS_PARENS,NUMPRS_NEG|NUMPRS_PARENS,3,0,0);
1192 EXPECT2(0,FAILDIG);
1194 /** NUMPRS_THOUSANDS **/
1196 /* With flag, thousands sep. not needed */
1197 CONVERT("0", NUMPRS_THOUSANDS);
1198 EXPECT(1,NUMPRS_THOUSANDS,0,1,0,0);
1199 EXPECT2(0,FAILDIG);
1201 /* With flag, thousands sep. and following digits consumed */
1202 CONVERT("1,000", NUMPRS_THOUSANDS);
1203 EXPECT(1,NUMPRS_THOUSANDS,NUMPRS_THOUSANDS,5,0,3);
1204 EXPECTRGB(0,1);
1206 /* With flag and decimal point, thousands sep. but not decimals consumed */
1207 CONVERT("1,000.0", NUMPRS_THOUSANDS);
1208 EXPECT(1,NUMPRS_THOUSANDS,NUMPRS_THOUSANDS,5,0,3);
1209 EXPECTRGB(0,1);
1211 /** NUMPRS_CURRENCY **/
1213 /* Without flag, chokes on currency sign */
1214 CONVERT("$11", 0);
1215 EXPECTFAIL;
1216 EXPECTRGB(0,FAILDIG);
1218 /* With flag, consumes currency sign */
1219 CONVERT("$11", NUMPRS_CURRENCY);
1220 EXPECT(2,NUMPRS_CURRENCY,NUMPRS_CURRENCY,3,0,0);
1221 EXPECT2(1,1);
1222 EXPECTRGB(2,FAILDIG);
1224 /* With flag only, doesn't consume decimal point */
1225 CONVERT("$11.1", NUMPRS_CURRENCY);
1226 EXPECT(2,NUMPRS_CURRENCY,NUMPRS_CURRENCY,3,0,0);
1227 EXPECT2(1,1);
1228 EXPECTRGB(2,FAILDIG);
1230 /* With flag and decimal flag, consumes decimal point and following digits */
1231 CONVERT("$11.1", NUMPRS_CURRENCY|NUMPRS_DECIMAL);
1232 EXPECT(3,NUMPRS_CURRENCY|NUMPRS_DECIMAL,NUMPRS_CURRENCY|NUMPRS_DECIMAL,5,0,-1);
1233 EXPECT2(1,1);
1234 EXPECTRGB(2,1);
1235 EXPECTRGB(3,FAILDIG);
1237 /* Thousands flag can only be used with currency */
1238 CONVERT("$1,234", NUMPRS_CURRENCY|NUMPRS_THOUSANDS);
1239 EXPECT(4,NUMPRS_CURRENCY|NUMPRS_THOUSANDS,NUMPRS_CURRENCY|NUMPRS_THOUSANDS,6,0,0);
1240 EXPECT2(1,2);
1241 EXPECTRGB(2,3);
1242 EXPECTRGB(3,4);
1243 EXPECTRGB(4,FAILDIG);
1245 /** NUMPRS_DECIMAL **/
1247 /* With flag, consumes decimal point */
1248 CONVERT("1.1", NUMPRS_DECIMAL);
1249 EXPECT(2,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1);
1250 EXPECT2(1,1);
1251 EXPECTRGB(2,FAILDIG);
1253 /* With flag, consumes decimal point. Skipping the decimal part is not an error */
1254 CONVERT("1.", NUMPRS_DECIMAL);
1255 EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,2,0,0);
1256 EXPECT2(1,FAILDIG);
1258 /* Consumes only one decimal point */
1259 CONVERT("1.1.", NUMPRS_DECIMAL);
1260 EXPECT(2,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1);
1261 EXPECT2(1,1);
1262 EXPECTRGB(2,FAILDIG);
1264 /** NUMPRS_EXPONENT **/
1266 /* Without flag, doesn't consume exponent */
1267 CONVERT("1e1", 0);
1268 EXPECT(1,0,0,1,0,0);
1269 EXPECT2(1,FAILDIG);
1271 /* With flag, consumes exponent */
1272 CONVERT("1e1", NUMPRS_EXPONENT);
1273 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,1);
1274 EXPECT2(1,FAILDIG);
1276 /* Negative exponents are accepted without flags */
1277 CONVERT("1e-1", NUMPRS_EXPONENT);
1278 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,-1);
1279 EXPECT2(1,FAILDIG);
1281 /* As are positive exponents and leading exponent 0s */
1282 CONVERT("1e+01", NUMPRS_EXPONENT);
1283 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,5,0,1);
1284 EXPECT2(1,FAILDIG);
1286 /* The same for zero exponents */
1287 CONVERT("1e0", NUMPRS_EXPONENT);
1288 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,0);
1289 EXPECT2(1,FAILDIG);
1291 /* Sign on a zero exponent doesn't matter */
1292 CONVERT("1e+0", NUMPRS_EXPONENT);
1293 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,0);
1294 EXPECT2(1,FAILDIG);
1296 CONVERT("1e-0", NUMPRS_EXPONENT);
1297 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,0);
1298 EXPECT2(1,FAILDIG);
1300 /* Doesn't consume a real number exponent */
1301 CONVERT("1e1.", NUMPRS_EXPONENT);
1302 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,1);
1303 EXPECT2(1,FAILDIG);
1305 /* Powers of 10 are calculated from the position of any decimal point */
1306 CONVERT("1.5e20", NUMPRS_EXPONENT|NUMPRS_DECIMAL);
1307 EXPECT(2,NUMPRS_EXPONENT|NUMPRS_DECIMAL,NUMPRS_EXPONENT|NUMPRS_DECIMAL,6,0,19);
1308 EXPECT2(1,5);
1310 CONVERT("1.5e-20", NUMPRS_EXPONENT|NUMPRS_DECIMAL);
1311 EXPECT(2,NUMPRS_EXPONENT|NUMPRS_DECIMAL,NUMPRS_EXPONENT|NUMPRS_DECIMAL,7,0,-21);
1312 EXPECT2(1,5);
1314 /** NUMPRS_USE_ALL **/
1316 /* Flag expects all digits */
1317 CONVERT("0", NUMPRS_USE_ALL);
1318 EXPECT(1,NUMPRS_USE_ALL,0,1,0,0);
1319 EXPECT2(0,FAILDIG);
1321 /* Rejects anything trailing */
1322 CONVERT("0 ", NUMPRS_USE_ALL);
1323 EXPECTFAIL;
1324 EXPECT2(0,FAILDIG);
1326 /* Unless consumed by trailing flag */
1327 CONVERT("0 ", NUMPRS_USE_ALL|NUMPRS_TRAILING_WHITE);
1328 EXPECT(1,NUMPRS_USE_ALL|NUMPRS_TRAILING_WHITE,NUMPRS_TRAILING_WHITE,2,0,0);
1329 EXPECT2(0,FAILDIG);
1331 /** Combinations **/
1333 /* Leading whitespace and plus, doesn't consume trailing whitespace */
1334 CONVERT("+ 0 ", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1335 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,3,0,0);
1336 EXPECT2(0,FAILDIG);
1338 /* Order of whitespace and plus is unimportant */
1339 CONVERT(" +0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1340 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,3,0,0);
1341 EXPECT2(0,FAILDIG);
1343 /* Leading whitespace can be repeated */
1344 CONVERT(" + 0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1345 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,4,0,0);
1346 EXPECT2(0,FAILDIG);
1348 /* But plus/minus etc. cannot */
1349 CONVERT("+ +0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1350 EXPECTFAIL;
1351 EXPECTRGB(0,FAILDIG);
1353 /* Inexact is not set if trailing zeros are removed */
1354 CONVERTN("10", 1, 0);
1355 EXPECT(1,0,0,2,0,1);
1356 EXPECT2(1,FAILDIG);
1358 /* Make sure a leading 0 is stripped but decimals after it get read */
1359 CONVERT("-0.51", NUMPRS_STD);
1360 EXPECT(2,NUMPRS_STD,NUMPRS_NEG|NUMPRS_DECIMAL|NUMPRS_LEADING_MINUS,5,0,-2);
1361 EXPECT2(5,1);
1363 /* Keep trailing zeros on whole number part of a decimal */
1364 CONVERT("10.1", NUMPRS_STD);
1365 EXPECT(3,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-1);
1366 EXPECT2(1,0);
1367 EXPECTRGB(2,1);
1369 /* Zeros after decimal sign */
1370 CONVERT("0.01", NUMPRS_STD);
1371 EXPECT(1,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-2);
1372 EXPECT2(1,FAILDIG);
1374 /* Trailing zeros after decimal part */
1375 CONVERT("0.10", NUMPRS_STD);
1376 EXPECT(1,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-1);
1377 EXPECT2(1,0);
1380 static HRESULT (WINAPI *pVarNumFromParseNum)(NUMPARSE*,BYTE*,ULONG,VARIANT*);
1382 /* Macros for converting and testing the result of VarNumFromParseNum */
1383 #define SETRGB(indx,val) if (!indx) memset(rgb, FAILDIG, sizeof(rgb)); rgb[indx] = val
1384 #undef CONVERT
1385 #define CONVERT(a,b,c,d,e,f,bits) \
1386 np.cDig = (a); np.dwInFlags = (b); np.dwOutFlags = (c); np.cchUsed = (d); \
1387 np.nBaseShift = (e); np.nPwr10 = (f); hres = pVarNumFromParseNum(&np, rgb, bits, &vOut)
1388 static const char *szFailOverflow = "Expected overflow, hres = %08x\n";
1389 #define EXPECT_OVERFLOW ok(hres == (HRESULT)DISP_E_OVERFLOW, szFailOverflow, hres)
1390 static const char *szFailOk = "Call failed, hres = %08x\n";
1391 #define EXPECT_OK ok(hres == (HRESULT)S_OK, szFailOk, hres); \
1392 if (hres == (HRESULT)S_OK)
1393 #define EXPECT_TYPE(typ) ok(V_VT(&vOut) == typ,"Expected Type = " #typ ", got %d\n", V_VT(&vOut))
1394 #define EXPECT_I1(val) EXPECT_OK { EXPECT_TYPE(VT_I1); \
1395 ok(V_I1(&vOut) == val, "Expected i1 = %d, got %d\n", (signed char)val, V_I1(&vOut)); }
1396 #define EXPECT_UI1(val) EXPECT_OK { EXPECT_TYPE(VT_UI1); \
1397 ok(V_UI1(&vOut) == val, "Expected ui1 = %d, got %d\n", (BYTE)val, V_UI1(&vOut)); }
1398 #define EXPECT_I2(val) EXPECT_OK { EXPECT_TYPE(VT_I2); \
1399 ok(V_I2(&vOut) == val, "Expected i2 = %d, got %d\n", (SHORT)val, V_I2(&vOut)); }
1400 #define EXPECT_UI2(val) EXPECT_OK { EXPECT_TYPE(VT_UI2); \
1401 ok(V_UI2(&vOut) == val, "Expected ui2 = %d, got %d\n", (USHORT)val, V_UI2(&vOut)); }
1402 #define EXPECT_I4(val) EXPECT_OK { EXPECT_TYPE(VT_I4); \
1403 ok(V_I4(&vOut) == val, "Expected i4 = %d, got %d\n", (LONG)val, V_I4(&vOut)); }
1404 #define EXPECT_UI4(val) EXPECT_OK { EXPECT_TYPE(VT_UI4); \
1405 ok(V_UI4(&vOut) == val, "Expected ui4 = %d, got %d\n", (ULONG)val, V_UI4(&vOut)); }
1406 #define EXPECT_I8(high,low) EXPECT_OK { EXPECT_TYPE(VT_I8); \
1407 ok(V_I8(&vOut) == ((((LONG64)(high))<<32)|(low)), "Expected i8 = %x%08x, got %x%08x\n", \
1408 (LONG)(high), (LONG)(low), (LONG)(V_I8(&vOut)>>32), (LONG)V_I8(&vOut) ); }
1409 #define EXPECT_UI8(val) EXPECT_OK { EXPECT_TYPE(VT_UI8); \
1410 ok(V_UI8(&vOut) == val, "Expected ui8 = 0x%x%08x, got 0x%x%08x\n", \
1411 (DWORD)((ULONG64)val >> 32), (DWORD)(ULONG64)val, (DWORD)(V_UI8(&vOut) >> 32), (DWORD)V_UI8(&vOut)); }
1412 #define EXPECT_R4(val) EXPECT_OK { EXPECT_TYPE(VT_R4); \
1413 ok(V_R4(&vOut) == val, "Expected r4 = %f, got %f\n", val, V_R4(&vOut)); }
1414 #define EXPECT_R8(val) EXPECT_OK { EXPECT_TYPE(VT_R8); \
1415 ok(V_R8(&vOut) == val, "Expected r8 = %g, got %g\n", val, V_R8(&vOut)); }
1416 #define CY_MULTIPLIER 10000
1417 #define EXPECT_CY(val) EXPECT_OK { EXPECT_TYPE(VT_CY); \
1418 ok(V_CY(&vOut).int64 == (LONG64)(val * CY_MULTIPLIER), "Expected r8 = 0x%x%08x, got 0x%x%08x\n", \
1419 (DWORD)((LONG64)val >> 23), (DWORD)(LONG64)val, (DWORD)(V_CY(&vOut).int64 >>32), (DWORD)V_CY(&vOut).int64); }
1420 #define EXPECT_DECIMAL(valHi, valMid, valLo) EXPECT_OK { EXPECT_TYPE(VT_DECIMAL); \
1421 ok((V_DECIMAL(&vOut).Hi32 == valHi) && (S1(U1(V_DECIMAL(&vOut))).Mid32 == valMid) && \
1422 (S1(U1(V_DECIMAL(&vOut))).Lo32 == valLo), \
1423 "Expected decimal = %x/0x%x%08x, got %x/0x%x%08x\n", valHi, valMid, valLo, \
1424 V_DECIMAL(&vOut).Hi32, S1(U1(V_DECIMAL(&vOut))).Mid32, S1(U1(V_DECIMAL(&vOut))).Lo32); }
1426 static void test_VarNumFromParseNum(void)
1428 HRESULT hres;
1429 NUMPARSE np;
1430 BYTE rgb[128];
1431 VARIANT vOut;
1433 CHECKPTR(VarNumFromParseNum);
1435 /* Convert the number 1 to different types */
1436 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I1); EXPECT_I1(1);
1437 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_UI1); EXPECT_UI1(1);
1438 /* Prefers a signed type to unsigned of the same size */
1439 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I1|VTBIT_UI1); EXPECT_I1(1);
1440 /* But takes the smaller size if possible */
1441 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I2|VTBIT_UI1); EXPECT_UI1(1);
1443 /* Try different integer sizes */
1444 #define INTEGER_VTBITS (VTBIT_I1|VTBIT_UI1|VTBIT_I2|VTBIT_UI2|VTBIT_I4|VTBIT_UI4|VTBIT_I8|VTBIT_UI8)
1446 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, INTEGER_VTBITS); EXPECT_I1(1);
1447 /* 127 */
1448 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 7);
1449 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_I1(127);
1450 /* 128 */
1451 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 8);
1452 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_UI1(128);
1453 /* 255 */
1454 SETRGB(0, 2); SETRGB(1, 5); SETRGB(2, 5);
1455 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_UI1(255);
1456 /* 256 */
1457 SETRGB(0, 2); SETRGB(1, 5); SETRGB(2, 6);
1458 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_I2(256);
1459 /* 32767 */
1460 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 7);
1461 CONVERT(5,0,0,5,0,0, INTEGER_VTBITS); EXPECT_I2(32767);
1462 /* 32768 */
1463 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 8);
1464 CONVERT(5,0,0,5,0,0, INTEGER_VTBITS); EXPECT_UI2(32768);
1466 /* Assume the above pattern holds for remaining positive integers; test negative */
1468 /* -128 */
1469 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 8);
1470 CONVERT(3,0,NUMPRS_NEG,3,0,0, INTEGER_VTBITS); EXPECT_I1(-128);
1471 /* -129 */
1472 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 9);
1473 CONVERT(3,0,NUMPRS_NEG,3,0,0, INTEGER_VTBITS); EXPECT_I2(-129);
1474 /* -32768 */
1475 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 8);
1476 CONVERT(5,0,NUMPRS_NEG,5,0,0, INTEGER_VTBITS); EXPECT_I2(-32768);
1477 /* -32768 */
1478 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 9);
1479 CONVERT(5,0,NUMPRS_NEG,5,0,0, INTEGER_VTBITS); EXPECT_I4(-32769);
1481 /* Assume the above pattern holds for remaining negative integers */
1483 /* Test hexadecimal conversions */
1484 SETRGB(0, 1); CONVERT(1,0,0,1,4,0, INTEGER_VTBITS); EXPECT_I1(0x01);
1485 /* 0x7f */
1486 SETRGB(0, 7); SETRGB(1, 0xf);
1487 CONVERT(2,0,0,2,4,0, INTEGER_VTBITS); EXPECT_I1(0x7f);
1488 SETRGB(0, 7); SETRGB(1, 0xf);
1489 CONVERT(2,0,0,2,4,0, VTBIT_DECIMAL); EXPECT_DECIMAL(0,0,0x7f);
1490 /* 0x7fff */
1491 SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
1492 CONVERT(4,0,0,4,4,0, INTEGER_VTBITS); EXPECT_I2(0x7fff);
1493 /* 0x7fffffff */
1494 SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
1495 SETRGB(4, 0xf); SETRGB(5, 0xf); SETRGB(6, 0xf); SETRGB(7, 0xf);
1496 CONVERT(8,0,0,8,4,0, INTEGER_VTBITS); EXPECT_I4(0x7fffffffL);
1497 /* 0x7fffffffffffffff (64 bits) */
1498 SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
1499 SETRGB(4, 0xf); SETRGB(5, 0xf); SETRGB(6, 0xf); SETRGB(7, 0xf);
1500 SETRGB(8, 0xf); SETRGB(9, 0xf); SETRGB(10, 0xf); SETRGB(11, 0xf);
1501 SETRGB(12, 0xf); SETRGB(13, 0xf); SETRGB(14, 0xf); SETRGB(15, 0xf);
1502 if (HAVE_OLEAUT32_I8)
1504 /* We cannot use INTEGER_VTBITS as WinXP and Win2003 are broken(?). They
1505 truncate the number to the smallest integer size requested:
1506 CONVERT(16,0,0,16,4,0, INTEGER_VTBITS); EXPECT_I1((signed char)0xff); */
1507 CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x7fffffff,0xffffffff);
1510 /* Assume the above pattern holds for numbers without hi-bit set, test (preservation of) hi-bit */
1511 /* 0x82 */
1512 SETRGB(0, 8); SETRGB(1, 2);
1513 CONVERT(2,0,0,2,4,0, INTEGER_VTBITS);
1514 EXPECT_I1((signed char)0x82);
1515 /* 0x8002 */
1516 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 2);
1517 CONVERT(4,0,0,4,4,0, INTEGER_VTBITS);
1518 EXPECT_I2((signed short)0x8002);
1519 /* 0x80000002 */
1520 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1521 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 2);
1522 CONVERT(8,0,0,8,4,0, INTEGER_VTBITS); EXPECT_I4(0x80000002);
1523 /* 0x8000000000000002 (64 bits) */
1524 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1525 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 0);
1526 SETRGB(8, 0); SETRGB(9, 0); SETRGB(10, 0); SETRGB(11, 0);
1527 SETRGB(12, 0); SETRGB(13, 0); SETRGB(14, 0); SETRGB(15, 2);
1528 if (HAVE_OLEAUT32_I8)
1530 /* We cannot use INTEGER_VTBITS as WinXP and Win2003 are broken(?). They
1531 truncate the number to the smallest integer size requested:
1532 CONVERT(16,0,0,16,4,0, INTEGER_VTBITS & ~VTBIT_I1);
1533 EXPECT_I2((signed short)0x0002); */
1534 CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x80000000,0x00000002);
1537 /* Test (preservation of) hi-bit with STRICT type requesting */
1538 /* 0x82 */
1539 SETRGB(0, 8); SETRGB(1, 2);
1540 CONVERT(2,0,0,2,4,0, VTBIT_I1);
1541 EXPECT_I1((signed char)0x82);
1542 /* 0x8002 */
1543 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 2);
1544 CONVERT(4,0,0,4,4,0, VTBIT_I2);
1545 EXPECT_I2((signed short)0x8002);
1546 /* 0x80000002 */
1547 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1548 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 2);
1549 CONVERT(8,0,0,8,4,0, VTBIT_I4); EXPECT_I4(0x80000002);
1550 /* 0x8000000000000002 (64 bits) */
1551 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1552 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 0);
1553 SETRGB(8, 0); SETRGB(9, 0); SETRGB(10, 0); SETRGB(11, 0);
1554 SETRGB(12, 0); SETRGB(13, 0); SETRGB(14, 0); SETRGB(15, 2);
1555 if (HAVE_OLEAUT32_I8)
1557 CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x80000000,0x00000002);
1559 /* Assume the above pattern holds for numbers with hi-bit set */
1561 /* Negative numbers overflow if we have only unsigned outputs */
1562 /* -1 */
1563 SETRGB(0, 1); CONVERT(1,0,NUMPRS_NEG,1,0,0, VTBIT_UI1); EXPECT_OVERFLOW;
1564 /* -0.6 */
1565 SETRGB(0, 6); CONVERT(1,0,NUMPRS_NEG,1,0,~0u, VTBIT_UI1); EXPECT_OVERFLOW;
1567 /* Except that rounding is done first, so -0.5 to 0 are accepted as 0 */
1568 /* -0.5 */
1569 SETRGB(0, 5); CONVERT(1,0,NUMPRS_NEG,1,0,~0u, VTBIT_UI1); EXPECT_UI1(0);
1571 /* Floating point zero is OK */
1572 /* 0.00000000E0 */
1573 SETRGB(0, 0); CONVERT(1,0,NUMPRS_DECIMAL|NUMPRS_EXPONENT,12,0,-8, VTBIT_R8);
1574 EXPECT_R8(0.0);
1576 /* Float is acceptable for an integer input value */
1577 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R4); EXPECT_R4(1.0f);
1578 /* As is double */
1579 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R8); EXPECT_R8(1.0);
1580 /* As is currency */
1581 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_CY); EXPECT_CY(1);
1583 /* Float is preferred over double */
1584 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R4|VTBIT_R8); EXPECT_R4(1.0f);
1586 /* Double is preferred over currency */
1587 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R8|VTBIT_CY); EXPECT_R8(1.0);
1589 /* Currency is preferred over decimal */
1590 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_CY|VTBIT_DECIMAL); EXPECT_CY(1);
1594 static void test_UdateFromDate( int line, DATE dt, ULONG flags, HRESULT r, WORD d, WORD m, WORD y,
1595 WORD h, WORD mn, WORD s, WORD ms, WORD dw, WORD dy)
1597 UDATE ud;
1598 HRESULT res;
1600 memset(&ud, 0, sizeof(ud));
1601 res = pVarUdateFromDate(dt, flags, &ud);
1602 ok_(__FILE__,line)(r == res && (res != S_OK || (ud.st.wYear == y && ud.st.wMonth == m && ud.st.wDay == d &&
1603 ud.st.wHour == h && ud.st.wMinute == mn && ud.st.wSecond == s &&
1604 ud.st.wMilliseconds == ms && ud.st.wDayOfWeek == dw && ud.wDayOfYear == dy)),
1605 "%.16g expected res(%x) %d,%d,%d,%d,%d,%d,%d %d %d, got res(%x) %d,%d,%d,%d,%d,%d,%d %d %d\n",
1606 dt, r, d, m, y, h, mn, s, ms, dw, dy,
1607 res, ud.st.wDay, ud.st.wMonth, ud.st.wYear, ud.st.wHour, ud.st.wMinute,
1608 ud.st.wSecond, ud.st.wMilliseconds, ud.st.wDayOfWeek, ud.wDayOfYear );
1610 #define DT2UD(dt,flags,r,d,m,y,h,mn,s,ms,dw,dy) test_UdateFromDate(__LINE__,dt,flags,r,d,m,y,h,mn,s,ms,dw,dy)
1612 static void test_VarUdateFromDate(void)
1614 CHECKPTR(VarUdateFromDate);
1615 DT2UD(29221.0,0,S_OK,1,1,1980,0,0,0,0,2,1); /* 1 Jan 1980 */
1616 DT2UD(29222.0,0,S_OK,2,1,1980,0,0,0,0,3,2); /* 2 Jan 1980 */
1617 DT2UD(33238.0,0,S_OK,31,12,1990,0,0,0,0,1,365); /* 31 Dec 1990 */
1618 DT2UD(0.0,0,S_OK,30,12,1899,0,0,0,0,6,364); /* 30 Dec 1899 - VT_DATE 0.0 */
1619 DT2UD(-657434.0,0,S_OK,1,1,100,0,0,0,0,5,1); /* 1 Jan 100 - Min */
1620 DT2UD(-657435.0,0,E_INVALIDARG,0,0,0,0,0,0,0,0,0); /* < 1 Jan 100 => err */
1621 DT2UD(2958465.0,0,S_OK,31,12,9999,0,0,0,0,5,365); /* 31 Dec 9999 - Max */
1622 DT2UD(2958466.0,0,E_INVALIDARG,0,0,0,0,0,0,0,0,0); /* > 31 Dec 9999 => err */
1624 /* VAR_VALIDDATE doesn't prevent upper and lower bounds being checked */
1625 DT2UD(-657435.0,VAR_VALIDDATE,E_INVALIDARG,0,0,0,0,0,0,0,0,0);
1626 DT2UD(2958466.0,VAR_VALIDDATE,E_INVALIDARG,0,0,0,0,0,0,0,0,0);
1628 /* Times */
1629 DT2UD(29221.25,0,S_OK,1,1,1980,6,0,0,0,2,1); /* 6 AM */
1630 DT2UD(29221.33333333,0,S_OK,1,1,1980,8,0,0,0,2,1); /* 8 AM */
1631 DT2UD(29221.5,0,S_OK,1,1,1980,12,0,0,0,2,1); /* 12 AM */
1632 DT2UD(29221.9888884444,0,S_OK,1,1,1980,23,44,0,0,2,1); /* 11:44 PM */
1633 DT2UD(29221.7508765432,0,S_OK,1,1,1980,18,1,16,0,2,1); /* 6:18:02 PM */
1635 /* Test handling of times on dates prior to the epoch */
1636 DT2UD(-5.25,0,S_OK,25,12,1899,6,0,0,0,1,359);
1637 DT2UD(-5.9999884259259,0,S_OK,25,12,1899,23,59,59,0,1,359);
1638 /* This just demonstrates the non-linear nature of values prior to the epoch */
1639 DT2UD(-4.0,0,S_OK,26,12,1899,0,0,0,0,2,360);
1640 /* Numerical oddity: for 0.0 < x < 1.0, x and -x represent the same datetime */
1641 DT2UD(-0.25,0,S_OK,30,12,1899,6,0,0,0,6,364);
1642 DT2UD(0.25,0,S_OK,30,12,1899,6,0,0,0,6,364);
1646 static void test_DateFromUDate( int line, WORD d, WORD m, WORD y, WORD h, WORD mn, WORD s, WORD ms,
1647 WORD dw, WORD dy, ULONG flags, HRESULT r, DATE dt )
1649 UDATE ud;
1650 double out;
1651 HRESULT res;
1653 ud.st.wYear = y;
1654 ud.st.wMonth = m;
1655 ud.st.wDay = d;
1656 ud.st.wHour = h;
1657 ud.st.wMinute = mn;
1658 ud.st.wSecond = s;
1659 ud.st.wMilliseconds = ms;
1660 ud.st.wDayOfWeek = dw;
1661 ud.wDayOfYear = dy;
1662 res = pVarDateFromUdate(&ud, flags, &out);
1663 ok_(__FILE__,line)(r == res && (r != S_OK || EQ_DOUBLE(out, dt)),
1664 "expected %x, %.16g, got %x, %.16g\n", r, dt, res, out);
1666 #define UD2T(d,m,y,h,mn,s,ms,dw,dy,flags,r,dt) test_DateFromUDate(__LINE__,d,m,y,h,mn,s,ms,dw,dy,flags,r,dt)
1668 static void test_VarDateFromUdate(void)
1670 CHECKPTR(VarDateFromUdate);
1671 UD2T(1,1,1980,0,0,0,0,2,1,0,S_OK,29221.0); /* 1 Jan 1980 */
1672 UD2T(2,1,1980,0,0,0,0,3,2,0,S_OK,29222.0); /* 2 Jan 1980 */
1673 UD2T(2,1,1980,0,0,0,0,4,5,0,S_OK,29222.0); /* 2 Jan 1980 */
1674 UD2T(31,12,1990,0,0,0,0,0,0,0,S_OK,33238.0); /* 31 Dec 1990 */
1675 UD2T(31,12,90,0,0,0,0,0,0,0,S_OK,33238.0); /* year < 100 is 1900+year! */
1676 UD2T(30,12,1899,0,0,0,0,6,364,0,S_OK,0.0); /* 30 Dec 1899 - VT_DATE 0.0 */
1677 UD2T(1,1,100,0,0,0,0,0,0,0,S_OK,-657434.0); /* 1 Jan 100 - Min */
1678 UD2T(31,12,9999,0,0,0,0,0,0,0,S_OK,2958465.0); /* 31 Dec 9999 - Max */
1679 UD2T(1,1,10000,0,0,0,0,0,0,0,E_INVALIDARG,0.0); /* > 31 Dec 9999 => err */
1680 UD2T(1,1,-10000,0,0,0,0,0,0,0,E_INVALIDARG,0.0);/* < -9999 => err */
1682 UD2T(30,12,1899,0,0,0,0,0,0,0,S_OK,0.0); /* 30 Dec 1899 0:00:00 */
1683 UD2T(30,12,1899,0,0,0,999,0,0,0,S_OK,0.0); /* Ignore milliseconds */
1685 UD2T(1,1,1980,18,1,16,0,2,1,0,S_OK,29221.75087962963); /* 6:18:02 PM */
1686 UD2T(1,300,1980,18,1,16,0,2,1,0,S_OK,38322.75087962963); /* Test fwdrolled month */
1687 UD2T(300,1,1980,18,1,16,0,2,1,0,S_OK,29520.75087962963); /* Test fwdrolled days */
1688 UD2T(0,1,1980,42,1,16,0,2,1,0,S_OK,29221.75087962963); /* Test fwdrolled hours */
1689 UD2T(1,1,1980,17,61,16,0,2,1,0,S_OK,29221.75087962963); /* Test fwdrolled minutes */
1690 UD2T(1,1,1980,18,0,76,0,2,1,0,S_OK,29221.75087962963); /* Test fwdrolled seconds */
1691 UD2T(1,-300,1980,18,1,16,0,2,1,0,S_OK,20059.75087962963); /* Test backrolled month */
1692 UD2T(-300,1,1980,18,1,16,0,2,1,0,S_OK,28920.75087962963); /* Test backrolled days */
1693 UD2T(3,1,1980,-30,1,16,0,2,1,0,S_OK,29221.75087962963); /* Test backrolled hours */
1694 UD2T(1,1,1980,20,-119,16,0,2,1,0,S_OK,29221.75087962963); /* Test backrolled minutes */
1695 UD2T(1,1,1980,18,3,-104,0,2,1,0,S_OK,29221.75087962963); /* Test backrolled seconds */
1696 UD2T(1,12001,-1020,18,1,16,0,0,0,0,S_OK,29221.75087962963); /* Test rolled year and month */
1697 UD2T(1,-23,1982,18,1,16,0,0,0,0,S_OK,29221.75087962963); /* Test backrolled month */
1698 UD2T(-59,3,1980,18,1,16,0,0,0,0,S_OK,29221.75087962963); /* Test backrolled days */
1699 UD2T(1,1,0,0,0,0,0,0,0,0,S_OK,36526); /* Test zero year */
1700 UD2T(0,0,1980,0,0,0,0,0,0,0,S_OK,29189); /* Test zero day and month */
1701 UD2T(0,1,1980,0,0,0,0,2,1,0,S_OK,29220.0); /* Test zero day = LastDayOfMonth */
1702 UD2T(-1,1,1980,18,1,16,0,0,0,0,S_OK,29219.75087962963); /* Test day -1 = LastDayOfMonth - 1 */
1703 UD2T(1,1,-1,18,1,16,0,0,0,0,S_OK,36161.75087962963); /* Test year -1 = 1999 */
1704 UD2T(1,-1,1980,18,1,16,0,0,0,0,S_OK,29160.7508796296); /* Test month -1 = 11 */
1705 UD2T(1,13,1980,0,0,0,0,2,1,0,S_OK,29587.0); /* Rolls fwd to 1/1/1981 */
1707 /* Test handling of times on dates prior to the epoch */
1708 UD2T(25,12,1899,6,0,0,0,1,359,0,S_OK,-5.25);
1709 UD2T(25,12,1899,23,59,59,0,1,359,0,S_OK,-5.9999884259259);
1710 /* This just demonstrates the non-linear nature of values prior to the epoch */
1711 UD2T(26,12,1899,0,0,0,0,2,360,0,S_OK,-4.0);
1712 /* for DATE values 0.0 < x < 1.0, x and -x represent the same datetime */
1713 /* but when converting to DATE, prefer the positive versions */
1714 UD2T(30,12,1899,6,0,0,0,6,364,0,S_OK,0.25);
1717 static void test_st2dt(int line, WORD d, WORD m, WORD y, WORD h, WORD mn,
1718 WORD s, WORD ms, INT r, double dt)
1720 SYSTEMTIME st;
1721 double out;
1722 INT res;
1724 st.wYear = y;
1725 st.wMonth = m;
1726 st.wDay = d;
1727 st.wHour = h;
1728 st.wMinute = mn;
1729 st.wSecond = s;
1730 st.wMilliseconds = ms;
1731 st.wDayOfWeek = 0;
1732 res = pSystemTimeToVariantTime(&st, &out);
1733 ok_(__FILE__,line)(r == res && (!r || EQ_DOUBLE(out, dt)),
1734 "expected %d, %.16g, got %d, %.16g\n", r, dt, res, out);
1736 #define ST2DT(d,m,y,h,mn,s,ms,r,dt) test_st2dt(__LINE__,d,m,y,h,mn,s,ms,r,dt)
1738 static void test_SystemTimeToVariantTime(void)
1740 CHECKPTR(SystemTimeToVariantTime);
1741 ST2DT(1,1,1980,0,0,0,0,TRUE,29221.0);
1742 ST2DT(2,1,1980,0,0,0,0,TRUE,29222.0);
1743 ST2DT(0,1,1980,0,0,0,0,TRUE,29220.0); /* Rolls back to 31 Dec 1899 */
1744 ST2DT(1,13,1980,0,0,0,0,FALSE,29587.0); /* Fails on invalid month */
1745 ST2DT(31,12,90,0,0,0,0,TRUE,33238.0); /* 30 <= year < 100 is 1900+year */
1746 ST2DT(1,1,30,0,0,0,0,TRUE,10959.0); /* 30 <= year < 100 is 1900+year */
1747 ST2DT(1,1,29,0,0,0,0,TRUE,47119.0); /* 0 <= year < 30 is 2000+year */
1748 ST2DT(1,1,0,0,0,0,0,TRUE,36526.0); /* 0 <= year < 30 is 2000+year */
1751 static void test_dt2st(int line, double dt, INT r, WORD d, WORD m, WORD y,
1752 WORD h, WORD mn, WORD s, WORD ms)
1754 SYSTEMTIME st;
1755 INT res;
1757 memset(&st, 0, sizeof(st));
1758 res = pVariantTimeToSystemTime(dt, &st);
1759 ok_(__FILE__,line)(r == res &&
1760 (!r || (st.wYear == y && st.wMonth == m && st.wDay == d &&
1761 st.wHour == h && st.wMinute == mn &&
1762 st.wSecond == s && st.wMilliseconds == ms)),
1763 "%.16g expected %d, %d,%d,%d,%d,%d,%d,%d, got %d, %d,%d,%d,%d,%d,%d,%d\n",
1764 dt, r, d, m, y, h, mn, s, ms, res, st.wDay, st.wMonth,
1765 st.wYear, st.wHour, st.wMinute, st.wSecond,
1766 st.wMilliseconds);
1768 #define DT2ST(dt,r,d,m,y,h,mn,s,ms) test_dt2st(__LINE__,dt,r,d,m,y,h,mn,s,ms)
1770 static void test_VariantTimeToSystemTime(void)
1772 CHECKPTR(VariantTimeToSystemTime);
1773 DT2ST(29221.0,1,1,1,1980,0,0,0,0);
1774 DT2ST(29222.0,1,2,1,1980,0,0,0,0);
1777 #define MKDOSDATE(d,m,y) ((d & 0x1f) | ((m & 0xf) << 5) | (((y-1980) & 0x7f) << 9))
1778 #define MKDOSTIME(h,m,s) (((s>>1) & 0x1f) | ((m & 0x3f) << 5) | ((h & 0x1f) << 11))
1780 static void test_dos2dt(int line, WORD d, WORD m, WORD y, WORD h, WORD mn,
1781 WORD s, INT r, double dt)
1783 unsigned short dosDate, dosTime;
1784 double out;
1785 INT res;
1787 out = 0.0;
1788 dosDate = MKDOSDATE(d, m, y);
1789 dosTime = MKDOSTIME(h, mn, s);
1790 res = pDosDateTimeToVariantTime(dosDate, dosTime, &out);
1791 ok_(__FILE__,line)(r == res && (!r || EQ_DOUBLE(out, dt)),
1792 "expected %d, %.16g, got %d, %.16g\n", r, dt, res, out);
1794 #define DOS2DT(d,m,y,h,mn,s,r,dt) test_dos2dt(__LINE__,d,m,y,h,mn,s,r,dt)
1796 static void test_DosDateTimeToVariantTime(void)
1798 CHECKPTR(DosDateTimeToVariantTime);
1800 /* Date */
1801 DOS2DT(1,1,1980,0,0,0,1,29221.0); /* 1/1/1980 */
1802 DOS2DT(31,12,2099,0,0,0,1,73050.0); /* 31/12/2099 */
1803 /* Dates are limited to the dos date max of 31/12/2099 */
1804 DOS2DT(31,12,2100,0,0,0,0,0.0); /* 31/12/2100 */
1805 /* Days and months of 0 cause date to roll back 1 day or month */
1806 DOS2DT(0,1,1980,0,0,0,1,29220.0); /* 0 Day => 31/12/1979 */
1807 DOS2DT(1,0,1980,0,0,0,1,29190.0); /* 0 Mth => 1/12/1979 */
1808 DOS2DT(0,0,1980,0,0,0,1,29189.0); /* 0 D/M => 30/11/1979 */
1809 /* Days > days in the month cause date to roll forward 1 month */
1810 DOS2DT(29,2,1981,0,0,0,1,29646.0); /* 29/2/1981 -> 3/1/1980 */
1811 DOS2DT(30,2,1981,0,0,0,1,29647.0); /* 30/2/1981 -> 4/1/1980 */
1812 /* Takes leap years into account when rolling forward */
1813 DOS2DT(29,2,1980,0,0,0,1,29280.0); /* 2/29/1980 */
1814 /* Months > 12 cause an error */
1815 DOS2DT(2,13,1980,0,0,0,0,0.0);
1817 /* Time */
1818 DOS2DT(1,1,1980,0,0,29,1,29221.00032407407); /* 1/1/1980 12:00:28 AM */
1819 DOS2DT(1,1,1980,0,0,31,1,29221.00034722222); /* 1/1/1980 12:00:30 AM */
1820 DOS2DT(1,1,1980,0,59,0,1,29221.04097222222); /* 1/1/1980 12:59:00 AM */
1821 DOS2DT(1,1,1980,0,60,0,0,0.0); /* Invalid minutes */
1822 DOS2DT(1,1,1980,0,0,60,0,0.0); /* Invalid seconds */
1823 DOS2DT(1,1,1980,23,0,0,1,29221.95833333333); /* 1/1/1980 11:00:00 PM */
1824 DOS2DT(1,1,1980,24,0,0,0,0.0); /* Invalid hours */
1826 DOS2DT(1,1,1980,0,0,1,1,29221.0);
1827 DOS2DT(2,1,1980,0,0,0,1,29222.0);
1828 DOS2DT(2,1,1980,0,0,0,1,29222.0);
1829 DOS2DT(31,12,1990,0,0,0,1,33238.0);
1830 DOS2DT(31,12,90,0,0,0,1,40543.0);
1831 DOS2DT(30,12,1899,0,0,0,1,46751.0);
1832 DOS2DT(1,1,100,0,0,0,1,43831.0);
1833 DOS2DT(31,12,9999,0,0,0,1,59901.0);
1834 DOS2DT(1,1,10000,0,0,0,1,59902.0);
1835 DOS2DT(1,1,-10000,0,0,0,1,48214.0);
1837 DOS2DT(30,12,1899,0,0,0,1,46751.0);
1838 DOS2DT(30,12,1899,0,0,1,1,46751.0);
1840 DOS2DT(1,1,1980,18,1,16,1,29221.75087962963);
1841 DOS2DT(1,300,1980,18,1,16,1,29556.75087962963);
1842 DOS2DT(300,1,1980,18,1,16,1,29232.75087962963);
1843 DOS2DT(0,1,1980,42,1,16,1,29220.4175462963);
1844 DOS2DT(1,1,1980,17,61,16,0,0.0);
1845 DOS2DT(1,1,1980,18,0,76,1,29221.75013888889);
1846 DOS2DT(1,-300,1980,18,1,16,1,29312.75087962963);
1847 DOS2DT(-300,1,1980,18,1,16,1,29240.75087962963);
1848 DOS2DT(3,1,1980,-30,1,16,1,29223.08421296296);
1849 DOS2DT(1,1,1980,20,-119,16,1,29221.83976851852);
1850 DOS2DT(1,1,1980,18,3,-104,1,29221.75236111111);
1851 DOS2DT(1,12001,-1020,18,1,16,1,55519.75087962963);
1852 DOS2DT(1,-23,1982,18,1,16,1,30195.75087962963);
1853 DOS2DT(-59,3,1980,18,1,16,1,29285.75087962963);
1854 DOS2DT(1,1,0,0,0,0,1,54058.0);
1855 DOS2DT(0,0,1980,0,0,0,1,29189.0);
1856 DOS2DT(0,1,1980,0,0,0,1,29220.0);
1857 DOS2DT(-1,1,1980,18,1,16,1,29251.75087962963);
1858 DOS2DT(1,1,-1,18,1,16,1,53693.75087962963);
1859 DOS2DT(1,-1,1980,18,1,16,0,0);
1862 static void test_dt2dos(int line, double dt, INT r, WORD d, WORD m, WORD y,
1863 WORD h, WORD mn, WORD s)
1865 unsigned short dosDate, dosTime, expDosDate, expDosTime;
1866 INT res;
1868 dosTime = dosDate = 0;
1869 expDosDate = MKDOSDATE(d,m,y);
1870 expDosTime = MKDOSTIME(h,mn,s);
1871 res = pVariantTimeToDosDateTime(dt, &dosDate, &dosTime);
1872 ok_(__FILE__,line)(r == res && (!r || (dosTime == expDosTime && dosDate == expDosDate)),
1873 "%g: expected %d,%d(%d/%d/%d),%d(%d:%d:%d) got %d,%d(%d/%d/%d),%d(%d:%d:%d)\n",
1874 dt, r, expDosDate, expDosDate & 0x1f,
1875 (expDosDate >> 5) & 0xf, 1980 + (expDosDate >> 9),
1876 expDosTime, expDosTime >> 11, (expDosTime >> 5) & 0x3f,
1877 (expDosTime & 0x1f),
1878 res, dosDate, dosDate & 0x1f, (dosDate >> 5) & 0xf,
1879 1980 + (dosDate >> 9), dosTime, dosTime >> 11,
1880 (dosTime >> 5) & 0x3f, (dosTime & 0x1f));
1882 #define DT2DOS(dt,r,d,m,y,h,mn,s) test_dt2dos(__LINE__,dt,r,d,m,y,h,mn,s)
1884 static void test_VariantTimeToDosDateTime(void)
1886 CHECKPTR(VariantTimeToDosDateTime);
1888 /* Date */
1889 DT2DOS(29221.0,1,1,1,1980,0,0,0); /* 1/1/1980 */
1890 DT2DOS(73050.0,1,31,12,2099,0,0,0); /* 31/12/2099 */
1891 DT2DOS(29220.0,0,0,0,0,0,0,0); /* 31/12/1979 - out of range */
1892 DT2DOS(73415.0,0,0,0,0,0,0,0); /* 31/12/2100 - out of range */
1894 /* Time */
1895 DT2DOS(29221.00032407407,1,1,1,1980,0,0,29); /* 1/1/1980 12:00:28 AM */
1896 DT2DOS(29221.00034722222,1,1,1,1980,0,0,31); /* 1/1/1980 12:00:30 AM */
1897 DT2DOS(29221.04097222222,1,1,1,1980,0,59,0); /* 1/1/1980 12:59:00 AM */
1898 DT2DOS(29221.95833333333,1,1,1,1980,23,0,0); /* 1/1/1980 11:00:00 PM */
1901 static HRESULT (WINAPI *pVarAbs)(LPVARIANT,LPVARIANT);
1903 #define VARABS(vt,val,rvt,rval) \
1904 V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
1905 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
1906 test_var_call1( __LINE__, pVarAbs, &v, &exp )
1908 static void test_VarAbs(void)
1910 static WCHAR szNum[] = {'-','1','.','1','\0' };
1911 char buff[8];
1912 HRESULT hres;
1913 VARIANT v, vDst, exp;
1914 size_t i;
1916 CHECKPTR(VarAbs);
1918 /* Test all possible V_VT values.
1920 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
1922 VARTYPE vt;
1924 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
1926 HRESULT hExpected = DISP_E_BADVARTYPE;
1928 SKIPTESTS(vt);
1930 memset(&v, 0, sizeof(v));
1931 V_VT(&v) = vt | ExtraFlags[i];
1932 V_VT(&vDst) = VT_EMPTY;
1934 hres = pVarAbs(&v,&vDst);
1935 if (ExtraFlags[i] & (VT_ARRAY|VT_ARRAY) ||
1936 (!ExtraFlags[i] && (vt == VT_UNKNOWN || vt == VT_BSTR ||
1937 vt == VT_DISPATCH || vt == VT_ERROR || vt == VT_RECORD)))
1939 hExpected = DISP_E_TYPEMISMATCH;
1941 else if (ExtraFlags[i] || vt >= VT_CLSID || vt == VT_VARIANT)
1943 hExpected = DISP_E_BADVARTYPE;
1945 else if (IsValidVariantClearVT(vt, ExtraFlags[i]))
1946 hExpected = S_OK;
1948 /* Native always fails on some vartypes that should be valid. don't
1949 * check that Wine does the same; these are bugs in native.
1951 if (vt == VT_I8 || vt == VT_UI8 || vt == VT_INT || vt == VT_UINT ||
1952 vt == VT_I1 || vt == VT_UI2 || vt == VT_UI4)
1953 continue;
1954 ok(hres == hExpected, "VarAbs: expected 0x%X, got 0x%X for vt %d | 0x%X\n",
1955 hExpected, hres, vt, ExtraFlags[i]);
1959 /* BOOL->I2, BSTR->R8, all others remain the same */
1960 VARABS(BOOL,VARIANT_TRUE,I2,-VARIANT_TRUE);
1961 VARABS(BOOL,VARIANT_FALSE,I2,VARIANT_FALSE);
1962 VARABS(EMPTY,0,I2,0);
1963 VARABS(EMPTY,1,I2,0);
1964 VARABS(NULL,0,NULL,0);
1965 VARABS(NULL,1,NULL,0);
1966 VARABS(I2,1,I2,1);
1967 VARABS(I2,-1,I2,1);
1968 VARABS(I4,1,I4,1);
1969 VARABS(I4,-1,I4,1);
1970 VARABS(UI1,1,UI1,1);
1971 VARABS(R4,1,R4,1);
1972 VARABS(R4,-1,R4,1);
1973 VARABS(R8,1,R8,1);
1974 VARABS(R8,-1,R8,1);
1975 VARABS(DATE,1,DATE,1);
1976 VARABS(DATE,-1,DATE,1);
1977 V_VT(&v) = VT_CY;
1978 V_CY(&v).int64 = -10000;
1979 memset(&vDst,0,sizeof(vDst));
1980 hres = pVarAbs(&v,&vDst);
1981 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
1982 "VarAbs(CY): expected 0x0 got 0x%X\n", hres);
1983 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char));
1984 if (buff[1])
1986 trace("Skipping VarAbs(BSTR) as decimal separator is '%s'\n", buff);
1987 return;
1988 } else {
1989 szNum[2] = buff[0];
1991 V_VT(&v) = VT_BSTR;
1992 V_BSTR(&v) = (BSTR)szNum;
1993 memset(&vDst,0,sizeof(vDst));
1994 hres = pVarAbs(&v,&vDst);
1995 ok(hres == S_OK && V_VT(&vDst) == VT_R8 && V_R8(&vDst) == 1.1,
1996 "VarAbs: expected 0x0,%d,%g, got 0x%X,%d,%g\n", VT_R8, 1.1, hres, V_VT(&vDst), V_R8(&vDst));
1999 static HRESULT (WINAPI *pVarNot)(LPVARIANT,LPVARIANT);
2001 #define VARNOT(vt,val,rvt,rval) \
2002 V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
2003 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
2004 test_var_call1( __LINE__, pVarNot, &v, &exp )
2006 static void test_VarNot(void)
2008 static const WCHAR szNum0[] = {'0','\0' };
2009 static const WCHAR szNum1[] = {'1','\0' };
2010 static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
2011 static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
2012 HRESULT hres;
2013 VARIANT v, exp, vDst;
2014 DECIMAL *pdec = &V_DECIMAL(&v);
2015 CY *pcy = &V_CY(&v);
2016 size_t i;
2018 CHECKPTR(VarNot);
2020 /* Test all possible V_VT values */
2021 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2023 VARTYPE vt;
2025 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2027 HRESULT hExpected = DISP_E_BADVARTYPE;
2029 SKIPTESTS(vt);
2031 memset(&v, 0, sizeof(v));
2032 V_VT(&v) = vt | ExtraFlags[i];
2033 V_VT(&vDst) = VT_EMPTY;
2035 switch (V_VT(&v))
2037 case VT_I1: case VT_UI1: case VT_I2: case VT_UI2:
2038 case VT_INT: case VT_UINT: case VT_I4: case VT_UI4:
2039 case VT_R4: case VT_R8:
2040 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
2041 case VT_DATE: case VT_CY:
2042 hExpected = S_OK;
2043 break;
2044 case VT_I8: case VT_UI8:
2045 if (HAVE_OLEAUT32_I8)
2046 hExpected = S_OK;
2047 break;
2048 case VT_RECORD:
2049 if (HAVE_OLEAUT32_RECORD)
2050 hExpected = DISP_E_TYPEMISMATCH;
2051 break;
2052 case VT_UNKNOWN: case VT_BSTR: case VT_DISPATCH: case VT_ERROR:
2053 hExpected = DISP_E_TYPEMISMATCH;
2054 break;
2055 default:
2056 if (IsValidVariantClearVT(vt, ExtraFlags[i]) && vt != VT_CLSID)
2057 hExpected = DISP_E_TYPEMISMATCH;
2058 break;
2061 hres = pVarNot(&v,&vDst);
2062 ok(hres == hExpected, "VarNot: expected 0x%X, got 0x%X vt %d|0x%X\n",
2063 hExpected, hres, vt, ExtraFlags[i]);
2066 /* Test the values returned by all cases that can succeed */
2067 VARNOT(EMPTY,0,I2,-1);
2068 VARNOT(EMPTY,1,I2,-1);
2069 VARNOT(NULL,0,NULL,0);
2070 VARNOT(NULL,1,NULL,0);
2071 VARNOT(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
2072 VARNOT(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
2073 VARNOT(I1,-1,I4,0);
2074 VARNOT(I1,0,I4,-1);
2075 VARNOT(I2,-1,I2,0);
2076 VARNOT(I2,0,I2,-1);
2077 VARNOT(I2,1,I2,-2);
2078 VARNOT(I4,1,I4,-2);
2079 VARNOT(I4,0,I4,-1);
2080 VARNOT(UI1,1,UI1,254);
2081 VARNOT(UI1,0,UI1,255);
2082 VARNOT(UI2,0,I4,-1);
2083 VARNOT(UI2,1,I4,-2);
2084 VARNOT(UI4,0,I4,-1);
2085 VARNOT(UI4,1,I4,-2);
2086 VARNOT(INT,0,I4,-1);
2087 VARNOT(INT,1,I4,-2);
2088 VARNOT(UINT,0,I4,-1);
2089 VARNOT(UINT,1,I4,-2);
2090 if (HAVE_OLEAUT32_I8)
2092 VARNOT(I8,1,I8,-2);
2093 VARNOT(I8,0,I8,-1);
2094 VARNOT(UI8,0,I4,-1);
2095 VARNOT(UI8,1,I4,-2);
2097 VARNOT(R4,1,I4,-2);
2098 VARNOT(R4,0,I4,-1);
2099 VARNOT(R8,1,I4,-2);
2100 VARNOT(R8,0,I4,-1);
2101 VARNOT(DATE,1,I4,-2);
2102 VARNOT(DATE,0,I4,-1);
2103 VARNOT(BSTR,(BSTR)szNum0,I4,-1);
2104 ok(V_VT(&v) == VT_BSTR && V_BSTR(&v) == szNum0, "VarNot(0): changed input\n");
2105 VARNOT(BSTR,(BSTR)szNum1,I4,-2);
2106 ok(V_VT(&v) == VT_BSTR && V_BSTR(&v) == szNum1, "VarNot(1): changed input\n");
2107 VARNOT(BSTR, (BSTR)szTrue, BOOL, VARIANT_FALSE);
2108 VARNOT(BSTR, (BSTR)szFalse, BOOL, VARIANT_TRUE);
2110 V_VT(&v) = VT_DECIMAL;
2111 S(U(*pdec)).sign = DECIMAL_NEG;
2112 S(U(*pdec)).scale = 0;
2113 pdec->Hi32 = 0;
2114 S1(U1(*pdec)).Mid32 = 0;
2115 S1(U1(*pdec)).Lo32 = 1;
2116 VARNOT(DECIMAL,*pdec,I4,0);
2118 pcy->int64 = 10000;
2119 VARNOT(CY,*pcy,I4,-2);
2121 pcy->int64 = 0;
2122 VARNOT(CY,*pcy,I4,-1);
2124 pcy->int64 = -1;
2125 VARNOT(CY,*pcy,I4,-1);
2128 static HRESULT (WINAPI *pVarSub)(LPVARIANT,LPVARIANT,LPVARIANT);
2130 #define VARSUB(vt1,val1,vt2,val2,rvt,rval) \
2131 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
2132 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
2133 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
2134 test_var_call2( __LINE__, pVarSub, &left, &right, &exp )
2136 static void test_VarSub(void)
2138 VARIANT left, right, exp, result, cy, dec;
2139 VARTYPE i;
2140 BSTR lbstr, rbstr;
2141 HRESULT hres, expectedhres;
2142 double r;
2144 CHECKPTR(VarSub);
2146 lbstr = SysAllocString(sz12);
2147 rbstr = SysAllocString(sz12);
2149 VariantInit(&left);
2150 VariantInit(&right);
2151 VariantInit(&result);
2153 /* Test all possible flag/vt combinations & the resulting vt type */
2154 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2157 VARTYPE leftvt, rightvt, resvt;
2159 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
2162 SKIPTESTS(leftvt);
2164 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
2167 SKIPTESTS(rightvt);
2168 expectedhres = S_OK;
2170 memset(&left, 0, sizeof(left));
2171 memset(&right, 0, sizeof(right));
2172 V_VT(&left) = leftvt | ExtraFlags[i];
2173 if (leftvt == VT_BSTR)
2174 V_BSTR(&left) = lbstr;
2175 V_VT(&right) = rightvt | ExtraFlags[i];
2176 if (rightvt == VT_BSTR)
2177 V_BSTR(&right) = rbstr;
2178 V_VT(&result) = VT_EMPTY;
2180 /* All extra flags produce errors */
2181 if (ExtraFlags[i] == (VT_VECTOR|VT_BYREF|VT_RESERVED) ||
2182 ExtraFlags[i] == (VT_VECTOR|VT_RESERVED) ||
2183 ExtraFlags[i] == (VT_VECTOR|VT_BYREF) ||
2184 ExtraFlags[i] == (VT_BYREF|VT_RESERVED) ||
2185 ExtraFlags[i] == VT_VECTOR ||
2186 ExtraFlags[i] == VT_BYREF ||
2187 ExtraFlags[i] == VT_RESERVED)
2189 expectedhres = DISP_E_BADVARTYPE;
2190 resvt = VT_EMPTY;
2192 else if (ExtraFlags[i] >= VT_ARRAY)
2194 expectedhres = DISP_E_TYPEMISMATCH;
2195 resvt = VT_EMPTY;
2197 /* Native VarSub cannot handle: VT_I1, VT_UI2, VT_UI4,
2198 VT_INT, VT_UINT and VT_UI8. Tested with WinXP */
2199 else if (!IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
2200 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
2201 leftvt == VT_CLSID || rightvt == VT_CLSID ||
2202 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
2203 leftvt == VT_I1 || rightvt == VT_I1 ||
2204 leftvt == VT_UI2 || rightvt == VT_UI2 ||
2205 leftvt == VT_UI4 || rightvt == VT_UI4 ||
2206 leftvt == VT_UI8 || rightvt == VT_UI8 ||
2207 leftvt == VT_INT || rightvt == VT_INT ||
2208 leftvt == VT_UINT || rightvt == VT_UINT ||
2209 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN ||
2210 leftvt == VT_RECORD || rightvt == VT_RECORD)
2212 if (leftvt == VT_RECORD && rightvt == VT_I8)
2214 if (HAVE_OLEAUT32_I8)
2215 expectedhres = DISP_E_TYPEMISMATCH;
2216 else
2217 expectedhres = DISP_E_BADVARTYPE;
2219 else if (leftvt < VT_UI1 && rightvt == VT_RECORD)
2220 expectedhres = DISP_E_TYPEMISMATCH;
2221 else if (leftvt >= VT_UI1 && rightvt == VT_RECORD)
2222 expectedhres = DISP_E_TYPEMISMATCH;
2223 else if (leftvt == VT_RECORD && rightvt <= VT_UI1)
2224 expectedhres = DISP_E_TYPEMISMATCH;
2225 else if (leftvt == VT_RECORD && rightvt > VT_UI1)
2226 expectedhres = DISP_E_BADVARTYPE;
2227 else
2228 expectedhres = DISP_E_BADVARTYPE;
2229 resvt = VT_EMPTY;
2231 else if ((leftvt == VT_NULL && rightvt == VT_DISPATCH) ||
2232 (leftvt == VT_DISPATCH && rightvt == VT_NULL))
2233 resvt = VT_NULL;
2234 else if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
2235 leftvt == VT_ERROR || rightvt == VT_ERROR)
2237 resvt = VT_EMPTY;
2238 expectedhres = DISP_E_TYPEMISMATCH;
2240 else if (leftvt == VT_NULL || rightvt == VT_NULL)
2241 resvt = VT_NULL;
2242 else if ((leftvt == VT_EMPTY && rightvt == VT_BSTR) ||
2243 (leftvt == VT_DATE && rightvt == VT_DATE) ||
2244 (leftvt == VT_BSTR && rightvt == VT_EMPTY) ||
2245 (leftvt == VT_BSTR && rightvt == VT_BSTR))
2246 resvt = VT_R8;
2247 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
2248 resvt = VT_DECIMAL;
2249 else if (leftvt == VT_DATE || rightvt == VT_DATE)
2250 resvt = VT_DATE;
2251 else if (leftvt == VT_CY || rightvt == VT_CY)
2252 resvt = VT_CY;
2253 else if (leftvt == VT_R8 || rightvt == VT_R8)
2254 resvt = VT_R8;
2255 else if (leftvt == VT_BSTR || rightvt == VT_BSTR) {
2256 resvt = VT_R8;
2257 } else if (leftvt == VT_R4 || rightvt == VT_R4) {
2258 if (leftvt == VT_I4 || rightvt == VT_I4 ||
2259 leftvt == VT_I8 || rightvt == VT_I8)
2260 resvt = VT_R8;
2261 else
2262 resvt = VT_R4;
2264 else if (leftvt == VT_I8 || rightvt == VT_I8)
2265 resvt = VT_I8;
2266 else if (leftvt == VT_I4 || rightvt == VT_I4)
2267 resvt = VT_I4;
2268 else if (leftvt == VT_I2 || rightvt == VT_I2 ||
2269 leftvt == VT_BOOL || rightvt == VT_BOOL ||
2270 (leftvt == VT_EMPTY && rightvt == VT_EMPTY))
2271 resvt = VT_I2;
2272 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
2273 resvt = VT_UI1;
2274 else
2276 resvt = VT_EMPTY;
2277 expectedhres = DISP_E_TYPEMISMATCH;
2280 hres = pVarSub(&left, &right, &result);
2282 ok(hres == expectedhres && V_VT(&result) == resvt,
2283 "VarSub: %d|0x%X, %d|0x%X: Expected failure 0x%X, "
2284 "got 0x%X, expected vt %d got vt %d\n",
2285 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i],
2286 expectedhres, hres, resvt, V_VT(&result));
2291 /* Test returned values */
2292 VARSUB(I4,4,I4,2,I4,2);
2293 VARSUB(I2,4,I2,2,I2,2);
2294 VARSUB(I2,-13,I4,5,I4,-18);
2295 VARSUB(I4,-13,I4,5,I4,-18);
2296 VARSUB(I2,7,R4,0.5f,R4,6.5f);
2297 VARSUB(R4,0.5f,I4,5,R8,-4.5);
2298 VARSUB(R8,7.1,BOOL,0,R8,7.1);
2299 VARSUB(BSTR,lbstr,I2,4,R8,8);
2300 VARSUB(BSTR,lbstr,BOOL,1,R8,11);
2301 VARSUB(BSTR,lbstr,R4,0.1f,R8,11.9);
2302 VARSUB(R4,0.2f,BSTR,rbstr,R8,-11.8);
2303 VARSUB(DATE,2.25,I4,7,DATE,-4.75);
2304 VARSUB(DATE,1.25,R4,-1.7f,DATE,2.95);
2306 VARSUB(UI1, UI1_MAX, UI1, UI1_MAX, UI1, 0);
2307 VARSUB(I2, I2_MAX, I2, I2_MAX, I2, 0);
2308 VARSUB(I2, I2_MIN, I2, I2_MIN, I2, 0);
2309 VARSUB(I4, I4_MAX, I4, I4_MAX, I4, 0);
2310 VARSUB(I4, I4_MIN, I4, I4_MIN, I4, 0);
2311 VARSUB(R4, R4_MAX, R4, R4_MAX, R4, 0.0f);
2312 VARSUB(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX - R4_MIN);
2313 VARSUB(R4, R4_MIN, R4, R4_MIN, R4, 0.0f);
2314 VARSUB(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX - R8_MIN);
2315 VARSUB(R8, R8_MIN, R8, R8_MIN, R8, 0.0);
2317 /* Manually test BSTR + BSTR */
2318 V_VT(&left) = VT_BSTR;
2319 V_BSTR(&left) = lbstr;
2320 V_VT(&right) = VT_BSTR;
2321 V_BSTR(&right) = rbstr;
2322 hres = pVarSub(&left, &right, &result);
2323 ok(hres == S_OK && V_VT(&result) == VT_R8,
2324 "VarSub: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
2325 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 0),
2326 "VarSub: BSTR + BSTR, expected %f got %f\n", 0.0, V_R8(&result));
2328 /* Manually test some VT_CY and VT_DECIMAL variants */
2329 V_VT(&cy) = VT_CY;
2330 hres = VarCyFromI4(4711, &V_CY(&cy));
2331 ok(hres == S_OK, "VarCyFromI4 failed!\n");
2332 V_VT(&dec) = VT_DECIMAL;
2333 hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec));
2334 ok(hres == S_OK, "VarDecFromR4 failed!\n");
2335 memset(&left, 0, sizeof(left));
2336 memset(&right, 0, sizeof(right));
2337 V_VT(&left) = VT_I4;
2338 V_I4(&left) = -11;
2339 V_VT(&right) = VT_UI1;
2340 V_UI1(&right) = 9;
2342 hres = pVarSub(&cy, &right, &result);
2343 ok(hres == S_OK && V_VT(&result) == VT_CY,
2344 "VarSub: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result)));
2345 hres = VarR8FromCy(V_CY(&result), &r);
2346 ok(hres == S_OK && EQ_DOUBLE(r, 4702),
2347 "VarSub: CY value %f, expected %f\n", r, (double)4720);
2349 hres = pVarSub(&left, &dec, &result);
2350 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
2351 "VarSub: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
2352 hres = VarR8FromDec(&V_DECIMAL(&result), &r);
2353 ok(hres == S_OK && EQ_DOUBLE(r, -6.8),
2354 "VarSub: DECIMAL value %f, expected %f\n", r, (double)-15.2);
2356 SysFreeString(lbstr);
2357 SysFreeString(rbstr);
2360 static HRESULT (WINAPI *pVarMod)(LPVARIANT,LPVARIANT,LPVARIANT);
2362 static void test_Mod( int line, VARIANT *left, VARIANT *right, VARIANT *expected, HRESULT expres )
2364 VARIANT result;
2365 HRESULT hres;
2367 memset( &result, 0, sizeof(result) );
2368 hres = pVarMod( left, right, &result );
2369 ok_(__FILE__,line)( hres == expres, "wrong result %x/%x\n", hres, expres );
2370 if (hres == S_OK)
2371 ok_(__FILE__,line)( is_expected_variant( &result, expected ),
2372 "got %s expected %s\n", variantstr(&result), variantstr(expected) );
2375 #define VARMOD(vt1,vt2,val1,val2,rvt,rval) \
2376 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
2377 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
2378 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
2379 test_var_call2( __LINE__, pVarMod, &left, &right, &exp )
2381 #define VARMOD2(vt1,vt2,val1,val2,rvt,rval,hexpected) \
2382 V_VT(&left) = VT_##vt1; V_I4(&left) = val1; \
2383 V_VT(&right) = VT_##vt2; V_I4(&right) = val2; \
2384 V_VT(&exp) = VT_##rvt; V_I4(&exp) = rval; \
2385 test_Mod( __LINE__, &left, &right, &exp, hexpected )
2387 static void test_VarMod(void)
2389 VARIANT v1, v2, vDst, left, right, exp;
2390 HRESULT hres;
2391 HRESULT hexpected = 0;
2392 static const WCHAR szNum0[] = {'1','2','5','\0'};
2393 static const WCHAR szNum1[] = {'1','0','\0'};
2394 int l, r;
2395 BOOL lFound, rFound;
2396 BOOL lValid;
2397 BSTR strNum0, strNum1;
2399 CHECKPTR(VarMod);
2401 VARMOD(I1,BOOL,100,10,I4,0);
2402 VARMOD(I1,I1,100,10,I4,0);
2403 VARMOD(I1,UI1,100,10,I4,0);
2404 VARMOD(I1,I2,100,10,I4,0);
2405 VARMOD(I1,UI2,100,10,I4,0);
2406 VARMOD(I1,I4,100,10,I4,0);
2407 VARMOD(I1,UI4,100,10,I4,0);
2408 VARMOD(I1,R4,100,10,I4,0);
2409 VARMOD(I1,R8,100,10,I4,0);
2411 VARMOD(UI1,BOOL,100,10,I2,0);
2412 VARMOD(UI1,I1,100,10,I4,0);
2413 VARMOD(UI1,UI1,100,10,UI1,0);
2414 VARMOD(UI1,I2,100,10,I2,0);
2415 VARMOD(UI1,UI2,100,10,I4,0);
2416 VARMOD(UI1,I4,100,10,I4,0);
2417 VARMOD(UI1,UI4,100,10,I4,0);
2418 VARMOD(UI1,R4,100,10,I4,0);
2419 VARMOD(UI1,R8,100,10,I4,0);
2421 VARMOD(I2,BOOL,100,10,I2,0);
2422 VARMOD(I2,I1,100,10,I4,0);
2423 VARMOD(I2,UI1,100,10,I2,0);
2424 VARMOD(I2,I2,100,10,I2,0);
2425 VARMOD(I2,UI2,100,10,I4,0);
2426 VARMOD(I2,I4,100,10,I4,0);
2427 VARMOD(I2,UI4,100,10,I4,0);
2428 VARMOD(I2,R4,100,10,I4,0);
2429 VARMOD(I2,R8,100,10,I4,0);
2431 VARMOD(I4,BOOL,100,10,I4,0);
2432 VARMOD(I4,I1,100,10,I4,0);
2433 VARMOD(I4,UI1,100,10,I4,0);
2434 VARMOD(I4,I2,100,10,I4,0);
2435 VARMOD(I4,UI2,100,10,I4,0);
2436 VARMOD(I4,I4,100,10,I4,0);
2437 VARMOD(I4,UI4,100,10,I4,0);
2438 VARMOD(I4,R4,100,10,I4,0);
2439 VARMOD(I4,R8,100,10,I4,0);
2440 VARMOD(UI4,BOOL,100,10,I4,0);
2441 VARMOD(UI4,I1,100,10,I4,0);
2442 VARMOD(UI4,UI1,100,10,I4,0);
2443 VARMOD(UI4,I2,100,10,I4,0);
2444 VARMOD(UI4,UI2,100,10,I4,0);
2445 VARMOD(UI4,I4,100,10,I4,0);
2446 VARMOD(UI4,UI4,100,10,I4,0);
2447 VARMOD(UI4,R4,100,10,I4,0);
2448 VARMOD(UI4,R8,100,10,I4,0);
2449 VARMOD(R4,BOOL,100,10,I4,0);
2450 VARMOD(R4,I1,100,10,I4,0);
2451 VARMOD(R4,UI1,100,10,I4,0);
2452 VARMOD(R4,I2,100,10,I4,0);
2453 VARMOD(R4,UI2,100,10,I4,0);
2454 VARMOD(R4,I4,100,10,I4,0);
2455 VARMOD(R4,UI4,100,10,I4,0);
2456 VARMOD(R4,R4,100,10,I4,0);
2457 VARMOD(R4,R8,100,10,I4,0);
2458 VARMOD(R8,BOOL,100,10,I4,0);
2459 VARMOD(R8,I1,100,10,I4,0);
2460 VARMOD(R8,UI1,100,10,I4,0);
2461 VARMOD(R8,I2,100,10,I4,0);
2462 VARMOD(R8,UI2,100,10,I4,0);
2463 VARMOD(R8,I4,100,10,I4,0);
2464 VARMOD(R8,UI4,100,10,I4,0);
2465 VARMOD(R8,R4,100,10,I4,0);
2466 VARMOD(R8,R8,100,10,I4,0);
2468 VARMOD(INT,INT,100,10,I4,0);
2469 VARMOD(INT,UINT,100,10,I4,0);
2471 VARMOD(BOOL,BOOL,100,10,I2,0);
2472 VARMOD(BOOL,I1,100,10,I4,0);
2473 VARMOD(BOOL,UI1,100,10,I2,0);
2474 VARMOD(BOOL,I2,100,10,I2,0);
2475 VARMOD(BOOL,UI2,100,10,I4,0);
2476 VARMOD(BOOL,I4,100,10,I4,0);
2477 VARMOD(BOOL,UI4,100,10,I4,0);
2478 VARMOD(BOOL,R4,100,10,I4,0);
2479 VARMOD(BOOL,R8,100,10,I4,0);
2480 VARMOD(BOOL,DATE,100,10,I4,0);
2482 VARMOD(DATE,BOOL,100,10,I4,0);
2483 VARMOD(DATE,I1,100,10,I4,0);
2484 VARMOD(DATE,UI1,100,10,I4,0);
2485 VARMOD(DATE,I2,100,10,I4,0);
2486 VARMOD(DATE,UI2,100,10,I4,0);
2487 VARMOD(DATE,I4,100,10,I4,0);
2488 VARMOD(DATE,UI4,100,10,I4,0);
2489 VARMOD(DATE,R4,100,10,I4,0);
2490 VARMOD(DATE,R8,100,10,I4,0);
2491 VARMOD(DATE,DATE,100,10,I4,0);
2493 strNum0 = SysAllocString(szNum0);
2494 strNum1 = SysAllocString(szNum1);
2495 VARMOD(BSTR,BSTR,strNum0,strNum1,I4,5);
2496 VARMOD(BSTR,I1,strNum0,10,I4,5);
2497 VARMOD(BSTR,I2,strNum0,10,I4,5);
2498 VARMOD(BSTR,I4,strNum0,10,I4,5);
2499 VARMOD(BSTR,R4,strNum0,10,I4,5);
2500 VARMOD(BSTR,R8,strNum0,10,I4,5);
2501 VARMOD(I4,BSTR,125,strNum1,I4,5);
2503 if (HAVE_OLEAUT32_I8)
2505 VARMOD(BOOL,I8,100,10,I8,0);
2506 VARMOD(I1,I8,100,10,I8,0);
2507 VARMOD(UI1,I8,100,10,I8,0);
2508 VARMOD(I2,I8,100,10,I8,0);
2509 VARMOD(I4,I8,100,10,I8,0);
2510 VARMOD(UI4,I8,100,10,I8,0);
2511 VARMOD(R4,I8,100,10,I8,0);
2512 VARMOD(R8,I8,100,10,I8,0);
2513 VARMOD(DATE,I8,100,10,I8,0);
2515 VARMOD(I8,BOOL,100,10,I8,0);
2516 VARMOD(I8,I1,100,10,I8,0);
2517 VARMOD(I8,UI1,100,10,I8,0);
2518 VARMOD(I8,I2,100,10,I8,0);
2519 VARMOD(I8,UI2,100,10,I8,0);
2520 VARMOD(I8,I4,100,10,I8,0);
2521 VARMOD(I8,UI4,100,10,I8,0);
2522 VARMOD(I8,R4,100,10,I8,0);
2523 VARMOD(I8,R8,100,10,I8,0);
2524 VARMOD(I8,I8,100,10,I8,0);
2526 VARMOD(BSTR,I8,strNum0,10,I8,5);
2529 /* test all combinations of types */
2530 for(l = 0; l < VT_BSTR_BLOB; l++)
2532 SKIPTESTS(l);
2534 for(r = 0; r < VT_BSTR_BLOB; r++)
2536 SKIPTESTS(r);
2538 if(l == VT_BSTR) continue;
2539 if(l == VT_DISPATCH) continue;
2540 if(r == VT_BSTR) continue;
2541 if(r == VT_DISPATCH) continue;
2543 lFound = TRUE;
2544 lValid = TRUE;
2545 switch(l)
2547 case VT_EMPTY:
2548 case VT_NULL:
2549 case VT_I1:
2550 case VT_UI1:
2551 case VT_I2:
2552 case VT_UI2:
2553 case VT_I4:
2554 case VT_I8:
2555 case VT_UI4:
2556 case VT_UI8:
2557 case VT_INT:
2558 case VT_UINT:
2559 case VT_R4:
2560 case VT_R8:
2561 case VT_BOOL:
2562 case VT_DATE:
2563 case VT_CY:
2564 case VT_DECIMAL:
2565 hexpected = S_OK;
2566 break;
2567 case VT_ERROR:
2568 case VT_VARIANT:
2569 case VT_UNKNOWN:
2570 case VT_RECORD:
2571 lValid = FALSE;
2572 break;
2573 default:
2574 lFound = FALSE;
2575 hexpected = DISP_E_BADVARTYPE;
2576 break;
2579 rFound = TRUE;
2580 switch(r)
2582 case VT_EMPTY:
2583 case VT_NULL:
2584 case VT_I1:
2585 case VT_UI1:
2586 case VT_I2:
2587 case VT_UI2:
2588 case VT_I4:
2589 case VT_I8:
2590 case VT_UI4:
2591 case VT_UI8:
2592 case VT_INT:
2593 case VT_UINT:
2594 case VT_R4:
2595 case VT_R8:
2596 case VT_BOOL:
2597 case VT_DATE:
2598 case VT_DECIMAL:
2599 case VT_CY:
2600 hexpected = S_OK;
2601 break;
2602 case VT_ERROR:
2603 case VT_VARIANT:
2604 case VT_UNKNOWN:
2605 case VT_RECORD:
2606 break;
2607 default:
2608 rFound = FALSE;
2609 break;
2612 if(((l == VT_I8) && (r == VT_INT)) || ((l == VT_INT) && (r == VT_I8)))
2614 hexpected = DISP_E_TYPEMISMATCH;
2615 } else if((l == VT_EMPTY) && (r == VT_NULL))
2617 hexpected = S_OK;
2618 } else if((l == VT_NULL) && (r == VT_EMPTY))
2620 hexpected = S_OK;
2621 } else if((l == VT_EMPTY) && (r == VT_CY))
2623 hexpected = S_OK;
2624 } else if((l == VT_EMPTY) && (r == VT_RECORD))
2626 hexpected = DISP_E_TYPEMISMATCH;
2627 } else if((r == VT_EMPTY) && lFound && lValid)
2629 hexpected = DISP_E_DIVBYZERO;
2630 } else if((l == VT_ERROR) || ((r == VT_ERROR) && lFound && lValid))
2632 hexpected = DISP_E_TYPEMISMATCH;
2633 } else if((l == VT_NULL) && (r == VT_NULL))
2635 hexpected = S_OK;
2636 } else if((l == VT_VARIANT) || ((r == VT_VARIANT) && lFound && lValid))
2638 hexpected = DISP_E_TYPEMISMATCH;
2639 } else if((l == VT_NULL) && (r == VT_RECORD))
2641 hexpected = DISP_E_TYPEMISMATCH;
2642 } else if((l == VT_I8) && (r == VT_DECIMAL))
2644 hexpected = S_OK;
2645 } else if((l == VT_DECIMAL) && (r == VT_I8))
2647 hexpected = S_OK;
2648 } else if((l == VT_UNKNOWN) || ((r == VT_UNKNOWN) && lFound && lValid))
2650 hexpected = DISP_E_TYPEMISMATCH;
2651 } else if((l == VT_NULL) && rFound)
2653 hexpected = S_OK;
2654 } else if(l == VT_RECORD)
2656 hexpected = DISP_E_TYPEMISMATCH;
2657 } else if((r == VT_RECORD) && lValid && lFound)
2659 hexpected = DISP_E_TYPEMISMATCH;
2660 } else if((l == VT_EMPTY) && (r == VT_EMPTY))
2662 hexpected = DISP_E_DIVBYZERO;
2663 } else if((l == VT_CY) && !rFound)
2665 hexpected = DISP_E_BADVARTYPE;
2666 } else if(lFound && !rFound)
2668 hexpected = DISP_E_BADVARTYPE;
2669 } else if(!lFound && rFound)
2671 hexpected = DISP_E_BADVARTYPE;
2672 } else if((r == VT_NULL) && lFound && lValid)
2674 hexpected = S_OK;
2675 } else if((l == VT_NULL) || (r == VT_NULL))
2677 hexpected = DISP_E_BADVARTYPE;
2678 } else if((l == VT_VARIANT) || (r == VT_VARIANT))
2680 hexpected = DISP_E_BADVARTYPE;
2681 } else if(lFound && !rFound)
2683 hexpected = DISP_E_BADVARTYPE;
2684 } else if(!lFound && !rFound)
2686 hexpected = DISP_E_BADVARTYPE;
2689 V_VT(&v1) = l;
2690 V_VT(&v2) = r;
2692 if(l == VT_CY)
2693 V_CY(&v1).int64 = 1000000;
2694 else if(l == VT_R4)
2695 V_R4(&v1) = 100;
2696 else if(l == VT_R8)
2697 V_R8(&v1) = 100;
2698 else if(l == VT_UI8)
2699 V_UI8(&v1) = 100;
2700 else if(l == VT_I8)
2701 V_I8(&v1) = 100;
2702 else if(l == VT_DATE)
2703 V_DATE(&v1) = 1000;
2704 else if (l == VT_DECIMAL)
2706 V_DECIMAL(&v1).Hi32 = 0;
2707 U1(V_DECIMAL(&v1)).Lo64 = 100;
2708 U(V_DECIMAL(&v1)).signscale = 0;
2710 else
2711 V_I4(&v1) = 10000;
2713 if(r == VT_CY)
2714 V_CY(&v2).int64 = 10000;
2715 else if(r == VT_R4)
2716 V_R4(&v2) = 100;
2717 else if(r == VT_R8)
2718 V_R8(&v2) = 100;
2719 else if(r == VT_UI8)
2720 V_UI8(&v2) = 100;
2721 else if(r == VT_I8)
2722 V_I8(&v2) = 100;
2723 else if(r == VT_DATE)
2724 V_DATE(&v2) = 1000;
2725 else if (r == VT_DECIMAL)
2727 V_DECIMAL(&v2).Hi32 = 0;
2728 U1(V_DECIMAL(&v2)).Lo64 = 100;
2729 U(V_DECIMAL(&v2)).signscale = 0;
2731 else
2732 V_I4(&v2) = 10000;
2734 if ((l != VT_I8 && l != VT_UI8 && r != VT_I8 && r != VT_UI8) || HAVE_OLEAUT32_I8)
2736 hres = pVarMod(&v1,&v2,&vDst);
2737 ok(hres == hexpected,
2738 "VarMod: expected 0x%x, got 0x%X for l type of %d, r type of %d,\n", hexpected, hres, l, r);
2744 /****************************/
2745 /* test some bad parameters */
2746 VARMOD(I4,I4,-1,-1,I4,0);
2748 /* test modulus with zero */
2749 VARMOD2(I4,I4,100,0,EMPTY,0,DISP_E_DIVBYZERO);
2751 VARMOD(I4,I4,0,10,I4,0); /* test 0 mod 10 */
2753 /* right parameter is type empty */
2754 VARMOD2(I4,EMPTY,100,10,EMPTY,0,DISP_E_DIVBYZERO);
2756 /* left parameter is type empty */
2757 VARMOD2(EMPTY,I4,100,10,I4,0,S_OK);
2759 /* mod with a null left value */
2760 VARMOD2(NULL,I4,125,10,NULL,0,S_OK);
2762 /* mod with a null right value */
2763 VARMOD2(I4,NULL,100,10,NULL,0,S_OK);
2765 /* void left value */
2766 VARMOD2(VOID,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2768 /* void right value */
2769 VARMOD2(I4,VOID,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2771 /* null left value, void right value */
2772 VARMOD2(NULL,VOID,100,10,EMPTY, 0, DISP_E_BADVARTYPE);
2774 /* void left value, null right value */
2775 VARMOD2(VOID,NULL,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2777 /* some currencies */
2778 V_VT(&v1) = VT_CY;
2779 V_VT(&v2) = VT_CY;
2780 V_CY(&v1).int64 = 100000;
2781 V_CY(&v2).int64 = 100000;
2782 hres = pVarMod(&v1,&v2,&vDst);
2783 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
2784 "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
2786 V_VT(&v1) = VT_I4;
2787 V_VT(&v2) = VT_CY;
2788 V_I4(&v1) = 100;
2789 V_CY(&v2).int64 = 100000;
2790 hres = pVarMod(&v1,&v2,&vDst);
2791 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
2792 "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
2794 /* some decimals */
2795 V_VT(&v1) = VT_DECIMAL;
2796 V_VT(&v2) = VT_DECIMAL;
2797 VarDecFromI4(100, &V_DECIMAL(&v1));
2798 VarDecFromI4(10, &V_DECIMAL(&v2));
2799 hres = pVarMod(&v1,&v2,&vDst);
2800 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
2801 "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
2803 V_VT(&v1) = VT_I4;
2804 V_VT(&v2) = VT_DECIMAL;
2805 V_I4(&v1) = 100;
2806 VarDecFromI4(10, &V_DECIMAL(&v2));
2807 hres = pVarMod(&v1,&v2,&vDst);
2808 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
2809 "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
2811 VARMOD2(UINT,I4,100,10,I4,0,S_OK);
2813 /* test that an error results in the type of the result changing but not its value */
2814 V_VT(&v1) = VT_UNKNOWN;
2815 V_VT(&v2) = VT_EMPTY;
2816 V_I4(&v1) = 100;
2817 V_CY(&v2).int64 = 100000;
2818 V_VT(&vDst) = VT_I4;
2819 V_I4(&vDst) = 1231;
2820 hres = pVarMod(&v1,&v2,&vDst);
2821 ok(hres == DISP_E_TYPEMISMATCH && V_VT(&vDst) == VT_EMPTY && V_I4(&vDst) == 1231,
2822 "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", DISP_E_TYPEMISMATCH, VT_EMPTY, 1231, hres, V_VT(&vDst), V_I4(&vDst));
2825 /* test some invalid types */
2826 /*TODO: not testing VT_DISPATCH */
2827 if (HAVE_OLEAUT32_I8)
2829 VARMOD2(I8,INT,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
2831 VARMOD2(ERROR,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
2832 VARMOD2(VARIANT,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
2833 VARMOD2(UNKNOWN,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
2834 VARMOD2(VOID,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2835 VARMOD2(HRESULT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2836 VARMOD2(PTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2837 VARMOD2(SAFEARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2838 VARMOD2(CARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2839 VARMOD2(USERDEFINED,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2840 VARMOD2(LPSTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2841 VARMOD2(LPWSTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2842 VARMOD2(RECORD,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
2843 VARMOD2(FILETIME,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2844 VARMOD2(BLOB,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2845 VARMOD2(STREAM,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2846 VARMOD2(STORAGE,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2847 VARMOD2(STREAMED_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2848 VARMOD2(STORED_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2849 VARMOD2(BLOB_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2850 VARMOD2(CF,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2851 VARMOD2(CLSID,CLSID,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2852 VARMOD2(VECTOR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2853 VARMOD2(ARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2854 VARMOD2(BYREF,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2856 /* test some more invalid types */
2857 V_VT(&v1) = 456;
2858 V_VT(&v2) = 234;
2859 V_I4(&v1) = 100;
2860 V_I4(&v2)= 10;
2861 hres = pVarMod(&v1,&v2,&vDst);
2862 ok(hres == DISP_E_BADVARTYPE && V_VT(&vDst) == VT_EMPTY,
2863 "VarMod: expected 0x%x,%d, got 0x%X,%d\n", DISP_E_BADVARTYPE, VT_EMPTY, hres, V_VT(&vDst));
2865 SysFreeString(strNum0);
2866 SysFreeString(strNum1);
2869 static HRESULT (WINAPI *pVarFix)(LPVARIANT,LPVARIANT);
2871 #define VARFIX(vt,val,rvt,rval) \
2872 V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
2873 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
2874 test_var_call1( __LINE__, pVarFix, &v, &exp )
2876 static void test_VarFix(void)
2878 static const WCHAR szNumMinus1[] = {'-','1','\0' };
2879 HRESULT hres;
2880 VARIANT v, exp, vDst;
2881 DECIMAL *pdec = &V_DECIMAL(&v);
2882 CY *pcy = &V_CY(&v);
2883 size_t i;
2885 CHECKPTR(VarFix);
2887 /* Test all possible V_VT values */
2888 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2890 VARTYPE vt;
2892 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2894 HRESULT bFail = TRUE;
2896 SKIPTESTS(vt);
2898 memset(&v, 0, sizeof(v));
2899 V_VT(&v) = vt | ExtraFlags[i];
2900 V_VT(&vDst) = VT_EMPTY;
2902 switch (V_VT(&v))
2904 case VT_UI1: case VT_I2: case VT_I4: case VT_R4: case VT_R8:
2905 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
2906 case VT_DATE: case VT_CY:
2907 bFail = FALSE;
2908 break;
2909 case VT_I8:
2910 if (HAVE_OLEAUT32_I8)
2911 bFail = FALSE;
2912 break;
2915 hres = pVarFix(&v,&vDst);
2916 if (bFail)
2917 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
2918 "VarFix: expected failure, got 0x%X vt %d|0x%X\n",
2919 hres, vt, ExtraFlags[i]);
2920 else
2921 ok(hres == S_OK, "VarFix: expected S_OK, got 0x%X vt %d|0x%X\n",
2922 hres, vt, ExtraFlags[i]);
2926 VARFIX(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE);
2927 VARFIX(BOOL,VARIANT_FALSE,I2,0);
2928 VARFIX(BOOL,1,I2,1);
2929 VARFIX(UI1,1,UI1,1);
2930 VARFIX(I2,-1,I2,-1);
2931 VARFIX(I4,-1,I4,-1);
2932 if (HAVE_OLEAUT32_I8)
2934 VARFIX(I8,-1,I8,-1);
2936 VARFIX(R4,1.4f,R4,1);
2937 VARFIX(R4,1.5f,R4,1);
2938 VARFIX(R4,1.6f,R4,1);
2939 VARFIX(R4,-1.4f,R4,-1);
2940 VARFIX(R4,-1.5f,R4,-1);
2941 VARFIX(R4,-1.6f,R4,-1);
2942 /* DATE & R8 round as for R4 */
2943 VARFIX(DATE,-1,DATE,-1);
2944 VARFIX(R8,-1,R8,-1);
2945 VARFIX(BSTR,(BSTR)szNumMinus1,R8,-1);
2947 V_VT(&v) = VT_EMPTY;
2948 hres = pVarFix(&v,&vDst);
2949 ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
2950 "VarFix: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY,
2951 hres, V_VT(&vDst), V_I2(&vDst));
2953 V_VT(&v) = VT_NULL;
2954 hres = pVarFix(&v,&vDst);
2955 ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
2956 "VarFix: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst));
2958 V_VT(&v) = VT_DECIMAL;
2959 S(U(*pdec)).sign = DECIMAL_NEG;
2960 S(U(*pdec)).scale = 0;
2961 pdec->Hi32 = 0;
2962 S1(U1(*pdec)).Mid32 = 0;
2963 S1(U1(*pdec)).Lo32 = 1;
2964 hres = pVarFix(&v,&vDst);
2965 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && !memcmp(&V_DECIMAL(&v), &V_DECIMAL(&vDst), sizeof(DECIMAL)),
2966 "VarFix: expected 0x0,%d,identical, got 0x%X,%d\n", VT_DECIMAL,
2967 hres, V_VT(&vDst));
2969 /* FIXME: Test some fractional decimals when VarDecFix is implemented */
2971 V_VT(&v) = VT_CY;
2972 pcy->int64 = -10000;
2973 hres = pVarFix(&v,&vDst);
2974 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
2975 "VarFix: VT_CY wrong, hres=0x%X\n", hres);
2977 V_VT(&v) = VT_CY;
2978 pcy->int64 = -16000;
2979 hres = pVarFix(&v,&vDst);
2980 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
2981 "VarFix: VT_CY wrong, hres=0x%X\n", hres);
2984 static HRESULT (WINAPI *pVarInt)(LPVARIANT,LPVARIANT);
2986 #define VARINT(vt,val,rvt,rval) \
2987 V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
2988 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
2989 test_var_call1( __LINE__, pVarInt, &v, &exp )
2991 static void test_VarInt(void)
2993 static const WCHAR szNumMinus1[] = {'-','1','\0' };
2994 HRESULT hres;
2995 VARIANT v, exp, vDst;
2996 DECIMAL *pdec = &V_DECIMAL(&v);
2997 CY *pcy = &V_CY(&v);
2998 size_t i;
3000 CHECKPTR(VarInt);
3002 /* Test all possible V_VT values */
3003 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
3005 VARTYPE vt;
3007 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
3009 HRESULT bFail = TRUE;
3011 SKIPTESTS(vt);
3013 memset(&v, 0, sizeof(v));
3014 V_VT(&v) = vt | ExtraFlags[i];
3015 V_VT(&vDst) = VT_EMPTY;
3017 switch (V_VT(&v))
3019 case VT_UI1: case VT_I2: case VT_I4: case VT_R4: case VT_R8:
3020 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
3021 case VT_DATE: case VT_CY:
3022 bFail = FALSE;
3023 break;
3024 case VT_I8:
3025 if (HAVE_OLEAUT32_I8)
3026 bFail = FALSE;
3027 break;
3030 hres = pVarInt(&v,&vDst);
3031 if (bFail)
3032 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3033 "VarInt: expected failure, got 0x%X vt %d|0x%X\n",
3034 hres, vt, ExtraFlags[i]);
3035 else
3036 ok(hres == S_OK, "VarInt: expected S_OK, got 0x%X vt %d|0x%X\n",
3037 hres, vt, ExtraFlags[i]);
3041 VARINT(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE);
3042 VARINT(BOOL,VARIANT_FALSE,I2,0);
3043 VARINT(BOOL,1,I2,1);
3044 VARINT(UI1,1,UI1,1);
3045 VARINT(I2,-1,I2,-1);
3046 VARINT(I4,-1,I4,-1);
3047 if (HAVE_OLEAUT32_I8)
3049 VARINT(I8,-1,I8,-1);
3051 VARINT(R4,1.4f,R4,1);
3052 VARINT(R4,1.5f,R4,1);
3053 VARINT(R4,1.6f,R4,1);
3054 VARINT(R4,-1.4f,R4,-2); /* Note these 3 are different from VarFix */
3055 VARINT(R4,-1.5f,R4,-2);
3056 VARINT(R4,-1.6f,R4,-2);
3057 /* DATE & R8 round as for R4 */
3058 VARINT(DATE,-1,DATE,-1);
3059 VARINT(R8,-1,R8,-1);
3060 VARINT(BSTR,(BSTR)szNumMinus1,R8,-1);
3062 V_VT(&v) = VT_EMPTY;
3063 hres = pVarInt(&v,&vDst);
3064 ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
3065 "VarInt: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY,
3066 hres, V_VT(&vDst), V_I2(&vDst));
3068 V_VT(&v) = VT_NULL;
3069 hres = pVarInt(&v,&vDst);
3070 ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
3071 "VarInt: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst));
3073 V_VT(&v) = VT_DECIMAL;
3074 S(U(*pdec)).sign = DECIMAL_NEG;
3075 S(U(*pdec)).scale = 0;
3076 pdec->Hi32 = 0;
3077 S1(U1(*pdec)).Mid32 = 0;
3078 S1(U1(*pdec)).Lo32 = 1;
3079 hres = pVarInt(&v,&vDst);
3080 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && !memcmp(&V_DECIMAL(&v), &V_DECIMAL(&vDst), sizeof(DECIMAL)),
3081 "VarInt: expected 0x0,%d,identical, got 0x%X,%d\n", VT_DECIMAL,
3082 hres, V_VT(&vDst));
3084 /* FIXME: Test some fractional decimals when VarDecInt is implemented */
3086 V_VT(&v) = VT_CY;
3087 pcy->int64 = -10000;
3088 hres = pVarInt(&v,&vDst);
3089 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
3090 "VarInt: VT_CY wrong, hres=0x%X\n", hres);
3092 V_VT(&v) = VT_CY;
3093 pcy->int64 = -11000;
3094 hres = pVarInt(&v,&vDst);
3095 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -20000,
3096 "VarInt: VT_CY wrong, hres=0x%X 0x%x%08x\n",
3097 hres, (DWORD)(V_CY(&vDst).int64 >> 32), (DWORD)V_CY(&vDst).int64);
3100 static HRESULT (WINAPI *pVarNeg)(LPVARIANT,LPVARIANT);
3102 #define VARNEG(vt,val,rvt,rval) \
3103 V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
3104 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
3105 test_var_call1( __LINE__, pVarNeg, &v, &exp )
3107 static void test_VarNeg(void)
3109 static const WCHAR szNumMinus1[] = {'-','1','\0' };
3110 static const WCHAR szNum1[] = {'1','\0' };
3111 HRESULT hres;
3112 VARIANT v, exp, vDst;
3113 DECIMAL *pdec = &V_DECIMAL(&v);
3114 CY *pcy = &V_CY(&v);
3115 size_t i;
3117 CHECKPTR(VarNeg);
3119 /* Test all possible V_VT values. But don't test the exact return values
3120 * except for success/failure, since M$ made a hash of them in the
3121 * native version. This at least ensures (as with all tests here) that
3122 * we will notice if/when new vtypes/flags are added in native.
3124 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
3126 VARTYPE vt;
3128 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
3130 HRESULT bFail = TRUE;
3132 SKIPTESTS(vt);
3134 memset(&v, 0, sizeof(v));
3135 V_VT(&v) = vt | ExtraFlags[i];
3136 V_VT(&vDst) = VT_EMPTY;
3138 switch (V_VT(&v))
3140 case VT_UI1: case VT_I2: case VT_I4:
3141 case VT_R4: case VT_R8:
3142 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
3143 case VT_DATE: case VT_CY:
3144 bFail = FALSE;
3145 break;
3146 case VT_I8:
3147 if (HAVE_OLEAUT32_I8)
3148 bFail = FALSE;
3151 hres = pVarNeg(&v,&vDst);
3152 if (bFail)
3153 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3154 "VarNeg: expected failure, got 0x%X vt %d|0x%X\n",
3155 hres, vt, ExtraFlags[i]);
3156 else
3157 ok(hres == S_OK, "VarNeg: expected S_OK, got 0x%X vt %d|0x%X\n",
3158 hres, vt, ExtraFlags[i]);
3162 VARNEG(BOOL,VARIANT_TRUE,I2,1);
3163 VARNEG(BOOL,VARIANT_FALSE,I2,0);
3164 VARNEG(BOOL,1,I2,-1);
3165 VARNEG(UI1,1,I2,-1);
3166 VARNEG(UI1,254,I2,-254);
3167 VARNEG(I2,-32768,I4,32768);
3168 VARNEG(I2,-1,I2,1);
3169 VARNEG(I2,1,I2,-1);
3170 VARNEG(I4,-((int)(~0u >> 1)) - 1,R8,-2147483648u);
3171 VARNEG(I4,-1,I4,1);
3172 VARNEG(I4,1,I4,-1);
3173 if (HAVE_OLEAUT32_I8)
3175 VARNEG(I8,1,I8,-1);
3176 VARNEG(I8,-1,I8,1);
3178 VARNEG(R4,1,R4,-1);
3179 VARNEG(R4,-1,R4,1);
3180 VARNEG(DATE,1,DATE,-1);
3181 VARNEG(DATE,-1,DATE,1);
3182 VARNEG(R8,1,R8,-1);
3183 VARNEG(R8,-1,R8,1);
3184 VARNEG(BSTR,(BSTR)szNumMinus1,R8,1);
3185 VARNEG(BSTR,(BSTR)szNum1,R8,-1);
3187 V_VT(&v) = VT_EMPTY;
3188 hres = pVarNeg(&v,&vDst);
3189 ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
3190 "VarNeg: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY,
3191 hres, V_VT(&vDst), V_I2(&vDst));
3193 V_VT(&v) = VT_NULL;
3194 hres = pVarNeg(&v,&vDst);
3195 ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
3196 "VarNeg: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst));
3198 V_VT(&v) = VT_DECIMAL;
3199 S(U(*pdec)).sign = DECIMAL_NEG;
3200 S(U(*pdec)).scale = 0;
3201 pdec->Hi32 = 0;
3202 S1(U1(*pdec)).Mid32 = 0;
3203 S1(U1(*pdec)).Lo32 = 1;
3204 hres = pVarNeg(&v,&vDst);
3205 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
3206 S(U(V_DECIMAL(&vDst))).sign == 0,
3207 "VarNeg: expected 0x0,%d,0x00, got 0x%X,%d,%02x\n", VT_DECIMAL,
3208 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
3210 S(U(*pdec)).sign = 0;
3211 hres = pVarNeg(&v,&vDst);
3212 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
3213 S(U(V_DECIMAL(&vDst))).sign == DECIMAL_NEG,
3214 "VarNeg: expected 0x0,%d,0x7f, got 0x%X,%d,%02x\n", VT_DECIMAL,
3215 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
3217 V_VT(&v) = VT_CY;
3218 pcy->int64 = -10000;
3219 hres = pVarNeg(&v,&vDst);
3220 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
3221 "VarNeg: VT_CY wrong, hres=0x%X\n", hres);
3224 static HRESULT (WINAPI *pVarRound)(LPVARIANT,int,LPVARIANT);
3226 static void test_Round( int line, VARIANT *arg, int deci, VARIANT *expected )
3228 VARIANT result;
3229 HRESULT hres;
3231 memset( &result, 0, sizeof(result) );
3232 hres = pVarRound( arg, deci, &result );
3233 ok_(__FILE__,line)( hres == S_OK, "wrong result %x\n", hres );
3234 if (hres == S_OK)
3235 ok_(__FILE__,line)( is_expected_variant( &result, expected ),
3236 "got %s expected %s\n", variantstr(&result), variantstr(expected) );
3238 #define VARROUND(vt,val,deci,rvt,rval) \
3239 V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
3240 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
3241 test_Round( __LINE__, &v, deci, &exp )
3243 static void test_VarRound(void)
3245 static WCHAR szNumMin[] = {'-','1','.','4','4','9','\0' };
3246 static WCHAR szNum[] = {'1','.','4','5','1','\0' };
3247 HRESULT hres;
3248 VARIANT v, exp, vDst;
3249 CY *pcy = &V_CY(&v);
3250 char buff[8];
3252 CHECKPTR(VarRound);
3254 /* first check valid integer types */
3255 VARROUND(BOOL,VARIANT_TRUE,0,I2,-1);
3256 VARROUND(BOOL,VARIANT_FALSE,0,I2,0);
3257 VARROUND(BOOL,1,0,I2,1);
3258 VARROUND(UI1,1,0,UI1,1);
3259 VARROUND(UI1,254,0,UI1,254);
3260 VARROUND(I2,-32768,0,I2,-32768);
3261 VARROUND(I2,-1,0,I2,-1);
3262 VARROUND(I2,1,0,I2,1);
3263 VARROUND(I4,-((int)(~0u >> 1)) - 1,0,I4,-((int)(~0u >> 1)) - 1);
3264 VARROUND(I4,-1,0,I4,-1);
3265 VARROUND(I4,1,0,I4,1);
3268 /* MSDN states that rounding of R4/R8 is dependent on the underlying
3269 * bit pattern of the number and so is architecture dependent. In this
3270 * case Wine returns .2 (which is more correct) and Native returns .3
3273 VARROUND(R4,1.0f,0,R4,1.0f);
3274 VARROUND(R4,-1.0f,0,R4,-1.0f);
3275 VARROUND(R8,1.0,0,R8,1.0);
3276 VARROUND(R8,-1.0,0,R8,-1.0);
3278 /* floating point numbers aren't exactly equal and we can't just
3279 * compare the first few digits. */
3280 VARROUND(DATE,1.451,1,DATE,1.5);
3281 VARROUND(DATE,-1.449,1,DATE,-1.4);
3283 /* replace the decimal separator */
3284 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char));
3285 if (!buff[1]) {
3286 szNumMin[2] = buff[0];
3287 szNum[1] = buff[0];
3288 VARROUND(BSTR,(BSTR)szNumMin,1,R8,-1.40);
3289 VARROUND(BSTR,(BSTR)szNum,1,R8,1.50);
3290 } else {
3291 skip("Skipping VarRound(BSTR) as decimal separator is '%s'\n", buff);
3294 VARROUND(R4,1.23456f,0,R4,1.0f);
3295 VARROUND(R4,1.23456f,1,R4,1.2f);
3296 VARROUND(R4,1.23456f,2,R4,1.23f);
3297 VARROUND(R4,1.23456f,3,R4,1.235f);
3298 VARROUND(R4,1.23456f,4,R4,1.2346f);
3299 VARROUND(R4,-1.23456f,0,R4,-1.0f);
3300 VARROUND(R4,-1.23456f,1,R4,-1.2f);
3301 VARROUND(R4,-1.23456f,2,R4,-1.23f);
3302 VARROUND(R4,-1.23456f,3,R4,-1.235f);
3303 VARROUND(R4,-1.23456f,4,R4,-1.2346f);
3305 VARROUND(R8,1.23456,0,R8,1.0);
3306 VARROUND(R8,1.23456,1,R8,1.2);
3307 VARROUND(R8,1.23456,2,R8,1.23);
3308 VARROUND(R8,1.23456,3,R8,1.235);
3309 VARROUND(R8,1.23456,4,R8,1.2346);
3310 VARROUND(R8,-1.23456,0,R8,-1.0);
3311 VARROUND(R8,-1.23456,1,R8,-1.2);
3312 VARROUND(R8,-1.23456,2,R8,-1.23);
3313 VARROUND(R8,-1.23456,3,R8,-1.235);
3314 VARROUND(R8,-1.23456,4,R8,-1.2346);
3316 V_VT(&v) = VT_EMPTY;
3317 hres = pVarRound(&v,0,&vDst);
3318 ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
3319 "VarRound: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY,
3320 hres, V_VT(&vDst), V_I2(&vDst));
3322 V_VT(&v) = VT_NULL;
3323 hres = pVarRound(&v,0,&vDst);
3324 ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
3325 "VarRound: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst));
3327 /* not yet implemented so no use testing yet
3328 todo_wine {
3329 DECIMAL *pdec = &V_DECIMAL(&v);
3330 V_VT(&v) = VT_DECIMAL;
3331 S(U(*pdec)).sign = DECIMAL_NEG;
3332 S(U(*pdec)).scale = 0;
3333 pdec->Hi32 = 0;
3334 S1(U1(*pdec)).Mid32 = 0;
3335 S1(U1(*pdec)).Lo32 = 1;
3336 hres = pVarRound(&v,0,&vDst);
3337 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
3338 S(U(V_DECIMAL(&vDst))).sign == 0,
3339 "VarRound: expected 0x0,%d,0x00, got 0x%X,%d,%02x\n", VT_DECIMAL,
3340 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
3342 S(U(*pdec)).sign = 0;
3343 hres = pVarRound(&v,0,&vDst);
3344 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
3345 S(U(V_DECIMAL(&vDst))).sign == DECIMAL_NEG,
3346 "VarRound: expected 0x0,%d,0x7f, got 0x%X,%d,%02x\n", VT_DECIMAL,
3347 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
3351 V_VT(&v) = VT_CY;
3352 pcy->int64 = 10000;
3353 hres = pVarRound(&v,0,&vDst);
3354 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
3355 "VarRound: VT_CY wrong, hres=0x%X\n", hres);
3359 static HRESULT (WINAPI *pVarXor)(LPVARIANT,LPVARIANT,LPVARIANT);
3361 #define VARXOR(vt1,val1,vt2,val2,rvt,rval) \
3362 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
3363 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
3364 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
3365 test_var_call2( __LINE__, pVarXor, &left, &right, &exp )
3367 #define VARXORCY(vt1,val1,val2,rvt,rval) \
3368 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
3369 V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \
3370 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
3371 test_var_call2( __LINE__, pVarXor, &left, &right, &exp )
3373 static void test_VarXor(void)
3375 static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
3376 static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
3377 VARIANT left, right, exp, result;
3378 BSTR lbstr, rbstr;
3379 VARTYPE i;
3380 HRESULT hres;
3382 CHECKPTR(VarXor);
3384 /* Test all possible flag/vt combinations & the resulting vt type */
3385 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
3387 VARTYPE leftvt, rightvt, resvt;
3389 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
3392 SKIPTESTS(leftvt);
3394 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
3396 BOOL bFail = FALSE;
3398 SKIPTESTS(rightvt);
3400 if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
3401 leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
3402 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
3403 continue;
3405 memset(&left, 0, sizeof(left));
3406 memset(&right, 0, sizeof(right));
3407 V_VT(&left) = leftvt | ExtraFlags[i];
3408 V_VT(&right) = rightvt | ExtraFlags[i];
3409 V_VT(&result) = VT_EMPTY;
3410 resvt = VT_I4;
3412 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
3413 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
3414 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
3415 leftvt == VT_CLSID || rightvt == VT_CLSID ||
3416 leftvt == VT_RECORD || rightvt == VT_RECORD ||
3417 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
3418 leftvt == VT_ERROR || rightvt == VT_ERROR)
3420 bFail = TRUE;
3422 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
3424 if (leftvt == rightvt ||
3425 leftvt == VT_I2 || rightvt == VT_I2 ||
3426 leftvt == VT_UI1 || rightvt == VT_UI1 ||
3427 leftvt == VT_BOOL || rightvt == VT_BOOL)
3428 resvt = VT_I2;
3429 else if (leftvt == VT_NULL || rightvt == VT_NULL)
3430 resvt = VT_NULL;
3431 else if (leftvt == VT_I8 || rightvt == VT_I8)
3432 resvt = VT_I8;
3434 else if (leftvt == VT_NULL || rightvt == VT_NULL)
3436 resvt = VT_NULL;
3438 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
3440 if (leftvt == rightvt)
3441 resvt = VT_UI1;
3442 else if (leftvt == rightvt ||
3443 leftvt == VT_I2 || rightvt == VT_I2 ||
3444 leftvt == VT_BOOL || rightvt == VT_BOOL)
3446 resvt = VT_I2;
3448 else if (leftvt == VT_I8 || rightvt == VT_I8)
3449 resvt = VT_I8;
3451 else if (leftvt == VT_I2 || rightvt == VT_I2)
3453 if (leftvt == rightvt ||
3454 leftvt == VT_BOOL || rightvt == VT_BOOL)
3455 resvt = VT_I2;
3456 else if (leftvt == VT_I8 || rightvt == VT_I8)
3457 resvt = VT_I8;
3459 else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
3461 resvt = VT_BOOL;
3463 else if (leftvt == VT_I8 || rightvt == VT_I8)
3465 if (leftvt == VT_INT || rightvt == VT_INT)
3466 bFail = TRUE;
3467 else
3468 resvt = VT_I8;
3470 hres = pVarXor(&left, &right, &result);
3471 if (bFail)
3472 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3473 "VarXor: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
3474 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
3475 V_VT(&result));
3476 else
3477 ok(hres == S_OK && V_VT(&result) == resvt,
3478 "VarXor: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
3479 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
3480 V_VT(&result));
3485 /* Test returned values
3486 * FIXME: Test VT_DECIMAL/VT_DISPATCH
3488 VARXOR(EMPTY,0,EMPTY,0,I2,0);
3489 VARXOR(EMPTY,1,EMPTY,0,I2,0);
3490 VARXOR(EMPTY,0,NULL,0,NULL,0);
3491 VARXOR(EMPTY,0,I1,0,I4,0);
3492 VARXOR(EMPTY,0,I1,1,I4,1);
3493 VARXOR(EMPTY,0,UI1,0,I2,0);
3494 VARXOR(EMPTY,0,UI1,1,I2,1);
3495 VARXOR(EMPTY,0,I2,0,I2,0);
3496 VARXOR(EMPTY,0,I2,1,I2,1);
3497 VARXOR(EMPTY,0,UI2,0,I4,0);
3498 VARXOR(EMPTY,0,UI2,1,I4,1);
3499 VARXOR(EMPTY,0,I4,0,I4,0);
3500 VARXOR(EMPTY,0,I4,1,I4,1);
3501 VARXOR(EMPTY,0,UI4,0,I4,0);
3502 VARXOR(EMPTY,0,UI4,1,I4,1);
3503 if (HAVE_OLEAUT32_I8)
3505 VARXOR(EMPTY,0,I8,0,I8,0);
3506 VARXOR(EMPTY,0,I8,1,I8,1);
3507 VARXOR(EMPTY,0,UI8,0,I4,0);
3508 VARXOR(EMPTY,0,UI8,1,I4,1);
3510 VARXOR(EMPTY,0,INT,0,I4,0);
3511 VARXOR(EMPTY,0,INT,1,I4,1);
3512 VARXOR(EMPTY,0,UINT,0,I4,0);
3513 VARXOR(EMPTY,0,UINT,1,I4,1);
3514 VARXOR(EMPTY,0,BOOL,0,I2,0);
3515 VARXOR(EMPTY,0,BOOL,1,I2,1);
3516 VARXOR(EMPTY,0,R4,0,I4,0);
3517 VARXOR(EMPTY,0,R4,1,I4,1);
3518 VARXOR(EMPTY,0,R8,0,I4,0);
3519 VARXOR(EMPTY,0,R8,1,I4,1);
3520 rbstr = SysAllocString(szFalse);
3521 VARXOR(EMPTY,0,BSTR,rbstr,I2,0);
3522 SysFreeString(rbstr);
3523 rbstr = SysAllocString(szTrue);
3524 VARXOR(EMPTY,0,BSTR,rbstr,I2,-1);
3525 VARXORCY(EMPTY,0,10000,I4,1);
3526 SysFreeString(rbstr);
3528 /* NULL OR 0 = NULL. NULL OR n = n */
3529 VARXOR(NULL,0,NULL,0,NULL,0);
3530 VARXOR(NULL,1,NULL,0,NULL,0);
3531 VARXOR(NULL,0,I1,0,NULL,0);
3532 VARXOR(NULL,0,I1,1,NULL,0);
3533 VARXOR(NULL,0,UI1,0,NULL,0);
3534 VARXOR(NULL,0,UI1,1,NULL,0);
3535 VARXOR(NULL,0,I2,0,NULL,0);
3536 VARXOR(NULL,0,I2,1,NULL,0);
3537 VARXOR(NULL,0,UI2,0,NULL,0);
3538 VARXOR(NULL,0,UI2,1,NULL,0);
3539 VARXOR(NULL,0,I4,0,NULL,0);
3540 VARXOR(NULL,0,I4,1,NULL,0);
3541 VARXOR(NULL,0,UI4,0,NULL,0);
3542 VARXOR(NULL,0,UI4,1,NULL,0);
3543 if (HAVE_OLEAUT32_I8)
3545 VARXOR(NULL,0,I8,0,NULL,0);
3546 VARXOR(NULL,0,I8,1,NULL,0);
3547 VARXOR(NULL,0,UI8,0,NULL,0);
3548 VARXOR(NULL,0,UI8,1,NULL,0);
3550 VARXOR(NULL,0,INT,0,NULL,0);
3551 VARXOR(NULL,0,INT,1,NULL,0);
3552 VARXOR(NULL,0,UINT,0,NULL,0);
3553 VARXOR(NULL,0,UINT,1,NULL,0);
3554 VARXOR(NULL,0,BOOL,0,NULL,0);
3555 VARXOR(NULL,0,BOOL,1,NULL,0);
3556 VARXOR(NULL,0,R4,0,NULL,0);
3557 VARXOR(NULL,0,R4,1,NULL,0);
3558 VARXOR(NULL,0,R8,0,NULL,0);
3559 VARXOR(NULL,0,R8,1,NULL,0);
3560 rbstr = SysAllocString(szFalse);
3561 VARXOR(NULL,0,BSTR,rbstr,NULL,0);
3562 SysFreeString(rbstr);
3563 rbstr = SysAllocString(szTrue);
3564 VARXOR(NULL,0,BSTR,rbstr,NULL,0);
3565 SysFreeString(rbstr);
3566 VARXORCY(NULL,0,10000,NULL,0);
3567 VARXORCY(NULL,0,0,NULL,0);
3569 VARXOR(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
3570 VARXOR(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
3571 VARXOR(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
3572 VARXOR(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
3573 /* Assume x,y & y,x are the same from now on to reduce the number of tests */
3574 VARXOR(BOOL,VARIANT_TRUE,I1,-1,I4,0);
3575 VARXOR(BOOL,VARIANT_TRUE,I1,0,I4,-1);
3576 VARXOR(BOOL,VARIANT_FALSE,I1,0,I4,0);
3577 VARXOR(BOOL,VARIANT_TRUE,UI1,255,I2,-256);
3578 VARXOR(BOOL,VARIANT_TRUE,UI1,0,I2,-1);
3579 VARXOR(BOOL,VARIANT_FALSE,UI1,0,I2,0);
3580 VARXOR(BOOL,VARIANT_TRUE,I2,-1,I2,0);
3581 VARXOR(BOOL,VARIANT_TRUE,I2,0,I2,-1);
3582 VARXOR(BOOL,VARIANT_FALSE,I2,0,I2,0);
3583 VARXOR(BOOL,VARIANT_TRUE,UI2,65535,I4,-65536);
3584 VARXOR(BOOL,VARIANT_TRUE,UI2,0,I4,-1);
3585 VARXOR(BOOL,VARIANT_FALSE,UI2,0,I4,0);
3586 VARXOR(BOOL,VARIANT_TRUE,I4,-1,I4,0);
3587 VARXOR(BOOL,VARIANT_TRUE,I4,0,I4,-1);
3588 VARXOR(BOOL,VARIANT_FALSE,I4,0,I4,0);
3589 VARXOR(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,0);
3590 VARXOR(BOOL,VARIANT_TRUE,UI4,0,I4,-1);
3591 VARXOR(BOOL,VARIANT_FALSE,UI4,0,I4,0);
3592 VARXOR(BOOL,VARIANT_TRUE,R4,-1,I4,0);
3593 VARXOR(BOOL,VARIANT_TRUE,R4,0,I4,-1);
3594 VARXOR(BOOL,VARIANT_FALSE,R4,0,I4,0);
3595 VARXOR(BOOL,VARIANT_TRUE,R8,-1,I4,0);
3596 VARXOR(BOOL,VARIANT_TRUE,R8,0,I4,-1);
3597 VARXOR(BOOL,VARIANT_FALSE,R8,0,I4,0);
3598 VARXOR(BOOL,VARIANT_TRUE,DATE,-1,I4,0);
3599 VARXOR(BOOL,VARIANT_TRUE,DATE,0,I4,-1);
3600 VARXOR(BOOL,VARIANT_FALSE,DATE,0,I4,0);
3601 if (HAVE_OLEAUT32_I8)
3603 VARXOR(BOOL,VARIANT_TRUE,I8,-1,I8,0);
3604 VARXOR(BOOL,VARIANT_TRUE,I8,0,I8,-1);
3605 VARXOR(BOOL,VARIANT_FALSE,I8,0,I8,0);
3606 /* This returns DISP_E_OVERFLOW which indicates that a conversion
3607 * to I4 is performed.
3609 /* VARXOR(BOOL,VARIANT_TRUE,UI8,-1,I4,-1); */
3610 VARXOR(BOOL,VARIANT_TRUE,UI8,0,I4,-1);
3611 VARXOR(BOOL,VARIANT_FALSE,UI8,0,I4,0);
3613 VARXOR(BOOL,VARIANT_TRUE,INT,-1,I4,0);
3614 VARXOR(BOOL,VARIANT_TRUE,INT,0,I4,-1);
3615 VARXOR(BOOL,VARIANT_FALSE,INT,0,I4,0);
3616 VARXOR(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,0);
3617 VARXOR(BOOL,VARIANT_TRUE,UINT,0,I4,-1);
3618 VARXOR(BOOL,VARIANT_FALSE,UINT,0,I4,0);
3619 rbstr = SysAllocString(szFalse);
3620 VARXOR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_FALSE);
3621 VARXOR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
3622 SysFreeString(rbstr);
3623 rbstr = SysAllocString(szTrue);
3624 VARXOR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_TRUE);
3625 VARXOR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_FALSE);
3626 SysFreeString(rbstr);
3627 VARXORCY(BOOL,VARIANT_TRUE,10000,I4,-2);
3628 VARXORCY(BOOL,VARIANT_TRUE,0,I4,-1);
3629 VARXORCY(BOOL,VARIANT_FALSE,0,I4,0);
3631 VARXOR(I1,-1,I1,-1,I4,0);
3632 VARXOR(I1,-1,I1,0,I4,-1);
3633 VARXOR(I1,0,I1,0,I4,0);
3634 VARXOR(I1,-1,UI1,255,I4,-256);
3635 VARXOR(I1,-1,UI1,0,I4,-1);
3636 VARXOR(I1,0,UI1,0,I4,0);
3637 VARXOR(I1,-1,I2,-1,I4,0);
3638 VARXOR(I1,-1,I2,0,I4,-1);
3639 VARXOR(I1,0,I2,0,I4,0);
3640 VARXOR(I1,-1,UI2,65535,I4,-65536);
3641 VARXOR(I1,-1,UI2,0,I4,-1);
3642 VARXOR(I1,0,UI2,0,I4,0);
3643 VARXOR(I1,-1,I4,-1,I4,0);
3644 VARXOR(I1,-1,I4,0,I4,-1);
3645 VARXOR(I1,0,I4,0,I4,0);
3646 VARXOR(I1,-1,UI4,0xffffffff,I4,0);
3647 VARXOR(I1,-1,UI4,0,I4,-1);
3648 VARXOR(I1,0,UI4,0,I4,0);
3649 VARXOR(I1,-1,R4,-1,I4,0);
3650 VARXOR(I1,-1,R4,0,I4,-1);
3651 VARXOR(I1,0,R4,0,I4,0);
3652 VARXOR(I1,-1,R8,-1,I4,0);
3653 VARXOR(I1,-1,R8,0,I4,-1);
3654 VARXOR(I1,0,R8,0,I4,0);
3655 VARXOR(I1,-1,DATE,-1,I4,0);
3656 VARXOR(I1,-1,DATE,0,I4,-1);
3657 VARXOR(I1,0,DATE,0,I4,0);
3658 if (HAVE_OLEAUT32_I8)
3660 VARXOR(I1,-1,I8,-1,I8,0);
3661 VARXOR(I1,-1,I8,0,I8,-1);
3662 VARXOR(I1,0,I8,0,I8,0);
3663 VARXOR(I1,-1,UI8,0,I4,-1);
3664 VARXOR(I1,0,UI8,0,I4,0);
3666 VARXOR(I1,-1,INT,-1,I4,0);
3667 VARXOR(I1,-1,INT,0,I4,-1);
3668 VARXOR(I1,0,INT,0,I4,0);
3669 VARXOR(I1,-1,UINT,0xffffffff,I4,0);
3670 VARXOR(I1,-1,UINT,0,I4,-1);
3671 VARXOR(I1,0,UINT,0,I4,0);
3672 rbstr = SysAllocString(szFalse);
3673 VARXOR(I1,0,BSTR,rbstr,I4,0);
3674 VARXOR(I1,-1,BSTR,rbstr,I4,-1);
3675 SysFreeString(rbstr);
3676 rbstr = SysAllocString(szTrue);
3677 VARXOR(I1,0,BSTR,rbstr,I4,-1);
3678 VARXOR(I1,-1,BSTR,rbstr,I4,0);
3679 SysFreeString(rbstr);
3680 VARXORCY(I1,-1,10000,I4,-2);
3681 VARXORCY(I1,-1,0,I4,-1);
3682 VARXORCY(I1,0,0,I4,0);
3684 VARXOR(UI1,255,UI1,255,UI1,0);
3685 VARXOR(UI1,255,UI1,0,UI1,255);
3686 VARXOR(UI1,0,UI1,0,UI1,0);
3687 VARXOR(UI1,255,I2,-1,I2,-256);
3688 VARXOR(UI1,255,I2,0,I2,255);
3689 VARXOR(UI1,0,I2,0,I2,0);
3690 VARXOR(UI1,255,UI2,65535,I4,65280);
3691 VARXOR(UI1,255,UI2,0,I4,255);
3692 VARXOR(UI1,0,UI2,0,I4,0);
3693 VARXOR(UI1,255,I4,-1,I4,-256);
3694 VARXOR(UI1,255,I4,0,I4,255);
3695 VARXOR(UI1,0,I4,0,I4,0);
3696 VARXOR(UI1,255,UI4,0xffffffff,I4,-256);
3697 VARXOR(UI1,255,UI4,0,I4,255);
3698 VARXOR(UI1,0,UI4,0,I4,0);
3699 VARXOR(UI1,255,R4,-1,I4,-256);
3700 VARXOR(UI1,255,R4,0,I4,255);
3701 VARXOR(UI1,0,R4,0,I4,0);
3702 VARXOR(UI1,255,R8,-1,I4,-256);
3703 VARXOR(UI1,255,R8,0,I4,255);
3704 VARXOR(UI1,0,R8,0,I4,0);
3705 VARXOR(UI1,255,DATE,-1,I4,-256);
3706 VARXOR(UI1,255,DATE,0,I4,255);
3707 VARXOR(UI1,0,DATE,0,I4,0);
3708 if (HAVE_OLEAUT32_I8)
3710 VARXOR(UI1,255,I8,-1,I8,-256);
3711 VARXOR(UI1,255,I8,0,I8,255);
3712 VARXOR(UI1,0,I8,0,I8,0);
3713 VARXOR(UI1,255,UI8,0,I4,255);
3714 VARXOR(UI1,0,UI8,0,I4,0);
3716 VARXOR(UI1,255,INT,-1,I4,-256);
3717 VARXOR(UI1,255,INT,0,I4,255);
3718 VARXOR(UI1,0,INT,0,I4,0);
3719 VARXOR(UI1,255,UINT,0xffffffff,I4,-256);
3720 VARXOR(UI1,255,UINT,0,I4,255);
3721 VARXOR(UI1,0,UINT,0,I4,0);
3722 rbstr = SysAllocString(szFalse);
3723 VARXOR(UI1,0,BSTR,rbstr,I2,0);
3724 VARXOR(UI1,255,BSTR,rbstr,I2,255);
3725 SysFreeString(rbstr);
3726 rbstr = SysAllocString(szTrue);
3727 VARXOR(UI1,0,BSTR,rbstr,I2,-1);
3728 VARXOR(UI1,255,BSTR,rbstr,I2,-256);
3729 SysFreeString(rbstr);
3730 VARXORCY(UI1,255,10000,I4,254);
3731 VARXORCY(UI1,255,0,I4,255);
3732 VARXORCY(UI1,0,0,I4,0);
3734 VARXOR(I2,-1,I2,-1,I2,0);
3735 VARXOR(I2,-1,I2,0,I2,-1);
3736 VARXOR(I2,0,I2,0,I2,0);
3737 VARXOR(I2,-1,UI2,65535,I4,-65536);
3738 VARXOR(I2,-1,UI2,0,I4,-1);
3739 VARXOR(I2,0,UI2,0,I4,0);
3740 VARXOR(I2,-1,I4,-1,I4,0);
3741 VARXOR(I2,-1,I4,0,I4,-1);
3742 VARXOR(I2,0,I4,0,I4,0);
3743 VARXOR(I2,-1,UI4,0xffffffff,I4,0);
3744 VARXOR(I2,-1,UI4,0,I4,-1);
3745 VARXOR(I2,0,UI4,0,I4,0);
3746 VARXOR(I2,-1,R4,-1,I4,0);
3747 VARXOR(I2,-1,R4,0,I4,-1);
3748 VARXOR(I2,0,R4,0,I4,0);
3749 VARXOR(I2,-1,R8,-1,I4,0);
3750 VARXOR(I2,-1,R8,0,I4,-1);
3751 VARXOR(I2,0,R8,0,I4,0);
3752 VARXOR(I2,-1,DATE,-1,I4,0);
3753 VARXOR(I2,-1,DATE,0,I4,-1);
3754 VARXOR(I2,0,DATE,0,I4,0);
3755 if (HAVE_OLEAUT32_I8)
3757 VARXOR(I2,-1,I8,-1,I8,0);
3758 VARXOR(I2,-1,I8,0,I8,-1);
3759 VARXOR(I2,0,I8,0,I8,0);
3760 VARXOR(I2,-1,UI8,0,I4,-1);
3761 VARXOR(I2,0,UI8,0,I4,0);
3763 VARXOR(I2,-1,INT,-1,I4,0);
3764 VARXOR(I2,-1,INT,0,I4,-1);
3765 VARXOR(I2,0,INT,0,I4,0);
3766 VARXOR(I2,-1,UINT,0xffffffff,I4,0);
3767 VARXOR(I2,-1,UINT,0,I4,-1);
3768 VARXOR(I2,0,UINT,0,I4,0);
3769 rbstr = SysAllocString(szFalse);
3770 VARXOR(I2,0,BSTR,rbstr,I2,0);
3771 VARXOR(I2,-1,BSTR,rbstr,I2,-1);
3772 SysFreeString(rbstr);
3773 rbstr = SysAllocString(szTrue);
3774 VARXOR(I2,0,BSTR,rbstr,I2,-1);
3775 VARXOR(I2,-1,BSTR,rbstr,I2,0);
3776 SysFreeString(rbstr);
3777 VARXORCY(I2,-1,10000,I4,-2);
3778 VARXORCY(I2,-1,0,I4,-1);
3779 VARXORCY(I2,0,0,I4,0);
3781 VARXOR(UI2,65535,UI2,65535,I4,0);
3782 VARXOR(UI2,65535,UI2,0,I4,65535);
3783 VARXOR(UI2,0,UI2,0,I4,0);
3784 VARXOR(UI2,65535,I4,-1,I4,-65536);
3785 VARXOR(UI2,65535,I4,0,I4,65535);
3786 VARXOR(UI2,0,I4,0,I4,0);
3787 VARXOR(UI2,65535,UI4,0xffffffff,I4,-65536);
3788 VARXOR(UI2,65535,UI4,0,I4,65535);
3789 VARXOR(UI2,0,UI4,0,I4,0);
3790 VARXOR(UI2,65535,R4,-1,I4,-65536);
3791 VARXOR(UI2,65535,R4,0,I4,65535);
3792 VARXOR(UI2,0,R4,0,I4,0);
3793 VARXOR(UI2,65535,R8,-1,I4,-65536);
3794 VARXOR(UI2,65535,R8,0,I4,65535);
3795 VARXOR(UI2,0,R8,0,I4,0);
3796 VARXOR(UI2,65535,DATE,-1,I4,-65536);
3797 VARXOR(UI2,65535,DATE,0,I4,65535);
3798 VARXOR(UI2,0,DATE,0,I4,0);
3799 if (HAVE_OLEAUT32_I8)
3801 VARXOR(UI2,65535,I8,-1,I8,-65536);
3802 VARXOR(UI2,65535,I8,0,I8,65535);
3803 VARXOR(UI2,0,I8,0,I8,0);
3804 VARXOR(UI2,65535,UI8,0,I4,65535);
3805 VARXOR(UI2,0,UI8,0,I4,0);
3807 VARXOR(UI2,65535,INT,-1,I4,-65536);
3808 VARXOR(UI2,65535,INT,0,I4,65535);
3809 VARXOR(UI2,0,INT,0,I4,0);
3810 VARXOR(UI2,65535,UINT,0xffffffff,I4,-65536);
3811 VARXOR(UI2,65535,UINT,0,I4,65535);
3812 VARXOR(UI2,0,UINT,0,I4,0);
3813 rbstr = SysAllocString(szFalse);
3814 VARXOR(UI2,0,BSTR,rbstr,I4,0);
3815 VARXOR(UI2,65535,BSTR,rbstr,I4,65535);
3816 SysFreeString(rbstr);
3817 rbstr = SysAllocString(szTrue);
3818 VARXOR(UI2,0,BSTR,rbstr,I4,-1);
3819 VARXOR(UI2,65535,BSTR,rbstr,I4,-65536);
3820 SysFreeString(rbstr);
3821 VARXORCY(UI2,65535,10000,I4,65534);
3822 VARXORCY(UI2,65535,0,I4,65535);
3823 VARXORCY(UI2,0,0,I4,0);
3825 VARXOR(I4,-1,I4,-1,I4,0);
3826 VARXOR(I4,-1,I4,0,I4,-1);
3827 VARXOR(I4,0,I4,0,I4,0);
3828 VARXOR(I4,-1,UI4,0xffffffff,I4,0);
3829 VARXOR(I4,-1,UI4,0,I4,-1);
3830 VARXOR(I4,0,UI4,0,I4,0);
3831 VARXOR(I4,-1,R4,-1,I4,0);
3832 VARXOR(I4,-1,R4,0,I4,-1);
3833 VARXOR(I4,0,R4,0,I4,0);
3834 VARXOR(I4,-1,R8,-1,I4,0);
3835 VARXOR(I4,-1,R8,0,I4,-1);
3836 VARXOR(I4,0,R8,0,I4,0);
3837 VARXOR(I4,-1,DATE,-1,I4,0);
3838 VARXOR(I4,-1,DATE,0,I4,-1);
3839 VARXOR(I4,0,DATE,0,I4,0);
3840 if (HAVE_OLEAUT32_I8)
3842 VARXOR(I4,-1,I8,-1,I8,0);
3843 VARXOR(I4,-1,I8,0,I8,-1);
3844 VARXOR(I4,0,I8,0,I8,0);
3845 VARXOR(I4,-1,UI8,0,I4,-1);
3846 VARXOR(I4,0,UI8,0,I4,0);
3848 VARXOR(I4,-1,INT,-1,I4,0);
3849 VARXOR(I4,-1,INT,0,I4,-1);
3850 VARXOR(I4,0,INT,0,I4,0);
3851 VARXOR(I4,-1,UINT,0xffffffff,I4,0);
3852 VARXOR(I4,-1,UINT,0,I4,-1);
3853 VARXOR(I4,0,UINT,0,I4,0);
3854 rbstr = SysAllocString(szFalse);
3855 VARXOR(I4,0,BSTR,rbstr,I4,0);
3856 VARXOR(I4,-1,BSTR,rbstr,I4,-1);
3857 SysFreeString(rbstr);
3858 rbstr = SysAllocString(szTrue);
3859 VARXOR(I4,0,BSTR,rbstr,I4,-1);
3860 VARXOR(I4,-1,BSTR,rbstr,I4,0);
3861 SysFreeString(rbstr);
3862 VARXORCY(I4,-1,10000,I4,-2);
3863 VARXORCY(I4,-1,0,I4,-1);
3864 VARXORCY(I4,0,0,I4,0);
3866 VARXOR(UI4,0xffffffff,UI4,0xffffffff,I4,0);
3867 VARXOR(UI4,0xffffffff,UI4,0,I4,-1);
3868 VARXOR(UI4,0,UI4,0,I4,0);
3869 VARXOR(UI4,0xffffffff,R4,-1,I4,0);
3870 VARXOR(UI4,0xffffffff,R4,0,I4,-1);
3871 VARXOR(UI4,0,R4,0,I4,0);
3872 VARXOR(UI4,0xffffffff,R8,-1,I4,0);
3873 VARXOR(UI4,0xffffffff,R8,0,I4,-1);
3874 VARXOR(UI4,0,R8,0,I4,0);
3875 VARXOR(UI4,0xffffffff,DATE,-1,I4,0);
3876 VARXOR(UI4,0xffffffff,DATE,0,I4,-1);
3877 VARXOR(UI4,0,DATE,0,I4,0);
3878 if (HAVE_OLEAUT32_I8)
3880 VARXOR(UI4,0xffffffff,I8,0,I8,0xffffffff);
3881 VARXOR(UI4,VARIANT_FALSE,I8,VARIANT_FALSE,I8,0);
3882 VARXOR(UI4,0,I8,0,I8,0);
3883 VARXOR(UI4,0xffffffff,UI8,0,I4,-1);
3884 VARXOR(UI4,0,UI8,0,I4,0);
3886 VARXOR(UI4,0xffffffff,INT,-1,I4,0);
3887 VARXOR(UI4,0xffffffff,INT,0,I4,-1);
3888 VARXOR(UI4,0,INT,0,I4,0);
3889 VARXOR(UI4,0xffffffff,UINT,0xffffffff,I4,0);
3890 VARXOR(UI4,0xffffffff,UINT,0,I4,-1);
3891 VARXOR(UI4,0,UINT,0,I4,0);
3892 rbstr = SysAllocString(szFalse);
3893 VARXOR(UI4,0,BSTR,rbstr,I4,0);
3894 VARXOR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
3895 SysFreeString(rbstr);
3896 rbstr = SysAllocString(szTrue);
3897 VARXOR(UI4,0,BSTR,rbstr,I4,-1);
3898 VARXOR(UI4,0xffffffff,BSTR,rbstr,I4,0);
3899 SysFreeString(rbstr);
3900 VARXORCY(UI4,0xffffffff,10000,I4,-2);
3901 VARXORCY(UI4,0xffffffff,0,I4,-1);
3902 VARXORCY(UI4,0,0,I4,0);
3904 VARXOR(R4,-1,R4,-1,I4,0);
3905 VARXOR(R4,-1,R4,0,I4,-1);
3906 VARXOR(R4,0,R4,0,I4,0);
3907 VARXOR(R4,-1,R8,-1,I4,0);
3908 VARXOR(R4,-1,R8,0,I4,-1);
3909 VARXOR(R4,0,R8,0,I4,0);
3910 VARXOR(R4,-1,DATE,-1,I4,0);
3911 VARXOR(R4,-1,DATE,0,I4,-1);
3912 VARXOR(R4,0,DATE,0,I4,0);
3913 if (HAVE_OLEAUT32_I8)
3915 VARXOR(R4,-1,I8,-1,I8,0);
3916 VARXOR(R4,-1,I8,0,I8,-1);
3917 VARXOR(R4,0,I8,0,I8,0);
3918 VARXOR(R4,-1,UI8,0,I4,-1);
3919 VARXOR(R4,0,UI8,0,I4,0);
3921 VARXOR(R4,-1,INT,-1,I4,0);
3922 VARXOR(R4,-1,INT,0,I4,-1);
3923 VARXOR(R4,0,INT,0,I4,0);
3924 VARXOR(R4,-1,UINT,0xffffffff,I4,0);
3925 VARXOR(R4,-1,UINT,0,I4,-1);
3926 VARXOR(R4,0,UINT,0,I4,0);
3927 rbstr = SysAllocString(szFalse);
3928 VARXOR(R4,0,BSTR,rbstr,I4,0);
3929 VARXOR(R4,-1,BSTR,rbstr,I4,-1);
3930 SysFreeString(rbstr);
3931 rbstr = SysAllocString(szTrue);
3932 VARXOR(R4,0,BSTR,rbstr,I4,-1);
3933 VARXOR(R4,-1,BSTR,rbstr,I4,0);
3934 SysFreeString(rbstr);
3935 VARXORCY(R4,-1,10000,I4,-2);
3936 VARXORCY(R4,-1,0,I4,-1);
3937 VARXORCY(R4,0,0,I4,0);
3939 VARXOR(R8,-1,R8,-1,I4,0);
3940 VARXOR(R8,-1,R8,0,I4,-1);
3941 VARXOR(R8,0,R8,0,I4,0);
3942 VARXOR(R8,-1,DATE,-1,I4,0);
3943 VARXOR(R8,-1,DATE,0,I4,-1);
3944 VARXOR(R8,0,DATE,0,I4,0);
3945 if (HAVE_OLEAUT32_I8)
3947 VARXOR(R8,-1,I8,-1,I8,0);
3948 VARXOR(R8,-1,I8,0,I8,-1);
3949 VARXOR(R8,0,I8,0,I8,0);
3950 VARXOR(R8,-1,UI8,0,I4,-1);
3951 VARXOR(R8,0,UI8,0,I4,0);
3953 VARXOR(R8,-1,INT,-1,I4,0);
3954 VARXOR(R8,-1,INT,0,I4,-1);
3955 VARXOR(R8,0,INT,0,I4,0);
3956 VARXOR(R8,-1,UINT,0xffffffff,I4,0);
3957 VARXOR(R8,-1,UINT,0,I4,-1);
3958 VARXOR(R8,0,UINT,0,I4,0);
3959 rbstr = SysAllocString(szFalse);
3960 VARXOR(R8,0,BSTR,rbstr,I4,0);
3961 VARXOR(R8,-1,BSTR,rbstr,I4,-1);
3962 SysFreeString(rbstr);
3963 rbstr = SysAllocString(szTrue);
3964 VARXOR(R8,0,BSTR,rbstr,I4,-1);
3965 VARXOR(R8,-1,BSTR,rbstr,I4,0);
3966 SysFreeString(rbstr);
3967 VARXORCY(R8,-1,10000,I4,-2);
3968 VARXORCY(R8,-1,0,I4,-1);
3969 VARXORCY(R8,0,0,I4,0);
3971 VARXOR(DATE,-1,DATE,-1,I4,0);
3972 VARXOR(DATE,-1,DATE,0,I4,-1);
3973 VARXOR(DATE,0,DATE,0,I4,0);
3974 if (HAVE_OLEAUT32_I8)
3976 VARXOR(DATE,-1,I8,-1,I8,0);
3977 VARXOR(DATE,-1,I8,0,I8,-1);
3978 VARXOR(DATE,0,I8,0,I8,0);
3979 VARXOR(DATE,-1,UI8,0,I4,-1);
3980 VARXOR(DATE,0,UI8,0,I4,0);
3982 VARXOR(DATE,-1,INT,-1,I4,0);
3983 VARXOR(DATE,-1,INT,0,I4,-1);
3984 VARXOR(DATE,0,INT,0,I4,0);
3985 VARXOR(DATE,-1,UINT,0xffffffff,I4,0);
3986 VARXOR(DATE,-1,UINT,0,I4,-1);
3987 VARXOR(DATE,0,UINT,0,I4,0);
3988 rbstr = SysAllocString(szFalse);
3989 VARXOR(DATE,0,BSTR,rbstr,I4,0);
3990 VARXOR(DATE,-1,BSTR,rbstr,I4,-1);
3991 SysFreeString(rbstr);
3992 rbstr = SysAllocString(szTrue);
3993 VARXOR(DATE,0,BSTR,rbstr,I4,-1);
3994 VARXOR(DATE,-1,BSTR,rbstr,I4,0);
3995 SysFreeString(rbstr);
3996 VARXORCY(DATE,-1,10000,I4,-2);
3997 VARXORCY(DATE,-1,0,I4,-1);
3998 VARXORCY(DATE,0,0,I4,0);
4000 if (HAVE_OLEAUT32_I8)
4002 VARXOR(I8,-1,I8,-1,I8,0);
4003 VARXOR(I8,-1,I8,0,I8,-1);
4004 VARXOR(I8,0,I8,0,I8,0);
4005 VARXOR(I8,-1,UI8,0,I8,-1);
4006 VARXOR(I8,0,UI8,0,I8,0);
4007 VARXOR(I8,-1,UINT,0,I8,-1);
4008 VARXOR(I8,0,UINT,0,I8,0);
4009 rbstr = SysAllocString(szFalse);
4010 VARXOR(I8,0,BSTR,rbstr,I8,0);
4011 VARXOR(I8,-1,BSTR,rbstr,I8,-1);
4012 SysFreeString(rbstr);
4013 rbstr = SysAllocString(szTrue);
4014 VARXOR(I8,0,BSTR,rbstr,I8,-1);
4015 VARXOR(I8,-1,BSTR,rbstr,I8,0);
4016 SysFreeString(rbstr);
4017 VARXORCY(I8,-1,10000,I8,-2);
4018 VARXORCY(I8,-1,0,I8,-1);
4019 VARXORCY(I8,0,0,I8,0);
4021 VARXOR(UI8,0xffff,UI8,0xffff,I4,0);
4022 VARXOR(UI8,0xffff,UI8,0,I4,0xffff);
4023 VARXOR(UI8,0,UI8,0,I4,0);
4024 VARXOR(UI8,0xffff,INT,-1,I4,-65536);
4025 VARXOR(UI8,0xffff,INT,0,I4,0xffff);
4026 VARXOR(UI8,0,INT,0,I4,0);
4027 VARXOR(UI8,0xffff,UINT,0xffff,I4,0);
4028 VARXOR(UI8,0xffff,UINT,0,I4,0xffff);
4029 VARXOR(UI8,0,UINT,0,I4,0);
4030 rbstr = SysAllocString(szFalse);
4031 VARXOR(UI8,0,BSTR,rbstr,I4,0);
4032 VARXOR(UI8,0xffff,BSTR,rbstr,I4,0xffff);
4033 SysFreeString(rbstr);
4034 rbstr = SysAllocString(szTrue);
4035 VARXOR(UI8,0,BSTR,rbstr,I4,-1);
4036 VARXOR(UI8,0xffff,BSTR,rbstr,I4,-65536);
4037 SysFreeString(rbstr);
4038 VARXORCY(UI8,0xffff,10000,I4,65534);
4039 VARXORCY(UI8,0xffff,0,I4,0xffff);
4040 VARXORCY(UI8,0,0,I4,0);
4043 VARXOR(INT,-1,INT,-1,I4,0);
4044 VARXOR(INT,-1,INT,0,I4,-1);
4045 VARXOR(INT,0,INT,0,I4,0);
4046 VARXOR(INT,-1,UINT,0xffff,I4,-65536);
4047 VARXOR(INT,-1,UINT,0,I4,-1);
4048 VARXOR(INT,0,UINT,0,I4,0);
4049 rbstr = SysAllocString(szFalse);
4050 VARXOR(INT,0,BSTR,rbstr,I4,0);
4051 VARXOR(INT,-1,BSTR,rbstr,I4,-1);
4052 SysFreeString(rbstr);
4053 rbstr = SysAllocString(szTrue);
4054 VARXOR(INT,0,BSTR,rbstr,I4,-1);
4055 VARXOR(INT,-1,BSTR,rbstr,I4,0);
4056 SysFreeString(rbstr);
4057 VARXORCY(INT,-1,10000,I4,-2);
4058 VARXORCY(INT,-1,0,I4,-1);
4059 VARXORCY(INT,0,0,I4,0);
4061 VARXOR(UINT,0xffff,UINT,0xffff,I4,0);
4062 VARXOR(UINT,0xffff,UINT,0,I4,0xffff);
4063 VARXOR(UINT,0,UINT,0,I4,0);
4064 rbstr = SysAllocString(szFalse);
4065 VARXOR(UINT,0,BSTR,rbstr,I4,0);
4066 VARXOR(UINT,0xffff,BSTR,rbstr,I4,0xffff);
4067 SysFreeString(rbstr);
4068 rbstr = SysAllocString(szTrue);
4069 VARXOR(UINT,0,BSTR,rbstr,I4,-1);
4070 VARXOR(UINT,0xffff,BSTR,rbstr,I4,-65536);
4071 SysFreeString(rbstr);
4072 VARXORCY(UINT,0xffff,10000,I4,65534);
4073 VARXORCY(UINT,0xffff,0,I4,0xffff);
4074 VARXORCY(UINT,0,0,I4,0);
4076 lbstr = SysAllocString(szFalse);
4077 rbstr = SysAllocString(szFalse);
4078 VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,0);
4079 SysFreeString(rbstr);
4080 rbstr = SysAllocString(szTrue);
4081 VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
4082 SysFreeString(lbstr);
4083 lbstr = SysAllocString(szTrue);
4084 VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_FALSE);
4085 VARXORCY(BSTR,lbstr,10000,I4,-2);
4086 SysFreeString(lbstr);
4087 lbstr = SysAllocString(szFalse);
4088 VARXORCY(BSTR,lbstr,10000,I4,1);
4089 SysFreeString(lbstr);
4090 SysFreeString(rbstr);
4093 static HRESULT (WINAPI *pVarOr)(LPVARIANT,LPVARIANT,LPVARIANT);
4095 #define VAROR(vt1,val1,vt2,val2,rvt,rval) \
4096 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
4097 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
4098 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
4099 test_var_call2( __LINE__, pVarOr, &left, &right, &exp )
4101 #define VARORCY(vt1,val1,val2,rvt,rval) \
4102 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
4103 V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \
4104 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
4105 test_var_call2( __LINE__, pVarOr, &left, &right, &exp )
4107 static void test_VarOr(void)
4109 static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
4110 static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
4111 VARIANT left, right, exp, result;
4112 BSTR lbstr, rbstr;
4113 VARTYPE i;
4114 HRESULT hres;
4116 CHECKPTR(VarOr);
4118 /* Test all possible flag/vt combinations & the resulting vt type */
4119 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
4121 VARTYPE leftvt, rightvt, resvt;
4123 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
4126 SKIPTESTS(leftvt);
4128 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
4130 BOOL bFail = FALSE;
4132 SKIPTESTS(rightvt);
4134 if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
4135 leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
4136 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
4137 continue;
4139 memset(&left, 0, sizeof(left));
4140 memset(&right, 0, sizeof(right));
4141 V_VT(&left) = leftvt | ExtraFlags[i];
4142 V_VT(&right) = rightvt | ExtraFlags[i];
4143 V_VT(&result) = VT_EMPTY;
4144 resvt = VT_I4;
4146 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
4147 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
4148 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
4149 leftvt == VT_CLSID || rightvt == VT_CLSID ||
4150 leftvt == VT_RECORD || rightvt == VT_RECORD ||
4151 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
4152 leftvt == VT_ERROR || rightvt == VT_ERROR)
4154 bFail = TRUE;
4156 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
4158 if (leftvt == rightvt ||
4159 leftvt == VT_I2 || rightvt == VT_I2 ||
4160 leftvt == VT_UI1 || rightvt == VT_UI1 ||
4161 leftvt == VT_BOOL || rightvt == VT_BOOL)
4162 resvt = VT_I2;
4163 else if (leftvt == VT_NULL || rightvt == VT_NULL)
4164 resvt = VT_NULL;
4165 else if (leftvt == VT_I8 || rightvt == VT_I8)
4166 resvt = VT_I8;
4168 else if (leftvt == VT_NULL || rightvt == VT_NULL)
4170 resvt = VT_NULL;
4172 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
4174 if (leftvt == rightvt)
4175 resvt = VT_UI1;
4176 else if (leftvt == rightvt ||
4177 leftvt == VT_I2 || rightvt == VT_I2 ||
4178 leftvt == VT_BOOL || rightvt == VT_BOOL)
4180 resvt = VT_I2;
4182 else if (leftvt == VT_I8 || rightvt == VT_I8)
4183 resvt = VT_I8;
4185 else if (leftvt == VT_I2 || rightvt == VT_I2)
4187 if (leftvt == rightvt ||
4188 leftvt == VT_BOOL || rightvt == VT_BOOL)
4189 resvt = VT_I2;
4190 else if (leftvt == VT_I8 || rightvt == VT_I8)
4191 resvt = VT_I8;
4193 else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
4195 resvt = VT_BOOL;
4197 else if (leftvt == VT_I8 || rightvt == VT_I8)
4199 if (leftvt == VT_INT || rightvt == VT_INT)
4200 bFail = TRUE;
4201 else
4202 resvt = VT_I8;
4204 hres = pVarOr(&left, &right, &result);
4205 if (bFail)
4206 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
4207 "VarOr: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
4208 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
4209 V_VT(&result));
4210 else
4211 ok(hres == S_OK && V_VT(&result) == resvt,
4212 "VarOr: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
4213 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
4214 V_VT(&result));
4219 /* Test returned values. Since we know the returned type is correct
4220 * and that we handle all combinations of invalid types, just check
4221 * that good type combinations produce the desired value.
4222 * FIXME: Test VT_DECIMAL/VT_DISPATCH
4224 VAROR(EMPTY,0,EMPTY,0,I2,0);
4225 VAROR(EMPTY,1,EMPTY,0,I2,0);
4226 VAROR(EMPTY,0,NULL,0,NULL,0);
4227 VAROR(EMPTY,0,I1,0,I4,0);
4228 VAROR(EMPTY,0,I1,1,I4,1);
4229 VAROR(EMPTY,0,UI1,0,I2,0);
4230 VAROR(EMPTY,0,UI1,1,I2,1);
4231 VAROR(EMPTY,0,I2,0,I2,0);
4232 VAROR(EMPTY,0,I2,1,I2,1);
4233 VAROR(EMPTY,0,UI2,0,I4,0);
4234 VAROR(EMPTY,0,UI2,1,I4,1);
4235 VAROR(EMPTY,0,I4,0,I4,0);
4236 VAROR(EMPTY,0,I4,1,I4,1);
4237 VAROR(EMPTY,0,UI4,0,I4,0);
4238 VAROR(EMPTY,0,UI4,1,I4,1);
4239 if (HAVE_OLEAUT32_I8)
4241 VAROR(EMPTY,0,I8,0,I8,0);
4242 VAROR(EMPTY,0,I8,1,I8,1);
4243 VAROR(EMPTY,0,UI8,0,I4,0);
4244 VAROR(EMPTY,0,UI8,1,I4,1);
4246 VAROR(EMPTY,0,INT,0,I4,0);
4247 VAROR(EMPTY,0,INT,1,I4,1);
4248 VAROR(EMPTY,0,UINT,0,I4,0);
4249 VAROR(EMPTY,0,UINT,1,I4,1);
4250 VAROR(EMPTY,0,BOOL,0,I2,0);
4251 VAROR(EMPTY,0,BOOL,1,I2,1);
4252 VAROR(EMPTY,0,R4,0,I4,0);
4253 VAROR(EMPTY,0,R4,1,I4,1);
4254 VAROR(EMPTY,0,R8,0,I4,0);
4255 VAROR(EMPTY,0,R8,1,I4,1);
4256 rbstr = SysAllocString(szFalse);
4257 VAROR(EMPTY,0,BSTR,rbstr,I2,0);
4258 SysFreeString(rbstr);
4259 rbstr = SysAllocString(szTrue);
4260 VAROR(EMPTY,0,BSTR,rbstr,I2,-1);
4261 SysFreeString(rbstr);
4262 VARORCY(EMPTY,0,10000,I4,1);
4264 /* NULL OR 0 = NULL. NULL OR n = n */
4265 VAROR(NULL,0,NULL,0,NULL,0);
4266 VAROR(NULL,1,NULL,0,NULL,0);
4267 VAROR(NULL,0,I1,0,NULL,0);
4268 VAROR(NULL,0,I1,1,I4,1);
4269 VAROR(NULL,0,UI1,0,NULL,0);
4270 VAROR(NULL,0,UI1,1,UI1,1);
4271 VAROR(NULL,0,I2,0,NULL,0);
4272 VAROR(NULL,0,I2,1,I2,1);
4273 VAROR(NULL,0,UI2,0,NULL,0);
4274 VAROR(NULL,0,UI2,1,I4,1);
4275 VAROR(NULL,0,I4,0,NULL,0);
4276 VAROR(NULL,0,I4,1,I4,1);
4277 VAROR(NULL,0,UI4,0,NULL,0);
4278 VAROR(NULL,0,UI4,1,I4,1);
4279 if (HAVE_OLEAUT32_I8)
4281 VAROR(NULL,0,I8,0,NULL,0);
4282 VAROR(NULL,0,I8,1,I8,1);
4283 VAROR(NULL,0,UI8,0,NULL,0);
4284 VAROR(NULL,0,UI8,1,I4,1);
4286 VAROR(NULL,0,INT,0,NULL,0);
4287 VAROR(NULL,0,INT,1,I4,1);
4288 VAROR(NULL,0,UINT,0,NULL,0);
4289 VAROR(NULL,0,UINT,1,I4,1);
4290 VAROR(NULL,0,BOOL,0,NULL,0);
4291 VAROR(NULL,0,BOOL,1,BOOL,1);
4292 VAROR(NULL,0,R4,0,NULL,0);
4293 VAROR(NULL,0,R4,1,I4,1);
4294 VAROR(NULL,0,R8,0,NULL,0);
4295 VAROR(NULL,0,R8,1,I4,1);
4296 rbstr = SysAllocString(szFalse);
4297 VAROR(NULL,0,BSTR,rbstr,NULL,0);
4298 SysFreeString(rbstr);
4299 rbstr = SysAllocString(szTrue);
4300 VAROR(NULL,0,BSTR,rbstr,BOOL,VARIANT_TRUE);
4301 SysFreeString(rbstr);
4302 VARORCY(NULL,0,10000,I4,1);
4303 VARORCY(NULL,0,0,NULL,0);
4305 VAROR(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
4306 VAROR(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
4307 VAROR(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
4308 VAROR(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
4309 /* Assume x,y & y,x are the same from now on to reduce the number of tests */
4310 VAROR(BOOL,VARIANT_TRUE,I1,-1,I4,-1);
4311 VAROR(BOOL,VARIANT_TRUE,I1,0,I4,-1);
4312 VAROR(BOOL,VARIANT_FALSE,I1,0,I4,0);
4313 VAROR(BOOL,VARIANT_TRUE,UI1,255,I2,-1);
4314 VAROR(BOOL,VARIANT_TRUE,UI1,0,I2,-1);
4315 VAROR(BOOL,VARIANT_FALSE,UI1,0,I2,0);
4316 VAROR(BOOL,VARIANT_TRUE,I2,-1,I2,-1);
4317 VAROR(BOOL,VARIANT_TRUE,I2,0,I2,-1);
4318 VAROR(BOOL,VARIANT_FALSE,I2,0,I2,0);
4319 VAROR(BOOL,VARIANT_TRUE,UI2,65535,I4,-1);
4320 VAROR(BOOL,VARIANT_TRUE,UI2,0,I4,-1);
4321 VAROR(BOOL,VARIANT_FALSE,UI2,0,I4,0);
4322 VAROR(BOOL,VARIANT_TRUE,I4,-1,I4,-1);
4323 VAROR(BOOL,VARIANT_TRUE,I4,0,I4,-1);
4324 VAROR(BOOL,VARIANT_FALSE,I4,0,I4,0);
4325 VAROR(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,-1);
4326 VAROR(BOOL,VARIANT_TRUE,UI4,0,I4,-1);
4327 VAROR(BOOL,VARIANT_FALSE,UI4,0,I4,0);
4328 VAROR(BOOL,VARIANT_TRUE,R4,-1,I4,-1);
4329 VAROR(BOOL,VARIANT_TRUE,R4,0,I4,-1);
4330 VAROR(BOOL,VARIANT_FALSE,R4,0,I4,0);
4331 VAROR(BOOL,VARIANT_TRUE,R8,-1,I4,-1);
4332 VAROR(BOOL,VARIANT_TRUE,R8,0,I4,-1);
4333 VAROR(BOOL,VARIANT_FALSE,R8,0,I4,0);
4334 VAROR(BOOL,VARIANT_TRUE,DATE,-1,I4,-1);
4335 VAROR(BOOL,VARIANT_TRUE,DATE,0,I4,-1);
4336 VAROR(BOOL,VARIANT_FALSE,DATE,0,I4,0);
4337 if (HAVE_OLEAUT32_I8)
4339 VAROR(BOOL,VARIANT_TRUE,I8,-1,I8,-1);
4340 VAROR(BOOL,VARIANT_TRUE,I8,0,I8,-1);
4341 VAROR(BOOL,VARIANT_FALSE,I8,0,I8,0);
4342 /* This returns DISP_E_OVERFLOW which indicates that a conversion
4343 * to I4 is performed.
4345 /* VAROR(BOOL,VARIANT_TRUE,UI8,-1,I4,-1); */
4346 VAROR(BOOL,VARIANT_TRUE,UI8,0,I4,-1);
4347 VAROR(BOOL,VARIANT_FALSE,UI8,0,I4,0);
4349 VAROR(BOOL,VARIANT_TRUE,INT,-1,I4,-1);
4350 VAROR(BOOL,VARIANT_TRUE,INT,0,I4,-1);
4351 VAROR(BOOL,VARIANT_FALSE,INT,0,I4,0);
4352 VAROR(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,-1);
4353 VAROR(BOOL,VARIANT_TRUE,UINT,0,I4,-1);
4354 VAROR(BOOL,VARIANT_FALSE,UINT,0,I4,0);
4355 rbstr = SysAllocString(szFalse);
4356 VAROR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_FALSE);
4357 VAROR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
4358 SysFreeString(rbstr);
4359 rbstr = SysAllocString(szTrue);
4360 VAROR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_TRUE);
4361 VAROR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
4362 SysFreeString(rbstr);
4363 VARORCY(BOOL,VARIANT_TRUE,10000,I4,-1);
4364 VARORCY(BOOL,VARIANT_TRUE,0,I4,-1);
4365 VARORCY(BOOL,VARIANT_FALSE,0,I4,0);
4367 VAROR(I1,-1,I1,-1,I4,-1);
4368 VAROR(I1,-1,I1,0,I4,-1);
4369 VAROR(I1,0,I1,0,I4,0);
4370 VAROR(I1,-1,UI1,255,I4,-1);
4371 VAROR(I1,-1,UI1,0,I4,-1);
4372 VAROR(I1,0,UI1,0,I4,0);
4373 VAROR(I1,-1,I2,-1,I4,-1);
4374 VAROR(I1,-1,I2,0,I4,-1);
4375 VAROR(I1,0,I2,0,I4,0);
4376 VAROR(I1,-1,UI2,65535,I4,-1);
4377 VAROR(I1,-1,UI2,0,I4,-1);
4378 VAROR(I1,0,UI2,0,I4,0);
4379 VAROR(I1,-1,I4,-1,I4,-1);
4380 VAROR(I1,-1,I4,0,I4,-1);
4381 VAROR(I1,0,I4,0,I4,0);
4382 VAROR(I1,-1,UI4,0xffffffff,I4,-1);
4383 VAROR(I1,-1,UI4,0,I4,-1);
4384 VAROR(I1,0,UI4,0,I4,0);
4385 VAROR(I1,-1,R4,-1,I4,-1);
4386 VAROR(I1,-1,R4,0,I4,-1);
4387 VAROR(I1,0,R4,0,I4,0);
4388 VAROR(I1,-1,R8,-1,I4,-1);
4389 VAROR(I1,-1,R8,0,I4,-1);
4390 VAROR(I1,0,R8,0,I4,0);
4391 VAROR(I1,-1,DATE,-1,I4,-1);
4392 VAROR(I1,-1,DATE,0,I4,-1);
4393 VAROR(I1,0,DATE,0,I4,0);
4394 if (HAVE_OLEAUT32_I8)
4396 VAROR(I1,-1,I8,-1,I8,-1);
4397 VAROR(I1,-1,I8,0,I8,-1);
4398 VAROR(I1,0,I8,0,I8,0);
4399 VAROR(I1,-1,UI8,0,I4,-1);
4400 VAROR(I1,0,UI8,0,I4,0);
4402 VAROR(I1,-1,INT,-1,I4,-1);
4403 VAROR(I1,-1,INT,0,I4,-1);
4404 VAROR(I1,0,INT,0,I4,0);
4405 VAROR(I1,-1,UINT,0xffffffff,I4,-1);
4406 VAROR(I1,-1,UINT,0,I4,-1);
4407 VAROR(I1,0,UINT,0,I4,0);
4408 rbstr = SysAllocString(szFalse);
4409 VAROR(I1,0,BSTR,rbstr,I4,0);
4410 VAROR(I1,-1,BSTR,rbstr,I4,-1);
4411 SysFreeString(rbstr);
4412 rbstr = SysAllocString(szTrue);
4413 VAROR(I1,0,BSTR,rbstr,I4,-1);
4414 VAROR(I1,-1,BSTR,rbstr,I4,-1);
4415 SysFreeString(rbstr);
4416 VARORCY(I1,-1,10000,I4,-1);
4417 VARORCY(I1,-1,0,I4,-1);
4418 VARORCY(I1,0,0,I4,0);
4420 VAROR(UI1,255,UI1,255,UI1,255);
4421 VAROR(UI1,255,UI1,0,UI1,255);
4422 VAROR(UI1,0,UI1,0,UI1,0);
4423 VAROR(UI1,255,I2,-1,I2,-1);
4424 VAROR(UI1,255,I2,0,I2,255);
4425 VAROR(UI1,0,I2,0,I2,0);
4426 VAROR(UI1,255,UI2,65535,I4,65535);
4427 VAROR(UI1,255,UI2,0,I4,255);
4428 VAROR(UI1,0,UI2,0,I4,0);
4429 VAROR(UI1,255,I4,-1,I4,-1);
4430 VAROR(UI1,255,I4,0,I4,255);
4431 VAROR(UI1,0,I4,0,I4,0);
4432 VAROR(UI1,255,UI4,0xffffffff,I4,-1);
4433 VAROR(UI1,255,UI4,0,I4,255);
4434 VAROR(UI1,0,UI4,0,I4,0);
4435 VAROR(UI1,255,R4,-1,I4,-1);
4436 VAROR(UI1,255,R4,0,I4,255);
4437 VAROR(UI1,0,R4,0,I4,0);
4438 VAROR(UI1,255,R8,-1,I4,-1);
4439 VAROR(UI1,255,R8,0,I4,255);
4440 VAROR(UI1,0,R8,0,I4,0);
4441 VAROR(UI1,255,DATE,-1,I4,-1);
4442 VAROR(UI1,255,DATE,0,I4,255);
4443 VAROR(UI1,0,DATE,0,I4,0);
4444 if (HAVE_OLEAUT32_I8)
4446 VAROR(UI1,255,I8,-1,I8,-1);
4447 VAROR(UI1,255,I8,0,I8,255);
4448 VAROR(UI1,0,I8,0,I8,0);
4449 VAROR(UI1,255,UI8,0,I4,255);
4450 VAROR(UI1,0,UI8,0,I4,0);
4452 VAROR(UI1,255,INT,-1,I4,-1);
4453 VAROR(UI1,255,INT,0,I4,255);
4454 VAROR(UI1,0,INT,0,I4,0);
4455 VAROR(UI1,255,UINT,0xffffffff,I4,-1);
4456 VAROR(UI1,255,UINT,0,I4,255);
4457 VAROR(UI1,0,UINT,0,I4,0);
4458 rbstr = SysAllocString(szFalse);
4459 VAROR(UI1,0,BSTR,rbstr,I2,0);
4460 VAROR(UI1,255,BSTR,rbstr,I2,255);
4461 SysFreeString(rbstr);
4462 rbstr = SysAllocString(szTrue);
4463 VAROR(UI1,0,BSTR,rbstr,I2,-1);
4464 VAROR(UI1,255,BSTR,rbstr,I2,-1);
4465 SysFreeString(rbstr);
4466 VARORCY(UI1,255,10000,I4,255);
4467 VARORCY(UI1,255,0,I4,255);
4468 VARORCY(UI1,0,0,I4,0);
4470 VAROR(I2,-1,I2,-1,I2,-1);
4471 VAROR(I2,-1,I2,0,I2,-1);
4472 VAROR(I2,0,I2,0,I2,0);
4473 VAROR(I2,-1,UI2,65535,I4,-1);
4474 VAROR(I2,-1,UI2,0,I4,-1);
4475 VAROR(I2,0,UI2,0,I4,0);
4476 VAROR(I2,-1,I4,-1,I4,-1);
4477 VAROR(I2,-1,I4,0,I4,-1);
4478 VAROR(I2,0,I4,0,I4,0);
4479 VAROR(I2,-1,UI4,0xffffffff,I4,-1);
4480 VAROR(I2,-1,UI4,0,I4,-1);
4481 VAROR(I2,0,UI4,0,I4,0);
4482 VAROR(I2,-1,R4,-1,I4,-1);
4483 VAROR(I2,-1,R4,0,I4,-1);
4484 VAROR(I2,0,R4,0,I4,0);
4485 VAROR(I2,-1,R8,-1,I4,-1);
4486 VAROR(I2,-1,R8,0,I4,-1);
4487 VAROR(I2,0,R8,0,I4,0);
4488 VAROR(I2,-1,DATE,-1,I4,-1);
4489 VAROR(I2,-1,DATE,0,I4,-1);
4490 VAROR(I2,0,DATE,0,I4,0);
4491 if (HAVE_OLEAUT32_I8)
4493 VAROR(I2,-1,I8,-1,I8,-1);
4494 VAROR(I2,-1,I8,0,I8,-1);
4495 VAROR(I2,0,I8,0,I8,0);
4496 VAROR(I2,-1,UI8,0,I4,-1);
4497 VAROR(I2,0,UI8,0,I4,0);
4499 VAROR(I2,-1,INT,-1,I4,-1);
4500 VAROR(I2,-1,INT,0,I4,-1);
4501 VAROR(I2,0,INT,0,I4,0);
4502 VAROR(I2,-1,UINT,0xffffffff,I4,-1);
4503 VAROR(I2,-1,UINT,0,I4,-1);
4504 VAROR(I2,0,UINT,0,I4,0);
4505 rbstr = SysAllocString(szFalse);
4506 VAROR(I2,0,BSTR,rbstr,I2,0);
4507 VAROR(I2,-1,BSTR,rbstr,I2,-1);
4508 SysFreeString(rbstr);
4509 rbstr = SysAllocString(szTrue);
4510 VAROR(I2,0,BSTR,rbstr,I2,-1);
4511 VAROR(I2,-1,BSTR,rbstr,I2,-1);
4512 SysFreeString(rbstr);
4513 VARORCY(I2,-1,10000,I4,-1);
4514 VARORCY(I2,-1,0,I4,-1);
4515 VARORCY(I2,0,0,I4,0);
4517 VAROR(UI2,65535,UI2,65535,I4,65535);
4518 VAROR(UI2,65535,UI2,0,I4,65535);
4519 VAROR(UI2,0,UI2,0,I4,0);
4520 VAROR(UI2,65535,I4,-1,I4,-1);
4521 VAROR(UI2,65535,I4,0,I4,65535);
4522 VAROR(UI2,0,I4,0,I4,0);
4523 VAROR(UI2,65535,UI4,0xffffffff,I4,-1);
4524 VAROR(UI2,65535,UI4,0,I4,65535);
4525 VAROR(UI2,0,UI4,0,I4,0);
4526 VAROR(UI2,65535,R4,-1,I4,-1);
4527 VAROR(UI2,65535,R4,0,I4,65535);
4528 VAROR(UI2,0,R4,0,I4,0);
4529 VAROR(UI2,65535,R8,-1,I4,-1);
4530 VAROR(UI2,65535,R8,0,I4,65535);
4531 VAROR(UI2,0,R8,0,I4,0);
4532 VAROR(UI2,65535,DATE,-1,I4,-1);
4533 VAROR(UI2,65535,DATE,0,I4,65535);
4534 VAROR(UI2,0,DATE,0,I4,0);
4535 if (HAVE_OLEAUT32_I8)
4537 VAROR(UI2,65535,I8,-1,I8,-1);
4538 VAROR(UI2,65535,I8,0,I8,65535);
4539 VAROR(UI2,0,I8,0,I8,0);
4540 VAROR(UI2,65535,UI8,0,I4,65535);
4541 VAROR(UI2,0,UI8,0,I4,0);
4543 VAROR(UI2,65535,INT,-1,I4,-1);
4544 VAROR(UI2,65535,INT,0,I4,65535);
4545 VAROR(UI2,0,INT,0,I4,0);
4546 VAROR(UI2,65535,UINT,0xffffffff,I4,-1);
4547 VAROR(UI2,65535,UINT,0,I4,65535);
4548 VAROR(UI2,0,UINT,0,I4,0);
4549 rbstr = SysAllocString(szFalse);
4550 VAROR(UI2,0,BSTR,rbstr,I4,0);
4551 VAROR(UI2,65535,BSTR,rbstr,I4,65535);
4552 SysFreeString(rbstr);
4553 rbstr = SysAllocString(szTrue);
4554 VAROR(UI2,0,BSTR,rbstr,I4,-1);
4555 VAROR(UI2,65535,BSTR,rbstr,I4,-1);
4556 SysFreeString(rbstr);
4557 VARORCY(UI2,65535,10000,I4,65535);
4558 VARORCY(UI2,65535,0,I4,65535);
4559 VARORCY(UI2,0,0,I4,0);
4561 VAROR(I4,-1,I4,-1,I4,-1);
4562 VAROR(I4,-1,I4,0,I4,-1);
4563 VAROR(I4,0,I4,0,I4,0);
4564 VAROR(I4,-1,UI4,0xffffffff,I4,-1);
4565 VAROR(I4,-1,UI4,0,I4,-1);
4566 VAROR(I4,0,UI4,0,I4,0);
4567 VAROR(I4,-1,R4,-1,I4,-1);
4568 VAROR(I4,-1,R4,0,I4,-1);
4569 VAROR(I4,0,R4,0,I4,0);
4570 VAROR(I4,-1,R8,-1,I4,-1);
4571 VAROR(I4,-1,R8,0,I4,-1);
4572 VAROR(I4,0,R8,0,I4,0);
4573 VAROR(I4,-1,DATE,-1,I4,-1);
4574 VAROR(I4,-1,DATE,0,I4,-1);
4575 VAROR(I4,0,DATE,0,I4,0);
4576 if (HAVE_OLEAUT32_I8)
4578 VAROR(I4,-1,I8,-1,I8,-1);
4579 VAROR(I4,-1,I8,0,I8,-1);
4580 VAROR(I4,0,I8,0,I8,0);
4581 VAROR(I4,-1,UI8,0,I4,-1);
4582 VAROR(I4,0,UI8,0,I4,0);
4584 VAROR(I4,-1,INT,-1,I4,-1);
4585 VAROR(I4,-1,INT,0,I4,-1);
4586 VAROR(I4,0,INT,0,I4,0);
4587 VAROR(I4,-1,UINT,0xffffffff,I4,-1);
4588 VAROR(I4,-1,UINT,0,I4,-1);
4589 VAROR(I4,0,UINT,0,I4,0);
4590 rbstr = SysAllocString(szFalse);
4591 VAROR(I4,0,BSTR,rbstr,I4,0);
4592 VAROR(I4,-1,BSTR,rbstr,I4,-1);
4593 SysFreeString(rbstr);
4594 rbstr = SysAllocString(szTrue);
4595 VAROR(I4,0,BSTR,rbstr,I4,-1);
4596 VAROR(I4,-1,BSTR,rbstr,I4,-1);
4597 SysFreeString(rbstr);
4598 VARORCY(I4,-1,10000,I4,-1);
4599 VARORCY(I4,-1,0,I4,-1);
4600 VARORCY(I4,0,0,I4,0);
4602 VAROR(UI4,0xffffffff,UI4,0xffffffff,I4,-1);
4603 VAROR(UI4,0xffffffff,UI4,0,I4,-1);
4604 VAROR(UI4,0,UI4,0,I4,0);
4605 VAROR(UI4,0xffffffff,R4,-1,I4,-1);
4606 VAROR(UI4,0xffffffff,R4,0,I4,-1);
4607 VAROR(UI4,0,R4,0,I4,0);
4608 VAROR(UI4,0xffffffff,R8,-1,I4,-1);
4609 VAROR(UI4,0xffffffff,R8,0,I4,-1);
4610 VAROR(UI4,0,R8,0,I4,0);
4611 VAROR(UI4,0xffffffff,DATE,-1,I4,-1);
4612 VAROR(UI4,0xffffffff,DATE,0,I4,-1);
4613 VAROR(UI4,0,DATE,0,I4,0);
4614 if (HAVE_OLEAUT32_I8)
4616 VAROR(UI4,0xffffffff,I8,-1,I8,-1);
4617 VAROR(UI4,0xffffffff,I8,0,I8,0xffffffff);
4618 VAROR(UI4,0,I8,0,I8,0);
4619 VAROR(UI4,0xffffffff,UI8,0,I4,-1);
4620 VAROR(UI4,0,UI8,0,I4,0);
4622 VAROR(UI4,0xffffffff,INT,-1,I4,-1);
4623 VAROR(UI4,0xffffffff,INT,0,I4,-1);
4624 VAROR(UI4,0,INT,0,I4,0);
4625 VAROR(UI4,0xffffffff,UINT,0xffffffff,I4,-1);
4626 VAROR(UI4,0xffffffff,UINT,0,I4,-1);
4627 VAROR(UI4,0,UINT,0,I4,0);
4628 rbstr = SysAllocString(szFalse);
4629 VAROR(UI4,0,BSTR,rbstr,I4,0);
4630 VAROR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
4631 SysFreeString(rbstr);
4632 rbstr = SysAllocString(szTrue);
4633 VAROR(UI4,0,BSTR,rbstr,I4,-1);
4634 VAROR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
4635 SysFreeString(rbstr);
4636 VARORCY(UI4,0xffffffff,10000,I4,-1);
4637 VARORCY(UI4,0xffffffff,0,I4,-1);
4638 VARORCY(UI4,0,0,I4,0);
4640 VAROR(R4,-1,R4,-1,I4,-1);
4641 VAROR(R4,-1,R4,0,I4,-1);
4642 VAROR(R4,0,R4,0,I4,0);
4643 VAROR(R4,-1,R8,-1,I4,-1);
4644 VAROR(R4,-1,R8,0,I4,-1);
4645 VAROR(R4,0,R8,0,I4,0);
4646 VAROR(R4,-1,DATE,-1,I4,-1);
4647 VAROR(R4,-1,DATE,0,I4,-1);
4648 VAROR(R4,0,DATE,0,I4,0);
4649 if (HAVE_OLEAUT32_I8)
4651 VAROR(R4,-1,I8,-1,I8,-1);
4652 VAROR(R4,-1,I8,0,I8,-1);
4653 VAROR(R4,0,I8,0,I8,0);
4654 VAROR(R4,-1,UI8,0,I4,-1);
4655 VAROR(R4,0,UI8,0,I4,0);
4657 VAROR(R4,-1,INT,-1,I4,-1);
4658 VAROR(R4,-1,INT,0,I4,-1);
4659 VAROR(R4,0,INT,0,I4,0);
4660 VAROR(R4,-1,UINT,0xffffffff,I4,-1);
4661 VAROR(R4,-1,UINT,0,I4,-1);
4662 VAROR(R4,0,UINT,0,I4,0);
4663 rbstr = SysAllocString(szFalse);
4664 VAROR(R4,0,BSTR,rbstr,I4,0);
4665 VAROR(R4,-1,BSTR,rbstr,I4,-1);
4666 SysFreeString(rbstr);
4667 rbstr = SysAllocString(szTrue);
4668 VAROR(R4,0,BSTR,rbstr,I4,-1);
4669 VAROR(R4,-1,BSTR,rbstr,I4,-1);
4670 SysFreeString(rbstr);
4671 VARORCY(R4,-1,10000,I4,-1);
4672 VARORCY(R4,-1,0,I4,-1);
4673 VARORCY(R4,0,0,I4,0);
4675 VAROR(R8,-1,R8,-1,I4,-1);
4676 VAROR(R8,-1,R8,0,I4,-1);
4677 VAROR(R8,0,R8,0,I4,0);
4678 VAROR(R8,-1,DATE,-1,I4,-1);
4679 VAROR(R8,-1,DATE,0,I4,-1);
4680 VAROR(R8,0,DATE,0,I4,0);
4681 if (HAVE_OLEAUT32_I8)
4683 VAROR(R8,-1,I8,-1,I8,-1);
4684 VAROR(R8,-1,I8,0,I8,-1);
4685 VAROR(R8,0,I8,0,I8,0);
4686 VAROR(R8,-1,UI8,0,I4,-1);
4687 VAROR(R8,0,UI8,0,I4,0);
4689 VAROR(R8,-1,INT,-1,I4,-1);
4690 VAROR(R8,-1,INT,0,I4,-1);
4691 VAROR(R8,0,INT,0,I4,0);
4692 VAROR(R8,-1,UINT,0xffffffff,I4,-1);
4693 VAROR(R8,-1,UINT,0,I4,-1);
4694 VAROR(R8,0,UINT,0,I4,0);
4695 rbstr = SysAllocString(szFalse);
4696 VAROR(R8,0,BSTR,rbstr,I4,0);
4697 VAROR(R8,-1,BSTR,rbstr,I4,-1);
4698 SysFreeString(rbstr);
4699 rbstr = SysAllocString(szTrue);
4700 VAROR(R8,0,BSTR,rbstr,I4,-1);
4701 VAROR(R8,-1,BSTR,rbstr,I4,-1);
4702 SysFreeString(rbstr);
4703 VARORCY(R8,-1,10000,I4,-1);
4704 VARORCY(R8,-1,0,I4,-1);
4705 VARORCY(R8,0,0,I4,0);
4707 VAROR(DATE,-1,DATE,-1,I4,-1);
4708 VAROR(DATE,-1,DATE,0,I4,-1);
4709 VAROR(DATE,0,DATE,0,I4,0);
4710 if (HAVE_OLEAUT32_I8)
4712 VAROR(DATE,-1,I8,-1,I8,-1);
4713 VAROR(DATE,-1,I8,0,I8,-1);
4714 VAROR(DATE,0,I8,0,I8,0);
4715 VAROR(DATE,-1,UI8,0,I4,-1);
4716 VAROR(DATE,0,UI8,0,I4,0);
4718 VAROR(DATE,-1,INT,-1,I4,-1);
4719 VAROR(DATE,-1,INT,0,I4,-1);
4720 VAROR(DATE,0,INT,0,I4,0);
4721 VAROR(DATE,-1,UINT,0xffffffff,I4,-1);
4722 VAROR(DATE,-1,UINT,0,I4,-1);
4723 VAROR(DATE,0,UINT,0,I4,0);
4724 rbstr = SysAllocString(szFalse);
4725 VAROR(DATE,0,BSTR,rbstr,I4,0);
4726 VAROR(DATE,-1,BSTR,rbstr,I4,-1);
4727 SysFreeString(rbstr);
4728 rbstr = SysAllocString(szTrue);
4729 VAROR(DATE,0,BSTR,rbstr,I4,-1);
4730 VAROR(DATE,-1,BSTR,rbstr,I4,-1);
4731 SysFreeString(rbstr);
4732 VARORCY(DATE,-1,10000,I4,-1);
4733 VARORCY(DATE,-1,0,I4,-1);
4734 VARORCY(DATE,0,0,I4,0);
4736 if (HAVE_OLEAUT32_I8)
4738 VAROR(I8,-1,I8,-1,I8,-1);
4739 VAROR(I8,-1,I8,0,I8,-1);
4740 VAROR(I8,0,I8,0,I8,0);
4741 VAROR(I8,-1,UI8,0,I8,-1);
4742 VAROR(I8,0,UI8,0,I8,0);
4743 /* These overflow under native and Wine
4744 VAROR(I8,-1,INT,-1,I4,-1);
4745 VAROR(I8,-1,INT,0,I4,-1);
4746 VAROR(I8,0,INT,0,I4,0); */
4747 VAROR(I8,-1,UINT,0xffffffff,I8,-1);
4748 VAROR(I8,-1,UINT,0,I8,-1);
4749 VAROR(I8,0,UINT,0,I8,0);
4750 rbstr = SysAllocString(szFalse);
4751 VAROR(I8,0,BSTR,rbstr,I8,0);
4752 VAROR(I8,-1,BSTR,rbstr,I8,-1);
4753 SysFreeString(rbstr);
4754 rbstr = SysAllocString(szTrue);
4755 VAROR(I8,0,BSTR,rbstr,I8,-1);
4756 VAROR(I8,-1,BSTR,rbstr,I8,-1);
4757 SysFreeString(rbstr);
4758 VARORCY(I8,-1,10000,I8,-1);
4759 VARORCY(I8,-1,0,I8,-1);
4760 VARORCY(I8,0,0,I8,0);
4762 VAROR(UI8,0xffff,UI8,0xffff,I4,0xffff);
4763 VAROR(UI8,0xffff,UI8,0,I4,0xffff);
4764 VAROR(UI8,0,UI8,0,I4,0);
4765 VAROR(UI8,0xffff,INT,-1,I4,-1);
4766 VAROR(UI8,0xffff,INT,0,I4,0xffff);
4767 VAROR(UI8,0,INT,0,I4,0);
4768 VAROR(UI8,0xffff,UINT,0xffff,I4,0xffff);
4769 VAROR(UI8,0xffff,UINT,0,I4,0xffff);
4770 VAROR(UI8,0,UINT,0,I4,0);
4771 rbstr = SysAllocString(szFalse);
4772 VAROR(UI8,0,BSTR,rbstr,I4,0);
4773 VAROR(UI8,0xffff,BSTR,rbstr,I4,0xffff);
4774 SysFreeString(rbstr);
4775 rbstr = SysAllocString(szTrue);
4776 VAROR(UI8,0,BSTR,rbstr,I4,-1);
4777 VAROR(UI8,0xffff,BSTR,rbstr,I4,-1);
4778 SysFreeString(rbstr);
4779 VARORCY(UI8,0xffff,10000,I4,0xffff);
4780 VARORCY(UI8,0xffff,0,I4,0xffff);
4781 VARORCY(UI8,0,0,I4,0);
4784 VAROR(INT,-1,INT,-1,I4,-1);
4785 VAROR(INT,-1,INT,0,I4,-1);
4786 VAROR(INT,0,INT,0,I4,0);
4787 VAROR(INT,-1,UINT,0xffff,I4,-1);
4788 VAROR(INT,-1,UINT,0,I4,-1);
4789 VAROR(INT,0,UINT,0,I4,0);
4790 rbstr = SysAllocString(szFalse);
4791 VAROR(INT,0,BSTR,rbstr,I4,0);
4792 VAROR(INT,-1,BSTR,rbstr,I4,-1);
4793 SysFreeString(rbstr);
4794 rbstr = SysAllocString(szTrue);
4795 VAROR(INT,0,BSTR,rbstr,I4,-1);
4796 VAROR(INT,-1,BSTR,rbstr,I4,-1);
4797 SysFreeString(rbstr);
4798 VARORCY(INT,-1,10000,I4,-1);
4799 VARORCY(INT,-1,0,I4,-1);
4800 VARORCY(INT,0,0,I4,0);
4802 VAROR(UINT,0xffff,UINT,0xffff,I4,0xffff);
4803 VAROR(UINT,0xffff,UINT,0,I4,0xffff);
4804 VAROR(UINT,0,UINT,0,I4,0);
4805 rbstr = SysAllocString(szFalse);
4806 VAROR(UINT,0,BSTR,rbstr,I4,0);
4807 VAROR(UINT,0xffff,BSTR,rbstr,I4,0xffff);
4808 SysFreeString(rbstr);
4809 rbstr = SysAllocString(szTrue);
4810 VAROR(UINT,0,BSTR,rbstr,I4,-1);
4811 VAROR(UINT,0xffff,BSTR,rbstr,I4,-1);
4812 SysFreeString(rbstr);
4813 VARORCY(UINT,0xffff,10000,I4,0xffff);
4814 VARORCY(UINT,0xffff,0,I4,0xffff);
4815 VARORCY(UINT,0,0,I4,0);
4817 lbstr = SysAllocString(szFalse);
4818 rbstr = SysAllocString(szFalse);
4819 VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,0);
4820 SysFreeString(rbstr);
4821 rbstr = SysAllocString(szTrue);
4822 VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
4823 SysFreeString(lbstr);
4824 lbstr = SysAllocString(szTrue);
4825 VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
4826 VARORCY(BSTR,lbstr,10000,I4,-1);
4827 SysFreeString(lbstr);
4828 lbstr = SysAllocString(szFalse);
4829 VARORCY(BSTR,lbstr,10000,I4,1);
4830 SysFreeString(lbstr);
4831 SysFreeString(rbstr);
4834 static HRESULT (WINAPI *pVarEqv)(LPVARIANT,LPVARIANT,LPVARIANT);
4836 #define VAREQV(vt1,val1,vt2,val2,rvt,rval) \
4837 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
4838 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
4839 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
4840 test_var_call2( __LINE__, pVarEqv, &left, &right, &exp )
4842 static void test_VarEqv(void)
4844 VARIANT left, right, exp, result;
4845 VARTYPE i;
4846 HRESULT hres;
4848 CHECKPTR(VarEqv);
4850 /* Test all possible flag/vt combinations & the resulting vt type */
4851 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
4853 VARTYPE leftvt, rightvt, resvt;
4855 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
4857 SKIPTESTS(leftvt);
4859 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
4861 BOOL bFail = FALSE;
4863 SKIPTESTS(rightvt);
4865 if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
4866 leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
4867 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
4868 continue;
4870 memset(&left, 0, sizeof(left));
4871 memset(&right, 0, sizeof(right));
4872 V_VT(&left) = leftvt | ExtraFlags[i];
4873 V_VT(&right) = rightvt | ExtraFlags[i];
4874 V_VT(&result) = VT_EMPTY;
4875 resvt = VT_I4;
4877 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
4878 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
4879 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
4880 leftvt == VT_CLSID || rightvt == VT_CLSID ||
4881 leftvt == VT_RECORD || rightvt == VT_RECORD ||
4882 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
4883 leftvt == VT_ERROR || rightvt == VT_ERROR)
4885 bFail = TRUE;
4887 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
4889 if (leftvt == rightvt ||
4890 leftvt == VT_I2 || rightvt == VT_I2 ||
4891 leftvt == VT_UI1 || rightvt == VT_UI1 ||
4892 leftvt == VT_BOOL || rightvt == VT_BOOL)
4893 resvt = VT_I2;
4894 else if (leftvt == VT_NULL || rightvt == VT_NULL)
4895 resvt = VT_NULL;
4896 else if (leftvt == VT_I8 || rightvt == VT_I8)
4897 resvt = VT_I8;
4899 else if (leftvt == VT_NULL || rightvt == VT_NULL)
4901 resvt = VT_NULL;
4903 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
4905 if (leftvt == rightvt)
4906 resvt = VT_UI1;
4907 else if (leftvt == rightvt ||
4908 leftvt == VT_I2 || rightvt == VT_I2 ||
4909 leftvt == VT_BOOL || rightvt == VT_BOOL)
4911 resvt = VT_I2;
4913 else if (leftvt == VT_I8 || rightvt == VT_I8)
4914 resvt = VT_I8;
4916 else if (leftvt == VT_I2 || rightvt == VT_I2)
4918 if (leftvt == rightvt ||
4919 leftvt == VT_BOOL || rightvt == VT_BOOL)
4920 resvt = VT_I2;
4921 else if (leftvt == VT_I8 || rightvt == VT_I8)
4922 resvt = VT_I8;
4924 else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
4926 resvt = VT_BOOL;
4928 else if (leftvt == VT_I8 || rightvt == VT_I8)
4930 if (leftvt == VT_INT || rightvt == VT_INT)
4931 bFail = TRUE;
4932 else
4933 resvt = VT_I8;
4935 hres = pVarEqv(&left, &right, &result);
4936 if (bFail)
4937 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
4938 "VarEqv: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
4939 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
4940 V_VT(&result));
4941 else
4942 ok(hres == S_OK && V_VT(&result) == resvt,
4943 "VarEqv: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
4944 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
4945 V_VT(&result));
4950 /* Test returned values */
4951 VAREQV(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
4952 VAREQV(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
4953 VAREQV(BOOL,TRUE,BOOL,TRUE,BOOL,VARIANT_TRUE);
4954 VAREQV(BOOL,FALSE,BOOL,FALSE,BOOL,VARIANT_TRUE);
4955 VAREQV(BOOL,TRUE,BOOL,FALSE,BOOL,-2);
4956 VAREQV(BOOL,FALSE,BOOL,TRUE,BOOL,-2);
4957 VAREQV(BOOL,6,BOOL,7,BOOL,-2);
4958 VAREQV(BOOL,6,BOOL,6,BOOL,VARIANT_TRUE);
4959 VAREQV(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE,I2,VARIANT_TRUE);
4960 VAREQV(BOOL,VARIANT_TRUE,I2,VARIANT_FALSE,I2,VARIANT_FALSE);
4961 VAREQV(BOOL,6,I2,7,I2,-2);
4962 VAREQV(UI1,1,UI1,1,UI1,255);
4963 VAREQV(UI1,1,UI1,0,UI1,254);
4964 VAREQV(UI1,0,UI1,1,UI1,254);
4965 if (HAVE_OLEAUT32_I8)
4967 VAREQV(UI4,VARIANT_FALSE,I8,VARIANT_FALSE,I8,-1);
4968 VAREQV(UI4,5,I8,19,I8,-23);
4969 VAREQV(UI4,VARIANT_FALSE,UI8,VARIANT_FALSE,I4,-1);
4973 static HRESULT (WINAPI *pVarMul)(LPVARIANT,LPVARIANT,LPVARIANT);
4975 #define VARMUL(vt1,val1,vt2,val2,rvt,rval) \
4976 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
4977 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
4978 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
4979 test_var_call2( __LINE__, pVarMul, &left, &right, &exp )
4981 static void test_VarMul(void)
4983 VARIANT left, right, exp, result, cy, dec;
4984 VARTYPE i;
4985 BSTR lbstr, rbstr;
4986 HRESULT hres;
4987 double r;
4989 CHECKPTR(VarMul);
4991 lbstr = SysAllocString(sz12);
4992 rbstr = SysAllocString(sz12);
4994 /* Test all possible flag/vt combinations & the resulting vt type */
4995 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
4997 VARTYPE leftvt, rightvt, resvt;
4999 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
5002 SKIPTESTS(leftvt);
5004 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
5006 BOOL bFail = FALSE;
5008 SKIPTESTS(rightvt);
5010 if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
5011 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
5012 continue;
5014 memset(&left, 0, sizeof(left));
5015 memset(&right, 0, sizeof(right));
5016 V_VT(&left) = leftvt | ExtraFlags[i];
5017 if (leftvt == VT_BSTR)
5018 V_BSTR(&left) = lbstr;
5019 V_VT(&right) = rightvt | ExtraFlags[i];
5020 if (rightvt == VT_BSTR)
5021 V_BSTR(&right) = rbstr;
5022 V_VT(&result) = VT_EMPTY;
5023 resvt = VT_UNKNOWN;
5025 /* Don't ask me why but native VarMul cannot handle:
5026 VT_I1, VT_UI2, VT_UI4, VT_INT, VT_UINT and VT_UI8.
5027 Tested with DCOM98, Win2k, WinXP */
5028 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
5029 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
5030 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
5031 leftvt == VT_CLSID || rightvt == VT_CLSID ||
5032 leftvt == VT_RECORD || rightvt == VT_RECORD ||
5033 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
5034 leftvt == VT_ERROR || rightvt == VT_ERROR ||
5035 leftvt == VT_I1 || rightvt == VT_I1 ||
5036 leftvt == VT_UI2 || rightvt == VT_UI2 ||
5037 leftvt == VT_UI4 || rightvt == VT_UI4 ||
5038 leftvt == VT_UI8 || rightvt == VT_UI8 ||
5039 leftvt == VT_INT || rightvt == VT_INT ||
5040 leftvt == VT_UINT || rightvt == VT_UINT) {
5041 bFail = TRUE;
5044 if (leftvt == VT_NULL || rightvt == VT_NULL)
5045 resvt = VT_NULL;
5046 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
5047 resvt = VT_DECIMAL;
5048 else if (leftvt == VT_R8 || rightvt == VT_R8 ||
5049 leftvt == VT_BSTR || rightvt == VT_BSTR ||
5050 leftvt == VT_DATE || rightvt == VT_DATE)
5051 resvt = VT_R8;
5052 else if (leftvt == VT_R4 || rightvt == VT_R4) {
5053 if (leftvt == VT_I4 || rightvt == VT_I4 ||
5054 leftvt == VT_I8 || rightvt == VT_I8 ||
5055 leftvt == VT_CY || rightvt == VT_CY)
5056 resvt = VT_R8;
5057 else
5058 resvt = VT_R4;
5059 } else if (leftvt == VT_CY || rightvt == VT_CY)
5060 resvt = VT_CY;
5061 else if (leftvt == VT_I8 || rightvt == VT_I8)
5062 resvt = VT_I8;
5063 else if (leftvt == VT_I4 || rightvt == VT_I4)
5064 resvt = VT_I4;
5065 else if (leftvt == VT_I2 || rightvt == VT_I2 ||
5066 leftvt == VT_BOOL || rightvt == VT_BOOL ||
5067 (leftvt == VT_EMPTY && rightvt == VT_EMPTY))
5068 resvt = VT_I2;
5069 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
5070 resvt = VT_UI1;
5072 hres = pVarMul(&left, &right, &result);
5073 if (bFail) {
5074 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
5075 "VarMul: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
5076 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
5077 V_VT(&result));
5078 } else {
5079 ok(hres == S_OK && V_VT(&result) == resvt,
5080 "VarMul: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
5081 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
5082 V_VT(&result));
5088 /* Test returned values */
5089 VARMUL(I4,4,I4,2,I4,8);
5090 VARMUL(I2,4,I2,2,I2,8);
5091 VARMUL(I2,-13,I4,5,I4,-65);
5092 VARMUL(I4,-13,I4,5,I4,-65);
5093 VARMUL(I2,7,R4,0.5f,R4,3.5f);
5094 VARMUL(R4,0.5f,I4,5,R8,2.5);
5095 VARMUL(R8,7.1,BOOL,0,R8,0);
5096 VARMUL(BSTR,lbstr,I2,4,R8,48);
5097 VARMUL(BSTR,lbstr,BOOL,1,R8,12);
5098 VARMUL(BSTR,lbstr,R4,0.1f,R8,1.2);
5099 VARMUL(BSTR,lbstr,BSTR,rbstr,R8,144);
5100 VARMUL(R4,0.2f,BSTR,rbstr,R8,2.4);
5101 VARMUL(DATE,2.25,I4,7,R8,15.75);
5103 VARMUL(UI1, UI1_MAX, UI1, UI1_MAX, I4, UI1_MAX * UI1_MAX);
5104 VARMUL(I2, I2_MAX, I2, I2_MAX, I4, I2_MAX * I2_MAX);
5105 VARMUL(I2, I2_MAX, I2, I2_MIN, I4, I2_MAX * I2_MIN);
5106 VARMUL(I2, I2_MIN, I2, I2_MIN, I4, I2_MIN * I2_MIN);
5107 VARMUL(I4, I4_MAX, I4, I4_MAX, R8, (double)I4_MAX * I4_MAX);
5108 VARMUL(I4, I4_MAX, I4, I4_MIN, R8, (double)I4_MAX * I4_MIN);
5109 VARMUL(I4, I4_MIN, I4, I4_MIN, R8, (double)I4_MIN * I4_MIN);
5110 VARMUL(R4, R4_MAX, R4, R4_MAX, R8, (double)R4_MAX * R4_MAX);
5111 VARMUL(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX * R4_MIN);
5112 VARMUL(R4, R4_MIN, R4, R4_MIN, R4, R4_MIN * R4_MIN);
5113 VARMUL(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX * R8_MIN);
5114 VARMUL(R8, R8_MIN, R8, R8_MIN, R8, R8_MIN * R8_MIN);
5116 /* Manuly test some VT_CY and VT_DECIMAL variants */
5117 V_VT(&cy) = VT_CY;
5118 hres = VarCyFromI4(4711, &V_CY(&cy));
5119 ok(hres == S_OK, "VarCyFromI4 failed!\n");
5120 V_VT(&dec) = VT_DECIMAL;
5121 hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec));
5122 ok(hres == S_OK, "VarDecFromR4 failed!\n");
5123 memset(&left, 0, sizeof(left));
5124 memset(&right, 0, sizeof(right));
5125 V_VT(&left) = VT_I4;
5126 V_I4(&left) = -11;
5127 V_VT(&right) = VT_UI1;
5128 V_UI1(&right) = 9;
5130 hres = pVarMul(&cy, &right, &result);
5131 ok(hres == S_OK && V_VT(&result) == VT_CY, "VarMul: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result)));
5132 hres = VarR8FromCy(V_CY(&result), &r);
5133 ok(hres == S_OK && EQ_DOUBLE(r, 42399), "VarMul: CY value %f, expected %f\n", r, (double)42399);
5135 hres = pVarMul(&left, &dec, &result);
5136 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL, "VarMul: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
5137 hres = VarR8FromDec(&V_DECIMAL(&result), &r);
5138 ok(hres == S_OK && EQ_DOUBLE(r, 46.2), "VarMul: DECIMAL value %f, expected %f\n", r, (double)46.2);
5140 SysFreeString(lbstr);
5141 SysFreeString(rbstr);
5144 static HRESULT (WINAPI *pVarAdd)(LPVARIANT,LPVARIANT,LPVARIANT);
5146 #define VARADD(vt1,val1,vt2,val2,rvt,rval) \
5147 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
5148 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
5149 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
5150 test_var_call2( __LINE__, pVarAdd, &left, &right, &exp )
5152 static void test_VarAdd(void)
5154 VARIANT left, right, exp, result, cy, dec;
5155 VARTYPE i;
5156 BSTR lbstr, rbstr;
5157 HRESULT hres;
5158 double r;
5160 CHECKPTR(VarAdd);
5162 lbstr = SysAllocString(sz12);
5163 rbstr = SysAllocString(sz12);
5165 /* Test all possible flag/vt combinations & the resulting vt type */
5166 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
5168 VARTYPE leftvt, rightvt, resvt;
5170 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
5173 SKIPTESTS(leftvt);
5175 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
5177 BOOL bFail = FALSE;
5179 SKIPTESTS(rightvt);
5181 if (leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
5182 continue;
5184 memset(&left, 0, sizeof(left));
5185 memset(&right, 0, sizeof(right));
5186 V_VT(&left) = leftvt | ExtraFlags[i];
5187 if (leftvt == VT_BSTR)
5188 V_BSTR(&left) = lbstr;
5189 V_VT(&right) = rightvt | ExtraFlags[i];
5190 if (rightvt == VT_BSTR)
5191 V_BSTR(&right) = rbstr;
5192 V_VT(&result) = VT_EMPTY;
5193 resvt = VT_ERROR;
5195 /* Don't ask me why but native VarAdd cannot handle:
5196 VT_I1, VT_UI2, VT_UI4, VT_INT, VT_UINT and VT_UI8.
5197 Tested with DCOM98, Win2k, WinXP */
5198 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
5199 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
5200 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
5201 leftvt == VT_CLSID || rightvt == VT_CLSID ||
5202 leftvt == VT_RECORD || rightvt == VT_RECORD ||
5203 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
5204 leftvt == VT_ERROR || rightvt == VT_ERROR ||
5205 leftvt == VT_I1 || rightvt == VT_I1 ||
5206 leftvt == VT_UI2 || rightvt == VT_UI2 ||
5207 leftvt == VT_UI4 || rightvt == VT_UI4 ||
5208 leftvt == VT_UI8 || rightvt == VT_UI8 ||
5209 leftvt == VT_INT || rightvt == VT_INT ||
5210 leftvt == VT_UINT || rightvt == VT_UINT) {
5211 bFail = TRUE;
5214 if (leftvt == VT_NULL || rightvt == VT_NULL)
5215 resvt = VT_NULL;
5216 else if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH)
5217 bFail = TRUE;
5218 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
5219 resvt = VT_DECIMAL;
5220 else if (leftvt == VT_DATE || rightvt == VT_DATE)
5221 resvt = VT_DATE;
5222 else if (leftvt == VT_CY || rightvt == VT_CY)
5223 resvt = VT_CY;
5224 else if (leftvt == VT_R8 || rightvt == VT_R8)
5225 resvt = VT_R8;
5226 else if (leftvt == VT_BSTR || rightvt == VT_BSTR) {
5227 if ((leftvt == VT_BSTR && rightvt == VT_BSTR) ||
5228 leftvt == VT_EMPTY || rightvt == VT_EMPTY)
5229 resvt = VT_BSTR;
5230 else
5231 resvt = VT_R8;
5232 } else if (leftvt == VT_R4 || rightvt == VT_R4) {
5233 if (leftvt == VT_I4 || rightvt == VT_I4 ||
5234 leftvt == VT_I8 || rightvt == VT_I8)
5235 resvt = VT_R8;
5236 else
5237 resvt = VT_R4;
5239 else if (leftvt == VT_I8 || rightvt == VT_I8)
5240 resvt = VT_I8;
5241 else if (leftvt == VT_I4 || rightvt == VT_I4)
5242 resvt = VT_I4;
5243 else if (leftvt == VT_I2 || rightvt == VT_I2 ||
5244 leftvt == VT_BOOL || rightvt == VT_BOOL ||
5245 (leftvt == VT_EMPTY && rightvt == VT_EMPTY))
5246 resvt = VT_I2;
5247 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
5248 resvt = VT_UI1;
5250 hres = pVarAdd(&left, &right, &result);
5251 if (bFail) {
5252 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
5253 "VarAdd: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
5254 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
5255 V_VT(&result));
5256 } else {
5257 ok(hres == S_OK && V_VT(&result) == resvt,
5258 "VarAdd: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
5259 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
5260 V_VT(&result));
5262 /* Note, we don't clear left/right deliberately here */
5263 VariantClear(&result);
5268 /* Test returned values */
5269 VARADD(I4,4,I4,2,I4,6);
5270 VARADD(I2,4,I2,2,I2,6);
5271 VARADD(I2,-13,I4,5,I4,-8);
5272 VARADD(I4,-13,I4,5,I4,-8);
5273 VARADD(I2,7,R4,0.5f,R4,7.5f);
5274 VARADD(R4,0.5f,I4,5,R8,5.5);
5275 VARADD(R8,7.1,BOOL,0,R8,7.1);
5276 VARADD(BSTR,lbstr,I2,4,R8,16);
5277 VARADD(BSTR,lbstr,BOOL,1,R8,13);
5278 VARADD(BSTR,lbstr,R4,0.1f,R8,12.1);
5279 VARADD(R4,0.2f,BSTR,rbstr,R8,12.2);
5280 VARADD(DATE,2.25,I4,7,DATE,9.25);
5281 VARADD(DATE,1.25,R4,-1.7f,DATE,-0.45);
5283 VARADD(UI1, UI1_MAX, UI1, UI1_MAX, I2, UI1_MAX + UI1_MAX);
5284 VARADD(I2, I2_MAX, I2, I2_MAX, I4, I2_MAX + I2_MAX);
5285 VARADD(I2, I2_MAX, I2, I2_MIN, I2, I2_MAX + I2_MIN);
5286 VARADD(I2, I2_MIN, I2, I2_MIN, I4, I2_MIN + I2_MIN);
5287 VARADD(I4, I4_MAX, I4, I4_MIN, I4, I4_MAX + I4_MIN);
5288 VARADD(I4, I4_MAX, I4, I4_MAX, R8, (double)I4_MAX + I4_MAX);
5289 VARADD(I4, I4_MIN, I4, I4_MIN, R8, (double)I4_MIN + I4_MIN);
5290 VARADD(R4, R4_MAX, R4, R4_MAX, R8, (double)R4_MAX + R4_MAX);
5291 VARADD(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX + R4_MIN);
5292 VARADD(R4, R4_MIN, R4, R4_MIN, R4, R4_MIN + R4_MIN);
5293 VARADD(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX + R8_MIN);
5294 VARADD(R8, R8_MIN, R8, R8_MIN, R8, R8_MIN + R8_MIN);
5296 /* Manually test BSTR + BSTR */
5297 V_VT(&left) = VT_BSTR;
5298 V_BSTR(&left) = lbstr;
5299 V_VT(&right) = VT_BSTR;
5300 V_BSTR(&right) = rbstr;
5301 hres = pVarAdd(&left, &right, &result);
5302 ok(hres == S_OK && V_VT(&result) == VT_BSTR, "VarAdd: expected coerced type VT_BSTR, got %s!\n", vtstr(V_VT(&result)));
5303 hres = VarR8FromStr(V_BSTR(&result), 0, 0, &r);
5304 ok(hres == S_OK && EQ_DOUBLE(r, 1212), "VarAdd: BSTR value %f, expected %f\n", r, (double)1212);
5305 VariantClear(&result);
5307 /* Manuly test some VT_CY and VT_DECIMAL variants */
5308 V_VT(&cy) = VT_CY;
5309 hres = VarCyFromI4(4711, &V_CY(&cy));
5310 ok(hres == S_OK, "VarCyFromI4 failed!\n");
5311 V_VT(&dec) = VT_DECIMAL;
5312 hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec));
5313 ok(hres == S_OK, "VarDecFromR4 failed!\n");
5314 memset(&left, 0, sizeof(left));
5315 memset(&right, 0, sizeof(right));
5316 V_VT(&left) = VT_I4;
5317 V_I4(&left) = -11;
5318 V_VT(&right) = VT_UI1;
5319 V_UI1(&right) = 9;
5321 hres = pVarAdd(&cy, &right, &result);
5322 ok(hres == S_OK && V_VT(&result) == VT_CY, "VarAdd: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result)));
5323 hres = VarR8FromCy(V_CY(&result), &r);
5324 ok(hres == S_OK && EQ_DOUBLE(r, 4720), "VarAdd: CY value %f, expected %f\n", r, (double)4720);
5326 hres = pVarAdd(&left, &dec, &result);
5327 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL, "VarAdd: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
5328 hres = VarR8FromDec(&V_DECIMAL(&result), &r);
5329 ok(hres == S_OK && EQ_DOUBLE(r, -15.2), "VarAdd: DECIMAL value %f, expected %f\n", r, (double)-15.2);
5330 VariantClear(&result);
5332 SysFreeString(lbstr);
5333 SysFreeString(rbstr);
5336 static HRESULT (WINAPI *pVarCmp)(LPVARIANT,LPVARIANT,LCID,ULONG);
5337 static HRESULT (WINAPI *pVarCat)(LPVARIANT,LPVARIANT,LPVARIANT);
5339 static void test_VarCat(void)
5341 LCID lcid;
5342 VARIANT left, right, result, expected, expected_broken;
5343 static const WCHAR sz34[] = {'3','4','\0'};
5344 static const WCHAR sz1234[] = {'1','2','3','4','\0'};
5345 static const WCHAR date_sz12[] = {'9','/','3','0','/','1','9','8','0','1','2','\0'};
5346 static const WCHAR date_sz12_broken[] = {'9','/','3','0','/','8','0','1','2','\0'};
5347 static const WCHAR sz12_date[] = {'1','2','9','/','3','0','/','1','9','8','0','\0'};
5348 static const WCHAR sz12_date_broken[] = {'1','2','9','/','3','0','/','8','0','\0'};
5349 static const WCHAR sz_empty[] = {'\0'};
5350 TCHAR orig_date_format[128];
5351 VARTYPE leftvt, rightvt, resultvt;
5352 HRESULT hres;
5353 HRESULT expected_error_num;
5355 CHECKPTR(VarCat);
5357 /* Set date format for testing */
5358 lcid = LOCALE_USER_DEFAULT;
5359 GetLocaleInfo(lcid,LOCALE_SSHORTDATE,orig_date_format,128);
5360 SetLocaleInfo(lcid,LOCALE_SSHORTDATE,"M/d/yyyy");
5362 VariantInit(&left);
5363 VariantInit(&right);
5364 VariantInit(&result);
5365 VariantInit(&expected);
5367 /* Check expected types for all combinations */
5368 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
5371 SKIPTESTS(leftvt);
5373 /* Check if we need/have support for I8 and/or UI8 */
5374 if ((leftvt == VT_I8 || leftvt == VT_UI8) && !HAVE_OLEAUT32_I8)
5375 continue;
5377 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
5380 SKIPTESTS(rightvt);
5381 expected_error_num = S_OK;
5382 resultvt = VT_EMPTY;
5384 if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
5385 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN ||
5386 leftvt == VT_RECORD || rightvt == VT_RECORD ||
5387 leftvt == 15 || rightvt == 15 /* Undefined type */)
5388 continue;
5390 /* Check if we need/have support for I8 and/or UI8 */
5391 if ((rightvt == VT_I8 || rightvt == VT_UI8) && !HAVE_OLEAUT32_I8)
5392 continue;
5394 if (leftvt == VT_NULL && rightvt == VT_NULL)
5395 resultvt = VT_NULL;
5396 else if (leftvt == VT_VARIANT && (rightvt == VT_ERROR ||
5397 rightvt == VT_DATE || rightvt == VT_DECIMAL))
5398 expected_error_num = DISP_E_TYPEMISMATCH;
5399 else if ((leftvt == VT_I2 || leftvt == VT_I4 ||
5400 leftvt == VT_R4 || leftvt == VT_R8 ||
5401 leftvt == VT_CY || leftvt == VT_BOOL ||
5402 leftvt == VT_BSTR || leftvt == VT_I1 ||
5403 leftvt == VT_UI1 || leftvt == VT_UI2 ||
5404 leftvt == VT_UI4 || leftvt == VT_I8 ||
5405 leftvt == VT_UI8 || leftvt == VT_INT ||
5406 leftvt == VT_UINT || leftvt == VT_EMPTY ||
5407 leftvt == VT_NULL || leftvt == VT_DECIMAL ||
5408 leftvt == VT_DATE)
5410 (rightvt == VT_I2 || rightvt == VT_I4 ||
5411 rightvt == VT_R4 || rightvt == VT_R8 ||
5412 rightvt == VT_CY || rightvt == VT_BOOL ||
5413 rightvt == VT_BSTR || rightvt == VT_I1 ||
5414 rightvt == VT_UI1 || rightvt == VT_UI2 ||
5415 rightvt == VT_UI4 || rightvt == VT_I8 ||
5416 rightvt == VT_UI8 || rightvt == VT_INT ||
5417 rightvt == VT_UINT || rightvt == VT_EMPTY ||
5418 rightvt == VT_NULL || rightvt == VT_DECIMAL ||
5419 rightvt == VT_DATE))
5420 resultvt = VT_BSTR;
5421 else if (rightvt == VT_ERROR && leftvt < VT_VOID)
5422 expected_error_num = DISP_E_TYPEMISMATCH;
5423 else if (leftvt == VT_ERROR && (rightvt == VT_DATE ||
5424 rightvt == VT_ERROR || rightvt == VT_DECIMAL))
5425 expected_error_num = DISP_E_TYPEMISMATCH;
5426 else if (rightvt == VT_DATE || rightvt == VT_ERROR ||
5427 rightvt == VT_DECIMAL)
5428 expected_error_num = DISP_E_BADVARTYPE;
5429 else if (leftvt == VT_ERROR || rightvt == VT_ERROR)
5430 expected_error_num = DISP_E_TYPEMISMATCH;
5431 else if (leftvt == VT_VARIANT)
5432 expected_error_num = DISP_E_TYPEMISMATCH;
5433 else if (rightvt == VT_VARIANT && (leftvt == VT_EMPTY ||
5434 leftvt == VT_NULL || leftvt == VT_I2 ||
5435 leftvt == VT_I4 || leftvt == VT_R4 ||
5436 leftvt == VT_R8 || leftvt == VT_CY ||
5437 leftvt == VT_DATE || leftvt == VT_BSTR ||
5438 leftvt == VT_BOOL || leftvt == VT_DECIMAL ||
5439 leftvt == VT_I1 || leftvt == VT_UI1 ||
5440 leftvt == VT_UI2 || leftvt == VT_UI4 ||
5441 leftvt == VT_I8 || leftvt == VT_UI8 ||
5442 leftvt == VT_INT || leftvt == VT_UINT
5444 expected_error_num = DISP_E_TYPEMISMATCH;
5445 else
5446 expected_error_num = DISP_E_BADVARTYPE;
5448 V_VT(&left) = leftvt;
5449 V_VT(&right) = rightvt;
5451 switch (leftvt) {
5452 case VT_BSTR:
5453 V_BSTR(&left) = SysAllocString(sz_empty); break;
5454 case VT_DATE:
5455 V_DATE(&left) = 0.0; break;
5456 case VT_DECIMAL:
5457 VarDecFromR8(0.0, &V_DECIMAL(&left)); break;
5458 default:
5459 V_I8(&left) = 0;
5462 switch (rightvt) {
5463 case VT_BSTR:
5464 V_BSTR(&right) = SysAllocString(sz_empty); break;
5465 case VT_DATE:
5466 V_DATE(&right) = 0.0; break;
5467 case VT_DECIMAL:
5468 VarDecFromR8(0.0, &V_DECIMAL(&right)); break;
5469 default:
5470 V_I8(&right) = 0;
5473 hres = pVarCat(&left, &right, &result);
5475 /* Determine the error code for the vt combination */
5476 ok(hres == expected_error_num,
5477 "VarCat: %d, %d returned error, 0x%X expected 0x%X.\n",
5478 leftvt, rightvt, expected_error_num, hres);
5480 /* Check types are correct */
5481 ok(V_VT(&result) == resultvt,
5482 "VarCat: %d, %d: expected vt %d, got vt %d\n",
5483 leftvt, rightvt, resultvt, V_VT(&result));
5485 VariantClear(&left);
5486 VariantClear(&right);
5487 VariantClear(&result);
5491 /* Running single comparison tests to compare outputs */
5493 /* Test concat strings */
5494 V_VT(&left) = VT_BSTR;
5495 V_VT(&right) = VT_BSTR;
5496 V_VT(&expected) = VT_BSTR;
5497 V_BSTR(&left) = SysAllocString(sz12);
5498 V_BSTR(&right) = SysAllocString(sz34);
5499 V_BSTR(&expected) = SysAllocString(sz1234);
5500 hres = pVarCat(&left,&right,&result);
5501 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5502 if (pVarCmp)
5503 ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ,
5504 "VarCat: VT_BSTR concat with VT_BSTR failed to return correct result\n");
5506 VariantClear(&left);
5507 VariantClear(&right);
5508 VariantClear(&result);
5510 /* Test if expression is VT_ERROR */
5511 V_VT(&left) = VT_ERROR;
5512 V_VT(&right) = VT_BSTR;
5513 V_BSTR(&right) = SysAllocString(sz1234);
5514 hres = pVarCat(&left,&right,&result);
5515 ok(hres == DISP_E_TYPEMISMATCH, "VarCat should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hres);
5516 ok(V_VT(&result) == VT_EMPTY,
5517 "VarCat: VT_ERROR concat with VT_BSTR should have returned VT_EMPTY\n");
5519 VariantClear(&left);
5520 VariantClear(&right);
5521 VariantClear(&result);
5523 V_VT(&left) = VT_BSTR;
5524 V_VT(&right) = VT_ERROR;
5525 V_BSTR(&left) = SysAllocString(sz1234);
5526 hres = pVarCat(&left,&right,&result);
5527 ok(hres == DISP_E_TYPEMISMATCH, "VarCat should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hres);
5528 ok(V_VT(&result) == VT_EMPTY,
5529 "VarCat: VT_BSTR concat with VT_ERROR should have returned VT_EMPTY\n");
5531 VariantClear(&left);
5532 VariantClear(&right);
5533 VariantClear(&result);
5534 VariantClear(&expected);
5536 /* Test combining boolean with number */
5537 V_VT(&left) = VT_INT;
5538 V_VT(&right) = VT_BOOL;
5539 V_VT(&expected) = VT_BSTR;
5540 V_INT(&left) = 12;
5541 V_BOOL(&right) = TRUE;
5542 V_BSTR(&expected) = SysAllocString(sz12_true);
5543 hres = pVarCat(&left,&right,&result);
5544 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5545 if (pVarCmp)
5547 hres = pVarCmp(&result,&expected,lcid,0);
5548 ok(hres == VARCMP_EQ, "Expected VARCMP_EQ, got %08x for %s, %s\n",
5549 hres, variantstr(&result), variantstr(&expected));
5552 VariantClear(&left);
5553 VariantClear(&right);
5554 VariantClear(&result);
5555 VariantClear(&expected);
5557 V_VT(&left) = VT_INT;
5558 V_VT(&right) = VT_BOOL;
5559 V_VT(&expected) = VT_BSTR;
5560 V_INT(&left) = 12;
5561 V_BOOL(&right) = FALSE;
5562 V_BSTR(&expected) = SysAllocString(sz12_false);
5563 hres = pVarCat(&left,&right,&result);
5564 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5565 if (pVarCmp)
5567 hres = pVarCmp(&result,&expected,lcid,0);
5568 ok(hres == VARCMP_EQ, "Expected VARCMP_EQ, got %08x for %s, %s\n",
5569 hres, variantstr(&result), variantstr(&expected));
5572 VariantClear(&left);
5573 VariantClear(&right);
5574 VariantClear(&result);
5575 VariantClear(&expected);
5577 /* Test when both expressions are numeric */
5578 V_VT(&left) = VT_INT;
5579 V_VT(&right) = VT_INT;
5580 V_VT(&expected) = VT_BSTR;
5581 V_INT(&left) = 12;
5582 V_INT(&right) = 34;
5583 V_BSTR(&expected) = SysAllocString(sz1234);
5584 hres = pVarCat(&left,&right,&result);
5585 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5586 if (pVarCmp)
5587 ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ,
5588 "VarCat: NUMBER concat with NUMBER returned incorrect result\n");
5590 VariantClear(&left);
5591 VariantClear(&right);
5592 VariantClear(&result);
5594 /* Test if one expression is numeric and the other is a string */
5595 V_VT(&left) = VT_INT;
5596 V_VT(&right) = VT_BSTR;
5597 V_INT(&left) = 12;
5598 V_BSTR(&right) = SysAllocString(sz34);
5599 hres = pVarCat(&left,&right,&result);
5600 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5601 if (pVarCmp)
5602 ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ,
5603 "VarCat: NUMBER concat with VT_BSTR, incorrect result\n");
5605 VariantClear(&left);
5606 VariantClear(&right);
5607 VariantClear(&result);
5609 V_VT(&left) = VT_BSTR;
5610 V_VT(&right) = VT_INT;
5611 V_BSTR(&left) = SysAllocString(sz12);
5612 V_INT(&right) = 34;
5613 hres = pVarCat(&left,&right,&result);
5614 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5615 if (pVarCmp)
5616 ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ,
5617 "VarCat: VT_BSTR concat with NUMBER, incorrect result\n");
5619 VariantClear(&left);
5620 VariantClear(&right);
5621 VariantClear(&result);
5622 VariantClear(&expected);
5624 /* Test concat dates with strings */
5625 V_VT(&left) = VT_BSTR;
5626 V_VT(&right) = VT_DATE;
5627 V_VT(&expected) = VT_BSTR;
5628 V_VT(&expected_broken) = VT_BSTR;
5629 V_BSTR(&left) = SysAllocString(sz12);
5630 V_DATE(&right) = 29494.0;
5631 V_BSTR(&expected)= SysAllocString(sz12_date);
5632 V_BSTR(&expected_broken)= SysAllocString(sz12_date_broken);
5633 hres = pVarCat(&left,&right,&result);
5634 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5635 if (pVarCmp)
5636 ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ ||
5637 broken(pVarCmp(&result,&expected_broken,lcid,0) == VARCMP_EQ), /* Some W98 and NT4 (intermittent) */
5638 "VarCat: VT_BSTR concat with VT_DATE returned incorrect result\n");
5640 VariantClear(&left);
5641 VariantClear(&right);
5642 VariantClear(&result);
5643 VariantClear(&expected);
5644 VariantClear(&expected_broken);
5646 V_VT(&left) = VT_DATE;
5647 V_VT(&right) = VT_BSTR;
5648 V_VT(&expected) = VT_BSTR;
5649 V_VT(&expected_broken) = VT_BSTR;
5650 V_DATE(&left) = 29494.0;
5651 V_BSTR(&right) = SysAllocString(sz12);
5652 V_BSTR(&expected)= SysAllocString(date_sz12);
5653 V_BSTR(&expected_broken)= SysAllocString(date_sz12_broken);
5654 hres = pVarCat(&left,&right,&result);
5655 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5656 if (pVarCmp)
5657 ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ ||
5658 broken(pVarCmp(&result,&expected_broken,lcid,0) == VARCMP_EQ), /* Some W98 and NT4 (intermittent) */
5659 "VarCat: VT_DATE concat with VT_BSTR returned incorrect result\n");
5661 VariantClear(&left);
5662 VariantClear(&right);
5663 VariantClear(&result);
5664 VariantClear(&expected);
5665 VariantClear(&expected_broken);
5667 /* Test of both expressions are empty */
5668 V_VT(&left) = VT_BSTR;
5669 V_VT(&right) = VT_BSTR;
5670 V_VT(&expected) = VT_BSTR;
5671 V_BSTR(&left) = SysAllocString(sz_empty);
5672 V_BSTR(&right) = SysAllocString(sz_empty);
5673 V_BSTR(&expected)= SysAllocString(sz_empty);
5674 hres = pVarCat(&left,&right,&result);
5675 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5676 if (pVarCmp)
5677 ok(pVarCmp(&result,&left,lcid,0) == VARCMP_EQ,
5678 "VarCat: EMPTY concat with EMPTY did not return empty VT_BSTR\n");
5680 /* Restore original date format settings */
5681 SetLocaleInfo(lcid,LOCALE_SSHORTDATE,orig_date_format);
5683 VariantClear(&left);
5684 VariantClear(&right);
5685 VariantClear(&result);
5686 VariantClear(&expected);
5688 /* Test boolean conversion */
5689 V_VT(&left) = VT_BOOL;
5690 V_BOOL(&left) = VARIANT_TRUE;
5691 V_VT(&right) = VT_BSTR;
5692 V_BSTR(&right) = SysAllocStringLen(NULL,0);
5693 hres = pVarCat(&left, &right, &result);
5694 ok(hres == S_OK, "VarCat failed: %08x\n", hres);
5695 if(!strcmp_wa(V_BSTR(&result), "True")) {
5696 V_VT(&right) = VT_BOOL;
5697 V_BOOL(&right) = 100;
5698 hres = pVarCat(&left, &right, &result);
5699 ok(hres == S_OK, "VarCat failed: %08x\n", hres);
5700 test_bstr_var(&result, "TrueTrue");
5701 VariantClear(&result);
5703 V_BOOL(&right) = VARIANT_FALSE;
5704 hres = pVarCat(&left, &right, &result);
5705 ok(hres == S_OK, "VarCat failed: %08x\n", hres);
5706 test_bstr_var(&result, "TrueFalse");
5707 VariantClear(&result);
5708 }else {
5709 skip("Got %s as True, assuming non-English locale\n", wine_dbgstr_w(V_BSTR(&result)));
5713 static HRESULT (WINAPI *pVarAnd)(LPVARIANT,LPVARIANT,LPVARIANT);
5715 #define VARAND(vt1,val1,vt2,val2,rvt,rval) \
5716 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
5717 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
5718 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
5719 test_var_call2( __LINE__, pVarAnd, &left, &right, &exp )
5721 #define VARANDCY(vt1,val1,val2,rvt,rval) \
5722 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
5723 V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \
5724 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
5725 test_var_call2( __LINE__, pVarAnd, &left, &right, &exp )
5727 /* Skip any type that is not defined or produces an error for every case */
5728 #define SKIPTESTAND(a) \
5729 if (a == VT_ERROR || a == VT_VARIANT || \
5730 a == VT_DISPATCH || a == VT_UNKNOWN || \
5731 a > VT_UINT || a == 15 /*not defined*/) \
5732 continue
5734 static void test_VarAnd(void)
5736 static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
5737 static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
5738 VARIANT left, right, exp, result;
5739 BSTR false_str, true_str;
5740 VARTYPE i;
5741 HRESULT hres;
5743 true_str = SysAllocString(szTrue);
5744 false_str = SysAllocString(szFalse);
5746 CHECKPTR(VarAnd);
5748 /* Test all possible flag/vt combinations & the resulting vt type */
5749 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
5751 VARTYPE leftvt, rightvt, resvt;
5753 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
5755 SKIPTESTAND(leftvt);
5757 /* Check if we need/have support for I8 and/or UI8 */
5758 if ((leftvt == VT_I8 || leftvt == VT_UI8) && !HAVE_OLEAUT32_I8)
5759 continue;
5761 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
5763 BOOL bFail = FALSE;
5764 SKIPTESTAND(rightvt);
5766 /* Check if we need/have support for I8 and/or UI8 */
5767 if ((rightvt == VT_I8 || rightvt == VT_UI8) && !HAVE_OLEAUT32_I8)
5768 continue;
5770 memset(&left, 0, sizeof(left));
5771 memset(&right, 0, sizeof(right));
5772 V_VT(&left) = leftvt | ExtraFlags[i];
5773 V_VT(&right) = rightvt | ExtraFlags[i];
5774 V_VT(&result) = VT_EMPTY;
5775 resvt = VT_EMPTY;
5776 if ((leftvt | ExtraFlags[i]) == VT_BSTR)
5777 V_BSTR(&left) = true_str;
5778 if ((rightvt | ExtraFlags[i]) == VT_BSTR)
5779 V_BSTR(&right) = true_str;
5781 /* Native VarAnd always returns an error when using extra
5782 * flags or if the variant combination is I8 and INT.
5784 if ((leftvt == VT_I8 && rightvt == VT_INT) ||
5785 (leftvt == VT_INT && rightvt == VT_I8) ||
5786 ExtraFlags[i] != 0)
5787 bFail = TRUE;
5789 /* Determine return type */
5790 else if (leftvt == VT_I8 || rightvt == VT_I8)
5791 resvt = VT_I8;
5792 else if (leftvt == VT_I4 || rightvt == VT_I4 ||
5793 leftvt == VT_UINT || rightvt == VT_UINT ||
5794 leftvt == VT_INT || rightvt == VT_INT ||
5795 leftvt == VT_UINT || rightvt == VT_UINT ||
5796 leftvt == VT_R4 || rightvt == VT_R4 ||
5797 leftvt == VT_R8 || rightvt == VT_R8 ||
5798 leftvt == VT_CY || rightvt == VT_CY ||
5799 leftvt == VT_DATE || rightvt == VT_DATE ||
5800 leftvt == VT_I1 || rightvt == VT_I1 ||
5801 leftvt == VT_UI2 || rightvt == VT_UI2 ||
5802 leftvt == VT_UI4 || rightvt == VT_UI4 ||
5803 leftvt == VT_UI8 || rightvt == VT_UI8 ||
5804 leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
5805 resvt = VT_I4;
5806 else if (leftvt == VT_UI1 || rightvt == VT_UI1 ||
5807 leftvt == VT_I2 || rightvt == VT_I2 ||
5808 leftvt == VT_EMPTY || rightvt == VT_EMPTY)
5809 if ((leftvt == VT_NULL && rightvt == VT_UI1) ||
5810 (leftvt == VT_UI1 && rightvt == VT_NULL) ||
5811 (leftvt == VT_UI1 && rightvt == VT_UI1))
5812 resvt = VT_UI1;
5813 else
5814 resvt = VT_I2;
5815 else if (leftvt == VT_BOOL || rightvt == VT_BOOL ||
5816 (leftvt == VT_BSTR && rightvt == VT_BSTR))
5817 resvt = VT_BOOL;
5818 else if (leftvt == VT_NULL || rightvt == VT_NULL ||
5819 leftvt == VT_BSTR || rightvt == VT_BSTR)
5820 resvt = VT_NULL;
5821 else
5822 bFail = TRUE;
5824 hres = pVarAnd(&left, &right, &result);
5826 /* Check expected HRESULT and if result variant type is correct */
5827 if (bFail)
5828 ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH,
5829 "VarAnd: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
5830 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
5831 vtstr(V_VT(&result)), hres);
5832 else
5833 ok (hres == S_OK && resvt == V_VT(&result),
5834 "VarAnd: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
5835 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
5836 S_OK, vtstr(V_VT(&result)), hres);
5842 * Test returned values. Since we know the returned type is correct
5843 * and that we handle all combinations of invalid types, just check
5844 * that good type combinations produce the desired value.
5845 * FIXME: Test VT_DECIMAL
5847 VARAND(EMPTY,0,EMPTY,0,I2,0);
5848 VARAND(EMPTY,1,EMPTY,0,I2,0);
5849 VARAND(EMPTY,1,EMPTY,1,I2,0);
5850 VARAND(EMPTY,0,NULL,0,I2,0);
5851 VARAND(EMPTY,1,NULL,0,I2,0);
5852 VARAND(EMPTY,1,NULL,1,I2,0);
5853 VARAND(EMPTY,0,I1,0,I4,0);
5854 VARAND(EMPTY,0,I1,1,I4,0);
5855 VARAND(EMPTY,1,I1,1,I4,0);
5856 VARAND(EMPTY,0,UI1,0,I2,0);
5857 VARAND(EMPTY,0,UI1,1,I2,0);
5858 VARAND(EMPTY,1,UI1,1,I2,0);
5859 VARAND(EMPTY,0,I2,0,I2,0);
5860 VARAND(EMPTY,0,I2,1,I2,0);
5861 VARAND(EMPTY,1,I2,1,I2,0);
5862 VARAND(EMPTY,0,UI2,0,I4,0);
5863 VARAND(EMPTY,0,UI2,1,I4,0);
5864 VARAND(EMPTY,1,UI2,1,I4,0);
5865 VARAND(EMPTY,0,I4,0,I4,0);
5866 VARAND(EMPTY,0,I4,1,I4,0);
5867 VARAND(EMPTY,1,I4,1,I4,0);
5868 VARAND(EMPTY,0,UI4,0,I4,0);
5869 VARAND(EMPTY,0,UI4,1,I4,0);
5870 VARAND(EMPTY,1,UI4,1,I4,0);
5871 if (HAVE_OLEAUT32_I8)
5873 VARAND(EMPTY,0,I8,0,I8,0);
5874 VARAND(EMPTY,0,I8,1,I8,0);
5875 VARAND(EMPTY,1,I8,1,I8,0);
5876 VARAND(EMPTY,0,UI8,0,I4,0);
5877 VARAND(EMPTY,0,UI8,1,I4,0);
5878 VARAND(EMPTY,1,UI8,1,I4,0);
5880 VARAND(EMPTY,0,INT,0,I4,0);
5881 VARAND(EMPTY,0,INT,1,I4,0);
5882 VARAND(EMPTY,1,INT,1,I4,0);
5883 VARAND(EMPTY,0,UINT,0,I4,0);
5884 VARAND(EMPTY,0,UINT,1,I4,0);
5885 VARAND(EMPTY,1,UINT,1,I4,0);
5886 VARAND(EMPTY,0,BOOL,0,I2,0);
5887 VARAND(EMPTY,0,BOOL,1,I2,0);
5888 VARAND(EMPTY,1,BOOL,1,I2,0);
5889 VARAND(EMPTY,0,R4,0,I4,0);
5890 VARAND(EMPTY,0,R4,1,I4,0);
5891 VARAND(EMPTY,1,R4,1,I4,0);
5892 VARAND(EMPTY,0,R8,0,I4,0);
5893 VARAND(EMPTY,0,R8,1,I4,0);
5894 VARAND(EMPTY,1,R8,1,I4,0);
5895 VARAND(EMPTY,0,BSTR,false_str,I2,0);
5896 VARAND(EMPTY,0,BSTR,true_str,I2,0);
5897 VARANDCY(EMPTY,0,10000,I4,0);
5899 /* NULL OR 0 = NULL. NULL OR n = n */
5900 VARAND(NULL,0,NULL,0,NULL,0);
5901 VARAND(NULL,1,NULL,0,NULL,0);
5902 VARAND(NULL,0,I1,0,I4,0);
5903 VARAND(NULL,0,I1,1,NULL,0);
5904 VARAND(NULL,0,UI1,0,UI1,0);
5905 VARAND(NULL,0,UI1,1,NULL,0);
5906 VARAND(NULL,0,I2,0,I2,0);
5907 VARAND(NULL,0,I2,1,NULL,0);
5908 VARAND(NULL,0,UI2,0,I4,0);
5909 VARAND(NULL,0,UI2,1,NULL,0);
5910 VARAND(NULL,0,I4,0,I4,0);
5911 VARAND(NULL,0,I4,1,NULL,0);
5912 VARAND(NULL,0,UI4,0,I4,0);
5913 VARAND(NULL,0,UI4,1,NULL,0);
5914 if (HAVE_OLEAUT32_I8)
5916 VARAND(NULL,0,I8,0,I8,0);
5917 VARAND(NULL,0,I8,1,NULL,0);
5918 VARAND(NULL,0,UI8,0,I4,0);
5919 VARAND(NULL,0,UI8,1,NULL,0);
5921 VARAND(NULL,0,INT,0,I4,0);
5922 VARAND(NULL,0,INT,1,NULL,0);
5923 VARAND(NULL,0,UINT,0,I4,0);
5924 VARAND(NULL,0,UINT,1,NULL,0);
5925 VARAND(NULL,0,BOOL,0,BOOL,0);
5926 VARAND(NULL,0,BOOL,1,NULL,0);
5927 VARAND(NULL,0,R4,0,I4,0);
5928 VARAND(NULL,0,R4,1,NULL,0);
5929 VARAND(NULL,0,R8,0,I4,0);
5930 VARAND(NULL,0,R8,1,NULL,0);
5931 VARAND(NULL,0,BSTR,false_str,BOOL,0);
5932 VARAND(NULL,0,BSTR,true_str,NULL,VARIANT_FALSE);
5933 VARANDCY(NULL,0,10000,NULL,0);
5934 VARANDCY(NULL,0,0,I4,0);
5935 VARAND(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
5936 VARAND(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
5937 VARAND(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
5938 VARAND(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
5940 /* Assume x,y & y,x are the same from now on to reduce the number of tests */
5941 VARAND(BOOL,VARIANT_TRUE,I1,-1,I4,-1);
5942 VARAND(BOOL,VARIANT_TRUE,I1,0,I4,0);
5943 VARAND(BOOL,VARIANT_FALSE,I1,0,I4,0);
5944 VARAND(BOOL,VARIANT_TRUE,UI1,255,I2,255);
5945 VARAND(BOOL,VARIANT_TRUE,UI1,0,I2,0);
5946 VARAND(BOOL,VARIANT_FALSE,UI1,0,I2,0);
5947 VARAND(BOOL,VARIANT_TRUE,I2,-1,I2,-1);
5948 VARAND(BOOL,VARIANT_TRUE,I2,0,I2,0);
5949 VARAND(BOOL,VARIANT_FALSE,I2,0,I2,0);
5950 VARAND(BOOL,VARIANT_TRUE,UI2,65535,I4,65535);
5951 VARAND(BOOL,VARIANT_TRUE,UI2,0,I4,0);
5952 VARAND(BOOL,VARIANT_FALSE,UI2,0,I4,0);
5953 VARAND(BOOL,VARIANT_TRUE,I4,-1,I4,-1);
5954 VARAND(BOOL,VARIANT_TRUE,I4,0,I4,0);
5955 VARAND(BOOL,VARIANT_FALSE,I4,0,I4,0);
5956 VARAND(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,-1);
5957 VARAND(BOOL,VARIANT_TRUE,UI4,0,I4,0);
5958 VARAND(BOOL,VARIANT_FALSE,UI4,0,I4,0);
5959 VARAND(BOOL,VARIANT_TRUE,R4,-1,I4,-1);
5960 VARAND(BOOL,VARIANT_TRUE,R4,0,I4,0);
5961 VARAND(BOOL,VARIANT_FALSE,R4,0,I4,0);
5962 VARAND(BOOL,VARIANT_TRUE,R8,-1,I4,-1);
5963 VARAND(BOOL,VARIANT_TRUE,R8,0,I4,0);
5964 VARAND(BOOL,VARIANT_FALSE,R8,0,I4,0);
5965 VARAND(BOOL,VARIANT_TRUE,DATE,-1,I4,-1);
5966 VARAND(BOOL,VARIANT_TRUE,DATE,0,I4,0);
5967 VARAND(BOOL,VARIANT_FALSE,DATE,0,I4,0);
5968 if (HAVE_OLEAUT32_I8)
5970 VARAND(BOOL,VARIANT_TRUE,I8,-1,I8,-1);
5971 VARAND(BOOL,VARIANT_TRUE,I8,0,I8,0);
5972 VARAND(BOOL,VARIANT_FALSE,I8,0,I8,0);
5973 VARAND(BOOL,VARIANT_TRUE,UI8,0,I4,0);
5974 VARAND(BOOL,VARIANT_FALSE,UI8,0,I4,0);
5976 VARAND(BOOL,VARIANT_TRUE,INT,-1,I4,-1);
5977 VARAND(BOOL,VARIANT_TRUE,INT,0,I4,0);
5978 VARAND(BOOL,VARIANT_FALSE,INT,0,I4,0);
5979 VARAND(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,-1);
5980 VARAND(BOOL,VARIANT_TRUE,UINT,0,I4,0);
5981 VARAND(BOOL,VARIANT_FALSE,UINT,0,I4,0);
5982 VARAND(BOOL,VARIANT_FALSE,BSTR,false_str,BOOL,VARIANT_FALSE);
5983 VARAND(BOOL,VARIANT_TRUE,BSTR,false_str,BOOL,VARIANT_FALSE);
5984 VARAND(BOOL,VARIANT_FALSE,BSTR,true_str,BOOL,VARIANT_FALSE);
5985 VARAND(BOOL,VARIANT_TRUE,BSTR,true_str,BOOL,VARIANT_TRUE);
5986 VARANDCY(BOOL,VARIANT_TRUE,10000,I4,1);
5987 VARANDCY(BOOL,VARIANT_TRUE,0,I4,0);
5988 VARANDCY(BOOL,VARIANT_FALSE,0,I4,0);
5989 VARAND(I1,-1,I1,-1,I4,-1);
5990 VARAND(I1,-1,I1,0,I4,0);
5991 VARAND(I1,0,I1,0,I4,0);
5992 VARAND(I1,-1,UI1,255,I4,255);
5993 VARAND(I1,-1,UI1,0,I4,0);
5994 VARAND(I1,0,UI1,0,I4,0);
5995 VARAND(I1,-1,I2,-1,I4,-1);
5996 VARAND(I1,-1,I2,0,I4,0);
5997 VARAND(I1,0,I2,0,I4,0);
5998 VARAND(I1,-1,UI2,65535,I4,65535);
5999 VARAND(I1,-1,UI2,0,I4,0);
6000 VARAND(I1,0,UI2,0,I4,0);
6001 VARAND(I1,-1,I4,-1,I4,-1);
6002 VARAND(I1,-1,I4,0,I4,0);
6003 VARAND(I1,0,I4,0,I4,0);
6004 VARAND(I1,-1,UI4,0xffffffff,I4,-1);
6005 VARAND(I1,-1,UI4,0,I4,0);
6006 VARAND(I1,0,UI4,0,I4,0);
6007 VARAND(I1,-1,R4,-1,I4,-1);
6008 VARAND(I1,-1,R4,0,I4,0);
6009 VARAND(I1,0,R4,0,I4,0);
6010 VARAND(I1,-1,R8,-1,I4,-1);
6011 VARAND(I1,-1,R8,0,I4,0);
6012 VARAND(I1,0,R8,0,I4,0);
6013 VARAND(I1,-1,DATE,-1,I4,-1);
6014 VARAND(I1,-1,DATE,0,I4,0);
6015 VARAND(I1,0,DATE,0,I4,0);
6016 if (HAVE_OLEAUT32_I8)
6018 VARAND(I1,-1,I8,-1,I8,-1);
6019 VARAND(I1,-1,I8,0,I8,0);
6020 VARAND(I1,0,I8,0,I8,0);
6021 VARAND(I1,-1,UI8,0,I4,0);
6022 VARAND(I1,0,UI8,0,I4,0);
6024 VARAND(I1,-1,INT,-1,I4,-1);
6025 VARAND(I1,-1,INT,0,I4,0);
6026 VARAND(I1,0,INT,0,I4,0);
6027 VARAND(I1,-1,UINT,0xffffffff,I4,-1);
6028 VARAND(I1,-1,UINT,0,I4,0);
6029 VARAND(I1,0,UINT,0,I4,0);
6030 VARAND(I1,0,BSTR,false_str,I4,0);
6031 VARAND(I1,-1,BSTR,false_str,I4,0);
6032 VARAND(I1,0,BSTR,true_str,I4,0);
6033 VARAND(I1,-1,BSTR,true_str,I4,-1);
6034 VARANDCY(I1,-1,10000,I4,1);
6035 VARANDCY(I1,-1,0,I4,0);
6036 VARANDCY(I1,0,0,I4,0);
6038 VARAND(UI1,255,UI1,255,UI1,255);
6039 VARAND(UI1,255,UI1,0,UI1,0);
6040 VARAND(UI1,0,UI1,0,UI1,0);
6041 VARAND(UI1,255,I2,-1,I2,255);
6042 VARAND(UI1,255,I2,0,I2,0);
6043 VARAND(UI1,0,I2,0,I2,0);
6044 VARAND(UI1,255,UI2,65535,I4,255);
6045 VARAND(UI1,255,UI2,0,I4,0);
6046 VARAND(UI1,0,UI2,0,I4,0);
6047 VARAND(UI1,255,I4,-1,I4,255);
6048 VARAND(UI1,255,I4,0,I4,0);
6049 VARAND(UI1,0,I4,0,I4,0);
6050 VARAND(UI1,255,UI4,0xffffffff,I4,255);
6051 VARAND(UI1,255,UI4,0,I4,0);
6052 VARAND(UI1,0,UI4,0,I4,0);
6053 VARAND(UI1,255,R4,-1,I4,255);
6054 VARAND(UI1,255,R4,0,I4,0);
6055 VARAND(UI1,0,R4,0,I4,0);
6056 VARAND(UI1,255,R8,-1,I4,255);
6057 VARAND(UI1,255,R8,0,I4,0);
6058 VARAND(UI1,0,R8,0,I4,0);
6059 VARAND(UI1,255,DATE,-1,I4,255);
6060 VARAND(UI1,255,DATE,0,I4,0);
6061 VARAND(UI1,0,DATE,0,I4,0);
6062 if (HAVE_OLEAUT32_I8)
6064 VARAND(UI1,255,I8,-1,I8,255);
6065 VARAND(UI1,255,I8,0,I8,0);
6066 VARAND(UI1,0,I8,0,I8,0);
6067 VARAND(UI1,255,UI8,0,I4,0);
6068 VARAND(UI1,0,UI8,0,I4,0);
6070 VARAND(UI1,255,INT,-1,I4,255);
6071 VARAND(UI1,255,INT,0,I4,0);
6072 VARAND(UI1,0,INT,0,I4,0);
6073 VARAND(UI1,255,UINT,0xffffffff,I4,255);
6074 VARAND(UI1,255,UINT,0,I4,0);
6075 VARAND(UI1,0,UINT,0,I4,0);
6076 VARAND(UI1,0,BSTR,false_str,I2,0);
6077 VARAND(UI1,255,BSTR,false_str,I2,0);
6078 VARAND(UI1,0,BSTR,true_str,I2,0);
6079 VARAND(UI1,255,BSTR,true_str,I2,255);
6080 VARANDCY(UI1,255,10000,I4,1);
6081 VARANDCY(UI1,255,0,I4,0);
6082 VARANDCY(UI1,0,0,I4,0);
6084 VARAND(I2,-1,I2,-1,I2,-1);
6085 VARAND(I2,-1,I2,0,I2,0);
6086 VARAND(I2,0,I2,0,I2,0);
6087 VARAND(I2,-1,UI2,65535,I4,65535);
6088 VARAND(I2,-1,UI2,0,I4,0);
6089 VARAND(I2,0,UI2,0,I4,0);
6090 VARAND(I2,-1,I4,-1,I4,-1);
6091 VARAND(I2,-1,I4,0,I4,0);
6092 VARAND(I2,0,I4,0,I4,0);
6093 VARAND(I2,-1,UI4,0xffffffff,I4,-1);
6094 VARAND(I2,-1,UI4,0,I4,0);
6095 VARAND(I2,0,UI4,0,I4,0);
6096 VARAND(I2,-1,R4,-1,I4,-1);
6097 VARAND(I2,-1,R4,0,I4,0);
6098 VARAND(I2,0,R4,0,I4,0);
6099 VARAND(I2,-1,R8,-1,I4,-1);
6100 VARAND(I2,-1,R8,0,I4,0);
6101 VARAND(I2,0,R8,0,I4,0);
6102 VARAND(I2,-1,DATE,-1,I4,-1);
6103 VARAND(I2,-1,DATE,0,I4,0);
6104 VARAND(I2,0,DATE,0,I4,0);
6105 if (HAVE_OLEAUT32_I8)
6107 VARAND(I2,-1,I8,-1,I8,-1);
6108 VARAND(I2,-1,I8,0,I8,0);
6109 VARAND(I2,0,I8,0,I8,0);
6110 VARAND(I2,-1,UI8,0,I4,0);
6111 VARAND(I2,0,UI8,0,I4,0);
6113 VARAND(I2,-1,INT,-1,I4,-1);
6114 VARAND(I2,-1,INT,0,I4,0);
6115 VARAND(I2,0,INT,0,I4,0);
6116 VARAND(I2,-1,UINT,0xffffffff,I4,-1);
6117 VARAND(I2,-1,UINT,0,I4,0);
6118 VARAND(I2,0,UINT,0,I4,0);
6119 VARAND(I2,0,BSTR,false_str,I2,0);
6120 VARAND(I2,-1,BSTR,false_str,I2,0);
6121 VARAND(I2,0,BSTR,true_str,I2,0);
6122 VARAND(I2,-1,BSTR,true_str,I2,-1);
6123 VARANDCY(I2,-1,10000,I4,1);
6124 VARANDCY(I2,-1,0,I4,0);
6125 VARANDCY(I2,0,0,I4,0);
6127 VARAND(UI2,65535,UI2,65535,I4,65535);
6128 VARAND(UI2,65535,UI2,0,I4,0);
6129 VARAND(UI2,0,UI2,0,I4,0);
6130 VARAND(UI2,65535,I4,-1,I4,65535);
6131 VARAND(UI2,65535,I4,0,I4,0);
6132 VARAND(UI2,0,I4,0,I4,0);
6133 VARAND(UI2,65535,UI4,0xffffffff,I4,65535);
6134 VARAND(UI2,65535,UI4,0,I4,0);
6135 VARAND(UI2,0,UI4,0,I4,0);
6136 VARAND(UI2,65535,R4,-1,I4,65535);
6137 VARAND(UI2,65535,R4,0,I4,0);
6138 VARAND(UI2,0,R4,0,I4,0);
6139 VARAND(UI2,65535,R8,-1,I4,65535);
6140 VARAND(UI2,65535,R8,0,I4,0);
6141 VARAND(UI2,0,R8,0,I4,0);
6142 VARAND(UI2,65535,DATE,-1,I4,65535);
6143 VARAND(UI2,65535,DATE,0,I4,0);
6144 VARAND(UI2,0,DATE,0,I4,0);
6145 if (HAVE_OLEAUT32_I8)
6147 VARAND(UI2,65535,I8,-1,I8,65535);
6148 VARAND(UI2,65535,I8,0,I8,0);
6149 VARAND(UI2,0,I8,0,I8,0);
6150 VARAND(UI2,65535,UI8,0,I4,0);
6151 VARAND(UI2,0,UI8,0,I4,0);
6153 VARAND(UI2,65535,INT,-1,I4,65535);
6154 VARAND(UI2,65535,INT,0,I4,0);
6155 VARAND(UI2,0,INT,0,I4,0);
6156 VARAND(UI2,65535,UINT,0xffffffff,I4,65535);
6157 VARAND(UI2,65535,UINT,0,I4,0);
6158 VARAND(UI2,0,UINT,0,I4,0);
6159 VARAND(UI2,0,BSTR,false_str,I4,0);
6160 VARAND(UI2,65535,BSTR,false_str,I4,0);
6161 VARAND(UI2,0,BSTR,true_str,I4,0);
6162 VARAND(UI2,65535,BSTR,true_str,I4,65535);
6163 VARANDCY(UI2,65535,10000,I4,1);
6164 VARANDCY(UI2,65535,0,I4,0);
6165 VARANDCY(UI2,0,0,I4,0);
6167 VARAND(I4,-1,I4,-1,I4,-1);
6168 VARAND(I4,-1,I4,0,I4,0);
6169 VARAND(I4,0,I4,0,I4,0);
6170 VARAND(I4,-1,UI4,0xffffffff,I4,-1);
6171 VARAND(I4,-1,UI4,0,I4,0);
6172 VARAND(I4,0,UI4,0,I4,0);
6173 VARAND(I4,-1,R4,-1,I4,-1);
6174 VARAND(I4,-1,R4,0,I4,0);
6175 VARAND(I4,0,R4,0,I4,0);
6176 VARAND(I4,-1,R8,-1,I4,-1);
6177 VARAND(I4,-1,R8,0,I4,0);
6178 VARAND(I4,0,R8,0,I4,0);
6179 VARAND(I4,-1,DATE,-1,I4,-1);
6180 VARAND(I4,-1,DATE,0,I4,0);
6181 VARAND(I4,0,DATE,0,I4,0);
6182 if (HAVE_OLEAUT32_I8)
6184 VARAND(I4,-1,I8,-1,I8,-1);
6185 VARAND(I4,-1,I8,0,I8,0);
6186 VARAND(I4,0,I8,0,I8,0);
6187 VARAND(I4,-1,UI8,0,I4,0);
6188 VARAND(I4,0,UI8,0,I4,0);
6190 VARAND(I4,-1,INT,-1,I4,-1);
6191 VARAND(I4,-1,INT,0,I4,0);
6192 VARAND(I4,0,INT,0,I4,0);
6193 VARAND(I4,-1,UINT,0xffffffff,I4,-1);
6194 VARAND(I4,-1,UINT,0,I4,0);
6195 VARAND(I4,0,UINT,0,I4,0);
6196 VARAND(I4,0,BSTR,false_str,I4,0);
6197 VARAND(I4,-1,BSTR,false_str,I4,0);
6198 VARAND(I4,0,BSTR,true_str,I4,0);
6199 VARAND(I4,-1,BSTR,true_str,I4,-1);
6200 VARANDCY(I4,-1,10000,I4,1);
6201 VARANDCY(I4,-1,0,I4,0);
6202 VARANDCY(I4,0,0,I4,0);
6204 VARAND(UI4,0xffffffff,UI4,0xffffffff,I4,-1);
6205 VARAND(UI4,0xffffffff,UI4,0,I4,0);
6206 VARAND(UI4,0,UI4,0,I4,0);
6207 VARAND(UI4,0xffffffff,R4,-1,I4,-1);
6208 VARAND(UI4,0xffffffff,R4,0,I4,0);
6209 VARAND(UI4,0,R4,0,I4,0);
6210 VARAND(UI4,0xffffffff,R8,-1,I4,-1);
6211 VARAND(UI4,0xffffffff,R8,0,I4,0);
6212 VARAND(UI4,0,R8,0,I4,0);
6213 VARAND(UI4,0xffffffff,DATE,-1,I4,-1);
6214 VARAND(UI4,0xffffffff,DATE,0,I4,0);
6215 VARAND(UI4,0,DATE,0,I4,0);
6216 if (HAVE_OLEAUT32_I8)
6218 VARAND(UI4,0xffffffff,I8,0,I8,0);
6219 VARAND(UI4,0,I8,0,I8,0);
6220 VARAND(UI4,0xffffffff,UI8,0,I4,0);
6221 VARAND(UI4,0,UI8,0,I4,0);
6223 VARAND(UI4,0xffffffff,INT,-1,I4,-1);
6224 VARAND(UI4,0xffffffff,INT,0,I4,0);
6225 VARAND(UI4,0,INT,0,I4,0);
6226 VARAND(UI4,0xffffffff,UINT,0xffffffff,I4,-1);
6227 VARAND(UI4,0xffffffff,UINT,0,I4,0);
6228 VARAND(UI4,0,UINT,0,I4,0);
6229 VARAND(UI4,0,BSTR,false_str,I4,0);
6230 VARAND(UI4,0xffffffff,BSTR,false_str,I4,0);
6231 VARAND(UI4,0,BSTR,true_str,I4,0);
6232 VARAND(UI4,0xffffffff,BSTR,true_str,I4,-1);
6233 VARANDCY(UI4,0xffffffff,10000,I4,1);
6234 VARANDCY(UI4,0xffffffff,0,I4,0);
6235 VARANDCY(UI4,0,0,I4,0);
6237 VARAND(R4,-1,R4,-1,I4,-1);
6238 VARAND(R4,-1,R4,0,I4,0);
6239 VARAND(R4,0,R4,0,I4,0);
6240 VARAND(R4,-1,R8,-1,I4,-1);
6241 VARAND(R4,-1,R8,0,I4,0);
6242 VARAND(R4,0,R8,0,I4,0);
6243 VARAND(R4,-1,DATE,-1,I4,-1);
6244 VARAND(R4,-1,DATE,0,I4,0);
6245 VARAND(R4,0,DATE,0,I4,0);
6246 if (HAVE_OLEAUT32_I8)
6248 VARAND(R4,-1,I8,-1,I8,-1);
6249 VARAND(R4,-1,I8,0,I8,0);
6250 VARAND(R4,0,I8,0,I8,0);
6251 VARAND(R4,-1,UI8,0,I4,0);
6252 VARAND(R4,0,UI8,0,I4,0);
6254 VARAND(R4,-1,INT,-1,I4,-1);
6255 VARAND(R4,-1,INT,0,I4,0);
6256 VARAND(R4,0,INT,0,I4,0);
6257 VARAND(R4,-1,UINT,0xffffffff,I4,-1);
6258 VARAND(R4,-1,UINT,0,I4,0);
6259 VARAND(R4,0,UINT,0,I4,0);
6260 VARAND(R4,0,BSTR,false_str,I4,0);
6261 VARAND(R4,-1,BSTR,false_str,I4,0);
6262 VARAND(R4,0,BSTR,true_str,I4,0);
6263 VARAND(R4,-1,BSTR,true_str,I4,-1);
6264 VARANDCY(R4,-1,10000,I4,1);
6265 VARANDCY(R4,-1,0,I4,0);
6266 VARANDCY(R4,0,0,I4,0);
6268 VARAND(R8,-1,R8,-1,I4,-1);
6269 VARAND(R8,-1,R8,0,I4,0);
6270 VARAND(R8,0,R8,0,I4,0);
6271 VARAND(R8,-1,DATE,-1,I4,-1);
6272 VARAND(R8,-1,DATE,0,I4,0);
6273 VARAND(R8,0,DATE,0,I4,0);
6274 if (HAVE_OLEAUT32_I8)
6276 VARAND(R8,-1,I8,-1,I8,-1);
6277 VARAND(R8,-1,I8,0,I8,0);
6278 VARAND(R8,0,I8,0,I8,0);
6279 VARAND(R8,-1,UI8,0,I4,0);
6280 VARAND(R8,0,UI8,0,I4,0);
6282 VARAND(R8,-1,INT,-1,I4,-1);
6283 VARAND(R8,-1,INT,0,I4,0);
6284 VARAND(R8,0,INT,0,I4,0);
6285 VARAND(R8,-1,UINT,0xffffffff,I4,-1);
6286 VARAND(R8,-1,UINT,0,I4,0);
6287 VARAND(R8,0,UINT,0,I4,0);
6288 VARAND(R8,0,BSTR,false_str,I4,0);
6289 VARAND(R8,-1,BSTR,false_str,I4,0);
6290 VARAND(R8,0,BSTR,true_str,I4,0);
6291 VARAND(R8,-1,BSTR,true_str,I4,-1);
6292 VARANDCY(R8,-1,10000,I4,1);
6293 VARANDCY(R8,-1,0,I4,0);
6294 VARANDCY(R8,0,0,I4,0);
6296 VARAND(DATE,-1,DATE,-1,I4,-1);
6297 VARAND(DATE,-1,DATE,0,I4,0);
6298 VARAND(DATE,0,DATE,0,I4,0);
6299 if (HAVE_OLEAUT32_I8)
6301 VARAND(DATE,-1,I8,-1,I8,-1);
6302 VARAND(DATE,-1,I8,0,I8,0);
6303 VARAND(DATE,0,I8,0,I8,0);
6304 VARAND(DATE,-1,UI8,0,I4,0);
6305 VARAND(DATE,0,UI8,0,I4,0);
6307 VARAND(DATE,-1,INT,-1,I4,-1);
6308 VARAND(DATE,-1,INT,0,I4,0);
6309 VARAND(DATE,0,INT,0,I4,0);
6310 VARAND(DATE,-1,UINT,0xffffffff,I4,-1);
6311 VARAND(DATE,-1,UINT,0,I4,0);
6312 VARAND(DATE,0,UINT,0,I4,0);
6313 VARAND(DATE,0,BSTR,false_str,I4,0);
6314 VARAND(DATE,-1,BSTR,false_str,I4,0);
6315 VARAND(DATE,0,BSTR,true_str,I4,0);
6316 VARAND(DATE,-1,BSTR,true_str,I4,-1);
6317 VARANDCY(DATE,-1,10000,I4,1);
6318 VARANDCY(DATE,-1,0,I4,0);
6319 VARANDCY(DATE,0,0,I4,0);
6321 if (HAVE_OLEAUT32_I8)
6323 VARAND(I8,-1,I8,-1,I8,-1);
6324 VARAND(I8,-1,I8,0,I8,0);
6325 VARAND(I8,0,I8,0,I8,0);
6326 VARAND(I8,-1,UI8,0,I8,0);
6327 VARAND(I8,0,UI8,0,I8,0);
6328 VARAND(I8,-1,UINT,0,I8,0);
6329 VARAND(I8,0,UINT,0,I8,0);
6330 VARAND(I8,0,BSTR,false_str,I8,0);
6331 VARAND(I8,-1,BSTR,false_str,I8,0);
6332 VARAND(I8,0,BSTR,true_str,I8,0);
6333 VARAND(I8,-1,BSTR,true_str,I8,-1);
6334 VARANDCY(I8,-1,10000,I8,1);
6335 VARANDCY(I8,-1,0,I8,0);
6336 VARANDCY(I8,0,0,I8,0);
6338 VARAND(UI8,0xffff,UI8,0xffff,I4,0xffff);
6339 VARAND(UI8,0xffff,UI8,0,I4,0);
6340 VARAND(UI8,0,UI8,0,I4,0);
6341 VARAND(UI8,0xffff,INT,-1,I4,65535);
6342 VARAND(UI8,0xffff,INT,0,I4,0);
6343 VARAND(UI8,0,INT,0,I4,0);
6344 VARAND(UI8,0xffff,UINT,0xffff,I4,0xffff);
6345 VARAND(UI8,0xffff,UINT,0,I4,0);
6346 VARAND(UI8,0,UINT,0,I4,0);
6347 VARAND(UI8,0,BSTR,false_str,I4,0);
6348 VARAND(UI8,0xffff,BSTR,false_str,I4,0);
6349 VARAND(UI8,0,BSTR,true_str,I4,0);
6350 VARAND(UI8,0xffff,BSTR,true_str,I4,65535);
6351 VARANDCY(UI8,0xffff,10000,I4,1);
6352 VARANDCY(UI8,0xffff,0,I4,0);
6353 VARANDCY(UI8,0,0,I4,0);
6356 VARAND(INT,-1,INT,-1,I4,-1);
6357 VARAND(INT,-1,INT,0,I4,0);
6358 VARAND(INT,0,INT,0,I4,0);
6359 VARAND(INT,-1,UINT,0xffff,I4,65535);
6360 VARAND(INT,-1,UINT,0,I4,0);
6361 VARAND(INT,0,UINT,0,I4,0);
6362 VARAND(INT,0,BSTR,false_str,I4,0);
6363 VARAND(INT,-1,BSTR,false_str,I4,0);
6364 VARAND(INT,0,BSTR,true_str,I4,0);
6365 VARAND(INT,-1,BSTR,true_str,I4,-1);
6366 VARANDCY(INT,-1,10000,I4,1);
6367 VARANDCY(INT,-1,0,I4,0);
6368 VARANDCY(INT,0,0,I4,0);
6370 VARAND(UINT,0xffff,UINT,0xffff,I4,0xffff);
6371 VARAND(UINT,0xffff,UINT,0,I4,0);
6372 VARAND(UINT,0,UINT,0,I4,0);
6373 VARAND(UINT,0,BSTR,false_str,I4,0);
6374 VARAND(UINT,0xffff,BSTR, false_str,I4,0);
6375 VARAND(UINT,0,BSTR,true_str,I4,0);
6376 VARAND(UINT,0xffff,BSTR,true_str,I4,65535);
6377 VARANDCY(UINT,0xffff,10000,I4,1);
6378 VARANDCY(UINT,0xffff,0,I4,0);
6379 VARANDCY(UINT,0,0,I4,0);
6381 VARAND(BSTR,false_str,BSTR,false_str,BOOL,0);
6382 VARAND(BSTR,true_str,BSTR,false_str,BOOL,VARIANT_FALSE);
6383 VARAND(BSTR,true_str,BSTR,true_str,BOOL,VARIANT_TRUE);
6384 VARANDCY(BSTR,true_str,10000,I4,1);
6385 VARANDCY(BSTR,false_str,10000,I4,0);
6387 SysFreeString(true_str);
6388 SysFreeString(false_str);
6391 static void test_cmp( int line, LCID lcid, UINT flags, VARIANT *left, VARIANT *right, HRESULT result )
6393 HRESULT hres;
6395 CHECKPTR(VarCmp);
6397 hres = pVarCmp(left,right,lcid,flags);
6398 ok_(__FILE__,line)(hres == result, "VarCmp(%s,%s): expected 0x%x, got hres=0x%x\n",
6399 variantstr(left), variantstr(right), result, hres );
6401 static void test_cmpex( int line, LCID lcid, VARIANT *left, VARIANT *right,
6402 HRESULT res1, HRESULT res2, HRESULT res3, HRESULT res4 )
6404 test_cmp( line, lcid, 0, left, right, res1 );
6405 V_VT(left) |= VT_RESERVED;
6406 test_cmp( line, lcid, 0, left, right, res2 );
6407 V_VT(left) &= ~VT_RESERVED;
6408 V_VT(right) |= VT_RESERVED;
6409 test_cmp( line, lcid, 0, left, right, res3 );
6410 V_VT(left) |= VT_RESERVED;
6411 test_cmp( line, lcid, 0, left, right, res4 );
6412 ok_(__FILE__,line)(V_VT(left) & V_VT(right) & VT_RESERVED, "VT_RESERVED filtered out\n");
6415 /* ERROR from wingdi.h is interfering here */
6416 #undef ERROR
6417 #define _VARCMP(vt1,val1,vtfl1,vt2,val2,vtfl2,lcid,flags,result) \
6418 V_##vt1(&left) = val1; V_VT(&left) = VT_##vt1 | vtfl1; \
6419 V_##vt2(&right) = val2; V_VT(&right) = VT_##vt2 | vtfl2; \
6420 test_cmp( __LINE__, lcid, flags, &left, &right, result )
6421 #define VARCMPEX(vt1,val1,vt2,val2,res1,res2,res3,res4) \
6422 V_##vt1(&left) = val1; V_VT(&left) = VT_##vt1; \
6423 V_##vt2(&right) = val2; V_VT(&right) = VT_##vt2; \
6424 test_cmpex( __LINE__, lcid, &left, &right, res1, res2, res3, res4 )
6425 #define VARCMP(vt1,val1,vt2,val2,result) \
6426 VARCMPEX(vt1,val1,vt2,val2,result,result,result,result)
6427 /* The above macros do not work for VT_NULL as NULL gets expanded first */
6428 #define V_NULL_ V_NULL
6429 #define VT_NULL_ VT_NULL
6431 static void test_VarCmp(void)
6433 VARIANT left, right;
6434 VARTYPE i;
6435 LCID lcid;
6436 HRESULT hres;
6437 DECIMAL dec;
6438 static const WCHAR szhuh[] = {'h','u','h','?','\0'};
6439 static const WCHAR sz2cents[] = {'2','c','e','n','t','s','\0'};
6440 static const WCHAR szempty[] = {'\0'};
6441 static const WCHAR sz0[] = {'0','\0'};
6442 static const WCHAR sz1[] = {'1','\0'};
6443 static const WCHAR sz7[] = {'7','\0'};
6444 static const WCHAR sz42[] = {'4','2','\0'};
6445 static const WCHAR sz1neg[] = {'-','1','\0'};
6446 static const WCHAR sz666neg[] = {'-','6','6','6','\0'};
6447 static const WCHAR sz1few[] = {'1','.','0','0','0','0','0','0','0','1','\0'};
6448 BSTR bstrhuh, bstrempty, bstr0, bstr1, bstr7, bstr42, bstr1neg, bstr666neg;
6449 BSTR bstr2cents, bstr1few;
6451 CHECKPTR(VarCmp);
6453 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
6454 bstrempty = SysAllocString(szempty);
6455 bstrhuh = SysAllocString(szhuh);
6456 bstr2cents = SysAllocString(sz2cents);
6457 bstr0 = SysAllocString(sz0);
6458 bstr1 = SysAllocString(sz1);
6459 bstr7 = SysAllocString(sz7);
6460 bstr42 = SysAllocString(sz42);
6461 bstr1neg = SysAllocString(sz1neg);
6462 bstr666neg = SysAllocString(sz666neg);
6463 bstr1few = SysAllocString(sz1few);
6465 /* Test all possible flag/vt combinations & the resulting vt type */
6466 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
6468 VARTYPE leftvt, rightvt;
6470 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
6473 SKIPTESTS(leftvt);
6475 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
6477 BOOL bFail = FALSE;
6478 HRESULT expect = VARCMP_EQ;
6480 SKIPTESTS(rightvt);
6482 memset(&left, 0, sizeof(left));
6483 memset(&right, 0, sizeof(right));
6484 V_VT(&left) = leftvt | ExtraFlags[i];
6485 if (leftvt == VT_BSTR) {
6486 V_BSTR(&left) = bstr1neg;
6487 if (ExtraFlags[i] & VT_RESERVED)
6488 expect = VARCMP_LT;
6489 else
6490 expect = VARCMP_GT;
6492 V_VT(&right) = rightvt | ExtraFlags[i];
6493 if (rightvt == VT_BSTR) {
6494 V_BSTR(&right) = bstr1neg;
6495 if (ExtraFlags[i] & VT_RESERVED)
6496 expect = VARCMP_GT;
6497 else
6498 expect = VARCMP_LT;
6501 /* Don't ask me why but native VarCmp cannot handle:
6502 VT_I1, VT_UI2, VT_UI4, VT_UINT and VT_UI8.
6503 VT_INT is only supported as left variant. Go figure.
6504 Tested with DCOM98, Win2k, WinXP */
6505 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
6506 !IsValidVariantClearVT(leftvt, ExtraFlags[i] & ~VT_RESERVED) ||
6507 !IsValidVariantClearVT(rightvt, ExtraFlags[i] & ~VT_RESERVED) ||
6508 leftvt == VT_CLSID || rightvt == VT_CLSID ||
6509 leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
6510 leftvt == VT_ERROR || rightvt == VT_ERROR ||
6511 leftvt == VT_RECORD || rightvt == VT_RECORD ||
6512 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN ||
6513 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
6514 leftvt == VT_I1 || rightvt == VT_I1 ||
6515 leftvt == VT_UI2 || rightvt == VT_UI2 ||
6516 leftvt == VT_UI4 || rightvt == VT_UI4 ||
6517 leftvt == VT_UI8 || rightvt == VT_UI8 ||
6518 rightvt == VT_INT ||
6519 leftvt == VT_UINT || rightvt == VT_UINT) {
6520 bFail = TRUE;
6523 if (leftvt == VT_ERROR && rightvt == VT_ERROR &&
6524 !(ExtraFlags[i] & ~VT_RESERVED)) {
6525 expect = VARCMP_EQ;
6526 bFail = FALSE;
6527 } else if (leftvt == VT_NULL || rightvt == VT_NULL)
6528 expect = VARCMP_NULL;
6529 else if (leftvt == VT_BSTR && rightvt == VT_BSTR)
6530 expect = VARCMP_EQ;
6531 else if (leftvt == VT_BSTR && rightvt == VT_EMPTY)
6532 expect = VARCMP_GT;
6533 else if (leftvt == VT_EMPTY && rightvt == VT_BSTR)
6534 expect = VARCMP_LT;
6536 hres = pVarCmp(&left, &right, LOCALE_USER_DEFAULT, 0);
6537 if (bFail) {
6538 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
6539 "VarCmp: %d|0x%X, %d|0x%X: Expected failure, got 0x%X\n",
6540 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres);
6541 } else {
6542 ok(hres == expect,
6543 "VarCmp: %d|0x%X, %d|0x%X: Expected 0x%X, got 0x%X\n",
6544 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], expect,
6545 hres);
6551 /* VARCMP{,EX} run each 4 tests with a permutation of all possible
6552 input variants with (1) and without (0) VT_RESERVED set. The order
6553 of the permutations is (0,0); (1,0); (0,1); (1,1) */
6554 VARCMP(INT,4711,I2,4711,VARCMP_EQ);
6555 VARCMP(INT,4711,I2,-4711,VARCMP_GT);
6556 VARCMP(ERROR,0,ERROR,0,VARCMP_EQ);
6557 VARCMP(ERROR,0,UI1,0,DISP_E_TYPEMISMATCH);
6558 VARCMP(EMPTY,0,EMPTY,0,VARCMP_EQ);
6559 VARCMP(I4,1,R8,1.0,VARCMP_EQ);
6560 VARCMP(EMPTY,19,I2,0,VARCMP_EQ);
6561 ok(V_EMPTY(&left) == 19, "VT_EMPTY modified!\n");
6562 VARCMP(I4,1,UI1,1,VARCMP_EQ);
6563 VARCMP(I2,2,I2,2,VARCMP_EQ);
6564 VARCMP(I2,1,I2,2,VARCMP_LT);
6565 VARCMP(I2,2,I2,1,VARCMP_GT);
6566 VARCMP(I2,2,EMPTY,1,VARCMP_GT);
6567 VARCMP(I2,2,NULL_,1,VARCMP_NULL);
6569 /* BSTR handling, especially in conjunction with VT_RESERVED */
6570 VARCMP(BSTR,bstr0,NULL_,0,VARCMP_NULL);
6571 VARCMP(BSTR,bstr0,BSTR,bstr0,VARCMP_EQ);
6572 VARCMP(BSTR,bstrempty,BSTR,bstr0,VARCMP_LT);
6573 VARCMP(BSTR,bstr7,BSTR,bstr0,VARCMP_GT);
6574 VARCMP(BSTR,bstr7,BSTR,bstr1neg,VARCMP_GT);
6575 VARCMP(BSTR,bstr0,BSTR,NULL,VARCMP_GT);
6576 VARCMP(BSTR,NULL,BSTR,NULL,VARCMP_EQ);
6577 VARCMP(BSTR,bstrempty,BSTR,NULL,VARCMP_EQ);
6578 VARCMP(BSTR,NULL,EMPTY,0,VARCMP_EQ);
6579 VARCMP(EMPTY,0,BSTR,NULL,VARCMP_EQ);
6580 VARCMP(EMPTY,0,BSTR,bstrempty,VARCMP_EQ);
6581 VARCMP(EMPTY,1,BSTR,bstrempty,VARCMP_EQ);
6582 VARCMP(BSTR,bstr0,EMPTY,0,VARCMP_GT);
6583 VARCMP(BSTR,bstr42,EMPTY,0,VARCMP_GT);
6584 VARCMPEX(BSTR,bstrempty,UI1,0,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
6585 VARCMPEX(BSTR,bstrempty,I2,-1,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
6586 VARCMPEX(I4,0,BSTR,bstrempty,VARCMP_LT,VARCMP_LT,VARCMP_GT,VARCMP_LT);
6587 VARCMPEX(BSTR,NULL,UI1,0,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
6588 VARCMPEX(I4,7,BSTR,NULL,VARCMP_LT,VARCMP_LT,VARCMP_GT,VARCMP_LT);
6589 _VARCMP(BSTR,(BSTR)100,0,I2,100,0,lcid,0,VARCMP_GT);
6590 VARCMPEX(BSTR,bstr0,UI1,0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
6591 VARCMPEX(I2,0,BSTR,bstr0,VARCMP_LT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT);
6592 VARCMP(BSTR,bstrhuh,I4,I4_MAX,VARCMP_GT);
6593 VARCMP(BSTR,bstr2cents,I4,2,VARCMP_GT);
6594 VARCMPEX(BSTR,bstr2cents,I4,42,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
6595 VARCMP(BSTR,bstr2cents,I4,-1,VARCMP_GT);
6596 VARCMPEX(BSTR,bstr2cents,I4,-666,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
6597 VARCMPEX(BSTR,bstr0,I2,0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
6598 VARCMPEX(BSTR,bstr0,I4,0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
6599 VARCMPEX(BSTR,bstr0,I4,-666,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
6600 VARCMP(BSTR,bstr1,I4,0,VARCMP_GT);
6601 VARCMPEX(BSTR,bstr1,I4,1,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
6602 VARCMPEX(BSTR,bstr1,I4,I4_MAX,VARCMP_GT,VARCMP_LT,VARCMP_LT,VARCMP_GT);
6603 VARCMPEX(BSTR,bstr1,I4,-1,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
6604 VARCMP(BSTR,bstr7,I4,1,VARCMP_GT);
6605 VARCMPEX(BSTR,bstr7,I4,7,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
6606 VARCMPEX(BSTR,bstr7,I4,42,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_GT);
6607 VARCMPEX(BSTR,bstr42,I4,7,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
6608 VARCMPEX(BSTR,bstr42,I4,42,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
6609 VARCMPEX(BSTR,bstr42,I4,I4_MAX,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_GT);
6610 VARCMPEX(BSTR,bstr1neg,I4,1,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
6611 VARCMPEX(BSTR,bstr1neg,I4,42,VARCMP_GT,VARCMP_LT,VARCMP_LT,VARCMP_LT);
6612 VARCMPEX(BSTR,bstr1neg,I4,-1,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT);
6613 VARCMPEX(BSTR,bstr1neg,I4,-666,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_LT);
6614 VARCMPEX(BSTR,bstr666neg,I4,1,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
6615 VARCMPEX(BSTR,bstr666neg,I4,7,VARCMP_GT,VARCMP_LT,VARCMP_LT,VARCMP_LT);
6616 VARCMPEX(BSTR,bstr666neg,I4,42,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
6617 VARCMPEX(BSTR,bstr666neg,I4,I4_MAX,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
6618 VARCMPEX(BSTR,bstr666neg,I4,-1,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
6619 VARCMPEX(BSTR,bstr666neg,I4,-666,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT);
6620 VARCMPEX(BSTR,bstr7,R8,7.0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
6621 VARCMPEX(R8,3.141592,BSTR,NULL,VARCMP_LT,VARCMP_LT,VARCMP_GT,VARCMP_LT);
6622 VARCMP(BSTR,bstr7,BSTR,bstr7,VARCMP_EQ);
6623 VARCMP(BSTR,bstr7,BSTR,bstr42,VARCMP_GT);
6624 VARCMP(BSTR,bstr42,BSTR,bstr7,VARCMP_LT);
6626 /* DECIMAL handling */
6627 setdec(&dec,0,0,0,0);
6628 VARCMPEX(DECIMAL,dec,BSTR,bstr0,VARCMP_LT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT);
6629 setdec64(&dec,0,0,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF); /* max DECIMAL */
6630 VARCMP(DECIMAL,dec,R8,R8_MAX,VARCMP_LT); /* R8 has bigger range */
6631 VARCMP(DECIMAL,dec,DATE,R8_MAX,VARCMP_LT); /* DATE has bigger range */
6632 setdec64(&dec,0,0x80,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF);
6633 VARCMP(DECIMAL,dec,R8,-R8_MAX,VARCMP_GT);
6634 setdec64(&dec,20,0,0x5,0x6BC75E2D,0x63100001); /* 1+1e-20 */
6635 VARCMP(DECIMAL,dec,R8,1,VARCMP_GT); /* DECIMAL has higher precision */
6637 /* Show that DATE is handled just as a R8 */
6638 VARCMP(DATE,DATE_MAX,DATE,DATE_MAX+1,VARCMP_LT);
6639 VARCMP(DATE,DATE_MIN,DATE,DATE_MIN-1,VARCMP_GT);
6640 VARCMP(DATE,R8_MIN,R8,R8_MIN,VARCMP_EQ);
6641 VARCMP(DATE,1,DATE,1+1e-15,VARCMP_LT); /* 1e-15 == 8.64e-11 seconds */
6642 VARCMP(DATE,25570.0,DATE,25570.0,VARCMP_EQ);
6643 VARCMP(DATE,25570.0,DATE,25571.0,VARCMP_LT);
6644 VARCMP(DATE,25571.0,DATE,25570.0,VARCMP_GT);
6645 VARCMP(DATE,25570.0,EMPTY,0,VARCMP_GT);
6646 VARCMP(DATE,25570.0,NULL_,0,VARCMP_NULL);
6648 /* R4 precision handling */
6649 VARCMP(R4,1,R8,1+1e-8,VARCMP_EQ);
6650 VARCMP(R8,1+1e-8,R4,1,VARCMP_EQ);
6651 VARCMP(R8,1+1e-8,R8,1,VARCMP_GT);
6652 VARCMP(R8,R4_MAX*1.1,R4,R4_MAX,VARCMP_GT);
6653 VARCMP(R4,R4_MAX,R8,R8_MAX,VARCMP_LT);
6654 VARCMP(R4,1,DATE,1+1e-8,VARCMP_EQ);
6655 VARCMP(R4,1,BSTR,bstr1few,VARCMP_LT); /* bstr1few == 1+1e-8 */
6656 setdec(&dec,8,0,0,0x5F5E101); /* 1+1e-8 */
6657 VARCMP(R4,1,DECIMAL,dec,VARCMP_LT);
6659 SysFreeString(bstrhuh);
6660 SysFreeString(bstrempty);
6661 SysFreeString(bstr0);
6662 SysFreeString(bstr1);
6663 SysFreeString(bstr7);
6664 SysFreeString(bstr42);
6665 SysFreeString(bstr1neg);
6666 SysFreeString(bstr666neg);
6667 SysFreeString(bstr2cents);
6668 SysFreeString(bstr1few);
6671 static HRESULT (WINAPI *pVarPow)(LPVARIANT,LPVARIANT,LPVARIANT);
6673 #define VARPOW(vt1,val1,vt2,val2,rvt,rval) \
6674 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
6675 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
6676 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
6677 test_var_call2( __LINE__, pVarPow, &left, &right, &exp )
6679 /* Skip any type that is not defined or produces an error for every case */
6680 #define SKIPTESTPOW(a) \
6681 if (a == VT_ERROR || a == VT_VARIANT || \
6682 a == VT_DISPATCH || a == VT_UNKNOWN || \
6683 a == VT_RECORD || a > VT_UINT || \
6684 a == 15 /*not defined*/) \
6685 continue
6687 static void test_VarPow(void)
6689 static const WCHAR str2[] = { '2','\0' };
6690 static const WCHAR str3[] = { '3','\0' };
6691 VARIANT left, right, exp, result, cy, dec;
6692 BSTR num2_str, num3_str;
6693 VARTYPE i;
6694 HRESULT hres;
6696 CHECKPTR(VarPow);
6698 num2_str = SysAllocString(str2);
6699 num3_str = SysAllocString(str3);
6701 /* Test all possible flag/vt combinations & the resulting vt type */
6702 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
6704 VARTYPE leftvt, rightvt, resvt;
6706 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
6708 SKIPTESTPOW(leftvt);
6710 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
6712 BOOL bFail = FALSE;
6713 SKIPTESTPOW(rightvt);
6715 /* Native crashes with VT_BYREF */
6716 if (ExtraFlags[i] == VT_BYREF)
6717 continue;
6719 memset(&left, 0, sizeof(left));
6720 memset(&right, 0, sizeof(right));
6721 V_VT(&left) = leftvt | ExtraFlags[i];
6722 V_VT(&right) = rightvt | ExtraFlags[i];
6723 V_VT(&result) = VT_EMPTY;
6724 resvt = VT_EMPTY;
6726 if (leftvt == VT_BSTR)
6727 V_BSTR(&left) = num2_str;
6728 if (rightvt == VT_BSTR)
6729 V_BSTR(&right) = num2_str;
6731 /* Native VarPow always returns an error when using extra flags */
6732 if (ExtraFlags[i] != 0)
6733 bFail = TRUE;
6735 /* Determine return type */
6736 else if ((leftvt == VT_NULL || rightvt == VT_NULL) &&
6737 ((leftvt != VT_I8 && leftvt != VT_UI8 &&
6738 rightvt != VT_I8 && rightvt != VT_UI8) || HAVE_OLEAUT32_I8))
6739 resvt = VT_NULL;
6740 else if ((leftvt == VT_EMPTY || leftvt == VT_I2 ||
6741 leftvt == VT_I4 || leftvt == VT_R4 ||
6742 leftvt == VT_R8 || leftvt == VT_CY ||
6743 leftvt == VT_DATE || leftvt == VT_BSTR ||
6744 leftvt == VT_BOOL || leftvt == VT_DECIMAL ||
6745 (leftvt >= VT_I1 && leftvt <= VT_UI4) ||
6746 (HAVE_OLEAUT32_I8 && (leftvt == VT_I8 || leftvt == VT_UI8)) ||
6747 leftvt == VT_INT || leftvt == VT_UINT) &&
6748 (rightvt == VT_EMPTY || rightvt == VT_I2 ||
6749 rightvt == VT_I4 || rightvt == VT_R4 ||
6750 rightvt == VT_R8 || rightvt == VT_CY ||
6751 rightvt == VT_DATE || rightvt == VT_BSTR ||
6752 rightvt == VT_BOOL || rightvt == VT_DECIMAL ||
6753 (rightvt >= VT_I1 && rightvt <= VT_UI4) ||
6754 (HAVE_OLEAUT32_I8 && (rightvt == VT_I8 || rightvt == VT_UI8)) ||
6755 rightvt == VT_INT || rightvt == VT_UINT))
6756 resvt = VT_R8;
6757 else
6758 bFail = TRUE;
6760 hres = pVarPow(&left, &right, &result);
6762 /* Check expected HRESULT and if result variant type is correct */
6763 if (bFail)
6764 ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH,
6765 "VarPow: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
6766 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
6767 vtstr(V_VT(&result)), hres);
6768 else
6769 ok (hres == S_OK && resvt == V_VT(&result),
6770 "VarPow: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
6771 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
6772 S_OK, vtstr(V_VT(&result)), hres);
6777 /* Check return values for valid variant type combinations */
6778 VARPOW(EMPTY,0,EMPTY,0,R8,1.0);
6779 VARPOW(EMPTY,0,NULL,0,NULL,0);
6780 VARPOW(EMPTY,0,I2,3,R8,0.0);
6781 VARPOW(EMPTY,0,I4,3,R8,0.0);
6782 VARPOW(EMPTY,0,R4,3.0f,R8,0.0);
6783 VARPOW(EMPTY,0,R8,3.0,R8,0.0);
6784 VARPOW(EMPTY,0,DATE,3,R8,0.0);
6785 VARPOW(EMPTY,0,BSTR,num3_str,R8,0.0);
6786 VARPOW(EMPTY,0,BOOL,VARIANT_FALSE,R8,1.0);
6787 VARPOW(EMPTY,0,I1,3,R8,0.0);
6788 VARPOW(EMPTY,0,UI1,3,R8,0.0);
6789 VARPOW(EMPTY,0,UI2,3,R8,0.0);
6790 VARPOW(EMPTY,0,UI4,3,R8,0.0);
6791 if (HAVE_OLEAUT32_I8)
6793 VARPOW(EMPTY,0,I8,3,R8,0.0);
6794 VARPOW(EMPTY,0,UI8,3,R8,0.0);
6796 VARPOW(EMPTY,0,INT,3,R8,0.0);
6797 VARPOW(EMPTY,0,UINT,3,R8,0.0);
6798 VARPOW(NULL,0,EMPTY,0,NULL,0);
6799 VARPOW(NULL,0,NULL,0,NULL,0);
6800 VARPOW(NULL,0,I2,3,NULL,0);
6801 VARPOW(NULL,0,I4,3,NULL,0);
6802 VARPOW(NULL,0,R4,3.0f,NULL,0);
6803 VARPOW(NULL,0,R8,3.0,NULL,0);
6804 VARPOW(NULL,0,DATE,3,NULL,0);
6805 VARPOW(NULL,0,BSTR,num3_str,NULL,0);
6806 VARPOW(NULL,0,BOOL,VARIANT_TRUE,NULL,0);
6807 VARPOW(NULL,0,I1,3,NULL,0);
6808 VARPOW(NULL,0,UI1,3,NULL,0);
6809 VARPOW(NULL,0,UI2,3,NULL,0);
6810 VARPOW(NULL,0,UI4,3,NULL,0);
6811 if (HAVE_OLEAUT32_I8)
6813 VARPOW(NULL,0,I8,3,NULL,0);
6814 VARPOW(NULL,0,UI8,3,NULL,0);
6816 VARPOW(NULL,0,INT,3,NULL,0);
6817 VARPOW(NULL,0,UINT,3,NULL,0);
6818 VARPOW(I2,2,EMPTY,0,R8,1.0);
6819 VARPOW(I2,2,NULL,0,NULL,0);
6820 VARPOW(I2,2,I2,3,R8,8.0);
6821 VARPOW(I2,2,I4,3,R8,8.0);
6822 VARPOW(I2,2,R4,3.0f,R8,8.0);
6823 VARPOW(I2,2,R8,3.0,R8,8.0);
6824 VARPOW(I2,2,DATE,3,R8,8.0);
6825 VARPOW(I2,2,BSTR,num3_str,R8,8.0);
6826 VARPOW(I2,2,BOOL,VARIANT_FALSE,R8,1.0);
6827 VARPOW(I2,2,I1,3,R8,8.0);
6828 VARPOW(I2,2,UI1,3,R8,8.0);
6829 VARPOW(I2,2,UI2,3,R8,8.0);
6830 VARPOW(I2,2,UI4,3,R8,8.0);
6831 if (HAVE_OLEAUT32_I8)
6833 VARPOW(I2,2,I8,3,R8,8.0);
6834 VARPOW(I2,2,UI8,3,R8,8.0);
6836 VARPOW(I2,2,INT,3,R8,8.0);
6837 VARPOW(I2,2,UINT,3,R8,8.0);
6838 VARPOW(I4,2,EMPTY,0,R8,1.0);
6839 VARPOW(I4,2,NULL,0,NULL,0);
6840 VARPOW(I4,2,I2,3,R8,8.0);
6841 VARPOW(I4,2,I4,3,R8,8.0);
6842 VARPOW(I4,2,R4,3.0f,R8,8.0);
6843 VARPOW(I4,2,R8,3.0,R8,8.0);
6844 VARPOW(I4,2,DATE,3,R8,8.0);
6845 VARPOW(I4,2,BSTR,num3_str,R8,8.0);
6846 VARPOW(I4,2,BOOL,VARIANT_FALSE,R8,1.0);
6847 VARPOW(I4,2,I1,3,R8,8.0);
6848 VARPOW(I4,2,UI1,3,R8,8.0);
6849 VARPOW(I4,2,UI2,3,R8,8.0);
6850 VARPOW(I4,2,UI4,3,R8,8.0);
6851 if (HAVE_OLEAUT32_I8)
6853 VARPOW(I4,2,I8,3,R8,8.0);
6854 VARPOW(I4,2,UI8,3,R8,8.0);
6856 VARPOW(I4,2,INT,3,R8,8.0);
6857 VARPOW(I4,2,UINT,3,R8,8.0);
6858 VARPOW(R4,2,EMPTY,0,R8,1.0);
6859 VARPOW(R4,2,NULL,0,NULL,0);
6860 VARPOW(R4,2,I2,3,R8,8.0);
6861 VARPOW(R4,2,I4,3,R8,8.0);
6862 VARPOW(R4,2,R4,3.0f,R8,8.0);
6863 VARPOW(R4,2,R8,3.0,R8,8.0);
6864 VARPOW(R4,2,DATE,3,R8,8.0);
6865 VARPOW(R4,2,BSTR,num3_str,R8,8.0);
6866 VARPOW(R4,2,BOOL,VARIANT_FALSE,R8,1.0);
6867 VARPOW(R4,2,I1,3,R8,8.0);
6868 VARPOW(R4,2,UI1,3,R8,8.0);
6869 VARPOW(R4,2,UI2,3,R8,8.0);
6870 VARPOW(R4,2,UI4,3,R8,8.0);
6871 if (HAVE_OLEAUT32_I8)
6873 VARPOW(R4,2,I8,3,R8,8.0);
6874 VARPOW(R4,2,UI8,3,R8,8.0);
6876 VARPOW(R4,2,INT,3,R8,8.0);
6877 VARPOW(R4,2,UINT,3,R8,8.0);
6878 VARPOW(R8,2,EMPTY,0,R8,1.0);
6879 VARPOW(R8,2,NULL,0,NULL,0);
6880 VARPOW(R8,2,I2,3,R8,8.0);
6881 VARPOW(R8,2,I4,3,R8,8.0);
6882 VARPOW(R8,2,R4,3.0f,R8,8.0);
6883 VARPOW(R8,2,R8,3.0,R8,8.0);
6884 VARPOW(R8,2,DATE,3,R8,8.0);
6885 VARPOW(R8,2,BSTR,num3_str,R8,8.0);
6886 VARPOW(R8,2,BOOL,VARIANT_FALSE,R8,1.0);
6887 VARPOW(R8,2,I1,3,R8,8.0);
6888 VARPOW(R8,2,UI1,3,R8,8.0);
6889 VARPOW(R8,2,UI2,3,R8,8.0);
6890 VARPOW(R8,2,UI4,3,R8,8.0);
6891 if (HAVE_OLEAUT32_I8)
6893 VARPOW(R8,2,I8,3,R8,8.0);
6894 VARPOW(R8,2,UI8,3,R8,8.0);
6896 VARPOW(R8,2,INT,3,R8,8.0);
6897 VARPOW(R8,2,UINT,3,R8,8.0);
6898 VARPOW(DATE,2,EMPTY,0,R8,1.0);
6899 VARPOW(DATE,2,NULL,0,NULL,0);
6900 VARPOW(DATE,2,I2,3,R8,8.0);
6901 VARPOW(DATE,2,I4,3,R8,8.0);
6902 VARPOW(DATE,2,R4,3.0f,R8,8.0);
6903 VARPOW(DATE,2,R8,3.0,R8,8.0);
6904 VARPOW(DATE,2,DATE,3,R8,8.0);
6905 VARPOW(DATE,2,BSTR,num3_str,R8,8.0);
6906 VARPOW(DATE,2,BOOL,VARIANT_FALSE,R8,1.0);
6907 VARPOW(DATE,2,I1,3,R8,8.0);
6908 VARPOW(DATE,2,UI1,3,R8,8.0);
6909 VARPOW(DATE,2,UI2,3,R8,8.0);
6910 VARPOW(DATE,2,UI4,3,R8,8.0);
6911 if (HAVE_OLEAUT32_I8)
6913 VARPOW(DATE,2,I8,3,R8,8.0);
6914 VARPOW(DATE,2,UI8,3,R8,8.0);
6916 VARPOW(DATE,2,INT,3,R8,8.0);
6917 VARPOW(DATE,2,UINT,3,R8,8.0);
6918 VARPOW(BSTR,num2_str,EMPTY,0,R8,1.0);
6919 VARPOW(BSTR,num2_str,NULL,0,NULL,0);
6920 VARPOW(BSTR,num2_str,I2,3,R8,8.0);
6921 VARPOW(BSTR,num2_str,I4,3,R8,8.0);
6922 VARPOW(BSTR,num2_str,R4,3.0f,R8,8.0);
6923 VARPOW(BSTR,num2_str,R8,3.0,R8,8.0);
6924 VARPOW(BSTR,num2_str,DATE,3,R8,8.0);
6925 VARPOW(BSTR,num2_str,BSTR,num3_str,R8,8.0);
6926 VARPOW(BSTR,num2_str,BOOL,VARIANT_FALSE,R8,1.0);
6927 VARPOW(BSTR,num2_str,I1,3,R8,8.0);
6928 VARPOW(BSTR,num2_str,UI1,3,R8,8.0);
6929 VARPOW(BSTR,num2_str,UI2,3,R8,8.0);
6930 VARPOW(BSTR,num2_str,UI4,3,R8,8.0);
6931 if (HAVE_OLEAUT32_I8)
6933 VARPOW(BSTR,num2_str,I8,3,R8,8.0);
6934 VARPOW(BSTR,num2_str,UI8,3,R8,8.0);
6936 VARPOW(BSTR,num2_str,INT,3,R8,8.0);
6937 VARPOW(BSTR,num2_str,UINT,3,R8,8.0);
6938 VARPOW(BOOL,VARIANT_TRUE,EMPTY,0,R8,1.0);
6939 VARPOW(BOOL,VARIANT_TRUE,NULL,0,NULL,0);
6940 VARPOW(BOOL,VARIANT_TRUE,I2,3,R8,-1.0);
6941 VARPOW(BOOL,VARIANT_TRUE,I4,3,R8,-1.0);
6942 VARPOW(BOOL,VARIANT_TRUE,R4,3.0f,R8,-1.0);
6943 VARPOW(BOOL,VARIANT_TRUE,R8,3.0,R8,-1.0);
6944 VARPOW(BOOL,VARIANT_TRUE,DATE,3,R8,-1.0);
6945 VARPOW(BOOL,VARIANT_TRUE,BSTR,num3_str,R8,-1.0);
6946 VARPOW(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,R8,-1.0);
6947 VARPOW(BOOL,VARIANT_TRUE,I1,3,R8,-1.0);
6948 VARPOW(BOOL,VARIANT_TRUE,UI1,3,R8,-1.0);
6949 VARPOW(BOOL,VARIANT_TRUE,UI2,3,R8,-1.0);
6950 VARPOW(BOOL,VARIANT_TRUE,UI4,3,R8,-1.0);
6951 if (HAVE_OLEAUT32_I8)
6953 VARPOW(BOOL,VARIANT_TRUE,I8,3,R8,-1.0);
6954 VARPOW(BOOL,VARIANT_TRUE,UI8,3,R8,-1.0);
6956 VARPOW(BOOL,VARIANT_TRUE,INT,3,R8,-1.0);
6957 VARPOW(BOOL,VARIANT_TRUE,UINT,3,R8,-1.0);
6958 VARPOW(I1,2,EMPTY,0,R8,1.0);
6959 VARPOW(I1,2,NULL,0,NULL,0);
6960 VARPOW(I1,2,I2,3,R8,8.0);
6961 VARPOW(I1,2,I4,3,R8,8.0);
6962 VARPOW(I1,2,R4,3.0f,R8,8.0);
6963 VARPOW(I1,2,R8,3.0,R8,8.0);
6964 VARPOW(I1,2,DATE,3,R8,8.0);
6965 VARPOW(I1,2,BSTR,num3_str,R8,8.0);
6966 VARPOW(I1,2,BOOL,VARIANT_FALSE,R8,1.0);
6967 VARPOW(I1,2,I1,3,R8,8.0);
6968 VARPOW(I1,2,UI1,3,R8,8.0);
6969 VARPOW(I1,2,UI2,3,R8,8.0);
6970 VARPOW(I1,2,UI4,3,R8,8.0);
6971 if (HAVE_OLEAUT32_I8)
6973 VARPOW(I1,2,I8,3,R8,8.0);
6974 VARPOW(I1,2,UI8,3,R8,8.0);
6976 VARPOW(I1,2,INT,3,R8,8.0);
6977 VARPOW(I1,2,UINT,3,R8,8.0);
6978 VARPOW(UI1,2,EMPTY,0,R8,1.0);
6979 VARPOW(UI1,2,NULL,0,NULL,0);
6980 VARPOW(UI1,2,I2,3,R8,8.0);
6981 VARPOW(UI1,2,I4,3,R8,8.0);
6982 VARPOW(UI1,2,R4,3.0f,R8,8.0);
6983 VARPOW(UI1,2,R8,3.0,R8,8.0);
6984 VARPOW(UI1,2,DATE,3,R8,8.0);
6985 VARPOW(UI1,2,BSTR,num3_str,R8,8.0);
6986 VARPOW(UI1,2,BOOL,VARIANT_FALSE,R8,1.0);
6987 VARPOW(UI1,2,I1,3,R8,8.0);
6988 VARPOW(UI1,2,UI1,3,R8,8.0);
6989 VARPOW(UI1,2,UI2,3,R8,8.0);
6990 VARPOW(UI1,2,UI4,3,R8,8.0);
6991 if (HAVE_OLEAUT32_I8)
6993 VARPOW(UI1,2,I8,3,R8,8.0);
6994 VARPOW(UI1,2,UI8,3,R8,8.0);
6996 VARPOW(UI1,2,INT,3,R8,8.0);
6997 VARPOW(UI1,2,UINT,3,R8,8.0);
6998 VARPOW(UI2,2,EMPTY,0,R8,1.0);
6999 VARPOW(UI2,2,NULL,0,NULL,0);
7000 VARPOW(UI2,2,I2,3,R8,8.0);
7001 VARPOW(UI2,2,I4,3,R8,8.0);
7002 VARPOW(UI2,2,R4,3.0f,R8,8.0);
7003 VARPOW(UI2,2,R8,3.0,R8,8.0);
7004 VARPOW(UI2,2,DATE,3,R8,8.0);
7005 VARPOW(UI2,2,BSTR,num3_str,R8,8.0);
7006 VARPOW(UI2,2,BOOL,VARIANT_FALSE,R8,1.0);
7007 VARPOW(UI2,2,I1,3,R8,8.0);
7008 VARPOW(UI2,2,UI1,3,R8,8.0);
7009 VARPOW(UI2,2,UI2,3,R8,8.0);
7010 VARPOW(UI2,2,UI4,3,R8,8.0);
7011 if (HAVE_OLEAUT32_I8)
7013 VARPOW(UI2,2,I8,3,R8,8.0);
7014 VARPOW(UI2,2,UI8,3,R8,8.0);
7016 VARPOW(UI2,2,INT,3,R8,8.0);
7017 VARPOW(UI2,2,UINT,3,R8,8.0);
7018 VARPOW(UI4,2,EMPTY,0,R8,1.0);
7019 VARPOW(UI4,2,NULL,0,NULL,0);
7020 VARPOW(UI4,2,I2,3,R8,8.0);
7021 VARPOW(UI4,2,I4,3,R8,8.0);
7022 VARPOW(UI4,2,R4,3.0f,R8,8.0);
7023 VARPOW(UI4,2,R8,3.0,R8,8.0);
7024 VARPOW(UI4,2,DATE,3,R8,8.0);
7025 VARPOW(UI4,2,BSTR,num3_str,R8,8.0);
7026 VARPOW(UI4,2,BOOL,VARIANT_FALSE,R8,1.0);
7027 VARPOW(UI4,2,I1,3,R8,8.0);
7028 VARPOW(UI4,2,UI1,3,R8,8.0);
7029 VARPOW(UI4,2,UI2,3,R8,8.0);
7030 VARPOW(UI4,2,UI4,3,R8,8.0);
7031 if (HAVE_OLEAUT32_I8)
7033 VARPOW(UI4,2,I8,3,R8,8.0);
7034 VARPOW(UI4,2,UI8,3,R8,8.0);
7036 VARPOW(UI4,2,INT,3,R8,8.0);
7037 VARPOW(UI4,2,UINT,3,R8,8.0);
7038 if (HAVE_OLEAUT32_I8)
7040 VARPOW(I8,2,EMPTY,0,R8,1.0);
7041 VARPOW(I8,2,NULL,0,NULL,0);
7042 VARPOW(I8,2,I2,3,R8,8.0);
7043 VARPOW(I8,2,I4,3,R8,8.0);
7044 VARPOW(I8,2,R4,3.0f,R8,8.0);
7045 VARPOW(I8,2,R8,3.0,R8,8.0);
7046 VARPOW(I8,2,DATE,3,R8,8.0);
7047 VARPOW(I8,2,BSTR,num3_str,R8,8.0);
7048 VARPOW(I8,2,BOOL,VARIANT_FALSE,R8,1.0);
7049 VARPOW(I8,2,I1,3,R8,8.0);
7050 VARPOW(I8,2,UI1,3,R8,8.0);
7051 VARPOW(I8,2,UI2,3,R8,8.0);
7052 VARPOW(I8,2,UI4,3,R8,8.0);
7053 VARPOW(I8,2,I8,3,R8,8.0);
7054 VARPOW(I8,2,UI8,3,R8,8.0);
7055 VARPOW(I8,2,INT,3,R8,8.0);
7056 VARPOW(I8,2,UINT,3,R8,8.0);
7057 VARPOW(UI8,2,EMPTY,0,R8,1.0);
7058 VARPOW(UI8,2,NULL,0,NULL,0);
7059 VARPOW(UI8,2,I2,3,R8,8.0);
7060 VARPOW(UI8,2,I4,3,R8,8.0);
7061 VARPOW(UI8,2,R4,3.0f,R8,8.0);
7062 VARPOW(UI8,2,R8,3.0,R8,8.0);
7063 VARPOW(UI8,2,DATE,3,R8,8.0);
7064 VARPOW(UI8,2,BSTR,num3_str,R8,8.0);
7065 VARPOW(UI8,2,I1,3,R8,8.0);
7066 VARPOW(UI8,2,UI1,3,R8,8.0);
7067 VARPOW(UI8,2,UI2,3,R8,8.0);
7068 VARPOW(UI8,2,UI4,3,R8,8.0);
7069 VARPOW(UI8,2,I8,3,R8,8.0);
7070 VARPOW(UI8,2,UI8,3,R8,8.0);
7071 VARPOW(UI8,2,INT,3,R8,8.0);
7072 VARPOW(UI8,2,UINT,3,R8,8.0);
7074 VARPOW(INT,2,EMPTY,0,R8,1.0);
7075 VARPOW(INT,2,NULL,0,NULL,0);
7076 VARPOW(INT,2,I2,3,R8,8.0);
7077 VARPOW(INT,2,I4,3,R8,8.0);
7078 VARPOW(INT,2,R4,3.0f,R8,8.0);
7079 VARPOW(INT,2,R8,3.0,R8,8.0);
7080 VARPOW(INT,2,DATE,3,R8,8.0);
7081 VARPOW(INT,2,BSTR,num3_str,R8,8.0);
7082 VARPOW(INT,2,BOOL,VARIANT_FALSE,R8,1.0);
7083 VARPOW(INT,2,I1,3,R8,8.0);
7084 VARPOW(INT,2,UI1,3,R8,8.0);
7085 VARPOW(INT,2,UI2,3,R8,8.0);
7086 VARPOW(INT,2,UI4,3,R8,8.0);
7087 if (HAVE_OLEAUT32_I8)
7089 VARPOW(INT,2,I8,3,R8,8.0);
7090 VARPOW(INT,2,UI8,3,R8,8.0);
7092 VARPOW(INT,2,INT,3,R8,8.0);
7093 VARPOW(INT,2,UINT,3,R8,8.0);
7094 VARPOW(UINT,2,EMPTY,0,R8,1.0);
7095 VARPOW(UINT,2,NULL,0,NULL,0);
7096 VARPOW(UINT,2,I2,3,R8,8.0);
7097 VARPOW(UINT,2,I4,3,R8,8.0);
7098 VARPOW(UINT,2,R4,3.0f,R8,8.0);
7099 VARPOW(UINT,2,R8,3.0,R8,8.0);
7100 VARPOW(UINT,2,DATE,3,R8,8.0);
7101 VARPOW(UINT,2,BSTR,num3_str,R8,8.0);
7102 VARPOW(UINT,2,BOOL,VARIANT_FALSE,R8,1.0);
7103 VARPOW(UINT,2,I1,3,R8,8.0);
7104 VARPOW(UINT,2,UI1,3,R8,8.0);
7105 VARPOW(UINT,2,UI2,3,R8,8.0);
7106 VARPOW(UINT,2,UI4,3,R8,8.0);
7107 if (HAVE_OLEAUT32_I8)
7109 VARPOW(UINT,2,I8,3,R8,8.0);
7110 VARPOW(UINT,2,UI8,3,R8,8.0);
7112 VARPOW(UINT,2,INT,3,R8,8.0);
7113 VARPOW(UINT,2,UINT,3,R8,8.0);
7115 /* Manually test some VT_CY, VT_DECIMAL variants */
7116 V_VT(&cy) = VT_CY;
7117 hres = VarCyFromI4(2, &V_CY(&cy));
7118 ok(hres == S_OK, "VarCyFromI4 failed!\n");
7119 V_VT(&dec) = VT_DECIMAL;
7120 hres = VarDecFromR8(2.0, &V_DECIMAL(&dec));
7121 ok(hres == S_OK, "VarDecFromR4 failed!\n");
7122 memset(&left, 0, sizeof(left));
7123 memset(&right, 0, sizeof(right));
7124 V_VT(&left) = VT_I4;
7125 V_I4(&left) = 100;
7126 V_VT(&right) = VT_I8;
7127 V_UI1(&right) = 2;
7129 hres = pVarPow(&cy, &cy, &result);
7130 ok(hres == S_OK && V_VT(&result) == VT_R8,
7131 "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7132 S_OK, hres, vtstr(V_VT(&result)));
7133 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 4.0),
7134 "VARPOW: CY value %f, expected %f\n", V_R8(&result), 4.0);
7136 hres = pVarPow(&cy, &right, &result);
7137 if (hres == S_OK)
7139 ok(hres == S_OK && V_VT(&result) == VT_R8,
7140 "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7141 S_OK, hres, vtstr(V_VT(&result)));
7142 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 4.0),
7143 "VARPOW: CY value %f, expected %f\n", V_R8(&result), 4.0);
7145 else
7147 ok(hres == DISP_E_BADVARTYPE && V_VT(&result) == VT_EMPTY,
7148 "VARPOW: expected coerced hres 0x%X type VT_EMPTY, got hres 0x%X type %s!\n",
7149 DISP_E_BADVARTYPE, hres, vtstr(V_VT(&result)));
7152 hres = pVarPow(&left, &cy, &result);
7153 ok(hres == S_OK && V_VT(&result) == VT_R8,
7154 "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7155 S_OK, hres, vtstr(V_VT(&result)));
7156 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 10000.0),
7157 "VARPOW: CY value %f, expected %f\n", V_R8(&result), 10000.0);
7159 hres = pVarPow(&left, &dec, &result);
7160 ok(hres == S_OK && V_VT(&result) == VT_R8,
7161 "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7162 S_OK, hres, vtstr(V_VT(&result)));
7163 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result),10000.0),
7164 "VARPOW: DECIMAL value %f, expected %f\n", V_R8(&result), 10000.0);
7166 hres = pVarPow(&dec, &dec, &result);
7167 ok(hres == S_OK && V_VT(&result) == VT_R8,
7168 "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7169 S_OK, hres, vtstr(V_VT(&result)));
7170 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 4.0),
7171 "VARPOW: DECIMAL value %f, expected %f\n", V_R8(&result), 4.0);
7173 hres = pVarPow(&dec, &right, &result);
7174 if (hres == S_OK)
7176 ok(hres == S_OK && V_VT(&result) == VT_R8,
7177 "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7178 S_OK, hres, vtstr(V_VT(&result)));
7179 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 4.0),
7180 "VARPOW: DECIMAL value %f, expected %f\n", V_R8(&result), 4.0);
7182 else
7184 ok(hres == DISP_E_BADVARTYPE && V_VT(&result) == VT_EMPTY,
7185 "VARPOW: expected coerced hres 0x%X type VT_EMPTY, got hres 0x%X type %s!\n",
7186 DISP_E_BADVARTYPE, hres, vtstr(V_VT(&result)));
7189 SysFreeString(num2_str);
7190 SysFreeString(num3_str);
7193 static HRESULT (WINAPI *pVarDiv)(LPVARIANT,LPVARIANT,LPVARIANT);
7195 #define VARDIV(vt1,val1,vt2,val2,rvt,rval) \
7196 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
7197 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
7198 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
7199 test_var_call2( __LINE__, pVarDiv, &left, &right, &exp )
7201 /* Skip any type that is not defined or produces an error for every case */
7202 #define SKIPTESTDIV(a) \
7203 if (a == VT_ERROR || a == VT_VARIANT || \
7204 a == VT_DISPATCH || a == VT_UNKNOWN || \
7205 a == VT_RECORD || a > VT_UINT || \
7206 a == VT_I1 || a == VT_UI8 || \
7207 a == VT_INT || a == VT_UINT || \
7208 a == VT_UI2 || a == VT_UI4 || \
7209 a == 15 /*not defined*/) \
7210 continue
7212 static void test_VarDiv(void)
7214 static const WCHAR str1[] = { '1','\0' };
7215 static const WCHAR str2[] = { '2','\0' };
7216 VARIANT left, right, exp, result, cy, dec;
7217 BSTR num1_str, num2_str;
7218 VARTYPE i;
7219 HRESULT hres;
7220 double r;
7222 num1_str = SysAllocString(str1);
7223 num2_str = SysAllocString(str2);
7225 CHECKPTR(VarDiv);
7227 /* Test all possible flag/vt combinations & the resulting vt type */
7228 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
7230 VARTYPE leftvt, rightvt, resvt;
7232 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
7234 SKIPTESTDIV(leftvt);
7236 /* Check if we need/have support for I8 */
7237 if (leftvt == VT_I8 && !HAVE_OLEAUT32_I8)
7238 continue;
7240 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
7242 BOOL bFail = FALSE;
7243 SKIPTESTDIV(rightvt);
7245 /* Check if we need/have support for I8 */
7246 if (rightvt == VT_I8 && !HAVE_OLEAUT32_I8)
7247 continue;
7249 /* Native crashes with VT_BYREF */
7250 if (ExtraFlags[i] == VT_BYREF)
7251 continue;
7253 memset(&left, 0, sizeof(left));
7254 memset(&right, 0, sizeof(right));
7255 V_VT(&left) = leftvt | ExtraFlags[i];
7256 V_VT(&right) = rightvt | ExtraFlags[i];
7257 V_VT(&result) = VT_EMPTY;
7258 resvt = VT_EMPTY;
7260 if (leftvt == VT_BSTR)
7261 V_BSTR(&left) = num2_str;
7262 else if (leftvt == VT_DECIMAL)
7264 VarDecFromR8(2.0, &V_DECIMAL(&left));
7265 V_VT(&left) = leftvt | ExtraFlags[i];
7268 /* Division by 0 is undefined */
7269 switch(rightvt)
7271 case VT_BSTR:
7272 V_BSTR(&right) = num2_str;
7273 break;
7274 case VT_DECIMAL:
7275 VarDecFromR8(2.0, &V_DECIMAL(&right));
7276 V_VT(&right) = rightvt | ExtraFlags[i];
7277 break;
7278 case VT_BOOL:
7279 V_BOOL(&right) = VARIANT_TRUE;
7280 break;
7281 case VT_I2: V_I2(&right) = 2; break;
7282 case VT_I4: V_I4(&right) = 2; break;
7283 case VT_R4: V_R4(&right) = 2.0f; break;
7284 case VT_R8: V_R8(&right) = 2.0; break;
7285 case VT_CY: V_CY(&right).int64 = 2; break;
7286 case VT_DATE: V_DATE(&right) = 2; break;
7287 case VT_UI1: V_UI1(&right) = 2; break;
7288 case VT_I8: V_I8(&right) = 2; break;
7289 default: break;
7292 /* Determine return type */
7293 if (!(rightvt == VT_EMPTY))
7295 if (leftvt == VT_NULL || rightvt == VT_NULL)
7296 resvt = VT_NULL;
7297 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
7298 resvt = VT_DECIMAL;
7299 else if (leftvt == VT_I8 || rightvt == VT_I8 ||
7300 leftvt == VT_CY || rightvt == VT_CY ||
7301 leftvt == VT_DATE || rightvt == VT_DATE ||
7302 leftvt == VT_I4 || rightvt == VT_I4 ||
7303 leftvt == VT_BSTR || rightvt == VT_BSTR ||
7304 leftvt == VT_I2 || rightvt == VT_I2 ||
7305 leftvt == VT_BOOL || rightvt == VT_BOOL ||
7306 leftvt == VT_R8 || rightvt == VT_R8 ||
7307 leftvt == VT_UI1 || rightvt == VT_UI1)
7309 if ((leftvt == VT_UI1 && rightvt == VT_R4) ||
7310 (leftvt == VT_R4 && rightvt == VT_UI1))
7311 resvt = VT_R4;
7312 else if ((leftvt == VT_R4 && (rightvt == VT_BOOL ||
7313 rightvt == VT_I2)) || (rightvt == VT_R4 &&
7314 (leftvt == VT_BOOL || leftvt == VT_I2)))
7315 resvt = VT_R4;
7316 else
7317 resvt = VT_R8;
7319 else if (leftvt == VT_R4 || rightvt == VT_R4)
7320 resvt = VT_R4;
7322 else if (leftvt == VT_NULL && rightvt == VT_EMPTY)
7323 resvt = VT_NULL;
7324 else
7325 bFail = TRUE;
7327 /* Native VarDiv always returns an error when using extra flags */
7328 if (ExtraFlags[i] != 0)
7329 bFail = TRUE;
7331 hres = pVarDiv(&left, &right, &result);
7333 /* Check expected HRESULT and if result variant type is correct */
7334 if (bFail)
7335 ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH ||
7336 hres == DISP_E_OVERFLOW || hres == DISP_E_DIVBYZERO,
7337 "VarDiv: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
7338 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
7339 vtstr(V_VT(&result)), hres);
7340 else
7341 ok (hres == S_OK && resvt == V_VT(&result),
7342 "VarDiv: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
7343 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
7344 S_OK, vtstr(V_VT(&result)), hres);
7349 /* Test return values for all the good cases */
7350 VARDIV(EMPTY,0,NULL,0,NULL,0);
7351 VARDIV(EMPTY,0,I2,2,R8,0.0);
7352 VARDIV(EMPTY,0,I4,2,R8,0.0);
7353 VARDIV(EMPTY,0,R4,2.0f,R4,0.0f);
7354 VARDIV(EMPTY,0,R8,2.0,R8,0.0);
7355 VARDIV(EMPTY,0,DATE,2.0,R8,0.0);
7356 VARDIV(EMPTY,0,BSTR,num2_str,R8,0.0);
7357 VARDIV(EMPTY,0,BOOL,VARIANT_TRUE,R8,0.0);
7358 VARDIV(EMPTY,0,UI1,2,R8,0.0);
7359 if (HAVE_OLEAUT32_I8)
7361 VARDIV(EMPTY,0,I8,2,R8,0.0);
7363 VARDIV(NULL,0,EMPTY,0,NULL,0);
7364 VARDIV(NULL,0,NULL,0,NULL,0);
7365 VARDIV(NULL,0,I2,2,NULL,0);
7366 VARDIV(NULL,0,I4,2,NULL,0);
7367 VARDIV(NULL,0,R4,2.0f,NULL,0);
7368 VARDIV(NULL,0,R8,2.0,NULL,0);
7369 VARDIV(NULL,0,DATE,2,NULL,0);
7370 VARDIV(NULL,0,BSTR,num2_str,NULL,0);
7371 VARDIV(NULL,0,BOOL,VARIANT_TRUE,NULL,0);
7372 VARDIV(NULL,0,UI1,2,NULL,0);
7373 if (HAVE_OLEAUT32_I8)
7375 VARDIV(NULL,0,I8,2,NULL,0);
7377 VARDIV(I2,2,NULL,0,NULL,0);
7378 VARDIV(I2,1,I2,2,R8,0.5);
7379 VARDIV(I2,1,I4,2,R8,0.5);
7380 VARDIV(I2,1,R4,2,R4,0.5f);
7381 VARDIV(I2,1,R8,2.0,R8,0.5);
7382 VARDIV(I2,1,DATE,2,R8,0.5);
7383 VARDIV(I2,1,BOOL,VARIANT_TRUE,R8,-1.0);
7384 VARDIV(I2,1,UI1,2,R8,0.5);
7385 if (HAVE_OLEAUT32_I8)
7387 VARDIV(I2,1,I8,2,R8,0.5);
7389 VARDIV(I4,1,NULL,0,NULL,0);
7390 VARDIV(I4,1,I2,2,R8,0.5);
7391 VARDIV(I4,1,I4,2,R8,0.5);
7392 VARDIV(I4,1,R4,2.0f,R8,0.5);
7393 VARDIV(I4,1,R8,2.0,R8,0.5);
7394 VARDIV(I4,1,DATE,2,R8,0.5);
7395 VARDIV(I4,1,BSTR,num2_str,R8,0.5);
7396 VARDIV(I4,1,BOOL,VARIANT_TRUE,R8,-1.0);
7397 VARDIV(I4,1,UI1,2,R8,0.5);
7398 if (HAVE_OLEAUT32_I8)
7400 VARDIV(I4,1,I8,2,R8,0.5);
7402 VARDIV(R4,1.0f,NULL,0,NULL,0);
7403 VARDIV(R4,1.0f,I2,2,R4,0.5f);
7404 VARDIV(R4,1.0f,I4,2,R8,0.5);
7405 VARDIV(R4,1.0f,R4,2.0f,R4,0.5f);
7406 VARDIV(R4,1.0f,R8,2.0,R8,0.5);
7407 VARDIV(R4,1.0f,DATE,2,R8,0.5);
7408 VARDIV(R4,1.0f,BSTR,num2_str,R8,0.5);
7409 VARDIV(R4,1.0f,BOOL,VARIANT_TRUE,R4,-1);
7410 VARDIV(R4,1.0f,UI1,2,R4,0.5f);
7411 if (HAVE_OLEAUT32_I8)
7413 VARDIV(R4,1.0f,I8,2,R8,0.5);
7415 VARDIV(R8,1.0,NULL,0,NULL,0);
7416 VARDIV(R8,1.0,I2,2,R8,0.5);
7417 VARDIV(R8,1.0,I4,2,R8,0.5);
7418 VARDIV(R8,1.0,R4,2.0f,R8,0.5);
7419 VARDIV(R8,1.0,R8,2.0,R8,0.5);
7420 VARDIV(R8,1.0,DATE,2,R8,0.5);
7421 VARDIV(R8,1.0,BSTR,num2_str,R8,0.5);
7422 VARDIV(R8,1.0,BOOL,VARIANT_TRUE,R8,-1.0);
7423 VARDIV(R8,1.0,UI1,2,R8,0.5);
7424 if (HAVE_OLEAUT32_I8)
7426 VARDIV(R8,1.0,I8,2,R8,0.5);
7428 VARDIV(DATE,1,NULL,0,NULL,0);
7429 VARDIV(DATE,1,I2,2,R8,0.5);
7430 VARDIV(DATE,1,I4,2,R8,0.5);
7431 VARDIV(DATE,1,R4,2.0f,R8,0.5);
7432 VARDIV(DATE,1,R8,2.0,R8,0.5);
7433 VARDIV(DATE,1,DATE,2,R8,0.5);
7434 VARDIV(DATE,1,BSTR,num2_str,R8,0.5);
7435 VARDIV(DATE,1,BOOL,VARIANT_TRUE,R8,-1.0);
7436 VARDIV(DATE,1,UI1,2,R8,0.5);
7437 if (HAVE_OLEAUT32_I8)
7439 VARDIV(DATE,1,I8,2,R8,0.5);
7441 VARDIV(BSTR,num1_str,NULL,0,NULL,0);
7442 VARDIV(BSTR,num1_str,I2,2,R8,0.5);
7443 VARDIV(BSTR,num1_str,I4,2,R8,0.5);
7444 VARDIV(BSTR,num1_str,R4,2.0f,R8,0.5);
7445 VARDIV(BSTR,num1_str,R8,2.0,R8,0.5);
7446 VARDIV(BSTR,num1_str,DATE,2,R8,0.5);
7447 VARDIV(BSTR,num1_str,BSTR,num2_str,R8,0.5);
7448 VARDIV(BSTR,num1_str,BOOL,VARIANT_TRUE,R8,-1);
7449 VARDIV(BSTR,num1_str,UI1,2,R8,0.5);
7450 if (HAVE_OLEAUT32_I8)
7452 VARDIV(BSTR,num1_str,I8,2,R8,0.5);
7454 VARDIV(BOOL,VARIANT_TRUE,NULL,0,NULL,0);
7455 VARDIV(BOOL,VARIANT_TRUE,I2,1,R8,-1.0);
7456 VARDIV(BOOL,VARIANT_FALSE,I2,1,R8,0.0);
7457 VARDIV(BOOL,VARIANT_TRUE,I4,1,R8,-1.0);
7458 VARDIV(BOOL,VARIANT_FALSE,I4,1,R8,0.0);
7459 VARDIV(BOOL,VARIANT_TRUE,R4,1,R4,-1.0f);
7460 VARDIV(BOOL,VARIANT_FALSE,R4,1,R4,0.0f);
7461 VARDIV(BOOL,VARIANT_TRUE,R8,1.0,R8,-1.0);
7462 VARDIV(BOOL,VARIANT_FALSE,R8,1.0,R8,0.0);
7463 VARDIV(BOOL,VARIANT_FALSE,DATE,2,R8,0.0);
7464 VARDIV(BOOL,VARIANT_FALSE,BSTR,num2_str,R8,0.0);
7465 VARDIV(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,R8,1.0);
7466 VARDIV(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,R8,0.0);
7467 VARDIV(BOOL,VARIANT_TRUE,UI1,1,R8,-1.0);
7468 if (HAVE_OLEAUT32_I8)
7470 VARDIV(BOOL,VARIANT_TRUE,I8,1,R8,-1.0);
7472 VARDIV(UI1,1,NULL,0,NULL,0);
7473 VARDIV(UI1,1,I2,2,R8,0.5);
7474 VARDIV(UI1,1,I4,2,R8,0.5);
7475 VARDIV(UI1,1,R4,2.0f,R4,0.5f);
7476 VARDIV(UI1,1,R8,2.0,R8,0.5);
7477 VARDIV(UI1,1,DATE,2,R8,0.5);
7478 VARDIV(UI1,1,BSTR,num2_str,R8,0.5);
7479 VARDIV(UI1,1,BOOL,VARIANT_TRUE,R8,-1);
7480 VARDIV(UI1,1,UI1,2,R8,0.5);
7481 if (HAVE_OLEAUT32_I8)
7483 VARDIV(UI1,1,I8,2,R8,0.5);
7484 VARDIV(I8,1,NULL,0,NULL,0);
7485 VARDIV(I8,1,I2,2,R8,0.5);
7486 VARDIV(I8,1,I4,2,R8,0.5);
7487 VARDIV(I8,1,R4,2.0f,R8,0.5);
7488 VARDIV(I8,1,R8,2.0,R8,0.5);
7489 VARDIV(I8,1,DATE,2,R8,0.5);
7490 VARDIV(I8,1,BSTR,num2_str,R8,0.5);
7491 VARDIV(I8,1,BOOL,VARIANT_TRUE,R8,-1);
7492 VARDIV(I8,1,UI1,2,R8,0.5);
7493 VARDIV(I8,1,I8,2,R8,0.5);
7496 /* Manually test some VT_CY, VT_DECIMAL variants */
7497 V_VT(&cy) = VT_CY;
7498 hres = VarCyFromI4(10000, &V_CY(&cy));
7499 ok(hres == S_OK, "VarCyFromI4 failed!\n");
7500 V_VT(&dec) = VT_DECIMAL;
7501 hres = VarDecFromR8(2.0, &V_DECIMAL(&dec));
7502 ok(hres == S_OK, "VarDecFromR4 failed!\n");
7503 memset(&left, 0, sizeof(left));
7504 memset(&right, 0, sizeof(right));
7505 V_VT(&left) = VT_I4;
7506 V_I4(&left) = 100;
7507 V_VT(&right) = VT_UI1;
7508 V_UI1(&right) = 2;
7510 hres = pVarDiv(&cy, &cy, &result);
7511 ok(hres == S_OK && V_VT(&result) == VT_R8,
7512 "VARDIV: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
7513 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 1.0),
7514 "VARDIV: CY value %f, expected %f\n", V_R8(&result), (double)1.0);
7516 hres = pVarDiv(&cy, &right, &result);
7517 ok(hres == S_OK && V_VT(&result) == VT_R8,
7518 "VARDIV: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
7519 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 5000.0),
7520 "VARDIV: CY value %f, expected %f\n", V_R8(&result), (double)5000.0);
7522 hres = pVarDiv(&left, &cy, &result);
7523 ok(hres == S_OK && V_VT(&result) == VT_R8,
7524 "VARDIV: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
7525 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 0.01),
7526 "VARDIV: CY value %f, expected %f\n", V_R8(&result), (double)0.01);
7528 hres = pVarDiv(&left, &dec, &result);
7529 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
7530 "VARDIV: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
7531 hres = VarR8FromDec(&V_DECIMAL(&result), &r);
7532 ok(hres == S_OK && EQ_DOUBLE(r, 50.0),
7533 "VARDIV: DECIMAL value %f, expected %f\n", r, (double)50.0);
7535 hres = pVarDiv(&dec, &dec, &result);
7536 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
7537 "VARDIV: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
7538 hres = VarR8FromDec(&V_DECIMAL(&result), &r);
7539 ok(hres == S_OK && EQ_DOUBLE(r, 1.0),
7540 "VARDIV: DECIMAL value %f, expected %f\n", r, (double)1.0);
7542 hres = pVarDiv(&dec, &right, &result);
7543 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
7544 "VARDIV: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
7545 hres = VarR8FromDec(&V_DECIMAL(&result), &r);
7546 ok(hres == S_OK && EQ_DOUBLE(r, 1.0),
7547 "VARDIV: DECIMAL value %f, expected %f\n", r, (double)1.0);
7549 /* Check for division by zero and overflow */
7550 V_VT(&left) = VT_R8;
7551 V_I4(&left) = 1;
7552 V_VT(&right) = VT_R8;
7553 V_I4(&right) = 0;
7554 hres = pVarDiv(&left, &right, &result);
7555 ok(hres == DISP_E_DIVBYZERO && V_VT(&result) == VT_EMPTY,
7556 "VARDIV: Division by (1.0/0.0) should result in DISP_E_DIVBYZERO but got 0x%X\n", hres);
7558 V_VT(&left) = VT_R8;
7559 V_I4(&left) = 0;
7560 V_VT(&right) = VT_R8;
7561 V_I4(&right) = 0;
7562 hres = pVarDiv(&left, &right, &result);
7563 ok(hres == DISP_E_OVERFLOW && V_VT(&result) == VT_EMPTY,
7564 "VARDIV: Division by (0.0/0.0) should result in DISP_E_OVERFLOW but got 0x%X\n", hres);
7566 SysFreeString(num1_str);
7567 SysFreeString(num2_str);
7570 static HRESULT (WINAPI *pVarIdiv)(LPVARIANT,LPVARIANT,LPVARIANT);
7572 #define VARIDIV(vt1,val1,vt2,val2,rvt,rval) \
7573 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
7574 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
7575 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
7576 test_var_call2( __LINE__, pVarIdiv, &left, &right, &exp )
7578 /* Skip any type that is not defined or produces an error for every case */
7579 #define SKIPTESTIDIV(a) \
7580 if (a == VT_ERROR || a == VT_VARIANT || \
7581 a == VT_DISPATCH || a == VT_UNKNOWN || \
7582 a == VT_RECORD || a > VT_UINT || \
7583 a == 15 /*not defined*/) \
7584 continue
7586 static void test_VarIdiv(void)
7588 static const WCHAR str1[] = { '1','\0' };
7589 static const WCHAR str2[] = { '2','\0' };
7590 VARIANT left, right, exp, result, cy, dec;
7591 BSTR num1_str, num2_str;
7592 VARTYPE i;
7593 HRESULT hres;
7595 CHECKPTR(VarIdiv);
7597 num1_str = SysAllocString(str1);
7598 num2_str = SysAllocString(str2);
7600 /* Test all possible flag/vt combinations & the resulting vt type */
7601 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
7603 VARTYPE leftvt, rightvt, resvt;
7605 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
7607 SKIPTESTIDIV(leftvt);
7609 /* Check if we need/have support for I8 and/or UI8 */
7610 if ((leftvt == VT_I8 || leftvt == VT_UI8) && !HAVE_OLEAUT32_I8)
7611 continue;
7613 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
7615 BOOL bFail = FALSE;
7616 SKIPTESTIDIV(rightvt);
7618 /* Native crashes with extra flag VT_BYREF */
7619 if (ExtraFlags[i] == VT_BYREF)
7620 continue;
7622 /* Check if we need/have support for I8 and/or UI8 */
7623 if ((rightvt == VT_I8 || rightvt == VT_UI8) && !HAVE_OLEAUT32_I8)
7624 continue;
7626 memset(&left, 0, sizeof(left));
7627 memset(&right, 0, sizeof(right));
7628 V_VT(&left) = leftvt | ExtraFlags[i];
7629 V_VT(&right) = rightvt | ExtraFlags[i];
7630 V_VT(&result) = VT_EMPTY;
7631 resvt = VT_EMPTY;
7633 if (leftvt == VT_BSTR)
7634 V_BSTR(&left) = num2_str;
7635 else if (leftvt == VT_DECIMAL)
7637 VarDecFromR8(2.0, &V_DECIMAL(&left));
7638 V_VT(&left) = leftvt | ExtraFlags[i];
7641 /* Division by 0 is undefined */
7642 switch(rightvt)
7644 case VT_BSTR:
7645 V_BSTR(&right) = num2_str;
7646 break;
7647 case VT_DECIMAL:
7648 VarDecFromR8(2.0, &V_DECIMAL(&right));
7649 V_VT(&right) = rightvt | ExtraFlags[i];
7650 break;
7651 case VT_BOOL:
7652 V_BOOL(&right) = VARIANT_TRUE;
7653 break;
7654 case VT_CY:
7655 VarCyFromI4(10000, &V_CY(&right));
7656 V_VT(&right) = rightvt | ExtraFlags[i];
7657 break;
7658 case VT_I2: V_I2(&right) = 2; break;
7659 case VT_I4: V_I4(&right) = 2; break;
7660 case VT_R4: V_R4(&right) = 2.0f; break;
7661 case VT_R8: V_R8(&right) = 2.0; break;
7662 case VT_DATE: V_DATE(&right) = 2; break;
7663 case VT_I1: V_I1(&right) = 2; break;
7664 case VT_UI1: V_UI1(&right) = 2; break;
7665 case VT_UI2: V_UI2(&right) = 2; break;
7666 case VT_UI4: V_UI4(&right) = 2; break;
7667 case VT_I8: V_I8(&right) = 2; break;
7668 case VT_UI8: V_UI8(&right) = 2; break;
7669 case VT_INT: V_INT(&right) = 2; break;
7670 case VT_UINT: V_UINT(&right) = 2; break;
7671 default: break;
7674 /* Native VarIdiv always returns an error when using extra
7675 * flags or if the variant combination is I8 and INT.
7677 if ((leftvt == VT_I8 && rightvt == VT_INT) ||
7678 (leftvt == VT_INT && rightvt == VT_I8) ||
7679 (rightvt == VT_EMPTY && leftvt != VT_NULL) ||
7680 ExtraFlags[i] != 0)
7681 bFail = TRUE;
7683 /* Determine variant type */
7684 else if (leftvt == VT_NULL || rightvt == VT_NULL)
7685 resvt = VT_NULL;
7686 else if (leftvt == VT_I8 || rightvt == VT_I8)
7687 resvt = VT_I8;
7688 else if (leftvt == VT_I4 || rightvt == VT_I4 ||
7689 leftvt == VT_INT || rightvt == VT_INT ||
7690 leftvt == VT_UINT || rightvt == VT_UINT ||
7691 leftvt == VT_UI8 || rightvt == VT_UI8 ||
7692 leftvt == VT_UI4 || rightvt == VT_UI4 ||
7693 leftvt == VT_UI2 || rightvt == VT_UI2 ||
7694 leftvt == VT_I1 || rightvt == VT_I1 ||
7695 leftvt == VT_BSTR || rightvt == VT_BSTR ||
7696 leftvt == VT_DATE || rightvt == VT_DATE ||
7697 leftvt == VT_CY || rightvt == VT_CY ||
7698 leftvt == VT_DECIMAL || rightvt == VT_DECIMAL ||
7699 leftvt == VT_R8 || rightvt == VT_R8 ||
7700 leftvt == VT_R4 || rightvt == VT_R4)
7701 resvt = VT_I4;
7702 else if (leftvt == VT_I2 || rightvt == VT_I2 ||
7703 leftvt == VT_BOOL || rightvt == VT_BOOL ||
7704 leftvt == VT_EMPTY)
7705 resvt = VT_I2;
7706 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
7707 resvt = VT_UI1;
7708 else
7709 bFail = TRUE;
7711 hres = pVarIdiv(&left, &right, &result);
7713 /* Check expected HRESULT and if result variant type is correct */
7714 if (bFail)
7715 ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH ||
7716 hres == DISP_E_DIVBYZERO,
7717 "VarIdiv: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
7718 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
7719 vtstr(V_VT(&result)), hres);
7720 else
7721 ok (hres == S_OK && resvt == V_VT(&result),
7722 "VarIdiv: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
7723 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
7724 S_OK, vtstr(V_VT(&result)), hres);
7729 /* Test return values for all the good cases */
7730 VARIDIV(EMPTY,0,NULL,0,NULL,0);
7731 VARIDIV(EMPTY,0,I2,1,I2,0);
7732 VARIDIV(EMPTY,0,I4,1,I4,0);
7733 VARIDIV(EMPTY,0,R4,1.0f,I4,0);
7734 VARIDIV(EMPTY,0,R8,1.0,I4,0);
7735 VARIDIV(EMPTY,0,DATE,1.0,I4,0);
7736 VARIDIV(EMPTY,0,BSTR,num1_str,I4,0);
7737 VARIDIV(EMPTY,0,BOOL,VARIANT_TRUE,I2,0);
7738 VARIDIV(EMPTY,0,I1,1,I4,0);
7739 VARIDIV(EMPTY,0,UI1,1,I2,0);
7740 VARIDIV(EMPTY,0,UI2,1,I4,0);
7741 VARIDIV(EMPTY,0,UI4,1,I4,0);
7742 if (HAVE_OLEAUT32_I8)
7744 VARIDIV(EMPTY,0,I8,1,I8,0);
7745 VARIDIV(EMPTY,0,UI8,1,I4,0);
7747 VARIDIV(EMPTY,0,INT,1,I4,0);
7748 VARIDIV(EMPTY,0,UINT,1,I4,0);
7749 VARIDIV(NULL,0,EMPTY,0,NULL,0);
7750 VARIDIV(NULL,0,NULL,0,NULL,0);
7751 VARIDIV(NULL,0,I2,1,NULL,0);
7752 VARIDIV(NULL,0,I4,1,NULL,0);
7753 VARIDIV(NULL,0,R4,1,NULL,0);
7754 VARIDIV(NULL,0,R8,1,NULL,0);
7755 VARIDIV(NULL,0,DATE,1,NULL,0);
7756 VARIDIV(NULL,0,BSTR,num1_str,NULL,0);
7757 VARIDIV(NULL,0,BOOL,VARIANT_TRUE,NULL,0);
7758 VARIDIV(NULL,0,I1,1,NULL,0);
7759 VARIDIV(NULL,0,UI1,1,NULL,0);
7760 VARIDIV(NULL,0,UI2,1,NULL,0);
7761 VARIDIV(NULL,0,UI4,1,NULL,0);
7762 if (HAVE_OLEAUT32_I8)
7764 VARIDIV(NULL,0,I8,1,NULL,0);
7765 VARIDIV(NULL,0,UI8,1,NULL,0);
7767 VARIDIV(NULL,0,INT,1,NULL,0);
7768 VARIDIV(NULL,0,UINT,1,NULL,0);
7769 VARIDIV(I2,2,NULL,0,NULL,0);
7770 VARIDIV(I2,2,I2,1,I2,2);
7771 VARIDIV(I2,2,I4,1,I4,2);
7772 VARIDIV(I2,2,R4,1,I4,2);
7773 VARIDIV(I2,2,R8,1,I4,2);
7774 VARIDIV(I2,2,DATE,1,I4,2);
7775 VARIDIV(I2,2,BSTR,num1_str,I4,2);
7776 VARIDIV(I2,2,BOOL,VARIANT_TRUE,I2,-2);
7777 VARIDIV(I2,2,I1,1,I4,2);
7778 VARIDIV(I2,2,UI1,1,I2,2);
7779 VARIDIV(I2,2,UI2,1,I4,2);
7780 VARIDIV(I2,2,UI4,1,I4,2);
7781 if (HAVE_OLEAUT32_I8)
7783 VARIDIV(I2,2,I8,1,I8,2);
7784 VARIDIV(I2,2,UI8,1,I4,2);
7786 VARIDIV(I2,2,INT,1,I4,2);
7787 VARIDIV(I2,2,UINT,1,I4,2);
7788 VARIDIV(I4,2,NULL,0,NULL,0);
7789 VARIDIV(I4,2,I2,1,I4,2);
7790 VARIDIV(I4,2,I4,1,I4,2);
7791 VARIDIV(I4,2,R4,1,I4,2);
7792 VARIDIV(I4,2,R8,1,I4,2);
7793 VARIDIV(I4,2,DATE,1,I4,2);
7794 VARIDIV(I4,2,BSTR,num1_str,I4,2);
7795 VARIDIV(I4,2,BOOL,VARIANT_TRUE,I4,-2);
7796 VARIDIV(I4,2,I1,1,I4,2);
7797 VARIDIV(I4,2,UI1,1,I4,2);
7798 VARIDIV(I4,2,UI2,1,I4,2);
7799 VARIDIV(I4,2,UI4,1,I4,2);
7800 if (HAVE_OLEAUT32_I8)
7802 VARIDIV(I4,2,I8,1,I8,2);
7803 VARIDIV(I4,2,UI8,1,I4,2);
7805 VARIDIV(I4,2,INT,1,I4,2);
7806 VARIDIV(I4,2,UINT,1,I4,2);
7807 VARIDIV(R4,2.0f,NULL,0,NULL,0);
7808 VARIDIV(R4,2.0f,I2,1,I4,2);
7809 VARIDIV(R4,2.0f,I4,1,I4,2);
7810 VARIDIV(R4,2.0f,R4,1.0f,I4,2);
7811 VARIDIV(R4,2.0f,R8,1.0,I4,2);
7812 VARIDIV(R4,2.0f,DATE,1,I4,2);
7813 VARIDIV(R4,2.0f,BSTR,num1_str,I4,2);
7814 VARIDIV(R4,2.0f,BOOL,VARIANT_TRUE,I4,-2);
7815 VARIDIV(R4,2.0f,I1,1,I4,2);
7816 VARIDIV(R4,2.0f,UI1,1,I4,2);
7817 VARIDIV(R4,2.0f,UI2,1,I4,2);
7818 VARIDIV(R4,2.0f,UI4,1,I4,2);
7819 if (HAVE_OLEAUT32_I8)
7821 VARIDIV(R4,2.0f,I8,1,I8,2);
7822 VARIDIV(R4,2.0f,UI8,1,I4,2);
7824 VARIDIV(R4,2.0f,INT,1,I4,2);
7825 VARIDIV(R4,2.0f,UINT,1,I4,2);
7826 VARIDIV(R8,2.0,NULL,0,NULL,0);
7827 VARIDIV(R8,2.0,I2,1,I4,2);
7828 VARIDIV(R8,2.0,I4,1,I4,2);
7829 VARIDIV(R8,2.0,R4,1,I4,2);
7830 VARIDIV(R8,2.0,R8,1,I4,2);
7831 VARIDIV(R8,2.0,DATE,1,I4,2);
7832 VARIDIV(R8,2.0,BSTR,num1_str,I4,2);
7833 VARIDIV(R8,2.0,BOOL,VARIANT_TRUE,I4,-2);
7834 VARIDIV(R8,2.0,I1,1,I4,2);
7835 VARIDIV(R8,2.0,UI1,1,I4,2);
7836 VARIDIV(R8,2.0,UI2,1,I4,2);
7837 VARIDIV(R8,2.0,UI4,1,I4,2);
7838 if (HAVE_OLEAUT32_I8)
7840 VARIDIV(R8,2.0,I8,1,I8,2);
7841 VARIDIV(R8,2.0,UI8,1,I4,2);
7843 VARIDIV(R8,2.0,INT,1,I4,2);
7844 VARIDIV(R8,2.0,UINT,1,I4,2);
7845 VARIDIV(DATE,2,NULL,0,NULL,0);
7846 VARIDIV(DATE,2,I2,1,I4,2);
7847 VARIDIV(DATE,2,I4,1,I4,2);
7848 VARIDIV(DATE,2,R4,1,I4,2);
7849 VARIDIV(DATE,2,R8,1,I4,2);
7850 VARIDIV(DATE,2,DATE,1,I4,2);
7851 VARIDIV(DATE,2,BSTR,num1_str,I4,2);
7852 VARIDIV(DATE,2,BOOL,VARIANT_TRUE,I4,-2);
7853 VARIDIV(DATE,2,I1,1,I4,2);
7854 VARIDIV(DATE,2,UI1,1,I4,2);
7855 VARIDIV(DATE,2,UI2,1,I4,2);
7856 VARIDIV(DATE,2,UI4,1,I4,2);
7857 if (HAVE_OLEAUT32_I8)
7859 VARIDIV(DATE,2,I8,1,I8,2);
7860 VARIDIV(DATE,2,UI8,1,I4,2);
7862 VARIDIV(DATE,2,INT,1,I4,2);
7863 VARIDIV(DATE,2,UINT,1,I4,2);
7864 VARIDIV(BSTR,num2_str,NULL,0,NULL,0);
7865 VARIDIV(BSTR,num2_str,I2,1,I4,2);
7866 VARIDIV(BSTR,num2_str,I4,1,I4,2);
7867 VARIDIV(BSTR,num2_str,R4,1.0f,I4,2);
7868 VARIDIV(BSTR,num2_str,R8,1.0,I4,2);
7869 VARIDIV(BSTR,num2_str,DATE,1,I4,2);
7870 VARIDIV(BSTR,num2_str,BSTR,num1_str,I4,2);
7871 VARIDIV(BSTR,num2_str,BOOL,VARIANT_TRUE,I4,-2);
7872 VARIDIV(BSTR,num2_str,I1,1,I4,2);
7873 VARIDIV(BSTR,num2_str,UI1,1,I4,2);
7874 VARIDIV(BSTR,num2_str,UI2,1,I4,2);
7875 VARIDIV(BSTR,num2_str,UI4,1,I4,2);
7876 if (HAVE_OLEAUT32_I8)
7878 VARIDIV(BSTR,num2_str,I8,1,I8,2);
7879 VARIDIV(BSTR,num2_str,UI8,1,I4,2);
7881 VARIDIV(BSTR,num2_str,INT,1,I4,2);
7882 VARIDIV(BSTR,num2_str,UINT,1,I4,2);
7883 VARIDIV(BOOL,VARIANT_TRUE,NULL,0,NULL,0);
7884 VARIDIV(BOOL,VARIANT_TRUE,I2,1,I2,-1);
7885 VARIDIV(BOOL,VARIANT_TRUE,I4,1,I4,-1);
7886 VARIDIV(BOOL,VARIANT_TRUE,R4,1.0f,I4,-1);
7887 VARIDIV(BOOL,VARIANT_TRUE,R8,1.0,I4,-1);
7888 VARIDIV(BOOL,VARIANT_TRUE,DATE,1,I4,-1);
7889 VARIDIV(BOOL,VARIANT_TRUE,BSTR,num1_str,I4,-1);
7890 VARIDIV(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,I2,1);
7891 VARIDIV(BOOL,VARIANT_TRUE,I1,1,I4,-1);
7892 VARIDIV(BOOL,VARIANT_TRUE,UI1,1,I2,-1);
7893 VARIDIV(BOOL,VARIANT_TRUE,UI2,1,I4,-1);
7894 VARIDIV(BOOL,VARIANT_TRUE,UI4,1,I4,-1);
7895 if (HAVE_OLEAUT32_I8)
7897 VARIDIV(BOOL,VARIANT_TRUE,I8,1,I8,-1);
7898 VARIDIV(BOOL,VARIANT_TRUE,UI8,1,I4,-1);
7900 VARIDIV(BOOL,VARIANT_TRUE,INT,1,I4,-1);
7901 VARIDIV(BOOL,VARIANT_TRUE,UINT,1,I4,-1);
7902 VARIDIV(I1,2,NULL,0,NULL,0);
7903 VARIDIV(I1,2,I2,1,I4,2);
7904 VARIDIV(I1,2,I4,1,I4,2);
7905 VARIDIV(I1,2,R4,1.0f,I4,2);
7906 VARIDIV(I1,2,R8,1.0,I4,2);
7907 VARIDIV(I1,2,DATE,1,I4,2);
7908 VARIDIV(I1,2,BSTR,num1_str,I4,2);
7909 VARIDIV(I1,2,BOOL,VARIANT_TRUE,I4,-2);
7910 VARIDIV(I1,2,I1,1,I4,2);
7911 VARIDIV(I1,2,UI1,1,I4,2);
7912 VARIDIV(I1,2,UI2,1,I4,2);
7913 VARIDIV(I1,2,UI4,1,I4,2);
7914 if (HAVE_OLEAUT32_I8)
7916 VARIDIV(I1,2,I8,1,I8,2);
7917 VARIDIV(I1,2,UI8,1,I4,2);
7919 VARIDIV(I1,2,INT,1,I4,2);
7920 VARIDIV(I1,2,UINT,1,I4,2);
7921 VARIDIV(UI1,2,NULL,0,NULL,0);
7922 VARIDIV(UI1,2,I2,1,I2,2);
7923 VARIDIV(UI1,2,I4,1,I4,2);
7924 VARIDIV(UI1,2,R4,1.0f,I4,2);
7925 VARIDIV(UI1,2,R8,1.0,I4,2);
7926 VARIDIV(UI1,2,DATE,1,I4,2);
7927 VARIDIV(UI1,2,BSTR,num1_str,I4,2);
7928 VARIDIV(UI1,2,BOOL,VARIANT_TRUE,I2,-2);
7929 VARIDIV(UI1,2,I1,1,I4,2);
7930 VARIDIV(UI1,2,UI1,1,UI1,2);
7931 VARIDIV(UI1,2,UI2,1,I4,2);
7932 VARIDIV(UI1,2,UI4,1,I4,2);
7933 if (HAVE_OLEAUT32_I8)
7935 VARIDIV(UI1,2,I8,1,I8,2);
7936 VARIDIV(UI1,2,UI8,1,I4,2);
7938 VARIDIV(UI1,2,INT,1,I4,2);
7939 VARIDIV(UI1,2,UINT,1,I4,2);
7940 VARIDIV(UI2,2,NULL,0,NULL,0);
7941 VARIDIV(UI2,2,I2,1,I4,2);
7942 VARIDIV(UI2,2,I4,1,I4,2);
7943 VARIDIV(UI2,2,R4,1.0f,I4,2);
7944 VARIDIV(UI2,2,R8,1.0,I4,2);
7945 VARIDIV(UI2,2,DATE,1,I4,2);
7946 VARIDIV(UI2,2,BSTR,num1_str,I4,2);
7947 VARIDIV(UI2,2,BOOL,VARIANT_TRUE,I4,-2);
7948 VARIDIV(UI2,2,I1,1,I4,2);
7949 VARIDIV(UI2,2,UI1,1,I4,2);
7950 VARIDIV(UI2,2,UI2,1,I4,2);
7951 VARIDIV(UI2,2,UI4,1,I4,2);
7952 if (HAVE_OLEAUT32_I8)
7954 VARIDIV(UI2,2,I8,1,I8,2);
7955 VARIDIV(UI2,2,UI8,1,I4,2);
7957 VARIDIV(UI2,2,INT,1,I4,2);
7958 VARIDIV(UI2,2,UINT,1,I4,2);
7959 VARIDIV(UI4,2,NULL,0,NULL,0);
7960 VARIDIV(UI4,2,I2,1,I4,2);
7961 VARIDIV(UI4,2,I4,1,I4,2);
7962 VARIDIV(UI4,2,R4,1.0f,I4,2);
7963 VARIDIV(UI4,2,R8,1.0,I4,2);
7964 VARIDIV(UI4,2,DATE,1,I4,2);
7965 VARIDIV(UI4,2,BSTR,num1_str,I4,2);
7966 VARIDIV(UI4,2,BOOL,VARIANT_TRUE,I4,-2);
7967 VARIDIV(UI4,2,I1,1,I4,2);
7968 VARIDIV(UI4,2,UI1,1,I4,2);
7969 VARIDIV(UI4,2,UI2,1,I4,2);
7970 VARIDIV(UI4,2,UI4,1,I4,2);
7971 if (HAVE_OLEAUT32_I8)
7973 VARIDIV(UI4,2,I8,1,I8,2);
7974 VARIDIV(UI4,2,UI8,1,I4,2);
7976 VARIDIV(UI4,2,INT,1,I4,2);
7977 VARIDIV(UI4,2,UINT,1,I4,2);
7978 if (HAVE_OLEAUT32_I8)
7980 VARIDIV(I8,2,NULL,0,NULL,0);
7981 VARIDIV(I8,2,I2,1,I8,2);
7982 VARIDIV(I8,2,I4,1,I8,2);
7983 VARIDIV(I8,2,R4,1.0f,I8,2);
7984 VARIDIV(I8,2,R8,1.0,I8,2);
7985 VARIDIV(I8,2,DATE,1,I8,2);
7986 VARIDIV(I8,2,BSTR,num1_str,I8,2);
7987 VARIDIV(I8,2,BOOL,1,I8,2);
7988 VARIDIV(I8,2,I1,1,I8,2);
7989 VARIDIV(I8,2,UI1,1,I8,2);
7990 VARIDIV(I8,2,UI2,1,I8,2);
7991 VARIDIV(I8,2,UI4,1,I8,2);
7992 VARIDIV(I8,2,I8,1,I8,2);
7993 VARIDIV(I8,2,UI8,1,I8,2);
7994 VARIDIV(I8,2,UINT,1,I8,2);
7995 VARIDIV(UI8,2,NULL,0,NULL,0);
7996 VARIDIV(UI8,2,I2,1,I4,2);
7997 VARIDIV(UI8,2,I4,1,I4,2);
7998 VARIDIV(UI8,2,R4,1.0f,I4,2);
7999 VARIDIV(UI8,2,R8,1.0,I4,2);
8000 VARIDIV(UI8,2,DATE,1,I4,2);
8001 VARIDIV(UI8,2,BSTR,num1_str,I4,2);
8002 VARIDIV(UI8,2,BOOL,VARIANT_TRUE,I4,-2);
8003 VARIDIV(UI8,2,I1,1,I4,2);
8004 VARIDIV(UI8,2,UI1,1,I4,2);
8005 VARIDIV(UI8,2,UI2,1,I4,2);
8006 VARIDIV(UI8,2,UI4,1,I4,2);
8007 VARIDIV(UI8,2,I8,1,I8,2);
8008 VARIDIV(UI8,2,UI8,1,I4,2);
8009 VARIDIV(UI8,2,INT,1,I4,2);
8010 VARIDIV(UI8,2,UINT,1,I4,2);
8012 VARIDIV(INT,2,NULL,0,NULL,0);
8013 VARIDIV(INT,2,I2,1,I4,2);
8014 VARIDIV(INT,2,I4,1,I4,2);
8015 VARIDIV(INT,2,R4,1.0f,I4,2);
8016 VARIDIV(INT,2,R8,1.0,I4,2);
8017 VARIDIV(INT,2,DATE,1,I4,2);
8018 VARIDIV(INT,2,BSTR,num1_str,I4,2);
8019 VARIDIV(INT,2,BOOL,VARIANT_TRUE,I4,-2);
8020 VARIDIV(INT,2,I1,1,I4,2);
8021 VARIDIV(INT,2,UI1,1,I4,2);
8022 VARIDIV(INT,2,UI2,1,I4,2);
8023 VARIDIV(INT,2,UI4,1,I4,2);
8024 if (HAVE_OLEAUT32_I8)
8026 VARIDIV(INT,2,UI8,1,I4,2);
8028 VARIDIV(INT,2,INT,1,I4,2);
8029 VARIDIV(INT,2,UINT,1,I4,2);
8030 VARIDIV(UINT,2,NULL,0,NULL,0);
8031 VARIDIV(UINT,2,I2,1,I4,2);
8032 VARIDIV(UINT,2,I4,1,I4,2);
8033 VARIDIV(UINT,2,R4,1.0f,I4,2);
8034 VARIDIV(UINT,2,R8,1.0,I4,2);
8035 VARIDIV(UINT,2,DATE,1,I4,2);
8036 VARIDIV(UINT,2,BSTR,num1_str,I4,2);
8037 VARIDIV(UINT,2,BOOL,VARIANT_TRUE,I4,-2);
8038 VARIDIV(UINT,2,I1,1,I4,2);
8039 VARIDIV(UINT,2,UI1,1,I4,2);
8040 VARIDIV(UINT,2,UI2,1,I4,2);
8041 VARIDIV(UINT,2,UI4,1,I4,2);
8042 if (HAVE_OLEAUT32_I8)
8044 VARIDIV(UINT,2,I8,1,I8,2);
8045 VARIDIV(UINT,2,UI8,1,I4,2);
8047 VARIDIV(UINT,2,INT,1,I4,2);
8048 VARIDIV(UINT,2,UINT,1,I4,2);
8050 /* Manually test some VT_CY, VT_DECIMAL variants */
8051 V_VT(&cy) = VT_CY;
8052 hres = VarCyFromI4(10000, &V_CY(&cy));
8053 ok(hres == S_OK, "VarCyFromI4 failed!\n");
8054 V_VT(&dec) = VT_DECIMAL;
8055 hres = VarDecFromR8(2.0, &V_DECIMAL(&dec));
8056 ok(hres == S_OK, "VarDecFromR4 failed!\n");
8057 memset(&left, 0, sizeof(left));
8058 memset(&right, 0, sizeof(right));
8059 V_VT(&left) = VT_I4;
8060 V_I4(&left) = 100;
8061 V_VT(&right) = VT_I8;
8062 V_UI1(&right) = 2;
8064 hres = pVarIdiv(&cy, &cy, &result);
8065 ok(hres == S_OK && V_VT(&result) == VT_I4,
8066 "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8067 S_OK, hres, vtstr(V_VT(&result)));
8068 ok(hres == S_OK && V_I4(&result) == 1,
8069 "VARIDIV: CY value %d, expected %d\n", V_I4(&result), 1);
8071 if (HAVE_OLEAUT32_I8)
8073 hres = pVarIdiv(&cy, &right, &result);
8074 ok(hres == S_OK && V_VT(&result) == VT_I8,
8075 "VARIDIV: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n",
8076 S_OK, hres, vtstr(V_VT(&result)));
8077 ok(hres == S_OK && V_I8(&result) == 5000,
8078 "VARIDIV: CY value 0x%x%08x, expected 0x%x\n",
8079 (DWORD)(V_I8(&result) >>32), (DWORD)V_I8(&result), 5000);
8082 hres = pVarIdiv(&left, &cy, &result);
8083 ok(hres == S_OK && V_VT(&result) == VT_I4,
8084 "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8085 S_OK, hres, vtstr(V_VT(&result)));
8086 ok(hres == S_OK && V_I4(&result) == 0,
8087 "VARIDIV: CY value %d, expected %d\n", V_I4(&result), 0);
8089 hres = pVarIdiv(&left, &dec, &result);
8090 ok(hres == S_OK && V_VT(&result) == VT_I4,
8091 "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8092 S_OK, hres, vtstr(V_VT(&result)));
8093 ok(hres == S_OK && V_I4(&result) == 50,
8094 "VARIDIV: DECIMAL value %d, expected %d\n", V_I4(&result), 50);
8096 hres = pVarIdiv(&dec, &dec, &result);
8097 ok(hres == S_OK && V_VT(&result) == VT_I4,
8098 "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8099 S_OK, hres, vtstr(V_VT(&result)));
8100 ok(hres == S_OK && V_I4(&result) == 1,
8101 "VARIDIV: DECIMAL value %d, expected %d\n", V_I4(&result), 1);
8103 if (HAVE_OLEAUT32_I8)
8105 hres = pVarIdiv(&dec, &right, &result);
8106 ok(hres == S_OK && V_VT(&result) == VT_I8,
8107 "VARIDIV: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n",
8108 S_OK, hres, vtstr(V_VT(&result)));
8109 ok(hres == S_OK && V_I8(&result) == 1,
8110 "VARIDIV: DECIMAL value 0x%x%08x, expected %d\n",
8111 (DWORD)(V_I8(&result) >> 32), (DWORD)V_I8(&result), 1);
8114 /* Check for division by zero */
8115 V_VT(&left) = VT_INT;
8116 V_I4(&left) = 1;
8117 V_VT(&right) = VT_INT;
8118 V_I4(&right) = 0;
8119 hres = pVarIdiv(&left, &right, &result);
8120 ok(hres == DISP_E_DIVBYZERO && V_VT(&result) == VT_EMPTY,
8121 "VARIDIV: Division by 0 should result in DISP_E_DIVBYZERO but got 0x%X\n", hres);
8123 V_VT(&left) = VT_INT;
8124 V_I4(&left) = 0;
8125 V_VT(&right) = VT_INT;
8126 V_I4(&right) = 0;
8127 hres = pVarIdiv(&left, &right, &result);
8128 ok(hres == DISP_E_DIVBYZERO && V_VT(&result) == VT_EMPTY,
8129 "VARIDIV: Division by 0 should result in DISP_E_DIVBYZERO but got 0x%X\n", hres);
8131 SysFreeString(num1_str);
8132 SysFreeString(num2_str);
8136 static HRESULT (WINAPI *pVarImp)(LPVARIANT,LPVARIANT,LPVARIANT);
8138 #define VARIMP(vt1,val1,vt2,val2,rvt,rval) \
8139 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
8140 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
8141 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
8142 test_var_call2( __LINE__, pVarImp, &left, &right, &exp )
8144 /* Skip any type that is not defined or produces an error for every case */
8145 #define SKIPTESTIMP(a) \
8146 if (a == VT_ERROR || a == VT_VARIANT || \
8147 a == VT_DISPATCH || a == VT_UNKNOWN || \
8148 a == VT_RECORD || a > VT_UINT || \
8149 a == 15 /*not defined*/) \
8150 continue
8152 static void test_VarImp(void)
8154 static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
8155 static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
8156 VARIANT left, right, exp, result, cy, dec;
8157 BSTR true_str, false_str;
8158 VARTYPE i;
8159 HRESULT hres;
8161 CHECKPTR(VarImp);
8163 true_str = SysAllocString(szTrue);
8164 false_str = SysAllocString(szFalse);
8166 /* Test all possible flag/vt combinations & the resulting vt type */
8167 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
8169 VARTYPE leftvt, rightvt, resvt;
8171 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
8173 SKIPTESTIMP(leftvt);
8175 /* Check if we need/have support for I8 and/or UI8 */
8176 if ((leftvt == VT_I8 || leftvt == VT_UI8) && !HAVE_OLEAUT32_I8)
8177 continue;
8179 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
8181 BOOL bFail = FALSE;
8182 SKIPTESTIMP(rightvt);
8184 /* Native crashes when using the extra flag VT_BYREF
8185 * or with the following VT combinations
8187 if ((leftvt == VT_UI4 && rightvt == VT_BSTR) ||
8188 (leftvt == VT_UI8 && rightvt == VT_BSTR) ||
8189 ExtraFlags[i] == VT_BYREF)
8190 continue;
8192 /* Check if we need/have support for I8 and/or UI8 */
8193 if ((rightvt == VT_I8 || rightvt == VT_UI8) && !HAVE_OLEAUT32_I8)
8194 continue;
8196 memset(&left, 0, sizeof(left));
8197 memset(&right, 0, sizeof(right));
8198 V_VT(&left) = leftvt | ExtraFlags[i];
8199 V_VT(&right) = rightvt | ExtraFlags[i];
8200 V_VT(&result) = VT_EMPTY;
8201 resvt = VT_EMPTY;
8203 if (leftvt == VT_BSTR)
8204 V_BSTR(&left) = true_str;
8206 /* This allows us to test return types that are not NULL
8207 * (NULL Imp value = n, NULL Imp 0 = NULL)
8209 switch(rightvt)
8211 case VT_BSTR:
8212 V_BSTR(&right) = true_str;
8213 break;
8214 case VT_DECIMAL:
8215 VarDecFromR8(2.0, &V_DECIMAL(&right));
8216 V_VT(&right) = rightvt | ExtraFlags[i];
8217 break;
8218 case VT_BOOL:
8219 V_BOOL(&right) = VARIANT_TRUE;
8220 break;
8221 case VT_I1: V_I1(&right) = 2; break;
8222 case VT_I2: V_I2(&right) = 2; break;
8223 case VT_I4: V_I4(&right) = 2; break;
8224 case VT_R4: V_R4(&right) = 2.0f; break;
8225 case VT_R8: V_R8(&right) = 2.0; break;
8226 case VT_CY: V_CY(&right).int64 = 10000; break;
8227 case VT_DATE: V_DATE(&right) = 2; break;
8228 case VT_I8: V_I8(&right) = 2; break;
8229 case VT_INT: V_INT(&right) = 2; break;
8230 case VT_UINT: V_UINT(&right) = 2; break;
8231 case VT_UI1: V_UI1(&right) = 2; break;
8232 case VT_UI2: V_UI2(&right) = 2; break;
8233 case VT_UI4: V_UI4(&right) = 2; break;
8234 case VT_UI8: V_UI8(&right) = 2; break;
8235 default: break;
8238 /* Native VarImp always returns an error when using extra
8239 * flags or if the variants are I8 and INT.
8241 if ((leftvt == VT_I8 && rightvt == VT_INT) ||
8242 ExtraFlags[i] != 0)
8243 bFail = TRUE;
8245 /* Determine result type */
8246 else if ((leftvt == VT_BSTR && rightvt == VT_NULL) ||
8247 (leftvt == VT_NULL && rightvt == VT_NULL) ||
8248 (leftvt == VT_NULL && rightvt == VT_EMPTY))
8249 resvt = VT_NULL;
8250 else if (leftvt == VT_I8 || rightvt == VT_I8)
8251 resvt = VT_I8;
8252 else if (leftvt == VT_I4 || rightvt == VT_I4 ||
8253 leftvt == VT_INT || rightvt == VT_INT ||
8254 leftvt == VT_UINT || rightvt == VT_UINT ||
8255 leftvt == VT_UI4 || rightvt == VT_UI4 ||
8256 leftvt == VT_UI8 || rightvt == VT_UI8 ||
8257 leftvt == VT_UI2 || rightvt == VT_UI2 ||
8258 leftvt == VT_DECIMAL || rightvt == VT_DECIMAL ||
8259 leftvt == VT_DATE || rightvt == VT_DATE ||
8260 leftvt == VT_CY || rightvt == VT_CY ||
8261 leftvt == VT_R8 || rightvt == VT_R8 ||
8262 leftvt == VT_R4 || rightvt == VT_R4 ||
8263 leftvt == VT_I1 || rightvt == VT_I1)
8264 resvt = VT_I4;
8265 else if ((leftvt == VT_UI1 && rightvt == VT_UI1) ||
8266 (leftvt == VT_UI1 && rightvt == VT_NULL) ||
8267 (leftvt == VT_NULL && rightvt == VT_UI1))
8268 resvt = VT_UI1;
8269 else if (leftvt == VT_EMPTY || rightvt == VT_EMPTY ||
8270 leftvt == VT_I2 || rightvt == VT_I2 ||
8271 leftvt == VT_UI1 || rightvt == VT_UI1)
8272 resvt = VT_I2;
8273 else if (leftvt == VT_BOOL || rightvt == VT_BOOL ||
8274 leftvt == VT_BSTR || rightvt == VT_BSTR)
8275 resvt = VT_BOOL;
8277 hres = pVarImp(&left, &right, &result);
8279 /* Check expected HRESULT and if result variant type is correct */
8280 if (bFail)
8281 ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH,
8282 "VarImp: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
8283 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
8284 vtstr(V_VT(&result)), hres);
8285 else
8286 ok (hres == S_OK && resvt == V_VT(&result),
8287 "VarImp: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
8288 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
8289 S_OK, vtstr(V_VT(&result)), hres);
8294 VARIMP(EMPTY,0,EMPTY,0,I2,-1);
8295 VARIMP(EMPTY,0,NULL,0,I2,-1);
8296 VARIMP(EMPTY,0,I2,-1,I2,-1);
8297 VARIMP(EMPTY,0,I4,-1,I4,-1);
8298 VARIMP(EMPTY,0,R4,0.0f,I4,-1);
8299 VARIMP(EMPTY,0,R8,-1.0,I4,-1);
8300 VARIMP(EMPTY,0,DATE,0,I4,-1);
8301 VARIMP(EMPTY,0,BSTR,true_str,I2,-1);
8302 VARIMP(EMPTY,0,BOOL,VARIANT_FALSE,I2,-1);
8303 VARIMP(EMPTY,0,I1,0,I4,-1);
8304 VARIMP(EMPTY,0,UI1,1,I2,-1);
8305 VARIMP(EMPTY,0,UI2,1,I4,-1);
8306 VARIMP(EMPTY,0,UI4,1,I4,-1);
8307 if (HAVE_OLEAUT32_I8)
8309 VARIMP(EMPTY,0,I8,1,I8,-1);
8310 VARIMP(EMPTY,0,UI8,1,I4,-1);
8312 VARIMP(EMPTY,0,INT,-1,I4,-1);
8313 VARIMP(EMPTY,0,UINT,1,I4,-1);
8314 VARIMP(NULL,0,EMPTY,0,NULL,0);
8315 VARIMP(NULL,0,NULL,0,NULL,0);
8316 VARIMP(NULL,0,I2,-1,I2,-1);
8317 VARIMP(NULL,0,I4,-1,I4,-1);
8318 VARIMP(NULL,0,R4,0.0f,NULL,0);
8319 VARIMP(NULL,0,R8,-1.0,I4,-1);
8320 VARIMP(NULL,0,DATE,0,NULL,0);
8321 VARIMP(NULL,0,BSTR,true_str,BOOL,-1);
8322 VARIMP(NULL,0,BOOL,VARIANT_FALSE,NULL,0);
8323 VARIMP(NULL,0,I1,0,NULL,0);
8324 VARIMP(NULL,0,UI1,1,UI1,1);
8325 VARIMP(NULL,0,UI2,1,I4,1);
8326 VARIMP(NULL,0,UI4,1,I4,1);
8327 if (HAVE_OLEAUT32_I8)
8329 VARIMP(NULL,0,I8,1,I8,1);
8330 VARIMP(NULL,0,UI8,1,I4,1);
8332 VARIMP(NULL,0,INT,-1,I4,-1);
8333 VARIMP(NULL,0,UINT,1,I4,1);
8334 VARIMP(I2,-1,EMPTY,0,I2,0);
8335 VARIMP(I2,-1,I2,-1,I2,-1);
8336 VARIMP(I2,-1,I4,-1,I4,-1);
8337 VARIMP(I2,-1,R4,0.0f,I4,0);
8338 VARIMP(I2,-1,R8,-1.0,I4,-1);
8339 VARIMP(I2,-1,DATE,0,I4,0);
8340 VARIMP(I2,-1,BSTR,true_str,I2,-1);
8341 VARIMP(I2,-1,BOOL,VARIANT_FALSE,I2,0);
8342 VARIMP(I2,-1,I1,0,I4,0);
8343 VARIMP(I2,-1,UI1,1,I2,1);
8344 VARIMP(I2,-1,UI2,1,I4,1);
8345 VARIMP(I2,-1,UI4,1,I4,1);
8346 if (HAVE_OLEAUT32_I8)
8348 VARIMP(I2,-1,I8,1,I8,1);
8349 VARIMP(I2,-1,UI8,1,I4,1);
8351 VARIMP(I2,-1,INT,-1,I4,-1);
8352 VARIMP(I2,-1,UINT,1,I4,1);
8353 VARIMP(I4,2,EMPTY,0,I4,-3);
8354 VARIMP(I4,2,NULL,0,I4,-3);
8355 VARIMP(I4,2,I2,-1,I4,-1);
8356 VARIMP(I4,2,I4,-1,I4,-1);
8357 VARIMP(I4,2,R4,0.0f,I4,-3);
8358 VARIMP(I4,2,R8,-1.0,I4,-1);
8359 VARIMP(I4,2,DATE,0,I4,-3);
8360 VARIMP(I4,2,BSTR,true_str,I4,-1);
8361 VARIMP(I4,2,BOOL,VARIANT_FALSE,I4,-3);
8362 VARIMP(I4,2,I1,0,I4,-3);
8363 VARIMP(I4,2,UI1,1,I4,-3);
8364 VARIMP(I4,2,UI2,1,I4,-3);
8365 VARIMP(I4,2,UI4,1,I4,-3);
8366 if (HAVE_OLEAUT32_I8)
8368 VARIMP(I4,2,I8,1,I8,-3);
8369 VARIMP(I4,2,UI8,1,I4,-3);
8371 VARIMP(I4,2,INT,-1,I4,-1);
8372 VARIMP(I4,2,UINT,1,I4,-3);
8373 VARIMP(R4,-1.0f,EMPTY,0,I4,0);
8374 VARIMP(R4,-1.0f,NULL,0,NULL,0);
8375 VARIMP(R4,-1.0f,I2,-1,I4,-1);
8376 VARIMP(R4,-1.0f,I4,-1,I4,-1);
8377 VARIMP(R4,-1.0f,R4,0.0f,I4,0);
8378 VARIMP(R4,-1.0f,R8,-1.0,I4,-1);
8379 VARIMP(R4,-1.0f,DATE,1,I4,1);
8380 VARIMP(R4,-1.0f,BSTR,true_str,I4,-1);
8381 VARIMP(R4,-1.0f,BOOL,VARIANT_FALSE,I4,0);
8382 VARIMP(R4,-1.0f,I1,0,I4,0);
8383 VARIMP(R4,-1.0f,UI1,1,I4,1);
8384 VARIMP(R4,-1.0f,UI2,1,I4,1);
8385 VARIMP(R4,-1.0f,UI4,1,I4,1);
8386 if (HAVE_OLEAUT32_I8)
8388 VARIMP(R4,-1.0f,I8,1,I8,1);
8389 VARIMP(R4,-1.0f,UI8,1,I4,1);
8391 VARIMP(R4,-1.0f,INT,-1,I4,-1);
8392 VARIMP(R4,-1.0f,UINT,1,I4,1);
8393 VARIMP(R8,1.0,EMPTY,0,I4,-2);
8394 VARIMP(R8,1.0,NULL,0,I4,-2);
8395 VARIMP(R8,1.0,I2,-1,I4,-1);
8396 VARIMP(R8,1.0,I4,-1,I4,-1);
8397 VARIMP(R8,1.0,R4,0.0f,I4,-2);
8398 VARIMP(R8,1.0,R8,-1.0,I4,-1);
8399 VARIMP(R8,1.0,DATE,0,I4,-2);
8400 VARIMP(R8,1.0,BSTR,true_str,I4,-1);
8401 VARIMP(R8,1.0,BOOL,VARIANT_FALSE,I4,-2);
8402 VARIMP(R8,1.0,I1,0,I4,-2);
8403 VARIMP(R8,1.0,UI1,1,I4,-1);
8404 VARIMP(R8,1.0,UI2,1,I4,-1);
8405 VARIMP(R8,1.0,UI4,1,I4,-1);
8406 if (HAVE_OLEAUT32_I8)
8408 VARIMP(R8,1.0,I8,1,I8,-1);
8409 VARIMP(R8,1.0,UI8,1,I4,-1);
8411 VARIMP(R8,1.0,INT,-1,I4,-1);
8412 VARIMP(R8,1.0,UINT,1,I4,-1);
8413 VARIMP(DATE,0,EMPTY,0,I4,-1);
8414 VARIMP(DATE,0,NULL,0,I4,-1);
8415 VARIMP(DATE,0,I2,-1,I4,-1);
8416 VARIMP(DATE,0,I4,-1,I4,-1);
8417 VARIMP(DATE,0,R4,0.0f,I4,-1);
8418 VARIMP(DATE,0,R8,-1.0,I4,-1);
8419 VARIMP(DATE,0,DATE,0,I4,-1);
8420 VARIMP(DATE,0,BSTR,true_str,I4,-1);
8421 VARIMP(DATE,0,BOOL,VARIANT_FALSE,I4,-1);
8422 VARIMP(DATE,0,I1,0,I4,-1);
8423 VARIMP(DATE,0,UI1,1,I4,-1);
8424 VARIMP(DATE,0,UI2,1,I4,-1);
8425 VARIMP(DATE,0,UI4,1,I4,-1);
8426 if (HAVE_OLEAUT32_I8)
8428 VARIMP(DATE,0,I8,1,I8,-1);
8429 VARIMP(DATE,0,UI8,1,I4,-1);
8431 VARIMP(DATE,0,INT,-1,I4,-1);
8432 VARIMP(DATE,0,UINT,1,I4,-1);
8433 VARIMP(BSTR,false_str,EMPTY,0,I2,-1);
8434 VARIMP(BSTR,false_str,NULL,0,BOOL,-1);
8435 VARIMP(BSTR,false_str,I2,-1,I2,-1);
8436 VARIMP(BSTR,false_str,I4,-1,I4,-1);
8437 VARIMP(BSTR,false_str,R4,0.0f,I4,-1);
8438 VARIMP(BSTR,false_str,R8,-1.0,I4,-1);
8439 VARIMP(BSTR,false_str,DATE,0,I4,-1);
8440 VARIMP(BSTR,false_str,BSTR,true_str,BOOL,-1);
8441 VARIMP(BSTR,false_str,BOOL,VARIANT_FALSE,BOOL,-1);
8442 VARIMP(BSTR,false_str,I1,0,I4,-1);
8443 VARIMP(BSTR,false_str,UI1,1,I2,-1);
8444 VARIMP(BSTR,false_str,UI2,1,I4,-1);
8445 VARIMP(BSTR,false_str,UI4,1,I4,-1);
8446 if (HAVE_OLEAUT32_I8)
8448 VARIMP(BSTR,false_str,I8,1,I8,-1);
8449 VARIMP(BSTR,false_str,UI8,1,I4,-1);
8451 VARIMP(BSTR,false_str,INT,-1,I4,-1);
8452 VARIMP(BSTR,false_str,UINT,1,I4,-1);
8453 VARIMP(BOOL,VARIANT_TRUE,EMPTY,0,I2,0);
8454 VARIMP(BOOL,VARIANT_TRUE,NULL,0,NULL,0);
8455 VARIMP(BOOL,VARIANT_TRUE,I2,-1,I2,-1);
8456 VARIMP(BOOL,VARIANT_TRUE,I4,-1,I4,-1);
8457 VARIMP(BOOL,VARIANT_TRUE,R4,0.0f,I4,0);
8458 VARIMP(BOOL,VARIANT_TRUE,R8,-1.0,I4,-1);
8459 VARIMP(BOOL,VARIANT_TRUE,DATE,0,I4,0);
8460 VARIMP(BOOL,VARIANT_TRUE,BSTR,true_str,BOOL,-1);
8461 VARIMP(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,0);
8462 VARIMP(BOOL,VARIANT_TRUE,I1,0,I4,0);
8463 VARIMP(BOOL,VARIANT_TRUE,UI1,1,I2,1);
8464 VARIMP(BOOL,VARIANT_TRUE,UI2,1,I4,1);
8465 VARIMP(BOOL,VARIANT_TRUE,UI4,1,I4,1);
8466 if (HAVE_OLEAUT32_I8)
8468 VARIMP(BOOL,VARIANT_TRUE,I8,1,I8,1);
8469 VARIMP(BOOL,VARIANT_TRUE,UI8,1,I4,1);
8471 VARIMP(BOOL,VARIANT_TRUE,INT,-1,I4,-1);
8472 VARIMP(BOOL,VARIANT_TRUE,UINT,1,I4,1);
8473 VARIMP(I1,-1,EMPTY,0,I4,0);
8474 VARIMP(I1,-1,NULL,0,NULL,0);
8475 VARIMP(I1,-1,I2,-1,I4,-1);
8476 VARIMP(I1,-1,I4,-1,I4,-1);
8477 VARIMP(I1,-1,R4,0.0f,I4,0);
8478 VARIMP(I1,-1,R8,-1.0,I4,-1);
8479 VARIMP(I1,-1,DATE,0,I4,0);
8480 VARIMP(I1,-1,BSTR,true_str,I4,-1);
8481 VARIMP(I1,-1,BOOL,VARIANT_FALSE,I4,0);
8482 VARIMP(I1,-1,I1,0,I4,0);
8483 VARIMP(I1,-1,UI1,1,I4,1);
8484 VARIMP(I1,-1,UI2,1,I4,1);
8485 VARIMP(I1,-1,UI4,1,I4,1);
8486 if (HAVE_OLEAUT32_I8)
8488 VARIMP(I1,-1,I8,1,I8,1);
8489 VARIMP(I1,-1,UI8,1,I4,1);
8491 VARIMP(I1,-1,INT,-1,I4,-1);
8492 VARIMP(I1,-1,UINT,1,I4,1);
8493 VARIMP(UI1,0,EMPTY,0,I2,-1);
8494 VARIMP(UI1,0,NULL,0,UI1,255);
8495 VARIMP(UI1,0,I2,-1,I2,-1);
8496 VARIMP(UI1,0,I4,-1,I4,-1);
8497 VARIMP(UI1,0,R4,0.0f,I4,-1);
8498 VARIMP(UI1,0,R8,-1.0,I4,-1);
8499 VARIMP(UI1,0,DATE,0,I4,-1);
8500 VARIMP(UI1,0,BSTR,true_str,I2,-1);
8501 VARIMP(UI1,0,BOOL,VARIANT_FALSE,I2,-1);
8502 VARIMP(UI1,0,I1,0,I4,-1);
8503 VARIMP(UI1,0,UI1,1,UI1,255);
8504 VARIMP(UI1,0,UI2,1,I4,-1);
8505 VARIMP(UI1,0,UI4,1,I4,-1);
8506 if (HAVE_OLEAUT32_I8)
8508 VARIMP(UI1,0,I8,1,I8,-1);
8509 VARIMP(UI1,0,UI8,1,I4,-1);
8511 VARIMP(UI1,0,INT,-1,I4,-1);
8512 VARIMP(UI1,0,UINT,1,I4,-1);
8513 VARIMP(UI2,0,EMPTY,0,I4,-1);
8514 VARIMP(UI2,0,NULL,0,I4,-1);
8515 VARIMP(UI2,0,I2,-1,I4,-1);
8516 VARIMP(UI2,0,I4,-1,I4,-1);
8517 VARIMP(UI2,0,R4,0.0f,I4,-1);
8518 VARIMP(UI2,0,R8,-1.0,I4,-1);
8519 VARIMP(UI2,0,DATE,0,I4,-1);
8520 VARIMP(UI2,0,BSTR,true_str,I4,-1);
8521 VARIMP(UI2,0,BOOL,VARIANT_FALSE,I4,-1);
8522 VARIMP(UI2,0,I1,0,I4,-1);
8523 VARIMP(UI2,0,UI1,1,I4,-1);
8524 VARIMP(UI2,0,UI2,1,I4,-1);
8525 VARIMP(UI2,0,UI4,1,I4,-1);
8526 if (HAVE_OLEAUT32_I8)
8528 VARIMP(UI2,0,I8,1,I8,-1);
8529 VARIMP(UI2,0,UI8,1,I4,-1);
8531 VARIMP(UI2,0,INT,-1,I4,-1);
8532 VARIMP(UI2,0,UINT,1,I4,-1);
8533 VARIMP(UI4,0,EMPTY,0,I4,-1);
8534 VARIMP(UI4,0,NULL,0,I4,-1);
8535 VARIMP(UI4,0,I2,-1,I4,-1);
8536 VARIMP(UI4,0,I4,-1,I4,-1);
8537 VARIMP(UI4,0,R4,0.0f,I4,-1);
8538 VARIMP(UI4,0,R8,-1.0,I4,-1);
8539 VARIMP(UI4,0,DATE,0,I4,-1);
8540 VARIMP(UI4,0,BSTR,true_str,I4,-1);
8541 VARIMP(UI4,0,BOOL,VARIANT_FALSE,I4,-1);
8542 VARIMP(UI4,0,I1,0,I4,-1);
8543 VARIMP(UI4,0,UI1,1,I4,-1);
8544 VARIMP(UI4,0,UI2,1,I4,-1);
8545 VARIMP(UI4,0,UI4,1,I4,-1);
8546 if (HAVE_OLEAUT32_I8)
8548 VARIMP(UI4,0,I8,1,I8,-1);
8549 VARIMP(UI4,0,UI8,1,I4,-1);
8551 VARIMP(UI4,0,INT,-1,I4,-1);
8552 VARIMP(UI4,0,UINT,1,I4,-1);
8553 if (HAVE_OLEAUT32_I8)
8555 VARIMP(I8,-1,EMPTY,0,I8,0);
8556 VARIMP(I8,-1,NULL,0,NULL,0);
8557 VARIMP(I8,-1,I2,-1,I8,-1);
8558 VARIMP(I8,-1,I4,-1,I8,-1);
8559 VARIMP(I8,-1,R4,0.0f,I8,0);
8560 VARIMP(I8,-1,R8,-1.0,I8,-1);
8561 VARIMP(I8,-1,DATE,0,I8,0);
8562 VARIMP(I8,-1,BSTR,true_str,I8,-1);
8563 VARIMP(I8,-1,BOOL,VARIANT_FALSE,I8,0);
8564 VARIMP(I8,-1,I1,0,I8,0);
8565 VARIMP(I8,-1,UI1,1,I8,1);
8566 VARIMP(I8,-1,UI2,1,I8,1);
8567 VARIMP(I8,-1,UI4,1,I8,1);
8568 VARIMP(I8,-1,I8,1,I8,1);
8569 VARIMP(I8,-1,UI8,1,I8,1);
8570 VARIMP(I8,-1,UINT,1,I8,1);
8571 VARIMP(UI8,0,EMPTY,0,I4,-1);
8572 VARIMP(UI8,0,NULL,0,I4,-1);
8573 VARIMP(UI8,0,I2,-1,I4,-1);
8574 VARIMP(UI8,0,I4,-1,I4,-1);
8575 VARIMP(UI8,0,R4,0.0f,I4,-1);
8576 VARIMP(UI8,0,R8,-1.0,I4,-1);
8577 VARIMP(UI8,0,DATE,0,I4,-1);
8578 VARIMP(UI8,0,BSTR,true_str,I4,-1);
8579 VARIMP(UI8,0,BOOL,VARIANT_FALSE,I4,-1);
8580 VARIMP(UI8,0,I1,0,I4,-1);
8581 VARIMP(UI8,0,UI1,1,I4,-1);
8582 VARIMP(UI8,0,UI2,1,I4,-1);
8583 VARIMP(UI8,0,UI4,1,I4,-1);
8584 VARIMP(UI8,0,I8,1,I8,-1);
8585 VARIMP(UI8,0,UI8,1,I4,-1);
8586 VARIMP(UI8,0,INT,-1,I4,-1);
8587 VARIMP(UI8,0,UINT,1,I4,-1);
8589 VARIMP(INT,-1,EMPTY,0,I4,0);
8590 VARIMP(INT,-1,NULL,0,NULL,0);
8591 VARIMP(INT,-1,I2,-1,I4,-1);
8592 VARIMP(INT,-1,I4,-1,I4,-1);
8593 VARIMP(INT,-1,R4,0.0f,I4,0);
8594 VARIMP(INT,-1,R8,-1.0,I4,-1);
8595 VARIMP(INT,-1,DATE,0,I4,0);
8596 VARIMP(INT,-1,BSTR,true_str,I4,-1);
8597 VARIMP(INT,-1,BOOL,VARIANT_FALSE,I4,0);
8598 VARIMP(INT,-1,I1,0,I4,0);
8599 VARIMP(INT,-1,UI1,1,I4,1);
8600 VARIMP(INT,-1,UI2,1,I4,1);
8601 VARIMP(INT,-1,UI4,1,I4,1);
8602 if (HAVE_OLEAUT32_I8)
8604 VARIMP(INT,-1,I8,1,I8,1);
8605 VARIMP(INT,-1,UI8,1,I4,1);
8607 VARIMP(INT,-1,INT,-1,I4,-1);
8608 VARIMP(INT,-1,UINT,1,I4,1);
8609 VARIMP(UINT,1,EMPTY,0,I4,-2);
8610 VARIMP(UINT,1,NULL,0,I4,-2);
8611 VARIMP(UINT,1,I2,-1,I4,-1);
8612 VARIMP(UINT,1,I4,-1,I4,-1);
8613 VARIMP(UINT,1,R4,0.0f,I4,-2);
8614 VARIMP(UINT,1,R8,-1.0,I4,-1);
8615 VARIMP(UINT,1,DATE,0,I4,-2);
8616 VARIMP(UINT,1,BSTR,true_str,I4,-1);
8617 VARIMP(UINT,1,BOOL,VARIANT_FALSE,I4,-2);
8618 VARIMP(UINT,1,I1,0,I4,-2);
8619 VARIMP(UINT,1,UI1,1,I4,-1);
8620 VARIMP(UINT,1,UI2,1,I4,-1);
8621 VARIMP(UINT,1,UI4,1,I4,-1);
8622 if (HAVE_OLEAUT32_I8)
8624 VARIMP(UINT,1,I8,1,I8,-1);
8625 VARIMP(UINT,1,UI8,1,I4,-1);
8627 VARIMP(UINT,1,INT,-1,I4,-1);
8628 VARIMP(UINT,1,UINT,1,I4,-1);
8630 /* Manually test some VT_CY, VT_DECIMAL variants */
8631 V_VT(&cy) = VT_CY;
8632 hres = VarCyFromI4(1, &V_CY(&cy));
8633 ok(hres == S_OK, "VarCyFromI4 failed!\n");
8634 V_VT(&dec) = VT_DECIMAL;
8635 hres = VarDecFromR8(2.0, &V_DECIMAL(&dec));
8636 ok(hres == S_OK, "VarDecFromR4 failed!\n");
8637 memset(&left, 0, sizeof(left));
8638 memset(&right, 0, sizeof(right));
8639 V_VT(&left) = VT_I4;
8640 V_I4(&left) = 0;
8641 V_VT(&right) = VT_I8;
8642 V_UI1(&right) = 0;
8644 hres = pVarImp(&cy, &cy, &result);
8645 ok(hres == S_OK && V_VT(&result) == VT_I4,
8646 "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8647 S_OK, hres, vtstr(V_VT(&result)));
8648 ok(hres == S_OK && V_I4(&result) == -1,
8649 "VARIMP: CY value %d, expected %d\n", V_I4(&result), -1);
8651 if (HAVE_OLEAUT32_I8)
8653 hres = pVarImp(&cy, &right, &result);
8654 ok(hres == S_OK && V_VT(&result) == VT_I8,
8655 "VARIMP: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n",
8656 S_OK, hres, vtstr(V_VT(&result)));
8657 ok(hres == S_OK && V_I8(&result) == -2,
8658 "VARIMP: CY value %x%08x, expected %d\n",
8659 (DWORD)((V_I8(&result)) >> 32), (DWORD)(V_I8(&result)), -2);
8662 hres = pVarImp(&left, &cy, &result);
8663 ok(hres == S_OK && V_VT(&result) == VT_I4,
8664 "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8665 S_OK, hres, vtstr(V_VT(&result)));
8666 ok(hres == S_OK && V_I4(&result) == -1,
8667 "VARIMP: CY value %d, expected %d\n", V_I4(&result), -1);
8669 hres = pVarImp(&left, &dec, &result);
8670 ok(hres == S_OK && V_VT(&result) == VT_I4,
8671 "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8672 S_OK, hres, vtstr(V_VT(&result)));
8673 ok(hres == S_OK && V_I4(&result) == -1,
8674 "VARIMP: DECIMAL value %d, expected %d\n", V_I4(&result), -1);
8676 hres = pVarImp(&dec, &dec, &result);
8677 ok(hres == S_OK && V_VT(&result) == VT_I4,
8678 "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8679 S_OK, hres, vtstr(V_VT(&result)));
8680 ok(hres == S_OK && V_I4(&result) == -1,
8681 "VARIMP: DECIMAL value %d, expected %d\n", V_I4(&result), -1);
8683 if (HAVE_OLEAUT32_I8)
8685 hres = pVarImp(&dec, &right, &result);
8686 ok(hres == S_OK && V_VT(&result) == VT_I8,
8687 "VARIMP: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n",
8688 S_OK, hres, vtstr(V_VT(&result)));
8689 ok(hres == S_OK && V_I8(&result) == -3,
8690 "VARIMP: DECIMAL value 0x%x%08x, expected %d\n",
8691 (DWORD)(V_I8(&result) >>32), (DWORD)V_I8(&result), -3);
8694 SysFreeString(false_str);
8695 SysFreeString(true_str);
8698 START_TEST(vartest)
8700 init();
8702 test_VariantInit();
8703 test_VariantClear();
8704 test_VariantCopy();
8705 test_VariantCopyInd();
8706 test_VarParseNumFromStr();
8707 test_VarNumFromParseNum();
8708 test_VarUdateFromDate();
8709 test_VarDateFromUdate();
8710 test_SystemTimeToVariantTime();
8711 test_VariantTimeToSystemTime();
8712 test_DosDateTimeToVariantTime();
8713 test_VariantTimeToDosDateTime();
8714 test_VarAbs();
8715 test_VarNot();
8716 test_VarSub();
8717 test_VarMod();
8718 test_VarFix();
8719 test_VarInt();
8720 test_VarNeg();
8721 test_VarRound();
8722 test_VarXor();
8723 test_VarOr();
8724 test_VarPow();
8725 test_VarEqv();
8726 test_VarMul();
8727 test_VarAdd();
8728 test_VarCmp(); /* Before test_VarCat() which needs VarCmp() */
8729 test_VarCat();
8730 test_VarAnd();
8731 test_VarDiv();
8732 test_VarIdiv();
8733 test_VarImp();