1 /* 2 * VARIANT test program 3 * 4 * Copyright 1998 Jean-Claude Cote 5 * Copyright 2006 Google (Benjamin Arai) 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 20 */ 21 22 #include <stdarg.h> 23 #include <stdio.h> 24 #include <math.h> 25 #include <float.h> 26 27 #define COBJMACROS 28 #define CONST_VTABLE 29 30 #include "windef.h" 31 #include "winbase.h" 32 #include "winsock2.h" 33 #include "wine/test.h" 34 #include "winuser.h" 35 #include "wingdi.h" 36 #include "winnls.h" 37 #include "winerror.h" 38 #include "winnt.h" 39 40 #include "wtypes.h" 41 #include "oleauto.h" 42 43 static HMODULE hOleaut32; 44 45 static HRESULT (WINAPI *pVarUdateFromDate)(DATE,ULONG,UDATE*); 46 static HRESULT (WINAPI *pVarDateFromUdate)(UDATE*,ULONG,DATE*); 47 static INT (WINAPI *pSystemTimeToVariantTime)(LPSYSTEMTIME,double*); 48 static INT (WINAPI *pVariantTimeToSystemTime)(double,LPSYSTEMTIME); 49 static INT (WINAPI *pDosDateTimeToVariantTime)(USHORT,USHORT,double*); 50 static INT (WINAPI *pVariantTimeToDosDateTime)(double,USHORT*,USHORT *); 51 52 static const WCHAR sz12[] = {'1','2','\0'}; 53 /* the strings are localized */ 54 static WCHAR sz12_false[32]; 55 static WCHAR sz12_true[32]; 56 57 /* Get a conversion function ptr, return if function not available */ 58 #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 /* When comparing floating point values we cannot expect an exact match 65 * because the rounding errors depend on the exact algorithm. 66 */ 67 #define EQ_DOUBLE(a,b) (fabs((a)-(b)) / (1.0+fabs(a)+fabs(b)) < 1e-14) 68 #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 /* Allow our test macros to work for VT_NULL and VT_EMPTY too */ 73 #define V_EMPTY(v) V_I4(v) 74 #define V_NULL(v) V_I4(v) 75 76 /* Size constraints for overflow tests */ 77 #define I1_MAX 0x7f 78 #define I1_MIN ((-I1_MAX)-1) 79 #define UI1_MAX 0xff 80 #define UI1_MIN 0 81 #define I2_MAX 0x7fff 82 #define I2_MIN ((-I2_MAX)-1) 83 #define UI2_MAX 0xffff 84 #define UI2_MIN 0 85 #define I4_MAX 0x7fffffff 86 #define I4_MIN ((-I4_MAX)-1) 87 #define UI4_MAX 0xffffffff 88 #define UI4_MIN 0 89 #define I8_MAX (((LONGLONG)I4_MAX << 32) | UI4_MAX) 90 #define I8_MIN ((-I8_MAX)-1) 91 #define UI8_MAX (((ULONGLONG)UI4_MAX << 32) | UI4_MAX) 92 #define UI8_MIN 0 93 #define DATE_MAX 2958465 94 #define DATE_MIN -657434 95 #define R4_MAX FLT_MAX 96 #define R4_MIN FLT_MIN 97 #define R8_MAX DBL_MAX 98 #define R8_MIN DBL_MIN 99 100 #define DEFINE_EXPECT(func) \ 101 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE 102 103 #define SET_EXPECT(func) \ 104 do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0) 105 106 #define CHECK_EXPECT2(func) \ 107 do { \ 108 ok(expect_ ##func, "unexpected call " #func "\n"); \ 109 called_ ## func = TRUE; \ 110 }while(0) 111 112 #define CHECK_EXPECT(func) \ 113 do { \ 114 CHECK_EXPECT2(func); \ 115 expect_ ## func = FALSE; \ 116 }while(0) 117 118 #define CHECK_CALLED(func) \ 119 do { \ 120 ok(called_ ## func, "expected " #func "\n"); \ 121 expect_ ## func = called_ ## func = FALSE; \ 122 }while(0) 123 124 DEFINE_EXPECT(dispatch_invoke); 125 126 typedef struct 127 { 128 IDispatch IDispatch_iface; 129 VARTYPE vt; 130 HRESULT result; 131 } DummyDispatch; 132 133 static inline DummyDispatch *impl_from_IDispatch(IDispatch *iface) 134 { 135 return CONTAINING_RECORD(iface, DummyDispatch, IDispatch_iface); 136 } 137 138 static ULONG WINAPI DummyDispatch_AddRef(IDispatch *iface) 139 { 140 return 2; 141 } 142 143 static ULONG WINAPI DummyDispatch_Release(IDispatch *iface) 144 { 145 return 1; 146 } 147 148 static HRESULT WINAPI DummyDispatch_QueryInterface(IDispatch *iface, 149 REFIID riid, 150 void** ppvObject) 151 { 152 *ppvObject = NULL; 153 154 if (IsEqualIID(riid, &IID_IDispatch) || 155 IsEqualIID(riid, &IID_IUnknown)) 156 { 157 *ppvObject = iface; 158 IDispatch_AddRef(iface); 159 } 160 161 return *ppvObject ? S_OK : E_NOINTERFACE; 162 } 163 164 static HRESULT WINAPI DummyDispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo) 165 { 166 ok(0, "Unexpected call\n"); 167 return E_NOTIMPL; 168 } 169 170 static HRESULT WINAPI DummyDispatch_GetTypeInfo(IDispatch *iface, UINT tinfo, LCID lcid, ITypeInfo **ti) 171 { 172 ok(0, "Unexpected call\n"); 173 return E_NOTIMPL; 174 } 175 176 static HRESULT WINAPI DummyDispatch_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *names, 177 UINT cnames, LCID lcid, DISPID *dispid) 178 { 179 ok(0, "Unexpected call\n"); 180 return E_NOTIMPL; 181 } 182 183 static HRESULT WINAPI DummyDispatch_Invoke(IDispatch *iface, 184 DISPID dispid, REFIID riid, 185 LCID lcid, WORD wFlags, 186 DISPPARAMS *params, 187 VARIANT *res, 188 EXCEPINFO *ei, 189 UINT *arg_err) 190 { 191 DummyDispatch *This = impl_from_IDispatch(iface); 192 193 CHECK_EXPECT(dispatch_invoke); 194 195 ok(dispid == DISPID_VALUE, "got dispid %d\n", dispid); 196 ok(IsEqualIID(riid, &IID_NULL), "go riid %s\n", wine_dbgstr_guid(riid)); 197 ok(wFlags == DISPATCH_PROPERTYGET, "Flags wrong\n"); 198 199 ok(params->rgvarg == NULL, "got %p\n", params->rgvarg); 200 ok(params->rgdispidNamedArgs == NULL, "got %p\n", params->rgdispidNamedArgs); 201 ok(params->cArgs == 0, "got %d\n", params->cArgs); 202 ok(params->cNamedArgs == 0, "got %d\n", params->cNamedArgs); 203 204 ok(res != NULL, "got %p\n", res); 205 ok(V_VT(res) == VT_EMPTY, "got %d\n", V_VT(res)); 206 ok(ei == NULL, "got %p\n", ei); 207 ok(arg_err == NULL, "got %p\n", arg_err); 208 209 if (FAILED(This->result)) 210 return This->result; 211 212 V_VT(res) = This->vt; 213 if (This->vt == VT_UI1) 214 V_UI1(res) = 34; 215 else if (This->vt == VT_NULL) 216 { 217 V_VT(res) = VT_NULL; 218 V_BSTR(res) = NULL; 219 } 220 else 221 memset(res, 0, sizeof(*res)); 222 223 return S_OK; 224 } 225 226 static const IDispatchVtbl DummyDispatch_VTable = 227 { 228 DummyDispatch_QueryInterface, 229 DummyDispatch_AddRef, 230 DummyDispatch_Release, 231 DummyDispatch_GetTypeInfoCount, 232 DummyDispatch_GetTypeInfo, 233 DummyDispatch_GetIDsOfNames, 234 DummyDispatch_Invoke 235 }; 236 237 static void init_test_dispatch(VARTYPE vt, DummyDispatch *dispatch) 238 { 239 dispatch->IDispatch_iface.lpVtbl = &DummyDispatch_VTable; 240 dispatch->vt = vt; 241 dispatch->result = S_OK; 242 } 243 244 typedef struct IRecordInfoImpl 245 { 246 IRecordInfo IRecordInfo_iface; 247 LONG ref; 248 unsigned int recordclear; 249 unsigned int getsize; 250 unsigned int recordcopy; 251 struct __tagBRECORD *rec; 252 } IRecordInfoImpl; 253 254 static inline IRecordInfoImpl *impl_from_IRecordInfo(IRecordInfo *iface) 255 { 256 return CONTAINING_RECORD(iface, IRecordInfoImpl, IRecordInfo_iface); 257 } 258 259 static HRESULT WINAPI RecordInfo_QueryInterface(IRecordInfo *iface, REFIID riid, void **obj) 260 { 261 *obj = NULL; 262 263 if (IsEqualIID(riid, &IID_IUnknown) || 264 IsEqualIID(riid, &IID_IRecordInfo)) 265 { 266 *obj = iface; 267 IRecordInfo_AddRef(iface); 268 return S_OK; 269 } 270 271 return E_NOINTERFACE; 272 } 273 274 static ULONG WINAPI RecordInfo_AddRef(IRecordInfo *iface) 275 { 276 IRecordInfoImpl* This = impl_from_IRecordInfo(iface); 277 return InterlockedIncrement(&This->ref); 278 } 279 280 static ULONG WINAPI RecordInfo_Release(IRecordInfo *iface) 281 { 282 IRecordInfoImpl* This = impl_from_IRecordInfo(iface); 283 ULONG ref = InterlockedDecrement(&This->ref); 284 285 if (!ref) 286 HeapFree(GetProcessHeap(), 0, This); 287 288 return ref; 289 } 290 291 static HRESULT WINAPI RecordInfo_RecordInit(IRecordInfo *iface, PVOID pvNew) 292 { 293 ok(0, "unexpected call\n"); 294 return E_NOTIMPL; 295 } 296 297 static HRESULT WINAPI RecordInfo_RecordClear(IRecordInfo *iface, void *data) 298 { 299 IRecordInfoImpl* This = impl_from_IRecordInfo(iface); 300 This->recordclear++; 301 This->rec->pvRecord = NULL; 302 return S_OK; 303 } 304 305 static HRESULT WINAPI RecordInfo_RecordCopy(IRecordInfo *iface, void *src, void *dest) 306 { 307 IRecordInfoImpl* This = impl_from_IRecordInfo(iface); 308 This->recordcopy++; 309 ok(src == (void*)0xdeadbeef, "wrong src pointer %p\n", src); 310 return S_OK; 311 } 312 313 static HRESULT WINAPI RecordInfo_GetGuid(IRecordInfo *iface, GUID *pguid) 314 { 315 ok(0, "unexpected call\n"); 316 return E_NOTIMPL; 317 } 318 319 static HRESULT WINAPI RecordInfo_GetName(IRecordInfo *iface, BSTR *pbstrName) 320 { 321 ok(0, "unexpected call\n"); 322 return E_NOTIMPL; 323 } 324 325 static HRESULT WINAPI RecordInfo_GetSize(IRecordInfo *iface, ULONG* size) 326 { 327 IRecordInfoImpl* This = impl_from_IRecordInfo(iface); 328 This->getsize++; 329 *size = 0; 330 return S_OK; 331 } 332 333 static HRESULT WINAPI RecordInfo_GetTypeInfo(IRecordInfo *iface, ITypeInfo **ppTypeInfo) 334 { 335 ok(0, "unexpected call\n"); 336 return E_NOTIMPL; 337 } 338 339 static HRESULT WINAPI RecordInfo_GetField(IRecordInfo *iface, PVOID pvData, 340 LPCOLESTR szFieldName, VARIANT *pvarField) 341 { 342 ok(0, "unexpected call\n"); 343 return E_NOTIMPL; 344 } 345 346 static HRESULT WINAPI RecordInfo_GetFieldNoCopy(IRecordInfo *iface, PVOID pvData, 347 LPCOLESTR szFieldName, VARIANT *pvarField, PVOID *ppvDataCArray) 348 { 349 ok(0, "unexpected call\n"); 350 return E_NOTIMPL; 351 } 352 353 static HRESULT WINAPI RecordInfo_PutField(IRecordInfo *iface, ULONG wFlags, PVOID pvData, 354 LPCOLESTR szFieldName, VARIANT *pvarField) 355 { 356 ok(0, "unexpected call\n"); 357 return E_NOTIMPL; 358 } 359 360 static HRESULT WINAPI RecordInfo_PutFieldNoCopy(IRecordInfo *iface, ULONG wFlags, 361 PVOID pvData, LPCOLESTR szFieldName, VARIANT *pvarField) 362 { 363 ok(0, "unexpected call\n"); 364 return E_NOTIMPL; 365 } 366 367 static HRESULT WINAPI RecordInfo_GetFieldNames(IRecordInfo *iface, ULONG *pcNames, 368 BSTR *rgBstrNames) 369 { 370 ok(0, "unexpected call\n"); 371 return E_NOTIMPL; 372 } 373 374 static BOOL WINAPI RecordInfo_IsMatchingType(IRecordInfo *iface, IRecordInfo *info2) 375 { 376 ok(0, "unexpected call\n"); 377 return FALSE; 378 } 379 380 static PVOID WINAPI RecordInfo_RecordCreate(IRecordInfo *iface) 381 { 382 ok(0, "unexpected call\n"); 383 return NULL; 384 } 385 386 static HRESULT WINAPI RecordInfo_RecordCreateCopy(IRecordInfo *iface, PVOID pvSource, 387 PVOID *ppvDest) 388 { 389 ok(0, "unexpected call\n"); 390 return E_NOTIMPL; 391 } 392 393 static HRESULT WINAPI RecordInfo_RecordDestroy(IRecordInfo *iface, PVOID pvRecord) 394 { 395 ok(0, "unexpected call\n"); 396 return E_NOTIMPL; 397 } 398 399 static const IRecordInfoVtbl RecordInfoVtbl = 400 { 401 RecordInfo_QueryInterface, 402 RecordInfo_AddRef, 403 RecordInfo_Release, 404 RecordInfo_RecordInit, 405 RecordInfo_RecordClear, 406 RecordInfo_RecordCopy, 407 RecordInfo_GetGuid, 408 RecordInfo_GetName, 409 RecordInfo_GetSize, 410 RecordInfo_GetTypeInfo, 411 RecordInfo_GetField, 412 RecordInfo_GetFieldNoCopy, 413 RecordInfo_PutField, 414 RecordInfo_PutFieldNoCopy, 415 RecordInfo_GetFieldNames, 416 RecordInfo_IsMatchingType, 417 RecordInfo_RecordCreate, 418 RecordInfo_RecordCreateCopy, 419 RecordInfo_RecordDestroy 420 }; 421 422 static IRecordInfoImpl *get_test_recordinfo(void) 423 { 424 IRecordInfoImpl *rec; 425 426 rec = HeapAlloc(GetProcessHeap(), 0, sizeof(IRecordInfoImpl)); 427 rec->IRecordInfo_iface.lpVtbl = &RecordInfoVtbl; 428 rec->ref = 1; 429 rec->recordclear = 0; 430 rec->getsize = 0; 431 rec->recordcopy = 0; 432 433 return rec; 434 } 435 436 static void init(void) 437 { 438 BSTR bstr; 439 HRESULT res; 440 441 res = VarBstrFromBool(VARIANT_TRUE, LANG_USER_DEFAULT, VAR_LOCALBOOL, &bstr); 442 ok(res == S_OK && bstr[0], "Expected localized string for 'True'\n"); 443 /* lstrcpyW / lstrcatW do not work on win95 */ 444 memcpy(sz12_true, sz12, sizeof(sz12)); 445 if (bstr) memcpy(&sz12_true[2], bstr, SysStringByteLen(bstr) + sizeof(WCHAR)); 446 SysFreeString(bstr); 447 448 res = VarBstrFromBool(VARIANT_FALSE, LANG_USER_DEFAULT, VAR_LOCALBOOL, &bstr); 449 ok(res == S_OK && bstr[0], "Expected localized string for 'False'\n"); 450 memcpy(sz12_false, sz12, sizeof(sz12)); 451 if (bstr) memcpy(&sz12_false[2], bstr, SysStringByteLen(bstr) + sizeof(WCHAR)); 452 SysFreeString(bstr); 453 454 hOleaut32 = GetModuleHandleA("oleaut32.dll"); 455 has_i8 = GetProcAddress(hOleaut32, "VarI8FromI1") != NULL; 456 if (!has_i8) 457 skip("No support for I8 and UI8 data types\n"); 458 } 459 460 /* Functions to set a DECIMAL */ 461 static void setdec(DECIMAL* dec, BYTE scl, BYTE sgn, ULONG hi32, ULONG64 lo64) 462 { 463 S(U(*dec)).scale = scl; 464 S(U(*dec)).sign = sgn; 465 dec->Hi32 = hi32; 466 U1(*dec).Lo64 = lo64; 467 } 468 469 static void setdec64(DECIMAL* dec, BYTE scl, BYTE sgn, ULONG hi32, ULONG mid32, ULONG lo32) 470 { 471 S(U(*dec)).scale = scl; 472 S(U(*dec)).sign = sgn; 473 dec->Hi32 = hi32; 474 S1(U1(*dec)).Mid32 = mid32; 475 S1(U1(*dec)).Lo32 = lo32; 476 } 477 478 /* return the string text of a given variant type */ 479 static char vtstr_buffer[16][256]; 480 static int vtstr_current=0; 481 static const char *vtstr(int x) 482 { 483 switch(x) { 484 #define CASE(vt) case VT_##vt: return #vt 485 CASE(EMPTY); 486 CASE(NULL); 487 CASE(I2); 488 CASE(I4); 489 CASE(R4); 490 CASE(R8); 491 CASE(CY); 492 CASE(DATE); 493 CASE(BSTR); 494 CASE(DISPATCH); 495 CASE(ERROR); 496 CASE(BOOL); 497 CASE(VARIANT); 498 CASE(UNKNOWN); 499 CASE(DECIMAL); 500 CASE(I1); 501 CASE(UI1); 502 CASE(UI2); 503 CASE(UI4); 504 CASE(I8); 505 CASE(UI8); 506 CASE(INT); 507 CASE(UINT); 508 CASE(VOID); 509 CASE(HRESULT); 510 CASE(PTR); 511 CASE(SAFEARRAY); 512 CASE(CARRAY); 513 CASE(USERDEFINED); 514 CASE(LPSTR); 515 CASE(LPWSTR); 516 CASE(RECORD); 517 CASE(INT_PTR); 518 CASE(UINT_PTR); 519 CASE(FILETIME); 520 CASE(BLOB); 521 CASE(STREAM); 522 CASE(STORAGE); 523 CASE(STREAMED_OBJECT); 524 CASE(STORED_OBJECT); 525 CASE(BLOB_OBJECT); 526 CASE(CF); 527 CASE(CLSID); 528 CASE(VERSIONED_STREAM); 529 CASE(VECTOR); 530 CASE(ARRAY); 531 CASE(BYREF); 532 CASE(RESERVED); 533 CASE(ILLEGAL); 534 #undef CASE 535 536 case 0xfff: 537 return "VT_BSTR_BLOB/VT_ILLEGALMASKED/VT_TYPEMASK"; 538 539 default: 540 vtstr_current %= sizeof(vtstr_buffer)/sizeof(*vtstr_buffer); 541 sprintf(vtstr_buffer[vtstr_current], "unknown variant type %d", x); 542 return vtstr_buffer[vtstr_current++]; 543 } 544 } 545 546 static const char *variantstr( const VARIANT *var ) 547 { 548 vtstr_current %= sizeof(vtstr_buffer)/sizeof(*vtstr_buffer); 549 switch(V_VT(var)) 550 { 551 case VT_I1: 552 sprintf( vtstr_buffer[vtstr_current], "VT_I1(%d)", V_I1(var) ); break; 553 case VT_I2: 554 sprintf( vtstr_buffer[vtstr_current], "VT_I2(%d)", V_I2(var) ); break; 555 case VT_I4: 556 sprintf( vtstr_buffer[vtstr_current], "VT_I4(%d)", V_I4(var) ); break; 557 case VT_INT: 558 sprintf( vtstr_buffer[vtstr_current], "VT_INT(%d)", V_INT(var) ); break; 559 case VT_I8: 560 sprintf( vtstr_buffer[vtstr_current], "VT_I8(%x%08x)", (UINT)(V_I8(var) >> 32), (UINT)V_I8(var) ); break; 561 case VT_UI8: 562 sprintf( vtstr_buffer[vtstr_current], "VT_UI8(%x%08x)", (UINT)(V_UI8(var) >> 32), (UINT)V_UI8(var) ); break; 563 case VT_R4: 564 sprintf( vtstr_buffer[vtstr_current], "VT_R4(%g)", V_R4(var) ); break; 565 case VT_R8: 566 sprintf( vtstr_buffer[vtstr_current], "VT_R8(%g)", V_R8(var) ); break; 567 case VT_UI1: 568 sprintf( vtstr_buffer[vtstr_current], "VT_UI1(%u)", V_UI1(var) ); break; 569 case VT_UI2: 570 sprintf( vtstr_buffer[vtstr_current], "VT_UI2(%u)", V_UI2(var) ); break; 571 case VT_UI4: 572 sprintf( vtstr_buffer[vtstr_current], "VT_UI4(%u)", V_UI4(var) ); break; 573 case VT_UINT: 574 sprintf( vtstr_buffer[vtstr_current], "VT_UINT(%d)", V_UINT(var) ); break; 575 case VT_CY: 576 sprintf( vtstr_buffer[vtstr_current], "VT_CY(%x%08x)", S(V_CY(var)).Hi, S(V_CY(var)).Lo ); break; 577 case VT_DATE: 578 sprintf( vtstr_buffer[vtstr_current], "VT_DATE(%g)", V_DATE(var) ); break; 579 default: 580 return vtstr(V_VT(var)); 581 } 582 return vtstr_buffer[vtstr_current++]; 583 } 584 585 static BOOL is_expected_variant( const VARIANT *result, const VARIANT *expected ) 586 { 587 if (V_VT(result) != V_VT(expected)) return FALSE; 588 switch(V_VT(expected)) 589 { 590 case VT_EMPTY: 591 case VT_NULL: 592 return TRUE; 593 594 #define CASE(vt) case VT_##vt: return (V_##vt(result) == V_##vt(expected)) 595 CASE(BOOL); 596 CASE(I1); 597 CASE(UI1); 598 CASE(I2); 599 CASE(UI2); 600 CASE(I4); 601 CASE(UI4); 602 CASE(I8); 603 CASE(UI8); 604 CASE(INT); 605 CASE(UINT); 606 #undef CASE 607 608 case VT_DATE: 609 return EQ_FLOAT(V_DATE(result), V_DATE(expected)); 610 case VT_R4: 611 return EQ_FLOAT(V_R4(result), V_R4(expected)); 612 case VT_R8: 613 return EQ_FLOAT(V_R8(result), V_R8(expected)); 614 case VT_CY: 615 return (V_CY(result).int64 == V_CY(expected).int64); 616 case VT_BSTR: 617 return !lstrcmpW( V_BSTR(result), V_BSTR(expected) ); 618 case VT_DECIMAL: 619 return !memcmp( &V_DECIMAL(result), &V_DECIMAL(expected), sizeof(DECIMAL) ); 620 default: 621 ok(0, "unhandled variant type %s\n",vtstr(V_VT(expected))); 622 return FALSE; 623 } 624 } 625 626 static void test_var_call1( int line, HRESULT (WINAPI *func)(LPVARIANT,LPVARIANT), 627 VARIANT *arg, VARIANT *expected ) 628 { 629 VARIANT old_arg = *arg; 630 VARIANT result; 631 HRESULT hres; 632 633 memset( &result, 0, sizeof(result) ); 634 hres = func( arg, &result ); 635 ok_(__FILE__,line)( hres == S_OK, "wrong result %x\n", hres ); 636 if (hres == S_OK) 637 ok_(__FILE__,line)( is_expected_variant( &result, expected ), 638 "got %s expected %s\n", variantstr(&result), variantstr(expected) ); 639 ok_(__FILE__,line)( is_expected_variant( arg, &old_arg ), "Modified argument %s / %s\n", 640 variantstr(&old_arg), variantstr(arg)); 641 VariantClear( &result ); 642 } 643 644 static void test_var_call2( int line, HRESULT (WINAPI *func)(LPVARIANT,LPVARIANT,LPVARIANT), 645 VARIANT *left, VARIANT *right, VARIANT *expected ) 646 { 647 VARIANT old_left = *left, old_right = *right; 648 VARIANT result; 649 HRESULT hres; 650 651 memset( &result, 0, sizeof(result) ); 652 hres = func( left, right, &result ); 653 ok_(__FILE__,line)( hres == S_OK, "wrong result %x\n", hres ); 654 if (hres == S_OK) 655 ok_(__FILE__,line)( is_expected_variant( &result, expected ), 656 "got %s expected %s\n", variantstr(&result), variantstr(expected) ); 657 ok_(__FILE__,line)( is_expected_variant( left, &old_left ), "Modified left argument %s / %s\n", 658 variantstr(&old_left), variantstr(left)); 659 ok_(__FILE__,line)( is_expected_variant( right, &old_right ), "Modified right argument %s / %s\n", 660 variantstr(&old_right), variantstr(right)); 661 VariantClear( &result ); 662 } 663 664 static int strcmp_wa(const WCHAR *strw, const char *stra) 665 { 666 WCHAR buf[512]; 667 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(buf[0])); 668 return lstrcmpW(strw, buf); 669 } 670 671 #define test_bstr_var(a,b) _test_bstr_var(__LINE__,a,b) 672 static void _test_bstr_var(unsigned line, const VARIANT *v, const char *str) 673 { 674 ok_(__FILE__,line)(V_VT(v) == VT_BSTR, "unexpected vt=%d\n", V_VT(v)); 675 if(V_VT(v) == VT_BSTR) 676 ok(!strcmp_wa(V_BSTR(v), str), "v=%s, expected %s\n", wine_dbgstr_w(V_BSTR(v)), str); 677 } 678 679 static void test_VariantInit(void) 680 { 681 VARIANT v; 682 683 memset(&v, -1, sizeof(v)); 684 VariantInit(&v); 685 ok(V_VT(&v) == VT_EMPTY, "VariantInit() returned vt %d\n", V_VT(&v)); 686 } 687 688 /* All possible combinations of extra V_VT() flags */ 689 static const VARTYPE ExtraFlags[16] = 690 { 691 0, 692 VT_VECTOR, 693 VT_ARRAY, 694 VT_BYREF, 695 VT_RESERVED, 696 VT_VECTOR|VT_ARRAY, 697 VT_VECTOR|VT_BYREF, 698 VT_VECTOR|VT_RESERVED, 699 VT_VECTOR|VT_ARRAY|VT_BYREF, 700 VT_VECTOR|VT_ARRAY|VT_RESERVED, 701 VT_VECTOR|VT_BYREF|VT_RESERVED, 702 VT_VECTOR|VT_ARRAY|VT_BYREF|VT_RESERVED, 703 VT_ARRAY|VT_BYREF, 704 VT_ARRAY|VT_RESERVED, 705 VT_ARRAY|VT_BYREF|VT_RESERVED, 706 VT_BYREF|VT_RESERVED, 707 }; 708 709 /* Determine if a vt is valid for VariantClear() */ 710 static BOOL IsValidVariantClearVT(VARTYPE vt, VARTYPE extraFlags) 711 { 712 BOOL ret = FALSE; 713 714 /* Only the following flags/types are valid */ 715 if ((vt <= VT_LPWSTR || vt == VT_RECORD || vt == VT_CLSID) && 716 vt != (VARTYPE)15 && 717 (vt < (VARTYPE)24 || vt > (VARTYPE)31) && 718 (!(extraFlags & (VT_BYREF|VT_ARRAY)) || vt > VT_NULL) && 719 (extraFlags == 0 || extraFlags == VT_BYREF || extraFlags == VT_ARRAY || 720 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 return ret; 726 } 727 728 typedef struct 729 { 730 IUnknown IUnknown_iface; 731 LONG ref; 732 LONG events; 733 } test_VariantClearImpl; 734 735 static inline test_VariantClearImpl *impl_from_IUnknown(IUnknown *iface) 736 { 737 return CONTAINING_RECORD(iface, test_VariantClearImpl, IUnknown_iface); 738 } 739 740 static HRESULT WINAPI VC_QueryInterface(LPUNKNOWN iface,REFIID riid,LPVOID *ppobj) 741 { 742 test_VariantClearImpl *This = impl_from_IUnknown(iface); 743 This->events |= 0x1; 744 return E_NOINTERFACE; 745 } 746 747 static ULONG WINAPI VC_AddRef(LPUNKNOWN iface) { 748 test_VariantClearImpl *This = impl_from_IUnknown(iface); 749 This->events |= 0x2; 750 return InterlockedIncrement(&This->ref); 751 } 752 753 static ULONG WINAPI VC_Release(LPUNKNOWN iface) { 754 test_VariantClearImpl *This = impl_from_IUnknown(iface); 755 /* static class, won't be freed */ 756 This->events |= 0x4; 757 return InterlockedDecrement(&This->ref); 758 } 759 760 static const IUnknownVtbl test_VariantClear_vtbl = { 761 VC_QueryInterface, 762 VC_AddRef, 763 VC_Release, 764 }; 765 766 static test_VariantClearImpl test_myVariantClearImpl = {{&test_VariantClear_vtbl}, 1, 0}; 767 768 static void test_VariantClear(void) 769 { 770 struct __tagBRECORD *rec; 771 IRecordInfoImpl *recinfo; 772 HRESULT hres; 773 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 if (0) 781 VariantClear(NULL); 782 783 /* Only the type field is set, to VT_EMPTY */ 784 V_VT(&v) = VT_UI4; 785 V_UI4(&v) = ~0u; 786 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 ok(V_UI4(&v) == ~0u, "VariantClear: Overwrote value\n"); 790 791 /* Test all possible V_VT values. 792 * Also demonstrates that null pointers in 'v' are not dereferenced. 793 * Individual variant tests should test VariantClear() with non-NULL values. 794 */ 795 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 796 { 797 VARTYPE vt; 798 799 for (vt = 0; vt <= VT_BSTR_BLOB; vt++) 800 { 801 HRESULT hExpected = DISP_E_BADVARTYPE; 802 803 SKIPTESTS(vt); 804 805 memset(&v, 0, sizeof(v)); 806 V_VT(&v) = vt | ExtraFlags[i]; 807 808 hres = VariantClear(&v); 809 810 if (IsValidVariantClearVT(vt, ExtraFlags[i])) 811 hExpected = S_OK; 812 813 ok(hres == hExpected, "VariantClear: expected 0x%X, got 0x%X for vt %d | 0x%X\n", 814 hExpected, hres, vt, ExtraFlags[i]); 815 } 816 } 817 818 /* Some BYREF tests with non-NULL ptrs */ 819 820 /* VARIANT BYREF */ 821 V_VT(&v2) = VT_I4; 822 V_I4(&v2) = 0x1234; 823 V_VT(&v) = VT_VARIANT | VT_BYREF; 824 V_VARIANTREF(&v) = &v2; 825 826 hres = VariantClear(&v); 827 ok(hres == S_OK, "ret %08x\n", hres); 828 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v)); 829 ok(V_VARIANTREF(&v) == &v2, "variant ref %p\n", V_VARIANTREF(&v2)); 830 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 /* I4 BYREF */ 834 i4 = 0x4321; 835 V_VT(&v) = VT_I4 | VT_BYREF; 836 V_I4REF(&v) = &i4; 837 838 hres = VariantClear(&v); 839 ok(hres == S_OK, "ret %08x\n", hres); 840 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v)); 841 ok(V_I4REF(&v) == &i4, "i4 ref %p\n", V_I4REF(&v2)); 842 ok(i4 == 0x4321, "i4 changed %08x\n", i4); 843 844 845 /* UNKNOWN */ 846 V_VT(&v) = VT_UNKNOWN; 847 V_UNKNOWN(&v) = &test_myVariantClearImpl.IUnknown_iface; 848 test_myVariantClearImpl.events = 0; 849 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 V_VT(&v) = VT_UNKNOWN | VT_BYREF; 859 V_UNKNOWNREF(&v) = &punk; 860 test_myVariantClearImpl.events = 0; 861 hres = VariantClear(&v); 862 ok(hres == S_OK, "ret %08x\n", hres); 863 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v)); 864 ok(V_UNKNOWNREF(&v) == &punk, "unknown ref %p\n", V_UNKNOWNREF(&v)); 865 /* Check that nothing got called */ 866 ok(test_myVariantClearImpl.events == 0, "Unexpected call. events %08x\n", test_myVariantClearImpl.events); 867 868 /* DISPATCH */ 869 V_VT(&v) = VT_DISPATCH; 870 V_DISPATCH(&v) = (IDispatch*)&test_myVariantClearImpl.IUnknown_iface; 871 test_myVariantClearImpl.events = 0; 872 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 ok(V_DISPATCH(&v) == (IDispatch*)&test_myVariantClearImpl.IUnknown_iface, 876 "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 V_VT(&v) = VT_DISPATCH | VT_BYREF; 883 V_DISPATCHREF(&v) = (IDispatch**)&punk; 884 test_myVariantClearImpl.events = 0; 885 hres = VariantClear(&v); 886 ok(hres == S_OK, "ret %08x\n", hres); 887 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v)); 888 ok(V_DISPATCHREF(&v) == (IDispatch**)&punk, "dispatch ref %p\n", V_DISPATCHREF(&v)); 889 /* Check that nothing got called */ 890 ok(test_myVariantClearImpl.events == 0, "Unexpected call. events %08x\n", test_myVariantClearImpl.events); 891 892 /* RECORD */ 893 recinfo = get_test_recordinfo(); 894 V_VT(&v) = VT_RECORD; 895 rec = &V_UNION(&v, brecVal); 896 rec->pRecInfo = &recinfo->IRecordInfo_iface; 897 rec->pvRecord = (void*)0xdeadbeef; 898 recinfo->recordclear = 0; 899 recinfo->ref = 2; 900 recinfo->rec = rec; 901 hres = VariantClear(&v); 902 ok(hres == S_OK, "ret %08x\n", hres); 903 ok(rec->pvRecord == NULL, "got %p\n", rec->pvRecord); 904 ok(recinfo->recordclear == 1, "got %d\n", recinfo->recordclear); 905 ok(recinfo->ref == 1, "got %d\n", recinfo->ref); 906 IRecordInfo_Release(&recinfo->IRecordInfo_iface); 907 } 908 909 static void test_VariantCopy(void) 910 { 911 struct __tagBRECORD *rec; 912 IRecordInfoImpl *recinfo; 913 VARIANTARG vSrc, vDst; 914 VARTYPE vt; 915 size_t i; 916 HRESULT hres, hExpected; 917 918 /* Establish that the failure/other cases are dealt with. Individual tests 919 * for each type should verify that data is copied correctly, references 920 * are updated, etc. 921 */ 922 923 /* vSrc == vDst */ 924 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 925 { 926 for (vt = 0; vt <= VT_BSTR_BLOB; vt++) 927 { 928 SKIPTESTS(vt); 929 930 memset(&vSrc, 0, sizeof(vSrc)); 931 V_VT(&vSrc) = vt | ExtraFlags[i]; 932 933 hExpected = DISP_E_BADVARTYPE; 934 /* src is allowed to be a VT_CLSID */ 935 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i])) 936 hExpected = S_OK; 937 938 hres = VariantCopy(&vSrc, &vSrc); 939 940 ok(hres == hExpected, 941 "Copy(src==dst): expected 0x%X, got 0x%X for src==dest vt %d|0x%X\n", 942 hExpected, hres, vt, ExtraFlags[i]); 943 } 944 } 945 946 /* Test that if VariantClear() fails on dest, the function fails. This also 947 * shows that dest is in fact cleared and not just overwritten 948 */ 949 memset(&vSrc, 0, sizeof(vSrc)); 950 V_VT(&vSrc) = VT_UI1; 951 952 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 953 { 954 for (vt = 0; vt <= VT_BSTR_BLOB; vt++) 955 { 956 SKIPTESTS(vt); 957 958 hExpected = DISP_E_BADVARTYPE; 959 960 memset(&vDst, 0, sizeof(vDst)); 961 V_VT(&vDst) = vt | ExtraFlags[i]; 962 963 if (IsValidVariantClearVT(vt, ExtraFlags[i])) 964 hExpected = S_OK; 965 966 hres = VariantCopy(&vDst, &vSrc); 967 968 ok(hres == hExpected, 969 "Copy(bad dst): expected 0x%X, got 0x%X for dest vt %d|0x%X\n", 970 hExpected, hres, vt, ExtraFlags[i]); 971 if (hres == S_OK) 972 ok(V_VT(&vDst) == VT_UI1, 973 "Copy(bad dst): expected vt = VT_UI1, got %d\n", V_VT(&vDst)); 974 } 975 } 976 977 /* Test that VariantClear() checks vSrc for validity before copying */ 978 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 979 { 980 for (vt = 0; vt <= VT_BSTR_BLOB; vt++) 981 { 982 SKIPTESTS(vt); 983 984 hExpected = DISP_E_BADVARTYPE; 985 986 memset(&vDst, 0, sizeof(vDst)); 987 V_VT(&vDst) = VT_EMPTY; 988 989 memset(&vSrc, 0, sizeof(vSrc)); 990 V_VT(&vSrc) = vt | ExtraFlags[i]; 991 992 /* src is allowed to be a VT_CLSID */ 993 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i])) 994 hExpected = S_OK; 995 996 hres = VariantCopy(&vDst, &vSrc); 997 998 ok(hres == hExpected, 999 "Copy(bad src): expected 0x%X, got 0x%X for src vt %d|0x%X\n", 1000 hExpected, hres, vt, ExtraFlags[i]); 1001 if (hres == S_OK) 1002 { 1003 ok(V_VT(&vDst) == (vt|ExtraFlags[i]), 1004 "Copy(bad src): expected vt = %d, got %d\n", 1005 vt | ExtraFlags[i], V_VT(&vDst)); 1006 VariantClear(&vDst); 1007 } 1008 } 1009 } 1010 1011 /* Test that copying a NULL BSTR results in an empty BSTR */ 1012 memset(&vDst, 0, sizeof(vDst)); 1013 V_VT(&vDst) = VT_EMPTY; 1014 memset(&vSrc, 0, sizeof(vSrc)); 1015 V_VT(&vSrc) = VT_BSTR; 1016 hres = VariantCopy(&vDst, &vSrc); 1017 ok(hres == S_OK, "Copy(NULL BSTR): Failed to copy a NULL BSTR\n"); 1018 if (hres == S_OK) 1019 { 1020 ok((V_VT(&vDst) == VT_BSTR) && V_BSTR(&vDst), 1021 "Copy(NULL BSTR): should have non-NULL result\n"); 1022 if ((V_VT(&vDst) == VT_BSTR) && V_BSTR(&vDst)) 1023 { 1024 ok(*V_BSTR(&vDst) == 0, "Copy(NULL BSTR): result not empty\n"); 1025 } 1026 VariantClear(&vDst); 1027 } 1028 1029 /* copy RECORD */ 1030 recinfo = get_test_recordinfo(); 1031 1032 memset(&vDst, 0, sizeof(vDst)); 1033 V_VT(&vDst) = VT_EMPTY; 1034 1035 V_VT(&vSrc) = VT_RECORD; 1036 rec = &V_UNION(&vSrc, brecVal); 1037 rec->pRecInfo = &recinfo->IRecordInfo_iface; 1038 rec->pvRecord = (void*)0xdeadbeef; 1039 1040 recinfo->recordclear = 0; 1041 recinfo->recordcopy = 0; 1042 recinfo->getsize = 0; 1043 recinfo->rec = rec; 1044 hres = VariantCopy(&vDst, &vSrc); 1045 ok(hres == S_OK, "ret %08x\n", hres); 1046 1047 rec = &V_UNION(&vDst, brecVal); 1048 ok(rec->pvRecord != (void*)0xdeadbeef && rec->pvRecord != NULL, "got %p\n", rec->pvRecord); 1049 ok(rec->pRecInfo == &recinfo->IRecordInfo_iface, "got %p\n", rec->pRecInfo); 1050 ok(recinfo->getsize == 1, "got %d\n", recinfo->recordclear); 1051 ok(recinfo->recordcopy == 1, "got %d\n", recinfo->recordclear); 1052 1053 VariantClear(&vDst); 1054 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 if ((extraFlags & VT_ARRAY) || 1063 (vt > VT_NULL && vt != (VARTYPE)15 && vt < VT_VOID && 1064 !(extraFlags & (VT_VECTOR|VT_RESERVED)))) 1065 { 1066 ret = TRUE; /* ok */ 1067 } 1068 return ret; 1069 } 1070 1071 static void test_VariantCopyInd(void) 1072 { 1073 VARIANTARG vSrc, vDst, vRef, vRef2; 1074 VARTYPE vt; 1075 size_t i; 1076 BYTE buffer[64]; 1077 HRESULT hres, hExpected; 1078 1079 memset(buffer, 0, sizeof(buffer)); 1080 1081 /* vSrc == vDst */ 1082 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 1083 { 1084 if (ExtraFlags[i] & VT_ARRAY) 1085 continue; /* Native crashes on NULL safearray */ 1086 1087 for (vt = 0; vt <= VT_BSTR_BLOB; vt++) 1088 { 1089 SKIPTESTS(vt); 1090 1091 memset(&vSrc, 0, sizeof(vSrc)); 1092 V_VT(&vSrc) = vt | ExtraFlags[i]; 1093 1094 hExpected = DISP_E_BADVARTYPE; 1095 if (!(ExtraFlags[i] & VT_BYREF)) 1096 { 1097 /* if src is not by-reference, acts as VariantCopy() */ 1098 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i])) 1099 hExpected = S_OK; 1100 } 1101 else 1102 { 1103 if (vt == VT_SAFEARRAY || vt == VT_BSTR || vt == VT_UNKNOWN || 1104 vt == VT_DISPATCH || vt == VT_RECORD) 1105 continue; /* Need valid ptrs for deep copies */ 1106 1107 V_BYREF(&vSrc) = &buffer; 1108 hExpected = E_INVALIDARG; 1109 1110 if ((vt == VT_I8 || vt == VT_UI8) && 1111 ExtraFlags[i] == VT_BYREF) 1112 { 1113 if (has_i8) 1114 hExpected = S_OK; /* Only valid if I8 is a known type */ 1115 } 1116 else if (IsValidVariantCopyIndVT(vt, ExtraFlags[i])) 1117 hExpected = S_OK; 1118 } 1119 1120 hres = VariantCopyInd(&vSrc, &vSrc); 1121 1122 ok(hres == hExpected, 1123 "CopyInd(src==dst): expected 0x%X, got 0x%X for src==dst vt %d|0x%X\n", 1124 hExpected, hres, vt, ExtraFlags[i]); 1125 } 1126 } 1127 1128 /* Bad dest */ 1129 memset(&vSrc, 0, sizeof(vSrc)); 1130 V_VT(&vSrc) = VT_UI1|VT_BYREF; 1131 V_BYREF(&vSrc) = &buffer; 1132 1133 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 1134 { 1135 for (vt = 0; vt <= VT_BSTR_BLOB; vt++) 1136 { 1137 SKIPTESTS(vt); 1138 1139 memset(&vDst, 0, sizeof(vDst)); 1140 V_VT(&vDst) = vt | ExtraFlags[i]; 1141 1142 hExpected = DISP_E_BADVARTYPE; 1143 1144 if (IsValidVariantClearVT(vt, ExtraFlags[i])) 1145 hExpected = S_OK; 1146 1147 hres = VariantCopyInd(&vDst, &vSrc); 1148 1149 ok(hres == hExpected, 1150 "CopyInd(bad dst): expected 0x%X, got 0x%X for dst vt %d|0x%X\n", 1151 hExpected, hres, vt, ExtraFlags[i]); 1152 if (hres == S_OK) 1153 ok(V_VT(&vDst) == VT_UI1, 1154 "CopyInd(bad dst): expected vt = VT_UI1, got %d\n", V_VT(&vDst)); 1155 } 1156 } 1157 1158 /* bad src */ 1159 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 1160 { 1161 if (ExtraFlags[i] & VT_ARRAY) 1162 continue; /* Native crashes on NULL safearray */ 1163 1164 for (vt = 0; vt <= VT_BSTR_BLOB; vt++) 1165 { 1166 SKIPTESTS(vt); 1167 1168 memset(&vDst, 0, sizeof(vDst)); 1169 V_VT(&vDst) = VT_EMPTY; 1170 1171 memset(&vSrc, 0, sizeof(vSrc)); 1172 V_VT(&vSrc) = vt | ExtraFlags[i]; 1173 1174 hExpected = DISP_E_BADVARTYPE; 1175 if (!(ExtraFlags[i] & VT_BYREF)) 1176 { 1177 /* if src is not by-reference, acts as VariantCopy() */ 1178 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i])) 1179 hExpected = S_OK; 1180 } 1181 else 1182 { 1183 if (vt == VT_SAFEARRAY || vt == VT_BSTR || vt == VT_UNKNOWN || 1184 vt == VT_DISPATCH || vt == VT_RECORD) 1185 continue; /* Need valid ptrs for deep copies, see vartype.c */ 1186 1187 V_BYREF(&vSrc) = &buffer; 1188 1189 hExpected = E_INVALIDARG; 1190 1191 if ((vt == VT_I8 || vt == VT_UI8) && 1192 ExtraFlags[i] == VT_BYREF) 1193 { 1194 if (has_i8) 1195 hExpected = S_OK; /* Only valid if I8 is a known type */ 1196 } 1197 else if (IsValidVariantCopyIndVT(vt, ExtraFlags[i])) 1198 hExpected = S_OK; 1199 } 1200 1201 hres = VariantCopyInd(&vDst, &vSrc); 1202 1203 ok(hres == hExpected, 1204 "CopyInd(bad src): expected 0x%X, got 0x%X for src vt %d|0x%X\n", 1205 hExpected, hres, vt, ExtraFlags[i]); 1206 if (hres == S_OK) 1207 { 1208 if (vt == VT_VARIANT && ExtraFlags[i] == VT_BYREF) 1209 { 1210 /* Type of vDst should be the type of the referenced variant. 1211 * Since we set the buffer to all zeros, its type should be 1212 * VT_EMPTY. 1213 */ 1214 ok(V_VT(&vDst) == VT_EMPTY, 1215 "CopyInd(bad src): expected dst vt = VT_EMPTY, got %d|0x%X\n", 1216 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK); 1217 } 1218 else 1219 { 1220 ok(V_VT(&vDst) == (vt|(ExtraFlags[i] & ~VT_BYREF)), 1221 "CopyInd(bad src): expected dst vt = %d|0x%X, got %d|0x%X\n", 1222 vt, ExtraFlags[i] & ~VT_BYREF, 1223 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK); 1224 } 1225 VariantClear(&vDst); 1226 } 1227 } 1228 } 1229 1230 /* By-reference variants are dereferenced */ 1231 V_VT(&vRef) = VT_UI1; 1232 V_UI1(&vRef) = 0x77; 1233 V_VT(&vSrc) = VT_VARIANT|VT_BYREF; 1234 V_VARIANTREF(&vSrc) = &vRef; 1235 VariantInit(&vDst); 1236 1237 hres = VariantCopyInd(&vDst, &vSrc); 1238 ok(hres == S_OK, "VariantCopyInd failed: 0x%08x\n", hres); 1239 ok(V_VT(&vDst) == VT_UI1 && V_UI1(&vDst) == 0x77, 1240 "CopyInd(deref): expected dst vt = VT_UI1, val 0x77, got %d|0x%X, 0x%2X\n", 1241 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK, V_UI1(&vDst)); 1242 1243 /* By-reference variant to a by-reference type succeeds */ 1244 V_VT(&vRef) = VT_UI1|VT_BYREF; 1245 V_UI1REF(&vRef) = buffer; buffer[0] = 0x88; 1246 V_VT(&vSrc) = VT_VARIANT|VT_BYREF; 1247 V_VARIANTREF(&vSrc) = &vRef; 1248 VariantInit(&vDst); 1249 1250 hres = VariantCopyInd(&vDst, &vSrc); 1251 ok(hres == S_OK, "VariantCopyInd failed: 0x%08x\n", hres); 1252 ok(V_VT(&vDst) == VT_UI1 && V_UI1(&vDst) == 0x88, 1253 "CopyInd(deref): expected dst vt = VT_UI1, val 0x77, got %d|0x%X, 0x%2X\n", 1254 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK, V_UI1(&vDst)); 1255 1256 /* But a by-reference variant to a by-reference variant fails */ 1257 V_VT(&vRef2) = VT_UI1; 1258 V_UI1(&vRef2) = 0x77; 1259 V_VT(&vRef) = VT_VARIANT|VT_BYREF; 1260 V_VARIANTREF(&vRef) = &vRef2; 1261 V_VT(&vSrc) = VT_VARIANT|VT_BYREF; 1262 V_VARIANTREF(&vSrc) = &vRef; 1263 VariantInit(&vDst); 1264 1265 hres = VariantCopyInd(&vDst, &vSrc); 1266 ok(hres == E_INVALIDARG, 1267 "CopyInd(ref->ref): expected E_INVALIDARG, got 0x%08x\n", hres); 1268 } 1269 1270 static HRESULT (WINAPI *pVarParseNumFromStr)(OLECHAR*,LCID,ULONG,NUMPARSE*,BYTE*); 1271 1272 /* Macros for converting and testing the result of VarParseNumFromStr */ 1273 #define FAILDIG 255 1274 1275 static HRESULT convert_str( const char *str, INT dig, ULONG flags, 1276 NUMPARSE *np, BYTE rgb[128], LCID lcid ) 1277 { 1278 OLECHAR buff[128]; 1279 MultiByteToWideChar( CP_ACP,0, str, -1, buff, sizeof(buff)/sizeof(WCHAR) ); 1280 memset( rgb, FAILDIG, 128 ); 1281 memset( np, 255, sizeof(*np) ); 1282 np->cDig = dig; 1283 np->dwInFlags = flags; 1284 return pVarParseNumFromStr( buff, lcid, LOCALE_NOUSEROVERRIDE, np, rgb); 1285 } 1286 1287 static void expect_NumFromStr( int line, HRESULT hres, NUMPARSE *np, INT a, ULONG b, ULONG c, 1288 INT d, INT e, INT f ) 1289 { 1290 if (hres == (HRESULT)S_OK) 1291 { 1292 ok_(__FILE__,line)(np->cDig == a, "Expected cDig = %d, got %d\n", a, np->cDig); 1293 ok_(__FILE__,line)(np->dwInFlags == b, "Expected dwInFlags = 0x%x, got 0x%x\n", b, np->dwInFlags); 1294 ok_(__FILE__,line)(np->dwOutFlags == c, "Expected dwOutFlags = 0x%x, got 0x%x\n", c, np->dwOutFlags); 1295 ok_(__FILE__,line)(np->cchUsed == d, "Expected cchUsed = %d, got %d\n", d, np->cchUsed); 1296 ok_(__FILE__,line)(np->nBaseShift == e, "Expected nBaseShift = %d, got %d\n", e, np->nBaseShift); 1297 ok_(__FILE__,line)(np->nPwr10 == f, "Expected nPwr10 = %d, got %d\n", f, np->nPwr10); 1298 } 1299 } 1300 1301 #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 #define EXPECT2(a,b) EXPECTRGB(0,a); EXPECTRGB(1,b) 1307 1308 static void test_VarParseNumFromStr(void) 1309 { 1310 HRESULT hres; 1311 /* Ensure all tests are using the same locale characters for '$', ',' etc */ 1312 LCID lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT); 1313 NUMPARSE np; 1314 BYTE rgb[128]; 1315 1316 /** No flags **/ 1317 1318 CHECKPTR(VarParseNumFromStr); 1319 1320 /* Consume a single digit */ 1321 CONVERT("7", 0); 1322 EXPECT(1,0,0,1,0,0); 1323 EXPECT2(7,FAILDIG); 1324 1325 /* cDig is not literal digits - zeros are suppressed and nPwr10 is increased */ 1326 CONVERT("10", 0); 1327 EXPECT(1,0,0,2,0,1); 1328 /* Note: Win32 writes the trailing zeros if they are within cDig's limits, 1329 * but then excludes them from the returned cDig count. 1330 * In our implementation we don't bother writing them at all. 1331 */ 1332 EXPECTRGB(0, 1); 1333 1334 /* if cDig is too small and numbers follow, sets INEXACT */ 1335 CONVERTN("11",1, 0); 1336 EXPECT(1,0,NUMPRS_INEXACT,2,0,1); 1337 EXPECT2(1,FAILDIG); 1338 1339 /* Strips leading zeros */ 1340 CONVERT("01", 0); 1341 EXPECT(1,0,0,2,0,0); 1342 EXPECT2(1,FAILDIG); 1343 1344 /* Strips leading zeros */ 1345 CONVERTN("01",1, 0); 1346 EXPECT(1,0,0,2,0,0); 1347 EXPECT2(1,FAILDIG); 1348 1349 1350 /* Fails on non digits */ 1351 CONVERT("a", 0); 1352 EXPECTFAIL; 1353 EXPECTRGB(0,FAILDIG); 1354 1355 /** NUMPRS_LEADING_WHITE/NUMPRS_TRAILING_WHITE **/ 1356 1357 /* Without flag, fails on whitespace */ 1358 CONVERT(" 0", 0); 1359 EXPECTFAIL; 1360 EXPECTRGB(0,FAILDIG); 1361 1362 1363 /* With flag, consumes whitespace */ 1364 CONVERT(" 0", NUMPRS_LEADING_WHITE); 1365 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0); 1366 EXPECT2(0,FAILDIG); 1367 1368 /* Test TAB once, then assume it acts as space for all cases */ 1369 CONVERT("\t0", NUMPRS_LEADING_WHITE); 1370 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0); 1371 EXPECT2(0,FAILDIG); 1372 1373 1374 /* Doesn't pick up trailing whitespace without flag */ 1375 CONVERT("0 ", 0); 1376 EXPECT(1,0,0,1,0,0); 1377 EXPECT2(0,FAILDIG); 1378 1379 /* With flag, consumes trailing whitespace */ 1380 CONVERT("0 ", NUMPRS_TRAILING_WHITE); 1381 EXPECT(1,NUMPRS_TRAILING_WHITE,NUMPRS_TRAILING_WHITE,2,0,0); 1382 EXPECT2(0,FAILDIG); 1383 1384 /* Leading flag only consumes leading */ 1385 CONVERT(" 0 ", NUMPRS_LEADING_WHITE); 1386 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0); 1387 EXPECT2(0,FAILDIG); 1388 1389 /* Both flags consumes both */ 1390 CONVERT(" 0 ", NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE); 1391 EXPECT(1,NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE,NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE,3,0,0); 1392 EXPECT2(0,FAILDIG); 1393 1394 /** NUMPRS_LEADING_PLUS/NUMPRS_TRAILING_PLUS **/ 1395 1396 /* Without flag, fails on + */ 1397 CONVERT("+0", 0); 1398 EXPECTFAIL; 1399 EXPECTRGB(0,FAILDIG); 1400 1401 /* With flag, consumes + */ 1402 CONVERT("+0", NUMPRS_LEADING_PLUS); 1403 EXPECT(1,NUMPRS_LEADING_PLUS,NUMPRS_LEADING_PLUS,2,0,0); 1404 EXPECT2(0,FAILDIG); 1405 1406 /* Without flag, doesn't consume trailing + */ 1407 CONVERT("0+", 0); 1408 EXPECT(1,0,0,1,0,0); 1409 EXPECT2(0,FAILDIG); 1410 1411 /* With flag, consumes trailing + */ 1412 CONVERT("0+", NUMPRS_TRAILING_PLUS); 1413 EXPECT(1,NUMPRS_TRAILING_PLUS,NUMPRS_TRAILING_PLUS,2,0,0); 1414 EXPECT2(0,FAILDIG); 1415 1416 /* With leading flag, doesn't consume trailing + */ 1417 CONVERT("+0+", NUMPRS_LEADING_PLUS); 1418 EXPECT(1,NUMPRS_LEADING_PLUS,NUMPRS_LEADING_PLUS,2,0,0); 1419 EXPECT2(0,FAILDIG); 1420 1421 /* Trailing + doesn't get consumed if we specify both (unlike whitespace) */ 1422 CONVERT("+0+", NUMPRS_LEADING_PLUS|NUMPRS_TRAILING_PLUS); 1423 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_TRAILING_PLUS,NUMPRS_LEADING_PLUS,2,0,0); 1424 EXPECT2(0,FAILDIG); 1425 1426 /** NUMPRS_LEADING_MINUS/NUMPRS_TRAILING_MINUS **/ 1427 1428 /* Without flag, fails on - */ 1429 CONVERT("-0", 0); 1430 EXPECTFAIL; 1431 EXPECTRGB(0,FAILDIG); 1432 1433 /* With flag, consumes - */ 1434 CONVERT("-0", NUMPRS_LEADING_MINUS); 1435 EXPECT(1,NUMPRS_LEADING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0); 1436 EXPECT2(0,FAILDIG); 1437 1438 /* Without flag, doesn't consume trailing - */ 1439 CONVERT("0-", 0); 1440 EXPECT(1,0,0,1,0,0); 1441 EXPECT2(0,FAILDIG); 1442 1443 /* With flag, consumes trailing - */ 1444 CONVERT("0-", NUMPRS_TRAILING_MINUS); 1445 EXPECT(1,NUMPRS_TRAILING_MINUS,NUMPRS_NEG|NUMPRS_TRAILING_MINUS,2,0,0); 1446 EXPECT2(0,FAILDIG); 1447 1448 /* With leading flag, doesn't consume trailing - */ 1449 CONVERT("-0-", NUMPRS_LEADING_MINUS); 1450 EXPECT(1,NUMPRS_LEADING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0); 1451 EXPECT2(0,FAILDIG); 1452 1453 /* Trailing - doesn't get consumed if we specify both (unlike whitespace) */ 1454 CONVERT("-0-", NUMPRS_LEADING_MINUS|NUMPRS_TRAILING_MINUS); 1455 EXPECT(1,NUMPRS_LEADING_MINUS|NUMPRS_TRAILING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0); 1456 EXPECT2(0,FAILDIG); 1457 1458 /** NUMPRS_HEX_OCT **/ 1459 1460 /* Could be hex, octal or decimal - With flag reads as decimal */ 1461 CONVERT("0", NUMPRS_HEX_OCT); 1462 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0); 1463 EXPECT2(0,FAILDIG); 1464 1465 /* Doesn't recognise hex in .asm syntax */ 1466 CONVERT("0h", NUMPRS_HEX_OCT); 1467 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0); 1468 EXPECT2(0,FAILDIG); 1469 1470 /* Doesn't fail with valid leading string but no digits */ 1471 CONVERT("0x", NUMPRS_HEX_OCT); 1472 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0); 1473 EXPECT2(0,FAILDIG); 1474 1475 /* Doesn't recognise hex format numbers at all! */ 1476 CONVERT("0x0", NUMPRS_HEX_OCT); 1477 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0); 1478 EXPECT2(0,FAILDIG); 1479 1480 /* Doesn't recognise plain hex digits either */ 1481 CONVERT("FE", NUMPRS_HEX_OCT); 1482 EXPECTFAIL; 1483 EXPECTRGB(0,FAILDIG); 1484 1485 /* Octal */ 1486 CONVERT("0100", NUMPRS_HEX_OCT); 1487 EXPECT(1,NUMPRS_HEX_OCT,0,4,0,2); 1488 EXPECTRGB(0,1); 1489 EXPECTRGB(1,0); 1490 EXPECTRGB(2,0); 1491 EXPECTRGB(3,FAILDIG); 1492 1493 /* VB hex */ 1494 CONVERT("&HF800", NUMPRS_HEX_OCT); 1495 EXPECT(4,NUMPRS_HEX_OCT,0x40,6,4,0); 1496 EXPECTRGB(0,15); 1497 EXPECTRGB(1,8); 1498 EXPECTRGB(2,0); 1499 EXPECTRGB(3,0); 1500 EXPECTRGB(4,FAILDIG); 1501 1502 /* VB hex lower case and leading zero */ 1503 CONVERT("&h0abcdef", NUMPRS_HEX_OCT); 1504 EXPECT(6,NUMPRS_HEX_OCT,0x40,9,4,0); 1505 EXPECTRGB(0,10); 1506 EXPECTRGB(1,11); 1507 EXPECTRGB(2,12); 1508 EXPECTRGB(3,13); 1509 EXPECTRGB(4,14); 1510 EXPECTRGB(5,15); 1511 EXPECTRGB(6,FAILDIG); 1512 1513 /* VB oct */ 1514 CONVERT("&O300", NUMPRS_HEX_OCT); 1515 EXPECT(3,NUMPRS_HEX_OCT,0x40,5,3,0); 1516 EXPECTRGB(0,3); 1517 EXPECTRGB(1,0); 1518 EXPECTRGB(2,0); 1519 EXPECTRGB(3,FAILDIG); 1520 1521 /* VB oct lower case and leading zero */ 1522 CONVERT("&o0777", NUMPRS_HEX_OCT); 1523 EXPECT(3,NUMPRS_HEX_OCT,0x40,6,3,0); 1524 EXPECTRGB(0,7); 1525 EXPECTRGB(1,7); 1526 EXPECTRGB(2,7); 1527 EXPECTRGB(3,FAILDIG); 1528 1529 /* VB oct char bigger than 7 */ 1530 CONVERT("&o128", NUMPRS_HEX_OCT); 1531 EXPECT(2,NUMPRS_HEX_OCT,0x40,4,3,0); 1532 EXPECTRGB(0,1); 1533 EXPECTRGB(1,2); 1534 EXPECTRGB(3,FAILDIG); 1535 1536 /** NUMPRS_PARENS **/ 1537 1538 /* Empty parens = error */ 1539 CONVERT("()", NUMPRS_PARENS); 1540 EXPECTFAIL; 1541 EXPECTRGB(0,FAILDIG); 1542 1543 /* With flag, trailing parens not consumed */ 1544 CONVERT("0()", NUMPRS_PARENS); 1545 EXPECT(1,NUMPRS_PARENS,0,1,0,0); 1546 EXPECT2(0,FAILDIG); 1547 1548 /* With flag, Number in parens made negative and parens consumed */ 1549 CONVERT("(0)", NUMPRS_PARENS); 1550 EXPECT(1,NUMPRS_PARENS,NUMPRS_NEG|NUMPRS_PARENS,3,0,0); 1551 EXPECT2(0,FAILDIG); 1552 1553 /** NUMPRS_THOUSANDS **/ 1554 1555 /* With flag, thousands sep. not needed */ 1556 CONVERT("0", NUMPRS_THOUSANDS); 1557 EXPECT(1,NUMPRS_THOUSANDS,0,1,0,0); 1558 EXPECT2(0,FAILDIG); 1559 1560 /* With flag, thousands sep. and following digits consumed */ 1561 CONVERT("1,000", NUMPRS_THOUSANDS); 1562 EXPECT(1,NUMPRS_THOUSANDS,NUMPRS_THOUSANDS,5,0,3); 1563 EXPECTRGB(0,1); 1564 1565 /* With flag and decimal point, thousands sep. but not decimals consumed */ 1566 CONVERT("1,000.0", NUMPRS_THOUSANDS); 1567 EXPECT(1,NUMPRS_THOUSANDS,NUMPRS_THOUSANDS,5,0,3); 1568 EXPECTRGB(0,1); 1569 1570 /** NUMPRS_CURRENCY **/ 1571 1572 /* Without flag, chokes on currency sign */ 1573 CONVERT("$11", 0); 1574 EXPECTFAIL; 1575 EXPECTRGB(0,FAILDIG); 1576 1577 /* With flag, consumes currency sign */ 1578 CONVERT("$11", NUMPRS_CURRENCY); 1579 EXPECT(2,NUMPRS_CURRENCY,NUMPRS_CURRENCY,3,0,0); 1580 EXPECT2(1,1); 1581 EXPECTRGB(2,FAILDIG); 1582 1583 /* With flag only, doesn't consume decimal point */ 1584 CONVERT("$11.1", NUMPRS_CURRENCY); 1585 EXPECT(2,NUMPRS_CURRENCY,NUMPRS_CURRENCY,3,0,0); 1586 EXPECT2(1,1); 1587 EXPECTRGB(2,FAILDIG); 1588 1589 /* With flag and decimal flag, consumes decimal point and following digits */ 1590 CONVERT("$11.1", NUMPRS_CURRENCY|NUMPRS_DECIMAL); 1591 EXPECT(3,NUMPRS_CURRENCY|NUMPRS_DECIMAL,NUMPRS_CURRENCY|NUMPRS_DECIMAL,5,0,-1); 1592 EXPECT2(1,1); 1593 EXPECTRGB(2,1); 1594 EXPECTRGB(3,FAILDIG); 1595 1596 /* Thousands flag can only be used with currency */ 1597 CONVERT("$1,234", NUMPRS_CURRENCY|NUMPRS_THOUSANDS); 1598 EXPECT(4,NUMPRS_CURRENCY|NUMPRS_THOUSANDS,NUMPRS_CURRENCY|NUMPRS_THOUSANDS,6,0,0); 1599 EXPECT2(1,2); 1600 EXPECTRGB(2,3); 1601 EXPECTRGB(3,4); 1602 EXPECTRGB(4,FAILDIG); 1603 1604 /** NUMPRS_DECIMAL **/ 1605 1606 /* With flag, consumes decimal point */ 1607 CONVERT("1.1", NUMPRS_DECIMAL); 1608 EXPECT(2,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1); 1609 EXPECT2(1,1); 1610 EXPECTRGB(2,FAILDIG); 1611 1612 /* With flag, consumes decimal point. Skipping the decimal part is not an error */ 1613 CONVERT("1.", NUMPRS_DECIMAL); 1614 EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,2,0,0); 1615 EXPECT2(1,FAILDIG); 1616 1617 /* Consumes only one decimal point */ 1618 CONVERT("1.1.", NUMPRS_DECIMAL); 1619 EXPECT(2,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1); 1620 EXPECT2(1,1); 1621 EXPECTRGB(2,FAILDIG); 1622 1623 /** NUMPRS_EXPONENT **/ 1624 1625 /* Without flag, doesn't consume exponent */ 1626 CONVERT("1e1", 0); 1627 EXPECT(1,0,0,1,0,0); 1628 EXPECT2(1,FAILDIG); 1629 1630 /* With flag, consumes exponent */ 1631 CONVERT("1e1", NUMPRS_EXPONENT); 1632 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,1); 1633 EXPECT2(1,FAILDIG); 1634 1635 /* Negative exponents are accepted without flags */ 1636 CONVERT("1e-1", NUMPRS_EXPONENT); 1637 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,-1); 1638 EXPECT2(1,FAILDIG); 1639 1640 /* As are positive exponents and leading exponent 0s */ 1641 CONVERT("1e+01", NUMPRS_EXPONENT); 1642 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,5,0,1); 1643 EXPECT2(1,FAILDIG); 1644 1645 /* The same for zero exponents */ 1646 CONVERT("1e0", NUMPRS_EXPONENT); 1647 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,0); 1648 EXPECT2(1,FAILDIG); 1649 1650 /* Sign on a zero exponent doesn't matter */ 1651 CONVERT("1e+0", NUMPRS_EXPONENT); 1652 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,0); 1653 EXPECT2(1,FAILDIG); 1654 1655 CONVERT("1e-0", NUMPRS_EXPONENT); 1656 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,0); 1657 EXPECT2(1,FAILDIG); 1658 1659 /* Doesn't consume a real number exponent */ 1660 CONVERT("1e1.", NUMPRS_EXPONENT); 1661 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,1); 1662 EXPECT2(1,FAILDIG); 1663 1664 /* Powers of 10 are calculated from the position of any decimal point */ 1665 CONVERT("1.5e20", NUMPRS_EXPONENT|NUMPRS_DECIMAL); 1666 EXPECT(2,NUMPRS_EXPONENT|NUMPRS_DECIMAL,NUMPRS_EXPONENT|NUMPRS_DECIMAL,6,0,19); 1667 EXPECT2(1,5); 1668 1669 CONVERT("1.5e-20", NUMPRS_EXPONENT|NUMPRS_DECIMAL); 1670 EXPECT(2,NUMPRS_EXPONENT|NUMPRS_DECIMAL,NUMPRS_EXPONENT|NUMPRS_DECIMAL,7,0,-21); 1671 EXPECT2(1,5); 1672 1673 /** NUMPRS_USE_ALL **/ 1674 1675 /* Flag expects all digits */ 1676 CONVERT("0", NUMPRS_USE_ALL); 1677 EXPECT(1,NUMPRS_USE_ALL,0,1,0,0); 1678 EXPECT2(0,FAILDIG); 1679 1680 /* Rejects anything trailing */ 1681 CONVERT("0 ", NUMPRS_USE_ALL); 1682 EXPECTFAIL; 1683 EXPECT2(0,FAILDIG); 1684 1685 /* Unless consumed by trailing flag */ 1686 CONVERT("0 ", NUMPRS_USE_ALL|NUMPRS_TRAILING_WHITE); 1687 EXPECT(1,NUMPRS_USE_ALL|NUMPRS_TRAILING_WHITE,NUMPRS_TRAILING_WHITE,2,0,0); 1688 EXPECT2(0,FAILDIG); 1689 1690 /** Combinations **/ 1691 1692 /* Leading whitespace and plus, doesn't consume trailing whitespace */ 1693 CONVERT("+ 0 ", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE); 1694 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,3,0,0); 1695 EXPECT2(0,FAILDIG); 1696 1697 /* Order of whitespace and plus is unimportant */ 1698 CONVERT(" +0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE); 1699 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,3,0,0); 1700 EXPECT2(0,FAILDIG); 1701 1702 /* Leading whitespace can be repeated */ 1703 CONVERT(" + 0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE); 1704 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,4,0,0); 1705 EXPECT2(0,FAILDIG); 1706 1707 /* But plus/minus etc. cannot */ 1708 CONVERT("+ +0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE); 1709 EXPECTFAIL; 1710 EXPECTRGB(0,FAILDIG); 1711 1712 /* Inexact is not set if trailing zeros are removed */ 1713 CONVERTN("10", 1, 0); 1714 EXPECT(1,0,0,2,0,1); 1715 EXPECT2(1,FAILDIG); 1716 1717 /* Make sure a leading 0 is stripped but decimals after it get read */ 1718 CONVERT("-0.51", NUMPRS_STD); 1719 EXPECT(2,NUMPRS_STD,NUMPRS_NEG|NUMPRS_DECIMAL|NUMPRS_LEADING_MINUS,5,0,-2); 1720 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 /* Zeros after decimal sign */ 1729 CONVERT("0.01", NUMPRS_STD); 1730 EXPECT(1,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-2); 1731 EXPECT2(1,FAILDIG); 1732 1733 /* Trailing zeros after decimal part */ 1734 CONVERT("0.10", NUMPRS_STD); 1735 EXPECT(1,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-1); 1736 EXPECT2(1,0); 1737 } 1738 1739 static HRESULT (WINAPI *pVarNumFromParseNum)(NUMPARSE*,BYTE*,ULONG,VARIANT*); 1740 1741 /* Macros for converting and testing the result of VarNumFromParseNum */ 1742 #define SETRGB(indx,val) if (!indx) memset(rgb, FAILDIG, sizeof(rgb)); rgb[indx] = val 1743 #undef CONVERT 1744 #define CONVERT(a,b,c,d,e,f,bits) \ 1745 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 if (hres == (HRESULT)S_OK) 1752 #define EXPECT_TYPE(typ) ok(V_VT(&vOut) == typ,"Expected Type = " #typ ", got %d\n", V_VT(&vOut)) 1753 #define EXPECT_I1(val) EXPECT_OK { EXPECT_TYPE(VT_I1); \ 1754 ok(V_I1(&vOut) == val, "Expected i1 = %d, got %d\n", (signed char)val, V_I1(&vOut)); } 1755 #define EXPECT_UI1(val) EXPECT_OK { EXPECT_TYPE(VT_UI1); \ 1756 ok(V_UI1(&vOut) == val, "Expected ui1 = %d, got %d\n", (BYTE)val, V_UI1(&vOut)); } 1757 #define EXPECT_I2(val) EXPECT_OK { EXPECT_TYPE(VT_I2); \ 1758 ok(V_I2(&vOut) == val, "Expected i2 = %d, got %d\n", (SHORT)val, V_I2(&vOut)); } 1759 #define EXPECT_UI2(val) EXPECT_OK { EXPECT_TYPE(VT_UI2); \ 1760 ok(V_UI2(&vOut) == val, "Expected ui2 = %d, got %d\n", (USHORT)val, V_UI2(&vOut)); } 1761 #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 #define EXPECT_R4(val) EXPECT_OK { EXPECT_TYPE(VT_R4); \ 1772 ok(V_R4(&vOut) == val, "Expected r4 = %f, got %f\n", val, V_R4(&vOut)); } 1773 #define EXPECT_R8(val) EXPECT_OK { EXPECT_TYPE(VT_R8); \ 1774 ok(V_R8(&vOut) == val, "Expected r8 = %g, got %g\n", val, V_R8(&vOut)); } 1775 #define CY_MULTIPLIER 10000 1776 #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 ok((V_DECIMAL(&vOut).Hi32 == valHi) && (S1(U1(V_DECIMAL(&vOut))).Mid32 == valMid) && \ 1781 (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 static void test_VarNumFromParseNum(void) 1786 { 1787 HRESULT hres; 1788 NUMPARSE np; 1789 BYTE rgb[128]; 1790 VARIANT vOut; 1791 1792 CHECKPTR(VarNumFromParseNum); 1793 1794 /* Convert the number 1 to different types */ 1795 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I1); EXPECT_I1(1); 1796 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_UI1); EXPECT_UI1(1); 1797 /* Prefers a signed type to unsigned of the same size */ 1798 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I1|VTBIT_UI1); EXPECT_I1(1); 1799 /* But takes the smaller size if possible */ 1800 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I2|VTBIT_UI1); EXPECT_UI1(1); 1801 1802 /* Try different integer sizes */ 1803 #define INTEGER_VTBITS (VTBIT_I1|VTBIT_UI1|VTBIT_I2|VTBIT_UI2|VTBIT_I4|VTBIT_UI4|VTBIT_I8|VTBIT_UI8) 1804 1805 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, INTEGER_VTBITS); EXPECT_I1(1); 1806 /* 127 */ 1807 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 7); 1808 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_I1(127); 1809 /* 128 */ 1810 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 8); 1811 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_UI1(128); 1812 /* 255 */ 1813 SETRGB(0, 2); SETRGB(1, 5); SETRGB(2, 5); 1814 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_UI1(255); 1815 /* 256 */ 1816 SETRGB(0, 2); SETRGB(1, 5); SETRGB(2, 6); 1817 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_I2(256); 1818 /* 32767 */ 1819 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 7); 1820 CONVERT(5,0,0,5,0,0, INTEGER_VTBITS); EXPECT_I2(32767); 1821 /* 32768 */ 1822 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 8); 1823 CONVERT(5,0,0,5,0,0, INTEGER_VTBITS); EXPECT_UI2(32768); 1824 1825 /* Assume the above pattern holds for remaining positive integers; test negative */ 1826 1827 /* -128 */ 1828 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 8); 1829 CONVERT(3,0,NUMPRS_NEG,3,0,0, INTEGER_VTBITS); EXPECT_I1(-128); 1830 /* -129 */ 1831 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 9); 1832 CONVERT(3,0,NUMPRS_NEG,3,0,0, INTEGER_VTBITS); EXPECT_I2(-129); 1833 /* -32768 */ 1834 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 8); 1835 CONVERT(5,0,NUMPRS_NEG,5,0,0, INTEGER_VTBITS); EXPECT_I2(-32768); 1836 /* -32768 */ 1837 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 9); 1838 CONVERT(5,0,NUMPRS_NEG,5,0,0, INTEGER_VTBITS); EXPECT_I4(-32769); 1839 1840 /* Assume the above pattern holds for remaining negative integers */ 1841 1842 /* Test hexadecimal conversions */ 1843 SETRGB(0, 1); CONVERT(1,0,0,1,4,0, INTEGER_VTBITS); EXPECT_I1(0x01); 1844 /* 0x7f */ 1845 SETRGB(0, 7); SETRGB(1, 0xf); 1846 CONVERT(2,0,0,2,4,0, INTEGER_VTBITS); EXPECT_I1(0x7f); 1847 SETRGB(0, 7); SETRGB(1, 0xf); 1848 CONVERT(2,0,0,2,4,0, VTBIT_DECIMAL); EXPECT_DECIMAL(0,0,0x7f); 1849 /* 0x7fff */ 1850 SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf); 1851 CONVERT(4,0,0,4,4,0, INTEGER_VTBITS); EXPECT_I2(0x7fff); 1852 /* 0x7fffffff */ 1853 SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf); 1854 SETRGB(4, 0xf); SETRGB(5, 0xf); SETRGB(6, 0xf); SETRGB(7, 0xf); 1855 CONVERT(8,0,0,8,4,0, INTEGER_VTBITS); EXPECT_I4(0x7fffffffL); 1856 /* 0x7fffffffffffffff (64 bits) */ 1857 SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf); 1858 SETRGB(4, 0xf); SETRGB(5, 0xf); SETRGB(6, 0xf); SETRGB(7, 0xf); 1859 SETRGB(8, 0xf); SETRGB(9, 0xf); SETRGB(10, 0xf); SETRGB(11, 0xf); 1860 SETRGB(12, 0xf); SETRGB(13, 0xf); SETRGB(14, 0xf); SETRGB(15, 0xf); 1861 if (has_i8) 1862 { 1863 /* We cannot use INTEGER_VTBITS as WinXP and Win2003 are broken(?). They 1864 truncate the number to the smallest integer size requested: 1865 CONVERT(16,0,0,16,4,0, INTEGER_VTBITS); EXPECT_I1((signed char)0xff); */ 1866 CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x7fffffff,0xffffffff); 1867 } 1868 1869 /* Assume the above pattern holds for numbers without hi-bit set, test (preservation of) hi-bit */ 1870 /* 0x82 */ 1871 SETRGB(0, 8); SETRGB(1, 2); 1872 CONVERT(2,0,0,2,4,0, INTEGER_VTBITS); 1873 EXPECT_I1((signed char)0x82); 1874 /* 0x8002 */ 1875 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 2); 1876 CONVERT(4,0,0,4,4,0, INTEGER_VTBITS); 1877 EXPECT_I2((signed short)0x8002); 1878 /* 0x80000002 */ 1879 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0); 1880 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 /* 0x8000000000000002 (64 bits) */ 1883 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0); 1884 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 0); 1885 SETRGB(8, 0); SETRGB(9, 0); SETRGB(10, 0); SETRGB(11, 0); 1886 SETRGB(12, 0); SETRGB(13, 0); SETRGB(14, 0); SETRGB(15, 2); 1887 if (has_i8) 1888 { 1889 /* We cannot use INTEGER_VTBITS as WinXP and Win2003 are broken(?). They 1890 truncate the number to the smallest integer size requested: 1891 CONVERT(16,0,0,16,4,0, INTEGER_VTBITS & ~VTBIT_I1); 1892 EXPECT_I2((signed short)0x0002); */ 1893 CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x80000000,0x00000002); 1894 } 1895 1896 /* Test (preservation of) hi-bit with STRICT type requesting */ 1897 /* 0x82 */ 1898 SETRGB(0, 8); SETRGB(1, 2); 1899 CONVERT(2,0,0,2,4,0, VTBIT_I1); 1900 EXPECT_I1((signed char)0x82); 1901 /* 0x8002 */ 1902 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 2); 1903 CONVERT(4,0,0,4,4,0, VTBIT_I2); 1904 EXPECT_I2((signed short)0x8002); 1905 /* 0x80000002 */ 1906 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0); 1907 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 /* 0x8000000000000002 (64 bits) */ 1910 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0); 1911 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 0); 1912 SETRGB(8, 0); SETRGB(9, 0); SETRGB(10, 0); SETRGB(11, 0); 1913 SETRGB(12, 0); SETRGB(13, 0); SETRGB(14, 0); SETRGB(15, 2); 1914 if (has_i8) 1915 { 1916 CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x80000000,0x00000002); 1917 } 1918 /* Assume the above pattern holds for numbers with hi-bit set */ 1919 1920 /* Negative numbers overflow if we have only unsigned outputs */ 1921 /* -1 */ 1922 SETRGB(0, 1); CONVERT(1,0,NUMPRS_NEG,1,0,0, VTBIT_UI1); EXPECT_OVERFLOW; 1923 /* -0.6 */ 1924 SETRGB(0, 6); CONVERT(1,0,NUMPRS_NEG,1,0,~0u, VTBIT_UI1); EXPECT_OVERFLOW; 1925 1926 /* Except that rounding is done first, so -0.5 to 0 are accepted as 0 */ 1927 /* -0.5 */ 1928 SETRGB(0, 5); CONVERT(1,0,NUMPRS_NEG,1,0,~0u, VTBIT_UI1); EXPECT_UI1(0); 1929 1930 /* Floating point zero is OK */ 1931 /* 0.00000000E0 */ 1932 SETRGB(0, 0); CONVERT(1,0,NUMPRS_DECIMAL|NUMPRS_EXPONENT,12,0,-8, VTBIT_R8); 1933 EXPECT_R8(0.0); 1934 1935 /* Float is acceptable for an integer input value */ 1936 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R4); EXPECT_R4(1.0f); 1937 /* As is double */ 1938 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R8); EXPECT_R8(1.0); 1939 /* As is currency */ 1940 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_CY); EXPECT_CY(1); 1941 1942 /* Float is preferred over double */ 1943 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R4|VTBIT_R8); EXPECT_R4(1.0f); 1944 1945 /* Double is preferred over currency */ 1946 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R8|VTBIT_CY); EXPECT_R8(1.0); 1947 1948 /* Currency is preferred over decimal */ 1949 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_CY|VTBIT_DECIMAL); EXPECT_CY(1); 1950 1951 /* Underflow test */ 1952 SETRGB(0, 1); CONVERT(1,0,NUMPRS_EXPONENT,1,0,-94938484, VTBIT_R4); EXPECT_R4(0.0); 1953 SETRGB(0, 1); CONVERT(1,0,NUMPRS_EXPONENT,1,0,-94938484, VTBIT_R8); EXPECT_R8(0.0); 1954 SETRGB(0, 1); CONVERT(1,0,NUMPRS_EXPONENT,1,0,-94938484, VTBIT_CY); EXPECT_CY(0); 1955 } 1956 1957 1958 static void test_UdateFromDate( int line, DATE dt, ULONG flags, HRESULT r, WORD d, WORD m, WORD y, 1959 WORD h, WORD mn, WORD s, WORD ms, WORD dw, WORD dy) 1960 { 1961 UDATE ud; 1962 HRESULT res; 1963 1964 memset(&ud, 0, sizeof(ud)); 1965 res = pVarUdateFromDate(dt, flags, &ud); 1966 ok_(__FILE__,line)(r == res && (res != S_OK || (ud.st.wYear == y && ud.st.wMonth == m && ud.st.wDay == d && 1967 ud.st.wHour == h && ud.st.wMinute == mn && ud.st.wSecond == s && 1968 ud.st.wMilliseconds == ms && ud.st.wDayOfWeek == dw && ud.wDayOfYear == dy)), 1969 "%.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", 1970 dt, r, d, m, y, h, mn, s, ms, dw, dy, 1971 res, ud.st.wDay, ud.st.wMonth, ud.st.wYear, ud.st.wHour, ud.st.wMinute, 1972 ud.st.wSecond, ud.st.wMilliseconds, ud.st.wDayOfWeek, ud.wDayOfYear ); 1973 } 1974 #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) 1975 1976 static void test_VarUdateFromDate(void) 1977 { 1978 CHECKPTR(VarUdateFromDate); 1979 DT2UD(29221.0,0,S_OK,1,1,1980,0,0,0,0,2,1); /* 1 Jan 1980 */ 1980 DT2UD(29222.0,0,S_OK,2,1,1980,0,0,0,0,3,2); /* 2 Jan 1980 */ 1981 DT2UD(33238.0,0,S_OK,31,12,1990,0,0,0,0,1,365); /* 31 Dec 1990 */ 1982 DT2UD(0.0,0,S_OK,30,12,1899,0,0,0,0,6,364); /* 30 Dec 1899 - VT_DATE 0.0 */ 1983 DT2UD(-657434.0,0,S_OK,1,1,100,0,0,0,0,5,1); /* 1 Jan 100 - Min */ 1984 DT2UD(-657435.0,0,E_INVALIDARG,0,0,0,0,0,0,0,0,0); /* < 1 Jan 100 => err */ 1985 DT2UD(2958465.0,0,S_OK,31,12,9999,0,0,0,0,5,365); /* 31 Dec 9999 - Max */ 1986 DT2UD(2958466.0,0,E_INVALIDARG,0,0,0,0,0,0,0,0,0); /* > 31 Dec 9999 => err */ 1987 1988 /* VAR_VALIDDATE doesn't prevent upper and lower bounds being checked */ 1989 DT2UD(-657435.0,VAR_VALIDDATE,E_INVALIDARG,0,0,0,0,0,0,0,0,0); 1990 DT2UD(2958466.0,VAR_VALIDDATE,E_INVALIDARG,0,0,0,0,0,0,0,0,0); 1991 1992 /* Times */ 1993 DT2UD(29221.25,0,S_OK,1,1,1980,6,0,0,0,2,1); /* 6 AM */ 1994 DT2UD(29221.33333333,0,S_OK,1,1,1980,8,0,0,0,2,1); /* 8 AM */ 1995 DT2UD(29221.5,0,S_OK,1,1,1980,12,0,0,0,2,1); /* 12 AM */ 1996 DT2UD(29221.9888884444,0,S_OK,1,1,1980,23,44,0,0,2,1); /* 11:44 PM */ 1997 DT2UD(29221.7508765432,0,S_OK,1,1,1980,18,1,16,0,2,1); /* 6:18:02 PM */ 1998 1999 /* Test handling of times on dates prior to the epoch */ 2000 DT2UD(-5.25,0,S_OK,25,12,1899,6,0,0,0,1,359); 2001 DT2UD(-5.9999884259259,0,S_OK,25,12,1899,23,59,59,0,1,359); 2002 /* This just demonstrates the non-linear nature of values prior to the epoch */ 2003 DT2UD(-4.0,0,S_OK,26,12,1899,0,0,0,0,2,360); 2004 /* Numerical oddity: for 0.0 < x < 1.0, x and -x represent the same datetime */ 2005 DT2UD(-0.25,0,S_OK,30,12,1899,6,0,0,0,6,364); 2006 DT2UD(0.25,0,S_OK,30,12,1899,6,0,0,0,6,364); 2007 } 2008 2009 2010 static void test_DateFromUDate( int line, WORD d, WORD m, WORD y, WORD h, WORD mn, WORD s, WORD ms, 2011 WORD dw, WORD dy, ULONG flags, HRESULT r, DATE dt ) 2012 { 2013 UDATE ud; 2014 double out; 2015 HRESULT res; 2016 2017 ud.st.wYear = y; 2018 ud.st.wMonth = m; 2019 ud.st.wDay = d; 2020 ud.st.wHour = h; 2021 ud.st.wMinute = mn; 2022 ud.st.wSecond = s; 2023 ud.st.wMilliseconds = ms; 2024 ud.st.wDayOfWeek = dw; 2025 ud.wDayOfYear = dy; 2026 res = pVarDateFromUdate(&ud, flags, &out); 2027 ok_(__FILE__,line)(r == res && (r != S_OK || EQ_DOUBLE(out, dt)), 2028 "expected %x, %.16g, got %x, %.16g\n", r, dt, res, out); 2029 } 2030 #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) 2031 2032 static void test_VarDateFromUdate(void) 2033 { 2034 CHECKPTR(VarDateFromUdate); 2035 UD2T(1,1,1980,0,0,0,0,2,1,0,S_OK,29221.0); /* 1 Jan 1980 */ 2036 UD2T(2,1,1980,0,0,0,0,3,2,0,S_OK,29222.0); /* 2 Jan 1980 */ 2037 UD2T(2,1,1980,0,0,0,0,4,5,0,S_OK,29222.0); /* 2 Jan 1980 */ 2038 UD2T(31,12,1990,0,0,0,0,0,0,0,S_OK,33238.0); /* 31 Dec 1990 */ 2039 UD2T(31,12,90,0,0,0,0,0,0,0,S_OK,33238.0); /* year < 100 is 1900+year! */ 2040 UD2T(30,12,1899,0,0,0,0,6,364,0,S_OK,0.0); /* 30 Dec 1899 - VT_DATE 0.0 */ 2041 UD2T(1,1,100,0,0,0,0,0,0,0,S_OK,-657434.0); /* 1 Jan 100 - Min */ 2042 UD2T(31,12,9999,0,0,0,0,0,0,0,S_OK,2958465.0); /* 31 Dec 9999 - Max */ 2043 UD2T(1,1,10000,0,0,0,0,0,0,0,E_INVALIDARG,0.0); /* > 31 Dec 9999 => err */ 2044 UD2T(1,1,-10000,0,0,0,0,0,0,0,E_INVALIDARG,0.0);/* < -9999 => err */ 2045 2046 UD2T(30,12,1899,0,0,0,0,0,0,0,S_OK,0.0); /* 30 Dec 1899 0:00:00 */ 2047 UD2T(30,12,1899,0,0,0,999,0,0,0,S_OK,0.0); /* Ignore milliseconds */ 2048 2049 UD2T(1,1,1980,18,1,16,0,2,1,0,S_OK,29221.75087962963); /* 6:18:02 PM */ 2050 UD2T(1,300,1980,18,1,16,0,2,1,0,S_OK,38322.75087962963); /* Test fwdrolled month */ 2051 UD2T(300,1,1980,18,1,16,0,2,1,0,S_OK,29520.75087962963); /* Test fwdrolled days */ 2052 UD2T(0,1,1980,42,1,16,0,2,1,0,S_OK,29221.75087962963); /* Test fwdrolled hours */ 2053 UD2T(1,1,1980,17,61,16,0,2,1,0,S_OK,29221.75087962963); /* Test fwdrolled minutes */ 2054 UD2T(1,1,1980,18,0,76,0,2,1,0,S_OK,29221.75087962963); /* Test fwdrolled seconds */ 2055 UD2T(1,-300,1980,18,1,16,0,2,1,0,S_OK,20059.75087962963); /* Test backrolled month */ 2056 UD2T(-300,1,1980,18,1,16,0,2,1,0,S_OK,28920.75087962963); /* Test backrolled days */ 2057 UD2T(3,1,1980,-30,1,16,0,2,1,0,S_OK,29221.75087962963); /* Test backrolled hours */ 2058 UD2T(1,1,1980,20,-119,16,0,2,1,0,S_OK,29221.75087962963); /* Test backrolled minutes */ 2059 UD2T(1,1,1980,18,3,-104,0,2,1,0,S_OK,29221.75087962963); /* Test backrolled seconds */ 2060 UD2T(1,12001,-1020,18,1,16,0,0,0,0,S_OK,29221.75087962963); /* Test rolled year and month */ 2061 UD2T(1,-23,1982,18,1,16,0,0,0,0,S_OK,29221.75087962963); /* Test backrolled month */ 2062 UD2T(-59,3,1980,18,1,16,0,0,0,0,S_OK,29221.75087962963); /* Test backrolled days */ 2063 UD2T(1,1,0,0,0,0,0,0,0,0,S_OK,36526); /* Test zero year */ 2064 UD2T(0,0,1980,0,0,0,0,0,0,0,S_OK,29189); /* Test zero day and month */ 2065 UD2T(0,1,1980,0,0,0,0,2,1,0,S_OK,29220.0); /* Test zero day = LastDayOfMonth */ 2066 UD2T(-1,1,1980,18,1,16,0,0,0,0,S_OK,29219.75087962963); /* Test day -1 = LastDayOfMonth - 1 */ 2067 UD2T(1,1,-1,18,1,16,0,0,0,0,S_OK,36161.75087962963); /* Test year -1 = 1999 */ 2068 UD2T(1,-1,1980,18,1,16,0,0,0,0,S_OK,29160.7508796296); /* Test month -1 = 11 */ 2069 UD2T(1,13,1980,0,0,0,0,2,1,0,S_OK,29587.0); /* Rolls fwd to 1/1/1981 */ 2070 2071 /* Test handling of times on dates prior to the epoch */ 2072 UD2T(25,12,1899,6,0,0,0,1,359,0,S_OK,-5.25); 2073 UD2T(25,12,1899,23,59,59,0,1,359,0,S_OK,-5.9999884259259); 2074 /* This just demonstrates the non-linear nature of values prior to the epoch */ 2075 UD2T(26,12,1899,0,0,0,0,2,360,0,S_OK,-4.0); 2076 /* for DATE values 0.0 < x < 1.0, x and -x represent the same datetime */ 2077 /* but when converting to DATE, prefer the positive versions */ 2078 UD2T(30,12,1899,6,0,0,0,6,364,0,S_OK,0.25); 2079 2080 UD2T(1,1,1980,18,1,16,0,2,1,VAR_TIMEVALUEONLY,S_OK,0.7508796296296296); 2081 UD2T(1,1,1980,18,1,16,0,2,1,VAR_DATEVALUEONLY,S_OK,29221.0); 2082 UD2T(25,12,1899,6,0,0,0,1,359,VAR_TIMEVALUEONLY,S_OK,0.25); 2083 UD2T(25,12,1899,6,0,0,0,1,359,VAR_DATEVALUEONLY,S_OK,-5.0); 2084 UD2T(1,-1,1980,18,1,16,0,0,0,VAR_TIMEVALUEONLY|VAR_DATEVALUEONLY,S_OK,0.7508796296296296); 2085 } 2086 2087 static void test_st2dt(int line, WORD d, WORD m, WORD y, WORD h, WORD mn, 2088 WORD s, WORD ms, INT r, double dt) 2089 { 2090 SYSTEMTIME st; 2091 double out; 2092 INT res; 2093 2094 st.wYear = y; 2095 st.wMonth = m; 2096 st.wDay = d; 2097 st.wHour = h; 2098 st.wMinute = mn; 2099 st.wSecond = s; 2100 st.wMilliseconds = ms; 2101 st.wDayOfWeek = 0; 2102 res = pSystemTimeToVariantTime(&st, &out); 2103 ok_(__FILE__,line)(r == res && (!r || EQ_DOUBLE(out, dt)), 2104 "expected %d, %.16g, got %d, %.16g\n", r, dt, res, out); 2105 } 2106 #define ST2DT(d,m,y,h,mn,s,ms,r,dt) test_st2dt(__LINE__,d,m,y,h,mn,s,ms,r,dt) 2107 2108 static void test_SystemTimeToVariantTime(void) 2109 { 2110 CHECKPTR(SystemTimeToVariantTime); 2111 ST2DT(1,1,1980,0,0,0,0,TRUE,29221.0); 2112 ST2DT(2,1,1980,0,0,0,0,TRUE,29222.0); 2113 ST2DT(0,1,1980,0,0,0,0,TRUE,29220.0); /* Rolls back to 31 Dec 1899 */ 2114 ST2DT(1,13,1980,0,0,0,0,FALSE,29587.0); /* Fails on invalid month */ 2115 ST2DT(32,1,1980,0,0,0,0,FALSE,0.0); /* Fails on invalid day */ 2116 ST2DT(1,1,-1,0,0,0,0,FALSE,0.0); /* Fails on invalid year */ 2117 ST2DT(1,1,10000,0,0,0,0,FALSE,0.0); /* Fails on invalid year */ 2118 ST2DT(1,1,9999,0,0,0,0,TRUE,2958101.0); /* 9999 is last valid year */ 2119 ST2DT(31,12,90,0,0,0,0,TRUE,33238.0); /* 30 <= year < 100 is 1900+year */ 2120 ST2DT(1,1,30,0,0,0,0,TRUE,10959.0); /* 30 <= year < 100 is 1900+year */ 2121 ST2DT(1,1,29,0,0,0,0,TRUE,47119.0); /* 0 <= year < 30 is 2000+year */ 2122 ST2DT(1,1,0,0,0,0,0,TRUE,36526.0); /* 0 <= year < 30 is 2000+year */ 2123 } 2124 2125 static void test_dt2st(int line, double dt, INT r, WORD d, WORD m, WORD y, 2126 WORD h, WORD mn, WORD s, WORD ms) 2127 { 2128 SYSTEMTIME st; 2129 INT res; 2130 2131 memset(&st, 0, sizeof(st)); 2132 res = pVariantTimeToSystemTime(dt, &st); 2133 ok_(__FILE__,line)(r == res && 2134 (!r || (st.wYear == y && st.wMonth == m && st.wDay == d && 2135 st.wHour == h && st.wMinute == mn && 2136 st.wSecond == s && st.wMilliseconds == ms)), 2137 "%.16g expected %d, %d,%d,%d,%d,%d,%d,%d, got %d, %d,%d,%d,%d,%d,%d,%d\n", 2138 dt, r, d, m, y, h, mn, s, ms, res, st.wDay, st.wMonth, 2139 st.wYear, st.wHour, st.wMinute, st.wSecond, 2140 st.wMilliseconds); 2141 } 2142 #define DT2ST(dt,r,d,m,y,h,mn,s,ms) test_dt2st(__LINE__,dt,r,d,m,y,h,mn,s,ms) 2143 2144 static void test_VariantTimeToSystemTime(void) 2145 { 2146 CHECKPTR(VariantTimeToSystemTime); 2147 DT2ST(29221.0,1,1,1,1980,0,0,0,0); 2148 DT2ST(29222.0,1,2,1,1980,0,0,0,0); 2149 } 2150 2151 #define MKDOSDATE(d,m,y) ((d & 0x1f) | ((m & 0xf) << 5) | (((y-1980) & 0x7f) << 9)) 2152 #define MKDOSTIME(h,m,s) (((s>>1) & 0x1f) | ((m & 0x3f) << 5) | ((h & 0x1f) << 11)) 2153 2154 static void test_dos2dt(int line, WORD d, WORD m, WORD y, WORD h, WORD mn, 2155 WORD s, INT r, double dt) 2156 { 2157 unsigned short dosDate, dosTime; 2158 double out; 2159 INT res; 2160 2161 out = 0.0; 2162 dosDate = MKDOSDATE(d, m, y); 2163 dosTime = MKDOSTIME(h, mn, s); 2164 res = pDosDateTimeToVariantTime(dosDate, dosTime, &out); 2165 ok_(__FILE__,line)(r == res && (!r || EQ_DOUBLE(out, dt)), 2166 "expected %d, %.16g, got %d, %.16g\n", r, dt, res, out); 2167 } 2168 #define DOS2DT(d,m,y,h,mn,s,r,dt) test_dos2dt(__LINE__,d,m,y,h,mn,s,r,dt) 2169 2170 static void test_DosDateTimeToVariantTime(void) 2171 { 2172 CHECKPTR(DosDateTimeToVariantTime); 2173 2174 /* Date */ 2175 DOS2DT(1,1,1980,0,0,0,1,29221.0); /* 1/1/1980 */ 2176 DOS2DT(31,12,2099,0,0,0,1,73050.0); /* 31/12/2099 */ 2177 /* Dates are limited to the dos date max of 31/12/2099 */ 2178 DOS2DT(31,12,2100,0,0,0,0,0.0); /* 31/12/2100 */ 2179 /* Days and months of 0 cause date to roll back 1 day or month */ 2180 DOS2DT(0,1,1980,0,0,0,1,29220.0); /* 0 Day => 31/12/1979 */ 2181 DOS2DT(1,0,1980,0,0,0,1,29190.0); /* 0 Mth => 1/12/1979 */ 2182 DOS2DT(0,0,1980,0,0,0,1,29189.0); /* 0 D/M => 30/11/1979 */ 2183 /* Days > days in the month cause date to roll forward 1 month */ 2184 DOS2DT(29,2,1981,0,0,0,1,29646.0); /* 29/2/1981 -> 3/1/1980 */ 2185 DOS2DT(30,2,1981,0,0,0,1,29647.0); /* 30/2/1981 -> 4/1/1980 */ 2186 /* Takes leap years into account when rolling forward */ 2187 DOS2DT(29,2,1980,0,0,0,1,29280.0); /* 2/29/1980 */ 2188 /* Months > 12 cause an error */ 2189 DOS2DT(2,13,1980,0,0,0,0,0.0); 2190 2191 /* Time */ 2192 DOS2DT(1,1,1980,0,0,29,1,29221.00032407407); /* 1/1/1980 12:00:28 AM */ 2193 DOS2DT(1,1,1980,0,0,31,1,29221.00034722222); /* 1/1/1980 12:00:30 AM */ 2194 DOS2DT(1,1,1980,0,59,0,1,29221.04097222222); /* 1/1/1980 12:59:00 AM */ 2195 DOS2DT(1,1,1980,0,60,0,0,0.0); /* Invalid minutes */ 2196 DOS2DT(1,1,1980,0,0,60,0,0.0); /* Invalid seconds */ 2197 DOS2DT(1,1,1980,23,0,0,1,29221.95833333333); /* 1/1/1980 11:00:00 PM */ 2198 DOS2DT(1,1,1980,24,0,0,0,0.0); /* Invalid hours */ 2199 2200 DOS2DT(1,1,1980,0,0,1,1,29221.0); 2201 DOS2DT(2,1,1980,0,0,0,1,29222.0); 2202 DOS2DT(2,1,1980,0,0,0,1,29222.0); 2203 DOS2DT(31,12,1990,0,0,0,1,33238.0); 2204 DOS2DT(31,12,90,0,0,0,1,40543.0); 2205 DOS2DT(30,12,1899,0,0,0,1,46751.0); 2206 DOS2DT(1,1,100,0,0,0,1,43831.0); 2207 DOS2DT(31,12,9999,0,0,0,1,59901.0); 2208 DOS2DT(1,1,10000,0,0,0,1,59902.0); 2209 DOS2DT(1,1,-10000,0,0,0,1,48214.0); 2210 2211 DOS2DT(30,12,1899,0,0,0,1,46751.0); 2212 DOS2DT(30,12,1899,0,0,1,1,46751.0); 2213 2214 DOS2DT(1,1,1980,18,1,16,1,29221.75087962963); 2215 DOS2DT(1,300,1980,18,1,16,1,29556.75087962963); 2216 DOS2DT(300,1,1980,18,1,16,1,29232.75087962963); 2217 DOS2DT(0,1,1980,42,1,16,1,29220.4175462963); 2218 DOS2DT(1,1,1980,17,61,16,0,0.0); 2219 DOS2DT(1,1,1980,18,0,76,1,29221.75013888889); 2220 DOS2DT(1,-300,1980,18,1,16,1,29312.75087962963); 2221 DOS2DT(-300,1,1980,18,1,16,1,29240.75087962963); 2222 DOS2DT(3,1,1980,-30,1,16,1,29223.08421296296); 2223 DOS2DT(1,1,1980,20,-119,16,1,29221.83976851852); 2224 DOS2DT(1,1,1980,18,3,-104,1,29221.75236111111); 2225 DOS2DT(1,12001,-1020,18,1,16,1,55519.75087962963); 2226 DOS2DT(1,-23,1982,18,1,16,1,30195.75087962963); 2227 DOS2DT(-59,3,1980,18,1,16,1,29285.75087962963); 2228 DOS2DT(1,1,0,0,0,0,1,54058.0); 2229 DOS2DT(0,0,1980,0,0,0,1,29189.0); 2230 DOS2DT(0,1,1980,0,0,0,1,29220.0); 2231 DOS2DT(-1,1,1980,18,1,16,1,29251.75087962963); 2232 DOS2DT(1,1,-1,18,1,16,1,53693.75087962963); 2233 DOS2DT(1,-1,1980,18,1,16,0,0); 2234 } 2235 2236 static void test_dt2dos(int line, double dt, INT r, WORD d, WORD m, WORD y, 2237 WORD h, WORD mn, WORD s) 2238 { 2239 unsigned short dosDate, dosTime, expDosDate, expDosTime; 2240 INT res; 2241 2242 dosTime = dosDate = 0; 2243 expDosDate = MKDOSDATE(d,m,y); 2244 expDosTime = MKDOSTIME(h,mn,s); 2245 res = pVariantTimeToDosDateTime(dt, &dosDate, &dosTime); 2246 ok_(__FILE__,line)(r == res && (!r || (dosTime == expDosTime && dosDate == expDosDate)), 2247 "%g: expected %d,%d(%d/%d/%d),%d(%d:%d:%d) got %d,%d(%d/%d/%d),%d(%d:%d:%d)\n", 2248 dt, r, expDosDate, expDosDate & 0x1f, 2249 (expDosDate >> 5) & 0xf, 1980 + (expDosDate >> 9), 2250 expDosTime, expDosTime >> 11, (expDosTime >> 5) & 0x3f, 2251 (expDosTime & 0x1f), 2252 res, dosDate, dosDate & 0x1f, (dosDate >> 5) & 0xf, 2253 1980 + (dosDate >> 9), dosTime, dosTime >> 11, 2254 (dosTime >> 5) & 0x3f, (dosTime & 0x1f)); 2255 } 2256 #define DT2DOS(dt,r,d,m,y,h,mn,s) test_dt2dos(__LINE__,dt,r,d,m,y,h,mn,s) 2257 2258 static void test_VariantTimeToDosDateTime(void) 2259 { 2260 CHECKPTR(VariantTimeToDosDateTime); 2261 2262 /* Date */ 2263 DT2DOS(29221.0,1,1,1,1980,0,0,0); /* 1/1/1980 */ 2264 DT2DOS(73050.0,1,31,12,2099,0,0,0); /* 31/12/2099 */ 2265 DT2DOS(29220.0,0,0,0,0,0,0,0); /* 31/12/1979 - out of range */ 2266 DT2DOS(73415.0,0,0,0,0,0,0,0); /* 31/12/2100 - out of range */ 2267 2268 /* Time */ 2269 DT2DOS(29221.00032407407,1,1,1,1980,0,0,29); /* 1/1/1980 12:00:28 AM */ 2270 DT2DOS(29221.00034722222,1,1,1,1980,0,0,31); /* 1/1/1980 12:00:30 AM */ 2271 DT2DOS(29221.04097222222,1,1,1,1980,0,59,0); /* 1/1/1980 12:59:00 AM */ 2272 DT2DOS(29221.95833333333,1,1,1,1980,23,0,0); /* 1/1/1980 11:00:00 PM */ 2273 } 2274 2275 static HRESULT (WINAPI *pVarAbs)(LPVARIANT,LPVARIANT); 2276 2277 #define VARABS(vt,val,rvt,rval) \ 2278 V_VT(&v) = VT_##vt; V_##vt(&v) = val; \ 2279 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 2280 test_var_call1( __LINE__, pVarAbs, &v, &exp ) 2281 2282 static void test_VarAbs(void) 2283 { 2284 static WCHAR szNum[] = {'-','1','.','1','\0' }; 2285 char buff[8]; 2286 HRESULT hres; 2287 VARIANT v, vDst, exp; 2288 size_t i; 2289 2290 CHECKPTR(VarAbs); 2291 2292 /* Test all possible V_VT values. 2293 */ 2294 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 2295 { 2296 VARTYPE vt; 2297 2298 for (vt = 0; vt <= VT_BSTR_BLOB; vt++) 2299 { 2300 HRESULT hExpected = DISP_E_BADVARTYPE; 2301 2302 SKIPTESTS(vt); 2303 2304 memset(&v, 0, sizeof(v)); 2305 V_VT(&v) = vt | ExtraFlags[i]; 2306 V_VT(&vDst) = VT_EMPTY; 2307 2308 hres = pVarAbs(&v,&vDst); 2309 if (ExtraFlags[i] & VT_ARRAY || 2310 (!ExtraFlags[i] && (vt == VT_UNKNOWN || vt == VT_BSTR || 2311 vt == VT_DISPATCH || vt == VT_ERROR || vt == VT_RECORD))) 2312 { 2313 hExpected = DISP_E_TYPEMISMATCH; 2314 } 2315 else if (ExtraFlags[i] || vt >= VT_CLSID || vt == VT_VARIANT) 2316 { 2317 hExpected = DISP_E_BADVARTYPE; 2318 } 2319 else if (IsValidVariantClearVT(vt, ExtraFlags[i])) 2320 hExpected = S_OK; 2321 2322 /* Native always fails on some vartypes that should be valid. don't 2323 * check that Wine does the same; these are bugs in native. 2324 */ 2325 if (vt == VT_I8 || vt == VT_UI8 || vt == VT_INT || vt == VT_UINT || 2326 vt == VT_I1 || vt == VT_UI2 || vt == VT_UI4) 2327 continue; 2328 ok(hres == hExpected, "VarAbs: expected 0x%X, got 0x%X for vt %d | 0x%X\n", 2329 hExpected, hres, vt, ExtraFlags[i]); 2330 } 2331 } 2332 2333 /* BOOL->I2, BSTR->R8, all others remain the same */ 2334 VARABS(BOOL,VARIANT_TRUE,I2,-VARIANT_TRUE); 2335 VARABS(BOOL,VARIANT_FALSE,I2,VARIANT_FALSE); 2336 VARABS(EMPTY,0,I2,0); 2337 VARABS(EMPTY,1,I2,0); 2338 VARABS(NULL,0,NULL,0); 2339 VARABS(NULL,1,NULL,0); 2340 VARABS(I2,1,I2,1); 2341 VARABS(I2,-1,I2,1); 2342 VARABS(I4,1,I4,1); 2343 VARABS(I4,-1,I4,1); 2344 VARABS(UI1,1,UI1,1); 2345 VARABS(R4,1,R4,1); 2346 VARABS(R4,-1,R4,1); 2347 VARABS(R8,1,R8,1); 2348 VARABS(R8,-1,R8,1); 2349 VARABS(DATE,1,DATE,1); 2350 VARABS(DATE,-1,DATE,1); 2351 V_VT(&v) = VT_CY; 2352 V_CY(&v).int64 = -10000; 2353 memset(&vDst,0,sizeof(vDst)); 2354 hres = pVarAbs(&v,&vDst); 2355 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000, 2356 "VarAbs(CY): expected 0x0 got 0x%X\n", hres); 2357 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char)); 2358 if (buff[1]) 2359 { 2360 trace("Skipping VarAbs(BSTR) as decimal separator is '%s'\n", buff); 2361 return; 2362 } else { 2363 szNum[2] = buff[0]; 2364 } 2365 V_VT(&v) = VT_BSTR; 2366 V_BSTR(&v) = (BSTR)szNum; 2367 memset(&vDst,0,sizeof(vDst)); 2368 hres = pVarAbs(&v,&vDst); 2369 ok(hres == S_OK && V_VT(&vDst) == VT_R8 && V_R8(&vDst) == 1.1, 2370 "VarAbs: expected 0x0,%d,%g, got 0x%X,%d,%g\n", VT_R8, 1.1, hres, V_VT(&vDst), V_R8(&vDst)); 2371 } 2372 2373 static HRESULT (WINAPI *pVarNot)(LPVARIANT,LPVARIANT); 2374 2375 #define VARNOT(vt,val,rvt,rval) \ 2376 V_VT(&v) = VT_##vt; V_##vt(&v) = val; \ 2377 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 2378 test_var_call1( __LINE__, pVarNot, &v, &exp ) 2379 2380 static void test_VarNot(void) 2381 { 2382 static const WCHAR szNum0[] = {'0','\0' }; 2383 static const WCHAR szNum1[] = {'1','\0' }; 2384 static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' }; 2385 static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' }; 2386 HRESULT hres; 2387 VARIANT v, exp, vDst; 2388 DECIMAL *pdec = &V_DECIMAL(&v); 2389 CY *pcy = &V_CY(&v); 2390 size_t i; 2391 2392 CHECKPTR(VarNot); 2393 2394 /* Test all possible V_VT values */ 2395 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 2396 { 2397 VARTYPE vt; 2398 2399 for (vt = 0; vt <= VT_BSTR_BLOB; vt++) 2400 { 2401 HRESULT hExpected = DISP_E_BADVARTYPE; 2402 2403 SKIPTESTS(vt); 2404 2405 memset(&v, 0, sizeof(v)); 2406 V_VT(&v) = vt | ExtraFlags[i]; 2407 V_VT(&vDst) = VT_EMPTY; 2408 2409 switch (V_VT(&v)) 2410 { 2411 case VT_I1: case VT_UI1: case VT_I2: case VT_UI2: 2412 case VT_INT: case VT_UINT: case VT_I4: case VT_UI4: 2413 case VT_R4: case VT_R8: 2414 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY: 2415 case VT_DATE: case VT_CY: 2416 hExpected = S_OK; 2417 break; 2418 case VT_I8: case VT_UI8: 2419 if (has_i8) 2420 hExpected = S_OK; 2421 break; 2422 case VT_RECORD: 2423 hExpected = DISP_E_TYPEMISMATCH; 2424 break; 2425 case VT_UNKNOWN: case VT_BSTR: case VT_DISPATCH: case VT_ERROR: 2426 hExpected = DISP_E_TYPEMISMATCH; 2427 break; 2428 default: 2429 if (IsValidVariantClearVT(vt, ExtraFlags[i]) && vt != VT_CLSID) 2430 hExpected = DISP_E_TYPEMISMATCH; 2431 break; 2432 } 2433 2434 hres = pVarNot(&v,&vDst); 2435 ok(hres == hExpected, "VarNot: expected 0x%X, got 0x%X vt %d|0x%X\n", 2436 hExpected, hres, vt, ExtraFlags[i]); 2437 } 2438 } 2439 /* Test the values returned by all cases that can succeed */ 2440 VARNOT(EMPTY,0,I2,-1); 2441 VARNOT(EMPTY,1,I2,-1); 2442 VARNOT(NULL,0,NULL,0); 2443 VARNOT(NULL,1,NULL,0); 2444 VARNOT(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE); 2445 VARNOT(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE); 2446 VARNOT(I1,-1,I4,0); 2447 VARNOT(I1,0,I4,-1); 2448 VARNOT(I2,-1,I2,0); 2449 VARNOT(I2,0,I2,-1); 2450 VARNOT(I2,1,I2,-2); 2451 VARNOT(I4,1,I4,-2); 2452 VARNOT(I4,0,I4,-1); 2453 VARNOT(UI1,1,UI1,254); 2454 VARNOT(UI1,0,UI1,255); 2455 VARNOT(UI2,0,I4,-1); 2456 VARNOT(UI2,1,I4,-2); 2457 VARNOT(UI4,0,I4,-1); 2458 VARNOT(UI4,1,I4,-2); 2459 VARNOT(INT,0,I4,-1); 2460 VARNOT(INT,1,I4,-2); 2461 VARNOT(UINT,0,I4,-1); 2462 VARNOT(UINT,1,I4,-2); 2463 if (has_i8) 2464 { 2465 VARNOT(I8,1,I8,-2); 2466 VARNOT(I8,0,I8,-1); 2467 VARNOT(UI8,0,I4,-1); 2468 VARNOT(UI8,1,I4,-2); 2469 } 2470 VARNOT(R4,1,I4,-2); 2471 VARNOT(R4,0,I4,-1); 2472 VARNOT(R8,1,I4,-2); 2473 VARNOT(R8,0,I4,-1); 2474 VARNOT(DATE,1,I4,-2); 2475 VARNOT(DATE,0,I4,-1); 2476 VARNOT(BSTR,(BSTR)szNum0,I4,-1); 2477 ok(V_VT(&v) == VT_BSTR && V_BSTR(&v) == szNum0, "VarNot(0): changed input\n"); 2478 VARNOT(BSTR,(BSTR)szNum1,I4,-2); 2479 ok(V_VT(&v) == VT_BSTR && V_BSTR(&v) == szNum1, "VarNot(1): changed input\n"); 2480 VARNOT(BSTR, (BSTR)szTrue, BOOL, VARIANT_FALSE); 2481 VARNOT(BSTR, (BSTR)szFalse, BOOL, VARIANT_TRUE); 2482 2483 S(U(*pdec)).sign = DECIMAL_NEG; 2484 S(U(*pdec)).scale = 0; 2485 pdec->Hi32 = 0; 2486 S1(U1(*pdec)).Mid32 = 0; 2487 S1(U1(*pdec)).Lo32 = 1; 2488 VARNOT(DECIMAL,*pdec,I4,0); 2489 2490 pcy->int64 = 10000; 2491 VARNOT(CY,*pcy,I4,-2); 2492 2493 pcy->int64 = 0; 2494 VARNOT(CY,*pcy,I4,-1); 2495 2496 pcy->int64 = -1; 2497 VARNOT(CY,*pcy,I4,-1); 2498 } 2499 2500 static HRESULT (WINAPI *pVarSub)(LPVARIANT,LPVARIANT,LPVARIANT); 2501 2502 #define VARSUB(vt1,val1,vt2,val2,rvt,rval) \ 2503 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \ 2504 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \ 2505 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 2506 test_var_call2( __LINE__, pVarSub, &left, &right, &exp ) 2507 2508 static void test_VarSub(void) 2509 { 2510 VARIANT left, right, exp, result, cy, dec; 2511 VARTYPE i; 2512 BSTR lbstr, rbstr; 2513 HRESULT hres, expectedhres; 2514 double r; 2515 2516 CHECKPTR(VarSub); 2517 2518 lbstr = SysAllocString(sz12); 2519 rbstr = SysAllocString(sz12); 2520 2521 VariantInit(&left); 2522 VariantInit(&right); 2523 VariantInit(&result); 2524 2525 /* Test all possible flag/vt combinations & the resulting vt type */ 2526 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 2527 { 2528 2529 VARTYPE leftvt, rightvt, resvt; 2530 2531 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++) 2532 { 2533 2534 SKIPTESTS(leftvt); 2535 2536 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++) 2537 { 2538 2539 SKIPTESTS(rightvt); 2540 expectedhres = S_OK; 2541 2542 memset(&left, 0, sizeof(left)); 2543 memset(&right, 0, sizeof(right)); 2544 V_VT(&left) = leftvt | ExtraFlags[i]; 2545 if (leftvt == VT_BSTR) 2546 V_BSTR(&left) = lbstr; 2547 V_VT(&right) = rightvt | ExtraFlags[i]; 2548 if (rightvt == VT_BSTR) 2549 V_BSTR(&right) = rbstr; 2550 V_VT(&result) = VT_EMPTY; 2551 2552 /* All extra flags produce errors */ 2553 if (ExtraFlags[i] == (VT_VECTOR|VT_BYREF|VT_RESERVED) || 2554 ExtraFlags[i] == (VT_VECTOR|VT_RESERVED) || 2555 ExtraFlags[i] == (VT_VECTOR|VT_BYREF) || 2556 ExtraFlags[i] == (VT_BYREF|VT_RESERVED) || 2557 ExtraFlags[i] == VT_VECTOR || 2558 ExtraFlags[i] == VT_BYREF || 2559 ExtraFlags[i] == VT_RESERVED) 2560 { 2561 expectedhres = DISP_E_BADVARTYPE; 2562 resvt = VT_EMPTY; 2563 } 2564 else if (ExtraFlags[i] >= VT_ARRAY) 2565 { 2566 expectedhres = DISP_E_TYPEMISMATCH; 2567 resvt = VT_EMPTY; 2568 } 2569 /* Native VarSub cannot handle: VT_I1, VT_UI2, VT_UI4, 2570 VT_INT, VT_UINT and VT_UI8. Tested with WinXP */ 2571 else if (!IsValidVariantClearVT(leftvt, ExtraFlags[i]) || 2572 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) || 2573 leftvt == VT_CLSID || rightvt == VT_CLSID || 2574 leftvt == VT_VARIANT || rightvt == VT_VARIANT || 2575 leftvt == VT_I1 || rightvt == VT_I1 || 2576 leftvt == VT_UI2 || rightvt == VT_UI2 || 2577 leftvt == VT_UI4 || rightvt == VT_UI4 || 2578 leftvt == VT_UI8 || rightvt == VT_UI8 || 2579 leftvt == VT_INT || rightvt == VT_INT || 2580 leftvt == VT_UINT || rightvt == VT_UINT || 2581 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN || 2582 leftvt == VT_RECORD || rightvt == VT_RECORD) 2583 { 2584 if (leftvt == VT_RECORD && rightvt == VT_I8) 2585 { 2586 if (has_i8) 2587 expectedhres = DISP_E_TYPEMISMATCH; 2588 else 2589 expectedhres = DISP_E_BADVARTYPE; 2590 } 2591 else if (leftvt < VT_UI1 && rightvt == VT_RECORD) 2592 expectedhres = DISP_E_TYPEMISMATCH; 2593 else if (leftvt >= VT_UI1 && rightvt == VT_RECORD) 2594 expectedhres = DISP_E_TYPEMISMATCH; 2595 else if (leftvt == VT_RECORD && rightvt <= VT_UI1) 2596 expectedhres = DISP_E_TYPEMISMATCH; 2597 else if (leftvt == VT_RECORD && rightvt > VT_UI1) 2598 expectedhres = DISP_E_BADVARTYPE; 2599 else 2600 expectedhres = DISP_E_BADVARTYPE; 2601 resvt = VT_EMPTY; 2602 } 2603 else if ((leftvt == VT_NULL && rightvt == VT_DISPATCH) || 2604 (leftvt == VT_DISPATCH && rightvt == VT_NULL)) 2605 resvt = VT_NULL; 2606 else if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH || 2607 leftvt == VT_ERROR || rightvt == VT_ERROR) 2608 { 2609 resvt = VT_EMPTY; 2610 expectedhres = DISP_E_TYPEMISMATCH; 2611 } 2612 else if (leftvt == VT_NULL || rightvt == VT_NULL) 2613 resvt = VT_NULL; 2614 else if ((leftvt == VT_EMPTY && rightvt == VT_BSTR) || 2615 (leftvt == VT_DATE && rightvt == VT_DATE) || 2616 (leftvt == VT_BSTR && rightvt == VT_EMPTY) || 2617 (leftvt == VT_BSTR && rightvt == VT_BSTR)) 2618 resvt = VT_R8; 2619 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL) 2620 resvt = VT_DECIMAL; 2621 else if (leftvt == VT_DATE || rightvt == VT_DATE) 2622 resvt = VT_DATE; 2623 else if (leftvt == VT_CY || rightvt == VT_CY) 2624 resvt = VT_CY; 2625 else if (leftvt == VT_R8 || rightvt == VT_R8) 2626 resvt = VT_R8; 2627 else if (leftvt == VT_BSTR || rightvt == VT_BSTR) { 2628 resvt = VT_R8; 2629 } else if (leftvt == VT_R4 || rightvt == VT_R4) { 2630 if (leftvt == VT_I4 || rightvt == VT_I4 || 2631 leftvt == VT_I8 || rightvt == VT_I8) 2632 resvt = VT_R8; 2633 else 2634 resvt = VT_R4; 2635 } 2636 else if (leftvt == VT_I8 || rightvt == VT_I8) 2637 resvt = VT_I8; 2638 else if (leftvt == VT_I4 || rightvt == VT_I4) 2639 resvt = VT_I4; 2640 else if (leftvt == VT_I2 || rightvt == VT_I2 || 2641 leftvt == VT_BOOL || rightvt == VT_BOOL || 2642 (leftvt == VT_EMPTY && rightvt == VT_EMPTY)) 2643 resvt = VT_I2; 2644 else if (leftvt == VT_UI1 || rightvt == VT_UI1) 2645 resvt = VT_UI1; 2646 else 2647 { 2648 resvt = VT_EMPTY; 2649 expectedhres = DISP_E_TYPEMISMATCH; 2650 } 2651 2652 hres = pVarSub(&left, &right, &result); 2653 2654 ok(hres == expectedhres && V_VT(&result) == resvt, 2655 "VarSub: %d|0x%X, %d|0x%X: Expected failure 0x%X, " 2656 "got 0x%X, expected vt %d got vt %d\n", 2657 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], 2658 expectedhres, hres, resvt, V_VT(&result)); 2659 } 2660 } 2661 } 2662 2663 /* Test returned values */ 2664 VARSUB(I4,4,I4,2,I4,2); 2665 VARSUB(I2,4,I2,2,I2,2); 2666 VARSUB(I2,-13,I4,5,I4,-18); 2667 VARSUB(I4,-13,I4,5,I4,-18); 2668 VARSUB(I2,7,R4,0.5f,R4,6.5f); 2669 VARSUB(R4,0.5f,I4,5,R8,-4.5); 2670 VARSUB(R8,7.1,BOOL,0,R8,7.1); 2671 VARSUB(BSTR,lbstr,I2,4,R8,8); 2672 VARSUB(BSTR,lbstr,BOOL,1,R8,11); 2673 VARSUB(BSTR,lbstr,R4,0.1f,R8,11.9); 2674 VARSUB(R4,0.2f,BSTR,rbstr,R8,-11.8); 2675 VARSUB(DATE,2.25,I4,7,DATE,-4.75); 2676 VARSUB(DATE,1.25,R4,-1.7f,DATE,2.95); 2677 2678 VARSUB(UI1, UI1_MAX, UI1, UI1_MAX, UI1, 0); 2679 VARSUB(I2, I2_MAX, I2, I2_MAX, I2, 0); 2680 VARSUB(I2, I2_MIN, I2, I2_MIN, I2, 0); 2681 VARSUB(I4, I4_MAX, I4, I4_MAX, I4, 0); 2682 VARSUB(I4, I4_MIN, I4, I4_MIN, I4, 0); 2683 VARSUB(R4, R4_MAX, R4, R4_MAX, R4, 0.0f); 2684 VARSUB(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX - R4_MIN); 2685 VARSUB(R4, R4_MIN, R4, R4_MIN, R4, 0.0f); 2686 VARSUB(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX - R8_MIN); 2687 VARSUB(R8, R8_MIN, R8, R8_MIN, R8, 0.0); 2688 2689 /* Manually test BSTR + BSTR */ 2690 V_VT(&left) = VT_BSTR; 2691 V_BSTR(&left) = lbstr; 2692 V_VT(&right) = VT_BSTR; 2693 V_BSTR(&right) = rbstr; 2694 hres = pVarSub(&left, &right, &result); 2695 ok(hres == S_OK && V_VT(&result) == VT_R8, 2696 "VarSub: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result))); 2697 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 0.0), 2698 "VarSub: BSTR + BSTR, expected %f got %f\n", 0.0, V_R8(&result)); 2699 2700 /* Manually test some VT_CY and VT_DECIMAL variants */ 2701 V_VT(&cy) = VT_CY; 2702 hres = VarCyFromI4(4711, &V_CY(&cy)); 2703 ok(hres == S_OK, "VarCyFromI4 failed!\n"); 2704 V_VT(&dec) = VT_DECIMAL; 2705 hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec)); 2706 ok(hres == S_OK, "VarDecFromR4 failed!\n"); 2707 memset(&left, 0, sizeof(left)); 2708 memset(&right, 0, sizeof(right)); 2709 V_VT(&left) = VT_I4; 2710 V_I4(&left) = -11; 2711 V_VT(&right) = VT_UI1; 2712 V_UI1(&right) = 9; 2713 2714 hres = pVarSub(&cy, &right, &result); 2715 ok(hres == S_OK && V_VT(&result) == VT_CY, 2716 "VarSub: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result))); 2717 hres = VarR8FromCy(V_CY(&result), &r); 2718 ok(hres == S_OK && EQ_DOUBLE(r, 4702.0), 2719 "VarSub: CY value %f, expected %f\n", r, (double)4720); 2720 2721 hres = pVarSub(&left, &dec, &result); 2722 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL, 2723 "VarSub: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result))); 2724 hres = VarR8FromDec(&V_DECIMAL(&result), &r); 2725 ok(hres == S_OK && EQ_DOUBLE(r, -6.8), 2726 "VarSub: DECIMAL value %f, expected %f\n", r, (double)-15.2); 2727 2728 SysFreeString(lbstr); 2729 SysFreeString(rbstr); 2730 } 2731 2732 static HRESULT (WINAPI *pVarMod)(LPVARIANT,LPVARIANT,LPVARIANT); 2733 2734 static void test_Mod( int line, VARIANT *left, VARIANT *right, VARIANT *expected, HRESULT expres ) 2735 { 2736 VARIANT result; 2737 HRESULT hres; 2738 2739 memset( &result, 0, sizeof(result) ); 2740 hres = pVarMod( left, right, &result ); 2741 ok_(__FILE__,line)( hres == expres, "wrong result %x/%x\n", hres, expres ); 2742 if (hres == S_OK) 2743 ok_(__FILE__,line)( is_expected_variant( &result, expected ), 2744 "got %s expected %s\n", variantstr(&result), variantstr(expected) ); 2745 } 2746 2747 #define VARMOD(vt1,vt2,val1,val2,rvt,rval) \ 2748 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \ 2749 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \ 2750 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 2751 test_var_call2( __LINE__, pVarMod, &left, &right, &exp ) 2752 2753 #define VARMOD2(vt1,vt2,val1,val2,rvt,rval,hexpected) \ 2754 V_VT(&left) = VT_##vt1; V_I4(&left) = val1; \ 2755 V_VT(&right) = VT_##vt2; V_I4(&right) = val2; \ 2756 V_VT(&exp) = VT_##rvt; V_I4(&exp) = rval; \ 2757 test_Mod( __LINE__, &left, &right, &exp, hexpected ) 2758 2759 static void test_VarMod(void) 2760 { 2761 VARIANT v1, v2, vDst, left, right, exp; 2762 HRESULT hres; 2763 HRESULT hexpected = 0; 2764 static const WCHAR szNum0[] = {'1','2','5','\0'}; 2765 static const WCHAR szNum1[] = {'1','0','\0'}; 2766 int l, r; 2767 BOOL lFound, rFound; 2768 BOOL lValid; 2769 BSTR strNum0, strNum1; 2770 2771 CHECKPTR(VarMod); 2772 2773 VARMOD(I1,BOOL,100,10,I4,0); 2774 VARMOD(I1,I1,100,10,I4,0); 2775 VARMOD(I1,UI1,100,10,I4,0); 2776 VARMOD(I1,I2,100,10,I4,0); 2777 VARMOD(I1,UI2,100,10,I4,0); 2778 VARMOD(I1,I4,100,10,I4,0); 2779 VARMOD(I1,UI4,100,10,I4,0); 2780 VARMOD(I1,R4,100,10,I4,0); 2781 VARMOD(I1,R8,100,10,I4,0); 2782 2783 VARMOD(UI1,BOOL,100,10,I2,0); 2784 VARMOD(UI1,I1,100,10,I4,0); 2785 VARMOD(UI1,UI1,100,10,UI1,0); 2786 VARMOD(UI1,I2,100,10,I2,0); 2787 VARMOD(UI1,UI2,100,10,I4,0); 2788 VARMOD(UI1,I4,100,10,I4,0); 2789 VARMOD(UI1,UI4,100,10,I4,0); 2790 VARMOD(UI1,R4,100,10,I4,0); 2791 VARMOD(UI1,R8,100,10,I4,0); 2792 2793 VARMOD(I2,BOOL,100,10,I2,0); 2794 VARMOD(I2,I1,100,10,I4,0); 2795 VARMOD(I2,UI1,100,10,I2,0); 2796 VARMOD(I2,I2,100,10,I2,0); 2797 VARMOD(I2,UI2,100,10,I4,0); 2798 VARMOD(I2,I4,100,10,I4,0); 2799 VARMOD(I2,UI4,100,10,I4,0); 2800 VARMOD(I2,R4,100,10,I4,0); 2801 VARMOD(I2,R8,100,10,I4,0); 2802 2803 VARMOD(I4,BOOL,100,10,I4,0); 2804 VARMOD(I4,I1,100,10,I4,0); 2805 VARMOD(I4,UI1,100,10,I4,0); 2806 VARMOD(I4,I2,100,10,I4,0); 2807 VARMOD(I4,UI2,100,10,I4,0); 2808 VARMOD(I4,I4,100,10,I4,0); 2809 VARMOD(I4,UI4,100,10,I4,0); 2810 VARMOD(I4,R4,100,10,I4,0); 2811 VARMOD(I4,R8,100,10,I4,0); 2812 VARMOD(UI4,BOOL,100,10,I4,0); 2813 VARMOD(UI4,I1,100,10,I4,0); 2814 VARMOD(UI4,UI1,100,10,I4,0); 2815 VARMOD(UI4,I2,100,10,I4,0); 2816 VARMOD(UI4,UI2,100,10,I4,0); 2817 VARMOD(UI4,I4,100,10,I4,0); 2818 VARMOD(UI4,UI4,100,10,I4,0); 2819 VARMOD(UI4,R4,100,10,I4,0); 2820 VARMOD(UI4,R8,100,10,I4,0); 2821 VARMOD(R4,BOOL,100,10,I4,0); 2822 VARMOD(R4,I1,100,10,I4,0); 2823 VARMOD(R4,UI1,100,10,I4,0); 2824 VARMOD(R4,I2,100,10,I4,0); 2825 VARMOD(R4,UI2,100,10,I4,0); 2826 VARMOD(R4,I4,100,10,I4,0); 2827 VARMOD(R4,UI4,100,10,I4,0); 2828 VARMOD(R4,R4,100,10,I4,0); 2829 VARMOD(R4,R8,100,10,I4,0); 2830 VARMOD(R8,BOOL,100,10,I4,0); 2831 VARMOD(R8,I1,100,10,I4,0); 2832 VARMOD(R8,UI1,100,10,I4,0); 2833 VARMOD(R8,I2,100,10,I4,0); 2834 VARMOD(R8,UI2,100,10,I4,0); 2835 VARMOD(R8,I4,100,10,I4,0); 2836 VARMOD(R8,UI4,100,10,I4,0); 2837 VARMOD(R8,R4,100,10,I4,0); 2838 VARMOD(R8,R8,100,10,I4,0); 2839 2840 VARMOD(INT,INT,100,10,I4,0); 2841 VARMOD(INT,UINT,100,10,I4,0); 2842 2843 VARMOD(BOOL,BOOL,100,10,I2,0); 2844 VARMOD(BOOL,I1,100,10,I4,0); 2845 VARMOD(BOOL,UI1,100,10,I2,0); 2846 VARMOD(BOOL,I2,100,10,I2,0); 2847 VARMOD(BOOL,UI2,100,10,I4,0); 2848 VARMOD(BOOL,I4,100,10,I4,0); 2849 VARMOD(BOOL,UI4,100,10,I4,0); 2850 VARMOD(BOOL,R4,100,10,I4,0); 2851 VARMOD(BOOL,R8,100,10,I4,0); 2852 VARMOD(BOOL,DATE,100,10,I4,0); 2853 2854 VARMOD(DATE,BOOL,100,10,I4,0); 2855 VARMOD(DATE,I1,100,10,I4,0); 2856 VARMOD(DATE,UI1,100,10,I4,0); 2857 VARMOD(DATE,I2,100,10,I4,0); 2858 VARMOD(DATE,UI2,100,10,I4,0); 2859 VARMOD(DATE,I4,100,10,I4,0); 2860 VARMOD(DATE,UI4,100,10,I4,0); 2861 VARMOD(DATE,R4,100,10,I4,0); 2862 VARMOD(DATE,R8,100,10,I4,0); 2863 VARMOD(DATE,DATE,100,10,I4,0); 2864 2865 strNum0 = SysAllocString(szNum0); 2866 strNum1 = SysAllocString(szNum1); 2867 VARMOD(BSTR,BSTR,strNum0,strNum1,I4,5); 2868 VARMOD(BSTR,I1,strNum0,10,I4,5); 2869 VARMOD(BSTR,I2,strNum0,10,I4,5); 2870 VARMOD(BSTR,I4,strNum0,10,I4,5); 2871 VARMOD(BSTR,R4,strNum0,10,I4,5); 2872 VARMOD(BSTR,R8,strNum0,10,I4,5); 2873 VARMOD(I4,BSTR,125,strNum1,I4,5); 2874 2875 if (has_i8) 2876 { 2877 VARMOD(BOOL,I8,100,10,I8,0); 2878 VARMOD(I1,I8,100,10,I8,0); 2879 VARMOD(UI1,I8,100,10,I8,0); 2880 VARMOD(I2,I8,100,10,I8,0); 2881 VARMOD(I4,I8,100,10,I8,0); 2882 VARMOD(UI4,I8,100,10,I8,0); 2883 VARMOD(R4,I8,100,10,I8,0); 2884 VARMOD(R8,I8,100,10,I8,0); 2885 VARMOD(DATE,I8,100,10,I8,0); 2886 2887 VARMOD(I8,BOOL,100,10,I8,0); 2888 VARMOD(I8,I1,100,10,I8,0); 2889 VARMOD(I8,UI1,100,10,I8,0); 2890 VARMOD(I8,I2,100,10,I8,0); 2891 VARMOD(I8,UI2,100,10,I8,0); 2892 VARMOD(I8,I4,100,10,I8,0); 2893 VARMOD(I8,UI4,100,10,I8,0); 2894 VARMOD(I8,R4,100,10,I8,0); 2895 VARMOD(I8,R8,100,10,I8,0); 2896 VARMOD(I8,I8,100,10,I8,0); 2897 2898 VARMOD(BSTR,I8,strNum0,10,I8,5); 2899 } 2900 2901 /* test all combinations of types */ 2902 for(l = 0; l < VT_BSTR_BLOB; l++) 2903 { 2904 SKIPTESTS(l); 2905 2906 for(r = 0; r < VT_BSTR_BLOB; r++) 2907 { 2908 SKIPTESTS(r); 2909 2910 if(l == VT_BSTR) continue; 2911 if(l == VT_DISPATCH) continue; 2912 if(r == VT_BSTR) continue; 2913 if(r == VT_DISPATCH) continue; 2914 2915 lFound = TRUE; 2916 lValid = TRUE; 2917 switch(l) 2918 { 2919 case VT_EMPTY: 2920 case VT_NULL: 2921 case VT_I1: 2922 case VT_UI1: 2923 case VT_I2: 2924 case VT_UI2: 2925 case VT_I4: 2926 case VT_I8: 2927 case VT_UI4: 2928 case VT_UI8: 2929 case VT_INT: 2930 case VT_UINT: 2931 case VT_R4: 2932 case VT_R8: 2933 case VT_BOOL: 2934 case VT_DATE: 2935 case VT_CY: 2936 case VT_DECIMAL: 2937 hexpected = S_OK; 2938 break; 2939 case VT_ERROR: 2940 case VT_VARIANT: 2941 case VT_UNKNOWN: 2942 case VT_RECORD: 2943 lValid = FALSE; 2944 break; 2945 default: 2946 lFound = FALSE; 2947 hexpected = DISP_E_BADVARTYPE; 2948 break; 2949 } 2950 2951 rFound = TRUE; 2952 switch(r) 2953 { 2954 case VT_EMPTY: 2955 case VT_NULL: 2956 case VT_I1: 2957 case VT_UI1: 2958 case VT_I2: 2959 case VT_UI2: 2960 case VT_I4: 2961 case VT_I8: 2962 case VT_UI4: 2963 case VT_UI8: 2964 case VT_INT: 2965 case VT_UINT: 2966 case VT_R4: 2967 case VT_R8: 2968 case VT_BOOL: 2969 case VT_DATE: 2970 case VT_DECIMAL: 2971 case VT_CY: 2972 hexpected = S_OK; 2973 break; 2974 case VT_ERROR: 2975 case VT_VARIANT: 2976 case VT_UNKNOWN: 2977 case VT_RECORD: 2978 break; 2979 default: 2980 rFound = FALSE; 2981 break; 2982 } 2983 2984 if(((l == VT_I8) && (r == VT_INT)) || ((l == VT_INT) && (r == VT_I8))) 2985 { 2986 hexpected = DISP_E_TYPEMISMATCH; 2987 } else if((l == VT_EMPTY) && (r == VT_NULL)) 2988 { 2989 hexpected = S_OK; 2990 } else if((l == VT_NULL) && (r == VT_EMPTY)) 2991 { 2992 hexpected = S_OK; 2993 } else if((l == VT_EMPTY) && (r == VT_CY)) 2994 { 2995 hexpected = S_OK; 2996 } else if((l == VT_EMPTY) && (r == VT_RECORD)) 2997 { 2998 hexpected = DISP_E_TYPEMISMATCH; 2999 } else if((r == VT_EMPTY) && lFound && lValid) 3000 { 3001 hexpected = DISP_E_DIVBYZERO; 3002 } else if((l == VT_ERROR) || ((r == VT_ERROR) && lFound && lValid)) 3003 { 3004 hexpected = DISP_E_TYPEMISMATCH; 3005 } else if((l == VT_NULL) && (r == VT_NULL)) 3006 { 3007 hexpected = S_OK; 3008 } else if((l == VT_VARIANT) || ((r == VT_VARIANT) && lFound && lValid)) 3009 { 3010 hexpected = DISP_E_TYPEMISMATCH; 3011 } else if((l == VT_NULL) && (r == VT_RECORD)) 3012 { 3013 hexpected = DISP_E_TYPEMISMATCH; 3014 } else if((l == VT_I8) && (r == VT_DECIMAL)) 3015 { 3016 hexpected = S_OK; 3017 } else if((l == VT_DECIMAL) && (r == VT_I8)) 3018 { 3019 hexpected = S_OK; 3020 } else if((l == VT_UNKNOWN) || ((r == VT_UNKNOWN) && lFound && lValid)) 3021 { 3022 hexpected = DISP_E_TYPEMISMATCH; 3023 } else if((l == VT_NULL) && rFound) 3024 { 3025 hexpected = S_OK; 3026 } else if(l == VT_RECORD) 3027 { 3028 hexpected = DISP_E_TYPEMISMATCH; 3029 } else if((r == VT_RECORD) && lValid && lFound) 3030 { 3031 hexpected = DISP_E_TYPEMISMATCH; 3032 } else if((l == VT_EMPTY) && (r == VT_EMPTY)) 3033 { 3034 hexpected = DISP_E_DIVBYZERO; 3035 } else if((l == VT_CY) && !rFound) 3036 { 3037 hexpected = DISP_E_BADVARTYPE; 3038 } else if(lFound && !rFound) 3039 { 3040 hexpected = DISP_E_BADVARTYPE; 3041 } else if(!lFound && rFound) 3042 { 3043 hexpected = DISP_E_BADVARTYPE; 3044 } else if((r == VT_NULL) && lFound && lValid) 3045 { 3046 hexpected = S_OK; 3047 } else if((l == VT_NULL) || (r == VT_NULL)) 3048 { 3049 hexpected = DISP_E_BADVARTYPE; 3050 } else if((l == VT_VARIANT) || (r == VT_VARIANT)) 3051 { 3052 hexpected = DISP_E_BADVARTYPE; 3053 } else if(!lFound && !rFound) 3054 { 3055 hexpected = DISP_E_BADVARTYPE; 3056 } 3057 3058 V_VT(&v1) = l; 3059 V_VT(&v2) = r; 3060 3061 if(l == VT_CY) 3062 V_CY(&v1).int64 = 1000000; 3063 else if(l == VT_R4) 3064 V_R4(&v1) = 100; 3065 else if(l == VT_R8) 3066 V_R8(&v1) = 100; 3067 else if(l == VT_UI8) 3068 V_UI8(&v1) = 100; 3069 else if(l == VT_I8) 3070 V_I8(&v1) = 100; 3071 else if(l == VT_DATE) 3072 V_DATE(&v1) = 1000; 3073 else if (l == VT_DECIMAL) 3074 { 3075 V_DECIMAL(&v1).Hi32 = 0; 3076 U1(V_DECIMAL(&v1)).Lo64 = 100; 3077 U(V_DECIMAL(&v1)).signscale = 0; 3078 } 3079 else 3080 V_I4(&v1) = 10000; 3081 3082 if(r == VT_CY) 3083 V_CY(&v2).int64 = 10000; 3084 else if(r == VT_R4) 3085 V_R4(&v2) = 100; 3086 else if(r == VT_R8) 3087 V_R8(&v2) = 100; 3088 else if(r == VT_UI8) 3089 V_UI8(&v2) = 100; 3090 else if(r == VT_I8) 3091 V_I8(&v2) = 100; 3092 else if(r == VT_DATE) 3093 V_DATE(&v2) = 1000; 3094 else if (r == VT_DECIMAL) 3095 { 3096 V_DECIMAL(&v2).Hi32 = 0; 3097 U1(V_DECIMAL(&v2)).Lo64 = 100; 3098 U(V_DECIMAL(&v2)).signscale = 0; 3099 } 3100 else 3101 V_I4(&v2) = 10000; 3102 3103 if ((l != VT_I8 && l != VT_UI8 && r != VT_I8 && r != VT_UI8) || has_i8) 3104 { 3105 hres = pVarMod(&v1,&v2,&vDst); 3106 ok(hres == hexpected, 3107 "VarMod: expected 0x%x, got 0x%X for l type of %d, r type of %d,\n", hexpected, hres, l, r); 3108 } 3109 } 3110 } 3111 3112 3113 /****************************/ 3114 /* test some bad parameters */ 3115 VARMOD(I4,I4,-1,-1,I4,0); 3116 3117 /* test modulus with zero */ 3118 VARMOD2(I4,I4,100,0,EMPTY,0,DISP_E_DIVBYZERO); 3119 3120 VARMOD(I4,I4,0,10,I4,0); /* test 0 mod 10 */ 3121 3122 /* right parameter is type empty */ 3123 VARMOD2(I4,EMPTY,100,10,EMPTY,0,DISP_E_DIVBYZERO); 3124 3125 /* left parameter is type empty */ 3126 VARMOD2(EMPTY,I4,100,10,I4,0,S_OK); 3127 3128 /* mod with a null left value */ 3129 VARMOD2(NULL,I4,125,10,NULL,0,S_OK); 3130 3131 /* mod with a null right value */ 3132 VARMOD2(I4,NULL,100,10,NULL,0,S_OK); 3133 3134 /* void left value */ 3135 VARMOD2(VOID,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3136 3137 /* void right value */ 3138 VARMOD2(I4,VOID,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3139 3140 /* null left value, void right value */ 3141 VARMOD2(NULL,VOID,100,10,EMPTY, 0, DISP_E_BADVARTYPE); 3142 3143 /* void left value, null right value */ 3144 VARMOD2(VOID,NULL,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3145 3146 /* some currencies */ 3147 V_VT(&v1) = VT_CY; 3148 V_VT(&v2) = VT_CY; 3149 V_CY(&v1).int64 = 100000; 3150 V_CY(&v2).int64 = 100000; 3151 hres = pVarMod(&v1,&v2,&vDst); 3152 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0, 3153 "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst)); 3154 3155 V_VT(&v1) = VT_I4; 3156 V_VT(&v2) = VT_CY; 3157 V_I4(&v1) = 100; 3158 V_CY(&v2).int64 = 100000; 3159 hres = pVarMod(&v1,&v2,&vDst); 3160 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0, 3161 "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst)); 3162 3163 /* some decimals */ 3164 V_VT(&v1) = VT_DECIMAL; 3165 V_VT(&v2) = VT_DECIMAL; 3166 VarDecFromI4(100, &V_DECIMAL(&v1)); 3167 VarDecFromI4(10, &V_DECIMAL(&v2)); 3168 hres = pVarMod(&v1,&v2,&vDst); 3169 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0, 3170 "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst)); 3171 3172 V_VT(&v1) = VT_I4; 3173 V_VT(&v2) = VT_DECIMAL; 3174 V_I4(&v1) = 100; 3175 VarDecFromI4(10, &V_DECIMAL(&v2)); 3176 hres = pVarMod(&v1,&v2,&vDst); 3177 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0, 3178 "VarMod: expected 0x%x,%d,%d, got 0x%X,%d,%d\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst)); 3179 3180 VARMOD2(UINT,I4,100,10,I4,0,S_OK); 3181 3182 /* test that an error results in the type of the result changing but not its value */ 3183 V_VT(&v1) = VT_UNKNOWN; 3184 V_VT(&v2) = VT_EMPTY; 3185 V_I4(&v1) = 100; 3186 V_CY(&v2).int64 = 100000; 3187 V_VT(&vDst) = VT_I4; 3188 V_I4(&vDst) = 1231; 3189 hres = pVarMod(&v1,&v2,&vDst); 3190 ok(hres == DISP_E_TYPEMISMATCH && V_VT(&vDst) == VT_EMPTY && V_I4(&vDst) == 1231, 3191 "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)); 3192 3193 3194 /* test some invalid types */ 3195 /*TODO: not testing VT_DISPATCH */ 3196 if (has_i8) 3197 { 3198 VARMOD2(I8,INT,100,10,EMPTY,0,DISP_E_TYPEMISMATCH); 3199 } 3200 VARMOD2(ERROR,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH); 3201 VARMOD2(VARIANT,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH); 3202 VARMOD2(UNKNOWN,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH); 3203 VARMOD2(VOID,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3204 VARMOD2(HRESULT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3205 VARMOD2(PTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3206 VARMOD2(SAFEARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3207 VARMOD2(CARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3208 VARMOD2(USERDEFINED,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3209 VARMOD2(LPSTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3210 VARMOD2(LPWSTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3211 VARMOD2(RECORD,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH); 3212 VARMOD2(FILETIME,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3213 VARMOD2(BLOB,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3214 VARMOD2(STREAM,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3215 VARMOD2(STORAGE,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3216 VARMOD2(STREAMED_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3217 VARMOD2(STORED_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3218 VARMOD2(BLOB_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3219 VARMOD2(CF,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3220 VARMOD2(CLSID,CLSID,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3221 VARMOD2(VECTOR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3222 VARMOD2(ARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3223 VARMOD2(BYREF,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE); 3224 3225 /* test some more invalid types */ 3226 V_VT(&v1) = 456; 3227 V_VT(&v2) = 234; 3228 V_I4(&v1) = 100; 3229 V_I4(&v2)= 10; 3230 hres = pVarMod(&v1,&v2,&vDst); 3231 ok(hres == DISP_E_BADVARTYPE && V_VT(&vDst) == VT_EMPTY, 3232 "VarMod: expected 0x%x,%d, got 0x%X,%d\n", DISP_E_BADVARTYPE, VT_EMPTY, hres, V_VT(&vDst)); 3233 3234 SysFreeString(strNum0); 3235 SysFreeString(strNum1); 3236 } 3237 3238 static HRESULT (WINAPI *pVarFix)(LPVARIANT,LPVARIANT); 3239 3240 #define VARFIX(vt,val,rvt,rval) \ 3241 V_VT(&v) = VT_##vt; V_##vt(&v) = val; \ 3242 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 3243 test_var_call1( __LINE__, pVarFix, &v, &exp ) 3244 3245 static void test_VarFix(void) 3246 { 3247 static const WCHAR szNumMinus1[] = {'-','1','\0' }; 3248 HRESULT hres; 3249 VARIANT v, exp, vDst; 3250 DECIMAL *pdec = &V_DECIMAL(&v); 3251 CY *pcy = &V_CY(&v); 3252 size_t i; 3253 3254 CHECKPTR(VarFix); 3255 3256 /* Test all possible V_VT values */ 3257 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 3258 { 3259 VARTYPE vt; 3260 3261 for (vt = 0; vt <= VT_BSTR_BLOB; vt++) 3262 { 3263 BOOL bFail = TRUE; 3264 3265 SKIPTESTS(vt); 3266 3267 memset(&v, 0, sizeof(v)); 3268 V_VT(&v) = vt | ExtraFlags[i]; 3269 V_VT(&vDst) = VT_EMPTY; 3270 3271 switch (V_VT(&v)) 3272 { 3273 case VT_UI1: case VT_I2: case VT_I4: case VT_R4: case VT_R8: 3274 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY: 3275 case VT_DATE: case VT_CY: 3276 bFail = FALSE; 3277 break; 3278 case VT_I8: 3279 if (has_i8) 3280 bFail = FALSE; 3281 break; 3282 } 3283 3284 hres = pVarFix(&v,&vDst); 3285 if (bFail) 3286 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE, 3287 "VarFix: expected failure, got 0x%X vt %d|0x%X\n", 3288 hres, vt, ExtraFlags[i]); 3289 else 3290 ok(hres == S_OK, "VarFix: expected S_OK, got 0x%X vt %d|0x%X\n", 3291 hres, vt, ExtraFlags[i]); 3292 } 3293 } 3294 3295 VARFIX(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE); 3296 VARFIX(BOOL,VARIANT_FALSE,I2,0); 3297 VARFIX(BOOL,1,I2,1); 3298 VARFIX(UI1,1,UI1,1); 3299 VARFIX(I2,-1,I2,-1); 3300 VARFIX(I4,-1,I4,-1); 3301 if (has_i8) 3302 { 3303 VARFIX(I8,-1,I8,-1); 3304 } 3305 VARFIX(R4,1.4f,R4,1); 3306 VARFIX(R4,1.5f,R4,1); 3307 VARFIX(R4,1.6f,R4,1); 3308 VARFIX(R4,-1.4f,R4,-1); 3309 VARFIX(R4,-1.5f,R4,-1); 3310 VARFIX(R4,-1.6f,R4,-1); 3311 /* DATE & R8 round as for R4 */ 3312 VARFIX(DATE,-1,DATE,-1); 3313 VARFIX(R8,-1,R8,-1); 3314 VARFIX(BSTR,(BSTR)szNumMinus1,R8,-1); 3315 3316 V_VT(&v) = VT_EMPTY; 3317 hres = pVarFix(&v,&vDst); 3318 ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0, 3319 "VarFix: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY, 3320 hres, V_VT(&vDst), V_I2(&vDst)); 3321 3322 V_VT(&v) = VT_NULL; 3323 hres = pVarFix(&v,&vDst); 3324 ok(hres == S_OK && V_VT(&vDst) == VT_NULL, 3325 "VarFix: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst)); 3326 3327 V_VT(&v) = VT_DECIMAL; 3328 S(U(*pdec)).sign = DECIMAL_NEG; 3329 S(U(*pdec)).scale = 0; 3330 pdec->Hi32 = 0; 3331 S1(U1(*pdec)).Mid32 = 0; 3332 S1(U1(*pdec)).Lo32 = 1; 3333 hres = pVarFix(&v,&vDst); 3334 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && !memcmp(&V_DECIMAL(&v), &V_DECIMAL(&vDst), sizeof(DECIMAL)), 3335 "VarFix: expected 0x0,%d,identical, got 0x%X,%d\n", VT_DECIMAL, 3336 hres, V_VT(&vDst)); 3337 3338 /* FIXME: Test some fractional decimals when VarDecFix is implemented */ 3339 3340 V_VT(&v) = VT_CY; 3341 pcy->int64 = -10000; 3342 hres = pVarFix(&v,&vDst); 3343 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000, 3344 "VarFix: VT_CY wrong, hres=0x%X\n", hres); 3345 3346 V_VT(&v) = VT_CY; 3347 pcy->int64 = -16000; 3348 hres = pVarFix(&v,&vDst); 3349 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000, 3350 "VarFix: VT_CY wrong, hres=0x%X\n", hres); 3351 } 3352 3353 static HRESULT (WINAPI *pVarInt)(LPVARIANT,LPVARIANT); 3354 3355 #define VARINT(vt,val,rvt,rval) \ 3356 V_VT(&v) = VT_##vt; V_##vt(&v) = val; \ 3357 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 3358 test_var_call1( __LINE__, pVarInt, &v, &exp ) 3359 3360 static void test_VarInt(void) 3361 { 3362 static const WCHAR szNumMinus1[] = {'-','1','\0' }; 3363 HRESULT hres; 3364 VARIANT v, exp, vDst; 3365 DECIMAL *pdec = &V_DECIMAL(&v); 3366 CY *pcy = &V_CY(&v); 3367 size_t i; 3368 3369 CHECKPTR(VarInt); 3370 3371 /* Test all possible V_VT values */ 3372 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 3373 { 3374 VARTYPE vt; 3375 3376 for (vt = 0; vt <= VT_BSTR_BLOB; vt++) 3377 { 3378 BOOL bFail = TRUE; 3379 3380 SKIPTESTS(vt); 3381 3382 memset(&v, 0, sizeof(v)); 3383 V_VT(&v) = vt | ExtraFlags[i]; 3384 V_VT(&vDst) = VT_EMPTY; 3385 3386 switch (V_VT(&v)) 3387 { 3388 case VT_UI1: case VT_I2: case VT_I4: case VT_R4: case VT_R8: 3389 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY: 3390 case VT_DATE: case VT_CY: 3391 bFail = FALSE; 3392 break; 3393 case VT_I8: 3394 if (has_i8) 3395 bFail = FALSE; 3396 break; 3397 } 3398 3399 hres = pVarInt(&v,&vDst); 3400 if (bFail) 3401 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE, 3402 "VarInt: expected failure, got 0x%X vt %d|0x%X\n", 3403 hres, vt, ExtraFlags[i]); 3404 else 3405 ok(hres == S_OK, "VarInt: expected S_OK, got 0x%X vt %d|0x%X\n", 3406 hres, vt, ExtraFlags[i]); 3407 } 3408 } 3409 3410 VARINT(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE); 3411 VARINT(BOOL,VARIANT_FALSE,I2,0); 3412 VARINT(BOOL,1,I2,1); 3413 VARINT(UI1,1,UI1,1); 3414 VARINT(I2,-1,I2,-1); 3415 VARINT(I4,-1,I4,-1); 3416 if (has_i8) 3417 { 3418 VARINT(I8,-1,I8,-1); 3419 } 3420 VARINT(R4,1.4f,R4,1); 3421 VARINT(R4,1.5f,R4,1); 3422 VARINT(R4,1.6f,R4,1); 3423 VARINT(R4,-1.4f,R4,-2); /* Note these 3 are different from VarFix */ 3424 VARINT(R4,-1.5f,R4,-2); 3425 VARINT(R4,-1.6f,R4,-2); 3426 /* DATE & R8 round as for R4 */ 3427 VARINT(DATE,-1,DATE,-1); 3428 VARINT(R8,-1,R8,-1); 3429 VARINT(BSTR,(BSTR)szNumMinus1,R8,-1); 3430 3431 V_VT(&v) = VT_EMPTY; 3432 hres = pVarInt(&v,&vDst); 3433 ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0, 3434 "VarInt: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY, 3435 hres, V_VT(&vDst), V_I2(&vDst)); 3436 3437 V_VT(&v) = VT_NULL; 3438 hres = pVarInt(&v,&vDst); 3439 ok(hres == S_OK && V_VT(&vDst) == VT_NULL, 3440 "VarInt: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst)); 3441 3442 V_VT(&v) = VT_DECIMAL; 3443 S(U(*pdec)).sign = DECIMAL_NEG; 3444 S(U(*pdec)).scale = 0; 3445 pdec->Hi32 = 0; 3446 S1(U1(*pdec)).Mid32 = 0; 3447 S1(U1(*pdec)).Lo32 = 1; 3448 hres = pVarInt(&v,&vDst); 3449 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && !memcmp(&V_DECIMAL(&v), &V_DECIMAL(&vDst), sizeof(DECIMAL)), 3450 "VarInt: expected 0x0,%d,identical, got 0x%X,%d\n", VT_DECIMAL, 3451 hres, V_VT(&vDst)); 3452 3453 /* FIXME: Test some fractional decimals when VarDecInt is implemented */ 3454 3455 V_VT(&v) = VT_CY; 3456 pcy->int64 = -10000; 3457 hres = pVarInt(&v,&vDst); 3458 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000, 3459 "VarInt: VT_CY wrong, hres=0x%X\n", hres); 3460 3461 V_VT(&v) = VT_CY; 3462 pcy->int64 = -11000; 3463 hres = pVarInt(&v,&vDst); 3464 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -20000, 3465 "VarInt: VT_CY wrong, hres=0x%X 0x%x%08x\n", 3466 hres, (DWORD)(V_CY(&vDst).int64 >> 32), (DWORD)V_CY(&vDst).int64); 3467 } 3468 3469 static HRESULT (WINAPI *pVarNeg)(LPVARIANT,LPVARIANT); 3470 3471 #define VARNEG(vt,val,rvt,rval) \ 3472 V_VT(&v) = VT_##vt; V_##vt(&v) = val; \ 3473 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 3474 test_var_call1( __LINE__, pVarNeg, &v, &exp ) 3475 3476 static void test_VarNeg(void) 3477 { 3478 static const WCHAR szNumMinus1[] = {'-','1','\0' }; 3479 static const WCHAR szNum1[] = {'1','\0' }; 3480 HRESULT hres; 3481 VARIANT v, exp, vDst; 3482 DECIMAL *pdec = &V_DECIMAL(&v); 3483 CY *pcy = &V_CY(&v); 3484 size_t i; 3485 3486 CHECKPTR(VarNeg); 3487 3488 /* Test all possible V_VT values. But don't test the exact return values 3489 * except for success/failure, since M$ made a hash of them in the 3490 * native version. This at least ensures (as with all tests here) that 3491 * we will notice if/when new vtypes/flags are added in native. 3492 */ 3493 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 3494 { 3495 VARTYPE vt; 3496 3497 for (vt = 0; vt <= VT_BSTR_BLOB; vt++) 3498 { 3499 BOOL bFail = TRUE; 3500 3501 SKIPTESTS(vt); 3502 3503 memset(&v, 0, sizeof(v)); 3504 V_VT(&v) = vt | ExtraFlags[i]; 3505 V_VT(&vDst) = VT_EMPTY; 3506 3507 switch (V_VT(&v)) 3508 { 3509 case VT_UI1: case VT_I2: case VT_I4: 3510 case VT_R4: case VT_R8: 3511 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY: 3512 case VT_DATE: case VT_CY: 3513 bFail = FALSE; 3514 break; 3515 case VT_I8: 3516 if (has_i8) 3517 bFail = FALSE; 3518 } 3519 3520 hres = pVarNeg(&v,&vDst); 3521 if (bFail) 3522 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE, 3523 "VarNeg: expected failure, got 0x%X vt %d|0x%X\n", 3524 hres, vt, ExtraFlags[i]); 3525 else 3526 ok(hres == S_OK, "VarNeg: expected S_OK, got 0x%X vt %d|0x%X\n", 3527 hres, vt, ExtraFlags[i]); 3528 } 3529 } 3530 3531 VARNEG(BOOL,VARIANT_TRUE,I2,1); 3532 VARNEG(BOOL,VARIANT_FALSE,I2,0); 3533 VARNEG(BOOL,1,I2,-1); 3534 VARNEG(UI1,1,I2,-1); 3535 VARNEG(UI1,254,I2,-254); 3536 VARNEG(I2,-32768,I4,32768); 3537 VARNEG(I2,-1,I2,1); 3538 VARNEG(I2,1,I2,-1); 3539 VARNEG(I4,-((int)(~0u >> 1)) - 1,R8,-2147483648u); 3540 VARNEG(I4,-1,I4,1); 3541 VARNEG(I4,1,I4,-1); 3542 if (has_i8) 3543 { 3544 VARNEG(I8,1,I8,-1); 3545 VARNEG(I8,-1,I8,1); 3546 } 3547 VARNEG(R4,1,R4,-1); 3548 VARNEG(R4,-1,R4,1); 3549 VARNEG(DATE,1,DATE,-1); 3550 VARNEG(DATE,-1,DATE,1); 3551 VARNEG(R8,1,R8,-1); 3552 VARNEG(R8,-1,R8,1); 3553 VARNEG(BSTR,(BSTR)szNumMinus1,R8,1); 3554 VARNEG(BSTR,(BSTR)szNum1,R8,-1); 3555 3556 V_VT(&v) = VT_EMPTY; 3557 hres = pVarNeg(&v,&vDst); 3558 ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0, 3559 "VarNeg: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY, 3560 hres, V_VT(&vDst), V_I2(&vDst)); 3561 3562 V_VT(&v) = VT_NULL; 3563 hres = pVarNeg(&v,&vDst); 3564 ok(hres == S_OK && V_VT(&vDst) == VT_NULL, 3565 "VarNeg: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst)); 3566 3567 V_VT(&v) = VT_DECIMAL; 3568 S(U(*pdec)).sign = DECIMAL_NEG; 3569 S(U(*pdec)).scale = 0; 3570 pdec->Hi32 = 0; 3571 S1(U1(*pdec)).Mid32 = 0; 3572 S1(U1(*pdec)).Lo32 = 1; 3573 hres = pVarNeg(&v,&vDst); 3574 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && 3575 S(U(V_DECIMAL(&vDst))).sign == 0, 3576 "VarNeg: expected 0x0,%d,0x00, got 0x%X,%d,%02x\n", VT_DECIMAL, 3577 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign); 3578 3579 S(U(*pdec)).sign = 0; 3580 hres = pVarNeg(&v,&vDst); 3581 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && 3582 S(U(V_DECIMAL(&vDst))).sign == DECIMAL_NEG, 3583 "VarNeg: expected 0x0,%d,0x7f, got 0x%X,%d,%02x\n", VT_DECIMAL, 3584 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign); 3585 3586 V_VT(&v) = VT_CY; 3587 pcy->int64 = -10000; 3588 hres = pVarNeg(&v,&vDst); 3589 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000, 3590 "VarNeg: VT_CY wrong, hres=0x%X\n", hres); 3591 } 3592 3593 static HRESULT (WINAPI *pVarRound)(LPVARIANT,int,LPVARIANT); 3594 3595 static void test_Round( int line, VARIANT *arg, int deci, VARIANT *expected ) 3596 { 3597 VARIANT result; 3598 HRESULT hres; 3599 3600 memset( &result, 0, sizeof(result) ); 3601 hres = pVarRound( arg, deci, &result ); 3602 ok_(__FILE__,line)( hres == S_OK, "wrong result %x\n", hres ); 3603 if (hres == S_OK) 3604 ok_(__FILE__,line)( is_expected_variant( &result, expected ), 3605 "got %s expected %s\n", variantstr(&result), variantstr(expected) ); 3606 } 3607 #define VARROUND(vt,val,deci,rvt,rval) \ 3608 V_VT(&v) = VT_##vt; V_##vt(&v) = val; \ 3609 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 3610 test_Round( __LINE__, &v, deci, &exp ) 3611 3612 struct decimal_t { 3613 BYTE scale; 3614 BYTE sign; 3615 ULONG Hi32; 3616 ULONG Mid32; 3617 ULONG Lo32; 3618 }; 3619 3620 struct decimal_round_t { 3621 struct decimal_t source; 3622 struct decimal_t ret; 3623 int dec; 3624 }; 3625 3626 static const struct decimal_round_t decimal_round_data[] = { 3627 {{ 0, DECIMAL_NEG, 0, 0, 1 }, { 0, DECIMAL_NEG, 0, 0, 1 }, 0}, 3628 {{ 0, 0, 0, 0, 1 }, { 0, 0, 0, 0, 1 }, 0}, 3629 {{ 2, 0, 0, 0, 155 }, { 0, 0, 0, 0, 16 }, 1}, 3630 {{ 2, 0, 0, 0, 155 }, { 1, 0, 0, 0, 2 }, 0}, 3631 {{ 2, 0, 0, 0, 199 }, { 1, 0, 0, 0, 20 }, 1}, 3632 {{ 2, 0, 0, 0, 199 }, { 2, 0, 0, 0, 199 }, 2}, 3633 {{ 2, DECIMAL_NEG, 0, 0, 199 }, { 2, DECIMAL_NEG, 0, 0, 199 }, 2}, 3634 {{ 2, DECIMAL_NEG, 0, 0, 55 }, { 2, DECIMAL_NEG, 0, 0, 6 }, 1}, 3635 {{ 2, 0, 0, 0, 55 }, { 2, 0, 0, 0, 6 }, 1} 3636 }; 3637 3638 static void test_VarRound(void) 3639 { 3640 static WCHAR szNumMin[] = {'-','1','.','4','4','9','\0' }; 3641 static WCHAR szNum[] = {'1','.','4','5','1','\0' }; 3642 HRESULT hres; 3643 VARIANT v, exp, vDst; 3644 CY *pcy = &V_CY(&v); 3645 char buff[8]; 3646 int i; 3647 3648 CHECKPTR(VarRound); 3649 3650 /* first check valid integer types */ 3651 VARROUND(BOOL,VARIANT_TRUE,0,I2,-1); 3652 VARROUND(BOOL,VARIANT_FALSE,0,I2,0); 3653 VARROUND(BOOL,1,0,I2,1); 3654 VARROUND(UI1,1,0,UI1,1); 3655 VARROUND(UI1,254,0,UI1,254); 3656 VARROUND(I2,-32768,0,I2,-32768); 3657 VARROUND(I2,-1,0,I2,-1); 3658 VARROUND(I2,1,0,I2,1); 3659 VARROUND(I4,-((int)(~0u >> 1)) - 1,0,I4,-((int)(~0u >> 1)) - 1); 3660 VARROUND(I4,-1,0,I4,-1); 3661 VARROUND(I4,1,0,I4,1); 3662 3663 3664 /* MSDN states that rounding of R4/R8 is dependent on the underlying 3665 * bit pattern of the number and so is architecture dependent. In this 3666 * case Wine returns .2 (which is more correct) and Native returns .3 3667 */ 3668 3669 VARROUND(R4,1.0f,0,R4,1.0f); 3670 VARROUND(R4,-1.0f,0,R4,-1.0f); 3671 VARROUND(R8,1.0,0,R8,1.0); 3672 VARROUND(R8,-1.0,0,R8,-1.0); 3673 3674 /* floating point numbers aren't exactly equal and we can't just 3675 * compare the first few digits. */ 3676 VARROUND(DATE,1.451,1,DATE,1.5); 3677 VARROUND(DATE,-1.449,1,DATE,-1.4); 3678 3679 /* replace the decimal separator */ 3680 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char)); 3681 if (!buff[1]) { 3682 szNumMin[2] = buff[0]; 3683 szNum[1] = buff[0]; 3684 VARROUND(BSTR,(BSTR)szNumMin,1,R8,-1.40); 3685 VARROUND(BSTR,(BSTR)szNum,1,R8,1.50); 3686 } else { 3687 skip("Skipping VarRound(BSTR) as decimal separator is '%s'\n", buff); 3688 } 3689 3690 VARROUND(R4,1.23456f,0,R4,1.0f); 3691 VARROUND(R4,1.23456f,1,R4,1.2f); 3692 VARROUND(R4,1.23456f,2,R4,1.23f); 3693 VARROUND(R4,1.23456f,3,R4,1.235f); 3694 VARROUND(R4,1.23456f,4,R4,1.2346f); 3695 VARROUND(R4,-1.23456f,0,R4,-1.0f); 3696 VARROUND(R4,-1.23456f,1,R4,-1.2f); 3697 VARROUND(R4,-1.23456f,2,R4,-1.23f); 3698 VARROUND(R4,-1.23456f,3,R4,-1.235f); 3699 VARROUND(R4,-1.23456f,4,R4,-1.2346f); 3700 3701 VARROUND(R8,1.23456,0,R8,1.0); 3702 VARROUND(R8,1.23456,1,R8,1.2); 3703 VARROUND(R8,1.23456,2,R8,1.23); 3704 VARROUND(R8,1.23456,3,R8,1.235); 3705 VARROUND(R8,1.23456,4,R8,1.2346); 3706 VARROUND(R8,-1.23456,0,R8,-1.0); 3707 VARROUND(R8,-1.23456,1,R8,-1.2); 3708 VARROUND(R8,-1.23456,2,R8,-1.23); 3709 VARROUND(R8,-1.23456,3,R8,-1.235); 3710 VARROUND(R8,-1.23456,4,R8,-1.2346); 3711 3712 V_VT(&v) = VT_EMPTY; 3713 hres = pVarRound(&v,0,&vDst); 3714 ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0, 3715 "VarRound: expected 0x0,%d,0 got 0x%X,%d,%d\n", VT_EMPTY, 3716 hres, V_VT(&vDst), V_I2(&vDst)); 3717 3718 V_VT(&v) = VT_NULL; 3719 hres = pVarRound(&v,0,&vDst); 3720 ok(hres == S_OK && V_VT(&vDst) == VT_NULL, 3721 "VarRound: expected 0x0,%d got 0x%X,%d\n", VT_NULL, hres, V_VT(&vDst)); 3722 3723 /* VT_DECIMAL */ 3724 for (i = 0; i < sizeof(decimal_round_data)/sizeof(struct decimal_round_t); i++) 3725 { 3726 const struct decimal_round_t *ptr = &decimal_round_data[i]; 3727 DECIMAL *pdec; 3728 3729 pdec = &V_DECIMAL(&v); 3730 V_VT(&v) = VT_DECIMAL; 3731 S(U(*pdec)).sign = ptr->source.sign; 3732 S(U(*pdec)).scale = ptr->source.scale; 3733 pdec->Hi32 = ptr->source.Hi32; 3734 S1(U1(*pdec)).Mid32 = ptr->source.Mid32; 3735 S1(U1(*pdec)).Lo32 = ptr->source.Lo32; 3736 VariantInit(&vDst); 3737 hres = pVarRound(&v, ptr->dec, &vDst); 3738 todo_wine 3739 ok(hres == S_OK, "%d: got 0x%08x\n", i, hres); 3740 if (hres == S_OK) 3741 { 3742 ok(V_VT(&vDst) == VT_DECIMAL, "%d: got VT %d, expected VT_DECIMAL\n", i, V_VT(&vDst)); 3743 ok(S(U(V_DECIMAL(&vDst))).sign == ptr->ret.sign, "%d: got sign 0x%02x, expected 0x%02x\n", 3744 i, S(U(V_DECIMAL(&vDst))).sign, ptr->ret.sign); 3745 ok(V_DECIMAL(&vDst).Hi32 == ptr->ret.Hi32, "%d: got Hi32 %d, expected %d\n", 3746 i, V_DECIMAL(&vDst).Hi32, ptr->ret.Hi32); 3747 ok(S1(U1(V_DECIMAL(&vDst))).Mid32 == ptr->ret.Mid32, "%d: got Mid32 %d, expected %d\n", 3748 i, S1(U1(V_DECIMAL(&vDst))).Mid32, ptr->ret.Mid32); 3749 ok(S1(U1(V_DECIMAL(&vDst))).Lo32 == ptr->ret.Lo32, "%d: got Lo32 %d, expected %d\n", 3750 i, S1(U1(V_DECIMAL(&vDst))).Lo32, ptr->ret.Lo32); 3751 } 3752 } 3753 3754 /* VT_CY */ 3755 V_VT(&v) = VT_CY; 3756 pcy->int64 = 10000; 3757 hres = pVarRound(&v,0,&vDst); 3758 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000, 3759 "VarRound: VT_CY wrong, hres=0x%X\n", hres); 3760 3761 } 3762 3763 static HRESULT (WINAPI *pVarXor)(LPVARIANT,LPVARIANT,LPVARIANT); 3764 3765 #define VARXOR(vt1,val1,vt2,val2,rvt,rval) \ 3766 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \ 3767 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \ 3768 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 3769 test_var_call2( __LINE__, pVarXor, &left, &right, &exp ) 3770 3771 #define VARXORCY(vt1,val1,val2,rvt,rval) \ 3772 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \ 3773 V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \ 3774 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 3775 test_var_call2( __LINE__, pVarXor, &left, &right, &exp ) 3776 3777 static void test_VarXor(void) 3778 { 3779 static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' }; 3780 static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' }; 3781 VARIANT left, right, exp, result; 3782 BSTR lbstr, rbstr; 3783 VARTYPE i; 3784 HRESULT hres; 3785 3786 CHECKPTR(VarXor); 3787 3788 /* Test all possible flag/vt combinations & the resulting vt type */ 3789 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 3790 { 3791 VARTYPE leftvt, rightvt, resvt; 3792 3793 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++) 3794 { 3795 3796 SKIPTESTS(leftvt); 3797 3798 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++) 3799 { 3800 BOOL bFail = FALSE; 3801 3802 SKIPTESTS(rightvt); 3803 3804 if (leftvt == VT_BSTR || rightvt == VT_BSTR || 3805 leftvt == VT_DISPATCH || rightvt == VT_DISPATCH || 3806 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN) 3807 continue; 3808 3809 memset(&left, 0, sizeof(left)); 3810 memset(&right, 0, sizeof(right)); 3811 V_VT(&left) = leftvt | ExtraFlags[i]; 3812 V_VT(&right) = rightvt | ExtraFlags[i]; 3813 V_VT(&result) = VT_EMPTY; 3814 resvt = VT_I4; 3815 3816 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF || 3817 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) || 3818 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) || 3819 leftvt == VT_CLSID || rightvt == VT_CLSID || 3820 leftvt == VT_RECORD || rightvt == VT_RECORD || 3821 leftvt == VT_VARIANT || rightvt == VT_VARIANT || 3822 leftvt == VT_ERROR || rightvt == VT_ERROR) 3823 { 3824 bFail = TRUE; 3825 } 3826 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY) 3827 { 3828 if (leftvt == rightvt || 3829 leftvt == VT_I2 || rightvt == VT_I2 || 3830 leftvt == VT_UI1 || rightvt == VT_UI1 || 3831 leftvt == VT_BOOL || rightvt == VT_BOOL) 3832 resvt = VT_I2; 3833 else if (leftvt == VT_NULL || rightvt == VT_NULL) 3834 resvt = VT_NULL; 3835 else if (leftvt == VT_I8 || rightvt == VT_I8) 3836 resvt = VT_I8; 3837 } 3838 else if (leftvt == VT_NULL || rightvt == VT_NULL) 3839 { 3840 resvt = VT_NULL; 3841 } 3842 else if (leftvt == VT_UI1 || rightvt == VT_UI1) 3843 { 3844 if (leftvt == rightvt) 3845 resvt = VT_UI1; 3846 else if (leftvt == rightvt || 3847 leftvt == VT_I2 || rightvt == VT_I2 || 3848 leftvt == VT_BOOL || rightvt == VT_BOOL) 3849 { 3850 resvt = VT_I2; 3851 } 3852 else if (leftvt == VT_I8 || rightvt == VT_I8) 3853 resvt = VT_I8; 3854 } 3855 else if (leftvt == VT_I2 || rightvt == VT_I2) 3856 { 3857 if (leftvt == rightvt || 3858 leftvt == VT_BOOL || rightvt == VT_BOOL) 3859 resvt = VT_I2; 3860 else if (leftvt == VT_I8 || rightvt == VT_I8) 3861 resvt = VT_I8; 3862 } 3863 else if (leftvt == VT_BOOL && rightvt == VT_BOOL) 3864 { 3865 resvt = VT_BOOL; 3866 } 3867 else if (leftvt == VT_I8 || rightvt == VT_I8) 3868 { 3869 if (leftvt == VT_INT || rightvt == VT_INT) 3870 bFail = TRUE; 3871 else 3872 resvt = VT_I8; 3873 } 3874 hres = pVarXor(&left, &right, &result); 3875 if (bFail) 3876 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE, 3877 "VarXor: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n", 3878 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres, 3879 V_VT(&result)); 3880 else 3881 ok(hres == S_OK && V_VT(&result) == resvt, 3882 "VarXor: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n", 3883 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres, 3884 V_VT(&result)); 3885 } 3886 } 3887 } 3888 3889 /* Test returned values 3890 * FIXME: Test VT_DECIMAL/VT_DISPATCH 3891 */ 3892 VARXOR(EMPTY,0,EMPTY,0,I2,0); 3893 VARXOR(EMPTY,1,EMPTY,0,I2,0); 3894 VARXOR(EMPTY,0,NULL,0,NULL,0); 3895 VARXOR(EMPTY,0,I1,0,I4,0); 3896 VARXOR(EMPTY,0,I1,1,I4,1); 3897 VARXOR(EMPTY,0,UI1,0,I2,0); 3898 VARXOR(EMPTY,0,UI1,1,I2,1); 3899 VARXOR(EMPTY,0,I2,0,I2,0); 3900 VARXOR(EMPTY,0,I2,1,I2,1); 3901 VARXOR(EMPTY,0,UI2,0,I4,0); 3902 VARXOR(EMPTY,0,UI2,1,I4,1); 3903 VARXOR(EMPTY,0,I4,0,I4,0); 3904 VARXOR(EMPTY,0,I4,1,I4,1); 3905 VARXOR(EMPTY,0,UI4,0,I4,0); 3906 VARXOR(EMPTY,0,UI4,1,I4,1); 3907 if (has_i8) 3908 { 3909 VARXOR(EMPTY,0,I8,0,I8,0); 3910 VARXOR(EMPTY,0,I8,1,I8,1); 3911 VARXOR(EMPTY,0,UI8,0,I4,0); 3912 VARXOR(EMPTY,0,UI8,1,I4,1); 3913 } 3914 VARXOR(EMPTY,0,INT,0,I4,0); 3915 VARXOR(EMPTY,0,INT,1,I4,1); 3916 VARXOR(EMPTY,0,UINT,0,I4,0); 3917 VARXOR(EMPTY,0,UINT,1,I4,1); 3918 VARXOR(EMPTY,0,BOOL,0,I2,0); 3919 VARXOR(EMPTY,0,BOOL,1,I2,1); 3920 VARXOR(EMPTY,0,R4,0,I4,0); 3921 VARXOR(EMPTY,0,R4,1,I4,1); 3922 VARXOR(EMPTY,0,R8,0,I4,0); 3923 VARXOR(EMPTY,0,R8,1,I4,1); 3924 rbstr = SysAllocString(szFalse); 3925 VARXOR(EMPTY,0,BSTR,rbstr,I2,0); 3926 SysFreeString(rbstr); 3927 rbstr = SysAllocString(szTrue); 3928 VARXOR(EMPTY,0,BSTR,rbstr,I2,-1); 3929 VARXORCY(EMPTY,0,10000,I4,1); 3930 SysFreeString(rbstr); 3931 3932 /* NULL OR 0 = NULL. NULL OR n = n */ 3933 VARXOR(NULL,0,NULL,0,NULL,0); 3934 VARXOR(NULL,1,NULL,0,NULL,0); 3935 VARXOR(NULL,0,I1,0,NULL,0); 3936 VARXOR(NULL,0,I1,1,NULL,0); 3937 VARXOR(NULL,0,UI1,0,NULL,0); 3938 VARXOR(NULL,0,UI1,1,NULL,0); 3939 VARXOR(NULL,0,I2,0,NULL,0); 3940 VARXOR(NULL,0,I2,1,NULL,0); 3941 VARXOR(NULL,0,UI2,0,NULL,0); 3942 VARXOR(NULL,0,UI2,1,NULL,0); 3943 VARXOR(NULL,0,I4,0,NULL,0); 3944 VARXOR(NULL,0,I4,1,NULL,0); 3945 VARXOR(NULL,0,UI4,0,NULL,0); 3946 VARXOR(NULL,0,UI4,1,NULL,0); 3947 if (has_i8) 3948 { 3949 VARXOR(NULL,0,I8,0,NULL,0); 3950 VARXOR(NULL,0,I8,1,NULL,0); 3951 VARXOR(NULL,0,UI8,0,NULL,0); 3952 VARXOR(NULL,0,UI8,1,NULL,0); 3953 } 3954 VARXOR(NULL,0,INT,0,NULL,0); 3955 VARXOR(NULL,0,INT,1,NULL,0); 3956 VARXOR(NULL,0,UINT,0,NULL,0); 3957 VARXOR(NULL,0,UINT,1,NULL,0); 3958 VARXOR(NULL,0,BOOL,0,NULL,0); 3959 VARXOR(NULL,0,BOOL,1,NULL,0); 3960 VARXOR(NULL,0,R4,0,NULL,0); 3961 VARXOR(NULL,0,R4,1,NULL,0); 3962 VARXOR(NULL,0,R8,0,NULL,0); 3963 VARXOR(NULL,0,R8,1,NULL,0); 3964 rbstr = SysAllocString(szFalse); 3965 VARXOR(NULL,0,BSTR,rbstr,NULL,0); 3966 SysFreeString(rbstr); 3967 rbstr = SysAllocString(szTrue); 3968 VARXOR(NULL,0,BSTR,rbstr,NULL,0); 3969 SysFreeString(rbstr); 3970 VARXORCY(NULL,0,10000,NULL,0); 3971 VARXORCY(NULL,0,0,NULL,0); 3972 3973 VARXOR(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE); 3974 VARXOR(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE); 3975 VARXOR(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE); 3976 VARXOR(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE); 3977 /* Assume x,y & y,x are the same from now on to reduce the number of tests */ 3978 VARXOR(BOOL,VARIANT_TRUE,I1,-1,I4,0); 3979 VARXOR(BOOL,VARIANT_TRUE,I1,0,I4,-1); 3980 VARXOR(BOOL,VARIANT_FALSE,I1,0,I4,0); 3981 VARXOR(BOOL,VARIANT_TRUE,UI1,255,I2,-256); 3982 VARXOR(BOOL,VARIANT_TRUE,UI1,0,I2,-1); 3983 VARXOR(BOOL,VARIANT_FALSE,UI1,0,I2,0); 3984 VARXOR(BOOL,VARIANT_TRUE,I2,-1,I2,0); 3985 VARXOR(BOOL,VARIANT_TRUE,I2,0,I2,-1); 3986 VARXOR(BOOL,VARIANT_FALSE,I2,0,I2,0); 3987 VARXOR(BOOL,VARIANT_TRUE,UI2,65535,I4,-65536); 3988 VARXOR(BOOL,VARIANT_TRUE,UI2,0,I4,-1); 3989 VARXOR(BOOL,VARIANT_FALSE,UI2,0,I4,0); 3990 VARXOR(BOOL,VARIANT_TRUE,I4,-1,I4,0); 3991 VARXOR(BOOL,VARIANT_TRUE,I4,0,I4,-1); 3992 VARXOR(BOOL,VARIANT_FALSE,I4,0,I4,0); 3993 VARXOR(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,0); 3994 VARXOR(BOOL,VARIANT_TRUE,UI4,0,I4,-1); 3995 VARXOR(BOOL,VARIANT_FALSE,UI4,0,I4,0); 3996 VARXOR(BOOL,VARIANT_TRUE,R4,-1,I4,0); 3997 VARXOR(BOOL,VARIANT_TRUE,R4,0,I4,-1); 3998 VARXOR(BOOL,VARIANT_FALSE,R4,0,I4,0); 3999 VARXOR(BOOL,VARIANT_TRUE,R8,-1,I4,0); 4000 VARXOR(BOOL,VARIANT_TRUE,R8,0,I4,-1); 4001 VARXOR(BOOL,VARIANT_FALSE,R8,0,I4,0); 4002 VARXOR(BOOL,VARIANT_TRUE,DATE,-1,I4,0); 4003 VARXOR(BOOL,VARIANT_TRUE,DATE,0,I4,-1); 4004 VARXOR(BOOL,VARIANT_FALSE,DATE,0,I4,0); 4005 if (has_i8) 4006 { 4007 VARXOR(BOOL,VARIANT_TRUE,I8,-1,I8,0); 4008 VARXOR(BOOL,VARIANT_TRUE,I8,0,I8,-1); 4009 VARXOR(BOOL,VARIANT_FALSE,I8,0,I8,0); 4010 /* This returns DISP_E_OVERFLOW which indicates that a conversion 4011 * to I4 is performed. 4012 */ 4013 /* VARXOR(BOOL,VARIANT_TRUE,UI8,-1,I4,-1); */ 4014 VARXOR(BOOL,VARIANT_TRUE,UI8,0,I4,-1); 4015 VARXOR(BOOL,VARIANT_FALSE,UI8,0,I4,0); 4016 } 4017 VARXOR(BOOL,VARIANT_TRUE,INT,-1,I4,0); 4018 VARXOR(BOOL,VARIANT_TRUE,INT,0,I4,-1); 4019 VARXOR(BOOL,VARIANT_FALSE,INT,0,I4,0); 4020 VARXOR(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,0); 4021 VARXOR(BOOL,VARIANT_TRUE,UINT,0,I4,-1); 4022 VARXOR(BOOL,VARIANT_FALSE,UINT,0,I4,0); 4023 rbstr = SysAllocString(szFalse); 4024 VARXOR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_FALSE); 4025 VARXOR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE); 4026 SysFreeString(rbstr); 4027 rbstr = SysAllocString(szTrue); 4028 VARXOR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_TRUE); 4029 VARXOR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_FALSE); 4030 SysFreeString(rbstr); 4031 VARXORCY(BOOL,VARIANT_TRUE,10000,I4,-2); 4032 VARXORCY(BOOL,VARIANT_TRUE,0,I4,-1); 4033 VARXORCY(BOOL,VARIANT_FALSE,0,I4,0); 4034 4035 VARXOR(I1,-1,I1,-1,I4,0); 4036 VARXOR(I1,-1,I1,0,I4,-1); 4037 VARXOR(I1,0,I1,0,I4,0); 4038 VARXOR(I1,-1,UI1,255,I4,-256); 4039 VARXOR(I1,-1,UI1,0,I4,-1); 4040 VARXOR(I1,0,UI1,0,I4,0); 4041 VARXOR(I1,-1,I2,-1,I4,0); 4042 VARXOR(I1,-1,I2,0,I4,-1); 4043 VARXOR(I1,0,I2,0,I4,0); 4044 VARXOR(I1,-1,UI2,65535,I4,-65536); 4045 VARXOR(I1,-1,UI2,0,I4,-1); 4046 VARXOR(I1,0,UI2,0,I4,0); 4047 VARXOR(I1,-1,I4,-1,I4,0); 4048 VARXOR(I1,-1,I4,0,I4,-1); 4049 VARXOR(I1,0,I4,0,I4,0); 4050 VARXOR(I1,-1,UI4,0xffffffff,I4,0); 4051 VARXOR(I1,-1,UI4,0,I4,-1); 4052 VARXOR(I1,0,UI4,0,I4,0); 4053 VARXOR(I1,-1,R4,-1,I4,0); 4054 VARXOR(I1,-1,R4,0,I4,-1); 4055 VARXOR(I1,0,R4,0,I4,0); 4056 VARXOR(I1,-1,R8,-1,I4,0); 4057 VARXOR(I1,-1,R8,0,I4,-1); 4058 VARXOR(I1,0,R8,0,I4,0); 4059 VARXOR(I1,-1,DATE,-1,I4,0); 4060 VARXOR(I1,-1,DATE,0,I4,-1); 4061 VARXOR(I1,0,DATE,0,I4,0); 4062 if (has_i8) 4063 { 4064 VARXOR(I1,-1,I8,-1,I8,0); 4065 VARXOR(I1,-1,I8,0,I8,-1); 4066 VARXOR(I1,0,I8,0,I8,0); 4067 VARXOR(I1,-1,UI8,0,I4,-1); 4068 VARXOR(I1,0,UI8,0,I4,0); 4069 } 4070 VARXOR(I1,-1,INT,-1,I4,0); 4071 VARXOR(I1,-1,INT,0,I4,-1); 4072 VARXOR(I1,0,INT,0,I4,0); 4073 VARXOR(I1,-1,UINT,0xffffffff,I4,0); 4074 VARXOR(I1,-1,UINT,0,I4,-1); 4075 VARXOR(I1,0,UINT,0,I4,0); 4076 rbstr = SysAllocString(szFalse); 4077 VARXOR(I1,0,BSTR,rbstr,I4,0); 4078 VARXOR(I1,-1,BSTR,rbstr,I4,-1); 4079 SysFreeString(rbstr); 4080 rbstr = SysAllocString(szTrue); 4081 VARXOR(I1,0,BSTR,rbstr,I4,-1); 4082 VARXOR(I1,-1,BSTR,rbstr,I4,0); 4083 SysFreeString(rbstr); 4084 VARXORCY(I1,-1,10000,I4,-2); 4085 VARXORCY(I1,-1,0,I4,-1); 4086 VARXORCY(I1,0,0,I4,0); 4087 4088 VARXOR(UI1,255,UI1,255,UI1,0); 4089 VARXOR(UI1,255,UI1,0,UI1,255); 4090 VARXOR(UI1,0,UI1,0,UI1,0); 4091 VARXOR(UI1,255,I2,-1,I2,-256); 4092 VARXOR(UI1,255,I2,0,I2,255); 4093 VARXOR(UI1,0,I2,0,I2,0); 4094 VARXOR(UI1,255,UI2,65535,I4,65280); 4095 VARXOR(UI1,255,UI2,0,I4,255); 4096 VARXOR(UI1,0,UI2,0,I4,0); 4097 VARXOR(UI1,255,I4,-1,I4,-256); 4098 VARXOR(UI1,255,I4,0,I4,255); 4099 VARXOR(UI1,0,I4,0,I4,0); 4100 VARXOR(UI1,255,UI4,0xffffffff,I4,-256); 4101 VARXOR(UI1,255,UI4,0,I4,255); 4102 VARXOR(UI1,0,UI4,0,I4,0); 4103 VARXOR(UI1,255,R4,-1,I4,-256); 4104 VARXOR(UI1,255,R4,0,I4,255); 4105 VARXOR(UI1,0,R4,0,I4,0); 4106 VARXOR(UI1,255,R8,-1,I4,-256); 4107 VARXOR(UI1,255,R8,0,I4,255); 4108 VARXOR(UI1,0,R8,0,I4,0); 4109 VARXOR(UI1,255,DATE,-1,I4,-256); 4110 VARXOR(UI1,255,DATE,0,I4,255); 4111 VARXOR(UI1,0,DATE,0,I4,0); 4112 if (has_i8) 4113 { 4114 VARXOR(UI1,255,I8,-1,I8,-256); 4115 VARXOR(UI1,255,I8,0,I8,255); 4116 VARXOR(UI1,0,I8,0,I8,0); 4117 VARXOR(UI1,255,UI8,0,I4,255); 4118 VARXOR(UI1,0,UI8,0,I4,0); 4119 } 4120 VARXOR(UI1,255,INT,-1,I4,-256); 4121 VARXOR(UI1,255,INT,0,I4,255); 4122 VARXOR(UI1,0,INT,0,I4,0); 4123 VARXOR(UI1,255,UINT,0xffffffff,I4,-256); 4124 VARXOR(UI1,255,UINT,0,I4,255); 4125 VARXOR(UI1,0,UINT,0,I4,0); 4126 rbstr = SysAllocString(szFalse); 4127 VARXOR(UI1,0,BSTR,rbstr,I2,0); 4128 VARXOR(UI1,255,BSTR,rbstr,I2,255); 4129 SysFreeString(rbstr); 4130 rbstr = SysAllocString(szTrue); 4131 VARXOR(UI1,0,BSTR,rbstr,I2,-1); 4132 VARXOR(UI1,255,BSTR,rbstr,I2,-256); 4133 SysFreeString(rbstr); 4134 VARXORCY(UI1,255,10000,I4,254); 4135 VARXORCY(UI1,255,0,I4,255); 4136 VARXORCY(UI1,0,0,I4,0); 4137 4138 VARXOR(I2,-1,I2,-1,I2,0); 4139 VARXOR(I2,-1,I2,0,I2,-1); 4140 VARXOR(I2,0,I2,0,I2,0); 4141 VARXOR(I2,-1,UI2,65535,I4,-65536); 4142 VARXOR(I2,-1,UI2,0,I4,-1); 4143 VARXOR(I2,0,UI2,0,I4,0); 4144 VARXOR(I2,-1,I4,-1,I4,0); 4145 VARXOR(I2,-1,I4,0,I4,-1); 4146 VARXOR(I2,0,I4,0,I4,0); 4147 VARXOR(I2,-1,UI4,0xffffffff,I4,0); 4148 VARXOR(I2,-1,UI4,0,I4,-1); 4149 VARXOR(I2,0,UI4,0,I4,0); 4150 VARXOR(I2,-1,R4,-1,I4,0); 4151 VARXOR(I2,-1,R4,0,I4,-1); 4152 VARXOR(I2,0,R4,0,I4,0); 4153 VARXOR(I2,-1,R8,-1,I4,0); 4154 VARXOR(I2,-1,R8,0,I4,-1); 4155 VARXOR(I2,0,R8,0,I4,0); 4156 VARXOR(I2,-1,DATE,-1,I4,0); 4157 VARXOR(I2,-1,DATE,0,I4,-1); 4158 VARXOR(I2,0,DATE,0,I4,0); 4159 if (has_i8) 4160 { 4161 VARXOR(I2,-1,I8,-1,I8,0); 4162 VARXOR(I2,-1,I8,0,I8,-1); 4163 VARXOR(I2,0,I8,0,I8,0); 4164 VARXOR(I2,-1,UI8,0,I4,-1); 4165 VARXOR(I2,0,UI8,0,I4,0); 4166 } 4167 VARXOR(I2,-1,INT,-1,I4,0); 4168 VARXOR(I2,-1,INT,0,I4,-1); 4169 VARXOR(I2,0,INT,0,I4,0); 4170 VARXOR(I2,-1,UINT,0xffffffff,I4,0); 4171 VARXOR(I2,-1,UINT,0,I4,-1); 4172 VARXOR(I2,0,UINT,0,I4,0); 4173 rbstr = SysAllocString(szFalse); 4174 VARXOR(I2,0,BSTR,rbstr,I2,0); 4175 VARXOR(I2,-1,BSTR,rbstr,I2,-1); 4176 SysFreeString(rbstr); 4177 rbstr = SysAllocString(szTrue); 4178 VARXOR(I2,0,BSTR,rbstr,I2,-1); 4179 VARXOR(I2,-1,BSTR,rbstr,I2,0); 4180 SysFreeString(rbstr); 4181 VARXORCY(I2,-1,10000,I4,-2); 4182 VARXORCY(I2,-1,0,I4,-1); 4183 VARXORCY(I2,0,0,I4,0); 4184 4185 VARXOR(UI2,65535,UI2,65535,I4,0); 4186 VARXOR(UI2,65535,UI2,0,I4,65535); 4187 VARXOR(UI2,0,UI2,0,I4,0); 4188 VARXOR(UI2,65535,I4,-1,I4,-65536); 4189 VARXOR(UI2,65535,I4,0,I4,65535); 4190 VARXOR(UI2,0,I4,0,I4,0); 4191 VARXOR(UI2,65535,UI4,0xffffffff,I4,-65536); 4192 VARXOR(UI2,65535,UI4,0,I4,65535); 4193 VARXOR(UI2,0,UI4,0,I4,0); 4194 VARXOR(UI2,65535,R4,-1,I4,-65536); 4195 VARXOR(UI2,65535,R4,0,I4,65535); 4196 VARXOR(UI2,0,R4,0,I4,0); 4197 VARXOR(UI2,65535,R8,-1,I4,-65536); 4198 VARXOR(UI2,65535,R8,0,I4,65535); 4199 VARXOR(UI2,0,R8,0,I4,0); 4200 VARXOR(UI2,65535,DATE,-1,I4,-65536); 4201 VARXOR(UI2,65535,DATE,0,I4,65535); 4202 VARXOR(UI2,0,DATE,0,I4,0); 4203 if (has_i8) 4204 { 4205 VARXOR(UI2,65535,I8,-1,I8,-65536); 4206 VARXOR(UI2,65535,I8,0,I8,65535); 4207 VARXOR(UI2,0,I8,0,I8,0); 4208 VARXOR(UI2,65535,UI8,0,I4,65535); 4209 VARXOR(UI2,0,UI8,0,I4,0); 4210 } 4211 VARXOR(UI2,65535,INT,-1,I4,-65536); 4212 VARXOR(UI2,65535,INT,0,I4,65535); 4213 VARXOR(UI2,0,INT,0,I4,0); 4214 VARXOR(UI2,65535,UINT,0xffffffff,I4,-65536); 4215 VARXOR(UI2,65535,UINT,0,I4,65535); 4216 VARXOR(UI2,0,UINT,0,I4,0); 4217 rbstr = SysAllocString(szFalse); 4218 VARXOR(UI2,0,BSTR,rbstr,I4,0); 4219 VARXOR(UI2,65535,BSTR,rbstr,I4,65535); 4220 SysFreeString(rbstr); 4221 rbstr = SysAllocString(szTrue); 4222 VARXOR(UI2,0,BSTR,rbstr,I4,-1); 4223 VARXOR(UI2,65535,BSTR,rbstr,I4,-65536); 4224 SysFreeString(rbstr); 4225 VARXORCY(UI2,65535,10000,I4,65534); 4226 VARXORCY(UI2,65535,0,I4,65535); 4227 VARXORCY(UI2,0,0,I4,0); 4228 4229 VARXOR(I4,-1,I4,-1,I4,0); 4230 VARXOR(I4,-1,I4,0,I4,-1); 4231 VARXOR(I4,0,I4,0,I4,0); 4232 VARXOR(I4,-1,UI4,0xffffffff,I4,0); 4233 VARXOR(I4,-1,UI4,0,I4,-1); 4234 VARXOR(I4,0,UI4,0,I4,0); 4235 VARXOR(I4,-1,R4,-1,I4,0); 4236 VARXOR(I4,-1,R4,0,I4,-1); 4237 VARXOR(I4,0,R4,0,I4,0); 4238 VARXOR(I4,-1,R8,-1,I4,0); 4239 VARXOR(I4,-1,R8,0,I4,-1); 4240 VARXOR(I4,0,R8,0,I4,0); 4241 VARXOR(I4,-1,DATE,-1,I4,0); 4242 VARXOR(I4,-1,DATE,0,I4,-1); 4243 VARXOR(I4,0,DATE,0,I4,0); 4244 if (has_i8) 4245 { 4246 VARXOR(I4,-1,I8,-1,I8,0); 4247 VARXOR(I4,-1,I8,0,I8,-1); 4248 VARXOR(I4,0,I8,0,I8,0); 4249 VARXOR(I4,-1,UI8,0,I4,-1); 4250 VARXOR(I4,0,UI8,0,I4,0); 4251 } 4252 VARXOR(I4,-1,INT,-1,I4,0); 4253 VARXOR(I4,-1,INT,0,I4,-1); 4254 VARXOR(I4,0,INT,0,I4,0); 4255 VARXOR(I4,-1,UINT,0xffffffff,I4,0); 4256 VARXOR(I4,-1,UINT,0,I4,-1); 4257 VARXOR(I4,0,UINT,0,I4,0); 4258 rbstr = SysAllocString(szFalse); 4259 VARXOR(I4,0,BSTR,rbstr,I4,0); 4260 VARXOR(I4,-1,BSTR,rbstr,I4,-1); 4261 SysFreeString(rbstr); 4262 rbstr = SysAllocString(szTrue); 4263 VARXOR(I4,0,BSTR,rbstr,I4,-1); 4264 VARXOR(I4,-1,BSTR,rbstr,I4,0); 4265 SysFreeString(rbstr); 4266 VARXORCY(I4,-1,10000,I4,-2); 4267 VARXORCY(I4,-1,0,I4,-1); 4268 VARXORCY(I4,0,0,I4,0); 4269 4270 VARXOR(UI4,0xffffffff,UI4,0xffffffff,I4,0); 4271 VARXOR(UI4,0xffffffff,UI4,0,I4,-1); 4272 VARXOR(UI4,0,UI4,0,I4,0); 4273 VARXOR(UI4,0xffffffff,R4,-1,I4,0); 4274 VARXOR(UI4,0xffffffff,R4,0,I4,-1); 4275 VARXOR(UI4,0,R4,0,I4,0); 4276 VARXOR(UI4,0xffffffff,R8,-1,I4,0); 4277 VARXOR(UI4,0xffffffff,R8,0,I4,-1); 4278 VARXOR(UI4,0,R8,0,I4,0); 4279 VARXOR(UI4,0xffffffff,DATE,-1,I4,0); 4280 VARXOR(UI4,0xffffffff,DATE,0,I4,-1); 4281 VARXOR(UI4,0,DATE,0,I4,0); 4282 if (has_i8) 4283 { 4284 VARXOR(UI4,0xffffffff,I8,0,I8,0xffffffff); 4285 VARXOR(UI4,VARIANT_FALSE,I8,VARIANT_FALSE,I8,0); 4286 VARXOR(UI4,0,I8,0,I8,0); 4287 VARXOR(UI4,0xffffffff,UI8,0,I4,-1); 4288 VARXOR(UI4,0,UI8,0,I4,0); 4289 } 4290 VARXOR(UI4,0xffffffff,INT,-1,I4,0); 4291 VARXOR(UI4,0xffffffff,INT,0,I4,-1); 4292 VARXOR(UI4,0,INT,0,I4,0); 4293 VARXOR(UI4,0xffffffff,UINT,0xffffffff,I4,0); 4294 VARXOR(UI4,0xffffffff,UINT,0,I4,-1); 4295 VARXOR(UI4,0,UINT,0,I4,0); 4296 rbstr = SysAllocString(szFalse); 4297 VARXOR(UI4,0,BSTR,rbstr,I4,0); 4298 VARXOR(UI4,0xffffffff,BSTR,rbstr,I4,-1); 4299 SysFreeString(rbstr); 4300 rbstr = SysAllocString(szTrue); 4301 VARXOR(UI4,0,BSTR,rbstr,I4,-1); 4302 VARXOR(UI4,0xffffffff,BSTR,rbstr,I4,0); 4303 SysFreeString(rbstr); 4304 VARXORCY(UI4,0xffffffff,10000,I4,-2); 4305 VARXORCY(UI4,0xffffffff,0,I4,-1); 4306 VARXORCY(UI4,0,0,I4,0); 4307 4308 VARXOR(R4,-1,R4,-1,I4,0); 4309 VARXOR(R4,-1,R4,0,I4,-1); 4310 VARXOR(R4,0,R4,0,I4,0); 4311 VARXOR(R4,-1,R8,-1,I4,0); 4312 VARXOR(R4,-1,R8,0,I4,-1); 4313 VARXOR(R4,0,R8,0,I4,0); 4314 VARXOR(R4,-1,DATE,-1,I4,0); 4315 VARXOR(R4,-1,DATE,0,I4,-1); 4316 VARXOR(R4,0,DATE,0,I4,0); 4317 if (has_i8) 4318 { 4319 VARXOR(R4,-1,I8,-1,I8,0); 4320 VARXOR(R4,-1,I8,0,I8,-1); 4321 VARXOR(R4,0,I8,0,I8,0); 4322 VARXOR(R4,-1,UI8,0,I4,-1); 4323 VARXOR(R4,0,UI8,0,I4,0); 4324 } 4325 VARXOR(R4,-1,INT,-1,I4,0); 4326 VARXOR(R4,-1,INT,0,I4,-1); 4327 VARXOR(R4,0,INT,0,I4,0); 4328 VARXOR(R4,-1,UINT,0xffffffff,I4,0); 4329 VARXOR(R4,-1,UINT,0,I4,-1); 4330 VARXOR(R4,0,UINT,0,I4,0); 4331 rbstr = SysAllocString(szFalse); 4332 VARXOR(R4,0,BSTR,rbstr,I4,0); 4333 VARXOR(R4,-1,BSTR,rbstr,I4,-1); 4334 SysFreeString(rbstr); 4335 rbstr = SysAllocString(szTrue); 4336 VARXOR(R4,0,BSTR,rbstr,I4,-1); 4337 VARXOR(R4,-1,BSTR,rbstr,I4,0); 4338 SysFreeString(rbstr); 4339 VARXORCY(R4,-1,10000,I4,-2); 4340 VARXORCY(R4,-1,0,I4,-1); 4341 VARXORCY(R4,0,0,I4,0); 4342 4343 VARXOR(R8,-1,R8,-1,I4,0); 4344 VARXOR(R8,-1,R8,0,I4,-1); 4345 VARXOR(R8,0,R8,0,I4,0); 4346 VARXOR(R8,-1,DATE,-1,I4,0); 4347 VARXOR(R8,-1,DATE,0,I4,-1); 4348 VARXOR(R8,0,DATE,0,I4,0); 4349 if (has_i8) 4350 { 4351 VARXOR(R8,-1,I8,-1,I8,0); 4352 VARXOR(R8,-1,I8,0,I8,-1); 4353 VARXOR(R8,0,I8,0,I8,0); 4354 VARXOR(R8,-1,UI8,0,I4,-1); 4355 VARXOR(R8,0,UI8,0,I4,0); 4356 } 4357 VARXOR(R8,-1,INT,-1,I4,0); 4358 VARXOR(R8,-1,INT,0,I4,-1); 4359 VARXOR(R8,0,INT,0,I4,0); 4360 VARXOR(R8,-1,UINT,0xffffffff,I4,0); 4361 VARXOR(R8,-1,UINT,0,I4,-1); 4362 VARXOR(R8,0,UINT,0,I4,0); 4363 rbstr = SysAllocString(szFalse); 4364 VARXOR(R8,0,BSTR,rbstr,I4,0); 4365 VARXOR(R8,-1,BSTR,rbstr,I4,-1); 4366 SysFreeString(rbstr); 4367 rbstr = SysAllocString(szTrue); 4368 VARXOR(R8,0,BSTR,rbstr,I4,-1); 4369 VARXOR(R8,-1,BSTR,rbstr,I4,0); 4370 SysFreeString(rbstr); 4371 VARXORCY(R8,-1,10000,I4,-2); 4372 VARXORCY(R8,-1,0,I4,-1); 4373 VARXORCY(R8,0,0,I4,0); 4374 4375 VARXOR(DATE,-1,DATE,-1,I4,0); 4376 VARXOR(DATE,-1,DATE,0,I4,-1); 4377 VARXOR(DATE,0,DATE,0,I4,0); 4378 if (has_i8) 4379 { 4380 VARXOR(DATE,-1,I8,-1,I8,0); 4381 VARXOR(DATE,-1,I8,0,I8,-1); 4382 VARXOR(DATE,0,I8,0,I8,0); 4383 VARXOR(DATE,-1,UI8,0,I4,-1); 4384 VARXOR(DATE,0,UI8,0,I4,0); 4385 } 4386 VARXOR(DATE,-1,INT,-1,I4,0); 4387 VARXOR(DATE,-1,INT,0,I4,-1); 4388 VARXOR(DATE,0,INT,0,I4,0); 4389 VARXOR(DATE,-1,UINT,0xffffffff,I4,0); 4390 VARXOR(DATE,-1,UINT,0,I4,-1); 4391 VARXOR(DATE,0,UINT,0,I4,0); 4392 rbstr = SysAllocString(szFalse); 4393 VARXOR(DATE,0,BSTR,rbstr,I4,0); 4394 VARXOR(DATE,-1,BSTR,rbstr,I4,-1); 4395 SysFreeString(rbstr); 4396 rbstr = SysAllocString(szTrue); 4397 VARXOR(DATE,0,BSTR,rbstr,I4,-1); 4398 VARXOR(DATE,-1,BSTR,rbstr,I4,0); 4399 SysFreeString(rbstr); 4400 VARXORCY(DATE,-1,10000,I4,-2); 4401 VARXORCY(DATE,-1,0,I4,-1); 4402 VARXORCY(DATE,0,0,I4,0); 4403 4404 if (has_i8) 4405 { 4406 VARXOR(I8,-1,I8,-1,I8,0); 4407 VARXOR(I8,-1,I8,0,I8,-1); 4408 VARXOR(I8,0,I8,0,I8,0); 4409 VARXOR(I8,-1,UI8,0,I8,-1); 4410 VARXOR(I8,0,UI8,0,I8,0); 4411 VARXOR(I8,-1,UINT,0,I8,-1); 4412 VARXOR(I8,0,UINT,0,I8,0); 4413 rbstr = SysAllocString(szFalse); 4414 VARXOR(I8,0,BSTR,rbstr,I8,0); 4415 VARXOR(I8,-1,BSTR,rbstr,I8,-1); 4416 SysFreeString(rbstr); 4417 rbstr = SysAllocString(szTrue); 4418 VARXOR(I8,0,BSTR,rbstr,I8,-1); 4419 VARXOR(I8,-1,BSTR,rbstr,I8,0); 4420 SysFreeString(rbstr); 4421 VARXORCY(I8,-1,10000,I8,-2); 4422 VARXORCY(I8,-1,0,I8,-1); 4423 VARXORCY(I8,0,0,I8,0); 4424 4425 VARXOR(UI8,0xffff,UI8,0xffff,I4,0); 4426 VARXOR(UI8,0xffff,UI8,0,I4,0xffff); 4427 VARXOR(UI8,0,UI8,0,I4,0); 4428 VARXOR(UI8,0xffff,INT,-1,I4,-65536); 4429 VARXOR(UI8,0xffff,INT,0,I4,0xffff); 4430 VARXOR(UI8,0,INT,0,I4,0); 4431 VARXOR(UI8,0xffff,UINT,0xffff,I4,0); 4432 VARXOR(UI8,0xffff,UINT,0,I4,0xffff); 4433 VARXOR(UI8,0,UINT,0,I4,0); 4434 rbstr = SysAllocString(szFalse); 4435 VARXOR(UI8,0,BSTR,rbstr,I4,0); 4436 VARXOR(UI8,0xffff,BSTR,rbstr,I4,0xffff); 4437 SysFreeString(rbstr); 4438 rbstr = SysAllocString(szTrue); 4439 VARXOR(UI8,0,BSTR,rbstr,I4,-1); 4440 VARXOR(UI8,0xffff,BSTR,rbstr,I4,-65536); 4441 SysFreeString(rbstr); 4442 VARXORCY(UI8,0xffff,10000,I4,65534); 4443 VARXORCY(UI8,0xffff,0,I4,0xffff); 4444 VARXORCY(UI8,0,0,I4,0); 4445 } 4446 4447 VARXOR(INT,-1,INT,-1,I4,0); 4448 VARXOR(INT,-1,INT,0,I4,-1); 4449 VARXOR(INT,0,INT,0,I4,0); 4450 VARXOR(INT,-1,UINT,0xffff,I4,-65536); 4451 VARXOR(INT,-1,UINT,0,I4,-1); 4452 VARXOR(INT,0,UINT,0,I4,0); 4453 rbstr = SysAllocString(szFalse); 4454 VARXOR(INT,0,BSTR,rbstr,I4,0); 4455 VARXOR(INT,-1,BSTR,rbstr,I4,-1); 4456 SysFreeString(rbstr); 4457 rbstr = SysAllocString(szTrue); 4458 VARXOR(INT,0,BSTR,rbstr,I4,-1); 4459 VARXOR(INT,-1,BSTR,rbstr,I4,0); 4460 SysFreeString(rbstr); 4461 VARXORCY(INT,-1,10000,I4,-2); 4462 VARXORCY(INT,-1,0,I4,-1); 4463 VARXORCY(INT,0,0,I4,0); 4464 4465 VARXOR(UINT,0xffff,UINT,0xffff,I4,0); 4466 VARXOR(UINT,0xffff,UINT,0,I4,0xffff); 4467 VARXOR(UINT,0,UINT,0,I4,0); 4468 rbstr = SysAllocString(szFalse); 4469 VARXOR(UINT,0,BSTR,rbstr,I4,0); 4470 VARXOR(UINT,0xffff,BSTR,rbstr,I4,0xffff); 4471 SysFreeString(rbstr); 4472 rbstr = SysAllocString(szTrue); 4473 VARXOR(UINT,0,BSTR,rbstr,I4,-1); 4474 VARXOR(UINT,0xffff,BSTR,rbstr,I4,-65536); 4475 SysFreeString(rbstr); 4476 VARXORCY(UINT,0xffff,10000,I4,65534); 4477 VARXORCY(UINT,0xffff,0,I4,0xffff); 4478 VARXORCY(UINT,0,0,I4,0); 4479 4480 lbstr = SysAllocString(szFalse); 4481 rbstr = SysAllocString(szFalse); 4482 VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,0); 4483 SysFreeString(rbstr); 4484 rbstr = SysAllocString(szTrue); 4485 VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE); 4486 SysFreeString(lbstr); 4487 lbstr = SysAllocString(szTrue); 4488 VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_FALSE); 4489 VARXORCY(BSTR,lbstr,10000,I4,-2); 4490 SysFreeString(lbstr); 4491 lbstr = SysAllocString(szFalse); 4492 VARXORCY(BSTR,lbstr,10000,I4,1); 4493 SysFreeString(lbstr); 4494 SysFreeString(rbstr); 4495 } 4496 4497 static HRESULT (WINAPI *pVarOr)(LPVARIANT,LPVARIANT,LPVARIANT); 4498 4499 #define VAROR(vt1,val1,vt2,val2,rvt,rval) \ 4500 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \ 4501 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \ 4502 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 4503 test_var_call2( __LINE__, pVarOr, &left, &right, &exp ) 4504 4505 #define VARORCY(vt1,val1,val2,rvt,rval) \ 4506 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \ 4507 V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \ 4508 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 4509 test_var_call2( __LINE__, pVarOr, &left, &right, &exp ) 4510 4511 static void test_VarOr(void) 4512 { 4513 static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' }; 4514 static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' }; 4515 VARIANT left, right, exp, result; 4516 BSTR lbstr, rbstr; 4517 VARTYPE i; 4518 HRESULT hres; 4519 4520 CHECKPTR(VarOr); 4521 4522 /* Test all possible flag/vt combinations & the resulting vt type */ 4523 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 4524 { 4525 VARTYPE leftvt, rightvt, resvt; 4526 4527 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++) 4528 { 4529 4530 SKIPTESTS(leftvt); 4531 4532 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++) 4533 { 4534 BOOL bFail = FALSE; 4535 4536 SKIPTESTS(rightvt); 4537 4538 if (leftvt == VT_BSTR || rightvt == VT_BSTR || 4539 leftvt == VT_DISPATCH || rightvt == VT_DISPATCH || 4540 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN) 4541 continue; 4542 4543 memset(&left, 0, sizeof(left)); 4544 memset(&right, 0, sizeof(right)); 4545 V_VT(&left) = leftvt | ExtraFlags[i]; 4546 V_VT(&right) = rightvt | ExtraFlags[i]; 4547 V_VT(&result) = VT_EMPTY; 4548 resvt = VT_I4; 4549 4550 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF || 4551 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) || 4552 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) || 4553 leftvt == VT_CLSID || rightvt == VT_CLSID || 4554 leftvt == VT_RECORD || rightvt == VT_RECORD || 4555 leftvt == VT_VARIANT || rightvt == VT_VARIANT || 4556 leftvt == VT_ERROR || rightvt == VT_ERROR) 4557 { 4558 bFail = TRUE; 4559 } 4560 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY) 4561 { 4562 if (leftvt == rightvt || 4563 leftvt == VT_I2 || rightvt == VT_I2 || 4564 leftvt == VT_UI1 || rightvt == VT_UI1 || 4565 leftvt == VT_BOOL || rightvt == VT_BOOL) 4566 resvt = VT_I2; 4567 else if (leftvt == VT_NULL || rightvt == VT_NULL) 4568 resvt = VT_NULL; 4569 else if (leftvt == VT_I8 || rightvt == VT_I8) 4570 resvt = VT_I8; 4571 } 4572 else if (leftvt == VT_NULL || rightvt == VT_NULL) 4573 { 4574 resvt = VT_NULL; 4575 } 4576 else if (leftvt == VT_UI1 || rightvt == VT_UI1) 4577 { 4578 if (leftvt == rightvt) 4579 resvt = VT_UI1; 4580 else if (leftvt == rightvt || 4581 leftvt == VT_I2 || rightvt == VT_I2 || 4582 leftvt == VT_BOOL || rightvt == VT_BOOL) 4583 { 4584 resvt = VT_I2; 4585 } 4586 else if (leftvt == VT_I8 || rightvt == VT_I8) 4587 resvt = VT_I8; 4588 } 4589 else if (leftvt == VT_I2 || rightvt == VT_I2) 4590 { 4591 if (leftvt == rightvt || 4592 leftvt == VT_BOOL || rightvt == VT_BOOL) 4593 resvt = VT_I2; 4594 else if (leftvt == VT_I8 || rightvt == VT_I8) 4595 resvt = VT_I8; 4596 } 4597 else if (leftvt == VT_BOOL && rightvt == VT_BOOL) 4598 { 4599 resvt = VT_BOOL; 4600 } 4601 else if (leftvt == VT_I8 || rightvt == VT_I8) 4602 { 4603 if (leftvt == VT_INT || rightvt == VT_INT) 4604 bFail = TRUE; 4605 else 4606 resvt = VT_I8; 4607 } 4608 hres = pVarOr(&left, &right, &result); 4609 if (bFail) 4610 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE, 4611 "VarOr: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n", 4612 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres, 4613 V_VT(&result)); 4614 else 4615 ok(hres == S_OK && V_VT(&result) == resvt, 4616 "VarOr: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n", 4617 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres, 4618 V_VT(&result)); 4619 } 4620 } 4621 } 4622 4623 /* Test returned values. Since we know the returned type is correct 4624 * and that we handle all combinations of invalid types, just check 4625 * that good type combinations produce the desired value. 4626 * FIXME: Test VT_DECIMAL/VT_DISPATCH 4627 */ 4628 VAROR(EMPTY,0,EMPTY,0,I2,0); 4629 VAROR(EMPTY,1,EMPTY,0,I2,0); 4630 VAROR(EMPTY,0,NULL,0,NULL,0); 4631 VAROR(EMPTY,0,I1,0,I4,0); 4632 VAROR(EMPTY,0,I1,1,I4,1); 4633 VAROR(EMPTY,0,UI1,0,I2,0); 4634 VAROR(EMPTY,0,UI1,1,I2,1); 4635 VAROR(EMPTY,0,I2,0,I2,0); 4636 VAROR(EMPTY,0,I2,1,I2,1); 4637 VAROR(EMPTY,0,UI2,0,I4,0); 4638 VAROR(EMPTY,0,UI2,1,I4,1); 4639 VAROR(EMPTY,0,I4,0,I4,0); 4640 VAROR(EMPTY,0,I4,1,I4,1); 4641 VAROR(EMPTY,0,UI4,0,I4,0); 4642 VAROR(EMPTY,0,UI4,1,I4,1); 4643 if (has_i8) 4644 { 4645 VAROR(EMPTY,0,I8,0,I8,0); 4646 VAROR(EMPTY,0,I8,1,I8,1); 4647 VAROR(EMPTY,0,UI8,0,I4,0); 4648 VAROR(EMPTY,0,UI8,1,I4,1); 4649 } 4650 VAROR(EMPTY,0,INT,0,I4,0); 4651 VAROR(EMPTY,0,INT,1,I4,1); 4652 VAROR(EMPTY,0,UINT,0,I4,0); 4653 VAROR(EMPTY,0,UINT,1,I4,1); 4654 VAROR(EMPTY,0,BOOL,0,I2,0); 4655 VAROR(EMPTY,0,BOOL,1,I2,1); 4656 VAROR(EMPTY,0,R4,0,I4,0); 4657 VAROR(EMPTY,0,R4,1,I4,1); 4658 VAROR(EMPTY,0,R8,0,I4,0); 4659 VAROR(EMPTY,0,R8,1,I4,1); 4660 rbstr = SysAllocString(szFalse); 4661 VAROR(EMPTY,0,BSTR,rbstr,I2,0); 4662 SysFreeString(rbstr); 4663 rbstr = SysAllocString(szTrue); 4664 VAROR(EMPTY,0,BSTR,rbstr,I2,-1); 4665 SysFreeString(rbstr); 4666 VARORCY(EMPTY,0,10000,I4,1); 4667 4668 /* NULL OR 0 = NULL. NULL OR n = n */ 4669 VAROR(NULL,0,NULL,0,NULL,0); 4670 VAROR(NULL,1,NULL,0,NULL,0); 4671 VAROR(NULL,0,I1,0,NULL,0); 4672 VAROR(NULL,0,I1,1,I4,1); 4673 VAROR(NULL,0,UI1,0,NULL,0); 4674 VAROR(NULL,0,UI1,1,UI1,1); 4675 VAROR(NULL,0,I2,0,NULL,0); 4676 VAROR(NULL,0,I2,1,I2,1); 4677 VAROR(NULL,0,UI2,0,NULL,0); 4678 VAROR(NULL,0,UI2,1,I4,1); 4679 VAROR(NULL,0,I4,0,NULL,0); 4680 VAROR(NULL,0,I4,1,I4,1); 4681 VAROR(NULL,0,UI4,0,NULL,0); 4682 VAROR(NULL,0,UI4,1,I4,1); 4683 if (has_i8) 4684 { 4685 VAROR(NULL,0,I8,0,NULL,0); 4686 VAROR(NULL,0,I8,1,I8,1); 4687 VAROR(NULL,0,UI8,0,NULL,0); 4688 VAROR(NULL,0,UI8,1,I4,1); 4689 } 4690 VAROR(NULL,0,INT,0,NULL,0); 4691 VAROR(NULL,0,INT,1,I4,1); 4692 VAROR(NULL,0,UINT,0,NULL,0); 4693 VAROR(NULL,0,UINT,1,I4,1); 4694 VAROR(NULL,0,BOOL,0,NULL,0); 4695 VAROR(NULL,0,BOOL,1,BOOL,1); 4696 VAROR(NULL,0,R4,0,NULL,0); 4697 VAROR(NULL,0,R4,1,I4,1); 4698 VAROR(NULL,0,R8,0,NULL,0); 4699 VAROR(NULL,0,R8,1,I4,1); 4700 rbstr = SysAllocString(szFalse); 4701 VAROR(NULL,0,BSTR,rbstr,NULL,0); 4702 SysFreeString(rbstr); 4703 rbstr = SysAllocString(szTrue); 4704 VAROR(NULL,0,BSTR,rbstr,BOOL,VARIANT_TRUE); 4705 SysFreeString(rbstr); 4706 VARORCY(NULL,0,10000,I4,1); 4707 VARORCY(NULL,0,0,NULL,0); 4708 4709 VAROR(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE); 4710 VAROR(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE); 4711 VAROR(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE); 4712 VAROR(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE); 4713 /* Assume x,y & y,x are the same from now on to reduce the number of tests */ 4714 VAROR(BOOL,VARIANT_TRUE,I1,-1,I4,-1); 4715 VAROR(BOOL,VARIANT_TRUE,I1,0,I4,-1); 4716 VAROR(BOOL,VARIANT_FALSE,I1,0,I4,0); 4717 VAROR(BOOL,VARIANT_TRUE,UI1,255,I2,-1); 4718 VAROR(BOOL,VARIANT_TRUE,UI1,0,I2,-1); 4719 VAROR(BOOL,VARIANT_FALSE,UI1,0,I2,0); 4720 VAROR(BOOL,VARIANT_TRUE,I2,-1,I2,-1); 4721 VAROR(BOOL,VARIANT_TRUE,I2,0,I2,-1); 4722 VAROR(BOOL,VARIANT_FALSE,I2,0,I2,0); 4723 VAROR(BOOL,VARIANT_TRUE,UI2,65535,I4,-1); 4724 VAROR(BOOL,VARIANT_TRUE,UI2,0,I4,-1); 4725 VAROR(BOOL,VARIANT_FALSE,UI2,0,I4,0); 4726 VAROR(BOOL,VARIANT_TRUE,I4,-1,I4,-1); 4727 VAROR(BOOL,VARIANT_TRUE,I4,0,I4,-1); 4728 VAROR(BOOL,VARIANT_FALSE,I4,0,I4,0); 4729 VAROR(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,-1); 4730 VAROR(BOOL,VARIANT_TRUE,UI4,0,I4,-1); 4731 VAROR(BOOL,VARIANT_FALSE,UI4,0,I4,0); 4732 VAROR(BOOL,VARIANT_TRUE,R4,-1,I4,-1); 4733 VAROR(BOOL,VARIANT_TRUE,R4,0,I4,-1); 4734 VAROR(BOOL,VARIANT_FALSE,R4,0,I4,0); 4735 VAROR(BOOL,VARIANT_TRUE,R8,-1,I4,-1); 4736 VAROR(BOOL,VARIANT_TRUE,R8,0,I4,-1); 4737 VAROR(BOOL,VARIANT_FALSE,R8,0,I4,0); 4738 VAROR(BOOL,VARIANT_TRUE,DATE,-1,I4,-1); 4739 VAROR(BOOL,VARIANT_TRUE,DATE,0,I4,-1); 4740 VAROR(BOOL,VARIANT_FALSE,DATE,0,I4,0); 4741 if (has_i8) 4742 { 4743 VAROR(BOOL,VARIANT_TRUE,I8,-1,I8,-1); 4744 VAROR(BOOL,VARIANT_TRUE,I8,0,I8,-1); 4745 VAROR(BOOL,VARIANT_FALSE,I8,0,I8,0); 4746 /* This returns DISP_E_OVERFLOW which indicates that a conversion 4747 * to I4 is performed. 4748 */ 4749 /* VAROR(BOOL,VARIANT_TRUE,UI8,-1,I4,-1); */ 4750 VAROR(BOOL,VARIANT_TRUE,UI8,0,I4,-1); 4751 VAROR(BOOL,VARIANT_FALSE,UI8,0,I4,0); 4752 } 4753 VAROR(BOOL,VARIANT_TRUE,INT,-1,I4,-1); 4754 VAROR(BOOL,VARIANT_TRUE,INT,0,I4,-1); 4755 VAROR(BOOL,VARIANT_FALSE,INT,0,I4,0); 4756 VAROR(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,-1); 4757 VAROR(BOOL,VARIANT_TRUE,UINT,0,I4,-1); 4758 VAROR(BOOL,VARIANT_FALSE,UINT,0,I4,0); 4759 rbstr = SysAllocString(szFalse); 4760 VAROR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_FALSE); 4761 VAROR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE); 4762 SysFreeString(rbstr); 4763 rbstr = SysAllocString(szTrue); 4764 VAROR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_TRUE); 4765 VAROR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE); 4766 SysFreeString(rbstr); 4767 VARORCY(BOOL,VARIANT_TRUE,10000,I4,-1); 4768 VARORCY(BOOL,VARIANT_TRUE,0,I4,-1); 4769 VARORCY(BOOL,VARIANT_FALSE,0,I4,0); 4770 4771 VAROR(I1,-1,I1,-1,I4,-1); 4772 VAROR(I1,-1,I1,0,I4,-1); 4773 VAROR(I1,0,I1,0,I4,0); 4774 VAROR(I1,-1,UI1,255,I4,-1); 4775 VAROR(I1,-1,UI1,0,I4,-1); 4776 VAROR(I1,0,UI1,0,I4,0); 4777 VAROR(I1,-1,I2,-1,I4,-1); 4778 VAROR(I1,-1,I2,0,I4,-1); 4779 VAROR(I1,0,I2,0,I4,0); 4780 VAROR(I1,-1,UI2,65535,I4,-1); 4781 VAROR(I1,-1,UI2,0,I4,-1); 4782 VAROR(I1,0,UI2,0,I4,0); 4783 VAROR(I1,-1,I4,-1,I4,-1); 4784 VAROR(I1,-1,I4,0,I4,-1); 4785 VAROR(I1,0,I4,0,I4,0); 4786 VAROR(I1,-1,UI4,0xffffffff,I4,-1); 4787 VAROR(I1,-1,UI4,0,I4,-1); 4788 VAROR(I1,0,UI4,0,I4,0); 4789 VAROR(I1,-1,R4,-1,I4,-1); 4790 VAROR(I1,-1,R4,0,I4,-1); 4791 VAROR(I1,0,R4,0,I4,0); 4792 VAROR(I1,-1,R8,-1,I4,-1); 4793 VAROR(I1,-1,R8,0,I4,-1); 4794 VAROR(I1,0,R8,0,I4,0); 4795 VAROR(I1,-1,DATE,-1,I4,-1); 4796 VAROR(I1,-1,DATE,0,I4,-1); 4797 VAROR(I1,0,DATE,0,I4,0); 4798 if (has_i8) 4799 { 4800 VAROR(I1,-1,I8,-1,I8,-1); 4801 VAROR(I1,-1,I8,0,I8,-1); 4802 VAROR(I1,0,I8,0,I8,0); 4803 VAROR(I1,-1,UI8,0,I4,-1); 4804 VAROR(I1,0,UI8,0,I4,0); 4805 } 4806 VAROR(I1,-1,INT,-1,I4,-1); 4807 VAROR(I1,-1,INT,0,I4,-1); 4808 VAROR(I1,0,INT,0,I4,0); 4809 VAROR(I1,-1,UINT,0xffffffff,I4,-1); 4810 VAROR(I1,-1,UINT,0,I4,-1); 4811 VAROR(I1,0,UINT,0,I4,0); 4812 rbstr = SysAllocString(szFalse); 4813 VAROR(I1,0,BSTR,rbstr,I4,0); 4814 VAROR(I1,-1,BSTR,rbstr,I4,-1); 4815 SysFreeString(rbstr); 4816 rbstr = SysAllocString(szTrue); 4817 VAROR(I1,0,BSTR,rbstr,I4,-1); 4818 VAROR(I1,-1,BSTR,rbstr,I4,-1); 4819 SysFreeString(rbstr); 4820 VARORCY(I1,-1,10000,I4,-1); 4821 VARORCY(I1,-1,0,I4,-1); 4822 VARORCY(I1,0,0,I4,0); 4823 4824 VAROR(UI1,255,UI1,255,UI1,255); 4825 VAROR(UI1,255,UI1,0,UI1,255); 4826 VAROR(UI1,0,UI1,0,UI1,0); 4827 VAROR(UI1,255,I2,-1,I2,-1); 4828 VAROR(UI1,255,I2,0,I2,255); 4829 VAROR(UI1,0,I2,0,I2,0); 4830 VAROR(UI1,255,UI2,65535,I4,65535); 4831 VAROR(UI1,255,UI2,0,I4,255); 4832 VAROR(UI1,0,UI2,0,I4,0); 4833 VAROR(UI1,255,I4,-1,I4,-1); 4834 VAROR(UI1,255,I4,0,I4,255); 4835 VAROR(UI1,0,I4,0,I4,0); 4836 VAROR(UI1,255,UI4,0xffffffff,I4,-1); 4837 VAROR(UI1,255,UI4,0,I4,255); 4838 VAROR(UI1,0,UI4,0,I4,0); 4839 VAROR(UI1,255,R4,-1,I4,-1); 4840 VAROR(UI1,255,R4,0,I4,255); 4841 VAROR(UI1,0,R4,0,I4,0); 4842 VAROR(UI1,255,R8,-1,I4,-1); 4843 VAROR(UI1,255,R8,0,I4,255); 4844 VAROR(UI1,0,R8,0,I4,0); 4845 VAROR(UI1,255,DATE,-1,I4,-1); 4846 VAROR(UI1,255,DATE,0,I4,255); 4847 VAROR(UI1,0,DATE,0,I4,0); 4848 if (has_i8) 4849 { 4850 VAROR(UI1,255,I8,-1,I8,-1); 4851 VAROR(UI1,255,I8,0,I8,255); 4852 VAROR(UI1,0,I8,0,I8,0); 4853 VAROR(UI1,255,UI8,0,I4,255); 4854 VAROR(UI1,0,UI8,0,I4,0); 4855 } 4856 VAROR(UI1,255,INT,-1,I4,-1); 4857 VAROR(UI1,255,INT,0,I4,255); 4858 VAROR(UI1,0,INT,0,I4,0); 4859 VAROR(UI1,255,UINT,0xffffffff,I4,-1); 4860 VAROR(UI1,255,UINT,0,I4,255); 4861 VAROR(UI1,0,UINT,0,I4,0); 4862 rbstr = SysAllocString(szFalse); 4863 VAROR(UI1,0,BSTR,rbstr,I2,0); 4864 VAROR(UI1,255,BSTR,rbstr,I2,255); 4865 SysFreeString(rbstr); 4866 rbstr = SysAllocString(szTrue); 4867 VAROR(UI1,0,BSTR,rbstr,I2,-1); 4868 VAROR(UI1,255,BSTR,rbstr,I2,-1); 4869 SysFreeString(rbstr); 4870 VARORCY(UI1,255,10000,I4,255); 4871 VARORCY(UI1,255,0,I4,255); 4872 VARORCY(UI1,0,0,I4,0); 4873 4874 VAROR(I2,-1,I2,-1,I2,-1); 4875 VAROR(I2,-1,I2,0,I2,-1); 4876 VAROR(I2,0,I2,0,I2,0); 4877 VAROR(I2,-1,UI2,65535,I4,-1); 4878 VAROR(I2,-1,UI2,0,I4,-1); 4879 VAROR(I2,0,UI2,0,I4,0); 4880 VAROR(I2,-1,I4,-1,I4,-1); 4881 VAROR(I2,-1,I4,0,I4,-1); 4882 VAROR(I2,0,I4,0,I4,0); 4883 VAROR(I2,-1,UI4,0xffffffff,I4,-1); 4884 VAROR(I2,-1,UI4,0,I4,-1); 4885 VAROR(I2,0,UI4,0,I4,0); 4886 VAROR(I2,-1,R4,-1,I4,-1); 4887 VAROR(I2,-1,R4,0,I4,-1); 4888 VAROR(I2,0,R4,0,I4,0); 4889 VAROR(I2,-1,R8,-1,I4,-1); 4890 VAROR(I2,-1,R8,0,I4,-1); 4891 VAROR(I2,0,R8,0,I4,0); 4892 VAROR(I2,-1,DATE,-1,I4,-1); 4893 VAROR(I2,-1,DATE,0,I4,-1); 4894 VAROR(I2,0,DATE,0,I4,0); 4895 if (has_i8) 4896 { 4897 VAROR(I2,-1,I8,-1,I8,-1); 4898 VAROR(I2,-1,I8,0,I8,-1); 4899 VAROR(I2,0,I8,0,I8,0); 4900 VAROR(I2,-1,UI8,0,I4,-1); 4901 VAROR(I2,0,UI8,0,I4,0); 4902 } 4903 VAROR(I2,-1,INT,-1,I4,-1); 4904 VAROR(I2,-1,INT,0,I4,-1); 4905 VAROR(I2,0,INT,0,I4,0); 4906 VAROR(I2,-1,UINT,0xffffffff,I4,-1); 4907 VAROR(I2,-1,UINT,0,I4,-1); 4908 VAROR(I2,0,UINT,0,I4,0); 4909 rbstr = SysAllocString(szFalse); 4910 VAROR(I2,0,BSTR,rbstr,I2,0); 4911 VAROR(I2,-1,BSTR,rbstr,I2,-1); 4912 SysFreeString(rbstr); 4913 rbstr = SysAllocString(szTrue); 4914 VAROR(I2,0,BSTR,rbstr,I2,-1); 4915 VAROR(I2,-1,BSTR,rbstr,I2,-1); 4916 SysFreeString(rbstr); 4917 VARORCY(I2,-1,10000,I4,-1); 4918 VARORCY(I2,-1,0,I4,-1); 4919 VARORCY(I2,0,0,I4,0); 4920 4921 VAROR(UI2,65535,UI2,65535,I4,65535); 4922 VAROR(UI2,65535,UI2,0,I4,65535); 4923 VAROR(UI2,0,UI2,0,I4,0); 4924 VAROR(UI2,65535,I4,-1,I4,-1); 4925 VAROR(UI2,65535,I4,0,I4,65535); 4926 VAROR(UI2,0,I4,0,I4,0); 4927 VAROR(UI2,65535,UI4,0xffffffff,I4,-1); 4928 VAROR(UI2,65535,UI4,0,I4,65535); 4929 VAROR(UI2,0,UI4,0,I4,0); 4930 VAROR(UI2,65535,R4,-1,I4,-1); 4931 VAROR(UI2,65535,R4,0,I4,65535); 4932 VAROR(UI2,0,R4,0,I4,0); 4933 VAROR(UI2,65535,R8,-1,I4,-1); 4934 VAROR(UI2,65535,R8,0,I4,65535); 4935 VAROR(UI2,0,R8,0,I4,0); 4936 VAROR(UI2,65535,DATE,-1,I4,-1); 4937 VAROR(UI2,65535,DATE,0,I4,65535); 4938 VAROR(UI2,0,DATE,0,I4,0); 4939 if (has_i8) 4940 { 4941 VAROR(UI2,65535,I8,-1,I8,-1); 4942 VAROR(UI2,65535,I8,0,I8,65535); 4943 VAROR(UI2,0,I8,0,I8,0); 4944 VAROR(UI2,65535,UI8,0,I4,65535); 4945 VAROR(UI2,0,UI8,0,I4,0); 4946 } 4947 VAROR(UI2,65535,INT,-1,I4,-1); 4948 VAROR(UI2,65535,INT,0,I4,65535); 4949 VAROR(UI2,0,INT,0,I4,0); 4950 VAROR(UI2,65535,UINT,0xffffffff,I4,-1); 4951 VAROR(UI2,65535,UINT,0,I4,65535); 4952 VAROR(UI2,0,UINT,0,I4,0); 4953 rbstr = SysAllocString(szFalse); 4954 VAROR(UI2,0,BSTR,rbstr,I4,0); 4955 VAROR(UI2,65535,BSTR,rbstr,I4,65535); 4956 SysFreeString(rbstr); 4957 rbstr = SysAllocString(szTrue); 4958 VAROR(UI2,0,BSTR,rbstr,I4,-1); 4959 VAROR(UI2,65535,BSTR,rbstr,I4,-1); 4960 SysFreeString(rbstr); 4961 VARORCY(UI2,65535,10000,I4,65535); 4962 VARORCY(UI2,65535,0,I4,65535); 4963 VARORCY(UI2,0,0,I4,0); 4964 4965 VAROR(I4,-1,I4,-1,I4,-1); 4966 VAROR(I4,-1,I4,0,I4,-1); 4967 VAROR(I4,0,I4,0,I4,0); 4968 VAROR(I4,-1,UI4,0xffffffff,I4,-1); 4969 VAROR(I4,-1,UI4,0,I4,-1); 4970 VAROR(I4,0,UI4,0,I4,0); 4971 VAROR(I4,-1,R4,-1,I4,-1); 4972 VAROR(I4,-1,R4,0,I4,-1); 4973 VAROR(I4,0,R4,0,I4,0); 4974 VAROR(I4,-1,R8,-1,I4,-1); 4975 VAROR(I4,-1,R8,0,I4,-1); 4976 VAROR(I4,0,R8,0,I4,0); 4977 VAROR(I4,-1,DATE,-1,I4,-1); 4978 VAROR(I4,-1,DATE,0,I4,-1); 4979 VAROR(I4,0,DATE,0,I4,0); 4980 if (has_i8) 4981 { 4982 VAROR(I4,-1,I8,-1,I8,-1); 4983 VAROR(I4,-1,I8,0,I8,-1); 4984 VAROR(I4,0,I8,0,I8,0); 4985 VAROR(I4,-1,UI8,0,I4,-1); 4986 VAROR(I4,0,UI8,0,I4,0); 4987 } 4988 VAROR(I4,-1,INT,-1,I4,-1); 4989 VAROR(I4,-1,INT,0,I4,-1); 4990 VAROR(I4,0,INT,0,I4,0); 4991 VAROR(I4,-1,UINT,0xffffffff,I4,-1); 4992 VAROR(I4,-1,UINT,0,I4,-1); 4993 VAROR(I4,0,UINT,0,I4,0); 4994 rbstr = SysAllocString(szFalse); 4995 VAROR(I4,0,BSTR,rbstr,I4,0); 4996 VAROR(I4,-1,BSTR,rbstr,I4,-1); 4997 SysFreeString(rbstr); 4998 rbstr = SysAllocString(szTrue); 4999 VAROR(I4,0,BSTR,rbstr,I4,-1); 5000 VAROR(I4,-1,BSTR,rbstr,I4,-1); 5001 SysFreeString(rbstr); 5002 VARORCY(I4,-1,10000,I4,-1); 5003 VARORCY(I4,-1,0,I4,-1); 5004 VARORCY(I4,0,0,I4,0); 5005 5006 VAROR(UI4,0xffffffff,UI4,0xffffffff,I4,-1); 5007 VAROR(UI4,0xffffffff,UI4,0,I4,-1); 5008 VAROR(UI4,0,UI4,0,I4,0); 5009 VAROR(UI4,0xffffffff,R4,-1,I4,-1); 5010 VAROR(UI4,0xffffffff,R4,0,I4,-1); 5011 VAROR(UI4,0,R4,0,I4,0); 5012 VAROR(UI4,0xffffffff,R8,-1,I4,-1); 5013 VAROR(UI4,0xffffffff,R8,0,I4,-1); 5014 VAROR(UI4,0,R8,0,I4,0); 5015 VAROR(UI4,0xffffffff,DATE,-1,I4,-1); 5016 VAROR(UI4,0xffffffff,DATE,0,I4,-1); 5017 VAROR(UI4,0,DATE,0,I4,0); 5018 if (has_i8) 5019 { 5020 VAROR(UI4,0xffffffff,I8,-1,I8,-1); 5021 VAROR(UI4,0xffffffff,I8,0,I8,0xffffffff); 5022 VAROR(UI4,0,I8,0,I8,0); 5023 VAROR(UI4,0xffffffff,UI8,0,I4,-1); 5024 VAROR(UI4,0,UI8,0,I4,0); 5025 } 5026 VAROR(UI4,0xffffffff,INT,-1,I4,-1); 5027 VAROR(UI4,0xffffffff,INT,0,I4,-1); 5028 VAROR(UI4,0,INT,0,I4,0); 5029 VAROR(UI4,0xffffffff,UINT,0xffffffff,I4,-1); 5030 VAROR(UI4,0xffffffff,UINT,0,I4,-1); 5031 VAROR(UI4,0,UINT,0,I4,0); 5032 rbstr = SysAllocString(szFalse); 5033 VAROR(UI4,0,BSTR,rbstr,I4,0); 5034 VAROR(UI4,0xffffffff,BSTR,rbstr,I4,-1); 5035 SysFreeString(rbstr); 5036 rbstr = SysAllocString(szTrue); 5037 VAROR(UI4,0,BSTR,rbstr,I4,-1); 5038 VAROR(UI4,0xffffffff,BSTR,rbstr,I4,-1); 5039 SysFreeString(rbstr); 5040 VARORCY(UI4,0xffffffff,10000,I4,-1); 5041 VARORCY(UI4,0xffffffff,0,I4,-1); 5042 VARORCY(UI4,0,0,I4,0); 5043 5044 VAROR(R4,-1,R4,-1,I4,-1); 5045 VAROR(R4,-1,R4,0,I4,-1); 5046 VAROR(R4,0,R4,0,I4,0); 5047 VAROR(R4,-1,R8,-1,I4,-1); 5048 VAROR(R4,-1,R8,0,I4,-1); 5049 VAROR(R4,0,R8,0,I4,0); 5050 VAROR(R4,-1,DATE,-1,I4,-1); 5051 VAROR(R4,-1,DATE,0,I4,-1); 5052 VAROR(R4,0,DATE,0,I4,0); 5053 if (has_i8) 5054 { 5055 VAROR(R4,-1,I8,-1,I8,-1); 5056 VAROR(R4,-1,I8,0,I8,-1); 5057 VAROR(R4,0,I8,0,I8,0); 5058 VAROR(R4,-1,UI8,0,I4,-1); 5059 VAROR(R4,0,UI8,0,I4,0); 5060 } 5061 VAROR(R4,-1,INT,-1,I4,-1); 5062 VAROR(R4,-1,INT,0,I4,-1); 5063 VAROR(R4,0,INT,0,I4,0); 5064 VAROR(R4,-1,UINT,0xffffffff,I4,-1); 5065 VAROR(R4,-1,UINT,0,I4,-1); 5066 VAROR(R4,0,UINT,0,I4,0); 5067 rbstr = SysAllocString(szFalse); 5068 VAROR(R4,0,BSTR,rbstr,I4,0); 5069 VAROR(R4,-1,BSTR,rbstr,I4,-1); 5070 SysFreeString(rbstr); 5071 rbstr = SysAllocString(szTrue); 5072 VAROR(R4,0,BSTR,rbstr,I4,-1); 5073 VAROR(R4,-1,BSTR,rbstr,I4,-1); 5074 SysFreeString(rbstr); 5075 VARORCY(R4,-1,10000,I4,-1); 5076 VARORCY(R4,-1,0,I4,-1); 5077 VARORCY(R4,0,0,I4,0); 5078 5079 VAROR(R8,-1,R8,-1,I4,-1); 5080 VAROR(R8,-1,R8,0,I4,-1); 5081 VAROR(R8,0,R8,0,I4,0); 5082 VAROR(R8,-1,DATE,-1,I4,-1); 5083 VAROR(R8,-1,DATE,0,I4,-1); 5084 VAROR(R8,0,DATE,0,I4,0); 5085 if (has_i8) 5086 { 5087 VAROR(R8,-1,I8,-1,I8,-1); 5088 VAROR(R8,-1,I8,0,I8,-1); 5089 VAROR(R8,0,I8,0,I8,0); 5090 VAROR(R8,-1,UI8,0,I4,-1); 5091 VAROR(R8,0,UI8,0,I4,0); 5092 } 5093 VAROR(R8,-1,INT,-1,I4,-1); 5094 VAROR(R8,-1,INT,0,I4,-1); 5095 VAROR(R8,0,INT,0,I4,0); 5096 VAROR(R8,-1,UINT,0xffffffff,I4,-1); 5097 VAROR(R8,-1,UINT,0,I4,-1); 5098 VAROR(R8,0,UINT,0,I4,0); 5099 rbstr = SysAllocString(szFalse); 5100 VAROR(R8,0,BSTR,rbstr,I4,0); 5101 VAROR(R8,-1,BSTR,rbstr,I4,-1); 5102 SysFreeString(rbstr); 5103 rbstr = SysAllocString(szTrue); 5104 VAROR(R8,0,BSTR,rbstr,I4,-1); 5105 VAROR(R8,-1,BSTR,rbstr,I4,-1); 5106 SysFreeString(rbstr); 5107 VARORCY(R8,-1,10000,I4,-1); 5108 VARORCY(R8,-1,0,I4,-1); 5109 VARORCY(R8,0,0,I4,0); 5110 5111 VAROR(DATE,-1,DATE,-1,I4,-1); 5112 VAROR(DATE,-1,DATE,0,I4,-1); 5113 VAROR(DATE,0,DATE,0,I4,0); 5114 if (has_i8) 5115 { 5116 VAROR(DATE,-1,I8,-1,I8,-1); 5117 VAROR(DATE,-1,I8,0,I8,-1); 5118 VAROR(DATE,0,I8,0,I8,0); 5119 VAROR(DATE,-1,UI8,0,I4,-1); 5120 VAROR(DATE,0,UI8,0,I4,0); 5121 } 5122 VAROR(DATE,-1,INT,-1,I4,-1); 5123 VAROR(DATE,-1,INT,0,I4,-1); 5124 VAROR(DATE,0,INT,0,I4,0); 5125 VAROR(DATE,-1,UINT,0xffffffff,I4,-1); 5126 VAROR(DATE,-1,UINT,0,I4,-1); 5127 VAROR(DATE,0,UINT,0,I4,0); 5128 rbstr = SysAllocString(szFalse); 5129 VAROR(DATE,0,BSTR,rbstr,I4,0); 5130 VAROR(DATE,-1,BSTR,rbstr,I4,-1); 5131 SysFreeString(rbstr); 5132 rbstr = SysAllocString(szTrue); 5133 VAROR(DATE,0,BSTR,rbstr,I4,-1); 5134 VAROR(DATE,-1,BSTR,rbstr,I4,-1); 5135 SysFreeString(rbstr); 5136 VARORCY(DATE,-1,10000,I4,-1); 5137 VARORCY(DATE,-1,0,I4,-1); 5138 VARORCY(DATE,0,0,I4,0); 5139 5140 if (has_i8) 5141 { 5142 VAROR(I8,-1,I8,-1,I8,-1); 5143 VAROR(I8,-1,I8,0,I8,-1); 5144 VAROR(I8,0,I8,0,I8,0); 5145 VAROR(I8,-1,UI8,0,I8,-1); 5146 VAROR(I8,0,UI8,0,I8,0); 5147 /* These overflow under native and Wine 5148 VAROR(I8,-1,INT,-1,I4,-1); 5149 VAROR(I8,-1,INT,0,I4,-1); 5150 VAROR(I8,0,INT,0,I4,0); */ 5151 VAROR(I8,-1,UINT,0xffffffff,I8,-1); 5152 VAROR(I8,-1,UINT,0,I8,-1); 5153 VAROR(I8,0,UINT,0,I8,0); 5154 rbstr = SysAllocString(szFalse); 5155 VAROR(I8,0,BSTR,rbstr,I8,0); 5156 VAROR(I8,-1,BSTR,rbstr,I8,-1); 5157 SysFreeString(rbstr); 5158 rbstr = SysAllocString(szTrue); 5159 VAROR(I8,0,BSTR,rbstr,I8,-1); 5160 VAROR(I8,-1,BSTR,rbstr,I8,-1); 5161 SysFreeString(rbstr); 5162 VARORCY(I8,-1,10000,I8,-1); 5163 VARORCY(I8,-1,0,I8,-1); 5164 VARORCY(I8,0,0,I8,0); 5165 5166 VAROR(UI8,0xffff,UI8,0xffff,I4,0xffff); 5167 VAROR(UI8,0xffff,UI8,0,I4,0xffff); 5168 VAROR(UI8,0,UI8,0,I4,0); 5169 VAROR(UI8,0xffff,INT,-1,I4,-1); 5170 VAROR(UI8,0xffff,INT,0,I4,0xffff); 5171 VAROR(UI8,0,INT,0,I4,0); 5172 VAROR(UI8,0xffff,UINT,0xffff,I4,0xffff); 5173 VAROR(UI8,0xffff,UINT,0,I4,0xffff); 5174 VAROR(UI8,0,UINT,0,I4,0); 5175 rbstr = SysAllocString(szFalse); 5176 VAROR(UI8,0,BSTR,rbstr,I4,0); 5177 VAROR(UI8,0xffff,BSTR,rbstr,I4,0xffff); 5178 SysFreeString(rbstr); 5179 rbstr = SysAllocString(szTrue); 5180 VAROR(UI8,0,BSTR,rbstr,I4,-1); 5181 VAROR(UI8,0xffff,BSTR,rbstr,I4,-1); 5182 SysFreeString(rbstr); 5183 VARORCY(UI8,0xffff,10000,I4,0xffff); 5184 VARORCY(UI8,0xffff,0,I4,0xffff); 5185 VARORCY(UI8,0,0,I4,0); 5186 } 5187 5188 VAROR(INT,-1,INT,-1,I4,-1); 5189 VAROR(INT,-1,INT,0,I4,-1); 5190 VAROR(INT,0,INT,0,I4,0); 5191 VAROR(INT,-1,UINT,0xffff,I4,-1); 5192 VAROR(INT,-1,UINT,0,I4,-1); 5193 VAROR(INT,0,UINT,0,I4,0); 5194 rbstr = SysAllocString(szFalse); 5195 VAROR(INT,0,BSTR,rbstr,I4,0); 5196 VAROR(INT,-1,BSTR,rbstr,I4,-1); 5197 SysFreeString(rbstr); 5198 rbstr = SysAllocString(szTrue); 5199 VAROR(INT,0,BSTR,rbstr,I4,-1); 5200 VAROR(INT,-1,BSTR,rbstr,I4,-1); 5201 SysFreeString(rbstr); 5202 VARORCY(INT,-1,10000,I4,-1); 5203 VARORCY(INT,-1,0,I4,-1); 5204 VARORCY(INT,0,0,I4,0); 5205 5206 VAROR(UINT,0xffff,UINT,0xffff,I4,0xffff); 5207 VAROR(UINT,0xffff,UINT,0,I4,0xffff); 5208 VAROR(UINT,0,UINT,0,I4,0); 5209 rbstr = SysAllocString(szFalse); 5210 VAROR(UINT,0,BSTR,rbstr,I4,0); 5211 VAROR(UINT,0xffff,BSTR,rbstr,I4,0xffff); 5212 SysFreeString(rbstr); 5213 rbstr = SysAllocString(szTrue); 5214 VAROR(UINT,0,BSTR,rbstr,I4,-1); 5215 VAROR(UINT,0xffff,BSTR,rbstr,I4,-1); 5216 SysFreeString(rbstr); 5217 VARORCY(UINT,0xffff,10000,I4,0xffff); 5218 VARORCY(UINT,0xffff,0,I4,0xffff); 5219 VARORCY(UINT,0,0,I4,0); 5220 5221 lbstr = SysAllocString(szFalse); 5222 rbstr = SysAllocString(szFalse); 5223 VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,0); 5224 SysFreeString(rbstr); 5225 rbstr = SysAllocString(szTrue); 5226 VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE); 5227 SysFreeString(lbstr); 5228 lbstr = SysAllocString(szTrue); 5229 VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE); 5230 VARORCY(BSTR,lbstr,10000,I4,-1); 5231 SysFreeString(lbstr); 5232 lbstr = SysAllocString(szFalse); 5233 VARORCY(BSTR,lbstr,10000,I4,1); 5234 SysFreeString(lbstr); 5235 SysFreeString(rbstr); 5236 } 5237 5238 static HRESULT (WINAPI *pVarEqv)(LPVARIANT,LPVARIANT,LPVARIANT); 5239 5240 #define VAREQV(vt1,val1,vt2,val2,rvt,rval) \ 5241 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \ 5242 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \ 5243 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 5244 test_var_call2( __LINE__, pVarEqv, &left, &right, &exp ) 5245 5246 static void test_VarEqv(void) 5247 { 5248 VARIANT left, right, exp, result; 5249 VARTYPE i; 5250 HRESULT hres; 5251 5252 CHECKPTR(VarEqv); 5253 5254 /* Test all possible flag/vt combinations & the resulting vt type */ 5255 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 5256 { 5257 VARTYPE leftvt, rightvt, resvt; 5258 5259 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++) 5260 { 5261 SKIPTESTS(leftvt); 5262 5263 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++) 5264 { 5265 BOOL bFail = FALSE; 5266 5267 SKIPTESTS(rightvt); 5268 5269 if (leftvt == VT_BSTR || rightvt == VT_BSTR || 5270 leftvt == VT_DISPATCH || rightvt == VT_DISPATCH || 5271 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN) 5272 continue; 5273 5274 memset(&left, 0, sizeof(left)); 5275 memset(&right, 0, sizeof(right)); 5276 V_VT(&left) = leftvt | ExtraFlags[i]; 5277 V_VT(&right) = rightvt | ExtraFlags[i]; 5278 V_VT(&result) = VT_EMPTY; 5279 resvt = VT_I4; 5280 5281 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF || 5282 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) || 5283 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) || 5284 leftvt == VT_CLSID || rightvt == VT_CLSID || 5285 leftvt == VT_RECORD || rightvt == VT_RECORD || 5286 leftvt == VT_VARIANT || rightvt == VT_VARIANT || 5287 leftvt == VT_ERROR || rightvt == VT_ERROR) 5288 { 5289 bFail = TRUE; 5290 } 5291 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY) 5292 { 5293 if (leftvt == rightvt || 5294 leftvt == VT_I2 || rightvt == VT_I2 || 5295 leftvt == VT_UI1 || rightvt == VT_UI1 || 5296 leftvt == VT_BOOL || rightvt == VT_BOOL) 5297 resvt = VT_I2; 5298 else if (leftvt == VT_NULL || rightvt == VT_NULL) 5299 resvt = VT_NULL; 5300 else if (leftvt == VT_I8 || rightvt == VT_I8) 5301 resvt = VT_I8; 5302 } 5303 else if (leftvt == VT_NULL || rightvt == VT_NULL) 5304 { 5305 resvt = VT_NULL; 5306 } 5307 else if (leftvt == VT_UI1 || rightvt == VT_UI1) 5308 { 5309 if (leftvt == rightvt) 5310 resvt = VT_UI1; 5311 else if (leftvt == rightvt || 5312 leftvt == VT_I2 || rightvt == VT_I2 || 5313 leftvt == VT_BOOL || rightvt == VT_BOOL) 5314 { 5315 resvt = VT_I2; 5316 } 5317 else if (leftvt == VT_I8 || rightvt == VT_I8) 5318 resvt = VT_I8; 5319 } 5320 else if (leftvt == VT_I2 || rightvt == VT_I2) 5321 { 5322 if (leftvt == rightvt || 5323 leftvt == VT_BOOL || rightvt == VT_BOOL) 5324 resvt = VT_I2; 5325 else if (leftvt == VT_I8 || rightvt == VT_I8) 5326 resvt = VT_I8; 5327 } 5328 else if (leftvt == VT_BOOL && rightvt == VT_BOOL) 5329 { 5330 resvt = VT_BOOL; 5331 } 5332 else if (leftvt == VT_I8 || rightvt == VT_I8) 5333 { 5334 if (leftvt == VT_INT || rightvt == VT_INT) 5335 bFail = TRUE; 5336 else 5337 resvt = VT_I8; 5338 } 5339 hres = pVarEqv(&left, &right, &result); 5340 if (bFail) 5341 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE, 5342 "VarEqv: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n", 5343 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres, 5344 V_VT(&result)); 5345 else 5346 ok(hres == S_OK && V_VT(&result) == resvt, 5347 "VarEqv: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n", 5348 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres, 5349 V_VT(&result)); 5350 } 5351 } 5352 } 5353 5354 /* Test returned values */ 5355 VAREQV(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE); 5356 VAREQV(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE); 5357 VAREQV(BOOL,TRUE,BOOL,TRUE,BOOL,VARIANT_TRUE); 5358 VAREQV(BOOL,FALSE,BOOL,FALSE,BOOL,VARIANT_TRUE); 5359 VAREQV(BOOL,TRUE,BOOL,FALSE,BOOL,-2); 5360 VAREQV(BOOL,FALSE,BOOL,TRUE,BOOL,-2); 5361 VAREQV(BOOL,6,BOOL,7,BOOL,-2); 5362 VAREQV(BOOL,6,BOOL,6,BOOL,VARIANT_TRUE); 5363 VAREQV(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE,I2,VARIANT_TRUE); 5364 VAREQV(BOOL,VARIANT_TRUE,I2,VARIANT_FALSE,I2,VARIANT_FALSE); 5365 VAREQV(BOOL,6,I2,7,I2,-2); 5366 VAREQV(UI1,1,UI1,1,UI1,255); 5367 VAREQV(UI1,1,UI1,0,UI1,254); 5368 VAREQV(UI1,0,UI1,1,UI1,254); 5369 if (has_i8) 5370 { 5371 VAREQV(UI4,VARIANT_FALSE,I8,VARIANT_FALSE,I8,-1); 5372 VAREQV(UI4,5,I8,19,I8,-23); 5373 VAREQV(UI4,VARIANT_FALSE,UI8,VARIANT_FALSE,I4,-1); 5374 } 5375 } 5376 5377 static HRESULT (WINAPI *pVarMul)(LPVARIANT,LPVARIANT,LPVARIANT); 5378 5379 #define VARMUL(vt1,val1,vt2,val2,rvt,rval) \ 5380 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \ 5381 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \ 5382 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 5383 test_var_call2( __LINE__, pVarMul, &left, &right, &exp ) 5384 5385 static void test_VarMul(void) 5386 { 5387 VARIANT left, right, exp, result, cy, dec; 5388 VARTYPE i; 5389 BSTR lbstr, rbstr; 5390 HRESULT hres; 5391 double r; 5392 5393 CHECKPTR(VarMul); 5394 5395 lbstr = SysAllocString(sz12); 5396 rbstr = SysAllocString(sz12); 5397 5398 /* Test all possible flag/vt combinations & the resulting vt type */ 5399 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 5400 { 5401 VARTYPE leftvt, rightvt, resvt; 5402 5403 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++) 5404 { 5405 5406 SKIPTESTS(leftvt); 5407 5408 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++) 5409 { 5410 BOOL bFail = FALSE; 5411 5412 SKIPTESTS(rightvt); 5413 5414 if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH || 5415 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN) 5416 continue; 5417 5418 memset(&left, 0, sizeof(left)); 5419 memset(&right, 0, sizeof(right)); 5420 V_VT(&left) = leftvt | ExtraFlags[i]; 5421 if (leftvt == VT_BSTR) 5422 V_BSTR(&left) = lbstr; 5423 V_VT(&right) = rightvt | ExtraFlags[i]; 5424 if (rightvt == VT_BSTR) 5425 V_BSTR(&right) = rbstr; 5426 V_VT(&result) = VT_EMPTY; 5427 resvt = VT_UNKNOWN; 5428 5429 /* Don't ask me why but native VarMul cannot handle: 5430 VT_I1, VT_UI2, VT_UI4, VT_INT, VT_UINT and VT_UI8. 5431 Tested with DCOM98, Win2k, WinXP */ 5432 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF || 5433 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) || 5434 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) || 5435 leftvt == VT_CLSID || rightvt == VT_CLSID || 5436 leftvt == VT_RECORD || rightvt == VT_RECORD || 5437 leftvt == VT_VARIANT || rightvt == VT_VARIANT || 5438 leftvt == VT_ERROR || rightvt == VT_ERROR || 5439 leftvt == VT_I1 || rightvt == VT_I1 || 5440 leftvt == VT_UI2 || rightvt == VT_UI2 || 5441 leftvt == VT_UI4 || rightvt == VT_UI4 || 5442 leftvt == VT_UI8 || rightvt == VT_UI8 || 5443 leftvt == VT_INT || rightvt == VT_INT || 5444 leftvt == VT_UINT || rightvt == VT_UINT) { 5445 bFail = TRUE; 5446 } 5447 5448 if (leftvt == VT_NULL || rightvt == VT_NULL) 5449 resvt = VT_NULL; 5450 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL) 5451 resvt = VT_DECIMAL; 5452 else if (leftvt == VT_R8 || rightvt == VT_R8 || 5453 leftvt == VT_BSTR || rightvt == VT_BSTR || 5454 leftvt == VT_DATE || rightvt == VT_DATE) 5455 resvt = VT_R8; 5456 else if (leftvt == VT_R4 || rightvt == VT_R4) { 5457 if (leftvt == VT_I4 || rightvt == VT_I4 || 5458 leftvt == VT_I8 || rightvt == VT_I8 || 5459 leftvt == VT_CY || rightvt == VT_CY) 5460 resvt = VT_R8; 5461 else 5462 resvt = VT_R4; 5463 } else if (leftvt == VT_CY || rightvt == VT_CY) 5464 resvt = VT_CY; 5465 else if (leftvt == VT_I8 || rightvt == VT_I8) 5466 resvt = VT_I8; 5467 else if (leftvt == VT_I4 || rightvt == VT_I4) 5468 resvt = VT_I4; 5469 else if (leftvt == VT_I2 || rightvt == VT_I2 || 5470 leftvt == VT_BOOL || rightvt == VT_BOOL || 5471 (leftvt == VT_EMPTY && rightvt == VT_EMPTY)) 5472 resvt = VT_I2; 5473 else if (leftvt == VT_UI1 || rightvt == VT_UI1) 5474 resvt = VT_UI1; 5475 5476 hres = pVarMul(&left, &right, &result); 5477 if (bFail) { 5478 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE, 5479 "VarMul: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n", 5480 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres, 5481 V_VT(&result)); 5482 } else { 5483 ok(hres == S_OK && V_VT(&result) == resvt, 5484 "VarMul: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n", 5485 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres, 5486 V_VT(&result)); 5487 } 5488 } 5489 } 5490 } 5491 5492 /* Test returned values */ 5493 VARMUL(I4,4,I4,2,I4,8); 5494 VARMUL(I2,4,I2,2,I2,8); 5495 VARMUL(I2,-13,I4,5,I4,-65); 5496 VARMUL(I4,-13,I4,5,I4,-65); 5497 VARMUL(I2,7,R4,0.5f,R4,3.5f); 5498 VARMUL(R4,0.5f,I4,5,R8,2.5); 5499 VARMUL(R8,7.1,BOOL,0,R8,0); 5500 VARMUL(BSTR,lbstr,I2,4,R8,48); 5501 VARMUL(BSTR,lbstr,BOOL,1,R8,12); 5502 VARMUL(BSTR,lbstr,R4,0.1f,R8,1.2); 5503 VARMUL(BSTR,lbstr,BSTR,rbstr,R8,144); 5504 VARMUL(R4,0.2f,BSTR,rbstr,R8,2.4); 5505 VARMUL(DATE,2.25,I4,7,R8,15.75); 5506 5507 VARMUL(UI1, UI1_MAX, UI1, UI1_MAX, I4, UI1_MAX * UI1_MAX); 5508 VARMUL(I2, I2_MAX, I2, I2_MAX, I4, I2_MAX * I2_MAX); 5509 VARMUL(I2, I2_MAX, I2, I2_MIN, I4, I2_MAX * I2_MIN); 5510 VARMUL(I2, I2_MIN, I2, I2_MIN, I4, I2_MIN * I2_MIN); 5511 VARMUL(I4, I4_MAX, I4, I4_MAX, R8, (double)I4_MAX * I4_MAX); 5512 VARMUL(I4, I4_MAX, I4, I4_MIN, R8, (double)I4_MAX * I4_MIN); 5513 VARMUL(I4, I4_MIN, I4, I4_MIN, R8, (double)I4_MIN * I4_MIN); 5514 VARMUL(R4, R4_MAX, R4, R4_MAX, R8, (double)R4_MAX * R4_MAX); 5515 VARMUL(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX * R4_MIN); 5516 VARMUL(R4, R4_MIN, R4, R4_MIN, R4, R4_MIN * R4_MIN); 5517 VARMUL(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX * R8_MIN); 5518 VARMUL(R8, R8_MIN, R8, R8_MIN, R8, R8_MIN * R8_MIN); 5519 5520 /* Manuly test some VT_CY and VT_DECIMAL variants */ 5521 V_VT(&cy) = VT_CY; 5522 hres = VarCyFromI4(4711, &V_CY(&cy)); 5523 ok(hres == S_OK, "VarCyFromI4 failed!\n"); 5524 V_VT(&dec) = VT_DECIMAL; 5525 hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec)); 5526 ok(hres == S_OK, "VarDecFromR4 failed!\n"); 5527 memset(&left, 0, sizeof(left)); 5528 memset(&right, 0, sizeof(right)); 5529 V_VT(&left) = VT_I4; 5530 V_I4(&left) = -11; 5531 V_VT(&right) = VT_UI1; 5532 V_UI1(&right) = 9; 5533 5534 hres = pVarMul(&cy, &right, &result); 5535 ok(hres == S_OK && V_VT(&result) == VT_CY, "VarMul: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result))); 5536 hres = VarR8FromCy(V_CY(&result), &r); 5537 ok(hres == S_OK && EQ_DOUBLE(r, 42399.0), "VarMul: CY value %f, expected %f\n", r, (double)42399); 5538 5539 hres = pVarMul(&left, &dec, &result); 5540 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL, "VarMul: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result))); 5541 hres = VarR8FromDec(&V_DECIMAL(&result), &r); 5542 ok(hres == S_OK && EQ_DOUBLE(r, 46.2), "VarMul: DECIMAL value %f, expected %f\n", r, (double)46.2); 5543 5544 SysFreeString(lbstr); 5545 SysFreeString(rbstr); 5546 } 5547 5548 static HRESULT (WINAPI *pVarAdd)(LPVARIANT,LPVARIANT,LPVARIANT); 5549 5550 #define VARADD(vt1,val1,vt2,val2,rvt,rval) \ 5551 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \ 5552 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \ 5553 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 5554 test_var_call2( __LINE__, pVarAdd, &left, &right, &exp ) 5555 5556 static void test_VarAdd(void) 5557 { 5558 VARIANT left, right, exp, result, cy, dec; 5559 VARTYPE i; 5560 BSTR lbstr, rbstr; 5561 HRESULT hres; 5562 double r; 5563 5564 CHECKPTR(VarAdd); 5565 5566 lbstr = SysAllocString(sz12); 5567 rbstr = SysAllocString(sz12); 5568 5569 /* Test all possible flag/vt combinations & the resulting vt type */ 5570 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 5571 { 5572 VARTYPE leftvt, rightvt, resvt; 5573 5574 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++) 5575 { 5576 5577 SKIPTESTS(leftvt); 5578 5579 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++) 5580 { 5581 BOOL bFail = FALSE; 5582 5583 SKIPTESTS(rightvt); 5584 5585 if (leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN) 5586 continue; 5587 5588 memset(&left, 0, sizeof(left)); 5589 memset(&right, 0, sizeof(right)); 5590 V_VT(&left) = leftvt | ExtraFlags[i]; 5591 if (leftvt == VT_BSTR) 5592 V_BSTR(&left) = lbstr; 5593 V_VT(&right) = rightvt | ExtraFlags[i]; 5594 if (rightvt == VT_BSTR) 5595 V_BSTR(&right) = rbstr; 5596 V_VT(&result) = VT_EMPTY; 5597 resvt = VT_ERROR; 5598 5599 /* Don't ask me why but native VarAdd cannot handle: 5600 VT_I1, VT_UI2, VT_UI4, VT_INT, VT_UINT and VT_UI8. 5601 Tested with DCOM98, Win2k, WinXP */ 5602 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF || 5603 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) || 5604 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) || 5605 leftvt == VT_CLSID || rightvt == VT_CLSID || 5606 leftvt == VT_RECORD || rightvt == VT_RECORD || 5607 leftvt == VT_VARIANT || rightvt == VT_VARIANT || 5608 leftvt == VT_ERROR || rightvt == VT_ERROR || 5609 leftvt == VT_I1 || rightvt == VT_I1 || 5610 leftvt == VT_UI2 || rightvt == VT_UI2 || 5611 leftvt == VT_UI4 || rightvt == VT_UI4 || 5612 leftvt == VT_UI8 || rightvt == VT_UI8 || 5613 leftvt == VT_INT || rightvt == VT_INT || 5614 leftvt == VT_UINT || rightvt == VT_UINT) { 5615 bFail = TRUE; 5616 } 5617 5618 if (leftvt == VT_NULL || rightvt == VT_NULL) 5619 resvt = VT_NULL; 5620 else if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH) 5621 bFail = TRUE; 5622 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL) 5623 resvt = VT_DECIMAL; 5624 else if (leftvt == VT_DATE || rightvt == VT_DATE) 5625 resvt = VT_DATE; 5626 else if (leftvt == VT_CY || rightvt == VT_CY) 5627 resvt = VT_CY; 5628 else if (leftvt == VT_R8 || rightvt == VT_R8) 5629 resvt = VT_R8; 5630 else if (leftvt == VT_BSTR || rightvt == VT_BSTR) { 5631 if ((leftvt == VT_BSTR && rightvt == VT_BSTR) || 5632 leftvt == VT_EMPTY || rightvt == VT_EMPTY) 5633 resvt = VT_BSTR; 5634 else 5635 resvt = VT_R8; 5636 } else if (leftvt == VT_R4 || rightvt == VT_R4) { 5637 if (leftvt == VT_I4 || rightvt == VT_I4 || 5638 leftvt == VT_I8 || rightvt == VT_I8) 5639 resvt = VT_R8; 5640 else 5641 resvt = VT_R4; 5642 } 5643 else if (leftvt == VT_I8 || rightvt == VT_I8) 5644 resvt = VT_I8; 5645 else if (leftvt == VT_I4 || rightvt == VT_I4) 5646 resvt = VT_I4; 5647 else if (leftvt == VT_I2 || rightvt == VT_I2 || 5648 leftvt == VT_BOOL || rightvt == VT_BOOL || 5649 (leftvt == VT_EMPTY && rightvt == VT_EMPTY)) 5650 resvt = VT_I2; 5651 else if (leftvt == VT_UI1 || rightvt == VT_UI1) 5652 resvt = VT_UI1; 5653 5654 hres = pVarAdd(&left, &right, &result); 5655 if (bFail) { 5656 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE, 5657 "VarAdd: %d|0x%X, %d|0x%X: Expected failure, got 0x%X vt %d\n", 5658 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres, 5659 V_VT(&result)); 5660 } else { 5661 ok(hres == S_OK && V_VT(&result) == resvt, 5662 "VarAdd: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%X vt %d\n", 5663 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres, 5664 V_VT(&result)); 5665 } 5666 /* Note, we don't clear left/right deliberately here */ 5667 VariantClear(&result); 5668 } 5669 } 5670 } 5671 5672 /* Test returned values */ 5673 VARADD(I4,4,I4,2,I4,6); 5674 VARADD(I2,4,I2,2,I2,6); 5675 VARADD(I2,-13,I4,5,I4,-8); 5676 VARADD(I4,-13,I4,5,I4,-8); 5677 VARADD(I2,7,R4,0.5f,R4,7.5f); 5678 VARADD(R4,0.5f,I4,5,R8,5.5); 5679 VARADD(R8,7.1,BOOL,0,R8,7.1); 5680 VARADD(BSTR,lbstr,I2,4,R8,16); 5681 VARADD(BSTR,lbstr,BOOL,1,R8,13); 5682 VARADD(BSTR,lbstr,R4,0.1f,R8,12.1); 5683 VARADD(R4,0.2f,BSTR,rbstr,R8,12.2); 5684 VARADD(DATE,2.25,I4,7,DATE,9.25); 5685 VARADD(DATE,1.25,R4,-1.7f,DATE,-0.45); 5686 5687 VARADD(UI1, UI1_MAX, UI1, UI1_MAX, I2, UI1_MAX + UI1_MAX); 5688 VARADD(I2, I2_MAX, I2, I2_MAX, I4, I2_MAX + I2_MAX); 5689 VARADD(I2, I2_MAX, I2, I2_MIN, I2, I2_MAX + I2_MIN); 5690 VARADD(I2, I2_MIN, I2, I2_MIN, I4, I2_MIN + I2_MIN); 5691 VARADD(I4, I4_MAX, I4, I4_MIN, I4, I4_MAX + I4_MIN); 5692 VARADD(I4, I4_MAX, I4, I4_MAX, R8, (double)I4_MAX + I4_MAX); 5693 VARADD(I4, I4_MIN, I4, I4_MIN, R8, (double)I4_MIN + I4_MIN); 5694 VARADD(R4, R4_MAX, R4, R4_MAX, R8, (double)R4_MAX + R4_MAX); 5695 VARADD(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX + R4_MIN); 5696 VARADD(R4, R4_MIN, R4, R4_MIN, R4, R4_MIN + R4_MIN); 5697 VARADD(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX + R8_MIN); 5698 VARADD(R8, R8_MIN, R8, R8_MIN, R8, R8_MIN + R8_MIN); 5699 5700 /* Manually test BSTR + BSTR */ 5701 V_VT(&left) = VT_BSTR; 5702 V_BSTR(&left) = lbstr; 5703 V_VT(&right) = VT_BSTR; 5704 V_BSTR(&right) = rbstr; 5705 hres = pVarAdd(&left, &right, &result); 5706 ok(hres == S_OK && V_VT(&result) == VT_BSTR, "VarAdd: expected coerced type VT_BSTR, got %s!\n", vtstr(V_VT(&result))); 5707 hres = VarR8FromStr(V_BSTR(&result), 0, 0, &r); 5708 ok(hres == S_OK && EQ_DOUBLE(r, 1212.0), "VarAdd: BSTR value %f, expected %f\n", r, (double)1212); 5709 VariantClear(&result); 5710 5711 /* Manuly test some VT_CY and VT_DECIMAL variants */ 5712 V_VT(&cy) = VT_CY; 5713 hres = VarCyFromI4(4711, &V_CY(&cy)); 5714 ok(hres == S_OK, "VarCyFromI4 failed!\n"); 5715 V_VT(&dec) = VT_DECIMAL; 5716 hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec)); 5717 ok(hres == S_OK, "VarDecFromR4 failed!\n"); 5718 memset(&left, 0, sizeof(left)); 5719 memset(&right, 0, sizeof(right)); 5720 V_VT(&left) = VT_I4; 5721 V_I4(&left) = -11; 5722 V_VT(&right) = VT_UI1; 5723 V_UI1(&right) = 9; 5724 5725 hres = pVarAdd(&cy, &right, &result); 5726 ok(hres == S_OK && V_VT(&result) == VT_CY, "VarAdd: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result))); 5727 hres = VarR8FromCy(V_CY(&result), &r); 5728 ok(hres == S_OK && EQ_DOUBLE(r, 4720.0), "VarAdd: CY value %f, expected %f\n", r, (double)4720); 5729 5730 hres = pVarAdd(&left, &dec, &result); 5731 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL, "VarAdd: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result))); 5732 hres = VarR8FromDec(&V_DECIMAL(&result), &r); 5733 ok(hres == S_OK && EQ_DOUBLE(r, -15.2), "VarAdd: DECIMAL value %f, expected %f\n", r, (double)-15.2); 5734 VariantClear(&result); 5735 5736 SysFreeString(lbstr); 5737 SysFreeString(rbstr); 5738 } 5739 5740 static HRESULT (WINAPI *pVarCmp)(LPVARIANT,LPVARIANT,LCID,ULONG); 5741 static HRESULT (WINAPI *pVarCat)(LPVARIANT,LPVARIANT,LPVARIANT); 5742 5743 static void test_VarCat(void) 5744 { 5745 LCID lcid; 5746 VARIANT left, right, result, expected, expected_broken; 5747 static const WCHAR sz34[] = {'3','4','\0'}; 5748 static const WCHAR sz1234[] = {'1','2','3','4','\0'}; 5749 static const WCHAR date_sz12[] = {'9','/','3','0','/','1','9','8','0','1','2','\0'}; 5750 static const WCHAR date_sz12_broken[] = {'9','/','3','0','/','8','0','1','2','\0'}; 5751 static const WCHAR sz12_date[] = {'1','2','9','/','3','0','/','1','9','8','0','\0'}; 5752 static const WCHAR sz12_date_broken[] = {'1','2','9','/','3','0','/','8','0','\0'}; 5753 static const WCHAR sz_empty[] = {'\0'}; 5754 CHAR orig_date_format[128]; 5755 VARTYPE leftvt, rightvt, resultvt; 5756 HRESULT hres; 5757 HRESULT expected_error_num; 5758 int cmp; 5759 DummyDispatch dispatch; 5760 5761 CHECKPTR(VarCat); 5762 5763 /* Set date format for testing */ 5764 lcid = LOCALE_USER_DEFAULT; 5765 GetLocaleInfoA(lcid,LOCALE_SSHORTDATE,orig_date_format,128); 5766 SetLocaleInfoA(lcid,LOCALE_SSHORTDATE,"M/d/yyyy"); 5767 5768 VariantInit(&left); 5769 VariantInit(&right); 5770 VariantInit(&result); 5771 VariantInit(&expected); 5772 5773 /* Check expected types for all combinations */ 5774 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++) 5775 { 5776 5777 SKIPTESTS(leftvt); 5778 5779 /* Check if we need/have support for I8 and/or UI8 */ 5780 if ((leftvt == VT_I8 || leftvt == VT_UI8) && !has_i8) 5781 continue; 5782 5783 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++) 5784 { 5785 5786 SKIPTESTS(rightvt); 5787 expected_error_num = S_OK; 5788 resultvt = VT_EMPTY; 5789 5790 if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH || 5791 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN || 5792 leftvt == VT_RECORD || rightvt == VT_RECORD || 5793 leftvt == 15 || rightvt == 15 /* Undefined type */) 5794 continue; 5795 5796 /* Check if we need/have support for I8 and/or UI8 */ 5797 if ((rightvt == VT_I8 || rightvt == VT_UI8) && !has_i8) 5798 continue; 5799 5800 if (leftvt == VT_NULL && rightvt == VT_NULL) 5801 resultvt = VT_NULL; 5802 else if (leftvt == VT_VARIANT && (rightvt == VT_ERROR || 5803 rightvt == VT_DATE || rightvt == VT_DECIMAL)) 5804 expected_error_num = DISP_E_TYPEMISMATCH; 5805 else if ((leftvt == VT_I2 || leftvt == VT_I4 || 5806 leftvt == VT_R4 || leftvt == VT_R8 || 5807 leftvt == VT_CY || leftvt == VT_BOOL || 5808 leftvt == VT_BSTR || leftvt == VT_I1 || 5809 leftvt == VT_UI1 || leftvt == VT_UI2 || 5810 leftvt == VT_UI4 || leftvt == VT_I8 || 5811 leftvt == VT_UI8 || leftvt == VT_INT || 5812 leftvt == VT_UINT || leftvt == VT_EMPTY || 5813 leftvt == VT_NULL || leftvt == VT_DECIMAL || 5814 leftvt == VT_DATE) 5815 && 5816 (rightvt == VT_I2 || rightvt == VT_I4 || 5817 rightvt == VT_R4 || rightvt == VT_R8 || 5818 rightvt == VT_CY || rightvt == VT_BOOL || 5819 rightvt == VT_BSTR || rightvt == VT_I1 || 5820 rightvt == VT_UI1 || rightvt == VT_UI2 || 5821 rightvt == VT_UI4 || rightvt == VT_I8 || 5822 rightvt == VT_UI8 || rightvt == VT_INT || 5823 rightvt == VT_UINT || rightvt == VT_EMPTY || 5824 rightvt == VT_NULL || rightvt == VT_DECIMAL || 5825 rightvt == VT_DATE)) 5826 resultvt = VT_BSTR; 5827 else if (rightvt == VT_ERROR && leftvt < VT_VOID) 5828 expected_error_num = DISP_E_TYPEMISMATCH; 5829 else if (leftvt == VT_ERROR && (rightvt == VT_DATE || 5830 rightvt == VT_ERROR || rightvt == VT_DECIMAL)) 5831 expected_error_num = DISP_E_TYPEMISMATCH; 5832 else if (rightvt == VT_DATE || rightvt == VT_ERROR || 5833 rightvt == VT_DECIMAL) 5834 expected_error_num = DISP_E_BADVARTYPE; 5835 else if (leftvt == VT_ERROR || rightvt == VT_ERROR) 5836 expected_error_num = DISP_E_TYPEMISMATCH; 5837 else if (leftvt == VT_VARIANT) 5838 expected_error_num = DISP_E_TYPEMISMATCH; 5839 else if (rightvt == VT_VARIANT && (leftvt == VT_EMPTY || 5840 leftvt == VT_NULL || leftvt == VT_I2 || 5841 leftvt == VT_I4 || leftvt == VT_R4 || 5842 leftvt == VT_R8 || leftvt == VT_CY || 5843 leftvt == VT_DATE || leftvt == VT_BSTR || 5844 leftvt == VT_BOOL || leftvt == VT_DECIMAL || 5845 leftvt == VT_I1 || leftvt == VT_UI1 || 5846 leftvt == VT_UI2 || leftvt == VT_UI4 || 5847 leftvt == VT_I8 || leftvt == VT_UI8 || 5848 leftvt == VT_INT || leftvt == VT_UINT 5849 )) 5850 expected_error_num = DISP_E_TYPEMISMATCH; 5851 else 5852 expected_error_num = DISP_E_BADVARTYPE; 5853 5854 V_VT(&left) = leftvt; 5855 V_VT(&right) = rightvt; 5856 5857 switch (leftvt) { 5858 case VT_BSTR: 5859 V_BSTR(&left) = SysAllocString(sz_empty); break; 5860 case VT_DATE: 5861 V_DATE(&left) = 0.0; break; 5862 case VT_DECIMAL: 5863 VarDecFromR8(0.0, &V_DECIMAL(&left)); break; 5864 default: 5865 V_I8(&left) = 0; 5866 } 5867 5868 switch (rightvt) { 5869 case VT_BSTR: 5870 V_BSTR(&right) = SysAllocString(sz_empty); break; 5871 case VT_DATE: 5872 V_DATE(&right) = 0.0; break; 5873 case VT_DECIMAL: 5874 VarDecFromR8(0.0, &V_DECIMAL(&right)); break; 5875 default: 5876 V_I8(&right) = 0; 5877 } 5878 5879 hres = pVarCat(&left, &right, &result); 5880 5881 /* Determine the error code for the vt combination */ 5882 ok(hres == expected_error_num, 5883 "VarCat: %d, %d returned error, 0x%X expected 0x%X.\n", 5884 leftvt, rightvt, hres, expected_error_num); 5885 5886 /* Check types are correct */ 5887 ok(V_VT(&result) == resultvt, 5888 "VarCat: %d, %d: expected vt %d, got vt %d\n", 5889 leftvt, rightvt, resultvt, V_VT(&result)); 5890 5891 VariantClear(&left); 5892 VariantClear(&right); 5893 VariantClear(&result); 5894 } 5895 } 5896 5897 /* Running single comparison tests to compare outputs */ 5898 5899 /* Test concat strings */ 5900 V_VT(&left) = VT_BSTR; 5901 V_VT(&right) = VT_BSTR; 5902 V_VT(&expected) = VT_BSTR; 5903 V_BSTR(&left) = SysAllocString(sz12); 5904 V_BSTR(&right) = SysAllocString(sz34); 5905 V_BSTR(&expected) = SysAllocString(sz1234); 5906 hres = pVarCat(&left,&right,&result); 5907 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres); 5908 if (pVarCmp) 5909 ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ, 5910 "VarCat: VT_BSTR concat with VT_BSTR failed to return correct result\n"); 5911 5912 VariantClear(&left); 5913 VariantClear(&right); 5914 VariantClear(&result); 5915 5916 /* Test if expression is VT_ERROR */ 5917 V_VT(&left) = VT_ERROR; 5918 V_VT(&right) = VT_BSTR; 5919 V_BSTR(&right) = SysAllocString(sz1234); 5920 hres = pVarCat(&left,&right,&result); 5921 ok(hres == DISP_E_TYPEMISMATCH, "VarCat should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hres); 5922 ok(V_VT(&result) == VT_EMPTY, 5923 "VarCat: VT_ERROR concat with VT_BSTR should have returned VT_EMPTY\n"); 5924 5925 VariantClear(&left); 5926 VariantClear(&right); 5927 VariantClear(&result); 5928 5929 V_VT(&left) = VT_BSTR; 5930 V_VT(&right) = VT_ERROR; 5931 V_BSTR(&left) = SysAllocString(sz1234); 5932 hres = pVarCat(&left,&right,&result); 5933 ok(hres == DISP_E_TYPEMISMATCH, "VarCat should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hres); 5934 ok(V_VT(&result) == VT_EMPTY, 5935 "VarCat: VT_BSTR concat with VT_ERROR should have returned VT_EMPTY\n"); 5936 5937 VariantClear(&left); 5938 VariantClear(&right); 5939 VariantClear(&result); 5940 VariantClear(&expected); 5941 5942 /* Test combining boolean with number */ 5943 V_VT(&left) = VT_INT; 5944 V_VT(&right) = VT_BOOL; 5945 V_VT(&expected) = VT_BSTR; 5946 V_INT(&left) = 12; 5947 V_BOOL(&right) = TRUE; 5948 V_BSTR(&expected) = SysAllocString(sz12_true); 5949 hres = pVarCat(&left,&right,&result); 5950 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres); 5951 if (pVarCmp) 5952 { 5953 hres = pVarCmp(&result,&expected,lcid,0); 5954 ok(hres == VARCMP_EQ, "Expected VARCMP_EQ, got %08x for %s, %s\n", 5955 hres, variantstr(&result), variantstr(&expected)); 5956 } 5957 5958 VariantClear(&left); 5959 VariantClear(&right); 5960 VariantClear(&result); 5961 VariantClear(&expected); 5962 5963 V_VT(&left) = VT_INT; 5964 V_VT(&right) = VT_BOOL; 5965 V_VT(&expected) = VT_BSTR; 5966 V_INT(&left) = 12; 5967 V_BOOL(&right) = FALSE; 5968 V_BSTR(&expected) = SysAllocString(sz12_false); 5969 hres = pVarCat(&left,&right,&result); 5970 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres); 5971 if (pVarCmp) 5972 { 5973 hres = pVarCmp(&result,&expected,lcid,0); 5974 ok(hres == VARCMP_EQ, "Expected VARCMP_EQ, got %08x for %s, %s\n", 5975 hres, variantstr(&result), variantstr(&expected)); 5976 } 5977 5978 VariantClear(&left); 5979 VariantClear(&right); 5980 VariantClear(&result); 5981 VariantClear(&expected); 5982 5983 /* Test when both expressions are numeric */ 5984 V_VT(&left) = VT_INT; 5985 V_VT(&right) = VT_INT; 5986 V_VT(&expected) = VT_BSTR; 5987 V_INT(&left) = 12; 5988 V_INT(&right) = 34; 5989 V_BSTR(&expected) = SysAllocString(sz1234); 5990 hres = pVarCat(&left,&right,&result); 5991 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres); 5992 if (pVarCmp) 5993 ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ, 5994 "VarCat: NUMBER concat with NUMBER returned incorrect result\n"); 5995 5996 VariantClear(&left); 5997 VariantClear(&right); 5998 VariantClear(&result); 5999 6000 /* Test if one expression is numeric and the other is a string */ 6001 V_VT(&left) = VT_INT; 6002 V_VT(&right) = VT_BSTR; 6003 V_INT(&left) = 12; 6004 V_BSTR(&right) = SysAllocString(sz34); 6005 hres = pVarCat(&left,&right,&result); 6006 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres); 6007 if (pVarCmp) 6008 ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ, 6009 "VarCat: NUMBER concat with VT_BSTR, incorrect result\n"); 6010 6011 VariantClear(&left); 6012 VariantClear(&right); 6013 VariantClear(&result); 6014 6015 V_VT(&left) = VT_BSTR; 6016 V_VT(&right) = VT_INT; 6017 V_BSTR(&left) = SysAllocString(sz12); 6018 V_INT(&right) = 34; 6019 hres = pVarCat(&left,&right,&result); 6020 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres); 6021 if (pVarCmp) 6022 ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ, 6023 "VarCat: VT_BSTR concat with NUMBER, incorrect result\n"); 6024 6025 VariantClear(&left); 6026 VariantClear(&right); 6027 VariantClear(&result); 6028 VariantClear(&expected); 6029 6030 /* Test concat dates with strings */ 6031 V_VT(&left) = VT_BSTR; 6032 V_VT(&right) = VT_DATE; 6033 V_VT(&expected) = VT_BSTR; 6034 V_VT(&expected_broken) = VT_BSTR; 6035 V_BSTR(&left) = SysAllocString(sz12); 6036 V_DATE(&right) = 29494.0; 6037 V_BSTR(&expected)= SysAllocString(sz12_date); 6038 V_BSTR(&expected_broken)= SysAllocString(sz12_date_broken); 6039 hres = pVarCat(&left,&right,&result); 6040 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres); 6041 if (pVarCmp) 6042 ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ || 6043 broken(pVarCmp(&result,&expected_broken,lcid,0) == VARCMP_EQ), /* Some W98 and NT4 (intermittent) */ 6044 "VarCat: VT_BSTR concat with VT_DATE returned incorrect result\n"); 6045 6046 VariantClear(&left); 6047 VariantClear(&right); 6048 VariantClear(&result); 6049 VariantClear(&expected); 6050 VariantClear(&expected_broken); 6051 6052 V_VT(&left) = VT_DATE; 6053 V_VT(&right) = VT_BSTR; 6054 V_VT(&expected) = VT_BSTR; 6055 V_VT(&expected_broken) = VT_BSTR; 6056 V_DATE(&left) = 29494.0; 6057 V_BSTR(&right) = SysAllocString(sz12); 6058 V_BSTR(&expected)= SysAllocString(date_sz12); 6059 V_BSTR(&expected_broken)= SysAllocString(date_sz12_broken); 6060 hres = pVarCat(&left,&right,&result); 6061 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres); 6062 if (pVarCmp) 6063 ok(pVarCmp(&result,&expected,lcid,0) == VARCMP_EQ || 6064 broken(pVarCmp(&result,&expected_broken,lcid,0) == VARCMP_EQ), /* Some W98 and NT4 (intermittent) */ 6065 "VarCat: VT_DATE concat with VT_BSTR returned incorrect result\n"); 6066 6067 VariantClear(&left); 6068 VariantClear(&right); 6069 VariantClear(&result); 6070 VariantClear(&expected); 6071 VariantClear(&expected_broken); 6072 6073 /* Test of both expressions are empty */ 6074 V_VT(&left) = VT_BSTR; 6075 V_VT(&right) = VT_BSTR; 6076 V_VT(&expected) = VT_BSTR; 6077 V_BSTR(&left) = SysAllocString(sz_empty); 6078 V_BSTR(&right) = SysAllocString(sz_empty); 6079 V_BSTR(&expected)= SysAllocString(sz_empty); 6080 hres = pVarCat(&left,&right,&result); 6081 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres); 6082 if (pVarCmp) 6083 ok(pVarCmp(&result,&left,lcid,0) == VARCMP_EQ, 6084 "VarCat: EMPTY concat with EMPTY did not return empty VT_BSTR\n"); 6085 6086 /* Restore original date format settings */ 6087 SetLocaleInfoA(lcid,LOCALE_SSHORTDATE,orig_date_format); 6088 6089 VariantClear(&left); 6090 VariantClear(&right); 6091 VariantClear(&result); 6092 VariantClear(&expected); 6093 6094 /* Dispatch conversion */ 6095 init_test_dispatch(VT_NULL, &dispatch); 6096 V_VT(&left) = VT_DISPATCH; 6097 V_DISPATCH(&left) = &dispatch.IDispatch_iface; 6098 6099 SET_EXPECT(dispatch_invoke); 6100 hres = VarCat(&left, &right, &result); 6101 ok(hres == S_OK, "got 0x%08x\n", hres); 6102 ok(V_VT(&result) == VT_BSTR, "got %d\n", V_VT(&result)); 6103 ok(SysStringLen(V_BSTR(&result)) == 0, "got %d\n", SysStringLen(V_BSTR(&result))); 6104 CHECK_CALLED(dispatch_invoke); 6105 6106 VariantClear(&left); 6107 VariantClear(&right); 6108 VariantClear(&result); 6109 6110 init_test_dispatch(VT_NULL, &dispatch); 6111 V_VT(&right) = VT_DISPATCH; 6112 V_DISPATCH(&right) = &dispatch.IDispatch_iface; 6113 6114 SET_EXPECT(dispatch_invoke); 6115 hres = VarCat(&left, &right, &result); 6116 ok(hres == S_OK, "got 0x%08x\n", hres); 6117 ok(V_VT(&result) == VT_BSTR, "got %d\n", V_VT(&result)); 6118 ok(SysStringLen(V_BSTR(&result)) == 0, "got %d\n", SysStringLen(V_BSTR(&result))); 6119 CHECK_CALLED(dispatch_invoke); 6120 6121 VariantClear(&left); 6122 VariantClear(&right); 6123 VariantClear(&result); 6124 6125 init_test_dispatch(VT_UI1, &dispatch); 6126 V_VT(&right) = VT_DISPATCH; 6127 V_DISPATCH(&right) = &dispatch.IDispatch_iface; 6128 6129 V_VT(&left) = VT_BSTR; 6130 V_BSTR(&left) = SysAllocString(sz12); 6131 SET_EXPECT(dispatch_invoke); 6132 hres = pVarCat(&left,&right,&result); 6133 ok(hres == S_OK, "VarCat failed with error 0x%08x\n", hres); 6134 CHECK_CALLED(dispatch_invoke); 6135 ok(!strcmp_wa(V_BSTR(&result), "1234"), "got %s\n", wine_dbgstr_w(V_BSTR(&result))); 6136 6137 VariantClear(&left); 6138 VariantClear(&right); 6139 VariantClear(&result); 6140 6141 init_test_dispatch(VT_NULL, &dispatch); 6142 dispatch.result = E_OUTOFMEMORY; 6143 V_VT(&right) = VT_DISPATCH; 6144 V_DISPATCH(&right) = &dispatch.IDispatch_iface; 6145 6146 SET_EXPECT(dispatch_invoke); 6147 hres = VarCat(&left, &right, &result); 6148 ok(hres == E_OUTOFMEMORY, "got 0x%08x\n", hres); 6149 CHECK_CALLED(dispatch_invoke); 6150 6151 VariantClear(&left); 6152 VariantClear(&right); 6153 VariantClear(&result); 6154 6155 init_test_dispatch(VT_NULL, &dispatch); 6156 dispatch.result = DISP_E_TYPEMISMATCH; 6157 V_VT(&right) = VT_DISPATCH; 6158 V_DISPATCH(&right) = &dispatch.IDispatch_iface; 6159 6160 SET_EXPECT(dispatch_invoke); 6161 hres = VarCat(&left, &right, &result); 6162 ok(hres == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hres); 6163 CHECK_CALLED(dispatch_invoke); 6164 6165 VariantClear(&left); 6166 VariantClear(&right); 6167 VariantClear(&result); 6168 6169 /* Test boolean conversion */ 6170 V_VT(&left) = VT_BOOL; 6171 V_BOOL(&left) = VARIANT_TRUE; 6172 V_VT(&right) = VT_BSTR; 6173 V_BSTR(&right) = SysAllocStringLen(NULL,0); 6174 hres = pVarCat(&left, &right, &result); 6175 ok(hres == S_OK, "VarCat failed: %08x\n", hres); 6176 VariantClear(&right); 6177 6178 cmp = strcmp_wa(V_BSTR(&result), "True"); 6179 VariantClear(&result); 6180 if(!cmp) { 6181 V_VT(&right) = VT_BOOL; 6182 V_BOOL(&right) = 100; 6183 hres = pVarCat(&left, &right, &result); 6184 ok(hres == S_OK, "VarCat failed: %08x\n", hres); 6185 test_bstr_var(&result, "TrueTrue"); 6186 VariantClear(&result); 6187 6188 V_BOOL(&right) = VARIANT_FALSE; 6189 hres = pVarCat(&left, &right, &result); 6190 ok(hres == S_OK, "VarCat failed: %08x\n", hres); 6191 test_bstr_var(&result, "TrueFalse"); 6192 VariantClear(&result); 6193 }else { 6194 skip("Got %s as True, assuming non-English locale\n", wine_dbgstr_w(V_BSTR(&result))); 6195 } 6196 } 6197 6198 static HRESULT (WINAPI *pVarAnd)(LPVARIANT,LPVARIANT,LPVARIANT); 6199 6200 #define VARAND(vt1,val1,vt2,val2,rvt,rval) \ 6201 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \ 6202 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \ 6203 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 6204 test_var_call2( __LINE__, pVarAnd, &left, &right, &exp ) 6205 6206 #define VARANDCY(vt1,val1,val2,rvt,rval) \ 6207 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \ 6208 V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \ 6209 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 6210 test_var_call2( __LINE__, pVarAnd, &left, &right, &exp ) 6211 6212 /* Skip any type that is not defined or produces an error for every case */ 6213 #define SKIPTESTAND(a) \ 6214 if (a == VT_ERROR || a == VT_VARIANT || \ 6215 a == VT_DISPATCH || a == VT_UNKNOWN || \ 6216 a > VT_UINT || a == 15 /*not defined*/) \ 6217 continue 6218 6219 static void test_VarAnd(void) 6220 { 6221 static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' }; 6222 static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' }; 6223 VARIANT left, right, exp, result; 6224 BSTR false_str, true_str; 6225 VARTYPE i; 6226 HRESULT hres; 6227 6228 CHECKPTR(VarAnd); 6229 6230 true_str = SysAllocString(szTrue); 6231 false_str = SysAllocString(szFalse); 6232 6233 /* Test all possible flag/vt combinations & the resulting vt type */ 6234 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 6235 { 6236 VARTYPE leftvt, rightvt, resvt; 6237 6238 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++) 6239 { 6240 SKIPTESTAND(leftvt); 6241 6242 /* Check if we need/have support for I8 and/or UI8 */ 6243 if ((leftvt == VT_I8 || leftvt == VT_UI8) && !has_i8) 6244 continue; 6245 6246 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++) 6247 { 6248 BOOL bFail = FALSE; 6249 SKIPTESTAND(rightvt); 6250 6251 /* Check if we need/have support for I8 and/or UI8 */ 6252 if ((rightvt == VT_I8 || rightvt == VT_UI8) && !has_i8) 6253 continue; 6254 6255 memset(&left, 0, sizeof(left)); 6256 memset(&right, 0, sizeof(right)); 6257 V_VT(&left) = leftvt | ExtraFlags[i]; 6258 V_VT(&right) = rightvt | ExtraFlags[i]; 6259 V_VT(&result) = VT_EMPTY; 6260 resvt = VT_EMPTY; 6261 if ((leftvt | ExtraFlags[i]) == VT_BSTR) 6262 V_BSTR(&left) = true_str; 6263 if ((rightvt | ExtraFlags[i]) == VT_BSTR) 6264 V_BSTR(&right) = true_str; 6265 6266 /* Native VarAnd always returns an error when using extra 6267 * flags or if the variant combination is I8 and INT. 6268 */ 6269 if ((leftvt == VT_I8 && rightvt == VT_INT) || 6270 (leftvt == VT_INT && rightvt == VT_I8) || 6271 ExtraFlags[i] != 0) 6272 bFail = TRUE; 6273 6274 /* Determine return type */ 6275 else if (leftvt == VT_I8 || rightvt == VT_I8) 6276 resvt = VT_I8; 6277 else if (leftvt == VT_I4 || rightvt == VT_I4 || 6278 leftvt == VT_UINT || rightvt == VT_UINT || 6279 leftvt == VT_INT || rightvt == VT_INT || 6280 leftvt == VT_R4 || rightvt == VT_R4 || 6281 leftvt == VT_R8 || rightvt == VT_R8 || 6282 leftvt == VT_CY || rightvt == VT_CY || 6283 leftvt == VT_DATE || rightvt == VT_DATE || 6284 leftvt == VT_I1 || rightvt == VT_I1 || 6285 leftvt == VT_UI2 || rightvt == VT_UI2 || 6286 leftvt == VT_UI4 || rightvt == VT_UI4 || 6287 leftvt == VT_UI8 || rightvt == VT_UI8 || 6288 leftvt == VT_DECIMAL || rightvt == VT_DECIMAL) 6289 resvt = VT_I4; 6290 else if (leftvt == VT_UI1 || rightvt == VT_UI1 || 6291 leftvt == VT_I2 || rightvt == VT_I2 || 6292 leftvt == VT_EMPTY || rightvt == VT_EMPTY) 6293 if ((leftvt == VT_NULL && rightvt == VT_UI1) || 6294 (leftvt == VT_UI1 && rightvt == VT_NULL) || 6295 (leftvt == VT_UI1 && rightvt == VT_UI1)) 6296 resvt = VT_UI1; 6297 else 6298 resvt = VT_I2; 6299 else if (leftvt == VT_BOOL || rightvt == VT_BOOL || 6300 (leftvt == VT_BSTR && rightvt == VT_BSTR)) 6301 resvt = VT_BOOL; 6302 else if (leftvt == VT_NULL || rightvt == VT_NULL || 6303 leftvt == VT_BSTR || rightvt == VT_BSTR) 6304 resvt = VT_NULL; 6305 else 6306 bFail = TRUE; 6307 6308 hres = pVarAnd(&left, &right, &result); 6309 6310 /* Check expected HRESULT and if result variant type is correct */ 6311 if (bFail) 6312 ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH, 6313 "VarAnd: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n", 6314 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], 6315 vtstr(V_VT(&result)), hres); 6316 else 6317 ok (hres == S_OK && resvt == V_VT(&result), 6318 "VarAnd: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n", 6319 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt), 6320 S_OK, vtstr(V_VT(&result)), hres); 6321 } 6322 } 6323 } 6324 6325 /* 6326 * Test returned values. Since we know the returned type is correct 6327 * and that we handle all combinations of invalid types, just check 6328 * that good type combinations produce the desired value. 6329 * FIXME: Test VT_DECIMAL 6330 */ 6331 VARAND(EMPTY,0,EMPTY,0,I2,0); 6332 VARAND(EMPTY,1,EMPTY,0,I2,0); 6333 VARAND(EMPTY,1,EMPTY,1,I2,0); 6334 VARAND(EMPTY,0,NULL,0,I2,0); 6335 VARAND(EMPTY,1,NULL,0,I2,0); 6336 VARAND(EMPTY,1,NULL,1,I2,0); 6337 VARAND(EMPTY,0,I1,0,I4,0); 6338 VARAND(EMPTY,0,I1,1,I4,0); 6339 VARAND(EMPTY,1,I1,1,I4,0); 6340 VARAND(EMPTY,0,UI1,0,I2,0); 6341 VARAND(EMPTY,0,UI1,1,I2,0); 6342 VARAND(EMPTY,1,UI1,1,I2,0); 6343 VARAND(EMPTY,0,I2,0,I2,0); 6344 VARAND(EMPTY,0,I2,1,I2,0); 6345 VARAND(EMPTY,1,I2,1,I2,0); 6346 VARAND(EMPTY,0,UI2,0,I4,0); 6347 VARAND(EMPTY,0,UI2,1,I4,0); 6348 VARAND(EMPTY,1,UI2,1,I4,0); 6349 VARAND(EMPTY,0,I4,0,I4,0); 6350 VARAND(EMPTY,0,I4,1,I4,0); 6351 VARAND(EMPTY,1,I4,1,I4,0); 6352 VARAND(EMPTY,0,UI4,0,I4,0); 6353 VARAND(EMPTY,0,UI4,1,I4,0); 6354 VARAND(EMPTY,1,UI4,1,I4,0); 6355 if (has_i8) 6356 { 6357 VARAND(EMPTY,0,I8,0,I8,0); 6358 VARAND(EMPTY,0,I8,1,I8,0); 6359 VARAND(EMPTY,1,I8,1,I8,0); 6360 VARAND(EMPTY,0,UI8,0,I4,0); 6361 VARAND(EMPTY,0,UI8,1,I4,0); 6362 VARAND(EMPTY,1,UI8,1,I4,0); 6363 } 6364 VARAND(EMPTY,0,INT,0,I4,0); 6365 VARAND(EMPTY,0,INT,1,I4,0); 6366 VARAND(EMPTY,1,INT,1,I4,0); 6367 VARAND(EMPTY,0,UINT,0,I4,0); 6368 VARAND(EMPTY,0,UINT,1,I4,0); 6369 VARAND(EMPTY,1,UINT,1,I4,0); 6370 VARAND(EMPTY,0,BOOL,0,I2,0); 6371 VARAND(EMPTY,0,BOOL,1,I2,0); 6372 VARAND(EMPTY,1,BOOL,1,I2,0); 6373 VARAND(EMPTY,0,R4,0,I4,0); 6374 VARAND(EMPTY,0,R4,1,I4,0); 6375 VARAND(EMPTY,1,R4,1,I4,0); 6376 VARAND(EMPTY,0,R8,0,I4,0); 6377 VARAND(EMPTY,0,R8,1,I4,0); 6378 VARAND(EMPTY,1,R8,1,I4,0); 6379 VARAND(EMPTY,0,BSTR,false_str,I2,0); 6380 VARAND(EMPTY,0,BSTR,true_str,I2,0); 6381 VARANDCY(EMPTY,0,10000,I4,0); 6382 6383 /* NULL OR 0 = NULL. NULL OR n = n */ 6384 VARAND(NULL,0,NULL,0,NULL,0); 6385 VARAND(NULL,1,NULL,0,NULL,0); 6386 VARAND(NULL,0,I1,0,I4,0); 6387 VARAND(NULL,0,I1,1,NULL,0); 6388 VARAND(NULL,0,UI1,0,UI1,0); 6389 VARAND(NULL,0,UI1,1,NULL,0); 6390 VARAND(NULL,0,I2,0,I2,0); 6391 VARAND(NULL,0,I2,1,NULL,0); 6392 VARAND(NULL,0,UI2,0,I4,0); 6393 VARAND(NULL,0,UI2,1,NULL,0); 6394 VARAND(NULL,0,I4,0,I4,0); 6395 VARAND(NULL,0,I4,1,NULL,0); 6396 VARAND(NULL,0,UI4,0,I4,0); 6397 VARAND(NULL,0,UI4,1,NULL,0); 6398 if (has_i8) 6399 { 6400 VARAND(NULL,0,I8,0,I8,0); 6401 VARAND(NULL,0,I8,1,NULL,0); 6402 VARAND(NULL,0,UI8,0,I4,0); 6403 VARAND(NULL,0,UI8,1,NULL,0); 6404 } 6405 VARAND(NULL,0,INT,0,I4,0); 6406 VARAND(NULL,0,INT,1,NULL,0); 6407 VARAND(NULL,0,UINT,0,I4,0); 6408 VARAND(NULL,0,UINT,1,NULL,0); 6409 VARAND(NULL,0,BOOL,0,BOOL,0); 6410 VARAND(NULL,0,BOOL,1,NULL,0); 6411 VARAND(NULL,0,R4,0,I4,0); 6412 VARAND(NULL,0,R4,1,NULL,0); 6413 VARAND(NULL,0,R8,0,I4,0); 6414 VARAND(NULL,0,R8,1,NULL,0); 6415 VARAND(NULL,0,BSTR,false_str,BOOL,0); 6416 VARAND(NULL,0,BSTR,true_str,NULL,VARIANT_FALSE); 6417 VARANDCY(NULL,0,10000,NULL,0); 6418 VARANDCY(NULL,0,0,I4,0); 6419 VARAND(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE); 6420 VARAND(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE); 6421 VARAND(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE); 6422 VARAND(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE); 6423 6424 /* Assume x,y & y,x are the same from now on to reduce the number of tests */ 6425 VARAND(BOOL,VARIANT_TRUE,I1,-1,I4,-1); 6426 VARAND(BOOL,VARIANT_TRUE,I1,0,I4,0); 6427 VARAND(BOOL,VARIANT_FALSE,I1,0,I4,0); 6428 VARAND(BOOL,VARIANT_TRUE,UI1,255,I2,255); 6429 VARAND(BOOL,VARIANT_TRUE,UI1,0,I2,0); 6430 VARAND(BOOL,VARIANT_FALSE,UI1,0,I2,0); 6431 VARAND(BOOL,VARIANT_TRUE,I2,-1,I2,-1); 6432 VARAND(BOOL,VARIANT_TRUE,I2,0,I2,0); 6433 VARAND(BOOL,VARIANT_FALSE,I2,0,I2,0); 6434 VARAND(BOOL,VARIANT_TRUE,UI2,65535,I4,65535); 6435 VARAND(BOOL,VARIANT_TRUE,UI2,0,I4,0); 6436 VARAND(BOOL,VARIANT_FALSE,UI2,0,I4,0); 6437 VARAND(BOOL,VARIANT_TRUE,I4,-1,I4,-1); 6438 VARAND(BOOL,VARIANT_TRUE,I4,0,I4,0); 6439 VARAND(BOOL,VARIANT_FALSE,I4,0,I4,0); 6440 VARAND(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,-1); 6441 VARAND(BOOL,VARIANT_TRUE,UI4,0,I4,0); 6442 VARAND(BOOL,VARIANT_FALSE,UI4,0,I4,0); 6443 VARAND(BOOL,VARIANT_TRUE,R4,-1,I4,-1); 6444 VARAND(BOOL,VARIANT_TRUE,R4,0,I4,0); 6445 VARAND(BOOL,VARIANT_FALSE,R4,0,I4,0); 6446 VARAND(BOOL,VARIANT_TRUE,R8,-1,I4,-1); 6447 VARAND(BOOL,VARIANT_TRUE,R8,0,I4,0); 6448 VARAND(BOOL,VARIANT_FALSE,R8,0,I4,0); 6449 VARAND(BOOL,VARIANT_TRUE,DATE,-1,I4,-1); 6450 VARAND(BOOL,VARIANT_TRUE,DATE,0,I4,0); 6451 VARAND(BOOL,VARIANT_FALSE,DATE,0,I4,0); 6452 if (has_i8) 6453 { 6454 VARAND(BOOL,VARIANT_TRUE,I8,-1,I8,-1); 6455 VARAND(BOOL,VARIANT_TRUE,I8,0,I8,0); 6456 VARAND(BOOL,VARIANT_FALSE,I8,0,I8,0); 6457 VARAND(BOOL,VARIANT_TRUE,UI8,0,I4,0); 6458 VARAND(BOOL,VARIANT_FALSE,UI8,0,I4,0); 6459 } 6460 VARAND(BOOL,VARIANT_TRUE,INT,-1,I4,-1); 6461 VARAND(BOOL,VARIANT_TRUE,INT,0,I4,0); 6462 VARAND(BOOL,VARIANT_FALSE,INT,0,I4,0); 6463 VARAND(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,-1); 6464 VARAND(BOOL,VARIANT_TRUE,UINT,0,I4,0); 6465 VARAND(BOOL,VARIANT_FALSE,UINT,0,I4,0); 6466 VARAND(BOOL,VARIANT_FALSE,BSTR,false_str,BOOL,VARIANT_FALSE); 6467 VARAND(BOOL,VARIANT_TRUE,BSTR,false_str,BOOL,VARIANT_FALSE); 6468 VARAND(BOOL,VARIANT_FALSE,BSTR,true_str,BOOL,VARIANT_FALSE); 6469 VARAND(BOOL,VARIANT_TRUE,BSTR,true_str,BOOL,VARIANT_TRUE); 6470 VARANDCY(BOOL,VARIANT_TRUE,10000,I4,1); 6471 VARANDCY(BOOL,VARIANT_TRUE,0,I4,0); 6472 VARANDCY(BOOL,VARIANT_FALSE,0,I4,0); 6473 VARAND(I1,-1,I1,-1,I4,-1); 6474 VARAND(I1,-1,I1,0,I4,0); 6475 VARAND(I1,0,I1,0,I4,0); 6476 VARAND(I1,-1,UI1,255,I4,255); 6477 VARAND(I1,-1,UI1,0,I4,0); 6478 VARAND(I1,0,UI1,0,I4,0); 6479 VARAND(I1,-1,I2,-1,I4,-1); 6480 VARAND(I1,-1,I2,0,I4,0); 6481 VARAND(I1,0,I2,0,I4,0); 6482 VARAND(I1,-1,UI2,65535,I4,65535); 6483 VARAND(I1,-1,UI2,0,I4,0); 6484 VARAND(I1,0,UI2,0,I4,0); 6485 VARAND(I1,-1,I4,-1,I4,-1); 6486 VARAND(I1,-1,I4,0,I4,0); 6487 VARAND(I1,0,I4,0,I4,0); 6488 VARAND(I1,-1,UI4,0xffffffff,I4,-1); 6489 VARAND(I1,-1,UI4,0,I4,0); 6490 VARAND(I1,0,UI4,0,I4,0); 6491 VARAND(I1,-1,R4,-1,I4,-1); 6492 VARAND(I1,-1,R4,0,I4,0); 6493 VARAND(I1,0,R4,0,I4,0); 6494 VARAND(I1,-1,R8,-1,I4,-1); 6495 VARAND(I1,-1,R8,0,I4,0); 6496 VARAND(I1,0,R8,0,I4,0); 6497 VARAND(I1,-1,DATE,-1,I4,-1); 6498 VARAND(I1,-1,DATE,0,I4,0); 6499 VARAND(I1,0,DATE,0,I4,0); 6500 if (has_i8) 6501 { 6502 VARAND(I1,-1,I8,-1,I8,-1); 6503 VARAND(I1,-1,I8,0,I8,0); 6504 VARAND(I1,0,I8,0,I8,0); 6505 VARAND(I1,-1,UI8,0,I4,0); 6506 VARAND(I1,0,UI8,0,I4,0); 6507 } 6508 VARAND(I1,-1,INT,-1,I4,-1); 6509 VARAND(I1,-1,INT,0,I4,0); 6510 VARAND(I1,0,INT,0,I4,0); 6511 VARAND(I1,-1,UINT,0xffffffff,I4,-1); 6512 VARAND(I1,-1,UINT,0,I4,0); 6513 VARAND(I1,0,UINT,0,I4,0); 6514 VARAND(I1,0,BSTR,false_str,I4,0); 6515 VARAND(I1,-1,BSTR,false_str,I4,0); 6516 VARAND(I1,0,BSTR,true_str,I4,0); 6517 VARAND(I1,-1,BSTR,true_str,I4,-1); 6518 VARANDCY(I1,-1,10000,I4,1); 6519 VARANDCY(I1,-1,0,I4,0); 6520 VARANDCY(I1,0,0,I4,0); 6521 6522 VARAND(UI1,255,UI1,255,UI1,255); 6523 VARAND(UI1,255,UI1,0,UI1,0); 6524 VARAND(UI1,0,UI1,0,UI1,0); 6525 VARAND(UI1,255,I2,-1,I2,255); 6526 VARAND(UI1,255,I2,0,I2,0); 6527 VARAND(UI1,0,I2,0,I2,0); 6528 VARAND(UI1,255,UI2,65535,I4,255); 6529 VARAND(UI1,255,UI2,0,I4,0); 6530 VARAND(UI1,0,UI2,0,I4,0); 6531 VARAND(UI1,255,I4,-1,I4,255); 6532 VARAND(UI1,255,I4,0,I4,0); 6533 VARAND(UI1,0,I4,0,I4,0); 6534 VARAND(UI1,255,UI4,0xffffffff,I4,255); 6535 VARAND(UI1,255,UI4,0,I4,0); 6536 VARAND(UI1,0,UI4,0,I4,0); 6537 VARAND(UI1,255,R4,-1,I4,255); 6538 VARAND(UI1,255,R4,0,I4,0); 6539 VARAND(UI1,0,R4,0,I4,0); 6540 VARAND(UI1,255,R8,-1,I4,255); 6541 VARAND(UI1,255,R8,0,I4,0); 6542 VARAND(UI1,0,R8,0,I4,0); 6543 VARAND(UI1,255,DATE,-1,I4,255); 6544 VARAND(UI1,255,DATE,0,I4,0); 6545 VARAND(UI1,0,DATE,0,I4,0); 6546 if (has_i8) 6547 { 6548 VARAND(UI1,255,I8,-1,I8,255); 6549 VARAND(UI1,255,I8,0,I8,0); 6550 VARAND(UI1,0,I8,0,I8,0); 6551 VARAND(UI1,255,UI8,0,I4,0); 6552 VARAND(UI1,0,UI8,0,I4,0); 6553 } 6554 VARAND(UI1,255,INT,-1,I4,255); 6555 VARAND(UI1,255,INT,0,I4,0); 6556 VARAND(UI1,0,INT,0,I4,0); 6557 VARAND(UI1,255,UINT,0xffffffff,I4,255); 6558 VARAND(UI1,255,UINT,0,I4,0); 6559 VARAND(UI1,0,UINT,0,I4,0); 6560 VARAND(UI1,0,BSTR,false_str,I2,0); 6561 VARAND(UI1,255,BSTR,false_str,I2,0); 6562 VARAND(UI1,0,BSTR,true_str,I2,0); 6563 VARAND(UI1,255,BSTR,true_str,I2,255); 6564 VARANDCY(UI1,255,10000,I4,1); 6565 VARANDCY(UI1,255,0,I4,0); 6566 VARANDCY(UI1,0,0,I4,0); 6567 6568 VARAND(I2,-1,I2,-1,I2,-1); 6569 VARAND(I2,-1,I2,0,I2,0); 6570 VARAND(I2,0,I2,0,I2,0); 6571 VARAND(I2,-1,UI2,65535,I4,65535); 6572 VARAND(I2,-1,UI2,0,I4,0); 6573 VARAND(I2,0,UI2,0,I4,0); 6574 VARAND(I2,-1,I4,-1,I4,-1); 6575 VARAND(I2,-1,I4,0,I4,0); 6576 VARAND(I2,0,I4,0,I4,0); 6577 VARAND(I2,-1,UI4,0xffffffff,I4,-1); 6578 VARAND(I2,-1,UI4,0,I4,0); 6579 VARAND(I2,0,UI4,0,I4,0); 6580 VARAND(I2,-1,R4,-1,I4,-1); 6581 VARAND(I2,-1,R4,0,I4,0); 6582 VARAND(I2,0,R4,0,I4,0); 6583 VARAND(I2,-1,R8,-1,I4,-1); 6584 VARAND(I2,-1,R8,0,I4,0); 6585 VARAND(I2,0,R8,0,I4,0); 6586 VARAND(I2,-1,DATE,-1,I4,-1); 6587 VARAND(I2,-1,DATE,0,I4,0); 6588 VARAND(I2,0,DATE,0,I4,0); 6589 if (has_i8) 6590 { 6591 VARAND(I2,-1,I8,-1,I8,-1); 6592 VARAND(I2,-1,I8,0,I8,0); 6593 VARAND(I2,0,I8,0,I8,0); 6594 VARAND(I2,-1,UI8,0,I4,0); 6595 VARAND(I2,0,UI8,0,I4,0); 6596 } 6597 VARAND(I2,-1,INT,-1,I4,-1); 6598 VARAND(I2,-1,INT,0,I4,0); 6599 VARAND(I2,0,INT,0,I4,0); 6600 VARAND(I2,-1,UINT,0xffffffff,I4,-1); 6601 VARAND(I2,-1,UINT,0,I4,0); 6602 VARAND(I2,0,UINT,0,I4,0); 6603 VARAND(I2,0,BSTR,false_str,I2,0); 6604 VARAND(I2,-1,BSTR,false_str,I2,0); 6605 VARAND(I2,0,BSTR,true_str,I2,0); 6606 VARAND(I2,-1,BSTR,true_str,I2,-1); 6607 VARANDCY(I2,-1,10000,I4,1); 6608 VARANDCY(I2,-1,0,I4,0); 6609 VARANDCY(I2,0,0,I4,0); 6610 6611 VARAND(UI2,65535,UI2,65535,I4,65535); 6612 VARAND(UI2,65535,UI2,0,I4,0); 6613 VARAND(UI2,0,UI2,0,I4,0); 6614 VARAND(UI2,65535,I4,-1,I4,65535); 6615 VARAND(UI2,65535,I4,0,I4,0); 6616 VARAND(UI2,0,I4,0,I4,0); 6617 VARAND(UI2,65535,UI4,0xffffffff,I4,65535); 6618 VARAND(UI2,65535,UI4,0,I4,0); 6619 VARAND(UI2,0,UI4,0,I4,0); 6620 VARAND(UI2,65535,R4,-1,I4,65535); 6621 VARAND(UI2,65535,R4,0,I4,0); 6622 VARAND(UI2,0,R4,0,I4,0); 6623 VARAND(UI2,65535,R8,-1,I4,65535); 6624 VARAND(UI2,65535,R8,0,I4,0); 6625 VARAND(UI2,0,R8,0,I4,0); 6626 VARAND(UI2,65535,DATE,-1,I4,65535); 6627 VARAND(UI2,65535,DATE,0,I4,0); 6628 VARAND(UI2,0,DATE,0,I4,0); 6629 if (has_i8) 6630 { 6631 VARAND(UI2,65535,I8,-1,I8,65535); 6632 VARAND(UI2,65535,I8,0,I8,0); 6633 VARAND(UI2,0,I8,0,I8,0); 6634 VARAND(UI2,65535,UI8,0,I4,0); 6635 VARAND(UI2,0,UI8,0,I4,0); 6636 } 6637 VARAND(UI2,65535,INT,-1,I4,65535); 6638 VARAND(UI2,65535,INT,0,I4,0); 6639 VARAND(UI2,0,INT,0,I4,0); 6640 VARAND(UI2,65535,UINT,0xffffffff,I4,65535); 6641 VARAND(UI2,65535,UINT,0,I4,0); 6642 VARAND(UI2,0,UINT,0,I4,0); 6643 VARAND(UI2,0,BSTR,false_str,I4,0); 6644 VARAND(UI2,65535,BSTR,false_str,I4,0); 6645 VARAND(UI2,0,BSTR,true_str,I4,0); 6646 VARAND(UI2,65535,BSTR,true_str,I4,65535); 6647 VARANDCY(UI2,65535,10000,I4,1); 6648 VARANDCY(UI2,65535,0,I4,0); 6649 VARANDCY(UI2,0,0,I4,0); 6650 6651 VARAND(I4,-1,I4,-1,I4,-1); 6652 VARAND(I4,-1,I4,0,I4,0); 6653 VARAND(I4,0,I4,0,I4,0); 6654 VARAND(I4,-1,UI4,0xffffffff,I4,-1); 6655 VARAND(I4,-1,UI4,0,I4,0); 6656 VARAND(I4,0,UI4,0,I4,0); 6657 VARAND(I4,-1,R4,-1,I4,-1); 6658 VARAND(I4,-1,R4,0,I4,0); 6659 VARAND(I4,0,R4,0,I4,0); 6660 VARAND(I4,-1,R8,-1,I4,-1); 6661 VARAND(I4,-1,R8,0,I4,0); 6662 VARAND(I4,0,R8,0,I4,0); 6663 VARAND(I4,-1,DATE,-1,I4,-1); 6664 VARAND(I4,-1,DATE,0,I4,0); 6665 VARAND(I4,0,DATE,0,I4,0); 6666 if (has_i8) 6667 { 6668 VARAND(I4,-1,I8,-1,I8,-1); 6669 VARAND(I4,-1,I8,0,I8,0); 6670 VARAND(I4,0,I8,0,I8,0); 6671 VARAND(I4,-1,UI8,0,I4,0); 6672 VARAND(I4,0,UI8,0,I4,0); 6673 } 6674 VARAND(I4,-1,INT,-1,I4,-1); 6675 VARAND(I4,-1,INT,0,I4,0); 6676 VARAND(I4,0,INT,0,I4,0); 6677 VARAND(I4,-1,UINT,0xffffffff,I4,-1); 6678 VARAND(I4,-1,UINT,0,I4,0); 6679 VARAND(I4,0,UINT,0,I4,0); 6680 VARAND(I4,0,BSTR,false_str,I4,0); 6681 VARAND(I4,-1,BSTR,false_str,I4,0); 6682 VARAND(I4,0,BSTR,true_str,I4,0); 6683 VARAND(I4,-1,BSTR,true_str,I4,-1); 6684 VARANDCY(I4,-1,10000,I4,1); 6685 VARANDCY(I4,-1,0,I4,0); 6686 VARANDCY(I4,0,0,I4,0); 6687 6688 VARAND(UI4,0xffffffff,UI4,0xffffffff,I4,-1); 6689 VARAND(UI4,0xffffffff,UI4,0,I4,0); 6690 VARAND(UI4,0,UI4,0,I4,0); 6691 VARAND(UI4,0xffffffff,R4,-1,I4,-1); 6692 VARAND(UI4,0xffffffff,R4,0,I4,0); 6693 VARAND(UI4,0,R4,0,I4,0); 6694 VARAND(UI4,0xffffffff,R8,-1,I4,-1); 6695 VARAND(UI4,0xffffffff,R8,0,I4,0); 6696 VARAND(UI4,0,R8,0,I4,0); 6697 VARAND(UI4,0xffffffff,DATE,-1,I4,-1); 6698 VARAND(UI4,0xffffffff,DATE,0,I4,0); 6699 VARAND(UI4,0,DATE,0,I4,0); 6700 if (has_i8) 6701 { 6702 VARAND(UI4,0xffffffff,I8,0,I8,0); 6703 VARAND(UI4,0,I8,0,I8,0); 6704 VARAND(UI4,0xffffffff,UI8,0,I4,0); 6705 VARAND(UI4,0,UI8,0,I4,0); 6706 } 6707 VARAND(UI4,0xffffffff,INT,-1,I4,-1); 6708 VARAND(UI4,0xffffffff,INT,0,I4,0); 6709 VARAND(UI4,0,INT,0,I4,0); 6710 VARAND(UI4,0xffffffff,UINT,0xffffffff,I4,-1); 6711 VARAND(UI4,0xffffffff,UINT,0,I4,0); 6712 VARAND(UI4,0,UINT,0,I4,0); 6713 VARAND(UI4,0,BSTR,false_str,I4,0); 6714 VARAND(UI4,0xffffffff,BSTR,false_str,I4,0); 6715 VARAND(UI4,0,BSTR,true_str,I4,0); 6716 VARAND(UI4,0xffffffff,BSTR,true_str,I4,-1); 6717 VARANDCY(UI4,0xffffffff,10000,I4,1); 6718 VARANDCY(UI4,0xffffffff,0,I4,0); 6719 VARANDCY(UI4,0,0,I4,0); 6720 6721 VARAND(R4,-1,R4,-1,I4,-1); 6722 VARAND(R4,-1,R4,0,I4,0); 6723 VARAND(R4,0,R4,0,I4,0); 6724 VARAND(R4,-1,R8,-1,I4,-1); 6725 VARAND(R4,-1,R8,0,I4,0); 6726 VARAND(R4,0,R8,0,I4,0); 6727 VARAND(R4,-1,DATE,-1,I4,-1); 6728 VARAND(R4,-1,DATE,0,I4,0); 6729 VARAND(R4,0,DATE,0,I4,0); 6730 if (has_i8) 6731 { 6732 VARAND(R4,-1,I8,-1,I8,-1); 6733 VARAND(R4,-1,I8,0,I8,0); 6734 VARAND(R4,0,I8,0,I8,0); 6735 VARAND(R4,-1,UI8,0,I4,0); 6736 VARAND(R4,0,UI8,0,I4,0); 6737 } 6738 VARAND(R4,-1,INT,-1,I4,-1); 6739 VARAND(R4,-1,INT,0,I4,0); 6740 VARAND(R4,0,INT,0,I4,0); 6741 VARAND(R4,-1,UINT,0xffffffff,I4,-1); 6742 VARAND(R4,-1,UINT,0,I4,0); 6743 VARAND(R4,0,UINT,0,I4,0); 6744 VARAND(R4,0,BSTR,false_str,I4,0); 6745 VARAND(R4,-1,BSTR,false_str,I4,0); 6746 VARAND(R4,0,BSTR,true_str,I4,0); 6747 VARAND(R4,-1,BSTR,true_str,I4,-1); 6748 VARANDCY(R4,-1,10000,I4,1); 6749 VARANDCY(R4,-1,0,I4,0); 6750 VARANDCY(R4,0,0,I4,0); 6751 6752 VARAND(R8,-1,R8,-1,I4,-1); 6753 VARAND(R8,-1,R8,0,I4,0); 6754 VARAND(R8,0,R8,0,I4,0); 6755 VARAND(R8,-1,DATE,-1,I4,-1); 6756 VARAND(R8,-1,DATE,0,I4,0); 6757 VARAND(R8,0,DATE,0,I4,0); 6758 if (has_i8) 6759 { 6760 VARAND(R8,-1,I8,-1,I8,-1); 6761 VARAND(R8,-1,I8,0,I8,0); 6762 VARAND(R8,0,I8,0,I8,0); 6763 VARAND(R8,-1,UI8,0,I4,0); 6764 VARAND(R8,0,UI8,0,I4,0); 6765 } 6766 VARAND(R8,-1,INT,-1,I4,-1); 6767 VARAND(R8,-1,INT,0,I4,0); 6768 VARAND(R8,0,INT,0,I4,0); 6769 VARAND(R8,-1,UINT,0xffffffff,I4,-1); 6770 VARAND(R8,-1,UINT,0,I4,0); 6771 VARAND(R8,0,UINT,0,I4,0); 6772 VARAND(R8,0,BSTR,false_str,I4,0); 6773 VARAND(R8,-1,BSTR,false_str,I4,0); 6774 VARAND(R8,0,BSTR,true_str,I4,0); 6775 VARAND(R8,-1,BSTR,true_str,I4,-1); 6776 VARANDCY(R8,-1,10000,I4,1); 6777 VARANDCY(R8,-1,0,I4,0); 6778 VARANDCY(R8,0,0,I4,0); 6779 6780 VARAND(DATE,-1,DATE,-1,I4,-1); 6781 VARAND(DATE,-1,DATE,0,I4,0); 6782 VARAND(DATE,0,DATE,0,I4,0); 6783 if (has_i8) 6784 { 6785 VARAND(DATE,-1,I8,-1,I8,-1); 6786 VARAND(DATE,-1,I8,0,I8,0); 6787 VARAND(DATE,0,I8,0,I8,0); 6788 VARAND(DATE,-1,UI8,0,I4,0); 6789 VARAND(DATE,0,UI8,0,I4,0); 6790 } 6791 VARAND(DATE,-1,INT,-1,I4,-1); 6792 VARAND(DATE,-1,INT,0,I4,0); 6793 VARAND(DATE,0,INT,0,I4,0); 6794 VARAND(DATE,-1,UINT,0xffffffff,I4,-1); 6795 VARAND(DATE,-1,UINT,0,I4,0); 6796 VARAND(DATE,0,UINT,0,I4,0); 6797 VARAND(DATE,0,BSTR,false_str,I4,0); 6798 VARAND(DATE,-1,BSTR,false_str,I4,0); 6799 VARAND(DATE,0,BSTR,true_str,I4,0); 6800 VARAND(DATE,-1,BSTR,true_str,I4,-1); 6801 VARANDCY(DATE,-1,10000,I4,1); 6802 VARANDCY(DATE,-1,0,I4,0); 6803 VARANDCY(DATE,0,0,I4,0); 6804 6805 if (has_i8) 6806 { 6807 VARAND(I8,-1,I8,-1,I8,-1); 6808 VARAND(I8,-1,I8,0,I8,0); 6809 VARAND(I8,0,I8,0,I8,0); 6810 VARAND(I8,-1,UI8,0,I8,0); 6811 VARAND(I8,0,UI8,0,I8,0); 6812 VARAND(I8,-1,UINT,0,I8,0); 6813 VARAND(I8,0,UINT,0,I8,0); 6814 VARAND(I8,0,BSTR,false_str,I8,0); 6815 VARAND(I8,-1,BSTR,false_str,I8,0); 6816 VARAND(I8,0,BSTR,true_str,I8,0); 6817 VARAND(I8,-1,BSTR,true_str,I8,-1); 6818 VARANDCY(I8,-1,10000,I8,1); 6819 VARANDCY(I8,-1,0,I8,0); 6820 VARANDCY(I8,0,0,I8,0); 6821 6822 VARAND(UI8,0xffff,UI8,0xffff,I4,0xffff); 6823 VARAND(UI8,0xffff,UI8,0,I4,0); 6824 VARAND(UI8,0,UI8,0,I4,0); 6825 VARAND(UI8,0xffff,INT,-1,I4,65535); 6826 VARAND(UI8,0xffff,INT,0,I4,0); 6827 VARAND(UI8,0,INT,0,I4,0); 6828 VARAND(UI8,0xffff,UINT,0xffff,I4,0xffff); 6829 VARAND(UI8,0xffff,UINT,0,I4,0); 6830 VARAND(UI8,0,UINT,0,I4,0); 6831 VARAND(UI8,0,BSTR,false_str,I4,0); 6832 VARAND(UI8,0xffff,BSTR,false_str,I4,0); 6833 VARAND(UI8,0,BSTR,true_str,I4,0); 6834 VARAND(UI8,0xffff,BSTR,true_str,I4,65535); 6835 VARANDCY(UI8,0xffff,10000,I4,1); 6836 VARANDCY(UI8,0xffff,0,I4,0); 6837 VARANDCY(UI8,0,0,I4,0); 6838 } 6839 6840 VARAND(INT,-1,INT,-1,I4,-1); 6841 VARAND(INT,-1,INT,0,I4,0); 6842 VARAND(INT,0,INT,0,I4,0); 6843 VARAND(INT,-1,UINT,0xffff,I4,65535); 6844 VARAND(INT,-1,UINT,0,I4,0); 6845 VARAND(INT,0,UINT,0,I4,0); 6846 VARAND(INT,0,BSTR,false_str,I4,0); 6847 VARAND(INT,-1,BSTR,false_str,I4,0); 6848 VARAND(INT,0,BSTR,true_str,I4,0); 6849 VARAND(INT,-1,BSTR,true_str,I4,-1); 6850 VARANDCY(INT,-1,10000,I4,1); 6851 VARANDCY(INT,-1,0,I4,0); 6852 VARANDCY(INT,0,0,I4,0); 6853 6854 VARAND(UINT,0xffff,UINT,0xffff,I4,0xffff); 6855 VARAND(UINT,0xffff,UINT,0,I4,0); 6856 VARAND(UINT,0,UINT,0,I4,0); 6857 VARAND(UINT,0,BSTR,false_str,I4,0); 6858 VARAND(UINT,0xffff,BSTR, false_str,I4,0); 6859 VARAND(UINT,0,BSTR,true_str,I4,0); 6860 VARAND(UINT,0xffff,BSTR,true_str,I4,65535); 6861 VARANDCY(UINT,0xffff,10000,I4,1); 6862 VARANDCY(UINT,0xffff,0,I4,0); 6863 VARANDCY(UINT,0,0,I4,0); 6864 6865 VARAND(BSTR,false_str,BSTR,false_str,BOOL,0); 6866 VARAND(BSTR,true_str,BSTR,false_str,BOOL,VARIANT_FALSE); 6867 VARAND(BSTR,true_str,BSTR,true_str,BOOL,VARIANT_TRUE); 6868 VARANDCY(BSTR,true_str,10000,I4,1); 6869 VARANDCY(BSTR,false_str,10000,I4,0); 6870 6871 SysFreeString(true_str); 6872 SysFreeString(false_str); 6873 } 6874 6875 static void test_cmp( int line, LCID lcid, UINT flags, VARIANT *left, VARIANT *right, HRESULT result ) 6876 { 6877 HRESULT hres; 6878 6879 CHECKPTR(VarCmp); 6880 6881 hres = pVarCmp(left,right,lcid,flags); 6882 ok_(__FILE__,line)(hres == result, "VarCmp(%s,%s): expected 0x%x, got hres=0x%x\n", 6883 variantstr(left), variantstr(right), result, hres ); 6884 } 6885 static void test_cmpex( int line, LCID lcid, VARIANT *left, VARIANT *right, 6886 HRESULT res1, HRESULT res2, HRESULT res3, HRESULT res4 ) 6887 { 6888 test_cmp( line, lcid, 0, left, right, res1 ); 6889 V_VT(left) |= VT_RESERVED; 6890 test_cmp( line, lcid, 0, left, right, res2 ); 6891 V_VT(left) &= ~VT_RESERVED; 6892 V_VT(right) |= VT_RESERVED; 6893 test_cmp( line, lcid, 0, left, right, res3 ); 6894 V_VT(left) |= VT_RESERVED; 6895 test_cmp( line, lcid, 0, left, right, res4 ); 6896 ok_(__FILE__,line)(V_VT(left) & V_VT(right) & VT_RESERVED, "VT_RESERVED filtered out\n"); 6897 } 6898 6899 /* ERROR from wingdi.h is interfering here */ 6900 #undef ERROR 6901 #define _VARCMP(vt1,val1,vtfl1,vt2,val2,vtfl2,lcid,flags,result) \ 6902 V_##vt1(&left) = val1; V_VT(&left) = VT_##vt1 | vtfl1; \ 6903 V_##vt2(&right) = val2; V_VT(&right) = VT_##vt2 | vtfl2; \ 6904 test_cmp( __LINE__, lcid, flags, &left, &right, result ) 6905 #define VARCMPEX(vt1,val1,vt2,val2,res1,res2,res3,res4) \ 6906 V_##vt1(&left) = val1; V_VT(&left) = VT_##vt1; \ 6907 V_##vt2(&right) = val2; V_VT(&right) = VT_##vt2; \ 6908 test_cmpex( __LINE__, lcid, &left, &right, res1, res2, res3, res4 ) 6909 #define VARCMP(vt1,val1,vt2,val2,result) \ 6910 VARCMPEX(vt1,val1,vt2,val2,result,result,result,result) 6911 /* The above macros do not work for VT_NULL as NULL gets expanded first */ 6912 #define V_NULL_ V_NULL 6913 #define VT_NULL_ VT_NULL 6914 6915 static void test_VarCmp(void) 6916 { 6917 VARIANT left, right; 6918 VARTYPE i; 6919 LCID lcid; 6920 HRESULT hres; 6921 DECIMAL dec; 6922 static const WCHAR szhuh[] = {'h','u','h','?','\0'}; 6923 static const WCHAR sz2cents[] = {'2','c','e','n','t','s','\0'}; 6924 static const WCHAR szempty[] = {'\0'}; 6925 static const WCHAR sz0[] = {'0','\0'}; 6926 static const WCHAR sz1[] = {'1','\0'}; 6927 static const WCHAR sz7[] = {'7','\0'}; 6928 static const WCHAR sz42[] = {'4','2','\0'}; 6929 static const WCHAR sz1neg[] = {'-','1','\0'}; 6930 static const WCHAR sz666neg[] = {'-','6','6','6','\0'}; 6931 static const WCHAR sz1few[] = {'1','.','0','0','0','0','0','0','0','1','\0'}; 6932 BSTR bstrhuh, bstrempty, bstr0, bstr1, bstr7, bstr42, bstr1neg, bstr666neg; 6933 BSTR bstr2cents, bstr1few; 6934 6935 CHECKPTR(VarCmp); 6936 6937 lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT); 6938 bstrempty = SysAllocString(szempty); 6939 bstrhuh = SysAllocString(szhuh); 6940 bstr2cents = SysAllocString(sz2cents); 6941 bstr0 = SysAllocString(sz0); 6942 bstr1 = SysAllocString(sz1); 6943 bstr7 = SysAllocString(sz7); 6944 bstr42 = SysAllocString(sz42); 6945 bstr1neg = SysAllocString(sz1neg); 6946 bstr666neg = SysAllocString(sz666neg); 6947 bstr1few = SysAllocString(sz1few); 6948 6949 /* Test all possible flag/vt combinations & the resulting vt type */ 6950 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 6951 { 6952 VARTYPE leftvt, rightvt; 6953 6954 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++) 6955 { 6956 6957 SKIPTESTS(leftvt); 6958 6959 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++) 6960 { 6961 BOOL bFail = FALSE; 6962 HRESULT expect = VARCMP_EQ; 6963 6964 SKIPTESTS(rightvt); 6965 6966 memset(&left, 0, sizeof(left)); 6967 memset(&right, 0, sizeof(right)); 6968 V_VT(&left) = leftvt | ExtraFlags[i]; 6969 if (leftvt == VT_BSTR) { 6970 V_BSTR(&left) = bstr1neg; 6971 if (ExtraFlags[i] & VT_RESERVED) 6972 expect = VARCMP_LT; 6973 else 6974 expect = VARCMP_GT; 6975 } 6976 V_VT(&right) = rightvt | ExtraFlags[i]; 6977 if (rightvt == VT_BSTR) { 6978 V_BSTR(&right) = bstr1neg; 6979 if (ExtraFlags[i] & VT_RESERVED) 6980 expect = VARCMP_GT; 6981 else 6982 expect = VARCMP_LT; 6983 } 6984 6985 /* Don't ask me why but native VarCmp cannot handle: 6986 VT_I1, VT_UI2, VT_UI4, VT_UINT and VT_UI8. 6987 VT_INT is only supported as left variant. Go figure. 6988 Tested with DCOM98, Win2k, WinXP */ 6989 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF || 6990 !IsValidVariantClearVT(leftvt, ExtraFlags[i] & ~VT_RESERVED) || 6991 !IsValidVariantClearVT(rightvt, ExtraFlags[i] & ~VT_RESERVED) || 6992 leftvt == VT_CLSID || rightvt == VT_CLSID || 6993 leftvt == VT_DISPATCH || rightvt == VT_DISPATCH || 6994 leftvt == VT_ERROR || rightvt == VT_ERROR || 6995 leftvt == VT_RECORD || rightvt == VT_RECORD || 6996 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN || 6997 leftvt == VT_VARIANT || rightvt == VT_VARIANT || 6998 leftvt == VT_I1 || rightvt == VT_I1 || 6999 leftvt == VT_UI2 || rightvt == VT_UI2 || 7000 leftvt == VT_UI4 || rightvt == VT_UI4 || 7001 leftvt == VT_UI8 || rightvt == VT_UI8 || 7002 rightvt == VT_INT || 7003 leftvt == VT_UINT || rightvt == VT_UINT) { 7004 bFail = TRUE; 7005 } 7006 7007 if (leftvt == VT_ERROR && rightvt == VT_ERROR && 7008 !(ExtraFlags[i] & ~VT_RESERVED)) { 7009 expect = VARCMP_EQ; 7010 bFail = FALSE; 7011 } else if (leftvt == VT_NULL || rightvt == VT_NULL) 7012 expect = VARCMP_NULL; 7013 else if (leftvt == VT_BSTR && rightvt == VT_BSTR) 7014 expect = VARCMP_EQ; 7015 else if (leftvt == VT_BSTR && rightvt == VT_EMPTY) 7016 expect = VARCMP_GT; 7017 else if (leftvt == VT_EMPTY && rightvt == VT_BSTR) 7018 expect = VARCMP_LT; 7019 7020 hres = pVarCmp(&left, &right, LOCALE_USER_DEFAULT, 0); 7021 if (bFail) { 7022 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE, 7023 "VarCmp: %d|0x%X, %d|0x%X: Expected failure, got 0x%X\n", 7024 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres); 7025 } else { 7026 ok(hres == expect, 7027 "VarCmp: %d|0x%X, %d|0x%X: Expected 0x%X, got 0x%X\n", 7028 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], expect, 7029 hres); 7030 } 7031 } 7032 } 7033 } 7034 7035 /* VARCMP{,EX} run each 4 tests with a permutation of all possible 7036 input variants with (1) and without (0) VT_RESERVED set. The order 7037 of the permutations is (0,0); (1,0); (0,1); (1,1) */ 7038 VARCMP(INT,4711,I2,4711,VARCMP_EQ); 7039 VARCMP(INT,4711,I2,-4711,VARCMP_GT); 7040 VARCMP(ERROR,0,ERROR,0,VARCMP_EQ); 7041 VARCMP(ERROR,0,UI1,0,DISP_E_TYPEMISMATCH); 7042 VARCMP(EMPTY,0,EMPTY,0,VARCMP_EQ); 7043 VARCMP(I4,1,R8,1.0,VARCMP_EQ); 7044 VARCMP(EMPTY,19,I2,0,VARCMP_EQ); 7045 ok(V_EMPTY(&left) == 19, "VT_EMPTY modified!\n"); 7046 VARCMP(I4,1,UI1,1,VARCMP_EQ); 7047 VARCMP(I2,2,I2,2,VARCMP_EQ); 7048 VARCMP(I2,1,I2,2,VARCMP_LT); 7049 VARCMP(I2,2,I2,1,VARCMP_GT); 7050 VARCMP(I2,2,EMPTY,1,VARCMP_GT); 7051 VARCMP(I2,2,NULL_,1,VARCMP_NULL); 7052 7053 /* BSTR handling, especially in conjunction with VT_RESERVED */ 7054 VARCMP(BSTR,bstr0,NULL_,0,VARCMP_NULL); 7055 VARCMP(BSTR,bstr0,BSTR,bstr0,VARCMP_EQ); 7056 VARCMP(BSTR,bstrempty,BSTR,bstr0,VARCMP_LT); 7057 VARCMP(BSTR,bstr7,BSTR,bstr0,VARCMP_GT); 7058 VARCMP(BSTR,bstr7,BSTR,bstr1neg,VARCMP_GT); 7059 VARCMP(BSTR,bstr0,BSTR,NULL,VARCMP_GT); 7060 VARCMP(BSTR,NULL,BSTR,NULL,VARCMP_EQ); 7061 VARCMP(BSTR,bstrempty,BSTR,NULL,VARCMP_EQ); 7062 VARCMP(BSTR,NULL,EMPTY,0,VARCMP_EQ); 7063 VARCMP(EMPTY,0,BSTR,NULL,VARCMP_EQ); 7064 VARCMP(EMPTY,0,BSTR,bstrempty,VARCMP_EQ); 7065 VARCMP(EMPTY,1,BSTR,bstrempty,VARCMP_EQ); 7066 VARCMP(BSTR,bstr0,EMPTY,0,VARCMP_GT); 7067 VARCMP(BSTR,bstr42,EMPTY,0,VARCMP_GT); 7068 VARCMPEX(BSTR,bstrempty,UI1,0,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT); 7069 VARCMPEX(BSTR,bstrempty,I2,-1,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT); 7070 VARCMPEX(I4,0,BSTR,bstrempty,VARCMP_LT,VARCMP_LT,VARCMP_GT,VARCMP_LT); 7071 VARCMPEX(BSTR,NULL,UI1,0,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT); 7072 VARCMPEX(I4,7,BSTR,NULL,VARCMP_LT,VARCMP_LT,VARCMP_GT,VARCMP_LT); 7073 _VARCMP(BSTR,(BSTR)100,0,I2,100,0,lcid,0,VARCMP_GT); 7074 VARCMPEX(BSTR,bstr0,UI1,0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT); 7075 VARCMPEX(I2,0,BSTR,bstr0,VARCMP_LT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT); 7076 VARCMP(BSTR,bstrhuh,I4,I4_MAX,VARCMP_GT); 7077 VARCMP(BSTR,bstr2cents,I4,2,VARCMP_GT); 7078 VARCMPEX(BSTR,bstr2cents,I4,42,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT); 7079 VARCMP(BSTR,bstr2cents,I4,-1,VARCMP_GT); 7080 VARCMPEX(BSTR,bstr2cents,I4,-666,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT); 7081 VARCMPEX(BSTR,bstr0,I2,0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT); 7082 VARCMPEX(BSTR,bstr0,I4,0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT); 7083 VARCMPEX(BSTR,bstr0,I4,-666,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT); 7084 VARCMP(BSTR,bstr1,I4,0,VARCMP_GT); 7085 VARCMPEX(BSTR,bstr1,I4,1,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT); 7086 VARCMPEX(BSTR,bstr1,I4,I4_MAX,VARCMP_GT,VARCMP_LT,VARCMP_LT,VARCMP_GT); 7087 VARCMPEX(BSTR,bstr1,I4,-1,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT); 7088 VARCMP(BSTR,bstr7,I4,1,VARCMP_GT); 7089 VARCMPEX(BSTR,bstr7,I4,7,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT); 7090 VARCMPEX(BSTR,bstr7,I4,42,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_GT); 7091 VARCMPEX(BSTR,bstr42,I4,7,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_GT); 7092 VARCMPEX(BSTR,bstr42,I4,42,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT); 7093 VARCMPEX(BSTR,bstr42,I4,I4_MAX,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_GT); 7094 VARCMPEX(BSTR,bstr1neg,I4,1,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT); 7095 VARCMPEX(BSTR,bstr1neg,I4,42,VARCMP_GT,VARCMP_LT,VARCMP_LT,VARCMP_LT); 7096 VARCMPEX(BSTR,bstr1neg,I4,-1,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT); 7097 VARCMPEX(BSTR,bstr1neg,I4,-666,VARCMP_GT,VARCMP_LT,VARCMP_GT,VARCMP_LT); 7098 VARCMPEX(BSTR,bstr666neg,I4,1,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT); 7099 VARCMPEX(BSTR,bstr666neg,I4,7,VARCMP_GT,VARCMP_LT,VARCMP_LT,VARCMP_LT); 7100 VARCMPEX(BSTR,bstr666neg,I4,42,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT); 7101 VARCMPEX(BSTR,bstr666neg,I4,I4_MAX,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT); 7102 VARCMPEX(BSTR,bstr666neg,I4,-1,VARCMP_GT,VARCMP_GT,VARCMP_LT,VARCMP_LT); 7103 VARCMPEX(BSTR,bstr666neg,I4,-666,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT); 7104 VARCMPEX(BSTR,bstr7,R8,7.0,VARCMP_GT,VARCMP_EQ,VARCMP_EQ,VARCMP_GT); 7105 VARCMPEX(R8,3.141592,BSTR,NULL,VARCMP_LT,VARCMP_LT,VARCMP_GT,VARCMP_LT); 7106 VARCMP(BSTR,bstr7,BSTR,bstr7,VARCMP_EQ); 7107 VARCMP(BSTR,bstr7,BSTR,bstr42,VARCMP_GT); 7108 VARCMP(BSTR,bstr42,BSTR,bstr7,VARCMP_LT); 7109 7110 /* DECIMAL handling */ 7111 setdec(&dec,0,0,0,0); 7112 VARCMPEX(DECIMAL,dec,BSTR,bstr0,VARCMP_LT,VARCMP_EQ,VARCMP_EQ,VARCMP_LT); 7113 setdec64(&dec,0,0,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF); /* max DECIMAL */ 7114 VARCMP(DECIMAL,dec,R8,R8_MAX,VARCMP_LT); /* R8 has bigger range */ 7115 VARCMP(DECIMAL,dec,DATE,R8_MAX,VARCMP_LT); /* DATE has bigger range */ 7116 setdec64(&dec,0,0x80,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF); 7117 VARCMP(DECIMAL,dec,R8,-R8_MAX,VARCMP_GT); 7118 setdec64(&dec,20,0,0x5,0x6BC75E2D,0x63100001); /* 1+1e-20 */ 7119 VARCMP(DECIMAL,dec,R8,1,VARCMP_GT); /* DECIMAL has higher precision */ 7120 7121 /* Show that DATE is handled just as a R8 */ 7122 VARCMP(DATE,DATE_MAX,DATE,DATE_MAX+1,VARCMP_LT); 7123 VARCMP(DATE,DATE_MIN,DATE,DATE_MIN-1,VARCMP_GT); 7124 VARCMP(DATE,R8_MIN,R8,R8_MIN,VARCMP_EQ); 7125 VARCMP(DATE,1,DATE,1+1e-15,VARCMP_LT); /* 1e-15 == 8.64e-11 seconds */ 7126 VARCMP(DATE,25570.0,DATE,25570.0,VARCMP_EQ); 7127 VARCMP(DATE,25570.0,DATE,25571.0,VARCMP_LT); 7128 VARCMP(DATE,25571.0,DATE,25570.0,VARCMP_GT); 7129 VARCMP(DATE,25570.0,EMPTY,0,VARCMP_GT); 7130 VARCMP(DATE,25570.0,NULL_,0,VARCMP_NULL); 7131 7132 /* R4 precision handling */ 7133 VARCMP(R4,1,R8,1+1e-8,VARCMP_EQ); 7134 VARCMP(R8,1+1e-8,R4,1,VARCMP_EQ); 7135 VARCMP(R8,1+1e-8,R8,1,VARCMP_GT); 7136 VARCMP(R8,R4_MAX*1.1,R4,R4_MAX,VARCMP_GT); 7137 VARCMP(R4,R4_MAX,R8,R8_MAX,VARCMP_LT); 7138 VARCMP(R4,1,DATE,1+1e-8,VARCMP_EQ); 7139 VARCMP(R4,1,BSTR,bstr1few,VARCMP_LT); /* bstr1few == 1+1e-8 */ 7140 setdec(&dec,8,0,0,0x5F5E101); /* 1+1e-8 */ 7141 VARCMP(R4,1,DECIMAL,dec,VARCMP_LT); 7142 7143 SysFreeString(bstrhuh); 7144 SysFreeString(bstrempty); 7145 SysFreeString(bstr0); 7146 SysFreeString(bstr1); 7147 SysFreeString(bstr7); 7148 SysFreeString(bstr42); 7149 SysFreeString(bstr1neg); 7150 SysFreeString(bstr666neg); 7151 SysFreeString(bstr2cents); 7152 SysFreeString(bstr1few); 7153 } 7154 7155 static HRESULT (WINAPI *pVarPow)(LPVARIANT,LPVARIANT,LPVARIANT); 7156 7157 #define VARPOW(vt1,val1,vt2,val2,rvt,rval) \ 7158 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \ 7159 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \ 7160 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 7161 test_var_call2( __LINE__, pVarPow, &left, &right, &exp ) 7162 7163 /* Skip any type that is not defined or produces an error for every case */ 7164 #define SKIPTESTPOW(a) \ 7165 if (a == VT_ERROR || a == VT_VARIANT || \ 7166 a == VT_DISPATCH || a == VT_UNKNOWN || \ 7167 a == VT_RECORD || a > VT_UINT || \ 7168 a == 15 /*not defined*/) \ 7169 continue 7170 7171 static void test_VarPow(void) 7172 { 7173 static const WCHAR str2[] = { '2','\0' }; 7174 static const WCHAR str3[] = { '3','\0' }; 7175 VARIANT left, right, exp, result, cy, dec; 7176 BSTR num2_str, num3_str; 7177 VARTYPE i; 7178 HRESULT hres; 7179 7180 CHECKPTR(VarPow); 7181 7182 num2_str = SysAllocString(str2); 7183 num3_str = SysAllocString(str3); 7184 7185 /* Test all possible flag/vt combinations & the resulting vt type */ 7186 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 7187 { 7188 VARTYPE leftvt, rightvt, resvt; 7189 7190 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++) 7191 { 7192 SKIPTESTPOW(leftvt); 7193 7194 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++) 7195 { 7196 BOOL bFail = FALSE; 7197 SKIPTESTPOW(rightvt); 7198 7199 /* Native crashes with VT_BYREF */ 7200 if (ExtraFlags[i] == VT_BYREF) 7201 continue; 7202 7203 memset(&left, 0, sizeof(left)); 7204 memset(&right, 0, sizeof(right)); 7205 V_VT(&left) = leftvt | ExtraFlags[i]; 7206 V_VT(&right) = rightvt | ExtraFlags[i]; 7207 V_VT(&result) = VT_EMPTY; 7208 resvt = VT_EMPTY; 7209 7210 if (leftvt == VT_BSTR) 7211 V_BSTR(&left) = num2_str; 7212 if (rightvt == VT_BSTR) 7213 V_BSTR(&right) = num2_str; 7214 7215 /* Native VarPow always returns an error when using extra flags */ 7216 if (ExtraFlags[i] != 0) 7217 bFail = TRUE; 7218 7219 /* Determine return type */ 7220 else if ((leftvt == VT_NULL || rightvt == VT_NULL) && 7221 ((leftvt != VT_I8 && leftvt != VT_UI8 && 7222 rightvt != VT_I8 && rightvt != VT_UI8) || has_i8)) 7223 resvt = VT_NULL; 7224 else if ((leftvt == VT_EMPTY || leftvt == VT_I2 || 7225 leftvt == VT_I4 || leftvt == VT_R4 || 7226 leftvt == VT_R8 || leftvt == VT_CY || 7227 leftvt == VT_DATE || leftvt == VT_BSTR || 7228 leftvt == VT_BOOL || leftvt == VT_DECIMAL || 7229 (leftvt >= VT_I1 && leftvt <= VT_UI4) || 7230 (has_i8 && (leftvt == VT_I8 || leftvt == VT_UI8)) || 7231 leftvt == VT_INT || leftvt == VT_UINT) && 7232 (rightvt == VT_EMPTY || rightvt == VT_I2 || 7233 rightvt == VT_I4 || rightvt == VT_R4 || 7234 rightvt == VT_R8 || rightvt == VT_CY || 7235 rightvt == VT_DATE || rightvt == VT_BSTR || 7236 rightvt == VT_BOOL || rightvt == VT_DECIMAL || 7237 (rightvt >= VT_I1 && rightvt <= VT_UI4) || 7238 (has_i8 && (rightvt == VT_I8 || rightvt == VT_UI8)) || 7239 rightvt == VT_INT || rightvt == VT_UINT)) 7240 resvt = VT_R8; 7241 else 7242 bFail = TRUE; 7243 7244 hres = pVarPow(&left, &right, &result); 7245 7246 /* Check expected HRESULT and if result variant type is correct */ 7247 if (bFail) 7248 ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH, 7249 "VarPow: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n", 7250 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], 7251 vtstr(V_VT(&result)), hres); 7252 else 7253 ok (hres == S_OK && resvt == V_VT(&result), 7254 "VarPow: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n", 7255 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt), 7256 S_OK, vtstr(V_VT(&result)), hres); 7257 } 7258 } 7259 } 7260 7261 /* Check return values for valid variant type combinations */ 7262 VARPOW(EMPTY,0,EMPTY,0,R8,1.0); 7263 VARPOW(EMPTY,0,NULL,0,NULL,0); 7264 VARPOW(EMPTY,0,I2,3,R8,0.0); 7265 VARPOW(EMPTY,0,I4,3,R8,0.0); 7266 VARPOW(EMPTY,0,R4,3.0f,R8,0.0); 7267 VARPOW(EMPTY,0,R8,3.0,R8,0.0); 7268 VARPOW(EMPTY,0,DATE,3,R8,0.0); 7269 VARPOW(EMPTY,0,BSTR,num3_str,R8,0.0); 7270 VARPOW(EMPTY,0,BOOL,VARIANT_FALSE,R8,1.0); 7271 VARPOW(EMPTY,0,I1,3,R8,0.0); 7272 VARPOW(EMPTY,0,UI1,3,R8,0.0); 7273 VARPOW(EMPTY,0,UI2,3,R8,0.0); 7274 VARPOW(EMPTY,0,UI4,3,R8,0.0); 7275 if (has_i8) 7276 { 7277 VARPOW(EMPTY,0,I8,3,R8,0.0); 7278 VARPOW(EMPTY,0,UI8,3,R8,0.0); 7279 } 7280 VARPOW(EMPTY,0,INT,3,R8,0.0); 7281 VARPOW(EMPTY,0,UINT,3,R8,0.0); 7282 VARPOW(NULL,0,EMPTY,0,NULL,0); 7283 VARPOW(NULL,0,NULL,0,NULL,0); 7284 VARPOW(NULL,0,I2,3,NULL,0); 7285 VARPOW(NULL,0,I4,3,NULL,0); 7286 VARPOW(NULL,0,R4,3.0f,NULL,0); 7287 VARPOW(NULL,0,R8,3.0,NULL,0); 7288 VARPOW(NULL,0,DATE,3,NULL,0); 7289 VARPOW(NULL,0,BSTR,num3_str,NULL,0); 7290 VARPOW(NULL,0,BOOL,VARIANT_TRUE,NULL,0); 7291 VARPOW(NULL,0,I1,3,NULL,0); 7292 VARPOW(NULL,0,UI1,3,NULL,0); 7293 VARPOW(NULL,0,UI2,3,NULL,0); 7294 VARPOW(NULL,0,UI4,3,NULL,0); 7295 if (has_i8) 7296 { 7297 VARPOW(NULL,0,I8,3,NULL,0); 7298 VARPOW(NULL,0,UI8,3,NULL,0); 7299 } 7300 VARPOW(NULL,0,INT,3,NULL,0); 7301 VARPOW(NULL,0,UINT,3,NULL,0); 7302 VARPOW(I2,2,EMPTY,0,R8,1.0); 7303 VARPOW(I2,2,NULL,0,NULL,0); 7304 VARPOW(I2,2,I2,3,R8,8.0); 7305 VARPOW(I2,2,I4,3,R8,8.0); 7306 VARPOW(I2,2,R4,3.0f,R8,8.0); 7307 VARPOW(I2,2,R8,3.0,R8,8.0); 7308 VARPOW(I2,2,DATE,3,R8,8.0); 7309 VARPOW(I2,2,BSTR,num3_str,R8,8.0); 7310 VARPOW(I2,2,BOOL,VARIANT_FALSE,R8,1.0); 7311 VARPOW(I2,2,I1,3,R8,8.0); 7312 VARPOW(I2,2,UI1,3,R8,8.0); 7313 VARPOW(I2,2,UI2,3,R8,8.0); 7314 VARPOW(I2,2,UI4,3,R8,8.0); 7315 if (has_i8) 7316 { 7317 VARPOW(I2,2,I8,3,R8,8.0); 7318 VARPOW(I2,2,UI8,3,R8,8.0); 7319 } 7320 VARPOW(I2,2,INT,3,R8,8.0); 7321 VARPOW(I2,2,UINT,3,R8,8.0); 7322 VARPOW(I4,2,EMPTY,0,R8,1.0); 7323 VARPOW(I4,2,NULL,0,NULL,0); 7324 VARPOW(I4,2,I2,3,R8,8.0); 7325 VARPOW(I4,2,I4,3,R8,8.0); 7326 VARPOW(I4,2,R4,3.0f,R8,8.0); 7327 VARPOW(I4,2,R8,3.0,R8,8.0); 7328 VARPOW(I4,2,DATE,3,R8,8.0); 7329 VARPOW(I4,2,BSTR,num3_str,R8,8.0); 7330 VARPOW(I4,2,BOOL,VARIANT_FALSE,R8,1.0); 7331 VARPOW(I4,2,I1,3,R8,8.0); 7332 VARPOW(I4,2,UI1,3,R8,8.0); 7333 VARPOW(I4,2,UI2,3,R8,8.0); 7334 VARPOW(I4,2,UI4,3,R8,8.0); 7335 if (has_i8) 7336 { 7337 VARPOW(I4,2,I8,3,R8,8.0); 7338 VARPOW(I4,2,UI8,3,R8,8.0); 7339 } 7340 VARPOW(I4,2,INT,3,R8,8.0); 7341 VARPOW(I4,2,UINT,3,R8,8.0); 7342 VARPOW(R4,2,EMPTY,0,R8,1.0); 7343 VARPOW(R4,2,NULL,0,NULL,0); 7344 VARPOW(R4,2,I2,3,R8,8.0); 7345 VARPOW(R4,2,I4,3,R8,8.0); 7346 VARPOW(R4,2,R4,3.0f,R8,8.0); 7347 VARPOW(R4,2,R8,3.0,R8,8.0); 7348 VARPOW(R4,2,DATE,3,R8,8.0); 7349 VARPOW(R4,2,BSTR,num3_str,R8,8.0); 7350 VARPOW(R4,2,BOOL,VARIANT_FALSE,R8,1.0); 7351 VARPOW(R4,2,I1,3,R8,8.0); 7352 VARPOW(R4,2,UI1,3,R8,8.0); 7353 VARPOW(R4,2,UI2,3,R8,8.0); 7354 VARPOW(R4,2,UI4,3,R8,8.0); 7355 if (has_i8) 7356 { 7357 VARPOW(R4,2,I8,3,R8,8.0); 7358 VARPOW(R4,2,UI8,3,R8,8.0); 7359 } 7360 VARPOW(R4,2,INT,3,R8,8.0); 7361 VARPOW(R4,2,UINT,3,R8,8.0); 7362 VARPOW(R8,2,EMPTY,0,R8,1.0); 7363 VARPOW(R8,2,NULL,0,NULL,0); 7364 VARPOW(R8,2,I2,3,R8,8.0); 7365 VARPOW(R8,2,I4,3,R8,8.0); 7366 VARPOW(R8,2,R4,3.0f,R8,8.0); 7367 VARPOW(R8,2,R8,3.0,R8,8.0); 7368 VARPOW(R8,2,DATE,3,R8,8.0); 7369 VARPOW(R8,2,BSTR,num3_str,R8,8.0); 7370 VARPOW(R8,2,BOOL,VARIANT_FALSE,R8,1.0); 7371 VARPOW(R8,2,I1,3,R8,8.0); 7372 VARPOW(R8,2,UI1,3,R8,8.0); 7373 VARPOW(R8,2,UI2,3,R8,8.0); 7374 VARPOW(R8,2,UI4,3,R8,8.0); 7375 if (has_i8) 7376 { 7377 VARPOW(R8,2,I8,3,R8,8.0); 7378 VARPOW(R8,2,UI8,3,R8,8.0); 7379 } 7380 VARPOW(R8,2,INT,3,R8,8.0); 7381 VARPOW(R8,2,UINT,3,R8,8.0); 7382 VARPOW(DATE,2,EMPTY,0,R8,1.0); 7383 VARPOW(DATE,2,NULL,0,NULL,0); 7384 VARPOW(DATE,2,I2,3,R8,8.0); 7385 VARPOW(DATE,2,I4,3,R8,8.0); 7386 VARPOW(DATE,2,R4,3.0f,R8,8.0); 7387 VARPOW(DATE,2,R8,3.0,R8,8.0); 7388 VARPOW(DATE,2,DATE,3,R8,8.0); 7389 VARPOW(DATE,2,BSTR,num3_str,R8,8.0); 7390 VARPOW(DATE,2,BOOL,VARIANT_FALSE,R8,1.0); 7391 VARPOW(DATE,2,I1,3,R8,8.0); 7392 VARPOW(DATE,2,UI1,3,R8,8.0); 7393 VARPOW(DATE,2,UI2,3,R8,8.0); 7394 VARPOW(DATE,2,UI4,3,R8,8.0); 7395 if (has_i8) 7396 { 7397 VARPOW(DATE,2,I8,3,R8,8.0); 7398 VARPOW(DATE,2,UI8,3,R8,8.0); 7399 } 7400 VARPOW(DATE,2,INT,3,R8,8.0); 7401 VARPOW(DATE,2,UINT,3,R8,8.0); 7402 VARPOW(BSTR,num2_str,EMPTY,0,R8,1.0); 7403 VARPOW(BSTR,num2_str,NULL,0,NULL,0); 7404 VARPOW(BSTR,num2_str,I2,3,R8,8.0); 7405 VARPOW(BSTR,num2_str,I4,3,R8,8.0); 7406 VARPOW(BSTR,num2_str,R4,3.0f,R8,8.0); 7407 VARPOW(BSTR,num2_str,R8,3.0,R8,8.0); 7408 VARPOW(BSTR,num2_str,DATE,3,R8,8.0); 7409 VARPOW(BSTR,num2_str,BSTR,num3_str,R8,8.0); 7410 VARPOW(BSTR,num2_str,BOOL,VARIANT_FALSE,R8,1.0); 7411 VARPOW(BSTR,num2_str,I1,3,R8,8.0); 7412 VARPOW(BSTR,num2_str,UI1,3,R8,8.0); 7413 VARPOW(BSTR,num2_str,UI2,3,R8,8.0); 7414 VARPOW(BSTR,num2_str,UI4,3,R8,8.0); 7415 if (has_i8) 7416 { 7417 VARPOW(BSTR,num2_str,I8,3,R8,8.0); 7418 VARPOW(BSTR,num2_str,UI8,3,R8,8.0); 7419 } 7420 VARPOW(BSTR,num2_str,INT,3,R8,8.0); 7421 VARPOW(BSTR,num2_str,UINT,3,R8,8.0); 7422 VARPOW(BOOL,VARIANT_TRUE,EMPTY,0,R8,1.0); 7423 VARPOW(BOOL,VARIANT_TRUE,NULL,0,NULL,0); 7424 VARPOW(BOOL,VARIANT_TRUE,I2,3,R8,-1.0); 7425 VARPOW(BOOL,VARIANT_TRUE,I4,3,R8,-1.0); 7426 VARPOW(BOOL,VARIANT_TRUE,R4,3.0f,R8,-1.0); 7427 VARPOW(BOOL,VARIANT_TRUE,R8,3.0,R8,-1.0); 7428 VARPOW(BOOL,VARIANT_TRUE,DATE,3,R8,-1.0); 7429 VARPOW(BOOL,VARIANT_TRUE,BSTR,num3_str,R8,-1.0); 7430 VARPOW(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,R8,-1.0); 7431 VARPOW(BOOL,VARIANT_TRUE,I1,3,R8,-1.0); 7432 VARPOW(BOOL,VARIANT_TRUE,UI1,3,R8,-1.0); 7433 VARPOW(BOOL,VARIANT_TRUE,UI2,3,R8,-1.0); 7434 VARPOW(BOOL,VARIANT_TRUE,UI4,3,R8,-1.0); 7435 if (has_i8) 7436 { 7437 VARPOW(BOOL,VARIANT_TRUE,I8,3,R8,-1.0); 7438 VARPOW(BOOL,VARIANT_TRUE,UI8,3,R8,-1.0); 7439 } 7440 VARPOW(BOOL,VARIANT_TRUE,INT,3,R8,-1.0); 7441 VARPOW(BOOL,VARIANT_TRUE,UINT,3,R8,-1.0); 7442 VARPOW(I1,2,EMPTY,0,R8,1.0); 7443 VARPOW(I1,2,NULL,0,NULL,0); 7444 VARPOW(I1,2,I2,3,R8,8.0); 7445 VARPOW(I1,2,I4,3,R8,8.0); 7446 VARPOW(I1,2,R4,3.0f,R8,8.0); 7447 VARPOW(I1,2,R8,3.0,R8,8.0); 7448 VARPOW(I1,2,DATE,3,R8,8.0); 7449 VARPOW(I1,2,BSTR,num3_str,R8,8.0); 7450 VARPOW(I1,2,BOOL,VARIANT_FALSE,R8,1.0); 7451 VARPOW(I1,2,I1,3,R8,8.0); 7452 VARPOW(I1,2,UI1,3,R8,8.0); 7453 VARPOW(I1,2,UI2,3,R8,8.0); 7454 VARPOW(I1,2,UI4,3,R8,8.0); 7455 if (has_i8) 7456 { 7457 VARPOW(I1,2,I8,3,R8,8.0); 7458 VARPOW(I1,2,UI8,3,R8,8.0); 7459 } 7460 VARPOW(I1,2,INT,3,R8,8.0); 7461 VARPOW(I1,2,UINT,3,R8,8.0); 7462 VARPOW(UI1,2,EMPTY,0,R8,1.0); 7463 VARPOW(UI1,2,NULL,0,NULL,0); 7464 VARPOW(UI1,2,I2,3,R8,8.0); 7465 VARPOW(UI1,2,I4,3,R8,8.0); 7466 VARPOW(UI1,2,R4,3.0f,R8,8.0); 7467 VARPOW(UI1,2,R8,3.0,R8,8.0); 7468 VARPOW(UI1,2,DATE,3,R8,8.0); 7469 VARPOW(UI1,2,BSTR,num3_str,R8,8.0); 7470 VARPOW(UI1,2,BOOL,VARIANT_FALSE,R8,1.0); 7471 VARPOW(UI1,2,I1,3,R8,8.0); 7472 VARPOW(UI1,2,UI1,3,R8,8.0); 7473 VARPOW(UI1,2,UI2,3,R8,8.0); 7474 VARPOW(UI1,2,UI4,3,R8,8.0); 7475 if (has_i8) 7476 { 7477 VARPOW(UI1,2,I8,3,R8,8.0); 7478 VARPOW(UI1,2,UI8,3,R8,8.0); 7479 } 7480 VARPOW(UI1,2,INT,3,R8,8.0); 7481 VARPOW(UI1,2,UINT,3,R8,8.0); 7482 VARPOW(UI2,2,EMPTY,0,R8,1.0); 7483 VARPOW(UI2,2,NULL,0,NULL,0); 7484 VARPOW(UI2,2,I2,3,R8,8.0); 7485 VARPOW(UI2,2,I4,3,R8,8.0); 7486 VARPOW(UI2,2,R4,3.0f,R8,8.0); 7487 VARPOW(UI2,2,R8,3.0,R8,8.0); 7488 VARPOW(UI2,2,DATE,3,R8,8.0); 7489 VARPOW(UI2,2,BSTR,num3_str,R8,8.0); 7490 VARPOW(UI2,2,BOOL,VARIANT_FALSE,R8,1.0); 7491 VARPOW(UI2,2,I1,3,R8,8.0); 7492 VARPOW(UI2,2,UI1,3,R8,8.0); 7493 VARPOW(UI2,2,UI2,3,R8,8.0); 7494 VARPOW(UI2,2,UI4,3,R8,8.0); 7495 if (has_i8) 7496 { 7497 VARPOW(UI2,2,I8,3,R8,8.0); 7498 VARPOW(UI2,2,UI8,3,R8,8.0); 7499 } 7500 VARPOW(UI2,2,INT,3,R8,8.0); 7501 VARPOW(UI2,2,UINT,3,R8,8.0); 7502 VARPOW(UI4,2,EMPTY,0,R8,1.0); 7503 VARPOW(UI4,2,NULL,0,NULL,0); 7504 VARPOW(UI4,2,I2,3,R8,8.0); 7505 VARPOW(UI4,2,I4,3,R8,8.0); 7506 VARPOW(UI4,2,R4,3.0f,R8,8.0); 7507 VARPOW(UI4,2,R8,3.0,R8,8.0); 7508 VARPOW(UI4,2,DATE,3,R8,8.0); 7509 VARPOW(UI4,2,BSTR,num3_str,R8,8.0); 7510 VARPOW(UI4,2,BOOL,VARIANT_FALSE,R8,1.0); 7511 VARPOW(UI4,2,I1,3,R8,8.0); 7512 VARPOW(UI4,2,UI1,3,R8,8.0); 7513 VARPOW(UI4,2,UI2,3,R8,8.0); 7514 VARPOW(UI4,2,UI4,3,R8,8.0); 7515 if (has_i8) 7516 { 7517 VARPOW(UI4,2,I8,3,R8,8.0); 7518 VARPOW(UI4,2,UI8,3,R8,8.0); 7519 } 7520 VARPOW(UI4,2,INT,3,R8,8.0); 7521 VARPOW(UI4,2,UINT,3,R8,8.0); 7522 if (has_i8) 7523 { 7524 VARPOW(I8,2,EMPTY,0,R8,1.0); 7525 VARPOW(I8,2,NULL,0,NULL,0); 7526 VARPOW(I8,2,I2,3,R8,8.0); 7527 VARPOW(I8,2,I4,3,R8,8.0); 7528 VARPOW(I8,2,R4,3.0f,R8,8.0); 7529 VARPOW(I8,2,R8,3.0,R8,8.0); 7530 VARPOW(I8,2,DATE,3,R8,8.0); 7531 VARPOW(I8,2,BSTR,num3_str,R8,8.0); 7532 VARPOW(I8,2,BOOL,VARIANT_FALSE,R8,1.0); 7533 VARPOW(I8,2,I1,3,R8,8.0); 7534 VARPOW(I8,2,UI1,3,R8,8.0); 7535 VARPOW(I8,2,UI2,3,R8,8.0); 7536 VARPOW(I8,2,UI4,3,R8,8.0); 7537 VARPOW(I8,2,I8,3,R8,8.0); 7538 VARPOW(I8,2,UI8,3,R8,8.0); 7539 VARPOW(I8,2,INT,3,R8,8.0); 7540 VARPOW(I8,2,UINT,3,R8,8.0); 7541 VARPOW(UI8,2,EMPTY,0,R8,1.0); 7542 VARPOW(UI8,2,NULL,0,NULL,0); 7543 VARPOW(UI8,2,I2,3,R8,8.0); 7544 VARPOW(UI8,2,I4,3,R8,8.0); 7545 VARPOW(UI8,2,R4,3.0f,R8,8.0); 7546 VARPOW(UI8,2,R8,3.0,R8,8.0); 7547 VARPOW(UI8,2,DATE,3,R8,8.0); 7548 VARPOW(UI8,2,BSTR,num3_str,R8,8.0); 7549 VARPOW(UI8,2,I1,3,R8,8.0); 7550 VARPOW(UI8,2,UI1,3,R8,8.0); 7551 VARPOW(UI8,2,UI2,3,R8,8.0); 7552 VARPOW(UI8,2,UI4,3,R8,8.0); 7553 VARPOW(UI8,2,I8,3,R8,8.0); 7554 VARPOW(UI8,2,UI8,3,R8,8.0); 7555 VARPOW(UI8,2,INT,3,R8,8.0); 7556 VARPOW(UI8,2,UINT,3,R8,8.0); 7557 } 7558 VARPOW(INT,2,EMPTY,0,R8,1.0); 7559 VARPOW(INT,2,NULL,0,NULL,0); 7560 VARPOW(INT,2,I2,3,R8,8.0); 7561 VARPOW(INT,2,I4,3,R8,8.0); 7562 VARPOW(INT,2,R4,3.0f,R8,8.0); 7563 VARPOW(INT,2,R8,3.0,R8,8.0); 7564 VARPOW(INT,2,DATE,3,R8,8.0); 7565 VARPOW(INT,2,BSTR,num3_str,R8,8.0); 7566 VARPOW(INT,2,BOOL,VARIANT_FALSE,R8,1.0); 7567 VARPOW(INT,2,I1,3,R8,8.0); 7568 VARPOW(INT,2,UI1,3,R8,8.0); 7569 VARPOW(INT,2,UI2,3,R8,8.0); 7570 VARPOW(INT,2,UI4,3,R8,8.0); 7571 if (has_i8) 7572 { 7573 VARPOW(INT,2,I8,3,R8,8.0); 7574 VARPOW(INT,2,UI8,3,R8,8.0); 7575 } 7576 VARPOW(INT,2,INT,3,R8,8.0); 7577 VARPOW(INT,2,UINT,3,R8,8.0); 7578 VARPOW(UINT,2,EMPTY,0,R8,1.0); 7579 VARPOW(UINT,2,NULL,0,NULL,0); 7580 VARPOW(UINT,2,I2,3,R8,8.0); 7581 VARPOW(UINT,2,I4,3,R8,8.0); 7582 VARPOW(UINT,2,R4,3.0f,R8,8.0); 7583 VARPOW(UINT,2,R8,3.0,R8,8.0); 7584 VARPOW(UINT,2,DATE,3,R8,8.0); 7585 VARPOW(UINT,2,BSTR,num3_str,R8,8.0); 7586 VARPOW(UINT,2,BOOL,VARIANT_FALSE,R8,1.0); 7587 VARPOW(UINT,2,I1,3,R8,8.0); 7588 VARPOW(UINT,2,UI1,3,R8,8.0); 7589 VARPOW(UINT,2,UI2,3,R8,8.0); 7590 VARPOW(UINT,2,UI4,3,R8,8.0); 7591 if (has_i8) 7592 { 7593 VARPOW(UINT,2,I8,3,R8,8.0); 7594 VARPOW(UINT,2,UI8,3,R8,8.0); 7595 } 7596 VARPOW(UINT,2,INT,3,R8,8.0); 7597 VARPOW(UINT,2,UINT,3,R8,8.0); 7598 7599 /* Manually test some VT_CY, VT_DECIMAL variants */ 7600 V_VT(&cy) = VT_CY; 7601 hres = VarCyFromI4(2, &V_CY(&cy)); 7602 ok(hres == S_OK, "VarCyFromI4 failed!\n"); 7603 V_VT(&dec) = VT_DECIMAL; 7604 hres = VarDecFromR8(2.0, &V_DECIMAL(&dec)); 7605 ok(hres == S_OK, "VarDecFromR4 failed!\n"); 7606 memset(&left, 0, sizeof(left)); 7607 memset(&right, 0, sizeof(right)); 7608 V_VT(&left) = VT_I4; 7609 V_I4(&left) = 100; 7610 V_VT(&right) = VT_I8; 7611 V_UI1(&right) = 2; 7612 7613 hres = pVarPow(&cy, &cy, &result); 7614 ok(hres == S_OK && V_VT(&result) == VT_R8, 7615 "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n", 7616 S_OK, hres, vtstr(V_VT(&result))); 7617 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 4.0), 7618 "VARPOW: CY value %f, expected %f\n", V_R8(&result), 4.0); 7619 7620 hres = pVarPow(&cy, &right, &result); 7621 if (hres == S_OK) 7622 { 7623 ok(V_VT(&result) == VT_R8, 7624 "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n", 7625 S_OK, hres, vtstr(V_VT(&result))); 7626 ok(EQ_DOUBLE(V_R8(&result), 4.0), 7627 "VARPOW: CY value %f, expected %f\n", V_R8(&result), 4.0); 7628 } 7629 else 7630 { 7631 ok(hres == DISP_E_BADVARTYPE && V_VT(&result) == VT_EMPTY, 7632 "VARPOW: expected coerced hres 0x%X type VT_EMPTY, got hres 0x%X type %s!\n", 7633 DISP_E_BADVARTYPE, hres, vtstr(V_VT(&result))); 7634 } 7635 7636 hres = pVarPow(&left, &cy, &result); 7637 ok(hres == S_OK && V_VT(&result) == VT_R8, 7638 "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n", 7639 S_OK, hres, vtstr(V_VT(&result))); 7640 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 10000.0), 7641 "VARPOW: CY value %f, expected %f\n", V_R8(&result), 10000.0); 7642 7643 hres = pVarPow(&left, &dec, &result); 7644 ok(hres == S_OK && V_VT(&result) == VT_R8, 7645 "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n", 7646 S_OK, hres, vtstr(V_VT(&result))); 7647 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result),10000.0), 7648 "VARPOW: DECIMAL value %f, expected %f\n", V_R8(&result), 10000.0); 7649 7650 hres = pVarPow(&dec, &dec, &result); 7651 ok(hres == S_OK && V_VT(&result) == VT_R8, 7652 "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n", 7653 S_OK, hres, vtstr(V_VT(&result))); 7654 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 4.0), 7655 "VARPOW: DECIMAL value %f, expected %f\n", V_R8(&result), 4.0); 7656 7657 hres = pVarPow(&dec, &right, &result); 7658 if (hres == S_OK) 7659 { 7660 ok(V_VT(&result) == VT_R8, 7661 "VARPOW: expected coerced hres 0x%X type VT_R8, got hres 0x%X type %s!\n", 7662 S_OK, hres, vtstr(V_VT(&result))); 7663 ok(EQ_DOUBLE(V_R8(&result), 4.0), 7664 "VARPOW: DECIMAL value %f, expected %f\n", V_R8(&result), 4.0); 7665 } 7666 else 7667 { 7668 ok(hres == DISP_E_BADVARTYPE && V_VT(&result) == VT_EMPTY, 7669 "VARPOW: expected coerced hres 0x%X type VT_EMPTY, got hres 0x%X type %s!\n", 7670 DISP_E_BADVARTYPE, hres, vtstr(V_VT(&result))); 7671 } 7672 7673 SysFreeString(num2_str); 7674 SysFreeString(num3_str); 7675 } 7676 7677 static HRESULT (WINAPI *pVarDiv)(LPVARIANT,LPVARIANT,LPVARIANT); 7678 7679 #define VARDIV(vt1,val1,vt2,val2,rvt,rval) \ 7680 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \ 7681 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \ 7682 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 7683 test_var_call2( __LINE__, pVarDiv, &left, &right, &exp ) 7684 7685 /* Skip any type that is not defined or produces an error for every case */ 7686 #define SKIPTESTDIV(a) \ 7687 if (a == VT_ERROR || a == VT_VARIANT || \ 7688 a == VT_DISPATCH || a == VT_UNKNOWN || \ 7689 a == VT_RECORD || a > VT_UINT || \ 7690 a == VT_I1 || a == VT_UI8 || \ 7691 a == VT_INT || a == VT_UINT || \ 7692 a == VT_UI2 || a == VT_UI4 || \ 7693 a == 15 /*not defined*/) \ 7694 continue 7695 7696 static void test_VarDiv(void) 7697 { 7698 static const WCHAR str1[] = { '1','\0' }; 7699 static const WCHAR str2[] = { '2','\0' }; 7700 VARIANT left, right, exp, result, cy, dec; 7701 BSTR num1_str, num2_str; 7702 VARTYPE i; 7703 HRESULT hres; 7704 double r; 7705 7706 CHECKPTR(VarDiv); 7707 7708 num1_str = SysAllocString(str1); 7709 num2_str = SysAllocString(str2); 7710 7711 /* Test all possible flag/vt combinations & the resulting vt type */ 7712 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 7713 { 7714 VARTYPE leftvt, rightvt, resvt; 7715 7716 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++) 7717 { 7718 SKIPTESTDIV(leftvt); 7719 7720 /* Check if we need/have support for I8 */ 7721 if (leftvt == VT_I8 && !has_i8) 7722 continue; 7723 7724 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++) 7725 { 7726 BOOL bFail = FALSE; 7727 SKIPTESTDIV(rightvt); 7728 7729 /* Check if we need/have support for I8 */ 7730 if (rightvt == VT_I8 && !has_i8) 7731 continue; 7732 7733 /* Native crashes with VT_BYREF */ 7734 if (ExtraFlags[i] == VT_BYREF) 7735 continue; 7736 7737 memset(&left, 0, sizeof(left)); 7738 memset(&right, 0, sizeof(right)); 7739 V_VT(&left) = leftvt | ExtraFlags[i]; 7740 V_VT(&right) = rightvt | ExtraFlags[i]; 7741 V_VT(&result) = VT_EMPTY; 7742 resvt = VT_EMPTY; 7743 7744 if (leftvt == VT_BSTR) 7745 V_BSTR(&left) = num2_str; 7746 else if (leftvt == VT_DECIMAL) 7747 { 7748 VarDecFromR8(2.0, &V_DECIMAL(&left)); 7749 V_VT(&left) = leftvt | ExtraFlags[i]; 7750 } 7751 7752 /* Division by 0 is undefined */ 7753 switch(rightvt) 7754 { 7755 case VT_BSTR: 7756 V_BSTR(&right) = num2_str; 7757 break; 7758 case VT_DECIMAL: 7759 VarDecFromR8(2.0, &V_DECIMAL(&right)); 7760 V_VT(&right) = rightvt | ExtraFlags[i]; 7761 break; 7762 case VT_BOOL: 7763 V_BOOL(&right) = VARIANT_TRUE; 7764 break; 7765 case VT_I2: V_I2(&right) = 2; break; 7766 case VT_I4: V_I4(&right) = 2; break; 7767 case VT_R4: V_R4(&right) = 2.0f; break; 7768 case VT_R8: V_R8(&right) = 2.0; break; 7769 case VT_CY: V_CY(&right).int64 = 2; break; 7770 case VT_DATE: V_DATE(&right) = 2; break; 7771 case VT_UI1: V_UI1(&right) = 2; break; 7772 case VT_I8: V_I8(&right) = 2; break; 7773 default: break; 7774 } 7775 7776 /* Determine return type */ 7777 if (rightvt != VT_EMPTY) 7778 { 7779 if (leftvt == VT_NULL || rightvt == VT_NULL) 7780 resvt = VT_NULL; 7781 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL) 7782 resvt = VT_DECIMAL; 7783 else if (leftvt == VT_I8 || rightvt == VT_I8 || 7784 leftvt == VT_CY || rightvt == VT_CY || 7785 leftvt == VT_DATE || rightvt == VT_DATE || 7786 leftvt == VT_I4 || rightvt == VT_I4 || 7787 leftvt == VT_BSTR || rightvt == VT_BSTR || 7788 leftvt == VT_I2 || rightvt == VT_I2 || 7789 leftvt == VT_BOOL || rightvt == VT_BOOL || 7790 leftvt == VT_R8 || rightvt == VT_R8 || 7791 leftvt == VT_UI1 || rightvt == VT_UI1) 7792 { 7793 if ((leftvt == VT_UI1 && rightvt == VT_R4) || 7794 (leftvt == VT_R4 && rightvt == VT_UI1)) 7795 resvt = VT_R4; 7796 else if ((leftvt == VT_R4 && (rightvt == VT_BOOL || 7797 rightvt == VT_I2)) || (rightvt == VT_R4 && 7798 (leftvt == VT_BOOL || leftvt == VT_I2))) 7799 resvt = VT_R4; 7800 else 7801 resvt = VT_R8; 7802 } 7803 else if (leftvt == VT_R4 || rightvt == VT_R4) 7804 resvt = VT_R4; 7805 } 7806 else if (leftvt == VT_NULL) 7807 resvt = VT_NULL; 7808 else 7809 bFail = TRUE; 7810 7811 /* Native VarDiv always returns an error when using extra flags */ 7812 if (ExtraFlags[i] != 0) 7813 bFail = TRUE; 7814 7815 hres = pVarDiv(&left, &right, &result); 7816 7817 /* Check expected HRESULT and if result variant type is correct */ 7818 if (bFail) 7819 ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH || 7820 hres == DISP_E_OVERFLOW || hres == DISP_E_DIVBYZERO, 7821 "VarDiv: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n", 7822 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], 7823 vtstr(V_VT(&result)), hres); 7824 else 7825 ok (hres == S_OK && resvt == V_VT(&result), 7826 "VarDiv: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n", 7827 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt), 7828 S_OK, vtstr(V_VT(&result)), hres); 7829 } 7830 } 7831 } 7832 7833 /* Test return values for all the good cases */ 7834 VARDIV(EMPTY,0,NULL,0,NULL,0); 7835 VARDIV(EMPTY,0,I2,2,R8,0.0); 7836 VARDIV(EMPTY,0,I4,2,R8,0.0); 7837 VARDIV(EMPTY,0,R4,2.0f,R4,0.0f); 7838 VARDIV(EMPTY,0,R8,2.0,R8,0.0); 7839 VARDIV(EMPTY,0,DATE,2.0,R8,0.0); 7840 VARDIV(EMPTY,0,BSTR,num2_str,R8,0.0); 7841 VARDIV(EMPTY,0,BOOL,VARIANT_TRUE,R8,0.0); 7842 VARDIV(EMPTY,0,UI1,2,R8,0.0); 7843 if (has_i8) 7844 { 7845 VARDIV(EMPTY,0,I8,2,R8,0.0); 7846 } 7847 VARDIV(NULL,0,EMPTY,0,NULL,0); 7848 VARDIV(NULL,0,NULL,0,NULL,0); 7849 VARDIV(NULL,0,I2,2,NULL,0); 7850 VARDIV(NULL,0,I4,2,NULL,0); 7851 VARDIV(NULL,0,R4,2.0f,NULL,0); 7852 VARDIV(NULL,0,R8,2.0,NULL,0); 7853 VARDIV(NULL,0,DATE,2,NULL,0); 7854 VARDIV(NULL,0,BSTR,num2_str,NULL,0); 7855 VARDIV(NULL,0,BOOL,VARIANT_TRUE,NULL,0); 7856 VARDIV(NULL,0,UI1,2,NULL,0); 7857 if (has_i8) 7858 { 7859 VARDIV(NULL,0,I8,2,NULL,0); 7860 } 7861 VARDIV(I2,2,NULL,0,NULL,0); 7862 VARDIV(I2,1,I2,2,R8,0.5); 7863 VARDIV(I2,1,I4,2,R8,0.5); 7864 VARDIV(I2,1,R4,2,R4,0.5f); 7865 VARDIV(I2,1,R8,2.0,R8,0.5); 7866 VARDIV(I2,1,DATE,2,R8,0.5); 7867 VARDIV(I2,1,BOOL,VARIANT_TRUE,R8,-1.0); 7868 VARDIV(I2,1,UI1,2,R8,0.5); 7869 if (has_i8) 7870 { 7871 VARDIV(I2,1,I8,2,R8,0.5); 7872 } 7873 VARDIV(I4,1,NULL,0,NULL,0); 7874 VARDIV(I4,1,I2,2,R8,0.5); 7875 VARDIV(I4,1,I4,2,R8,0.5); 7876 VARDIV(I4,1,R4,2.0f,R8,0.5); 7877 VARDIV(I4,1,R8,2.0,R8,0.5); 7878 VARDIV(I4,1,DATE,2,R8,0.5); 7879 VARDIV(I4,1,BSTR,num2_str,R8,0.5); 7880 VARDIV(I4,1,BOOL,VARIANT_TRUE,R8,-1.0); 7881 VARDIV(I4,1,UI1,2,R8,0.5); 7882 if (has_i8) 7883 { 7884 VARDIV(I4,1,I8,2,R8,0.5); 7885 } 7886 VARDIV(R4,1.0f,NULL,0,NULL,0); 7887 VARDIV(R4,1.0f,I2,2,R4,0.5f); 7888 VARDIV(R4,1.0f,I4,2,R8,0.5); 7889 VARDIV(R4,1.0f,R4,2.0f,R4,0.5f); 7890 VARDIV(R4,1.0f,R8,2.0,R8,0.5); 7891 VARDIV(R4,1.0f,DATE,2,R8,0.5); 7892 VARDIV(R4,1.0f,BSTR,num2_str,R8,0.5); 7893 VARDIV(R4,1.0f,BOOL,VARIANT_TRUE,R4,-1); 7894 VARDIV(R4,1.0f,UI1,2,R4,0.5f); 7895 if (has_i8) 7896 { 7897 VARDIV(R4,1.0f,I8,2,R8,0.5); 7898 } 7899 VARDIV(R8,1.0,NULL,0,NULL,0); 7900 VARDIV(R8,1.0,I2,2,R8,0.5); 7901 VARDIV(R8,1.0,I4,2,R8,0.5); 7902 VARDIV(R8,1.0,R4,2.0f,R8,0.5); 7903 VARDIV(R8,1.0,R8,2.0,R8,0.5); 7904 VARDIV(R8,1.0,DATE,2,R8,0.5); 7905 VARDIV(R8,1.0,BSTR,num2_str,R8,0.5); 7906 VARDIV(R8,1.0,BOOL,VARIANT_TRUE,R8,-1.0); 7907 VARDIV(R8,1.0,UI1,2,R8,0.5); 7908 if (has_i8) 7909 { 7910 VARDIV(R8,1.0,I8,2,R8,0.5); 7911 } 7912 VARDIV(DATE,1,NULL,0,NULL,0); 7913 VARDIV(DATE,1,I2,2,R8,0.5); 7914 VARDIV(DATE,1,I4,2,R8,0.5); 7915 VARDIV(DATE,1,R4,2.0f,R8,0.5); 7916 VARDIV(DATE,1,R8,2.0,R8,0.5); 7917 VARDIV(DATE,1,DATE,2,R8,0.5); 7918 VARDIV(DATE,1,BSTR,num2_str,R8,0.5); 7919 VARDIV(DATE,1,BOOL,VARIANT_TRUE,R8,-1.0); 7920 VARDIV(DATE,1,UI1,2,R8,0.5); 7921 if (has_i8) 7922 { 7923 VARDIV(DATE,1,I8,2,R8,0.5); 7924 } 7925 VARDIV(BSTR,num1_str,NULL,0,NULL,0); 7926 VARDIV(BSTR,num1_str,I2,2,R8,0.5); 7927 VARDIV(BSTR,num1_str,I4,2,R8,0.5); 7928 VARDIV(BSTR,num1_str,R4,2.0f,R8,0.5); 7929 VARDIV(BSTR,num1_str,R8,2.0,R8,0.5); 7930 VARDIV(BSTR,num1_str,DATE,2,R8,0.5); 7931 VARDIV(BSTR,num1_str,BSTR,num2_str,R8,0.5); 7932 VARDIV(BSTR,num1_str,BOOL,VARIANT_TRUE,R8,-1); 7933 VARDIV(BSTR,num1_str,UI1,2,R8,0.5); 7934 if (has_i8) 7935 { 7936 VARDIV(BSTR,num1_str,I8,2,R8,0.5); 7937 } 7938 VARDIV(BOOL,VARIANT_TRUE,NULL,0,NULL,0); 7939 VARDIV(BOOL,VARIANT_TRUE,I2,1,R8,-1.0); 7940 VARDIV(BOOL,VARIANT_FALSE,I2,1,R8,0.0); 7941 VARDIV(BOOL,VARIANT_TRUE,I4,1,R8,-1.0); 7942 VARDIV(BOOL,VARIANT_FALSE,I4,1,R8,0.0); 7943 VARDIV(BOOL,VARIANT_TRUE,R4,1,R4,-1.0f); 7944 VARDIV(BOOL,VARIANT_FALSE,R4,1,R4,0.0f); 7945 VARDIV(BOOL,VARIANT_TRUE,R8,1.0,R8,-1.0); 7946 VARDIV(BOOL,VARIANT_FALSE,R8,1.0,R8,0.0); 7947 VARDIV(BOOL,VARIANT_FALSE,DATE,2,R8,0.0); 7948 VARDIV(BOOL,VARIANT_FALSE,BSTR,num2_str,R8,0.0); 7949 VARDIV(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,R8,1.0); 7950 VARDIV(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,R8,0.0); 7951 VARDIV(BOOL,VARIANT_TRUE,UI1,1,R8,-1.0); 7952 if (has_i8) 7953 { 7954 VARDIV(BOOL,VARIANT_TRUE,I8,1,R8,-1.0); 7955 } 7956 VARDIV(UI1,1,NULL,0,NULL,0); 7957 VARDIV(UI1,1,I2,2,R8,0.5); 7958 VARDIV(UI1,1,I4,2,R8,0.5); 7959 VARDIV(UI1,1,R4,2.0f,R4,0.5f); 7960 VARDIV(UI1,1,R8,2.0,R8,0.5); 7961 VARDIV(UI1,1,DATE,2,R8,0.5); 7962 VARDIV(UI1,1,BSTR,num2_str,R8,0.5); 7963 VARDIV(UI1,1,BOOL,VARIANT_TRUE,R8,-1); 7964 VARDIV(UI1,1,UI1,2,R8,0.5); 7965 if (has_i8) 7966 { 7967 VARDIV(UI1,1,I8,2,R8,0.5); 7968 VARDIV(I8,1,NULL,0,NULL,0); 7969 VARDIV(I8,1,I2,2,R8,0.5); 7970 VARDIV(I8,1,I4,2,R8,0.5); 7971 VARDIV(I8,1,R4,2.0f,R8,0.5); 7972 VARDIV(I8,1,R8,2.0,R8,0.5); 7973 VARDIV(I8,1,DATE,2,R8,0.5); 7974 VARDIV(I8,1,BSTR,num2_str,R8,0.5); 7975 VARDIV(I8,1,BOOL,VARIANT_TRUE,R8,-1); 7976 VARDIV(I8,1,UI1,2,R8,0.5); 7977 VARDIV(I8,1,I8,2,R8,0.5); 7978 } 7979 7980 /* Manually test some VT_CY, VT_DECIMAL variants */ 7981 V_VT(&cy) = VT_CY; 7982 hres = VarCyFromI4(10000, &V_CY(&cy)); 7983 ok(hres == S_OK, "VarCyFromI4 failed!\n"); 7984 V_VT(&dec) = VT_DECIMAL; 7985 hres = VarDecFromR8(2.0, &V_DECIMAL(&dec)); 7986 ok(hres == S_OK, "VarDecFromR4 failed!\n"); 7987 memset(&left, 0, sizeof(left)); 7988 memset(&right, 0, sizeof(right)); 7989 V_VT(&left) = VT_I4; 7990 V_I4(&left) = 100; 7991 V_VT(&right) = VT_UI1; 7992 V_UI1(&right) = 2; 7993 7994 hres = pVarDiv(&cy, &cy, &result); 7995 ok(hres == S_OK && V_VT(&result) == VT_R8, 7996 "VARDIV: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result))); 7997 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 1.0), 7998 "VARDIV: CY value %f, expected %f\n", V_R8(&result), (double)1.0); 7999 8000 hres = pVarDiv(&cy, &right, &result); 8001 ok(hres == S_OK && V_VT(&result) == VT_R8, 8002 "VARDIV: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result))); 8003 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 5000.0), 8004 "VARDIV: CY value %f, expected %f\n", V_R8(&result), (double)5000.0); 8005 8006 hres = pVarDiv(&left, &cy, &result); 8007 ok(hres == S_OK && V_VT(&result) == VT_R8, 8008 "VARDIV: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result))); 8009 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 0.01), 8010 "VARDIV: CY value %f, expected %f\n", V_R8(&result), (double)0.01); 8011 8012 hres = pVarDiv(&left, &dec, &result); 8013 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL, 8014 "VARDIV: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result))); 8015 hres = VarR8FromDec(&V_DECIMAL(&result), &r); 8016 ok(hres == S_OK && EQ_DOUBLE(r, 50.0), 8017 "VARDIV: DECIMAL value %f, expected %f\n", r, (double)50.0); 8018 8019 hres = pVarDiv(&dec, &dec, &result); 8020 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL, 8021 "VARDIV: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result))); 8022 hres = VarR8FromDec(&V_DECIMAL(&result), &r); 8023 ok(hres == S_OK && EQ_DOUBLE(r, 1.0), 8024 "VARDIV: DECIMAL value %f, expected %f\n", r, (double)1.0); 8025 8026 hres = pVarDiv(&dec, &right, &result); 8027 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL, 8028 "VARDIV: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result))); 8029 hres = VarR8FromDec(&V_DECIMAL(&result), &r); 8030 ok(hres == S_OK && EQ_DOUBLE(r, 1.0), 8031 "VARDIV: DECIMAL value %f, expected %f\n", r, (double)1.0); 8032 8033 /* Check for division by zero and overflow */ 8034 V_VT(&left) = VT_R8; 8035 V_I4(&left) = 1; 8036 V_VT(&right) = VT_R8; 8037 V_I4(&right) = 0; 8038 hres = pVarDiv(&left, &right, &result); 8039 ok(hres == DISP_E_DIVBYZERO && V_VT(&result) == VT_EMPTY, 8040 "VARDIV: Division by (1.0/0.0) should result in DISP_E_DIVBYZERO but got 0x%X\n", hres); 8041 8042 V_VT(&left) = VT_R8; 8043 V_I4(&left) = 0; 8044 V_VT(&right) = VT_R8; 8045 V_I4(&right) = 0; 8046 hres = pVarDiv(&left, &right, &result); 8047 ok(hres == DISP_E_OVERFLOW && V_VT(&result) == VT_EMPTY, 8048 "VARDIV: Division by (0.0/0.0) should result in DISP_E_OVERFLOW but got 0x%X\n", hres); 8049 8050 SysFreeString(num1_str); 8051 SysFreeString(num2_str); 8052 } 8053 8054 static HRESULT (WINAPI *pVarIdiv)(LPVARIANT,LPVARIANT,LPVARIANT); 8055 8056 #define VARIDIV(vt1,val1,vt2,val2,rvt,rval) \ 8057 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \ 8058 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \ 8059 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 8060 test_var_call2( __LINE__, pVarIdiv, &left, &right, &exp ) 8061 8062 /* Skip any type that is not defined or produces an error for every case */ 8063 #define SKIPTESTIDIV(a) \ 8064 if (a == VT_ERROR || a == VT_VARIANT || \ 8065 a == VT_DISPATCH || a == VT_UNKNOWN || \ 8066 a == VT_RECORD || a > VT_UINT || \ 8067 a == 15 /*not defined*/) \ 8068 continue 8069 8070 static void test_VarIdiv(void) 8071 { 8072 static const WCHAR str1[] = { '1','\0' }; 8073 static const WCHAR str2[] = { '2','\0' }; 8074 VARIANT left, right, exp, result, cy, dec; 8075 BSTR num1_str, num2_str; 8076 VARTYPE i; 8077 HRESULT hres; 8078 8079 CHECKPTR(VarIdiv); 8080 8081 num1_str = SysAllocString(str1); 8082 num2_str = SysAllocString(str2); 8083 8084 /* Test all possible flag/vt combinations & the resulting vt type */ 8085 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 8086 { 8087 VARTYPE leftvt, rightvt, resvt; 8088 8089 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++) 8090 { 8091 SKIPTESTIDIV(leftvt); 8092 8093 /* Check if we need/have support for I8 and/or UI8 */ 8094 if ((leftvt == VT_I8 || leftvt == VT_UI8) && !has_i8) 8095 continue; 8096 8097 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++) 8098 { 8099 BOOL bFail = FALSE; 8100 SKIPTESTIDIV(rightvt); 8101 8102 /* Native crashes with extra flag VT_BYREF */ 8103 if (ExtraFlags[i] == VT_BYREF) 8104 continue; 8105 8106 /* Check if we need/have support for I8 and/or UI8 */ 8107 if ((rightvt == VT_I8 || rightvt == VT_UI8) && !has_i8) 8108 continue; 8109 8110 memset(&left, 0, sizeof(left)); 8111 memset(&right, 0, sizeof(right)); 8112 V_VT(&left) = leftvt | ExtraFlags[i]; 8113 V_VT(&right) = rightvt | ExtraFlags[i]; 8114 V_VT(&result) = VT_EMPTY; 8115 resvt = VT_EMPTY; 8116 8117 if (leftvt == VT_BSTR) 8118 V_BSTR(&left) = num2_str; 8119 else if (leftvt == VT_DECIMAL) 8120 { 8121 VarDecFromR8(2.0, &V_DECIMAL(&left)); 8122 V_VT(&left) = leftvt | ExtraFlags[i]; 8123 } 8124 8125 /* Division by 0 is undefined */ 8126 switch(rightvt) 8127 { 8128 case VT_BSTR: 8129 V_BSTR(&right) = num2_str; 8130 break; 8131 case VT_DECIMAL: 8132 VarDecFromR8(2.0, &V_DECIMAL(&right)); 8133 V_VT(&right) = rightvt | ExtraFlags[i]; 8134 break; 8135 case VT_BOOL: 8136 V_BOOL(&right) = VARIANT_TRUE; 8137 break; 8138 case VT_CY: 8139 VarCyFromI4(10000, &V_CY(&right)); 8140 V_VT(&right) = rightvt | ExtraFlags[i]; 8141 break; 8142 case VT_I2: V_I2(&right) = 2; break; 8143 case VT_I4: V_I4(&right) = 2; break; 8144 case VT_R4: V_R4(&right) = 2.0f; break; 8145 case VT_R8: V_R8(&right) = 2.0; break; 8146 case VT_DATE: V_DATE(&right) = 2; break; 8147 case VT_I1: V_I1(&right) = 2; break; 8148 case VT_UI1: V_UI1(&right) = 2; break; 8149 case VT_UI2: V_UI2(&right) = 2; break; 8150 case VT_UI4: V_UI4(&right) = 2; break; 8151 case VT_I8: V_I8(&right) = 2; break; 8152 case VT_UI8: V_UI8(&right) = 2; break; 8153 case VT_INT: V_INT(&right) = 2; break; 8154 case VT_UINT: V_UINT(&right) = 2; break; 8155 default: break; 8156 } 8157 8158 /* Native VarIdiv always returns an error when using extra 8159 * flags or if the variant combination is I8 and INT. 8160 */ 8161 if ((leftvt == VT_I8 && rightvt == VT_INT) || 8162 (leftvt == VT_INT && rightvt == VT_I8) || 8163 (rightvt == VT_EMPTY && leftvt != VT_NULL) || 8164 ExtraFlags[i] != 0) 8165 bFail = TRUE; 8166 8167 /* Determine variant type */ 8168 else if (leftvt == VT_NULL || rightvt == VT_NULL) 8169 resvt = VT_NULL; 8170 else if (leftvt == VT_I8 || rightvt == VT_I8) 8171 resvt = VT_I8; 8172 else if (leftvt == VT_I4 || rightvt == VT_I4 || 8173 leftvt == VT_INT || rightvt == VT_INT || 8174 leftvt == VT_UINT || rightvt == VT_UINT || 8175 leftvt == VT_UI8 || rightvt == VT_UI8 || 8176 leftvt == VT_UI4 || rightvt == VT_UI4 || 8177 leftvt == VT_UI2 || rightvt == VT_UI2 || 8178 leftvt == VT_I1 || rightvt == VT_I1 || 8179 leftvt == VT_BSTR || rightvt == VT_BSTR || 8180 leftvt == VT_DATE || rightvt == VT_DATE || 8181 leftvt == VT_CY || rightvt == VT_CY || 8182 leftvt == VT_DECIMAL || rightvt == VT_DECIMAL || 8183 leftvt == VT_R8 || rightvt == VT_R8 || 8184 leftvt == VT_R4 || rightvt == VT_R4) 8185 resvt = VT_I4; 8186 else if (leftvt == VT_I2 || rightvt == VT_I2 || 8187 leftvt == VT_BOOL || rightvt == VT_BOOL || 8188 leftvt == VT_EMPTY) 8189 resvt = VT_I2; 8190 else if (leftvt == VT_UI1 || rightvt == VT_UI1) 8191 resvt = VT_UI1; 8192 else 8193 bFail = TRUE; 8194 8195 hres = pVarIdiv(&left, &right, &result); 8196 8197 /* Check expected HRESULT and if result variant type is correct */ 8198 if (bFail) 8199 ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH || 8200 hres == DISP_E_DIVBYZERO, 8201 "VarIdiv: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n", 8202 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], 8203 vtstr(V_VT(&result)), hres); 8204 else 8205 ok (hres == S_OK && resvt == V_VT(&result), 8206 "VarIdiv: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n", 8207 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt), 8208 S_OK, vtstr(V_VT(&result)), hres); 8209 } 8210 } 8211 } 8212 8213 /* Test return values for all the good cases */ 8214 VARIDIV(EMPTY,0,NULL,0,NULL,0); 8215 VARIDIV(EMPTY,0,I2,1,I2,0); 8216 VARIDIV(EMPTY,0,I4,1,I4,0); 8217 VARIDIV(EMPTY,0,R4,1.0f,I4,0); 8218 VARIDIV(EMPTY,0,R8,1.0,I4,0); 8219 VARIDIV(EMPTY,0,DATE,1.0,I4,0); 8220 VARIDIV(EMPTY,0,BSTR,num1_str,I4,0); 8221 VARIDIV(EMPTY,0,BOOL,VARIANT_TRUE,I2,0); 8222 VARIDIV(EMPTY,0,I1,1,I4,0); 8223 VARIDIV(EMPTY,0,UI1,1,I2,0); 8224 VARIDIV(EMPTY,0,UI2,1,I4,0); 8225 VARIDIV(EMPTY,0,UI4,1,I4,0); 8226 if (has_i8) 8227 { 8228 VARIDIV(EMPTY,0,I8,1,I8,0); 8229 VARIDIV(EMPTY,0,UI8,1,I4,0); 8230 } 8231 VARIDIV(EMPTY,0,INT,1,I4,0); 8232 VARIDIV(EMPTY,0,UINT,1,I4,0); 8233 VARIDIV(NULL,0,EMPTY,0,NULL,0); 8234 VARIDIV(NULL,0,NULL,0,NULL,0); 8235 VARIDIV(NULL,0,I2,1,NULL,0); 8236 VARIDIV(NULL,0,I4,1,NULL,0); 8237 VARIDIV(NULL,0,R4,1,NULL,0); 8238 VARIDIV(NULL,0,R8,1,NULL,0); 8239 VARIDIV(NULL,0,DATE,1,NULL,0); 8240 VARIDIV(NULL,0,BSTR,num1_str,NULL,0); 8241 VARIDIV(NULL,0,BOOL,VARIANT_TRUE,NULL,0); 8242 VARIDIV(NULL,0,I1,1,NULL,0); 8243 VARIDIV(NULL,0,UI1,1,NULL,0); 8244 VARIDIV(NULL,0,UI2,1,NULL,0); 8245 VARIDIV(NULL,0,UI4,1,NULL,0); 8246 if (has_i8) 8247 { 8248 VARIDIV(NULL,0,I8,1,NULL,0); 8249 VARIDIV(NULL,0,UI8,1,NULL,0); 8250 } 8251 VARIDIV(NULL,0,INT,1,NULL,0); 8252 VARIDIV(NULL,0,UINT,1,NULL,0); 8253 VARIDIV(I2,2,NULL,0,NULL,0); 8254 VARIDIV(I2,2,I2,1,I2,2); 8255 VARIDIV(I2,2,I4,1,I4,2); 8256 VARIDIV(I2,2,R4,1,I4,2); 8257 VARIDIV(I2,2,R8,1,I4,2); 8258 VARIDIV(I2,2,DATE,1,I4,2); 8259 VARIDIV(I2,2,BSTR,num1_str,I4,2); 8260 VARIDIV(I2,2,BOOL,VARIANT_TRUE,I2,-2); 8261 VARIDIV(I2,2,I1,1,I4,2); 8262 VARIDIV(I2,2,UI1,1,I2,2); 8263 VARIDIV(I2,2,UI2,1,I4,2); 8264 VARIDIV(I2,2,UI4,1,I4,2); 8265 if (has_i8) 8266 { 8267 VARIDIV(I2,2,I8,1,I8,2); 8268 VARIDIV(I2,2,UI8,1,I4,2); 8269 } 8270 VARIDIV(I2,2,INT,1,I4,2); 8271 VARIDIV(I2,2,UINT,1,I4,2); 8272 VARIDIV(I4,2,NULL,0,NULL,0); 8273 VARIDIV(I4,2,I2,1,I4,2); 8274 VARIDIV(I4,2,I4,1,I4,2); 8275 VARIDIV(I4,2,R4,1,I4,2); 8276 VARIDIV(I4,2,R8,1,I4,2); 8277 VARIDIV(I4,2,DATE,1,I4,2); 8278 VARIDIV(I4,2,BSTR,num1_str,I4,2); 8279 VARIDIV(I4,2,BOOL,VARIANT_TRUE,I4,-2); 8280 VARIDIV(I4,2,I1,1,I4,2); 8281 VARIDIV(I4,2,UI1,1,I4,2); 8282 VARIDIV(I4,2,UI2,1,I4,2); 8283 VARIDIV(I4,2,UI4,1,I4,2); 8284 if (has_i8) 8285 { 8286 VARIDIV(I4,2,I8,1,I8,2); 8287 VARIDIV(I4,2,UI8,1,I4,2); 8288 } 8289 VARIDIV(I4,2,INT,1,I4,2); 8290 VARIDIV(I4,2,UINT,1,I4,2); 8291 VARIDIV(R4,2.0f,NULL,0,NULL,0); 8292 VARIDIV(R4,2.0f,I2,1,I4,2); 8293 VARIDIV(R4,2.0f,I4,1,I4,2); 8294 VARIDIV(R4,2.0f,R4,1.0f,I4,2); 8295 VARIDIV(R4,2.0f,R8,1.0,I4,2); 8296 VARIDIV(R4,2.0f,DATE,1,I4,2); 8297 VARIDIV(R4,2.0f,BSTR,num1_str,I4,2); 8298 VARIDIV(R4,2.0f,BOOL,VARIANT_TRUE,I4,-2); 8299 VARIDIV(R4,2.0f,I1,1,I4,2); 8300 VARIDIV(R4,2.0f,UI1,1,I4,2); 8301 VARIDIV(R4,2.0f,UI2,1,I4,2); 8302 VARIDIV(R4,2.0f,UI4,1,I4,2); 8303 if (has_i8) 8304 { 8305 VARIDIV(R4,2.0f,I8,1,I8,2); 8306 VARIDIV(R4,2.0f,UI8,1,I4,2); 8307 } 8308 VARIDIV(R4,2.0f,INT,1,I4,2); 8309 VARIDIV(R4,2.0f,UINT,1,I4,2); 8310 VARIDIV(R8,2.0,NULL,0,NULL,0); 8311 VARIDIV(R8,2.0,I2,1,I4,2); 8312 VARIDIV(R8,2.0,I4,1,I4,2); 8313 VARIDIV(R8,2.0,R4,1,I4,2); 8314 VARIDIV(R8,2.0,R8,1,I4,2); 8315 VARIDIV(R8,2.0,DATE,1,I4,2); 8316 VARIDIV(R8,2.0,BSTR,num1_str,I4,2); 8317 VARIDIV(R8,2.0,BOOL,VARIANT_TRUE,I4,-2); 8318 VARIDIV(R8,2.0,I1,1,I4,2); 8319 VARIDIV(R8,2.0,UI1,1,I4,2); 8320 VARIDIV(R8,2.0,UI2,1,I4,2); 8321 VARIDIV(R8,2.0,UI4,1,I4,2); 8322 if (has_i8) 8323 { 8324 VARIDIV(R8,2.0,I8,1,I8,2); 8325 VARIDIV(R8,2.0,UI8,1,I4,2); 8326 } 8327 VARIDIV(R8,2.0,INT,1,I4,2); 8328 VARIDIV(R8,2.0,UINT,1,I4,2); 8329 VARIDIV(DATE,2,NULL,0,NULL,0); 8330 VARIDIV(DATE,2,I2,1,I4,2); 8331 VARIDIV(DATE,2,I4,1,I4,2); 8332 VARIDIV(DATE,2,R4,1,I4,2); 8333 VARIDIV(DATE,2,R8,1,I4,2); 8334 VARIDIV(DATE,2,DATE,1,I4,2); 8335 VARIDIV(DATE,2,BSTR,num1_str,I4,2); 8336 VARIDIV(DATE,2,BOOL,VARIANT_TRUE,I4,-2); 8337 VARIDIV(DATE,2,I1,1,I4,2); 8338 VARIDIV(DATE,2,UI1,1,I4,2); 8339 VARIDIV(DATE,2,UI2,1,I4,2); 8340 VARIDIV(DATE,2,UI4,1,I4,2); 8341 if (has_i8) 8342 { 8343 VARIDIV(DATE,2,I8,1,I8,2); 8344 VARIDIV(DATE,2,UI8,1,I4,2); 8345 } 8346 VARIDIV(DATE,2,INT,1,I4,2); 8347 VARIDIV(DATE,2,UINT,1,I4,2); 8348 VARIDIV(BSTR,num2_str,NULL,0,NULL,0); 8349 VARIDIV(BSTR,num2_str,I2,1,I4,2); 8350 VARIDIV(BSTR,num2_str,I4,1,I4,2); 8351 VARIDIV(BSTR,num2_str,R4,1.0f,I4,2); 8352 VARIDIV(BSTR,num2_str,R8,1.0,I4,2); 8353 VARIDIV(BSTR,num2_str,DATE,1,I4,2); 8354 VARIDIV(BSTR,num2_str,BSTR,num1_str,I4,2); 8355 VARIDIV(BSTR,num2_str,BOOL,VARIANT_TRUE,I4,-2); 8356 VARIDIV(BSTR,num2_str,I1,1,I4,2); 8357 VARIDIV(BSTR,num2_str,UI1,1,I4,2); 8358 VARIDIV(BSTR,num2_str,UI2,1,I4,2); 8359 VARIDIV(BSTR,num2_str,UI4,1,I4,2); 8360 if (has_i8) 8361 { 8362 VARIDIV(BSTR,num2_str,I8,1,I8,2); 8363 VARIDIV(BSTR,num2_str,UI8,1,I4,2); 8364 } 8365 VARIDIV(BSTR,num2_str,INT,1,I4,2); 8366 VARIDIV(BSTR,num2_str,UINT,1,I4,2); 8367 VARIDIV(BOOL,VARIANT_TRUE,NULL,0,NULL,0); 8368 VARIDIV(BOOL,VARIANT_TRUE,I2,1,I2,-1); 8369 VARIDIV(BOOL,VARIANT_TRUE,I4,1,I4,-1); 8370 VARIDIV(BOOL,VARIANT_TRUE,R4,1.0f,I4,-1); 8371 VARIDIV(BOOL,VARIANT_TRUE,R8,1.0,I4,-1); 8372 VARIDIV(BOOL,VARIANT_TRUE,DATE,1,I4,-1); 8373 VARIDIV(BOOL,VARIANT_TRUE,BSTR,num1_str,I4,-1); 8374 VARIDIV(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,I2,1); 8375 VARIDIV(BOOL,VARIANT_TRUE,I1,1,I4,-1); 8376 VARIDIV(BOOL,VARIANT_TRUE,UI1,1,I2,-1); 8377 VARIDIV(BOOL,VARIANT_TRUE,UI2,1,I4,-1); 8378 VARIDIV(BOOL,VARIANT_TRUE,UI4,1,I4,-1); 8379 if (has_i8) 8380 { 8381 VARIDIV(BOOL,VARIANT_TRUE,I8,1,I8,-1); 8382 VARIDIV(BOOL,VARIANT_TRUE,UI8,1,I4,-1); 8383 } 8384 VARIDIV(BOOL,VARIANT_TRUE,INT,1,I4,-1); 8385 VARIDIV(BOOL,VARIANT_TRUE,UINT,1,I4,-1); 8386 VARIDIV(I1,2,NULL,0,NULL,0); 8387 VARIDIV(I1,2,I2,1,I4,2); 8388 VARIDIV(I1,2,I4,1,I4,2); 8389 VARIDIV(I1,2,R4,1.0f,I4,2); 8390 VARIDIV(I1,2,R8,1.0,I4,2); 8391 VARIDIV(I1,2,DATE,1,I4,2); 8392 VARIDIV(I1,2,BSTR,num1_str,I4,2); 8393 VARIDIV(I1,2,BOOL,VARIANT_TRUE,I4,-2); 8394 VARIDIV(I1,2,I1,1,I4,2); 8395 VARIDIV(I1,2,UI1,1,I4,2); 8396 VARIDIV(I1,2,UI2,1,I4,2); 8397 VARIDIV(I1,2,UI4,1,I4,2); 8398 if (has_i8) 8399 { 8400 VARIDIV(I1,2,I8,1,I8,2); 8401 VARIDIV(I1,2,UI8,1,I4,2); 8402 } 8403 VARIDIV(I1,2,INT,1,I4,2); 8404 VARIDIV(I1,2,UINT,1,I4,2); 8405 VARIDIV(UI1,2,NULL,0,NULL,0); 8406 VARIDIV(UI1,2,I2,1,I2,2); 8407 VARIDIV(UI1,2,I4,1,I4,2); 8408 VARIDIV(UI1,2,R4,1.0f,I4,2); 8409 VARIDIV(UI1,2,R8,1.0,I4,2); 8410 VARIDIV(UI1,2,DATE,1,I4,2); 8411 VARIDIV(UI1,2,BSTR,num1_str,I4,2); 8412 VARIDIV(UI1,2,BOOL,VARIANT_TRUE,I2,-2); 8413 VARIDIV(UI1,2,I1,1,I4,2); 8414 VARIDIV(UI1,2,UI1,1,UI1,2); 8415 VARIDIV(UI1,2,UI2,1,I4,2); 8416 VARIDIV(UI1,2,UI4,1,I4,2); 8417 if (has_i8) 8418 { 8419 VARIDIV(UI1,2,I8,1,I8,2); 8420 VARIDIV(UI1,2,UI8,1,I4,2); 8421 } 8422 VARIDIV(UI1,2,INT,1,I4,2); 8423 VARIDIV(UI1,2,UINT,1,I4,2); 8424 VARIDIV(UI2,2,NULL,0,NULL,0); 8425 VARIDIV(UI2,2,I2,1,I4,2); 8426 VARIDIV(UI2,2,I4,1,I4,2); 8427 VARIDIV(UI2,2,R4,1.0f,I4,2); 8428 VARIDIV(UI2,2,R8,1.0,I4,2); 8429 VARIDIV(UI2,2,DATE,1,I4,2); 8430 VARIDIV(UI2,2,BSTR,num1_str,I4,2); 8431 VARIDIV(UI2,2,BOOL,VARIANT_TRUE,I4,-2); 8432 VARIDIV(UI2,2,I1,1,I4,2); 8433 VARIDIV(UI2,2,UI1,1,I4,2); 8434 VARIDIV(UI2,2,UI2,1,I4,2); 8435 VARIDIV(UI2,2,UI4,1,I4,2); 8436 if (has_i8) 8437 { 8438 VARIDIV(UI2,2,I8,1,I8,2); 8439 VARIDIV(UI2,2,UI8,1,I4,2); 8440 } 8441 VARIDIV(UI2,2,INT,1,I4,2); 8442 VARIDIV(UI2,2,UINT,1,I4,2); 8443 VARIDIV(UI4,2,NULL,0,NULL,0); 8444 VARIDIV(UI4,2,I2,1,I4,2); 8445 VARIDIV(UI4,2,I4,1,I4,2); 8446 VARIDIV(UI4,2,R4,1.0f,I4,2); 8447 VARIDIV(UI4,2,R8,1.0,I4,2); 8448 VARIDIV(UI4,2,DATE,1,I4,2); 8449 VARIDIV(UI4,2,BSTR,num1_str,I4,2); 8450 VARIDIV(UI4,2,BOOL,VARIANT_TRUE,I4,-2); 8451 VARIDIV(UI4,2,I1,1,I4,2); 8452 VARIDIV(UI4,2,UI1,1,I4,2); 8453 VARIDIV(UI4,2,UI2,1,I4,2); 8454 VARIDIV(UI4,2,UI4,1,I4,2); 8455 if (has_i8) 8456 { 8457 VARIDIV(UI4,2,I8,1,I8,2); 8458 VARIDIV(UI4,2,UI8,1,I4,2); 8459 } 8460 VARIDIV(UI4,2,INT,1,I4,2); 8461 VARIDIV(UI4,2,UINT,1,I4,2); 8462 if (has_i8) 8463 { 8464 VARIDIV(I8,2,NULL,0,NULL,0); 8465 VARIDIV(I8,2,I2,1,I8,2); 8466 VARIDIV(I8,2,I4,1,I8,2); 8467 VARIDIV(I8,2,R4,1.0f,I8,2); 8468 VARIDIV(I8,2,R8,1.0,I8,2); 8469 VARIDIV(I8,2,DATE,1,I8,2); 8470 VARIDIV(I8,2,BSTR,num1_str,I8,2); 8471 VARIDIV(I8,2,BOOL,1,I8,2); 8472 VARIDIV(I8,2,I1,1,I8,2); 8473 VARIDIV(I8,2,UI1,1,I8,2); 8474 VARIDIV(I8,2,UI2,1,I8,2); 8475 VARIDIV(I8,2,UI4,1,I8,2); 8476 VARIDIV(I8,2,I8,1,I8,2); 8477 VARIDIV(I8,2,UI8,1,I8,2); 8478 VARIDIV(I8,2,UINT,1,I8,2); 8479 VARIDIV(UI8,2,NULL,0,NULL,0); 8480 VARIDIV(UI8,2,I2,1,I4,2); 8481 VARIDIV(UI8,2,I4,1,I4,2); 8482 VARIDIV(UI8,2,R4,1.0f,I4,2); 8483 VARIDIV(UI8,2,R8,1.0,I4,2); 8484 VARIDIV(UI8,2,DATE,1,I4,2); 8485 VARIDIV(UI8,2,BSTR,num1_str,I4,2); 8486 VARIDIV(UI8,2,BOOL,VARIANT_TRUE,I4,-2); 8487 VARIDIV(UI8,2,I1,1,I4,2); 8488 VARIDIV(UI8,2,UI1,1,I4,2); 8489 VARIDIV(UI8,2,UI2,1,I4,2); 8490 VARIDIV(UI8,2,UI4,1,I4,2); 8491 VARIDIV(UI8,2,I8,1,I8,2); 8492 VARIDIV(UI8,2,UI8,1,I4,2); 8493 VARIDIV(UI8,2,INT,1,I4,2); 8494 VARIDIV(UI8,2,UINT,1,I4,2); 8495 } 8496 VARIDIV(INT,2,NULL,0,NULL,0); 8497 VARIDIV(INT,2,I2,1,I4,2); 8498 VARIDIV(INT,2,I4,1,I4,2); 8499 VARIDIV(INT,2,R4,1.0f,I4,2); 8500 VARIDIV(INT,2,R8,1.0,I4,2); 8501 VARIDIV(INT,2,DATE,1,I4,2); 8502 VARIDIV(INT,2,BSTR,num1_str,I4,2); 8503 VARIDIV(INT,2,BOOL,VARIANT_TRUE,I4,-2); 8504 VARIDIV(INT,2,I1,1,I4,2); 8505 VARIDIV(INT,2,UI1,1,I4,2); 8506 VARIDIV(INT,2,UI2,1,I4,2); 8507 VARIDIV(INT,2,UI4,1,I4,2); 8508 if (has_i8) 8509 { 8510 VARIDIV(INT,2,UI8,1,I4,2); 8511 } 8512 VARIDIV(INT,2,INT,1,I4,2); 8513 VARIDIV(INT,2,UINT,1,I4,2); 8514 VARIDIV(UINT,2,NULL,0,NULL,0); 8515 VARIDIV(UINT,2,I2,1,I4,2); 8516 VARIDIV(UINT,2,I4,1,I4,2); 8517 VARIDIV(UINT,2,R4,1.0f,I4,2); 8518 VARIDIV(UINT,2,R8,1.0,I4,2); 8519 VARIDIV(UINT,2,DATE,1,I4,2); 8520 VARIDIV(UINT,2,BSTR,num1_str,I4,2); 8521 VARIDIV(UINT,2,BOOL,VARIANT_TRUE,I4,-2); 8522 VARIDIV(UINT,2,I1,1,I4,2); 8523 VARIDIV(UINT,2,UI1,1,I4,2); 8524 VARIDIV(UINT,2,UI2,1,I4,2); 8525 VARIDIV(UINT,2,UI4,1,I4,2); 8526 if (has_i8) 8527 { 8528 VARIDIV(UINT,2,I8,1,I8,2); 8529 VARIDIV(UINT,2,UI8,1,I4,2); 8530 } 8531 VARIDIV(UINT,2,INT,1,I4,2); 8532 VARIDIV(UINT,2,UINT,1,I4,2); 8533 8534 /* Manually test some VT_CY, VT_DECIMAL variants */ 8535 V_VT(&cy) = VT_CY; 8536 hres = VarCyFromI4(10000, &V_CY(&cy)); 8537 ok(hres == S_OK, "VarCyFromI4 failed!\n"); 8538 V_VT(&dec) = VT_DECIMAL; 8539 hres = VarDecFromR8(2.0, &V_DECIMAL(&dec)); 8540 ok(hres == S_OK, "VarDecFromR4 failed!\n"); 8541 memset(&left, 0, sizeof(left)); 8542 memset(&right, 0, sizeof(right)); 8543 V_VT(&left) = VT_I4; 8544 V_I4(&left) = 100; 8545 V_VT(&right) = VT_I8; 8546 V_UI1(&right) = 2; 8547 8548 hres = pVarIdiv(&cy, &cy, &result); 8549 ok(hres == S_OK && V_VT(&result) == VT_I4, 8550 "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n", 8551 S_OK, hres, vtstr(V_VT(&result))); 8552 ok(hres == S_OK && V_I4(&result) == 1, 8553 "VARIDIV: CY value %d, expected %d\n", V_I4(&result), 1); 8554 8555 if (has_i8) 8556 { 8557 hres = pVarIdiv(&cy, &right, &result); 8558 ok(hres == S_OK && V_VT(&result) == VT_I8, 8559 "VARIDIV: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n", 8560 S_OK, hres, vtstr(V_VT(&result))); 8561 ok(hres == S_OK && V_I8(&result) == 5000, 8562 "VARIDIV: CY value 0x%x%08x, expected 0x%x\n", 8563 (DWORD)(V_I8(&result) >>32), (DWORD)V_I8(&result), 5000); 8564 } 8565 8566 hres = pVarIdiv(&left, &cy, &result); 8567 ok(hres == S_OK && V_VT(&result) == VT_I4, 8568 "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n", 8569 S_OK, hres, vtstr(V_VT(&result))); 8570 ok(hres == S_OK && V_I4(&result) == 0, 8571 "VARIDIV: CY value %d, expected %d\n", V_I4(&result), 0); 8572 8573 hres = pVarIdiv(&left, &dec, &result); 8574 ok(hres == S_OK && V_VT(&result) == VT_I4, 8575 "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n", 8576 S_OK, hres, vtstr(V_VT(&result))); 8577 ok(hres == S_OK && V_I4(&result) == 50, 8578 "VARIDIV: DECIMAL value %d, expected %d\n", V_I4(&result), 50); 8579 8580 hres = pVarIdiv(&dec, &dec, &result); 8581 ok(hres == S_OK && V_VT(&result) == VT_I4, 8582 "VARIDIV: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n", 8583 S_OK, hres, vtstr(V_VT(&result))); 8584 ok(hres == S_OK && V_I4(&result) == 1, 8585 "VARIDIV: DECIMAL value %d, expected %d\n", V_I4(&result), 1); 8586 8587 if (has_i8) 8588 { 8589 hres = pVarIdiv(&dec, &right, &result); 8590 ok(hres == S_OK && V_VT(&result) == VT_I8, 8591 "VARIDIV: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n", 8592 S_OK, hres, vtstr(V_VT(&result))); 8593 ok(hres == S_OK && V_I8(&result) == 1, 8594 "VARIDIV: DECIMAL value 0x%x%08x, expected %d\n", 8595 (DWORD)(V_I8(&result) >> 32), (DWORD)V_I8(&result), 1); 8596 } 8597 8598 /* Check for division by zero */ 8599 V_VT(&left) = VT_INT; 8600 V_I4(&left) = 1; 8601 V_VT(&right) = VT_INT; 8602 V_I4(&right) = 0; 8603 hres = pVarIdiv(&left, &right, &result); 8604 ok(hres == DISP_E_DIVBYZERO && V_VT(&result) == VT_EMPTY, 8605 "VARIDIV: Division by 0 should result in DISP_E_DIVBYZERO but got 0x%X\n", hres); 8606 8607 V_VT(&left) = VT_INT; 8608 V_I4(&left) = 0; 8609 V_VT(&right) = VT_INT; 8610 V_I4(&right) = 0; 8611 hres = pVarIdiv(&left, &right, &result); 8612 ok(hres == DISP_E_DIVBYZERO && V_VT(&result) == VT_EMPTY, 8613 "VARIDIV: Division by 0 should result in DISP_E_DIVBYZERO but got 0x%X\n", hres); 8614 8615 SysFreeString(num1_str); 8616 SysFreeString(num2_str); 8617 } 8618 8619 8620 static HRESULT (WINAPI *pVarImp)(LPVARIANT,LPVARIANT,LPVARIANT); 8621 8622 #define VARIMP(vt1,val1,vt2,val2,rvt,rval) \ 8623 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \ 8624 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \ 8625 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \ 8626 test_var_call2( __LINE__, pVarImp, &left, &right, &exp ) 8627 8628 /* Skip any type that is not defined or produces an error for every case */ 8629 #define SKIPTESTIMP(a) \ 8630 if (a == VT_ERROR || a == VT_VARIANT || \ 8631 a == VT_DISPATCH || a == VT_UNKNOWN || \ 8632 a == VT_RECORD || a > VT_UINT || \ 8633 a == 15 /*not defined*/) \ 8634 continue 8635 8636 static void test_VarImp(void) 8637 { 8638 static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' }; 8639 static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' }; 8640 VARIANT left, right, exp, result, cy, dec; 8641 BSTR true_str, false_str; 8642 VARTYPE i; 8643 HRESULT hres; 8644 8645 CHECKPTR(VarImp); 8646 8647 true_str = SysAllocString(szTrue); 8648 false_str = SysAllocString(szFalse); 8649 8650 /* Test all possible flag/vt combinations & the resulting vt type */ 8651 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++) 8652 { 8653 VARTYPE leftvt, rightvt, resvt; 8654 8655 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++) 8656 { 8657 SKIPTESTIMP(leftvt); 8658 8659 /* Check if we need/have support for I8 and/or UI8 */ 8660 if ((leftvt == VT_I8 || leftvt == VT_UI8) && !has_i8) 8661 continue; 8662 8663 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++) 8664 { 8665 BOOL bFail = FALSE; 8666 SKIPTESTIMP(rightvt); 8667 8668 /* Native crashes when using the extra flag VT_BYREF 8669 * or with the following VT combinations 8670 */ 8671 if ((leftvt == VT_UI4 && rightvt == VT_BSTR) || 8672 (leftvt == VT_UI8 && rightvt == VT_BSTR) || 8673 ExtraFlags[i] == VT_BYREF) 8674 continue; 8675 8676 /* Check if we need/have support for I8 and/or UI8 */ 8677 if ((rightvt == VT_I8 || rightvt == VT_UI8) && !has_i8) 8678 continue; 8679 8680 memset(&left, 0, sizeof(left)); 8681 memset(&right, 0, sizeof(right)); 8682 V_VT(&left) = leftvt | ExtraFlags[i]; 8683 V_VT(&right) = rightvt | ExtraFlags[i]; 8684 V_VT(&result) = VT_EMPTY; 8685 resvt = VT_EMPTY; 8686 8687 if (leftvt == VT_BSTR) 8688 V_BSTR(&left) = true_str; 8689 8690 /* This allows us to test return types that are not NULL 8691 * (NULL Imp value = n, NULL Imp 0 = NULL) 8692 */ 8693 switch(rightvt) 8694 { 8695 case VT_BSTR: 8696 V_BSTR(&right) = true_str; 8697 break; 8698 case VT_DECIMAL: 8699 VarDecFromR8(2.0, &V_DECIMAL(&right)); 8700 V_VT(&right) = rightvt | ExtraFlags[i]; 8701 break; 8702 case VT_BOOL: 8703 V_BOOL(&right) = VARIANT_TRUE; 8704 break; 8705 case VT_I1: V_I1(&right) = 2; break; 8706 case VT_I2: V_I2(&right) = 2; break; 8707 case VT_I4: V_I4(&right) = 2; break; 8708 case VT_R4: V_R4(&right) = 2.0f; break; 8709 case VT_R8: V_R8(&right) = 2.0; break; 8710 case VT_CY: V_CY(&right).int64 = 10000; break; 8711 case VT_DATE: V_DATE(&right) = 2; break; 8712 case VT_I8: V_I8(&right) = 2; break; 8713 case VT_INT: V_INT(&right) = 2; break; 8714 case VT_UINT: V_UINT(&right) = 2; break; 8715 case VT_UI1: V_UI1(&right) = 2; break; 8716 case VT_UI2: V_UI2(&right) = 2; break; 8717 case VT_UI4: V_UI4(&right) = 2; break; 8718 case VT_UI8: V_UI8(&right) = 2; break; 8719 default: break; 8720 } 8721 8722 /* Native VarImp always returns an error when using extra 8723 * flags or if the variants are I8 and INT. 8724 */ 8725 if ((leftvt == VT_I8 && rightvt == VT_INT) || 8726 ExtraFlags[i] != 0) 8727 bFail = TRUE; 8728 8729 /* Determine result type */ 8730 else if ((leftvt == VT_BSTR && rightvt == VT_NULL) || 8731 (leftvt == VT_NULL && rightvt == VT_NULL) || 8732 (leftvt == VT_NULL && rightvt == VT_EMPTY)) 8733 resvt = VT_NULL; 8734 else if (leftvt == VT_I8 || rightvt == VT_I8) 8735 resvt = VT_I8; 8736 else if (leftvt == VT_I4 || rightvt == VT_I4 || 8737 leftvt == VT_INT || rightvt == VT_INT || 8738 leftvt == VT_UINT || rightvt == VT_UINT || 8739 leftvt == VT_UI4 || rightvt == VT_UI4 || 8740 leftvt == VT_UI8 || rightvt == VT_UI8 || 8741 leftvt == VT_UI2 || rightvt == VT_UI2 || 8742 leftvt == VT_DECIMAL || rightvt == VT_DECIMAL || 8743 leftvt == VT_DATE || rightvt == VT_DATE || 8744 leftvt == VT_CY || rightvt == VT_CY || 8745 leftvt == VT_R8 || rightvt == VT_R8 || 8746 leftvt == VT_R4 || rightvt == VT_R4 || 8747 leftvt == VT_I1 || rightvt == VT_I1) 8748 resvt = VT_I4; 8749 else if ((leftvt == VT_UI1 && rightvt == VT_UI1) || 8750 (leftvt == VT_UI1 && rightvt == VT_NULL) || 8751 (leftvt == VT_NULL && rightvt == VT_UI1)) 8752 resvt = VT_UI1; 8753 else if (leftvt == VT_EMPTY || rightvt == VT_EMPTY || 8754 leftvt == VT_I2 || rightvt == VT_I2 || 8755 leftvt == VT_UI1 || rightvt == VT_UI1) 8756 resvt = VT_I2; 8757 else if (leftvt == VT_BOOL || rightvt == VT_BOOL || 8758 leftvt == VT_BSTR || rightvt == VT_BSTR) 8759 resvt = VT_BOOL; 8760 8761 hres = pVarImp(&left, &right, &result); 8762 8763 /* Check expected HRESULT and if result variant type is correct */ 8764 if (bFail) 8765 ok (hres == DISP_E_BADVARTYPE || hres == DISP_E_TYPEMISMATCH, 8766 "VarImp: %s|0x%X, %s|0x%X: got vt %s hr 0x%X\n", 8767 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], 8768 vtstr(V_VT(&result)), hres); 8769 else 8770 ok (hres == S_OK && resvt == V_VT(&result), 8771 "VarImp: %s|0x%X, %s|0x%X: expected vt %s hr 0x%X, got vt %s hr 0x%X\n", 8772 vtstr(leftvt), ExtraFlags[i], vtstr(rightvt), ExtraFlags[i], vtstr(resvt), 8773 S_OK, vtstr(V_VT(&result)), hres); 8774 } 8775 } 8776 } 8777 8778 VARIMP(EMPTY,0,EMPTY,0,I2,-1); 8779 VARIMP(EMPTY,0,NULL,0,I2,-1); 8780 VARIMP(EMPTY,0,I2,-1,I2,-1); 8781 VARIMP(EMPTY,0,I4,-1,I4,-1); 8782 VARIMP(EMPTY,0,R4,0.0f,I4,-1); 8783 VARIMP(EMPTY,0,R8,-1.0,I4,-1); 8784 VARIMP(EMPTY,0,DATE,0,I4,-1); 8785 VARIMP(EMPTY,0,BSTR,true_str,I2,-1); 8786 VARIMP(EMPTY,0,BOOL,VARIANT_FALSE,I2,-1); 8787 VARIMP(EMPTY,0,I1,0,I4,-1); 8788 VARIMP(EMPTY,0,UI1,1,I2,-1); 8789 VARIMP(EMPTY,0,UI2,1,I4,-1); 8790 VARIMP(EMPTY,0,UI4,1,I4,-1); 8791 if (has_i8) 8792 { 8793 VARIMP(EMPTY,0,I8,1,I8,-1); 8794 VARIMP(EMPTY,0,UI8,1,I4,-1); 8795 } 8796 VARIMP(EMPTY,0,INT,-1,I4,-1); 8797 VARIMP(EMPTY,0,UINT,1,I4,-1); 8798 VARIMP(NULL,0,EMPTY,0,NULL,0); 8799 VARIMP(NULL,0,NULL,0,NULL,0); 8800 VARIMP(NULL,0,I2,-1,I2,-1); 8801 VARIMP(NULL,0,I4,-1,I4,-1); 8802 VARIMP(NULL,0,R4,0.0f,NULL,0); 8803 VARIMP(NULL,0,R8,-1.0,I4,-1); 8804 VARIMP(NULL,0,DATE,0,NULL,0); 8805 VARIMP(NULL,0,BSTR,true_str,BOOL,-1); 8806 VARIMP(NULL,0,BOOL,VARIANT_FALSE,NULL,0); 8807 VARIMP(NULL,0,I1,0,NULL,0); 8808 VARIMP(NULL,0,UI1,1,UI1,1); 8809 VARIMP(NULL,0,UI2,1,I4,1); 8810 VARIMP(NULL,0,UI4,1,I4,1); 8811 if (has_i8) 8812 { 8813 VARIMP(NULL,0,I8,1,I8,1); 8814 VARIMP(NULL,0,UI8,1,I4,1); 8815 } 8816 VARIMP(NULL,0,INT,-1,I4,-1); 8817 VARIMP(NULL,0,UINT,1,I4,1); 8818 VARIMP(I2,-1,EMPTY,0,I2,0); 8819 VARIMP(I2,-1,I2,-1,I2,-1); 8820 VARIMP(I2,-1,I4,-1,I4,-1); 8821 VARIMP(I2,-1,R4,0.0f,I4,0); 8822 VARIMP(I2,-1,R8,-1.0,I4,-1); 8823 VARIMP(I2,-1,DATE,0,I4,0); 8824 VARIMP(I2,-1,BSTR,true_str,I2,-1); 8825 VARIMP(I2,-1,BOOL,VARIANT_FALSE,I2,0); 8826 VARIMP(I2,-1,I1,0,I4,0); 8827 VARIMP(I2,-1,UI1,1,I2,1); 8828 VARIMP(I2,-1,UI2,1,I4,1); 8829 VARIMP(I2,-1,UI4,1,I4,1); 8830 if (has_i8) 8831 { 8832 VARIMP(I2,-1,I8,1,I8,1); 8833 VARIMP(I2,-1,UI8,1,I4,1); 8834 } 8835 VARIMP(I2,-1,INT,-1,I4,-1); 8836 VARIMP(I2,-1,UINT,1,I4,1); 8837 VARIMP(I4,2,EMPTY,0,I4,-3); 8838 VARIMP(I4,2,NULL,0,I4,-3); 8839 VARIMP(I4,2,I2,-1,I4,-1); 8840 VARIMP(I4,2,I4,-1,I4,-1); 8841 VARIMP(I4,2,R4,0.0f,I4,-3); 8842 VARIMP(I4,2,R8,-1.0,I4,-1); 8843 VARIMP(I4,2,DATE,0,I4,-3); 8844 VARIMP(I4,2,BSTR,true_str,I4,-1); 8845 VARIMP(I4,2,BOOL,VARIANT_FALSE,I4,-3); 8846 VARIMP(I4,2,I1,0,I4,-3); 8847 VARIMP(I4,2,UI1,1,I4,-3); 8848 VARIMP(I4,2,UI2,1,I4,-3); 8849 VARIMP(I4,2,UI4,1,I4,-3); 8850 if (has_i8) 8851 { 8852 VARIMP(I4,2,I8,1,I8,-3); 8853 VARIMP(I4,2,UI8,1,I4,-3); 8854 } 8855 VARIMP(I4,2,INT,-1,I4,-1); 8856 VARIMP(I4,2,UINT,1,I4,-3); 8857 VARIMP(R4,-1.0f,EMPTY,0,I4,0); 8858 VARIMP(R4,-1.0f,NULL,0,NULL,0); 8859 VARIMP(R4,-1.0f,I2,-1,I4,-1); 8860 VARIMP(R4,-1.0f,I4,-1,I4,-1); 8861 VARIMP(R4,-1.0f,R4,0.0f,I4,0); 8862 VARIMP(R4,-1.0f,R8,-1.0,I4,-1); 8863 VARIMP(R4,-1.0f,DATE,1,I4,1); 8864 VARIMP(R4,-1.0f,BSTR,true_str,I4,-1); 8865 VARIMP(R4,-1.0f,BOOL,VARIANT_FALSE,I4,0); 8866 VARIMP(R4,-1.0f,I1,0,I4,0); 8867 VARIMP(R4,-1.0f,UI1,1,I4,1); 8868 VARIMP(R4,-1.0f,UI2,1,I4,1); 8869 VARIMP(R4,-1.0f,UI4,1,I4,1); 8870 if (has_i8) 8871 { 8872 VARIMP(R4,-1.0f,I8,1,I8,1); 8873 VARIMP(R4,-1.0f,UI8,1,I4,1); 8874 } 8875 VARIMP(R4,-1.0f,INT,-1,I4,-1); 8876 VARIMP(R4,-1.0f,UINT,1,I4,1); 8877 VARIMP(R8,1.0,EMPTY,0,I4,-2); 8878 VARIMP(R8,1.0,NULL,0,I4,-2); 8879 VARIMP(R8,1.0,I2,-1,I4,-1); 8880 VARIMP(R8,1.0,I4,-1,I4,-1); 8881 VARIMP(R8,1.0,R4,0.0f,I4,-2); 8882 VARIMP(R8,1.0,R8,-1.0,I4,-1); 8883 VARIMP(R8,1.0,DATE,0,I4,-2); 8884 VARIMP(R8,1.0,BSTR,true_str,I4,-1); 8885 VARIMP(R8,1.0,BOOL,VARIANT_FALSE,I4,-2); 8886 VARIMP(R8,1.0,I1,0,I4,-2); 8887 VARIMP(R8,1.0,UI1,1,I4,-1); 8888 VARIMP(R8,1.0,UI2,1,I4,-1); 8889 VARIMP(R8,1.0,UI4,1,I4,-1); 8890 if (has_i8) 8891 { 8892 VARIMP(R8,1.0,I8,1,I8,-1); 8893 VARIMP(R8,1.0,UI8,1,I4,-1); 8894 } 8895 VARIMP(R8,1.0,INT,-1,I4,-1); 8896 VARIMP(R8,1.0,UINT,1,I4,-1); 8897 VARIMP(DATE,0,EMPTY,0,I4,-1); 8898 VARIMP(DATE,0,NULL,0,I4,-1); 8899 VARIMP(DATE,0,I2,-1,I4,-1); 8900 VARIMP(DATE,0,I4,-1,I4,-1); 8901 VARIMP(DATE,0,R4,0.0f,I4,-1); 8902 VARIMP(DATE,0,R8,-1.0,I4,-1); 8903 VARIMP(DATE,0,DATE,0,I4,-1); 8904 VARIMP(DATE,0,BSTR,true_str,I4,-1); 8905 VARIMP(DATE,0,BOOL,VARIANT_FALSE,I4,-1); 8906 VARIMP(DATE,0,I1,0,I4,-1); 8907 VARIMP(DATE,0,UI1,1,I4,-1); 8908 VARIMP(DATE,0,UI2,1,I4,-1); 8909 VARIMP(DATE,0,UI4,1,I4,-1); 8910 if (has_i8) 8911 { 8912 VARIMP(DATE,0,I8,1,I8,-1); 8913 VARIMP(DATE,0,UI8,1,I4,-1); 8914 } 8915 VARIMP(DATE,0,INT,-1,I4,-1); 8916 VARIMP(DATE,0,UINT,1,I4,-1); 8917 VARIMP(BSTR,false_str,EMPTY,0,I2,-1); 8918 VARIMP(BSTR,false_str,NULL,0,BOOL,-1); 8919 VARIMP(BSTR,false_str,I2,-1,I2,-1); 8920 VARIMP(BSTR,false_str,I4,-1,I4,-1); 8921 VARIMP(BSTR,false_str,R4,0.0f,I4,-1); 8922 VARIMP(BSTR,false_str,R8,-1.0,I4,-1); 8923 VARIMP(BSTR,false_str,DATE,0,I4,-1); 8924 VARIMP(BSTR,false_str,BSTR,true_str,BOOL,-1); 8925 VARIMP(BSTR,false_str,BOOL,VARIANT_FALSE,BOOL,-1); 8926 VARIMP(BSTR,false_str,I1,0,I4,-1); 8927 VARIMP(BSTR,false_str,UI1,1,I2,-1); 8928 VARIMP(BSTR,false_str,UI2,1,I4,-1); 8929 VARIMP(BSTR,false_str,UI4,1,I4,-1); 8930 if (has_i8) 8931 { 8932 VARIMP(BSTR,false_str,I8,1,I8,-1); 8933 VARIMP(BSTR,false_str,UI8,1,I4,-1); 8934 } 8935 VARIMP(BSTR,false_str,INT,-1,I4,-1); 8936 VARIMP(BSTR,false_str,UINT,1,I4,-1); 8937 VARIMP(BOOL,VARIANT_TRUE,EMPTY,0,I2,0); 8938 VARIMP(BOOL,VARIANT_TRUE,NULL,0,NULL,0); 8939 VARIMP(BOOL,VARIANT_TRUE,I2,-1,I2,-1); 8940 VARIMP(BOOL,VARIANT_TRUE,I4,-1,I4,-1); 8941 VARIMP(BOOL,VARIANT_TRUE,R4,0.0f,I4,0); 8942 VARIMP(BOOL,VARIANT_TRUE,R8,-1.0,I4,-1); 8943 VARIMP(BOOL,VARIANT_TRUE,DATE,0,I4,0); 8944 VARIMP(BOOL,VARIANT_TRUE,BSTR,true_str,BOOL,-1); 8945 VARIMP(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,0); 8946 VARIMP(BOOL,VARIANT_TRUE,I1,0,I4,0); 8947 VARIMP(BOOL,VARIANT_TRUE,UI1,1,I2,1); 8948 VARIMP(BOOL,VARIANT_TRUE,UI2,1,I4,1); 8949 VARIMP(BOOL,VARIANT_TRUE,UI4,1,I4,1); 8950 if (has_i8) 8951 { 8952 VARIMP(BOOL,VARIANT_TRUE,I8,1,I8,1); 8953 VARIMP(BOOL,VARIANT_TRUE,UI8,1,I4,1); 8954 } 8955 VARIMP(BOOL,VARIANT_TRUE,INT,-1,I4,-1); 8956 VARIMP(BOOL,VARIANT_TRUE,UINT,1,I4,1); 8957 VARIMP(I1,-1,EMPTY,0,I4,0); 8958 VARIMP(I1,-1,NULL,0,NULL,0); 8959 VARIMP(I1,-1,I2,-1,I4,-1); 8960 VARIMP(I1,-1,I4,-1,I4,-1); 8961 VARIMP(I1,-1,R4,0.0f,I4,0); 8962 VARIMP(I1,-1,R8,-1.0,I4,-1); 8963 VARIMP(I1,-1,DATE,0,I4,0); 8964 VARIMP(I1,-1,BSTR,true_str,I4,-1); 8965 VARIMP(I1,-1,BOOL,VARIANT_FALSE,I4,0); 8966 VARIMP(I1,-1,I1,0,I4,0); 8967 VARIMP(I1,-1,UI1,1,I4,1); 8968 VARIMP(I1,-1,UI2,1,I4,1); 8969 VARIMP(I1,-1,UI4,1,I4,1); 8970 if (has_i8) 8971 { 8972 VARIMP(I1,-1,I8,1,I8,1); 8973 VARIMP(I1,-1,UI8,1,I4,1); 8974 } 8975 VARIMP(I1,-1,INT,-1,I4,-1); 8976 VARIMP(I1,-1,UINT,1,I4,1); 8977 VARIMP(UI1,0,EMPTY,0,I2,-1); 8978 VARIMP(UI1,0,NULL,0,UI1,255); 8979 VARIMP(UI1,0,I2,-1,I2,-1); 8980 VARIMP(UI1,0,I4,-1,I4,-1); 8981 VARIMP(UI1,0,R4,0.0f,I4,-1); 8982 VARIMP(UI1,0,R8,-1.0,I4,-1); 8983 VARIMP(UI1,0,DATE,0,I4,-1); 8984 VARIMP(UI1,0,BSTR,true_str,I2,-1); 8985 VARIMP(UI1,0,BOOL,VARIANT_FALSE,I2,-1); 8986 VARIMP(UI1,0,I1,0,I4,-1); 8987 VARIMP(UI1,0,UI1,1,UI1,255); 8988 VARIMP(UI1,0,UI2,1,I4,-1); 8989 VARIMP(UI1,0,UI4,1,I4,-1); 8990 if (has_i8) 8991 { 8992 VARIMP(UI1,0,I8,1,I8,-1); 8993 VARIMP(UI1,0,UI8,1,I4,-1); 8994 } 8995 VARIMP(UI1,0,INT,-1,I4,-1); 8996 VARIMP(UI1,0,UINT,1,I4,-1); 8997 VARIMP(UI2,0,EMPTY,0,I4,-1); 8998 VARIMP(UI2,0,NULL,0,I4,-1); 8999 VARIMP(UI2,0,I2,-1,I4,-1); 9000 VARIMP(UI2,0,I4,-1,I4,-1); 9001 VARIMP(UI2,0,R4,0.0f,I4,-1); 9002 VARIMP(UI2,0,R8,-1.0,I4,-1); 9003 VARIMP(UI2,0,DATE,0,I4,-1); 9004 VARIMP(UI2,0,BSTR,true_str,I4,-1); 9005 VARIMP(UI2,0,BOOL,VARIANT_FALSE,I4,-1); 9006 VARIMP(UI2,0,I1,0,I4,-1); 9007 VARIMP(UI2,0,UI1,1,I4,-1); 9008 VARIMP(UI2,0,UI2,1,I4,-1); 9009 VARIMP(UI2,0,UI4,1,I4,-1); 9010 if (has_i8) 9011 { 9012 VARIMP(UI2,0,I8,1,I8,-1); 9013 VARIMP(UI2,0,UI8,1,I4,-1); 9014 } 9015 VARIMP(UI2,0,INT,-1,I4,-1); 9016 VARIMP(UI2,0,UINT,1,I4,-1); 9017 VARIMP(UI4,0,EMPTY,0,I4,-1); 9018 VARIMP(UI4,0,NULL,0,I4,-1); 9019 VARIMP(UI4,0,I2,-1,I4,-1); 9020 VARIMP(UI4,0,I4,-1,I4,-1); 9021 VARIMP(UI4,0,R4,0.0f,I4,-1); 9022 VARIMP(UI4,0,R8,-1.0,I4,-1); 9023 VARIMP(UI4,0,DATE,0,I4,-1); 9024 VARIMP(UI4,0,BSTR,true_str,I4,-1); 9025 VARIMP(UI4,0,BOOL,VARIANT_FALSE,I4,-1); 9026 VARIMP(UI4,0,I1,0,I4,-1); 9027 VARIMP(UI4,0,UI1,1,I4,-1); 9028 VARIMP(UI4,0,UI2,1,I4,-1); 9029 VARIMP(UI4,0,UI4,1,I4,-1); 9030 if (has_i8) 9031 { 9032 VARIMP(UI4,0,I8,1,I8,-1); 9033 VARIMP(UI4,0,UI8,1,I4,-1); 9034 } 9035 VARIMP(UI4,0,INT,-1,I4,-1); 9036 VARIMP(UI4,0,UINT,1,I4,-1); 9037 if (has_i8) 9038 { 9039 VARIMP(I8,-1,EMPTY,0,I8,0); 9040 VARIMP(I8,-1,NULL,0,NULL,0); 9041 VARIMP(I8,-1,I2,-1,I8,-1); 9042 VARIMP(I8,-1,I4,-1,I8,-1); 9043 VARIMP(I8,-1,R4,0.0f,I8,0); 9044 VARIMP(I8,-1,R8,-1.0,I8,-1); 9045 VARIMP(I8,-1,DATE,0,I8,0); 9046 VARIMP(I8,-1,BSTR,true_str,I8,-1); 9047 VARIMP(I8,-1,BOOL,VARIANT_FALSE,I8,0); 9048 VARIMP(I8,-1,I1,0,I8,0); 9049 VARIMP(I8,-1,UI1,1,I8,1); 9050 VARIMP(I8,-1,UI2,1,I8,1); 9051 VARIMP(I8,-1,UI4,1,I8,1); 9052 VARIMP(I8,-1,I8,1,I8,1); 9053 VARIMP(I8,-1,UI8,1,I8,1); 9054 VARIMP(I8,-1,UINT,1,I8,1); 9055 VARIMP(UI8,0,EMPTY,0,I4,-1); 9056 VARIMP(UI8,0,NULL,0,I4,-1); 9057 VARIMP(UI8,0,I2,-1,I4,-1); 9058 VARIMP(UI8,0,I4,-1,I4,-1); 9059 VARIMP(UI8,0,R4,0.0f,I4,-1); 9060 VARIMP(UI8,0,R8,-1.0,I4,-1); 9061 VARIMP(UI8,0,DATE,0,I4,-1); 9062 VARIMP(UI8,0,BSTR,true_str,I4,-1); 9063 VARIMP(UI8,0,BOOL,VARIANT_FALSE,I4,-1); 9064 VARIMP(UI8,0,I1,0,I4,-1); 9065 VARIMP(UI8,0,UI1,1,I4,-1); 9066 VARIMP(UI8,0,UI2,1,I4,-1); 9067 VARIMP(UI8,0,UI4,1,I4,-1); 9068 VARIMP(UI8,0,I8,1,I8,-1); 9069 VARIMP(UI8,0,UI8,1,I4,-1); 9070 VARIMP(UI8,0,INT,-1,I4,-1); 9071 VARIMP(UI8,0,UINT,1,I4,-1); 9072 } 9073 VARIMP(INT,-1,EMPTY,0,I4,0); 9074 VARIMP(INT,-1,NULL,0,NULL,0); 9075 VARIMP(INT,-1,I2,-1,I4,-1); 9076 VARIMP(INT,-1,I4,-1,I4,-1); 9077 VARIMP(INT,-1,R4,0.0f,I4,0); 9078 VARIMP(INT,-1,R8,-1.0,I4,-1); 9079 VARIMP(INT,-1,DATE,0,I4,0); 9080 VARIMP(INT,-1,BSTR,true_str,I4,-1); 9081 VARIMP(INT,-1,BOOL,VARIANT_FALSE,I4,0); 9082 VARIMP(INT,-1,I1,0,I4,0); 9083 VARIMP(INT,-1,UI1,1,I4,1); 9084 VARIMP(INT,-1,UI2,1,I4,1); 9085 VARIMP(INT,-1,UI4,1,I4,1); 9086 if (has_i8) 9087 { 9088 VARIMP(INT,-1,I8,1,I8,1); 9089 VARIMP(INT,-1,UI8,1,I4,1); 9090 } 9091 VARIMP(INT,-1,INT,-1,I4,-1); 9092 VARIMP(INT,-1,UINT,1,I4,1); 9093 VARIMP(UINT,1,EMPTY,0,I4,-2); 9094 VARIMP(UINT,1,NULL,0,I4,-2); 9095 VARIMP(UINT,1,I2,-1,I4,-1); 9096 VARIMP(UINT,1,I4,-1,I4,-1); 9097 VARIMP(UINT,1,R4,0.0f,I4,-2); 9098 VARIMP(UINT,1,R8,-1.0,I4,-1); 9099 VARIMP(UINT,1,DATE,0,I4,-2); 9100 VARIMP(UINT,1,BSTR,true_str,I4,-1); 9101 VARIMP(UINT,1,BOOL,VARIANT_FALSE,I4,-2); 9102 VARIMP(UINT,1,I1,0,I4,-2); 9103 VARIMP(UINT,1,UI1,1,I4,-1); 9104 VARIMP(UINT,1,UI2,1,I4,-1); 9105 VARIMP(UINT,1,UI4,1,I4,-1); 9106 if (has_i8) 9107 { 9108 VARIMP(UINT,1,I8,1,I8,-1); 9109 VARIMP(UINT,1,UI8,1,I4,-1); 9110 } 9111 VARIMP(UINT,1,INT,-1,I4,-1); 9112 VARIMP(UINT,1,UINT,1,I4,-1); 9113 9114 /* Manually test some VT_CY, VT_DECIMAL variants */ 9115 V_VT(&cy) = VT_CY; 9116 hres = VarCyFromI4(1, &V_CY(&cy)); 9117 ok(hres == S_OK, "VarCyFromI4 failed!\n"); 9118 V_VT(&dec) = VT_DECIMAL; 9119 hres = VarDecFromR8(2.0, &V_DECIMAL(&dec)); 9120 ok(hres == S_OK, "VarDecFromR4 failed!\n"); 9121 memset(&left, 0, sizeof(left)); 9122 memset(&right, 0, sizeof(right)); 9123 V_VT(&left) = VT_I4; 9124 V_I4(&left) = 0; 9125 V_VT(&right) = VT_I8; 9126 V_UI1(&right) = 0; 9127 9128 hres = pVarImp(&cy, &cy, &result); 9129 ok(hres == S_OK && V_VT(&result) == VT_I4, 9130 "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n", 9131 S_OK, hres, vtstr(V_VT(&result))); 9132 ok(hres == S_OK && V_I4(&result) == -1, 9133 "VARIMP: CY value %d, expected %d\n", V_I4(&result), -1); 9134 9135 if (has_i8) 9136 { 9137 hres = pVarImp(&cy, &right, &result); 9138 ok(hres == S_OK && V_VT(&result) == VT_I8, 9139 "VARIMP: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n", 9140 S_OK, hres, vtstr(V_VT(&result))); 9141 ok(hres == S_OK && V_I8(&result) == -2, 9142 "VARIMP: CY value %x%08x, expected %d\n", 9143 (DWORD)((V_I8(&result)) >> 32), (DWORD)(V_I8(&result)), -2); 9144 } 9145 9146 hres = pVarImp(&left, &cy, &result); 9147 ok(hres == S_OK && V_VT(&result) == VT_I4, 9148 "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n", 9149 S_OK, hres, vtstr(V_VT(&result))); 9150 ok(hres == S_OK && V_I4(&result) == -1, 9151 "VARIMP: CY value %d, expected %d\n", V_I4(&result), -1); 9152 9153 hres = pVarImp(&left, &dec, &result); 9154 ok(hres == S_OK && V_VT(&result) == VT_I4, 9155 "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n", 9156 S_OK, hres, vtstr(V_VT(&result))); 9157 ok(hres == S_OK && V_I4(&result) == -1, 9158 "VARIMP: DECIMAL value %d, expected %d\n", V_I4(&result), -1); 9159 9160 hres = pVarImp(&dec, &dec, &result); 9161 ok(hres == S_OK && V_VT(&result) == VT_I4, 9162 "VARIMP: expected coerced hres 0x%X type VT_I4, got hres 0x%X type %s!\n", 9163 S_OK, hres, vtstr(V_VT(&result))); 9164 ok(hres == S_OK && V_I4(&result) == -1, 9165 "VARIMP: DECIMAL value %d, expected %d\n", V_I4(&result), -1); 9166 9167 if (has_i8) 9168 { 9169 hres = pVarImp(&dec, &right, &result); 9170 ok(hres == S_OK && V_VT(&result) == VT_I8, 9171 "VARIMP: expected coerced hres 0x%X type VT_I8, got hres 0x%X type %s!\n", 9172 S_OK, hres, vtstr(V_VT(&result))); 9173 ok(hres == S_OK && V_I8(&result) == -3, 9174 "VARIMP: DECIMAL value 0x%x%08x, expected %d\n", 9175 (DWORD)(V_I8(&result) >>32), (DWORD)V_I8(&result), -3); 9176 } 9177 9178 SysFreeString(false_str); 9179 SysFreeString(true_str); 9180 } 9181 9182 START_TEST(vartest) 9183 { 9184 init(); 9185 9186 test_VariantInit(); 9187 test_VariantClear(); 9188 test_VariantCopy(); 9189 test_VariantCopyInd(); 9190 test_VarParseNumFromStr(); 9191 test_VarNumFromParseNum(); 9192 test_VarUdateFromDate(); 9193 test_VarDateFromUdate(); 9194 test_SystemTimeToVariantTime(); 9195 test_VariantTimeToSystemTime(); 9196 test_DosDateTimeToVariantTime(); 9197 test_VariantTimeToDosDateTime(); 9198 test_VarAbs(); 9199 test_VarNot(); 9200 test_VarSub(); 9201 test_VarMod(); 9202 test_VarFix(); 9203 test_VarInt(); 9204 test_VarNeg(); 9205 test_VarRound(); 9206 test_VarXor(); 9207 test_VarOr(); 9208 test_VarPow(); 9209 test_VarEqv(); 9210 test_VarMul(); 9211 test_VarAdd(); 9212 test_VarCmp(); /* Before test_VarCat() which needs VarCmp() */ 9213 test_VarCat(); 9214 test_VarAnd(); 9215 test_VarDiv(); 9216 test_VarIdiv(); 9217 test_VarImp(); 9218 } 9219