1 /*
2  * VARIANT test program
3  *
4  * Copyright 1998 Jean-Claude Cote
5  * Copyright 2006 Google (Benjamin Arai)
6  *
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.
11  *
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.
16  *
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
20  */
21 
22 #include "precomp.h"
23 
24 #include <float.h>
25 
26 static HMODULE hOleaut32;
27 
28 static HRESULT (WINAPI *pVarUdateFromDate)(DATE,ULONG,UDATE*);
29 static HRESULT (WINAPI *pVarDateFromUdate)(UDATE*,ULONG,DATE*);
30 static INT (WINAPI *pSystemTimeToVariantTime)(LPSYSTEMTIME,double*);
31 static INT (WINAPI *pVariantTimeToSystemTime)(double,LPSYSTEMTIME);
32 static INT (WINAPI *pDosDateTimeToVariantTime)(USHORT,USHORT,double*);
33 static INT (WINAPI *pVariantTimeToDosDateTime)(double,USHORT*,USHORT *);
34 
35 static const WCHAR sz12[] = {'1','2','\0'};
36 /* the strings are localized */
37 static WCHAR sz12_false[32];
38 static WCHAR sz12_true[32];
39 
40 /* Get a conversion function ptr, return if function not available */
41 #define CHECKPTR(func) p##func = (void*)GetProcAddress(hOleaut32, #func); \
42   if (!p##func) { win_skip("function " # func " not available, not testing it\n"); return; }
43 
44 /* Has I8/UI8 data type? */
45 static BOOL has_i8;
46 
47 /* When comparing floating point values we cannot expect an exact match
48  * because the rounding errors depend on the exact algorithm.
49  */
50 #define EQ_DOUBLE(a,b)     (fabs((a)-(b)) / (1.0+fabs(a)+fabs(b)) < 1e-14)
51 #define EQ_FLOAT(a,b)      (fabs((a)-(b)) / (1.0+fabs(a)+fabs(b)) < 1e-7)
52 
53 #define SKIPTESTS(a)  if((a > VT_CLSID+10) && (a < VT_BSTR_BLOB-10)) continue
54 
55 /* Allow our test macros to work for VT_NULL and VT_EMPTY too */
56 #define V_EMPTY(v) V_I4(v)
57 #define V_NULL(v) V_I4(v)
58 
59 /* Size constraints for overflow tests */
60 #define I1_MAX   0x7f
61 #define I1_MIN   ((-I1_MAX)-1)
62 #define UI1_MAX  0xff
63 #define UI1_MIN  0
64 #define I2_MAX   0x7fff
65 #define I2_MIN   ((-I2_MAX)-1)
66 #define UI2_MAX  0xffff
67 #define UI2_MIN  0
68 #define I4_MAX   0x7fffffff
69 #define I4_MIN   ((-I4_MAX)-1)
70 #define UI4_MAX  0xffffffff
71 #define UI4_MIN  0
72 #define I8_MAX   (((LONGLONG)I4_MAX << 32) | UI4_MAX)
73 #define I8_MIN   ((-I8_MAX)-1)
74 #define UI8_MAX  (((ULONGLONG)UI4_MAX << 32) | UI4_MAX)
75 #define UI8_MIN  0
76 #define DATE_MAX 2958465
77 #define DATE_MIN -657434
78 #define R4_MAX FLT_MAX
79 #define R4_MIN FLT_MIN
80 #define R8_MAX DBL_MAX
81 #define R8_MIN DBL_MIN
82 
83 #define DEFINE_EXPECT(func) \
84     static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
85 
86 #define SET_EXPECT(func) \
87     do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
88 
89 #define CHECK_EXPECT2(func) \
90     do { \
91         ok(expect_ ##func, "unexpected call " #func "\n"); \
92         called_ ## func = TRUE; \
93     }while(0)
94 
95 #define CHECK_EXPECT(func) \
96     do { \
97         CHECK_EXPECT2(func); \
98         expect_ ## func = FALSE; \
99     }while(0)
100 
101 #define CHECK_CALLED(func) \
102     do { \
103         ok(called_ ## func, "expected " #func "\n"); \
104         expect_ ## func = called_ ## func = FALSE; \
105     }while(0)
106 
107 DEFINE_EXPECT(dispatch_invoke);
108 
109 typedef struct
110 {
111     IDispatch IDispatch_iface;
112     VARTYPE vt;
113     HRESULT result;
114 } DummyDispatch;
115 
116 static inline DummyDispatch *impl_from_IDispatch(IDispatch *iface)
117 {
118     return CONTAINING_RECORD(iface, DummyDispatch, IDispatch_iface);
119 }
120 
121 static ULONG WINAPI DummyDispatch_AddRef(IDispatch *iface)
122 {
123     return 2;
124 }
125 
126 static ULONG WINAPI DummyDispatch_Release(IDispatch *iface)
127 {
128     return 1;
129 }
130 
131 static HRESULT WINAPI DummyDispatch_QueryInterface(IDispatch *iface,
132                                                    REFIID riid,
133                                                    void** ppvObject)
134 {
135     *ppvObject = NULL;
136 
137     if (IsEqualIID(riid, &IID_IDispatch) ||
138         IsEqualIID(riid, &IID_IUnknown))
139     {
140         *ppvObject = iface;
141         IDispatch_AddRef(iface);
142     }
143 
144     return *ppvObject ? S_OK : E_NOINTERFACE;
145 }
146 
147 static HRESULT WINAPI DummyDispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
148 {
149     ok(0, "Unexpected call\n");
150     return E_NOTIMPL;
151 }
152 
153 static HRESULT WINAPI DummyDispatch_GetTypeInfo(IDispatch *iface, UINT tinfo, LCID lcid, ITypeInfo **ti)
154 {
155     ok(0, "Unexpected call\n");
156     return E_NOTIMPL;
157 }
158 
159 static HRESULT WINAPI DummyDispatch_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *names,
160     UINT cnames, LCID lcid, DISPID *dispid)
161 {
162     ok(0, "Unexpected call\n");
163     return E_NOTIMPL;
164 }
165 
166 static HRESULT WINAPI DummyDispatch_Invoke(IDispatch *iface,
167                                            DISPID dispid, REFIID riid,
168                                            LCID lcid, WORD wFlags,
169                                            DISPPARAMS *params,
170                                            VARIANT *res,
171                                            EXCEPINFO *ei,
172                                            UINT *arg_err)
173 {
174     DummyDispatch *This = impl_from_IDispatch(iface);
175 
176     CHECK_EXPECT(dispatch_invoke);
177 
178     ok(dispid == DISPID_VALUE, "got dispid %d\n", dispid);
179     ok(IsEqualIID(riid, &IID_NULL), "go riid %s\n", wine_dbgstr_guid(riid));
180     ok(wFlags == DISPATCH_PROPERTYGET, "Flags wrong\n");
181 
182     ok(params->rgvarg == NULL, "got %p\n", params->rgvarg);
183     ok(params->rgdispidNamedArgs == NULL, "got %p\n", params->rgdispidNamedArgs);
184     ok(params->cArgs == 0, "got %d\n", params->cArgs);
185     ok(params->cNamedArgs == 0, "got %d\n", params->cNamedArgs);
186 
187     ok(res != NULL, "got %p\n", res);
188     ok(V_VT(res) == VT_EMPTY, "got %d\n", V_VT(res));
189     ok(ei == NULL, "got %p\n", ei);
190     ok(arg_err == NULL, "got %p\n", arg_err);
191 
192     if (FAILED(This->result))
193         return This->result;
194 
195     V_VT(res) = This->vt;
196     if (This->vt == VT_UI1)
197         V_UI1(res) = 34;
198     else if (This->vt == VT_NULL)
199     {
200         V_VT(res) = VT_NULL;
201         V_BSTR(res) = NULL;
202     }
203     else
204         memset(res, 0, sizeof(*res));
205 
206     return S_OK;
207 }
208 
209 static const IDispatchVtbl DummyDispatch_VTable =
210 {
211     DummyDispatch_QueryInterface,
212     DummyDispatch_AddRef,
213     DummyDispatch_Release,
214     DummyDispatch_GetTypeInfoCount,
215     DummyDispatch_GetTypeInfo,
216     DummyDispatch_GetIDsOfNames,
217     DummyDispatch_Invoke
218 };
219 
220 static void init_test_dispatch(VARTYPE vt, DummyDispatch *dispatch)
221 {
222     dispatch->IDispatch_iface.lpVtbl = &DummyDispatch_VTable;
223     dispatch->vt = vt;
224     dispatch->result = S_OK;
225 }
226 
227 typedef struct IRecordInfoImpl
228 {
229     IRecordInfo IRecordInfo_iface;
230     LONG ref;
231     unsigned int recordclear;
232     unsigned int getsize;
233     unsigned int recordcopy;
234     struct __tagBRECORD *rec;
235 } IRecordInfoImpl;
236 
237 static inline IRecordInfoImpl *impl_from_IRecordInfo(IRecordInfo *iface)
238 {
239     return CONTAINING_RECORD(iface, IRecordInfoImpl, IRecordInfo_iface);
240 }
241 
242 static HRESULT WINAPI RecordInfo_QueryInterface(IRecordInfo *iface, REFIID riid, void **obj)
243 {
244     *obj = NULL;
245 
246     if (IsEqualIID(riid, &IID_IUnknown) ||
247         IsEqualIID(riid, &IID_IRecordInfo))
248     {
249         *obj = iface;
250         IRecordInfo_AddRef(iface);
251         return S_OK;
252     }
253 
254     return E_NOINTERFACE;
255 }
256 
257 static ULONG WINAPI RecordInfo_AddRef(IRecordInfo *iface)
258 {
259     IRecordInfoImpl* This = impl_from_IRecordInfo(iface);
260     return InterlockedIncrement(&This->ref);
261 }
262 
263 static ULONG WINAPI RecordInfo_Release(IRecordInfo *iface)
264 {
265     IRecordInfoImpl* This = impl_from_IRecordInfo(iface);
266     ULONG ref = InterlockedDecrement(&This->ref);
267 
268     if (!ref)
269         HeapFree(GetProcessHeap(), 0, This);
270 
271     return ref;
272 }
273 
274 static HRESULT WINAPI RecordInfo_RecordInit(IRecordInfo *iface, PVOID pvNew)
275 {
276     ok(0, "unexpected call\n");
277     return E_NOTIMPL;
278 }
279 
280 static HRESULT WINAPI RecordInfo_RecordClear(IRecordInfo *iface, void *data)
281 {
282     IRecordInfoImpl* This = impl_from_IRecordInfo(iface);
283     This->recordclear++;
284     This->rec->pvRecord = NULL;
285     return S_OK;
286 }
287 
288 static HRESULT WINAPI RecordInfo_RecordCopy(IRecordInfo *iface, void *src, void *dest)
289 {
290     IRecordInfoImpl* This = impl_from_IRecordInfo(iface);
291     This->recordcopy++;
292     ok(src == (void*)0xdeadbeef, "wrong src pointer %p\n", src);
293     return S_OK;
294 }
295 
296 static HRESULT WINAPI RecordInfo_GetGuid(IRecordInfo *iface, GUID *pguid)
297 {
298     ok(0, "unexpected call\n");
299     return E_NOTIMPL;
300 }
301 
302 static HRESULT WINAPI RecordInfo_GetName(IRecordInfo *iface, BSTR *pbstrName)
303 {
304     ok(0, "unexpected call\n");
305     return E_NOTIMPL;
306 }
307 
308 static HRESULT WINAPI RecordInfo_GetSize(IRecordInfo *iface, ULONG* size)
309 {
310     IRecordInfoImpl* This = impl_from_IRecordInfo(iface);
311     This->getsize++;
312     *size = 0;
313     return S_OK;
314 }
315 
316 static HRESULT WINAPI RecordInfo_GetTypeInfo(IRecordInfo *iface, ITypeInfo **ppTypeInfo)
317 {
318     ok(0, "unexpected call\n");
319     return E_NOTIMPL;
320 }
321 
322 static HRESULT WINAPI RecordInfo_GetField(IRecordInfo *iface, PVOID pvData,
323                                                 LPCOLESTR szFieldName, VARIANT *pvarField)
324 {
325     ok(0, "unexpected call\n");
326     return E_NOTIMPL;
327 }
328 
329 static HRESULT WINAPI RecordInfo_GetFieldNoCopy(IRecordInfo *iface, PVOID pvData,
330                             LPCOLESTR szFieldName, VARIANT *pvarField, PVOID *ppvDataCArray)
331 {
332     ok(0, "unexpected call\n");
333     return E_NOTIMPL;
334 }
335 
336 static HRESULT WINAPI RecordInfo_PutField(IRecordInfo *iface, ULONG wFlags, PVOID pvData,
337                                             LPCOLESTR szFieldName, VARIANT *pvarField)
338 {
339     ok(0, "unexpected call\n");
340     return E_NOTIMPL;
341 }
342 
343 static HRESULT WINAPI RecordInfo_PutFieldNoCopy(IRecordInfo *iface, ULONG wFlags,
344                 PVOID pvData, LPCOLESTR szFieldName, VARIANT *pvarField)
345 {
346     ok(0, "unexpected call\n");
347     return E_NOTIMPL;
348 }
349 
350 static HRESULT WINAPI RecordInfo_GetFieldNames(IRecordInfo *iface, ULONG *pcNames,
351                                                 BSTR *rgBstrNames)
352 {
353     ok(0, "unexpected call\n");
354     return E_NOTIMPL;
355 }
356 
357 static BOOL WINAPI RecordInfo_IsMatchingType(IRecordInfo *iface, IRecordInfo *info2)
358 {
359     ok(0, "unexpected call\n");
360     return FALSE;
361 }
362 
363 static PVOID WINAPI RecordInfo_RecordCreate(IRecordInfo *iface)
364 {
365     ok(0, "unexpected call\n");
366     return NULL;
367 }
368 
369 static HRESULT WINAPI RecordInfo_RecordCreateCopy(IRecordInfo *iface, PVOID pvSource,
370                                                     PVOID *ppvDest)
371 {
372     ok(0, "unexpected call\n");
373     return E_NOTIMPL;
374 }
375 
376 static HRESULT WINAPI RecordInfo_RecordDestroy(IRecordInfo *iface, PVOID pvRecord)
377 {
378     ok(0, "unexpected call\n");
379     return E_NOTIMPL;
380 }
381 
382 static const IRecordInfoVtbl RecordInfoVtbl =
383 {
384     RecordInfo_QueryInterface,
385     RecordInfo_AddRef,
386     RecordInfo_Release,
387     RecordInfo_RecordInit,
388     RecordInfo_RecordClear,
389     RecordInfo_RecordCopy,
390     RecordInfo_GetGuid,
391     RecordInfo_GetName,
392     RecordInfo_GetSize,
393     RecordInfo_GetTypeInfo,
394     RecordInfo_GetField,
395     RecordInfo_GetFieldNoCopy,
396     RecordInfo_PutField,
397     RecordInfo_PutFieldNoCopy,
398     RecordInfo_GetFieldNames,
399     RecordInfo_IsMatchingType,
400     RecordInfo_RecordCreate,
401     RecordInfo_RecordCreateCopy,
402     RecordInfo_RecordDestroy
403 };
404 
405 static IRecordInfoImpl *get_test_recordinfo(void)
406 {
407     IRecordInfoImpl *rec;
408 
409     rec = HeapAlloc(GetProcessHeap(), 0, sizeof(IRecordInfoImpl));
410     rec->IRecordInfo_iface.lpVtbl = &RecordInfoVtbl;
411     rec->ref = 1;
412     rec->recordclear = 0;
413     rec->getsize = 0;
414     rec->recordcopy = 0;
415 
416     return rec;
417 }
418 
419 static void init(void)
420 {
421     BSTR bstr;
422     HRESULT res;
423 
424     res = VarBstrFromBool(VARIANT_TRUE, LANG_USER_DEFAULT, VAR_LOCALBOOL, &bstr);
425     ok(res == S_OK && bstr[0], "Expected localized string for 'True'\n");
426     /* lstrcpyW / lstrcatW do not work on win95 */
427     memcpy(sz12_true, sz12, sizeof(sz12));
428     if (bstr) memcpy(&sz12_true[2], bstr, SysStringByteLen(bstr) + sizeof(WCHAR));
429     SysFreeString(bstr);
430 
431     res = VarBstrFromBool(VARIANT_FALSE, LANG_USER_DEFAULT, VAR_LOCALBOOL, &bstr);
432     ok(res == S_OK && bstr[0], "Expected localized string for 'False'\n");
433     memcpy(sz12_false, sz12, sizeof(sz12));
434     if (bstr) memcpy(&sz12_false[2], bstr, SysStringByteLen(bstr) + sizeof(WCHAR));
435     SysFreeString(bstr);
436 
437     hOleaut32 = GetModuleHandleA("oleaut32.dll");
438     has_i8 = GetProcAddress(hOleaut32, "VarI8FromI1") != NULL;
439     if (!has_i8)
440         skip("No support for I8 and UI8 data types\n");
441 }
442 
443 /* Functions to set a DECIMAL */
444 static void setdec(DECIMAL* dec, BYTE scl, BYTE sgn, ULONG hi32, ULONG64 lo64)
445 {
446     S(U(*dec)).scale = scl;
447     S(U(*dec)).sign = sgn;
448     dec->Hi32 = hi32;
449     U1(*dec).Lo64 = lo64;
450 }
451 
452 static void setdec64(DECIMAL* dec, BYTE scl, BYTE sgn, ULONG hi32, ULONG mid32, ULONG lo32)
453 {
454     S(U(*dec)).scale = scl;
455     S(U(*dec)).sign = sgn;
456     dec->Hi32 = hi32;
457     S1(U1(*dec)).Mid32 = mid32;
458     S1(U1(*dec)).Lo32 = lo32;
459 }
460 
461 /* return the string text of a given variant type */
462 static char vtstr_buffer[16][256];
463 static int vtstr_current=0;
464 static const char *vtstr(int x)
465 {
466     switch(x) {
467 #define CASE(vt) case VT_##vt: return #vt
468     CASE(EMPTY);
469     CASE(NULL);
470     CASE(I2);
471     CASE(I4);
472     CASE(R4);
473     CASE(R8);
474     CASE(CY);
475     CASE(DATE);
476     CASE(BSTR);
477     CASE(DISPATCH);
478     CASE(ERROR);
479     CASE(BOOL);
480     CASE(VARIANT);
481     CASE(UNKNOWN);
482     CASE(DECIMAL);
483     CASE(I1);
484     CASE(UI1);
485     CASE(UI2);
486     CASE(UI4);
487     CASE(I8);
488     CASE(UI8);
489     CASE(INT);
490     CASE(UINT);
491     CASE(VOID);
492     CASE(HRESULT);
493     CASE(PTR);
494     CASE(SAFEARRAY);
495     CASE(CARRAY);
496     CASE(USERDEFINED);
497     CASE(LPSTR);
498     CASE(LPWSTR);
499     CASE(RECORD);
500     CASE(INT_PTR);
501     CASE(UINT_PTR);
502     CASE(FILETIME);
503     CASE(BLOB);
504     CASE(STREAM);
505     CASE(STORAGE);
506     CASE(STREAMED_OBJECT);
507     CASE(STORED_OBJECT);
508     CASE(BLOB_OBJECT);
509     CASE(CF);
510     CASE(CLSID);
511     CASE(VERSIONED_STREAM);
512     CASE(VECTOR);
513     CASE(ARRAY);
514     CASE(BYREF);
515     CASE(RESERVED);
516     CASE(ILLEGAL);
517 #undef CASE
518 
519     case 0xfff:
520         return "VT_BSTR_BLOB/VT_ILLEGALMASKED/VT_TYPEMASK";
521 
522     default:
523         vtstr_current %= sizeof(vtstr_buffer)/sizeof(*vtstr_buffer);
524         sprintf(vtstr_buffer[vtstr_current], "unknown variant type %d", x);
525         return vtstr_buffer[vtstr_current++];
526     }
527 }
528 
529 static const char *variantstr( const VARIANT *var )
530 {
531     vtstr_current %= sizeof(vtstr_buffer)/sizeof(*vtstr_buffer);
532     switch(V_VT(var))
533     {
534     case VT_I1:
535         sprintf( vtstr_buffer[vtstr_current], "VT_I1(%d)", V_I1(var) ); break;
536     case VT_I2:
537         sprintf( vtstr_buffer[vtstr_current], "VT_I2(%d)", V_I2(var) ); break;
538     case VT_I4:
539         sprintf( vtstr_buffer[vtstr_current], "VT_I4(%d)", V_I4(var) ); break;
540     case VT_INT:
541         sprintf( vtstr_buffer[vtstr_current], "VT_INT(%d)", V_INT(var) ); break;
542     case VT_I8:
543         sprintf( vtstr_buffer[vtstr_current], "VT_I8(%x%08x)", (UINT)(V_I8(var) >> 32), (UINT)V_I8(var) ); break;
544     case VT_UI8:
545         sprintf( vtstr_buffer[vtstr_current], "VT_UI8(%x%08x)", (UINT)(V_UI8(var) >> 32), (UINT)V_UI8(var) ); break;
546     case VT_R4:
547         sprintf( vtstr_buffer[vtstr_current], "VT_R4(%g)", V_R4(var) ); break;
548     case VT_R8:
549         sprintf( vtstr_buffer[vtstr_current], "VT_R8(%g)", V_R8(var) ); break;
550     case VT_UI1:
551         sprintf( vtstr_buffer[vtstr_current], "VT_UI1(%u)", V_UI1(var) ); break;
552     case VT_UI2:
553         sprintf( vtstr_buffer[vtstr_current], "VT_UI2(%u)", V_UI2(var) ); break;
554     case VT_UI4:
555         sprintf( vtstr_buffer[vtstr_current], "VT_UI4(%u)", V_UI4(var) ); break;
556     case VT_UINT:
557         sprintf( vtstr_buffer[vtstr_current], "VT_UINT(%d)", V_UINT(var) ); break;
558     case VT_CY:
559         sprintf( vtstr_buffer[vtstr_current], "VT_CY(%x%08x)", S(V_CY(var)).Hi, S(V_CY(var)).Lo ); break;
560     case VT_DATE:
561         sprintf( vtstr_buffer[vtstr_current], "VT_DATE(%g)", V_DATE(var) ); break;
562     default:
563         return vtstr(V_VT(var));
564     }
565     return vtstr_buffer[vtstr_current++];
566 }
567 
568 static BOOL is_expected_variant( const VARIANT *result, const VARIANT *expected )
569 {
570     if (V_VT(result) != V_VT(expected)) return FALSE;
571     switch(V_VT(expected))
572     {
573     case VT_EMPTY:
574     case VT_NULL:
575         return TRUE;
576 
577 #define CASE(vt) case VT_##vt: return (V_##vt(result) == V_##vt(expected))
578     CASE(BOOL);
579     CASE(I1);
580     CASE(UI1);
581     CASE(I2);
582     CASE(UI2);
583     CASE(I4);
584     CASE(UI4);
585     CASE(I8);
586     CASE(UI8);
587     CASE(INT);
588     CASE(UINT);
589 #undef CASE
590 
591     case VT_DATE:
592         return EQ_FLOAT(V_DATE(result), V_DATE(expected));
593     case VT_R4:
594         return EQ_FLOAT(V_R4(result), V_R4(expected));
595     case VT_R8:
596         return EQ_FLOAT(V_R8(result), V_R8(expected));
597     case VT_CY:
598         return (V_CY(result).int64 == V_CY(expected).int64);
599     case VT_BSTR:
600         return !lstrcmpW( V_BSTR(result), V_BSTR(expected) );
601     case VT_DECIMAL:
602         return !memcmp( &V_DECIMAL(result), &V_DECIMAL(expected), sizeof(DECIMAL) );
603     default:
604         ok(0, "unhandled variant type %s\n",vtstr(V_VT(expected)));
605         return FALSE;
606     }
607 }
608 
609 static void test_var_call1( int line, HRESULT (WINAPI *func)(LPVARIANT,LPVARIANT),
610                            VARIANT *arg, VARIANT *expected )
611 {
612     VARIANT old_arg = *arg;
613     VARIANT result;
614     HRESULT hres;
615 
616     memset( &result, 0, sizeof(result) );
617     hres = func( arg, &result );
618     ok_(__FILE__,line)( hres == S_OK, "wrong result %x\n", hres );
619     if (hres == S_OK)
620         ok_(__FILE__,line)( is_expected_variant( &result, expected ),
621                             "got %s expected %s\n", variantstr(&result), variantstr(expected) );
622     ok_(__FILE__,line)( is_expected_variant( arg, &old_arg ), "Modified argument %s / %s\n",
623                         variantstr(&old_arg), variantstr(arg));
624     VariantClear( &result );
625 }
626 
627 static void test_var_call2( int line, HRESULT (WINAPI *func)(LPVARIANT,LPVARIANT,LPVARIANT),
628                             VARIANT *left, VARIANT *right, VARIANT *expected )
629 {
630     VARIANT old_left = *left, old_right = *right;
631     VARIANT result;
632     HRESULT hres;
633 
634     memset( &result, 0, sizeof(result) );
635     hres = func( left, right, &result );
636     ok_(__FILE__,line)( hres == S_OK, "wrong result %x\n", hres );
637     if (hres == S_OK)
638         ok_(__FILE__,line)( is_expected_variant( &result, expected ),
639                             "got %s expected %s\n", variantstr(&result), variantstr(expected) );
640     ok_(__FILE__,line)( is_expected_variant( left, &old_left ), "Modified left argument %s / %s\n",
641                         variantstr(&old_left), variantstr(left));
642     ok_(__FILE__,line)( is_expected_variant( right, &old_right ), "Modified right argument %s / %s\n",
643                         variantstr(&old_right), variantstr(right));
644     VariantClear( &result );
645 }
646 
647 static int strcmp_wa(const WCHAR *strw, const char *stra)
648 {
649     WCHAR buf[512];
650     MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(buf[0]));
651     return lstrcmpW(strw, buf);
652 }
653 
654 #define test_bstr_var(a,b) _test_bstr_var(__LINE__,a,b)
655 static void _test_bstr_var(unsigned line, const VARIANT *v, const char *str)
656 {
657     ok_(__FILE__,line)(V_VT(v) == VT_BSTR, "unexpected vt=%d\n", V_VT(v));
658     if(V_VT(v) == VT_BSTR)
659         ok(!strcmp_wa(V_BSTR(v), str), "v=%s, expected %s\n", wine_dbgstr_w(V_BSTR(v)), str);
660 }
661 
662 static void test_VariantInit(void)
663 {
664   VARIANT v;
665 
666   memset(&v, -1, sizeof(v));
667   VariantInit(&v);
668   ok(V_VT(&v) == VT_EMPTY, "VariantInit() returned vt %d\n", V_VT(&v));
669 }
670 
671 /* All possible combinations of extra V_VT() flags */
672 static const VARTYPE ExtraFlags[16] =
673 {
674   0,
675   VT_VECTOR,
676   VT_ARRAY,
677   VT_BYREF,
678   VT_RESERVED,
679   VT_VECTOR|VT_ARRAY,
680   VT_VECTOR|VT_BYREF,
681   VT_VECTOR|VT_RESERVED,
682   VT_VECTOR|VT_ARRAY|VT_BYREF,
683   VT_VECTOR|VT_ARRAY|VT_RESERVED,
684   VT_VECTOR|VT_BYREF|VT_RESERVED,
685   VT_VECTOR|VT_ARRAY|VT_BYREF|VT_RESERVED,
686   VT_ARRAY|VT_BYREF,
687   VT_ARRAY|VT_RESERVED,
688   VT_ARRAY|VT_BYREF|VT_RESERVED,
689   VT_BYREF|VT_RESERVED,
690 };
691 
692 /* Determine if a vt is valid for VariantClear() */
693 static BOOL IsValidVariantClearVT(VARTYPE vt, VARTYPE extraFlags)
694 {
695   BOOL ret = FALSE;
696 
697   /* Only the following flags/types are valid */
698   if ((vt <= VT_LPWSTR || vt == VT_RECORD || vt == VT_CLSID) &&
699       vt != (VARTYPE)15 &&
700       (vt < (VARTYPE)24 || vt > (VARTYPE)31) &&
701       (!(extraFlags & (VT_BYREF|VT_ARRAY)) || vt > VT_NULL) &&
702       (extraFlags == 0 || extraFlags == VT_BYREF || extraFlags == VT_ARRAY ||
703        extraFlags == (VT_ARRAY|VT_BYREF)))
704     ret = TRUE; /* ok */
705 
706   if (!has_i8 && (vt == VT_I8 || vt == VT_UI8))
707     ret = FALSE; /* Old versions of oleaut32 */
708   return ret;
709 }
710 
711 typedef struct
712 {
713     IUnknown IUnknown_iface;
714     LONG     ref;
715     LONG     events;
716 } test_VariantClearImpl;
717 
718 static inline test_VariantClearImpl *impl_from_IUnknown(IUnknown *iface)
719 {
720     return CONTAINING_RECORD(iface, test_VariantClearImpl, IUnknown_iface);
721 }
722 
723 static HRESULT WINAPI VC_QueryInterface(LPUNKNOWN iface,REFIID riid,LPVOID *ppobj)
724 {
725     test_VariantClearImpl *This = impl_from_IUnknown(iface);
726     This->events |= 0x1;
727     return E_NOINTERFACE;
728 }
729 
730 static ULONG WINAPI VC_AddRef(LPUNKNOWN iface) {
731     test_VariantClearImpl *This = impl_from_IUnknown(iface);
732     This->events |= 0x2;
733     return InterlockedIncrement(&This->ref);
734 }
735 
736 static ULONG WINAPI VC_Release(LPUNKNOWN iface) {
737     test_VariantClearImpl *This = impl_from_IUnknown(iface);
738     /* static class, won't be  freed */
739     This->events |= 0x4;
740     return InterlockedDecrement(&This->ref);
741 }
742 
743 static const IUnknownVtbl test_VariantClear_vtbl = {
744     VC_QueryInterface,
745     VC_AddRef,
746     VC_Release,
747 };
748 
749 static test_VariantClearImpl test_myVariantClearImpl = {{&test_VariantClear_vtbl}, 1, 0};
750 
751 static void test_VariantClear(void)
752 {
753   struct __tagBRECORD *rec;
754   IRecordInfoImpl *recinfo;
755   HRESULT hres;
756   VARIANTARG v;
757   VARIANT v2;
758   size_t i;
759   LONG i4;
760   IUnknown *punk;
761 
762   /* Crashes: Native does not test input for NULL, so neither does Wine */
763   if (0)
764       VariantClear(NULL);
765 
766   /* Only the type field is set, to VT_EMPTY */
767   V_VT(&v) = VT_UI4;
768   V_UI4(&v) = ~0u;
769   hres = VariantClear(&v);
770   ok((hres == S_OK && V_VT(&v) == VT_EMPTY),
771      "VariantClear: Type set to %d, res %08x\n", V_VT(&v), hres);
772   ok(V_UI4(&v) == ~0u, "VariantClear: Overwrote value\n");
773 
774   /* Test all possible V_VT values.
775    * Also demonstrates that null pointers in 'v' are not dereferenced.
776    * Individual variant tests should test VariantClear() with non-NULL values.
777    */
778   for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
779   {
780     VARTYPE vt;
781 
782     for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
783     {
784       HRESULT hExpected = DISP_E_BADVARTYPE;
785 
786       SKIPTESTS(vt);
787 
788       memset(&v, 0, sizeof(v));
789       V_VT(&v) = vt | ExtraFlags[i];
790 
791       hres = VariantClear(&v);
792 
793       if (IsValidVariantClearVT(vt, ExtraFlags[i]))
794         hExpected = S_OK;
795 
796       ok(hres == hExpected, "VariantClear: expected 0x%X, got 0x%X for vt %d | 0x%X\n",
797          hExpected, hres, vt, ExtraFlags[i]);
798     }
799   }
800 
801   /* Some BYREF tests with non-NULL ptrs */
802 
803   /* VARIANT BYREF */
804   V_VT(&v2) = VT_I4;
805   V_I4(&v2) = 0x1234;
806   V_VT(&v) = VT_VARIANT | VT_BYREF;
807   V_VARIANTREF(&v) = &v2;
808 
809   hres = VariantClear(&v);
810   ok(hres == S_OK, "ret %08x\n", hres);
811   ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
812   ok(V_VARIANTREF(&v) == &v2, "variant ref %p\n", V_VARIANTREF(&v2));
813   ok(V_VT(&v2) == VT_I4, "vt %04x\n", V_VT(&v2));
814   ok(V_I4(&v2) == 0x1234, "i4 %04x\n", V_I4(&v2));
815 
816   /* I4 BYREF */
817   i4 = 0x4321;
818   V_VT(&v) = VT_I4 | VT_BYREF;
819   V_I4REF(&v) = &i4;
820 
821   hres = VariantClear(&v);
822   ok(hres == S_OK, "ret %08x\n", hres);
823   ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
824   ok(V_I4REF(&v) == &i4, "i4 ref %p\n", V_I4REF(&v2));
825   ok(i4 == 0x4321, "i4 changed %08x\n", i4);
826 
827 
828   /* UNKNOWN */
829   V_VT(&v) = VT_UNKNOWN;
830   V_UNKNOWN(&v) = &test_myVariantClearImpl.IUnknown_iface;
831   test_myVariantClearImpl.events = 0;
832   hres = VariantClear(&v);
833   ok(hres == S_OK, "ret %08x\n", hres);
834   ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
835   ok(V_UNKNOWN(&v) == &test_myVariantClearImpl.IUnknown_iface, "unknown %p\n", V_UNKNOWN(&v));
836   /* Check that Release got called, but nothing else */
837   ok(test_myVariantClearImpl.events ==  0x4, "Unexpected call. events %08x\n", test_myVariantClearImpl.events);
838 
839   /* UNKNOWN BYREF */
840   punk = &test_myVariantClearImpl.IUnknown_iface;
841   V_VT(&v) = VT_UNKNOWN | VT_BYREF;
842   V_UNKNOWNREF(&v) = &punk;
843   test_myVariantClearImpl.events = 0;
844   hres = VariantClear(&v);
845   ok(hres == S_OK, "ret %08x\n", hres);
846   ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
847   ok(V_UNKNOWNREF(&v) == &punk, "unknown ref %p\n", V_UNKNOWNREF(&v));
848   /* Check that nothing got called */
849   ok(test_myVariantClearImpl.events ==  0, "Unexpected call. events %08x\n", test_myVariantClearImpl.events);
850 
851   /* DISPATCH */
852   V_VT(&v) = VT_DISPATCH;
853   V_DISPATCH(&v) = (IDispatch*)&test_myVariantClearImpl.IUnknown_iface;
854   test_myVariantClearImpl.events = 0;
855   hres = VariantClear(&v);
856   ok(hres == S_OK, "ret %08x\n", hres);
857   ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
858   ok(V_DISPATCH(&v) == (IDispatch*)&test_myVariantClearImpl.IUnknown_iface,
859      "dispatch %p\n", V_DISPATCH(&v));
860   /* Check that Release got called, but nothing else */
861   ok(test_myVariantClearImpl.events ==  0x4, "Unexpected call. events %08x\n", test_myVariantClearImpl.events);
862 
863   /* DISPATCH BYREF */
864   punk = &test_myVariantClearImpl.IUnknown_iface;
865   V_VT(&v) = VT_DISPATCH | VT_BYREF;
866   V_DISPATCHREF(&v) = (IDispatch**)&punk;
867   test_myVariantClearImpl.events = 0;
868   hres = VariantClear(&v);
869   ok(hres == S_OK, "ret %08x\n", hres);
870   ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
871   ok(V_DISPATCHREF(&v) == (IDispatch**)&punk, "dispatch ref %p\n", V_DISPATCHREF(&v));
872   /* Check that nothing got called */
873   ok(test_myVariantClearImpl.events ==  0, "Unexpected call. events %08x\n", test_myVariantClearImpl.events);
874 
875   /* RECORD */
876   recinfo = get_test_recordinfo();
877   V_VT(&v) = VT_RECORD;
878   rec = &V_UNION(&v, brecVal);
879   rec->pRecInfo = &recinfo->IRecordInfo_iface;
880   rec->pvRecord = (void*)0xdeadbeef;
881   recinfo->recordclear = 0;
882   recinfo->ref = 2;
883   recinfo->rec = rec;
884   hres = VariantClear(&v);
885   ok(hres == S_OK, "ret %08x\n", hres);
886   ok(rec->pvRecord == NULL, "got %p\n", rec->pvRecord);
887   ok(recinfo->recordclear == 1, "got %d\n", recinfo->recordclear);
888   ok(recinfo->ref == 1, "got %d\n", recinfo->ref);
889   IRecordInfo_Release(&recinfo->IRecordInfo_iface);
890 }
891 
892 static void test_VariantCopy(void)
893 {
894   struct __tagBRECORD *rec;
895   IRecordInfoImpl *recinfo;
896   VARIANTARG vSrc, vDst;
897   VARTYPE vt;
898   size_t i;
899   HRESULT hres, hExpected;
900 
901   /* Establish that the failure/other cases are dealt with. Individual tests
902    * for each type should verify that data is copied correctly, references
903    * are updated, etc.
904    */
905 
906   /* vSrc == vDst */
907   for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
908   {
909     for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
910     {
911       SKIPTESTS(vt);
912 
913       memset(&vSrc, 0, sizeof(vSrc));
914       V_VT(&vSrc) = vt | ExtraFlags[i];
915 
916       hExpected = DISP_E_BADVARTYPE;
917       /* src is allowed to be a VT_CLSID */
918       if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
919         hExpected = S_OK;
920 
921       hres = VariantCopy(&vSrc, &vSrc);
922 
923       ok(hres == hExpected,
924          "Copy(src==dst): expected 0x%X, got 0x%X for src==dest vt %d|0x%X\n",
925          hExpected, hres, vt, ExtraFlags[i]);
926     }
927   }
928 
929   /* Test that if VariantClear() fails on dest, the function fails. This also
930    * shows that dest is in fact cleared and not just overwritten
931    */
932   memset(&vSrc, 0, sizeof(vSrc));
933   V_VT(&vSrc) = VT_UI1;
934 
935   for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
936   {
937     for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
938     {
939       SKIPTESTS(vt);
940 
941       hExpected = DISP_E_BADVARTYPE;
942 
943       memset(&vDst, 0, sizeof(vDst));
944       V_VT(&vDst) = vt | ExtraFlags[i];
945 
946       if (IsValidVariantClearVT(vt, ExtraFlags[i]))
947         hExpected = S_OK;
948 
949       hres = VariantCopy(&vDst, &vSrc);
950 
951       ok(hres == hExpected,
952          "Copy(bad dst): expected 0x%X, got 0x%X for dest vt %d|0x%X\n",
953          hExpected, hres, vt, ExtraFlags[i]);
954       if (hres == S_OK)
955         ok(V_VT(&vDst) == VT_UI1,
956            "Copy(bad dst): expected vt = VT_UI1, got %d\n", V_VT(&vDst));
957     }
958   }
959 
960   /* Test that VariantClear() checks vSrc for validity before copying */
961   for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
962   {
963     for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
964     {
965       SKIPTESTS(vt);
966 
967       hExpected = DISP_E_BADVARTYPE;
968 
969       memset(&vDst, 0, sizeof(vDst));
970       V_VT(&vDst) = VT_EMPTY;
971 
972       memset(&vSrc, 0, sizeof(vSrc));
973       V_VT(&vSrc) = vt | ExtraFlags[i];
974 
975       /* src is allowed to be a VT_CLSID */
976       if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
977         hExpected = S_OK;
978 
979       hres = VariantCopy(&vDst, &vSrc);
980 
981       ok(hres == hExpected,
982          "Copy(bad src): expected 0x%X, got 0x%X for src vt %d|0x%X\n",
983          hExpected, hres, vt, ExtraFlags[i]);
984       if (hres == S_OK)
985       {
986         ok(V_VT(&vDst) == (vt|ExtraFlags[i]),
987            "Copy(bad src): expected vt = %d, got %d\n",
988            vt | ExtraFlags[i], V_VT(&vDst));
989         VariantClear(&vDst);
990       }
991     }
992   }
993 
994   /* Test that copying a NULL BSTR results in an empty BSTR */
995   memset(&vDst, 0, sizeof(vDst));
996   V_VT(&vDst) = VT_EMPTY;
997   memset(&vSrc, 0, sizeof(vSrc));
998   V_VT(&vSrc) = VT_BSTR;
999   hres = VariantCopy(&vDst, &vSrc);
1000   ok(hres == S_OK, "Copy(NULL BSTR): Failed to copy a NULL BSTR\n");
1001   if (hres == S_OK)
1002   {
1003     ok((V_VT(&vDst) == VT_BSTR) && V_BSTR(&vDst),
1004        "Copy(NULL BSTR): should have non-NULL result\n");
1005     if ((V_VT(&vDst) == VT_BSTR) && V_BSTR(&vDst))
1006     {
1007       ok(*V_BSTR(&vDst) == 0, "Copy(NULL BSTR): result not empty\n");
1008     }
1009     VariantClear(&vDst);
1010   }
1011 
1012   /* copy RECORD */
1013   recinfo = get_test_recordinfo();
1014 
1015   memset(&vDst, 0, sizeof(vDst));
1016   V_VT(&vDst) = VT_EMPTY;
1017 
1018   V_VT(&vSrc) = VT_RECORD;
1019   rec = &V_UNION(&vSrc, brecVal);
1020   rec->pRecInfo = &recinfo->IRecordInfo_iface;
1021   rec->pvRecord = (void*)0xdeadbeef;
1022 
1023   recinfo->recordclear = 0;
1024   recinfo->recordcopy = 0;
1025   recinfo->getsize = 0;
1026   recinfo->rec = rec;
1027   hres = VariantCopy(&vDst, &vSrc);
1028   ok(hres == S_OK, "ret %08x\n", hres);
1029 
1030   rec = &V_UNION(&vDst, brecVal);
1031   ok(rec->pvRecord != (void*)0xdeadbeef && rec->pvRecord != NULL, "got %p\n", rec->pvRecord);
1032   ok(rec->pRecInfo == &recinfo->IRecordInfo_iface, "got %p\n", rec->pRecInfo);
1033   ok(recinfo->getsize == 1, "got %d\n", recinfo->recordclear);
1034   ok(recinfo->recordcopy == 1, "got %d\n", recinfo->recordclear);
1035 
1036   VariantClear(&vDst);
1037   VariantClear(&vSrc);
1038 }
1039 
1040 /* Determine if a vt is valid for VariantCopyInd() */
1041 static BOOL IsValidVariantCopyIndVT(VARTYPE vt, VARTYPE extraFlags)
1042 {
1043   BOOL ret = FALSE;
1044 
1045   if ((extraFlags & VT_ARRAY) ||
1046      (vt > VT_NULL && vt != (VARTYPE)15 && vt < VT_VOID &&
1047      !(extraFlags & (VT_VECTOR|VT_RESERVED))))
1048   {
1049     ret = TRUE; /* ok */
1050   }
1051   return ret;
1052 }
1053 
1054 static void test_VariantCopyInd(void)
1055 {
1056   VARIANTARG vSrc, vDst, vRef, vRef2;
1057   VARTYPE vt;
1058   size_t i;
1059   BYTE buffer[64];
1060   HRESULT hres, hExpected;
1061 
1062   memset(buffer, 0, sizeof(buffer));
1063 
1064   /* vSrc == vDst */
1065   for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
1066   {
1067     if (ExtraFlags[i] & VT_ARRAY)
1068       continue; /* Native crashes on NULL safearray */
1069 
1070     for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
1071     {
1072       SKIPTESTS(vt);
1073 
1074       memset(&vSrc, 0, sizeof(vSrc));
1075       V_VT(&vSrc) = vt | ExtraFlags[i];
1076 
1077       hExpected = DISP_E_BADVARTYPE;
1078       if (!(ExtraFlags[i] & VT_BYREF))
1079       {
1080         /* if src is not by-reference, acts as VariantCopy() */
1081         if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
1082           hExpected = S_OK;
1083       }
1084       else
1085       {
1086         if (vt == VT_SAFEARRAY || vt == VT_BSTR || vt == VT_UNKNOWN ||
1087             vt == VT_DISPATCH || vt == VT_RECORD)
1088           continue; /* Need valid ptrs for deep copies */
1089 
1090         V_BYREF(&vSrc) = &buffer;
1091         hExpected = E_INVALIDARG;
1092 
1093         if ((vt == VT_I8 || vt == VT_UI8) &&
1094             ExtraFlags[i] == VT_BYREF)
1095         {
1096           if (has_i8)
1097             hExpected = S_OK; /* Only valid if I8 is a known type */
1098         }
1099         else if (IsValidVariantCopyIndVT(vt, ExtraFlags[i]))
1100           hExpected = S_OK;
1101       }
1102 
1103       hres = VariantCopyInd(&vSrc, &vSrc);
1104 
1105       ok(hres == hExpected,
1106          "CopyInd(src==dst): expected 0x%X, got 0x%X for src==dst vt %d|0x%X\n",
1107          hExpected, hres, vt, ExtraFlags[i]);
1108     }
1109   }
1110 
1111   /* Bad dest */
1112   memset(&vSrc, 0, sizeof(vSrc));
1113   V_VT(&vSrc) = VT_UI1|VT_BYREF;
1114   V_BYREF(&vSrc) = &buffer;
1115 
1116   for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
1117   {
1118     for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
1119     {
1120       SKIPTESTS(vt);
1121 
1122       memset(&vDst, 0, sizeof(vDst));
1123       V_VT(&vDst) = vt | ExtraFlags[i];
1124 
1125       hExpected = DISP_E_BADVARTYPE;
1126 
1127       if (IsValidVariantClearVT(vt, ExtraFlags[i]))
1128         hExpected = S_OK;
1129 
1130       hres = VariantCopyInd(&vDst, &vSrc);
1131 
1132       ok(hres == hExpected,
1133          "CopyInd(bad dst): expected 0x%X, got 0x%X for dst vt %d|0x%X\n",
1134          hExpected, hres, vt, ExtraFlags[i]);
1135       if (hres == S_OK)
1136         ok(V_VT(&vDst) == VT_UI1,
1137            "CopyInd(bad dst): expected vt = VT_UI1, got %d\n", V_VT(&vDst));
1138     }
1139   }
1140 
1141   /* bad src */
1142   for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
1143   {
1144     if (ExtraFlags[i] & VT_ARRAY)
1145       continue; /* Native crashes on NULL safearray */
1146 
1147     for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
1148     {
1149       SKIPTESTS(vt);
1150 
1151       memset(&vDst, 0, sizeof(vDst));
1152       V_VT(&vDst) = VT_EMPTY;
1153 
1154       memset(&vSrc, 0, sizeof(vSrc));
1155       V_VT(&vSrc) = vt | ExtraFlags[i];
1156 
1157       hExpected = DISP_E_BADVARTYPE;
1158       if (!(ExtraFlags[i] & VT_BYREF))
1159       {
1160         /* if src is not by-reference, acts as VariantCopy() */
1161         if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
1162           hExpected = S_OK;
1163       }
1164       else
1165       {
1166         if (vt == VT_SAFEARRAY || vt == VT_BSTR || vt == VT_UNKNOWN ||
1167             vt == VT_DISPATCH || vt == VT_RECORD)
1168           continue; /* Need valid ptrs for deep copies, see vartype.c */
1169 
1170         V_BYREF(&vSrc) = &buffer;
1171 
1172         hExpected = E_INVALIDARG;
1173 
1174         if ((vt == VT_I8 || vt == VT_UI8) &&
1175             ExtraFlags[i] == VT_BYREF)
1176         {
1177           if (has_i8)
1178             hExpected = S_OK; /* Only valid if I8 is a known type */
1179         }
1180         else if (IsValidVariantCopyIndVT(vt, ExtraFlags[i]))
1181           hExpected = S_OK;
1182       }
1183 
1184       hres = VariantCopyInd(&vDst, &vSrc);
1185 
1186       ok(hres == hExpected,
1187          "CopyInd(bad src): expected 0x%X, got 0x%X for src vt %d|0x%X\n",
1188          hExpected, hres, vt, ExtraFlags[i]);
1189       if (hres == S_OK)
1190       {
1191         if (vt == VT_VARIANT && ExtraFlags[i] == VT_BYREF)
1192         {
1193           /* Type of vDst should be the type of the referenced variant.
1194            * Since we set the buffer to all zeros, its type should be
1195            * VT_EMPTY.
1196            */
1197           ok(V_VT(&vDst) == VT_EMPTY,
1198              "CopyInd(bad src): expected dst vt = VT_EMPTY, got %d|0x%X\n",
1199              V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK);
1200         }
1201         else
1202         {
1203           ok(V_VT(&vDst) == (vt|(ExtraFlags[i] & ~VT_BYREF)),
1204              "CopyInd(bad src): expected dst vt = %d|0x%X, got %d|0x%X\n",
1205              vt, ExtraFlags[i] & ~VT_BYREF,
1206              V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK);
1207         }
1208         VariantClear(&vDst);
1209       }
1210     }
1211   }
1212 
1213   /* By-reference variants are dereferenced */
1214   V_VT(&vRef) = VT_UI1;
1215   V_UI1(&vRef) = 0x77;
1216   V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
1217   V_VARIANTREF(&vSrc) = &vRef;
1218   VariantInit(&vDst);
1219 
1220   hres = VariantCopyInd(&vDst, &vSrc);
1221   ok(hres == S_OK, "VariantCopyInd failed: 0x%08x\n", hres);
1222   ok(V_VT(&vDst) == VT_UI1 && V_UI1(&vDst) == 0x77,
1223      "CopyInd(deref): expected dst vt = VT_UI1, val 0x77, got %d|0x%X, 0x%2X\n",
1224       V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK, V_UI1(&vDst));
1225 
1226   /* By-reference variant to a by-reference type succeeds */
1227   V_VT(&vRef) = VT_UI1|VT_BYREF;
1228   V_UI1REF(&vRef) = buffer; buffer[0] = 0x88;
1229   V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
1230   V_VARIANTREF(&vSrc) = &vRef;
1231   VariantInit(&vDst);
1232 
1233   hres = VariantCopyInd(&vDst, &vSrc);
1234   ok(hres == S_OK, "VariantCopyInd failed: 0x%08x\n", hres);
1235   ok(V_VT(&vDst) == VT_UI1 && V_UI1(&vDst) == 0x88,
1236      "CopyInd(deref): expected dst vt = VT_UI1, val 0x77, got %d|0x%X, 0x%2X\n",
1237       V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK, V_UI1(&vDst));
1238 
1239   /* But a by-reference variant to a by-reference variant fails */
1240   V_VT(&vRef2) = VT_UI1;
1241   V_UI1(&vRef2) = 0x77;
1242   V_VT(&vRef) = VT_VARIANT|VT_BYREF;
1243   V_VARIANTREF(&vRef) = &vRef2;
1244   V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
1245   V_VARIANTREF(&vSrc) = &vRef;
1246   VariantInit(&vDst);
1247 
1248   hres = VariantCopyInd(&vDst, &vSrc);
1249   ok(hres == E_INVALIDARG,
1250      "CopyInd(ref->ref): expected E_INVALIDARG, got 0x%08x\n", hres);
1251 }
1252 
1253 static HRESULT (WINAPI *pVarParseNumFromStr)(OLECHAR*,LCID,ULONG,NUMPARSE*,BYTE*);
1254 
1255 /* Macros for converting and testing the result of VarParseNumFromStr */
1256 #define FAILDIG 255
1257 
1258 static HRESULT convert_str( const char *str, INT dig, ULONG flags,
1259                             NUMPARSE *np, BYTE rgb[128], LCID lcid )
1260 {
1261     OLECHAR buff[128];
1262     MultiByteToWideChar( CP_ACP,0, str, -1, buff, sizeof(buff)/sizeof(WCHAR) );
1263     memset( rgb, FAILDIG, 128 );
1264     memset( np, 255, sizeof(*np) );
1265     np->cDig = dig;
1266     np->dwInFlags = flags;
1267     return pVarParseNumFromStr( buff, lcid, LOCALE_NOUSEROVERRIDE, np, rgb);
1268 }
1269 
1270 static void expect_NumFromStr( int line, HRESULT hres, NUMPARSE *np, INT a, ULONG b, ULONG c,
1271                                INT d, INT e, INT f )
1272 {
1273     if (hres == (HRESULT)S_OK)
1274     {
1275         ok_(__FILE__,line)(np->cDig == a, "Expected cDig = %d, got %d\n", a, np->cDig);
1276         ok_(__FILE__,line)(np->dwInFlags == b, "Expected dwInFlags = 0x%x, got 0x%x\n", b, np->dwInFlags);
1277         ok_(__FILE__,line)(np->dwOutFlags == c, "Expected dwOutFlags = 0x%x, got 0x%x\n", c, np->dwOutFlags);
1278         ok_(__FILE__,line)(np->cchUsed == d, "Expected cchUsed = %d, got %d\n", d, np->cchUsed);
1279         ok_(__FILE__,line)(np->nBaseShift == e, "Expected nBaseShift = %d, got %d\n", e, np->nBaseShift);
1280         ok_(__FILE__,line)(np->nPwr10 == f, "Expected nPwr10 = %d, got %d\n", f, np->nPwr10);
1281     }
1282 }
1283 
1284 #define CONVERTN(str,dig,flags) hres = convert_str( str, dig, flags, &np, rgb, lcid )
1285 #define CONVERT(str,flags) CONVERTN(str,sizeof(rgb),flags)
1286 #define EXPECT(a,b,c,d,e,f) expect_NumFromStr( __LINE__, hres, &np, a, b, c, d, e, f )
1287 #define EXPECTRGB(a,b) ok(rgb[a] == b, "Digit[%d], expected %d, got %d\n", a, b, rgb[a])
1288 #define EXPECTFAIL ok(hres == (HRESULT)DISP_E_TYPEMISMATCH, "Call succeeded, hres = %08x\n", hres)
1289 #define EXPECT2(a,b) EXPECTRGB(0,a); EXPECTRGB(1,b)
1290 
1291 static void test_VarParseNumFromStr(void)
1292 {
1293   HRESULT hres;
1294   /* Ensure all tests are using the same locale characters for '$', ',' etc */
1295   LCID lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1296   NUMPARSE np;
1297   BYTE rgb[128];
1298 
1299   /** No flags **/
1300 
1301   CHECKPTR(VarParseNumFromStr);
1302 
1303   /* Consume a single digit */
1304   CONVERT("7", 0);
1305   EXPECT(1,0,0,1,0,0);
1306   EXPECT2(7,FAILDIG);
1307 
1308   /* cDig is not literal digits - zeros are suppressed and nPwr10 is increased */
1309   CONVERT("10", 0);
1310   EXPECT(1,0,0,2,0,1);
1311   /* Note: Win32 writes the trailing zeros if they are within cDig's limits,
1312    * but then excludes them from the returned cDig count.
1313    * In our implementation we don't bother writing them at all.
1314    */
1315   EXPECTRGB(0, 1);
1316 
1317   /* if cDig is too small and numbers follow, sets INEXACT */
1318   CONVERTN("11",1, 0);
1319   EXPECT(1,0,NUMPRS_INEXACT,2,0,1);
1320   EXPECT2(1,FAILDIG);
1321 
1322   /* Strips leading zeros */
1323   CONVERT("01", 0);
1324   EXPECT(1,0,0,2,0,0);
1325   EXPECT2(1,FAILDIG);
1326 
1327   /* Strips leading zeros */
1328   CONVERTN("01",1, 0);
1329   EXPECT(1,0,0,2,0,0);
1330   EXPECT2(1,FAILDIG);
1331 
1332 
1333   /* Fails on non digits */
1334   CONVERT("a", 0);
1335   EXPECTFAIL;
1336   EXPECTRGB(0,FAILDIG);
1337 
1338   /** NUMPRS_LEADING_WHITE/NUMPRS_TRAILING_WHITE **/
1339 
1340   /* Without flag, fails on whitespace */
1341   CONVERT(" 0", 0);
1342   EXPECTFAIL;
1343   EXPECTRGB(0,FAILDIG);
1344 
1345 
1346   /* With flag, consumes whitespace */
1347   CONVERT(" 0", NUMPRS_LEADING_WHITE);
1348   EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
1349   EXPECT2(0,FAILDIG);
1350 
1351   /* Test TAB once, then assume it acts as space for all cases */
1352   CONVERT("\t0", NUMPRS_LEADING_WHITE);
1353   EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
1354   EXPECT2(0,FAILDIG);
1355 
1356 
1357   /* Doesn't pick up trailing whitespace without flag */
1358   CONVERT("0 ", 0);
1359   EXPECT(1,0,0,1,0,0);
1360   EXPECT2(0,FAILDIG);
1361 
1362   /* With flag, consumes trailing whitespace */
1363   CONVERT("0 ", NUMPRS_TRAILING_WHITE);
1364   EXPECT(1,NUMPRS_TRAILING_WHITE,NUMPRS_TRAILING_WHITE,2,0,0);
1365   EXPECT2(0,FAILDIG);
1366 
1367   /* Leading flag only consumes leading */
1368   CONVERT(" 0 ", NUMPRS_LEADING_WHITE);
1369   EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
1370   EXPECT2(0,FAILDIG);
1371 
1372   /* Both flags consumes both */
1373   CONVERT(" 0 ", NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE);
1374   EXPECT(1,NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE,NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE,3,0,0);
1375   EXPECT2(0,FAILDIG);
1376 
1377   /** NUMPRS_LEADING_PLUS/NUMPRS_TRAILING_PLUS **/
1378 
1379   /* Without flag, fails on + */
1380   CONVERT("+0", 0);
1381   EXPECTFAIL;
1382   EXPECTRGB(0,FAILDIG);
1383 
1384   /* With flag, consumes + */
1385   CONVERT("+0", NUMPRS_LEADING_PLUS);
1386   EXPECT(1,NUMPRS_LEADING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
1387   EXPECT2(0,FAILDIG);
1388 
1389   /* Without flag, doesn't consume trailing + */
1390   CONVERT("0+", 0);
1391   EXPECT(1,0,0,1,0,0);
1392   EXPECT2(0,FAILDIG);
1393 
1394   /* With flag, consumes trailing + */
1395   CONVERT("0+", NUMPRS_TRAILING_PLUS);
1396   EXPECT(1,NUMPRS_TRAILING_PLUS,NUMPRS_TRAILING_PLUS,2,0,0);
1397   EXPECT2(0,FAILDIG);
1398 
1399   /* With leading flag, doesn't consume trailing + */
1400   CONVERT("+0+", NUMPRS_LEADING_PLUS);
1401   EXPECT(1,NUMPRS_LEADING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
1402   EXPECT2(0,FAILDIG);
1403 
1404   /* Trailing + doesn't get consumed if we specify both (unlike whitespace) */
1405   CONVERT("+0+", NUMPRS_LEADING_PLUS|NUMPRS_TRAILING_PLUS);
1406   EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_TRAILING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
1407   EXPECT2(0,FAILDIG);
1408 
1409   /** NUMPRS_LEADING_MINUS/NUMPRS_TRAILING_MINUS **/
1410 
1411   /* Without flag, fails on - */
1412   CONVERT("-0", 0);
1413   EXPECTFAIL;
1414   EXPECTRGB(0,FAILDIG);
1415 
1416   /* With flag, consumes - */
1417   CONVERT("-0", NUMPRS_LEADING_MINUS);
1418   EXPECT(1,NUMPRS_LEADING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
1419   EXPECT2(0,FAILDIG);
1420 
1421   /* Without flag, doesn't consume trailing - */
1422   CONVERT("0-", 0);
1423   EXPECT(1,0,0,1,0,0);
1424   EXPECT2(0,FAILDIG);
1425 
1426   /* With flag, consumes trailing - */
1427   CONVERT("0-", NUMPRS_TRAILING_MINUS);
1428   EXPECT(1,NUMPRS_TRAILING_MINUS,NUMPRS_NEG|NUMPRS_TRAILING_MINUS,2,0,0);
1429   EXPECT2(0,FAILDIG);
1430 
1431   /* With leading flag, doesn't consume trailing - */
1432   CONVERT("-0-", NUMPRS_LEADING_MINUS);
1433   EXPECT(1,NUMPRS_LEADING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
1434   EXPECT2(0,FAILDIG);
1435 
1436   /* Trailing - doesn't get consumed if we specify both (unlike whitespace) */
1437   CONVERT("-0-", NUMPRS_LEADING_MINUS|NUMPRS_TRAILING_MINUS);
1438   EXPECT(1,NUMPRS_LEADING_MINUS|NUMPRS_TRAILING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
1439   EXPECT2(0,FAILDIG);
1440 
1441   /** NUMPRS_HEX_OCT **/
1442 
1443   /* Could be hex, octal or decimal - With flag reads as decimal */
1444   CONVERT("0", NUMPRS_HEX_OCT);
1445   EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
1446   EXPECT2(0,FAILDIG);
1447 
1448   /* Doesn't recognise hex in .asm syntax */
1449   CONVERT("0h", NUMPRS_HEX_OCT);
1450   EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
1451   EXPECT2(0,FAILDIG);
1452 
1453   /* Doesn't fail with valid leading string but no digits */
1454   CONVERT("0x", NUMPRS_HEX_OCT);
1455   EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
1456   EXPECT2(0,FAILDIG);
1457 
1458   /* Doesn't recognise hex format numbers at all! */
1459   CONVERT("0x0", NUMPRS_HEX_OCT);
1460   EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
1461   EXPECT2(0,FAILDIG);
1462 
1463   /* Doesn't recognise plain hex digits either */
1464   CONVERT("FE", NUMPRS_HEX_OCT);
1465   EXPECTFAIL;
1466   EXPECTRGB(0,FAILDIG);
1467 
1468   /* Octal */
1469   CONVERT("0100", NUMPRS_HEX_OCT);
1470   EXPECT(1,NUMPRS_HEX_OCT,0,4,0,2);
1471   EXPECTRGB(0,1);
1472   EXPECTRGB(1,0);
1473   EXPECTRGB(2,0);
1474   EXPECTRGB(3,FAILDIG);
1475 
1476   /* VB hex */
1477   CONVERT("&HF800", NUMPRS_HEX_OCT);
1478   EXPECT(4,NUMPRS_HEX_OCT,0x40,6,4,0);
1479   EXPECTRGB(0,15);
1480   EXPECTRGB(1,8);
1481   EXPECTRGB(2,0);
1482   EXPECTRGB(3,0);
1483   EXPECTRGB(4,FAILDIG);
1484 
1485   /* VB hex lower case and leading zero */
1486   CONVERT("&h0abcdef", NUMPRS_HEX_OCT);
1487   EXPECT(6,NUMPRS_HEX_OCT,0x40,9,4,0);
1488   EXPECTRGB(0,10);
1489   EXPECTRGB(1,11);
1490   EXPECTRGB(2,12);
1491   EXPECTRGB(3,13);
1492   EXPECTRGB(4,14);
1493   EXPECTRGB(5,15);
1494   EXPECTRGB(6,FAILDIG);
1495 
1496   /* VB oct */
1497   CONVERT("&O300", NUMPRS_HEX_OCT);
1498   EXPECT(3,NUMPRS_HEX_OCT,0x40,5,3,0);
1499   EXPECTRGB(0,3);
1500   EXPECTRGB(1,0);
1501   EXPECTRGB(2,0);
1502   EXPECTRGB(3,FAILDIG);
1503 
1504   /* VB oct lower case and leading zero */
1505   CONVERT("&o0777", NUMPRS_HEX_OCT);
1506   EXPECT(3,NUMPRS_HEX_OCT,0x40,6,3,0);
1507   EXPECTRGB(0,7);
1508   EXPECTRGB(1,7);
1509   EXPECTRGB(2,7);
1510   EXPECTRGB(3,FAILDIG);
1511 
1512   /* VB oct char bigger than 7 */
1513   CONVERT("&o128", NUMPRS_HEX_OCT);
1514   EXPECT(2,NUMPRS_HEX_OCT,0x40,4,3,0);
1515   EXPECTRGB(0,1);
1516   EXPECTRGB(1,2);
1517   EXPECTRGB(3,FAILDIG);
1518 
1519   /** NUMPRS_PARENS **/
1520 
1521   /* Empty parens = error */
1522   CONVERT("()", NUMPRS_PARENS);
1523   EXPECTFAIL;
1524   EXPECTRGB(0,FAILDIG);
1525 
1526   /* With flag, trailing parens not consumed */
1527   CONVERT("0()", NUMPRS_PARENS);
1528   EXPECT(1,NUMPRS_PARENS,0,1,0,0);
1529   EXPECT2(0,FAILDIG);
1530 
1531   /* With flag, Number in parens made negative and parens consumed */
1532   CONVERT("(0)", NUMPRS_PARENS);
1533   EXPECT(1,NUMPRS_PARENS,NUMPRS_NEG|NUMPRS_PARENS,3,0,0);
1534   EXPECT2(0,FAILDIG);
1535 
1536   /** NUMPRS_THOUSANDS **/
1537 
1538   /* With flag, thousands sep. not needed */
1539   CONVERT("0", NUMPRS_THOUSANDS);
1540   EXPECT(1,NUMPRS_THOUSANDS,0,1,0,0);
1541   EXPECT2(0,FAILDIG);
1542 
1543   /* With flag, thousands sep. and following digits consumed */
1544   CONVERT("1,000", NUMPRS_THOUSANDS);
1545   EXPECT(1,NUMPRS_THOUSANDS,NUMPRS_THOUSANDS,5,0,3);
1546   EXPECTRGB(0,1);
1547 
1548   /* With flag and decimal point, thousands sep. but not decimals consumed */
1549   CONVERT("1,000.0", NUMPRS_THOUSANDS);
1550   EXPECT(1,NUMPRS_THOUSANDS,NUMPRS_THOUSANDS,5,0,3);
1551   EXPECTRGB(0,1);
1552 
1553   /** NUMPRS_CURRENCY **/
1554 
1555   /* Without flag, chokes on currency sign */
1556   CONVERT("$11", 0);
1557   EXPECTFAIL;
1558   EXPECTRGB(0,FAILDIG);
1559 
1560   /* With flag, consumes currency sign */
1561   CONVERT("$11", NUMPRS_CURRENCY);
1562   EXPECT(2,NUMPRS_CURRENCY,NUMPRS_CURRENCY,3,0,0);
1563   EXPECT2(1,1);
1564   EXPECTRGB(2,FAILDIG);
1565 
1566   /* With flag only, doesn't consume decimal point */
1567   CONVERT("$11.1", NUMPRS_CURRENCY);
1568   EXPECT(2,NUMPRS_CURRENCY,NUMPRS_CURRENCY,3,0,0);
1569   EXPECT2(1,1);
1570   EXPECTRGB(2,FAILDIG);
1571 
1572   /* With flag and decimal flag, consumes decimal point and following digits */
1573   CONVERT("$11.1", NUMPRS_CURRENCY|NUMPRS_DECIMAL);
1574   EXPECT(3,NUMPRS_CURRENCY|NUMPRS_DECIMAL,NUMPRS_CURRENCY|NUMPRS_DECIMAL,5,0,-1);
1575   EXPECT2(1,1);
1576   EXPECTRGB(2,1);
1577   EXPECTRGB(3,FAILDIG);
1578 
1579   /* Thousands flag can only be used with currency */
1580   CONVERT("$1,234", NUMPRS_CURRENCY|NUMPRS_THOUSANDS);
1581   EXPECT(4,NUMPRS_CURRENCY|NUMPRS_THOUSANDS,NUMPRS_CURRENCY|NUMPRS_THOUSANDS,6,0,0);
1582   EXPECT2(1,2);
1583   EXPECTRGB(2,3);
1584   EXPECTRGB(3,4);
1585   EXPECTRGB(4,FAILDIG);
1586 
1587   /** NUMPRS_DECIMAL **/
1588 
1589   /* With flag, consumes decimal point */
1590   CONVERT("1.1", NUMPRS_DECIMAL);
1591   EXPECT(2,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1);
1592   EXPECT2(1,1);
1593   EXPECTRGB(2,FAILDIG);
1594 
1595   /* With flag, consumes decimal point. Skipping the decimal part is not an error */
1596   CONVERT("1.", NUMPRS_DECIMAL);
1597   EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,2,0,0);
1598   EXPECT2(1,FAILDIG);
1599 
1600   /* Consumes only one decimal point */
1601   CONVERT("1.1.", NUMPRS_DECIMAL);
1602   EXPECT(2,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1);
1603   EXPECT2(1,1);
1604   EXPECTRGB(2,FAILDIG);
1605 
1606   /** NUMPRS_EXPONENT **/
1607 
1608   /* Without flag, doesn't consume exponent */
1609   CONVERT("1e1", 0);
1610   EXPECT(1,0,0,1,0,0);
1611   EXPECT2(1,FAILDIG);
1612 
1613   /* With flag, consumes exponent */
1614   CONVERT("1e1", NUMPRS_EXPONENT);
1615   EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,1);
1616   EXPECT2(1,FAILDIG);
1617 
1618   /* Negative exponents are accepted without flags */
1619   CONVERT("1e-1", NUMPRS_EXPONENT);
1620   EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,-1);
1621   EXPECT2(1,FAILDIG);
1622 
1623   /* As are positive exponents and leading exponent 0s */
1624   CONVERT("1e+01", NUMPRS_EXPONENT);
1625   EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,5,0,1);
1626   EXPECT2(1,FAILDIG);
1627 
1628   /* The same for zero exponents */
1629   CONVERT("1e0", NUMPRS_EXPONENT);
1630   EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,0);
1631   EXPECT2(1,FAILDIG);
1632 
1633   /* Sign on a zero exponent doesn't matter */
1634   CONVERT("1e+0", NUMPRS_EXPONENT);
1635   EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,0);
1636   EXPECT2(1,FAILDIG);
1637 
1638   CONVERT("1e-0", NUMPRS_EXPONENT);
1639   EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,0);
1640   EXPECT2(1,FAILDIG);
1641 
1642   /* Doesn't consume a real number exponent */
1643   CONVERT("1e1.", NUMPRS_EXPONENT);
1644   EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,1);
1645   EXPECT2(1,FAILDIG);
1646 
1647   /* Powers of 10 are calculated from the position of any decimal point */
1648   CONVERT("1.5e20", NUMPRS_EXPONENT|NUMPRS_DECIMAL);
1649   EXPECT(2,NUMPRS_EXPONENT|NUMPRS_DECIMAL,NUMPRS_EXPONENT|NUMPRS_DECIMAL,6,0,19);
1650   EXPECT2(1,5);
1651 
1652   CONVERT("1.5e-20", NUMPRS_EXPONENT|NUMPRS_DECIMAL);
1653   EXPECT(2,NUMPRS_EXPONENT|NUMPRS_DECIMAL,NUMPRS_EXPONENT|NUMPRS_DECIMAL,7,0,-21);
1654   EXPECT2(1,5);
1655 
1656   /** NUMPRS_USE_ALL **/
1657 
1658   /* Flag expects all digits */
1659   CONVERT("0", NUMPRS_USE_ALL);
1660   EXPECT(1,NUMPRS_USE_ALL,0,1,0,0);
1661   EXPECT2(0,FAILDIG);
1662 
1663   /* Rejects anything trailing */
1664   CONVERT("0 ", NUMPRS_USE_ALL);
1665   EXPECTFAIL;
1666   EXPECT2(0,FAILDIG);
1667 
1668   /* Unless consumed by trailing flag */
1669   CONVERT("0 ", NUMPRS_USE_ALL|NUMPRS_TRAILING_WHITE);
1670   EXPECT(1,NUMPRS_USE_ALL|NUMPRS_TRAILING_WHITE,NUMPRS_TRAILING_WHITE,2,0,0);
1671   EXPECT2(0,FAILDIG);
1672 
1673   /** Combinations **/
1674 
1675   /* Leading whitespace and plus, doesn't consume trailing whitespace */
1676   CONVERT("+ 0 ", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1677   EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,3,0,0);
1678   EXPECT2(0,FAILDIG);
1679 
1680   /* Order of whitespace and plus is unimportant */
1681   CONVERT(" +0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1682   EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,3,0,0);
1683   EXPECT2(0,FAILDIG);
1684 
1685   /* Leading whitespace can be repeated */
1686   CONVERT(" + 0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1687   EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,4,0,0);
1688   EXPECT2(0,FAILDIG);
1689 
1690   /* But plus/minus etc. cannot */
1691   CONVERT("+ +0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1692   EXPECTFAIL;
1693   EXPECTRGB(0,FAILDIG);
1694 
1695   /* Inexact is not set if trailing zeros are removed */
1696   CONVERTN("10", 1, 0);
1697   EXPECT(1,0,0,2,0,1);
1698   EXPECT2(1,FAILDIG);
1699 
1700   /* Make sure a leading 0 is stripped but decimals after it get read */
1701   CONVERT("-0.51", NUMPRS_STD);
1702   EXPECT(2,NUMPRS_STD,NUMPRS_NEG|NUMPRS_DECIMAL|NUMPRS_LEADING_MINUS,5,0,-2);
1703   EXPECT2(5,1);
1704 
1705   /* Keep trailing zeros on whole number part of a decimal */
1706   CONVERT("10.1", NUMPRS_STD);
1707   EXPECT(3,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-1);
1708   EXPECT2(1,0);
1709   EXPECTRGB(2,1);
1710 
1711   /* Zeros after decimal sign */
1712   CONVERT("0.01", NUMPRS_STD);
1713   EXPECT(1,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-2);
1714   EXPECT2(1,FAILDIG);
1715 
1716   /* Trailing zeros after decimal part */
1717   CONVERT("0.10", NUMPRS_STD);
1718   EXPECT(1,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-1);
1719   EXPECT2(1,0);
1720 }
1721 
1722 static HRESULT (WINAPI *pVarNumFromParseNum)(NUMPARSE*,BYTE*,ULONG,VARIANT*);
1723 
1724 /* Macros for converting and testing the result of VarNumFromParseNum */
1725 #define SETRGB(indx,val) if (!indx) memset(rgb, FAILDIG, sizeof(rgb)); rgb[indx] = val
1726 #undef CONVERT
1727 #define CONVERT(a,b,c,d,e,f,bits) \
1728     np.cDig = (a); np.dwInFlags = (b); np.dwOutFlags = (c); np.cchUsed = (d); \
1729     np.nBaseShift = (e); np.nPwr10 = (f); hres = pVarNumFromParseNum(&np, rgb, bits, &vOut)
1730 static const char *szFailOverflow = "Expected overflow, hres = %08x\n";
1731 #define EXPECT_OVERFLOW ok(hres == (HRESULT)DISP_E_OVERFLOW, szFailOverflow, hres)
1732 static const char *szFailOk = "Call failed, hres = %08x\n";
1733 #define EXPECT_OK ok(hres == (HRESULT)S_OK, szFailOk, hres); \
1734   if (hres == (HRESULT)S_OK)
1735 #define EXPECT_TYPE(typ) ok(V_VT(&vOut) == typ,"Expected Type = " #typ ", got %d\n", V_VT(&vOut))
1736 #define EXPECT_I1(val) EXPECT_OK { EXPECT_TYPE(VT_I1); \
1737   ok(V_I1(&vOut) == val, "Expected i1 = %d, got %d\n", (signed char)val, V_I1(&vOut)); }
1738 #define EXPECT_UI1(val) EXPECT_OK { EXPECT_TYPE(VT_UI1); \
1739   ok(V_UI1(&vOut) == val, "Expected ui1 = %d, got %d\n", (BYTE)val, V_UI1(&vOut)); }
1740 #define EXPECT_I2(val) EXPECT_OK { EXPECT_TYPE(VT_I2); \
1741   ok(V_I2(&vOut) == val, "Expected i2 = %d, got %d\n", (SHORT)val, V_I2(&vOut)); }
1742 #define EXPECT_UI2(val) EXPECT_OK { EXPECT_TYPE(VT_UI2); \
1743   ok(V_UI2(&vOut) == val, "Expected ui2 = %d, got %d\n", (USHORT)val, V_UI2(&vOut)); }
1744 #define EXPECT_I4(val) EXPECT_OK { EXPECT_TYPE(VT_I4); \
1745   ok(V_I4(&vOut) == val, "Expected i4 = %d, got %d\n", (LONG)val, V_I4(&vOut)); }
1746 #define EXPECT_UI4(val) EXPECT_OK { EXPECT_TYPE(VT_UI4); \
1747   ok(V_UI4(&vOut) == val, "Expected ui4 = %d, got %d\n", (ULONG)val, V_UI4(&vOut)); }
1748 #define EXPECT_I8(high,low) EXPECT_OK { EXPECT_TYPE(VT_I8); \
1749   ok(V_I8(&vOut) == ((((ULONG64)(high))<<32)|(low)), "Expected i8 = %x%08x, got %x%08x\n", \
1750      (LONG)(high), (LONG)(low), (LONG)(V_I8(&vOut)>>32), (LONG)V_I8(&vOut) ); }
1751 #define EXPECT_UI8(val) EXPECT_OK { EXPECT_TYPE(VT_UI8); \
1752   ok(V_UI8(&vOut) == val, "Expected ui8 = 0x%x%08x, got 0x%x%08x\n", \
1753       (DWORD)((ULONG64)val >> 32), (DWORD)(ULONG64)val, (DWORD)(V_UI8(&vOut) >> 32), (DWORD)V_UI8(&vOut)); }
1754 #define EXPECT_R4(val) EXPECT_OK { EXPECT_TYPE(VT_R4); \
1755   ok(V_R4(&vOut) == val, "Expected r4 = %f, got %f\n", val, V_R4(&vOut)); }
1756 #define EXPECT_R8(val) EXPECT_OK { EXPECT_TYPE(VT_R8); \
1757   ok(V_R8(&vOut) == val, "Expected r8 = %g, got %g\n", val, V_R8(&vOut)); }
1758 #define CY_MULTIPLIER 10000
1759 #define EXPECT_CY(val) EXPECT_OK { EXPECT_TYPE(VT_CY); \
1760   ok(V_CY(&vOut).int64 == (LONG64)(val * CY_MULTIPLIER), "Expected r8 = 0x%x%08x, got 0x%x%08x\n", \
1761       (DWORD)((LONG64)val >> 23), (DWORD)(LONG64)val, (DWORD)(V_CY(&vOut).int64 >>32), (DWORD)V_CY(&vOut).int64); }
1762 #define EXPECT_DECIMAL(valHi, valMid, valLo) EXPECT_OK { EXPECT_TYPE(VT_DECIMAL); \
1763       ok((V_DECIMAL(&vOut).Hi32 == valHi) && (S1(U1(V_DECIMAL(&vOut))).Mid32 == valMid) && \
1764       (S1(U1(V_DECIMAL(&vOut))).Lo32 == valLo),                      \
1765   "Expected decimal = %x/0x%x%08x, got %x/0x%x%08x\n", valHi, valMid, valLo, \
1766       V_DECIMAL(&vOut).Hi32, S1(U1(V_DECIMAL(&vOut))).Mid32, S1(U1(V_DECIMAL(&vOut))).Lo32); }
1767 
1768 static void test_VarNumFromParseNum(void)
1769 {
1770   HRESULT hres;
1771   NUMPARSE np;
1772   BYTE rgb[128];
1773   VARIANT vOut;
1774 
1775   CHECKPTR(VarNumFromParseNum);
1776 
1777   /* Convert the number 1 to different types */
1778   SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I1); EXPECT_I1(1);
1779   SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_UI1); EXPECT_UI1(1);
1780   /* Prefers a signed type to unsigned of the same size */
1781   SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I1|VTBIT_UI1); EXPECT_I1(1);
1782   /* But takes the smaller size if possible */
1783   SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I2|VTBIT_UI1); EXPECT_UI1(1);
1784 
1785   /* Try different integer sizes */
1786 #define INTEGER_VTBITS (VTBIT_I1|VTBIT_UI1|VTBIT_I2|VTBIT_UI2|VTBIT_I4|VTBIT_UI4|VTBIT_I8|VTBIT_UI8)
1787 
1788   SETRGB(0, 1); CONVERT(1,0,0,1,0,0, INTEGER_VTBITS); EXPECT_I1(1);
1789   /* 127 */
1790   SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 7);
1791   CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_I1(127);
1792   /* 128 */
1793   SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 8);
1794   CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_UI1(128);
1795   /* 255 */
1796   SETRGB(0, 2); SETRGB(1, 5); SETRGB(2, 5);
1797   CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_UI1(255);
1798   /* 256 */
1799   SETRGB(0, 2); SETRGB(1, 5); SETRGB(2, 6);
1800   CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_I2(256);
1801   /* 32767 */
1802   SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 7);
1803   CONVERT(5,0,0,5,0,0, INTEGER_VTBITS); EXPECT_I2(32767);
1804   /* 32768 */
1805   SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 8);
1806   CONVERT(5,0,0,5,0,0, INTEGER_VTBITS); EXPECT_UI2(32768);
1807 
1808   /* Assume the above pattern holds for remaining positive integers; test negative */
1809 
1810   /* -128 */
1811   SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 8);
1812   CONVERT(3,0,NUMPRS_NEG,3,0,0, INTEGER_VTBITS); EXPECT_I1(-128);
1813   /* -129 */
1814   SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 9);
1815   CONVERT(3,0,NUMPRS_NEG,3,0,0, INTEGER_VTBITS); EXPECT_I2(-129);
1816   /* -32768 */
1817   SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 8);
1818   CONVERT(5,0,NUMPRS_NEG,5,0,0, INTEGER_VTBITS); EXPECT_I2(-32768);
1819   /* -32768 */
1820   SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 9);
1821   CONVERT(5,0,NUMPRS_NEG,5,0,0, INTEGER_VTBITS); EXPECT_I4(-32769);
1822 
1823   /* Assume the above pattern holds for remaining negative integers */
1824 
1825   /* Test hexadecimal conversions */
1826   SETRGB(0, 1); CONVERT(1,0,0,1,4,0, INTEGER_VTBITS); EXPECT_I1(0x01);
1827   /* 0x7f */
1828   SETRGB(0, 7); SETRGB(1, 0xf);
1829   CONVERT(2,0,0,2,4,0, INTEGER_VTBITS); EXPECT_I1(0x7f);
1830   SETRGB(0, 7); SETRGB(1, 0xf);
1831   CONVERT(2,0,0,2,4,0, VTBIT_DECIMAL); EXPECT_DECIMAL(0,0,0x7f);
1832   /* 0x7fff */
1833   SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
1834   CONVERT(4,0,0,4,4,0, INTEGER_VTBITS); EXPECT_I2(0x7fff);
1835   /* 0x7fffffff */
1836   SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
1837   SETRGB(4, 0xf); SETRGB(5, 0xf); SETRGB(6, 0xf); SETRGB(7, 0xf);
1838   CONVERT(8,0,0,8,4,0, INTEGER_VTBITS); EXPECT_I4(0x7fffffffL);
1839   /* 0x7fffffffffffffff (64 bits) */
1840   SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
1841   SETRGB(4, 0xf); SETRGB(5, 0xf); SETRGB(6, 0xf); SETRGB(7, 0xf);
1842   SETRGB(8, 0xf); SETRGB(9, 0xf); SETRGB(10, 0xf); SETRGB(11, 0xf);
1843   SETRGB(12, 0xf); SETRGB(13, 0xf); SETRGB(14, 0xf); SETRGB(15, 0xf);
1844   if (has_i8)
1845   {
1846     /* We cannot use INTEGER_VTBITS as WinXP and Win2003 are broken(?). They
1847        truncate the number to the smallest integer size requested:
1848        CONVERT(16,0,0,16,4,0, INTEGER_VTBITS); EXPECT_I1((signed char)0xff); */
1849     CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x7fffffff,0xffffffff);
1850   }
1851 
1852   /* Assume the above pattern holds for numbers without hi-bit set, test (preservation of) hi-bit */
1853   /* 0x82 */
1854   SETRGB(0, 8); SETRGB(1, 2);
1855   CONVERT(2,0,0,2,4,0, INTEGER_VTBITS);
1856   EXPECT_I1((signed char)0x82);
1857   /* 0x8002 */
1858   SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 2);
1859   CONVERT(4,0,0,4,4,0, INTEGER_VTBITS);
1860   EXPECT_I2((signed short)0x8002);
1861   /* 0x80000002 */
1862   SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1863   SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 2);
1864   CONVERT(8,0,0,8,4,0, INTEGER_VTBITS); EXPECT_I4(0x80000002);
1865   /* 0x8000000000000002 (64 bits) */
1866   SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1867   SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 0);
1868   SETRGB(8, 0); SETRGB(9, 0); SETRGB(10, 0); SETRGB(11, 0);
1869   SETRGB(12, 0); SETRGB(13, 0); SETRGB(14, 0); SETRGB(15, 2);
1870   if (has_i8)
1871   {
1872     /* We cannot use INTEGER_VTBITS as WinXP and Win2003 are broken(?). They
1873        truncate the number to the smallest integer size requested:
1874        CONVERT(16,0,0,16,4,0, INTEGER_VTBITS & ~VTBIT_I1);
1875        EXPECT_I2((signed short)0x0002); */
1876     CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x80000000,0x00000002);
1877   }
1878 
1879   /* Test (preservation of) hi-bit with STRICT type requesting */
1880   /* 0x82 */
1881   SETRGB(0, 8); SETRGB(1, 2);
1882   CONVERT(2,0,0,2,4,0, VTBIT_I1);
1883   EXPECT_I1((signed char)0x82);
1884   /* 0x8002 */
1885   SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 2);
1886   CONVERT(4,0,0,4,4,0, VTBIT_I2);
1887   EXPECT_I2((signed short)0x8002);
1888   /* 0x80000002 */
1889   SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1890   SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 2);
1891   CONVERT(8,0,0,8,4,0, VTBIT_I4); EXPECT_I4(0x80000002);
1892   /* 0x8000000000000002 (64 bits) */
1893   SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1894   SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 0);
1895   SETRGB(8, 0); SETRGB(9, 0); SETRGB(10, 0); SETRGB(11, 0);
1896   SETRGB(12, 0); SETRGB(13, 0); SETRGB(14, 0); SETRGB(15, 2);
1897   if (has_i8)
1898   {
1899     CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x80000000,0x00000002);
1900   }
1901   /* Assume the above pattern holds for numbers with hi-bit set */
1902 
1903   /* Negative numbers overflow if we have only unsigned outputs */
1904   /* -1 */
1905   SETRGB(0, 1); CONVERT(1,0,NUMPRS_NEG,1,0,0, VTBIT_UI1); EXPECT_OVERFLOW;
1906   /* -0.6 */
1907   SETRGB(0, 6); CONVERT(1,0,NUMPRS_NEG,1,0,~0u, VTBIT_UI1); EXPECT_OVERFLOW;
1908 
1909   /* Except that rounding is done first, so -0.5 to 0 are accepted as 0 */
1910   /* -0.5 */
1911   SETRGB(0, 5); CONVERT(1,0,NUMPRS_NEG,1,0,~0u, VTBIT_UI1); EXPECT_UI1(0);
1912 
1913   /* Floating point zero is OK */
1914   /* 0.00000000E0 */
1915   SETRGB(0, 0); CONVERT(1,0,NUMPRS_DECIMAL|NUMPRS_EXPONENT,12,0,-8, VTBIT_R8);
1916   EXPECT_R8(0.0);
1917 
1918   /* Float is acceptable for an integer input value */
1919   SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R4); EXPECT_R4(1.0f);
1920   /* As is double */
1921   SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R8); EXPECT_R8(1.0);
1922   /* As is currency */
1923   SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_CY); EXPECT_CY(1);
1924 
1925   /* Float is preferred over double */
1926   SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R4|VTBIT_R8); EXPECT_R4(1.0f);
1927 
1928   /* Double is preferred over currency */
1929   SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R8|VTBIT_CY); EXPECT_R8(1.0);
1930 
1931   /* Currency is preferred over decimal */
1932   SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_CY|VTBIT_DECIMAL); EXPECT_CY(1);
1933 }
1934 
1935 
1936 static void test_UdateFromDate( int line, DATE dt, ULONG flags, HRESULT r, WORD d, WORD m, WORD y,
1937                                 WORD h, WORD mn, WORD s, WORD ms, WORD dw, WORD dy)
1938 {
1939     UDATE ud;
1940     HRESULT res;
1941 
1942     memset(&ud, 0, sizeof(ud));
1943     res = pVarUdateFromDate(dt, flags, &ud);
1944     ok_(__FILE__,line)(r == res && (res != S_OK || (ud.st.wYear == y && ud.st.wMonth == m && ud.st.wDay == d &&
1945                        ud.st.wHour == h && ud.st.wMinute == mn && ud.st.wSecond == s &&
1946                        ud.st.wMilliseconds == ms && ud.st.wDayOfWeek == dw && ud.wDayOfYear == dy)),
1947                        "%.16g expected res(%x) %d,%d,%d,%d,%d,%d,%d  %d %d, got res(%x) %d,%d,%d,%d,%d,%d,%d  %d %d\n",
1948                        dt, r, d, m, y, h, mn, s, ms, dw, dy,
1949                        res, ud.st.wDay, ud.st.wMonth, ud.st.wYear, ud.st.wHour, ud.st.wMinute,
1950                        ud.st.wSecond, ud.st.wMilliseconds, ud.st.wDayOfWeek, ud.wDayOfYear );
1951 }
1952 #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)
1953 
1954 static void test_VarUdateFromDate(void)
1955 {
1956   CHECKPTR(VarUdateFromDate);
1957   DT2UD(29221.0,0,S_OK,1,1,1980,0,0,0,0,2,1);        /* 1 Jan 1980 */
1958   DT2UD(29222.0,0,S_OK,2,1,1980,0,0,0,0,3,2);        /* 2 Jan 1980 */
1959   DT2UD(33238.0,0,S_OK,31,12,1990,0,0,0,0,1,365);    /* 31 Dec 1990 */
1960   DT2UD(0.0,0,S_OK,30,12,1899,0,0,0,0,6,364);        /* 30 Dec 1899 - VT_DATE 0.0 */
1961   DT2UD(-657434.0,0,S_OK,1,1,100,0,0,0,0,5,1);       /* 1 Jan 100 - Min */
1962   DT2UD(-657435.0,0,E_INVALIDARG,0,0,0,0,0,0,0,0,0); /* < 1 Jan 100 => err */
1963   DT2UD(2958465.0,0,S_OK,31,12,9999,0,0,0,0,5,365);  /* 31 Dec 9999 - Max */
1964   DT2UD(2958466.0,0,E_INVALIDARG,0,0,0,0,0,0,0,0,0); /* > 31 Dec 9999 => err  */
1965 
1966   /* VAR_VALIDDATE doesn't prevent upper and lower bounds being checked */
1967   DT2UD(-657435.0,VAR_VALIDDATE,E_INVALIDARG,0,0,0,0,0,0,0,0,0);
1968   DT2UD(2958466.0,VAR_VALIDDATE,E_INVALIDARG,0,0,0,0,0,0,0,0,0);
1969 
1970   /* Times */
1971   DT2UD(29221.25,0,S_OK,1,1,1980,6,0,0,0,2,1);           /* 6 AM */
1972   DT2UD(29221.33333333,0,S_OK,1,1,1980,8,0,0,0,2,1);     /* 8 AM */
1973   DT2UD(29221.5,0,S_OK,1,1,1980,12,0,0,0,2,1);           /* 12 AM */
1974   DT2UD(29221.9888884444,0,S_OK,1,1,1980,23,44,0,0,2,1); /* 11:44 PM */
1975   DT2UD(29221.7508765432,0,S_OK,1,1,1980,18,1,16,0,2,1); /* 6:18:02 PM */
1976 
1977   /* Test handling of times on dates prior to the epoch */
1978   DT2UD(-5.25,0,S_OK,25,12,1899,6,0,0,0,1,359);
1979   DT2UD(-5.9999884259259,0,S_OK,25,12,1899,23,59,59,0,1,359);
1980   /* This just demonstrates the non-linear nature of values prior to the epoch */
1981   DT2UD(-4.0,0,S_OK,26,12,1899,0,0,0,0,2,360);
1982   /* Numerical oddity: for 0.0 < x < 1.0, x and -x represent the same datetime */
1983   DT2UD(-0.25,0,S_OK,30,12,1899,6,0,0,0,6,364);
1984   DT2UD(0.25,0,S_OK,30,12,1899,6,0,0,0,6,364);
1985 }
1986 
1987 
1988 static void test_DateFromUDate( int line, WORD d, WORD m, WORD y, WORD h, WORD mn, WORD s, WORD ms,
1989                                 WORD dw, WORD dy, ULONG flags, HRESULT r, DATE dt )
1990 {
1991     UDATE ud;
1992     double out;
1993     HRESULT res;
1994 
1995     ud.st.wYear = y;
1996     ud.st.wMonth = m;
1997     ud.st.wDay = d;
1998     ud.st.wHour = h;
1999     ud.st.wMinute = mn;
2000     ud.st.wSecond = s;
2001     ud.st.wMilliseconds = ms;
2002     ud.st.wDayOfWeek = dw;
2003     ud.wDayOfYear = dy;
2004     res = pVarDateFromUdate(&ud, flags, &out);
2005     ok_(__FILE__,line)(r == res && (r != S_OK || EQ_DOUBLE(out, dt)),
2006                        "expected %x, %.16g, got %x, %.16g\n", r, dt, res, out);
2007 }
2008 #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)
2009 
2010 static void test_VarDateFromUdate(void)
2011 {
2012   CHECKPTR(VarDateFromUdate);
2013   UD2T(1,1,1980,0,0,0,0,2,1,0,S_OK,29221.0);      /* 1 Jan 1980 */
2014   UD2T(2,1,1980,0,0,0,0,3,2,0,S_OK,29222.0);      /* 2 Jan 1980 */
2015   UD2T(2,1,1980,0,0,0,0,4,5,0,S_OK,29222.0);      /* 2 Jan 1980 */
2016   UD2T(31,12,1990,0,0,0,0,0,0,0,S_OK,33238.0);    /* 31 Dec 1990 */
2017   UD2T(31,12,90,0,0,0,0,0,0,0,S_OK,33238.0);      /* year < 100 is 1900+year! */
2018   UD2T(30,12,1899,0,0,0,0,6,364,0,S_OK,0.0);      /* 30 Dec 1899 - VT_DATE 0.0 */
2019   UD2T(1,1,100,0,0,0,0,0,0,0,S_OK,-657434.0);     /* 1 Jan 100 - Min */
2020   UD2T(31,12,9999,0,0,0,0,0,0,0,S_OK,2958465.0);  /* 31 Dec 9999 - Max */
2021   UD2T(1,1,10000,0,0,0,0,0,0,0,E_INVALIDARG,0.0); /* > 31 Dec 9999 => err  */
2022   UD2T(1,1,-10000,0,0,0,0,0,0,0,E_INVALIDARG,0.0);/* < -9999 => err  */
2023 
2024   UD2T(30,12,1899,0,0,0,0,0,0,0,S_OK,0.0); /* 30 Dec 1899 0:00:00  */
2025   UD2T(30,12,1899,0,0,0,999,0,0,0,S_OK,0.0); /* Ignore milliseconds  */
2026 
2027   UD2T(1,1,1980,18,1,16,0,2,1,0,S_OK,29221.75087962963);             /* 6:18:02 PM */
2028   UD2T(1,300,1980,18,1,16,0,2,1,0,S_OK,38322.75087962963);           /* Test fwdrolled month */
2029   UD2T(300,1,1980,18,1,16,0,2,1,0,S_OK,29520.75087962963);           /* Test fwdrolled days */
2030   UD2T(0,1,1980,42,1,16,0,2,1,0,S_OK,29221.75087962963);             /* Test fwdrolled hours */
2031   UD2T(1,1,1980,17,61,16,0,2,1,0,S_OK,29221.75087962963);            /* Test fwdrolled minutes */
2032   UD2T(1,1,1980,18,0,76,0,2,1,0,S_OK,29221.75087962963);             /* Test fwdrolled seconds */
2033   UD2T(1,-300,1980,18,1,16,0,2,1,0,S_OK,20059.75087962963);          /* Test backrolled month */
2034   UD2T(-300,1,1980,18,1,16,0,2,1,0,S_OK,28920.75087962963);          /* Test backrolled days */
2035   UD2T(3,1,1980,-30,1,16,0,2,1,0,S_OK,29221.75087962963);            /* Test backrolled hours */
2036   UD2T(1,1,1980,20,-119,16,0,2,1,0,S_OK,29221.75087962963);          /* Test backrolled minutes */
2037   UD2T(1,1,1980,18,3,-104,0,2,1,0,S_OK,29221.75087962963);           /* Test backrolled seconds */
2038   UD2T(1,12001,-1020,18,1,16,0,0,0,0,S_OK,29221.75087962963);        /* Test rolled year and month */
2039   UD2T(1,-23,1982,18,1,16,0,0,0,0,S_OK,29221.75087962963);           /* Test backrolled month */
2040   UD2T(-59,3,1980,18,1,16,0,0,0,0,S_OK,29221.75087962963);           /* Test backrolled days */
2041   UD2T(1,1,0,0,0,0,0,0,0,0,S_OK,36526);                              /* Test zero year */
2042   UD2T(0,0,1980,0,0,0,0,0,0,0,S_OK,29189);                           /* Test zero day and month */
2043   UD2T(0,1,1980,0,0,0,0,2,1,0,S_OK,29220.0);                         /* Test zero day = LastDayOfMonth */
2044   UD2T(-1,1,1980,18,1,16,0,0,0,0,S_OK,29219.75087962963);            /* Test day -1 = LastDayOfMonth - 1 */
2045   UD2T(1,1,-1,18,1,16,0,0,0,0,S_OK,36161.75087962963);               /* Test year -1 = 1999 */
2046   UD2T(1,-1,1980,18,1,16,0,0,0,0,S_OK,29160.7508796296);             /* Test month -1 = 11 */
2047   UD2T(1,13,1980,0,0,0,0,2,1,0,S_OK,29587.0);                        /* Rolls fwd to 1/1/1981 */
2048 
2049   /* Test handling of times on dates prior to the epoch */
2050   UD2T(25,12,1899,6,0,0,0,1,359,0,S_OK,-5.25);
2051   UD2T(25,12,1899,23,59,59,0,1,359,0,S_OK,-5.9999884259259);
2052   /* This just demonstrates the non-linear nature of values prior to the epoch */
2053   UD2T(26,12,1899,0,0,0,0,2,360,0,S_OK,-4.0);
2054   /* for DATE values 0.0 < x < 1.0, x and -x represent the same datetime */
2055   /* but when converting to DATE, prefer the positive versions */
2056   UD2T(30,12,1899,6,0,0,0,6,364,0,S_OK,0.25);
2057 
2058   UD2T(1,1,1980,18,1,16,0,2,1,VAR_TIMEVALUEONLY,S_OK,0.7508796296296296);
2059   UD2T(1,1,1980,18,1,16,0,2,1,VAR_DATEVALUEONLY,S_OK,29221.0);
2060   UD2T(25,12,1899,6,0,0,0,1,359,VAR_TIMEVALUEONLY,S_OK,0.25);
2061   UD2T(25,12,1899,6,0,0,0,1,359,VAR_DATEVALUEONLY,S_OK,-5.0);
2062   UD2T(1,-1,1980,18,1,16,0,0,0,VAR_TIMEVALUEONLY|VAR_DATEVALUEONLY,S_OK,0.7508796296296296);
2063 }
2064 
2065 static void test_st2dt(int line, WORD d, WORD m, WORD y, WORD h, WORD mn,
2066                        WORD s, WORD ms, INT r, double dt)
2067 {
2068     SYSTEMTIME st;
2069     double out;
2070     INT res;
2071 
2072     st.wYear = y;
2073     st.wMonth = m;
2074     st.wDay = d;
2075     st.wHour = h;
2076     st.wMinute = mn;
2077     st.wSecond = s;
2078     st.wMilliseconds = ms;
2079     st.wDayOfWeek = 0;
2080     res = pSystemTimeToVariantTime(&st, &out);
2081     ok_(__FILE__,line)(r == res && (!r || EQ_DOUBLE(out, dt)),
2082                        "expected %d, %.16g, got %d, %.16g\n", r, dt, res, out);
2083 }
2084 #define ST2DT(d,m,y,h,mn,s,ms,r,dt) test_st2dt(__LINE__,d,m,y,h,mn,s,ms,r,dt)
2085 
2086 static void test_SystemTimeToVariantTime(void)
2087 {
2088   CHECKPTR(SystemTimeToVariantTime);
2089   ST2DT(1,1,1980,0,0,0,0,TRUE,29221.0);
2090   ST2DT(2,1,1980,0,0,0,0,TRUE,29222.0);
2091   ST2DT(0,1,1980,0,0,0,0,TRUE,29220.0);   /* Rolls back to 31 Dec 1899 */
2092   ST2DT(1,13,1980,0,0,0,0,FALSE,29587.0); /* Fails on invalid month */
2093   ST2DT(32,1,1980,0,0,0,0,FALSE,0.0);     /* Fails on invalid day */
2094   ST2DT(1,1,-1,0,0,0,0,FALSE,0.0);        /* Fails on invalid year */
2095   ST2DT(1,1,10000,0,0,0,0,FALSE,0.0);     /* Fails on invalid year */
2096   ST2DT(1,1,9999,0,0,0,0,TRUE,2958101.0); /* 9999 is last valid year */
2097   ST2DT(31,12,90,0,0,0,0,TRUE,33238.0);   /* 30 <= year < 100 is 1900+year */
2098   ST2DT(1,1,30,0,0,0,0,TRUE,10959.0);     /* 30 <= year < 100 is 1900+year */
2099   ST2DT(1,1,29,0,0,0,0,TRUE,47119.0);     /* 0 <= year < 30 is 2000+year */
2100   ST2DT(1,1,0,0,0,0,0,TRUE,36526.0);      /* 0 <= year < 30 is 2000+year */
2101 }
2102 
2103 static void test_dt2st(int line, double dt, INT r, WORD d, WORD m, WORD y,
2104                        WORD h, WORD mn, WORD s, WORD ms)
2105 {
2106   SYSTEMTIME st;
2107   INT res;
2108 
2109   memset(&st, 0, sizeof(st));
2110   res = pVariantTimeToSystemTime(dt, &st);
2111   ok_(__FILE__,line)(r == res &&
2112                      (!r || (st.wYear == y && st.wMonth == m && st.wDay == d &&
2113                              st.wHour == h && st.wMinute == mn &&
2114                              st.wSecond == s && st.wMilliseconds == ms)),
2115                      "%.16g expected %d, %d,%d,%d,%d,%d,%d,%d, got %d, %d,%d,%d,%d,%d,%d,%d\n",
2116                      dt, r, d, m, y, h, mn, s, ms, res, st.wDay, st.wMonth,
2117                      st.wYear, st.wHour, st.wMinute, st.wSecond,
2118                      st.wMilliseconds);
2119 }
2120 #define DT2ST(dt,r,d,m,y,h,mn,s,ms) test_dt2st(__LINE__,dt,r,d,m,y,h,mn,s,ms)
2121 
2122 static void test_VariantTimeToSystemTime(void)
2123 {
2124   CHECKPTR(VariantTimeToSystemTime);
2125   DT2ST(29221.0,1,1,1,1980,0,0,0,0);
2126   DT2ST(29222.0,1,2,1,1980,0,0,0,0);
2127 }
2128 
2129 #define MKDOSDATE(d,m,y) ((d & 0x1f) | ((m & 0xf) << 5) | (((y-1980) & 0x7f) << 9))
2130 #define MKDOSTIME(h,m,s) (((s>>1) & 0x1f) | ((m & 0x3f) << 5) | ((h & 0x1f) << 11))
2131 
2132 static void test_dos2dt(int line, WORD d, WORD m, WORD y, WORD h, WORD mn,
2133                         WORD s, INT r, double dt)
2134 {
2135     unsigned short dosDate, dosTime;
2136     double out;
2137     INT res;
2138 
2139     out = 0.0;
2140     dosDate = MKDOSDATE(d, m, y);
2141     dosTime = MKDOSTIME(h, mn, s);
2142     res = pDosDateTimeToVariantTime(dosDate, dosTime, &out);
2143     ok_(__FILE__,line)(r == res && (!r || EQ_DOUBLE(out, dt)),
2144                        "expected %d, %.16g, got %d, %.16g\n", r, dt, res, out);
2145 }
2146 #define DOS2DT(d,m,y,h,mn,s,r,dt) test_dos2dt(__LINE__,d,m,y,h,mn,s,r,dt)
2147 
2148 static void test_DosDateTimeToVariantTime(void)
2149 {
2150   CHECKPTR(DosDateTimeToVariantTime);
2151 
2152   /* Date */
2153   DOS2DT(1,1,1980,0,0,0,1,29221.0); /* 1/1/1980 */
2154   DOS2DT(31,12,2099,0,0,0,1,73050.0); /* 31/12/2099 */
2155   /* Dates are limited to the dos date max of 31/12/2099 */
2156   DOS2DT(31,12,2100,0,0,0,0,0.0); /* 31/12/2100 */
2157   /* Days and months of 0 cause date to roll back 1 day or month */
2158   DOS2DT(0,1,1980,0,0,0,1,29220.0); /* 0 Day => 31/12/1979 */
2159   DOS2DT(1,0,1980,0,0,0,1,29190.0); /* 0 Mth =>  1/12/1979 */
2160   DOS2DT(0,0,1980,0,0,0,1,29189.0); /* 0 D/M => 30/11/1979 */
2161   /* Days > days in the month cause date to roll forward 1 month */
2162   DOS2DT(29,2,1981,0,0,0,1,29646.0); /* 29/2/1981 -> 3/1/1980 */
2163   DOS2DT(30,2,1981,0,0,0,1,29647.0); /* 30/2/1981 -> 4/1/1980 */
2164   /* Takes leap years into account when rolling forward */
2165   DOS2DT(29,2,1980,0,0,0,1,29280.0); /* 2/29/1980 */
2166   /* Months > 12 cause an error */
2167   DOS2DT(2,13,1980,0,0,0,0,0.0);
2168 
2169   /* Time */
2170   DOS2DT(1,1,1980,0,0,29,1,29221.00032407407); /* 1/1/1980 12:00:28 AM */
2171   DOS2DT(1,1,1980,0,0,31,1,29221.00034722222); /* 1/1/1980 12:00:30 AM */
2172   DOS2DT(1,1,1980,0,59,0,1,29221.04097222222); /* 1/1/1980 12:59:00 AM */
2173   DOS2DT(1,1,1980,0,60,0,0,0.0);               /* Invalid minutes */
2174   DOS2DT(1,1,1980,0,0,60,0,0.0);               /* Invalid seconds */
2175   DOS2DT(1,1,1980,23,0,0,1,29221.95833333333); /* 1/1/1980 11:00:00 PM */
2176   DOS2DT(1,1,1980,24,0,0,0,0.0);               /* Invalid hours */
2177 
2178   DOS2DT(1,1,1980,0,0,1,1,29221.0);
2179   DOS2DT(2,1,1980,0,0,0,1,29222.0);
2180   DOS2DT(2,1,1980,0,0,0,1,29222.0);
2181   DOS2DT(31,12,1990,0,0,0,1,33238.0);
2182   DOS2DT(31,12,90,0,0,0,1,40543.0);
2183   DOS2DT(30,12,1899,0,0,0,1,46751.0);
2184   DOS2DT(1,1,100,0,0,0,1,43831.0);
2185   DOS2DT(31,12,9999,0,0,0,1,59901.0);
2186   DOS2DT(1,1,10000,0,0,0,1,59902.0);
2187   DOS2DT(1,1,-10000,0,0,0,1,48214.0);
2188 
2189   DOS2DT(30,12,1899,0,0,0,1,46751.0);
2190   DOS2DT(30,12,1899,0,0,1,1,46751.0);
2191 
2192   DOS2DT(1,1,1980,18,1,16,1,29221.75087962963);
2193   DOS2DT(1,300,1980,18,1,16,1,29556.75087962963);
2194   DOS2DT(300,1,1980,18,1,16,1,29232.75087962963);
2195   DOS2DT(0,1,1980,42,1,16,1,29220.4175462963);
2196   DOS2DT(1,1,1980,17,61,16,0,0.0);
2197   DOS2DT(1,1,1980,18,0,76,1,29221.75013888889);
2198   DOS2DT(1,-300,1980,18,1,16,1,29312.75087962963);
2199   DOS2DT(-300,1,1980,18,1,16,1,29240.75087962963);
2200   DOS2DT(3,1,1980,-30,1,16,1,29223.08421296296);
2201   DOS2DT(1,1,1980,20,-119,16,1,29221.83976851852);
2202   DOS2DT(1,1,1980,18,3,-104,1,29221.75236111111);
2203   DOS2DT(1,12001,-1020,18,1,16,1,55519.75087962963);
2204   DOS2DT(1,-23,1982,18,1,16,1,30195.75087962963);
2205   DOS2DT(-59,3,1980,18,1,16,1,29285.75087962963);
2206   DOS2DT(1,1,0,0,0,0,1,54058.0);
2207   DOS2DT(0,0,1980,0,0,0,1,29189.0);
2208   DOS2DT(0,1,1980,0,0,0,1,29220.0);
2209   DOS2DT(-1,1,1980,18,1,16,1,29251.75087962963);
2210   DOS2DT(1,1,-1,18,1,16,1,53693.75087962963);
2211   DOS2DT(1,-1,1980,18,1,16,0,0);
2212 }
2213 
2214 static void test_dt2dos(int line, double dt, INT r, WORD d, WORD m, WORD y,
2215                         WORD h, WORD mn, WORD s)
2216 {
2217     unsigned short dosDate, dosTime, expDosDate, expDosTime;
2218     INT res;
2219 
2220     dosTime = dosDate = 0;
2221     expDosDate = MKDOSDATE(d,m,y);
2222     expDosTime = MKDOSTIME(h,mn,s);
2223     res = pVariantTimeToDosDateTime(dt, &dosDate, &dosTime);
2224     ok_(__FILE__,line)(r == res && (!r || (dosTime == expDosTime && dosDate == expDosDate)),
2225                        "%g: expected %d,%d(%d/%d/%d),%d(%d:%d:%d) got %d,%d(%d/%d/%d),%d(%d:%d:%d)\n",
2226                        dt, r, expDosDate, expDosDate & 0x1f,
2227                        (expDosDate >> 5) & 0xf, 1980 + (expDosDate >> 9),
2228                        expDosTime, expDosTime >> 11, (expDosTime >> 5) & 0x3f,
2229                        (expDosTime & 0x1f),
2230                        res, dosDate, dosDate & 0x1f, (dosDate >> 5) & 0xf,
2231                        1980 + (dosDate >> 9), dosTime, dosTime >> 11,
2232                        (dosTime >> 5) & 0x3f, (dosTime & 0x1f));
2233 }
2234 #define DT2DOS(dt,r,d,m,y,h,mn,s) test_dt2dos(__LINE__,dt,r,d,m,y,h,mn,s)
2235 
2236 static void test_VariantTimeToDosDateTime(void)
2237 {
2238   CHECKPTR(VariantTimeToDosDateTime);
2239 
2240   /* Date */
2241   DT2DOS(29221.0,1,1,1,1980,0,0,0);   /* 1/1/1980 */
2242   DT2DOS(73050.0,1,31,12,2099,0,0,0); /* 31/12/2099 */
2243   DT2DOS(29220.0,0,0,0,0,0,0,0);      /* 31/12/1979 - out of range */
2244   DT2DOS(73415.0,0,0,0,0,0,0,0);      /* 31/12/2100 - out of range */
2245 
2246   /* Time */
2247   DT2DOS(29221.00032407407,1,1,1,1980,0,0,29); /* 1/1/1980 12:00:28 AM */
2248   DT2DOS(29221.00034722222,1,1,1,1980,0,0,31); /* 1/1/1980 12:00:30 AM */
2249   DT2DOS(29221.04097222222,1,1,1,1980,0,59,0); /* 1/1/1980 12:59:00 AM */
2250   DT2DOS(29221.95833333333,1,1,1,1980,23,0,0); /* 1/1/1980 11:00:00 PM */
2251 }
2252 
2253 static HRESULT (WINAPI *pVarAbs)(LPVARIANT,LPVARIANT);
2254 
2255 #define VARABS(vt,val,rvt,rval)                  \
2256     V_VT(&v) = VT_##vt; V_##vt(&v) = val;        \
2257     V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
2258     test_var_call1( __LINE__, pVarAbs, &v, &exp )
2259 
2260 static void test_VarAbs(void)
2261 {
2262     static WCHAR szNum[] = {'-','1','.','1','\0' };
2263     char buff[8];
2264     HRESULT hres;
2265     VARIANT v, vDst, exp;
2266     size_t i;
2267 
2268     CHECKPTR(VarAbs);
2269 
2270     /* Test all possible V_VT values.
2271      */
2272     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2273     {
2274         VARTYPE vt;
2275 
2276         for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2277         {
2278             HRESULT hExpected = DISP_E_BADVARTYPE;
2279 
2280             SKIPTESTS(vt);
2281 
2282             memset(&v, 0, sizeof(v));
2283             V_VT(&v) = vt | ExtraFlags[i];
2284             V_VT(&vDst) = VT_EMPTY;
2285 
2286             hres = pVarAbs(&v,&vDst);
2287             if (ExtraFlags[i] & VT_ARRAY ||
2288                 (!ExtraFlags[i] && (vt == VT_UNKNOWN || vt == VT_BSTR ||
2289                  vt == VT_DISPATCH || vt == VT_ERROR || vt == VT_RECORD)))
2290             {
2291                 hExpected = DISP_E_TYPEMISMATCH;
2292             }
2293             else if (ExtraFlags[i] || vt >= VT_CLSID || vt == VT_VARIANT)
2294             {
2295                 hExpected = DISP_E_BADVARTYPE;
2296             }
2297             else if (IsValidVariantClearVT(vt, ExtraFlags[i]))
2298                 hExpected = S_OK;
2299 
2300             /* Native always fails on some vartypes that should be valid. don't
2301              * check that Wine does the same; these are bugs in native.
2302              */
2303             if (vt == VT_I8 || vt == VT_UI8 || vt == VT_INT || vt == VT_UINT ||
2304                 vt == VT_I1 || vt == VT_UI2 || vt == VT_UI4)
2305                 continue;
2306             ok(hres == hExpected, "VarAbs: expected 0x%X, got 0x%X for vt %d | 0x%X\n",
2307                hExpected, hres, vt, ExtraFlags[i]);
2308         }
2309     }
2310 
2311     /* BOOL->I2, BSTR->R8, all others remain the same */
2312     VARABS(BOOL,VARIANT_TRUE,I2,-VARIANT_TRUE);
2313     VARABS(BOOL,VARIANT_FALSE,I2,VARIANT_FALSE);
2314     VARABS(EMPTY,0,I2,0);
2315     VARABS(EMPTY,1,I2,0);
2316     VARABS(NULL,0,NULL,0);
2317     VARABS(NULL,1,NULL,0);
2318     VARABS(I2,1,I2,1);
2319     VARABS(I2,-1,I2,1);
2320     VARABS(I4,1,I4,1);
2321     VARABS(I4,-1,I4,1);
2322     VARABS(UI1,1,UI1,1);
2323     VARABS(R4,1,R4,1);
2324     VARABS(R4,-1,R4,1);
2325     VARABS(R8,1,R8,1);
2326     VARABS(R8,-1,R8,1);
2327     VARABS(DATE,1,DATE,1);
2328     VARABS(DATE,-1,DATE,1);
2329     V_VT(&v) = VT_CY;
2330     V_CY(&v).int64 = -10000;
2331     memset(&vDst,0,sizeof(vDst));
2332     hres = pVarAbs(&v,&vDst);
2333     ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
2334        "VarAbs(CY): expected 0x0 got 0x%X\n", hres);
2335     GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char));
2336     if (buff[1])
2337     {
2338         trace("Skipping VarAbs(BSTR) as decimal separator is '%s'\n", buff);
2339         return;
2340     } else {
2341 	szNum[2] = buff[0];
2342     }
2343     V_VT(&v) = VT_BSTR;
2344     V_BSTR(&v) = (BSTR)szNum;
2345     memset(&vDst,0,sizeof(vDst));
2346     hres = pVarAbs(&v,&vDst);
2347     ok(hres == S_OK && V_VT(&vDst) == VT_R8 && V_R8(&vDst) == 1.1,
2348        "VarAbs: expected 0x0,%d,%g, got 0x%X,%d,%g\n", VT_R8, 1.1, hres, V_VT(&vDst), V_R8(&vDst));
2349 }
2350 
2351 static HRESULT (WINAPI *pVarNot)(LPVARIANT,LPVARIANT);
2352 
2353 #define VARNOT(vt,val,rvt,rval)                  \
2354     V_VT(&v) = VT_##vt; V_##vt(&v) = val;        \
2355     V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
2356     test_var_call1( __LINE__, pVarNot, &v, &exp )
2357 
2358 static void test_VarNot(void)
2359 {
2360     static const WCHAR szNum0[] = {'0','\0' };
2361     static const WCHAR szNum1[] = {'1','\0' };
2362     static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
2363     static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
2364     HRESULT hres;
2365     VARIANT v, exp, vDst;
2366     DECIMAL *pdec = &V_DECIMAL(&v);
2367     CY *pcy = &V_CY(&v);
2368     size_t i;
2369 
2370     CHECKPTR(VarNot);
2371 
2372     /* Test all possible V_VT values */
2373     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2374     {
2375         VARTYPE vt;
2376 
2377         for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2378         {
2379             HRESULT hExpected = DISP_E_BADVARTYPE;
2380 
2381             SKIPTESTS(vt);
2382 
2383             memset(&v, 0, sizeof(v));
2384             V_VT(&v) = vt | ExtraFlags[i];
2385             V_VT(&vDst) = VT_EMPTY;
2386 
2387             switch (V_VT(&v))
2388             {
2389             case VT_I1:  case VT_UI1: case VT_I2:  case VT_UI2:
2390             case VT_INT: case VT_UINT: case VT_I4:  case VT_UI4:
2391             case VT_R4:  case VT_R8:
2392             case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
2393             case VT_DATE: case VT_CY:
2394                 hExpected = S_OK;
2395                 break;
2396             case VT_I8: case VT_UI8:
2397                 if (has_i8)
2398                     hExpected = S_OK;
2399                 break;
2400             case VT_RECORD:
2401                 hExpected = DISP_E_TYPEMISMATCH;
2402                 break;
2403             case VT_UNKNOWN: case VT_BSTR: case VT_DISPATCH: case VT_ERROR:
2404                 hExpected = DISP_E_TYPEMISMATCH;
2405                 break;
2406             default:
2407                 if (IsValidVariantClearVT(vt, ExtraFlags[i]) && vt != VT_CLSID)
2408                    hExpected = DISP_E_TYPEMISMATCH;
2409                 break;
2410             }
2411 
2412             hres = pVarNot(&v,&vDst);
2413             ok(hres == hExpected, "VarNot: expected 0x%X, got 0x%X vt %d|0x%X\n",
2414                hExpected, hres, vt, ExtraFlags[i]);
2415         }
2416     }
2417     /* Test the values returned by all cases that can succeed */
2418     VARNOT(EMPTY,0,I2,-1);
2419     VARNOT(EMPTY,1,I2,-1);
2420     VARNOT(NULL,0,NULL,0);
2421     VARNOT(NULL,1,NULL,0);
2422     VARNOT(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
2423     VARNOT(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
2424     VARNOT(I1,-1,I4,0);
2425     VARNOT(I1,0,I4,-1);
2426     VARNOT(I2,-1,I2,0);
2427     VARNOT(I2,0,I2,-1);
2428     VARNOT(I2,1,I2,-2);
2429     VARNOT(I4,1,I4,-2);
2430     VARNOT(I4,0,I4,-1);
2431     VARNOT(UI1,1,UI1,254);
2432     VARNOT(UI1,0,UI1,255);
2433     VARNOT(UI2,0,I4,-1);
2434     VARNOT(UI2,1,I4,-2);
2435     VARNOT(UI4,0,I4,-1);
2436     VARNOT(UI4,1,I4,-2);
2437     VARNOT(INT,0,I4,-1);
2438     VARNOT(INT,1,I4,-2);
2439     VARNOT(UINT,0,I4,-1);
2440     VARNOT(UINT,1,I4,-2);
2441     if (has_i8)
2442     {
2443         VARNOT(I8,1,I8,-2);
2444         VARNOT(I8,0,I8,-1);
2445         VARNOT(UI8,0,I4,-1);
2446         VARNOT(UI8,1,I4,-2);
2447     }
2448     VARNOT(R4,1,I4,-2);
2449     VARNOT(R4,0,I4,-1);
2450     VARNOT(R8,1,I4,-2);
2451     VARNOT(R8,0,I4,-1);
2452     VARNOT(DATE,1,I4,-2);
2453     VARNOT(DATE,0,I4,-1);
2454     VARNOT(BSTR,(BSTR)szNum0,I4,-1);
2455     ok(V_VT(&v) == VT_BSTR && V_BSTR(&v) == szNum0, "VarNot(0): changed input\n");
2456     VARNOT(BSTR,(BSTR)szNum1,I4,-2);
2457     ok(V_VT(&v) == VT_BSTR && V_BSTR(&v) == szNum1, "VarNot(1): changed input\n");
2458     VARNOT(BSTR, (BSTR)szTrue, BOOL, VARIANT_FALSE);
2459     VARNOT(BSTR, (BSTR)szFalse, BOOL, VARIANT_TRUE);
2460 
2461     S(U(*pdec)).sign = DECIMAL_NEG;
2462     S(U(*pdec)).scale = 0;
2463     pdec->Hi32 = 0;
2464     S1(U1(*pdec)).Mid32 = 0;
2465     S1(U1(*pdec)).Lo32 = 1;
2466     VARNOT(DECIMAL,*pdec,I4,0);
2467 
2468     pcy->int64 = 10000;
2469     VARNOT(CY,*pcy,I4,-2);
2470 
2471     pcy->int64 = 0;
2472     VARNOT(CY,*pcy,I4,-1);
2473 
2474     pcy->int64 = -1;
2475     VARNOT(CY,*pcy,I4,-1);
2476 }
2477 
2478 static HRESULT (WINAPI *pVarSub)(LPVARIANT,LPVARIANT,LPVARIANT);
2479 
2480 #define VARSUB(vt1,val1,vt2,val2,rvt,rval)               \
2481         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
2482         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
2483         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
2484         test_var_call2( __LINE__, pVarSub, &left, &right, &exp )
2485 
2486 static void test_VarSub(void)
2487 {
2488     VARIANT left, right, exp, result, cy, dec;
2489     VARTYPE i;
2490     BSTR lbstr, rbstr;
2491     HRESULT hres, expectedhres;
2492     double r;
2493 
2494     CHECKPTR(VarSub);
2495 
2496     lbstr = SysAllocString(sz12);
2497     rbstr = SysAllocString(sz12);
2498 
2499     VariantInit(&left);
2500     VariantInit(&right);
2501     VariantInit(&result);
2502 
2503     /* Test all possible flag/vt combinations & the resulting vt type */
2504     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2505     {
2506 
2507         VARTYPE leftvt, rightvt, resvt;
2508 
2509         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
2510         {
2511 
2512             SKIPTESTS(leftvt);
2513 
2514             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
2515             {
2516 
2517                 SKIPTESTS(rightvt);
2518                 expectedhres = S_OK;
2519 
2520                 memset(&left, 0, sizeof(left));
2521                 memset(&right, 0, sizeof(right));
2522                 V_VT(&left) = leftvt | ExtraFlags[i];
2523                 if (leftvt == VT_BSTR)
2524                     V_BSTR(&left) = lbstr;
2525                 V_VT(&right) = rightvt | ExtraFlags[i];
2526                 if (rightvt == VT_BSTR)
2527                     V_BSTR(&right) = rbstr;
2528                 V_VT(&result) = VT_EMPTY;
2529 
2530                 /* All extra flags produce errors */
2531                 if (ExtraFlags[i] == (VT_VECTOR|VT_BYREF|VT_RESERVED) ||
2532                     ExtraFlags[i] == (VT_VECTOR|VT_RESERVED) ||
2533                     ExtraFlags[i] == (VT_VECTOR|VT_BYREF) ||
2534                     ExtraFlags[i] == (VT_BYREF|VT_RESERVED) ||
2535                     ExtraFlags[i] == VT_VECTOR ||
2536                     ExtraFlags[i] == VT_BYREF ||
2537                     ExtraFlags[i] == VT_RESERVED)
2538                 {
2539                     expectedhres = DISP_E_BADVARTYPE;
2540                     resvt = VT_EMPTY;
2541                 }
2542                 else if (ExtraFlags[i] >= VT_ARRAY)
2543                 {
2544                     expectedhres = DISP_E_TYPEMISMATCH;
2545                     resvt = VT_EMPTY;
2546                 }
2547                 /* Native VarSub cannot handle: VT_I1, VT_UI2, VT_UI4,
2548                    VT_INT, VT_UINT and VT_UI8. Tested with WinXP */
2549                 else if (!IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
2550                     !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
2551                     leftvt == VT_CLSID || rightvt == VT_CLSID ||
2552                     leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
2553                     leftvt == VT_I1 || rightvt == VT_I1 ||
2554                     leftvt == VT_UI2 || rightvt == VT_UI2 ||
2555                     leftvt == VT_UI4 || rightvt == VT_UI4 ||
2556                     leftvt == VT_UI8 || rightvt == VT_UI8 ||
2557                     leftvt == VT_INT || rightvt == VT_INT ||
2558                     leftvt == VT_UINT || rightvt == VT_UINT ||
2559                     leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN ||
2560                     leftvt == VT_RECORD || rightvt == VT_RECORD)
2561                 {
2562                     if (leftvt == VT_RECORD && rightvt == VT_I8)
2563                     {
2564                         if (has_i8)
2565                             expectedhres = DISP_E_TYPEMISMATCH;
2566                         else
2567                             expectedhres = DISP_E_BADVARTYPE;
2568                     }
2569                     else if (leftvt < VT_UI1 && rightvt == VT_RECORD)
2570                         expectedhres = DISP_E_TYPEMISMATCH;
2571                     else if (leftvt >= VT_UI1 && rightvt == VT_RECORD)
2572                         expectedhres = DISP_E_TYPEMISMATCH;
2573                     else if (leftvt == VT_RECORD && rightvt <= VT_UI1)
2574                         expectedhres = DISP_E_TYPEMISMATCH;
2575                     else if (leftvt == VT_RECORD && rightvt > VT_UI1)
2576                         expectedhres = DISP_E_BADVARTYPE;
2577                     else
2578                         expectedhres = DISP_E_BADVARTYPE;
2579                     resvt = VT_EMPTY;
2580                 }
2581                 else if ((leftvt == VT_NULL && rightvt == VT_DISPATCH) ||
2582                     (leftvt == VT_DISPATCH && rightvt == VT_NULL))
2583                     resvt = VT_NULL;
2584                 else if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
2585                     leftvt == VT_ERROR || rightvt == VT_ERROR)
2586                 {
2587                     resvt = VT_EMPTY;
2588                     expectedhres = DISP_E_TYPEMISMATCH;
2589                 }
2590                 else if (leftvt == VT_NULL || rightvt == VT_NULL)
2591                     resvt = VT_NULL;
2592                 else if ((leftvt == VT_EMPTY && rightvt == VT_BSTR) ||
2593                     (leftvt == VT_DATE && rightvt == VT_DATE) ||
2594                     (leftvt == VT_BSTR && rightvt == VT_EMPTY) ||
2595                     (leftvt == VT_BSTR && rightvt == VT_BSTR))
2596                     resvt = VT_R8;
2597                 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
2598                     resvt = VT_DECIMAL;
2599                 else if (leftvt == VT_DATE || rightvt == VT_DATE)
2600                     resvt = VT_DATE;
2601                 else if (leftvt == VT_CY || rightvt == VT_CY)
2602                     resvt = VT_CY;
2603                 else if (leftvt == VT_R8 || rightvt == VT_R8)
2604                     resvt = VT_R8;
2605                 else if (leftvt == VT_BSTR || rightvt == VT_BSTR) {
2606                     resvt = VT_R8;
2607                 } else if (leftvt == VT_R4 || rightvt == VT_R4) {
2608                     if (leftvt == VT_I4 || rightvt == VT_I4 ||
2609                         leftvt == VT_I8 || rightvt == VT_I8)
2610                         resvt = VT_R8;
2611                     else
2612                         resvt = VT_R4;
2613                 }
2614                 else if (leftvt == VT_I8 || rightvt == VT_I8)
2615                     resvt = VT_I8;
2616                 else if (leftvt == VT_I4 || rightvt == VT_I4)
2617                     resvt = VT_I4;
2618                 else if (leftvt == VT_I2 || rightvt == VT_I2 ||
2619                     leftvt == VT_BOOL || rightvt == VT_BOOL ||
2620                     (leftvt == VT_EMPTY && rightvt == VT_EMPTY))
2621                     resvt = VT_I2;
2622                 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
2623                     resvt = VT_UI1;
2624                 else
2625                 {
2626                     resvt = VT_EMPTY;
2627                     expectedhres = DISP_E_TYPEMISMATCH;
2628                 }
2629 
2630                 hres = pVarSub(&left, &right, &result);
2631 
2632                 ok(hres == expectedhres && V_VT(&result) == resvt,
2633                     "VarSub: %d|0x%X, %d|0x%X: Expected failure 0x%X, "
2634                     "got 0x%X, expected vt %d got vt %d\n",
2635                     leftvt, ExtraFlags[i], rightvt, ExtraFlags[i],
2636                     expectedhres, hres, resvt, V_VT(&result));
2637             }
2638         }
2639     }
2640 
2641     /* Test returned values */
2642     VARSUB(I4,4,I4,2,I4,2);
2643     VARSUB(I2,4,I2,2,I2,2);
2644     VARSUB(I2,-13,I4,5,I4,-18);
2645     VARSUB(I4,-13,I4,5,I4,-18);
2646     VARSUB(I2,7,R4,0.5f,R4,6.5f);
2647     VARSUB(R4,0.5f,I4,5,R8,-4.5);
2648     VARSUB(R8,7.1,BOOL,0,R8,7.1);
2649     VARSUB(BSTR,lbstr,I2,4,R8,8);
2650     VARSUB(BSTR,lbstr,BOOL,1,R8,11);
2651     VARSUB(BSTR,lbstr,R4,0.1f,R8,11.9);
2652     VARSUB(R4,0.2f,BSTR,rbstr,R8,-11.8);
2653     VARSUB(DATE,2.25,I4,7,DATE,-4.75);
2654     VARSUB(DATE,1.25,R4,-1.7f,DATE,2.95);
2655 
2656     VARSUB(UI1, UI1_MAX, UI1, UI1_MAX, UI1, 0);
2657     VARSUB(I2, I2_MAX, I2, I2_MAX, I2, 0);
2658     VARSUB(I2, I2_MIN, I2, I2_MIN, I2, 0);
2659     VARSUB(I4, I4_MAX, I4, I4_MAX, I4, 0);
2660     VARSUB(I4, I4_MIN, I4, I4_MIN, I4, 0);
2661     VARSUB(R4, R4_MAX, R4, R4_MAX, R4, 0.0f);
2662     VARSUB(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX - R4_MIN);
2663     VARSUB(R4, R4_MIN, R4, R4_MIN, R4, 0.0f);
2664     VARSUB(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX - R8_MIN);
2665     VARSUB(R8, R8_MIN, R8, R8_MIN, R8, 0.0);
2666 
2667     /* Manually test BSTR + BSTR */
2668     V_VT(&left) = VT_BSTR;
2669     V_BSTR(&left) = lbstr;
2670     V_VT(&right) = VT_BSTR;
2671     V_BSTR(&right) = rbstr;
2672     hres = pVarSub(&left, &right, &result);
2673     ok(hres == S_OK && V_VT(&result) == VT_R8,
2674         "VarSub: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
2675     ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 0.0),
2676         "VarSub: BSTR + BSTR, expected %f got %f\n", 0.0, V_R8(&result));
2677 
2678     /* Manually test some VT_CY and VT_DECIMAL variants */
2679     V_VT(&cy) = VT_CY;
2680     hres = VarCyFromI4(4711, &V_CY(&cy));
2681     ok(hres == S_OK, "VarCyFromI4 failed!\n");
2682     V_VT(&dec) = VT_DECIMAL;
2683     hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec));
2684     ok(hres == S_OK, "VarDecFromR4 failed!\n");
2685     memset(&left, 0, sizeof(left));
2686     memset(&right, 0, sizeof(right));
2687     V_VT(&left) = VT_I4;
2688     V_I4(&left) = -11;
2689     V_VT(&right) = VT_UI1;
2690     V_UI1(&right) = 9;
2691 
2692     hres = pVarSub(&cy, &right, &result);
2693     ok(hres == S_OK && V_VT(&result) == VT_CY,
2694         "VarSub: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result)));
2695     hres = VarR8FromCy(V_CY(&result), &r);
2696     ok(hres == S_OK && EQ_DOUBLE(r, 4702.0),
2697         "VarSub: CY value %f, expected %f\n", r, (double)4720);
2698 
2699     hres = pVarSub(&left, &dec, &result);
2700     ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
2701         "VarSub: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
2702     hres = VarR8FromDec(&V_DECIMAL(&result), &r);
2703     ok(hres == S_OK && EQ_DOUBLE(r, -6.8),
2704         "VarSub: DECIMAL value %f, expected %f\n", r, (double)-15.2);
2705 
2706     SysFreeString(lbstr);
2707     SysFreeString(rbstr);
2708 }
2709 
2710 static HRESULT (WINAPI *pVarMod)(LPVARIANT,LPVARIANT,LPVARIANT);
2711 
2712 static void test_Mod( int line, VARIANT *left, VARIANT *right, VARIANT *expected, HRESULT expres )
2713 {
2714     VARIANT result;
2715     HRESULT hres;
2716 
2717     memset( &result, 0, sizeof(result) );
2718     hres = pVarMod( left, right, &result );
2719     ok_(__FILE__,line)( hres == expres, "wrong result %x/%x\n", hres, expres );
2720     if (hres == S_OK)
2721         ok_(__FILE__,line)( is_expected_variant( &result, expected ),
2722                             "got %s expected %s\n", variantstr(&result), variantstr(expected) );
2723 }
2724 
2725 #define VARMOD(vt1,vt2,val1,val2,rvt,rval)               \
2726         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
2727         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
2728         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
2729         test_var_call2( __LINE__, pVarMod, &left, &right, &exp )
2730 
2731 #define VARMOD2(vt1,vt2,val1,val2,rvt,rval,hexpected)         \
2732         V_VT(&left) = VT_##vt1; V_I4(&left) = val1;           \
2733         V_VT(&right) = VT_##vt2; V_I4(&right) = val2;         \
2734         V_VT(&exp) = VT_##rvt; V_I4(&exp) = rval;             \
2735         test_Mod( __LINE__, &left, &right, &exp, hexpected )
2736 
2737 static void test_VarMod(void)
2738 {
2739   VARIANT v1, v2, vDst, left, right, exp;
2740   HRESULT hres;
2741   HRESULT hexpected = 0;
2742   static const WCHAR szNum0[] = {'1','2','5','\0'};
2743   static const WCHAR szNum1[] = {'1','0','\0'};
2744   int l, r;
2745   BOOL lFound, rFound;
2746   BOOL lValid;
2747   BSTR strNum0, strNum1;
2748 
2749   CHECKPTR(VarMod);
2750 
2751   VARMOD(I1,BOOL,100,10,I4,0);
2752   VARMOD(I1,I1,100,10,I4,0);
2753   VARMOD(I1,UI1,100,10,I4,0);
2754   VARMOD(I1,I2,100,10,I4,0);
2755   VARMOD(I1,UI2,100,10,I4,0);
2756   VARMOD(I1,I4,100,10,I4,0);
2757   VARMOD(I1,UI4,100,10,I4,0);
2758   VARMOD(I1,R4,100,10,I4,0);
2759   VARMOD(I1,R8,100,10,I4,0);
2760 
2761   VARMOD(UI1,BOOL,100,10,I2,0);
2762   VARMOD(UI1,I1,100,10,I4,0);
2763   VARMOD(UI1,UI1,100,10,UI1,0);
2764   VARMOD(UI1,I2,100,10,I2,0);
2765   VARMOD(UI1,UI2,100,10,I4,0);
2766   VARMOD(UI1,I4,100,10,I4,0);
2767   VARMOD(UI1,UI4,100,10,I4,0);
2768   VARMOD(UI1,R4,100,10,I4,0);
2769   VARMOD(UI1,R8,100,10,I4,0);
2770 
2771   VARMOD(I2,BOOL,100,10,I2,0);
2772   VARMOD(I2,I1,100,10,I4,0);
2773   VARMOD(I2,UI1,100,10,I2,0);
2774   VARMOD(I2,I2,100,10,I2,0);
2775   VARMOD(I2,UI2,100,10,I4,0);
2776   VARMOD(I2,I4,100,10,I4,0);
2777   VARMOD(I2,UI4,100,10,I4,0);
2778   VARMOD(I2,R4,100,10,I4,0);
2779   VARMOD(I2,R8,100,10,I4,0);
2780 
2781   VARMOD(I4,BOOL,100,10,I4,0);
2782   VARMOD(I4,I1,100,10,I4,0);
2783   VARMOD(I4,UI1,100,10,I4,0);
2784   VARMOD(I4,I2,100,10,I4,0);
2785   VARMOD(I4,UI2,100,10,I4,0);
2786   VARMOD(I4,I4,100,10,I4,0);
2787   VARMOD(I4,UI4,100,10,I4,0);
2788   VARMOD(I4,R4,100,10,I4,0);
2789   VARMOD(I4,R8,100,10,I4,0);
2790   VARMOD(UI4,BOOL,100,10,I4,0);
2791   VARMOD(UI4,I1,100,10,I4,0);
2792   VARMOD(UI4,UI1,100,10,I4,0);
2793   VARMOD(UI4,I2,100,10,I4,0);
2794   VARMOD(UI4,UI2,100,10,I4,0);
2795   VARMOD(UI4,I4,100,10,I4,0);
2796   VARMOD(UI4,UI4,100,10,I4,0);
2797   VARMOD(UI4,R4,100,10,I4,0);
2798   VARMOD(UI4,R8,100,10,I4,0);
2799   VARMOD(R4,BOOL,100,10,I4,0);
2800   VARMOD(R4,I1,100,10,I4,0);
2801   VARMOD(R4,UI1,100,10,I4,0);
2802   VARMOD(R4,I2,100,10,I4,0);
2803   VARMOD(R4,UI2,100,10,I4,0);
2804   VARMOD(R4,I4,100,10,I4,0);
2805   VARMOD(R4,UI4,100,10,I4,0);
2806   VARMOD(R4,R4,100,10,I4,0);
2807   VARMOD(R4,R8,100,10,I4,0);
2808   VARMOD(R8,BOOL,100,10,I4,0);
2809   VARMOD(R8,I1,100,10,I4,0);
2810   VARMOD(R8,UI1,100,10,I4,0);
2811   VARMOD(R8,I2,100,10,I4,0);
2812   VARMOD(R8,UI2,100,10,I4,0);
2813   VARMOD(R8,I4,100,10,I4,0);
2814   VARMOD(R8,UI4,100,10,I4,0);
2815   VARMOD(R8,R4,100,10,I4,0);
2816   VARMOD(R8,R8,100,10,I4,0);
2817 
2818   VARMOD(INT,INT,100,10,I4,0);
2819   VARMOD(INT,UINT,100,10,I4,0);
2820 
2821   VARMOD(BOOL,BOOL,100,10,I2,0);
2822   VARMOD(BOOL,I1,100,10,I4,0);
2823   VARMOD(BOOL,UI1,100,10,I2,0);
2824   VARMOD(BOOL,I2,100,10,I2,0);
2825   VARMOD(BOOL,UI2,100,10,I4,0);
2826   VARMOD(BOOL,I4,100,10,I4,0);
2827   VARMOD(BOOL,UI4,100,10,I4,0);
2828   VARMOD(BOOL,R4,100,10,I4,0);
2829   VARMOD(BOOL,R8,100,10,I4,0);
2830   VARMOD(BOOL,DATE,100,10,I4,0);
2831 
2832   VARMOD(DATE,BOOL,100,10,I4,0);
2833   VARMOD(DATE,I1,100,10,I4,0);
2834   VARMOD(DATE,UI1,100,10,I4,0);
2835   VARMOD(DATE,I2,100,10,I4,0);
2836   VARMOD(DATE,UI2,100,10,I4,0);
2837   VARMOD(DATE,I4,100,10,I4,0);
2838   VARMOD(DATE,UI4,100,10,I4,0);
2839   VARMOD(DATE,R4,100,10,I4,0);
2840   VARMOD(DATE,R8,100,10,I4,0);
2841   VARMOD(DATE,DATE,100,10,I4,0);
2842 
2843   strNum0 = SysAllocString(szNum0);
2844   strNum1 = SysAllocString(szNum1);
2845   VARMOD(BSTR,BSTR,strNum0,strNum1,I4,5);
2846   VARMOD(BSTR,I1,strNum0,10,I4,5);
2847   VARMOD(BSTR,I2,strNum0,10,I4,5);
2848   VARMOD(BSTR,I4,strNum0,10,I4,5);
2849   VARMOD(BSTR,R4,strNum0,10,I4,5);
2850   VARMOD(BSTR,R8,strNum0,10,I4,5);
2851   VARMOD(I4,BSTR,125,strNum1,I4,5);
2852 
2853   if (has_i8)
2854   {
2855     VARMOD(BOOL,I8,100,10,I8,0);
2856     VARMOD(I1,I8,100,10,I8,0);
2857     VARMOD(UI1,I8,100,10,I8,0);
2858     VARMOD(I2,I8,100,10,I8,0);
2859     VARMOD(I4,I8,100,10,I8,0);
2860     VARMOD(UI4,I8,100,10,I8,0);
2861     VARMOD(R4,I8,100,10,I8,0);
2862     VARMOD(R8,I8,100,10,I8,0);
2863     VARMOD(DATE,I8,100,10,I8,0);
2864 
2865     VARMOD(I8,BOOL,100,10,I8,0);
2866     VARMOD(I8,I1,100,10,I8,0);
2867     VARMOD(I8,UI1,100,10,I8,0);
2868     VARMOD(I8,I2,100,10,I8,0);
2869     VARMOD(I8,UI2,100,10,I8,0);
2870     VARMOD(I8,I4,100,10,I8,0);
2871     VARMOD(I8,UI4,100,10,I8,0);
2872     VARMOD(I8,R4,100,10,I8,0);
2873     VARMOD(I8,R8,100,10,I8,0);
2874     VARMOD(I8,I8,100,10,I8,0);
2875 
2876     VARMOD(BSTR,I8,strNum0,10,I8,5);
2877   }
2878 
2879   /* test all combinations of types */
2880   for(l = 0; l < VT_BSTR_BLOB; l++)
2881   {
2882     SKIPTESTS(l);
2883 
2884     for(r = 0; r < VT_BSTR_BLOB; r++)
2885     {
2886       SKIPTESTS(r);
2887 
2888       if(l == VT_BSTR) continue;
2889       if(l == VT_DISPATCH) continue;
2890       if(r == VT_BSTR) continue;
2891       if(r == VT_DISPATCH) continue;
2892 
2893       lFound = TRUE;
2894       lValid = TRUE;
2895       switch(l)
2896 	{
2897 	case VT_EMPTY:
2898 	case VT_NULL:
2899 	case VT_I1:
2900 	case VT_UI1:
2901 	case VT_I2:
2902 	case VT_UI2:
2903 	case VT_I4:
2904 	case VT_I8:
2905 	case VT_UI4:
2906 	case VT_UI8:
2907 	case VT_INT:
2908 	case VT_UINT:
2909 	case VT_R4:
2910 	case VT_R8:
2911 	case VT_BOOL:
2912 	case VT_DATE:
2913 	case VT_CY:
2914 	case VT_DECIMAL:
2915 	  hexpected = S_OK;
2916 	  break;
2917 	case VT_ERROR:
2918 	case VT_VARIANT:
2919 	case VT_UNKNOWN:
2920 	case VT_RECORD:
2921 	  lValid = FALSE;
2922 	  break;
2923 	default:
2924 	  lFound = FALSE;
2925 	  hexpected = DISP_E_BADVARTYPE;
2926 	  break;
2927 	}
2928 
2929       rFound = TRUE;
2930       switch(r)
2931 	{
2932 	case VT_EMPTY:
2933 	case VT_NULL:
2934 	case VT_I1:
2935 	case VT_UI1:
2936 	case VT_I2:
2937 	case VT_UI2:
2938 	case VT_I4:
2939 	case VT_I8:
2940 	case VT_UI4:
2941 	case VT_UI8:
2942 	case VT_INT:
2943 	case VT_UINT:
2944 	case VT_R4:
2945 	case VT_R8:
2946 	case VT_BOOL:
2947 	case VT_DATE:
2948 	case VT_DECIMAL:
2949 	case VT_CY:
2950 	  hexpected = S_OK;
2951 	  break;
2952 	case VT_ERROR:
2953 	case VT_VARIANT:
2954 	case VT_UNKNOWN:
2955 	case VT_RECORD:
2956 	  break;
2957 	default:
2958 	  rFound = FALSE;
2959 	  break;
2960 	}
2961 
2962       if(((l == VT_I8) && (r == VT_INT)) || ((l == VT_INT) && (r == VT_I8)))
2963       {
2964 	hexpected = DISP_E_TYPEMISMATCH;
2965       } else if((l == VT_EMPTY) && (r == VT_NULL))
2966       {
2967 	hexpected = S_OK;
2968       } else if((l == VT_NULL) && (r == VT_EMPTY))
2969       {
2970 	hexpected = S_OK;
2971       } else if((l == VT_EMPTY) && (r == VT_CY))
2972       {
2973 	hexpected = S_OK;
2974       } else if((l == VT_EMPTY) && (r == VT_RECORD))
2975       {
2976 	hexpected = DISP_E_TYPEMISMATCH;
2977       } else if((r == VT_EMPTY) && lFound && lValid)
2978       {
2979 	hexpected = DISP_E_DIVBYZERO;
2980       } else if((l == VT_ERROR) || ((r == VT_ERROR) && lFound && lValid))
2981       {
2982 	hexpected = DISP_E_TYPEMISMATCH;
2983       } else if((l == VT_NULL) && (r == VT_NULL))
2984       {
2985 	hexpected = S_OK;
2986       } else if((l == VT_VARIANT) || ((r == VT_VARIANT) && lFound && lValid))
2987       {
2988 	hexpected = DISP_E_TYPEMISMATCH;
2989       } else if((l == VT_NULL) && (r == VT_RECORD))
2990       {
2991 	hexpected = DISP_E_TYPEMISMATCH;
2992       } else if((l == VT_I8) && (r == VT_DECIMAL))
2993       {
2994 	hexpected = S_OK;
2995       } else if((l == VT_DECIMAL) && (r == VT_I8))
2996       {
2997 	hexpected = S_OK;
2998       } else if((l == VT_UNKNOWN) || ((r == VT_UNKNOWN) && lFound && lValid))
2999       {
3000 	hexpected = DISP_E_TYPEMISMATCH;
3001       } else if((l == VT_NULL) && rFound)
3002       {
3003 	hexpected = S_OK;
3004       } else if(l == VT_RECORD)
3005       {
3006 	hexpected = DISP_E_TYPEMISMATCH;
3007       } else if((r == VT_RECORD) && lValid && lFound)
3008       {
3009 	hexpected = DISP_E_TYPEMISMATCH;
3010       } else if((l == VT_EMPTY) && (r == VT_EMPTY))
3011       {
3012 	hexpected = DISP_E_DIVBYZERO;
3013       } else if((l == VT_CY) && !rFound)
3014       {
3015 	hexpected = DISP_E_BADVARTYPE;
3016       } else if(lFound && !rFound)
3017       {
3018 	hexpected = DISP_E_BADVARTYPE;
3019       } else if(!lFound && rFound)
3020       {
3021 	hexpected = DISP_E_BADVARTYPE;
3022       } else if((r == VT_NULL) && lFound && lValid)
3023       {
3024 	hexpected = S_OK;
3025       } else if((l == VT_NULL) || (r == VT_NULL))
3026       {
3027 	hexpected = DISP_E_BADVARTYPE;
3028       } else if((l == VT_VARIANT) || (r == VT_VARIANT))
3029       {
3030 	hexpected = DISP_E_BADVARTYPE;
3031       } else if(!lFound && !rFound)
3032       {
3033 	hexpected = DISP_E_BADVARTYPE;
3034       }
3035 
3036       V_VT(&v1) = l;
3037       V_VT(&v2) = r;
3038 
3039       if(l == VT_CY)
3040 	V_CY(&v1).int64 = 1000000;
3041       else if(l == VT_R4)
3042 	V_R4(&v1) = 100;
3043       else if(l == VT_R8)
3044 	V_R8(&v1) = 100;
3045       else if(l == VT_UI8)
3046 	V_UI8(&v1) = 100;
3047       else if(l == VT_I8)
3048 	V_I8(&v1) = 100;
3049       else if(l == VT_DATE)
3050 	V_DATE(&v1) = 1000;
3051       else if (l == VT_DECIMAL)
3052       {
3053 	V_DECIMAL(&v1).Hi32 = 0;
3054 	U1(V_DECIMAL(&v1)).Lo64 = 100;
3055 	U(V_DECIMAL(&v1)).signscale = 0;
3056       }
3057       else
3058 	V_I4(&v1) = 10000;
3059 
3060       if(r == VT_CY)
3061 	V_CY(&v2).int64 = 10000;
3062       else if(r == VT_R4)
3063 	V_R4(&v2) = 100;
3064       else if(r == VT_R8)
3065 	V_R8(&v2) = 100;
3066       else if(r == VT_UI8)
3067 	V_UI8(&v2) = 100;
3068       else if(r == VT_I8)
3069 	V_I8(&v2) = 100;
3070       else if(r == VT_DATE)
3071 	V_DATE(&v2) = 1000;
3072       else if (r == VT_DECIMAL)
3073       {
3074 	V_DECIMAL(&v2).Hi32 = 0;
3075 	U1(V_DECIMAL(&v2)).Lo64 = 100;
3076 	U(V_DECIMAL(&v2)).signscale = 0;
3077       }
3078       else
3079 	V_I4(&v2) = 10000;
3080 
3081       if ((l != VT_I8 && l != VT_UI8 && r != VT_I8 && r != VT_UI8) || has_i8)
3082       {
3083         hres = pVarMod(&v1,&v2,&vDst);
3084         ok(hres == hexpected,
3085            "VarMod: expected 0x%x, got 0x%X for l type of %d, r type of %d,\n", hexpected, hres, l, r);
3086       }
3087     }
3088   }
3089 
3090 
3091   /****************************/
3092   /* test some bad parameters */
3093   VARMOD(I4,I4,-1,-1,I4,0);
3094 
3095   /* test modulus with zero */
3096   VARMOD2(I4,I4,100,0,EMPTY,0,DISP_E_DIVBYZERO);
3097 
3098   VARMOD(I4,I4,0,10,I4,0); /* test 0 mod 10 */
3099 
3100   /* right parameter is type empty */
3101   VARMOD2(I4,EMPTY,100,10,EMPTY,0,DISP_E_DIVBYZERO);
3102 
3103   /* left parameter is type empty */
3104   VARMOD2(EMPTY,I4,100,10,I4,0,S_OK);
3105 
3106   /* mod with a null left value */
3107   VARMOD2(NULL,I4,125,10,NULL,0,S_OK);
3108 
3109   /* mod with a null right value */
3110   VARMOD2(I4,NULL,100,10,NULL,0,S_OK);
3111 
3112   /* void left value */
3113   VARMOD2(VOID,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3114 
3115   /* void right value */
3116   VARMOD2(I4,VOID,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3117 
3118   /* null left value, void right value */
3119   VARMOD2(NULL,VOID,100,10,EMPTY, 0, DISP_E_BADVARTYPE);
3120 
3121   /* void left value, null right value */
3122   VARMOD2(VOID,NULL,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3123 
3124   /* some currencies */
3125   V_VT(&v1) = VT_CY;
3126   V_VT(&v2) = VT_CY;
3127   V_CY(&v1).int64 = 100000;
3128   V_CY(&v2).int64 = 100000;
3129   hres = pVarMod(&v1,&v2,&vDst);
3130   ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
3131      "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
3132 
3133   V_VT(&v1) = VT_I4;
3134   V_VT(&v2) = VT_CY;
3135   V_I4(&v1) = 100;
3136   V_CY(&v2).int64 = 100000;
3137   hres = pVarMod(&v1,&v2,&vDst);
3138   ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
3139      "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
3140 
3141   /* some decimals */
3142   V_VT(&v1) = VT_DECIMAL;
3143   V_VT(&v2) = VT_DECIMAL;
3144   VarDecFromI4(100, &V_DECIMAL(&v1));
3145   VarDecFromI4(10, &V_DECIMAL(&v2));
3146   hres = pVarMod(&v1,&v2,&vDst);
3147   ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
3148      "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
3149 
3150   V_VT(&v1) = VT_I4;
3151   V_VT(&v2) = VT_DECIMAL;
3152   V_I4(&v1) = 100;
3153   VarDecFromI4(10, &V_DECIMAL(&v2));
3154   hres = pVarMod(&v1,&v2,&vDst);
3155   ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
3156      "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
3157 
3158   VARMOD2(UINT,I4,100,10,I4,0,S_OK);
3159 
3160   /* test that an error results in the type of the result changing but not its value */
3161   V_VT(&v1) = VT_UNKNOWN;
3162   V_VT(&v2) = VT_EMPTY;
3163   V_I4(&v1) = 100;
3164   V_CY(&v2).int64 = 100000;
3165   V_VT(&vDst) = VT_I4;
3166   V_I4(&vDst) = 1231;
3167   hres = pVarMod(&v1,&v2,&vDst);
3168   ok(hres == DISP_E_TYPEMISMATCH && V_VT(&vDst) == VT_EMPTY && V_I4(&vDst) == 1231,
3169      "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));
3170 
3171 
3172   /* test some invalid types */
3173   /*TODO: not testing VT_DISPATCH */
3174   if (has_i8)
3175   {
3176     VARMOD2(I8,INT,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
3177   }
3178   VARMOD2(ERROR,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
3179   VARMOD2(VARIANT,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
3180   VARMOD2(UNKNOWN,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
3181   VARMOD2(VOID,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3182   VARMOD2(HRESULT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3183   VARMOD2(PTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3184   VARMOD2(SAFEARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3185   VARMOD2(CARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3186   VARMOD2(USERDEFINED,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3187   VARMOD2(LPSTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3188   VARMOD2(LPWSTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3189   VARMOD2(RECORD,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
3190   VARMOD2(FILETIME,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3191   VARMOD2(BLOB,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3192   VARMOD2(STREAM,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3193   VARMOD2(STORAGE,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3194   VARMOD2(STREAMED_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3195   VARMOD2(STORED_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3196   VARMOD2(BLOB_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3197   VARMOD2(CF,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3198   VARMOD2(CLSID,CLSID,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3199   VARMOD2(VECTOR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3200   VARMOD2(ARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3201   VARMOD2(BYREF,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3202 
3203   /* test some more invalid types */
3204   V_VT(&v1) = 456;
3205   V_VT(&v2) = 234;
3206   V_I4(&v1) = 100;
3207   V_I4(&v2)=  10;
3208   hres = pVarMod(&v1,&v2,&vDst);
3209   ok(hres == DISP_E_BADVARTYPE && V_VT(&vDst) == VT_EMPTY,
3210      "VarMod: expected 0x%x,%d, got 0x%X,%d\n", DISP_E_BADVARTYPE, VT_EMPTY, hres, V_VT(&vDst));
3211 
3212   SysFreeString(strNum0);
3213   SysFreeString(strNum1);
3214 }
3215 
3216 static HRESULT (WINAPI *pVarFix)(LPVARIANT,LPVARIANT);
3217 
3218 #define VARFIX(vt,val,rvt,rval)                  \
3219     V_VT(&v) = VT_##vt; V_##vt(&v) = val;        \
3220     V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
3221     test_var_call1( __LINE__, pVarFix, &v, &exp )
3222 
3223 static void test_VarFix(void)
3224 {
3225     static const WCHAR szNumMinus1[] = {'-','1','\0' };
3226     HRESULT hres;
3227     VARIANT v, exp, vDst;
3228     DECIMAL *pdec = &V_DECIMAL(&v);
3229     CY *pcy = &V_CY(&v);
3230     size_t i;
3231 
3232     CHECKPTR(VarFix);
3233 
3234     /* Test all possible V_VT values */
3235     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
3236     {
3237         VARTYPE vt;
3238 
3239         for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
3240         {
3241             BOOL bFail = TRUE;
3242 
3243             SKIPTESTS(vt);
3244 
3245             memset(&v, 0, sizeof(v));
3246             V_VT(&v) = vt | ExtraFlags[i];
3247             V_VT(&vDst) = VT_EMPTY;
3248 
3249             switch (V_VT(&v))
3250             {
3251               case VT_UI1: case VT_I2: case VT_I4: case VT_R4:  case VT_R8:
3252               case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
3253               case VT_DATE: case VT_CY:
3254                 bFail = FALSE;
3255                 break;
3256               case VT_I8:
3257                 if (has_i8)
3258                   bFail = FALSE;
3259                 break;
3260             }
3261 
3262             hres = pVarFix(&v,&vDst);
3263             if (bFail)
3264               ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3265                  "VarFix: expected failure, got 0x%X vt %d|0x%X\n",
3266                  hres, vt, ExtraFlags[i]);
3267             else
3268                  ok(hres == S_OK, "VarFix: expected S_OK, got 0x%X vt %d|0x%X\n",
3269                     hres, vt, ExtraFlags[i]);
3270         }
3271     }
3272 
3273     VARFIX(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE);
3274     VARFIX(BOOL,VARIANT_FALSE,I2,0);
3275     VARFIX(BOOL,1,I2,1);
3276     VARFIX(UI1,1,UI1,1);
3277     VARFIX(I2,-1,I2,-1);
3278     VARFIX(I4,-1,I4,-1);
3279     if (has_i8)
3280     {
3281         VARFIX(I8,-1,I8,-1);
3282     }
3283     VARFIX(R4,1.4f,R4,1);
3284     VARFIX(R4,1.5f,R4,1);
3285     VARFIX(R4,1.6f,R4,1);
3286     VARFIX(R4,-1.4f,R4,-1);
3287     VARFIX(R4,-1.5f,R4,-1);
3288     VARFIX(R4,-1.6f,R4,-1);
3289     /* DATE & R8 round as for R4 */
3290     VARFIX(DATE,-1,DATE,-1);
3291     VARFIX(R8,-1,R8,-1);
3292     VARFIX(BSTR,(BSTR)szNumMinus1,R8,-1);
3293 
3294     V_VT(&v) = VT_EMPTY;
3295     hres = pVarFix(&v,&vDst);
3296     ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
3297        "VarFix: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY,
3298        hres, V_VT(&vDst), V_I2(&vDst));
3299 
3300     V_VT(&v) = VT_NULL;
3301     hres = pVarFix(&v,&vDst);
3302     ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
3303        "VarFix: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst));
3304 
3305     V_VT(&v) = VT_DECIMAL;
3306     S(U(*pdec)).sign = DECIMAL_NEG;
3307     S(U(*pdec)).scale = 0;
3308     pdec->Hi32 = 0;
3309     S1(U1(*pdec)).Mid32 = 0;
3310     S1(U1(*pdec)).Lo32 = 1;
3311     hres = pVarFix(&v,&vDst);
3312     ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && !memcmp(&V_DECIMAL(&v), &V_DECIMAL(&vDst), sizeof(DECIMAL)),
3313        "VarFix: expected 0x0,%d,identical, got 0x%X,%d\n", VT_DECIMAL,
3314        hres, V_VT(&vDst));
3315 
3316     /* FIXME: Test some fractional decimals when VarDecFix is implemented */
3317 
3318     V_VT(&v) = VT_CY;
3319     pcy->int64 = -10000;
3320     hres = pVarFix(&v,&vDst);
3321     ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
3322        "VarFix: VT_CY wrong, hres=0x%X\n", hres);
3323 
3324     V_VT(&v) = VT_CY;
3325     pcy->int64 = -16000;
3326     hres = pVarFix(&v,&vDst);
3327     ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
3328        "VarFix: VT_CY wrong, hres=0x%X\n", hres);
3329 }
3330 
3331 static HRESULT (WINAPI *pVarInt)(LPVARIANT,LPVARIANT);
3332 
3333 #define VARINT(vt,val,rvt,rval)                  \
3334     V_VT(&v) = VT_##vt; V_##vt(&v) = val;        \
3335     V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
3336     test_var_call1( __LINE__, pVarInt, &v, &exp )
3337 
3338 static void test_VarInt(void)
3339 {
3340     static const WCHAR szNumMinus1[] = {'-','1','\0' };
3341     HRESULT hres;
3342     VARIANT v, exp, vDst;
3343     DECIMAL *pdec = &V_DECIMAL(&v);
3344     CY *pcy = &V_CY(&v);
3345     size_t i;
3346 
3347     CHECKPTR(VarInt);
3348 
3349     /* Test all possible V_VT values */
3350     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
3351     {
3352         VARTYPE vt;
3353 
3354         for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
3355         {
3356             BOOL bFail = TRUE;
3357 
3358             SKIPTESTS(vt);
3359 
3360             memset(&v, 0, sizeof(v));
3361             V_VT(&v) = vt | ExtraFlags[i];
3362             V_VT(&vDst) = VT_EMPTY;
3363 
3364             switch (V_VT(&v))
3365             {
3366               case VT_UI1: case VT_I2: case VT_I4: case VT_R4:  case VT_R8:
3367               case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
3368               case VT_DATE: case VT_CY:
3369                 bFail = FALSE;
3370                 break;
3371               case VT_I8:
3372                 if (has_i8)
3373                   bFail = FALSE;
3374                 break;
3375             }
3376 
3377             hres = pVarInt(&v,&vDst);
3378             if (bFail)
3379               ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3380                  "VarInt: expected failure, got 0x%X vt %d|0x%X\n",
3381                  hres, vt, ExtraFlags[i]);
3382             else
3383                  ok(hres == S_OK, "VarInt: expected S_OK, got 0x%X vt %d|0x%X\n",
3384                     hres, vt, ExtraFlags[i]);
3385         }
3386     }
3387 
3388     VARINT(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE);
3389     VARINT(BOOL,VARIANT_FALSE,I2,0);
3390     VARINT(BOOL,1,I2,1);
3391     VARINT(UI1,1,UI1,1);
3392     VARINT(I2,-1,I2,-1);
3393     VARINT(I4,-1,I4,-1);
3394     if (has_i8)
3395     {
3396         VARINT(I8,-1,I8,-1);
3397     }
3398     VARINT(R4,1.4f,R4,1);
3399     VARINT(R4,1.5f,R4,1);
3400     VARINT(R4,1.6f,R4,1);
3401     VARINT(R4,-1.4f,R4,-2); /* Note these 3 are different from VarFix */
3402     VARINT(R4,-1.5f,R4,-2);
3403     VARINT(R4,-1.6f,R4,-2);
3404     /* DATE & R8 round as for R4 */
3405     VARINT(DATE,-1,DATE,-1);
3406     VARINT(R8,-1,R8,-1);
3407     VARINT(BSTR,(BSTR)szNumMinus1,R8,-1);
3408 
3409     V_VT(&v) = VT_EMPTY;
3410     hres = pVarInt(&v,&vDst);
3411     ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
3412        "VarInt: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY,
3413        hres, V_VT(&vDst), V_I2(&vDst));
3414 
3415     V_VT(&v) = VT_NULL;
3416     hres = pVarInt(&v,&vDst);
3417     ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
3418        "VarInt: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst));
3419 
3420     V_VT(&v) = VT_DECIMAL;
3421     S(U(*pdec)).sign = DECIMAL_NEG;
3422     S(U(*pdec)).scale = 0;
3423     pdec->Hi32 = 0;
3424     S1(U1(*pdec)).Mid32 = 0;
3425     S1(U1(*pdec)).Lo32 = 1;
3426     hres = pVarInt(&v,&vDst);
3427     ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && !memcmp(&V_DECIMAL(&v), &V_DECIMAL(&vDst), sizeof(DECIMAL)),
3428        "VarInt: expected 0x0,%d,identical, got 0x%X,%d\n", VT_DECIMAL,
3429        hres, V_VT(&vDst));
3430 
3431     /* FIXME: Test some fractional decimals when VarDecInt is implemented */
3432 
3433     V_VT(&v) = VT_CY;
3434     pcy->int64 = -10000;
3435     hres = pVarInt(&v,&vDst);
3436     ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
3437        "VarInt: VT_CY wrong, hres=0x%X\n", hres);
3438 
3439     V_VT(&v) = VT_CY;
3440     pcy->int64 = -11000;
3441     hres = pVarInt(&v,&vDst);
3442     ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -20000,
3443        "VarInt: VT_CY wrong, hres=0x%X 0x%x%08x\n",
3444        hres, (DWORD)(V_CY(&vDst).int64 >> 32), (DWORD)V_CY(&vDst).int64);
3445 }
3446 
3447 static HRESULT (WINAPI *pVarNeg)(LPVARIANT,LPVARIANT);
3448 
3449 #define VARNEG(vt,val,rvt,rval)                  \
3450     V_VT(&v) = VT_##vt; V_##vt(&v) = val;        \
3451     V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
3452     test_var_call1( __LINE__, pVarNeg, &v, &exp )
3453 
3454 static void test_VarNeg(void)
3455 {
3456     static const WCHAR szNumMinus1[] = {'-','1','\0' };
3457     static const WCHAR szNum1[] = {'1','\0' };
3458     HRESULT hres;
3459     VARIANT v, exp, vDst;
3460     DECIMAL *pdec = &V_DECIMAL(&v);
3461     CY *pcy = &V_CY(&v);
3462     size_t i;
3463 
3464     CHECKPTR(VarNeg);
3465 
3466     /* Test all possible V_VT values. But don't test the exact return values
3467      * except for success/failure, since M$ made a hash of them in the
3468      * native version. This at least ensures (as with all tests here) that
3469      * we will notice if/when new vtypes/flags are added in native.
3470      */
3471     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
3472     {
3473         VARTYPE vt;
3474 
3475         for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
3476         {
3477             BOOL bFail = TRUE;
3478 
3479             SKIPTESTS(vt);
3480 
3481             memset(&v, 0, sizeof(v));
3482             V_VT(&v) = vt | ExtraFlags[i];
3483             V_VT(&vDst) = VT_EMPTY;
3484 
3485             switch (V_VT(&v))
3486             {
3487             case VT_UI1: case VT_I2: case VT_I4:
3488             case VT_R4:  case VT_R8:
3489             case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
3490             case VT_DATE: case VT_CY:
3491                 bFail = FALSE;
3492                 break;
3493             case VT_I8:
3494                 if (has_i8)
3495                     bFail = FALSE;
3496             }
3497 
3498             hres = pVarNeg(&v,&vDst);
3499             if (bFail)
3500                 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3501                    "VarNeg: expected failure, got 0x%X vt %d|0x%X\n",
3502                    hres, vt, ExtraFlags[i]);
3503             else
3504                 ok(hres == S_OK, "VarNeg: expected S_OK, got 0x%X vt %d|0x%X\n",
3505                     hres, vt, ExtraFlags[i]);
3506         }
3507     }
3508 
3509     VARNEG(BOOL,VARIANT_TRUE,I2,1);
3510     VARNEG(BOOL,VARIANT_FALSE,I2,0);
3511     VARNEG(BOOL,1,I2,-1);
3512     VARNEG(UI1,1,I2,-1);
3513     VARNEG(UI1,254,I2,-254);
3514     VARNEG(I2,-32768,I4,32768);
3515     VARNEG(I2,-1,I2,1);
3516     VARNEG(I2,1,I2,-1);
3517     VARNEG(I4,-((int)(~0u >> 1)) - 1,R8,-2147483648u);
3518     VARNEG(I4,-1,I4,1);
3519     VARNEG(I4,1,I4,-1);
3520     if (has_i8)
3521     {
3522         VARNEG(I8,1,I8,-1);
3523         VARNEG(I8,-1,I8,1);
3524     }
3525     VARNEG(R4,1,R4,-1);
3526     VARNEG(R4,-1,R4,1);
3527     VARNEG(DATE,1,DATE,-1);
3528     VARNEG(DATE,-1,DATE,1);
3529     VARNEG(R8,1,R8,-1);
3530     VARNEG(R8,-1,R8,1);
3531     VARNEG(BSTR,(BSTR)szNumMinus1,R8,1);
3532     VARNEG(BSTR,(BSTR)szNum1,R8,-1);
3533 
3534     V_VT(&v) = VT_EMPTY;
3535     hres = pVarNeg(&v,&vDst);
3536     ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
3537        "VarNeg: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY,
3538        hres, V_VT(&vDst), V_I2(&vDst));
3539 
3540     V_VT(&v) = VT_NULL;
3541     hres = pVarNeg(&v,&vDst);
3542     ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
3543        "VarNeg: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst));
3544 
3545     V_VT(&v) = VT_DECIMAL;
3546     S(U(*pdec)).sign = DECIMAL_NEG;
3547     S(U(*pdec)).scale = 0;
3548     pdec->Hi32 = 0;
3549     S1(U1(*pdec)).Mid32 = 0;
3550     S1(U1(*pdec)).Lo32 = 1;
3551     hres = pVarNeg(&v,&vDst);
3552     ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
3553        S(U(V_DECIMAL(&vDst))).sign == 0,
3554        "VarNeg: expected 0x0,%d,0x00, got 0x%X,%d,%02x\n", VT_DECIMAL,
3555        hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
3556 
3557     S(U(*pdec)).sign = 0;
3558     hres = pVarNeg(&v,&vDst);
3559     ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
3560        S(U(V_DECIMAL(&vDst))).sign == DECIMAL_NEG,
3561        "VarNeg: expected 0x0,%d,0x7f, got 0x%X,%d,%02x\n", VT_DECIMAL,
3562        hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
3563 
3564     V_VT(&v) = VT_CY;
3565     pcy->int64 = -10000;
3566     hres = pVarNeg(&v,&vDst);
3567     ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
3568        "VarNeg: VT_CY wrong, hres=0x%X\n", hres);
3569 }
3570 
3571 static HRESULT (WINAPI *pVarRound)(LPVARIANT,int,LPVARIANT);
3572 
3573 static void test_Round( int line, VARIANT *arg, int deci, VARIANT *expected )
3574 {
3575     VARIANT result;
3576     HRESULT hres;
3577 
3578     memset( &result, 0, sizeof(result) );
3579     hres = pVarRound( arg, deci, &result );
3580     ok_(__FILE__,line)( hres == S_OK, "wrong result %x\n", hres );
3581     if (hres == S_OK)
3582         ok_(__FILE__,line)( is_expected_variant( &result, expected ),
3583                             "got %s expected %s\n", variantstr(&result), variantstr(expected) );
3584 }
3585 #define VARROUND(vt,val,deci,rvt,rval)           \
3586     V_VT(&v) = VT_##vt; V_##vt(&v) = val;        \
3587     V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
3588     test_Round( __LINE__, &v, deci, &exp )
3589 
3590 struct decimal_t {
3591     BYTE scale;
3592     BYTE sign;
3593     ULONG Hi32;
3594     ULONG Mid32;
3595     ULONG Lo32;
3596 };
3597 
3598 struct decimal_round_t {
3599     struct decimal_t source;
3600     struct decimal_t ret;
3601     int dec;
3602 };
3603 
3604 static const struct decimal_round_t decimal_round_data[] = {
3605     {{ 0, DECIMAL_NEG, 0, 0, 1 }, { 0, DECIMAL_NEG, 0, 0, 1 }, 0},
3606     {{ 0, 0, 0, 0, 1 }, { 0, 0, 0, 0, 1 }, 0},
3607     {{ 2, 0, 0, 0, 155 }, { 0, 0, 0, 0, 16 }, 1},
3608     {{ 2, 0, 0, 0, 155 }, { 1, 0, 0, 0, 2 }, 0},
3609     {{ 2, 0, 0, 0, 199 }, { 1, 0, 0, 0, 20 }, 1},
3610     {{ 2, 0, 0, 0, 199 }, { 2, 0, 0, 0, 199 }, 2},
3611     {{ 2, DECIMAL_NEG, 0, 0, 199 }, { 2, DECIMAL_NEG, 0, 0, 199 }, 2},
3612     {{ 2, DECIMAL_NEG, 0, 0, 55 },  { 2, DECIMAL_NEG, 0, 0, 6 }, 1},
3613     {{ 2, 0, 0, 0, 55 },  { 2, 0, 0, 0, 6 }, 1}
3614 };
3615 
3616 static void test_VarRound(void)
3617 {
3618     static WCHAR szNumMin[] = {'-','1','.','4','4','9','\0' };
3619     static WCHAR szNum[] = {'1','.','4','5','1','\0' };
3620     HRESULT hres;
3621     VARIANT v, exp, vDst;
3622     CY *pcy = &V_CY(&v);
3623     char buff[8];
3624     int i;
3625 
3626     CHECKPTR(VarRound);
3627 
3628     /* first check valid integer types */
3629     VARROUND(BOOL,VARIANT_TRUE,0,I2,-1);
3630     VARROUND(BOOL,VARIANT_FALSE,0,I2,0);
3631     VARROUND(BOOL,1,0,I2,1);
3632     VARROUND(UI1,1,0,UI1,1);
3633     VARROUND(UI1,254,0,UI1,254);
3634     VARROUND(I2,-32768,0,I2,-32768);
3635     VARROUND(I2,-1,0,I2,-1);
3636     VARROUND(I2,1,0,I2,1);
3637     VARROUND(I4,-((int)(~0u >> 1)) - 1,0,I4,-((int)(~0u >> 1)) - 1);
3638     VARROUND(I4,-1,0,I4,-1);
3639     VARROUND(I4,1,0,I4,1);
3640 
3641 
3642     /* MSDN states that rounding of R4/R8 is dependent on the underlying
3643      * bit pattern of the number and so is architecture dependent. In this
3644      * case Wine returns .2 (which is more correct) and Native returns .3
3645      */
3646 
3647     VARROUND(R4,1.0f,0,R4,1.0f);
3648     VARROUND(R4,-1.0f,0,R4,-1.0f);
3649     VARROUND(R8,1.0,0,R8,1.0);
3650     VARROUND(R8,-1.0,0,R8,-1.0);
3651 
3652     /* floating point numbers aren't exactly equal and we can't just
3653      * compare the first few digits. */
3654     VARROUND(DATE,1.451,1,DATE,1.5);
3655     VARROUND(DATE,-1.449,1,DATE,-1.4);
3656 
3657     /* replace the decimal separator */
3658     GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char));
3659     if (!buff[1]) {
3660         szNumMin[2] = buff[0];
3661         szNum[1] = buff[0];
3662         VARROUND(BSTR,(BSTR)szNumMin,1,R8,-1.40);
3663         VARROUND(BSTR,(BSTR)szNum,1,R8,1.50);
3664     } else {
3665         skip("Skipping VarRound(BSTR) as decimal separator is '%s'\n", buff);
3666     }
3667 
3668     VARROUND(R4,1.23456f,0,R4,1.0f);
3669     VARROUND(R4,1.23456f,1,R4,1.2f);
3670     VARROUND(R4,1.23456f,2,R4,1.23f);
3671     VARROUND(R4,1.23456f,3,R4,1.235f);
3672     VARROUND(R4,1.23456f,4,R4,1.2346f);
3673     VARROUND(R4,-1.23456f,0,R4,-1.0f);
3674     VARROUND(R4,-1.23456f,1,R4,-1.2f);
3675     VARROUND(R4,-1.23456f,2,R4,-1.23f);
3676     VARROUND(R4,-1.23456f,3,R4,-1.235f);
3677     VARROUND(R4,-1.23456f,4,R4,-1.2346f);
3678 
3679     VARROUND(R8,1.23456,0,R8,1.0);
3680     VARROUND(R8,1.23456,1,R8,1.2);
3681     VARROUND(R8,1.23456,2,R8,1.23);
3682     VARROUND(R8,1.23456,3,R8,1.235);
3683     VARROUND(R8,1.23456,4,R8,1.2346);
3684     VARROUND(R8,-1.23456,0,R8,-1.0);
3685     VARROUND(R8,-1.23456,1,R8,-1.2);
3686     VARROUND(R8,-1.23456,2,R8,-1.23);
3687     VARROUND(R8,-1.23456,3,R8,-1.235);
3688     VARROUND(R8,-1.23456,4,R8,-1.2346);
3689 
3690     V_VT(&v) = VT_EMPTY;
3691     hres = pVarRound(&v,0,&vDst);
3692     ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
3693         "VarRound: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY,
3694         hres, V_VT(&vDst), V_I2(&vDst));
3695 
3696     V_VT(&v) = VT_NULL;
3697     hres = pVarRound(&v,0,&vDst);
3698     ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
3699         "VarRound: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst));
3700 
3701     /* VT_DECIMAL */
3702     for (i = 0; i < sizeof(decimal_round_data)/sizeof(struct decimal_round_t); i++)
3703     {
3704         const struct decimal_round_t *ptr = &decimal_round_data[i];
3705         DECIMAL *pdec;
3706 
3707         pdec = &V_DECIMAL(&v);
3708         V_VT(&v) = VT_DECIMAL;
3709         S(U(*pdec)).sign = ptr->source.sign;
3710         S(U(*pdec)).scale = ptr->source.scale;
3711         pdec->Hi32 = ptr->source.Hi32;
3712         S1(U1(*pdec)).Mid32 = ptr->source.Mid32;
3713         S1(U1(*pdec)).Lo32 = ptr->source.Lo32;
3714         VariantInit(&vDst);
3715         hres = pVarRound(&v, ptr->dec, &vDst);
3716     todo_wine
3717         ok(hres == S_OK, "%d: got 0x%08x\n", i, hres);
3718         if (hres == S_OK)
3719         {
3720             ok(V_VT(&vDst) == VT_DECIMAL, "%d: got VT %d, expected VT_DECIMAL\n", i, V_VT(&vDst));
3721             ok(S(U(V_DECIMAL(&vDst))).sign == ptr->ret.sign, "%d: got sign 0x%02x, expected 0x%02x\n",
3722                 i, S(U(V_DECIMAL(&vDst))).sign, ptr->ret.sign);
3723             ok(V_DECIMAL(&vDst).Hi32 == ptr->ret.Hi32, "%d: got Hi32 %d, expected %d\n",
3724                 i, V_DECIMAL(&vDst).Hi32, ptr->ret.Hi32);
3725             ok(S1(U1(V_DECIMAL(&vDst))).Mid32 == ptr->ret.Mid32, "%d: got Mid32 %d, expected %d\n",
3726                i, S1(U1(V_DECIMAL(&vDst))).Mid32,  ptr->ret.Mid32);
3727             ok(S1(U1(V_DECIMAL(&vDst))).Lo32 == ptr->ret.Lo32, "%d: got Lo32 %d, expected %d\n",
3728                 i, S1(U1(V_DECIMAL(&vDst))).Lo32, ptr->ret.Lo32);
3729         }
3730     }
3731 
3732     /* VT_CY */
3733     V_VT(&v) = VT_CY;
3734     pcy->int64 = 10000;
3735     hres = pVarRound(&v,0,&vDst);
3736     ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
3737         "VarRound: VT_CY wrong, hres=0x%X\n", hres);
3738 
3739 }
3740 
3741 static HRESULT (WINAPI *pVarXor)(LPVARIANT,LPVARIANT,LPVARIANT);
3742 
3743 #define VARXOR(vt1,val1,vt2,val2,rvt,rval)               \
3744         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
3745         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
3746         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
3747         test_var_call2( __LINE__, pVarXor, &left, &right, &exp )
3748 
3749 #define VARXORCY(vt1,val1,val2,rvt,rval)                 \
3750         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
3751         V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \
3752         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
3753         test_var_call2( __LINE__, pVarXor, &left, &right, &exp )
3754 
3755 static void test_VarXor(void)
3756 {
3757     static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
3758     static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
3759     VARIANT left, right, exp, result;
3760     BSTR lbstr, rbstr;
3761     VARTYPE i;
3762     HRESULT hres;
3763 
3764     CHECKPTR(VarXor);
3765 
3766     /* Test all possible flag/vt combinations & the resulting vt type */
3767     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
3768     {
3769         VARTYPE leftvt, rightvt, resvt;
3770 
3771         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
3772         {
3773 
3774             SKIPTESTS(leftvt);
3775 
3776             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
3777             {
3778                 BOOL bFail = FALSE;
3779 
3780                 SKIPTESTS(rightvt);
3781 
3782                 if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
3783                     leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
3784                     leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
3785                     continue;
3786 
3787                 memset(&left, 0, sizeof(left));
3788                 memset(&right, 0, sizeof(right));
3789                 V_VT(&left) = leftvt | ExtraFlags[i];
3790                 V_VT(&right) = rightvt | ExtraFlags[i];
3791                 V_VT(&result) = VT_EMPTY;
3792                 resvt = VT_I4;
3793 
3794                 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
3795                     !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
3796                     !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
3797                     leftvt == VT_CLSID || rightvt == VT_CLSID ||
3798                     leftvt == VT_RECORD || rightvt == VT_RECORD ||
3799                     leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
3800                     leftvt == VT_ERROR || rightvt == VT_ERROR)
3801                 {
3802                     bFail = TRUE;
3803                 }
3804                 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
3805                 {
3806                     if (leftvt == rightvt ||
3807                         leftvt == VT_I2 || rightvt == VT_I2 ||
3808                         leftvt == VT_UI1 || rightvt == VT_UI1 ||
3809                         leftvt == VT_BOOL || rightvt == VT_BOOL)
3810                         resvt = VT_I2;
3811                     else if (leftvt == VT_NULL || rightvt == VT_NULL)
3812                         resvt = VT_NULL;
3813                     else if (leftvt == VT_I8 || rightvt == VT_I8)
3814                         resvt = VT_I8;
3815                 }
3816                 else if (leftvt == VT_NULL || rightvt == VT_NULL)
3817                 {
3818                     resvt = VT_NULL;
3819                 }
3820                 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
3821                 {
3822                     if (leftvt == rightvt)
3823                         resvt = VT_UI1;
3824                     else if (leftvt == rightvt ||
3825                         leftvt == VT_I2 || rightvt == VT_I2 ||
3826                         leftvt == VT_BOOL || rightvt == VT_BOOL)
3827                     {
3828                         resvt = VT_I2;
3829                     }
3830                     else if (leftvt == VT_I8 || rightvt == VT_I8)
3831                         resvt = VT_I8;
3832                 }
3833                 else if (leftvt == VT_I2 || rightvt == VT_I2)
3834                 {
3835                     if (leftvt == rightvt ||
3836                         leftvt == VT_BOOL || rightvt == VT_BOOL)
3837                         resvt = VT_I2;
3838                     else if (leftvt == VT_I8 || rightvt == VT_I8)
3839                         resvt = VT_I8;
3840                 }
3841                 else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
3842                 {
3843                     resvt = VT_BOOL;
3844                 }
3845                 else if (leftvt == VT_I8 || rightvt == VT_I8)
3846                 {
3847                     if (leftvt == VT_INT || rightvt == VT_INT)
3848                         bFail = TRUE;
3849                     else
3850                         resvt = VT_I8;
3851                 }
3852                 hres = pVarXor(&left, &right, &result);
3853                 if (bFail)
3854                     ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3855                        "VarXor: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
3856                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
3857                        V_VT(&result));
3858                 else
3859                     ok(hres == S_OK && V_VT(&result) == resvt,
3860                        "VarXor: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
3861                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
3862                        V_VT(&result));
3863             }
3864         }
3865     }
3866 
3867     /* Test returned values
3868      * FIXME: Test VT_DECIMAL/VT_DISPATCH
3869      */
3870     VARXOR(EMPTY,0,EMPTY,0,I2,0);
3871     VARXOR(EMPTY,1,EMPTY,0,I2,0);
3872     VARXOR(EMPTY,0,NULL,0,NULL,0);
3873     VARXOR(EMPTY,0,I1,0,I4,0);
3874     VARXOR(EMPTY,0,I1,1,I4,1);
3875     VARXOR(EMPTY,0,UI1,0,I2,0);
3876     VARXOR(EMPTY,0,UI1,1,I2,1);
3877     VARXOR(EMPTY,0,I2,0,I2,0);
3878     VARXOR(EMPTY,0,I2,1,I2,1);
3879     VARXOR(EMPTY,0,UI2,0,I4,0);
3880     VARXOR(EMPTY,0,UI2,1,I4,1);
3881     VARXOR(EMPTY,0,I4,0,I4,0);
3882     VARXOR(EMPTY,0,I4,1,I4,1);
3883     VARXOR(EMPTY,0,UI4,0,I4,0);
3884     VARXOR(EMPTY,0,UI4,1,I4,1);
3885     if (has_i8)
3886     {
3887         VARXOR(EMPTY,0,I8,0,I8,0);
3888         VARXOR(EMPTY,0,I8,1,I8,1);
3889         VARXOR(EMPTY,0,UI8,0,I4,0);
3890         VARXOR(EMPTY,0,UI8,1,I4,1);
3891     }
3892     VARXOR(EMPTY,0,INT,0,I4,0);
3893     VARXOR(EMPTY,0,INT,1,I4,1);
3894     VARXOR(EMPTY,0,UINT,0,I4,0);
3895     VARXOR(EMPTY,0,UINT,1,I4,1);
3896     VARXOR(EMPTY,0,BOOL,0,I2,0);
3897     VARXOR(EMPTY,0,BOOL,1,I2,1);
3898     VARXOR(EMPTY,0,R4,0,I4,0);
3899     VARXOR(EMPTY,0,R4,1,I4,1);
3900     VARXOR(EMPTY,0,R8,0,I4,0);
3901     VARXOR(EMPTY,0,R8,1,I4,1);
3902     rbstr = SysAllocString(szFalse);
3903     VARXOR(EMPTY,0,BSTR,rbstr,I2,0);
3904     SysFreeString(rbstr);
3905     rbstr = SysAllocString(szTrue);
3906     VARXOR(EMPTY,0,BSTR,rbstr,I2,-1);
3907     VARXORCY(EMPTY,0,10000,I4,1);
3908     SysFreeString(rbstr);
3909 
3910     /* NULL OR 0 = NULL. NULL OR n = n */
3911     VARXOR(NULL,0,NULL,0,NULL,0);
3912     VARXOR(NULL,1,NULL,0,NULL,0);
3913     VARXOR(NULL,0,I1,0,NULL,0);
3914     VARXOR(NULL,0,I1,1,NULL,0);
3915     VARXOR(NULL,0,UI1,0,NULL,0);
3916     VARXOR(NULL,0,UI1,1,NULL,0);
3917     VARXOR(NULL,0,I2,0,NULL,0);
3918     VARXOR(NULL,0,I2,1,NULL,0);
3919     VARXOR(NULL,0,UI2,0,NULL,0);
3920     VARXOR(NULL,0,UI2,1,NULL,0);
3921     VARXOR(NULL,0,I4,0,NULL,0);
3922     VARXOR(NULL,0,I4,1,NULL,0);
3923     VARXOR(NULL,0,UI4,0,NULL,0);
3924     VARXOR(NULL,0,UI4,1,NULL,0);
3925     if (has_i8)
3926     {
3927         VARXOR(NULL,0,I8,0,NULL,0);
3928         VARXOR(NULL,0,I8,1,NULL,0);
3929         VARXOR(NULL,0,UI8,0,NULL,0);
3930         VARXOR(NULL,0,UI8,1,NULL,0);
3931     }
3932     VARXOR(NULL,0,INT,0,NULL,0);
3933     VARXOR(NULL,0,INT,1,NULL,0);
3934     VARXOR(NULL,0,UINT,0,NULL,0);
3935     VARXOR(NULL,0,UINT,1,NULL,0);
3936     VARXOR(NULL,0,BOOL,0,NULL,0);
3937     VARXOR(NULL,0,BOOL,1,NULL,0);
3938     VARXOR(NULL,0,R4,0,NULL,0);
3939     VARXOR(NULL,0,R4,1,NULL,0);
3940     VARXOR(NULL,0,R8,0,NULL,0);
3941     VARXOR(NULL,0,R8,1,NULL,0);
3942     rbstr = SysAllocString(szFalse);
3943     VARXOR(NULL,0,BSTR,rbstr,NULL,0);
3944     SysFreeString(rbstr);
3945     rbstr = SysAllocString(szTrue);
3946     VARXOR(NULL,0,BSTR,rbstr,NULL,0);
3947     SysFreeString(rbstr);
3948     VARXORCY(NULL,0,10000,NULL,0);
3949     VARXORCY(NULL,0,0,NULL,0);
3950 
3951     VARXOR(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
3952     VARXOR(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
3953     VARXOR(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
3954     VARXOR(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
3955     /* Assume x,y & y,x are the same from now on to reduce the number of tests */
3956     VARXOR(BOOL,VARIANT_TRUE,I1,-1,I4,0);
3957     VARXOR(BOOL,VARIANT_TRUE,I1,0,I4,-1);
3958     VARXOR(BOOL,VARIANT_FALSE,I1,0,I4,0);
3959     VARXOR(BOOL,VARIANT_TRUE,UI1,255,I2,-256);
3960     VARXOR(BOOL,VARIANT_TRUE,UI1,0,I2,-1);
3961     VARXOR(BOOL,VARIANT_FALSE,UI1,0,I2,0);
3962     VARXOR(BOOL,VARIANT_TRUE,I2,-1,I2,0);
3963     VARXOR(BOOL,VARIANT_TRUE,I2,0,I2,-1);
3964     VARXOR(BOOL,VARIANT_FALSE,I2,0,I2,0);
3965     VARXOR(BOOL,VARIANT_TRUE,UI2,65535,I4,-65536);
3966     VARXOR(BOOL,VARIANT_TRUE,UI2,0,I4,-1);
3967     VARXOR(BOOL,VARIANT_FALSE,UI2,0,I4,0);
3968     VARXOR(BOOL,VARIANT_TRUE,I4,-1,I4,0);
3969     VARXOR(BOOL,VARIANT_TRUE,I4,0,I4,-1);
3970     VARXOR(BOOL,VARIANT_FALSE,I4,0,I4,0);
3971     VARXOR(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,0);
3972     VARXOR(BOOL,VARIANT_TRUE,UI4,0,I4,-1);
3973     VARXOR(BOOL,VARIANT_FALSE,UI4,0,I4,0);
3974     VARXOR(BOOL,VARIANT_TRUE,R4,-1,I4,0);
3975     VARXOR(BOOL,VARIANT_TRUE,R4,0,I4,-1);
3976     VARXOR(BOOL,VARIANT_FALSE,R4,0,I4,0);
3977     VARXOR(BOOL,VARIANT_TRUE,R8,-1,I4,0);
3978     VARXOR(BOOL,VARIANT_TRUE,R8,0,I4,-1);
3979     VARXOR(BOOL,VARIANT_FALSE,R8,0,I4,0);
3980     VARXOR(BOOL,VARIANT_TRUE,DATE,-1,I4,0);
3981     VARXOR(BOOL,VARIANT_TRUE,DATE,0,I4,-1);
3982     VARXOR(BOOL,VARIANT_FALSE,DATE,0,I4,0);
3983     if (has_i8)
3984     {
3985         VARXOR(BOOL,VARIANT_TRUE,I8,-1,I8,0);
3986         VARXOR(BOOL,VARIANT_TRUE,I8,0,I8,-1);
3987         VARXOR(BOOL,VARIANT_FALSE,I8,0,I8,0);
3988         /* This returns DISP_E_OVERFLOW which indicates that a conversion
3989          * to I4 is performed.
3990          */
3991         /* VARXOR(BOOL,VARIANT_TRUE,UI8,-1,I4,-1); */
3992         VARXOR(BOOL,VARIANT_TRUE,UI8,0,I4,-1);
3993         VARXOR(BOOL,VARIANT_FALSE,UI8,0,I4,0);
3994     }
3995     VARXOR(BOOL,VARIANT_TRUE,INT,-1,I4,0);
3996     VARXOR(BOOL,VARIANT_TRUE,INT,0,I4,-1);
3997     VARXOR(BOOL,VARIANT_FALSE,INT,0,I4,0);
3998     VARXOR(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,0);
3999     VARXOR(BOOL,VARIANT_TRUE,UINT,0,I4,-1);
4000     VARXOR(BOOL,VARIANT_FALSE,UINT,0,I4,0);
4001     rbstr = SysAllocString(szFalse);
4002     VARXOR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_FALSE);
4003     VARXOR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
4004     SysFreeString(rbstr);
4005     rbstr = SysAllocString(szTrue);
4006     VARXOR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_TRUE);
4007     VARXOR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_FALSE);
4008     SysFreeString(rbstr);
4009     VARXORCY(BOOL,VARIANT_TRUE,10000,I4,-2);
4010     VARXORCY(BOOL,VARIANT_TRUE,0,I4,-1);
4011     VARXORCY(BOOL,VARIANT_FALSE,0,I4,0);
4012 
4013     VARXOR(I1,-1,I1,-1,I4,0);
4014     VARXOR(I1,-1,I1,0,I4,-1);
4015     VARXOR(I1,0,I1,0,I4,0);
4016     VARXOR(I1,-1,UI1,255,I4,-256);
4017     VARXOR(I1,-1,UI1,0,I4,-1);
4018     VARXOR(I1,0,UI1,0,I4,0);
4019     VARXOR(I1,-1,I2,-1,I4,0);
4020     VARXOR(I1,-1,I2,0,I4,-1);
4021     VARXOR(I1,0,I2,0,I4,0);
4022     VARXOR(I1,-1,UI2,65535,I4,-65536);
4023     VARXOR(I1,-1,UI2,0,I4,-1);
4024     VARXOR(I1,0,UI2,0,I4,0);
4025     VARXOR(I1,-1,I4,-1,I4,0);
4026     VARXOR(I1,-1,I4,0,I4,-1);
4027     VARXOR(I1,0,I4,0,I4,0);
4028     VARXOR(I1,-1,UI4,0xffffffff,I4,0);
4029     VARXOR(I1,-1,UI4,0,I4,-1);
4030     VARXOR(I1,0,UI4,0,I4,0);
4031     VARXOR(I1,-1,R4,-1,I4,0);
4032     VARXOR(I1,-1,R4,0,I4,-1);
4033     VARXOR(I1,0,R4,0,I4,0);
4034     VARXOR(I1,-1,R8,-1,I4,0);
4035     VARXOR(I1,-1,R8,0,I4,-1);
4036     VARXOR(I1,0,R8,0,I4,0);
4037     VARXOR(I1,-1,DATE,-1,I4,0);
4038     VARXOR(I1,-1,DATE,0,I4,-1);
4039     VARXOR(I1,0,DATE,0,I4,0);
4040     if (has_i8)
4041     {
4042         VARXOR(I1,-1,I8,-1,I8,0);
4043         VARXOR(I1,-1,I8,0,I8,-1);
4044         VARXOR(I1,0,I8,0,I8,0);
4045         VARXOR(I1,-1,UI8,0,I4,-1);
4046         VARXOR(I1,0,UI8,0,I4,0);
4047     }
4048     VARXOR(I1,-1,INT,-1,I4,0);
4049     VARXOR(I1,-1,INT,0,I4,-1);
4050     VARXOR(I1,0,INT,0,I4,0);
4051     VARXOR(I1,-1,UINT,0xffffffff,I4,0);
4052     VARXOR(I1,-1,UINT,0,I4,-1);
4053     VARXOR(I1,0,UINT,0,I4,0);
4054     rbstr = SysAllocString(szFalse);
4055     VARXOR(I1,0,BSTR,rbstr,I4,0);
4056     VARXOR(I1,-1,BSTR,rbstr,I4,-1);
4057     SysFreeString(rbstr);
4058     rbstr = SysAllocString(szTrue);
4059     VARXOR(I1,0,BSTR,rbstr,I4,-1);
4060     VARXOR(I1,-1,BSTR,rbstr,I4,0);
4061     SysFreeString(rbstr);
4062     VARXORCY(I1,-1,10000,I4,-2);
4063     VARXORCY(I1,-1,0,I4,-1);
4064     VARXORCY(I1,0,0,I4,0);
4065 
4066     VARXOR(UI1,255,UI1,255,UI1,0);
4067     VARXOR(UI1,255,UI1,0,UI1,255);
4068     VARXOR(UI1,0,UI1,0,UI1,0);
4069     VARXOR(UI1,255,I2,-1,I2,-256);
4070     VARXOR(UI1,255,I2,0,I2,255);
4071     VARXOR(UI1,0,I2,0,I2,0);
4072     VARXOR(UI1,255,UI2,65535,I4,65280);
4073     VARXOR(UI1,255,UI2,0,I4,255);
4074     VARXOR(UI1,0,UI2,0,I4,0);
4075     VARXOR(UI1,255,I4,-1,I4,-256);
4076     VARXOR(UI1,255,I4,0,I4,255);
4077     VARXOR(UI1,0,I4,0,I4,0);
4078     VARXOR(UI1,255,UI4,0xffffffff,I4,-256);
4079     VARXOR(UI1,255,UI4,0,I4,255);
4080     VARXOR(UI1,0,UI4,0,I4,0);
4081     VARXOR(UI1,255,R4,-1,I4,-256);
4082     VARXOR(UI1,255,R4,0,I4,255);
4083     VARXOR(UI1,0,R4,0,I4,0);
4084     VARXOR(UI1,255,R8,-1,I4,-256);
4085     VARXOR(UI1,255,R8,0,I4,255);
4086     VARXOR(UI1,0,R8,0,I4,0);
4087     VARXOR(UI1,255,DATE,-1,I4,-256);
4088     VARXOR(UI1,255,DATE,0,I4,255);
4089     VARXOR(UI1,0,DATE,0,I4,0);
4090     if (has_i8)
4091     {
4092         VARXOR(UI1,255,I8,-1,I8,-256);
4093         VARXOR(UI1,255,I8,0,I8,255);
4094         VARXOR(UI1,0,I8,0,I8,0);
4095         VARXOR(UI1,255,UI8,0,I4,255);
4096         VARXOR(UI1,0,UI8,0,I4,0);
4097     }
4098     VARXOR(UI1,255,INT,-1,I4,-256);
4099     VARXOR(UI1,255,INT,0,I4,255);
4100     VARXOR(UI1,0,INT,0,I4,0);
4101     VARXOR(UI1,255,UINT,0xffffffff,I4,-256);
4102     VARXOR(UI1,255,UINT,0,I4,255);
4103     VARXOR(UI1,0,UINT,0,I4,0);
4104     rbstr = SysAllocString(szFalse);
4105     VARXOR(UI1,0,BSTR,rbstr,I2,0);
4106     VARXOR(UI1,255,BSTR,rbstr,I2,255);
4107     SysFreeString(rbstr);
4108     rbstr = SysAllocString(szTrue);
4109     VARXOR(UI1,0,BSTR,rbstr,I2,-1);
4110     VARXOR(UI1,255,BSTR,rbstr,I2,-256);
4111     SysFreeString(rbstr);
4112     VARXORCY(UI1,255,10000,I4,254);
4113     VARXORCY(UI1,255,0,I4,255);
4114     VARXORCY(UI1,0,0,I4,0);
4115 
4116     VARXOR(I2,-1,I2,-1,I2,0);
4117     VARXOR(I2,-1,I2,0,I2,-1);
4118     VARXOR(I2,0,I2,0,I2,0);
4119     VARXOR(I2,-1,UI2,65535,I4,-65536);
4120     VARXOR(I2,-1,UI2,0,I4,-1);
4121     VARXOR(I2,0,UI2,0,I4,0);
4122     VARXOR(I2,-1,I4,-1,I4,0);
4123     VARXOR(I2,-1,I4,0,I4,-1);
4124     VARXOR(I2,0,I4,0,I4,0);
4125     VARXOR(I2,-1,UI4,0xffffffff,I4,0);
4126     VARXOR(I2,-1,UI4,0,I4,-1);
4127     VARXOR(I2,0,UI4,0,I4,0);
4128     VARXOR(I2,-1,R4,-1,I4,0);
4129     VARXOR(I2,-1,R4,0,I4,-1);
4130     VARXOR(I2,0,R4,0,I4,0);
4131     VARXOR(I2,-1,R8,-1,I4,0);
4132     VARXOR(I2,-1,R8,0,I4,-1);
4133     VARXOR(I2,0,R8,0,I4,0);
4134     VARXOR(I2,-1,DATE,-1,I4,0);
4135     VARXOR(I2,-1,DATE,0,I4,-1);
4136     VARXOR(I2,0,DATE,0,I4,0);
4137     if (has_i8)
4138     {
4139         VARXOR(I2,-1,I8,-1,I8,0);
4140         VARXOR(I2,-1,I8,0,I8,-1);
4141         VARXOR(I2,0,I8,0,I8,0);
4142         VARXOR(I2,-1,UI8,0,I4,-1);
4143         VARXOR(I2,0,UI8,0,I4,0);
4144     }
4145     VARXOR(I2,-1,INT,-1,I4,0);
4146     VARXOR(I2,-1,INT,0,I4,-1);
4147     VARXOR(I2,0,INT,0,I4,0);
4148     VARXOR(I2,-1,UINT,0xffffffff,I4,0);
4149     VARXOR(I2,-1,UINT,0,I4,-1);
4150     VARXOR(I2,0,UINT,0,I4,0);
4151     rbstr = SysAllocString(szFalse);
4152     VARXOR(I2,0,BSTR,rbstr,I2,0);
4153     VARXOR(I2,-1,BSTR,rbstr,I2,-1);
4154     SysFreeString(rbstr);
4155     rbstr = SysAllocString(szTrue);
4156     VARXOR(I2,0,BSTR,rbstr,I2,-1);
4157     VARXOR(I2,-1,BSTR,rbstr,I2,0);
4158     SysFreeString(rbstr);
4159     VARXORCY(I2,-1,10000,I4,-2);
4160     VARXORCY(I2,-1,0,I4,-1);
4161     VARXORCY(I2,0,0,I4,0);
4162 
4163     VARXOR(UI2,65535,UI2,65535,I4,0);
4164     VARXOR(UI2,65535,UI2,0,I4,65535);
4165     VARXOR(UI2,0,UI2,0,I4,0);
4166     VARXOR(UI2,65535,I4,-1,I4,-65536);
4167     VARXOR(UI2,65535,I4,0,I4,65535);
4168     VARXOR(UI2,0,I4,0,I4,0);
4169     VARXOR(UI2,65535,UI4,0xffffffff,I4,-65536);
4170     VARXOR(UI2,65535,UI4,0,I4,65535);
4171     VARXOR(UI2,0,UI4,0,I4,0);
4172     VARXOR(UI2,65535,R4,-1,I4,-65536);
4173     VARXOR(UI2,65535,R4,0,I4,65535);
4174     VARXOR(UI2,0,R4,0,I4,0);
4175     VARXOR(UI2,65535,R8,-1,I4,-65536);
4176     VARXOR(UI2,65535,R8,0,I4,65535);
4177     VARXOR(UI2,0,R8,0,I4,0);
4178     VARXOR(UI2,65535,DATE,-1,I4,-65536);
4179     VARXOR(UI2,65535,DATE,0,I4,65535);
4180     VARXOR(UI2,0,DATE,0,I4,0);
4181     if (has_i8)
4182     {
4183         VARXOR(UI2,65535,I8,-1,I8,-65536);
4184         VARXOR(UI2,65535,I8,0,I8,65535);
4185         VARXOR(UI2,0,I8,0,I8,0);
4186         VARXOR(UI2,65535,UI8,0,I4,65535);
4187         VARXOR(UI2,0,UI8,0,I4,0);
4188     }
4189     VARXOR(UI2,65535,INT,-1,I4,-65536);
4190     VARXOR(UI2,65535,INT,0,I4,65535);
4191     VARXOR(UI2,0,INT,0,I4,0);
4192     VARXOR(UI2,65535,UINT,0xffffffff,I4,-65536);
4193     VARXOR(UI2,65535,UINT,0,I4,65535);
4194     VARXOR(UI2,0,UINT,0,I4,0);
4195     rbstr = SysAllocString(szFalse);
4196     VARXOR(UI2,0,BSTR,rbstr,I4,0);
4197     VARXOR(UI2,65535,BSTR,rbstr,I4,65535);
4198     SysFreeString(rbstr);
4199     rbstr = SysAllocString(szTrue);
4200     VARXOR(UI2,0,BSTR,rbstr,I4,-1);
4201     VARXOR(UI2,65535,BSTR,rbstr,I4,-65536);
4202     SysFreeString(rbstr);
4203     VARXORCY(UI2,65535,10000,I4,65534);
4204     VARXORCY(UI2,65535,0,I4,65535);
4205     VARXORCY(UI2,0,0,I4,0);
4206 
4207     VARXOR(I4,-1,I4,-1,I4,0);
4208     VARXOR(I4,-1,I4,0,I4,-1);
4209     VARXOR(I4,0,I4,0,I4,0);
4210     VARXOR(I4,-1,UI4,0xffffffff,I4,0);
4211     VARXOR(I4,-1,UI4,0,I4,-1);
4212     VARXOR(I4,0,UI4,0,I4,0);
4213     VARXOR(I4,-1,R4,-1,I4,0);
4214     VARXOR(I4,-1,R4,0,I4,-1);
4215     VARXOR(I4,0,R4,0,I4,0);
4216     VARXOR(I4,-1,R8,-1,I4,0);
4217     VARXOR(I4,-1,R8,0,I4,-1);
4218     VARXOR(I4,0,R8,0,I4,0);
4219     VARXOR(I4,-1,DATE,-1,I4,0);
4220     VARXOR(I4,-1,DATE,0,I4,-1);
4221     VARXOR(I4,0,DATE,0,I4,0);
4222     if (has_i8)
4223     {
4224         VARXOR(I4,-1,I8,-1,I8,0);
4225         VARXOR(I4,-1,I8,0,I8,-1);
4226         VARXOR(I4,0,I8,0,I8,0);
4227         VARXOR(I4,-1,UI8,0,I4,-1);
4228         VARXOR(I4,0,UI8,0,I4,0);
4229     }
4230     VARXOR(I4,-1,INT,-1,I4,0);
4231     VARXOR(I4,-1,INT,0,I4,-1);
4232     VARXOR(I4,0,INT,0,I4,0);
4233     VARXOR(I4,-1,UINT,0xffffffff,I4,0);
4234     VARXOR(I4,-1,UINT,0,I4,-1);
4235     VARXOR(I4,0,UINT,0,I4,0);
4236     rbstr = SysAllocString(szFalse);
4237     VARXOR(I4,0,BSTR,rbstr,I4,0);
4238     VARXOR(I4,-1,BSTR,rbstr,I4,-1);
4239     SysFreeString(rbstr);
4240     rbstr = SysAllocString(szTrue);
4241     VARXOR(I4,0,BSTR,rbstr,I4,-1);
4242     VARXOR(I4,-1,BSTR,rbstr,I4,0);
4243     SysFreeString(rbstr);
4244     VARXORCY(I4,-1,10000,I4,-2);
4245     VARXORCY(I4,-1,0,I4,-1);
4246     VARXORCY(I4,0,0,I4,0);
4247 
4248     VARXOR(UI4,0xffffffff,UI4,0xffffffff,I4,0);
4249     VARXOR(UI4,0xffffffff,UI4,0,I4,-1);
4250     VARXOR(UI4,0,UI4,0,I4,0);
4251     VARXOR(UI4,0xffffffff,R4,-1,I4,0);
4252     VARXOR(UI4,0xffffffff,R4,0,I4,-1);
4253     VARXOR(UI4,0,R4,0,I4,0);
4254     VARXOR(UI4,0xffffffff,R8,-1,I4,0);
4255     VARXOR(UI4,0xffffffff,R8,0,I4,-1);
4256     VARXOR(UI4,0,R8,0,I4,0);
4257     VARXOR(UI4,0xffffffff,DATE,-1,I4,0);
4258     VARXOR(UI4,0xffffffff,DATE,0,I4,-1);
4259     VARXOR(UI4,0,DATE,0,I4,0);
4260     if (has_i8)
4261     {
4262         VARXOR(UI4,0xffffffff,I8,0,I8,0xffffffff);
4263         VARXOR(UI4,VARIANT_FALSE,I8,VARIANT_FALSE,I8,0);
4264         VARXOR(UI4,0,I8,0,I8,0);
4265         VARXOR(UI4,0xffffffff,UI8,0,I4,-1);
4266         VARXOR(UI4,0,UI8,0,I4,0);
4267     }
4268     VARXOR(UI4,0xffffffff,INT,-1,I4,0);
4269     VARXOR(UI4,0xffffffff,INT,0,I4,-1);
4270     VARXOR(UI4,0,INT,0,I4,0);
4271     VARXOR(UI4,0xffffffff,UINT,0xffffffff,I4,0);
4272     VARXOR(UI4,0xffffffff,UINT,0,I4,-1);
4273     VARXOR(UI4,0,UINT,0,I4,0);
4274     rbstr = SysAllocString(szFalse);
4275     VARXOR(UI4,0,BSTR,rbstr,I4,0);
4276     VARXOR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
4277     SysFreeString(rbstr);
4278     rbstr = SysAllocString(szTrue);
4279     VARXOR(UI4,0,BSTR,rbstr,I4,-1);
4280     VARXOR(UI4,0xffffffff,BSTR,rbstr,I4,0);
4281     SysFreeString(rbstr);
4282     VARXORCY(UI4,0xffffffff,10000,I4,-2);
4283     VARXORCY(UI4,0xffffffff,0,I4,-1);
4284     VARXORCY(UI4,0,0,I4,0);
4285 
4286     VARXOR(R4,-1,R4,-1,I4,0);
4287     VARXOR(R4,-1,R4,0,I4,-1);
4288     VARXOR(R4,0,R4,0,I4,0);
4289     VARXOR(R4,-1,R8,-1,I4,0);
4290     VARXOR(R4,-1,R8,0,I4,-1);
4291     VARXOR(R4,0,R8,0,I4,0);
4292     VARXOR(R4,-1,DATE,-1,I4,0);
4293     VARXOR(R4,-1,DATE,0,I4,-1);
4294     VARXOR(R4,0,DATE,0,I4,0);
4295     if (has_i8)
4296     {
4297         VARXOR(R4,-1,I8,-1,I8,0);
4298         VARXOR(R4,-1,I8,0,I8,-1);
4299         VARXOR(R4,0,I8,0,I8,0);
4300         VARXOR(R4,-1,UI8,0,I4,-1);
4301         VARXOR(R4,0,UI8,0,I4,0);
4302     }
4303     VARXOR(R4,-1,INT,-1,I4,0);
4304     VARXOR(R4,-1,INT,0,I4,-1);
4305     VARXOR(R4,0,INT,0,I4,0);
4306     VARXOR(R4,-1,UINT,0xffffffff,I4,0);
4307     VARXOR(R4,-1,UINT,0,I4,-1);
4308     VARXOR(R4,0,UINT,0,I4,0);
4309     rbstr = SysAllocString(szFalse);
4310     VARXOR(R4,0,BSTR,rbstr,I4,0);
4311     VARXOR(R4,-1,BSTR,rbstr,I4,-1);
4312     SysFreeString(rbstr);
4313     rbstr = SysAllocString(szTrue);
4314     VARXOR(R4,0,BSTR,rbstr,I4,-1);
4315     VARXOR(R4,-1,BSTR,rbstr,I4,0);
4316     SysFreeString(rbstr);
4317     VARXORCY(R4,-1,10000,I4,-2);
4318     VARXORCY(R4,-1,0,I4,-1);
4319     VARXORCY(R4,0,0,I4,0);
4320 
4321     VARXOR(R8,-1,R8,-1,I4,0);
4322     VARXOR(R8,-1,R8,0,I4,-1);
4323     VARXOR(R8,0,R8,0,I4,0);
4324     VARXOR(R8,-1,DATE,-1,I4,0);
4325     VARXOR(R8,-1,DATE,0,I4,-1);
4326     VARXOR(R8,0,DATE,0,I4,0);
4327     if (has_i8)
4328     {
4329         VARXOR(R8,-1,I8,-1,I8,0);
4330         VARXOR(R8,-1,I8,0,I8,-1);
4331         VARXOR(R8,0,I8,0,I8,0);
4332         VARXOR(R8,-1,UI8,0,I4,-1);
4333         VARXOR(R8,0,UI8,0,I4,0);
4334     }
4335     VARXOR(R8,-1,INT,-1,I4,0);
4336     VARXOR(R8,-1,INT,0,I4,-1);
4337     VARXOR(R8,0,INT,0,I4,0);
4338     VARXOR(R8,-1,UINT,0xffffffff,I4,0);
4339     VARXOR(R8,-1,UINT,0,I4,-1);
4340     VARXOR(R8,0,UINT,0,I4,0);
4341     rbstr = SysAllocString(szFalse);
4342     VARXOR(R8,0,BSTR,rbstr,I4,0);
4343     VARXOR(R8,-1,BSTR,rbstr,I4,-1);
4344     SysFreeString(rbstr);
4345     rbstr = SysAllocString(szTrue);
4346     VARXOR(R8,0,BSTR,rbstr,I4,-1);
4347     VARXOR(R8,-1,BSTR,rbstr,I4,0);
4348     SysFreeString(rbstr);
4349     VARXORCY(R8,-1,10000,I4,-2);
4350     VARXORCY(R8,-1,0,I4,-1);
4351     VARXORCY(R8,0,0,I4,0);
4352 
4353     VARXOR(DATE,-1,DATE,-1,I4,0);
4354     VARXOR(DATE,-1,DATE,0,I4,-1);
4355     VARXOR(DATE,0,DATE,0,I4,0);
4356     if (has_i8)
4357     {
4358         VARXOR(DATE,-1,I8,-1,I8,0);
4359         VARXOR(DATE,-1,I8,0,I8,-1);
4360         VARXOR(DATE,0,I8,0,I8,0);
4361         VARXOR(DATE,-1,UI8,0,I4,-1);
4362         VARXOR(DATE,0,UI8,0,I4,0);
4363     }
4364     VARXOR(DATE,-1,INT,-1,I4,0);
4365     VARXOR(DATE,-1,INT,0,I4,-1);
4366     VARXOR(DATE,0,INT,0,I4,0);
4367     VARXOR(DATE,-1,UINT,0xffffffff,I4,0);
4368     VARXOR(DATE,-1,UINT,0,I4,-1);
4369     VARXOR(DATE,0,UINT,0,I4,0);
4370     rbstr = SysAllocString(szFalse);
4371     VARXOR(DATE,0,BSTR,rbstr,I4,0);
4372     VARXOR(DATE,-1,BSTR,rbstr,I4,-1);
4373     SysFreeString(rbstr);
4374     rbstr = SysAllocString(szTrue);
4375     VARXOR(DATE,0,BSTR,rbstr,I4,-1);
4376     VARXOR(DATE,-1,BSTR,rbstr,I4,0);
4377     SysFreeString(rbstr);
4378     VARXORCY(DATE,-1,10000,I4,-2);
4379     VARXORCY(DATE,-1,0,I4,-1);
4380     VARXORCY(DATE,0,0,I4,0);
4381 
4382     if (has_i8)
4383     {
4384         VARXOR(I8,-1,I8,-1,I8,0);
4385         VARXOR(I8,-1,I8,0,I8,-1);
4386         VARXOR(I8,0,I8,0,I8,0);
4387         VARXOR(I8,-1,UI8,0,I8,-1);
4388         VARXOR(I8,0,UI8,0,I8,0);
4389         VARXOR(I8,-1,UINT,0,I8,-1);
4390         VARXOR(I8,0,UINT,0,I8,0);
4391         rbstr = SysAllocString(szFalse);
4392         VARXOR(I8,0,BSTR,rbstr,I8,0);
4393         VARXOR(I8,-1,BSTR,rbstr,I8,-1);
4394         SysFreeString(rbstr);
4395         rbstr = SysAllocString(szTrue);
4396         VARXOR(I8,0,BSTR,rbstr,I8,-1);
4397         VARXOR(I8,-1,BSTR,rbstr,I8,0);
4398         SysFreeString(rbstr);
4399         VARXORCY(I8,-1,10000,I8,-2);
4400         VARXORCY(I8,-1,0,I8,-1);
4401         VARXORCY(I8,0,0,I8,0);
4402 
4403         VARXOR(UI8,0xffff,UI8,0xffff,I4,0);
4404         VARXOR(UI8,0xffff,UI8,0,I4,0xffff);
4405         VARXOR(UI8,0,UI8,0,I4,0);
4406         VARXOR(UI8,0xffff,INT,-1,I4,-65536);
4407         VARXOR(UI8,0xffff,INT,0,I4,0xffff);
4408         VARXOR(UI8,0,INT,0,I4,0);
4409         VARXOR(UI8,0xffff,UINT,0xffff,I4,0);
4410         VARXOR(UI8,0xffff,UINT,0,I4,0xffff);
4411         VARXOR(UI8,0,UINT,0,I4,0);
4412         rbstr = SysAllocString(szFalse);
4413         VARXOR(UI8,0,BSTR,rbstr,I4,0);
4414         VARXOR(UI8,0xffff,BSTR,rbstr,I4,0xffff);
4415         SysFreeString(rbstr);
4416         rbstr = SysAllocString(szTrue);
4417         VARXOR(UI8,0,BSTR,rbstr,I4,-1);
4418         VARXOR(UI8,0xffff,BSTR,rbstr,I4,-65536);
4419         SysFreeString(rbstr);
4420         VARXORCY(UI8,0xffff,10000,I4,65534);
4421         VARXORCY(UI8,0xffff,0,I4,0xffff);
4422         VARXORCY(UI8,0,0,I4,0);
4423     }
4424 
4425     VARXOR(INT,-1,INT,-1,I4,0);
4426     VARXOR(INT,-1,INT,0,I4,-1);
4427     VARXOR(INT,0,INT,0,I4,0);
4428     VARXOR(INT,-1,UINT,0xffff,I4,-65536);
4429     VARXOR(INT,-1,UINT,0,I4,-1);
4430     VARXOR(INT,0,UINT,0,I4,0);
4431     rbstr = SysAllocString(szFalse);
4432     VARXOR(INT,0,BSTR,rbstr,I4,0);
4433     VARXOR(INT,-1,BSTR,rbstr,I4,-1);
4434     SysFreeString(rbstr);
4435     rbstr = SysAllocString(szTrue);
4436     VARXOR(INT,0,BSTR,rbstr,I4,-1);
4437     VARXOR(INT,-1,BSTR,rbstr,I4,0);
4438     SysFreeString(rbstr);
4439     VARXORCY(INT,-1,10000,I4,-2);
4440     VARXORCY(INT,-1,0,I4,-1);
4441     VARXORCY(INT,0,0,I4,0);
4442 
4443     VARXOR(UINT,0xffff,UINT,0xffff,I4,0);
4444     VARXOR(UINT,0xffff,UINT,0,I4,0xffff);
4445     VARXOR(UINT,0,UINT,0,I4,0);
4446     rbstr = SysAllocString(szFalse);
4447     VARXOR(UINT,0,BSTR,rbstr,I4,0);
4448     VARXOR(UINT,0xffff,BSTR,rbstr,I4,0xffff);
4449     SysFreeString(rbstr);
4450     rbstr = SysAllocString(szTrue);
4451     VARXOR(UINT,0,BSTR,rbstr,I4,-1);
4452     VARXOR(UINT,0xffff,BSTR,rbstr,I4,-65536);
4453     SysFreeString(rbstr);
4454     VARXORCY(UINT,0xffff,10000,I4,65534);
4455     VARXORCY(UINT,0xffff,0,I4,0xffff);
4456     VARXORCY(UINT,0,0,I4,0);
4457 
4458     lbstr = SysAllocString(szFalse);
4459     rbstr = SysAllocString(szFalse);
4460     VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,0);
4461     SysFreeString(rbstr);
4462     rbstr = SysAllocString(szTrue);
4463     VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
4464     SysFreeString(lbstr);
4465     lbstr = SysAllocString(szTrue);
4466     VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_FALSE);
4467     VARXORCY(BSTR,lbstr,10000,I4,-2);
4468     SysFreeString(lbstr);
4469     lbstr = SysAllocString(szFalse);
4470     VARXORCY(BSTR,lbstr,10000,I4,1);
4471     SysFreeString(lbstr);
4472     SysFreeString(rbstr);
4473 }
4474 
4475 static HRESULT (WINAPI *pVarOr)(LPVARIANT,LPVARIANT,LPVARIANT);
4476 
4477 #define VAROR(vt1,val1,vt2,val2,rvt,rval)                \
4478         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
4479         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
4480         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
4481         test_var_call2( __LINE__, pVarOr, &left, &right, &exp )
4482 
4483 #define VARORCY(vt1,val1,val2,rvt,rval)                  \
4484         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
4485         V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \
4486         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
4487         test_var_call2( __LINE__, pVarOr, &left, &right, &exp )
4488 
4489 static void test_VarOr(void)
4490 {
4491     static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
4492     static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
4493     VARIANT left, right, exp, result;
4494     BSTR lbstr, rbstr;
4495     VARTYPE i;
4496     HRESULT hres;
4497 
4498     CHECKPTR(VarOr);
4499 
4500     /* Test all possible flag/vt combinations & the resulting vt type */
4501     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
4502     {
4503         VARTYPE leftvt, rightvt, resvt;
4504 
4505         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
4506         {
4507 
4508             SKIPTESTS(leftvt);
4509 
4510             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
4511             {
4512                 BOOL bFail = FALSE;
4513 
4514                 SKIPTESTS(rightvt);
4515 
4516                 if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
4517                     leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
4518                     leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
4519                     continue;
4520 
4521                 memset(&left, 0, sizeof(left));
4522                 memset(&right, 0, sizeof(right));
4523                 V_VT(&left) = leftvt | ExtraFlags[i];
4524                 V_VT(&right) = rightvt | ExtraFlags[i];
4525                 V_VT(&result) = VT_EMPTY;
4526                 resvt = VT_I4;
4527 
4528                 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
4529                     !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
4530                     !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
4531                     leftvt == VT_CLSID || rightvt == VT_CLSID ||
4532                     leftvt == VT_RECORD || rightvt == VT_RECORD ||
4533                     leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
4534                     leftvt == VT_ERROR || rightvt == VT_ERROR)
4535                 {
4536                     bFail = TRUE;
4537                 }
4538                 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
4539                 {
4540                     if (leftvt == rightvt ||
4541                         leftvt == VT_I2 || rightvt == VT_I2 ||
4542                         leftvt == VT_UI1 || rightvt == VT_UI1 ||
4543                         leftvt == VT_BOOL || rightvt == VT_BOOL)
4544                         resvt = VT_I2;
4545                     else if (leftvt == VT_NULL || rightvt == VT_NULL)
4546                         resvt = VT_NULL;
4547                     else if (leftvt == VT_I8 || rightvt == VT_I8)
4548                         resvt = VT_I8;
4549                 }
4550                 else if (leftvt == VT_NULL || rightvt == VT_NULL)
4551                 {
4552                     resvt = VT_NULL;
4553                 }
4554                 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
4555                 {
4556                     if (leftvt == rightvt)
4557                         resvt = VT_UI1;
4558                     else if (leftvt == rightvt ||
4559                         leftvt == VT_I2 || rightvt == VT_I2 ||
4560                         leftvt == VT_BOOL || rightvt == VT_BOOL)
4561                     {
4562                         resvt = VT_I2;
4563                     }
4564                     else if (leftvt == VT_I8 || rightvt == VT_I8)
4565                         resvt = VT_I8;
4566                 }
4567                 else if (leftvt == VT_I2 || rightvt == VT_I2)
4568                 {
4569                     if (leftvt == rightvt ||
4570                         leftvt == VT_BOOL || rightvt == VT_BOOL)
4571                         resvt = VT_I2;
4572                     else if (leftvt == VT_I8 || rightvt == VT_I8)
4573                         resvt = VT_I8;
4574                 }
4575                 else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
4576                 {
4577                     resvt = VT_BOOL;
4578                 }
4579                 else if (leftvt == VT_I8 || rightvt == VT_I8)
4580                 {
4581                     if (leftvt == VT_INT || rightvt == VT_INT)
4582                         bFail = TRUE;
4583                     else
4584                         resvt = VT_I8;
4585                 }
4586                 hres = pVarOr(&left, &right, &result);
4587                 if (bFail)
4588                     ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
4589                        "VarOr: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
4590                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
4591                        V_VT(&result));
4592                 else
4593                     ok(hres == S_OK && V_VT(&result) == resvt,
4594                        "VarOr: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
4595                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
4596                        V_VT(&result));
4597             }
4598         }
4599     }
4600 
4601     /* Test returned values. Since we know the returned type is correct
4602      * and that we handle all combinations of invalid types, just check
4603      * that good type combinations produce the desired value.
4604      * FIXME: Test VT_DECIMAL/VT_DISPATCH
4605      */
4606     VAROR(EMPTY,0,EMPTY,0,I2,0);
4607     VAROR(EMPTY,1,EMPTY,0,I2,0);
4608     VAROR(EMPTY,0,NULL,0,NULL,0);
4609     VAROR(EMPTY,0,I1,0,I4,0);
4610     VAROR(EMPTY,0,I1,1,I4,1);
4611     VAROR(EMPTY,0,UI1,0,I2,0);
4612     VAROR(EMPTY,0,UI1,1,I2,1);
4613     VAROR(EMPTY,0,I2,0,I2,0);
4614     VAROR(EMPTY,0,I2,1,I2,1);
4615     VAROR(EMPTY,0,UI2,0,I4,0);
4616     VAROR(EMPTY,0,UI2,1,I4,1);
4617     VAROR(EMPTY,0,I4,0,I4,0);
4618     VAROR(EMPTY,0,I4,1,I4,1);
4619     VAROR(EMPTY,0,UI4,0,I4,0);
4620     VAROR(EMPTY,0,UI4,1,I4,1);
4621     if (has_i8)
4622     {
4623         VAROR(EMPTY,0,I8,0,I8,0);
4624         VAROR(EMPTY,0,I8,1,I8,1);
4625         VAROR(EMPTY,0,UI8,0,I4,0);
4626         VAROR(EMPTY,0,UI8,1,I4,1);
4627     }
4628     VAROR(EMPTY,0,INT,0,I4,0);
4629     VAROR(EMPTY,0,INT,1,I4,1);
4630     VAROR(EMPTY,0,UINT,0,I4,0);
4631     VAROR(EMPTY,0,UINT,1,I4,1);
4632     VAROR(EMPTY,0,BOOL,0,I2,0);
4633     VAROR(EMPTY,0,BOOL,1,I2,1);
4634     VAROR(EMPTY,0,R4,0,I4,0);
4635     VAROR(EMPTY,0,R4,1,I4,1);
4636     VAROR(EMPTY,0,R8,0,I4,0);
4637     VAROR(EMPTY,0,R8,1,I4,1);
4638     rbstr = SysAllocString(szFalse);
4639     VAROR(EMPTY,0,BSTR,rbstr,I2,0);
4640     SysFreeString(rbstr);
4641     rbstr = SysAllocString(szTrue);
4642     VAROR(EMPTY,0,BSTR,rbstr,I2,-1);
4643     SysFreeString(rbstr);
4644     VARORCY(EMPTY,0,10000,I4,1);
4645 
4646     /* NULL OR 0 = NULL. NULL OR n = n */
4647     VAROR(NULL,0,NULL,0,NULL,0);
4648     VAROR(NULL,1,NULL,0,NULL,0);
4649     VAROR(NULL,0,I1,0,NULL,0);
4650     VAROR(NULL,0,I1,1,I4,1);
4651     VAROR(NULL,0,UI1,0,NULL,0);
4652     VAROR(NULL,0,UI1,1,UI1,1);
4653     VAROR(NULL,0,I2,0,NULL,0);
4654     VAROR(NULL,0,I2,1,I2,1);
4655     VAROR(NULL,0,UI2,0,NULL,0);
4656     VAROR(NULL,0,UI2,1,I4,1);
4657     VAROR(NULL,0,I4,0,NULL,0);
4658     VAROR(NULL,0,I4,1,I4,1);
4659     VAROR(NULL,0,UI4,0,NULL,0);
4660     VAROR(NULL,0,UI4,1,I4,1);
4661     if (has_i8)
4662     {
4663         VAROR(NULL,0,I8,0,NULL,0);
4664         VAROR(NULL,0,I8,1,I8,1);
4665         VAROR(NULL,0,UI8,0,NULL,0);
4666         VAROR(NULL,0,UI8,1,I4,1);
4667     }
4668     VAROR(NULL,0,INT,0,NULL,0);
4669     VAROR(NULL,0,INT,1,I4,1);
4670     VAROR(NULL,0,UINT,0,NULL,0);
4671     VAROR(NULL,0,UINT,1,I4,1);
4672     VAROR(NULL,0,BOOL,0,NULL,0);
4673     VAROR(NULL,0,BOOL,1,BOOL,1);
4674     VAROR(NULL,0,R4,0,NULL,0);
4675     VAROR(NULL,0,R4,1,I4,1);
4676     VAROR(NULL,0,R8,0,NULL,0);
4677     VAROR(NULL,0,R8,1,I4,1);
4678     rbstr = SysAllocString(szFalse);
4679     VAROR(NULL,0,BSTR,rbstr,NULL,0);
4680     SysFreeString(rbstr);
4681     rbstr = SysAllocString(szTrue);
4682     VAROR(NULL,0,BSTR,rbstr,BOOL,VARIANT_TRUE);
4683     SysFreeString(rbstr);
4684     VARORCY(NULL,0,10000,I4,1);
4685     VARORCY(NULL,0,0,NULL,0);
4686 
4687     VAROR(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
4688     VAROR(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
4689     VAROR(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
4690     VAROR(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
4691     /* Assume x,y & y,x are the same from now on to reduce the number of tests */
4692     VAROR(BOOL,VARIANT_TRUE,I1,-1,I4,-1);
4693     VAROR(BOOL,VARIANT_TRUE,I1,0,I4,-1);
4694     VAROR(BOOL,VARIANT_FALSE,I1,0,I4,0);
4695     VAROR(BOOL,VARIANT_TRUE,UI1,255,I2,-1);
4696     VAROR(BOOL,VARIANT_TRUE,UI1,0,I2,-1);
4697     VAROR(BOOL,VARIANT_FALSE,UI1,0,I2,0);
4698     VAROR(BOOL,VARIANT_TRUE,I2,-1,I2,-1);
4699     VAROR(BOOL,VARIANT_TRUE,I2,0,I2,-1);
4700     VAROR(BOOL,VARIANT_FALSE,I2,0,I2,0);
4701     VAROR(BOOL,VARIANT_TRUE,UI2,65535,I4,-1);
4702     VAROR(BOOL,VARIANT_TRUE,UI2,0,I4,-1);
4703     VAROR(BOOL,VARIANT_FALSE,UI2,0,I4,0);
4704     VAROR(BOOL,VARIANT_TRUE,I4,-1,I4,-1);
4705     VAROR(BOOL,VARIANT_TRUE,I4,0,I4,-1);
4706     VAROR(BOOL,VARIANT_FALSE,I4,0,I4,0);
4707     VAROR(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,-1);
4708     VAROR(BOOL,VARIANT_TRUE,UI4,0,I4,-1);
4709     VAROR(BOOL,VARIANT_FALSE,UI4,0,I4,0);
4710     VAROR(BOOL,VARIANT_TRUE,R4,-1,I4,-1);
4711     VAROR(BOOL,VARIANT_TRUE,R4,0,I4,-1);
4712     VAROR(BOOL,VARIANT_FALSE,R4,0,I4,0);
4713     VAROR(BOOL,VARIANT_TRUE,R8,-1,I4,-1);
4714     VAROR(BOOL,VARIANT_TRUE,R8,0,I4,-1);
4715     VAROR(BOOL,VARIANT_FALSE,R8,0,I4,0);
4716     VAROR(BOOL,VARIANT_TRUE,DATE,-1,I4,-1);
4717     VAROR(BOOL,VARIANT_TRUE,DATE,0,I4,-1);
4718     VAROR(BOOL,VARIANT_FALSE,DATE,0,I4,0);
4719     if (has_i8)
4720     {
4721         VAROR(BOOL,VARIANT_TRUE,I8,-1,I8,-1);
4722         VAROR(BOOL,VARIANT_TRUE,I8,0,I8,-1);
4723         VAROR(BOOL,VARIANT_FALSE,I8,0,I8,0);
4724         /* This returns DISP_E_OVERFLOW which indicates that a conversion
4725          * to I4 is performed.
4726          */
4727         /* VAROR(BOOL,VARIANT_TRUE,UI8,-1,I4,-1); */
4728         VAROR(BOOL,VARIANT_TRUE,UI8,0,I4,-1);
4729         VAROR(BOOL,VARIANT_FALSE,UI8,0,I4,0);
4730     }
4731     VAROR(BOOL,VARIANT_TRUE,INT,-1,I4,-1);
4732     VAROR(BOOL,VARIANT_TRUE,INT,0,I4,-1);
4733     VAROR(BOOL,VARIANT_FALSE,INT,0,I4,0);
4734     VAROR(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,-1);
4735     VAROR(BOOL,VARIANT_TRUE,UINT,0,I4,-1);
4736     VAROR(BOOL,VARIANT_FALSE,UINT,0,I4,0);
4737     rbstr = SysAllocString(szFalse);
4738     VAROR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_FALSE);
4739     VAROR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
4740     SysFreeString(rbstr);
4741     rbstr = SysAllocString(szTrue);
4742     VAROR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_TRUE);
4743     VAROR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
4744     SysFreeString(rbstr);
4745     VARORCY(BOOL,VARIANT_TRUE,10000,I4,-1);
4746     VARORCY(BOOL,VARIANT_TRUE,0,I4,-1);
4747     VARORCY(BOOL,VARIANT_FALSE,0,I4,0);
4748 
4749     VAROR(I1,-1,I1,-1,I4,-1);
4750     VAROR(I1,-1,I1,0,I4,-1);
4751     VAROR(I1,0,I1,0,I4,0);
4752     VAROR(I1,-1,UI1,255,I4,-1);
4753     VAROR(I1,-1,UI1,0,I4,-1);
4754     VAROR(I1,0,UI1,0,I4,0);
4755     VAROR(I1,-1,I2,-1,I4,-1);
4756     VAROR(I1,-1,I2,0,I4,-1);
4757     VAROR(I1,0,I2,0,I4,0);
4758     VAROR(I1,-1,UI2,65535,I4,-1);
4759     VAROR(I1,-1,UI2,0,I4,-1);
4760     VAROR(I1,0,UI2,0,I4,0);
4761     VAROR(I1,-1,I4,-1,I4,-1);
4762     VAROR(I1,-1,I4,0,I4,-1);
4763     VAROR(I1,0,I4,0,I4,0);
4764     VAROR(I1,-1,UI4,0xffffffff,I4,-1);
4765     VAROR(I1,-1,UI4,0,I4,-1);
4766     VAROR(I1,0,UI4,0,I4,0);
4767     VAROR(I1,-1,R4,-1,I4,-1);
4768     VAROR(I1,-1,R4,0,I4,-1);
4769     VAROR(I1,0,R4,0,I4,0);
4770     VAROR(I1,-1,R8,-1,I4,-1);
4771     VAROR(I1,-1,R8,0,I4,-1);
4772     VAROR(I1,0,R8,0,I4,0);
4773     VAROR(I1,-1,DATE,-1,I4,-1);
4774     VAROR(I1,-1,DATE,0,I4,-1);
4775     VAROR(I1,0,DATE,0,I4,0);
4776     if (has_i8)
4777     {
4778         VAROR(I1,-1,I8,-1,I8,-1);
4779         VAROR(I1,-1,I8,0,I8,-1);
4780         VAROR(I1,0,I8,0,I8,0);
4781         VAROR(I1,-1,UI8,0,I4,-1);
4782         VAROR(I1,0,UI8,0,I4,0);
4783     }
4784     VAROR(I1,-1,INT,-1,I4,-1);
4785     VAROR(I1,-1,INT,0,I4,-1);
4786     VAROR(I1,0,INT,0,I4,0);
4787     VAROR(I1,-1,UINT,0xffffffff,I4,-1);
4788     VAROR(I1,-1,UINT,0,I4,-1);
4789     VAROR(I1,0,UINT,0,I4,0);
4790     rbstr = SysAllocString(szFalse);
4791     VAROR(I1,0,BSTR,rbstr,I4,0);
4792     VAROR(I1,-1,BSTR,rbstr,I4,-1);
4793     SysFreeString(rbstr);
4794     rbstr = SysAllocString(szTrue);
4795     VAROR(I1,0,BSTR,rbstr,I4,-1);
4796     VAROR(I1,-1,BSTR,rbstr,I4,-1);
4797     SysFreeString(rbstr);
4798     VARORCY(I1,-1,10000,I4,-1);
4799     VARORCY(I1,-1,0,I4,-1);
4800     VARORCY(I1,0,0,I4,0);
4801 
4802     VAROR(UI1,255,UI1,255,UI1,255);
4803     VAROR(UI1,255,UI1,0,UI1,255);
4804     VAROR(UI1,0,UI1,0,UI1,0);
4805     VAROR(UI1,255,I2,-1,I2,-1);
4806     VAROR(UI1,255,I2,0,I2,255);
4807     VAROR(UI1,0,I2,0,I2,0);
4808     VAROR(UI1,255,UI2,65535,I4,65535);
4809     VAROR(UI1,255,UI2,0,I4,255);
4810     VAROR(UI1,0,UI2,0,I4,0);
4811     VAROR(UI1,255,I4,-1,I4,-1);
4812     VAROR(UI1,255,I4,0,I4,255);
4813     VAROR(UI1,0,I4,0,I4,0);
4814     VAROR(UI1,255,UI4,0xffffffff,I4,-1);
4815     VAROR(UI1,255,UI4,0,I4,255);
4816     VAROR(UI1,0,UI4,0,I4,0);
4817     VAROR(UI1,255,R4,-1,I4,-1);
4818     VAROR(UI1,255,R4,0,I4,255);
4819     VAROR(UI1,0,R4,0,I4,0);
4820     VAROR(UI1,255,R8,-1,I4,-1);
4821     VAROR(UI1,255,R8,0,I4,255);
4822     VAROR(UI1,0,R8,0,I4,0);
4823     VAROR(UI1,255,DATE,-1,I4,-1);
4824     VAROR(UI1,255,DATE,0,I4,255);
4825     VAROR(UI1,0,DATE,0,I4,0);
4826     if (has_i8)
4827     {
4828         VAROR(UI1,255,I8,-1,I8,-1);
4829         VAROR(UI1,255,I8,0,I8,255);
4830         VAROR(UI1,0,I8,0,I8,0);
4831         VAROR(UI1,255,UI8,0,I4,255);
4832         VAROR(UI1,0,UI8,0,I4,0);
4833     }
4834     VAROR(UI1,255,INT,-1,I4,-1);
4835     VAROR(UI1,255,INT,0,I4,255);
4836     VAROR(UI1,0,INT,0,I4,0);
4837     VAROR(UI1,255,UINT,0xffffffff,I4,-1);
4838     VAROR(UI1,255,UINT,0,I4,255);
4839     VAROR(UI1,0,UINT,0,I4,0);
4840     rbstr = SysAllocString(szFalse);
4841     VAROR(UI1,0,BSTR,rbstr,I2,0);
4842     VAROR(UI1,255,BSTR,rbstr,I2,255);
4843     SysFreeString(rbstr);
4844     rbstr = SysAllocString(szTrue);
4845     VAROR(UI1,0,BSTR,rbstr,I2,-1);
4846     VAROR(UI1,255,BSTR,rbstr,I2,-1);
4847     SysFreeString(rbstr);
4848     VARORCY(UI1,255,10000,I4,255);
4849     VARORCY(UI1,255,0,I4,255);
4850     VARORCY(UI1,0,0,I4,0);
4851 
4852     VAROR(I2,-1,I2,-1,I2,-1);
4853     VAROR(I2,-1,I2,0,I2,-1);
4854     VAROR(I2,0,I2,0,I2,0);
4855     VAROR(I2,-1,UI2,65535,I4,-1);
4856     VAROR(I2,-1,UI2,0,I4,-1);
4857     VAROR(I2,0,UI2,0,I4,0);
4858     VAROR(I2,-1,I4,-1,I4,-1);
4859     VAROR(I2,-1,I4,0,I4,-1);
4860     VAROR(I2,0,I4,0,I4,0);
4861     VAROR(I2,-1,UI4,0xffffffff,I4,-1);
4862     VAROR(I2,-1,UI4,0,I4,-1);
4863     VAROR(I2,0,UI4,0,I4,0);
4864     VAROR(I2,-1,R4,-1,I4,-1);
4865     VAROR(I2,-1,R4,0,I4,-1);
4866     VAROR(I2,0,R4,0,I4,0);
4867     VAROR(I2,-1,R8,-1,I4,-1);
4868     VAROR(I2,-1,R8,0,I4,-1);
4869     VAROR(I2,0,R8,0,I4,0);
4870     VAROR(I2,-1,DATE,-1,I4,-1);
4871     VAROR(I2,-1,DATE,0,I4,-1);
4872     VAROR(I2,0,DATE,0,I4,0);
4873     if (has_i8)
4874     {
4875         VAROR(I2,-1,I8,-1,I8,-1);
4876         VAROR(I2,-1,I8,0,I8,-1);
4877         VAROR(I2,0,I8,0,I8,0);
4878         VAROR(I2,-1,UI8,0,I4,-1);
4879         VAROR(I2,0,UI8,0,I4,0);
4880     }
4881     VAROR(I2,-1,INT,-1,I4,-1);
4882     VAROR(I2,-1,INT,0,I4,-1);
4883     VAROR(I2,0,INT,0,I4,0);
4884     VAROR(I2,-1,UINT,0xffffffff,I4,-1);
4885     VAROR(I2,-1,UINT,0,I4,-1);
4886     VAROR(I2,0,UINT,0,I4,0);
4887     rbstr = SysAllocString(szFalse);
4888     VAROR(I2,0,BSTR,rbstr,I2,0);
4889     VAROR(I2,-1,BSTR,rbstr,I2,-1);
4890     SysFreeString(rbstr);
4891     rbstr = SysAllocString(szTrue);
4892     VAROR(I2,0,BSTR,rbstr,I2,-1);
4893     VAROR(I2,-1,BSTR,rbstr,I2,-1);
4894     SysFreeString(rbstr);
4895     VARORCY(I2,-1,10000,I4,-1);
4896     VARORCY(I2,-1,0,I4,-1);
4897     VARORCY(I2,0,0,I4,0);
4898 
4899     VAROR(UI2,65535,UI2,65535,I4,65535);
4900     VAROR(UI2,65535,UI2,0,I4,65535);
4901     VAROR(UI2,0,UI2,0,I4,0);
4902     VAROR(UI2,65535,I4,-1,I4,-1);
4903     VAROR(UI2,65535,I4,0,I4,65535);
4904     VAROR(UI2,0,I4,0,I4,0);
4905     VAROR(UI2,65535,UI4,0xffffffff,I4,-1);
4906     VAROR(UI2,65535,UI4,0,I4,65535);
4907     VAROR(UI2,0,UI4,0,I4,0);
4908     VAROR(UI2,65535,R4,-1,I4,-1);
4909     VAROR(UI2,65535,R4,0,I4,65535);
4910     VAROR(UI2,0,R4,0,I4,0);
4911     VAROR(UI2,65535,R8,-1,I4,-1);
4912     VAROR(UI2,65535,R8,0,I4,65535);
4913     VAROR(UI2,0,R8,0,I4,0);
4914     VAROR(UI2,65535,DATE,-1,I4,-1);
4915     VAROR(UI2,65535,DATE,0,I4,65535);
4916     VAROR(UI2,0,DATE,0,I4,0);
4917     if (has_i8)
4918     {
4919         VAROR(UI2,65535,I8,-1,I8,-1);
4920         VAROR(UI2,65535,I8,0,I8,65535);
4921         VAROR(UI2,0,I8,0,I8,0);
4922         VAROR(UI2,65535,UI8,0,I4,65535);
4923         VAROR(UI2,0,UI8,0,I4,0);
4924     }
4925     VAROR(UI2,65535,INT,-1,I4,-1);
4926     VAROR(UI2,65535,INT,0,I4,65535);
4927     VAROR(UI2,0,INT,0,I4,0);
4928     VAROR(UI2,65535,UINT,0xffffffff,I4,-1);
4929     VAROR(UI2,65535,UINT,0,I4,65535);
4930     VAROR(UI2,0,UINT,0,I4,0);
4931     rbstr = SysAllocString(szFalse);
4932     VAROR(UI2,0,BSTR,rbstr,I4,0);
4933     VAROR(UI2,65535,BSTR,rbstr,I4,65535);
4934     SysFreeString(rbstr);
4935     rbstr = SysAllocString(szTrue);
4936     VAROR(UI2,0,BSTR,rbstr,I4,-1);
4937     VAROR(UI2,65535,BSTR,rbstr,I4,-1);
4938     SysFreeString(rbstr);
4939     VARORCY(UI2,65535,10000,I4,65535);
4940     VARORCY(UI2,65535,0,I4,65535);
4941     VARORCY(UI2,0,0,I4,0);
4942 
4943     VAROR(I4,-1,I4,-1,I4,-1);
4944     VAROR(I4,-1,I4,0,I4,-1);
4945     VAROR(I4,0,I4,0,I4,0);
4946     VAROR(I4,-1,UI4,0xffffffff,I4,-1);
4947     VAROR(I4,-1,UI4,0,I4,-1);
4948     VAROR(I4,0,UI4,0,I4,0);
4949     VAROR(I4,-1,R4,-1,I4,-1);
4950     VAROR(I4,-1,R4,0,I4,-1);
4951     VAROR(I4,0,R4,0,I4,0);
4952     VAROR(I4,-1,R8,-1,I4,-1);
4953     VAROR(I4,-1,R8,0,I4,-1);
4954     VAROR(I4,0,R8,0,I4,0);
4955     VAROR(I4,-1,DATE,-1,I4,-1);
4956     VAROR(I4,-1,DATE,0,I4,-1);
4957     VAROR(I4,0,DATE,0,I4,0);
4958     if (has_i8)
4959     {
4960         VAROR(I4,-1,I8,-1,I8,-1);
4961         VAROR(I4,-1,I8,0,I8,-1);
4962         VAROR(I4,0,I8,0,I8,0);
4963         VAROR(I4,-1,UI8,0,I4,-1);
4964         VAROR(I4,0,UI8,0,I4,0);
4965     }
4966     VAROR(I4,-1,INT,-1,I4,-1);
4967     VAROR(I4,-1,INT,0,I4,-1);
4968     VAROR(I4,0,INT,0,I4,0);
4969     VAROR(I4,-1,UINT,0xffffffff,I4,-1);
4970     VAROR(I4,-1,UINT,0,I4,-1);
4971     VAROR(I4,0,UINT,0,I4,0);
4972     rbstr = SysAllocString(szFalse);
4973     VAROR(I4,0,BSTR,rbstr,I4,0);
4974     VAROR(I4,-1,BSTR,rbstr,I4,-1);
4975     SysFreeString(rbstr);
4976     rbstr = SysAllocString(szTrue);
4977     VAROR(I4,0,BSTR,rbstr,I4,-1);
4978     VAROR(I4,-1,BSTR,rbstr,I4,-1);
4979     SysFreeString(rbstr);
4980     VARORCY(I4,-1,10000,I4,-1);
4981     VARORCY(I4,-1,0,I4,-1);
4982     VARORCY(I4,0,0,I4,0);
4983 
4984     VAROR(UI4,0xffffffff,UI4,0xffffffff,I4,-1);
4985     VAROR(UI4,0xffffffff,UI4,0,I4,-1);
4986     VAROR(UI4,0,UI4,0,I4,0);
4987     VAROR(UI4,0xffffffff,R4,-1,I4,-1);
4988     VAROR(UI4,0xffffffff,R4,0,I4,-1);
4989     VAROR(UI4,0,R4,0,I4,0);
4990     VAROR(UI4,0xffffffff,R8,-1,I4,-1);
4991     VAROR(UI4,0xffffffff,R8,0,I4,-1);
4992     VAROR(UI4,0,R8,0,I4,0);
4993     VAROR(UI4,0xffffffff,DATE,-1,I4,-1);
4994     VAROR(UI4,0xffffffff,DATE,0,I4,-1);
4995     VAROR(UI4,0,DATE,0,I4,0);
4996     if (has_i8)
4997     {
4998         VAROR(UI4,0xffffffff,I8,-1,I8,-1);
4999         VAROR(UI4,0xffffffff,I8,0,I8,0xffffffff);
5000         VAROR(UI4,0,I8,0,I8,0);
5001         VAROR(UI4,0xffffffff,UI8,0,I4,-1);
5002         VAROR(UI4,0,UI8,0,I4,0);
5003     }
5004     VAROR(UI4,0xffffffff,INT,-1,I4,-1);
5005     VAROR(UI4,0xffffffff,INT,0,I4,-1);
5006     VAROR(UI4,0,INT,0,I4,0);
5007     VAROR(UI4,0xffffffff,UINT,0xffffffff,I4,-1);
5008     VAROR(UI4,0xffffffff,UINT,0,I4,-1);
5009     VAROR(UI4,0,UINT,0,I4,0);
5010     rbstr = SysAllocString(szFalse);
5011     VAROR(UI4,0,BSTR,rbstr,I4,0);
5012     VAROR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
5013     SysFreeString(rbstr);
5014     rbstr = SysAllocString(szTrue);
5015     VAROR(UI4,0,BSTR,rbstr,I4,-1);
5016     VAROR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
5017     SysFreeString(rbstr);
5018     VARORCY(UI4,0xffffffff,10000,I4,-1);
5019     VARORCY(UI4,0xffffffff,0,I4,-1);
5020     VARORCY(UI4,0,0,I4,0);
5021 
5022     VAROR(R4,-1,R4,-1,I4,-1);
5023     VAROR(R4,-1,R4,0,I4,-1);
5024     VAROR(R4,0,R4,0,I4,0);
5025     VAROR(R4,-1,R8,-1,I4,-1);
5026     VAROR(R4,-1,R8,0,I4,-1);
5027     VAROR(R4,0,R8,0,I4,0);
5028     VAROR(R4,-1,DATE,-1,I4,-1);
5029     VAROR(R4,-1,DATE,0,I4,-1);
5030     VAROR(R4,0,DATE,0,I4,0);
5031     if (has_i8)
5032     {
5033         VAROR(R4,-1,I8,-1,I8,-1);
5034         VAROR(R4,-1,I8,0,I8,-1);
5035         VAROR(R4,0,I8,0,I8,0);
5036         VAROR(R4,-1,UI8,0,I4,-1);
5037         VAROR(R4,0,UI8,0,I4,0);
5038     }
5039     VAROR(R4,-1,INT,-1,I4,-1);
5040     VAROR(R4,-1,INT,0,I4,-1);
5041     VAROR(R4,0,INT,0,I4,0);
5042     VAROR(R4,-1,UINT,0xffffffff,I4,-1);
5043     VAROR(R4,-1,UINT,0,I4,-1);
5044     VAROR(R4,0,UINT,0,I4,0);
5045     rbstr = SysAllocString(szFalse);
5046     VAROR(R4,0,BSTR,rbstr,I4,0);
5047     VAROR(R4,-1,BSTR,rbstr,I4,-1);
5048     SysFreeString(rbstr);
5049     rbstr = SysAllocString(szTrue);
5050     VAROR(R4,0,BSTR,rbstr,I4,-1);
5051     VAROR(R4,-1,BSTR,rbstr,I4,-1);
5052     SysFreeString(rbstr);
5053     VARORCY(R4,-1,10000,I4,-1);
5054     VARORCY(R4,-1,0,I4,-1);
5055     VARORCY(R4,0,0,I4,0);
5056 
5057     VAROR(R8,-1,R8,-1,I4,-1);
5058     VAROR(R8,-1,R8,0,I4,-1);
5059     VAROR(R8,0,R8,0,I4,0);
5060     VAROR(R8,-1,DATE,-1,I4,-1);
5061     VAROR(R8,-1,DATE,0,I4,-1);
5062     VAROR(R8,0,DATE,0,I4,0);
5063     if (has_i8)
5064     {
5065         VAROR(R8,-1,I8,-1,I8,-1);
5066         VAROR(R8,-1,I8,0,I8,-1);
5067         VAROR(R8,0,I8,0,I8,0);
5068         VAROR(R8,-1,UI8,0,I4,-1);
5069         VAROR(R8,0,UI8,0,I4,0);
5070     }
5071     VAROR(R8,-1,INT,-1,I4,-1);
5072     VAROR(R8,-1,INT,0,I4,-1);
5073     VAROR(R8,0,INT,0,I4,0);
5074     VAROR(R8,-1,UINT,0xffffffff,I4,-1);
5075     VAROR(R8,-1,UINT,0,I4,-1);
5076     VAROR(R8,0,UINT,0,I4,0);
5077     rbstr = SysAllocString(szFalse);
5078     VAROR(R8,0,BSTR,rbstr,I4,0);
5079     VAROR(R8,-1,BSTR,rbstr,I4,-1);
5080     SysFreeString(rbstr);
5081     rbstr = SysAllocString(szTrue);
5082     VAROR(R8,0,BSTR,rbstr,I4,-1);
5083     VAROR(R8,-1,BSTR,rbstr,I4,-1);
5084     SysFreeString(rbstr);
5085     VARORCY(R8,-1,10000,I4,-1);
5086     VARORCY(R8,-1,0,I4,-1);
5087     VARORCY(R8,0,0,I4,0);
5088 
5089     VAROR(DATE,-1,DATE,-1,I4,-1);
5090     VAROR(DATE,-1,DATE,0,I4,-1);
5091     VAROR(DATE,0,DATE,0,I4,0);
5092     if (has_i8)
5093     {
5094         VAROR(DATE,-1,I8,-1,I8,-1);
5095         VAROR(DATE,-1,I8,0,I8,-1);
5096         VAROR(DATE,0,I8,0,I8,0);
5097         VAROR(DATE,-1,UI8,0,I4,-1);
5098         VAROR(DATE,0,UI8,0,I4,0);
5099     }
5100     VAROR(DATE,-1,INT,-1,I4,-1);
5101     VAROR(DATE,-1,INT,0,I4,-1);
5102     VAROR(DATE,0,INT,0,I4,0);
5103     VAROR(DATE,-1,UINT,0xffffffff,I4,-1);
5104     VAROR(DATE,-1,UINT,0,I4,-1);
5105     VAROR(DATE,0,UINT,0,I4,0);
5106     rbstr = SysAllocString(szFalse);
5107     VAROR(DATE,0,BSTR,rbstr,I4,0);
5108     VAROR(DATE,-1,BSTR,rbstr,I4,-1);
5109     SysFreeString(rbstr);
5110     rbstr = SysAllocString(szTrue);
5111     VAROR(DATE,0,BSTR,rbstr,I4,-1);
5112     VAROR(DATE,-1,BSTR,rbstr,I4,-1);
5113     SysFreeString(rbstr);
5114     VARORCY(DATE,-1,10000,I4,-1);
5115     VARORCY(DATE,-1,0,I4,-1);
5116     VARORCY(DATE,0,0,I4,0);
5117 
5118     if (has_i8)
5119     {
5120         VAROR(I8,-1,I8,-1,I8,-1);
5121         VAROR(I8,-1,I8,0,I8,-1);
5122         VAROR(I8,0,I8,0,I8,0);
5123         VAROR(I8,-1,UI8,0,I8,-1);
5124         VAROR(I8,0,UI8,0,I8,0);
5125         /* These overflow under native and Wine
5126         VAROR(I8,-1,INT,-1,I4,-1);
5127         VAROR(I8,-1,INT,0,I4,-1);
5128         VAROR(I8,0,INT,0,I4,0); */
5129         VAROR(I8,-1,UINT,0xffffffff,I8,-1);
5130         VAROR(I8,-1,UINT,0,I8,-1);
5131         VAROR(I8,0,UINT,0,I8,0);
5132         rbstr = SysAllocString(szFalse);
5133         VAROR(I8,0,BSTR,rbstr,I8,0);
5134         VAROR(I8,-1,BSTR,rbstr,I8,-1);
5135         SysFreeString(rbstr);
5136         rbstr = SysAllocString(szTrue);
5137         VAROR(I8,0,BSTR,rbstr,I8,-1);
5138         VAROR(I8,-1,BSTR,rbstr,I8,-1);
5139         SysFreeString(rbstr);
5140         VARORCY(I8,-1,10000,I8,-1);
5141         VARORCY(I8,-1,0,I8,-1);
5142         VARORCY(I8,0,0,I8,0);
5143 
5144         VAROR(UI8,0xffff,UI8,0xffff,I4,0xffff);
5145         VAROR(UI8,0xffff,UI8,0,I4,0xffff);
5146         VAROR(UI8,0,UI8,0,I4,0);
5147         VAROR(UI8,0xffff,INT,-1,I4,-1);
5148         VAROR(UI8,0xffff,INT,0,I4,0xffff);
5149         VAROR(UI8,0,INT,0,I4,0);
5150         VAROR(UI8,0xffff,UINT,0xffff,I4,0xffff);
5151         VAROR(UI8,0xffff,UINT,0,I4,0xffff);
5152         VAROR(UI8,0,UINT,0,I4,0);
5153         rbstr = SysAllocString(szFalse);
5154         VAROR(UI8,0,BSTR,rbstr,I4,0);
5155         VAROR(UI8,0xffff,BSTR,rbstr,I4,0xffff);
5156         SysFreeString(rbstr);
5157         rbstr = SysAllocString(szTrue);
5158         VAROR(UI8,0,BSTR,rbstr,I4,-1);
5159         VAROR(UI8,0xffff,BSTR,rbstr,I4,-1);
5160         SysFreeString(rbstr);
5161         VARORCY(UI8,0xffff,10000,I4,0xffff);
5162         VARORCY(UI8,0xffff,0,I4,0xffff);
5163         VARORCY(UI8,0,0,I4,0);
5164     }
5165 
5166     VAROR(INT,-1,INT,-1,I4,-1);
5167     VAROR(INT,-1,INT,0,I4,-1);
5168     VAROR(INT,0,INT,0,I4,0);
5169     VAROR(INT,-1,UINT,0xffff,I4,-1);
5170     VAROR(INT,-1,UINT,0,I4,-1);
5171     VAROR(INT,0,UINT,0,I4,0);
5172     rbstr = SysAllocString(szFalse);
5173     VAROR(INT,0,BSTR,rbstr,I4,0);
5174     VAROR(INT,-1,BSTR,rbstr,I4,-1);
5175     SysFreeString(rbstr);
5176     rbstr = SysAllocString(szTrue);
5177     VAROR(INT,0,BSTR,rbstr,I4,-1);
5178     VAROR(INT,-1,BSTR,rbstr,I4,-1);
5179     SysFreeString(rbstr);
5180     VARORCY(INT,-1,10000,I4,-1);
5181     VARORCY(INT,-1,0,I4,-1);
5182     VARORCY(INT,0,0,I4,0);
5183 
5184     VAROR(UINT,0xffff,UINT,0xffff,I4,0xffff);
5185     VAROR(UINT,0xffff,UINT,0,I4,0xffff);
5186     VAROR(UINT,0,UINT,0,I4,0);
5187     rbstr = SysAllocString(szFalse);
5188     VAROR(UINT,0,BSTR,rbstr,I4,0);
5189     VAROR(UINT,0xffff,BSTR,rbstr,I4,0xffff);
5190     SysFreeString(rbstr);
5191     rbstr = SysAllocString(szTrue);
5192     VAROR(UINT,0,BSTR,rbstr,I4,-1);
5193     VAROR(UINT,0xffff,BSTR,rbstr,I4,-1);
5194     SysFreeString(rbstr);
5195     VARORCY(UINT,0xffff,10000,I4,0xffff);
5196     VARORCY(UINT,0xffff,0,I4,0xffff);
5197     VARORCY(UINT,0,0,I4,0);
5198 
5199     lbstr = SysAllocString(szFalse);
5200     rbstr = SysAllocString(szFalse);
5201     VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,0);
5202     SysFreeString(rbstr);
5203     rbstr = SysAllocString(szTrue);
5204     VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
5205     SysFreeString(lbstr);
5206     lbstr = SysAllocString(szTrue);
5207     VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
5208     VARORCY(BSTR,lbstr,10000,I4,-1);
5209     SysFreeString(lbstr);
5210     lbstr = SysAllocString(szFalse);
5211     VARORCY(BSTR,lbstr,10000,I4,1);
5212     SysFreeString(lbstr);
5213     SysFreeString(rbstr);
5214 }
5215 
5216 static HRESULT (WINAPI *pVarEqv)(LPVARIANT,LPVARIANT,LPVARIANT);
5217 
5218 #define VAREQV(vt1,val1,vt2,val2,rvt,rval)           \
5219     V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
5220     V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
5221     V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
5222     test_var_call2( __LINE__, pVarEqv, &left, &right, &exp )
5223 
5224 static void test_VarEqv(void)
5225 {
5226     VARIANT left, right, exp, result;
5227     VARTYPE i;
5228     HRESULT hres;
5229 
5230     CHECKPTR(VarEqv);
5231 
5232     /* Test all possible flag/vt combinations & the resulting vt type */
5233     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
5234     {
5235         VARTYPE leftvt, rightvt, resvt;
5236 
5237         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
5238         {
5239             SKIPTESTS(leftvt);
5240 
5241             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
5242             {
5243                 BOOL bFail = FALSE;
5244 
5245                 SKIPTESTS(rightvt);
5246 
5247                 if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
5248                     leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
5249                     leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
5250                     continue;
5251 
5252                 memset(&left, 0, sizeof(left));
5253                 memset(&right, 0, sizeof(right));
5254                 V_VT(&left) = leftvt | ExtraFlags[i];
5255                 V_VT(&right) = rightvt | ExtraFlags[i];
5256                 V_VT(&result) = VT_EMPTY;
5257                 resvt = VT_I4;
5258 
5259                 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
5260                     !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
5261                     !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
5262                     leftvt == VT_CLSID || rightvt == VT_CLSID ||
5263                     leftvt == VT_RECORD || rightvt == VT_RECORD ||
5264                     leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
5265                     leftvt == VT_ERROR || rightvt == VT_ERROR)
5266                 {
5267                     bFail = TRUE;
5268                 }
5269                 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
5270                 {
5271                     if (leftvt == rightvt ||
5272                         leftvt == VT_I2 || rightvt == VT_I2 ||
5273                         leftvt == VT_UI1 || rightvt == VT_UI1 ||
5274                         leftvt == VT_BOOL || rightvt == VT_BOOL)
5275                         resvt = VT_I2;
5276                     else if (leftvt == VT_NULL || rightvt == VT_NULL)
5277                         resvt = VT_NULL;
5278                     else if (leftvt == VT_I8 || rightvt == VT_I8)
5279                         resvt = VT_I8;
5280                 }
5281                 else if (leftvt == VT_NULL || rightvt == VT_NULL)
5282                 {
5283                     resvt = VT_NULL;
5284                 }
5285                 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
5286                 {
5287                     if (leftvt == rightvt)
5288                         resvt = VT_UI1;
5289                     else if (leftvt == rightvt ||
5290                         leftvt == VT_I2 || rightvt == VT_I2 ||
5291                         leftvt == VT_BOOL || rightvt == VT_BOOL)
5292                     {
5293                         resvt = VT_I2;
5294                     }
5295                     else if (leftvt == VT_I8 || rightvt == VT_I8)
5296                         resvt = VT_I8;
5297                 }
5298                 else if (leftvt == VT_I2 || rightvt == VT_I2)
5299                 {
5300                     if (leftvt == rightvt ||
5301                         leftvt == VT_BOOL || rightvt == VT_BOOL)
5302                         resvt = VT_I2;
5303                     else if (leftvt == VT_I8 || rightvt == VT_I8)
5304                         resvt = VT_I8;
5305                 }
5306                 else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
5307                 {
5308                     resvt = VT_BOOL;
5309                 }
5310                 else if (leftvt == VT_I8 || rightvt == VT_I8)
5311                 {
5312                     if (leftvt == VT_INT || rightvt == VT_INT)
5313                         bFail = TRUE;
5314                     else
5315                         resvt = VT_I8;
5316                 }
5317                 hres = pVarEqv(&left, &right, &result);
5318                 if (bFail)
5319                     ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
5320                        "VarEqv: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
5321                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
5322                        V_VT(&result));
5323                 else
5324                     ok(hres == S_OK && V_VT(&result) == resvt,
5325                        "VarEqv: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
5326                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
5327                        V_VT(&result));
5328             }
5329         }
5330     }
5331 
5332     /* Test returned values */
5333     VAREQV(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
5334     VAREQV(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
5335     VAREQV(BOOL,TRUE,BOOL,TRUE,BOOL,VARIANT_TRUE);
5336     VAREQV(BOOL,FALSE,BOOL,FALSE,BOOL,VARIANT_TRUE);
5337     VAREQV(BOOL,TRUE,BOOL,FALSE,BOOL,-2);
5338     VAREQV(BOOL,FALSE,BOOL,TRUE,BOOL,-2);
5339     VAREQV(BOOL,6,BOOL,7,BOOL,-2);
5340     VAREQV(BOOL,6,BOOL,6,BOOL,VARIANT_TRUE);
5341     VAREQV(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE,I2,VARIANT_TRUE);
5342     VAREQV(BOOL,VARIANT_TRUE,I2,VARIANT_FALSE,I2,VARIANT_FALSE);
5343     VAREQV(BOOL,6,I2,7,I2,-2);
5344     VAREQV(UI1,1,UI1,1,UI1,255);
5345     VAREQV(UI1,1,UI1,0,UI1,254);
5346     VAREQV(UI1,0,UI1,1,UI1,254);
5347     if (has_i8)
5348     {
5349         VAREQV(UI4,VARIANT_FALSE,I8,VARIANT_FALSE,I8,-1);
5350         VAREQV(UI4,5,I8,19,I8,-23);
5351         VAREQV(UI4,VARIANT_FALSE,UI8,VARIANT_FALSE,I4,-1);
5352     }
5353 }
5354 
5355 static HRESULT (WINAPI *pVarMul)(LPVARIANT,LPVARIANT,LPVARIANT);
5356 
5357 #define VARMUL(vt1,val1,vt2,val2,rvt,rval)               \
5358         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
5359         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
5360         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
5361         test_var_call2( __LINE__, pVarMul, &left, &right, &exp )
5362 
5363 static void test_VarMul(void)
5364 {
5365     VARIANT left, right, exp, result, cy, dec;
5366     VARTYPE i;
5367     BSTR lbstr, rbstr;
5368     HRESULT hres;
5369     double r;
5370 
5371     CHECKPTR(VarMul);
5372 
5373     lbstr = SysAllocString(sz12);
5374     rbstr = SysAllocString(sz12);
5375 
5376     /* Test all possible flag/vt combinations & the resulting vt type */
5377     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
5378     {
5379         VARTYPE leftvt, rightvt, resvt;
5380 
5381         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
5382         {
5383 
5384             SKIPTESTS(leftvt);
5385 
5386             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
5387             {
5388                 BOOL bFail = FALSE;
5389 
5390                 SKIPTESTS(rightvt);
5391 
5392                 if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
5393                     leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
5394                     continue;
5395 
5396                 memset(&left, 0, sizeof(left));
5397                 memset(&right, 0, sizeof(right));
5398                 V_VT(&left) = leftvt | ExtraFlags[i];
5399                 if (leftvt == VT_BSTR)
5400                     V_BSTR(&left) = lbstr;
5401                 V_VT(&right) = rightvt | ExtraFlags[i];
5402                 if (rightvt == VT_BSTR)
5403                     V_BSTR(&right) = rbstr;
5404                 V_VT(&result) = VT_EMPTY;
5405                 resvt = VT_UNKNOWN;
5406 
5407                 /* Don't ask me why but native VarMul cannot handle:
5408                    VT_I1, VT_UI2, VT_UI4, VT_INT, VT_UINT and VT_UI8.
5409                    Tested with DCOM98, Win2k, WinXP */
5410                 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
5411                     !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
5412                     !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
5413                     leftvt == VT_CLSID || rightvt == VT_CLSID ||
5414                     leftvt == VT_RECORD || rightvt == VT_RECORD ||
5415                     leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
5416                     leftvt == VT_ERROR || rightvt == VT_ERROR ||
5417                     leftvt == VT_I1 || rightvt == VT_I1 ||
5418                     leftvt == VT_UI2 || rightvt == VT_UI2 ||
5419                     leftvt == VT_UI4 || rightvt == VT_UI4 ||
5420                     leftvt == VT_UI8 || rightvt == VT_UI8 ||
5421                     leftvt == VT_INT || rightvt == VT_INT ||
5422                     leftvt == VT_UINT || rightvt == VT_UINT) {
5423                     bFail = TRUE;
5424                 }
5425 
5426                 if (leftvt == VT_NULL || rightvt == VT_NULL)
5427                     resvt = VT_NULL;
5428                 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
5429                     resvt = VT_DECIMAL;
5430                 else if (leftvt == VT_R8 || rightvt == VT_R8 ||
5431                          leftvt == VT_BSTR || rightvt == VT_BSTR ||
5432                          leftvt == VT_DATE || rightvt == VT_DATE)
5433                     resvt = VT_R8;
5434                 else if (leftvt == VT_R4 || rightvt == VT_R4) {
5435                     if (leftvt == VT_I4 || rightvt == VT_I4 ||
5436                         leftvt == VT_I8 || rightvt == VT_I8 ||
5437                         leftvt == VT_CY || rightvt == VT_CY)
5438                         resvt = VT_R8;
5439                     else
5440                         resvt = VT_R4;
5441                 } else if (leftvt == VT_CY || rightvt == VT_CY)
5442                     resvt = VT_CY;
5443                 else if (leftvt == VT_I8 || rightvt == VT_I8)
5444                     resvt = VT_I8;
5445                 else if (leftvt == VT_I4 || rightvt == VT_I4)
5446                     resvt = VT_I4;
5447                 else if (leftvt == VT_I2 || rightvt == VT_I2 ||
5448                          leftvt == VT_BOOL || rightvt == VT_BOOL ||
5449                          (leftvt == VT_EMPTY && rightvt == VT_EMPTY))
5450                     resvt = VT_I2;
5451                 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
5452                     resvt = VT_UI1;
5453 
5454                 hres = pVarMul(&left, &right, &result);
5455                 if (bFail) {
5456                     ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
5457                        "VarMul: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
5458                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
5459                        V_VT(&result));
5460                 } else {
5461                     ok(hres == S_OK && V_VT(&result) == resvt,
5462                        "VarMul: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
5463                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
5464                        V_VT(&result));
5465                 }
5466             }
5467         }
5468     }
5469 
5470     /* Test returned values */
5471     VARMUL(I4,4,I4,2,I4,8);
5472     VARMUL(I2,4,I2,2,I2,8);
5473     VARMUL(I2,-13,I4,5,I4,-65);
5474     VARMUL(I4,-13,I4,5,I4,-65);
5475     VARMUL(I2,7,R4,0.5f,R4,3.5f);
5476     VARMUL(R4,0.5f,I4,5,R8,2.5);
5477     VARMUL(R8,7.1,BOOL,0,R8,0);
5478     VARMUL(BSTR,lbstr,I2,4,R8,48);
5479     VARMUL(BSTR,lbstr,BOOL,1,R8,12);
5480     VARMUL(BSTR,lbstr,R4,0.1f,R8,1.2);
5481     VARMUL(BSTR,lbstr,BSTR,rbstr,R8,144);
5482     VARMUL(R4,0.2f,BSTR,rbstr,R8,2.4);
5483     VARMUL(DATE,2.25,I4,7,R8,15.75);
5484 
5485     VARMUL(UI1, UI1_MAX, UI1, UI1_MAX, I4, UI1_MAX * UI1_MAX);
5486     VARMUL(I2, I2_MAX, I2, I2_MAX, I4, I2_MAX * I2_MAX);
5487     VARMUL(I2, I2_MAX, I2, I2_MIN, I4, I2_MAX * I2_MIN);
5488     VARMUL(I2, I2_MIN, I2, I2_MIN, I4, I2_MIN * I2_MIN);
5489     VARMUL(I4, I4_MAX, I4, I4_MAX, R8, (double)I4_MAX * I4_MAX);
5490     VARMUL(I4, I4_MAX, I4, I4_MIN, R8, (double)I4_MAX * I4_MIN);
5491     VARMUL(I4, I4_MIN, I4, I4_MIN, R8, (double)I4_MIN * I4_MIN);
5492     VARMUL(R4, R4_MAX, R4, R4_MAX, R8, (double)R4_MAX * R4_MAX);
5493     VARMUL(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX * R4_MIN);
5494     VARMUL(R4, R4_MIN, R4, R4_MIN, R4, R4_MIN * R4_MIN);
5495     VARMUL(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX * R8_MIN);
5496     VARMUL(R8, R8_MIN, R8, R8_MIN, R8, R8_MIN * R8_MIN);
5497 
5498     /* Manuly test some VT_CY and VT_DECIMAL variants */
5499     V_VT(&cy) = VT_CY;
5500     hres = VarCyFromI4(4711, &V_CY(&cy));
5501     ok(hres == S_OK, "VarCyFromI4 failed!\n");
5502     V_VT(&dec) = VT_DECIMAL;
5503     hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec));
5504     ok(hres == S_OK, "VarDecFromR4 failed!\n");
5505     memset(&left, 0, sizeof(left));
5506     memset(&right, 0, sizeof(right));
5507     V_VT(&left) = VT_I4;
5508     V_I4(&left) = -11;
5509     V_VT(&right) = VT_UI1;
5510     V_UI1(&right) = 9;
5511 
5512     hres = pVarMul(&cy, &right, &result);
5513     ok(hres == S_OK && V_VT(&result) == VT_CY, "VarMul: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result)));
5514     hres = VarR8FromCy(V_CY(&result), &r);
5515     ok(hres == S_OK && EQ_DOUBLE(r, 42399.0), "VarMul: CY value %f, expected %f\n", r, (double)42399);
5516 
5517     hres = pVarMul(&left, &dec, &result);
5518     ok(hres == S_OK && V_VT(&result) == VT_DECIMAL, "VarMul: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
5519     hres = VarR8FromDec(&V_DECIMAL(&result), &r);
5520     ok(hres == S_OK && EQ_DOUBLE(r, 46.2), "VarMul: DECIMAL value %f, expected %f\n", r, (double)46.2);
5521 
5522     SysFreeString(lbstr);
5523     SysFreeString(rbstr);
5524 }
5525 
5526 static HRESULT (WINAPI *pVarAdd)(LPVARIANT,LPVARIANT,LPVARIANT);
5527 
5528 #define VARADD(vt1,val1,vt2,val2,rvt,rval)               \
5529         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
5530         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
5531         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
5532         test_var_call2( __LINE__, pVarAdd, &left, &right, &exp )
5533 
5534 static void test_VarAdd(void)
5535 {
5536     VARIANT left, right, exp, result, cy, dec;
5537     VARTYPE i;
5538     BSTR lbstr, rbstr;
5539     HRESULT hres;
5540     double r;
5541 
5542     CHECKPTR(VarAdd);
5543 
5544     lbstr = SysAllocString(sz12);
5545     rbstr = SysAllocString(sz12);
5546 
5547     /* Test all possible flag/vt combinations & the resulting vt type */
5548     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
5549     {
5550         VARTYPE leftvt, rightvt, resvt;
5551 
5552         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
5553         {
5554 
5555             SKIPTESTS(leftvt);
5556 
5557             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
5558             {
5559                 BOOL bFail = FALSE;
5560 
5561                 SKIPTESTS(rightvt);
5562 
5563                 if (leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
5564                     continue;
5565 
5566                 memset(&left, 0, sizeof(left));
5567                 memset(&right, 0, sizeof(right));
5568                 V_VT(&left) = leftvt | ExtraFlags[i];
5569                 if (leftvt == VT_BSTR)
5570                     V_BSTR(&left) = lbstr;
5571                 V_VT(&right) = rightvt | ExtraFlags[i];
5572                 if (rightvt == VT_BSTR)
5573                     V_BSTR(&right) = rbstr;
5574                 V_VT(&result) = VT_EMPTY;
5575                 resvt = VT_ERROR;
5576 
5577                 /* Don't ask me why but native VarAdd cannot handle:
5578                    VT_I1, VT_UI2, VT_UI4, VT_INT, VT_UINT and VT_UI8.
5579                    Tested with DCOM98, Win2k, WinXP */
5580                 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
5581                     !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
5582                     !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
5583                     leftvt == VT_CLSID || rightvt == VT_CLSID ||
5584                     leftvt == VT_RECORD || rightvt == VT_RECORD ||
5585                     leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
5586                     leftvt == VT_ERROR || rightvt == VT_ERROR ||
5587                     leftvt == VT_I1 || rightvt == VT_I1 ||
5588                     leftvt == VT_UI2 || rightvt == VT_UI2 ||
5589                     leftvt == VT_UI4 || rightvt == VT_UI4 ||
5590                     leftvt == VT_UI8 || rightvt == VT_UI8 ||
5591                     leftvt == VT_INT || rightvt == VT_INT ||
5592                     leftvt == VT_UINT || rightvt == VT_UINT) {
5593                     bFail = TRUE;
5594                 }
5595 
5596                 if (leftvt == VT_NULL || rightvt == VT_NULL)
5597                     resvt = VT_NULL;
5598                 else if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH)
5599                     bFail = TRUE;
5600                 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
5601                     resvt = VT_DECIMAL;
5602                 else if (leftvt == VT_DATE || rightvt == VT_DATE)
5603                     resvt = VT_DATE;
5604                 else if (leftvt == VT_CY || rightvt == VT_CY)
5605                     resvt = VT_CY;
5606                 else if (leftvt == VT_R8 || rightvt == VT_R8)
5607                     resvt = VT_R8;
5608                 else if (leftvt == VT_BSTR || rightvt == VT_BSTR) {
5609                     if ((leftvt == VT_BSTR && rightvt == VT_BSTR) ||
5610                          leftvt == VT_EMPTY || rightvt == VT_EMPTY)
5611                         resvt = VT_BSTR;
5612                     else
5613                         resvt = VT_R8;
5614                 } else if (leftvt == VT_R4 || rightvt == VT_R4) {
5615                     if (leftvt == VT_I4 || rightvt == VT_I4 ||
5616                         leftvt == VT_I8 || rightvt == VT_I8)
5617                         resvt = VT_R8;
5618                     else
5619                         resvt = VT_R4;
5620                 }
5621                 else if (leftvt == VT_I8 || rightvt == VT_I8)
5622                     resvt = VT_I8;
5623                 else if (leftvt == VT_I4 || rightvt == VT_I4)
5624                     resvt = VT_I4;
5625                 else if (leftvt == VT_I2 || rightvt == VT_I2 ||
5626                          leftvt == VT_BOOL || rightvt == VT_BOOL ||
5627                          (leftvt == VT_EMPTY && rightvt == VT_EMPTY))
5628                     resvt = VT_I2;
5629                 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
5630                     resvt = VT_UI1;
5631 
5632                 hres = pVarAdd(&left, &right, &result);
5633                 if (bFail) {
5634                     ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
5635                        "VarAdd: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
5636                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
5637                        V_VT(&result));
5638                 } else {
5639                     ok(hres == S_OK && V_VT(&result) == resvt,
5640                        "VarAdd: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
5641                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
5642                        V_VT(&result));
5643                 }
5644                 /* Note, we don't clear left/right deliberately here */
5645                 VariantClear(&result);
5646             }
5647         }
5648     }
5649 
5650     /* Test returned values */
5651     VARADD(I4,4,I4,2,I4,6);
5652     VARADD(I2,4,I2,2,I2,6);
5653     VARADD(I2,-13,I4,5,I4,-8);
5654     VARADD(I4,-13,I4,5,I4,-8);
5655     VARADD(I2,7,R4,0.5f,R4,7.5f);
5656     VARADD(R4,0.5f,I4,5,R8,5.5);
5657     VARADD(R8,7.1,BOOL,0,R8,7.1);
5658     VARADD(BSTR,lbstr,I2,4,R8,16);
5659     VARADD(BSTR,lbstr,BOOL,1,R8,13);
5660     VARADD(BSTR,lbstr,R4,0.1f,R8,12.1);
5661     VARADD(R4,0.2f,BSTR,rbstr,R8,12.2);
5662     VARADD(DATE,2.25,I4,7,DATE,9.25);
5663     VARADD(DATE,1.25,R4,-1.7f,DATE,-0.45);
5664 
5665     VARADD(UI1, UI1_MAX, UI1, UI1_MAX, I2, UI1_MAX + UI1_MAX);
5666     VARADD(I2, I2_MAX, I2, I2_MAX, I4, I2_MAX + I2_MAX);
5667     VARADD(I2, I2_MAX, I2, I2_MIN, I2, I2_MAX + I2_MIN);
5668     VARADD(I2, I2_MIN, I2, I2_MIN, I4, I2_MIN + I2_MIN);
5669     VARADD(I4, I4_MAX, I4, I4_MIN, I4, I4_MAX + I4_MIN);
5670     VARADD(I4, I4_MAX, I4, I4_MAX, R8, (double)I4_MAX + I4_MAX);
5671     VARADD(I4, I4_MIN, I4, I4_MIN, R8, (double)I4_MIN + I4_MIN);
5672     VARADD(R4, R4_MAX, R4, R4_MAX, R8, (double)R4_MAX + R4_MAX);
5673     VARADD(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX + R4_MIN);
5674     VARADD(R4, R4_MIN, R4, R4_MIN, R4, R4_MIN + R4_MIN);
5675     VARADD(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX + R8_MIN);
5676     VARADD(R8, R8_MIN, R8, R8_MIN, R8, R8_MIN + R8_MIN);
5677 
5678     /* Manually test BSTR + BSTR */
5679     V_VT(&left) = VT_BSTR;
5680     V_BSTR(&left) = lbstr;
5681     V_VT(&right) = VT_BSTR;
5682     V_BSTR(&right) = rbstr;
5683     hres = pVarAdd(&left, &right, &result);
5684     ok(hres == S_OK && V_VT(&result) == VT_BSTR, "VarAdd: expected coerced type VT_BSTR, got %s!\n", vtstr(V_VT(&result)));
5685     hres = VarR8FromStr(V_BSTR(&result), 0, 0, &r);
5686     ok(hres == S_OK && EQ_DOUBLE(r, 1212.0), "VarAdd: BSTR value %f, expected %f\n", r, (double)1212);
5687     VariantClear(&result);
5688 
5689     /* Manuly test some VT_CY and VT_DECIMAL variants */
5690     V_VT(&cy) = VT_CY;
5691     hres = VarCyFromI4(4711, &V_CY(&cy));
5692     ok(hres == S_OK, "VarCyFromI4 failed!\n");
5693     V_VT(&dec) = VT_DECIMAL;
5694     hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec));
5695     ok(hres == S_OK, "VarDecFromR4 failed!\n");
5696     memset(&left, 0, sizeof(left));
5697     memset(&right, 0, sizeof(right));
5698     V_VT(&left) = VT_I4;
5699     V_I4(&left) = -11;
5700     V_VT(&right) = VT_UI1;
5701     V_UI1(&right) = 9;
5702 
5703     hres = pVarAdd(&cy, &right, &result);
5704     ok(hres == S_OK && V_VT(&result) == VT_CY, "VarAdd: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result)));
5705     hres = VarR8FromCy(V_CY(&result), &r);
5706     ok(hres == S_OK && EQ_DOUBLE(r, 4720.0), "VarAdd: CY value %f, expected %f\n", r, (double)4720);
5707 
5708     hres = pVarAdd(&left, &dec, &result);
5709     ok(hres == S_OK && V_VT(&result) == VT_DECIMAL, "VarAdd: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
5710     hres = VarR8FromDec(&V_DECIMAL(&result), &r);
5711     ok(hres == S_OK && EQ_DOUBLE(r, -15.2), "VarAdd: DECIMAL value %f, expected %f\n", r, (double)-15.2);
5712     VariantClear(&result);
5713 
5714     SysFreeString(lbstr);
5715     SysFreeString(rbstr);
5716 }
5717 
5718 static HRESULT (WINAPI *pVarCmp)(LPVARIANT,LPVARIANT,LCID,ULONG);
5719 static HRESULT (WINAPI *pVarCat)(LPVARIANT,LPVARIANT,LPVARIANT);
5720 
5721 static void test_VarCat(void)
5722 {
5723     LCID lcid;
5724     VARIANT left, right, result, expected, expected_broken;
5725     static const WCHAR sz34[] = {'3','4','\0'};
5726     static const WCHAR sz1234[] = {'1','2','3','4','\0'};
5727     static const WCHAR date_sz12[] = {'9','/','3','0','/','1','9','8','0','1','2','\0'};
5728     static const WCHAR date_sz12_broken[] = {'9','/','3','0','/','8','0','1','2','\0'};
5729     static const WCHAR sz12_date[] = {'1','2','9','/','3','0','/','1','9','8','0','\0'};
5730     static const WCHAR sz12_date_broken[] = {'1','2','9','/','3','0','/','8','0','\0'};
5731     static const WCHAR sz_empty[] = {'\0'};
5732     CHAR orig_date_format[128];
5733     VARTYPE leftvt, rightvt, resultvt;
5734     HRESULT hres;
5735     HRESULT expected_error_num;
5736     int cmp;
5737     DummyDispatch dispatch;
5738 
5739     CHECKPTR(VarCat);
5740 
5741     /* Set date format for testing */
5742     lcid = LOCALE_USER_DEFAULT;
5743     GetLocaleInfoA(lcid,LOCALE_SSHORTDATE,orig_date_format,128);
5744     SetLocaleInfoA(lcid,LOCALE_SSHORTDATE,"M/d/yyyy");
5745 
5746     VariantInit(&left);
5747     VariantInit(&right);
5748     VariantInit(&result);
5749     VariantInit(&expected);
5750 
5751     /* Check expected types for all combinations */
5752     for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
5753     {
5754 
5755         SKIPTESTS(leftvt);
5756 
5757         /* Check if we need/have support for I8 and/or UI8 */
5758         if ((leftvt == VT_I8 || leftvt == VT_UI8) && !has_i8)
5759             continue;
5760 
5761         for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
5762         {
5763 
5764             SKIPTESTS(rightvt);
5765             expected_error_num = S_OK;
5766             resultvt = VT_EMPTY;
5767 
5768             if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
5769                 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN  ||
5770                 leftvt == VT_RECORD || rightvt == VT_RECORD  ||
5771                 leftvt == 15 || rightvt == 15 /* Undefined type */)
5772                 continue;
5773 
5774             /* Check if we need/have support for I8 and/or UI8 */
5775             if ((rightvt == VT_I8 || rightvt == VT_UI8) && !has_i8)
5776                 continue;
5777 
5778             if (leftvt == VT_NULL && rightvt == VT_NULL)
5779                 resultvt = VT_NULL;
5780             else if (leftvt == VT_VARIANT && (rightvt == VT_ERROR ||
5781                 rightvt == VT_DATE || rightvt == VT_DECIMAL))
5782                 expected_error_num = DISP_E_TYPEMISMATCH;
5783             else if ((leftvt == VT_I2 || leftvt == VT_I4 ||
5784                 leftvt == VT_R4 || leftvt == VT_R8 ||
5785                 leftvt == VT_CY || leftvt == VT_BOOL ||
5786                 leftvt == VT_BSTR || leftvt == VT_I1 ||
5787                 leftvt == VT_UI1 || leftvt == VT_UI2 ||
5788                 leftvt == VT_UI4 || leftvt == VT_I8 ||
5789                 leftvt == VT_UI8 || leftvt == VT_INT ||
5790                 leftvt == VT_UINT || leftvt == VT_EMPTY ||
5791                 leftvt == VT_NULL || leftvt == VT_DECIMAL ||
5792                 leftvt == VT_DATE)
5793                 &&
5794                 (rightvt == VT_I2 || rightvt == VT_I4 ||
5795                 rightvt == VT_R4 || rightvt == VT_R8 ||
5796                 rightvt == VT_CY || rightvt == VT_BOOL ||
5797                 rightvt == VT_BSTR || rightvt == VT_I1 ||
5798                 rightvt == VT_UI1 || rightvt == VT_UI2 ||
5799                 rightvt == VT_UI4 || rightvt == VT_I8 ||
5800                 rightvt == VT_UI8 || rightvt == VT_INT ||
5801                 rightvt == VT_UINT || rightvt == VT_EMPTY ||
5802                 rightvt == VT_NULL || rightvt == VT_DECIMAL ||
5803                 rightvt == VT_DATE))
5804                 resultvt = VT_BSTR;
5805             else if (rightvt == VT_ERROR && leftvt < VT_VOID)
5806                 expected_error_num = DISP_E_TYPEMISMATCH;
5807             else if (leftvt == VT_ERROR && (rightvt == VT_DATE ||
5808                 rightvt == VT_ERROR || rightvt == VT_DECIMAL))
5809                 expected_error_num = DISP_E_TYPEMISMATCH;
5810             else if (rightvt == VT_DATE || rightvt == VT_ERROR ||
5811                 rightvt == VT_DECIMAL)
5812                 expected_error_num = DISP_E_BADVARTYPE;
5813             else if (leftvt == VT_ERROR || rightvt == VT_ERROR)
5814                 expected_error_num = DISP_E_TYPEMISMATCH;
5815             else if (leftvt == VT_VARIANT)
5816                 expected_error_num = DISP_E_TYPEMISMATCH;
5817             else if (rightvt == VT_VARIANT && (leftvt == VT_EMPTY ||
5818                 leftvt == VT_NULL || leftvt ==  VT_I2 ||
5819                 leftvt == VT_I4 || leftvt == VT_R4 ||
5820                 leftvt == VT_R8 || leftvt == VT_CY ||
5821                 leftvt == VT_DATE || leftvt == VT_BSTR ||
5822                 leftvt == VT_BOOL ||  leftvt == VT_DECIMAL ||
5823                 leftvt == VT_I1 || leftvt == VT_UI1 ||
5824                 leftvt == VT_UI2 || leftvt == VT_UI4 ||
5825                 leftvt == VT_I8 || leftvt == VT_UI8 ||
5826                 leftvt == VT_INT || leftvt == VT_UINT
5827                 ))
5828                 expected_error_num = DISP_E_TYPEMISMATCH;
5829             else
5830                 expected_error_num = DISP_E_BADVARTYPE;
5831 
5832             V_VT(&left) = leftvt;
5833             V_VT(&right) = rightvt;
5834 
5835             switch (leftvt) {
5836             case VT_BSTR:
5837                 V_BSTR(&left) = SysAllocString(sz_empty); break;
5838             case VT_DATE:
5839                 V_DATE(&left) = 0.0; break;
5840             case VT_DECIMAL:
5841                 VarDecFromR8(0.0, &V_DECIMAL(&left)); break;
5842             default:
5843                 V_I8(&left) = 0;
5844             }
5845 
5846             switch (rightvt) {
5847             case VT_BSTR:
5848                 V_BSTR(&right) = SysAllocString(sz_empty); break;
5849             case VT_DATE:
5850                 V_DATE(&right) = 0.0; break;
5851             case VT_DECIMAL:
5852                 VarDecFromR8(0.0, &V_DECIMAL(&right)); break;
5853             default:
5854                 V_I8(&right) = 0;
5855             }
5856 
5857             hres = pVarCat(&left, &right, &result);
5858 
5859             /* Determine the error code for the vt combination */
5860             ok(hres == expected_error_num,
5861                 "VarCat: %d, %d returned error, 0x%X expected 0x%X.\n",
5862                 leftvt, rightvt, hres, expected_error_num);
5863 
5864             /* Check types are correct */
5865             ok(V_VT(&result) == resultvt,
5866                 "VarCat: %d, %d: expected vt %d, got vt %d\n",
5867                 leftvt, rightvt, resultvt, V_VT(&result));
5868 
5869             VariantClear(&left);
5870             VariantClear(&right);
5871             VariantClear(&result);
5872         }
5873     }
5874 
5875     /* Running single comparison tests to compare outputs */
5876 
5877     /* Test concat strings */
5878     V_VT(&left) = VT_BSTR;
5879     V_VT(&right) = VT_BSTR;
5880     V_VT(&expected) = VT_BSTR;
5881     V_BSTR(&left) = SysAllocString(sz12);
5882     V_BSTR(&right) = SysAllocString(sz34);
5883     V_BSTR(&expected) = SysAllocString(sz1234);
5884     hres = pVarCat(&left,&right,&result);
5885     ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5886     if (pVarCmp)
5887         ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ,
5888            "VarCat: VT_BSTR concat with VT_BSTR failed to return correct result\n");
5889 
5890     VariantClear(&left);
5891     VariantClear(&right);
5892     VariantClear(&result);
5893 
5894     /* Test if expression is VT_ERROR */
5895     V_VT(&left) = VT_ERROR;
5896     V_VT(&right) = VT_BSTR;
5897     V_BSTR(&right) = SysAllocString(sz1234);
5898     hres = pVarCat(&left,&right,&result);
5899     ok(hres == DISP_E_TYPEMISMATCH, "VarCat should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hres);
5900     ok(V_VT(&result) == VT_EMPTY,
5901         "VarCat: VT_ERROR concat with VT_BSTR should have returned VT_EMPTY\n");
5902 
5903     VariantClear(&left);
5904     VariantClear(&right);
5905     VariantClear(&result);
5906 
5907     V_VT(&left) = VT_BSTR;
5908     V_VT(&right) = VT_ERROR;
5909     V_BSTR(&left) = SysAllocString(sz1234);
5910     hres = pVarCat(&left,&right,&result);
5911     ok(hres == DISP_E_TYPEMISMATCH, "VarCat should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hres);
5912     ok(V_VT(&result) == VT_EMPTY,
5913         "VarCat: VT_BSTR concat with VT_ERROR should have returned VT_EMPTY\n");
5914 
5915     VariantClear(&left);
5916     VariantClear(&right);
5917     VariantClear(&result);
5918     VariantClear(&expected);
5919 
5920     /* Test combining boolean with number */
5921     V_VT(&left) = VT_INT;
5922     V_VT(&right) = VT_BOOL;
5923     V_VT(&expected) = VT_BSTR;
5924     V_INT(&left) = 12;
5925     V_BOOL(&right) = TRUE;
5926     V_BSTR(&expected) = SysAllocString(sz12_true);
5927     hres = pVarCat(&left,&right,&result);
5928     ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5929     if (pVarCmp)
5930     {
5931         hres = pVarCmp(&result,&expected,lcid,0);
5932         ok(hres == VARCMP_EQ, "Expected VARCMP_EQ, got %08x for %s, %s\n",
5933            hres, variantstr(&result), variantstr(&expected));
5934     }
5935 
5936     VariantClear(&left);
5937     VariantClear(&right);
5938     VariantClear(&result);
5939     VariantClear(&expected);
5940 
5941     V_VT(&left) = VT_INT;
5942     V_VT(&right) = VT_BOOL;
5943     V_VT(&expected) = VT_BSTR;
5944     V_INT(&left) = 12;
5945     V_BOOL(&right) = FALSE;
5946     V_BSTR(&expected) = SysAllocString(sz12_false);
5947     hres = pVarCat(&left,&right,&result);
5948     ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5949     if (pVarCmp)
5950     {
5951         hres = pVarCmp(&result,&expected,lcid,0);
5952         ok(hres == VARCMP_EQ, "Expected VARCMP_EQ, got %08x for %s, %s\n",
5953            hres, variantstr(&result), variantstr(&expected));
5954     }
5955 
5956     VariantClear(&left);
5957     VariantClear(&right);
5958     VariantClear(&result);
5959     VariantClear(&expected);
5960 
5961     /* Test when both expressions are numeric */
5962     V_VT(&left) = VT_INT;
5963     V_VT(&right) = VT_INT;
5964     V_VT(&expected) = VT_BSTR;
5965     V_INT(&left)  = 12;
5966     V_INT(&right) = 34;
5967     V_BSTR(&expected) = SysAllocString(sz1234);
5968     hres = pVarCat(&left,&right,&result);
5969     ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5970     if (pVarCmp)
5971         ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ,
5972            "VarCat: NUMBER concat with NUMBER returned incorrect result\n");
5973 
5974     VariantClear(&left);
5975     VariantClear(&right);
5976     VariantClear(&result);
5977 
5978     /* Test if one expression is numeric and the other is a string */
5979     V_VT(&left) = VT_INT;
5980     V_VT(&right) = VT_BSTR;
5981     V_INT(&left) = 12;
5982     V_BSTR(&right) = SysAllocString(sz34);
5983     hres = pVarCat(&left,&right,&result);
5984     ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5985     if (pVarCmp)
5986         ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ,
5987            "VarCat: NUMBER concat with VT_BSTR, incorrect result\n");
5988 
5989     VariantClear(&left);
5990     VariantClear(&right);
5991     VariantClear(&result);
5992 
5993     V_VT(&left) = VT_BSTR;
5994     V_VT(&right) = VT_INT;
5995     V_BSTR(&left) = SysAllocString(sz12);
5996     V_INT(&right) = 34;
5997     hres = pVarCat(&left,&right,&result);
5998     ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5999     if (pVarCmp)
6000         ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ,
6001            "VarCat: VT_BSTR concat with NUMBER, incorrect result\n");
6002 
6003     VariantClear(&left);
6004     VariantClear(&right);
6005     VariantClear(&result);
6006     VariantClear(&expected);
6007 
6008     /* Test concat dates with strings */
6009     V_VT(&left) = VT_BSTR;
6010     V_VT(&right) = VT_DATE;
6011     V_VT(&expected) = VT_BSTR;
6012     V_VT(&expected_broken) = VT_BSTR;
6013     V_BSTR(&left) = SysAllocString(sz12);
6014     V_DATE(&right) = 29494.0;
6015     V_BSTR(&expected)= SysAllocString(sz12_date);
6016     V_BSTR(&expected_broken)= SysAllocString(sz12_date_broken);
6017     hres = pVarCat(&left,&right,&result);
6018     ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
6019     if (pVarCmp)
6020         ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ ||
6021            broken(pVarCmp(&result,&expected_broken,lcid,0) == VARCMP_EQ), /* Some W98 and NT4 (intermittent) */
6022            "VarCat: VT_BSTR concat with VT_DATE returned incorrect result\n");
6023 
6024     VariantClear(&left);
6025     VariantClear(&right);
6026     VariantClear(&result);
6027     VariantClear(&expected);
6028     VariantClear(&expected_broken);
6029 
6030     V_VT(&left) = VT_DATE;
6031     V_VT(&right) = VT_BSTR;
6032     V_VT(&expected) = VT_BSTR;
6033     V_VT(&expected_broken) = VT_BSTR;
6034     V_DATE(&left) = 29494.0;
6035     V_BSTR(&right) = SysAllocString(sz12);
6036     V_BSTR(&expected)= SysAllocString(date_sz12);
6037     V_BSTR(&expected_broken)= SysAllocString(date_sz12_broken);
6038     hres = pVarCat(&left,&right,&result);
6039     ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
6040     if (pVarCmp)
6041         ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ ||
6042            broken(pVarCmp(&result,&expected_broken,lcid,0) == VARCMP_EQ), /* Some W98 and NT4 (intermittent) */
6043            "VarCat: VT_DATE concat with VT_BSTR returned incorrect result\n");
6044 
6045     VariantClear(&left);
6046     VariantClear(&right);
6047     VariantClear(&result);
6048     VariantClear(&expected);
6049     VariantClear(&expected_broken);
6050 
6051     /* Test of both expressions are empty */
6052     V_VT(&left) = VT_BSTR;
6053     V_VT(&right) = VT_BSTR;
6054     V_VT(&expected) = VT_BSTR;
6055     V_BSTR(&left) = SysAllocString(sz_empty);
6056     V_BSTR(&right) = SysAllocString(sz_empty);
6057     V_BSTR(&expected)= SysAllocString(sz_empty);
6058     hres = pVarCat(&left,&right,&result);
6059     ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
6060     if (pVarCmp)
6061         ok(pVarCmp(&result,&left,lcid,0) == VARCMP_EQ,
6062            "VarCat: EMPTY concat with EMPTY did not return empty VT_BSTR\n");
6063 
6064     /* Restore original date format settings */
6065     SetLocaleInfoA(lcid,LOCALE_SSHORTDATE,orig_date_format);
6066 
6067     VariantClear(&left);
6068     VariantClear(&right);
6069     VariantClear(&result);
6070     VariantClear(&expected);
6071 
6072     /* Dispatch conversion */
6073     init_test_dispatch(VT_NULL, &dispatch);
6074     V_VT(&left) = VT_DISPATCH;
6075     V_DISPATCH(&left) = &dispatch.IDispatch_iface;
6076 
6077     SET_EXPECT(dispatch_invoke);
6078     hres = VarCat(&left, &right, &result);
6079     ok(hres == S_OK, "got 0x%08x\n", hres);
6080     ok(V_VT(&result) == VT_BSTR, "got %d\n", V_VT(&result));
6081     ok(SysStringLen(V_BSTR(&result)) == 0, "got %d\n", SysStringLen(V_BSTR(&result)));
6082     CHECK_CALLED(dispatch_invoke);
6083 
6084     VariantClear(&left);
6085     VariantClear(&right);
6086     VariantClear(&result);
6087 
6088     init_test_dispatch(VT_NULL, &dispatch);
6089     V_VT(&right) = VT_DISPATCH;
6090     V_DISPATCH(&right) = &dispatch.IDispatch_iface;
6091 
6092     SET_EXPECT(dispatch_invoke);
6093     hres = VarCat(&left, &right, &result);
6094     ok(hres == S_OK, "got 0x%08x\n", hres);
6095     ok(V_VT(&result) == VT_BSTR, "got %d\n", V_VT(&result));
6096     ok(SysStringLen(V_BSTR(&result)) == 0, "got %d\n", SysStringLen(V_BSTR(&result)));
6097     CHECK_CALLED(dispatch_invoke);
6098 
6099     VariantClear(&left);
6100     VariantClear(&right);
6101     VariantClear(&result);
6102 
6103     init_test_dispatch(VT_UI1, &dispatch);
6104     V_VT(&right) = VT_DISPATCH;
6105     V_DISPATCH(&right) = &dispatch.IDispatch_iface;
6106 
6107     V_VT(&left) = VT_BSTR;
6108     V_BSTR(&left) = SysAllocString(sz12);
6109     SET_EXPECT(dispatch_invoke);
6110     hres = pVarCat(&left,&right,&result);
6111     ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
6112     CHECK_CALLED(dispatch_invoke);
6113     ok(!strcmp_wa(V_BSTR(&result), "1234"), "got %s\n", wine_dbgstr_w(V_BSTR(&result)));
6114 
6115     VariantClear(&left);
6116     VariantClear(&right);
6117     VariantClear(&result);
6118 
6119     init_test_dispatch(VT_NULL, &dispatch);
6120     dispatch.result = E_OUTOFMEMORY;
6121     V_VT(&right) = VT_DISPATCH;
6122     V_DISPATCH(&right) = &dispatch.IDispatch_iface;
6123 
6124     SET_EXPECT(dispatch_invoke);
6125     hres = VarCat(&left, &right, &result);
6126     ok(hres == E_OUTOFMEMORY, "got 0x%08x\n", hres);
6127     CHECK_CALLED(dispatch_invoke);
6128 
6129     VariantClear(&left);
6130     VariantClear(&right);
6131     VariantClear(&result);
6132 
6133     init_test_dispatch(VT_NULL, &dispatch);
6134     dispatch.result = DISP_E_TYPEMISMATCH;
6135     V_VT(&right) = VT_DISPATCH;
6136     V_DISPATCH(&right) = &dispatch.IDispatch_iface;
6137 
6138     SET_EXPECT(dispatch_invoke);
6139     hres = VarCat(&left, &right, &result);
6140     ok(hres == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hres);
6141     CHECK_CALLED(dispatch_invoke);
6142 
6143     VariantClear(&left);
6144     VariantClear(&right);
6145     VariantClear(&result);
6146 
6147     /* Test boolean conversion */
6148     V_VT(&left) = VT_BOOL;
6149     V_BOOL(&left) = VARIANT_TRUE;
6150     V_VT(&right) = VT_BSTR;
6151     V_BSTR(&right) = SysAllocStringLen(NULL,0);
6152     hres = pVarCat(&left, &right, &result);
6153     ok(hres == S_OK, "VarCat failed: %08x\n", hres);
6154     VariantClear(&right);
6155 
6156     cmp = strcmp_wa(V_BSTR(&result), "True");
6157     VariantClear(&result);
6158     if(!cmp) {
6159         V_VT(&right) = VT_BOOL;
6160         V_BOOL(&right) = 100;
6161         hres = pVarCat(&left, &right, &result);
6162         ok(hres == S_OK, "VarCat failed: %08x\n", hres);
6163         test_bstr_var(&result, "TrueTrue");
6164         VariantClear(&result);
6165 
6166         V_BOOL(&right) = VARIANT_FALSE;
6167         hres = pVarCat(&left, &right, &result);
6168         ok(hres == S_OK, "VarCat failed: %08x\n", hres);
6169         test_bstr_var(&result, "TrueFalse");
6170         VariantClear(&result);
6171     }else {
6172         skip("Got %s as True, assuming non-English locale\n", wine_dbgstr_w(V_BSTR(&result)));
6173     }
6174 }
6175 
6176 static HRESULT (WINAPI *pVarAnd)(LPVARIANT,LPVARIANT,LPVARIANT);
6177 
6178 #define VARAND(vt1,val1,vt2,val2,rvt,rval)               \
6179         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
6180         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
6181         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
6182         test_var_call2( __LINE__, pVarAnd, &left, &right, &exp )
6183 
6184 #define VARANDCY(vt1,val1,val2,rvt,rval)                 \
6185         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
6186         V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \
6187         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
6188         test_var_call2( __LINE__, pVarAnd, &left, &right, &exp )
6189 
6190 /* Skip any type that is not defined or produces an error for every case */
6191 #define SKIPTESTAND(a)                                \
6192         if (a == VT_ERROR || a == VT_VARIANT ||       \
6193             a == VT_DISPATCH || a == VT_UNKNOWN ||    \
6194             a > VT_UINT || a == 15 /*not defined*/)   \
6195             continue
6196 
6197 static void test_VarAnd(void)
6198 {
6199     static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
6200     static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
6201     VARIANT left, right, exp, result;
6202     BSTR false_str, true_str;
6203     VARTYPE i;
6204     HRESULT hres;
6205 
6206     CHECKPTR(VarAnd);
6207 
6208     true_str = SysAllocString(szTrue);
6209     false_str = SysAllocString(szFalse);
6210 
6211     /* Test all possible flag/vt combinations & the resulting vt type */
6212     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
6213     {
6214         VARTYPE leftvt, rightvt, resvt;
6215 
6216         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
6217         {
6218             SKIPTESTAND(leftvt);
6219 
6220             /* Check if we need/have support for I8 and/or UI8 */
6221             if ((leftvt == VT_I8 || leftvt == VT_UI8) && !has_i8)
6222                 continue;
6223 
6224             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
6225             {
6226                 BOOL bFail = FALSE;
6227                 SKIPTESTAND(rightvt);
6228 
6229                 /* Check if we need/have support for I8 and/or UI8 */
6230                 if ((rightvt == VT_I8 || rightvt == VT_UI8) && !has_i8)
6231                     continue;
6232 
6233                 memset(&left, 0, sizeof(left));
6234                 memset(&right, 0, sizeof(right));
6235                 V_VT(&left) = leftvt | ExtraFlags[i];
6236                 V_VT(&right) = rightvt | ExtraFlags[i];
6237                 V_VT(&result) = VT_EMPTY;
6238                 resvt = VT_EMPTY;
6239                 if ((leftvt | ExtraFlags[i]) == VT_BSTR)
6240                     V_BSTR(&left) = true_str;
6241                 if ((rightvt | ExtraFlags[i]) == VT_BSTR)
6242                     V_BSTR(&right) = true_str;
6243 
6244                 /* Native VarAnd always returns an error when using extra
6245                  * flags or if the variant combination is I8 and INT.
6246                  */
6247                 if ((leftvt == VT_I8 && rightvt == VT_INT) ||
6248                     (leftvt == VT_INT && rightvt == VT_I8) ||
6249                     ExtraFlags[i] != 0)
6250                     bFail = TRUE;
6251 
6252                 /* Determine return type */
6253                 else if (leftvt == VT_I8 || rightvt == VT_I8)
6254                     resvt = VT_I8;
6255                 else if (leftvt == VT_I4 || rightvt == VT_I4 ||
6256                     leftvt == VT_UINT || rightvt == VT_UINT ||
6257                     leftvt == VT_INT || rightvt == VT_INT ||
6258                     leftvt == VT_R4 || rightvt == VT_R4 ||
6259                     leftvt == VT_R8 || rightvt == VT_R8 ||
6260                     leftvt == VT_CY || rightvt == VT_CY ||
6261                     leftvt == VT_DATE || rightvt == VT_DATE ||
6262                     leftvt == VT_I1 || rightvt == VT_I1 ||
6263                     leftvt == VT_UI2 || rightvt == VT_UI2 ||
6264                     leftvt == VT_UI4 || rightvt == VT_UI4 ||
6265                     leftvt == VT_UI8 || rightvt == VT_UI8 ||
6266                     leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
6267                     resvt = VT_I4;
6268                 else if (leftvt == VT_UI1 || rightvt == VT_UI1 ||
6269                     leftvt == VT_I2 || rightvt == VT_I2 ||
6270                     leftvt == VT_EMPTY || rightvt == VT_EMPTY)
6271                     if ((leftvt == VT_NULL && rightvt == VT_UI1) ||
6272                         (leftvt == VT_UI1 && rightvt == VT_NULL) ||
6273                         (leftvt == VT_UI1 && rightvt == VT_UI1))
6274                         resvt = VT_UI1;
6275                     else
6276                         resvt = VT_I2;
6277                 else if (leftvt == VT_BOOL || rightvt == VT_BOOL ||
6278                     (leftvt == VT_BSTR && rightvt == VT_BSTR))
6279                     resvt = VT_BOOL;
6280                 else if (leftvt == VT_NULL || rightvt == VT_NULL ||
6281                     leftvt == VT_BSTR || rightvt == VT_BSTR)
6282                     resvt = VT_NULL;
6283                 else
6284                     bFail = TRUE;
6285 
6286                 hres = pVarAnd(&left, &right, &result);
6287 
6288                 /* Check expected HRESULT and if result variant type is correct */
6289                 if (bFail)
6290                     ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH,
6291                         "VarAnd: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
6292                         vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
6293                         vtstr(V_VT(&result)), hres);
6294                 else
6295                     ok (hres == S_OK && resvt == V_VT(&result),
6296                         "VarAnd: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
6297                         vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
6298                         S_OK, vtstr(V_VT(&result)), hres);
6299             }
6300         }
6301     }
6302 
6303     /*
6304      * Test returned values. Since we know the returned type is correct
6305      * and that we handle all combinations of invalid types, just check
6306      * that good type combinations produce the desired value.
6307      * FIXME: Test VT_DECIMAL
6308      */
6309     VARAND(EMPTY,0,EMPTY,0,I2,0);
6310     VARAND(EMPTY,1,EMPTY,0,I2,0);
6311     VARAND(EMPTY,1,EMPTY,1,I2,0);
6312     VARAND(EMPTY,0,NULL,0,I2,0);
6313     VARAND(EMPTY,1,NULL,0,I2,0);
6314     VARAND(EMPTY,1,NULL,1,I2,0);
6315     VARAND(EMPTY,0,I1,0,I4,0);
6316     VARAND(EMPTY,0,I1,1,I4,0);
6317     VARAND(EMPTY,1,I1,1,I4,0);
6318     VARAND(EMPTY,0,UI1,0,I2,0);
6319     VARAND(EMPTY,0,UI1,1,I2,0);
6320     VARAND(EMPTY,1,UI1,1,I2,0);
6321     VARAND(EMPTY,0,I2,0,I2,0);
6322     VARAND(EMPTY,0,I2,1,I2,0);
6323     VARAND(EMPTY,1,I2,1,I2,0);
6324     VARAND(EMPTY,0,UI2,0,I4,0);
6325     VARAND(EMPTY,0,UI2,1,I4,0);
6326     VARAND(EMPTY,1,UI2,1,I4,0);
6327     VARAND(EMPTY,0,I4,0,I4,0);
6328     VARAND(EMPTY,0,I4,1,I4,0);
6329     VARAND(EMPTY,1,I4,1,I4,0);
6330     VARAND(EMPTY,0,UI4,0,I4,0);
6331     VARAND(EMPTY,0,UI4,1,I4,0);
6332     VARAND(EMPTY,1,UI4,1,I4,0);
6333     if (has_i8)
6334     {
6335         VARAND(EMPTY,0,I8,0,I8,0);
6336         VARAND(EMPTY,0,I8,1,I8,0);
6337         VARAND(EMPTY,1,I8,1,I8,0);
6338         VARAND(EMPTY,0,UI8,0,I4,0);
6339         VARAND(EMPTY,0,UI8,1,I4,0);
6340         VARAND(EMPTY,1,UI8,1,I4,0);
6341     }
6342     VARAND(EMPTY,0,INT,0,I4,0);
6343     VARAND(EMPTY,0,INT,1,I4,0);
6344     VARAND(EMPTY,1,INT,1,I4,0);
6345     VARAND(EMPTY,0,UINT,0,I4,0);
6346     VARAND(EMPTY,0,UINT,1,I4,0);
6347     VARAND(EMPTY,1,UINT,1,I4,0);
6348     VARAND(EMPTY,0,BOOL,0,I2,0);
6349     VARAND(EMPTY,0,BOOL,1,I2,0);
6350     VARAND(EMPTY,1,BOOL,1,I2,0);
6351     VARAND(EMPTY,0,R4,0,I4,0);
6352     VARAND(EMPTY,0,R4,1,I4,0);
6353     VARAND(EMPTY,1,R4,1,I4,0);
6354     VARAND(EMPTY,0,R8,0,I4,0);
6355     VARAND(EMPTY,0,R8,1,I4,0);
6356     VARAND(EMPTY,1,R8,1,I4,0);
6357     VARAND(EMPTY,0,BSTR,false_str,I2,0);
6358     VARAND(EMPTY,0,BSTR,true_str,I2,0);
6359     VARANDCY(EMPTY,0,10000,I4,0);
6360 
6361     /* NULL OR 0 = NULL. NULL OR n = n */
6362     VARAND(NULL,0,NULL,0,NULL,0);
6363     VARAND(NULL,1,NULL,0,NULL,0);
6364     VARAND(NULL,0,I1,0,I4,0);
6365     VARAND(NULL,0,I1,1,NULL,0);
6366     VARAND(NULL,0,UI1,0,UI1,0);
6367     VARAND(NULL,0,UI1,1,NULL,0);
6368     VARAND(NULL,0,I2,0,I2,0);
6369     VARAND(NULL,0,I2,1,NULL,0);
6370     VARAND(NULL,0,UI2,0,I4,0);
6371     VARAND(NULL,0,UI2,1,NULL,0);
6372     VARAND(NULL,0,I4,0,I4,0);
6373     VARAND(NULL,0,I4,1,NULL,0);
6374     VARAND(NULL,0,UI4,0,I4,0);
6375     VARAND(NULL,0,UI4,1,NULL,0);
6376     if (has_i8)
6377     {
6378         VARAND(NULL,0,I8,0,I8,0);
6379         VARAND(NULL,0,I8,1,NULL,0);
6380         VARAND(NULL,0,UI8,0,I4,0);
6381         VARAND(NULL,0,UI8,1,NULL,0);
6382     }
6383     VARAND(NULL,0,INT,0,I4,0);
6384     VARAND(NULL,0,INT,1,NULL,0);
6385     VARAND(NULL,0,UINT,0,I4,0);
6386     VARAND(NULL,0,UINT,1,NULL,0);
6387     VARAND(NULL,0,BOOL,0,BOOL,0);
6388     VARAND(NULL,0,BOOL,1,NULL,0);
6389     VARAND(NULL,0,R4,0,I4,0);
6390     VARAND(NULL,0,R4,1,NULL,0);
6391     VARAND(NULL,0,R8,0,I4,0);
6392     VARAND(NULL,0,R8,1,NULL,0);
6393     VARAND(NULL,0,BSTR,false_str,BOOL,0);
6394     VARAND(NULL,0,BSTR,true_str,NULL,VARIANT_FALSE);
6395     VARANDCY(NULL,0,10000,NULL,0);
6396     VARANDCY(NULL,0,0,I4,0);
6397     VARAND(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
6398     VARAND(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
6399     VARAND(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
6400     VARAND(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
6401 
6402     /* Assume x,y & y,x are the same from now on to reduce the number of tests */
6403     VARAND(BOOL,VARIANT_TRUE,I1,-1,I4,-1);
6404     VARAND(BOOL,VARIANT_TRUE,I1,0,I4,0);
6405     VARAND(BOOL,VARIANT_FALSE,I1,0,I4,0);
6406     VARAND(BOOL,VARIANT_TRUE,UI1,255,I2,255);
6407     VARAND(BOOL,VARIANT_TRUE,UI1,0,I2,0);
6408     VARAND(BOOL,VARIANT_FALSE,UI1,0,I2,0);
6409     VARAND(BOOL,VARIANT_TRUE,I2,-1,I2,-1);
6410     VARAND(BOOL,VARIANT_TRUE,I2,0,I2,0);
6411     VARAND(BOOL,VARIANT_FALSE,I2,0,I2,0);
6412     VARAND(BOOL,VARIANT_TRUE,UI2,65535,I4,65535);
6413     VARAND(BOOL,VARIANT_TRUE,UI2,0,I4,0);
6414     VARAND(BOOL,VARIANT_FALSE,UI2,0,I4,0);
6415     VARAND(BOOL,VARIANT_TRUE,I4,-1,I4,-1);
6416     VARAND(BOOL,VARIANT_TRUE,I4,0,I4,0);
6417     VARAND(BOOL,VARIANT_FALSE,I4,0,I4,0);
6418     VARAND(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,-1);
6419     VARAND(BOOL,VARIANT_TRUE,UI4,0,I4,0);
6420     VARAND(BOOL,VARIANT_FALSE,UI4,0,I4,0);
6421     VARAND(BOOL,VARIANT_TRUE,R4,-1,I4,-1);
6422     VARAND(BOOL,VARIANT_TRUE,R4,0,I4,0);
6423     VARAND(BOOL,VARIANT_FALSE,R4,0,I4,0);
6424     VARAND(BOOL,VARIANT_TRUE,R8,-1,I4,-1);
6425     VARAND(BOOL,VARIANT_TRUE,R8,0,I4,0);
6426     VARAND(BOOL,VARIANT_FALSE,R8,0,I4,0);
6427     VARAND(BOOL,VARIANT_TRUE,DATE,-1,I4,-1);
6428     VARAND(BOOL,VARIANT_TRUE,DATE,0,I4,0);
6429     VARAND(BOOL,VARIANT_FALSE,DATE,0,I4,0);
6430     if (has_i8)
6431     {
6432         VARAND(BOOL,VARIANT_TRUE,I8,-1,I8,-1);
6433         VARAND(BOOL,VARIANT_TRUE,I8,0,I8,0);
6434         VARAND(BOOL,VARIANT_FALSE,I8,0,I8,0);
6435         VARAND(BOOL,VARIANT_TRUE,UI8,0,I4,0);
6436         VARAND(BOOL,VARIANT_FALSE,UI8,0,I4,0);
6437     }
6438     VARAND(BOOL,VARIANT_TRUE,INT,-1,I4,-1);
6439     VARAND(BOOL,VARIANT_TRUE,INT,0,I4,0);
6440     VARAND(BOOL,VARIANT_FALSE,INT,0,I4,0);
6441     VARAND(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,-1);
6442     VARAND(BOOL,VARIANT_TRUE,UINT,0,I4,0);
6443     VARAND(BOOL,VARIANT_FALSE,UINT,0,I4,0);
6444     VARAND(BOOL,VARIANT_FALSE,BSTR,false_str,BOOL,VARIANT_FALSE);
6445     VARAND(BOOL,VARIANT_TRUE,BSTR,false_str,BOOL,VARIANT_FALSE);
6446     VARAND(BOOL,VARIANT_FALSE,BSTR,true_str,BOOL,VARIANT_FALSE);
6447     VARAND(BOOL,VARIANT_TRUE,BSTR,true_str,BOOL,VARIANT_TRUE);
6448     VARANDCY(BOOL,VARIANT_TRUE,10000,I4,1);
6449     VARANDCY(BOOL,VARIANT_TRUE,0,I4,0);
6450     VARANDCY(BOOL,VARIANT_FALSE,0,I4,0);
6451     VARAND(I1,-1,I1,-1,I4,-1);
6452     VARAND(I1,-1,I1,0,I4,0);
6453     VARAND(I1,0,I1,0,I4,0);
6454     VARAND(I1,-1,UI1,255,I4,255);
6455     VARAND(I1,-1,UI1,0,I4,0);
6456     VARAND(I1,0,UI1,0,I4,0);
6457     VARAND(I1,-1,I2,-1,I4,-1);
6458     VARAND(I1,-1,I2,0,I4,0);
6459     VARAND(I1,0,I2,0,I4,0);
6460     VARAND(I1,-1,UI2,65535,I4,65535);
6461     VARAND(I1,-1,UI2,0,I4,0);
6462     VARAND(I1,0,UI2,0,I4,0);
6463     VARAND(I1,-1,I4,-1,I4,-1);
6464     VARAND(I1,-1,I4,0,I4,0);
6465     VARAND(I1,0,I4,0,I4,0);
6466     VARAND(I1,-1,UI4,0xffffffff,I4,-1);
6467     VARAND(I1,-1,UI4,0,I4,0);
6468     VARAND(I1,0,UI4,0,I4,0);
6469     VARAND(I1,-1,R4,-1,I4,-1);
6470     VARAND(I1,-1,R4,0,I4,0);
6471     VARAND(I1,0,R4,0,I4,0);
6472     VARAND(I1,-1,R8,-1,I4,-1);
6473     VARAND(I1,-1,R8,0,I4,0);
6474     VARAND(I1,0,R8,0,I4,0);
6475     VARAND(I1,-1,DATE,-1,I4,-1);
6476     VARAND(I1,-1,DATE,0,I4,0);
6477     VARAND(I1,0,DATE,0,I4,0);
6478     if (has_i8)
6479     {
6480         VARAND(I1,-1,I8,-1,I8,-1);
6481         VARAND(I1,-1,I8,0,I8,0);
6482         VARAND(I1,0,I8,0,I8,0);
6483         VARAND(I1,-1,UI8,0,I4,0);
6484         VARAND(I1,0,UI8,0,I4,0);
6485     }
6486     VARAND(I1,-1,INT,-1,I4,-1);
6487     VARAND(I1,-1,INT,0,I4,0);
6488     VARAND(I1,0,INT,0,I4,0);
6489     VARAND(I1,-1,UINT,0xffffffff,I4,-1);
6490     VARAND(I1,-1,UINT,0,I4,0);
6491     VARAND(I1,0,UINT,0,I4,0);
6492     VARAND(I1,0,BSTR,false_str,I4,0);
6493     VARAND(I1,-1,BSTR,false_str,I4,0);
6494     VARAND(I1,0,BSTR,true_str,I4,0);
6495     VARAND(I1,-1,BSTR,true_str,I4,-1);
6496     VARANDCY(I1,-1,10000,I4,1);
6497     VARANDCY(I1,-1,0,I4,0);
6498     VARANDCY(I1,0,0,I4,0);
6499 
6500     VARAND(UI1,255,UI1,255,UI1,255);
6501     VARAND(UI1,255,UI1,0,UI1,0);
6502     VARAND(UI1,0,UI1,0,UI1,0);
6503     VARAND(UI1,255,I2,-1,I2,255);
6504     VARAND(UI1,255,I2,0,I2,0);
6505     VARAND(UI1,0,I2,0,I2,0);
6506     VARAND(UI1,255,UI2,65535,I4,255);
6507     VARAND(UI1,255,UI2,0,I4,0);
6508     VARAND(UI1,0,UI2,0,I4,0);
6509     VARAND(UI1,255,I4,-1,I4,255);
6510     VARAND(UI1,255,I4,0,I4,0);
6511     VARAND(UI1,0,I4,0,I4,0);
6512     VARAND(UI1,255,UI4,0xffffffff,I4,255);
6513     VARAND(UI1,255,UI4,0,I4,0);
6514     VARAND(UI1,0,UI4,0,I4,0);
6515     VARAND(UI1,255,R4,-1,I4,255);
6516     VARAND(UI1,255,R4,0,I4,0);
6517     VARAND(UI1,0,R4,0,I4,0);
6518     VARAND(UI1,255,R8,-1,I4,255);
6519     VARAND(UI1,255,R8,0,I4,0);
6520     VARAND(UI1,0,R8,0,I4,0);
6521     VARAND(UI1,255,DATE,-1,I4,255);
6522     VARAND(UI1,255,DATE,0,I4,0);
6523     VARAND(UI1,0,DATE,0,I4,0);
6524     if (has_i8)
6525     {
6526         VARAND(UI1,255,I8,-1,I8,255);
6527         VARAND(UI1,255,I8,0,I8,0);
6528         VARAND(UI1,0,I8,0,I8,0);
6529         VARAND(UI1,255,UI8,0,I4,0);
6530         VARAND(UI1,0,UI8,0,I4,0);
6531     }
6532     VARAND(UI1,255,INT,-1,I4,255);
6533     VARAND(UI1,255,INT,0,I4,0);
6534     VARAND(UI1,0,INT,0,I4,0);
6535     VARAND(UI1,255,UINT,0xffffffff,I4,255);
6536     VARAND(UI1,255,UINT,0,I4,0);
6537     VARAND(UI1,0,UINT,0,I4,0);
6538     VARAND(UI1,0,BSTR,false_str,I2,0);
6539     VARAND(UI1,255,BSTR,false_str,I2,0);
6540     VARAND(UI1,0,BSTR,true_str,I2,0);
6541     VARAND(UI1,255,BSTR,true_str,I2,255);
6542     VARANDCY(UI1,255,10000,I4,1);
6543     VARANDCY(UI1,255,0,I4,0);
6544     VARANDCY(UI1,0,0,I4,0);
6545 
6546     VARAND(I2,-1,I2,-1,I2,-1);
6547     VARAND(I2,-1,I2,0,I2,0);
6548     VARAND(I2,0,I2,0,I2,0);
6549     VARAND(I2,-1,UI2,65535,I4,65535);
6550     VARAND(I2,-1,UI2,0,I4,0);
6551     VARAND(I2,0,UI2,0,I4,0);
6552     VARAND(I2,-1,I4,-1,I4,-1);
6553     VARAND(I2,-1,I4,0,I4,0);
6554     VARAND(I2,0,I4,0,I4,0);
6555     VARAND(I2,-1,UI4,0xffffffff,I4,-1);
6556     VARAND(I2,-1,UI4,0,I4,0);
6557     VARAND(I2,0,UI4,0,I4,0);
6558     VARAND(I2,-1,R4,-1,I4,-1);
6559     VARAND(I2,-1,R4,0,I4,0);
6560     VARAND(I2,0,R4,0,I4,0);
6561     VARAND(I2,-1,R8,-1,I4,-1);
6562     VARAND(I2,-1,R8,0,I4,0);
6563     VARAND(I2,0,R8,0,I4,0);
6564     VARAND(I2,-1,DATE,-1,I4,-1);
6565     VARAND(I2,-1,DATE,0,I4,0);
6566     VARAND(I2,0,DATE,0,I4,0);
6567     if (has_i8)
6568     {
6569         VARAND(I2,-1,I8,-1,I8,-1);
6570         VARAND(I2,-1,I8,0,I8,0);
6571         VARAND(I2,0,I8,0,I8,0);
6572         VARAND(I2,-1,UI8,0,I4,0);
6573         VARAND(I2,0,UI8,0,I4,0);
6574     }
6575     VARAND(I2,-1,INT,-1,I4,-1);
6576     VARAND(I2,-1,INT,0,I4,0);
6577     VARAND(I2,0,INT,0,I4,0);
6578     VARAND(I2,-1,UINT,0xffffffff,I4,-1);
6579     VARAND(I2,-1,UINT,0,I4,0);
6580     VARAND(I2,0,UINT,0,I4,0);
6581     VARAND(I2,0,BSTR,false_str,I2,0);
6582     VARAND(I2,-1,BSTR,false_str,I2,0);
6583     VARAND(I2,0,BSTR,true_str,I2,0);
6584     VARAND(I2,-1,BSTR,true_str,I2,-1);
6585     VARANDCY(I2,-1,10000,I4,1);
6586     VARANDCY(I2,-1,0,I4,0);
6587     VARANDCY(I2,0,0,I4,0);
6588 
6589     VARAND(UI2,65535,UI2,65535,I4,65535);
6590     VARAND(UI2,65535,UI2,0,I4,0);
6591     VARAND(UI2,0,UI2,0,I4,0);
6592     VARAND(UI2,65535,I4,-1,I4,65535);
6593     VARAND(UI2,65535,I4,0,I4,0);
6594     VARAND(UI2,0,I4,0,I4,0);
6595     VARAND(UI2,65535,UI4,0xffffffff,I4,65535);
6596     VARAND(UI2,65535,UI4,0,I4,0);
6597     VARAND(UI2,0,UI4,0,I4,0);
6598     VARAND(UI2,65535,R4,-1,I4,65535);
6599     VARAND(UI2,65535,R4,0,I4,0);
6600     VARAND(UI2,0,R4,0,I4,0);
6601     VARAND(UI2,65535,R8,-1,I4,65535);
6602     VARAND(UI2,65535,R8,0,I4,0);
6603     VARAND(UI2,0,R8,0,I4,0);
6604     VARAND(UI2,65535,DATE,-1,I4,65535);
6605     VARAND(UI2,65535,DATE,0,I4,0);
6606     VARAND(UI2,0,DATE,0,I4,0);
6607     if (has_i8)
6608     {
6609         VARAND(UI2,65535,I8,-1,I8,65535);
6610         VARAND(UI2,65535,I8,0,I8,0);
6611         VARAND(UI2,0,I8,0,I8,0);
6612         VARAND(UI2,65535,UI8,0,I4,0);
6613         VARAND(UI2,0,UI8,0,I4,0);
6614     }
6615     VARAND(UI2,65535,INT,-1,I4,65535);
6616     VARAND(UI2,65535,INT,0,I4,0);
6617     VARAND(UI2,0,INT,0,I4,0);
6618     VARAND(UI2,65535,UINT,0xffffffff,I4,65535);
6619     VARAND(UI2,65535,UINT,0,I4,0);
6620     VARAND(UI2,0,UINT,0,I4,0);
6621     VARAND(UI2,0,BSTR,false_str,I4,0);
6622     VARAND(UI2,65535,BSTR,false_str,I4,0);
6623     VARAND(UI2,0,BSTR,true_str,I4,0);
6624     VARAND(UI2,65535,BSTR,true_str,I4,65535);
6625     VARANDCY(UI2,65535,10000,I4,1);
6626     VARANDCY(UI2,65535,0,I4,0);
6627     VARANDCY(UI2,0,0,I4,0);
6628 
6629     VARAND(I4,-1,I4,-1,I4,-1);
6630     VARAND(I4,-1,I4,0,I4,0);
6631     VARAND(I4,0,I4,0,I4,0);
6632     VARAND(I4,-1,UI4,0xffffffff,I4,-1);
6633     VARAND(I4,-1,UI4,0,I4,0);
6634     VARAND(I4,0,UI4,0,I4,0);
6635     VARAND(I4,-1,R4,-1,I4,-1);
6636     VARAND(I4,-1,R4,0,I4,0);
6637     VARAND(I4,0,R4,0,I4,0);
6638     VARAND(I4,-1,R8,-1,I4,-1);
6639     VARAND(I4,-1,R8,0,I4,0);
6640     VARAND(I4,0,R8,0,I4,0);
6641     VARAND(I4,-1,DATE,-1,I4,-1);
6642     VARAND(I4,-1,DATE,0,I4,0);
6643     VARAND(I4,0,DATE,0,I4,0);
6644     if (has_i8)
6645     {
6646         VARAND(I4,-1,I8,-1,I8,-1);
6647         VARAND(I4,-1,I8,0,I8,0);
6648         VARAND(I4,0,I8,0,I8,0);
6649         VARAND(I4,-1,UI8,0,I4,0);
6650         VARAND(I4,0,UI8,0,I4,0);
6651     }
6652     VARAND(I4,-1,INT,-1,I4,-1);
6653     VARAND(I4,-1,INT,0,I4,0);
6654     VARAND(I4,0,INT,0,I4,0);
6655     VARAND(I4,-1,UINT,0xffffffff,I4,-1);
6656     VARAND(I4,-1,UINT,0,I4,0);
6657     VARAND(I4,0,UINT,0,I4,0);
6658     VARAND(I4,0,BSTR,false_str,I4,0);
6659     VARAND(I4,-1,BSTR,false_str,I4,0);
6660     VARAND(I4,0,BSTR,true_str,I4,0);
6661     VARAND(I4,-1,BSTR,true_str,I4,-1);
6662     VARANDCY(I4,-1,10000,I4,1);
6663     VARANDCY(I4,-1,0,I4,0);
6664     VARANDCY(I4,0,0,I4,0);
6665 
6666     VARAND(UI4,0xffffffff,UI4,0xffffffff,I4,-1);
6667     VARAND(UI4,0xffffffff,UI4,0,I4,0);
6668     VARAND(UI4,0,UI4,0,I4,0);
6669     VARAND(UI4,0xffffffff,R4,-1,I4,-1);
6670     VARAND(UI4,0xffffffff,R4,0,I4,0);
6671     VARAND(UI4,0,R4,0,I4,0);
6672     VARAND(UI4,0xffffffff,R8,-1,I4,-1);
6673     VARAND(UI4,0xffffffff,R8,0,I4,0);
6674     VARAND(UI4,0,R8,0,I4,0);
6675     VARAND(UI4,0xffffffff,DATE,-1,I4,-1);
6676     VARAND(UI4,0xffffffff,DATE,0,I4,0);
6677     VARAND(UI4,0,DATE,0,I4,0);
6678     if (has_i8)
6679     {
6680         VARAND(UI4,0xffffffff,I8,0,I8,0);
6681         VARAND(UI4,0,I8,0,I8,0);
6682         VARAND(UI4,0xffffffff,UI8,0,I4,0);
6683         VARAND(UI4,0,UI8,0,I4,0);
6684     }
6685     VARAND(UI4,0xffffffff,INT,-1,I4,-1);
6686     VARAND(UI4,0xffffffff,INT,0,I4,0);
6687     VARAND(UI4,0,INT,0,I4,0);
6688     VARAND(UI4,0xffffffff,UINT,0xffffffff,I4,-1);
6689     VARAND(UI4,0xffffffff,UINT,0,I4,0);
6690     VARAND(UI4,0,UINT,0,I4,0);
6691     VARAND(UI4,0,BSTR,false_str,I4,0);
6692     VARAND(UI4,0xffffffff,BSTR,false_str,I4,0);
6693     VARAND(UI4,0,BSTR,true_str,I4,0);
6694     VARAND(UI4,0xffffffff,BSTR,true_str,I4,-1);
6695     VARANDCY(UI4,0xffffffff,10000,I4,1);
6696     VARANDCY(UI4,0xffffffff,0,I4,0);
6697     VARANDCY(UI4,0,0,I4,0);
6698 
6699     VARAND(R4,-1,R4,-1,I4,-1);
6700     VARAND(R4,-1,R4,0,I4,0);
6701     VARAND(R4,0,R4,0,I4,0);
6702     VARAND(R4,-1,R8,-1,I4,-1);
6703     VARAND(R4,-1,R8,0,I4,0);
6704     VARAND(R4,0,R8,0,I4,0);
6705     VARAND(R4,-1,DATE,-1,I4,-1);
6706     VARAND(R4,-1,DATE,0,I4,0);
6707     VARAND(R4,0,DATE,0,I4,0);
6708     if (has_i8)
6709     {
6710         VARAND(R4,-1,I8,-1,I8,-1);
6711         VARAND(R4,-1,I8,0,I8,0);
6712         VARAND(R4,0,I8,0,I8,0);
6713         VARAND(R4,-1,UI8,0,I4,0);
6714         VARAND(R4,0,UI8,0,I4,0);
6715     }
6716     VARAND(R4,-1,INT,-1,I4,-1);
6717     VARAND(R4,-1,INT,0,I4,0);
6718     VARAND(R4,0,INT,0,I4,0);
6719     VARAND(R4,-1,UINT,0xffffffff,I4,-1);
6720     VARAND(R4,-1,UINT,0,I4,0);
6721     VARAND(R4,0,UINT,0,I4,0);
6722     VARAND(R4,0,BSTR,false_str,I4,0);
6723     VARAND(R4,-1,BSTR,false_str,I4,0);
6724     VARAND(R4,0,BSTR,true_str,I4,0);
6725     VARAND(R4,-1,BSTR,true_str,I4,-1);
6726     VARANDCY(R4,-1,10000,I4,1);
6727     VARANDCY(R4,-1,0,I4,0);
6728     VARANDCY(R4,0,0,I4,0);
6729 
6730     VARAND(R8,-1,R8,-1,I4,-1);
6731     VARAND(R8,-1,R8,0,I4,0);
6732     VARAND(R8,0,R8,0,I4,0);
6733     VARAND(R8,-1,DATE,-1,I4,-1);
6734     VARAND(R8,-1,DATE,0,I4,0);
6735     VARAND(R8,0,DATE,0,I4,0);
6736     if (has_i8)
6737     {
6738         VARAND(R8,-1,I8,-1,I8,-1);
6739         VARAND(R8,-1,I8,0,I8,0);
6740         VARAND(R8,0,I8,0,I8,0);
6741         VARAND(R8,-1,UI8,0,I4,0);
6742         VARAND(R8,0,UI8,0,I4,0);
6743     }
6744     VARAND(R8,-1,INT,-1,I4,-1);
6745     VARAND(R8,-1,INT,0,I4,0);
6746     VARAND(R8,0,INT,0,I4,0);
6747     VARAND(R8,-1,UINT,0xffffffff,I4,-1);
6748     VARAND(R8,-1,UINT,0,I4,0);
6749     VARAND(R8,0,UINT,0,I4,0);
6750     VARAND(R8,0,BSTR,false_str,I4,0);
6751     VARAND(R8,-1,BSTR,false_str,I4,0);
6752     VARAND(R8,0,BSTR,true_str,I4,0);
6753     VARAND(R8,-1,BSTR,true_str,I4,-1);
6754     VARANDCY(R8,-1,10000,I4,1);
6755     VARANDCY(R8,-1,0,I4,0);
6756     VARANDCY(R8,0,0,I4,0);
6757 
6758     VARAND(DATE,-1,DATE,-1,I4,-1);
6759     VARAND(DATE,-1,DATE,0,I4,0);
6760     VARAND(DATE,0,DATE,0,I4,0);
6761     if (has_i8)
6762     {
6763         VARAND(DATE,-1,I8,-1,I8,-1);
6764         VARAND(DATE,-1,I8,0,I8,0);
6765         VARAND(DATE,0,I8,0,I8,0);
6766         VARAND(DATE,-1,UI8,0,I4,0);
6767         VARAND(DATE,0,UI8,0,I4,0);
6768     }
6769     VARAND(DATE,-1,INT,-1,I4,-1);
6770     VARAND(DATE,-1,INT,0,I4,0);
6771     VARAND(DATE,0,INT,0,I4,0);
6772     VARAND(DATE,-1,UINT,0xffffffff,I4,-1);
6773     VARAND(DATE,-1,UINT,0,I4,0);
6774     VARAND(DATE,0,UINT,0,I4,0);
6775     VARAND(DATE,0,BSTR,false_str,I4,0);
6776     VARAND(DATE,-1,BSTR,false_str,I4,0);
6777     VARAND(DATE,0,BSTR,true_str,I4,0);
6778     VARAND(DATE,-1,BSTR,true_str,I4,-1);
6779     VARANDCY(DATE,-1,10000,I4,1);
6780     VARANDCY(DATE,-1,0,I4,0);
6781     VARANDCY(DATE,0,0,I4,0);
6782 
6783     if (has_i8)
6784     {
6785         VARAND(I8,-1,I8,-1,I8,-1);
6786         VARAND(I8,-1,I8,0,I8,0);
6787         VARAND(I8,0,I8,0,I8,0);
6788         VARAND(I8,-1,UI8,0,I8,0);
6789         VARAND(I8,0,UI8,0,I8,0);
6790         VARAND(I8,-1,UINT,0,I8,0);
6791         VARAND(I8,0,UINT,0,I8,0);
6792         VARAND(I8,0,BSTR,false_str,I8,0);
6793         VARAND(I8,-1,BSTR,false_str,I8,0);
6794         VARAND(I8,0,BSTR,true_str,I8,0);
6795         VARAND(I8,-1,BSTR,true_str,I8,-1);
6796         VARANDCY(I8,-1,10000,I8,1);
6797         VARANDCY(I8,-1,0,I8,0);
6798         VARANDCY(I8,0,0,I8,0);
6799 
6800         VARAND(UI8,0xffff,UI8,0xffff,I4,0xffff);
6801         VARAND(UI8,0xffff,UI8,0,I4,0);
6802         VARAND(UI8,0,UI8,0,I4,0);
6803         VARAND(UI8,0xffff,INT,-1,I4,65535);
6804         VARAND(UI8,0xffff,INT,0,I4,0);
6805         VARAND(UI8,0,INT,0,I4,0);
6806         VARAND(UI8,0xffff,UINT,0xffff,I4,0xffff);
6807         VARAND(UI8,0xffff,UINT,0,I4,0);
6808         VARAND(UI8,0,UINT,0,I4,0);
6809         VARAND(UI8,0,BSTR,false_str,I4,0);
6810         VARAND(UI8,0xffff,BSTR,false_str,I4,0);
6811         VARAND(UI8,0,BSTR,true_str,I4,0);
6812         VARAND(UI8,0xffff,BSTR,true_str,I4,65535);
6813         VARANDCY(UI8,0xffff,10000,I4,1);
6814         VARANDCY(UI8,0xffff,0,I4,0);
6815         VARANDCY(UI8,0,0,I4,0);
6816     }
6817 
6818     VARAND(INT,-1,INT,-1,I4,-1);
6819     VARAND(INT,-1,INT,0,I4,0);
6820     VARAND(INT,0,INT,0,I4,0);
6821     VARAND(INT,-1,UINT,0xffff,I4,65535);
6822     VARAND(INT,-1,UINT,0,I4,0);
6823     VARAND(INT,0,UINT,0,I4,0);
6824     VARAND(INT,0,BSTR,false_str,I4,0);
6825     VARAND(INT,-1,BSTR,false_str,I4,0);
6826     VARAND(INT,0,BSTR,true_str,I4,0);
6827     VARAND(INT,-1,BSTR,true_str,I4,-1);
6828     VARANDCY(INT,-1,10000,I4,1);
6829     VARANDCY(INT,-1,0,I4,0);
6830     VARANDCY(INT,0,0,I4,0);
6831 
6832     VARAND(UINT,0xffff,UINT,0xffff,I4,0xffff);
6833     VARAND(UINT,0xffff,UINT,0,I4,0);
6834     VARAND(UINT,0,UINT,0,I4,0);
6835     VARAND(UINT,0,BSTR,false_str,I4,0);
6836     VARAND(UINT,0xffff,BSTR, false_str,I4,0);
6837     VARAND(UINT,0,BSTR,true_str,I4,0);
6838     VARAND(UINT,0xffff,BSTR,true_str,I4,65535);
6839     VARANDCY(UINT,0xffff,10000,I4,1);
6840     VARANDCY(UINT,0xffff,0,I4,0);
6841     VARANDCY(UINT,0,0,I4,0);
6842 
6843     VARAND(BSTR,false_str,BSTR,false_str,BOOL,0);
6844     VARAND(BSTR,true_str,BSTR,false_str,BOOL,VARIANT_FALSE);
6845     VARAND(BSTR,true_str,BSTR,true_str,BOOL,VARIANT_TRUE);
6846     VARANDCY(BSTR,true_str,10000,I4,1);
6847     VARANDCY(BSTR,false_str,10000,I4,0);
6848 
6849     SysFreeString(true_str);
6850     SysFreeString(false_str);
6851 }
6852 
6853 static void test_cmp( int line, LCID lcid, UINT flags, VARIANT *left, VARIANT *right, HRESULT result )
6854 {
6855     HRESULT hres;
6856 
6857     CHECKPTR(VarCmp);
6858 
6859     hres = pVarCmp(left,right,lcid,flags);
6860     ok_(__FILE__,line)(hres == result, "VarCmp(%s,%s): expected 0x%x, got hres=0x%x\n",
6861                        variantstr(left), variantstr(right), result, hres );
6862 }
6863 static void test_cmpex( int line, LCID lcid, VARIANT *left, VARIANT *right,
6864                         HRESULT res1, HRESULT res2, HRESULT res3, HRESULT res4 )
6865 {
6866     test_cmp( line, lcid, 0, left, right, res1 );
6867     V_VT(left) |= VT_RESERVED;
6868     test_cmp( line, lcid, 0, left, right, res2 );
6869     V_VT(left) &= ~VT_RESERVED;
6870     V_VT(right) |= VT_RESERVED;
6871     test_cmp( line, lcid, 0, left, right, res3 );
6872     V_VT(left) |= VT_RESERVED;
6873     test_cmp( line, lcid, 0, left, right, res4 );
6874     ok_(__FILE__,line)(V_VT(left) & V_VT(right) & VT_RESERVED, "VT_RESERVED filtered out\n");
6875 }
6876 
6877 /* ERROR from wingdi.h is interfering here */
6878 #undef ERROR
6879 #define _VARCMP(vt1,val1,vtfl1,vt2,val2,vtfl2,lcid,flags,result) \
6880         V_##vt1(&left) = val1; V_VT(&left) = VT_##vt1 | vtfl1; \
6881         V_##vt2(&right) = val2; V_VT(&right) = VT_##vt2 | vtfl2; \
6882         test_cmp( __LINE__, lcid, flags, &left, &right, result )
6883 #define VARCMPEX(vt1,val1,vt2,val2,res1,res2,res3,res4) \
6884         V_##vt1(&left) = val1; V_VT(&left) = VT_##vt1; \
6885         V_##vt2(&right) = val2; V_VT(&right) = VT_##vt2; \
6886         test_cmpex( __LINE__, lcid, &left, &right, res1, res2, res3, res4 )
6887 #define VARCMP(vt1,val1,vt2,val2,result) \
6888         VARCMPEX(vt1,val1,vt2,val2,result,result,result,result)
6889 /* The above macros do not work for VT_NULL as NULL gets expanded first */
6890 #define V_NULL_  V_NULL
6891 #define VT_NULL_ VT_NULL
6892 
6893 static void test_VarCmp(void)
6894 {
6895     VARIANT left, right;
6896     VARTYPE i;
6897     LCID lcid;
6898     HRESULT hres;
6899     DECIMAL dec;
6900     static const WCHAR szhuh[] = {'h','u','h','?','\0'};
6901     static const WCHAR sz2cents[] = {'2','c','e','n','t','s','\0'};
6902     static const WCHAR szempty[] = {'\0'};
6903     static const WCHAR sz0[] = {'0','\0'};
6904     static const WCHAR sz1[] = {'1','\0'};
6905     static const WCHAR sz7[] = {'7','\0'};
6906     static const WCHAR sz42[] = {'4','2','\0'};
6907     static const WCHAR sz1neg[] = {'-','1','\0'};
6908     static const WCHAR sz666neg[] = {'-','6','6','6','\0'};
6909     static const WCHAR sz1few[] = {'1','.','0','0','0','0','0','0','0','1','\0'};
6910     BSTR bstrhuh, bstrempty, bstr0, bstr1, bstr7, bstr42, bstr1neg, bstr666neg;
6911     BSTR bstr2cents, bstr1few;
6912 
6913     CHECKPTR(VarCmp);
6914 
6915     lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
6916     bstrempty = SysAllocString(szempty);
6917     bstrhuh = SysAllocString(szhuh);
6918     bstr2cents = SysAllocString(sz2cents);
6919     bstr0 = SysAllocString(sz0);
6920     bstr1 = SysAllocString(sz1);
6921     bstr7 = SysAllocString(sz7);
6922     bstr42 = SysAllocString(sz42);
6923     bstr1neg = SysAllocString(sz1neg);
6924     bstr666neg = SysAllocString(sz666neg);
6925     bstr1few = SysAllocString(sz1few);
6926 
6927     /* Test all possible flag/vt combinations & the resulting vt type */
6928     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
6929     {
6930         VARTYPE leftvt, rightvt;
6931 
6932         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
6933         {
6934 
6935             SKIPTESTS(leftvt);
6936 
6937             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
6938             {
6939                 BOOL bFail = FALSE;
6940                 HRESULT expect = VARCMP_EQ;
6941 
6942                 SKIPTESTS(rightvt);
6943 
6944                 memset(&left, 0, sizeof(left));
6945                 memset(&right, 0, sizeof(right));
6946                 V_VT(&left) = leftvt | ExtraFlags[i];
6947                 if (leftvt == VT_BSTR) {
6948                     V_BSTR(&left) = bstr1neg;
6949                     if (ExtraFlags[i] & VT_RESERVED)
6950                         expect = VARCMP_LT;
6951                     else
6952                         expect = VARCMP_GT;
6953                 }
6954                 V_VT(&right) = rightvt | ExtraFlags[i];
6955                 if (rightvt == VT_BSTR) {
6956                     V_BSTR(&right) = bstr1neg;
6957                     if (ExtraFlags[i] & VT_RESERVED)
6958                         expect = VARCMP_GT;
6959                     else
6960                         expect = VARCMP_LT;
6961                 }
6962 
6963                 /* Don't ask me why but native VarCmp cannot handle:
6964                    VT_I1, VT_UI2, VT_UI4, VT_UINT and VT_UI8.
6965                    VT_INT is only supported as left variant. Go figure.
6966                    Tested with DCOM98, Win2k, WinXP */
6967                 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
6968                     !IsValidVariantClearVT(leftvt, ExtraFlags[i] & ~VT_RESERVED) ||
6969                     !IsValidVariantClearVT(rightvt, ExtraFlags[i] & ~VT_RESERVED) ||
6970                     leftvt == VT_CLSID || rightvt == VT_CLSID ||
6971                     leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
6972                     leftvt == VT_ERROR || rightvt == VT_ERROR ||
6973                     leftvt == VT_RECORD || rightvt == VT_RECORD ||
6974                     leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN ||
6975                     leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
6976                     leftvt == VT_I1 || rightvt == VT_I1 ||
6977                     leftvt == VT_UI2 || rightvt == VT_UI2 ||
6978                     leftvt == VT_UI4 || rightvt == VT_UI4 ||
6979                     leftvt == VT_UI8 || rightvt == VT_UI8 ||
6980                     rightvt == VT_INT ||
6981                     leftvt == VT_UINT || rightvt == VT_UINT) {
6982                     bFail = TRUE;
6983                 }
6984 
6985                 if (leftvt == VT_ERROR && rightvt == VT_ERROR &&
6986                     !(ExtraFlags[i] & ~VT_RESERVED)) {
6987                     expect = VARCMP_EQ;
6988                     bFail = FALSE;
6989                 } else if (leftvt == VT_NULL || rightvt == VT_NULL)
6990                     expect = VARCMP_NULL;
6991                 else if (leftvt == VT_BSTR && rightvt == VT_BSTR)
6992                     expect = VARCMP_EQ;
6993                 else if (leftvt == VT_BSTR && rightvt == VT_EMPTY)
6994                     expect = VARCMP_GT;
6995                 else if (leftvt == VT_EMPTY && rightvt == VT_BSTR)
6996                     expect = VARCMP_LT;
6997 
6998                 hres = pVarCmp(&left, &right, LOCALE_USER_DEFAULT, 0);
6999                 if (bFail) {
7000                     ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
7001                        "VarCmp: %d|0x%X, %d|0x%X: Expected failure, got 0x%X\n",
7002                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres);
7003                 } else {
7004                     ok(hres == expect,
7005                        "VarCmp: %d|0x%X, %d|0x%X: Expected 0x%X, got 0x%X\n",
7006                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], expect,
7007                        hres);
7008                 }
7009             }
7010         }
7011     }
7012 
7013     /* VARCMP{,EX} run each 4 tests with a permutation of all possible
7014        input variants with (1) and without (0) VT_RESERVED set. The order
7015        of the permutations is (0,0); (1,0); (0,1); (1,1) */
7016     VARCMP(INT,4711,I2,4711,VARCMP_EQ);
7017     VARCMP(INT,4711,I2,-4711,VARCMP_GT);
7018     VARCMP(ERROR,0,ERROR,0,VARCMP_EQ);
7019     VARCMP(ERROR,0,UI1,0,DISP_E_TYPEMISMATCH);
7020     VARCMP(EMPTY,0,EMPTY,0,VARCMP_EQ);
7021     VARCMP(I4,1,R8,1.0,VARCMP_EQ);
7022     VARCMP(EMPTY,19,I2,0,VARCMP_EQ);
7023     ok(V_EMPTY(&left) == 19, "VT_EMPTY modified!\n");
7024     VARCMP(I4,1,UI1,1,VARCMP_EQ);
7025     VARCMP(I2,2,I2,2,VARCMP_EQ);
7026     VARCMP(I2,1,I2,2,VARCMP_LT);
7027     VARCMP(I2,2,I2,1,VARCMP_GT);
7028     VARCMP(I2,2,EMPTY,1,VARCMP_GT);
7029     VARCMP(I2,2,NULL_,1,VARCMP_NULL);
7030 
7031     /* BSTR handling, especially in conjunction with VT_RESERVED */
7032     VARCMP(BSTR,bstr0,NULL_,0,VARCMP_NULL);
7033     VARCMP(BSTR,bstr0,BSTR,bstr0,VARCMP_EQ);
7034     VARCMP(BSTR,bstrempty,BSTR,bstr0,VARCMP_LT);
7035     VARCMP(BSTR,bstr7,BSTR,bstr0,VARCMP_GT);
7036     VARCMP(BSTR,bstr7,BSTR,bstr1neg,VARCMP_GT);
7037     VARCMP(BSTR,bstr0,BSTR,NULL,VARCMP_GT);
7038     VARCMP(BSTR,NULL,BSTR,NULL,VARCMP_EQ);
7039     VARCMP(BSTR,bstrempty,BSTR,NULL,VARCMP_EQ);
7040     VARCMP(BSTR,NULL,EMPTY,0,VARCMP_EQ);
7041     VARCMP(EMPTY,0,BSTR,NULL,VARCMP_EQ);
7042     VARCMP(EMPTY,0,BSTR,bstrempty,VARCMP_EQ);
7043     VARCMP(EMPTY,1,BSTR,bstrempty,VARCMP_EQ);
7044     VARCMP(BSTR,bstr0,EMPTY,0,VARCMP_GT);
7045     VARCMP(BSTR,bstr42,EMPTY,0,VARCMP_GT);
7046     VARCMPEX(BSTR,bstrempty,UI1,0,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
7047     VARCMPEX(BSTR,bstrempty,I2,-1,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
7048     VARCMPEX(I4,0,BSTR,bstrempty,VARCMP_LT,VARCMP_LT,VARCMP_GT,VARCMP_LT);
7049     VARCMPEX(BSTR,NULL,UI1,0,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
7050     VARCMPEX(I4,7,BSTR,NULL,VARCMP_LT,VARCMP_LT,VARCMP_GT,VARCMP_LT);
7051     _VARCMP(BSTR,(BSTR)100,0,I2,100,0,lcid,0,VARCMP_GT);
7052     VARCMPEX(BSTR,bstr0,UI1,0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
7053     VARCMPEX(I2,0,BSTR,bstr0,VARCMP_LT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT);
7054     VARCMP(BSTR,bstrhuh,I4,I4_MAX,VARCMP_GT);
7055     VARCMP(BSTR,bstr2cents,I4,2,VARCMP_GT);
7056     VARCMPEX(BSTR,bstr2cents,I4,42,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
7057     VARCMP(BSTR,bstr2cents,I4,-1,VARCMP_GT);
7058     VARCMPEX(BSTR,bstr2cents,I4,-666,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
7059     VARCMPEX(BSTR,bstr0,I2,0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
7060     VARCMPEX(BSTR,bstr0,I4,0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
7061     VARCMPEX(BSTR,bstr0,I4,-666,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
7062     VARCMP(BSTR,bstr1,I4,0,VARCMP_GT);
7063     VARCMPEX(BSTR,bstr1,I4,1,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
7064     VARCMPEX(BSTR,bstr1,I4,I4_MAX,VARCMP_GT,VARCMP_LT,VARCMP_LT,VARCMP_GT);
7065     VARCMPEX(BSTR,bstr1,I4,-1,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
7066     VARCMP(BSTR,bstr7,I4,1,VARCMP_GT);
7067     VARCMPEX(BSTR,bstr7,I4,7,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
7068     VARCMPEX(BSTR,bstr7,I4,42,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_GT);
7069     VARCMPEX(BSTR,bstr42,I4,7,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
7070     VARCMPEX(BSTR,bstr42,I4,42,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
7071     VARCMPEX(BSTR,bstr42,I4,I4_MAX,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_GT);
7072     VARCMPEX(BSTR,bstr1neg,I4,1,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
7073     VARCMPEX(BSTR,bstr1neg,I4,42,VARCMP_GT,VARCMP_LT,VARCMP_LT,VARCMP_LT);
7074     VARCMPEX(BSTR,bstr1neg,I4,-1,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT);
7075     VARCMPEX(BSTR,bstr1neg,I4,-666,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_LT);
7076     VARCMPEX(BSTR,bstr666neg,I4,1,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
7077     VARCMPEX(BSTR,bstr666neg,I4,7,VARCMP_GT,VARCMP_LT,VARCMP_LT,VARCMP_LT);
7078     VARCMPEX(BSTR,bstr666neg,I4,42,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
7079     VARCMPEX(BSTR,bstr666neg,I4,I4_MAX,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
7080     VARCMPEX(BSTR,bstr666neg,I4,-1,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
7081     VARCMPEX(BSTR,bstr666neg,I4,-666,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT);
7082     VARCMPEX(BSTR,bstr7,R8,7.0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
7083     VARCMPEX(R8,3.141592,BSTR,NULL,VARCMP_LT,VARCMP_LT,VARCMP_GT,VARCMP_LT);
7084     VARCMP(BSTR,bstr7,BSTR,bstr7,VARCMP_EQ);
7085     VARCMP(BSTR,bstr7,BSTR,bstr42,VARCMP_GT);
7086     VARCMP(BSTR,bstr42,BSTR,bstr7,VARCMP_LT);
7087 
7088     /* DECIMAL handling */
7089     setdec(&dec,0,0,0,0);
7090     VARCMPEX(DECIMAL,dec,BSTR,bstr0,VARCMP_LT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT);
7091     setdec64(&dec,0,0,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF); /* max DECIMAL */
7092     VARCMP(DECIMAL,dec,R8,R8_MAX,VARCMP_LT);    /* R8 has bigger range */
7093     VARCMP(DECIMAL,dec,DATE,R8_MAX,VARCMP_LT);  /* DATE has bigger range */
7094     setdec64(&dec,0,0x80,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF);
7095     VARCMP(DECIMAL,dec,R8,-R8_MAX,VARCMP_GT);
7096     setdec64(&dec,20,0,0x5,0x6BC75E2D,0x63100001);    /* 1+1e-20 */
7097     VARCMP(DECIMAL,dec,R8,1,VARCMP_GT); /* DECIMAL has higher precision */
7098 
7099     /* Show that DATE is handled just as a R8 */
7100     VARCMP(DATE,DATE_MAX,DATE,DATE_MAX+1,VARCMP_LT);
7101     VARCMP(DATE,DATE_MIN,DATE,DATE_MIN-1,VARCMP_GT);
7102     VARCMP(DATE,R8_MIN,R8,R8_MIN,VARCMP_EQ);
7103     VARCMP(DATE,1,DATE,1+1e-15,VARCMP_LT);      /* 1e-15 == 8.64e-11 seconds */
7104     VARCMP(DATE,25570.0,DATE,25570.0,VARCMP_EQ);
7105     VARCMP(DATE,25570.0,DATE,25571.0,VARCMP_LT);
7106     VARCMP(DATE,25571.0,DATE,25570.0,VARCMP_GT);
7107     VARCMP(DATE,25570.0,EMPTY,0,VARCMP_GT);
7108     VARCMP(DATE,25570.0,NULL_,0,VARCMP_NULL);
7109 
7110     /* R4 precision handling */
7111     VARCMP(R4,1,R8,1+1e-8,VARCMP_EQ);
7112     VARCMP(R8,1+1e-8,R4,1,VARCMP_EQ);
7113     VARCMP(R8,1+1e-8,R8,1,VARCMP_GT);
7114     VARCMP(R8,R4_MAX*1.1,R4,R4_MAX,VARCMP_GT);
7115     VARCMP(R4,R4_MAX,R8,R8_MAX,VARCMP_LT);
7116     VARCMP(R4,1,DATE,1+1e-8,VARCMP_EQ);
7117     VARCMP(R4,1,BSTR,bstr1few,VARCMP_LT); /* bstr1few == 1+1e-8 */
7118     setdec(&dec,8,0,0,0x5F5E101);         /* 1+1e-8 */
7119     VARCMP(R4,1,DECIMAL,dec,VARCMP_LT);
7120 
7121     SysFreeString(bstrhuh);
7122     SysFreeString(bstrempty);
7123     SysFreeString(bstr0);
7124     SysFreeString(bstr1);
7125     SysFreeString(bstr7);
7126     SysFreeString(bstr42);
7127     SysFreeString(bstr1neg);
7128     SysFreeString(bstr666neg);
7129     SysFreeString(bstr2cents);
7130     SysFreeString(bstr1few);
7131 }
7132 
7133 static HRESULT (WINAPI *pVarPow)(LPVARIANT,LPVARIANT,LPVARIANT);
7134 
7135 #define VARPOW(vt1,val1,vt2,val2,rvt,rval)               \
7136         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
7137         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
7138         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
7139         test_var_call2( __LINE__, pVarPow, &left, &right, &exp )
7140 
7141 /* Skip any type that is not defined or produces an error for every case */
7142 #define SKIPTESTPOW(a)                            \
7143     if (a == VT_ERROR || a == VT_VARIANT ||       \
7144         a == VT_DISPATCH || a == VT_UNKNOWN ||    \
7145         a == VT_RECORD || a > VT_UINT ||          \
7146         a == 15 /*not defined*/)                  \
7147         continue
7148 
7149 static void test_VarPow(void)
7150 {
7151     static const WCHAR str2[] = { '2','\0' };
7152     static const WCHAR str3[] = { '3','\0' };
7153     VARIANT left, right, exp, result, cy, dec;
7154     BSTR num2_str, num3_str;
7155     VARTYPE i;
7156     HRESULT hres;
7157 
7158     CHECKPTR(VarPow);
7159 
7160     num2_str = SysAllocString(str2);
7161     num3_str = SysAllocString(str3);
7162 
7163     /* Test all possible flag/vt combinations & the resulting vt type */
7164     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
7165     {
7166         VARTYPE leftvt, rightvt, resvt;
7167 
7168         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
7169         {
7170             SKIPTESTPOW(leftvt);
7171 
7172             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
7173             {
7174                 BOOL bFail = FALSE;
7175                 SKIPTESTPOW(rightvt);
7176 
7177                 /* Native crashes with VT_BYREF */
7178                 if (ExtraFlags[i] == VT_BYREF)
7179                     continue;
7180 
7181                 memset(&left, 0, sizeof(left));
7182                 memset(&right, 0, sizeof(right));
7183                 V_VT(&left) = leftvt | ExtraFlags[i];
7184                 V_VT(&right) = rightvt | ExtraFlags[i];
7185                 V_VT(&result) = VT_EMPTY;
7186                 resvt = VT_EMPTY;
7187 
7188                 if (leftvt == VT_BSTR)
7189                     V_BSTR(&left) = num2_str;
7190                 if (rightvt == VT_BSTR)
7191                     V_BSTR(&right) = num2_str;
7192 
7193                 /* Native VarPow always returns an error when using extra flags */
7194                 if (ExtraFlags[i] != 0)
7195                     bFail = TRUE;
7196 
7197                 /* Determine return type */
7198                 else if ((leftvt == VT_NULL || rightvt == VT_NULL) &&
7199                          ((leftvt != VT_I8 && leftvt != VT_UI8 &&
7200                            rightvt != VT_I8 && rightvt != VT_UI8) || has_i8))
7201                     resvt = VT_NULL;
7202                 else if ((leftvt == VT_EMPTY || leftvt == VT_I2 ||
7203                     leftvt == VT_I4 || leftvt == VT_R4 ||
7204                     leftvt == VT_R8 || leftvt == VT_CY ||
7205                     leftvt == VT_DATE || leftvt == VT_BSTR ||
7206                     leftvt == VT_BOOL || leftvt == VT_DECIMAL ||
7207                     (leftvt >= VT_I1 && leftvt <= VT_UI4) ||
7208                     (has_i8 && (leftvt == VT_I8 || leftvt == VT_UI8)) ||
7209                     leftvt == VT_INT || leftvt == VT_UINT) &&
7210                     (rightvt == VT_EMPTY || rightvt == VT_I2 ||
7211                     rightvt == VT_I4 || rightvt == VT_R4 ||
7212                     rightvt == VT_R8 || rightvt == VT_CY ||
7213                     rightvt == VT_DATE || rightvt == VT_BSTR ||
7214                     rightvt == VT_BOOL || rightvt == VT_DECIMAL ||
7215                     (rightvt >= VT_I1 && rightvt <= VT_UI4) ||
7216                     (has_i8 && (rightvt == VT_I8 || rightvt == VT_UI8)) ||
7217                     rightvt == VT_INT || rightvt == VT_UINT))
7218                     resvt = VT_R8;
7219                 else
7220                     bFail = TRUE;
7221 
7222                 hres = pVarPow(&left, &right, &result);
7223 
7224                 /* Check expected HRESULT and if result variant type is correct */
7225                 if (bFail)
7226                     ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH,
7227                         "VarPow: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
7228                         vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
7229                         vtstr(V_VT(&result)), hres);
7230                 else
7231                     ok (hres == S_OK && resvt == V_VT(&result),
7232                         "VarPow: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
7233                         vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
7234                         S_OK, vtstr(V_VT(&result)), hres);
7235             }
7236         }
7237     }
7238 
7239     /* Check return values for valid variant type combinations */
7240     VARPOW(EMPTY,0,EMPTY,0,R8,1.0);
7241     VARPOW(EMPTY,0,NULL,0,NULL,0);
7242     VARPOW(EMPTY,0,I2,3,R8,0.0);
7243     VARPOW(EMPTY,0,I4,3,R8,0.0);
7244     VARPOW(EMPTY,0,R4,3.0f,R8,0.0);
7245     VARPOW(EMPTY,0,R8,3.0,R8,0.0);
7246     VARPOW(EMPTY,0,DATE,3,R8,0.0);
7247     VARPOW(EMPTY,0,BSTR,num3_str,R8,0.0);
7248     VARPOW(EMPTY,0,BOOL,VARIANT_FALSE,R8,1.0);
7249     VARPOW(EMPTY,0,I1,3,R8,0.0);
7250     VARPOW(EMPTY,0,UI1,3,R8,0.0);
7251     VARPOW(EMPTY,0,UI2,3,R8,0.0);
7252     VARPOW(EMPTY,0,UI4,3,R8,0.0);
7253     if (has_i8)
7254     {
7255         VARPOW(EMPTY,0,I8,3,R8,0.0);
7256         VARPOW(EMPTY,0,UI8,3,R8,0.0);
7257     }
7258     VARPOW(EMPTY,0,INT,3,R8,0.0);
7259     VARPOW(EMPTY,0,UINT,3,R8,0.0);
7260     VARPOW(NULL,0,EMPTY,0,NULL,0);
7261     VARPOW(NULL,0,NULL,0,NULL,0);
7262     VARPOW(NULL,0,I2,3,NULL,0);
7263     VARPOW(NULL,0,I4,3,NULL,0);
7264     VARPOW(NULL,0,R4,3.0f,NULL,0);
7265     VARPOW(NULL,0,R8,3.0,NULL,0);
7266     VARPOW(NULL,0,DATE,3,NULL,0);
7267     VARPOW(NULL,0,BSTR,num3_str,NULL,0);
7268     VARPOW(NULL,0,BOOL,VARIANT_TRUE,NULL,0);
7269     VARPOW(NULL,0,I1,3,NULL,0);
7270     VARPOW(NULL,0,UI1,3,NULL,0);
7271     VARPOW(NULL,0,UI2,3,NULL,0);
7272     VARPOW(NULL,0,UI4,3,NULL,0);
7273     if (has_i8)
7274     {
7275         VARPOW(NULL,0,I8,3,NULL,0);
7276         VARPOW(NULL,0,UI8,3,NULL,0);
7277     }
7278     VARPOW(NULL,0,INT,3,NULL,0);
7279     VARPOW(NULL,0,UINT,3,NULL,0);
7280     VARPOW(I2,2,EMPTY,0,R8,1.0);
7281     VARPOW(I2,2,NULL,0,NULL,0);
7282     VARPOW(I2,2,I2,3,R8,8.0);
7283     VARPOW(I2,2,I4,3,R8,8.0);
7284     VARPOW(I2,2,R4,3.0f,R8,8.0);
7285     VARPOW(I2,2,R8,3.0,R8,8.0);
7286     VARPOW(I2,2,DATE,3,R8,8.0);
7287     VARPOW(I2,2,BSTR,num3_str,R8,8.0);
7288     VARPOW(I2,2,BOOL,VARIANT_FALSE,R8,1.0);
7289     VARPOW(I2,2,I1,3,R8,8.0);
7290     VARPOW(I2,2,UI1,3,R8,8.0);
7291     VARPOW(I2,2,UI2,3,R8,8.0);
7292     VARPOW(I2,2,UI4,3,R8,8.0);
7293     if (has_i8)
7294     {
7295         VARPOW(I2,2,I8,3,R8,8.0);
7296         VARPOW(I2,2,UI8,3,R8,8.0);
7297     }
7298     VARPOW(I2,2,INT,3,R8,8.0);
7299     VARPOW(I2,2,UINT,3,R8,8.0);
7300     VARPOW(I4,2,EMPTY,0,R8,1.0);
7301     VARPOW(I4,2,NULL,0,NULL,0);
7302     VARPOW(I4,2,I2,3,R8,8.0);
7303     VARPOW(I4,2,I4,3,R8,8.0);
7304     VARPOW(I4,2,R4,3.0f,R8,8.0);
7305     VARPOW(I4,2,R8,3.0,R8,8.0);
7306     VARPOW(I4,2,DATE,3,R8,8.0);
7307     VARPOW(I4,2,BSTR,num3_str,R8,8.0);
7308     VARPOW(I4,2,BOOL,VARIANT_FALSE,R8,1.0);
7309     VARPOW(I4,2,I1,3,R8,8.0);
7310     VARPOW(I4,2,UI1,3,R8,8.0);
7311     VARPOW(I4,2,UI2,3,R8,8.0);
7312     VARPOW(I4,2,UI4,3,R8,8.0);
7313     if (has_i8)
7314     {
7315         VARPOW(I4,2,I8,3,R8,8.0);
7316         VARPOW(I4,2,UI8,3,R8,8.0);
7317     }
7318     VARPOW(I4,2,INT,3,R8,8.0);
7319     VARPOW(I4,2,UINT,3,R8,8.0);
7320     VARPOW(R4,2,EMPTY,0,R8,1.0);
7321     VARPOW(R4,2,NULL,0,NULL,0);
7322     VARPOW(R4,2,I2,3,R8,8.0);
7323     VARPOW(R4,2,I4,3,R8,8.0);
7324     VARPOW(R4,2,R4,3.0f,R8,8.0);
7325     VARPOW(R4,2,R8,3.0,R8,8.0);
7326     VARPOW(R4,2,DATE,3,R8,8.0);
7327     VARPOW(R4,2,BSTR,num3_str,R8,8.0);
7328     VARPOW(R4,2,BOOL,VARIANT_FALSE,R8,1.0);
7329     VARPOW(R4,2,I1,3,R8,8.0);
7330     VARPOW(R4,2,UI1,3,R8,8.0);
7331     VARPOW(R4,2,UI2,3,R8,8.0);
7332     VARPOW(R4,2,UI4,3,R8,8.0);
7333     if (has_i8)
7334     {
7335         VARPOW(R4,2,I8,3,R8,8.0);
7336         VARPOW(R4,2,UI8,3,R8,8.0);
7337     }
7338     VARPOW(R4,2,INT,3,R8,8.0);
7339     VARPOW(R4,2,UINT,3,R8,8.0);
7340     VARPOW(R8,2,EMPTY,0,R8,1.0);
7341     VARPOW(R8,2,NULL,0,NULL,0);
7342     VARPOW(R8,2,I2,3,R8,8.0);
7343     VARPOW(R8,2,I4,3,R8,8.0);
7344     VARPOW(R8,2,R4,3.0f,R8,8.0);
7345     VARPOW(R8,2,R8,3.0,R8,8.0);
7346     VARPOW(R8,2,DATE,3,R8,8.0);
7347     VARPOW(R8,2,BSTR,num3_str,R8,8.0);
7348     VARPOW(R8,2,BOOL,VARIANT_FALSE,R8,1.0);
7349     VARPOW(R8,2,I1,3,R8,8.0);
7350     VARPOW(R8,2,UI1,3,R8,8.0);
7351     VARPOW(R8,2,UI2,3,R8,8.0);
7352     VARPOW(R8,2,UI4,3,R8,8.0);
7353     if (has_i8)
7354     {
7355         VARPOW(R8,2,I8,3,R8,8.0);
7356         VARPOW(R8,2,UI8,3,R8,8.0);
7357     }
7358     VARPOW(R8,2,INT,3,R8,8.0);
7359     VARPOW(R8,2,UINT,3,R8,8.0);
7360     VARPOW(DATE,2,EMPTY,0,R8,1.0);
7361     VARPOW(DATE,2,NULL,0,NULL,0);
7362     VARPOW(DATE,2,I2,3,R8,8.0);
7363     VARPOW(DATE,2,I4,3,R8,8.0);
7364     VARPOW(DATE,2,R4,3.0f,R8,8.0);
7365     VARPOW(DATE,2,R8,3.0,R8,8.0);
7366     VARPOW(DATE,2,DATE,3,R8,8.0);
7367     VARPOW(DATE,2,BSTR,num3_str,R8,8.0);
7368     VARPOW(DATE,2,BOOL,VARIANT_FALSE,R8,1.0);
7369     VARPOW(DATE,2,I1,3,R8,8.0);
7370     VARPOW(DATE,2,UI1,3,R8,8.0);
7371     VARPOW(DATE,2,UI2,3,R8,8.0);
7372     VARPOW(DATE,2,UI4,3,R8,8.0);
7373     if (has_i8)
7374     {
7375         VARPOW(DATE,2,I8,3,R8,8.0);
7376         VARPOW(DATE,2,UI8,3,R8,8.0);
7377     }
7378     VARPOW(DATE,2,INT,3,R8,8.0);
7379     VARPOW(DATE,2,UINT,3,R8,8.0);
7380     VARPOW(BSTR,num2_str,EMPTY,0,R8,1.0);
7381     VARPOW(BSTR,num2_str,NULL,0,NULL,0);
7382     VARPOW(BSTR,num2_str,I2,3,R8,8.0);
7383     VARPOW(BSTR,num2_str,I4,3,R8,8.0);
7384     VARPOW(BSTR,num2_str,R4,3.0f,R8,8.0);
7385     VARPOW(BSTR,num2_str,R8,3.0,R8,8.0);
7386     VARPOW(BSTR,num2_str,DATE,3,R8,8.0);
7387     VARPOW(BSTR,num2_str,BSTR,num3_str,R8,8.0);
7388     VARPOW(BSTR,num2_str,BOOL,VARIANT_FALSE,R8,1.0);
7389     VARPOW(BSTR,num2_str,I1,3,R8,8.0);
7390     VARPOW(BSTR,num2_str,UI1,3,R8,8.0);
7391     VARPOW(BSTR,num2_str,UI2,3,R8,8.0);
7392     VARPOW(BSTR,num2_str,UI4,3,R8,8.0);
7393     if (has_i8)
7394     {
7395         VARPOW(BSTR,num2_str,I8,3,R8,8.0);
7396         VARPOW(BSTR,num2_str,UI8,3,R8,8.0);
7397     }
7398     VARPOW(BSTR,num2_str,INT,3,R8,8.0);
7399     VARPOW(BSTR,num2_str,UINT,3,R8,8.0);
7400     VARPOW(BOOL,VARIANT_TRUE,EMPTY,0,R8,1.0);
7401     VARPOW(BOOL,VARIANT_TRUE,NULL,0,NULL,0);
7402     VARPOW(BOOL,VARIANT_TRUE,I2,3,R8,-1.0);
7403     VARPOW(BOOL,VARIANT_TRUE,I4,3,R8,-1.0);
7404     VARPOW(BOOL,VARIANT_TRUE,R4,3.0f,R8,-1.0);
7405     VARPOW(BOOL,VARIANT_TRUE,R8,3.0,R8,-1.0);
7406     VARPOW(BOOL,VARIANT_TRUE,DATE,3,R8,-1.0);
7407     VARPOW(BOOL,VARIANT_TRUE,BSTR,num3_str,R8,-1.0);
7408     VARPOW(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,R8,-1.0);
7409     VARPOW(BOOL,VARIANT_TRUE,I1,3,R8,-1.0);
7410     VARPOW(BOOL,VARIANT_TRUE,UI1,3,R8,-1.0);
7411     VARPOW(BOOL,VARIANT_TRUE,UI2,3,R8,-1.0);
7412     VARPOW(BOOL,VARIANT_TRUE,UI4,3,R8,-1.0);
7413     if (has_i8)
7414     {
7415         VARPOW(BOOL,VARIANT_TRUE,I8,3,R8,-1.0);
7416         VARPOW(BOOL,VARIANT_TRUE,UI8,3,R8,-1.0);
7417     }
7418     VARPOW(BOOL,VARIANT_TRUE,INT,3,R8,-1.0);
7419     VARPOW(BOOL,VARIANT_TRUE,UINT,3,R8,-1.0);
7420     VARPOW(I1,2,EMPTY,0,R8,1.0);
7421     VARPOW(I1,2,NULL,0,NULL,0);
7422     VARPOW(I1,2,I2,3,R8,8.0);
7423     VARPOW(I1,2,I4,3,R8,8.0);
7424     VARPOW(I1,2,R4,3.0f,R8,8.0);
7425     VARPOW(I1,2,R8,3.0,R8,8.0);
7426     VARPOW(I1,2,DATE,3,R8,8.0);
7427     VARPOW(I1,2,BSTR,num3_str,R8,8.0);
7428     VARPOW(I1,2,BOOL,VARIANT_FALSE,R8,1.0);
7429     VARPOW(I1,2,I1,3,R8,8.0);
7430     VARPOW(I1,2,UI1,3,R8,8.0);
7431     VARPOW(I1,2,UI2,3,R8,8.0);
7432     VARPOW(I1,2,UI4,3,R8,8.0);
7433     if (has_i8)
7434     {
7435         VARPOW(I1,2,I8,3,R8,8.0);
7436         VARPOW(I1,2,UI8,3,R8,8.0);
7437     }
7438     VARPOW(I1,2,INT,3,R8,8.0);
7439     VARPOW(I1,2,UINT,3,R8,8.0);
7440     VARPOW(UI1,2,EMPTY,0,R8,1.0);
7441     VARPOW(UI1,2,NULL,0,NULL,0);
7442     VARPOW(UI1,2,I2,3,R8,8.0);
7443     VARPOW(UI1,2,I4,3,R8,8.0);
7444     VARPOW(UI1,2,R4,3.0f,R8,8.0);
7445     VARPOW(UI1,2,R8,3.0,R8,8.0);
7446     VARPOW(UI1,2,DATE,3,R8,8.0);
7447     VARPOW(UI1,2,BSTR,num3_str,R8,8.0);
7448     VARPOW(UI1,2,BOOL,VARIANT_FALSE,R8,1.0);
7449     VARPOW(UI1,2,I1,3,R8,8.0);
7450     VARPOW(UI1,2,UI1,3,R8,8.0);
7451     VARPOW(UI1,2,UI2,3,R8,8.0);
7452     VARPOW(UI1,2,UI4,3,R8,8.0);
7453     if (has_i8)
7454     {
7455         VARPOW(UI1,2,I8,3,R8,8.0);
7456         VARPOW(UI1,2,UI8,3,R8,8.0);
7457     }
7458     VARPOW(UI1,2,INT,3,R8,8.0);
7459     VARPOW(UI1,2,UINT,3,R8,8.0);
7460     VARPOW(UI2,2,EMPTY,0,R8,1.0);
7461     VARPOW(UI2,2,NULL,0,NULL,0);
7462     VARPOW(UI2,2,I2,3,R8,8.0);
7463     VARPOW(UI2,2,I4,3,R8,8.0);
7464     VARPOW(UI2,2,R4,3.0f,R8,8.0);
7465     VARPOW(UI2,2,R8,3.0,R8,8.0);
7466     VARPOW(UI2,2,DATE,3,R8,8.0);
7467     VARPOW(UI2,2,BSTR,num3_str,R8,8.0);
7468     VARPOW(UI2,2,BOOL,VARIANT_FALSE,R8,1.0);
7469     VARPOW(UI2,2,I1,3,R8,8.0);
7470     VARPOW(UI2,2,UI1,3,R8,8.0);
7471     VARPOW(UI2,2,UI2,3,R8,8.0);
7472     VARPOW(UI2,2,UI4,3,R8,8.0);
7473     if (has_i8)
7474     {
7475         VARPOW(UI2,2,I8,3,R8,8.0);
7476         VARPOW(UI2,2,UI8,3,R8,8.0);
7477     }
7478     VARPOW(UI2,2,INT,3,R8,8.0);
7479     VARPOW(UI2,2,UINT,3,R8,8.0);
7480     VARPOW(UI4,2,EMPTY,0,R8,1.0);
7481     VARPOW(UI4,2,NULL,0,NULL,0);
7482     VARPOW(UI4,2,I2,3,R8,8.0);
7483     VARPOW(UI4,2,I4,3,R8,8.0);
7484     VARPOW(UI4,2,R4,3.0f,R8,8.0);
7485     VARPOW(UI4,2,R8,3.0,R8,8.0);
7486     VARPOW(UI4,2,DATE,3,R8,8.0);
7487     VARPOW(UI4,2,BSTR,num3_str,R8,8.0);
7488     VARPOW(UI4,2,BOOL,VARIANT_FALSE,R8,1.0);
7489     VARPOW(UI4,2,I1,3,R8,8.0);
7490     VARPOW(UI4,2,UI1,3,R8,8.0);
7491     VARPOW(UI4,2,UI2,3,R8,8.0);
7492     VARPOW(UI4,2,UI4,3,R8,8.0);
7493     if (has_i8)
7494     {
7495         VARPOW(UI4,2,I8,3,R8,8.0);
7496         VARPOW(UI4,2,UI8,3,R8,8.0);
7497     }
7498     VARPOW(UI4,2,INT,3,R8,8.0);
7499     VARPOW(UI4,2,UINT,3,R8,8.0);
7500     if (has_i8)
7501     {
7502         VARPOW(I8,2,EMPTY,0,R8,1.0);
7503         VARPOW(I8,2,NULL,0,NULL,0);
7504         VARPOW(I8,2,I2,3,R8,8.0);
7505         VARPOW(I8,2,I4,3,R8,8.0);
7506         VARPOW(I8,2,R4,3.0f,R8,8.0);
7507         VARPOW(I8,2,R8,3.0,R8,8.0);
7508         VARPOW(I8,2,DATE,3,R8,8.0);
7509         VARPOW(I8,2,BSTR,num3_str,R8,8.0);
7510         VARPOW(I8,2,BOOL,VARIANT_FALSE,R8,1.0);
7511         VARPOW(I8,2,I1,3,R8,8.0);
7512         VARPOW(I8,2,UI1,3,R8,8.0);
7513         VARPOW(I8,2,UI2,3,R8,8.0);
7514         VARPOW(I8,2,UI4,3,R8,8.0);
7515         VARPOW(I8,2,I8,3,R8,8.0);
7516         VARPOW(I8,2,UI8,3,R8,8.0);
7517         VARPOW(I8,2,INT,3,R8,8.0);
7518         VARPOW(I8,2,UINT,3,R8,8.0);
7519         VARPOW(UI8,2,EMPTY,0,R8,1.0);
7520         VARPOW(UI8,2,NULL,0,NULL,0);
7521         VARPOW(UI8,2,I2,3,R8,8.0);
7522         VARPOW(UI8,2,I4,3,R8,8.0);
7523         VARPOW(UI8,2,R4,3.0f,R8,8.0);
7524         VARPOW(UI8,2,R8,3.0,R8,8.0);
7525         VARPOW(UI8,2,DATE,3,R8,8.0);
7526         VARPOW(UI8,2,BSTR,num3_str,R8,8.0);
7527         VARPOW(UI8,2,I1,3,R8,8.0);
7528         VARPOW(UI8,2,UI1,3,R8,8.0);
7529         VARPOW(UI8,2,UI2,3,R8,8.0);
7530         VARPOW(UI8,2,UI4,3,R8,8.0);
7531         VARPOW(UI8,2,I8,3,R8,8.0);
7532         VARPOW(UI8,2,UI8,3,R8,8.0);
7533         VARPOW(UI8,2,INT,3,R8,8.0);
7534         VARPOW(UI8,2,UINT,3,R8,8.0);
7535     }
7536     VARPOW(INT,2,EMPTY,0,R8,1.0);
7537     VARPOW(INT,2,NULL,0,NULL,0);
7538     VARPOW(INT,2,I2,3,R8,8.0);
7539     VARPOW(INT,2,I4,3,R8,8.0);
7540     VARPOW(INT,2,R4,3.0f,R8,8.0);
7541     VARPOW(INT,2,R8,3.0,R8,8.0);
7542     VARPOW(INT,2,DATE,3,R8,8.0);
7543     VARPOW(INT,2,BSTR,num3_str,R8,8.0);
7544     VARPOW(INT,2,BOOL,VARIANT_FALSE,R8,1.0);
7545     VARPOW(INT,2,I1,3,R8,8.0);
7546     VARPOW(INT,2,UI1,3,R8,8.0);
7547     VARPOW(INT,2,UI2,3,R8,8.0);
7548     VARPOW(INT,2,UI4,3,R8,8.0);
7549     if (has_i8)
7550     {
7551         VARPOW(INT,2,I8,3,R8,8.0);
7552         VARPOW(INT,2,UI8,3,R8,8.0);
7553     }
7554     VARPOW(INT,2,INT,3,R8,8.0);
7555     VARPOW(INT,2,UINT,3,R8,8.0);
7556     VARPOW(UINT,2,EMPTY,0,R8,1.0);
7557     VARPOW(UINT,2,NULL,0,NULL,0);
7558     VARPOW(UINT,2,I2,3,R8,8.0);
7559     VARPOW(UINT,2,I4,3,R8,8.0);
7560     VARPOW(UINT,2,R4,3.0f,R8,8.0);
7561     VARPOW(UINT,2,R8,3.0,R8,8.0);
7562     VARPOW(UINT,2,DATE,3,R8,8.0);
7563     VARPOW(UINT,2,BSTR,num3_str,R8,8.0);
7564     VARPOW(UINT,2,BOOL,VARIANT_FALSE,R8,1.0);
7565     VARPOW(UINT,2,I1,3,R8,8.0);
7566     VARPOW(UINT,2,UI1,3,R8,8.0);
7567     VARPOW(UINT,2,UI2,3,R8,8.0);
7568     VARPOW(UINT,2,UI4,3,R8,8.0);
7569     if (has_i8)
7570     {
7571         VARPOW(UINT,2,I8,3,R8,8.0);
7572         VARPOW(UINT,2,UI8,3,R8,8.0);
7573     }
7574     VARPOW(UINT,2,INT,3,R8,8.0);
7575     VARPOW(UINT,2,UINT,3,R8,8.0);
7576 
7577     /* Manually test some VT_CY, VT_DECIMAL variants */
7578     V_VT(&cy) = VT_CY;
7579     hres = VarCyFromI4(2, &V_CY(&cy));
7580     ok(hres == S_OK, "VarCyFromI4 failed!\n");
7581     V_VT(&dec) = VT_DECIMAL;
7582     hres = VarDecFromR8(2.0, &V_DECIMAL(&dec));
7583     ok(hres == S_OK, "VarDecFromR4 failed!\n");
7584     memset(&left, 0, sizeof(left));
7585     memset(&right, 0, sizeof(right));
7586     V_VT(&left) = VT_I4;
7587     V_I4(&left) = 100;
7588     V_VT(&right) = VT_I8;
7589     V_UI1(&right) = 2;
7590 
7591     hres = pVarPow(&cy, &cy, &result);
7592     ok(hres == S_OK && V_VT(&result) == VT_R8,
7593         "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7594         S_OK, hres, vtstr(V_VT(&result)));
7595     ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 4.0),
7596         "VARPOW: CY value %f, expected %f\n", V_R8(&result), 4.0);
7597 
7598     hres = pVarPow(&cy, &right, &result);
7599     if (hres == S_OK)
7600     {
7601         ok(V_VT(&result) == VT_R8,
7602            "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7603            S_OK, hres, vtstr(V_VT(&result)));
7604         ok(EQ_DOUBLE(V_R8(&result), 4.0),
7605            "VARPOW: CY value %f, expected %f\n", V_R8(&result), 4.0);
7606     }
7607     else
7608     {
7609         ok(hres == DISP_E_BADVARTYPE && V_VT(&result) == VT_EMPTY,
7610            "VARPOW: expected coerced hres 0x%X type VT_EMPTY, got hres 0x%X type %s!\n",
7611            DISP_E_BADVARTYPE, hres, vtstr(V_VT(&result)));
7612     }
7613 
7614     hres = pVarPow(&left, &cy, &result);
7615     ok(hres == S_OK && V_VT(&result) == VT_R8,
7616         "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7617         S_OK, hres, vtstr(V_VT(&result)));
7618     ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 10000.0),
7619         "VARPOW: CY value %f, expected %f\n", V_R8(&result), 10000.0);
7620 
7621     hres = pVarPow(&left, &dec, &result);
7622     ok(hres == S_OK && V_VT(&result) == VT_R8,
7623         "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7624         S_OK, hres, vtstr(V_VT(&result)));
7625     ok(hres == S_OK && EQ_DOUBLE(V_R8(&result),10000.0),
7626         "VARPOW: DECIMAL value %f, expected %f\n", V_R8(&result), 10000.0);
7627 
7628     hres = pVarPow(&dec, &dec, &result);
7629     ok(hres == S_OK && V_VT(&result) == VT_R8,
7630         "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7631         S_OK, hres, vtstr(V_VT(&result)));
7632     ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 4.0),
7633         "VARPOW: DECIMAL value %f, expected %f\n", V_R8(&result), 4.0);
7634 
7635     hres = pVarPow(&dec, &right, &result);
7636     if (hres == S_OK)
7637     {
7638         ok(V_VT(&result) == VT_R8,
7639            "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7640            S_OK, hres, vtstr(V_VT(&result)));
7641         ok(EQ_DOUBLE(V_R8(&result), 4.0),
7642            "VARPOW: DECIMAL value %f, expected %f\n", V_R8(&result), 4.0);
7643     }
7644     else
7645     {
7646         ok(hres == DISP_E_BADVARTYPE && V_VT(&result) == VT_EMPTY,
7647            "VARPOW: expected coerced hres 0x%X type VT_EMPTY, got hres 0x%X type %s!\n",
7648            DISP_E_BADVARTYPE, hres, vtstr(V_VT(&result)));
7649     }
7650 
7651     SysFreeString(num2_str);
7652     SysFreeString(num3_str);
7653 }
7654 
7655 static HRESULT (WINAPI *pVarDiv)(LPVARIANT,LPVARIANT,LPVARIANT);
7656 
7657 #define VARDIV(vt1,val1,vt2,val2,rvt,rval)               \
7658         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
7659         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
7660         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
7661         test_var_call2( __LINE__, pVarDiv, &left, &right, &exp )
7662 
7663 /* Skip any type that is not defined or produces an error for every case */
7664 #define SKIPTESTDIV(a)                            \
7665     if (a == VT_ERROR || a == VT_VARIANT ||       \
7666         a == VT_DISPATCH || a == VT_UNKNOWN ||    \
7667         a == VT_RECORD || a > VT_UINT ||          \
7668         a == VT_I1 || a == VT_UI8 ||              \
7669         a == VT_INT || a == VT_UINT ||            \
7670         a == VT_UI2 || a == VT_UI4 ||             \
7671         a == 15 /*not defined*/)                  \
7672         continue
7673 
7674 static void test_VarDiv(void)
7675 {
7676     static const WCHAR str1[] = { '1','\0' };
7677     static const WCHAR str2[] = { '2','\0' };
7678     VARIANT left, right, exp, result, cy, dec;
7679     BSTR num1_str, num2_str;
7680     VARTYPE i;
7681     HRESULT hres;
7682     double r;
7683 
7684     CHECKPTR(VarDiv);
7685 
7686     num1_str = SysAllocString(str1);
7687     num2_str = SysAllocString(str2);
7688 
7689     /* Test all possible flag/vt combinations & the resulting vt type */
7690     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
7691     {
7692         VARTYPE leftvt, rightvt, resvt;
7693 
7694         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
7695         {
7696             SKIPTESTDIV(leftvt);
7697 
7698             /* Check if we need/have support for I8 */
7699             if (leftvt == VT_I8 && !has_i8)
7700                 continue;
7701 
7702             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
7703             {
7704                 BOOL bFail = FALSE;
7705                 SKIPTESTDIV(rightvt);
7706 
7707                 /* Check if we need/have support for I8 */
7708                 if (rightvt == VT_I8 && !has_i8)
7709                     continue;
7710 
7711                 /* Native crashes with VT_BYREF */
7712                 if (ExtraFlags[i] == VT_BYREF)
7713                     continue;
7714 
7715                 memset(&left, 0, sizeof(left));
7716                 memset(&right, 0, sizeof(right));
7717                 V_VT(&left) = leftvt | ExtraFlags[i];
7718                 V_VT(&right) = rightvt | ExtraFlags[i];
7719                 V_VT(&result) = VT_EMPTY;
7720                 resvt = VT_EMPTY;
7721 
7722                 if (leftvt == VT_BSTR)
7723                     V_BSTR(&left) = num2_str;
7724                 else if (leftvt == VT_DECIMAL)
7725                 {
7726                     VarDecFromR8(2.0, &V_DECIMAL(&left));
7727                     V_VT(&left) = leftvt | ExtraFlags[i];
7728                 }
7729 
7730                 /* Division by 0 is undefined */
7731                 switch(rightvt)
7732                 {
7733                 case VT_BSTR:
7734                     V_BSTR(&right) = num2_str;
7735                     break;
7736                 case VT_DECIMAL:
7737                     VarDecFromR8(2.0, &V_DECIMAL(&right));
7738                     V_VT(&right) = rightvt | ExtraFlags[i];
7739                     break;
7740                 case VT_BOOL:
7741                     V_BOOL(&right) = VARIANT_TRUE;
7742                     break;
7743                 case VT_I2: V_I2(&right) = 2; break;
7744                 case VT_I4: V_I4(&right) = 2; break;
7745                 case VT_R4: V_R4(&right) = 2.0f; break;
7746                 case VT_R8: V_R8(&right) = 2.0; break;
7747                 case VT_CY: V_CY(&right).int64 = 2; break;
7748                 case VT_DATE: V_DATE(&right) = 2; break;
7749                 case VT_UI1: V_UI1(&right) = 2; break;
7750                 case VT_I8: V_I8(&right) = 2; break;
7751                 default: break;
7752                 }
7753 
7754                 /* Determine return type */
7755                 if (rightvt != VT_EMPTY)
7756                 {
7757                     if (leftvt == VT_NULL || rightvt == VT_NULL)
7758                         resvt = VT_NULL;
7759                     else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
7760                         resvt = VT_DECIMAL;
7761                     else if (leftvt == VT_I8 || rightvt == VT_I8 ||
7762                         leftvt == VT_CY || rightvt == VT_CY ||
7763                         leftvt == VT_DATE || rightvt == VT_DATE ||
7764                         leftvt == VT_I4 || rightvt == VT_I4 ||
7765                         leftvt == VT_BSTR || rightvt == VT_BSTR ||
7766                         leftvt == VT_I2 || rightvt == VT_I2 ||
7767                         leftvt == VT_BOOL || rightvt == VT_BOOL ||
7768                         leftvt == VT_R8 || rightvt == VT_R8 ||
7769                         leftvt == VT_UI1 || rightvt == VT_UI1)
7770                     {
7771                         if ((leftvt == VT_UI1 && rightvt == VT_R4) ||
7772                             (leftvt == VT_R4 && rightvt == VT_UI1))
7773                             resvt = VT_R4;
7774                         else if ((leftvt == VT_R4 && (rightvt == VT_BOOL ||
7775                             rightvt == VT_I2)) || (rightvt == VT_R4 &&
7776                             (leftvt == VT_BOOL || leftvt == VT_I2)))
7777                             resvt = VT_R4;
7778                         else
7779                             resvt = VT_R8;
7780                     }
7781                     else if (leftvt == VT_R4 || rightvt == VT_R4)
7782                         resvt = VT_R4;
7783                 }
7784                 else if (leftvt == VT_NULL)
7785                     resvt = VT_NULL;
7786                 else
7787                     bFail = TRUE;
7788 
7789                 /* Native VarDiv always returns an error when using extra flags */
7790                 if (ExtraFlags[i] != 0)
7791                     bFail = TRUE;
7792 
7793                 hres = pVarDiv(&left, &right, &result);
7794 
7795                 /* Check expected HRESULT and if result variant type is correct */
7796                 if (bFail)
7797                     ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH ||
7798                         hres == DISP_E_OVERFLOW || hres == DISP_E_DIVBYZERO,
7799                         "VarDiv: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
7800                         vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
7801                         vtstr(V_VT(&result)), hres);
7802                 else
7803                     ok (hres == S_OK && resvt == V_VT(&result),
7804                         "VarDiv: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
7805                         vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
7806                         S_OK, vtstr(V_VT(&result)), hres);
7807             }
7808         }
7809     }
7810 
7811     /* Test return values for all the good cases */
7812     VARDIV(EMPTY,0,NULL,0,NULL,0);
7813     VARDIV(EMPTY,0,I2,2,R8,0.0);
7814     VARDIV(EMPTY,0,I4,2,R8,0.0);
7815     VARDIV(EMPTY,0,R4,2.0f,R4,0.0f);
7816     VARDIV(EMPTY,0,R8,2.0,R8,0.0);
7817     VARDIV(EMPTY,0,DATE,2.0,R8,0.0);
7818     VARDIV(EMPTY,0,BSTR,num2_str,R8,0.0);
7819     VARDIV(EMPTY,0,BOOL,VARIANT_TRUE,R8,0.0);
7820     VARDIV(EMPTY,0,UI1,2,R8,0.0);
7821     if (has_i8)
7822     {
7823         VARDIV(EMPTY,0,I8,2,R8,0.0);
7824     }
7825     VARDIV(NULL,0,EMPTY,0,NULL,0);
7826     VARDIV(NULL,0,NULL,0,NULL,0);
7827     VARDIV(NULL,0,I2,2,NULL,0);
7828     VARDIV(NULL,0,I4,2,NULL,0);
7829     VARDIV(NULL,0,R4,2.0f,NULL,0);
7830     VARDIV(NULL,0,R8,2.0,NULL,0);
7831     VARDIV(NULL,0,DATE,2,NULL,0);
7832     VARDIV(NULL,0,BSTR,num2_str,NULL,0);
7833     VARDIV(NULL,0,BOOL,VARIANT_TRUE,NULL,0);
7834     VARDIV(NULL,0,UI1,2,NULL,0);
7835     if (has_i8)
7836     {
7837         VARDIV(NULL,0,I8,2,NULL,0);
7838     }
7839     VARDIV(I2,2,NULL,0,NULL,0);
7840     VARDIV(I2,1,I2,2,R8,0.5);
7841     VARDIV(I2,1,I4,2,R8,0.5);
7842     VARDIV(I2,1,R4,2,R4,0.5f);
7843     VARDIV(I2,1,R8,2.0,R8,0.5);
7844     VARDIV(I2,1,DATE,2,R8,0.5);
7845     VARDIV(I2,1,BOOL,VARIANT_TRUE,R8,-1.0);
7846     VARDIV(I2,1,UI1,2,R8,0.5);
7847     if (has_i8)
7848     {
7849         VARDIV(I2,1,I8,2,R8,0.5);
7850     }
7851     VARDIV(I4,1,NULL,0,NULL,0);
7852     VARDIV(I4,1,I2,2,R8,0.5);
7853     VARDIV(I4,1,I4,2,R8,0.5);
7854     VARDIV(I4,1,R4,2.0f,R8,0.5);
7855     VARDIV(I4,1,R8,2.0,R8,0.5);
7856     VARDIV(I4,1,DATE,2,R8,0.5);
7857     VARDIV(I4,1,BSTR,num2_str,R8,0.5);
7858     VARDIV(I4,1,BOOL,VARIANT_TRUE,R8,-1.0);
7859     VARDIV(I4,1,UI1,2,R8,0.5);
7860     if (has_i8)
7861     {
7862         VARDIV(I4,1,I8,2,R8,0.5);
7863     }
7864     VARDIV(R4,1.0f,NULL,0,NULL,0);
7865     VARDIV(R4,1.0f,I2,2,R4,0.5f);
7866     VARDIV(R4,1.0f,I4,2,R8,0.5);
7867     VARDIV(R4,1.0f,R4,2.0f,R4,0.5f);
7868     VARDIV(R4,1.0f,R8,2.0,R8,0.5);
7869     VARDIV(R4,1.0f,DATE,2,R8,0.5);
7870     VARDIV(R4,1.0f,BSTR,num2_str,R8,0.5);
7871     VARDIV(R4,1.0f,BOOL,VARIANT_TRUE,R4,-1);
7872     VARDIV(R4,1.0f,UI1,2,R4,0.5f);
7873     if (has_i8)
7874     {
7875         VARDIV(R4,1.0f,I8,2,R8,0.5);
7876     }
7877     VARDIV(R8,1.0,NULL,0,NULL,0);
7878     VARDIV(R8,1.0,I2,2,R8,0.5);
7879     VARDIV(R8,1.0,I4,2,R8,0.5);
7880     VARDIV(R8,1.0,R4,2.0f,R8,0.5);
7881     VARDIV(R8,1.0,R8,2.0,R8,0.5);
7882     VARDIV(R8,1.0,DATE,2,R8,0.5);
7883     VARDIV(R8,1.0,BSTR,num2_str,R8,0.5);
7884     VARDIV(R8,1.0,BOOL,VARIANT_TRUE,R8,-1.0);
7885     VARDIV(R8,1.0,UI1,2,R8,0.5);
7886     if (has_i8)
7887     {
7888         VARDIV(R8,1.0,I8,2,R8,0.5);
7889     }
7890     VARDIV(DATE,1,NULL,0,NULL,0);
7891     VARDIV(DATE,1,I2,2,R8,0.5);
7892     VARDIV(DATE,1,I4,2,R8,0.5);
7893     VARDIV(DATE,1,R4,2.0f,R8,0.5);
7894     VARDIV(DATE,1,R8,2.0,R8,0.5);
7895     VARDIV(DATE,1,DATE,2,R8,0.5);
7896     VARDIV(DATE,1,BSTR,num2_str,R8,0.5);
7897     VARDIV(DATE,1,BOOL,VARIANT_TRUE,R8,-1.0);
7898     VARDIV(DATE,1,UI1,2,R8,0.5);
7899     if (has_i8)
7900     {
7901         VARDIV(DATE,1,I8,2,R8,0.5);
7902     }
7903     VARDIV(BSTR,num1_str,NULL,0,NULL,0);
7904     VARDIV(BSTR,num1_str,I2,2,R8,0.5);
7905     VARDIV(BSTR,num1_str,I4,2,R8,0.5);
7906     VARDIV(BSTR,num1_str,R4,2.0f,R8,0.5);
7907     VARDIV(BSTR,num1_str,R8,2.0,R8,0.5);
7908     VARDIV(BSTR,num1_str,DATE,2,R8,0.5);
7909     VARDIV(BSTR,num1_str,BSTR,num2_str,R8,0.5);
7910     VARDIV(BSTR,num1_str,BOOL,VARIANT_TRUE,R8,-1);
7911     VARDIV(BSTR,num1_str,UI1,2,R8,0.5);
7912     if (has_i8)
7913     {
7914         VARDIV(BSTR,num1_str,I8,2,R8,0.5);
7915     }
7916     VARDIV(BOOL,VARIANT_TRUE,NULL,0,NULL,0);
7917     VARDIV(BOOL,VARIANT_TRUE,I2,1,R8,-1.0);
7918     VARDIV(BOOL,VARIANT_FALSE,I2,1,R8,0.0);
7919     VARDIV(BOOL,VARIANT_TRUE,I4,1,R8,-1.0);
7920     VARDIV(BOOL,VARIANT_FALSE,I4,1,R8,0.0);
7921     VARDIV(BOOL,VARIANT_TRUE,R4,1,R4,-1.0f);
7922     VARDIV(BOOL,VARIANT_FALSE,R4,1,R4,0.0f);
7923     VARDIV(BOOL,VARIANT_TRUE,R8,1.0,R8,-1.0);
7924     VARDIV(BOOL,VARIANT_FALSE,R8,1.0,R8,0.0);
7925     VARDIV(BOOL,VARIANT_FALSE,DATE,2,R8,0.0);
7926     VARDIV(BOOL,VARIANT_FALSE,BSTR,num2_str,R8,0.0);
7927     VARDIV(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,R8,1.0);
7928     VARDIV(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,R8,0.0);
7929     VARDIV(BOOL,VARIANT_TRUE,UI1,1,R8,-1.0);
7930     if (has_i8)
7931     {
7932         VARDIV(BOOL,VARIANT_TRUE,I8,1,R8,-1.0);
7933     }
7934     VARDIV(UI1,1,NULL,0,NULL,0);
7935     VARDIV(UI1,1,I2,2,R8,0.5);
7936     VARDIV(UI1,1,I4,2,R8,0.5);
7937     VARDIV(UI1,1,R4,2.0f,R4,0.5f);
7938     VARDIV(UI1,1,R8,2.0,R8,0.5);
7939     VARDIV(UI1,1,DATE,2,R8,0.5);
7940     VARDIV(UI1,1,BSTR,num2_str,R8,0.5);
7941     VARDIV(UI1,1,BOOL,VARIANT_TRUE,R8,-1);
7942     VARDIV(UI1,1,UI1,2,R8,0.5);
7943     if (has_i8)
7944     {
7945         VARDIV(UI1,1,I8,2,R8,0.5);
7946         VARDIV(I8,1,NULL,0,NULL,0);
7947         VARDIV(I8,1,I2,2,R8,0.5);
7948         VARDIV(I8,1,I4,2,R8,0.5);
7949         VARDIV(I8,1,R4,2.0f,R8,0.5);
7950         VARDIV(I8,1,R8,2.0,R8,0.5);
7951         VARDIV(I8,1,DATE,2,R8,0.5);
7952         VARDIV(I8,1,BSTR,num2_str,R8,0.5);
7953         VARDIV(I8,1,BOOL,VARIANT_TRUE,R8,-1);
7954         VARDIV(I8,1,UI1,2,R8,0.5);
7955         VARDIV(I8,1,I8,2,R8,0.5);
7956     }
7957 
7958     /* Manually test some VT_CY, VT_DECIMAL variants */
7959     V_VT(&cy) = VT_CY;
7960     hres = VarCyFromI4(10000, &V_CY(&cy));
7961     ok(hres == S_OK, "VarCyFromI4 failed!\n");
7962     V_VT(&dec) = VT_DECIMAL;
7963     hres = VarDecFromR8(2.0, &V_DECIMAL(&dec));
7964     ok(hres == S_OK, "VarDecFromR4 failed!\n");
7965     memset(&left, 0, sizeof(left));
7966     memset(&right, 0, sizeof(right));
7967     V_VT(&left) = VT_I4;
7968     V_I4(&left) = 100;
7969     V_VT(&right) = VT_UI1;
7970     V_UI1(&right) = 2;
7971 
7972     hres = pVarDiv(&cy, &cy, &result);
7973     ok(hres == S_OK && V_VT(&result) == VT_R8,
7974         "VARDIV: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
7975     ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 1.0),
7976         "VARDIV: CY value %f, expected %f\n", V_R8(&result), (double)1.0);
7977 
7978     hres = pVarDiv(&cy, &right, &result);
7979     ok(hres == S_OK && V_VT(&result) == VT_R8,
7980         "VARDIV: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
7981     ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 5000.0),
7982         "VARDIV: CY value %f, expected %f\n", V_R8(&result), (double)5000.0);
7983 
7984     hres = pVarDiv(&left, &cy, &result);
7985     ok(hres == S_OK && V_VT(&result) == VT_R8,
7986         "VARDIV: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
7987     ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 0.01),
7988         "VARDIV: CY value %f, expected %f\n", V_R8(&result), (double)0.01);
7989 
7990     hres = pVarDiv(&left, &dec, &result);
7991     ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
7992         "VARDIV: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
7993     hres = VarR8FromDec(&V_DECIMAL(&result), &r);
7994     ok(hres == S_OK && EQ_DOUBLE(r, 50.0),
7995         "VARDIV: DECIMAL value %f, expected %f\n", r, (double)50.0);
7996 
7997     hres = pVarDiv(&dec, &dec, &result);
7998     ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
7999         "VARDIV: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
8000     hres = VarR8FromDec(&V_DECIMAL(&result), &r);
8001     ok(hres == S_OK && EQ_DOUBLE(r, 1.0),
8002         "VARDIV: DECIMAL value %f, expected %f\n", r, (double)1.0);
8003 
8004     hres = pVarDiv(&dec, &right, &result);
8005     ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
8006         "VARDIV: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
8007     hres = VarR8FromDec(&V_DECIMAL(&result), &r);
8008     ok(hres == S_OK && EQ_DOUBLE(r, 1.0),
8009         "VARDIV: DECIMAL value %f, expected %f\n", r, (double)1.0);
8010 
8011     /* Check for division by zero and overflow */
8012     V_VT(&left) = VT_R8;
8013     V_I4(&left) = 1;
8014     V_VT(&right) = VT_R8;
8015     V_I4(&right) = 0;
8016     hres = pVarDiv(&left, &right, &result);
8017     ok(hres == DISP_E_DIVBYZERO && V_VT(&result) == VT_EMPTY,
8018         "VARDIV: Division by (1.0/0.0) should result in DISP_E_DIVBYZERO but got 0x%X\n", hres);
8019 
8020     V_VT(&left) = VT_R8;
8021     V_I4(&left) = 0;
8022     V_VT(&right) = VT_R8;
8023     V_I4(&right) = 0;
8024     hres = pVarDiv(&left, &right, &result);
8025     ok(hres == DISP_E_OVERFLOW && V_VT(&result) == VT_EMPTY,
8026         "VARDIV: Division by (0.0/0.0) should result in DISP_E_OVERFLOW but got 0x%X\n", hres);
8027 
8028     SysFreeString(num1_str);
8029     SysFreeString(num2_str);
8030 }
8031 
8032 static HRESULT (WINAPI *pVarIdiv)(LPVARIANT,LPVARIANT,LPVARIANT);
8033 
8034 #define VARIDIV(vt1,val1,vt2,val2,rvt,rval)              \
8035         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
8036         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
8037         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
8038         test_var_call2( __LINE__, pVarIdiv, &left, &right, &exp )
8039 
8040 /* Skip any type that is not defined or produces an error for every case */
8041 #define SKIPTESTIDIV(a)                           \
8042     if (a == VT_ERROR || a == VT_VARIANT ||       \
8043         a == VT_DISPATCH || a == VT_UNKNOWN ||    \
8044         a == VT_RECORD || a > VT_UINT ||          \
8045         a == 15 /*not defined*/)                  \
8046         continue
8047 
8048 static void test_VarIdiv(void)
8049 {
8050     static const WCHAR str1[] = { '1','\0' };
8051     static const WCHAR str2[] = { '2','\0' };
8052     VARIANT left, right, exp, result, cy, dec;
8053     BSTR num1_str, num2_str;
8054     VARTYPE i;
8055     HRESULT hres;
8056 
8057     CHECKPTR(VarIdiv);
8058 
8059     num1_str = SysAllocString(str1);
8060     num2_str = SysAllocString(str2);
8061 
8062     /* Test all possible flag/vt combinations & the resulting vt type */
8063     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
8064     {
8065         VARTYPE leftvt, rightvt, resvt;
8066 
8067         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
8068         {
8069             SKIPTESTIDIV(leftvt);
8070 
8071             /* Check if we need/have support for I8 and/or UI8 */
8072             if ((leftvt == VT_I8 || leftvt == VT_UI8) && !has_i8)
8073                 continue;
8074 
8075             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
8076             {
8077                 BOOL bFail = FALSE;
8078                 SKIPTESTIDIV(rightvt);
8079 
8080                 /* Native crashes with extra flag VT_BYREF */
8081                 if (ExtraFlags[i] == VT_BYREF)
8082                     continue;
8083 
8084                 /* Check if we need/have support for I8 and/or UI8 */
8085                 if ((rightvt == VT_I8 || rightvt == VT_UI8) && !has_i8)
8086                     continue;
8087 
8088                 memset(&left, 0, sizeof(left));
8089                 memset(&right, 0, sizeof(right));
8090                 V_VT(&left) = leftvt | ExtraFlags[i];
8091                 V_VT(&right) = rightvt | ExtraFlags[i];
8092                 V_VT(&result) = VT_EMPTY;
8093                 resvt = VT_EMPTY;
8094 
8095                 if (leftvt == VT_BSTR)
8096                     V_BSTR(&left) = num2_str;
8097                 else if (leftvt == VT_DECIMAL)
8098                 {
8099                     VarDecFromR8(2.0, &V_DECIMAL(&left));
8100                     V_VT(&left) = leftvt | ExtraFlags[i];
8101                 }
8102 
8103                 /* Division by 0 is undefined */
8104                 switch(rightvt)
8105                 {
8106                 case VT_BSTR:
8107                     V_BSTR(&right) = num2_str;
8108                     break;
8109                 case VT_DECIMAL:
8110                     VarDecFromR8(2.0, &V_DECIMAL(&right));
8111                     V_VT(&right) = rightvt | ExtraFlags[i];
8112                     break;
8113                 case VT_BOOL:
8114                     V_BOOL(&right) = VARIANT_TRUE;
8115                     break;
8116                 case VT_CY:
8117                     VarCyFromI4(10000, &V_CY(&right));
8118                     V_VT(&right) = rightvt | ExtraFlags[i];
8119                     break;
8120                 case VT_I2: V_I2(&right) = 2; break;
8121                 case VT_I4: V_I4(&right) = 2; break;
8122                 case VT_R4: V_R4(&right) = 2.0f; break;
8123                 case VT_R8: V_R8(&right) = 2.0; break;
8124                 case VT_DATE: V_DATE(&right) = 2; break;
8125                 case VT_I1: V_I1(&right) = 2; break;
8126                 case VT_UI1: V_UI1(&right) = 2; break;
8127                 case VT_UI2: V_UI2(&right) = 2; break;
8128                 case VT_UI4: V_UI4(&right) = 2; break;
8129                 case VT_I8: V_I8(&right) = 2; break;
8130                 case VT_UI8: V_UI8(&right) = 2; break;
8131                 case VT_INT: V_INT(&right) = 2; break;
8132                 case VT_UINT: V_UINT(&right) = 2; break;
8133                 default: break;
8134                 }
8135 
8136                 /* Native VarIdiv always returns an error when using extra
8137                  * flags or if the variant combination is I8 and INT.
8138                  */
8139                 if ((leftvt == VT_I8 && rightvt == VT_INT) ||
8140                     (leftvt == VT_INT && rightvt == VT_I8) ||
8141                     (rightvt == VT_EMPTY && leftvt != VT_NULL) ||
8142                     ExtraFlags[i] != 0)
8143                     bFail = TRUE;
8144 
8145                 /* Determine variant type */
8146                 else if (leftvt == VT_NULL || rightvt == VT_NULL)
8147                     resvt = VT_NULL;
8148                 else if (leftvt == VT_I8 || rightvt == VT_I8)
8149                     resvt = VT_I8;
8150                 else if (leftvt == VT_I4 || rightvt == VT_I4 ||
8151                     leftvt == VT_INT || rightvt == VT_INT ||
8152                     leftvt == VT_UINT || rightvt == VT_UINT ||
8153                     leftvt == VT_UI8 || rightvt == VT_UI8 ||
8154                     leftvt == VT_UI4 || rightvt == VT_UI4 ||
8155                     leftvt == VT_UI2 || rightvt == VT_UI2 ||
8156                     leftvt == VT_I1 || rightvt == VT_I1 ||
8157                     leftvt == VT_BSTR || rightvt == VT_BSTR ||
8158                     leftvt == VT_DATE || rightvt == VT_DATE ||
8159                     leftvt == VT_CY || rightvt == VT_CY ||
8160                     leftvt == VT_DECIMAL || rightvt == VT_DECIMAL ||
8161                     leftvt == VT_R8 || rightvt == VT_R8 ||
8162                     leftvt == VT_R4 || rightvt == VT_R4)
8163                     resvt = VT_I4;
8164                 else if (leftvt == VT_I2 || rightvt == VT_I2 ||
8165                     leftvt == VT_BOOL || rightvt == VT_BOOL ||
8166                     leftvt == VT_EMPTY)
8167                     resvt = VT_I2;
8168                 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
8169                     resvt = VT_UI1;
8170                 else
8171                     bFail = TRUE;
8172 
8173                 hres = pVarIdiv(&left, &right, &result);
8174 
8175                 /* Check expected HRESULT and if result variant type is correct */
8176                 if (bFail)
8177                     ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH ||
8178                         hres == DISP_E_DIVBYZERO,
8179                         "VarIdiv: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
8180                         vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
8181                         vtstr(V_VT(&result)), hres);
8182                 else
8183                     ok (hres == S_OK && resvt == V_VT(&result),
8184                         "VarIdiv: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
8185                         vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
8186                         S_OK, vtstr(V_VT(&result)), hres);
8187             }
8188         }
8189     }
8190 
8191     /* Test return values for all the good cases */
8192     VARIDIV(EMPTY,0,NULL,0,NULL,0);
8193     VARIDIV(EMPTY,0,I2,1,I2,0);
8194     VARIDIV(EMPTY,0,I4,1,I4,0);
8195     VARIDIV(EMPTY,0,R4,1.0f,I4,0);
8196     VARIDIV(EMPTY,0,R8,1.0,I4,0);
8197     VARIDIV(EMPTY,0,DATE,1.0,I4,0);
8198     VARIDIV(EMPTY,0,BSTR,num1_str,I4,0);
8199     VARIDIV(EMPTY,0,BOOL,VARIANT_TRUE,I2,0);
8200     VARIDIV(EMPTY,0,I1,1,I4,0);
8201     VARIDIV(EMPTY,0,UI1,1,I2,0);
8202     VARIDIV(EMPTY,0,UI2,1,I4,0);
8203     VARIDIV(EMPTY,0,UI4,1,I4,0);
8204     if (has_i8)
8205     {
8206         VARIDIV(EMPTY,0,I8,1,I8,0);
8207         VARIDIV(EMPTY,0,UI8,1,I4,0);
8208     }
8209     VARIDIV(EMPTY,0,INT,1,I4,0);
8210     VARIDIV(EMPTY,0,UINT,1,I4,0);
8211     VARIDIV(NULL,0,EMPTY,0,NULL,0);
8212     VARIDIV(NULL,0,NULL,0,NULL,0);
8213     VARIDIV(NULL,0,I2,1,NULL,0);
8214     VARIDIV(NULL,0,I4,1,NULL,0);
8215     VARIDIV(NULL,0,R4,1,NULL,0);
8216     VARIDIV(NULL,0,R8,1,NULL,0);
8217     VARIDIV(NULL,0,DATE,1,NULL,0);
8218     VARIDIV(NULL,0,BSTR,num1_str,NULL,0);
8219     VARIDIV(NULL,0,BOOL,VARIANT_TRUE,NULL,0);
8220     VARIDIV(NULL,0,I1,1,NULL,0);
8221     VARIDIV(NULL,0,UI1,1,NULL,0);
8222     VARIDIV(NULL,0,UI2,1,NULL,0);
8223     VARIDIV(NULL,0,UI4,1,NULL,0);
8224     if (has_i8)
8225     {
8226         VARIDIV(NULL,0,I8,1,NULL,0);
8227         VARIDIV(NULL,0,UI8,1,NULL,0);
8228     }
8229     VARIDIV(NULL,0,INT,1,NULL,0);
8230     VARIDIV(NULL,0,UINT,1,NULL,0);
8231     VARIDIV(I2,2,NULL,0,NULL,0);
8232     VARIDIV(I2,2,I2,1,I2,2);
8233     VARIDIV(I2,2,I4,1,I4,2);
8234     VARIDIV(I2,2,R4,1,I4,2);
8235     VARIDIV(I2,2,R8,1,I4,2);
8236     VARIDIV(I2,2,DATE,1,I4,2);
8237     VARIDIV(I2,2,BSTR,num1_str,I4,2);
8238     VARIDIV(I2,2,BOOL,VARIANT_TRUE,I2,-2);
8239     VARIDIV(I2,2,I1,1,I4,2);
8240     VARIDIV(I2,2,UI1,1,I2,2);
8241     VARIDIV(I2,2,UI2,1,I4,2);
8242     VARIDIV(I2,2,UI4,1,I4,2);
8243     if (has_i8)
8244     {
8245         VARIDIV(I2,2,I8,1,I8,2);
8246         VARIDIV(I2,2,UI8,1,I4,2);
8247     }
8248     VARIDIV(I2,2,INT,1,I4,2);
8249     VARIDIV(I2,2,UINT,1,I4,2);
8250     VARIDIV(I4,2,NULL,0,NULL,0);
8251     VARIDIV(I4,2,I2,1,I4,2);
8252     VARIDIV(I4,2,I4,1,I4,2);
8253     VARIDIV(I4,2,R4,1,I4,2);
8254     VARIDIV(I4,2,R8,1,I4,2);
8255     VARIDIV(I4,2,DATE,1,I4,2);
8256     VARIDIV(I4,2,BSTR,num1_str,I4,2);
8257     VARIDIV(I4,2,BOOL,VARIANT_TRUE,I4,-2);
8258     VARIDIV(I4,2,I1,1,I4,2);
8259     VARIDIV(I4,2,UI1,1,I4,2);
8260     VARIDIV(I4,2,UI2,1,I4,2);
8261     VARIDIV(I4,2,UI4,1,I4,2);
8262     if (has_i8)
8263     {
8264         VARIDIV(I4,2,I8,1,I8,2);
8265         VARIDIV(I4,2,UI8,1,I4,2);
8266     }
8267     VARIDIV(I4,2,INT,1,I4,2);
8268     VARIDIV(I4,2,UINT,1,I4,2);
8269     VARIDIV(R4,2.0f,NULL,0,NULL,0);
8270     VARIDIV(R4,2.0f,I2,1,I4,2);
8271     VARIDIV(R4,2.0f,I4,1,I4,2);
8272     VARIDIV(R4,2.0f,R4,1.0f,I4,2);
8273     VARIDIV(R4,2.0f,R8,1.0,I4,2);
8274     VARIDIV(R4,2.0f,DATE,1,I4,2);
8275     VARIDIV(R4,2.0f,BSTR,num1_str,I4,2);
8276     VARIDIV(R4,2.0f,BOOL,VARIANT_TRUE,I4,-2);
8277     VARIDIV(R4,2.0f,I1,1,I4,2);
8278     VARIDIV(R4,2.0f,UI1,1,I4,2);
8279     VARIDIV(R4,2.0f,UI2,1,I4,2);
8280     VARIDIV(R4,2.0f,UI4,1,I4,2);
8281     if (has_i8)
8282     {
8283         VARIDIV(R4,2.0f,I8,1,I8,2);
8284         VARIDIV(R4,2.0f,UI8,1,I4,2);
8285     }
8286     VARIDIV(R4,2.0f,INT,1,I4,2);
8287     VARIDIV(R4,2.0f,UINT,1,I4,2);
8288     VARIDIV(R8,2.0,NULL,0,NULL,0);
8289     VARIDIV(R8,2.0,I2,1,I4,2);
8290     VARIDIV(R8,2.0,I4,1,I4,2);
8291     VARIDIV(R8,2.0,R4,1,I4,2);
8292     VARIDIV(R8,2.0,R8,1,I4,2);
8293     VARIDIV(R8,2.0,DATE,1,I4,2);
8294     VARIDIV(R8,2.0,BSTR,num1_str,I4,2);
8295     VARIDIV(R8,2.0,BOOL,VARIANT_TRUE,I4,-2);
8296     VARIDIV(R8,2.0,I1,1,I4,2);
8297     VARIDIV(R8,2.0,UI1,1,I4,2);
8298     VARIDIV(R8,2.0,UI2,1,I4,2);
8299     VARIDIV(R8,2.0,UI4,1,I4,2);
8300     if (has_i8)
8301     {
8302         VARIDIV(R8,2.0,I8,1,I8,2);
8303         VARIDIV(R8,2.0,UI8,1,I4,2);
8304     }
8305     VARIDIV(R8,2.0,INT,1,I4,2);
8306     VARIDIV(R8,2.0,UINT,1,I4,2);
8307     VARIDIV(DATE,2,NULL,0,NULL,0);
8308     VARIDIV(DATE,2,I2,1,I4,2);
8309     VARIDIV(DATE,2,I4,1,I4,2);
8310     VARIDIV(DATE,2,R4,1,I4,2);
8311     VARIDIV(DATE,2,R8,1,I4,2);
8312     VARIDIV(DATE,2,DATE,1,I4,2);
8313     VARIDIV(DATE,2,BSTR,num1_str,I4,2);
8314     VARIDIV(DATE,2,BOOL,VARIANT_TRUE,I4,-2);
8315     VARIDIV(DATE,2,I1,1,I4,2);
8316     VARIDIV(DATE,2,UI1,1,I4,2);
8317     VARIDIV(DATE,2,UI2,1,I4,2);
8318     VARIDIV(DATE,2,UI4,1,I4,2);
8319     if (has_i8)
8320     {
8321         VARIDIV(DATE,2,I8,1,I8,2);
8322         VARIDIV(DATE,2,UI8,1,I4,2);
8323     }
8324     VARIDIV(DATE,2,INT,1,I4,2);
8325     VARIDIV(DATE,2,UINT,1,I4,2);
8326     VARIDIV(BSTR,num2_str,NULL,0,NULL,0);
8327     VARIDIV(BSTR,num2_str,I2,1,I4,2);
8328     VARIDIV(BSTR,num2_str,I4,1,I4,2);
8329     VARIDIV(BSTR,num2_str,R4,1.0f,I4,2);
8330     VARIDIV(BSTR,num2_str,R8,1.0,I4,2);
8331     VARIDIV(BSTR,num2_str,DATE,1,I4,2);
8332     VARIDIV(BSTR,num2_str,BSTR,num1_str,I4,2);
8333     VARIDIV(BSTR,num2_str,BOOL,VARIANT_TRUE,I4,-2);
8334     VARIDIV(BSTR,num2_str,I1,1,I4,2);
8335     VARIDIV(BSTR,num2_str,UI1,1,I4,2);
8336     VARIDIV(BSTR,num2_str,UI2,1,I4,2);
8337     VARIDIV(BSTR,num2_str,UI4,1,I4,2);
8338     if (has_i8)
8339     {
8340         VARIDIV(BSTR,num2_str,I8,1,I8,2);
8341         VARIDIV(BSTR,num2_str,UI8,1,I4,2);
8342     }
8343     VARIDIV(BSTR,num2_str,INT,1,I4,2);
8344     VARIDIV(BSTR,num2_str,UINT,1,I4,2);
8345     VARIDIV(BOOL,VARIANT_TRUE,NULL,0,NULL,0);
8346     VARIDIV(BOOL,VARIANT_TRUE,I2,1,I2,-1);
8347     VARIDIV(BOOL,VARIANT_TRUE,I4,1,I4,-1);
8348     VARIDIV(BOOL,VARIANT_TRUE,R4,1.0f,I4,-1);
8349     VARIDIV(BOOL,VARIANT_TRUE,R8,1.0,I4,-1);
8350     VARIDIV(BOOL,VARIANT_TRUE,DATE,1,I4,-1);
8351     VARIDIV(BOOL,VARIANT_TRUE,BSTR,num1_str,I4,-1);
8352     VARIDIV(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,I2,1);
8353     VARIDIV(BOOL,VARIANT_TRUE,I1,1,I4,-1);
8354     VARIDIV(BOOL,VARIANT_TRUE,UI1,1,I2,-1);
8355     VARIDIV(BOOL,VARIANT_TRUE,UI2,1,I4,-1);
8356     VARIDIV(BOOL,VARIANT_TRUE,UI4,1,I4,-1);
8357     if (has_i8)
8358     {
8359         VARIDIV(BOOL,VARIANT_TRUE,I8,1,I8,-1);
8360         VARIDIV(BOOL,VARIANT_TRUE,UI8,1,I4,-1);
8361     }
8362     VARIDIV(BOOL,VARIANT_TRUE,INT,1,I4,-1);
8363     VARIDIV(BOOL,VARIANT_TRUE,UINT,1,I4,-1);
8364     VARIDIV(I1,2,NULL,0,NULL,0);
8365     VARIDIV(I1,2,I2,1,I4,2);
8366     VARIDIV(I1,2,I4,1,I4,2);
8367     VARIDIV(I1,2,R4,1.0f,I4,2);
8368     VARIDIV(I1,2,R8,1.0,I4,2);
8369     VARIDIV(I1,2,DATE,1,I4,2);
8370     VARIDIV(I1,2,BSTR,num1_str,I4,2);
8371     VARIDIV(I1,2,BOOL,VARIANT_TRUE,I4,-2);
8372     VARIDIV(I1,2,I1,1,I4,2);
8373     VARIDIV(I1,2,UI1,1,I4,2);
8374     VARIDIV(I1,2,UI2,1,I4,2);
8375     VARIDIV(I1,2,UI4,1,I4,2);
8376     if (has_i8)
8377     {
8378         VARIDIV(I1,2,I8,1,I8,2);
8379         VARIDIV(I1,2,UI8,1,I4,2);
8380     }
8381     VARIDIV(I1,2,INT,1,I4,2);
8382     VARIDIV(I1,2,UINT,1,I4,2);
8383     VARIDIV(UI1,2,NULL,0,NULL,0);
8384     VARIDIV(UI1,2,I2,1,I2,2);
8385     VARIDIV(UI1,2,I4,1,I4,2);
8386     VARIDIV(UI1,2,R4,1.0f,I4,2);
8387     VARIDIV(UI1,2,R8,1.0,I4,2);
8388     VARIDIV(UI1,2,DATE,1,I4,2);
8389     VARIDIV(UI1,2,BSTR,num1_str,I4,2);
8390     VARIDIV(UI1,2,BOOL,VARIANT_TRUE,I2,-2);
8391     VARIDIV(UI1,2,I1,1,I4,2);
8392     VARIDIV(UI1,2,UI1,1,UI1,2);
8393     VARIDIV(UI1,2,UI2,1,I4,2);
8394     VARIDIV(UI1,2,UI4,1,I4,2);
8395     if (has_i8)
8396     {
8397         VARIDIV(UI1,2,I8,1,I8,2);
8398         VARIDIV(UI1,2,UI8,1,I4,2);
8399     }
8400     VARIDIV(UI1,2,INT,1,I4,2);
8401     VARIDIV(UI1,2,UINT,1,I4,2);
8402     VARIDIV(UI2,2,NULL,0,NULL,0);
8403     VARIDIV(UI2,2,I2,1,I4,2);
8404     VARIDIV(UI2,2,I4,1,I4,2);
8405     VARIDIV(UI2,2,R4,1.0f,I4,2);
8406     VARIDIV(UI2,2,R8,1.0,I4,2);
8407     VARIDIV(UI2,2,DATE,1,I4,2);
8408     VARIDIV(UI2,2,BSTR,num1_str,I4,2);
8409     VARIDIV(UI2,2,BOOL,VARIANT_TRUE,I4,-2);
8410     VARIDIV(UI2,2,I1,1,I4,2);
8411     VARIDIV(UI2,2,UI1,1,I4,2);
8412     VARIDIV(UI2,2,UI2,1,I4,2);
8413     VARIDIV(UI2,2,UI4,1,I4,2);
8414     if (has_i8)
8415     {
8416         VARIDIV(UI2,2,I8,1,I8,2);
8417         VARIDIV(UI2,2,UI8,1,I4,2);
8418     }
8419     VARIDIV(UI2,2,INT,1,I4,2);
8420     VARIDIV(UI2,2,UINT,1,I4,2);
8421     VARIDIV(UI4,2,NULL,0,NULL,0);
8422     VARIDIV(UI4,2,I2,1,I4,2);
8423     VARIDIV(UI4,2,I4,1,I4,2);
8424     VARIDIV(UI4,2,R4,1.0f,I4,2);
8425     VARIDIV(UI4,2,R8,1.0,I4,2);
8426     VARIDIV(UI4,2,DATE,1,I4,2);
8427     VARIDIV(UI4,2,BSTR,num1_str,I4,2);
8428     VARIDIV(UI4,2,BOOL,VARIANT_TRUE,I4,-2);
8429     VARIDIV(UI4,2,I1,1,I4,2);
8430     VARIDIV(UI4,2,UI1,1,I4,2);
8431     VARIDIV(UI4,2,UI2,1,I4,2);
8432     VARIDIV(UI4,2,UI4,1,I4,2);
8433     if (has_i8)
8434     {
8435         VARIDIV(UI4,2,I8,1,I8,2);
8436         VARIDIV(UI4,2,UI8,1,I4,2);
8437     }
8438     VARIDIV(UI4,2,INT,1,I4,2);
8439     VARIDIV(UI4,2,UINT,1,I4,2);
8440     if (has_i8)
8441     {
8442         VARIDIV(I8,2,NULL,0,NULL,0);
8443         VARIDIV(I8,2,I2,1,I8,2);
8444         VARIDIV(I8,2,I4,1,I8,2);
8445         VARIDIV(I8,2,R4,1.0f,I8,2);
8446         VARIDIV(I8,2,R8,1.0,I8,2);
8447         VARIDIV(I8,2,DATE,1,I8,2);
8448         VARIDIV(I8,2,BSTR,num1_str,I8,2);
8449         VARIDIV(I8,2,BOOL,1,I8,2);
8450         VARIDIV(I8,2,I1,1,I8,2);
8451         VARIDIV(I8,2,UI1,1,I8,2);
8452         VARIDIV(I8,2,UI2,1,I8,2);
8453         VARIDIV(I8,2,UI4,1,I8,2);
8454         VARIDIV(I8,2,I8,1,I8,2);
8455         VARIDIV(I8,2,UI8,1,I8,2);
8456         VARIDIV(I8,2,UINT,1,I8,2);
8457         VARIDIV(UI8,2,NULL,0,NULL,0);
8458         VARIDIV(UI8,2,I2,1,I4,2);
8459         VARIDIV(UI8,2,I4,1,I4,2);
8460         VARIDIV(UI8,2,R4,1.0f,I4,2);
8461         VARIDIV(UI8,2,R8,1.0,I4,2);
8462         VARIDIV(UI8,2,DATE,1,I4,2);
8463         VARIDIV(UI8,2,BSTR,num1_str,I4,2);
8464         VARIDIV(UI8,2,BOOL,VARIANT_TRUE,I4,-2);
8465         VARIDIV(UI8,2,I1,1,I4,2);
8466         VARIDIV(UI8,2,UI1,1,I4,2);
8467         VARIDIV(UI8,2,UI2,1,I4,2);
8468         VARIDIV(UI8,2,UI4,1,I4,2);
8469         VARIDIV(UI8,2,I8,1,I8,2);
8470         VARIDIV(UI8,2,UI8,1,I4,2);
8471         VARIDIV(UI8,2,INT,1,I4,2);
8472         VARIDIV(UI8,2,UINT,1,I4,2);
8473     }
8474     VARIDIV(INT,2,NULL,0,NULL,0);
8475     VARIDIV(INT,2,I2,1,I4,2);
8476     VARIDIV(INT,2,I4,1,I4,2);
8477     VARIDIV(INT,2,R4,1.0f,I4,2);
8478     VARIDIV(INT,2,R8,1.0,I4,2);
8479     VARIDIV(INT,2,DATE,1,I4,2);
8480     VARIDIV(INT,2,BSTR,num1_str,I4,2);
8481     VARIDIV(INT,2,BOOL,VARIANT_TRUE,I4,-2);
8482     VARIDIV(INT,2,I1,1,I4,2);
8483     VARIDIV(INT,2,UI1,1,I4,2);
8484     VARIDIV(INT,2,UI2,1,I4,2);
8485     VARIDIV(INT,2,UI4,1,I4,2);
8486     if (has_i8)
8487     {
8488         VARIDIV(INT,2,UI8,1,I4,2);
8489     }
8490     VARIDIV(INT,2,INT,1,I4,2);
8491     VARIDIV(INT,2,UINT,1,I4,2);
8492     VARIDIV(UINT,2,NULL,0,NULL,0);
8493     VARIDIV(UINT,2,I2,1,I4,2);
8494     VARIDIV(UINT,2,I4,1,I4,2);
8495     VARIDIV(UINT,2,R4,1.0f,I4,2);
8496     VARIDIV(UINT,2,R8,1.0,I4,2);
8497     VARIDIV(UINT,2,DATE,1,I4,2);
8498     VARIDIV(UINT,2,BSTR,num1_str,I4,2);
8499     VARIDIV(UINT,2,BOOL,VARIANT_TRUE,I4,-2);
8500     VARIDIV(UINT,2,I1,1,I4,2);
8501     VARIDIV(UINT,2,UI1,1,I4,2);
8502     VARIDIV(UINT,2,UI2,1,I4,2);
8503     VARIDIV(UINT,2,UI4,1,I4,2);
8504     if (has_i8)
8505     {
8506         VARIDIV(UINT,2,I8,1,I8,2);
8507         VARIDIV(UINT,2,UI8,1,I4,2);
8508     }
8509     VARIDIV(UINT,2,INT,1,I4,2);
8510     VARIDIV(UINT,2,UINT,1,I4,2);
8511 
8512     /* Manually test some VT_CY, VT_DECIMAL variants */
8513     V_VT(&cy) = VT_CY;
8514     hres = VarCyFromI4(10000, &V_CY(&cy));
8515     ok(hres == S_OK, "VarCyFromI4 failed!\n");
8516     V_VT(&dec) = VT_DECIMAL;
8517     hres = VarDecFromR8(2.0, &V_DECIMAL(&dec));
8518     ok(hres == S_OK, "VarDecFromR4 failed!\n");
8519     memset(&left, 0, sizeof(left));
8520     memset(&right, 0, sizeof(right));
8521     V_VT(&left) = VT_I4;
8522     V_I4(&left) = 100;
8523     V_VT(&right) = VT_I8;
8524     V_UI1(&right) = 2;
8525 
8526     hres = pVarIdiv(&cy, &cy, &result);
8527     ok(hres == S_OK && V_VT(&result) == VT_I4,
8528         "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8529         S_OK, hres, vtstr(V_VT(&result)));
8530     ok(hres == S_OK && V_I4(&result) == 1,
8531         "VARIDIV: CY value %d, expected %d\n", V_I4(&result), 1);
8532 
8533     if (has_i8)
8534     {
8535         hres = pVarIdiv(&cy, &right, &result);
8536         ok(hres == S_OK && V_VT(&result) == VT_I8,
8537             "VARIDIV: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n",
8538             S_OK, hres, vtstr(V_VT(&result)));
8539         ok(hres == S_OK && V_I8(&result) == 5000,
8540             "VARIDIV: CY value 0x%x%08x, expected 0x%x\n",
8541 	    (DWORD)(V_I8(&result) >>32), (DWORD)V_I8(&result), 5000);
8542     }
8543 
8544     hres = pVarIdiv(&left, &cy, &result);
8545     ok(hres == S_OK && V_VT(&result) == VT_I4,
8546         "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8547         S_OK, hres, vtstr(V_VT(&result)));
8548     ok(hres == S_OK && V_I4(&result) == 0,
8549         "VARIDIV: CY value %d, expected %d\n", V_I4(&result), 0);
8550 
8551     hres = pVarIdiv(&left, &dec, &result);
8552     ok(hres == S_OK && V_VT(&result) == VT_I4,
8553         "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8554         S_OK, hres, vtstr(V_VT(&result)));
8555     ok(hres == S_OK && V_I4(&result) == 50,
8556         "VARIDIV: DECIMAL value %d, expected %d\n", V_I4(&result), 50);
8557 
8558     hres = pVarIdiv(&dec, &dec, &result);
8559     ok(hres == S_OK && V_VT(&result) == VT_I4,
8560         "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8561         S_OK, hres, vtstr(V_VT(&result)));
8562     ok(hres == S_OK && V_I4(&result) == 1,
8563         "VARIDIV: DECIMAL value %d, expected %d\n", V_I4(&result), 1);
8564 
8565     if (has_i8)
8566     {
8567         hres = pVarIdiv(&dec, &right, &result);
8568         ok(hres == S_OK && V_VT(&result) == VT_I8,
8569             "VARIDIV: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n",
8570             S_OK, hres, vtstr(V_VT(&result)));
8571         ok(hres == S_OK && V_I8(&result) == 1,
8572             "VARIDIV: DECIMAL value 0x%x%08x, expected %d\n",
8573 	    (DWORD)(V_I8(&result) >> 32), (DWORD)V_I8(&result), 1);
8574     }
8575 
8576     /* Check for division by zero */
8577     V_VT(&left) = VT_INT;
8578     V_I4(&left) = 1;
8579     V_VT(&right) = VT_INT;
8580     V_I4(&right) = 0;
8581     hres = pVarIdiv(&left, &right, &result);
8582     ok(hres == DISP_E_DIVBYZERO && V_VT(&result) == VT_EMPTY,
8583         "VARIDIV: Division by 0 should result in DISP_E_DIVBYZERO but got 0x%X\n", hres);
8584 
8585     V_VT(&left) = VT_INT;
8586     V_I4(&left) = 0;
8587     V_VT(&right) = VT_INT;
8588     V_I4(&right) = 0;
8589     hres = pVarIdiv(&left, &right, &result);
8590     ok(hres == DISP_E_DIVBYZERO && V_VT(&result) == VT_EMPTY,
8591         "VARIDIV: Division by 0 should result in DISP_E_DIVBYZERO but got 0x%X\n", hres);
8592 
8593     SysFreeString(num1_str);
8594     SysFreeString(num2_str);
8595 }
8596 
8597 
8598 static HRESULT (WINAPI *pVarImp)(LPVARIANT,LPVARIANT,LPVARIANT);
8599 
8600 #define VARIMP(vt1,val1,vt2,val2,rvt,rval)              \
8601         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
8602         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
8603         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
8604         test_var_call2( __LINE__, pVarImp, &left, &right, &exp )
8605 
8606 /* Skip any type that is not defined or produces an error for every case */
8607 #define SKIPTESTIMP(a)                            \
8608     if (a == VT_ERROR || a == VT_VARIANT ||       \
8609         a == VT_DISPATCH || a == VT_UNKNOWN ||    \
8610         a == VT_RECORD || a > VT_UINT ||          \
8611         a == 15 /*not defined*/)                  \
8612         continue
8613 
8614 static void test_VarImp(void)
8615 {
8616     static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
8617     static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
8618     VARIANT left, right, exp, result, cy, dec;
8619     BSTR true_str, false_str;
8620     VARTYPE i;
8621     HRESULT hres;
8622 
8623     CHECKPTR(VarImp);
8624 
8625     true_str = SysAllocString(szTrue);
8626     false_str = SysAllocString(szFalse);
8627 
8628     /* Test all possible flag/vt combinations & the resulting vt type */
8629     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
8630     {
8631         VARTYPE leftvt, rightvt, resvt;
8632 
8633         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
8634         {
8635             SKIPTESTIMP(leftvt);
8636 
8637             /* Check if we need/have support for I8 and/or UI8 */
8638             if ((leftvt == VT_I8 || leftvt == VT_UI8) && !has_i8)
8639                 continue;
8640 
8641             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
8642             {
8643                 BOOL bFail = FALSE;
8644                 SKIPTESTIMP(rightvt);
8645 
8646                 /* Native crashes when using the extra flag VT_BYREF
8647                  * or with the following VT combinations
8648                  */
8649                 if ((leftvt == VT_UI4 && rightvt == VT_BSTR) ||
8650                     (leftvt == VT_UI8 && rightvt == VT_BSTR) ||
8651                     ExtraFlags[i] == VT_BYREF)
8652                     continue;
8653 
8654                 /* Check if we need/have support for I8 and/or UI8 */
8655                 if ((rightvt == VT_I8 || rightvt == VT_UI8) && !has_i8)
8656                     continue;
8657 
8658                 memset(&left, 0, sizeof(left));
8659                 memset(&right, 0, sizeof(right));
8660                 V_VT(&left) = leftvt | ExtraFlags[i];
8661                 V_VT(&right) = rightvt | ExtraFlags[i];
8662                 V_VT(&result) = VT_EMPTY;
8663                 resvt = VT_EMPTY;
8664 
8665                 if (leftvt == VT_BSTR)
8666                     V_BSTR(&left) = true_str;
8667 
8668                 /* This allows us to test return types that are not NULL
8669                  * (NULL Imp value = n, NULL Imp 0 = NULL)
8670                  */
8671                 switch(rightvt)
8672                 {
8673                 case VT_BSTR:
8674                     V_BSTR(&right) = true_str;
8675                     break;
8676                 case VT_DECIMAL:
8677                     VarDecFromR8(2.0, &V_DECIMAL(&right));
8678                     V_VT(&right) = rightvt | ExtraFlags[i];
8679                     break;
8680                 case VT_BOOL:
8681                     V_BOOL(&right) = VARIANT_TRUE;
8682                     break;
8683                 case VT_I1: V_I1(&right) = 2; break;
8684                 case VT_I2: V_I2(&right) = 2; break;
8685                 case VT_I4: V_I4(&right) = 2; break;
8686                 case VT_R4: V_R4(&right) = 2.0f; break;
8687                 case VT_R8: V_R8(&right) = 2.0; break;
8688                 case VT_CY: V_CY(&right).int64 = 10000; break;
8689                 case VT_DATE: V_DATE(&right) = 2; break;
8690                 case VT_I8: V_I8(&right) = 2; break;
8691                 case VT_INT: V_INT(&right) = 2; break;
8692                 case VT_UINT: V_UINT(&right) = 2; break;
8693                 case VT_UI1: V_UI1(&right) = 2; break;
8694                 case VT_UI2: V_UI2(&right) = 2; break;
8695                 case VT_UI4: V_UI4(&right) = 2; break;
8696                 case VT_UI8: V_UI8(&right) = 2; break;
8697                 default: break;
8698                 }
8699 
8700                 /* Native VarImp always returns an error when using extra
8701                  * flags or if the variants are I8 and INT.
8702                  */
8703                 if ((leftvt == VT_I8 && rightvt == VT_INT) ||
8704                     ExtraFlags[i] != 0)
8705                     bFail = TRUE;
8706 
8707                 /* Determine result type */
8708                 else if ((leftvt == VT_BSTR && rightvt == VT_NULL) ||
8709                     (leftvt == VT_NULL && rightvt == VT_NULL) ||
8710                     (leftvt == VT_NULL && rightvt == VT_EMPTY))
8711                     resvt = VT_NULL;
8712                 else if (leftvt == VT_I8 || rightvt == VT_I8)
8713                     resvt = VT_I8;
8714                 else if (leftvt == VT_I4 || rightvt == VT_I4 ||
8715                     leftvt == VT_INT || rightvt == VT_INT ||
8716                     leftvt == VT_UINT || rightvt == VT_UINT ||
8717                     leftvt == VT_UI4 || rightvt == VT_UI4 ||
8718                     leftvt == VT_UI8 || rightvt == VT_UI8 ||
8719                     leftvt == VT_UI2 || rightvt == VT_UI2 ||
8720                     leftvt == VT_DECIMAL || rightvt == VT_DECIMAL ||
8721                     leftvt == VT_DATE || rightvt == VT_DATE ||
8722                     leftvt == VT_CY || rightvt == VT_CY ||
8723                     leftvt == VT_R8 || rightvt == VT_R8 ||
8724                     leftvt == VT_R4 || rightvt == VT_R4 ||
8725                     leftvt == VT_I1 || rightvt == VT_I1)
8726                     resvt = VT_I4;
8727                 else if ((leftvt == VT_UI1 && rightvt == VT_UI1) ||
8728                     (leftvt == VT_UI1 && rightvt == VT_NULL) ||
8729                     (leftvt == VT_NULL && rightvt == VT_UI1))
8730                     resvt = VT_UI1;
8731                 else if (leftvt == VT_EMPTY || rightvt == VT_EMPTY ||
8732                     leftvt == VT_I2 || rightvt == VT_I2 ||
8733                     leftvt == VT_UI1 || rightvt == VT_UI1)
8734                     resvt = VT_I2;
8735                 else if (leftvt == VT_BOOL || rightvt == VT_BOOL ||
8736                     leftvt == VT_BSTR || rightvt == VT_BSTR)
8737                     resvt = VT_BOOL;
8738 
8739                 hres = pVarImp(&left, &right, &result);
8740 
8741                 /* Check expected HRESULT and if result variant type is correct */
8742                 if (bFail)
8743                     ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH,
8744                         "VarImp: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
8745                         vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
8746                         vtstr(V_VT(&result)), hres);
8747                 else
8748                     ok (hres == S_OK && resvt == V_VT(&result),
8749                         "VarImp: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
8750                         vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
8751                         S_OK, vtstr(V_VT(&result)), hres);
8752             }
8753         }
8754     }
8755 
8756     VARIMP(EMPTY,0,EMPTY,0,I2,-1);
8757     VARIMP(EMPTY,0,NULL,0,I2,-1);
8758     VARIMP(EMPTY,0,I2,-1,I2,-1);
8759     VARIMP(EMPTY,0,I4,-1,I4,-1);
8760     VARIMP(EMPTY,0,R4,0.0f,I4,-1);
8761     VARIMP(EMPTY,0,R8,-1.0,I4,-1);
8762     VARIMP(EMPTY,0,DATE,0,I4,-1);
8763     VARIMP(EMPTY,0,BSTR,true_str,I2,-1);
8764     VARIMP(EMPTY,0,BOOL,VARIANT_FALSE,I2,-1);
8765     VARIMP(EMPTY,0,I1,0,I4,-1);
8766     VARIMP(EMPTY,0,UI1,1,I2,-1);
8767     VARIMP(EMPTY,0,UI2,1,I4,-1);
8768     VARIMP(EMPTY,0,UI4,1,I4,-1);
8769     if (has_i8)
8770     {
8771         VARIMP(EMPTY,0,I8,1,I8,-1);
8772         VARIMP(EMPTY,0,UI8,1,I4,-1);
8773     }
8774     VARIMP(EMPTY,0,INT,-1,I4,-1);
8775     VARIMP(EMPTY,0,UINT,1,I4,-1);
8776     VARIMP(NULL,0,EMPTY,0,NULL,0);
8777     VARIMP(NULL,0,NULL,0,NULL,0);
8778     VARIMP(NULL,0,I2,-1,I2,-1);
8779     VARIMP(NULL,0,I4,-1,I4,-1);
8780     VARIMP(NULL,0,R4,0.0f,NULL,0);
8781     VARIMP(NULL,0,R8,-1.0,I4,-1);
8782     VARIMP(NULL,0,DATE,0,NULL,0);
8783     VARIMP(NULL,0,BSTR,true_str,BOOL,-1);
8784     VARIMP(NULL,0,BOOL,VARIANT_FALSE,NULL,0);
8785     VARIMP(NULL,0,I1,0,NULL,0);
8786     VARIMP(NULL,0,UI1,1,UI1,1);
8787     VARIMP(NULL,0,UI2,1,I4,1);
8788     VARIMP(NULL,0,UI4,1,I4,1);
8789     if (has_i8)
8790     {
8791         VARIMP(NULL,0,I8,1,I8,1);
8792         VARIMP(NULL,0,UI8,1,I4,1);
8793     }
8794     VARIMP(NULL,0,INT,-1,I4,-1);
8795     VARIMP(NULL,0,UINT,1,I4,1);
8796     VARIMP(I2,-1,EMPTY,0,I2,0);
8797     VARIMP(I2,-1,I2,-1,I2,-1);
8798     VARIMP(I2,-1,I4,-1,I4,-1);
8799     VARIMP(I2,-1,R4,0.0f,I4,0);
8800     VARIMP(I2,-1,R8,-1.0,I4,-1);
8801     VARIMP(I2,-1,DATE,0,I4,0);
8802     VARIMP(I2,-1,BSTR,true_str,I2,-1);
8803     VARIMP(I2,-1,BOOL,VARIANT_FALSE,I2,0);
8804     VARIMP(I2,-1,I1,0,I4,0);
8805     VARIMP(I2,-1,UI1,1,I2,1);
8806     VARIMP(I2,-1,UI2,1,I4,1);
8807     VARIMP(I2,-1,UI4,1,I4,1);
8808     if (has_i8)
8809     {
8810         VARIMP(I2,-1,I8,1,I8,1);
8811         VARIMP(I2,-1,UI8,1,I4,1);
8812     }
8813     VARIMP(I2,-1,INT,-1,I4,-1);
8814     VARIMP(I2,-1,UINT,1,I4,1);
8815     VARIMP(I4,2,EMPTY,0,I4,-3);
8816     VARIMP(I4,2,NULL,0,I4,-3);
8817     VARIMP(I4,2,I2,-1,I4,-1);
8818     VARIMP(I4,2,I4,-1,I4,-1);
8819     VARIMP(I4,2,R4,0.0f,I4,-3);
8820     VARIMP(I4,2,R8,-1.0,I4,-1);
8821     VARIMP(I4,2,DATE,0,I4,-3);
8822     VARIMP(I4,2,BSTR,true_str,I4,-1);
8823     VARIMP(I4,2,BOOL,VARIANT_FALSE,I4,-3);
8824     VARIMP(I4,2,I1,0,I4,-3);
8825     VARIMP(I4,2,UI1,1,I4,-3);
8826     VARIMP(I4,2,UI2,1,I4,-3);
8827     VARIMP(I4,2,UI4,1,I4,-3);
8828     if (has_i8)
8829     {
8830         VARIMP(I4,2,I8,1,I8,-3);
8831         VARIMP(I4,2,UI8,1,I4,-3);
8832     }
8833     VARIMP(I4,2,INT,-1,I4,-1);
8834     VARIMP(I4,2,UINT,1,I4,-3);
8835     VARIMP(R4,-1.0f,EMPTY,0,I4,0);
8836     VARIMP(R4,-1.0f,NULL,0,NULL,0);
8837     VARIMP(R4,-1.0f,I2,-1,I4,-1);
8838     VARIMP(R4,-1.0f,I4,-1,I4,-1);
8839     VARIMP(R4,-1.0f,R4,0.0f,I4,0);
8840     VARIMP(R4,-1.0f,R8,-1.0,I4,-1);
8841     VARIMP(R4,-1.0f,DATE,1,I4,1);
8842     VARIMP(R4,-1.0f,BSTR,true_str,I4,-1);
8843     VARIMP(R4,-1.0f,BOOL,VARIANT_FALSE,I4,0);
8844     VARIMP(R4,-1.0f,I1,0,I4,0);
8845     VARIMP(R4,-1.0f,UI1,1,I4,1);
8846     VARIMP(R4,-1.0f,UI2,1,I4,1);
8847     VARIMP(R4,-1.0f,UI4,1,I4,1);
8848     if (has_i8)
8849     {
8850         VARIMP(R4,-1.0f,I8,1,I8,1);
8851         VARIMP(R4,-1.0f,UI8,1,I4,1);
8852     }
8853     VARIMP(R4,-1.0f,INT,-1,I4,-1);
8854     VARIMP(R4,-1.0f,UINT,1,I4,1);
8855     VARIMP(R8,1.0,EMPTY,0,I4,-2);
8856     VARIMP(R8,1.0,NULL,0,I4,-2);
8857     VARIMP(R8,1.0,I2,-1,I4,-1);
8858     VARIMP(R8,1.0,I4,-1,I4,-1);
8859     VARIMP(R8,1.0,R4,0.0f,I4,-2);
8860     VARIMP(R8,1.0,R8,-1.0,I4,-1);
8861     VARIMP(R8,1.0,DATE,0,I4,-2);
8862     VARIMP(R8,1.0,BSTR,true_str,I4,-1);
8863     VARIMP(R8,1.0,BOOL,VARIANT_FALSE,I4,-2);
8864     VARIMP(R8,1.0,I1,0,I4,-2);
8865     VARIMP(R8,1.0,UI1,1,I4,-1);
8866     VARIMP(R8,1.0,UI2,1,I4,-1);
8867     VARIMP(R8,1.0,UI4,1,I4,-1);
8868     if (has_i8)
8869     {
8870         VARIMP(R8,1.0,I8,1,I8,-1);
8871         VARIMP(R8,1.0,UI8,1,I4,-1);
8872     }
8873     VARIMP(R8,1.0,INT,-1,I4,-1);
8874     VARIMP(R8,1.0,UINT,1,I4,-1);
8875     VARIMP(DATE,0,EMPTY,0,I4,-1);
8876     VARIMP(DATE,0,NULL,0,I4,-1);
8877     VARIMP(DATE,0,I2,-1,I4,-1);
8878     VARIMP(DATE,0,I4,-1,I4,-1);
8879     VARIMP(DATE,0,R4,0.0f,I4,-1);
8880     VARIMP(DATE,0,R8,-1.0,I4,-1);
8881     VARIMP(DATE,0,DATE,0,I4,-1);
8882     VARIMP(DATE,0,BSTR,true_str,I4,-1);
8883     VARIMP(DATE,0,BOOL,VARIANT_FALSE,I4,-1);
8884     VARIMP(DATE,0,I1,0,I4,-1);
8885     VARIMP(DATE,0,UI1,1,I4,-1);
8886     VARIMP(DATE,0,UI2,1,I4,-1);
8887     VARIMP(DATE,0,UI4,1,I4,-1);
8888     if (has_i8)
8889     {
8890         VARIMP(DATE,0,I8,1,I8,-1);
8891         VARIMP(DATE,0,UI8,1,I4,-1);
8892     }
8893     VARIMP(DATE,0,INT,-1,I4,-1);
8894     VARIMP(DATE,0,UINT,1,I4,-1);
8895     VARIMP(BSTR,false_str,EMPTY,0,I2,-1);
8896     VARIMP(BSTR,false_str,NULL,0,BOOL,-1);
8897     VARIMP(BSTR,false_str,I2,-1,I2,-1);
8898     VARIMP(BSTR,false_str,I4,-1,I4,-1);
8899     VARIMP(BSTR,false_str,R4,0.0f,I4,-1);
8900     VARIMP(BSTR,false_str,R8,-1.0,I4,-1);
8901     VARIMP(BSTR,false_str,DATE,0,I4,-1);
8902     VARIMP(BSTR,false_str,BSTR,true_str,BOOL,-1);
8903     VARIMP(BSTR,false_str,BOOL,VARIANT_FALSE,BOOL,-1);
8904     VARIMP(BSTR,false_str,I1,0,I4,-1);
8905     VARIMP(BSTR,false_str,UI1,1,I2,-1);
8906     VARIMP(BSTR,false_str,UI2,1,I4,-1);
8907     VARIMP(BSTR,false_str,UI4,1,I4,-1);
8908     if (has_i8)
8909     {
8910         VARIMP(BSTR,false_str,I8,1,I8,-1);
8911         VARIMP(BSTR,false_str,UI8,1,I4,-1);
8912     }
8913     VARIMP(BSTR,false_str,INT,-1,I4,-1);
8914     VARIMP(BSTR,false_str,UINT,1,I4,-1);
8915     VARIMP(BOOL,VARIANT_TRUE,EMPTY,0,I2,0);
8916     VARIMP(BOOL,VARIANT_TRUE,NULL,0,NULL,0);
8917     VARIMP(BOOL,VARIANT_TRUE,I2,-1,I2,-1);
8918     VARIMP(BOOL,VARIANT_TRUE,I4,-1,I4,-1);
8919     VARIMP(BOOL,VARIANT_TRUE,R4,0.0f,I4,0);
8920     VARIMP(BOOL,VARIANT_TRUE,R8,-1.0,I4,-1);
8921     VARIMP(BOOL,VARIANT_TRUE,DATE,0,I4,0);
8922     VARIMP(BOOL,VARIANT_TRUE,BSTR,true_str,BOOL,-1);
8923     VARIMP(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,0);
8924     VARIMP(BOOL,VARIANT_TRUE,I1,0,I4,0);
8925     VARIMP(BOOL,VARIANT_TRUE,UI1,1,I2,1);
8926     VARIMP(BOOL,VARIANT_TRUE,UI2,1,I4,1);
8927     VARIMP(BOOL,VARIANT_TRUE,UI4,1,I4,1);
8928     if (has_i8)
8929     {
8930         VARIMP(BOOL,VARIANT_TRUE,I8,1,I8,1);
8931         VARIMP(BOOL,VARIANT_TRUE,UI8,1,I4,1);
8932     }
8933     VARIMP(BOOL,VARIANT_TRUE,INT,-1,I4,-1);
8934     VARIMP(BOOL,VARIANT_TRUE,UINT,1,I4,1);
8935     VARIMP(I1,-1,EMPTY,0,I4,0);
8936     VARIMP(I1,-1,NULL,0,NULL,0);
8937     VARIMP(I1,-1,I2,-1,I4,-1);
8938     VARIMP(I1,-1,I4,-1,I4,-1);
8939     VARIMP(I1,-1,R4,0.0f,I4,0);
8940     VARIMP(I1,-1,R8,-1.0,I4,-1);
8941     VARIMP(I1,-1,DATE,0,I4,0);
8942     VARIMP(I1,-1,BSTR,true_str,I4,-1);
8943     VARIMP(I1,-1,BOOL,VARIANT_FALSE,I4,0);
8944     VARIMP(I1,-1,I1,0,I4,0);
8945     VARIMP(I1,-1,UI1,1,I4,1);
8946     VARIMP(I1,-1,UI2,1,I4,1);
8947     VARIMP(I1,-1,UI4,1,I4,1);
8948     if (has_i8)
8949     {
8950         VARIMP(I1,-1,I8,1,I8,1);
8951         VARIMP(I1,-1,UI8,1,I4,1);
8952     }
8953     VARIMP(I1,-1,INT,-1,I4,-1);
8954     VARIMP(I1,-1,UINT,1,I4,1);
8955     VARIMP(UI1,0,EMPTY,0,I2,-1);
8956     VARIMP(UI1,0,NULL,0,UI1,255);
8957     VARIMP(UI1,0,I2,-1,I2,-1);
8958     VARIMP(UI1,0,I4,-1,I4,-1);
8959     VARIMP(UI1,0,R4,0.0f,I4,-1);
8960     VARIMP(UI1,0,R8,-1.0,I4,-1);
8961     VARIMP(UI1,0,DATE,0,I4,-1);
8962     VARIMP(UI1,0,BSTR,true_str,I2,-1);
8963     VARIMP(UI1,0,BOOL,VARIANT_FALSE,I2,-1);
8964     VARIMP(UI1,0,I1,0,I4,-1);
8965     VARIMP(UI1,0,UI1,1,UI1,255);
8966     VARIMP(UI1,0,UI2,1,I4,-1);
8967     VARIMP(UI1,0,UI4,1,I4,-1);
8968     if (has_i8)
8969     {
8970         VARIMP(UI1,0,I8,1,I8,-1);
8971         VARIMP(UI1,0,UI8,1,I4,-1);
8972     }
8973     VARIMP(UI1,0,INT,-1,I4,-1);
8974     VARIMP(UI1,0,UINT,1,I4,-1);
8975     VARIMP(UI2,0,EMPTY,0,I4,-1);
8976     VARIMP(UI2,0,NULL,0,I4,-1);
8977     VARIMP(UI2,0,I2,-1,I4,-1);
8978     VARIMP(UI2,0,I4,-1,I4,-1);
8979     VARIMP(UI2,0,R4,0.0f,I4,-1);
8980     VARIMP(UI2,0,R8,-1.0,I4,-1);
8981     VARIMP(UI2,0,DATE,0,I4,-1);
8982     VARIMP(UI2,0,BSTR,true_str,I4,-1);
8983     VARIMP(UI2,0,BOOL,VARIANT_FALSE,I4,-1);
8984     VARIMP(UI2,0,I1,0,I4,-1);
8985     VARIMP(UI2,0,UI1,1,I4,-1);
8986     VARIMP(UI2,0,UI2,1,I4,-1);
8987     VARIMP(UI2,0,UI4,1,I4,-1);
8988     if (has_i8)
8989     {
8990         VARIMP(UI2,0,I8,1,I8,-1);
8991         VARIMP(UI2,0,UI8,1,I4,-1);
8992     }
8993     VARIMP(UI2,0,INT,-1,I4,-1);
8994     VARIMP(UI2,0,UINT,1,I4,-1);
8995     VARIMP(UI4,0,EMPTY,0,I4,-1);
8996     VARIMP(UI4,0,NULL,0,I4,-1);
8997     VARIMP(UI4,0,I2,-1,I4,-1);
8998     VARIMP(UI4,0,I4,-1,I4,-1);
8999     VARIMP(UI4,0,R4,0.0f,I4,-1);
9000     VARIMP(UI4,0,R8,-1.0,I4,-1);
9001     VARIMP(UI4,0,DATE,0,I4,-1);
9002     VARIMP(UI4,0,BSTR,true_str,I4,-1);
9003     VARIMP(UI4,0,BOOL,VARIANT_FALSE,I4,-1);
9004     VARIMP(UI4,0,I1,0,I4,-1);
9005     VARIMP(UI4,0,UI1,1,I4,-1);
9006     VARIMP(UI4,0,UI2,1,I4,-1);
9007     VARIMP(UI4,0,UI4,1,I4,-1);
9008     if (has_i8)
9009     {
9010         VARIMP(UI4,0,I8,1,I8,-1);
9011         VARIMP(UI4,0,UI8,1,I4,-1);
9012     }
9013     VARIMP(UI4,0,INT,-1,I4,-1);
9014     VARIMP(UI4,0,UINT,1,I4,-1);
9015     if (has_i8)
9016     {
9017         VARIMP(I8,-1,EMPTY,0,I8,0);
9018         VARIMP(I8,-1,NULL,0,NULL,0);
9019         VARIMP(I8,-1,I2,-1,I8,-1);
9020         VARIMP(I8,-1,I4,-1,I8,-1);
9021         VARIMP(I8,-1,R4,0.0f,I8,0);
9022         VARIMP(I8,-1,R8,-1.0,I8,-1);
9023         VARIMP(I8,-1,DATE,0,I8,0);
9024         VARIMP(I8,-1,BSTR,true_str,I8,-1);
9025         VARIMP(I8,-1,BOOL,VARIANT_FALSE,I8,0);
9026         VARIMP(I8,-1,I1,0,I8,0);
9027         VARIMP(I8,-1,UI1,1,I8,1);
9028         VARIMP(I8,-1,UI2,1,I8,1);
9029         VARIMP(I8,-1,UI4,1,I8,1);
9030         VARIMP(I8,-1,I8,1,I8,1);
9031         VARIMP(I8,-1,UI8,1,I8,1);
9032         VARIMP(I8,-1,UINT,1,I8,1);
9033         VARIMP(UI8,0,EMPTY,0,I4,-1);
9034         VARIMP(UI8,0,NULL,0,I4,-1);
9035         VARIMP(UI8,0,I2,-1,I4,-1);
9036         VARIMP(UI8,0,I4,-1,I4,-1);
9037         VARIMP(UI8,0,R4,0.0f,I4,-1);
9038         VARIMP(UI8,0,R8,-1.0,I4,-1);
9039         VARIMP(UI8,0,DATE,0,I4,-1);
9040         VARIMP(UI8,0,BSTR,true_str,I4,-1);
9041         VARIMP(UI8,0,BOOL,VARIANT_FALSE,I4,-1);
9042         VARIMP(UI8,0,I1,0,I4,-1);
9043         VARIMP(UI8,0,UI1,1,I4,-1);
9044         VARIMP(UI8,0,UI2,1,I4,-1);
9045         VARIMP(UI8,0,UI4,1,I4,-1);
9046         VARIMP(UI8,0,I8,1,I8,-1);
9047         VARIMP(UI8,0,UI8,1,I4,-1);
9048         VARIMP(UI8,0,INT,-1,I4,-1);
9049         VARIMP(UI8,0,UINT,1,I4,-1);
9050     }
9051     VARIMP(INT,-1,EMPTY,0,I4,0);
9052     VARIMP(INT,-1,NULL,0,NULL,0);
9053     VARIMP(INT,-1,I2,-1,I4,-1);
9054     VARIMP(INT,-1,I4,-1,I4,-1);
9055     VARIMP(INT,-1,R4,0.0f,I4,0);
9056     VARIMP(INT,-1,R8,-1.0,I4,-1);
9057     VARIMP(INT,-1,DATE,0,I4,0);
9058     VARIMP(INT,-1,BSTR,true_str,I4,-1);
9059     VARIMP(INT,-1,BOOL,VARIANT_FALSE,I4,0);
9060     VARIMP(INT,-1,I1,0,I4,0);
9061     VARIMP(INT,-1,UI1,1,I4,1);
9062     VARIMP(INT,-1,UI2,1,I4,1);
9063     VARIMP(INT,-1,UI4,1,I4,1);
9064     if (has_i8)
9065     {
9066         VARIMP(INT,-1,I8,1,I8,1);
9067         VARIMP(INT,-1,UI8,1,I4,1);
9068     }
9069     VARIMP(INT,-1,INT,-1,I4,-1);
9070     VARIMP(INT,-1,UINT,1,I4,1);
9071     VARIMP(UINT,1,EMPTY,0,I4,-2);
9072     VARIMP(UINT,1,NULL,0,I4,-2);
9073     VARIMP(UINT,1,I2,-1,I4,-1);
9074     VARIMP(UINT,1,I4,-1,I4,-1);
9075     VARIMP(UINT,1,R4,0.0f,I4,-2);
9076     VARIMP(UINT,1,R8,-1.0,I4,-1);
9077     VARIMP(UINT,1,DATE,0,I4,-2);
9078     VARIMP(UINT,1,BSTR,true_str,I4,-1);
9079     VARIMP(UINT,1,BOOL,VARIANT_FALSE,I4,-2);
9080     VARIMP(UINT,1,I1,0,I4,-2);
9081     VARIMP(UINT,1,UI1,1,I4,-1);
9082     VARIMP(UINT,1,UI2,1,I4,-1);
9083     VARIMP(UINT,1,UI4,1,I4,-1);
9084     if (has_i8)
9085     {
9086         VARIMP(UINT,1,I8,1,I8,-1);
9087         VARIMP(UINT,1,UI8,1,I4,-1);
9088     }
9089     VARIMP(UINT,1,INT,-1,I4,-1);
9090     VARIMP(UINT,1,UINT,1,I4,-1);
9091 
9092     /* Manually test some VT_CY, VT_DECIMAL variants */
9093     V_VT(&cy) = VT_CY;
9094     hres = VarCyFromI4(1, &V_CY(&cy));
9095     ok(hres == S_OK, "VarCyFromI4 failed!\n");
9096     V_VT(&dec) = VT_DECIMAL;
9097     hres = VarDecFromR8(2.0, &V_DECIMAL(&dec));
9098     ok(hres == S_OK, "VarDecFromR4 failed!\n");
9099     memset(&left, 0, sizeof(left));
9100     memset(&right, 0, sizeof(right));
9101     V_VT(&left) = VT_I4;
9102     V_I4(&left) = 0;
9103     V_VT(&right) = VT_I8;
9104     V_UI1(&right) = 0;
9105 
9106     hres = pVarImp(&cy, &cy, &result);
9107     ok(hres == S_OK && V_VT(&result) == VT_I4,
9108         "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
9109         S_OK, hres, vtstr(V_VT(&result)));
9110     ok(hres == S_OK && V_I4(&result) == -1,
9111         "VARIMP: CY value %d, expected %d\n", V_I4(&result), -1);
9112 
9113     if (has_i8)
9114     {
9115         hres = pVarImp(&cy, &right, &result);
9116         ok(hres == S_OK && V_VT(&result) == VT_I8,
9117             "VARIMP: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n",
9118             S_OK, hres, vtstr(V_VT(&result)));
9119         ok(hres == S_OK && V_I8(&result) == -2,
9120             "VARIMP: CY value %x%08x, expected %d\n",
9121             (DWORD)((V_I8(&result)) >> 32), (DWORD)(V_I8(&result)), -2);
9122     }
9123 
9124     hres = pVarImp(&left, &cy, &result);
9125     ok(hres == S_OK && V_VT(&result) == VT_I4,
9126         "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
9127         S_OK, hres, vtstr(V_VT(&result)));
9128     ok(hres == S_OK && V_I4(&result) == -1,
9129         "VARIMP: CY value %d, expected %d\n", V_I4(&result), -1);
9130 
9131     hres = pVarImp(&left, &dec, &result);
9132     ok(hres == S_OK && V_VT(&result) == VT_I4,
9133         "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
9134         S_OK, hres, vtstr(V_VT(&result)));
9135     ok(hres == S_OK && V_I4(&result) == -1,
9136         "VARIMP: DECIMAL value %d, expected %d\n", V_I4(&result), -1);
9137 
9138     hres = pVarImp(&dec, &dec, &result);
9139     ok(hres == S_OK && V_VT(&result) == VT_I4,
9140         "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
9141         S_OK, hres, vtstr(V_VT(&result)));
9142     ok(hres == S_OK && V_I4(&result) == -1,
9143         "VARIMP: DECIMAL value %d, expected %d\n", V_I4(&result), -1);
9144 
9145     if (has_i8)
9146     {
9147         hres = pVarImp(&dec, &right, &result);
9148         ok(hres == S_OK && V_VT(&result) == VT_I8,
9149             "VARIMP: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n",
9150             S_OK, hres, vtstr(V_VT(&result)));
9151         ok(hres == S_OK && V_I8(&result) == -3,
9152             "VARIMP: DECIMAL value 0x%x%08x, expected %d\n",
9153 	    (DWORD)(V_I8(&result) >>32), (DWORD)V_I8(&result), -3);
9154     }
9155 
9156     SysFreeString(false_str);
9157     SysFreeString(true_str);
9158 }
9159 
9160 START_TEST(vartest)
9161 {
9162   init();
9163 
9164   test_VariantInit();
9165   test_VariantClear();
9166   test_VariantCopy();
9167   test_VariantCopyInd();
9168   test_VarParseNumFromStr();
9169   test_VarNumFromParseNum();
9170   test_VarUdateFromDate();
9171   test_VarDateFromUdate();
9172   test_SystemTimeToVariantTime();
9173   test_VariantTimeToSystemTime();
9174   test_DosDateTimeToVariantTime();
9175   test_VariantTimeToDosDateTime();
9176   test_VarAbs();
9177   test_VarNot();
9178   test_VarSub();
9179   test_VarMod();
9180   test_VarFix();
9181   test_VarInt();
9182   test_VarNeg();
9183   test_VarRound();
9184   test_VarXor();
9185   test_VarOr();
9186   test_VarPow();
9187   test_VarEqv();
9188   test_VarMul();
9189   test_VarAdd();
9190   test_VarCmp(); /* Before test_VarCat() which needs VarCmp() */
9191   test_VarCat();
9192   test_VarAnd();
9193   test_VarDiv();
9194   test_VarIdiv();
9195   test_VarImp();
9196 }
9197