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
30 #include "wine/test.h"
40 static HMODULE hOleaut32;
42 static HRESULT (WINAPI *pVarUdateFromDate)(DATE,ULONG,UDATE*);
43 static HRESULT (WINAPI *pVarDateFromUdate)(UDATE*,ULONG,DATE*);
44 static INT (WINAPI *pSystemTimeToVariantTime)(LPSYSTEMTIME,double*);
45 static INT (WINAPI *pVariantTimeToSystemTime)(double,LPSYSTEMTIME);
46 static INT (WINAPI *pDosDateTimeToVariantTime)(USHORT,USHORT,double*);
47 static INT (WINAPI *pVariantTimeToDosDateTime)(double,USHORT*,USHORT *);
49 static const WCHAR sz12[] = {'1','2','\0'};
50 /* the strings are localized */
51 static WCHAR sz12_false[32];
52 static WCHAR sz12_true[32];
54 /* Get a conversion function ptr, return if function not available */
55 #define CHECKPTR(func) p##func = (void*)GetProcAddress(hOleaut32, #func); \
56 if (!p##func) { trace("function " # func " not available, not testing it\n"); return; }
58 /* Have IRecordInfo data type? */
59 static int HAVE_OLEAUT32_RECORD = 0;
60 /* Have I8/UI8 data type? */
61 static int HAVE_OLEAUT32_I8 = 0;
62 /* Is this an ancient version with support for only I2/I4/R4/R8/DATE? */
63 static int IS_ANCIENT = 0;
65 /* When comparing floating point values we cannot expect an exact match
66 * because the rounding errors depend on the exact algorithm.
68 #define EQ_DOUBLE(a,b) (fabs((a)-(b)) / (1.0+fabs(a)+fabs(b)) < 1e-14)
69 #define EQ_FLOAT(a,b) (fabs((a)-(b)) / (1.0+fabs(a)+fabs(b)) < 1e-7)
71 #define SKIPTESTS(a) if((a > VT_CLSID+10) && (a < VT_BSTR_BLOB-10)) continue
73 /* Allow our test macros to work for VT_NULL and VT_EMPTY too */
74 #define V_EMPTY(v) V_I4(v)
75 #define V_NULL(v) V_I4(v)
77 /* Size constraints for overflow tests */
79 #define I1_MIN ((-I1_MAX)-1)
83 #define I2_MIN ((-I2_MAX)-1)
84 #define UI2_MAX 0xffff
86 #define I4_MAX 0x7fffffff
87 #define I4_MIN ((-I4_MAX)-1)
88 #define UI4_MAX 0xffffffff
90 #define I8_MAX (((LONGLONG)I4_MAX << 32) | UI4_MAX)
91 #define I8_MIN ((-I8_MAX)-1)
92 #define UI8_MAX (((ULONGLONG)UI4_MAX << 32) | UI4_MAX)
94 #define DATE_MAX 2958465
95 #define DATE_MIN -657434
96 #define R4_MAX FLT_MAX
97 #define R4_MIN FLT_MIN
98 #define R8_MAX DBL_MAX
99 #define R8_MIN DBL_MIN
101 static void init(void)
106 res = VarBstrFromBool(VARIANT_TRUE, LANG_USER_DEFAULT, VAR_LOCALBOOL, &bstr);
107 ok(SUCCEEDED(res) && (lstrlenW(bstr) > 0),
108 "Expected localized string for 'True'\n");
109 /* lstrcpyW / lstrcatW do not work on win95 */
110 memcpy(sz12_true, sz12, sizeof(sz12));
111 if (bstr) memcpy(&sz12_true[2], bstr, SysStringByteLen(bstr) + sizeof(WCHAR));
114 res = VarBstrFromBool(VARIANT_FALSE, LANG_USER_DEFAULT, VAR_LOCALBOOL, &bstr);
115 ok(SUCCEEDED(res) && (lstrlenW(bstr) > 0),
116 "Expected localized string for 'False'\n");
117 memcpy(sz12_false, sz12, sizeof(sz12));
118 if (bstr) memcpy(&sz12_false[2], bstr, SysStringByteLen(bstr) + sizeof(WCHAR));
121 hOleaut32 = GetModuleHandle("oleaut32.dll");
123 /* Is a given function exported from oleaut32? */
124 #define HAVE_FUNC(func) ((void*)GetProcAddress(hOleaut32, #func) != NULL)
126 HAVE_OLEAUT32_I8 = HAVE_FUNC(VarI8FromI1);
127 if (!HAVE_OLEAUT32_I8)
128 skip("No support for I8 and UI8 data types\n");
130 HAVE_OLEAUT32_RECORD = HAVE_FUNC(SafeArraySetRecordInfo);
131 IS_ANCIENT = (!HAVE_FUNC(VarI1FromI2));
136 /* Functions to set a DECIMAL */
137 static void setdec(DECIMAL* dec, BYTE scl, BYTE sgn, ULONG hi32, ULONG64 lo64)
139 S(U(*dec)).scale = scl;
140 S(U(*dec)).sign = sgn;
142 U1(*dec).Lo64 = lo64;
145 static void setdec64(DECIMAL* dec, BYTE scl, BYTE sgn, ULONG hi32, ULONG mid32, ULONG lo32)
147 S(U(*dec)).scale = scl;
148 S(U(*dec)).sign = sgn;
150 S1(U1(*dec)).Mid32 = mid32;
151 S1(U1(*dec)).Lo32 = lo32;
154 static inline int strcmpW( const WCHAR *str1, const WCHAR *str2 )
156 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
157 return *str1 - *str2;
160 /* return the string text of a given variant type */
161 static char vtstr_buffer[16][256];
162 static int vtstr_current=0;
163 static const char *vtstr(int x)
166 #define CASE(vt) case VT_##vt: return #vt
205 CASE(STREAMED_OBJECT);
210 CASE(VERSIONED_STREAM);
219 return "VT_BSTR_BLOB/VT_ILLEGALMASKED/VT_TYPEMASK";
222 vtstr_current %= sizeof(vtstr_buffer)/sizeof(*vtstr_buffer);
223 sprintf(vtstr_buffer[vtstr_current], "unknown variant type %d", x);
224 return vtstr_buffer[vtstr_current++];
228 static const char *variantstr( const VARIANT *var )
230 vtstr_current %= sizeof(vtstr_buffer)/sizeof(*vtstr_buffer);
234 sprintf( vtstr_buffer[vtstr_current], "VT_I1(%d)", V_I1(var) ); break;
236 sprintf( vtstr_buffer[vtstr_current], "VT_I2(%d)", V_I2(var) ); break;
238 sprintf( vtstr_buffer[vtstr_current], "VT_I4(%d)", V_I4(var) ); break;
240 sprintf( vtstr_buffer[vtstr_current], "VT_INT(%d)", V_INT(var) ); break;
242 sprintf( vtstr_buffer[vtstr_current], "VT_I8(%x%08x)", (UINT)(V_I8(var) >> 32), (UINT)V_I8(var) ); break;
244 sprintf( vtstr_buffer[vtstr_current], "VT_UI8(%x%08x)", (UINT)(V_UI8(var) >> 32), (UINT)V_UI8(var) ); break;
246 sprintf( vtstr_buffer[vtstr_current], "VT_R4(%g)", V_R4(var) ); break;
248 sprintf( vtstr_buffer[vtstr_current], "VT_R8(%g)", V_R8(var) ); break;
250 sprintf( vtstr_buffer[vtstr_current], "VT_UI1(%u)", V_UI1(var) ); break;
252 sprintf( vtstr_buffer[vtstr_current], "VT_UI2(%u)", V_UI2(var) ); break;
254 sprintf( vtstr_buffer[vtstr_current], "VT_UI4(%u)", V_UI4(var) ); break;
256 sprintf( vtstr_buffer[vtstr_current], "VT_UINT(%d)", V_UINT(var) ); break;
258 sprintf( vtstr_buffer[vtstr_current], "VT_CY(%x%08x)", S(V_CY(var)).Hi, S(V_CY(var)).Lo ); break;
260 sprintf( vtstr_buffer[vtstr_current], "VT_DATE(%g)", V_DATE(var) ); break;
262 return vtstr(V_VT(var));
264 return vtstr_buffer[vtstr_current++];
267 static BOOL is_expected_variant( const VARIANT *result, const VARIANT *expected )
269 if (V_VT(result) != V_VT(expected)) return FALSE;
270 switch(V_VT(expected))
276 #define CASE(vt) case VT_##vt: return (V_##vt(result) == V_##vt(expected))
291 return EQ_FLOAT(V_DATE(result), V_DATE(expected));
293 return EQ_FLOAT(V_R4(result), V_R4(expected));
295 return EQ_FLOAT(V_R8(result), V_R8(expected));
297 return (V_CY(result).int64 == V_CY(expected).int64);
299 return !lstrcmpW( V_BSTR(result), V_BSTR(expected) );
301 return !memcmp( &V_DECIMAL(result), &V_DECIMAL(expected), sizeof(DECIMAL) );
303 ok(0, "unhandled variant type %s\n",vtstr(V_VT(expected)));
308 static void test_var_call1( int line, HRESULT (WINAPI *func)(LPVARIANT,LPVARIANT),
309 VARIANT *arg, VARIANT *expected )
311 VARIANT old_arg = *arg;
315 memset( &result, 0, sizeof(result) );
316 hres = func( arg, &result );
317 ok_(__FILE__,line)( hres == S_OK, "wrong result %x\n", hres );
319 ok_(__FILE__,line)( is_expected_variant( &result, expected ),
320 "got %s expected %s\n", variantstr(&result), variantstr(expected) );
321 ok_(__FILE__,line)( is_expected_variant( arg, &old_arg ), "Modified argument %s / %s\n",
322 variantstr(&old_arg), variantstr(arg));
323 VariantClear( &result );
326 static void test_var_call2( int line, HRESULT (WINAPI *func)(LPVARIANT,LPVARIANT,LPVARIANT),
327 VARIANT *left, VARIANT *right, VARIANT *expected )
329 VARIANT old_left = *left, old_right = *right;
333 memset( &result, 0, sizeof(result) );
334 hres = func( left, right, &result );
335 ok_(__FILE__,line)( hres == S_OK, "wrong result %x\n", hres );
337 ok_(__FILE__,line)( is_expected_variant( &result, expected ),
338 "got %s expected %s\n", variantstr(&result), variantstr(expected) );
339 ok_(__FILE__,line)( is_expected_variant( left, &old_left ), "Modified left argument %s / %s\n",
340 variantstr(&old_left), variantstr(left));
341 ok_(__FILE__,line)( is_expected_variant( right, &old_right ), "Modified right argument %s / %s\n",
342 variantstr(&old_right), variantstr(right));
343 VariantClear( &result );
347 static void test_VariantInit(void)
351 /* Test that VariantInit() only sets the type */
352 memset(&v1, -1, sizeof(v1));
354 V_VT(&v2) = VT_EMPTY;
356 ok(!memcmp(&v1, &v2, sizeof(v1)), "VariantInit() set extra fields\n");
359 /* All possible combinations of extra V_VT() flags */
360 static const VARTYPE ExtraFlags[16] =
369 VT_VECTOR|VT_RESERVED,
370 VT_VECTOR|VT_ARRAY|VT_BYREF,
371 VT_VECTOR|VT_ARRAY|VT_RESERVED,
372 VT_VECTOR|VT_BYREF|VT_RESERVED,
373 VT_VECTOR|VT_ARRAY|VT_BYREF|VT_RESERVED,
375 VT_ARRAY|VT_RESERVED,
376 VT_ARRAY|VT_BYREF|VT_RESERVED,
377 VT_BYREF|VT_RESERVED,
380 /* Determine if a vt is valid for VariantClear() */
381 static int IsValidVariantClearVT(VARTYPE vt, VARTYPE extraFlags)
385 /* Only the following flags/types are valid */
386 if ((vt <= VT_LPWSTR || vt == VT_RECORD || vt == VT_CLSID) &&
388 (vt < (VARTYPE)24 || vt > (VARTYPE)31) &&
389 (!(extraFlags & (VT_BYREF|VT_ARRAY)) || vt > VT_NULL) &&
390 (extraFlags == 0 || extraFlags == VT_BYREF || extraFlags == VT_ARRAY ||
391 extraFlags == (VT_ARRAY|VT_BYREF)))
394 if ((vt == VT_RECORD && !HAVE_OLEAUT32_RECORD) ||
395 ((vt == VT_I8 || vt == VT_UI8) && !HAVE_OLEAUT32_I8))
396 ret = 0; /* Old versions of oleaut32 */
402 const IUnknownVtbl *lpVtbl;
405 } test_VariantClearImpl;
407 static HRESULT WINAPI VC_QueryInterface(LPUNKNOWN iface,REFIID riid,LPVOID *ppobj)
409 test_VariantClearImpl *This = (test_VariantClearImpl *)iface;
411 return E_NOINTERFACE;
414 static ULONG WINAPI VC_AddRef(LPUNKNOWN iface) {
415 test_VariantClearImpl *This = (test_VariantClearImpl *)iface;
417 return InterlockedIncrement(&This->ref);
420 static ULONG WINAPI VC_Release(LPUNKNOWN iface) {
421 test_VariantClearImpl *This = (test_VariantClearImpl *)iface;
422 /* static class, won't be freed */
424 return InterlockedDecrement(&This->ref);
427 static const IUnknownVtbl test_VariantClear_vtbl = {
433 static test_VariantClearImpl test_myVariantClearImpl = {&test_VariantClear_vtbl, 1, 0};
435 static void test_VariantClear(void)
444 /* Crashes: Native does not test input for NULL, so neither does Wine */
445 if (0) hres = VariantClear(NULL);
447 /* Only the type field is set, to VT_EMPTY */
450 hres = VariantClear(&v);
451 ok((hres == S_OK && V_VT(&v) == VT_EMPTY) ||
452 (IS_ANCIENT && hres == DISP_E_BADVARTYPE && V_VT(&v) == VT_UI4),
453 "VariantClear: Type set to %d, res %08x\n", V_VT(&v), hres);
454 ok(V_UI4(&v) == ~0u, "VariantClear: Overwrote value\n");
456 /* Test all possible V_VT values.
457 * Also demonstrates that null pointers in 'v' are not dereferenced.
458 * Individual variant tests should test VariantClear() with non-NULL values.
460 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
464 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
466 HRESULT hExpected = DISP_E_BADVARTYPE;
470 memset(&v, 0, sizeof(v));
471 V_VT(&v) = vt | ExtraFlags[i];
473 hres = VariantClear(&v);
475 if (IsValidVariantClearVT(vt, ExtraFlags[i]))
478 ok(hres == hExpected, "VariantClear: expected 0x%X, got 0x%X for vt %d | 0x%X\n",
479 hExpected, hres, vt, ExtraFlags[i]);
483 /* Some BYREF tests with non-NULL ptrs */
488 V_VT(&v) = VT_VARIANT | VT_BYREF;
489 V_VARIANTREF(&v) = &v2;
491 hres = VariantClear(&v);
492 ok(hres == S_OK, "ret %08x\n", hres);
493 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
494 ok(V_VARIANTREF(&v) == &v2, "variant ref %p\n", V_VARIANTREF(&v2));
495 ok(V_VT(&v2) == VT_I4, "vt %04x\n", V_VT(&v2));
496 ok(V_I4(&v2) == 0x1234, "i4 %04x\n", V_I4(&v2));
500 V_VT(&v) = VT_I4 | VT_BYREF;
503 hres = VariantClear(&v);
504 ok(hres == S_OK, "ret %08x\n", hres);
505 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
506 ok(V_I4REF(&v) == &i4, "i4 ref %p\n", V_I4REF(&v2));
507 ok(i4 == 0x4321, "i4 changed %08x\n", i4);
511 V_VT(&v) = VT_UNKNOWN;
512 V_UNKNOWN(&v) = (IUnknown*)&test_myVariantClearImpl;
513 test_myVariantClearImpl.events = 0;
514 hres = VariantClear(&v);
515 ok(hres == S_OK, "ret %08x\n", hres);
516 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
517 ok(V_UNKNOWN(&v) == (IUnknown*)&test_myVariantClearImpl, "unknown %p\n", V_UNKNOWN(&v));
518 /* Check that Release got called, but nothing else */
519 ok(test_myVariantClearImpl.events == 0x4, "Unexpected call. events %08x\n", test_myVariantClearImpl.events);
522 punk = (IUnknown*)&test_myVariantClearImpl;
523 V_VT(&v) = VT_UNKNOWN | VT_BYREF;
524 V_UNKNOWNREF(&v) = &punk;
525 test_myVariantClearImpl.events = 0;
526 hres = VariantClear(&v);
527 ok(hres == S_OK, "ret %08x\n", hres);
528 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
529 ok(V_UNKNOWNREF(&v) == &punk, "unknown ref %p\n", V_UNKNOWNREF(&v));
530 /* Check that nothing got called */
531 ok(test_myVariantClearImpl.events == 0, "Unexpected call. events %08x\n", test_myVariantClearImpl.events);
534 V_VT(&v) = VT_DISPATCH;
535 V_DISPATCH(&v) = (IDispatch*)&test_myVariantClearImpl;
536 test_myVariantClearImpl.events = 0;
537 hres = VariantClear(&v);
538 ok(hres == S_OK, "ret %08x\n", hres);
539 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
540 ok(V_DISPATCH(&v) == (IDispatch*)&test_myVariantClearImpl, "dispatch %p\n", V_DISPATCH(&v));
541 /* Check that Release got called, but nothing else */
542 ok(test_myVariantClearImpl.events == 0x4, "Unexpected call. events %08x\n", test_myVariantClearImpl.events);
545 punk = (IUnknown*)&test_myVariantClearImpl;
546 V_VT(&v) = VT_DISPATCH | VT_BYREF;
547 V_DISPATCHREF(&v) = (IDispatch**)&punk;
548 test_myVariantClearImpl.events = 0;
549 hres = VariantClear(&v);
550 ok(hres == S_OK, "ret %08x\n", hres);
551 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
552 ok(V_DISPATCHREF(&v) == (IDispatch**)&punk, "dispatch ref %p\n", V_DISPATCHREF(&v));
553 /* Check that nothing got called */
554 ok(test_myVariantClearImpl.events == 0, "Unexpected call. events %08x\n", test_myVariantClearImpl.events);
557 static void test_VariantCopy(void)
559 VARIANTARG vSrc, vDst;
562 HRESULT hres, hExpected;
564 /* Establish that the failure/other cases are dealt with. Individual tests
565 * for each type should verify that data is copied correctly, references
570 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
572 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
576 memset(&vSrc, 0, sizeof(vSrc));
577 V_VT(&vSrc) = vt | ExtraFlags[i];
579 hExpected = DISP_E_BADVARTYPE;
580 /* src is allowed to be a VT_CLSID */
581 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
584 hres = VariantCopy(&vSrc, &vSrc);
586 ok(hres == hExpected,
587 "Copy(src==dst): expected 0x%X, got 0x%X for src==dest vt %d|0x%X\n",
588 hExpected, hres, vt, ExtraFlags[i]);
592 /* Test that if VariantClear() fails on dest, the function fails. This also
593 * shows that dest is in fact cleared and not just overwritten
595 memset(&vSrc, 0, sizeof(vSrc));
596 V_VT(&vSrc) = VT_UI1;
598 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
600 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
604 hExpected = DISP_E_BADVARTYPE;
606 memset(&vDst, 0, sizeof(vDst));
607 V_VT(&vDst) = vt | ExtraFlags[i];
609 if (IsValidVariantClearVT(vt, ExtraFlags[i]))
612 hres = VariantCopy(&vDst, &vSrc);
614 ok(hres == hExpected,
615 "Copy(bad dst): expected 0x%X, got 0x%X for dest vt %d|0x%X\n",
616 hExpected, hres, vt, ExtraFlags[i]);
618 ok(V_VT(&vDst) == VT_UI1,
619 "Copy(bad dst): expected vt = VT_UI1, got %d\n", V_VT(&vDst));
623 /* Test that VariantClear() checks vSrc for validity before copying */
624 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
626 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
630 hExpected = DISP_E_BADVARTYPE;
632 memset(&vDst, 0, sizeof(vDst));
633 V_VT(&vDst) = VT_EMPTY;
635 memset(&vSrc, 0, sizeof(vSrc));
636 V_VT(&vSrc) = vt | ExtraFlags[i];
638 /* src is allowed to be a VT_CLSID */
639 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
642 hres = VariantCopy(&vDst, &vSrc);
644 ok(hres == hExpected,
645 "Copy(bad src): expected 0x%X, got 0x%X for src vt %d|0x%X\n",
646 hExpected, hres, vt, ExtraFlags[i]);
649 ok(V_VT(&vDst) == (vt|ExtraFlags[i]),
650 "Copy(bad src): expected vt = %d, got %d\n",
651 vt | ExtraFlags[i], V_VT(&vDst));
657 /* Test that copying a NULL BSTR results in an empty BSTR */
658 memset(&vDst, 0, sizeof(vDst));
659 V_VT(&vDst) = VT_EMPTY;
660 memset(&vSrc, 0, sizeof(vSrc));
661 V_VT(&vSrc) = VT_BSTR;
662 hres = VariantCopy(&vDst, &vSrc);
663 ok(hres == S_OK, "Copy(NULL BSTR): Failed to copy a NULL BSTR\n");
666 ok((V_VT(&vDst) == VT_BSTR) && V_BSTR(&vDst),
667 "Copy(NULL BSTR): should have non-NULL result\n");
668 if ((V_VT(&vDst) == VT_BSTR) && V_BSTR(&vDst))
670 ok(*V_BSTR(&vDst) == 0, "Copy(NULL BSTR): result not empty\n");
676 /* Determine if a vt is valid for VariantCopyInd() */
677 static int IsValidVariantCopyIndVT(VARTYPE vt, VARTYPE extraFlags)
681 if ((extraFlags & VT_ARRAY) ||
682 (vt > VT_NULL && vt != (VARTYPE)15 && vt < VT_VOID &&
683 !(extraFlags & (VT_VECTOR|VT_RESERVED))))
690 static void test_VariantCopyInd(void)
692 VARIANTARG vSrc, vDst, vRef, vRef2;
696 HRESULT hres, hExpected;
698 memset(buffer, 0, sizeof(buffer));
701 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
703 if (ExtraFlags[i] & VT_ARRAY)
704 continue; /* Native crashes on NULL safearray */
706 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
710 memset(&vSrc, 0, sizeof(vSrc));
711 V_VT(&vSrc) = vt | ExtraFlags[i];
713 hExpected = DISP_E_BADVARTYPE;
714 if (!(ExtraFlags[i] & VT_BYREF))
716 /* if src is not by-reference, acts as VariantCopy() */
717 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
722 if (vt == VT_SAFEARRAY || vt == VT_BSTR || vt == VT_UNKNOWN ||
723 vt == VT_DISPATCH || vt == VT_RECORD)
724 continue; /* Need valid ptrs for deep copies */
726 V_BYREF(&vSrc) = &buffer;
727 hExpected = E_INVALIDARG;
729 if ((vt == VT_I8 || vt == VT_UI8) &&
730 ExtraFlags[i] == VT_BYREF)
732 if (HAVE_OLEAUT32_I8)
733 hExpected = S_OK; /* Only valid if I8 is a known type */
735 else if (IsValidVariantCopyIndVT(vt, ExtraFlags[i]))
739 hres = VariantCopyInd(&vSrc, &vSrc);
741 ok(hres == hExpected,
742 "CopyInd(src==dst): expected 0x%X, got 0x%X for src==dst vt %d|0x%X\n",
743 hExpected, hres, vt, ExtraFlags[i]);
748 memset(&vSrc, 0, sizeof(vSrc));
749 V_VT(&vSrc) = VT_UI1|VT_BYREF;
750 V_BYREF(&vSrc) = &buffer;
752 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
754 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
758 memset(&vDst, 0, sizeof(vDst));
759 V_VT(&vDst) = vt | ExtraFlags[i];
761 hExpected = DISP_E_BADVARTYPE;
763 if (IsValidVariantClearVT(vt, ExtraFlags[i]))
766 hres = VariantCopyInd(&vDst, &vSrc);
768 ok(hres == hExpected,
769 "CopyInd(bad dst): expected 0x%X, got 0x%X for dst vt %d|0x%X\n",
770 hExpected, hres, vt, ExtraFlags[i]);
772 ok(V_VT(&vDst) == VT_UI1,
773 "CopyInd(bad dst): expected vt = VT_UI1, got %d\n", V_VT(&vDst));
778 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
780 if (ExtraFlags[i] & VT_ARRAY)
781 continue; /* Native crashes on NULL safearray */
783 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
787 memset(&vDst, 0, sizeof(vDst));
788 V_VT(&vDst) = VT_EMPTY;
790 memset(&vSrc, 0, sizeof(vSrc));
791 V_VT(&vSrc) = vt | ExtraFlags[i];
793 hExpected = DISP_E_BADVARTYPE;
794 if (!(ExtraFlags[i] & VT_BYREF))
796 /* if src is not by-reference, acts as VariantCopy() */
797 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
802 if (vt == VT_SAFEARRAY || vt == VT_BSTR || vt == VT_UNKNOWN ||
803 vt == VT_DISPATCH || vt == VT_RECORD)
804 continue; /* Need valid ptrs for deep copies, see vartype.c */
806 V_BYREF(&vSrc) = &buffer;
808 hExpected = E_INVALIDARG;
810 if ((vt == VT_I8 || vt == VT_UI8) &&
811 ExtraFlags[i] == VT_BYREF)
813 if (HAVE_OLEAUT32_I8)
814 hExpected = S_OK; /* Only valid if I8 is a known type */
816 else if (IsValidVariantCopyIndVT(vt, ExtraFlags[i]))
820 hres = VariantCopyInd(&vDst, &vSrc);
822 ok(hres == hExpected,
823 "CopyInd(bad src): expected 0x%X, got 0x%X for src vt %d|0x%X\n",
824 hExpected, hres, vt, ExtraFlags[i]);
827 if (vt == VT_VARIANT && ExtraFlags[i] == VT_BYREF)
829 /* Type of vDst should be the type of the referenced variant.
830 * Since we set the buffer to all zeros, its type should be
833 ok(V_VT(&vDst) == VT_EMPTY,
834 "CopyInd(bad src): expected dst vt = VT_EMPTY, got %d|0x%X\n",
835 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK);
839 ok(V_VT(&vDst) == (vt|(ExtraFlags[i] & ~VT_BYREF)),
840 "CopyInd(bad src): expected dst vt = %d|0x%X, got %d|0x%X\n",
841 vt, ExtraFlags[i] & ~VT_BYREF,
842 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK);
849 /* By-reference variants are dereferenced */
850 V_VT(&vRef) = VT_UI1;
852 V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
853 V_VARIANTREF(&vSrc) = &vRef;
856 hres = VariantCopyInd(&vDst, &vSrc);
857 ok(V_VT(&vDst) == VT_UI1 && V_UI1(&vDst) == 0x77,
858 "CopyInd(deref): expected dst vt = VT_UI1, val 0x77, got %d|0x%X, 0x%2X\n",
859 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK, V_UI1(&vDst));
861 /* By-reference variant to a by-reference type succeeds */
862 V_VT(&vRef) = VT_UI1|VT_BYREF;
863 V_UI1REF(&vRef) = buffer; buffer[0] = 0x88;
864 V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
865 V_VARIANTREF(&vSrc) = &vRef;
868 hres = VariantCopyInd(&vDst, &vSrc);
869 ok(V_VT(&vDst) == VT_UI1 && V_UI1(&vDst) == 0x88,
870 "CopyInd(deref): expected dst vt = VT_UI1, val 0x77, got %d|0x%X, 0x%2X\n",
871 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK, V_UI1(&vDst));
873 /* But a by-reference variant to a by-reference variant fails */
874 V_VT(&vRef2) = VT_UI1;
875 V_UI1(&vRef2) = 0x77;
876 V_VT(&vRef) = VT_VARIANT|VT_BYREF;
877 V_VARIANTREF(&vRef) = &vRef2;
878 V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
879 V_VARIANTREF(&vSrc) = &vRef;
882 hres = VariantCopyInd(&vDst, &vSrc);
883 ok(hres == E_INVALIDARG,
884 "CopyInd(ref->ref): expected E_INVALIDARG, got 0x%08x\n", hres);
887 static HRESULT (WINAPI *pVarParseNumFromStr)(OLECHAR*,LCID,ULONG,NUMPARSE*,BYTE*);
889 /* Macros for converting and testing the result of VarParseNumFromStr */
892 static HRESULT convert_str( const char *str, INT dig, ULONG flags,
893 NUMPARSE *np, BYTE rgb[128], LCID lcid )
896 MultiByteToWideChar( CP_ACP,0, str, -1, buff, sizeof(buff)/sizeof(WCHAR) );
897 memset( rgb, FAILDIG, 128 );
898 memset( np, 255, sizeof(*np) );
900 np->dwInFlags = flags;
901 return pVarParseNumFromStr( buff, lcid, LOCALE_NOUSEROVERRIDE, np, rgb);
904 static void expect_NumFromStr( int line, HRESULT hres, NUMPARSE *np, INT a, ULONG b, ULONG c,
905 INT d, INT e, INT f )
907 if (hres == (HRESULT)S_OK)
909 ok_(__FILE__,line)(np->cDig == a, "Expected cDig = %d, got %d\n", a, np->cDig);
910 ok_(__FILE__,line)(np->dwInFlags == b, "Expected dwInFlags = 0x%x, got 0x%x\n", b, np->dwInFlags);
911 ok_(__FILE__,line)(np->dwOutFlags == c, "Expected dwOutFlags = 0x%x, got 0x%x\n", c, np->dwOutFlags);
912 ok_(__FILE__,line)(np->cchUsed == d, "Expected cchUsed = %d, got %d\n", d, np->cchUsed);
913 ok_(__FILE__,line)(np->nBaseShift == e, "Expected nBaseShift = %d, got %d\n", e, np->nBaseShift);
914 ok_(__FILE__,line)(np->nPwr10 == f, "Expected nPwr10 = %d, got %d\n", f, np->nPwr10);
918 #define CONVERTN(str,dig,flags) hres = convert_str( str, dig, flags, &np, rgb, lcid )
919 #define CONVERT(str,flags) CONVERTN(str,sizeof(rgb),flags)
920 #define EXPECT(a,b,c,d,e,f) expect_NumFromStr( __LINE__, hres, &np, a, b, c, d, e, f )
921 #define EXPECTRGB(a,b) ok(rgb[a] == b, "Digit[%d], expected %d, got %d\n", a, b, rgb[a])
922 #define EXPECTFAIL ok(hres == (HRESULT)DISP_E_TYPEMISMATCH, "Call succeeded, hres = %08x\n", hres)
923 #define EXPECT2(a,b) EXPECTRGB(0,a); EXPECTRGB(1,b)
925 static void test_VarParseNumFromStr(void)
928 /* Ensure all tests are using the same locale characters for '$', ',' etc */
929 LCID lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
935 CHECKPTR(VarParseNumFromStr);
937 /* Consume a single digit */
942 /* cDig is not literal digits - zeros are suppressed and nPwr10 is increased */
945 /* Note: Win32 writes the trailing zeros if they are within cDig's limits,
946 * but then excludes them from the returned cDig count.
947 * In our implementation we don't bother writing them at all.
951 /* if cDig is too small and numbers follow, sets INEXACT */
953 EXPECT(1,0,NUMPRS_INEXACT,2,0,1);
956 /* Strips leading zeros */
961 /* Strips leading zeros */
967 /* Fails on non digits */
970 EXPECTRGB(0,FAILDIG);
972 /** NUMPRS_LEADING_WHITE/NUMPRS_TRAILING_WHITE **/
974 /* Without flag, fails on whitespace */
977 EXPECTRGB(0,FAILDIG);
980 /* With flag, consumes whitespace */
981 CONVERT(" 0", NUMPRS_LEADING_WHITE);
982 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
985 /* Test TAB once, then assume it acts as space for all cases */
986 CONVERT("\t0", NUMPRS_LEADING_WHITE);
987 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
991 /* Doesn't pick up trailing whitespace without flag */
996 /* With flag, consumes trailing whitespace */
997 CONVERT("0 ", NUMPRS_TRAILING_WHITE);
998 EXPECT(1,NUMPRS_TRAILING_WHITE,NUMPRS_TRAILING_WHITE,2,0,0);
1001 /* Leading flag only consumes leading */
1002 CONVERT(" 0 ", NUMPRS_LEADING_WHITE);
1003 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
1006 /* Both flags consumes both */
1007 CONVERT(" 0 ", NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE);
1008 EXPECT(1,NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE,NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE,3,0,0);
1011 /** NUMPRS_LEADING_PLUS/NUMPRS_TRAILING_PLUS **/
1013 /* Without flag, fails on + */
1016 EXPECTRGB(0,FAILDIG);
1018 /* With flag, consumes + */
1019 CONVERT("+0", NUMPRS_LEADING_PLUS);
1020 EXPECT(1,NUMPRS_LEADING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
1023 /* Without flag, doesn't consume trailing + */
1025 EXPECT(1,0,0,1,0,0);
1028 /* With flag, consumes trailing + */
1029 CONVERT("0+", NUMPRS_TRAILING_PLUS);
1030 EXPECT(1,NUMPRS_TRAILING_PLUS,NUMPRS_TRAILING_PLUS,2,0,0);
1033 /* With leading flag, doesn't consume trailing + */
1034 CONVERT("+0+", NUMPRS_LEADING_PLUS);
1035 EXPECT(1,NUMPRS_LEADING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
1038 /* Trailing + doesn't get consumed if we specify both (unlike whitespace) */
1039 CONVERT("+0+", NUMPRS_LEADING_PLUS|NUMPRS_TRAILING_PLUS);
1040 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_TRAILING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
1043 /** NUMPRS_LEADING_MINUS/NUMPRS_TRAILING_MINUS **/
1045 /* Without flag, fails on - */
1048 EXPECTRGB(0,FAILDIG);
1050 /* With flag, consumes - */
1051 CONVERT("-0", NUMPRS_LEADING_MINUS);
1052 EXPECT(1,NUMPRS_LEADING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
1055 /* Without flag, doesn't consume trailing - */
1057 EXPECT(1,0,0,1,0,0);
1060 /* With flag, consumes trailing - */
1061 CONVERT("0-", NUMPRS_TRAILING_MINUS);
1062 EXPECT(1,NUMPRS_TRAILING_MINUS,NUMPRS_NEG|NUMPRS_TRAILING_MINUS,2,0,0);
1065 /* With leading flag, doesn't consume trailing - */
1066 CONVERT("-0-", NUMPRS_LEADING_MINUS);
1067 EXPECT(1,NUMPRS_LEADING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
1070 /* Trailing - doesn't get consumed if we specify both (unlike whitespace) */
1071 CONVERT("-0-", NUMPRS_LEADING_MINUS|NUMPRS_TRAILING_MINUS);
1072 EXPECT(1,NUMPRS_LEADING_MINUS|NUMPRS_TRAILING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
1075 /** NUMPRS_HEX_OCT **/
1077 /* Could be hex, octal or decimal - With flag reads as decimal */
1078 CONVERT("0", NUMPRS_HEX_OCT);
1079 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
1082 /* Doesn't recognise hex in .asm syntax */
1083 CONVERT("0h", NUMPRS_HEX_OCT);
1084 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
1087 /* Doesn't fail with valid leading string but no digits */
1088 CONVERT("0x", NUMPRS_HEX_OCT);
1089 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
1092 /* Doesn't recognise hex format numbers at all! */
1093 CONVERT("0x0", NUMPRS_HEX_OCT);
1094 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
1097 /* Doesn't recognise plain hex digits either */
1098 CONVERT("FE", NUMPRS_HEX_OCT);
1100 EXPECTRGB(0,FAILDIG);
1103 CONVERT("0100", NUMPRS_HEX_OCT);
1104 EXPECT(1,NUMPRS_HEX_OCT,0,4,0,2);
1108 EXPECTRGB(3,FAILDIG);
1111 CONVERT("&HF800", NUMPRS_HEX_OCT);
1112 EXPECT(4,NUMPRS_HEX_OCT,0x40,6,4,0);
1117 EXPECTRGB(4,FAILDIG);
1119 /* VB hex lower case and leading zero */
1120 CONVERT("&h0abcdef", NUMPRS_HEX_OCT);
1121 EXPECT(6,NUMPRS_HEX_OCT,0x40,9,4,0);
1128 EXPECTRGB(6,FAILDIG);
1131 CONVERT("&O300", NUMPRS_HEX_OCT);
1132 EXPECT(3,NUMPRS_HEX_OCT,0x40,5,3,0);
1136 EXPECTRGB(3,FAILDIG);
1138 /* VB oct lower case and leading zero */
1139 CONVERT("&o0777", NUMPRS_HEX_OCT);
1140 EXPECT(3,NUMPRS_HEX_OCT,0x40,6,3,0);
1144 EXPECTRGB(3,FAILDIG);
1146 /* VB oct char bigger than 7 */
1147 CONVERT("&o128", NUMPRS_HEX_OCT);
1149 Native versions 2.x of oleaut32 allow this to succeed: later versions and Wine don't
1151 EXPECTRGB(0,FAILDIG);
1153 /** NUMPRS_PARENS **/
1155 /* Empty parens = error */
1156 CONVERT("()", NUMPRS_PARENS);
1158 EXPECTRGB(0,FAILDIG);
1160 /* With flag, trailing parens not consumed */
1161 CONVERT("0()", NUMPRS_PARENS);
1162 EXPECT(1,NUMPRS_PARENS,0,1,0,0);
1165 /* With flag, Number in parens made negative and parens consumed */
1166 CONVERT("(0)", NUMPRS_PARENS);
1167 EXPECT(1,NUMPRS_PARENS,NUMPRS_NEG|NUMPRS_PARENS,3,0,0);
1170 /** NUMPRS_THOUSANDS **/
1172 /* With flag, thousands sep. not needed */
1173 CONVERT("0", NUMPRS_THOUSANDS);
1174 EXPECT(1,NUMPRS_THOUSANDS,0,1,0,0);
1177 /* With flag, thousands sep. and following digits consumed */
1178 CONVERT("1,000", NUMPRS_THOUSANDS);
1179 EXPECT(1,NUMPRS_THOUSANDS,NUMPRS_THOUSANDS,5,0,3);
1182 /* With flag and decimal point, thousands sep. but not decimals consumed */
1183 CONVERT("1,000.0", NUMPRS_THOUSANDS);
1184 EXPECT(1,NUMPRS_THOUSANDS,NUMPRS_THOUSANDS,5,0,3);
1187 /** NUMPRS_CURRENCY **/
1189 /* Without flag, chokes on currency sign */
1192 EXPECTRGB(0,FAILDIG);
1194 /* With flag, consumes currency sign */
1195 CONVERT("$11", NUMPRS_CURRENCY);
1196 EXPECT(2,NUMPRS_CURRENCY,NUMPRS_CURRENCY,3,0,0);
1198 EXPECTRGB(2,FAILDIG);
1200 /* With flag only, doesn't consume decimal point */
1201 CONVERT("$11.1", NUMPRS_CURRENCY);
1202 EXPECT(2,NUMPRS_CURRENCY,NUMPRS_CURRENCY,3,0,0);
1204 EXPECTRGB(2,FAILDIG);
1206 /* With flag and decimal flag, consumes decimal point and following digits */
1207 CONVERT("$11.1", NUMPRS_CURRENCY|NUMPRS_DECIMAL);
1208 EXPECT(3,NUMPRS_CURRENCY|NUMPRS_DECIMAL,NUMPRS_CURRENCY|NUMPRS_DECIMAL,5,0,-1);
1211 EXPECTRGB(3,FAILDIG);
1213 /* Thousands flag can only be used with currency */
1214 CONVERT("$1,234", NUMPRS_CURRENCY|NUMPRS_THOUSANDS);
1215 EXPECT(4,NUMPRS_CURRENCY|NUMPRS_THOUSANDS,NUMPRS_CURRENCY|NUMPRS_THOUSANDS,6,0,0);
1219 EXPECTRGB(4,FAILDIG);
1221 /** NUMPRS_DECIMAL **/
1223 /* With flag, consumes decimal point */
1224 CONVERT("1.1", NUMPRS_DECIMAL);
1225 EXPECT(2,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1);
1227 EXPECTRGB(2,FAILDIG);
1229 /* With flag, consumes decimal point. Skipping the decimal part is not an error */
1230 CONVERT("1.", NUMPRS_DECIMAL);
1231 EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,2,0,0);
1234 /* Consumes only one decimal point */
1235 CONVERT("1.1.", NUMPRS_DECIMAL);
1236 EXPECT(2,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1);
1238 EXPECTRGB(2,FAILDIG);
1240 /** NUMPRS_EXPONENT **/
1242 /* Without flag, doesn't consume exponent */
1244 EXPECT(1,0,0,1,0,0);
1247 /* With flag, consumes exponent */
1248 CONVERT("1e1", NUMPRS_EXPONENT);
1249 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,1);
1252 /* Negative exponents are accepted without flags */
1253 CONVERT("1e-1", NUMPRS_EXPONENT);
1254 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,-1);
1257 /* As are positive exponents and leading exponent 0s */
1258 CONVERT("1e+01", NUMPRS_EXPONENT);
1259 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,5,0,1);
1262 /* The same for zero exponents */
1263 CONVERT("1e0", NUMPRS_EXPONENT);
1264 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,0);
1267 /* Sign on a zero exponent doesn't matter */
1268 CONVERT("1e+0", NUMPRS_EXPONENT);
1269 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,0);
1272 CONVERT("1e-0", NUMPRS_EXPONENT);
1273 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,0);
1276 /* Doesn't consume a real number exponent */
1277 CONVERT("1e1.", NUMPRS_EXPONENT);
1278 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,1);
1281 /* Powers of 10 are calculated from the position of any decimal point */
1282 CONVERT("1.5e20", NUMPRS_EXPONENT|NUMPRS_DECIMAL);
1283 EXPECT(2,NUMPRS_EXPONENT|NUMPRS_DECIMAL,NUMPRS_EXPONENT|NUMPRS_DECIMAL,6,0,19);
1286 CONVERT("1.5e-20", NUMPRS_EXPONENT|NUMPRS_DECIMAL);
1287 EXPECT(2,NUMPRS_EXPONENT|NUMPRS_DECIMAL,NUMPRS_EXPONENT|NUMPRS_DECIMAL,7,0,-21);
1290 /** NUMPRS_USE_ALL **/
1292 /* Flag expects all digits */
1293 CONVERT("0", NUMPRS_USE_ALL);
1294 EXPECT(1,NUMPRS_USE_ALL,0,1,0,0);
1297 /* Rejects anything trailing */
1298 CONVERT("0 ", NUMPRS_USE_ALL);
1302 /* Unless consumed by trailing flag */
1303 CONVERT("0 ", NUMPRS_USE_ALL|NUMPRS_TRAILING_WHITE);
1304 EXPECT(1,NUMPRS_USE_ALL|NUMPRS_TRAILING_WHITE,NUMPRS_TRAILING_WHITE,2,0,0);
1307 /** Combinations **/
1309 /* Leading whitespace and plus, doesn't consume trailing whitespace */
1310 CONVERT("+ 0 ", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1311 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,3,0,0);
1314 /* Order of whitespace and plus is unimportant */
1315 CONVERT(" +0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1316 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,3,0,0);
1319 /* Leading whitespace can be repeated */
1320 CONVERT(" + 0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1321 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,4,0,0);
1324 /* But plus/minus etc. cannot */
1325 CONVERT("+ +0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1327 EXPECTRGB(0,FAILDIG);
1329 /* Inexact is not set if trailing zeros are removed */
1330 CONVERTN("10", 1, 0);
1331 EXPECT(1,0,0,2,0,1);
1334 /* Make sure a leading 0 is stripped but decimals after it get read */
1335 CONVERT("-0.51", NUMPRS_STD);
1336 EXPECT(2,NUMPRS_STD,NUMPRS_NEG|NUMPRS_DECIMAL|NUMPRS_LEADING_MINUS,5,0,-2);
1339 /* Keep trailing zeros on whole number part of a decimal */
1340 CONVERT("10.1", NUMPRS_STD);
1341 EXPECT(3,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-1);
1345 /* Zeros after decimal sign */
1346 CONVERT("0.01", NUMPRS_STD);
1347 EXPECT(1,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-2);
1350 /* Trailing zeros after decimal part */
1351 CONVERT("0.10", NUMPRS_STD);
1352 EXPECT(1,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-1);
1356 static HRESULT (WINAPI *pVarNumFromParseNum)(NUMPARSE*,BYTE*,ULONG,VARIANT*);
1358 /* Macros for converting and testing the result of VarNumFromParseNum */
1359 #define SETRGB(indx,val) if (!indx) memset(rgb, FAILDIG, sizeof(rgb)); rgb[indx] = val
1361 #define CONVERT(a,b,c,d,e,f,bits) \
1362 np.cDig = (a); np.dwInFlags = (b); np.dwOutFlags = (c); np.cchUsed = (d); \
1363 np.nBaseShift = (e); np.nPwr10 = (f); hres = pVarNumFromParseNum(&np, rgb, bits, &vOut)
1364 static const char *szFailOverflow = "Expected overflow, hres = %08x\n";
1365 #define EXPECT_OVERFLOW ok(hres == (HRESULT)DISP_E_OVERFLOW, szFailOverflow, hres)
1366 static const char *szFailOk = "Call failed, hres = %08x\n";
1367 #define EXPECT_OK ok(hres == (HRESULT)S_OK, szFailOk, hres); \
1368 if (hres == (HRESULT)S_OK)
1369 #define EXPECT_TYPE(typ) ok(V_VT(&vOut) == typ,"Expected Type = " #typ ", got %d\n", V_VT(&vOut))
1370 #define EXPECT_I1(val) EXPECT_OK { EXPECT_TYPE(VT_I1); \
1371 ok(V_I1(&vOut) == val, "Expected i1 = %d, got %d\n", (signed char)val, V_I1(&vOut)); }
1372 #define EXPECT_UI1(val) EXPECT_OK { EXPECT_TYPE(VT_UI1); \
1373 ok(V_UI1(&vOut) == val, "Expected ui1 = %d, got %d\n", (BYTE)val, V_UI1(&vOut)); }
1374 #define EXPECT_I2(val) EXPECT_OK { EXPECT_TYPE(VT_I2); \
1375 ok(V_I2(&vOut) == val, "Expected i2 = %d, got %d\n", (SHORT)val, V_I2(&vOut)); }
1376 #define EXPECT_UI2(val) EXPECT_OK { EXPECT_TYPE(VT_UI2); \
1377 ok(V_UI2(&vOut) == val, "Expected ui2 = %d, got %d\n", (USHORT)val, V_UI2(&vOut)); }
1378 #define EXPECT_I4(val) EXPECT_OK { EXPECT_TYPE(VT_I4); \
1379 ok(V_I4(&vOut) == val, "Expected i4 = %d, got %d\n", (LONG)val, V_I4(&vOut)); }
1380 #define EXPECT_UI4(val) EXPECT_OK { EXPECT_TYPE(VT_UI4); \
1381 ok(V_UI4(&vOut) == val, "Expected ui4 = %d, got %d\n", (ULONG)val, V_UI4(&vOut)); }
1382 #define EXPECT_I8(high,low) EXPECT_OK { EXPECT_TYPE(VT_I8); \
1383 ok(V_I8(&vOut) == ((((LONG64)(high))<<32)|(low)), "Expected i8 = %x%08x, got %x%08x\n", \
1384 (LONG)(high), (LONG)(low), (LONG)(V_I8(&vOut)>>32), (LONG)V_I8(&vOut) ); }
1385 #define EXPECT_UI8(val) EXPECT_OK { EXPECT_TYPE(VT_UI8); \
1386 ok(V_UI8(&vOut) == val, "Expected ui8 = 0x%x%08x, got 0x%x%08x\n", \
1387 (DWORD)((ULONG64)val >> 32), (DWORD)(ULONG64)val, (DWORD)(V_UI8(&vOut) >> 32), (DWORD)V_UI8(&vOut)); }
1388 #define EXPECT_R4(val) EXPECT_OK { EXPECT_TYPE(VT_R4); \
1389 ok(V_R4(&vOut) == val, "Expected r4 = %f, got %f\n", val, V_R4(&vOut)); }
1390 #define EXPECT_R8(val) EXPECT_OK { EXPECT_TYPE(VT_R8); \
1391 ok(V_R8(&vOut) == val, "Expected r8 = %g, got %g\n", val, V_R8(&vOut)); }
1392 #define CY_MULTIPLIER 10000
1393 #define EXPECT_CY(val) EXPECT_OK { EXPECT_TYPE(VT_CY); \
1394 ok(V_CY(&vOut).int64 == (LONG64)(val * CY_MULTIPLIER), "Expected r8 = 0x%x%08x, got 0x%x%08x\n", \
1395 (DWORD)((LONG64)val >> 23), (DWORD)(LONG64)val, (DWORD)(V_CY(&vOut).int64 >>32), (DWORD)V_CY(&vOut).int64); }
1396 #define EXPECT_DECIMAL(valHi, valMid, valLo) EXPECT_OK { EXPECT_TYPE(VT_DECIMAL); \
1397 ok((V_DECIMAL(&vOut).Hi32 == valHi) && (S1(U1(V_DECIMAL(&vOut))).Mid32 == valMid) && \
1398 (S1(U1(V_DECIMAL(&vOut))).Lo32 == valLo), \
1399 "Expected decimal = %x/0x%x%08x, got %x/0x%x%08x\n", valHi, valMid, valLo, \
1400 V_DECIMAL(&vOut).Hi32, S1(U1(V_DECIMAL(&vOut))).Mid32, S1(U1(V_DECIMAL(&vOut))).Lo32); }
1402 static void test_VarNumFromParseNum(void)
1409 CHECKPTR(VarNumFromParseNum);
1411 /* Convert the number 1 to different types */
1412 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I1); EXPECT_I1(1);
1413 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_UI1); EXPECT_UI1(1);
1414 /* Prefers a signed type to unsigned of the same size */
1415 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I1|VTBIT_UI1); EXPECT_I1(1);
1416 /* But takes the smaller size if possible */
1417 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I2|VTBIT_UI1); EXPECT_UI1(1);
1419 /* Try different integer sizes */
1420 #define INTEGER_VTBITS (VTBIT_I1|VTBIT_UI1|VTBIT_I2|VTBIT_UI2|VTBIT_I4|VTBIT_UI4|VTBIT_I8|VTBIT_UI8)
1422 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, INTEGER_VTBITS); EXPECT_I1(1);
1424 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 7);
1425 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_I1(127);
1427 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 8);
1428 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_UI1(128);
1430 SETRGB(0, 2); SETRGB(1, 5); SETRGB(2, 5);
1431 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_UI1(255);
1433 SETRGB(0, 2); SETRGB(1, 5); SETRGB(2, 6);
1434 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_I2(256);
1436 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 7);
1437 CONVERT(5,0,0,5,0,0, INTEGER_VTBITS); EXPECT_I2(32767);
1439 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 8);
1440 CONVERT(5,0,0,5,0,0, INTEGER_VTBITS); EXPECT_UI2(32768);
1442 /* Assume the above pattern holds for remaining positive integers; test negative */
1445 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 8);
1446 CONVERT(3,0,NUMPRS_NEG,3,0,0, INTEGER_VTBITS); EXPECT_I1(-128);
1448 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 9);
1449 CONVERT(3,0,NUMPRS_NEG,3,0,0, INTEGER_VTBITS); EXPECT_I2(-129);
1451 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 8);
1452 CONVERT(5,0,NUMPRS_NEG,5,0,0, INTEGER_VTBITS); EXPECT_I2(-32768);
1454 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 9);
1455 CONVERT(5,0,NUMPRS_NEG,5,0,0, INTEGER_VTBITS); EXPECT_I4(-32769);
1457 /* Assume the above pattern holds for remaining negative integers */
1459 /* Test hexadecimal conversions */
1460 SETRGB(0, 1); CONVERT(1,0,0,1,4,0, INTEGER_VTBITS); EXPECT_I1(0x01);
1462 SETRGB(0, 7); SETRGB(1, 0xf);
1463 CONVERT(2,0,0,2,4,0, INTEGER_VTBITS); EXPECT_I1(0x7f);
1464 SETRGB(0, 7); SETRGB(1, 0xf);
1465 CONVERT(2,0,0,2,4,0, VTBIT_DECIMAL); EXPECT_DECIMAL(0,0,0x7f);
1467 SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
1468 CONVERT(4,0,0,4,4,0, INTEGER_VTBITS); EXPECT_I2(0x7fff);
1470 SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
1471 SETRGB(4, 0xf); SETRGB(5, 0xf); SETRGB(6, 0xf); SETRGB(7, 0xf);
1472 CONVERT(8,0,0,8,4,0, INTEGER_VTBITS); EXPECT_I4(0x7fffffffL);
1473 /* 0x7fffffffffffffff (64 bits) */
1474 SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
1475 SETRGB(4, 0xf); SETRGB(5, 0xf); SETRGB(6, 0xf); SETRGB(7, 0xf);
1476 SETRGB(8, 0xf); SETRGB(9, 0xf); SETRGB(10, 0xf); SETRGB(11, 0xf);
1477 SETRGB(12, 0xf); SETRGB(13, 0xf); SETRGB(14, 0xf); SETRGB(15, 0xf);
1478 if (HAVE_OLEAUT32_I8)
1480 /* We cannot use INTEGER_VTBITS as WinXP and Win2003 are broken(?). They
1481 truncate the number to the smallest integer size requested:
1482 CONVERT(16,0,0,16,4,0, INTEGER_VTBITS); EXPECT_I1((signed char)0xff); */
1483 CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x7fffffff,0xffffffff);
1486 /* Assume the above pattern holds for numbers without hi-bit set, test (preservation of) hi-bit */
1488 SETRGB(0, 8); SETRGB(1, 2);
1489 CONVERT(2,0,0,2,4,0, INTEGER_VTBITS);
1490 EXPECT_I1((signed char)0x82);
1492 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 2);
1493 CONVERT(4,0,0,4,4,0, INTEGER_VTBITS);
1494 EXPECT_I2((signed short)0x8002);
1496 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1497 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 2);
1498 CONVERT(8,0,0,8,4,0, INTEGER_VTBITS); EXPECT_I4(0x80000002);
1499 /* 0x8000000000000002 (64 bits) */
1500 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1501 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 0);
1502 SETRGB(8, 0); SETRGB(9, 0); SETRGB(10, 0); SETRGB(11, 0);
1503 SETRGB(12, 0); SETRGB(13, 0); SETRGB(14, 0); SETRGB(15, 2);
1504 if (HAVE_OLEAUT32_I8)
1506 /* We cannot use INTEGER_VTBITS as WinXP and Win2003 are broken(?). They
1507 truncate the number to the smallest integer size requested:
1508 CONVERT(16,0,0,16,4,0, INTEGER_VTBITS & ~VTBIT_I1);
1509 EXPECT_I2((signed short)0x0002); */
1510 CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x80000000,0x00000002);
1513 /* Test (preservation of) hi-bit with STRICT type requesting */
1515 SETRGB(0, 8); SETRGB(1, 2);
1516 CONVERT(2,0,0,2,4,0, VTBIT_I1);
1517 EXPECT_I1((signed char)0x82);
1519 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 2);
1520 CONVERT(4,0,0,4,4,0, VTBIT_I2);
1521 EXPECT_I2((signed short)0x8002);
1523 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1524 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 2);
1525 CONVERT(8,0,0,8,4,0, VTBIT_I4); EXPECT_I4(0x80000002);
1526 /* 0x8000000000000002 (64 bits) */
1527 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1528 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 0);
1529 SETRGB(8, 0); SETRGB(9, 0); SETRGB(10, 0); SETRGB(11, 0);
1530 SETRGB(12, 0); SETRGB(13, 0); SETRGB(14, 0); SETRGB(15, 2);
1531 if (HAVE_OLEAUT32_I8)
1533 CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x80000000,0x00000002);
1535 /* Assume the above pattern holds for numbers with hi-bit set */
1537 /* Negative numbers overflow if we have only unsigned outputs */
1539 SETRGB(0, 1); CONVERT(1,0,NUMPRS_NEG,1,0,0, VTBIT_UI1); EXPECT_OVERFLOW;
1541 SETRGB(0, 6); CONVERT(1,0,NUMPRS_NEG,1,0,~0u, VTBIT_UI1); EXPECT_OVERFLOW;
1543 /* Except that rounding is done first, so -0.5 to 0 are accepted as 0 */
1545 SETRGB(0, 5); CONVERT(1,0,NUMPRS_NEG,1,0,~0u, VTBIT_UI1); EXPECT_UI1(0);
1547 /* Floating point zero is OK */
1549 SETRGB(0, 0); CONVERT(1,0,NUMPRS_DECIMAL|NUMPRS_EXPONENT,12,0,-8, VTBIT_R8);
1552 /* Float is acceptable for an integer input value */
1553 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R4); EXPECT_R4(1.0f);
1555 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R8); EXPECT_R8(1.0);
1556 /* As is currency */
1557 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_CY); EXPECT_CY(1);
1559 /* Float is preferred over double */
1560 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R4|VTBIT_R8); EXPECT_R4(1.0f);
1562 /* Double is preferred over currency */
1563 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R8|VTBIT_CY); EXPECT_R8(1.0);
1565 /* Currency is preferred over decimal */
1566 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_CY|VTBIT_DECIMAL); EXPECT_CY(1);
1570 static void test_UdateFromDate( int line, DATE dt, ULONG flags, HRESULT r, WORD d, WORD m, WORD y,
1571 WORD h, WORD mn, WORD s, WORD ms, WORD dw, WORD dy)
1576 memset(&ud, 0, sizeof(ud));
1577 res = pVarUdateFromDate(dt, flags, &ud);
1578 ok_(__FILE__,line)(r == res, "Wrong result %x/%x\n", r, res);
1580 ok_(__FILE__,line)(ud.st.wYear == y && ud.st.wMonth == m && ud.st.wDay == d &&
1581 ud.st.wHour == h && ud.st.wMinute == mn && ud.st.wSecond == s &&
1582 ud.st.wMilliseconds == ms && ud.st.wDayOfWeek == dw && ud.wDayOfYear == dy,
1583 "%.16g expected %d,%d,%d,%d,%d,%d,%d %d %d, got %d,%d,%d,%d,%d,%d,%d %d %d\n",
1584 dt, d, m, y, h, mn, s, ms, dw, dy,
1585 ud.st.wDay, ud.st.wMonth, ud.st.wYear, ud.st.wHour, ud.st.wMinute,
1586 ud.st.wSecond, ud.st.wMilliseconds, ud.st.wDayOfWeek, ud.wDayOfYear );
1588 #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)
1590 static void test_VarUdateFromDate(void)
1592 CHECKPTR(VarUdateFromDate);
1593 DT2UD(29221.0,0,S_OK,1,1,1980,0,0,0,0,2,1); /* 1 Jan 1980 */
1594 DT2UD(29222.0,0,S_OK,2,1,1980,0,0,0,0,3,2); /* 2 Jan 1980 */
1595 DT2UD(33238.0,0,S_OK,31,12,1990,0,0,0,0,1,365); /* 31 Dec 1990 */
1596 DT2UD(0.0,0,S_OK,30,12,1899,0,0,0,0,6,364); /* 30 Dec 1899 - VT_DATE 0.0 */
1597 DT2UD(-657434.0,0,S_OK,1,1,100,0,0,0,0,5,1); /* 1 Jan 100 - Min */
1598 DT2UD(-657435.0,0,E_INVALIDARG,0,0,0,0,0,0,0,0,0); /* < 1 Jan 100 => err */
1599 DT2UD(2958465.0,0,S_OK,31,12,9999,0,0,0,0,5,365); /* 31 Dec 9999 - Max */
1600 DT2UD(2958466.0,0,E_INVALIDARG,0,0,0,0,0,0,0,0,0); /* > 31 Dec 9999 => err */
1602 /* VAR_VALIDDATE doesn't prevent upper and lower bounds being checked */
1603 DT2UD(-657435.0,VAR_VALIDDATE,E_INVALIDARG,0,0,0,0,0,0,0,0,0);
1604 DT2UD(2958466.0,VAR_VALIDDATE,E_INVALIDARG,0,0,0,0,0,0,0,0,0);
1607 DT2UD(29221.25,0,S_OK,1,1,1980,6,0,0,0,2,1); /* 6 AM */
1608 DT2UD(29221.33333333,0,S_OK,1,1,1980,8,0,0,0,2,1); /* 8 AM */
1609 DT2UD(29221.5,0,S_OK,1,1,1980,12,0,0,0,2,1); /* 12 AM */
1610 DT2UD(29221.9888884444,0,S_OK,1,1,1980,23,44,0,0,2,1); /* 11:44 PM */
1611 DT2UD(29221.7508765432,0,S_OK,1,1,1980,18,1,16,0,2,1); /* 6:18:02 PM */
1615 static void test_DateFromUDate( int line, WORD d, WORD m, WORD y, WORD h, WORD mn, WORD s, WORD ms,
1616 WORD dw, WORD dy, ULONG flags, HRESULT r, DATE dt )
1628 ud.st.wMilliseconds = ms;
1629 ud.st.wDayOfWeek = dw;
1631 res = pVarDateFromUdate(&ud, flags, &out);
1632 ok_(__FILE__,line)(r == res && (FAILED(r) || EQ_DOUBLE(out, dt)),
1633 "expected %x, %.16g, got %x, %.16g\n", r, dt, res, out);
1635 #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)
1637 static void test_VarDateFromUdate(void)
1639 CHECKPTR(VarDateFromUdate);
1640 UD2T(1,1,1980,0,0,0,0,2,1,0,S_OK,29221.0); /* 1 Jan 1980 */
1641 UD2T(2,1,1980,0,0,0,0,3,2,0,S_OK,29222.0); /* 2 Jan 1980 */
1642 UD2T(2,1,1980,0,0,0,0,4,5,0,S_OK,29222.0); /* 2 Jan 1980 */
1643 UD2T(31,12,1990,0,0,0,0,0,0,0,S_OK,33238.0); /* 31 Dec 1990 */
1644 UD2T(31,12,90,0,0,0,0,0,0,0,S_OK,33238.0); /* year < 100 is 1900+year! */
1645 UD2T(30,12,1899,0,0,0,0,6,364,0,S_OK,0.0); /* 30 Dec 1899 - VT_DATE 0.0 */
1646 UD2T(1,1,100,0,0,0,0,0,0,0,S_OK,-657434.0); /* 1 Jan 100 - Min */
1647 UD2T(31,12,9999,0,0,0,0,0,0,0,S_OK,2958465.0); /* 31 Dec 9999 - Max */
1648 UD2T(1,1,10000,0,0,0,0,0,0,0,E_INVALIDARG,0.0); /* > 31 Dec 9999 => err */
1649 UD2T(1,1,-10000,0,0,0,0,0,0,0,E_INVALIDARG,0.0);/* < -9999 => err */
1651 UD2T(30,12,1899,0,0,0,0,0,0,0,S_OK,0.0); /* 30 Dec 1899 0:00:00 */
1652 UD2T(30,12,1899,0,0,0,999,0,0,0,S_OK,0.0); /* Ignore milliseconds */
1654 UD2T(1,1,1980,18,1,16,0,2,1,0,S_OK,29221.75087962963); /* 6:18:02 PM */
1655 UD2T(1,300,1980,18,1,16,0,2,1,0,S_OK,38322.75087962963); /* Test fwdrolled month */
1656 UD2T(300,1,1980,18,1,16,0,2,1,0,S_OK,29520.75087962963); /* Test fwdrolled days */
1657 UD2T(0,1,1980,42,1,16,0,2,1,0,S_OK,29221.75087962963); /* Test fwdrolled hours */
1658 UD2T(1,1,1980,17,61,16,0,2,1,0,S_OK,29221.75087962963); /* Test fwdrolled minutes */
1659 UD2T(1,1,1980,18,0,76,0,2,1,0,S_OK,29221.75087962963); /* Test fwdrolled seconds */
1660 UD2T(1,-300,1980,18,1,16,0,2,1,0,S_OK,20059.75087962963); /* Test backrolled month */
1661 UD2T(-300,1,1980,18,1,16,0,2,1,0,S_OK,28920.75087962963); /* Test backrolled days */
1662 UD2T(3,1,1980,-30,1,16,0,2,1,0,S_OK,29221.75087962963); /* Test backrolled hours */
1663 UD2T(1,1,1980,20,-119,16,0,2,1,0,S_OK,29221.75087962963); /* Test backrolled minutes */
1664 UD2T(1,1,1980,18,3,-104,0,2,1,0,S_OK,29221.75087962963); /* Test backrolled seconds */
1665 UD2T(1,12001,-1020,18,1,16,0,0,0,0,S_OK,29221.75087962963); /* Test rolled year and month */
1666 UD2T(1,-23,1982,18,1,16,0,0,0,0,S_OK,29221.75087962963); /* Test backrolled month */
1667 UD2T(-59,3,1980,18,1,16,0,0,0,0,S_OK,29221.75087962963); /* Test backrolled days */
1668 todo_wine UD2T(1,1,0,0,0,0,0,0,0,0,S_OK,36526); /* Test zero year */
1669 UD2T(0,0,1980,0,0,0,0,0,0,0,S_OK,29189); /* Test zero day and month */
1670 UD2T(0,1,1980,0,0,0,0,2,1,0,S_OK,29220.0); /* Test zero day = LastDayOfMonth */
1671 UD2T(-1,1,1980,18,1,16,0,0,0,0,S_OK,29219.75087962963); /* Test day -1 = LastDayOfMonth - 1 */
1672 UD2T(1,1,-1,18,1,16,0,0,0,0,S_OK,36161.75087962963); /* Test year -1 = 1999 */
1673 UD2T(1,-1,1980,18,1,16,0,0,0,0,S_OK,29160.7508796296); /* Test month -1 = 11 */
1674 UD2T(1,13,1980,0,0,0,0,2,1,0,S_OK,29587.0); /* Rolls fwd to 1/1/1981 */
1677 static void test_st2dt(int line, WORD d, WORD m, WORD y, WORD h, WORD mn,
1678 WORD s, WORD ms, INT r, double dt)
1690 st.wMilliseconds = ms;
1692 res = pSystemTimeToVariantTime(&st, &out);
1693 ok_(__FILE__,line)(r == res && (!r || EQ_DOUBLE(out, dt)),
1694 "expected %d, %.16g, got %d, %.16g\n", r, dt, res, out);
1696 #define ST2DT(d,m,y,h,mn,s,ms,r,dt) test_st2dt(__LINE__,d,m,y,h,mn,s,ms,r,dt)
1698 static void test_SystemTimeToVariantTime(void)
1700 CHECKPTR(SystemTimeToVariantTime);
1701 ST2DT(1,1,1980,0,0,0,0,TRUE,29221.0);
1702 ST2DT(2,1,1980,0,0,0,0,TRUE,29222.0);
1703 ST2DT(0,1,1980,0,0,0,0,TRUE,29220.0); /* Rolls back to 31 Dec 1899 */
1704 ST2DT(1,13,1980,0,0,0,0,FALSE,29587.0); /* Fails on invalid month */
1705 ST2DT(31,12,90,0,0,0,0,TRUE,33238.0); /* year < 100 is 1900+year! */
1708 static void test_dt2st(int line, double dt, INT r, WORD d, WORD m, WORD y,
1709 WORD h, WORD mn, WORD s, WORD ms)
1714 memset(&st, 0, sizeof(st));
1715 res = pVariantTimeToSystemTime(dt, &st);
1716 ok_(__FILE__,line)(r == res &&
1717 (!r || (st.wYear == y && st.wMonth == m && st.wDay == d &&
1718 st.wHour == h && st.wMinute == mn &&
1719 st.wSecond == s && st.wMilliseconds == ms)),
1720 "%.16g expected %d, %d,%d,%d,%d,%d,%d,%d, got %d, %d,%d,%d,%d,%d,%d,%d\n",
1721 dt, r, d, m, y, h, mn, s, ms, res, st.wDay, st.wMonth,
1722 st.wYear, st.wHour, st.wMinute, st.wSecond,
1725 #define DT2ST(dt,r,d,m,y,h,mn,s,ms) test_dt2st(__LINE__,dt,r,d,m,y,h,mn,s,ms)
1727 static void test_VariantTimeToSystemTime(void)
1729 CHECKPTR(VariantTimeToSystemTime);
1730 DT2ST(29221.0,1,1,1,1980,0,0,0,0);
1731 DT2ST(29222.0,1,2,1,1980,0,0,0,0);
1734 #define MKDOSDATE(d,m,y) ((d & 0x1f) | ((m & 0xf) << 5) | (((y-1980) & 0x7f) << 9))
1735 #define MKDOSTIME(h,m,s) (((s>>1) & 0x1f) | ((m & 0x3f) << 5) | ((h & 0x1f) << 11))
1737 static void test_dos2dt(int line, WORD d, WORD m, WORD y, WORD h, WORD mn,
1738 WORD s, INT r, double dt)
1740 unsigned short dosDate, dosTime;
1745 dosDate = MKDOSDATE(d, m, y);
1746 dosTime = MKDOSTIME(h, mn, s);
1747 res = pDosDateTimeToVariantTime(dosDate, dosTime, &out);
1748 ok_(__FILE__,line)(r == res && (!r || EQ_DOUBLE(out, dt)),
1749 "expected %d, %.16g, got %d, %.16g\n", r, dt, res, out);
1751 #define DOS2DT(d,m,y,h,mn,s,r,dt) test_dos2dt(__LINE__,d,m,y,h,mn,s,r,dt)
1753 static void test_DosDateTimeToVariantTime(void)
1755 CHECKPTR(DosDateTimeToVariantTime);
1758 DOS2DT(1,1,1980,0,0,0,1,29221.0); /* 1/1/1980 */
1759 DOS2DT(31,12,2099,0,0,0,1,73050.0); /* 31/12/2099 */
1760 /* Dates are limited to the dos date max of 31/12/2099 */
1761 DOS2DT(31,12,2100,0,0,0,0,0.0); /* 31/12/2100 */
1762 /* Days and months of 0 cause date to roll back 1 day or month */
1763 DOS2DT(0,1,1980,0,0,0,1,29220.0); /* 0 Day => 31/12/1979 */
1764 DOS2DT(1,0,1980,0,0,0,1,29190.0); /* 0 Mth => 1/12/1979 */
1765 DOS2DT(0,0,1980,0,0,0,1,29189.0); /* 0 D/M => 30/11/1979 */
1766 /* Days > days in the month cause date to roll forward 1 month */
1767 DOS2DT(29,2,1981,0,0,0,1,29646.0); /* 29/2/1981 -> 3/1/1980 */
1768 DOS2DT(30,2,1981,0,0,0,1,29647.0); /* 30/2/1981 -> 4/1/1980 */
1769 /* Takes leap years into account when rolling forward */
1770 DOS2DT(29,2,1980,0,0,0,1,29280.0); /* 2/29/1980 */
1771 /* Months > 12 cause an error */
1772 DOS2DT(2,13,1980,0,0,0,0,0.0);
1775 DOS2DT(1,1,1980,0,0,29,1,29221.00032407407); /* 1/1/1980 12:00:28 AM */
1776 DOS2DT(1,1,1980,0,0,31,1,29221.00034722222); /* 1/1/1980 12:00:30 AM */
1777 DOS2DT(1,1,1980,0,59,0,1,29221.04097222222); /* 1/1/1980 12:59:00 AM */
1778 DOS2DT(1,1,1980,0,60,0,0,0.0); /* Invalid minutes */
1779 DOS2DT(1,1,1980,0,0,60,0,0.0); /* Invalid seconds */
1780 DOS2DT(1,1,1980,23,0,0,1,29221.95833333333); /* 1/1/1980 11:00:00 PM */
1781 DOS2DT(1,1,1980,24,0,0,0,0.0); /* Invalid hours */
1784 static void test_dt2dos(int line, double dt, INT r, WORD d, WORD m, WORD y,
1785 WORD h, WORD mn, WORD s)
1787 unsigned short dosDate, dosTime, expDosDate, expDosTime;
1790 dosTime = dosDate = 0;
1791 expDosDate = MKDOSDATE(d,m,y);
1792 expDosTime = MKDOSTIME(h,mn,s);
1793 res = pVariantTimeToDosDateTime(dt, &dosDate, &dosTime);
1794 ok_(__FILE__,line)(r == res && (!r || (dosTime == expDosTime && dosDate == expDosDate)),
1795 "%g: expected %d,%d(%d/%d/%d),%d(%d:%d:%d) got %d,%d(%d/%d/%d),%d(%d:%d:%d)\n",
1796 dt, r, expDosDate, expDosDate & 0x1f,
1797 (expDosDate >> 5) & 0xf, 1980 + (expDosDate >> 9),
1798 expDosTime, expDosTime >> 11, (expDosTime >> 5) & 0x3f,
1799 (expDosTime & 0x1f),
1800 res, dosDate, dosDate & 0x1f, (dosDate >> 5) & 0xf,
1801 1980 + (dosDate >> 9), dosTime, dosTime >> 11,
1802 (dosTime >> 5) & 0x3f, (dosTime & 0x1f));
1804 #define DT2DOS(dt,r,d,m,y,h,mn,s) test_dt2dos(__LINE__,dt,r,d,m,y,h,mn,s)
1806 static void test_VariantTimeToDosDateTime(void)
1808 CHECKPTR(VariantTimeToDosDateTime);
1811 DT2DOS(29221.0,1,1,1,1980,0,0,0); /* 1/1/1980 */
1812 DT2DOS(73050.0,1,31,12,2099,0,0,0); /* 31/12/2099 */
1813 DT2DOS(29220.0,0,0,0,0,0,0,0); /* 31/12/1979 - out of range */
1814 DT2DOS(73415.0,0,0,0,0,0,0,0); /* 31/12/2100 - out of range */
1817 DT2DOS(29221.00032407407,1,1,1,1980,0,0,29); /* 1/1/1980 12:00:28 AM */
1818 DT2DOS(29221.00034722222,1,1,1,1980,0,0,31); /* 1/1/1980 12:00:30 AM */
1819 DT2DOS(29221.04097222222,1,1,1,1980,0,59,0); /* 1/1/1980 12:59:00 AM */
1820 DT2DOS(29221.95833333333,1,1,1,1980,23,0,0); /* 1/1/1980 11:00:00 PM */
1823 static HRESULT (WINAPI *pVarAbs)(LPVARIANT,LPVARIANT);
1825 #define VARABS(vt,val,rvt,rval) \
1826 V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
1827 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
1828 test_var_call1( __LINE__, pVarAbs, &v, &exp )
1830 static void test_VarAbs(void)
1832 static WCHAR szNum[] = {'-','1','.','1','\0' };
1835 VARIANT v, vDst, exp;
1840 /* Test all possible V_VT values.
1842 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
1846 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
1848 HRESULT hExpected = DISP_E_BADVARTYPE;
1852 memset(&v, 0, sizeof(v));
1853 V_VT(&v) = vt | ExtraFlags[i];
1854 V_VT(&vDst) = VT_EMPTY;
1856 hres = pVarAbs(&v,&vDst);
1857 if (ExtraFlags[i] & (VT_ARRAY|VT_ARRAY) ||
1858 (!ExtraFlags[i] && (vt == VT_UNKNOWN || vt == VT_BSTR ||
1859 vt == VT_DISPATCH || vt == VT_ERROR || vt == VT_RECORD)))
1861 hExpected = DISP_E_TYPEMISMATCH;
1863 else if (ExtraFlags[i] || vt >= VT_CLSID || vt == VT_VARIANT)
1865 hExpected = DISP_E_BADVARTYPE;
1867 else if (IsValidVariantClearVT(vt, ExtraFlags[i]))
1870 /* Native always fails on some vartypes that should be valid. don't
1871 * check that Wine does the same; these are bugs in native.
1873 if (vt == VT_I8 || vt == VT_UI8 || vt == VT_INT || vt == VT_UINT ||
1874 vt == VT_I1 || vt == VT_UI2 || vt == VT_UI4)
1876 ok(hres == hExpected, "VarAbs: expected 0x%X, got 0x%X for vt %d | 0x%X\n",
1877 hExpected, hres, vt, ExtraFlags[i]);
1881 /* BOOL->I2, BSTR->R8, all others remain the same */
1882 VARABS(BOOL,VARIANT_TRUE,I2,-VARIANT_TRUE);
1883 VARABS(BOOL,VARIANT_FALSE,I2,VARIANT_FALSE);
1884 VARABS(EMPTY,0,I2,0);
1885 VARABS(EMPTY,1,I2,0);
1886 VARABS(NULL,0,NULL,0);
1887 VARABS(NULL,1,NULL,0);
1892 VARABS(UI1,1,UI1,1);
1897 VARABS(DATE,1,DATE,1);
1898 VARABS(DATE,-1,DATE,1);
1900 V_CY(&v).int64 = -10000;
1901 memset(&vDst,0,sizeof(vDst));
1902 hres = pVarAbs(&v,&vDst);
1903 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
1904 "VarAbs(CY): expected 0x0 got 0x%X\n", hres);
1905 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char));
1908 trace("Skipping VarAbs(BSTR) as decimal separator is '%s'\n", buff);
1914 V_BSTR(&v) = (BSTR)szNum;
1915 memset(&vDst,0,sizeof(vDst));
1916 hres = pVarAbs(&v,&vDst);
1917 ok(hres == S_OK && V_VT(&vDst) == VT_R8 && V_R8(&vDst) == 1.1,
1918 "VarAbs: expected 0x0,%d,%g, got 0x%X,%d,%g\n", VT_R8, 1.1, hres, V_VT(&vDst), V_R8(&vDst));
1921 static HRESULT (WINAPI *pVarNot)(LPVARIANT,LPVARIANT);
1923 #define VARNOT(vt,val,rvt,rval) \
1924 V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
1925 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
1926 test_var_call1( __LINE__, pVarNot, &v, &exp )
1928 static void test_VarNot(void)
1930 static const WCHAR szNum0[] = {'0','\0' };
1931 static const WCHAR szNum1[] = {'1','\0' };
1933 VARIANT v, exp, vDst;
1934 DECIMAL *pdec = &V_DECIMAL(&v);
1935 CY *pcy = &V_CY(&v);
1940 /* Test all possible V_VT values */
1941 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
1945 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
1947 HRESULT hExpected = DISP_E_BADVARTYPE;
1951 memset(&v, 0, sizeof(v));
1952 V_VT(&v) = vt | ExtraFlags[i];
1953 V_VT(&vDst) = VT_EMPTY;
1957 case VT_I1: case VT_UI1: case VT_I2: case VT_UI2:
1958 case VT_INT: case VT_UINT: case VT_I4: case VT_UI4:
1959 case VT_R4: case VT_R8:
1960 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
1961 case VT_DATE: case VT_CY:
1964 case VT_I8: case VT_UI8:
1965 if (HAVE_OLEAUT32_I8)
1969 if (HAVE_OLEAUT32_RECORD)
1970 hExpected = DISP_E_TYPEMISMATCH;
1972 case VT_UNKNOWN: case VT_BSTR: case VT_DISPATCH: case VT_ERROR:
1973 hExpected = DISP_E_TYPEMISMATCH;
1976 if (IsValidVariantClearVT(vt, ExtraFlags[i]) && vt != VT_CLSID)
1977 hExpected = DISP_E_TYPEMISMATCH;
1981 hres = pVarNot(&v,&vDst);
1982 ok(hres == hExpected, "VarNot: expected 0x%X, got 0x%X vt %d|0x%X\n",
1983 hExpected, hres, vt, ExtraFlags[i]);
1986 /* Test the values returned by all cases that can succeed */
1987 VARNOT(EMPTY,0,I2,-1);
1988 VARNOT(EMPTY,1,I2,-1);
1989 VARNOT(NULL,0,NULL,0);
1990 VARNOT(NULL,1,NULL,0);
1991 VARNOT(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
1992 VARNOT(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
2000 VARNOT(UI1,1,UI1,254);
2001 VARNOT(UI1,0,UI1,255);
2002 VARNOT(UI2,0,I4,-1);
2003 VARNOT(UI2,1,I4,-2);
2004 VARNOT(UI4,0,I4,-1);
2005 VARNOT(UI4,1,I4,-2);
2006 VARNOT(INT,0,I4,-1);
2007 VARNOT(INT,1,I4,-2);
2008 VARNOT(UINT,0,I4,-1);
2009 VARNOT(UINT,1,I4,-2);
2010 if (HAVE_OLEAUT32_I8)
2014 VARNOT(UI8,0,I4,-1);
2015 VARNOT(UI8,1,I4,-2);
2021 VARNOT(DATE,1,I4,-2);
2022 VARNOT(DATE,0,I4,-1);
2023 VARNOT(BSTR,(BSTR)szNum0,I4,-1);
2024 ok(V_VT(&v) == VT_BSTR && V_BSTR(&v) == szNum0, "VarNot(0): changed input\n");
2025 VARNOT(BSTR,(BSTR)szNum1,I4,-2);
2026 ok(V_VT(&v) == VT_BSTR && V_BSTR(&v) == szNum1, "VarNot(1): changed input\n");
2028 V_VT(&v) = VT_DECIMAL;
2029 S(U(*pdec)).sign = DECIMAL_NEG;
2030 S(U(*pdec)).scale = 0;
2032 S1(U1(*pdec)).Mid32 = 0;
2033 S1(U1(*pdec)).Lo32 = 1;
2034 VARNOT(DECIMAL,*pdec,I4,0);
2037 VARNOT(CY,*pcy,I4,-2);
2040 VARNOT(CY,*pcy,I4,-1);
2043 VARNOT(CY,*pcy,I4,-1);
2046 static HRESULT (WINAPI *pVarSub)(LPVARIANT,LPVARIANT,LPVARIANT);
2048 #define VARSUB(vt1,val1,vt2,val2,rvt,rval) \
2049 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
2050 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
2051 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
2052 test_var_call2( __LINE__, pVarSub, &left, &right, &exp )
2054 static void test_VarSub(void)
2056 VARIANT left, right, exp, result, cy, dec;
2059 HRESULT hres, expectedhres;
2064 lbstr = SysAllocString(sz12);
2065 rbstr = SysAllocString(sz12);
2068 VariantInit(&right);
2069 VariantInit(&result);
2071 /* Test all possible flag/vt combinations & the resulting vt type */
2072 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2075 VARTYPE leftvt, rightvt, resvt;
2077 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
2082 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
2086 expectedhres = S_OK;
2088 memset(&left, 0, sizeof(left));
2089 memset(&right, 0, sizeof(right));
2090 V_VT(&left) = leftvt | ExtraFlags[i];
2091 if (leftvt == VT_BSTR)
2092 V_BSTR(&left) = lbstr;
2093 V_VT(&right) = rightvt | ExtraFlags[i];
2094 if (rightvt == VT_BSTR)
2095 V_BSTR(&right) = rbstr;
2096 V_VT(&result) = VT_EMPTY;
2099 /* All extra flags produce errors */
2100 if (ExtraFlags[i] == (VT_VECTOR|VT_BYREF|VT_RESERVED) ||
2101 ExtraFlags[i] == (VT_VECTOR|VT_RESERVED) ||
2102 ExtraFlags[i] == (VT_VECTOR|VT_BYREF) ||
2103 ExtraFlags[i] == (VT_BYREF|VT_RESERVED) ||
2104 ExtraFlags[i] == VT_VECTOR ||
2105 ExtraFlags[i] == VT_BYREF ||
2106 ExtraFlags[i] == VT_RESERVED)
2108 expectedhres = DISP_E_BADVARTYPE;
2111 else if (ExtraFlags[i] >= VT_ARRAY)
2113 expectedhres = DISP_E_TYPEMISMATCH;
2116 /* Native VarSub cannot handle: VT_I1, VT_UI2, VT_UI4,
2117 VT_INT, VT_UINT and VT_UI8. Tested with WinXP */
2118 else if (!IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
2119 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
2120 leftvt == VT_CLSID || rightvt == VT_CLSID ||
2121 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
2122 leftvt == VT_I1 || rightvt == VT_I1 ||
2123 leftvt == VT_UI2 || rightvt == VT_UI2 ||
2124 leftvt == VT_UI4 || rightvt == VT_UI4 ||
2125 leftvt == VT_UI8 || rightvt == VT_UI8 ||
2126 leftvt == VT_INT || rightvt == VT_INT ||
2127 leftvt == VT_UINT || rightvt == VT_UINT ||
2128 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN ||
2129 leftvt == VT_RECORD || rightvt == VT_RECORD)
2131 if (leftvt == VT_RECORD && rightvt == VT_I8)
2133 if (HAVE_OLEAUT32_I8)
2134 expectedhres = DISP_E_TYPEMISMATCH;
2136 expectedhres = DISP_E_BADVARTYPE;
2138 else if (leftvt < VT_UI1 && rightvt == VT_RECORD)
2139 expectedhres = DISP_E_TYPEMISMATCH;
2140 else if (leftvt >= VT_UI1 && rightvt == VT_RECORD)
2141 expectedhres = DISP_E_TYPEMISMATCH;
2142 else if (leftvt == VT_RECORD && rightvt <= VT_UI1)
2143 expectedhres = DISP_E_TYPEMISMATCH;
2144 else if (leftvt == VT_RECORD && rightvt > VT_UI1)
2145 expectedhres = DISP_E_BADVARTYPE;
2147 expectedhres = DISP_E_BADVARTYPE;
2150 else if ((leftvt == VT_NULL && rightvt == VT_DISPATCH) ||
2151 (leftvt == VT_DISPATCH && rightvt == VT_NULL))
2153 else if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
2154 leftvt == VT_ERROR || rightvt == VT_ERROR)
2157 expectedhres = DISP_E_TYPEMISMATCH;
2159 else if (leftvt == VT_NULL || rightvt == VT_NULL)
2161 else if ((leftvt == VT_EMPTY && rightvt == VT_BSTR) ||
2162 (leftvt == VT_DATE && rightvt == VT_DATE) ||
2163 (leftvt == VT_BSTR && rightvt == VT_EMPTY) ||
2164 (leftvt == VT_BSTR && rightvt == VT_BSTR))
2166 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
2168 else if (leftvt == VT_DATE || rightvt == VT_DATE)
2170 else if (leftvt == VT_CY || rightvt == VT_CY)
2172 else if (leftvt == VT_R8 || rightvt == VT_R8)
2174 else if (leftvt == VT_BSTR || rightvt == VT_BSTR) {
2176 } else if (leftvt == VT_R4 || rightvt == VT_R4) {
2177 if (leftvt == VT_I4 || rightvt == VT_I4 ||
2178 leftvt == VT_I8 || rightvt == VT_I8)
2183 else if (leftvt == VT_I8 || rightvt == VT_I8)
2185 else if (leftvt == VT_I4 || rightvt == VT_I4)
2187 else if (leftvt == VT_I2 || rightvt == VT_I2 ||
2188 leftvt == VT_BOOL || rightvt == VT_BOOL ||
2189 (leftvt == VT_EMPTY && rightvt == VT_EMPTY))
2191 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
2196 expectedhres = DISP_E_TYPEMISMATCH;
2199 hres = pVarSub(&left, &right, &result);
2201 ok(hres == expectedhres && V_VT(&result) == resvt,
2202 "VarSub: %d|0x%X, %d|0x%X: Expected failure 0x%X, "
2203 "got 0x%X, expected vt %d got vt %d\n",
2204 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i],
2205 expectedhres, hres, resvt, V_VT(&result));
2210 /* Test returned values */
2211 VARSUB(I4,4,I4,2,I4,2);
2212 VARSUB(I2,4,I2,2,I2,2);
2213 VARSUB(I2,-13,I4,5,I4,-18);
2214 VARSUB(I4,-13,I4,5,I4,-18);
2215 VARSUB(I2,7,R4,0.5f,R4,6.5f);
2216 VARSUB(R4,0.5f,I4,5,R8,-4.5);
2217 VARSUB(R8,7.1,BOOL,0,R8,7.1);
2218 VARSUB(BSTR,lbstr,I2,4,R8,8);
2219 VARSUB(BSTR,lbstr,BOOL,1,R8,11);
2220 VARSUB(BSTR,lbstr,R4,0.1f,R8,11.9);
2221 VARSUB(R4,0.2f,BSTR,rbstr,R8,-11.8);
2222 VARSUB(DATE,2.25,I4,7,DATE,-4.75);
2223 VARSUB(DATE,1.25,R4,-1.7f,DATE,2.95);
2225 VARSUB(UI1, UI1_MAX, UI1, UI1_MAX, UI1, 0);
2226 VARSUB(I2, I2_MAX, I2, I2_MAX, I2, 0);
2227 VARSUB(I2, I2_MIN, I2, I2_MIN, I2, 0);
2228 VARSUB(I4, I4_MAX, I4, I4_MAX, I4, 0);
2229 VARSUB(I4, I4_MIN, I4, I4_MIN, I4, 0);
2230 VARSUB(R4, R4_MAX, R4, R4_MAX, R4, 0.0f);
2231 VARSUB(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX - R4_MIN);
2232 VARSUB(R4, R4_MIN, R4, R4_MIN, R4, 0.0f);
2233 VARSUB(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX - R8_MIN);
2234 VARSUB(R8, R8_MIN, R8, R8_MIN, R8, 0.0);
2236 /* Manually test BSTR + BSTR */
2237 V_VT(&left) = VT_BSTR;
2238 V_BSTR(&left) = lbstr;
2239 V_VT(&right) = VT_BSTR;
2240 V_BSTR(&right) = rbstr;
2241 hres = VarSub(&left, &right, &result);
2242 ok(hres == S_OK && V_VT(&result) == VT_R8,
2243 "VarSub: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
2244 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 0),
2245 "VarSub: BSTR + BSTR, expected %f got %f\n", 0.0, V_R8(&result));
2247 /* Manually test some VT_CY and VT_DECIMAL variants */
2249 hres = VarCyFromI4(4711, &V_CY(&cy));
2250 ok(hres == S_OK, "VarCyFromI4 failed!\n");
2251 V_VT(&dec) = VT_DECIMAL;
2252 hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec));
2253 ok(hres == S_OK, "VarDecFromR4 failed!\n");
2254 memset(&left, 0, sizeof(left));
2255 memset(&right, 0, sizeof(right));
2256 V_VT(&left) = VT_I4;
2258 V_VT(&right) = VT_UI1;
2261 hres = VarSub(&cy, &right, &result);
2262 ok(hres == S_OK && V_VT(&result) == VT_CY,
2263 "VarSub: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result)));
2264 hres = VarR8FromCy(V_CY(&result), &r);
2265 ok(hres == S_OK && EQ_DOUBLE(r, 4702),
2266 "VarSub: CY value %f, expected %f\n", r, (double)4720);
2268 hres = VarSub(&left, &dec, &result);
2269 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
2270 "VarSub: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
2271 hres = VarR8FromDec(&V_DECIMAL(&result), &r);
2272 ok(hres == S_OK && EQ_DOUBLE(r, -6.8),
2273 "VarSub: DECIMAL value %f, expected %f\n", r, (double)-15.2);
2275 SysFreeString(lbstr);
2276 SysFreeString(rbstr);
2279 static HRESULT (WINAPI *pVarMod)(LPVARIANT,LPVARIANT,LPVARIANT);
2281 static void test_Mod( int line, VARIANT *left, VARIANT *right, VARIANT *expected, HRESULT expres )
2286 memset( &result, 0, sizeof(result) );
2287 hres = pVarMod( left, right, &result );
2288 ok_(__FILE__,line)( hres == expres, "wrong result %x/%x\n", hres, expres );
2290 ok_(__FILE__,line)( is_expected_variant( &result, expected ),
2291 "got %s expected %s\n", variantstr(&result), variantstr(expected) );
2294 #define VARMOD(vt1,vt2,val1,val2,rvt,rval) \
2295 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
2296 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
2297 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
2298 test_var_call2( __LINE__, pVarMod, &left, &right, &exp )
2300 #define VARMOD2(vt1,vt2,val1,val2,rvt,rval,hexpected) \
2301 V_VT(&left) = VT_##vt1; V_I4(&left) = val1; \
2302 V_VT(&right) = VT_##vt2; V_I4(&right) = val2; \
2303 V_VT(&exp) = VT_##rvt; V_I4(&exp) = rval; \
2304 test_Mod( __LINE__, &left, &right, &exp, hexpected )
2306 static void test_VarMod(void)
2308 VARIANT v1, v2, vDst, left, right, exp;
2310 HRESULT hexpected = 0;
2311 static const WCHAR szNum0[] = {'1','2','5','\0'};
2312 static const WCHAR szNum1[] = {'1','0','\0'};
2314 BOOL lFound, rFound;
2315 BOOL lValid, rValid;
2316 BSTR strNum0, strNum1;
2320 VARMOD(I1,BOOL,100,10,I4,0);
2321 VARMOD(I1,I1,100,10,I4,0);
2322 VARMOD(I1,UI1,100,10,I4,0);
2323 VARMOD(I1,I2,100,10,I4,0);
2324 VARMOD(I1,UI2,100,10,I4,0);
2325 VARMOD(I1,I4,100,10,I4,0);
2326 VARMOD(I1,UI4,100,10,I4,0);
2327 VARMOD(I1,R4,100,10,I4,0);
2328 VARMOD(I1,R8,100,10,I4,0);
2330 VARMOD(UI1,BOOL,100,10,I2,0);
2331 VARMOD(UI1,I1,100,10,I4,0);
2332 VARMOD(UI1,UI1,100,10,UI1,0);
2333 VARMOD(UI1,I2,100,10,I2,0);
2334 VARMOD(UI1,UI2,100,10,I4,0);
2335 VARMOD(UI1,I4,100,10,I4,0);
2336 VARMOD(UI1,UI4,100,10,I4,0);
2337 VARMOD(UI1,R4,100,10,I4,0);
2338 VARMOD(UI1,R8,100,10,I4,0);
2340 VARMOD(I2,BOOL,100,10,I2,0);
2341 VARMOD(I2,I1,100,10,I4,0);
2342 VARMOD(I2,UI1,100,10,I2,0);
2343 VARMOD(I2,I2,100,10,I2,0);
2344 VARMOD(I2,UI2,100,10,I4,0);
2345 VARMOD(I2,I4,100,10,I4,0);
2346 VARMOD(I2,UI4,100,10,I4,0);
2347 VARMOD(I2,R4,100,10,I4,0);
2348 VARMOD(I2,R8,100,10,I4,0);
2350 VARMOD(I4,BOOL,100,10,I4,0);
2351 VARMOD(I4,I1,100,10,I4,0);
2352 VARMOD(I4,UI1,100,10,I4,0);
2353 VARMOD(I4,I2,100,10,I4,0);
2354 VARMOD(I4,UI2,100,10,I4,0);
2355 VARMOD(I4,I4,100,10,I4,0);
2356 VARMOD(I4,UI4,100,10,I4,0);
2357 VARMOD(I4,R4,100,10,I4,0);
2358 VARMOD(I4,R8,100,10,I4,0);
2359 VARMOD(UI4,BOOL,100,10,I4,0);
2360 VARMOD(UI4,I1,100,10,I4,0);
2361 VARMOD(UI4,UI1,100,10,I4,0);
2362 VARMOD(UI4,I2,100,10,I4,0);
2363 VARMOD(UI4,UI2,100,10,I4,0);
2364 VARMOD(UI4,I4,100,10,I4,0);
2365 VARMOD(UI4,UI4,100,10,I4,0);
2366 VARMOD(UI4,R4,100,10,I4,0);
2367 VARMOD(UI4,R8,100,10,I4,0);
2368 VARMOD(R4,BOOL,100,10,I4,0);
2369 VARMOD(R4,I1,100,10,I4,0);
2370 VARMOD(R4,UI1,100,10,I4,0);
2371 VARMOD(R4,I2,100,10,I4,0);
2372 VARMOD(R4,UI2,100,10,I4,0);
2373 VARMOD(R4,I4,100,10,I4,0);
2374 VARMOD(R4,UI4,100,10,I4,0);
2375 VARMOD(R4,R4,100,10,I4,0);
2376 VARMOD(R4,R8,100,10,I4,0);
2377 VARMOD(R8,BOOL,100,10,I4,0);
2378 VARMOD(R8,I1,100,10,I4,0);
2379 VARMOD(R8,UI1,100,10,I4,0);
2380 VARMOD(R8,I2,100,10,I4,0);
2381 VARMOD(R8,UI2,100,10,I4,0);
2382 VARMOD(R8,I4,100,10,I4,0);
2383 VARMOD(R8,UI4,100,10,I4,0);
2384 VARMOD(R8,R4,100,10,I4,0);
2385 VARMOD(R8,R8,100,10,I4,0);
2387 VARMOD(INT,INT,100,10,I4,0);
2388 VARMOD(INT,UINT,100,10,I4,0);
2390 VARMOD(BOOL,BOOL,100,10,I2,0);
2391 VARMOD(BOOL,I1,100,10,I4,0);
2392 VARMOD(BOOL,UI1,100,10,I2,0);
2393 VARMOD(BOOL,I2,100,10,I2,0);
2394 VARMOD(BOOL,UI2,100,10,I4,0);
2395 VARMOD(BOOL,I4,100,10,I4,0);
2396 VARMOD(BOOL,UI4,100,10,I4,0);
2397 VARMOD(BOOL,R4,100,10,I4,0);
2398 VARMOD(BOOL,R8,100,10,I4,0);
2399 VARMOD(BOOL,DATE,100,10,I4,0);
2401 VARMOD(DATE,BOOL,100,10,I4,0);
2402 VARMOD(DATE,I1,100,10,I4,0);
2403 VARMOD(DATE,UI1,100,10,I4,0);
2404 VARMOD(DATE,I2,100,10,I4,0);
2405 VARMOD(DATE,UI2,100,10,I4,0);
2406 VARMOD(DATE,I4,100,10,I4,0);
2407 VARMOD(DATE,UI4,100,10,I4,0);
2408 VARMOD(DATE,R4,100,10,I4,0);
2409 VARMOD(DATE,R8,100,10,I4,0);
2410 VARMOD(DATE,DATE,100,10,I4,0);
2412 strNum0 = SysAllocString(szNum0);
2413 strNum1 = SysAllocString(szNum1);
2414 VARMOD(BSTR,BSTR,strNum0,strNum1,I4,5);
2415 VARMOD(BSTR,I1,strNum0,10,I4,5);
2416 VARMOD(BSTR,I2,strNum0,10,I4,5);
2417 VARMOD(BSTR,I4,strNum0,10,I4,5);
2418 VARMOD(BSTR,R4,strNum0,10,I4,5);
2419 VARMOD(BSTR,R8,strNum0,10,I4,5);
2420 VARMOD(I4,BSTR,125,strNum1,I4,5);
2422 if (HAVE_OLEAUT32_I8)
2424 VARMOD(BOOL,I8,100,10,I8,0);
2425 VARMOD(I1,I8,100,10,I8,0);
2426 VARMOD(UI1,I8,100,10,I8,0);
2427 VARMOD(I2,I8,100,10,I8,0);
2428 VARMOD(I4,I8,100,10,I8,0);
2429 VARMOD(UI4,I8,100,10,I8,0);
2430 VARMOD(R4,I8,100,10,I8,0);
2431 VARMOD(R8,I8,100,10,I8,0);
2432 VARMOD(DATE,I8,100,10,I8,0);
2434 VARMOD(I8,BOOL,100,10,I8,0);
2435 VARMOD(I8,I1,100,10,I8,0);
2436 VARMOD(I8,UI1,100,10,I8,0);
2437 VARMOD(I8,I2,100,10,I8,0);
2438 VARMOD(I8,UI2,100,10,I8,0);
2439 VARMOD(I8,I4,100,10,I8,0);
2440 VARMOD(I8,UI4,100,10,I8,0);
2441 VARMOD(I8,R4,100,10,I8,0);
2442 VARMOD(I8,R8,100,10,I8,0);
2443 VARMOD(I8,I8,100,10,I8,0);
2445 VARMOD(BSTR,I8,strNum0,10,I8,5);
2448 /* test all combinations of types */
2449 for(l = 0; l < VT_BSTR_BLOB; l++)
2453 for(r = 0; r < VT_BSTR_BLOB; r++)
2457 if(l == VT_BSTR) continue;
2458 if(l == VT_DISPATCH) continue;
2459 if(r == VT_BSTR) continue;
2460 if(r == VT_DISPATCH) continue;
2494 hexpected = DISP_E_BADVARTYPE;
2533 if(((l == VT_I8) && (r == VT_INT)) || ((l == VT_INT) && (r == VT_I8)))
2535 hexpected = DISP_E_TYPEMISMATCH;
2536 } else if((l == VT_EMPTY) && (r == VT_NULL))
2539 } else if((l == VT_NULL) && (r == VT_EMPTY))
2542 } else if((l == VT_EMPTY) && (r == VT_CY))
2545 } else if((l == VT_EMPTY) && (r == VT_RECORD))
2547 hexpected = DISP_E_TYPEMISMATCH;
2548 } else if((r == VT_EMPTY) && lFound && lValid)
2550 hexpected = DISP_E_DIVBYZERO;
2551 } else if((l == VT_ERROR) || ((r == VT_ERROR) && lFound && lValid))
2553 hexpected = DISP_E_TYPEMISMATCH;
2554 } else if((l == VT_NULL) && (r == VT_NULL))
2557 } else if((l == VT_VARIANT) || ((r == VT_VARIANT) && lFound && lValid))
2559 hexpected = DISP_E_TYPEMISMATCH;
2560 } else if((l == VT_NULL) && (r == VT_RECORD))
2562 hexpected = DISP_E_TYPEMISMATCH;
2563 } else if((l == VT_I8) && (r == VT_DECIMAL))
2566 } else if((l == VT_DECIMAL) && (r == VT_I8))
2569 } else if((l == VT_UNKNOWN) || ((r == VT_UNKNOWN) && lFound && lValid))
2571 hexpected = DISP_E_TYPEMISMATCH;
2572 } else if((l == VT_NULL) && rFound)
2575 } else if(l == VT_RECORD)
2577 hexpected = DISP_E_TYPEMISMATCH;
2578 } else if((r == VT_RECORD) && lValid && lFound)
2580 hexpected = DISP_E_TYPEMISMATCH;
2581 } else if((l == VT_EMPTY) && (r == VT_EMPTY))
2583 hexpected = DISP_E_DIVBYZERO;
2584 } else if((l == VT_CY) && !rFound)
2586 hexpected = DISP_E_BADVARTYPE;
2587 } else if(lFound && !rFound)
2589 hexpected = DISP_E_BADVARTYPE;
2590 } else if(!lFound && rFound)
2592 hexpected = DISP_E_BADVARTYPE;
2593 } else if((r == VT_NULL) && lFound && lValid)
2596 } else if((l == VT_NULL) || (r == VT_NULL))
2598 hexpected = DISP_E_BADVARTYPE;
2599 } else if((l == VT_VARIANT) || (r == VT_VARIANT))
2601 hexpected = DISP_E_BADVARTYPE;
2602 } else if(lFound && !rFound)
2604 hexpected = DISP_E_BADVARTYPE;
2605 } else if(!lFound && !rFound)
2607 hexpected = DISP_E_BADVARTYPE;
2614 V_CY(&v1).int64 = 1000000;
2619 else if(l == VT_UI8)
2623 else if(l == VT_DATE)
2625 else if (l == VT_DECIMAL)
2627 V_DECIMAL(&v1).Hi32 = 0;
2628 U1(V_DECIMAL(&v1)).Lo64 = 100;
2629 U(V_DECIMAL(&v1)).signscale = 0;
2635 V_CY(&v2).int64 = 10000;
2640 else if(r == VT_UI8)
2644 else if(r == VT_DATE)
2646 else if (r == VT_DECIMAL)
2648 V_DECIMAL(&v2).Hi32 = 0;
2649 U1(V_DECIMAL(&v2)).Lo64 = 100;
2650 U(V_DECIMAL(&v2)).signscale = 0;
2655 if ((l != VT_I8 && l != VT_UI8 && r != VT_I8 && r != VT_UI8) || HAVE_OLEAUT32_I8)
2657 hres = pVarMod(&v1,&v2,&vDst);
2658 ok(hres == hexpected,
2659 "VarMod: expected 0x%x, got 0x%X for l type of %d, r type of %d,\n", hexpected, hres, l, r);
2665 /****************************/
2666 /* test some bad parameters */
2667 VARMOD(I4,I4,-1,-1,I4,0);
2669 /* test modulus with zero */
2670 VARMOD2(I4,I4,100,0,EMPTY,0,DISP_E_DIVBYZERO);
2672 VARMOD(I4,I4,0,10,I4,0); /* test 0 mod 10 */
2674 /* right parameter is type empty */
2675 VARMOD2(I4,EMPTY,100,10,EMPTY,0,DISP_E_DIVBYZERO);
2677 /* left parameter is type empty */
2678 VARMOD2(EMPTY,I4,100,10,I4,0,S_OK);
2680 /* mod with a null left value */
2681 VARMOD2(NULL,I4,125,10,NULL,0,S_OK);
2683 /* mod with a null right value */
2684 VARMOD2(I4,NULL,100,10,NULL,0,S_OK);
2686 /* void left value */
2687 VARMOD2(VOID,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2689 /* void right value */
2690 VARMOD2(I4,VOID,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2692 /* null left value, void right value */
2693 VARMOD2(NULL,VOID,100,10,EMPTY, 0, DISP_E_BADVARTYPE);
2695 /* void left value, null right value */
2696 VARMOD2(VOID,NULL,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2698 /* some currencies */
2701 V_CY(&v1).int64 = 100000;
2702 V_CY(&v2).int64 = 100000;
2703 hres = pVarMod(&v1,&v2,&vDst);
2704 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
2705 "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
2710 V_CY(&v2).int64 = 100000;
2711 hres = pVarMod(&v1,&v2,&vDst);
2712 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
2713 "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
2716 V_VT(&v1) = VT_DECIMAL;
2717 V_VT(&v2) = VT_DECIMAL;
2718 VarDecFromI4(100, &V_DECIMAL(&v1));
2719 VarDecFromI4(10, &V_DECIMAL(&v2));
2720 hres = pVarMod(&v1,&v2,&vDst);
2721 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
2722 "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
2725 V_VT(&v2) = VT_DECIMAL;
2727 VarDecFromI4(10, &V_DECIMAL(&v2));
2728 hres = pVarMod(&v1,&v2,&vDst);
2729 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
2730 "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
2732 VARMOD2(UINT,I4,100,10,I4,0,S_OK);
2734 /* test that an error results in the type of the result changing but not its value */
2735 V_VT(&v1) = VT_UNKNOWN;
2736 V_VT(&v2) = VT_EMPTY;
2738 V_CY(&v2).int64 = 100000;
2739 V_VT(&vDst) = VT_I4;
2741 hres = pVarMod(&v1,&v2,&vDst);
2742 ok(hres == DISP_E_TYPEMISMATCH && V_VT(&vDst) == VT_EMPTY && V_I4(&vDst) == 1231,
2743 "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));
2746 /* test some invalid types */
2747 /*TODO: not testing VT_DISPATCH */
2748 if (HAVE_OLEAUT32_I8)
2750 VARMOD2(I8,INT,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
2752 VARMOD2(ERROR,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
2753 VARMOD2(VARIANT,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
2754 VARMOD2(UNKNOWN,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
2755 VARMOD2(VOID,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2756 VARMOD2(HRESULT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2757 VARMOD2(PTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2758 VARMOD2(SAFEARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2759 VARMOD2(CARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2760 VARMOD2(USERDEFINED,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2761 VARMOD2(LPSTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2762 VARMOD2(LPWSTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2763 VARMOD2(RECORD,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
2764 VARMOD2(FILETIME,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2765 VARMOD2(BLOB,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2766 VARMOD2(STREAM,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2767 VARMOD2(STORAGE,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2768 VARMOD2(STREAMED_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2769 VARMOD2(STORED_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2770 VARMOD2(BLOB_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2771 VARMOD2(CF,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2772 VARMOD2(CLSID,CLSID,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2773 VARMOD2(VECTOR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2774 VARMOD2(ARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2775 VARMOD2(BYREF,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2777 /* test some more invalid types */
2782 hres = pVarMod(&v1,&v2,&vDst);
2783 ok(hres == DISP_E_BADVARTYPE && V_VT(&vDst) == VT_EMPTY,
2784 "VarMod: expected 0x%x,%d, got 0x%X,%d\n", DISP_E_BADVARTYPE, VT_EMPTY, hres, V_VT(&vDst));
2786 SysFreeString(strNum0);
2787 SysFreeString(strNum1);
2790 static HRESULT (WINAPI *pVarFix)(LPVARIANT,LPVARIANT);
2792 #define VARFIX(vt,val,rvt,rval) \
2793 V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
2794 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
2795 test_var_call1( __LINE__, pVarFix, &v, &exp )
2797 static void test_VarFix(void)
2799 static const WCHAR szNumMinus1[] = {'-','1','\0' };
2801 VARIANT v, exp, vDst;
2802 DECIMAL *pdec = &V_DECIMAL(&v);
2803 CY *pcy = &V_CY(&v);
2808 /* Test all possible V_VT values */
2809 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2813 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2815 HRESULT bFail = TRUE;
2819 memset(&v, 0, sizeof(v));
2820 V_VT(&v) = vt | ExtraFlags[i];
2821 V_VT(&vDst) = VT_EMPTY;
2825 case VT_UI1: case VT_I2: case VT_I4: case VT_R4: case VT_R8:
2826 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
2827 case VT_DATE: case VT_CY:
2831 if (HAVE_OLEAUT32_I8)
2836 hres = pVarFix(&v,&vDst);
2838 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
2839 "VarFix: expected failure, got 0x%X vt %d|0x%X\n",
2840 hres, vt, ExtraFlags[i]);
2842 ok(hres == S_OK, "VarFix: expected S_OK, got 0x%X vt %d|0x%X\n",
2843 hres, vt, ExtraFlags[i]);
2847 VARFIX(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE);
2848 VARFIX(BOOL,VARIANT_FALSE,I2,0);
2849 VARFIX(BOOL,1,I2,1);
2850 VARFIX(UI1,1,UI1,1);
2851 VARFIX(I2,-1,I2,-1);
2852 VARFIX(I4,-1,I4,-1);
2853 if (HAVE_OLEAUT32_I8)
2855 VARFIX(I8,-1,I8,-1);
2857 VARFIX(R4,1.4f,R4,1);
2858 VARFIX(R4,1.5f,R4,1);
2859 VARFIX(R4,1.6f,R4,1);
2860 VARFIX(R4,-1.4f,R4,-1);
2861 VARFIX(R4,-1.5f,R4,-1);
2862 VARFIX(R4,-1.6f,R4,-1);
2863 /* DATE & R8 round as for R4 */
2864 VARFIX(DATE,-1,DATE,-1);
2865 VARFIX(R8,-1,R8,-1);
2866 VARFIX(BSTR,(BSTR)szNumMinus1,R8,-1);
2868 V_VT(&v) = VT_EMPTY;
2869 hres = pVarFix(&v,&vDst);
2870 ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
2871 "VarFix: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY,
2872 hres, V_VT(&vDst), V_I2(&vDst));
2875 hres = pVarFix(&v,&vDst);
2876 ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
2877 "VarFix: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst));
2879 V_VT(&v) = VT_DECIMAL;
2880 S(U(*pdec)).sign = DECIMAL_NEG;
2881 S(U(*pdec)).scale = 0;
2883 S1(U1(*pdec)).Mid32 = 0;
2884 S1(U1(*pdec)).Lo32 = 1;
2885 hres = pVarFix(&v,&vDst);
2886 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && !memcmp(&V_DECIMAL(&v), &V_DECIMAL(&vDst), sizeof(DECIMAL)),
2887 "VarFix: expected 0x0,%d,identical, got 0x%X,%d\n", VT_DECIMAL,
2890 /* FIXME: Test some fractional decimals when VarDecFix is implemented */
2893 pcy->int64 = -10000;
2894 hres = pVarFix(&v,&vDst);
2895 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
2896 "VarFix: VT_CY wrong, hres=0x%X\n", hres);
2899 pcy->int64 = -16000;
2900 hres = pVarFix(&v,&vDst);
2901 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
2902 "VarFix: VT_CY wrong, hres=0x%X\n", hres);
2905 static HRESULT (WINAPI *pVarInt)(LPVARIANT,LPVARIANT);
2907 #define VARINT(vt,val,rvt,rval) \
2908 V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
2909 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
2910 test_var_call1( __LINE__, pVarInt, &v, &exp )
2912 static void test_VarInt(void)
2914 static const WCHAR szNumMinus1[] = {'-','1','\0' };
2916 VARIANT v, exp, vDst;
2917 DECIMAL *pdec = &V_DECIMAL(&v);
2918 CY *pcy = &V_CY(&v);
2923 /* Test all possible V_VT values */
2924 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2928 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2930 HRESULT bFail = TRUE;
2934 memset(&v, 0, sizeof(v));
2935 V_VT(&v) = vt | ExtraFlags[i];
2936 V_VT(&vDst) = VT_EMPTY;
2940 case VT_UI1: case VT_I2: case VT_I4: case VT_R4: case VT_R8:
2941 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
2942 case VT_DATE: case VT_CY:
2946 if (HAVE_OLEAUT32_I8)
2951 hres = pVarInt(&v,&vDst);
2953 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
2954 "VarInt: expected failure, got 0x%X vt %d|0x%X\n",
2955 hres, vt, ExtraFlags[i]);
2957 ok(hres == S_OK, "VarInt: expected S_OK, got 0x%X vt %d|0x%X\n",
2958 hres, vt, ExtraFlags[i]);
2962 VARINT(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE);
2963 VARINT(BOOL,VARIANT_FALSE,I2,0);
2964 VARINT(BOOL,1,I2,1);
2965 VARINT(UI1,1,UI1,1);
2966 VARINT(I2,-1,I2,-1);
2967 VARINT(I4,-1,I4,-1);
2968 if (HAVE_OLEAUT32_I8)
2970 VARINT(I8,-1,I8,-1);
2972 VARINT(R4,1.4f,R4,1);
2973 VARINT(R4,1.5f,R4,1);
2974 VARINT(R4,1.6f,R4,1);
2975 VARINT(R4,-1.4f,R4,-2); /* Note these 3 are different from VarFix */
2976 VARINT(R4,-1.5f,R4,-2);
2977 VARINT(R4,-1.6f,R4,-2);
2978 /* DATE & R8 round as for R4 */
2979 VARINT(DATE,-1,DATE,-1);
2980 VARINT(R8,-1,R8,-1);
2981 VARINT(BSTR,(BSTR)szNumMinus1,R8,-1);
2983 V_VT(&v) = VT_EMPTY;
2984 hres = pVarInt(&v,&vDst);
2985 ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
2986 "VarInt: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY,
2987 hres, V_VT(&vDst), V_I2(&vDst));
2990 hres = pVarInt(&v,&vDst);
2991 ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
2992 "VarInt: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst));
2994 V_VT(&v) = VT_DECIMAL;
2995 S(U(*pdec)).sign = DECIMAL_NEG;
2996 S(U(*pdec)).scale = 0;
2998 S1(U1(*pdec)).Mid32 = 0;
2999 S1(U1(*pdec)).Lo32 = 1;
3000 hres = pVarInt(&v,&vDst);
3001 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && !memcmp(&V_DECIMAL(&v), &V_DECIMAL(&vDst), sizeof(DECIMAL)),
3002 "VarInt: expected 0x0,%d,identical, got 0x%X,%d\n", VT_DECIMAL,
3005 /* FIXME: Test some fractional decimals when VarDecInt is implemented */
3008 pcy->int64 = -10000;
3009 hres = pVarInt(&v,&vDst);
3010 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
3011 "VarInt: VT_CY wrong, hres=0x%X\n", hres);
3014 pcy->int64 = -11000;
3015 hres = pVarInt(&v,&vDst);
3016 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -20000,
3017 "VarInt: VT_CY wrong, hres=0x%X 0x%x%08x\n",
3018 hres, (DWORD)(V_CY(&vDst).int64 >> 32), (DWORD)V_CY(&vDst).int64);
3021 static HRESULT (WINAPI *pVarNeg)(LPVARIANT,LPVARIANT);
3023 #define VARNEG(vt,val,rvt,rval) \
3024 V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
3025 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
3026 test_var_call1( __LINE__, pVarNeg, &v, &exp )
3028 static void test_VarNeg(void)
3030 static const WCHAR szNumMinus1[] = {'-','1','\0' };
3031 static const WCHAR szNum1[] = {'1','\0' };
3033 VARIANT v, exp, vDst;
3034 DECIMAL *pdec = &V_DECIMAL(&v);
3035 CY *pcy = &V_CY(&v);
3040 /* Test all possible V_VT values. But don't test the exact return values
3041 * except for success/failure, since M$ made a hash of them in the
3042 * native version. This at least ensures (as with all tests here) that
3043 * we will notice if/when new vtypes/flags are added in native.
3045 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
3049 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
3051 HRESULT bFail = TRUE;
3055 memset(&v, 0, sizeof(v));
3056 V_VT(&v) = vt | ExtraFlags[i];
3057 V_VT(&vDst) = VT_EMPTY;
3061 case VT_UI1: case VT_I2: case VT_I4:
3062 case VT_R4: case VT_R8:
3063 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
3064 case VT_DATE: case VT_CY:
3068 if (HAVE_OLEAUT32_I8)
3072 hres = pVarNeg(&v,&vDst);
3074 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3075 "VarNeg: expected failure, got 0x%X vt %d|0x%X\n",
3076 hres, vt, ExtraFlags[i]);
3078 ok(hres == S_OK, "VarNeg: expected S_OK, got 0x%X vt %d|0x%X\n",
3079 hres, vt, ExtraFlags[i]);
3083 VARNEG(BOOL,VARIANT_TRUE,I2,1);
3084 VARNEG(BOOL,VARIANT_FALSE,I2,0);
3085 VARNEG(BOOL,1,I2,-1);
3086 VARNEG(UI1,1,I2,-1);
3087 VARNEG(UI1,254,I2,-254);
3088 VARNEG(I2,-32768,I4,32768);
3091 VARNEG(I4,-((int)(~0u >> 1)) - 1,R8,-2147483648u);
3094 if (HAVE_OLEAUT32_I8)
3101 VARNEG(DATE,1,DATE,-1);
3102 VARNEG(DATE,-1,DATE,1);
3105 VARNEG(BSTR,(BSTR)szNumMinus1,R8,1);
3106 VARNEG(BSTR,(BSTR)szNum1,R8,-1);
3108 V_VT(&v) = VT_EMPTY;
3109 hres = pVarNeg(&v,&vDst);
3110 ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
3111 "VarNeg: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY,
3112 hres, V_VT(&vDst), V_I2(&vDst));
3115 hres = pVarNeg(&v,&vDst);
3116 ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
3117 "VarNeg: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst));
3119 V_VT(&v) = VT_DECIMAL;
3120 S(U(*pdec)).sign = DECIMAL_NEG;
3121 S(U(*pdec)).scale = 0;
3123 S1(U1(*pdec)).Mid32 = 0;
3124 S1(U1(*pdec)).Lo32 = 1;
3125 hres = pVarNeg(&v,&vDst);
3126 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
3127 S(U(V_DECIMAL(&vDst))).sign == 0,
3128 "VarNeg: expected 0x0,%d,0x00, got 0x%X,%d,%02x\n", VT_DECIMAL,
3129 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
3131 S(U(*pdec)).sign = 0;
3132 hres = pVarNeg(&v,&vDst);
3133 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
3134 S(U(V_DECIMAL(&vDst))).sign == DECIMAL_NEG,
3135 "VarNeg: expected 0x0,%d,0x7f, got 0x%X,%d,%02x\n", VT_DECIMAL,
3136 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
3139 pcy->int64 = -10000;
3140 hres = pVarNeg(&v,&vDst);
3141 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
3142 "VarNeg: VT_CY wrong, hres=0x%X\n", hres);
3145 static HRESULT (WINAPI *pVarRound)(LPVARIANT,int,LPVARIANT);
3147 static void test_Round( int line, VARIANT *arg, int deci, VARIANT *expected )
3152 memset( &result, 0, sizeof(result) );
3153 hres = pVarRound( arg, deci, &result );
3154 ok_(__FILE__,line)( hres == S_OK, "wrong result %x\n", hres );
3156 ok_(__FILE__,line)( is_expected_variant( &result, expected ),
3157 "got %s expected %s\n", variantstr(&result), variantstr(expected) );
3159 #define VARROUND(vt,val,deci,rvt,rval) \
3160 V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
3161 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
3162 test_Round( __LINE__, &v, deci, &exp )
3164 static void test_VarRound(void)
3166 static WCHAR szNumMin[] = {'-','1','.','4','4','9','\0' };
3167 static WCHAR szNum[] = {'1','.','4','5','1','\0' };
3169 VARIANT v, exp, vDst;
3170 CY *pcy = &V_CY(&v);
3175 /* first check valid integer types */
3176 VARROUND(BOOL,VARIANT_TRUE,0,I2,-1);
3177 VARROUND(BOOL,VARIANT_FALSE,0,I2,0);
3178 VARROUND(BOOL,1,0,I2,1);
3179 VARROUND(UI1,1,0,UI1,1);
3180 VARROUND(UI1,254,0,UI1,254);
3181 VARROUND(I2,-32768,0,I2,-32768);
3182 VARROUND(I2,-1,0,I2,-1);
3183 VARROUND(I2,1,0,I2,1);
3184 VARROUND(I4,-((int)(~0u >> 1)) - 1,0,I4,-((int)(~0u >> 1)) - 1);
3185 VARROUND(I4,-1,0,I4,-1);
3186 VARROUND(I4,1,0,I4,1);
3189 /* MSDN states that rounding of R4/R8 is dependent on the underlying
3190 * bit pattern of the number and so is architecture dependent. In this
3191 * case Wine returns .2 (which is more correct) and Native returns .3
3194 VARROUND(R4,1.0f,0,R4,1.0f);
3195 VARROUND(R4,-1.0f,0,R4,-1.0f);
3196 VARROUND(R8,1.0,0,R8,1.0);
3197 VARROUND(R8,-1.0,0,R8,-1.0);
3199 /* floating point numbers aren't exactly equal and we can't just
3200 * compare the first few digits. */
3201 VARROUND(DATE,1.451,1,DATE,1.5);
3202 VARROUND(DATE,-1.449,1,DATE,-1.4);
3204 /* replace the decimal separator */
3205 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char));
3207 szNumMin[2] = buff[0];
3209 VARROUND(BSTR,(BSTR)szNumMin,1,R8,-1.40);
3210 VARROUND(BSTR,(BSTR)szNum,1,R8,1.50);
3212 skip("Skipping VarRound(BSTR) as decimal separator is '%s'\n", buff);
3215 VARROUND(R4,1.23456f,0,R4,1.0f);
3216 VARROUND(R4,1.23456f,1,R4,1.2f);
3217 VARROUND(R4,1.23456f,2,R4,1.23f);
3218 VARROUND(R4,1.23456f,3,R4,1.235f);
3219 VARROUND(R4,1.23456f,4,R4,1.2346f);
3220 VARROUND(R4,-1.23456f,0,R4,-1.0f);
3221 VARROUND(R4,-1.23456f,1,R4,-1.2f);
3222 VARROUND(R4,-1.23456f,2,R4,-1.23f);
3223 VARROUND(R4,-1.23456f,3,R4,-1.235f);
3224 VARROUND(R4,-1.23456f,4,R4,-1.2346f);
3226 VARROUND(R8,1.23456,0,R8,1.0);
3227 VARROUND(R8,1.23456,1,R8,1.2);
3228 VARROUND(R8,1.23456,2,R8,1.23);
3229 VARROUND(R8,1.23456,3,R8,1.235);
3230 VARROUND(R8,1.23456,4,R8,1.2346);
3231 VARROUND(R8,-1.23456,0,R8,-1.0);
3232 VARROUND(R8,-1.23456,1,R8,-1.2);
3233 VARROUND(R8,-1.23456,2,R8,-1.23);
3234 VARROUND(R8,-1.23456,3,R8,-1.235);
3235 VARROUND(R8,-1.23456,4,R8,-1.2346);
3237 V_VT(&v) = VT_EMPTY;
3238 hres = pVarRound(&v,0,&vDst);
3239 ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
3240 "VarRound: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY,
3241 hres, V_VT(&vDst), V_I2(&vDst));
3244 hres = pVarRound(&v,0,&vDst);
3245 ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
3246 "VarRound: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst));
3248 /* not yet implemented so no use testing yet
3250 DECIMAL *pdec = &V_DECIMAL(&v);
3251 V_VT(&v) = VT_DECIMAL;
3252 S(U(*pdec)).sign = DECIMAL_NEG;
3253 S(U(*pdec)).scale = 0;
3255 S1(U1(*pdec)).Mid32 = 0;
3256 S1(U1(*pdec)).Lo32 = 1;
3257 hres = pVarRound(&v,0,&vDst);
3258 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
3259 S(U(V_DECIMAL(&vDst))).sign == 0,
3260 "VarRound: expected 0x0,%d,0x00, got 0x%X,%d,%02x\n", VT_DECIMAL,
3261 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
3263 S(U(*pdec)).sign = 0;
3264 hres = pVarRound(&v,0,&vDst);
3265 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
3266 S(U(V_DECIMAL(&vDst))).sign == DECIMAL_NEG,
3267 "VarRound: expected 0x0,%d,0x7f, got 0x%X,%d,%02x\n", VT_DECIMAL,
3268 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
3274 hres = pVarRound(&v,0,&vDst);
3275 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
3276 "VarRound: VT_CY wrong, hres=0x%X\n", hres);
3280 static HRESULT (WINAPI *pVarXor)(LPVARIANT,LPVARIANT,LPVARIANT);
3282 #define VARXOR(vt1,val1,vt2,val2,rvt,rval) \
3283 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
3284 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
3285 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
3286 test_var_call2( __LINE__, pVarXor, &left, &right, &exp )
3288 #define VARXORCY(vt1,val1,val2,rvt,rval) \
3289 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
3290 V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \
3291 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
3292 test_var_call2( __LINE__, pVarXor, &left, &right, &exp )
3294 static void test_VarXor(void)
3296 static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
3297 static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
3298 VARIANT left, right, exp, result;
3305 /* Test all possible flag/vt combinations & the resulting vt type */
3306 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
3308 VARTYPE leftvt, rightvt, resvt;
3310 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
3315 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
3321 if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
3322 leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
3323 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
3326 memset(&left, 0, sizeof(left));
3327 memset(&right, 0, sizeof(right));
3328 V_VT(&left) = leftvt | ExtraFlags[i];
3329 V_VT(&right) = rightvt | ExtraFlags[i];
3330 V_VT(&result) = VT_EMPTY;
3333 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
3334 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
3335 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
3336 leftvt == VT_CLSID || rightvt == VT_CLSID ||
3337 leftvt == VT_RECORD || rightvt == VT_RECORD ||
3338 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
3339 leftvt == VT_ERROR || rightvt == VT_ERROR)
3343 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
3345 if (leftvt == rightvt ||
3346 leftvt == VT_I2 || rightvt == VT_I2 ||
3347 leftvt == VT_UI1 || rightvt == VT_UI1 ||
3348 leftvt == VT_BOOL || rightvt == VT_BOOL)
3350 else if (leftvt == VT_NULL || rightvt == VT_NULL)
3352 else if (leftvt == VT_I8 || rightvt == VT_I8)
3355 else if (leftvt == VT_NULL || rightvt == VT_NULL)
3359 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
3361 if (leftvt == rightvt)
3363 else if (leftvt == rightvt ||
3364 leftvt == VT_I2 || rightvt == VT_I2 ||
3365 leftvt == VT_BOOL || rightvt == VT_BOOL)
3369 else if (leftvt == VT_I8 || rightvt == VT_I8)
3372 else if (leftvt == VT_I2 || rightvt == VT_I2)
3374 if (leftvt == rightvt ||
3375 leftvt == VT_BOOL || rightvt == VT_BOOL)
3377 else if (leftvt == VT_I8 || rightvt == VT_I8)
3380 else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
3384 else if (leftvt == VT_I8 || rightvt == VT_I8)
3386 if (leftvt == VT_INT || rightvt == VT_INT)
3391 hres = pVarXor(&left, &right, &result);
3393 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3394 "VarXor: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
3395 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
3398 ok(hres == S_OK && V_VT(&result) == resvt,
3399 "VarXor: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
3400 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
3406 /* Test returned values
3407 * FIXME: Test VT_DECIMAL/VT_DISPATCH
3409 VARXOR(EMPTY,0,EMPTY,0,I2,0);
3410 VARXOR(EMPTY,1,EMPTY,0,I2,0);
3411 VARXOR(EMPTY,0,NULL,0,NULL,0);
3412 VARXOR(EMPTY,0,I1,0,I4,0);
3413 VARXOR(EMPTY,0,I1,1,I4,1);
3414 VARXOR(EMPTY,0,UI1,0,I2,0);
3415 VARXOR(EMPTY,0,UI1,1,I2,1);
3416 VARXOR(EMPTY,0,I2,0,I2,0);
3417 VARXOR(EMPTY,0,I2,1,I2,1);
3418 VARXOR(EMPTY,0,UI2,0,I4,0);
3419 VARXOR(EMPTY,0,UI2,1,I4,1);
3420 VARXOR(EMPTY,0,I4,0,I4,0);
3421 VARXOR(EMPTY,0,I4,1,I4,1);
3422 VARXOR(EMPTY,0,UI4,0,I4,0);
3423 VARXOR(EMPTY,0,UI4,1,I4,1);
3424 if (HAVE_OLEAUT32_I8)
3426 VARXOR(EMPTY,0,I8,0,I8,0);
3427 VARXOR(EMPTY,0,I8,1,I8,1);
3428 VARXOR(EMPTY,0,UI8,0,I4,0);
3429 VARXOR(EMPTY,0,UI8,1,I4,1);
3431 VARXOR(EMPTY,0,INT,0,I4,0);
3432 VARXOR(EMPTY,0,INT,1,I4,1);
3433 VARXOR(EMPTY,0,UINT,0,I4,0);
3434 VARXOR(EMPTY,0,UINT,1,I4,1);
3435 VARXOR(EMPTY,0,BOOL,0,I2,0);
3436 VARXOR(EMPTY,0,BOOL,1,I2,1);
3437 VARXOR(EMPTY,0,R4,0,I4,0);
3438 VARXOR(EMPTY,0,R4,1,I4,1);
3439 VARXOR(EMPTY,0,R8,0,I4,0);
3440 VARXOR(EMPTY,0,R8,1,I4,1);
3441 rbstr = SysAllocString(szFalse);
3442 VARXOR(EMPTY,0,BSTR,rbstr,I2,0);
3443 SysFreeString(rbstr);
3444 rbstr = SysAllocString(szTrue);
3445 VARXOR(EMPTY,0,BSTR,rbstr,I2,-1);
3446 VARXORCY(EMPTY,0,10000,I4,1);
3447 SysFreeString(rbstr);
3449 /* NULL OR 0 = NULL. NULL OR n = n */
3450 VARXOR(NULL,0,NULL,0,NULL,0);
3451 VARXOR(NULL,1,NULL,0,NULL,0);
3452 VARXOR(NULL,0,I1,0,NULL,0);
3453 VARXOR(NULL,0,I1,1,NULL,0);
3454 VARXOR(NULL,0,UI1,0,NULL,0);
3455 VARXOR(NULL,0,UI1,1,NULL,0);
3456 VARXOR(NULL,0,I2,0,NULL,0);
3457 VARXOR(NULL,0,I2,1,NULL,0);
3458 VARXOR(NULL,0,UI2,0,NULL,0);
3459 VARXOR(NULL,0,UI2,1,NULL,0);
3460 VARXOR(NULL,0,I4,0,NULL,0);
3461 VARXOR(NULL,0,I4,1,NULL,0);
3462 VARXOR(NULL,0,UI4,0,NULL,0);
3463 VARXOR(NULL,0,UI4,1,NULL,0);
3464 if (HAVE_OLEAUT32_I8)
3466 VARXOR(NULL,0,I8,0,NULL,0);
3467 VARXOR(NULL,0,I8,1,NULL,0);
3468 VARXOR(NULL,0,UI8,0,NULL,0);
3469 VARXOR(NULL,0,UI8,1,NULL,0);
3471 VARXOR(NULL,0,INT,0,NULL,0);
3472 VARXOR(NULL,0,INT,1,NULL,0);
3473 VARXOR(NULL,0,UINT,0,NULL,0);
3474 VARXOR(NULL,0,UINT,1,NULL,0);
3475 VARXOR(NULL,0,BOOL,0,NULL,0);
3476 VARXOR(NULL,0,BOOL,1,NULL,0);
3477 VARXOR(NULL,0,R4,0,NULL,0);
3478 VARXOR(NULL,0,R4,1,NULL,0);
3479 VARXOR(NULL,0,R8,0,NULL,0);
3480 VARXOR(NULL,0,R8,1,NULL,0);
3481 rbstr = SysAllocString(szFalse);
3482 VARXOR(NULL,0,BSTR,rbstr,NULL,0);
3483 SysFreeString(rbstr);
3484 rbstr = SysAllocString(szTrue);
3485 VARXOR(NULL,0,BSTR,rbstr,NULL,0);
3486 SysFreeString(rbstr);
3487 VARXORCY(NULL,0,10000,NULL,0);
3488 VARXORCY(NULL,0,0,NULL,0);
3490 VARXOR(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
3491 VARXOR(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
3492 VARXOR(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
3493 VARXOR(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
3494 /* Assume x,y & y,x are the same from now on to reduce the number of tests */
3495 VARXOR(BOOL,VARIANT_TRUE,I1,-1,I4,0);
3496 VARXOR(BOOL,VARIANT_TRUE,I1,0,I4,-1);
3497 VARXOR(BOOL,VARIANT_FALSE,I1,0,I4,0);
3498 VARXOR(BOOL,VARIANT_TRUE,UI1,255,I2,-256);
3499 VARXOR(BOOL,VARIANT_TRUE,UI1,0,I2,-1);
3500 VARXOR(BOOL,VARIANT_FALSE,UI1,0,I2,0);
3501 VARXOR(BOOL,VARIANT_TRUE,I2,-1,I2,0);
3502 VARXOR(BOOL,VARIANT_TRUE,I2,0,I2,-1);
3503 VARXOR(BOOL,VARIANT_FALSE,I2,0,I2,0);
3504 VARXOR(BOOL,VARIANT_TRUE,UI2,65535,I4,-65536);
3505 VARXOR(BOOL,VARIANT_TRUE,UI2,0,I4,-1);
3506 VARXOR(BOOL,VARIANT_FALSE,UI2,0,I4,0);
3507 VARXOR(BOOL,VARIANT_TRUE,I4,-1,I4,0);
3508 VARXOR(BOOL,VARIANT_TRUE,I4,0,I4,-1);
3509 VARXOR(BOOL,VARIANT_FALSE,I4,0,I4,0);
3510 VARXOR(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,0);
3511 VARXOR(BOOL,VARIANT_TRUE,UI4,0,I4,-1);
3512 VARXOR(BOOL,VARIANT_FALSE,UI4,0,I4,0);
3513 VARXOR(BOOL,VARIANT_TRUE,R4,-1,I4,0);
3514 VARXOR(BOOL,VARIANT_TRUE,R4,0,I4,-1);
3515 VARXOR(BOOL,VARIANT_FALSE,R4,0,I4,0);
3516 VARXOR(BOOL,VARIANT_TRUE,R8,-1,I4,0);
3517 VARXOR(BOOL,VARIANT_TRUE,R8,0,I4,-1);
3518 VARXOR(BOOL,VARIANT_FALSE,R8,0,I4,0);
3519 VARXOR(BOOL,VARIANT_TRUE,DATE,-1,I4,0);
3520 VARXOR(BOOL,VARIANT_TRUE,DATE,0,I4,-1);
3521 VARXOR(BOOL,VARIANT_FALSE,DATE,0,I4,0);
3522 if (HAVE_OLEAUT32_I8)
3524 VARXOR(BOOL,VARIANT_TRUE,I8,-1,I8,0);
3525 VARXOR(BOOL,VARIANT_TRUE,I8,0,I8,-1);
3526 VARXOR(BOOL,VARIANT_FALSE,I8,0,I8,0);
3527 /* This returns DISP_E_OVERFLOW which indicates that a conversion
3528 * to I4 is performed.
3530 /* VARXOR(BOOL,VARIANT_TRUE,UI8,-1,I4,-1); */
3531 VARXOR(BOOL,VARIANT_TRUE,UI8,0,I4,-1);
3532 VARXOR(BOOL,VARIANT_FALSE,UI8,0,I4,0);
3534 VARXOR(BOOL,VARIANT_TRUE,INT,-1,I4,0);
3535 VARXOR(BOOL,VARIANT_TRUE,INT,0,I4,-1);
3536 VARXOR(BOOL,VARIANT_FALSE,INT,0,I4,0);
3537 VARXOR(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,0);
3538 VARXOR(BOOL,VARIANT_TRUE,UINT,0,I4,-1);
3539 VARXOR(BOOL,VARIANT_FALSE,UINT,0,I4,0);
3540 rbstr = SysAllocString(szFalse);
3541 VARXOR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_FALSE);
3542 VARXOR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
3543 SysFreeString(rbstr);
3544 rbstr = SysAllocString(szTrue);
3545 VARXOR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_TRUE);
3546 VARXOR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_FALSE);
3547 SysFreeString(rbstr);
3548 VARXORCY(BOOL,VARIANT_TRUE,10000,I4,-2);
3549 VARXORCY(BOOL,VARIANT_TRUE,0,I4,-1);
3550 VARXORCY(BOOL,VARIANT_FALSE,0,I4,0);
3552 VARXOR(I1,-1,I1,-1,I4,0);
3553 VARXOR(I1,-1,I1,0,I4,-1);
3554 VARXOR(I1,0,I1,0,I4,0);
3555 VARXOR(I1,-1,UI1,255,I4,-256);
3556 VARXOR(I1,-1,UI1,0,I4,-1);
3557 VARXOR(I1,0,UI1,0,I4,0);
3558 VARXOR(I1,-1,I2,-1,I4,0);
3559 VARXOR(I1,-1,I2,0,I4,-1);
3560 VARXOR(I1,0,I2,0,I4,0);
3561 VARXOR(I1,-1,UI2,65535,I4,-65536);
3562 VARXOR(I1,-1,UI2,0,I4,-1);
3563 VARXOR(I1,0,UI2,0,I4,0);
3564 VARXOR(I1,-1,I4,-1,I4,0);
3565 VARXOR(I1,-1,I4,0,I4,-1);
3566 VARXOR(I1,0,I4,0,I4,0);
3567 VARXOR(I1,-1,UI4,0xffffffff,I4,0);
3568 VARXOR(I1,-1,UI4,0,I4,-1);
3569 VARXOR(I1,0,UI4,0,I4,0);
3570 VARXOR(I1,-1,R4,-1,I4,0);
3571 VARXOR(I1,-1,R4,0,I4,-1);
3572 VARXOR(I1,0,R4,0,I4,0);
3573 VARXOR(I1,-1,R8,-1,I4,0);
3574 VARXOR(I1,-1,R8,0,I4,-1);
3575 VARXOR(I1,0,R8,0,I4,0);
3576 VARXOR(I1,-1,DATE,-1,I4,0);
3577 VARXOR(I1,-1,DATE,0,I4,-1);
3578 VARXOR(I1,0,DATE,0,I4,0);
3579 if (HAVE_OLEAUT32_I8)
3581 VARXOR(I1,-1,I8,-1,I8,0);
3582 VARXOR(I1,-1,I8,0,I8,-1);
3583 VARXOR(I1,0,I8,0,I8,0);
3584 VARXOR(I1,-1,UI8,0,I4,-1);
3585 VARXOR(I1,0,UI8,0,I4,0);
3587 VARXOR(I1,-1,INT,-1,I4,0);
3588 VARXOR(I1,-1,INT,0,I4,-1);
3589 VARXOR(I1,0,INT,0,I4,0);
3590 VARXOR(I1,-1,UINT,0xffffffff,I4,0);
3591 VARXOR(I1,-1,UINT,0,I4,-1);
3592 VARXOR(I1,0,UINT,0,I4,0);
3593 rbstr = SysAllocString(szFalse);
3594 VARXOR(I1,0,BSTR,rbstr,I4,0);
3595 VARXOR(I1,-1,BSTR,rbstr,I4,-1);
3596 SysFreeString(rbstr);
3597 rbstr = SysAllocString(szTrue);
3598 VARXOR(I1,0,BSTR,rbstr,I4,-1);
3599 VARXOR(I1,-1,BSTR,rbstr,I4,0);
3600 SysFreeString(rbstr);
3601 VARXORCY(I1,-1,10000,I4,-2);
3602 VARXORCY(I1,-1,0,I4,-1);
3603 VARXORCY(I1,0,0,I4,0);
3605 VARXOR(UI1,255,UI1,255,UI1,0);
3606 VARXOR(UI1,255,UI1,0,UI1,255);
3607 VARXOR(UI1,0,UI1,0,UI1,0);
3608 VARXOR(UI1,255,I2,-1,I2,-256);
3609 VARXOR(UI1,255,I2,0,I2,255);
3610 VARXOR(UI1,0,I2,0,I2,0);
3611 VARXOR(UI1,255,UI2,65535,I4,65280);
3612 VARXOR(UI1,255,UI2,0,I4,255);
3613 VARXOR(UI1,0,UI2,0,I4,0);
3614 VARXOR(UI1,255,I4,-1,I4,-256);
3615 VARXOR(UI1,255,I4,0,I4,255);
3616 VARXOR(UI1,0,I4,0,I4,0);
3617 VARXOR(UI1,255,UI4,0xffffffff,I4,-256);
3618 VARXOR(UI1,255,UI4,0,I4,255);
3619 VARXOR(UI1,0,UI4,0,I4,0);
3620 VARXOR(UI1,255,R4,-1,I4,-256);
3621 VARXOR(UI1,255,R4,0,I4,255);
3622 VARXOR(UI1,0,R4,0,I4,0);
3623 VARXOR(UI1,255,R8,-1,I4,-256);
3624 VARXOR(UI1,255,R8,0,I4,255);
3625 VARXOR(UI1,0,R8,0,I4,0);
3626 VARXOR(UI1,255,DATE,-1,I4,-256);
3627 VARXOR(UI1,255,DATE,0,I4,255);
3628 VARXOR(UI1,0,DATE,0,I4,0);
3629 if (HAVE_OLEAUT32_I8)
3631 VARXOR(UI1,255,I8,-1,I8,-256);
3632 VARXOR(UI1,255,I8,0,I8,255);
3633 VARXOR(UI1,0,I8,0,I8,0);
3634 VARXOR(UI1,255,UI8,0,I4,255);
3635 VARXOR(UI1,0,UI8,0,I4,0);
3637 VARXOR(UI1,255,INT,-1,I4,-256);
3638 VARXOR(UI1,255,INT,0,I4,255);
3639 VARXOR(UI1,0,INT,0,I4,0);
3640 VARXOR(UI1,255,UINT,0xffffffff,I4,-256);
3641 VARXOR(UI1,255,UINT,0,I4,255);
3642 VARXOR(UI1,0,UINT,0,I4,0);
3643 rbstr = SysAllocString(szFalse);
3644 VARXOR(UI1,0,BSTR,rbstr,I2,0);
3645 VARXOR(UI1,255,BSTR,rbstr,I2,255);
3646 SysFreeString(rbstr);
3647 rbstr = SysAllocString(szTrue);
3648 VARXOR(UI1,0,BSTR,rbstr,I2,-1);
3649 VARXOR(UI1,255,BSTR,rbstr,I2,-256);
3650 SysFreeString(rbstr);
3651 VARXORCY(UI1,255,10000,I4,254);
3652 VARXORCY(UI1,255,0,I4,255);
3653 VARXORCY(UI1,0,0,I4,0);
3655 VARXOR(I2,-1,I2,-1,I2,0);
3656 VARXOR(I2,-1,I2,0,I2,-1);
3657 VARXOR(I2,0,I2,0,I2,0);
3658 VARXOR(I2,-1,UI2,65535,I4,-65536);
3659 VARXOR(I2,-1,UI2,0,I4,-1);
3660 VARXOR(I2,0,UI2,0,I4,0);
3661 VARXOR(I2,-1,I4,-1,I4,0);
3662 VARXOR(I2,-1,I4,0,I4,-1);
3663 VARXOR(I2,0,I4,0,I4,0);
3664 VARXOR(I2,-1,UI4,0xffffffff,I4,0);
3665 VARXOR(I2,-1,UI4,0,I4,-1);
3666 VARXOR(I2,0,UI4,0,I4,0);
3667 VARXOR(I2,-1,R4,-1,I4,0);
3668 VARXOR(I2,-1,R4,0,I4,-1);
3669 VARXOR(I2,0,R4,0,I4,0);
3670 VARXOR(I2,-1,R8,-1,I4,0);
3671 VARXOR(I2,-1,R8,0,I4,-1);
3672 VARXOR(I2,0,R8,0,I4,0);
3673 VARXOR(I2,-1,DATE,-1,I4,0);
3674 VARXOR(I2,-1,DATE,0,I4,-1);
3675 VARXOR(I2,0,DATE,0,I4,0);
3676 if (HAVE_OLEAUT32_I8)
3678 VARXOR(I2,-1,I8,-1,I8,0);
3679 VARXOR(I2,-1,I8,0,I8,-1);
3680 VARXOR(I2,0,I8,0,I8,0);
3681 VARXOR(I2,-1,UI8,0,I4,-1);
3682 VARXOR(I2,0,UI8,0,I4,0);
3684 VARXOR(I2,-1,INT,-1,I4,0);
3685 VARXOR(I2,-1,INT,0,I4,-1);
3686 VARXOR(I2,0,INT,0,I4,0);
3687 VARXOR(I2,-1,UINT,0xffffffff,I4,0);
3688 VARXOR(I2,-1,UINT,0,I4,-1);
3689 VARXOR(I2,0,UINT,0,I4,0);
3690 rbstr = SysAllocString(szFalse);
3691 VARXOR(I2,0,BSTR,rbstr,I2,0);
3692 VARXOR(I2,-1,BSTR,rbstr,I2,-1);
3693 SysFreeString(rbstr);
3694 rbstr = SysAllocString(szTrue);
3695 VARXOR(I2,0,BSTR,rbstr,I2,-1);
3696 VARXOR(I2,-1,BSTR,rbstr,I2,0);
3697 SysFreeString(rbstr);
3698 VARXORCY(I2,-1,10000,I4,-2);
3699 VARXORCY(I2,-1,0,I4,-1);
3700 VARXORCY(I2,0,0,I4,0);
3702 VARXOR(UI2,65535,UI2,65535,I4,0);
3703 VARXOR(UI2,65535,UI2,0,I4,65535);
3704 VARXOR(UI2,0,UI2,0,I4,0);
3705 VARXOR(UI2,65535,I4,-1,I4,-65536);
3706 VARXOR(UI2,65535,I4,0,I4,65535);
3707 VARXOR(UI2,0,I4,0,I4,0);
3708 VARXOR(UI2,65535,UI4,0xffffffff,I4,-65536);
3709 VARXOR(UI2,65535,UI4,0,I4,65535);
3710 VARXOR(UI2,0,UI4,0,I4,0);
3711 VARXOR(UI2,65535,R4,-1,I4,-65536);
3712 VARXOR(UI2,65535,R4,0,I4,65535);
3713 VARXOR(UI2,0,R4,0,I4,0);
3714 VARXOR(UI2,65535,R8,-1,I4,-65536);
3715 VARXOR(UI2,65535,R8,0,I4,65535);
3716 VARXOR(UI2,0,R8,0,I4,0);
3717 VARXOR(UI2,65535,DATE,-1,I4,-65536);
3718 VARXOR(UI2,65535,DATE,0,I4,65535);
3719 VARXOR(UI2,0,DATE,0,I4,0);
3720 if (HAVE_OLEAUT32_I8)
3722 VARXOR(UI2,65535,I8,-1,I8,-65536);
3723 VARXOR(UI2,65535,I8,0,I8,65535);
3724 VARXOR(UI2,0,I8,0,I8,0);
3725 VARXOR(UI2,65535,UI8,0,I4,65535);
3726 VARXOR(UI2,0,UI8,0,I4,0);
3728 VARXOR(UI2,65535,INT,-1,I4,-65536);
3729 VARXOR(UI2,65535,INT,0,I4,65535);
3730 VARXOR(UI2,0,INT,0,I4,0);
3731 VARXOR(UI2,65535,UINT,0xffffffff,I4,-65536);
3732 VARXOR(UI2,65535,UINT,0,I4,65535);
3733 VARXOR(UI2,0,UINT,0,I4,0);
3734 rbstr = SysAllocString(szFalse);
3735 VARXOR(UI2,0,BSTR,rbstr,I4,0);
3736 VARXOR(UI2,65535,BSTR,rbstr,I4,65535);
3737 SysFreeString(rbstr);
3738 rbstr = SysAllocString(szTrue);
3739 VARXOR(UI2,0,BSTR,rbstr,I4,-1);
3740 VARXOR(UI2,65535,BSTR,rbstr,I4,-65536);
3741 SysFreeString(rbstr);
3742 VARXORCY(UI2,65535,10000,I4,65534);
3743 VARXORCY(UI2,65535,0,I4,65535);
3744 VARXORCY(UI2,0,0,I4,0);
3746 VARXOR(I4,-1,I4,-1,I4,0);
3747 VARXOR(I4,-1,I4,0,I4,-1);
3748 VARXOR(I4,0,I4,0,I4,0);
3749 VARXOR(I4,-1,UI4,0xffffffff,I4,0);
3750 VARXOR(I4,-1,UI4,0,I4,-1);
3751 VARXOR(I4,0,UI4,0,I4,0);
3752 VARXOR(I4,-1,R4,-1,I4,0);
3753 VARXOR(I4,-1,R4,0,I4,-1);
3754 VARXOR(I4,0,R4,0,I4,0);
3755 VARXOR(I4,-1,R8,-1,I4,0);
3756 VARXOR(I4,-1,R8,0,I4,-1);
3757 VARXOR(I4,0,R8,0,I4,0);
3758 VARXOR(I4,-1,DATE,-1,I4,0);
3759 VARXOR(I4,-1,DATE,0,I4,-1);
3760 VARXOR(I4,0,DATE,0,I4,0);
3761 if (HAVE_OLEAUT32_I8)
3763 VARXOR(I4,-1,I8,-1,I8,0);
3764 VARXOR(I4,-1,I8,0,I8,-1);
3765 VARXOR(I4,0,I8,0,I8,0);
3766 VARXOR(I4,-1,UI8,0,I4,-1);
3767 VARXOR(I4,0,UI8,0,I4,0);
3769 VARXOR(I4,-1,INT,-1,I4,0);
3770 VARXOR(I4,-1,INT,0,I4,-1);
3771 VARXOR(I4,0,INT,0,I4,0);
3772 VARXOR(I4,-1,UINT,0xffffffff,I4,0);
3773 VARXOR(I4,-1,UINT,0,I4,-1);
3774 VARXOR(I4,0,UINT,0,I4,0);
3775 rbstr = SysAllocString(szFalse);
3776 VARXOR(I4,0,BSTR,rbstr,I4,0);
3777 VARXOR(I4,-1,BSTR,rbstr,I4,-1);
3778 SysFreeString(rbstr);
3779 rbstr = SysAllocString(szTrue);
3780 VARXOR(I4,0,BSTR,rbstr,I4,-1);
3781 VARXOR(I4,-1,BSTR,rbstr,I4,0);
3782 SysFreeString(rbstr);
3783 VARXORCY(I4,-1,10000,I4,-2);
3784 VARXORCY(I4,-1,0,I4,-1);
3785 VARXORCY(I4,0,0,I4,0);
3787 VARXOR(UI4,0xffffffff,UI4,0xffffffff,I4,0);
3788 VARXOR(UI4,0xffffffff,UI4,0,I4,-1);
3789 VARXOR(UI4,0,UI4,0,I4,0);
3790 VARXOR(UI4,0xffffffff,R4,-1,I4,0);
3791 VARXOR(UI4,0xffffffff,R4,0,I4,-1);
3792 VARXOR(UI4,0,R4,0,I4,0);
3793 VARXOR(UI4,0xffffffff,R8,-1,I4,0);
3794 VARXOR(UI4,0xffffffff,R8,0,I4,-1);
3795 VARXOR(UI4,0,R8,0,I4,0);
3796 VARXOR(UI4,0xffffffff,DATE,-1,I4,0);
3797 VARXOR(UI4,0xffffffff,DATE,0,I4,-1);
3798 VARXOR(UI4,0,DATE,0,I4,0);
3799 if (HAVE_OLEAUT32_I8)
3801 VARXOR(UI4,0xffffffff,I8,0,I8,0xffffffff);
3802 VARXOR(UI4,VARIANT_FALSE,I8,VARIANT_FALSE,I8,0);
3803 VARXOR(UI4,0,I8,0,I8,0);
3804 VARXOR(UI4,0xffffffff,UI8,0,I4,-1);
3805 VARXOR(UI4,0,UI8,0,I4,0);
3807 VARXOR(UI4,0xffffffff,INT,-1,I4,0);
3808 VARXOR(UI4,0xffffffff,INT,0,I4,-1);
3809 VARXOR(UI4,0,INT,0,I4,0);
3810 VARXOR(UI4,0xffffffff,UINT,0xffffffff,I4,0);
3811 VARXOR(UI4,0xffffffff,UINT,0,I4,-1);
3812 VARXOR(UI4,0,UINT,0,I4,0);
3813 rbstr = SysAllocString(szFalse);
3814 VARXOR(UI4,0,BSTR,rbstr,I4,0);
3815 VARXOR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
3816 SysFreeString(rbstr);
3817 rbstr = SysAllocString(szTrue);
3818 VARXOR(UI4,0,BSTR,rbstr,I4,-1);
3819 VARXOR(UI4,0xffffffff,BSTR,rbstr,I4,0);
3820 SysFreeString(rbstr);
3821 VARXORCY(UI4,0xffffffff,10000,I4,-2);
3822 VARXORCY(UI4,0xffffffff,0,I4,-1);
3823 VARXORCY(UI4,0,0,I4,0);
3825 VARXOR(R4,-1,R4,-1,I4,0);
3826 VARXOR(R4,-1,R4,0,I4,-1);
3827 VARXOR(R4,0,R4,0,I4,0);
3828 VARXOR(R4,-1,R8,-1,I4,0);
3829 VARXOR(R4,-1,R8,0,I4,-1);
3830 VARXOR(R4,0,R8,0,I4,0);
3831 VARXOR(R4,-1,DATE,-1,I4,0);
3832 VARXOR(R4,-1,DATE,0,I4,-1);
3833 VARXOR(R4,0,DATE,0,I4,0);
3834 if (HAVE_OLEAUT32_I8)
3836 VARXOR(R4,-1,I8,-1,I8,0);
3837 VARXOR(R4,-1,I8,0,I8,-1);
3838 VARXOR(R4,0,I8,0,I8,0);
3839 VARXOR(R4,-1,UI8,0,I4,-1);
3840 VARXOR(R4,0,UI8,0,I4,0);
3842 VARXOR(R4,-1,INT,-1,I4,0);
3843 VARXOR(R4,-1,INT,0,I4,-1);
3844 VARXOR(R4,0,INT,0,I4,0);
3845 VARXOR(R4,-1,UINT,0xffffffff,I4,0);
3846 VARXOR(R4,-1,UINT,0,I4,-1);
3847 VARXOR(R4,0,UINT,0,I4,0);
3848 rbstr = SysAllocString(szFalse);
3849 VARXOR(R4,0,BSTR,rbstr,I4,0);
3850 VARXOR(R4,-1,BSTR,rbstr,I4,-1);
3851 SysFreeString(rbstr);
3852 rbstr = SysAllocString(szTrue);
3853 VARXOR(R4,0,BSTR,rbstr,I4,-1);
3854 VARXOR(R4,-1,BSTR,rbstr,I4,0);
3855 SysFreeString(rbstr);
3856 VARXORCY(R4,-1,10000,I4,-2);
3857 VARXORCY(R4,-1,0,I4,-1);
3858 VARXORCY(R4,0,0,I4,0);
3860 VARXOR(R8,-1,R8,-1,I4,0);
3861 VARXOR(R8,-1,R8,0,I4,-1);
3862 VARXOR(R8,0,R8,0,I4,0);
3863 VARXOR(R8,-1,DATE,-1,I4,0);
3864 VARXOR(R8,-1,DATE,0,I4,-1);
3865 VARXOR(R8,0,DATE,0,I4,0);
3866 if (HAVE_OLEAUT32_I8)
3868 VARXOR(R8,-1,I8,-1,I8,0);
3869 VARXOR(R8,-1,I8,0,I8,-1);
3870 VARXOR(R8,0,I8,0,I8,0);
3871 VARXOR(R8,-1,UI8,0,I4,-1);
3872 VARXOR(R8,0,UI8,0,I4,0);
3874 VARXOR(R8,-1,INT,-1,I4,0);
3875 VARXOR(R8,-1,INT,0,I4,-1);
3876 VARXOR(R8,0,INT,0,I4,0);
3877 VARXOR(R8,-1,UINT,0xffffffff,I4,0);
3878 VARXOR(R8,-1,UINT,0,I4,-1);
3879 VARXOR(R8,0,UINT,0,I4,0);
3880 rbstr = SysAllocString(szFalse);
3881 VARXOR(R8,0,BSTR,rbstr,I4,0);
3882 VARXOR(R8,-1,BSTR,rbstr,I4,-1);
3883 SysFreeString(rbstr);
3884 rbstr = SysAllocString(szTrue);
3885 VARXOR(R8,0,BSTR,rbstr,I4,-1);
3886 VARXOR(R8,-1,BSTR,rbstr,I4,0);
3887 SysFreeString(rbstr);
3888 VARXORCY(R8,-1,10000,I4,-2);
3889 VARXORCY(R8,-1,0,I4,-1);
3890 VARXORCY(R8,0,0,I4,0);
3892 VARXOR(DATE,-1,DATE,-1,I4,0);
3893 VARXOR(DATE,-1,DATE,0,I4,-1);
3894 VARXOR(DATE,0,DATE,0,I4,0);
3895 if (HAVE_OLEAUT32_I8)
3897 VARXOR(DATE,-1,I8,-1,I8,0);
3898 VARXOR(DATE,-1,I8,0,I8,-1);
3899 VARXOR(DATE,0,I8,0,I8,0);
3900 VARXOR(DATE,-1,UI8,0,I4,-1);
3901 VARXOR(DATE,0,UI8,0,I4,0);
3903 VARXOR(DATE,-1,INT,-1,I4,0);
3904 VARXOR(DATE,-1,INT,0,I4,-1);
3905 VARXOR(DATE,0,INT,0,I4,0);
3906 VARXOR(DATE,-1,UINT,0xffffffff,I4,0);
3907 VARXOR(DATE,-1,UINT,0,I4,-1);
3908 VARXOR(DATE,0,UINT,0,I4,0);
3909 rbstr = SysAllocString(szFalse);
3910 VARXOR(DATE,0,BSTR,rbstr,I4,0);
3911 VARXOR(DATE,-1,BSTR,rbstr,I4,-1);
3912 SysFreeString(rbstr);
3913 rbstr = SysAllocString(szTrue);
3914 VARXOR(DATE,0,BSTR,rbstr,I4,-1);
3915 VARXOR(DATE,-1,BSTR,rbstr,I4,0);
3916 SysFreeString(rbstr);
3917 VARXORCY(DATE,-1,10000,I4,-2);
3918 VARXORCY(DATE,-1,0,I4,-1);
3919 VARXORCY(DATE,0,0,I4,0);
3921 if (HAVE_OLEAUT32_I8)
3923 VARXOR(I8,-1,I8,-1,I8,0);
3924 VARXOR(I8,-1,I8,0,I8,-1);
3925 VARXOR(I8,0,I8,0,I8,0);
3926 VARXOR(I8,-1,UI8,0,I8,-1);
3927 VARXOR(I8,0,UI8,0,I8,0);
3928 VARXOR(I8,-1,UINT,0,I8,-1);
3929 VARXOR(I8,0,UINT,0,I8,0);
3930 rbstr = SysAllocString(szFalse);
3931 VARXOR(I8,0,BSTR,rbstr,I8,0);
3932 VARXOR(I8,-1,BSTR,rbstr,I8,-1);
3933 SysFreeString(rbstr);
3934 rbstr = SysAllocString(szTrue);
3935 VARXOR(I8,0,BSTR,rbstr,I8,-1);
3936 VARXOR(I8,-1,BSTR,rbstr,I8,0);
3937 SysFreeString(rbstr);
3938 VARXORCY(I8,-1,10000,I8,-2);
3939 VARXORCY(I8,-1,0,I8,-1);
3940 VARXORCY(I8,0,0,I8,0);
3942 VARXOR(UI8,0xffff,UI8,0xffff,I4,0);
3943 VARXOR(UI8,0xffff,UI8,0,I4,0xffff);
3944 VARXOR(UI8,0,UI8,0,I4,0);
3945 VARXOR(UI8,0xffff,INT,-1,I4,-65536);
3946 VARXOR(UI8,0xffff,INT,0,I4,0xffff);
3947 VARXOR(UI8,0,INT,0,I4,0);
3948 VARXOR(UI8,0xffff,UINT,0xffff,I4,0);
3949 VARXOR(UI8,0xffff,UINT,0,I4,0xffff);
3950 VARXOR(UI8,0,UINT,0,I4,0);
3951 rbstr = SysAllocString(szFalse);
3952 VARXOR(UI8,0,BSTR,rbstr,I4,0);
3953 VARXOR(UI8,0xffff,BSTR,rbstr,I4,0xffff);
3954 SysFreeString(rbstr);
3955 rbstr = SysAllocString(szTrue);
3956 VARXOR(UI8,0,BSTR,rbstr,I4,-1);
3957 VARXOR(UI8,0xffff,BSTR,rbstr,I4,-65536);
3958 SysFreeString(rbstr);
3959 VARXORCY(UI8,0xffff,10000,I4,65534);
3960 VARXORCY(UI8,0xffff,0,I4,0xffff);
3961 VARXORCY(UI8,0,0,I4,0);
3964 VARXOR(INT,-1,INT,-1,I4,0);
3965 VARXOR(INT,-1,INT,0,I4,-1);
3966 VARXOR(INT,0,INT,0,I4,0);
3967 VARXOR(INT,-1,UINT,0xffff,I4,-65536);
3968 VARXOR(INT,-1,UINT,0,I4,-1);
3969 VARXOR(INT,0,UINT,0,I4,0);
3970 rbstr = SysAllocString(szFalse);
3971 VARXOR(INT,0,BSTR,rbstr,I4,0);
3972 VARXOR(INT,-1,BSTR,rbstr,I4,-1);
3973 SysFreeString(rbstr);
3974 rbstr = SysAllocString(szTrue);
3975 VARXOR(INT,0,BSTR,rbstr,I4,-1);
3976 VARXOR(INT,-1,BSTR,rbstr,I4,0);
3977 SysFreeString(rbstr);
3978 VARXORCY(INT,-1,10000,I4,-2);
3979 VARXORCY(INT,-1,0,I4,-1);
3980 VARXORCY(INT,0,0,I4,0);
3982 VARXOR(UINT,0xffff,UINT,0xffff,I4,0);
3983 VARXOR(UINT,0xffff,UINT,0,I4,0xffff);
3984 VARXOR(UINT,0,UINT,0,I4,0);
3985 rbstr = SysAllocString(szFalse);
3986 VARXOR(UINT,0,BSTR,rbstr,I4,0);
3987 VARXOR(UINT,0xffff,BSTR,rbstr,I4,0xffff);
3988 SysFreeString(rbstr);
3989 rbstr = SysAllocString(szTrue);
3990 VARXOR(UINT,0,BSTR,rbstr,I4,-1);
3991 VARXOR(UINT,0xffff,BSTR,rbstr,I4,-65536);
3992 SysFreeString(rbstr);
3993 VARXORCY(UINT,0xffff,10000,I4,65534);
3994 VARXORCY(UINT,0xffff,0,I4,0xffff);
3995 VARXORCY(UINT,0,0,I4,0);
3997 lbstr = SysAllocString(szFalse);
3998 rbstr = SysAllocString(szFalse);
3999 VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,0);
4000 SysFreeString(rbstr);
4001 rbstr = SysAllocString(szTrue);
4002 VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
4003 SysFreeString(lbstr);
4004 lbstr = SysAllocString(szTrue);
4005 VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_FALSE);
4006 VARXORCY(BSTR,lbstr,10000,I4,-2);
4007 SysFreeString(lbstr);
4008 lbstr = SysAllocString(szFalse);
4009 VARXORCY(BSTR,lbstr,10000,I4,1);
4010 SysFreeString(lbstr);
4011 SysFreeString(rbstr);
4014 static HRESULT (WINAPI *pVarOr)(LPVARIANT,LPVARIANT,LPVARIANT);
4016 #define VAROR(vt1,val1,vt2,val2,rvt,rval) \
4017 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
4018 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
4019 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
4020 test_var_call2( __LINE__, pVarOr, &left, &right, &exp )
4022 #define VARORCY(vt1,val1,val2,rvt,rval) \
4023 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
4024 V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \
4025 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
4026 test_var_call2( __LINE__, pVarOr, &left, &right, &exp )
4028 static void test_VarOr(void)
4030 static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
4031 static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
4032 VARIANT left, right, exp, result;
4039 /* Test all possible flag/vt combinations & the resulting vt type */
4040 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
4042 VARTYPE leftvt, rightvt, resvt;
4044 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
4049 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
4055 if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
4056 leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
4057 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
4060 memset(&left, 0, sizeof(left));
4061 memset(&right, 0, sizeof(right));
4062 V_VT(&left) = leftvt | ExtraFlags[i];
4063 V_VT(&right) = rightvt | ExtraFlags[i];
4064 V_VT(&result) = VT_EMPTY;
4067 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
4068 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
4069 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
4070 leftvt == VT_CLSID || rightvt == VT_CLSID ||
4071 leftvt == VT_RECORD || rightvt == VT_RECORD ||
4072 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
4073 leftvt == VT_ERROR || rightvt == VT_ERROR)
4077 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
4079 if (leftvt == rightvt ||
4080 leftvt == VT_I2 || rightvt == VT_I2 ||
4081 leftvt == VT_UI1 || rightvt == VT_UI1 ||
4082 leftvt == VT_BOOL || rightvt == VT_BOOL)
4084 else if (leftvt == VT_NULL || rightvt == VT_NULL)
4086 else if (leftvt == VT_I8 || rightvt == VT_I8)
4089 else if (leftvt == VT_NULL || rightvt == VT_NULL)
4093 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
4095 if (leftvt == rightvt)
4097 else if (leftvt == rightvt ||
4098 leftvt == VT_I2 || rightvt == VT_I2 ||
4099 leftvt == VT_BOOL || rightvt == VT_BOOL)
4103 else if (leftvt == VT_I8 || rightvt == VT_I8)
4106 else if (leftvt == VT_I2 || rightvt == VT_I2)
4108 if (leftvt == rightvt ||
4109 leftvt == VT_BOOL || rightvt == VT_BOOL)
4111 else if (leftvt == VT_I8 || rightvt == VT_I8)
4114 else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
4118 else if (leftvt == VT_I8 || rightvt == VT_I8)
4120 if (leftvt == VT_INT || rightvt == VT_INT)
4125 hres = pVarOr(&left, &right, &result);
4127 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
4128 "VarOr: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
4129 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
4132 ok(hres == S_OK && V_VT(&result) == resvt,
4133 "VarOr: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
4134 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
4140 /* Test returned values. Since we know the returned type is correct
4141 * and that we handle all combinations of invalid types, just check
4142 * that good type combinations produce the desired value.
4143 * FIXME: Test VT_DECIMAL/VT_DISPATCH
4145 VAROR(EMPTY,0,EMPTY,0,I2,0);
4146 VAROR(EMPTY,1,EMPTY,0,I2,0);
4147 VAROR(EMPTY,0,NULL,0,NULL,0);
4148 VAROR(EMPTY,0,I1,0,I4,0);
4149 VAROR(EMPTY,0,I1,1,I4,1);
4150 VAROR(EMPTY,0,UI1,0,I2,0);
4151 VAROR(EMPTY,0,UI1,1,I2,1);
4152 VAROR(EMPTY,0,I2,0,I2,0);
4153 VAROR(EMPTY,0,I2,1,I2,1);
4154 VAROR(EMPTY,0,UI2,0,I4,0);
4155 VAROR(EMPTY,0,UI2,1,I4,1);
4156 VAROR(EMPTY,0,I4,0,I4,0);
4157 VAROR(EMPTY,0,I4,1,I4,1);
4158 VAROR(EMPTY,0,UI4,0,I4,0);
4159 VAROR(EMPTY,0,UI4,1,I4,1);
4160 if (HAVE_OLEAUT32_I8)
4162 VAROR(EMPTY,0,I8,0,I8,0);
4163 VAROR(EMPTY,0,I8,1,I8,1);
4164 VAROR(EMPTY,0,UI8,0,I4,0);
4165 VAROR(EMPTY,0,UI8,1,I4,1);
4167 VAROR(EMPTY,0,INT,0,I4,0);
4168 VAROR(EMPTY,0,INT,1,I4,1);
4169 VAROR(EMPTY,0,UINT,0,I4,0);
4170 VAROR(EMPTY,0,UINT,1,I4,1);
4171 VAROR(EMPTY,0,BOOL,0,I2,0);
4172 VAROR(EMPTY,0,BOOL,1,I2,1);
4173 VAROR(EMPTY,0,R4,0,I4,0);
4174 VAROR(EMPTY,0,R4,1,I4,1);
4175 VAROR(EMPTY,0,R8,0,I4,0);
4176 VAROR(EMPTY,0,R8,1,I4,1);
4177 rbstr = SysAllocString(szFalse);
4178 VAROR(EMPTY,0,BSTR,rbstr,I2,0);
4179 SysFreeString(rbstr);
4180 rbstr = SysAllocString(szTrue);
4181 VAROR(EMPTY,0,BSTR,rbstr,I2,-1);
4182 SysFreeString(rbstr);
4183 VARORCY(EMPTY,0,10000,I4,1);
4185 /* NULL OR 0 = NULL. NULL OR n = n */
4186 VAROR(NULL,0,NULL,0,NULL,0);
4187 VAROR(NULL,1,NULL,0,NULL,0);
4188 VAROR(NULL,0,I1,0,NULL,0);
4189 VAROR(NULL,0,I1,1,I4,1);
4190 VAROR(NULL,0,UI1,0,NULL,0);
4191 VAROR(NULL,0,UI1,1,UI1,1);
4192 VAROR(NULL,0,I2,0,NULL,0);
4193 VAROR(NULL,0,I2,1,I2,1);
4194 VAROR(NULL,0,UI2,0,NULL,0);
4195 VAROR(NULL,0,UI2,1,I4,1);
4196 VAROR(NULL,0,I4,0,NULL,0);
4197 VAROR(NULL,0,I4,1,I4,1);
4198 VAROR(NULL,0,UI4,0,NULL,0);
4199 VAROR(NULL,0,UI4,1,I4,1);
4200 if (HAVE_OLEAUT32_I8)
4202 VAROR(NULL,0,I8,0,NULL,0);
4203 VAROR(NULL,0,I8,1,I8,1);
4204 VAROR(NULL,0,UI8,0,NULL,0);
4205 VAROR(NULL,0,UI8,1,I4,1);
4207 VAROR(NULL,0,INT,0,NULL,0);
4208 VAROR(NULL,0,INT,1,I4,1);
4209 VAROR(NULL,0,UINT,0,NULL,0);
4210 VAROR(NULL,0,UINT,1,I4,1);
4211 VAROR(NULL,0,BOOL,0,NULL,0);
4212 VAROR(NULL,0,BOOL,1,BOOL,1);
4213 VAROR(NULL,0,R4,0,NULL,0);
4214 VAROR(NULL,0,R4,1,I4,1);
4215 VAROR(NULL,0,R8,0,NULL,0);
4216 VAROR(NULL,0,R8,1,I4,1);
4217 rbstr = SysAllocString(szFalse);
4218 VAROR(NULL,0,BSTR,rbstr,NULL,0);
4219 SysFreeString(rbstr);
4220 rbstr = SysAllocString(szTrue);
4221 VAROR(NULL,0,BSTR,rbstr,BOOL,VARIANT_TRUE);
4222 SysFreeString(rbstr);
4223 VARORCY(NULL,0,10000,I4,1);
4224 VARORCY(NULL,0,0,NULL,0);
4226 VAROR(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
4227 VAROR(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
4228 VAROR(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
4229 VAROR(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
4230 /* Assume x,y & y,x are the same from now on to reduce the number of tests */
4231 VAROR(BOOL,VARIANT_TRUE,I1,-1,I4,-1);
4232 VAROR(BOOL,VARIANT_TRUE,I1,0,I4,-1);
4233 VAROR(BOOL,VARIANT_FALSE,I1,0,I4,0);
4234 VAROR(BOOL,VARIANT_TRUE,UI1,255,I2,-1);
4235 VAROR(BOOL,VARIANT_TRUE,UI1,0,I2,-1);
4236 VAROR(BOOL,VARIANT_FALSE,UI1,0,I2,0);
4237 VAROR(BOOL,VARIANT_TRUE,I2,-1,I2,-1);
4238 VAROR(BOOL,VARIANT_TRUE,I2,0,I2,-1);
4239 VAROR(BOOL,VARIANT_FALSE,I2,0,I2,0);
4240 VAROR(BOOL,VARIANT_TRUE,UI2,65535,I4,-1);
4241 VAROR(BOOL,VARIANT_TRUE,UI2,0,I4,-1);
4242 VAROR(BOOL,VARIANT_FALSE,UI2,0,I4,0);
4243 VAROR(BOOL,VARIANT_TRUE,I4,-1,I4,-1);
4244 VAROR(BOOL,VARIANT_TRUE,I4,0,I4,-1);
4245 VAROR(BOOL,VARIANT_FALSE,I4,0,I4,0);
4246 VAROR(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,-1);
4247 VAROR(BOOL,VARIANT_TRUE,UI4,0,I4,-1);
4248 VAROR(BOOL,VARIANT_FALSE,UI4,0,I4,0);
4249 VAROR(BOOL,VARIANT_TRUE,R4,-1,I4,-1);
4250 VAROR(BOOL,VARIANT_TRUE,R4,0,I4,-1);
4251 VAROR(BOOL,VARIANT_FALSE,R4,0,I4,0);
4252 VAROR(BOOL,VARIANT_TRUE,R8,-1,I4,-1);
4253 VAROR(BOOL,VARIANT_TRUE,R8,0,I4,-1);
4254 VAROR(BOOL,VARIANT_FALSE,R8,0,I4,0);
4255 VAROR(BOOL,VARIANT_TRUE,DATE,-1,I4,-1);
4256 VAROR(BOOL,VARIANT_TRUE,DATE,0,I4,-1);
4257 VAROR(BOOL,VARIANT_FALSE,DATE,0,I4,0);
4258 if (HAVE_OLEAUT32_I8)
4260 VAROR(BOOL,VARIANT_TRUE,I8,-1,I8,-1);
4261 VAROR(BOOL,VARIANT_TRUE,I8,0,I8,-1);
4262 VAROR(BOOL,VARIANT_FALSE,I8,0,I8,0);
4263 /* This returns DISP_E_OVERFLOW which indicates that a conversion
4264 * to I4 is performed.
4266 /* VAROR(BOOL,VARIANT_TRUE,UI8,-1,I4,-1); */
4267 VAROR(BOOL,VARIANT_TRUE,UI8,0,I4,-1);
4268 VAROR(BOOL,VARIANT_FALSE,UI8,0,I4,0);
4270 VAROR(BOOL,VARIANT_TRUE,INT,-1,I4,-1);
4271 VAROR(BOOL,VARIANT_TRUE,INT,0,I4,-1);
4272 VAROR(BOOL,VARIANT_FALSE,INT,0,I4,0);
4273 VAROR(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,-1);
4274 VAROR(BOOL,VARIANT_TRUE,UINT,0,I4,-1);
4275 VAROR(BOOL,VARIANT_FALSE,UINT,0,I4,0);
4276 rbstr = SysAllocString(szFalse);
4277 VAROR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_FALSE);
4278 VAROR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
4279 SysFreeString(rbstr);
4280 rbstr = SysAllocString(szTrue);
4281 VAROR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_TRUE);
4282 VAROR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
4283 SysFreeString(rbstr);
4284 VARORCY(BOOL,VARIANT_TRUE,10000,I4,-1);
4285 VARORCY(BOOL,VARIANT_TRUE,0,I4,-1);
4286 VARORCY(BOOL,VARIANT_FALSE,0,I4,0);
4288 VAROR(I1,-1,I1,-1,I4,-1);
4289 VAROR(I1,-1,I1,0,I4,-1);
4290 VAROR(I1,0,I1,0,I4,0);
4291 VAROR(I1,-1,UI1,255,I4,-1);
4292 VAROR(I1,-1,UI1,0,I4,-1);
4293 VAROR(I1,0,UI1,0,I4,0);
4294 VAROR(I1,-1,I2,-1,I4,-1);
4295 VAROR(I1,-1,I2,0,I4,-1);
4296 VAROR(I1,0,I2,0,I4,0);
4297 VAROR(I1,-1,UI2,65535,I4,-1);
4298 VAROR(I1,-1,UI2,0,I4,-1);
4299 VAROR(I1,0,UI2,0,I4,0);
4300 VAROR(I1,-1,I4,-1,I4,-1);
4301 VAROR(I1,-1,I4,0,I4,-1);
4302 VAROR(I1,0,I4,0,I4,0);
4303 VAROR(I1,-1,UI4,0xffffffff,I4,-1);
4304 VAROR(I1,-1,UI4,0,I4,-1);
4305 VAROR(I1,0,UI4,0,I4,0);
4306 VAROR(I1,-1,R4,-1,I4,-1);
4307 VAROR(I1,-1,R4,0,I4,-1);
4308 VAROR(I1,0,R4,0,I4,0);
4309 VAROR(I1,-1,R8,-1,I4,-1);
4310 VAROR(I1,-1,R8,0,I4,-1);
4311 VAROR(I1,0,R8,0,I4,0);
4312 VAROR(I1,-1,DATE,-1,I4,-1);
4313 VAROR(I1,-1,DATE,0,I4,-1);
4314 VAROR(I1,0,DATE,0,I4,0);
4315 if (HAVE_OLEAUT32_I8)
4317 VAROR(I1,-1,I8,-1,I8,-1);
4318 VAROR(I1,-1,I8,0,I8,-1);
4319 VAROR(I1,0,I8,0,I8,0);
4320 VAROR(I1,-1,UI8,0,I4,-1);
4321 VAROR(I1,0,UI8,0,I4,0);
4323 VAROR(I1,-1,INT,-1,I4,-1);
4324 VAROR(I1,-1,INT,0,I4,-1);
4325 VAROR(I1,0,INT,0,I4,0);
4326 VAROR(I1,-1,UINT,0xffffffff,I4,-1);
4327 VAROR(I1,-1,UINT,0,I4,-1);
4328 VAROR(I1,0,UINT,0,I4,0);
4329 rbstr = SysAllocString(szFalse);
4330 VAROR(I1,0,BSTR,rbstr,I4,0);
4331 VAROR(I1,-1,BSTR,rbstr,I4,-1);
4332 SysFreeString(rbstr);
4333 rbstr = SysAllocString(szTrue);
4334 VAROR(I1,0,BSTR,rbstr,I4,-1);
4335 VAROR(I1,-1,BSTR,rbstr,I4,-1);
4336 SysFreeString(rbstr);
4337 VARORCY(I1,-1,10000,I4,-1);
4338 VARORCY(I1,-1,0,I4,-1);
4339 VARORCY(I1,0,0,I4,0);
4341 VAROR(UI1,255,UI1,255,UI1,255);
4342 VAROR(UI1,255,UI1,0,UI1,255);
4343 VAROR(UI1,0,UI1,0,UI1,0);
4344 VAROR(UI1,255,I2,-1,I2,-1);
4345 VAROR(UI1,255,I2,0,I2,255);
4346 VAROR(UI1,0,I2,0,I2,0);
4347 VAROR(UI1,255,UI2,65535,I4,65535);
4348 VAROR(UI1,255,UI2,0,I4,255);
4349 VAROR(UI1,0,UI2,0,I4,0);
4350 VAROR(UI1,255,I4,-1,I4,-1);
4351 VAROR(UI1,255,I4,0,I4,255);
4352 VAROR(UI1,0,I4,0,I4,0);
4353 VAROR(UI1,255,UI4,0xffffffff,I4,-1);
4354 VAROR(UI1,255,UI4,0,I4,255);
4355 VAROR(UI1,0,UI4,0,I4,0);
4356 VAROR(UI1,255,R4,-1,I4,-1);
4357 VAROR(UI1,255,R4,0,I4,255);
4358 VAROR(UI1,0,R4,0,I4,0);
4359 VAROR(UI1,255,R8,-1,I4,-1);
4360 VAROR(UI1,255,R8,0,I4,255);
4361 VAROR(UI1,0,R8,0,I4,0);
4362 VAROR(UI1,255,DATE,-1,I4,-1);
4363 VAROR(UI1,255,DATE,0,I4,255);
4364 VAROR(UI1,0,DATE,0,I4,0);
4365 if (HAVE_OLEAUT32_I8)
4367 VAROR(UI1,255,I8,-1,I8,-1);
4368 VAROR(UI1,255,I8,0,I8,255);
4369 VAROR(UI1,0,I8,0,I8,0);
4370 VAROR(UI1,255,UI8,0,I4,255);
4371 VAROR(UI1,0,UI8,0,I4,0);
4373 VAROR(UI1,255,INT,-1,I4,-1);
4374 VAROR(UI1,255,INT,0,I4,255);
4375 VAROR(UI1,0,INT,0,I4,0);
4376 VAROR(UI1,255,UINT,0xffffffff,I4,-1);
4377 VAROR(UI1,255,UINT,0,I4,255);
4378 VAROR(UI1,0,UINT,0,I4,0);
4379 rbstr = SysAllocString(szFalse);
4380 VAROR(UI1,0,BSTR,rbstr,I2,0);
4381 VAROR(UI1,255,BSTR,rbstr,I2,255);
4382 SysFreeString(rbstr);
4383 rbstr = SysAllocString(szTrue);
4384 VAROR(UI1,0,BSTR,rbstr,I2,-1);
4385 VAROR(UI1,255,BSTR,rbstr,I2,-1);
4386 SysFreeString(rbstr);
4387 VARORCY(UI1,255,10000,I4,255);
4388 VARORCY(UI1,255,0,I4,255);
4389 VARORCY(UI1,0,0,I4,0);
4391 VAROR(I2,-1,I2,-1,I2,-1);
4392 VAROR(I2,-1,I2,0,I2,-1);
4393 VAROR(I2,0,I2,0,I2,0);
4394 VAROR(I2,-1,UI2,65535,I4,-1);
4395 VAROR(I2,-1,UI2,0,I4,-1);
4396 VAROR(I2,0,UI2,0,I4,0);
4397 VAROR(I2,-1,I4,-1,I4,-1);
4398 VAROR(I2,-1,I4,0,I4,-1);
4399 VAROR(I2,0,I4,0,I4,0);
4400 VAROR(I2,-1,UI4,0xffffffff,I4,-1);
4401 VAROR(I2,-1,UI4,0,I4,-1);
4402 VAROR(I2,0,UI4,0,I4,0);
4403 VAROR(I2,-1,R4,-1,I4,-1);
4404 VAROR(I2,-1,R4,0,I4,-1);
4405 VAROR(I2,0,R4,0,I4,0);
4406 VAROR(I2,-1,R8,-1,I4,-1);
4407 VAROR(I2,-1,R8,0,I4,-1);
4408 VAROR(I2,0,R8,0,I4,0);
4409 VAROR(I2,-1,DATE,-1,I4,-1);
4410 VAROR(I2,-1,DATE,0,I4,-1);
4411 VAROR(I2,0,DATE,0,I4,0);
4412 if (HAVE_OLEAUT32_I8)
4414 VAROR(I2,-1,I8,-1,I8,-1);
4415 VAROR(I2,-1,I8,0,I8,-1);
4416 VAROR(I2,0,I8,0,I8,0);
4417 VAROR(I2,-1,UI8,0,I4,-1);
4418 VAROR(I2,0,UI8,0,I4,0);
4420 VAROR(I2,-1,INT,-1,I4,-1);
4421 VAROR(I2,-1,INT,0,I4,-1);
4422 VAROR(I2,0,INT,0,I4,0);
4423 VAROR(I2,-1,UINT,0xffffffff,I4,-1);
4424 VAROR(I2,-1,UINT,0,I4,-1);
4425 VAROR(I2,0,UINT,0,I4,0);
4426 rbstr = SysAllocString(szFalse);
4427 VAROR(I2,0,BSTR,rbstr,I2,0);
4428 VAROR(I2,-1,BSTR,rbstr,I2,-1);
4429 SysFreeString(rbstr);
4430 rbstr = SysAllocString(szTrue);
4431 VAROR(I2,0,BSTR,rbstr,I2,-1);
4432 VAROR(I2,-1,BSTR,rbstr,I2,-1);
4433 SysFreeString(rbstr);
4434 VARORCY(I2,-1,10000,I4,-1);
4435 VARORCY(I2,-1,0,I4,-1);
4436 VARORCY(I2,0,0,I4,0);
4438 VAROR(UI2,65535,UI2,65535,I4,65535);
4439 VAROR(UI2,65535,UI2,0,I4,65535);
4440 VAROR(UI2,0,UI2,0,I4,0);
4441 VAROR(UI2,65535,I4,-1,I4,-1);
4442 VAROR(UI2,65535,I4,0,I4,65535);
4443 VAROR(UI2,0,I4,0,I4,0);
4444 VAROR(UI2,65535,UI4,0xffffffff,I4,-1);
4445 VAROR(UI2,65535,UI4,0,I4,65535);
4446 VAROR(UI2,0,UI4,0,I4,0);
4447 VAROR(UI2,65535,R4,-1,I4,-1);
4448 VAROR(UI2,65535,R4,0,I4,65535);
4449 VAROR(UI2,0,R4,0,I4,0);
4450 VAROR(UI2,65535,R8,-1,I4,-1);
4451 VAROR(UI2,65535,R8,0,I4,65535);
4452 VAROR(UI2,0,R8,0,I4,0);
4453 VAROR(UI2,65535,DATE,-1,I4,-1);
4454 VAROR(UI2,65535,DATE,0,I4,65535);
4455 VAROR(UI2,0,DATE,0,I4,0);
4456 if (HAVE_OLEAUT32_I8)
4458 VAROR(UI2,65535,I8,-1,I8,-1);
4459 VAROR(UI2,65535,I8,0,I8,65535);
4460 VAROR(UI2,0,I8,0,I8,0);
4461 VAROR(UI2,65535,UI8,0,I4,65535);
4462 VAROR(UI2,0,UI8,0,I4,0);
4464 VAROR(UI2,65535,INT,-1,I4,-1);
4465 VAROR(UI2,65535,INT,0,I4,65535);
4466 VAROR(UI2,0,INT,0,I4,0);
4467 VAROR(UI2,65535,UINT,0xffffffff,I4,-1);
4468 VAROR(UI2,65535,UINT,0,I4,65535);
4469 VAROR(UI2,0,UINT,0,I4,0);
4470 rbstr = SysAllocString(szFalse);
4471 VAROR(UI2,0,BSTR,rbstr,I4,0);
4472 VAROR(UI2,65535,BSTR,rbstr,I4,65535);
4473 SysFreeString(rbstr);
4474 rbstr = SysAllocString(szTrue);
4475 VAROR(UI2,0,BSTR,rbstr,I4,-1);
4476 VAROR(UI2,65535,BSTR,rbstr,I4,-1);
4477 SysFreeString(rbstr);
4478 VARORCY(UI2,65535,10000,I4,65535);
4479 VARORCY(UI2,65535,0,I4,65535);
4480 VARORCY(UI2,0,0,I4,0);
4482 VAROR(I4,-1,I4,-1,I4,-1);
4483 VAROR(I4,-1,I4,0,I4,-1);
4484 VAROR(I4,0,I4,0,I4,0);
4485 VAROR(I4,-1,UI4,0xffffffff,I4,-1);
4486 VAROR(I4,-1,UI4,0,I4,-1);
4487 VAROR(I4,0,UI4,0,I4,0);
4488 VAROR(I4,-1,R4,-1,I4,-1);
4489 VAROR(I4,-1,R4,0,I4,-1);
4490 VAROR(I4,0,R4,0,I4,0);
4491 VAROR(I4,-1,R8,-1,I4,-1);
4492 VAROR(I4,-1,R8,0,I4,-1);
4493 VAROR(I4,0,R8,0,I4,0);
4494 VAROR(I4,-1,DATE,-1,I4,-1);
4495 VAROR(I4,-1,DATE,0,I4,-1);
4496 VAROR(I4,0,DATE,0,I4,0);
4497 if (HAVE_OLEAUT32_I8)
4499 VAROR(I4,-1,I8,-1,I8,-1);
4500 VAROR(I4,-1,I8,0,I8,-1);
4501 VAROR(I4,0,I8,0,I8,0);
4502 VAROR(I4,-1,UI8,0,I4,-1);
4503 VAROR(I4,0,UI8,0,I4,0);
4505 VAROR(I4,-1,INT,-1,I4,-1);
4506 VAROR(I4,-1,INT,0,I4,-1);
4507 VAROR(I4,0,INT,0,I4,0);
4508 VAROR(I4,-1,UINT,0xffffffff,I4,-1);
4509 VAROR(I4,-1,UINT,0,I4,-1);
4510 VAROR(I4,0,UINT,0,I4,0);
4511 rbstr = SysAllocString(szFalse);
4512 VAROR(I4,0,BSTR,rbstr,I4,0);
4513 VAROR(I4,-1,BSTR,rbstr,I4,-1);
4514 SysFreeString(rbstr);
4515 rbstr = SysAllocString(szTrue);
4516 VAROR(I4,0,BSTR,rbstr,I4,-1);
4517 VAROR(I4,-1,BSTR,rbstr,I4,-1);
4518 SysFreeString(rbstr);
4519 VARORCY(I4,-1,10000,I4,-1);
4520 VARORCY(I4,-1,0,I4,-1);
4521 VARORCY(I4,0,0,I4,0);
4523 VAROR(UI4,0xffffffff,UI4,0xffffffff,I4,-1);
4524 VAROR(UI4,0xffffffff,UI4,0,I4,-1);
4525 VAROR(UI4,0,UI4,0,I4,0);
4526 VAROR(UI4,0xffffffff,R4,-1,I4,-1);
4527 VAROR(UI4,0xffffffff,R4,0,I4,-1);
4528 VAROR(UI4,0,R4,0,I4,0);
4529 VAROR(UI4,0xffffffff,R8,-1,I4,-1);
4530 VAROR(UI4,0xffffffff,R8,0,I4,-1);
4531 VAROR(UI4,0,R8,0,I4,0);
4532 VAROR(UI4,0xffffffff,DATE,-1,I4,-1);
4533 VAROR(UI4,0xffffffff,DATE,0,I4,-1);
4534 VAROR(UI4,0,DATE,0,I4,0);
4535 if (HAVE_OLEAUT32_I8)
4537 VAROR(UI4,0xffffffff,I8,-1,I8,-1);
4538 VAROR(UI4,0xffffffff,I8,0,I8,0xffffffff);
4539 VAROR(UI4,0,I8,0,I8,0);
4540 VAROR(UI4,0xffffffff,UI8,0,I4,-1);
4541 VAROR(UI4,0,UI8,0,I4,0);
4543 VAROR(UI4,0xffffffff,INT,-1,I4,-1);
4544 VAROR(UI4,0xffffffff,INT,0,I4,-1);
4545 VAROR(UI4,0,INT,0,I4,0);
4546 VAROR(UI4,0xffffffff,UINT,0xffffffff,I4,-1);
4547 VAROR(UI4,0xffffffff,UINT,0,I4,-1);
4548 VAROR(UI4,0,UINT,0,I4,0);
4549 rbstr = SysAllocString(szFalse);
4550 VAROR(UI4,0,BSTR,rbstr,I4,0);
4551 VAROR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
4552 SysFreeString(rbstr);
4553 rbstr = SysAllocString(szTrue);
4554 VAROR(UI4,0,BSTR,rbstr,I4,-1);
4555 VAROR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
4556 SysFreeString(rbstr);
4557 VARORCY(UI4,0xffffffff,10000,I4,-1);
4558 VARORCY(UI4,0xffffffff,0,I4,-1);
4559 VARORCY(UI4,0,0,I4,0);
4561 VAROR(R4,-1,R4,-1,I4,-1);
4562 VAROR(R4,-1,R4,0,I4,-1);
4563 VAROR(R4,0,R4,0,I4,0);
4564 VAROR(R4,-1,R8,-1,I4,-1);
4565 VAROR(R4,-1,R8,0,I4,-1);
4566 VAROR(R4,0,R8,0,I4,0);
4567 VAROR(R4,-1,DATE,-1,I4,-1);
4568 VAROR(R4,-1,DATE,0,I4,-1);
4569 VAROR(R4,0,DATE,0,I4,0);
4570 if (HAVE_OLEAUT32_I8)
4572 VAROR(R4,-1,I8,-1,I8,-1);
4573 VAROR(R4,-1,I8,0,I8,-1);
4574 VAROR(R4,0,I8,0,I8,0);
4575 VAROR(R4,-1,UI8,0,I4,-1);
4576 VAROR(R4,0,UI8,0,I4,0);
4578 VAROR(R4,-1,INT,-1,I4,-1);
4579 VAROR(R4,-1,INT,0,I4,-1);
4580 VAROR(R4,0,INT,0,I4,0);
4581 VAROR(R4,-1,UINT,0xffffffff,I4,-1);
4582 VAROR(R4,-1,UINT,0,I4,-1);
4583 VAROR(R4,0,UINT,0,I4,0);
4584 rbstr = SysAllocString(szFalse);
4585 VAROR(R4,0,BSTR,rbstr,I4,0);
4586 VAROR(R4,-1,BSTR,rbstr,I4,-1);
4587 SysFreeString(rbstr);
4588 rbstr = SysAllocString(szTrue);
4589 VAROR(R4,0,BSTR,rbstr,I4,-1);
4590 VAROR(R4,-1,BSTR,rbstr,I4,-1);
4591 SysFreeString(rbstr);
4592 VARORCY(R4,-1,10000,I4,-1);
4593 VARORCY(R4,-1,0,I4,-1);
4594 VARORCY(R4,0,0,I4,0);
4596 VAROR(R8,-1,R8,-1,I4,-1);
4597 VAROR(R8,-1,R8,0,I4,-1);
4598 VAROR(R8,0,R8,0,I4,0);
4599 VAROR(R8,-1,DATE,-1,I4,-1);
4600 VAROR(R8,-1,DATE,0,I4,-1);
4601 VAROR(R8,0,DATE,0,I4,0);
4602 if (HAVE_OLEAUT32_I8)
4604 VAROR(R8,-1,I8,-1,I8,-1);
4605 VAROR(R8,-1,I8,0,I8,-1);
4606 VAROR(R8,0,I8,0,I8,0);
4607 VAROR(R8,-1,UI8,0,I4,-1);
4608 VAROR(R8,0,UI8,0,I4,0);
4610 VAROR(R8,-1,INT,-1,I4,-1);
4611 VAROR(R8,-1,INT,0,I4,-1);
4612 VAROR(R8,0,INT,0,I4,0);
4613 VAROR(R8,-1,UINT,0xffffffff,I4,-1);
4614 VAROR(R8,-1,UINT,0,I4,-1);
4615 VAROR(R8,0,UINT,0,I4,0);
4616 rbstr = SysAllocString(szFalse);
4617 VAROR(R8,0,BSTR,rbstr,I4,0);
4618 VAROR(R8,-1,BSTR,rbstr,I4,-1);
4619 SysFreeString(rbstr);
4620 rbstr = SysAllocString(szTrue);
4621 VAROR(R8,0,BSTR,rbstr,I4,-1);
4622 VAROR(R8,-1,BSTR,rbstr,I4,-1);
4623 SysFreeString(rbstr);
4624 VARORCY(R8,-1,10000,I4,-1);
4625 VARORCY(R8,-1,0,I4,-1);
4626 VARORCY(R8,0,0,I4,0);
4628 VAROR(DATE,-1,DATE,-1,I4,-1);
4629 VAROR(DATE,-1,DATE,0,I4,-1);
4630 VAROR(DATE,0,DATE,0,I4,0);
4631 if (HAVE_OLEAUT32_I8)
4633 VAROR(DATE,-1,I8,-1,I8,-1);
4634 VAROR(DATE,-1,I8,0,I8,-1);
4635 VAROR(DATE,0,I8,0,I8,0);
4636 VAROR(DATE,-1,UI8,0,I4,-1);
4637 VAROR(DATE,0,UI8,0,I4,0);
4639 VAROR(DATE,-1,INT,-1,I4,-1);
4640 VAROR(DATE,-1,INT,0,I4,-1);
4641 VAROR(DATE,0,INT,0,I4,0);
4642 VAROR(DATE,-1,UINT,0xffffffff,I4,-1);
4643 VAROR(DATE,-1,UINT,0,I4,-1);
4644 VAROR(DATE,0,UINT,0,I4,0);
4645 rbstr = SysAllocString(szFalse);
4646 VAROR(DATE,0,BSTR,rbstr,I4,0);
4647 VAROR(DATE,-1,BSTR,rbstr,I4,-1);
4648 SysFreeString(rbstr);
4649 rbstr = SysAllocString(szTrue);
4650 VAROR(DATE,0,BSTR,rbstr,I4,-1);
4651 VAROR(DATE,-1,BSTR,rbstr,I4,-1);
4652 SysFreeString(rbstr);
4653 VARORCY(DATE,-1,10000,I4,-1);
4654 VARORCY(DATE,-1,0,I4,-1);
4655 VARORCY(DATE,0,0,I4,0);
4657 if (HAVE_OLEAUT32_I8)
4659 VAROR(I8,-1,I8,-1,I8,-1);
4660 VAROR(I8,-1,I8,0,I8,-1);
4661 VAROR(I8,0,I8,0,I8,0);
4662 VAROR(I8,-1,UI8,0,I8,-1);
4663 VAROR(I8,0,UI8,0,I8,0);
4664 /* These overflow under native and Wine
4665 VAROR(I8,-1,INT,-1,I4,-1);
4666 VAROR(I8,-1,INT,0,I4,-1);
4667 VAROR(I8,0,INT,0,I4,0); */
4668 VAROR(I8,-1,UINT,0xffffffff,I8,-1);
4669 VAROR(I8,-1,UINT,0,I8,-1);
4670 VAROR(I8,0,UINT,0,I8,0);
4671 rbstr = SysAllocString(szFalse);
4672 VAROR(I8,0,BSTR,rbstr,I8,0);
4673 VAROR(I8,-1,BSTR,rbstr,I8,-1);
4674 SysFreeString(rbstr);
4675 rbstr = SysAllocString(szTrue);
4676 VAROR(I8,0,BSTR,rbstr,I8,-1);
4677 VAROR(I8,-1,BSTR,rbstr,I8,-1);
4678 SysFreeString(rbstr);
4679 VARORCY(I8,-1,10000,I8,-1);
4680 VARORCY(I8,-1,0,I8,-1);
4681 VARORCY(I8,0,0,I8,0);
4683 VAROR(UI8,0xffff,UI8,0xffff,I4,0xffff);
4684 VAROR(UI8,0xffff,UI8,0,I4,0xffff);
4685 VAROR(UI8,0,UI8,0,I4,0);
4686 VAROR(UI8,0xffff,INT,-1,I4,-1);
4687 VAROR(UI8,0xffff,INT,0,I4,0xffff);
4688 VAROR(UI8,0,INT,0,I4,0);
4689 VAROR(UI8,0xffff,UINT,0xffff,I4,0xffff);
4690 VAROR(UI8,0xffff,UINT,0,I4,0xffff);
4691 VAROR(UI8,0,UINT,0,I4,0);
4692 rbstr = SysAllocString(szFalse);
4693 VAROR(UI8,0,BSTR,rbstr,I4,0);
4694 VAROR(UI8,0xffff,BSTR,rbstr,I4,0xffff);
4695 SysFreeString(rbstr);
4696 rbstr = SysAllocString(szTrue);
4697 VAROR(UI8,0,BSTR,rbstr,I4,-1);
4698 VAROR(UI8,0xffff,BSTR,rbstr,I4,-1);
4699 SysFreeString(rbstr);
4700 VARORCY(UI8,0xffff,10000,I4,0xffff);
4701 VARORCY(UI8,0xffff,0,I4,0xffff);
4702 VARORCY(UI8,0,0,I4,0);
4705 VAROR(INT,-1,INT,-1,I4,-1);
4706 VAROR(INT,-1,INT,0,I4,-1);
4707 VAROR(INT,0,INT,0,I4,0);
4708 VAROR(INT,-1,UINT,0xffff,I4,-1);
4709 VAROR(INT,-1,UINT,0,I4,-1);
4710 VAROR(INT,0,UINT,0,I4,0);
4711 rbstr = SysAllocString(szFalse);
4712 VAROR(INT,0,BSTR,rbstr,I4,0);
4713 VAROR(INT,-1,BSTR,rbstr,I4,-1);
4714 SysFreeString(rbstr);
4715 rbstr = SysAllocString(szTrue);
4716 VAROR(INT,0,BSTR,rbstr,I4,-1);
4717 VAROR(INT,-1,BSTR,rbstr,I4,-1);
4718 SysFreeString(rbstr);
4719 VARORCY(INT,-1,10000,I4,-1);
4720 VARORCY(INT,-1,0,I4,-1);
4721 VARORCY(INT,0,0,I4,0);
4723 VAROR(UINT,0xffff,UINT,0xffff,I4,0xffff);
4724 VAROR(UINT,0xffff,UINT,0,I4,0xffff);
4725 VAROR(UINT,0,UINT,0,I4,0);
4726 rbstr = SysAllocString(szFalse);
4727 VAROR(UINT,0,BSTR,rbstr,I4,0);
4728 VAROR(UINT,0xffff,BSTR,rbstr,I4,0xffff);
4729 SysFreeString(rbstr);
4730 rbstr = SysAllocString(szTrue);
4731 VAROR(UINT,0,BSTR,rbstr,I4,-1);
4732 VAROR(UINT,0xffff,BSTR,rbstr,I4,-1);
4733 SysFreeString(rbstr);
4734 VARORCY(UINT,0xffff,10000,I4,0xffff);
4735 VARORCY(UINT,0xffff,0,I4,0xffff);
4736 VARORCY(UINT,0,0,I4,0);
4738 lbstr = SysAllocString(szFalse);
4739 rbstr = SysAllocString(szFalse);
4740 VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,0);
4741 SysFreeString(rbstr);
4742 rbstr = SysAllocString(szTrue);
4743 VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
4744 SysFreeString(lbstr);
4745 lbstr = SysAllocString(szTrue);
4746 VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
4747 VARORCY(BSTR,lbstr,10000,I4,-1);
4748 SysFreeString(lbstr);
4749 lbstr = SysAllocString(szFalse);
4750 VARORCY(BSTR,lbstr,10000,I4,1);
4751 SysFreeString(lbstr);
4752 SysFreeString(rbstr);
4755 static HRESULT (WINAPI *pVarEqv)(LPVARIANT,LPVARIANT,LPVARIANT);
4757 #define VAREQV(vt1,val1,vt2,val2,rvt,rval) \
4758 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
4759 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
4760 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
4761 test_var_call2( __LINE__, pVarEqv, &left, &right, &exp )
4763 static void test_VarEqv(void)
4765 VARIANT left, right, exp, result;
4771 /* Test all possible flag/vt combinations & the resulting vt type */
4772 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
4774 VARTYPE leftvt, rightvt, resvt;
4776 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
4780 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
4786 if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
4787 leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
4788 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
4791 memset(&left, 0, sizeof(left));
4792 memset(&right, 0, sizeof(right));
4793 V_VT(&left) = leftvt | ExtraFlags[i];
4794 V_VT(&right) = rightvt | ExtraFlags[i];
4795 V_VT(&result) = VT_EMPTY;
4798 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
4799 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
4800 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
4801 leftvt == VT_CLSID || rightvt == VT_CLSID ||
4802 leftvt == VT_RECORD || rightvt == VT_RECORD ||
4803 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
4804 leftvt == VT_ERROR || rightvt == VT_ERROR)
4808 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
4810 if (leftvt == rightvt ||
4811 leftvt == VT_I2 || rightvt == VT_I2 ||
4812 leftvt == VT_UI1 || rightvt == VT_UI1 ||
4813 leftvt == VT_BOOL || rightvt == VT_BOOL)
4815 else if (leftvt == VT_NULL || rightvt == VT_NULL)
4817 else if (leftvt == VT_I8 || rightvt == VT_I8)
4820 else if (leftvt == VT_NULL || rightvt == VT_NULL)
4824 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
4826 if (leftvt == rightvt)
4828 else if (leftvt == rightvt ||
4829 leftvt == VT_I2 || rightvt == VT_I2 ||
4830 leftvt == VT_BOOL || rightvt == VT_BOOL)
4834 else if (leftvt == VT_I8 || rightvt == VT_I8)
4837 else if (leftvt == VT_I2 || rightvt == VT_I2)
4839 if (leftvt == rightvt ||
4840 leftvt == VT_BOOL || rightvt == VT_BOOL)
4842 else if (leftvt == VT_I8 || rightvt == VT_I8)
4845 else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
4849 else if (leftvt == VT_I8 || rightvt == VT_I8)
4851 if (leftvt == VT_INT || rightvt == VT_INT)
4856 hres = pVarEqv(&left, &right, &result);
4858 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
4859 "VarEqv: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
4860 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
4863 ok(hres == S_OK && V_VT(&result) == resvt,
4864 "VarEqv: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
4865 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
4871 /* Test returned values */
4872 VAREQV(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
4873 VAREQV(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
4874 VAREQV(BOOL,TRUE,BOOL,TRUE,BOOL,VARIANT_TRUE);
4875 VAREQV(BOOL,FALSE,BOOL,FALSE,BOOL,VARIANT_TRUE);
4876 VAREQV(BOOL,TRUE,BOOL,FALSE,BOOL,-2);
4877 VAREQV(BOOL,FALSE,BOOL,TRUE,BOOL,-2);
4878 VAREQV(BOOL,6,BOOL,7,BOOL,-2);
4879 VAREQV(BOOL,6,BOOL,6,BOOL,VARIANT_TRUE);
4880 VAREQV(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE,I2,VARIANT_TRUE);
4881 VAREQV(BOOL,VARIANT_TRUE,I2,VARIANT_FALSE,I2,VARIANT_FALSE);
4882 VAREQV(BOOL,6,I2,7,I2,-2);
4883 VAREQV(UI1,1,UI1,1,UI1,255);
4884 VAREQV(UI1,1,UI1,0,UI1,254);
4885 VAREQV(UI1,0,UI1,1,UI1,254);
4886 if (HAVE_OLEAUT32_I8)
4888 VAREQV(UI4,VARIANT_FALSE,I8,VARIANT_FALSE,I8,-1);
4889 VAREQV(UI4,5,I8,19,I8,-23);
4890 VAREQV(UI4,VARIANT_FALSE,UI8,VARIANT_FALSE,I4,-1);
4894 static HRESULT (WINAPI *pVarMul)(LPVARIANT,LPVARIANT,LPVARIANT);
4896 #define VARMUL(vt1,val1,vt2,val2,rvt,rval) \
4897 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
4898 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
4899 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
4900 test_var_call2( __LINE__, pVarMul, &left, &right, &exp )
4902 static void test_VarMul(void)
4904 VARIANT left, right, exp, result, cy, dec;
4912 lbstr = SysAllocString(sz12);
4913 rbstr = SysAllocString(sz12);
4915 /* Test all possible flag/vt combinations & the resulting vt type */
4916 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
4918 VARTYPE leftvt, rightvt, resvt;
4920 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
4925 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
4931 if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
4932 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
4935 memset(&left, 0, sizeof(left));
4936 memset(&right, 0, sizeof(right));
4937 V_VT(&left) = leftvt | ExtraFlags[i];
4938 if (leftvt == VT_BSTR)
4939 V_BSTR(&left) = lbstr;
4940 V_VT(&right) = rightvt | ExtraFlags[i];
4941 if (rightvt == VT_BSTR)
4942 V_BSTR(&right) = rbstr;
4943 V_VT(&result) = VT_EMPTY;
4946 /* Don't ask me why but native VarMul cannot handle:
4947 VT_I1, VT_UI2, VT_UI4, VT_INT, VT_UINT and VT_UI8.
4948 Tested with DCOM98, Win2k, WinXP */
4949 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
4950 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
4951 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
4952 leftvt == VT_CLSID || rightvt == VT_CLSID ||
4953 leftvt == VT_RECORD || rightvt == VT_RECORD ||
4954 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
4955 leftvt == VT_ERROR || rightvt == VT_ERROR ||
4956 leftvt == VT_I1 || rightvt == VT_I1 ||
4957 leftvt == VT_UI2 || rightvt == VT_UI2 ||
4958 leftvt == VT_UI4 || rightvt == VT_UI4 ||
4959 leftvt == VT_UI8 || rightvt == VT_UI8 ||
4960 leftvt == VT_INT || rightvt == VT_INT ||
4961 leftvt == VT_UINT || rightvt == VT_UINT) {
4965 if (leftvt == VT_NULL || rightvt == VT_NULL)
4967 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
4969 else if (leftvt == VT_R8 || rightvt == VT_R8 ||
4970 leftvt == VT_BSTR || rightvt == VT_BSTR ||
4971 leftvt == VT_DATE || rightvt == VT_DATE)
4973 else if (leftvt == VT_R4 || rightvt == VT_R4) {
4974 if (leftvt == VT_I4 || rightvt == VT_I4 ||
4975 leftvt == VT_I8 || rightvt == VT_I8 ||
4976 leftvt == VT_CY || rightvt == VT_CY)
4980 } else if (leftvt == VT_CY || rightvt == VT_CY)
4982 else if (leftvt == VT_I8 || rightvt == VT_I8)
4984 else if (leftvt == VT_I4 || rightvt == VT_I4)
4986 else if (leftvt == VT_I2 || rightvt == VT_I2 ||
4987 leftvt == VT_BOOL || rightvt == VT_BOOL ||
4988 (leftvt == VT_EMPTY && rightvt == VT_EMPTY))
4990 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
4993 hres = pVarMul(&left, &right, &result);
4995 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
4996 "VarMul: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
4997 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
5000 ok(hres == S_OK && V_VT(&result) == resvt,
5001 "VarMul: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
5002 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
5009 /* Test returned values */
5010 VARMUL(I4,4,I4,2,I4,8);
5011 VARMUL(I2,4,I2,2,I2,8);
5012 VARMUL(I2,-13,I4,5,I4,-65);
5013 VARMUL(I4,-13,I4,5,I4,-65);
5014 VARMUL(I2,7,R4,0.5f,R4,3.5f);
5015 VARMUL(R4,0.5f,I4,5,R8,2.5);
5016 VARMUL(R8,7.1,BOOL,0,R8,0);
5017 VARMUL(BSTR,lbstr,I2,4,R8,48);
5018 VARMUL(BSTR,lbstr,BOOL,1,R8,12);
5019 VARMUL(BSTR,lbstr,R4,0.1f,R8,1.2);
5020 VARMUL(BSTR,lbstr,BSTR,rbstr,R8,144);
5021 VARMUL(R4,0.2f,BSTR,rbstr,R8,2.4);
5022 VARMUL(DATE,2.25,I4,7,R8,15.75);
5024 VARMUL(UI1, UI1_MAX, UI1, UI1_MAX, I4, UI1_MAX * UI1_MAX);
5025 VARMUL(I2, I2_MAX, I2, I2_MAX, I4, I2_MAX * I2_MAX);
5026 VARMUL(I2, I2_MAX, I2, I2_MIN, I4, I2_MAX * I2_MIN);
5027 VARMUL(I2, I2_MIN, I2, I2_MIN, I4, I2_MIN * I2_MIN);
5028 VARMUL(I4, I4_MAX, I4, I4_MAX, R8, (double)I4_MAX * I4_MAX);
5029 VARMUL(I4, I4_MAX, I4, I4_MIN, R8, (double)I4_MAX * I4_MIN);
5030 VARMUL(I4, I4_MIN, I4, I4_MIN, R8, (double)I4_MIN * I4_MIN);
5031 VARMUL(R4, R4_MAX, R4, R4_MAX, R8, (double)R4_MAX * R4_MAX);
5032 VARMUL(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX * R4_MIN);
5033 VARMUL(R4, R4_MIN, R4, R4_MIN, R4, R4_MIN * R4_MIN);
5034 VARMUL(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX * R8_MIN);
5035 VARMUL(R8, R8_MIN, R8, R8_MIN, R8, R8_MIN * R8_MIN);
5037 /* Manuly test some VT_CY and VT_DECIMAL variants */
5039 hres = VarCyFromI4(4711, &V_CY(&cy));
5040 ok(hres == S_OK, "VarCyFromI4 failed!\n");
5041 V_VT(&dec) = VT_DECIMAL;
5042 hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec));
5043 ok(hres == S_OK, "VarDecFromR4 failed!\n");
5044 memset(&left, 0, sizeof(left));
5045 memset(&right, 0, sizeof(right));
5046 V_VT(&left) = VT_I4;
5048 V_VT(&right) = VT_UI1;
5051 hres = VarMul(&cy, &right, &result);
5052 ok(hres == S_OK && V_VT(&result) == VT_CY, "VarMul: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result)));
5053 hres = VarR8FromCy(V_CY(&result), &r);
5054 ok(hres == S_OK && EQ_DOUBLE(r, 42399), "VarMul: CY value %f, expected %f\n", r, (double)42399);
5056 hres = VarMul(&left, &dec, &result);
5057 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL, "VarMul: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
5058 hres = VarR8FromDec(&V_DECIMAL(&result), &r);
5059 ok(hres == S_OK && EQ_DOUBLE(r, 46.2), "VarMul: DECIMAL value %f, expected %f\n", r, (double)46.2);
5061 SysFreeString(lbstr);
5062 SysFreeString(rbstr);
5065 static HRESULT (WINAPI *pVarAdd)(LPVARIANT,LPVARIANT,LPVARIANT);
5067 #define VARADD(vt1,val1,vt2,val2,rvt,rval) \
5068 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
5069 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
5070 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
5071 test_var_call2( __LINE__, pVarAdd, &left, &right, &exp )
5073 static void test_VarAdd(void)
5075 VARIANT left, right, exp, result, cy, dec;
5083 lbstr = SysAllocString(sz12);
5084 rbstr = SysAllocString(sz12);
5086 /* Test all possible flag/vt combinations & the resulting vt type */
5087 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
5089 VARTYPE leftvt, rightvt, resvt;
5091 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
5096 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
5102 if (leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
5105 memset(&left, 0, sizeof(left));
5106 memset(&right, 0, sizeof(right));
5107 V_VT(&left) = leftvt | ExtraFlags[i];
5108 if (leftvt == VT_BSTR)
5109 V_BSTR(&left) = lbstr;
5110 V_VT(&right) = rightvt | ExtraFlags[i];
5111 if (rightvt == VT_BSTR)
5112 V_BSTR(&right) = rbstr;
5113 V_VT(&result) = VT_EMPTY;
5116 /* Don't ask me why but native VarAdd cannot handle:
5117 VT_I1, VT_UI2, VT_UI4, VT_INT, VT_UINT and VT_UI8.
5118 Tested with DCOM98, Win2k, WinXP */
5119 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
5120 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
5121 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
5122 leftvt == VT_CLSID || rightvt == VT_CLSID ||
5123 leftvt == VT_RECORD || rightvt == VT_RECORD ||
5124 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
5125 leftvt == VT_ERROR || rightvt == VT_ERROR ||
5126 leftvt == VT_I1 || rightvt == VT_I1 ||
5127 leftvt == VT_UI2 || rightvt == VT_UI2 ||
5128 leftvt == VT_UI4 || rightvt == VT_UI4 ||
5129 leftvt == VT_UI8 || rightvt == VT_UI8 ||
5130 leftvt == VT_INT || rightvt == VT_INT ||
5131 leftvt == VT_UINT || rightvt == VT_UINT) {
5135 if (leftvt == VT_NULL || rightvt == VT_NULL)
5137 else if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH)
5139 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
5141 else if (leftvt == VT_DATE || rightvt == VT_DATE)
5143 else if (leftvt == VT_CY || rightvt == VT_CY)
5145 else if (leftvt == VT_R8 || rightvt == VT_R8)
5147 else if (leftvt == VT_BSTR || rightvt == VT_BSTR) {
5148 if ((leftvt == VT_BSTR && rightvt == VT_BSTR) ||
5149 leftvt == VT_EMPTY || rightvt == VT_EMPTY)
5153 } else if (leftvt == VT_R4 || rightvt == VT_R4) {
5154 if (leftvt == VT_I4 || rightvt == VT_I4 ||
5155 leftvt == VT_I8 || rightvt == VT_I8)
5160 else if (leftvt == VT_I8 || rightvt == VT_I8)
5162 else if (leftvt == VT_I4 || rightvt == VT_I4)
5164 else if (leftvt == VT_I2 || rightvt == VT_I2 ||
5165 leftvt == VT_BOOL || rightvt == VT_BOOL ||
5166 (leftvt == VT_EMPTY && rightvt == VT_EMPTY))
5168 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
5171 hres = pVarAdd(&left, &right, &result);
5173 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
5174 "VarAdd: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
5175 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
5178 ok(hres == S_OK && V_VT(&result) == resvt,
5179 "VarAdd: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
5180 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
5183 /* Note, we don't clear left/right deliberately here */
5184 VariantClear(&result);
5189 /* Test returned values */
5190 VARADD(I4,4,I4,2,I4,6);
5191 VARADD(I2,4,I2,2,I2,6);
5192 VARADD(I2,-13,I4,5,I4,-8);
5193 VARADD(I4,-13,I4,5,I4,-8);
5194 VARADD(I2,7,R4,0.5f,R4,7.5f);
5195 VARADD(R4,0.5f,I4,5,R8,5.5);
5196 VARADD(R8,7.1,BOOL,0,R8,7.1);
5197 VARADD(BSTR,lbstr,I2,4,R8,16);
5198 VARADD(BSTR,lbstr,BOOL,1,R8,13);
5199 VARADD(BSTR,lbstr,R4,0.1f,R8,12.1);
5200 VARADD(R4,0.2f,BSTR,rbstr,R8,12.2);
5201 VARADD(DATE,2.25,I4,7,DATE,9.25);
5202 VARADD(DATE,1.25,R4,-1.7f,DATE,-0.45);
5204 VARADD(UI1, UI1_MAX, UI1, UI1_MAX, I2, UI1_MAX + UI1_MAX);
5205 VARADD(I2, I2_MAX, I2, I2_MAX, I4, I2_MAX + I2_MAX);
5206 VARADD(I2, I2_MAX, I2, I2_MIN, I2, I2_MAX + I2_MIN);
5207 VARADD(I2, I2_MIN, I2, I2_MIN, I4, I2_MIN + I2_MIN);
5208 VARADD(I4, I4_MAX, I4, I4_MIN, I4, I4_MAX + I4_MIN);
5209 VARADD(I4, I4_MAX, I4, I4_MAX, R8, (double)I4_MAX + I4_MAX);
5210 VARADD(I4, I4_MIN, I4, I4_MIN, R8, (double)I4_MIN + I4_MIN);
5211 VARADD(R4, R4_MAX, R4, R4_MAX, R8, (double)R4_MAX + R4_MAX);
5212 VARADD(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX + R4_MIN);
5213 VARADD(R4, R4_MIN, R4, R4_MIN, R4, R4_MIN + R4_MIN);
5214 VARADD(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX + R8_MIN);
5215 VARADD(R8, R8_MIN, R8, R8_MIN, R8, R8_MIN + R8_MIN);
5217 /* Manually test BSTR + BSTR */
5218 V_VT(&left) = VT_BSTR;
5219 V_BSTR(&left) = lbstr;
5220 V_VT(&right) = VT_BSTR;
5221 V_BSTR(&right) = rbstr;
5222 hres = VarAdd(&left, &right, &result);
5223 ok(hres == S_OK && V_VT(&result) == VT_BSTR, "VarAdd: expected coerced type VT_BSTR, got %s!\n", vtstr(V_VT(&result)));
5224 hres = VarR8FromStr(V_BSTR(&result), 0, 0, &r);
5225 ok(hres == S_OK && EQ_DOUBLE(r, 1212), "VarAdd: BSTR value %f, expected %f\n", r, (double)1212);
5226 VariantClear(&result);
5228 /* Manuly test some VT_CY and VT_DECIMAL variants */
5230 hres = VarCyFromI4(4711, &V_CY(&cy));
5231 ok(hres == S_OK, "VarCyFromI4 failed!\n");
5232 V_VT(&dec) = VT_DECIMAL;
5233 hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec));
5234 ok(hres == S_OK, "VarDecFromR4 failed!\n");
5235 memset(&left, 0, sizeof(left));
5236 memset(&right, 0, sizeof(right));
5237 V_VT(&left) = VT_I4;
5239 V_VT(&right) = VT_UI1;
5242 hres = VarAdd(&cy, &right, &result);
5243 ok(hres == S_OK && V_VT(&result) == VT_CY, "VarAdd: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result)));
5244 hres = VarR8FromCy(V_CY(&result), &r);
5245 ok(hres == S_OK && EQ_DOUBLE(r, 4720), "VarAdd: CY value %f, expected %f\n", r, (double)4720);
5247 hres = VarAdd(&left, &dec, &result);
5248 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL, "VarAdd: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
5249 hres = VarR8FromDec(&V_DECIMAL(&result), &r);
5250 ok(hres == S_OK && EQ_DOUBLE(r, -15.2), "VarAdd: DECIMAL value %f, expected %f\n", r, (double)-15.2);
5251 VariantClear(&result);
5253 SysFreeString(lbstr);
5254 SysFreeString(rbstr);
5257 static void test_VarCat(void)
5260 VARIANT left, right, result, expected, expected_broken;
5261 static const WCHAR sz34[] = {'3','4','\0'};
5262 static const WCHAR sz1234[] = {'1','2','3','4','\0'};
5263 static const WCHAR date_sz12[] = {'9','/','3','0','/','1','9','8','0','1','2','\0'};
5264 static const WCHAR date_sz12_broken[] = {'9','/','3','0','/','8','0','1','2','\0'};
5265 static const WCHAR sz12_date[] = {'1','2','9','/','3','0','/','1','9','8','0','\0'};
5266 static const WCHAR sz12_date_broken[] = {'1','2','9','/','3','0','/','8','0','\0'};
5267 static const WCHAR sz_empty[] = {'\0'};
5268 TCHAR orig_date_format[128];
5269 VARTYPE leftvt, rightvt, resultvt;
5271 HRESULT expected_error_num;
5273 /* Set date format for testing */
5274 lcid = LOCALE_USER_DEFAULT;
5275 GetLocaleInfo(lcid,LOCALE_SSHORTDATE,orig_date_format,128);
5276 SetLocaleInfo(lcid,LOCALE_SSHORTDATE,"M/d/yyyy");
5279 VariantInit(&right);
5280 VariantInit(&result);
5281 VariantInit(&expected);
5283 /* Check expected types for all combinations */
5284 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
5289 /* Check if we need/have support for I8 and/or UI8 */
5290 if ((leftvt == VT_I8 || leftvt == VT_UI8) && !HAVE_OLEAUT32_I8)
5293 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
5297 expected_error_num = S_OK;
5298 resultvt = VT_EMPTY;
5300 if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
5301 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN ||
5302 leftvt == VT_RECORD || rightvt == VT_RECORD ||
5303 leftvt == 15 || rightvt == 15 /* Undefined type */)
5306 /* Check if we need/have support for I8 and/or UI8 */
5307 if ((rightvt == VT_I8 || rightvt == VT_UI8) && !HAVE_OLEAUT32_I8)
5310 if (leftvt == VT_NULL && rightvt == VT_NULL)
5312 else if (leftvt == VT_VARIANT && (rightvt == VT_ERROR ||
5313 rightvt == VT_DATE || rightvt == VT_DECIMAL))
5314 expected_error_num = DISP_E_TYPEMISMATCH;
5315 else if ((leftvt == VT_I2 || leftvt == VT_I4 ||
5316 leftvt == VT_R4 || leftvt == VT_R8 ||
5317 leftvt == VT_CY || leftvt == VT_BOOL ||
5318 leftvt == VT_BSTR || leftvt == VT_I1 ||
5319 leftvt == VT_UI1 || leftvt == VT_UI2 ||
5320 leftvt == VT_UI4 || leftvt == VT_I8 ||
5321 leftvt == VT_UI8 || leftvt == VT_INT ||
5322 leftvt == VT_UINT || leftvt == VT_EMPTY ||
5323 leftvt == VT_NULL || leftvt == VT_DECIMAL ||
5326 (rightvt == VT_I2 || rightvt == VT_I4 ||
5327 rightvt == VT_R4 || rightvt == VT_R8 ||
5328 rightvt == VT_CY || rightvt == VT_BOOL ||
5329 rightvt == VT_BSTR || rightvt == VT_I1 ||
5330 rightvt == VT_UI1 || rightvt == VT_UI2 ||
5331 rightvt == VT_UI4 || rightvt == VT_I8 ||
5332 rightvt == VT_UI8 || rightvt == VT_INT ||
5333 rightvt == VT_UINT || rightvt == VT_EMPTY ||
5334 rightvt == VT_NULL || rightvt == VT_DECIMAL ||
5335 rightvt == VT_DATE))
5337 else if (rightvt == VT_ERROR && leftvt < VT_VOID)
5338 expected_error_num = DISP_E_TYPEMISMATCH;
5339 else if (leftvt == VT_ERROR && (rightvt == VT_DATE ||
5340 rightvt == VT_ERROR || rightvt == VT_DECIMAL))
5341 expected_error_num = DISP_E_TYPEMISMATCH;
5342 else if (rightvt == VT_DATE || rightvt == VT_ERROR ||
5343 rightvt == VT_DECIMAL)
5344 expected_error_num = DISP_E_BADVARTYPE;
5345 else if (leftvt == VT_ERROR || rightvt == VT_ERROR)
5346 expected_error_num = DISP_E_TYPEMISMATCH;
5347 else if (leftvt == VT_VARIANT)
5348 expected_error_num = DISP_E_TYPEMISMATCH;
5349 else if (rightvt == VT_VARIANT && (leftvt == VT_EMPTY ||
5350 leftvt == VT_NULL || leftvt == VT_I2 ||
5351 leftvt == VT_I4 || leftvt == VT_R4 ||
5352 leftvt == VT_R8 || leftvt == VT_CY ||
5353 leftvt == VT_DATE || leftvt == VT_BSTR ||
5354 leftvt == VT_BOOL || leftvt == VT_DECIMAL ||
5355 leftvt == VT_I1 || leftvt == VT_UI1 ||
5356 leftvt == VT_UI2 || leftvt == VT_UI4 ||
5357 leftvt == VT_I8 || leftvt == VT_UI8 ||
5358 leftvt == VT_INT || leftvt == VT_UINT
5360 expected_error_num = DISP_E_TYPEMISMATCH;
5362 expected_error_num = DISP_E_BADVARTYPE;
5364 V_VT(&left) = leftvt;
5365 V_VT(&right) = rightvt;
5369 V_BSTR(&left) = SysAllocString(sz_empty); break;
5371 V_DATE(&left) = 0.0; break;
5373 VarDecFromR8(0.0, &V_DECIMAL(&left)); break;
5380 V_BSTR(&right) = SysAllocString(sz_empty); break;
5382 V_DATE(&right) = 0.0; break;
5384 VarDecFromR8(0.0, &V_DECIMAL(&right)); break;
5389 hres = VarCat(&left, &right, &result);
5391 /* Determine the error code for the vt combination */
5392 ok(hres == expected_error_num,
5393 "VarCat: %d, %d returned error, 0x%X expected 0x%X.\n",
5394 leftvt, rightvt, expected_error_num, hres);
5396 /* Check types are correct */
5397 ok(V_VT(&result) == resultvt,
5398 "VarCat: %d, %d: expected vt %d, got vt %d\n",
5399 leftvt, rightvt, resultvt, V_VT(&result));
5401 VariantClear(&left);
5402 VariantClear(&right);
5403 VariantClear(&result);
5407 /* Running single comparison tests to compare outputs */
5409 /* Test concat strings */
5410 V_VT(&left) = VT_BSTR;
5411 V_VT(&right) = VT_BSTR;
5412 V_VT(&expected) = VT_BSTR;
5413 V_BSTR(&left) = SysAllocString(sz12);
5414 V_BSTR(&right) = SysAllocString(sz34);
5415 V_BSTR(&expected) = SysAllocString(sz1234);
5416 hres = VarCat(&left,&right,&result);
5417 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5418 ok(VarCmp(&result,&expected,lcid,0) == VARCMP_EQ,
5419 "VarCat: VT_BSTR concat with VT_BSTR failed to return correct result\n");
5421 VariantClear(&left);
5422 VariantClear(&right);
5423 VariantClear(&result);
5425 /* Test if expression is VT_ERROR */
5426 V_VT(&left) = VT_ERROR;
5427 V_VT(&right) = VT_BSTR;
5428 V_BSTR(&right) = SysAllocString(sz1234);
5429 hres = VarCat(&left,&right,&result);
5430 ok(hres == DISP_E_TYPEMISMATCH, "VarCat should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hres);
5431 ok(V_VT(&result) == VT_EMPTY,
5432 "VarCat: VT_ERROR concat with VT_BSTR should have returned VT_EMPTY\n");
5434 VariantClear(&left);
5435 VariantClear(&right);
5436 VariantClear(&result);
5438 V_VT(&left) = VT_BSTR;
5439 V_VT(&right) = VT_ERROR;
5440 V_BSTR(&left) = SysAllocString(sz1234);
5441 hres = VarCat(&left,&right,&result);
5442 ok(hres == DISP_E_TYPEMISMATCH, "VarCat should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hres);
5443 ok(V_VT(&result) == VT_EMPTY,
5444 "VarCat: VT_BSTR concat with VT_ERROR should have returned VT_EMPTY\n");
5446 VariantClear(&left);
5447 VariantClear(&right);
5448 VariantClear(&result);
5449 VariantClear(&expected);
5451 /* Test combining boolean with number */
5452 V_VT(&left) = VT_INT;
5453 V_VT(&right) = VT_BOOL;
5454 V_VT(&expected) = VT_BSTR;
5456 V_BOOL(&right) = TRUE;
5457 V_BSTR(&expected) = SysAllocString(sz12_true);
5458 hres = VarCat(&left,&right,&result);
5459 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5460 hres = VarCmp(&result,&expected,lcid,0);
5461 ok(hres == VARCMP_EQ, "Expected VARCMP_EQ, got %08x for %s, %s\n",
5462 hres, variantstr(&result), variantstr(&expected));
5464 VariantClear(&left);
5465 VariantClear(&right);
5466 VariantClear(&result);
5467 VariantClear(&expected);
5469 V_VT(&left) = VT_INT;
5470 V_VT(&right) = VT_BOOL;
5471 V_VT(&expected) = VT_BSTR;
5473 V_BOOL(&right) = FALSE;
5474 V_BSTR(&expected) = SysAllocString(sz12_false);
5475 hres = VarCat(&left,&right,&result);
5476 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5477 hres = VarCmp(&result,&expected,lcid,0);
5478 ok(hres == VARCMP_EQ, "Expected VARCMP_EQ, got %08x for %s, %s\n",
5479 hres, variantstr(&result), variantstr(&expected));
5481 VariantClear(&left);
5482 VariantClear(&right);
5483 VariantClear(&result);
5484 VariantClear(&expected);
5486 /* Test when both expressions are numeric */
5487 V_VT(&left) = VT_INT;
5488 V_VT(&right) = VT_INT;
5489 V_VT(&expected) = VT_BSTR;
5492 V_BSTR(&expected) = SysAllocString(sz1234);
5493 hres = VarCat(&left,&right,&result);
5494 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5495 ok(VarCmp(&result,&expected,lcid,0) == VARCMP_EQ,
5496 "VarCat: NUMBER concat with NUMBER returned incorrect result\n");
5498 VariantClear(&left);
5499 VariantClear(&right);
5500 VariantClear(&result);
5502 /* Test if one expression is numeric and the other is a string */
5503 V_VT(&left) = VT_INT;
5504 V_VT(&right) = VT_BSTR;
5506 V_BSTR(&right) = SysAllocString(sz34);
5507 hres = VarCat(&left,&right,&result);
5508 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5509 ok(VarCmp(&result,&expected,lcid,0) == VARCMP_EQ,
5510 "VarCat: NUMBER concat with VT_BSTR, incorrect result\n");
5512 VariantClear(&left);
5513 VariantClear(&right);
5514 VariantClear(&result);
5516 V_VT(&left) = VT_BSTR;
5517 V_VT(&right) = VT_INT;
5518 V_BSTR(&left) = SysAllocString(sz12);
5520 hres = VarCat(&left,&right,&result);
5521 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5522 ok(VarCmp(&result,&expected,lcid,0) == VARCMP_EQ,
5523 "VarCat: VT_BSTR concat with NUMBER, incorrect result\n");
5525 VariantClear(&left);
5526 VariantClear(&right);
5527 VariantClear(&result);
5528 VariantClear(&expected);
5530 /* Test concat dates with strings */
5531 V_VT(&left) = VT_BSTR;
5532 V_VT(&right) = VT_DATE;
5533 V_VT(&expected) = VT_BSTR;
5534 V_VT(&expected_broken) = VT_BSTR;
5535 V_BSTR(&left) = SysAllocString(sz12);
5536 V_DATE(&right) = 29494.0;
5537 V_BSTR(&expected)= SysAllocString(sz12_date);
5538 V_BSTR(&expected_broken)= SysAllocString(sz12_date_broken);
5539 hres = VarCat(&left,&right,&result);
5540 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5541 ok(VarCmp(&result,&expected,lcid,0) == VARCMP_EQ ||
5542 broken(VarCmp(&result,&expected_broken,lcid,0) == VARCMP_EQ), /* Some W98 and NT4 (intermittent) */
5543 "VarCat: VT_BSTR concat with VT_DATE returned incorrect result\n");
5545 VariantClear(&left);
5546 VariantClear(&right);
5547 VariantClear(&result);
5548 VariantClear(&expected);
5549 VariantClear(&expected_broken);
5551 V_VT(&left) = VT_DATE;
5552 V_VT(&right) = VT_BSTR;
5553 V_VT(&expected) = VT_BSTR;
5554 V_VT(&expected_broken) = VT_BSTR;
5555 V_DATE(&left) = 29494.0;
5556 V_BSTR(&right) = SysAllocString(sz12);
5557 V_BSTR(&expected)= SysAllocString(date_sz12);
5558 V_BSTR(&expected_broken)= SysAllocString(date_sz12_broken);
5559 hres = VarCat(&left,&right,&result);
5560 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5561 ok(VarCmp(&result,&expected,lcid,0) == VARCMP_EQ ||
5562 broken(VarCmp(&result,&expected_broken,lcid,0) == VARCMP_EQ), /* Some W98 and NT4 (intermittent) */
5563 "VarCat: VT_DATE concat with VT_BSTR returned incorrect result\n");
5565 VariantClear(&left);
5566 VariantClear(&right);
5567 VariantClear(&result);
5568 VariantClear(&expected);
5569 VariantClear(&expected_broken);
5571 /* Test of both expressions are empty */
5572 V_VT(&left) = VT_BSTR;
5573 V_VT(&right) = VT_BSTR;
5574 V_VT(&expected) = VT_BSTR;
5575 V_BSTR(&left) = SysAllocString(sz_empty);
5576 V_BSTR(&right) = SysAllocString(sz_empty);
5577 V_BSTR(&expected)= SysAllocString(sz_empty);
5578 hres = VarCat(&left,&right,&result);
5579 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5580 ok(VarCmp(&result,&left,lcid,0) == VARCMP_EQ,
5581 "VarCat: EMPTY concat with EMPTY did not return empty VT_BSTR\n");
5583 /* Restore original date format settings */
5584 SetLocaleInfo(lcid,LOCALE_SSHORTDATE,orig_date_format);
5586 VariantClear(&left);
5587 VariantClear(&right);
5588 VariantClear(&result);
5589 VariantClear(&expected);
5592 static HRESULT (WINAPI *pVarAnd)(LPVARIANT,LPVARIANT,LPVARIANT);
5594 #define VARAND(vt1,val1,vt2,val2,rvt,rval) \
5595 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
5596 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
5597 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
5598 test_var_call2( __LINE__, pVarAnd, &left, &right, &exp )
5600 #define VARANDCY(vt1,val1,val2,rvt,rval) \
5601 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
5602 V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \
5603 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
5604 test_var_call2( __LINE__, pVarAnd, &left, &right, &exp )
5606 /* Skip any type that is not defined or produces an error for every case */
5607 #define SKIPTESTAND(a) \
5608 if (a == VT_ERROR || a == VT_VARIANT || \
5609 a == VT_DISPATCH || a == VT_UNKNOWN || \
5610 a > VT_UINT || a == 15 /*not defined*/) \
5613 static void test_VarAnd(void)
5615 static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
5616 static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
5617 VARIANT left, right, exp, result;
5618 BSTR false_str, true_str;
5622 true_str = SysAllocString(szTrue);
5623 false_str = SysAllocString(szFalse);
5627 /* Test all possible flag/vt combinations & the resulting vt type */
5628 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
5630 VARTYPE leftvt, rightvt, resvt;
5632 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
5634 SKIPTESTAND(leftvt);
5636 /* Check if we need/have support for I8 and/or UI8 */
5637 if ((leftvt == VT_I8 || leftvt == VT_UI8) && !HAVE_OLEAUT32_I8)
5640 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
5643 SKIPTESTAND(rightvt);
5645 /* Check if we need/have support for I8 and/or UI8 */
5646 if ((rightvt == VT_I8 || rightvt == VT_UI8) && !HAVE_OLEAUT32_I8)
5649 memset(&left, 0, sizeof(left));
5650 memset(&right, 0, sizeof(right));
5651 V_VT(&left) = leftvt | ExtraFlags[i];
5652 V_VT(&right) = rightvt | ExtraFlags[i];
5653 V_VT(&result) = VT_EMPTY;
5655 if ((leftvt | ExtraFlags[i]) == VT_BSTR)
5656 V_BSTR(&left) = true_str;
5657 if ((rightvt | ExtraFlags[i]) == VT_BSTR)
5658 V_BSTR(&right) = true_str;
5660 /* Native VarAnd always returns an error when using extra
5661 * flags or if the variant combination is I8 and INT.
5663 if ((leftvt == VT_I8 && rightvt == VT_INT) ||
5664 (leftvt == VT_INT && rightvt == VT_I8) ||
5668 /* Determine return type */
5669 else if (leftvt == VT_I8 || rightvt == VT_I8)
5671 else if (leftvt == VT_I4 || rightvt == VT_I4 ||
5672 leftvt == VT_UINT || rightvt == VT_UINT ||
5673 leftvt == VT_INT || rightvt == VT_INT ||
5674 leftvt == VT_UINT || rightvt == VT_UINT ||
5675 leftvt == VT_R4 || rightvt == VT_R4 ||
5676 leftvt == VT_R8 || rightvt == VT_R8 ||
5677 leftvt == VT_CY || rightvt == VT_CY ||
5678 leftvt == VT_DATE || rightvt == VT_DATE ||
5679 leftvt == VT_I1 || rightvt == VT_I1 ||
5680 leftvt == VT_UI2 || rightvt == VT_UI2 ||
5681 leftvt == VT_UI4 || rightvt == VT_UI4 ||
5682 leftvt == VT_UI8 || rightvt == VT_UI8 ||
5683 leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
5685 else if (leftvt == VT_UI1 || rightvt == VT_UI1 ||
5686 leftvt == VT_I2 || rightvt == VT_I2 ||
5687 leftvt == VT_EMPTY || rightvt == VT_EMPTY)
5688 if ((leftvt == VT_NULL && rightvt == VT_UI1) ||
5689 (leftvt == VT_UI1 && rightvt == VT_NULL) ||
5690 (leftvt == VT_UI1 && rightvt == VT_UI1))
5694 else if (leftvt == VT_BOOL || rightvt == VT_BOOL ||
5695 (leftvt == VT_BSTR && rightvt == VT_BSTR))
5697 else if (leftvt == VT_NULL || rightvt == VT_NULL ||
5698 leftvt == VT_BSTR || rightvt == VT_BSTR)
5703 hres = pVarAnd(&left, &right, &result);
5705 /* Check expected HRESULT and if result variant type is correct */
5707 ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH,
5708 "VarAnd: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
5709 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
5710 vtstr(V_VT(&result)), hres);
5712 ok (hres == S_OK && resvt == V_VT(&result),
5713 "VarAnd: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
5714 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
5715 S_OK, vtstr(V_VT(&result)), hres);
5721 * Test returned values. Since we know the returned type is correct
5722 * and that we handle all combinations of invalid types, just check
5723 * that good type combinations produce the desired value.
5724 * FIXME: Test VT_DECIMAL
5726 VARAND(EMPTY,0,EMPTY,0,I2,0);
5727 VARAND(EMPTY,1,EMPTY,0,I2,0);
5728 VARAND(EMPTY,1,EMPTY,1,I2,0);
5729 VARAND(EMPTY,0,NULL,0,I2,0);
5730 VARAND(EMPTY,1,NULL,0,I2,0);
5731 VARAND(EMPTY,1,NULL,1,I2,0);
5732 VARAND(EMPTY,0,I1,0,I4,0);
5733 VARAND(EMPTY,0,I1,1,I4,0);
5734 VARAND(EMPTY,1,I1,1,I4,0);
5735 VARAND(EMPTY,0,UI1,0,I2,0);
5736 VARAND(EMPTY,0,UI1,1,I2,0);
5737 VARAND(EMPTY,1,UI1,1,I2,0);
5738 VARAND(EMPTY,0,I2,0,I2,0);
5739 VARAND(EMPTY,0,I2,1,I2,0);
5740 VARAND(EMPTY,1,I2,1,I2,0);
5741 VARAND(EMPTY,0,UI2,0,I4,0);
5742 VARAND(EMPTY,0,UI2,1,I4,0);
5743 VARAND(EMPTY,1,UI2,1,I4,0);
5744 VARAND(EMPTY,0,I4,0,I4,0);
5745 VARAND(EMPTY,0,I4,1,I4,0);
5746 VARAND(EMPTY,1,I4,1,I4,0);
5747 VARAND(EMPTY,0,UI4,0,I4,0);
5748 VARAND(EMPTY,0,UI4,1,I4,0);
5749 VARAND(EMPTY,1,UI4,1,I4,0);
5750 if (HAVE_OLEAUT32_I8)
5752 VARAND(EMPTY,0,I8,0,I8,0);
5753 VARAND(EMPTY,0,I8,1,I8,0);
5754 VARAND(EMPTY,1,I8,1,I8,0);
5755 VARAND(EMPTY,0,UI8,0,I4,0);
5756 VARAND(EMPTY,0,UI8,1,I4,0);
5757 VARAND(EMPTY,1,UI8,1,I4,0);
5759 VARAND(EMPTY,0,INT,0,I4,0);
5760 VARAND(EMPTY,0,INT,1,I4,0);
5761 VARAND(EMPTY,1,INT,1,I4,0);
5762 VARAND(EMPTY,0,UINT,0,I4,0);
5763 VARAND(EMPTY,0,UINT,1,I4,0);
5764 VARAND(EMPTY,1,UINT,1,I4,0);
5765 VARAND(EMPTY,0,BOOL,0,I2,0);
5766 VARAND(EMPTY,0,BOOL,1,I2,0);
5767 VARAND(EMPTY,1,BOOL,1,I2,0);
5768 VARAND(EMPTY,0,R4,0,I4,0);
5769 VARAND(EMPTY,0,R4,1,I4,0);
5770 VARAND(EMPTY,1,R4,1,I4,0);
5771 VARAND(EMPTY,0,R8,0,I4,0);
5772 VARAND(EMPTY,0,R8,1,I4,0);
5773 VARAND(EMPTY,1,R8,1,I4,0);
5774 VARAND(EMPTY,0,BSTR,false_str,I2,0);
5775 VARAND(EMPTY,0,BSTR,true_str,I2,0);
5776 VARANDCY(EMPTY,0,10000,I4,0);
5778 /* NULL OR 0 = NULL. NULL OR n = n */
5779 VARAND(NULL,0,NULL,0,NULL,0);
5780 VARAND(NULL,1,NULL,0,NULL,0);
5781 VARAND(NULL,0,I1,0,I4,0);
5782 VARAND(NULL,0,I1,1,NULL,0);
5783 VARAND(NULL,0,UI1,0,UI1,0);
5784 VARAND(NULL,0,UI1,1,NULL,0);
5785 VARAND(NULL,0,I2,0,I2,0);
5786 VARAND(NULL,0,I2,1,NULL,0);
5787 VARAND(NULL,0,UI2,0,I4,0);
5788 VARAND(NULL,0,UI2,1,NULL,0);
5789 VARAND(NULL,0,I4,0,I4,0);
5790 VARAND(NULL,0,I4,1,NULL,0);
5791 VARAND(NULL,0,UI4,0,I4,0);
5792 VARAND(NULL,0,UI4,1,NULL,0);
5793 if (HAVE_OLEAUT32_I8)
5795 VARAND(NULL,0,I8,0,I8,0);
5796 VARAND(NULL,0,I8,1,NULL,0);
5797 VARAND(NULL,0,UI8,0,I4,0);
5798 VARAND(NULL,0,UI8,1,NULL,0);
5800 VARAND(NULL,0,INT,0,I4,0);
5801 VARAND(NULL,0,INT,1,NULL,0);
5802 VARAND(NULL,0,UINT,0,I4,0);
5803 VARAND(NULL,0,UINT,1,NULL,0);
5804 VARAND(NULL,0,BOOL,0,BOOL,0);
5805 VARAND(NULL,0,BOOL,1,NULL,0);
5806 VARAND(NULL,0,R4,0,I4,0);
5807 VARAND(NULL,0,R4,1,NULL,0);
5808 VARAND(NULL,0,R8,0,I4,0);
5809 VARAND(NULL,0,R8,1,NULL,0);
5810 VARAND(NULL,0,BSTR,false_str,BOOL,0);
5811 VARAND(NULL,0,BSTR,true_str,NULL,VARIANT_FALSE);
5812 VARANDCY(NULL,0,10000,NULL,0);
5813 VARANDCY(NULL,0,0,I4,0);
5814 VARAND(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
5815 VARAND(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
5816 VARAND(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
5817 VARAND(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
5819 /* Assume x,y & y,x are the same from now on to reduce the number of tests */
5820 VARAND(BOOL,VARIANT_TRUE,I1,-1,I4,-1);
5821 VARAND(BOOL,VARIANT_TRUE,I1,0,I4,0);
5822 VARAND(BOOL,VARIANT_FALSE,I1,0,I4,0);
5823 VARAND(BOOL,VARIANT_TRUE,UI1,255,I2,255);
5824 VARAND(BOOL,VARIANT_TRUE,UI1,0,I2,0);
5825 VARAND(BOOL,VARIANT_FALSE,UI1,0,I2,0);
5826 VARAND(BOOL,VARIANT_TRUE,I2,-1,I2,-1);
5827 VARAND(BOOL,VARIANT_TRUE,I2,0,I2,0);
5828 VARAND(BOOL,VARIANT_FALSE,I2,0,I2,0);
5829 VARAND(BOOL,VARIANT_TRUE,UI2,65535,I4,65535);
5830 VARAND(BOOL,VARIANT_TRUE,UI2,0,I4,0);
5831 VARAND(BOOL,VARIANT_FALSE,UI2,0,I4,0);
5832 VARAND(BOOL,VARIANT_TRUE,I4,-1,I4,-1);
5833 VARAND(BOOL,VARIANT_TRUE,I4,0,I4,0);
5834 VARAND(BOOL,VARIANT_FALSE,I4,0,I4,0);
5835 VARAND(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,-1);
5836 VARAND(BOOL,VARIANT_TRUE,UI4,0,I4,0);
5837 VARAND(BOOL,VARIANT_FALSE,UI4,0,I4,0);
5838 VARAND(BOOL,VARIANT_TRUE,R4,-1,I4,-1);
5839 VARAND(BOOL,VARIANT_TRUE,R4,0,I4,0);
5840 VARAND(BOOL,VARIANT_FALSE,R4,0,I4,0);
5841 VARAND(BOOL,VARIANT_TRUE,R8,-1,I4,-1);
5842 VARAND(BOOL,VARIANT_TRUE,R8,0,I4,0);
5843 VARAND(BOOL,VARIANT_FALSE,R8,0,I4,0);
5844 VARAND(BOOL,VARIANT_TRUE,DATE,-1,I4,-1);
5845 VARAND(BOOL,VARIANT_TRUE,DATE,0,I4,0);
5846 VARAND(BOOL,VARIANT_FALSE,DATE,0,I4,0);
5847 if (HAVE_OLEAUT32_I8)
5849 VARAND(BOOL,VARIANT_TRUE,I8,-1,I8,-1);
5850 VARAND(BOOL,VARIANT_TRUE,I8,0,I8,0);
5851 VARAND(BOOL,VARIANT_FALSE,I8,0,I8,0);
5852 VARAND(BOOL,VARIANT_TRUE,UI8,0,I4,0);
5853 VARAND(BOOL,VARIANT_FALSE,UI8,0,I4,0);
5855 VARAND(BOOL,VARIANT_TRUE,INT,-1,I4,-1);
5856 VARAND(BOOL,VARIANT_TRUE,INT,0,I4,0);
5857 VARAND(BOOL,VARIANT_FALSE,INT,0,I4,0);
5858 VARAND(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,-1);
5859 VARAND(BOOL,VARIANT_TRUE,UINT,0,I4,0);
5860 VARAND(BOOL,VARIANT_FALSE,UINT,0,I4,0);
5861 VARAND(BOOL,VARIANT_FALSE,BSTR,false_str,BOOL,VARIANT_FALSE);
5862 VARAND(BOOL,VARIANT_TRUE,BSTR,false_str,BOOL,VARIANT_FALSE);
5863 VARAND(BOOL,VARIANT_FALSE,BSTR,true_str,BOOL,VARIANT_FALSE);
5864 VARAND(BOOL,VARIANT_TRUE,BSTR,true_str,BOOL,VARIANT_TRUE);
5865 VARANDCY(BOOL,VARIANT_TRUE,10000,I4,1);
5866 VARANDCY(BOOL,VARIANT_TRUE,0,I4,0);
5867 VARANDCY(BOOL,VARIANT_FALSE,0,I4,0);
5868 VARAND(I1,-1,I1,-1,I4,-1);
5869 VARAND(I1,-1,I1,0,I4,0);
5870 VARAND(I1,0,I1,0,I4,0);
5871 VARAND(I1,-1,UI1,255,I4,255);
5872 VARAND(I1,-1,UI1,0,I4,0);
5873 VARAND(I1,0,UI1,0,I4,0);
5874 VARAND(I1,-1,I2,-1,I4,-1);
5875 VARAND(I1,-1,I2,0,I4,0);
5876 VARAND(I1,0,I2,0,I4,0);
5877 VARAND(I1,-1,UI2,65535,I4,65535);
5878 VARAND(I1,-1,UI2,0,I4,0);
5879 VARAND(I1,0,UI2,0,I4,0);
5880 VARAND(I1,-1,I4,-1,I4,-1);
5881 VARAND(I1,-1,I4,0,I4,0);
5882 VARAND(I1,0,I4,0,I4,0);
5883 VARAND(I1,-1,UI4,0xffffffff,I4,-1);
5884 VARAND(I1,-1,UI4,0,I4,0);
5885 VARAND(I1,0,UI4,0,I4,0);
5886 VARAND(I1,-1,R4,-1,I4,-1);
5887 VARAND(I1,-1,R4,0,I4,0);
5888 VARAND(I1,0,R4,0,I4,0);
5889 VARAND(I1,-1,R8,-1,I4,-1);
5890 VARAND(I1,-1,R8,0,I4,0);
5891 VARAND(I1,0,R8,0,I4,0);
5892 VARAND(I1,-1,DATE,-1,I4,-1);
5893 VARAND(I1,-1,DATE,0,I4,0);
5894 VARAND(I1,0,DATE,0,I4,0);
5895 if (HAVE_OLEAUT32_I8)
5897 VARAND(I1,-1,I8,-1,I8,-1);
5898 VARAND(I1,-1,I8,0,I8,0);
5899 VARAND(I1,0,I8,0,I8,0);
5900 VARAND(I1,-1,UI8,0,I4,0);
5901 VARAND(I1,0,UI8,0,I4,0);
5903 VARAND(I1,-1,INT,-1,I4,-1);
5904 VARAND(I1,-1,INT,0,I4,0);
5905 VARAND(I1,0,INT,0,I4,0);
5906 VARAND(I1,-1,UINT,0xffffffff,I4,-1);
5907 VARAND(I1,-1,UINT,0,I4,0);
5908 VARAND(I1,0,UINT,0,I4,0);
5909 VARAND(I1,0,BSTR,false_str,I4,0);
5910 VARAND(I1,-1,BSTR,false_str,I4,0);
5911 VARAND(I1,0,BSTR,true_str,I4,0);
5912 VARAND(I1,-1,BSTR,true_str,I4,-1);
5913 VARANDCY(I1,-1,10000,I4,1);
5914 VARANDCY(I1,-1,0,I4,0);
5915 VARANDCY(I1,0,0,I4,0);
5917 VARAND(UI1,255,UI1,255,UI1,255);
5918 VARAND(UI1,255,UI1,0,UI1,0);
5919 VARAND(UI1,0,UI1,0,UI1,0);
5920 VARAND(UI1,255,I2,-1,I2,255);
5921 VARAND(UI1,255,I2,0,I2,0);
5922 VARAND(UI1,0,I2,0,I2,0);
5923 VARAND(UI1,255,UI2,65535,I4,255);
5924 VARAND(UI1,255,UI2,0,I4,0);
5925 VARAND(UI1,0,UI2,0,I4,0);
5926 VARAND(UI1,255,I4,-1,I4,255);
5927 VARAND(UI1,255,I4,0,I4,0);
5928 VARAND(UI1,0,I4,0,I4,0);
5929 VARAND(UI1,255,UI4,0xffffffff,I4,255);
5930 VARAND(UI1,255,UI4,0,I4,0);
5931 VARAND(UI1,0,UI4,0,I4,0);
5932 VARAND(UI1,255,R4,-1,I4,255);
5933 VARAND(UI1,255,R4,0,I4,0);
5934 VARAND(UI1,0,R4,0,I4,0);
5935 VARAND(UI1,255,R8,-1,I4,255);
5936 VARAND(UI1,255,R8,0,I4,0);
5937 VARAND(UI1,0,R8,0,I4,0);
5938 VARAND(UI1,255,DATE,-1,I4,255);
5939 VARAND(UI1,255,DATE,0,I4,0);
5940 VARAND(UI1,0,DATE,0,I4,0);
5941 if (HAVE_OLEAUT32_I8)
5943 VARAND(UI1,255,I8,-1,I8,255);
5944 VARAND(UI1,255,I8,0,I8,0);
5945 VARAND(UI1,0,I8,0,I8,0);
5946 VARAND(UI1,255,UI8,0,I4,0);
5947 VARAND(UI1,0,UI8,0,I4,0);
5949 VARAND(UI1,255,INT,-1,I4,255);
5950 VARAND(UI1,255,INT,0,I4,0);
5951 VARAND(UI1,0,INT,0,I4,0);
5952 VARAND(UI1,255,UINT,0xffffffff,I4,255);
5953 VARAND(UI1,255,UINT,0,I4,0);
5954 VARAND(UI1,0,UINT,0,I4,0);
5955 VARAND(UI1,0,BSTR,false_str,I2,0);
5956 VARAND(UI1,255,BSTR,false_str,I2,0);
5957 VARAND(UI1,0,BSTR,true_str,I2,0);
5958 VARAND(UI1,255,BSTR,true_str,I2,255);
5959 VARANDCY(UI1,255,10000,I4,1);
5960 VARANDCY(UI1,255,0,I4,0);
5961 VARANDCY(UI1,0,0,I4,0);
5963 VARAND(I2,-1,I2,-1,I2,-1);
5964 VARAND(I2,-1,I2,0,I2,0);
5965 VARAND(I2,0,I2,0,I2,0);
5966 VARAND(I2,-1,UI2,65535,I4,65535);
5967 VARAND(I2,-1,UI2,0,I4,0);
5968 VARAND(I2,0,UI2,0,I4,0);
5969 VARAND(I2,-1,I4,-1,I4,-1);
5970 VARAND(I2,-1,I4,0,I4,0);
5971 VARAND(I2,0,I4,0,I4,0);
5972 VARAND(I2,-1,UI4,0xffffffff,I4,-1);
5973 VARAND(I2,-1,UI4,0,I4,0);
5974 VARAND(I2,0,UI4,0,I4,0);
5975 VARAND(I2,-1,R4,-1,I4,-1);
5976 VARAND(I2,-1,R4,0,I4,0);
5977 VARAND(I2,0,R4,0,I4,0);
5978 VARAND(I2,-1,R8,-1,I4,-1);
5979 VARAND(I2,-1,R8,0,I4,0);
5980 VARAND(I2,0,R8,0,I4,0);
5981 VARAND(I2,-1,DATE,-1,I4,-1);
5982 VARAND(I2,-1,DATE,0,I4,0);
5983 VARAND(I2,0,DATE,0,I4,0);
5984 if (HAVE_OLEAUT32_I8)
5986 VARAND(I2,-1,I8,-1,I8,-1);
5987 VARAND(I2,-1,I8,0,I8,0);
5988 VARAND(I2,0,I8,0,I8,0);
5989 VARAND(I2,-1,UI8,0,I4,0);
5990 VARAND(I2,0,UI8,0,I4,0);
5992 VARAND(I2,-1,INT,-1,I4,-1);
5993 VARAND(I2,-1,INT,0,I4,0);
5994 VARAND(I2,0,INT,0,I4,0);
5995 VARAND(I2,-1,UINT,0xffffffff,I4,-1);
5996 VARAND(I2,-1,UINT,0,I4,0);
5997 VARAND(I2,0,UINT,0,I4,0);
5998 VARAND(I2,0,BSTR,false_str,I2,0);
5999 VARAND(I2,-1,BSTR,false_str,I2,0);
6000 VARAND(I2,0,BSTR,true_str,I2,0);
6001 VARAND(I2,-1,BSTR,true_str,I2,-1);
6002 VARANDCY(I2,-1,10000,I4,1);
6003 VARANDCY(I2,-1,0,I4,0);
6004 VARANDCY(I2,0,0,I4,0);
6006 VARAND(UI2,65535,UI2,65535,I4,65535);
6007 VARAND(UI2,65535,UI2,0,I4,0);
6008 VARAND(UI2,0,UI2,0,I4,0);
6009 VARAND(UI2,65535,I4,-1,I4,65535);
6010 VARAND(UI2,65535,I4,0,I4,0);
6011 VARAND(UI2,0,I4,0,I4,0);
6012 VARAND(UI2,65535,UI4,0xffffffff,I4,65535);
6013 VARAND(UI2,65535,UI4,0,I4,0);
6014 VARAND(UI2,0,UI4,0,I4,0);
6015 VARAND(UI2,65535,R4,-1,I4,65535);
6016 VARAND(UI2,65535,R4,0,I4,0);
6017 VARAND(UI2,0,R4,0,I4,0);
6018 VARAND(UI2,65535,R8,-1,I4,65535);
6019 VARAND(UI2,65535,R8,0,I4,0);
6020 VARAND(UI2,0,R8,0,I4,0);
6021 VARAND(UI2,65535,DATE,-1,I4,65535);
6022 VARAND(UI2,65535,DATE,0,I4,0);
6023 VARAND(UI2,0,DATE,0,I4,0);
6024 if (HAVE_OLEAUT32_I8)
6026 VARAND(UI2,65535,I8,-1,I8,65535);
6027 VARAND(UI2,65535,I8,0,I8,0);
6028 VARAND(UI2,0,I8,0,I8,0);
6029 VARAND(UI2,65535,UI8,0,I4,0);
6030 VARAND(UI2,0,UI8,0,I4,0);
6032 VARAND(UI2,65535,INT,-1,I4,65535);
6033 VARAND(UI2,65535,INT,0,I4,0);
6034 VARAND(UI2,0,INT,0,I4,0);
6035 VARAND(UI2,65535,UINT,0xffffffff,I4,65535);
6036 VARAND(UI2,65535,UINT,0,I4,0);
6037 VARAND(UI2,0,UINT,0,I4,0);
6038 VARAND(UI2,0,BSTR,false_str,I4,0);
6039 VARAND(UI2,65535,BSTR,false_str,I4,0);
6040 VARAND(UI2,0,BSTR,true_str,I4,0);
6041 VARAND(UI2,65535,BSTR,true_str,I4,65535);
6042 VARANDCY(UI2,65535,10000,I4,1);
6043 VARANDCY(UI2,65535,0,I4,0);
6044 VARANDCY(UI2,0,0,I4,0);
6046 VARAND(I4,-1,I4,-1,I4,-1);
6047 VARAND(I4,-1,I4,0,I4,0);
6048 VARAND(I4,0,I4,0,I4,0);
6049 VARAND(I4,-1,UI4,0xffffffff,I4,-1);
6050 VARAND(I4,-1,UI4,0,I4,0);
6051 VARAND(I4,0,UI4,0,I4,0);
6052 VARAND(I4,-1,R4,-1,I4,-1);
6053 VARAND(I4,-1,R4,0,I4,0);
6054 VARAND(I4,0,R4,0,I4,0);
6055 VARAND(I4,-1,R8,-1,I4,-1);
6056 VARAND(I4,-1,R8,0,I4,0);
6057 VARAND(I4,0,R8,0,I4,0);
6058 VARAND(I4,-1,DATE,-1,I4,-1);
6059 VARAND(I4,-1,DATE,0,I4,0);
6060 VARAND(I4,0,DATE,0,I4,0);
6061 if (HAVE_OLEAUT32_I8)
6063 VARAND(I4,-1,I8,-1,I8,-1);
6064 VARAND(I4,-1,I8,0,I8,0);
6065 VARAND(I4,0,I8,0,I8,0);
6066 VARAND(I4,-1,UI8,0,I4,0);
6067 VARAND(I4,0,UI8,0,I4,0);
6069 VARAND(I4,-1,INT,-1,I4,-1);
6070 VARAND(I4,-1,INT,0,I4,0);
6071 VARAND(I4,0,INT,0,I4,0);
6072 VARAND(I4,-1,UINT,0xffffffff,I4,-1);
6073 VARAND(I4,-1,UINT,0,I4,0);
6074 VARAND(I4,0,UINT,0,I4,0);
6075 VARAND(I4,0,BSTR,false_str,I4,0);
6076 VARAND(I4,-1,BSTR,false_str,I4,0);
6077 VARAND(I4,0,BSTR,true_str,I4,0);
6078 VARAND(I4,-1,BSTR,true_str,I4,-1);
6079 VARANDCY(I4,-1,10000,I4,1);
6080 VARANDCY(I4,-1,0,I4,0);
6081 VARANDCY(I4,0,0,I4,0);
6083 VARAND(UI4,0xffffffff,UI4,0xffffffff,I4,-1);
6084 VARAND(UI4,0xffffffff,UI4,0,I4,0);
6085 VARAND(UI4,0,UI4,0,I4,0);
6086 VARAND(UI4,0xffffffff,R4,-1,I4,-1);
6087 VARAND(UI4,0xffffffff,R4,0,I4,0);
6088 VARAND(UI4,0,R4,0,I4,0);
6089 VARAND(UI4,0xffffffff,R8,-1,I4,-1);
6090 VARAND(UI4,0xffffffff,R8,0,I4,0);
6091 VARAND(UI4,0,R8,0,I4,0);
6092 VARAND(UI4,0xffffffff,DATE,-1,I4,-1);
6093 VARAND(UI4,0xffffffff,DATE,0,I4,0);
6094 VARAND(UI4,0,DATE,0,I4,0);
6095 if (HAVE_OLEAUT32_I8)
6097 VARAND(UI4,0xffffffff,I8,0,I8,0);
6098 VARAND(UI4,0,I8,0,I8,0);
6099 VARAND(UI4,0xffffffff,UI8,0,I4,0);
6100 VARAND(UI4,0,UI8,0,I4,0);
6102 VARAND(UI4,0xffffffff,INT,-1,I4,-1);
6103 VARAND(UI4,0xffffffff,INT,0,I4,0);
6104 VARAND(UI4,0,INT,0,I4,0);
6105 VARAND(UI4,0xffffffff,UINT,0xffffffff,I4,-1);
6106 VARAND(UI4,0xffffffff,UINT,0,I4,0);
6107 VARAND(UI4,0,UINT,0,I4,0);
6108 VARAND(UI4,0,BSTR,false_str,I4,0);
6109 VARAND(UI4,0xffffffff,BSTR,false_str,I4,0);
6110 VARAND(UI4,0,BSTR,true_str,I4,0);
6111 VARAND(UI4,0xffffffff,BSTR,true_str,I4,-1);
6112 VARANDCY(UI4,0xffffffff,10000,I4,1);
6113 VARANDCY(UI4,0xffffffff,0,I4,0);
6114 VARANDCY(UI4,0,0,I4,0);
6116 VARAND(R4,-1,R4,-1,I4,-1);
6117 VARAND(R4,-1,R4,0,I4,0);
6118 VARAND(R4,0,R4,0,I4,0);
6119 VARAND(R4,-1,R8,-1,I4,-1);
6120 VARAND(R4,-1,R8,0,I4,0);
6121 VARAND(R4,0,R8,0,I4,0);
6122 VARAND(R4,-1,DATE,-1,I4,-1);
6123 VARAND(R4,-1,DATE,0,I4,0);
6124 VARAND(R4,0,DATE,0,I4,0);
6125 if (HAVE_OLEAUT32_I8)
6127 VARAND(R4,-1,I8,-1,I8,-1);
6128 VARAND(R4,-1,I8,0,I8,0);
6129 VARAND(R4,0,I8,0,I8,0);
6130 VARAND(R4,-1,UI8,0,I4,0);
6131 VARAND(R4,0,UI8,0,I4,0);
6133 VARAND(R4,-1,INT,-1,I4,-1);
6134 VARAND(R4,-1,INT,0,I4,0);
6135 VARAND(R4,0,INT,0,I4,0);
6136 VARAND(R4,-1,UINT,0xffffffff,I4,-1);
6137 VARAND(R4,-1,UINT,0,I4,0);
6138 VARAND(R4,0,UINT,0,I4,0);
6139 VARAND(R4,0,BSTR,false_str,I4,0);
6140 VARAND(R4,-1,BSTR,false_str,I4,0);
6141 VARAND(R4,0,BSTR,true_str,I4,0);
6142 VARAND(R4,-1,BSTR,true_str,I4,-1);
6143 VARANDCY(R4,-1,10000,I4,1);
6144 VARANDCY(R4,-1,0,I4,0);
6145 VARANDCY(R4,0,0,I4,0);
6147 VARAND(R8,-1,R8,-1,I4,-1);
6148 VARAND(R8,-1,R8,0,I4,0);
6149 VARAND(R8,0,R8,0,I4,0);
6150 VARAND(R8,-1,DATE,-1,I4,-1);
6151 VARAND(R8,-1,DATE,0,I4,0);
6152 VARAND(R8,0,DATE,0,I4,0);
6153 if (HAVE_OLEAUT32_I8)
6155 VARAND(R8,-1,I8,-1,I8,-1);
6156 VARAND(R8,-1,I8,0,I8,0);
6157 VARAND(R8,0,I8,0,I8,0);
6158 VARAND(R8,-1,UI8,0,I4,0);
6159 VARAND(R8,0,UI8,0,I4,0);
6161 VARAND(R8,-1,INT,-1,I4,-1);
6162 VARAND(R8,-1,INT,0,I4,0);
6163 VARAND(R8,0,INT,0,I4,0);
6164 VARAND(R8,-1,UINT,0xffffffff,I4,-1);
6165 VARAND(R8,-1,UINT,0,I4,0);
6166 VARAND(R8,0,UINT,0,I4,0);
6167 VARAND(R8,0,BSTR,false_str,I4,0);
6168 VARAND(R8,-1,BSTR,false_str,I4,0);
6169 VARAND(R8,0,BSTR,true_str,I4,0);
6170 VARAND(R8,-1,BSTR,true_str,I4,-1);
6171 VARANDCY(R8,-1,10000,I4,1);
6172 VARANDCY(R8,-1,0,I4,0);
6173 VARANDCY(R8,0,0,I4,0);
6175 VARAND(DATE,-1,DATE,-1,I4,-1);
6176 VARAND(DATE,-1,DATE,0,I4,0);
6177 VARAND(DATE,0,DATE,0,I4,0);
6178 if (HAVE_OLEAUT32_I8)
6180 VARAND(DATE,-1,I8,-1,I8,-1);
6181 VARAND(DATE,-1,I8,0,I8,0);
6182 VARAND(DATE,0,I8,0,I8,0);
6183 VARAND(DATE,-1,UI8,0,I4,0);
6184 VARAND(DATE,0,UI8,0,I4,0);
6186 VARAND(DATE,-1,INT,-1,I4,-1);
6187 VARAND(DATE,-1,INT,0,I4,0);
6188 VARAND(DATE,0,INT,0,I4,0);
6189 VARAND(DATE,-1,UINT,0xffffffff,I4,-1);
6190 VARAND(DATE,-1,UINT,0,I4,0);
6191 VARAND(DATE,0,UINT,0,I4,0);
6192 VARAND(DATE,0,BSTR,false_str,I4,0);
6193 VARAND(DATE,-1,BSTR,false_str,I4,0);
6194 VARAND(DATE,0,BSTR,true_str,I4,0);
6195 VARAND(DATE,-1,BSTR,true_str,I4,-1);
6196 VARANDCY(DATE,-1,10000,I4,1);
6197 VARANDCY(DATE,-1,0,I4,0);
6198 VARANDCY(DATE,0,0,I4,0);
6200 if (HAVE_OLEAUT32_I8)
6202 VARAND(I8,-1,I8,-1,I8,-1);
6203 VARAND(I8,-1,I8,0,I8,0);
6204 VARAND(I8,0,I8,0,I8,0);
6205 VARAND(I8,-1,UI8,0,I8,0);
6206 VARAND(I8,0,UI8,0,I8,0);
6207 VARAND(I8,-1,UINT,0,I8,0);
6208 VARAND(I8,0,UINT,0,I8,0);
6209 VARAND(I8,0,BSTR,false_str,I8,0);
6210 VARAND(I8,-1,BSTR,false_str,I8,0);
6211 VARAND(I8,0,BSTR,true_str,I8,0);
6212 VARAND(I8,-1,BSTR,true_str,I8,-1);
6213 VARANDCY(I8,-1,10000,I8,1);
6214 VARANDCY(I8,-1,0,I8,0);
6215 VARANDCY(I8,0,0,I8,0);
6217 VARAND(UI8,0xffff,UI8,0xffff,I4,0xffff);
6218 VARAND(UI8,0xffff,UI8,0,I4,0);
6219 VARAND(UI8,0,UI8,0,I4,0);
6220 VARAND(UI8,0xffff,INT,-1,I4,65535);
6221 VARAND(UI8,0xffff,INT,0,I4,0);
6222 VARAND(UI8,0,INT,0,I4,0);
6223 VARAND(UI8,0xffff,UINT,0xffff,I4,0xffff);
6224 VARAND(UI8,0xffff,UINT,0,I4,0);
6225 VARAND(UI8,0,UINT,0,I4,0);
6226 VARAND(UI8,0,BSTR,false_str,I4,0);
6227 VARAND(UI8,0xffff,BSTR,false_str,I4,0);
6228 VARAND(UI8,0,BSTR,true_str,I4,0);
6229 VARAND(UI8,0xffff,BSTR,true_str,I4,65535);
6230 VARANDCY(UI8,0xffff,10000,I4,1);
6231 VARANDCY(UI8,0xffff,0,I4,0);
6232 VARANDCY(UI8,0,0,I4,0);
6235 VARAND(INT,-1,INT,-1,I4,-1);
6236 VARAND(INT,-1,INT,0,I4,0);
6237 VARAND(INT,0,INT,0,I4,0);
6238 VARAND(INT,-1,UINT,0xffff,I4,65535);
6239 VARAND(INT,-1,UINT,0,I4,0);
6240 VARAND(INT,0,UINT,0,I4,0);
6241 VARAND(INT,0,BSTR,false_str,I4,0);
6242 VARAND(INT,-1,BSTR,false_str,I4,0);
6243 VARAND(INT,0,BSTR,true_str,I4,0);
6244 VARAND(INT,-1,BSTR,true_str,I4,-1);
6245 VARANDCY(INT,-1,10000,I4,1);
6246 VARANDCY(INT,-1,0,I4,0);
6247 VARANDCY(INT,0,0,I4,0);
6249 VARAND(UINT,0xffff,UINT,0xffff,I4,0xffff);
6250 VARAND(UINT,0xffff,UINT,0,I4,0);
6251 VARAND(UINT,0,UINT,0,I4,0);
6252 VARAND(UINT,0,BSTR,false_str,I4,0);
6253 VARAND(UINT,0xffff,BSTR, false_str,I4,0);
6254 VARAND(UINT,0,BSTR,true_str,I4,0);
6255 VARAND(UINT,0xffff,BSTR,true_str,I4,65535);
6256 VARANDCY(UINT,0xffff,10000,I4,1);
6257 VARANDCY(UINT,0xffff,0,I4,0);
6258 VARANDCY(UINT,0,0,I4,0);
6260 VARAND(BSTR,false_str,BSTR,false_str,BOOL,0);
6261 VARAND(BSTR,true_str,BSTR,false_str,BOOL,VARIANT_FALSE);
6262 VARAND(BSTR,true_str,BSTR,true_str,BOOL,VARIANT_TRUE);
6263 VARANDCY(BSTR,true_str,10000,I4,1);
6264 VARANDCY(BSTR,false_str,10000,I4,0);
6266 SysFreeString(true_str);
6267 SysFreeString(false_str);
6270 static HRESULT (WINAPI *pVarCmp)(LPVARIANT,LPVARIANT,LCID,ULONG);
6272 static void test_cmp( int line, LCID lcid, UINT flags, VARIANT *left, VARIANT *right, HRESULT result )
6276 hres = pVarCmp(left,right,lcid,flags);
6277 ok_(__FILE__,line)(hres == result, "VarCmp(%s,%s): expected 0x%x, got hres=0x%x\n",
6278 variantstr(left), variantstr(right), result, hres );
6280 static void test_cmpex( int line, LCID lcid, VARIANT *left, VARIANT *right,
6281 HRESULT res1, HRESULT res2, HRESULT res3, HRESULT res4 )
6283 test_cmp( line, lcid, 0, left, right, res1 );
6284 V_VT(left) |= VT_RESERVED;
6285 test_cmp( line, lcid, 0, left, right, res2 );
6286 V_VT(left) &= ~VT_RESERVED;
6287 V_VT(right) |= VT_RESERVED;
6288 test_cmp( line, lcid, 0, left, right, res3 );
6289 V_VT(left) |= VT_RESERVED;
6290 test_cmp( line, lcid, 0, left, right, res4 );
6291 ok_(__FILE__,line)(V_VT(left) & V_VT(right) & VT_RESERVED, "VT_RESERVED filtered out\n");
6294 /* ERROR from wingdi.h is interfering here */
6296 #define _VARCMP(vt1,val1,vtfl1,vt2,val2,vtfl2,lcid,flags,result) \
6297 V_##vt1(&left) = val1; V_VT(&left) = VT_##vt1 | vtfl1; \
6298 V_##vt2(&right) = val2; V_VT(&right) = VT_##vt2 | vtfl2; \
6299 test_cmp( __LINE__, lcid, flags, &left, &right, result )
6300 #define VARCMPEX(vt1,val1,vt2,val2,res1,res2,res3,res4) \
6301 V_##vt1(&left) = val1; V_VT(&left) = VT_##vt1; \
6302 V_##vt2(&right) = val2; V_VT(&right) = VT_##vt2; \
6303 test_cmpex( __LINE__, lcid, &left, &right, res1, res2, res3, res4 )
6304 #define VARCMP(vt1,val1,vt2,val2,result) \
6305 VARCMPEX(vt1,val1,vt2,val2,result,result,result,result)
6306 /* The above macros do not work for VT_NULL as NULL gets expanded first */
6307 #define V_NULL_ V_NULL
6308 #define VT_NULL_ VT_NULL
6310 static void test_VarCmp(void)
6312 VARIANT left, right;
6317 static const WCHAR szhuh[] = {'h','u','h','?','\0'};
6318 static const WCHAR sz2cents[] = {'2','c','e','n','t','s','\0'};
6319 static const WCHAR szempty[] = {'\0'};
6320 static const WCHAR sz0[] = {'0','\0'};
6321 static const WCHAR sz1[] = {'1','\0'};
6322 static const WCHAR sz7[] = {'7','\0'};
6323 static const WCHAR sz42[] = {'4','2','\0'};
6324 static const WCHAR sz1neg[] = {'-','1','\0'};
6325 static const WCHAR sz666neg[] = {'-','6','6','6','\0'};
6326 static const WCHAR sz1few[] = {'1','.','0','0','0','0','0','0','0','1','\0'};
6327 BSTR bstrhuh, bstrempty, bstr0, bstr1, bstr7, bstr42, bstr1neg, bstr666neg;
6328 BSTR bstr2cents, bstr1few;
6332 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
6333 bstrempty = SysAllocString(szempty);
6334 bstrhuh = SysAllocString(szhuh);
6335 bstr2cents = SysAllocString(sz2cents);
6336 bstr0 = SysAllocString(sz0);
6337 bstr1 = SysAllocString(sz1);
6338 bstr7 = SysAllocString(sz7);
6339 bstr42 = SysAllocString(sz42);
6340 bstr1neg = SysAllocString(sz1neg);
6341 bstr666neg = SysAllocString(sz666neg);
6342 bstr1few = SysAllocString(sz1few);
6344 /* Test all possible flag/vt combinations & the resulting vt type */
6345 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
6347 VARTYPE leftvt, rightvt;
6349 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
6354 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
6357 HRESULT expect = VARCMP_EQ;
6361 memset(&left, 0, sizeof(left));
6362 memset(&right, 0, sizeof(right));
6363 V_VT(&left) = leftvt | ExtraFlags[i];
6364 if (leftvt == VT_BSTR) {
6365 V_BSTR(&left) = bstr1neg;
6366 if (ExtraFlags[i] & VT_RESERVED)
6371 V_VT(&right) = rightvt | ExtraFlags[i];
6372 if (rightvt == VT_BSTR) {
6373 V_BSTR(&right) = bstr1neg;
6374 if (ExtraFlags[i] & VT_RESERVED)
6380 /* Don't ask me why but native VarCmp cannot handle:
6381 VT_I1, VT_UI2, VT_UI4, VT_UINT and VT_UI8.
6382 VT_INT is only supported as left variant. Go figure.
6383 Tested with DCOM98, Win2k, WinXP */
6384 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
6385 !IsValidVariantClearVT(leftvt, ExtraFlags[i] & ~VT_RESERVED) ||
6386 !IsValidVariantClearVT(rightvt, ExtraFlags[i] & ~VT_RESERVED) ||
6387 leftvt == VT_CLSID || rightvt == VT_CLSID ||
6388 leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
6389 leftvt == VT_ERROR || rightvt == VT_ERROR ||
6390 leftvt == VT_RECORD || rightvt == VT_RECORD ||
6391 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN ||
6392 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
6393 leftvt == VT_I1 || rightvt == VT_I1 ||
6394 leftvt == VT_UI2 || rightvt == VT_UI2 ||
6395 leftvt == VT_UI4 || rightvt == VT_UI4 ||
6396 leftvt == VT_UI8 || rightvt == VT_UI8 ||
6397 rightvt == VT_INT ||
6398 leftvt == VT_UINT || rightvt == VT_UINT) {
6402 if (leftvt == VT_ERROR && rightvt == VT_ERROR &&
6403 !(ExtraFlags[i] & ~VT_RESERVED)) {
6406 } else if (leftvt == VT_NULL || rightvt == VT_NULL)
6407 expect = VARCMP_NULL;
6408 else if (leftvt == VT_BSTR && rightvt == VT_BSTR)
6410 else if (leftvt == VT_BSTR && rightvt == VT_EMPTY)
6412 else if (leftvt == VT_EMPTY && rightvt == VT_BSTR)
6415 hres = pVarCmp(&left, &right, LOCALE_USER_DEFAULT, 0);
6417 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
6418 "VarCmp: %d|0x%X, %d|0x%X: Expected failure, got 0x%X\n",
6419 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres);
6422 "VarCmp: %d|0x%X, %d|0x%X: Expected 0x%X, got 0x%X\n",
6423 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], expect,
6430 /* VARCMP{,EX} run each 4 tests with a permutation of all possible
6431 input variants with (1) and without (0) VT_RESERVED set. The order
6432 of the permutations is (0,0); (1,0); (0,1); (1,1) */
6433 VARCMP(INT,4711,I2,4711,VARCMP_EQ);
6434 VARCMP(INT,4711,I2,-4711,VARCMP_GT);
6435 VARCMP(ERROR,0,ERROR,0,VARCMP_EQ);
6436 VARCMP(ERROR,0,UI1,0,DISP_E_TYPEMISMATCH);
6437 VARCMP(EMPTY,0,EMPTY,0,VARCMP_EQ);
6438 VARCMP(I4,1,R8,1.0,VARCMP_EQ);
6439 VARCMP(EMPTY,19,I2,0,VARCMP_EQ);
6440 ok(V_EMPTY(&left) == 19, "VT_EMPTY modified!\n");
6441 VARCMP(I4,1,UI1,1,VARCMP_EQ);
6442 VARCMP(I2,2,I2,2,VARCMP_EQ);
6443 VARCMP(I2,1,I2,2,VARCMP_LT);
6444 VARCMP(I2,2,I2,1,VARCMP_GT);
6445 VARCMP(I2,2,EMPTY,1,VARCMP_GT);
6446 VARCMP(I2,2,NULL_,1,VARCMP_NULL);
6448 /* BSTR handling, especially in conjunction with VT_RESERVED */
6449 VARCMP(BSTR,bstr0,NULL_,0,VARCMP_NULL);
6450 VARCMP(BSTR,bstr0,BSTR,bstr0,VARCMP_EQ);
6451 VARCMP(BSTR,bstrempty,BSTR,bstr0,VARCMP_LT);
6452 VARCMP(BSTR,bstr7,BSTR,bstr0,VARCMP_GT);
6453 VARCMP(BSTR,bstr7,BSTR,bstr1neg,VARCMP_GT);
6454 VARCMP(BSTR,bstr0,BSTR,NULL,VARCMP_GT);
6455 VARCMP(BSTR,NULL,BSTR,NULL,VARCMP_EQ);
6456 VARCMP(BSTR,bstrempty,BSTR,NULL,VARCMP_EQ);
6457 VARCMP(BSTR,NULL,EMPTY,0,VARCMP_EQ);
6458 VARCMP(EMPTY,0,BSTR,NULL,VARCMP_EQ);
6459 VARCMP(EMPTY,0,BSTR,bstrempty,VARCMP_EQ);
6460 VARCMP(EMPTY,1,BSTR,bstrempty,VARCMP_EQ);
6461 VARCMP(BSTR,bstr0,EMPTY,0,VARCMP_GT);
6462 VARCMP(BSTR,bstr42,EMPTY,0,VARCMP_GT);
6463 VARCMPEX(BSTR,bstrempty,UI1,0,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
6464 VARCMPEX(BSTR,bstrempty,I2,-1,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
6465 VARCMPEX(I4,0,BSTR,bstrempty,VARCMP_LT,VARCMP_LT,VARCMP_GT,VARCMP_LT);
6466 VARCMPEX(BSTR,NULL,UI1,0,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
6467 VARCMPEX(I4,7,BSTR,NULL,VARCMP_LT,VARCMP_LT,VARCMP_GT,VARCMP_LT);
6468 _VARCMP(BSTR,(BSTR)100,0,I2,100,0,lcid,0,VARCMP_GT);
6469 VARCMPEX(BSTR,bstr0,UI1,0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
6470 VARCMPEX(I2,0,BSTR,bstr0,VARCMP_LT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT);
6471 VARCMP(BSTR,bstrhuh,I4,I4_MAX,VARCMP_GT);
6472 VARCMP(BSTR,bstr2cents,I4,2,VARCMP_GT);
6473 VARCMPEX(BSTR,bstr2cents,I4,42,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
6474 VARCMP(BSTR,bstr2cents,I4,-1,VARCMP_GT);
6475 VARCMPEX(BSTR,bstr2cents,I4,-666,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
6476 VARCMPEX(BSTR,bstr0,I2,0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
6477 VARCMPEX(BSTR,bstr0,I4,0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
6478 VARCMPEX(BSTR,bstr0,I4,-666,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
6479 VARCMP(BSTR,bstr1,I4,0,VARCMP_GT);
6480 VARCMPEX(BSTR,bstr1,I4,1,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
6481 VARCMPEX(BSTR,bstr1,I4,I4_MAX,VARCMP_GT,VARCMP_LT,VARCMP_LT,VARCMP_GT);
6482 VARCMPEX(BSTR,bstr1,I4,-1,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
6483 VARCMP(BSTR,bstr7,I4,1,VARCMP_GT);
6484 VARCMPEX(BSTR,bstr7,I4,7,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
6485 VARCMPEX(BSTR,bstr7,I4,42,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_GT);
6486 VARCMPEX(BSTR,bstr42,I4,7,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
6487 VARCMPEX(BSTR,bstr42,I4,42,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
6488 VARCMPEX(BSTR,bstr42,I4,I4_MAX,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_GT);
6489 VARCMPEX(BSTR,bstr1neg,I4,1,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
6490 VARCMPEX(BSTR,bstr1neg,I4,42,VARCMP_GT,VARCMP_LT,VARCMP_LT,VARCMP_LT);
6491 VARCMPEX(BSTR,bstr1neg,I4,-1,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT);
6492 VARCMPEX(BSTR,bstr1neg,I4,-666,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_LT);
6493 VARCMPEX(BSTR,bstr666neg,I4,1,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
6494 VARCMPEX(BSTR,bstr666neg,I4,7,VARCMP_GT,VARCMP_LT,VARCMP_LT,VARCMP_LT);
6495 VARCMPEX(BSTR,bstr666neg,I4,42,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
6496 VARCMPEX(BSTR,bstr666neg,I4,I4_MAX,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
6497 VARCMPEX(BSTR,bstr666neg,I4,-1,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
6498 VARCMPEX(BSTR,bstr666neg,I4,-666,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT);
6499 VARCMPEX(BSTR,bstr7,R8,7.0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
6500 VARCMPEX(R8,3.141592,BSTR,NULL,VARCMP_LT,VARCMP_LT,VARCMP_GT,VARCMP_LT);
6501 VARCMP(BSTR,bstr7,BSTR,bstr7,VARCMP_EQ);
6502 VARCMP(BSTR,bstr7,BSTR,bstr42,VARCMP_GT);
6503 VARCMP(BSTR,bstr42,BSTR,bstr7,VARCMP_LT);
6505 /* DECIMAL handling */
6506 setdec(&dec,0,0,0,0);
6507 VARCMPEX(DECIMAL,dec,BSTR,bstr0,VARCMP_LT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT);
6508 setdec64(&dec,0,0,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF); /* max DECIMAL */
6509 VARCMP(DECIMAL,dec,R8,R8_MAX,VARCMP_LT); /* R8 has bigger range */
6510 VARCMP(DECIMAL,dec,DATE,R8_MAX,VARCMP_LT); /* DATE has bigger range */
6511 setdec64(&dec,0,0x80,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF);
6512 VARCMP(DECIMAL,dec,R8,-R8_MAX,VARCMP_GT);
6513 setdec64(&dec,20,0,0x5,0x6BC75E2D,0x63100001); /* 1+1e-20 */
6514 VARCMP(DECIMAL,dec,R8,1,VARCMP_GT); /* DECIMAL has higher precision */
6516 /* Show that DATE is handled just as a R8 */
6517 VARCMP(DATE,DATE_MAX,DATE,DATE_MAX+1,VARCMP_LT);
6518 VARCMP(DATE,DATE_MIN,DATE,DATE_MIN-1,VARCMP_GT);
6519 VARCMP(DATE,R8_MIN,R8,R8_MIN,VARCMP_EQ);
6520 VARCMP(DATE,1,DATE,1+1e-15,VARCMP_LT); /* 1e-15 == 8.64e-11 seconds */
6521 VARCMP(DATE,25570.0,DATE,25570.0,VARCMP_EQ);
6522 VARCMP(DATE,25570.0,DATE,25571.0,VARCMP_LT);
6523 VARCMP(DATE,25571.0,DATE,25570.0,VARCMP_GT);
6524 VARCMP(DATE,25570.0,EMPTY,0,VARCMP_GT);
6525 VARCMP(DATE,25570.0,NULL_,0,VARCMP_NULL);
6527 /* R4 precision handling */
6528 VARCMP(R4,1,R8,1+1e-8,VARCMP_EQ);
6529 VARCMP(R8,1+1e-8,R4,1,VARCMP_EQ);
6530 VARCMP(R8,1+1e-8,R8,1,VARCMP_GT);
6531 VARCMP(R8,R4_MAX*1.1,R4,R4_MAX,VARCMP_GT);
6532 VARCMP(R4,R4_MAX,R8,R8_MAX,VARCMP_LT);
6533 VARCMP(R4,1,DATE,1+1e-8,VARCMP_EQ);
6534 VARCMP(R4,1,BSTR,bstr1few,VARCMP_LT); /* bstr1few == 1+1e-8 */
6535 setdec(&dec,8,0,0,0x5F5E101); /* 1+1e-8 */
6536 VARCMP(R4,1,DECIMAL,dec,VARCMP_LT);
6538 SysFreeString(bstrhuh);
6539 SysFreeString(bstrempty);
6540 SysFreeString(bstr0);
6541 SysFreeString(bstr1);
6542 SysFreeString(bstr7);
6543 SysFreeString(bstr42);
6544 SysFreeString(bstr1neg);
6545 SysFreeString(bstr666neg);
6546 SysFreeString(bstr2cents);
6547 SysFreeString(bstr1few);
6550 static HRESULT (WINAPI *pVarPow)(LPVARIANT,LPVARIANT,LPVARIANT);
6552 #define VARPOW(vt1,val1,vt2,val2,rvt,rval) \
6553 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
6554 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
6555 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
6556 test_var_call2( __LINE__, pVarPow, &left, &right, &exp )
6558 /* Skip any type that is not defined or produces an error for every case */
6559 #define SKIPTESTPOW(a) \
6560 if (a == VT_ERROR || a == VT_VARIANT || \
6561 a == VT_DISPATCH || a == VT_UNKNOWN || \
6562 a == VT_RECORD || a > VT_UINT || \
6563 a == 15 /*not defined*/) \
6566 static void test_VarPow(void)
6568 static const WCHAR str2[] = { '2','\0' };
6569 static const WCHAR str3[] = { '3','\0' };
6570 VARIANT left, right, exp, result, cy, dec;
6571 BSTR num2_str, num3_str;
6577 num2_str = SysAllocString(str2);
6578 num3_str = SysAllocString(str3);
6580 /* Test all possible flag/vt combinations & the resulting vt type */
6581 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
6583 VARTYPE leftvt, rightvt, resvt;
6585 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
6587 SKIPTESTPOW(leftvt);
6589 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
6592 SKIPTESTPOW(rightvt);
6594 /* Native crashes with VT_BYREF */
6595 if (ExtraFlags[i] == VT_BYREF)
6598 memset(&left, 0, sizeof(left));
6599 memset(&right, 0, sizeof(right));
6600 V_VT(&left) = leftvt | ExtraFlags[i];
6601 V_VT(&right) = rightvt | ExtraFlags[i];
6602 V_VT(&result) = VT_EMPTY;
6605 if (leftvt == VT_BSTR)
6606 V_BSTR(&left) = num2_str;
6607 if (rightvt == VT_BSTR)
6608 V_BSTR(&right) = num2_str;
6610 /* Native VarPow always returns an error when using extra flags */
6611 if (ExtraFlags[i] != 0)
6614 /* Determine return type */
6615 else if ((leftvt == VT_NULL || rightvt == VT_NULL) &&
6616 ((leftvt != VT_I8 && leftvt != VT_UI8 &&
6617 rightvt != VT_I8 && rightvt != VT_UI8) || HAVE_OLEAUT32_I8))
6619 else if ((leftvt == VT_EMPTY || leftvt == VT_I2 ||
6620 leftvt == VT_I4 || leftvt == VT_R4 ||
6621 leftvt == VT_R8 || leftvt == VT_CY ||
6622 leftvt == VT_DATE || leftvt == VT_BSTR ||
6623 leftvt == VT_BOOL || leftvt == VT_DECIMAL ||
6624 (leftvt >= VT_I1 && leftvt <= VT_UI4) ||
6625 (HAVE_OLEAUT32_I8 && (leftvt == VT_I8 || leftvt == VT_UI8)) ||
6626 leftvt == VT_INT || leftvt == VT_UINT) &&
6627 (rightvt == VT_EMPTY || rightvt == VT_I2 ||
6628 rightvt == VT_I4 || rightvt == VT_R4 ||
6629 rightvt == VT_R8 || rightvt == VT_CY ||
6630 rightvt == VT_DATE || rightvt == VT_BSTR ||
6631 rightvt == VT_BOOL || rightvt == VT_DECIMAL ||
6632 (rightvt >= VT_I1 && rightvt <= VT_UI4) ||
6633 (HAVE_OLEAUT32_I8 && (rightvt == VT_I8 || rightvt == VT_UI8)) ||
6634 rightvt == VT_INT || rightvt == VT_UINT))
6639 hres = pVarPow(&left, &right, &result);
6641 /* Check expected HRESULT and if result variant type is correct */
6643 ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH,
6644 "VarPow: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
6645 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
6646 vtstr(V_VT(&result)), hres);
6648 ok (hres == S_OK && resvt == V_VT(&result),
6649 "VarPow: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
6650 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
6651 S_OK, vtstr(V_VT(&result)), hres);
6656 /* Check return values for valid variant type combinations */
6657 VARPOW(EMPTY,0,EMPTY,0,R8,1.0);
6658 VARPOW(EMPTY,0,NULL,0,NULL,0);
6659 VARPOW(EMPTY,0,I2,3,R8,0.0);
6660 VARPOW(EMPTY,0,I4,3,R8,0.0);
6661 VARPOW(EMPTY,0,R4,3.0f,R8,0.0);
6662 VARPOW(EMPTY,0,R8,3.0,R8,0.0);
6663 VARPOW(EMPTY,0,DATE,3,R8,0.0);
6664 VARPOW(EMPTY,0,BSTR,num3_str,R8,0.0);
6665 VARPOW(EMPTY,0,BOOL,VARIANT_FALSE,R8,1.0);
6666 VARPOW(EMPTY,0,I1,3,R8,0.0);
6667 VARPOW(EMPTY,0,UI1,3,R8,0.0);
6668 VARPOW(EMPTY,0,UI2,3,R8,0.0);
6669 VARPOW(EMPTY,0,UI4,3,R8,0.0);
6670 if (HAVE_OLEAUT32_I8)
6672 VARPOW(EMPTY,0,I8,3,R8,0.0);
6673 VARPOW(EMPTY,0,UI8,3,R8,0.0);
6675 VARPOW(EMPTY,0,INT,3,R8,0.0);
6676 VARPOW(EMPTY,0,UINT,3,R8,0.0);
6677 VARPOW(NULL,0,EMPTY,0,NULL,0);
6678 VARPOW(NULL,0,NULL,0,NULL,0);
6679 VARPOW(NULL,0,I2,3,NULL,0);
6680 VARPOW(NULL,0,I4,3,NULL,0);
6681 VARPOW(NULL,0,R4,3.0f,NULL,0);
6682 VARPOW(NULL,0,R8,3.0,NULL,0);
6683 VARPOW(NULL,0,DATE,3,NULL,0);
6684 VARPOW(NULL,0,BSTR,num3_str,NULL,0);
6685 VARPOW(NULL,0,BOOL,VARIANT_TRUE,NULL,0);
6686 VARPOW(NULL,0,I1,3,NULL,0);
6687 VARPOW(NULL,0,UI1,3,NULL,0);
6688 VARPOW(NULL,0,UI2,3,NULL,0);
6689 VARPOW(NULL,0,UI4,3,NULL,0);
6690 if (HAVE_OLEAUT32_I8)
6692 VARPOW(NULL,0,I8,3,NULL,0);
6693 VARPOW(NULL,0,UI8,3,NULL,0);
6695 VARPOW(NULL,0,INT,3,NULL,0);
6696 VARPOW(NULL,0,UINT,3,NULL,0);
6697 VARPOW(I2,2,EMPTY,0,R8,1.0);
6698 VARPOW(I2,2,NULL,0,NULL,0);
6699 VARPOW(I2,2,I2,3,R8,8.0);
6700 VARPOW(I2,2,I4,3,R8,8.0);
6701 VARPOW(I2,2,R4,3.0f,R8,8.0);
6702 VARPOW(I2,2,R8,3.0,R8,8.0);
6703 VARPOW(I2,2,DATE,3,R8,8.0);
6704 VARPOW(I2,2,BSTR,num3_str,R8,8.0);
6705 VARPOW(I2,2,BOOL,VARIANT_FALSE,R8,1.0);
6706 VARPOW(I2,2,I1,3,R8,8.0);
6707 VARPOW(I2,2,UI1,3,R8,8.0);
6708 VARPOW(I2,2,UI2,3,R8,8.0);
6709 VARPOW(I2,2,UI4,3,R8,8.0);
6710 if (HAVE_OLEAUT32_I8)
6712 VARPOW(I2,2,I8,3,R8,8.0);
6713 VARPOW(I2,2,UI8,3,R8,8.0);
6715 VARPOW(I2,2,INT,3,R8,8.0);
6716 VARPOW(I2,2,UINT,3,R8,8.0);
6717 VARPOW(I4,2,EMPTY,0,R8,1.0);
6718 VARPOW(I4,2,NULL,0,NULL,0);
6719 VARPOW(I4,2,I2,3,R8,8.0);
6720 VARPOW(I4,2,I4,3,R8,8.0);
6721 VARPOW(I4,2,R4,3.0f,R8,8.0);
6722 VARPOW(I4,2,R8,3.0,R8,8.0);
6723 VARPOW(I4,2,DATE,3,R8,8.0);
6724 VARPOW(I4,2,BSTR,num3_str,R8,8.0);
6725 VARPOW(I4,2,BOOL,VARIANT_FALSE,R8,1.0);
6726 VARPOW(I4,2,I1,3,R8,8.0);
6727 VARPOW(I4,2,UI1,3,R8,8.0);
6728 VARPOW(I4,2,UI2,3,R8,8.0);
6729 VARPOW(I4,2,UI4,3,R8,8.0);
6730 if (HAVE_OLEAUT32_I8)
6732 VARPOW(I4,2,I8,3,R8,8.0);
6733 VARPOW(I4,2,UI8,3,R8,8.0);
6735 VARPOW(I4,2,INT,3,R8,8.0);
6736 VARPOW(I4,2,UINT,3,R8,8.0);
6737 VARPOW(R4,2,EMPTY,0,R8,1.0);
6738 VARPOW(R4,2,NULL,0,NULL,0);
6739 VARPOW(R4,2,I2,3,R8,8.0);
6740 VARPOW(R4,2,I4,3,R8,8.0);
6741 VARPOW(R4,2,R4,3.0f,R8,8.0);
6742 VARPOW(R4,2,R8,3.0,R8,8.0);
6743 VARPOW(R4,2,DATE,3,R8,8.0);
6744 VARPOW(R4,2,BSTR,num3_str,R8,8.0);
6745 VARPOW(R4,2,BOOL,VARIANT_FALSE,R8,1.0);
6746 VARPOW(R4,2,I1,3,R8,8.0);
6747 VARPOW(R4,2,UI1,3,R8,8.0);
6748 VARPOW(R4,2,UI2,3,R8,8.0);
6749 VARPOW(R4,2,UI4,3,R8,8.0);
6750 if (HAVE_OLEAUT32_I8)
6752 VARPOW(R4,2,I8,3,R8,8.0);
6753 VARPOW(R4,2,UI8,3,R8,8.0);
6755 VARPOW(R4,2,INT,3,R8,8.0);
6756 VARPOW(R4,2,UINT,3,R8,8.0);
6757 VARPOW(R8,2,EMPTY,0,R8,1.0);
6758 VARPOW(R8,2,NULL,0,NULL,0);
6759 VARPOW(R8,2,I2,3,R8,8.0);
6760 VARPOW(R8,2,I4,3,R8,8.0);
6761 VARPOW(R8,2,R4,3.0f,R8,8.0);
6762 VARPOW(R8,2,R8,3.0,R8,8.0);
6763 VARPOW(R8,2,DATE,3,R8,8.0);
6764 VARPOW(R8,2,BSTR,num3_str,R8,8.0);
6765 VARPOW(R8,2,BOOL,VARIANT_FALSE,R8,1.0);
6766 VARPOW(R8,2,I1,3,R8,8.0);
6767 VARPOW(R8,2,UI1,3,R8,8.0);
6768 VARPOW(R8,2,UI2,3,R8,8.0);
6769 VARPOW(R8,2,UI4,3,R8,8.0);
6770 if (HAVE_OLEAUT32_I8)
6772 VARPOW(R8,2,I8,3,R8,8.0);
6773 VARPOW(R8,2,UI8,3,R8,8.0);
6775 VARPOW(R8,2,INT,3,R8,8.0);
6776 VARPOW(R8,2,UINT,3,R8,8.0);
6777 VARPOW(DATE,2,EMPTY,0,R8,1.0);
6778 VARPOW(DATE,2,NULL,0,NULL,0);
6779 VARPOW(DATE,2,I2,3,R8,8.0);
6780 VARPOW(DATE,2,I4,3,R8,8.0);
6781 VARPOW(DATE,2,R4,3.0f,R8,8.0);
6782 VARPOW(DATE,2,R8,3.0,R8,8.0);
6783 VARPOW(DATE,2,DATE,3,R8,8.0);
6784 VARPOW(DATE,2,BSTR,num3_str,R8,8.0);
6785 VARPOW(DATE,2,BOOL,VARIANT_FALSE,R8,1.0);
6786 VARPOW(DATE,2,I1,3,R8,8.0);
6787 VARPOW(DATE,2,UI1,3,R8,8.0);
6788 VARPOW(DATE,2,UI2,3,R8,8.0);
6789 VARPOW(DATE,2,UI4,3,R8,8.0);
6790 if (HAVE_OLEAUT32_I8)
6792 VARPOW(DATE,2,I8,3,R8,8.0);
6793 VARPOW(DATE,2,UI8,3,R8,8.0);
6795 VARPOW(DATE,2,INT,3,R8,8.0);
6796 VARPOW(DATE,2,UINT,3,R8,8.0);
6797 VARPOW(BSTR,num2_str,EMPTY,0,R8,1.0);
6798 VARPOW(BSTR,num2_str,NULL,0,NULL,0);
6799 VARPOW(BSTR,num2_str,I2,3,R8,8.0);
6800 VARPOW(BSTR,num2_str,I4,3,R8,8.0);
6801 VARPOW(BSTR,num2_str,R4,3.0f,R8,8.0);
6802 VARPOW(BSTR,num2_str,R8,3.0,R8,8.0);
6803 VARPOW(BSTR,num2_str,DATE,3,R8,8.0);
6804 VARPOW(BSTR,num2_str,BSTR,num3_str,R8,8.0);
6805 VARPOW(BSTR,num2_str,BOOL,VARIANT_FALSE,R8,1.0);
6806 VARPOW(BSTR,num2_str,I1,3,R8,8.0);
6807 VARPOW(BSTR,num2_str,UI1,3,R8,8.0);
6808 VARPOW(BSTR,num2_str,UI2,3,R8,8.0);
6809 VARPOW(BSTR,num2_str,UI4,3,R8,8.0);
6810 if (HAVE_OLEAUT32_I8)
6812 VARPOW(BSTR,num2_str,I8,3,R8,8.0);
6813 VARPOW(BSTR,num2_str,UI8,3,R8,8.0);
6815 VARPOW(BSTR,num2_str,INT,3,R8,8.0);
6816 VARPOW(BSTR,num2_str,UINT,3,R8,8.0);
6817 VARPOW(BOOL,VARIANT_TRUE,EMPTY,0,R8,1.0);
6818 VARPOW(BOOL,VARIANT_TRUE,NULL,0,NULL,0);
6819 VARPOW(BOOL,VARIANT_TRUE,I2,3,R8,-1.0);
6820 VARPOW(BOOL,VARIANT_TRUE,I4,3,R8,-1.0);
6821 VARPOW(BOOL,VARIANT_TRUE,R4,3.0f,R8,-1.0);
6822 VARPOW(BOOL,VARIANT_TRUE,R8,3.0,R8,-1.0);
6823 VARPOW(BOOL,VARIANT_TRUE,DATE,3,R8,-1.0);
6824 VARPOW(BOOL,VARIANT_TRUE,BSTR,num3_str,R8,-1.0);
6825 VARPOW(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,R8,-1.0);
6826 VARPOW(BOOL,VARIANT_TRUE,I1,3,R8,-1.0);
6827 VARPOW(BOOL,VARIANT_TRUE,UI1,3,R8,-1.0);
6828 VARPOW(BOOL,VARIANT_TRUE,UI2,3,R8,-1.0);
6829 VARPOW(BOOL,VARIANT_TRUE,UI4,3,R8,-1.0);
6830 if (HAVE_OLEAUT32_I8)
6832 VARPOW(BOOL,VARIANT_TRUE,I8,3,R8,-1.0);
6833 VARPOW(BOOL,VARIANT_TRUE,UI8,3,R8,-1.0);
6835 VARPOW(BOOL,VARIANT_TRUE,INT,3,R8,-1.0);
6836 VARPOW(BOOL,VARIANT_TRUE,UINT,3,R8,-1.0);
6837 VARPOW(I1,2,EMPTY,0,R8,1.0);
6838 VARPOW(I1,2,NULL,0,NULL,0);
6839 VARPOW(I1,2,I2,3,R8,8.0);
6840 VARPOW(I1,2,I4,3,R8,8.0);
6841 VARPOW(I1,2,R4,3.0f,R8,8.0);
6842 VARPOW(I1,2,R8,3.0,R8,8.0);
6843 VARPOW(I1,2,DATE,3,R8,8.0);
6844 VARPOW(I1,2,BSTR,num3_str,R8,8.0);
6845 VARPOW(I1,2,BOOL,VARIANT_FALSE,R8,1.0);
6846 VARPOW(I1,2,I1,3,R8,8.0);
6847 VARPOW(I1,2,UI1,3,R8,8.0);
6848 VARPOW(I1,2,UI2,3,R8,8.0);
6849 VARPOW(I1,2,UI4,3,R8,8.0);
6850 if (HAVE_OLEAUT32_I8)
6852 VARPOW(I1,2,I8,3,R8,8.0);
6853 VARPOW(I1,2,UI8,3,R8,8.0);
6855 VARPOW(I1,2,INT,3,R8,8.0);
6856 VARPOW(I1,2,UINT,3,R8,8.0);
6857 VARPOW(UI1,2,EMPTY,0,R8,1.0);
6858 VARPOW(UI1,2,NULL,0,NULL,0);
6859 VARPOW(UI1,2,I2,3,R8,8.0);
6860 VARPOW(UI1,2,I4,3,R8,8.0);
6861 VARPOW(UI1,2,R4,3.0f,R8,8.0);
6862 VARPOW(UI1,2,R8,3.0,R8,8.0);
6863 VARPOW(UI1,2,DATE,3,R8,8.0);
6864 VARPOW(UI1,2,BSTR,num3_str,R8,8.0);
6865 VARPOW(UI1,2,BOOL,VARIANT_FALSE,R8,1.0);
6866 VARPOW(UI1,2,I1,3,R8,8.0);
6867 VARPOW(UI1,2,UI1,3,R8,8.0);
6868 VARPOW(UI1,2,UI2,3,R8,8.0);
6869 VARPOW(UI1,2,UI4,3,R8,8.0);
6870 if (HAVE_OLEAUT32_I8)
6872 VARPOW(UI1,2,I8,3,R8,8.0);
6873 VARPOW(UI1,2,UI8,3,R8,8.0);
6875 VARPOW(UI1,2,INT,3,R8,8.0);
6876 VARPOW(UI1,2,UINT,3,R8,8.0);
6877 VARPOW(UI2,2,EMPTY,0,R8,1.0);
6878 VARPOW(UI2,2,NULL,0,NULL,0);
6879 VARPOW(UI2,2,I2,3,R8,8.0);
6880 VARPOW(UI2,2,I4,3,R8,8.0);
6881 VARPOW(UI2,2,R4,3.0f,R8,8.0);
6882 VARPOW(UI2,2,R8,3.0,R8,8.0);
6883 VARPOW(UI2,2,DATE,3,R8,8.0);
6884 VARPOW(UI2,2,BSTR,num3_str,R8,8.0);
6885 VARPOW(UI2,2,BOOL,VARIANT_FALSE,R8,1.0);
6886 VARPOW(UI2,2,I1,3,R8,8.0);
6887 VARPOW(UI2,2,UI1,3,R8,8.0);
6888 VARPOW(UI2,2,UI2,3,R8,8.0);
6889 VARPOW(UI2,2,UI4,3,R8,8.0);
6890 if (HAVE_OLEAUT32_I8)
6892 VARPOW(UI2,2,I8,3,R8,8.0);
6893 VARPOW(UI2,2,UI8,3,R8,8.0);
6895 VARPOW(UI2,2,INT,3,R8,8.0);
6896 VARPOW(UI2,2,UINT,3,R8,8.0);
6897 VARPOW(UI4,2,EMPTY,0,R8,1.0);
6898 VARPOW(UI4,2,NULL,0,NULL,0);
6899 VARPOW(UI4,2,I2,3,R8,8.0);
6900 VARPOW(UI4,2,I4,3,R8,8.0);
6901 VARPOW(UI4,2,R4,3.0f,R8,8.0);
6902 VARPOW(UI4,2,R8,3.0,R8,8.0);
6903 VARPOW(UI4,2,DATE,3,R8,8.0);
6904 VARPOW(UI4,2,BSTR,num3_str,R8,8.0);
6905 VARPOW(UI4,2,BOOL,VARIANT_FALSE,R8,1.0);
6906 VARPOW(UI4,2,I1,3,R8,8.0);
6907 VARPOW(UI4,2,UI1,3,R8,8.0);
6908 VARPOW(UI4,2,UI2,3,R8,8.0);
6909 VARPOW(UI4,2,UI4,3,R8,8.0);
6910 if (HAVE_OLEAUT32_I8)
6912 VARPOW(UI4,2,I8,3,R8,8.0);
6913 VARPOW(UI4,2,UI8,3,R8,8.0);
6915 VARPOW(UI4,2,INT,3,R8,8.0);
6916 VARPOW(UI4,2,UINT,3,R8,8.0);
6917 if (HAVE_OLEAUT32_I8)
6919 VARPOW(I8,2,EMPTY,0,R8,1.0);
6920 VARPOW(I8,2,NULL,0,NULL,0);
6921 VARPOW(I8,2,I2,3,R8,8.0);
6922 VARPOW(I8,2,I4,3,R8,8.0);
6923 VARPOW(I8,2,R4,3.0f,R8,8.0);
6924 VARPOW(I8,2,R8,3.0,R8,8.0);
6925 VARPOW(I8,2,DATE,3,R8,8.0);
6926 VARPOW(I8,2,BSTR,num3_str,R8,8.0);
6927 VARPOW(I8,2,BOOL,VARIANT_FALSE,R8,1.0);
6928 VARPOW(I8,2,I1,3,R8,8.0);
6929 VARPOW(I8,2,UI1,3,R8,8.0);
6930 VARPOW(I8,2,UI2,3,R8,8.0);
6931 VARPOW(I8,2,UI4,3,R8,8.0);
6932 VARPOW(I8,2,I8,3,R8,8.0);
6933 VARPOW(I8,2,UI8,3,R8,8.0);
6934 VARPOW(I8,2,INT,3,R8,8.0);
6935 VARPOW(I8,2,UINT,3,R8,8.0);
6936 VARPOW(UI8,2,EMPTY,0,R8,1.0);
6937 VARPOW(UI8,2,NULL,0,NULL,0);
6938 VARPOW(UI8,2,I2,3,R8,8.0);
6939 VARPOW(UI8,2,I4,3,R8,8.0);
6940 VARPOW(UI8,2,R4,3.0f,R8,8.0);
6941 VARPOW(UI8,2,R8,3.0,R8,8.0);
6942 VARPOW(UI8,2,DATE,3,R8,8.0);
6943 VARPOW(UI8,2,BSTR,num3_str,R8,8.0);
6944 VARPOW(UI8,2,I1,3,R8,8.0);
6945 VARPOW(UI8,2,UI1,3,R8,8.0);
6946 VARPOW(UI8,2,UI2,3,R8,8.0);
6947 VARPOW(UI8,2,UI4,3,R8,8.0);
6948 VARPOW(UI8,2,I8,3,R8,8.0);
6949 VARPOW(UI8,2,UI8,3,R8,8.0);
6950 VARPOW(UI8,2,INT,3,R8,8.0);
6951 VARPOW(UI8,2,UINT,3,R8,8.0);
6953 VARPOW(INT,2,EMPTY,0,R8,1.0);
6954 VARPOW(INT,2,NULL,0,NULL,0);
6955 VARPOW(INT,2,I2,3,R8,8.0);
6956 VARPOW(INT,2,I4,3,R8,8.0);
6957 VARPOW(INT,2,R4,3.0f,R8,8.0);
6958 VARPOW(INT,2,R8,3.0,R8,8.0);
6959 VARPOW(INT,2,DATE,3,R8,8.0);
6960 VARPOW(INT,2,BSTR,num3_str,R8,8.0);
6961 VARPOW(INT,2,BOOL,VARIANT_FALSE,R8,1.0);
6962 VARPOW(INT,2,I1,3,R8,8.0);
6963 VARPOW(INT,2,UI1,3,R8,8.0);
6964 VARPOW(INT,2,UI2,3,R8,8.0);
6965 VARPOW(INT,2,UI4,3,R8,8.0);
6966 if (HAVE_OLEAUT32_I8)
6968 VARPOW(INT,2,I8,3,R8,8.0);
6969 VARPOW(INT,2,UI8,3,R8,8.0);
6971 VARPOW(INT,2,INT,3,R8,8.0);
6972 VARPOW(INT,2,UINT,3,R8,8.0);
6973 VARPOW(UINT,2,EMPTY,0,R8,1.0);
6974 VARPOW(UINT,2,NULL,0,NULL,0);
6975 VARPOW(UINT,2,I2,3,R8,8.0);
6976 VARPOW(UINT,2,I4,3,R8,8.0);
6977 VARPOW(UINT,2,R4,3.0f,R8,8.0);
6978 VARPOW(UINT,2,R8,3.0,R8,8.0);
6979 VARPOW(UINT,2,DATE,3,R8,8.0);
6980 VARPOW(UINT,2,BSTR,num3_str,R8,8.0);
6981 VARPOW(UINT,2,BOOL,VARIANT_FALSE,R8,1.0);
6982 VARPOW(UINT,2,I1,3,R8,8.0);
6983 VARPOW(UINT,2,UI1,3,R8,8.0);
6984 VARPOW(UINT,2,UI2,3,R8,8.0);
6985 VARPOW(UINT,2,UI4,3,R8,8.0);
6986 if (HAVE_OLEAUT32_I8)
6988 VARPOW(UINT,2,I8,3,R8,8.0);
6989 VARPOW(UINT,2,UI8,3,R8,8.0);
6991 VARPOW(UINT,2,INT,3,R8,8.0);
6992 VARPOW(UINT,2,UINT,3,R8,8.0);
6994 /* Manually test some VT_CY, VT_DECIMAL variants */
6996 hres = VarCyFromI4(2, &V_CY(&cy));
6997 ok(hres == S_OK, "VarCyFromI4 failed!\n");
6998 V_VT(&dec) = VT_DECIMAL;
6999 hres = VarDecFromR8(2.0, &V_DECIMAL(&dec));
7000 ok(hres == S_OK, "VarDecFromR4 failed!\n");
7001 memset(&left, 0, sizeof(left));
7002 memset(&right, 0, sizeof(right));
7003 V_VT(&left) = VT_I4;
7005 V_VT(&right) = VT_I8;
7008 hres = pVarPow(&cy, &cy, &result);
7009 ok(hres == S_OK && V_VT(&result) == VT_R8,
7010 "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7011 S_OK, hres, vtstr(V_VT(&result)));
7012 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 4.0),
7013 "VARPOW: CY value %f, expected %f\n", V_R8(&result), 4.0);
7015 hres = pVarPow(&cy, &right, &result);
7018 ok(hres == S_OK && V_VT(&result) == VT_R8,
7019 "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7020 S_OK, hres, vtstr(V_VT(&result)));
7021 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 4.0),
7022 "VARPOW: CY value %f, expected %f\n", V_R8(&result), 4.0);
7026 ok(hres == DISP_E_BADVARTYPE && V_VT(&result) == VT_EMPTY,
7027 "VARPOW: expected coerced hres 0x%X type VT_EMPTY, got hres 0x%X type %s!\n",
7028 DISP_E_BADVARTYPE, hres, vtstr(V_VT(&result)));
7031 hres = pVarPow(&left, &cy, &result);
7032 ok(hres == S_OK && V_VT(&result) == VT_R8,
7033 "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7034 S_OK, hres, vtstr(V_VT(&result)));
7035 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 10000.0),
7036 "VARPOW: CY value %f, expected %f\n", V_R8(&result), 10000.0);
7038 hres = pVarPow(&left, &dec, &result);
7039 ok(hres == S_OK && V_VT(&result) == VT_R8,
7040 "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7041 S_OK, hres, vtstr(V_VT(&result)));
7042 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result),10000.0),
7043 "VARPOW: DECIMAL value %f, expected %f\n", V_R8(&result), 10000.0);
7045 hres = pVarPow(&dec, &dec, &result);
7046 ok(hres == S_OK && V_VT(&result) == VT_R8,
7047 "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7048 S_OK, hres, vtstr(V_VT(&result)));
7049 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 4.0),
7050 "VARPOW: DECIMAL value %f, expected %f\n", V_R8(&result), 4.0);
7052 hres = pVarPow(&dec, &right, &result);
7055 ok(hres == S_OK && V_VT(&result) == VT_R8,
7056 "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7057 S_OK, hres, vtstr(V_VT(&result)));
7058 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 4.0),
7059 "VARPOW: DECIMAL value %f, expected %f\n", V_R8(&result), 4.0);
7063 ok(hres == DISP_E_BADVARTYPE && V_VT(&result) == VT_EMPTY,
7064 "VARPOW: expected coerced hres 0x%X type VT_EMPTY, got hres 0x%X type %s!\n",
7065 DISP_E_BADVARTYPE, hres, vtstr(V_VT(&result)));
7068 SysFreeString(num2_str);
7069 SysFreeString(num3_str);
7072 static HRESULT (WINAPI *pVarDiv)(LPVARIANT,LPVARIANT,LPVARIANT);
7074 #define VARDIV(vt1,val1,vt2,val2,rvt,rval) \
7075 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
7076 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
7077 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
7078 test_var_call2( __LINE__, pVarDiv, &left, &right, &exp )
7080 /* Skip any type that is not defined or produces an error for every case */
7081 #define SKIPTESTDIV(a) \
7082 if (a == VT_ERROR || a == VT_VARIANT || \
7083 a == VT_DISPATCH || a == VT_UNKNOWN || \
7084 a == VT_RECORD || a > VT_UINT || \
7085 a == VT_I1 || a == VT_UI8 || \
7086 a == VT_INT || a == VT_UINT || \
7087 a == VT_UI2 || a == VT_UI4 || \
7088 a == 15 /*not defined*/) \
7091 static void test_VarDiv(void)
7093 static const WCHAR str1[] = { '1','\0' };
7094 static const WCHAR str2[] = { '2','\0' };
7095 VARIANT left, right, exp, result, cy, dec;
7096 BSTR num1_str, num2_str;
7098 HRESULT hres, expectedhres;
7101 num1_str = SysAllocString(str1);
7102 num2_str = SysAllocString(str2);
7106 /* Test all possible flag/vt combinations & the resulting vt type */
7107 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
7109 VARTYPE leftvt, rightvt, resvt;
7111 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
7113 SKIPTESTDIV(leftvt);
7115 /* Check if we need/have support for I8 */
7116 if (leftvt == VT_I8 && !HAVE_OLEAUT32_I8)
7119 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
7122 SKIPTESTDIV(rightvt);
7124 /* Check if we need/have support for I8 */
7125 if (rightvt == VT_I8 && !HAVE_OLEAUT32_I8)
7128 /* Native crashes with VT_BYREF */
7129 if (ExtraFlags[i] == VT_BYREF)
7132 memset(&left, 0, sizeof(left));
7133 memset(&right, 0, sizeof(right));
7134 V_VT(&left) = leftvt | ExtraFlags[i];
7135 V_VT(&right) = rightvt | ExtraFlags[i];
7136 V_VT(&result) = VT_EMPTY;
7138 expectedhres = S_OK;
7140 if (leftvt == VT_BSTR)
7141 V_BSTR(&left) = num2_str;
7142 else if (leftvt == VT_DECIMAL)
7144 VarDecFromR8(2.0, &V_DECIMAL(&left));
7145 V_VT(&left) = leftvt | ExtraFlags[i];
7148 /* Division by 0 is undefined */
7152 V_BSTR(&right) = num2_str;
7155 VarDecFromR8(2.0, &V_DECIMAL(&right));
7156 V_VT(&right) = rightvt | ExtraFlags[i];
7159 V_BOOL(&right) = VARIANT_TRUE;
7161 case VT_I2: V_I2(&right) = 2; break;
7162 case VT_I4: V_I4(&right) = 2; break;
7163 case VT_R4: V_R4(&right) = 2.0f; break;
7164 case VT_R8: V_R8(&right) = 2.0; break;
7165 case VT_CY: V_CY(&right).int64 = 2; break;
7166 case VT_DATE: V_DATE(&right) = 2; break;
7167 case VT_UI1: V_UI1(&right) = 2; break;
7168 case VT_I8: V_I8(&right) = 2; break;
7172 /* Determine return type */
7173 if (!(rightvt == VT_EMPTY))
7175 if (leftvt == VT_NULL || rightvt == VT_NULL)
7177 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
7179 else if (leftvt == VT_I8 || rightvt == VT_I8 ||
7180 leftvt == VT_CY || rightvt == VT_CY ||
7181 leftvt == VT_DATE || rightvt == VT_DATE ||
7182 leftvt == VT_I4 || rightvt == VT_I4 ||
7183 leftvt == VT_BSTR || rightvt == VT_BSTR ||
7184 leftvt == VT_I2 || rightvt == VT_I2 ||
7185 leftvt == VT_BOOL || rightvt == VT_BOOL ||
7186 leftvt == VT_R8 || rightvt == VT_R8 ||
7187 leftvt == VT_UI1 || rightvt == VT_UI1)
7189 if ((leftvt == VT_UI1 && rightvt == VT_R4) ||
7190 (leftvt == VT_R4 && rightvt == VT_UI1))
7192 else if ((leftvt == VT_R4 && (rightvt == VT_BOOL ||
7193 rightvt == VT_I2)) || (rightvt == VT_R4 &&
7194 (leftvt == VT_BOOL || leftvt == VT_I2)))
7199 else if (leftvt == VT_R4 || rightvt == VT_R4)
7202 else if (leftvt == VT_NULL && rightvt == VT_EMPTY)
7207 /* Native VarDiv always returns an error when using extra flags */
7208 if (ExtraFlags[i] != 0)
7211 hres = pVarDiv(&left, &right, &result);
7213 /* Check expected HRESULT and if result variant type is correct */
7215 ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH ||
7216 hres == DISP_E_OVERFLOW || hres == DISP_E_DIVBYZERO,
7217 "VarDiv: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
7218 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
7219 vtstr(V_VT(&result)), hres);
7221 ok (hres == S_OK && resvt == V_VT(&result),
7222 "VarDiv: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
7223 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
7224 S_OK, vtstr(V_VT(&result)), hres);
7229 /* Test return values for all the good cases */
7230 VARDIV(EMPTY,0,NULL,0,NULL,0);
7231 VARDIV(EMPTY,0,I2,2,R8,0.0);
7232 VARDIV(EMPTY,0,I4,2,R8,0.0);
7233 VARDIV(EMPTY,0,R4,2.0f,R4,0.0f);
7234 VARDIV(EMPTY,0,R8,2.0,R8,0.0);
7235 VARDIV(EMPTY,0,DATE,2.0,R8,0.0);
7236 VARDIV(EMPTY,0,BSTR,num2_str,R8,0.0);
7237 VARDIV(EMPTY,0,BOOL,VARIANT_TRUE,R8,0.0);
7238 VARDIV(EMPTY,0,UI1,2,R8,0.0);
7239 if (HAVE_OLEAUT32_I8)
7241 VARDIV(EMPTY,0,I8,2,R8,0.0);
7243 VARDIV(NULL,0,EMPTY,0,NULL,0);
7244 VARDIV(NULL,0,NULL,0,NULL,0);
7245 VARDIV(NULL,0,I2,2,NULL,0);
7246 VARDIV(NULL,0,I4,2,NULL,0);
7247 VARDIV(NULL,0,R4,2.0f,NULL,0);
7248 VARDIV(NULL,0,R8,2.0,NULL,0);
7249 VARDIV(NULL,0,DATE,2,NULL,0);
7250 VARDIV(NULL,0,BSTR,num2_str,NULL,0);
7251 VARDIV(NULL,0,BOOL,VARIANT_TRUE,NULL,0);
7252 VARDIV(NULL,0,UI1,2,NULL,0);
7253 if (HAVE_OLEAUT32_I8)
7255 VARDIV(NULL,0,I8,2,NULL,0);
7257 VARDIV(I2,2,NULL,0,NULL,0);
7258 VARDIV(I2,1,I2,2,R8,0.5);
7259 VARDIV(I2,1,I4,2,R8,0.5);
7260 VARDIV(I2,1,R4,2,R4,0.5f);
7261 VARDIV(I2,1,R8,2.0,R8,0.5);
7262 VARDIV(I2,1,DATE,2,R8,0.5);
7263 VARDIV(I2,1,BOOL,VARIANT_TRUE,R8,-1.0);
7264 VARDIV(I2,1,UI1,2,R8,0.5);
7265 if (HAVE_OLEAUT32_I8)
7267 VARDIV(I2,1,I8,2,R8,0.5);
7269 VARDIV(I4,1,NULL,0,NULL,0);
7270 VARDIV(I4,1,I2,2,R8,0.5);
7271 VARDIV(I4,1,I4,2,R8,0.5);
7272 VARDIV(I4,1,R4,2.0f,R8,0.5);
7273 VARDIV(I4,1,R8,2.0,R8,0.5);
7274 VARDIV(I4,1,DATE,2,R8,0.5);
7275 VARDIV(I4,1,BSTR,num2_str,R8,0.5);
7276 VARDIV(I4,1,BOOL,VARIANT_TRUE,R8,-1.0);
7277 VARDIV(I4,1,UI1,2,R8,0.5);
7278 if (HAVE_OLEAUT32_I8)
7280 VARDIV(I4,1,I8,2,R8,0.5);
7282 VARDIV(R4,1.0f,NULL,0,NULL,0);
7283 VARDIV(R4,1.0f,I2,2,R4,0.5f);
7284 VARDIV(R4,1.0f,I4,2,R8,0.5);
7285 VARDIV(R4,1.0f,R4,2.0f,R4,0.5f);
7286 VARDIV(R4,1.0f,R8,2.0,R8,0.5);
7287 VARDIV(R4,1.0f,DATE,2,R8,0.5);
7288 VARDIV(R4,1.0f,BSTR,num2_str,R8,0.5);
7289 VARDIV(R4,1.0f,BOOL,VARIANT_TRUE,R4,-1);
7290 VARDIV(R4,1.0f,UI1,2,R4,0.5f);
7291 if (HAVE_OLEAUT32_I8)
7293 VARDIV(R4,1.0f,I8,2,R8,0.5);
7295 VARDIV(R8,1.0,NULL,0,NULL,0);
7296 VARDIV(R8,1.0,I2,2,R8,0.5);
7297 VARDIV(R8,1.0,I4,2,R8,0.5);
7298 VARDIV(R8,1.0,R4,2.0f,R8,0.5);
7299 VARDIV(R8,1.0,R8,2.0,R8,0.5);
7300 VARDIV(R8,1.0,DATE,2,R8,0.5);
7301 VARDIV(R8,1.0,BSTR,num2_str,R8,0.5);
7302 VARDIV(R8,1.0,BOOL,VARIANT_TRUE,R8,-1.0);
7303 VARDIV(R8,1.0,UI1,2,R8,0.5);
7304 if (HAVE_OLEAUT32_I8)
7306 VARDIV(R8,1.0,I8,2,R8,0.5);
7308 VARDIV(DATE,1,NULL,0,NULL,0);
7309 VARDIV(DATE,1,I2,2,R8,0.5);
7310 VARDIV(DATE,1,I4,2,R8,0.5);
7311 VARDIV(DATE,1,R4,2.0f,R8,0.5);
7312 VARDIV(DATE,1,R8,2.0,R8,0.5);
7313 VARDIV(DATE,1,DATE,2,R8,0.5);
7314 VARDIV(DATE,1,BSTR,num2_str,R8,0.5);
7315 VARDIV(DATE,1,BOOL,VARIANT_TRUE,R8,-1.0);
7316 VARDIV(DATE,1,UI1,2,R8,0.5);
7317 if (HAVE_OLEAUT32_I8)
7319 VARDIV(DATE,1,I8,2,R8,0.5);
7321 VARDIV(BSTR,num1_str,NULL,0,NULL,0);
7322 VARDIV(BSTR,num1_str,I2,2,R8,0.5);
7323 VARDIV(BSTR,num1_str,I4,2,R8,0.5);
7324 VARDIV(BSTR,num1_str,R4,2.0f,R8,0.5);
7325 VARDIV(BSTR,num1_str,R8,2.0,R8,0.5);
7326 VARDIV(BSTR,num1_str,DATE,2,R8,0.5);
7327 VARDIV(BSTR,num1_str,BSTR,num2_str,R8,0.5);
7328 VARDIV(BSTR,num1_str,BOOL,VARIANT_TRUE,R8,-1);
7329 VARDIV(BSTR,num1_str,UI1,2,R8,0.5);
7330 if (HAVE_OLEAUT32_I8)
7332 VARDIV(BSTR,num1_str,I8,2,R8,0.5);
7334 VARDIV(BOOL,VARIANT_TRUE,NULL,0,NULL,0);
7335 VARDIV(BOOL,VARIANT_TRUE,I2,1,R8,-1.0);
7336 VARDIV(BOOL,VARIANT_FALSE,I2,1,R8,0.0);
7337 VARDIV(BOOL,VARIANT_TRUE,I4,1,R8,-1.0);
7338 VARDIV(BOOL,VARIANT_FALSE,I4,1,R8,0.0);
7339 VARDIV(BOOL,VARIANT_TRUE,R4,1,R4,-1.0f);
7340 VARDIV(BOOL,VARIANT_FALSE,R4,1,R4,0.0f);
7341 VARDIV(BOOL,VARIANT_TRUE,R8,1.0,R8,-1.0);
7342 VARDIV(BOOL,VARIANT_FALSE,R8,1.0,R8,0.0);
7343 VARDIV(BOOL,VARIANT_FALSE,DATE,2,R8,0.0);
7344 VARDIV(BOOL,VARIANT_FALSE,BSTR,num2_str,R8,0.0);
7345 VARDIV(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,R8,1.0);
7346 VARDIV(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,R8,0.0);
7347 VARDIV(BOOL,VARIANT_TRUE,UI1,1,R8,-1.0);
7348 if (HAVE_OLEAUT32_I8)
7350 VARDIV(BOOL,VARIANT_TRUE,I8,1,R8,-1.0);
7352 VARDIV(UI1,1,NULL,0,NULL,0);
7353 VARDIV(UI1,1,I2,2,R8,0.5);
7354 VARDIV(UI1,1,I4,2,R8,0.5);
7355 VARDIV(UI1,1,R4,2.0f,R4,0.5f);
7356 VARDIV(UI1,1,R8,2.0,R8,0.5);
7357 VARDIV(UI1,1,DATE,2,R8,0.5);
7358 VARDIV(UI1,1,BSTR,num2_str,R8,0.5);
7359 VARDIV(UI1,1,BOOL,VARIANT_TRUE,R8,-1);
7360 VARDIV(UI1,1,UI1,2,R8,0.5);
7361 if (HAVE_OLEAUT32_I8)
7363 VARDIV(UI1,1,I8,2,R8,0.5);
7364 VARDIV(I8,1,NULL,0,NULL,0);
7365 VARDIV(I8,1,I2,2,R8,0.5);
7366 VARDIV(I8,1,I4,2,R8,0.5);
7367 VARDIV(I8,1,R4,2.0f,R8,0.5);
7368 VARDIV(I8,1,R8,2.0,R8,0.5);
7369 VARDIV(I8,1,DATE,2,R8,0.5);
7370 VARDIV(I8,1,BSTR,num2_str,R8,0.5);
7371 VARDIV(I8,1,BOOL,VARIANT_TRUE,R8,-1);
7372 VARDIV(I8,1,UI1,2,R8,0.5);
7373 VARDIV(I8,1,I8,2,R8,0.5);
7376 /* Manually test some VT_CY, VT_DECIMAL variants */
7378 hres = VarCyFromI4(10000, &V_CY(&cy));
7379 ok(hres == S_OK, "VarCyFromI4 failed!\n");
7380 V_VT(&dec) = VT_DECIMAL;
7381 hres = VarDecFromR8(2.0, &V_DECIMAL(&dec));
7382 ok(hres == S_OK, "VarDecFromR4 failed!\n");
7383 memset(&left, 0, sizeof(left));
7384 memset(&right, 0, sizeof(right));
7385 V_VT(&left) = VT_I4;
7387 V_VT(&right) = VT_UI1;
7390 hres = pVarDiv(&cy, &cy, &result);
7391 ok(hres == S_OK && V_VT(&result) == VT_R8,
7392 "VARDIV: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
7393 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 1.0),
7394 "VARDIV: CY value %f, expected %f\n", V_R8(&result), (double)1.0);
7396 hres = pVarDiv(&cy, &right, &result);
7397 ok(hres == S_OK && V_VT(&result) == VT_R8,
7398 "VARDIV: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
7399 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 5000.0),
7400 "VARDIV: CY value %f, expected %f\n", V_R8(&result), (double)5000.0);
7402 hres = pVarDiv(&left, &cy, &result);
7403 ok(hres == S_OK && V_VT(&result) == VT_R8,
7404 "VARDIV: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
7405 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 0.01),
7406 "VARDIV: CY value %f, expected %f\n", V_R8(&result), (double)0.01);
7408 hres = pVarDiv(&left, &dec, &result);
7409 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
7410 "VARDIV: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
7411 hres = VarR8FromDec(&V_DECIMAL(&result), &r);
7412 ok(hres == S_OK && EQ_DOUBLE(r, 50.0),
7413 "VARDIV: DECIMAL value %f, expected %f\n", r, (double)50.0);
7415 hres = pVarDiv(&dec, &dec, &result);
7416 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
7417 "VARDIV: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
7418 hres = VarR8FromDec(&V_DECIMAL(&result), &r);
7419 ok(hres == S_OK && EQ_DOUBLE(r, 1.0),
7420 "VARDIV: DECIMAL value %f, expected %f\n", r, (double)1.0);
7422 hres = pVarDiv(&dec, &right, &result);
7423 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
7424 "VARDIV: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
7425 hres = VarR8FromDec(&V_DECIMAL(&result), &r);
7426 ok(hres == S_OK && EQ_DOUBLE(r, 1.0),
7427 "VARDIV: DECIMAL value %f, expected %f\n", r, (double)1.0);
7429 /* Check for division by zero and overflow */
7430 V_VT(&left) = VT_R8;
7432 V_VT(&right) = VT_R8;
7434 hres = pVarDiv(&left, &right, &result);
7435 ok(hres == DISP_E_DIVBYZERO && V_VT(&result) == VT_EMPTY,
7436 "VARDIV: Division by (1.0/0.0) should result in DISP_E_DIVBYZERO but got 0x%X\n", hres);
7438 V_VT(&left) = VT_R8;
7440 V_VT(&right) = VT_R8;
7442 hres = pVarDiv(&left, &right, &result);
7443 ok(hres == DISP_E_OVERFLOW && V_VT(&result) == VT_EMPTY,
7444 "VARDIV: Division by (0.0/0.0) should result in DISP_E_OVERFLOW but got 0x%X\n", hres);
7446 SysFreeString(num1_str);
7447 SysFreeString(num2_str);
7450 static HRESULT (WINAPI *pVarIdiv)(LPVARIANT,LPVARIANT,LPVARIANT);
7452 #define VARIDIV(vt1,val1,vt2,val2,rvt,rval) \
7453 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
7454 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
7455 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
7456 test_var_call2( __LINE__, pVarIdiv, &left, &right, &exp )
7458 /* Skip any type that is not defined or produces an error for every case */
7459 #define SKIPTESTIDIV(a) \
7460 if (a == VT_ERROR || a == VT_VARIANT || \
7461 a == VT_DISPATCH || a == VT_UNKNOWN || \
7462 a == VT_RECORD || a > VT_UINT || \
7463 a == 15 /*not defined*/) \
7466 static void test_VarIdiv(void)
7468 static const WCHAR str1[] = { '1','\0' };
7469 static const WCHAR str2[] = { '2','\0' };
7470 VARIANT left, right, exp, result, cy, dec;
7471 BSTR num1_str, num2_str;
7477 num1_str = SysAllocString(str1);
7478 num2_str = SysAllocString(str2);
7480 /* Test all possible flag/vt combinations & the resulting vt type */
7481 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
7483 VARTYPE leftvt, rightvt, resvt;
7485 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
7487 SKIPTESTIDIV(leftvt);
7489 /* Check if we need/have support for I8 and/or UI8 */
7490 if ((leftvt == VT_I8 || leftvt == VT_UI8) && !HAVE_OLEAUT32_I8)
7493 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
7496 SKIPTESTIDIV(rightvt);
7498 /* Native crashes with extra flag VT_BYREF */
7499 if (ExtraFlags[i] == VT_BYREF)
7502 /* Check if we need/have support for I8 and/or UI8 */
7503 if ((rightvt == VT_I8 || rightvt == VT_UI8) && !HAVE_OLEAUT32_I8)
7506 memset(&left, 0, sizeof(left));
7507 memset(&right, 0, sizeof(right));
7508 V_VT(&left) = leftvt | ExtraFlags[i];
7509 V_VT(&right) = rightvt | ExtraFlags[i];
7510 V_VT(&result) = VT_EMPTY;
7513 if (leftvt == VT_BSTR)
7514 V_BSTR(&left) = num2_str;
7515 else if (leftvt == VT_DECIMAL)
7517 VarDecFromR8(2.0, &V_DECIMAL(&left));
7518 V_VT(&left) = leftvt | ExtraFlags[i];
7521 /* Division by 0 is undefined */
7525 V_BSTR(&right) = num2_str;
7528 VarDecFromR8(2.0, &V_DECIMAL(&right));
7529 V_VT(&right) = rightvt | ExtraFlags[i];
7532 V_BOOL(&right) = VARIANT_TRUE;
7535 VarCyFromI4(10000, &V_CY(&right));
7536 V_VT(&right) = rightvt | ExtraFlags[i];
7538 case VT_I2: V_I2(&right) = 2; break;
7539 case VT_I4: V_I4(&right) = 2; break;
7540 case VT_R4: V_R4(&right) = 2.0f; break;
7541 case VT_R8: V_R8(&right) = 2.0; break;
7542 case VT_DATE: V_DATE(&right) = 2; break;
7543 case VT_I1: V_I1(&right) = 2; break;
7544 case VT_UI1: V_UI1(&right) = 2; break;
7545 case VT_UI2: V_UI2(&right) = 2; break;
7546 case VT_UI4: V_UI4(&right) = 2; break;
7547 case VT_I8: V_I8(&right) = 2; break;
7548 case VT_UI8: V_UI8(&right) = 2; break;
7549 case VT_INT: V_INT(&right) = 2; break;
7550 case VT_UINT: V_UINT(&right) = 2; break;
7554 /* Native VarIdiv always returns an error when using extra
7555 * flags or if the variant combination is I8 and INT.
7557 if ((leftvt == VT_I8 && rightvt == VT_INT) ||
7558 (leftvt == VT_INT && rightvt == VT_I8) ||
7559 (rightvt == VT_EMPTY && leftvt != VT_NULL) ||
7563 /* Determine variant type */
7564 else if (leftvt == VT_NULL || rightvt == VT_NULL)
7566 else if (leftvt == VT_I8 || rightvt == VT_I8)
7568 else if (leftvt == VT_I4 || rightvt == VT_I4 ||
7569 leftvt == VT_INT || rightvt == VT_INT ||
7570 leftvt == VT_UINT || rightvt == VT_UINT ||
7571 leftvt == VT_UI8 || rightvt == VT_UI8 ||
7572 leftvt == VT_UI4 || rightvt == VT_UI4 ||
7573 leftvt == VT_UI2 || rightvt == VT_UI2 ||
7574 leftvt == VT_I1 || rightvt == VT_I1 ||
7575 leftvt == VT_BSTR || rightvt == VT_BSTR ||
7576 leftvt == VT_DATE || rightvt == VT_DATE ||
7577 leftvt == VT_CY || rightvt == VT_CY ||
7578 leftvt == VT_DECIMAL || rightvt == VT_DECIMAL ||
7579 leftvt == VT_R8 || rightvt == VT_R8 ||
7580 leftvt == VT_R4 || rightvt == VT_R4)
7582 else if (leftvt == VT_I2 || rightvt == VT_I2 ||
7583 leftvt == VT_BOOL || rightvt == VT_BOOL ||
7586 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
7591 hres = pVarIdiv(&left, &right, &result);
7593 /* Check expected HRESULT and if result variant type is correct */
7595 ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH ||
7596 hres == DISP_E_DIVBYZERO,
7597 "VarIdiv: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
7598 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
7599 vtstr(V_VT(&result)), hres);
7601 ok (hres == S_OK && resvt == V_VT(&result),
7602 "VarIdiv: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
7603 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
7604 S_OK, vtstr(V_VT(&result)), hres);
7609 /* Test return values for all the good cases */
7610 VARIDIV(EMPTY,0,NULL,0,NULL,0);
7611 VARIDIV(EMPTY,0,I2,1,I2,0);
7612 VARIDIV(EMPTY,0,I4,1,I4,0);
7613 VARIDIV(EMPTY,0,R4,1.0f,I4,0);
7614 VARIDIV(EMPTY,0,R8,1.0,I4,0);
7615 VARIDIV(EMPTY,0,DATE,1.0,I4,0);
7616 VARIDIV(EMPTY,0,BSTR,num1_str,I4,0);
7617 VARIDIV(EMPTY,0,BOOL,VARIANT_TRUE,I2,0);
7618 VARIDIV(EMPTY,0,I1,1,I4,0);
7619 VARIDIV(EMPTY,0,UI1,1,I2,0);
7620 VARIDIV(EMPTY,0,UI2,1,I4,0);
7621 VARIDIV(EMPTY,0,UI4,1,I4,0);
7622 if (HAVE_OLEAUT32_I8)
7624 VARIDIV(EMPTY,0,I8,1,I8,0);
7625 VARIDIV(EMPTY,0,UI8,1,I4,0);
7627 VARIDIV(EMPTY,0,INT,1,I4,0);
7628 VARIDIV(EMPTY,0,UINT,1,I4,0);
7629 VARIDIV(NULL,0,EMPTY,0,NULL,0);
7630 VARIDIV(NULL,0,NULL,0,NULL,0);
7631 VARIDIV(NULL,0,I2,1,NULL,0);
7632 VARIDIV(NULL,0,I4,1,NULL,0);
7633 VARIDIV(NULL,0,R4,1,NULL,0);
7634 VARIDIV(NULL,0,R8,1,NULL,0);
7635 VARIDIV(NULL,0,DATE,1,NULL,0);
7636 VARIDIV(NULL,0,BSTR,num1_str,NULL,0);
7637 VARIDIV(NULL,0,BOOL,VARIANT_TRUE,NULL,0);
7638 VARIDIV(NULL,0,I1,1,NULL,0);
7639 VARIDIV(NULL,0,UI1,1,NULL,0);
7640 VARIDIV(NULL,0,UI2,1,NULL,0);
7641 VARIDIV(NULL,0,UI4,1,NULL,0);
7642 if (HAVE_OLEAUT32_I8)
7644 VARIDIV(NULL,0,I8,1,NULL,0);
7645 VARIDIV(NULL,0,UI8,1,NULL,0);
7647 VARIDIV(NULL,0,INT,1,NULL,0);
7648 VARIDIV(NULL,0,UINT,1,NULL,0);
7649 VARIDIV(I2,2,NULL,0,NULL,0);
7650 VARIDIV(I2,2,I2,1,I2,2);
7651 VARIDIV(I2,2,I4,1,I4,2);
7652 VARIDIV(I2,2,R4,1,I4,2);
7653 VARIDIV(I2,2,R8,1,I4,2);
7654 VARIDIV(I2,2,DATE,1,I4,2);
7655 VARIDIV(I2,2,BSTR,num1_str,I4,2);
7656 VARIDIV(I2,2,BOOL,VARIANT_TRUE,I2,-2);
7657 VARIDIV(I2,2,I1,1,I4,2);
7658 VARIDIV(I2,2,UI1,1,I2,2);
7659 VARIDIV(I2,2,UI2,1,I4,2);
7660 VARIDIV(I2,2,UI4,1,I4,2);
7661 if (HAVE_OLEAUT32_I8)
7663 VARIDIV(I2,2,I8,1,I8,2);
7664 VARIDIV(I2,2,UI8,1,I4,2);
7666 VARIDIV(I2,2,INT,1,I4,2);
7667 VARIDIV(I2,2,UINT,1,I4,2);
7668 VARIDIV(I4,2,NULL,0,NULL,0);
7669 VARIDIV(I4,2,I2,1,I4,2);
7670 VARIDIV(I4,2,I4,1,I4,2);
7671 VARIDIV(I4,2,R4,1,I4,2);
7672 VARIDIV(I4,2,R8,1,I4,2);
7673 VARIDIV(I4,2,DATE,1,I4,2);
7674 VARIDIV(I4,2,BSTR,num1_str,I4,2);
7675 VARIDIV(I4,2,BOOL,VARIANT_TRUE,I4,-2);
7676 VARIDIV(I4,2,I1,1,I4,2);
7677 VARIDIV(I4,2,UI1,1,I4,2);
7678 VARIDIV(I4,2,UI2,1,I4,2);
7679 VARIDIV(I4,2,UI4,1,I4,2);
7680 if (HAVE_OLEAUT32_I8)
7682 VARIDIV(I4,2,I8,1,I8,2);
7683 VARIDIV(I4,2,UI8,1,I4,2);
7685 VARIDIV(I4,2,INT,1,I4,2);
7686 VARIDIV(I4,2,UINT,1,I4,2);
7687 VARIDIV(R4,2.0f,NULL,0,NULL,0);
7688 VARIDIV(R4,2.0f,I2,1,I4,2);
7689 VARIDIV(R4,2.0f,I4,1,I4,2);
7690 VARIDIV(R4,2.0f,R4,1.0f,I4,2);
7691 VARIDIV(R4,2.0f,R8,1.0,I4,2);
7692 VARIDIV(R4,2.0f,DATE,1,I4,2);
7693 VARIDIV(R4,2.0f,BSTR,num1_str,I4,2);
7694 VARIDIV(R4,2.0f,BOOL,VARIANT_TRUE,I4,-2);
7695 VARIDIV(R4,2.0f,I1,1,I4,2);
7696 VARIDIV(R4,2.0f,UI1,1,I4,2);
7697 VARIDIV(R4,2.0f,UI2,1,I4,2);
7698 VARIDIV(R4,2.0f,UI4,1,I4,2);
7699 if (HAVE_OLEAUT32_I8)
7701 VARIDIV(R4,2.0f,I8,1,I8,2);
7702 VARIDIV(R4,2.0f,UI8,1,I4,2);
7704 VARIDIV(R4,2.0f,INT,1,I4,2);
7705 VARIDIV(R4,2.0f,UINT,1,I4,2);
7706 VARIDIV(R8,2.0,NULL,0,NULL,0);
7707 VARIDIV(R8,2.0,I2,1,I4,2);
7708 VARIDIV(R8,2.0,I4,1,I4,2);
7709 VARIDIV(R8,2.0,R4,1,I4,2);
7710 VARIDIV(R8,2.0,R8,1,I4,2);
7711 VARIDIV(R8,2.0,DATE,1,I4,2);
7712 VARIDIV(R8,2.0,BSTR,num1_str,I4,2);
7713 VARIDIV(R8,2.0,BOOL,VARIANT_TRUE,I4,-2);
7714 VARIDIV(R8,2.0,I1,1,I4,2);
7715 VARIDIV(R8,2.0,UI1,1,I4,2);
7716 VARIDIV(R8,2.0,UI2,1,I4,2);
7717 VARIDIV(R8,2.0,UI4,1,I4,2);
7718 if (HAVE_OLEAUT32_I8)
7720 VARIDIV(R8,2.0,I8,1,I8,2);
7721 VARIDIV(R8,2.0,UI8,1,I4,2);
7723 VARIDIV(R8,2.0,INT,1,I4,2);
7724 VARIDIV(R8,2.0,UINT,1,I4,2);
7725 VARIDIV(DATE,2,NULL,0,NULL,0);
7726 VARIDIV(DATE,2,I2,1,I4,2);
7727 VARIDIV(DATE,2,I4,1,I4,2);
7728 VARIDIV(DATE,2,R4,1,I4,2);
7729 VARIDIV(DATE,2,R8,1,I4,2);
7730 VARIDIV(DATE,2,DATE,1,I4,2);
7731 VARIDIV(DATE,2,BSTR,num1_str,I4,2);
7732 VARIDIV(DATE,2,BOOL,VARIANT_TRUE,I4,-2);
7733 VARIDIV(DATE,2,I1,1,I4,2);
7734 VARIDIV(DATE,2,UI1,1,I4,2);
7735 VARIDIV(DATE,2,UI2,1,I4,2);
7736 VARIDIV(DATE,2,UI4,1,I4,2);
7737 if (HAVE_OLEAUT32_I8)
7739 VARIDIV(DATE,2,I8,1,I8,2);
7740 VARIDIV(DATE,2,UI8,1,I4,2);
7742 VARIDIV(DATE,2,INT,1,I4,2);
7743 VARIDIV(DATE,2,UINT,1,I4,2);
7744 VARIDIV(BSTR,num2_str,NULL,0,NULL,0);
7745 VARIDIV(BSTR,num2_str,I2,1,I4,2);
7746 VARIDIV(BSTR,num2_str,I4,1,I4,2);
7747 VARIDIV(BSTR,num2_str,R4,1.0f,I4,2);
7748 VARIDIV(BSTR,num2_str,R8,1.0,I4,2);
7749 VARIDIV(BSTR,num2_str,DATE,1,I4,2);
7750 VARIDIV(BSTR,num2_str,BSTR,num1_str,I4,2);
7751 VARIDIV(BSTR,num2_str,BOOL,VARIANT_TRUE,I4,-2);
7752 VARIDIV(BSTR,num2_str,I1,1,I4,2);
7753 VARIDIV(BSTR,num2_str,UI1,1,I4,2);
7754 VARIDIV(BSTR,num2_str,UI2,1,I4,2);
7755 VARIDIV(BSTR,num2_str,UI4,1,I4,2);
7756 if (HAVE_OLEAUT32_I8)
7758 VARIDIV(BSTR,num2_str,I8,1,I8,2);
7759 VARIDIV(BSTR,num2_str,UI8,1,I4,2);
7761 VARIDIV(BSTR,num2_str,INT,1,I4,2);
7762 VARIDIV(BSTR,num2_str,UINT,1,I4,2);
7763 VARIDIV(BOOL,VARIANT_TRUE,NULL,0,NULL,0);
7764 VARIDIV(BOOL,VARIANT_TRUE,I2,1,I2,-1);
7765 VARIDIV(BOOL,VARIANT_TRUE,I4,1,I4,-1);
7766 VARIDIV(BOOL,VARIANT_TRUE,R4,1.0f,I4,-1);
7767 VARIDIV(BOOL,VARIANT_TRUE,R8,1.0,I4,-1);
7768 VARIDIV(BOOL,VARIANT_TRUE,DATE,1,I4,-1);
7769 VARIDIV(BOOL,VARIANT_TRUE,BSTR,num1_str,I4,-1);
7770 VARIDIV(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,I2,1);
7771 VARIDIV(BOOL,VARIANT_TRUE,I1,1,I4,-1);
7772 VARIDIV(BOOL,VARIANT_TRUE,UI1,1,I2,-1);
7773 VARIDIV(BOOL,VARIANT_TRUE,UI2,1,I4,-1);
7774 VARIDIV(BOOL,VARIANT_TRUE,UI4,1,I4,-1);
7775 if (HAVE_OLEAUT32_I8)
7777 VARIDIV(BOOL,VARIANT_TRUE,I8,1,I8,-1);
7778 VARIDIV(BOOL,VARIANT_TRUE,UI8,1,I4,-1);
7780 VARIDIV(BOOL,VARIANT_TRUE,INT,1,I4,-1);
7781 VARIDIV(BOOL,VARIANT_TRUE,UINT,1,I4,-1);
7782 VARIDIV(I1,2,NULL,0,NULL,0);
7783 VARIDIV(I1,2,I2,1,I4,2);
7784 VARIDIV(I1,2,I4,1,I4,2);
7785 VARIDIV(I1,2,R4,1.0f,I4,2);
7786 VARIDIV(I1,2,R8,1.0,I4,2);
7787 VARIDIV(I1,2,DATE,1,I4,2);
7788 VARIDIV(I1,2,BSTR,num1_str,I4,2);
7789 VARIDIV(I1,2,BOOL,VARIANT_TRUE,I4,-2);
7790 VARIDIV(I1,2,I1,1,I4,2);
7791 VARIDIV(I1,2,UI1,1,I4,2);
7792 VARIDIV(I1,2,UI2,1,I4,2);
7793 VARIDIV(I1,2,UI4,1,I4,2);
7794 if (HAVE_OLEAUT32_I8)
7796 VARIDIV(I1,2,I8,1,I8,2);
7797 VARIDIV(I1,2,UI8,1,I4,2);
7799 VARIDIV(I1,2,INT,1,I4,2);
7800 VARIDIV(I1,2,UINT,1,I4,2);
7801 VARIDIV(UI1,2,NULL,0,NULL,0);
7802 VARIDIV(UI1,2,I2,1,I2,2);
7803 VARIDIV(UI1,2,I4,1,I4,2);
7804 VARIDIV(UI1,2,R4,1.0f,I4,2);
7805 VARIDIV(UI1,2,R8,1.0,I4,2);
7806 VARIDIV(UI1,2,DATE,1,I4,2);
7807 VARIDIV(UI1,2,BSTR,num1_str,I4,2);
7808 VARIDIV(UI1,2,BOOL,VARIANT_TRUE,I2,-2);
7809 VARIDIV(UI1,2,I1,1,I4,2);
7810 VARIDIV(UI1,2,UI1,1,UI1,2);
7811 VARIDIV(UI1,2,UI2,1,I4,2);
7812 VARIDIV(UI1,2,UI4,1,I4,2);
7813 if (HAVE_OLEAUT32_I8)
7815 VARIDIV(UI1,2,I8,1,I8,2);
7816 VARIDIV(UI1,2,UI8,1,I4,2);
7818 VARIDIV(UI1,2,INT,1,I4,2);
7819 VARIDIV(UI1,2,UINT,1,I4,2);
7820 VARIDIV(UI2,2,NULL,0,NULL,0);
7821 VARIDIV(UI2,2,I2,1,I4,2);
7822 VARIDIV(UI2,2,I4,1,I4,2);
7823 VARIDIV(UI2,2,R4,1.0f,I4,2);
7824 VARIDIV(UI2,2,R8,1.0,I4,2);
7825 VARIDIV(UI2,2,DATE,1,I4,2);
7826 VARIDIV(UI2,2,BSTR,num1_str,I4,2);
7827 VARIDIV(UI2,2,BOOL,VARIANT_TRUE,I4,-2);
7828 VARIDIV(UI2,2,I1,1,I4,2);
7829 VARIDIV(UI2,2,UI1,1,I4,2);
7830 VARIDIV(UI2,2,UI2,1,I4,2);
7831 VARIDIV(UI2,2,UI4,1,I4,2);
7832 if (HAVE_OLEAUT32_I8)
7834 VARIDIV(UI2,2,I8,1,I8,2);
7835 VARIDIV(UI2,2,UI8,1,I4,2);
7837 VARIDIV(UI2,2,INT,1,I4,2);
7838 VARIDIV(UI2,2,UINT,1,I4,2);
7839 VARIDIV(UI4,2,NULL,0,NULL,0);
7840 VARIDIV(UI4,2,I2,1,I4,2);
7841 VARIDIV(UI4,2,I4,1,I4,2);
7842 VARIDIV(UI4,2,R4,1.0f,I4,2);
7843 VARIDIV(UI4,2,R8,1.0,I4,2);
7844 VARIDIV(UI4,2,DATE,1,I4,2);
7845 VARIDIV(UI4,2,BSTR,num1_str,I4,2);
7846 VARIDIV(UI4,2,BOOL,VARIANT_TRUE,I4,-2);
7847 VARIDIV(UI4,2,I1,1,I4,2);
7848 VARIDIV(UI4,2,UI1,1,I4,2);
7849 VARIDIV(UI4,2,UI2,1,I4,2);
7850 VARIDIV(UI4,2,UI4,1,I4,2);
7851 if (HAVE_OLEAUT32_I8)
7853 VARIDIV(UI4,2,I8,1,I8,2);
7854 VARIDIV(UI4,2,UI8,1,I4,2);
7856 VARIDIV(UI4,2,INT,1,I4,2);
7857 VARIDIV(UI4,2,UINT,1,I4,2);
7858 if (HAVE_OLEAUT32_I8)
7860 VARIDIV(I8,2,NULL,0,NULL,0);
7861 VARIDIV(I8,2,I2,1,I8,2);
7862 VARIDIV(I8,2,I4,1,I8,2);
7863 VARIDIV(I8,2,R4,1.0f,I8,2);
7864 VARIDIV(I8,2,R8,1.0,I8,2);
7865 VARIDIV(I8,2,DATE,1,I8,2);
7866 VARIDIV(I8,2,BSTR,num1_str,I8,2);
7867 VARIDIV(I8,2,BOOL,1,I8,2);
7868 VARIDIV(I8,2,I1,1,I8,2);
7869 VARIDIV(I8,2,UI1,1,I8,2);
7870 VARIDIV(I8,2,UI2,1,I8,2);
7871 VARIDIV(I8,2,UI4,1,I8,2);
7872 VARIDIV(I8,2,I8,1,I8,2);
7873 VARIDIV(I8,2,UI8,1,I8,2);
7874 VARIDIV(I8,2,UINT,1,I8,2);
7875 VARIDIV(UI8,2,NULL,0,NULL,0);
7876 VARIDIV(UI8,2,I2,1,I4,2);
7877 VARIDIV(UI8,2,I4,1,I4,2);
7878 VARIDIV(UI8,2,R4,1.0f,I4,2);
7879 VARIDIV(UI8,2,R8,1.0,I4,2);
7880 VARIDIV(UI8,2,DATE,1,I4,2);
7881 VARIDIV(UI8,2,BSTR,num1_str,I4,2);
7882 VARIDIV(UI8,2,BOOL,VARIANT_TRUE,I4,-2);
7883 VARIDIV(UI8,2,I1,1,I4,2);
7884 VARIDIV(UI8,2,UI1,1,I4,2);
7885 VARIDIV(UI8,2,UI2,1,I4,2);
7886 VARIDIV(UI8,2,UI4,1,I4,2);
7887 VARIDIV(UI8,2,I8,1,I8,2);
7888 VARIDIV(UI8,2,UI8,1,I4,2);
7889 VARIDIV(UI8,2,INT,1,I4,2);
7890 VARIDIV(UI8,2,UINT,1,I4,2);
7892 VARIDIV(INT,2,NULL,0,NULL,0);
7893 VARIDIV(INT,2,I2,1,I4,2);
7894 VARIDIV(INT,2,I4,1,I4,2);
7895 VARIDIV(INT,2,R4,1.0f,I4,2);
7896 VARIDIV(INT,2,R8,1.0,I4,2);
7897 VARIDIV(INT,2,DATE,1,I4,2);
7898 VARIDIV(INT,2,BSTR,num1_str,I4,2);
7899 VARIDIV(INT,2,BOOL,VARIANT_TRUE,I4,-2);
7900 VARIDIV(INT,2,I1,1,I4,2);
7901 VARIDIV(INT,2,UI1,1,I4,2);
7902 VARIDIV(INT,2,UI2,1,I4,2);
7903 VARIDIV(INT,2,UI4,1,I4,2);
7904 if (HAVE_OLEAUT32_I8)
7906 VARIDIV(INT,2,UI8,1,I4,2);
7908 VARIDIV(INT,2,INT,1,I4,2);
7909 VARIDIV(INT,2,UINT,1,I4,2);
7910 VARIDIV(UINT,2,NULL,0,NULL,0);
7911 VARIDIV(UINT,2,I2,1,I4,2);
7912 VARIDIV(UINT,2,I4,1,I4,2);
7913 VARIDIV(UINT,2,R4,1.0f,I4,2);
7914 VARIDIV(UINT,2,R8,1.0,I4,2);
7915 VARIDIV(UINT,2,DATE,1,I4,2);
7916 VARIDIV(UINT,2,BSTR,num1_str,I4,2);
7917 VARIDIV(UINT,2,BOOL,VARIANT_TRUE,I4,-2);
7918 VARIDIV(UINT,2,I1,1,I4,2);
7919 VARIDIV(UINT,2,UI1,1,I4,2);
7920 VARIDIV(UINT,2,UI2,1,I4,2);
7921 VARIDIV(UINT,2,UI4,1,I4,2);
7922 if (HAVE_OLEAUT32_I8)
7924 VARIDIV(UINT,2,I8,1,I8,2);
7925 VARIDIV(UINT,2,UI8,1,I4,2);
7927 VARIDIV(UINT,2,INT,1,I4,2);
7928 VARIDIV(UINT,2,UINT,1,I4,2);
7930 /* Manually test some VT_CY, VT_DECIMAL variants */
7932 hres = VarCyFromI4(10000, &V_CY(&cy));
7933 ok(hres == S_OK, "VarCyFromI4 failed!\n");
7934 V_VT(&dec) = VT_DECIMAL;
7935 hres = VarDecFromR8(2.0, &V_DECIMAL(&dec));
7936 ok(hres == S_OK, "VarDecFromR4 failed!\n");
7937 memset(&left, 0, sizeof(left));
7938 memset(&right, 0, sizeof(right));
7939 V_VT(&left) = VT_I4;
7941 V_VT(&right) = VT_I8;
7944 hres = VarIdiv(&cy, &cy, &result);
7945 ok(hres == S_OK && V_VT(&result) == VT_I4,
7946 "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
7947 S_OK, hres, vtstr(V_VT(&result)));
7948 ok(hres == S_OK && V_I4(&result) == 1,
7949 "VARIDIV: CY value %d, expected %d\n", V_I4(&result), 1);
7951 if (HAVE_OLEAUT32_I8)
7953 hres = VarIdiv(&cy, &right, &result);
7954 ok(hres == S_OK && V_VT(&result) == VT_I8,
7955 "VARIDIV: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n",
7956 S_OK, hres, vtstr(V_VT(&result)));
7957 ok(hres == S_OK && V_I8(&result) == 5000,
7958 "VARIDIV: CY value 0x%x%08x, expected 0x%x\n",
7959 (DWORD)(V_I8(&result) >>32), (DWORD)V_I8(&result), 5000);
7962 hres = VarIdiv(&left, &cy, &result);
7963 ok(hres == S_OK && V_VT(&result) == VT_I4,
7964 "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
7965 S_OK, hres, vtstr(V_VT(&result)));
7966 ok(hres == S_OK && V_I4(&result) == 0,
7967 "VARIDIV: CY value %d, expected %d\n", V_I4(&result), 0);
7969 hres = VarIdiv(&left, &dec, &result);
7970 ok(hres == S_OK && V_VT(&result) == VT_I4,
7971 "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
7972 S_OK, hres, vtstr(V_VT(&result)));
7973 ok(hres == S_OK && V_I4(&result) == 50,
7974 "VARIDIV: DECIMAL value %d, expected %d\n", V_I4(&result), 50);
7976 hres = VarIdiv(&dec, &dec, &result);
7977 ok(hres == S_OK && V_VT(&result) == VT_I4,
7978 "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
7979 S_OK, hres, vtstr(V_VT(&result)));
7980 ok(hres == S_OK && V_I4(&result) == 1,
7981 "VARIDIV: DECIMAL value %d, expected %d\n", V_I4(&result), 1);
7983 if (HAVE_OLEAUT32_I8)
7985 hres = VarIdiv(&dec, &right, &result);
7986 ok(hres == S_OK && V_VT(&result) == VT_I8,
7987 "VARIDIV: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n",
7988 S_OK, hres, vtstr(V_VT(&result)));
7989 ok(hres == S_OK && V_I8(&result) == 1,
7990 "VARIDIV: DECIMAL value 0x%x%08x, expected %d\n",
7991 (DWORD)(V_I8(&result) >> 32), (DWORD)V_I8(&result), 1);
7994 /* Check for division by zero */
7995 V_VT(&left) = VT_INT;
7997 V_VT(&right) = VT_INT;
7999 hres = pVarIdiv(&left, &right, &result);
8000 ok(hres == DISP_E_DIVBYZERO && V_VT(&result) == VT_EMPTY,
8001 "VARIDIV: Division by 0 should result in DISP_E_DIVBYZERO but got 0x%X\n", hres);
8003 V_VT(&left) = VT_INT;
8005 V_VT(&right) = VT_INT;
8007 hres = pVarIdiv(&left, &right, &result);
8008 ok(hres == DISP_E_DIVBYZERO && V_VT(&result) == VT_EMPTY,
8009 "VARIDIV: Division by 0 should result in DISP_E_DIVBYZERO but got 0x%X\n", hres);
8011 SysFreeString(num1_str);
8012 SysFreeString(num2_str);
8016 static HRESULT (WINAPI *pVarImp)(LPVARIANT,LPVARIANT,LPVARIANT);
8018 #define VARIMP(vt1,val1,vt2,val2,rvt,rval) \
8019 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
8020 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
8021 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
8022 test_var_call2( __LINE__, pVarImp, &left, &right, &exp )
8024 /* Skip any type that is not defined or produces an error for every case */
8025 #define SKIPTESTIMP(a) \
8026 if (a == VT_ERROR || a == VT_VARIANT || \
8027 a == VT_DISPATCH || a == VT_UNKNOWN || \
8028 a == VT_RECORD || a > VT_UINT || \
8029 a == 15 /*not defined*/) \
8032 static void test_VarImp(void)
8034 static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
8035 static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
8036 VARIANT left, right, exp, result, cy, dec;
8037 BSTR true_str, false_str;
8043 true_str = SysAllocString(szTrue);
8044 false_str = SysAllocString(szFalse);
8046 /* Test all possible flag/vt combinations & the resulting vt type */
8047 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
8049 VARTYPE leftvt, rightvt, resvt;
8051 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
8053 SKIPTESTIMP(leftvt);
8055 /* Check if we need/have support for I8 and/or UI8 */
8056 if ((leftvt == VT_I8 || leftvt == VT_UI8) && !HAVE_OLEAUT32_I8)
8059 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
8062 SKIPTESTIMP(rightvt);
8064 /* Native crashes when using the extra flag VT_BYREF
8065 * or with the following VT combinations
8067 if ((leftvt == VT_UI4 && rightvt == VT_BSTR) ||
8068 (leftvt == VT_UI8 && rightvt == VT_BSTR) ||
8069 ExtraFlags[i] == VT_BYREF)
8072 /* Check if we need/have support for I8 and/or UI8 */
8073 if ((rightvt == VT_I8 || rightvt == VT_UI8) && !HAVE_OLEAUT32_I8)
8076 memset(&left, 0, sizeof(left));
8077 memset(&right, 0, sizeof(right));
8078 V_VT(&left) = leftvt | ExtraFlags[i];
8079 V_VT(&right) = rightvt | ExtraFlags[i];
8080 V_VT(&result) = VT_EMPTY;
8083 if (leftvt == VT_BSTR)
8084 V_BSTR(&left) = true_str;
8086 /* This allows us to test return types that are not NULL
8087 * (NULL Imp value = n, NULL Imp 0 = NULL)
8092 V_BSTR(&right) = true_str;
8095 VarDecFromR8(2.0, &V_DECIMAL(&right));
8096 V_VT(&right) = rightvt | ExtraFlags[i];
8099 V_BOOL(&right) = VARIANT_TRUE;
8101 case VT_I1: V_I1(&right) = 2; break;
8102 case VT_I2: V_I2(&right) = 2; break;
8103 case VT_I4: V_I4(&right) = 2; break;
8104 case VT_R4: V_R4(&right) = 2.0f; break;
8105 case VT_R8: V_R8(&right) = 2.0; break;
8106 case VT_CY: V_CY(&right).int64 = 10000; break;
8107 case VT_DATE: V_DATE(&right) = 2; break;
8108 case VT_I8: V_I8(&right) = 2; break;
8109 case VT_INT: V_INT(&right) = 2; break;
8110 case VT_UINT: V_UINT(&right) = 2; break;
8111 case VT_UI1: V_UI1(&right) = 2; break;
8112 case VT_UI2: V_UI2(&right) = 2; break;
8113 case VT_UI4: V_UI4(&right) = 2; break;
8114 case VT_UI8: V_UI8(&right) = 2; break;
8118 /* Native VarImp always returns an error when using extra
8119 * flags or if the variants are I8 and INT.
8121 if ((leftvt == VT_I8 && rightvt == VT_INT) ||
8125 /* Determine result type */
8126 else if ((leftvt == VT_BSTR && rightvt == VT_NULL) ||
8127 (leftvt == VT_NULL && rightvt == VT_NULL) ||
8128 (leftvt == VT_NULL && rightvt == VT_EMPTY))
8130 else if (leftvt == VT_I8 || rightvt == VT_I8)
8132 else if (leftvt == VT_I4 || rightvt == VT_I4 ||
8133 leftvt == VT_INT || rightvt == VT_INT ||
8134 leftvt == VT_UINT || rightvt == VT_UINT ||
8135 leftvt == VT_UI4 || rightvt == VT_UI4 ||
8136 leftvt == VT_UI8 || rightvt == VT_UI8 ||
8137 leftvt == VT_UI2 || rightvt == VT_UI2 ||
8138 leftvt == VT_DECIMAL || rightvt == VT_DECIMAL ||
8139 leftvt == VT_DATE || rightvt == VT_DATE ||
8140 leftvt == VT_CY || rightvt == VT_CY ||
8141 leftvt == VT_R8 || rightvt == VT_R8 ||
8142 leftvt == VT_R4 || rightvt == VT_R4 ||
8143 leftvt == VT_I1 || rightvt == VT_I1)
8145 else if ((leftvt == VT_UI1 && rightvt == VT_UI1) ||
8146 (leftvt == VT_UI1 && rightvt == VT_NULL) ||
8147 (leftvt == VT_NULL && rightvt == VT_UI1))
8149 else if (leftvt == VT_EMPTY || rightvt == VT_EMPTY ||
8150 leftvt == VT_I2 || rightvt == VT_I2 ||
8151 leftvt == VT_UI1 || rightvt == VT_UI1)
8153 else if (leftvt == VT_BOOL || rightvt == VT_BOOL ||
8154 leftvt == VT_BSTR || rightvt == VT_BSTR)
8157 hres = pVarImp(&left, &right, &result);
8159 /* Check expected HRESULT and if result variant type is correct */
8161 ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH,
8162 "VarImp: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
8163 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
8164 vtstr(V_VT(&result)), hres);
8166 ok (hres == S_OK && resvt == V_VT(&result),
8167 "VarImp: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
8168 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
8169 S_OK, vtstr(V_VT(&result)), hres);
8174 VARIMP(EMPTY,0,EMPTY,0,I2,-1);
8175 VARIMP(EMPTY,0,NULL,0,I2,-1);
8176 VARIMP(EMPTY,0,I2,-1,I2,-1);
8177 VARIMP(EMPTY,0,I4,-1,I4,-1);
8178 VARIMP(EMPTY,0,R4,0.0f,I4,-1);
8179 VARIMP(EMPTY,0,R8,-1.0,I4,-1);
8180 VARIMP(EMPTY,0,DATE,0,I4,-1);
8181 VARIMP(EMPTY,0,BSTR,true_str,I2,-1);
8182 VARIMP(EMPTY,0,BOOL,VARIANT_FALSE,I2,-1);
8183 VARIMP(EMPTY,0,I1,0,I4,-1);
8184 VARIMP(EMPTY,0,UI1,1,I2,-1);
8185 VARIMP(EMPTY,0,UI2,1,I4,-1);
8186 VARIMP(EMPTY,0,UI4,1,I4,-1);
8187 if (HAVE_OLEAUT32_I8)
8189 VARIMP(EMPTY,0,I8,1,I8,-1);
8190 VARIMP(EMPTY,0,UI8,1,I4,-1);
8192 VARIMP(EMPTY,0,INT,-1,I4,-1);
8193 VARIMP(EMPTY,0,UINT,1,I4,-1);
8194 VARIMP(NULL,0,EMPTY,0,NULL,0);
8195 VARIMP(NULL,0,NULL,0,NULL,0);
8196 VARIMP(NULL,0,I2,-1,I2,-1);
8197 VARIMP(NULL,0,I4,-1,I4,-1);
8198 VARIMP(NULL,0,R4,0.0f,NULL,0);
8199 VARIMP(NULL,0,R8,-1.0,I4,-1);
8200 VARIMP(NULL,0,DATE,0,NULL,0);
8201 VARIMP(NULL,0,BSTR,true_str,BOOL,-1);
8202 VARIMP(NULL,0,BOOL,VARIANT_FALSE,NULL,0);
8203 VARIMP(NULL,0,I1,0,NULL,0);
8204 VARIMP(NULL,0,UI1,1,UI1,1);
8205 VARIMP(NULL,0,UI2,1,I4,1);
8206 VARIMP(NULL,0,UI4,1,I4,1);
8207 if (HAVE_OLEAUT32_I8)
8209 VARIMP(NULL,0,I8,1,I8,1);
8210 VARIMP(NULL,0,UI8,1,I4,1);
8212 VARIMP(NULL,0,INT,-1,I4,-1);
8213 VARIMP(NULL,0,UINT,1,I4,1);
8214 VARIMP(I2,-1,EMPTY,0,I2,0);
8215 VARIMP(I2,-1,I2,-1,I2,-1);
8216 VARIMP(I2,-1,I4,-1,I4,-1);
8217 VARIMP(I2,-1,R4,0.0f,I4,0);
8218 VARIMP(I2,-1,R8,-1.0,I4,-1);
8219 VARIMP(I2,-1,DATE,0,I4,0);
8220 VARIMP(I2,-1,BSTR,true_str,I2,-1);
8221 VARIMP(I2,-1,BOOL,VARIANT_FALSE,I2,0);
8222 VARIMP(I2,-1,I1,0,I4,0);
8223 VARIMP(I2,-1,UI1,1,I2,1);
8224 VARIMP(I2,-1,UI2,1,I4,1);
8225 VARIMP(I2,-1,UI4,1,I4,1);
8226 if (HAVE_OLEAUT32_I8)
8228 VARIMP(I2,-1,I8,1,I8,1);
8229 VARIMP(I2,-1,UI8,1,I4,1);
8231 VARIMP(I2,-1,INT,-1,I4,-1);
8232 VARIMP(I2,-1,UINT,1,I4,1);
8233 VARIMP(I4,2,EMPTY,0,I4,-3);
8234 VARIMP(I4,2,NULL,0,I4,-3);
8235 VARIMP(I4,2,I2,-1,I4,-1);
8236 VARIMP(I4,2,I4,-1,I4,-1);
8237 VARIMP(I4,2,R4,0.0f,I4,-3);
8238 VARIMP(I4,2,R8,-1.0,I4,-1);
8239 VARIMP(I4,2,DATE,0,I4,-3);
8240 VARIMP(I4,2,BSTR,true_str,I4,-1);
8241 VARIMP(I4,2,BOOL,VARIANT_FALSE,I4,-3);
8242 VARIMP(I4,2,I1,0,I4,-3);
8243 VARIMP(I4,2,UI1,1,I4,-3);
8244 VARIMP(I4,2,UI2,1,I4,-3);
8245 VARIMP(I4,2,UI4,1,I4,-3);
8246 if (HAVE_OLEAUT32_I8)
8248 VARIMP(I4,2,I8,1,I8,-3);
8249 VARIMP(I4,2,UI8,1,I4,-3);
8251 VARIMP(I4,2,INT,-1,I4,-1);
8252 VARIMP(I4,2,UINT,1,I4,-3);
8253 VARIMP(R4,-1.0f,EMPTY,0,I4,0);
8254 VARIMP(R4,-1.0f,NULL,0,NULL,0);
8255 VARIMP(R4,-1.0f,I2,-1,I4,-1);
8256 VARIMP(R4,-1.0f,I4,-1,I4,-1);
8257 VARIMP(R4,-1.0f,R4,0.0f,I4,0);
8258 VARIMP(R4,-1.0f,R8,-1.0,I4,-1);
8259 VARIMP(R4,-1.0f,DATE,1,I4,1);
8260 VARIMP(R4,-1.0f,BSTR,true_str,I4,-1);
8261 VARIMP(R4,-1.0f,BOOL,VARIANT_FALSE,I4,0);
8262 VARIMP(R4,-1.0f,I1,0,I4,0);
8263 VARIMP(R4,-1.0f,UI1,1,I4,1);
8264 VARIMP(R4,-1.0f,UI2,1,I4,1);
8265 VARIMP(R4,-1.0f,UI4,1,I4,1);
8266 if (HAVE_OLEAUT32_I8)
8268 VARIMP(R4,-1.0f,I8,1,I8,1);
8269 VARIMP(R4,-1.0f,UI8,1,I4,1);
8271 VARIMP(R4,-1.0f,INT,-1,I4,-1);
8272 VARIMP(R4,-1.0f,UINT,1,I4,1);
8273 VARIMP(R8,1.0,EMPTY,0,I4,-2);
8274 VARIMP(R8,1.0,NULL,0,I4,-2);
8275 VARIMP(R8,1.0,I2,-1,I4,-1);
8276 VARIMP(R8,1.0,I4,-1,I4,-1);
8277 VARIMP(R8,1.0,R4,0.0f,I4,-2);
8278 VARIMP(R8,1.0,R8,-1.0,I4,-1);
8279 VARIMP(R8,1.0,DATE,0,I4,-2);
8280 VARIMP(R8,1.0,BSTR,true_str,I4,-1);
8281 VARIMP(R8,1.0,BOOL,VARIANT_FALSE,I4,-2);
8282 VARIMP(R8,1.0,I1,0,I4,-2);
8283 VARIMP(R8,1.0,UI1,1,I4,-1);
8284 VARIMP(R8,1.0,UI2,1,I4,-1);
8285 VARIMP(R8,1.0,UI4,1,I4,-1);
8286 if (HAVE_OLEAUT32_I8)
8288 VARIMP(R8,1.0,I8,1,I8,-1);
8289 VARIMP(R8,1.0,UI8,1,I4,-1);
8291 VARIMP(R8,1.0,INT,-1,I4,-1);
8292 VARIMP(R8,1.0,UINT,1,I4,-1);
8293 VARIMP(DATE,0,EMPTY,0,I4,-1);
8294 VARIMP(DATE,0,NULL,0,I4,-1);
8295 VARIMP(DATE,0,I2,-1,I4,-1);
8296 VARIMP(DATE,0,I4,-1,I4,-1);
8297 VARIMP(DATE,0,R4,0.0f,I4,-1);
8298 VARIMP(DATE,0,R8,-1.0,I4,-1);
8299 VARIMP(DATE,0,DATE,0,I4,-1);
8300 VARIMP(DATE,0,BSTR,true_str,I4,-1);
8301 VARIMP(DATE,0,BOOL,VARIANT_FALSE,I4,-1);
8302 VARIMP(DATE,0,I1,0,I4,-1);
8303 VARIMP(DATE,0,UI1,1,I4,-1);
8304 VARIMP(DATE,0,UI2,1,I4,-1);
8305 VARIMP(DATE,0,UI4,1,I4,-1);
8306 if (HAVE_OLEAUT32_I8)
8308 VARIMP(DATE,0,I8,1,I8,-1);
8309 VARIMP(DATE,0,UI8,1,I4,-1);
8311 VARIMP(DATE,0,INT,-1,I4,-1);
8312 VARIMP(DATE,0,UINT,1,I4,-1);
8313 VARIMP(BSTR,false_str,EMPTY,0,I2,-1);
8314 VARIMP(BSTR,false_str,NULL,0,BOOL,-1);
8315 VARIMP(BSTR,false_str,I2,-1,I2,-1);
8316 VARIMP(BSTR,false_str,I4,-1,I4,-1);
8317 VARIMP(BSTR,false_str,R4,0.0f,I4,-1);
8318 VARIMP(BSTR,false_str,R8,-1.0,I4,-1);
8319 VARIMP(BSTR,false_str,DATE,0,I4,-1);
8320 VARIMP(BSTR,false_str,BSTR,true_str,BOOL,-1);
8321 VARIMP(BSTR,false_str,BOOL,VARIANT_FALSE,BOOL,-1);
8322 VARIMP(BSTR,false_str,I1,0,I4,-1);
8323 VARIMP(BSTR,false_str,UI1,1,I2,-1);
8324 VARIMP(BSTR,false_str,UI2,1,I4,-1);
8325 VARIMP(BSTR,false_str,UI4,1,I4,-1);
8326 if (HAVE_OLEAUT32_I8)
8328 VARIMP(BSTR,false_str,I8,1,I8,-1);
8329 VARIMP(BSTR,false_str,UI8,1,I4,-1);
8331 VARIMP(BSTR,false_str,INT,-1,I4,-1);
8332 VARIMP(BSTR,false_str,UINT,1,I4,-1);
8333 VARIMP(BOOL,VARIANT_TRUE,EMPTY,0,I2,0);
8334 VARIMP(BOOL,VARIANT_TRUE,NULL,0,NULL,0);
8335 VARIMP(BOOL,VARIANT_TRUE,I2,-1,I2,-1);
8336 VARIMP(BOOL,VARIANT_TRUE,I4,-1,I4,-1);
8337 VARIMP(BOOL,VARIANT_TRUE,R4,0.0f,I4,0);
8338 VARIMP(BOOL,VARIANT_TRUE,R8,-1.0,I4,-1);
8339 VARIMP(BOOL,VARIANT_TRUE,DATE,0,I4,0);
8340 VARIMP(BOOL,VARIANT_TRUE,BSTR,true_str,BOOL,-1);
8341 VARIMP(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,0);
8342 VARIMP(BOOL,VARIANT_TRUE,I1,0,I4,0);
8343 VARIMP(BOOL,VARIANT_TRUE,UI1,1,I2,1);
8344 VARIMP(BOOL,VARIANT_TRUE,UI2,1,I4,1);
8345 VARIMP(BOOL,VARIANT_TRUE,UI4,1,I4,1);
8346 if (HAVE_OLEAUT32_I8)
8348 VARIMP(BOOL,VARIANT_TRUE,I8,1,I8,1);
8349 VARIMP(BOOL,VARIANT_TRUE,UI8,1,I4,1);
8351 VARIMP(BOOL,VARIANT_TRUE,INT,-1,I4,-1);
8352 VARIMP(BOOL,VARIANT_TRUE,UINT,1,I4,1);
8353 VARIMP(I1,-1,EMPTY,0,I4,0);
8354 VARIMP(I1,-1,NULL,0,NULL,0);
8355 VARIMP(I1,-1,I2,-1,I4,-1);
8356 VARIMP(I1,-1,I4,-1,I4,-1);
8357 VARIMP(I1,-1,R4,0.0f,I4,0);
8358 VARIMP(I1,-1,R8,-1.0,I4,-1);
8359 VARIMP(I1,-1,DATE,0,I4,0);
8360 VARIMP(I1,-1,BSTR,true_str,I4,-1);
8361 VARIMP(I1,-1,BOOL,VARIANT_FALSE,I4,0);
8362 VARIMP(I1,-1,I1,0,I4,0);
8363 VARIMP(I1,-1,UI1,1,I4,1);
8364 VARIMP(I1,-1,UI2,1,I4,1);
8365 VARIMP(I1,-1,UI4,1,I4,1);
8366 if (HAVE_OLEAUT32_I8)
8368 VARIMP(I1,-1,I8,1,I8,1);
8369 VARIMP(I1,-1,UI8,1,I4,1);
8371 VARIMP(I1,-1,INT,-1,I4,-1);
8372 VARIMP(I1,-1,UINT,1,I4,1);
8373 VARIMP(UI1,0,EMPTY,0,I2,-1);
8374 VARIMP(UI1,0,NULL,0,UI1,255);
8375 VARIMP(UI1,0,I2,-1,I2,-1);
8376 VARIMP(UI1,0,I4,-1,I4,-1);
8377 VARIMP(UI1,0,R4,0.0f,I4,-1);
8378 VARIMP(UI1,0,R8,-1.0,I4,-1);
8379 VARIMP(UI1,0,DATE,0,I4,-1);
8380 VARIMP(UI1,0,BSTR,true_str,I2,-1);
8381 VARIMP(UI1,0,BOOL,VARIANT_FALSE,I2,-1);
8382 VARIMP(UI1,0,I1,0,I4,-1);
8383 VARIMP(UI1,0,UI1,1,UI1,255);
8384 VARIMP(UI1,0,UI2,1,I4,-1);
8385 VARIMP(UI1,0,UI4,1,I4,-1);
8386 if (HAVE_OLEAUT32_I8)
8388 VARIMP(UI1,0,I8,1,I8,-1);
8389 VARIMP(UI1,0,UI8,1,I4,-1);
8391 VARIMP(UI1,0,INT,-1,I4,-1);
8392 VARIMP(UI1,0,UINT,1,I4,-1);
8393 VARIMP(UI2,0,EMPTY,0,I4,-1);
8394 VARIMP(UI2,0,NULL,0,I4,-1);
8395 VARIMP(UI2,0,I2,-1,I4,-1);
8396 VARIMP(UI2,0,I4,-1,I4,-1);
8397 VARIMP(UI2,0,R4,0.0f,I4,-1);
8398 VARIMP(UI2,0,R8,-1.0,I4,-1);
8399 VARIMP(UI2,0,DATE,0,I4,-1);
8400 VARIMP(UI2,0,BSTR,true_str,I4,-1);
8401 VARIMP(UI2,0,BOOL,VARIANT_FALSE,I4,-1);
8402 VARIMP(UI2,0,I1,0,I4,-1);
8403 VARIMP(UI2,0,UI1,1,I4,-1);
8404 VARIMP(UI2,0,UI2,1,I4,-1);
8405 VARIMP(UI2,0,UI4,1,I4,-1);
8406 if (HAVE_OLEAUT32_I8)
8408 VARIMP(UI2,0,I8,1,I8,-1);
8409 VARIMP(UI2,0,UI8,1,I4,-1);
8411 VARIMP(UI2,0,INT,-1,I4,-1);
8412 VARIMP(UI2,0,UINT,1,I4,-1);
8413 VARIMP(UI4,0,EMPTY,0,I4,-1);
8414 VARIMP(UI4,0,NULL,0,I4,-1);
8415 VARIMP(UI4,0,I2,-1,I4,-1);
8416 VARIMP(UI4,0,I4,-1,I4,-1);
8417 VARIMP(UI4,0,R4,0.0f,I4,-1);
8418 VARIMP(UI4,0,R8,-1.0,I4,-1);
8419 VARIMP(UI4,0,DATE,0,I4,-1);
8420 VARIMP(UI4,0,BSTR,true_str,I4,-1);
8421 VARIMP(UI4,0,BOOL,VARIANT_FALSE,I4,-1);
8422 VARIMP(UI4,0,I1,0,I4,-1);
8423 VARIMP(UI4,0,UI1,1,I4,-1);
8424 VARIMP(UI4,0,UI2,1,I4,-1);
8425 VARIMP(UI4,0,UI4,1,I4,-1);
8426 if (HAVE_OLEAUT32_I8)
8428 VARIMP(UI4,0,I8,1,I8,-1);
8429 VARIMP(UI4,0,UI8,1,I4,-1);
8431 VARIMP(UI4,0,INT,-1,I4,-1);
8432 VARIMP(UI4,0,UINT,1,I4,-1);
8433 if (HAVE_OLEAUT32_I8)
8435 VARIMP(I8,-1,EMPTY,0,I8,0);
8436 VARIMP(I8,-1,NULL,0,NULL,0);
8437 VARIMP(I8,-1,I2,-1,I8,-1);
8438 VARIMP(I8,-1,I4,-1,I8,-1);
8439 VARIMP(I8,-1,R4,0.0f,I8,0);
8440 VARIMP(I8,-1,R8,-1.0,I8,-1);
8441 VARIMP(I8,-1,DATE,0,I8,0);
8442 VARIMP(I8,-1,BSTR,true_str,I8,-1);
8443 VARIMP(I8,-1,BOOL,VARIANT_FALSE,I8,0);
8444 VARIMP(I8,-1,I1,0,I8,0);
8445 VARIMP(I8,-1,UI1,1,I8,1);
8446 VARIMP(I8,-1,UI2,1,I8,1);
8447 VARIMP(I8,-1,UI4,1,I8,1);
8448 VARIMP(I8,-1,I8,1,I8,1);
8449 VARIMP(I8,-1,UI8,1,I8,1);
8450 VARIMP(I8,-1,UINT,1,I8,1);
8451 VARIMP(UI8,0,EMPTY,0,I4,-1);
8452 VARIMP(UI8,0,NULL,0,I4,-1);
8453 VARIMP(UI8,0,I2,-1,I4,-1);
8454 VARIMP(UI8,0,I4,-1,I4,-1);
8455 VARIMP(UI8,0,R4,0.0f,I4,-1);
8456 VARIMP(UI8,0,R8,-1.0,I4,-1);
8457 VARIMP(UI8,0,DATE,0,I4,-1);
8458 VARIMP(UI8,0,BSTR,true_str,I4,-1);
8459 VARIMP(UI8,0,BOOL,VARIANT_FALSE,I4,-1);
8460 VARIMP(UI8,0,I1,0,I4,-1);
8461 VARIMP(UI8,0,UI1,1,I4,-1);
8462 VARIMP(UI8,0,UI2,1,I4,-1);
8463 VARIMP(UI8,0,UI4,1,I4,-1);
8464 VARIMP(UI8,0,I8,1,I8,-1);
8465 VARIMP(UI8,0,UI8,1,I4,-1);
8466 VARIMP(UI8,0,INT,-1,I4,-1);
8467 VARIMP(UI8,0,UINT,1,I4,-1);
8469 VARIMP(INT,-1,EMPTY,0,I4,0);
8470 VARIMP(INT,-1,NULL,0,NULL,0);
8471 VARIMP(INT,-1,I2,-1,I4,-1);
8472 VARIMP(INT,-1,I4,-1,I4,-1);
8473 VARIMP(INT,-1,R4,0.0f,I4,0);
8474 VARIMP(INT,-1,R8,-1.0,I4,-1);
8475 VARIMP(INT,-1,DATE,0,I4,0);
8476 VARIMP(INT,-1,BSTR,true_str,I4,-1);
8477 VARIMP(INT,-1,BOOL,VARIANT_FALSE,I4,0);
8478 VARIMP(INT,-1,I1,0,I4,0);
8479 VARIMP(INT,-1,UI1,1,I4,1);
8480 VARIMP(INT,-1,UI2,1,I4,1);
8481 VARIMP(INT,-1,UI4,1,I4,1);
8482 if (HAVE_OLEAUT32_I8)
8484 VARIMP(INT,-1,I8,1,I8,1);
8485 VARIMP(INT,-1,UI8,1,I4,1);
8487 VARIMP(INT,-1,INT,-1,I4,-1);
8488 VARIMP(INT,-1,UINT,1,I4,1);
8489 VARIMP(UINT,1,EMPTY,0,I4,-2);
8490 VARIMP(UINT,1,NULL,0,I4,-2);
8491 VARIMP(UINT,1,I2,-1,I4,-1);
8492 VARIMP(UINT,1,I4,-1,I4,-1);
8493 VARIMP(UINT,1,R4,0.0f,I4,-2);
8494 VARIMP(UINT,1,R8,-1.0,I4,-1);
8495 VARIMP(UINT,1,DATE,0,I4,-2);
8496 VARIMP(UINT,1,BSTR,true_str,I4,-1);
8497 VARIMP(UINT,1,BOOL,VARIANT_FALSE,I4,-2);
8498 VARIMP(UINT,1,I1,0,I4,-2);
8499 VARIMP(UINT,1,UI1,1,I4,-1);
8500 VARIMP(UINT,1,UI2,1,I4,-1);
8501 VARIMP(UINT,1,UI4,1,I4,-1);
8502 if (HAVE_OLEAUT32_I8)
8504 VARIMP(UINT,1,I8,1,I8,-1);
8505 VARIMP(UINT,1,UI8,1,I4,-1);
8507 VARIMP(UINT,1,INT,-1,I4,-1);
8508 VARIMP(UINT,1,UINT,1,I4,-1);
8510 /* Manually test some VT_CY, VT_DECIMAL variants */
8512 hres = VarCyFromI4(1, &V_CY(&cy));
8513 ok(hres == S_OK, "VarCyFromI4 failed!\n");
8514 V_VT(&dec) = VT_DECIMAL;
8515 hres = VarDecFromR8(2.0, &V_DECIMAL(&dec));
8516 ok(hres == S_OK, "VarDecFromR4 failed!\n");
8517 memset(&left, 0, sizeof(left));
8518 memset(&right, 0, sizeof(right));
8519 V_VT(&left) = VT_I4;
8521 V_VT(&right) = VT_I8;
8524 hres = pVarImp(&cy, &cy, &result);
8525 ok(hres == S_OK && V_VT(&result) == VT_I4,
8526 "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8527 S_OK, hres, vtstr(V_VT(&result)));
8528 ok(hres == S_OK && V_I4(&result) == -1,
8529 "VARIMP: CY value %d, expected %d\n", V_I4(&result), -1);
8531 if (HAVE_OLEAUT32_I8)
8533 hres = pVarImp(&cy, &right, &result);
8534 ok(hres == S_OK && V_VT(&result) == VT_I8,
8535 "VARIMP: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n",
8536 S_OK, hres, vtstr(V_VT(&result)));
8537 ok(hres == S_OK && V_I8(&result) == -2,
8538 "VARIMP: CY value %x%08x, expected %d\n",
8539 (DWORD)((V_I8(&result)) >> 32), (DWORD)(V_I8(&result)), -2);
8542 hres = pVarImp(&left, &cy, &result);
8543 ok(hres == S_OK && V_VT(&result) == VT_I4,
8544 "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8545 S_OK, hres, vtstr(V_VT(&result)));
8546 ok(hres == S_OK && V_I4(&result) == -1,
8547 "VARIMP: CY value %d, expected %d\n", V_I4(&result), -1);
8549 hres = pVarImp(&left, &dec, &result);
8550 ok(hres == S_OK && V_VT(&result) == VT_I4,
8551 "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8552 S_OK, hres, vtstr(V_VT(&result)));
8553 ok(hres == S_OK && V_I4(&result) == -1,
8554 "VARIMP: DECIMAL value %d, expected %d\n", V_I4(&result), -1);
8556 hres = pVarImp(&dec, &dec, &result);
8557 ok(hres == S_OK && V_VT(&result) == VT_I4,
8558 "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8559 S_OK, hres, vtstr(V_VT(&result)));
8560 ok(hres == S_OK && V_I4(&result) == -1,
8561 "VARIMP: DECIMAL value %d, expected %d\n", V_I4(&result), -1);
8563 if (HAVE_OLEAUT32_I8)
8565 hres = pVarImp(&dec, &right, &result);
8566 ok(hres == S_OK && V_VT(&result) == VT_I8,
8567 "VARIMP: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n",
8568 S_OK, hres, vtstr(V_VT(&result)));
8569 ok(hres == S_OK && V_I8(&result) == -3,
8570 "VARIMP: DECIMAL value 0x%x%08x, expected %d\n",
8571 (DWORD)(V_I8(&result) >>32), (DWORD)V_I8(&result), -3);
8574 SysFreeString(false_str);
8575 SysFreeString(true_str);
8583 test_VariantClear();
8585 test_VariantCopyInd();
8586 test_VarParseNumFromStr();
8587 test_VarNumFromParseNum();
8588 test_VarUdateFromDate();
8589 test_VarDateFromUdate();
8590 test_SystemTimeToVariantTime();
8591 test_VariantTimeToSystemTime();
8592 test_DosDateTimeToVariantTime();
8593 test_VariantTimeToDosDateTime();