vartest.c 315 KB
Newer Older
1 2 3 4
/*
 * VARIANT test program
 *
 * Copyright 1998 Jean-Claude Cote
5
 * Copyright 2006 Google (Benjamin Arai)
6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 <stdarg.h>
23 24 25 26
#include <stdio.h>
#include <math.h>
#include <float.h>

27
#define COBJMACROS
28 29
#define CONST_VTABLE

30
#include "windef.h"
31
#include "winbase.h"
32
#include "winsock2.h"
33
#include "wine/test.h"
34 35 36 37 38 39 40 41 42
#include "winuser.h"
#include "wingdi.h"
#include "winnls.h"
#include "winerror.h"
#include "winnt.h"

#include "wtypes.h"
#include "oleauto.h"

43
static HMODULE hOleaut32;
44

45 46 47 48 49 50 51
static HRESULT (WINAPI *pVarUdateFromDate)(DATE,ULONG,UDATE*);
static HRESULT (WINAPI *pVarDateFromUdate)(UDATE*,ULONG,DATE*);
static INT (WINAPI *pSystemTimeToVariantTime)(LPSYSTEMTIME,double*);
static INT (WINAPI *pVariantTimeToSystemTime)(double,LPSYSTEMTIME);
static INT (WINAPI *pDosDateTimeToVariantTime)(USHORT,USHORT,double*);
static INT (WINAPI *pVariantTimeToDosDateTime)(double,USHORT*,USHORT *);

52 53 54 55 56
static const WCHAR sz12[] = {'1','2','\0'};
/* the strings are localized */
static WCHAR sz12_false[32];
static WCHAR sz12_true[32];

57 58
/* Get a conversion function ptr, return if function not available */
#define CHECKPTR(func) p##func = (void*)GetProcAddress(hOleaut32, #func); \
59
  if (!p##func) { win_skip("function " # func " not available, not testing it\n"); return; }
60

61
/* Has I8/UI8 data type? */
62
static BOOL has_i8;
63

64 65 66
/* When comparing floating point values we cannot expect an exact match
 * because the rounding errors depend on the exact algorithm.
 */
67 68
#define EQ_DOUBLE(a,b)     (fabs((a)-(b)) / (1.0+fabs(a)+fabs(b)) < 1e-14)
#define EQ_FLOAT(a,b)      (fabs((a)-(b)) / (1.0+fabs(a)+fabs(b)) < 1e-7)
69

70
#define SKIPTESTS(a)  if((a > VT_CLSID+10) && (a < VT_BSTR_BLOB-10)) continue
71

72 73 74 75
/* Allow our test macros to work for VT_NULL and VT_EMPTY too */
#define V_EMPTY(v) V_I4(v)
#define V_NULL(v) V_I4(v)

Michael Stefaniuc's avatar
Michael Stefaniuc committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
/* Size constraints for overflow tests */
#define I1_MAX   0x7f
#define I1_MIN   ((-I1_MAX)-1)
#define UI1_MAX  0xff
#define UI1_MIN  0
#define I2_MAX   0x7fff
#define I2_MIN   ((-I2_MAX)-1)
#define UI2_MAX  0xffff
#define UI2_MIN  0
#define I4_MAX   0x7fffffff
#define I4_MIN   ((-I4_MAX)-1)
#define UI4_MAX  0xffffffff
#define UI4_MIN  0
#define I8_MAX   (((LONGLONG)I4_MAX << 32) | UI4_MAX)
#define I8_MIN   ((-I8_MAX)-1)
#define UI8_MAX  (((ULONGLONG)UI4_MAX << 32) | UI4_MAX)
#define UI8_MIN  0
#define DATE_MAX 2958465
#define DATE_MIN -657434
#define R4_MAX FLT_MAX
#define R4_MIN FLT_MIN
#define R8_MAX DBL_MAX
#define R8_MIN DBL_MIN

100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
#define DEFINE_EXPECT(func) \
    static BOOL expect_ ## func = FALSE, called_ ## func = FALSE

#define SET_EXPECT(func) \
    do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)

#define CHECK_EXPECT2(func) \
    do { \
        ok(expect_ ##func, "unexpected call " #func "\n"); \
        called_ ## func = TRUE; \
    }while(0)

#define CHECK_EXPECT(func) \
    do { \
        CHECK_EXPECT2(func); \
        expect_ ## func = FALSE; \
    }while(0)

#define CHECK_CALLED(func) \
    do { \
        ok(called_ ## func, "expected " #func "\n"); \
        expect_ ## func = called_ ## func = FALSE; \
    }while(0)

DEFINE_EXPECT(dispatch_invoke);

typedef struct
{
    IDispatch IDispatch_iface;
    VARTYPE vt;
    HRESULT result;
} DummyDispatch;

static inline DummyDispatch *impl_from_IDispatch(IDispatch *iface)
{
    return CONTAINING_RECORD(iface, DummyDispatch, IDispatch_iface);
}

static ULONG WINAPI DummyDispatch_AddRef(IDispatch *iface)
{
    return 2;
}

static ULONG WINAPI DummyDispatch_Release(IDispatch *iface)
{
    return 1;
}

static HRESULT WINAPI DummyDispatch_QueryInterface(IDispatch *iface,
                                                   REFIID riid,
                                                   void** ppvObject)
{
    *ppvObject = NULL;

    if (IsEqualIID(riid, &IID_IDispatch) ||
        IsEqualIID(riid, &IID_IUnknown))
    {
        *ppvObject = iface;
        IDispatch_AddRef(iface);
    }

    return *ppvObject ? S_OK : E_NOINTERFACE;
}

static HRESULT WINAPI DummyDispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
{
    ok(0, "Unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI DummyDispatch_GetTypeInfo(IDispatch *iface, UINT tinfo, LCID lcid, ITypeInfo **ti)
{
    ok(0, "Unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI DummyDispatch_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *names,
    UINT cnames, LCID lcid, DISPID *dispid)
{
    ok(0, "Unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI DummyDispatch_Invoke(IDispatch *iface,
                                           DISPID dispid, REFIID riid,
                                           LCID lcid, WORD wFlags,
                                           DISPPARAMS *params,
                                           VARIANT *res,
                                           EXCEPINFO *ei,
                                           UINT *arg_err)
{
    DummyDispatch *This = impl_from_IDispatch(iface);

    CHECK_EXPECT(dispatch_invoke);

    ok(dispid == DISPID_VALUE, "got dispid %d\n", dispid);
    ok(IsEqualIID(riid, &IID_NULL), "go riid %s\n", wine_dbgstr_guid(riid));
    ok(wFlags == DISPATCH_PROPERTYGET, "Flags wrong\n");

    ok(params->rgvarg == NULL, "got %p\n", params->rgvarg);
    ok(params->rgdispidNamedArgs == NULL, "got %p\n", params->rgdispidNamedArgs);
    ok(params->cArgs == 0, "got %d\n", params->cArgs);
    ok(params->cNamedArgs == 0, "got %d\n", params->cNamedArgs);

    ok(res != NULL, "got %p\n", res);
    ok(V_VT(res) == VT_EMPTY, "got %d\n", V_VT(res));
    ok(ei == NULL, "got %p\n", ei);
    ok(arg_err == NULL, "got %p\n", arg_err);

    if (FAILED(This->result))
        return This->result;

    V_VT(res) = This->vt;
    if (This->vt == VT_UI1)
        V_UI1(res) = 34;
    else if (This->vt == VT_NULL)
    {
        V_VT(res) = VT_NULL;
        V_BSTR(res) = NULL;
    }
    else
        memset(res, 0, sizeof(*res));

    return S_OK;
}

static const IDispatchVtbl DummyDispatch_VTable =
{
    DummyDispatch_QueryInterface,
    DummyDispatch_AddRef,
    DummyDispatch_Release,
    DummyDispatch_GetTypeInfoCount,
    DummyDispatch_GetTypeInfo,
    DummyDispatch_GetIDsOfNames,
    DummyDispatch_Invoke
};

static void init_test_dispatch(VARTYPE vt, DummyDispatch *dispatch)
{
    dispatch->IDispatch_iface.lpVtbl = &DummyDispatch_VTable;
    dispatch->vt = vt;
    dispatch->result = S_OK;
}

244 245 246 247 248
typedef struct IRecordInfoImpl
{
    IRecordInfo IRecordInfo_iface;
    LONG ref;
    unsigned int recordclear;
249 250
    unsigned int getsize;
    unsigned int recordcopy;
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
    struct __tagBRECORD *rec;
} IRecordInfoImpl;

static inline IRecordInfoImpl *impl_from_IRecordInfo(IRecordInfo *iface)
{
    return CONTAINING_RECORD(iface, IRecordInfoImpl, IRecordInfo_iface);
}

static HRESULT WINAPI RecordInfo_QueryInterface(IRecordInfo *iface, REFIID riid, void **obj)
{
    *obj = NULL;

    if (IsEqualIID(riid, &IID_IUnknown) ||
        IsEqualIID(riid, &IID_IRecordInfo))
    {
        *obj = iface;
        IRecordInfo_AddRef(iface);
        return S_OK;
    }

    return E_NOINTERFACE;
}

static ULONG WINAPI RecordInfo_AddRef(IRecordInfo *iface)
{
    IRecordInfoImpl* This = impl_from_IRecordInfo(iface);
    return InterlockedIncrement(&This->ref);
}

static ULONG WINAPI RecordInfo_Release(IRecordInfo *iface)
{
    IRecordInfoImpl* This = impl_from_IRecordInfo(iface);
    ULONG ref = InterlockedDecrement(&This->ref);

    if (!ref)
        HeapFree(GetProcessHeap(), 0, This);

    return ref;
}

static HRESULT WINAPI RecordInfo_RecordInit(IRecordInfo *iface, PVOID pvNew)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI RecordInfo_RecordClear(IRecordInfo *iface, void *data)
{
    IRecordInfoImpl* This = impl_from_IRecordInfo(iface);
    This->recordclear++;
    This->rec->pvRecord = NULL;
    return S_OK;
}

305
static HRESULT WINAPI RecordInfo_RecordCopy(IRecordInfo *iface, void *src, void *dest)
306
{
307 308 309 310
    IRecordInfoImpl* This = impl_from_IRecordInfo(iface);
    This->recordcopy++;
    ok(src == (void*)0xdeadbeef, "wrong src pointer %p\n", src);
    return S_OK;
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
}

static HRESULT WINAPI RecordInfo_GetGuid(IRecordInfo *iface, GUID *pguid)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI RecordInfo_GetName(IRecordInfo *iface, BSTR *pbstrName)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI RecordInfo_GetSize(IRecordInfo *iface, ULONG* size)
{
327 328 329 330
    IRecordInfoImpl* This = impl_from_IRecordInfo(iface);
    This->getsize++;
    *size = 0;
    return S_OK;
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
}

static HRESULT WINAPI RecordInfo_GetTypeInfo(IRecordInfo *iface, ITypeInfo **ppTypeInfo)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI RecordInfo_GetField(IRecordInfo *iface, PVOID pvData,
                                                LPCOLESTR szFieldName, VARIANT *pvarField)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI RecordInfo_GetFieldNoCopy(IRecordInfo *iface, PVOID pvData,
                            LPCOLESTR szFieldName, VARIANT *pvarField, PVOID *ppvDataCArray)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI RecordInfo_PutField(IRecordInfo *iface, ULONG wFlags, PVOID pvData,
                                            LPCOLESTR szFieldName, VARIANT *pvarField)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI RecordInfo_PutFieldNoCopy(IRecordInfo *iface, ULONG wFlags,
                PVOID pvData, LPCOLESTR szFieldName, VARIANT *pvarField)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI RecordInfo_GetFieldNames(IRecordInfo *iface, ULONG *pcNames,
                                                BSTR *rgBstrNames)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static BOOL WINAPI RecordInfo_IsMatchingType(IRecordInfo *iface, IRecordInfo *info2)
{
    ok(0, "unexpected call\n");
377
    return FALSE;
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
}

static PVOID WINAPI RecordInfo_RecordCreate(IRecordInfo *iface)
{
    ok(0, "unexpected call\n");
    return NULL;
}

static HRESULT WINAPI RecordInfo_RecordCreateCopy(IRecordInfo *iface, PVOID pvSource,
                                                    PVOID *ppvDest)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI RecordInfo_RecordDestroy(IRecordInfo *iface, PVOID pvRecord)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static const IRecordInfoVtbl RecordInfoVtbl =
{
    RecordInfo_QueryInterface,
    RecordInfo_AddRef,
    RecordInfo_Release,
    RecordInfo_RecordInit,
    RecordInfo_RecordClear,
    RecordInfo_RecordCopy,
    RecordInfo_GetGuid,
    RecordInfo_GetName,
    RecordInfo_GetSize,
    RecordInfo_GetTypeInfo,
    RecordInfo_GetField,
    RecordInfo_GetFieldNoCopy,
    RecordInfo_PutField,
    RecordInfo_PutFieldNoCopy,
    RecordInfo_GetFieldNames,
    RecordInfo_IsMatchingType,
    RecordInfo_RecordCreate,
    RecordInfo_RecordCreateCopy,
    RecordInfo_RecordDestroy
};

static IRecordInfoImpl *get_test_recordinfo(void)
{
    IRecordInfoImpl *rec;

    rec = HeapAlloc(GetProcessHeap(), 0, sizeof(IRecordInfoImpl));
    rec->IRecordInfo_iface.lpVtbl = &RecordInfoVtbl;
    rec->ref = 1;
429 430 431 432
    rec->recordclear = 0;
    rec->getsize = 0;
    rec->recordcopy = 0;

433 434 435
    return rec;
}

436 437
static void init(void)
{
438 439 440 441
    BSTR bstr;
    HRESULT res;

    res = VarBstrFromBool(VARIANT_TRUE, LANG_USER_DEFAULT, VAR_LOCALBOOL, &bstr);
442
    ok(res == S_OK && bstr[0], "Expected localized string for 'True'\n");
443 444 445
    /* lstrcpyW / lstrcatW do not work on win95 */
    memcpy(sz12_true, sz12, sizeof(sz12));
    if (bstr) memcpy(&sz12_true[2], bstr, SysStringByteLen(bstr) + sizeof(WCHAR));
446 447 448
    SysFreeString(bstr);

    res = VarBstrFromBool(VARIANT_FALSE, LANG_USER_DEFAULT, VAR_LOCALBOOL, &bstr);
449
    ok(res == S_OK && bstr[0], "Expected localized string for 'False'\n");
450 451
    memcpy(sz12_false, sz12, sizeof(sz12));
    if (bstr) memcpy(&sz12_false[2], bstr, SysStringByteLen(bstr) + sizeof(WCHAR));
452 453
    SysFreeString(bstr);

454
    hOleaut32 = GetModuleHandleA("oleaut32.dll");
455 456 457
    has_i8 = GetProcAddress(hOleaut32, "VarI8FromI1") != NULL;
    if (!has_i8)
        skip("No support for I8 and UI8 data types\n");
458 459
}

460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
/* Functions to set a DECIMAL */
static void setdec(DECIMAL* dec, BYTE scl, BYTE sgn, ULONG hi32, ULONG64 lo64)
{
    S(U(*dec)).scale = scl;
    S(U(*dec)).sign = sgn;
    dec->Hi32 = hi32;
    U1(*dec).Lo64 = lo64;
}

static void setdec64(DECIMAL* dec, BYTE scl, BYTE sgn, ULONG hi32, ULONG mid32, ULONG lo32)
{
    S(U(*dec)).scale = scl;
    S(U(*dec)).sign = sgn;
    dec->Hi32 = hi32;
    S1(U1(*dec)).Mid32 = mid32;
    S1(U1(*dec)).Lo32 = lo32;
}
477

478
/* return the string text of a given variant type */
479 480
static char vtstr_buffer[16][256];
static int vtstr_current=0;
481
static const char *vtstr(int x)
Jon Griffiths's avatar
Jon Griffiths committed
482
{
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544
    switch(x) {
#define CASE(vt) case VT_##vt: return #vt
    CASE(EMPTY);
    CASE(NULL);
    CASE(I2);
    CASE(I4);
    CASE(R4);
    CASE(R8);
    CASE(CY);
    CASE(DATE);
    CASE(BSTR);
    CASE(DISPATCH);
    CASE(ERROR);
    CASE(BOOL);
    CASE(VARIANT);
    CASE(UNKNOWN);
    CASE(DECIMAL);
    CASE(I1);
    CASE(UI1);
    CASE(UI2);
    CASE(UI4);
    CASE(I8);
    CASE(UI8);
    CASE(INT);
    CASE(UINT);
    CASE(VOID);
    CASE(HRESULT);
    CASE(PTR);
    CASE(SAFEARRAY);
    CASE(CARRAY);
    CASE(USERDEFINED);
    CASE(LPSTR);
    CASE(LPWSTR);
    CASE(RECORD);
    CASE(INT_PTR);
    CASE(UINT_PTR);
    CASE(FILETIME);
    CASE(BLOB);
    CASE(STREAM);
    CASE(STORAGE);
    CASE(STREAMED_OBJECT);
    CASE(STORED_OBJECT);
    CASE(BLOB_OBJECT);
    CASE(CF);
    CASE(CLSID);
    CASE(VERSIONED_STREAM);
    CASE(VECTOR);
    CASE(ARRAY);
    CASE(BYREF);
    CASE(RESERVED);
    CASE(ILLEGAL);
#undef CASE

    case 0xfff:
        return "VT_BSTR_BLOB/VT_ILLEGALMASKED/VT_TYPEMASK";

    default:
        vtstr_current %= sizeof(vtstr_buffer)/sizeof(*vtstr_buffer);
        sprintf(vtstr_buffer[vtstr_current], "unknown variant type %d", x);
        return vtstr_buffer[vtstr_current++];
    }
}
545

546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
static const char *variantstr( const VARIANT *var )
{
    vtstr_current %= sizeof(vtstr_buffer)/sizeof(*vtstr_buffer);
    switch(V_VT(var))
    {
    case VT_I1:
        sprintf( vtstr_buffer[vtstr_current], "VT_I1(%d)", V_I1(var) ); break;
    case VT_I2:
        sprintf( vtstr_buffer[vtstr_current], "VT_I2(%d)", V_I2(var) ); break;
    case VT_I4:
        sprintf( vtstr_buffer[vtstr_current], "VT_I4(%d)", V_I4(var) ); break;
    case VT_INT:
        sprintf( vtstr_buffer[vtstr_current], "VT_INT(%d)", V_INT(var) ); break;
    case VT_I8:
        sprintf( vtstr_buffer[vtstr_current], "VT_I8(%x%08x)", (UINT)(V_I8(var) >> 32), (UINT)V_I8(var) ); break;
    case VT_UI8:
        sprintf( vtstr_buffer[vtstr_current], "VT_UI8(%x%08x)", (UINT)(V_UI8(var) >> 32), (UINT)V_UI8(var) ); break;
    case VT_R4:
        sprintf( vtstr_buffer[vtstr_current], "VT_R4(%g)", V_R4(var) ); break;
    case VT_R8:
        sprintf( vtstr_buffer[vtstr_current], "VT_R8(%g)", V_R8(var) ); break;
    case VT_UI1:
        sprintf( vtstr_buffer[vtstr_current], "VT_UI1(%u)", V_UI1(var) ); break;
    case VT_UI2:
        sprintf( vtstr_buffer[vtstr_current], "VT_UI2(%u)", V_UI2(var) ); break;
    case VT_UI4:
        sprintf( vtstr_buffer[vtstr_current], "VT_UI4(%u)", V_UI4(var) ); break;
    case VT_UINT:
        sprintf( vtstr_buffer[vtstr_current], "VT_UINT(%d)", V_UINT(var) ); break;
    case VT_CY:
        sprintf( vtstr_buffer[vtstr_current], "VT_CY(%x%08x)", S(V_CY(var)).Hi, S(V_CY(var)).Lo ); break;
    case VT_DATE:
        sprintf( vtstr_buffer[vtstr_current], "VT_DATE(%g)", V_DATE(var) ); break;
    default:
        return vtstr(V_VT(var));
    }
    return vtstr_buffer[vtstr_current++];
583 584
}

585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
static BOOL is_expected_variant( const VARIANT *result, const VARIANT *expected )
{
    if (V_VT(result) != V_VT(expected)) return FALSE;
    switch(V_VT(expected))
    {
    case VT_EMPTY:
    case VT_NULL:
        return TRUE;

#define CASE(vt) case VT_##vt: return (V_##vt(result) == V_##vt(expected))
    CASE(BOOL);
    CASE(I1);
    CASE(UI1);
    CASE(I2);
    CASE(UI2);
    CASE(I4);
    CASE(UI4);
    CASE(I8);
    CASE(UI8);
    CASE(INT);
    CASE(UINT);
#undef CASE

    case VT_DATE:
        return EQ_FLOAT(V_DATE(result), V_DATE(expected));
    case VT_R4:
        return EQ_FLOAT(V_R4(result), V_R4(expected));
    case VT_R8:
        return EQ_FLOAT(V_R8(result), V_R8(expected));
    case VT_CY:
        return (V_CY(result).int64 == V_CY(expected).int64);
    case VT_BSTR:
        return !lstrcmpW( V_BSTR(result), V_BSTR(expected) );
    case VT_DECIMAL:
        return !memcmp( &V_DECIMAL(result), &V_DECIMAL(expected), sizeof(DECIMAL) );
    default:
        ok(0, "unhandled variant type %s\n",vtstr(V_VT(expected)));
622
        return FALSE;
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
    }
}

static void test_var_call1( int line, HRESULT (WINAPI *func)(LPVARIANT,LPVARIANT),
                           VARIANT *arg, VARIANT *expected )
{
    VARIANT old_arg = *arg;
    VARIANT result;
    HRESULT hres;

    memset( &result, 0, sizeof(result) );
    hres = func( arg, &result );
    ok_(__FILE__,line)( hres == S_OK, "wrong result %x\n", hres );
    if (hres == S_OK)
        ok_(__FILE__,line)( is_expected_variant( &result, expected ),
                            "got %s expected %s\n", variantstr(&result), variantstr(expected) );
    ok_(__FILE__,line)( is_expected_variant( arg, &old_arg ), "Modified argument %s / %s\n",
                        variantstr(&old_arg), variantstr(arg));
641
    VariantClear( &result );
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
}

static void test_var_call2( int line, HRESULT (WINAPI *func)(LPVARIANT,LPVARIANT,LPVARIANT),
                            VARIANT *left, VARIANT *right, VARIANT *expected )
{
    VARIANT old_left = *left, old_right = *right;
    VARIANT result;
    HRESULT hres;

    memset( &result, 0, sizeof(result) );
    hres = func( left, right, &result );
    ok_(__FILE__,line)( hres == S_OK, "wrong result %x\n", hres );
    if (hres == S_OK)
        ok_(__FILE__,line)( is_expected_variant( &result, expected ),
                            "got %s expected %s\n", variantstr(&result), variantstr(expected) );
    ok_(__FILE__,line)( is_expected_variant( left, &old_left ), "Modified left argument %s / %s\n",
                        variantstr(&old_left), variantstr(left));
    ok_(__FILE__,line)( is_expected_variant( right, &old_right ), "Modified right argument %s / %s\n",
                        variantstr(&old_right), variantstr(right));
661
    VariantClear( &result );
662 663
}

664 665 666
static int strcmp_wa(const WCHAR *strw, const char *stra)
{
    WCHAR buf[512];
667
    MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(buf[0]));
668 669 670 671 672 673 674 675 676 677
    return lstrcmpW(strw, buf);
}

#define test_bstr_var(a,b) _test_bstr_var(__LINE__,a,b)
static void _test_bstr_var(unsigned line, const VARIANT *v, const char *str)
{
    ok_(__FILE__,line)(V_VT(v) == VT_BSTR, "unexpected vt=%d\n", V_VT(v));
    if(V_VT(v) == VT_BSTR)
        ok(!strcmp_wa(V_BSTR(v), str), "v=%s, expected %s\n", wine_dbgstr_w(V_BSTR(v)), str);
}
678

679 680
static void test_VariantInit(void)
{
681 682 683 684 685
  VARIANT v;

  memset(&v, -1, sizeof(v));
  VariantInit(&v);
  ok(V_VT(&v) == VT_EMPTY, "VariantInit() returned vt %d\n", V_VT(&v));
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
}

/* All possible combinations of extra V_VT() flags */
static const VARTYPE ExtraFlags[16] =
{
  0,
  VT_VECTOR,
  VT_ARRAY,
  VT_BYREF,
  VT_RESERVED,
  VT_VECTOR|VT_ARRAY,
  VT_VECTOR|VT_BYREF,
  VT_VECTOR|VT_RESERVED,
  VT_VECTOR|VT_ARRAY|VT_BYREF,
  VT_VECTOR|VT_ARRAY|VT_RESERVED,
  VT_VECTOR|VT_BYREF|VT_RESERVED,
  VT_VECTOR|VT_ARRAY|VT_BYREF|VT_RESERVED,
  VT_ARRAY|VT_BYREF,
  VT_ARRAY|VT_RESERVED,
  VT_ARRAY|VT_BYREF|VT_RESERVED,
  VT_BYREF|VT_RESERVED,
};

709
/* Determine if a vt is valid for VariantClear() */
710
static BOOL IsValidVariantClearVT(VARTYPE vt, VARTYPE extraFlags)
711
{
712
  BOOL ret = FALSE;
713 714 715 716 717 718 719 720

  /* Only the following flags/types are valid */
  if ((vt <= VT_LPWSTR || vt == VT_RECORD || vt == VT_CLSID) &&
      vt != (VARTYPE)15 &&
      (vt < (VARTYPE)24 || vt > (VARTYPE)31) &&
      (!(extraFlags & (VT_BYREF|VT_ARRAY)) || vt > VT_NULL) &&
      (extraFlags == 0 || extraFlags == VT_BYREF || extraFlags == VT_ARRAY ||
       extraFlags == (VT_ARRAY|VT_BYREF)))
721
    ret = TRUE; /* ok */
722

723
  if (!has_i8 && (vt == VT_I8 || vt == VT_UI8))
724
    ret = FALSE; /* Old versions of oleaut32 */
725 726 727
  return ret;
}

728 729
typedef struct
{
730 731 732
    IUnknown IUnknown_iface;
    LONG     ref;
    LONG     events;
733 734
} test_VariantClearImpl;

735 736 737 738 739
static inline test_VariantClearImpl *impl_from_IUnknown(IUnknown *iface)
{
    return CONTAINING_RECORD(iface, test_VariantClearImpl, IUnknown_iface);
}

740 741
static HRESULT WINAPI VC_QueryInterface(LPUNKNOWN iface,REFIID riid,LPVOID *ppobj)
{
742
    test_VariantClearImpl *This = impl_from_IUnknown(iface);
743 744 745 746 747
    This->events |= 0x1;
    return E_NOINTERFACE;
}

static ULONG WINAPI VC_AddRef(LPUNKNOWN iface) {
748
    test_VariantClearImpl *This = impl_from_IUnknown(iface);
749 750 751 752 753
    This->events |= 0x2;
    return InterlockedIncrement(&This->ref);
}

static ULONG WINAPI VC_Release(LPUNKNOWN iface) {
754
    test_VariantClearImpl *This = impl_from_IUnknown(iface);
755 756 757 758 759 760 761 762 763 764 765
    /* static class, won't be  freed */
    This->events |= 0x4;
    return InterlockedDecrement(&This->ref);
}

static const IUnknownVtbl test_VariantClear_vtbl = {
    VC_QueryInterface,
    VC_AddRef,
    VC_Release,
};

766
static test_VariantClearImpl test_myVariantClearImpl = {{&test_VariantClear_vtbl}, 1, 0};
767

768 769
static void test_VariantClear(void)
{
770 771
  struct __tagBRECORD *rec;
  IRecordInfoImpl *recinfo;
772 773
  HRESULT hres;
  VARIANTARG v;
774
  VARIANT v2;
775
  size_t i;
776
  LONG i4;
777
  IUnknown *punk;
778 779

  /* Crashes: Native does not test input for NULL, so neither does Wine */
780 781
  if (0)
      VariantClear(NULL);
782 783 784 785 786

  /* Only the type field is set, to VT_EMPTY */
  V_VT(&v) = VT_UI4;
  V_UI4(&v) = ~0u;
  hres = VariantClear(&v);
787
  ok((hres == S_OK && V_VT(&v) == VT_EMPTY),
788
     "VariantClear: Type set to %d, res %08x\n", V_VT(&v), hres);
789 790 791 792 793 794
  ok(V_UI4(&v) == ~0u, "VariantClear: Overwrote value\n");

  /* Test all possible V_VT values.
   * Also demonstrates that null pointers in 'v' are not dereferenced.
   * Individual variant tests should test VariantClear() with non-NULL values.
   */
795
  for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
796 797 798 799 800 801 802
  {
    VARTYPE vt;

    for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
    {
      HRESULT hExpected = DISP_E_BADVARTYPE;

803 804
      SKIPTESTS(vt);

805 806 807 808 809
      memset(&v, 0, sizeof(v));
      V_VT(&v) = vt | ExtraFlags[i];

      hres = VariantClear(&v);

810
      if (IsValidVariantClearVT(vt, ExtraFlags[i]))
811 812
        hExpected = S_OK;

813
      ok(hres == hExpected, "VariantClear: expected 0x%X, got 0x%X for vt %d | 0x%X\n",
814 815 816
         hExpected, hres, vt, ExtraFlags[i]);
    }
  }
817 818 819 820 821 822 823 824 825 826

  /* Some BYREF tests with non-NULL ptrs */

  /* VARIANT BYREF */
  V_VT(&v2) = VT_I4;
  V_I4(&v2) = 0x1234;
  V_VT(&v) = VT_VARIANT | VT_BYREF;
  V_VARIANTREF(&v) = &v2;

  hres = VariantClear(&v);
827
  ok(hres == S_OK, "ret %08x\n", hres);
828 829 830
  ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
  ok(V_VARIANTREF(&v) == &v2, "variant ref %p\n", V_VARIANTREF(&v2));
  ok(V_VT(&v2) == VT_I4, "vt %04x\n", V_VT(&v2));
831
  ok(V_I4(&v2) == 0x1234, "i4 %04x\n", V_I4(&v2));
832 833 834 835 836 837 838

  /* I4 BYREF */
  i4 = 0x4321;
  V_VT(&v) = VT_I4 | VT_BYREF;
  V_I4REF(&v) = &i4;

  hres = VariantClear(&v);
839
  ok(hres == S_OK, "ret %08x\n", hres);
840 841
  ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
  ok(V_I4REF(&v) == &i4, "i4 ref %p\n", V_I4REF(&v2));
842
  ok(i4 == 0x4321, "i4 changed %08x\n", i4);
843 844 845 846


  /* UNKNOWN */
  V_VT(&v) = VT_UNKNOWN;
847
  V_UNKNOWN(&v) = &test_myVariantClearImpl.IUnknown_iface;
848 849
  test_myVariantClearImpl.events = 0;
  hres = VariantClear(&v);
850
  ok(hres == S_OK, "ret %08x\n", hres);
851
  ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
852
  ok(V_UNKNOWN(&v) == &test_myVariantClearImpl.IUnknown_iface, "unknown %p\n", V_UNKNOWN(&v));
853
  /* Check that Release got called, but nothing else */
854
  ok(test_myVariantClearImpl.events ==  0x4, "Unexpected call. events %08x\n", test_myVariantClearImpl.events);
855 856

  /* UNKNOWN BYREF */
857
  punk = &test_myVariantClearImpl.IUnknown_iface;
858 859 860 861
  V_VT(&v) = VT_UNKNOWN | VT_BYREF;
  V_UNKNOWNREF(&v) = &punk;
  test_myVariantClearImpl.events = 0;
  hres = VariantClear(&v);
862
  ok(hres == S_OK, "ret %08x\n", hres);
863 864 865
  ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
  ok(V_UNKNOWNREF(&v) == &punk, "unknown ref %p\n", V_UNKNOWNREF(&v));
  /* Check that nothing got called */
866
  ok(test_myVariantClearImpl.events ==  0, "Unexpected call. events %08x\n", test_myVariantClearImpl.events);
867 868 869

  /* DISPATCH */
  V_VT(&v) = VT_DISPATCH;
870
  V_DISPATCH(&v) = (IDispatch*)&test_myVariantClearImpl.IUnknown_iface;
871 872
  test_myVariantClearImpl.events = 0;
  hres = VariantClear(&v);
873
  ok(hres == S_OK, "ret %08x\n", hres);
874
  ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
875 876
  ok(V_DISPATCH(&v) == (IDispatch*)&test_myVariantClearImpl.IUnknown_iface,
     "dispatch %p\n", V_DISPATCH(&v));
877
  /* Check that Release got called, but nothing else */
878
  ok(test_myVariantClearImpl.events ==  0x4, "Unexpected call. events %08x\n", test_myVariantClearImpl.events);
879 880

  /* DISPATCH BYREF */
881
  punk = &test_myVariantClearImpl.IUnknown_iface;
882 883 884 885
  V_VT(&v) = VT_DISPATCH | VT_BYREF;
  V_DISPATCHREF(&v) = (IDispatch**)&punk;
  test_myVariantClearImpl.events = 0;
  hres = VariantClear(&v);
886
  ok(hres == S_OK, "ret %08x\n", hres);
887 888 889
  ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
  ok(V_DISPATCHREF(&v) == (IDispatch**)&punk, "dispatch ref %p\n", V_DISPATCHREF(&v));
  /* Check that nothing got called */
890
  ok(test_myVariantClearImpl.events ==  0, "Unexpected call. events %08x\n", test_myVariantClearImpl.events);
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906

  /* RECORD */
  recinfo = get_test_recordinfo();
  V_VT(&v) = VT_RECORD;
  rec = &V_UNION(&v, brecVal);
  rec->pRecInfo = &recinfo->IRecordInfo_iface;
  rec->pvRecord = (void*)0xdeadbeef;
  recinfo->recordclear = 0;
  recinfo->ref = 2;
  recinfo->rec = rec;
  hres = VariantClear(&v);
  ok(hres == S_OK, "ret %08x\n", hres);
  ok(rec->pvRecord == NULL, "got %p\n", rec->pvRecord);
  ok(recinfo->recordclear == 1, "got %d\n", recinfo->recordclear);
  ok(recinfo->ref == 1, "got %d\n", recinfo->ref);
  IRecordInfo_Release(&recinfo->IRecordInfo_iface);
907 908
}

909 910
static void test_VariantCopy(void)
{
911 912
  struct __tagBRECORD *rec;
  IRecordInfoImpl *recinfo;
913 914 915 916 917 918 919 920 921 922 923
  VARIANTARG vSrc, vDst;
  VARTYPE vt;
  size_t i;
  HRESULT hres, hExpected;

  /* Establish that the failure/other cases are dealt with. Individual tests
   * for each type should verify that data is copied correctly, references
   * are updated, etc.
   */

  /* vSrc == vDst */
924
  for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
925 926 927
  {
    for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
    {
928 929
      SKIPTESTS(vt);

930 931 932 933 934 935 936 937 938 939 940
      memset(&vSrc, 0, sizeof(vSrc));
      V_VT(&vSrc) = vt | ExtraFlags[i];

      hExpected = DISP_E_BADVARTYPE;
      /* src is allowed to be a VT_CLSID */
      if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
        hExpected = S_OK;

      hres = VariantCopy(&vSrc, &vSrc);

      ok(hres == hExpected,
941
         "Copy(src==dst): expected 0x%X, got 0x%X for src==dest vt %d|0x%X\n",
942 943 944 945 946 947 948 949 950 951
         hExpected, hres, vt, ExtraFlags[i]);
    }
  }

  /* Test that if VariantClear() fails on dest, the function fails. This also
   * shows that dest is in fact cleared and not just overwritten
   */
  memset(&vSrc, 0, sizeof(vSrc));
  V_VT(&vSrc) = VT_UI1;

952
  for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
953 954 955
  {
    for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
    {
956 957
      SKIPTESTS(vt);

958 959 960 961 962 963 964 965 966 967 968
      hExpected = DISP_E_BADVARTYPE;

      memset(&vDst, 0, sizeof(vDst));
      V_VT(&vDst) = vt | ExtraFlags[i];

      if (IsValidVariantClearVT(vt, ExtraFlags[i]))
        hExpected = S_OK;

      hres = VariantCopy(&vDst, &vSrc);

      ok(hres == hExpected,
969
         "Copy(bad dst): expected 0x%X, got 0x%X for dest vt %d|0x%X\n",
970 971 972 973 974 975 976 977
         hExpected, hres, vt, ExtraFlags[i]);
      if (hres == S_OK)
        ok(V_VT(&vDst) == VT_UI1,
           "Copy(bad dst): expected vt = VT_UI1, got %d\n", V_VT(&vDst));
    }
  }

  /* Test that VariantClear() checks vSrc for validity before copying */
978
  for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
979 980 981
  {
    for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
    {
982 983
      SKIPTESTS(vt);

984 985 986 987 988 989 990 991 992 993 994 995 996 997 998
      hExpected = DISP_E_BADVARTYPE;

      memset(&vDst, 0, sizeof(vDst));
      V_VT(&vDst) = VT_EMPTY;

      memset(&vSrc, 0, sizeof(vSrc));
      V_VT(&vSrc) = vt | ExtraFlags[i];

      /* src is allowed to be a VT_CLSID */
      if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
        hExpected = S_OK;

      hres = VariantCopy(&vDst, &vSrc);

      ok(hres == hExpected,
999
         "Copy(bad src): expected 0x%X, got 0x%X for src vt %d|0x%X\n",
1000 1001
         hExpected, hres, vt, ExtraFlags[i]);
      if (hres == S_OK)
1002
      {
1003 1004 1005
        ok(V_VT(&vDst) == (vt|ExtraFlags[i]),
           "Copy(bad src): expected vt = %d, got %d\n",
           vt | ExtraFlags[i], V_VT(&vDst));
1006 1007
        VariantClear(&vDst);
      }
1008 1009
    }
  }
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
  
  /* Test that copying a NULL BSTR results in an empty BSTR */
  memset(&vDst, 0, sizeof(vDst));
  V_VT(&vDst) = VT_EMPTY;
  memset(&vSrc, 0, sizeof(vSrc));
  V_VT(&vSrc) = VT_BSTR;
  hres = VariantCopy(&vDst, &vSrc);
  ok(hres == S_OK, "Copy(NULL BSTR): Failed to copy a NULL BSTR\n");
  if (hres == S_OK)
  {
    ok((V_VT(&vDst) == VT_BSTR) && V_BSTR(&vDst),
       "Copy(NULL BSTR): should have non-NULL result\n");
    if ((V_VT(&vDst) == VT_BSTR) && V_BSTR(&vDst))
    {
      ok(*V_BSTR(&vDst) == 0, "Copy(NULL BSTR): result not empty\n");
    }
1026
    VariantClear(&vDst);
1027
  }
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054

  /* copy RECORD */
  recinfo = get_test_recordinfo();

  memset(&vDst, 0, sizeof(vDst));
  V_VT(&vDst) = VT_EMPTY;

  V_VT(&vSrc) = VT_RECORD;
  rec = &V_UNION(&vSrc, brecVal);
  rec->pRecInfo = &recinfo->IRecordInfo_iface;
  rec->pvRecord = (void*)0xdeadbeef;

  recinfo->recordclear = 0;
  recinfo->recordcopy = 0;
  recinfo->getsize = 0;
  recinfo->rec = rec;
  hres = VariantCopy(&vDst, &vSrc);
  ok(hres == S_OK, "ret %08x\n", hres);

  rec = &V_UNION(&vDst, brecVal);
  ok(rec->pvRecord != (void*)0xdeadbeef && rec->pvRecord != NULL, "got %p\n", rec->pvRecord);
  ok(rec->pRecInfo == &recinfo->IRecordInfo_iface, "got %p\n", rec->pRecInfo);
  ok(recinfo->getsize == 1, "got %d\n", recinfo->recordclear);
  ok(recinfo->recordcopy == 1, "got %d\n", recinfo->recordclear);

  VariantClear(&vDst);
  VariantClear(&vSrc);
1055 1056 1057
}

/* Determine if a vt is valid for VariantCopyInd() */
1058
static BOOL IsValidVariantCopyIndVT(VARTYPE vt, VARTYPE extraFlags)
1059
{
1060
  BOOL ret = FALSE;
1061 1062 1063 1064 1065

  if ((extraFlags & VT_ARRAY) ||
     (vt > VT_NULL && vt != (VARTYPE)15 && vt < VT_VOID &&
     !(extraFlags & (VT_VECTOR|VT_RESERVED))))
  {
1066
    ret = TRUE; /* ok */
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
  }
  return ret;
}

static void test_VariantCopyInd(void)
{
  VARIANTARG vSrc, vDst, vRef, vRef2;
  VARTYPE vt;
  size_t i;
  BYTE buffer[64];
  HRESULT hres, hExpected;

  memset(buffer, 0, sizeof(buffer));

  /* vSrc == vDst */
1082
  for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
1083 1084 1085 1086 1087 1088
  {
    if (ExtraFlags[i] & VT_ARRAY)
      continue; /* Native crashes on NULL safearray */

    for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
    {
1089 1090
      SKIPTESTS(vt);

1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
      memset(&vSrc, 0, sizeof(vSrc));
      V_VT(&vSrc) = vt | ExtraFlags[i];

      hExpected = DISP_E_BADVARTYPE;
      if (!(ExtraFlags[i] & VT_BYREF))
      {
        /* if src is not by-reference, acts as VariantCopy() */
        if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
          hExpected = S_OK;
      }
      else
      {
        if (vt == VT_SAFEARRAY || vt == VT_BSTR || vt == VT_UNKNOWN ||
            vt == VT_DISPATCH || vt == VT_RECORD)
          continue; /* Need valid ptrs for deep copies */

        V_BYREF(&vSrc) = &buffer;
        hExpected = E_INVALIDARG;

        if ((vt == VT_I8 || vt == VT_UI8) &&
            ExtraFlags[i] == VT_BYREF)
        {
1113
          if (has_i8)
1114 1115 1116 1117 1118 1119 1120 1121 1122
            hExpected = S_OK; /* Only valid if I8 is a known type */
        }
        else if (IsValidVariantCopyIndVT(vt, ExtraFlags[i]))
          hExpected = S_OK;
      }

      hres = VariantCopyInd(&vSrc, &vSrc);

      ok(hres == hExpected,
1123
         "CopyInd(src==dst): expected 0x%X, got 0x%X for src==dst vt %d|0x%X\n",
1124 1125 1126 1127 1128 1129 1130 1131 1132
         hExpected, hres, vt, ExtraFlags[i]);
    }
  }

  /* Bad dest */
  memset(&vSrc, 0, sizeof(vSrc));
  V_VT(&vSrc) = VT_UI1|VT_BYREF;
  V_BYREF(&vSrc) = &buffer;

1133
  for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
1134 1135 1136
  {
    for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
    {
1137 1138
      SKIPTESTS(vt);

1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149
      memset(&vDst, 0, sizeof(vDst));
      V_VT(&vDst) = vt | ExtraFlags[i];

      hExpected = DISP_E_BADVARTYPE;

      if (IsValidVariantClearVT(vt, ExtraFlags[i]))
        hExpected = S_OK;

      hres = VariantCopyInd(&vDst, &vSrc);

      ok(hres == hExpected,
1150
         "CopyInd(bad dst): expected 0x%X, got 0x%X for dst vt %d|0x%X\n",
1151 1152 1153 1154 1155 1156 1157 1158
         hExpected, hres, vt, ExtraFlags[i]);
      if (hres == S_OK)
        ok(V_VT(&vDst) == VT_UI1,
           "CopyInd(bad dst): expected vt = VT_UI1, got %d\n", V_VT(&vDst));
    }
  }

  /* bad src */
1159
  for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
1160 1161 1162 1163 1164 1165
  {
    if (ExtraFlags[i] & VT_ARRAY)
      continue; /* Native crashes on NULL safearray */

    for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
    {
1166 1167
      SKIPTESTS(vt);

1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193
      memset(&vDst, 0, sizeof(vDst));
      V_VT(&vDst) = VT_EMPTY;

      memset(&vSrc, 0, sizeof(vSrc));
      V_VT(&vSrc) = vt | ExtraFlags[i];

      hExpected = DISP_E_BADVARTYPE;
      if (!(ExtraFlags[i] & VT_BYREF))
      {
        /* if src is not by-reference, acts as VariantCopy() */
        if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
          hExpected = S_OK;
      }
      else
      {
        if (vt == VT_SAFEARRAY || vt == VT_BSTR || vt == VT_UNKNOWN ||
            vt == VT_DISPATCH || vt == VT_RECORD)
          continue; /* Need valid ptrs for deep copies, see vartype.c */

        V_BYREF(&vSrc) = &buffer;

        hExpected = E_INVALIDARG;

        if ((vt == VT_I8 || vt == VT_UI8) &&
            ExtraFlags[i] == VT_BYREF)
        {
1194
          if (has_i8)
1195 1196 1197 1198 1199 1200 1201 1202 1203
            hExpected = S_OK; /* Only valid if I8 is a known type */
        }
        else if (IsValidVariantCopyIndVT(vt, ExtraFlags[i]))
          hExpected = S_OK;
      }

      hres = VariantCopyInd(&vDst, &vSrc);

      ok(hres == hExpected,
1204
         "CopyInd(bad src): expected 0x%X, got 0x%X for src vt %d|0x%X\n",
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224
         hExpected, hres, vt, ExtraFlags[i]);
      if (hres == S_OK)
      {
        if (vt == VT_VARIANT && ExtraFlags[i] == VT_BYREF)
        {
          /* Type of vDst should be the type of the referenced variant.
           * Since we set the buffer to all zeros, its type should be
           * VT_EMPTY.
           */
          ok(V_VT(&vDst) == VT_EMPTY,
             "CopyInd(bad src): expected dst vt = VT_EMPTY, got %d|0x%X\n",
             V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK);
        }
        else
        {
          ok(V_VT(&vDst) == (vt|(ExtraFlags[i] & ~VT_BYREF)),
             "CopyInd(bad src): expected dst vt = %d|0x%X, got %d|0x%X\n",
             vt, ExtraFlags[i] & ~VT_BYREF,
             V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK);
        }
1225
        VariantClear(&vDst);
1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237
      }
    }
  }

  /* By-reference variants are dereferenced */
  V_VT(&vRef) = VT_UI1;
  V_UI1(&vRef) = 0x77;
  V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
  V_VARIANTREF(&vSrc) = &vRef;
  VariantInit(&vDst);

  hres = VariantCopyInd(&vDst, &vSrc);
1238
  ok(hres == S_OK, "VariantCopyInd failed: 0x%08x\n", hres);
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250
  ok(V_VT(&vDst) == VT_UI1 && V_UI1(&vDst) == 0x77,
     "CopyInd(deref): expected dst vt = VT_UI1, val 0x77, got %d|0x%X, 0x%2X\n",
      V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK, V_UI1(&vDst));

  /* By-reference variant to a by-reference type succeeds */
  V_VT(&vRef) = VT_UI1|VT_BYREF;
  V_UI1REF(&vRef) = buffer; buffer[0] = 0x88;
  V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
  V_VARIANTREF(&vSrc) = &vRef;
  VariantInit(&vDst);

  hres = VariantCopyInd(&vDst, &vSrc);
1251
  ok(hres == S_OK, "VariantCopyInd failed: 0x%08x\n", hres);
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266
  ok(V_VT(&vDst) == VT_UI1 && V_UI1(&vDst) == 0x88,
     "CopyInd(deref): expected dst vt = VT_UI1, val 0x77, got %d|0x%X, 0x%2X\n",
      V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK, V_UI1(&vDst));

  /* But a by-reference variant to a by-reference variant fails */
  V_VT(&vRef2) = VT_UI1;
  V_UI1(&vRef2) = 0x77;
  V_VT(&vRef) = VT_VARIANT|VT_BYREF;
  V_VARIANTREF(&vRef) = &vRef2;
  V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
  V_VARIANTREF(&vSrc) = &vRef;
  VariantInit(&vDst);

  hres = VariantCopyInd(&vDst, &vSrc);
  ok(hres == E_INVALIDARG,
1267
     "CopyInd(ref->ref): expected E_INVALIDARG, got 0x%08x\n", hres);
1268 1269
}

1270 1271
static HRESULT (WINAPI *pVarParseNumFromStr)(OLECHAR*,LCID,ULONG,NUMPARSE*,BYTE*);

1272 1273
/* Macros for converting and testing the result of VarParseNumFromStr */
#define FAILDIG 255
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301

static HRESULT convert_str( const char *str, INT dig, ULONG flags,
                            NUMPARSE *np, BYTE rgb[128], LCID lcid )
{
    OLECHAR buff[128];
    MultiByteToWideChar( CP_ACP,0, str, -1, buff, sizeof(buff)/sizeof(WCHAR) );
    memset( rgb, FAILDIG, 128 );
    memset( np, 255, sizeof(*np) );
    np->cDig = dig;
    np->dwInFlags = flags;
    return pVarParseNumFromStr( buff, lcid, LOCALE_NOUSEROVERRIDE, np, rgb);
}

static void expect_NumFromStr( int line, HRESULT hres, NUMPARSE *np, INT a, ULONG b, ULONG c,
                               INT d, INT e, INT f )
{
    if (hres == (HRESULT)S_OK)
    {
        ok_(__FILE__,line)(np->cDig == a, "Expected cDig = %d, got %d\n", a, np->cDig);
        ok_(__FILE__,line)(np->dwInFlags == b, "Expected dwInFlags = 0x%x, got 0x%x\n", b, np->dwInFlags);
        ok_(__FILE__,line)(np->dwOutFlags == c, "Expected dwOutFlags = 0x%x, got 0x%x\n", c, np->dwOutFlags);
        ok_(__FILE__,line)(np->cchUsed == d, "Expected cchUsed = %d, got %d\n", d, np->cchUsed);
        ok_(__FILE__,line)(np->nBaseShift == e, "Expected nBaseShift = %d, got %d\n", e, np->nBaseShift);
        ok_(__FILE__,line)(np->nPwr10 == f, "Expected nPwr10 = %d, got %d\n", f, np->nPwr10);
    }
}

#define CONVERTN(str,dig,flags) hres = convert_str( str, dig, flags, &np, rgb, lcid )
1302
#define CONVERT(str,flags) CONVERTN(str,sizeof(rgb),flags)
1303
#define EXPECT(a,b,c,d,e,f) expect_NumFromStr( __LINE__, hres, &np, a, b, c, d, e, f )
1304
#define EXPECTRGB(a,b) ok(rgb[a] == b, "Digit[%d], expected %d, got %d\n", a, b, rgb[a])
1305
#define EXPECTFAIL ok(hres == (HRESULT)DISP_E_TYPEMISMATCH, "Call succeeded, hres = %08x\n", hres)
1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317
#define EXPECT2(a,b) EXPECTRGB(0,a); EXPECTRGB(1,b)

static void test_VarParseNumFromStr(void)
{
  HRESULT hres;
  /* Ensure all tests are using the same locale characters for '$', ',' etc */
  LCID lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
  NUMPARSE np;
  BYTE rgb[128];

  /** No flags **/

1318 1319
  CHECKPTR(VarParseNumFromStr);

1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464
  /* Consume a single digit */
  CONVERT("7", 0);
  EXPECT(1,0,0,1,0,0);
  EXPECT2(7,FAILDIG);

  /* cDig is not literal digits - zeros are suppressed and nPwr10 is increased */
  CONVERT("10", 0);
  EXPECT(1,0,0,2,0,1);
  /* Note: Win32 writes the trailing zeros if they are within cDig's limits,
   * but then excludes them from the returned cDig count.
   * In our implementation we don't bother writing them at all.
   */
  EXPECTRGB(0, 1);

  /* if cDig is too small and numbers follow, sets INEXACT */
  CONVERTN("11",1, 0);
  EXPECT(1,0,NUMPRS_INEXACT,2,0,1);
  EXPECT2(1,FAILDIG);

  /* Strips leading zeros */
  CONVERT("01", 0);
  EXPECT(1,0,0,2,0,0);
  EXPECT2(1,FAILDIG);

  /* Strips leading zeros */
  CONVERTN("01",1, 0);
  EXPECT(1,0,0,2,0,0);
  EXPECT2(1,FAILDIG);


  /* Fails on non digits */
  CONVERT("a", 0);
  EXPECTFAIL;
  EXPECTRGB(0,FAILDIG);

  /** NUMPRS_LEADING_WHITE/NUMPRS_TRAILING_WHITE **/

  /* Without flag, fails on whitespace */
  CONVERT(" 0", 0);
  EXPECTFAIL;
  EXPECTRGB(0,FAILDIG);


  /* With flag, consumes whitespace */
  CONVERT(" 0", NUMPRS_LEADING_WHITE);
  EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
  EXPECT2(0,FAILDIG);

  /* Test TAB once, then assume it acts as space for all cases */
  CONVERT("\t0", NUMPRS_LEADING_WHITE);
  EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
  EXPECT2(0,FAILDIG);


  /* Doesn't pick up trailing whitespace without flag */
  CONVERT("0 ", 0);
  EXPECT(1,0,0,1,0,0);
  EXPECT2(0,FAILDIG);

  /* With flag, consumes trailing whitespace */
  CONVERT("0 ", NUMPRS_TRAILING_WHITE);
  EXPECT(1,NUMPRS_TRAILING_WHITE,NUMPRS_TRAILING_WHITE,2,0,0);
  EXPECT2(0,FAILDIG);

  /* Leading flag only consumes leading */
  CONVERT(" 0 ", NUMPRS_LEADING_WHITE);
  EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
  EXPECT2(0,FAILDIG);

  /* Both flags consumes both */
  CONVERT(" 0 ", NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE);
  EXPECT(1,NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE,NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE,3,0,0);
  EXPECT2(0,FAILDIG);

  /** NUMPRS_LEADING_PLUS/NUMPRS_TRAILING_PLUS **/

  /* Without flag, fails on + */
  CONVERT("+0", 0);
  EXPECTFAIL;
  EXPECTRGB(0,FAILDIG);

  /* With flag, consumes + */
  CONVERT("+0", NUMPRS_LEADING_PLUS);
  EXPECT(1,NUMPRS_LEADING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
  EXPECT2(0,FAILDIG);

  /* Without flag, doesn't consume trailing + */
  CONVERT("0+", 0);
  EXPECT(1,0,0,1,0,0);
  EXPECT2(0,FAILDIG);

  /* With flag, consumes trailing + */
  CONVERT("0+", NUMPRS_TRAILING_PLUS);
  EXPECT(1,NUMPRS_TRAILING_PLUS,NUMPRS_TRAILING_PLUS,2,0,0);
  EXPECT2(0,FAILDIG);

  /* With leading flag, doesn't consume trailing + */
  CONVERT("+0+", NUMPRS_LEADING_PLUS);
  EXPECT(1,NUMPRS_LEADING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
  EXPECT2(0,FAILDIG);

  /* Trailing + doesn't get consumed if we specify both (unlike whitespace) */
  CONVERT("+0+", NUMPRS_LEADING_PLUS|NUMPRS_TRAILING_PLUS);
  EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_TRAILING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
  EXPECT2(0,FAILDIG);

  /** NUMPRS_LEADING_MINUS/NUMPRS_TRAILING_MINUS **/

  /* Without flag, fails on - */
  CONVERT("-0", 0);
  EXPECTFAIL;
  EXPECTRGB(0,FAILDIG);

  /* With flag, consumes - */
  CONVERT("-0", NUMPRS_LEADING_MINUS);
  EXPECT(1,NUMPRS_LEADING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
  EXPECT2(0,FAILDIG);

  /* Without flag, doesn't consume trailing - */
  CONVERT("0-", 0);
  EXPECT(1,0,0,1,0,0);
  EXPECT2(0,FAILDIG);

  /* With flag, consumes trailing - */
  CONVERT("0-", NUMPRS_TRAILING_MINUS);
  EXPECT(1,NUMPRS_TRAILING_MINUS,NUMPRS_NEG|NUMPRS_TRAILING_MINUS,2,0,0);
  EXPECT2(0,FAILDIG);

  /* With leading flag, doesn't consume trailing - */
  CONVERT("-0-", NUMPRS_LEADING_MINUS);
  EXPECT(1,NUMPRS_LEADING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
  EXPECT2(0,FAILDIG);

  /* Trailing - doesn't get consumed if we specify both (unlike whitespace) */
  CONVERT("-0-", NUMPRS_LEADING_MINUS|NUMPRS_TRAILING_MINUS);
  EXPECT(1,NUMPRS_LEADING_MINUS|NUMPRS_TRAILING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
  EXPECT2(0,FAILDIG);

  /** NUMPRS_HEX_OCT **/

  /* Could be hex, octal or decimal - With flag reads as decimal */
  CONVERT("0", NUMPRS_HEX_OCT);
  EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
  EXPECT2(0,FAILDIG);

1465
  /* Doesn't recognise hex in .asm syntax */
1466 1467 1468 1469 1470 1471 1472 1473 1474
  CONVERT("0h", NUMPRS_HEX_OCT);
  EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
  EXPECT2(0,FAILDIG);

  /* Doesn't fail with valid leading string but no digits */
  CONVERT("0x", NUMPRS_HEX_OCT);
  EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
  EXPECT2(0,FAILDIG);

1475
  /* Doesn't recognise hex format numbers at all! */
1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488
  CONVERT("0x0", NUMPRS_HEX_OCT);
  EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
  EXPECT2(0,FAILDIG);

  /* Doesn't recognise plain hex digits either */
  CONVERT("FE", NUMPRS_HEX_OCT);
  EXPECTFAIL;
  EXPECTRGB(0,FAILDIG);

  /* Octal */
  CONVERT("0100", NUMPRS_HEX_OCT);
  EXPECT(1,NUMPRS_HEX_OCT,0,4,0,2);
  EXPECTRGB(0,1);
1489 1490
  EXPECTRGB(1,0);
  EXPECTRGB(2,0);
1491 1492
  EXPECTRGB(3,FAILDIG);

1493 1494 1495 1496 1497 1498 1499 1500 1501 1502
  /* VB hex */
  CONVERT("&HF800", NUMPRS_HEX_OCT);
  EXPECT(4,NUMPRS_HEX_OCT,0x40,6,4,0);
  EXPECTRGB(0,15);
  EXPECTRGB(1,8);
  EXPECTRGB(2,0);
  EXPECTRGB(3,0);
  EXPECTRGB(4,FAILDIG);

  /* VB hex lower case and leading zero */
1503 1504
  CONVERT("&h0abcdef", NUMPRS_HEX_OCT);
  EXPECT(6,NUMPRS_HEX_OCT,0x40,9,4,0);
1505 1506 1507 1508
  EXPECTRGB(0,10);
  EXPECTRGB(1,11);
  EXPECTRGB(2,12);
  EXPECTRGB(3,13);
1509 1510 1511
  EXPECTRGB(4,14);
  EXPECTRGB(5,15);
  EXPECTRGB(6,FAILDIG);
1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530

  /* VB oct */
  CONVERT("&O300", NUMPRS_HEX_OCT);
  EXPECT(3,NUMPRS_HEX_OCT,0x40,5,3,0);
  EXPECTRGB(0,3);
  EXPECTRGB(1,0);
  EXPECTRGB(2,0);
  EXPECTRGB(3,FAILDIG);

  /* VB oct lower case and leading zero */
  CONVERT("&o0777", NUMPRS_HEX_OCT);
  EXPECT(3,NUMPRS_HEX_OCT,0x40,6,3,0);
  EXPECTRGB(0,7);
  EXPECTRGB(1,7);
  EXPECTRGB(2,7);
  EXPECTRGB(3,FAILDIG);

  /* VB oct char bigger than 7 */
  CONVERT("&o128", NUMPRS_HEX_OCT);
1531 1532 1533 1534 1535
  EXPECT(2,NUMPRS_HEX_OCT,0x40,4,3,0);
  EXPECTRGB(0,1);
  EXPECTRGB(1,2);
  EXPECTRGB(3,FAILDIG);

1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639
  /** NUMPRS_PARENS **/

  /* Empty parens = error */
  CONVERT("()", NUMPRS_PARENS);
  EXPECTFAIL;
  EXPECTRGB(0,FAILDIG);

  /* With flag, trailing parens not consumed */
  CONVERT("0()", NUMPRS_PARENS);
  EXPECT(1,NUMPRS_PARENS,0,1,0,0);
  EXPECT2(0,FAILDIG);

  /* With flag, Number in parens made negative and parens consumed */
  CONVERT("(0)", NUMPRS_PARENS);
  EXPECT(1,NUMPRS_PARENS,NUMPRS_NEG|NUMPRS_PARENS,3,0,0);
  EXPECT2(0,FAILDIG);

  /** NUMPRS_THOUSANDS **/

  /* With flag, thousands sep. not needed */
  CONVERT("0", NUMPRS_THOUSANDS);
  EXPECT(1,NUMPRS_THOUSANDS,0,1,0,0);
  EXPECT2(0,FAILDIG);

  /* With flag, thousands sep. and following digits consumed */
  CONVERT("1,000", NUMPRS_THOUSANDS);
  EXPECT(1,NUMPRS_THOUSANDS,NUMPRS_THOUSANDS,5,0,3);
  EXPECTRGB(0,1);

  /* With flag and decimal point, thousands sep. but not decimals consumed */
  CONVERT("1,000.0", NUMPRS_THOUSANDS);
  EXPECT(1,NUMPRS_THOUSANDS,NUMPRS_THOUSANDS,5,0,3);
  EXPECTRGB(0,1);

  /** NUMPRS_CURRENCY **/

  /* Without flag, chokes on currency sign */
  CONVERT("$11", 0);
  EXPECTFAIL;
  EXPECTRGB(0,FAILDIG);

  /* With flag, consumes currency sign */
  CONVERT("$11", NUMPRS_CURRENCY);
  EXPECT(2,NUMPRS_CURRENCY,NUMPRS_CURRENCY,3,0,0);
  EXPECT2(1,1);
  EXPECTRGB(2,FAILDIG);

  /* With flag only, doesn't consume decimal point */
  CONVERT("$11.1", NUMPRS_CURRENCY);
  EXPECT(2,NUMPRS_CURRENCY,NUMPRS_CURRENCY,3,0,0);
  EXPECT2(1,1);
  EXPECTRGB(2,FAILDIG);

  /* With flag and decimal flag, consumes decimal point and following digits */
  CONVERT("$11.1", NUMPRS_CURRENCY|NUMPRS_DECIMAL);
  EXPECT(3,NUMPRS_CURRENCY|NUMPRS_DECIMAL,NUMPRS_CURRENCY|NUMPRS_DECIMAL,5,0,-1);
  EXPECT2(1,1);
  EXPECTRGB(2,1);
  EXPECTRGB(3,FAILDIG);

  /* Thousands flag can only be used with currency */
  CONVERT("$1,234", NUMPRS_CURRENCY|NUMPRS_THOUSANDS);
  EXPECT(4,NUMPRS_CURRENCY|NUMPRS_THOUSANDS,NUMPRS_CURRENCY|NUMPRS_THOUSANDS,6,0,0);
  EXPECT2(1,2);
  EXPECTRGB(2,3);
  EXPECTRGB(3,4);
  EXPECTRGB(4,FAILDIG);

  /** NUMPRS_DECIMAL **/

  /* With flag, consumes decimal point */
  CONVERT("1.1", NUMPRS_DECIMAL);
  EXPECT(2,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1);
  EXPECT2(1,1);
  EXPECTRGB(2,FAILDIG);

  /* With flag, consumes decimal point. Skipping the decimal part is not an error */
  CONVERT("1.", NUMPRS_DECIMAL);
  EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,2,0,0);
  EXPECT2(1,FAILDIG);

  /* Consumes only one decimal point */
  CONVERT("1.1.", NUMPRS_DECIMAL);
  EXPECT(2,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1);
  EXPECT2(1,1);
  EXPECTRGB(2,FAILDIG);

  /** NUMPRS_EXPONENT **/

  /* Without flag, doesn't consume exponent */
  CONVERT("1e1", 0);
  EXPECT(1,0,0,1,0,0);
  EXPECT2(1,FAILDIG);

  /* With flag, consumes exponent */
  CONVERT("1e1", NUMPRS_EXPONENT);
  EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,1);
  EXPECT2(1,FAILDIG);

  /* Negative exponents are accepted without flags */
  CONVERT("1e-1", NUMPRS_EXPONENT);
  EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,-1);
  EXPECT2(1,FAILDIG);

1640
  /* As are positive exponents and leading exponent 0s */
1641 1642 1643 1644
  CONVERT("1e+01", NUMPRS_EXPONENT);
  EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,5,0,1);
  EXPECT2(1,FAILDIG);

1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658
  /* The same for zero exponents */
  CONVERT("1e0", NUMPRS_EXPONENT);
  EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,0);
  EXPECT2(1,FAILDIG);

  /* Sign on a zero exponent doesn't matter */
  CONVERT("1e+0", NUMPRS_EXPONENT);
  EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,0);
  EXPECT2(1,FAILDIG);

  CONVERT("1e-0", NUMPRS_EXPONENT);
  EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,0);
  EXPECT2(1,FAILDIG);

1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691
  /* Doesn't consume a real number exponent */
  CONVERT("1e1.", NUMPRS_EXPONENT);
  EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,1);
  EXPECT2(1,FAILDIG);

  /* Powers of 10 are calculated from the position of any decimal point */
  CONVERT("1.5e20", NUMPRS_EXPONENT|NUMPRS_DECIMAL);
  EXPECT(2,NUMPRS_EXPONENT|NUMPRS_DECIMAL,NUMPRS_EXPONENT|NUMPRS_DECIMAL,6,0,19);
  EXPECT2(1,5);

  CONVERT("1.5e-20", NUMPRS_EXPONENT|NUMPRS_DECIMAL);
  EXPECT(2,NUMPRS_EXPONENT|NUMPRS_DECIMAL,NUMPRS_EXPONENT|NUMPRS_DECIMAL,7,0,-21);
  EXPECT2(1,5);

  /** NUMPRS_USE_ALL **/

  /* Flag expects all digits */
  CONVERT("0", NUMPRS_USE_ALL);
  EXPECT(1,NUMPRS_USE_ALL,0,1,0,0);
  EXPECT2(0,FAILDIG);

  /* Rejects anything trailing */
  CONVERT("0 ", NUMPRS_USE_ALL);
  EXPECTFAIL;
  EXPECT2(0,FAILDIG);

  /* Unless consumed by trailing flag */
  CONVERT("0 ", NUMPRS_USE_ALL|NUMPRS_TRAILING_WHITE);
  EXPECT(1,NUMPRS_USE_ALL|NUMPRS_TRAILING_WHITE,NUMPRS_TRAILING_WHITE,2,0,0);
  EXPECT2(0,FAILDIG);

  /** Combinations **/

1692
  /* Leading whitespace and plus, doesn't consume trailing whitespace */
1693 1694 1695 1696
  CONVERT("+ 0 ", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
  EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,3,0,0);
  EXPECT2(0,FAILDIG);

1697
  /* Order of whitespace and plus is unimportant */
1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720
  CONVERT(" +0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
  EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,3,0,0);
  EXPECT2(0,FAILDIG);

  /* Leading whitespace can be repeated */
  CONVERT(" + 0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
  EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,4,0,0);
  EXPECT2(0,FAILDIG);

  /* But plus/minus etc. cannot */
  CONVERT("+ +0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
  EXPECTFAIL;
  EXPECTRGB(0,FAILDIG);

  /* Inexact is not set if trailing zeros are removed */
  CONVERTN("10", 1, 0);
  EXPECT(1,0,0,2,0,1);
  EXPECT2(1,FAILDIG);

  /* Make sure a leading 0 is stripped but decimals after it get read */
  CONVERT("-0.51", NUMPRS_STD);
  EXPECT(2,NUMPRS_STD,NUMPRS_NEG|NUMPRS_DECIMAL|NUMPRS_LEADING_MINUS,5,0,-2);
  EXPECT2(5,1);
1721 1722

  /* Keep trailing zeros on whole number part of a decimal */
1723
  CONVERT("10.1", NUMPRS_STD);
1724
  EXPECT(3,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-1);
1725
  EXPECT2(1,0);
1726
  EXPECTRGB(2,1);
1727 1728 1729 1730 1731 1732 1733 1734 1735 1736

  /* Zeros after decimal sign */
  CONVERT("0.01", NUMPRS_STD);
  EXPECT(1,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-2);
  EXPECT2(1,FAILDIG);

  /* Trailing zeros after decimal part */
  CONVERT("0.10", NUMPRS_STD);
  EXPECT(1,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-1);
  EXPECT2(1,0);
1737 1738
}

1739 1740
static HRESULT (WINAPI *pVarNumFromParseNum)(NUMPARSE*,BYTE*,ULONG,VARIANT*);

1741 1742 1743 1744 1745
/* Macros for converting and testing the result of VarNumFromParseNum */
#define SETRGB(indx,val) if (!indx) memset(rgb, FAILDIG, sizeof(rgb)); rgb[indx] = val
#undef CONVERT
#define CONVERT(a,b,c,d,e,f,bits) \
    np.cDig = (a); np.dwInFlags = (b); np.dwOutFlags = (c); np.cchUsed = (d); \
1746
    np.nBaseShift = (e); np.nPwr10 = (f); hres = pVarNumFromParseNum(&np, rgb, bits, &vOut)
1747
static const char *szFailOverflow = "Expected overflow, hres = %08x\n";
1748
#define EXPECT_OVERFLOW ok(hres == (HRESULT)DISP_E_OVERFLOW, szFailOverflow, hres)
1749
static const char *szFailOk = "Call failed, hres = %08x\n";
1750
#define EXPECT_OK ok(hres == (HRESULT)S_OK, szFailOk, hres); \
1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761
  if (hres == (HRESULT)S_OK)
#define EXPECT_TYPE(typ) ok(V_VT(&vOut) == typ,"Expected Type = " #typ ", got %d\n", V_VT(&vOut))
#define EXPECT_I1(val) EXPECT_OK { EXPECT_TYPE(VT_I1); \
  ok(V_I1(&vOut) == val, "Expected i1 = %d, got %d\n", (signed char)val, V_I1(&vOut)); }
#define EXPECT_UI1(val) EXPECT_OK { EXPECT_TYPE(VT_UI1); \
  ok(V_UI1(&vOut) == val, "Expected ui1 = %d, got %d\n", (BYTE)val, V_UI1(&vOut)); }
#define EXPECT_I2(val) EXPECT_OK { EXPECT_TYPE(VT_I2); \
  ok(V_I2(&vOut) == val, "Expected i2 = %d, got %d\n", (SHORT)val, V_I2(&vOut)); }
#define EXPECT_UI2(val) EXPECT_OK { EXPECT_TYPE(VT_UI2); \
  ok(V_UI2(&vOut) == val, "Expected ui2 = %d, got %d\n", (USHORT)val, V_UI2(&vOut)); }
#define EXPECT_I4(val) EXPECT_OK { EXPECT_TYPE(VT_I4); \
1762
  ok(V_I4(&vOut) == val, "Expected i4 = %d, got %d\n", (LONG)val, V_I4(&vOut)); }
1763
#define EXPECT_UI4(val) EXPECT_OK { EXPECT_TYPE(VT_UI4); \
1764
  ok(V_UI4(&vOut) == val, "Expected ui4 = %d, got %d\n", (ULONG)val, V_UI4(&vOut)); }
1765
#define EXPECT_I8(high,low) EXPECT_OK { EXPECT_TYPE(VT_I8); \
1766
  ok(V_I8(&vOut) == ((((ULONG64)(high))<<32)|(low)), "Expected i8 = %x%08x, got %x%08x\n", \
1767
     (LONG)(high), (LONG)(low), (LONG)(V_I8(&vOut)>>32), (LONG)V_I8(&vOut) ); }
1768
#define EXPECT_UI8(val) EXPECT_OK { EXPECT_TYPE(VT_UI8); \
1769
  ok(V_UI8(&vOut) == val, "Expected ui8 = 0x%x%08x, got 0x%x%08x\n", \
1770
      (DWORD)((ULONG64)val >> 32), (DWORD)(ULONG64)val, (DWORD)(V_UI8(&vOut) >> 32), (DWORD)V_UI8(&vOut)); }
1771 1772 1773 1774 1775 1776
#define EXPECT_R4(val) EXPECT_OK { EXPECT_TYPE(VT_R4); \
  ok(V_R4(&vOut) == val, "Expected r4 = %f, got %f\n", val, V_R4(&vOut)); }
#define EXPECT_R8(val) EXPECT_OK { EXPECT_TYPE(VT_R8); \
  ok(V_R8(&vOut) == val, "Expected r8 = %g, got %g\n", val, V_R8(&vOut)); }
#define CY_MULTIPLIER 10000
#define EXPECT_CY(val) EXPECT_OK { EXPECT_TYPE(VT_CY); \
1777
  ok(V_CY(&vOut).int64 == (LONG64)(val * CY_MULTIPLIER), "Expected r8 = 0x%x%08x, got 0x%x%08x\n", \
1778
      (DWORD)((LONG64)val >> 23), (DWORD)(LONG64)val, (DWORD)(V_CY(&vOut).int64 >>32), (DWORD)V_CY(&vOut).int64); }
1779
#define EXPECT_DECIMAL(valHi, valMid, valLo) EXPECT_OK { EXPECT_TYPE(VT_DECIMAL); \
1780 1781
      ok((V_DECIMAL(&vOut).Hi32 == valHi) && (S1(U1(V_DECIMAL(&vOut))).Mid32 == valMid) && \
      (S1(U1(V_DECIMAL(&vOut))).Lo32 == valLo),                      \
1782
  "Expected decimal = %x/0x%x%08x, got %x/0x%x%08x\n", valHi, valMid, valLo, \
1783
      V_DECIMAL(&vOut).Hi32, S1(U1(V_DECIMAL(&vOut))).Mid32, S1(U1(V_DECIMAL(&vOut))).Lo32); }
1784 1785 1786 1787 1788 1789 1790 1791

static void test_VarNumFromParseNum(void)
{
  HRESULT hres;
  NUMPARSE np;
  BYTE rgb[128];
  VARIANT vOut;

1792 1793
  CHECKPTR(VarNumFromParseNum);
    
1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841
  /* Convert the number 1 to different types */
  SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I1); EXPECT_I1(1);
  SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_UI1); EXPECT_UI1(1);
  /* Prefers a signed type to unsigned of the same size */
  SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I1|VTBIT_UI1); EXPECT_I1(1);
  /* But takes the smaller size if possible */
  SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I2|VTBIT_UI1); EXPECT_UI1(1);

  /* Try different integer sizes */
#define INTEGER_VTBITS (VTBIT_I1|VTBIT_UI1|VTBIT_I2|VTBIT_UI2|VTBIT_I4|VTBIT_UI4|VTBIT_I8|VTBIT_UI8)

  SETRGB(0, 1); CONVERT(1,0,0,1,0,0, INTEGER_VTBITS); EXPECT_I1(1);
  /* 127 */
  SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 7);
  CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_I1(127);
  /* 128 */
  SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 8);
  CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_UI1(128);
  /* 255 */
  SETRGB(0, 2); SETRGB(1, 5); SETRGB(2, 5);
  CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_UI1(255);
  /* 256 */
  SETRGB(0, 2); SETRGB(1, 5); SETRGB(2, 6);
  CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_I2(256);
  /* 32767 */
  SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 7);
  CONVERT(5,0,0,5,0,0, INTEGER_VTBITS); EXPECT_I2(32767);
  /* 32768 */
  SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 8);
  CONVERT(5,0,0,5,0,0, INTEGER_VTBITS); EXPECT_UI2(32768);

  /* Assume the above pattern holds for remaining positive integers; test negative */

  /* -128 */
  SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 8);
  CONVERT(3,0,NUMPRS_NEG,3,0,0, INTEGER_VTBITS); EXPECT_I1(-128);
  /* -129 */
  SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 9);
  CONVERT(3,0,NUMPRS_NEG,3,0,0, INTEGER_VTBITS); EXPECT_I2(-129);
  /* -32768 */
  SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 8);
  CONVERT(5,0,NUMPRS_NEG,5,0,0, INTEGER_VTBITS); EXPECT_I2(-32768);
  /* -32768 */
  SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 9);
  CONVERT(5,0,NUMPRS_NEG,5,0,0, INTEGER_VTBITS); EXPECT_I4(-32769);

  /* Assume the above pattern holds for remaining negative integers */

1842 1843 1844 1845 1846
  /* Test hexadecimal conversions */
  SETRGB(0, 1); CONVERT(1,0,0,1,4,0, INTEGER_VTBITS); EXPECT_I1(0x01);
  /* 0x7f */
  SETRGB(0, 7); SETRGB(1, 0xf);
  CONVERT(2,0,0,2,4,0, INTEGER_VTBITS); EXPECT_I1(0x7f);
1847 1848
  SETRGB(0, 7); SETRGB(1, 0xf);
  CONVERT(2,0,0,2,4,0, VTBIT_DECIMAL); EXPECT_DECIMAL(0,0,0x7f);
1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860
  /* 0x7fff */
  SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
  CONVERT(4,0,0,4,4,0, INTEGER_VTBITS); EXPECT_I2(0x7fff);
  /* 0x7fffffff */
  SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
  SETRGB(4, 0xf); SETRGB(5, 0xf); SETRGB(6, 0xf); SETRGB(7, 0xf);
  CONVERT(8,0,0,8,4,0, INTEGER_VTBITS); EXPECT_I4(0x7fffffffL);
  /* 0x7fffffffffffffff (64 bits) */
  SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
  SETRGB(4, 0xf); SETRGB(5, 0xf); SETRGB(6, 0xf); SETRGB(7, 0xf);
  SETRGB(8, 0xf); SETRGB(9, 0xf); SETRGB(10, 0xf); SETRGB(11, 0xf);
  SETRGB(12, 0xf); SETRGB(13, 0xf); SETRGB(14, 0xf); SETRGB(15, 0xf);
1861
  if (has_i8)
Richard Cohen's avatar
Richard Cohen committed
1862
  {
1863 1864 1865 1866
    /* We cannot use INTEGER_VTBITS as WinXP and Win2003 are broken(?). They
       truncate the number to the smallest integer size requested:
       CONVERT(16,0,0,16,4,0, INTEGER_VTBITS); EXPECT_I1((signed char)0xff); */
    CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x7fffffff,0xffffffff);
Richard Cohen's avatar
Richard Cohen committed
1867
  }
1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880

  /* Assume the above pattern holds for numbers without hi-bit set, test (preservation of) hi-bit */
  /* 0x82 */
  SETRGB(0, 8); SETRGB(1, 2);
  CONVERT(2,0,0,2,4,0, INTEGER_VTBITS);
  EXPECT_I1((signed char)0x82);
  /* 0x8002 */
  SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 2);
  CONVERT(4,0,0,4,4,0, INTEGER_VTBITS);
  EXPECT_I2((signed short)0x8002);
  /* 0x80000002 */
  SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
  SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 2);
1881
  CONVERT(8,0,0,8,4,0, INTEGER_VTBITS); EXPECT_I4(0x80000002);
1882 1883 1884 1885 1886
  /* 0x8000000000000002 (64 bits) */
  SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
  SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 0);
  SETRGB(8, 0); SETRGB(9, 0); SETRGB(10, 0); SETRGB(11, 0);
  SETRGB(12, 0); SETRGB(13, 0); SETRGB(14, 0); SETRGB(15, 2);
1887
  if (has_i8)
Richard Cohen's avatar
Richard Cohen committed
1888
  {
1889 1890 1891 1892 1893
    /* We cannot use INTEGER_VTBITS as WinXP and Win2003 are broken(?). They
       truncate the number to the smallest integer size requested:
       CONVERT(16,0,0,16,4,0, INTEGER_VTBITS & ~VTBIT_I1);
       EXPECT_I2((signed short)0x0002); */
    CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x80000000,0x00000002);
Richard Cohen's avatar
Richard Cohen committed
1894
  }
1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907

  /* Test (preservation of) hi-bit with STRICT type requesting */
  /* 0x82 */
  SETRGB(0, 8); SETRGB(1, 2);
  CONVERT(2,0,0,2,4,0, VTBIT_I1);
  EXPECT_I1((signed char)0x82);
  /* 0x8002 */
  SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 2);
  CONVERT(4,0,0,4,4,0, VTBIT_I2);
  EXPECT_I2((signed short)0x8002);
  /* 0x80000002 */
  SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
  SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 2);
1908
  CONVERT(8,0,0,8,4,0, VTBIT_I4); EXPECT_I4(0x80000002);
1909 1910 1911 1912 1913
  /* 0x8000000000000002 (64 bits) */
  SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
  SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 0);
  SETRGB(8, 0); SETRGB(9, 0); SETRGB(10, 0); SETRGB(11, 0);
  SETRGB(12, 0); SETRGB(13, 0); SETRGB(14, 0); SETRGB(15, 2);
1914
  if (has_i8)
Richard Cohen's avatar
Richard Cohen committed
1915 1916 1917
  {
    CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x80000000,0x00000002);
  }
1918 1919
  /* Assume the above pattern holds for numbers with hi-bit set */

1920 1921 1922 1923 1924 1925 1926 1927 1928 1929
  /* Negative numbers overflow if we have only unsigned outputs */
  /* -1 */
  SETRGB(0, 1); CONVERT(1,0,NUMPRS_NEG,1,0,0, VTBIT_UI1); EXPECT_OVERFLOW;
  /* -0.6 */
  SETRGB(0, 6); CONVERT(1,0,NUMPRS_NEG,1,0,~0u, VTBIT_UI1); EXPECT_OVERFLOW;

  /* Except that rounding is done first, so -0.5 to 0 are accepted as 0 */
  /* -0.5 */
  SETRGB(0, 5); CONVERT(1,0,NUMPRS_NEG,1,0,~0u, VTBIT_UI1); EXPECT_UI1(0);

1930 1931 1932 1933 1934
  /* Floating point zero is OK */
  /* 0.00000000E0 */
  SETRGB(0, 0); CONVERT(1,0,NUMPRS_DECIMAL|NUMPRS_EXPONENT,12,0,-8, VTBIT_R8);
  EXPECT_R8(0.0);

1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951
  /* Float is acceptable for an integer input value */
  SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R4); EXPECT_R4(1.0f);
  /* As is double */
  SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R8); EXPECT_R8(1.0);
  /* As is currency */
  SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_CY); EXPECT_CY(1);

  /* Float is preferred over double */
  SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R4|VTBIT_R8); EXPECT_R4(1.0f);

  /* Double is preferred over currency */
  SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R8|VTBIT_CY); EXPECT_R8(1.0);

  /* Currency is preferred over decimal */
  SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_CY|VTBIT_DECIMAL); EXPECT_CY(1);
}

1952

1953 1954
static void test_UdateFromDate( int line, DATE dt, ULONG flags, HRESULT r, WORD d, WORD m, WORD y,
                                WORD h, WORD mn, WORD s, WORD ms, WORD dw, WORD dy)
1955
{
1956 1957 1958 1959 1960
    UDATE ud;
    HRESULT res;

    memset(&ud, 0, sizeof(ud));
    res = pVarUdateFromDate(dt, flags, &ud);
1961
    ok_(__FILE__,line)(r == res && (res != S_OK || (ud.st.wYear == y && ud.st.wMonth == m && ud.st.wDay == d &&
1962 1963 1964 1965 1966 1967
                       ud.st.wHour == h && ud.st.wMinute == mn && ud.st.wSecond == s &&
                       ud.st.wMilliseconds == ms && ud.st.wDayOfWeek == dw && ud.wDayOfYear == dy)),
                       "%.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",
                       dt, r, d, m, y, h, mn, s, ms, dw, dy,
                       res, ud.st.wDay, ud.st.wMonth, ud.st.wYear, ud.st.wHour, ud.st.wMinute,
                       ud.st.wSecond, ud.st.wMilliseconds, ud.st.wDayOfWeek, ud.wDayOfYear );
1968 1969
}
#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)
1970

1971 1972
static void test_VarUdateFromDate(void)
{
1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992
  CHECKPTR(VarUdateFromDate);
  DT2UD(29221.0,0,S_OK,1,1,1980,0,0,0,0,2,1);        /* 1 Jan 1980 */
  DT2UD(29222.0,0,S_OK,2,1,1980,0,0,0,0,3,2);        /* 2 Jan 1980 */
  DT2UD(33238.0,0,S_OK,31,12,1990,0,0,0,0,1,365);    /* 31 Dec 1990 */
  DT2UD(0.0,0,S_OK,30,12,1899,0,0,0,0,6,364);        /* 30 Dec 1899 - VT_DATE 0.0 */
  DT2UD(-657434.0,0,S_OK,1,1,100,0,0,0,0,5,1);       /* 1 Jan 100 - Min */
  DT2UD(-657435.0,0,E_INVALIDARG,0,0,0,0,0,0,0,0,0); /* < 1 Jan 100 => err */
  DT2UD(2958465.0,0,S_OK,31,12,9999,0,0,0,0,5,365);  /* 31 Dec 9999 - Max */
  DT2UD(2958466.0,0,E_INVALIDARG,0,0,0,0,0,0,0,0,0); /* > 31 Dec 9999 => err  */

  /* VAR_VALIDDATE doesn't prevent upper and lower bounds being checked */
  DT2UD(-657435.0,VAR_VALIDDATE,E_INVALIDARG,0,0,0,0,0,0,0,0,0);
  DT2UD(2958466.0,VAR_VALIDDATE,E_INVALIDARG,0,0,0,0,0,0,0,0,0);

  /* Times */
  DT2UD(29221.25,0,S_OK,1,1,1980,6,0,0,0,2,1);           /* 6 AM */
  DT2UD(29221.33333333,0,S_OK,1,1,1980,8,0,0,0,2,1);     /* 8 AM */
  DT2UD(29221.5,0,S_OK,1,1,1980,12,0,0,0,2,1);           /* 12 AM */
  DT2UD(29221.9888884444,0,S_OK,1,1,1980,23,44,0,0,2,1); /* 11:44 PM */
  DT2UD(29221.7508765432,0,S_OK,1,1,1980,18,1,16,0,2,1); /* 6:18:02 PM */
1993 1994

  /* Test handling of times on dates prior to the epoch */
1995 1996
  DT2UD(-5.25,0,S_OK,25,12,1899,6,0,0,0,1,359);
  DT2UD(-5.9999884259259,0,S_OK,25,12,1899,23,59,59,0,1,359);
1997
  /* This just demonstrates the non-linear nature of values prior to the epoch */
1998
  DT2UD(-4.0,0,S_OK,26,12,1899,0,0,0,0,2,360);
1999
  /* Numerical oddity: for 0.0 < x < 1.0, x and -x represent the same datetime */
2000
  DT2UD(-0.25,0,S_OK,30,12,1899,6,0,0,0,6,364);
2001
  DT2UD(0.25,0,S_OK,30,12,1899,6,0,0,0,6,364);
2002 2003 2004
}


2005 2006
static void test_DateFromUDate( int line, WORD d, WORD m, WORD y, WORD h, WORD mn, WORD s, WORD ms,
                                WORD dw, WORD dy, ULONG flags, HRESULT r, DATE dt )
2007
{
2008 2009 2010 2011
    UDATE ud;
    double out;
    HRESULT res;

2012 2013 2014 2015 2016 2017 2018 2019 2020
    ud.st.wYear = y;
    ud.st.wMonth = m;
    ud.st.wDay = d;
    ud.st.wHour = h;
    ud.st.wMinute = mn;
    ud.st.wSecond = s;
    ud.st.wMilliseconds = ms;
    ud.st.wDayOfWeek = dw;
    ud.wDayOfYear = dy;
2021
    res = pVarDateFromUdate(&ud, flags, &out);
2022
    ok_(__FILE__,line)(r == res && (r != S_OK || EQ_DOUBLE(out, dt)),
2023 2024 2025
                       "expected %x, %.16g, got %x, %.16g\n", r, dt, res, out);
}
#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)
2026

2027 2028
static void test_VarDateFromUdate(void)
{
2029 2030 2031
  CHECKPTR(VarDateFromUdate);
  UD2T(1,1,1980,0,0,0,0,2,1,0,S_OK,29221.0);      /* 1 Jan 1980 */
  UD2T(2,1,1980,0,0,0,0,3,2,0,S_OK,29222.0);      /* 2 Jan 1980 */
2032
  UD2T(2,1,1980,0,0,0,0,4,5,0,S_OK,29222.0);      /* 2 Jan 1980 */
2033 2034 2035 2036 2037 2038
  UD2T(31,12,1990,0,0,0,0,0,0,0,S_OK,33238.0);    /* 31 Dec 1990 */
  UD2T(31,12,90,0,0,0,0,0,0,0,S_OK,33238.0);      /* year < 100 is 1900+year! */
  UD2T(30,12,1899,0,0,0,0,6,364,0,S_OK,0.0);      /* 30 Dec 1899 - VT_DATE 0.0 */
  UD2T(1,1,100,0,0,0,0,0,0,0,S_OK,-657434.0);     /* 1 Jan 100 - Min */
  UD2T(31,12,9999,0,0,0,0,0,0,0,S_OK,2958465.0);  /* 31 Dec 9999 - Max */
  UD2T(1,1,10000,0,0,0,0,0,0,0,E_INVALIDARG,0.0); /* > 31 Dec 9999 => err  */
2039
  UD2T(1,1,-10000,0,0,0,0,0,0,0,E_INVALIDARG,0.0);/* < -9999 => err  */
2040

2041 2042 2043
  UD2T(30,12,1899,0,0,0,0,0,0,0,S_OK,0.0); /* 30 Dec 1899 0:00:00  */
  UD2T(30,12,1899,0,0,0,999,0,0,0,S_OK,0.0); /* Ignore milliseconds  */

2044
  UD2T(1,1,1980,18,1,16,0,2,1,0,S_OK,29221.75087962963);             /* 6:18:02 PM */
2045 2046
  UD2T(1,300,1980,18,1,16,0,2,1,0,S_OK,38322.75087962963);           /* Test fwdrolled month */
  UD2T(300,1,1980,18,1,16,0,2,1,0,S_OK,29520.75087962963);           /* Test fwdrolled days */
2047 2048 2049
  UD2T(0,1,1980,42,1,16,0,2,1,0,S_OK,29221.75087962963);             /* Test fwdrolled hours */
  UD2T(1,1,1980,17,61,16,0,2,1,0,S_OK,29221.75087962963);            /* Test fwdrolled minutes */
  UD2T(1,1,1980,18,0,76,0,2,1,0,S_OK,29221.75087962963);             /* Test fwdrolled seconds */
2050 2051
  UD2T(1,-300,1980,18,1,16,0,2,1,0,S_OK,20059.75087962963);          /* Test backrolled month */
  UD2T(-300,1,1980,18,1,16,0,2,1,0,S_OK,28920.75087962963);          /* Test backrolled days */
2052 2053 2054 2055 2056
  UD2T(3,1,1980,-30,1,16,0,2,1,0,S_OK,29221.75087962963);            /* Test backrolled hours */
  UD2T(1,1,1980,20,-119,16,0,2,1,0,S_OK,29221.75087962963);          /* Test backrolled minutes */
  UD2T(1,1,1980,18,3,-104,0,2,1,0,S_OK,29221.75087962963);           /* Test backrolled seconds */
  UD2T(1,12001,-1020,18,1,16,0,0,0,0,S_OK,29221.75087962963);        /* Test rolled year and month */
  UD2T(1,-23,1982,18,1,16,0,0,0,0,S_OK,29221.75087962963);           /* Test backrolled month */
2057
  UD2T(-59,3,1980,18,1,16,0,0,0,0,S_OK,29221.75087962963);           /* Test backrolled days */
André Hentschel's avatar
André Hentschel committed
2058
  UD2T(1,1,0,0,0,0,0,0,0,0,S_OK,36526);                              /* Test zero year */
2059 2060 2061 2062 2063 2064
  UD2T(0,0,1980,0,0,0,0,0,0,0,S_OK,29189);                           /* Test zero day and month */
  UD2T(0,1,1980,0,0,0,0,2,1,0,S_OK,29220.0);                         /* Test zero day = LastDayOfMonth */
  UD2T(-1,1,1980,18,1,16,0,0,0,0,S_OK,29219.75087962963);            /* Test day -1 = LastDayOfMonth - 1 */
  UD2T(1,1,-1,18,1,16,0,0,0,0,S_OK,36161.75087962963);               /* Test year -1 = 1999 */
  UD2T(1,-1,1980,18,1,16,0,0,0,0,S_OK,29160.7508796296);             /* Test month -1 = 11 */
  UD2T(1,13,1980,0,0,0,0,2,1,0,S_OK,29587.0);                        /* Rolls fwd to 1/1/1981 */
2065 2066

  /* Test handling of times on dates prior to the epoch */
2067 2068
  UD2T(25,12,1899,6,0,0,0,1,359,0,S_OK,-5.25);
  UD2T(25,12,1899,23,59,59,0,1,359,0,S_OK,-5.9999884259259);
2069
  /* This just demonstrates the non-linear nature of values prior to the epoch */
2070
  UD2T(26,12,1899,0,0,0,0,2,360,0,S_OK,-4.0);
2071 2072 2073
  /* for DATE values 0.0 < x < 1.0, x and -x represent the same datetime */
  /* but when converting to DATE, prefer the positive versions */
  UD2T(30,12,1899,6,0,0,0,6,364,0,S_OK,0.25);
2074 2075 2076 2077 2078 2079

  UD2T(1,1,1980,18,1,16,0,2,1,VAR_TIMEVALUEONLY,S_OK,0.7508796296296296);
  UD2T(1,1,1980,18,1,16,0,2,1,VAR_DATEVALUEONLY,S_OK,29221.0);
  UD2T(25,12,1899,6,0,0,0,1,359,VAR_TIMEVALUEONLY,S_OK,0.25);
  UD2T(25,12,1899,6,0,0,0,1,359,VAR_DATEVALUEONLY,S_OK,-5.0);
  UD2T(1,-1,1980,18,1,16,0,0,0,VAR_TIMEVALUEONLY|VAR_DATEVALUEONLY,S_OK,0.7508796296296296);
2080 2081
}

2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101
static void test_st2dt(int line, WORD d, WORD m, WORD y, WORD h, WORD mn,
                       WORD s, WORD ms, INT r, double dt)
{
    SYSTEMTIME st;
    double out;
    INT res;

    st.wYear = y;
    st.wMonth = m;
    st.wDay = d;
    st.wHour = h;
    st.wMinute = mn;
    st.wSecond = s;
    st.wMilliseconds = ms;
    st.wDayOfWeek = 0;
    res = pSystemTimeToVariantTime(&st, &out);
    ok_(__FILE__,line)(r == res && (!r || EQ_DOUBLE(out, dt)),
                       "expected %d, %.16g, got %d, %.16g\n", r, dt, res, out);
}
#define ST2DT(d,m,y,h,mn,s,ms,r,dt) test_st2dt(__LINE__,d,m,y,h,mn,s,ms,r,dt)
2102 2103 2104 2105 2106 2107 2108 2109

static void test_SystemTimeToVariantTime(void)
{
  CHECKPTR(SystemTimeToVariantTime);
  ST2DT(1,1,1980,0,0,0,0,TRUE,29221.0);
  ST2DT(2,1,1980,0,0,0,0,TRUE,29222.0);
  ST2DT(0,1,1980,0,0,0,0,TRUE,29220.0);   /* Rolls back to 31 Dec 1899 */
  ST2DT(1,13,1980,0,0,0,0,FALSE,29587.0); /* Fails on invalid month */
2110 2111 2112 2113
  ST2DT(32,1,1980,0,0,0,0,FALSE,0.0);     /* Fails on invalid day */
  ST2DT(1,1,-1,0,0,0,0,FALSE,0.0);        /* Fails on invalid year */
  ST2DT(1,1,10000,0,0,0,0,FALSE,0.0);     /* Fails on invalid year */
  ST2DT(1,1,9999,0,0,0,0,TRUE,2958101.0); /* 9999 is last valid year */
2114 2115 2116 2117
  ST2DT(31,12,90,0,0,0,0,TRUE,33238.0);   /* 30 <= year < 100 is 1900+year */
  ST2DT(1,1,30,0,0,0,0,TRUE,10959.0);     /* 30 <= year < 100 is 1900+year */
  ST2DT(1,1,29,0,0,0,0,TRUE,47119.0);     /* 0 <= year < 30 is 2000+year */
  ST2DT(1,1,0,0,0,0,0,TRUE,36526.0);      /* 0 <= year < 30 is 2000+year */
2118 2119
}

2120 2121
static void test_dt2st(int line, double dt, INT r, WORD d, WORD m, WORD y,
                       WORD h, WORD mn, WORD s, WORD ms)
2122 2123
{
  SYSTEMTIME st;
2124
  INT res;
2125

2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140
  memset(&st, 0, sizeof(st));
  res = pVariantTimeToSystemTime(dt, &st);
  ok_(__FILE__,line)(r == res &&
                     (!r || (st.wYear == y && st.wMonth == m && st.wDay == d &&
                             st.wHour == h && st.wMinute == mn &&
                             st.wSecond == s && st.wMilliseconds == ms)),
                     "%.16g expected %d, %d,%d,%d,%d,%d,%d,%d, got %d, %d,%d,%d,%d,%d,%d,%d\n",
                     dt, r, d, m, y, h, mn, s, ms, res, st.wDay, st.wMonth,
                     st.wYear, st.wHour, st.wMinute, st.wSecond,
                     st.wMilliseconds);
}
#define DT2ST(dt,r,d,m,y,h,mn,s,ms) test_dt2st(__LINE__,dt,r,d,m,y,h,mn,s,ms)

static void test_VariantTimeToSystemTime(void)
{
2141 2142 2143 2144 2145 2146 2147 2148
  CHECKPTR(VariantTimeToSystemTime);
  DT2ST(29221.0,1,1,1,1980,0,0,0,0);
  DT2ST(29222.0,1,2,1,1980,0,0,0,0);
}

#define MKDOSDATE(d,m,y) ((d & 0x1f) | ((m & 0xf) << 5) | (((y-1980) & 0x7f) << 9))
#define MKDOSTIME(h,m,s) (((s>>1) & 0x1f) | ((m & 0x3f) << 5) | ((h & 0x1f) << 11))

2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163
static void test_dos2dt(int line, WORD d, WORD m, WORD y, WORD h, WORD mn,
                        WORD s, INT r, double dt)
{
    unsigned short dosDate, dosTime;
    double out;
    INT res;

    out = 0.0;
    dosDate = MKDOSDATE(d, m, y);
    dosTime = MKDOSTIME(h, mn, s);
    res = pDosDateTimeToVariantTime(dosDate, dosTime, &out);
    ok_(__FILE__,line)(r == res && (!r || EQ_DOUBLE(out, dt)),
                       "expected %d, %.16g, got %d, %.16g\n", r, dt, res, out);
}
#define DOS2DT(d,m,y,h,mn,s,r,dt) test_dos2dt(__LINE__,d,m,y,h,mn,s,r,dt)
2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189

static void test_DosDateTimeToVariantTime(void)
{
  CHECKPTR(DosDateTimeToVariantTime);

  /* Date */
  DOS2DT(1,1,1980,0,0,0,1,29221.0); /* 1/1/1980 */
  DOS2DT(31,12,2099,0,0,0,1,73050.0); /* 31/12/2099 */
  /* Dates are limited to the dos date max of 31/12/2099 */
  DOS2DT(31,12,2100,0,0,0,0,0.0); /* 31/12/2100 */
  /* Days and months of 0 cause date to roll back 1 day or month */
  DOS2DT(0,1,1980,0,0,0,1,29220.0); /* 0 Day => 31/12/1979 */
  DOS2DT(1,0,1980,0,0,0,1,29190.0); /* 0 Mth =>  1/12/1979 */
  DOS2DT(0,0,1980,0,0,0,1,29189.0); /* 0 D/M => 30/11/1979 */
  /* Days > days in the month cause date to roll forward 1 month */
  DOS2DT(29,2,1981,0,0,0,1,29646.0); /* 29/2/1981 -> 3/1/1980 */
  DOS2DT(30,2,1981,0,0,0,1,29647.0); /* 30/2/1981 -> 4/1/1980 */
  /* Takes leap years into account when rolling forward */
  DOS2DT(29,2,1980,0,0,0,1,29280.0); /* 2/29/1980 */
  /* Months > 12 cause an error */
  DOS2DT(2,13,1980,0,0,0,0,0.0);

  /* Time */
  DOS2DT(1,1,1980,0,0,29,1,29221.00032407407); /* 1/1/1980 12:00:28 AM */
  DOS2DT(1,1,1980,0,0,31,1,29221.00034722222); /* 1/1/1980 12:00:30 AM */
  DOS2DT(1,1,1980,0,59,0,1,29221.04097222222); /* 1/1/1980 12:59:00 AM */
2190 2191
  DOS2DT(1,1,1980,0,60,0,0,0.0);               /* Invalid minutes */
  DOS2DT(1,1,1980,0,0,60,0,0.0);               /* Invalid seconds */
2192 2193
  DOS2DT(1,1,1980,23,0,0,1,29221.95833333333); /* 1/1/1980 11:00:00 PM */
  DOS2DT(1,1,1980,24,0,0,0,0.0);               /* Invalid hours */
2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228

  DOS2DT(1,1,1980,0,0,1,1,29221.0);
  DOS2DT(2,1,1980,0,0,0,1,29222.0);
  DOS2DT(2,1,1980,0,0,0,1,29222.0);
  DOS2DT(31,12,1990,0,0,0,1,33238.0);
  DOS2DT(31,12,90,0,0,0,1,40543.0);
  DOS2DT(30,12,1899,0,0,0,1,46751.0);
  DOS2DT(1,1,100,0,0,0,1,43831.0);
  DOS2DT(31,12,9999,0,0,0,1,59901.0);
  DOS2DT(1,1,10000,0,0,0,1,59902.0);
  DOS2DT(1,1,-10000,0,0,0,1,48214.0);

  DOS2DT(30,12,1899,0,0,0,1,46751.0);
  DOS2DT(30,12,1899,0,0,1,1,46751.0);

  DOS2DT(1,1,1980,18,1,16,1,29221.75087962963);
  DOS2DT(1,300,1980,18,1,16,1,29556.75087962963);
  DOS2DT(300,1,1980,18,1,16,1,29232.75087962963);
  DOS2DT(0,1,1980,42,1,16,1,29220.4175462963);
  DOS2DT(1,1,1980,17,61,16,0,0.0);
  DOS2DT(1,1,1980,18,0,76,1,29221.75013888889);
  DOS2DT(1,-300,1980,18,1,16,1,29312.75087962963);
  DOS2DT(-300,1,1980,18,1,16,1,29240.75087962963);
  DOS2DT(3,1,1980,-30,1,16,1,29223.08421296296);
  DOS2DT(1,1,1980,20,-119,16,1,29221.83976851852);
  DOS2DT(1,1,1980,18,3,-104,1,29221.75236111111);
  DOS2DT(1,12001,-1020,18,1,16,1,55519.75087962963);
  DOS2DT(1,-23,1982,18,1,16,1,30195.75087962963);
  DOS2DT(-59,3,1980,18,1,16,1,29285.75087962963);
  DOS2DT(1,1,0,0,0,0,1,54058.0);
  DOS2DT(0,0,1980,0,0,0,1,29189.0);
  DOS2DT(0,1,1980,0,0,0,1,29220.0);
  DOS2DT(-1,1,1980,18,1,16,1,29251.75087962963);
  DOS2DT(1,1,-1,18,1,16,1,53693.75087962963);
  DOS2DT(1,-1,1980,18,1,16,0,0);
2229 2230
}

2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251
static void test_dt2dos(int line, double dt, INT r, WORD d, WORD m, WORD y,
                        WORD h, WORD mn, WORD s)
{
    unsigned short dosDate, dosTime, expDosDate, expDosTime;
    INT res;

    dosTime = dosDate = 0;
    expDosDate = MKDOSDATE(d,m,y);
    expDosTime = MKDOSTIME(h,mn,s);
    res = pVariantTimeToDosDateTime(dt, &dosDate, &dosTime);
    ok_(__FILE__,line)(r == res && (!r || (dosTime == expDosTime && dosDate == expDosDate)),
                       "%g: expected %d,%d(%d/%d/%d),%d(%d:%d:%d) got %d,%d(%d/%d/%d),%d(%d:%d:%d)\n",
                       dt, r, expDosDate, expDosDate & 0x1f,
                       (expDosDate >> 5) & 0xf, 1980 + (expDosDate >> 9),
                       expDosTime, expDosTime >> 11, (expDosTime >> 5) & 0x3f,
                       (expDosTime & 0x1f),
                       res, dosDate, dosDate & 0x1f, (dosDate >> 5) & 0xf,
                       1980 + (dosDate >> 9), dosTime, dosTime >> 11,
                       (dosTime >> 5) & 0x3f, (dosTime & 0x1f));
}
#define DT2DOS(dt,r,d,m,y,h,mn,s) test_dt2dos(__LINE__,dt,r,d,m,y,h,mn,s)
2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269

static void test_VariantTimeToDosDateTime(void)
{
  CHECKPTR(VariantTimeToDosDateTime);

  /* Date */
  DT2DOS(29221.0,1,1,1,1980,0,0,0);   /* 1/1/1980 */
  DT2DOS(73050.0,1,31,12,2099,0,0,0); /* 31/12/2099 */
  DT2DOS(29220.0,0,0,0,0,0,0,0);      /* 31/12/1979 - out of range */
  DT2DOS(73415.0,0,0,0,0,0,0,0);      /* 31/12/2100 - out of range */

  /* Time */
  DT2DOS(29221.00032407407,1,1,1,1980,0,0,29); /* 1/1/1980 12:00:28 AM */
  DT2DOS(29221.00034722222,1,1,1,1980,0,0,31); /* 1/1/1980 12:00:30 AM */
  DT2DOS(29221.04097222222,1,1,1,1980,0,59,0); /* 1/1/1980 12:59:00 AM */
  DT2DOS(29221.95833333333,1,1,1,1980,23,0,0); /* 1/1/1980 11:00:00 PM */
}

2270 2271
static HRESULT (WINAPI *pVarAbs)(LPVARIANT,LPVARIANT);

2272 2273 2274
#define VARABS(vt,val,rvt,rval)                  \
    V_VT(&v) = VT_##vt; V_##vt(&v) = val;        \
    V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
2275
    test_var_call1( __LINE__, pVarAbs, &v, &exp )
2276 2277 2278

static void test_VarAbs(void)
{
2279
    static WCHAR szNum[] = {'-','1','.','1','\0' };
2280
    char buff[8];
2281
    HRESULT hres;
2282
    VARIANT v, vDst, exp;
2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296
    size_t i;

    CHECKPTR(VarAbs);

    /* Test all possible V_VT values.
     */
    for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
    {
        VARTYPE vt;

        for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
        {
            HRESULT hExpected = DISP_E_BADVARTYPE;

2297 2298
            SKIPTESTS(vt);

2299 2300 2301 2302 2303
            memset(&v, 0, sizeof(v));
            V_VT(&v) = vt | ExtraFlags[i];
            V_VT(&vDst) = VT_EMPTY;

            hres = pVarAbs(&v,&vDst);
2304
            if (ExtraFlags[i] & VT_ARRAY ||
2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322
                (!ExtraFlags[i] && (vt == VT_UNKNOWN || vt == VT_BSTR ||
                 vt == VT_DISPATCH || vt == VT_ERROR || vt == VT_RECORD)))
            {
                hExpected = DISP_E_TYPEMISMATCH;
            }
            else if (ExtraFlags[i] || vt >= VT_CLSID || vt == VT_VARIANT)
            {
                hExpected = DISP_E_BADVARTYPE;
            }
            else if (IsValidVariantClearVT(vt, ExtraFlags[i]))
                hExpected = S_OK;

            /* Native always fails on some vartypes that should be valid. don't
             * check that Wine does the same; these are bugs in native.
             */
            if (vt == VT_I8 || vt == VT_UI8 || vt == VT_INT || vt == VT_UINT ||
                vt == VT_I1 || vt == VT_UI2 || vt == VT_UI4)
                continue;
2323
            ok(hres == hExpected, "VarAbs: expected 0x%X, got 0x%X for vt %d | 0x%X\n",
2324 2325 2326 2327 2328 2329 2330
               hExpected, hres, vt, ExtraFlags[i]);
        }
    }

    /* BOOL->I2, BSTR->R8, all others remain the same */
    VARABS(BOOL,VARIANT_TRUE,I2,-VARIANT_TRUE);
    VARABS(BOOL,VARIANT_FALSE,I2,VARIANT_FALSE);
2331 2332 2333 2334
    VARABS(EMPTY,0,I2,0);
    VARABS(EMPTY,1,I2,0);
    VARABS(NULL,0,NULL,0);
    VARABS(NULL,1,NULL,0);
2335 2336 2337 2338 2339 2340 2341 2342 2343
    VARABS(I2,1,I2,1);
    VARABS(I2,-1,I2,1);
    VARABS(I4,1,I4,1);
    VARABS(I4,-1,I4,1);
    VARABS(UI1,1,UI1,1);
    VARABS(R4,1,R4,1);
    VARABS(R4,-1,R4,1);
    VARABS(R8,1,R8,1);
    VARABS(R8,-1,R8,1);
2344 2345 2346 2347 2348 2349 2350
    VARABS(DATE,1,DATE,1);
    VARABS(DATE,-1,DATE,1);
    V_VT(&v) = VT_CY;
    V_CY(&v).int64 = -10000;
    memset(&vDst,0,sizeof(vDst));
    hres = pVarAbs(&v,&vDst);
    ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
2351
       "VarAbs(CY): expected 0x0 got 0x%X\n", hres);
2352
    GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char));
2353
    if (buff[1])
2354
    {
2355
        trace("Skipping VarAbs(BSTR) as decimal separator is '%s'\n", buff);
2356
        return;
2357 2358
    } else {
	szNum[2] = buff[0];
2359
    }
2360 2361 2362 2363 2364
    V_VT(&v) = VT_BSTR;
    V_BSTR(&v) = (BSTR)szNum;
    memset(&vDst,0,sizeof(vDst));
    hres = pVarAbs(&v,&vDst);
    ok(hres == S_OK && V_VT(&vDst) == VT_R8 && V_R8(&vDst) == 1.1,
2365
       "VarAbs: expected 0x0,%d,%g, got 0x%X,%d,%g\n", VT_R8, 1.1, hres, V_VT(&vDst), V_R8(&vDst));
2366 2367 2368 2369
}

static HRESULT (WINAPI *pVarNot)(LPVARIANT,LPVARIANT);

2370 2371 2372
#define VARNOT(vt,val,rvt,rval)                  \
    V_VT(&v) = VT_##vt; V_##vt(&v) = val;        \
    V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
2373
    test_var_call1( __LINE__, pVarNot, &v, &exp )
2374 2375 2376 2377 2378

static void test_VarNot(void)
{
    static const WCHAR szNum0[] = {'0','\0' };
    static const WCHAR szNum1[] = {'1','\0' };
2379 2380
    static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
    static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
2381
    HRESULT hres;
2382
    VARIANT v, exp, vDst;
2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397
    DECIMAL *pdec = &V_DECIMAL(&v);
    CY *pcy = &V_CY(&v);
    size_t i;

    CHECKPTR(VarNot);

    /* Test all possible V_VT values */
    for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
    {
        VARTYPE vt;

        for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
        {
            HRESULT hExpected = DISP_E_BADVARTYPE;

2398 2399
            SKIPTESTS(vt);

2400 2401 2402 2403 2404 2405 2406 2407
            memset(&v, 0, sizeof(v));
            V_VT(&v) = vt | ExtraFlags[i];
            V_VT(&vDst) = VT_EMPTY;

            switch (V_VT(&v))
            {
            case VT_I1:  case VT_UI1: case VT_I2:  case VT_UI2:
            case VT_INT: case VT_UINT: case VT_I4:  case VT_UI4:
2408
            case VT_R4:  case VT_R8:
2409 2410 2411 2412
            case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
            case VT_DATE: case VT_CY:
                hExpected = S_OK;
                break;
2413
            case VT_I8: case VT_UI8:
2414
                if (has_i8)
2415 2416
                    hExpected = S_OK;
                break;
2417
            case VT_RECORD:
2418
                hExpected = DISP_E_TYPEMISMATCH;
2419 2420
                break;
            case VT_UNKNOWN: case VT_BSTR: case VT_DISPATCH: case VT_ERROR:
2421 2422 2423 2424 2425 2426 2427 2428 2429
                hExpected = DISP_E_TYPEMISMATCH;
                break;
            default:
                if (IsValidVariantClearVT(vt, ExtraFlags[i]) && vt != VT_CLSID)
                   hExpected = DISP_E_TYPEMISMATCH;
                break;
            }

            hres = pVarNot(&v,&vDst);
2430
            ok(hres == hExpected, "VarNot: expected 0x%X, got 0x%X vt %d|0x%X\n",
2431
               hExpected, hres, vt, ExtraFlags[i]);
2432 2433
        }
    }
2434 2435 2436 2437 2438
    /* Test the values returned by all cases that can succeed */
    VARNOT(EMPTY,0,I2,-1);
    VARNOT(EMPTY,1,I2,-1);
    VARNOT(NULL,0,NULL,0);
    VARNOT(NULL,1,NULL,0);
2439 2440
    VARNOT(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
    VARNOT(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
2441 2442
    VARNOT(I1,-1,I4,0);
    VARNOT(I1,0,I4,-1);
2443 2444 2445 2446 2447 2448 2449
    VARNOT(I2,-1,I2,0);
    VARNOT(I2,0,I2,-1);
    VARNOT(I2,1,I2,-2);
    VARNOT(I4,1,I4,-2);
    VARNOT(I4,0,I4,-1);
    VARNOT(UI1,1,UI1,254);
    VARNOT(UI1,0,UI1,255);
2450 2451 2452 2453 2454 2455 2456 2457
    VARNOT(UI2,0,I4,-1);
    VARNOT(UI2,1,I4,-2);
    VARNOT(UI4,0,I4,-1);
    VARNOT(UI4,1,I4,-2);
    VARNOT(INT,0,I4,-1);
    VARNOT(INT,1,I4,-2);
    VARNOT(UINT,0,I4,-1);
    VARNOT(UINT,1,I4,-2);
2458
    if (has_i8)
2459 2460 2461 2462 2463 2464
    {
        VARNOT(I8,1,I8,-2);
        VARNOT(I8,0,I8,-1);
        VARNOT(UI8,0,I4,-1);
        VARNOT(UI8,1,I4,-2);
    }
2465 2466 2467 2468
    VARNOT(R4,1,I4,-2);
    VARNOT(R4,0,I4,-1);
    VARNOT(R8,1,I4,-2);
    VARNOT(R8,0,I4,-1);
2469 2470
    VARNOT(DATE,1,I4,-2);
    VARNOT(DATE,0,I4,-1);
2471
    VARNOT(BSTR,(BSTR)szNum0,I4,-1);
2472
    ok(V_VT(&v) == VT_BSTR && V_BSTR(&v) == szNum0, "VarNot(0): changed input\n");
2473
    VARNOT(BSTR,(BSTR)szNum1,I4,-2);
2474
    ok(V_VT(&v) == VT_BSTR && V_BSTR(&v) == szNum1, "VarNot(1): changed input\n");
2475 2476
    VARNOT(BSTR, (BSTR)szTrue, BOOL, VARIANT_FALSE);
    VARNOT(BSTR, (BSTR)szFalse, BOOL, VARIANT_TRUE);
2477

2478 2479
    S(U(*pdec)).sign = DECIMAL_NEG;
    S(U(*pdec)).scale = 0;
2480
    pdec->Hi32 = 0;
2481 2482
    S1(U1(*pdec)).Mid32 = 0;
    S1(U1(*pdec)).Lo32 = 1;
2483
    VARNOT(DECIMAL,*pdec,I4,0);
2484

2485 2486
    pcy->int64 = 10000;
    VARNOT(CY,*pcy,I4,-2);
2487 2488 2489 2490 2491 2492

    pcy->int64 = 0;
    VARNOT(CY,*pcy,I4,-1);

    pcy->int64 = -1;
    VARNOT(CY,*pcy,I4,-1);
2493
}
2494

2495
static HRESULT (WINAPI *pVarSub)(LPVARIANT,LPVARIANT,LPVARIANT);
2496

2497 2498
#define VARSUB(vt1,val1,vt2,val2,rvt,rval)               \
        V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
2499
        V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
2500
        V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
2501
        test_var_call2( __LINE__, pVarSub, &left, &right, &exp )
2502

2503 2504
static void test_VarSub(void)
{
2505
    VARIANT left, right, exp, result, cy, dec;
2506 2507 2508 2509
    VARTYPE i;
    BSTR lbstr, rbstr;
    HRESULT hres, expectedhres;
    double r;
2510

2511
    CHECKPTR(VarSub);
Jon Griffiths's avatar
Jon Griffiths committed
2512

2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579
    lbstr = SysAllocString(sz12);
    rbstr = SysAllocString(sz12);

    VariantInit(&left);
    VariantInit(&right);
    VariantInit(&result);

    /* Test all possible flag/vt combinations & the resulting vt type */
    for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
    {

        VARTYPE leftvt, rightvt, resvt;

        for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
        {

            SKIPTESTS(leftvt);

            for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
            {

                SKIPTESTS(rightvt);
                expectedhres = S_OK;

                memset(&left, 0, sizeof(left));
                memset(&right, 0, sizeof(right));
                V_VT(&left) = leftvt | ExtraFlags[i];
                if (leftvt == VT_BSTR)
                    V_BSTR(&left) = lbstr;
                V_VT(&right) = rightvt | ExtraFlags[i];
                if (rightvt == VT_BSTR)
                    V_BSTR(&right) = rbstr;
                V_VT(&result) = VT_EMPTY;

                /* All extra flags produce errors */
                if (ExtraFlags[i] == (VT_VECTOR|VT_BYREF|VT_RESERVED) ||
                    ExtraFlags[i] == (VT_VECTOR|VT_RESERVED) ||
                    ExtraFlags[i] == (VT_VECTOR|VT_BYREF) ||
                    ExtraFlags[i] == (VT_BYREF|VT_RESERVED) ||
                    ExtraFlags[i] == VT_VECTOR ||
                    ExtraFlags[i] == VT_BYREF ||
                    ExtraFlags[i] == VT_RESERVED)
                {
                    expectedhres = DISP_E_BADVARTYPE;
                    resvt = VT_EMPTY;
                }
                else if (ExtraFlags[i] >= VT_ARRAY)
                {
                    expectedhres = DISP_E_TYPEMISMATCH;
                    resvt = VT_EMPTY;
                }
                /* Native VarSub cannot handle: VT_I1, VT_UI2, VT_UI4,
                   VT_INT, VT_UINT and VT_UI8. Tested with WinXP */
                else if (!IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
                    !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
                    leftvt == VT_CLSID || rightvt == VT_CLSID ||
                    leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
                    leftvt == VT_I1 || rightvt == VT_I1 ||
                    leftvt == VT_UI2 || rightvt == VT_UI2 ||
                    leftvt == VT_UI4 || rightvt == VT_UI4 ||
                    leftvt == VT_UI8 || rightvt == VT_UI8 ||
                    leftvt == VT_INT || rightvt == VT_INT ||
                    leftvt == VT_UINT || rightvt == VT_UINT ||
                    leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN ||
                    leftvt == VT_RECORD || rightvt == VT_RECORD)
                {
                    if (leftvt == VT_RECORD && rightvt == VT_I8)
2580
                    {
2581
                        if (has_i8)
2582 2583 2584 2585
                            expectedhres = DISP_E_TYPEMISMATCH;
                        else
                            expectedhres = DISP_E_BADVARTYPE;
                    }
2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649
                    else if (leftvt < VT_UI1 && rightvt == VT_RECORD)
                        expectedhres = DISP_E_TYPEMISMATCH;
                    else if (leftvt >= VT_UI1 && rightvt == VT_RECORD)
                        expectedhres = DISP_E_TYPEMISMATCH;
                    else if (leftvt == VT_RECORD && rightvt <= VT_UI1)
                        expectedhres = DISP_E_TYPEMISMATCH;
                    else if (leftvt == VT_RECORD && rightvt > VT_UI1)
                        expectedhres = DISP_E_BADVARTYPE;
                    else
                        expectedhres = DISP_E_BADVARTYPE;
                    resvt = VT_EMPTY;
                }
                else if ((leftvt == VT_NULL && rightvt == VT_DISPATCH) ||
                    (leftvt == VT_DISPATCH && rightvt == VT_NULL))
                    resvt = VT_NULL;
                else if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
                    leftvt == VT_ERROR || rightvt == VT_ERROR)
                {
                    resvt = VT_EMPTY;
                    expectedhres = DISP_E_TYPEMISMATCH;
                }
                else if (leftvt == VT_NULL || rightvt == VT_NULL)
                    resvt = VT_NULL;
                else if ((leftvt == VT_EMPTY && rightvt == VT_BSTR) ||
                    (leftvt == VT_DATE && rightvt == VT_DATE) ||
                    (leftvt == VT_BSTR && rightvt == VT_EMPTY) ||
                    (leftvt == VT_BSTR && rightvt == VT_BSTR))
                    resvt = VT_R8;
                else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
                    resvt = VT_DECIMAL;
                else if (leftvt == VT_DATE || rightvt == VT_DATE)
                    resvt = VT_DATE;
                else if (leftvt == VT_CY || rightvt == VT_CY)
                    resvt = VT_CY;
                else if (leftvt == VT_R8 || rightvt == VT_R8)
                    resvt = VT_R8;
                else if (leftvt == VT_BSTR || rightvt == VT_BSTR) {
                    resvt = VT_R8;
                } else if (leftvt == VT_R4 || rightvt == VT_R4) {
                    if (leftvt == VT_I4 || rightvt == VT_I4 ||
                        leftvt == VT_I8 || rightvt == VT_I8)
                        resvt = VT_R8;
                    else
                        resvt = VT_R4;
                }
                else if (leftvt == VT_I8 || rightvt == VT_I8)
                    resvt = VT_I8;
                else if (leftvt == VT_I4 || rightvt == VT_I4)
                    resvt = VT_I4;
                else if (leftvt == VT_I2 || rightvt == VT_I2 ||
                    leftvt == VT_BOOL || rightvt == VT_BOOL ||
                    (leftvt == VT_EMPTY && rightvt == VT_EMPTY))
                    resvt = VT_I2;
                else if (leftvt == VT_UI1 || rightvt == VT_UI1)
                    resvt = VT_UI1;
                else
                {
                    resvt = VT_EMPTY;
                    expectedhres = DISP_E_TYPEMISMATCH;
                }

                hres = pVarSub(&left, &right, &result);

                ok(hres == expectedhres && V_VT(&result) == resvt,
2650 2651
                    "VarSub: %d|0x%X, %d|0x%X: Expected failure 0x%X, "
                    "got 0x%X, expected vt %d got vt %d\n",
2652 2653 2654 2655 2656
                    leftvt, ExtraFlags[i], rightvt, ExtraFlags[i],
                    expectedhres, hres, resvt, V_VT(&result));
            }
        }
    }
2657

2658 2659 2660 2661 2662
    /* Test returned values */
    VARSUB(I4,4,I4,2,I4,2);
    VARSUB(I2,4,I2,2,I2,2);
    VARSUB(I2,-13,I4,5,I4,-18);
    VARSUB(I4,-13,I4,5,I4,-18);
2663 2664
    VARSUB(I2,7,R4,0.5f,R4,6.5f);
    VARSUB(R4,0.5f,I4,5,R8,-4.5);
2665 2666 2667
    VARSUB(R8,7.1,BOOL,0,R8,7.1);
    VARSUB(BSTR,lbstr,I2,4,R8,8);
    VARSUB(BSTR,lbstr,BOOL,1,R8,11);
2668 2669
    VARSUB(BSTR,lbstr,R4,0.1f,R8,11.9);
    VARSUB(R4,0.2f,BSTR,rbstr,R8,-11.8);
2670
    VARSUB(DATE,2.25,I4,7,DATE,-4.75);
2671
    VARSUB(DATE,1.25,R4,-1.7f,DATE,2.95);
2672 2673 2674 2675

    VARSUB(UI1, UI1_MAX, UI1, UI1_MAX, UI1, 0);
    VARSUB(I2, I2_MAX, I2, I2_MAX, I2, 0);
    VARSUB(I2, I2_MIN, I2, I2_MIN, I2, 0);
2676 2677 2678
    VARSUB(I4, I4_MAX, I4, I4_MAX, I4, 0);
    VARSUB(I4, I4_MIN, I4, I4_MIN, I4, 0);
    VARSUB(R4, R4_MAX, R4, R4_MAX, R4, 0.0f);
2679
    VARSUB(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX - R4_MIN);
2680
    VARSUB(R4, R4_MIN, R4, R4_MIN, R4, 0.0f);
2681 2682 2683 2684 2685 2686 2687 2688
    VARSUB(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX - R8_MIN);
    VARSUB(R8, R8_MIN, R8, R8_MIN, R8, 0.0);

    /* Manually test BSTR + BSTR */
    V_VT(&left) = VT_BSTR;
    V_BSTR(&left) = lbstr;
    V_VT(&right) = VT_BSTR;
    V_BSTR(&right) = rbstr;
2689
    hres = pVarSub(&left, &right, &result);
2690 2691
    ok(hres == S_OK && V_VT(&result) == VT_R8,
        "VarSub: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
2692
    ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 0.0),
2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708
        "VarSub: BSTR + BSTR, expected %f got %f\n", 0.0, V_R8(&result));

    /* Manually test some VT_CY and VT_DECIMAL variants */
    V_VT(&cy) = VT_CY;
    hres = VarCyFromI4(4711, &V_CY(&cy));
    ok(hres == S_OK, "VarCyFromI4 failed!\n");
    V_VT(&dec) = VT_DECIMAL;
    hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec));
    ok(hres == S_OK, "VarDecFromR4 failed!\n");
    memset(&left, 0, sizeof(left));
    memset(&right, 0, sizeof(right));
    V_VT(&left) = VT_I4;
    V_I4(&left) = -11;
    V_VT(&right) = VT_UI1;
    V_UI1(&right) = 9;

2709
    hres = pVarSub(&cy, &right, &result);
2710 2711 2712
    ok(hres == S_OK && V_VT(&result) == VT_CY,
        "VarSub: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result)));
    hres = VarR8FromCy(V_CY(&result), &r);
2713
    ok(hres == S_OK && EQ_DOUBLE(r, 4702.0),
2714 2715
        "VarSub: CY value %f, expected %f\n", r, (double)4720);

2716
    hres = pVarSub(&left, &dec, &result);
2717 2718 2719 2720 2721 2722 2723 2724
    ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
        "VarSub: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
    hres = VarR8FromDec(&V_DECIMAL(&result), &r);
    ok(hres == S_OK && EQ_DOUBLE(r, -6.8),
        "VarSub: DECIMAL value %f, expected %f\n", r, (double)-15.2);

    SysFreeString(lbstr);
    SysFreeString(rbstr);
2725 2726
}

2727 2728
static HRESULT (WINAPI *pVarMod)(LPVARIANT,LPVARIANT,LPVARIANT);

2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745
static void test_Mod( int line, VARIANT *left, VARIANT *right, VARIANT *expected, HRESULT expres )
{
    VARIANT result;
    HRESULT hres;

    memset( &result, 0, sizeof(result) );
    hres = pVarMod( left, right, &result );
    ok_(__FILE__,line)( hres == expres, "wrong result %x/%x\n", hres, expres );
    if (hres == S_OK)
        ok_(__FILE__,line)( is_expected_variant( &result, expected ),
                            "got %s expected %s\n", variantstr(&result), variantstr(expected) );
}

#define VARMOD(vt1,vt2,val1,val2,rvt,rval)               \
        V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
        V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
        V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
2746
        test_var_call2( __LINE__, pVarMod, &left, &right, &exp )
2747 2748 2749 2750 2751

#define VARMOD2(vt1,vt2,val1,val2,rvt,rval,hexpected)         \
        V_VT(&left) = VT_##vt1; V_I4(&left) = val1;           \
        V_VT(&right) = VT_##vt2; V_I4(&right) = val2;         \
        V_VT(&exp) = VT_##rvt; V_I4(&exp) = rval;             \
2752
        test_Mod( __LINE__, &left, &right, &exp, hexpected )
2753

2754 2755
static void test_VarMod(void)
{
2756
  VARIANT v1, v2, vDst, left, right, exp;
2757 2758 2759 2760 2761 2762
  HRESULT hres;
  HRESULT hexpected = 0;
  static const WCHAR szNum0[] = {'1','2','5','\0'};
  static const WCHAR szNum1[] = {'1','0','\0'};
  int l, r;
  BOOL lFound, rFound;
2763
  BOOL lValid;
2764 2765 2766 2767
  BSTR strNum0, strNum1;

  CHECKPTR(VarMod);

2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858
  VARMOD(I1,BOOL,100,10,I4,0);
  VARMOD(I1,I1,100,10,I4,0);
  VARMOD(I1,UI1,100,10,I4,0);
  VARMOD(I1,I2,100,10,I4,0);
  VARMOD(I1,UI2,100,10,I4,0);
  VARMOD(I1,I4,100,10,I4,0);
  VARMOD(I1,UI4,100,10,I4,0);
  VARMOD(I1,R4,100,10,I4,0);
  VARMOD(I1,R8,100,10,I4,0);

  VARMOD(UI1,BOOL,100,10,I2,0);
  VARMOD(UI1,I1,100,10,I4,0);
  VARMOD(UI1,UI1,100,10,UI1,0);
  VARMOD(UI1,I2,100,10,I2,0);
  VARMOD(UI1,UI2,100,10,I4,0);
  VARMOD(UI1,I4,100,10,I4,0);
  VARMOD(UI1,UI4,100,10,I4,0);
  VARMOD(UI1,R4,100,10,I4,0);
  VARMOD(UI1,R8,100,10,I4,0);

  VARMOD(I2,BOOL,100,10,I2,0);
  VARMOD(I2,I1,100,10,I4,0);
  VARMOD(I2,UI1,100,10,I2,0);
  VARMOD(I2,I2,100,10,I2,0);
  VARMOD(I2,UI2,100,10,I4,0);
  VARMOD(I2,I4,100,10,I4,0);
  VARMOD(I2,UI4,100,10,I4,0);
  VARMOD(I2,R4,100,10,I4,0);
  VARMOD(I2,R8,100,10,I4,0);

  VARMOD(I4,BOOL,100,10,I4,0);
  VARMOD(I4,I1,100,10,I4,0);
  VARMOD(I4,UI1,100,10,I4,0);
  VARMOD(I4,I2,100,10,I4,0);
  VARMOD(I4,UI2,100,10,I4,0);
  VARMOD(I4,I4,100,10,I4,0);
  VARMOD(I4,UI4,100,10,I4,0);
  VARMOD(I4,R4,100,10,I4,0);
  VARMOD(I4,R8,100,10,I4,0);
  VARMOD(UI4,BOOL,100,10,I4,0);
  VARMOD(UI4,I1,100,10,I4,0);
  VARMOD(UI4,UI1,100,10,I4,0);
  VARMOD(UI4,I2,100,10,I4,0);
  VARMOD(UI4,UI2,100,10,I4,0);
  VARMOD(UI4,I4,100,10,I4,0);
  VARMOD(UI4,UI4,100,10,I4,0);
  VARMOD(UI4,R4,100,10,I4,0);
  VARMOD(UI4,R8,100,10,I4,0);
  VARMOD(R4,BOOL,100,10,I4,0);
  VARMOD(R4,I1,100,10,I4,0);
  VARMOD(R4,UI1,100,10,I4,0);
  VARMOD(R4,I2,100,10,I4,0);
  VARMOD(R4,UI2,100,10,I4,0);
  VARMOD(R4,I4,100,10,I4,0);
  VARMOD(R4,UI4,100,10,I4,0);
  VARMOD(R4,R4,100,10,I4,0);
  VARMOD(R4,R8,100,10,I4,0);
  VARMOD(R8,BOOL,100,10,I4,0);
  VARMOD(R8,I1,100,10,I4,0);
  VARMOD(R8,UI1,100,10,I4,0);
  VARMOD(R8,I2,100,10,I4,0);
  VARMOD(R8,UI2,100,10,I4,0);
  VARMOD(R8,I4,100,10,I4,0);
  VARMOD(R8,UI4,100,10,I4,0);
  VARMOD(R8,R4,100,10,I4,0);
  VARMOD(R8,R8,100,10,I4,0);

  VARMOD(INT,INT,100,10,I4,0);
  VARMOD(INT,UINT,100,10,I4,0);

  VARMOD(BOOL,BOOL,100,10,I2,0);
  VARMOD(BOOL,I1,100,10,I4,0);
  VARMOD(BOOL,UI1,100,10,I2,0);
  VARMOD(BOOL,I2,100,10,I2,0);
  VARMOD(BOOL,UI2,100,10,I4,0);
  VARMOD(BOOL,I4,100,10,I4,0);
  VARMOD(BOOL,UI4,100,10,I4,0);
  VARMOD(BOOL,R4,100,10,I4,0);
  VARMOD(BOOL,R8,100,10,I4,0);
  VARMOD(BOOL,DATE,100,10,I4,0);

  VARMOD(DATE,BOOL,100,10,I4,0);
  VARMOD(DATE,I1,100,10,I4,0);
  VARMOD(DATE,UI1,100,10,I4,0);
  VARMOD(DATE,I2,100,10,I4,0);
  VARMOD(DATE,UI2,100,10,I4,0);
  VARMOD(DATE,I4,100,10,I4,0);
  VARMOD(DATE,UI4,100,10,I4,0);
  VARMOD(DATE,R4,100,10,I4,0);
  VARMOD(DATE,R8,100,10,I4,0);
  VARMOD(DATE,DATE,100,10,I4,0);
2859 2860 2861

  strNum0 = SysAllocString(szNum0);
  strNum1 = SysAllocString(szNum1);
2862 2863 2864 2865 2866 2867 2868
  VARMOD(BSTR,BSTR,strNum0,strNum1,I4,5);
  VARMOD(BSTR,I1,strNum0,10,I4,5);
  VARMOD(BSTR,I2,strNum0,10,I4,5);
  VARMOD(BSTR,I4,strNum0,10,I4,5);
  VARMOD(BSTR,R4,strNum0,10,I4,5);
  VARMOD(BSTR,R8,strNum0,10,I4,5);
  VARMOD(I4,BSTR,125,strNum1,I4,5);
2869

2870
  if (has_i8)
Richard Cohen's avatar
Richard Cohen committed
2871
  {
2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893
    VARMOD(BOOL,I8,100,10,I8,0);
    VARMOD(I1,I8,100,10,I8,0);
    VARMOD(UI1,I8,100,10,I8,0);
    VARMOD(I2,I8,100,10,I8,0);
    VARMOD(I4,I8,100,10,I8,0);
    VARMOD(UI4,I8,100,10,I8,0);
    VARMOD(R4,I8,100,10,I8,0);
    VARMOD(R8,I8,100,10,I8,0);
    VARMOD(DATE,I8,100,10,I8,0);

    VARMOD(I8,BOOL,100,10,I8,0);
    VARMOD(I8,I1,100,10,I8,0);
    VARMOD(I8,UI1,100,10,I8,0);
    VARMOD(I8,I2,100,10,I8,0);
    VARMOD(I8,UI2,100,10,I8,0);
    VARMOD(I8,I4,100,10,I8,0);
    VARMOD(I8,UI4,100,10,I8,0);
    VARMOD(I8,R4,100,10,I8,0);
    VARMOD(I8,R8,100,10,I8,0);
    VARMOD(I8,I8,100,10,I8,0);

    VARMOD(BSTR,I8,strNum0,10,I8,5);
Richard Cohen's avatar
Richard Cohen committed
2894 2895
  }

2896 2897 2898
  /* test all combinations of types */
  for(l = 0; l < VT_BSTR_BLOB; l++)
  {
2899 2900
    SKIPTESTS(l);

2901 2902
    for(r = 0; r < VT_BSTR_BLOB; r++)
    {
2903 2904
      SKIPTESTS(r);
        
2905 2906 2907 2908
      if(l == VT_BSTR) continue;
      if(l == VT_DISPATCH) continue;
      if(r == VT_BSTR) continue;
      if(r == VT_DISPATCH) continue;
Jon Griffiths's avatar
Jon Griffiths committed
2909

2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930
      lFound = TRUE;
      lValid = TRUE;
      switch(l)
	{
	case VT_EMPTY:
	case VT_NULL:
	case VT_I1:
	case VT_UI1:
	case VT_I2:
	case VT_UI2:
	case VT_I4:
	case VT_I8:
	case VT_UI4:
	case VT_UI8:
	case VT_INT:
	case VT_UINT:
	case VT_R4:
	case VT_R8:
	case VT_BOOL:
	case VT_DATE:
	case VT_CY:
2931
	case VT_DECIMAL:
2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964
	  hexpected = S_OK;
	  break;
	case VT_ERROR:
	case VT_VARIANT:
	case VT_UNKNOWN:
	case VT_RECORD:
	  lValid = FALSE;
	  break;
	default:
	  lFound = FALSE;
	  hexpected = DISP_E_BADVARTYPE;
	  break;
	}

      rFound = TRUE;
      switch(r)
	{
	case VT_EMPTY:
	case VT_NULL:
	case VT_I1:
	case VT_UI1:
	case VT_I2:
	case VT_UI2:
	case VT_I4:
	case VT_I8:
	case VT_UI4:
	case VT_UI8:
	case VT_INT:
	case VT_UINT:
	case VT_R4:
	case VT_R8:
	case VT_BOOL:
	case VT_DATE:
2965
	case VT_DECIMAL:
2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008
	case VT_CY:
	  hexpected = S_OK;
	  break;
	case VT_ERROR:
	case VT_VARIANT:
	case VT_UNKNOWN:
	case VT_RECORD:
	  break;
	default:
	  rFound = FALSE;
	  break;
	}

      if(((l == VT_I8) && (r == VT_INT)) || ((l == VT_INT) && (r == VT_I8)))
      {
	hexpected = DISP_E_TYPEMISMATCH;
      } else if((l == VT_EMPTY) && (r == VT_NULL))
      {
	hexpected = S_OK;
      } else if((l == VT_NULL) && (r == VT_EMPTY))
      {
	hexpected = S_OK;
      } else if((l == VT_EMPTY) && (r == VT_CY))
      {
	hexpected = S_OK;
      } else if((l == VT_EMPTY) && (r == VT_RECORD))
      {
	hexpected = DISP_E_TYPEMISMATCH;
      } else if((r == VT_EMPTY) && lFound && lValid)
      {
	hexpected = DISP_E_DIVBYZERO;
      } else if((l == VT_ERROR) || ((r == VT_ERROR) && lFound && lValid))
      {
	hexpected = DISP_E_TYPEMISMATCH;
      } else if((l == VT_NULL) && (r == VT_NULL))
      {
	hexpected = S_OK;
      } else if((l == VT_VARIANT) || ((r == VT_VARIANT) && lFound && lValid))
      {
	hexpected = DISP_E_TYPEMISMATCH;
      } else if((l == VT_NULL) && (r == VT_RECORD))
      {
	hexpected = DISP_E_TYPEMISMATCH;
3009
      } else if((l == VT_I8) && (r == VT_DECIMAL))
3010
      {
3011 3012 3013 3014
	hexpected = S_OK;
      } else if((l == VT_DECIMAL) && (r == VT_I8))
      {
	hexpected = S_OK;
3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051
      } else if((l == VT_UNKNOWN) || ((r == VT_UNKNOWN) && lFound && lValid))
      {
	hexpected = DISP_E_TYPEMISMATCH;
      } else if((l == VT_NULL) && rFound)
      {
	hexpected = S_OK;
      } else if(l == VT_RECORD)
      {
	hexpected = DISP_E_TYPEMISMATCH;
      } else if((r == VT_RECORD) && lValid && lFound)
      {
	hexpected = DISP_E_TYPEMISMATCH;
      } else if((l == VT_EMPTY) && (r == VT_EMPTY))
      {
	hexpected = DISP_E_DIVBYZERO;
      } else if((l == VT_CY) && !rFound)
      {
	hexpected = DISP_E_BADVARTYPE;
      } else if(lFound && !rFound)
      {
	hexpected = DISP_E_BADVARTYPE;
      } else if(!lFound && rFound)
      {
	hexpected = DISP_E_BADVARTYPE;
      } else if((r == VT_NULL) && lFound && lValid)
      {
	hexpected = S_OK;
      } else if((l == VT_NULL) || (r == VT_NULL))
      {
	hexpected = DISP_E_BADVARTYPE;
      } else if((l == VT_VARIANT) || (r == VT_VARIANT))
      {
	hexpected = DISP_E_BADVARTYPE;
      } else if(!lFound && !rFound)
      {
	hexpected = DISP_E_BADVARTYPE;
      }
Jon Griffiths's avatar
Jon Griffiths committed
3052

3053 3054
      V_VT(&v1) = l;
      V_VT(&v2) = r;
Jon Griffiths's avatar
Jon Griffiths committed
3055

3056 3057 3058 3059 3060 3061 3062 3063
      if(l == VT_CY)
	V_CY(&v1).int64 = 1000000;
      else if(l == VT_R4)
	V_R4(&v1) = 100;
      else if(l == VT_R8)
	V_R8(&v1) = 100;
      else if(l == VT_UI8)
	V_UI8(&v1) = 100;
3064 3065
      else if(l == VT_I8)
	V_I8(&v1) = 100;
3066 3067
      else if(l == VT_DATE)
	V_DATE(&v1) = 1000;
3068 3069 3070
      else if (l == VT_DECIMAL)
      {
	V_DECIMAL(&v1).Hi32 = 0;
3071 3072
	U1(V_DECIMAL(&v1)).Lo64 = 100;
	U(V_DECIMAL(&v1)).signscale = 0;
3073
      }
3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084
      else
	V_I4(&v1) = 10000;

      if(r == VT_CY)
	V_CY(&v2).int64 = 10000;
      else if(r == VT_R4)
	V_R4(&v2) = 100;
      else if(r == VT_R8)
	V_R8(&v2) = 100;
      else if(r == VT_UI8)
	V_UI8(&v2) = 100;
3085 3086
      else if(r == VT_I8)
	V_I8(&v2) = 100;
3087 3088
      else if(r == VT_DATE)
	V_DATE(&v2) = 1000;
3089 3090 3091
      else if (r == VT_DECIMAL)
      {
	V_DECIMAL(&v2).Hi32 = 0;
3092 3093
	U1(V_DECIMAL(&v2)).Lo64 = 100;
	U(V_DECIMAL(&v2)).signscale = 0;
3094
      }
3095 3096 3097
      else
	V_I4(&v2) = 10000;

3098
      if ((l != VT_I8 && l != VT_UI8 && r != VT_I8 && r != VT_UI8) || has_i8)
Richard Cohen's avatar
Richard Cohen committed
3099 3100 3101
      {
        hres = pVarMod(&v1,&v2,&vDst);
        ok(hres == hexpected,
3102
           "VarMod: expected 0x%x, got 0x%X for l type of %d, r type of %d,\n", hexpected, hres, l, r);
Richard Cohen's avatar
Richard Cohen committed
3103
      }
3104 3105 3106 3107 3108 3109
    }
  }


  /****************************/
  /* test some bad parameters */
3110
  VARMOD(I4,I4,-1,-1,I4,0);
3111 3112 3113 3114

  /* test modulus with zero */
  VARMOD2(I4,I4,100,0,EMPTY,0,DISP_E_DIVBYZERO);

3115
  VARMOD(I4,I4,0,10,I4,0); /* test 0 mod 10 */
3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147

  /* right parameter is type empty */
  VARMOD2(I4,EMPTY,100,10,EMPTY,0,DISP_E_DIVBYZERO);

  /* left parameter is type empty */
  VARMOD2(EMPTY,I4,100,10,I4,0,S_OK);

  /* mod with a null left value */
  VARMOD2(NULL,I4,125,10,NULL,0,S_OK);

  /* mod with a null right value */
  VARMOD2(I4,NULL,100,10,NULL,0,S_OK);

  /* void left value */
  VARMOD2(VOID,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);

  /* void right value */
  VARMOD2(I4,VOID,100,10,EMPTY,0,DISP_E_BADVARTYPE);

  /* null left value, void right value */
  VARMOD2(NULL,VOID,100,10,EMPTY, 0, DISP_E_BADVARTYPE);

  /* void left value, null right value */
  VARMOD2(VOID,NULL,100,10,EMPTY,0,DISP_E_BADVARTYPE);

  /* some currencies */
  V_VT(&v1) = VT_CY;
  V_VT(&v2) = VT_CY;
  V_CY(&v1).int64 = 100000;
  V_CY(&v2).int64 = 100000;
  hres = pVarMod(&v1,&v2,&vDst);
  ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
3148
     "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
3149 3150 3151 3152 3153 3154 3155

  V_VT(&v1) = VT_I4;
  V_VT(&v2) = VT_CY;
  V_I4(&v1) = 100;
  V_CY(&v2).int64 = 100000;
  hres = pVarMod(&v1,&v2,&vDst);
  ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
3156
     "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
3157

3158 3159 3160 3161 3162 3163 3164
  /* some decimals */
  V_VT(&v1) = VT_DECIMAL;
  V_VT(&v2) = VT_DECIMAL;
  VarDecFromI4(100, &V_DECIMAL(&v1));
  VarDecFromI4(10, &V_DECIMAL(&v2));
  hres = pVarMod(&v1,&v2,&vDst);
  ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
3165
     "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
3166 3167 3168 3169 3170 3171 3172

  V_VT(&v1) = VT_I4;
  V_VT(&v2) = VT_DECIMAL;
  V_I4(&v1) = 100;
  VarDecFromI4(10, &V_DECIMAL(&v2));
  hres = pVarMod(&v1,&v2,&vDst);
  ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
3173
     "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
3174

3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185
  VARMOD2(UINT,I4,100,10,I4,0,S_OK);

  /* test that an error results in the type of the result changing but not its value */
  V_VT(&v1) = VT_UNKNOWN;
  V_VT(&v2) = VT_EMPTY;
  V_I4(&v1) = 100;
  V_CY(&v2).int64 = 100000;
  V_VT(&vDst) = VT_I4;
  V_I4(&vDst) = 1231;
  hres = pVarMod(&v1,&v2,&vDst);
  ok(hres == DISP_E_TYPEMISMATCH && V_VT(&vDst) == VT_EMPTY && V_I4(&vDst) == 1231,
3186
     "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));
Jon Griffiths's avatar
Jon Griffiths committed
3187

3188 3189 3190

  /* test some invalid types */
  /*TODO: not testing VT_DISPATCH */
3191
  if (has_i8)
Richard Cohen's avatar
Richard Cohen committed
3192 3193 3194
  {
    VARMOD2(I8,INT,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
  }
3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225
  VARMOD2(ERROR,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
  VARMOD2(VARIANT,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
  VARMOD2(UNKNOWN,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
  VARMOD2(VOID,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
  VARMOD2(HRESULT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
  VARMOD2(PTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
  VARMOD2(SAFEARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
  VARMOD2(CARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
  VARMOD2(USERDEFINED,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
  VARMOD2(LPSTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
  VARMOD2(LPWSTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
  VARMOD2(RECORD,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
  VARMOD2(FILETIME,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
  VARMOD2(BLOB,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
  VARMOD2(STREAM,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
  VARMOD2(STORAGE,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
  VARMOD2(STREAMED_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
  VARMOD2(STORED_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
  VARMOD2(BLOB_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
  VARMOD2(CF,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
  VARMOD2(CLSID,CLSID,100,10,EMPTY,0,DISP_E_BADVARTYPE);
  VARMOD2(VECTOR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
  VARMOD2(ARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
  VARMOD2(BYREF,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);

  /* test some more invalid types */
  V_VT(&v1) = 456;
  V_VT(&v2) = 234;
  V_I4(&v1) = 100;
  V_I4(&v2)=  10;
  hres = pVarMod(&v1,&v2,&vDst);
3226 3227
  ok(hres == DISP_E_BADVARTYPE && V_VT(&vDst) == VT_EMPTY,
     "VarMod: expected 0x%x,%d, got 0x%X,%d\n", DISP_E_BADVARTYPE, VT_EMPTY, hres, V_VT(&vDst));
3228 3229 3230

  SysFreeString(strNum0);
  SysFreeString(strNum1);
3231 3232
}

3233 3234
static HRESULT (WINAPI *pVarFix)(LPVARIANT,LPVARIANT);

3235 3236 3237
#define VARFIX(vt,val,rvt,rval)                  \
    V_VT(&v) = VT_##vt; V_##vt(&v) = val;        \
    V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
3238
    test_var_call1( __LINE__, pVarFix, &v, &exp )
3239 3240 3241 3242 3243

static void test_VarFix(void)
{
    static const WCHAR szNumMinus1[] = {'-','1','\0' };
    HRESULT hres;
3244
    VARIANT v, exp, vDst;
3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257
    DECIMAL *pdec = &V_DECIMAL(&v);
    CY *pcy = &V_CY(&v);
    size_t i;

    CHECKPTR(VarFix);

    /* Test all possible V_VT values */
    for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
    {
        VARTYPE vt;

        for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
        {
3258
            BOOL bFail = TRUE;
3259

3260 3261
            SKIPTESTS(vt);

3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273
            memset(&v, 0, sizeof(v));
            V_VT(&v) = vt | ExtraFlags[i];
            V_VT(&vDst) = VT_EMPTY;

            switch (V_VT(&v))
            {
              case VT_UI1: case VT_I2: case VT_I4: case VT_R4:  case VT_R8:
              case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
              case VT_DATE: case VT_CY:
                bFail = FALSE;
                break;
              case VT_I8:
3274
                if (has_i8)
3275 3276 3277 3278 3279 3280 3281
                  bFail = FALSE;
                break;
            }

            hres = pVarFix(&v,&vDst);
            if (bFail)
              ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3282
                 "VarFix: expected failure, got 0x%X vt %d|0x%X\n",
3283 3284
                 hres, vt, ExtraFlags[i]);
            else
3285
                 ok(hres == S_OK, "VarFix: expected S_OK, got 0x%X vt %d|0x%X\n",
3286 3287 3288 3289 3290 3291 3292 3293 3294 3295
                    hres, vt, ExtraFlags[i]);
        }
    }

    VARFIX(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE);
    VARFIX(BOOL,VARIANT_FALSE,I2,0);
    VARFIX(BOOL,1,I2,1);
    VARFIX(UI1,1,UI1,1);
    VARFIX(I2,-1,I2,-1);
    VARFIX(I4,-1,I4,-1);
3296
    if (has_i8)
3297 3298 3299
    {
        VARFIX(I8,-1,I8,-1);
    }
3300 3301 3302 3303 3304 3305
    VARFIX(R4,1.4f,R4,1);
    VARFIX(R4,1.5f,R4,1);
    VARFIX(R4,1.6f,R4,1);
    VARFIX(R4,-1.4f,R4,-1);
    VARFIX(R4,-1.5f,R4,-1);
    VARFIX(R4,-1.6f,R4,-1);
3306 3307 3308 3309 3310 3311 3312 3313
    /* DATE & R8 round as for R4 */
    VARFIX(DATE,-1,DATE,-1);
    VARFIX(R8,-1,R8,-1);
    VARFIX(BSTR,(BSTR)szNumMinus1,R8,-1);

    V_VT(&v) = VT_EMPTY;
    hres = pVarFix(&v,&vDst);
    ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
3314
       "VarFix: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY,
3315 3316 3317 3318 3319
       hres, V_VT(&vDst), V_I2(&vDst));

    V_VT(&v) = VT_NULL;
    hres = pVarFix(&v,&vDst);
    ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
3320
       "VarFix: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst));
3321 3322

    V_VT(&v) = VT_DECIMAL;
3323 3324
    S(U(*pdec)).sign = DECIMAL_NEG;
    S(U(*pdec)).scale = 0;
3325
    pdec->Hi32 = 0;
3326 3327
    S1(U1(*pdec)).Mid32 = 0;
    S1(U1(*pdec)).Lo32 = 1;
3328
    hres = pVarFix(&v,&vDst);
3329
    ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && !memcmp(&V_DECIMAL(&v), &V_DECIMAL(&vDst), sizeof(DECIMAL)),
3330
       "VarFix: expected 0x0,%d,identical, got 0x%X,%d\n", VT_DECIMAL,
3331 3332 3333 3334 3335 3336 3337 3338
       hres, V_VT(&vDst));

    /* FIXME: Test some fractional decimals when VarDecFix is implemented */

    V_VT(&v) = VT_CY;
    pcy->int64 = -10000;
    hres = pVarFix(&v,&vDst);
    ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
3339
       "VarFix: VT_CY wrong, hres=0x%X\n", hres);
3340 3341 3342 3343 3344

    V_VT(&v) = VT_CY;
    pcy->int64 = -16000;
    hres = pVarFix(&v,&vDst);
    ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
3345
       "VarFix: VT_CY wrong, hres=0x%X\n", hres);
3346 3347 3348 3349
}

static HRESULT (WINAPI *pVarInt)(LPVARIANT,LPVARIANT);

3350 3351 3352
#define VARINT(vt,val,rvt,rval)                  \
    V_VT(&v) = VT_##vt; V_##vt(&v) = val;        \
    V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
3353
    test_var_call1( __LINE__, pVarInt, &v, &exp )
3354 3355 3356 3357 3358

static void test_VarInt(void)
{
    static const WCHAR szNumMinus1[] = {'-','1','\0' };
    HRESULT hres;
3359
    VARIANT v, exp, vDst;
3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372
    DECIMAL *pdec = &V_DECIMAL(&v);
    CY *pcy = &V_CY(&v);
    size_t i;

    CHECKPTR(VarInt);

    /* Test all possible V_VT values */
    for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
    {
        VARTYPE vt;

        for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
        {
3373
            BOOL bFail = TRUE;
3374

3375 3376
            SKIPTESTS(vt);

3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388
            memset(&v, 0, sizeof(v));
            V_VT(&v) = vt | ExtraFlags[i];
            V_VT(&vDst) = VT_EMPTY;

            switch (V_VT(&v))
            {
              case VT_UI1: case VT_I2: case VT_I4: case VT_R4:  case VT_R8:
              case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
              case VT_DATE: case VT_CY:
                bFail = FALSE;
                break;
              case VT_I8:
3389
                if (has_i8)
3390 3391 3392 3393 3394 3395 3396
                  bFail = FALSE;
                break;
            }

            hres = pVarInt(&v,&vDst);
            if (bFail)
              ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3397
                 "VarInt: expected failure, got 0x%X vt %d|0x%X\n",
3398 3399
                 hres, vt, ExtraFlags[i]);
            else
3400
                 ok(hres == S_OK, "VarInt: expected S_OK, got 0x%X vt %d|0x%X\n",
3401 3402 3403 3404 3405 3406 3407 3408 3409 3410
                    hres, vt, ExtraFlags[i]);
        }
    }

    VARINT(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE);
    VARINT(BOOL,VARIANT_FALSE,I2,0);
    VARINT(BOOL,1,I2,1);
    VARINT(UI1,1,UI1,1);
    VARINT(I2,-1,I2,-1);
    VARINT(I4,-1,I4,-1);
3411
    if (has_i8)
3412 3413 3414
    {
        VARINT(I8,-1,I8,-1);
    }
3415 3416 3417 3418 3419 3420
    VARINT(R4,1.4f,R4,1);
    VARINT(R4,1.5f,R4,1);
    VARINT(R4,1.6f,R4,1);
    VARINT(R4,-1.4f,R4,-2); /* Note these 3 are different from VarFix */
    VARINT(R4,-1.5f,R4,-2);
    VARINT(R4,-1.6f,R4,-2);
3421 3422 3423 3424 3425 3426 3427 3428
    /* DATE & R8 round as for R4 */
    VARINT(DATE,-1,DATE,-1);
    VARINT(R8,-1,R8,-1);
    VARINT(BSTR,(BSTR)szNumMinus1,R8,-1);

    V_VT(&v) = VT_EMPTY;
    hres = pVarInt(&v,&vDst);
    ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
3429
       "VarInt: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY,
3430 3431 3432 3433 3434
       hres, V_VT(&vDst), V_I2(&vDst));

    V_VT(&v) = VT_NULL;
    hres = pVarInt(&v,&vDst);
    ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
3435
       "VarInt: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst));
3436 3437

    V_VT(&v) = VT_DECIMAL;
3438 3439
    S(U(*pdec)).sign = DECIMAL_NEG;
    S(U(*pdec)).scale = 0;
3440
    pdec->Hi32 = 0;
3441 3442
    S1(U1(*pdec)).Mid32 = 0;
    S1(U1(*pdec)).Lo32 = 1;
3443
    hres = pVarInt(&v,&vDst);
3444
    ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && !memcmp(&V_DECIMAL(&v), &V_DECIMAL(&vDst), sizeof(DECIMAL)),
3445
       "VarInt: expected 0x0,%d,identical, got 0x%X,%d\n", VT_DECIMAL,
3446 3447 3448 3449 3450 3451 3452 3453
       hres, V_VT(&vDst));

    /* FIXME: Test some fractional decimals when VarDecInt is implemented */

    V_VT(&v) = VT_CY;
    pcy->int64 = -10000;
    hres = pVarInt(&v,&vDst);
    ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
3454
       "VarInt: VT_CY wrong, hres=0x%X\n", hres);
3455 3456 3457 3458 3459

    V_VT(&v) = VT_CY;
    pcy->int64 = -11000;
    hres = pVarInt(&v,&vDst);
    ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -20000,
3460
       "VarInt: VT_CY wrong, hres=0x%X 0x%x%08x\n",
3461
       hres, (DWORD)(V_CY(&vDst).int64 >> 32), (DWORD)V_CY(&vDst).int64);
3462 3463 3464 3465
}

static HRESULT (WINAPI *pVarNeg)(LPVARIANT,LPVARIANT);

3466 3467 3468
#define VARNEG(vt,val,rvt,rval)                  \
    V_VT(&v) = VT_##vt; V_##vt(&v) = val;        \
    V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
3469
    test_var_call1( __LINE__, pVarNeg, &v, &exp )
3470 3471 3472 3473 3474 3475

static void test_VarNeg(void)
{
    static const WCHAR szNumMinus1[] = {'-','1','\0' };
    static const WCHAR szNum1[] = {'1','\0' };
    HRESULT hres;
3476
    VARIANT v, exp, vDst;
3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493
    DECIMAL *pdec = &V_DECIMAL(&v);
    CY *pcy = &V_CY(&v);
    size_t i;

    CHECKPTR(VarNeg);

    /* Test all possible V_VT values. But don't test the exact return values
     * except for success/failure, since M$ made a hash of them in the
     * native version. This at least ensures (as with all tests here) that
     * we will notice if/when new vtypes/flags are added in native.
     */
    for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
    {
        VARTYPE vt;

        for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
        {
3494
            BOOL bFail = TRUE;
3495

3496 3497
            SKIPTESTS(vt);

3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510
            memset(&v, 0, sizeof(v));
            V_VT(&v) = vt | ExtraFlags[i];
            V_VT(&vDst) = VT_EMPTY;

            switch (V_VT(&v))
            {
            case VT_UI1: case VT_I2: case VT_I4:
            case VT_R4:  case VT_R8:
            case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
            case VT_DATE: case VT_CY:
                bFail = FALSE;
                break;
            case VT_I8:
3511
                if (has_i8)
3512 3513 3514 3515 3516 3517
                    bFail = FALSE;
            }

            hres = pVarNeg(&v,&vDst);
            if (bFail)
                ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3518
                   "VarNeg: expected failure, got 0x%X vt %d|0x%X\n",
3519 3520
                   hres, vt, ExtraFlags[i]);
            else
3521
                ok(hres == S_OK, "VarNeg: expected S_OK, got 0x%X vt %d|0x%X\n",
3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536
                    hres, vt, ExtraFlags[i]);
        }
    }

    VARNEG(BOOL,VARIANT_TRUE,I2,1);
    VARNEG(BOOL,VARIANT_FALSE,I2,0);
    VARNEG(BOOL,1,I2,-1);
    VARNEG(UI1,1,I2,-1);
    VARNEG(UI1,254,I2,-254);
    VARNEG(I2,-32768,I4,32768);
    VARNEG(I2,-1,I2,1);
    VARNEG(I2,1,I2,-1);
    VARNEG(I4,-((int)(~0u >> 1)) - 1,R8,-2147483648u);
    VARNEG(I4,-1,I4,1);
    VARNEG(I4,1,I4,-1);
3537
    if (has_i8)
3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553
    {
        VARNEG(I8,1,I8,-1);
        VARNEG(I8,-1,I8,1);
    }
    VARNEG(R4,1,R4,-1);
    VARNEG(R4,-1,R4,1);
    VARNEG(DATE,1,DATE,-1);
    VARNEG(DATE,-1,DATE,1);
    VARNEG(R8,1,R8,-1);
    VARNEG(R8,-1,R8,1);
    VARNEG(BSTR,(BSTR)szNumMinus1,R8,1);
    VARNEG(BSTR,(BSTR)szNum1,R8,-1);

    V_VT(&v) = VT_EMPTY;
    hres = pVarNeg(&v,&vDst);
    ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
3554
       "VarNeg: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY,
3555 3556 3557 3558 3559
       hres, V_VT(&vDst), V_I2(&vDst));

    V_VT(&v) = VT_NULL;
    hres = pVarNeg(&v,&vDst);
    ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
3560
       "VarNeg: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst));
3561 3562

    V_VT(&v) = VT_DECIMAL;
3563 3564
    S(U(*pdec)).sign = DECIMAL_NEG;
    S(U(*pdec)).scale = 0;
3565
    pdec->Hi32 = 0;
3566 3567
    S1(U1(*pdec)).Mid32 = 0;
    S1(U1(*pdec)).Lo32 = 1;
3568 3569
    hres = pVarNeg(&v,&vDst);
    ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
3570
       S(U(V_DECIMAL(&vDst))).sign == 0,
3571
       "VarNeg: expected 0x0,%d,0x00, got 0x%X,%d,%02x\n", VT_DECIMAL,
3572
       hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
3573

3574
    S(U(*pdec)).sign = 0;
3575 3576
    hres = pVarNeg(&v,&vDst);
    ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
3577
       S(U(V_DECIMAL(&vDst))).sign == DECIMAL_NEG,
3578
       "VarNeg: expected 0x0,%d,0x7f, got 0x%X,%d,%02x\n", VT_DECIMAL,
3579
       hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
3580 3581 3582 3583 3584

    V_VT(&v) = VT_CY;
    pcy->int64 = -10000;
    hres = pVarNeg(&v,&vDst);
    ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
3585
       "VarNeg: VT_CY wrong, hres=0x%X\n", hres);
3586 3587
}

3588 3589
static HRESULT (WINAPI *pVarRound)(LPVARIANT,int,LPVARIANT);

3590 3591 3592 3593
static void test_Round( int line, VARIANT *arg, int deci, VARIANT *expected )
{
    VARIANT result;
    HRESULT hres;
3594

3595 3596 3597 3598 3599 3600 3601 3602 3603 3604
    memset( &result, 0, sizeof(result) );
    hres = pVarRound( arg, deci, &result );
    ok_(__FILE__,line)( hres == S_OK, "wrong result %x\n", hres );
    if (hres == S_OK)
        ok_(__FILE__,line)( is_expected_variant( &result, expected ),
                            "got %s expected %s\n", variantstr(&result), variantstr(expected) );
}
#define VARROUND(vt,val,deci,rvt,rval)           \
    V_VT(&v) = VT_##vt; V_##vt(&v) = val;        \
    V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
3605
    test_Round( __LINE__, &v, deci, &exp )
3606

3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632
struct decimal_t {
    BYTE scale;
    BYTE sign;
    ULONG Hi32;
    ULONG Mid32;
    ULONG Lo32;
};

struct decimal_round_t {
    struct decimal_t source;
    struct decimal_t ret;
    int dec;
};

static const struct decimal_round_t decimal_round_data[] = {
    {{ 0, DECIMAL_NEG, 0, 0, 1 }, { 0, DECIMAL_NEG, 0, 0, 1 }, 0},
    {{ 0, 0, 0, 0, 1 }, { 0, 0, 0, 0, 1 }, 0},
    {{ 2, 0, 0, 0, 155 }, { 0, 0, 0, 0, 16 }, 1},
    {{ 2, 0, 0, 0, 155 }, { 1, 0, 0, 0, 2 }, 0},
    {{ 2, 0, 0, 0, 199 }, { 1, 0, 0, 0, 20 }, 1},
    {{ 2, 0, 0, 0, 199 }, { 2, 0, 0, 0, 199 }, 2},
    {{ 2, DECIMAL_NEG, 0, 0, 199 }, { 2, DECIMAL_NEG, 0, 0, 199 }, 2},
    {{ 2, DECIMAL_NEG, 0, 0, 55 },  { 2, DECIMAL_NEG, 0, 0, 6 }, 1},
    {{ 2, 0, 0, 0, 55 },  { 2, 0, 0, 0, 6 }, 1}
};

3633 3634
static void test_VarRound(void)
{
3635 3636
    static WCHAR szNumMin[] = {'-','1','.','4','4','9','\0' };
    static WCHAR szNum[] = {'1','.','4','5','1','\0' };
3637
    HRESULT hres;
3638
    VARIANT v, exp, vDst;
3639
    CY *pcy = &V_CY(&v);
3640
    char buff[8];
3641
    int i;
3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663

    CHECKPTR(VarRound);

    /* first check valid integer types */
    VARROUND(BOOL,VARIANT_TRUE,0,I2,-1);
    VARROUND(BOOL,VARIANT_FALSE,0,I2,0);
    VARROUND(BOOL,1,0,I2,1);
    VARROUND(UI1,1,0,UI1,1);
    VARROUND(UI1,254,0,UI1,254);
    VARROUND(I2,-32768,0,I2,-32768);
    VARROUND(I2,-1,0,I2,-1);
    VARROUND(I2,1,0,I2,1);
    VARROUND(I4,-((int)(~0u >> 1)) - 1,0,I4,-((int)(~0u >> 1)) - 1);
    VARROUND(I4,-1,0,I4,-1);
    VARROUND(I4,1,0,I4,1);


    /* MSDN states that rounding of R4/R8 is dependent on the underlying
     * bit pattern of the number and so is architecture dependent. In this
     * case Wine returns .2 (which is more correct) and Native returns .3
     */

3664 3665
    VARROUND(R4,1.0f,0,R4,1.0f);
    VARROUND(R4,-1.0f,0,R4,-1.0f);
3666 3667
    VARROUND(R8,1.0,0,R8,1.0);
    VARROUND(R8,-1.0,0,R8,-1.0);
3668 3669

    /* floating point numbers aren't exactly equal and we can't just
3670 3671
     * compare the first few digits. */
    VARROUND(DATE,1.451,1,DATE,1.5);
3672
    VARROUND(DATE,-1.449,1,DATE,-1.4);
3673

3674
    /* replace the decimal separator */
3675
    GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char));
3676 3677 3678
    if (!buff[1]) {
        szNumMin[2] = buff[0];
        szNum[1] = buff[0];
3679
        VARROUND(BSTR,(BSTR)szNumMin,1,R8,-1.40);
3680
        VARROUND(BSTR,(BSTR)szNum,1,R8,1.50);
3681 3682
    } else {
        skip("Skipping VarRound(BSTR) as decimal separator is '%s'\n", buff);
3683
    }
3684

3685 3686 3687 3688 3689 3690 3691 3692 3693 3694
    VARROUND(R4,1.23456f,0,R4,1.0f);
    VARROUND(R4,1.23456f,1,R4,1.2f);
    VARROUND(R4,1.23456f,2,R4,1.23f);
    VARROUND(R4,1.23456f,3,R4,1.235f);
    VARROUND(R4,1.23456f,4,R4,1.2346f);
    VARROUND(R4,-1.23456f,0,R4,-1.0f);
    VARROUND(R4,-1.23456f,1,R4,-1.2f);
    VARROUND(R4,-1.23456f,2,R4,-1.23f);
    VARROUND(R4,-1.23456f,3,R4,-1.235f);
    VARROUND(R4,-1.23456f,4,R4,-1.2346f);
3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705

    VARROUND(R8,1.23456,0,R8,1.0);
    VARROUND(R8,1.23456,1,R8,1.2);
    VARROUND(R8,1.23456,2,R8,1.23);
    VARROUND(R8,1.23456,3,R8,1.235);
    VARROUND(R8,1.23456,4,R8,1.2346);
    VARROUND(R8,-1.23456,0,R8,-1.0);
    VARROUND(R8,-1.23456,1,R8,-1.2);
    VARROUND(R8,-1.23456,2,R8,-1.23);
    VARROUND(R8,-1.23456,3,R8,-1.235);
    VARROUND(R8,-1.23456,4,R8,-1.2346);
3706 3707 3708 3709

    V_VT(&v) = VT_EMPTY;
    hres = pVarRound(&v,0,&vDst);
    ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
3710
        "VarRound: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY,
3711 3712 3713 3714 3715
        hres, V_VT(&vDst), V_I2(&vDst));

    V_VT(&v) = VT_NULL;
    hres = pVarRound(&v,0,&vDst);
    ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
3716
        "VarRound: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst));
3717

3718 3719 3720 3721 3722 3723 3724
    /* VT_DECIMAL */
    for (i = 0; i < sizeof(decimal_round_data)/sizeof(struct decimal_round_t); i++)
    {
        const struct decimal_round_t *ptr = &decimal_round_data[i];
        DECIMAL *pdec;

        pdec = &V_DECIMAL(&v);
3725
        V_VT(&v) = VT_DECIMAL;
3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741
        S(U(*pdec)).sign = ptr->source.sign;
        S(U(*pdec)).scale = ptr->source.scale;
        pdec->Hi32 = ptr->source.Hi32;
        S1(U1(*pdec)).Mid32 = ptr->source.Mid32;
        S1(U1(*pdec)).Lo32 = ptr->source.Lo32;
        VariantInit(&vDst);
        hres = pVarRound(&v, ptr->dec, &vDst);
    todo_wine
        ok(hres == S_OK, "%d: got 0x%08x\n", i, hres);
        if (hres == S_OK)
        {
            ok(V_VT(&vDst) == VT_DECIMAL, "%d: got VT %d, expected VT_DECIMAL\n", i, V_VT(&vDst));
            ok(S(U(V_DECIMAL(&vDst))).sign == ptr->ret.sign, "%d: got sign 0x%02x, expected 0x%02x\n",
                i, S(U(V_DECIMAL(&vDst))).sign, ptr->ret.sign);
            ok(V_DECIMAL(&vDst).Hi32 == ptr->ret.Hi32, "%d: got Hi32 %d, expected %d\n",
                i, V_DECIMAL(&vDst).Hi32, ptr->ret.Hi32);
3742 3743 3744 3745
            ok(S1(U1(V_DECIMAL(&vDst))).Mid32 == ptr->ret.Mid32, "%d: got Mid32 %d, expected %d\n",
               i, S1(U1(V_DECIMAL(&vDst))).Mid32,  ptr->ret.Mid32);
            ok(S1(U1(V_DECIMAL(&vDst))).Lo32 == ptr->ret.Lo32, "%d: got Lo32 %d, expected %d\n",
                i, S1(U1(V_DECIMAL(&vDst))).Lo32, ptr->ret.Lo32);
3746
        }
3747 3748
    }

3749
    /* VT_CY */
3750 3751 3752 3753
    V_VT(&v) = VT_CY;
    pcy->int64 = 10000;
    hres = pVarRound(&v,0,&vDst);
    ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
3754
        "VarRound: VT_CY wrong, hres=0x%X\n", hres);
3755 3756 3757

}

Jon Griffiths's avatar
Jon Griffiths committed
3758 3759
static HRESULT (WINAPI *pVarXor)(LPVARIANT,LPVARIANT,LPVARIANT);

3760 3761
#define VARXOR(vt1,val1,vt2,val2,rvt,rval)               \
        V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
Jon Griffiths's avatar
Jon Griffiths committed
3762
        V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
3763
        V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
3764
        test_var_call2( __LINE__, pVarXor, &left, &right, &exp )
3765 3766 3767

#define VARXORCY(vt1,val1,val2,rvt,rval)                 \
        V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
3768
        V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \
3769
        V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
3770
        test_var_call2( __LINE__, pVarXor, &left, &right, &exp )
Jon Griffiths's avatar
Jon Griffiths committed
3771 3772 3773

static void test_VarXor(void)
{
3774 3775
    static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
    static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
3776
    VARIANT left, right, exp, result;
3777
    BSTR lbstr, rbstr;
Jon Griffiths's avatar
Jon Griffiths committed
3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789
    VARTYPE i;
    HRESULT hres;

    CHECKPTR(VarXor);

    /* Test all possible flag/vt combinations & the resulting vt type */
    for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
    {
        VARTYPE leftvt, rightvt, resvt;

        for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
        {
3790

3791 3792
            SKIPTESTS(leftvt);
                    
Jon Griffiths's avatar
Jon Griffiths committed
3793 3794 3795 3796
            for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
            {
                BOOL bFail = FALSE;

3797
                SKIPTESTS(rightvt);
3798
                
Jon Griffiths's avatar
Jon Griffiths committed
3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871
                if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
                    leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
                    leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
                    continue;

                memset(&left, 0, sizeof(left));
                memset(&right, 0, sizeof(right));
                V_VT(&left) = leftvt | ExtraFlags[i];
                V_VT(&right) = rightvt | ExtraFlags[i];
                V_VT(&result) = VT_EMPTY;
                resvt = VT_I4;

                if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
                    !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
                    !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
                    leftvt == VT_CLSID || rightvt == VT_CLSID ||
                    leftvt == VT_RECORD || rightvt == VT_RECORD ||
                    leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
                    leftvt == VT_ERROR || rightvt == VT_ERROR)
                {
                    bFail = TRUE;
                }
                if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
                {
                    if (leftvt == rightvt ||
                        leftvt == VT_I2 || rightvt == VT_I2 ||
                        leftvt == VT_UI1 || rightvt == VT_UI1 ||
                        leftvt == VT_BOOL || rightvt == VT_BOOL)
                        resvt = VT_I2;
                    else if (leftvt == VT_NULL || rightvt == VT_NULL)
                        resvt = VT_NULL;
                    else if (leftvt == VT_I8 || rightvt == VT_I8)
                        resvt = VT_I8;
                }
                else if (leftvt == VT_NULL || rightvt == VT_NULL)
                {
                    resvt = VT_NULL;
                }
                else if (leftvt == VT_UI1 || rightvt == VT_UI1)
                {
                    if (leftvt == rightvt)
                        resvt = VT_UI1;
                    else if (leftvt == rightvt ||
                        leftvt == VT_I2 || rightvt == VT_I2 ||
                        leftvt == VT_BOOL || rightvt == VT_BOOL)
                    {
                        resvt = VT_I2;
                    }
                    else if (leftvt == VT_I8 || rightvt == VT_I8)
                        resvt = VT_I8;
                }
                else if (leftvt == VT_I2 || rightvt == VT_I2)
                {
                    if (leftvt == rightvt ||
                        leftvt == VT_BOOL || rightvt == VT_BOOL)
                        resvt = VT_I2;
                    else if (leftvt == VT_I8 || rightvt == VT_I8)
                        resvt = VT_I8;
                }
                else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
                {
                    resvt = VT_BOOL;
                }
                else if (leftvt == VT_I8 || rightvt == VT_I8)
                {
                    if (leftvt == VT_INT || rightvt == VT_INT)
                        bFail = TRUE;
                    else
                        resvt = VT_I8;
                }
                hres = pVarXor(&left, &right, &result);
                if (bFail)
                    ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3872
                       "VarXor: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
Jon Griffiths's avatar
Jon Griffiths committed
3873 3874 3875 3876
                       leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
                       V_VT(&result));
                else
                    ok(hres == S_OK && V_VT(&result) == resvt,
3877
                       "VarXor: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
Jon Griffiths's avatar
Jon Griffiths committed
3878 3879 3880 3881 3882 3883
                       leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
                       V_VT(&result));
            }
        }
    }

3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901
    /* Test returned values
     * FIXME: Test VT_DECIMAL/VT_DISPATCH
     */
    VARXOR(EMPTY,0,EMPTY,0,I2,0);
    VARXOR(EMPTY,1,EMPTY,0,I2,0);
    VARXOR(EMPTY,0,NULL,0,NULL,0);
    VARXOR(EMPTY,0,I1,0,I4,0);
    VARXOR(EMPTY,0,I1,1,I4,1);
    VARXOR(EMPTY,0,UI1,0,I2,0);
    VARXOR(EMPTY,0,UI1,1,I2,1);
    VARXOR(EMPTY,0,I2,0,I2,0);
    VARXOR(EMPTY,0,I2,1,I2,1);
    VARXOR(EMPTY,0,UI2,0,I4,0);
    VARXOR(EMPTY,0,UI2,1,I4,1);
    VARXOR(EMPTY,0,I4,0,I4,0);
    VARXOR(EMPTY,0,I4,1,I4,1);
    VARXOR(EMPTY,0,UI4,0,I4,0);
    VARXOR(EMPTY,0,UI4,1,I4,1);
3902
    if (has_i8)
3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920
    {
        VARXOR(EMPTY,0,I8,0,I8,0);
        VARXOR(EMPTY,0,I8,1,I8,1);
        VARXOR(EMPTY,0,UI8,0,I4,0);
        VARXOR(EMPTY,0,UI8,1,I4,1);
    }
    VARXOR(EMPTY,0,INT,0,I4,0);
    VARXOR(EMPTY,0,INT,1,I4,1);
    VARXOR(EMPTY,0,UINT,0,I4,0);
    VARXOR(EMPTY,0,UINT,1,I4,1);
    VARXOR(EMPTY,0,BOOL,0,I2,0);
    VARXOR(EMPTY,0,BOOL,1,I2,1);
    VARXOR(EMPTY,0,R4,0,I4,0);
    VARXOR(EMPTY,0,R4,1,I4,1);
    VARXOR(EMPTY,0,R8,0,I4,0);
    VARXOR(EMPTY,0,R8,1,I4,1);
    rbstr = SysAllocString(szFalse);
    VARXOR(EMPTY,0,BSTR,rbstr,I2,0);
3921
    SysFreeString(rbstr);
3922 3923 3924
    rbstr = SysAllocString(szTrue);
    VARXOR(EMPTY,0,BSTR,rbstr,I2,-1);
    VARXORCY(EMPTY,0,10000,I4,1);
3925
    SysFreeString(rbstr);
3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941

    /* NULL OR 0 = NULL. NULL OR n = n */
    VARXOR(NULL,0,NULL,0,NULL,0);
    VARXOR(NULL,1,NULL,0,NULL,0);
    VARXOR(NULL,0,I1,0,NULL,0);
    VARXOR(NULL,0,I1,1,NULL,0);
    VARXOR(NULL,0,UI1,0,NULL,0);
    VARXOR(NULL,0,UI1,1,NULL,0);
    VARXOR(NULL,0,I2,0,NULL,0);
    VARXOR(NULL,0,I2,1,NULL,0);
    VARXOR(NULL,0,UI2,0,NULL,0);
    VARXOR(NULL,0,UI2,1,NULL,0);
    VARXOR(NULL,0,I4,0,NULL,0);
    VARXOR(NULL,0,I4,1,NULL,0);
    VARXOR(NULL,0,UI4,0,NULL,0);
    VARXOR(NULL,0,UI4,1,NULL,0);
3942
    if (has_i8)
3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960
    {
        VARXOR(NULL,0,I8,0,NULL,0);
        VARXOR(NULL,0,I8,1,NULL,0);
        VARXOR(NULL,0,UI8,0,NULL,0);
        VARXOR(NULL,0,UI8,1,NULL,0);
    }
    VARXOR(NULL,0,INT,0,NULL,0);
    VARXOR(NULL,0,INT,1,NULL,0);
    VARXOR(NULL,0,UINT,0,NULL,0);
    VARXOR(NULL,0,UINT,1,NULL,0);
    VARXOR(NULL,0,BOOL,0,NULL,0);
    VARXOR(NULL,0,BOOL,1,NULL,0);
    VARXOR(NULL,0,R4,0,NULL,0);
    VARXOR(NULL,0,R4,1,NULL,0);
    VARXOR(NULL,0,R8,0,NULL,0);
    VARXOR(NULL,0,R8,1,NULL,0);
    rbstr = SysAllocString(szFalse);
    VARXOR(NULL,0,BSTR,rbstr,NULL,0);
3961
    SysFreeString(rbstr);
3962 3963
    rbstr = SysAllocString(szTrue);
    VARXOR(NULL,0,BSTR,rbstr,NULL,0);
3964
    SysFreeString(rbstr);
3965 3966 3967
    VARXORCY(NULL,0,10000,NULL,0);
    VARXORCY(NULL,0,0,NULL,0);

Jon Griffiths's avatar
Jon Griffiths committed
3968
    VARXOR(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
3969
    VARXOR(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
Jon Griffiths's avatar
Jon Griffiths committed
3970
    VARXOR(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999
    VARXOR(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
    /* Assume x,y & y,x are the same from now on to reduce the number of tests */
    VARXOR(BOOL,VARIANT_TRUE,I1,-1,I4,0);
    VARXOR(BOOL,VARIANT_TRUE,I1,0,I4,-1);
    VARXOR(BOOL,VARIANT_FALSE,I1,0,I4,0);
    VARXOR(BOOL,VARIANT_TRUE,UI1,255,I2,-256);
    VARXOR(BOOL,VARIANT_TRUE,UI1,0,I2,-1);
    VARXOR(BOOL,VARIANT_FALSE,UI1,0,I2,0);
    VARXOR(BOOL,VARIANT_TRUE,I2,-1,I2,0);
    VARXOR(BOOL,VARIANT_TRUE,I2,0,I2,-1);
    VARXOR(BOOL,VARIANT_FALSE,I2,0,I2,0);
    VARXOR(BOOL,VARIANT_TRUE,UI2,65535,I4,-65536);
    VARXOR(BOOL,VARIANT_TRUE,UI2,0,I4,-1);
    VARXOR(BOOL,VARIANT_FALSE,UI2,0,I4,0);
    VARXOR(BOOL,VARIANT_TRUE,I4,-1,I4,0);
    VARXOR(BOOL,VARIANT_TRUE,I4,0,I4,-1);
    VARXOR(BOOL,VARIANT_FALSE,I4,0,I4,0);
    VARXOR(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,0);
    VARXOR(BOOL,VARIANT_TRUE,UI4,0,I4,-1);
    VARXOR(BOOL,VARIANT_FALSE,UI4,0,I4,0);
    VARXOR(BOOL,VARIANT_TRUE,R4,-1,I4,0);
    VARXOR(BOOL,VARIANT_TRUE,R4,0,I4,-1);
    VARXOR(BOOL,VARIANT_FALSE,R4,0,I4,0);
    VARXOR(BOOL,VARIANT_TRUE,R8,-1,I4,0);
    VARXOR(BOOL,VARIANT_TRUE,R8,0,I4,-1);
    VARXOR(BOOL,VARIANT_FALSE,R8,0,I4,0);
    VARXOR(BOOL,VARIANT_TRUE,DATE,-1,I4,0);
    VARXOR(BOOL,VARIANT_TRUE,DATE,0,I4,-1);
    VARXOR(BOOL,VARIANT_FALSE,DATE,0,I4,0);
4000
    if (has_i8)
4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020
    {
        VARXOR(BOOL,VARIANT_TRUE,I8,-1,I8,0);
        VARXOR(BOOL,VARIANT_TRUE,I8,0,I8,-1);
        VARXOR(BOOL,VARIANT_FALSE,I8,0,I8,0);
        /* This returns DISP_E_OVERFLOW which indicates that a conversion
         * to I4 is performed.
         */
        /* VARXOR(BOOL,VARIANT_TRUE,UI8,-1,I4,-1); */
        VARXOR(BOOL,VARIANT_TRUE,UI8,0,I4,-1);
        VARXOR(BOOL,VARIANT_FALSE,UI8,0,I4,0);
    }
    VARXOR(BOOL,VARIANT_TRUE,INT,-1,I4,0);
    VARXOR(BOOL,VARIANT_TRUE,INT,0,I4,-1);
    VARXOR(BOOL,VARIANT_FALSE,INT,0,I4,0);
    VARXOR(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,0);
    VARXOR(BOOL,VARIANT_TRUE,UINT,0,I4,-1);
    VARXOR(BOOL,VARIANT_FALSE,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VARXOR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_FALSE);
    VARXOR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
4021
    SysFreeString(rbstr);
4022 4023 4024
    rbstr = SysAllocString(szTrue);
    VARXOR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_TRUE);
    VARXOR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_FALSE);
4025
    SysFreeString(rbstr);
4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056
    VARXORCY(BOOL,VARIANT_TRUE,10000,I4,-2);
    VARXORCY(BOOL,VARIANT_TRUE,0,I4,-1);
    VARXORCY(BOOL,VARIANT_FALSE,0,I4,0);

    VARXOR(I1,-1,I1,-1,I4,0);
    VARXOR(I1,-1,I1,0,I4,-1);
    VARXOR(I1,0,I1,0,I4,0);
    VARXOR(I1,-1,UI1,255,I4,-256);
    VARXOR(I1,-1,UI1,0,I4,-1);
    VARXOR(I1,0,UI1,0,I4,0);
    VARXOR(I1,-1,I2,-1,I4,0);
    VARXOR(I1,-1,I2,0,I4,-1);
    VARXOR(I1,0,I2,0,I4,0);
    VARXOR(I1,-1,UI2,65535,I4,-65536);
    VARXOR(I1,-1,UI2,0,I4,-1);
    VARXOR(I1,0,UI2,0,I4,0);
    VARXOR(I1,-1,I4,-1,I4,0);
    VARXOR(I1,-1,I4,0,I4,-1);
    VARXOR(I1,0,I4,0,I4,0);
    VARXOR(I1,-1,UI4,0xffffffff,I4,0);
    VARXOR(I1,-1,UI4,0,I4,-1);
    VARXOR(I1,0,UI4,0,I4,0);
    VARXOR(I1,-1,R4,-1,I4,0);
    VARXOR(I1,-1,R4,0,I4,-1);
    VARXOR(I1,0,R4,0,I4,0);
    VARXOR(I1,-1,R8,-1,I4,0);
    VARXOR(I1,-1,R8,0,I4,-1);
    VARXOR(I1,0,R8,0,I4,0);
    VARXOR(I1,-1,DATE,-1,I4,0);
    VARXOR(I1,-1,DATE,0,I4,-1);
    VARXOR(I1,0,DATE,0,I4,0);
4057
    if (has_i8)
4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073
    {
        VARXOR(I1,-1,I8,-1,I8,0);
        VARXOR(I1,-1,I8,0,I8,-1);
        VARXOR(I1,0,I8,0,I8,0);
        VARXOR(I1,-1,UI8,0,I4,-1);
        VARXOR(I1,0,UI8,0,I4,0);
    }
    VARXOR(I1,-1,INT,-1,I4,0);
    VARXOR(I1,-1,INT,0,I4,-1);
    VARXOR(I1,0,INT,0,I4,0);
    VARXOR(I1,-1,UINT,0xffffffff,I4,0);
    VARXOR(I1,-1,UINT,0,I4,-1);
    VARXOR(I1,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VARXOR(I1,0,BSTR,rbstr,I4,0);
    VARXOR(I1,-1,BSTR,rbstr,I4,-1);
4074
    SysFreeString(rbstr);
4075 4076 4077
    rbstr = SysAllocString(szTrue);
    VARXOR(I1,0,BSTR,rbstr,I4,-1);
    VARXOR(I1,-1,BSTR,rbstr,I4,0);
4078
    SysFreeString(rbstr);
4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106
    VARXORCY(I1,-1,10000,I4,-2);
    VARXORCY(I1,-1,0,I4,-1);
    VARXORCY(I1,0,0,I4,0);

    VARXOR(UI1,255,UI1,255,UI1,0);
    VARXOR(UI1,255,UI1,0,UI1,255);
    VARXOR(UI1,0,UI1,0,UI1,0);
    VARXOR(UI1,255,I2,-1,I2,-256);
    VARXOR(UI1,255,I2,0,I2,255);
    VARXOR(UI1,0,I2,0,I2,0);
    VARXOR(UI1,255,UI2,65535,I4,65280);
    VARXOR(UI1,255,UI2,0,I4,255);
    VARXOR(UI1,0,UI2,0,I4,0);
    VARXOR(UI1,255,I4,-1,I4,-256);
    VARXOR(UI1,255,I4,0,I4,255);
    VARXOR(UI1,0,I4,0,I4,0);
    VARXOR(UI1,255,UI4,0xffffffff,I4,-256);
    VARXOR(UI1,255,UI4,0,I4,255);
    VARXOR(UI1,0,UI4,0,I4,0);
    VARXOR(UI1,255,R4,-1,I4,-256);
    VARXOR(UI1,255,R4,0,I4,255);
    VARXOR(UI1,0,R4,0,I4,0);
    VARXOR(UI1,255,R8,-1,I4,-256);
    VARXOR(UI1,255,R8,0,I4,255);
    VARXOR(UI1,0,R8,0,I4,0);
    VARXOR(UI1,255,DATE,-1,I4,-256);
    VARXOR(UI1,255,DATE,0,I4,255);
    VARXOR(UI1,0,DATE,0,I4,0);
4107
    if (has_i8)
4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123
    {
        VARXOR(UI1,255,I8,-1,I8,-256);
        VARXOR(UI1,255,I8,0,I8,255);
        VARXOR(UI1,0,I8,0,I8,0);
        VARXOR(UI1,255,UI8,0,I4,255);
        VARXOR(UI1,0,UI8,0,I4,0);
    }
    VARXOR(UI1,255,INT,-1,I4,-256);
    VARXOR(UI1,255,INT,0,I4,255);
    VARXOR(UI1,0,INT,0,I4,0);
    VARXOR(UI1,255,UINT,0xffffffff,I4,-256);
    VARXOR(UI1,255,UINT,0,I4,255);
    VARXOR(UI1,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VARXOR(UI1,0,BSTR,rbstr,I2,0);
    VARXOR(UI1,255,BSTR,rbstr,I2,255);
4124
    SysFreeString(rbstr);
4125 4126 4127
    rbstr = SysAllocString(szTrue);
    VARXOR(UI1,0,BSTR,rbstr,I2,-1);
    VARXOR(UI1,255,BSTR,rbstr,I2,-256);
4128
    SysFreeString(rbstr);
4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153
    VARXORCY(UI1,255,10000,I4,254);
    VARXORCY(UI1,255,0,I4,255);
    VARXORCY(UI1,0,0,I4,0);

    VARXOR(I2,-1,I2,-1,I2,0);
    VARXOR(I2,-1,I2,0,I2,-1);
    VARXOR(I2,0,I2,0,I2,0);
    VARXOR(I2,-1,UI2,65535,I4,-65536);
    VARXOR(I2,-1,UI2,0,I4,-1);
    VARXOR(I2,0,UI2,0,I4,0);
    VARXOR(I2,-1,I4,-1,I4,0);
    VARXOR(I2,-1,I4,0,I4,-1);
    VARXOR(I2,0,I4,0,I4,0);
    VARXOR(I2,-1,UI4,0xffffffff,I4,0);
    VARXOR(I2,-1,UI4,0,I4,-1);
    VARXOR(I2,0,UI4,0,I4,0);
    VARXOR(I2,-1,R4,-1,I4,0);
    VARXOR(I2,-1,R4,0,I4,-1);
    VARXOR(I2,0,R4,0,I4,0);
    VARXOR(I2,-1,R8,-1,I4,0);
    VARXOR(I2,-1,R8,0,I4,-1);
    VARXOR(I2,0,R8,0,I4,0);
    VARXOR(I2,-1,DATE,-1,I4,0);
    VARXOR(I2,-1,DATE,0,I4,-1);
    VARXOR(I2,0,DATE,0,I4,0);
4154
    if (has_i8)
4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170
    {
        VARXOR(I2,-1,I8,-1,I8,0);
        VARXOR(I2,-1,I8,0,I8,-1);
        VARXOR(I2,0,I8,0,I8,0);
        VARXOR(I2,-1,UI8,0,I4,-1);
        VARXOR(I2,0,UI8,0,I4,0);
    }
    VARXOR(I2,-1,INT,-1,I4,0);
    VARXOR(I2,-1,INT,0,I4,-1);
    VARXOR(I2,0,INT,0,I4,0);
    VARXOR(I2,-1,UINT,0xffffffff,I4,0);
    VARXOR(I2,-1,UINT,0,I4,-1);
    VARXOR(I2,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VARXOR(I2,0,BSTR,rbstr,I2,0);
    VARXOR(I2,-1,BSTR,rbstr,I2,-1);
4171
    SysFreeString(rbstr);
4172 4173 4174
    rbstr = SysAllocString(szTrue);
    VARXOR(I2,0,BSTR,rbstr,I2,-1);
    VARXOR(I2,-1,BSTR,rbstr,I2,0);
4175
    SysFreeString(rbstr);
4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197
    VARXORCY(I2,-1,10000,I4,-2);
    VARXORCY(I2,-1,0,I4,-1);
    VARXORCY(I2,0,0,I4,0);

    VARXOR(UI2,65535,UI2,65535,I4,0);
    VARXOR(UI2,65535,UI2,0,I4,65535);
    VARXOR(UI2,0,UI2,0,I4,0);
    VARXOR(UI2,65535,I4,-1,I4,-65536);
    VARXOR(UI2,65535,I4,0,I4,65535);
    VARXOR(UI2,0,I4,0,I4,0);
    VARXOR(UI2,65535,UI4,0xffffffff,I4,-65536);
    VARXOR(UI2,65535,UI4,0,I4,65535);
    VARXOR(UI2,0,UI4,0,I4,0);
    VARXOR(UI2,65535,R4,-1,I4,-65536);
    VARXOR(UI2,65535,R4,0,I4,65535);
    VARXOR(UI2,0,R4,0,I4,0);
    VARXOR(UI2,65535,R8,-1,I4,-65536);
    VARXOR(UI2,65535,R8,0,I4,65535);
    VARXOR(UI2,0,R8,0,I4,0);
    VARXOR(UI2,65535,DATE,-1,I4,-65536);
    VARXOR(UI2,65535,DATE,0,I4,65535);
    VARXOR(UI2,0,DATE,0,I4,0);
4198
    if (has_i8)
4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214
    {
        VARXOR(UI2,65535,I8,-1,I8,-65536);
        VARXOR(UI2,65535,I8,0,I8,65535);
        VARXOR(UI2,0,I8,0,I8,0);
        VARXOR(UI2,65535,UI8,0,I4,65535);
        VARXOR(UI2,0,UI8,0,I4,0);
    }
    VARXOR(UI2,65535,INT,-1,I4,-65536);
    VARXOR(UI2,65535,INT,0,I4,65535);
    VARXOR(UI2,0,INT,0,I4,0);
    VARXOR(UI2,65535,UINT,0xffffffff,I4,-65536);
    VARXOR(UI2,65535,UINT,0,I4,65535);
    VARXOR(UI2,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VARXOR(UI2,0,BSTR,rbstr,I4,0);
    VARXOR(UI2,65535,BSTR,rbstr,I4,65535);
4215
    SysFreeString(rbstr);
4216 4217 4218
    rbstr = SysAllocString(szTrue);
    VARXOR(UI2,0,BSTR,rbstr,I4,-1);
    VARXOR(UI2,65535,BSTR,rbstr,I4,-65536);
4219
    SysFreeString(rbstr);
4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238
    VARXORCY(UI2,65535,10000,I4,65534);
    VARXORCY(UI2,65535,0,I4,65535);
    VARXORCY(UI2,0,0,I4,0);

    VARXOR(I4,-1,I4,-1,I4,0);
    VARXOR(I4,-1,I4,0,I4,-1);
    VARXOR(I4,0,I4,0,I4,0);
    VARXOR(I4,-1,UI4,0xffffffff,I4,0);
    VARXOR(I4,-1,UI4,0,I4,-1);
    VARXOR(I4,0,UI4,0,I4,0);
    VARXOR(I4,-1,R4,-1,I4,0);
    VARXOR(I4,-1,R4,0,I4,-1);
    VARXOR(I4,0,R4,0,I4,0);
    VARXOR(I4,-1,R8,-1,I4,0);
    VARXOR(I4,-1,R8,0,I4,-1);
    VARXOR(I4,0,R8,0,I4,0);
    VARXOR(I4,-1,DATE,-1,I4,0);
    VARXOR(I4,-1,DATE,0,I4,-1);
    VARXOR(I4,0,DATE,0,I4,0);
4239
    if (has_i8)
4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255
    {
        VARXOR(I4,-1,I8,-1,I8,0);
        VARXOR(I4,-1,I8,0,I8,-1);
        VARXOR(I4,0,I8,0,I8,0);
        VARXOR(I4,-1,UI8,0,I4,-1);
        VARXOR(I4,0,UI8,0,I4,0);
    }
    VARXOR(I4,-1,INT,-1,I4,0);
    VARXOR(I4,-1,INT,0,I4,-1);
    VARXOR(I4,0,INT,0,I4,0);
    VARXOR(I4,-1,UINT,0xffffffff,I4,0);
    VARXOR(I4,-1,UINT,0,I4,-1);
    VARXOR(I4,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VARXOR(I4,0,BSTR,rbstr,I4,0);
    VARXOR(I4,-1,BSTR,rbstr,I4,-1);
4256
    SysFreeString(rbstr);
4257 4258 4259
    rbstr = SysAllocString(szTrue);
    VARXOR(I4,0,BSTR,rbstr,I4,-1);
    VARXOR(I4,-1,BSTR,rbstr,I4,0);
4260
    SysFreeString(rbstr);
4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276
    VARXORCY(I4,-1,10000,I4,-2);
    VARXORCY(I4,-1,0,I4,-1);
    VARXORCY(I4,0,0,I4,0);

    VARXOR(UI4,0xffffffff,UI4,0xffffffff,I4,0);
    VARXOR(UI4,0xffffffff,UI4,0,I4,-1);
    VARXOR(UI4,0,UI4,0,I4,0);
    VARXOR(UI4,0xffffffff,R4,-1,I4,0);
    VARXOR(UI4,0xffffffff,R4,0,I4,-1);
    VARXOR(UI4,0,R4,0,I4,0);
    VARXOR(UI4,0xffffffff,R8,-1,I4,0);
    VARXOR(UI4,0xffffffff,R8,0,I4,-1);
    VARXOR(UI4,0,R8,0,I4,0);
    VARXOR(UI4,0xffffffff,DATE,-1,I4,0);
    VARXOR(UI4,0xffffffff,DATE,0,I4,-1);
    VARXOR(UI4,0,DATE,0,I4,0);
4277
    if (has_i8)
4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293
    {
        VARXOR(UI4,0xffffffff,I8,0,I8,0xffffffff);
        VARXOR(UI4,VARIANT_FALSE,I8,VARIANT_FALSE,I8,0);
        VARXOR(UI4,0,I8,0,I8,0);
        VARXOR(UI4,0xffffffff,UI8,0,I4,-1);
        VARXOR(UI4,0,UI8,0,I4,0);
    }
    VARXOR(UI4,0xffffffff,INT,-1,I4,0);
    VARXOR(UI4,0xffffffff,INT,0,I4,-1);
    VARXOR(UI4,0,INT,0,I4,0);
    VARXOR(UI4,0xffffffff,UINT,0xffffffff,I4,0);
    VARXOR(UI4,0xffffffff,UINT,0,I4,-1);
    VARXOR(UI4,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VARXOR(UI4,0,BSTR,rbstr,I4,0);
    VARXOR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
4294
    SysFreeString(rbstr);
4295 4296 4297
    rbstr = SysAllocString(szTrue);
    VARXOR(UI4,0,BSTR,rbstr,I4,-1);
    VARXOR(UI4,0xffffffff,BSTR,rbstr,I4,0);
4298
    SysFreeString(rbstr);
4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311
    VARXORCY(UI4,0xffffffff,10000,I4,-2);
    VARXORCY(UI4,0xffffffff,0,I4,-1);
    VARXORCY(UI4,0,0,I4,0);

    VARXOR(R4,-1,R4,-1,I4,0);
    VARXOR(R4,-1,R4,0,I4,-1);
    VARXOR(R4,0,R4,0,I4,0);
    VARXOR(R4,-1,R8,-1,I4,0);
    VARXOR(R4,-1,R8,0,I4,-1);
    VARXOR(R4,0,R8,0,I4,0);
    VARXOR(R4,-1,DATE,-1,I4,0);
    VARXOR(R4,-1,DATE,0,I4,-1);
    VARXOR(R4,0,DATE,0,I4,0);
4312
    if (has_i8)
4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328
    {
        VARXOR(R4,-1,I8,-1,I8,0);
        VARXOR(R4,-1,I8,0,I8,-1);
        VARXOR(R4,0,I8,0,I8,0);
        VARXOR(R4,-1,UI8,0,I4,-1);
        VARXOR(R4,0,UI8,0,I4,0);
    }
    VARXOR(R4,-1,INT,-1,I4,0);
    VARXOR(R4,-1,INT,0,I4,-1);
    VARXOR(R4,0,INT,0,I4,0);
    VARXOR(R4,-1,UINT,0xffffffff,I4,0);
    VARXOR(R4,-1,UINT,0,I4,-1);
    VARXOR(R4,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VARXOR(R4,0,BSTR,rbstr,I4,0);
    VARXOR(R4,-1,BSTR,rbstr,I4,-1);
4329
    SysFreeString(rbstr);
4330 4331 4332
    rbstr = SysAllocString(szTrue);
    VARXOR(R4,0,BSTR,rbstr,I4,-1);
    VARXOR(R4,-1,BSTR,rbstr,I4,0);
4333
    SysFreeString(rbstr);
4334 4335 4336 4337 4338 4339 4340 4341 4342 4343
    VARXORCY(R4,-1,10000,I4,-2);
    VARXORCY(R4,-1,0,I4,-1);
    VARXORCY(R4,0,0,I4,0);

    VARXOR(R8,-1,R8,-1,I4,0);
    VARXOR(R8,-1,R8,0,I4,-1);
    VARXOR(R8,0,R8,0,I4,0);
    VARXOR(R8,-1,DATE,-1,I4,0);
    VARXOR(R8,-1,DATE,0,I4,-1);
    VARXOR(R8,0,DATE,0,I4,0);
4344
    if (has_i8)
4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360
    {
        VARXOR(R8,-1,I8,-1,I8,0);
        VARXOR(R8,-1,I8,0,I8,-1);
        VARXOR(R8,0,I8,0,I8,0);
        VARXOR(R8,-1,UI8,0,I4,-1);
        VARXOR(R8,0,UI8,0,I4,0);
    }
    VARXOR(R8,-1,INT,-1,I4,0);
    VARXOR(R8,-1,INT,0,I4,-1);
    VARXOR(R8,0,INT,0,I4,0);
    VARXOR(R8,-1,UINT,0xffffffff,I4,0);
    VARXOR(R8,-1,UINT,0,I4,-1);
    VARXOR(R8,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VARXOR(R8,0,BSTR,rbstr,I4,0);
    VARXOR(R8,-1,BSTR,rbstr,I4,-1);
4361
    SysFreeString(rbstr);
4362 4363 4364
    rbstr = SysAllocString(szTrue);
    VARXOR(R8,0,BSTR,rbstr,I4,-1);
    VARXOR(R8,-1,BSTR,rbstr,I4,0);
4365
    SysFreeString(rbstr);
4366 4367 4368 4369 4370 4371 4372
    VARXORCY(R8,-1,10000,I4,-2);
    VARXORCY(R8,-1,0,I4,-1);
    VARXORCY(R8,0,0,I4,0);

    VARXOR(DATE,-1,DATE,-1,I4,0);
    VARXOR(DATE,-1,DATE,0,I4,-1);
    VARXOR(DATE,0,DATE,0,I4,0);
4373
    if (has_i8)
Jon Griffiths's avatar
Jon Griffiths committed
4374
    {
4375 4376 4377 4378 4379
        VARXOR(DATE,-1,I8,-1,I8,0);
        VARXOR(DATE,-1,I8,0,I8,-1);
        VARXOR(DATE,0,I8,0,I8,0);
        VARXOR(DATE,-1,UI8,0,I4,-1);
        VARXOR(DATE,0,UI8,0,I4,0);
Jon Griffiths's avatar
Jon Griffiths committed
4380
    }
4381 4382 4383 4384 4385 4386 4387 4388 4389
    VARXOR(DATE,-1,INT,-1,I4,0);
    VARXOR(DATE,-1,INT,0,I4,-1);
    VARXOR(DATE,0,INT,0,I4,0);
    VARXOR(DATE,-1,UINT,0xffffffff,I4,0);
    VARXOR(DATE,-1,UINT,0,I4,-1);
    VARXOR(DATE,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VARXOR(DATE,0,BSTR,rbstr,I4,0);
    VARXOR(DATE,-1,BSTR,rbstr,I4,-1);
4390
    SysFreeString(rbstr);
4391 4392 4393
    rbstr = SysAllocString(szTrue);
    VARXOR(DATE,0,BSTR,rbstr,I4,-1);
    VARXOR(DATE,-1,BSTR,rbstr,I4,0);
4394
    SysFreeString(rbstr);
4395 4396 4397
    VARXORCY(DATE,-1,10000,I4,-2);
    VARXORCY(DATE,-1,0,I4,-1);
    VARXORCY(DATE,0,0,I4,0);
Jon Griffiths's avatar
Jon Griffiths committed
4398

4399
    if (has_i8)
4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410
    {
        VARXOR(I8,-1,I8,-1,I8,0);
        VARXOR(I8,-1,I8,0,I8,-1);
        VARXOR(I8,0,I8,0,I8,0);
        VARXOR(I8,-1,UI8,0,I8,-1);
        VARXOR(I8,0,UI8,0,I8,0);
        VARXOR(I8,-1,UINT,0,I8,-1);
        VARXOR(I8,0,UINT,0,I8,0);
        rbstr = SysAllocString(szFalse);
        VARXOR(I8,0,BSTR,rbstr,I8,0);
        VARXOR(I8,-1,BSTR,rbstr,I8,-1);
4411
        SysFreeString(rbstr);
4412 4413 4414
        rbstr = SysAllocString(szTrue);
        VARXOR(I8,0,BSTR,rbstr,I8,-1);
        VARXOR(I8,-1,BSTR,rbstr,I8,0);
4415
        SysFreeString(rbstr);
4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431
        VARXORCY(I8,-1,10000,I8,-2);
        VARXORCY(I8,-1,0,I8,-1);
        VARXORCY(I8,0,0,I8,0);

        VARXOR(UI8,0xffff,UI8,0xffff,I4,0);
        VARXOR(UI8,0xffff,UI8,0,I4,0xffff);
        VARXOR(UI8,0,UI8,0,I4,0);
        VARXOR(UI8,0xffff,INT,-1,I4,-65536);
        VARXOR(UI8,0xffff,INT,0,I4,0xffff);
        VARXOR(UI8,0,INT,0,I4,0);
        VARXOR(UI8,0xffff,UINT,0xffff,I4,0);
        VARXOR(UI8,0xffff,UINT,0,I4,0xffff);
        VARXOR(UI8,0,UINT,0,I4,0);
        rbstr = SysAllocString(szFalse);
        VARXOR(UI8,0,BSTR,rbstr,I4,0);
        VARXOR(UI8,0xffff,BSTR,rbstr,I4,0xffff);
4432
        SysFreeString(rbstr);
4433 4434 4435
        rbstr = SysAllocString(szTrue);
        VARXOR(UI8,0,BSTR,rbstr,I4,-1);
        VARXOR(UI8,0xffff,BSTR,rbstr,I4,-65536);
4436
        SysFreeString(rbstr);
4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450
        VARXORCY(UI8,0xffff,10000,I4,65534);
        VARXORCY(UI8,0xffff,0,I4,0xffff);
        VARXORCY(UI8,0,0,I4,0);
    }

    VARXOR(INT,-1,INT,-1,I4,0);
    VARXOR(INT,-1,INT,0,I4,-1);
    VARXOR(INT,0,INT,0,I4,0);
    VARXOR(INT,-1,UINT,0xffff,I4,-65536);
    VARXOR(INT,-1,UINT,0,I4,-1);
    VARXOR(INT,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VARXOR(INT,0,BSTR,rbstr,I4,0);
    VARXOR(INT,-1,BSTR,rbstr,I4,-1);
4451
    SysFreeString(rbstr);
4452 4453 4454
    rbstr = SysAllocString(szTrue);
    VARXOR(INT,0,BSTR,rbstr,I4,-1);
    VARXOR(INT,-1,BSTR,rbstr,I4,0);
4455
    SysFreeString(rbstr);
4456 4457 4458 4459 4460 4461 4462 4463 4464 4465
    VARXORCY(INT,-1,10000,I4,-2);
    VARXORCY(INT,-1,0,I4,-1);
    VARXORCY(INT,0,0,I4,0);

    VARXOR(UINT,0xffff,UINT,0xffff,I4,0);
    VARXOR(UINT,0xffff,UINT,0,I4,0xffff);
    VARXOR(UINT,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VARXOR(UINT,0,BSTR,rbstr,I4,0);
    VARXOR(UINT,0xffff,BSTR,rbstr,I4,0xffff);
4466
    SysFreeString(rbstr);
4467 4468 4469
    rbstr = SysAllocString(szTrue);
    VARXOR(UINT,0,BSTR,rbstr,I4,-1);
    VARXOR(UINT,0xffff,BSTR,rbstr,I4,-65536);
4470
    SysFreeString(rbstr);
4471 4472 4473 4474 4475 4476 4477
    VARXORCY(UINT,0xffff,10000,I4,65534);
    VARXORCY(UINT,0xffff,0,I4,0xffff);
    VARXORCY(UINT,0,0,I4,0);

    lbstr = SysAllocString(szFalse);
    rbstr = SysAllocString(szFalse);
    VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,0);
4478
    SysFreeString(rbstr);
4479 4480
    rbstr = SysAllocString(szTrue);
    VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
4481
    SysFreeString(lbstr);
4482 4483 4484
    lbstr = SysAllocString(szTrue);
    VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_FALSE);
    VARXORCY(BSTR,lbstr,10000,I4,-2);
4485
    SysFreeString(lbstr);
4486 4487
    lbstr = SysAllocString(szFalse);
    VARXORCY(BSTR,lbstr,10000,I4,1);
4488 4489
    SysFreeString(lbstr);
    SysFreeString(rbstr);
Jon Griffiths's avatar
Jon Griffiths committed
4490 4491
}

4492 4493
static HRESULT (WINAPI *pVarOr)(LPVARIANT,LPVARIANT,LPVARIANT);

4494 4495
#define VAROR(vt1,val1,vt2,val2,rvt,rval)                \
        V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
4496
        V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
4497
        V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
4498
        test_var_call2( __LINE__, pVarOr, &left, &right, &exp )
4499 4500 4501

#define VARORCY(vt1,val1,val2,rvt,rval)                  \
        V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
4502
        V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \
4503
        V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
4504
        test_var_call2( __LINE__, pVarOr, &left, &right, &exp )
Jon Griffiths's avatar
Jon Griffiths committed
4505

4506 4507 4508 4509
static void test_VarOr(void)
{
    static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
    static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
4510
    VARIANT left, right, exp, result;
4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605
    BSTR lbstr, rbstr;
    VARTYPE i;
    HRESULT hres;

    CHECKPTR(VarOr);

    /* Test all possible flag/vt combinations & the resulting vt type */
    for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
    {
        VARTYPE leftvt, rightvt, resvt;

        for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
        {
        
            SKIPTESTS(leftvt);
        
            for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
            {
                BOOL bFail = FALSE;

                SKIPTESTS(rightvt);
                
                if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
                    leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
                    leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
                    continue;

                memset(&left, 0, sizeof(left));
                memset(&right, 0, sizeof(right));
                V_VT(&left) = leftvt | ExtraFlags[i];
                V_VT(&right) = rightvt | ExtraFlags[i];
                V_VT(&result) = VT_EMPTY;
                resvt = VT_I4;

                if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
                    !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
                    !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
                    leftvt == VT_CLSID || rightvt == VT_CLSID ||
                    leftvt == VT_RECORD || rightvt == VT_RECORD ||
                    leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
                    leftvt == VT_ERROR || rightvt == VT_ERROR)
                {
                    bFail = TRUE;
                }
                if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
                {
                    if (leftvt == rightvt ||
                        leftvt == VT_I2 || rightvt == VT_I2 ||
                        leftvt == VT_UI1 || rightvt == VT_UI1 ||
                        leftvt == VT_BOOL || rightvt == VT_BOOL)
                        resvt = VT_I2;
                    else if (leftvt == VT_NULL || rightvt == VT_NULL)
                        resvt = VT_NULL;
                    else if (leftvt == VT_I8 || rightvt == VT_I8)
                        resvt = VT_I8;
                }
                else if (leftvt == VT_NULL || rightvt == VT_NULL)
                {
                    resvt = VT_NULL;
                }
                else if (leftvt == VT_UI1 || rightvt == VT_UI1)
                {
                    if (leftvt == rightvt)
                        resvt = VT_UI1;
                    else if (leftvt == rightvt ||
                        leftvt == VT_I2 || rightvt == VT_I2 ||
                        leftvt == VT_BOOL || rightvt == VT_BOOL)
                    {
                        resvt = VT_I2;
                    }
                    else if (leftvt == VT_I8 || rightvt == VT_I8)
                        resvt = VT_I8;
                }
                else if (leftvt == VT_I2 || rightvt == VT_I2)
                {
                    if (leftvt == rightvt ||
                        leftvt == VT_BOOL || rightvt == VT_BOOL)
                        resvt = VT_I2;
                    else if (leftvt == VT_I8 || rightvt == VT_I8)
                        resvt = VT_I8;
                }
                else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
                {
                    resvt = VT_BOOL;
                }
                else if (leftvt == VT_I8 || rightvt == VT_I8)
                {
                    if (leftvt == VT_INT || rightvt == VT_INT)
                        bFail = TRUE;
                    else
                        resvt = VT_I8;
                }
                hres = pVarOr(&left, &right, &result);
                if (bFail)
                    ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
4606
                       "VarOr: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
4607 4608 4609 4610
                       leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
                       V_VT(&result));
                else
                    ok(hres == S_OK && V_VT(&result) == resvt,
4611
                       "VarOr: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637
                       leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
                       V_VT(&result));
            }
        }
    }

    /* Test returned values. Since we know the returned type is correct
     * and that we handle all combinations of invalid types, just check
     * that good type combinations produce the desired value.
     * FIXME: Test VT_DECIMAL/VT_DISPATCH
     */
    VAROR(EMPTY,0,EMPTY,0,I2,0);
    VAROR(EMPTY,1,EMPTY,0,I2,0);
    VAROR(EMPTY,0,NULL,0,NULL,0);
    VAROR(EMPTY,0,I1,0,I4,0);
    VAROR(EMPTY,0,I1,1,I4,1);
    VAROR(EMPTY,0,UI1,0,I2,0);
    VAROR(EMPTY,0,UI1,1,I2,1);
    VAROR(EMPTY,0,I2,0,I2,0);
    VAROR(EMPTY,0,I2,1,I2,1);
    VAROR(EMPTY,0,UI2,0,I4,0);
    VAROR(EMPTY,0,UI2,1,I4,1);
    VAROR(EMPTY,0,I4,0,I4,0);
    VAROR(EMPTY,0,I4,1,I4,1);
    VAROR(EMPTY,0,UI4,0,I4,0);
    VAROR(EMPTY,0,UI4,1,I4,1);
4638
    if (has_i8)
4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656
    {
        VAROR(EMPTY,0,I8,0,I8,0);
        VAROR(EMPTY,0,I8,1,I8,1);
        VAROR(EMPTY,0,UI8,0,I4,0);
        VAROR(EMPTY,0,UI8,1,I4,1);
    }
    VAROR(EMPTY,0,INT,0,I4,0);
    VAROR(EMPTY,0,INT,1,I4,1);
    VAROR(EMPTY,0,UINT,0,I4,0);
    VAROR(EMPTY,0,UINT,1,I4,1);
    VAROR(EMPTY,0,BOOL,0,I2,0);
    VAROR(EMPTY,0,BOOL,1,I2,1);
    VAROR(EMPTY,0,R4,0,I4,0);
    VAROR(EMPTY,0,R4,1,I4,1);
    VAROR(EMPTY,0,R8,0,I4,0);
    VAROR(EMPTY,0,R8,1,I4,1);
    rbstr = SysAllocString(szFalse);
    VAROR(EMPTY,0,BSTR,rbstr,I2,0);
4657
    SysFreeString(rbstr);
4658 4659
    rbstr = SysAllocString(szTrue);
    VAROR(EMPTY,0,BSTR,rbstr,I2,-1);
4660
    SysFreeString(rbstr);
4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677
    VARORCY(EMPTY,0,10000,I4,1);

    /* NULL OR 0 = NULL. NULL OR n = n */
    VAROR(NULL,0,NULL,0,NULL,0);
    VAROR(NULL,1,NULL,0,NULL,0);
    VAROR(NULL,0,I1,0,NULL,0);
    VAROR(NULL,0,I1,1,I4,1);
    VAROR(NULL,0,UI1,0,NULL,0);
    VAROR(NULL,0,UI1,1,UI1,1);
    VAROR(NULL,0,I2,0,NULL,0);
    VAROR(NULL,0,I2,1,I2,1);
    VAROR(NULL,0,UI2,0,NULL,0);
    VAROR(NULL,0,UI2,1,I4,1);
    VAROR(NULL,0,I4,0,NULL,0);
    VAROR(NULL,0,I4,1,I4,1);
    VAROR(NULL,0,UI4,0,NULL,0);
    VAROR(NULL,0,UI4,1,I4,1);
4678
    if (has_i8)
4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696
    {
        VAROR(NULL,0,I8,0,NULL,0);
        VAROR(NULL,0,I8,1,I8,1);
        VAROR(NULL,0,UI8,0,NULL,0);
        VAROR(NULL,0,UI8,1,I4,1);
    }
    VAROR(NULL,0,INT,0,NULL,0);
    VAROR(NULL,0,INT,1,I4,1);
    VAROR(NULL,0,UINT,0,NULL,0);
    VAROR(NULL,0,UINT,1,I4,1);
    VAROR(NULL,0,BOOL,0,NULL,0);
    VAROR(NULL,0,BOOL,1,BOOL,1);
    VAROR(NULL,0,R4,0,NULL,0);
    VAROR(NULL,0,R4,1,I4,1);
    VAROR(NULL,0,R8,0,NULL,0);
    VAROR(NULL,0,R8,1,I4,1);
    rbstr = SysAllocString(szFalse);
    VAROR(NULL,0,BSTR,rbstr,NULL,0);
4697
    SysFreeString(rbstr);
4698 4699
    rbstr = SysAllocString(szTrue);
    VAROR(NULL,0,BSTR,rbstr,BOOL,VARIANT_TRUE);
4700
    SysFreeString(rbstr);
4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735
    VARORCY(NULL,0,10000,I4,1);
    VARORCY(NULL,0,0,NULL,0);

    VAROR(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
    VAROR(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
    VAROR(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
    VAROR(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
    /* Assume x,y & y,x are the same from now on to reduce the number of tests */
    VAROR(BOOL,VARIANT_TRUE,I1,-1,I4,-1);
    VAROR(BOOL,VARIANT_TRUE,I1,0,I4,-1);
    VAROR(BOOL,VARIANT_FALSE,I1,0,I4,0);
    VAROR(BOOL,VARIANT_TRUE,UI1,255,I2,-1);
    VAROR(BOOL,VARIANT_TRUE,UI1,0,I2,-1);
    VAROR(BOOL,VARIANT_FALSE,UI1,0,I2,0);
    VAROR(BOOL,VARIANT_TRUE,I2,-1,I2,-1);
    VAROR(BOOL,VARIANT_TRUE,I2,0,I2,-1);
    VAROR(BOOL,VARIANT_FALSE,I2,0,I2,0);
    VAROR(BOOL,VARIANT_TRUE,UI2,65535,I4,-1);
    VAROR(BOOL,VARIANT_TRUE,UI2,0,I4,-1);
    VAROR(BOOL,VARIANT_FALSE,UI2,0,I4,0);
    VAROR(BOOL,VARIANT_TRUE,I4,-1,I4,-1);
    VAROR(BOOL,VARIANT_TRUE,I4,0,I4,-1);
    VAROR(BOOL,VARIANT_FALSE,I4,0,I4,0);
    VAROR(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,-1);
    VAROR(BOOL,VARIANT_TRUE,UI4,0,I4,-1);
    VAROR(BOOL,VARIANT_FALSE,UI4,0,I4,0);
    VAROR(BOOL,VARIANT_TRUE,R4,-1,I4,-1);
    VAROR(BOOL,VARIANT_TRUE,R4,0,I4,-1);
    VAROR(BOOL,VARIANT_FALSE,R4,0,I4,0);
    VAROR(BOOL,VARIANT_TRUE,R8,-1,I4,-1);
    VAROR(BOOL,VARIANT_TRUE,R8,0,I4,-1);
    VAROR(BOOL,VARIANT_FALSE,R8,0,I4,0);
    VAROR(BOOL,VARIANT_TRUE,DATE,-1,I4,-1);
    VAROR(BOOL,VARIANT_TRUE,DATE,0,I4,-1);
    VAROR(BOOL,VARIANT_FALSE,DATE,0,I4,0);
4736
    if (has_i8)
4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756
    {
        VAROR(BOOL,VARIANT_TRUE,I8,-1,I8,-1);
        VAROR(BOOL,VARIANT_TRUE,I8,0,I8,-1);
        VAROR(BOOL,VARIANT_FALSE,I8,0,I8,0);
        /* This returns DISP_E_OVERFLOW which indicates that a conversion
         * to I4 is performed.
         */
        /* VAROR(BOOL,VARIANT_TRUE,UI8,-1,I4,-1); */
        VAROR(BOOL,VARIANT_TRUE,UI8,0,I4,-1);
        VAROR(BOOL,VARIANT_FALSE,UI8,0,I4,0);
    }
    VAROR(BOOL,VARIANT_TRUE,INT,-1,I4,-1);
    VAROR(BOOL,VARIANT_TRUE,INT,0,I4,-1);
    VAROR(BOOL,VARIANT_FALSE,INT,0,I4,0);
    VAROR(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,-1);
    VAROR(BOOL,VARIANT_TRUE,UINT,0,I4,-1);
    VAROR(BOOL,VARIANT_FALSE,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VAROR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_FALSE);
    VAROR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
4757
    SysFreeString(rbstr);
4758 4759 4760
    rbstr = SysAllocString(szTrue);
    VAROR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_TRUE);
    VAROR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
4761
    SysFreeString(rbstr);
4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792
    VARORCY(BOOL,VARIANT_TRUE,10000,I4,-1);
    VARORCY(BOOL,VARIANT_TRUE,0,I4,-1);
    VARORCY(BOOL,VARIANT_FALSE,0,I4,0);

    VAROR(I1,-1,I1,-1,I4,-1);
    VAROR(I1,-1,I1,0,I4,-1);
    VAROR(I1,0,I1,0,I4,0);
    VAROR(I1,-1,UI1,255,I4,-1);
    VAROR(I1,-1,UI1,0,I4,-1);
    VAROR(I1,0,UI1,0,I4,0);
    VAROR(I1,-1,I2,-1,I4,-1);
    VAROR(I1,-1,I2,0,I4,-1);
    VAROR(I1,0,I2,0,I4,0);
    VAROR(I1,-1,UI2,65535,I4,-1);
    VAROR(I1,-1,UI2,0,I4,-1);
    VAROR(I1,0,UI2,0,I4,0);
    VAROR(I1,-1,I4,-1,I4,-1);
    VAROR(I1,-1,I4,0,I4,-1);
    VAROR(I1,0,I4,0,I4,0);
    VAROR(I1,-1,UI4,0xffffffff,I4,-1);
    VAROR(I1,-1,UI4,0,I4,-1);
    VAROR(I1,0,UI4,0,I4,0);
    VAROR(I1,-1,R4,-1,I4,-1);
    VAROR(I1,-1,R4,0,I4,-1);
    VAROR(I1,0,R4,0,I4,0);
    VAROR(I1,-1,R8,-1,I4,-1);
    VAROR(I1,-1,R8,0,I4,-1);
    VAROR(I1,0,R8,0,I4,0);
    VAROR(I1,-1,DATE,-1,I4,-1);
    VAROR(I1,-1,DATE,0,I4,-1);
    VAROR(I1,0,DATE,0,I4,0);
4793
    if (has_i8)
4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809
    {
        VAROR(I1,-1,I8,-1,I8,-1);
        VAROR(I1,-1,I8,0,I8,-1);
        VAROR(I1,0,I8,0,I8,0);
        VAROR(I1,-1,UI8,0,I4,-1);
        VAROR(I1,0,UI8,0,I4,0);
    }
    VAROR(I1,-1,INT,-1,I4,-1);
    VAROR(I1,-1,INT,0,I4,-1);
    VAROR(I1,0,INT,0,I4,0);
    VAROR(I1,-1,UINT,0xffffffff,I4,-1);
    VAROR(I1,-1,UINT,0,I4,-1);
    VAROR(I1,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VAROR(I1,0,BSTR,rbstr,I4,0);
    VAROR(I1,-1,BSTR,rbstr,I4,-1);
4810
    SysFreeString(rbstr);
4811 4812 4813
    rbstr = SysAllocString(szTrue);
    VAROR(I1,0,BSTR,rbstr,I4,-1);
    VAROR(I1,-1,BSTR,rbstr,I4,-1);
4814
    SysFreeString(rbstr);
4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842
    VARORCY(I1,-1,10000,I4,-1);
    VARORCY(I1,-1,0,I4,-1);
    VARORCY(I1,0,0,I4,0);

    VAROR(UI1,255,UI1,255,UI1,255);
    VAROR(UI1,255,UI1,0,UI1,255);
    VAROR(UI1,0,UI1,0,UI1,0);
    VAROR(UI1,255,I2,-1,I2,-1);
    VAROR(UI1,255,I2,0,I2,255);
    VAROR(UI1,0,I2,0,I2,0);
    VAROR(UI1,255,UI2,65535,I4,65535);
    VAROR(UI1,255,UI2,0,I4,255);
    VAROR(UI1,0,UI2,0,I4,0);
    VAROR(UI1,255,I4,-1,I4,-1);
    VAROR(UI1,255,I4,0,I4,255);
    VAROR(UI1,0,I4,0,I4,0);
    VAROR(UI1,255,UI4,0xffffffff,I4,-1);
    VAROR(UI1,255,UI4,0,I4,255);
    VAROR(UI1,0,UI4,0,I4,0);
    VAROR(UI1,255,R4,-1,I4,-1);
    VAROR(UI1,255,R4,0,I4,255);
    VAROR(UI1,0,R4,0,I4,0);
    VAROR(UI1,255,R8,-1,I4,-1);
    VAROR(UI1,255,R8,0,I4,255);
    VAROR(UI1,0,R8,0,I4,0);
    VAROR(UI1,255,DATE,-1,I4,-1);
    VAROR(UI1,255,DATE,0,I4,255);
    VAROR(UI1,0,DATE,0,I4,0);
4843
    if (has_i8)
4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859
    {
        VAROR(UI1,255,I8,-1,I8,-1);
        VAROR(UI1,255,I8,0,I8,255);
        VAROR(UI1,0,I8,0,I8,0);
        VAROR(UI1,255,UI8,0,I4,255);
        VAROR(UI1,0,UI8,0,I4,0);
    }
    VAROR(UI1,255,INT,-1,I4,-1);
    VAROR(UI1,255,INT,0,I4,255);
    VAROR(UI1,0,INT,0,I4,0);
    VAROR(UI1,255,UINT,0xffffffff,I4,-1);
    VAROR(UI1,255,UINT,0,I4,255);
    VAROR(UI1,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VAROR(UI1,0,BSTR,rbstr,I2,0);
    VAROR(UI1,255,BSTR,rbstr,I2,255);
4860
    SysFreeString(rbstr);
4861 4862 4863
    rbstr = SysAllocString(szTrue);
    VAROR(UI1,0,BSTR,rbstr,I2,-1);
    VAROR(UI1,255,BSTR,rbstr,I2,-1);
4864
    SysFreeString(rbstr);
4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889
    VARORCY(UI1,255,10000,I4,255);
    VARORCY(UI1,255,0,I4,255);
    VARORCY(UI1,0,0,I4,0);

    VAROR(I2,-1,I2,-1,I2,-1);
    VAROR(I2,-1,I2,0,I2,-1);
    VAROR(I2,0,I2,0,I2,0);
    VAROR(I2,-1,UI2,65535,I4,-1);
    VAROR(I2,-1,UI2,0,I4,-1);
    VAROR(I2,0,UI2,0,I4,0);
    VAROR(I2,-1,I4,-1,I4,-1);
    VAROR(I2,-1,I4,0,I4,-1);
    VAROR(I2,0,I4,0,I4,0);
    VAROR(I2,-1,UI4,0xffffffff,I4,-1);
    VAROR(I2,-1,UI4,0,I4,-1);
    VAROR(I2,0,UI4,0,I4,0);
    VAROR(I2,-1,R4,-1,I4,-1);
    VAROR(I2,-1,R4,0,I4,-1);
    VAROR(I2,0,R4,0,I4,0);
    VAROR(I2,-1,R8,-1,I4,-1);
    VAROR(I2,-1,R8,0,I4,-1);
    VAROR(I2,0,R8,0,I4,0);
    VAROR(I2,-1,DATE,-1,I4,-1);
    VAROR(I2,-1,DATE,0,I4,-1);
    VAROR(I2,0,DATE,0,I4,0);
4890
    if (has_i8)
4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906
    {
        VAROR(I2,-1,I8,-1,I8,-1);
        VAROR(I2,-1,I8,0,I8,-1);
        VAROR(I2,0,I8,0,I8,0);
        VAROR(I2,-1,UI8,0,I4,-1);
        VAROR(I2,0,UI8,0,I4,0);
    }
    VAROR(I2,-1,INT,-1,I4,-1);
    VAROR(I2,-1,INT,0,I4,-1);
    VAROR(I2,0,INT,0,I4,0);
    VAROR(I2,-1,UINT,0xffffffff,I4,-1);
    VAROR(I2,-1,UINT,0,I4,-1);
    VAROR(I2,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VAROR(I2,0,BSTR,rbstr,I2,0);
    VAROR(I2,-1,BSTR,rbstr,I2,-1);
4907
    SysFreeString(rbstr);
4908 4909 4910
    rbstr = SysAllocString(szTrue);
    VAROR(I2,0,BSTR,rbstr,I2,-1);
    VAROR(I2,-1,BSTR,rbstr,I2,-1);
4911
    SysFreeString(rbstr);
4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933
    VARORCY(I2,-1,10000,I4,-1);
    VARORCY(I2,-1,0,I4,-1);
    VARORCY(I2,0,0,I4,0);

    VAROR(UI2,65535,UI2,65535,I4,65535);
    VAROR(UI2,65535,UI2,0,I4,65535);
    VAROR(UI2,0,UI2,0,I4,0);
    VAROR(UI2,65535,I4,-1,I4,-1);
    VAROR(UI2,65535,I4,0,I4,65535);
    VAROR(UI2,0,I4,0,I4,0);
    VAROR(UI2,65535,UI4,0xffffffff,I4,-1);
    VAROR(UI2,65535,UI4,0,I4,65535);
    VAROR(UI2,0,UI4,0,I4,0);
    VAROR(UI2,65535,R4,-1,I4,-1);
    VAROR(UI2,65535,R4,0,I4,65535);
    VAROR(UI2,0,R4,0,I4,0);
    VAROR(UI2,65535,R8,-1,I4,-1);
    VAROR(UI2,65535,R8,0,I4,65535);
    VAROR(UI2,0,R8,0,I4,0);
    VAROR(UI2,65535,DATE,-1,I4,-1);
    VAROR(UI2,65535,DATE,0,I4,65535);
    VAROR(UI2,0,DATE,0,I4,0);
4934
    if (has_i8)
4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950
    {
        VAROR(UI2,65535,I8,-1,I8,-1);
        VAROR(UI2,65535,I8,0,I8,65535);
        VAROR(UI2,0,I8,0,I8,0);
        VAROR(UI2,65535,UI8,0,I4,65535);
        VAROR(UI2,0,UI8,0,I4,0);
    }
    VAROR(UI2,65535,INT,-1,I4,-1);
    VAROR(UI2,65535,INT,0,I4,65535);
    VAROR(UI2,0,INT,0,I4,0);
    VAROR(UI2,65535,UINT,0xffffffff,I4,-1);
    VAROR(UI2,65535,UINT,0,I4,65535);
    VAROR(UI2,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VAROR(UI2,0,BSTR,rbstr,I4,0);
    VAROR(UI2,65535,BSTR,rbstr,I4,65535);
4951
    SysFreeString(rbstr);
4952 4953 4954
    rbstr = SysAllocString(szTrue);
    VAROR(UI2,0,BSTR,rbstr,I4,-1);
    VAROR(UI2,65535,BSTR,rbstr,I4,-1);
4955
    SysFreeString(rbstr);
4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974
    VARORCY(UI2,65535,10000,I4,65535);
    VARORCY(UI2,65535,0,I4,65535);
    VARORCY(UI2,0,0,I4,0);

    VAROR(I4,-1,I4,-1,I4,-1);
    VAROR(I4,-1,I4,0,I4,-1);
    VAROR(I4,0,I4,0,I4,0);
    VAROR(I4,-1,UI4,0xffffffff,I4,-1);
    VAROR(I4,-1,UI4,0,I4,-1);
    VAROR(I4,0,UI4,0,I4,0);
    VAROR(I4,-1,R4,-1,I4,-1);
    VAROR(I4,-1,R4,0,I4,-1);
    VAROR(I4,0,R4,0,I4,0);
    VAROR(I4,-1,R8,-1,I4,-1);
    VAROR(I4,-1,R8,0,I4,-1);
    VAROR(I4,0,R8,0,I4,0);
    VAROR(I4,-1,DATE,-1,I4,-1);
    VAROR(I4,-1,DATE,0,I4,-1);
    VAROR(I4,0,DATE,0,I4,0);
4975
    if (has_i8)
4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991
    {
        VAROR(I4,-1,I8,-1,I8,-1);
        VAROR(I4,-1,I8,0,I8,-1);
        VAROR(I4,0,I8,0,I8,0);
        VAROR(I4,-1,UI8,0,I4,-1);
        VAROR(I4,0,UI8,0,I4,0);
    }
    VAROR(I4,-1,INT,-1,I4,-1);
    VAROR(I4,-1,INT,0,I4,-1);
    VAROR(I4,0,INT,0,I4,0);
    VAROR(I4,-1,UINT,0xffffffff,I4,-1);
    VAROR(I4,-1,UINT,0,I4,-1);
    VAROR(I4,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VAROR(I4,0,BSTR,rbstr,I4,0);
    VAROR(I4,-1,BSTR,rbstr,I4,-1);
4992
    SysFreeString(rbstr);
4993 4994 4995
    rbstr = SysAllocString(szTrue);
    VAROR(I4,0,BSTR,rbstr,I4,-1);
    VAROR(I4,-1,BSTR,rbstr,I4,-1);
4996
    SysFreeString(rbstr);
4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012
    VARORCY(I4,-1,10000,I4,-1);
    VARORCY(I4,-1,0,I4,-1);
    VARORCY(I4,0,0,I4,0);

    VAROR(UI4,0xffffffff,UI4,0xffffffff,I4,-1);
    VAROR(UI4,0xffffffff,UI4,0,I4,-1);
    VAROR(UI4,0,UI4,0,I4,0);
    VAROR(UI4,0xffffffff,R4,-1,I4,-1);
    VAROR(UI4,0xffffffff,R4,0,I4,-1);
    VAROR(UI4,0,R4,0,I4,0);
    VAROR(UI4,0xffffffff,R8,-1,I4,-1);
    VAROR(UI4,0xffffffff,R8,0,I4,-1);
    VAROR(UI4,0,R8,0,I4,0);
    VAROR(UI4,0xffffffff,DATE,-1,I4,-1);
    VAROR(UI4,0xffffffff,DATE,0,I4,-1);
    VAROR(UI4,0,DATE,0,I4,0);
5013
    if (has_i8)
5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029
    {
        VAROR(UI4,0xffffffff,I8,-1,I8,-1);
        VAROR(UI4,0xffffffff,I8,0,I8,0xffffffff);
        VAROR(UI4,0,I8,0,I8,0);
        VAROR(UI4,0xffffffff,UI8,0,I4,-1);
        VAROR(UI4,0,UI8,0,I4,0);
    }
    VAROR(UI4,0xffffffff,INT,-1,I4,-1);
    VAROR(UI4,0xffffffff,INT,0,I4,-1);
    VAROR(UI4,0,INT,0,I4,0);
    VAROR(UI4,0xffffffff,UINT,0xffffffff,I4,-1);
    VAROR(UI4,0xffffffff,UINT,0,I4,-1);
    VAROR(UI4,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VAROR(UI4,0,BSTR,rbstr,I4,0);
    VAROR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
5030
    SysFreeString(rbstr);
5031 5032 5033
    rbstr = SysAllocString(szTrue);
    VAROR(UI4,0,BSTR,rbstr,I4,-1);
    VAROR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
5034
    SysFreeString(rbstr);
5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047
    VARORCY(UI4,0xffffffff,10000,I4,-1);
    VARORCY(UI4,0xffffffff,0,I4,-1);
    VARORCY(UI4,0,0,I4,0);

    VAROR(R4,-1,R4,-1,I4,-1);
    VAROR(R4,-1,R4,0,I4,-1);
    VAROR(R4,0,R4,0,I4,0);
    VAROR(R4,-1,R8,-1,I4,-1);
    VAROR(R4,-1,R8,0,I4,-1);
    VAROR(R4,0,R8,0,I4,0);
    VAROR(R4,-1,DATE,-1,I4,-1);
    VAROR(R4,-1,DATE,0,I4,-1);
    VAROR(R4,0,DATE,0,I4,0);
5048
    if (has_i8)
5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064
    {
        VAROR(R4,-1,I8,-1,I8,-1);
        VAROR(R4,-1,I8,0,I8,-1);
        VAROR(R4,0,I8,0,I8,0);
        VAROR(R4,-1,UI8,0,I4,-1);
        VAROR(R4,0,UI8,0,I4,0);
    }
    VAROR(R4,-1,INT,-1,I4,-1);
    VAROR(R4,-1,INT,0,I4,-1);
    VAROR(R4,0,INT,0,I4,0);
    VAROR(R4,-1,UINT,0xffffffff,I4,-1);
    VAROR(R4,-1,UINT,0,I4,-1);
    VAROR(R4,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VAROR(R4,0,BSTR,rbstr,I4,0);
    VAROR(R4,-1,BSTR,rbstr,I4,-1);
5065
    SysFreeString(rbstr);
5066 5067 5068
    rbstr = SysAllocString(szTrue);
    VAROR(R4,0,BSTR,rbstr,I4,-1);
    VAROR(R4,-1,BSTR,rbstr,I4,-1);
5069
    SysFreeString(rbstr);
5070 5071 5072 5073 5074 5075 5076 5077 5078 5079
    VARORCY(R4,-1,10000,I4,-1);
    VARORCY(R4,-1,0,I4,-1);
    VARORCY(R4,0,0,I4,0);

    VAROR(R8,-1,R8,-1,I4,-1);
    VAROR(R8,-1,R8,0,I4,-1);
    VAROR(R8,0,R8,0,I4,0);
    VAROR(R8,-1,DATE,-1,I4,-1);
    VAROR(R8,-1,DATE,0,I4,-1);
    VAROR(R8,0,DATE,0,I4,0);
5080
    if (has_i8)
5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096
    {
        VAROR(R8,-1,I8,-1,I8,-1);
        VAROR(R8,-1,I8,0,I8,-1);
        VAROR(R8,0,I8,0,I8,0);
        VAROR(R8,-1,UI8,0,I4,-1);
        VAROR(R8,0,UI8,0,I4,0);
    }
    VAROR(R8,-1,INT,-1,I4,-1);
    VAROR(R8,-1,INT,0,I4,-1);
    VAROR(R8,0,INT,0,I4,0);
    VAROR(R8,-1,UINT,0xffffffff,I4,-1);
    VAROR(R8,-1,UINT,0,I4,-1);
    VAROR(R8,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VAROR(R8,0,BSTR,rbstr,I4,0);
    VAROR(R8,-1,BSTR,rbstr,I4,-1);
5097
    SysFreeString(rbstr);
5098 5099 5100
    rbstr = SysAllocString(szTrue);
    VAROR(R8,0,BSTR,rbstr,I4,-1);
    VAROR(R8,-1,BSTR,rbstr,I4,-1);
5101
    SysFreeString(rbstr);
5102 5103 5104 5105 5106 5107 5108
    VARORCY(R8,-1,10000,I4,-1);
    VARORCY(R8,-1,0,I4,-1);
    VARORCY(R8,0,0,I4,0);

    VAROR(DATE,-1,DATE,-1,I4,-1);
    VAROR(DATE,-1,DATE,0,I4,-1);
    VAROR(DATE,0,DATE,0,I4,0);
5109
    if (has_i8)
5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125
    {
        VAROR(DATE,-1,I8,-1,I8,-1);
        VAROR(DATE,-1,I8,0,I8,-1);
        VAROR(DATE,0,I8,0,I8,0);
        VAROR(DATE,-1,UI8,0,I4,-1);
        VAROR(DATE,0,UI8,0,I4,0);
    }
    VAROR(DATE,-1,INT,-1,I4,-1);
    VAROR(DATE,-1,INT,0,I4,-1);
    VAROR(DATE,0,INT,0,I4,0);
    VAROR(DATE,-1,UINT,0xffffffff,I4,-1);
    VAROR(DATE,-1,UINT,0,I4,-1);
    VAROR(DATE,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VAROR(DATE,0,BSTR,rbstr,I4,0);
    VAROR(DATE,-1,BSTR,rbstr,I4,-1);
5126
    SysFreeString(rbstr);
5127 5128 5129
    rbstr = SysAllocString(szTrue);
    VAROR(DATE,0,BSTR,rbstr,I4,-1);
    VAROR(DATE,-1,BSTR,rbstr,I4,-1);
5130
    SysFreeString(rbstr);
5131 5132 5133 5134
    VARORCY(DATE,-1,10000,I4,-1);
    VARORCY(DATE,-1,0,I4,-1);
    VARORCY(DATE,0,0,I4,0);

5135
    if (has_i8)
5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151
    {
        VAROR(I8,-1,I8,-1,I8,-1);
        VAROR(I8,-1,I8,0,I8,-1);
        VAROR(I8,0,I8,0,I8,0);
        VAROR(I8,-1,UI8,0,I8,-1);
        VAROR(I8,0,UI8,0,I8,0);
        /* These overflow under native and Wine
        VAROR(I8,-1,INT,-1,I4,-1);
        VAROR(I8,-1,INT,0,I4,-1);
        VAROR(I8,0,INT,0,I4,0); */
        VAROR(I8,-1,UINT,0xffffffff,I8,-1);
        VAROR(I8,-1,UINT,0,I8,-1);
        VAROR(I8,0,UINT,0,I8,0);
        rbstr = SysAllocString(szFalse);
        VAROR(I8,0,BSTR,rbstr,I8,0);
        VAROR(I8,-1,BSTR,rbstr,I8,-1);
5152
        SysFreeString(rbstr);
5153 5154 5155
        rbstr = SysAllocString(szTrue);
        VAROR(I8,0,BSTR,rbstr,I8,-1);
        VAROR(I8,-1,BSTR,rbstr,I8,-1);
5156
        SysFreeString(rbstr);
5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172
        VARORCY(I8,-1,10000,I8,-1);
        VARORCY(I8,-1,0,I8,-1);
        VARORCY(I8,0,0,I8,0);

        VAROR(UI8,0xffff,UI8,0xffff,I4,0xffff);
        VAROR(UI8,0xffff,UI8,0,I4,0xffff);
        VAROR(UI8,0,UI8,0,I4,0);
        VAROR(UI8,0xffff,INT,-1,I4,-1);
        VAROR(UI8,0xffff,INT,0,I4,0xffff);
        VAROR(UI8,0,INT,0,I4,0);
        VAROR(UI8,0xffff,UINT,0xffff,I4,0xffff);
        VAROR(UI8,0xffff,UINT,0,I4,0xffff);
        VAROR(UI8,0,UINT,0,I4,0);
        rbstr = SysAllocString(szFalse);
        VAROR(UI8,0,BSTR,rbstr,I4,0);
        VAROR(UI8,0xffff,BSTR,rbstr,I4,0xffff);
5173
        SysFreeString(rbstr);
5174 5175 5176
        rbstr = SysAllocString(szTrue);
        VAROR(UI8,0,BSTR,rbstr,I4,-1);
        VAROR(UI8,0xffff,BSTR,rbstr,I4,-1);
5177
        SysFreeString(rbstr);
5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191
        VARORCY(UI8,0xffff,10000,I4,0xffff);
        VARORCY(UI8,0xffff,0,I4,0xffff);
        VARORCY(UI8,0,0,I4,0);
    }

    VAROR(INT,-1,INT,-1,I4,-1);
    VAROR(INT,-1,INT,0,I4,-1);
    VAROR(INT,0,INT,0,I4,0);
    VAROR(INT,-1,UINT,0xffff,I4,-1);
    VAROR(INT,-1,UINT,0,I4,-1);
    VAROR(INT,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VAROR(INT,0,BSTR,rbstr,I4,0);
    VAROR(INT,-1,BSTR,rbstr,I4,-1);
5192
    SysFreeString(rbstr);
5193 5194 5195
    rbstr = SysAllocString(szTrue);
    VAROR(INT,0,BSTR,rbstr,I4,-1);
    VAROR(INT,-1,BSTR,rbstr,I4,-1);
5196
    SysFreeString(rbstr);
5197 5198 5199 5200 5201 5202 5203 5204 5205 5206
    VARORCY(INT,-1,10000,I4,-1);
    VARORCY(INT,-1,0,I4,-1);
    VARORCY(INT,0,0,I4,0);

    VAROR(UINT,0xffff,UINT,0xffff,I4,0xffff);
    VAROR(UINT,0xffff,UINT,0,I4,0xffff);
    VAROR(UINT,0,UINT,0,I4,0);
    rbstr = SysAllocString(szFalse);
    VAROR(UINT,0,BSTR,rbstr,I4,0);
    VAROR(UINT,0xffff,BSTR,rbstr,I4,0xffff);
5207
    SysFreeString(rbstr);
5208 5209 5210
    rbstr = SysAllocString(szTrue);
    VAROR(UINT,0,BSTR,rbstr,I4,-1);
    VAROR(UINT,0xffff,BSTR,rbstr,I4,-1);
5211
    SysFreeString(rbstr);
5212 5213 5214 5215 5216 5217 5218
    VARORCY(UINT,0xffff,10000,I4,0xffff);
    VARORCY(UINT,0xffff,0,I4,0xffff);
    VARORCY(UINT,0,0,I4,0);

    lbstr = SysAllocString(szFalse);
    rbstr = SysAllocString(szFalse);
    VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,0);
5219
    SysFreeString(rbstr);
5220 5221
    rbstr = SysAllocString(szTrue);
    VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
5222
    SysFreeString(lbstr);
5223 5224 5225
    lbstr = SysAllocString(szTrue);
    VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
    VARORCY(BSTR,lbstr,10000,I4,-1);
5226
    SysFreeString(lbstr);
5227 5228
    lbstr = SysAllocString(szFalse);
    VARORCY(BSTR,lbstr,10000,I4,1);
5229 5230
    SysFreeString(lbstr);
    SysFreeString(rbstr);
5231
}
Jon Griffiths's avatar
Jon Griffiths committed
5232 5233 5234

static HRESULT (WINAPI *pVarEqv)(LPVARIANT,LPVARIANT,LPVARIANT);

5235 5236 5237 5238
#define VAREQV(vt1,val1,vt2,val2,rvt,rval)           \
    V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
    V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
    V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
5239
    test_var_call2( __LINE__, pVarEqv, &left, &right, &exp )
Jon Griffiths's avatar
Jon Griffiths committed
5240 5241 5242

static void test_VarEqv(void)
{
5243
    VARIANT left, right, exp, result;
Jon Griffiths's avatar
Jon Griffiths committed
5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255
    VARTYPE i;
    HRESULT hres;

    CHECKPTR(VarEqv);

    /* Test all possible flag/vt combinations & the resulting vt type */
    for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
    {
        VARTYPE leftvt, rightvt, resvt;

        for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
        {
5256 5257
            SKIPTESTS(leftvt);

Jon Griffiths's avatar
Jon Griffiths committed
5258 5259 5260 5261
            for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
            {
                BOOL bFail = FALSE;

5262 5263
                SKIPTESTS(rightvt);

Jon Griffiths's avatar
Jon Griffiths committed
5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336
                if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
                    leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
                    leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
                    continue;

                memset(&left, 0, sizeof(left));
                memset(&right, 0, sizeof(right));
                V_VT(&left) = leftvt | ExtraFlags[i];
                V_VT(&right) = rightvt | ExtraFlags[i];
                V_VT(&result) = VT_EMPTY;
                resvt = VT_I4;

                if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
                    !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
                    !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
                    leftvt == VT_CLSID || rightvt == VT_CLSID ||
                    leftvt == VT_RECORD || rightvt == VT_RECORD ||
                    leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
                    leftvt == VT_ERROR || rightvt == VT_ERROR)
                {
                    bFail = TRUE;
                }
                if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
                {
                    if (leftvt == rightvt ||
                        leftvt == VT_I2 || rightvt == VT_I2 ||
                        leftvt == VT_UI1 || rightvt == VT_UI1 ||
                        leftvt == VT_BOOL || rightvt == VT_BOOL)
                        resvt = VT_I2;
                    else if (leftvt == VT_NULL || rightvt == VT_NULL)
                        resvt = VT_NULL;
                    else if (leftvt == VT_I8 || rightvt == VT_I8)
                        resvt = VT_I8;
                }
                else if (leftvt == VT_NULL || rightvt == VT_NULL)
                {
                    resvt = VT_NULL;
                }
                else if (leftvt == VT_UI1 || rightvt == VT_UI1)
                {
                    if (leftvt == rightvt)
                        resvt = VT_UI1;
                    else if (leftvt == rightvt ||
                        leftvt == VT_I2 || rightvt == VT_I2 ||
                        leftvt == VT_BOOL || rightvt == VT_BOOL)
                    {
                        resvt = VT_I2;
                    }
                    else if (leftvt == VT_I8 || rightvt == VT_I8)
                        resvt = VT_I8;
                }
                else if (leftvt == VT_I2 || rightvt == VT_I2)
                {
                    if (leftvt == rightvt ||
                        leftvt == VT_BOOL || rightvt == VT_BOOL)
                        resvt = VT_I2;
                    else if (leftvt == VT_I8 || rightvt == VT_I8)
                        resvt = VT_I8;
                }
                else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
                {
                    resvt = VT_BOOL;
                }
                else if (leftvt == VT_I8 || rightvt == VT_I8)
                {
                    if (leftvt == VT_INT || rightvt == VT_INT)
                        bFail = TRUE;
                    else
                        resvt = VT_I8;
                }
                hres = pVarEqv(&left, &right, &result);
                if (bFail)
                    ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
5337
                       "VarEqv: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
Jon Griffiths's avatar
Jon Griffiths committed
5338 5339 5340 5341
                       leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
                       V_VT(&result));
                else
                    ok(hres == S_OK && V_VT(&result) == resvt,
5342
                       "VarEqv: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
Jon Griffiths's avatar
Jon Griffiths committed
5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363
                       leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
                       V_VT(&result));
            }
        }
    }

    /* Test returned values */
    VAREQV(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
    VAREQV(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
    VAREQV(BOOL,TRUE,BOOL,TRUE,BOOL,VARIANT_TRUE);
    VAREQV(BOOL,FALSE,BOOL,FALSE,BOOL,VARIANT_TRUE);
    VAREQV(BOOL,TRUE,BOOL,FALSE,BOOL,-2);
    VAREQV(BOOL,FALSE,BOOL,TRUE,BOOL,-2);
    VAREQV(BOOL,6,BOOL,7,BOOL,-2);
    VAREQV(BOOL,6,BOOL,6,BOOL,VARIANT_TRUE);
    VAREQV(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE,I2,VARIANT_TRUE);
    VAREQV(BOOL,VARIANT_TRUE,I2,VARIANT_FALSE,I2,VARIANT_FALSE);
    VAREQV(BOOL,6,I2,7,I2,-2);
    VAREQV(UI1,1,UI1,1,UI1,255);
    VAREQV(UI1,1,UI1,0,UI1,254);
    VAREQV(UI1,0,UI1,1,UI1,254);
5364
    if (has_i8)
Jon Griffiths's avatar
Jon Griffiths committed
5365 5366 5367 5368 5369 5370 5371
    {
        VAREQV(UI4,VARIANT_FALSE,I8,VARIANT_FALSE,I8,-1);
        VAREQV(UI4,5,I8,19,I8,-23);
        VAREQV(UI4,VARIANT_FALSE,UI8,VARIANT_FALSE,I4,-1);
    }
}

Michael Stefaniuc's avatar
Michael Stefaniuc committed
5372 5373
static HRESULT (WINAPI *pVarMul)(LPVARIANT,LPVARIANT,LPVARIANT);

5374 5375
#define VARMUL(vt1,val1,vt2,val2,rvt,rval)               \
        V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5376
        V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
5377
        V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
5378
        test_var_call2( __LINE__, pVarMul, &left, &right, &exp )
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5379 5380 5381

static void test_VarMul(void)
{
5382
    VARIANT left, right, exp, result, cy, dec;
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473
    VARTYPE i;
    BSTR lbstr, rbstr;
    HRESULT hres;
    double r;

    CHECKPTR(VarMul);

    lbstr = SysAllocString(sz12);
    rbstr = SysAllocString(sz12);

    /* Test all possible flag/vt combinations & the resulting vt type */
    for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
    {
        VARTYPE leftvt, rightvt, resvt;

        for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
        {

            SKIPTESTS(leftvt);

            for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
            {
                BOOL bFail = FALSE;

                SKIPTESTS(rightvt);

                if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
                    leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
                    continue;

                memset(&left, 0, sizeof(left));
                memset(&right, 0, sizeof(right));
                V_VT(&left) = leftvt | ExtraFlags[i];
                if (leftvt == VT_BSTR)
                    V_BSTR(&left) = lbstr;
                V_VT(&right) = rightvt | ExtraFlags[i];
                if (rightvt == VT_BSTR)
                    V_BSTR(&right) = rbstr;
                V_VT(&result) = VT_EMPTY;
                resvt = VT_UNKNOWN;

                /* Don't ask me why but native VarMul cannot handle:
                   VT_I1, VT_UI2, VT_UI4, VT_INT, VT_UINT and VT_UI8.
                   Tested with DCOM98, Win2k, WinXP */
                if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
                    !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
                    !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
                    leftvt == VT_CLSID || rightvt == VT_CLSID ||
                    leftvt == VT_RECORD || rightvt == VT_RECORD ||
                    leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
                    leftvt == VT_ERROR || rightvt == VT_ERROR ||
                    leftvt == VT_I1 || rightvt == VT_I1 ||
                    leftvt == VT_UI2 || rightvt == VT_UI2 ||
                    leftvt == VT_UI4 || rightvt == VT_UI4 ||
                    leftvt == VT_UI8 || rightvt == VT_UI8 ||
                    leftvt == VT_INT || rightvt == VT_INT ||
                    leftvt == VT_UINT || rightvt == VT_UINT) {
                    bFail = TRUE;
                }

                if (leftvt == VT_NULL || rightvt == VT_NULL)
                    resvt = VT_NULL;
                else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
                    resvt = VT_DECIMAL;
                else if (leftvt == VT_R8 || rightvt == VT_R8 ||
                         leftvt == VT_BSTR || rightvt == VT_BSTR ||
                         leftvt == VT_DATE || rightvt == VT_DATE)
                    resvt = VT_R8;
                else if (leftvt == VT_R4 || rightvt == VT_R4) {
                    if (leftvt == VT_I4 || rightvt == VT_I4 ||
                        leftvt == VT_I8 || rightvt == VT_I8 ||
                        leftvt == VT_CY || rightvt == VT_CY)
                        resvt = VT_R8;
                    else
                        resvt = VT_R4;
                } else if (leftvt == VT_CY || rightvt == VT_CY)
                    resvt = VT_CY;
                else if (leftvt == VT_I8 || rightvt == VT_I8)
                    resvt = VT_I8;
                else if (leftvt == VT_I4 || rightvt == VT_I4)
                    resvt = VT_I4;
                else if (leftvt == VT_I2 || rightvt == VT_I2 ||
                         leftvt == VT_BOOL || rightvt == VT_BOOL ||
                         (leftvt == VT_EMPTY && rightvt == VT_EMPTY))
                    resvt = VT_I2;
                else if (leftvt == VT_UI1 || rightvt == VT_UI1)
                    resvt = VT_UI1;

                hres = pVarMul(&left, &right, &result);
                if (bFail) {
                    ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
5474
                       "VarMul: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5475 5476 5477 5478
                       leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
                       V_VT(&result));
                } else {
                    ok(hres == S_OK && V_VT(&result) == resvt,
5479
                       "VarMul: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491
                       leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
                       V_VT(&result));
                }
            }
        }
    }

    /* Test returned values */
    VARMUL(I4,4,I4,2,I4,8);
    VARMUL(I2,4,I2,2,I2,8);
    VARMUL(I2,-13,I4,5,I4,-65);
    VARMUL(I4,-13,I4,5,I4,-65);
5492 5493
    VARMUL(I2,7,R4,0.5f,R4,3.5f);
    VARMUL(R4,0.5f,I4,5,R8,2.5);
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5494 5495 5496
    VARMUL(R8,7.1,BOOL,0,R8,0);
    VARMUL(BSTR,lbstr,I2,4,R8,48);
    VARMUL(BSTR,lbstr,BOOL,1,R8,12);
5497
    VARMUL(BSTR,lbstr,R4,0.1f,R8,1.2);
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5498
    VARMUL(BSTR,lbstr,BSTR,rbstr,R8,144);
5499
    VARMUL(R4,0.2f,BSTR,rbstr,R8,2.4);
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528
    VARMUL(DATE,2.25,I4,7,R8,15.75);

    VARMUL(UI1, UI1_MAX, UI1, UI1_MAX, I4, UI1_MAX * UI1_MAX);
    VARMUL(I2, I2_MAX, I2, I2_MAX, I4, I2_MAX * I2_MAX);
    VARMUL(I2, I2_MAX, I2, I2_MIN, I4, I2_MAX * I2_MIN);
    VARMUL(I2, I2_MIN, I2, I2_MIN, I4, I2_MIN * I2_MIN);
    VARMUL(I4, I4_MAX, I4, I4_MAX, R8, (double)I4_MAX * I4_MAX);
    VARMUL(I4, I4_MAX, I4, I4_MIN, R8, (double)I4_MAX * I4_MIN);
    VARMUL(I4, I4_MIN, I4, I4_MIN, R8, (double)I4_MIN * I4_MIN);
    VARMUL(R4, R4_MAX, R4, R4_MAX, R8, (double)R4_MAX * R4_MAX);
    VARMUL(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX * R4_MIN);
    VARMUL(R4, R4_MIN, R4, R4_MIN, R4, R4_MIN * R4_MIN);
    VARMUL(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX * R8_MIN);
    VARMUL(R8, R8_MIN, R8, R8_MIN, R8, R8_MIN * R8_MIN);

    /* Manuly test some VT_CY and VT_DECIMAL variants */
    V_VT(&cy) = VT_CY;
    hres = VarCyFromI4(4711, &V_CY(&cy));
    ok(hres == S_OK, "VarCyFromI4 failed!\n");
    V_VT(&dec) = VT_DECIMAL;
    hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec));
    ok(hres == S_OK, "VarDecFromR4 failed!\n");
    memset(&left, 0, sizeof(left));
    memset(&right, 0, sizeof(right));
    V_VT(&left) = VT_I4;
    V_I4(&left) = -11;
    V_VT(&right) = VT_UI1;
    V_UI1(&right) = 9;

5529
    hres = pVarMul(&cy, &right, &result);
5530
    ok(hres == S_OK && V_VT(&result) == VT_CY, "VarMul: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result)));
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5531
    hres = VarR8FromCy(V_CY(&result), &r);
5532
    ok(hres == S_OK && EQ_DOUBLE(r, 42399.0), "VarMul: CY value %f, expected %f\n", r, (double)42399);
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5533

5534
    hres = pVarMul(&left, &dec, &result);
5535
    ok(hres == S_OK && V_VT(&result) == VT_DECIMAL, "VarMul: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5536 5537
    hres = VarR8FromDec(&V_DECIMAL(&result), &r);
    ok(hres == S_OK && EQ_DOUBLE(r, 46.2), "VarMul: DECIMAL value %f, expected %f\n", r, (double)46.2);
5538 5539 5540

    SysFreeString(lbstr);
    SysFreeString(rbstr);
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5541 5542
}

Michael Stefaniuc's avatar
Michael Stefaniuc committed
5543 5544
static HRESULT (WINAPI *pVarAdd)(LPVARIANT,LPVARIANT,LPVARIANT);

5545 5546
#define VARADD(vt1,val1,vt2,val2,rvt,rval)               \
        V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5547
        V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
5548
        V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
5549
        test_var_call2( __LINE__, pVarAdd, &left, &right, &exp )
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5550 5551 5552

static void test_VarAdd(void)
{
5553
    VARIANT left, right, exp, result, cy, dec;
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651
    VARTYPE i;
    BSTR lbstr, rbstr;
    HRESULT hres;
    double r;

    CHECKPTR(VarAdd);

    lbstr = SysAllocString(sz12);
    rbstr = SysAllocString(sz12);

    /* Test all possible flag/vt combinations & the resulting vt type */
    for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
    {
        VARTYPE leftvt, rightvt, resvt;

        for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
        {

            SKIPTESTS(leftvt);

            for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
            {
                BOOL bFail = FALSE;

                SKIPTESTS(rightvt);

                if (leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
                    continue;

                memset(&left, 0, sizeof(left));
                memset(&right, 0, sizeof(right));
                V_VT(&left) = leftvt | ExtraFlags[i];
                if (leftvt == VT_BSTR)
                    V_BSTR(&left) = lbstr;
                V_VT(&right) = rightvt | ExtraFlags[i];
                if (rightvt == VT_BSTR)
                    V_BSTR(&right) = rbstr;
                V_VT(&result) = VT_EMPTY;
                resvt = VT_ERROR;

                /* Don't ask me why but native VarAdd cannot handle:
                   VT_I1, VT_UI2, VT_UI4, VT_INT, VT_UINT and VT_UI8.
                   Tested with DCOM98, Win2k, WinXP */
                if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
                    !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
                    !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
                    leftvt == VT_CLSID || rightvt == VT_CLSID ||
                    leftvt == VT_RECORD || rightvt == VT_RECORD ||
                    leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
                    leftvt == VT_ERROR || rightvt == VT_ERROR ||
                    leftvt == VT_I1 || rightvt == VT_I1 ||
                    leftvt == VT_UI2 || rightvt == VT_UI2 ||
                    leftvt == VT_UI4 || rightvt == VT_UI4 ||
                    leftvt == VT_UI8 || rightvt == VT_UI8 ||
                    leftvt == VT_INT || rightvt == VT_INT ||
                    leftvt == VT_UINT || rightvt == VT_UINT) {
                    bFail = TRUE;
                }

                if (leftvt == VT_NULL || rightvt == VT_NULL)
                    resvt = VT_NULL;
                else if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH)
                    bFail = TRUE;
                else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
                    resvt = VT_DECIMAL;
                else if (leftvt == VT_DATE || rightvt == VT_DATE)
                    resvt = VT_DATE;
                else if (leftvt == VT_CY || rightvt == VT_CY)
                    resvt = VT_CY;
                else if (leftvt == VT_R8 || rightvt == VT_R8)
                    resvt = VT_R8;
                else if (leftvt == VT_BSTR || rightvt == VT_BSTR) {
                    if ((leftvt == VT_BSTR && rightvt == VT_BSTR) ||
                         leftvt == VT_EMPTY || rightvt == VT_EMPTY)
                        resvt = VT_BSTR;
                    else
                        resvt = VT_R8;
                } else if (leftvt == VT_R4 || rightvt == VT_R4) {
                    if (leftvt == VT_I4 || rightvt == VT_I4 ||
                        leftvt == VT_I8 || rightvt == VT_I8)
                        resvt = VT_R8;
                    else
                        resvt = VT_R4;
                }
                else if (leftvt == VT_I8 || rightvt == VT_I8)
                    resvt = VT_I8;
                else if (leftvt == VT_I4 || rightvt == VT_I4)
                    resvt = VT_I4;
                else if (leftvt == VT_I2 || rightvt == VT_I2 ||
                         leftvt == VT_BOOL || rightvt == VT_BOOL ||
                         (leftvt == VT_EMPTY && rightvt == VT_EMPTY))
                    resvt = VT_I2;
                else if (leftvt == VT_UI1 || rightvt == VT_UI1)
                    resvt = VT_UI1;

                hres = pVarAdd(&left, &right, &result);
                if (bFail) {
                    ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
5652
                       "VarAdd: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n",
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5653 5654 5655 5656
                       leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
                       V_VT(&result));
                } else {
                    ok(hres == S_OK && V_VT(&result) == resvt,
5657
                       "VarAdd: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n",
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5658 5659 5660
                       leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
                       V_VT(&result));
                }
5661 5662
                /* Note, we don't clear left/right deliberately here */
                VariantClear(&result);
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5663 5664 5665 5666 5667 5668 5669 5670 5671
            }
        }
    }

    /* Test returned values */
    VARADD(I4,4,I4,2,I4,6);
    VARADD(I2,4,I2,2,I2,6);
    VARADD(I2,-13,I4,5,I4,-8);
    VARADD(I4,-13,I4,5,I4,-8);
5672 5673
    VARADD(I2,7,R4,0.5f,R4,7.5f);
    VARADD(R4,0.5f,I4,5,R8,5.5);
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5674 5675 5676
    VARADD(R8,7.1,BOOL,0,R8,7.1);
    VARADD(BSTR,lbstr,I2,4,R8,16);
    VARADD(BSTR,lbstr,BOOL,1,R8,13);
5677 5678
    VARADD(BSTR,lbstr,R4,0.1f,R8,12.1);
    VARADD(R4,0.2f,BSTR,rbstr,R8,12.2);
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5679
    VARADD(DATE,2.25,I4,7,DATE,9.25);
5680
    VARADD(DATE,1.25,R4,-1.7f,DATE,-0.45);
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5681 5682 5683 5684 5685 5686

    VARADD(UI1, UI1_MAX, UI1, UI1_MAX, I2, UI1_MAX + UI1_MAX);
    VARADD(I2, I2_MAX, I2, I2_MAX, I4, I2_MAX + I2_MAX);
    VARADD(I2, I2_MAX, I2, I2_MIN, I2, I2_MAX + I2_MIN);
    VARADD(I2, I2_MIN, I2, I2_MIN, I4, I2_MIN + I2_MIN);
    VARADD(I4, I4_MAX, I4, I4_MIN, I4, I4_MAX + I4_MIN);
5687 5688
    VARADD(I4, I4_MAX, I4, I4_MAX, R8, (double)I4_MAX + I4_MAX);
    VARADD(I4, I4_MIN, I4, I4_MIN, R8, (double)I4_MIN + I4_MIN);
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5689 5690 5691 5692 5693 5694
    VARADD(R4, R4_MAX, R4, R4_MAX, R8, (double)R4_MAX + R4_MAX);
    VARADD(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX + R4_MIN);
    VARADD(R4, R4_MIN, R4, R4_MIN, R4, R4_MIN + R4_MIN);
    VARADD(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX + R8_MIN);
    VARADD(R8, R8_MIN, R8, R8_MIN, R8, R8_MIN + R8_MIN);

5695
    /* Manually test BSTR + BSTR */
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5696 5697 5698 5699
    V_VT(&left) = VT_BSTR;
    V_BSTR(&left) = lbstr;
    V_VT(&right) = VT_BSTR;
    V_BSTR(&right) = rbstr;
5700
    hres = pVarAdd(&left, &right, &result);
5701
    ok(hres == S_OK && V_VT(&result) == VT_BSTR, "VarAdd: expected coerced type VT_BSTR, got %s!\n", vtstr(V_VT(&result)));
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5702
    hres = VarR8FromStr(V_BSTR(&result), 0, 0, &r);
5703
    ok(hres == S_OK && EQ_DOUBLE(r, 1212.0), "VarAdd: BSTR value %f, expected %f\n", r, (double)1212);
5704
    VariantClear(&result);
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719

    /* Manuly test some VT_CY and VT_DECIMAL variants */
    V_VT(&cy) = VT_CY;
    hres = VarCyFromI4(4711, &V_CY(&cy));
    ok(hres == S_OK, "VarCyFromI4 failed!\n");
    V_VT(&dec) = VT_DECIMAL;
    hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec));
    ok(hres == S_OK, "VarDecFromR4 failed!\n");
    memset(&left, 0, sizeof(left));
    memset(&right, 0, sizeof(right));
    V_VT(&left) = VT_I4;
    V_I4(&left) = -11;
    V_VT(&right) = VT_UI1;
    V_UI1(&right) = 9;

5720
    hres = pVarAdd(&cy, &right, &result);
5721
    ok(hres == S_OK && V_VT(&result) == VT_CY, "VarAdd: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result)));
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5722
    hres = VarR8FromCy(V_CY(&result), &r);
5723
    ok(hres == S_OK && EQ_DOUBLE(r, 4720.0), "VarAdd: CY value %f, expected %f\n", r, (double)4720);
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5724

5725
    hres = pVarAdd(&left, &dec, &result);
5726
    ok(hres == S_OK && V_VT(&result) == VT_DECIMAL, "VarAdd: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5727 5728
    hres = VarR8FromDec(&V_DECIMAL(&result), &r);
    ok(hres == S_OK && EQ_DOUBLE(r, -15.2), "VarAdd: DECIMAL value %f, expected %f\n", r, (double)-15.2);
5729
    VariantClear(&result);
5730 5731 5732

    SysFreeString(lbstr);
    SysFreeString(rbstr);
Michael Stefaniuc's avatar
Michael Stefaniuc committed
5733 5734
}

5735 5736 5737
static HRESULT (WINAPI *pVarCmp)(LPVARIANT,LPVARIANT,LCID,ULONG);
static HRESULT (WINAPI *pVarCat)(LPVARIANT,LPVARIANT,LPVARIANT);

5738 5739 5740
static void test_VarCat(void)
{
    LCID lcid;
5741
    VARIANT left, right, result, expected, expected_broken;
5742 5743 5744
    static const WCHAR sz34[] = {'3','4','\0'};
    static const WCHAR sz1234[] = {'1','2','3','4','\0'};
    static const WCHAR date_sz12[] = {'9','/','3','0','/','1','9','8','0','1','2','\0'};
5745
    static const WCHAR date_sz12_broken[] = {'9','/','3','0','/','8','0','1','2','\0'};
5746
    static const WCHAR sz12_date[] = {'1','2','9','/','3','0','/','1','9','8','0','\0'};
5747
    static const WCHAR sz12_date_broken[] = {'1','2','9','/','3','0','/','8','0','\0'};
5748
    static const WCHAR sz_empty[] = {'\0'};
5749
    CHAR orig_date_format[128];
5750 5751
    VARTYPE leftvt, rightvt, resultvt;
    HRESULT hres;
5752
    HRESULT expected_error_num;
5753
    int cmp;
5754
    DummyDispatch dispatch;
5755

5756 5757
    CHECKPTR(VarCat);

5758 5759
    /* Set date format for testing */
    lcid = LOCALE_USER_DEFAULT;
5760 5761
    GetLocaleInfoA(lcid,LOCALE_SSHORTDATE,orig_date_format,128);
    SetLocaleInfoA(lcid,LOCALE_SSHORTDATE,"M/d/yyyy");
5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773

    VariantInit(&left);
    VariantInit(&right);
    VariantInit(&result);
    VariantInit(&expected);

    /* Check expected types for all combinations */
    for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
    {

        SKIPTESTS(leftvt);

5774
        /* Check if we need/have support for I8 and/or UI8 */
5775
        if ((leftvt == VT_I8 || leftvt == VT_UI8) && !has_i8)
5776 5777
            continue;

5778 5779
        for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
        {
5780

5781
            SKIPTESTS(rightvt);
5782 5783
            expected_error_num = S_OK;
            resultvt = VT_EMPTY;
5784 5785 5786 5787

            if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
                leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN  ||
                leftvt == VT_RECORD || rightvt == VT_RECORD  ||
5788 5789
                leftvt == 15 || rightvt == 15 /* Undefined type */)
                continue;
5790

5791
            /* Check if we need/have support for I8 and/or UI8 */
5792
            if ((rightvt == VT_I8 || rightvt == VT_UI8) && !has_i8)
5793 5794
                continue;

5795
            if (leftvt == VT_NULL && rightvt == VT_NULL)
5796
                resultvt = VT_NULL;
5797 5798 5799
            else if (leftvt == VT_VARIANT && (rightvt == VT_ERROR ||
                rightvt == VT_DATE || rightvt == VT_DECIMAL))
                expected_error_num = DISP_E_TYPEMISMATCH;
5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821
            else if ((leftvt == VT_I2 || leftvt == VT_I4 ||
                leftvt == VT_R4 || leftvt == VT_R8 ||
                leftvt == VT_CY || leftvt == VT_BOOL ||
                leftvt == VT_BSTR || leftvt == VT_I1 ||
                leftvt == VT_UI1 || leftvt == VT_UI2 ||
                leftvt == VT_UI4 || leftvt == VT_I8 ||
                leftvt == VT_UI8 || leftvt == VT_INT ||
                leftvt == VT_UINT || leftvt == VT_EMPTY ||
                leftvt == VT_NULL || leftvt == VT_DECIMAL ||
                leftvt == VT_DATE)
                &&
                (rightvt == VT_I2 || rightvt == VT_I4 ||
                rightvt == VT_R4 || rightvt == VT_R8 ||
                rightvt == VT_CY || rightvt == VT_BOOL ||
                rightvt == VT_BSTR || rightvt == VT_I1 ||
                rightvt == VT_UI1 || rightvt == VT_UI2 ||
                rightvt == VT_UI4 || rightvt == VT_I8 ||
                rightvt == VT_UI8 || rightvt == VT_INT ||
                rightvt == VT_UINT || rightvt == VT_EMPTY ||
                rightvt == VT_NULL || rightvt == VT_DECIMAL ||
                rightvt == VT_DATE))
                resultvt = VT_BSTR;
5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845
            else if (rightvt == VT_ERROR && leftvt < VT_VOID)
                expected_error_num = DISP_E_TYPEMISMATCH;
            else if (leftvt == VT_ERROR && (rightvt == VT_DATE ||
                rightvt == VT_ERROR || rightvt == VT_DECIMAL))
                expected_error_num = DISP_E_TYPEMISMATCH;
            else if (rightvt == VT_DATE || rightvt == VT_ERROR ||
                rightvt == VT_DECIMAL)
                expected_error_num = DISP_E_BADVARTYPE;
            else if (leftvt == VT_ERROR || rightvt == VT_ERROR)
                expected_error_num = DISP_E_TYPEMISMATCH;
            else if (leftvt == VT_VARIANT)
                expected_error_num = DISP_E_TYPEMISMATCH;
            else if (rightvt == VT_VARIANT && (leftvt == VT_EMPTY ||
                leftvt == VT_NULL || leftvt ==  VT_I2 ||
                leftvt == VT_I4 || leftvt == VT_R4 ||
                leftvt == VT_R8 || leftvt == VT_CY ||
                leftvt == VT_DATE || leftvt == VT_BSTR ||
                leftvt == VT_BOOL ||  leftvt == VT_DECIMAL ||
                leftvt == VT_I1 || leftvt == VT_UI1 ||
                leftvt == VT_UI2 || leftvt == VT_UI4 ||
                leftvt == VT_I8 || leftvt == VT_UI8 ||
                leftvt == VT_INT || leftvt == VT_UINT
                ))
                expected_error_num = DISP_E_TYPEMISMATCH;
5846
            else
5847
                expected_error_num = DISP_E_BADVARTYPE;
5848 5849 5850 5851

            V_VT(&left) = leftvt;
            V_VT(&right) = rightvt;

5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872
            switch (leftvt) {
            case VT_BSTR:
                V_BSTR(&left) = SysAllocString(sz_empty); break;
            case VT_DATE:
                V_DATE(&left) = 0.0; break;
            case VT_DECIMAL:
                VarDecFromR8(0.0, &V_DECIMAL(&left)); break;
            default:
                V_I8(&left) = 0;
            }

            switch (rightvt) {
            case VT_BSTR:
                V_BSTR(&right) = SysAllocString(sz_empty); break;
            case VT_DATE:
                V_DATE(&right) = 0.0; break;
            case VT_DECIMAL:
                VarDecFromR8(0.0, &V_DECIMAL(&right)); break;
            default:
                V_I8(&right) = 0;
            }
5873

5874
            hres = pVarCat(&left, &right, &result);
5875

5876 5877
            /* Determine the error code for the vt combination */
            ok(hres == expected_error_num,
5878
                "VarCat: %d, %d returned error, 0x%X expected 0x%X.\n",
5879
                leftvt, rightvt, hres, expected_error_num);
5880 5881 5882 5883 5884

            /* Check types are correct */
            ok(V_VT(&result) == resultvt,
                "VarCat: %d, %d: expected vt %d, got vt %d\n",
                leftvt, rightvt, resultvt, V_VT(&result));
5885 5886 5887 5888 5889 5890 5891

            VariantClear(&left);
            VariantClear(&right);
            VariantClear(&result);
        }
    }

5892
    /* Running single comparison tests to compare outputs */
5893 5894 5895 5896 5897 5898 5899 5900

    /* Test concat strings */
    V_VT(&left) = VT_BSTR;
    V_VT(&right) = VT_BSTR;
    V_VT(&expected) = VT_BSTR;
    V_BSTR(&left) = SysAllocString(sz12);
    V_BSTR(&right) = SysAllocString(sz34);
    V_BSTR(&expected) = SysAllocString(sz1234);
5901
    hres = pVarCat(&left,&right,&result);
5902
    ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5903 5904 5905
    if (pVarCmp)
        ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ,
           "VarCat: VT_BSTR concat with VT_BSTR failed to return correct result\n");
5906 5907 5908 5909 5910 5911 5912 5913

    VariantClear(&left);
    VariantClear(&right);
    VariantClear(&result);

    /* Test if expression is VT_ERROR */
    V_VT(&left) = VT_ERROR;
    V_VT(&right) = VT_BSTR;
5914
    V_BSTR(&right) = 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 5918 5919 5920 5921 5922 5923 5924 5925
    ok(V_VT(&result) == VT_EMPTY,
        "VarCat: VT_ERROR concat with VT_BSTR should have returned VT_EMPTY\n");

    VariantClear(&left);
    VariantClear(&right);
    VariantClear(&result);

    V_VT(&left) = VT_BSTR;
    V_VT(&right) = VT_ERROR;
5926
    V_BSTR(&left) = SysAllocString(sz1234);
5927
    hres = pVarCat(&left,&right,&result);
5928
    ok(hres == DISP_E_TYPEMISMATCH, "VarCat should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hres);
5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943
    ok(V_VT(&result) == VT_EMPTY,
        "VarCat: VT_BSTR concat with VT_ERROR should have returned VT_EMPTY\n");

    VariantClear(&left);
    VariantClear(&right);
    VariantClear(&result);
    VariantClear(&expected);

    /* Test combining boolean with number */
    V_VT(&left) = VT_INT;
    V_VT(&right) = VT_BOOL;
    V_VT(&expected) = VT_BSTR;
    V_INT(&left) = 12;
    V_BOOL(&right) = TRUE;
    V_BSTR(&expected) = SysAllocString(sz12_true);
5944
    hres = pVarCat(&left,&right,&result);
5945
    ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5946 5947 5948 5949 5950 5951
    if (pVarCmp)
    {
        hres = pVarCmp(&result,&expected,lcid,0);
        ok(hres == VARCMP_EQ, "Expected VARCMP_EQ, got %08x for %s, %s\n",
           hres, variantstr(&result), variantstr(&expected));
    }
5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963

    VariantClear(&left);
    VariantClear(&right);
    VariantClear(&result);
    VariantClear(&expected);

    V_VT(&left) = VT_INT;
    V_VT(&right) = VT_BOOL;
    V_VT(&expected) = VT_BSTR;
    V_INT(&left) = 12;
    V_BOOL(&right) = FALSE;
    V_BSTR(&expected) = SysAllocString(sz12_false);
5964
    hres = pVarCat(&left,&right,&result);
5965
    ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5966 5967 5968 5969 5970 5971
    if (pVarCmp)
    {
        hres = pVarCmp(&result,&expected,lcid,0);
        ok(hres == VARCMP_EQ, "Expected VARCMP_EQ, got %08x for %s, %s\n",
           hres, variantstr(&result), variantstr(&expected));
    }
5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984

    VariantClear(&left);
    VariantClear(&right);
    VariantClear(&result);
    VariantClear(&expected);

    /* Test when both expressions are numeric */
    V_VT(&left) = VT_INT;
    V_VT(&right) = VT_INT;
    V_VT(&expected) = VT_BSTR;
    V_INT(&left)  = 12;
    V_INT(&right) = 34;
    V_BSTR(&expected) = SysAllocString(sz1234);
5985
    hres = pVarCat(&left,&right,&result);
5986
    ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
5987 5988 5989
    if (pVarCmp)
        ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ,
           "VarCat: NUMBER concat with NUMBER returned incorrect result\n");
5990 5991 5992 5993 5994 5995 5996 5997 5998 5999

    VariantClear(&left);
    VariantClear(&right);
    VariantClear(&result);

    /* Test if one expression is numeric and the other is a string */
    V_VT(&left) = VT_INT;
    V_VT(&right) = VT_BSTR;
    V_INT(&left) = 12;
    V_BSTR(&right) = SysAllocString(sz34);
6000
    hres = pVarCat(&left,&right,&result);
6001
    ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
6002 6003 6004
    if (pVarCmp)
        ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ,
           "VarCat: NUMBER concat with VT_BSTR, incorrect result\n");
6005 6006 6007 6008 6009 6010 6011 6012 6013

    VariantClear(&left);
    VariantClear(&right);
    VariantClear(&result);

    V_VT(&left) = VT_BSTR;
    V_VT(&right) = VT_INT;
    V_BSTR(&left) = SysAllocString(sz12);
    V_INT(&right) = 34;
6014
    hres = pVarCat(&left,&right,&result);
6015
    ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
6016 6017 6018
    if (pVarCmp)
        ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ,
           "VarCat: VT_BSTR concat with NUMBER, incorrect result\n");
6019 6020 6021 6022

    VariantClear(&left);
    VariantClear(&right);
    VariantClear(&result);
6023
    VariantClear(&expected);
6024 6025 6026 6027 6028

    /* Test concat dates with strings */
    V_VT(&left) = VT_BSTR;
    V_VT(&right) = VT_DATE;
    V_VT(&expected) = VT_BSTR;
6029
    V_VT(&expected_broken) = VT_BSTR;
6030 6031 6032
    V_BSTR(&left) = SysAllocString(sz12);
    V_DATE(&right) = 29494.0;
    V_BSTR(&expected)= SysAllocString(sz12_date);
6033
    V_BSTR(&expected_broken)= SysAllocString(sz12_date_broken);
6034
    hres = pVarCat(&left,&right,&result);
6035
    ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
6036 6037 6038 6039
    if (pVarCmp)
        ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ ||
           broken(pVarCmp(&result,&expected_broken,lcid,0) == VARCMP_EQ), /* Some W98 and NT4 (intermittent) */
           "VarCat: VT_BSTR concat with VT_DATE returned incorrect result\n");
6040 6041 6042 6043 6044

    VariantClear(&left);
    VariantClear(&right);
    VariantClear(&result);
    VariantClear(&expected);
6045
    VariantClear(&expected_broken);
6046 6047 6048 6049

    V_VT(&left) = VT_DATE;
    V_VT(&right) = VT_BSTR;
    V_VT(&expected) = VT_BSTR;
6050
    V_VT(&expected_broken) = VT_BSTR;
6051 6052 6053
    V_DATE(&left) = 29494.0;
    V_BSTR(&right) = SysAllocString(sz12);
    V_BSTR(&expected)= SysAllocString(date_sz12);
6054
    V_BSTR(&expected_broken)= SysAllocString(date_sz12_broken);
6055
    hres = pVarCat(&left,&right,&result);
6056
    ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
6057 6058 6059 6060
    if (pVarCmp)
        ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ ||
           broken(pVarCmp(&result,&expected_broken,lcid,0) == VARCMP_EQ), /* Some W98 and NT4 (intermittent) */
           "VarCat: VT_DATE concat with VT_BSTR returned incorrect result\n");
6061 6062 6063 6064 6065

    VariantClear(&left);
    VariantClear(&right);
    VariantClear(&result);
    VariantClear(&expected);
6066
    VariantClear(&expected_broken);
6067 6068 6069 6070 6071 6072 6073 6074

    /* Test of both expressions are empty */
    V_VT(&left) = VT_BSTR;
    V_VT(&right) = VT_BSTR;
    V_VT(&expected) = VT_BSTR;
    V_BSTR(&left) = SysAllocString(sz_empty);
    V_BSTR(&right) = SysAllocString(sz_empty);
    V_BSTR(&expected)= SysAllocString(sz_empty);
6075
    hres = pVarCat(&left,&right,&result);
6076
    ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
6077 6078 6079
    if (pVarCmp)
        ok(pVarCmp(&result,&left,lcid,0) == VARCMP_EQ,
           "VarCat: EMPTY concat with EMPTY did not return empty VT_BSTR\n");
6080 6081

    /* Restore original date format settings */
6082
    SetLocaleInfoA(lcid,LOCALE_SSHORTDATE,orig_date_format);
6083 6084 6085 6086 6087

    VariantClear(&left);
    VariantClear(&right);
    VariantClear(&result);
    VariantClear(&expected);
6088

6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149
    /* Dispatch conversion */
    init_test_dispatch(VT_NULL, &dispatch);
    V_VT(&left) = VT_DISPATCH;
    V_DISPATCH(&left) = &dispatch.IDispatch_iface;

    SET_EXPECT(dispatch_invoke);
    hres = VarCat(&left, &right, &result);
    todo_wine ok(hres == S_OK, "got 0x%08x\n", hres);
    ok(V_VT(&result) == VT_BSTR, "got %d\n", V_VT(&result));
    ok(SysStringLen(V_BSTR(&result)) == 0, "got %d\n", SysStringLen(V_BSTR(&result)));
    CHECK_CALLED(dispatch_invoke);

    VariantClear(&left);
    VariantClear(&right);
    VariantClear(&result);

    init_test_dispatch(VT_NULL, &dispatch);
    V_VT(&right) = VT_DISPATCH;
    V_DISPATCH(&right) = &dispatch.IDispatch_iface;

    SET_EXPECT(dispatch_invoke);
    hres = VarCat(&left, &right, &result);
    todo_wine ok(hres == S_OK, "got 0x%08x\n", hres);
    ok(V_VT(&result) == VT_BSTR, "got %d\n", V_VT(&result));
    ok(SysStringLen(V_BSTR(&result)) == 0, "got %d\n", SysStringLen(V_BSTR(&result)));
    CHECK_CALLED(dispatch_invoke);

    VariantClear(&left);
    VariantClear(&right);
    VariantClear(&result);

    init_test_dispatch(VT_UI1, &dispatch);
    V_VT(&right) = VT_DISPATCH;
    V_DISPATCH(&right) = &dispatch.IDispatch_iface;

    V_VT(&left) = VT_BSTR;
    V_BSTR(&left) = SysAllocString(sz12);
    SET_EXPECT(dispatch_invoke);
    hres = pVarCat(&left,&right,&result);
    ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres);
    CHECK_CALLED(dispatch_invoke);
    ok(!strcmp_wa(V_BSTR(&result), "1234"), "got %s\n", wine_dbgstr_w(V_BSTR(&result)));

    VariantClear(&left);
    VariantClear(&right);
    VariantClear(&result);

    init_test_dispatch(VT_NULL, &dispatch);
    dispatch.result = E_OUTOFMEMORY;
    V_VT(&right) = VT_DISPATCH;
    V_DISPATCH(&right) = &dispatch.IDispatch_iface;

    SET_EXPECT(dispatch_invoke);
    hres = VarCat(&left, &right, &result);
    todo_wine ok(hres == E_OUTOFMEMORY, "got 0x%08x\n", hres);
    CHECK_CALLED(dispatch_invoke);

    VariantClear(&left);
    VariantClear(&right);
    VariantClear(&result);

6150 6151 6152 6153 6154
    /* Test boolean conversion */
    V_VT(&left) = VT_BOOL;
    V_BOOL(&left) = VARIANT_TRUE;
    V_VT(&right) = VT_BSTR;
    V_BSTR(&right) = SysAllocStringLen(NULL,0);
6155
    hres = pVarCat(&left, &right, &result);
6156
    ok(hres == S_OK, "VarCat failed: %08x\n", hres);
6157 6158 6159 6160 6161
    VariantClear(&right);

    cmp = strcmp_wa(V_BSTR(&result), "True");
    VariantClear(&result);
    if(!cmp) {
6162 6163
        V_VT(&right) = VT_BOOL;
        V_BOOL(&right) = 100;
6164
        hres = pVarCat(&left, &right, &result);
6165 6166 6167 6168 6169
        ok(hres == S_OK, "VarCat failed: %08x\n", hres);
        test_bstr_var(&result, "TrueTrue");
        VariantClear(&result);

        V_BOOL(&right) = VARIANT_FALSE;
6170
        hres = pVarCat(&left, &right, &result);
6171 6172 6173 6174 6175 6176
        ok(hres == S_OK, "VarCat failed: %08x\n", hres);
        test_bstr_var(&result, "TrueFalse");
        VariantClear(&result);
    }else {
        skip("Got %s as True, assuming non-English locale\n", wine_dbgstr_w(V_BSTR(&result)));
    }
6177 6178
}

6179 6180
static HRESULT (WINAPI *pVarAnd)(LPVARIANT,LPVARIANT,LPVARIANT);

6181 6182 6183 6184
#define VARAND(vt1,val1,vt2,val2,rvt,rval)               \
        V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
        V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
        V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
6185
        test_var_call2( __LINE__, pVarAnd, &left, &right, &exp )
6186 6187 6188 6189 6190

#define VARANDCY(vt1,val1,val2,rvt,rval)                 \
        V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
        V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \
        V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
6191
        test_var_call2( __LINE__, pVarAnd, &left, &right, &exp )
6192

6193
/* Skip any type that is not defined or produces an error for every case */
6194 6195 6196 6197
#define SKIPTESTAND(a)                                \
        if (a == VT_ERROR || a == VT_VARIANT ||       \
            a == VT_DISPATCH || a == VT_UNKNOWN ||    \
            a > VT_UINT || a == 15 /*not defined*/)   \
6198
            continue
6199 6200 6201 6202 6203

static void test_VarAnd(void)
{
    static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
    static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
6204
    VARIANT left, right, exp, result;
6205 6206 6207 6208
    BSTR false_str, true_str;
    VARTYPE i;
    HRESULT hres;

6209 6210
    CHECKPTR(VarAnd);

6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222
    true_str = SysAllocString(szTrue);
    false_str = SysAllocString(szFalse);

    /* Test all possible flag/vt combinations & the resulting vt type */
    for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
    {
        VARTYPE leftvt, rightvt, resvt;

        for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
        {
            SKIPTESTAND(leftvt);

6223
            /* Check if we need/have support for I8 and/or UI8 */
6224
            if ((leftvt == VT_I8 || leftvt == VT_UI8) && !has_i8)
6225 6226
                continue;

6227 6228 6229 6230 6231
            for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
            {
                BOOL bFail = FALSE;
                SKIPTESTAND(rightvt);

6232
                /* Check if we need/have support for I8 and/or UI8 */
6233
                if ((rightvt == VT_I8 || rightvt == VT_UI8) && !has_i8)
6234 6235
                    continue;

6236 6237 6238 6239 6240 6241
                memset(&left, 0, sizeof(left));
                memset(&right, 0, sizeof(right));
                V_VT(&left) = leftvt | ExtraFlags[i];
                V_VT(&right) = rightvt | ExtraFlags[i];
                V_VT(&result) = VT_EMPTY;
                resvt = VT_EMPTY;
6242
                if ((leftvt | ExtraFlags[i]) == VT_BSTR)
6243
                    V_BSTR(&left) = true_str;
6244
                if ((rightvt | ExtraFlags[i]) == VT_BSTR)
6245 6246
                    V_BSTR(&right) = true_str;

6247
                /* Native VarAnd always returns an error when using extra
6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293
                 * flags or if the variant combination is I8 and INT.
                 */
                if ((leftvt == VT_I8 && rightvt == VT_INT) ||
                    (leftvt == VT_INT && rightvt == VT_I8) ||
                    ExtraFlags[i] != 0)
                    bFail = TRUE;

                /* Determine return type */
                else if (leftvt == VT_I8 || rightvt == VT_I8)
                    resvt = VT_I8;
                else if (leftvt == VT_I4 || rightvt == VT_I4 ||
                    leftvt == VT_UINT || rightvt == VT_UINT ||
                    leftvt == VT_INT || rightvt == VT_INT ||
                    leftvt == VT_R4 || rightvt == VT_R4 ||
                    leftvt == VT_R8 || rightvt == VT_R8 ||
                    leftvt == VT_CY || rightvt == VT_CY ||
                    leftvt == VT_DATE || rightvt == VT_DATE ||
                    leftvt == VT_I1 || rightvt == VT_I1 ||
                    leftvt == VT_UI2 || rightvt == VT_UI2 ||
                    leftvt == VT_UI4 || rightvt == VT_UI4 ||
                    leftvt == VT_UI8 || rightvt == VT_UI8 ||
                    leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
                    resvt = VT_I4;
                else if (leftvt == VT_UI1 || rightvt == VT_UI1 ||
                    leftvt == VT_I2 || rightvt == VT_I2 ||
                    leftvt == VT_EMPTY || rightvt == VT_EMPTY)
                    if ((leftvt == VT_NULL && rightvt == VT_UI1) ||
                        (leftvt == VT_UI1 && rightvt == VT_NULL) ||
                        (leftvt == VT_UI1 && rightvt == VT_UI1))
                        resvt = VT_UI1;
                    else
                        resvt = VT_I2;
                else if (leftvt == VT_BOOL || rightvt == VT_BOOL ||
                    (leftvt == VT_BSTR && rightvt == VT_BSTR))
                    resvt = VT_BOOL;
                else if (leftvt == VT_NULL || rightvt == VT_NULL ||
                    leftvt == VT_BSTR || rightvt == VT_BSTR)
                    resvt = VT_NULL;
                else
                    bFail = TRUE;

                hres = pVarAnd(&left, &right, &result);

                /* Check expected HRESULT and if result variant type is correct */
                if (bFail)
                    ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH,
6294
                        "VarAnd: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
6295 6296 6297 6298
                        vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
                        vtstr(V_VT(&result)), hres);
                else
                    ok (hres == S_OK && resvt == V_VT(&result),
6299
                        "VarAnd: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335
                        vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
                        S_OK, vtstr(V_VT(&result)), hres);
            }
        }
    }

    /*
     * Test returned values. Since we know the returned type is correct
     * and that we handle all combinations of invalid types, just check
     * that good type combinations produce the desired value.
     * FIXME: Test VT_DECIMAL
     */
    VARAND(EMPTY,0,EMPTY,0,I2,0);
    VARAND(EMPTY,1,EMPTY,0,I2,0);
    VARAND(EMPTY,1,EMPTY,1,I2,0);
    VARAND(EMPTY,0,NULL,0,I2,0);
    VARAND(EMPTY,1,NULL,0,I2,0);
    VARAND(EMPTY,1,NULL,1,I2,0);
    VARAND(EMPTY,0,I1,0,I4,0);
    VARAND(EMPTY,0,I1,1,I4,0);
    VARAND(EMPTY,1,I1,1,I4,0);
    VARAND(EMPTY,0,UI1,0,I2,0);
    VARAND(EMPTY,0,UI1,1,I2,0);
    VARAND(EMPTY,1,UI1,1,I2,0);
    VARAND(EMPTY,0,I2,0,I2,0);
    VARAND(EMPTY,0,I2,1,I2,0);
    VARAND(EMPTY,1,I2,1,I2,0);
    VARAND(EMPTY,0,UI2,0,I4,0);
    VARAND(EMPTY,0,UI2,1,I4,0);
    VARAND(EMPTY,1,UI2,1,I4,0);
    VARAND(EMPTY,0,I4,0,I4,0);
    VARAND(EMPTY,0,I4,1,I4,0);
    VARAND(EMPTY,1,I4,1,I4,0);
    VARAND(EMPTY,0,UI4,0,I4,0);
    VARAND(EMPTY,0,UI4,1,I4,0);
    VARAND(EMPTY,1,UI4,1,I4,0);
6336
    if (has_i8)
6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378
    {
        VARAND(EMPTY,0,I8,0,I8,0);
        VARAND(EMPTY,0,I8,1,I8,0);
        VARAND(EMPTY,1,I8,1,I8,0);
        VARAND(EMPTY,0,UI8,0,I4,0);
        VARAND(EMPTY,0,UI8,1,I4,0);
        VARAND(EMPTY,1,UI8,1,I4,0);
    }
    VARAND(EMPTY,0,INT,0,I4,0);
    VARAND(EMPTY,0,INT,1,I4,0);
    VARAND(EMPTY,1,INT,1,I4,0);
    VARAND(EMPTY,0,UINT,0,I4,0);
    VARAND(EMPTY,0,UINT,1,I4,0);
    VARAND(EMPTY,1,UINT,1,I4,0);
    VARAND(EMPTY,0,BOOL,0,I2,0);
    VARAND(EMPTY,0,BOOL,1,I2,0);
    VARAND(EMPTY,1,BOOL,1,I2,0);
    VARAND(EMPTY,0,R4,0,I4,0);
    VARAND(EMPTY,0,R4,1,I4,0);
    VARAND(EMPTY,1,R4,1,I4,0);
    VARAND(EMPTY,0,R8,0,I4,0);
    VARAND(EMPTY,0,R8,1,I4,0);
    VARAND(EMPTY,1,R8,1,I4,0);
    VARAND(EMPTY,0,BSTR,false_str,I2,0);
    VARAND(EMPTY,0,BSTR,true_str,I2,0);
    VARANDCY(EMPTY,0,10000,I4,0);

    /* NULL OR 0 = NULL. NULL OR n = n */
    VARAND(NULL,0,NULL,0,NULL,0);
    VARAND(NULL,1,NULL,0,NULL,0);
    VARAND(NULL,0,I1,0,I4,0);
    VARAND(NULL,0,I1,1,NULL,0);
    VARAND(NULL,0,UI1,0,UI1,0);
    VARAND(NULL,0,UI1,1,NULL,0);
    VARAND(NULL,0,I2,0,I2,0);
    VARAND(NULL,0,I2,1,NULL,0);
    VARAND(NULL,0,UI2,0,I4,0);
    VARAND(NULL,0,UI2,1,NULL,0);
    VARAND(NULL,0,I4,0,I4,0);
    VARAND(NULL,0,I4,1,NULL,0);
    VARAND(NULL,0,UI4,0,I4,0);
    VARAND(NULL,0,UI4,1,NULL,0);
6379
    if (has_i8)
6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432
    {
        VARAND(NULL,0,I8,0,I8,0);
        VARAND(NULL,0,I8,1,NULL,0);
        VARAND(NULL,0,UI8,0,I4,0);
        VARAND(NULL,0,UI8,1,NULL,0);
    }
    VARAND(NULL,0,INT,0,I4,0);
    VARAND(NULL,0,INT,1,NULL,0);
    VARAND(NULL,0,UINT,0,I4,0);
    VARAND(NULL,0,UINT,1,NULL,0);
    VARAND(NULL,0,BOOL,0,BOOL,0);
    VARAND(NULL,0,BOOL,1,NULL,0);
    VARAND(NULL,0,R4,0,I4,0);
    VARAND(NULL,0,R4,1,NULL,0);
    VARAND(NULL,0,R8,0,I4,0);
    VARAND(NULL,0,R8,1,NULL,0);
    VARAND(NULL,0,BSTR,false_str,BOOL,0);
    VARAND(NULL,0,BSTR,true_str,NULL,VARIANT_FALSE);
    VARANDCY(NULL,0,10000,NULL,0);
    VARANDCY(NULL,0,0,I4,0);
    VARAND(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
    VARAND(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
    VARAND(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
    VARAND(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);

    /* Assume x,y & y,x are the same from now on to reduce the number of tests */
    VARAND(BOOL,VARIANT_TRUE,I1,-1,I4,-1);
    VARAND(BOOL,VARIANT_TRUE,I1,0,I4,0);
    VARAND(BOOL,VARIANT_FALSE,I1,0,I4,0);
    VARAND(BOOL,VARIANT_TRUE,UI1,255,I2,255);
    VARAND(BOOL,VARIANT_TRUE,UI1,0,I2,0);
    VARAND(BOOL,VARIANT_FALSE,UI1,0,I2,0);
    VARAND(BOOL,VARIANT_TRUE,I2,-1,I2,-1);
    VARAND(BOOL,VARIANT_TRUE,I2,0,I2,0);
    VARAND(BOOL,VARIANT_FALSE,I2,0,I2,0);
    VARAND(BOOL,VARIANT_TRUE,UI2,65535,I4,65535);
    VARAND(BOOL,VARIANT_TRUE,UI2,0,I4,0);
    VARAND(BOOL,VARIANT_FALSE,UI2,0,I4,0);
    VARAND(BOOL,VARIANT_TRUE,I4,-1,I4,-1);
    VARAND(BOOL,VARIANT_TRUE,I4,0,I4,0);
    VARAND(BOOL,VARIANT_FALSE,I4,0,I4,0);
    VARAND(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,-1);
    VARAND(BOOL,VARIANT_TRUE,UI4,0,I4,0);
    VARAND(BOOL,VARIANT_FALSE,UI4,0,I4,0);
    VARAND(BOOL,VARIANT_TRUE,R4,-1,I4,-1);
    VARAND(BOOL,VARIANT_TRUE,R4,0,I4,0);
    VARAND(BOOL,VARIANT_FALSE,R4,0,I4,0);
    VARAND(BOOL,VARIANT_TRUE,R8,-1,I4,-1);
    VARAND(BOOL,VARIANT_TRUE,R8,0,I4,0);
    VARAND(BOOL,VARIANT_FALSE,R8,0,I4,0);
    VARAND(BOOL,VARIANT_TRUE,DATE,-1,I4,-1);
    VARAND(BOOL,VARIANT_TRUE,DATE,0,I4,0);
    VARAND(BOOL,VARIANT_FALSE,DATE,0,I4,0);
6433
    if (has_i8)
6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480
    {
        VARAND(BOOL,VARIANT_TRUE,I8,-1,I8,-1);
        VARAND(BOOL,VARIANT_TRUE,I8,0,I8,0);
        VARAND(BOOL,VARIANT_FALSE,I8,0,I8,0);
        VARAND(BOOL,VARIANT_TRUE,UI8,0,I4,0);
        VARAND(BOOL,VARIANT_FALSE,UI8,0,I4,0);
    }
    VARAND(BOOL,VARIANT_TRUE,INT,-1,I4,-1);
    VARAND(BOOL,VARIANT_TRUE,INT,0,I4,0);
    VARAND(BOOL,VARIANT_FALSE,INT,0,I4,0);
    VARAND(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,-1);
    VARAND(BOOL,VARIANT_TRUE,UINT,0,I4,0);
    VARAND(BOOL,VARIANT_FALSE,UINT,0,I4,0);
    VARAND(BOOL,VARIANT_FALSE,BSTR,false_str,BOOL,VARIANT_FALSE);
    VARAND(BOOL,VARIANT_TRUE,BSTR,false_str,BOOL,VARIANT_FALSE);
    VARAND(BOOL,VARIANT_FALSE,BSTR,true_str,BOOL,VARIANT_FALSE);
    VARAND(BOOL,VARIANT_TRUE,BSTR,true_str,BOOL,VARIANT_TRUE);
    VARANDCY(BOOL,VARIANT_TRUE,10000,I4,1);
    VARANDCY(BOOL,VARIANT_TRUE,0,I4,0);
    VARANDCY(BOOL,VARIANT_FALSE,0,I4,0);
    VARAND(I1,-1,I1,-1,I4,-1);
    VARAND(I1,-1,I1,0,I4,0);
    VARAND(I1,0,I1,0,I4,0);
    VARAND(I1,-1,UI1,255,I4,255);
    VARAND(I1,-1,UI1,0,I4,0);
    VARAND(I1,0,UI1,0,I4,0);
    VARAND(I1,-1,I2,-1,I4,-1);
    VARAND(I1,-1,I2,0,I4,0);
    VARAND(I1,0,I2,0,I4,0);
    VARAND(I1,-1,UI2,65535,I4,65535);
    VARAND(I1,-1,UI2,0,I4,0);
    VARAND(I1,0,UI2,0,I4,0);
    VARAND(I1,-1,I4,-1,I4,-1);
    VARAND(I1,-1,I4,0,I4,0);
    VARAND(I1,0,I4,0,I4,0);
    VARAND(I1,-1,UI4,0xffffffff,I4,-1);
    VARAND(I1,-1,UI4,0,I4,0);
    VARAND(I1,0,UI4,0,I4,0);
    VARAND(I1,-1,R4,-1,I4,-1);
    VARAND(I1,-1,R4,0,I4,0);
    VARAND(I1,0,R4,0,I4,0);
    VARAND(I1,-1,R8,-1,I4,-1);
    VARAND(I1,-1,R8,0,I4,0);
    VARAND(I1,0,R8,0,I4,0);
    VARAND(I1,-1,DATE,-1,I4,-1);
    VARAND(I1,-1,DATE,0,I4,0);
    VARAND(I1,0,DATE,0,I4,0);
6481
    if (has_i8)
6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526
    {
        VARAND(I1,-1,I8,-1,I8,-1);
        VARAND(I1,-1,I8,0,I8,0);
        VARAND(I1,0,I8,0,I8,0);
        VARAND(I1,-1,UI8,0,I4,0);
        VARAND(I1,0,UI8,0,I4,0);
    }
    VARAND(I1,-1,INT,-1,I4,-1);
    VARAND(I1,-1,INT,0,I4,0);
    VARAND(I1,0,INT,0,I4,0);
    VARAND(I1,-1,UINT,0xffffffff,I4,-1);
    VARAND(I1,-1,UINT,0,I4,0);
    VARAND(I1,0,UINT,0,I4,0);
    VARAND(I1,0,BSTR,false_str,I4,0);
    VARAND(I1,-1,BSTR,false_str,I4,0);
    VARAND(I1,0,BSTR,true_str,I4,0);
    VARAND(I1,-1,BSTR,true_str,I4,-1);
    VARANDCY(I1,-1,10000,I4,1);
    VARANDCY(I1,-1,0,I4,0);
    VARANDCY(I1,0,0,I4,0);

    VARAND(UI1,255,UI1,255,UI1,255);
    VARAND(UI1,255,UI1,0,UI1,0);
    VARAND(UI1,0,UI1,0,UI1,0);
    VARAND(UI1,255,I2,-1,I2,255);
    VARAND(UI1,255,I2,0,I2,0);
    VARAND(UI1,0,I2,0,I2,0);
    VARAND(UI1,255,UI2,65535,I4,255);
    VARAND(UI1,255,UI2,0,I4,0);
    VARAND(UI1,0,UI2,0,I4,0);
    VARAND(UI1,255,I4,-1,I4,255);
    VARAND(UI1,255,I4,0,I4,0);
    VARAND(UI1,0,I4,0,I4,0);
    VARAND(UI1,255,UI4,0xffffffff,I4,255);
    VARAND(UI1,255,UI4,0,I4,0);
    VARAND(UI1,0,UI4,0,I4,0);
    VARAND(UI1,255,R4,-1,I4,255);
    VARAND(UI1,255,R4,0,I4,0);
    VARAND(UI1,0,R4,0,I4,0);
    VARAND(UI1,255,R8,-1,I4,255);
    VARAND(UI1,255,R8,0,I4,0);
    VARAND(UI1,0,R8,0,I4,0);
    VARAND(UI1,255,DATE,-1,I4,255);
    VARAND(UI1,255,DATE,0,I4,0);
    VARAND(UI1,0,DATE,0,I4,0);
6527
    if (has_i8)
6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569
    {
        VARAND(UI1,255,I8,-1,I8,255);
        VARAND(UI1,255,I8,0,I8,0);
        VARAND(UI1,0,I8,0,I8,0);
        VARAND(UI1,255,UI8,0,I4,0);
        VARAND(UI1,0,UI8,0,I4,0);
    }
    VARAND(UI1,255,INT,-1,I4,255);
    VARAND(UI1,255,INT,0,I4,0);
    VARAND(UI1,0,INT,0,I4,0);
    VARAND(UI1,255,UINT,0xffffffff,I4,255);
    VARAND(UI1,255,UINT,0,I4,0);
    VARAND(UI1,0,UINT,0,I4,0);
    VARAND(UI1,0,BSTR,false_str,I2,0);
    VARAND(UI1,255,BSTR,false_str,I2,0);
    VARAND(UI1,0,BSTR,true_str,I2,0);
    VARAND(UI1,255,BSTR,true_str,I2,255);
    VARANDCY(UI1,255,10000,I4,1);
    VARANDCY(UI1,255,0,I4,0);
    VARANDCY(UI1,0,0,I4,0);

    VARAND(I2,-1,I2,-1,I2,-1);
    VARAND(I2,-1,I2,0,I2,0);
    VARAND(I2,0,I2,0,I2,0);
    VARAND(I2,-1,UI2,65535,I4,65535);
    VARAND(I2,-1,UI2,0,I4,0);
    VARAND(I2,0,UI2,0,I4,0);
    VARAND(I2,-1,I4,-1,I4,-1);
    VARAND(I2,-1,I4,0,I4,0);
    VARAND(I2,0,I4,0,I4,0);
    VARAND(I2,-1,UI4,0xffffffff,I4,-1);
    VARAND(I2,-1,UI4,0,I4,0);
    VARAND(I2,0,UI4,0,I4,0);
    VARAND(I2,-1,R4,-1,I4,-1);
    VARAND(I2,-1,R4,0,I4,0);
    VARAND(I2,0,R4,0,I4,0);
    VARAND(I2,-1,R8,-1,I4,-1);
    VARAND(I2,-1,R8,0,I4,0);
    VARAND(I2,0,R8,0,I4,0);
    VARAND(I2,-1,DATE,-1,I4,-1);
    VARAND(I2,-1,DATE,0,I4,0);
    VARAND(I2,0,DATE,0,I4,0);
6570
    if (has_i8)
6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609
    {
        VARAND(I2,-1,I8,-1,I8,-1);
        VARAND(I2,-1,I8,0,I8,0);
        VARAND(I2,0,I8,0,I8,0);
        VARAND(I2,-1,UI8,0,I4,0);
        VARAND(I2,0,UI8,0,I4,0);
    }
    VARAND(I2,-1,INT,-1,I4,-1);
    VARAND(I2,-1,INT,0,I4,0);
    VARAND(I2,0,INT,0,I4,0);
    VARAND(I2,-1,UINT,0xffffffff,I4,-1);
    VARAND(I2,-1,UINT,0,I4,0);
    VARAND(I2,0,UINT,0,I4,0);
    VARAND(I2,0,BSTR,false_str,I2,0);
    VARAND(I2,-1,BSTR,false_str,I2,0);
    VARAND(I2,0,BSTR,true_str,I2,0);
    VARAND(I2,-1,BSTR,true_str,I2,-1);
    VARANDCY(I2,-1,10000,I4,1);
    VARANDCY(I2,-1,0,I4,0);
    VARANDCY(I2,0,0,I4,0);

    VARAND(UI2,65535,UI2,65535,I4,65535);
    VARAND(UI2,65535,UI2,0,I4,0);
    VARAND(UI2,0,UI2,0,I4,0);
    VARAND(UI2,65535,I4,-1,I4,65535);
    VARAND(UI2,65535,I4,0,I4,0);
    VARAND(UI2,0,I4,0,I4,0);
    VARAND(UI2,65535,UI4,0xffffffff,I4,65535);
    VARAND(UI2,65535,UI4,0,I4,0);
    VARAND(UI2,0,UI4,0,I4,0);
    VARAND(UI2,65535,R4,-1,I4,65535);
    VARAND(UI2,65535,R4,0,I4,0);
    VARAND(UI2,0,R4,0,I4,0);
    VARAND(UI2,65535,R8,-1,I4,65535);
    VARAND(UI2,65535,R8,0,I4,0);
    VARAND(UI2,0,R8,0,I4,0);
    VARAND(UI2,65535,DATE,-1,I4,65535);
    VARAND(UI2,65535,DATE,0,I4,0);
    VARAND(UI2,0,DATE,0,I4,0);
6610
    if (has_i8)
6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646
    {
        VARAND(UI2,65535,I8,-1,I8,65535);
        VARAND(UI2,65535,I8,0,I8,0);
        VARAND(UI2,0,I8,0,I8,0);
        VARAND(UI2,65535,UI8,0,I4,0);
        VARAND(UI2,0,UI8,0,I4,0);
    }
    VARAND(UI2,65535,INT,-1,I4,65535);
    VARAND(UI2,65535,INT,0,I4,0);
    VARAND(UI2,0,INT,0,I4,0);
    VARAND(UI2,65535,UINT,0xffffffff,I4,65535);
    VARAND(UI2,65535,UINT,0,I4,0);
    VARAND(UI2,0,UINT,0,I4,0);
    VARAND(UI2,0,BSTR,false_str,I4,0);
    VARAND(UI2,65535,BSTR,false_str,I4,0);
    VARAND(UI2,0,BSTR,true_str,I4,0);
    VARAND(UI2,65535,BSTR,true_str,I4,65535);
    VARANDCY(UI2,65535,10000,I4,1);
    VARANDCY(UI2,65535,0,I4,0);
    VARANDCY(UI2,0,0,I4,0);

    VARAND(I4,-1,I4,-1,I4,-1);
    VARAND(I4,-1,I4,0,I4,0);
    VARAND(I4,0,I4,0,I4,0);
    VARAND(I4,-1,UI4,0xffffffff,I4,-1);
    VARAND(I4,-1,UI4,0,I4,0);
    VARAND(I4,0,UI4,0,I4,0);
    VARAND(I4,-1,R4,-1,I4,-1);
    VARAND(I4,-1,R4,0,I4,0);
    VARAND(I4,0,R4,0,I4,0);
    VARAND(I4,-1,R8,-1,I4,-1);
    VARAND(I4,-1,R8,0,I4,0);
    VARAND(I4,0,R8,0,I4,0);
    VARAND(I4,-1,DATE,-1,I4,-1);
    VARAND(I4,-1,DATE,0,I4,0);
    VARAND(I4,0,DATE,0,I4,0);
6647
    if (has_i8)
6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680
    {
        VARAND(I4,-1,I8,-1,I8,-1);
        VARAND(I4,-1,I8,0,I8,0);
        VARAND(I4,0,I8,0,I8,0);
        VARAND(I4,-1,UI8,0,I4,0);
        VARAND(I4,0,UI8,0,I4,0);
    }
    VARAND(I4,-1,INT,-1,I4,-1);
    VARAND(I4,-1,INT,0,I4,0);
    VARAND(I4,0,INT,0,I4,0);
    VARAND(I4,-1,UINT,0xffffffff,I4,-1);
    VARAND(I4,-1,UINT,0,I4,0);
    VARAND(I4,0,UINT,0,I4,0);
    VARAND(I4,0,BSTR,false_str,I4,0);
    VARAND(I4,-1,BSTR,false_str,I4,0);
    VARAND(I4,0,BSTR,true_str,I4,0);
    VARAND(I4,-1,BSTR,true_str,I4,-1);
    VARANDCY(I4,-1,10000,I4,1);
    VARANDCY(I4,-1,0,I4,0);
    VARANDCY(I4,0,0,I4,0);

    VARAND(UI4,0xffffffff,UI4,0xffffffff,I4,-1);
    VARAND(UI4,0xffffffff,UI4,0,I4,0);
    VARAND(UI4,0,UI4,0,I4,0);
    VARAND(UI4,0xffffffff,R4,-1,I4,-1);
    VARAND(UI4,0xffffffff,R4,0,I4,0);
    VARAND(UI4,0,R4,0,I4,0);
    VARAND(UI4,0xffffffff,R8,-1,I4,-1);
    VARAND(UI4,0xffffffff,R8,0,I4,0);
    VARAND(UI4,0,R8,0,I4,0);
    VARAND(UI4,0xffffffff,DATE,-1,I4,-1);
    VARAND(UI4,0xffffffff,DATE,0,I4,0);
    VARAND(UI4,0,DATE,0,I4,0);
6681
    if (has_i8)
6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710
    {
        VARAND(UI4,0xffffffff,I8,0,I8,0);
        VARAND(UI4,0,I8,0,I8,0);
        VARAND(UI4,0xffffffff,UI8,0,I4,0);
        VARAND(UI4,0,UI8,0,I4,0);
    }
    VARAND(UI4,0xffffffff,INT,-1,I4,-1);
    VARAND(UI4,0xffffffff,INT,0,I4,0);
    VARAND(UI4,0,INT,0,I4,0);
    VARAND(UI4,0xffffffff,UINT,0xffffffff,I4,-1);
    VARAND(UI4,0xffffffff,UINT,0,I4,0);
    VARAND(UI4,0,UINT,0,I4,0);
    VARAND(UI4,0,BSTR,false_str,I4,0);
    VARAND(UI4,0xffffffff,BSTR,false_str,I4,0);
    VARAND(UI4,0,BSTR,true_str,I4,0);
    VARAND(UI4,0xffffffff,BSTR,true_str,I4,-1);
    VARANDCY(UI4,0xffffffff,10000,I4,1);
    VARANDCY(UI4,0xffffffff,0,I4,0);
    VARANDCY(UI4,0,0,I4,0);

    VARAND(R4,-1,R4,-1,I4,-1);
    VARAND(R4,-1,R4,0,I4,0);
    VARAND(R4,0,R4,0,I4,0);
    VARAND(R4,-1,R8,-1,I4,-1);
    VARAND(R4,-1,R8,0,I4,0);
    VARAND(R4,0,R8,0,I4,0);
    VARAND(R4,-1,DATE,-1,I4,-1);
    VARAND(R4,-1,DATE,0,I4,0);
    VARAND(R4,0,DATE,0,I4,0);
6711
    if (has_i8)
6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738
    {
        VARAND(R4,-1,I8,-1,I8,-1);
        VARAND(R4,-1,I8,0,I8,0);
        VARAND(R4,0,I8,0,I8,0);
        VARAND(R4,-1,UI8,0,I4,0);
        VARAND(R4,0,UI8,0,I4,0);
    }
    VARAND(R4,-1,INT,-1,I4,-1);
    VARAND(R4,-1,INT,0,I4,0);
    VARAND(R4,0,INT,0,I4,0);
    VARAND(R4,-1,UINT,0xffffffff,I4,-1);
    VARAND(R4,-1,UINT,0,I4,0);
    VARAND(R4,0,UINT,0,I4,0);
    VARAND(R4,0,BSTR,false_str,I4,0);
    VARAND(R4,-1,BSTR,false_str,I4,0);
    VARAND(R4,0,BSTR,true_str,I4,0);
    VARAND(R4,-1,BSTR,true_str,I4,-1);
    VARANDCY(R4,-1,10000,I4,1);
    VARANDCY(R4,-1,0,I4,0);
    VARANDCY(R4,0,0,I4,0);

    VARAND(R8,-1,R8,-1,I4,-1);
    VARAND(R8,-1,R8,0,I4,0);
    VARAND(R8,0,R8,0,I4,0);
    VARAND(R8,-1,DATE,-1,I4,-1);
    VARAND(R8,-1,DATE,0,I4,0);
    VARAND(R8,0,DATE,0,I4,0);
6739
    if (has_i8)
6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763
    {
        VARAND(R8,-1,I8,-1,I8,-1);
        VARAND(R8,-1,I8,0,I8,0);
        VARAND(R8,0,I8,0,I8,0);
        VARAND(R8,-1,UI8,0,I4,0);
        VARAND(R8,0,UI8,0,I4,0);
    }
    VARAND(R8,-1,INT,-1,I4,-1);
    VARAND(R8,-1,INT,0,I4,0);
    VARAND(R8,0,INT,0,I4,0);
    VARAND(R8,-1,UINT,0xffffffff,I4,-1);
    VARAND(R8,-1,UINT,0,I4,0);
    VARAND(R8,0,UINT,0,I4,0);
    VARAND(R8,0,BSTR,false_str,I4,0);
    VARAND(R8,-1,BSTR,false_str,I4,0);
    VARAND(R8,0,BSTR,true_str,I4,0);
    VARAND(R8,-1,BSTR,true_str,I4,-1);
    VARANDCY(R8,-1,10000,I4,1);
    VARANDCY(R8,-1,0,I4,0);
    VARANDCY(R8,0,0,I4,0);

    VARAND(DATE,-1,DATE,-1,I4,-1);
    VARAND(DATE,-1,DATE,0,I4,0);
    VARAND(DATE,0,DATE,0,I4,0);
6764
    if (has_i8)
6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785
    {
        VARAND(DATE,-1,I8,-1,I8,-1);
        VARAND(DATE,-1,I8,0,I8,0);
        VARAND(DATE,0,I8,0,I8,0);
        VARAND(DATE,-1,UI8,0,I4,0);
        VARAND(DATE,0,UI8,0,I4,0);
    }
    VARAND(DATE,-1,INT,-1,I4,-1);
    VARAND(DATE,-1,INT,0,I4,0);
    VARAND(DATE,0,INT,0,I4,0);
    VARAND(DATE,-1,UINT,0xffffffff,I4,-1);
    VARAND(DATE,-1,UINT,0,I4,0);
    VARAND(DATE,0,UINT,0,I4,0);
    VARAND(DATE,0,BSTR,false_str,I4,0);
    VARAND(DATE,-1,BSTR,false_str,I4,0);
    VARAND(DATE,0,BSTR,true_str,I4,0);
    VARAND(DATE,-1,BSTR,true_str,I4,-1);
    VARANDCY(DATE,-1,10000,I4,1);
    VARANDCY(DATE,-1,0,I4,0);
    VARANDCY(DATE,0,0,I4,0);

6786
    if (has_i8)
6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855
    {
        VARAND(I8,-1,I8,-1,I8,-1);
        VARAND(I8,-1,I8,0,I8,0);
        VARAND(I8,0,I8,0,I8,0);
        VARAND(I8,-1,UI8,0,I8,0);
        VARAND(I8,0,UI8,0,I8,0);
        VARAND(I8,-1,UINT,0,I8,0);
        VARAND(I8,0,UINT,0,I8,0);
        VARAND(I8,0,BSTR,false_str,I8,0);
        VARAND(I8,-1,BSTR,false_str,I8,0);
        VARAND(I8,0,BSTR,true_str,I8,0);
        VARAND(I8,-1,BSTR,true_str,I8,-1);
        VARANDCY(I8,-1,10000,I8,1);
        VARANDCY(I8,-1,0,I8,0);
        VARANDCY(I8,0,0,I8,0);

        VARAND(UI8,0xffff,UI8,0xffff,I4,0xffff);
        VARAND(UI8,0xffff,UI8,0,I4,0);
        VARAND(UI8,0,UI8,0,I4,0);
        VARAND(UI8,0xffff,INT,-1,I4,65535);
        VARAND(UI8,0xffff,INT,0,I4,0);
        VARAND(UI8,0,INT,0,I4,0);
        VARAND(UI8,0xffff,UINT,0xffff,I4,0xffff);
        VARAND(UI8,0xffff,UINT,0,I4,0);
        VARAND(UI8,0,UINT,0,I4,0);
        VARAND(UI8,0,BSTR,false_str,I4,0);
        VARAND(UI8,0xffff,BSTR,false_str,I4,0);
        VARAND(UI8,0,BSTR,true_str,I4,0);
        VARAND(UI8,0xffff,BSTR,true_str,I4,65535);
        VARANDCY(UI8,0xffff,10000,I4,1);
        VARANDCY(UI8,0xffff,0,I4,0);
        VARANDCY(UI8,0,0,I4,0);
    }

    VARAND(INT,-1,INT,-1,I4,-1);
    VARAND(INT,-1,INT,0,I4,0);
    VARAND(INT,0,INT,0,I4,0);
    VARAND(INT,-1,UINT,0xffff,I4,65535);
    VARAND(INT,-1,UINT,0,I4,0);
    VARAND(INT,0,UINT,0,I4,0);
    VARAND(INT,0,BSTR,false_str,I4,0);
    VARAND(INT,-1,BSTR,false_str,I4,0);
    VARAND(INT,0,BSTR,true_str,I4,0);
    VARAND(INT,-1,BSTR,true_str,I4,-1);
    VARANDCY(INT,-1,10000,I4,1);
    VARANDCY(INT,-1,0,I4,0);
    VARANDCY(INT,0,0,I4,0);

    VARAND(UINT,0xffff,UINT,0xffff,I4,0xffff);
    VARAND(UINT,0xffff,UINT,0,I4,0);
    VARAND(UINT,0,UINT,0,I4,0);
    VARAND(UINT,0,BSTR,false_str,I4,0);
    VARAND(UINT,0xffff,BSTR, false_str,I4,0);
    VARAND(UINT,0,BSTR,true_str,I4,0);
    VARAND(UINT,0xffff,BSTR,true_str,I4,65535);
    VARANDCY(UINT,0xffff,10000,I4,1);
    VARANDCY(UINT,0xffff,0,I4,0);
    VARANDCY(UINT,0,0,I4,0);

    VARAND(BSTR,false_str,BSTR,false_str,BOOL,0);
    VARAND(BSTR,true_str,BSTR,false_str,BOOL,VARIANT_FALSE);
    VARAND(BSTR,true_str,BSTR,true_str,BOOL,VARIANT_TRUE);
    VARANDCY(BSTR,true_str,10000,I4,1);
    VARANDCY(BSTR,false_str,10000,I4,0);

    SysFreeString(true_str);
    SysFreeString(false_str);
}

6856 6857 6858 6859
static void test_cmp( int line, LCID lcid, UINT flags, VARIANT *left, VARIANT *right, HRESULT result )
{
    HRESULT hres;

6860 6861
    CHECKPTR(VarCmp);

6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879
    hres = pVarCmp(left,right,lcid,flags);
    ok_(__FILE__,line)(hres == result, "VarCmp(%s,%s): expected 0x%x, got hres=0x%x\n",
                       variantstr(left), variantstr(right), result, hres );
}
static void test_cmpex( int line, LCID lcid, VARIANT *left, VARIANT *right,
                        HRESULT res1, HRESULT res2, HRESULT res3, HRESULT res4 )
{
    test_cmp( line, lcid, 0, left, right, res1 );
    V_VT(left) |= VT_RESERVED;
    test_cmp( line, lcid, 0, left, right, res2 );
    V_VT(left) &= ~VT_RESERVED;
    V_VT(right) |= VT_RESERVED;
    test_cmp( line, lcid, 0, left, right, res3 );
    V_VT(left) |= VT_RESERVED;
    test_cmp( line, lcid, 0, left, right, res4 );
    ok_(__FILE__,line)(V_VT(left) & V_VT(right) & VT_RESERVED, "VT_RESERVED filtered out\n");
}

6880 6881 6882 6883 6884
/* ERROR from wingdi.h is interfering here */
#undef ERROR
#define _VARCMP(vt1,val1,vtfl1,vt2,val2,vtfl2,lcid,flags,result) \
        V_##vt1(&left) = val1; V_VT(&left) = VT_##vt1 | vtfl1; \
        V_##vt2(&right) = val2; V_VT(&right) = VT_##vt2 | vtfl2; \
6885
        test_cmp( __LINE__, lcid, flags, &left, &right, result )
6886
#define VARCMPEX(vt1,val1,vt2,val2,res1,res2,res3,res4) \
6887 6888
        V_##vt1(&left) = val1; V_VT(&left) = VT_##vt1; \
        V_##vt2(&right) = val2; V_VT(&right) = VT_##vt2; \
6889
        test_cmpex( __LINE__, lcid, &left, &right, res1, res2, res3, res4 )
6890 6891
#define VARCMP(vt1,val1,vt2,val2,result) \
        VARCMPEX(vt1,val1,vt2,val2,result,result,result,result)
6892 6893 6894
/* The above macros do not work for VT_NULL as NULL gets expanded first */
#define V_NULL_  V_NULL
#define VT_NULL_ VT_NULL
6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003

static void test_VarCmp(void)
{
    VARIANT left, right;
    VARTYPE i;
    LCID lcid;
    HRESULT hres;
    DECIMAL dec;
    static const WCHAR szhuh[] = {'h','u','h','?','\0'};
    static const WCHAR sz2cents[] = {'2','c','e','n','t','s','\0'};
    static const WCHAR szempty[] = {'\0'};
    static const WCHAR sz0[] = {'0','\0'};
    static const WCHAR sz1[] = {'1','\0'};
    static const WCHAR sz7[] = {'7','\0'};
    static const WCHAR sz42[] = {'4','2','\0'};
    static const WCHAR sz1neg[] = {'-','1','\0'};
    static const WCHAR sz666neg[] = {'-','6','6','6','\0'};
    static const WCHAR sz1few[] = {'1','.','0','0','0','0','0','0','0','1','\0'};
    BSTR bstrhuh, bstrempty, bstr0, bstr1, bstr7, bstr42, bstr1neg, bstr666neg;
    BSTR bstr2cents, bstr1few;

    CHECKPTR(VarCmp);

    lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
    bstrempty = SysAllocString(szempty);
    bstrhuh = SysAllocString(szhuh);
    bstr2cents = SysAllocString(sz2cents);
    bstr0 = SysAllocString(sz0);
    bstr1 = SysAllocString(sz1);
    bstr7 = SysAllocString(sz7);
    bstr42 = SysAllocString(sz42);
    bstr1neg = SysAllocString(sz1neg);
    bstr666neg = SysAllocString(sz666neg);
    bstr1few = SysAllocString(sz1few);

    /* Test all possible flag/vt combinations & the resulting vt type */
    for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
    {
        VARTYPE leftvt, rightvt;

        for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
        {

            SKIPTESTS(leftvt);

            for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
            {
                BOOL bFail = FALSE;
                HRESULT expect = VARCMP_EQ;

                SKIPTESTS(rightvt);

                memset(&left, 0, sizeof(left));
                memset(&right, 0, sizeof(right));
                V_VT(&left) = leftvt | ExtraFlags[i];
                if (leftvt == VT_BSTR) {
                    V_BSTR(&left) = bstr1neg;
                    if (ExtraFlags[i] & VT_RESERVED)
                        expect = VARCMP_LT;
                    else
                        expect = VARCMP_GT;
                }
                V_VT(&right) = rightvt | ExtraFlags[i];
                if (rightvt == VT_BSTR) {
                    V_BSTR(&right) = bstr1neg;
                    if (ExtraFlags[i] & VT_RESERVED)
                        expect = VARCMP_GT;
                    else
                        expect = VARCMP_LT;
                }

                /* Don't ask me why but native VarCmp cannot handle:
                   VT_I1, VT_UI2, VT_UI4, VT_UINT and VT_UI8.
                   VT_INT is only supported as left variant. Go figure.
                   Tested with DCOM98, Win2k, WinXP */
                if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
                    !IsValidVariantClearVT(leftvt, ExtraFlags[i] & ~VT_RESERVED) ||
                    !IsValidVariantClearVT(rightvt, ExtraFlags[i] & ~VT_RESERVED) ||
                    leftvt == VT_CLSID || rightvt == VT_CLSID ||
                    leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
                    leftvt == VT_ERROR || rightvt == VT_ERROR ||
                    leftvt == VT_RECORD || rightvt == VT_RECORD ||
                    leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN ||
                    leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
                    leftvt == VT_I1 || rightvt == VT_I1 ||
                    leftvt == VT_UI2 || rightvt == VT_UI2 ||
                    leftvt == VT_UI4 || rightvt == VT_UI4 ||
                    leftvt == VT_UI8 || rightvt == VT_UI8 ||
                    rightvt == VT_INT ||
                    leftvt == VT_UINT || rightvt == VT_UINT) {
                    bFail = TRUE;
                }

                if (leftvt == VT_ERROR && rightvt == VT_ERROR &&
                    !(ExtraFlags[i] & ~VT_RESERVED)) {
                    expect = VARCMP_EQ;
                    bFail = FALSE;
                } else if (leftvt == VT_NULL || rightvt == VT_NULL)
                    expect = VARCMP_NULL;
                else if (leftvt == VT_BSTR && rightvt == VT_BSTR)
                    expect = VARCMP_EQ;
                else if (leftvt == VT_BSTR && rightvt == VT_EMPTY)
                    expect = VARCMP_GT;
                else if (leftvt == VT_EMPTY && rightvt == VT_BSTR)
                    expect = VARCMP_LT;

                hres = pVarCmp(&left, &right, LOCALE_USER_DEFAULT, 0);
                if (bFail) {
                    ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
7004
                       "VarCmp: %d|0x%X, %d|0x%X: Expected failure, got 0x%X\n",
7005 7006 7007
                       leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres);
                } else {
                    ok(hres == expect,
7008
                       "VarCmp: %d|0x%X, %d|0x%X: Expected 0x%X, got 0x%X\n",
7009 7010 7011 7012 7013 7014 7015
                       leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], expect,
                       hres);
                }
            }
        }
    }

7016
    /* VARCMP{,EX} run each 4 tests with a permutation of all possible
7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027
       input variants with (1) and without (0) VT_RESERVED set. The order
       of the permutations is (0,0); (1,0); (0,1); (1,1) */
    VARCMP(INT,4711,I2,4711,VARCMP_EQ);
    VARCMP(INT,4711,I2,-4711,VARCMP_GT);
    VARCMP(ERROR,0,ERROR,0,VARCMP_EQ);
    VARCMP(ERROR,0,UI1,0,DISP_E_TYPEMISMATCH);
    VARCMP(EMPTY,0,EMPTY,0,VARCMP_EQ);
    VARCMP(I4,1,R8,1.0,VARCMP_EQ);
    VARCMP(EMPTY,19,I2,0,VARCMP_EQ);
    ok(V_EMPTY(&left) == 19, "VT_EMPTY modified!\n");
    VARCMP(I4,1,UI1,1,VARCMP_EQ);
7028 7029 7030 7031 7032
    VARCMP(I2,2,I2,2,VARCMP_EQ);
    VARCMP(I2,1,I2,2,VARCMP_LT);
    VARCMP(I2,2,I2,1,VARCMP_GT);
    VARCMP(I2,2,EMPTY,1,VARCMP_GT);
    VARCMP(I2,2,NULL_,1,VARCMP_NULL);
7033

7034
    /* BSTR handling, especially in conjunction with VT_RESERVED */
7035
    VARCMP(BSTR,bstr0,NULL_,0,VARCMP_NULL);
7036 7037 7038 7039 7040 7041 7042 7043
    VARCMP(BSTR,bstr0,BSTR,bstr0,VARCMP_EQ);
    VARCMP(BSTR,bstrempty,BSTR,bstr0,VARCMP_LT);
    VARCMP(BSTR,bstr7,BSTR,bstr0,VARCMP_GT);
    VARCMP(BSTR,bstr7,BSTR,bstr1neg,VARCMP_GT);
    VARCMP(BSTR,bstr0,BSTR,NULL,VARCMP_GT);
    VARCMP(BSTR,NULL,BSTR,NULL,VARCMP_EQ);
    VARCMP(BSTR,bstrempty,BSTR,NULL,VARCMP_EQ);
    VARCMP(BSTR,NULL,EMPTY,0,VARCMP_EQ);
7044
    VARCMP(EMPTY,0,BSTR,NULL,VARCMP_EQ);
7045 7046 7047
    VARCMP(EMPTY,0,BSTR,bstrempty,VARCMP_EQ);
    VARCMP(EMPTY,1,BSTR,bstrempty,VARCMP_EQ);
    VARCMP(BSTR,bstr0,EMPTY,0,VARCMP_GT);
7048
    VARCMP(BSTR,bstr42,EMPTY,0,VARCMP_GT);
7049 7050 7051 7052 7053
    VARCMPEX(BSTR,bstrempty,UI1,0,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
    VARCMPEX(BSTR,bstrempty,I2,-1,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
    VARCMPEX(I4,0,BSTR,bstrempty,VARCMP_LT,VARCMP_LT,VARCMP_GT,VARCMP_LT);
    VARCMPEX(BSTR,NULL,UI1,0,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
    VARCMPEX(I4,7,BSTR,NULL,VARCMP_LT,VARCMP_LT,VARCMP_GT,VARCMP_LT);
7054
    _VARCMP(BSTR,(BSTR)100,0,I2,100,0,lcid,0,VARCMP_GT);
7055 7056 7057 7058 7059 7060 7061
    VARCMPEX(BSTR,bstr0,UI1,0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
    VARCMPEX(I2,0,BSTR,bstr0,VARCMP_LT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT);
    VARCMP(BSTR,bstrhuh,I4,I4_MAX,VARCMP_GT);
    VARCMP(BSTR,bstr2cents,I4,2,VARCMP_GT);
    VARCMPEX(BSTR,bstr2cents,I4,42,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
    VARCMP(BSTR,bstr2cents,I4,-1,VARCMP_GT);
    VARCMPEX(BSTR,bstr2cents,I4,-666,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
7062
    VARCMPEX(BSTR,bstr0,I2,0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086
    VARCMPEX(BSTR,bstr0,I4,0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
    VARCMPEX(BSTR,bstr0,I4,-666,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
    VARCMP(BSTR,bstr1,I4,0,VARCMP_GT);
    VARCMPEX(BSTR,bstr1,I4,1,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
    VARCMPEX(BSTR,bstr1,I4,I4_MAX,VARCMP_GT,VARCMP_LT,VARCMP_LT,VARCMP_GT);
    VARCMPEX(BSTR,bstr1,I4,-1,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
    VARCMP(BSTR,bstr7,I4,1,VARCMP_GT);
    VARCMPEX(BSTR,bstr7,I4,7,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
    VARCMPEX(BSTR,bstr7,I4,42,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_GT);
    VARCMPEX(BSTR,bstr42,I4,7,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT);
    VARCMPEX(BSTR,bstr42,I4,42,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
    VARCMPEX(BSTR,bstr42,I4,I4_MAX,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_GT);
    VARCMPEX(BSTR,bstr1neg,I4,1,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
    VARCMPEX(BSTR,bstr1neg,I4,42,VARCMP_GT,VARCMP_LT,VARCMP_LT,VARCMP_LT);
    VARCMPEX(BSTR,bstr1neg,I4,-1,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT);
    VARCMPEX(BSTR,bstr1neg,I4,-666,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_LT);
    VARCMPEX(BSTR,bstr666neg,I4,1,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
    VARCMPEX(BSTR,bstr666neg,I4,7,VARCMP_GT,VARCMP_LT,VARCMP_LT,VARCMP_LT);
    VARCMPEX(BSTR,bstr666neg,I4,42,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
    VARCMPEX(BSTR,bstr666neg,I4,I4_MAX,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
    VARCMPEX(BSTR,bstr666neg,I4,-1,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT);
    VARCMPEX(BSTR,bstr666neg,I4,-666,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT);
    VARCMPEX(BSTR,bstr7,R8,7.0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT);
    VARCMPEX(R8,3.141592,BSTR,NULL,VARCMP_LT,VARCMP_LT,VARCMP_GT,VARCMP_LT);
7087 7088 7089
    VARCMP(BSTR,bstr7,BSTR,bstr7,VARCMP_EQ);
    VARCMP(BSTR,bstr7,BSTR,bstr42,VARCMP_GT);
    VARCMP(BSTR,bstr42,BSTR,bstr7,VARCMP_LT);
7090 7091

    /* DECIMAL handling */
7092
    setdec(&dec,0,0,0,0);
7093
    VARCMPEX(DECIMAL,dec,BSTR,bstr0,VARCMP_LT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT);
7094
    setdec64(&dec,0,0,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF); /* max DECIMAL */
7095 7096
    VARCMP(DECIMAL,dec,R8,R8_MAX,VARCMP_LT);    /* R8 has bigger range */
    VARCMP(DECIMAL,dec,DATE,R8_MAX,VARCMP_LT);  /* DATE has bigger range */
7097
    setdec64(&dec,0,0x80,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF);
7098
    VARCMP(DECIMAL,dec,R8,-R8_MAX,VARCMP_GT);
7099
    setdec64(&dec,20,0,0x5,0x6BC75E2D,0x63100001);    /* 1+1e-20 */
7100
    VARCMP(DECIMAL,dec,R8,1,VARCMP_GT); /* DECIMAL has higher precision */
7101 7102 7103 7104 7105 7106

    /* Show that DATE is handled just as a R8 */
    VARCMP(DATE,DATE_MAX,DATE,DATE_MAX+1,VARCMP_LT);
    VARCMP(DATE,DATE_MIN,DATE,DATE_MIN-1,VARCMP_GT);
    VARCMP(DATE,R8_MIN,R8,R8_MIN,VARCMP_EQ);
    VARCMP(DATE,1,DATE,1+1e-15,VARCMP_LT);      /* 1e-15 == 8.64e-11 seconds */
7107 7108 7109 7110 7111
    VARCMP(DATE,25570.0,DATE,25570.0,VARCMP_EQ);
    VARCMP(DATE,25570.0,DATE,25571.0,VARCMP_LT);
    VARCMP(DATE,25571.0,DATE,25570.0,VARCMP_GT);
    VARCMP(DATE,25570.0,EMPTY,0,VARCMP_GT);
    VARCMP(DATE,25570.0,NULL_,0,VARCMP_NULL);
7112

7113
    /* R4 precision handling */
7114 7115 7116 7117 7118 7119 7120
    VARCMP(R4,1,R8,1+1e-8,VARCMP_EQ);
    VARCMP(R8,1+1e-8,R4,1,VARCMP_EQ);
    VARCMP(R8,1+1e-8,R8,1,VARCMP_GT);
    VARCMP(R8,R4_MAX*1.1,R4,R4_MAX,VARCMP_GT);
    VARCMP(R4,R4_MAX,R8,R8_MAX,VARCMP_LT);
    VARCMP(R4,1,DATE,1+1e-8,VARCMP_EQ);
    VARCMP(R4,1,BSTR,bstr1few,VARCMP_LT); /* bstr1few == 1+1e-8 */
7121
    setdec(&dec,8,0,0,0x5F5E101);         /* 1+1e-8 */
7122
    VARCMP(R4,1,DECIMAL,dec,VARCMP_LT);
7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133

    SysFreeString(bstrhuh);
    SysFreeString(bstrempty);
    SysFreeString(bstr0);
    SysFreeString(bstr1);
    SysFreeString(bstr7);
    SysFreeString(bstr42);
    SysFreeString(bstr1neg);
    SysFreeString(bstr666neg);
    SysFreeString(bstr2cents);
    SysFreeString(bstr1few);
7134 7135
}

7136 7137
static HRESULT (WINAPI *pVarPow)(LPVARIANT,LPVARIANT,LPVARIANT);

7138 7139 7140 7141
#define VARPOW(vt1,val1,vt2,val2,rvt,rval)               \
        V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
        V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
        V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
7142
        test_var_call2( __LINE__, pVarPow, &left, &right, &exp )
7143

7144
/* Skip any type that is not defined or produces an error for every case */
7145 7146 7147 7148 7149
#define SKIPTESTPOW(a)                            \
    if (a == VT_ERROR || a == VT_VARIANT ||       \
        a == VT_DISPATCH || a == VT_UNKNOWN ||    \
        a == VT_RECORD || a > VT_UINT ||          \
        a == 15 /*not defined*/)                  \
7150
        continue
7151 7152 7153 7154 7155

static void test_VarPow(void)
{
    static const WCHAR str2[] = { '2','\0' };
    static const WCHAR str3[] = { '3','\0' };
7156
    VARIANT left, right, exp, result, cy, dec;
7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195
    BSTR num2_str, num3_str;
    VARTYPE i;
    HRESULT hres;

    CHECKPTR(VarPow);

    num2_str = SysAllocString(str2);
    num3_str = SysAllocString(str3);

    /* Test all possible flag/vt combinations & the resulting vt type */
    for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
    {
        VARTYPE leftvt, rightvt, resvt;

        for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
        {
            SKIPTESTPOW(leftvt);

            for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
            {
                BOOL bFail = FALSE;
                SKIPTESTPOW(rightvt);

                /* Native crashes with VT_BYREF */
                if (ExtraFlags[i] == VT_BYREF)
                    continue;

                memset(&left, 0, sizeof(left));
                memset(&right, 0, sizeof(right));
                V_VT(&left) = leftvt | ExtraFlags[i];
                V_VT(&right) = rightvt | ExtraFlags[i];
                V_VT(&result) = VT_EMPTY;
                resvt = VT_EMPTY;

                if (leftvt == VT_BSTR)
                    V_BSTR(&left) = num2_str;
                if (rightvt == VT_BSTR)
                    V_BSTR(&right) = num2_str;

7196
                /* Native VarPow always returns an error when using extra flags */
7197 7198 7199 7200
                if (ExtraFlags[i] != 0)
                    bFail = TRUE;

                /* Determine return type */
7201 7202
                else if ((leftvt == VT_NULL || rightvt == VT_NULL) &&
                         ((leftvt != VT_I8 && leftvt != VT_UI8 &&
7203
                           rightvt != VT_I8 && rightvt != VT_UI8) || has_i8))
7204 7205 7206 7207 7208 7209
                    resvt = VT_NULL;
                else if ((leftvt == VT_EMPTY || leftvt == VT_I2 ||
                    leftvt == VT_I4 || leftvt == VT_R4 ||
                    leftvt == VT_R8 || leftvt == VT_CY ||
                    leftvt == VT_DATE || leftvt == VT_BSTR ||
                    leftvt == VT_BOOL || leftvt == VT_DECIMAL ||
7210
                    (leftvt >= VT_I1 && leftvt <= VT_UI4) ||
7211
                    (has_i8 && (leftvt == VT_I8 || leftvt == VT_UI8)) ||
7212
                    leftvt == VT_INT || leftvt == VT_UINT) &&
7213 7214 7215 7216 7217
                    (rightvt == VT_EMPTY || rightvt == VT_I2 ||
                    rightvt == VT_I4 || rightvt == VT_R4 ||
                    rightvt == VT_R8 || rightvt == VT_CY ||
                    rightvt == VT_DATE || rightvt == VT_BSTR ||
                    rightvt == VT_BOOL || rightvt == VT_DECIMAL ||
7218
                    (rightvt >= VT_I1 && rightvt <= VT_UI4) ||
7219
                    (has_i8 && (rightvt == VT_I8 || rightvt == VT_UI8)) ||
7220
                    rightvt == VT_INT || rightvt == VT_UINT))
7221 7222 7223 7224 7225 7226 7227 7228 7229
                    resvt = VT_R8;
                else
                    bFail = TRUE;

                hres = pVarPow(&left, &right, &result);

                /* Check expected HRESULT and if result variant type is correct */
                if (bFail)
                    ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH,
7230
                        "VarPow: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
7231 7232 7233 7234
                        vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
                        vtstr(V_VT(&result)), hres);
                else
                    ok (hres == S_OK && resvt == V_VT(&result),
7235
                        "VarPow: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246
                        vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
                        S_OK, vtstr(V_VT(&result)), hres);
            }
        }
    }

    /* Check return values for valid variant type combinations */
    VARPOW(EMPTY,0,EMPTY,0,R8,1.0);
    VARPOW(EMPTY,0,NULL,0,NULL,0);
    VARPOW(EMPTY,0,I2,3,R8,0.0);
    VARPOW(EMPTY,0,I4,3,R8,0.0);
7247
    VARPOW(EMPTY,0,R4,3.0f,R8,0.0);
7248 7249 7250 7251 7252 7253 7254 7255
    VARPOW(EMPTY,0,R8,3.0,R8,0.0);
    VARPOW(EMPTY,0,DATE,3,R8,0.0);
    VARPOW(EMPTY,0,BSTR,num3_str,R8,0.0);
    VARPOW(EMPTY,0,BOOL,VARIANT_FALSE,R8,1.0);
    VARPOW(EMPTY,0,I1,3,R8,0.0);
    VARPOW(EMPTY,0,UI1,3,R8,0.0);
    VARPOW(EMPTY,0,UI2,3,R8,0.0);
    VARPOW(EMPTY,0,UI4,3,R8,0.0);
7256
    if (has_i8)
7257 7258 7259 7260
    {
        VARPOW(EMPTY,0,I8,3,R8,0.0);
        VARPOW(EMPTY,0,UI8,3,R8,0.0);
    }
7261 7262 7263 7264 7265 7266
    VARPOW(EMPTY,0,INT,3,R8,0.0);
    VARPOW(EMPTY,0,UINT,3,R8,0.0);
    VARPOW(NULL,0,EMPTY,0,NULL,0);
    VARPOW(NULL,0,NULL,0,NULL,0);
    VARPOW(NULL,0,I2,3,NULL,0);
    VARPOW(NULL,0,I4,3,NULL,0);
7267
    VARPOW(NULL,0,R4,3.0f,NULL,0);
7268 7269 7270 7271 7272 7273 7274 7275
    VARPOW(NULL,0,R8,3.0,NULL,0);
    VARPOW(NULL,0,DATE,3,NULL,0);
    VARPOW(NULL,0,BSTR,num3_str,NULL,0);
    VARPOW(NULL,0,BOOL,VARIANT_TRUE,NULL,0);
    VARPOW(NULL,0,I1,3,NULL,0);
    VARPOW(NULL,0,UI1,3,NULL,0);
    VARPOW(NULL,0,UI2,3,NULL,0);
    VARPOW(NULL,0,UI4,3,NULL,0);
7276
    if (has_i8)
7277 7278 7279 7280
    {
        VARPOW(NULL,0,I8,3,NULL,0);
        VARPOW(NULL,0,UI8,3,NULL,0);
    }
7281 7282 7283 7284 7285 7286
    VARPOW(NULL,0,INT,3,NULL,0);
    VARPOW(NULL,0,UINT,3,NULL,0);
    VARPOW(I2,2,EMPTY,0,R8,1.0);
    VARPOW(I2,2,NULL,0,NULL,0);
    VARPOW(I2,2,I2,3,R8,8.0);
    VARPOW(I2,2,I4,3,R8,8.0);
7287
    VARPOW(I2,2,R4,3.0f,R8,8.0);
7288 7289 7290 7291 7292 7293 7294 7295
    VARPOW(I2,2,R8,3.0,R8,8.0);
    VARPOW(I2,2,DATE,3,R8,8.0);
    VARPOW(I2,2,BSTR,num3_str,R8,8.0);
    VARPOW(I2,2,BOOL,VARIANT_FALSE,R8,1.0);
    VARPOW(I2,2,I1,3,R8,8.0);
    VARPOW(I2,2,UI1,3,R8,8.0);
    VARPOW(I2,2,UI2,3,R8,8.0);
    VARPOW(I2,2,UI4,3,R8,8.0);
7296
    if (has_i8)
7297 7298 7299 7300
    {
        VARPOW(I2,2,I8,3,R8,8.0);
        VARPOW(I2,2,UI8,3,R8,8.0);
    }
7301 7302 7303 7304 7305 7306
    VARPOW(I2,2,INT,3,R8,8.0);
    VARPOW(I2,2,UINT,3,R8,8.0);
    VARPOW(I4,2,EMPTY,0,R8,1.0);
    VARPOW(I4,2,NULL,0,NULL,0);
    VARPOW(I4,2,I2,3,R8,8.0);
    VARPOW(I4,2,I4,3,R8,8.0);
7307
    VARPOW(I4,2,R4,3.0f,R8,8.0);
7308 7309 7310 7311 7312 7313 7314 7315
    VARPOW(I4,2,R8,3.0,R8,8.0);
    VARPOW(I4,2,DATE,3,R8,8.0);
    VARPOW(I4,2,BSTR,num3_str,R8,8.0);
    VARPOW(I4,2,BOOL,VARIANT_FALSE,R8,1.0);
    VARPOW(I4,2,I1,3,R8,8.0);
    VARPOW(I4,2,UI1,3,R8,8.0);
    VARPOW(I4,2,UI2,3,R8,8.0);
    VARPOW(I4,2,UI4,3,R8,8.0);
7316
    if (has_i8)
7317 7318 7319 7320
    {
        VARPOW(I4,2,I8,3,R8,8.0);
        VARPOW(I4,2,UI8,3,R8,8.0);
    }
7321 7322 7323 7324 7325 7326
    VARPOW(I4,2,INT,3,R8,8.0);
    VARPOW(I4,2,UINT,3,R8,8.0);
    VARPOW(R4,2,EMPTY,0,R8,1.0);
    VARPOW(R4,2,NULL,0,NULL,0);
    VARPOW(R4,2,I2,3,R8,8.0);
    VARPOW(R4,2,I4,3,R8,8.0);
7327
    VARPOW(R4,2,R4,3.0f,R8,8.0);
7328 7329 7330 7331 7332 7333 7334 7335
    VARPOW(R4,2,R8,3.0,R8,8.0);
    VARPOW(R4,2,DATE,3,R8,8.0);
    VARPOW(R4,2,BSTR,num3_str,R8,8.0);
    VARPOW(R4,2,BOOL,VARIANT_FALSE,R8,1.0);
    VARPOW(R4,2,I1,3,R8,8.0);
    VARPOW(R4,2,UI1,3,R8,8.0);
    VARPOW(R4,2,UI2,3,R8,8.0);
    VARPOW(R4,2,UI4,3,R8,8.0);
7336
    if (has_i8)
7337 7338 7339 7340
    {
        VARPOW(R4,2,I8,3,R8,8.0);
        VARPOW(R4,2,UI8,3,R8,8.0);
    }
7341 7342 7343 7344 7345 7346
    VARPOW(R4,2,INT,3,R8,8.0);
    VARPOW(R4,2,UINT,3,R8,8.0);
    VARPOW(R8,2,EMPTY,0,R8,1.0);
    VARPOW(R8,2,NULL,0,NULL,0);
    VARPOW(R8,2,I2,3,R8,8.0);
    VARPOW(R8,2,I4,3,R8,8.0);
7347
    VARPOW(R8,2,R4,3.0f,R8,8.0);
7348 7349 7350 7351 7352 7353 7354 7355
    VARPOW(R8,2,R8,3.0,R8,8.0);
    VARPOW(R8,2,DATE,3,R8,8.0);
    VARPOW(R8,2,BSTR,num3_str,R8,8.0);
    VARPOW(R8,2,BOOL,VARIANT_FALSE,R8,1.0);
    VARPOW(R8,2,I1,3,R8,8.0);
    VARPOW(R8,2,UI1,3,R8,8.0);
    VARPOW(R8,2,UI2,3,R8,8.0);
    VARPOW(R8,2,UI4,3,R8,8.0);
7356
    if (has_i8)
7357 7358 7359 7360
    {
        VARPOW(R8,2,I8,3,R8,8.0);
        VARPOW(R8,2,UI8,3,R8,8.0);
    }
7361 7362 7363 7364 7365 7366
    VARPOW(R8,2,INT,3,R8,8.0);
    VARPOW(R8,2,UINT,3,R8,8.0);
    VARPOW(DATE,2,EMPTY,0,R8,1.0);
    VARPOW(DATE,2,NULL,0,NULL,0);
    VARPOW(DATE,2,I2,3,R8,8.0);
    VARPOW(DATE,2,I4,3,R8,8.0);
7367
    VARPOW(DATE,2,R4,3.0f,R8,8.0);
7368 7369 7370 7371 7372 7373 7374 7375
    VARPOW(DATE,2,R8,3.0,R8,8.0);
    VARPOW(DATE,2,DATE,3,R8,8.0);
    VARPOW(DATE,2,BSTR,num3_str,R8,8.0);
    VARPOW(DATE,2,BOOL,VARIANT_FALSE,R8,1.0);
    VARPOW(DATE,2,I1,3,R8,8.0);
    VARPOW(DATE,2,UI1,3,R8,8.0);
    VARPOW(DATE,2,UI2,3,R8,8.0);
    VARPOW(DATE,2,UI4,3,R8,8.0);
7376
    if (has_i8)
7377 7378 7379 7380
    {
        VARPOW(DATE,2,I8,3,R8,8.0);
        VARPOW(DATE,2,UI8,3,R8,8.0);
    }
7381 7382 7383 7384 7385 7386
    VARPOW(DATE,2,INT,3,R8,8.0);
    VARPOW(DATE,2,UINT,3,R8,8.0);
    VARPOW(BSTR,num2_str,EMPTY,0,R8,1.0);
    VARPOW(BSTR,num2_str,NULL,0,NULL,0);
    VARPOW(BSTR,num2_str,I2,3,R8,8.0);
    VARPOW(BSTR,num2_str,I4,3,R8,8.0);
7387
    VARPOW(BSTR,num2_str,R4,3.0f,R8,8.0);
7388 7389 7390 7391 7392 7393 7394 7395
    VARPOW(BSTR,num2_str,R8,3.0,R8,8.0);
    VARPOW(BSTR,num2_str,DATE,3,R8,8.0);
    VARPOW(BSTR,num2_str,BSTR,num3_str,R8,8.0);
    VARPOW(BSTR,num2_str,BOOL,VARIANT_FALSE,R8,1.0);
    VARPOW(BSTR,num2_str,I1,3,R8,8.0);
    VARPOW(BSTR,num2_str,UI1,3,R8,8.0);
    VARPOW(BSTR,num2_str,UI2,3,R8,8.0);
    VARPOW(BSTR,num2_str,UI4,3,R8,8.0);
7396
    if (has_i8)
7397 7398 7399 7400
    {
        VARPOW(BSTR,num2_str,I8,3,R8,8.0);
        VARPOW(BSTR,num2_str,UI8,3,R8,8.0);
    }
7401 7402 7403 7404 7405 7406
    VARPOW(BSTR,num2_str,INT,3,R8,8.0);
    VARPOW(BSTR,num2_str,UINT,3,R8,8.0);
    VARPOW(BOOL,VARIANT_TRUE,EMPTY,0,R8,1.0);
    VARPOW(BOOL,VARIANT_TRUE,NULL,0,NULL,0);
    VARPOW(BOOL,VARIANT_TRUE,I2,3,R8,-1.0);
    VARPOW(BOOL,VARIANT_TRUE,I4,3,R8,-1.0);
7407
    VARPOW(BOOL,VARIANT_TRUE,R4,3.0f,R8,-1.0);
7408 7409 7410 7411 7412 7413 7414 7415
    VARPOW(BOOL,VARIANT_TRUE,R8,3.0,R8,-1.0);
    VARPOW(BOOL,VARIANT_TRUE,DATE,3,R8,-1.0);
    VARPOW(BOOL,VARIANT_TRUE,BSTR,num3_str,R8,-1.0);
    VARPOW(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,R8,-1.0);
    VARPOW(BOOL,VARIANT_TRUE,I1,3,R8,-1.0);
    VARPOW(BOOL,VARIANT_TRUE,UI1,3,R8,-1.0);
    VARPOW(BOOL,VARIANT_TRUE,UI2,3,R8,-1.0);
    VARPOW(BOOL,VARIANT_TRUE,UI4,3,R8,-1.0);
7416
    if (has_i8)
7417 7418 7419 7420
    {
        VARPOW(BOOL,VARIANT_TRUE,I8,3,R8,-1.0);
        VARPOW(BOOL,VARIANT_TRUE,UI8,3,R8,-1.0);
    }
7421 7422 7423 7424 7425 7426
    VARPOW(BOOL,VARIANT_TRUE,INT,3,R8,-1.0);
    VARPOW(BOOL,VARIANT_TRUE,UINT,3,R8,-1.0);
    VARPOW(I1,2,EMPTY,0,R8,1.0);
    VARPOW(I1,2,NULL,0,NULL,0);
    VARPOW(I1,2,I2,3,R8,8.0);
    VARPOW(I1,2,I4,3,R8,8.0);
7427
    VARPOW(I1,2,R4,3.0f,R8,8.0);
7428 7429 7430 7431 7432 7433 7434 7435
    VARPOW(I1,2,R8,3.0,R8,8.0);
    VARPOW(I1,2,DATE,3,R8,8.0);
    VARPOW(I1,2,BSTR,num3_str,R8,8.0);
    VARPOW(I1,2,BOOL,VARIANT_FALSE,R8,1.0);
    VARPOW(I1,2,I1,3,R8,8.0);
    VARPOW(I1,2,UI1,3,R8,8.0);
    VARPOW(I1,2,UI2,3,R8,8.0);
    VARPOW(I1,2,UI4,3,R8,8.0);
7436
    if (has_i8)
7437 7438 7439 7440
    {
        VARPOW(I1,2,I8,3,R8,8.0);
        VARPOW(I1,2,UI8,3,R8,8.0);
    }
7441 7442 7443 7444 7445 7446
    VARPOW(I1,2,INT,3,R8,8.0);
    VARPOW(I1,2,UINT,3,R8,8.0);
    VARPOW(UI1,2,EMPTY,0,R8,1.0);
    VARPOW(UI1,2,NULL,0,NULL,0);
    VARPOW(UI1,2,I2,3,R8,8.0);
    VARPOW(UI1,2,I4,3,R8,8.0);
7447
    VARPOW(UI1,2,R4,3.0f,R8,8.0);
7448 7449 7450 7451 7452 7453 7454 7455
    VARPOW(UI1,2,R8,3.0,R8,8.0);
    VARPOW(UI1,2,DATE,3,R8,8.0);
    VARPOW(UI1,2,BSTR,num3_str,R8,8.0);
    VARPOW(UI1,2,BOOL,VARIANT_FALSE,R8,1.0);
    VARPOW(UI1,2,I1,3,R8,8.0);
    VARPOW(UI1,2,UI1,3,R8,8.0);
    VARPOW(UI1,2,UI2,3,R8,8.0);
    VARPOW(UI1,2,UI4,3,R8,8.0);
7456
    if (has_i8)
7457 7458 7459 7460
    {
        VARPOW(UI1,2,I8,3,R8,8.0);
        VARPOW(UI1,2,UI8,3,R8,8.0);
    }
7461 7462 7463 7464 7465 7466
    VARPOW(UI1,2,INT,3,R8,8.0);
    VARPOW(UI1,2,UINT,3,R8,8.0);
    VARPOW(UI2,2,EMPTY,0,R8,1.0);
    VARPOW(UI2,2,NULL,0,NULL,0);
    VARPOW(UI2,2,I2,3,R8,8.0);
    VARPOW(UI2,2,I4,3,R8,8.0);
7467
    VARPOW(UI2,2,R4,3.0f,R8,8.0);
7468 7469 7470 7471 7472 7473 7474 7475
    VARPOW(UI2,2,R8,3.0,R8,8.0);
    VARPOW(UI2,2,DATE,3,R8,8.0);
    VARPOW(UI2,2,BSTR,num3_str,R8,8.0);
    VARPOW(UI2,2,BOOL,VARIANT_FALSE,R8,1.0);
    VARPOW(UI2,2,I1,3,R8,8.0);
    VARPOW(UI2,2,UI1,3,R8,8.0);
    VARPOW(UI2,2,UI2,3,R8,8.0);
    VARPOW(UI2,2,UI4,3,R8,8.0);
7476
    if (has_i8)
7477 7478 7479 7480
    {
        VARPOW(UI2,2,I8,3,R8,8.0);
        VARPOW(UI2,2,UI8,3,R8,8.0);
    }
7481 7482 7483 7484 7485 7486
    VARPOW(UI2,2,INT,3,R8,8.0);
    VARPOW(UI2,2,UINT,3,R8,8.0);
    VARPOW(UI4,2,EMPTY,0,R8,1.0);
    VARPOW(UI4,2,NULL,0,NULL,0);
    VARPOW(UI4,2,I2,3,R8,8.0);
    VARPOW(UI4,2,I4,3,R8,8.0);
7487
    VARPOW(UI4,2,R4,3.0f,R8,8.0);
7488 7489 7490 7491 7492 7493 7494 7495
    VARPOW(UI4,2,R8,3.0,R8,8.0);
    VARPOW(UI4,2,DATE,3,R8,8.0);
    VARPOW(UI4,2,BSTR,num3_str,R8,8.0);
    VARPOW(UI4,2,BOOL,VARIANT_FALSE,R8,1.0);
    VARPOW(UI4,2,I1,3,R8,8.0);
    VARPOW(UI4,2,UI1,3,R8,8.0);
    VARPOW(UI4,2,UI2,3,R8,8.0);
    VARPOW(UI4,2,UI4,3,R8,8.0);
7496
    if (has_i8)
7497 7498 7499 7500
    {
        VARPOW(UI4,2,I8,3,R8,8.0);
        VARPOW(UI4,2,UI8,3,R8,8.0);
    }
7501 7502
    VARPOW(UI4,2,INT,3,R8,8.0);
    VARPOW(UI4,2,UINT,3,R8,8.0);
7503
    if (has_i8)
7504 7505 7506 7507 7508
    {
        VARPOW(I8,2,EMPTY,0,R8,1.0);
        VARPOW(I8,2,NULL,0,NULL,0);
        VARPOW(I8,2,I2,3,R8,8.0);
        VARPOW(I8,2,I4,3,R8,8.0);
7509
        VARPOW(I8,2,R4,3.0f,R8,8.0);
7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525
        VARPOW(I8,2,R8,3.0,R8,8.0);
        VARPOW(I8,2,DATE,3,R8,8.0);
        VARPOW(I8,2,BSTR,num3_str,R8,8.0);
        VARPOW(I8,2,BOOL,VARIANT_FALSE,R8,1.0);
        VARPOW(I8,2,I1,3,R8,8.0);
        VARPOW(I8,2,UI1,3,R8,8.0);
        VARPOW(I8,2,UI2,3,R8,8.0);
        VARPOW(I8,2,UI4,3,R8,8.0);
        VARPOW(I8,2,I8,3,R8,8.0);
        VARPOW(I8,2,UI8,3,R8,8.0);
        VARPOW(I8,2,INT,3,R8,8.0);
        VARPOW(I8,2,UINT,3,R8,8.0);
        VARPOW(UI8,2,EMPTY,0,R8,1.0);
        VARPOW(UI8,2,NULL,0,NULL,0);
        VARPOW(UI8,2,I2,3,R8,8.0);
        VARPOW(UI8,2,I4,3,R8,8.0);
7526
        VARPOW(UI8,2,R4,3.0f,R8,8.0);
7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538
        VARPOW(UI8,2,R8,3.0,R8,8.0);
        VARPOW(UI8,2,DATE,3,R8,8.0);
        VARPOW(UI8,2,BSTR,num3_str,R8,8.0);
        VARPOW(UI8,2,I1,3,R8,8.0);
        VARPOW(UI8,2,UI1,3,R8,8.0);
        VARPOW(UI8,2,UI2,3,R8,8.0);
        VARPOW(UI8,2,UI4,3,R8,8.0);
        VARPOW(UI8,2,I8,3,R8,8.0);
        VARPOW(UI8,2,UI8,3,R8,8.0);
        VARPOW(UI8,2,INT,3,R8,8.0);
        VARPOW(UI8,2,UINT,3,R8,8.0);
    }
7539 7540 7541 7542
    VARPOW(INT,2,EMPTY,0,R8,1.0);
    VARPOW(INT,2,NULL,0,NULL,0);
    VARPOW(INT,2,I2,3,R8,8.0);
    VARPOW(INT,2,I4,3,R8,8.0);
7543
    VARPOW(INT,2,R4,3.0f,R8,8.0);
7544 7545 7546 7547 7548 7549 7550 7551
    VARPOW(INT,2,R8,3.0,R8,8.0);
    VARPOW(INT,2,DATE,3,R8,8.0);
    VARPOW(INT,2,BSTR,num3_str,R8,8.0);
    VARPOW(INT,2,BOOL,VARIANT_FALSE,R8,1.0);
    VARPOW(INT,2,I1,3,R8,8.0);
    VARPOW(INT,2,UI1,3,R8,8.0);
    VARPOW(INT,2,UI2,3,R8,8.0);
    VARPOW(INT,2,UI4,3,R8,8.0);
7552
    if (has_i8)
7553 7554 7555 7556
    {
        VARPOW(INT,2,I8,3,R8,8.0);
        VARPOW(INT,2,UI8,3,R8,8.0);
    }
7557 7558 7559 7560 7561 7562
    VARPOW(INT,2,INT,3,R8,8.0);
    VARPOW(INT,2,UINT,3,R8,8.0);
    VARPOW(UINT,2,EMPTY,0,R8,1.0);
    VARPOW(UINT,2,NULL,0,NULL,0);
    VARPOW(UINT,2,I2,3,R8,8.0);
    VARPOW(UINT,2,I4,3,R8,8.0);
7563
    VARPOW(UINT,2,R4,3.0f,R8,8.0);
7564 7565 7566 7567 7568 7569 7570 7571
    VARPOW(UINT,2,R8,3.0,R8,8.0);
    VARPOW(UINT,2,DATE,3,R8,8.0);
    VARPOW(UINT,2,BSTR,num3_str,R8,8.0);
    VARPOW(UINT,2,BOOL,VARIANT_FALSE,R8,1.0);
    VARPOW(UINT,2,I1,3,R8,8.0);
    VARPOW(UINT,2,UI1,3,R8,8.0);
    VARPOW(UINT,2,UI2,3,R8,8.0);
    VARPOW(UINT,2,UI4,3,R8,8.0);
7572
    if (has_i8)
7573 7574 7575 7576
    {
        VARPOW(UINT,2,I8,3,R8,8.0);
        VARPOW(UINT,2,UI8,3,R8,8.0);
    }
7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595
    VARPOW(UINT,2,INT,3,R8,8.0);
    VARPOW(UINT,2,UINT,3,R8,8.0);

    /* Manually test some VT_CY, VT_DECIMAL variants */
    V_VT(&cy) = VT_CY;
    hres = VarCyFromI4(2, &V_CY(&cy));
    ok(hres == S_OK, "VarCyFromI4 failed!\n");
    V_VT(&dec) = VT_DECIMAL;
    hres = VarDecFromR8(2.0, &V_DECIMAL(&dec));
    ok(hres == S_OK, "VarDecFromR4 failed!\n");
    memset(&left, 0, sizeof(left));
    memset(&right, 0, sizeof(right));
    V_VT(&left) = VT_I4;
    V_I4(&left) = 100;
    V_VT(&right) = VT_I8;
    V_UI1(&right) = 2;

    hres = pVarPow(&cy, &cy, &result);
    ok(hres == S_OK && V_VT(&result) == VT_R8,
7596
        "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7597 7598 7599 7600 7601
        S_OK, hres, vtstr(V_VT(&result)));
    ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 4.0),
        "VARPOW: CY value %f, expected %f\n", V_R8(&result), 4.0);

    hres = pVarPow(&cy, &right, &result);
7602 7603
    if (hres == S_OK)
    {
7604
        ok(V_VT(&result) == VT_R8,
7605 7606
           "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
           S_OK, hres, vtstr(V_VT(&result)));
7607
        ok(EQ_DOUBLE(V_R8(&result), 4.0),
7608 7609 7610 7611 7612 7613 7614 7615
           "VARPOW: CY value %f, expected %f\n", V_R8(&result), 4.0);
    }
    else
    {
        ok(hres == DISP_E_BADVARTYPE && V_VT(&result) == VT_EMPTY,
           "VARPOW: expected coerced hres 0x%X type VT_EMPTY, got hres 0x%X type %s!\n",
           DISP_E_BADVARTYPE, hres, vtstr(V_VT(&result)));
    }
7616 7617 7618

    hres = pVarPow(&left, &cy, &result);
    ok(hres == S_OK && V_VT(&result) == VT_R8,
7619
        "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7620 7621 7622 7623 7624 7625
        S_OK, hres, vtstr(V_VT(&result)));
    ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 10000.0),
        "VARPOW: CY value %f, expected %f\n", V_R8(&result), 10000.0);

    hres = pVarPow(&left, &dec, &result);
    ok(hres == S_OK && V_VT(&result) == VT_R8,
7626
        "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7627 7628 7629 7630 7631 7632
        S_OK, hres, vtstr(V_VT(&result)));
    ok(hres == S_OK && EQ_DOUBLE(V_R8(&result),10000.0),
        "VARPOW: DECIMAL value %f, expected %f\n", V_R8(&result), 10000.0);

    hres = pVarPow(&dec, &dec, &result);
    ok(hres == S_OK && V_VT(&result) == VT_R8,
7633
        "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
7634 7635 7636 7637 7638
        S_OK, hres, vtstr(V_VT(&result)));
    ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 4.0),
        "VARPOW: DECIMAL value %f, expected %f\n", V_R8(&result), 4.0);

    hres = pVarPow(&dec, &right, &result);
7639 7640
    if (hres == S_OK)
    {
7641
        ok(V_VT(&result) == VT_R8,
7642 7643
           "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n",
           S_OK, hres, vtstr(V_VT(&result)));
7644
        ok(EQ_DOUBLE(V_R8(&result), 4.0),
7645 7646 7647 7648 7649 7650 7651 7652
           "VARPOW: DECIMAL value %f, expected %f\n", V_R8(&result), 4.0);
    }
    else
    {
        ok(hres == DISP_E_BADVARTYPE && V_VT(&result) == VT_EMPTY,
           "VARPOW: expected coerced hres 0x%X type VT_EMPTY, got hres 0x%X type %s!\n",
           DISP_E_BADVARTYPE, hres, vtstr(V_VT(&result)));
    }
7653 7654 7655 7656 7657

    SysFreeString(num2_str);
    SysFreeString(num3_str);
}

7658 7659
static HRESULT (WINAPI *pVarDiv)(LPVARIANT,LPVARIANT,LPVARIANT);

7660 7661 7662 7663
#define VARDIV(vt1,val1,vt2,val2,rvt,rval)               \
        V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
        V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
        V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
7664
        test_var_call2( __LINE__, pVarDiv, &left, &right, &exp )
7665

7666
/* Skip any type that is not defined or produces an error for every case */
7667 7668 7669 7670 7671 7672 7673 7674
#define SKIPTESTDIV(a)                            \
    if (a == VT_ERROR || a == VT_VARIANT ||       \
        a == VT_DISPATCH || a == VT_UNKNOWN ||    \
        a == VT_RECORD || a > VT_UINT ||          \
        a == VT_I1 || a == VT_UI8 ||              \
        a == VT_INT || a == VT_UINT ||            \
        a == VT_UI2 || a == VT_UI4 ||             \
        a == 15 /*not defined*/)                  \
7675
        continue
7676 7677 7678 7679 7680

static void test_VarDiv(void)
{
    static const WCHAR str1[] = { '1','\0' };
    static const WCHAR str2[] = { '2','\0' };
7681
    VARIANT left, right, exp, result, cy, dec;
7682 7683
    BSTR num1_str, num2_str;
    VARTYPE i;
7684
    HRESULT hres;
7685 7686
    double r;

7687 7688
    CHECKPTR(VarDiv);

7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700
    num1_str = SysAllocString(str1);
    num2_str = SysAllocString(str2);

    /* Test all possible flag/vt combinations & the resulting vt type */
    for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
    {
        VARTYPE leftvt, rightvt, resvt;

        for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
        {
            SKIPTESTDIV(leftvt);

7701
            /* Check if we need/have support for I8 */
7702
            if (leftvt == VT_I8 && !has_i8)
7703 7704
                continue;

7705 7706 7707 7708 7709
            for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
            {
                BOOL bFail = FALSE;
                SKIPTESTDIV(rightvt);

7710
                /* Check if we need/have support for I8 */
7711
                if (rightvt == VT_I8 && !has_i8)
7712 7713
                    continue;

7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747
                /* Native crashes with VT_BYREF */
                if (ExtraFlags[i] == VT_BYREF)
                    continue;

                memset(&left, 0, sizeof(left));
                memset(&right, 0, sizeof(right));
                V_VT(&left) = leftvt | ExtraFlags[i];
                V_VT(&right) = rightvt | ExtraFlags[i];
                V_VT(&result) = VT_EMPTY;
                resvt = VT_EMPTY;

                if (leftvt == VT_BSTR)
                    V_BSTR(&left) = num2_str;
                else if (leftvt == VT_DECIMAL)
                {
                    VarDecFromR8(2.0, &V_DECIMAL(&left));
                    V_VT(&left) = leftvt | ExtraFlags[i];
                }

                /* Division by 0 is undefined */
                switch(rightvt)
                {
                case VT_BSTR:
                    V_BSTR(&right) = num2_str;
                    break;
                case VT_DECIMAL:
                    VarDecFromR8(2.0, &V_DECIMAL(&right));
                    V_VT(&right) = rightvt | ExtraFlags[i];
                    break;
                case VT_BOOL:
                    V_BOOL(&right) = VARIANT_TRUE;
                    break;
                case VT_I2: V_I2(&right) = 2; break;
                case VT_I4: V_I4(&right) = 2; break;
7748
                case VT_R4: V_R4(&right) = 2.0f; break;
7749 7750 7751 7752 7753 7754 7755 7756 7757
                case VT_R8: V_R8(&right) = 2.0; break;
                case VT_CY: V_CY(&right).int64 = 2; break;
                case VT_DATE: V_DATE(&right) = 2; break;
                case VT_UI1: V_UI1(&right) = 2; break;
                case VT_I8: V_I8(&right) = 2; break;
                default: break;
                }

                /* Determine return type */
7758
                if (rightvt != VT_EMPTY)
7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786
                {
                    if (leftvt == VT_NULL || rightvt == VT_NULL)
                        resvt = VT_NULL;
                    else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
                        resvt = VT_DECIMAL;
                    else if (leftvt == VT_I8 || rightvt == VT_I8 ||
                        leftvt == VT_CY || rightvt == VT_CY ||
                        leftvt == VT_DATE || rightvt == VT_DATE ||
                        leftvt == VT_I4 || rightvt == VT_I4 ||
                        leftvt == VT_BSTR || rightvt == VT_BSTR ||
                        leftvt == VT_I2 || rightvt == VT_I2 ||
                        leftvt == VT_BOOL || rightvt == VT_BOOL ||
                        leftvt == VT_R8 || rightvt == VT_R8 ||
                        leftvt == VT_UI1 || rightvt == VT_UI1)
                    {
                        if ((leftvt == VT_UI1 && rightvt == VT_R4) ||
                            (leftvt == VT_R4 && rightvt == VT_UI1))
                            resvt = VT_R4;
                        else if ((leftvt == VT_R4 && (rightvt == VT_BOOL ||
                            rightvt == VT_I2)) || (rightvt == VT_R4 &&
                            (leftvt == VT_BOOL || leftvt == VT_I2)))
                            resvt = VT_R4;
                        else
                            resvt = VT_R8;
                    }
                    else if (leftvt == VT_R4 || rightvt == VT_R4)
                        resvt = VT_R4;
                }
7787
                else if (leftvt == VT_NULL)
7788 7789 7790 7791
                    resvt = VT_NULL;
                else
                    bFail = TRUE;

7792
                /* Native VarDiv always returns an error when using extra flags */
7793 7794 7795 7796 7797 7798 7799 7800 7801
                if (ExtraFlags[i] != 0)
                    bFail = TRUE;

                hres = pVarDiv(&left, &right, &result);

                /* Check expected HRESULT and if result variant type is correct */
                if (bFail)
                    ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH ||
                        hres == DISP_E_OVERFLOW || hres == DISP_E_DIVBYZERO,
7802
                        "VarDiv: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
7803 7804 7805 7806
                        vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
                        vtstr(V_VT(&result)), hres);
                else
                    ok (hres == S_OK && resvt == V_VT(&result),
7807
                        "VarDiv: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
7808 7809 7810 7811 7812 7813 7814 7815 7816 7817
                        vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
                        S_OK, vtstr(V_VT(&result)), hres);
            }
        }
    }

    /* Test return values for all the good cases */
    VARDIV(EMPTY,0,NULL,0,NULL,0);
    VARDIV(EMPTY,0,I2,2,R8,0.0);
    VARDIV(EMPTY,0,I4,2,R8,0.0);
7818
    VARDIV(EMPTY,0,R4,2.0f,R4,0.0f);
7819 7820 7821 7822 7823
    VARDIV(EMPTY,0,R8,2.0,R8,0.0);
    VARDIV(EMPTY,0,DATE,2.0,R8,0.0);
    VARDIV(EMPTY,0,BSTR,num2_str,R8,0.0);
    VARDIV(EMPTY,0,BOOL,VARIANT_TRUE,R8,0.0);
    VARDIV(EMPTY,0,UI1,2,R8,0.0);
7824
    if (has_i8)
7825 7826 7827
    {
        VARDIV(EMPTY,0,I8,2,R8,0.0);
    }
7828 7829 7830 7831
    VARDIV(NULL,0,EMPTY,0,NULL,0);
    VARDIV(NULL,0,NULL,0,NULL,0);
    VARDIV(NULL,0,I2,2,NULL,0);
    VARDIV(NULL,0,I4,2,NULL,0);
7832
    VARDIV(NULL,0,R4,2.0f,NULL,0);
7833 7834 7835 7836 7837
    VARDIV(NULL,0,R8,2.0,NULL,0);
    VARDIV(NULL,0,DATE,2,NULL,0);
    VARDIV(NULL,0,BSTR,num2_str,NULL,0);
    VARDIV(NULL,0,BOOL,VARIANT_TRUE,NULL,0);
    VARDIV(NULL,0,UI1,2,NULL,0);
7838
    if (has_i8)
7839 7840 7841
    {
        VARDIV(NULL,0,I8,2,NULL,0);
    }
7842 7843 7844
    VARDIV(I2,2,NULL,0,NULL,0);
    VARDIV(I2,1,I2,2,R8,0.5);
    VARDIV(I2,1,I4,2,R8,0.5);
7845
    VARDIV(I2,1,R4,2,R4,0.5f);
7846 7847 7848 7849
    VARDIV(I2,1,R8,2.0,R8,0.5);
    VARDIV(I2,1,DATE,2,R8,0.5);
    VARDIV(I2,1,BOOL,VARIANT_TRUE,R8,-1.0);
    VARDIV(I2,1,UI1,2,R8,0.5);
7850
    if (has_i8)
7851 7852 7853
    {
        VARDIV(I2,1,I8,2,R8,0.5);
    }
7854 7855 7856
    VARDIV(I4,1,NULL,0,NULL,0);
    VARDIV(I4,1,I2,2,R8,0.5);
    VARDIV(I4,1,I4,2,R8,0.5);
7857
    VARDIV(I4,1,R4,2.0f,R8,0.5);
7858 7859 7860 7861 7862
    VARDIV(I4,1,R8,2.0,R8,0.5);
    VARDIV(I4,1,DATE,2,R8,0.5);
    VARDIV(I4,1,BSTR,num2_str,R8,0.5);
    VARDIV(I4,1,BOOL,VARIANT_TRUE,R8,-1.0);
    VARDIV(I4,1,UI1,2,R8,0.5);
7863
    if (has_i8)
7864 7865 7866
    {
        VARDIV(I4,1,I8,2,R8,0.5);
    }
7867 7868 7869 7870 7871 7872 7873 7874 7875
    VARDIV(R4,1.0f,NULL,0,NULL,0);
    VARDIV(R4,1.0f,I2,2,R4,0.5f);
    VARDIV(R4,1.0f,I4,2,R8,0.5);
    VARDIV(R4,1.0f,R4,2.0f,R4,0.5f);
    VARDIV(R4,1.0f,R8,2.0,R8,0.5);
    VARDIV(R4,1.0f,DATE,2,R8,0.5);
    VARDIV(R4,1.0f,BSTR,num2_str,R8,0.5);
    VARDIV(R4,1.0f,BOOL,VARIANT_TRUE,R4,-1);
    VARDIV(R4,1.0f,UI1,2,R4,0.5f);
7876
    if (has_i8)
7877 7878 7879
    {
        VARDIV(R4,1.0f,I8,2,R8,0.5);
    }
7880 7881 7882
    VARDIV(R8,1.0,NULL,0,NULL,0);
    VARDIV(R8,1.0,I2,2,R8,0.5);
    VARDIV(R8,1.0,I4,2,R8,0.5);
7883
    VARDIV(R8,1.0,R4,2.0f,R8,0.5);
7884 7885 7886 7887 7888
    VARDIV(R8,1.0,R8,2.0,R8,0.5);
    VARDIV(R8,1.0,DATE,2,R8,0.5);
    VARDIV(R8,1.0,BSTR,num2_str,R8,0.5);
    VARDIV(R8,1.0,BOOL,VARIANT_TRUE,R8,-1.0);
    VARDIV(R8,1.0,UI1,2,R8,0.5);
7889
    if (has_i8)
7890 7891 7892
    {
        VARDIV(R8,1.0,I8,2,R8,0.5);
    }
7893 7894 7895
    VARDIV(DATE,1,NULL,0,NULL,0);
    VARDIV(DATE,1,I2,2,R8,0.5);
    VARDIV(DATE,1,I4,2,R8,0.5);
7896
    VARDIV(DATE,1,R4,2.0f,R8,0.5);
7897 7898 7899 7900 7901
    VARDIV(DATE,1,R8,2.0,R8,0.5);
    VARDIV(DATE,1,DATE,2,R8,0.5);
    VARDIV(DATE,1,BSTR,num2_str,R8,0.5);
    VARDIV(DATE,1,BOOL,VARIANT_TRUE,R8,-1.0);
    VARDIV(DATE,1,UI1,2,R8,0.5);
7902
    if (has_i8)
7903 7904 7905
    {
        VARDIV(DATE,1,I8,2,R8,0.5);
    }
7906 7907 7908
    VARDIV(BSTR,num1_str,NULL,0,NULL,0);
    VARDIV(BSTR,num1_str,I2,2,R8,0.5);
    VARDIV(BSTR,num1_str,I4,2,R8,0.5);
7909
    VARDIV(BSTR,num1_str,R4,2.0f,R8,0.5);
7910 7911 7912 7913 7914
    VARDIV(BSTR,num1_str,R8,2.0,R8,0.5);
    VARDIV(BSTR,num1_str,DATE,2,R8,0.5);
    VARDIV(BSTR,num1_str,BSTR,num2_str,R8,0.5);
    VARDIV(BSTR,num1_str,BOOL,VARIANT_TRUE,R8,-1);
    VARDIV(BSTR,num1_str,UI1,2,R8,0.5);
7915
    if (has_i8)
7916 7917 7918
    {
        VARDIV(BSTR,num1_str,I8,2,R8,0.5);
    }
7919 7920 7921 7922 7923
    VARDIV(BOOL,VARIANT_TRUE,NULL,0,NULL,0);
    VARDIV(BOOL,VARIANT_TRUE,I2,1,R8,-1.0);
    VARDIV(BOOL,VARIANT_FALSE,I2,1,R8,0.0);
    VARDIV(BOOL,VARIANT_TRUE,I4,1,R8,-1.0);
    VARDIV(BOOL,VARIANT_FALSE,I4,1,R8,0.0);
7924 7925
    VARDIV(BOOL,VARIANT_TRUE,R4,1,R4,-1.0f);
    VARDIV(BOOL,VARIANT_FALSE,R4,1,R4,0.0f);
7926 7927 7928 7929 7930 7931 7932
    VARDIV(BOOL,VARIANT_TRUE,R8,1.0,R8,-1.0);
    VARDIV(BOOL,VARIANT_FALSE,R8,1.0,R8,0.0);
    VARDIV(BOOL,VARIANT_FALSE,DATE,2,R8,0.0);
    VARDIV(BOOL,VARIANT_FALSE,BSTR,num2_str,R8,0.0);
    VARDIV(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,R8,1.0);
    VARDIV(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,R8,0.0);
    VARDIV(BOOL,VARIANT_TRUE,UI1,1,R8,-1.0);
7933
    if (has_i8)
7934 7935 7936
    {
        VARDIV(BOOL,VARIANT_TRUE,I8,1,R8,-1.0);
    }
7937 7938 7939
    VARDIV(UI1,1,NULL,0,NULL,0);
    VARDIV(UI1,1,I2,2,R8,0.5);
    VARDIV(UI1,1,I4,2,R8,0.5);
7940
    VARDIV(UI1,1,R4,2.0f,R4,0.5f);
7941 7942 7943 7944 7945
    VARDIV(UI1,1,R8,2.0,R8,0.5);
    VARDIV(UI1,1,DATE,2,R8,0.5);
    VARDIV(UI1,1,BSTR,num2_str,R8,0.5);
    VARDIV(UI1,1,BOOL,VARIANT_TRUE,R8,-1);
    VARDIV(UI1,1,UI1,2,R8,0.5);
7946
    if (has_i8)
7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959
    {
        VARDIV(UI1,1,I8,2,R8,0.5);
        VARDIV(I8,1,NULL,0,NULL,0);
        VARDIV(I8,1,I2,2,R8,0.5);
        VARDIV(I8,1,I4,2,R8,0.5);
        VARDIV(I8,1,R4,2.0f,R8,0.5);
        VARDIV(I8,1,R8,2.0,R8,0.5);
        VARDIV(I8,1,DATE,2,R8,0.5);
        VARDIV(I8,1,BSTR,num2_str,R8,0.5);
        VARDIV(I8,1,BOOL,VARIANT_TRUE,R8,-1);
        VARDIV(I8,1,UI1,2,R8,0.5);
        VARDIV(I8,1,I8,2,R8,0.5);
    }
7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015

    /* Manually test some VT_CY, VT_DECIMAL variants */
    V_VT(&cy) = VT_CY;
    hres = VarCyFromI4(10000, &V_CY(&cy));
    ok(hres == S_OK, "VarCyFromI4 failed!\n");
    V_VT(&dec) = VT_DECIMAL;
    hres = VarDecFromR8(2.0, &V_DECIMAL(&dec));
    ok(hres == S_OK, "VarDecFromR4 failed!\n");
    memset(&left, 0, sizeof(left));
    memset(&right, 0, sizeof(right));
    V_VT(&left) = VT_I4;
    V_I4(&left) = 100;
    V_VT(&right) = VT_UI1;
    V_UI1(&right) = 2;

    hres = pVarDiv(&cy, &cy, &result);
    ok(hres == S_OK && V_VT(&result) == VT_R8,
        "VARDIV: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
    ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 1.0),
        "VARDIV: CY value %f, expected %f\n", V_R8(&result), (double)1.0);

    hres = pVarDiv(&cy, &right, &result);
    ok(hres == S_OK && V_VT(&result) == VT_R8,
        "VARDIV: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
    ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 5000.0),
        "VARDIV: CY value %f, expected %f\n", V_R8(&result), (double)5000.0);

    hres = pVarDiv(&left, &cy, &result);
    ok(hres == S_OK && V_VT(&result) == VT_R8,
        "VARDIV: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
    ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 0.01),
        "VARDIV: CY value %f, expected %f\n", V_R8(&result), (double)0.01);

    hres = pVarDiv(&left, &dec, &result);
    ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
        "VARDIV: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
    hres = VarR8FromDec(&V_DECIMAL(&result), &r);
    ok(hres == S_OK && EQ_DOUBLE(r, 50.0),
        "VARDIV: DECIMAL value %f, expected %f\n", r, (double)50.0);

    hres = pVarDiv(&dec, &dec, &result);
    ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
        "VARDIV: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
    hres = VarR8FromDec(&V_DECIMAL(&result), &r);
    ok(hres == S_OK && EQ_DOUBLE(r, 1.0),
        "VARDIV: DECIMAL value %f, expected %f\n", r, (double)1.0);

    hres = pVarDiv(&dec, &right, &result);
    ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
        "VARDIV: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
    hres = VarR8FromDec(&V_DECIMAL(&result), &r);
    ok(hres == S_OK && EQ_DOUBLE(r, 1.0),
        "VARDIV: DECIMAL value %f, expected %f\n", r, (double)1.0);

    /* Check for division by zero and overflow */
    V_VT(&left) = VT_R8;
8016
    V_I4(&left) = 1;
8017
    V_VT(&right) = VT_R8;
8018
    V_I4(&right) = 0;
8019 8020
    hres = pVarDiv(&left, &right, &result);
    ok(hres == DISP_E_DIVBYZERO && V_VT(&result) == VT_EMPTY,
8021
        "VARDIV: Division by (1.0/0.0) should result in DISP_E_DIVBYZERO but got 0x%X\n", hres);
8022 8023

    V_VT(&left) = VT_R8;
8024
    V_I4(&left) = 0;
8025
    V_VT(&right) = VT_R8;
8026
    V_I4(&right) = 0;
8027 8028
    hres = pVarDiv(&left, &right, &result);
    ok(hres == DISP_E_OVERFLOW && V_VT(&result) == VT_EMPTY,
8029
        "VARDIV: Division by (0.0/0.0) should result in DISP_E_OVERFLOW but got 0x%X\n", hres);
8030 8031 8032 8033 8034

    SysFreeString(num1_str);
    SysFreeString(num2_str);
}

8035 8036
static HRESULT (WINAPI *pVarIdiv)(LPVARIANT,LPVARIANT,LPVARIANT);

8037 8038 8039 8040
#define VARIDIV(vt1,val1,vt2,val2,rvt,rval)              \
        V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
        V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
        V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
8041
        test_var_call2( __LINE__, pVarIdiv, &left, &right, &exp )
8042

8043
/* Skip any type that is not defined or produces an error for every case */
8044 8045 8046 8047 8048
#define SKIPTESTIDIV(a)                           \
    if (a == VT_ERROR || a == VT_VARIANT ||       \
        a == VT_DISPATCH || a == VT_UNKNOWN ||    \
        a == VT_RECORD || a > VT_UINT ||          \
        a == 15 /*not defined*/)                  \
8049
        continue
8050 8051 8052 8053 8054

static void test_VarIdiv(void)
{
    static const WCHAR str1[] = { '1','\0' };
    static const WCHAR str2[] = { '2','\0' };
8055
    VARIANT left, right, exp, result, cy, dec;
8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073
    BSTR num1_str, num2_str;
    VARTYPE i;
    HRESULT hres;

    CHECKPTR(VarIdiv);

    num1_str = SysAllocString(str1);
    num2_str = SysAllocString(str2);

    /* Test all possible flag/vt combinations & the resulting vt type */
    for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
    {
        VARTYPE leftvt, rightvt, resvt;

        for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
        {
            SKIPTESTIDIV(leftvt);

8074
            /* Check if we need/have support for I8 and/or UI8 */
8075
            if ((leftvt == VT_I8 || leftvt == VT_UI8) && !has_i8)
8076 8077
                continue;

8078 8079 8080 8081 8082 8083 8084 8085 8086
            for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
            {
                BOOL bFail = FALSE;
                SKIPTESTIDIV(rightvt);

                /* Native crashes with extra flag VT_BYREF */
                if (ExtraFlags[i] == VT_BYREF)
                    continue;

8087
                /* Check if we need/have support for I8 and/or UI8 */
8088
                if ((rightvt == VT_I8 || rightvt == VT_UI8) && !has_i8)
8089 8090
                    continue;

8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124
                memset(&left, 0, sizeof(left));
                memset(&right, 0, sizeof(right));
                V_VT(&left) = leftvt | ExtraFlags[i];
                V_VT(&right) = rightvt | ExtraFlags[i];
                V_VT(&result) = VT_EMPTY;
                resvt = VT_EMPTY;

                if (leftvt == VT_BSTR)
                    V_BSTR(&left) = num2_str;
                else if (leftvt == VT_DECIMAL)
                {
                    VarDecFromR8(2.0, &V_DECIMAL(&left));
                    V_VT(&left) = leftvt | ExtraFlags[i];
                }

                /* Division by 0 is undefined */
                switch(rightvt)
                {
                case VT_BSTR:
                    V_BSTR(&right) = num2_str;
                    break;
                case VT_DECIMAL:
                    VarDecFromR8(2.0, &V_DECIMAL(&right));
                    V_VT(&right) = rightvt | ExtraFlags[i];
                    break;
                case VT_BOOL:
                    V_BOOL(&right) = VARIANT_TRUE;
                    break;
                case VT_CY:
                    VarCyFromI4(10000, &V_CY(&right));
                    V_VT(&right) = rightvt | ExtraFlags[i];
                    break;
                case VT_I2: V_I2(&right) = 2; break;
                case VT_I4: V_I4(&right) = 2; break;
8125
                case VT_R4: V_R4(&right) = 2.0f; break;
8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138
                case VT_R8: V_R8(&right) = 2.0; break;
                case VT_DATE: V_DATE(&right) = 2; break;
                case VT_I1: V_I1(&right) = 2; break;
                case VT_UI1: V_UI1(&right) = 2; break;
                case VT_UI2: V_UI2(&right) = 2; break;
                case VT_UI4: V_UI4(&right) = 2; break;
                case VT_I8: V_I8(&right) = 2; break;
                case VT_UI8: V_UI8(&right) = 2; break;
                case VT_INT: V_INT(&right) = 2; break;
                case VT_UINT: V_UINT(&right) = 2; break;
                default: break;
                }

8139
                /* Native VarIdiv always returns an error when using extra
8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181
                 * flags or if the variant combination is I8 and INT.
                 */
                if ((leftvt == VT_I8 && rightvt == VT_INT) ||
                    (leftvt == VT_INT && rightvt == VT_I8) ||
                    (rightvt == VT_EMPTY && leftvt != VT_NULL) ||
                    ExtraFlags[i] != 0)
                    bFail = TRUE;

                /* Determine variant type */
                else if (leftvt == VT_NULL || rightvt == VT_NULL)
                    resvt = VT_NULL;
                else if (leftvt == VT_I8 || rightvt == VT_I8)
                    resvt = VT_I8;
                else if (leftvt == VT_I4 || rightvt == VT_I4 ||
                    leftvt == VT_INT || rightvt == VT_INT ||
                    leftvt == VT_UINT || rightvt == VT_UINT ||
                    leftvt == VT_UI8 || rightvt == VT_UI8 ||
                    leftvt == VT_UI4 || rightvt == VT_UI4 ||
                    leftvt == VT_UI2 || rightvt == VT_UI2 ||
                    leftvt == VT_I1 || rightvt == VT_I1 ||
                    leftvt == VT_BSTR || rightvt == VT_BSTR ||
                    leftvt == VT_DATE || rightvt == VT_DATE ||
                    leftvt == VT_CY || rightvt == VT_CY ||
                    leftvt == VT_DECIMAL || rightvt == VT_DECIMAL ||
                    leftvt == VT_R8 || rightvt == VT_R8 ||
                    leftvt == VT_R4 || rightvt == VT_R4)
                    resvt = VT_I4;
                else if (leftvt == VT_I2 || rightvt == VT_I2 ||
                    leftvt == VT_BOOL || rightvt == VT_BOOL ||
                    leftvt == VT_EMPTY)
                    resvt = VT_I2;
                else if (leftvt == VT_UI1 || rightvt == VT_UI1)
                    resvt = VT_UI1;
                else
                    bFail = TRUE;

                hres = pVarIdiv(&left, &right, &result);

                /* Check expected HRESULT and if result variant type is correct */
                if (bFail)
                    ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH ||
                        hres == DISP_E_DIVBYZERO,
8182
                        "VarIdiv: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
8183 8184 8185 8186
                        vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
                        vtstr(V_VT(&result)), hres);
                else
                    ok (hres == S_OK && resvt == V_VT(&result),
8187
                        "VarIdiv: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
8188 8189 8190 8191 8192 8193 8194 8195 8196 8197
                        vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
                        S_OK, vtstr(V_VT(&result)), hres);
            }
        }
    }

    /* Test return values for all the good cases */
    VARIDIV(EMPTY,0,NULL,0,NULL,0);
    VARIDIV(EMPTY,0,I2,1,I2,0);
    VARIDIV(EMPTY,0,I4,1,I4,0);
8198
    VARIDIV(EMPTY,0,R4,1.0f,I4,0);
8199 8200 8201 8202 8203 8204 8205 8206
    VARIDIV(EMPTY,0,R8,1.0,I4,0);
    VARIDIV(EMPTY,0,DATE,1.0,I4,0);
    VARIDIV(EMPTY,0,BSTR,num1_str,I4,0);
    VARIDIV(EMPTY,0,BOOL,VARIANT_TRUE,I2,0);
    VARIDIV(EMPTY,0,I1,1,I4,0);
    VARIDIV(EMPTY,0,UI1,1,I2,0);
    VARIDIV(EMPTY,0,UI2,1,I4,0);
    VARIDIV(EMPTY,0,UI4,1,I4,0);
8207
    if (has_i8)
8208 8209 8210 8211
    {
        VARIDIV(EMPTY,0,I8,1,I8,0);
        VARIDIV(EMPTY,0,UI8,1,I4,0);
    }
8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226
    VARIDIV(EMPTY,0,INT,1,I4,0);
    VARIDIV(EMPTY,0,UINT,1,I4,0);
    VARIDIV(NULL,0,EMPTY,0,NULL,0);
    VARIDIV(NULL,0,NULL,0,NULL,0);
    VARIDIV(NULL,0,I2,1,NULL,0);
    VARIDIV(NULL,0,I4,1,NULL,0);
    VARIDIV(NULL,0,R4,1,NULL,0);
    VARIDIV(NULL,0,R8,1,NULL,0);
    VARIDIV(NULL,0,DATE,1,NULL,0);
    VARIDIV(NULL,0,BSTR,num1_str,NULL,0);
    VARIDIV(NULL,0,BOOL,VARIANT_TRUE,NULL,0);
    VARIDIV(NULL,0,I1,1,NULL,0);
    VARIDIV(NULL,0,UI1,1,NULL,0);
    VARIDIV(NULL,0,UI2,1,NULL,0);
    VARIDIV(NULL,0,UI4,1,NULL,0);
8227
    if (has_i8)
8228 8229 8230 8231
    {
        VARIDIV(NULL,0,I8,1,NULL,0);
        VARIDIV(NULL,0,UI8,1,NULL,0);
    }
8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245
    VARIDIV(NULL,0,INT,1,NULL,0);
    VARIDIV(NULL,0,UINT,1,NULL,0);
    VARIDIV(I2,2,NULL,0,NULL,0);
    VARIDIV(I2,2,I2,1,I2,2);
    VARIDIV(I2,2,I4,1,I4,2);
    VARIDIV(I2,2,R4,1,I4,2);
    VARIDIV(I2,2,R8,1,I4,2);
    VARIDIV(I2,2,DATE,1,I4,2);
    VARIDIV(I2,2,BSTR,num1_str,I4,2);
    VARIDIV(I2,2,BOOL,VARIANT_TRUE,I2,-2);
    VARIDIV(I2,2,I1,1,I4,2);
    VARIDIV(I2,2,UI1,1,I2,2);
    VARIDIV(I2,2,UI2,1,I4,2);
    VARIDIV(I2,2,UI4,1,I4,2);
8246
    if (has_i8)
8247 8248 8249 8250
    {
        VARIDIV(I2,2,I8,1,I8,2);
        VARIDIV(I2,2,UI8,1,I4,2);
    }
8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264
    VARIDIV(I2,2,INT,1,I4,2);
    VARIDIV(I2,2,UINT,1,I4,2);
    VARIDIV(I4,2,NULL,0,NULL,0);
    VARIDIV(I4,2,I2,1,I4,2);
    VARIDIV(I4,2,I4,1,I4,2);
    VARIDIV(I4,2,R4,1,I4,2);
    VARIDIV(I4,2,R8,1,I4,2);
    VARIDIV(I4,2,DATE,1,I4,2);
    VARIDIV(I4,2,BSTR,num1_str,I4,2);
    VARIDIV(I4,2,BOOL,VARIANT_TRUE,I4,-2);
    VARIDIV(I4,2,I1,1,I4,2);
    VARIDIV(I4,2,UI1,1,I4,2);
    VARIDIV(I4,2,UI2,1,I4,2);
    VARIDIV(I4,2,UI4,1,I4,2);
8265
    if (has_i8)
8266 8267 8268 8269
    {
        VARIDIV(I4,2,I8,1,I8,2);
        VARIDIV(I4,2,UI8,1,I4,2);
    }
8270 8271
    VARIDIV(I4,2,INT,1,I4,2);
    VARIDIV(I4,2,UINT,1,I4,2);
8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283
    VARIDIV(R4,2.0f,NULL,0,NULL,0);
    VARIDIV(R4,2.0f,I2,1,I4,2);
    VARIDIV(R4,2.0f,I4,1,I4,2);
    VARIDIV(R4,2.0f,R4,1.0f,I4,2);
    VARIDIV(R4,2.0f,R8,1.0,I4,2);
    VARIDIV(R4,2.0f,DATE,1,I4,2);
    VARIDIV(R4,2.0f,BSTR,num1_str,I4,2);
    VARIDIV(R4,2.0f,BOOL,VARIANT_TRUE,I4,-2);
    VARIDIV(R4,2.0f,I1,1,I4,2);
    VARIDIV(R4,2.0f,UI1,1,I4,2);
    VARIDIV(R4,2.0f,UI2,1,I4,2);
    VARIDIV(R4,2.0f,UI4,1,I4,2);
8284
    if (has_i8)
8285 8286 8287 8288
    {
        VARIDIV(R4,2.0f,I8,1,I8,2);
        VARIDIV(R4,2.0f,UI8,1,I4,2);
    }
8289 8290
    VARIDIV(R4,2.0f,INT,1,I4,2);
    VARIDIV(R4,2.0f,UINT,1,I4,2);
8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302
    VARIDIV(R8,2.0,NULL,0,NULL,0);
    VARIDIV(R8,2.0,I2,1,I4,2);
    VARIDIV(R8,2.0,I4,1,I4,2);
    VARIDIV(R8,2.0,R4,1,I4,2);
    VARIDIV(R8,2.0,R8,1,I4,2);
    VARIDIV(R8,2.0,DATE,1,I4,2);
    VARIDIV(R8,2.0,BSTR,num1_str,I4,2);
    VARIDIV(R8,2.0,BOOL,VARIANT_TRUE,I4,-2);
    VARIDIV(R8,2.0,I1,1,I4,2);
    VARIDIV(R8,2.0,UI1,1,I4,2);
    VARIDIV(R8,2.0,UI2,1,I4,2);
    VARIDIV(R8,2.0,UI4,1,I4,2);
8303
    if (has_i8)
8304 8305 8306 8307
    {
        VARIDIV(R8,2.0,I8,1,I8,2);
        VARIDIV(R8,2.0,UI8,1,I4,2);
    }
8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321
    VARIDIV(R8,2.0,INT,1,I4,2);
    VARIDIV(R8,2.0,UINT,1,I4,2);
    VARIDIV(DATE,2,NULL,0,NULL,0);
    VARIDIV(DATE,2,I2,1,I4,2);
    VARIDIV(DATE,2,I4,1,I4,2);
    VARIDIV(DATE,2,R4,1,I4,2);
    VARIDIV(DATE,2,R8,1,I4,2);
    VARIDIV(DATE,2,DATE,1,I4,2);
    VARIDIV(DATE,2,BSTR,num1_str,I4,2);
    VARIDIV(DATE,2,BOOL,VARIANT_TRUE,I4,-2);
    VARIDIV(DATE,2,I1,1,I4,2);
    VARIDIV(DATE,2,UI1,1,I4,2);
    VARIDIV(DATE,2,UI2,1,I4,2);
    VARIDIV(DATE,2,UI4,1,I4,2);
8322
    if (has_i8)
8323 8324 8325 8326
    {
        VARIDIV(DATE,2,I8,1,I8,2);
        VARIDIV(DATE,2,UI8,1,I4,2);
    }
8327 8328 8329 8330 8331
    VARIDIV(DATE,2,INT,1,I4,2);
    VARIDIV(DATE,2,UINT,1,I4,2);
    VARIDIV(BSTR,num2_str,NULL,0,NULL,0);
    VARIDIV(BSTR,num2_str,I2,1,I4,2);
    VARIDIV(BSTR,num2_str,I4,1,I4,2);
8332
    VARIDIV(BSTR,num2_str,R4,1.0f,I4,2);
8333 8334 8335 8336 8337 8338 8339 8340
    VARIDIV(BSTR,num2_str,R8,1.0,I4,2);
    VARIDIV(BSTR,num2_str,DATE,1,I4,2);
    VARIDIV(BSTR,num2_str,BSTR,num1_str,I4,2);
    VARIDIV(BSTR,num2_str,BOOL,VARIANT_TRUE,I4,-2);
    VARIDIV(BSTR,num2_str,I1,1,I4,2);
    VARIDIV(BSTR,num2_str,UI1,1,I4,2);
    VARIDIV(BSTR,num2_str,UI2,1,I4,2);
    VARIDIV(BSTR,num2_str,UI4,1,I4,2);
8341
    if (has_i8)
8342 8343 8344 8345
    {
        VARIDIV(BSTR,num2_str,I8,1,I8,2);
        VARIDIV(BSTR,num2_str,UI8,1,I4,2);
    }
8346 8347 8348 8349 8350
    VARIDIV(BSTR,num2_str,INT,1,I4,2);
    VARIDIV(BSTR,num2_str,UINT,1,I4,2);
    VARIDIV(BOOL,VARIANT_TRUE,NULL,0,NULL,0);
    VARIDIV(BOOL,VARIANT_TRUE,I2,1,I2,-1);
    VARIDIV(BOOL,VARIANT_TRUE,I4,1,I4,-1);
8351
    VARIDIV(BOOL,VARIANT_TRUE,R4,1.0f,I4,-1);
8352 8353 8354 8355 8356 8357 8358 8359
    VARIDIV(BOOL,VARIANT_TRUE,R8,1.0,I4,-1);
    VARIDIV(BOOL,VARIANT_TRUE,DATE,1,I4,-1);
    VARIDIV(BOOL,VARIANT_TRUE,BSTR,num1_str,I4,-1);
    VARIDIV(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,I2,1);
    VARIDIV(BOOL,VARIANT_TRUE,I1,1,I4,-1);
    VARIDIV(BOOL,VARIANT_TRUE,UI1,1,I2,-1);
    VARIDIV(BOOL,VARIANT_TRUE,UI2,1,I4,-1);
    VARIDIV(BOOL,VARIANT_TRUE,UI4,1,I4,-1);
8360
    if (has_i8)
8361 8362 8363 8364
    {
        VARIDIV(BOOL,VARIANT_TRUE,I8,1,I8,-1);
        VARIDIV(BOOL,VARIANT_TRUE,UI8,1,I4,-1);
    }
8365 8366 8367 8368 8369
    VARIDIV(BOOL,VARIANT_TRUE,INT,1,I4,-1);
    VARIDIV(BOOL,VARIANT_TRUE,UINT,1,I4,-1);
    VARIDIV(I1,2,NULL,0,NULL,0);
    VARIDIV(I1,2,I2,1,I4,2);
    VARIDIV(I1,2,I4,1,I4,2);
8370
    VARIDIV(I1,2,R4,1.0f,I4,2);
8371 8372 8373 8374 8375 8376 8377 8378
    VARIDIV(I1,2,R8,1.0,I4,2);
    VARIDIV(I1,2,DATE,1,I4,2);
    VARIDIV(I1,2,BSTR,num1_str,I4,2);
    VARIDIV(I1,2,BOOL,VARIANT_TRUE,I4,-2);
    VARIDIV(I1,2,I1,1,I4,2);
    VARIDIV(I1,2,UI1,1,I4,2);
    VARIDIV(I1,2,UI2,1,I4,2);
    VARIDIV(I1,2,UI4,1,I4,2);
8379
    if (has_i8)
8380 8381 8382 8383
    {
        VARIDIV(I1,2,I8,1,I8,2);
        VARIDIV(I1,2,UI8,1,I4,2);
    }
8384 8385 8386 8387 8388
    VARIDIV(I1,2,INT,1,I4,2);
    VARIDIV(I1,2,UINT,1,I4,2);
    VARIDIV(UI1,2,NULL,0,NULL,0);
    VARIDIV(UI1,2,I2,1,I2,2);
    VARIDIV(UI1,2,I4,1,I4,2);
8389
    VARIDIV(UI1,2,R4,1.0f,I4,2);
8390 8391 8392 8393 8394 8395 8396 8397
    VARIDIV(UI1,2,R8,1.0,I4,2);
    VARIDIV(UI1,2,DATE,1,I4,2);
    VARIDIV(UI1,2,BSTR,num1_str,I4,2);
    VARIDIV(UI1,2,BOOL,VARIANT_TRUE,I2,-2);
    VARIDIV(UI1,2,I1,1,I4,2);
    VARIDIV(UI1,2,UI1,1,UI1,2);
    VARIDIV(UI1,2,UI2,1,I4,2);
    VARIDIV(UI1,2,UI4,1,I4,2);
8398
    if (has_i8)
8399 8400 8401 8402
    {
        VARIDIV(UI1,2,I8,1,I8,2);
        VARIDIV(UI1,2,UI8,1,I4,2);
    }
8403 8404 8405 8406 8407
    VARIDIV(UI1,2,INT,1,I4,2);
    VARIDIV(UI1,2,UINT,1,I4,2);
    VARIDIV(UI2,2,NULL,0,NULL,0);
    VARIDIV(UI2,2,I2,1,I4,2);
    VARIDIV(UI2,2,I4,1,I4,2);
8408
    VARIDIV(UI2,2,R4,1.0f,I4,2);
8409 8410 8411 8412 8413 8414 8415 8416
    VARIDIV(UI2,2,R8,1.0,I4,2);
    VARIDIV(UI2,2,DATE,1,I4,2);
    VARIDIV(UI2,2,BSTR,num1_str,I4,2);
    VARIDIV(UI2,2,BOOL,VARIANT_TRUE,I4,-2);
    VARIDIV(UI2,2,I1,1,I4,2);
    VARIDIV(UI2,2,UI1,1,I4,2);
    VARIDIV(UI2,2,UI2,1,I4,2);
    VARIDIV(UI2,2,UI4,1,I4,2);
8417
    if (has_i8)
8418 8419 8420 8421
    {
        VARIDIV(UI2,2,I8,1,I8,2);
        VARIDIV(UI2,2,UI8,1,I4,2);
    }
8422 8423 8424 8425 8426
    VARIDIV(UI2,2,INT,1,I4,2);
    VARIDIV(UI2,2,UINT,1,I4,2);
    VARIDIV(UI4,2,NULL,0,NULL,0);
    VARIDIV(UI4,2,I2,1,I4,2);
    VARIDIV(UI4,2,I4,1,I4,2);
8427
    VARIDIV(UI4,2,R4,1.0f,I4,2);
8428 8429 8430 8431 8432 8433 8434 8435
    VARIDIV(UI4,2,R8,1.0,I4,2);
    VARIDIV(UI4,2,DATE,1,I4,2);
    VARIDIV(UI4,2,BSTR,num1_str,I4,2);
    VARIDIV(UI4,2,BOOL,VARIANT_TRUE,I4,-2);
    VARIDIV(UI4,2,I1,1,I4,2);
    VARIDIV(UI4,2,UI1,1,I4,2);
    VARIDIV(UI4,2,UI2,1,I4,2);
    VARIDIV(UI4,2,UI4,1,I4,2);
8436
    if (has_i8)
8437 8438 8439 8440
    {
        VARIDIV(UI4,2,I8,1,I8,2);
        VARIDIV(UI4,2,UI8,1,I4,2);
    }
8441 8442
    VARIDIV(UI4,2,INT,1,I4,2);
    VARIDIV(UI4,2,UINT,1,I4,2);
8443
    if (has_i8)
8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476
    {
        VARIDIV(I8,2,NULL,0,NULL,0);
        VARIDIV(I8,2,I2,1,I8,2);
        VARIDIV(I8,2,I4,1,I8,2);
        VARIDIV(I8,2,R4,1.0f,I8,2);
        VARIDIV(I8,2,R8,1.0,I8,2);
        VARIDIV(I8,2,DATE,1,I8,2);
        VARIDIV(I8,2,BSTR,num1_str,I8,2);
        VARIDIV(I8,2,BOOL,1,I8,2);
        VARIDIV(I8,2,I1,1,I8,2);
        VARIDIV(I8,2,UI1,1,I8,2);
        VARIDIV(I8,2,UI2,1,I8,2);
        VARIDIV(I8,2,UI4,1,I8,2);
        VARIDIV(I8,2,I8,1,I8,2);
        VARIDIV(I8,2,UI8,1,I8,2);
        VARIDIV(I8,2,UINT,1,I8,2);
        VARIDIV(UI8,2,NULL,0,NULL,0);
        VARIDIV(UI8,2,I2,1,I4,2);
        VARIDIV(UI8,2,I4,1,I4,2);
        VARIDIV(UI8,2,R4,1.0f,I4,2);
        VARIDIV(UI8,2,R8,1.0,I4,2);
        VARIDIV(UI8,2,DATE,1,I4,2);
        VARIDIV(UI8,2,BSTR,num1_str,I4,2);
        VARIDIV(UI8,2,BOOL,VARIANT_TRUE,I4,-2);
        VARIDIV(UI8,2,I1,1,I4,2);
        VARIDIV(UI8,2,UI1,1,I4,2);
        VARIDIV(UI8,2,UI2,1,I4,2);
        VARIDIV(UI8,2,UI4,1,I4,2);
        VARIDIV(UI8,2,I8,1,I8,2);
        VARIDIV(UI8,2,UI8,1,I4,2);
        VARIDIV(UI8,2,INT,1,I4,2);
        VARIDIV(UI8,2,UINT,1,I4,2);
    }
8477 8478 8479
    VARIDIV(INT,2,NULL,0,NULL,0);
    VARIDIV(INT,2,I2,1,I4,2);
    VARIDIV(INT,2,I4,1,I4,2);
8480
    VARIDIV(INT,2,R4,1.0f,I4,2);
8481 8482 8483 8484 8485 8486 8487 8488
    VARIDIV(INT,2,R8,1.0,I4,2);
    VARIDIV(INT,2,DATE,1,I4,2);
    VARIDIV(INT,2,BSTR,num1_str,I4,2);
    VARIDIV(INT,2,BOOL,VARIANT_TRUE,I4,-2);
    VARIDIV(INT,2,I1,1,I4,2);
    VARIDIV(INT,2,UI1,1,I4,2);
    VARIDIV(INT,2,UI2,1,I4,2);
    VARIDIV(INT,2,UI4,1,I4,2);
8489
    if (has_i8)
8490 8491 8492
    {
        VARIDIV(INT,2,UI8,1,I4,2);
    }
8493 8494 8495 8496 8497
    VARIDIV(INT,2,INT,1,I4,2);
    VARIDIV(INT,2,UINT,1,I4,2);
    VARIDIV(UINT,2,NULL,0,NULL,0);
    VARIDIV(UINT,2,I2,1,I4,2);
    VARIDIV(UINT,2,I4,1,I4,2);
8498
    VARIDIV(UINT,2,R4,1.0f,I4,2);
8499 8500 8501 8502 8503 8504 8505 8506
    VARIDIV(UINT,2,R8,1.0,I4,2);
    VARIDIV(UINT,2,DATE,1,I4,2);
    VARIDIV(UINT,2,BSTR,num1_str,I4,2);
    VARIDIV(UINT,2,BOOL,VARIANT_TRUE,I4,-2);
    VARIDIV(UINT,2,I1,1,I4,2);
    VARIDIV(UINT,2,UI1,1,I4,2);
    VARIDIV(UINT,2,UI2,1,I4,2);
    VARIDIV(UINT,2,UI4,1,I4,2);
8507
    if (has_i8)
8508 8509 8510 8511
    {
        VARIDIV(UINT,2,I8,1,I8,2);
        VARIDIV(UINT,2,UI8,1,I4,2);
    }
8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528
    VARIDIV(UINT,2,INT,1,I4,2);
    VARIDIV(UINT,2,UINT,1,I4,2);

    /* Manually test some VT_CY, VT_DECIMAL variants */
    V_VT(&cy) = VT_CY;
    hres = VarCyFromI4(10000, &V_CY(&cy));
    ok(hres == S_OK, "VarCyFromI4 failed!\n");
    V_VT(&dec) = VT_DECIMAL;
    hres = VarDecFromR8(2.0, &V_DECIMAL(&dec));
    ok(hres == S_OK, "VarDecFromR4 failed!\n");
    memset(&left, 0, sizeof(left));
    memset(&right, 0, sizeof(right));
    V_VT(&left) = VT_I4;
    V_I4(&left) = 100;
    V_VT(&right) = VT_I8;
    V_UI1(&right) = 2;

8529
    hres = pVarIdiv(&cy, &cy, &result);
8530
    ok(hres == S_OK && V_VT(&result) == VT_I4,
8531
        "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8532 8533
        S_OK, hres, vtstr(V_VT(&result)));
    ok(hres == S_OK && V_I4(&result) == 1,
8534
        "VARIDIV: CY value %d, expected %d\n", V_I4(&result), 1);
8535

8536
    if (has_i8)
8537
    {
8538
        hres = pVarIdiv(&cy, &right, &result);
8539 8540 8541 8542 8543 8544 8545
        ok(hres == S_OK && V_VT(&result) == VT_I8,
            "VARIDIV: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n",
            S_OK, hres, vtstr(V_VT(&result)));
        ok(hres == S_OK && V_I8(&result) == 5000,
            "VARIDIV: CY value 0x%x%08x, expected 0x%x\n",
	    (DWORD)(V_I8(&result) >>32), (DWORD)V_I8(&result), 5000);
    }
8546

8547
    hres = pVarIdiv(&left, &cy, &result);
8548
    ok(hres == S_OK && V_VT(&result) == VT_I4,
8549
        "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8550 8551
        S_OK, hres, vtstr(V_VT(&result)));
    ok(hres == S_OK && V_I4(&result) == 0,
8552
        "VARIDIV: CY value %d, expected %d\n", V_I4(&result), 0);
8553

8554
    hres = pVarIdiv(&left, &dec, &result);
8555
    ok(hres == S_OK && V_VT(&result) == VT_I4,
8556
        "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8557 8558
        S_OK, hres, vtstr(V_VT(&result)));
    ok(hres == S_OK && V_I4(&result) == 50,
8559
        "VARIDIV: DECIMAL value %d, expected %d\n", V_I4(&result), 50);
8560

8561
    hres = pVarIdiv(&dec, &dec, &result);
8562
    ok(hres == S_OK && V_VT(&result) == VT_I4,
8563
        "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
8564 8565
        S_OK, hres, vtstr(V_VT(&result)));
    ok(hres == S_OK && V_I4(&result) == 1,
8566
        "VARIDIV: DECIMAL value %d, expected %d\n", V_I4(&result), 1);
8567

8568
    if (has_i8)
8569
    {
8570
        hres = pVarIdiv(&dec, &right, &result);
8571 8572 8573 8574 8575 8576 8577
        ok(hres == S_OK && V_VT(&result) == VT_I8,
            "VARIDIV: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n",
            S_OK, hres, vtstr(V_VT(&result)));
        ok(hres == S_OK && V_I8(&result) == 1,
            "VARIDIV: DECIMAL value 0x%x%08x, expected %d\n",
	    (DWORD)(V_I8(&result) >> 32), (DWORD)V_I8(&result), 1);
    }
8578 8579 8580 8581 8582 8583 8584 8585

    /* Check for division by zero */
    V_VT(&left) = VT_INT;
    V_I4(&left) = 1;
    V_VT(&right) = VT_INT;
    V_I4(&right) = 0;
    hres = pVarIdiv(&left, &right, &result);
    ok(hres == DISP_E_DIVBYZERO && V_VT(&result) == VT_EMPTY,
8586
        "VARIDIV: Division by 0 should result in DISP_E_DIVBYZERO but got 0x%X\n", hres);
8587 8588 8589 8590 8591 8592 8593

    V_VT(&left) = VT_INT;
    V_I4(&left) = 0;
    V_VT(&right) = VT_INT;
    V_I4(&right) = 0;
    hres = pVarIdiv(&left, &right, &result);
    ok(hres == DISP_E_DIVBYZERO && V_VT(&result) == VT_EMPTY,
8594
        "VARIDIV: Division by 0 should result in DISP_E_DIVBYZERO but got 0x%X\n", hres);
8595 8596 8597 8598 8599

    SysFreeString(num1_str);
    SysFreeString(num2_str);
}

8600 8601 8602

static HRESULT (WINAPI *pVarImp)(LPVARIANT,LPVARIANT,LPVARIANT);

8603 8604 8605 8606
#define VARIMP(vt1,val1,vt2,val2,rvt,rval)              \
        V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1;   \
        V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
        V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval;     \
8607
        test_var_call2( __LINE__, pVarImp, &left, &right, &exp )
8608

8609
/* Skip any type that is not defined or produces an error for every case */
8610 8611 8612 8613 8614
#define SKIPTESTIMP(a)                            \
    if (a == VT_ERROR || a == VT_VARIANT ||       \
        a == VT_DISPATCH || a == VT_UNKNOWN ||    \
        a == VT_RECORD || a > VT_UINT ||          \
        a == 15 /*not defined*/)                  \
8615
        continue
8616 8617 8618 8619 8620

static void test_VarImp(void)
{
    static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
    static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
8621
    VARIANT left, right, exp, result, cy, dec;
8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639
    BSTR true_str, false_str;
    VARTYPE i;
    HRESULT hres;

    CHECKPTR(VarImp);

    true_str = SysAllocString(szTrue);
    false_str = SysAllocString(szFalse);

    /* Test all possible flag/vt combinations & the resulting vt type */
    for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
    {
        VARTYPE leftvt, rightvt, resvt;

        for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
        {
            SKIPTESTIMP(leftvt);

8640
            /* Check if we need/have support for I8 and/or UI8 */
8641
            if ((leftvt == VT_I8 || leftvt == VT_UI8) && !has_i8)
8642 8643
                continue;

8644 8645 8646 8647 8648
            for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
            {
                BOOL bFail = FALSE;
                SKIPTESTIMP(rightvt);

8649
                /* Native crashes when using the extra flag VT_BYREF
8650 8651 8652 8653 8654 8655 8656
                 * or with the following VT combinations
                 */
                if ((leftvt == VT_UI4 && rightvt == VT_BSTR) ||
                    (leftvt == VT_UI8 && rightvt == VT_BSTR) ||
                    ExtraFlags[i] == VT_BYREF)
                    continue;

8657
                /* Check if we need/have support for I8 and/or UI8 */
8658
                if ((rightvt == VT_I8 || rightvt == VT_UI8) && !has_i8)
8659 8660
                    continue;

8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688
                memset(&left, 0, sizeof(left));
                memset(&right, 0, sizeof(right));
                V_VT(&left) = leftvt | ExtraFlags[i];
                V_VT(&right) = rightvt | ExtraFlags[i];
                V_VT(&result) = VT_EMPTY;
                resvt = VT_EMPTY;

                if (leftvt == VT_BSTR)
                    V_BSTR(&left) = true_str;

                /* This allows us to test return types that are not NULL
                 * (NULL Imp value = n, NULL Imp 0 = NULL)
                 */
                switch(rightvt)
                {
                case VT_BSTR:
                    V_BSTR(&right) = true_str;
                    break;
                case VT_DECIMAL:
                    VarDecFromR8(2.0, &V_DECIMAL(&right));
                    V_VT(&right) = rightvt | ExtraFlags[i];
                    break;
                case VT_BOOL:
                    V_BOOL(&right) = VARIANT_TRUE;
                    break;
                case VT_I1: V_I1(&right) = 2; break;
                case VT_I2: V_I2(&right) = 2; break;
                case VT_I4: V_I4(&right) = 2; break;
8689
                case VT_R4: V_R4(&right) = 2.0f; break;
8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702
                case VT_R8: V_R8(&right) = 2.0; break;
                case VT_CY: V_CY(&right).int64 = 10000; break;
                case VT_DATE: V_DATE(&right) = 2; break;
                case VT_I8: V_I8(&right) = 2; break;
                case VT_INT: V_INT(&right) = 2; break;
                case VT_UINT: V_UINT(&right) = 2; break;
                case VT_UI1: V_UI1(&right) = 2; break;
                case VT_UI2: V_UI2(&right) = 2; break;
                case VT_UI4: V_UI4(&right) = 2; break;
                case VT_UI8: V_UI8(&right) = 2; break;
                default: break;
                }

8703
                /* Native VarImp always returns an error when using extra
8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746
                 * flags or if the variants are I8 and INT.
                 */
                if ((leftvt == VT_I8 && rightvt == VT_INT) ||
                    ExtraFlags[i] != 0)
                    bFail = TRUE;

                /* Determine result type */
                else if ((leftvt == VT_BSTR && rightvt == VT_NULL) ||
                    (leftvt == VT_NULL && rightvt == VT_NULL) ||
                    (leftvt == VT_NULL && rightvt == VT_EMPTY))
                    resvt = VT_NULL;
                else if (leftvt == VT_I8 || rightvt == VT_I8)
                    resvt = VT_I8;
                else if (leftvt == VT_I4 || rightvt == VT_I4 ||
                    leftvt == VT_INT || rightvt == VT_INT ||
                    leftvt == VT_UINT || rightvt == VT_UINT ||
                    leftvt == VT_UI4 || rightvt == VT_UI4 ||
                    leftvt == VT_UI8 || rightvt == VT_UI8 ||
                    leftvt == VT_UI2 || rightvt == VT_UI2 ||
                    leftvt == VT_DECIMAL || rightvt == VT_DECIMAL ||
                    leftvt == VT_DATE || rightvt == VT_DATE ||
                    leftvt == VT_CY || rightvt == VT_CY ||
                    leftvt == VT_R8 || rightvt == VT_R8 ||
                    leftvt == VT_R4 || rightvt == VT_R4 ||
                    leftvt == VT_I1 || rightvt == VT_I1)
                    resvt = VT_I4;
                else if ((leftvt == VT_UI1 && rightvt == VT_UI1) ||
                    (leftvt == VT_UI1 && rightvt == VT_NULL) ||
                    (leftvt == VT_NULL && rightvt == VT_UI1))
                    resvt = VT_UI1;
                else if (leftvt == VT_EMPTY || rightvt == VT_EMPTY ||
                    leftvt == VT_I2 || rightvt == VT_I2 ||
                    leftvt == VT_UI1 || rightvt == VT_UI1)
                    resvt = VT_I2;
                else if (leftvt == VT_BOOL || rightvt == VT_BOOL ||
                    leftvt == VT_BSTR || rightvt == VT_BSTR)
                    resvt = VT_BOOL;

                hres = pVarImp(&left, &right, &result);

                /* Check expected HRESULT and if result variant type is correct */
                if (bFail)
                    ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH,
8747
                        "VarImp: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n",
8748 8749 8750 8751
                        vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i],
                        vtstr(V_VT(&result)), hres);
                else
                    ok (hres == S_OK && resvt == V_VT(&result),
8752
                        "VarImp: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n",
8753 8754 8755 8756 8757 8758 8759 8760 8761 8762
                        vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt),
                        S_OK, vtstr(V_VT(&result)), hres);
            }
        }
    }

    VARIMP(EMPTY,0,EMPTY,0,I2,-1);
    VARIMP(EMPTY,0,NULL,0,I2,-1);
    VARIMP(EMPTY,0,I2,-1,I2,-1);
    VARIMP(EMPTY,0,I4,-1,I4,-1);
8763
    VARIMP(EMPTY,0,R4,0.0f,I4,-1);
8764 8765 8766 8767 8768 8769 8770 8771
    VARIMP(EMPTY,0,R8,-1.0,I4,-1);
    VARIMP(EMPTY,0,DATE,0,I4,-1);
    VARIMP(EMPTY,0,BSTR,true_str,I2,-1);
    VARIMP(EMPTY,0,BOOL,VARIANT_FALSE,I2,-1);
    VARIMP(EMPTY,0,I1,0,I4,-1);
    VARIMP(EMPTY,0,UI1,1,I2,-1);
    VARIMP(EMPTY,0,UI2,1,I4,-1);
    VARIMP(EMPTY,0,UI4,1,I4,-1);
8772
    if (has_i8)
8773 8774 8775 8776
    {
        VARIMP(EMPTY,0,I8,1,I8,-1);
        VARIMP(EMPTY,0,UI8,1,I4,-1);
    }
8777 8778 8779 8780 8781 8782
    VARIMP(EMPTY,0,INT,-1,I4,-1);
    VARIMP(EMPTY,0,UINT,1,I4,-1);
    VARIMP(NULL,0,EMPTY,0,NULL,0);
    VARIMP(NULL,0,NULL,0,NULL,0);
    VARIMP(NULL,0,I2,-1,I2,-1);
    VARIMP(NULL,0,I4,-1,I4,-1);
8783
    VARIMP(NULL,0,R4,0.0f,NULL,0);
8784 8785 8786 8787 8788 8789 8790 8791
    VARIMP(NULL,0,R8,-1.0,I4,-1);
    VARIMP(NULL,0,DATE,0,NULL,0);
    VARIMP(NULL,0,BSTR,true_str,BOOL,-1);
    VARIMP(NULL,0,BOOL,VARIANT_FALSE,NULL,0);
    VARIMP(NULL,0,I1,0,NULL,0);
    VARIMP(NULL,0,UI1,1,UI1,1);
    VARIMP(NULL,0,UI2,1,I4,1);
    VARIMP(NULL,0,UI4,1,I4,1);
8792
    if (has_i8)
8793 8794 8795 8796
    {
        VARIMP(NULL,0,I8,1,I8,1);
        VARIMP(NULL,0,UI8,1,I4,1);
    }
8797 8798 8799 8800 8801
    VARIMP(NULL,0,INT,-1,I4,-1);
    VARIMP(NULL,0,UINT,1,I4,1);
    VARIMP(I2,-1,EMPTY,0,I2,0);
    VARIMP(I2,-1,I2,-1,I2,-1);
    VARIMP(I2,-1,I4,-1,I4,-1);
8802
    VARIMP(I2,-1,R4,0.0f,I4,0);
8803 8804 8805 8806 8807 8808 8809 8810
    VARIMP(I2,-1,R8,-1.0,I4,-1);
    VARIMP(I2,-1,DATE,0,I4,0);
    VARIMP(I2,-1,BSTR,true_str,I2,-1);
    VARIMP(I2,-1,BOOL,VARIANT_FALSE,I2,0);
    VARIMP(I2,-1,I1,0,I4,0);
    VARIMP(I2,-1,UI1,1,I2,1);
    VARIMP(I2,-1,UI2,1,I4,1);
    VARIMP(I2,-1,UI4,1,I4,1);
8811
    if (has_i8)
8812 8813 8814 8815
    {
        VARIMP(I2,-1,I8,1,I8,1);
        VARIMP(I2,-1,UI8,1,I4,1);
    }
8816 8817 8818 8819 8820 8821
    VARIMP(I2,-1,INT,-1,I4,-1);
    VARIMP(I2,-1,UINT,1,I4,1);
    VARIMP(I4,2,EMPTY,0,I4,-3);
    VARIMP(I4,2,NULL,0,I4,-3);
    VARIMP(I4,2,I2,-1,I4,-1);
    VARIMP(I4,2,I4,-1,I4,-1);
8822
    VARIMP(I4,2,R4,0.0f,I4,-3);
8823 8824 8825 8826 8827 8828 8829 8830
    VARIMP(I4,2,R8,-1.0,I4,-1);
    VARIMP(I4,2,DATE,0,I4,-3);
    VARIMP(I4,2,BSTR,true_str,I4,-1);
    VARIMP(I4,2,BOOL,VARIANT_FALSE,I4,-3);
    VARIMP(I4,2,I1,0,I4,-3);
    VARIMP(I4,2,UI1,1,I4,-3);
    VARIMP(I4,2,UI2,1,I4,-3);
    VARIMP(I4,2,UI4,1,I4,-3);
8831
    if (has_i8)
8832 8833 8834 8835
    {
        VARIMP(I4,2,I8,1,I8,-3);
        VARIMP(I4,2,UI8,1,I4,-3);
    }
8836 8837
    VARIMP(I4,2,INT,-1,I4,-1);
    VARIMP(I4,2,UINT,1,I4,-3);
8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850
    VARIMP(R4,-1.0f,EMPTY,0,I4,0);
    VARIMP(R4,-1.0f,NULL,0,NULL,0);
    VARIMP(R4,-1.0f,I2,-1,I4,-1);
    VARIMP(R4,-1.0f,I4,-1,I4,-1);
    VARIMP(R4,-1.0f,R4,0.0f,I4,0);
    VARIMP(R4,-1.0f,R8,-1.0,I4,-1);
    VARIMP(R4,-1.0f,DATE,1,I4,1);
    VARIMP(R4,-1.0f,BSTR,true_str,I4,-1);
    VARIMP(R4,-1.0f,BOOL,VARIANT_FALSE,I4,0);
    VARIMP(R4,-1.0f,I1,0,I4,0);
    VARIMP(R4,-1.0f,UI1,1,I4,1);
    VARIMP(R4,-1.0f,UI2,1,I4,1);
    VARIMP(R4,-1.0f,UI4,1,I4,1);
8851
    if (has_i8)
8852 8853 8854 8855
    {
        VARIMP(R4,-1.0f,I8,1,I8,1);
        VARIMP(R4,-1.0f,UI8,1,I4,1);
    }
8856 8857
    VARIMP(R4,-1.0f,INT,-1,I4,-1);
    VARIMP(R4,-1.0f,UINT,1,I4,1);
8858 8859 8860 8861
    VARIMP(R8,1.0,EMPTY,0,I4,-2);
    VARIMP(R8,1.0,NULL,0,I4,-2);
    VARIMP(R8,1.0,I2,-1,I4,-1);
    VARIMP(R8,1.0,I4,-1,I4,-1);
8862
    VARIMP(R8,1.0,R4,0.0f,I4,-2);
8863 8864 8865 8866 8867 8868 8869 8870
    VARIMP(R8,1.0,R8,-1.0,I4,-1);
    VARIMP(R8,1.0,DATE,0,I4,-2);
    VARIMP(R8,1.0,BSTR,true_str,I4,-1);
    VARIMP(R8,1.0,BOOL,VARIANT_FALSE,I4,-2);
    VARIMP(R8,1.0,I1,0,I4,-2);
    VARIMP(R8,1.0,UI1,1,I4,-1);
    VARIMP(R8,1.0,UI2,1,I4,-1);
    VARIMP(R8,1.0,UI4,1,I4,-1);
8871
    if (has_i8)
8872 8873 8874 8875
    {
        VARIMP(R8,1.0,I8,1,I8,-1);
        VARIMP(R8,1.0,UI8,1,I4,-1);
    }
8876 8877 8878 8879 8880 8881
    VARIMP(R8,1.0,INT,-1,I4,-1);
    VARIMP(R8,1.0,UINT,1,I4,-1);
    VARIMP(DATE,0,EMPTY,0,I4,-1);
    VARIMP(DATE,0,NULL,0,I4,-1);
    VARIMP(DATE,0,I2,-1,I4,-1);
    VARIMP(DATE,0,I4,-1,I4,-1);
8882
    VARIMP(DATE,0,R4,0.0f,I4,-1);
8883 8884 8885 8886 8887 8888 8889 8890
    VARIMP(DATE,0,R8,-1.0,I4,-1);
    VARIMP(DATE,0,DATE,0,I4,-1);
    VARIMP(DATE,0,BSTR,true_str,I4,-1);
    VARIMP(DATE,0,BOOL,VARIANT_FALSE,I4,-1);
    VARIMP(DATE,0,I1,0,I4,-1);
    VARIMP(DATE,0,UI1,1,I4,-1);
    VARIMP(DATE,0,UI2,1,I4,-1);
    VARIMP(DATE,0,UI4,1,I4,-1);
8891
    if (has_i8)
8892 8893 8894 8895
    {
        VARIMP(DATE,0,I8,1,I8,-1);
        VARIMP(DATE,0,UI8,1,I4,-1);
    }
8896 8897 8898 8899 8900 8901
    VARIMP(DATE,0,INT,-1,I4,-1);
    VARIMP(DATE,0,UINT,1,I4,-1);
    VARIMP(BSTR,false_str,EMPTY,0,I2,-1);
    VARIMP(BSTR,false_str,NULL,0,BOOL,-1);
    VARIMP(BSTR,false_str,I2,-1,I2,-1);
    VARIMP(BSTR,false_str,I4,-1,I4,-1);
8902
    VARIMP(BSTR,false_str,R4,0.0f,I4,-1);
8903 8904 8905 8906 8907 8908 8909 8910
    VARIMP(BSTR,false_str,R8,-1.0,I4,-1);
    VARIMP(BSTR,false_str,DATE,0,I4,-1);
    VARIMP(BSTR,false_str,BSTR,true_str,BOOL,-1);
    VARIMP(BSTR,false_str,BOOL,VARIANT_FALSE,BOOL,-1);
    VARIMP(BSTR,false_str,I1,0,I4,-1);
    VARIMP(BSTR,false_str,UI1,1,I2,-1);
    VARIMP(BSTR,false_str,UI2,1,I4,-1);
    VARIMP(BSTR,false_str,UI4,1,I4,-1);
8911
    if (has_i8)
8912 8913 8914 8915
    {
        VARIMP(BSTR,false_str,I8,1,I8,-1);
        VARIMP(BSTR,false_str,UI8,1,I4,-1);
    }
8916 8917 8918 8919 8920 8921
    VARIMP(BSTR,false_str,INT,-1,I4,-1);
    VARIMP(BSTR,false_str,UINT,1,I4,-1);
    VARIMP(BOOL,VARIANT_TRUE,EMPTY,0,I2,0);
    VARIMP(BOOL,VARIANT_TRUE,NULL,0,NULL,0);
    VARIMP(BOOL,VARIANT_TRUE,I2,-1,I2,-1);
    VARIMP(BOOL,VARIANT_TRUE,I4,-1,I4,-1);
8922
    VARIMP(BOOL,VARIANT_TRUE,R4,0.0f,I4,0);
8923 8924 8925 8926 8927 8928 8929 8930
    VARIMP(BOOL,VARIANT_TRUE,R8,-1.0,I4,-1);
    VARIMP(BOOL,VARIANT_TRUE,DATE,0,I4,0);
    VARIMP(BOOL,VARIANT_TRUE,BSTR,true_str,BOOL,-1);
    VARIMP(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,0);
    VARIMP(BOOL,VARIANT_TRUE,I1,0,I4,0);
    VARIMP(BOOL,VARIANT_TRUE,UI1,1,I2,1);
    VARIMP(BOOL,VARIANT_TRUE,UI2,1,I4,1);
    VARIMP(BOOL,VARIANT_TRUE,UI4,1,I4,1);
8931
    if (has_i8)
8932 8933 8934 8935
    {
        VARIMP(BOOL,VARIANT_TRUE,I8,1,I8,1);
        VARIMP(BOOL,VARIANT_TRUE,UI8,1,I4,1);
    }
8936 8937 8938 8939 8940 8941
    VARIMP(BOOL,VARIANT_TRUE,INT,-1,I4,-1);
    VARIMP(BOOL,VARIANT_TRUE,UINT,1,I4,1);
    VARIMP(I1,-1,EMPTY,0,I4,0);
    VARIMP(I1,-1,NULL,0,NULL,0);
    VARIMP(I1,-1,I2,-1,I4,-1);
    VARIMP(I1,-1,I4,-1,I4,-1);
8942
    VARIMP(I1,-1,R4,0.0f,I4,0);
8943 8944 8945 8946 8947 8948 8949 8950
    VARIMP(I1,-1,R8,-1.0,I4,-1);
    VARIMP(I1,-1,DATE,0,I4,0);
    VARIMP(I1,-1,BSTR,true_str,I4,-1);
    VARIMP(I1,-1,BOOL,VARIANT_FALSE,I4,0);
    VARIMP(I1,-1,I1,0,I4,0);
    VARIMP(I1,-1,UI1,1,I4,1);
    VARIMP(I1,-1,UI2,1,I4,1);
    VARIMP(I1,-1,UI4,1,I4,1);
8951
    if (has_i8)
8952 8953 8954 8955
    {
        VARIMP(I1,-1,I8,1,I8,1);
        VARIMP(I1,-1,UI8,1,I4,1);
    }
8956 8957 8958 8959 8960 8961
    VARIMP(I1,-1,INT,-1,I4,-1);
    VARIMP(I1,-1,UINT,1,I4,1);
    VARIMP(UI1,0,EMPTY,0,I2,-1);
    VARIMP(UI1,0,NULL,0,UI1,255);
    VARIMP(UI1,0,I2,-1,I2,-1);
    VARIMP(UI1,0,I4,-1,I4,-1);
8962
    VARIMP(UI1,0,R4,0.0f,I4,-1);
8963 8964 8965 8966 8967 8968 8969 8970
    VARIMP(UI1,0,R8,-1.0,I4,-1);
    VARIMP(UI1,0,DATE,0,I4,-1);
    VARIMP(UI1,0,BSTR,true_str,I2,-1);
    VARIMP(UI1,0,BOOL,VARIANT_FALSE,I2,-1);
    VARIMP(UI1,0,I1,0,I4,-1);
    VARIMP(UI1,0,UI1,1,UI1,255);
    VARIMP(UI1,0,UI2,1,I4,-1);
    VARIMP(UI1,0,UI4,1,I4,-1);
8971
    if (has_i8)
8972 8973 8974 8975
    {
        VARIMP(UI1,0,I8,1,I8,-1);
        VARIMP(UI1,0,UI8,1,I4,-1);
    }
8976 8977 8978 8979 8980 8981
    VARIMP(UI1,0,INT,-1,I4,-1);
    VARIMP(UI1,0,UINT,1,I4,-1);
    VARIMP(UI2,0,EMPTY,0,I4,-1);
    VARIMP(UI2,0,NULL,0,I4,-1);
    VARIMP(UI2,0,I2,-1,I4,-1);
    VARIMP(UI2,0,I4,-1,I4,-1);
8982
    VARIMP(UI2,0,R4,0.0f,I4,-1);
8983 8984 8985 8986 8987 8988 8989 8990
    VARIMP(UI2,0,R8,-1.0,I4,-1);
    VARIMP(UI2,0,DATE,0,I4,-1);
    VARIMP(UI2,0,BSTR,true_str,I4,-1);
    VARIMP(UI2,0,BOOL,VARIANT_FALSE,I4,-1);
    VARIMP(UI2,0,I1,0,I4,-1);
    VARIMP(UI2,0,UI1,1,I4,-1);
    VARIMP(UI2,0,UI2,1,I4,-1);
    VARIMP(UI2,0,UI4,1,I4,-1);
8991
    if (has_i8)
8992 8993 8994 8995
    {
        VARIMP(UI2,0,I8,1,I8,-1);
        VARIMP(UI2,0,UI8,1,I4,-1);
    }
8996 8997 8998 8999 9000 9001
    VARIMP(UI2,0,INT,-1,I4,-1);
    VARIMP(UI2,0,UINT,1,I4,-1);
    VARIMP(UI4,0,EMPTY,0,I4,-1);
    VARIMP(UI4,0,NULL,0,I4,-1);
    VARIMP(UI4,0,I2,-1,I4,-1);
    VARIMP(UI4,0,I4,-1,I4,-1);
9002
    VARIMP(UI4,0,R4,0.0f,I4,-1);
9003 9004 9005 9006 9007 9008 9009 9010
    VARIMP(UI4,0,R8,-1.0,I4,-1);
    VARIMP(UI4,0,DATE,0,I4,-1);
    VARIMP(UI4,0,BSTR,true_str,I4,-1);
    VARIMP(UI4,0,BOOL,VARIANT_FALSE,I4,-1);
    VARIMP(UI4,0,I1,0,I4,-1);
    VARIMP(UI4,0,UI1,1,I4,-1);
    VARIMP(UI4,0,UI2,1,I4,-1);
    VARIMP(UI4,0,UI4,1,I4,-1);
9011
    if (has_i8)
9012 9013 9014 9015
    {
        VARIMP(UI4,0,I8,1,I8,-1);
        VARIMP(UI4,0,UI8,1,I4,-1);
    }
9016 9017
    VARIMP(UI4,0,INT,-1,I4,-1);
    VARIMP(UI4,0,UINT,1,I4,-1);
9018
    if (has_i8)
9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053
    {
        VARIMP(I8,-1,EMPTY,0,I8,0);
        VARIMP(I8,-1,NULL,0,NULL,0);
        VARIMP(I8,-1,I2,-1,I8,-1);
        VARIMP(I8,-1,I4,-1,I8,-1);
        VARIMP(I8,-1,R4,0.0f,I8,0);
        VARIMP(I8,-1,R8,-1.0,I8,-1);
        VARIMP(I8,-1,DATE,0,I8,0);
        VARIMP(I8,-1,BSTR,true_str,I8,-1);
        VARIMP(I8,-1,BOOL,VARIANT_FALSE,I8,0);
        VARIMP(I8,-1,I1,0,I8,0);
        VARIMP(I8,-1,UI1,1,I8,1);
        VARIMP(I8,-1,UI2,1,I8,1);
        VARIMP(I8,-1,UI4,1,I8,1);
        VARIMP(I8,-1,I8,1,I8,1);
        VARIMP(I8,-1,UI8,1,I8,1);
        VARIMP(I8,-1,UINT,1,I8,1);
        VARIMP(UI8,0,EMPTY,0,I4,-1);
        VARIMP(UI8,0,NULL,0,I4,-1);
        VARIMP(UI8,0,I2,-1,I4,-1);
        VARIMP(UI8,0,I4,-1,I4,-1);
        VARIMP(UI8,0,R4,0.0f,I4,-1);
        VARIMP(UI8,0,R8,-1.0,I4,-1);
        VARIMP(UI8,0,DATE,0,I4,-1);
        VARIMP(UI8,0,BSTR,true_str,I4,-1);
        VARIMP(UI8,0,BOOL,VARIANT_FALSE,I4,-1);
        VARIMP(UI8,0,I1,0,I4,-1);
        VARIMP(UI8,0,UI1,1,I4,-1);
        VARIMP(UI8,0,UI2,1,I4,-1);
        VARIMP(UI8,0,UI4,1,I4,-1);
        VARIMP(UI8,0,I8,1,I8,-1);
        VARIMP(UI8,0,UI8,1,I4,-1);
        VARIMP(UI8,0,INT,-1,I4,-1);
        VARIMP(UI8,0,UINT,1,I4,-1);
    }
9054 9055 9056 9057
    VARIMP(INT,-1,EMPTY,0,I4,0);
    VARIMP(INT,-1,NULL,0,NULL,0);
    VARIMP(INT,-1,I2,-1,I4,-1);
    VARIMP(INT,-1,I4,-1,I4,-1);
9058
    VARIMP(INT,-1,R4,0.0f,I4,0);
9059 9060 9061 9062 9063 9064 9065 9066
    VARIMP(INT,-1,R8,-1.0,I4,-1);
    VARIMP(INT,-1,DATE,0,I4,0);
    VARIMP(INT,-1,BSTR,true_str,I4,-1);
    VARIMP(INT,-1,BOOL,VARIANT_FALSE,I4,0);
    VARIMP(INT,-1,I1,0,I4,0);
    VARIMP(INT,-1,UI1,1,I4,1);
    VARIMP(INT,-1,UI2,1,I4,1);
    VARIMP(INT,-1,UI4,1,I4,1);
9067
    if (has_i8)
9068 9069 9070 9071
    {
        VARIMP(INT,-1,I8,1,I8,1);
        VARIMP(INT,-1,UI8,1,I4,1);
    }
9072 9073 9074 9075 9076 9077
    VARIMP(INT,-1,INT,-1,I4,-1);
    VARIMP(INT,-1,UINT,1,I4,1);
    VARIMP(UINT,1,EMPTY,0,I4,-2);
    VARIMP(UINT,1,NULL,0,I4,-2);
    VARIMP(UINT,1,I2,-1,I4,-1);
    VARIMP(UINT,1,I4,-1,I4,-1);
9078
    VARIMP(UINT,1,R4,0.0f,I4,-2);
9079 9080 9081 9082 9083 9084 9085 9086
    VARIMP(UINT,1,R8,-1.0,I4,-1);
    VARIMP(UINT,1,DATE,0,I4,-2);
    VARIMP(UINT,1,BSTR,true_str,I4,-1);
    VARIMP(UINT,1,BOOL,VARIANT_FALSE,I4,-2);
    VARIMP(UINT,1,I1,0,I4,-2);
    VARIMP(UINT,1,UI1,1,I4,-1);
    VARIMP(UINT,1,UI2,1,I4,-1);
    VARIMP(UINT,1,UI4,1,I4,-1);
9087
    if (has_i8)
9088 9089 9090 9091
    {
        VARIMP(UINT,1,I8,1,I8,-1);
        VARIMP(UINT,1,UI8,1,I4,-1);
    }
9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110
    VARIMP(UINT,1,INT,-1,I4,-1);
    VARIMP(UINT,1,UINT,1,I4,-1);

    /* Manually test some VT_CY, VT_DECIMAL variants */
    V_VT(&cy) = VT_CY;
    hres = VarCyFromI4(1, &V_CY(&cy));
    ok(hres == S_OK, "VarCyFromI4 failed!\n");
    V_VT(&dec) = VT_DECIMAL;
    hres = VarDecFromR8(2.0, &V_DECIMAL(&dec));
    ok(hres == S_OK, "VarDecFromR4 failed!\n");
    memset(&left, 0, sizeof(left));
    memset(&right, 0, sizeof(right));
    V_VT(&left) = VT_I4;
    V_I4(&left) = 0;
    V_VT(&right) = VT_I8;
    V_UI1(&right) = 0;

    hres = pVarImp(&cy, &cy, &result);
    ok(hres == S_OK && V_VT(&result) == VT_I4,
9111
        "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
9112 9113
        S_OK, hres, vtstr(V_VT(&result)));
    ok(hres == S_OK && V_I4(&result) == -1,
9114
        "VARIMP: CY value %d, expected %d\n", V_I4(&result), -1);
9115

9116
    if (has_i8)
9117 9118 9119 9120 9121 9122 9123 9124 9125
    {
        hres = pVarImp(&cy, &right, &result);
        ok(hres == S_OK && V_VT(&result) == VT_I8,
            "VARIMP: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n",
            S_OK, hres, vtstr(V_VT(&result)));
        ok(hres == S_OK && V_I8(&result) == -2,
            "VARIMP: CY value %x%08x, expected %d\n",
            (DWORD)((V_I8(&result)) >> 32), (DWORD)(V_I8(&result)), -2);
    }
9126 9127 9128

    hres = pVarImp(&left, &cy, &result);
    ok(hres == S_OK && V_VT(&result) == VT_I4,
9129
        "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
9130 9131
        S_OK, hres, vtstr(V_VT(&result)));
    ok(hres == S_OK && V_I4(&result) == -1,
9132
        "VARIMP: CY value %d, expected %d\n", V_I4(&result), -1);
9133 9134 9135

    hres = pVarImp(&left, &dec, &result);
    ok(hres == S_OK && V_VT(&result) == VT_I4,
9136
        "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
9137 9138
        S_OK, hres, vtstr(V_VT(&result)));
    ok(hres == S_OK && V_I4(&result) == -1,
9139
        "VARIMP: DECIMAL value %d, expected %d\n", V_I4(&result), -1);
9140 9141 9142

    hres = pVarImp(&dec, &dec, &result);
    ok(hres == S_OK && V_VT(&result) == VT_I4,
9143
        "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n",
9144 9145
        S_OK, hres, vtstr(V_VT(&result)));
    ok(hres == S_OK && V_I4(&result) == -1,
9146
        "VARIMP: DECIMAL value %d, expected %d\n", V_I4(&result), -1);
9147

9148
    if (has_i8)
9149 9150 9151 9152 9153 9154 9155 9156 9157
    {
        hres = pVarImp(&dec, &right, &result);
        ok(hres == S_OK && V_VT(&result) == VT_I8,
            "VARIMP: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n",
            S_OK, hres, vtstr(V_VT(&result)));
        ok(hres == S_OK && V_I8(&result) == -3,
            "VARIMP: DECIMAL value 0x%x%08x, expected %d\n",
	    (DWORD)(V_I8(&result) >>32), (DWORD)V_I8(&result), -3);
    }
9158 9159 9160 9161 9162

    SysFreeString(false_str);
    SysFreeString(true_str);
}

9163 9164
START_TEST(vartest)
{
9165
  init();
9166

9167 9168
  test_VariantInit();
  test_VariantClear();
9169 9170
  test_VariantCopy();
  test_VariantCopyInd();
9171 9172
  test_VarParseNumFromStr();
  test_VarNumFromParseNum();
9173 9174 9175 9176 9177 9178
  test_VarUdateFromDate();
  test_VarDateFromUdate();
  test_SystemTimeToVariantTime();
  test_VariantTimeToSystemTime();
  test_DosDateTimeToVariantTime();
  test_VariantTimeToDosDateTime();
9179 9180
  test_VarAbs();
  test_VarNot();
9181
  test_VarSub();
9182
  test_VarMod();
9183 9184 9185
  test_VarFix();
  test_VarInt();
  test_VarNeg();
9186
  test_VarRound();
Jon Griffiths's avatar
Jon Griffiths committed
9187
  test_VarXor();
9188
  test_VarOr();
9189
  test_VarPow();
Jon Griffiths's avatar
Jon Griffiths committed
9190
  test_VarEqv();
Michael Stefaniuc's avatar
Michael Stefaniuc committed
9191
  test_VarMul();
Michael Stefaniuc's avatar
Michael Stefaniuc committed
9192
  test_VarAdd();
9193
  test_VarCmp(); /* Before test_VarCat() which needs VarCmp() */
9194
  test_VarCat();
9195
  test_VarAnd();
9196
  test_VarDiv();
9197
  test_VarIdiv();
9198
  test_VarImp();
9199
}