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   /* Underflow test */
1935   SETRGB(0, 1); CONVERT(1,0,NUMPRS_EXPONENT,1,0,-94938484, VTBIT_R4); EXPECT_R4(0.0);
1936   SETRGB(0, 1); CONVERT(1,0,NUMPRS_EXPONENT,1,0,-94938484, VTBIT_R8); EXPECT_R8(0.0);
1937   SETRGB(0, 1); CONVERT(1,0,NUMPRS_EXPONENT,1,0,-94938484, VTBIT_CY); EXPECT_CY(0);
1938 }
1939 
1940 
1941 static void test_UdateFromDate( int line, DATE dt, ULONG flags, HRESULT r, WORD d, WORD m, WORD y,
1942                                 WORD h, WORD mn, WORD s, WORD ms, WORD dw, WORD dy)
1943 {
1944     UDATE ud;
1945     HRESULT res;
1946 
1947     memset(&ud, 0, sizeof(ud));
1948     res = pVarUdateFromDate(dt, flags, &ud);
1949     ok_(__FILE__,line)(r == res && (res != S_OK || (ud.st.wYear == y && ud.st.wMonth == m && ud.st.wDay == d &&
1950                        ud.st.wHour == h && ud.st.wMinute == mn && ud.st.wSecond == s &&
1951                        ud.st.wMilliseconds == ms && ud.st.wDayOfWeek == dw && ud.wDayOfYear == dy)),
1952                        "%.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",
1953                        dt, r, d, m, y, h, mn, s, ms, dw, dy,
1954                        res, ud.st.wDay, ud.st.wMonth, ud.st.wYear, ud.st.wHour, ud.st.wMinute,
1955                        ud.st.wSecond, ud.st.wMilliseconds, ud.st.wDayOfWeek, ud.wDayOfYear );
1956 }
1957 #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)
1958 
1959 static void test_VarUdateFromDate(void)
1960 {
1961   CHECKPTR(VarUdateFromDate);
1962   DT2UD(29221.0,0,S_OK,1,1,1980,0,0,0,0,2,1);        /* 1 Jan 1980 */
1963   DT2UD(29222.0,0,S_OK,2,1,1980,0,0,0,0,3,2);        /* 2 Jan 1980 */
1964   DT2UD(33238.0,0,S_OK,31,12,1990,0,0,0,0,1,365);    /* 31 Dec 1990 */
1965   DT2UD(0.0,0,S_OK,30,12,1899,0,0,0,0,6,364);        /* 30 Dec 1899 - VT_DATE 0.0 */
1966   DT2UD(-657434.0,0,S_OK,1,1,100,0,0,0,0,5,1);       /* 1 Jan 100 - Min */
1967   DT2UD(-657435.0,0,E_INVALIDARG,0,0,0,0,0,0,0,0,0); /* < 1 Jan 100 => err */
1968   DT2UD(2958465.0,0,S_OK,31,12,9999,0,0,0,0,5,365);  /* 31 Dec 9999 - Max */
1969   DT2UD(2958466.0,0,E_INVALIDARG,0,0,0,0,0,0,0,0,0); /* > 31 Dec 9999 => err  */
1970 
1971   /* VAR_VALIDDATE doesn't prevent upper and lower bounds being checked */
1972   DT2UD(-657435.0,VAR_VALIDDATE,E_INVALIDARG,0,0,0,0,0,0,0,0,0);
1973   DT2UD(2958466.0,VAR_VALIDDATE,E_INVALIDARG,0,0,0,0,0,0,0,0,0);
1974 
1975   /* Times */
1976   DT2UD(29221.25,0,S_OK,1,1,1980,6,0,0,0,2,1);           /* 6 AM */
1977   DT2UD(29221.33333333,0,S_OK,1,1,1980,8,0,0,0,2,1);     /* 8 AM */
1978   DT2UD(29221.5,0,S_OK,1,1,1980,12,0,0,0,2,1);           /* 12 AM */
1979   DT2UD(29221.9888884444,0,S_OK,1,1,1980,23,44,0,0,2,1); /* 11:44 PM */
1980   DT2UD(29221.7508765432,0,S_OK,1,1,1980,18,1,16,0,2,1); /* 6:18:02 PM */
1981 
1982   /* Test handling of times on dates prior to the epoch */
1983   DT2UD(-5.25,0,S_OK,25,12,1899,6,0,0,0,1,359);
1984   DT2UD(-5.9999884259259,0,S_OK,25,12,1899,23,59,59,0,1,359);
1985   /* This just demonstrates the non-linear nature of values prior to the epoch */
1986   DT2UD(-4.0,0,S_OK,26,12,1899,0,0,0,0,2,360);
1987   /* Numerical oddity: for 0.0 < x < 1.0, x and -x represent the same datetime */
1988   DT2UD(-0.25,0,S_OK,30,12,1899,6,0,0,0,6,364);
1989   DT2UD(0.25,0,S_OK,30,12,1899,6,0,0,0,6,364);
1990 }
1991 
1992 
1993 static void test_DateFromUDate( int line, WORD d, WORD m, WORD y, WORD h, WORD mn, WORD s, WORD ms,
1994                                 WORD dw, WORD dy, ULONG flags, HRESULT r, DATE dt )
1995 {
1996     UDATE ud;
1997     double out;
1998     HRESULT res;
1999 
2000     ud.st.wYear = y;
2001     ud.st.wMonth = m;
2002     ud.st.wDay = d;
2003     ud.st.wHour = h;
2004     ud.st.wMinute = mn;
2005     ud.st.wSecond = s;
2006     ud.st.wMilliseconds = ms;
2007     ud.st.wDayOfWeek = dw;
2008     ud.wDayOfYear = dy;
2009     res = pVarDateFromUdate(&ud, flags, &out);
2010     ok_(__FILE__,line)(r == res && (r != S_OK || EQ_DOUBLE(out, dt)),
2011                        "expected %x, %.16g, got %x, %.16g\n", r, dt, res, out);
2012 }
2013 #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)
2014 
2015 static void test_VarDateFromUdate(void)
2016 {
2017   CHECKPTR(VarDateFromUdate);
2018   UD2T(1,1,1980,0,0,0,0,2,1,0,S_OK,29221.0);      /* 1 Jan 1980 */
2019   UD2T(2,1,1980,0,0,0,0,3,2,0,S_OK,29222.0);      /* 2 Jan 1980 */
2020   UD2T(2,1,1980,0,0,0,0,4,5,0,S_OK,29222.0);      /* 2 Jan 1980 */
2021   UD2T(31,12,1990,0,0,0,0,0,0,0,S_OK,33238.0);    /* 31 Dec 1990 */
2022   UD2T(31,12,90,0,0,0,0,0,0,0,S_OK,33238.0);      /* year < 100 is 1900+year! */
2023   UD2T(30,12,1899,0,0,0,0,6,364,0,S_OK,0.0);      /* 30 Dec 1899 - VT_DATE 0.0 */
2024   UD2T(1,1,100,0,0,0,0,0,0,0,S_OK,-657434.0);     /* 1 Jan 100 - Min */
2025   UD2T(31,12,9999,0,0,0,0,0,0,0,S_OK,2958465.0);  /* 31 Dec 9999 - Max */
2026   UD2T(1,1,10000,0,0,0,0,0,0,0,E_INVALIDARG,0.0); /* > 31 Dec 9999 => err  */
2027   UD2T(1,1,-10000,0,0,0,0,0,0,0,E_INVALIDARG,0.0);/* < -9999 => err  */
2028 
2029   UD2T(30,12,1899,0,0,0,0,0,0,0,S_OK,0.0); /* 30 Dec 1899 0:00:00  */
2030   UD2T(30,12,1899,0,0,0,999,0,0,0,S_OK,0.0); /* Ignore milliseconds  */
2031 
2032   UD2T(1,1,1980,18,1,16,0,2,1,0,S_OK,29221.75087962963);             /* 6:18:02 PM */
2033   UD2T(1,300,1980,18,1,16,0,2,1,0,S_OK,38322.75087962963);           /* Test fwdrolled month */
2034   UD2T(300,1,1980,18,1,16,0,2,1,0,S_OK,29520.75087962963);           /* Test fwdrolled days */
2035   UD2T(0,1,1980,42,1,16,0,2,1,0,S_OK,29221.75087962963);             /* Test fwdrolled hours */
2036   UD2T(1,1,1980,17,61,16,0,2,1,0,S_OK,29221.75087962963);            /* Test fwdrolled minutes */
2037   UD2T(1,1,1980,18,0,76,0,2,1,0,S_OK,29221.75087962963);             /* Test fwdrolled seconds */
2038   UD2T(1,-300,1980,18,1,16,0,2,1,0,S_OK,20059.75087962963);          /* Test backrolled month */
2039   UD2T(-300,1,1980,18,1,16,0,2,1,0,S_OK,28920.75087962963);          /* Test backrolled days */
2040   UD2T(3,1,1980,-30,1,16,0,2,1,0,S_OK,29221.75087962963);            /* Test backrolled hours */
2041   UD2T(1,1,1980,20,-119,16,0,2,1,0,S_OK,29221.75087962963);          /* Test backrolled minutes */
2042   UD2T(1,1,1980,18,3,-104,0,2,1,0,S_OK,29221.75087962963);           /* Test backrolled seconds */
2043   UD2T(1,12001,-1020,18,1,16,0,0,0,0,S_OK,29221.75087962963);        /* Test rolled year and month */
2044   UD2T(1,-23,1982,18,1,16,0,0,0,0,S_OK,29221.75087962963);           /* Test backrolled month */
2045   UD2T(-59,3,1980,18,1,16,0,0,0,0,S_OK,29221.75087962963);           /* Test backrolled days */
2046   UD2T(1,1,0,0,0,0,0,0,0,0,S_OK,36526);                              /* Test zero year */
2047   UD2T(0,0,1980,0,0,0,0,0,0,0,S_OK,29189);                           /* Test zero day and month */
2048   UD2T(0,1,1980,0,0,0,0,2,1,0,S_OK,29220.0);                         /* Test zero day = LastDayOfMonth */
2049   UD2T(-1,1,1980,18,1,16,0,0,0,0,S_OK,29219.75087962963);            /* Test day -1 = LastDayOfMonth - 1 */
2050   UD2T(1,1,-1,18,1,16,0,0,0,0,S_OK,36161.75087962963);               /* Test year -1 = 1999 */
2051   UD2T(1,-1,1980,18,1,16,0,0,0,0,S_OK,29160.7508796296);             /* Test month -1 = 11 */
2052   UD2T(1,13,1980,0,0,0,0,2,1,0,S_OK,29587.0);                        /* Rolls fwd to 1/1/1981 */
2053 
2054   /* Test handling of times on dates prior to the epoch */
2055   UD2T(25,12,1899,6,0,0,0,1,359,0,S_OK,-5.25);
2056   UD2T(25,12,1899,23,59,59,0,1,359,0,S_OK,-5.9999884259259);
2057   /* This just demonstrates the non-linear nature of values prior to the epoch */
2058   UD2T(26,12,1899,0,0,0,0,2,360,0,S_OK,-4.0);
2059   /* for DATE values 0.0 < x < 1.0, x and -x represent the same datetime */
2060   /* but when converting to DATE, prefer the positive versions */
2061   UD2T(30,12,1899,6,0,0,0,6,364,0,S_OK,0.25);
2062 
2063   UD2T(1,1,1980,18,1,16,0,2,1,VAR_TIMEVALUEONLY,S_OK,0.7508796296296296);
2064   UD2T(1,1,1980,18,1,16,0,2,1,VAR_DATEVALUEONLY,S_OK,29221.0);
2065   UD2T(25,12,1899,6,0,0,0,1,359,VAR_TIMEVALUEONLY,S_OK,0.25);
2066   UD2T(25,12,1899,6,0,0,0,1,359,VAR_DATEVALUEONLY,S_OK,-5.0);
2067   UD2T(1,-1,1980,18,1,16,0,0,0,VAR_TIMEVALUEONLY|VAR_DATEVALUEONLY,S_OK,0.7508796296296296);
2068 }
2069 
2070 static void test_st2dt(int line, WORD d, WORD m, WORD y, WORD h, WORD mn,
2071                        WORD s, WORD ms, INT r, double dt)
2072 {
2073     SYSTEMTIME st;
2074     double out;
2075     INT res;
2076 
2077     st.wYear = y;
2078     st.wMonth = m;
2079     st.wDay = d;
2080     st.wHour = h;
2081     st.wMinute = mn;
2082     st.wSecond = s;
2083     st.wMilliseconds = ms;
2084     st.wDayOfWeek = 0;
2085     res = pSystemTimeToVariantTime(&st, &out);
2086     ok_(__FILE__,line)(r == res && (!r || EQ_DOUBLE(out, dt)),
2087                        "expected %d, %.16g, got %d, %.16g\n", r, dt, res, out);
2088 }
2089 #define ST2DT(d,m,y,h,mn,s,ms,r,dt) test_st2dt(__LINE__,d,m,y,h,mn,s,ms,r,dt)
2090 
2091 static void test_SystemTimeToVariantTime(void)
2092 {
2093   CHECKPTR(SystemTimeToVariantTime);
2094   ST2DT(1,1,1980,0,0,0,0,TRUE,29221.0);
2095   ST2DT(2,1,1980,0,0,0,0,TRUE,29222.0);
2096   ST2DT(0,1,1980,0,0,0,0,TRUE,29220.0);   /* Rolls back to 31 Dec 1899 */
2097   ST2DT(1,13,1980,0,0,0,0,FALSE,29587.0); /* Fails on invalid month */
2098   ST2DT(32,1,1980,0,0,0,0,FALSE,0.0);     /* Fails on invalid day */
2099   ST2DT(1,1,-1,0,0,0,0,FALSE,0.0);        /* Fails on invalid year */
2100   ST2DT(1,1,10000,0,0,0,0,FALSE,0.0);     /* Fails on invalid year */
2101   ST2DT(1,1,9999,0,0,0,0,TRUE,2958101.0); /* 9999 is last valid year */
2102   ST2DT(31,12,90,0,0,0,0,TRUE,33238.0);   /* 30 <= year < 100 is 1900+year */
2103   ST2DT(1,1,30,0,0,0,0,TRUE,10959.0);     /* 30 <= year < 100 is 1900+year */
2104   ST2DT(1,1,29,0,0,0,0,TRUE,47119.0);     /* 0 <= year < 30 is 2000+year */
2105   ST2DT(1,1,0,0,0,0,0,TRUE,36526.0);      /* 0 <= year < 30 is 2000+year */
2106 }
2107 
2108 static void test_dt2st(int line, double dt, INT r, WORD d, WORD m, WORD y,
2109                        WORD h, WORD mn, WORD s, WORD ms)
2110 {
2111   SYSTEMTIME st;
2112   INT res;
2113 
2114   memset(&st, 0, sizeof(st));
2115   res = pVariantTimeToSystemTime(dt, &st);
2116   ok_(__FILE__,line)(r == res &&
2117                      (!r || (st.wYear == y && st.wMonth == m && st.wDay == d &&
2118                              st.wHour == h && st.wMinute == mn &&
2119                              st.wSecond == s && st.wMilliseconds == ms)),
2120                      "%.16g expected %d, %d,%d,%d,%d,%d,%d,%d, got %d, %d,%d,%d,%d,%d,%d,%d\n",
2121                      dt, r, d, m, y, h, mn, s, ms, res, st.wDay, st.wMonth,
2122                      st.wYear, st.wHour, st.wMinute, st.wSecond,
2123                      st.wMilliseconds);
2124 }
2125 #define DT2ST(dt,r,d,m,y,h,mn,s,ms) test_dt2st(__LINE__,dt,r,d,m,y,h,mn,s,ms)
2126 
2127 static void test_VariantTimeToSystemTime(void)
2128 {
2129   CHECKPTR(VariantTimeToSystemTime);
2130   DT2ST(29221.0,1,1,1,1980,0,0,0,0);
2131   DT2ST(29222.0,1,2,1,1980,0,0,0,0);
2132 }
2133 
2134 #define MKDOSDATE(d,m,y) ((d & 0x1f) | ((m & 0xf) << 5) | (((y-1980) & 0x7f) << 9))
2135 #define MKDOSTIME(h,m,s) (((s>>1) & 0x1f) | ((m & 0x3f) << 5) | ((h & 0x1f) << 11))
2136 
2137 static void test_dos2dt(int line, WORD d, WORD m, WORD y, WORD h, WORD mn,
2138                         WORD s, INT r, double dt)
2139 {
2140     unsigned short dosDate, dosTime;
2141     double out;
2142     INT res;
2143 
2144     out = 0.0;
2145     dosDate = MKDOSDATE(d, m, y);
2146     dosTime = MKDOSTIME(h, mn, s);
2147     res = pDosDateTimeToVariantTime(dosDate, dosTime, &out);
2148     ok_(__FILE__,line)(r == res && (!r || EQ_DOUBLE(out, dt)),
2149                        "expected %d, %.16g, got %d, %.16g\n", r, dt, res, out);
2150 }
2151 #define DOS2DT(d,m,y,h,mn,s,r,dt) test_dos2dt(__LINE__,d,m,y,h,mn,s,r,dt)
2152 
2153 static void test_DosDateTimeToVariantTime(void)
2154 {
2155   CHECKPTR(DosDateTimeToVariantTime);
2156 
2157   /* Date */
2158   DOS2DT(1,1,1980,0,0,0,1,29221.0); /* 1/1/1980 */
2159   DOS2DT(31,12,2099,0,0,0,1,73050.0); /* 31/12/2099 */
2160   /* Dates are limited to the dos date max of 31/12/2099 */
2161   DOS2DT(31,12,2100,0,0,0,0,0.0); /* 31/12/2100 */
2162   /* Days and months of 0 cause date to roll back 1 day or month */
2163   DOS2DT(0,1,1980,0,0,0,1,29220.0); /* 0 Day => 31/12/1979 */
2164   DOS2DT(1,0,1980,0,0,0,1,29190.0); /* 0 Mth =>  1/12/1979 */
2165   DOS2DT(0,0,1980,0,0,0,1,29189.0); /* 0 D/M => 30/11/1979 */
2166   /* Days > days in the month cause date to roll forward 1 month */
2167   DOS2DT(29,2,1981,0,0,0,1,29646.0); /* 29/2/1981 -> 3/1/1980 */
2168   DOS2DT(30,2,1981,0,0,0,1,29647.0); /* 30/2/1981 -> 4/1/1980 */
2169   /* Takes leap years into account when rolling forward */
2170   DOS2DT(29,2,1980,0,0,0,1,29280.0); /* 2/29/1980 */
2171   /* Months > 12 cause an error */
2172   DOS2DT(2,13,1980,0,0,0,0,0.0);
2173 
2174   /* Time */
2175   DOS2DT(1,1,1980,0,0,29,1,29221.00032407407); /* 1/1/1980 12:00:28 AM */
2176   DOS2DT(1,1,1980,0,0,31,1,29221.00034722222); /* 1/1/1980 12:00:30 AM */
2177   DOS2DT(1,1,1980,0,59,0,1,29221.04097222222); /* 1/1/1980 12:59:00 AM */
2178   DOS2DT(1,1,1980,0,60,0,0,0.0);               /* Invalid minutes */
2179   DOS2DT(1,1,1980,0,0,60,0,0.0);               /* Invalid seconds */
2180   DOS2DT(1,1,1980,23,0,0,1,29221.95833333333); /* 1/1/1980 11:00:00 PM */
2181   DOS2DT(1,1,1980,24,0,0,0,0.0);               /* Invalid hours */
2182 
2183   DOS2DT(1,1,1980,0,0,1,1,29221.0);
2184   DOS2DT(2,1,1980,0,0,0,1,29222.0);
2185   DOS2DT(2,1,1980,0,0,0,1,29222.0);
2186   DOS2DT(31,12,1990,0,0,0,1,33238.0);
2187   DOS2DT(31,12,90,0,0,0,1,40543.0);
2188   DOS2DT(30,12,1899,0,0,0,1,46751.0);
2189   DOS2DT(1,1,100,0,0,0,1,43831.0);
2190   DOS2DT(31,12,9999,0,0,0,1,59901.0);
2191   DOS2DT(1,1,10000,0,0,0,1,59902.0);
2192   DOS2DT(1,1,-10000,0,0,0,1,48214.0);
2193 
2194   DOS2DT(30,12,1899,0,0,0,1,46751.0);
2195   DOS2DT(30,12,1899,0,0,1,1,46751.0);
2196 
2197   DOS2DT(1,1,1980,18,1,16,1,29221.75087962963);
2198   DOS2DT(1,300,1980,18,1,16,1,29556.75087962963);
2199   DOS2DT(300,1,1980,18,1,16,1,29232.75087962963);
2200   DOS2DT(0,1,1980,42,1,16,1,29220.4175462963);
2201   DOS2DT(1,1,1980,17,61,16,0,0.0);
2202   DOS2DT(1,1,1980,18,0,76,1,29221.75013888889);
2203   DOS2DT(1,-300,1980,18,1,16,1,29312.75087962963);
2204   DOS2DT(-300,1,1980,18,1,16,1,29240.75087962963);
2205   DOS2DT(3,1,1980,-30,1,16,1,29223.08421296296);
2206   DOS2DT(1,1,1980,20,-119,16,1,29221.83976851852);
2207   DOS2DT(1,1,1980,18,3,-104,1,29221.75236111111);
2208   DOS2DT(1,12001,-1020,18,1,16,1,55519.75087962963);
2209   DOS2DT(1,-23,1982,18,1,16,1,30195.75087962963);
2210   DOS2DT(-59,3,1980,18,1,16,1,29285.75087962963);
2211   DOS2DT(1,1,0,0,0,0,1,54058.0);
2212   DOS2DT(0,0,1980,0,0,0,1,29189.0);
2213   DOS2DT(0,1,1980,0,0,0,1,29220.0);
2214   DOS2DT(-1,1,1980,18,1,16,1,29251.75087962963);
2215   DOS2DT(1,1,-1,18,1,16,1,53693.75087962963);
2216   DOS2DT(1,-1,1980,18,1,16,0,0);
2217 }
2218 
2219 static void test_dt2dos(int line, double dt, INT r, WORD d, WORD m, WORD y,
2220                         WORD h, WORD mn, WORD s)
2221 {
2222     unsigned short dosDate, dosTime, expDosDate, expDosTime;
2223     INT res;
2224 
2225     dosTime = dosDate = 0;
2226     expDosDate = MKDOSDATE(d,m,y);
2227     expDosTime = MKDOSTIME(h,mn,s);
2228     res = pVariantTimeToDosDateTime(dt, &dosDate, &dosTime);
2229     ok_(__FILE__,line)(r == res && (!r || (dosTime == expDosTime && dosDate == expDosDate)),
2230                        "%g: expected %d,%d(%d/%d/%d),%d(%d:%d:%d) got %d,%d(%d/%d/%d),%d(%d:%d:%d)\n",
2231                        dt, r, expDosDate, expDosDate & 0x1f,
2232                        (expDosDate >> 5) & 0xf, 1980 + (expDosDate >> 9),
2233                        expDosTime, expDosTime >> 11, (expDosTime >> 5) & 0x3f,
2234                        (expDosTime & 0x1f),
2235                        res, dosDate, dosDate & 0x1f, (dosDate >> 5) & 0xf,
2236                        1980 + (dosDate >> 9), dosTime, dosTime >> 11,
2237                        (dosTime >> 5) & 0x3f, (dosTime & 0x1f));
2238 }
2239 #define DT2DOS(dt,r,d,m,y,h,mn,s) test_dt2dos(__LINE__,dt,r,d,m,y,h,mn,s)
2240 
2241 static void test_VariantTimeToDosDateTime(void)
2242 {
2243   CHECKPTR(VariantTimeToDosDateTime);
2244 
2245   /* Date */
2246   DT2DOS(29221.0,1,1,1,1980,0,0,0);   /* 1/1/1980 */
2247   DT2DOS(73050.0,1,31,12,2099,0,0,0); /* 31/12/2099 */
2248   DT2DOS(29220.0,0,0,0,0,0,0,0);      /* 31/12/1979 - out of range */
2249   DT2DOS(73415.0,0,0,0,0,0,0,0);      /* 31/12/2100 - out of range */
2250 
2251   /* Time */
2252   DT2DOS(29221.00032407407,1,1,1,1980,0,0,29); /* 1/1/1980 12:00:28 AM */
2253   DT2DOS(29221.00034722222,1,1,1,1980,0,0,31); /* 1/1/1980 12:00:30 AM */
2254   DT2DOS(29221.04097222222,1,1,1,1980,0,59,0); /* 1/1/1980 12:59:00 AM */
2255   DT2DOS(29221.95833333333,1,1,1,1980,23,0,0); /* 1/1/1980 11:00:00 PM */
2256 }
2257 
2258 static HRESULT (WINAPI *pVarAbs)(LPVARIANT,LPVARIANT);
2259 
2260 #define VARABS(vt,val,rvt,rval)                  \
2261     V_VT(&v) = VT_##vt; V_##vt(&v) = val;        \
2262     V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
2263     test_var_call1( __LINE__, pVarAbs, &v, &exp )
2264 
2265 static void test_VarAbs(void)
2266 {
2267     static WCHAR szNum[] = {'-','1','.','1','\0' };
2268     char buff[8];
2269     HRESULT hres;
2270     VARIANT v, vDst, exp;
2271     size_t i;
2272 
2273     CHECKPTR(VarAbs);
2274 
2275     /* Test all possible V_VT values.
2276      */
2277     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2278     {
2279         VARTYPE vt;
2280 
2281         for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2282         {
2283             HRESULT hExpected = DISP_E_BADVARTYPE;
2284 
2285             SKIPTESTS(vt);
2286 
2287             memset(&v, 0, sizeof(v));
2288             V_VT(&v) = vt | ExtraFlags[i];
2289             V_VT(&vDst) = VT_EMPTY;
2290 
2291             hres = pVarAbs(&v,&vDst);
2292             if (ExtraFlags[i] & VT_ARRAY ||
2293                 (!ExtraFlags[i] && (vt == VT_UNKNOWN || vt == VT_BSTR ||
2294                  vt == VT_DISPATCH || vt == VT_ERROR || vt == VT_RECORD)))
2295             {
2296                 hExpected = DISP_E_TYPEMISMATCH;
2297             }
2298             else if (ExtraFlags[i] || vt >= VT_CLSID || vt == VT_VARIANT)
2299             {
2300                 hExpected = DISP_E_BADVARTYPE;
2301             }
2302             else if (IsValidVariantClearVT(vt, ExtraFlags[i]))
2303                 hExpected = S_OK;
2304 
2305             /* Native always fails on some vartypes that should be valid. don't
2306              * check that Wine does the same; these are bugs in native.
2307              */
2308             if (vt == VT_I8 || vt == VT_UI8 || vt == VT_INT || vt == VT_UINT ||
2309                 vt == VT_I1 || vt == VT_UI2 || vt == VT_UI4)
2310                 continue;
2311             ok(hres == hExpected, "VarAbs: expected 0x%X, got 0x%X for vt %d | 0x%X\n",
2312                hExpected, hres, vt, ExtraFlags[i]);
2313         }
2314     }
2315 
2316     /* BOOL->I2, BSTR->R8, all others remain the same */
2317     VARABS(BOOL,VARIANT_TRUE,I2,-VARIANT_TRUE);
2318     VARABS(BOOL,VARIANT_FALSE,I2,VARIANT_FALSE);
2319     VARABS(EMPTY,0,I2,0);
2320     VARABS(EMPTY,1,I2,0);
2321     VARABS(NULL,0,NULL,0);
2322     VARABS(NULL,1,NULL,0);
2323     VARABS(I2,1,I2,1);
2324     VARABS(I2,-1,I2,1);
2325     VARABS(I4,1,I4,1);
2326     VARABS(I4,-1,I4,1);
2327     VARABS(UI1,1,UI1,1);
2328     VARABS(R4,1,R4,1);
2329     VARABS(R4,-1,R4,1);
2330     VARABS(R8,1,R8,1);
2331     VARABS(R8,-1,R8,1);
2332     VARABS(DATE,1,DATE,1);
2333     VARABS(DATE,-1,DATE,1);
2334     V_VT(&v) = VT_CY;
2335     V_CY(&v).int64 = -10000;
2336     memset(&vDst,0,sizeof(vDst));
2337     hres = pVarAbs(&v,&vDst);
2338     ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
2339        "VarAbs(CY): expected 0x0 got 0x%X\n", hres);
2340     GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char));
2341     if (buff[1])
2342     {
2343         trace("Skipping VarAbs(BSTR) as decimal separator is '%s'\n", buff);
2344         return;
2345     } else {
2346 	szNum[2] = buff[0];
2347     }
2348     V_VT(&v) = VT_BSTR;
2349     V_BSTR(&v) = (BSTR)szNum;
2350     memset(&vDst,0,sizeof(vDst));
2351     hres = pVarAbs(&v,&vDst);
2352     ok(hres == S_OK && V_VT(&vDst) == VT_R8 && V_R8(&vDst) == 1.1,
2353        "VarAbs: expected 0x0,%d,%g, got 0x%X,%d,%g\n", VT_R8, 1.1, hres, V_VT(&vDst), V_R8(&vDst));
2354 }
2355 
2356 static HRESULT (WINAPI *pVarNot)(LPVARIANT,LPVARIANT);
2357 
2358 #define VARNOT(vt,val,rvt,rval)                  \
2359     V_VT(&v) = VT_##vt; V_##vt(&v) = val;        \
2360     V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
2361     test_var_call1( __LINE__, pVarNot, &v, &exp )
2362 
2363 static void test_VarNot(void)
2364 {
2365     static const WCHAR szNum0[] = {'0','\0' };
2366     static const WCHAR szNum1[] = {'1','\0' };
2367     static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
2368     static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
2369     HRESULT hres;
2370     VARIANT v, exp, vDst;
2371     DECIMAL *pdec = &V_DECIMAL(&v);
2372     CY *pcy = &V_CY(&v);
2373     size_t i;
2374 
2375     CHECKPTR(VarNot);
2376 
2377     /* Test all possible V_VT values */
2378     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2379     {
2380         VARTYPE vt;
2381 
2382         for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2383         {
2384             HRESULT hExpected = DISP_E_BADVARTYPE;
2385 
2386             SKIPTESTS(vt);
2387 
2388             memset(&v, 0, sizeof(v));
2389             V_VT(&v) = vt | ExtraFlags[i];
2390             V_VT(&vDst) = VT_EMPTY;
2391 
2392             switch (V_VT(&v))
2393             {
2394             case VT_I1:  case VT_UI1: case VT_I2:  case VT_UI2:
2395             case VT_INT: case VT_UINT: case VT_I4:  case VT_UI4:
2396             case VT_R4:  case VT_R8:
2397             case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
2398             case VT_DATE: case VT_CY:
2399                 hExpected = S_OK;
2400                 break;
2401             case VT_I8: case VT_UI8:
2402                 if (has_i8)
2403                     hExpected = S_OK;
2404                 break;
2405             case VT_RECORD:
2406                 hExpected = DISP_E_TYPEMISMATCH;
2407                 break;
2408             case VT_UNKNOWN: case VT_BSTR: case VT_DISPATCH: case VT_ERROR:
2409                 hExpected = DISP_E_TYPEMISMATCH;
2410                 break;
2411             default:
2412                 if (IsValidVariantClearVT(vt, ExtraFlags[i]) && vt != VT_CLSID)
2413                    hExpected = DISP_E_TYPEMISMATCH;
2414                 break;
2415             }
2416 
2417             hres = pVarNot(&v,&vDst);
2418             ok(hres == hExpected, "VarNot: expected 0x%X, got 0x%X vt %d|0x%X\n",
2419                hExpected, hres, vt, ExtraFlags[i]);
2420         }
2421     }
2422     /* Test the values returned by all cases that can succeed */
2423     VARNOT(EMPTY,0,I2,-1);
2424     VARNOT(EMPTY,1,I2,-1);
2425     VARNOT(NULL,0,NULL,0);
2426     VARNOT(NULL,1,NULL,0);
2427     VARNOT(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
2428     VARNOT(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
2429     VARNOT(I1,-1,I4,0);
2430     VARNOT(I1,0,I4,-1);
2431     VARNOT(I2,-1,I2,0);
2432     VARNOT(I2,0,I2,-1);
2433     VARNOT(I2,1,I2,-2);
2434     VARNOT(I4,1,I4,-2);
2435     VARNOT(I4,0,I4,-1);
2436     VARNOT(UI1,1,UI1,254);
2437     VARNOT(UI1,0,UI1,255);
2438     VARNOT(UI2,0,I4,-1);
2439     VARNOT(UI2,1,I4,-2);
2440     VARNOT(UI4,0,I4,-1);
2441     VARNOT(UI4,1,I4,-2);
2442     VARNOT(INT,0,I4,-1);
2443     VARNOT(INT,1,I4,-2);
2444     VARNOT(UINT,0,I4,-1);
2445     VARNOT(UINT,1,I4,-2);
2446     if (has_i8)
2447     {
2448         VARNOT(I8,1,I8,-2);
2449         VARNOT(I8,0,I8,-1);
2450         VARNOT(UI8,0,I4,-1);
2451         VARNOT(UI8,1,I4,-2);
2452     }
2453     VARNOT(R4,1,I4,-2);
2454     VARNOT(R4,0,I4,-1);
2455     VARNOT(R8,1,I4,-2);
2456     VARNOT(R8,0,I4,-1);
2457     VARNOT(DATE,1,I4,-2);
2458     VARNOT(DATE,0,I4,-1);
2459     VARNOT(BSTR,(BSTR)szNum0,I4,-1);
2460     ok(V_VT(&v) == VT_BSTR && V_BSTR(&v) == szNum0, "VarNot(0): changed input\n");
2461     VARNOT(BSTR,(BSTR)szNum1,I4,-2);
2462     ok(V_VT(&v) == VT_BSTR && V_BSTR(&v) == szNum1, "VarNot(1): changed input\n");
2463     VARNOT(BSTR, (BSTR)szTrue, BOOL, VARIANT_FALSE);
2464     VARNOT(BSTR, (BSTR)szFalse, BOOL, VARIANT_TRUE);
2465 
2466     S(U(*pdec)).sign = DECIMAL_NEG;
2467     S(U(*pdec)).scale = 0;
2468     pdec->Hi32 = 0;
2469     S1(U1(*pdec)).Mid32 = 0;
2470     S1(U1(*pdec)).Lo32 = 1;
2471     VARNOT(DECIMAL,*pdec,I4,0);
2472 
2473     pcy->int64 = 10000;
2474     VARNOT(CY,*pcy,I4,-2);
2475 
2476     pcy->int64 = 0;
2477     VARNOT(CY,*pcy,I4,-1);
2478 
2479     pcy->int64 = -1;
2480     VARNOT(CY,*pcy,I4,-1);
2481 }
2482 
2483 static HRESULT (WINAPI *pVarSub)(LPVARIANT,LPVARIANT,LPVARIANT);
2484 
2485 #define VARSUB(vt1,val1,vt2,val2,rvt,rval)               \
2486         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
2487         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
2488         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
2489         test_var_call2( __LINE__, pVarSub, &left, &right, &exp )
2490 
2491 static void test_VarSub(void)
2492 {
2493     VARIANT left, right, exp, result, cy, dec;
2494     VARTYPE i;
2495     BSTR lbstr, rbstr;
2496     HRESULT hres, expectedhres;
2497     double r;
2498 
2499     CHECKPTR(VarSub);
2500 
2501     lbstr = SysAllocString(sz12);
2502     rbstr = SysAllocString(sz12);
2503 
2504     VariantInit(&left);
2505     VariantInit(&right);
2506     VariantInit(&result);
2507 
2508     /* Test all possible flag/vt combinations & the resulting vt type */
2509     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2510     {
2511 
2512         VARTYPE leftvt, rightvt, resvt;
2513 
2514         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
2515         {
2516 
2517             SKIPTESTS(leftvt);
2518 
2519             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
2520             {
2521 
2522                 SKIPTESTS(rightvt);
2523                 expectedhres = S_OK;
2524 
2525                 memset(&left, 0, sizeof(left));
2526                 memset(&right, 0, sizeof(right));
2527                 V_VT(&left) = leftvt | ExtraFlags[i];
2528                 if (leftvt == VT_BSTR)
2529                     V_BSTR(&left) = lbstr;
2530                 V_VT(&right) = rightvt | ExtraFlags[i];
2531                 if (rightvt == VT_BSTR)
2532                     V_BSTR(&right) = rbstr;
2533                 V_VT(&result) = VT_EMPTY;
2534 
2535                 /* All extra flags produce errors */
2536                 if (ExtraFlags[i] == (VT_VECTOR|VT_BYREF|VT_RESERVED) ||
2537                     ExtraFlags[i] == (VT_VECTOR|VT_RESERVED) ||
2538                     ExtraFlags[i] == (VT_VECTOR|VT_BYREF) ||
2539                     ExtraFlags[i] == (VT_BYREF|VT_RESERVED) ||
2540                     ExtraFlags[i] == VT_VECTOR ||
2541                     ExtraFlags[i] == VT_BYREF ||
2542                     ExtraFlags[i] == VT_RESERVED)
2543                 {
2544                     expectedhres = DISP_E_BADVARTYPE;
2545                     resvt = VT_EMPTY;
2546                 }
2547                 else if (ExtraFlags[i] >= VT_ARRAY)
2548                 {
2549                     expectedhres = DISP_E_TYPEMISMATCH;
2550                     resvt = VT_EMPTY;
2551                 }
2552                 /* Native VarSub cannot handle: VT_I1, VT_UI2, VT_UI4,
2553                    VT_INT, VT_UINT and VT_UI8. Tested with WinXP */
2554                 else if (!IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
2555                     !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
2556                     leftvt == VT_CLSID || rightvt == VT_CLSID ||
2557                     leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
2558                     leftvt == VT_I1 || rightvt == VT_I1 ||
2559                     leftvt == VT_UI2 || rightvt == VT_UI2 ||
2560                     leftvt == VT_UI4 || rightvt == VT_UI4 ||
2561                     leftvt == VT_UI8 || rightvt == VT_UI8 ||
2562                     leftvt == VT_INT || rightvt == VT_INT ||
2563                     leftvt == VT_UINT || rightvt == VT_UINT ||
2564                     leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN ||
2565                     leftvt == VT_RECORD || rightvt == VT_RECORD)
2566                 {
2567                     if (leftvt == VT_RECORD && rightvt == VT_I8)
2568                     {
2569                         if (has_i8)
2570                             expectedhres = DISP_E_TYPEMISMATCH;
2571                         else
2572                             expectedhres = DISP_E_BADVARTYPE;
2573                     }
2574                     else if (leftvt < VT_UI1 && rightvt == VT_RECORD)
2575                         expectedhres = DISP_E_TYPEMISMATCH;
2576                     else if (leftvt >= VT_UI1 && rightvt == VT_RECORD)
2577                         expectedhres = DISP_E_TYPEMISMATCH;
2578                     else if (leftvt == VT_RECORD && rightvt <= VT_UI1)
2579                         expectedhres = DISP_E_TYPEMISMATCH;
2580                     else if (leftvt == VT_RECORD && rightvt > VT_UI1)
2581                         expectedhres = DISP_E_BADVARTYPE;
2582                     else
2583                         expectedhres = DISP_E_BADVARTYPE;
2584                     resvt = VT_EMPTY;
2585                 }
2586                 else if ((leftvt == VT_NULL && rightvt == VT_DISPATCH) ||
2587                     (leftvt == VT_DISPATCH && rightvt == VT_NULL))
2588                     resvt = VT_NULL;
2589                 else if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
2590                     leftvt == VT_ERROR || rightvt == VT_ERROR)
2591                 {
2592                     resvt = VT_EMPTY;
2593                     expectedhres = DISP_E_TYPEMISMATCH;
2594                 }
2595                 else if (leftvt == VT_NULL || rightvt == VT_NULL)
2596                     resvt = VT_NULL;
2597                 else if ((leftvt == VT_EMPTY && rightvt == VT_BSTR) ||
2598                     (leftvt == VT_DATE && rightvt == VT_DATE) ||
2599                     (leftvt == VT_BSTR && rightvt == VT_EMPTY) ||
2600                     (leftvt == VT_BSTR && rightvt == VT_BSTR))
2601                     resvt = VT_R8;
2602                 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
2603                     resvt = VT_DECIMAL;
2604                 else if (leftvt == VT_DATE || rightvt == VT_DATE)
2605                     resvt = VT_DATE;
2606                 else if (leftvt == VT_CY || rightvt == VT_CY)
2607                     resvt = VT_CY;
2608                 else if (leftvt == VT_R8 || rightvt == VT_R8)
2609                     resvt = VT_R8;
2610                 else if (leftvt == VT_BSTR || rightvt == VT_BSTR) {
2611                     resvt = VT_R8;
2612                 } else if (leftvt == VT_R4 || rightvt == VT_R4) {
2613                     if (leftvt == VT_I4 || rightvt == VT_I4 ||
2614                         leftvt == VT_I8 || rightvt == VT_I8)
2615                         resvt = VT_R8;
2616                     else
2617                         resvt = VT_R4;
2618                 }
2619                 else if (leftvt == VT_I8 || rightvt == VT_I8)
2620                     resvt = VT_I8;
2621                 else if (leftvt == VT_I4 || rightvt == VT_I4)
2622                     resvt = VT_I4;
2623                 else if (leftvt == VT_I2 || rightvt == VT_I2 ||
2624                     leftvt == VT_BOOL || rightvt == VT_BOOL ||
2625                     (leftvt == VT_EMPTY && rightvt == VT_EMPTY))
2626                     resvt = VT_I2;
2627                 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
2628                     resvt = VT_UI1;
2629                 else
2630                 {
2631                     resvt = VT_EMPTY;
2632                     expectedhres = DISP_E_TYPEMISMATCH;
2633                 }
2634 
2635                 hres = pVarSub(&left, &right, &result);
2636 
2637                 ok(hres == expectedhres && V_VT(&result) == resvt,
2638                     "VarSub: %d|0x%X, %d|0x%X: Expected failure 0x%X, "
2639                     "got 0x%X, expected vt %d got vt %d\n",
2640                     leftvt, ExtraFlags[i], rightvt, ExtraFlags[i],
2641                     expectedhres, hres, resvt, V_VT(&result));
2642             }
2643         }
2644     }
2645 
2646     /* Test returned values */
2647     VARSUB(I4,4,I4,2,I4,2);
2648     VARSUB(I2,4,I2,2,I2,2);
2649     VARSUB(I2,-13,I4,5,I4,-18);
2650     VARSUB(I4,-13,I4,5,I4,-18);
2651     VARSUB(I2,7,R4,0.5f,R4,6.5f);
2652     VARSUB(R4,0.5f,I4,5,R8,-4.5);
2653     VARSUB(R8,7.1,BOOL,0,R8,7.1);
2654     VARSUB(BSTR,lbstr,I2,4,R8,8);
2655     VARSUB(BSTR,lbstr,BOOL,1,R8,11);
2656     VARSUB(BSTR,lbstr,R4,0.1f,R8,11.9);
2657     VARSUB(R4,0.2f,BSTR,rbstr,R8,-11.8);
2658     VARSUB(DATE,2.25,I4,7,DATE,-4.75);
2659     VARSUB(DATE,1.25,R4,-1.7f,DATE,2.95);
2660 
2661     VARSUB(UI1, UI1_MAX, UI1, UI1_MAX, UI1, 0);
2662     VARSUB(I2, I2_MAX, I2, I2_MAX, I2, 0);
2663     VARSUB(I2, I2_MIN, I2, I2_MIN, I2, 0);
2664     VARSUB(I4, I4_MAX, I4, I4_MAX, I4, 0);
2665     VARSUB(I4, I4_MIN, I4, I4_MIN, I4, 0);
2666     VARSUB(R4, R4_MAX, R4, R4_MAX, R4, 0.0f);
2667     VARSUB(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX - R4_MIN);
2668     VARSUB(R4, R4_MIN, R4, R4_MIN, R4, 0.0f);
2669     VARSUB(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX - R8_MIN);
2670     VARSUB(R8, R8_MIN, R8, R8_MIN, R8, 0.0);
2671 
2672     /* Manually test BSTR + BSTR */
2673     V_VT(&left) = VT_BSTR;
2674     V_BSTR(&left) = lbstr;
2675     V_VT(&right) = VT_BSTR;
2676     V_BSTR(&right) = rbstr;
2677     hres = pVarSub(&left, &right, &result);
2678     ok(hres == S_OK && V_VT(&result) == VT_R8,
2679         "VarSub: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
2680     ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 0.0),
2681         "VarSub: BSTR + BSTR, expected %f got %f\n", 0.0, V_R8(&result));
2682 
2683     /* Manually test some VT_CY and VT_DECIMAL variants */
2684     V_VT(&cy) = VT_CY;
2685     hres = VarCyFromI4(4711, &V_CY(&cy));
2686     ok(hres == S_OK, "VarCyFromI4 failed!\n");
2687     V_VT(&dec) = VT_DECIMAL;
2688     hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec));
2689     ok(hres == S_OK, "VarDecFromR4 failed!\n");
2690     memset(&left, 0, sizeof(left));
2691     memset(&right, 0, sizeof(right));
2692     V_VT(&left) = VT_I4;
2693     V_I4(&left) = -11;
2694     V_VT(&right) = VT_UI1;
2695     V_UI1(&right) = 9;
2696 
2697     hres = pVarSub(&cy, &right, &result);
2698     ok(hres == S_OK && V_VT(&result) == VT_CY,
2699         "VarSub: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result)));
2700     hres = VarR8FromCy(V_CY(&result), &r);
2701     ok(hres == S_OK && EQ_DOUBLE(r, 4702.0),
2702         "VarSub: CY value %f, expected %f\n", r, (double)4720);
2703 
2704     hres = pVarSub(&left, &dec, &result);
2705     ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
2706         "VarSub: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
2707     hres = VarR8FromDec(&V_DECIMAL(&result), &r);
2708     ok(hres == S_OK && EQ_DOUBLE(r, -6.8),
2709         "VarSub: DECIMAL value %f, expected %f\n", r, (double)-15.2);
2710 
2711     SysFreeString(lbstr);
2712     SysFreeString(rbstr);
2713 }
2714 
2715 static HRESULT (WINAPI *pVarMod)(LPVARIANT,LPVARIANT,LPVARIANT);
2716 
2717 static void test_Mod( int line, VARIANT *left, VARIANT *right, VARIANT *expected, HRESULT expres )
2718 {
2719     VARIANT result;
2720     HRESULT hres;
2721 
2722     memset( &result, 0, sizeof(result) );
2723     hres = pVarMod( left, right, &result );
2724     ok_(__FILE__,line)( hres == expres, "wrong result %x/%x\n", hres, expres );
2725     if (hres == S_OK)
2726         ok_(__FILE__,line)( is_expected_variant( &result, expected ),
2727                             "got %s expected %s\n", variantstr(&result), variantstr(expected) );
2728 }
2729 
2730 #define VARMOD(vt1,vt2,val1,val2,rvt,rval)               \
2731         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
2732         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
2733         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
2734         test_var_call2( __LINE__, pVarMod, &left, &right, &exp )
2735 
2736 #define VARMOD2(vt1,vt2,val1,val2,rvt,rval,hexpected)         \
2737         V_VT(&left) = VT_##vt1; V_I4(&left) = val1;           \
2738         V_VT(&right) = VT_##vt2; V_I4(&right) = val2;         \
2739         V_VT(&exp) = VT_##rvt; V_I4(&exp) = rval;             \
2740         test_Mod( __LINE__, &left, &right, &exp, hexpected )
2741 
2742 static void test_VarMod(void)
2743 {
2744   VARIANT v1, v2, vDst, left, right, exp;
2745   HRESULT hres;
2746   HRESULT hexpected = 0;
2747   static const WCHAR szNum0[] = {'1','2','5','\0'};
2748   static const WCHAR szNum1[] = {'1','0','\0'};
2749   int l, r;
2750   BOOL lFound, rFound;
2751   BOOL lValid;
2752   BSTR strNum0, strNum1;
2753 
2754   CHECKPTR(VarMod);
2755 
2756   VARMOD(I1,BOOL,100,10,I4,0);
2757   VARMOD(I1,I1,100,10,I4,0);
2758   VARMOD(I1,UI1,100,10,I4,0);
2759   VARMOD(I1,I2,100,10,I4,0);
2760   VARMOD(I1,UI2,100,10,I4,0);
2761   VARMOD(I1,I4,100,10,I4,0);
2762   VARMOD(I1,UI4,100,10,I4,0);
2763   VARMOD(I1,R4,100,10,I4,0);
2764   VARMOD(I1,R8,100,10,I4,0);
2765 
2766   VARMOD(UI1,BOOL,100,10,I2,0);
2767   VARMOD(UI1,I1,100,10,I4,0);
2768   VARMOD(UI1,UI1,100,10,UI1,0);
2769   VARMOD(UI1,I2,100,10,I2,0);
2770   VARMOD(UI1,UI2,100,10,I4,0);
2771   VARMOD(UI1,I4,100,10,I4,0);
2772   VARMOD(UI1,UI4,100,10,I4,0);
2773   VARMOD(UI1,R4,100,10,I4,0);
2774   VARMOD(UI1,R8,100,10,I4,0);
2775 
2776   VARMOD(I2,BOOL,100,10,I2,0);
2777   VARMOD(I2,I1,100,10,I4,0);
2778   VARMOD(I2,UI1,100,10,I2,0);
2779   VARMOD(I2,I2,100,10,I2,0);
2780   VARMOD(I2,UI2,100,10,I4,0);
2781   VARMOD(I2,I4,100,10,I4,0);
2782   VARMOD(I2,UI4,100,10,I4,0);
2783   VARMOD(I2,R4,100,10,I4,0);
2784   VARMOD(I2,R8,100,10,I4,0);
2785 
2786   VARMOD(I4,BOOL,100,10,I4,0);
2787   VARMOD(I4,I1,100,10,I4,0);
2788   VARMOD(I4,UI1,100,10,I4,0);
2789   VARMOD(I4,I2,100,10,I4,0);
2790   VARMOD(I4,UI2,100,10,I4,0);
2791   VARMOD(I4,I4,100,10,I4,0);
2792   VARMOD(I4,UI4,100,10,I4,0);
2793   VARMOD(I4,R4,100,10,I4,0);
2794   VARMOD(I4,R8,100,10,I4,0);
2795   VARMOD(UI4,BOOL,100,10,I4,0);
2796   VARMOD(UI4,I1,100,10,I4,0);
2797   VARMOD(UI4,UI1,100,10,I4,0);
2798   VARMOD(UI4,I2,100,10,I4,0);
2799   VARMOD(UI4,UI2,100,10,I4,0);
2800   VARMOD(UI4,I4,100,10,I4,0);
2801   VARMOD(UI4,UI4,100,10,I4,0);
2802   VARMOD(UI4,R4,100,10,I4,0);
2803   VARMOD(UI4,R8,100,10,I4,0);
2804   VARMOD(R4,BOOL,100,10,I4,0);
2805   VARMOD(R4,I1,100,10,I4,0);
2806   VARMOD(R4,UI1,100,10,I4,0);
2807   VARMOD(R4,I2,100,10,I4,0);
2808   VARMOD(R4,UI2,100,10,I4,0);
2809   VARMOD(R4,I4,100,10,I4,0);
2810   VARMOD(R4,UI4,100,10,I4,0);
2811   VARMOD(R4,R4,100,10,I4,0);
2812   VARMOD(R4,R8,100,10,I4,0);
2813   VARMOD(R8,BOOL,100,10,I4,0);
2814   VARMOD(R8,I1,100,10,I4,0);
2815   VARMOD(R8,UI1,100,10,I4,0);
2816   VARMOD(R8,I2,100,10,I4,0);
2817   VARMOD(R8,UI2,100,10,I4,0);
2818   VARMOD(R8,I4,100,10,I4,0);
2819   VARMOD(R8,UI4,100,10,I4,0);
2820   VARMOD(R8,R4,100,10,I4,0);
2821   VARMOD(R8,R8,100,10,I4,0);
2822 
2823   VARMOD(INT,INT,100,10,I4,0);
2824   VARMOD(INT,UINT,100,10,I4,0);
2825 
2826   VARMOD(BOOL,BOOL,100,10,I2,0);
2827   VARMOD(BOOL,I1,100,10,I4,0);
2828   VARMOD(BOOL,UI1,100,10,I2,0);
2829   VARMOD(BOOL,I2,100,10,I2,0);
2830   VARMOD(BOOL,UI2,100,10,I4,0);
2831   VARMOD(BOOL,I4,100,10,I4,0);
2832   VARMOD(BOOL,UI4,100,10,I4,0);
2833   VARMOD(BOOL,R4,100,10,I4,0);
2834   VARMOD(BOOL,R8,100,10,I4,0);
2835   VARMOD(BOOL,DATE,100,10,I4,0);
2836 
2837   VARMOD(DATE,BOOL,100,10,I4,0);
2838   VARMOD(DATE,I1,100,10,I4,0);
2839   VARMOD(DATE,UI1,100,10,I4,0);
2840   VARMOD(DATE,I2,100,10,I4,0);
2841   VARMOD(DATE,UI2,100,10,I4,0);
2842   VARMOD(DATE,I4,100,10,I4,0);
2843   VARMOD(DATE,UI4,100,10,I4,0);
2844   VARMOD(DATE,R4,100,10,I4,0);
2845   VARMOD(DATE,R8,100,10,I4,0);
2846   VARMOD(DATE,DATE,100,10,I4,0);
2847 
2848   strNum0 = SysAllocString(szNum0);
2849   strNum1 = SysAllocString(szNum1);
2850   VARMOD(BSTR,BSTR,strNum0,strNum1,I4,5);
2851   VARMOD(BSTR,I1,strNum0,10,I4,5);
2852   VARMOD(BSTR,I2,strNum0,10,I4,5);
2853   VARMOD(BSTR,I4,strNum0,10,I4,5);
2854   VARMOD(BSTR,R4,strNum0,10,I4,5);
2855   VARMOD(BSTR,R8,strNum0,10,I4,5);
2856   VARMOD(I4,BSTR,125,strNum1,I4,5);
2857 
2858   if (has_i8)
2859   {
2860     VARMOD(BOOL,I8,100,10,I8,0);
2861     VARMOD(I1,I8,100,10,I8,0);
2862     VARMOD(UI1,I8,100,10,I8,0);
2863     VARMOD(I2,I8,100,10,I8,0);
2864     VARMOD(I4,I8,100,10,I8,0);
2865     VARMOD(UI4,I8,100,10,I8,0);
2866     VARMOD(R4,I8,100,10,I8,0);
2867     VARMOD(R8,I8,100,10,I8,0);
2868     VARMOD(DATE,I8,100,10,I8,0);
2869 
2870     VARMOD(I8,BOOL,100,10,I8,0);
2871     VARMOD(I8,I1,100,10,I8,0);
2872     VARMOD(I8,UI1,100,10,I8,0);
2873     VARMOD(I8,I2,100,10,I8,0);
2874     VARMOD(I8,UI2,100,10,I8,0);
2875     VARMOD(I8,I4,100,10,I8,0);
2876     VARMOD(I8,UI4,100,10,I8,0);
2877     VARMOD(I8,R4,100,10,I8,0);
2878     VARMOD(I8,R8,100,10,I8,0);
2879     VARMOD(I8,I8,100,10,I8,0);
2880 
2881     VARMOD(BSTR,I8,strNum0,10,I8,5);
2882   }
2883 
2884   /* test all combinations of types */
2885   for(l = 0; l < VT_BSTR_BLOB; l++)
2886   {
2887     SKIPTESTS(l);
2888 
2889     for(r = 0; r < VT_BSTR_BLOB; r++)
2890     {
2891       SKIPTESTS(r);
2892 
2893       if(l == VT_BSTR) continue;
2894       if(l == VT_DISPATCH) continue;
2895       if(r == VT_BSTR) continue;
2896       if(r == VT_DISPATCH) continue;
2897 
2898       lFound = TRUE;
2899       lValid = TRUE;
2900       switch(l)
2901 	{
2902 	case VT_EMPTY:
2903 	case VT_NULL:
2904 	case VT_I1:
2905 	case VT_UI1:
2906 	case VT_I2:
2907 	case VT_UI2:
2908 	case VT_I4:
2909 	case VT_I8:
2910 	case VT_UI4:
2911 	case VT_UI8:
2912 	case VT_INT:
2913 	case VT_UINT:
2914 	case VT_R4:
2915 	case VT_R8:
2916 	case VT_BOOL:
2917 	case VT_DATE:
2918 	case VT_CY:
2919 	case VT_DECIMAL:
2920 	  hexpected = S_OK;
2921 	  break;
2922 	case VT_ERROR:
2923 	case VT_VARIANT:
2924 	case VT_UNKNOWN:
2925 	case VT_RECORD:
2926 	  lValid = FALSE;
2927 	  break;
2928 	default:
2929 	  lFound = FALSE;
2930 	  hexpected = DISP_E_BADVARTYPE;
2931 	  break;
2932 	}
2933 
2934       rFound = TRUE;
2935       switch(r)
2936 	{
2937 	case VT_EMPTY:
2938 	case VT_NULL:
2939 	case VT_I1:
2940 	case VT_UI1:
2941 	case VT_I2:
2942 	case VT_UI2:
2943 	case VT_I4:
2944 	case VT_I8:
2945 	case VT_UI4:
2946 	case VT_UI8:
2947 	case VT_INT:
2948 	case VT_UINT:
2949 	case VT_R4:
2950 	case VT_R8:
2951 	case VT_BOOL:
2952 	case VT_DATE:
2953 	case VT_DECIMAL:
2954 	case VT_CY:
2955 	  hexpected = S_OK;
2956 	  break;
2957 	case VT_ERROR:
2958 	case VT_VARIANT:
2959 	case VT_UNKNOWN:
2960 	case VT_RECORD:
2961 	  break;
2962 	default:
2963 	  rFound = FALSE;
2964 	  break;
2965 	}
2966 
2967       if(((l == VT_I8) && (r == VT_INT)) || ((l == VT_INT) && (r == VT_I8)))
2968       {
2969 	hexpected = DISP_E_TYPEMISMATCH;
2970       } else if((l == VT_EMPTY) && (r == VT_NULL))
2971       {
2972 	hexpected = S_OK;
2973       } else if((l == VT_NULL) && (r == VT_EMPTY))
2974       {
2975 	hexpected = S_OK;
2976       } else if((l == VT_EMPTY) && (r == VT_CY))
2977       {
2978 	hexpected = S_OK;
2979       } else if((l == VT_EMPTY) && (r == VT_RECORD))
2980       {
2981 	hexpected = DISP_E_TYPEMISMATCH;
2982       } else if((r == VT_EMPTY) && lFound && lValid)
2983       {
2984 	hexpected = DISP_E_DIVBYZERO;
2985       } else if((l == VT_ERROR) || ((r == VT_ERROR) && lFound && lValid))
2986       {
2987 	hexpected = DISP_E_TYPEMISMATCH;
2988       } else if((l == VT_NULL) && (r == VT_NULL))
2989       {
2990 	hexpected = S_OK;
2991       } else if((l == VT_VARIANT) || ((r == VT_VARIANT) && lFound && lValid))
2992       {
2993 	hexpected = DISP_E_TYPEMISMATCH;
2994       } else if((l == VT_NULL) && (r == VT_RECORD))
2995       {
2996 	hexpected = DISP_E_TYPEMISMATCH;
2997       } else if((l == VT_I8) && (r == VT_DECIMAL))
2998       {
2999 	hexpected = S_OK;
3000       } else if((l == VT_DECIMAL) && (r == VT_I8))
3001       {
3002 	hexpected = S_OK;
3003       } else if((l == VT_UNKNOWN) || ((r == VT_UNKNOWN) && lFound && lValid))
3004       {
3005 	hexpected = DISP_E_TYPEMISMATCH;
3006       } else if((l == VT_NULL) && rFound)
3007       {
3008 	hexpected = S_OK;
3009       } else if(l == VT_RECORD)
3010       {
3011 	hexpected = DISP_E_TYPEMISMATCH;
3012       } else if((r == VT_RECORD) && lValid && lFound)
3013       {
3014 	hexpected = DISP_E_TYPEMISMATCH;
3015       } else if((l == VT_EMPTY) && (r == VT_EMPTY))
3016       {
3017 	hexpected = DISP_E_DIVBYZERO;
3018       } else if((l == VT_CY) && !rFound)
3019       {
3020 	hexpected = DISP_E_BADVARTYPE;
3021       } else if(lFound && !rFound)
3022       {
3023 	hexpected = DISP_E_BADVARTYPE;
3024       } else if(!lFound && rFound)
3025       {
3026 	hexpected = DISP_E_BADVARTYPE;
3027       } else if((r == VT_NULL) && lFound && lValid)
3028       {
3029 	hexpected = S_OK;
3030       } else if((l == VT_NULL) || (r == VT_NULL))
3031       {
3032 	hexpected = DISP_E_BADVARTYPE;
3033       } else if((l == VT_VARIANT) || (r == VT_VARIANT))
3034       {
3035 	hexpected = DISP_E_BADVARTYPE;
3036       } else if(!lFound && !rFound)
3037       {
3038 	hexpected = DISP_E_BADVARTYPE;
3039       }
3040 
3041       V_VT(&v1) = l;
3042       V_VT(&v2) = r;
3043 
3044       if(l == VT_CY)
3045 	V_CY(&v1).int64 = 1000000;
3046       else if(l == VT_R4)
3047 	V_R4(&v1) = 100;
3048       else if(l == VT_R8)
3049 	V_R8(&v1) = 100;
3050       else if(l == VT_UI8)
3051 	V_UI8(&v1) = 100;
3052       else if(l == VT_I8)
3053 	V_I8(&v1) = 100;
3054       else if(l == VT_DATE)
3055 	V_DATE(&v1) = 1000;
3056       else if (l == VT_DECIMAL)
3057       {
3058 	V_DECIMAL(&v1).Hi32 = 0;
3059 	U1(V_DECIMAL(&v1)).Lo64 = 100;
3060 	U(V_DECIMAL(&v1)).signscale = 0;
3061       }
3062       else
3063 	V_I4(&v1) = 10000;
3064 
3065       if(r == VT_CY)
3066 	V_CY(&v2).int64 = 10000;
3067       else if(r == VT_R4)
3068 	V_R4(&v2) = 100;
3069       else if(r == VT_R8)
3070 	V_R8(&v2) = 100;
3071       else if(r == VT_UI8)
3072 	V_UI8(&v2) = 100;
3073       else if(r == VT_I8)
3074 	V_I8(&v2) = 100;
3075       else if(r == VT_DATE)
3076 	V_DATE(&v2) = 1000;
3077       else if (r == VT_DECIMAL)
3078       {
3079 	V_DECIMAL(&v2).Hi32 = 0;
3080 	U1(V_DECIMAL(&v2)).Lo64 = 100;
3081 	U(V_DECIMAL(&v2)).signscale = 0;
3082       }
3083       else
3084 	V_I4(&v2) = 10000;
3085 
3086       if ((l != VT_I8 && l != VT_UI8 && r != VT_I8 && r != VT_UI8) || has_i8)
3087       {
3088         hres = pVarMod(&v1,&v2,&vDst);
3089         ok(hres == hexpected,
3090            "VarMod: expected 0x%x, got 0x%X for l type of %d, r type of %d,\n", hexpected, hres, l, r);
3091       }
3092     }
3093   }
3094 
3095 
3096   /****************************/
3097   /* test some bad parameters */
3098   VARMOD(I4,I4,-1,-1,I4,0);
3099 
3100   /* test modulus with zero */
3101   VARMOD2(I4,I4,100,0,EMPTY,0,DISP_E_DIVBYZERO);
3102 
3103   VARMOD(I4,I4,0,10,I4,0); /* test 0 mod 10 */
3104 
3105   /* right parameter is type empty */
3106   VARMOD2(I4,EMPTY,100,10,EMPTY,0,DISP_E_DIVBYZERO);
3107 
3108   /* left parameter is type empty */
3109   VARMOD2(EMPTY,I4,100,10,I4,0,S_OK);
3110 
3111   /* mod with a null left value */
3112   VARMOD2(NULL,I4,125,10,NULL,0,S_OK);
3113 
3114   /* mod with a null right value */
3115   VARMOD2(I4,NULL,100,10,NULL,0,S_OK);
3116 
3117   /* void left value */
3118   VARMOD2(VOID,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3119 
3120   /* void right value */
3121   VARMOD2(I4,VOID,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3122 
3123   /* null left value, void right value */
3124   VARMOD2(NULL,VOID,100,10,EMPTY, 0, DISP_E_BADVARTYPE);
3125 
3126   /* void left value, null right value */
3127   VARMOD2(VOID,NULL,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3128 
3129   /* some currencies */
3130   V_VT(&v1) = VT_CY;
3131   V_VT(&v2) = VT_CY;
3132   V_CY(&v1).int64 = 100000;
3133   V_CY(&v2).int64 = 100000;
3134   hres = pVarMod(&v1,&v2,&vDst);
3135   ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
3136      "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
3137 
3138   V_VT(&v1) = VT_I4;
3139   V_VT(&v2) = VT_CY;
3140   V_I4(&v1) = 100;
3141   V_CY(&v2).int64 = 100000;
3142   hres = pVarMod(&v1,&v2,&vDst);
3143   ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
3144      "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
3145 
3146   /* some decimals */
3147   V_VT(&v1) = VT_DECIMAL;
3148   V_VT(&v2) = VT_DECIMAL;
3149   VarDecFromI4(100, &V_DECIMAL(&v1));
3150   VarDecFromI4(10, &V_DECIMAL(&v2));
3151   hres = pVarMod(&v1,&v2,&vDst);
3152   ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
3153      "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
3154 
3155   V_VT(&v1) = VT_I4;
3156   V_VT(&v2) = VT_DECIMAL;
3157   V_I4(&v1) = 100;
3158   VarDecFromI4(10, &V_DECIMAL(&v2));
3159   hres = pVarMod(&v1,&v2,&vDst);
3160   ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
3161      "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
3162 
3163   VARMOD2(UINT,I4,100,10,I4,0,S_OK);
3164 
3165   /* test that an error results in the type of the result changing but not its value */
3166   V_VT(&v1) = VT_UNKNOWN;
3167   V_VT(&v2) = VT_EMPTY;
3168   V_I4(&v1) = 100;
3169   V_CY(&v2).int64 = 100000;
3170   V_VT(&vDst) = VT_I4;
3171   V_I4(&vDst) = 1231;
3172   hres = pVarMod(&v1,&v2,&vDst);
3173   ok(hres == DISP_E_TYPEMISMATCH && V_VT(&vDst) == VT_EMPTY && V_I4(&vDst) == 1231,
3174      "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));
3175 
3176 
3177   /* test some invalid types */
3178   /*TODO: not testing VT_DISPATCH */
3179   if (has_i8)
3180   {
3181     VARMOD2(I8,INT,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
3182   }
3183   VARMOD2(ERROR,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
3184   VARMOD2(VARIANT,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
3185   VARMOD2(UNKNOWN,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
3186   VARMOD2(VOID,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3187   VARMOD2(HRESULT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3188   VARMOD2(PTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3189   VARMOD2(SAFEARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3190   VARMOD2(CARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3191   VARMOD2(USERDEFINED,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3192   VARMOD2(LPSTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3193   VARMOD2(LPWSTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3194   VARMOD2(RECORD,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
3195   VARMOD2(FILETIME,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3196   VARMOD2(BLOB,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3197   VARMOD2(STREAM,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3198   VARMOD2(STORAGE,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3199   VARMOD2(STREAMED_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3200   VARMOD2(STORED_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3201   VARMOD2(BLOB_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3202   VARMOD2(CF,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3203   VARMOD2(CLSID,CLSID,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3204   VARMOD2(VECTOR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3205   VARMOD2(ARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3206   VARMOD2(BYREF,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
3207 
3208   /* test some more invalid types */
3209   V_VT(&v1) = 456;
3210   V_VT(&v2) = 234;
3211   V_I4(&v1) = 100;
3212   V_I4(&v2)=  10;
3213   hres = pVarMod(&v1,&v2,&vDst);
3214   ok(hres == DISP_E_BADVARTYPE && V_VT(&vDst) == VT_EMPTY,
3215      "VarMod: expected 0x%x,%d, got 0x%X,%d\n", DISP_E_BADVARTYPE, VT_EMPTY, hres, V_VT(&vDst));
3216 
3217   SysFreeString(strNum0);
3218   SysFreeString(strNum1);
3219 }
3220 
3221 static HRESULT (WINAPI *pVarFix)(LPVARIANT,LPVARIANT);
3222 
3223 #define VARFIX(vt,val,rvt,rval)                  \
3224     V_VT(&v) = VT_##vt; V_##vt(&v) = val;        \
3225     V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
3226     test_var_call1( __LINE__, pVarFix, &v, &exp )
3227 
3228 static void test_VarFix(void)
3229 {
3230     static const WCHAR szNumMinus1[] = {'-','1','\0' };
3231     HRESULT hres;
3232     VARIANT v, exp, vDst;
3233     DECIMAL *pdec = &V_DECIMAL(&v);
3234     CY *pcy = &V_CY(&v);
3235     size_t i;
3236 
3237     CHECKPTR(VarFix);
3238 
3239     /* Test all possible V_VT values */
3240     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
3241     {
3242         VARTYPE vt;
3243 
3244         for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
3245         {
3246             BOOL bFail = TRUE;
3247 
3248             SKIPTESTS(vt);
3249 
3250             memset(&v, 0, sizeof(v));
3251             V_VT(&v) = vt | ExtraFlags[i];
3252             V_VT(&vDst) = VT_EMPTY;
3253 
3254             switch (V_VT(&v))
3255             {
3256               case VT_UI1: case VT_I2: case VT_I4: case VT_R4:  case VT_R8:
3257               case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
3258               case VT_DATE: case VT_CY:
3259                 bFail = FALSE;
3260                 break;
3261               case VT_I8:
3262                 if (has_i8)
3263                   bFail = FALSE;
3264                 break;
3265             }
3266 
3267             hres = pVarFix(&v,&vDst);
3268             if (bFail)
3269               ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3270                  "VarFix: expected failure, got 0x%X vt %d|0x%X\n",
3271                  hres, vt, ExtraFlags[i]);
3272             else
3273                  ok(hres == S_OK, "VarFix: expected S_OK, got 0x%X vt %d|0x%X\n",
3274                     hres, vt, ExtraFlags[i]);
3275         }
3276     }
3277 
3278     VARFIX(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE);
3279     VARFIX(BOOL,VARIANT_FALSE,I2,0);
3280     VARFIX(BOOL,1,I2,1);
3281     VARFIX(UI1,1,UI1,1);
3282     VARFIX(I2,-1,I2,-1);
3283     VARFIX(I4,-1,I4,-1);
3284     if (has_i8)
3285     {
3286         VARFIX(I8,-1,I8,-1);
3287     }
3288     VARFIX(R4,1.4f,R4,1);
3289     VARFIX(R4,1.5f,R4,1);
3290     VARFIX(R4,1.6f,R4,1);
3291     VARFIX(R4,-1.4f,R4,-1);
3292     VARFIX(R4,-1.5f,R4,-1);
3293     VARFIX(R4,-1.6f,R4,-1);
3294     /* DATE & R8 round as for R4 */
3295     VARFIX(DATE,-1,DATE,-1);
3296     VARFIX(R8,-1,R8,-1);
3297     VARFIX(BSTR,(BSTR)szNumMinus1,R8,-1);
3298 
3299     V_VT(&v) = VT_EMPTY;
3300     hres = pVarFix(&v,&vDst);
3301     ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
3302        "VarFix: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY,
3303        hres, V_VT(&vDst), V_I2(&vDst));
3304 
3305     V_VT(&v) = VT_NULL;
3306     hres = pVarFix(&v,&vDst);
3307     ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
3308        "VarFix: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst));
3309 
3310     V_VT(&v) = VT_DECIMAL;
3311     S(U(*pdec)).sign = DECIMAL_NEG;
3312     S(U(*pdec)).scale = 0;
3313     pdec->Hi32 = 0;
3314     S1(U1(*pdec)).Mid32 = 0;
3315     S1(U1(*pdec)).Lo32 = 1;
3316     hres = pVarFix(&v,&vDst);
3317     ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && !memcmp(&V_DECIMAL(&v), &V_DECIMAL(&vDst), sizeof(DECIMAL)),
3318        "VarFix: expected 0x0,%d,identical, got 0x%X,%d\n", VT_DECIMAL,
3319        hres, V_VT(&vDst));
3320 
3321     /* FIXME: Test some fractional decimals when VarDecFix is implemented */
3322 
3323     V_VT(&v) = VT_CY;
3324     pcy->int64 = -10000;
3325     hres = pVarFix(&v,&vDst);
3326     ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
3327        "VarFix: VT_CY wrong, hres=0x%X\n", hres);
3328 
3329     V_VT(&v) = VT_CY;
3330     pcy->int64 = -16000;
3331     hres = pVarFix(&v,&vDst);
3332     ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
3333        "VarFix: VT_CY wrong, hres=0x%X\n", hres);
3334 }
3335 
3336 static HRESULT (WINAPI *pVarInt)(LPVARIANT,LPVARIANT);
3337 
3338 #define VARINT(vt,val,rvt,rval)                  \
3339     V_VT(&v) = VT_##vt; V_##vt(&v) = val;        \
3340     V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
3341     test_var_call1( __LINE__, pVarInt, &v, &exp )
3342 
3343 static void test_VarInt(void)
3344 {
3345     static const WCHAR szNumMinus1[] = {'-','1','\0' };
3346     HRESULT hres;
3347     VARIANT v, exp, vDst;
3348     DECIMAL *pdec = &V_DECIMAL(&v);
3349     CY *pcy = &V_CY(&v);
3350     size_t i;
3351 
3352     CHECKPTR(VarInt);
3353 
3354     /* Test all possible V_VT values */
3355     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
3356     {
3357         VARTYPE vt;
3358 
3359         for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
3360         {
3361             BOOL bFail = TRUE;
3362 
3363             SKIPTESTS(vt);
3364 
3365             memset(&v, 0, sizeof(v));
3366             V_VT(&v) = vt | ExtraFlags[i];
3367             V_VT(&vDst) = VT_EMPTY;
3368 
3369             switch (V_VT(&v))
3370             {
3371               case VT_UI1: case VT_I2: case VT_I4: case VT_R4:  case VT_R8:
3372               case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
3373               case VT_DATE: case VT_CY:
3374                 bFail = FALSE;
3375                 break;
3376               case VT_I8:
3377                 if (has_i8)
3378                   bFail = FALSE;
3379                 break;
3380             }
3381 
3382             hres = pVarInt(&v,&vDst);
3383             if (bFail)
3384               ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3385                  "VarInt: expected failure, got 0x%X vt %d|0x%X\n",
3386                  hres, vt, ExtraFlags[i]);
3387             else
3388                  ok(hres == S_OK, "VarInt: expected S_OK, got 0x%X vt %d|0x%X\n",
3389                     hres, vt, ExtraFlags[i]);
3390         }
3391     }
3392 
3393     VARINT(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE);
3394     VARINT(BOOL,VARIANT_FALSE,I2,0);
3395     VARINT(BOOL,1,I2,1);
3396     VARINT(UI1,1,UI1,1);
3397     VARINT(I2,-1,I2,-1);
3398     VARINT(I4,-1,I4,-1);
3399     if (has_i8)
3400     {
3401         VARINT(I8,-1,I8,-1);
3402     }
3403     VARINT(R4,1.4f,R4,1);
3404     VARINT(R4,1.5f,R4,1);
3405     VARINT(R4,1.6f,R4,1);
3406     VARINT(R4,-1.4f,R4,-2); /* Note these 3 are different from VarFix */
3407     VARINT(R4,-1.5f,R4,-2);
3408     VARINT(R4,-1.6f,R4,-2);
3409     /* DATE & R8 round as for R4 */
3410     VARINT(DATE,-1,DATE,-1);
3411     VARINT(R8,-1,R8,-1);
3412     VARINT(BSTR,(BSTR)szNumMinus1,R8,-1);
3413 
3414     V_VT(&v) = VT_EMPTY;
3415     hres = pVarInt(&v,&vDst);
3416     ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
3417        "VarInt: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY,
3418        hres, V_VT(&vDst), V_I2(&vDst));
3419 
3420     V_VT(&v) = VT_NULL;
3421     hres = pVarInt(&v,&vDst);
3422     ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
3423        "VarInt: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst));
3424 
3425     V_VT(&v) = VT_DECIMAL;
3426     S(U(*pdec)).sign = DECIMAL_NEG;
3427     S(U(*pdec)).scale = 0;
3428     pdec->Hi32 = 0;
3429     S1(U1(*pdec)).Mid32 = 0;
3430     S1(U1(*pdec)).Lo32 = 1;
3431     hres = pVarInt(&v,&vDst);
3432     ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && !memcmp(&V_DECIMAL(&v), &V_DECIMAL(&vDst), sizeof(DECIMAL)),
3433        "VarInt: expected 0x0,%d,identical, got 0x%X,%d\n", VT_DECIMAL,
3434        hres, V_VT(&vDst));
3435 
3436     /* FIXME: Test some fractional decimals when VarDecInt is implemented */
3437 
3438     V_VT(&v) = VT_CY;
3439     pcy->int64 = -10000;
3440     hres = pVarInt(&v,&vDst);
3441     ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
3442        "VarInt: VT_CY wrong, hres=0x%X\n", hres);
3443 
3444     V_VT(&v) = VT_CY;
3445     pcy->int64 = -11000;
3446     hres = pVarInt(&v,&vDst);
3447     ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -20000,
3448        "VarInt: VT_CY wrong, hres=0x%X 0x%x%08x\n",
3449        hres, (DWORD)(V_CY(&vDst).int64 >> 32), (DWORD)V_CY(&vDst).int64);
3450 }
3451 
3452 static HRESULT (WINAPI *pVarNeg)(LPVARIANT,LPVARIANT);
3453 
3454 #define VARNEG(vt,val,rvt,rval)                  \
3455     V_VT(&v) = VT_##vt; V_##vt(&v) = val;        \
3456     V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
3457     test_var_call1( __LINE__, pVarNeg, &v, &exp )
3458 
3459 static void test_VarNeg(void)
3460 {
3461     static const WCHAR szNumMinus1[] = {'-','1','\0' };
3462     static const WCHAR szNum1[] = {'1','\0' };
3463     HRESULT hres;
3464     VARIANT v, exp, vDst;
3465     DECIMAL *pdec = &V_DECIMAL(&v);
3466     CY *pcy = &V_CY(&v);
3467     size_t i;
3468 
3469     CHECKPTR(VarNeg);
3470 
3471     /* Test all possible V_VT values. But don't test the exact return values
3472      * except for success/failure, since M$ made a hash of them in the
3473      * native version. This at least ensures (as with all tests here) that
3474      * we will notice if/when new vtypes/flags are added in native.
3475      */
3476     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
3477     {
3478         VARTYPE vt;
3479 
3480         for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
3481         {
3482             BOOL bFail = TRUE;
3483 
3484             SKIPTESTS(vt);
3485 
3486             memset(&v, 0, sizeof(v));
3487             V_VT(&v) = vt | ExtraFlags[i];
3488             V_VT(&vDst) = VT_EMPTY;
3489 
3490             switch (V_VT(&v))
3491             {
3492             case VT_UI1: case VT_I2: case VT_I4:
3493             case VT_R4:  case VT_R8:
3494             case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
3495             case VT_DATE: case VT_CY:
3496                 bFail = FALSE;
3497                 break;
3498             case VT_I8:
3499                 if (has_i8)
3500                     bFail = FALSE;
3501             }
3502 
3503             hres = pVarNeg(&v,&vDst);
3504             if (bFail)
3505                 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3506                    "VarNeg: expected failure, got 0x%X vt %d|0x%X\n",
3507                    hres, vt, ExtraFlags[i]);
3508             else
3509                 ok(hres == S_OK, "VarNeg: expected S_OK, got 0x%X vt %d|0x%X\n",
3510                     hres, vt, ExtraFlags[i]);
3511         }
3512     }
3513 
3514     VARNEG(BOOL,VARIANT_TRUE,I2,1);
3515     VARNEG(BOOL,VARIANT_FALSE,I2,0);
3516     VARNEG(BOOL,1,I2,-1);
3517     VARNEG(UI1,1,I2,-1);
3518     VARNEG(UI1,254,I2,-254);
3519     VARNEG(I2,-32768,I4,32768);
3520     VARNEG(I2,-1,I2,1);
3521     VARNEG(I2,1,I2,-1);
3522     VARNEG(I4,-((int)(~0u >> 1)) - 1,R8,-2147483648u);
3523     VARNEG(I4,-1,I4,1);
3524     VARNEG(I4,1,I4,-1);
3525     if (has_i8)
3526     {
3527         VARNEG(I8,1,I8,-1);
3528         VARNEG(I8,-1,I8,1);
3529     }
3530     VARNEG(R4,1,R4,-1);
3531     VARNEG(R4,-1,R4,1);
3532     VARNEG(DATE,1,DATE,-1);
3533     VARNEG(DATE,-1,DATE,1);
3534     VARNEG(R8,1,R8,-1);
3535     VARNEG(R8,-1,R8,1);
3536     VARNEG(BSTR,(BSTR)szNumMinus1,R8,1);
3537     VARNEG(BSTR,(BSTR)szNum1,R8,-1);
3538 
3539     V_VT(&v) = VT_EMPTY;
3540     hres = pVarNeg(&v,&vDst);
3541     ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
3542        "VarNeg: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY,
3543        hres, V_VT(&vDst), V_I2(&vDst));
3544 
3545     V_VT(&v) = VT_NULL;
3546     hres = pVarNeg(&v,&vDst);
3547     ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
3548        "VarNeg: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst));
3549 
3550     V_VT(&v) = VT_DECIMAL;
3551     S(U(*pdec)).sign = DECIMAL_NEG;
3552     S(U(*pdec)).scale = 0;
3553     pdec->Hi32 = 0;
3554     S1(U1(*pdec)).Mid32 = 0;
3555     S1(U1(*pdec)).Lo32 = 1;
3556     hres = pVarNeg(&v,&vDst);
3557     ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
3558        S(U(V_DECIMAL(&vDst))).sign == 0,
3559        "VarNeg: expected 0x0,%d,0x00, got 0x%X,%d,%02x\n", VT_DECIMAL,
3560        hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
3561 
3562     S(U(*pdec)).sign = 0;
3563     hres = pVarNeg(&v,&vDst);
3564     ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
3565        S(U(V_DECIMAL(&vDst))).sign == DECIMAL_NEG,
3566        "VarNeg: expected 0x0,%d,0x7f, got 0x%X,%d,%02x\n", VT_DECIMAL,
3567        hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
3568 
3569     V_VT(&v) = VT_CY;
3570     pcy->int64 = -10000;
3571     hres = pVarNeg(&v,&vDst);
3572     ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
3573        "VarNeg: VT_CY wrong, hres=0x%X\n", hres);
3574 }
3575 
3576 static HRESULT (WINAPI *pVarRound)(LPVARIANT,int,LPVARIANT);
3577 
3578 static void test_Round( int line, VARIANT *arg, int deci, VARIANT *expected )
3579 {
3580     VARIANT result;
3581     HRESULT hres;
3582 
3583     memset( &result, 0, sizeof(result) );
3584     hres = pVarRound( arg, deci, &result );
3585     ok_(__FILE__,line)( hres == S_OK, "wrong result %x\n", hres );
3586     if (hres == S_OK)
3587         ok_(__FILE__,line)( is_expected_variant( &result, expected ),
3588                             "got %s expected %s\n", variantstr(&result), variantstr(expected) );
3589 }
3590 #define VARROUND(vt,val,deci,rvt,rval)           \
3591     V_VT(&v) = VT_##vt; V_##vt(&v) = val;        \
3592     V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
3593     test_Round( __LINE__, &v, deci, &exp )
3594 
3595 struct decimal_t {
3596     BYTE scale;
3597     BYTE sign;
3598     ULONG Hi32;
3599     ULONG Mid32;
3600     ULONG Lo32;
3601 };
3602 
3603 struct decimal_round_t {
3604     struct decimal_t source;
3605     struct decimal_t ret;
3606     int dec;
3607 };
3608 
3609 static const struct decimal_round_t decimal_round_data[] = {
3610     {{ 0, DECIMAL_NEG, 0, 0, 1 }, { 0, DECIMAL_NEG, 0, 0, 1 }, 0},
3611     {{ 0, 0, 0, 0, 1 }, { 0, 0, 0, 0, 1 }, 0},
3612     {{ 2, 0, 0, 0, 155 }, { 0, 0, 0, 0, 16 }, 1},
3613     {{ 2, 0, 0, 0, 155 }, { 1, 0, 0, 0, 2 }, 0},
3614     {{ 2, 0, 0, 0, 199 }, { 1, 0, 0, 0, 20 }, 1},
3615     {{ 2, 0, 0, 0, 199 }, { 2, 0, 0, 0, 199 }, 2},
3616     {{ 2, DECIMAL_NEG, 0, 0, 199 }, { 2, DECIMAL_NEG, 0, 0, 199 }, 2},
3617     {{ 2, DECIMAL_NEG, 0, 0, 55 },  { 2, DECIMAL_NEG, 0, 0, 6 }, 1},
3618     {{ 2, 0, 0, 0, 55 },  { 2, 0, 0, 0, 6 }, 1}
3619 };
3620 
3621 static void test_VarRound(void)
3622 {
3623     static WCHAR szNumMin[] = {'-','1','.','4','4','9','\0' };
3624     static WCHAR szNum[] = {'1','.','4','5','1','\0' };
3625     HRESULT hres;
3626     VARIANT v, exp, vDst;
3627     CY *pcy = &V_CY(&v);
3628     char buff[8];
3629     int i;
3630 
3631     CHECKPTR(VarRound);
3632 
3633     /* first check valid integer types */
3634     VARROUND(BOOL,VARIANT_TRUE,0,I2,-1);
3635     VARROUND(BOOL,VARIANT_FALSE,0,I2,0);
3636     VARROUND(BOOL,1,0,I2,1);
3637     VARROUND(UI1,1,0,UI1,1);
3638     VARROUND(UI1,254,0,UI1,254);
3639     VARROUND(I2,-32768,0,I2,-32768);
3640     VARROUND(I2,-1,0,I2,-1);
3641     VARROUND(I2,1,0,I2,1);
3642     VARROUND(I4,-((int)(~0u >> 1)) - 1,0,I4,-((int)(~0u >> 1)) - 1);
3643     VARROUND(I4,-1,0,I4,-1);
3644     VARROUND(I4,1,0,I4,1);
3645 
3646 
3647     /* MSDN states that rounding of R4/R8 is dependent on the underlying
3648      * bit pattern of the number and so is architecture dependent. In this
3649      * case Wine returns .2 (which is more correct) and Native returns .3
3650      */
3651 
3652     VARROUND(R4,1.0f,0,R4,1.0f);
3653     VARROUND(R4,-1.0f,0,R4,-1.0f);
3654     VARROUND(R8,1.0,0,R8,1.0);
3655     VARROUND(R8,-1.0,0,R8,-1.0);
3656 
3657     /* floating point numbers aren't exactly equal and we can't just
3658      * compare the first few digits. */
3659     VARROUND(DATE,1.451,1,DATE,1.5);
3660     VARROUND(DATE,-1.449,1,DATE,-1.4);
3661 
3662     /* replace the decimal separator */
3663     GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char));
3664     if (!buff[1]) {
3665         szNumMin[2] = buff[0];
3666         szNum[1] = buff[0];
3667         VARROUND(BSTR,(BSTR)szNumMin,1,R8,-1.40);
3668         VARROUND(BSTR,(BSTR)szNum,1,R8,1.50);
3669     } else {
3670         skip("Skipping VarRound(BSTR) as decimal separator is '%s'\n", buff);
3671     }
3672 
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     VARROUND(R4,-1.23456f,0,R4,-1.0f);
3679     VARROUND(R4,-1.23456f,1,R4,-1.2f);
3680     VARROUND(R4,-1.23456f,2,R4,-1.23f);
3681     VARROUND(R4,-1.23456f,3,R4,-1.235f);
3682     VARROUND(R4,-1.23456f,4,R4,-1.2346f);
3683 
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     VARROUND(R8,-1.23456,0,R8,-1.0);
3690     VARROUND(R8,-1.23456,1,R8,-1.2);
3691     VARROUND(R8,-1.23456,2,R8,-1.23);
3692     VARROUND(R8,-1.23456,3,R8,-1.235);
3693     VARROUND(R8,-1.23456,4,R8,-1.2346);
3694 
3695     V_VT(&v) = VT_EMPTY;
3696     hres = pVarRound(&v,0,&vDst);
3697     ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
3698         "VarRound: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY,
3699         hres, V_VT(&vDst), V_I2(&vDst));
3700 
3701     V_VT(&v) = VT_NULL;
3702     hres = pVarRound(&v,0,&vDst);
3703     ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
3704         "VarRound: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst));
3705 
3706     /* VT_DECIMAL */
3707     for (i = 0; i < sizeof(decimal_round_data)/sizeof(struct decimal_round_t); i++)
3708     {
3709         const struct decimal_round_t *ptr = &decimal_round_data[i];
3710         DECIMAL *pdec;
3711 
3712         pdec = &V_DECIMAL(&v);
3713         V_VT(&v) = VT_DECIMAL;
3714         S(U(*pdec)).sign = ptr->source.sign;
3715         S(U(*pdec)).scale = ptr->source.scale;
3716         pdec->Hi32 = ptr->source.Hi32;
3717         S1(U1(*pdec)).Mid32 = ptr->source.Mid32;
3718         S1(U1(*pdec)).Lo32 = ptr->source.Lo32;
3719         VariantInit(&vDst);
3720         hres = pVarRound(&v, ptr->dec, &vDst);
3721     todo_wine
3722         ok(hres == S_OK, "%d: got 0x%08x\n", i, hres);
3723         if (hres == S_OK)
3724         {
3725             ok(V_VT(&vDst) == VT_DECIMAL, "%d: got VT %d, expected VT_DECIMAL\n", i, V_VT(&vDst));
3726             ok(S(U(V_DECIMAL(&vDst))).sign == ptr->ret.sign, "%d: got sign 0x%02x, expected 0x%02x\n",
3727                 i, S(U(V_DECIMAL(&vDst))).sign, ptr->ret.sign);
3728             ok(V_DECIMAL(&vDst).Hi32 == ptr->ret.Hi32, "%d: got Hi32 %d, expected %d\n",
3729                 i, V_DECIMAL(&vDst).Hi32, ptr->ret.Hi32);
3730             ok(S1(U1(V_DECIMAL(&vDst))).Mid32 == ptr->ret.Mid32, "%d: got Mid32 %d, expected %d\n",
3731                i, S1(U1(V_DECIMAL(&vDst))).Mid32,  ptr->ret.Mid32);
3732             ok(S1(U1(V_DECIMAL(&vDst))).Lo32 == ptr->ret.Lo32, "%d: got Lo32 %d, expected %d\n",
3733                 i, S1(U1(V_DECIMAL(&vDst))).Lo32, ptr->ret.Lo32);
3734         }
3735     }
3736 
3737     /* VT_CY */
3738     V_VT(&v) = VT_CY;
3739     pcy->int64 = 10000;
3740     hres = pVarRound(&v,0,&vDst);
3741     ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
3742         "VarRound: VT_CY wrong, hres=0x%X\n", hres);
3743 
3744 }
3745 
3746 static HRESULT (WINAPI *pVarXor)(LPVARIANT,LPVARIANT,LPVARIANT);
3747 
3748 #define VARXOR(vt1,val1,vt2,val2,rvt,rval)               \
3749         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
3750         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
3751         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
3752         test_var_call2( __LINE__, pVarXor, &left, &right, &exp )
3753 
3754 #define VARXORCY(vt1,val1,val2,rvt,rval)                 \
3755         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
3756         V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \
3757         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
3758         test_var_call2( __LINE__, pVarXor, &left, &right, &exp )
3759 
3760 static void test_VarXor(void)
3761 {
3762     static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
3763     static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
3764     VARIANT left, right, exp, result;
3765     BSTR lbstr, rbstr;
3766     VARTYPE i;
3767     HRESULT hres;
3768 
3769     CHECKPTR(VarXor);
3770 
3771     /* Test all possible flag/vt combinations & the resulting vt type */
3772     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
3773     {
3774         VARTYPE leftvt, rightvt, resvt;
3775 
3776         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
3777         {
3778 
3779             SKIPTESTS(leftvt);
3780 
3781             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
3782             {
3783                 BOOL bFail = FALSE;
3784 
3785                 SKIPTESTS(rightvt);
3786 
3787                 if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
3788                     leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
3789                     leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
3790                     continue;
3791 
3792                 memset(&left, 0, sizeof(left));
3793                 memset(&right, 0, sizeof(right));
3794                 V_VT(&left) = leftvt | ExtraFlags[i];
3795                 V_VT(&right) = rightvt | ExtraFlags[i];
3796                 V_VT(&result) = VT_EMPTY;
3797                 resvt = VT_I4;
3798 
3799                 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
3800                     !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
3801                     !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
3802                     leftvt == VT_CLSID || rightvt == VT_CLSID ||
3803                     leftvt == VT_RECORD || rightvt == VT_RECORD ||
3804                     leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
3805                     leftvt == VT_ERROR || rightvt == VT_ERROR)
3806                 {
3807                     bFail = TRUE;
3808                 }
3809                 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
3810                 {
3811                     if (leftvt == rightvt ||
3812                         leftvt == VT_I2 || rightvt == VT_I2 ||
3813                         leftvt == VT_UI1 || rightvt == VT_UI1 ||
3814                         leftvt == VT_BOOL || rightvt == VT_BOOL)
3815                         resvt = VT_I2;
3816                     else if (leftvt == VT_NULL || rightvt == VT_NULL)
3817                         resvt = VT_NULL;
3818                     else if (leftvt == VT_I8 || rightvt == VT_I8)
3819                         resvt = VT_I8;
3820                 }
3821                 else if (leftvt == VT_NULL || rightvt == VT_NULL)
3822                 {
3823                     resvt = VT_NULL;
3824                 }
3825                 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
3826                 {
3827                     if (leftvt == rightvt)
3828                         resvt = VT_UI1;
3829                     else if (leftvt == rightvt ||
3830                         leftvt == VT_I2 || rightvt == VT_I2 ||
3831                         leftvt == VT_BOOL || rightvt == VT_BOOL)
3832                     {
3833                         resvt = VT_I2;
3834                     }
3835                     else if (leftvt == VT_I8 || rightvt == VT_I8)
3836                         resvt = VT_I8;
3837                 }
3838                 else if (leftvt == VT_I2 || rightvt == VT_I2)
3839                 {
3840                     if (leftvt == rightvt ||
3841                         leftvt == VT_BOOL || rightvt == VT_BOOL)
3842                         resvt = VT_I2;
3843                     else if (leftvt == VT_I8 || rightvt == VT_I8)
3844                         resvt = VT_I8;
3845                 }
3846                 else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
3847                 {
3848                     resvt = VT_BOOL;
3849                 }
3850                 else if (leftvt == VT_I8 || rightvt == VT_I8)
3851                 {
3852                     if (leftvt == VT_INT || rightvt == VT_INT)
3853                         bFail = TRUE;
3854                     else
3855                         resvt = VT_I8;
3856                 }
3857                 hres = pVarXor(&left, &right, &result);
3858                 if (bFail)
3859                     ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3860                        "VarXor: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
3861                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
3862                        V_VT(&result));
3863                 else
3864                     ok(hres == S_OK && V_VT(&result) == resvt,
3865                        "VarXor: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
3866                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
3867                        V_VT(&result));
3868             }
3869         }
3870     }
3871 
3872     /* Test returned values
3873      * FIXME: Test VT_DECIMAL/VT_DISPATCH
3874      */
3875     VARXOR(EMPTY,0,EMPTY,0,I2,0);
3876     VARXOR(EMPTY,1,EMPTY,0,I2,0);
3877     VARXOR(EMPTY,0,NULL,0,NULL,0);
3878     VARXOR(EMPTY,0,I1,0,I4,0);
3879     VARXOR(EMPTY,0,I1,1,I4,1);
3880     VARXOR(EMPTY,0,UI1,0,I2,0);
3881     VARXOR(EMPTY,0,UI1,1,I2,1);
3882     VARXOR(EMPTY,0,I2,0,I2,0);
3883     VARXOR(EMPTY,0,I2,1,I2,1);
3884     VARXOR(EMPTY,0,UI2,0,I4,0);
3885     VARXOR(EMPTY,0,UI2,1,I4,1);
3886     VARXOR(EMPTY,0,I4,0,I4,0);
3887     VARXOR(EMPTY,0,I4,1,I4,1);
3888     VARXOR(EMPTY,0,UI4,0,I4,0);
3889     VARXOR(EMPTY,0,UI4,1,I4,1);
3890     if (has_i8)
3891     {
3892         VARXOR(EMPTY,0,I8,0,I8,0);
3893         VARXOR(EMPTY,0,I8,1,I8,1);
3894         VARXOR(EMPTY,0,UI8,0,I4,0);
3895         VARXOR(EMPTY,0,UI8,1,I4,1);
3896     }
3897     VARXOR(EMPTY,0,INT,0,I4,0);
3898     VARXOR(EMPTY,0,INT,1,I4,1);
3899     VARXOR(EMPTY,0,UINT,0,I4,0);
3900     VARXOR(EMPTY,0,UINT,1,I4,1);
3901     VARXOR(EMPTY,0,BOOL,0,I2,0);
3902     VARXOR(EMPTY,0,BOOL,1,I2,1);
3903     VARXOR(EMPTY,0,R4,0,I4,0);
3904     VARXOR(EMPTY,0,R4,1,I4,1);
3905     VARXOR(EMPTY,0,R8,0,I4,0);
3906     VARXOR(EMPTY,0,R8,1,I4,1);
3907     rbstr = SysAllocString(szFalse);
3908     VARXOR(EMPTY,0,BSTR,rbstr,I2,0);
3909     SysFreeString(rbstr);
3910     rbstr = SysAllocString(szTrue);
3911     VARXOR(EMPTY,0,BSTR,rbstr,I2,-1);
3912     VARXORCY(EMPTY,0,10000,I4,1);
3913     SysFreeString(rbstr);
3914 
3915     /* NULL OR 0 = NULL. NULL OR n = n */
3916     VARXOR(NULL,0,NULL,0,NULL,0);
3917     VARXOR(NULL,1,NULL,0,NULL,0);
3918     VARXOR(NULL,0,I1,0,NULL,0);
3919     VARXOR(NULL,0,I1,1,NULL,0);
3920     VARXOR(NULL,0,UI1,0,NULL,0);
3921     VARXOR(NULL,0,UI1,1,NULL,0);
3922     VARXOR(NULL,0,I2,0,NULL,0);
3923     VARXOR(NULL,0,I2,1,NULL,0);
3924     VARXOR(NULL,0,UI2,0,NULL,0);
3925     VARXOR(NULL,0,UI2,1,NULL,0);
3926     VARXOR(NULL,0,I4,0,NULL,0);
3927     VARXOR(NULL,0,I4,1,NULL,0);
3928     VARXOR(NULL,0,UI4,0,NULL,0);
3929     VARXOR(NULL,0,UI4,1,NULL,0);
3930     if (has_i8)
3931     {
3932         VARXOR(NULL,0,I8,0,NULL,0);
3933         VARXOR(NULL,0,I8,1,NULL,0);
3934         VARXOR(NULL,0,UI8,0,NULL,0);
3935         VARXOR(NULL,0,UI8,1,NULL,0);
3936     }
3937     VARXOR(NULL,0,INT,0,NULL,0);
3938     VARXOR(NULL,0,INT,1,NULL,0);
3939     VARXOR(NULL,0,UINT,0,NULL,0);
3940     VARXOR(NULL,0,UINT,1,NULL,0);
3941     VARXOR(NULL,0,BOOL,0,NULL,0);
3942     VARXOR(NULL,0,BOOL,1,NULL,0);
3943     VARXOR(NULL,0,R4,0,NULL,0);
3944     VARXOR(NULL,0,R4,1,NULL,0);
3945     VARXOR(NULL,0,R8,0,NULL,0);
3946     VARXOR(NULL,0,R8,1,NULL,0);
3947     rbstr = SysAllocString(szFalse);
3948     VARXOR(NULL,0,BSTR,rbstr,NULL,0);
3949     SysFreeString(rbstr);
3950     rbstr = SysAllocString(szTrue);
3951     VARXOR(NULL,0,BSTR,rbstr,NULL,0);
3952     SysFreeString(rbstr);
3953     VARXORCY(NULL,0,10000,NULL,0);
3954     VARXORCY(NULL,0,0,NULL,0);
3955 
3956     VARXOR(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
3957     VARXOR(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
3958     VARXOR(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
3959     VARXOR(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
3960     /* Assume x,y & y,x are the same from now on to reduce the number of tests */
3961     VARXOR(BOOL,VARIANT_TRUE,I1,-1,I4,0);
3962     VARXOR(BOOL,VARIANT_TRUE,I1,0,I4,-1);
3963     VARXOR(BOOL,VARIANT_FALSE,I1,0,I4,0);
3964     VARXOR(BOOL,VARIANT_TRUE,UI1,255,I2,-256);
3965     VARXOR(BOOL,VARIANT_TRUE,UI1,0,I2,-1);
3966     VARXOR(BOOL,VARIANT_FALSE,UI1,0,I2,0);
3967     VARXOR(BOOL,VARIANT_TRUE,I2,-1,I2,0);
3968     VARXOR(BOOL,VARIANT_TRUE,I2,0,I2,-1);
3969     VARXOR(BOOL,VARIANT_FALSE,I2,0,I2,0);
3970     VARXOR(BOOL,VARIANT_TRUE,UI2,65535,I4,-65536);
3971     VARXOR(BOOL,VARIANT_TRUE,UI2,0,I4,-1);
3972     VARXOR(BOOL,VARIANT_FALSE,UI2,0,I4,0);
3973     VARXOR(BOOL,VARIANT_TRUE,I4,-1,I4,0);
3974     VARXOR(BOOL,VARIANT_TRUE,I4,0,I4,-1);
3975     VARXOR(BOOL,VARIANT_FALSE,I4,0,I4,0);
3976     VARXOR(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,0);
3977     VARXOR(BOOL,VARIANT_TRUE,UI4,0,I4,-1);
3978     VARXOR(BOOL,VARIANT_FALSE,UI4,0,I4,0);
3979     VARXOR(BOOL,VARIANT_TRUE,R4,-1,I4,0);
3980     VARXOR(BOOL,VARIANT_TRUE,R4,0,I4,-1);
3981     VARXOR(BOOL,VARIANT_FALSE,R4,0,I4,0);
3982     VARXOR(BOOL,VARIANT_TRUE,R8,-1,I4,0);
3983     VARXOR(BOOL,VARIANT_TRUE,R8,0,I4,-1);
3984     VARXOR(BOOL,VARIANT_FALSE,R8,0,I4,0);
3985     VARXOR(BOOL,VARIANT_TRUE,DATE,-1,I4,0);
3986     VARXOR(BOOL,VARIANT_TRUE,DATE,0,I4,-1);
3987     VARXOR(BOOL,VARIANT_FALSE,DATE,0,I4,0);
3988     if (has_i8)
3989     {
3990         VARXOR(BOOL,VARIANT_TRUE,I8,-1,I8,0);
3991         VARXOR(BOOL,VARIANT_TRUE,I8,0,I8,-1);
3992         VARXOR(BOOL,VARIANT_FALSE,I8,0,I8,0);
3993         /* This returns DISP_E_OVERFLOW which indicates that a conversion
3994          * to I4 is performed.
3995          */
3996         /* VARXOR(BOOL,VARIANT_TRUE,UI8,-1,I4,-1); */
3997         VARXOR(BOOL,VARIANT_TRUE,UI8,0,I4,-1);
3998         VARXOR(BOOL,VARIANT_FALSE,UI8,0,I4,0);
3999     }
4000     VARXOR(BOOL,VARIANT_TRUE,INT,-1,I4,0);
4001     VARXOR(BOOL,VARIANT_TRUE,INT,0,I4,-1);
4002     VARXOR(BOOL,VARIANT_FALSE,INT,0,I4,0);
4003     VARXOR(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,0);
4004     VARXOR(BOOL,VARIANT_TRUE,UINT,0,I4,-1);
4005     VARXOR(BOOL,VARIANT_FALSE,UINT,0,I4,0);
4006     rbstr = SysAllocString(szFalse);
4007     VARXOR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_FALSE);
4008     VARXOR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
4009     SysFreeString(rbstr);
4010     rbstr = SysAllocString(szTrue);
4011     VARXOR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_TRUE);
4012     VARXOR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_FALSE);
4013     SysFreeString(rbstr);
4014     VARXORCY(BOOL,VARIANT_TRUE,10000,I4,-2);
4015     VARXORCY(BOOL,VARIANT_TRUE,0,I4,-1);
4016     VARXORCY(BOOL,VARIANT_FALSE,0,I4,0);
4017 
4018     VARXOR(I1,-1,I1,-1,I4,0);
4019     VARXOR(I1,-1,I1,0,I4,-1);
4020     VARXOR(I1,0,I1,0,I4,0);
4021     VARXOR(I1,-1,UI1,255,I4,-256);
4022     VARXOR(I1,-1,UI1,0,I4,-1);
4023     VARXOR(I1,0,UI1,0,I4,0);
4024     VARXOR(I1,-1,I2,-1,I4,0);
4025     VARXOR(I1,-1,I2,0,I4,-1);
4026     VARXOR(I1,0,I2,0,I4,0);
4027     VARXOR(I1,-1,UI2,65535,I4,-65536);
4028     VARXOR(I1,-1,UI2,0,I4,-1);
4029     VARXOR(I1,0,UI2,0,I4,0);
4030     VARXOR(I1,-1,I4,-1,I4,0);
4031     VARXOR(I1,-1,I4,0,I4,-1);
4032     VARXOR(I1,0,I4,0,I4,0);
4033     VARXOR(I1,-1,UI4,0xffffffff,I4,0);
4034     VARXOR(I1,-1,UI4,0,I4,-1);
4035     VARXOR(I1,0,UI4,0,I4,0);
4036     VARXOR(I1,-1,R4,-1,I4,0);
4037     VARXOR(I1,-1,R4,0,I4,-1);
4038     VARXOR(I1,0,R4,0,I4,0);
4039     VARXOR(I1,-1,R8,-1,I4,0);
4040     VARXOR(I1,-1,R8,0,I4,-1);
4041     VARXOR(I1,0,R8,0,I4,0);
4042     VARXOR(I1,-1,DATE,-1,I4,0);
4043     VARXOR(I1,-1,DATE,0,I4,-1);
4044     VARXOR(I1,0,DATE,0,I4,0);
4045     if (has_i8)
4046     {
4047         VARXOR(I1,-1,I8,-1,I8,0);
4048         VARXOR(I1,-1,I8,0,I8,-1);
4049         VARXOR(I1,0,I8,0,I8,0);
4050         VARXOR(I1,-1,UI8,0,I4,-1);
4051         VARXOR(I1,0,UI8,0,I4,0);
4052     }
4053     VARXOR(I1,-1,INT,-1,I4,0);
4054     VARXOR(I1,-1,INT,0,I4,-1);
4055     VARXOR(I1,0,INT,0,I4,0);
4056     VARXOR(I1,-1,UINT,0xffffffff,I4,0);
4057     VARXOR(I1,-1,UINT,0,I4,-1);
4058     VARXOR(I1,0,UINT,0,I4,0);
4059     rbstr = SysAllocString(szFalse);
4060     VARXOR(I1,0,BSTR,rbstr,I4,0);
4061     VARXOR(I1,-1,BSTR,rbstr,I4,-1);
4062     SysFreeString(rbstr);
4063     rbstr = SysAllocString(szTrue);
4064     VARXOR(I1,0,BSTR,rbstr,I4,-1);
4065     VARXOR(I1,-1,BSTR,rbstr,I4,0);
4066     SysFreeString(rbstr);
4067     VARXORCY(I1,-1,10000,I4,-2);
4068     VARXORCY(I1,-1,0,I4,-1);
4069     VARXORCY(I1,0,0,I4,0);
4070 
4071     VARXOR(UI1,255,UI1,255,UI1,0);
4072     VARXOR(UI1,255,UI1,0,UI1,255);
4073     VARXOR(UI1,0,UI1,0,UI1,0);
4074     VARXOR(UI1,255,I2,-1,I2,-256);
4075     VARXOR(UI1,255,I2,0,I2,255);
4076     VARXOR(UI1,0,I2,0,I2,0);
4077     VARXOR(UI1,255,UI2,65535,I4,65280);
4078     VARXOR(UI1,255,UI2,0,I4,255);
4079     VARXOR(UI1,0,UI2,0,I4,0);
4080     VARXOR(UI1,255,I4,-1,I4,-256);
4081     VARXOR(UI1,255,I4,0,I4,255);
4082     VARXOR(UI1,0,I4,0,I4,0);
4083     VARXOR(UI1,255,UI4,0xffffffff,I4,-256);
4084     VARXOR(UI1,255,UI4,0,I4,255);
4085     VARXOR(UI1,0,UI4,0,I4,0);
4086     VARXOR(UI1,255,R4,-1,I4,-256);
4087     VARXOR(UI1,255,R4,0,I4,255);
4088     VARXOR(UI1,0,R4,0,I4,0);
4089     VARXOR(UI1,255,R8,-1,I4,-256);
4090     VARXOR(UI1,255,R8,0,I4,255);
4091     VARXOR(UI1,0,R8,0,I4,0);
4092     VARXOR(UI1,255,DATE,-1,I4,-256);
4093     VARXOR(UI1,255,DATE,0,I4,255);
4094     VARXOR(UI1,0,DATE,0,I4,0);
4095     if (has_i8)
4096     {
4097         VARXOR(UI1,255,I8,-1,I8,-256);
4098         VARXOR(UI1,255,I8,0,I8,255);
4099         VARXOR(UI1,0,I8,0,I8,0);
4100         VARXOR(UI1,255,UI8,0,I4,255);
4101         VARXOR(UI1,0,UI8,0,I4,0);
4102     }
4103     VARXOR(UI1,255,INT,-1,I4,-256);
4104     VARXOR(UI1,255,INT,0,I4,255);
4105     VARXOR(UI1,0,INT,0,I4,0);
4106     VARXOR(UI1,255,UINT,0xffffffff,I4,-256);
4107     VARXOR(UI1,255,UINT,0,I4,255);
4108     VARXOR(UI1,0,UINT,0,I4,0);
4109     rbstr = SysAllocString(szFalse);
4110     VARXOR(UI1,0,BSTR,rbstr,I2,0);
4111     VARXOR(UI1,255,BSTR,rbstr,I2,255);
4112     SysFreeString(rbstr);
4113     rbstr = SysAllocString(szTrue);
4114     VARXOR(UI1,0,BSTR,rbstr,I2,-1);
4115     VARXOR(UI1,255,BSTR,rbstr,I2,-256);
4116     SysFreeString(rbstr);
4117     VARXORCY(UI1,255,10000,I4,254);
4118     VARXORCY(UI1,255,0,I4,255);
4119     VARXORCY(UI1,0,0,I4,0);
4120 
4121     VARXOR(I2,-1,I2,-1,I2,0);
4122     VARXOR(I2,-1,I2,0,I2,-1);
4123     VARXOR(I2,0,I2,0,I2,0);
4124     VARXOR(I2,-1,UI2,65535,I4,-65536);
4125     VARXOR(I2,-1,UI2,0,I4,-1);
4126     VARXOR(I2,0,UI2,0,I4,0);
4127     VARXOR(I2,-1,I4,-1,I4,0);
4128     VARXOR(I2,-1,I4,0,I4,-1);
4129     VARXOR(I2,0,I4,0,I4,0);
4130     VARXOR(I2,-1,UI4,0xffffffff,I4,0);
4131     VARXOR(I2,-1,UI4,0,I4,-1);
4132     VARXOR(I2,0,UI4,0,I4,0);
4133     VARXOR(I2,-1,R4,-1,I4,0);
4134     VARXOR(I2,-1,R4,0,I4,-1);
4135     VARXOR(I2,0,R4,0,I4,0);
4136     VARXOR(I2,-1,R8,-1,I4,0);
4137     VARXOR(I2,-1,R8,0,I4,-1);
4138     VARXOR(I2,0,R8,0,I4,0);
4139     VARXOR(I2,-1,DATE,-1,I4,0);
4140     VARXOR(I2,-1,DATE,0,I4,-1);
4141     VARXOR(I2,0,DATE,0,I4,0);
4142     if (has_i8)
4143     {
4144         VARXOR(I2,-1,I8,-1,I8,0);
4145         VARXOR(I2,-1,I8,0,I8,-1);
4146         VARXOR(I2,0,I8,0,I8,0);
4147         VARXOR(I2,-1,UI8,0,I4,-1);
4148         VARXOR(I2,0,UI8,0,I4,0);
4149     }
4150     VARXOR(I2,-1,INT,-1,I4,0);
4151     VARXOR(I2,-1,INT,0,I4,-1);
4152     VARXOR(I2,0,INT,0,I4,0);
4153     VARXOR(I2,-1,UINT,0xffffffff,I4,0);
4154     VARXOR(I2,-1,UINT,0,I4,-1);
4155     VARXOR(I2,0,UINT,0,I4,0);
4156     rbstr = SysAllocString(szFalse);
4157     VARXOR(I2,0,BSTR,rbstr,I2,0);
4158     VARXOR(I2,-1,BSTR,rbstr,I2,-1);
4159     SysFreeString(rbstr);
4160     rbstr = SysAllocString(szTrue);
4161     VARXOR(I2,0,BSTR,rbstr,I2,-1);
4162     VARXOR(I2,-1,BSTR,rbstr,I2,0);
4163     SysFreeString(rbstr);
4164     VARXORCY(I2,-1,10000,I4,-2);
4165     VARXORCY(I2,-1,0,I4,-1);
4166     VARXORCY(I2,0,0,I4,0);
4167 
4168     VARXOR(UI2,65535,UI2,65535,I4,0);
4169     VARXOR(UI2,65535,UI2,0,I4,65535);
4170     VARXOR(UI2,0,UI2,0,I4,0);
4171     VARXOR(UI2,65535,I4,-1,I4,-65536);
4172     VARXOR(UI2,65535,I4,0,I4,65535);
4173     VARXOR(UI2,0,I4,0,I4,0);
4174     VARXOR(UI2,65535,UI4,0xffffffff,I4,-65536);
4175     VARXOR(UI2,65535,UI4,0,I4,65535);
4176     VARXOR(UI2,0,UI4,0,I4,0);
4177     VARXOR(UI2,65535,R4,-1,I4,-65536);
4178     VARXOR(UI2,65535,R4,0,I4,65535);
4179     VARXOR(UI2,0,R4,0,I4,0);
4180     VARXOR(UI2,65535,R8,-1,I4,-65536);
4181     VARXOR(UI2,65535,R8,0,I4,65535);
4182     VARXOR(UI2,0,R8,0,I4,0);
4183     VARXOR(UI2,65535,DATE,-1,I4,-65536);
4184     VARXOR(UI2,65535,DATE,0,I4,65535);
4185     VARXOR(UI2,0,DATE,0,I4,0);
4186     if (has_i8)
4187     {
4188         VARXOR(UI2,65535,I8,-1,I8,-65536);
4189         VARXOR(UI2,65535,I8,0,I8,65535);
4190         VARXOR(UI2,0,I8,0,I8,0);
4191         VARXOR(UI2,65535,UI8,0,I4,65535);
4192         VARXOR(UI2,0,UI8,0,I4,0);
4193     }
4194     VARXOR(UI2,65535,INT,-1,I4,-65536);
4195     VARXOR(UI2,65535,INT,0,I4,65535);
4196     VARXOR(UI2,0,INT,0,I4,0);
4197     VARXOR(UI2,65535,UINT,0xffffffff,I4,-65536);
4198     VARXOR(UI2,65535,UINT,0,I4,65535);
4199     VARXOR(UI2,0,UINT,0,I4,0);
4200     rbstr = SysAllocString(szFalse);
4201     VARXOR(UI2,0,BSTR,rbstr,I4,0);
4202     VARXOR(UI2,65535,BSTR,rbstr,I4,65535);
4203     SysFreeString(rbstr);
4204     rbstr = SysAllocString(szTrue);
4205     VARXOR(UI2,0,BSTR,rbstr,I4,-1);
4206     VARXOR(UI2,65535,BSTR,rbstr,I4,-65536);
4207     SysFreeString(rbstr);
4208     VARXORCY(UI2,65535,10000,I4,65534);
4209     VARXORCY(UI2,65535,0,I4,65535);
4210     VARXORCY(UI2,0,0,I4,0);
4211 
4212     VARXOR(I4,-1,I4,-1,I4,0);
4213     VARXOR(I4,-1,I4,0,I4,-1);
4214     VARXOR(I4,0,I4,0,I4,0);
4215     VARXOR(I4,-1,UI4,0xffffffff,I4,0);
4216     VARXOR(I4,-1,UI4,0,I4,-1);
4217     VARXOR(I4,0,UI4,0,I4,0);
4218     VARXOR(I4,-1,R4,-1,I4,0);
4219     VARXOR(I4,-1,R4,0,I4,-1);
4220     VARXOR(I4,0,R4,0,I4,0);
4221     VARXOR(I4,-1,R8,-1,I4,0);
4222     VARXOR(I4,-1,R8,0,I4,-1);
4223     VARXOR(I4,0,R8,0,I4,0);
4224     VARXOR(I4,-1,DATE,-1,I4,0);
4225     VARXOR(I4,-1,DATE,0,I4,-1);
4226     VARXOR(I4,0,DATE,0,I4,0);
4227     if (has_i8)
4228     {
4229         VARXOR(I4,-1,I8,-1,I8,0);
4230         VARXOR(I4,-1,I8,0,I8,-1);
4231         VARXOR(I4,0,I8,0,I8,0);
4232         VARXOR(I4,-1,UI8,0,I4,-1);
4233         VARXOR(I4,0,UI8,0,I4,0);
4234     }
4235     VARXOR(I4,-1,INT,-1,I4,0);
4236     VARXOR(I4,-1,INT,0,I4,-1);
4237     VARXOR(I4,0,INT,0,I4,0);
4238     VARXOR(I4,-1,UINT,0xffffffff,I4,0);
4239     VARXOR(I4,-1,UINT,0,I4,-1);
4240     VARXOR(I4,0,UINT,0,I4,0);
4241     rbstr = SysAllocString(szFalse);
4242     VARXOR(I4,0,BSTR,rbstr,I4,0);
4243     VARXOR(I4,-1,BSTR,rbstr,I4,-1);
4244     SysFreeString(rbstr);
4245     rbstr = SysAllocString(szTrue);
4246     VARXOR(I4,0,BSTR,rbstr,I4,-1);
4247     VARXOR(I4,-1,BSTR,rbstr,I4,0);
4248     SysFreeString(rbstr);
4249     VARXORCY(I4,-1,10000,I4,-2);
4250     VARXORCY(I4,-1,0,I4,-1);
4251     VARXORCY(I4,0,0,I4,0);
4252 
4253     VARXOR(UI4,0xffffffff,UI4,0xffffffff,I4,0);
4254     VARXOR(UI4,0xffffffff,UI4,0,I4,-1);
4255     VARXOR(UI4,0,UI4,0,I4,0);
4256     VARXOR(UI4,0xffffffff,R4,-1,I4,0);
4257     VARXOR(UI4,0xffffffff,R4,0,I4,-1);
4258     VARXOR(UI4,0,R4,0,I4,0);
4259     VARXOR(UI4,0xffffffff,R8,-1,I4,0);
4260     VARXOR(UI4,0xffffffff,R8,0,I4,-1);
4261     VARXOR(UI4,0,R8,0,I4,0);
4262     VARXOR(UI4,0xffffffff,DATE,-1,I4,0);
4263     VARXOR(UI4,0xffffffff,DATE,0,I4,-1);
4264     VARXOR(UI4,0,DATE,0,I4,0);
4265     if (has_i8)
4266     {
4267         VARXOR(UI4,0xffffffff,I8,0,I8,0xffffffff);
4268         VARXOR(UI4,VARIANT_FALSE,I8,VARIANT_FALSE,I8,0);
4269         VARXOR(UI4,0,I8,0,I8,0);
4270         VARXOR(UI4,0xffffffff,UI8,0,I4,-1);
4271         VARXOR(UI4,0,UI8,0,I4,0);
4272     }
4273     VARXOR(UI4,0xffffffff,INT,-1,I4,0);
4274     VARXOR(UI4,0xffffffff,INT,0,I4,-1);
4275     VARXOR(UI4,0,INT,0,I4,0);
4276     VARXOR(UI4,0xffffffff,UINT,0xffffffff,I4,0);
4277     VARXOR(UI4,0xffffffff,UINT,0,I4,-1);
4278     VARXOR(UI4,0,UINT,0,I4,0);
4279     rbstr = SysAllocString(szFalse);
4280     VARXOR(UI4,0,BSTR,rbstr,I4,0);
4281     VARXOR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
4282     SysFreeString(rbstr);
4283     rbstr = SysAllocString(szTrue);
4284     VARXOR(UI4,0,BSTR,rbstr,I4,-1);
4285     VARXOR(UI4,0xffffffff,BSTR,rbstr,I4,0);
4286     SysFreeString(rbstr);
4287     VARXORCY(UI4,0xffffffff,10000,I4,-2);
4288     VARXORCY(UI4,0xffffffff,0,I4,-1);
4289     VARXORCY(UI4,0,0,I4,0);
4290 
4291     VARXOR(R4,-1,R4,-1,I4,0);
4292     VARXOR(R4,-1,R4,0,I4,-1);
4293     VARXOR(R4,0,R4,0,I4,0);
4294     VARXOR(R4,-1,R8,-1,I4,0);
4295     VARXOR(R4,-1,R8,0,I4,-1);
4296     VARXOR(R4,0,R8,0,I4,0);
4297     VARXOR(R4,-1,DATE,-1,I4,0);
4298     VARXOR(R4,-1,DATE,0,I4,-1);
4299     VARXOR(R4,0,DATE,0,I4,0);
4300     if (has_i8)
4301     {
4302         VARXOR(R4,-1,I8,-1,I8,0);
4303         VARXOR(R4,-1,I8,0,I8,-1);
4304         VARXOR(R4,0,I8,0,I8,0);
4305         VARXOR(R4,-1,UI8,0,I4,-1);
4306         VARXOR(R4,0,UI8,0,I4,0);
4307     }
4308     VARXOR(R4,-1,INT,-1,I4,0);
4309     VARXOR(R4,-1,INT,0,I4,-1);
4310     VARXOR(R4,0,INT,0,I4,0);
4311     VARXOR(R4,-1,UINT,0xffffffff,I4,0);
4312     VARXOR(R4,-1,UINT,0,I4,-1);
4313     VARXOR(R4,0,UINT,0,I4,0);
4314     rbstr = SysAllocString(szFalse);
4315     VARXOR(R4,0,BSTR,rbstr,I4,0);
4316     VARXOR(R4,-1,BSTR,rbstr,I4,-1);
4317     SysFreeString(rbstr);
4318     rbstr = SysAllocString(szTrue);
4319     VARXOR(R4,0,BSTR,rbstr,I4,-1);
4320     VARXOR(R4,-1,BSTR,rbstr,I4,0);
4321     SysFreeString(rbstr);
4322     VARXORCY(R4,-1,10000,I4,-2);
4323     VARXORCY(R4,-1,0,I4,-1);
4324     VARXORCY(R4,0,0,I4,0);
4325 
4326     VARXOR(R8,-1,R8,-1,I4,0);
4327     VARXOR(R8,-1,R8,0,I4,-1);
4328     VARXOR(R8,0,R8,0,I4,0);
4329     VARXOR(R8,-1,DATE,-1,I4,0);
4330     VARXOR(R8,-1,DATE,0,I4,-1);
4331     VARXOR(R8,0,DATE,0,I4,0);
4332     if (has_i8)
4333     {
4334         VARXOR(R8,-1,I8,-1,I8,0);
4335         VARXOR(R8,-1,I8,0,I8,-1);
4336         VARXOR(R8,0,I8,0,I8,0);
4337         VARXOR(R8,-1,UI8,0,I4,-1);
4338         VARXOR(R8,0,UI8,0,I4,0);
4339     }
4340     VARXOR(R8,-1,INT,-1,I4,0);
4341     VARXOR(R8,-1,INT,0,I4,-1);
4342     VARXOR(R8,0,INT,0,I4,0);
4343     VARXOR(R8,-1,UINT,0xffffffff,I4,0);
4344     VARXOR(R8,-1,UINT,0,I4,-1);
4345     VARXOR(R8,0,UINT,0,I4,0);
4346     rbstr = SysAllocString(szFalse);
4347     VARXOR(R8,0,BSTR,rbstr,I4,0);
4348     VARXOR(R8,-1,BSTR,rbstr,I4,-1);
4349     SysFreeString(rbstr);
4350     rbstr = SysAllocString(szTrue);
4351     VARXOR(R8,0,BSTR,rbstr,I4,-1);
4352     VARXOR(R8,-1,BSTR,rbstr,I4,0);
4353     SysFreeString(rbstr);
4354     VARXORCY(R8,-1,10000,I4,-2);
4355     VARXORCY(R8,-1,0,I4,-1);
4356     VARXORCY(R8,0,0,I4,0);
4357 
4358     VARXOR(DATE,-1,DATE,-1,I4,0);
4359     VARXOR(DATE,-1,DATE,0,I4,-1);
4360     VARXOR(DATE,0,DATE,0,I4,0);
4361     if (has_i8)
4362     {
4363         VARXOR(DATE,-1,I8,-1,I8,0);
4364         VARXOR(DATE,-1,I8,0,I8,-1);
4365         VARXOR(DATE,0,I8,0,I8,0);
4366         VARXOR(DATE,-1,UI8,0,I4,-1);
4367         VARXOR(DATE,0,UI8,0,I4,0);
4368     }
4369     VARXOR(DATE,-1,INT,-1,I4,0);
4370     VARXOR(DATE,-1,INT,0,I4,-1);
4371     VARXOR(DATE,0,INT,0,I4,0);
4372     VARXOR(DATE,-1,UINT,0xffffffff,I4,0);
4373     VARXOR(DATE,-1,UINT,0,I4,-1);
4374     VARXOR(DATE,0,UINT,0,I4,0);
4375     rbstr = SysAllocString(szFalse);
4376     VARXOR(DATE,0,BSTR,rbstr,I4,0);
4377     VARXOR(DATE,-1,BSTR,rbstr,I4,-1);
4378     SysFreeString(rbstr);
4379     rbstr = SysAllocString(szTrue);
4380     VARXOR(DATE,0,BSTR,rbstr,I4,-1);
4381     VARXOR(DATE,-1,BSTR,rbstr,I4,0);
4382     SysFreeString(rbstr);
4383     VARXORCY(DATE,-1,10000,I4,-2);
4384     VARXORCY(DATE,-1,0,I4,-1);
4385     VARXORCY(DATE,0,0,I4,0);
4386 
4387     if (has_i8)
4388     {
4389         VARXOR(I8,-1,I8,-1,I8,0);
4390         VARXOR(I8,-1,I8,0,I8,-1);
4391         VARXOR(I8,0,I8,0,I8,0);
4392         VARXOR(I8,-1,UI8,0,I8,-1);
4393         VARXOR(I8,0,UI8,0,I8,0);
4394         VARXOR(I8,-1,UINT,0,I8,-1);
4395         VARXOR(I8,0,UINT,0,I8,0);
4396         rbstr = SysAllocString(szFalse);
4397         VARXOR(I8,0,BSTR,rbstr,I8,0);
4398         VARXOR(I8,-1,BSTR,rbstr,I8,-1);
4399         SysFreeString(rbstr);
4400         rbstr = SysAllocString(szTrue);
4401         VARXOR(I8,0,BSTR,rbstr,I8,-1);
4402         VARXOR(I8,-1,BSTR,rbstr,I8,0);
4403         SysFreeString(rbstr);
4404         VARXORCY(I8,-1,10000,I8,-2);
4405         VARXORCY(I8,-1,0,I8,-1);
4406         VARXORCY(I8,0,0,I8,0);
4407 
4408         VARXOR(UI8,0xffff,UI8,0xffff,I4,0);
4409         VARXOR(UI8,0xffff,UI8,0,I4,0xffff);
4410         VARXOR(UI8,0,UI8,0,I4,0);
4411         VARXOR(UI8,0xffff,INT,-1,I4,-65536);
4412         VARXOR(UI8,0xffff,INT,0,I4,0xffff);
4413         VARXOR(UI8,0,INT,0,I4,0);
4414         VARXOR(UI8,0xffff,UINT,0xffff,I4,0);
4415         VARXOR(UI8,0xffff,UINT,0,I4,0xffff);
4416         VARXOR(UI8,0,UINT,0,I4,0);
4417         rbstr = SysAllocString(szFalse);
4418         VARXOR(UI8,0,BSTR,rbstr,I4,0);
4419         VARXOR(UI8,0xffff,BSTR,rbstr,I4,0xffff);
4420         SysFreeString(rbstr);
4421         rbstr = SysAllocString(szTrue);
4422         VARXOR(UI8,0,BSTR,rbstr,I4,-1);
4423         VARXOR(UI8,0xffff,BSTR,rbstr,I4,-65536);
4424         SysFreeString(rbstr);
4425         VARXORCY(UI8,0xffff,10000,I4,65534);
4426         VARXORCY(UI8,0xffff,0,I4,0xffff);
4427         VARXORCY(UI8,0,0,I4,0);
4428     }
4429 
4430     VARXOR(INT,-1,INT,-1,I4,0);
4431     VARXOR(INT,-1,INT,0,I4,-1);
4432     VARXOR(INT,0,INT,0,I4,0);
4433     VARXOR(INT,-1,UINT,0xffff,I4,-65536);
4434     VARXOR(INT,-1,UINT,0,I4,-1);
4435     VARXOR(INT,0,UINT,0,I4,0);
4436     rbstr = SysAllocString(szFalse);
4437     VARXOR(INT,0,BSTR,rbstr,I4,0);
4438     VARXOR(INT,-1,BSTR,rbstr,I4,-1);
4439     SysFreeString(rbstr);
4440     rbstr = SysAllocString(szTrue);
4441     VARXOR(INT,0,BSTR,rbstr,I4,-1);
4442     VARXOR(INT,-1,BSTR,rbstr,I4,0);
4443     SysFreeString(rbstr);
4444     VARXORCY(INT,-1,10000,I4,-2);
4445     VARXORCY(INT,-1,0,I4,-1);
4446     VARXORCY(INT,0,0,I4,0);
4447 
4448     VARXOR(UINT,0xffff,UINT,0xffff,I4,0);
4449     VARXOR(UINT,0xffff,UINT,0,I4,0xffff);
4450     VARXOR(UINT,0,UINT,0,I4,0);
4451     rbstr = SysAllocString(szFalse);
4452     VARXOR(UINT,0,BSTR,rbstr,I4,0);
4453     VARXOR(UINT,0xffff,BSTR,rbstr,I4,0xffff);
4454     SysFreeString(rbstr);
4455     rbstr = SysAllocString(szTrue);
4456     VARXOR(UINT,0,BSTR,rbstr,I4,-1);
4457     VARXOR(UINT,0xffff,BSTR,rbstr,I4,-65536);
4458     SysFreeString(rbstr);
4459     VARXORCY(UINT,0xffff,10000,I4,65534);
4460     VARXORCY(UINT,0xffff,0,I4,0xffff);
4461     VARXORCY(UINT,0,0,I4,0);
4462 
4463     lbstr = SysAllocString(szFalse);
4464     rbstr = SysAllocString(szFalse);
4465     VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,0);
4466     SysFreeString(rbstr);
4467     rbstr = SysAllocString(szTrue);
4468     VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
4469     SysFreeString(lbstr);
4470     lbstr = SysAllocString(szTrue);
4471     VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_FALSE);
4472     VARXORCY(BSTR,lbstr,10000,I4,-2);
4473     SysFreeString(lbstr);
4474     lbstr = SysAllocString(szFalse);
4475     VARXORCY(BSTR,lbstr,10000,I4,1);
4476     SysFreeString(lbstr);
4477     SysFreeString(rbstr);
4478 }
4479 
4480 static HRESULT (WINAPI *pVarOr)(LPVARIANT,LPVARIANT,LPVARIANT);
4481 
4482 #define VAROR(vt1,val1,vt2,val2,rvt,rval)                \
4483         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
4484         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
4485         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
4486         test_var_call2( __LINE__, pVarOr, &left, &right, &exp )
4487 
4488 #define VARORCY(vt1,val1,val2,rvt,rval)                  \
4489         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
4490         V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \
4491         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
4492         test_var_call2( __LINE__, pVarOr, &left, &right, &exp )
4493 
4494 static void test_VarOr(void)
4495 {
4496     static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
4497     static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
4498     VARIANT left, right, exp, result;
4499     BSTR lbstr, rbstr;
4500     VARTYPE i;
4501     HRESULT hres;
4502 
4503     CHECKPTR(VarOr);
4504 
4505     /* Test all possible flag/vt combinations & the resulting vt type */
4506     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
4507     {
4508         VARTYPE leftvt, rightvt, resvt;
4509 
4510         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
4511         {
4512 
4513             SKIPTESTS(leftvt);
4514 
4515             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
4516             {
4517                 BOOL bFail = FALSE;
4518 
4519                 SKIPTESTS(rightvt);
4520 
4521                 if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
4522                     leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
4523                     leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
4524                     continue;
4525 
4526                 memset(&left, 0, sizeof(left));
4527                 memset(&right, 0, sizeof(right));
4528                 V_VT(&left) = leftvt | ExtraFlags[i];
4529                 V_VT(&right) = rightvt | ExtraFlags[i];
4530                 V_VT(&result) = VT_EMPTY;
4531                 resvt = VT_I4;
4532 
4533                 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
4534                     !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
4535                     !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
4536                     leftvt == VT_CLSID || rightvt == VT_CLSID ||
4537                     leftvt == VT_RECORD || rightvt == VT_RECORD ||
4538                     leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
4539                     leftvt == VT_ERROR || rightvt == VT_ERROR)
4540                 {
4541                     bFail = TRUE;
4542                 }
4543                 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
4544                 {
4545                     if (leftvt == rightvt ||
4546                         leftvt == VT_I2 || rightvt == VT_I2 ||
4547                         leftvt == VT_UI1 || rightvt == VT_UI1 ||
4548                         leftvt == VT_BOOL || rightvt == VT_BOOL)
4549                         resvt = VT_I2;
4550                     else if (leftvt == VT_NULL || rightvt == VT_NULL)
4551                         resvt = VT_NULL;
4552                     else if (leftvt == VT_I8 || rightvt == VT_I8)
4553                         resvt = VT_I8;
4554                 }
4555                 else if (leftvt == VT_NULL || rightvt == VT_NULL)
4556                 {
4557                     resvt = VT_NULL;
4558                 }
4559                 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
4560                 {
4561                     if (leftvt == rightvt)
4562                         resvt = VT_UI1;
4563                     else if (leftvt == rightvt ||
4564                         leftvt == VT_I2 || rightvt == VT_I2 ||
4565                         leftvt == VT_BOOL || rightvt == VT_BOOL)
4566                     {
4567                         resvt = VT_I2;
4568                     }
4569                     else if (leftvt == VT_I8 || rightvt == VT_I8)
4570                         resvt = VT_I8;
4571                 }
4572                 else if (leftvt == VT_I2 || rightvt == VT_I2)
4573                 {
4574                     if (leftvt == rightvt ||
4575                         leftvt == VT_BOOL || rightvt == VT_BOOL)
4576                         resvt = VT_I2;
4577                     else if (leftvt == VT_I8 || rightvt == VT_I8)
4578                         resvt = VT_I8;
4579                 }
4580                 else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
4581                 {
4582                     resvt = VT_BOOL;
4583                 }
4584                 else if (leftvt == VT_I8 || rightvt == VT_I8)
4585                 {
4586                     if (leftvt == VT_INT || rightvt == VT_INT)
4587                         bFail = TRUE;
4588                     else
4589                         resvt = VT_I8;
4590                 }
4591                 hres = pVarOr(&left, &right, &result);
4592                 if (bFail)
4593                     ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
4594                        "VarOr: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
4595                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
4596                        V_VT(&result));
4597                 else
4598                     ok(hres == S_OK && V_VT(&result) == resvt,
4599                        "VarOr: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
4600                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
4601                        V_VT(&result));
4602             }
4603         }
4604     }
4605 
4606     /* Test returned values. Since we know the returned type is correct
4607      * and that we handle all combinations of invalid types, just check
4608      * that good type combinations produce the desired value.
4609      * FIXME: Test VT_DECIMAL/VT_DISPATCH
4610      */
4611     VAROR(EMPTY,0,EMPTY,0,I2,0);
4612     VAROR(EMPTY,1,EMPTY,0,I2,0);
4613     VAROR(EMPTY,0,NULL,0,NULL,0);
4614     VAROR(EMPTY,0,I1,0,I4,0);
4615     VAROR(EMPTY,0,I1,1,I4,1);
4616     VAROR(EMPTY,0,UI1,0,I2,0);
4617     VAROR(EMPTY,0,UI1,1,I2,1);
4618     VAROR(EMPTY,0,I2,0,I2,0);
4619     VAROR(EMPTY,0,I2,1,I2,1);
4620     VAROR(EMPTY,0,UI2,0,I4,0);
4621     VAROR(EMPTY,0,UI2,1,I4,1);
4622     VAROR(EMPTY,0,I4,0,I4,0);
4623     VAROR(EMPTY,0,I4,1,I4,1);
4624     VAROR(EMPTY,0,UI4,0,I4,0);
4625     VAROR(EMPTY,0,UI4,1,I4,1);
4626     if (has_i8)
4627     {
4628         VAROR(EMPTY,0,I8,0,I8,0);
4629         VAROR(EMPTY,0,I8,1,I8,1);
4630         VAROR(EMPTY,0,UI8,0,I4,0);
4631         VAROR(EMPTY,0,UI8,1,I4,1);
4632     }
4633     VAROR(EMPTY,0,INT,0,I4,0);
4634     VAROR(EMPTY,0,INT,1,I4,1);
4635     VAROR(EMPTY,0,UINT,0,I4,0);
4636     VAROR(EMPTY,0,UINT,1,I4,1);
4637     VAROR(EMPTY,0,BOOL,0,I2,0);
4638     VAROR(EMPTY,0,BOOL,1,I2,1);
4639     VAROR(EMPTY,0,R4,0,I4,0);
4640     VAROR(EMPTY,0,R4,1,I4,1);
4641     VAROR(EMPTY,0,R8,0,I4,0);
4642     VAROR(EMPTY,0,R8,1,I4,1);
4643     rbstr = SysAllocString(szFalse);
4644     VAROR(EMPTY,0,BSTR,rbstr,I2,0);
4645     SysFreeString(rbstr);
4646     rbstr = SysAllocString(szTrue);
4647     VAROR(EMPTY,0,BSTR,rbstr,I2,-1);
4648     SysFreeString(rbstr);
4649     VARORCY(EMPTY,0,10000,I4,1);
4650 
4651     /* NULL OR 0 = NULL. NULL OR n = n */
4652     VAROR(NULL,0,NULL,0,NULL,0);
4653     VAROR(NULL,1,NULL,0,NULL,0);
4654     VAROR(NULL,0,I1,0,NULL,0);
4655     VAROR(NULL,0,I1,1,I4,1);
4656     VAROR(NULL,0,UI1,0,NULL,0);
4657     VAROR(NULL,0,UI1,1,UI1,1);
4658     VAROR(NULL,0,I2,0,NULL,0);
4659     VAROR(NULL,0,I2,1,I2,1);
4660     VAROR(NULL,0,UI2,0,NULL,0);
4661     VAROR(NULL,0,UI2,1,I4,1);
4662     VAROR(NULL,0,I4,0,NULL,0);
4663     VAROR(NULL,0,I4,1,I4,1);
4664     VAROR(NULL,0,UI4,0,NULL,0);
4665     VAROR(NULL,0,UI4,1,I4,1);
4666     if (has_i8)
4667     {
4668         VAROR(NULL,0,I8,0,NULL,0);
4669         VAROR(NULL,0,I8,1,I8,1);
4670         VAROR(NULL,0,UI8,0,NULL,0);
4671         VAROR(NULL,0,UI8,1,I4,1);
4672     }
4673     VAROR(NULL,0,INT,0,NULL,0);
4674     VAROR(NULL,0,INT,1,I4,1);
4675     VAROR(NULL,0,UINT,0,NULL,0);
4676     VAROR(NULL,0,UINT,1,I4,1);
4677     VAROR(NULL,0,BOOL,0,NULL,0);
4678     VAROR(NULL,0,BOOL,1,BOOL,1);
4679     VAROR(NULL,0,R4,0,NULL,0);
4680     VAROR(NULL,0,R4,1,I4,1);
4681     VAROR(NULL,0,R8,0,NULL,0);
4682     VAROR(NULL,0,R8,1,I4,1);
4683     rbstr = SysAllocString(szFalse);
4684     VAROR(NULL,0,BSTR,rbstr,NULL,0);
4685     SysFreeString(rbstr);
4686     rbstr = SysAllocString(szTrue);
4687     VAROR(NULL,0,BSTR,rbstr,BOOL,VARIANT_TRUE);
4688     SysFreeString(rbstr);
4689     VARORCY(NULL,0,10000,I4,1);
4690     VARORCY(NULL,0,0,NULL,0);
4691 
4692     VAROR(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
4693     VAROR(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
4694     VAROR(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
4695     VAROR(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
4696     /* Assume x,y & y,x are the same from now on to reduce the number of tests */
4697     VAROR(BOOL,VARIANT_TRUE,I1,-1,I4,-1);
4698     VAROR(BOOL,VARIANT_TRUE,I1,0,I4,-1);
4699     VAROR(BOOL,VARIANT_FALSE,I1,0,I4,0);
4700     VAROR(BOOL,VARIANT_TRUE,UI1,255,I2,-1);
4701     VAROR(BOOL,VARIANT_TRUE,UI1,0,I2,-1);
4702     VAROR(BOOL,VARIANT_FALSE,UI1,0,I2,0);
4703     VAROR(BOOL,VARIANT_TRUE,I2,-1,I2,-1);
4704     VAROR(BOOL,VARIANT_TRUE,I2,0,I2,-1);
4705     VAROR(BOOL,VARIANT_FALSE,I2,0,I2,0);
4706     VAROR(BOOL,VARIANT_TRUE,UI2,65535,I4,-1);
4707     VAROR(BOOL,VARIANT_TRUE,UI2,0,I4,-1);
4708     VAROR(BOOL,VARIANT_FALSE,UI2,0,I4,0);
4709     VAROR(BOOL,VARIANT_TRUE,I4,-1,I4,-1);
4710     VAROR(BOOL,VARIANT_TRUE,I4,0,I4,-1);
4711     VAROR(BOOL,VARIANT_FALSE,I4,0,I4,0);
4712     VAROR(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,-1);
4713     VAROR(BOOL,VARIANT_TRUE,UI4,0,I4,-1);
4714     VAROR(BOOL,VARIANT_FALSE,UI4,0,I4,0);
4715     VAROR(BOOL,VARIANT_TRUE,R4,-1,I4,-1);
4716     VAROR(BOOL,VARIANT_TRUE,R4,0,I4,-1);
4717     VAROR(BOOL,VARIANT_FALSE,R4,0,I4,0);
4718     VAROR(BOOL,VARIANT_TRUE,R8,-1,I4,-1);
4719     VAROR(BOOL,VARIANT_TRUE,R8,0,I4,-1);
4720     VAROR(BOOL,VARIANT_FALSE,R8,0,I4,0);
4721     VAROR(BOOL,VARIANT_TRUE,DATE,-1,I4,-1);
4722     VAROR(BOOL,VARIANT_TRUE,DATE,0,I4,-1);
4723     VAROR(BOOL,VARIANT_FALSE,DATE,0,I4,0);
4724     if (has_i8)
4725     {
4726         VAROR(BOOL,VARIANT_TRUE,I8,-1,I8,-1);
4727         VAROR(BOOL,VARIANT_TRUE,I8,0,I8,-1);
4728         VAROR(BOOL,VARIANT_FALSE,I8,0,I8,0);
4729         /* This returns DISP_E_OVERFLOW which indicates that a conversion
4730          * to I4 is performed.
4731          */
4732         /* VAROR(BOOL,VARIANT_TRUE,UI8,-1,I4,-1); */
4733         VAROR(BOOL,VARIANT_TRUE,UI8,0,I4,-1);
4734         VAROR(BOOL,VARIANT_FALSE,UI8,0,I4,0);
4735     }
4736     VAROR(BOOL,VARIANT_TRUE,INT,-1,I4,-1);
4737     VAROR(BOOL,VARIANT_TRUE,INT,0,I4,-1);
4738     VAROR(BOOL,VARIANT_FALSE,INT,0,I4,0);
4739     VAROR(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,-1);
4740     VAROR(BOOL,VARIANT_TRUE,UINT,0,I4,-1);
4741     VAROR(BOOL,VARIANT_FALSE,UINT,0,I4,0);
4742     rbstr = SysAllocString(szFalse);
4743     VAROR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_FALSE);
4744     VAROR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
4745     SysFreeString(rbstr);
4746     rbstr = SysAllocString(szTrue);
4747     VAROR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_TRUE);
4748     VAROR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
4749     SysFreeString(rbstr);
4750     VARORCY(BOOL,VARIANT_TRUE,10000,I4,-1);
4751     VARORCY(BOOL,VARIANT_TRUE,0,I4,-1);
4752     VARORCY(BOOL,VARIANT_FALSE,0,I4,0);
4753 
4754     VAROR(I1,-1,I1,-1,I4,-1);
4755     VAROR(I1,-1,I1,0,I4,-1);
4756     VAROR(I1,0,I1,0,I4,0);
4757     VAROR(I1,-1,UI1,255,I4,-1);
4758     VAROR(I1,-1,UI1,0,I4,-1);
4759     VAROR(I1,0,UI1,0,I4,0);
4760     VAROR(I1,-1,I2,-1,I4,-1);
4761     VAROR(I1,-1,I2,0,I4,-1);
4762     VAROR(I1,0,I2,0,I4,0);
4763     VAROR(I1,-1,UI2,65535,I4,-1);
4764     VAROR(I1,-1,UI2,0,I4,-1);
4765     VAROR(I1,0,UI2,0,I4,0);
4766     VAROR(I1,-1,I4,-1,I4,-1);
4767     VAROR(I1,-1,I4,0,I4,-1);
4768     VAROR(I1,0,I4,0,I4,0);
4769     VAROR(I1,-1,UI4,0xffffffff,I4,-1);
4770     VAROR(I1,-1,UI4,0,I4,-1);
4771     VAROR(I1,0,UI4,0,I4,0);
4772     VAROR(I1,-1,R4,-1,I4,-1);
4773     VAROR(I1,-1,R4,0,I4,-1);
4774     VAROR(I1,0,R4,0,I4,0);
4775     VAROR(I1,-1,R8,-1,I4,-1);
4776     VAROR(I1,-1,R8,0,I4,-1);
4777     VAROR(I1,0,R8,0,I4,0);
4778     VAROR(I1,-1,DATE,-1,I4,-1);
4779     VAROR(I1,-1,DATE,0,I4,-1);
4780     VAROR(I1,0,DATE,0,I4,0);
4781     if (has_i8)
4782     {
4783         VAROR(I1,-1,I8,-1,I8,-1);
4784         VAROR(I1,-1,I8,0,I8,-1);
4785         VAROR(I1,0,I8,0,I8,0);
4786         VAROR(I1,-1,UI8,0,I4,-1);
4787         VAROR(I1,0,UI8,0,I4,0);
4788     }
4789     VAROR(I1,-1,INT,-1,I4,-1);
4790     VAROR(I1,-1,INT,0,I4,-1);
4791     VAROR(I1,0,INT,0,I4,0);
4792     VAROR(I1,-1,UINT,0xffffffff,I4,-1);
4793     VAROR(I1,-1,UINT,0,I4,-1);
4794     VAROR(I1,0,UINT,0,I4,0);
4795     rbstr = SysAllocString(szFalse);
4796     VAROR(I1,0,BSTR,rbstr,I4,0);
4797     VAROR(I1,-1,BSTR,rbstr,I4,-1);
4798     SysFreeString(rbstr);
4799     rbstr = SysAllocString(szTrue);
4800     VAROR(I1,0,BSTR,rbstr,I4,-1);
4801     VAROR(I1,-1,BSTR,rbstr,I4,-1);
4802     SysFreeString(rbstr);
4803     VARORCY(I1,-1,10000,I4,-1);
4804     VARORCY(I1,-1,0,I4,-1);
4805     VARORCY(I1,0,0,I4,0);
4806 
4807     VAROR(UI1,255,UI1,255,UI1,255);
4808     VAROR(UI1,255,UI1,0,UI1,255);
4809     VAROR(UI1,0,UI1,0,UI1,0);
4810     VAROR(UI1,255,I2,-1,I2,-1);
4811     VAROR(UI1,255,I2,0,I2,255);
4812     VAROR(UI1,0,I2,0,I2,0);
4813     VAROR(UI1,255,UI2,65535,I4,65535);
4814     VAROR(UI1,255,UI2,0,I4,255);
4815     VAROR(UI1,0,UI2,0,I4,0);
4816     VAROR(UI1,255,I4,-1,I4,-1);
4817     VAROR(UI1,255,I4,0,I4,255);
4818     VAROR(UI1,0,I4,0,I4,0);
4819     VAROR(UI1,255,UI4,0xffffffff,I4,-1);
4820     VAROR(UI1,255,UI4,0,I4,255);
4821     VAROR(UI1,0,UI4,0,I4,0);
4822     VAROR(UI1,255,R4,-1,I4,-1);
4823     VAROR(UI1,255,R4,0,I4,255);
4824     VAROR(UI1,0,R4,0,I4,0);
4825     VAROR(UI1,255,R8,-1,I4,-1);
4826     VAROR(UI1,255,R8,0,I4,255);
4827     VAROR(UI1,0,R8,0,I4,0);
4828     VAROR(UI1,255,DATE,-1,I4,-1);
4829     VAROR(UI1,255,DATE,0,I4,255);
4830     VAROR(UI1,0,DATE,0,I4,0);
4831     if (has_i8)
4832     {
4833         VAROR(UI1,255,I8,-1,I8,-1);
4834         VAROR(UI1,255,I8,0,I8,255);
4835         VAROR(UI1,0,I8,0,I8,0);
4836         VAROR(UI1,255,UI8,0,I4,255);
4837         VAROR(UI1,0,UI8,0,I4,0);
4838     }
4839     VAROR(UI1,255,INT,-1,I4,-1);
4840     VAROR(UI1,255,INT,0,I4,255);
4841     VAROR(UI1,0,INT,0,I4,0);
4842     VAROR(UI1,255,UINT,0xffffffff,I4,-1);
4843     VAROR(UI1,255,UINT,0,I4,255);
4844     VAROR(UI1,0,UINT,0,I4,0);
4845     rbstr = SysAllocString(szFalse);
4846     VAROR(UI1,0,BSTR,rbstr,I2,0);
4847     VAROR(UI1,255,BSTR,rbstr,I2,255);
4848     SysFreeString(rbstr);
4849     rbstr = SysAllocString(szTrue);
4850     VAROR(UI1,0,BSTR,rbstr,I2,-1);
4851     VAROR(UI1,255,BSTR,rbstr,I2,-1);
4852     SysFreeString(rbstr);
4853     VARORCY(UI1,255,10000,I4,255);
4854     VARORCY(UI1,255,0,I4,255);
4855     VARORCY(UI1,0,0,I4,0);
4856 
4857     VAROR(I2,-1,I2,-1,I2,-1);
4858     VAROR(I2,-1,I2,0,I2,-1);
4859     VAROR(I2,0,I2,0,I2,0);
4860     VAROR(I2,-1,UI2,65535,I4,-1);
4861     VAROR(I2,-1,UI2,0,I4,-1);
4862     VAROR(I2,0,UI2,0,I4,0);
4863     VAROR(I2,-1,I4,-1,I4,-1);
4864     VAROR(I2,-1,I4,0,I4,-1);
4865     VAROR(I2,0,I4,0,I4,0);
4866     VAROR(I2,-1,UI4,0xffffffff,I4,-1);
4867     VAROR(I2,-1,UI4,0,I4,-1);
4868     VAROR(I2,0,UI4,0,I4,0);
4869     VAROR(I2,-1,R4,-1,I4,-1);
4870     VAROR(I2,-1,R4,0,I4,-1);
4871     VAROR(I2,0,R4,0,I4,0);
4872     VAROR(I2,-1,R8,-1,I4,-1);
4873     VAROR(I2,-1,R8,0,I4,-1);
4874     VAROR(I2,0,R8,0,I4,0);
4875     VAROR(I2,-1,DATE,-1,I4,-1);
4876     VAROR(I2,-1,DATE,0,I4,-1);
4877     VAROR(I2,0,DATE,0,I4,0);
4878     if (has_i8)
4879     {
4880         VAROR(I2,-1,I8,-1,I8,-1);
4881         VAROR(I2,-1,I8,0,I8,-1);
4882         VAROR(I2,0,I8,0,I8,0);
4883         VAROR(I2,-1,UI8,0,I4,-1);
4884         VAROR(I2,0,UI8,0,I4,0);
4885     }
4886     VAROR(I2,-1,INT,-1,I4,-1);
4887     VAROR(I2,-1,INT,0,I4,-1);
4888     VAROR(I2,0,INT,0,I4,0);
4889     VAROR(I2,-1,UINT,0xffffffff,I4,-1);
4890     VAROR(I2,-1,UINT,0,I4,-1);
4891     VAROR(I2,0,UINT,0,I4,0);
4892     rbstr = SysAllocString(szFalse);
4893     VAROR(I2,0,BSTR,rbstr,I2,0);
4894     VAROR(I2,-1,BSTR,rbstr,I2,-1);
4895     SysFreeString(rbstr);
4896     rbstr = SysAllocString(szTrue);
4897     VAROR(I2,0,BSTR,rbstr,I2,-1);
4898     VAROR(I2,-1,BSTR,rbstr,I2,-1);
4899     SysFreeString(rbstr);
4900     VARORCY(I2,-1,10000,I4,-1);
4901     VARORCY(I2,-1,0,I4,-1);
4902     VARORCY(I2,0,0,I4,0);
4903 
4904     VAROR(UI2,65535,UI2,65535,I4,65535);
4905     VAROR(UI2,65535,UI2,0,I4,65535);
4906     VAROR(UI2,0,UI2,0,I4,0);
4907     VAROR(UI2,65535,I4,-1,I4,-1);
4908     VAROR(UI2,65535,I4,0,I4,65535);
4909     VAROR(UI2,0,I4,0,I4,0);
4910     VAROR(UI2,65535,UI4,0xffffffff,I4,-1);
4911     VAROR(UI2,65535,UI4,0,I4,65535);
4912     VAROR(UI2,0,UI4,0,I4,0);
4913     VAROR(UI2,65535,R4,-1,I4,-1);
4914     VAROR(UI2,65535,R4,0,I4,65535);
4915     VAROR(UI2,0,R4,0,I4,0);
4916     VAROR(UI2,65535,R8,-1,I4,-1);
4917     VAROR(UI2,65535,R8,0,I4,65535);
4918     VAROR(UI2,0,R8,0,I4,0);
4919     VAROR(UI2,65535,DATE,-1,I4,-1);
4920     VAROR(UI2,65535,DATE,0,I4,65535);
4921     VAROR(UI2,0,DATE,0,I4,0);
4922     if (has_i8)
4923     {
4924         VAROR(UI2,65535,I8,-1,I8,-1);
4925         VAROR(UI2,65535,I8,0,I8,65535);
4926         VAROR(UI2,0,I8,0,I8,0);
4927         VAROR(UI2,65535,UI8,0,I4,65535);
4928         VAROR(UI2,0,UI8,0,I4,0);
4929     }
4930     VAROR(UI2,65535,INT,-1,I4,-1);
4931     VAROR(UI2,65535,INT,0,I4,65535);
4932     VAROR(UI2,0,INT,0,I4,0);
4933     VAROR(UI2,65535,UINT,0xffffffff,I4,-1);
4934     VAROR(UI2,65535,UINT,0,I4,65535);
4935     VAROR(UI2,0,UINT,0,I4,0);
4936     rbstr = SysAllocString(szFalse);
4937     VAROR(UI2,0,BSTR,rbstr,I4,0);
4938     VAROR(UI2,65535,BSTR,rbstr,I4,65535);
4939     SysFreeString(rbstr);
4940     rbstr = SysAllocString(szTrue);
4941     VAROR(UI2,0,BSTR,rbstr,I4,-1);
4942     VAROR(UI2,65535,BSTR,rbstr,I4,-1);
4943     SysFreeString(rbstr);
4944     VARORCY(UI2,65535,10000,I4,65535);
4945     VARORCY(UI2,65535,0,I4,65535);
4946     VARORCY(UI2,0,0,I4,0);
4947 
4948     VAROR(I4,-1,I4,-1,I4,-1);
4949     VAROR(I4,-1,I4,0,I4,-1);
4950     VAROR(I4,0,I4,0,I4,0);
4951     VAROR(I4,-1,UI4,0xffffffff,I4,-1);
4952     VAROR(I4,-1,UI4,0,I4,-1);
4953     VAROR(I4,0,UI4,0,I4,0);
4954     VAROR(I4,-1,R4,-1,I4,-1);
4955     VAROR(I4,-1,R4,0,I4,-1);
4956     VAROR(I4,0,R4,0,I4,0);
4957     VAROR(I4,-1,R8,-1,I4,-1);
4958     VAROR(I4,-1,R8,0,I4,-1);
4959     VAROR(I4,0,R8,0,I4,0);
4960     VAROR(I4,-1,DATE,-1,I4,-1);
4961     VAROR(I4,-1,DATE,0,I4,-1);
4962     VAROR(I4,0,DATE,0,I4,0);
4963     if (has_i8)
4964     {
4965         VAROR(I4,-1,I8,-1,I8,-1);
4966         VAROR(I4,-1,I8,0,I8,-1);
4967         VAROR(I4,0,I8,0,I8,0);
4968         VAROR(I4,-1,UI8,0,I4,-1);
4969         VAROR(I4,0,UI8,0,I4,0);
4970     }
4971     VAROR(I4,-1,INT,-1,I4,-1);
4972     VAROR(I4,-1,INT,0,I4,-1);
4973     VAROR(I4,0,INT,0,I4,0);
4974     VAROR(I4,-1,UINT,0xffffffff,I4,-1);
4975     VAROR(I4,-1,UINT,0,I4,-1);
4976     VAROR(I4,0,UINT,0,I4,0);
4977     rbstr = SysAllocString(szFalse);
4978     VAROR(I4,0,BSTR,rbstr,I4,0);
4979     VAROR(I4,-1,BSTR,rbstr,I4,-1);
4980     SysFreeString(rbstr);
4981     rbstr = SysAllocString(szTrue);
4982     VAROR(I4,0,BSTR,rbstr,I4,-1);
4983     VAROR(I4,-1,BSTR,rbstr,I4,-1);
4984     SysFreeString(rbstr);
4985     VARORCY(I4,-1,10000,I4,-1);
4986     VARORCY(I4,-1,0,I4,-1);
4987     VARORCY(I4,0,0,I4,0);
4988 
4989     VAROR(UI4,0xffffffff,UI4,0xffffffff,I4,-1);
4990     VAROR(UI4,0xffffffff,UI4,0,I4,-1);
4991     VAROR(UI4,0,UI4,0,I4,0);
4992     VAROR(UI4,0xffffffff,R4,-1,I4,-1);
4993     VAROR(UI4,0xffffffff,R4,0,I4,-1);
4994     VAROR(UI4,0,R4,0,I4,0);
4995     VAROR(UI4,0xffffffff,R8,-1,I4,-1);
4996     VAROR(UI4,0xffffffff,R8,0,I4,-1);
4997     VAROR(UI4,0,R8,0,I4,0);
4998     VAROR(UI4,0xffffffff,DATE,-1,I4,-1);
4999     VAROR(UI4,0xffffffff,DATE,0,I4,-1);
5000     VAROR(UI4,0,DATE,0,I4,0);
5001     if (has_i8)
5002     {
5003         VAROR(UI4,0xffffffff,I8,-1,I8,-1);
5004         VAROR(UI4,0xffffffff,I8,0,I8,0xffffffff);
5005         VAROR(UI4,0,I8,0,I8,0);
5006         VAROR(UI4,0xffffffff,UI8,0,I4,-1);
5007         VAROR(UI4,0,UI8,0,I4,0);
5008     }
5009     VAROR(UI4,0xffffffff,INT,-1,I4,-1);
5010     VAROR(UI4,0xffffffff,INT,0,I4,-1);
5011     VAROR(UI4,0,INT,0,I4,0);
5012     VAROR(UI4,0xffffffff,UINT,0xffffffff,I4,-1);
5013     VAROR(UI4,0xffffffff,UINT,0,I4,-1);
5014     VAROR(UI4,0,UINT,0,I4,0);
5015     rbstr = SysAllocString(szFalse);
5016     VAROR(UI4,0,BSTR,rbstr,I4,0);
5017     VAROR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
5018     SysFreeString(rbstr);
5019     rbstr = SysAllocString(szTrue);
5020     VAROR(UI4,0,BSTR,rbstr,I4,-1);
5021     VAROR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
5022     SysFreeString(rbstr);
5023     VARORCY(UI4,0xffffffff,10000,I4,-1);
5024     VARORCY(UI4,0xffffffff,0,I4,-1);
5025     VARORCY(UI4,0,0,I4,0);
5026 
5027     VAROR(R4,-1,R4,-1,I4,-1);
5028     VAROR(R4,-1,R4,0,I4,-1);
5029     VAROR(R4,0,R4,0,I4,0);
5030     VAROR(R4,-1,R8,-1,I4,-1);
5031     VAROR(R4,-1,R8,0,I4,-1);
5032     VAROR(R4,0,R8,0,I4,0);
5033     VAROR(R4,-1,DATE,-1,I4,-1);
5034     VAROR(R4,-1,DATE,0,I4,-1);
5035     VAROR(R4,0,DATE,0,I4,0);
5036     if (has_i8)
5037     {
5038         VAROR(R4,-1,I8,-1,I8,-1);
5039         VAROR(R4,-1,I8,0,I8,-1);
5040         VAROR(R4,0,I8,0,I8,0);
5041         VAROR(R4,-1,UI8,0,I4,-1);
5042         VAROR(R4,0,UI8,0,I4,0);
5043     }
5044     VAROR(R4,-1,INT,-1,I4,-1);
5045     VAROR(R4,-1,INT,0,I4,-1);
5046     VAROR(R4,0,INT,0,I4,0);
5047     VAROR(R4,-1,UINT,0xffffffff,I4,-1);
5048     VAROR(R4,-1,UINT,0,I4,-1);
5049     VAROR(R4,0,UINT,0,I4,0);
5050     rbstr = SysAllocString(szFalse);
5051     VAROR(R4,0,BSTR,rbstr,I4,0);
5052     VAROR(R4,-1,BSTR,rbstr,I4,-1);
5053     SysFreeString(rbstr);
5054     rbstr = SysAllocString(szTrue);
5055     VAROR(R4,0,BSTR,rbstr,I4,-1);
5056     VAROR(R4,-1,BSTR,rbstr,I4,-1);
5057     SysFreeString(rbstr);
5058     VARORCY(R4,-1,10000,I4,-1);
5059     VARORCY(R4,-1,0,I4,-1);
5060     VARORCY(R4,0,0,I4,0);
5061 
5062     VAROR(R8,-1,R8,-1,I4,-1);
5063     VAROR(R8,-1,R8,0,I4,-1);
5064     VAROR(R8,0,R8,0,I4,0);
5065     VAROR(R8,-1,DATE,-1,I4,-1);
5066     VAROR(R8,-1,DATE,0,I4,-1);
5067     VAROR(R8,0,DATE,0,I4,0);
5068     if (has_i8)
5069     {
5070         VAROR(R8,-1,I8,-1,I8,-1);
5071         VAROR(R8,-1,I8,0,I8,-1);
5072         VAROR(R8,0,I8,0,I8,0);
5073         VAROR(R8,-1,UI8,0,I4,-1);
5074         VAROR(R8,0,UI8,0,I4,0);
5075     }
5076     VAROR(R8,-1,INT,-1,I4,-1);
5077     VAROR(R8,-1,INT,0,I4,-1);
5078     VAROR(R8,0,INT,0,I4,0);
5079     VAROR(R8,-1,UINT,0xffffffff,I4,-1);
5080     VAROR(R8,-1,UINT,0,I4,-1);
5081     VAROR(R8,0,UINT,0,I4,0);
5082     rbstr = SysAllocString(szFalse);
5083     VAROR(R8,0,BSTR,rbstr,I4,0);
5084     VAROR(R8,-1,BSTR,rbstr,I4,-1);
5085     SysFreeString(rbstr);
5086     rbstr = SysAllocString(szTrue);
5087     VAROR(R8,0,BSTR,rbstr,I4,-1);
5088     VAROR(R8,-1,BSTR,rbstr,I4,-1);
5089     SysFreeString(rbstr);
5090     VARORCY(R8,-1,10000,I4,-1);
5091     VARORCY(R8,-1,0,I4,-1);
5092     VARORCY(R8,0,0,I4,0);
5093 
5094     VAROR(DATE,-1,DATE,-1,I4,-1);
5095     VAROR(DATE,-1,DATE,0,I4,-1);
5096     VAROR(DATE,0,DATE,0,I4,0);
5097     if (has_i8)
5098     {
5099         VAROR(DATE,-1,I8,-1,I8,-1);
5100         VAROR(DATE,-1,I8,0,I8,-1);
5101         VAROR(DATE,0,I8,0,I8,0);
5102         VAROR(DATE,-1,UI8,0,I4,-1);
5103         VAROR(DATE,0,UI8,0,I4,0);
5104     }
5105     VAROR(DATE,-1,INT,-1,I4,-1);
5106     VAROR(DATE,-1,INT,0,I4,-1);
5107     VAROR(DATE,0,INT,0,I4,0);
5108     VAROR(DATE,-1,UINT,0xffffffff,I4,-1);
5109     VAROR(DATE,-1,UINT,0,I4,-1);
5110     VAROR(DATE,0,UINT,0,I4,0);
5111     rbstr = SysAllocString(szFalse);
5112     VAROR(DATE,0,BSTR,rbstr,I4,0);
5113     VAROR(DATE,-1,BSTR,rbstr,I4,-1);
5114     SysFreeString(rbstr);
5115     rbstr = SysAllocString(szTrue);
5116     VAROR(DATE,0,BSTR,rbstr,I4,-1);
5117     VAROR(DATE,-1,BSTR,rbstr,I4,-1);
5118     SysFreeString(rbstr);
5119     VARORCY(DATE,-1,10000,I4,-1);
5120     VARORCY(DATE,-1,0,I4,-1);
5121     VARORCY(DATE,0,0,I4,0);
5122 
5123     if (has_i8)
5124     {
5125         VAROR(I8,-1,I8,-1,I8,-1);
5126         VAROR(I8,-1,I8,0,I8,-1);
5127         VAROR(I8,0,I8,0,I8,0);
5128         VAROR(I8,-1,UI8,0,I8,-1);
5129         VAROR(I8,0,UI8,0,I8,0);
5130         /* These overflow under native and Wine
5131         VAROR(I8,-1,INT,-1,I4,-1);
5132         VAROR(I8,-1,INT,0,I4,-1);
5133         VAROR(I8,0,INT,0,I4,0); */
5134         VAROR(I8,-1,UINT,0xffffffff,I8,-1);
5135         VAROR(I8,-1,UINT,0,I8,-1);
5136         VAROR(I8,0,UINT,0,I8,0);
5137         rbstr = SysAllocString(szFalse);
5138         VAROR(I8,0,BSTR,rbstr,I8,0);
5139         VAROR(I8,-1,BSTR,rbstr,I8,-1);
5140         SysFreeString(rbstr);
5141         rbstr = SysAllocString(szTrue);
5142         VAROR(I8,0,BSTR,rbstr,I8,-1);
5143         VAROR(I8,-1,BSTR,rbstr,I8,-1);
5144         SysFreeString(rbstr);
5145         VARORCY(I8,-1,10000,I8,-1);
5146         VARORCY(I8,-1,0,I8,-1);
5147         VARORCY(I8,0,0,I8,0);
5148 
5149         VAROR(UI8,0xffff,UI8,0xffff,I4,0xffff);
5150         VAROR(UI8,0xffff,UI8,0,I4,0xffff);
5151         VAROR(UI8,0,UI8,0,I4,0);
5152         VAROR(UI8,0xffff,INT,-1,I4,-1);
5153         VAROR(UI8,0xffff,INT,0,I4,0xffff);
5154         VAROR(UI8,0,INT,0,I4,0);
5155         VAROR(UI8,0xffff,UINT,0xffff,I4,0xffff);
5156         VAROR(UI8,0xffff,UINT,0,I4,0xffff);
5157         VAROR(UI8,0,UINT,0,I4,0);
5158         rbstr = SysAllocString(szFalse);
5159         VAROR(UI8,0,BSTR,rbstr,I4,0);
5160         VAROR(UI8,0xffff,BSTR,rbstr,I4,0xffff);
5161         SysFreeString(rbstr);
5162         rbstr = SysAllocString(szTrue);
5163         VAROR(UI8,0,BSTR,rbstr,I4,-1);
5164         VAROR(UI8,0xffff,BSTR,rbstr,I4,-1);
5165         SysFreeString(rbstr);
5166         VARORCY(UI8,0xffff,10000,I4,0xffff);
5167         VARORCY(UI8,0xffff,0,I4,0xffff);
5168         VARORCY(UI8,0,0,I4,0);
5169     }
5170 
5171     VAROR(INT,-1,INT,-1,I4,-1);
5172     VAROR(INT,-1,INT,0,I4,-1);
5173     VAROR(INT,0,INT,0,I4,0);
5174     VAROR(INT,-1,UINT,0xffff,I4,-1);
5175     VAROR(INT,-1,UINT,0,I4,-1);
5176     VAROR(INT,0,UINT,0,I4,0);
5177     rbstr = SysAllocString(szFalse);
5178     VAROR(INT,0,BSTR,rbstr,I4,0);
5179     VAROR(INT,-1,BSTR,rbstr,I4,-1);
5180     SysFreeString(rbstr);
5181     rbstr = SysAllocString(szTrue);
5182     VAROR(INT,0,BSTR,rbstr,I4,-1);
5183     VAROR(INT,-1,BSTR,rbstr,I4,-1);
5184     SysFreeString(rbstr);
5185     VARORCY(INT,-1,10000,I4,-1);
5186     VARORCY(INT,-1,0,I4,-1);
5187     VARORCY(INT,0,0,I4,0);
5188 
5189     VAROR(UINT,0xffff,UINT,0xffff,I4,0xffff);
5190     VAROR(UINT,0xffff,UINT,0,I4,0xffff);
5191     VAROR(UINT,0,UINT,0,I4,0);
5192     rbstr = SysAllocString(szFalse);
5193     VAROR(UINT,0,BSTR,rbstr,I4,0);
5194     VAROR(UINT,0xffff,BSTR,rbstr,I4,0xffff);
5195     SysFreeString(rbstr);
5196     rbstr = SysAllocString(szTrue);
5197     VAROR(UINT,0,BSTR,rbstr,I4,-1);
5198     VAROR(UINT,0xffff,BSTR,rbstr,I4,-1);
5199     SysFreeString(rbstr);
5200     VARORCY(UINT,0xffff,10000,I4,0xffff);
5201     VARORCY(UINT,0xffff,0,I4,0xffff);
5202     VARORCY(UINT,0,0,I4,0);
5203 
5204     lbstr = SysAllocString(szFalse);
5205     rbstr = SysAllocString(szFalse);
5206     VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,0);
5207     SysFreeString(rbstr);
5208     rbstr = SysAllocString(szTrue);
5209     VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
5210     SysFreeString(lbstr);
5211     lbstr = SysAllocString(szTrue);
5212     VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
5213     VARORCY(BSTR,lbstr,10000,I4,-1);
5214     SysFreeString(lbstr);
5215     lbstr = SysAllocString(szFalse);
5216     VARORCY(BSTR,lbstr,10000,I4,1);
5217     SysFreeString(lbstr);
5218     SysFreeString(rbstr);
5219 }
5220 
5221 static HRESULT (WINAPI *pVarEqv)(LPVARIANT,LPVARIANT,LPVARIANT);
5222 
5223 #define VAREQV(vt1,val1,vt2,val2,rvt,rval)           \
5224     V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
5225     V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
5226     V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
5227     test_var_call2( __LINE__, pVarEqv, &left, &right, &exp )
5228 
5229 static void test_VarEqv(void)
5230 {
5231     VARIANT left, right, exp, result;
5232     VARTYPE i;
5233     HRESULT hres;
5234 
5235     CHECKPTR(VarEqv);
5236 
5237     /* Test all possible flag/vt combinations & the resulting vt type */
5238     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
5239     {
5240         VARTYPE leftvt, rightvt, resvt;
5241 
5242         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
5243         {
5244             SKIPTESTS(leftvt);
5245 
5246             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
5247             {
5248                 BOOL bFail = FALSE;
5249 
5250                 SKIPTESTS(rightvt);
5251 
5252                 if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
5253                     leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
5254                     leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
5255                     continue;
5256 
5257                 memset(&left, 0, sizeof(left));
5258                 memset(&right, 0, sizeof(right));
5259                 V_VT(&left) = leftvt | ExtraFlags[i];
5260                 V_VT(&right) = rightvt | ExtraFlags[i];
5261                 V_VT(&result) = VT_EMPTY;
5262                 resvt = VT_I4;
5263 
5264                 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
5265                     !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
5266                     !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
5267                     leftvt == VT_CLSID || rightvt == VT_CLSID ||
5268                     leftvt == VT_RECORD || rightvt == VT_RECORD ||
5269                     leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
5270                     leftvt == VT_ERROR || rightvt == VT_ERROR)
5271                 {
5272                     bFail = TRUE;
5273                 }
5274                 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
5275                 {
5276                     if (leftvt == rightvt ||
5277                         leftvt == VT_I2 || rightvt == VT_I2 ||
5278                         leftvt == VT_UI1 || rightvt == VT_UI1 ||
5279                         leftvt == VT_BOOL || rightvt == VT_BOOL)
5280                         resvt = VT_I2;
5281                     else if (leftvt == VT_NULL || rightvt == VT_NULL)
5282                         resvt = VT_NULL;
5283                     else if (leftvt == VT_I8 || rightvt == VT_I8)
5284                         resvt = VT_I8;
5285                 }
5286                 else if (leftvt == VT_NULL || rightvt == VT_NULL)
5287                 {
5288                     resvt = VT_NULL;
5289                 }
5290                 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
5291                 {
5292                     if (leftvt == rightvt)
5293                         resvt = VT_UI1;
5294                     else if (leftvt == rightvt ||
5295                         leftvt == VT_I2 || rightvt == VT_I2 ||
5296                         leftvt == VT_BOOL || rightvt == VT_BOOL)
5297                     {
5298                         resvt = VT_I2;
5299                     }
5300                     else if (leftvt == VT_I8 || rightvt == VT_I8)
5301                         resvt = VT_I8;
5302                 }
5303                 else if (leftvt == VT_I2 || rightvt == VT_I2)
5304                 {
5305                     if (leftvt == rightvt ||
5306                         leftvt == VT_BOOL || rightvt == VT_BOOL)
5307                         resvt = VT_I2;
5308                     else if (leftvt == VT_I8 || rightvt == VT_I8)
5309                         resvt = VT_I8;
5310                 }
5311                 else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
5312                 {
5313                     resvt = VT_BOOL;
5314                 }
5315                 else if (leftvt == VT_I8 || rightvt == VT_I8)
5316                 {
5317                     if (leftvt == VT_INT || rightvt == VT_INT)
5318                         bFail = TRUE;
5319                     else
5320                         resvt = VT_I8;
5321                 }
5322                 hres = pVarEqv(&left, &right, &result);
5323                 if (bFail)
5324                     ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
5325                        "VarEqv: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
5326                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
5327                        V_VT(&result));
5328                 else
5329                     ok(hres == S_OK && V_VT(&result) == resvt,
5330                        "VarEqv: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
5331                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
5332                        V_VT(&result));
5333             }
5334         }
5335     }
5336 
5337     /* Test returned values */
5338     VAREQV(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
5339     VAREQV(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
5340     VAREQV(BOOL,TRUE,BOOL,TRUE,BOOL,VARIANT_TRUE);
5341     VAREQV(BOOL,FALSE,BOOL,FALSE,BOOL,VARIANT_TRUE);
5342     VAREQV(BOOL,TRUE,BOOL,FALSE,BOOL,-2);
5343     VAREQV(BOOL,FALSE,BOOL,TRUE,BOOL,-2);
5344     VAREQV(BOOL,6,BOOL,7,BOOL,-2);
5345     VAREQV(BOOL,6,BOOL,6,BOOL,VARIANT_TRUE);
5346     VAREQV(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE,I2,VARIANT_TRUE);
5347     VAREQV(BOOL,VARIANT_TRUE,I2,VARIANT_FALSE,I2,VARIANT_FALSE);
5348     VAREQV(BOOL,6,I2,7,I2,-2);
5349     VAREQV(UI1,1,UI1,1,UI1,255);
5350     VAREQV(UI1,1,UI1,0,UI1,254);
5351     VAREQV(UI1,0,UI1,1,UI1,254);
5352     if (has_i8)
5353     {
5354         VAREQV(UI4,VARIANT_FALSE,I8,VARIANT_FALSE,I8,-1);
5355         VAREQV(UI4,5,I8,19,I8,-23);
5356         VAREQV(UI4,VARIANT_FALSE,UI8,VARIANT_FALSE,I4,-1);
5357     }
5358 }
5359 
5360 static HRESULT (WINAPI *pVarMul)(LPVARIANT,LPVARIANT,LPVARIANT);
5361 
5362 #define VARMUL(vt1,val1,vt2,val2,rvt,rval)               \
5363         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
5364         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
5365         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
5366         test_var_call2( __LINE__, pVarMul, &left, &right, &exp )
5367 
5368 static void test_VarMul(void)
5369 {
5370     VARIANT left, right, exp, result, cy, dec;
5371     VARTYPE i;
5372     BSTR lbstr, rbstr;
5373     HRESULT hres;
5374     double r;
5375 
5376     CHECKPTR(VarMul);
5377 
5378     lbstr = SysAllocString(sz12);
5379     rbstr = SysAllocString(sz12);
5380 
5381     /* Test all possible flag/vt combinations & the resulting vt type */
5382     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
5383     {
5384         VARTYPE leftvt, rightvt, resvt;
5385 
5386         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
5387         {
5388 
5389             SKIPTESTS(leftvt);
5390 
5391             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
5392             {
5393                 BOOL bFail = FALSE;
5394 
5395                 SKIPTESTS(rightvt);
5396 
5397                 if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
5398                     leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
5399                     continue;
5400 
5401                 memset(&left, 0, sizeof(left));
5402                 memset(&right, 0, sizeof(right));
5403                 V_VT(&left) = leftvt | ExtraFlags[i];
5404                 if (leftvt == VT_BSTR)
5405                     V_BSTR(&left) = lbstr;
5406                 V_VT(&right) = rightvt | ExtraFlags[i];
5407                 if (rightvt == VT_BSTR)
5408                     V_BSTR(&right) = rbstr;
5409                 V_VT(&result) = VT_EMPTY;
5410                 resvt = VT_UNKNOWN;
5411 
5412                 /* Don't ask me why but native VarMul cannot handle:
5413                    VT_I1, VT_UI2, VT_UI4, VT_INT, VT_UINT and VT_UI8.
5414                    Tested with DCOM98, Win2k, WinXP */
5415                 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
5416                     !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
5417                     !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
5418                     leftvt == VT_CLSID || rightvt == VT_CLSID ||
5419                     leftvt == VT_RECORD || rightvt == VT_RECORD ||
5420                     leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
5421                     leftvt == VT_ERROR || rightvt == VT_ERROR ||
5422                     leftvt == VT_I1 || rightvt == VT_I1 ||
5423                     leftvt == VT_UI2 || rightvt == VT_UI2 ||
5424                     leftvt == VT_UI4 || rightvt == VT_UI4 ||
5425                     leftvt == VT_UI8 || rightvt == VT_UI8 ||
5426                     leftvt == VT_INT || rightvt == VT_INT ||
5427                     leftvt == VT_UINT || rightvt == VT_UINT) {
5428                     bFail = TRUE;
5429                 }
5430 
5431                 if (leftvt == VT_NULL || rightvt == VT_NULL)
5432                     resvt = VT_NULL;
5433                 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
5434                     resvt = VT_DECIMAL;
5435                 else if (leftvt == VT_R8 || rightvt == VT_R8 ||
5436                          leftvt == VT_BSTR || rightvt == VT_BSTR ||
5437                          leftvt == VT_DATE || rightvt == VT_DATE)
5438                     resvt = VT_R8;
5439                 else if (leftvt == VT_R4 || rightvt == VT_R4) {
5440                     if (leftvt == VT_I4 || rightvt == VT_I4 ||
5441                         leftvt == VT_I8 || rightvt == VT_I8 ||
5442                         leftvt == VT_CY || rightvt == VT_CY)
5443                         resvt = VT_R8;
5444                     else
5445                         resvt = VT_R4;
5446                 } else if (leftvt == VT_CY || rightvt == VT_CY)
5447                     resvt = VT_CY;
5448                 else if (leftvt == VT_I8 || rightvt == VT_I8)
5449                     resvt = VT_I8;
5450                 else if (leftvt == VT_I4 || rightvt == VT_I4)
5451                     resvt = VT_I4;
5452                 else if (leftvt == VT_I2 || rightvt == VT_I2 ||
5453                          leftvt == VT_BOOL || rightvt == VT_BOOL ||
5454                          (leftvt == VT_EMPTY && rightvt == VT_EMPTY))
5455                     resvt = VT_I2;
5456                 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
5457                     resvt = VT_UI1;
5458 
5459                 hres = pVarMul(&left, &right, &result);
5460                 if (bFail) {
5461                     ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
5462                        "VarMul: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
5463                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
5464                        V_VT(&result));
5465                 } else {
5466                     ok(hres == S_OK && V_VT(&result) == resvt,
5467                        "VarMul: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
5468                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
5469                        V_VT(&result));
5470                 }
5471             }
5472         }
5473     }
5474 
5475     /* Test returned values */
5476     VARMUL(I4,4,I4,2,I4,8);
5477     VARMUL(I2,4,I2,2,I2,8);
5478     VARMUL(I2,-13,I4,5,I4,-65);
5479     VARMUL(I4,-13,I4,5,I4,-65);
5480     VARMUL(I2,7,R4,0.5f,R4,3.5f);
5481     VARMUL(R4,0.5f,I4,5,R8,2.5);
5482     VARMUL(R8,7.1,BOOL,0,R8,0);
5483     VARMUL(BSTR,lbstr,I2,4,R8,48);
5484     VARMUL(BSTR,lbstr,BOOL,1,R8,12);
5485     VARMUL(BSTR,lbstr,R4,0.1f,R8,1.2);
5486     VARMUL(BSTR,lbstr,BSTR,rbstr,R8,144);
5487     VARMUL(R4,0.2f,BSTR,rbstr,R8,2.4);
5488     VARMUL(DATE,2.25,I4,7,R8,15.75);
5489 
5490     VARMUL(UI1, UI1_MAX, UI1, UI1_MAX, I4, UI1_MAX * UI1_MAX);
5491     VARMUL(I2, I2_MAX, I2, I2_MAX, I4, I2_MAX * I2_MAX);
5492     VARMUL(I2, I2_MAX, I2, I2_MIN, I4, I2_MAX * I2_MIN);
5493     VARMUL(I2, I2_MIN, I2, I2_MIN, I4, I2_MIN * I2_MIN);
5494     VARMUL(I4, I4_MAX, I4, I4_MAX, R8, (double)I4_MAX * I4_MAX);
5495     VARMUL(I4, I4_MAX, I4, I4_MIN, R8, (double)I4_MAX * I4_MIN);
5496     VARMUL(I4, I4_MIN, I4, I4_MIN, R8, (double)I4_MIN * I4_MIN);
5497     VARMUL(R4, R4_MAX, R4, R4_MAX, R8, (double)R4_MAX * R4_MAX);
5498     VARMUL(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX * R4_MIN);
5499     VARMUL(R4, R4_MIN, R4, R4_MIN, R4, R4_MIN * R4_MIN);
5500     VARMUL(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX * R8_MIN);
5501     VARMUL(R8, R8_MIN, R8, R8_MIN, R8, R8_MIN * R8_MIN);
5502 
5503     /* Manuly test some VT_CY and VT_DECIMAL variants */
5504     V_VT(&cy) = VT_CY;
5505     hres = VarCyFromI4(4711, &V_CY(&cy));
5506     ok(hres == S_OK, "VarCyFromI4 failed!\n");
5507     V_VT(&dec) = VT_DECIMAL;
5508     hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec));
5509     ok(hres == S_OK, "VarDecFromR4 failed!\n");
5510     memset(&left, 0, sizeof(left));
5511     memset(&right, 0, sizeof(right));
5512     V_VT(&left) = VT_I4;
5513     V_I4(&left) = -11;
5514     V_VT(&right) = VT_UI1;
5515     V_UI1(&right) = 9;
5516 
5517     hres = pVarMul(&cy, &right, &result);
5518     ok(hres == S_OK && V_VT(&result) == VT_CY, "VarMul: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result)));
5519     hres = VarR8FromCy(V_CY(&result), &r);
5520     ok(hres == S_OK && EQ_DOUBLE(r, 42399.0), "VarMul: CY value %f, expected %f\n", r, (double)42399);
5521 
5522     hres = pVarMul(&left, &dec, &result);
5523     ok(hres == S_OK && V_VT(&result) == VT_DECIMAL, "VarMul: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
5524     hres = VarR8FromDec(&V_DECIMAL(&result), &r);
5525     ok(hres == S_OK && EQ_DOUBLE(r, 46.2), "VarMul: DECIMAL value %f, expected %f\n", r, (double)46.2);
5526 
5527     SysFreeString(lbstr);
5528     SysFreeString(rbstr);
5529 }
5530 
5531 static HRESULT (WINAPI *pVarAdd)(LPVARIANT,LPVARIANT,LPVARIANT);
5532 
5533 #define VARADD(vt1,val1,vt2,val2,rvt,rval)               \
5534         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
5535         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
5536         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
5537         test_var_call2( __LINE__, pVarAdd, &left, &right, &exp )
5538 
5539 static void test_VarAdd(void)
5540 {
5541     VARIANT left, right, exp, result, cy, dec;
5542     VARTYPE i;
5543     BSTR lbstr, rbstr;
5544     HRESULT hres;
5545     double r;
5546 
5547     CHECKPTR(VarAdd);
5548 
5549     lbstr = SysAllocString(sz12);
5550     rbstr = SysAllocString(sz12);
5551 
5552     /* Test all possible flag/vt combinations & the resulting vt type */
5553     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
5554     {
5555         VARTYPE leftvt, rightvt, resvt;
5556 
5557         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
5558         {
5559 
5560             SKIPTESTS(leftvt);
5561 
5562             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
5563             {
5564                 BOOL bFail = FALSE;
5565 
5566                 SKIPTESTS(rightvt);
5567 
5568                 if (leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
5569                     continue;
5570 
5571                 memset(&left, 0, sizeof(left));
5572                 memset(&right, 0, sizeof(right));
5573                 V_VT(&left) = leftvt | ExtraFlags[i];
5574                 if (leftvt == VT_BSTR)
5575                     V_BSTR(&left) = lbstr;
5576                 V_VT(&right) = rightvt | ExtraFlags[i];
5577                 if (rightvt == VT_BSTR)
5578                     V_BSTR(&right) = rbstr;
5579                 V_VT(&result) = VT_EMPTY;
5580                 resvt = VT_ERROR;
5581 
5582                 /* Don't ask me why but native VarAdd cannot handle:
5583                    VT_I1, VT_UI2, VT_UI4, VT_INT, VT_UINT and VT_UI8.
5584                    Tested with DCOM98, Win2k, WinXP */
5585                 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
5586                     !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
5587                     !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
5588                     leftvt == VT_CLSID || rightvt == VT_CLSID ||
5589                     leftvt == VT_RECORD || rightvt == VT_RECORD ||
5590                     leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
5591                     leftvt == VT_ERROR || rightvt == VT_ERROR ||
5592                     leftvt == VT_I1 || rightvt == VT_I1 ||
5593                     leftvt == VT_UI2 || rightvt == VT_UI2 ||
5594                     leftvt == VT_UI4 || rightvt == VT_UI4 ||
5595                     leftvt == VT_UI8 || rightvt == VT_UI8 ||
5596                     leftvt == VT_INT || rightvt == VT_INT ||
5597                     leftvt == VT_UINT || rightvt == VT_UINT) {
5598                     bFail = TRUE;
5599                 }
5600 
5601                 if (leftvt == VT_NULL || rightvt == VT_NULL)
5602                     resvt = VT_NULL;
5603                 else if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH)
5604                     bFail = TRUE;
5605                 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
5606                     resvt = VT_DECIMAL;
5607                 else if (leftvt == VT_DATE || rightvt == VT_DATE)
5608                     resvt = VT_DATE;
5609                 else if (leftvt == VT_CY || rightvt == VT_CY)
5610                     resvt = VT_CY;
5611                 else if (leftvt == VT_R8 || rightvt == VT_R8)
5612                     resvt = VT_R8;
5613                 else if (leftvt == VT_BSTR || rightvt == VT_BSTR) {
5614                     if ((leftvt == VT_BSTR && rightvt == VT_BSTR) ||
5615                          leftvt == VT_EMPTY || rightvt == VT_EMPTY)
5616                         resvt = VT_BSTR;
5617                     else
5618                         resvt = VT_R8;
5619                 } else if (leftvt == VT_R4 || rightvt == VT_R4) {
5620                     if (leftvt == VT_I4 || rightvt == VT_I4 ||
5621                         leftvt == VT_I8 || rightvt == VT_I8)
5622                         resvt = VT_R8;
5623                     else
5624                         resvt = VT_R4;
5625                 }
5626                 else if (leftvt == VT_I8 || rightvt == VT_I8)
5627                     resvt = VT_I8;
5628                 else if (leftvt == VT_I4 || rightvt == VT_I4)
5629                     resvt = VT_I4;
5630                 else if (leftvt == VT_I2 || rightvt == VT_I2 ||
5631                          leftvt == VT_BOOL || rightvt == VT_BOOL ||
5632                          (leftvt == VT_EMPTY && rightvt == VT_EMPTY))
5633                     resvt = VT_I2;
5634                 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
5635                     resvt = VT_UI1;
5636 
5637                 hres = pVarAdd(&left, &right, &result);
5638                 if (bFail) {
5639                     ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
5640                        "VarAdd: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
5641                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
5642                        V_VT(&result));
5643                 } else {
5644                     ok(hres == S_OK && V_VT(&result) == resvt,
5645                        "VarAdd: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
5646                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
5647                        V_VT(&result));
5648                 }
5649                 /* Note, we don't clear left/right deliberately here */
5650                 VariantClear(&result);
5651             }
5652         }
5653     }
5654 
5655     /* Test returned values */
5656     VARADD(I4,4,I4,2,I4,6);
5657     VARADD(I2,4,I2,2,I2,6);
5658     VARADD(I2,-13,I4,5,I4,-8);
5659     VARADD(I4,-13,I4,5,I4,-8);
5660     VARADD(I2,7,R4,0.5f,R4,7.5f);
5661     VARADD(R4,0.5f,I4,5,R8,5.5);
5662     VARADD(R8,7.1,BOOL,0,R8,7.1);
5663     VARADD(BSTR,lbstr,I2,4,R8,16);
5664     VARADD(BSTR,lbstr,BOOL,1,R8,13);
5665     VARADD(BSTR,lbstr,R4,0.1f,R8,12.1);
5666     VARADD(R4,0.2f,BSTR,rbstr,R8,12.2);
5667     VARADD(DATE,2.25,I4,7,DATE,9.25);
5668     VARADD(DATE,1.25,R4,-1.7f,DATE,-0.45);
5669 
5670     VARADD(UI1, UI1_MAX, UI1, UI1_MAX, I2, UI1_MAX + UI1_MAX);
5671     VARADD(I2, I2_MAX, I2, I2_MAX, I4, I2_MAX + I2_MAX);
5672     VARADD(I2, I2_MAX, I2, I2_MIN, I2, I2_MAX + I2_MIN);
5673     VARADD(I2, I2_MIN, I2, I2_MIN, I4, I2_MIN + I2_MIN);
5674     VARADD(I4, I4_MAX, I4, I4_MIN, I4, I4_MAX + I4_MIN);
5675     VARADD(I4, I4_MAX, I4, I4_MAX, R8, (double)I4_MAX + I4_MAX);
5676     VARADD(I4, I4_MIN, I4, I4_MIN, R8, (double)I4_MIN + I4_MIN);
5677     VARADD(R4, R4_MAX, R4, R4_MAX, R8, (double)R4_MAX + R4_MAX);
5678     VARADD(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX + R4_MIN);
5679     VARADD(R4, R4_MIN, R4, R4_MIN, R4, R4_MIN + R4_MIN);
5680     VARADD(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX + R8_MIN);
5681     VARADD(R8, R8_MIN, R8, R8_MIN, R8, R8_MIN + R8_MIN);
5682 
5683     /* Manually test BSTR + BSTR */
5684     V_VT(&left) = VT_BSTR;
5685     V_BSTR(&left) = lbstr;
5686     V_VT(&right) = VT_BSTR;
5687     V_BSTR(&right) = rbstr;
5688     hres = pVarAdd(&left, &right, &result);
5689     ok(hres == S_OK && V_VT(&result) == VT_BSTR, "VarAdd: expected coerced type VT_BSTR, got %s!\n", vtstr(V_VT(&result)));
5690     hres = VarR8FromStr(V_BSTR(&result), 0, 0, &r);
5691     ok(hres == S_OK && EQ_DOUBLE(r, 1212.0), "VarAdd: BSTR value %f, expected %f\n", r, (double)1212);
5692     VariantClear(&result);
5693 
5694     /* Manuly test some VT_CY and VT_DECIMAL variants */
5695     V_VT(&cy) = VT_CY;
5696     hres = VarCyFromI4(4711, &V_CY(&cy));
5697     ok(hres == S_OK, "VarCyFromI4 failed!\n");
5698     V_VT(&dec) = VT_DECIMAL;
5699     hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec));
5700     ok(hres == S_OK, "VarDecFromR4 failed!\n");
5701     memset(&left, 0, sizeof(left));
5702     memset(&right, 0, sizeof(right));
5703     V_VT(&left) = VT_I4;
5704     V_I4(&left) = -11;
5705     V_VT(&right) = VT_UI1;
5706     V_UI1(&right) = 9;
5707 
5708     hres = pVarAdd(&cy, &right, &result);
5709     ok(hres == S_OK && V_VT(&result) == VT_CY, "VarAdd: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result)));
5710     hres = VarR8FromCy(V_CY(&result), &r);
5711     ok(hres == S_OK && EQ_DOUBLE(r, 4720.0), "VarAdd: CY value %f, expected %f\n", r, (double)4720);
5712 
5713     hres = pVarAdd(&left, &dec, &result);
5714     ok(hres == S_OK && V_VT(&result) == VT_DECIMAL, "VarAdd: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
5715     hres = VarR8FromDec(&V_DECIMAL(&result), &r);
5716     ok(hres == S_OK && EQ_DOUBLE(r, -15.2), "VarAdd: DECIMAL value %f, expected %f\n", r, (double)-15.2);
5717     VariantClear(&result);
5718 
5719     SysFreeString(lbstr);
5720     SysFreeString(rbstr);
5721 }
5722 
5723 static HRESULT (WINAPI *pVarCmp)(LPVARIANT,LPVARIANT,LCID,ULONG);
5724 static HRESULT (WINAPI *pVarCat)(LPVARIANT,LPVARIANT,LPVARIANT);
5725 
5726 static void test_VarCat(void)
5727 {
5728     LCID lcid;
5729     VARIANT left, right, result, expected, expected_broken;
5730     static const WCHAR sz34[] = {'3','4','\0'};
5731     static const WCHAR sz1234[] = {'1','2','3','4','\0'};
5732     static const WCHAR date_sz12[] = {'9','/','3','0','/','1','9','8','0','1','2','\0'};
5733     static const WCHAR date_sz12_broken[] = {'9','/','3','0','/','8','0','1','2','\0'};
5734     static const WCHAR sz12_date[] = {'1','2','9','/','3','0','/','1','9','8','0','\0'};
5735     static const WCHAR sz12_date_broken[] = {'1','2','9','/','3','0','/','8','0','\0'};
5736     static const WCHAR sz_empty[] = {'\0'};
5737     CHAR orig_date_format[128];
5738     VARTYPE leftvt, rightvt, resultvt;
5739     HRESULT hres;
5740     HRESULT expected_error_num;
5741     int cmp;
5742     DummyDispatch dispatch;
5743 
5744     CHECKPTR(VarCat);
5745 
5746     /* Set date format for testing */
5747     lcid = LOCALE_USER_DEFAULT;
5748     GetLocaleInfoA(lcid,LOCALE_SSHORTDATE,orig_date_format,128);
5749     SetLocaleInfoA(lcid,LOCALE_SSHORTDATE,"M/d/yyyy");
5750 
5751     VariantInit(&left);
5752     VariantInit(&right);
5753     VariantInit(&result);
5754     VariantInit(&expected);
5755 
5756     /* Check expected types for all combinations */
5757     for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
5758     {
5759 
5760         SKIPTESTS(leftvt);
5761 
5762         /* Check if we need/have support for I8 and/or UI8 */
5763         if ((leftvt == VT_I8 || leftvt == VT_UI8) && !has_i8)
5764             continue;
5765 
5766         for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
5767         {
5768 
5769             SKIPTESTS(rightvt);
5770             expected_error_num = S_OK;
5771             resultvt = VT_EMPTY;
5772 
5773             if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
5774                 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN  ||
5775                 leftvt == VT_RECORD || rightvt == VT_RECORD  ||
5776                 leftvt == 15 || rightvt == 15 /* Undefined type */)
5777                 continue;
5778 
5779             /* Check if we need/have support for I8 and/or UI8 */
5780             if ((rightvt == VT_I8 || rightvt == VT_UI8) && !has_i8)
5781                 continue;
5782 
5783             if (leftvt == VT_NULL && rightvt == VT_NULL)
5784                 resultvt = VT_NULL;
5785             else if (leftvt == VT_VARIANT && (rightvt == VT_ERROR ||
5786                 rightvt == VT_DATE || rightvt == VT_DECIMAL))
5787                 expected_error_num = DISP_E_TYPEMISMATCH;
5788             else if ((leftvt == VT_I2 || leftvt == VT_I4 ||
5789                 leftvt == VT_R4 || leftvt == VT_R8 ||
5790                 leftvt == VT_CY || leftvt == VT_BOOL ||
5791                 leftvt == VT_BSTR || leftvt == VT_I1 ||
5792                 leftvt == VT_UI1 || leftvt == VT_UI2 ||
5793                 leftvt == VT_UI4 || leftvt == VT_I8 ||
5794                 leftvt == VT_UI8 || leftvt == VT_INT ||
5795                 leftvt == VT_UINT || leftvt == VT_EMPTY ||
5796                 leftvt == VT_NULL || leftvt == VT_DECIMAL ||
5797                 leftvt == VT_DATE)
5798                 &&
5799                 (rightvt == VT_I2 || rightvt == VT_I4 ||
5800                 rightvt == VT_R4 || rightvt == VT_R8 ||
5801                 rightvt == VT_CY || rightvt == VT_BOOL ||
5802                 rightvt == VT_BSTR || rightvt == VT_I1 ||
5803                 rightvt == VT_UI1 || rightvt == VT_UI2 ||
5804                 rightvt == VT_UI4 || rightvt == VT_I8 ||
5805                 rightvt == VT_UI8 || rightvt == VT_INT ||
5806                 rightvt == VT_UINT || rightvt == VT_EMPTY ||
5807                 rightvt == VT_NULL || rightvt == VT_DECIMAL ||
5808                 rightvt == VT_DATE))
5809                 resultvt = VT_BSTR;
5810             else if (rightvt == VT_ERROR && leftvt < VT_VOID)
5811                 expected_error_num = DISP_E_TYPEMISMATCH;
5812             else if (leftvt == VT_ERROR && (rightvt == VT_DATE ||
5813                 rightvt == VT_ERROR || rightvt == VT_DECIMAL))
5814                 expected_error_num = DISP_E_TYPEMISMATCH;
5815             else if (rightvt == VT_DATE || rightvt == VT_ERROR ||
5816                 rightvt == VT_DECIMAL)
5817                 expected_error_num = DISP_E_BADVARTYPE;
5818             else if (leftvt == VT_ERROR || rightvt == VT_ERROR)
5819                 expected_error_num = DISP_E_TYPEMISMATCH;
5820             else if (leftvt == VT_VARIANT)
5821                 expected_error_num = DISP_E_TYPEMISMATCH;
5822             else if (rightvt == VT_VARIANT && (leftvt == VT_EMPTY ||
5823                 leftvt == VT_NULL || leftvt ==  VT_I2 ||
5824                 leftvt == VT_I4 || leftvt == VT_R4 ||
5825                 leftvt == VT_R8 || leftvt == VT_CY ||
5826                 leftvt == VT_DATE || leftvt == VT_BSTR ||
5827                 leftvt == VT_BOOL ||  leftvt == VT_DECIMAL ||
5828                 leftvt == VT_I1 || leftvt == VT_UI1 ||
5829                 leftvt == VT_UI2 || leftvt == VT_UI4 ||
5830                 leftvt == VT_I8 || leftvt == VT_UI8 ||
5831                 leftvt == VT_INT || leftvt == VT_UINT
5832                 ))
5833                 expected_error_num = DISP_E_TYPEMISMATCH;
5834             else
5835                 expected_error_num = DISP_E_BADVARTYPE;
5836 
5837             V_VT(&left) = leftvt;
5838             V_VT(&right) = rightvt;
5839 
5840             switch (leftvt) {
5841             case VT_BSTR:
5842                 V_BSTR(&left) = SysAllocString(sz_empty); break;
5843             case VT_DATE:
5844                 V_DATE(&left) = 0.0; break;
5845             case VT_DECIMAL:
5846                 VarDecFromR8(0.0, &V_DECIMAL(&left)); break;
5847             default:
5848                 V_I8(&left) = 0;
5849             }
5850 
5851             switch (rightvt) {
5852             case VT_BSTR:
5853                 V_BSTR(&right) = SysAllocString(sz_empty); break;
5854             case VT_DATE:
5855                 V_DATE(&right) = 0.0; break;
5856             case VT_DECIMAL:
5857                 VarDecFromR8(0.0, &V_DECIMAL(&right)); break;
5858             default:
5859                 V_I8(&right) = 0;
5860             }
5861 
5862             hres = pVarCat(&left, &right, &result);
5863 
5864             /* Determine the error code for the vt combination */
5865             ok(hres == expected_error_num,
5866                 "VarCat: %d, %d returned error, 0x%X expected 0x%X.\n",
5867                 leftvt, rightvt, hres, expected_error_num);
5868 
5869             /* Check types are correct */
5870             ok(V_VT(&result) == resultvt,
5871                 "VarCat: %d, %d: expected vt %d, got vt %d\n",
5872                 leftvt, rightvt, resultvt, V_VT(&result));
5873 
5874             VariantClear(&left);
5875             VariantClear(&right);
5876             VariantClear(&result);
5877         }
5878     }
5879 
5880     /* Running single comparison tests to compare outputs */
5881 
5882     /* Test concat strings */
5883     V_VT(&left) = VT_BSTR;
5884     V_VT(&right) = VT_BSTR;
5885     V_VT(&expected) = VT_BSTR;
5886     V_BSTR(&left) = SysAllocString(sz12);
5887     V_BSTR(&right) = SysAllocString(sz34);
5888     V_BSTR(&expected) = SysAllocString(sz1234);
5889     hres = pVarCat(&left,&right,&result);
5890     ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5891     if (pVarCmp)
5892         ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ,
5893            "VarCat: VT_BSTR concat with VT_BSTR failed to return correct result\n");
5894 
5895     VariantClear(&left);
5896     VariantClear(&right);
5897     VariantClear(&result);
5898 
5899     /* Test if expression is VT_ERROR */
5900     V_VT(&left) = VT_ERROR;
5901     V_VT(&right) = VT_BSTR;
5902     V_BSTR(&right) = SysAllocString(sz1234);
5903     hres = pVarCat(&left,&right,&result);
5904     ok(hres == DISP_E_TYPEMISMATCH, "VarCat should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hres);
5905     ok(V_VT(&result) == VT_EMPTY,
5906         "VarCat: VT_ERROR concat with VT_BSTR should have returned VT_EMPTY\n");
5907 
5908     VariantClear(&left);
5909     VariantClear(&right);
5910     VariantClear(&result);
5911 
5912     V_VT(&left) = VT_BSTR;
5913     V_VT(&right) = VT_ERROR;
5914     V_BSTR(&left) = SysAllocString(sz1234);
5915     hres = pVarCat(&left,&right,&result);
5916     ok(hres == DISP_E_TYPEMISMATCH, "VarCat should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hres);
5917     ok(V_VT(&result) == VT_EMPTY,
5918         "VarCat: VT_BSTR concat with VT_ERROR should have returned VT_EMPTY\n");
5919 
5920     VariantClear(&left);
5921     VariantClear(&right);
5922     VariantClear(&result);
5923     VariantClear(&expected);
5924 
5925     /* Test combining boolean with number */
5926     V_VT(&left) = VT_INT;
5927     V_VT(&right) = VT_BOOL;
5928     V_VT(&expected) = VT_BSTR;
5929     V_INT(&left) = 12;
5930     V_BOOL(&right) = TRUE;
5931     V_BSTR(&expected) = SysAllocString(sz12_true);
5932     hres = pVarCat(&left,&right,&result);
5933     ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5934     if (pVarCmp)
5935     {
5936         hres = pVarCmp(&result,&expected,lcid,0);
5937         ok(hres == VARCMP_EQ, "Expected VARCMP_EQ, got %08x for %s, %s\n",
5938            hres, variantstr(&result), variantstr(&expected));
5939     }
5940 
5941     VariantClear(&left);
5942     VariantClear(&right);
5943     VariantClear(&result);
5944     VariantClear(&expected);
5945 
5946     V_VT(&left) = VT_INT;
5947     V_VT(&right) = VT_BOOL;
5948     V_VT(&expected) = VT_BSTR;
5949     V_INT(&left) = 12;
5950     V_BOOL(&right) = FALSE;
5951     V_BSTR(&expected) = SysAllocString(sz12_false);
5952     hres = pVarCat(&left,&right,&result);
5953     ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5954     if (pVarCmp)
5955     {
5956         hres = pVarCmp(&result,&expected,lcid,0);
5957         ok(hres == VARCMP_EQ, "Expected VARCMP_EQ, got %08x for %s, %s\n",
5958            hres, variantstr(&result), variantstr(&expected));
5959     }
5960 
5961     VariantClear(&left);
5962     VariantClear(&right);
5963     VariantClear(&result);
5964     VariantClear(&expected);
5965 
5966     /* Test when both expressions are numeric */
5967     V_VT(&left) = VT_INT;
5968     V_VT(&right) = VT_INT;
5969     V_VT(&expected) = VT_BSTR;
5970     V_INT(&left)  = 12;
5971     V_INT(&right) = 34;
5972     V_BSTR(&expected) = SysAllocString(sz1234);
5973     hres = pVarCat(&left,&right,&result);
5974     ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5975     if (pVarCmp)
5976         ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ,
5977            "VarCat: NUMBER concat with NUMBER returned incorrect result\n");
5978 
5979     VariantClear(&left);
5980     VariantClear(&right);
5981     VariantClear(&result);
5982 
5983     /* Test if one expression is numeric and the other is a string */
5984     V_VT(&left) = VT_INT;
5985     V_VT(&right) = VT_BSTR;
5986     V_INT(&left) = 12;
5987     V_BSTR(&right) = SysAllocString(sz34);
5988     hres = pVarCat(&left,&right,&result);
5989     ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5990     if (pVarCmp)
5991         ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ,
5992            "VarCat: NUMBER concat with VT_BSTR, incorrect result\n");
5993 
5994     VariantClear(&left);
5995     VariantClear(&right);
5996     VariantClear(&result);
5997 
5998     V_VT(&left) = VT_BSTR;
5999     V_VT(&right) = VT_INT;
6000     V_BSTR(&left) = SysAllocString(sz12);
6001     V_INT(&right) = 34;
6002     hres = pVarCat(&left,&right,&result);
6003     ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
6004     if (pVarCmp)
6005         ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ,
6006            "VarCat: VT_BSTR concat with NUMBER, incorrect result\n");
6007 
6008     VariantClear(&left);
6009     VariantClear(&right);
6010     VariantClear(&result);
6011     VariantClear(&expected);
6012 
6013     /* Test concat dates with strings */
6014     V_VT(&left) = VT_BSTR;
6015     V_VT(&right) = VT_DATE;
6016     V_VT(&expected) = VT_BSTR;
6017     V_VT(&expected_broken) = VT_BSTR;
6018     V_BSTR(&left) = SysAllocString(sz12);
6019     V_DATE(&right) = 29494.0;
6020     V_BSTR(&expected)= SysAllocString(sz12_date);
6021     V_BSTR(&expected_broken)= SysAllocString(sz12_date_broken);
6022     hres = pVarCat(&left,&right,&result);
6023     ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
6024     if (pVarCmp)
6025         ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ ||
6026            broken(pVarCmp(&result,&expected_broken,lcid,0) == VARCMP_EQ), /* Some W98 and NT4 (intermittent) */
6027            "VarCat: VT_BSTR concat with VT_DATE returned incorrect result\n");
6028 
6029     VariantClear(&left);
6030     VariantClear(&right);
6031     VariantClear(&result);
6032     VariantClear(&expected);
6033     VariantClear(&expected_broken);
6034 
6035     V_VT(&left) = VT_DATE;
6036     V_VT(&right) = VT_BSTR;
6037     V_VT(&expected) = VT_BSTR;
6038     V_VT(&expected_broken) = VT_BSTR;
6039     V_DATE(&left) = 29494.0;
6040     V_BSTR(&right) = SysAllocString(sz12);
6041     V_BSTR(&expected)= SysAllocString(date_sz12);
6042     V_BSTR(&expected_broken)= SysAllocString(date_sz12_broken);
6043     hres = pVarCat(&left,&right,&result);
6044     ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
6045     if (pVarCmp)
6046         ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ ||
6047            broken(pVarCmp(&result,&expected_broken,lcid,0) == VARCMP_EQ), /* Some W98 and NT4 (intermittent) */
6048            "VarCat: VT_DATE concat with VT_BSTR returned incorrect result\n");
6049 
6050     VariantClear(&left);
6051     VariantClear(&right);
6052     VariantClear(&result);
6053     VariantClear(&expected);
6054     VariantClear(&expected_broken);
6055 
6056     /* Test of both expressions are empty */
6057     V_VT(&left) = VT_BSTR;
6058     V_VT(&right) = VT_BSTR;
6059     V_VT(&expected) = VT_BSTR;
6060     V_BSTR(&left) = SysAllocString(sz_empty);
6061     V_BSTR(&right) = SysAllocString(sz_empty);
6062     V_BSTR(&expected)= SysAllocString(sz_empty);
6063     hres = pVarCat(&left,&right,&result);
6064     ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
6065     if (pVarCmp)
6066         ok(pVarCmp(&result,&left,lcid,0) == VARCMP_EQ,
6067            "VarCat: EMPTY concat with EMPTY did not return empty VT_BSTR\n");
6068 
6069     /* Restore original date format settings */
6070     SetLocaleInfoA(lcid,LOCALE_SSHORTDATE,orig_date_format);
6071 
6072     VariantClear(&left);
6073     VariantClear(&right);
6074     VariantClear(&result);
6075     VariantClear(&expected);
6076 
6077     /* Dispatch conversion */
6078     init_test_dispatch(VT_NULL, &dispatch);
6079     V_VT(&left) = VT_DISPATCH;
6080     V_DISPATCH(&left) = &dispatch.IDispatch_iface;
6081 
6082     SET_EXPECT(dispatch_invoke);
6083     hres = VarCat(&left, &right, &result);
6084     ok(hres == S_OK, "got 0x%08x\n", hres);
6085     ok(V_VT(&result) == VT_BSTR, "got %d\n", V_VT(&result));
6086     ok(SysStringLen(V_BSTR(&result)) == 0, "got %d\n", SysStringLen(V_BSTR(&result)));
6087     CHECK_CALLED(dispatch_invoke);
6088 
6089     VariantClear(&left);
6090     VariantClear(&right);
6091     VariantClear(&result);
6092 
6093     init_test_dispatch(VT_NULL, &dispatch);
6094     V_VT(&right) = VT_DISPATCH;
6095     V_DISPATCH(&right) = &dispatch.IDispatch_iface;
6096 
6097     SET_EXPECT(dispatch_invoke);
6098     hres = VarCat(&left, &right, &result);
6099     ok(hres == S_OK, "got 0x%08x\n", hres);
6100     ok(V_VT(&result) == VT_BSTR, "got %d\n", V_VT(&result));
6101     ok(SysStringLen(V_BSTR(&result)) == 0, "got %d\n", SysStringLen(V_BSTR(&result)));
6102     CHECK_CALLED(dispatch_invoke);
6103 
6104     VariantClear(&left);
6105     VariantClear(&right);
6106     VariantClear(&result);
6107 
6108     init_test_dispatch(VT_UI1, &dispatch);
6109     V_VT(&right) = VT_DISPATCH;
6110     V_DISPATCH(&right) = &dispatch.IDispatch_iface;
6111 
6112     V_VT(&left) = VT_BSTR;
6113     V_BSTR(&left) = SysAllocString(sz12);
6114     SET_EXPECT(dispatch_invoke);
6115     hres = pVarCat(&left,&right,&result);
6116     ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
6117     CHECK_CALLED(dispatch_invoke);
6118     ok(!strcmp_wa(V_BSTR(&result), "1234"), "got %s\n", wine_dbgstr_w(V_BSTR(&result)));
6119 
6120     VariantClear(&left);
6121     VariantClear(&right);
6122     VariantClear(&result);
6123 
6124     init_test_dispatch(VT_NULL, &dispatch);
6125     dispatch.result = E_OUTOFMEMORY;
6126     V_VT(&right) = VT_DISPATCH;
6127     V_DISPATCH(&right) = &dispatch.IDispatch_iface;
6128 
6129     SET_EXPECT(dispatch_invoke);
6130     hres = VarCat(&left, &right, &result);
6131     ok(hres == E_OUTOFMEMORY, "got 0x%08x\n", hres);
6132     CHECK_CALLED(dispatch_invoke);
6133 
6134     VariantClear(&left);
6135     VariantClear(&right);
6136     VariantClear(&result);
6137 
6138     init_test_dispatch(VT_NULL, &dispatch);
6139     dispatch.result = DISP_E_TYPEMISMATCH;
6140     V_VT(&right) = VT_DISPATCH;
6141     V_DISPATCH(&right) = &dispatch.IDispatch_iface;
6142 
6143     SET_EXPECT(dispatch_invoke);
6144     hres = VarCat(&left, &right, &result);
6145     ok(hres == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hres);
6146     CHECK_CALLED(dispatch_invoke);
6147 
6148     VariantClear(&left);
6149     VariantClear(&right);
6150     VariantClear(&result);
6151 
6152     /* Test boolean conversion */
6153     V_VT(&left) = VT_BOOL;
6154     V_BOOL(&left) = VARIANT_TRUE;
6155     V_VT(&right) = VT_BSTR;
6156     V_BSTR(&right) = SysAllocStringLen(NULL,0);
6157     hres = pVarCat(&left, &right, &result);
6158     ok(hres == S_OK, "VarCat failed: %08x\n", hres);
6159     VariantClear(&right);
6160 
6161     cmp = strcmp_wa(V_BSTR(&result), "True");
6162     VariantClear(&result);
6163     if(!cmp) {
6164         V_VT(&right) = VT_BOOL;
6165         V_BOOL(&right) = 100;
6166         hres = pVarCat(&left, &right, &result);
6167         ok(hres == S_OK, "VarCat failed: %08x\n", hres);
6168         test_bstr_var(&result, "TrueTrue");
6169         VariantClear(&result);
6170 
6171         V_BOOL(&right) = VARIANT_FALSE;
6172         hres = pVarCat(&left, &right, &result);
6173         ok(hres == S_OK, "VarCat failed: %08x\n", hres);
6174         test_bstr_var(&result, "TrueFalse");
6175         VariantClear(&result);
6176     }else {
6177         skip("Got %s as True, assuming non-English locale\n", wine_dbgstr_w(V_BSTR(&result)));
6178     }
6179 }
6180 
6181 static HRESULT (WINAPI *pVarAnd)(LPVARIANT,LPVARIANT,LPVARIANT);
6182 
6183 #define VARAND(vt1,val1,vt2,val2,rvt,rval)               \
6184         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
6185         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
6186         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
6187         test_var_call2( __LINE__, pVarAnd, &left, &right, &exp )
6188 
6189 #define VARANDCY(vt1,val1,val2,rvt,rval)                 \
6190         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
6191         V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \
6192         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
6193         test_var_call2( __LINE__, pVarAnd, &left, &right, &exp )
6194 
6195 /* Skip any type that is not defined or produces an error for every case */
6196 #define SKIPTESTAND(a)                                \
6197         if (a == VT_ERROR || a == VT_VARIANT ||       \
6198             a == VT_DISPATCH || a == VT_UNKNOWN ||    \
6199             a > VT_UINT || a == 15 /*not defined*/)   \
6200             continue
6201 
6202 static void test_VarAnd(void)
6203 {
6204     static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
6205     static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
6206     VARIANT left, right, exp, result;
6207     BSTR false_str, true_str;
6208     VARTYPE i;
6209     HRESULT hres;
6210 
6211     CHECKPTR(VarAnd);
6212 
6213     true_str = SysAllocString(szTrue);
6214     false_str = SysAllocString(szFalse);
6215 
6216     /* Test all possible flag/vt combinations & the resulting vt type */
6217     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
6218     {
6219         VARTYPE leftvt, rightvt, resvt;
6220 
6221         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
6222         {
6223             SKIPTESTAND(leftvt);
6224 
6225             /* Check if we need/have support for I8 and/or UI8 */
6226             if ((leftvt == VT_I8 || leftvt == VT_UI8) && !has_i8)
6227                 continue;
6228 
6229             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
6230             {
6231                 BOOL bFail = FALSE;
6232                 SKIPTESTAND(rightvt);
6233 
6234                 /* Check if we need/have support for I8 and/or UI8 */
6235                 if ((rightvt == VT_I8 || rightvt == VT_UI8) && !has_i8)
6236                     continue;
6237 
6238                 memset(&left, 0, sizeof(left));
6239                 memset(&right, 0, sizeof(right));
6240                 V_VT(&left) = leftvt | ExtraFlags[i];
6241                 V_VT(&right) = rightvt | ExtraFlags[i];
6242                 V_VT(&result) = VT_EMPTY;
6243                 resvt = VT_EMPTY;
6244                 if ((leftvt | ExtraFlags[i]) == VT_BSTR)
6245                     V_BSTR(&left) = true_str;
6246                 if ((rightvt | ExtraFlags[i]) == VT_BSTR)
6247                     V_BSTR(&right) = true_str;
6248 
6249                 /* Native VarAnd always returns an error when using extra
6250                  * flags or if the variant combination is I8 and INT.
6251                  */
6252                 if ((leftvt == VT_I8 && rightvt == VT_INT) ||
6253                     (leftvt == VT_INT && rightvt == VT_I8) ||
6254                     ExtraFlags[i] != 0)
6255                     bFail = TRUE;
6256 
6257                 /* Determine return type */
6258                 else if (leftvt == VT_I8 || rightvt == VT_I8)
6259                     resvt = VT_I8;
6260                 else if (leftvt == VT_I4 || rightvt == VT_I4 ||
6261                     leftvt == VT_UINT || rightvt == VT_UINT ||
6262                     leftvt == VT_INT || rightvt == VT_INT ||
6263                     leftvt == VT_R4 || rightvt == VT_R4 ||
6264                     leftvt == VT_R8 || rightvt == VT_R8 ||
6265                     leftvt == VT_CY || rightvt == VT_CY ||
6266                     leftvt == VT_DATE || rightvt == VT_DATE ||
6267                     leftvt == VT_I1 || rightvt == VT_I1 ||
6268                     leftvt == VT_UI2 || rightvt == VT_UI2 ||
6269                     leftvt == VT_UI4 || rightvt == VT_UI4 ||
6270                     leftvt == VT_UI8 || rightvt == VT_UI8 ||
6271                     leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
6272                     resvt = VT_I4;
6273                 else if (leftvt == VT_UI1 || rightvt == VT_UI1 ||
6274                     leftvt == VT_I2 || rightvt == VT_I2 ||
6275                     leftvt == VT_EMPTY || rightvt == VT_EMPTY)
6276                     if ((leftvt == VT_NULL && rightvt == VT_UI1) ||
6277                         (leftvt == VT_UI1 && rightvt == VT_NULL) ||
6278                         (leftvt == VT_UI1 && rightvt == VT_UI1))
6279                         resvt = VT_UI1;
6280                     else
6281                         resvt = VT_I2;
6282                 else if (leftvt == VT_BOOL || rightvt == VT_BOOL ||
6283                     (leftvt == VT_BSTR && rightvt == VT_BSTR))
6284                     resvt = VT_BOOL;
6285                 else if (leftvt == VT_NULL || rightvt == VT_NULL ||
6286                     leftvt == VT_BSTR || rightvt == VT_BSTR)
6287                     resvt = VT_NULL;
6288                 else
6289                     bFail = TRUE;
6290 
6291                 hres = pVarAnd(&left, &right, &result);
6292 
6293                 /* Check expected HRESULT and if result variant type is correct */
6294                 if (bFail)
6295                     ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH,
6296                         "VarAnd: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
6297                         vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
6298                         vtstr(V_VT(&result)), hres);
6299                 else
6300                     ok (hres == S_OK && resvt == V_VT(&result),
6301                         "VarAnd: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
6302                         vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
6303                         S_OK, vtstr(V_VT(&result)), hres);
6304             }
6305         }
6306     }
6307 
6308     /*
6309      * Test returned values. Since we know the returned type is correct
6310      * and that we handle all combinations of invalid types, just check
6311      * that good type combinations produce the desired value.
6312      * FIXME: Test VT_DECIMAL
6313      */
6314     VARAND(EMPTY,0,EMPTY,0,I2,0);
6315     VARAND(EMPTY,1,EMPTY,0,I2,0);
6316     VARAND(EMPTY,1,EMPTY,1,I2,0);
6317     VARAND(EMPTY,0,NULL,0,I2,0);
6318     VARAND(EMPTY,1,NULL,0,I2,0);
6319     VARAND(EMPTY,1,NULL,1,I2,0);
6320     VARAND(EMPTY,0,I1,0,I4,0);
6321     VARAND(EMPTY,0,I1,1,I4,0);
6322     VARAND(EMPTY,1,I1,1,I4,0);
6323     VARAND(EMPTY,0,UI1,0,I2,0);
6324     VARAND(EMPTY,0,UI1,1,I2,0);
6325     VARAND(EMPTY,1,UI1,1,I2,0);
6326     VARAND(EMPTY,0,I2,0,I2,0);
6327     VARAND(EMPTY,0,I2,1,I2,0);
6328     VARAND(EMPTY,1,I2,1,I2,0);
6329     VARAND(EMPTY,0,UI2,0,I4,0);
6330     VARAND(EMPTY,0,UI2,1,I4,0);
6331     VARAND(EMPTY,1,UI2,1,I4,0);
6332     VARAND(EMPTY,0,I4,0,I4,0);
6333     VARAND(EMPTY,0,I4,1,I4,0);
6334     VARAND(EMPTY,1,I4,1,I4,0);
6335     VARAND(EMPTY,0,UI4,0,I4,0);
6336     VARAND(EMPTY,0,UI4,1,I4,0);
6337     VARAND(EMPTY,1,UI4,1,I4,0);
6338     if (has_i8)
6339     {
6340         VARAND(EMPTY,0,I8,0,I8,0);
6341         VARAND(EMPTY,0,I8,1,I8,0);
6342         VARAND(EMPTY,1,I8,1,I8,0);
6343         VARAND(EMPTY,0,UI8,0,I4,0);
6344         VARAND(EMPTY,0,UI8,1,I4,0);
6345         VARAND(EMPTY,1,UI8,1,I4,0);
6346     }
6347     VARAND(EMPTY,0,INT,0,I4,0);
6348     VARAND(EMPTY,0,INT,1,I4,0);
6349     VARAND(EMPTY,1,INT,1,I4,0);
6350     VARAND(EMPTY,0,UINT,0,I4,0);
6351     VARAND(EMPTY,0,UINT,1,I4,0);
6352     VARAND(EMPTY,1,UINT,1,I4,0);
6353     VARAND(EMPTY,0,BOOL,0,I2,0);
6354     VARAND(EMPTY,0,BOOL,1,I2,0);
6355     VARAND(EMPTY,1,BOOL,1,I2,0);
6356     VARAND(EMPTY,0,R4,0,I4,0);
6357     VARAND(EMPTY,0,R4,1,I4,0);
6358     VARAND(EMPTY,1,R4,1,I4,0);
6359     VARAND(EMPTY,0,R8,0,I4,0);
6360     VARAND(EMPTY,0,R8,1,I4,0);
6361     VARAND(EMPTY,1,R8,1,I4,0);
6362     VARAND(EMPTY,0,BSTR,false_str,I2,0);
6363     VARAND(EMPTY,0,BSTR,true_str,I2,0);
6364     VARANDCY(EMPTY,0,10000,I4,0);
6365 
6366     /* NULL OR 0 = NULL. NULL OR n = n */
6367     VARAND(NULL,0,NULL,0,NULL,0);
6368     VARAND(NULL,1,NULL,0,NULL,0);
6369     VARAND(NULL,0,I1,0,I4,0);
6370     VARAND(NULL,0,I1,1,NULL,0);
6371     VARAND(NULL,0,UI1,0,UI1,0);
6372     VARAND(NULL,0,UI1,1,NULL,0);
6373     VARAND(NULL,0,I2,0,I2,0);
6374     VARAND(NULL,0,I2,1,NULL,0);
6375     VARAND(NULL,0,UI2,0,I4,0);
6376     VARAND(NULL,0,UI2,1,NULL,0);
6377     VARAND(NULL,0,I4,0,I4,0);
6378     VARAND(NULL,0,I4,1,NULL,0);
6379     VARAND(NULL,0,UI4,0,I4,0);
6380     VARAND(NULL,0,UI4,1,NULL,0);
6381     if (has_i8)
6382     {
6383         VARAND(NULL,0,I8,0,I8,0);
6384         VARAND(NULL,0,I8,1,NULL,0);
6385         VARAND(NULL,0,UI8,0,I4,0);
6386         VARAND(NULL,0,UI8,1,NULL,0);
6387     }
6388     VARAND(NULL,0,INT,0,I4,0);
6389     VARAND(NULL,0,INT,1,NULL,0);
6390     VARAND(NULL,0,UINT,0,I4,0);
6391     VARAND(NULL,0,UINT,1,NULL,0);
6392     VARAND(NULL,0,BOOL,0,BOOL,0);
6393     VARAND(NULL,0,BOOL,1,NULL,0);
6394     VARAND(NULL,0,R4,0,I4,0);
6395     VARAND(NULL,0,R4,1,NULL,0);
6396     VARAND(NULL,0,R8,0,I4,0);
6397     VARAND(NULL,0,R8,1,NULL,0);
6398     VARAND(NULL,0,BSTR,false_str,BOOL,0);
6399     VARAND(NULL,0,BSTR,true_str,NULL,VARIANT_FALSE);
6400     VARANDCY(NULL,0,10000,NULL,0);
6401     VARANDCY(NULL,0,0,I4,0);
6402     VARAND(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
6403     VARAND(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
6404     VARAND(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
6405     VARAND(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
6406 
6407     /* Assume x,y & y,x are the same from now on to reduce the number of tests */
6408     VARAND(BOOL,VARIANT_TRUE,I1,-1,I4,-1);
6409     VARAND(BOOL,VARIANT_TRUE,I1,0,I4,0);
6410     VARAND(BOOL,VARIANT_FALSE,I1,0,I4,0);
6411     VARAND(BOOL,VARIANT_TRUE,UI1,255,I2,255);
6412     VARAND(BOOL,VARIANT_TRUE,UI1,0,I2,0);
6413     VARAND(BOOL,VARIANT_FALSE,UI1,0,I2,0);
6414     VARAND(BOOL,VARIANT_TRUE,I2,-1,I2,-1);
6415     VARAND(BOOL,VARIANT_TRUE,I2,0,I2,0);
6416     VARAND(BOOL,VARIANT_FALSE,I2,0,I2,0);
6417     VARAND(BOOL,VARIANT_TRUE,UI2,65535,I4,65535);
6418     VARAND(BOOL,VARIANT_TRUE,UI2,0,I4,0);
6419     VARAND(BOOL,VARIANT_FALSE,UI2,0,I4,0);
6420     VARAND(BOOL,VARIANT_TRUE,I4,-1,I4,-1);
6421     VARAND(BOOL,VARIANT_TRUE,I4,0,I4,0);
6422     VARAND(BOOL,VARIANT_FALSE,I4,0,I4,0);
6423     VARAND(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,-1);
6424     VARAND(BOOL,VARIANT_TRUE,UI4,0,I4,0);
6425     VARAND(BOOL,VARIANT_FALSE,UI4,0,I4,0);
6426     VARAND(BOOL,VARIANT_TRUE,R4,-1,I4,-1);
6427     VARAND(BOOL,VARIANT_TRUE,R4,0,I4,0);
6428     VARAND(BOOL,VARIANT_FALSE,R4,0,I4,0);
6429     VARAND(BOOL,VARIANT_TRUE,R8,-1,I4,-1);
6430     VARAND(BOOL,VARIANT_TRUE,R8,0,I4,0);
6431     VARAND(BOOL,VARIANT_FALSE,R8,0,I4,0);
6432     VARAND(BOOL,VARIANT_TRUE,DATE,-1,I4,-1);
6433     VARAND(BOOL,VARIANT_TRUE,DATE,0,I4,0);
6434     VARAND(BOOL,VARIANT_FALSE,DATE,0,I4,0);
6435     if (has_i8)
6436     {
6437         VARAND(BOOL,VARIANT_TRUE,I8,-1,I8,-1);
6438         VARAND(BOOL,VARIANT_TRUE,I8,0,I8,0);
6439         VARAND(BOOL,VARIANT_FALSE,I8,0,I8,0);
6440         VARAND(BOOL,VARIANT_TRUE,UI8,0,I4,0);
6441         VARAND(BOOL,VARIANT_FALSE,UI8,0,I4,0);
6442     }
6443     VARAND(BOOL,VARIANT_TRUE,INT,-1,I4,-1);
6444     VARAND(BOOL,VARIANT_TRUE,INT,0,I4,0);
6445     VARAND(BOOL,VARIANT_FALSE,INT,0,I4,0);
6446     VARAND(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,-1);
6447     VARAND(BOOL,VARIANT_TRUE,UINT,0,I4,0);
6448     VARAND(BOOL,VARIANT_FALSE,UINT,0,I4,0);
6449     VARAND(BOOL,VARIANT_FALSE,BSTR,false_str,BOOL,VARIANT_FALSE);
6450     VARAND(BOOL,VARIANT_TRUE,BSTR,false_str,BOOL,VARIANT_FALSE);
6451     VARAND(BOOL,VARIANT_FALSE,BSTR,true_str,BOOL,VARIANT_FALSE);
6452     VARAND(BOOL,VARIANT_TRUE,BSTR,true_str,BOOL,VARIANT_TRUE);
6453     VARANDCY(BOOL,VARIANT_TRUE,10000,I4,1);
6454     VARANDCY(BOOL,VARIANT_TRUE,0,I4,0);
6455     VARANDCY(BOOL,VARIANT_FALSE,0,I4,0);
6456     VARAND(I1,-1,I1,-1,I4,-1);
6457     VARAND(I1,-1,I1,0,I4,0);
6458     VARAND(I1,0,I1,0,I4,0);
6459     VARAND(I1,-1,UI1,255,I4,255);
6460     VARAND(I1,-1,UI1,0,I4,0);
6461     VARAND(I1,0,UI1,0,I4,0);
6462     VARAND(I1,-1,I2,-1,I4,-1);
6463     VARAND(I1,-1,I2,0,I4,0);
6464     VARAND(I1,0,I2,0,I4,0);
6465     VARAND(I1,-1,UI2,65535,I4,65535);
6466     VARAND(I1,-1,UI2,0,I4,0);
6467     VARAND(I1,0,UI2,0,I4,0);
6468     VARAND(I1,-1,I4,-1,I4,-1);
6469     VARAND(I1,-1,I4,0,I4,0);
6470     VARAND(I1,0,I4,0,I4,0);
6471     VARAND(I1,-1,UI4,0xffffffff,I4,-1);
6472     VARAND(I1,-1,UI4,0,I4,0);
6473     VARAND(I1,0,UI4,0,I4,0);
6474     VARAND(I1,-1,R4,-1,I4,-1);
6475     VARAND(I1,-1,R4,0,I4,0);
6476     VARAND(I1,0,R4,0,I4,0);
6477     VARAND(I1,-1,R8,-1,I4,-1);
6478     VARAND(I1,-1,R8,0,I4,0);
6479     VARAND(I1,0,R8,0,I4,0);
6480     VARAND(I1,-1,DATE,-1,I4,-1);
6481     VARAND(I1,-1,DATE,0,I4,0);
6482     VARAND(I1,0,DATE,0,I4,0);
6483     if (has_i8)
6484     {
6485         VARAND(I1,-1,I8,-1,I8,-1);
6486         VARAND(I1,-1,I8,0,I8,0);
6487         VARAND(I1,0,I8,0,I8,0);
6488         VARAND(I1,-1,UI8,0,I4,0);
6489         VARAND(I1,0,UI8,0,I4,0);
6490     }
6491     VARAND(I1,-1,INT,-1,I4,-1);
6492     VARAND(I1,-1,INT,0,I4,0);
6493     VARAND(I1,0,INT,0,I4,0);
6494     VARAND(I1,-1,UINT,0xffffffff,I4,-1);
6495     VARAND(I1,-1,UINT,0,I4,0);
6496     VARAND(I1,0,UINT,0,I4,0);
6497     VARAND(I1,0,BSTR,false_str,I4,0);
6498     VARAND(I1,-1,BSTR,false_str,I4,0);
6499     VARAND(I1,0,BSTR,true_str,I4,0);
6500     VARAND(I1,-1,BSTR,true_str,I4,-1);
6501     VARANDCY(I1,-1,10000,I4,1);
6502     VARANDCY(I1,-1,0,I4,0);
6503     VARANDCY(I1,0,0,I4,0);
6504 
6505     VARAND(UI1,255,UI1,255,UI1,255);
6506     VARAND(UI1,255,UI1,0,UI1,0);
6507     VARAND(UI1,0,UI1,0,UI1,0);
6508     VARAND(UI1,255,I2,-1,I2,255);
6509     VARAND(UI1,255,I2,0,I2,0);
6510     VARAND(UI1,0,I2,0,I2,0);
6511     VARAND(UI1,255,UI2,65535,I4,255);
6512     VARAND(UI1,255,UI2,0,I4,0);
6513     VARAND(UI1,0,UI2,0,I4,0);
6514     VARAND(UI1,255,I4,-1,I4,255);
6515     VARAND(UI1,255,I4,0,I4,0);
6516     VARAND(UI1,0,I4,0,I4,0);
6517     VARAND(UI1,255,UI4,0xffffffff,I4,255);
6518     VARAND(UI1,255,UI4,0,I4,0);
6519     VARAND(UI1,0,UI4,0,I4,0);
6520     VARAND(UI1,255,R4,-1,I4,255);
6521     VARAND(UI1,255,R4,0,I4,0);
6522     VARAND(UI1,0,R4,0,I4,0);
6523     VARAND(UI1,255,R8,-1,I4,255);
6524     VARAND(UI1,255,R8,0,I4,0);
6525     VARAND(UI1,0,R8,0,I4,0);
6526     VARAND(UI1,255,DATE,-1,I4,255);
6527     VARAND(UI1,255,DATE,0,I4,0);
6528     VARAND(UI1,0,DATE,0,I4,0);
6529     if (has_i8)
6530     {
6531         VARAND(UI1,255,I8,-1,I8,255);
6532         VARAND(UI1,255,I8,0,I8,0);
6533         VARAND(UI1,0,I8,0,I8,0);
6534         VARAND(UI1,255,UI8,0,I4,0);
6535         VARAND(UI1,0,UI8,0,I4,0);
6536     }
6537     VARAND(UI1,255,INT,-1,I4,255);
6538     VARAND(UI1,255,INT,0,I4,0);
6539     VARAND(UI1,0,INT,0,I4,0);
6540     VARAND(UI1,255,UINT,0xffffffff,I4,255);
6541     VARAND(UI1,255,UINT,0,I4,0);
6542     VARAND(UI1,0,UINT,0,I4,0);
6543     VARAND(UI1,0,BSTR,false_str,I2,0);
6544     VARAND(UI1,255,BSTR,false_str,I2,0);
6545     VARAND(UI1,0,BSTR,true_str,I2,0);
6546     VARAND(UI1,255,BSTR,true_str,I2,255);
6547     VARANDCY(UI1,255,10000,I4,1);
6548     VARANDCY(UI1,255,0,I4,0);
6549     VARANDCY(UI1,0,0,I4,0);
6550 
6551     VARAND(I2,-1,I2,-1,I2,-1);
6552     VARAND(I2,-1,I2,0,I2,0);
6553     VARAND(I2,0,I2,0,I2,0);
6554     VARAND(I2,-1,UI2,65535,I4,65535);
6555     VARAND(I2,-1,UI2,0,I4,0);
6556     VARAND(I2,0,UI2,0,I4,0);
6557     VARAND(I2,-1,I4,-1,I4,-1);
6558     VARAND(I2,-1,I4,0,I4,0);
6559     VARAND(I2,0,I4,0,I4,0);
6560     VARAND(I2,-1,UI4,0xffffffff,I4,-1);
6561     VARAND(I2,-1,UI4,0,I4,0);
6562     VARAND(I2,0,UI4,0,I4,0);
6563     VARAND(I2,-1,R4,-1,I4,-1);
6564     VARAND(I2,-1,R4,0,I4,0);
6565     VARAND(I2,0,R4,0,I4,0);
6566     VARAND(I2,-1,R8,-1,I4,-1);
6567     VARAND(I2,-1,R8,0,I4,0);
6568     VARAND(I2,0,R8,0,I4,0);
6569     VARAND(I2,-1,DATE,-1,I4,-1);
6570     VARAND(I2,-1,DATE,0,I4,0);
6571     VARAND(I2,0,DATE,0,I4,0);
6572     if (has_i8)
6573     {
6574         VARAND(I2,-1,I8,-1,I8,-1);
6575         VARAND(I2,-1,I8,0,I8,0);
6576         VARAND(I2,0,I8,0,I8,0);
6577         VARAND(I2,-1,UI8,0,I4,0);
6578         VARAND(I2,0,UI8,0,I4,0);
6579     }
6580     VARAND(I2,-1,INT,-1,I4,-1);
6581     VARAND(I2,-1,INT,0,I4,0);
6582     VARAND(I2,0,INT,0,I4,0);
6583     VARAND(I2,-1,UINT,0xffffffff,I4,-1);
6584     VARAND(I2,-1,UINT,0,I4,0);
6585     VARAND(I2,0,UINT,0,I4,0);
6586     VARAND(I2,0,BSTR,false_str,I2,0);
6587     VARAND(I2,-1,BSTR,false_str,I2,0);
6588     VARAND(I2,0,BSTR,true_str,I2,0);
6589     VARAND(I2,-1,BSTR,true_str,I2,-1);
6590     VARANDCY(I2,-1,10000,I4,1);
6591     VARANDCY(I2,-1,0,I4,0);
6592     VARANDCY(I2,0,0,I4,0);
6593 
6594     VARAND(UI2,65535,UI2,65535,I4,65535);
6595     VARAND(UI2,65535,UI2,0,I4,0);
6596     VARAND(UI2,0,UI2,0,I4,0);
6597     VARAND(UI2,65535,I4,-1,I4,65535);
6598     VARAND(UI2,65535,I4,0,I4,0);
6599     VARAND(UI2,0,I4,0,I4,0);
6600     VARAND(UI2,65535,UI4,0xffffffff,I4,65535);
6601     VARAND(UI2,65535,UI4,0,I4,0);
6602     VARAND(UI2,0,UI4,0,I4,0);
6603     VARAND(UI2,65535,R4,-1,I4,65535);
6604     VARAND(UI2,65535,R4,0,I4,0);
6605     VARAND(UI2,0,R4,0,I4,0);
6606     VARAND(UI2,65535,R8,-1,I4,65535);
6607     VARAND(UI2,65535,R8,0,I4,0);
6608     VARAND(UI2,0,R8,0,I4,0);
6609     VARAND(UI2,65535,DATE,-1,I4,65535);
6610     VARAND(UI2,65535,DATE,0,I4,0);
6611     VARAND(UI2,0,DATE,0,I4,0);
6612     if (has_i8)
6613     {
6614         VARAND(UI2,65535,I8,-1,I8,65535);
6615         VARAND(UI2,65535,I8,0,I8,0);
6616         VARAND(UI2,0,I8,0,I8,0);
6617         VARAND(UI2,65535,UI8,0,I4,0);
6618         VARAND(UI2,0,UI8,0,I4,0);
6619     }
6620     VARAND(UI2,65535,INT,-1,I4,65535);
6621     VARAND(UI2,65535,INT,0,I4,0);
6622     VARAND(UI2,0,INT,0,I4,0);
6623     VARAND(UI2,65535,UINT,0xffffffff,I4,65535);
6624     VARAND(UI2,65535,UINT,0,I4,0);
6625     VARAND(UI2,0,UINT,0,I4,0);
6626     VARAND(UI2,0,BSTR,false_str,I4,0);
6627     VARAND(UI2,65535,BSTR,false_str,I4,0);
6628     VARAND(UI2,0,BSTR,true_str,I4,0);
6629     VARAND(UI2,65535,BSTR,true_str,I4,65535);
6630     VARANDCY(UI2,65535,10000,I4,1);
6631     VARANDCY(UI2,65535,0,I4,0);
6632     VARANDCY(UI2,0,0,I4,0);
6633 
6634     VARAND(I4,-1,I4,-1,I4,-1);
6635     VARAND(I4,-1,I4,0,I4,0);
6636     VARAND(I4,0,I4,0,I4,0);
6637     VARAND(I4,-1,UI4,0xffffffff,I4,-1);
6638     VARAND(I4,-1,UI4,0,I4,0);
6639     VARAND(I4,0,UI4,0,I4,0);
6640     VARAND(I4,-1,R4,-1,I4,-1);
6641     VARAND(I4,-1,R4,0,I4,0);
6642     VARAND(I4,0,R4,0,I4,0);
6643     VARAND(I4,-1,R8,-1,I4,-1);
6644     VARAND(I4,-1,R8,0,I4,0);
6645     VARAND(I4,0,R8,0,I4,0);
6646     VARAND(I4,-1,DATE,-1,I4,-1);
6647     VARAND(I4,-1,DATE,0,I4,0);
6648     VARAND(I4,0,DATE,0,I4,0);
6649     if (has_i8)
6650     {
6651         VARAND(I4,-1,I8,-1,I8,-1);
6652         VARAND(I4,-1,I8,0,I8,0);
6653         VARAND(I4,0,I8,0,I8,0);
6654         VARAND(I4,-1,UI8,0,I4,0);
6655         VARAND(I4,0,UI8,0,I4,0);
6656     }
6657     VARAND(I4,-1,INT,-1,I4,-1);
6658     VARAND(I4,-1,INT,0,I4,0);
6659     VARAND(I4,0,INT,0,I4,0);
6660     VARAND(I4,-1,UINT,0xffffffff,I4,-1);
6661     VARAND(I4,-1,UINT,0,I4,0);
6662     VARAND(I4,0,UINT,0,I4,0);
6663     VARAND(I4,0,BSTR,false_str,I4,0);
6664     VARAND(I4,-1,BSTR,false_str,I4,0);
6665     VARAND(I4,0,BSTR,true_str,I4,0);
6666     VARAND(I4,-1,BSTR,true_str,I4,-1);
6667     VARANDCY(I4,-1,10000,I4,1);
6668     VARANDCY(I4,-1,0,I4,0);
6669     VARANDCY(I4,0,0,I4,0);
6670 
6671     VARAND(UI4,0xffffffff,UI4,0xffffffff,I4,-1);
6672     VARAND(UI4,0xffffffff,UI4,0,I4,0);
6673     VARAND(UI4,0,UI4,0,I4,0);
6674     VARAND(UI4,0xffffffff,R4,-1,I4,-1);
6675     VARAND(UI4,0xffffffff,R4,0,I4,0);
6676     VARAND(UI4,0,R4,0,I4,0);
6677     VARAND(UI4,0xffffffff,R8,-1,I4,-1);
6678     VARAND(UI4,0xffffffff,R8,0,I4,0);
6679     VARAND(UI4,0,R8,0,I4,0);
6680     VARAND(UI4,0xffffffff,DATE,-1,I4,-1);
6681     VARAND(UI4,0xffffffff,DATE,0,I4,0);
6682     VARAND(UI4,0,DATE,0,I4,0);
6683     if (has_i8)
6684     {
6685         VARAND(UI4,0xffffffff,I8,0,I8,0);
6686         VARAND(UI4,0,I8,0,I8,0);
6687         VARAND(UI4,0xffffffff,UI8,0,I4,0);
6688         VARAND(UI4,0,UI8,0,I4,0);
6689     }
6690     VARAND(UI4,0xffffffff,INT,-1,I4,-1);
6691     VARAND(UI4,0xffffffff,INT,0,I4,0);
6692     VARAND(UI4,0,INT,0,I4,0);
6693     VARAND(UI4,0xffffffff,UINT,0xffffffff,I4,-1);
6694     VARAND(UI4,0xffffffff,UINT,0,I4,0);
6695     VARAND(UI4,0,UINT,0,I4,0);
6696     VARAND(UI4,0,BSTR,false_str,I4,0);
6697     VARAND(UI4,0xffffffff,BSTR,false_str,I4,0);
6698     VARAND(UI4,0,BSTR,true_str,I4,0);
6699     VARAND(UI4,0xffffffff,BSTR,true_str,I4,-1);
6700     VARANDCY(UI4,0xffffffff,10000,I4,1);
6701     VARANDCY(UI4,0xffffffff,0,I4,0);
6702     VARANDCY(UI4,0,0,I4,0);
6703 
6704     VARAND(R4,-1,R4,-1,I4,-1);
6705     VARAND(R4,-1,R4,0,I4,0);
6706     VARAND(R4,0,R4,0,I4,0);
6707     VARAND(R4,-1,R8,-1,I4,-1);
6708     VARAND(R4,-1,R8,0,I4,0);
6709     VARAND(R4,0,R8,0,I4,0);
6710     VARAND(R4,-1,DATE,-1,I4,-1);
6711     VARAND(R4,-1,DATE,0,I4,0);
6712     VARAND(R4,0,DATE,0,I4,0);
6713     if (has_i8)
6714     {
6715         VARAND(R4,-1,I8,-1,I8,-1);
6716         VARAND(R4,-1,I8,0,I8,0);
6717         VARAND(R4,0,I8,0,I8,0);
6718         VARAND(R4,-1,UI8,0,I4,0);
6719         VARAND(R4,0,UI8,0,I4,0);
6720     }
6721     VARAND(R4,-1,INT,-1,I4,-1);
6722     VARAND(R4,-1,INT,0,I4,0);
6723     VARAND(R4,0,INT,0,I4,0);
6724     VARAND(R4,-1,UINT,0xffffffff,I4,-1);
6725     VARAND(R4,-1,UINT,0,I4,0);
6726     VARAND(R4,0,UINT,0,I4,0);
6727     VARAND(R4,0,BSTR,false_str,I4,0);
6728     VARAND(R4,-1,BSTR,false_str,I4,0);
6729     VARAND(R4,0,BSTR,true_str,I4,0);
6730     VARAND(R4,-1,BSTR,true_str,I4,-1);
6731     VARANDCY(R4,-1,10000,I4,1);
6732     VARANDCY(R4,-1,0,I4,0);
6733     VARANDCY(R4,0,0,I4,0);
6734 
6735     VARAND(R8,-1,R8,-1,I4,-1);
6736     VARAND(R8,-1,R8,0,I4,0);
6737     VARAND(R8,0,R8,0,I4,0);
6738     VARAND(R8,-1,DATE,-1,I4,-1);
6739     VARAND(R8,-1,DATE,0,I4,0);
6740     VARAND(R8,0,DATE,0,I4,0);
6741     if (has_i8)
6742     {
6743         VARAND(R8,-1,I8,-1,I8,-1);
6744         VARAND(R8,-1,I8,0,I8,0);
6745         VARAND(R8,0,I8,0,I8,0);
6746         VARAND(R8,-1,UI8,0,I4,0);
6747         VARAND(R8,0,UI8,0,I4,0);
6748     }
6749     VARAND(R8,-1,INT,-1,I4,-1);
6750     VARAND(R8,-1,INT,0,I4,0);
6751     VARAND(R8,0,INT,0,I4,0);
6752     VARAND(R8,-1,UINT,0xffffffff,I4,-1);
6753     VARAND(R8,-1,UINT,0,I4,0);
6754     VARAND(R8,0,UINT,0,I4,0);
6755     VARAND(R8,0,BSTR,false_str,I4,0);
6756     VARAND(R8,-1,BSTR,false_str,I4,0);
6757     VARAND(R8,0,BSTR,true_str,I4,0);
6758     VARAND(R8,-1,BSTR,true_str,I4,-1);
6759     VARANDCY(R8,-1,10000,I4,1);
6760     VARANDCY(R8,-1,0,I4,0);
6761     VARANDCY(R8,0,0,I4,0);
6762 
6763     VARAND(DATE,-1,DATE,-1,I4,-1);
6764     VARAND(DATE,-1,DATE,0,I4,0);
6765     VARAND(DATE,0,DATE,0,I4,0);
6766     if (has_i8)
6767     {
6768         VARAND(DATE,-1,I8,-1,I8,-1);
6769         VARAND(DATE,-1,I8,0,I8,0);
6770         VARAND(DATE,0,I8,0,I8,0);
6771         VARAND(DATE,-1,UI8,0,I4,0);
6772         VARAND(DATE,0,UI8,0,I4,0);
6773     }
6774     VARAND(DATE,-1,INT,-1,I4,-1);
6775     VARAND(DATE,-1,INT,0,I4,0);
6776     VARAND(DATE,0,INT,0,I4,0);
6777     VARAND(DATE,-1,UINT,0xffffffff,I4,-1);
6778     VARAND(DATE,-1,UINT,0,I4,0);
6779     VARAND(DATE,0,UINT,0,I4,0);
6780     VARAND(DATE,0,BSTR,false_str,I4,0);
6781     VARAND(DATE,-1,BSTR,false_str,I4,0);
6782     VARAND(DATE,0,BSTR,true_str,I4,0);
6783     VARAND(DATE,-1,BSTR,true_str,I4,-1);
6784     VARANDCY(DATE,-1,10000,I4,1);
6785     VARANDCY(DATE,-1,0,I4,0);
6786     VARANDCY(DATE,0,0,I4,0);
6787 
6788     if (has_i8)
6789     {
6790         VARAND(I8,-1,I8,-1,I8,-1);
6791         VARAND(I8,-1,I8,0,I8,0);
6792         VARAND(I8,0,I8,0,I8,0);
6793         VARAND(I8,-1,UI8,0,I8,0);
6794         VARAND(I8,0,UI8,0,I8,0);
6795         VARAND(I8,-1,UINT,0,I8,0);
6796         VARAND(I8,0,UINT,0,I8,0);
6797         VARAND(I8,0,BSTR,false_str,I8,0);
6798         VARAND(I8,-1,BSTR,false_str,I8,0);
6799         VARAND(I8,0,BSTR,true_str,I8,0);
6800         VARAND(I8,-1,BSTR,true_str,I8,-1);
6801         VARANDCY(I8,-1,10000,I8,1);
6802         VARANDCY(I8,-1,0,I8,0);
6803         VARANDCY(I8,0,0,I8,0);
6804 
6805         VARAND(UI8,0xffff,UI8,0xffff,I4,0xffff);
6806         VARAND(UI8,0xffff,UI8,0,I4,0);
6807         VARAND(UI8,0,UI8,0,I4,0);
6808         VARAND(UI8,0xffff,INT,-1,I4,65535);
6809         VARAND(UI8,0xffff,INT,0,I4,0);
6810         VARAND(UI8,0,INT,0,I4,0);
6811         VARAND(UI8,0xffff,UINT,0xffff,I4,0xffff);
6812         VARAND(UI8,0xffff,UINT,0,I4,0);
6813         VARAND(UI8,0,UINT,0,I4,0);
6814         VARAND(UI8,0,BSTR,false_str,I4,0);
6815         VARAND(UI8,0xffff,BSTR,false_str,I4,0);
6816         VARAND(UI8,0,BSTR,true_str,I4,0);
6817         VARAND(UI8,0xffff,BSTR,true_str,I4,65535);
6818         VARANDCY(UI8,0xffff,10000,I4,1);
6819         VARANDCY(UI8,0xffff,0,I4,0);
6820         VARANDCY(UI8,0,0,I4,0);
6821     }
6822 
6823     VARAND(INT,-1,INT,-1,I4,-1);
6824     VARAND(INT,-1,INT,0,I4,0);
6825     VARAND(INT,0,INT,0,I4,0);
6826     VARAND(INT,-1,UINT,0xffff,I4,65535);
6827     VARAND(INT,-1,UINT,0,I4,0);
6828     VARAND(INT,0,UINT,0,I4,0);
6829     VARAND(INT,0,BSTR,false_str,I4,0);
6830     VARAND(INT,-1,BSTR,false_str,I4,0);
6831     VARAND(INT,0,BSTR,true_str,I4,0);
6832     VARAND(INT,-1,BSTR,true_str,I4,-1);
6833     VARANDCY(INT,-1,10000,I4,1);
6834     VARANDCY(INT,-1,0,I4,0);
6835     VARANDCY(INT,0,0,I4,0);
6836 
6837     VARAND(UINT,0xffff,UINT,0xffff,I4,0xffff);
6838     VARAND(UINT,0xffff,UINT,0,I4,0);
6839     VARAND(UINT,0,UINT,0,I4,0);
6840     VARAND(UINT,0,BSTR,false_str,I4,0);
6841     VARAND(UINT,0xffff,BSTR, false_str,I4,0);
6842     VARAND(UINT,0,BSTR,true_str,I4,0);
6843     VARAND(UINT,0xffff,BSTR,true_str,I4,65535);
6844     VARANDCY(UINT,0xffff,10000,I4,1);
6845     VARANDCY(UINT,0xffff,0,I4,0);
6846     VARANDCY(UINT,0,0,I4,0);
6847 
6848     VARAND(BSTR,false_str,BSTR,false_str,BOOL,0);
6849     VARAND(BSTR,true_str,BSTR,false_str,BOOL,VARIANT_FALSE);
6850     VARAND(BSTR,true_str,BSTR,true_str,BOOL,VARIANT_TRUE);
6851     VARANDCY(BSTR,true_str,10000,I4,1);
6852     VARANDCY(BSTR,false_str,10000,I4,0);
6853 
6854     SysFreeString(true_str);
6855     SysFreeString(false_str);
6856 }
6857 
6858 static void test_cmp( int line, LCID lcid, UINT flags, VARIANT *left, VARIANT *right, HRESULT result )
6859 {
6860     HRESULT hres;
6861 
6862     CHECKPTR(VarCmp);
6863 
6864     hres = pVarCmp(left,right,lcid,flags);
6865     ok_(__FILE__,line)(hres == result, "VarCmp(%s,%s): expected 0x%x, got hres=0x%x\n",
6866                        variantstr(left), variantstr(right), result, hres );
6867 }
6868 static void test_cmpex( int line, LCID lcid, VARIANT *left, VARIANT *right,
6869                         HRESULT res1, HRESULT res2, HRESULT res3, HRESULT res4 )
6870 {
6871     test_cmp( line, lcid, 0, left, right, res1 );
6872     V_VT(left) |= VT_RESERVED;
6873     test_cmp( line, lcid, 0, left, right, res2 );
6874     V_VT(left) &= ~VT_RESERVED;
6875     V_VT(right) |= VT_RESERVED;
6876     test_cmp( line, lcid, 0, left, right, res3 );
6877     V_VT(left) |= VT_RESERVED;
6878     test_cmp( line, lcid, 0, left, right, res4 );
6879     ok_(__FILE__,line)(V_VT(left) & V_VT(right) & VT_RESERVED, "VT_RESERVED filtered out\n");
6880 }
6881 
6882 /* ERROR from wingdi.h is interfering here */
6883 #undef ERROR
6884 #define _VARCMP(vt1,val1,vtfl1,vt2,val2,vtfl2,lcid,flags,result) \
6885         V_##vt1(&left) = val1; V_VT(&left) = VT_##vt1 | vtfl1; \
6886         V_##vt2(&right) = val2; V_VT(&right) = VT_##vt2 | vtfl2; \
6887         test_cmp( __LINE__, lcid, flags, &left, &right, result )
6888 #define VARCMPEX(vt1,val1,vt2,val2,res1,res2,res3,res4) \
6889         V_##vt1(&left) = val1; V_VT(&left) = VT_##vt1; \
6890         V_##vt2(&right) = val2; V_VT(&right) = VT_##vt2; \
6891         test_cmpex( __LINE__, lcid, &left, &right, res1, res2, res3, res4 )
6892 #define VARCMP(vt1,val1,vt2,val2,result) \
6893         VARCMPEX(vt1,val1,vt2,val2,result,result,result,result)
6894 /* The above macros do not work for VT_NULL as NULL gets expanded first */
6895 #define V_NULL_  V_NULL
6896 #define VT_NULL_ VT_NULL
6897 
6898 static void test_VarCmp(void)
6899 {
6900     VARIANT left, right;
6901     VARTYPE i;
6902     LCID lcid;
6903     HRESULT hres;
6904     DECIMAL dec;
6905     static const WCHAR szhuh[] = {'h','u','h','?','\0'};
6906     static const WCHAR sz2cents[] = {'2','c','e','n','t','s','\0'};
6907     static const WCHAR szempty[] = {'\0'};
6908     static const WCHAR sz0[] = {'0','\0'};
6909     static const WCHAR sz1[] = {'1','\0'};
6910     static const WCHAR sz7[] = {'7','\0'};
6911     static const WCHAR sz42[] = {'4','2','\0'};
6912     static const WCHAR sz1neg[] = {'-','1','\0'};
6913     static const WCHAR sz666neg[] = {'-','6','6','6','\0'};
6914     static const WCHAR sz1few[] = {'1','.','0','0','0','0','0','0','0','1','\0'};
6915     BSTR bstrhuh, bstrempty, bstr0, bstr1, bstr7, bstr42, bstr1neg, bstr666neg;
6916     BSTR bstr2cents, bstr1few;
6917 
6918     CHECKPTR(VarCmp);
6919 
6920     lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
6921     bstrempty = SysAllocString(szempty);
6922     bstrhuh = SysAllocString(szhuh);
6923     bstr2cents = SysAllocString(sz2cents);
6924     bstr0 = SysAllocString(sz0);
6925     bstr1 = SysAllocString(sz1);
6926     bstr7 = SysAllocString(sz7);
6927     bstr42 = SysAllocString(sz42);
6928     bstr1neg = SysAllocString(sz1neg);
6929     bstr666neg = SysAllocString(sz666neg);
6930     bstr1few = SysAllocString(sz1few);
6931 
6932     /* Test all possible flag/vt combinations & the resulting vt type */
6933     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
6934     {
6935         VARTYPE leftvt, rightvt;
6936 
6937         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
6938         {
6939 
6940             SKIPTESTS(leftvt);
6941 
6942             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
6943             {
6944                 BOOL bFail = FALSE;
6945                 HRESULT expect = VARCMP_EQ;
6946 
6947                 SKIPTESTS(rightvt);
6948 
6949                 memset(&left, 0, sizeof(left));
6950                 memset(&right, 0, sizeof(right));
6951                 V_VT(&left) = leftvt | ExtraFlags[i];
6952                 if (leftvt == VT_BSTR) {
6953                     V_BSTR(&left) = bstr1neg;
6954                     if (ExtraFlags[i] & VT_RESERVED)
6955                         expect = VARCMP_LT;
6956                     else
6957                         expect = VARCMP_GT;
6958                 }
6959                 V_VT(&right) = rightvt | ExtraFlags[i];
6960                 if (rightvt == VT_BSTR) {
6961                     V_BSTR(&right) = bstr1neg;
6962                     if (ExtraFlags[i] & VT_RESERVED)
6963                         expect = VARCMP_GT;
6964                     else
6965                         expect = VARCMP_LT;
6966                 }
6967 
6968                 /* Don't ask me why but native VarCmp cannot handle:
6969                    VT_I1, VT_UI2, VT_UI4, VT_UINT and VT_UI8.
6970                    VT_INT is only supported as left variant. Go figure.
6971                    Tested with DCOM98, Win2k, WinXP */
6972                 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
6973                     !IsValidVariantClearVT(leftvt, ExtraFlags[i] & ~VT_RESERVED) ||
6974                     !IsValidVariantClearVT(rightvt, ExtraFlags[i] & ~VT_RESERVED) ||
6975                     leftvt == VT_CLSID || rightvt == VT_CLSID ||
6976                     leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
6977                     leftvt == VT_ERROR || rightvt == VT_ERROR ||
6978                     leftvt == VT_RECORD || rightvt == VT_RECORD ||
6979                     leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN ||
6980                     leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
6981                     leftvt == VT_I1 || rightvt == VT_I1 ||
6982                     leftvt == VT_UI2 || rightvt == VT_UI2 ||
6983                     leftvt == VT_UI4 || rightvt == VT_UI4 ||
6984                     leftvt == VT_UI8 || rightvt == VT_UI8 ||
6985                     rightvt == VT_INT ||
6986                     leftvt == VT_UINT || rightvt == VT_UINT) {
6987                     bFail = TRUE;
6988                 }
6989 
6990                 if (leftvt == VT_ERROR && rightvt == VT_ERROR &&
6991                     !(ExtraFlags[i] & ~VT_RESERVED)) {
6992                     expect = VARCMP_EQ;
6993                     bFail = FALSE;
6994                 } else if (leftvt == VT_NULL || rightvt == VT_NULL)
6995                     expect = VARCMP_NULL;
6996                 else if (leftvt == VT_BSTR && rightvt == VT_BSTR)
6997                     expect = VARCMP_EQ;
6998                 else if (leftvt == VT_BSTR && rightvt == VT_EMPTY)
6999                     expect = VARCMP_GT;
7000                 else if (leftvt == VT_EMPTY && rightvt == VT_BSTR)
7001                     expect = VARCMP_LT;
7002 
7003                 hres = pVarCmp(&left, &right, LOCALE_USER_DEFAULT, 0);
7004                 if (bFail) {
7005                     ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
7006                        "VarCmp: %d|0x%X, %d|0x%X: Expected failure, got 0x%X\n",
7007                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres);
7008                 } else {
7009                     ok(hres == expect,
7010                        "VarCmp: %d|0x%X, %d|0x%X: Expected 0x%X, got 0x%X\n",
7011                        leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], expect,
7012                        hres);
7013                 }
7014             }
7015         }
7016     }
7017 
7018     /* VARCMP{,EX} run each 4 tests with a permutation of all possible
7019        input variants with (1) and without (0) VT_RESERVED set. The order
7020        of the permutations is (0,0); (1,0); (0,1); (1,1) */
7021     VARCMP(INT,4711,I2,4711,VARCMP_EQ);
7022     VARCMP(INT,4711,I2,-4711,VARCMP_GT);
7023     VARCMP(ERROR,0,ERROR,0,VARCMP_EQ);
7024     VARCMP(ERROR,0,UI1,0,DISP_E_TYPEMISMATCH);
7025     VARCMP(EMPTY,0,EMPTY,0,VARCMP_EQ);
7026     VARCMP(I4,1,R8,1.0,VARCMP_EQ);
7027     VARCMP(EMPTY,19,I2,0,VARCMP_EQ);
7028     ok(V_EMPTY(&left) == 19, "VT_EMPTY modified!\n");
7029     VARCMP(I4,1,UI1,1,VARCMP_EQ);
7030     VARCMP(I2,2,I2,2,VARCMP_EQ);
7031     VARCMP(I2,1,I2,2,VARCMP_LT);
7032     VARCMP(I2,2,I2,1,VARCMP_GT);
7033     VARCMP(I2,2,EMPTY,1,VARCMP_GT);
7034     VARCMP(I2,2,NULL_,1,VARCMP_NULL);
7035 
7036     /* BSTR handling, especially in conjunction with VT_RESERVED */
7037     VARCMP(BSTR,bstr0,NULL_,0,VARCMP_NULL);
7038     VARCMP(BSTR,bstr0,BSTR,bstr0,VARCMP_EQ);
7039     VARCMP(BSTR,bstrempty,BSTR,bstr0,VARCMP_LT);
7040     VARCMP(BSTR,bstr7,BSTR,bstr0,VARCMP_GT);
7041     VARCMP(BSTR,bstr7,BSTR,bstr1neg,VARCMP_GT);
7042     VARCMP(BSTR,bstr0,BSTR,NULL,VARCMP_GT);
7043     VARCMP(BSTR,NULL,BSTR,NULL,VARCMP_EQ);
7044     VARCMP(BSTR,bstrempty,BSTR,NULL,VARCMP_EQ);
7045     VARCMP(BSTR,NULL,EMPTY,0,VARCMP_EQ);
7046     VARCMP(EMPTY,0,BSTR,NULL,VARCMP_EQ);
7047     VARCMP(EMPTY,0,BSTR,bstrempty,VARCMP_EQ);
7048     VARCMP(EMPTY,1,BSTR,bstrempty,VARCMP_EQ);
7049     VARCMP(BSTR,bstr0,EMPTY,0,VARCMP_GT);
7050     VARCMP(BSTR,bstr42,EMPTY,0,VARCMP_GT);
7051     VARCMPEX(BSTR,bstrempty,UI1,0,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
7052     VARCMPEX(BSTR,bstrempty,I2,-1,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
7053     VARCMPEX(I4,0,BSTR,bstrempty,VARCMP_LT,VARCMP_LT,VARCMP_GT,VARCMP_LT);
7054     VARCMPEX(BSTR,NULL,UI1,0,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
7055     VARCMPEX(I4,7,BSTR,NULL,VARCMP_LT,VARCMP_LT,VARCMP_GT,VARCMP_LT);
7056     _VARCMP(BSTR,(BSTR)100,0,I2,100,0,lcid,0,VARCMP_GT);
7057     VARCMPEX(BSTR,bstr0,UI1,0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
7058     VARCMPEX(I2,0,BSTR,bstr0,VARCMP_LT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT);
7059     VARCMP(BSTR,bstrhuh,I4,I4_MAX,VARCMP_GT);
7060     VARCMP(BSTR,bstr2cents,I4,2,VARCMP_GT);
7061     VARCMPEX(BSTR,bstr2cents,I4,42,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
7062     VARCMP(BSTR,bstr2cents,I4,-1,VARCMP_GT);
7063     VARCMPEX(BSTR,bstr2cents,I4,-666,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
7064     VARCMPEX(BSTR,bstr0,I2,0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
7065     VARCMPEX(BSTR,bstr0,I4,0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
7066     VARCMPEX(BSTR,bstr0,I4,-666,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
7067     VARCMP(BSTR,bstr1,I4,0,VARCMP_GT);
7068     VARCMPEX(BSTR,bstr1,I4,1,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
7069     VARCMPEX(BSTR,bstr1,I4,I4_MAX,VARCMP_GT,VARCMP_LT,VARCMP_LT,VARCMP_GT);
7070     VARCMPEX(BSTR,bstr1,I4,-1,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
7071     VARCMP(BSTR,bstr7,I4,1,VARCMP_GT);
7072     VARCMPEX(BSTR,bstr7,I4,7,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
7073     VARCMPEX(BSTR,bstr7,I4,42,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_GT);
7074     VARCMPEX(BSTR,bstr42,I4,7,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
7075     VARCMPEX(BSTR,bstr42,I4,42,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
7076     VARCMPEX(BSTR,bstr42,I4,I4_MAX,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_GT);
7077     VARCMPEX(BSTR,bstr1neg,I4,1,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
7078     VARCMPEX(BSTR,bstr1neg,I4,42,VARCMP_GT,VARCMP_LT,VARCMP_LT,VARCMP_LT);
7079     VARCMPEX(BSTR,bstr1neg,I4,-1,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT);
7080     VARCMPEX(BSTR,bstr1neg,I4,-666,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_LT);
7081     VARCMPEX(BSTR,bstr666neg,I4,1,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
7082     VARCMPEX(BSTR,bstr666neg,I4,7,VARCMP_GT,VARCMP_LT,VARCMP_LT,VARCMP_LT);
7083     VARCMPEX(BSTR,bstr666neg,I4,42,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
7084     VARCMPEX(BSTR,bstr666neg,I4,I4_MAX,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
7085     VARCMPEX(BSTR,bstr666neg,I4,-1,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
7086     VARCMPEX(BSTR,bstr666neg,I4,-666,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT);
7087     VARCMPEX(BSTR,bstr7,R8,7.0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
7088     VARCMPEX(R8,3.141592,BSTR,NULL,VARCMP_LT,VARCMP_LT,VARCMP_GT,VARCMP_LT);
7089     VARCMP(BSTR,bstr7,BSTR,bstr7,VARCMP_EQ);
7090     VARCMP(BSTR,bstr7,BSTR,bstr42,VARCMP_GT);
7091     VARCMP(BSTR,bstr42,BSTR,bstr7,VARCMP_LT);
7092 
7093     /* DECIMAL handling */
7094     setdec(&dec,0,0,0,0);
7095     VARCMPEX(DECIMAL,dec,BSTR,bstr0,VARCMP_LT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT);
7096     setdec64(&dec,0,0,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF); /* max DECIMAL */
7097     VARCMP(DECIMAL,dec,R8,R8_MAX,VARCMP_LT);    /* R8 has bigger range */
7098     VARCMP(DECIMAL,dec,DATE,R8_MAX,VARCMP_LT);  /* DATE has bigger range */
7099     setdec64(&dec,0,0x80,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF);
7100     VARCMP(DECIMAL,dec,R8,-R8_MAX,VARCMP_GT);
7101     setdec64(&dec,20,0,0x5,0x6BC75E2D,0x63100001);    /* 1+1e-20 */
7102     VARCMP(DECIMAL,dec,R8,1,VARCMP_GT); /* DECIMAL has higher precision */
7103 
7104     /* Show that DATE is handled just as a R8 */
7105     VARCMP(DATE,DATE_MAX,DATE,DATE_MAX+1,VARCMP_LT);
7106     VARCMP(DATE,DATE_MIN,DATE,DATE_MIN-1,VARCMP_GT);
7107     VARCMP(DATE,R8_MIN,R8,R8_MIN,VARCMP_EQ);
7108     VARCMP(DATE,1,DATE,1+1e-15,VARCMP_LT);      /* 1e-15 == 8.64e-11 seconds */
7109     VARCMP(DATE,25570.0,DATE,25570.0,VARCMP_EQ);
7110     VARCMP(DATE,25570.0,DATE,25571.0,VARCMP_LT);
7111     VARCMP(DATE,25571.0,DATE,25570.0,VARCMP_GT);
7112     VARCMP(DATE,25570.0,EMPTY,0,VARCMP_GT);
7113     VARCMP(DATE,25570.0,NULL_,0,VARCMP_NULL);
7114 
7115     /* R4 precision handling */
7116     VARCMP(R4,1,R8,1+1e-8,VARCMP_EQ);
7117     VARCMP(R8,1+1e-8,R4,1,VARCMP_EQ);
7118     VARCMP(R8,1+1e-8,R8,1,VARCMP_GT);
7119     VARCMP(R8,R4_MAX*1.1,R4,R4_MAX,VARCMP_GT);
7120     VARCMP(R4,R4_MAX,R8,R8_MAX,VARCMP_LT);
7121     VARCMP(R4,1,DATE,1+1e-8,VARCMP_EQ);
7122     VARCMP(R4,1,BSTR,bstr1few,VARCMP_LT); /* bstr1few == 1+1e-8 */
7123     setdec(&dec,8,0,0,0x5F5E101);         /* 1+1e-8 */
7124     VARCMP(R4,1,DECIMAL,dec,VARCMP_LT);
7125 
7126     SysFreeString(bstrhuh);
7127     SysFreeString(bstrempty);
7128     SysFreeString(bstr0);
7129     SysFreeString(bstr1);
7130     SysFreeString(bstr7);
7131     SysFreeString(bstr42);
7132     SysFreeString(bstr1neg);
7133     SysFreeString(bstr666neg);
7134     SysFreeString(bstr2cents);
7135     SysFreeString(bstr1few);
7136 }
7137 
7138 static HRESULT (WINAPI *pVarPow)(LPVARIANT,LPVARIANT,LPVARIANT);
7139 
7140 #define VARPOW(vt1,val1,vt2,val2,rvt,rval)               \
7141         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
7142         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
7143         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
7144         test_var_call2( __LINE__, pVarPow, &left, &right, &exp )
7145 
7146 /* Skip any type that is not defined or produces an error for every case */
7147 #define SKIPTESTPOW(a)                            \
7148     if (a == VT_ERROR || a == VT_VARIANT ||       \
7149         a == VT_DISPATCH || a == VT_UNKNOWN ||    \
7150         a == VT_RECORD || a > VT_UINT ||          \
7151         a == 15 /*not defined*/)                  \
7152         continue
7153 
7154 static void test_VarPow(void)
7155 {
7156     static const WCHAR str2[] = { '2','\0' };
7157     static const WCHAR str3[] = { '3','\0' };
7158     VARIANT left, right, exp, result, cy, dec;
7159     BSTR num2_str, num3_str;
7160     VARTYPE i;
7161     HRESULT hres;
7162 
7163     CHECKPTR(VarPow);
7164 
7165     num2_str = SysAllocString(str2);
7166     num3_str = SysAllocString(str3);
7167 
7168     /* Test all possible flag/vt combinations & the resulting vt type */
7169     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
7170     {
7171         VARTYPE leftvt, rightvt, resvt;
7172 
7173         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
7174         {
7175             SKIPTESTPOW(leftvt);
7176 
7177             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
7178             {
7179                 BOOL bFail = FALSE;
7180                 SKIPTESTPOW(rightvt);
7181 
7182                 /* Native crashes with VT_BYREF */
7183                 if (ExtraFlags[i] == VT_BYREF)
7184                     continue;
7185 
7186                 memset(&left, 0, sizeof(left));
7187                 memset(&right, 0, sizeof(right));
7188                 V_VT(&left) = leftvt | ExtraFlags[i];
7189                 V_VT(&right) = rightvt | ExtraFlags[i];
7190                 V_VT(&result) = VT_EMPTY;
7191                 resvt = VT_EMPTY;
7192 
7193                 if (leftvt == VT_BSTR)
7194                     V_BSTR(&left) = num2_str;
7195                 if (rightvt == VT_BSTR)
7196                     V_BSTR(&right) = num2_str;
7197 
7198                 /* Native VarPow always returns an error when using extra flags */
7199                 if (ExtraFlags[i] != 0)
7200                     bFail = TRUE;
7201 
7202                 /* Determine return type */
7203                 else if ((leftvt == VT_NULL || rightvt == VT_NULL) &&
7204                          ((leftvt != VT_I8 && leftvt != VT_UI8 &&
7205                            rightvt != VT_I8 && rightvt != VT_UI8) || has_i8))
7206                     resvt = VT_NULL;
7207                 else if ((leftvt == VT_EMPTY || leftvt == VT_I2 ||
7208                     leftvt == VT_I4 || leftvt == VT_R4 ||
7209                     leftvt == VT_R8 || leftvt == VT_CY ||
7210                     leftvt == VT_DATE || leftvt == VT_BSTR ||
7211                     leftvt == VT_BOOL || leftvt == VT_DECIMAL ||
7212                     (leftvt >= VT_I1 && leftvt <= VT_UI4) ||
7213                     (has_i8 && (leftvt == VT_I8 || leftvt == VT_UI8)) ||
7214                     leftvt == VT_INT || leftvt == VT_UINT) &&
7215                     (rightvt == VT_EMPTY || rightvt == VT_I2 ||
7216                     rightvt == VT_I4 || rightvt == VT_R4 ||
7217                     rightvt == VT_R8 || rightvt == VT_CY ||
7218                     rightvt == VT_DATE || rightvt == VT_BSTR ||
7219                     rightvt == VT_BOOL || rightvt == VT_DECIMAL ||
7220                     (rightvt >= VT_I1 && rightvt <= VT_UI4) ||
7221                     (has_i8 && (rightvt == VT_I8 || rightvt == VT_UI8)) ||
7222                     rightvt == VT_INT || rightvt == VT_UINT))
7223                     resvt = VT_R8;
7224                 else
7225                     bFail = TRUE;
7226 
7227                 hres = pVarPow(&left, &right, &result);
7228 
7229                 /* Check expected HRESULT and if result variant type is correct */
7230                 if (bFail)
7231                     ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH,
7232                         "VarPow: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
7233                         vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
7234                         vtstr(V_VT(&result)), hres);
7235                 else
7236                     ok (hres == S_OK && resvt == V_VT(&result),
7237                         "VarPow: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
7238                         vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
7239                         S_OK, vtstr(V_VT(&result)), hres);
7240             }
7241         }
7242     }
7243 
7244     /* Check return values for valid variant type combinations */
7245     VARPOW(EMPTY,0,EMPTY,0,R8,1.0);
7246     VARPOW(EMPTY,0,NULL,0,NULL,0);
7247     VARPOW(EMPTY,0,I2,3,R8,0.0);
7248     VARPOW(EMPTY,0,I4,3,R8,0.0);
7249     VARPOW(EMPTY,0,R4,3.0f,R8,0.0);
7250     VARPOW(EMPTY,0,R8,3.0,R8,0.0);
7251     VARPOW(EMPTY,0,DATE,3,R8,0.0);
7252     VARPOW(EMPTY,0,BSTR,num3_str,R8,0.0);
7253     VARPOW(EMPTY,0,BOOL,VARIANT_FALSE,R8,1.0);
7254     VARPOW(EMPTY,0,I1,3,R8,0.0);
7255     VARPOW(EMPTY,0,UI1,3,R8,0.0);
7256     VARPOW(EMPTY,0,UI2,3,R8,0.0);
7257     VARPOW(EMPTY,0,UI4,3,R8,0.0);
7258     if (has_i8)
7259     {
7260         VARPOW(EMPTY,0,I8,3,R8,0.0);
7261         VARPOW(EMPTY,0,UI8,3,R8,0.0);
7262     }
7263     VARPOW(EMPTY,0,INT,3,R8,0.0);
7264     VARPOW(EMPTY,0,UINT,3,R8,0.0);
7265     VARPOW(NULL,0,EMPTY,0,NULL,0);
7266     VARPOW(NULL,0,NULL,0,NULL,0);
7267     VARPOW(NULL,0,I2,3,NULL,0);
7268     VARPOW(NULL,0,I4,3,NULL,0);
7269     VARPOW(NULL,0,R4,3.0f,NULL,0);
7270     VARPOW(NULL,0,R8,3.0,NULL,0);
7271     VARPOW(NULL,0,DATE,3,NULL,0);
7272     VARPOW(NULL,0,BSTR,num3_str,NULL,0);
7273     VARPOW(NULL,0,BOOL,VARIANT_TRUE,NULL,0);
7274     VARPOW(NULL,0,I1,3,NULL,0);
7275     VARPOW(NULL,0,UI1,3,NULL,0);
7276     VARPOW(NULL,0,UI2,3,NULL,0);
7277     VARPOW(NULL,0,UI4,3,NULL,0);
7278     if (has_i8)
7279     {
7280         VARPOW(NULL,0,I8,3,NULL,0);
7281         VARPOW(NULL,0,UI8,3,NULL,0);
7282     }
7283     VARPOW(NULL,0,INT,3,NULL,0);
7284     VARPOW(NULL,0,UINT,3,NULL,0);
7285     VARPOW(I2,2,EMPTY,0,R8,1.0);
7286     VARPOW(I2,2,NULL,0,NULL,0);
7287     VARPOW(I2,2,I2,3,R8,8.0);
7288     VARPOW(I2,2,I4,3,R8,8.0);
7289     VARPOW(I2,2,R4,3.0f,R8,8.0);
7290     VARPOW(I2,2,R8,3.0,R8,8.0);
7291     VARPOW(I2,2,DATE,3,R8,8.0);
7292     VARPOW(I2,2,BSTR,num3_str,R8,8.0);
7293     VARPOW(I2,2,BOOL,VARIANT_FALSE,R8,1.0);
7294     VARPOW(I2,2,I1,3,R8,8.0);
7295     VARPOW(I2,2,UI1,3,R8,8.0);
7296     VARPOW(I2,2,UI2,3,R8,8.0);
7297     VARPOW(I2,2,UI4,3,R8,8.0);
7298     if (has_i8)
7299     {
7300         VARPOW(I2,2,I8,3,R8,8.0);
7301         VARPOW(I2,2,UI8,3,R8,8.0);
7302     }
7303     VARPOW(I2,2,INT,3,R8,8.0);
7304     VARPOW(I2,2,UINT,3,R8,8.0);
7305     VARPOW(I4,2,EMPTY,0,R8,1.0);
7306     VARPOW(I4,2,NULL,0,NULL,0);
7307     VARPOW(I4,2,I2,3,R8,8.0);
7308     VARPOW(I4,2,I4,3,R8,8.0);
7309     VARPOW(I4,2,R4,3.0f,R8,8.0);
7310     VARPOW(I4,2,R8,3.0,R8,8.0);
7311     VARPOW(I4,2,DATE,3,R8,8.0);
7312     VARPOW(I4,2,BSTR,num3_str,R8,8.0);
7313     VARPOW(I4,2,BOOL,VARIANT_FALSE,R8,1.0);
7314     VARPOW(I4,2,I1,3,R8,8.0);
7315     VARPOW(I4,2,UI1,3,R8,8.0);
7316     VARPOW(I4,2,UI2,3,R8,8.0);
7317     VARPOW(I4,2,UI4,3,R8,8.0);
7318     if (has_i8)
7319     {
7320         VARPOW(I4,2,I8,3,R8,8.0);
7321         VARPOW(I4,2,UI8,3,R8,8.0);
7322     }
7323     VARPOW(I4,2,INT,3,R8,8.0);
7324     VARPOW(I4,2,UINT,3,R8,8.0);
7325     VARPOW(R4,2,EMPTY,0,R8,1.0);
7326     VARPOW(R4,2,NULL,0,NULL,0);
7327     VARPOW(R4,2,I2,3,R8,8.0);
7328     VARPOW(R4,2,I4,3,R8,8.0);
7329     VARPOW(R4,2,R4,3.0f,R8,8.0);
7330     VARPOW(R4,2,R8,3.0,R8,8.0);
7331     VARPOW(R4,2,DATE,3,R8,8.0);
7332     VARPOW(R4,2,BSTR,num3_str,R8,8.0);
7333     VARPOW(R4,2,BOOL,VARIANT_FALSE,R8,1.0);
7334     VARPOW(R4,2,I1,3,R8,8.0);
7335     VARPOW(R4,2,UI1,3,R8,8.0);
7336     VARPOW(R4,2,UI2,3,R8,8.0);
7337     VARPOW(R4,2,UI4,3,R8,8.0);
7338     if (has_i8)
7339     {
7340         VARPOW(R4,2,I8,3,R8,8.0);
7341         VARPOW(R4,2,UI8,3,R8,8.0);
7342     }
7343     VARPOW(R4,2,INT,3,R8,8.0);
7344     VARPOW(R4,2,UINT,3,R8,8.0);
7345     VARPOW(R8,2,EMPTY,0,R8,1.0);
7346     VARPOW(R8,2,NULL,0,NULL,0);
7347     VARPOW(R8,2,I2,3,R8,8.0);
7348     VARPOW(R8,2,I4,3,R8,8.0);
7349     VARPOW(R8,2,R4,3.0f,R8,8.0);
7350     VARPOW(R8,2,R8,3.0,R8,8.0);
7351     VARPOW(R8,2,DATE,3,R8,8.0);
7352     VARPOW(R8,2,BSTR,num3_str,R8,8.0);
7353     VARPOW(R8,2,BOOL,VARIANT_FALSE,R8,1.0);
7354     VARPOW(R8,2,I1,3,R8,8.0);
7355     VARPOW(R8,2,UI1,3,R8,8.0);
7356     VARPOW(R8,2,UI2,3,R8,8.0);
7357     VARPOW(R8,2,UI4,3,R8,8.0);
7358     if (has_i8)
7359     {
7360         VARPOW(R8,2,I8,3,R8,8.0);
7361         VARPOW(R8,2,UI8,3,R8,8.0);
7362     }
7363     VARPOW(R8,2,INT,3,R8,8.0);
7364     VARPOW(R8,2,UINT,3,R8,8.0);
7365     VARPOW(DATE,2,EMPTY,0,R8,1.0);
7366     VARPOW(DATE,2,NULL,0,NULL,0);
7367     VARPOW(DATE,2,I2,3,R8,8.0);
7368     VARPOW(DATE,2,I4,3,R8,8.0);
7369     VARPOW(DATE,2,R4,3.0f,R8,8.0);
7370     VARPOW(DATE,2,R8,3.0,R8,8.0);
7371     VARPOW(DATE,2,DATE,3,R8,8.0);
7372     VARPOW(DATE,2,BSTR,num3_str,R8,8.0);
7373     VARPOW(DATE,2,BOOL,VARIANT_FALSE,R8,1.0);
7374     VARPOW(DATE,2,I1,3,R8,8.0);
7375     VARPOW(DATE,2,UI1,3,R8,8.0);
7376     VARPOW(DATE,2,UI2,3,R8,8.0);
7377     VARPOW(DATE,2,UI4,3,R8,8.0);
7378     if (has_i8)
7379     {
7380         VARPOW(DATE,2,I8,3,R8,8.0);
7381         VARPOW(DATE,2,UI8,3,R8,8.0);
7382     }
7383     VARPOW(DATE,2,INT,3,R8,8.0);
7384     VARPOW(DATE,2,UINT,3,R8,8.0);
7385     VARPOW(BSTR,num2_str,EMPTY,0,R8,1.0);
7386     VARPOW(BSTR,num2_str,NULL,0,NULL,0);
7387     VARPOW(BSTR,num2_str,I2,3,R8,8.0);
7388     VARPOW(BSTR,num2_str,I4,3,R8,8.0);
7389     VARPOW(BSTR,num2_str,R4,3.0f,R8,8.0);
7390     VARPOW(BSTR,num2_str,R8,3.0,R8,8.0);
7391     VARPOW(BSTR,num2_str,DATE,3,R8,8.0);
7392     VARPOW(BSTR,num2_str,BSTR,num3_str,R8,8.0);
7393     VARPOW(BSTR,num2_str,BOOL,VARIANT_FALSE,R8,1.0);
7394     VARPOW(BSTR,num2_str,I1,3,R8,8.0);
7395     VARPOW(BSTR,num2_str,UI1,3,R8,8.0);
7396     VARPOW(BSTR,num2_str,UI2,3,R8,8.0);
7397     VARPOW(BSTR,num2_str,UI4,3,R8,8.0);
7398     if (has_i8)
7399     {
7400         VARPOW(BSTR,num2_str,I8,3,R8,8.0);
7401         VARPOW(BSTR,num2_str,UI8,3,R8,8.0);
7402     }
7403     VARPOW(BSTR,num2_str,INT,3,R8,8.0);
7404     VARPOW(BSTR,num2_str,UINT,3,R8,8.0);
7405     VARPOW(BOOL,VARIANT_TRUE,EMPTY,0,R8,1.0);
7406     VARPOW(BOOL,VARIANT_TRUE,NULL,0,NULL,0);
7407     VARPOW(BOOL,VARIANT_TRUE,I2,3,R8,-1.0);
7408     VARPOW(BOOL,VARIANT_TRUE,I4,3,R8,-1.0);
7409     VARPOW(BOOL,VARIANT_TRUE,R4,3.0f,R8,-1.0);
7410     VARPOW(BOOL,VARIANT_TRUE,R8,3.0,R8,-1.0);
7411     VARPOW(BOOL,VARIANT_TRUE,DATE,3,R8,-1.0);
7412     VARPOW(BOOL,VARIANT_TRUE,BSTR,num3_str,R8,-1.0);
7413     VARPOW(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,R8,-1.0);
7414     VARPOW(BOOL,VARIANT_TRUE,I1,3,R8,-1.0);
7415     VARPOW(BOOL,VARIANT_TRUE,UI1,3,R8,-1.0);
7416     VARPOW(BOOL,VARIANT_TRUE,UI2,3,R8,-1.0);
7417     VARPOW(BOOL,VARIANT_TRUE,UI4,3,R8,-1.0);
7418     if (has_i8)
7419     {
7420         VARPOW(BOOL,VARIANT_TRUE,I8,3,R8,-1.0);
7421         VARPOW(BOOL,VARIANT_TRUE,UI8,3,R8,-1.0);
7422     }
7423     VARPOW(BOOL,VARIANT_TRUE,INT,3,R8,-1.0);
7424     VARPOW(BOOL,VARIANT_TRUE,UINT,3,R8,-1.0);
7425     VARPOW(I1,2,EMPTY,0,R8,1.0);
7426     VARPOW(I1,2,NULL,0,NULL,0);
7427     VARPOW(I1,2,I2,3,R8,8.0);
7428     VARPOW(I1,2,I4,3,R8,8.0);
7429     VARPOW(I1,2,R4,3.0f,R8,8.0);
7430     VARPOW(I1,2,R8,3.0,R8,8.0);
7431     VARPOW(I1,2,DATE,3,R8,8.0);
7432     VARPOW(I1,2,BSTR,num3_str,R8,8.0);
7433     VARPOW(I1,2,BOOL,VARIANT_FALSE,R8,1.0);
7434     VARPOW(I1,2,I1,3,R8,8.0);
7435     VARPOW(I1,2,UI1,3,R8,8.0);
7436     VARPOW(I1,2,UI2,3,R8,8.0);
7437     VARPOW(I1,2,UI4,3,R8,8.0);
7438     if (has_i8)
7439     {
7440         VARPOW(I1,2,I8,3,R8,8.0);
7441         VARPOW(I1,2,UI8,3,R8,8.0);
7442     }
7443     VARPOW(I1,2,INT,3,R8,8.0);
7444     VARPOW(I1,2,UINT,3,R8,8.0);
7445     VARPOW(UI1,2,EMPTY,0,R8,1.0);
7446     VARPOW(UI1,2,NULL,0,NULL,0);
7447     VARPOW(UI1,2,I2,3,R8,8.0);
7448     VARPOW(UI1,2,I4,3,R8,8.0);
7449     VARPOW(UI1,2,R4,3.0f,R8,8.0);
7450     VARPOW(UI1,2,R8,3.0,R8,8.0);
7451     VARPOW(UI1,2,DATE,3,R8,8.0);
7452     VARPOW(UI1,2,BSTR,num3_str,R8,8.0);
7453     VARPOW(UI1,2,BOOL,VARIANT_FALSE,R8,1.0);
7454     VARPOW(UI1,2,I1,3,R8,8.0);
7455     VARPOW(UI1,2,UI1,3,R8,8.0);
7456     VARPOW(UI1,2,UI2,3,R8,8.0);
7457     VARPOW(UI1,2,UI4,3,R8,8.0);
7458     if (has_i8)
7459     {
7460         VARPOW(UI1,2,I8,3,R8,8.0);
7461         VARPOW(UI1,2,UI8,3,R8,8.0);
7462     }
7463     VARPOW(UI1,2,INT,3,R8,8.0);
7464     VARPOW(UI1,2,UINT,3,R8,8.0);
7465     VARPOW(UI2,2,EMPTY,0,R8,1.0);
7466     VARPOW(UI2,2,NULL,0,NULL,0);
7467     VARPOW(UI2,2,I2,3,R8,8.0);
7468     VARPOW(UI2,2,I4,3,R8,8.0);
7469     VARPOW(UI2,2,R4,3.0f,R8,8.0);
7470     VARPOW(UI2,2,R8,3.0,R8,8.0);
7471     VARPOW(UI2,2,DATE,3,R8,8.0);
7472     VARPOW(UI2,2,BSTR,num3_str,R8,8.0);
7473     VARPOW(UI2,2,BOOL,VARIANT_FALSE,R8,1.0);
7474     VARPOW(UI2,2,I1,3,R8,8.0);
7475     VARPOW(UI2,2,UI1,3,R8,8.0);
7476     VARPOW(UI2,2,UI2,3,R8,8.0);
7477     VARPOW(UI2,2,UI4,3,R8,8.0);
7478     if (has_i8)
7479     {
7480         VARPOW(UI2,2,I8,3,R8,8.0);
7481         VARPOW(UI2,2,UI8,3,R8,8.0);
7482     }
7483     VARPOW(UI2,2,INT,3,R8,8.0);
7484     VARPOW(UI2,2,UINT,3,R8,8.0);
7485     VARPOW(UI4,2,EMPTY,0,R8,1.0);
7486     VARPOW(UI4,2,NULL,0,NULL,0);
7487     VARPOW(UI4,2,I2,3,R8,8.0);
7488     VARPOW(UI4,2,I4,3,R8,8.0);
7489     VARPOW(UI4,2,R4,3.0f,R8,8.0);
7490     VARPOW(UI4,2,R8,3.0,R8,8.0);
7491     VARPOW(UI4,2,DATE,3,R8,8.0);
7492     VARPOW(UI4,2,BSTR,num3_str,R8,8.0);
7493     VARPOW(UI4,2,BOOL,VARIANT_FALSE,R8,1.0);
7494     VARPOW(UI4,2,I1,3,R8,8.0);
7495     VARPOW(UI4,2,UI1,3,R8,8.0);
7496     VARPOW(UI4,2,UI2,3,R8,8.0);
7497     VARPOW(UI4,2,UI4,3,R8,8.0);
7498     if (has_i8)
7499     {
7500         VARPOW(UI4,2,I8,3,R8,8.0);
7501         VARPOW(UI4,2,UI8,3,R8,8.0);
7502     }
7503     VARPOW(UI4,2,INT,3,R8,8.0);
7504     VARPOW(UI4,2,UINT,3,R8,8.0);
7505     if (has_i8)
7506     {
7507         VARPOW(I8,2,EMPTY,0,R8,1.0);
7508         VARPOW(I8,2,NULL,0,NULL,0);
7509         VARPOW(I8,2,I2,3,R8,8.0);
7510         VARPOW(I8,2,I4,3,R8,8.0);
7511         VARPOW(I8,2,R4,3.0f,R8,8.0);
7512         VARPOW(I8,2,R8,3.0,R8,8.0);
7513         VARPOW(I8,2,DATE,3,R8,8.0);
7514         VARPOW(I8,2,BSTR,num3_str,R8,8.0);
7515         VARPOW(I8,2,BOOL,VARIANT_FALSE,R8,1.0);
7516         VARPOW(I8,2,I1,3,R8,8.0);
7517         VARPOW(I8,2,UI1,3,R8,8.0);
7518         VARPOW(I8,2,UI2,3,R8,8.0);
7519         VARPOW(I8,2,UI4,3,R8,8.0);
7520         VARPOW(I8,2,I8,3,R8,8.0);
7521         VARPOW(I8,2,UI8,3,R8,8.0);
7522         VARPOW(I8,2,INT,3,R8,8.0);
7523         VARPOW(I8,2,UINT,3,R8,8.0);
7524         VARPOW(UI8,2,EMPTY,0,R8,1.0);
7525         VARPOW(UI8,2,NULL,0,NULL,0);
7526         VARPOW(UI8,2,I2,3,R8,8.0);
7527         VARPOW(UI8,2,I4,3,R8,8.0);
7528         VARPOW(UI8,2,R4,3.0f,R8,8.0);
7529         VARPOW(UI8,2,R8,3.0,R8,8.0);
7530         VARPOW(UI8,2,DATE,3,R8,8.0);
7531         VARPOW(UI8,2,BSTR,num3_str,R8,8.0);
7532         VARPOW(UI8,2,I1,3,R8,8.0);
7533         VARPOW(UI8,2,UI1,3,R8,8.0);
7534         VARPOW(UI8,2,UI2,3,R8,8.0);
7535         VARPOW(UI8,2,UI4,3,R8,8.0);
7536         VARPOW(UI8,2,I8,3,R8,8.0);
7537         VARPOW(UI8,2,UI8,3,R8,8.0);
7538         VARPOW(UI8,2,INT,3,R8,8.0);
7539         VARPOW(UI8,2,UINT,3,R8,8.0);
7540     }
7541     VARPOW(INT,2,EMPTY,0,R8,1.0);
7542     VARPOW(INT,2,NULL,0,NULL,0);
7543     VARPOW(INT,2,I2,3,R8,8.0);
7544     VARPOW(INT,2,I4,3,R8,8.0);
7545     VARPOW(INT,2,R4,3.0f,R8,8.0);
7546     VARPOW(INT,2,R8,3.0,R8,8.0);
7547     VARPOW(INT,2,DATE,3,R8,8.0);
7548     VARPOW(INT,2,BSTR,num3_str,R8,8.0);
7549     VARPOW(INT,2,BOOL,VARIANT_FALSE,R8,1.0);
7550     VARPOW(INT,2,I1,3,R8,8.0);
7551     VARPOW(INT,2,UI1,3,R8,8.0);
7552     VARPOW(INT,2,UI2,3,R8,8.0);
7553     VARPOW(INT,2,UI4,3,R8,8.0);
7554     if (has_i8)
7555     {
7556         VARPOW(INT,2,I8,3,R8,8.0);
7557         VARPOW(INT,2,UI8,3,R8,8.0);
7558     }
7559     VARPOW(INT,2,INT,3,R8,8.0);
7560     VARPOW(INT,2,UINT,3,R8,8.0);
7561     VARPOW(UINT,2,EMPTY,0,R8,1.0);
7562     VARPOW(UINT,2,NULL,0,NULL,0);
7563     VARPOW(UINT,2,I2,3,R8,8.0);
7564     VARPOW(UINT,2,I4,3,R8,8.0);
7565     VARPOW(UINT,2,R4,3.0f,R8,8.0);
7566     VARPOW(UINT,2,R8,3.0,R8,8.0);
7567     VARPOW(UINT,2,DATE,3,R8,8.0);
7568     VARPOW(UINT,2,BSTR,num3_str,R8,8.0);
7569     VARPOW(UINT,2,BOOL,VARIANT_FALSE,R8,1.0);
7570     VARPOW(UINT,2,I1,3,R8,8.0);
7571     VARPOW(UINT,2,UI1,3,R8,8.0);
7572     VARPOW(UINT,2,UI2,3,R8,8.0);
7573     VARPOW(UINT,2,UI4,3,R8,8.0);
7574     if (has_i8)
7575     {
7576         VARPOW(UINT,2,I8,3,R8,8.0);
7577         VARPOW(UINT,2,UI8,3,R8,8.0);
7578     }
7579     VARPOW(UINT,2,INT,3,R8,8.0);
7580     VARPOW(UINT,2,UINT,3,R8,8.0);
7581 
7582     /* Manually test some VT_CY, VT_DECIMAL variants */
7583     V_VT(&cy) = VT_CY;
7584     hres = VarCyFromI4(2, &V_CY(&cy));
7585     ok(hres == S_OK, "VarCyFromI4 failed!\n");
7586     V_VT(&dec) = VT_DECIMAL;
7587     hres = VarDecFromR8(2.0, &V_DECIMAL(&dec));
7588     ok(hres == S_OK, "VarDecFromR4 failed!\n");
7589     memset(&left, 0, sizeof(left));
7590     memset(&right, 0, sizeof(right));
7591     V_VT(&left) = VT_I4;
7592     V_I4(&left) = 100;
7593     V_VT(&right) = VT_I8;
7594     V_UI1(&right) = 2;
7595 
7596     hres = pVarPow(&cy, &cy, &result);
7597     ok(hres == S_OK && V_VT(&result) == VT_R8,
7598         "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7599         S_OK, hres, vtstr(V_VT(&result)));
7600     ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 4.0),
7601         "VARPOW: CY value %f, expected %f\n", V_R8(&result), 4.0);
7602 
7603     hres = pVarPow(&cy, &right, &result);
7604     if (hres == S_OK)
7605     {
7606         ok(V_VT(&result) == VT_R8,
7607            "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7608            S_OK, hres, vtstr(V_VT(&result)));
7609         ok(EQ_DOUBLE(V_R8(&result), 4.0),
7610            "VARPOW: CY value %f, expected %f\n", V_R8(&result), 4.0);
7611     }
7612     else
7613     {
7614         ok(hres == DISP_E_BADVARTYPE && V_VT(&result) == VT_EMPTY,
7615            "VARPOW: expected coerced hres 0x%X type VT_EMPTY, got hres 0x%X type %s!\n",
7616            DISP_E_BADVARTYPE, hres, vtstr(V_VT(&result)));
7617     }
7618 
7619     hres = pVarPow(&left, &cy, &result);
7620     ok(hres == S_OK && V_VT(&result) == VT_R8,
7621         "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7622         S_OK, hres, vtstr(V_VT(&result)));
7623     ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 10000.0),
7624         "VARPOW: CY value %f, expected %f\n", V_R8(&result), 10000.0);
7625 
7626     hres = pVarPow(&left, &dec, &result);
7627     ok(hres == S_OK && V_VT(&result) == VT_R8,
7628         "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7629         S_OK, hres, vtstr(V_VT(&result)));
7630     ok(hres == S_OK && EQ_DOUBLE(V_R8(&result),10000.0),
7631         "VARPOW: DECIMAL value %f, expected %f\n", V_R8(&result), 10000.0);
7632 
7633     hres = pVarPow(&dec, &dec, &result);
7634     ok(hres == S_OK && V_VT(&result) == VT_R8,
7635         "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7636         S_OK, hres, vtstr(V_VT(&result)));
7637     ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 4.0),
7638         "VARPOW: DECIMAL value %f, expected %f\n", V_R8(&result), 4.0);
7639 
7640     hres = pVarPow(&dec, &right, &result);
7641     if (hres == S_OK)
7642     {
7643         ok(V_VT(&result) == VT_R8,
7644            "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7645            S_OK, hres, vtstr(V_VT(&result)));
7646         ok(EQ_DOUBLE(V_R8(&result), 4.0),
7647            "VARPOW: DECIMAL value %f, expected %f\n", V_R8(&result), 4.0);
7648     }
7649     else
7650     {
7651         ok(hres == DISP_E_BADVARTYPE && V_VT(&result) == VT_EMPTY,
7652            "VARPOW: expected coerced hres 0x%X type VT_EMPTY, got hres 0x%X type %s!\n",
7653            DISP_E_BADVARTYPE, hres, vtstr(V_VT(&result)));
7654     }
7655 
7656     SysFreeString(num2_str);
7657     SysFreeString(num3_str);
7658 }
7659 
7660 static HRESULT (WINAPI *pVarDiv)(LPVARIANT,LPVARIANT,LPVARIANT);
7661 
7662 #define VARDIV(vt1,val1,vt2,val2,rvt,rval)               \
7663         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
7664         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
7665         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
7666         test_var_call2( __LINE__, pVarDiv, &left, &right, &exp )
7667 
7668 /* Skip any type that is not defined or produces an error for every case */
7669 #define SKIPTESTDIV(a)                            \
7670     if (a == VT_ERROR || a == VT_VARIANT ||       \
7671         a == VT_DISPATCH || a == VT_UNKNOWN ||    \
7672         a == VT_RECORD || a > VT_UINT ||          \
7673         a == VT_I1 || a == VT_UI8 ||              \
7674         a == VT_INT || a == VT_UINT ||            \
7675         a == VT_UI2 || a == VT_UI4 ||             \
7676         a == 15 /*not defined*/)                  \
7677         continue
7678 
7679 static void test_VarDiv(void)
7680 {
7681     static const WCHAR str1[] = { '1','\0' };
7682     static const WCHAR str2[] = { '2','\0' };
7683     VARIANT left, right, exp, result, cy, dec;
7684     BSTR num1_str, num2_str;
7685     VARTYPE i;
7686     HRESULT hres;
7687     double r;
7688 
7689     CHECKPTR(VarDiv);
7690 
7691     num1_str = SysAllocString(str1);
7692     num2_str = SysAllocString(str2);
7693 
7694     /* Test all possible flag/vt combinations & the resulting vt type */
7695     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
7696     {
7697         VARTYPE leftvt, rightvt, resvt;
7698 
7699         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
7700         {
7701             SKIPTESTDIV(leftvt);
7702 
7703             /* Check if we need/have support for I8 */
7704             if (leftvt == VT_I8 && !has_i8)
7705                 continue;
7706 
7707             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
7708             {
7709                 BOOL bFail = FALSE;
7710                 SKIPTESTDIV(rightvt);
7711 
7712                 /* Check if we need/have support for I8 */
7713                 if (rightvt == VT_I8 && !has_i8)
7714                     continue;
7715 
7716                 /* Native crashes with VT_BYREF */
7717                 if (ExtraFlags[i] == VT_BYREF)
7718                     continue;
7719 
7720                 memset(&left, 0, sizeof(left));
7721                 memset(&right, 0, sizeof(right));
7722                 V_VT(&left) = leftvt | ExtraFlags[i];
7723                 V_VT(&right) = rightvt | ExtraFlags[i];
7724                 V_VT(&result) = VT_EMPTY;
7725                 resvt = VT_EMPTY;
7726 
7727                 if (leftvt == VT_BSTR)
7728                     V_BSTR(&left) = num2_str;
7729                 else if (leftvt == VT_DECIMAL)
7730                 {
7731                     VarDecFromR8(2.0, &V_DECIMAL(&left));
7732                     V_VT(&left) = leftvt | ExtraFlags[i];
7733                 }
7734 
7735                 /* Division by 0 is undefined */
7736                 switch(rightvt)
7737                 {
7738                 case VT_BSTR:
7739                     V_BSTR(&right) = num2_str;
7740                     break;
7741                 case VT_DECIMAL:
7742                     VarDecFromR8(2.0, &V_DECIMAL(&right));
7743                     V_VT(&right) = rightvt | ExtraFlags[i];
7744                     break;
7745                 case VT_BOOL:
7746                     V_BOOL(&right) = VARIANT_TRUE;
7747                     break;
7748                 case VT_I2: V_I2(&right) = 2; break;
7749                 case VT_I4: V_I4(&right) = 2; break;
7750                 case VT_R4: V_R4(&right) = 2.0f; break;
7751                 case VT_R8: V_R8(&right) = 2.0; break;
7752                 case VT_CY: V_CY(&right).int64 = 2; break;
7753                 case VT_DATE: V_DATE(&right) = 2; break;
7754                 case VT_UI1: V_UI1(&right) = 2; break;
7755                 case VT_I8: V_I8(&right) = 2; break;
7756                 default: break;
7757                 }
7758 
7759                 /* Determine return type */
7760                 if (rightvt != VT_EMPTY)
7761                 {
7762                     if (leftvt == VT_NULL || rightvt == VT_NULL)
7763                         resvt = VT_NULL;
7764                     else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
7765                         resvt = VT_DECIMAL;
7766                     else if (leftvt == VT_I8 || rightvt == VT_I8 ||
7767                         leftvt == VT_CY || rightvt == VT_CY ||
7768                         leftvt == VT_DATE || rightvt == VT_DATE ||
7769                         leftvt == VT_I4 || rightvt == VT_I4 ||
7770                         leftvt == VT_BSTR || rightvt == VT_BSTR ||
7771                         leftvt == VT_I2 || rightvt == VT_I2 ||
7772                         leftvt == VT_BOOL || rightvt == VT_BOOL ||
7773                         leftvt == VT_R8 || rightvt == VT_R8 ||
7774                         leftvt == VT_UI1 || rightvt == VT_UI1)
7775                     {
7776                         if ((leftvt == VT_UI1 && rightvt == VT_R4) ||
7777                             (leftvt == VT_R4 && rightvt == VT_UI1))
7778                             resvt = VT_R4;
7779                         else if ((leftvt == VT_R4 && (rightvt == VT_BOOL ||
7780                             rightvt == VT_I2)) || (rightvt == VT_R4 &&
7781                             (leftvt == VT_BOOL || leftvt == VT_I2)))
7782                             resvt = VT_R4;
7783                         else
7784                             resvt = VT_R8;
7785                     }
7786                     else if (leftvt == VT_R4 || rightvt == VT_R4)
7787                         resvt = VT_R4;
7788                 }
7789                 else if (leftvt == VT_NULL)
7790                     resvt = VT_NULL;
7791                 else
7792                     bFail = TRUE;
7793 
7794                 /* Native VarDiv always returns an error when using extra flags */
7795                 if (ExtraFlags[i] != 0)
7796                     bFail = TRUE;
7797 
7798                 hres = pVarDiv(&left, &right, &result);
7799 
7800                 /* Check expected HRESULT and if result variant type is correct */
7801                 if (bFail)
7802                     ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH ||
7803                         hres == DISP_E_OVERFLOW || hres == DISP_E_DIVBYZERO,
7804                         "VarDiv: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
7805                         vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
7806                         vtstr(V_VT(&result)), hres);
7807                 else
7808                     ok (hres == S_OK && resvt == V_VT(&result),
7809                         "VarDiv: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
7810                         vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
7811                         S_OK, vtstr(V_VT(&result)), hres);
7812             }
7813         }
7814     }
7815 
7816     /* Test return values for all the good cases */
7817     VARDIV(EMPTY,0,NULL,0,NULL,0);
7818     VARDIV(EMPTY,0,I2,2,R8,0.0);
7819     VARDIV(EMPTY,0,I4,2,R8,0.0);
7820     VARDIV(EMPTY,0,R4,2.0f,R4,0.0f);
7821     VARDIV(EMPTY,0,R8,2.0,R8,0.0);
7822     VARDIV(EMPTY,0,DATE,2.0,R8,0.0);
7823     VARDIV(EMPTY,0,BSTR,num2_str,R8,0.0);
7824     VARDIV(EMPTY,0,BOOL,VARIANT_TRUE,R8,0.0);
7825     VARDIV(EMPTY,0,UI1,2,R8,0.0);
7826     if (has_i8)
7827     {
7828         VARDIV(EMPTY,0,I8,2,R8,0.0);
7829     }
7830     VARDIV(NULL,0,EMPTY,0,NULL,0);
7831     VARDIV(NULL,0,NULL,0,NULL,0);
7832     VARDIV(NULL,0,I2,2,NULL,0);
7833     VARDIV(NULL,0,I4,2,NULL,0);
7834     VARDIV(NULL,0,R4,2.0f,NULL,0);
7835     VARDIV(NULL,0,R8,2.0,NULL,0);
7836     VARDIV(NULL,0,DATE,2,NULL,0);
7837     VARDIV(NULL,0,BSTR,num2_str,NULL,0);
7838     VARDIV(NULL,0,BOOL,VARIANT_TRUE,NULL,0);
7839     VARDIV(NULL,0,UI1,2,NULL,0);
7840     if (has_i8)
7841     {
7842         VARDIV(NULL,0,I8,2,NULL,0);
7843     }
7844     VARDIV(I2,2,NULL,0,NULL,0);
7845     VARDIV(I2,1,I2,2,R8,0.5);
7846     VARDIV(I2,1,I4,2,R8,0.5);
7847     VARDIV(I2,1,R4,2,R4,0.5f);
7848     VARDIV(I2,1,R8,2.0,R8,0.5);
7849     VARDIV(I2,1,DATE,2,R8,0.5);
7850     VARDIV(I2,1,BOOL,VARIANT_TRUE,R8,-1.0);
7851     VARDIV(I2,1,UI1,2,R8,0.5);
7852     if (has_i8)
7853     {
7854         VARDIV(I2,1,I8,2,R8,0.5);
7855     }
7856     VARDIV(I4,1,NULL,0,NULL,0);
7857     VARDIV(I4,1,I2,2,R8,0.5);
7858     VARDIV(I4,1,I4,2,R8,0.5);
7859     VARDIV(I4,1,R4,2.0f,R8,0.5);
7860     VARDIV(I4,1,R8,2.0,R8,0.5);
7861     VARDIV(I4,1,DATE,2,R8,0.5);
7862     VARDIV(I4,1,BSTR,num2_str,R8,0.5);
7863     VARDIV(I4,1,BOOL,VARIANT_TRUE,R8,-1.0);
7864     VARDIV(I4,1,UI1,2,R8,0.5);
7865     if (has_i8)
7866     {
7867         VARDIV(I4,1,I8,2,R8,0.5);
7868     }
7869     VARDIV(R4,1.0f,NULL,0,NULL,0);
7870     VARDIV(R4,1.0f,I2,2,R4,0.5f);
7871     VARDIV(R4,1.0f,I4,2,R8,0.5);
7872     VARDIV(R4,1.0f,R4,2.0f,R4,0.5f);
7873     VARDIV(R4,1.0f,R8,2.0,R8,0.5);
7874     VARDIV(R4,1.0f,DATE,2,R8,0.5);
7875     VARDIV(R4,1.0f,BSTR,num2_str,R8,0.5);
7876     VARDIV(R4,1.0f,BOOL,VARIANT_TRUE,R4,-1);
7877     VARDIV(R4,1.0f,UI1,2,R4,0.5f);
7878     if (has_i8)
7879     {
7880         VARDIV(R4,1.0f,I8,2,R8,0.5);
7881     }
7882     VARDIV(R8,1.0,NULL,0,NULL,0);
7883     VARDIV(R8,1.0,I2,2,R8,0.5);
7884     VARDIV(R8,1.0,I4,2,R8,0.5);
7885     VARDIV(R8,1.0,R4,2.0f,R8,0.5);
7886     VARDIV(R8,1.0,R8,2.0,R8,0.5);
7887     VARDIV(R8,1.0,DATE,2,R8,0.5);
7888     VARDIV(R8,1.0,BSTR,num2_str,R8,0.5);
7889     VARDIV(R8,1.0,BOOL,VARIANT_TRUE,R8,-1.0);
7890     VARDIV(R8,1.0,UI1,2,R8,0.5);
7891     if (has_i8)
7892     {
7893         VARDIV(R8,1.0,I8,2,R8,0.5);
7894     }
7895     VARDIV(DATE,1,NULL,0,NULL,0);
7896     VARDIV(DATE,1,I2,2,R8,0.5);
7897     VARDIV(DATE,1,I4,2,R8,0.5);
7898     VARDIV(DATE,1,R4,2.0f,R8,0.5);
7899     VARDIV(DATE,1,R8,2.0,R8,0.5);
7900     VARDIV(DATE,1,DATE,2,R8,0.5);
7901     VARDIV(DATE,1,BSTR,num2_str,R8,0.5);
7902     VARDIV(DATE,1,BOOL,VARIANT_TRUE,R8,-1.0);
7903     VARDIV(DATE,1,UI1,2,R8,0.5);
7904     if (has_i8)
7905     {
7906         VARDIV(DATE,1,I8,2,R8,0.5);
7907     }
7908     VARDIV(BSTR,num1_str,NULL,0,NULL,0);
7909     VARDIV(BSTR,num1_str,I2,2,R8,0.5);
7910     VARDIV(BSTR,num1_str,I4,2,R8,0.5);
7911     VARDIV(BSTR,num1_str,R4,2.0f,R8,0.5);
7912     VARDIV(BSTR,num1_str,R8,2.0,R8,0.5);
7913     VARDIV(BSTR,num1_str,DATE,2,R8,0.5);
7914     VARDIV(BSTR,num1_str,BSTR,num2_str,R8,0.5);
7915     VARDIV(BSTR,num1_str,BOOL,VARIANT_TRUE,R8,-1);
7916     VARDIV(BSTR,num1_str,UI1,2,R8,0.5);
7917     if (has_i8)
7918     {
7919         VARDIV(BSTR,num1_str,I8,2,R8,0.5);
7920     }
7921     VARDIV(BOOL,VARIANT_TRUE,NULL,0,NULL,0);
7922     VARDIV(BOOL,VARIANT_TRUE,I2,1,R8,-1.0);
7923     VARDIV(BOOL,VARIANT_FALSE,I2,1,R8,0.0);
7924     VARDIV(BOOL,VARIANT_TRUE,I4,1,R8,-1.0);
7925     VARDIV(BOOL,VARIANT_FALSE,I4,1,R8,0.0);
7926     VARDIV(BOOL,VARIANT_TRUE,R4,1,R4,-1.0f);
7927     VARDIV(BOOL,VARIANT_FALSE,R4,1,R4,0.0f);
7928     VARDIV(BOOL,VARIANT_TRUE,R8,1.0,R8,-1.0);
7929     VARDIV(BOOL,VARIANT_FALSE,R8,1.0,R8,0.0);
7930     VARDIV(BOOL,VARIANT_FALSE,DATE,2,R8,0.0);
7931     VARDIV(BOOL,VARIANT_FALSE,BSTR,num2_str,R8,0.0);
7932     VARDIV(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,R8,1.0);
7933     VARDIV(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,R8,0.0);
7934     VARDIV(BOOL,VARIANT_TRUE,UI1,1,R8,-1.0);
7935     if (has_i8)
7936     {
7937         VARDIV(BOOL,VARIANT_TRUE,I8,1,R8,-1.0);
7938     }
7939     VARDIV(UI1,1,NULL,0,NULL,0);
7940     VARDIV(UI1,1,I2,2,R8,0.5);
7941     VARDIV(UI1,1,I4,2,R8,0.5);
7942     VARDIV(UI1,1,R4,2.0f,R4,0.5f);
7943     VARDIV(UI1,1,R8,2.0,R8,0.5);
7944     VARDIV(UI1,1,DATE,2,R8,0.5);
7945     VARDIV(UI1,1,BSTR,num2_str,R8,0.5);
7946     VARDIV(UI1,1,BOOL,VARIANT_TRUE,R8,-1);
7947     VARDIV(UI1,1,UI1,2,R8,0.5);
7948     if (has_i8)
7949     {
7950         VARDIV(UI1,1,I8,2,R8,0.5);
7951         VARDIV(I8,1,NULL,0,NULL,0);
7952         VARDIV(I8,1,I2,2,R8,0.5);
7953         VARDIV(I8,1,I4,2,R8,0.5);
7954         VARDIV(I8,1,R4,2.0f,R8,0.5);
7955         VARDIV(I8,1,R8,2.0,R8,0.5);
7956         VARDIV(I8,1,DATE,2,R8,0.5);
7957         VARDIV(I8,1,BSTR,num2_str,R8,0.5);
7958         VARDIV(I8,1,BOOL,VARIANT_TRUE,R8,-1);
7959         VARDIV(I8,1,UI1,2,R8,0.5);
7960         VARDIV(I8,1,I8,2,R8,0.5);
7961     }
7962 
7963     /* Manually test some VT_CY, VT_DECIMAL variants */
7964     V_VT(&cy) = VT_CY;
7965     hres = VarCyFromI4(10000, &V_CY(&cy));
7966     ok(hres == S_OK, "VarCyFromI4 failed!\n");
7967     V_VT(&dec) = VT_DECIMAL;
7968     hres = VarDecFromR8(2.0, &V_DECIMAL(&dec));
7969     ok(hres == S_OK, "VarDecFromR4 failed!\n");
7970     memset(&left, 0, sizeof(left));
7971     memset(&right, 0, sizeof(right));
7972     V_VT(&left) = VT_I4;
7973     V_I4(&left) = 100;
7974     V_VT(&right) = VT_UI1;
7975     V_UI1(&right) = 2;
7976 
7977     hres = pVarDiv(&cy, &cy, &result);
7978     ok(hres == S_OK && V_VT(&result) == VT_R8,
7979         "VARDIV: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
7980     ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 1.0),
7981         "VARDIV: CY value %f, expected %f\n", V_R8(&result), (double)1.0);
7982 
7983     hres = pVarDiv(&cy, &right, &result);
7984     ok(hres == S_OK && V_VT(&result) == VT_R8,
7985         "VARDIV: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
7986     ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 5000.0),
7987         "VARDIV: CY value %f, expected %f\n", V_R8(&result), (double)5000.0);
7988 
7989     hres = pVarDiv(&left, &cy, &result);
7990     ok(hres == S_OK && V_VT(&result) == VT_R8,
7991         "VARDIV: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
7992     ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 0.01),
7993         "VARDIV: CY value %f, expected %f\n", V_R8(&result), (double)0.01);
7994 
7995     hres = pVarDiv(&left, &dec, &result);
7996     ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
7997         "VARDIV: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
7998     hres = VarR8FromDec(&V_DECIMAL(&result), &r);
7999     ok(hres == S_OK && EQ_DOUBLE(r, 50.0),
8000         "VARDIV: DECIMAL value %f, expected %f\n", r, (double)50.0);
8001 
8002     hres = pVarDiv(&dec, &dec, &result);
8003     ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
8004         "VARDIV: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
8005     hres = VarR8FromDec(&V_DECIMAL(&result), &r);
8006     ok(hres == S_OK && EQ_DOUBLE(r, 1.0),
8007         "VARDIV: DECIMAL value %f, expected %f\n", r, (double)1.0);
8008 
8009     hres = pVarDiv(&dec, &right, &result);
8010     ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
8011         "VARDIV: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
8012     hres = VarR8FromDec(&V_DECIMAL(&result), &r);
8013     ok(hres == S_OK && EQ_DOUBLE(r, 1.0),
8014         "VARDIV: DECIMAL value %f, expected %f\n", r, (double)1.0);
8015 
8016     /* Check for division by zero and overflow */
8017     V_VT(&left) = VT_R8;
8018     V_I4(&left) = 1;
8019     V_VT(&right) = VT_R8;
8020     V_I4(&right) = 0;
8021     hres = pVarDiv(&left, &right, &result);
8022     ok(hres == DISP_E_DIVBYZERO && V_VT(&result) == VT_EMPTY,
8023         "VARDIV: Division by (1.0/0.0) should result in DISP_E_DIVBYZERO but got 0x%X\n", hres);
8024 
8025     V_VT(&left) = VT_R8;
8026     V_I4(&left) = 0;
8027     V_VT(&right) = VT_R8;
8028     V_I4(&right) = 0;
8029     hres = pVarDiv(&left, &right, &result);
8030     ok(hres == DISP_E_OVERFLOW && V_VT(&result) == VT_EMPTY,
8031         "VARDIV: Division by (0.0/0.0) should result in DISP_E_OVERFLOW but got 0x%X\n", hres);
8032 
8033     SysFreeString(num1_str);
8034     SysFreeString(num2_str);
8035 }
8036 
8037 static HRESULT (WINAPI *pVarIdiv)(LPVARIANT,LPVARIANT,LPVARIANT);
8038 
8039 #define VARIDIV(vt1,val1,vt2,val2,rvt,rval)              \
8040         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
8041         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
8042         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
8043         test_var_call2( __LINE__, pVarIdiv, &left, &right, &exp )
8044 
8045 /* Skip any type that is not defined or produces an error for every case */
8046 #define SKIPTESTIDIV(a)                           \
8047     if (a == VT_ERROR || a == VT_VARIANT ||       \
8048         a == VT_DISPATCH || a == VT_UNKNOWN ||    \
8049         a == VT_RECORD || a > VT_UINT ||          \
8050         a == 15 /*not defined*/)                  \
8051         continue
8052 
8053 static void test_VarIdiv(void)
8054 {
8055     static const WCHAR str1[] = { '1','\0' };
8056     static const WCHAR str2[] = { '2','\0' };
8057     VARIANT left, right, exp, result, cy, dec;
8058     BSTR num1_str, num2_str;
8059     VARTYPE i;
8060     HRESULT hres;
8061 
8062     CHECKPTR(VarIdiv);
8063 
8064     num1_str = SysAllocString(str1);
8065     num2_str = SysAllocString(str2);
8066 
8067     /* Test all possible flag/vt combinations & the resulting vt type */
8068     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
8069     {
8070         VARTYPE leftvt, rightvt, resvt;
8071 
8072         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
8073         {
8074             SKIPTESTIDIV(leftvt);
8075 
8076             /* Check if we need/have support for I8 and/or UI8 */
8077             if ((leftvt == VT_I8 || leftvt == VT_UI8) && !has_i8)
8078                 continue;
8079 
8080             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
8081             {
8082                 BOOL bFail = FALSE;
8083                 SKIPTESTIDIV(rightvt);
8084 
8085                 /* Native crashes with extra flag VT_BYREF */
8086                 if (ExtraFlags[i] == VT_BYREF)
8087                     continue;
8088 
8089                 /* Check if we need/have support for I8 and/or UI8 */
8090                 if ((rightvt == VT_I8 || rightvt == VT_UI8) && !has_i8)
8091                     continue;
8092 
8093                 memset(&left, 0, sizeof(left));
8094                 memset(&right, 0, sizeof(right));
8095                 V_VT(&left) = leftvt | ExtraFlags[i];
8096                 V_VT(&right) = rightvt | ExtraFlags[i];
8097                 V_VT(&result) = VT_EMPTY;
8098                 resvt = VT_EMPTY;
8099 
8100                 if (leftvt == VT_BSTR)
8101                     V_BSTR(&left) = num2_str;
8102                 else if (leftvt == VT_DECIMAL)
8103                 {
8104                     VarDecFromR8(2.0, &V_DECIMAL(&left));
8105                     V_VT(&left) = leftvt | ExtraFlags[i];
8106                 }
8107 
8108                 /* Division by 0 is undefined */
8109                 switch(rightvt)
8110                 {
8111                 case VT_BSTR:
8112                     V_BSTR(&right) = num2_str;
8113                     break;
8114                 case VT_DECIMAL:
8115                     VarDecFromR8(2.0, &V_DECIMAL(&right));
8116                     V_VT(&right) = rightvt | ExtraFlags[i];
8117                     break;
8118                 case VT_BOOL:
8119                     V_BOOL(&right) = VARIANT_TRUE;
8120                     break;
8121                 case VT_CY:
8122                     VarCyFromI4(10000, &V_CY(&right));
8123                     V_VT(&right) = rightvt | ExtraFlags[i];
8124                     break;
8125                 case VT_I2: V_I2(&right) = 2; break;
8126                 case VT_I4: V_I4(&right) = 2; break;
8127                 case VT_R4: V_R4(&right) = 2.0f; break;
8128                 case VT_R8: V_R8(&right) = 2.0; break;
8129                 case VT_DATE: V_DATE(&right) = 2; break;
8130                 case VT_I1: V_I1(&right) = 2; break;
8131                 case VT_UI1: V_UI1(&right) = 2; break;
8132                 case VT_UI2: V_UI2(&right) = 2; break;
8133                 case VT_UI4: V_UI4(&right) = 2; break;
8134                 case VT_I8: V_I8(&right) = 2; break;
8135                 case VT_UI8: V_UI8(&right) = 2; break;
8136                 case VT_INT: V_INT(&right) = 2; break;
8137                 case VT_UINT: V_UINT(&right) = 2; break;
8138                 default: break;
8139                 }
8140 
8141                 /* Native VarIdiv always returns an error when using extra
8142                  * flags or if the variant combination is I8 and INT.
8143                  */
8144                 if ((leftvt == VT_I8 && rightvt == VT_INT) ||
8145                     (leftvt == VT_INT && rightvt == VT_I8) ||
8146                     (rightvt == VT_EMPTY && leftvt != VT_NULL) ||
8147                     ExtraFlags[i] != 0)
8148                     bFail = TRUE;
8149 
8150                 /* Determine variant type */
8151                 else if (leftvt == VT_NULL || rightvt == VT_NULL)
8152                     resvt = VT_NULL;
8153                 else if (leftvt == VT_I8 || rightvt == VT_I8)
8154                     resvt = VT_I8;
8155                 else if (leftvt == VT_I4 || rightvt == VT_I4 ||
8156                     leftvt == VT_INT || rightvt == VT_INT ||
8157                     leftvt == VT_UINT || rightvt == VT_UINT ||
8158                     leftvt == VT_UI8 || rightvt == VT_UI8 ||
8159                     leftvt == VT_UI4 || rightvt == VT_UI4 ||
8160                     leftvt == VT_UI2 || rightvt == VT_UI2 ||
8161                     leftvt == VT_I1 || rightvt == VT_I1 ||
8162                     leftvt == VT_BSTR || rightvt == VT_BSTR ||
8163                     leftvt == VT_DATE || rightvt == VT_DATE ||
8164                     leftvt == VT_CY || rightvt == VT_CY ||
8165                     leftvt == VT_DECIMAL || rightvt == VT_DECIMAL ||
8166                     leftvt == VT_R8 || rightvt == VT_R8 ||
8167                     leftvt == VT_R4 || rightvt == VT_R4)
8168                     resvt = VT_I4;
8169                 else if (leftvt == VT_I2 || rightvt == VT_I2 ||
8170                     leftvt == VT_BOOL || rightvt == VT_BOOL ||
8171                     leftvt == VT_EMPTY)
8172                     resvt = VT_I2;
8173                 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
8174                     resvt = VT_UI1;
8175                 else
8176                     bFail = TRUE;
8177 
8178                 hres = pVarIdiv(&left, &right, &result);
8179 
8180                 /* Check expected HRESULT and if result variant type is correct */
8181                 if (bFail)
8182                     ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH ||
8183                         hres == DISP_E_DIVBYZERO,
8184                         "VarIdiv: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
8185                         vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
8186                         vtstr(V_VT(&result)), hres);
8187                 else
8188                     ok (hres == S_OK && resvt == V_VT(&result),
8189                         "VarIdiv: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
8190                         vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
8191                         S_OK, vtstr(V_VT(&result)), hres);
8192             }
8193         }
8194     }
8195 
8196     /* Test return values for all the good cases */
8197     VARIDIV(EMPTY,0,NULL,0,NULL,0);
8198     VARIDIV(EMPTY,0,I2,1,I2,0);
8199     VARIDIV(EMPTY,0,I4,1,I4,0);
8200     VARIDIV(EMPTY,0,R4,1.0f,I4,0);
8201     VARIDIV(EMPTY,0,R8,1.0,I4,0);
8202     VARIDIV(EMPTY,0,DATE,1.0,I4,0);
8203     VARIDIV(EMPTY,0,BSTR,num1_str,I4,0);
8204     VARIDIV(EMPTY,0,BOOL,VARIANT_TRUE,I2,0);
8205     VARIDIV(EMPTY,0,I1,1,I4,0);
8206     VARIDIV(EMPTY,0,UI1,1,I2,0);
8207     VARIDIV(EMPTY,0,UI2,1,I4,0);
8208     VARIDIV(EMPTY,0,UI4,1,I4,0);
8209     if (has_i8)
8210     {
8211         VARIDIV(EMPTY,0,I8,1,I8,0);
8212         VARIDIV(EMPTY,0,UI8,1,I4,0);
8213     }
8214     VARIDIV(EMPTY,0,INT,1,I4,0);
8215     VARIDIV(EMPTY,0,UINT,1,I4,0);
8216     VARIDIV(NULL,0,EMPTY,0,NULL,0);
8217     VARIDIV(NULL,0,NULL,0,NULL,0);
8218     VARIDIV(NULL,0,I2,1,NULL,0);
8219     VARIDIV(NULL,0,I4,1,NULL,0);
8220     VARIDIV(NULL,0,R4,1,NULL,0);
8221     VARIDIV(NULL,0,R8,1,NULL,0);
8222     VARIDIV(NULL,0,DATE,1,NULL,0);
8223     VARIDIV(NULL,0,BSTR,num1_str,NULL,0);
8224     VARIDIV(NULL,0,BOOL,VARIANT_TRUE,NULL,0);
8225     VARIDIV(NULL,0,I1,1,NULL,0);
8226     VARIDIV(NULL,0,UI1,1,NULL,0);
8227     VARIDIV(NULL,0,UI2,1,NULL,0);
8228     VARIDIV(NULL,0,UI4,1,NULL,0);
8229     if (has_i8)
8230     {
8231         VARIDIV(NULL,0,I8,1,NULL,0);
8232         VARIDIV(NULL,0,UI8,1,NULL,0);
8233     }
8234     VARIDIV(NULL,0,INT,1,NULL,0);
8235     VARIDIV(NULL,0,UINT,1,NULL,0);
8236     VARIDIV(I2,2,NULL,0,NULL,0);
8237     VARIDIV(I2,2,I2,1,I2,2);
8238     VARIDIV(I2,2,I4,1,I4,2);
8239     VARIDIV(I2,2,R4,1,I4,2);
8240     VARIDIV(I2,2,R8,1,I4,2);
8241     VARIDIV(I2,2,DATE,1,I4,2);
8242     VARIDIV(I2,2,BSTR,num1_str,I4,2);
8243     VARIDIV(I2,2,BOOL,VARIANT_TRUE,I2,-2);
8244     VARIDIV(I2,2,I1,1,I4,2);
8245     VARIDIV(I2,2,UI1,1,I2,2);
8246     VARIDIV(I2,2,UI2,1,I4,2);
8247     VARIDIV(I2,2,UI4,1,I4,2);
8248     if (has_i8)
8249     {
8250         VARIDIV(I2,2,I8,1,I8,2);
8251         VARIDIV(I2,2,UI8,1,I4,2);
8252     }
8253     VARIDIV(I2,2,INT,1,I4,2);
8254     VARIDIV(I2,2,UINT,1,I4,2);
8255     VARIDIV(I4,2,NULL,0,NULL,0);
8256     VARIDIV(I4,2,I2,1,I4,2);
8257     VARIDIV(I4,2,I4,1,I4,2);
8258     VARIDIV(I4,2,R4,1,I4,2);
8259     VARIDIV(I4,2,R8,1,I4,2);
8260     VARIDIV(I4,2,DATE,1,I4,2);
8261     VARIDIV(I4,2,BSTR,num1_str,I4,2);
8262     VARIDIV(I4,2,BOOL,VARIANT_TRUE,I4,-2);
8263     VARIDIV(I4,2,I1,1,I4,2);
8264     VARIDIV(I4,2,UI1,1,I4,2);
8265     VARIDIV(I4,2,UI2,1,I4,2);
8266     VARIDIV(I4,2,UI4,1,I4,2);
8267     if (has_i8)
8268     {
8269         VARIDIV(I4,2,I8,1,I8,2);
8270         VARIDIV(I4,2,UI8,1,I4,2);
8271     }
8272     VARIDIV(I4,2,INT,1,I4,2);
8273     VARIDIV(I4,2,UINT,1,I4,2);
8274     VARIDIV(R4,2.0f,NULL,0,NULL,0);
8275     VARIDIV(R4,2.0f,I2,1,I4,2);
8276     VARIDIV(R4,2.0f,I4,1,I4,2);
8277     VARIDIV(R4,2.0f,R4,1.0f,I4,2);
8278     VARIDIV(R4,2.0f,R8,1.0,I4,2);
8279     VARIDIV(R4,2.0f,DATE,1,I4,2);
8280     VARIDIV(R4,2.0f,BSTR,num1_str,I4,2);
8281     VARIDIV(R4,2.0f,BOOL,VARIANT_TRUE,I4,-2);
8282     VARIDIV(R4,2.0f,I1,1,I4,2);
8283     VARIDIV(R4,2.0f,UI1,1,I4,2);
8284     VARIDIV(R4,2.0f,UI2,1,I4,2);
8285     VARIDIV(R4,2.0f,UI4,1,I4,2);
8286     if (has_i8)
8287     {
8288         VARIDIV(R4,2.0f,I8,1,I8,2);
8289         VARIDIV(R4,2.0f,UI8,1,I4,2);
8290     }
8291     VARIDIV(R4,2.0f,INT,1,I4,2);
8292     VARIDIV(R4,2.0f,UINT,1,I4,2);
8293     VARIDIV(R8,2.0,NULL,0,NULL,0);
8294     VARIDIV(R8,2.0,I2,1,I4,2);
8295     VARIDIV(R8,2.0,I4,1,I4,2);
8296     VARIDIV(R8,2.0,R4,1,I4,2);
8297     VARIDIV(R8,2.0,R8,1,I4,2);
8298     VARIDIV(R8,2.0,DATE,1,I4,2);
8299     VARIDIV(R8,2.0,BSTR,num1_str,I4,2);
8300     VARIDIV(R8,2.0,BOOL,VARIANT_TRUE,I4,-2);
8301     VARIDIV(R8,2.0,I1,1,I4,2);
8302     VARIDIV(R8,2.0,UI1,1,I4,2);
8303     VARIDIV(R8,2.0,UI2,1,I4,2);
8304     VARIDIV(R8,2.0,UI4,1,I4,2);
8305     if (has_i8)
8306     {
8307         VARIDIV(R8,2.0,I8,1,I8,2);
8308         VARIDIV(R8,2.0,UI8,1,I4,2);
8309     }
8310     VARIDIV(R8,2.0,INT,1,I4,2);
8311     VARIDIV(R8,2.0,UINT,1,I4,2);
8312     VARIDIV(DATE,2,NULL,0,NULL,0);
8313     VARIDIV(DATE,2,I2,1,I4,2);
8314     VARIDIV(DATE,2,I4,1,I4,2);
8315     VARIDIV(DATE,2,R4,1,I4,2);
8316     VARIDIV(DATE,2,R8,1,I4,2);
8317     VARIDIV(DATE,2,DATE,1,I4,2);
8318     VARIDIV(DATE,2,BSTR,num1_str,I4,2);
8319     VARIDIV(DATE,2,BOOL,VARIANT_TRUE,I4,-2);
8320     VARIDIV(DATE,2,I1,1,I4,2);
8321     VARIDIV(DATE,2,UI1,1,I4,2);
8322     VARIDIV(DATE,2,UI2,1,I4,2);
8323     VARIDIV(DATE,2,UI4,1,I4,2);
8324     if (has_i8)
8325     {
8326         VARIDIV(DATE,2,I8,1,I8,2);
8327         VARIDIV(DATE,2,UI8,1,I4,2);
8328     }
8329     VARIDIV(DATE,2,INT,1,I4,2);
8330     VARIDIV(DATE,2,UINT,1,I4,2);
8331     VARIDIV(BSTR,num2_str,NULL,0,NULL,0);
8332     VARIDIV(BSTR,num2_str,I2,1,I4,2);
8333     VARIDIV(BSTR,num2_str,I4,1,I4,2);
8334     VARIDIV(BSTR,num2_str,R4,1.0f,I4,2);
8335     VARIDIV(BSTR,num2_str,R8,1.0,I4,2);
8336     VARIDIV(BSTR,num2_str,DATE,1,I4,2);
8337     VARIDIV(BSTR,num2_str,BSTR,num1_str,I4,2);
8338     VARIDIV(BSTR,num2_str,BOOL,VARIANT_TRUE,I4,-2);
8339     VARIDIV(BSTR,num2_str,I1,1,I4,2);
8340     VARIDIV(BSTR,num2_str,UI1,1,I4,2);
8341     VARIDIV(BSTR,num2_str,UI2,1,I4,2);
8342     VARIDIV(BSTR,num2_str,UI4,1,I4,2);
8343     if (has_i8)
8344     {
8345         VARIDIV(BSTR,num2_str,I8,1,I8,2);
8346         VARIDIV(BSTR,num2_str,UI8,1,I4,2);
8347     }
8348     VARIDIV(BSTR,num2_str,INT,1,I4,2);
8349     VARIDIV(BSTR,num2_str,UINT,1,I4,2);
8350     VARIDIV(BOOL,VARIANT_TRUE,NULL,0,NULL,0);
8351     VARIDIV(BOOL,VARIANT_TRUE,I2,1,I2,-1);
8352     VARIDIV(BOOL,VARIANT_TRUE,I4,1,I4,-1);
8353     VARIDIV(BOOL,VARIANT_TRUE,R4,1.0f,I4,-1);
8354     VARIDIV(BOOL,VARIANT_TRUE,R8,1.0,I4,-1);
8355     VARIDIV(BOOL,VARIANT_TRUE,DATE,1,I4,-1);
8356     VARIDIV(BOOL,VARIANT_TRUE,BSTR,num1_str,I4,-1);
8357     VARIDIV(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,I2,1);
8358     VARIDIV(BOOL,VARIANT_TRUE,I1,1,I4,-1);
8359     VARIDIV(BOOL,VARIANT_TRUE,UI1,1,I2,-1);
8360     VARIDIV(BOOL,VARIANT_TRUE,UI2,1,I4,-1);
8361     VARIDIV(BOOL,VARIANT_TRUE,UI4,1,I4,-1);
8362     if (has_i8)
8363     {
8364         VARIDIV(BOOL,VARIANT_TRUE,I8,1,I8,-1);
8365         VARIDIV(BOOL,VARIANT_TRUE,UI8,1,I4,-1);
8366     }
8367     VARIDIV(BOOL,VARIANT_TRUE,INT,1,I4,-1);
8368     VARIDIV(BOOL,VARIANT_TRUE,UINT,1,I4,-1);
8369     VARIDIV(I1,2,NULL,0,NULL,0);
8370     VARIDIV(I1,2,I2,1,I4,2);
8371     VARIDIV(I1,2,I4,1,I4,2);
8372     VARIDIV(I1,2,R4,1.0f,I4,2);
8373     VARIDIV(I1,2,R8,1.0,I4,2);
8374     VARIDIV(I1,2,DATE,1,I4,2);
8375     VARIDIV(I1,2,BSTR,num1_str,I4,2);
8376     VARIDIV(I1,2,BOOL,VARIANT_TRUE,I4,-2);
8377     VARIDIV(I1,2,I1,1,I4,2);
8378     VARIDIV(I1,2,UI1,1,I4,2);
8379     VARIDIV(I1,2,UI2,1,I4,2);
8380     VARIDIV(I1,2,UI4,1,I4,2);
8381     if (has_i8)
8382     {
8383         VARIDIV(I1,2,I8,1,I8,2);
8384         VARIDIV(I1,2,UI8,1,I4,2);
8385     }
8386     VARIDIV(I1,2,INT,1,I4,2);
8387     VARIDIV(I1,2,UINT,1,I4,2);
8388     VARIDIV(UI1,2,NULL,0,NULL,0);
8389     VARIDIV(UI1,2,I2,1,I2,2);
8390     VARIDIV(UI1,2,I4,1,I4,2);
8391     VARIDIV(UI1,2,R4,1.0f,I4,2);
8392     VARIDIV(UI1,2,R8,1.0,I4,2);
8393     VARIDIV(UI1,2,DATE,1,I4,2);
8394     VARIDIV(UI1,2,BSTR,num1_str,I4,2);
8395     VARIDIV(UI1,2,BOOL,VARIANT_TRUE,I2,-2);
8396     VARIDIV(UI1,2,I1,1,I4,2);
8397     VARIDIV(UI1,2,UI1,1,UI1,2);
8398     VARIDIV(UI1,2,UI2,1,I4,2);
8399     VARIDIV(UI1,2,UI4,1,I4,2);
8400     if (has_i8)
8401     {
8402         VARIDIV(UI1,2,I8,1,I8,2);
8403         VARIDIV(UI1,2,UI8,1,I4,2);
8404     }
8405     VARIDIV(UI1,2,INT,1,I4,2);
8406     VARIDIV(UI1,2,UINT,1,I4,2);
8407     VARIDIV(UI2,2,NULL,0,NULL,0);
8408     VARIDIV(UI2,2,I2,1,I4,2);
8409     VARIDIV(UI2,2,I4,1,I4,2);
8410     VARIDIV(UI2,2,R4,1.0f,I4,2);
8411     VARIDIV(UI2,2,R8,1.0,I4,2);
8412     VARIDIV(UI2,2,DATE,1,I4,2);
8413     VARIDIV(UI2,2,BSTR,num1_str,I4,2);
8414     VARIDIV(UI2,2,BOOL,VARIANT_TRUE,I4,-2);
8415     VARIDIV(UI2,2,I1,1,I4,2);
8416     VARIDIV(UI2,2,UI1,1,I4,2);
8417     VARIDIV(UI2,2,UI2,1,I4,2);
8418     VARIDIV(UI2,2,UI4,1,I4,2);
8419     if (has_i8)
8420     {
8421         VARIDIV(UI2,2,I8,1,I8,2);
8422         VARIDIV(UI2,2,UI8,1,I4,2);
8423     }
8424     VARIDIV(UI2,2,INT,1,I4,2);
8425     VARIDIV(UI2,2,UINT,1,I4,2);
8426     VARIDIV(UI4,2,NULL,0,NULL,0);
8427     VARIDIV(UI4,2,I2,1,I4,2);
8428     VARIDIV(UI4,2,I4,1,I4,2);
8429     VARIDIV(UI4,2,R4,1.0f,I4,2);
8430     VARIDIV(UI4,2,R8,1.0,I4,2);
8431     VARIDIV(UI4,2,DATE,1,I4,2);
8432     VARIDIV(UI4,2,BSTR,num1_str,I4,2);
8433     VARIDIV(UI4,2,BOOL,VARIANT_TRUE,I4,-2);
8434     VARIDIV(UI4,2,I1,1,I4,2);
8435     VARIDIV(UI4,2,UI1,1,I4,2);
8436     VARIDIV(UI4,2,UI2,1,I4,2);
8437     VARIDIV(UI4,2,UI4,1,I4,2);
8438     if (has_i8)
8439     {
8440         VARIDIV(UI4,2,I8,1,I8,2);
8441         VARIDIV(UI4,2,UI8,1,I4,2);
8442     }
8443     VARIDIV(UI4,2,INT,1,I4,2);
8444     VARIDIV(UI4,2,UINT,1,I4,2);
8445     if (has_i8)
8446     {
8447         VARIDIV(I8,2,NULL,0,NULL,0);
8448         VARIDIV(I8,2,I2,1,I8,2);
8449         VARIDIV(I8,2,I4,1,I8,2);
8450         VARIDIV(I8,2,R4,1.0f,I8,2);
8451         VARIDIV(I8,2,R8,1.0,I8,2);
8452         VARIDIV(I8,2,DATE,1,I8,2);
8453         VARIDIV(I8,2,BSTR,num1_str,I8,2);
8454         VARIDIV(I8,2,BOOL,1,I8,2);
8455         VARIDIV(I8,2,I1,1,I8,2);
8456         VARIDIV(I8,2,UI1,1,I8,2);
8457         VARIDIV(I8,2,UI2,1,I8,2);
8458         VARIDIV(I8,2,UI4,1,I8,2);
8459         VARIDIV(I8,2,I8,1,I8,2);
8460         VARIDIV(I8,2,UI8,1,I8,2);
8461         VARIDIV(I8,2,UINT,1,I8,2);
8462         VARIDIV(UI8,2,NULL,0,NULL,0);
8463         VARIDIV(UI8,2,I2,1,I4,2);
8464         VARIDIV(UI8,2,I4,1,I4,2);
8465         VARIDIV(UI8,2,R4,1.0f,I4,2);
8466         VARIDIV(UI8,2,R8,1.0,I4,2);
8467         VARIDIV(UI8,2,DATE,1,I4,2);
8468         VARIDIV(UI8,2,BSTR,num1_str,I4,2);
8469         VARIDIV(UI8,2,BOOL,VARIANT_TRUE,I4,-2);
8470         VARIDIV(UI8,2,I1,1,I4,2);
8471         VARIDIV(UI8,2,UI1,1,I4,2);
8472         VARIDIV(UI8,2,UI2,1,I4,2);
8473         VARIDIV(UI8,2,UI4,1,I4,2);
8474         VARIDIV(UI8,2,I8,1,I8,2);
8475         VARIDIV(UI8,2,UI8,1,I4,2);
8476         VARIDIV(UI8,2,INT,1,I4,2);
8477         VARIDIV(UI8,2,UINT,1,I4,2);
8478     }
8479     VARIDIV(INT,2,NULL,0,NULL,0);
8480     VARIDIV(INT,2,I2,1,I4,2);
8481     VARIDIV(INT,2,I4,1,I4,2);
8482     VARIDIV(INT,2,R4,1.0f,I4,2);
8483     VARIDIV(INT,2,R8,1.0,I4,2);
8484     VARIDIV(INT,2,DATE,1,I4,2);
8485     VARIDIV(INT,2,BSTR,num1_str,I4,2);
8486     VARIDIV(INT,2,BOOL,VARIANT_TRUE,I4,-2);
8487     VARIDIV(INT,2,I1,1,I4,2);
8488     VARIDIV(INT,2,UI1,1,I4,2);
8489     VARIDIV(INT,2,UI2,1,I4,2);
8490     VARIDIV(INT,2,UI4,1,I4,2);
8491     if (has_i8)
8492     {
8493         VARIDIV(INT,2,UI8,1,I4,2);
8494     }
8495     VARIDIV(INT,2,INT,1,I4,2);
8496     VARIDIV(INT,2,UINT,1,I4,2);
8497     VARIDIV(UINT,2,NULL,0,NULL,0);
8498     VARIDIV(UINT,2,I2,1,I4,2);
8499     VARIDIV(UINT,2,I4,1,I4,2);
8500     VARIDIV(UINT,2,R4,1.0f,I4,2);
8501     VARIDIV(UINT,2,R8,1.0,I4,2);
8502     VARIDIV(UINT,2,DATE,1,I4,2);
8503     VARIDIV(UINT,2,BSTR,num1_str,I4,2);
8504     VARIDIV(UINT,2,BOOL,VARIANT_TRUE,I4,-2);
8505     VARIDIV(UINT,2,I1,1,I4,2);
8506     VARIDIV(UINT,2,UI1,1,I4,2);
8507     VARIDIV(UINT,2,UI2,1,I4,2);
8508     VARIDIV(UINT,2,UI4,1,I4,2);
8509     if (has_i8)
8510     {
8511         VARIDIV(UINT,2,I8,1,I8,2);
8512         VARIDIV(UINT,2,UI8,1,I4,2);
8513     }
8514     VARIDIV(UINT,2,INT,1,I4,2);
8515     VARIDIV(UINT,2,UINT,1,I4,2);
8516 
8517     /* Manually test some VT_CY, VT_DECIMAL variants */
8518     V_VT(&cy) = VT_CY;
8519     hres = VarCyFromI4(10000, &V_CY(&cy));
8520     ok(hres == S_OK, "VarCyFromI4 failed!\n");
8521     V_VT(&dec) = VT_DECIMAL;
8522     hres = VarDecFromR8(2.0, &V_DECIMAL(&dec));
8523     ok(hres == S_OK, "VarDecFromR4 failed!\n");
8524     memset(&left, 0, sizeof(left));
8525     memset(&right, 0, sizeof(right));
8526     V_VT(&left) = VT_I4;
8527     V_I4(&left) = 100;
8528     V_VT(&right) = VT_I8;
8529     V_UI1(&right) = 2;
8530 
8531     hres = pVarIdiv(&cy, &cy, &result);
8532     ok(hres == S_OK && V_VT(&result) == VT_I4,
8533         "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8534         S_OK, hres, vtstr(V_VT(&result)));
8535     ok(hres == S_OK && V_I4(&result) == 1,
8536         "VARIDIV: CY value %d, expected %d\n", V_I4(&result), 1);
8537 
8538     if (has_i8)
8539     {
8540         hres = pVarIdiv(&cy, &right, &result);
8541         ok(hres == S_OK && V_VT(&result) == VT_I8,
8542             "VARIDIV: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n",
8543             S_OK, hres, vtstr(V_VT(&result)));
8544         ok(hres == S_OK && V_I8(&result) == 5000,
8545             "VARIDIV: CY value 0x%x%08x, expected 0x%x\n",
8546 	    (DWORD)(V_I8(&result) >>32), (DWORD)V_I8(&result), 5000);
8547     }
8548 
8549     hres = pVarIdiv(&left, &cy, &result);
8550     ok(hres == S_OK && V_VT(&result) == VT_I4,
8551         "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8552         S_OK, hres, vtstr(V_VT(&result)));
8553     ok(hres == S_OK && V_I4(&result) == 0,
8554         "VARIDIV: CY value %d, expected %d\n", V_I4(&result), 0);
8555 
8556     hres = pVarIdiv(&left, &dec, &result);
8557     ok(hres == S_OK && V_VT(&result) == VT_I4,
8558         "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8559         S_OK, hres, vtstr(V_VT(&result)));
8560     ok(hres == S_OK && V_I4(&result) == 50,
8561         "VARIDIV: DECIMAL value %d, expected %d\n", V_I4(&result), 50);
8562 
8563     hres = pVarIdiv(&dec, &dec, &result);
8564     ok(hres == S_OK && V_VT(&result) == VT_I4,
8565         "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8566         S_OK, hres, vtstr(V_VT(&result)));
8567     ok(hres == S_OK && V_I4(&result) == 1,
8568         "VARIDIV: DECIMAL value %d, expected %d\n", V_I4(&result), 1);
8569 
8570     if (has_i8)
8571     {
8572         hres = pVarIdiv(&dec, &right, &result);
8573         ok(hres == S_OK && V_VT(&result) == VT_I8,
8574             "VARIDIV: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n",
8575             S_OK, hres, vtstr(V_VT(&result)));
8576         ok(hres == S_OK && V_I8(&result) == 1,
8577             "VARIDIV: DECIMAL value 0x%x%08x, expected %d\n",
8578 	    (DWORD)(V_I8(&result) >> 32), (DWORD)V_I8(&result), 1);
8579     }
8580 
8581     /* Check for division by zero */
8582     V_VT(&left) = VT_INT;
8583     V_I4(&left) = 1;
8584     V_VT(&right) = VT_INT;
8585     V_I4(&right) = 0;
8586     hres = pVarIdiv(&left, &right, &result);
8587     ok(hres == DISP_E_DIVBYZERO && V_VT(&result) == VT_EMPTY,
8588         "VARIDIV: Division by 0 should result in DISP_E_DIVBYZERO but got 0x%X\n", hres);
8589 
8590     V_VT(&left) = VT_INT;
8591     V_I4(&left) = 0;
8592     V_VT(&right) = VT_INT;
8593     V_I4(&right) = 0;
8594     hres = pVarIdiv(&left, &right, &result);
8595     ok(hres == DISP_E_DIVBYZERO && V_VT(&result) == VT_EMPTY,
8596         "VARIDIV: Division by 0 should result in DISP_E_DIVBYZERO but got 0x%X\n", hres);
8597 
8598     SysFreeString(num1_str);
8599     SysFreeString(num2_str);
8600 }
8601 
8602 
8603 static HRESULT (WINAPI *pVarImp)(LPVARIANT,LPVARIANT,LPVARIANT);
8604 
8605 #define VARIMP(vt1,val1,vt2,val2,rvt,rval)              \
8606         V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
8607         V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
8608         V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
8609         test_var_call2( __LINE__, pVarImp, &left, &right, &exp )
8610 
8611 /* Skip any type that is not defined or produces an error for every case */
8612 #define SKIPTESTIMP(a)                            \
8613     if (a == VT_ERROR || a == VT_VARIANT ||       \
8614         a == VT_DISPATCH || a == VT_UNKNOWN ||    \
8615         a == VT_RECORD || a > VT_UINT ||          \
8616         a == 15 /*not defined*/)                  \
8617         continue
8618 
8619 static void test_VarImp(void)
8620 {
8621     static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
8622     static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
8623     VARIANT left, right, exp, result, cy, dec;
8624     BSTR true_str, false_str;
8625     VARTYPE i;
8626     HRESULT hres;
8627 
8628     CHECKPTR(VarImp);
8629 
8630     true_str = SysAllocString(szTrue);
8631     false_str = SysAllocString(szFalse);
8632 
8633     /* Test all possible flag/vt combinations & the resulting vt type */
8634     for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
8635     {
8636         VARTYPE leftvt, rightvt, resvt;
8637 
8638         for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
8639         {
8640             SKIPTESTIMP(leftvt);
8641 
8642             /* Check if we need/have support for I8 and/or UI8 */
8643             if ((leftvt == VT_I8 || leftvt == VT_UI8) && !has_i8)
8644                 continue;
8645 
8646             for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
8647             {
8648                 BOOL bFail = FALSE;
8649                 SKIPTESTIMP(rightvt);
8650 
8651                 /* Native crashes when using the extra flag VT_BYREF
8652                  * or with the following VT combinations
8653                  */
8654                 if ((leftvt == VT_UI4 && rightvt == VT_BSTR) ||
8655                     (leftvt == VT_UI8 && rightvt == VT_BSTR) ||
8656                     ExtraFlags[i] == VT_BYREF)
8657                     continue;
8658 
8659                 /* Check if we need/have support for I8 and/or UI8 */
8660                 if ((rightvt == VT_I8 || rightvt == VT_UI8) && !has_i8)
8661                     continue;
8662 
8663                 memset(&left, 0, sizeof(left));
8664                 memset(&right, 0, sizeof(right));
8665                 V_VT(&left) = leftvt | ExtraFlags[i];
8666                 V_VT(&right) = rightvt | ExtraFlags[i];
8667                 V_VT(&result) = VT_EMPTY;
8668                 resvt = VT_EMPTY;
8669 
8670                 if (leftvt == VT_BSTR)
8671                     V_BSTR(&left) = true_str;
8672 
8673                 /* This allows us to test return types that are not NULL
8674                  * (NULL Imp value = n, NULL Imp 0 = NULL)
8675                  */
8676                 switch(rightvt)
8677                 {
8678                 case VT_BSTR:
8679                     V_BSTR(&right) = true_str;
8680                     break;
8681                 case VT_DECIMAL:
8682                     VarDecFromR8(2.0, &V_DECIMAL(&right));
8683                     V_VT(&right) = rightvt | ExtraFlags[i];
8684                     break;
8685                 case VT_BOOL:
8686                     V_BOOL(&right) = VARIANT_TRUE;
8687                     break;
8688                 case VT_I1: V_I1(&right) = 2; break;
8689                 case VT_I2: V_I2(&right) = 2; break;
8690                 case VT_I4: V_I4(&right) = 2; break;
8691                 case VT_R4: V_R4(&right) = 2.0f; break;
8692                 case VT_R8: V_R8(&right) = 2.0; break;
8693                 case VT_CY: V_CY(&right).int64 = 10000; break;
8694                 case VT_DATE: V_DATE(&right) = 2; break;
8695                 case VT_I8: V_I8(&right) = 2; break;
8696                 case VT_INT: V_INT(&right) = 2; break;
8697                 case VT_UINT: V_UINT(&right) = 2; break;
8698                 case VT_UI1: V_UI1(&right) = 2; break;
8699                 case VT_UI2: V_UI2(&right) = 2; break;
8700                 case VT_UI4: V_UI4(&right) = 2; break;
8701                 case VT_UI8: V_UI8(&right) = 2; break;
8702                 default: break;
8703                 }
8704 
8705                 /* Native VarImp always returns an error when using extra
8706                  * flags or if the variants are I8 and INT.
8707                  */
8708                 if ((leftvt == VT_I8 && rightvt == VT_INT) ||
8709                     ExtraFlags[i] != 0)
8710                     bFail = TRUE;
8711 
8712                 /* Determine result type */
8713                 else if ((leftvt == VT_BSTR && rightvt == VT_NULL) ||
8714                     (leftvt == VT_NULL && rightvt == VT_NULL) ||
8715                     (leftvt == VT_NULL && rightvt == VT_EMPTY))
8716                     resvt = VT_NULL;
8717                 else if (leftvt == VT_I8 || rightvt == VT_I8)
8718                     resvt = VT_I8;
8719                 else if (leftvt == VT_I4 || rightvt == VT_I4 ||
8720                     leftvt == VT_INT || rightvt == VT_INT ||
8721                     leftvt == VT_UINT || rightvt == VT_UINT ||
8722                     leftvt == VT_UI4 || rightvt == VT_UI4 ||
8723                     leftvt == VT_UI8 || rightvt == VT_UI8 ||
8724                     leftvt == VT_UI2 || rightvt == VT_UI2 ||
8725                     leftvt == VT_DECIMAL || rightvt == VT_DECIMAL ||
8726                     leftvt == VT_DATE || rightvt == VT_DATE ||
8727                     leftvt == VT_CY || rightvt == VT_CY ||
8728                     leftvt == VT_R8 || rightvt == VT_R8 ||
8729                     leftvt == VT_R4 || rightvt == VT_R4 ||
8730                     leftvt == VT_I1 || rightvt == VT_I1)
8731                     resvt = VT_I4;
8732                 else if ((leftvt == VT_UI1 && rightvt == VT_UI1) ||
8733                     (leftvt == VT_UI1 && rightvt == VT_NULL) ||
8734                     (leftvt == VT_NULL && rightvt == VT_UI1))
8735                     resvt = VT_UI1;
8736                 else if (leftvt == VT_EMPTY || rightvt == VT_EMPTY ||
8737                     leftvt == VT_I2 || rightvt == VT_I2 ||
8738                     leftvt == VT_UI1 || rightvt == VT_UI1)
8739                     resvt = VT_I2;
8740                 else if (leftvt == VT_BOOL || rightvt == VT_BOOL ||
8741                     leftvt == VT_BSTR || rightvt == VT_BSTR)
8742                     resvt = VT_BOOL;
8743 
8744                 hres = pVarImp(&left, &right, &result);
8745 
8746                 /* Check expected HRESULT and if result variant type is correct */
8747                 if (bFail)
8748                     ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH,
8749                         "VarImp: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
8750                         vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
8751                         vtstr(V_VT(&result)), hres);
8752                 else
8753                     ok (hres == S_OK && resvt == V_VT(&result),
8754                         "VarImp: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
8755                         vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
8756                         S_OK, vtstr(V_VT(&result)), hres);
8757             }
8758         }
8759     }
8760 
8761     VARIMP(EMPTY,0,EMPTY,0,I2,-1);
8762     VARIMP(EMPTY,0,NULL,0,I2,-1);
8763     VARIMP(EMPTY,0,I2,-1,I2,-1);
8764     VARIMP(EMPTY,0,I4,-1,I4,-1);
8765     VARIMP(EMPTY,0,R4,0.0f,I4,-1);
8766     VARIMP(EMPTY,0,R8,-1.0,I4,-1);
8767     VARIMP(EMPTY,0,DATE,0,I4,-1);
8768     VARIMP(EMPTY,0,BSTR,true_str,I2,-1);
8769     VARIMP(EMPTY,0,BOOL,VARIANT_FALSE,I2,-1);
8770     VARIMP(EMPTY,0,I1,0,I4,-1);
8771     VARIMP(EMPTY,0,UI1,1,I2,-1);
8772     VARIMP(EMPTY,0,UI2,1,I4,-1);
8773     VARIMP(EMPTY,0,UI4,1,I4,-1);
8774     if (has_i8)
8775     {
8776         VARIMP(EMPTY,0,I8,1,I8,-1);
8777         VARIMP(EMPTY,0,UI8,1,I4,-1);
8778     }
8779     VARIMP(EMPTY,0,INT,-1,I4,-1);
8780     VARIMP(EMPTY,0,UINT,1,I4,-1);
8781     VARIMP(NULL,0,EMPTY,0,NULL,0);
8782     VARIMP(NULL,0,NULL,0,NULL,0);
8783     VARIMP(NULL,0,I2,-1,I2,-1);
8784     VARIMP(NULL,0,I4,-1,I4,-1);
8785     VARIMP(NULL,0,R4,0.0f,NULL,0);
8786     VARIMP(NULL,0,R8,-1.0,I4,-1);
8787     VARIMP(NULL,0,DATE,0,NULL,0);
8788     VARIMP(NULL,0,BSTR,true_str,BOOL,-1);
8789     VARIMP(NULL,0,BOOL,VARIANT_FALSE,NULL,0);
8790     VARIMP(NULL,0,I1,0,NULL,0);
8791     VARIMP(NULL,0,UI1,1,UI1,1);
8792     VARIMP(NULL,0,UI2,1,I4,1);
8793     VARIMP(NULL,0,UI4,1,I4,1);
8794     if (has_i8)
8795     {
8796         VARIMP(NULL,0,I8,1,I8,1);
8797         VARIMP(NULL,0,UI8,1,I4,1);
8798     }
8799     VARIMP(NULL,0,INT,-1,I4,-1);
8800     VARIMP(NULL,0,UINT,1,I4,1);
8801     VARIMP(I2,-1,EMPTY,0,I2,0);
8802     VARIMP(I2,-1,I2,-1,I2,-1);
8803     VARIMP(I2,-1,I4,-1,I4,-1);
8804     VARIMP(I2,-1,R4,0.0f,I4,0);
8805     VARIMP(I2,-1,R8,-1.0,I4,-1);
8806     VARIMP(I2,-1,DATE,0,I4,0);
8807     VARIMP(I2,-1,BSTR,true_str,I2,-1);
8808     VARIMP(I2,-1,BOOL,VARIANT_FALSE,I2,0);
8809     VARIMP(I2,-1,I1,0,I4,0);
8810     VARIMP(I2,-1,UI1,1,I2,1);
8811     VARIMP(I2,-1,UI2,1,I4,1);
8812     VARIMP(I2,-1,UI4,1,I4,1);
8813     if (has_i8)
8814     {
8815         VARIMP(I2,-1,I8,1,I8,1);
8816         VARIMP(I2,-1,UI8,1,I4,1);
8817     }
8818     VARIMP(I2,-1,INT,-1,I4,-1);
8819     VARIMP(I2,-1,UINT,1,I4,1);
8820     VARIMP(I4,2,EMPTY,0,I4,-3);
8821     VARIMP(I4,2,NULL,0,I4,-3);
8822     VARIMP(I4,2,I2,-1,I4,-1);
8823     VARIMP(I4,2,I4,-1,I4,-1);
8824     VARIMP(I4,2,R4,0.0f,I4,-3);
8825     VARIMP(I4,2,R8,-1.0,I4,-1);
8826     VARIMP(I4,2,DATE,0,I4,-3);
8827     VARIMP(I4,2,BSTR,true_str,I4,-1);
8828     VARIMP(I4,2,BOOL,VARIANT_FALSE,I4,-3);
8829     VARIMP(I4,2,I1,0,I4,-3);
8830     VARIMP(I4,2,UI1,1,I4,-3);
8831     VARIMP(I4,2,UI2,1,I4,-3);
8832     VARIMP(I4,2,UI4,1,I4,-3);
8833     if (has_i8)
8834     {
8835         VARIMP(I4,2,I8,1,I8,-3);
8836         VARIMP(I4,2,UI8,1,I4,-3);
8837     }
8838     VARIMP(I4,2,INT,-1,I4,-1);
8839     VARIMP(I4,2,UINT,1,I4,-3);
8840     VARIMP(R4,-1.0f,EMPTY,0,I4,0);
8841     VARIMP(R4,-1.0f,NULL,0,NULL,0);
8842     VARIMP(R4,-1.0f,I2,-1,I4,-1);
8843     VARIMP(R4,-1.0f,I4,-1,I4,-1);
8844     VARIMP(R4,-1.0f,R4,0.0f,I4,0);
8845     VARIMP(R4,-1.0f,R8,-1.0,I4,-1);
8846     VARIMP(R4,-1.0f,DATE,1,I4,1);
8847     VARIMP(R4,-1.0f,BSTR,true_str,I4,-1);
8848     VARIMP(R4,-1.0f,BOOL,VARIANT_FALSE,I4,0);
8849     VARIMP(R4,-1.0f,I1,0,I4,0);
8850     VARIMP(R4,-1.0f,UI1,1,I4,1);
8851     VARIMP(R4,-1.0f,UI2,1,I4,1);
8852     VARIMP(R4,-1.0f,UI4,1,I4,1);
8853     if (has_i8)
8854     {
8855         VARIMP(R4,-1.0f,I8,1,I8,1);
8856         VARIMP(R4,-1.0f,UI8,1,I4,1);
8857     }
8858     VARIMP(R4,-1.0f,INT,-1,I4,-1);
8859     VARIMP(R4,-1.0f,UINT,1,I4,1);
8860     VARIMP(R8,1.0,EMPTY,0,I4,-2);
8861     VARIMP(R8,1.0,NULL,0,I4,-2);
8862     VARIMP(R8,1.0,I2,-1,I4,-1);
8863     VARIMP(R8,1.0,I4,-1,I4,-1);
8864     VARIMP(R8,1.0,R4,0.0f,I4,-2);
8865     VARIMP(R8,1.0,R8,-1.0,I4,-1);
8866     VARIMP(R8,1.0,DATE,0,I4,-2);
8867     VARIMP(R8,1.0,BSTR,true_str,I4,-1);
8868     VARIMP(R8,1.0,BOOL,VARIANT_FALSE,I4,-2);
8869     VARIMP(R8,1.0,I1,0,I4,-2);
8870     VARIMP(R8,1.0,UI1,1,I4,-1);
8871     VARIMP(R8,1.0,UI2,1,I4,-1);
8872     VARIMP(R8,1.0,UI4,1,I4,-1);
8873     if (has_i8)
8874     {
8875         VARIMP(R8,1.0,I8,1,I8,-1);
8876         VARIMP(R8,1.0,UI8,1,I4,-1);
8877     }
8878     VARIMP(R8,1.0,INT,-1,I4,-1);
8879     VARIMP(R8,1.0,UINT,1,I4,-1);
8880     VARIMP(DATE,0,EMPTY,0,I4,-1);
8881     VARIMP(DATE,0,NULL,0,I4,-1);
8882     VARIMP(DATE,0,I2,-1,I4,-1);
8883     VARIMP(DATE,0,I4,-1,I4,-1);
8884     VARIMP(DATE,0,R4,0.0f,I4,-1);
8885     VARIMP(DATE,0,R8,-1.0,I4,-1);
8886     VARIMP(DATE,0,DATE,0,I4,-1);
8887     VARIMP(DATE,0,BSTR,true_str,I4,-1);
8888     VARIMP(DATE,0,BOOL,VARIANT_FALSE,I4,-1);
8889     VARIMP(DATE,0,I1,0,I4,-1);
8890     VARIMP(DATE,0,UI1,1,I4,-1);
8891     VARIMP(DATE,0,UI2,1,I4,-1);
8892     VARIMP(DATE,0,UI4,1,I4,-1);
8893     if (has_i8)
8894     {
8895         VARIMP(DATE,0,I8,1,I8,-1);
8896         VARIMP(DATE,0,UI8,1,I4,-1);
8897     }
8898     VARIMP(DATE,0,INT,-1,I4,-1);
8899     VARIMP(DATE,0,UINT,1,I4,-1);
8900     VARIMP(BSTR,false_str,EMPTY,0,I2,-1);
8901     VARIMP(BSTR,false_str,NULL,0,BOOL,-1);
8902     VARIMP(BSTR,false_str,I2,-1,I2,-1);
8903     VARIMP(BSTR,false_str,I4,-1,I4,-1);
8904     VARIMP(BSTR,false_str,R4,0.0f,I4,-1);
8905     VARIMP(BSTR,false_str,R8,-1.0,I4,-1);
8906     VARIMP(BSTR,false_str,DATE,0,I4,-1);
8907     VARIMP(BSTR,false_str,BSTR,true_str,BOOL,-1);
8908     VARIMP(BSTR,false_str,BOOL,VARIANT_FALSE,BOOL,-1);
8909     VARIMP(BSTR,false_str,I1,0,I4,-1);
8910     VARIMP(BSTR,false_str,UI1,1,I2,-1);
8911     VARIMP(BSTR,false_str,UI2,1,I4,-1);
8912     VARIMP(BSTR,false_str,UI4,1,I4,-1);
8913     if (has_i8)
8914     {
8915         VARIMP(BSTR,false_str,I8,1,I8,-1);
8916         VARIMP(BSTR,false_str,UI8,1,I4,-1);
8917     }
8918     VARIMP(BSTR,false_str,INT,-1,I4,-1);
8919     VARIMP(BSTR,false_str,UINT,1,I4,-1);
8920     VARIMP(BOOL,VARIANT_TRUE,EMPTY,0,I2,0);
8921     VARIMP(BOOL,VARIANT_TRUE,NULL,0,NULL,0);
8922     VARIMP(BOOL,VARIANT_TRUE,I2,-1,I2,-1);
8923     VARIMP(BOOL,VARIANT_TRUE,I4,-1,I4,-1);
8924     VARIMP(BOOL,VARIANT_TRUE,R4,0.0f,I4,0);
8925     VARIMP(BOOL,VARIANT_TRUE,R8,-1.0,I4,-1);
8926     VARIMP(BOOL,VARIANT_TRUE,DATE,0,I4,0);
8927     VARIMP(BOOL,VARIANT_TRUE,BSTR,true_str,BOOL,-1);
8928     VARIMP(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,0);
8929     VARIMP(BOOL,VARIANT_TRUE,I1,0,I4,0);
8930     VARIMP(BOOL,VARIANT_TRUE,UI1,1,I2,1);
8931     VARIMP(BOOL,VARIANT_TRUE,UI2,1,I4,1);
8932     VARIMP(BOOL,VARIANT_TRUE,UI4,1,I4,1);
8933     if (has_i8)
8934     {
8935         VARIMP(BOOL,VARIANT_TRUE,I8,1,I8,1);
8936         VARIMP(BOOL,VARIANT_TRUE,UI8,1,I4,1);
8937     }
8938     VARIMP(BOOL,VARIANT_TRUE,INT,-1,I4,-1);
8939     VARIMP(BOOL,VARIANT_TRUE,UINT,1,I4,1);
8940     VARIMP(I1,-1,EMPTY,0,I4,0);
8941     VARIMP(I1,-1,NULL,0,NULL,0);
8942     VARIMP(I1,-1,I2,-1,I4,-1);
8943     VARIMP(I1,-1,I4,-1,I4,-1);
8944     VARIMP(I1,-1,R4,0.0f,I4,0);
8945     VARIMP(I1,-1,R8,-1.0,I4,-1);
8946     VARIMP(I1,-1,DATE,0,I4,0);
8947     VARIMP(I1,-1,BSTR,true_str,I4,-1);
8948     VARIMP(I1,-1,BOOL,VARIANT_FALSE,I4,0);
8949     VARIMP(I1,-1,I1,0,I4,0);
8950     VARIMP(I1,-1,UI1,1,I4,1);
8951     VARIMP(I1,-1,UI2,1,I4,1);
8952     VARIMP(I1,-1,UI4,1,I4,1);
8953     if (has_i8)
8954     {
8955         VARIMP(I1,-1,I8,1,I8,1);
8956         VARIMP(I1,-1,UI8,1,I4,1);
8957     }
8958     VARIMP(I1,-1,INT,-1,I4,-1);
8959     VARIMP(I1,-1,UINT,1,I4,1);
8960     VARIMP(UI1,0,EMPTY,0,I2,-1);
8961     VARIMP(UI1,0,NULL,0,UI1,255);
8962     VARIMP(UI1,0,I2,-1,I2,-1);
8963     VARIMP(UI1,0,I4,-1,I4,-1);
8964     VARIMP(UI1,0,R4,0.0f,I4,-1);
8965     VARIMP(UI1,0,R8,-1.0,I4,-1);
8966     VARIMP(UI1,0,DATE,0,I4,-1);
8967     VARIMP(UI1,0,BSTR,true_str,I2,-1);
8968     VARIMP(UI1,0,BOOL,VARIANT_FALSE,I2,-1);
8969     VARIMP(UI1,0,I1,0,I4,-1);
8970     VARIMP(UI1,0,UI1,1,UI1,255);
8971     VARIMP(UI1,0,UI2,1,I4,-1);
8972     VARIMP(UI1,0,UI4,1,I4,-1);
8973     if (has_i8)
8974     {
8975         VARIMP(UI1,0,I8,1,I8,-1);
8976         VARIMP(UI1,0,UI8,1,I4,-1);
8977     }
8978     VARIMP(UI1,0,INT,-1,I4,-1);
8979     VARIMP(UI1,0,UINT,1,I4,-1);
8980     VARIMP(UI2,0,EMPTY,0,I4,-1);
8981     VARIMP(UI2,0,NULL,0,I4,-1);
8982     VARIMP(UI2,0,I2,-1,I4,-1);
8983     VARIMP(UI2,0,I4,-1,I4,-1);
8984     VARIMP(UI2,0,R4,0.0f,I4,-1);
8985     VARIMP(UI2,0,R8,-1.0,I4,-1);
8986     VARIMP(UI2,0,DATE,0,I4,-1);
8987     VARIMP(UI2,0,BSTR,true_str,I4,-1);
8988     VARIMP(UI2,0,BOOL,VARIANT_FALSE,I4,-1);
8989     VARIMP(UI2,0,I1,0,I4,-1);
8990     VARIMP(UI2,0,UI1,1,I4,-1);
8991     VARIMP(UI2,0,UI2,1,I4,-1);
8992     VARIMP(UI2,0,UI4,1,I4,-1);
8993     if (has_i8)
8994     {
8995         VARIMP(UI2,0,I8,1,I8,-1);
8996         VARIMP(UI2,0,UI8,1,I4,-1);
8997     }
8998     VARIMP(UI2,0,INT,-1,I4,-1);
8999     VARIMP(UI2,0,UINT,1,I4,-1);
9000     VARIMP(UI4,0,EMPTY,0,I4,-1);
9001     VARIMP(UI4,0,NULL,0,I4,-1);
9002     VARIMP(UI4,0,I2,-1,I4,-1);
9003     VARIMP(UI4,0,I4,-1,I4,-1);
9004     VARIMP(UI4,0,R4,0.0f,I4,-1);
9005     VARIMP(UI4,0,R8,-1.0,I4,-1);
9006     VARIMP(UI4,0,DATE,0,I4,-1);
9007     VARIMP(UI4,0,BSTR,true_str,I4,-1);
9008     VARIMP(UI4,0,BOOL,VARIANT_FALSE,I4,-1);
9009     VARIMP(UI4,0,I1,0,I4,-1);
9010     VARIMP(UI4,0,UI1,1,I4,-1);
9011     VARIMP(UI4,0,UI2,1,I4,-1);
9012     VARIMP(UI4,0,UI4,1,I4,-1);
9013     if (has_i8)
9014     {
9015         VARIMP(UI4,0,I8,1,I8,-1);
9016         VARIMP(UI4,0,UI8,1,I4,-1);
9017     }
9018     VARIMP(UI4,0,INT,-1,I4,-1);
9019     VARIMP(UI4,0,UINT,1,I4,-1);
9020     if (has_i8)
9021     {
9022         VARIMP(I8,-1,EMPTY,0,I8,0);
9023         VARIMP(I8,-1,NULL,0,NULL,0);
9024         VARIMP(I8,-1,I2,-1,I8,-1);
9025         VARIMP(I8,-1,I4,-1,I8,-1);
9026         VARIMP(I8,-1,R4,0.0f,I8,0);
9027         VARIMP(I8,-1,R8,-1.0,I8,-1);
9028         VARIMP(I8,-1,DATE,0,I8,0);
9029         VARIMP(I8,-1,BSTR,true_str,I8,-1);
9030         VARIMP(I8,-1,BOOL,VARIANT_FALSE,I8,0);
9031         VARIMP(I8,-1,I1,0,I8,0);
9032         VARIMP(I8,-1,UI1,1,I8,1);
9033         VARIMP(I8,-1,UI2,1,I8,1);
9034         VARIMP(I8,-1,UI4,1,I8,1);
9035         VARIMP(I8,-1,I8,1,I8,1);
9036         VARIMP(I8,-1,UI8,1,I8,1);
9037         VARIMP(I8,-1,UINT,1,I8,1);
9038         VARIMP(UI8,0,EMPTY,0,I4,-1);
9039         VARIMP(UI8,0,NULL,0,I4,-1);
9040         VARIMP(UI8,0,I2,-1,I4,-1);
9041         VARIMP(UI8,0,I4,-1,I4,-1);
9042         VARIMP(UI8,0,R4,0.0f,I4,-1);
9043         VARIMP(UI8,0,R8,-1.0,I4,-1);
9044         VARIMP(UI8,0,DATE,0,I4,-1);
9045         VARIMP(UI8,0,BSTR,true_str,I4,-1);
9046         VARIMP(UI8,0,BOOL,VARIANT_FALSE,I4,-1);
9047         VARIMP(UI8,0,I1,0,I4,-1);
9048         VARIMP(UI8,0,UI1,1,I4,-1);
9049         VARIMP(UI8,0,UI2,1,I4,-1);
9050         VARIMP(UI8,0,UI4,1,I4,-1);
9051         VARIMP(UI8,0,I8,1,I8,-1);
9052         VARIMP(UI8,0,UI8,1,I4,-1);
9053         VARIMP(UI8,0,INT,-1,I4,-1);
9054         VARIMP(UI8,0,UINT,1,I4,-1);
9055     }
9056     VARIMP(INT,-1,EMPTY,0,I4,0);
9057     VARIMP(INT,-1,NULL,0,NULL,0);
9058     VARIMP(INT,-1,I2,-1,I4,-1);
9059     VARIMP(INT,-1,I4,-1,I4,-1);
9060     VARIMP(INT,-1,R4,0.0f,I4,0);
9061     VARIMP(INT,-1,R8,-1.0,I4,-1);
9062     VARIMP(INT,-1,DATE,0,I4,0);
9063     VARIMP(INT,-1,BSTR,true_str,I4,-1);
9064     VARIMP(INT,-1,BOOL,VARIANT_FALSE,I4,0);
9065     VARIMP(INT,-1,I1,0,I4,0);
9066     VARIMP(INT,-1,UI1,1,I4,1);
9067     VARIMP(INT,-1,UI2,1,I4,1);
9068     VARIMP(INT,-1,UI4,1,I4,1);
9069     if (has_i8)
9070     {
9071         VARIMP(INT,-1,I8,1,I8,1);
9072         VARIMP(INT,-1,UI8,1,I4,1);
9073     }
9074     VARIMP(INT,-1,INT,-1,I4,-1);
9075     VARIMP(INT,-1,UINT,1,I4,1);
9076     VARIMP(UINT,1,EMPTY,0,I4,-2);
9077     VARIMP(UINT,1,NULL,0,I4,-2);
9078     VARIMP(UINT,1,I2,-1,I4,-1);
9079     VARIMP(UINT,1,I4,-1,I4,-1);
9080     VARIMP(UINT,1,R4,0.0f,I4,-2);
9081     VARIMP(UINT,1,R8,-1.0,I4,-1);
9082     VARIMP(UINT,1,DATE,0,I4,-2);
9083     VARIMP(UINT,1,BSTR,true_str,I4,-1);
9084     VARIMP(UINT,1,BOOL,VARIANT_FALSE,I4,-2);
9085     VARIMP(UINT,1,I1,0,I4,-2);
9086     VARIMP(UINT,1,UI1,1,I4,-1);
9087     VARIMP(UINT,1,UI2,1,I4,-1);
9088     VARIMP(UINT,1,UI4,1,I4,-1);
9089     if (has_i8)
9090     {
9091         VARIMP(UINT,1,I8,1,I8,-1);
9092         VARIMP(UINT,1,UI8,1,I4,-1);
9093     }
9094     VARIMP(UINT,1,INT,-1,I4,-1);
9095     VARIMP(UINT,1,UINT,1,I4,-1);
9096 
9097     /* Manually test some VT_CY, VT_DECIMAL variants */
9098     V_VT(&cy) = VT_CY;
9099     hres = VarCyFromI4(1, &V_CY(&cy));
9100     ok(hres == S_OK, "VarCyFromI4 failed!\n");
9101     V_VT(&dec) = VT_DECIMAL;
9102     hres = VarDecFromR8(2.0, &V_DECIMAL(&dec));
9103     ok(hres == S_OK, "VarDecFromR4 failed!\n");
9104     memset(&left, 0, sizeof(left));
9105     memset(&right, 0, sizeof(right));
9106     V_VT(&left) = VT_I4;
9107     V_I4(&left) = 0;
9108     V_VT(&right) = VT_I8;
9109     V_UI1(&right) = 0;
9110 
9111     hres = pVarImp(&cy, &cy, &result);
9112     ok(hres == S_OK && V_VT(&result) == VT_I4,
9113         "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
9114         S_OK, hres, vtstr(V_VT(&result)));
9115     ok(hres == S_OK && V_I4(&result) == -1,
9116         "VARIMP: CY value %d, expected %d\n", V_I4(&result), -1);
9117 
9118     if (has_i8)
9119     {
9120         hres = pVarImp(&cy, &right, &result);
9121         ok(hres == S_OK && V_VT(&result) == VT_I8,
9122             "VARIMP: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n",
9123             S_OK, hres, vtstr(V_VT(&result)));
9124         ok(hres == S_OK && V_I8(&result) == -2,
9125             "VARIMP: CY value %x%08x, expected %d\n",
9126             (DWORD)((V_I8(&result)) >> 32), (DWORD)(V_I8(&result)), -2);
9127     }
9128 
9129     hres = pVarImp(&left, &cy, &result);
9130     ok(hres == S_OK && V_VT(&result) == VT_I4,
9131         "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
9132         S_OK, hres, vtstr(V_VT(&result)));
9133     ok(hres == S_OK && V_I4(&result) == -1,
9134         "VARIMP: CY value %d, expected %d\n", V_I4(&result), -1);
9135 
9136     hres = pVarImp(&left, &dec, &result);
9137     ok(hres == S_OK && V_VT(&result) == VT_I4,
9138         "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
9139         S_OK, hres, vtstr(V_VT(&result)));
9140     ok(hres == S_OK && V_I4(&result) == -1,
9141         "VARIMP: DECIMAL value %d, expected %d\n", V_I4(&result), -1);
9142 
9143     hres = pVarImp(&dec, &dec, &result);
9144     ok(hres == S_OK && V_VT(&result) == VT_I4,
9145         "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
9146         S_OK, hres, vtstr(V_VT(&result)));
9147     ok(hres == S_OK && V_I4(&result) == -1,
9148         "VARIMP: DECIMAL value %d, expected %d\n", V_I4(&result), -1);
9149 
9150     if (has_i8)
9151     {
9152         hres = pVarImp(&dec, &right, &result);
9153         ok(hres == S_OK && V_VT(&result) == VT_I8,
9154             "VARIMP: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n",
9155             S_OK, hres, vtstr(V_VT(&result)));
9156         ok(hres == S_OK && V_I8(&result) == -3,
9157             "VARIMP: DECIMAL value 0x%x%08x, expected %d\n",
9158 	    (DWORD)(V_I8(&result) >>32), (DWORD)V_I8(&result), -3);
9159     }
9160 
9161     SysFreeString(false_str);
9162     SysFreeString(true_str);
9163 }
9164 
9165 START_TEST(vartest)
9166 {
9167   init();
9168 
9169   test_VariantInit();
9170   test_VariantClear();
9171   test_VariantCopy();
9172   test_VariantCopyInd();
9173   test_VarParseNumFromStr();
9174   test_VarNumFromParseNum();
9175   test_VarUdateFromDate();
9176   test_VarDateFromUdate();
9177   test_SystemTimeToVariantTime();
9178   test_VariantTimeToSystemTime();
9179   test_DosDateTimeToVariantTime();
9180   test_VariantTimeToDosDateTime();
9181   test_VarAbs();
9182   test_VarNot();
9183   test_VarSub();
9184   test_VarMod();
9185   test_VarFix();
9186   test_VarInt();
9187   test_VarNeg();
9188   test_VarRound();
9189   test_VarXor();
9190   test_VarOr();
9191   test_VarPow();
9192   test_VarEqv();
9193   test_VarMul();
9194   test_VarAdd();
9195   test_VarCmp(); /* Before test_VarCat() which needs VarCmp() */
9196   test_VarCat();
9197   test_VarAnd();
9198   test_VarDiv();
9199   test_VarIdiv();
9200   test_VarImp();
9201 }
9202