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