Release 20050930.
[wine/gsoc-2012-control.git] / dlls / oleaut32 / tests / vartest.c
blob1786173917e858e8abb35f24968db1e1ad3296ae
1 /*
2 * VARIANT test program
4 * Copyright 1998 Jean-Claude Cote
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <math.h>
24 #include <float.h>
25 #include <time.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winsock.h"
30 #include "wine/test.h"
31 #include "winuser.h"
32 #include "wingdi.h"
33 #include "winnls.h"
34 #include "winerror.h"
35 #include "winnt.h"
37 #include "wtypes.h"
38 #include "oleauto.h"
40 static HMODULE hOleaut32;
42 static HRESULT (WINAPI *pVarUdateFromDate)(DATE,ULONG,UDATE*);
43 static HRESULT (WINAPI *pVarDateFromUdate)(UDATE*,ULONG,DATE*);
44 static INT (WINAPI *pSystemTimeToVariantTime)(LPSYSTEMTIME,double*);
45 static INT (WINAPI *pVariantTimeToSystemTime)(double,LPSYSTEMTIME);
46 static INT (WINAPI *pDosDateTimeToVariantTime)(USHORT,USHORT,double*);
47 static INT (WINAPI *pVariantTimeToDosDateTime)(double,USHORT*,USHORT *);
48 static HRESULT (WINAPI *pVarFormatNumber)(LPVARIANT,int,int,int,int,ULONG,BSTR*);
49 static HRESULT (WINAPI *pVarFormat)(LPVARIANT,LPOLESTR,int,int,ULONG,BSTR*);
51 /* Get a conversion function ptr, return if function not available */
52 #define CHECKPTR(func) p##func = (void*)GetProcAddress(hOleaut32, #func); \
53 if (!p##func) { trace("function " # func " not available, not testing it\n"); return; }
55 /* Is a given function exported from oleaut32? */
56 #define HAVE_FUNC(func) ((void*)GetProcAddress(hOleaut32, #func) != NULL)
58 /* Have IRecordInfo data type? */
59 #define HAVE_OLEAUT32_RECORD HAVE_FUNC(SafeArraySetRecordInfo)
60 /* Have CY data type? */
61 #define HAVE_OLEAUT32_CY HAVE_FUNC(VarCyAdd)
62 /* Have I8/UI8 data type? */
63 #define HAVE_OLEAUT32_I8 HAVE_FUNC(VarI8FromI1)
64 /* Is this an ancient version with support for only I2/I4/R4/R8/DATE? */
65 #define IS_ANCIENT (!HAVE_FUNC(VarI1FromI2))
67 /* When comparing floating point values we cannot expect an exact match
68 * because the rounding errors depend on the exact algorithm.
70 #define EQ_DOUBLE(a,b) (fabs((a)-(b))<1e-14)
71 #define EQ_FLOAT(a,b) (fabs((a)-(b))<1e-7)
73 #define SKIPTESTS(a) if((a > VT_CLSID+10) && (a < VT_BSTR_BLOB-10)) continue;
75 /* Allow our test macros to work for VT_NULL and VT_EMPTY too */
76 #define V_EMPTY(v) V_I4(v)
77 #define V_NULL(v) V_I4(v)
79 /* Size constraints for overflow tests */
80 #define I1_MAX 0x7f
81 #define I1_MIN ((-I1_MAX)-1)
82 #define UI1_MAX 0xff
83 #define UI1_MIN 0
84 #define I2_MAX 0x7fff
85 #define I2_MIN ((-I2_MAX)-1)
86 #define UI2_MAX 0xffff
87 #define UI2_MIN 0
88 #define I4_MAX 0x7fffffff
89 #define I4_MIN ((-I4_MAX)-1)
90 #define UI4_MAX 0xffffffff
91 #define UI4_MIN 0
92 #define I8_MAX (((LONGLONG)I4_MAX << 32) | UI4_MAX)
93 #define I8_MIN ((-I8_MAX)-1)
94 #define UI8_MAX (((ULONGLONG)UI4_MAX << 32) | UI4_MAX)
95 #define UI8_MIN 0
96 #define DATE_MAX 2958465
97 #define DATE_MIN -657434
98 #define R4_MAX FLT_MAX
99 #define R4_MIN FLT_MIN
100 #define R8_MAX DBL_MAX
101 #define R8_MIN DBL_MIN
103 static inline int strcmpW( const WCHAR *str1, const WCHAR *str2 )
105 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
106 return *str1 - *str2;
109 /* return the string text of a given variant type */
110 static const char *vtstr(int x)
112 switch(x) {
113 case 0:
114 return "VT_EMPTY";
115 case 1:
116 return "VT_NULL";
117 case 2:
118 return "VT_I2";
119 case 3:
120 return "VT_I4";
121 case 4:
122 return "VT_R4";
123 case 5:
124 return "VT_R8";
125 case 6:
126 return "VT_CY";
127 case 7:
128 return "VT_DATE";
129 case 8:
130 return "VT_BSTR";
131 case 9:
132 return "VT_DISPATCH";
133 case 10:
134 return "VT_ERROR";
135 case 11:
136 return "VT_BOOL";
137 case 12:
138 return "VT_VARIANT";
139 case 13:
140 return "VT_UNKNOWN";
141 case 14:
142 return "VT_DECIMAL";
143 case 15:
144 return "notdefined";
145 case 16:
146 return "VT_I1";
147 case 17:
148 return "VT_UI1";
149 case 18:
150 return "VT_UI2";
151 case 19:
152 return "VT_UI4";
153 case 20:
154 return "VT_I8";
155 case 21:
156 return "VT_UI8";
157 case 22:
158 return "VT_INT";
159 case 23:
160 return "VT_UINT";
161 case 24:
162 return "VT_VOID";
163 case 25:
164 return "VT_HRESULT";
165 case 26:
166 return "VT_PTR";
167 case 27:
168 return "VT_SAFEARRAY";
169 case 28:
170 return "VT_CARRAY";
171 case 29:
172 return "VT_USERDEFINED";
173 case 30:
174 return "VT_LPSTR";
175 case 31:
176 return "VT_LPWSTR";
177 case 36:
178 return "VT_RECORD";
179 case 64:
180 return "VT_FILETIME";
181 case 65:
182 return "VT_BLOB";
183 case 66:
184 return "VT_STREAM";
185 case 67:
186 return "VT_STORAGE";
187 case 68:
188 return "VT_STREAMED_OBJECT";
189 case 69:
190 return "VT_STORED_OBJECT";
191 case 70:
192 return "VT_BLOB_OBJECT";
193 case 71:
194 return "VT_CF";
195 case 72:
196 return "VT_CLSID";
197 case 0xFFF:
198 return "VT_BSTR_BLOB/VT_ILLEGALMASKED/VT_TYPEMASK";
199 case 0x1000:
200 return "VT_VECTOR";
201 case 0x2000:
202 return "VT_ARRAY";
203 case 0x4000:
204 return "VT_BYREF";
205 case 0x8000:
206 return "VT_BYREF";
207 case 0xFFFF:
208 return "VT_ILLEGAL";
210 default:
211 return "defineme";
215 static void test_VariantInit(void)
217 VARIANTARG v1, v2;
219 /* Test that VariantInit() only sets the type */
220 memset(&v1, -1, sizeof(v1));
221 v2 = v1;
222 V_VT(&v2) = VT_EMPTY;
223 VariantInit(&v1);
224 ok(!memcmp(&v1, &v2, sizeof(v1)), "VariantInit() set extra fields\n");
227 /* All possible combinations of extra V_VT() flags */
228 static const VARTYPE ExtraFlags[16] =
231 VT_VECTOR,
232 VT_ARRAY,
233 VT_BYREF,
234 VT_RESERVED,
235 VT_VECTOR|VT_ARRAY,
236 VT_VECTOR|VT_BYREF,
237 VT_VECTOR|VT_RESERVED,
238 VT_VECTOR|VT_ARRAY|VT_BYREF,
239 VT_VECTOR|VT_ARRAY|VT_RESERVED,
240 VT_VECTOR|VT_BYREF|VT_RESERVED,
241 VT_VECTOR|VT_ARRAY|VT_BYREF|VT_RESERVED,
242 VT_ARRAY|VT_BYREF,
243 VT_ARRAY|VT_RESERVED,
244 VT_ARRAY|VT_BYREF|VT_RESERVED,
245 VT_BYREF|VT_RESERVED,
248 /* Determine if a vt is valid for VariantClear() */
249 static int IsValidVariantClearVT(VARTYPE vt, VARTYPE extraFlags)
251 int ret = 0;
253 /* Only the following flags/types are valid */
254 if ((vt <= VT_LPWSTR || vt == VT_RECORD || vt == VT_CLSID) &&
255 vt != (VARTYPE)15 &&
256 (vt < (VARTYPE)24 || vt > (VARTYPE)31) &&
257 (!(extraFlags & (VT_BYREF|VT_ARRAY)) || vt > VT_NULL) &&
258 (extraFlags == 0 || extraFlags == VT_BYREF || extraFlags == VT_ARRAY ||
259 extraFlags == (VT_ARRAY|VT_BYREF)))
260 ret = 1; /* ok */
262 if ((vt == VT_RECORD && !HAVE_OLEAUT32_RECORD) ||
263 ((vt == VT_I8 || vt == VT_UI8) && !HAVE_OLEAUT32_I8))
264 ret = 0; /* Old versions of oleaut32 */
265 return ret;
268 static void test_VariantClear(void)
270 HRESULT hres;
271 VARIANTARG v;
272 size_t i;
274 #if 0
275 /* Crashes: Native does not test input for NULL, so neither does Wine */
276 hres = VariantClear(NULL);
277 #endif
279 /* Only the type field is set, to VT_EMPTY */
280 V_VT(&v) = VT_UI4;
281 V_UI4(&v) = ~0u;
282 hres = VariantClear(&v);
283 ok((hres == S_OK && V_VT(&v) == VT_EMPTY) ||
284 (IS_ANCIENT && hres == DISP_E_BADVARTYPE && V_VT(&v) == VT_UI4),
285 "VariantClear: Type set to %d, res %08lx\n", V_VT(&v), hres);
286 ok(V_UI4(&v) == ~0u, "VariantClear: Overwrote value\n");
288 /* Test all possible V_VT values.
289 * Also demonstrates that null pointers in 'v' are not dereferenced.
290 * Individual variant tests should test VariantClear() with non-NULL values.
292 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
294 VARTYPE vt;
296 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
298 HRESULT hExpected = DISP_E_BADVARTYPE;
300 SKIPTESTS(vt);
302 memset(&v, 0, sizeof(v));
303 V_VT(&v) = vt | ExtraFlags[i];
305 hres = VariantClear(&v);
307 if (IsValidVariantClearVT(vt, ExtraFlags[i]))
308 hExpected = S_OK;
310 ok(hres == hExpected, "VariantClear: expected 0x%lX, got 0x%lX for vt %d | 0x%X\n",
311 hExpected, hres, vt, ExtraFlags[i]);
316 static void test_VariantCopy(void)
318 VARIANTARG vSrc, vDst;
319 VARTYPE vt;
320 size_t i;
321 HRESULT hres, hExpected;
323 /* Establish that the failure/other cases are dealt with. Individual tests
324 * for each type should verify that data is copied correctly, references
325 * are updated, etc.
328 /* vSrc == vDst */
329 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
331 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
333 SKIPTESTS(vt);
335 memset(&vSrc, 0, sizeof(vSrc));
336 V_VT(&vSrc) = vt | ExtraFlags[i];
338 hExpected = DISP_E_BADVARTYPE;
339 /* src is allowed to be a VT_CLSID */
340 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
341 hExpected = S_OK;
343 hres = VariantCopy(&vSrc, &vSrc);
345 ok(hres == hExpected,
346 "Copy(src==dst): expected 0x%lX, got 0x%lX for src==dest vt %d|0x%X\n",
347 hExpected, hres, vt, ExtraFlags[i]);
351 /* Test that if VariantClear() fails on dest, the function fails. This also
352 * shows that dest is in fact cleared and not just overwritten
354 memset(&vSrc, 0, sizeof(vSrc));
355 V_VT(&vSrc) = VT_UI1;
357 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
359 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
361 SKIPTESTS(vt);
363 hExpected = DISP_E_BADVARTYPE;
365 memset(&vDst, 0, sizeof(vDst));
366 V_VT(&vDst) = vt | ExtraFlags[i];
368 if (IsValidVariantClearVT(vt, ExtraFlags[i]))
369 hExpected = S_OK;
371 hres = VariantCopy(&vDst, &vSrc);
373 ok(hres == hExpected,
374 "Copy(bad dst): expected 0x%lX, got 0x%lX for dest vt %d|0x%X\n",
375 hExpected, hres, vt, ExtraFlags[i]);
376 if (hres == S_OK)
377 ok(V_VT(&vDst) == VT_UI1,
378 "Copy(bad dst): expected vt = VT_UI1, got %d\n", V_VT(&vDst));
382 /* Test that VariantClear() checks vSrc for validity before copying */
383 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
385 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
387 SKIPTESTS(vt);
389 hExpected = DISP_E_BADVARTYPE;
391 memset(&vDst, 0, sizeof(vDst));
392 V_VT(&vDst) = VT_EMPTY;
394 memset(&vSrc, 0, sizeof(vSrc));
395 V_VT(&vSrc) = vt | ExtraFlags[i];
397 /* src is allowed to be a VT_CLSID */
398 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
399 hExpected = S_OK;
401 hres = VariantCopy(&vDst, &vSrc);
403 ok(hres == hExpected,
404 "Copy(bad src): expected 0x%lX, got 0x%lX for src vt %d|0x%X\n",
405 hExpected, hres, vt, ExtraFlags[i]);
406 if (hres == S_OK)
407 ok(V_VT(&vDst) == (vt|ExtraFlags[i]),
408 "Copy(bad src): expected vt = %d, got %d\n",
409 vt | ExtraFlags[i], V_VT(&vDst));
414 /* Determine if a vt is valid for VariantCopyInd() */
415 static int IsValidVariantCopyIndVT(VARTYPE vt, VARTYPE extraFlags)
417 int ret = 0;
419 if ((extraFlags & VT_ARRAY) ||
420 (vt > VT_NULL && vt != (VARTYPE)15 && vt < VT_VOID &&
421 !(extraFlags & (VT_VECTOR|VT_RESERVED))))
423 ret = 1; /* ok */
425 return ret;
428 static void test_VariantCopyInd(void)
430 VARIANTARG vSrc, vDst, vRef, vRef2;
431 VARTYPE vt;
432 size_t i;
433 BYTE buffer[64];
434 HRESULT hres, hExpected;
436 memset(buffer, 0, sizeof(buffer));
438 /* vSrc == vDst */
439 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
441 if (ExtraFlags[i] & VT_ARRAY)
442 continue; /* Native crashes on NULL safearray */
444 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
446 SKIPTESTS(vt);
448 memset(&vSrc, 0, sizeof(vSrc));
449 V_VT(&vSrc) = vt | ExtraFlags[i];
451 hExpected = DISP_E_BADVARTYPE;
452 if (!(ExtraFlags[i] & VT_BYREF))
454 /* if src is not by-reference, acts as VariantCopy() */
455 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
456 hExpected = S_OK;
458 else
460 if (vt == VT_SAFEARRAY || vt == VT_BSTR || vt == VT_UNKNOWN ||
461 vt == VT_DISPATCH || vt == VT_RECORD)
462 continue; /* Need valid ptrs for deep copies */
464 V_BYREF(&vSrc) = &buffer;
465 hExpected = E_INVALIDARG;
467 if ((vt == VT_I8 || vt == VT_UI8) &&
468 ExtraFlags[i] == VT_BYREF)
470 if (HAVE_OLEAUT32_I8)
471 hExpected = S_OK; /* Only valid if I8 is a known type */
473 else if (IsValidVariantCopyIndVT(vt, ExtraFlags[i]))
474 hExpected = S_OK;
477 hres = VariantCopyInd(&vSrc, &vSrc);
479 ok(hres == hExpected,
480 "CopyInd(src==dst): expected 0x%lX, got 0x%lX for src==dst vt %d|0x%X\n",
481 hExpected, hres, vt, ExtraFlags[i]);
485 /* Bad dest */
486 memset(&vSrc, 0, sizeof(vSrc));
487 V_VT(&vSrc) = VT_UI1|VT_BYREF;
488 V_BYREF(&vSrc) = &buffer;
490 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
492 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
494 SKIPTESTS(vt);
496 memset(&vDst, 0, sizeof(vDst));
497 V_VT(&vDst) = vt | ExtraFlags[i];
499 hExpected = DISP_E_BADVARTYPE;
501 if (IsValidVariantClearVT(vt, ExtraFlags[i]))
502 hExpected = S_OK;
504 hres = VariantCopyInd(&vDst, &vSrc);
506 ok(hres == hExpected,
507 "CopyInd(bad dst): expected 0x%lX, got 0x%lX for dst vt %d|0x%X\n",
508 hExpected, hres, vt, ExtraFlags[i]);
509 if (hres == S_OK)
510 ok(V_VT(&vDst) == VT_UI1,
511 "CopyInd(bad dst): expected vt = VT_UI1, got %d\n", V_VT(&vDst));
515 /* bad src */
516 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
518 if (ExtraFlags[i] & VT_ARRAY)
519 continue; /* Native crashes on NULL safearray */
521 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
523 SKIPTESTS(vt);
525 memset(&vDst, 0, sizeof(vDst));
526 V_VT(&vDst) = VT_EMPTY;
528 memset(&vSrc, 0, sizeof(vSrc));
529 V_VT(&vSrc) = vt | ExtraFlags[i];
531 hExpected = DISP_E_BADVARTYPE;
532 if (!(ExtraFlags[i] & VT_BYREF))
534 /* if src is not by-reference, acts as VariantCopy() */
535 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
536 hExpected = S_OK;
538 else
540 if (vt == VT_SAFEARRAY || vt == VT_BSTR || vt == VT_UNKNOWN ||
541 vt == VT_DISPATCH || vt == VT_RECORD)
542 continue; /* Need valid ptrs for deep copies, see vartype.c */
544 V_BYREF(&vSrc) = &buffer;
546 hExpected = E_INVALIDARG;
548 if ((vt == VT_I8 || vt == VT_UI8) &&
549 ExtraFlags[i] == VT_BYREF)
551 if (HAVE_OLEAUT32_I8)
552 hExpected = S_OK; /* Only valid if I8 is a known type */
554 else if (IsValidVariantCopyIndVT(vt, ExtraFlags[i]))
555 hExpected = S_OK;
558 hres = VariantCopyInd(&vDst, &vSrc);
560 ok(hres == hExpected,
561 "CopyInd(bad src): expected 0x%lX, got 0x%lX for src vt %d|0x%X\n",
562 hExpected, hres, vt, ExtraFlags[i]);
563 if (hres == S_OK)
565 if (vt == VT_VARIANT && ExtraFlags[i] == VT_BYREF)
567 /* Type of vDst should be the type of the referenced variant.
568 * Since we set the buffer to all zeros, its type should be
569 * VT_EMPTY.
571 ok(V_VT(&vDst) == VT_EMPTY,
572 "CopyInd(bad src): expected dst vt = VT_EMPTY, got %d|0x%X\n",
573 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK);
575 else
577 ok(V_VT(&vDst) == (vt|(ExtraFlags[i] & ~VT_BYREF)),
578 "CopyInd(bad src): expected dst vt = %d|0x%X, got %d|0x%X\n",
579 vt, ExtraFlags[i] & ~VT_BYREF,
580 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK);
586 /* By-reference variants are dereferenced */
587 V_VT(&vRef) = VT_UI1;
588 V_UI1(&vRef) = 0x77;
589 V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
590 V_VARIANTREF(&vSrc) = &vRef;
591 VariantInit(&vDst);
593 hres = VariantCopyInd(&vDst, &vSrc);
594 ok(V_VT(&vDst) == VT_UI1 && V_UI1(&vDst) == 0x77,
595 "CopyInd(deref): expected dst vt = VT_UI1, val 0x77, got %d|0x%X, 0x%2X\n",
596 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK, V_UI1(&vDst));
598 /* By-reference variant to a by-reference type succeeds */
599 V_VT(&vRef) = VT_UI1|VT_BYREF;
600 V_UI1REF(&vRef) = buffer; buffer[0] = 0x88;
601 V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
602 V_VARIANTREF(&vSrc) = &vRef;
603 VariantInit(&vDst);
605 hres = VariantCopyInd(&vDst, &vSrc);
606 ok(V_VT(&vDst) == VT_UI1 && V_UI1(&vDst) == 0x88,
607 "CopyInd(deref): expected dst vt = VT_UI1, val 0x77, got %d|0x%X, 0x%2X\n",
608 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK, V_UI1(&vDst));
610 /* But a by-reference variant to a by-reference variant fails */
611 V_VT(&vRef2) = VT_UI1;
612 V_UI1(&vRef2) = 0x77;
613 V_VT(&vRef) = VT_VARIANT|VT_BYREF;
614 V_VARIANTREF(&vRef) = &vRef2;
615 V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
616 V_VARIANTREF(&vSrc) = &vRef;
617 VariantInit(&vDst);
619 hres = VariantCopyInd(&vDst, &vSrc);
620 ok(hres == E_INVALIDARG,
621 "CopyInd(ref->ref): expected E_INVALIDARG, got 0x%08lx\n", hres);
624 static HRESULT (WINAPI *pVarParseNumFromStr)(OLECHAR*,LCID,ULONG,NUMPARSE*,BYTE*);
626 /* Macros for converting and testing the result of VarParseNumFromStr */
627 #define FAILDIG 255
628 #define CONVERTN(str,dig,flags) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)/sizeof(WCHAR)); \
629 memset(rgb, FAILDIG, sizeof(rgb)); memset(&np,-1,sizeof(np)); np.cDig = dig; np.dwInFlags = flags; \
630 hres = pVarParseNumFromStr(buff,lcid,LOCALE_NOUSEROVERRIDE,&np,rgb)
631 #define CONVERT(str,flags) CONVERTN(str,sizeof(rgb),flags)
632 #define EXPECT(a,b,c,d,e,f) ok(hres == (HRESULT)S_OK, "Call failed, hres = %08lx\n", hres); \
633 if (hres == (HRESULT)S_OK) { \
634 ok(np.cDig == (a), "Expected cDig = %d, got %d\n", (a), np.cDig); \
635 ok(np.dwInFlags == (b), "Expected dwInFlags = 0x%lx, got 0x%lx\n", (ULONG)(b), np.dwInFlags); \
636 ok(np.dwOutFlags == (c), "Expected dwOutFlags = 0x%lx, got 0x%lx\n", (ULONG)(c), np.dwOutFlags); \
637 ok(np.cchUsed == (d), "Expected cchUsed = %d, got %d\n", (d), np.cchUsed); \
638 ok(np.nBaseShift == (e), "Expected nBaseShift = %d, got %d\n", (e), np.nBaseShift); \
639 ok(np.nPwr10 == (f), "Expected nPwr10 = %d, got %d\n", (f), np.nPwr10); \
641 #define EXPECTRGB(a,b) ok(rgb[a] == b, "Digit[%d], expected %d, got %d\n", a, b, rgb[a])
642 #define EXPECTFAIL ok(hres == (HRESULT)DISP_E_TYPEMISMATCH, "Call succeeded, hres = %08lx\n", hres)
643 #define EXPECT2(a,b) EXPECTRGB(0,a); EXPECTRGB(1,b)
645 static void test_VarParseNumFromStr(void)
647 HRESULT hres;
648 OLECHAR buff[128];
649 /* Ensure all tests are using the same locale characters for '$', ',' etc */
650 LCID lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
651 NUMPARSE np;
652 BYTE rgb[128];
654 /** No flags **/
656 CHECKPTR(VarParseNumFromStr);
658 /* Consume a single digit */
659 CONVERT("7", 0);
660 EXPECT(1,0,0,1,0,0);
661 EXPECT2(7,FAILDIG);
663 /* cDig is not literal digits - zeros are suppressed and nPwr10 is increased */
664 CONVERT("10", 0);
665 EXPECT(1,0,0,2,0,1);
666 /* Note: Win32 writes the trailing zeros if they are within cDig's limits,
667 * but then excludes them from the returned cDig count.
668 * In our implementation we don't bother writing them at all.
670 EXPECTRGB(0, 1);
672 /* if cDig is too small and numbers follow, sets INEXACT */
673 CONVERTN("11",1, 0);
674 EXPECT(1,0,NUMPRS_INEXACT,2,0,1);
675 EXPECT2(1,FAILDIG);
677 /* Strips leading zeros */
678 CONVERT("01", 0);
679 EXPECT(1,0,0,2,0,0);
680 EXPECT2(1,FAILDIG);
682 /* Strips leading zeros */
683 CONVERTN("01",1, 0);
684 EXPECT(1,0,0,2,0,0);
685 EXPECT2(1,FAILDIG);
688 /* Fails on non digits */
689 CONVERT("a", 0);
690 EXPECTFAIL;
691 EXPECTRGB(0,FAILDIG);
693 /** NUMPRS_LEADING_WHITE/NUMPRS_TRAILING_WHITE **/
695 /* Without flag, fails on whitespace */
696 CONVERT(" 0", 0);
697 EXPECTFAIL;
698 EXPECTRGB(0,FAILDIG);
701 /* With flag, consumes whitespace */
702 CONVERT(" 0", NUMPRS_LEADING_WHITE);
703 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
704 EXPECT2(0,FAILDIG);
706 /* Test TAB once, then assume it acts as space for all cases */
707 CONVERT("\t0", NUMPRS_LEADING_WHITE);
708 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
709 EXPECT2(0,FAILDIG);
712 /* Doesn't pick up trailing whitespace without flag */
713 CONVERT("0 ", 0);
714 EXPECT(1,0,0,1,0,0);
715 EXPECT2(0,FAILDIG);
717 /* With flag, consumes trailing whitespace */
718 CONVERT("0 ", NUMPRS_TRAILING_WHITE);
719 EXPECT(1,NUMPRS_TRAILING_WHITE,NUMPRS_TRAILING_WHITE,2,0,0);
720 EXPECT2(0,FAILDIG);
722 /* Leading flag only consumes leading */
723 CONVERT(" 0 ", NUMPRS_LEADING_WHITE);
724 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
725 EXPECT2(0,FAILDIG);
727 /* Both flags consumes both */
728 CONVERT(" 0 ", NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE);
729 EXPECT(1,NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE,NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE,3,0,0);
730 EXPECT2(0,FAILDIG);
732 /** NUMPRS_LEADING_PLUS/NUMPRS_TRAILING_PLUS **/
734 /* Without flag, fails on + */
735 CONVERT("+0", 0);
736 EXPECTFAIL;
737 EXPECTRGB(0,FAILDIG);
739 /* With flag, consumes + */
740 CONVERT("+0", NUMPRS_LEADING_PLUS);
741 EXPECT(1,NUMPRS_LEADING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
742 EXPECT2(0,FAILDIG);
744 /* Without flag, doesn't consume trailing + */
745 CONVERT("0+", 0);
746 EXPECT(1,0,0,1,0,0);
747 EXPECT2(0,FAILDIG);
749 /* With flag, consumes trailing + */
750 CONVERT("0+", NUMPRS_TRAILING_PLUS);
751 EXPECT(1,NUMPRS_TRAILING_PLUS,NUMPRS_TRAILING_PLUS,2,0,0);
752 EXPECT2(0,FAILDIG);
754 /* With leading flag, doesn't consume trailing + */
755 CONVERT("+0+", NUMPRS_LEADING_PLUS);
756 EXPECT(1,NUMPRS_LEADING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
757 EXPECT2(0,FAILDIG);
759 /* Trailing + doesn't get consumed if we specify both (unlike whitespace) */
760 CONVERT("+0+", NUMPRS_LEADING_PLUS|NUMPRS_TRAILING_PLUS);
761 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_TRAILING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
762 EXPECT2(0,FAILDIG);
764 /** NUMPRS_LEADING_MINUS/NUMPRS_TRAILING_MINUS **/
766 /* Without flag, fails on - */
767 CONVERT("-0", 0);
768 EXPECTFAIL;
769 EXPECTRGB(0,FAILDIG);
771 /* With flag, consumes - */
772 CONVERT("-0", NUMPRS_LEADING_MINUS);
773 EXPECT(1,NUMPRS_LEADING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
774 EXPECT2(0,FAILDIG);
776 /* Without flag, doesn't consume trailing - */
777 CONVERT("0-", 0);
778 EXPECT(1,0,0,1,0,0);
779 EXPECT2(0,FAILDIG);
781 /* With flag, consumes trailing - */
782 CONVERT("0-", NUMPRS_TRAILING_MINUS);
783 EXPECT(1,NUMPRS_TRAILING_MINUS,NUMPRS_NEG|NUMPRS_TRAILING_MINUS,2,0,0);
784 EXPECT2(0,FAILDIG);
786 /* With leading flag, doesn't consume trailing - */
787 CONVERT("-0-", NUMPRS_LEADING_MINUS);
788 EXPECT(1,NUMPRS_LEADING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
789 EXPECT2(0,FAILDIG);
791 /* Trailing - doesn't get consumed if we specify both (unlike whitespace) */
792 CONVERT("-0-", NUMPRS_LEADING_MINUS|NUMPRS_TRAILING_MINUS);
793 EXPECT(1,NUMPRS_LEADING_MINUS|NUMPRS_TRAILING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
794 EXPECT2(0,FAILDIG);
796 /** NUMPRS_HEX_OCT **/
798 /* Could be hex, octal or decimal - With flag reads as decimal */
799 CONVERT("0", NUMPRS_HEX_OCT);
800 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
801 EXPECT2(0,FAILDIG);
803 /* Doesn't recognise hex in .asm sytax */
804 CONVERT("0h", NUMPRS_HEX_OCT);
805 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
806 EXPECT2(0,FAILDIG);
808 /* Doesn't fail with valid leading string but no digits */
809 CONVERT("0x", NUMPRS_HEX_OCT);
810 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
811 EXPECT2(0,FAILDIG);
813 /* Doesn't recognise hex format humbers at all! */
814 CONVERT("0x0", NUMPRS_HEX_OCT);
815 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
816 EXPECT2(0,FAILDIG);
818 /* Doesn't recognise plain hex digits either */
819 CONVERT("FE", NUMPRS_HEX_OCT);
820 EXPECTFAIL;
821 EXPECTRGB(0,FAILDIG);
823 /* Octal */
824 CONVERT("0100", NUMPRS_HEX_OCT);
825 EXPECT(1,NUMPRS_HEX_OCT,0,4,0,2);
826 EXPECTRGB(0,1);
827 EXPECTRGB(1,0);
828 EXPECTRGB(2,0);
829 EXPECTRGB(3,FAILDIG);
831 /* VB hex */
832 CONVERT("&HF800", NUMPRS_HEX_OCT);
833 EXPECT(4,NUMPRS_HEX_OCT,0x40,6,4,0);
834 EXPECTRGB(0,15);
835 EXPECTRGB(1,8);
836 EXPECTRGB(2,0);
837 EXPECTRGB(3,0);
838 EXPECTRGB(4,FAILDIG);
840 /* VB hex lower case and leading zero */
841 CONVERT("&h0abcd", NUMPRS_HEX_OCT);
842 EXPECT(4,NUMPRS_HEX_OCT,0x40,7,4,0);
843 EXPECTRGB(0,10);
844 EXPECTRGB(1,11);
845 EXPECTRGB(2,12);
846 EXPECTRGB(3,13);
847 EXPECTRGB(4,FAILDIG);
849 /* VB oct */
850 CONVERT("&O300", NUMPRS_HEX_OCT);
851 EXPECT(3,NUMPRS_HEX_OCT,0x40,5,3,0);
852 EXPECTRGB(0,3);
853 EXPECTRGB(1,0);
854 EXPECTRGB(2,0);
855 EXPECTRGB(3,FAILDIG);
857 /* VB oct lower case and leading zero */
858 CONVERT("&o0777", NUMPRS_HEX_OCT);
859 EXPECT(3,NUMPRS_HEX_OCT,0x40,6,3,0);
860 EXPECTRGB(0,7);
861 EXPECTRGB(1,7);
862 EXPECTRGB(2,7);
863 EXPECTRGB(3,FAILDIG);
865 /* VB oct char bigger than 7 */
866 CONVERT("&o128", NUMPRS_HEX_OCT);
868 Native versions 2.x of oleaut32 allow this to succeed: later versions and Wine don't
869 EXPECTFAIL;
870 EXPECTRGB(0,FAILDIG);
872 /** NUMPRS_PARENS **/
874 /* Empty parens = error */
875 CONVERT("()", NUMPRS_PARENS);
876 EXPECTFAIL;
877 EXPECTRGB(0,FAILDIG);
879 /* With flag, trailing parens not consumed */
880 CONVERT("0()", NUMPRS_PARENS);
881 EXPECT(1,NUMPRS_PARENS,0,1,0,0);
882 EXPECT2(0,FAILDIG);
884 /* With flag, Number in parens made negative and parens consumed */
885 CONVERT("(0)", NUMPRS_PARENS);
886 EXPECT(1,NUMPRS_PARENS,NUMPRS_NEG|NUMPRS_PARENS,3,0,0);
887 EXPECT2(0,FAILDIG);
889 /** NUMPRS_THOUSANDS **/
891 /* With flag, thousands sep. not needed */
892 CONVERT("0", NUMPRS_THOUSANDS);
893 EXPECT(1,NUMPRS_THOUSANDS,0,1,0,0);
894 EXPECT2(0,FAILDIG);
896 /* With flag, thousands sep. and following digits consumed */
897 CONVERT("1,000", NUMPRS_THOUSANDS);
898 EXPECT(1,NUMPRS_THOUSANDS,NUMPRS_THOUSANDS,5,0,3);
899 EXPECTRGB(0,1);
901 /* With flag and decimal point, thousands sep. but not decimals consumed */
902 CONVERT("1,000.0", NUMPRS_THOUSANDS);
903 EXPECT(1,NUMPRS_THOUSANDS,NUMPRS_THOUSANDS,5,0,3);
904 EXPECTRGB(0,1);
906 /** NUMPRS_CURRENCY **/
908 /* Without flag, chokes on currency sign */
909 CONVERT("$11", 0);
910 EXPECTFAIL;
911 EXPECTRGB(0,FAILDIG);
913 /* With flag, consumes currency sign */
914 CONVERT("$11", NUMPRS_CURRENCY);
915 EXPECT(2,NUMPRS_CURRENCY,NUMPRS_CURRENCY,3,0,0);
916 EXPECT2(1,1);
917 EXPECTRGB(2,FAILDIG);
919 /* With flag only, doesn't consume decimal point */
920 CONVERT("$11.1", NUMPRS_CURRENCY);
921 EXPECT(2,NUMPRS_CURRENCY,NUMPRS_CURRENCY,3,0,0);
922 EXPECT2(1,1);
923 EXPECTRGB(2,FAILDIG);
925 /* With flag and decimal flag, consumes decimal point and following digits */
926 CONVERT("$11.1", NUMPRS_CURRENCY|NUMPRS_DECIMAL);
927 EXPECT(3,NUMPRS_CURRENCY|NUMPRS_DECIMAL,NUMPRS_CURRENCY|NUMPRS_DECIMAL,5,0,-1);
928 EXPECT2(1,1);
929 EXPECTRGB(2,1);
930 EXPECTRGB(3,FAILDIG);
932 /* Thousands flag can only be used with currency */
933 CONVERT("$1,234", NUMPRS_CURRENCY|NUMPRS_THOUSANDS);
934 EXPECT(4,NUMPRS_CURRENCY|NUMPRS_THOUSANDS,NUMPRS_CURRENCY|NUMPRS_THOUSANDS,6,0,0);
935 EXPECT2(1,2);
936 EXPECTRGB(2,3);
937 EXPECTRGB(3,4);
938 EXPECTRGB(4,FAILDIG);
940 /** NUMPRS_DECIMAL **/
942 /* With flag, consumes decimal point */
943 CONVERT("1.1", NUMPRS_DECIMAL);
944 EXPECT(2,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1);
945 EXPECT2(1,1);
946 EXPECTRGB(2,FAILDIG);
948 /* With flag, consumes decimal point. Skipping the decimal part is not an error */
949 CONVERT("1.", NUMPRS_DECIMAL);
950 EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,2,0,0);
951 EXPECT2(1,FAILDIG);
953 /* Consumes only one decimal point */
954 CONVERT("1.1.", NUMPRS_DECIMAL);
955 EXPECT(2,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1);
956 EXPECT2(1,1);
957 EXPECTRGB(2,FAILDIG);
959 /** NUMPRS_EXPONENT **/
961 /* Without flag, doesn't consume exponent */
962 CONVERT("1e1", 0);
963 EXPECT(1,0,0,1,0,0);
964 EXPECT2(1,FAILDIG);
966 /* With flag, consumes exponent */
967 CONVERT("1e1", NUMPRS_EXPONENT);
968 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,1);
969 EXPECT2(1,FAILDIG);
971 /* Negative exponents are accepted without flags */
972 CONVERT("1e-1", NUMPRS_EXPONENT);
973 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,-1);
974 EXPECT2(1,FAILDIG);
976 /* As are positive exponents and leading exponent 0's */
977 CONVERT("1e+01", NUMPRS_EXPONENT);
978 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,5,0,1);
979 EXPECT2(1,FAILDIG);
981 /* The same for zero exponents */
982 CONVERT("1e0", NUMPRS_EXPONENT);
983 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,0);
984 EXPECT2(1,FAILDIG);
986 /* Sign on a zero exponent doesn't matter */
987 CONVERT("1e+0", NUMPRS_EXPONENT);
988 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,0);
989 EXPECT2(1,FAILDIG);
991 CONVERT("1e-0", NUMPRS_EXPONENT);
992 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,0);
993 EXPECT2(1,FAILDIG);
995 /* Doesn't consume a real number exponent */
996 CONVERT("1e1.", NUMPRS_EXPONENT);
997 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,1);
998 EXPECT2(1,FAILDIG);
1000 /* Powers of 10 are calculated from the position of any decimal point */
1001 CONVERT("1.5e20", NUMPRS_EXPONENT|NUMPRS_DECIMAL);
1002 EXPECT(2,NUMPRS_EXPONENT|NUMPRS_DECIMAL,NUMPRS_EXPONENT|NUMPRS_DECIMAL,6,0,19);
1003 EXPECT2(1,5);
1005 CONVERT("1.5e-20", NUMPRS_EXPONENT|NUMPRS_DECIMAL);
1006 EXPECT(2,NUMPRS_EXPONENT|NUMPRS_DECIMAL,NUMPRS_EXPONENT|NUMPRS_DECIMAL,7,0,-21);
1007 EXPECT2(1,5);
1009 /** NUMPRS_USE_ALL **/
1011 /* Flag expects all digits */
1012 CONVERT("0", NUMPRS_USE_ALL);
1013 EXPECT(1,NUMPRS_USE_ALL,0,1,0,0);
1014 EXPECT2(0,FAILDIG);
1016 /* Rejects anything trailing */
1017 CONVERT("0 ", NUMPRS_USE_ALL);
1018 EXPECTFAIL;
1019 EXPECT2(0,FAILDIG);
1021 /* Unless consumed by trailing flag */
1022 CONVERT("0 ", NUMPRS_USE_ALL|NUMPRS_TRAILING_WHITE);
1023 EXPECT(1,NUMPRS_USE_ALL|NUMPRS_TRAILING_WHITE,NUMPRS_TRAILING_WHITE,2,0,0);
1024 EXPECT2(0,FAILDIG);
1026 /** Combinations **/
1028 /* Leading whitepace and plus, doesn't consume trailing whitespace */
1029 CONVERT("+ 0 ", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1030 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,3,0,0);
1031 EXPECT2(0,FAILDIG);
1033 /* Order of whitepace and plus is unimportant */
1034 CONVERT(" +0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1035 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,3,0,0);
1036 EXPECT2(0,FAILDIG);
1038 /* Leading whitespace can be repeated */
1039 CONVERT(" + 0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1040 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,4,0,0);
1041 EXPECT2(0,FAILDIG);
1043 /* But plus/minus etc. cannot */
1044 CONVERT("+ +0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1045 EXPECTFAIL;
1046 EXPECTRGB(0,FAILDIG);
1048 /* Inexact is not set if trailing zeros are removed */
1049 CONVERTN("10", 1, 0);
1050 EXPECT(1,0,0,2,0,1);
1051 EXPECT2(1,FAILDIG);
1053 /* Make sure a leading 0 is stripped but decimals after it get read */
1054 CONVERT("-0.51", NUMPRS_STD);
1055 EXPECT(2,NUMPRS_STD,NUMPRS_NEG|NUMPRS_DECIMAL|NUMPRS_LEADING_MINUS,5,0,-2);
1056 EXPECT2(5,1);
1058 /* Keep trailing zeros on whole number part of a decimal */
1059 CONVERT("10.1", NUMPRS_STD);
1060 EXPECT(3,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-1);
1061 EXPECT2(1,0);
1062 EXPECTRGB(2,1);
1064 /* Zeros after decimal sign */
1065 CONVERT("0.01", NUMPRS_STD);
1066 EXPECT(1,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-2);
1067 EXPECT2(1,FAILDIG);
1069 /* Trailing zeros after decimal part */
1070 CONVERT("0.10", NUMPRS_STD);
1071 EXPECT(1,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-1);
1072 EXPECT2(1,0);
1075 static HRESULT (WINAPI *pVarNumFromParseNum)(NUMPARSE*,BYTE*,ULONG,VARIANT*);
1077 /* Macros for converting and testing the result of VarNumFromParseNum */
1078 #define SETRGB(indx,val) if (!indx) memset(rgb, FAILDIG, sizeof(rgb)); rgb[indx] = val
1079 #undef CONVERT
1080 #define CONVERT(a,b,c,d,e,f,bits) \
1081 np.cDig = (a); np.dwInFlags = (b); np.dwOutFlags = (c); np.cchUsed = (d); \
1082 np.nBaseShift = (e); np.nPwr10 = (f); hres = pVarNumFromParseNum(&np, rgb, bits, &vOut)
1083 static const char *szFailOverflow = "Expected overflow, hres = %08lx\n";
1084 #define EXPECT_OVERFLOW ok(hres == (HRESULT)DISP_E_OVERFLOW, szFailOverflow, hres)
1085 static const char *szFailOk = "Call failed, hres = %08lx\n";
1086 #define EXPECT_OK ok(hres == (HRESULT)S_OK, szFailOk, hres); \
1087 if (hres == (HRESULT)S_OK)
1088 #define EXPECT_TYPE(typ) ok(V_VT(&vOut) == typ,"Expected Type = " #typ ", got %d\n", V_VT(&vOut))
1089 #define EXPECT_I1(val) EXPECT_OK { EXPECT_TYPE(VT_I1); \
1090 ok(V_I1(&vOut) == val, "Expected i1 = %d, got %d\n", (signed char)val, V_I1(&vOut)); }
1091 #define EXPECT_UI1(val) EXPECT_OK { EXPECT_TYPE(VT_UI1); \
1092 ok(V_UI1(&vOut) == val, "Expected ui1 = %d, got %d\n", (BYTE)val, V_UI1(&vOut)); }
1093 #define EXPECT_I2(val) EXPECT_OK { EXPECT_TYPE(VT_I2); \
1094 ok(V_I2(&vOut) == val, "Expected i2 = %d, got %d\n", (SHORT)val, V_I2(&vOut)); }
1095 #define EXPECT_UI2(val) EXPECT_OK { EXPECT_TYPE(VT_UI2); \
1096 ok(V_UI2(&vOut) == val, "Expected ui2 = %d, got %d\n", (USHORT)val, V_UI2(&vOut)); }
1097 #define EXPECT_I4(val) EXPECT_OK { EXPECT_TYPE(VT_I4); \
1098 ok(V_I4(&vOut) == val, "Expected i4 = %ld, got %ld\n", (LONG)val, V_I4(&vOut)); }
1099 #define EXPECT_UI4(val) EXPECT_OK { EXPECT_TYPE(VT_UI4); \
1100 ok(V_UI4(&vOut) == val, "Expected ui4 = %ld, got %ld\n", (ULONG)val, V_UI4(&vOut)); }
1101 #define EXPECT_I8(high,low) EXPECT_OK { EXPECT_TYPE(VT_I8); \
1102 ok(V_I8(&vOut) == ((((LONG64)(high))<<32)|(low)), "Expected i8 = %lx%08lx, got %lx%08lx\n", \
1103 (LONG)(high), (LONG)(low), (LONG)(V_I8(&vOut)>>32), (LONG)V_I8(&vOut) ); }
1104 #define EXPECT_UI8(val) EXPECT_OK { EXPECT_TYPE(VT_UI8); \
1105 ok(V_UI8(&vOut) == val, "Expected ui8 = %lld, got %lld\n", (ULONG64)val, V_UI8(&vOut)); }
1106 #define EXPECT_R4(val) EXPECT_OK { EXPECT_TYPE(VT_R4); \
1107 ok(V_R4(&vOut) == val, "Expected r4 = %f, got %f\n", val, V_R4(&vOut)); }
1108 #define EXPECT_R8(val) EXPECT_OK { EXPECT_TYPE(VT_R8); \
1109 ok(V_R8(&vOut) == val, "Expected r8 = %g, got %g\n", val, V_R8(&vOut)); }
1110 #define CY_MULTIPLIER 10000
1111 #define EXPECT_CY(val) EXPECT_OK { EXPECT_TYPE(VT_CY); \
1112 ok(V_CY(&vOut).int64 == (LONG64)(val * CY_MULTIPLIER), "Expected r8 = %lld, got %lld\n", (LONG64)val, V_CY(&vOut).int64); }
1114 static void test_VarNumFromParseNum(void)
1116 HRESULT hres;
1117 NUMPARSE np;
1118 BYTE rgb[128];
1119 VARIANT vOut;
1121 CHECKPTR(VarNumFromParseNum);
1123 /* Convert the number 1 to different types */
1124 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I1); EXPECT_I1(1);
1125 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_UI1); EXPECT_UI1(1);
1126 /* Prefers a signed type to unsigned of the same size */
1127 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I1|VTBIT_UI1); EXPECT_I1(1);
1128 /* But takes the smaller size if possible */
1129 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I2|VTBIT_UI1); EXPECT_UI1(1);
1131 /* Try different integer sizes */
1132 #define INTEGER_VTBITS (VTBIT_I1|VTBIT_UI1|VTBIT_I2|VTBIT_UI2|VTBIT_I4|VTBIT_UI4|VTBIT_I8|VTBIT_UI8)
1134 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, INTEGER_VTBITS); EXPECT_I1(1);
1135 /* 127 */
1136 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 7);
1137 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_I1(127);
1138 /* 128 */
1139 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 8);
1140 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_UI1(128);
1141 /* 255 */
1142 SETRGB(0, 2); SETRGB(1, 5); SETRGB(2, 5);
1143 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_UI1(255);
1144 /* 256 */
1145 SETRGB(0, 2); SETRGB(1, 5); SETRGB(2, 6);
1146 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_I2(256);
1147 /* 32767 */
1148 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 7);
1149 CONVERT(5,0,0,5,0,0, INTEGER_VTBITS); EXPECT_I2(32767);
1150 /* 32768 */
1151 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 8);
1152 CONVERT(5,0,0,5,0,0, INTEGER_VTBITS); EXPECT_UI2(32768);
1154 /* Assume the above pattern holds for remaining positive integers; test negative */
1156 /* -128 */
1157 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 8);
1158 CONVERT(3,0,NUMPRS_NEG,3,0,0, INTEGER_VTBITS); EXPECT_I1(-128);
1159 /* -129 */
1160 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 9);
1161 CONVERT(3,0,NUMPRS_NEG,3,0,0, INTEGER_VTBITS); EXPECT_I2(-129);
1162 /* -32768 */
1163 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 8);
1164 CONVERT(5,0,NUMPRS_NEG,5,0,0, INTEGER_VTBITS); EXPECT_I2(-32768);
1165 /* -32768 */
1166 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 9);
1167 CONVERT(5,0,NUMPRS_NEG,5,0,0, INTEGER_VTBITS); EXPECT_I4(-32769);
1169 /* Assume the above pattern holds for remaining negative integers */
1171 /* Test hexadecimal conversions */
1172 SETRGB(0, 1); CONVERT(1,0,0,1,4,0, INTEGER_VTBITS); EXPECT_I1(0x01);
1173 /* 0x7f */
1174 SETRGB(0, 7); SETRGB(1, 0xf);
1175 CONVERT(2,0,0,2,4,0, INTEGER_VTBITS); EXPECT_I1(0x7f);
1176 /* 0x7fff */
1177 SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
1178 CONVERT(4,0,0,4,4,0, INTEGER_VTBITS); EXPECT_I2(0x7fff);
1179 /* 0x7fffffff */
1180 SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
1181 SETRGB(4, 0xf); SETRGB(5, 0xf); SETRGB(6, 0xf); SETRGB(7, 0xf);
1182 CONVERT(8,0,0,8,4,0, INTEGER_VTBITS); EXPECT_I4(0x7fffffffL);
1183 /* 0x7fffffffffffffff (64 bits) */
1184 SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
1185 SETRGB(4, 0xf); SETRGB(5, 0xf); SETRGB(6, 0xf); SETRGB(7, 0xf);
1186 SETRGB(8, 0xf); SETRGB(9, 0xf); SETRGB(10, 0xf); SETRGB(11, 0xf);
1187 SETRGB(12, 0xf); SETRGB(13, 0xf); SETRGB(14, 0xf); SETRGB(15, 0xf);
1188 if (HAVE_OLEAUT32_I8)
1190 /* We cannot use INTEGER_VTBITS as WinXP and Win2003 are broken(?). They
1191 truncate the number to the smallest integer size requested:
1192 CONVERT(16,0,0,16,4,0, INTEGER_VTBITS); EXPECT_I1((signed char)0xff); */
1193 CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x7fffffff,0xffffffff);
1196 /* Assume the above pattern holds for numbers without hi-bit set, test (preservation of) hi-bit */
1197 /* 0x82 */
1198 SETRGB(0, 8); SETRGB(1, 2);
1199 CONVERT(2,0,0,2,4,0, INTEGER_VTBITS);
1200 EXPECT_I1((signed char)0x82);
1201 /* 0x8002 */
1202 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 2);
1203 CONVERT(4,0,0,4,4,0, INTEGER_VTBITS);
1204 EXPECT_I2((signed short)0x8002);
1205 /* 0x80000002 */
1206 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1207 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 2);
1208 CONVERT(8,0,0,8,4,0, INTEGER_VTBITS); EXPECT_I4(0x80000002);
1209 /* 0x8000000000000002 (64 bits) */
1210 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1211 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 0);
1212 SETRGB(8, 0); SETRGB(9, 0); SETRGB(10, 0); SETRGB(11, 0);
1213 SETRGB(12, 0); SETRGB(13, 0); SETRGB(14, 0); SETRGB(15, 2);
1214 if (HAVE_OLEAUT32_I8)
1216 /* We cannot use INTEGER_VTBITS as WinXP and Win2003 are broken(?). They
1217 truncate the number to the smallest integer size requested:
1218 CONVERT(16,0,0,16,4,0, INTEGER_VTBITS & ~VTBIT_I1);
1219 EXPECT_I2((signed short)0x0002); */
1220 CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x80000000,0x00000002);
1223 /* Test (preservation of) hi-bit with STRICT type requesting */
1224 /* 0x82 */
1225 SETRGB(0, 8); SETRGB(1, 2);
1226 CONVERT(2,0,0,2,4,0, VTBIT_I1);
1227 EXPECT_I1((signed char)0x82);
1228 /* 0x8002 */
1229 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 2);
1230 CONVERT(4,0,0,4,4,0, VTBIT_I2);
1231 EXPECT_I2((signed short)0x8002);
1232 /* 0x80000002 */
1233 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1234 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 2);
1235 CONVERT(8,0,0,8,4,0, VTBIT_I4); EXPECT_I4(0x80000002);
1236 /* 0x8000000000000002 (64 bits) */
1237 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1238 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 0);
1239 SETRGB(8, 0); SETRGB(9, 0); SETRGB(10, 0); SETRGB(11, 0);
1240 SETRGB(12, 0); SETRGB(13, 0); SETRGB(14, 0); SETRGB(15, 2);
1241 if (HAVE_OLEAUT32_I8)
1243 CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x80000000,0x00000002);
1245 /* Assume the above pattern holds for numbers with hi-bit set */
1247 /* Negative numbers overflow if we have only unsigned outputs */
1248 /* -1 */
1249 SETRGB(0, 1); CONVERT(1,0,NUMPRS_NEG,1,0,0, VTBIT_UI1); EXPECT_OVERFLOW;
1250 /* -0.6 */
1251 SETRGB(0, 6); CONVERT(1,0,NUMPRS_NEG,1,0,~0u, VTBIT_UI1); EXPECT_OVERFLOW;
1253 /* Except that rounding is done first, so -0.5 to 0 are accepted as 0 */
1254 /* -0.5 */
1255 SETRGB(0, 5); CONVERT(1,0,NUMPRS_NEG,1,0,~0u, VTBIT_UI1); EXPECT_UI1(0);
1257 /* Floating point zero is OK */
1258 /* 0.00000000E0 */
1259 SETRGB(0, 0); CONVERT(1,0,NUMPRS_DECIMAL|NUMPRS_EXPONENT,12,0,-8, VTBIT_R8);
1260 EXPECT_R8(0.0);
1262 /* Float is acceptable for an integer input value */
1263 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R4); EXPECT_R4(1.0f);
1264 /* As is double */
1265 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R8); EXPECT_R8(1.0);
1266 /* As is currency */
1267 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_CY); EXPECT_CY(1);
1269 /* Float is preferred over double */
1270 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R4|VTBIT_R8); EXPECT_R4(1.0f);
1272 /* Double is preferred over currency */
1273 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R8|VTBIT_CY); EXPECT_R8(1.0);
1275 /* Currency is preferred over decimal */
1276 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_CY|VTBIT_DECIMAL); EXPECT_CY(1);
1279 static const char* szUdateFromDateFail = "%.16g expected %lx, %d,%d,%d,%d,%d,%d,%d %d %d"
1280 ", got %lx, %d,%d,%d,%d,%d,%d,%d %d %d\n";
1281 #define DT2UD(dt,flags,r,d,m,y,h,mn,s,ms,dw,dy) \
1282 memset(&ud, 0, sizeof(ud)); \
1283 res = pVarUdateFromDate(dt, flags, &ud); \
1284 ok(r == res && (FAILED(r) || (ud.st.wYear == y && ud.st.wMonth == m && ud.st.wDay == d && \
1285 ud.st.wHour == h && ud.st.wMinute == mn && ud.st.wSecond == s && \
1286 ud.st.wMilliseconds == ms && ud.st.wDayOfWeek == dw && ud.wDayOfYear == dy)), \
1287 szUdateFromDateFail, dt, r, d, m, y, h, mn, s, ms, dw, dy, res, ud.st.wDay, ud.st.wMonth, \
1288 ud.st.wYear, ud.st.wHour, ud.st.wMinute, ud.st.wSecond, \
1289 ud.st.wMilliseconds, ud.st.wDayOfWeek, ud.wDayOfYear)
1291 static void test_VarUdateFromDate(void)
1293 UDATE ud;
1294 HRESULT res;
1296 CHECKPTR(VarUdateFromDate);
1297 DT2UD(29221.0,0,S_OK,1,1,1980,0,0,0,0,2,1); /* 1 Jan 1980 */
1298 DT2UD(29222.0,0,S_OK,2,1,1980,0,0,0,0,3,2); /* 2 Jan 1980 */
1299 DT2UD(33238.0,0,S_OK,31,12,1990,0,0,0,0,1,365); /* 31 Dec 1990 */
1300 DT2UD(0.0,0,S_OK,30,12,1899,0,0,0,0,6,364); /* 30 Dec 1899 - VT_DATE 0.0 */
1301 DT2UD(-657434.0,0,S_OK,1,1,100,0,0,0,0,5,1); /* 1 Jan 100 - Min */
1302 DT2UD(-657435.0,0,E_INVALIDARG,0,0,0,0,0,0,0,0,0); /* < 1 Jan 100 => err */
1303 DT2UD(2958465.0,0,S_OK,31,12,9999,0,0,0,0,5,365); /* 31 Dec 9999 - Max */
1304 DT2UD(2958466.0,0,E_INVALIDARG,0,0,0,0,0,0,0,0,0); /* > 31 Dec 9999 => err */
1306 /* VAR_VALIDDATE doesn't prevent upper and lower bounds being checked */
1307 DT2UD(-657435.0,VAR_VALIDDATE,E_INVALIDARG,0,0,0,0,0,0,0,0,0);
1308 DT2UD(2958466.0,VAR_VALIDDATE,E_INVALIDARG,0,0,0,0,0,0,0,0,0);
1310 /* Times */
1311 DT2UD(29221.25,0,S_OK,1,1,1980,6,0,0,0,2,1); /* 6 AM */
1312 DT2UD(29221.33333333,0,S_OK,1,1,1980,8,0,0,0,2,1); /* 8 AM */
1313 DT2UD(29221.5,0,S_OK,1,1,1980,12,0,0,0,2,1); /* 12 AM */
1314 DT2UD(29221.9888884444,0,S_OK,1,1,1980,23,44,0,0,2,1); /* 11:44 PM */
1315 DT2UD(29221.7508765432,0,S_OK,1,1,1980,18,1,16,0,2,1); /* 6:18:02 PM */
1318 #define UD2T(d,m,y,h,mn,s,ms,dw,dy,flags,r,dt) \
1319 ud.st.wYear = (y); ud.st.wMonth = (m); ud.st.wDay = (d); ud.st.wHour = (h); \
1320 ud.st.wMinute = (mn); ud.st.wSecond = (s); ud.st.wMilliseconds = (ms); \
1321 ud.st.wDayOfWeek = (dw); ud.wDayOfYear = (dy); \
1322 res = pVarDateFromUdate(&ud, (flags), &out); \
1323 ok((r) == res && (FAILED(r) || fabs(out-(dt)) < 1.0e-11), \
1324 "expected %lx, %.16g, got %lx, %.16g\n", r, dt, res, out)
1326 static void test_VarDateFromUdate(void)
1328 UDATE ud;
1329 double out;
1330 HRESULT res;
1332 CHECKPTR(VarDateFromUdate);
1333 UD2T(1,1,1980,0,0,0,0,2,1,0,S_OK,29221.0); /* 1 Jan 1980 */
1334 UD2T(2,1,1980,0,0,0,0,3,2,0,S_OK,29222.0); /* 2 Jan 1980 */
1335 UD2T(31,12,1990,0,0,0,0,0,0,0,S_OK,33238.0); /* 31 Dec 1990 */
1336 UD2T(31,12,90,0,0,0,0,0,0,0,S_OK,33238.0); /* year < 100 is 1900+year! */
1337 UD2T(30,12,1899,0,0,0,0,6,364,0,S_OK,0.0); /* 30 Dec 1899 - VT_DATE 0.0 */
1338 UD2T(1,1,100,0,0,0,0,0,0,0,S_OK,-657434.0); /* 1 Jan 100 - Min */
1339 UD2T(31,12,9999,0,0,0,0,0,0,0,S_OK,2958465.0); /* 31 Dec 9999 - Max */
1340 UD2T(1,1,10000,0,0,0,0,0,0,0,E_INVALIDARG,0.0); /* > 31 Dec 9999 => err */
1342 UD2T(1,1,1980,18,1,16,0,2,1,0,S_OK,29221.75087962963); /* 6:18:02 PM */
1344 UD2T(0,1,1980,0,0,0,0,2,1,0,S_OK,29220.0); /* Rolls back to 31 Dec 1899 */
1345 UD2T(1,13,1980,0,0,0,0,2,1,0,S_OK,29587.0); /* Rolls fwd to 1/1/1981 */
1348 #define ST2DT(d,m,y,h,mn,s,ms,r,dt) \
1349 st.wYear = y; st.wMonth = m; st.wDay = d; st.wHour = h; st.wMinute = mn; \
1350 st.wSecond = s; st.wMilliseconds = ms; st.wDayOfWeek = 0; \
1351 res = pSystemTimeToVariantTime(&st, &out); \
1352 ok(r == res && (!r || fabs(out-dt) < 1.0e-11), \
1353 "expected %d, %.16g, got %d, %.16g\n", r, dt, res, out)
1355 static void test_SystemTimeToVariantTime(void)
1357 SYSTEMTIME st;
1358 double out;
1359 int res;
1361 CHECKPTR(SystemTimeToVariantTime);
1362 ST2DT(1,1,1980,0,0,0,0,TRUE,29221.0);
1363 ST2DT(2,1,1980,0,0,0,0,TRUE,29222.0);
1364 ST2DT(0,1,1980,0,0,0,0,TRUE,29220.0); /* Rolls back to 31 Dec 1899 */
1365 ST2DT(1,13,1980,0,0,0,0,FALSE,29587.0); /* Fails on invalid month */
1366 ST2DT(31,12,90,0,0,0,0,TRUE,33238.0); /* year < 100 is 1900+year! */
1369 #define DT2ST(dt,r,d,m,y,h,mn,s,ms) \
1370 memset(&st, 0, sizeof(st)); \
1371 res = pVariantTimeToSystemTime(dt, &st); \
1372 ok(r == res && (!r || (st.wYear == y && st.wMonth == m && st.wDay == d && \
1373 st.wHour == h && st.wMinute == mn && st.wSecond == s && \
1374 st.wMilliseconds == ms)), \
1375 "%.16g expected %d, %d,%d,%d,%d,%d,%d,%d, got %d, %d,%d,%d,%d,%d,%d,%d\n", \
1376 dt, r, d, m, y, h, mn, s, ms, res, st.wDay, st.wMonth, st.wYear, \
1377 st.wHour, st.wMinute, st.wSecond, st.wMilliseconds)
1379 static void test_VariantTimeToSystemTime(void)
1381 SYSTEMTIME st;
1382 int res;
1384 CHECKPTR(VariantTimeToSystemTime);
1385 DT2ST(29221.0,1,1,1,1980,0,0,0,0);
1386 DT2ST(29222.0,1,2,1,1980,0,0,0,0);
1389 #define MKDOSDATE(d,m,y) ((d & 0x1f) | ((m & 0xf) << 5) | (((y-1980) & 0x7f) << 9))
1390 #define MKDOSTIME(h,m,s) (((s>>1) & 0x1f) | ((m & 0x3f) << 5) | ((h & 0x1f) << 11))
1392 static const char *szDosDateToVarTimeFail = "expected %d, %.16g, got %d, %.16g\n";
1393 #define DOS2DT(d,m,y,h,mn,s,r,dt) out = 0.0; \
1394 dosDate = MKDOSDATE(d,m,y); \
1395 dosTime = MKDOSTIME(h,mn,s); \
1396 res = pDosDateTimeToVariantTime(dosDate, dosTime, &out); \
1397 ok(r == res && (!r || fabs(out-dt) < 1.0e-11), \
1398 szDosDateToVarTimeFail, r, dt, res, out)
1400 static void test_DosDateTimeToVariantTime(void)
1402 USHORT dosDate, dosTime;
1403 double out;
1404 INT res;
1406 CHECKPTR(DosDateTimeToVariantTime);
1408 /* Date */
1409 DOS2DT(1,1,1980,0,0,0,1,29221.0); /* 1/1/1980 */
1410 DOS2DT(31,12,2099,0,0,0,1,73050.0); /* 31/12/2099 */
1411 /* Dates are limited to the dos date max of 31/12/2099 */
1412 DOS2DT(31,12,2100,0,0,0,0,0.0); /* 31/12/2100 */
1413 /* Days and months of 0 cause date to roll back 1 day or month */
1414 DOS2DT(0,1,1980,0,0,0,1,29220.0); /* 0 Day => 31/12/1979 */
1415 DOS2DT(1,0,1980,0,0,0,1,29190.0); /* 0 Mth => 1/12/1979 */
1416 DOS2DT(0,0,1980,0,0,0,1,29189.0); /* 0 D/M => 30/11/1979 */
1417 /* Days > days in the month cause date to roll forward 1 month */
1418 DOS2DT(29,2,1981,0,0,0,1,29646.0); /* 29/2/1981 -> 3/1/1980 */
1419 DOS2DT(30,2,1981,0,0,0,1,29647.0); /* 30/2/1981 -> 4/1/1980 */
1420 /* Takes leap years into account when rolling forward */
1421 DOS2DT(29,2,1980,0,0,0,1,29280.0); /* 2/29/1980 */
1422 /* Months > 12 cause an error */
1423 DOS2DT(2,13,1980,0,0,0,0,0.0);
1425 /* Time */
1426 DOS2DT(1,1,1980,0,0,29,1,29221.00032407407); /* 1/1/1980 12:00:28 AM */
1427 DOS2DT(1,1,1980,0,0,31,1,29221.00034722222); /* 1/1/1980 12:00:30 AM */
1428 DOS2DT(1,1,1980,0,59,0,1,29221.04097222222); /* 1/1/1980 12:59:00 AM */
1429 DOS2DT(1,1,1980,0,60,0,0,0.0); /* Invalid seconds */
1430 DOS2DT(1,1,1980,23,0,0,1,29221.95833333333); /* 1/1/1980 11:00:00 PM */
1431 DOS2DT(1,1,1980,24,0,0,0,0.0); /* Invalid hours */
1434 #define DT2DOS(dt,r,d,m,y,h,mn,s) dosTime = dosDate = 0; \
1435 expDosDate = MKDOSDATE(d,m,y); \
1436 expDosTime = MKDOSTIME(h,mn,s); \
1437 res = pVariantTimeToDosDateTime(dt, &dosDate, &dosTime); \
1438 ok(r == res && (!r || (dosTime == expDosTime && dosDate == expDosDate)), \
1439 "%g: expected %d,%d(%d/%d/%d),%d(%d:%d:%d) got %d,%d(%d/%d/%d),%d(%d:%d:%d)\n", \
1440 dt, r, expDosDate, expDosDate & 0x1f, (expDosDate >> 5) & 0xf, 1980 + (expDosDate >> 9), \
1441 expDosTime, expDosTime >> 11, (expDosTime >> 5) & 0x3f, (expDosTime & 0x1f), \
1442 res, dosDate, dosDate & 0x1f, (dosDate >> 5) & 0xf, 1980 + (dosDate >> 9), \
1443 dosTime, dosTime >> 11, (dosTime >> 5) & 0x3f, (dosTime & 0x1f))
1445 static void test_VariantTimeToDosDateTime(void)
1447 USHORT dosDate, dosTime, expDosDate, expDosTime;
1448 INT res;
1450 CHECKPTR(VariantTimeToDosDateTime);
1452 /* Date */
1453 DT2DOS(29221.0,1,1,1,1980,0,0,0); /* 1/1/1980 */
1454 DT2DOS(73050.0,1,31,12,2099,0,0,0); /* 31/12/2099 */
1455 DT2DOS(29220.0,0,0,0,0,0,0,0); /* 31/12/1979 - out of range */
1456 DT2DOS(73415.0,0,0,0,0,0,0,0); /* 31/12/2100 - out of range */
1458 /* Time */
1459 DT2DOS(29221.00032407407,1,1,1,1980,0,0,29); /* 1/1/1980 12:00:28 AM */
1460 DT2DOS(29221.00034722222,1,1,1,1980,0,0,31); /* 1/1/1980 12:00:30 AM */
1461 DT2DOS(29221.04097222222,1,1,1,1980,0,59,0); /* 1/1/1980 12:59:00 AM */
1462 DT2DOS(29221.95833333333,1,1,1,1980,23,0,0); /* 1/1/1980 11:00:00 PM */
1465 #define FMT_NUMBER(vt,val) \
1466 VariantInit(&v); V_VT(&v) = vt; val(&v) = 1; \
1467 hres = pVarFormatNumber(&v,2,0,0,0,0,&str); \
1468 ok(hres == S_OK, "VarFormatNumber (vt %d): returned %8lx\n", vt, hres); \
1469 if (hres == S_OK) \
1470 ok(str && strcmpW(str,szResult1) == 0, \
1471 "VarFormatNumber (vt %d): string different\n", vt)
1473 static void test_VarFormatNumber(void)
1475 static const WCHAR szSrc1[] = { '1','\0' };
1476 static const WCHAR szResult1[] = { '1','.','0','0','\0' };
1477 static const WCHAR szSrc2[] = { '-','1','\0' };
1478 static const WCHAR szResult2[] = { '(','1','.','0','0',')','\0' };
1479 char buff[8];
1480 HRESULT hres;
1481 VARIANT v;
1482 BSTR str = NULL;
1484 CHECKPTR(VarFormatNumber);
1486 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char));
1487 if (buff[0] != '.' || buff[1])
1489 trace("Skipping VarFormatNumber tests as decimal separator is '%s'\n", buff);
1490 return;
1493 FMT_NUMBER(VT_I1, V_I1);
1494 FMT_NUMBER(VT_UI1, V_UI1);
1495 FMT_NUMBER(VT_I2, V_I2);
1496 FMT_NUMBER(VT_UI2, V_UI2);
1497 FMT_NUMBER(VT_I4, V_I4);
1498 FMT_NUMBER(VT_UI4, V_UI4);
1499 if (HAVE_OLEAUT32_I8)
1501 FMT_NUMBER(VT_I8, V_I8);
1502 FMT_NUMBER(VT_UI8, V_UI8);
1504 FMT_NUMBER(VT_R4, V_R4);
1505 FMT_NUMBER(VT_R8, V_R8);
1506 FMT_NUMBER(VT_BOOL, V_BOOL);
1508 V_VT(&v) = VT_BSTR;
1509 V_BSTR(&v) = SysAllocString(szSrc1);
1511 hres = pVarFormatNumber(&v,2,0,0,0,0,&str);
1512 ok(hres == S_OK, "VarFormatNumber (bstr): returned %8lx\n", hres);
1513 if (hres == S_OK)
1514 ok(str && strcmpW(str, szResult1) == 0, "VarFormatNumber (bstr): string different\n");
1515 SysFreeString(V_BSTR(&v));
1516 SysFreeString(str);
1518 V_BSTR(&v) = SysAllocString(szSrc2);
1519 hres = pVarFormatNumber(&v,2,0,-1,0,0,&str);
1520 ok(hres == S_OK, "VarFormatNumber (bstr): returned %8lx\n", hres);
1521 if (hres == S_OK)
1522 ok(str && strcmpW(str, szResult2) == 0, "VarFormatNumber (-bstr): string different\n");
1523 SysFreeString(V_BSTR(&v));
1524 SysFreeString(str);
1527 #define SIGNED_VTBITS (VTBIT_I1|VTBIT_I2|VTBIT_I4|VTBIT_I8|VTBIT_R4|VTBIT_R8)
1529 static const char *szVarFmtFail = "VT %d|0x%04x Format %s: expected 0x%08lx, '%s', got 0x%08lx, '%s'\n";
1530 #define VARFMT(vt,v,val,fmt,ret,str) do { \
1531 if (out) SysFreeString(out); out = NULL; \
1532 V_VT(&in) = (vt); v(&in) = val; \
1533 if (fmt) MultiByteToWideChar(CP_ACP, 0, fmt, -1, buffW, sizeof(buffW)/sizeof(WCHAR)); \
1534 hres = pVarFormat(&in,fmt ? buffW : NULL,fd,fw,flags,&out); \
1535 if (SUCCEEDED(hres)) WideCharToMultiByte(CP_ACP, 0, out, -1, buff, sizeof(buff),0,0); \
1536 else buff[0] = '\0'; \
1537 ok(hres == ret && (FAILED(ret) || !strcmp(buff, str)), \
1538 szVarFmtFail, \
1539 (vt)&VT_TYPEMASK,(vt)&~VT_TYPEMASK,fmt?fmt:"<null>",ret,str,hres,buff); \
1540 } while(0)
1542 typedef struct tagFMTRES
1544 LPCSTR fmt;
1545 LPCSTR one_res;
1546 LPCSTR zero_res;
1547 } FMTRES;
1549 static const FMTRES VarFormat_results[] =
1551 { NULL, "1", "0" },
1552 { "", "1", "0" },
1553 { "General Number", "1", "0" },
1554 { "Percent", "100.00%", "0.00%" },
1555 { "Standard", "1.00", "0.00" },
1556 { "Scientific","1.00E+00", "0.00E+00" },
1557 { "True/False", "True", "False" },
1558 { "On/Off", "On", "Off" },
1559 { "Yes/No", "Yes", "No" },
1560 { "#", "1", "" },
1561 { "##", "1", "" },
1562 { "#.#", "1.", "." },
1563 { "0", "1", "0" },
1564 { "00", "01", "00" },
1565 { "0.0", "1.0", "0.0" },
1566 { "00\\c\\o\\p\\y", "01copy","00copy" },
1567 { "\"pos\";\"neg\"", "pos", "pos" },
1568 { "\"pos\";\"neg\";\"zero\"","pos", "zero" }
1571 typedef struct tagFMTDATERES
1573 DATE val;
1574 LPCSTR fmt;
1575 LPCSTR res;
1576 } FMTDATERES;
1578 static const FMTDATERES VarFormat_date_results[] =
1580 { 0.0, "w", "7" },
1581 { 0.0, "w", "6" },
1582 { 0.0, "w", "5" },
1583 { 0.0, "w", "4" },
1584 { 0.0, "w", "3" },
1585 { 0.0, "w", "2" },
1586 { 0.0, "w", "1" }, /* First 7 entries must remain in this order! */
1587 { 2.525, "am/pm", "pm" },
1588 { 2.525, "AM/PM", "PM" },
1589 { 2.525, "A/P", "P" },
1590 { 2.525, "a/p", "p" },
1591 { 2.525, "q", "1" },
1592 { 2.525, "d", "1" },
1593 { 2.525, "dd", "01" },
1594 { 2.525, "ddd", "Mon" },
1595 { 2.525, "dddd", "Monday" },
1596 { 2.525, "mmm", "Jan" },
1597 { 2.525, "mmmm", "January" },
1598 { 2.525, "y", "1" },
1599 { 2.525, "yy", "00" },
1600 { 2.525, "yyy", "001" },
1601 { 2.525, "yyyy", "1900" },
1602 { 2.525, "dd mm yyyy hh:mm:ss", "01 01 1900 12:36:00" },
1603 { 2.525, "dd mm yyyy mm", "01 01 1900 01" },
1604 { 2.525, "dd mm yyyy :mm", "01 01 1900 :01" },
1605 { 2.525, "dd mm yyyy hh:mm", "01 01 1900 12:36" },
1606 { 2.525, "mm mm", "01 01" },
1607 { 2.525, "mm :mm:ss", "01 :01:00" },
1608 { 2.525, "mm :ss:mm", "01 :00:01" },
1609 { 2.525, "hh:mm :ss:mm", "12:36 :00:01" },
1610 { 2.525, "hh:dd :mm:mm", "12:01 :01:01" },
1611 { 2.525, "dd:hh :mm:mm", "01:12 :36:01" },
1612 { 2.525, "hh :mm:mm", "12 :36:01" },
1613 { 2.525, "dd :mm:mm", "01 :01:01" },
1614 { 2.525, "dd :mm:nn", "01 :01:36" },
1615 { 2.725, "hh:nn:ss A/P", "05:24:00 P" }
1618 #define VNUMFMT(vt,v) \
1619 for (i = 0; i < sizeof(VarFormat_results)/sizeof(FMTRES); i++) \
1621 VARFMT(vt,v,1,VarFormat_results[i].fmt,S_OK,VarFormat_results[i].one_res); \
1622 VARFMT(vt,v,0,VarFormat_results[i].fmt,S_OK,VarFormat_results[i].zero_res); \
1624 if ((1 << vt) & SIGNED_VTBITS) \
1626 VARFMT(vt,v,-1,"\"pos\";\"neg\"",S_OK,"neg"); \
1627 VARFMT(vt,v,-1,"\"pos\";\"neg\";\"zero\"",S_OK,"neg"); \
1630 static void test_VarFormat(void)
1632 static const WCHAR szTesting[] = { 't','e','s','t','i','n','g','\0' };
1633 size_t i;
1634 WCHAR buffW[256];
1635 char buff[256];
1636 VARIANT in;
1637 VARIANT_BOOL bTrue = VARIANT_TRUE, bFalse = VARIANT_FALSE;
1638 int fd = 0, fw = 0;
1639 ULONG flags = 0;
1640 BSTR bstrin, out = NULL;
1641 HRESULT hres;
1643 CHECKPTR(VarFormat);
1645 if (PRIMARYLANGID(LANGIDFROMLCID(GetUserDefaultLCID())) != LANG_ENGLISH)
1647 trace("Skipping VarFormat tests for non english language\n");
1648 return;
1650 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char));
1651 if (buff[0] != '.' || buff[1])
1653 trace("Skipping VarFormat tests as decimal separator is '%s'\n", buff);
1654 return;
1656 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IDIGITS, buff, sizeof(buff)/sizeof(char));
1657 if (buff[0] != '2' || buff[1])
1659 trace("Skipping VarFormat tests as decimal places is '%s'\n", buff);
1660 return;
1663 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"True/False",S_OK,"True");
1664 VARFMT(VT_BOOL,V_BOOL,VARIANT_FALSE,"True/False",S_OK,"False");
1666 VNUMFMT(VT_I1,V_I1);
1667 VNUMFMT(VT_I2,V_I2);
1668 VNUMFMT(VT_I4,V_I4);
1669 if (HAVE_OLEAUT32_I8)
1671 VNUMFMT(VT_I8,V_I8);
1673 VNUMFMT(VT_INT,V_INT);
1674 VNUMFMT(VT_UI1,V_UI1);
1675 VNUMFMT(VT_UI2,V_UI2);
1676 VNUMFMT(VT_UI4,V_UI4);
1677 if (HAVE_OLEAUT32_I8)
1679 VNUMFMT(VT_UI8,V_UI8);
1681 VNUMFMT(VT_UINT,V_UINT);
1682 VNUMFMT(VT_R4,V_R4);
1683 VNUMFMT(VT_R8,V_R8);
1685 /* Reference types are dereferenced */
1686 VARFMT(VT_BOOL|VT_BYREF,V_BOOLREF,&bTrue,"True/False",S_OK,"True");
1687 VARFMT(VT_BOOL|VT_BYREF,V_BOOLREF,&bFalse,"True/False",S_OK,"False");
1689 /* Dates */
1690 for (i = 0; i < sizeof(VarFormat_date_results)/sizeof(FMTDATERES); i++)
1692 if (i < 7)
1693 fd = i + 1; /* Test first day */
1694 else
1695 fd = 0;
1696 VARFMT(VT_DATE,V_DATE,VarFormat_date_results[i].val,
1697 VarFormat_date_results[i].fmt,S_OK,
1698 VarFormat_date_results[i].res);
1701 /* Strings */
1702 bstrin = SysAllocString(szTesting);
1703 VARFMT(VT_BSTR,V_BSTR,bstrin,"",S_OK,"testing");
1704 VARFMT(VT_BSTR,V_BSTR,bstrin,"@",S_OK,"testing");
1705 VARFMT(VT_BSTR,V_BSTR,bstrin,"&",S_OK,"testing");
1706 VARFMT(VT_BSTR,V_BSTR,bstrin,"\\x@\\x@",S_OK,"xtxesting");
1707 VARFMT(VT_BSTR,V_BSTR,bstrin,"\\x&\\x&",S_OK,"xtxesting");
1708 VARFMT(VT_BSTR,V_BSTR,bstrin,"@\\x",S_OK,"txesting");
1709 VARFMT(VT_BSTR,V_BSTR,bstrin,"@@@@@@@@",S_OK," testing");
1710 VARFMT(VT_BSTR,V_BSTR,bstrin,"@\\x@@@@@@@",S_OK," xtesting");
1711 VARFMT(VT_BSTR,V_BSTR,bstrin,"&&&&&&&&",S_OK,"testing");
1712 VARFMT(VT_BSTR,V_BSTR,bstrin,"!&&&&&&&",S_OK,"testing");
1713 VARFMT(VT_BSTR,V_BSTR,bstrin,"&&&&&&&!",S_OK,"testing");
1714 VARFMT(VT_BSTR,V_BSTR,bstrin,">&&",S_OK,"TESTING");
1715 VARFMT(VT_BSTR,V_BSTR,bstrin,"<&&",S_OK,"testing");
1716 VARFMT(VT_BSTR,V_BSTR,bstrin,"<&>&",S_OK,"testing");
1717 SysFreeString(bstrin);
1718 /* Numeric values are converted to strings then output */
1719 VARFMT(VT_I1,V_I1,1,"<&>&",S_OK,"1");
1721 /* Number formats */
1722 VARFMT(VT_I4,V_I4,1,"#00000000",S_OK,"00000001");
1723 VARFMT(VT_I4,V_I4,1,"000###",S_OK,"000001");
1724 VARFMT(VT_I4,V_I4,1,"#00##00#0",S_OK,"00000001");
1725 VARFMT(VT_I4,V_I4,1,"1#####0000",S_OK,"10001");
1726 VARFMT(VT_R8,V_R8,1.23456789,"0#.0#0#0#0#0",S_OK,"01.234567890");
1727 VARFMT(VT_R8,V_R8,1.2,"0#.0#0#0#0#0",S_OK,"01.200000000");
1728 VARFMT(VT_R8,V_R8,9.87654321,"#0.#0#0#0#0#",S_OK,"9.87654321");
1729 VARFMT(VT_R8,V_R8,9.8,"#0.#0#0#0#0#",S_OK,"9.80000000");
1730 VARFMT(VT_R8,V_R8,0.00000008,"#0.#0#0#0#0#0",S_OK,"0.0000000800");
1731 VARFMT(VT_R8,V_R8,0.00010705,"#0.##########",S_OK,"0.00010705");
1732 VARFMT(VT_I4,V_I4,17,"#0",S_OK,"17");
1733 VARFMT(VT_I4,V_I4,4711,"#0",S_OK,"4711");
1734 VARFMT(VT_I4,V_I4,17,"#00",S_OK,"17");
1735 VARFMT(VT_I4,V_I4,100,"0##",S_OK,"100");
1736 VARFMT(VT_I4,V_I4,17,"#000",S_OK,"017");
1737 VARFMT(VT_I4,V_I4,17,"#0.00",S_OK,"17.00");
1738 VARFMT(VT_I4,V_I4,17,"#0000.00",S_OK,"0017.00");
1739 VARFMT(VT_I4,V_I4,17,"#.00",S_OK,"17.00");
1740 VARFMT(VT_R8,V_R8,1.7,"#.00",S_OK,"1.70");
1741 VARFMT(VT_R8,V_R8,.17,"#.00",S_OK,".17");
1742 VARFMT(VT_I4,V_I4,17,"#3",S_OK,"173");
1743 VARFMT(VT_I4,V_I4,17,"#33",S_OK,"1733");
1744 VARFMT(VT_I4,V_I4,17,"#3.33",S_OK,"173.33");
1745 VARFMT(VT_I4,V_I4,17,"#3333.33",S_OK,"173333.33");
1746 VARFMT(VT_I4,V_I4,17,"#.33",S_OK,"17.33");
1747 VARFMT(VT_R8,V_R8,.17,"#.33",S_OK,".33");
1748 VARFMT(VT_R8,V_R8,1.7,"0.0000E-000",S_OK,"1.7000E000");
1749 VARFMT(VT_R8,V_R8,1.7,"0.0000e-1",S_OK,"1.7000e01");
1750 VARFMT(VT_R8,V_R8,86.936849,"#0.000000000000e-000",S_OK,"86.936849000000e000");
1751 VARFMT(VT_R8,V_R8,1.7,"#0",S_OK,"2");
1752 VARFMT(VT_R8,V_R8,1.7,"#.33",S_OK,"2.33");
1753 VARFMT(VT_R8,V_R8,1.7,"#3",S_OK,"23");
1754 VARFMT(VT_R8,V_R8,1.73245,"0.0000E+000",S_OK,"1.7325E+000");
1755 VARFMT(VT_R8,V_R8,9.9999999,"#0.000000",S_OK,"10.000000");
1756 VARFMT(VT_R8,V_R8,1.7,"0.0000e+0#",S_OK,"1.7000e+0");
1757 VARFMT(VT_R8,V_R8,100.0001e+0,"0.0000E+0",S_OK,"1.0000E+2");
1758 VARFMT(VT_R8,V_R8,1000001,"0.0000e+1",S_OK,"1.0000e+61");
1759 VARFMT(VT_R8,V_R8,100.0001e+25,"0.0000e+0",S_OK,"1.0000e+27");
1760 VARFMT(VT_R8,V_R8,450.0001e+43,"#000.0000e+0",S_OK,"4500.0010e+42");
1761 VARFMT(VT_R8,V_R8,0.0001e-11,"##00.0000e-0",S_OK,"1000.0000e-18");
1762 VARFMT(VT_R8,V_R8,0.0317e-11,"0000.0000e-0",S_OK,"3170.0000e-16");
1763 VARFMT(VT_R8,V_R8,0.0021e-11,"00##.0000e-0",S_OK,"2100.0000e-17");
1764 VARFMT(VT_R8,V_R8,1.0001e-27,"##00.0000e-0",S_OK,"1000.1000e-30");
1765 VARFMT(VT_R8,V_R8,47.11,".0000E+0",S_OK,".4711E+2");
1766 VARFMT(VT_R8,V_R8,3.0401e-13,"#####.####e-0%",S_OK,"30401.e-15%");
1769 /* 'out' is not cleared */
1770 out = (BSTR)0x1;
1771 pVarFormat(&in,NULL,fd,fw,flags,&out); /* Would crash if out is cleared */
1772 out = NULL;
1774 /* Invalid args */
1775 hres = pVarFormat(&in,NULL,fd,fw,flags,NULL);
1776 ok(hres == E_INVALIDARG, "Null out: expected E_INVALIDARG, got 0x%08lx\n", hres);
1777 hres = pVarFormat(NULL,NULL,fd,fw,flags,&out);
1778 ok(hres == E_INVALIDARG, "Null in: expected E_INVALIDARG, got 0x%08lx\n", hres);
1779 fd = -1;
1780 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
1781 fd = 8;
1782 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
1783 fd = 0; fw = -1;
1784 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
1785 fw = 4;
1786 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
1789 static HRESULT (WINAPI *pVarAbs)(LPVARIANT,LPVARIANT);
1791 static const char *szVarAbsFail = "VarAbs: expected 0x0,%d,%d, got 0x%lX,%d,%d\n";
1792 #define VARABS(vt,val,rvt,rval) V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
1793 memset(&vDst,0,sizeof(vDst)); hres = pVarAbs(&v,&vDst); \
1794 ok(hres == S_OK && V_VT(&vDst) == VT_##rvt && V_##rvt(&vDst) == (rval), \
1795 szVarAbsFail, VT_##rvt, (int)(rval), \
1796 hres, V_VT(&vDst), (int)V_##rvt(&vDst))
1798 static void test_VarAbs(void)
1800 static const WCHAR szNum[] = {'-','1','.','1','\0' };
1801 char buff[8];
1802 HRESULT hres;
1803 VARIANT v, vDst;
1804 size_t i;
1806 CHECKPTR(VarAbs);
1808 /* Test all possible V_VT values.
1810 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
1812 VARTYPE vt;
1814 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
1816 HRESULT hExpected = DISP_E_BADVARTYPE;
1818 SKIPTESTS(vt);
1820 memset(&v, 0, sizeof(v));
1821 V_VT(&v) = vt | ExtraFlags[i];
1822 V_VT(&vDst) = VT_EMPTY;
1824 hres = pVarAbs(&v,&vDst);
1825 if (ExtraFlags[i] & (VT_ARRAY|VT_ARRAY) ||
1826 (!ExtraFlags[i] && (vt == VT_UNKNOWN || vt == VT_BSTR ||
1827 vt == VT_DISPATCH || vt == VT_ERROR || vt == VT_RECORD)))
1829 hExpected = DISP_E_TYPEMISMATCH;
1831 else if (ExtraFlags[i] || vt >= VT_CLSID || vt == VT_VARIANT)
1833 hExpected = DISP_E_BADVARTYPE;
1835 else if (IsValidVariantClearVT(vt, ExtraFlags[i]))
1836 hExpected = S_OK;
1838 /* Native always fails on some vartypes that should be valid. don't
1839 * check that Wine does the same; these are bugs in native.
1841 if (vt == VT_I8 || vt == VT_UI8 || vt == VT_INT || vt == VT_UINT ||
1842 vt == VT_I1 || vt == VT_UI2 || vt == VT_UI4)
1843 continue;
1844 ok(hres == hExpected, "VarAbs: expected 0x%lX, got 0x%lX for vt %d | 0x%X\n",
1845 hExpected, hres, vt, ExtraFlags[i]);
1849 /* BOOL->I2, BSTR->R8, all others remain the same */
1850 VARABS(BOOL,VARIANT_TRUE,I2,-VARIANT_TRUE);
1851 VARABS(BOOL,VARIANT_FALSE,I2,VARIANT_FALSE);
1852 VARABS(EMPTY,0,I2,0);
1853 VARABS(EMPTY,1,I2,0);
1854 VARABS(NULL,0,NULL,0);
1855 VARABS(NULL,1,NULL,0);
1856 VARABS(I2,1,I2,1);
1857 VARABS(I2,-1,I2,1);
1858 VARABS(I4,1,I4,1);
1859 VARABS(I4,-1,I4,1);
1860 VARABS(UI1,1,UI1,1);
1861 VARABS(R4,1,R4,1);
1862 VARABS(R4,-1,R4,1);
1863 VARABS(R8,1,R8,1);
1864 VARABS(R8,-1,R8,1);
1865 VARABS(DATE,1,DATE,1);
1866 VARABS(DATE,-1,DATE,1);
1867 V_VT(&v) = VT_CY;
1868 V_CY(&v).int64 = -10000;
1869 memset(&vDst,0,sizeof(vDst));
1870 hres = pVarAbs(&v,&vDst);
1871 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
1872 "VarAbs(CY): expected 0x0 got 0x%lX\n", hres);
1873 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char));
1874 if (buff[0] != '.' || buff[1])
1876 trace("Skipping VarAbs(BSTR) as decimal separator is '%s'\n", buff);
1877 return;
1879 V_VT(&v) = VT_BSTR;
1880 V_BSTR(&v) = (BSTR)szNum;
1881 memset(&vDst,0,sizeof(vDst));
1882 hres = pVarAbs(&v,&vDst);
1883 ok(hres == S_OK && V_VT(&vDst) == VT_R8 && V_R8(&vDst) == 1.1,
1884 "VarAbs: expected 0x0,%d,%g, got 0x%lX,%d,%g\n", VT_R8, 1.1, hres, V_VT(&vDst), V_R8(&vDst));
1887 static HRESULT (WINAPI *pVarNot)(LPVARIANT,LPVARIANT);
1889 static const char *szVarNotFail = "VarNot: expected 0x0,%d,%d, got 0x%lX,%d,%d\n";
1890 #define VARNOT(vt,val,rvt,rval) V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
1891 memset(&vDst,0,sizeof(vDst)); hres = pVarNot(&v,&vDst); \
1892 ok(hres == S_OK && V_VT(&vDst) == VT_##rvt && V_##rvt(&vDst) == (rval), \
1893 szVarNotFail, VT_##rvt, (int)(rval), \
1894 hres, V_VT(&vDst), (int)V_##rvt(&vDst))
1896 static void test_VarNot(void)
1898 static const WCHAR szNum0[] = {'0','\0' };
1899 static const WCHAR szNum1[] = {'1','\0' };
1900 HRESULT hres;
1901 VARIANT v, vDst;
1902 DECIMAL *pdec = &V_DECIMAL(&v);
1903 CY *pcy = &V_CY(&v);
1904 size_t i;
1906 CHECKPTR(VarNot);
1908 /* Test all possible V_VT values */
1909 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
1911 VARTYPE vt;
1913 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
1915 HRESULT hExpected = DISP_E_BADVARTYPE;
1917 SKIPTESTS(vt);
1919 memset(&v, 0, sizeof(v));
1920 V_VT(&v) = vt | ExtraFlags[i];
1921 V_VT(&vDst) = VT_EMPTY;
1923 switch (V_VT(&v))
1925 case VT_I1: case VT_UI1: case VT_I2: case VT_UI2:
1926 case VT_INT: case VT_UINT: case VT_I4: case VT_UI4:
1927 case VT_R4: case VT_R8:
1928 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
1929 case VT_DATE: case VT_CY:
1930 hExpected = S_OK;
1931 break;
1932 case VT_I8: case VT_UI8:
1933 if (HAVE_OLEAUT32_I8)
1934 hExpected = S_OK;
1935 break;
1936 case VT_RECORD:
1937 if (HAVE_OLEAUT32_RECORD)
1938 hExpected = DISP_E_TYPEMISMATCH;
1939 break;
1940 case VT_UNKNOWN: case VT_BSTR: case VT_DISPATCH: case VT_ERROR:
1941 hExpected = DISP_E_TYPEMISMATCH;
1942 break;
1943 default:
1944 if (IsValidVariantClearVT(vt, ExtraFlags[i]) && vt != VT_CLSID)
1945 hExpected = DISP_E_TYPEMISMATCH;
1946 break;
1949 hres = pVarNot(&v,&vDst);
1950 ok(hres == hExpected, "VarNot: expected 0x%lX, got 0x%lX vt %d|0x%X\n",
1951 hExpected, hres, vt, ExtraFlags[i]);
1954 /* Test the values returned by all cases that can succeed */
1955 VARNOT(EMPTY,0,I2,-1);
1956 VARNOT(EMPTY,1,I2,-1);
1957 VARNOT(NULL,0,NULL,0);
1958 VARNOT(NULL,1,NULL,0);
1959 VARNOT(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
1960 VARNOT(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
1961 VARNOT(I1,-1,I4,0);
1962 VARNOT(I1,0,I4,-1);
1963 VARNOT(I2,-1,I2,0);
1964 VARNOT(I2,0,I2,-1);
1965 VARNOT(I2,1,I2,-2);
1966 VARNOT(I4,1,I4,-2);
1967 VARNOT(I4,0,I4,-1);
1968 VARNOT(UI1,1,UI1,254);
1969 VARNOT(UI1,0,UI1,255);
1970 VARNOT(UI2,0,I4,-1);
1971 VARNOT(UI2,1,I4,-2);
1972 VARNOT(UI4,0,I4,-1);
1973 VARNOT(UI4,1,I4,-2);
1974 VARNOT(INT,0,I4,-1);
1975 VARNOT(INT,1,I4,-2);
1976 VARNOT(UINT,0,I4,-1);
1977 VARNOT(UINT,1,I4,-2);
1978 if (HAVE_OLEAUT32_I8)
1980 VARNOT(I8,1,I8,-2);
1981 VARNOT(I8,0,I8,-1);
1982 VARNOT(UI8,0,I4,-1);
1983 VARNOT(UI8,1,I4,-2);
1985 VARNOT(R4,1,I4,-2);
1986 VARNOT(R4,0,I4,-1);
1987 VARNOT(R8,1,I4,-2);
1988 VARNOT(R8,0,I4,-1);
1989 VARNOT(DATE,1,I4,-2);
1990 VARNOT(DATE,0,I4,-1);
1991 VARNOT(BSTR,(BSTR)szNum0,I4,-1);
1992 ok(V_VT(&v) == VT_BSTR && V_BSTR(&v) == szNum0, "VarNot(0): changed input\n");
1993 VARNOT(BSTR,(BSTR)szNum1,I4,-2);
1994 ok(V_VT(&v) == VT_BSTR && V_BSTR(&v) == szNum1, "VarNot(1): changed input\n");
1996 V_VT(&v) = VT_DECIMAL;
1997 S(U(*pdec)).sign = DECIMAL_NEG;
1998 S(U(*pdec)).scale = 0;
1999 pdec->Hi32 = 0;
2000 S1(U1(*pdec)).Mid32 = 0;
2001 S1(U1(*pdec)).Lo32 = 1;
2002 VARNOT(DECIMAL,*pdec,I4,0);
2004 pcy->int64 = 10000;
2005 VARNOT(CY,*pcy,I4,-2);
2007 pcy->int64 = 0;
2008 VARNOT(CY,*pcy,I4,-1);
2010 pcy->int64 = -1;
2011 VARNOT(CY,*pcy,I4,-1);
2013 static HRESULT (WINAPI *pVarSub)(LPVARIANT,LPVARIANT,LPVARIANT);
2015 static void test_VarSub(void)
2017 VARIANT va, vb, vc;
2018 HRESULT hr;
2020 CHECKPTR(VarSub);
2022 V_VT(&va) = VT_DATE;
2023 V_DATE(&va) = 200000.0;
2024 V_VT(&vb) = VT_DATE;
2025 V_DATE(&vb) = 100000.0;
2027 hr = pVarSub(&va, &vb, &vc);
2028 ok(hr == S_OK,"VarSub of VT_DATE - VT_DATE failed with %lx\n", hr);
2029 ok(V_VT(&vc) == VT_R8,"VarSub of VT_DATE - VT_DATE returned vt 0x%x\n", V_VT(&vc));
2030 ok(((V_R8(&vc) > 99999.9) && (V_R8(&vc) < 100000.1)),"VarSub of VT_DATE - VT_DATE should return 100000.0, but returned %g\n", V_R8(&vc));
2031 /* fprintf(stderr,"VarSub of 10000-20000 returned: %g\n", V_R8(&vc)); */
2034 static const char *szVarModFail = "VarMod: expected 0x%lx,%d(%s),%d, got 0x%lX,%d(%s),%d\n";
2035 #define VARMOD(vt1,vt2,val1,val2,rvt,rval,hexpected) V_VT(&v1) = VT_##vt1; V_##vt1(&v1) = val1; \
2036 V_VT(&v2) = VT_##vt2; V_##vt2(&v2) = val2; \
2037 memset(&vDst,0,sizeof(vDst)); hres = pVarMod(&v1,&v2,&vDst); \
2038 ok(hres == hexpected && V_VT(&vDst) == VT_##rvt && V_##rvt(&vDst) == (rval), \
2039 szVarModFail, hexpected, VT_##rvt, vtstr(VT_##rvt), (int)(rval), \
2040 hres, V_VT(&vDst), vtstr(V_VT(&vDst)), (int)V_##rvt(&vDst))
2042 static const char *szVarMod2Fail = "VarMod: expected 0x%lx,%d(%s),%d, got 0x%lX,%d(%s),%d\n";
2043 #define VARMOD2(vt1,vt2,val1,val2,rvt,rval,hexpected) V_VT(&v1) = VT_##vt1; V_I4(&v1) = val1; \
2044 V_VT(&v2) = VT_##vt2; V_I4(&v2) = val2; \
2045 memset(&vDst,0,sizeof(vDst)); hres = pVarMod(&v1,&v2,&vDst); \
2046 ok(hres == hexpected && V_VT(&vDst) == VT_##rvt && V_I4(&vDst) == (rval), \
2047 szVarMod2Fail, hexpected, VT_##rvt, vtstr(VT_##rvt), (int)(rval), \
2048 hres, V_VT(&vDst), vtstr(V_VT(&vDst)), (int)V_I4(&vDst))
2050 static HRESULT (WINAPI *pVarMod)(LPVARIANT,LPVARIANT,LPVARIANT);
2052 static void test_VarMod(void)
2054 VARIANT v1, v2, vDst;
2055 HRESULT hres;
2056 HRESULT hexpected = 0;
2057 static const WCHAR szNum0[] = {'1','2','5','\0'};
2058 static const WCHAR szNum1[] = {'1','0','\0'};
2059 int l, r;
2060 BOOL lFound, rFound;
2061 BOOL lValid, rValid;
2062 BSTR strNum0, strNum1;
2064 CHECKPTR(VarMod);
2066 VARMOD(I1,BOOL,100,10,I4,0,S_OK);
2067 VARMOD(I1,I1,100,10,I4,0,S_OK);
2068 VARMOD(I1,UI1,100,10,I4,0,S_OK);
2069 VARMOD(I1,I2,100,10,I4,0,S_OK);
2070 VARMOD(I1,UI2,100,10,I4,0,S_OK);
2071 VARMOD(I1,I4,100,10,I4,0,S_OK);
2072 VARMOD(I1,UI4,100,10,I4,0,S_OK);
2073 VARMOD(I1,R4,100,10,I4,0,S_OK);
2074 VARMOD(I1,R8,100,10,I4,0,S_OK);
2076 VARMOD(UI1,BOOL,100,10,I2,0,S_OK);
2077 VARMOD(UI1,I1,100,10,I4,0,S_OK);
2078 VARMOD(UI1,UI1,100,10,UI1,0,S_OK);
2079 VARMOD(UI1,I2,100,10,I2,0,S_OK);
2080 VARMOD(UI1,UI2,100,10,I4,0,S_OK);
2081 VARMOD(UI1,I4,100,10,I4,0,S_OK);
2082 VARMOD(UI1,UI4,100,10,I4,0,S_OK);
2083 VARMOD(UI1,R4,100,10,I4,0,S_OK);
2084 VARMOD(UI1,R8,100,10,I4,0,S_OK);
2086 VARMOD(I2,BOOL,100,10,I2,0,S_OK);
2087 VARMOD(I2,I1,100,10,I4,0,S_OK);
2088 VARMOD(I2,UI1,100,10,I2,0,S_OK);
2089 VARMOD(I2,I2,100,10,I2,0,S_OK);
2090 VARMOD(I2,UI2,100,10,I4,0,S_OK);
2091 VARMOD(I2,I4,100,10,I4,0,S_OK);
2092 VARMOD(I2,UI4,100,10,I4,0,S_OK);
2093 VARMOD(I2,R4,100,10,I4,0,S_OK);
2094 VARMOD(I2,R8,100,10,I4,0,S_OK);
2096 VARMOD(I4,BOOL,100,10,I4,0,S_OK);
2097 VARMOD(I4,I1,100,10,I4,0,S_OK);
2098 VARMOD(I4,UI1,100,10,I4,0,S_OK);
2099 VARMOD(I4,I2,100,10,I4,0,S_OK);
2100 VARMOD(I4,UI2,100,10,I4,0,S_OK);
2101 VARMOD(I4,I4,100,10,I4,0,S_OK);
2102 VARMOD(I4,UI4,100,10,I4,0,S_OK);
2103 VARMOD(I4,R4,100,10,I4,0,S_OK);
2104 VARMOD(I4,R8,100,10,I4,0,S_OK);
2105 VARMOD(UI4,BOOL,100,10,I4,0,S_OK);
2106 VARMOD(UI4,I1,100,10,I4,0,S_OK);
2107 VARMOD(UI4,UI1,100,10,I4,0,S_OK);
2108 VARMOD(UI4,I2,100,10,I4,0,S_OK);
2109 VARMOD(UI4,UI2,100,10,I4,0,S_OK);
2110 VARMOD(UI4,I4,100,10,I4,0,S_OK);
2111 VARMOD(UI4,UI4,100,10,I4,0,S_OK);
2112 VARMOD(UI4,R4,100,10,I4,0,S_OK);
2113 VARMOD(UI4,R8,100,10,I4,0,S_OK);
2114 VARMOD(R4,BOOL,100,10,I4,0,S_OK);
2115 VARMOD(R4,I1,100,10,I4,0,S_OK);
2116 VARMOD(R4,UI1,100,10,I4,0,S_OK);
2117 VARMOD(R4,I2,100,10,I4,0,S_OK);
2118 VARMOD(R4,UI2,100,10,I4,0,S_OK);
2119 VARMOD(R4,I4,100,10,I4,0,S_OK);
2120 VARMOD(R4,UI4,100,10,I4,0,S_OK);
2121 VARMOD(R4,R4,100,10,I4,0,S_OK);
2122 VARMOD(R4,R8,100,10,I4,0,S_OK);
2123 VARMOD(R8,BOOL,100,10,I4,0,S_OK);
2124 VARMOD(R8,I1,100,10,I4,0,S_OK);
2125 VARMOD(R8,UI1,100,10,I4,0,S_OK);
2126 VARMOD(R8,I2,100,10,I4,0,S_OK);
2127 VARMOD(R8,UI2,100,10,I4,0,S_OK);
2128 VARMOD(R8,I4,100,10,I4,0,S_OK);
2129 VARMOD(R8,UI4,100,10,I4,0,S_OK);
2130 VARMOD(R8,R4,100,10,I4,0,S_OK);
2131 VARMOD(R8,R8,100,10,I4,0,S_OK);
2133 VARMOD(INT,INT,100,10,I4,0,S_OK);
2134 VARMOD(INT,UINT,100,10,I4,0,S_OK);
2136 VARMOD(BOOL,BOOL,100,10,I2,0,S_OK);
2137 VARMOD(BOOL,I1,100,10,I4,0,S_OK);
2138 VARMOD(BOOL,UI1,100,10,I2,0,S_OK);
2139 VARMOD(BOOL,I2,100,10,I2,0,S_OK);
2140 VARMOD(BOOL,UI2,100,10,I4,0,S_OK);
2141 VARMOD(BOOL,I4,100,10,I4,0,S_OK);
2142 VARMOD(BOOL,UI4,100,10,I4,0,S_OK);
2143 VARMOD(BOOL,R4,100,10,I4,0,S_OK);
2144 VARMOD(BOOL,R8,100,10,I4,0,S_OK);
2145 VARMOD(BOOL,DATE,100,10,I4,0,S_OK);
2147 VARMOD(DATE,BOOL,100,10,I4,0,S_OK);
2148 VARMOD(DATE,I1,100,10,I4,0,S_OK);
2149 VARMOD(DATE,UI1,100,10,I4,0,S_OK);
2150 VARMOD(DATE,I2,100,10,I4,0,S_OK);
2151 VARMOD(DATE,UI2,100,10,I4,0,S_OK);
2152 VARMOD(DATE,I4,100,10,I4,0,S_OK);
2153 VARMOD(DATE,UI4,100,10,I4,0,S_OK);
2154 VARMOD(DATE,R4,100,10,I4,0,S_OK);
2155 VARMOD(DATE,R8,100,10,I4,0,S_OK);
2156 VARMOD(DATE,DATE,100,10,I4,0,S_OK);
2158 strNum0 = SysAllocString(szNum0);
2159 strNum1 = SysAllocString(szNum1);
2160 VARMOD(BSTR,BSTR,strNum0,strNum1,I4,5,S_OK);
2161 VARMOD(BSTR,I1,strNum0,10,I4,5,S_OK);
2162 VARMOD(BSTR,I2,strNum0,10,I4,5,S_OK);
2163 VARMOD(BSTR,I4,strNum0,10,I4,5,S_OK);
2164 VARMOD(BSTR,R4,strNum0,10,I4,5,S_OK);
2165 VARMOD(BSTR,R8,strNum0,10,I4,5,S_OK);
2166 VARMOD(I4,BSTR,125,strNum1,I4,5,S_OK);
2168 if (HAVE_OLEAUT32_I8)
2170 VARMOD(BOOL,I8,100,10,I8,0,S_OK);
2171 VARMOD(I1,I8,100,10,I8,0,S_OK);
2172 VARMOD(UI1,I8,100,10,I8,0,S_OK);
2173 VARMOD(I2,I8,100,10,I8,0,S_OK);
2174 VARMOD(I4,I8,100,10,I8,0,S_OK);
2175 VARMOD(UI4,I8,100,10,I8,0,S_OK);
2176 VARMOD(R4,I8,100,10,I8,0,S_OK);
2177 VARMOD(R8,I8,100,10,I8,0,S_OK);
2178 VARMOD(DATE,I8,100,10,I8,0,S_OK);
2180 VARMOD(I8,BOOL,100,10,I8,0,S_OK);
2181 VARMOD(I8,I1,100,10,I8,0,S_OK);
2182 VARMOD(I8,UI1,100,10,I8,0,S_OK);
2183 VARMOD(I8,I2,100,10,I8,0,S_OK);
2184 VARMOD(I8,UI2,100,10,I8,0,S_OK);
2185 VARMOD(I8,I4,100,10,I8,0,S_OK);
2186 VARMOD(I8,UI4,100,10,I8,0,S_OK);
2187 VARMOD(I8,R4,100,10,I8,0,S_OK);
2188 VARMOD(I8,R8,100,10,I8,0,S_OK);
2189 VARMOD(I8,I8,100,10,I8,0,S_OK);
2191 VARMOD(BSTR,I8,strNum0,10,I8,5,S_OK);
2194 /* test all combinations of types */
2195 for(l = 0; l < VT_BSTR_BLOB; l++)
2197 SKIPTESTS(l);
2199 for(r = 0; r < VT_BSTR_BLOB; r++)
2201 SKIPTESTS(r);
2203 if(l == VT_BSTR) continue;
2204 if(l == VT_DISPATCH) continue;
2205 if(r == VT_BSTR) continue;
2206 if(r == VT_DISPATCH) continue;
2208 lFound = TRUE;
2209 lValid = TRUE;
2210 switch(l)
2212 case VT_EMPTY:
2213 case VT_NULL:
2214 case VT_I1:
2215 case VT_UI1:
2216 case VT_I2:
2217 case VT_UI2:
2218 case VT_I4:
2219 case VT_I8:
2220 case VT_UI4:
2221 case VT_UI8:
2222 case VT_INT:
2223 case VT_UINT:
2224 case VT_R4:
2225 case VT_R8:
2226 case VT_BOOL:
2227 case VT_DATE:
2228 case VT_CY:
2229 hexpected = S_OK;
2230 break;
2231 case VT_ERROR:
2232 case VT_VARIANT:
2233 case VT_UNKNOWN:
2234 case VT_DECIMAL:
2235 case VT_RECORD:
2236 lValid = FALSE;
2237 break;
2238 default:
2239 lFound = FALSE;
2240 hexpected = DISP_E_BADVARTYPE;
2241 break;
2244 rFound = TRUE;
2245 rValid = TRUE;
2246 switch(r)
2248 case VT_EMPTY:
2249 case VT_NULL:
2250 case VT_I1:
2251 case VT_UI1:
2252 case VT_I2:
2253 case VT_UI2:
2254 case VT_I4:
2255 case VT_I8:
2256 case VT_UI4:
2257 case VT_UI8:
2258 case VT_INT:
2259 case VT_UINT:
2260 case VT_R4:
2261 case VT_R8:
2262 case VT_BOOL:
2263 case VT_DATE:
2264 case VT_CY:
2265 hexpected = S_OK;
2266 break;
2267 case VT_ERROR:
2268 case VT_VARIANT:
2269 case VT_UNKNOWN:
2270 case VT_DECIMAL:
2271 case VT_RECORD:
2272 rValid = FALSE;
2273 break;
2274 default:
2275 rFound = FALSE;
2276 break;
2279 if(((l == VT_I8) && (r == VT_INT)) || ((l == VT_INT) && (r == VT_I8)))
2281 hexpected = DISP_E_TYPEMISMATCH;
2282 } else if((l == VT_EMPTY) && (r == VT_NULL))
2284 hexpected = S_OK;
2285 } else if((l == VT_NULL) && (r == VT_EMPTY))
2287 hexpected = S_OK;
2288 } else if((l == VT_EMPTY) && (r == VT_CY))
2290 hexpected = S_OK;
2291 } else if((l == VT_EMPTY) && (r == VT_RECORD))
2293 hexpected = DISP_E_TYPEMISMATCH;
2294 } else if((r == VT_EMPTY) && lFound && lValid)
2296 hexpected = DISP_E_DIVBYZERO;
2297 } else if((l == VT_ERROR) || ((r == VT_ERROR) && lFound && lValid))
2299 hexpected = DISP_E_TYPEMISMATCH;
2300 } else if((l == VT_NULL) && (r == VT_NULL))
2302 hexpected = S_OK;
2303 } else if((l == VT_VARIANT) || ((r == VT_VARIANT) && lFound && lValid))
2305 hexpected = DISP_E_TYPEMISMATCH;
2306 } else if((l == VT_NULL) && (r == VT_RECORD))
2308 hexpected = DISP_E_TYPEMISMATCH;
2309 } else if((l == VT_NULL) && (r == VT_DECIMAL))
2311 hexpected = DISP_E_OVERFLOW;
2312 } else if((l == VT_UNKNOWN) || ((r == VT_UNKNOWN) && lFound && lValid))
2314 hexpected = DISP_E_TYPEMISMATCH;
2315 } else if((l == VT_NULL) && rFound)
2317 hexpected = S_OK;
2318 } else if((l == VT_DECIMAL) || ((r == VT_DECIMAL) && lFound && lValid))
2320 hexpected = DISP_E_OVERFLOW;
2321 } else if(l == VT_RECORD)
2323 hexpected = DISP_E_TYPEMISMATCH;
2324 } else if((r == VT_RECORD) && lValid && lFound)
2326 hexpected = DISP_E_TYPEMISMATCH;
2327 } else if((l == VT_EMPTY) && (r == VT_EMPTY))
2329 hexpected = DISP_E_DIVBYZERO;
2330 } else if((l == VT_CY) && !rFound)
2332 hexpected = DISP_E_BADVARTYPE;
2333 } else if(lFound && !rFound)
2335 hexpected = DISP_E_BADVARTYPE;
2336 } else if(!lFound && rFound)
2338 hexpected = DISP_E_BADVARTYPE;
2339 } else if((r == VT_NULL) && lFound && lValid)
2341 hexpected = S_OK;
2342 } else if((l == VT_NULL) || (r == VT_NULL))
2344 hexpected = DISP_E_BADVARTYPE;
2345 } else if((l == VT_VARIANT) || (r == VT_VARIANT))
2347 hexpected = DISP_E_BADVARTYPE;
2348 } else if(lFound && !rFound)
2350 hexpected = DISP_E_BADVARTYPE;
2351 } else if(!lFound && !rFound)
2353 hexpected = DISP_E_BADVARTYPE;
2356 V_VT(&v1) = l;
2357 V_VT(&v2) = r;
2359 if(l == VT_CY)
2360 V_CY(&v1).int64 = 1000000;
2361 else if(l == VT_R4)
2362 V_R4(&v1) = 100;
2363 else if(l == VT_R8)
2364 V_R8(&v1) = 100;
2365 else if(l == VT_UI8)
2366 V_UI8(&v1) = 100;
2367 else if(l == VT_DATE)
2368 V_DATE(&v1) = 1000;
2369 else
2370 V_I4(&v1) = 10000;
2372 if(r == VT_CY)
2373 V_CY(&v2).int64 = 10000;
2374 else if(r == VT_R4)
2375 V_R4(&v2) = 100;
2376 else if(r == VT_R8)
2377 V_R8(&v2) = 100;
2378 else if(r == VT_UI8)
2379 V_UI8(&v2) = 100;
2380 else if(r == VT_DATE)
2381 V_DATE(&v2) = 1000;
2382 else
2383 V_I4(&v2) = 10000;
2385 if ((l != VT_I8 && l != VT_UI8 && r != VT_I8 && r != VT_UI8) || HAVE_OLEAUT32_I8)
2387 hres = pVarMod(&v1,&v2,&vDst);
2388 ok(hres == hexpected,
2389 "VarMod: expected 0x%lx, got 0x%lX for l type of %d, r type of %d,\n", hexpected, hres, l, r);
2395 /****************************/
2396 /* test some bad parameters */
2397 VARMOD(I4,I4,-1,-1,I4,0,S_OK);
2399 /* test modulus with zero */
2400 VARMOD2(I4,I4,100,0,EMPTY,0,DISP_E_DIVBYZERO);
2402 VARMOD(I4,I4,0,10,I4,0,S_OK); /* test 0 mod 10 */
2404 /* right parameter is type empty */
2405 VARMOD2(I4,EMPTY,100,10,EMPTY,0,DISP_E_DIVBYZERO);
2407 /* left parameter is type empty */
2408 VARMOD2(EMPTY,I4,100,10,I4,0,S_OK);
2410 /* mod with a null left value */
2411 VARMOD2(NULL,I4,125,10,NULL,0,S_OK);
2413 /* mod with a null right value */
2414 VARMOD2(I4,NULL,100,10,NULL,0,S_OK);
2416 /* void left value */
2417 VARMOD2(VOID,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2419 /* void right value */
2420 VARMOD2(I4,VOID,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2422 /* null left value, void right value */
2423 VARMOD2(NULL,VOID,100,10,EMPTY, 0, DISP_E_BADVARTYPE);
2425 /* void left value, null right value */
2426 VARMOD2(VOID,NULL,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2428 /* some currencies */
2429 V_VT(&v1) = VT_CY;
2430 V_VT(&v2) = VT_CY;
2431 V_CY(&v1).int64 = 100000;
2432 V_CY(&v2).int64 = 100000;
2433 hres = pVarMod(&v1,&v2,&vDst);
2434 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
2435 "VarMod: expected 0x%lx,%d,%d, got 0x%lX,%d,%ld\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
2437 V_VT(&v1) = VT_I4;
2438 V_VT(&v2) = VT_CY;
2439 V_I4(&v1) = 100;
2440 V_CY(&v2).int64 = 100000;
2441 hres = pVarMod(&v1,&v2,&vDst);
2442 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
2443 "VarMod: expected 0x%lx,%d,%d, got 0x%lX,%d,%ld\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
2445 VARMOD2(UINT,I4,100,10,I4,0,S_OK);
2447 /* test that an error results in the type of the result changing but not its value */
2448 V_VT(&v1) = VT_UNKNOWN;
2449 V_VT(&v2) = VT_EMPTY;
2450 V_I4(&v1) = 100;
2451 V_CY(&v2).int64 = 100000;
2452 V_VT(&vDst) = VT_I4;
2453 V_I4(&vDst) = 1231;
2454 hres = pVarMod(&v1,&v2,&vDst);
2455 ok(hres == DISP_E_TYPEMISMATCH && V_VT(&vDst) == VT_EMPTY && V_I4(&vDst) == 1231,
2456 "VarMod: expected 0x%lx,%d,%d, got 0x%lX,%d,%ld\n", DISP_E_TYPEMISMATCH, VT_EMPTY, 1231, hres, V_VT(&vDst), V_I4(&vDst));
2459 /* test some invalid types */
2460 /*TODO: not testing VT_DISPATCH */
2461 if (HAVE_OLEAUT32_I8)
2463 VARMOD2(I8,INT,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
2465 VARMOD2(ERROR,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
2466 VARMOD2(VARIANT,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
2467 VARMOD2(UNKNOWN,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
2468 VARMOD2(DECIMAL,I4,100,10,EMPTY,0,DISP_E_OVERFLOW);
2469 VARMOD2(VOID,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2470 VARMOD2(HRESULT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2471 VARMOD2(PTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2472 VARMOD2(SAFEARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2473 VARMOD2(CARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2474 VARMOD2(USERDEFINED,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2475 VARMOD2(LPSTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2476 VARMOD2(LPWSTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2477 VARMOD2(RECORD,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
2478 VARMOD2(FILETIME,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2479 VARMOD2(BLOB,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2480 VARMOD2(STREAM,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2481 VARMOD2(STORAGE,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2482 VARMOD2(STREAMED_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2483 VARMOD2(STORED_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2484 VARMOD2(BLOB_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2485 VARMOD2(CF,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2486 VARMOD2(CLSID,CLSID,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2487 VARMOD2(VECTOR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2488 VARMOD2(ARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2489 VARMOD2(BYREF,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2491 /* test some more invalid types */
2492 V_VT(&v1) = 456;
2493 V_VT(&v2) = 234;
2494 V_I4(&v1) = 100;
2495 V_I4(&v2)= 10;
2496 hres = pVarMod(&v1,&v2,&vDst);
2497 ok(hres == DISP_E_BADVARTYPE && V_VT(&vDst) == VT_EMPTY && V_I4(&vDst) == 0,
2498 "VarMod: expected 0x%lx,%d,%d, got 0x%lX,%d,%ld\n", DISP_E_BADVARTYPE, VT_EMPTY, 0, hres, V_VT(&vDst), V_I4(&vDst));
2501 static HRESULT (WINAPI *pVarFix)(LPVARIANT,LPVARIANT);
2503 static const char *szVarFixFail = "VarFix: expected 0x0,%d,%d, got 0x%lX,%d,%d\n";
2504 #define VARFIX(vt,val,rvt,rval) V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
2505 memset(&vDst,0,sizeof(vDst)); hres = pVarFix(&v,&vDst); \
2506 ok(hres == S_OK && V_VT(&vDst) == VT_##rvt && V_##rvt(&vDst) == (rval), \
2507 szVarFixFail, VT_##rvt, (int)(rval), \
2508 hres, V_VT(&vDst), (int)V_##rvt(&vDst))
2510 static void test_VarFix(void)
2512 static const WCHAR szNumMinus1[] = {'-','1','\0' };
2513 HRESULT hres;
2514 VARIANT v, vDst;
2515 DECIMAL *pdec = &V_DECIMAL(&v);
2516 CY *pcy = &V_CY(&v);
2517 size_t i;
2519 CHECKPTR(VarFix);
2521 /* Test all possible V_VT values */
2522 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2524 VARTYPE vt;
2526 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2528 HRESULT bFail = TRUE;
2530 SKIPTESTS(vt);
2532 memset(&v, 0, sizeof(v));
2533 V_VT(&v) = vt | ExtraFlags[i];
2534 V_VT(&vDst) = VT_EMPTY;
2536 switch (V_VT(&v))
2538 case VT_UI1: case VT_I2: case VT_I4: case VT_R4: case VT_R8:
2539 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
2540 case VT_DATE: case VT_CY:
2541 bFail = FALSE;
2542 break;
2543 case VT_I8:
2544 if (HAVE_OLEAUT32_I8)
2545 bFail = FALSE;
2546 break;
2549 hres = pVarFix(&v,&vDst);
2550 if (bFail)
2551 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
2552 "VarFix: expected failure, got 0x%lX vt %d|0x%X\n",
2553 hres, vt, ExtraFlags[i]);
2554 else
2555 ok(hres == S_OK, "VarFix: expected S_OK, got 0x%lX vt %d|0x%X\n",
2556 hres, vt, ExtraFlags[i]);
2560 VARFIX(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE);
2561 VARFIX(BOOL,VARIANT_FALSE,I2,0);
2562 VARFIX(BOOL,1,I2,1);
2563 VARFIX(UI1,1,UI1,1);
2564 VARFIX(I2,-1,I2,-1);
2565 VARFIX(I4,-1,I4,-1);
2566 if (HAVE_OLEAUT32_I8)
2568 VARFIX(I8,-1,I8,-1);
2570 VARFIX(R4,1.4,R4,1);
2571 VARFIX(R4,1.5,R4,1);
2572 VARFIX(R4,1.6,R4,1);
2573 VARFIX(R4,-1.4,R4,-1);
2574 VARFIX(R4,-1.5,R4,-1);
2575 VARFIX(R4,-1.6,R4,-1);
2576 /* DATE & R8 round as for R4 */
2577 VARFIX(DATE,-1,DATE,-1);
2578 VARFIX(R8,-1,R8,-1);
2579 VARFIX(BSTR,(BSTR)szNumMinus1,R8,-1);
2581 V_VT(&v) = VT_EMPTY;
2582 hres = pVarFix(&v,&vDst);
2583 ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
2584 "VarFix: expected 0x0,%d,0 got 0x%lX,%d,%d\n", VT_EMPTY,
2585 hres, V_VT(&vDst), V_I2(&vDst));
2587 V_VT(&v) = VT_NULL;
2588 hres = pVarFix(&v,&vDst);
2589 ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
2590 "VarFix: expected 0x0,%d got 0x%lX,%d\n", VT_NULL, hres, V_VT(&vDst));
2592 V_VT(&v) = VT_DECIMAL;
2593 S(U(*pdec)).sign = DECIMAL_NEG;
2594 S(U(*pdec)).scale = 0;
2595 pdec->Hi32 = 0;
2596 S1(U1(*pdec)).Mid32 = 0;
2597 S1(U1(*pdec)).Lo32 = 1;
2598 hres = pVarFix(&v,&vDst);
2599 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && !memcmp(&v, &vDst, sizeof(v)),
2600 "VarFix: expected 0x0,%d,identical, got 0x%lX,%d\n", VT_DECIMAL,
2601 hres, V_VT(&vDst));
2603 /* FIXME: Test some fractional decimals when VarDecFix is implemented */
2605 V_VT(&v) = VT_CY;
2606 pcy->int64 = -10000;
2607 hres = pVarFix(&v,&vDst);
2608 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
2609 "VarFix: VT_CY wrong, hres=0x%lX\n", hres);
2611 V_VT(&v) = VT_CY;
2612 pcy->int64 = -16000;
2613 hres = pVarFix(&v,&vDst);
2614 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
2615 "VarFix: VT_CY wrong, hres=0x%lX\n", hres);
2618 static HRESULT (WINAPI *pVarInt)(LPVARIANT,LPVARIANT);
2620 static const char *szVarIntFail = "VarInt: expected 0x0,%d,%d, got 0x%lX,%d,%d\n";
2621 #define VARINT(vt,val,rvt,rval) V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
2622 memset(&vDst,0,sizeof(vDst)); hres = pVarInt(&v,&vDst); \
2623 ok(hres == S_OK && V_VT(&vDst) == VT_##rvt && V_##rvt(&vDst) == (rval), \
2624 szVarIntFail, VT_##rvt, (int)(rval), \
2625 hres, V_VT(&vDst), (int)V_##rvt(&vDst))
2627 static void test_VarInt(void)
2629 static const WCHAR szNumMinus1[] = {'-','1','\0' };
2630 HRESULT hres;
2631 VARIANT v, vDst;
2632 DECIMAL *pdec = &V_DECIMAL(&v);
2633 CY *pcy = &V_CY(&v);
2634 size_t i;
2636 CHECKPTR(VarInt);
2638 /* Test all possible V_VT values */
2639 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2641 VARTYPE vt;
2643 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2645 HRESULT bFail = TRUE;
2647 SKIPTESTS(vt);
2649 memset(&v, 0, sizeof(v));
2650 V_VT(&v) = vt | ExtraFlags[i];
2651 V_VT(&vDst) = VT_EMPTY;
2653 switch (V_VT(&v))
2655 case VT_UI1: case VT_I2: case VT_I4: case VT_R4: case VT_R8:
2656 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
2657 case VT_DATE: case VT_CY:
2658 bFail = FALSE;
2659 break;
2660 case VT_I8:
2661 if (HAVE_OLEAUT32_I8)
2662 bFail = FALSE;
2663 break;
2666 hres = pVarInt(&v,&vDst);
2667 if (bFail)
2668 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
2669 "VarInt: expected failure, got 0x%lX vt %d|0x%X\n",
2670 hres, vt, ExtraFlags[i]);
2671 else
2672 ok(hres == S_OK, "VarInt: expected S_OK, got 0x%lX vt %d|0x%X\n",
2673 hres, vt, ExtraFlags[i]);
2677 VARINT(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE);
2678 VARINT(BOOL,VARIANT_FALSE,I2,0);
2679 VARINT(BOOL,1,I2,1);
2680 VARINT(UI1,1,UI1,1);
2681 VARINT(I2,-1,I2,-1);
2682 VARINT(I4,-1,I4,-1);
2683 if (HAVE_OLEAUT32_I8)
2685 VARINT(I8,-1,I8,-1);
2687 VARINT(R4,1.4,R4,1);
2688 VARINT(R4,1.5,R4,1);
2689 VARINT(R4,1.6,R4,1);
2690 VARINT(R4,-1.4,R4,-2); /* Note these 3 are different from VarFix */
2691 VARINT(R4,-1.5,R4,-2);
2692 VARINT(R4,-1.6,R4,-2);
2693 /* DATE & R8 round as for R4 */
2694 VARINT(DATE,-1,DATE,-1);
2695 VARINT(R8,-1,R8,-1);
2696 VARINT(BSTR,(BSTR)szNumMinus1,R8,-1);
2698 V_VT(&v) = VT_EMPTY;
2699 hres = pVarInt(&v,&vDst);
2700 ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
2701 "VarInt: expected 0x0,%d,0 got 0x%lX,%d,%d\n", VT_EMPTY,
2702 hres, V_VT(&vDst), V_I2(&vDst));
2704 V_VT(&v) = VT_NULL;
2705 hres = pVarInt(&v,&vDst);
2706 ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
2707 "VarInt: expected 0x0,%d got 0x%lX,%d\n", VT_NULL, hres, V_VT(&vDst));
2709 V_VT(&v) = VT_DECIMAL;
2710 S(U(*pdec)).sign = DECIMAL_NEG;
2711 S(U(*pdec)).scale = 0;
2712 pdec->Hi32 = 0;
2713 S1(U1(*pdec)).Mid32 = 0;
2714 S1(U1(*pdec)).Lo32 = 1;
2715 hres = pVarInt(&v,&vDst);
2716 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && !memcmp(&v, &vDst, sizeof(v)),
2717 "VarInt: expected 0x0,%d,identical, got 0x%lX,%d\n", VT_DECIMAL,
2718 hres, V_VT(&vDst));
2720 /* FIXME: Test some fractional decimals when VarDecInt is implemented */
2722 V_VT(&v) = VT_CY;
2723 pcy->int64 = -10000;
2724 hres = pVarInt(&v,&vDst);
2725 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
2726 "VarInt: VT_CY wrong, hres=0x%lX\n", hres);
2728 V_VT(&v) = VT_CY;
2729 pcy->int64 = -11000;
2730 hres = pVarInt(&v,&vDst);
2731 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -20000,
2732 "VarInt: VT_CY wrong, hres=0x%lX %lld\n", hres,V_CY(&vDst).int64);
2735 static HRESULT (WINAPI *pVarNeg)(LPVARIANT,LPVARIANT);
2737 static const char *szVarNegFail = "VarNeg: expected 0x0,%d,%d, got 0x%lX,%d,%d\n";
2738 #define VARNEG(vt,val,rvt,rval) V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
2739 memset(&vDst,0,sizeof(vDst)); hres = pVarNeg(&v,&vDst); \
2740 ok(hres == S_OK && V_VT(&vDst) == VT_##rvt && V_##rvt(&vDst) == (rval), \
2741 szVarNegFail, VT_##rvt, (int)(rval), \
2742 hres, V_VT(&vDst), (int)V_##rvt(&vDst))
2744 static void test_VarNeg(void)
2746 static const WCHAR szNumMinus1[] = {'-','1','\0' };
2747 static const WCHAR szNum1[] = {'1','\0' };
2748 HRESULT hres;
2749 VARIANT v, vDst;
2750 DECIMAL *pdec = &V_DECIMAL(&v);
2751 CY *pcy = &V_CY(&v);
2752 size_t i;
2754 CHECKPTR(VarNeg);
2756 /* Test all possible V_VT values. But don't test the exact return values
2757 * except for success/failure, since M$ made a hash of them in the
2758 * native version. This at least ensures (as with all tests here) that
2759 * we will notice if/when new vtypes/flags are added in native.
2761 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2763 VARTYPE vt;
2765 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2767 HRESULT bFail = TRUE;
2769 SKIPTESTS(vt);
2771 memset(&v, 0, sizeof(v));
2772 V_VT(&v) = vt | ExtraFlags[i];
2773 V_VT(&vDst) = VT_EMPTY;
2775 switch (V_VT(&v))
2777 case VT_UI1: case VT_I2: case VT_I4:
2778 case VT_R4: case VT_R8:
2779 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
2780 case VT_DATE: case VT_CY:
2781 bFail = FALSE;
2782 break;
2783 case VT_I8:
2784 if (HAVE_OLEAUT32_I8)
2785 bFail = FALSE;
2788 hres = pVarNeg(&v,&vDst);
2789 if (bFail)
2790 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
2791 "VarNeg: expected failure, got 0x%lX vt %d|0x%X\n",
2792 hres, vt, ExtraFlags[i]);
2793 else
2794 ok(hres == S_OK, "VarNeg: expected S_OK, got 0x%lX vt %d|0x%X\n",
2795 hres, vt, ExtraFlags[i]);
2799 VARNEG(BOOL,VARIANT_TRUE,I2,1);
2800 VARNEG(BOOL,VARIANT_FALSE,I2,0);
2801 VARNEG(BOOL,1,I2,-1);
2802 VARNEG(UI1,1,I2,-1);
2803 VARNEG(UI1,254,I2,-254);
2804 VARNEG(I2,-32768,I4,32768);
2805 VARNEG(I2,-1,I2,1);
2806 VARNEG(I2,1,I2,-1);
2807 VARNEG(I4,-((int)(~0u >> 1)) - 1,R8,-2147483648u);
2808 VARNEG(I4,-1,I4,1);
2809 VARNEG(I4,1,I4,-1);
2810 if (HAVE_OLEAUT32_I8)
2812 VARNEG(I8,1,I8,-1);
2813 VARNEG(I8,-1,I8,1);
2815 VARNEG(R4,1,R4,-1);
2816 VARNEG(R4,-1,R4,1);
2817 VARNEG(DATE,1,DATE,-1);
2818 VARNEG(DATE,-1,DATE,1);
2819 VARNEG(R8,1,R8,-1);
2820 VARNEG(R8,-1,R8,1);
2821 VARNEG(BSTR,(BSTR)szNumMinus1,R8,1);
2822 VARNEG(BSTR,(BSTR)szNum1,R8,-1);
2824 V_VT(&v) = VT_EMPTY;
2825 hres = pVarNeg(&v,&vDst);
2826 ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
2827 "VarNeg: expected 0x0,%d,0 got 0x%lX,%d,%d\n", VT_EMPTY,
2828 hres, V_VT(&vDst), V_I2(&vDst));
2830 V_VT(&v) = VT_NULL;
2831 hres = pVarNeg(&v,&vDst);
2832 ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
2833 "VarNeg: expected 0x0,%d got 0x%lX,%d\n", VT_NULL, hres, V_VT(&vDst));
2835 V_VT(&v) = VT_DECIMAL;
2836 S(U(*pdec)).sign = DECIMAL_NEG;
2837 S(U(*pdec)).scale = 0;
2838 pdec->Hi32 = 0;
2839 S1(U1(*pdec)).Mid32 = 0;
2840 S1(U1(*pdec)).Lo32 = 1;
2841 hres = pVarNeg(&v,&vDst);
2842 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
2843 S(U(V_DECIMAL(&vDst))).sign == 0,
2844 "VarNeg: expected 0x0,%d,0x00, got 0x%lX,%d,%02x\n", VT_DECIMAL,
2845 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
2847 S(U(*pdec)).sign = 0;
2848 hres = pVarNeg(&v,&vDst);
2849 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
2850 S(U(V_DECIMAL(&vDst))).sign == DECIMAL_NEG,
2851 "VarNeg: expected 0x0,%d,0x7f, got 0x%lX,%d,%02x\n", VT_DECIMAL,
2852 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
2854 V_VT(&v) = VT_CY;
2855 pcy->int64 = -10000;
2856 hres = pVarNeg(&v,&vDst);
2857 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
2858 "VarNeg: VT_CY wrong, hres=0x%lX\n", hres);
2861 static HRESULT (WINAPI *pVarRound)(LPVARIANT,int,LPVARIANT);
2863 #define VARROUND(vt,val,deci,rvt,rval) V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
2864 memset(&vDst,0,sizeof(vDst)); hres = pVarRound(&v,deci,&vDst); \
2865 ok(hres == S_OK && V_VT(&vDst) == VT_##rvt && V_##rvt(&vDst) == (rval), \
2866 "VarRound: expected 0x0,%d,%d, got 0x%lX,%d,%d\n", VT_##rvt, (int)(rval), \
2867 hres, V_VT(&vDst), (int)V_##rvt(&vDst))
2869 #define VARROUNDF(vt,val,deci,rvt,rval) V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
2870 memset(&vDst,0,sizeof(vDst)); hres = pVarRound(&v,deci,&vDst); \
2871 ok(hres == S_OK && V_VT(&vDst) == VT_##rvt && V_##rvt(&vDst) == (rval), \
2872 "VarRound: expected 0x0,%d,%f, got 0x%lX,%d,%f\n", VT_##rvt, rval, \
2873 hres, V_VT(&vDst), V_##rvt(&vDst))
2875 static void test_VarRound(void)
2877 /* static const WCHAR szNumMin[] = {'-','1','.','4','5','\0' };
2878 static const WCHAR szNum[] = {'1','.','4','5','\0' }; */
2879 HRESULT hres;
2880 VARIANT v, vDst;
2881 CY *pcy = &V_CY(&v);
2883 CHECKPTR(VarRound);
2885 /* first check valid integer types */
2886 VARROUND(BOOL,VARIANT_TRUE,0,I2,-1);
2887 VARROUND(BOOL,VARIANT_FALSE,0,I2,0);
2888 VARROUND(BOOL,1,0,I2,1);
2889 VARROUND(UI1,1,0,UI1,1);
2890 VARROUND(UI1,254,0,UI1,254);
2891 VARROUND(I2,-32768,0,I2,-32768);
2892 VARROUND(I2,-1,0,I2,-1);
2893 VARROUND(I2,1,0,I2,1);
2894 VARROUND(I4,-((int)(~0u >> 1)) - 1,0,I4,-((int)(~0u >> 1)) - 1);
2895 VARROUND(I4,-1,0,I4,-1);
2896 VARROUND(I4,1,0,I4,1);
2899 /* MSDN states that rounding of R4/R8 is dependent on the underlying
2900 * bit pattern of the number and so is architecture dependent. In this
2901 * case Wine returns .2 (which is more correct) and Native returns .3
2904 VARROUNDF(R4,1.0,0,R4,1.0);
2905 VARROUNDF(R4,-1.0,0,R4,-1.0);
2906 VARROUNDF(R8,1.0,0,R8,1.0);
2907 VARROUNDF(R8,-1.0,0,R8,-1.0);
2909 /* floating point numbers aren't exactly equal and we can't just
2910 * compare the first few digits.
2911 todo_wine {
2912 VARROUNDF(DATE,1.451,1,DATE,1.5);
2913 VARROUNDF(DATE,-1.45,1,DATE,-1.4);
2914 VARROUNDF(BSTR,(BSTR)szNumMin,1,R8,-1.40);
2915 VARROUNDF(BSTR,(BSTR)szNum,1,R8,1.50);
2917 VARROUNDF(R4,1.23456,0,R4,1.0);
2918 VARROUNDF(R4,1.23456,1,R4,1.2);
2919 VARROUNDF(R4,1.23456,2,R4,1.23);
2920 VARROUNDF(R4,1.23456,3,R4,1.235);
2921 VARROUNDF(R4,1.23456,4,R4,1.2346);
2922 VARROUNDF(R4,-1.23456,0,R4,-1.0);
2923 VARROUNDF(R4,-1.23456,1,R4,-1.2);
2924 VARROUNDF(R4,-1.23456,2,R4,-1.23);
2925 VARROUNDF(R4,-1.23456,3,R4,-1.235);
2926 VARROUNDF(R4,-1.23456,4,R4,-1.2346);
2928 VARROUNDF(R8,1.23456,0,R8,1.0);
2929 VARROUNDF(R8,1.23456,1,R8,1.2);
2930 VARROUNDF(R8,1.23456,2,R8,1.23);
2931 VARROUNDF(R8,1.23456,3,R8,1.235);
2932 VARROUNDF(R8,1.23456,4,R8,1.2346);
2933 VARROUNDF(R8,-1.23456,0,R8,-1.0);
2934 VARROUNDF(R8,-1.23456,1,R8,-1.2);
2935 VARROUNDF(R8,-1.23456,2,R8,-1.23);
2936 VARROUNDF(R8,-1.23456,3,R8,-1.235);
2937 VARROUNDF(R8,-1.23456,4,R8,-1.2346);
2941 V_VT(&v) = VT_EMPTY;
2942 hres = pVarRound(&v,0,&vDst);
2943 ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
2944 "VarRound: expected 0x0,%d,0 got 0x%lX,%d,%d\n", VT_EMPTY,
2945 hres, V_VT(&vDst), V_I2(&vDst));
2947 V_VT(&v) = VT_NULL;
2948 hres = pVarRound(&v,0,&vDst);
2949 ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
2950 "VarRound: expected 0x0,%d got 0x%lX,%d\n", VT_NULL, hres, V_VT(&vDst));
2952 /* not yet implemented so no use testing yet
2953 todo_wine {
2954 DECIMAL *pdec = &V_DECIMAL(&v);
2955 V_VT(&v) = VT_DECIMAL;
2956 S(U(*pdec)).sign = DECIMAL_NEG;
2957 S(U(*pdec)).scale = 0;
2958 pdec->Hi32 = 0;
2959 S1(U1(*pdec)).Mid32 = 0;
2960 S1(U1(*pdec)).Lo32 = 1;
2961 hres = pVarRound(&v,0,&vDst);
2962 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
2963 S(U(V_DECIMAL(&vDst))).sign == 0,
2964 "VarRound: expected 0x0,%d,0x00, got 0x%lX,%d,%02x\n", VT_DECIMAL,
2965 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
2967 S(U(*pdec)).sign = 0;
2968 hres = pVarRound(&v,0,&vDst);
2969 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
2970 S(U(V_DECIMAL(&vDst))).sign == DECIMAL_NEG,
2971 "VarRound: expected 0x0,%d,0x7f, got 0x%lX,%d,%02x\n", VT_DECIMAL,
2972 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
2976 V_VT(&v) = VT_CY;
2977 pcy->int64 = 10000;
2978 hres = pVarRound(&v,0,&vDst);
2979 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
2980 "VarRound: VT_CY wrong, hres=0x%lX\n", hres);
2984 static HRESULT (WINAPI *pVarXor)(LPVARIANT,LPVARIANT,LPVARIANT);
2986 static const char *szVarXorFail = "VarXor(%d,%d): expected 0x0,%d,%d, got 0x%lX,%d,%d\n";
2987 #define VARXOR(vt1,val1,vt2,val2,rvt,rval) \
2988 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
2989 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
2990 memset(&result,0,sizeof(result)); hres = pVarXor(&left,&right,&result); \
2991 ok(hres == S_OK && V_VT(&result) == VT_##rvt && V_##rvt(&result) == (rval), \
2992 szVarXorFail, VT_##vt1, VT_##vt2, \
2993 VT_##rvt, (int)(rval), hres, V_VT(&result), (int)V_##rvt(&result)); \
2994 ok(V_VT(&left) == VT_##vt1 && V_##vt1(&left) == val1 && \
2995 V_VT(&right) == VT_##vt2 && V_##vt2(&right) == val2, \
2996 "VarXor(%d,%d): Modified input arguments\n",VT_##vt1,VT_##vt2)
2997 #define VARXORCY(vt1,val1,val2,rvt,rval) \
2998 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
2999 V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \
3000 memset(&result,0,sizeof(result)); hres = pVarXor(&left,&right,&result); \
3001 ok(hres == S_OK && V_VT(&result) == VT_##rvt && V_##rvt(&result) == (rval), \
3002 "VarXor(%d,%d): expected 0x0,%d,%d, got 0x%lX,%d,%d\n", VT_##vt1, VT_CY, \
3003 VT_##rvt, (int)(rval), hres, V_VT(&result), (int)V_##rvt(&result)); \
3004 ok(V_VT(&left) == VT_##vt1 && V_##vt1(&left) == val1 && \
3005 V_VT(&right) == VT_CY && V_CY(&right).int64 == val2, \
3006 "VarXor(%d,%d): Modified input arguments\n",VT_##vt1,VT_CY)
3008 static void test_VarXor(void)
3010 static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
3011 static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
3012 VARIANT left, right, result;
3013 BSTR lbstr, rbstr;
3014 VARTYPE i;
3015 HRESULT hres;
3017 CHECKPTR(VarXor);
3019 /* Test all possible flag/vt combinations & the resulting vt type */
3020 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
3022 VARTYPE leftvt, rightvt, resvt;
3024 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
3027 SKIPTESTS(leftvt);
3029 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
3031 BOOL bFail = FALSE;
3033 SKIPTESTS(rightvt);
3035 if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
3036 leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
3037 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
3038 continue;
3040 memset(&left, 0, sizeof(left));
3041 memset(&right, 0, sizeof(right));
3042 V_VT(&left) = leftvt | ExtraFlags[i];
3043 V_VT(&right) = rightvt | ExtraFlags[i];
3044 V_VT(&result) = VT_EMPTY;
3045 resvt = VT_I4;
3047 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
3048 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
3049 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
3050 leftvt == VT_CLSID || rightvt == VT_CLSID ||
3051 leftvt == VT_RECORD || rightvt == VT_RECORD ||
3052 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
3053 leftvt == VT_ERROR || rightvt == VT_ERROR)
3055 bFail = TRUE;
3057 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
3059 if (leftvt == rightvt ||
3060 leftvt == VT_I2 || rightvt == VT_I2 ||
3061 leftvt == VT_UI1 || rightvt == VT_UI1 ||
3062 leftvt == VT_BOOL || rightvt == VT_BOOL)
3063 resvt = VT_I2;
3064 else if (leftvt == VT_NULL || rightvt == VT_NULL)
3065 resvt = VT_NULL;
3066 else if (leftvt == VT_I8 || rightvt == VT_I8)
3067 resvt = VT_I8;
3069 else if (leftvt == VT_NULL || rightvt == VT_NULL)
3071 resvt = VT_NULL;
3073 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
3075 if (leftvt == rightvt)
3076 resvt = VT_UI1;
3077 else if (leftvt == rightvt ||
3078 leftvt == VT_I2 || rightvt == VT_I2 ||
3079 leftvt == VT_BOOL || rightvt == VT_BOOL)
3081 resvt = VT_I2;
3083 else if (leftvt == VT_I8 || rightvt == VT_I8)
3084 resvt = VT_I8;
3086 else if (leftvt == VT_I2 || rightvt == VT_I2)
3088 if (leftvt == rightvt ||
3089 leftvt == VT_BOOL || rightvt == VT_BOOL)
3090 resvt = VT_I2;
3091 else if (leftvt == VT_I8 || rightvt == VT_I8)
3092 resvt = VT_I8;
3094 else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
3096 resvt = VT_BOOL;
3098 else if (leftvt == VT_I8 || rightvt == VT_I8)
3100 if (leftvt == VT_INT || rightvt == VT_INT)
3101 bFail = TRUE;
3102 else
3103 resvt = VT_I8;
3105 hres = pVarXor(&left, &right, &result);
3106 if (bFail)
3107 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3108 "VarXor: %d|0x%X, %d|0x%X: Expected failure, got 0x%lX vt %d\n",
3109 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
3110 V_VT(&result));
3111 else
3112 ok(hres == S_OK && V_VT(&result) == resvt,
3113 "VarXor: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%lX vt %d\n",
3114 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
3115 V_VT(&result));
3120 /* Test returned values
3121 * FIXME: Test VT_DECIMAL/VT_DISPATCH
3123 VARXOR(EMPTY,0,EMPTY,0,I2,0);
3124 VARXOR(EMPTY,1,EMPTY,0,I2,0);
3125 VARXOR(EMPTY,0,NULL,0,NULL,0);
3126 VARXOR(EMPTY,0,I1,0,I4,0);
3127 VARXOR(EMPTY,0,I1,1,I4,1);
3128 VARXOR(EMPTY,0,UI1,0,I2,0);
3129 VARXOR(EMPTY,0,UI1,1,I2,1);
3130 VARXOR(EMPTY,0,I2,0,I2,0);
3131 VARXOR(EMPTY,0,I2,1,I2,1);
3132 VARXOR(EMPTY,0,UI2,0,I4,0);
3133 VARXOR(EMPTY,0,UI2,1,I4,1);
3134 VARXOR(EMPTY,0,I4,0,I4,0);
3135 VARXOR(EMPTY,0,I4,1,I4,1);
3136 VARXOR(EMPTY,0,UI4,0,I4,0);
3137 VARXOR(EMPTY,0,UI4,1,I4,1);
3138 if (HAVE_OLEAUT32_I8)
3140 VARXOR(EMPTY,0,I8,0,I8,0);
3141 VARXOR(EMPTY,0,I8,1,I8,1);
3142 VARXOR(EMPTY,0,UI8,0,I4,0);
3143 VARXOR(EMPTY,0,UI8,1,I4,1);
3145 VARXOR(EMPTY,0,INT,0,I4,0);
3146 VARXOR(EMPTY,0,INT,1,I4,1);
3147 VARXOR(EMPTY,0,UINT,0,I4,0);
3148 VARXOR(EMPTY,0,UINT,1,I4,1);
3149 VARXOR(EMPTY,0,BOOL,0,I2,0);
3150 VARXOR(EMPTY,0,BOOL,1,I2,1);
3151 VARXOR(EMPTY,0,R4,0,I4,0);
3152 VARXOR(EMPTY,0,R4,1,I4,1);
3153 VARXOR(EMPTY,0,R8,0,I4,0);
3154 VARXOR(EMPTY,0,R8,1,I4,1);
3155 rbstr = SysAllocString(szFalse);
3156 VARXOR(EMPTY,0,BSTR,rbstr,I2,0);
3157 rbstr = SysAllocString(szTrue);
3158 VARXOR(EMPTY,0,BSTR,rbstr,I2,-1);
3159 VARXORCY(EMPTY,0,10000,I4,1);
3161 /* NULL OR 0 = NULL. NULL OR n = n */
3162 VARXOR(NULL,0,NULL,0,NULL,0);
3163 VARXOR(NULL,1,NULL,0,NULL,0);
3164 VARXOR(NULL,0,I1,0,NULL,0);
3165 VARXOR(NULL,0,I1,1,NULL,0);
3166 VARXOR(NULL,0,UI1,0,NULL,0);
3167 VARXOR(NULL,0,UI1,1,NULL,0);
3168 VARXOR(NULL,0,I2,0,NULL,0);
3169 VARXOR(NULL,0,I2,1,NULL,0);
3170 VARXOR(NULL,0,UI2,0,NULL,0);
3171 VARXOR(NULL,0,UI2,1,NULL,0);
3172 VARXOR(NULL,0,I4,0,NULL,0);
3173 VARXOR(NULL,0,I4,1,NULL,0);
3174 VARXOR(NULL,0,UI4,0,NULL,0);
3175 VARXOR(NULL,0,UI4,1,NULL,0);
3176 if (HAVE_OLEAUT32_I8)
3178 VARXOR(NULL,0,I8,0,NULL,0);
3179 VARXOR(NULL,0,I8,1,NULL,0);
3180 VARXOR(NULL,0,UI8,0,NULL,0);
3181 VARXOR(NULL,0,UI8,1,NULL,0);
3183 VARXOR(NULL,0,INT,0,NULL,0);
3184 VARXOR(NULL,0,INT,1,NULL,0);
3185 VARXOR(NULL,0,UINT,0,NULL,0);
3186 VARXOR(NULL,0,UINT,1,NULL,0);
3187 VARXOR(NULL,0,BOOL,0,NULL,0);
3188 VARXOR(NULL,0,BOOL,1,NULL,0);
3189 VARXOR(NULL,0,R4,0,NULL,0);
3190 VARXOR(NULL,0,R4,1,NULL,0);
3191 VARXOR(NULL,0,R8,0,NULL,0);
3192 VARXOR(NULL,0,R8,1,NULL,0);
3193 rbstr = SysAllocString(szFalse);
3194 VARXOR(NULL,0,BSTR,rbstr,NULL,0);
3195 rbstr = SysAllocString(szTrue);
3196 VARXOR(NULL,0,BSTR,rbstr,NULL,0);
3197 VARXORCY(NULL,0,10000,NULL,0);
3198 VARXORCY(NULL,0,0,NULL,0);
3200 VARXOR(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
3201 VARXOR(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
3202 VARXOR(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
3203 VARXOR(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
3204 /* Assume x,y & y,x are the same from now on to reduce the number of tests */
3205 VARXOR(BOOL,VARIANT_TRUE,I1,-1,I4,0);
3206 VARXOR(BOOL,VARIANT_TRUE,I1,0,I4,-1);
3207 VARXOR(BOOL,VARIANT_FALSE,I1,0,I4,0);
3208 VARXOR(BOOL,VARIANT_TRUE,UI1,255,I2,-256);
3209 VARXOR(BOOL,VARIANT_TRUE,UI1,0,I2,-1);
3210 VARXOR(BOOL,VARIANT_FALSE,UI1,0,I2,0);
3211 VARXOR(BOOL,VARIANT_TRUE,I2,-1,I2,0);
3212 VARXOR(BOOL,VARIANT_TRUE,I2,0,I2,-1);
3213 VARXOR(BOOL,VARIANT_FALSE,I2,0,I2,0);
3214 VARXOR(BOOL,VARIANT_TRUE,UI2,65535,I4,-65536);
3215 VARXOR(BOOL,VARIANT_TRUE,UI2,0,I4,-1);
3216 VARXOR(BOOL,VARIANT_FALSE,UI2,0,I4,0);
3217 VARXOR(BOOL,VARIANT_TRUE,I4,-1,I4,0);
3218 VARXOR(BOOL,VARIANT_TRUE,I4,0,I4,-1);
3219 VARXOR(BOOL,VARIANT_FALSE,I4,0,I4,0);
3220 VARXOR(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,0);
3221 VARXOR(BOOL,VARIANT_TRUE,UI4,0,I4,-1);
3222 VARXOR(BOOL,VARIANT_FALSE,UI4,0,I4,0);
3223 VARXOR(BOOL,VARIANT_TRUE,R4,-1,I4,0);
3224 VARXOR(BOOL,VARIANT_TRUE,R4,0,I4,-1);
3225 VARXOR(BOOL,VARIANT_FALSE,R4,0,I4,0);
3226 VARXOR(BOOL,VARIANT_TRUE,R8,-1,I4,0);
3227 VARXOR(BOOL,VARIANT_TRUE,R8,0,I4,-1);
3228 VARXOR(BOOL,VARIANT_FALSE,R8,0,I4,0);
3229 VARXOR(BOOL,VARIANT_TRUE,DATE,-1,I4,0);
3230 VARXOR(BOOL,VARIANT_TRUE,DATE,0,I4,-1);
3231 VARXOR(BOOL,VARIANT_FALSE,DATE,0,I4,0);
3232 if (HAVE_OLEAUT32_I8)
3234 VARXOR(BOOL,VARIANT_TRUE,I8,-1,I8,0);
3235 VARXOR(BOOL,VARIANT_TRUE,I8,0,I8,-1);
3236 VARXOR(BOOL,VARIANT_FALSE,I8,0,I8,0);
3237 /* This returns DISP_E_OVERFLOW which indicates that a conversion
3238 * to I4 is performed.
3240 /* VARXOR(BOOL,VARIANT_TRUE,UI8,-1,I4,-1); */
3241 VARXOR(BOOL,VARIANT_TRUE,UI8,0,I4,-1);
3242 VARXOR(BOOL,VARIANT_FALSE,UI8,0,I4,0);
3244 VARXOR(BOOL,VARIANT_TRUE,INT,-1,I4,0);
3245 VARXOR(BOOL,VARIANT_TRUE,INT,0,I4,-1);
3246 VARXOR(BOOL,VARIANT_FALSE,INT,0,I4,0);
3247 VARXOR(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,0);
3248 VARXOR(BOOL,VARIANT_TRUE,UINT,0,I4,-1);
3249 VARXOR(BOOL,VARIANT_FALSE,UINT,0,I4,0);
3250 rbstr = SysAllocString(szFalse);
3251 VARXOR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_FALSE);
3252 VARXOR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
3253 rbstr = SysAllocString(szTrue);
3254 VARXOR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_TRUE);
3255 VARXOR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_FALSE);
3256 VARXORCY(BOOL,VARIANT_TRUE,10000,I4,-2);
3257 VARXORCY(BOOL,VARIANT_TRUE,0,I4,-1);
3258 VARXORCY(BOOL,VARIANT_FALSE,0,I4,0);
3260 VARXOR(I1,-1,I1,-1,I4,0);
3261 VARXOR(I1,-1,I1,0,I4,-1);
3262 VARXOR(I1,0,I1,0,I4,0);
3263 VARXOR(I1,-1,UI1,255,I4,-256);
3264 VARXOR(I1,-1,UI1,0,I4,-1);
3265 VARXOR(I1,0,UI1,0,I4,0);
3266 VARXOR(I1,-1,I2,-1,I4,0);
3267 VARXOR(I1,-1,I2,0,I4,-1);
3268 VARXOR(I1,0,I2,0,I4,0);
3269 VARXOR(I1,-1,UI2,65535,I4,-65536);
3270 VARXOR(I1,-1,UI2,0,I4,-1);
3271 VARXOR(I1,0,UI2,0,I4,0);
3272 VARXOR(I1,-1,I4,-1,I4,0);
3273 VARXOR(I1,-1,I4,0,I4,-1);
3274 VARXOR(I1,0,I4,0,I4,0);
3275 VARXOR(I1,-1,UI4,0xffffffff,I4,0);
3276 VARXOR(I1,-1,UI4,0,I4,-1);
3277 VARXOR(I1,0,UI4,0,I4,0);
3278 VARXOR(I1,-1,R4,-1,I4,0);
3279 VARXOR(I1,-1,R4,0,I4,-1);
3280 VARXOR(I1,0,R4,0,I4,0);
3281 VARXOR(I1,-1,R8,-1,I4,0);
3282 VARXOR(I1,-1,R8,0,I4,-1);
3283 VARXOR(I1,0,R8,0,I4,0);
3284 VARXOR(I1,-1,DATE,-1,I4,0);
3285 VARXOR(I1,-1,DATE,0,I4,-1);
3286 VARXOR(I1,0,DATE,0,I4,0);
3287 if (HAVE_OLEAUT32_I8)
3289 VARXOR(I1,-1,I8,-1,I8,0);
3290 VARXOR(I1,-1,I8,0,I8,-1);
3291 VARXOR(I1,0,I8,0,I8,0);
3292 VARXOR(I1,-1,UI8,0,I4,-1);
3293 VARXOR(I1,0,UI8,0,I4,0);
3295 VARXOR(I1,-1,INT,-1,I4,0);
3296 VARXOR(I1,-1,INT,0,I4,-1);
3297 VARXOR(I1,0,INT,0,I4,0);
3298 VARXOR(I1,-1,UINT,0xffffffff,I4,0);
3299 VARXOR(I1,-1,UINT,0,I4,-1);
3300 VARXOR(I1,0,UINT,0,I4,0);
3301 rbstr = SysAllocString(szFalse);
3302 VARXOR(I1,0,BSTR,rbstr,I4,0);
3303 VARXOR(I1,-1,BSTR,rbstr,I4,-1);
3304 rbstr = SysAllocString(szTrue);
3305 VARXOR(I1,0,BSTR,rbstr,I4,-1);
3306 VARXOR(I1,-1,BSTR,rbstr,I4,0);
3307 VARXORCY(I1,-1,10000,I4,-2);
3308 VARXORCY(I1,-1,0,I4,-1);
3309 VARXORCY(I1,0,0,I4,0);
3311 VARXOR(UI1,255,UI1,255,UI1,0);
3312 VARXOR(UI1,255,UI1,0,UI1,255);
3313 VARXOR(UI1,0,UI1,0,UI1,0);
3314 VARXOR(UI1,255,I2,-1,I2,-256);
3315 VARXOR(UI1,255,I2,0,I2,255);
3316 VARXOR(UI1,0,I2,0,I2,0);
3317 VARXOR(UI1,255,UI2,65535,I4,65280);
3318 VARXOR(UI1,255,UI2,0,I4,255);
3319 VARXOR(UI1,0,UI2,0,I4,0);
3320 VARXOR(UI1,255,I4,-1,I4,-256);
3321 VARXOR(UI1,255,I4,0,I4,255);
3322 VARXOR(UI1,0,I4,0,I4,0);
3323 VARXOR(UI1,255,UI4,0xffffffff,I4,-256);
3324 VARXOR(UI1,255,UI4,0,I4,255);
3325 VARXOR(UI1,0,UI4,0,I4,0);
3326 VARXOR(UI1,255,R4,-1,I4,-256);
3327 VARXOR(UI1,255,R4,0,I4,255);
3328 VARXOR(UI1,0,R4,0,I4,0);
3329 VARXOR(UI1,255,R8,-1,I4,-256);
3330 VARXOR(UI1,255,R8,0,I4,255);
3331 VARXOR(UI1,0,R8,0,I4,0);
3332 VARXOR(UI1,255,DATE,-1,I4,-256);
3333 VARXOR(UI1,255,DATE,0,I4,255);
3334 VARXOR(UI1,0,DATE,0,I4,0);
3335 if (HAVE_OLEAUT32_I8)
3337 VARXOR(UI1,255,I8,-1,I8,-256);
3338 VARXOR(UI1,255,I8,0,I8,255);
3339 VARXOR(UI1,0,I8,0,I8,0);
3340 VARXOR(UI1,255,UI8,0,I4,255);
3341 VARXOR(UI1,0,UI8,0,I4,0);
3343 VARXOR(UI1,255,INT,-1,I4,-256);
3344 VARXOR(UI1,255,INT,0,I4,255);
3345 VARXOR(UI1,0,INT,0,I4,0);
3346 VARXOR(UI1,255,UINT,0xffffffff,I4,-256);
3347 VARXOR(UI1,255,UINT,0,I4,255);
3348 VARXOR(UI1,0,UINT,0,I4,0);
3349 rbstr = SysAllocString(szFalse);
3350 VARXOR(UI1,0,BSTR,rbstr,I2,0);
3351 VARXOR(UI1,255,BSTR,rbstr,I2,255);
3352 rbstr = SysAllocString(szTrue);
3353 VARXOR(UI1,0,BSTR,rbstr,I2,-1);
3354 VARXOR(UI1,255,BSTR,rbstr,I2,-256);
3355 VARXORCY(UI1,255,10000,I4,254);
3356 VARXORCY(UI1,255,0,I4,255);
3357 VARXORCY(UI1,0,0,I4,0);
3359 VARXOR(I2,-1,I2,-1,I2,0);
3360 VARXOR(I2,-1,I2,0,I2,-1);
3361 VARXOR(I2,0,I2,0,I2,0);
3362 VARXOR(I2,-1,UI2,65535,I4,-65536);
3363 VARXOR(I2,-1,UI2,0,I4,-1);
3364 VARXOR(I2,0,UI2,0,I4,0);
3365 VARXOR(I2,-1,I4,-1,I4,0);
3366 VARXOR(I2,-1,I4,0,I4,-1);
3367 VARXOR(I2,0,I4,0,I4,0);
3368 VARXOR(I2,-1,UI4,0xffffffff,I4,0);
3369 VARXOR(I2,-1,UI4,0,I4,-1);
3370 VARXOR(I2,0,UI4,0,I4,0);
3371 VARXOR(I2,-1,R4,-1,I4,0);
3372 VARXOR(I2,-1,R4,0,I4,-1);
3373 VARXOR(I2,0,R4,0,I4,0);
3374 VARXOR(I2,-1,R8,-1,I4,0);
3375 VARXOR(I2,-1,R8,0,I4,-1);
3376 VARXOR(I2,0,R8,0,I4,0);
3377 VARXOR(I2,-1,DATE,-1,I4,0);
3378 VARXOR(I2,-1,DATE,0,I4,-1);
3379 VARXOR(I2,0,DATE,0,I4,0);
3380 if (HAVE_OLEAUT32_I8)
3382 VARXOR(I2,-1,I8,-1,I8,0);
3383 VARXOR(I2,-1,I8,0,I8,-1);
3384 VARXOR(I2,0,I8,0,I8,0);
3385 VARXOR(I2,-1,UI8,0,I4,-1);
3386 VARXOR(I2,0,UI8,0,I4,0);
3388 VARXOR(I2,-1,INT,-1,I4,0);
3389 VARXOR(I2,-1,INT,0,I4,-1);
3390 VARXOR(I2,0,INT,0,I4,0);
3391 VARXOR(I2,-1,UINT,0xffffffff,I4,0);
3392 VARXOR(I2,-1,UINT,0,I4,-1);
3393 VARXOR(I2,0,UINT,0,I4,0);
3394 rbstr = SysAllocString(szFalse);
3395 VARXOR(I2,0,BSTR,rbstr,I2,0);
3396 VARXOR(I2,-1,BSTR,rbstr,I2,-1);
3397 rbstr = SysAllocString(szTrue);
3398 VARXOR(I2,0,BSTR,rbstr,I2,-1);
3399 VARXOR(I2,-1,BSTR,rbstr,I2,0);
3400 VARXORCY(I2,-1,10000,I4,-2);
3401 VARXORCY(I2,-1,0,I4,-1);
3402 VARXORCY(I2,0,0,I4,0);
3404 VARXOR(UI2,65535,UI2,65535,I4,0);
3405 VARXOR(UI2,65535,UI2,0,I4,65535);
3406 VARXOR(UI2,0,UI2,0,I4,0);
3407 VARXOR(UI2,65535,I4,-1,I4,-65536);
3408 VARXOR(UI2,65535,I4,0,I4,65535);
3409 VARXOR(UI2,0,I4,0,I4,0);
3410 VARXOR(UI2,65535,UI4,0xffffffff,I4,-65536);
3411 VARXOR(UI2,65535,UI4,0,I4,65535);
3412 VARXOR(UI2,0,UI4,0,I4,0);
3413 VARXOR(UI2,65535,R4,-1,I4,-65536);
3414 VARXOR(UI2,65535,R4,0,I4,65535);
3415 VARXOR(UI2,0,R4,0,I4,0);
3416 VARXOR(UI2,65535,R8,-1,I4,-65536);
3417 VARXOR(UI2,65535,R8,0,I4,65535);
3418 VARXOR(UI2,0,R8,0,I4,0);
3419 VARXOR(UI2,65535,DATE,-1,I4,-65536);
3420 VARXOR(UI2,65535,DATE,0,I4,65535);
3421 VARXOR(UI2,0,DATE,0,I4,0);
3422 if (HAVE_OLEAUT32_I8)
3424 VARXOR(UI2,65535,I8,-1,I8,-65536);
3425 VARXOR(UI2,65535,I8,0,I8,65535);
3426 VARXOR(UI2,0,I8,0,I8,0);
3427 VARXOR(UI2,65535,UI8,0,I4,65535);
3428 VARXOR(UI2,0,UI8,0,I4,0);
3430 VARXOR(UI2,65535,INT,-1,I4,-65536);
3431 VARXOR(UI2,65535,INT,0,I4,65535);
3432 VARXOR(UI2,0,INT,0,I4,0);
3433 VARXOR(UI2,65535,UINT,0xffffffff,I4,-65536);
3434 VARXOR(UI2,65535,UINT,0,I4,65535);
3435 VARXOR(UI2,0,UINT,0,I4,0);
3436 rbstr = SysAllocString(szFalse);
3437 VARXOR(UI2,0,BSTR,rbstr,I4,0);
3438 VARXOR(UI2,65535,BSTR,rbstr,I4,65535);
3439 rbstr = SysAllocString(szTrue);
3440 VARXOR(UI2,0,BSTR,rbstr,I4,-1);
3441 VARXOR(UI2,65535,BSTR,rbstr,I4,-65536);
3442 VARXORCY(UI2,65535,10000,I4,65534);
3443 VARXORCY(UI2,65535,0,I4,65535);
3444 VARXORCY(UI2,0,0,I4,0);
3446 VARXOR(I4,-1,I4,-1,I4,0);
3447 VARXOR(I4,-1,I4,0,I4,-1);
3448 VARXOR(I4,0,I4,0,I4,0);
3449 VARXOR(I4,-1,UI4,0xffffffff,I4,0);
3450 VARXOR(I4,-1,UI4,0,I4,-1);
3451 VARXOR(I4,0,UI4,0,I4,0);
3452 VARXOR(I4,-1,R4,-1,I4,0);
3453 VARXOR(I4,-1,R4,0,I4,-1);
3454 VARXOR(I4,0,R4,0,I4,0);
3455 VARXOR(I4,-1,R8,-1,I4,0);
3456 VARXOR(I4,-1,R8,0,I4,-1);
3457 VARXOR(I4,0,R8,0,I4,0);
3458 VARXOR(I4,-1,DATE,-1,I4,0);
3459 VARXOR(I4,-1,DATE,0,I4,-1);
3460 VARXOR(I4,0,DATE,0,I4,0);
3461 if (HAVE_OLEAUT32_I8)
3463 VARXOR(I4,-1,I8,-1,I8,0);
3464 VARXOR(I4,-1,I8,0,I8,-1);
3465 VARXOR(I4,0,I8,0,I8,0);
3466 VARXOR(I4,-1,UI8,0,I4,-1);
3467 VARXOR(I4,0,UI8,0,I4,0);
3469 VARXOR(I4,-1,INT,-1,I4,0);
3470 VARXOR(I4,-1,INT,0,I4,-1);
3471 VARXOR(I4,0,INT,0,I4,0);
3472 VARXOR(I4,-1,UINT,0xffffffff,I4,0);
3473 VARXOR(I4,-1,UINT,0,I4,-1);
3474 VARXOR(I4,0,UINT,0,I4,0);
3475 rbstr = SysAllocString(szFalse);
3476 VARXOR(I4,0,BSTR,rbstr,I4,0);
3477 VARXOR(I4,-1,BSTR,rbstr,I4,-1);
3478 rbstr = SysAllocString(szTrue);
3479 VARXOR(I4,0,BSTR,rbstr,I4,-1);
3480 VARXOR(I4,-1,BSTR,rbstr,I4,0);
3481 VARXORCY(I4,-1,10000,I4,-2);
3482 VARXORCY(I4,-1,0,I4,-1);
3483 VARXORCY(I4,0,0,I4,0);
3485 VARXOR(UI4,0xffffffff,UI4,0xffffffff,I4,0);
3486 VARXOR(UI4,0xffffffff,UI4,0,I4,-1);
3487 VARXOR(UI4,0,UI4,0,I4,0);
3488 VARXOR(UI4,0xffffffff,R4,-1,I4,0);
3489 VARXOR(UI4,0xffffffff,R4,0,I4,-1);
3490 VARXOR(UI4,0,R4,0,I4,0);
3491 VARXOR(UI4,0xffffffff,R8,-1,I4,0);
3492 VARXOR(UI4,0xffffffff,R8,0,I4,-1);
3493 VARXOR(UI4,0,R8,0,I4,0);
3494 VARXOR(UI4,0xffffffff,DATE,-1,I4,0);
3495 VARXOR(UI4,0xffffffff,DATE,0,I4,-1);
3496 VARXOR(UI4,0,DATE,0,I4,0);
3497 if (HAVE_OLEAUT32_I8)
3499 VARXOR(UI4,0xffffffff,I8,0,I8,0xffffffff);
3500 VARXOR(UI4,VARIANT_FALSE,I8,VARIANT_FALSE,I8,0);
3501 VARXOR(UI4,0,I8,0,I8,0);
3502 VARXOR(UI4,0xffffffff,UI8,0,I4,-1);
3503 VARXOR(UI4,0,UI8,0,I4,0);
3505 VARXOR(UI4,0xffffffff,INT,-1,I4,0);
3506 VARXOR(UI4,0xffffffff,INT,0,I4,-1);
3507 VARXOR(UI4,0,INT,0,I4,0);
3508 VARXOR(UI4,0xffffffff,UINT,0xffffffff,I4,0);
3509 VARXOR(UI4,0xffffffff,UINT,0,I4,-1);
3510 VARXOR(UI4,0,UINT,0,I4,0);
3511 rbstr = SysAllocString(szFalse);
3512 VARXOR(UI4,0,BSTR,rbstr,I4,0);
3513 VARXOR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
3514 rbstr = SysAllocString(szTrue);
3515 VARXOR(UI4,0,BSTR,rbstr,I4,-1);
3516 VARXOR(UI4,0xffffffff,BSTR,rbstr,I4,0);
3517 VARXORCY(UI4,0xffffffff,10000,I4,-2);
3518 VARXORCY(UI4,0xffffffff,0,I4,-1);
3519 VARXORCY(UI4,0,0,I4,0);
3521 VARXOR(R4,-1,R4,-1,I4,0);
3522 VARXOR(R4,-1,R4,0,I4,-1);
3523 VARXOR(R4,0,R4,0,I4,0);
3524 VARXOR(R4,-1,R8,-1,I4,0);
3525 VARXOR(R4,-1,R8,0,I4,-1);
3526 VARXOR(R4,0,R8,0,I4,0);
3527 VARXOR(R4,-1,DATE,-1,I4,0);
3528 VARXOR(R4,-1,DATE,0,I4,-1);
3529 VARXOR(R4,0,DATE,0,I4,0);
3530 if (HAVE_OLEAUT32_I8)
3532 VARXOR(R4,-1,I8,-1,I8,0);
3533 VARXOR(R4,-1,I8,0,I8,-1);
3534 VARXOR(R4,0,I8,0,I8,0);
3535 VARXOR(R4,-1,UI8,0,I4,-1);
3536 VARXOR(R4,0,UI8,0,I4,0);
3538 VARXOR(R4,-1,INT,-1,I4,0);
3539 VARXOR(R4,-1,INT,0,I4,-1);
3540 VARXOR(R4,0,INT,0,I4,0);
3541 VARXOR(R4,-1,UINT,0xffffffff,I4,0);
3542 VARXOR(R4,-1,UINT,0,I4,-1);
3543 VARXOR(R4,0,UINT,0,I4,0);
3544 rbstr = SysAllocString(szFalse);
3545 VARXOR(R4,0,BSTR,rbstr,I4,0);
3546 VARXOR(R4,-1,BSTR,rbstr,I4,-1);
3547 rbstr = SysAllocString(szTrue);
3548 VARXOR(R4,0,BSTR,rbstr,I4,-1);
3549 VARXOR(R4,-1,BSTR,rbstr,I4,0);
3550 VARXORCY(R4,-1,10000,I4,-2);
3551 VARXORCY(R4,-1,0,I4,-1);
3552 VARXORCY(R4,0,0,I4,0);
3554 VARXOR(R8,-1,R8,-1,I4,0);
3555 VARXOR(R8,-1,R8,0,I4,-1);
3556 VARXOR(R8,0,R8,0,I4,0);
3557 VARXOR(R8,-1,DATE,-1,I4,0);
3558 VARXOR(R8,-1,DATE,0,I4,-1);
3559 VARXOR(R8,0,DATE,0,I4,0);
3560 if (HAVE_OLEAUT32_I8)
3562 VARXOR(R8,-1,I8,-1,I8,0);
3563 VARXOR(R8,-1,I8,0,I8,-1);
3564 VARXOR(R8,0,I8,0,I8,0);
3565 VARXOR(R8,-1,UI8,0,I4,-1);
3566 VARXOR(R8,0,UI8,0,I4,0);
3568 VARXOR(R8,-1,INT,-1,I4,0);
3569 VARXOR(R8,-1,INT,0,I4,-1);
3570 VARXOR(R8,0,INT,0,I4,0);
3571 VARXOR(R8,-1,UINT,0xffffffff,I4,0);
3572 VARXOR(R8,-1,UINT,0,I4,-1);
3573 VARXOR(R8,0,UINT,0,I4,0);
3574 rbstr = SysAllocString(szFalse);
3575 VARXOR(R8,0,BSTR,rbstr,I4,0);
3576 VARXOR(R8,-1,BSTR,rbstr,I4,-1);
3577 rbstr = SysAllocString(szTrue);
3578 VARXOR(R8,0,BSTR,rbstr,I4,-1);
3579 VARXOR(R8,-1,BSTR,rbstr,I4,0);
3580 VARXORCY(R8,-1,10000,I4,-2);
3581 VARXORCY(R8,-1,0,I4,-1);
3582 VARXORCY(R8,0,0,I4,0);
3584 VARXOR(DATE,-1,DATE,-1,I4,0);
3585 VARXOR(DATE,-1,DATE,0,I4,-1);
3586 VARXOR(DATE,0,DATE,0,I4,0);
3587 if (HAVE_OLEAUT32_I8)
3589 VARXOR(DATE,-1,I8,-1,I8,0);
3590 VARXOR(DATE,-1,I8,0,I8,-1);
3591 VARXOR(DATE,0,I8,0,I8,0);
3592 VARXOR(DATE,-1,UI8,0,I4,-1);
3593 VARXOR(DATE,0,UI8,0,I4,0);
3595 VARXOR(DATE,-1,INT,-1,I4,0);
3596 VARXOR(DATE,-1,INT,0,I4,-1);
3597 VARXOR(DATE,0,INT,0,I4,0);
3598 VARXOR(DATE,-1,UINT,0xffffffff,I4,0);
3599 VARXOR(DATE,-1,UINT,0,I4,-1);
3600 VARXOR(DATE,0,UINT,0,I4,0);
3601 rbstr = SysAllocString(szFalse);
3602 VARXOR(DATE,0,BSTR,rbstr,I4,0);
3603 VARXOR(DATE,-1,BSTR,rbstr,I4,-1);
3604 rbstr = SysAllocString(szTrue);
3605 VARXOR(DATE,0,BSTR,rbstr,I4,-1);
3606 VARXOR(DATE,-1,BSTR,rbstr,I4,0);
3607 VARXORCY(DATE,-1,10000,I4,-2);
3608 VARXORCY(DATE,-1,0,I4,-1);
3609 VARXORCY(DATE,0,0,I4,0);
3611 if (HAVE_OLEAUT32_I8)
3613 VARXOR(I8,-1,I8,-1,I8,0);
3614 VARXOR(I8,-1,I8,0,I8,-1);
3615 VARXOR(I8,0,I8,0,I8,0);
3616 VARXOR(I8,-1,UI8,0,I8,-1);
3617 VARXOR(I8,0,UI8,0,I8,0);
3618 VARXOR(I8,-1,UINT,0,I8,-1);
3619 VARXOR(I8,0,UINT,0,I8,0);
3620 rbstr = SysAllocString(szFalse);
3621 VARXOR(I8,0,BSTR,rbstr,I8,0);
3622 VARXOR(I8,-1,BSTR,rbstr,I8,-1);
3623 rbstr = SysAllocString(szTrue);
3624 VARXOR(I8,0,BSTR,rbstr,I8,-1);
3625 VARXOR(I8,-1,BSTR,rbstr,I8,0);
3626 VARXORCY(I8,-1,10000,I8,-2);
3627 VARXORCY(I8,-1,0,I8,-1);
3628 VARXORCY(I8,0,0,I8,0);
3630 VARXOR(UI8,0xffff,UI8,0xffff,I4,0);
3631 VARXOR(UI8,0xffff,UI8,0,I4,0xffff);
3632 VARXOR(UI8,0,UI8,0,I4,0);
3633 VARXOR(UI8,0xffff,INT,-1,I4,-65536);
3634 VARXOR(UI8,0xffff,INT,0,I4,0xffff);
3635 VARXOR(UI8,0,INT,0,I4,0);
3636 VARXOR(UI8,0xffff,UINT,0xffff,I4,0);
3637 VARXOR(UI8,0xffff,UINT,0,I4,0xffff);
3638 VARXOR(UI8,0,UINT,0,I4,0);
3639 rbstr = SysAllocString(szFalse);
3640 VARXOR(UI8,0,BSTR,rbstr,I4,0);
3641 VARXOR(UI8,0xffff,BSTR,rbstr,I4,0xffff);
3642 rbstr = SysAllocString(szTrue);
3643 VARXOR(UI8,0,BSTR,rbstr,I4,-1);
3644 VARXOR(UI8,0xffff,BSTR,rbstr,I4,-65536);
3645 VARXORCY(UI8,0xffff,10000,I4,65534);
3646 VARXORCY(UI8,0xffff,0,I4,0xffff);
3647 VARXORCY(UI8,0,0,I4,0);
3650 VARXOR(INT,-1,INT,-1,I4,0);
3651 VARXOR(INT,-1,INT,0,I4,-1);
3652 VARXOR(INT,0,INT,0,I4,0);
3653 VARXOR(INT,-1,UINT,0xffff,I4,-65536);
3654 VARXOR(INT,-1,UINT,0,I4,-1);
3655 VARXOR(INT,0,UINT,0,I4,0);
3656 rbstr = SysAllocString(szFalse);
3657 VARXOR(INT,0,BSTR,rbstr,I4,0);
3658 VARXOR(INT,-1,BSTR,rbstr,I4,-1);
3659 rbstr = SysAllocString(szTrue);
3660 VARXOR(INT,0,BSTR,rbstr,I4,-1);
3661 VARXOR(INT,-1,BSTR,rbstr,I4,0);
3662 VARXORCY(INT,-1,10000,I4,-2);
3663 VARXORCY(INT,-1,0,I4,-1);
3664 VARXORCY(INT,0,0,I4,0);
3666 VARXOR(UINT,0xffff,UINT,0xffff,I4,0);
3667 VARXOR(UINT,0xffff,UINT,0,I4,0xffff);
3668 VARXOR(UINT,0,UINT,0,I4,0);
3669 rbstr = SysAllocString(szFalse);
3670 VARXOR(UINT,0,BSTR,rbstr,I4,0);
3671 VARXOR(UINT,0xffff,BSTR,rbstr,I4,0xffff);
3672 rbstr = SysAllocString(szTrue);
3673 VARXOR(UINT,0,BSTR,rbstr,I4,-1);
3674 VARXOR(UINT,0xffff,BSTR,rbstr,I4,-65536);
3675 VARXORCY(UINT,0xffff,10000,I4,65534);
3676 VARXORCY(UINT,0xffff,0,I4,0xffff);
3677 VARXORCY(UINT,0,0,I4,0);
3679 lbstr = SysAllocString(szFalse);
3680 rbstr = SysAllocString(szFalse);
3681 VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,0);
3682 rbstr = SysAllocString(szTrue);
3683 VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
3684 lbstr = SysAllocString(szTrue);
3685 VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_FALSE);
3686 VARXORCY(BSTR,lbstr,10000,I4,-2);
3687 lbstr = SysAllocString(szFalse);
3688 VARXORCY(BSTR,lbstr,10000,I4,1);
3691 static HRESULT (WINAPI *pVarOr)(LPVARIANT,LPVARIANT,LPVARIANT);
3693 static const char *szVarOrFail = "VarOr(%d,%d): expected 0x0,%d,%d, got 0x%lX,%d,%d\n";
3694 static const char *szVarOrChanged = "VarOr(%d,%d): Modified input arguments\n";
3695 #define VAROR(vt1,val1,vt2,val2,rvt,rval) \
3696 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
3697 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
3698 memset(&result,0,sizeof(result)); hres = pVarOr(&left,&right,&result); \
3699 ok(hres == S_OK && V_VT(&result) == VT_##rvt && V_##rvt(&result) == (rval), \
3700 szVarOrFail, VT_##vt1, VT_##vt2, \
3701 VT_##rvt, (int)(rval), hres, V_VT(&result), (int)V_##rvt(&result)); \
3702 ok(V_VT(&left) == VT_##vt1 && V_##vt1(&left) == val1 && \
3703 V_VT(&right) == VT_##vt2 && V_##vt2(&right) == val2, \
3704 szVarOrChanged,VT_##vt1,VT_##vt2)
3705 #define VARORCY(vt1,val1,val2,rvt,rval) \
3706 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
3707 V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \
3708 memset(&result,0,sizeof(result)); hres = pVarOr(&left,&right,&result); \
3709 ok(hres == S_OK && V_VT(&result) == VT_##rvt && V_##rvt(&result) == (rval), \
3710 "VarOr(%d,%d): expected 0x0,%d,%d, got 0x%lX,%d,%d\n", VT_##vt1, VT_CY, \
3711 VT_##rvt, (int)(rval), hres, V_VT(&result), (int)V_##rvt(&result)); \
3712 ok(V_VT(&left) == VT_##vt1 && V_##vt1(&left) == val1 && \
3713 V_VT(&right) == VT_CY && V_CY(&right).int64 == val2, \
3714 "VarOr(%d,%d): Modified input arguments\n",VT_##vt1,VT_CY)
3716 static void test_VarOr(void)
3718 static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
3719 static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
3720 VARIANT left, right, result;
3721 BSTR lbstr, rbstr;
3722 VARTYPE i;
3723 HRESULT hres;
3725 CHECKPTR(VarOr);
3727 /* Test all possible flag/vt combinations & the resulting vt type */
3728 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
3730 VARTYPE leftvt, rightvt, resvt;
3732 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
3735 SKIPTESTS(leftvt);
3737 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
3739 BOOL bFail = FALSE;
3741 SKIPTESTS(rightvt);
3743 if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
3744 leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
3745 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
3746 continue;
3748 memset(&left, 0, sizeof(left));
3749 memset(&right, 0, sizeof(right));
3750 V_VT(&left) = leftvt | ExtraFlags[i];
3751 V_VT(&right) = rightvt | ExtraFlags[i];
3752 V_VT(&result) = VT_EMPTY;
3753 resvt = VT_I4;
3755 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
3756 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
3757 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
3758 leftvt == VT_CLSID || rightvt == VT_CLSID ||
3759 leftvt == VT_RECORD || rightvt == VT_RECORD ||
3760 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
3761 leftvt == VT_ERROR || rightvt == VT_ERROR)
3763 bFail = TRUE;
3765 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
3767 if (leftvt == rightvt ||
3768 leftvt == VT_I2 || rightvt == VT_I2 ||
3769 leftvt == VT_UI1 || rightvt == VT_UI1 ||
3770 leftvt == VT_BOOL || rightvt == VT_BOOL)
3771 resvt = VT_I2;
3772 else if (leftvt == VT_NULL || rightvt == VT_NULL)
3773 resvt = VT_NULL;
3774 else if (leftvt == VT_I8 || rightvt == VT_I8)
3775 resvt = VT_I8;
3777 else if (leftvt == VT_NULL || rightvt == VT_NULL)
3779 resvt = VT_NULL;
3781 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
3783 if (leftvt == rightvt)
3784 resvt = VT_UI1;
3785 else if (leftvt == rightvt ||
3786 leftvt == VT_I2 || rightvt == VT_I2 ||
3787 leftvt == VT_BOOL || rightvt == VT_BOOL)
3789 resvt = VT_I2;
3791 else if (leftvt == VT_I8 || rightvt == VT_I8)
3792 resvt = VT_I8;
3794 else if (leftvt == VT_I2 || rightvt == VT_I2)
3796 if (leftvt == rightvt ||
3797 leftvt == VT_BOOL || rightvt == VT_BOOL)
3798 resvt = VT_I2;
3799 else if (leftvt == VT_I8 || rightvt == VT_I8)
3800 resvt = VT_I8;
3802 else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
3804 resvt = VT_BOOL;
3806 else if (leftvt == VT_I8 || rightvt == VT_I8)
3808 if (leftvt == VT_INT || rightvt == VT_INT)
3809 bFail = TRUE;
3810 else
3811 resvt = VT_I8;
3813 hres = pVarOr(&left, &right, &result);
3814 if (bFail)
3815 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3816 "VarOr: %d|0x%X, %d|0x%X: Expected failure, got 0x%lX vt %d\n",
3817 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
3818 V_VT(&result));
3819 else
3820 ok(hres == S_OK && V_VT(&result) == resvt,
3821 "VarOr: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%lX vt %d\n",
3822 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
3823 V_VT(&result));
3828 /* Test returned values. Since we know the returned type is correct
3829 * and that we handle all combinations of invalid types, just check
3830 * that good type combinations produce the desired value.
3831 * FIXME: Test VT_DECIMAL/VT_DISPATCH
3833 VAROR(EMPTY,0,EMPTY,0,I2,0);
3834 VAROR(EMPTY,1,EMPTY,0,I2,0);
3835 VAROR(EMPTY,0,NULL,0,NULL,0);
3836 VAROR(EMPTY,0,I1,0,I4,0);
3837 VAROR(EMPTY,0,I1,1,I4,1);
3838 VAROR(EMPTY,0,UI1,0,I2,0);
3839 VAROR(EMPTY,0,UI1,1,I2,1);
3840 VAROR(EMPTY,0,I2,0,I2,0);
3841 VAROR(EMPTY,0,I2,1,I2,1);
3842 VAROR(EMPTY,0,UI2,0,I4,0);
3843 VAROR(EMPTY,0,UI2,1,I4,1);
3844 VAROR(EMPTY,0,I4,0,I4,0);
3845 VAROR(EMPTY,0,I4,1,I4,1);
3846 VAROR(EMPTY,0,UI4,0,I4,0);
3847 VAROR(EMPTY,0,UI4,1,I4,1);
3848 if (HAVE_OLEAUT32_I8)
3850 VAROR(EMPTY,0,I8,0,I8,0);
3851 VAROR(EMPTY,0,I8,1,I8,1);
3852 VAROR(EMPTY,0,UI8,0,I4,0);
3853 VAROR(EMPTY,0,UI8,1,I4,1);
3855 VAROR(EMPTY,0,INT,0,I4,0);
3856 VAROR(EMPTY,0,INT,1,I4,1);
3857 VAROR(EMPTY,0,UINT,0,I4,0);
3858 VAROR(EMPTY,0,UINT,1,I4,1);
3859 VAROR(EMPTY,0,BOOL,0,I2,0);
3860 VAROR(EMPTY,0,BOOL,1,I2,1);
3861 VAROR(EMPTY,0,R4,0,I4,0);
3862 VAROR(EMPTY,0,R4,1,I4,1);
3863 VAROR(EMPTY,0,R8,0,I4,0);
3864 VAROR(EMPTY,0,R8,1,I4,1);
3865 rbstr = SysAllocString(szFalse);
3866 VAROR(EMPTY,0,BSTR,rbstr,I2,0);
3867 rbstr = SysAllocString(szTrue);
3868 VAROR(EMPTY,0,BSTR,rbstr,I2,-1);
3869 VARORCY(EMPTY,0,10000,I4,1);
3871 /* NULL OR 0 = NULL. NULL OR n = n */
3872 VAROR(NULL,0,NULL,0,NULL,0);
3873 VAROR(NULL,1,NULL,0,NULL,0);
3874 VAROR(NULL,0,I1,0,NULL,0);
3875 VAROR(NULL,0,I1,1,I4,1);
3876 VAROR(NULL,0,UI1,0,NULL,0);
3877 VAROR(NULL,0,UI1,1,UI1,1);
3878 VAROR(NULL,0,I2,0,NULL,0);
3879 VAROR(NULL,0,I2,1,I2,1);
3880 VAROR(NULL,0,UI2,0,NULL,0);
3881 VAROR(NULL,0,UI2,1,I4,1);
3882 VAROR(NULL,0,I4,0,NULL,0);
3883 VAROR(NULL,0,I4,1,I4,1);
3884 VAROR(NULL,0,UI4,0,NULL,0);
3885 VAROR(NULL,0,UI4,1,I4,1);
3886 if (HAVE_OLEAUT32_I8)
3888 VAROR(NULL,0,I8,0,NULL,0);
3889 VAROR(NULL,0,I8,1,I8,1);
3890 VAROR(NULL,0,UI8,0,NULL,0);
3891 VAROR(NULL,0,UI8,1,I4,1);
3893 VAROR(NULL,0,INT,0,NULL,0);
3894 VAROR(NULL,0,INT,1,I4,1);
3895 VAROR(NULL,0,UINT,0,NULL,0);
3896 VAROR(NULL,0,UINT,1,I4,1);
3897 VAROR(NULL,0,BOOL,0,NULL,0);
3898 VAROR(NULL,0,BOOL,1,BOOL,1);
3899 VAROR(NULL,0,R4,0,NULL,0);
3900 VAROR(NULL,0,R4,1,I4,1);
3901 VAROR(NULL,0,R8,0,NULL,0);
3902 VAROR(NULL,0,R8,1,I4,1);
3903 rbstr = SysAllocString(szFalse);
3904 VAROR(NULL,0,BSTR,rbstr,NULL,0);
3905 rbstr = SysAllocString(szTrue);
3906 VAROR(NULL,0,BSTR,rbstr,BOOL,VARIANT_TRUE);
3907 VARORCY(NULL,0,10000,I4,1);
3908 VARORCY(NULL,0,0,NULL,0);
3910 VAROR(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
3911 VAROR(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
3912 VAROR(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
3913 VAROR(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
3914 /* Assume x,y & y,x are the same from now on to reduce the number of tests */
3915 VAROR(BOOL,VARIANT_TRUE,I1,-1,I4,-1);
3916 VAROR(BOOL,VARIANT_TRUE,I1,0,I4,-1);
3917 VAROR(BOOL,VARIANT_FALSE,I1,0,I4,0);
3918 VAROR(BOOL,VARIANT_TRUE,UI1,255,I2,-1);
3919 VAROR(BOOL,VARIANT_TRUE,UI1,0,I2,-1);
3920 VAROR(BOOL,VARIANT_FALSE,UI1,0,I2,0);
3921 VAROR(BOOL,VARIANT_TRUE,I2,-1,I2,-1);
3922 VAROR(BOOL,VARIANT_TRUE,I2,0,I2,-1);
3923 VAROR(BOOL,VARIANT_FALSE,I2,0,I2,0);
3924 VAROR(BOOL,VARIANT_TRUE,UI2,65535,I4,-1);
3925 VAROR(BOOL,VARIANT_TRUE,UI2,0,I4,-1);
3926 VAROR(BOOL,VARIANT_FALSE,UI2,0,I4,0);
3927 VAROR(BOOL,VARIANT_TRUE,I4,-1,I4,-1);
3928 VAROR(BOOL,VARIANT_TRUE,I4,0,I4,-1);
3929 VAROR(BOOL,VARIANT_FALSE,I4,0,I4,0);
3930 VAROR(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,-1);
3931 VAROR(BOOL,VARIANT_TRUE,UI4,0,I4,-1);
3932 VAROR(BOOL,VARIANT_FALSE,UI4,0,I4,0);
3933 VAROR(BOOL,VARIANT_TRUE,R4,-1,I4,-1);
3934 VAROR(BOOL,VARIANT_TRUE,R4,0,I4,-1);
3935 VAROR(BOOL,VARIANT_FALSE,R4,0,I4,0);
3936 VAROR(BOOL,VARIANT_TRUE,R8,-1,I4,-1);
3937 VAROR(BOOL,VARIANT_TRUE,R8,0,I4,-1);
3938 VAROR(BOOL,VARIANT_FALSE,R8,0,I4,0);
3939 VAROR(BOOL,VARIANT_TRUE,DATE,-1,I4,-1);
3940 VAROR(BOOL,VARIANT_TRUE,DATE,0,I4,-1);
3941 VAROR(BOOL,VARIANT_FALSE,DATE,0,I4,0);
3942 if (HAVE_OLEAUT32_I8)
3944 VAROR(BOOL,VARIANT_TRUE,I8,-1,I8,-1);
3945 VAROR(BOOL,VARIANT_TRUE,I8,0,I8,-1);
3946 VAROR(BOOL,VARIANT_FALSE,I8,0,I8,0);
3947 /* This returns DISP_E_OVERFLOW which indicates that a conversion
3948 * to I4 is performed.
3950 /* VAROR(BOOL,VARIANT_TRUE,UI8,-1,I4,-1); */
3951 VAROR(BOOL,VARIANT_TRUE,UI8,0,I4,-1);
3952 VAROR(BOOL,VARIANT_FALSE,UI8,0,I4,0);
3954 VAROR(BOOL,VARIANT_TRUE,INT,-1,I4,-1);
3955 VAROR(BOOL,VARIANT_TRUE,INT,0,I4,-1);
3956 VAROR(BOOL,VARIANT_FALSE,INT,0,I4,0);
3957 VAROR(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,-1);
3958 VAROR(BOOL,VARIANT_TRUE,UINT,0,I4,-1);
3959 VAROR(BOOL,VARIANT_FALSE,UINT,0,I4,0);
3960 rbstr = SysAllocString(szFalse);
3961 VAROR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_FALSE);
3962 VAROR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
3963 rbstr = SysAllocString(szTrue);
3964 VAROR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_TRUE);
3965 VAROR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
3966 VARORCY(BOOL,VARIANT_TRUE,10000,I4,-1);
3967 VARORCY(BOOL,VARIANT_TRUE,0,I4,-1);
3968 VARORCY(BOOL,VARIANT_FALSE,0,I4,0);
3970 VAROR(I1,-1,I1,-1,I4,-1);
3971 VAROR(I1,-1,I1,0,I4,-1);
3972 VAROR(I1,0,I1,0,I4,0);
3973 VAROR(I1,-1,UI1,255,I4,-1);
3974 VAROR(I1,-1,UI1,0,I4,-1);
3975 VAROR(I1,0,UI1,0,I4,0);
3976 VAROR(I1,-1,I2,-1,I4,-1);
3977 VAROR(I1,-1,I2,0,I4,-1);
3978 VAROR(I1,0,I2,0,I4,0);
3979 VAROR(I1,-1,UI2,65535,I4,-1);
3980 VAROR(I1,-1,UI2,0,I4,-1);
3981 VAROR(I1,0,UI2,0,I4,0);
3982 VAROR(I1,-1,I4,-1,I4,-1);
3983 VAROR(I1,-1,I4,0,I4,-1);
3984 VAROR(I1,0,I4,0,I4,0);
3985 VAROR(I1,-1,UI4,0xffffffff,I4,-1);
3986 VAROR(I1,-1,UI4,0,I4,-1);
3987 VAROR(I1,0,UI4,0,I4,0);
3988 VAROR(I1,-1,R4,-1,I4,-1);
3989 VAROR(I1,-1,R4,0,I4,-1);
3990 VAROR(I1,0,R4,0,I4,0);
3991 VAROR(I1,-1,R8,-1,I4,-1);
3992 VAROR(I1,-1,R8,0,I4,-1);
3993 VAROR(I1,0,R8,0,I4,0);
3994 VAROR(I1,-1,DATE,-1,I4,-1);
3995 VAROR(I1,-1,DATE,0,I4,-1);
3996 VAROR(I1,0,DATE,0,I4,0);
3997 if (HAVE_OLEAUT32_I8)
3999 VAROR(I1,-1,I8,-1,I8,-1);
4000 VAROR(I1,-1,I8,0,I8,-1);
4001 VAROR(I1,0,I8,0,I8,0);
4002 VAROR(I1,-1,UI8,0,I4,-1);
4003 VAROR(I1,0,UI8,0,I4,0);
4005 VAROR(I1,-1,INT,-1,I4,-1);
4006 VAROR(I1,-1,INT,0,I4,-1);
4007 VAROR(I1,0,INT,0,I4,0);
4008 VAROR(I1,-1,UINT,0xffffffff,I4,-1);
4009 VAROR(I1,-1,UINT,0,I4,-1);
4010 VAROR(I1,0,UINT,0,I4,0);
4011 rbstr = SysAllocString(szFalse);
4012 VAROR(I1,0,BSTR,rbstr,I4,0);
4013 VAROR(I1,-1,BSTR,rbstr,I4,-1);
4014 rbstr = SysAllocString(szTrue);
4015 VAROR(I1,0,BSTR,rbstr,I4,-1);
4016 VAROR(I1,-1,BSTR,rbstr,I4,-1);
4017 VARORCY(I1,-1,10000,I4,-1);
4018 VARORCY(I1,-1,0,I4,-1);
4019 VARORCY(I1,0,0,I4,0);
4021 VAROR(UI1,255,UI1,255,UI1,255);
4022 VAROR(UI1,255,UI1,0,UI1,255);
4023 VAROR(UI1,0,UI1,0,UI1,0);
4024 VAROR(UI1,255,I2,-1,I2,-1);
4025 VAROR(UI1,255,I2,0,I2,255);
4026 VAROR(UI1,0,I2,0,I2,0);
4027 VAROR(UI1,255,UI2,65535,I4,65535);
4028 VAROR(UI1,255,UI2,0,I4,255);
4029 VAROR(UI1,0,UI2,0,I4,0);
4030 VAROR(UI1,255,I4,-1,I4,-1);
4031 VAROR(UI1,255,I4,0,I4,255);
4032 VAROR(UI1,0,I4,0,I4,0);
4033 VAROR(UI1,255,UI4,0xffffffff,I4,-1);
4034 VAROR(UI1,255,UI4,0,I4,255);
4035 VAROR(UI1,0,UI4,0,I4,0);
4036 VAROR(UI1,255,R4,-1,I4,-1);
4037 VAROR(UI1,255,R4,0,I4,255);
4038 VAROR(UI1,0,R4,0,I4,0);
4039 VAROR(UI1,255,R8,-1,I4,-1);
4040 VAROR(UI1,255,R8,0,I4,255);
4041 VAROR(UI1,0,R8,0,I4,0);
4042 VAROR(UI1,255,DATE,-1,I4,-1);
4043 VAROR(UI1,255,DATE,0,I4,255);
4044 VAROR(UI1,0,DATE,0,I4,0);
4045 if (HAVE_OLEAUT32_I8)
4047 VAROR(UI1,255,I8,-1,I8,-1);
4048 VAROR(UI1,255,I8,0,I8,255);
4049 VAROR(UI1,0,I8,0,I8,0);
4050 VAROR(UI1,255,UI8,0,I4,255);
4051 VAROR(UI1,0,UI8,0,I4,0);
4053 VAROR(UI1,255,INT,-1,I4,-1);
4054 VAROR(UI1,255,INT,0,I4,255);
4055 VAROR(UI1,0,INT,0,I4,0);
4056 VAROR(UI1,255,UINT,0xffffffff,I4,-1);
4057 VAROR(UI1,255,UINT,0,I4,255);
4058 VAROR(UI1,0,UINT,0,I4,0);
4059 rbstr = SysAllocString(szFalse);
4060 VAROR(UI1,0,BSTR,rbstr,I2,0);
4061 VAROR(UI1,255,BSTR,rbstr,I2,255);
4062 rbstr = SysAllocString(szTrue);
4063 VAROR(UI1,0,BSTR,rbstr,I2,-1);
4064 VAROR(UI1,255,BSTR,rbstr,I2,-1);
4065 VARORCY(UI1,255,10000,I4,255);
4066 VARORCY(UI1,255,0,I4,255);
4067 VARORCY(UI1,0,0,I4,0);
4069 VAROR(I2,-1,I2,-1,I2,-1);
4070 VAROR(I2,-1,I2,0,I2,-1);
4071 VAROR(I2,0,I2,0,I2,0);
4072 VAROR(I2,-1,UI2,65535,I4,-1);
4073 VAROR(I2,-1,UI2,0,I4,-1);
4074 VAROR(I2,0,UI2,0,I4,0);
4075 VAROR(I2,-1,I4,-1,I4,-1);
4076 VAROR(I2,-1,I4,0,I4,-1);
4077 VAROR(I2,0,I4,0,I4,0);
4078 VAROR(I2,-1,UI4,0xffffffff,I4,-1);
4079 VAROR(I2,-1,UI4,0,I4,-1);
4080 VAROR(I2,0,UI4,0,I4,0);
4081 VAROR(I2,-1,R4,-1,I4,-1);
4082 VAROR(I2,-1,R4,0,I4,-1);
4083 VAROR(I2,0,R4,0,I4,0);
4084 VAROR(I2,-1,R8,-1,I4,-1);
4085 VAROR(I2,-1,R8,0,I4,-1);
4086 VAROR(I2,0,R8,0,I4,0);
4087 VAROR(I2,-1,DATE,-1,I4,-1);
4088 VAROR(I2,-1,DATE,0,I4,-1);
4089 VAROR(I2,0,DATE,0,I4,0);
4090 if (HAVE_OLEAUT32_I8)
4092 VAROR(I2,-1,I8,-1,I8,-1);
4093 VAROR(I2,-1,I8,0,I8,-1);
4094 VAROR(I2,0,I8,0,I8,0);
4095 VAROR(I2,-1,UI8,0,I4,-1);
4096 VAROR(I2,0,UI8,0,I4,0);
4098 VAROR(I2,-1,INT,-1,I4,-1);
4099 VAROR(I2,-1,INT,0,I4,-1);
4100 VAROR(I2,0,INT,0,I4,0);
4101 VAROR(I2,-1,UINT,0xffffffff,I4,-1);
4102 VAROR(I2,-1,UINT,0,I4,-1);
4103 VAROR(I2,0,UINT,0,I4,0);
4104 rbstr = SysAllocString(szFalse);
4105 VAROR(I2,0,BSTR,rbstr,I2,0);
4106 VAROR(I2,-1,BSTR,rbstr,I2,-1);
4107 rbstr = SysAllocString(szTrue);
4108 VAROR(I2,0,BSTR,rbstr,I2,-1);
4109 VAROR(I2,-1,BSTR,rbstr,I2,-1);
4110 VARORCY(I2,-1,10000,I4,-1);
4111 VARORCY(I2,-1,0,I4,-1);
4112 VARORCY(I2,0,0,I4,0);
4114 VAROR(UI2,65535,UI2,65535,I4,65535);
4115 VAROR(UI2,65535,UI2,0,I4,65535);
4116 VAROR(UI2,0,UI2,0,I4,0);
4117 VAROR(UI2,65535,I4,-1,I4,-1);
4118 VAROR(UI2,65535,I4,0,I4,65535);
4119 VAROR(UI2,0,I4,0,I4,0);
4120 VAROR(UI2,65535,UI4,0xffffffff,I4,-1);
4121 VAROR(UI2,65535,UI4,0,I4,65535);
4122 VAROR(UI2,0,UI4,0,I4,0);
4123 VAROR(UI2,65535,R4,-1,I4,-1);
4124 VAROR(UI2,65535,R4,0,I4,65535);
4125 VAROR(UI2,0,R4,0,I4,0);
4126 VAROR(UI2,65535,R8,-1,I4,-1);
4127 VAROR(UI2,65535,R8,0,I4,65535);
4128 VAROR(UI2,0,R8,0,I4,0);
4129 VAROR(UI2,65535,DATE,-1,I4,-1);
4130 VAROR(UI2,65535,DATE,0,I4,65535);
4131 VAROR(UI2,0,DATE,0,I4,0);
4132 if (HAVE_OLEAUT32_I8)
4134 VAROR(UI2,65535,I8,-1,I8,-1);
4135 VAROR(UI2,65535,I8,0,I8,65535);
4136 VAROR(UI2,0,I8,0,I8,0);
4137 VAROR(UI2,65535,UI8,0,I4,65535);
4138 VAROR(UI2,0,UI8,0,I4,0);
4140 VAROR(UI2,65535,INT,-1,I4,-1);
4141 VAROR(UI2,65535,INT,0,I4,65535);
4142 VAROR(UI2,0,INT,0,I4,0);
4143 VAROR(UI2,65535,UINT,0xffffffff,I4,-1);
4144 VAROR(UI2,65535,UINT,0,I4,65535);
4145 VAROR(UI2,0,UINT,0,I4,0);
4146 rbstr = SysAllocString(szFalse);
4147 VAROR(UI2,0,BSTR,rbstr,I4,0);
4148 VAROR(UI2,65535,BSTR,rbstr,I4,65535);
4149 rbstr = SysAllocString(szTrue);
4150 VAROR(UI2,0,BSTR,rbstr,I4,-1);
4151 VAROR(UI2,65535,BSTR,rbstr,I4,-1);
4152 VARORCY(UI2,65535,10000,I4,65535);
4153 VARORCY(UI2,65535,0,I4,65535);
4154 VARORCY(UI2,0,0,I4,0);
4156 VAROR(I4,-1,I4,-1,I4,-1);
4157 VAROR(I4,-1,I4,0,I4,-1);
4158 VAROR(I4,0,I4,0,I4,0);
4159 VAROR(I4,-1,UI4,0xffffffff,I4,-1);
4160 VAROR(I4,-1,UI4,0,I4,-1);
4161 VAROR(I4,0,UI4,0,I4,0);
4162 VAROR(I4,-1,R4,-1,I4,-1);
4163 VAROR(I4,-1,R4,0,I4,-1);
4164 VAROR(I4,0,R4,0,I4,0);
4165 VAROR(I4,-1,R8,-1,I4,-1);
4166 VAROR(I4,-1,R8,0,I4,-1);
4167 VAROR(I4,0,R8,0,I4,0);
4168 VAROR(I4,-1,DATE,-1,I4,-1);
4169 VAROR(I4,-1,DATE,0,I4,-1);
4170 VAROR(I4,0,DATE,0,I4,0);
4171 if (HAVE_OLEAUT32_I8)
4173 VAROR(I4,-1,I8,-1,I8,-1);
4174 VAROR(I4,-1,I8,0,I8,-1);
4175 VAROR(I4,0,I8,0,I8,0);
4176 VAROR(I4,-1,UI8,0,I4,-1);
4177 VAROR(I4,0,UI8,0,I4,0);
4179 VAROR(I4,-1,INT,-1,I4,-1);
4180 VAROR(I4,-1,INT,0,I4,-1);
4181 VAROR(I4,0,INT,0,I4,0);
4182 VAROR(I4,-1,UINT,0xffffffff,I4,-1);
4183 VAROR(I4,-1,UINT,0,I4,-1);
4184 VAROR(I4,0,UINT,0,I4,0);
4185 rbstr = SysAllocString(szFalse);
4186 VAROR(I4,0,BSTR,rbstr,I4,0);
4187 VAROR(I4,-1,BSTR,rbstr,I4,-1);
4188 rbstr = SysAllocString(szTrue);
4189 VAROR(I4,0,BSTR,rbstr,I4,-1);
4190 VAROR(I4,-1,BSTR,rbstr,I4,-1);
4191 VARORCY(I4,-1,10000,I4,-1);
4192 VARORCY(I4,-1,0,I4,-1);
4193 VARORCY(I4,0,0,I4,0);
4195 VAROR(UI4,0xffffffff,UI4,0xffffffff,I4,-1);
4196 VAROR(UI4,0xffffffff,UI4,0,I4,-1);
4197 VAROR(UI4,0,UI4,0,I4,0);
4198 VAROR(UI4,0xffffffff,R4,-1,I4,-1);
4199 VAROR(UI4,0xffffffff,R4,0,I4,-1);
4200 VAROR(UI4,0,R4,0,I4,0);
4201 VAROR(UI4,0xffffffff,R8,-1,I4,-1);
4202 VAROR(UI4,0xffffffff,R8,0,I4,-1);
4203 VAROR(UI4,0,R8,0,I4,0);
4204 VAROR(UI4,0xffffffff,DATE,-1,I4,-1);
4205 VAROR(UI4,0xffffffff,DATE,0,I4,-1);
4206 VAROR(UI4,0,DATE,0,I4,0);
4207 if (HAVE_OLEAUT32_I8)
4209 VAROR(UI4,0xffffffff,I8,-1,I8,-1);
4210 VAROR(UI4,0xffffffff,I8,0,I8,0xffffffff);
4211 VAROR(UI4,0,I8,0,I8,0);
4212 VAROR(UI4,0xffffffff,UI8,0,I4,-1);
4213 VAROR(UI4,0,UI8,0,I4,0);
4215 VAROR(UI4,0xffffffff,INT,-1,I4,-1);
4216 VAROR(UI4,0xffffffff,INT,0,I4,-1);
4217 VAROR(UI4,0,INT,0,I4,0);
4218 VAROR(UI4,0xffffffff,UINT,0xffffffff,I4,-1);
4219 VAROR(UI4,0xffffffff,UINT,0,I4,-1);
4220 VAROR(UI4,0,UINT,0,I4,0);
4221 rbstr = SysAllocString(szFalse);
4222 VAROR(UI4,0,BSTR,rbstr,I4,0);
4223 VAROR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
4224 rbstr = SysAllocString(szTrue);
4225 VAROR(UI4,0,BSTR,rbstr,I4,-1);
4226 VAROR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
4227 VARORCY(UI4,0xffffffff,10000,I4,-1);
4228 VARORCY(UI4,0xffffffff,0,I4,-1);
4229 VARORCY(UI4,0,0,I4,0);
4231 VAROR(R4,-1,R4,-1,I4,-1);
4232 VAROR(R4,-1,R4,0,I4,-1);
4233 VAROR(R4,0,R4,0,I4,0);
4234 VAROR(R4,-1,R8,-1,I4,-1);
4235 VAROR(R4,-1,R8,0,I4,-1);
4236 VAROR(R4,0,R8,0,I4,0);
4237 VAROR(R4,-1,DATE,-1,I4,-1);
4238 VAROR(R4,-1,DATE,0,I4,-1);
4239 VAROR(R4,0,DATE,0,I4,0);
4240 if (HAVE_OLEAUT32_I8)
4242 VAROR(R4,-1,I8,-1,I8,-1);
4243 VAROR(R4,-1,I8,0,I8,-1);
4244 VAROR(R4,0,I8,0,I8,0);
4245 VAROR(R4,-1,UI8,0,I4,-1);
4246 VAROR(R4,0,UI8,0,I4,0);
4248 VAROR(R4,-1,INT,-1,I4,-1);
4249 VAROR(R4,-1,INT,0,I4,-1);
4250 VAROR(R4,0,INT,0,I4,0);
4251 VAROR(R4,-1,UINT,0xffffffff,I4,-1);
4252 VAROR(R4,-1,UINT,0,I4,-1);
4253 VAROR(R4,0,UINT,0,I4,0);
4254 rbstr = SysAllocString(szFalse);
4255 VAROR(R4,0,BSTR,rbstr,I4,0);
4256 VAROR(R4,-1,BSTR,rbstr,I4,-1);
4257 rbstr = SysAllocString(szTrue);
4258 VAROR(R4,0,BSTR,rbstr,I4,-1);
4259 VAROR(R4,-1,BSTR,rbstr,I4,-1);
4260 VARORCY(R4,-1,10000,I4,-1);
4261 VARORCY(R4,-1,0,I4,-1);
4262 VARORCY(R4,0,0,I4,0);
4264 VAROR(R8,-1,R8,-1,I4,-1);
4265 VAROR(R8,-1,R8,0,I4,-1);
4266 VAROR(R8,0,R8,0,I4,0);
4267 VAROR(R8,-1,DATE,-1,I4,-1);
4268 VAROR(R8,-1,DATE,0,I4,-1);
4269 VAROR(R8,0,DATE,0,I4,0);
4270 if (HAVE_OLEAUT32_I8)
4272 VAROR(R8,-1,I8,-1,I8,-1);
4273 VAROR(R8,-1,I8,0,I8,-1);
4274 VAROR(R8,0,I8,0,I8,0);
4275 VAROR(R8,-1,UI8,0,I4,-1);
4276 VAROR(R8,0,UI8,0,I4,0);
4278 VAROR(R8,-1,INT,-1,I4,-1);
4279 VAROR(R8,-1,INT,0,I4,-1);
4280 VAROR(R8,0,INT,0,I4,0);
4281 VAROR(R8,-1,UINT,0xffffffff,I4,-1);
4282 VAROR(R8,-1,UINT,0,I4,-1);
4283 VAROR(R8,0,UINT,0,I4,0);
4284 rbstr = SysAllocString(szFalse);
4285 VAROR(R8,0,BSTR,rbstr,I4,0);
4286 VAROR(R8,-1,BSTR,rbstr,I4,-1);
4287 rbstr = SysAllocString(szTrue);
4288 VAROR(R8,0,BSTR,rbstr,I4,-1);
4289 VAROR(R8,-1,BSTR,rbstr,I4,-1);
4290 VARORCY(R8,-1,10000,I4,-1);
4291 VARORCY(R8,-1,0,I4,-1);
4292 VARORCY(R8,0,0,I4,0);
4294 VAROR(DATE,-1,DATE,-1,I4,-1);
4295 VAROR(DATE,-1,DATE,0,I4,-1);
4296 VAROR(DATE,0,DATE,0,I4,0);
4297 if (HAVE_OLEAUT32_I8)
4299 VAROR(DATE,-1,I8,-1,I8,-1);
4300 VAROR(DATE,-1,I8,0,I8,-1);
4301 VAROR(DATE,0,I8,0,I8,0);
4302 VAROR(DATE,-1,UI8,0,I4,-1);
4303 VAROR(DATE,0,UI8,0,I4,0);
4305 VAROR(DATE,-1,INT,-1,I4,-1);
4306 VAROR(DATE,-1,INT,0,I4,-1);
4307 VAROR(DATE,0,INT,0,I4,0);
4308 VAROR(DATE,-1,UINT,0xffffffff,I4,-1);
4309 VAROR(DATE,-1,UINT,0,I4,-1);
4310 VAROR(DATE,0,UINT,0,I4,0);
4311 rbstr = SysAllocString(szFalse);
4312 VAROR(DATE,0,BSTR,rbstr,I4,0);
4313 VAROR(DATE,-1,BSTR,rbstr,I4,-1);
4314 rbstr = SysAllocString(szTrue);
4315 VAROR(DATE,0,BSTR,rbstr,I4,-1);
4316 VAROR(DATE,-1,BSTR,rbstr,I4,-1);
4317 VARORCY(DATE,-1,10000,I4,-1);
4318 VARORCY(DATE,-1,0,I4,-1);
4319 VARORCY(DATE,0,0,I4,0);
4321 if (HAVE_OLEAUT32_I8)
4323 VAROR(I8,-1,I8,-1,I8,-1);
4324 VAROR(I8,-1,I8,0,I8,-1);
4325 VAROR(I8,0,I8,0,I8,0);
4326 VAROR(I8,-1,UI8,0,I8,-1);
4327 VAROR(I8,0,UI8,0,I8,0);
4328 /* These overflow under native and Wine
4329 VAROR(I8,-1,INT,-1,I4,-1);
4330 VAROR(I8,-1,INT,0,I4,-1);
4331 VAROR(I8,0,INT,0,I4,0); */
4332 VAROR(I8,-1,UINT,0xffffffff,I8,-1);
4333 VAROR(I8,-1,UINT,0,I8,-1);
4334 VAROR(I8,0,UINT,0,I8,0);
4335 rbstr = SysAllocString(szFalse);
4336 VAROR(I8,0,BSTR,rbstr,I8,0);
4337 VAROR(I8,-1,BSTR,rbstr,I8,-1);
4338 rbstr = SysAllocString(szTrue);
4339 VAROR(I8,0,BSTR,rbstr,I8,-1);
4340 VAROR(I8,-1,BSTR,rbstr,I8,-1);
4341 VARORCY(I8,-1,10000,I8,-1);
4342 VARORCY(I8,-1,0,I8,-1);
4343 VARORCY(I8,0,0,I8,0);
4345 VAROR(UI8,0xffff,UI8,0xffff,I4,0xffff);
4346 VAROR(UI8,0xffff,UI8,0,I4,0xffff);
4347 VAROR(UI8,0,UI8,0,I4,0);
4348 VAROR(UI8,0xffff,INT,-1,I4,-1);
4349 VAROR(UI8,0xffff,INT,0,I4,0xffff);
4350 VAROR(UI8,0,INT,0,I4,0);
4351 VAROR(UI8,0xffff,UINT,0xffff,I4,0xffff);
4352 VAROR(UI8,0xffff,UINT,0,I4,0xffff);
4353 VAROR(UI8,0,UINT,0,I4,0);
4354 rbstr = SysAllocString(szFalse);
4355 VAROR(UI8,0,BSTR,rbstr,I4,0);
4356 VAROR(UI8,0xffff,BSTR,rbstr,I4,0xffff);
4357 rbstr = SysAllocString(szTrue);
4358 VAROR(UI8,0,BSTR,rbstr,I4,-1);
4359 VAROR(UI8,0xffff,BSTR,rbstr,I4,-1);
4360 VARORCY(UI8,0xffff,10000,I4,0xffff);
4361 VARORCY(UI8,0xffff,0,I4,0xffff);
4362 VARORCY(UI8,0,0,I4,0);
4365 VAROR(INT,-1,INT,-1,I4,-1);
4366 VAROR(INT,-1,INT,0,I4,-1);
4367 VAROR(INT,0,INT,0,I4,0);
4368 VAROR(INT,-1,UINT,0xffff,I4,-1);
4369 VAROR(INT,-1,UINT,0,I4,-1);
4370 VAROR(INT,0,UINT,0,I4,0);
4371 rbstr = SysAllocString(szFalse);
4372 VAROR(INT,0,BSTR,rbstr,I4,0);
4373 VAROR(INT,-1,BSTR,rbstr,I4,-1);
4374 rbstr = SysAllocString(szTrue);
4375 VAROR(INT,0,BSTR,rbstr,I4,-1);
4376 VAROR(INT,-1,BSTR,rbstr,I4,-1);
4377 VARORCY(INT,-1,10000,I4,-1);
4378 VARORCY(INT,-1,0,I4,-1);
4379 VARORCY(INT,0,0,I4,0);
4381 VAROR(UINT,0xffff,UINT,0xffff,I4,0xffff);
4382 VAROR(UINT,0xffff,UINT,0,I4,0xffff);
4383 VAROR(UINT,0,UINT,0,I4,0);
4384 rbstr = SysAllocString(szFalse);
4385 VAROR(UINT,0,BSTR,rbstr,I4,0);
4386 VAROR(UINT,0xffff,BSTR,rbstr,I4,0xffff);
4387 rbstr = SysAllocString(szTrue);
4388 VAROR(UINT,0,BSTR,rbstr,I4,-1);
4389 VAROR(UINT,0xffff,BSTR,rbstr,I4,-1);
4390 VARORCY(UINT,0xffff,10000,I4,0xffff);
4391 VARORCY(UINT,0xffff,0,I4,0xffff);
4392 VARORCY(UINT,0,0,I4,0);
4394 lbstr = SysAllocString(szFalse);
4395 rbstr = SysAllocString(szFalse);
4396 VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,0);
4397 rbstr = SysAllocString(szTrue);
4398 VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
4399 lbstr = SysAllocString(szTrue);
4400 VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
4401 VARORCY(BSTR,lbstr,10000,I4,-1);
4402 lbstr = SysAllocString(szFalse);
4403 VARORCY(BSTR,lbstr,10000,I4,1);
4406 static HRESULT (WINAPI *pVarEqv)(LPVARIANT,LPVARIANT,LPVARIANT);
4408 static const char *szVarEqvFail = "VarEqv(%d,%d): expected 0x0,%d,%d, got 0x%lX,%d,%d\n";
4409 #define VAREQV(vt1,val1,vt2,val2,rvt,rval) \
4410 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
4411 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
4412 memset(&result,0,sizeof(result)); hres = pVarEqv(&left,&right,&result); \
4413 ok(hres == S_OK && V_VT(&result) == VT_##rvt && V_##rvt(&result) == (rval), \
4414 szVarEqvFail, VT_##vt1, VT_##vt2, \
4415 VT_##rvt, (int)(rval), hres, V_VT(&result), (int)V_##rvt(&result))
4417 static void test_VarEqv(void)
4419 VARIANT left, right, result;
4420 VARTYPE i;
4421 HRESULT hres;
4423 CHECKPTR(VarEqv);
4425 /* Test all possible flag/vt combinations & the resulting vt type */
4426 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
4428 VARTYPE leftvt, rightvt, resvt;
4430 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
4432 SKIPTESTS(leftvt);
4434 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
4436 BOOL bFail = FALSE;
4438 SKIPTESTS(rightvt);
4440 if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
4441 leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
4442 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
4443 continue;
4445 memset(&left, 0, sizeof(left));
4446 memset(&right, 0, sizeof(right));
4447 V_VT(&left) = leftvt | ExtraFlags[i];
4448 V_VT(&right) = rightvt | ExtraFlags[i];
4449 V_VT(&result) = VT_EMPTY;
4450 resvt = VT_I4;
4452 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
4453 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
4454 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
4455 leftvt == VT_CLSID || rightvt == VT_CLSID ||
4456 leftvt == VT_RECORD || rightvt == VT_RECORD ||
4457 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
4458 leftvt == VT_ERROR || rightvt == VT_ERROR)
4460 bFail = TRUE;
4462 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
4464 if (leftvt == rightvt ||
4465 leftvt == VT_I2 || rightvt == VT_I2 ||
4466 leftvt == VT_UI1 || rightvt == VT_UI1 ||
4467 leftvt == VT_BOOL || rightvt == VT_BOOL)
4468 resvt = VT_I2;
4469 else if (leftvt == VT_NULL || rightvt == VT_NULL)
4470 resvt = VT_NULL;
4471 else if (leftvt == VT_I8 || rightvt == VT_I8)
4472 resvt = VT_I8;
4474 else if (leftvt == VT_NULL || rightvt == VT_NULL)
4476 resvt = VT_NULL;
4478 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
4480 if (leftvt == rightvt)
4481 resvt = VT_UI1;
4482 else if (leftvt == rightvt ||
4483 leftvt == VT_I2 || rightvt == VT_I2 ||
4484 leftvt == VT_BOOL || rightvt == VT_BOOL)
4486 resvt = VT_I2;
4488 else if (leftvt == VT_I8 || rightvt == VT_I8)
4489 resvt = VT_I8;
4491 else if (leftvt == VT_I2 || rightvt == VT_I2)
4493 if (leftvt == rightvt ||
4494 leftvt == VT_BOOL || rightvt == VT_BOOL)
4495 resvt = VT_I2;
4496 else if (leftvt == VT_I8 || rightvt == VT_I8)
4497 resvt = VT_I8;
4499 else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
4501 resvt = VT_BOOL;
4503 else if (leftvt == VT_I8 || rightvt == VT_I8)
4505 if (leftvt == VT_INT || rightvt == VT_INT)
4506 bFail = TRUE;
4507 else
4508 resvt = VT_I8;
4510 hres = pVarEqv(&left, &right, &result);
4511 if (bFail)
4512 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
4513 "VarEqv: %d|0x%X, %d|0x%X: Expected failure, got 0x%lX vt %d\n",
4514 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
4515 V_VT(&result));
4516 else
4517 ok(hres == S_OK && V_VT(&result) == resvt,
4518 "VarEqv: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%lX vt %d\n",
4519 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
4520 V_VT(&result));
4525 /* Test returned values */
4526 VAREQV(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
4527 VAREQV(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
4528 VAREQV(BOOL,TRUE,BOOL,TRUE,BOOL,VARIANT_TRUE);
4529 VAREQV(BOOL,FALSE,BOOL,FALSE,BOOL,VARIANT_TRUE);
4530 VAREQV(BOOL,TRUE,BOOL,FALSE,BOOL,-2);
4531 VAREQV(BOOL,FALSE,BOOL,TRUE,BOOL,-2);
4532 VAREQV(BOOL,6,BOOL,7,BOOL,-2);
4533 VAREQV(BOOL,6,BOOL,6,BOOL,VARIANT_TRUE);
4534 VAREQV(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE,I2,VARIANT_TRUE);
4535 VAREQV(BOOL,VARIANT_TRUE,I2,VARIANT_FALSE,I2,VARIANT_FALSE);
4536 VAREQV(BOOL,6,I2,7,I2,-2);
4537 VAREQV(UI1,1,UI1,1,UI1,255);
4538 VAREQV(UI1,1,UI1,0,UI1,254);
4539 VAREQV(UI1,0,UI1,1,UI1,254);
4540 if (HAVE_OLEAUT32_I8)
4542 VAREQV(UI4,VARIANT_FALSE,I8,VARIANT_FALSE,I8,-1);
4543 VAREQV(UI4,5,I8,19,I8,-23);
4544 VAREQV(UI4,VARIANT_FALSE,UI8,VARIANT_FALSE,I4,-1);
4548 static HRESULT (WINAPI *pVarMul)(LPVARIANT,LPVARIANT,LPVARIANT);
4550 static const char *szVarMulI4 = "VarMul(%d,%d): expected 0x0,%d,%d, got 0x%lX,%d,%d\n";
4551 static const char *szVarMulR8 = "VarMul(%d,%d): expected 0x0,%d,%f, got 0x%lX,%d,%f\n";
4553 #define VARMUL(vt1,val1,vt2,val2,rvt,rval) \
4554 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
4555 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
4556 memset(&result,0,sizeof(result)); hres = pVarMul(&left,&right,&result); \
4557 if (VT_##rvt == VT_R4 || VT_##rvt == VT_R8) { \
4558 ok(hres == S_OK && V_VT(&result) == VT_##rvt && \
4559 EQ_FLOAT(V_##rvt(&result), rval), \
4560 szVarMulR8, VT_##vt1, VT_##vt2, \
4561 VT_##rvt, (double)(rval), hres, V_VT(&result), (double)V_##rvt(&result)); \
4562 } else { \
4563 ok(hres == S_OK && V_VT(&result) == VT_##rvt && V_##rvt(&result) == (rval), \
4564 szVarMulI4, VT_##vt1, VT_##vt2, \
4565 VT_##rvt, (int)(rval), hres, V_VT(&result), (int)V_##rvt(&result)); }
4567 static void test_VarMul(void)
4569 static const WCHAR sz12[] = {'1','2','\0'};
4570 VARIANT left, right, result, cy, dec;
4571 VARTYPE i;
4572 BSTR lbstr, rbstr;
4573 HRESULT hres;
4574 double r;
4576 CHECKPTR(VarMul);
4578 lbstr = SysAllocString(sz12);
4579 rbstr = SysAllocString(sz12);
4581 /* Test all possible flag/vt combinations & the resulting vt type */
4582 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
4584 VARTYPE leftvt, rightvt, resvt;
4586 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
4589 SKIPTESTS(leftvt);
4591 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
4593 BOOL bFail = FALSE;
4595 SKIPTESTS(rightvt);
4597 if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
4598 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
4599 continue;
4601 memset(&left, 0, sizeof(left));
4602 memset(&right, 0, sizeof(right));
4603 V_VT(&left) = leftvt | ExtraFlags[i];
4604 if (leftvt == VT_BSTR)
4605 V_BSTR(&left) = lbstr;
4606 V_VT(&right) = rightvt | ExtraFlags[i];
4607 if (rightvt == VT_BSTR)
4608 V_BSTR(&right) = rbstr;
4609 V_VT(&result) = VT_EMPTY;
4610 resvt = VT_UNKNOWN;
4612 /* Don't ask me why but native VarMul cannot handle:
4613 VT_I1, VT_UI2, VT_UI4, VT_INT, VT_UINT and VT_UI8.
4614 Tested with DCOM98, Win2k, WinXP */
4615 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
4616 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
4617 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
4618 leftvt == VT_CLSID || rightvt == VT_CLSID ||
4619 leftvt == VT_RECORD || rightvt == VT_RECORD ||
4620 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
4621 leftvt == VT_ERROR || rightvt == VT_ERROR ||
4622 leftvt == VT_I1 || rightvt == VT_I1 ||
4623 leftvt == VT_UI2 || rightvt == VT_UI2 ||
4624 leftvt == VT_UI4 || rightvt == VT_UI4 ||
4625 leftvt == VT_UI8 || rightvt == VT_UI8 ||
4626 leftvt == VT_INT || rightvt == VT_INT ||
4627 leftvt == VT_UINT || rightvt == VT_UINT) {
4628 bFail = TRUE;
4631 if (leftvt == VT_NULL || rightvt == VT_NULL)
4632 resvt = VT_NULL;
4633 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
4634 resvt = VT_DECIMAL;
4635 else if (leftvt == VT_R8 || rightvt == VT_R8 ||
4636 leftvt == VT_BSTR || rightvt == VT_BSTR ||
4637 leftvt == VT_DATE || rightvt == VT_DATE)
4638 resvt = VT_R8;
4639 else if (leftvt == VT_R4 || rightvt == VT_R4) {
4640 if (leftvt == VT_I4 || rightvt == VT_I4 ||
4641 leftvt == VT_I8 || rightvt == VT_I8 ||
4642 leftvt == VT_CY || rightvt == VT_CY)
4643 resvt = VT_R8;
4644 else
4645 resvt = VT_R4;
4646 } else if (leftvt == VT_CY || rightvt == VT_CY)
4647 resvt = VT_CY;
4648 else if (leftvt == VT_I8 || rightvt == VT_I8)
4649 resvt = VT_I8;
4650 else if (leftvt == VT_I4 || rightvt == VT_I4)
4651 resvt = VT_I4;
4652 else if (leftvt == VT_I2 || rightvt == VT_I2 ||
4653 leftvt == VT_BOOL || rightvt == VT_BOOL ||
4654 (leftvt == VT_EMPTY && rightvt == VT_EMPTY))
4655 resvt = VT_I2;
4656 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
4657 resvt = VT_UI1;
4659 hres = pVarMul(&left, &right, &result);
4660 if (bFail) {
4661 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
4662 "VarMul: %d|0x%X, %d|0x%X: Expected failure, got 0x%lX vt %d\n",
4663 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
4664 V_VT(&result));
4665 } else {
4666 ok(hres == S_OK && V_VT(&result) == resvt,
4667 "VarMul: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%lX vt %d\n",
4668 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
4669 V_VT(&result));
4675 /* Test returned values */
4676 VARMUL(I4,4,I4,2,I4,8);
4677 VARMUL(I2,4,I2,2,I2,8);
4678 VARMUL(I2,-13,I4,5,I4,-65);
4679 VARMUL(I4,-13,I4,5,I4,-65);
4680 VARMUL(I2,7,R4,0.5,R4,3.5);
4681 VARMUL(R4,0.5,I4,5,R8,2.5);
4682 VARMUL(R8,7.1,BOOL,0,R8,0);
4683 VARMUL(BSTR,lbstr,I2,4,R8,48);
4684 VARMUL(BSTR,lbstr,BOOL,1,R8,12);
4685 VARMUL(BSTR,lbstr,R4,0.1,R8,1.2);
4686 VARMUL(BSTR,lbstr,BSTR,rbstr,R8,144);
4687 VARMUL(R4,0.2,BSTR,rbstr,R8,2.4);
4688 VARMUL(DATE,2.25,I4,7,R8,15.75);
4690 VARMUL(UI1, UI1_MAX, UI1, UI1_MAX, I4, UI1_MAX * UI1_MAX);
4691 VARMUL(I2, I2_MAX, I2, I2_MAX, I4, I2_MAX * I2_MAX);
4692 VARMUL(I2, I2_MAX, I2, I2_MIN, I4, I2_MAX * I2_MIN);
4693 VARMUL(I2, I2_MIN, I2, I2_MIN, I4, I2_MIN * I2_MIN);
4694 VARMUL(I4, I4_MAX, I4, I4_MAX, R8, (double)I4_MAX * I4_MAX);
4695 VARMUL(I4, I4_MAX, I4, I4_MIN, R8, (double)I4_MAX * I4_MIN);
4696 VARMUL(I4, I4_MIN, I4, I4_MIN, R8, (double)I4_MIN * I4_MIN);
4697 VARMUL(R4, R4_MAX, R4, R4_MAX, R8, (double)R4_MAX * R4_MAX);
4698 VARMUL(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX * R4_MIN);
4699 VARMUL(R4, R4_MIN, R4, R4_MIN, R4, R4_MIN * R4_MIN);
4700 VARMUL(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX * R8_MIN);
4701 VARMUL(R8, R8_MIN, R8, R8_MIN, R8, R8_MIN * R8_MIN);
4703 /* Manuly test some VT_CY and VT_DECIMAL variants */
4704 V_VT(&cy) = VT_CY;
4705 hres = VarCyFromI4(4711, &V_CY(&cy));
4706 ok(hres == S_OK, "VarCyFromI4 failed!\n");
4707 V_VT(&dec) = VT_DECIMAL;
4708 hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec));
4709 ok(hres == S_OK, "VarDecFromR4 failed!\n");
4710 memset(&left, 0, sizeof(left));
4711 memset(&right, 0, sizeof(right));
4712 V_VT(&left) = VT_I4;
4713 V_I4(&left) = -11;
4714 V_VT(&right) = VT_UI1;
4715 V_UI1(&right) = 9;
4717 hres = VarMul(&cy, &right, &result);
4718 ok(hres == S_OK && V_VT(&result) == VT_CY, "VarMul: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result)));
4719 hres = VarR8FromCy(V_CY(&result), &r);
4720 ok(hres == S_OK && EQ_DOUBLE(r, 42399), "VarMul: CY value %f, expected %f\n", r, (double)42399);
4722 hres = VarMul(&left, &dec, &result);
4723 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL, "VarMul: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
4724 hres = VarR8FromDec(&V_DECIMAL(&result), &r);
4725 ok(hres == S_OK && EQ_DOUBLE(r, 46.2), "VarMul: DECIMAL value %f, expected %f\n", r, (double)46.2);
4728 static HRESULT (WINAPI *pVarAdd)(LPVARIANT,LPVARIANT,LPVARIANT);
4730 static const char *szVarAddI4 = "VarAdd(%d,%d): expected 0x0,%d,%d, got 0x%lX,%d,%d\n";
4731 static const char *szVarAddR8 = "VarAdd(%d,%d): expected 0x0,%d,%f, got 0x%lX,%d,%f\n";
4733 #define VARADD(vt1,val1,vt2,val2,rvt,rval) \
4734 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
4735 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
4736 memset(&result,0,sizeof(result)); hres = pVarAdd(&left,&right,&result); \
4737 if (VT_##rvt == VT_R4 || VT_##rvt == VT_R8 || VT_##rvt == VT_DATE) { \
4738 ok(hres == S_OK && V_VT(&result) == VT_##rvt && \
4739 EQ_FLOAT(V_##rvt(&result), rval), \
4740 szVarAddR8, VT_##vt1, VT_##vt2, \
4741 VT_##rvt, (double)(rval), hres, V_VT(&result), (double)V_##rvt(&result)); \
4742 } else { \
4743 ok(hres == S_OK && V_VT(&result) == VT_##rvt && V_##rvt(&result) == (rval), \
4744 szVarAddI4, VT_##vt1, VT_##vt2, \
4745 VT_##rvt, (int)(rval), hres, V_VT(&result), (int)V_##rvt(&result)); }
4747 static void test_VarAdd(void)
4749 static const WCHAR sz12[] = {'1','2','\0'};
4750 VARIANT left, right, result, cy, dec;
4751 VARTYPE i;
4752 BSTR lbstr, rbstr;
4753 HRESULT hres;
4754 double r;
4756 CHECKPTR(VarAdd);
4758 lbstr = SysAllocString(sz12);
4759 rbstr = SysAllocString(sz12);
4761 /* Test all possible flag/vt combinations & the resulting vt type */
4762 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
4764 VARTYPE leftvt, rightvt, resvt;
4766 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
4769 SKIPTESTS(leftvt);
4771 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
4773 BOOL bFail = FALSE;
4775 SKIPTESTS(rightvt);
4777 if (leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
4778 continue;
4780 memset(&left, 0, sizeof(left));
4781 memset(&right, 0, sizeof(right));
4782 V_VT(&left) = leftvt | ExtraFlags[i];
4783 if (leftvt == VT_BSTR)
4784 V_BSTR(&left) = lbstr;
4785 V_VT(&right) = rightvt | ExtraFlags[i];
4786 if (rightvt == VT_BSTR)
4787 V_BSTR(&right) = rbstr;
4788 V_VT(&result) = VT_EMPTY;
4789 resvt = VT_ERROR;
4791 /* Don't ask me why but native VarAdd cannot handle:
4792 VT_I1, VT_UI2, VT_UI4, VT_INT, VT_UINT and VT_UI8.
4793 Tested with DCOM98, Win2k, WinXP */
4794 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
4795 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
4796 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
4797 leftvt == VT_CLSID || rightvt == VT_CLSID ||
4798 leftvt == VT_RECORD || rightvt == VT_RECORD ||
4799 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
4800 leftvt == VT_ERROR || rightvt == VT_ERROR ||
4801 leftvt == VT_I1 || rightvt == VT_I1 ||
4802 leftvt == VT_UI2 || rightvt == VT_UI2 ||
4803 leftvt == VT_UI4 || rightvt == VT_UI4 ||
4804 leftvt == VT_UI8 || rightvt == VT_UI8 ||
4805 leftvt == VT_INT || rightvt == VT_INT ||
4806 leftvt == VT_UINT || rightvt == VT_UINT) {
4807 bFail = TRUE;
4810 if (leftvt == VT_NULL || rightvt == VT_NULL)
4811 resvt = VT_NULL;
4812 else if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH)
4813 bFail = TRUE;
4814 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
4815 resvt = VT_DECIMAL;
4816 else if (leftvt == VT_DATE || rightvt == VT_DATE)
4817 resvt = VT_DATE;
4818 else if (leftvt == VT_CY || rightvt == VT_CY)
4819 resvt = VT_CY;
4820 else if (leftvt == VT_R8 || rightvt == VT_R8)
4821 resvt = VT_R8;
4822 else if (leftvt == VT_BSTR || rightvt == VT_BSTR) {
4823 if ((leftvt == VT_BSTR && rightvt == VT_BSTR) ||
4824 leftvt == VT_EMPTY || rightvt == VT_EMPTY)
4825 resvt = VT_BSTR;
4826 else
4827 resvt = VT_R8;
4828 } else if (leftvt == VT_R4 || rightvt == VT_R4) {
4829 if (leftvt == VT_I4 || rightvt == VT_I4 ||
4830 leftvt == VT_I8 || rightvt == VT_I8)
4831 resvt = VT_R8;
4832 else
4833 resvt = VT_R4;
4835 else if (leftvt == VT_I8 || rightvt == VT_I8)
4836 resvt = VT_I8;
4837 else if (leftvt == VT_I4 || rightvt == VT_I4)
4838 resvt = VT_I4;
4839 else if (leftvt == VT_I2 || rightvt == VT_I2 ||
4840 leftvt == VT_BOOL || rightvt == VT_BOOL ||
4841 (leftvt == VT_EMPTY && rightvt == VT_EMPTY))
4842 resvt = VT_I2;
4843 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
4844 resvt = VT_UI1;
4846 hres = pVarAdd(&left, &right, &result);
4847 if (bFail) {
4848 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
4849 "VarAdd: %d|0x%X, %d|0x%X: Expected failure, got 0x%lX vt %d\n",
4850 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
4851 V_VT(&result));
4852 } else {
4853 ok(hres == S_OK && V_VT(&result) == resvt,
4854 "VarAdd: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%lX vt %d\n",
4855 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
4856 V_VT(&result));
4862 /* Test returned values */
4863 VARADD(I4,4,I4,2,I4,6);
4864 VARADD(I2,4,I2,2,I2,6);
4865 VARADD(I2,-13,I4,5,I4,-8);
4866 VARADD(I4,-13,I4,5,I4,-8);
4867 VARADD(I2,7,R4,0.5,R4,7.5);
4868 VARADD(R4,0.5,I4,5,R8,5.5);
4869 VARADD(R8,7.1,BOOL,0,R8,7.1);
4870 VARADD(BSTR,lbstr,I2,4,R8,16);
4871 VARADD(BSTR,lbstr,BOOL,1,R8,13);
4872 VARADD(BSTR,lbstr,R4,0.1,R8,12.1);
4873 VARADD(R4,0.2,BSTR,rbstr,R8,12.2);
4874 VARADD(DATE,2.25,I4,7,DATE,9.25);
4875 VARADD(DATE,1.25,R4,-1.7,DATE,-0.45);
4877 VARADD(UI1, UI1_MAX, UI1, UI1_MAX, I2, UI1_MAX + UI1_MAX);
4878 VARADD(I2, I2_MAX, I2, I2_MAX, I4, I2_MAX + I2_MAX);
4879 VARADD(I2, I2_MAX, I2, I2_MIN, I2, I2_MAX + I2_MIN);
4880 VARADD(I2, I2_MIN, I2, I2_MIN, I4, I2_MIN + I2_MIN);
4881 VARADD(I4, I4_MAX, I4, I4_MIN, I4, I4_MAX + I4_MIN);
4882 VARADD(I4, I4_MAX, I4, I4_MAX, R8, (double)I4_MAX + I4_MAX);
4883 VARADD(I4, I4_MIN, I4, I4_MIN, R8, (double)I4_MIN + I4_MIN);
4884 VARADD(R4, R4_MAX, R4, R4_MAX, R8, (double)R4_MAX + R4_MAX);
4885 VARADD(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX + R4_MIN);
4886 VARADD(R4, R4_MIN, R4, R4_MIN, R4, R4_MIN + R4_MIN);
4887 VARADD(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX + R8_MIN);
4888 VARADD(R8, R8_MIN, R8, R8_MIN, R8, R8_MIN + R8_MIN);
4890 /* Manualy test BSTR + BSTR */
4891 V_VT(&left) = VT_BSTR;
4892 V_BSTR(&left) = lbstr;
4893 V_VT(&right) = VT_BSTR;
4894 V_BSTR(&right) = rbstr;
4895 hres = VarAdd(&left, &right, &result);
4896 ok(hres == S_OK && V_VT(&result) == VT_BSTR, "VarAdd: expected coerced type VT_BSTR, got %s!\n", vtstr(V_VT(&result)));
4897 hres = VarR8FromStr(V_BSTR(&result), 0, 0, &r);
4898 ok(hres == S_OK && EQ_DOUBLE(r, 1212), "VarAdd: BSTR value %f, expected %f\n", r, (double)1212);
4900 /* Manuly test some VT_CY and VT_DECIMAL variants */
4901 V_VT(&cy) = VT_CY;
4902 hres = VarCyFromI4(4711, &V_CY(&cy));
4903 ok(hres == S_OK, "VarCyFromI4 failed!\n");
4904 V_VT(&dec) = VT_DECIMAL;
4905 hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec));
4906 ok(hres == S_OK, "VarDecFromR4 failed!\n");
4907 memset(&left, 0, sizeof(left));
4908 memset(&right, 0, sizeof(right));
4909 V_VT(&left) = VT_I4;
4910 V_I4(&left) = -11;
4911 V_VT(&right) = VT_UI1;
4912 V_UI1(&right) = 9;
4914 hres = VarAdd(&cy, &right, &result);
4915 ok(hres == S_OK && V_VT(&result) == VT_CY, "VarAdd: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result)));
4916 hres = VarR8FromCy(V_CY(&result), &r);
4917 ok(hres == S_OK && EQ_DOUBLE(r, 4720), "VarAdd: CY value %f, expected %f\n", r, (double)4720);
4919 hres = VarAdd(&left, &dec, &result);
4920 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL, "VarAdd: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
4921 hres = VarR8FromDec(&V_DECIMAL(&result), &r);
4922 ok(hres == S_OK && EQ_DOUBLE(r, -15.2), "VarAdd: DECIMAL value %f, expected %f\n", r, (double)-15.2);
4925 START_TEST(vartest)
4927 hOleaut32 = LoadLibraryA("oleaut32.dll");
4929 test_VariantInit();
4930 test_VariantClear();
4931 test_VariantCopy();
4932 test_VariantCopyInd();
4933 test_VarParseNumFromStr();
4934 test_VarNumFromParseNum();
4935 test_VarUdateFromDate();
4936 test_VarDateFromUdate();
4937 test_SystemTimeToVariantTime();
4938 test_VariantTimeToSystemTime();
4939 test_DosDateTimeToVariantTime();
4940 test_VariantTimeToDosDateTime();
4941 test_VarFormatNumber();
4942 test_VarFormat();
4943 test_VarAbs();
4944 test_VarNot();
4945 test_VarSub();
4946 test_VarMod();
4947 test_VarFix();
4948 test_VarInt();
4949 test_VarNeg();
4950 test_VarRound();
4951 test_VarXor();
4952 test_VarOr();
4953 test_VarEqv();
4954 test_VarMul();
4955 test_VarAdd();