Tests for VarMul().
[wine/multimedia.git] / dlls / oleaut32 / tests / vartest.c
blob58409d59104c5d9d07542c6eb7a4ff94974e6be8
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 #ifdef NONAMELESSUNION
43 # define U(x) (x).u
44 # define U1(x) (x).u1
45 #else
46 # define U(x) (x)
47 # define U1(x) (x)
48 #endif
49 #ifdef NONAMELESSSTRUCT
50 # define S(x) (x).s
51 # define S1(x) (x).s1
52 #else
53 # define S(x) (x)
54 # define S1(x) (x)
55 #endif
57 static HRESULT (WINAPI *pVarUdateFromDate)(DATE,ULONG,UDATE*);
58 static HRESULT (WINAPI *pVarDateFromUdate)(UDATE*,ULONG,DATE*);
59 static INT (WINAPI *pSystemTimeToVariantTime)(LPSYSTEMTIME,double*);
60 static INT (WINAPI *pVariantTimeToSystemTime)(double,LPSYSTEMTIME);
61 static INT (WINAPI *pDosDateTimeToVariantTime)(USHORT,USHORT,double*);
62 static INT (WINAPI *pVariantTimeToDosDateTime)(double,USHORT*,USHORT *);
63 static HRESULT (WINAPI *pVarFormatNumber)(LPVARIANT,int,int,int,int,ULONG,BSTR*);
64 static HRESULT (WINAPI *pVarFormat)(LPVARIANT,LPOLESTR,int,int,ULONG,BSTR*);
66 /* Get a conversion function ptr, return if function not available */
67 #define CHECKPTR(func) p##func = (void*)GetProcAddress(hOleaut32, #func); \
68 if (!p##func) { trace("function " # func " not available, not testing it\n"); return; }
70 /* Is a given function exported from oleaut32? */
71 #define HAVE_FUNC(func) ((void*)GetProcAddress(hOleaut32, #func) != NULL)
73 /* Have IRecordInfo data type? */
74 #define HAVE_OLEAUT32_RECORD HAVE_FUNC(SafeArraySetRecordInfo)
75 /* Have CY data type? */
76 #define HAVE_OLEAUT32_CY HAVE_FUNC(VarCyAdd)
77 /* Have I8/UI8 data type? */
78 #define HAVE_OLEAUT32_I8 HAVE_FUNC(VarI8FromI1)
79 /* Is this an ancient version with support for only I2/I4/R4/R8/DATE? */
80 #define IS_ANCIENT (!HAVE_FUNC(VarI1FromI2))
82 /* When comparing floating point values we cannot expect an exact match
83 * because the rounding errors depend on the exact algorithm.
85 #define EQ_DOUBLE(a,b) (fabs((a)-(b))<1e-14)
86 #define EQ_FLOAT(a,b) (fabs((a)-(b))<1e-7)
88 #define SKIPTESTS(a) if((a > VT_CLSID+10) && (a < VT_BSTR_BLOB-10)) continue;
90 /* Allow our test macros to work for VT_NULL and VT_EMPTY too */
91 #define V_EMPTY(v) V_I4(v)
92 #define V_NULL(v) V_I4(v)
94 /* Size constraints for overflow tests */
95 #define I1_MAX 0x7f
96 #define I1_MIN ((-I1_MAX)-1)
97 #define UI1_MAX 0xff
98 #define UI1_MIN 0
99 #define I2_MAX 0x7fff
100 #define I2_MIN ((-I2_MAX)-1)
101 #define UI2_MAX 0xffff
102 #define UI2_MIN 0
103 #define I4_MAX 0x7fffffff
104 #define I4_MIN ((-I4_MAX)-1)
105 #define UI4_MAX 0xffffffff
106 #define UI4_MIN 0
107 #define I8_MAX (((LONGLONG)I4_MAX << 32) | UI4_MAX)
108 #define I8_MIN ((-I8_MAX)-1)
109 #define UI8_MAX (((ULONGLONG)UI4_MAX << 32) | UI4_MAX)
110 #define UI8_MIN 0
111 #define DATE_MAX 2958465
112 #define DATE_MIN -657434
113 #define R4_MAX FLT_MAX
114 #define R4_MIN FLT_MIN
115 #define R8_MAX DBL_MAX
116 #define R8_MIN DBL_MIN
118 static inline int strcmpW( const WCHAR *str1, const WCHAR *str2 )
120 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
121 return *str1 - *str2;
124 /* return the string text of a given variant type */
125 static const char *vtstr(int x)
127 switch(x) {
128 case 0:
129 return "VT_EMPTY";
130 case 1:
131 return "VT_NULL";
132 case 2:
133 return "VT_I2";
134 case 3:
135 return "VT_I4";
136 case 4:
137 return "VT_R4";
138 case 5:
139 return "VT_R8";
140 case 6:
141 return "VT_CY";
142 case 7:
143 return "VT_DATE";
144 case 8:
145 return "VT_BSTR";
146 case 9:
147 return "VT_DISPATCH";
148 case 10:
149 return "VT_ERROR";
150 case 11:
151 return "VT_BOOL";
152 case 12:
153 return "VT_VARIANT";
154 case 13:
155 return "VT_UNKNOWN";
156 case 14:
157 return "VT_DECIMAL";
158 case 15:
159 return "notdefined";
160 case 16:
161 return "VT_I1";
162 case 17:
163 return "VT_UI1";
164 case 18:
165 return "VT_UI2";
166 case 19:
167 return "VT_UI4";
168 case 20:
169 return "VT_I8";
170 case 21:
171 return "VT_UI8";
172 case 22:
173 return "VT_INT";
174 case 23:
175 return "VT_UINT";
176 case 24:
177 return "VT_VOID";
178 case 25:
179 return "VT_HRESULT";
180 case 26:
181 return "VT_PTR";
182 case 27:
183 return "VT_SAFEARRAY";
184 case 28:
185 return "VT_CARRAY";
186 case 29:
187 return "VT_USERDEFINED";
188 case 30:
189 return "VT_LPSTR";
190 case 31:
191 return "VT_LPWSTR";
192 case 36:
193 return "VT_RECORD";
194 case 64:
195 return "VT_FILETIME";
196 case 65:
197 return "VT_BLOB";
198 case 66:
199 return "VT_STREAM";
200 case 67:
201 return "VT_STORAGE";
202 case 68:
203 return "VT_STREAMED_OBJECT";
204 case 69:
205 return "VT_STORED_OBJECT";
206 case 70:
207 return "VT_BLOB_OBJECT";
208 case 71:
209 return "VT_CF";
210 case 72:
211 return "VT_CLSID";
212 case 0xFFF:
213 return "VT_BSTR_BLOB/VT_ILLEGALMASKED/VT_TYPEMASK";
214 case 0x1000:
215 return "VT_VECTOR";
216 case 0x2000:
217 return "VT_ARRAY";
218 case 0x4000:
219 return "VT_BYREF";
220 case 0x8000:
221 return "VT_BYREF";
222 case 0xFFFF:
223 return "VT_ILLEGAL";
225 default:
226 return "defineme";
230 static void test_VariantInit(void)
232 VARIANTARG v1, v2;
234 /* Test that VariantInit() only sets the type */
235 memset(&v1, -1, sizeof(v1));
236 v2 = v1;
237 V_VT(&v2) = VT_EMPTY;
238 VariantInit(&v1);
239 ok(!memcmp(&v1, &v2, sizeof(v1)), "VariantInit() set extra fields\n");
242 /* All possible combinations of extra V_VT() flags */
243 static const VARTYPE ExtraFlags[16] =
246 VT_VECTOR,
247 VT_ARRAY,
248 VT_BYREF,
249 VT_RESERVED,
250 VT_VECTOR|VT_ARRAY,
251 VT_VECTOR|VT_BYREF,
252 VT_VECTOR|VT_RESERVED,
253 VT_VECTOR|VT_ARRAY|VT_BYREF,
254 VT_VECTOR|VT_ARRAY|VT_RESERVED,
255 VT_VECTOR|VT_BYREF|VT_RESERVED,
256 VT_VECTOR|VT_ARRAY|VT_BYREF|VT_RESERVED,
257 VT_ARRAY|VT_BYREF,
258 VT_ARRAY|VT_RESERVED,
259 VT_ARRAY|VT_BYREF|VT_RESERVED,
260 VT_BYREF|VT_RESERVED,
263 /* Determine if a vt is valid for VariantClear() */
264 static int IsValidVariantClearVT(VARTYPE vt, VARTYPE extraFlags)
266 int ret = 0;
268 /* Only the following flags/types are valid */
269 if ((vt <= VT_LPWSTR || vt == VT_RECORD || vt == VT_CLSID) &&
270 vt != (VARTYPE)15 &&
271 (vt < (VARTYPE)24 || vt > (VARTYPE)31) &&
272 (!(extraFlags & (VT_BYREF|VT_ARRAY)) || vt > VT_NULL) &&
273 (extraFlags == 0 || extraFlags == VT_BYREF || extraFlags == VT_ARRAY ||
274 extraFlags == (VT_ARRAY|VT_BYREF)))
275 ret = 1; /* ok */
277 if ((vt == VT_RECORD && !HAVE_OLEAUT32_RECORD) ||
278 ((vt == VT_I8 || vt == VT_UI8) && !HAVE_OLEAUT32_I8))
279 ret = 0; /* Old versions of oleaut32 */
280 return ret;
283 static void test_VariantClear(void)
285 HRESULT hres;
286 VARIANTARG v;
287 size_t i;
289 #if 0
290 /* Crashes: Native does not test input for NULL, so neither does Wine */
291 hres = VariantClear(NULL);
292 #endif
294 /* Only the type field is set, to VT_EMPTY */
295 V_VT(&v) = VT_UI4;
296 V_UI4(&v) = ~0u;
297 hres = VariantClear(&v);
298 ok((hres == S_OK && V_VT(&v) == VT_EMPTY) ||
299 (IS_ANCIENT && hres == DISP_E_BADVARTYPE && V_VT(&v) == VT_UI4),
300 "VariantClear: Type set to %d, res %08lx\n", V_VT(&v), hres);
301 ok(V_UI4(&v) == ~0u, "VariantClear: Overwrote value\n");
303 /* Test all possible V_VT values.
304 * Also demonstrates that null pointers in 'v' are not dereferenced.
305 * Individual variant tests should test VariantClear() with non-NULL values.
307 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
309 VARTYPE vt;
311 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
313 HRESULT hExpected = DISP_E_BADVARTYPE;
315 SKIPTESTS(vt);
317 memset(&v, 0, sizeof(v));
318 V_VT(&v) = vt | ExtraFlags[i];
320 hres = VariantClear(&v);
322 if (IsValidVariantClearVT(vt, ExtraFlags[i]))
323 hExpected = S_OK;
325 ok(hres == hExpected, "VariantClear: expected 0x%lX, got 0x%lX for vt %d | 0x%X\n",
326 hExpected, hres, vt, ExtraFlags[i]);
331 static void test_VariantCopy(void)
333 VARIANTARG vSrc, vDst;
334 VARTYPE vt;
335 size_t i;
336 HRESULT hres, hExpected;
338 /* Establish that the failure/other cases are dealt with. Individual tests
339 * for each type should verify that data is copied correctly, references
340 * are updated, etc.
343 /* vSrc == vDst */
344 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
346 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
348 SKIPTESTS(vt);
350 memset(&vSrc, 0, sizeof(vSrc));
351 V_VT(&vSrc) = vt | ExtraFlags[i];
353 hExpected = DISP_E_BADVARTYPE;
354 /* src is allowed to be a VT_CLSID */
355 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
356 hExpected = S_OK;
358 hres = VariantCopy(&vSrc, &vSrc);
360 ok(hres == hExpected,
361 "Copy(src==dst): expected 0x%lX, got 0x%lX for src==dest vt %d|0x%X\n",
362 hExpected, hres, vt, ExtraFlags[i]);
366 /* Test that if VariantClear() fails on dest, the function fails. This also
367 * shows that dest is in fact cleared and not just overwritten
369 memset(&vSrc, 0, sizeof(vSrc));
370 V_VT(&vSrc) = VT_UI1;
372 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
374 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
376 SKIPTESTS(vt);
378 hExpected = DISP_E_BADVARTYPE;
380 memset(&vDst, 0, sizeof(vDst));
381 V_VT(&vDst) = vt | ExtraFlags[i];
383 if (IsValidVariantClearVT(vt, ExtraFlags[i]))
384 hExpected = S_OK;
386 hres = VariantCopy(&vDst, &vSrc);
388 ok(hres == hExpected,
389 "Copy(bad dst): expected 0x%lX, got 0x%lX for dest vt %d|0x%X\n",
390 hExpected, hres, vt, ExtraFlags[i]);
391 if (hres == S_OK)
392 ok(V_VT(&vDst) == VT_UI1,
393 "Copy(bad dst): expected vt = VT_UI1, got %d\n", V_VT(&vDst));
397 /* Test that VariantClear() checks vSrc for validity before copying */
398 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
400 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
402 SKIPTESTS(vt);
404 hExpected = DISP_E_BADVARTYPE;
406 memset(&vDst, 0, sizeof(vDst));
407 V_VT(&vDst) = VT_EMPTY;
409 memset(&vSrc, 0, sizeof(vSrc));
410 V_VT(&vSrc) = vt | ExtraFlags[i];
412 /* src is allowed to be a VT_CLSID */
413 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
414 hExpected = S_OK;
416 hres = VariantCopy(&vDst, &vSrc);
418 ok(hres == hExpected,
419 "Copy(bad src): expected 0x%lX, got 0x%lX for src vt %d|0x%X\n",
420 hExpected, hres, vt, ExtraFlags[i]);
421 if (hres == S_OK)
422 ok(V_VT(&vDst) == (vt|ExtraFlags[i]),
423 "Copy(bad src): expected vt = %d, got %d\n",
424 vt | ExtraFlags[i], V_VT(&vDst));
429 /* Determine if a vt is valid for VariantCopyInd() */
430 static int IsValidVariantCopyIndVT(VARTYPE vt, VARTYPE extraFlags)
432 int ret = 0;
434 if ((extraFlags & VT_ARRAY) ||
435 (vt > VT_NULL && vt != (VARTYPE)15 && vt < VT_VOID &&
436 !(extraFlags & (VT_VECTOR|VT_RESERVED))))
438 ret = 1; /* ok */
440 return ret;
443 static void test_VariantCopyInd(void)
445 VARIANTARG vSrc, vDst, vRef, vRef2;
446 VARTYPE vt;
447 size_t i;
448 BYTE buffer[64];
449 HRESULT hres, hExpected;
451 memset(buffer, 0, sizeof(buffer));
453 /* vSrc == vDst */
454 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
456 if (ExtraFlags[i] & VT_ARRAY)
457 continue; /* Native crashes on NULL safearray */
459 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
461 SKIPTESTS(vt);
463 memset(&vSrc, 0, sizeof(vSrc));
464 V_VT(&vSrc) = vt | ExtraFlags[i];
466 hExpected = DISP_E_BADVARTYPE;
467 if (!(ExtraFlags[i] & VT_BYREF))
469 /* if src is not by-reference, acts as VariantCopy() */
470 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
471 hExpected = S_OK;
473 else
475 if (vt == VT_SAFEARRAY || vt == VT_BSTR || vt == VT_UNKNOWN ||
476 vt == VT_DISPATCH || vt == VT_RECORD)
477 continue; /* Need valid ptrs for deep copies */
479 V_BYREF(&vSrc) = &buffer;
480 hExpected = E_INVALIDARG;
482 if ((vt == VT_I8 || vt == VT_UI8) &&
483 ExtraFlags[i] == VT_BYREF)
485 if (HAVE_OLEAUT32_I8)
486 hExpected = S_OK; /* Only valid if I8 is a known type */
488 else if (IsValidVariantCopyIndVT(vt, ExtraFlags[i]))
489 hExpected = S_OK;
492 hres = VariantCopyInd(&vSrc, &vSrc);
494 ok(hres == hExpected,
495 "CopyInd(src==dst): expected 0x%lX, got 0x%lX for src==dst vt %d|0x%X\n",
496 hExpected, hres, vt, ExtraFlags[i]);
500 /* Bad dest */
501 memset(&vSrc, 0, sizeof(vSrc));
502 V_VT(&vSrc) = VT_UI1|VT_BYREF;
503 V_BYREF(&vSrc) = &buffer;
505 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
507 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
509 SKIPTESTS(vt);
511 memset(&vDst, 0, sizeof(vDst));
512 V_VT(&vDst) = vt | ExtraFlags[i];
514 hExpected = DISP_E_BADVARTYPE;
516 if (IsValidVariantClearVT(vt, ExtraFlags[i]))
517 hExpected = S_OK;
519 hres = VariantCopyInd(&vDst, &vSrc);
521 ok(hres == hExpected,
522 "CopyInd(bad dst): expected 0x%lX, got 0x%lX for dst vt %d|0x%X\n",
523 hExpected, hres, vt, ExtraFlags[i]);
524 if (hres == S_OK)
525 ok(V_VT(&vDst) == VT_UI1,
526 "CopyInd(bad dst): expected vt = VT_UI1, got %d\n", V_VT(&vDst));
530 /* bad src */
531 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]) && !IS_ANCIENT; i++)
533 if (ExtraFlags[i] & VT_ARRAY)
534 continue; /* Native crashes on NULL safearray */
536 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
538 SKIPTESTS(vt);
540 memset(&vDst, 0, sizeof(vDst));
541 V_VT(&vDst) = VT_EMPTY;
543 memset(&vSrc, 0, sizeof(vSrc));
544 V_VT(&vSrc) = vt | ExtraFlags[i];
546 hExpected = DISP_E_BADVARTYPE;
547 if (!(ExtraFlags[i] & VT_BYREF))
549 /* if src is not by-reference, acts as VariantCopy() */
550 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
551 hExpected = S_OK;
553 else
555 if (vt == VT_SAFEARRAY || vt == VT_BSTR || vt == VT_UNKNOWN ||
556 vt == VT_DISPATCH || vt == VT_RECORD)
557 continue; /* Need valid ptrs for deep copies, see vartype.c */
559 V_BYREF(&vSrc) = &buffer;
561 hExpected = E_INVALIDARG;
563 if ((vt == VT_I8 || vt == VT_UI8) &&
564 ExtraFlags[i] == VT_BYREF)
566 if (HAVE_OLEAUT32_I8)
567 hExpected = S_OK; /* Only valid if I8 is a known type */
569 else if (IsValidVariantCopyIndVT(vt, ExtraFlags[i]))
570 hExpected = S_OK;
573 hres = VariantCopyInd(&vDst, &vSrc);
575 ok(hres == hExpected,
576 "CopyInd(bad src): expected 0x%lX, got 0x%lX for src vt %d|0x%X\n",
577 hExpected, hres, vt, ExtraFlags[i]);
578 if (hres == S_OK)
580 if (vt == VT_VARIANT && ExtraFlags[i] == VT_BYREF)
582 /* Type of vDst should be the type of the referenced variant.
583 * Since we set the buffer to all zeros, its type should be
584 * VT_EMPTY.
586 ok(V_VT(&vDst) == VT_EMPTY,
587 "CopyInd(bad src): expected dst vt = VT_EMPTY, got %d|0x%X\n",
588 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK);
590 else
592 ok(V_VT(&vDst) == (vt|(ExtraFlags[i] & ~VT_BYREF)),
593 "CopyInd(bad src): expected dst vt = %d|0x%X, got %d|0x%X\n",
594 vt, ExtraFlags[i] & ~VT_BYREF,
595 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK);
601 /* By-reference variants are dereferenced */
602 V_VT(&vRef) = VT_UI1;
603 V_UI1(&vRef) = 0x77;
604 V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
605 V_VARIANTREF(&vSrc) = &vRef;
606 VariantInit(&vDst);
608 hres = VariantCopyInd(&vDst, &vSrc);
609 ok(V_VT(&vDst) == VT_UI1 && V_UI1(&vDst) == 0x77,
610 "CopyInd(deref): expected dst vt = VT_UI1, val 0x77, got %d|0x%X, 0x%2X\n",
611 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK, V_UI1(&vDst));
613 /* By-reference variant to a by-reference type succeeds */
614 V_VT(&vRef) = VT_UI1|VT_BYREF;
615 V_UI1REF(&vRef) = buffer; buffer[0] = 0x88;
616 V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
617 V_VARIANTREF(&vSrc) = &vRef;
618 VariantInit(&vDst);
620 hres = VariantCopyInd(&vDst, &vSrc);
621 ok(V_VT(&vDst) == VT_UI1 && V_UI1(&vDst) == 0x88,
622 "CopyInd(deref): expected dst vt = VT_UI1, val 0x77, got %d|0x%X, 0x%2X\n",
623 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK, V_UI1(&vDst));
625 /* But a by-reference variant to a by-reference variant fails */
626 V_VT(&vRef2) = VT_UI1;
627 V_UI1(&vRef2) = 0x77;
628 V_VT(&vRef) = VT_VARIANT|VT_BYREF;
629 V_VARIANTREF(&vRef) = &vRef2;
630 V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
631 V_VARIANTREF(&vSrc) = &vRef;
632 VariantInit(&vDst);
634 hres = VariantCopyInd(&vDst, &vSrc);
635 ok(hres == E_INVALIDARG,
636 "CopyInd(ref->ref): expected E_INVALIDARG, got 0x%08lx\n", hres);
639 static HRESULT (WINAPI *pVarParseNumFromStr)(OLECHAR*,LCID,ULONG,NUMPARSE*,BYTE*);
641 /* Macros for converting and testing the result of VarParseNumFromStr */
642 #define FAILDIG 255
643 #define CONVERTN(str,dig,flags) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)); \
644 memset(rgb, FAILDIG, sizeof(rgb)); memset(&np,-1,sizeof(np)); np.cDig = dig; np.dwInFlags = flags; \
645 hres = pVarParseNumFromStr(buff,lcid,LOCALE_NOUSEROVERRIDE,&np,rgb)
646 #define CONVERT(str,flags) CONVERTN(str,sizeof(rgb),flags)
647 #define EXPECT(a,b,c,d,e,f) ok(hres == (HRESULT)S_OK, "Call failed, hres = %08lx\n", hres); \
648 if (hres == (HRESULT)S_OK) { \
649 ok(np.cDig == (a), "Expected cDig = %d, got %d\n", (a), np.cDig); \
650 ok(np.dwInFlags == (b), "Expected dwInFlags = 0x%lx, got 0x%lx\n", (ULONG)(b), np.dwInFlags); \
651 ok(np.dwOutFlags == (c), "Expected dwOutFlags = 0x%lx, got 0x%lx\n", (ULONG)(c), np.dwOutFlags); \
652 ok(np.cchUsed == (d), "Expected cchUsed = %d, got %d\n", (d), np.cchUsed); \
653 ok(np.nBaseShift == (e), "Expected nBaseShift = %d, got %d\n", (e), np.nBaseShift); \
654 ok(np.nPwr10 == (f), "Expected nPwr10 = %d, got %d\n", (f), np.nPwr10); \
656 #define EXPECTRGB(a,b) ok(rgb[a] == b, "Digit[%d], expected %d, got %d\n", a, b, rgb[a])
657 #define EXPECTFAIL ok(hres == (HRESULT)DISP_E_TYPEMISMATCH, "Call succeeded, hres = %08lx\n", hres)
658 #define EXPECT2(a,b) EXPECTRGB(0,a); EXPECTRGB(1,b)
660 static void test_VarParseNumFromStr(void)
662 HRESULT hres;
663 OLECHAR buff[128];
664 /* Ensure all tests are using the same locale characters for '$', ',' etc */
665 LCID lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
666 NUMPARSE np;
667 BYTE rgb[128];
669 /** No flags **/
671 CHECKPTR(VarParseNumFromStr);
673 /* Consume a single digit */
674 CONVERT("7", 0);
675 EXPECT(1,0,0,1,0,0);
676 EXPECT2(7,FAILDIG);
678 /* cDig is not literal digits - zeros are suppressed and nPwr10 is increased */
679 CONVERT("10", 0);
680 EXPECT(1,0,0,2,0,1);
681 /* Note: Win32 writes the trailing zeros if they are within cDig's limits,
682 * but then excludes them from the returned cDig count.
683 * In our implementation we don't bother writing them at all.
685 EXPECTRGB(0, 1);
687 /* if cDig is too small and numbers follow, sets INEXACT */
688 CONVERTN("11",1, 0);
689 EXPECT(1,0,NUMPRS_INEXACT,2,0,1);
690 EXPECT2(1,FAILDIG);
692 /* Strips leading zeros */
693 CONVERT("01", 0);
694 EXPECT(1,0,0,2,0,0);
695 EXPECT2(1,FAILDIG);
697 /* Strips leading zeros */
698 CONVERTN("01",1, 0);
699 EXPECT(1,0,0,2,0,0);
700 EXPECT2(1,FAILDIG);
703 /* Fails on non digits */
704 CONVERT("a", 0);
705 EXPECTFAIL;
706 EXPECTRGB(0,FAILDIG);
708 /** NUMPRS_LEADING_WHITE/NUMPRS_TRAILING_WHITE **/
710 /* Without flag, fails on whitespace */
711 CONVERT(" 0", 0);
712 EXPECTFAIL;
713 EXPECTRGB(0,FAILDIG);
716 /* With flag, consumes whitespace */
717 CONVERT(" 0", NUMPRS_LEADING_WHITE);
718 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
719 EXPECT2(0,FAILDIG);
721 /* Test TAB once, then assume it acts as space for all cases */
722 CONVERT("\t0", NUMPRS_LEADING_WHITE);
723 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
724 EXPECT2(0,FAILDIG);
727 /* Doesn't pick up trailing whitespace without flag */
728 CONVERT("0 ", 0);
729 EXPECT(1,0,0,1,0,0);
730 EXPECT2(0,FAILDIG);
732 /* With flag, consumes trailing whitespace */
733 CONVERT("0 ", NUMPRS_TRAILING_WHITE);
734 EXPECT(1,NUMPRS_TRAILING_WHITE,NUMPRS_TRAILING_WHITE,2,0,0);
735 EXPECT2(0,FAILDIG);
737 /* Leading flag only consumes leading */
738 CONVERT(" 0 ", NUMPRS_LEADING_WHITE);
739 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
740 EXPECT2(0,FAILDIG);
742 /* Both flags consumes both */
743 CONVERT(" 0 ", NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE);
744 EXPECT(1,NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE,NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE,3,0,0);
745 EXPECT2(0,FAILDIG);
747 /** NUMPRS_LEADING_PLUS/NUMPRS_TRAILING_PLUS **/
749 /* Without flag, fails on + */
750 CONVERT("+0", 0);
751 EXPECTFAIL;
752 EXPECTRGB(0,FAILDIG);
754 /* With flag, consumes + */
755 CONVERT("+0", NUMPRS_LEADING_PLUS);
756 EXPECT(1,NUMPRS_LEADING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
757 EXPECT2(0,FAILDIG);
759 /* Without flag, doesn't consume trailing + */
760 CONVERT("0+", 0);
761 EXPECT(1,0,0,1,0,0);
762 EXPECT2(0,FAILDIG);
764 /* With flag, consumes trailing + */
765 CONVERT("0+", NUMPRS_TRAILING_PLUS);
766 EXPECT(1,NUMPRS_TRAILING_PLUS,NUMPRS_TRAILING_PLUS,2,0,0);
767 EXPECT2(0,FAILDIG);
769 /* With leading flag, doesn't consume trailing + */
770 CONVERT("+0+", NUMPRS_LEADING_PLUS);
771 EXPECT(1,NUMPRS_LEADING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
772 EXPECT2(0,FAILDIG);
774 /* Trailing + doesn't get consumed if we specify both (unlike whitespace) */
775 CONVERT("+0+", NUMPRS_LEADING_PLUS|NUMPRS_TRAILING_PLUS);
776 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_TRAILING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
777 EXPECT2(0,FAILDIG);
779 /** NUMPRS_LEADING_MINUS/NUMPRS_TRAILING_MINUS **/
781 /* Without flag, fails on - */
782 CONVERT("-0", 0);
783 EXPECTFAIL;
784 EXPECTRGB(0,FAILDIG);
786 /* With flag, consumes - */
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 /* Without flag, doesn't consume trailing - */
792 CONVERT("0-", 0);
793 EXPECT(1,0,0,1,0,0);
794 EXPECT2(0,FAILDIG);
796 /* With flag, consumes trailing - */
797 CONVERT("0-", NUMPRS_TRAILING_MINUS);
798 EXPECT(1,NUMPRS_TRAILING_MINUS,NUMPRS_NEG|NUMPRS_TRAILING_MINUS,2,0,0);
799 EXPECT2(0,FAILDIG);
801 /* With leading flag, doesn't consume trailing - */
802 CONVERT("-0-", NUMPRS_LEADING_MINUS);
803 EXPECT(1,NUMPRS_LEADING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
804 EXPECT2(0,FAILDIG);
806 /* Trailing - doesn't get consumed if we specify both (unlike whitespace) */
807 CONVERT("-0-", NUMPRS_LEADING_MINUS|NUMPRS_TRAILING_MINUS);
808 EXPECT(1,NUMPRS_LEADING_MINUS|NUMPRS_TRAILING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
809 EXPECT2(0,FAILDIG);
811 /** NUMPRS_HEX_OCT **/
813 /* Could be hex, octal or decimal - With flag reads as decimal */
814 CONVERT("0", NUMPRS_HEX_OCT);
815 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
816 EXPECT2(0,FAILDIG);
818 /* Doesn't recognise hex in .asm sytax */
819 CONVERT("0h", NUMPRS_HEX_OCT);
820 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
821 EXPECT2(0,FAILDIG);
823 /* Doesn't fail with valid leading string but no digits */
824 CONVERT("0x", NUMPRS_HEX_OCT);
825 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
826 EXPECT2(0,FAILDIG);
828 /* Doesn't recognise hex format humbers at all! */
829 CONVERT("0x0", NUMPRS_HEX_OCT);
830 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
831 EXPECT2(0,FAILDIG);
833 /* Doesn't recognise plain hex digits either */
834 CONVERT("FE", NUMPRS_HEX_OCT);
835 EXPECTFAIL;
836 EXPECTRGB(0,FAILDIG);
838 /* Octal */
839 CONVERT("0100", NUMPRS_HEX_OCT);
840 EXPECT(1,NUMPRS_HEX_OCT,0,4,0,2);
841 EXPECTRGB(0,1);
842 EXPECTRGB(1,0);
843 EXPECTRGB(2,0);
844 EXPECTRGB(3,FAILDIG);
846 /* VB hex */
847 CONVERT("&HF800", NUMPRS_HEX_OCT);
848 EXPECT(4,NUMPRS_HEX_OCT,0x40,6,4,0);
849 EXPECTRGB(0,15);
850 EXPECTRGB(1,8);
851 EXPECTRGB(2,0);
852 EXPECTRGB(3,0);
853 EXPECTRGB(4,FAILDIG);
855 /* VB hex lower case and leading zero */
856 CONVERT("&h0abcd", NUMPRS_HEX_OCT);
857 EXPECT(4,NUMPRS_HEX_OCT,0x40,7,4,0);
858 EXPECTRGB(0,10);
859 EXPECTRGB(1,11);
860 EXPECTRGB(2,12);
861 EXPECTRGB(3,13);
862 EXPECTRGB(4,FAILDIG);
864 /* VB oct */
865 CONVERT("&O300", NUMPRS_HEX_OCT);
866 EXPECT(3,NUMPRS_HEX_OCT,0x40,5,3,0);
867 EXPECTRGB(0,3);
868 EXPECTRGB(1,0);
869 EXPECTRGB(2,0);
870 EXPECTRGB(3,FAILDIG);
872 /* VB oct lower case and leading zero */
873 CONVERT("&o0777", NUMPRS_HEX_OCT);
874 EXPECT(3,NUMPRS_HEX_OCT,0x40,6,3,0);
875 EXPECTRGB(0,7);
876 EXPECTRGB(1,7);
877 EXPECTRGB(2,7);
878 EXPECTRGB(3,FAILDIG);
880 /* VB oct char bigger than 7 */
881 CONVERT("&o128", NUMPRS_HEX_OCT);
883 Native versions 2.x of oleaut32 allow this to succeed: later versions and Wine don't
884 EXPECTFAIL;
885 EXPECTRGB(0,FAILDIG);
887 /** NUMPRS_PARENS **/
889 /* Empty parens = error */
890 CONVERT("()", NUMPRS_PARENS);
891 EXPECTFAIL;
892 EXPECTRGB(0,FAILDIG);
894 /* With flag, trailing parens not consumed */
895 CONVERT("0()", NUMPRS_PARENS);
896 EXPECT(1,NUMPRS_PARENS,0,1,0,0);
897 EXPECT2(0,FAILDIG);
899 /* With flag, Number in parens made negative and parens consumed */
900 CONVERT("(0)", NUMPRS_PARENS);
901 EXPECT(1,NUMPRS_PARENS,NUMPRS_NEG|NUMPRS_PARENS,3,0,0);
902 EXPECT2(0,FAILDIG);
904 /** NUMPRS_THOUSANDS **/
906 /* With flag, thousands sep. not needed */
907 CONVERT("0", NUMPRS_THOUSANDS);
908 EXPECT(1,NUMPRS_THOUSANDS,0,1,0,0);
909 EXPECT2(0,FAILDIG);
911 /* With flag, thousands sep. and following digits consumed */
912 CONVERT("1,000", NUMPRS_THOUSANDS);
913 EXPECT(1,NUMPRS_THOUSANDS,NUMPRS_THOUSANDS,5,0,3);
914 EXPECTRGB(0,1);
916 /* With flag and decimal point, thousands sep. but not decimals consumed */
917 CONVERT("1,000.0", NUMPRS_THOUSANDS);
918 EXPECT(1,NUMPRS_THOUSANDS,NUMPRS_THOUSANDS,5,0,3);
919 EXPECTRGB(0,1);
921 /** NUMPRS_CURRENCY **/
923 /* Without flag, chokes on currency sign */
924 CONVERT("$11", 0);
925 EXPECTFAIL;
926 EXPECTRGB(0,FAILDIG);
928 /* With flag, consumes currency sign */
929 CONVERT("$11", NUMPRS_CURRENCY);
930 EXPECT(2,NUMPRS_CURRENCY,NUMPRS_CURRENCY,3,0,0);
931 EXPECT2(1,1);
932 EXPECTRGB(2,FAILDIG);
934 /* With flag only, doesn't consume decimal point */
935 CONVERT("$11.1", NUMPRS_CURRENCY);
936 EXPECT(2,NUMPRS_CURRENCY,NUMPRS_CURRENCY,3,0,0);
937 EXPECT2(1,1);
938 EXPECTRGB(2,FAILDIG);
940 /* With flag and decimal flag, consumes decimal point and following digits */
941 CONVERT("$11.1", NUMPRS_CURRENCY|NUMPRS_DECIMAL);
942 EXPECT(3,NUMPRS_CURRENCY|NUMPRS_DECIMAL,NUMPRS_CURRENCY|NUMPRS_DECIMAL,5,0,-1);
943 EXPECT2(1,1);
944 EXPECTRGB(2,1);
945 EXPECTRGB(3,FAILDIG);
947 /* Thousands flag can only be used with currency */
948 CONVERT("$1,234", NUMPRS_CURRENCY|NUMPRS_THOUSANDS);
949 EXPECT(4,NUMPRS_CURRENCY|NUMPRS_THOUSANDS,NUMPRS_CURRENCY|NUMPRS_THOUSANDS,6,0,0);
950 EXPECT2(1,2);
951 EXPECTRGB(2,3);
952 EXPECTRGB(3,4);
953 EXPECTRGB(4,FAILDIG);
955 /** NUMPRS_DECIMAL **/
957 /* With flag, consumes decimal point */
958 CONVERT("1.1", NUMPRS_DECIMAL);
959 EXPECT(2,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1);
960 EXPECT2(1,1);
961 EXPECTRGB(2,FAILDIG);
963 /* With flag, consumes decimal point. Skipping the decimal part is not an error */
964 CONVERT("1.", NUMPRS_DECIMAL);
965 EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,2,0,0);
966 EXPECT2(1,FAILDIG);
968 /* Consumes only one decimal point */
969 CONVERT("1.1.", NUMPRS_DECIMAL);
970 EXPECT(2,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1);
971 EXPECT2(1,1);
972 EXPECTRGB(2,FAILDIG);
974 /** NUMPRS_EXPONENT **/
976 /* Without flag, doesn't consume exponent */
977 CONVERT("1e1", 0);
978 EXPECT(1,0,0,1,0,0);
979 EXPECT2(1,FAILDIG);
981 /* With flag, consumes exponent */
982 CONVERT("1e1", NUMPRS_EXPONENT);
983 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,1);
984 EXPECT2(1,FAILDIG);
986 /* Negative exponents are accepted without flags */
987 CONVERT("1e-1", NUMPRS_EXPONENT);
988 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,-1);
989 EXPECT2(1,FAILDIG);
991 /* As are positive exponents and leading exponent 0's */
992 CONVERT("1e+01", NUMPRS_EXPONENT);
993 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,5,0,1);
994 EXPECT2(1,FAILDIG);
996 /* The same for zero exponents */
997 CONVERT("1e0", NUMPRS_EXPONENT);
998 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,0);
999 EXPECT2(1,FAILDIG);
1001 /* Sign on a zero exponent doesn't matter */
1002 CONVERT("1e+0", NUMPRS_EXPONENT);
1003 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,0);
1004 EXPECT2(1,FAILDIG);
1006 CONVERT("1e-0", NUMPRS_EXPONENT);
1007 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,0);
1008 EXPECT2(1,FAILDIG);
1010 /* Doesn't consume a real number exponent */
1011 CONVERT("1e1.", NUMPRS_EXPONENT);
1012 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,1);
1013 EXPECT2(1,FAILDIG);
1015 /* Powers of 10 are calculated from the position of any decimal point */
1016 CONVERT("1.5e20", NUMPRS_EXPONENT|NUMPRS_DECIMAL);
1017 EXPECT(2,NUMPRS_EXPONENT|NUMPRS_DECIMAL,NUMPRS_EXPONENT|NUMPRS_DECIMAL,6,0,19);
1018 EXPECT2(1,5);
1020 CONVERT("1.5e-20", NUMPRS_EXPONENT|NUMPRS_DECIMAL);
1021 EXPECT(2,NUMPRS_EXPONENT|NUMPRS_DECIMAL,NUMPRS_EXPONENT|NUMPRS_DECIMAL,7,0,-21);
1022 EXPECT2(1,5);
1024 /** NUMPRS_USE_ALL **/
1026 /* Flag expects all digits */
1027 CONVERT("0", NUMPRS_USE_ALL);
1028 EXPECT(1,NUMPRS_USE_ALL,0,1,0,0);
1029 EXPECT2(0,FAILDIG);
1031 /* Rejects anything trailing */
1032 CONVERT("0 ", NUMPRS_USE_ALL);
1033 EXPECTFAIL;
1034 EXPECT2(0,FAILDIG);
1036 /* Unless consumed by trailing flag */
1037 CONVERT("0 ", NUMPRS_USE_ALL|NUMPRS_TRAILING_WHITE);
1038 EXPECT(1,NUMPRS_USE_ALL|NUMPRS_TRAILING_WHITE,NUMPRS_TRAILING_WHITE,2,0,0);
1039 EXPECT2(0,FAILDIG);
1041 /** Combinations **/
1043 /* Leading whitepace and plus, doesn't consume trailing whitespace */
1044 CONVERT("+ 0 ", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1045 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,3,0,0);
1046 EXPECT2(0,FAILDIG);
1048 /* Order of whitepace and plus is unimportant */
1049 CONVERT(" +0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1050 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,3,0,0);
1051 EXPECT2(0,FAILDIG);
1053 /* Leading whitespace can be repeated */
1054 CONVERT(" + 0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1055 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,4,0,0);
1056 EXPECT2(0,FAILDIG);
1058 /* But plus/minus etc. cannot */
1059 CONVERT("+ +0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1060 EXPECTFAIL;
1061 EXPECTRGB(0,FAILDIG);
1063 /* Inexact is not set if trailing zeros are removed */
1064 CONVERTN("10", 1, 0);
1065 EXPECT(1,0,0,2,0,1);
1066 EXPECT2(1,FAILDIG);
1068 /* Make sure a leading 0 is stripped but decimals after it get read */
1069 CONVERT("-0.51", NUMPRS_STD);
1070 EXPECT(2,NUMPRS_STD,NUMPRS_NEG|NUMPRS_DECIMAL|NUMPRS_LEADING_MINUS,5,0,-2);
1071 EXPECT2(5,1);
1073 /* Keep trailing zeros on whole number part of a decimal */
1074 CONVERT("10.1", NUMPRS_STD);
1075 EXPECT(3,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-1);
1076 EXPECT2(1,0);
1077 EXPECTRGB(2,1);
1079 /* Zeros after decimal sign */
1080 CONVERT("0.01", NUMPRS_STD);
1081 EXPECT(1,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-2);
1082 EXPECT2(1,FAILDIG);
1084 /* Trailing zeros after decimal part */
1085 CONVERT("0.10", NUMPRS_STD);
1086 EXPECT(1,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-1);
1087 EXPECT2(1,0);
1090 static HRESULT (WINAPI *pVarNumFromParseNum)(NUMPARSE*,BYTE*,ULONG,VARIANT*);
1092 /* Macros for converting and testing the result of VarNumFromParseNum */
1093 #define SETRGB(indx,val) if (!indx) memset(rgb, FAILDIG, sizeof(rgb)); rgb[indx] = val
1094 #undef CONVERT
1095 #define CONVERT(a,b,c,d,e,f,bits) \
1096 np.cDig = (a); np.dwInFlags = (b); np.dwOutFlags = (c); np.cchUsed = (d); \
1097 np.nBaseShift = (e); np.nPwr10 = (f); hres = pVarNumFromParseNum(&np, rgb, bits, &vOut)
1098 static const char *szFailOverflow = "Expected overflow, hres = %08lx\n";
1099 #define EXPECT_OVERFLOW ok(hres == (HRESULT)DISP_E_OVERFLOW, szFailOverflow, hres)
1100 static const char *szFailOk = "Call failed, hres = %08lx\n";
1101 #define EXPECT_OK ok(hres == (HRESULT)S_OK, szFailOk, hres); \
1102 if (hres == (HRESULT)S_OK)
1103 #define EXPECT_TYPE(typ) ok(V_VT(&vOut) == typ,"Expected Type = " #typ ", got %d\n", V_VT(&vOut))
1104 #define EXPECT_I1(val) EXPECT_OK { EXPECT_TYPE(VT_I1); \
1105 ok(V_I1(&vOut) == val, "Expected i1 = %d, got %d\n", (signed char)val, V_I1(&vOut)); }
1106 #define EXPECT_UI1(val) EXPECT_OK { EXPECT_TYPE(VT_UI1); \
1107 ok(V_UI1(&vOut) == val, "Expected ui1 = %d, got %d\n", (BYTE)val, V_UI1(&vOut)); }
1108 #define EXPECT_I2(val) EXPECT_OK { EXPECT_TYPE(VT_I2); \
1109 ok(V_I2(&vOut) == val, "Expected i2 = %d, got %d\n", (SHORT)val, V_I2(&vOut)); }
1110 #define EXPECT_UI2(val) EXPECT_OK { EXPECT_TYPE(VT_UI2); \
1111 ok(V_UI2(&vOut) == val, "Expected ui2 = %d, got %d\n", (USHORT)val, V_UI2(&vOut)); }
1112 #define EXPECT_I4(val) EXPECT_OK { EXPECT_TYPE(VT_I4); \
1113 ok(V_I4(&vOut) == val, "Expected i4 = %ld, got %ld\n", (LONG)val, V_I4(&vOut)); }
1114 #define EXPECT_UI4(val) EXPECT_OK { EXPECT_TYPE(VT_UI4); \
1115 ok(V_UI4(&vOut) == val, "Expected ui4 = %ld, got %ld\n", (ULONG)val, V_UI4(&vOut)); }
1116 #define EXPECT_I8(high,low) EXPECT_OK { EXPECT_TYPE(VT_I8); \
1117 ok(V_I8(&vOut) == ((((LONG64)(high))<<32)|(low)), "Expected i8 = %lx%08lx, got %lx%08lx\n", \
1118 (LONG)(high), (LONG)(low), (LONG)(V_I8(&vOut)>>32), (LONG)V_I8(&vOut) ); }
1119 #define EXPECT_UI8(val) EXPECT_OK { EXPECT_TYPE(VT_UI8); \
1120 ok(V_UI8(&vOut) == val, "Expected ui8 = %lld, got %lld\n", (ULONG64)val, V_UI8(&vOut)); }
1121 #define EXPECT_R4(val) EXPECT_OK { EXPECT_TYPE(VT_R4); \
1122 ok(V_R4(&vOut) == val, "Expected r4 = %f, got %f\n", val, V_R4(&vOut)); }
1123 #define EXPECT_R8(val) EXPECT_OK { EXPECT_TYPE(VT_R8); \
1124 ok(V_R8(&vOut) == val, "Expected r8 = %g, got %g\n", val, V_R8(&vOut)); }
1125 #define CY_MULTIPLIER 10000
1126 #define EXPECT_CY(val) EXPECT_OK { EXPECT_TYPE(VT_CY); \
1127 ok(V_CY(&vOut).int64 == (LONG64)(val * CY_MULTIPLIER), "Expected r8 = %lld, got %lld\n", (LONG64)val, V_CY(&vOut).int64); }
1129 static void test_VarNumFromParseNum(void)
1131 HRESULT hres;
1132 NUMPARSE np;
1133 BYTE rgb[128];
1134 VARIANT vOut;
1136 CHECKPTR(VarNumFromParseNum);
1138 /* Convert the number 1 to different types */
1139 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I1); EXPECT_I1(1);
1140 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_UI1); EXPECT_UI1(1);
1141 /* Prefers a signed type to unsigned of the same size */
1142 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I1|VTBIT_UI1); EXPECT_I1(1);
1143 /* But takes the smaller size if possible */
1144 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I2|VTBIT_UI1); EXPECT_UI1(1);
1146 /* Try different integer sizes */
1147 #define INTEGER_VTBITS (VTBIT_I1|VTBIT_UI1|VTBIT_I2|VTBIT_UI2|VTBIT_I4|VTBIT_UI4|VTBIT_I8|VTBIT_UI8)
1149 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, INTEGER_VTBITS); EXPECT_I1(1);
1150 /* 127 */
1151 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 7);
1152 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_I1(127);
1153 /* 128 */
1154 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 8);
1155 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_UI1(128);
1156 /* 255 */
1157 SETRGB(0, 2); SETRGB(1, 5); SETRGB(2, 5);
1158 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_UI1(255);
1159 /* 256 */
1160 SETRGB(0, 2); SETRGB(1, 5); SETRGB(2, 6);
1161 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_I2(256);
1162 /* 32767 */
1163 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 7);
1164 CONVERT(5,0,0,5,0,0, INTEGER_VTBITS); EXPECT_I2(32767);
1165 /* 32768 */
1166 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 8);
1167 CONVERT(5,0,0,5,0,0, INTEGER_VTBITS); EXPECT_UI2(32768);
1169 /* Assume the above pattern holds for remaining positive integers; test negative */
1171 /* -128 */
1172 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 8);
1173 CONVERT(3,0,NUMPRS_NEG,3,0,0, INTEGER_VTBITS); EXPECT_I1(-128);
1174 /* -129 */
1175 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 9);
1176 CONVERT(3,0,NUMPRS_NEG,3,0,0, INTEGER_VTBITS); EXPECT_I2(-129);
1177 /* -32768 */
1178 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 8);
1179 CONVERT(5,0,NUMPRS_NEG,5,0,0, INTEGER_VTBITS); EXPECT_I2(-32768);
1180 /* -32768 */
1181 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 9);
1182 CONVERT(5,0,NUMPRS_NEG,5,0,0, INTEGER_VTBITS); EXPECT_I4(-32769);
1184 /* Assume the above pattern holds for remaining negative integers */
1186 /* Test hexadecimal conversions */
1187 SETRGB(0, 1); CONVERT(1,0,0,1,4,0, INTEGER_VTBITS); EXPECT_I1(0x01);
1188 /* 0x7f */
1189 SETRGB(0, 7); SETRGB(1, 0xf);
1190 CONVERT(2,0,0,2,4,0, INTEGER_VTBITS); EXPECT_I1(0x7f);
1191 /* 0x7fff */
1192 SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
1193 CONVERT(4,0,0,4,4,0, INTEGER_VTBITS); EXPECT_I2(0x7fff);
1194 /* 0x7fffffff */
1195 SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
1196 SETRGB(4, 0xf); SETRGB(5, 0xf); SETRGB(6, 0xf); SETRGB(7, 0xf);
1197 CONVERT(8,0,0,8,4,0, INTEGER_VTBITS); EXPECT_I4(0x7fffffffL);
1198 /* 0x7fffffffffffffff (64 bits) */
1199 SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
1200 SETRGB(4, 0xf); SETRGB(5, 0xf); SETRGB(6, 0xf); SETRGB(7, 0xf);
1201 SETRGB(8, 0xf); SETRGB(9, 0xf); SETRGB(10, 0xf); SETRGB(11, 0xf);
1202 SETRGB(12, 0xf); SETRGB(13, 0xf); SETRGB(14, 0xf); SETRGB(15, 0xf);
1203 if (HAVE_OLEAUT32_I8)
1205 CONVERT(16,0,0,16,4,0, INTEGER_VTBITS); EXPECT_I8(0x7fffffff,0xffffffff);
1208 /* Assume the above pattern holds for numbers without hi-bit set, test (preservation of) hi-bit */
1209 /* 0x82 */
1210 SETRGB(0, 8); SETRGB(1, 2);
1211 CONVERT(2,0,0,2,4,0, INTEGER_VTBITS);
1212 EXPECT_I1((signed char)0x82);
1213 /* 0x8002 */
1214 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 2);
1215 CONVERT(4,0,0,4,4,0, INTEGER_VTBITS);
1216 EXPECT_I2((signed short)0x8002);
1217 /* 0x80000002 */
1218 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1219 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 2);
1220 CONVERT(8,0,0,8,4,0, INTEGER_VTBITS); EXPECT_I4(0x80000002L);
1221 /* 0x8000000000000002 (64 bits) */
1222 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1223 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 0);
1224 SETRGB(8, 0); SETRGB(9, 0); SETRGB(10, 0); SETRGB(11, 0);
1225 SETRGB(12, 0); SETRGB(13, 0); SETRGB(14, 0); SETRGB(15, 2);
1226 if (HAVE_OLEAUT32_I8)
1228 CONVERT(16,0,0,16,4,0, INTEGER_VTBITS); EXPECT_I8(0x80000000,0x00000002);
1231 /* Test (preservation of) hi-bit with STRICT type requesting */
1232 /* 0x82 */
1233 SETRGB(0, 8); SETRGB(1, 2);
1234 CONVERT(2,0,0,2,4,0, VTBIT_I1);
1235 EXPECT_I1((signed char)0x82);
1236 /* 0x8002 */
1237 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 2);
1238 CONVERT(4,0,0,4,4,0, VTBIT_I2);
1239 EXPECT_I2((signed short)0x8002);
1240 /* 0x80000002 */
1241 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1242 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 2);
1243 CONVERT(8,0,0,8,4,0, VTBIT_I4); EXPECT_I4(0x80000002L);
1244 /* 0x8000000000000002 (64 bits) */
1245 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1246 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 0);
1247 SETRGB(8, 0); SETRGB(9, 0); SETRGB(10, 0); SETRGB(11, 0);
1248 SETRGB(12, 0); SETRGB(13, 0); SETRGB(14, 0); SETRGB(15, 2);
1249 if (HAVE_OLEAUT32_I8)
1251 CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x80000000,0x00000002);
1253 /* Assume the above pattern holds for numbers with hi-bit set */
1255 /* Negative numbers overflow if we have only unsigned outputs */
1256 /* -1 */
1257 SETRGB(0, 1); CONVERT(1,0,NUMPRS_NEG,1,0,0, VTBIT_UI1); EXPECT_OVERFLOW;
1258 /* -0.6 */
1259 SETRGB(0, 6); CONVERT(1,0,NUMPRS_NEG,1,0,~0u, VTBIT_UI1); EXPECT_OVERFLOW;
1261 /* Except that rounding is done first, so -0.5 to 0 are accepted as 0 */
1262 /* -0.5 */
1263 SETRGB(0, 5); CONVERT(1,0,NUMPRS_NEG,1,0,~0u, VTBIT_UI1); EXPECT_UI1(0);
1265 /* Floating point zero is OK */
1266 /* 0.00000000E0 */
1267 SETRGB(0, 0); CONVERT(1,0,NUMPRS_DECIMAL|NUMPRS_EXPONENT,12,0,-8, VTBIT_R8);
1268 EXPECT_R8(0.0);
1270 /* Float is acceptable for an integer input value */
1271 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R4); EXPECT_R4(1.0f);
1272 /* As is double */
1273 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R8); EXPECT_R8(1.0);
1274 /* As is currency */
1275 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_CY); EXPECT_CY(1);
1277 /* Float is preferred over double */
1278 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R4|VTBIT_R8); EXPECT_R4(1.0f);
1280 /* Double is preferred over currency */
1281 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R8|VTBIT_CY); EXPECT_R8(1.0);
1283 /* Currency is preferred over decimal */
1284 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_CY|VTBIT_DECIMAL); EXPECT_CY(1);
1287 static const char* szUdateFromDateFail = "%.16g expected %lx, %d,%d,%d,%d,%d,%d,%d %d %d"
1288 ", got %lx, %d,%d,%d,%d,%d,%d,%d %d %d\n";
1289 #define DT2UD(dt,flags,r,d,m,y,h,mn,s,ms,dw,dy) \
1290 memset(&ud, 0, sizeof(ud)); \
1291 res = pVarUdateFromDate(dt, flags, &ud); \
1292 ok(r == res && (FAILED(r) || (ud.st.wYear == y && ud.st.wMonth == m && ud.st.wDay == d && \
1293 ud.st.wHour == h && ud.st.wMinute == mn && ud.st.wSecond == s && \
1294 ud.st.wMilliseconds == ms && ud.st.wDayOfWeek == dw && ud.wDayOfYear == dy)), \
1295 szUdateFromDateFail, dt, r, d, m, y, h, mn, s, ms, dw, dy, res, ud.st.wDay, ud.st.wMonth, \
1296 ud.st.wYear, ud.st.wHour, ud.st.wMinute, ud.st.wSecond, \
1297 ud.st.wMilliseconds, ud.st.wDayOfWeek, ud.wDayOfYear)
1299 static void test_VarUdateFromDate(void)
1301 UDATE ud;
1302 HRESULT res;
1304 CHECKPTR(VarUdateFromDate);
1305 DT2UD(29221.0,0,S_OK,1,1,1980,0,0,0,0,2,1); /* 1 Jan 1980 */
1306 DT2UD(29222.0,0,S_OK,2,1,1980,0,0,0,0,3,2); /* 2 Jan 1980 */
1307 DT2UD(33238.0,0,S_OK,31,12,1990,0,0,0,0,1,365); /* 31 Dec 1990 */
1308 DT2UD(0.0,0,S_OK,30,12,1899,0,0,0,0,6,364); /* 30 Dec 1899 - VT_DATE 0.0 */
1309 DT2UD(-657434.0,0,S_OK,1,1,100,0,0,0,0,5,1); /* 1 Jan 100 - Min */
1310 DT2UD(-657435.0,0,E_INVALIDARG,0,0,0,0,0,0,0,0,0); /* < 1 Jan 100 => err */
1311 DT2UD(2958465.0,0,S_OK,31,12,9999,0,0,0,0,5,365); /* 31 Dec 9999 - Max */
1312 DT2UD(2958466.0,0,E_INVALIDARG,0,0,0,0,0,0,0,0,0); /* > 31 Dec 9999 => err */
1314 /* VAR_VALIDDATE doesn't prevent upper and lower bounds being checked */
1315 DT2UD(-657435.0,VAR_VALIDDATE,E_INVALIDARG,0,0,0,0,0,0,0,0,0);
1316 DT2UD(2958466.0,VAR_VALIDDATE,E_INVALIDARG,0,0,0,0,0,0,0,0,0);
1318 /* Times */
1319 DT2UD(29221.25,0,S_OK,1,1,1980,6,0,0,0,2,1); /* 6 AM */
1320 DT2UD(29221.33333333,0,S_OK,1,1,1980,8,0,0,0,2,1); /* 8 AM */
1321 DT2UD(29221.5,0,S_OK,1,1,1980,12,0,0,0,2,1); /* 12 AM */
1322 DT2UD(29221.9888884444,0,S_OK,1,1,1980,23,44,0,0,2,1); /* 11:44 PM */
1323 DT2UD(29221.7508765432,0,S_OK,1,1,1980,18,1,16,0,2,1); /* 6:18:02 PM */
1326 #define UD2T(d,m,y,h,mn,s,ms,dw,dy,flags,r,dt) \
1327 ud.st.wYear = (y); ud.st.wMonth = (m); ud.st.wDay = (d); ud.st.wHour = (h); \
1328 ud.st.wMinute = (mn); ud.st.wSecond = (s); ud.st.wMilliseconds = (ms); \
1329 ud.st.wDayOfWeek = (dw); ud.wDayOfYear = (dy); \
1330 res = pVarDateFromUdate(&ud, (flags), &out); \
1331 ok((r) == res && (FAILED(r) || fabs(out-(dt)) < 1.0e-11), \
1332 "expected %lx, %.16g, got %lx, %.16g\n", r, dt, res, out)
1334 static void test_VarDateFromUdate(void)
1336 UDATE ud;
1337 double out;
1338 HRESULT res;
1340 CHECKPTR(VarDateFromUdate);
1341 UD2T(1,1,1980,0,0,0,0,2,1,0,S_OK,29221.0); /* 1 Jan 1980 */
1342 UD2T(2,1,1980,0,0,0,0,3,2,0,S_OK,29222.0); /* 2 Jan 1980 */
1343 UD2T(31,12,1990,0,0,0,0,0,0,0,S_OK,33238.0); /* 31 Dec 1990 */
1344 UD2T(31,12,90,0,0,0,0,0,0,0,S_OK,33238.0); /* year < 100 is 1900+year! */
1345 UD2T(30,12,1899,0,0,0,0,6,364,0,S_OK,0.0); /* 30 Dec 1899 - VT_DATE 0.0 */
1346 UD2T(1,1,100,0,0,0,0,0,0,0,S_OK,-657434.0); /* 1 Jan 100 - Min */
1347 UD2T(31,12,9999,0,0,0,0,0,0,0,S_OK,2958465.0); /* 31 Dec 9999 - Max */
1348 UD2T(1,1,10000,0,0,0,0,0,0,0,E_INVALIDARG,0.0); /* > 31 Dec 9999 => err */
1350 UD2T(1,1,1980,18,1,16,0,2,1,0,S_OK,29221.75087962963); /* 6:18:02 PM */
1352 UD2T(0,1,1980,0,0,0,0,2,1,0,S_OK,29220.0); /* Rolls back to 31 Dec 1899 */
1353 UD2T(1,13,1980,0,0,0,0,2,1,0,S_OK,29587.0); /* Rolls fwd to 1/1/1981 */
1356 #define ST2DT(d,m,y,h,mn,s,ms,r,dt) \
1357 st.wYear = y; st.wMonth = m; st.wDay = d; st.wHour = h; st.wMinute = mn; \
1358 st.wSecond = s; st.wMilliseconds = ms; st.wDayOfWeek = 0; \
1359 res = pSystemTimeToVariantTime(&st, &out); \
1360 ok(r == res && (!r || fabs(out-dt) < 1.0e-11), \
1361 "expected %d, %.16g, got %d, %.16g\n", r, dt, res, out)
1363 static void test_SystemTimeToVariantTime(void)
1365 SYSTEMTIME st;
1366 double out;
1367 int res;
1369 CHECKPTR(SystemTimeToVariantTime);
1370 ST2DT(1,1,1980,0,0,0,0,TRUE,29221.0);
1371 ST2DT(2,1,1980,0,0,0,0,TRUE,29222.0);
1372 ST2DT(0,1,1980,0,0,0,0,TRUE,29220.0); /* Rolls back to 31 Dec 1899 */
1373 ST2DT(1,13,1980,0,0,0,0,FALSE,29587.0); /* Fails on invalid month */
1374 ST2DT(31,12,90,0,0,0,0,TRUE,33238.0); /* year < 100 is 1900+year! */
1377 #define DT2ST(dt,r,d,m,y,h,mn,s,ms) \
1378 memset(&st, 0, sizeof(st)); \
1379 res = pVariantTimeToSystemTime(dt, &st); \
1380 ok(r == res && (!r || (st.wYear == y && st.wMonth == m && st.wDay == d && \
1381 st.wHour == h && st.wMinute == mn && st.wSecond == s && \
1382 st.wMilliseconds == ms)), \
1383 "%.16g expected %d, %d,%d,%d,%d,%d,%d,%d, got %d, %d,%d,%d,%d,%d,%d,%d\n", \
1384 dt, r, d, m, y, h, mn, s, ms, res, st.wDay, st.wMonth, st.wYear, \
1385 st.wHour, st.wMinute, st.wSecond, st.wMilliseconds)
1387 static void test_VariantTimeToSystemTime(void)
1389 SYSTEMTIME st;
1390 int res;
1392 CHECKPTR(VariantTimeToSystemTime);
1393 DT2ST(29221.0,1,1,1,1980,0,0,0,0);
1394 DT2ST(29222.0,1,2,1,1980,0,0,0,0);
1397 #define MKDOSDATE(d,m,y) ((d & 0x1f) | ((m & 0xf) << 5) | (((y-1980) & 0x7f) << 9))
1398 #define MKDOSTIME(h,m,s) (((s>>1) & 0x1f) | ((m & 0x3f) << 5) | ((h & 0x1f) << 11))
1400 static const char *szDosDateToVarTimeFail = "expected %d, %.16g, got %d, %.16g\n";
1401 #define DOS2DT(d,m,y,h,mn,s,r,dt) out = 0.0; \
1402 dosDate = MKDOSDATE(d,m,y); \
1403 dosTime = MKDOSTIME(h,mn,s); \
1404 res = pDosDateTimeToVariantTime(dosDate, dosTime, &out); \
1405 ok(r == res && (!r || fabs(out-dt) < 1.0e-11), \
1406 szDosDateToVarTimeFail, r, dt, res, out)
1408 static void test_DosDateTimeToVariantTime(void)
1410 USHORT dosDate, dosTime;
1411 double out;
1412 INT res;
1414 CHECKPTR(DosDateTimeToVariantTime);
1416 /* Date */
1417 DOS2DT(1,1,1980,0,0,0,1,29221.0); /* 1/1/1980 */
1418 DOS2DT(31,12,2099,0,0,0,1,73050.0); /* 31/12/2099 */
1419 /* Dates are limited to the dos date max of 31/12/2099 */
1420 DOS2DT(31,12,2100,0,0,0,0,0.0); /* 31/12/2100 */
1421 /* Days and months of 0 cause date to roll back 1 day or month */
1422 DOS2DT(0,1,1980,0,0,0,1,29220.0); /* 0 Day => 31/12/1979 */
1423 DOS2DT(1,0,1980,0,0,0,1,29190.0); /* 0 Mth => 1/12/1979 */
1424 DOS2DT(0,0,1980,0,0,0,1,29189.0); /* 0 D/M => 30/11/1979 */
1425 /* Days > days in the month cause date to roll forward 1 month */
1426 DOS2DT(29,2,1981,0,0,0,1,29646.0); /* 29/2/1981 -> 3/1/1980 */
1427 DOS2DT(30,2,1981,0,0,0,1,29647.0); /* 30/2/1981 -> 4/1/1980 */
1428 /* Takes leap years into account when rolling forward */
1429 DOS2DT(29,2,1980,0,0,0,1,29280.0); /* 2/29/1980 */
1430 /* Months > 12 cause an error */
1431 DOS2DT(2,13,1980,0,0,0,0,0.0);
1433 /* Time */
1434 DOS2DT(1,1,1980,0,0,29,1,29221.00032407407); /* 1/1/1980 12:00:28 AM */
1435 DOS2DT(1,1,1980,0,0,31,1,29221.00034722222); /* 1/1/1980 12:00:30 AM */
1436 DOS2DT(1,1,1980,0,59,0,1,29221.04097222222); /* 1/1/1980 12:59:00 AM */
1437 DOS2DT(1,1,1980,0,60,0,0,0.0); /* Invalid seconds */
1438 DOS2DT(1,1,1980,23,0,0,1,29221.95833333333); /* 1/1/1980 11:00:00 PM */
1439 DOS2DT(1,1,1980,24,0,0,0,0.0); /* Invalid hours */
1442 #define DT2DOS(dt,r,d,m,y,h,mn,s) dosTime = dosDate = 0; \
1443 expDosDate = MKDOSDATE(d,m,y); \
1444 expDosTime = MKDOSTIME(h,mn,s); \
1445 res = pVariantTimeToDosDateTime(dt, &dosDate, &dosTime); \
1446 ok(r == res && (!r || (dosTime == expDosTime && dosDate == expDosDate)), \
1447 "%g: expected %d,%d(%d/%d/%d),%d(%d:%d:%d) got %d,%d(%d/%d/%d),%d(%d:%d:%d)\n", \
1448 dt, r, expDosDate, expDosDate & 0x1f, (expDosDate >> 5) & 0xf, 1980 + (expDosDate >> 9), \
1449 expDosTime, expDosTime >> 11, (expDosTime >> 5) & 0x3f, (expDosTime & 0x1f), \
1450 res, dosDate, dosDate & 0x1f, (dosDate >> 5) & 0xf, 1980 + (dosDate >> 9), \
1451 dosTime, dosTime >> 11, (dosTime >> 5) & 0x3f, (dosTime & 0x1f))
1453 static void test_VariantTimeToDosDateTime(void)
1455 USHORT dosDate, dosTime, expDosDate, expDosTime;
1456 INT res;
1458 CHECKPTR(VariantTimeToDosDateTime);
1460 /* Date */
1461 DT2DOS(29221.0,1,1,1,1980,0,0,0); /* 1/1/1980 */
1462 DT2DOS(73050.0,1,31,12,2099,0,0,0); /* 31/12/2099 */
1463 DT2DOS(29220.0,0,0,0,0,0,0,0); /* 31/12/1979 - out of range */
1464 DT2DOS(73415.0,0,0,0,0,0,0,0); /* 31/12/2100 - out of range */
1466 /* Time */
1467 DT2DOS(29221.00032407407,1,1,1,1980,0,0,29); /* 1/1/1980 12:00:28 AM */
1468 DT2DOS(29221.00034722222,1,1,1,1980,0,0,31); /* 1/1/1980 12:00:30 AM */
1469 DT2DOS(29221.04097222222,1,1,1,1980,0,59,0); /* 1/1/1980 12:59:00 AM */
1470 DT2DOS(29221.95833333333,1,1,1,1980,23,0,0); /* 1/1/1980 11:00:00 PM */
1473 #define FMT_NUMBER(vt,val) \
1474 VariantInit(&v); V_VT(&v) = vt; val(&v) = 1; \
1475 hres = pVarFormatNumber(&v,2,0,0,0,0,&str); \
1476 ok(hres == S_OK, "VarFormatNumber (vt %d): returned %8lx\n", vt, hres); \
1477 if (hres == S_OK) \
1478 ok(str && strcmpW(str,szResult1) == 0, \
1479 "VarFormatNumber (vt %d): string different\n", vt)
1481 static void test_VarFormatNumber(void)
1483 static const WCHAR szSrc1[] = { '1','\0' };
1484 static const WCHAR szResult1[] = { '1','.','0','0','\0' };
1485 static const WCHAR szSrc2[] = { '-','1','\0' };
1486 static const WCHAR szResult2[] = { '(','1','.','0','0',')','\0' };
1487 char buff[8];
1488 HRESULT hres;
1489 VARIANT v;
1490 BSTR str = NULL;
1492 CHECKPTR(VarFormatNumber);
1494 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char));
1495 if (buff[0] != '.' || buff[1])
1497 trace("Skipping VarFormatNumber tests as decimal separator is '%s'\n", buff);
1498 return;
1501 FMT_NUMBER(VT_I1, V_I1);
1502 FMT_NUMBER(VT_UI1, V_UI1);
1503 FMT_NUMBER(VT_I2, V_I2);
1504 FMT_NUMBER(VT_UI2, V_UI2);
1505 FMT_NUMBER(VT_I4, V_I4);
1506 FMT_NUMBER(VT_UI4, V_UI4);
1507 if (HAVE_OLEAUT32_I8)
1509 FMT_NUMBER(VT_I8, V_I8);
1510 FMT_NUMBER(VT_UI8, V_UI8);
1512 FMT_NUMBER(VT_R4, V_R4);
1513 FMT_NUMBER(VT_R8, V_R8);
1514 FMT_NUMBER(VT_BOOL, V_BOOL);
1516 V_VT(&v) = VT_BSTR;
1517 V_BSTR(&v) = SysAllocString(szSrc1);
1519 hres = pVarFormatNumber(&v,2,0,0,0,0,&str);
1520 ok(hres == S_OK, "VarFormatNumber (bstr): returned %8lx\n", hres);
1521 if (hres == S_OK)
1522 ok(str && strcmpW(str, szResult1) == 0, "VarFormatNumber (bstr): string different\n");
1523 SysFreeString(V_BSTR(&v));
1524 SysFreeString(str);
1526 V_BSTR(&v) = SysAllocString(szSrc2);
1527 hres = pVarFormatNumber(&v,2,0,-1,0,0,&str);
1528 ok(hres == S_OK, "VarFormatNumber (bstr): returned %8lx\n", hres);
1529 if (hres == S_OK)
1530 ok(str && strcmpW(str, szResult2) == 0, "VarFormatNumber (-bstr): string different\n");
1531 SysFreeString(V_BSTR(&v));
1532 SysFreeString(str);
1535 #define SIGNED_VTBITS (VTBIT_I1|VTBIT_I2|VTBIT_I4|VTBIT_I8|VTBIT_R4|VTBIT_R8)
1537 static const char *szVarFmtFail = "VT %d|0x%04x Format %s: expected 0x%08lx, '%s', got 0x%08lx, '%s'\n";
1538 #define VARFMT(vt,v,val,fmt,ret,str) do { \
1539 if (out) SysFreeString(out); out = NULL; \
1540 V_VT(&in) = (vt); v(&in) = val; \
1541 if (fmt) MultiByteToWideChar(CP_ACP, 0, fmt, -1, buffW, sizeof(buffW)/sizeof(WCHAR)); \
1542 hres = pVarFormat(&in,fmt ? buffW : NULL,fd,fw,flags,&out); \
1543 if (SUCCEEDED(hres)) WideCharToMultiByte(CP_ACP, 0, out, -1, buff, sizeof(buff),0,0); \
1544 else buff[0] = '\0'; \
1545 ok(hres == ret && (FAILED(ret) || !strcmp(buff, str)), \
1546 szVarFmtFail, \
1547 (vt)&VT_TYPEMASK,(vt)&~VT_TYPEMASK,fmt?fmt:"<null>",ret,str,hres,buff); \
1548 } while(0)
1550 typedef struct tagFMTRES
1552 LPCSTR fmt;
1553 LPCSTR one_res;
1554 LPCSTR zero_res;
1555 } FMTRES;
1557 static const FMTRES VarFormat_results[] =
1559 { NULL, "1", "0" },
1560 { "", "1", "0" },
1561 { "General Number", "1", "0" },
1562 { "Percent", "100.00%", "0.00%" },
1563 { "Standard", "1.00", "0.00" },
1564 { "Scientific","1.00E+00", "0.00E+00" },
1565 { "True/False", "True", "False" },
1566 { "On/Off", "On", "Off" },
1567 { "Yes/No", "Yes", "No" },
1568 { "#", "1", "" },
1569 { "##", "1", "" },
1570 { "#.#", "1.", "." },
1571 { "0", "1", "0" },
1572 { "00", "01", "00" },
1573 { "0.0", "1.0", "0.0" },
1574 { "00\\c\\o\\p\\y", "01copy","00copy" },
1575 { "\"pos\";\"neg\"", "pos", "pos" },
1576 { "\"pos\";\"neg\";\"zero\"","pos", "zero" }
1579 typedef struct tagFMTDATERES
1581 DATE val;
1582 LPCSTR fmt;
1583 LPCSTR res;
1584 } FMTDATERES;
1586 static const FMTDATERES VarFormat_date_results[] =
1588 { 0.0, "w", "7" },
1589 { 0.0, "w", "6" },
1590 { 0.0, "w", "5" },
1591 { 0.0, "w", "4" },
1592 { 0.0, "w", "3" },
1593 { 0.0, "w", "2" },
1594 { 0.0, "w", "1" }, /* First 7 entries must remain in this order! */
1595 { 2.525, "am/pm", "pm" },
1596 { 2.525, "AM/PM", "PM" },
1597 { 2.525, "A/P", "P" },
1598 { 2.525, "a/p", "p" },
1599 { 2.525, "q", "1" },
1600 { 2.525, "d", "1" },
1601 { 2.525, "dd", "01" },
1602 { 2.525, "ddd", "Mon" },
1603 { 2.525, "dddd", "Monday" },
1604 { 2.525, "mmm", "Jan" },
1605 { 2.525, "mmmm", "January" },
1606 { 2.525, "y", "1" },
1607 { 2.525, "yy", "00" },
1608 { 2.525, "yyy", "001" },
1609 { 2.525, "yyyy", "1900" },
1610 { 2.525, "dd mm yyyy hh:mm:ss", "01 01 1900 12:36:00" },
1611 { 2.525, "dd mm yyyy mm", "01 01 1900 01" },
1612 { 2.525, "dd mm yyyy :mm", "01 01 1900 :01" },
1613 { 2.525, "dd mm yyyy hh:mm", "01 01 1900 12:36" },
1614 { 2.525, "mm mm", "01 01" },
1615 { 2.525, "mm :mm:ss", "01 :01:00" },
1616 { 2.525, "mm :ss:mm", "01 :00:01" },
1617 { 2.525, "hh:mm :ss:mm", "12:36 :00:01" },
1618 { 2.525, "hh:dd :mm:mm", "12:01 :01:01" },
1619 { 2.525, "dd:hh :mm:mm", "01:12 :36:01" },
1620 { 2.525, "hh :mm:mm", "12 :36:01" },
1621 { 2.525, "dd :mm:mm", "01 :01:01" },
1622 { 2.525, "dd :mm:nn", "01 :01:36" },
1623 { 2.725, "hh:nn:ss A/P", "05:24:00 P" }
1626 #define VNUMFMT(vt,v) \
1627 for (i = 0; i < sizeof(VarFormat_results)/sizeof(FMTRES); i++) \
1629 VARFMT(vt,v,1,VarFormat_results[i].fmt,S_OK,VarFormat_results[i].one_res); \
1630 VARFMT(vt,v,0,VarFormat_results[i].fmt,S_OK,VarFormat_results[i].zero_res); \
1632 if ((1 << vt) & SIGNED_VTBITS) \
1634 VARFMT(vt,v,-1,"\"pos\";\"neg\"",S_OK,"neg"); \
1635 VARFMT(vt,v,-1,"\"pos\";\"neg\";\"zero\"",S_OK,"neg"); \
1638 static void test_VarFormat(void)
1640 static const WCHAR szTesting[] = { 't','e','s','t','i','n','g','\0' };
1641 size_t i;
1642 WCHAR buffW[256];
1643 char buff[256];
1644 VARIANT in;
1645 VARIANT_BOOL bTrue = VARIANT_TRUE, bFalse = VARIANT_FALSE;
1646 int fd = 0, fw = 0;
1647 ULONG flags = 0;
1648 BSTR bstrin, out = NULL;
1649 HRESULT hres;
1651 CHECKPTR(VarFormat);
1653 if (PRIMARYLANGID(LANGIDFROMLCID(GetUserDefaultLCID())) != LANG_ENGLISH)
1655 trace("Skipping VarFormat tests for non english language\n");
1656 return;
1658 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char));
1659 if (buff[0] != '.' || buff[1])
1661 trace("Skipping VarFormat tests as decimal separator is '%s'\n", buff);
1662 return;
1664 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IDIGITS, buff, sizeof(buff)/sizeof(char));
1665 if (buff[0] != '2' || buff[1])
1667 trace("Skipping VarFormat tests as decimal places is '%s'\n", buff);
1668 return;
1671 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"True/False",S_OK,"True");
1672 VARFMT(VT_BOOL,V_BOOL,VARIANT_FALSE,"True/False",S_OK,"False");
1674 VNUMFMT(VT_I1,V_I1);
1675 VNUMFMT(VT_I2,V_I2);
1676 VNUMFMT(VT_I4,V_I4);
1677 if (HAVE_OLEAUT32_I8)
1679 VNUMFMT(VT_I8,V_I8);
1681 VNUMFMT(VT_INT,V_INT);
1682 VNUMFMT(VT_UI1,V_UI1);
1683 VNUMFMT(VT_UI2,V_UI2);
1684 VNUMFMT(VT_UI4,V_UI4);
1685 if (HAVE_OLEAUT32_I8)
1687 VNUMFMT(VT_UI8,V_UI8);
1689 VNUMFMT(VT_UINT,V_UINT);
1690 VNUMFMT(VT_R4,V_R4);
1691 VNUMFMT(VT_R8,V_R8);
1693 /* Reference types are dereferenced */
1694 VARFMT(VT_BOOL|VT_BYREF,V_BOOLREF,&bTrue,"True/False",S_OK,"True");
1695 VARFMT(VT_BOOL|VT_BYREF,V_BOOLREF,&bFalse,"True/False",S_OK,"False");
1697 /* Dates */
1698 for (i = 0; i < sizeof(VarFormat_date_results)/sizeof(FMTDATERES); i++)
1700 if (i < 7)
1701 fd = i + 1; /* Test first day */
1702 else
1703 fd = 0;
1704 VARFMT(VT_DATE,V_DATE,VarFormat_date_results[i].val,
1705 VarFormat_date_results[i].fmt,S_OK,
1706 VarFormat_date_results[i].res);
1709 /* Strings */
1710 bstrin = SysAllocString(szTesting);
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,"\\x@\\x@",S_OK,"xtxesting");
1715 VARFMT(VT_BSTR,V_BSTR,bstrin,"\\x&\\x&",S_OK,"xtxesting");
1716 VARFMT(VT_BSTR,V_BSTR,bstrin,"@\\x",S_OK,"txesting");
1717 VARFMT(VT_BSTR,V_BSTR,bstrin,"@@@@@@@@",S_OK," testing");
1718 VARFMT(VT_BSTR,V_BSTR,bstrin,"@\\x@@@@@@@",S_OK," xtesting");
1719 VARFMT(VT_BSTR,V_BSTR,bstrin,"&&&&&&&&",S_OK,"testing");
1720 VARFMT(VT_BSTR,V_BSTR,bstrin,"!&&&&&&&",S_OK,"testing");
1721 VARFMT(VT_BSTR,V_BSTR,bstrin,"&&&&&&&!",S_OK,"testing");
1722 VARFMT(VT_BSTR,V_BSTR,bstrin,">&&",S_OK,"TESTING");
1723 VARFMT(VT_BSTR,V_BSTR,bstrin,"<&&",S_OK,"testing");
1724 VARFMT(VT_BSTR,V_BSTR,bstrin,"<&>&",S_OK,"testing");
1725 SysFreeString(bstrin);
1726 /* Numeric values are converted to strings then output */
1727 VARFMT(VT_I1,V_I1,1,"<&>&",S_OK,"1");
1729 /* 'out' is not cleared */
1730 out = (BSTR)0x1;
1731 pVarFormat(&in,NULL,fd,fw,flags,&out); /* Would crash if out is cleared */
1732 out = NULL;
1734 /* Invalid args */
1735 hres = pVarFormat(&in,NULL,fd,fw,flags,NULL);
1736 ok(hres == E_INVALIDARG, "Null out: expected E_INVALIDARG, got 0x%08lx\n", hres);
1737 hres = pVarFormat(NULL,NULL,fd,fw,flags,&out);
1738 ok(hres == E_INVALIDARG, "Null in: expected E_INVALIDARG, got 0x%08lx\n", hres);
1739 fd = -1;
1740 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
1741 fd = 8;
1742 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
1743 fd = 0; fw = -1;
1744 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
1745 fw = 4;
1746 VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
1749 static HRESULT (WINAPI *pVarAbs)(LPVARIANT,LPVARIANT);
1751 static const char *szVarAbsFail = "VarAbs: expected 0x0,%d,%d, got 0x%lX,%d,%d\n";
1752 #define VARABS(vt,val,rvt,rval) V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
1753 memset(&vDst,0,sizeof(vDst)); hres = pVarAbs(&v,&vDst); \
1754 ok(hres == S_OK && V_VT(&vDst) == VT_##rvt && V_##rvt(&vDst) == (rval), \
1755 szVarAbsFail, VT_##rvt, (int)(rval), \
1756 hres, V_VT(&vDst), (int)V_##rvt(&vDst))
1758 static void test_VarAbs(void)
1760 static const WCHAR szNum[] = {'-','1','.','1','\0' };
1761 char buff[8];
1762 HRESULT hres;
1763 VARIANT v, vDst;
1764 size_t i;
1766 CHECKPTR(VarAbs);
1768 /* Test all possible V_VT values.
1770 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
1772 VARTYPE vt;
1774 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
1776 HRESULT hExpected = DISP_E_BADVARTYPE;
1778 SKIPTESTS(vt);
1780 memset(&v, 0, sizeof(v));
1781 V_VT(&v) = vt | ExtraFlags[i];
1782 V_VT(&vDst) = VT_EMPTY;
1784 hres = pVarAbs(&v,&vDst);
1785 if (ExtraFlags[i] & (VT_ARRAY|VT_ARRAY) ||
1786 (!ExtraFlags[i] && (vt == VT_UNKNOWN || vt == VT_BSTR ||
1787 vt == VT_DISPATCH || vt == VT_ERROR || vt == VT_RECORD)))
1789 hExpected = DISP_E_TYPEMISMATCH;
1791 else if (ExtraFlags[i] || vt >= VT_CLSID || vt == VT_VARIANT)
1793 hExpected = DISP_E_BADVARTYPE;
1795 else if (IsValidVariantClearVT(vt, ExtraFlags[i]))
1796 hExpected = S_OK;
1798 /* Native always fails on some vartypes that should be valid. don't
1799 * check that Wine does the same; these are bugs in native.
1801 if (vt == VT_I8 || vt == VT_UI8 || vt == VT_INT || vt == VT_UINT ||
1802 vt == VT_I1 || vt == VT_UI2 || vt == VT_UI4)
1803 continue;
1804 ok(hres == hExpected, "VarAbs: expected 0x%lX, got 0x%lX for vt %d | 0x%X\n",
1805 hExpected, hres, vt, ExtraFlags[i]);
1809 /* BOOL->I2, BSTR->R8, all others remain the same */
1810 VARABS(BOOL,VARIANT_TRUE,I2,-VARIANT_TRUE);
1811 VARABS(BOOL,VARIANT_FALSE,I2,VARIANT_FALSE);
1812 VARABS(EMPTY,0,I2,0);
1813 VARABS(EMPTY,1,I2,0);
1814 VARABS(NULL,0,NULL,0);
1815 VARABS(NULL,1,NULL,0);
1816 VARABS(I2,1,I2,1);
1817 VARABS(I2,-1,I2,1);
1818 VARABS(I4,1,I4,1);
1819 VARABS(I4,-1,I4,1);
1820 VARABS(UI1,1,UI1,1);
1821 VARABS(R4,1,R4,1);
1822 VARABS(R4,-1,R4,1);
1823 VARABS(R8,1,R8,1);
1824 VARABS(R8,-1,R8,1);
1825 VARABS(DATE,1,DATE,1);
1826 VARABS(DATE,-1,DATE,1);
1827 V_VT(&v) = VT_CY;
1828 V_CY(&v).int64 = -10000;
1829 memset(&vDst,0,sizeof(vDst));
1830 hres = pVarAbs(&v,&vDst);
1831 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
1832 "VarAbs(CY): expected 0x0 got 0x%lX\n", hres);
1833 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char));
1834 if (buff[0] != '.' || buff[1])
1836 trace("Skipping VarAbs(BSTR) as decimal separator is '%s'\n", buff);
1837 return;
1839 V_VT(&v) = VT_BSTR;
1840 V_BSTR(&v) = (BSTR)szNum;
1841 memset(&vDst,0,sizeof(vDst));
1842 hres = pVarAbs(&v,&vDst);
1843 ok(hres == S_OK && V_VT(&vDst) == VT_R8 && V_R8(&vDst) == 1.1,
1844 "VarAbs: expected 0x0,%d,%g, got 0x%lX,%d,%g\n", VT_R8, 1.1, hres, V_VT(&vDst), V_R8(&vDst));
1847 static HRESULT (WINAPI *pVarNot)(LPVARIANT,LPVARIANT);
1849 static const char *szVarNotFail = "VarNot: expected 0x0,%d,%d, got 0x%lX,%d,%d\n";
1850 #define VARNOT(vt,val,rvt,rval) V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
1851 memset(&vDst,0,sizeof(vDst)); hres = pVarNot(&v,&vDst); \
1852 ok(hres == S_OK && V_VT(&vDst) == VT_##rvt && V_##rvt(&vDst) == (rval), \
1853 szVarNotFail, VT_##rvt, (int)(rval), \
1854 hres, V_VT(&vDst), (int)V_##rvt(&vDst))
1856 static void test_VarNot(void)
1858 static const WCHAR szNum0[] = {'0','\0' };
1859 static const WCHAR szNum1[] = {'1','\0' };
1860 HRESULT hres;
1861 VARIANT v, vDst;
1862 DECIMAL *pdec = &V_DECIMAL(&v);
1863 CY *pcy = &V_CY(&v);
1864 size_t i;
1866 CHECKPTR(VarNot);
1868 /* Test all possible V_VT values */
1869 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
1871 VARTYPE vt;
1873 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
1875 HRESULT hExpected = DISP_E_BADVARTYPE;
1877 SKIPTESTS(vt);
1879 memset(&v, 0, sizeof(v));
1880 V_VT(&v) = vt | ExtraFlags[i];
1881 V_VT(&vDst) = VT_EMPTY;
1883 switch (V_VT(&v))
1885 case VT_I1: case VT_UI1: case VT_I2: case VT_UI2:
1886 case VT_INT: case VT_UINT: case VT_I4: case VT_UI4:
1887 case VT_R4: case VT_R8:
1888 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
1889 case VT_DATE: case VT_CY:
1890 hExpected = S_OK;
1891 break;
1892 case VT_I8: case VT_UI8:
1893 if (HAVE_OLEAUT32_I8)
1894 hExpected = S_OK;
1895 break;
1896 case VT_RECORD:
1897 if (HAVE_OLEAUT32_RECORD)
1898 hExpected = DISP_E_TYPEMISMATCH;
1899 break;
1900 case VT_UNKNOWN: case VT_BSTR: case VT_DISPATCH: case VT_ERROR:
1901 hExpected = DISP_E_TYPEMISMATCH;
1902 break;
1903 default:
1904 if (IsValidVariantClearVT(vt, ExtraFlags[i]) && vt != VT_CLSID)
1905 hExpected = DISP_E_TYPEMISMATCH;
1906 break;
1909 hres = pVarNot(&v,&vDst);
1910 ok(hres == hExpected, "VarNot: expected 0x%lX, got 0x%lX vt %d|0x%X\n",
1911 hExpected, hres, vt, ExtraFlags[i]);
1914 /* Test the values returned by all cases that can succeed */
1915 VARNOT(EMPTY,0,I2,-1);
1916 VARNOT(EMPTY,1,I2,-1);
1917 VARNOT(NULL,0,NULL,0);
1918 VARNOT(NULL,1,NULL,0);
1919 VARNOT(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
1920 VARNOT(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
1921 VARNOT(I1,-1,I4,0);
1922 VARNOT(I1,0,I4,-1);
1923 VARNOT(I2,-1,I2,0);
1924 VARNOT(I2,0,I2,-1);
1925 VARNOT(I2,1,I2,-2);
1926 VARNOT(I4,1,I4,-2);
1927 VARNOT(I4,0,I4,-1);
1928 VARNOT(UI1,1,UI1,254);
1929 VARNOT(UI1,0,UI1,255);
1930 VARNOT(UI2,0,I4,-1);
1931 VARNOT(UI2,1,I4,-2);
1932 VARNOT(UI4,0,I4,-1);
1933 VARNOT(UI4,1,I4,-2);
1934 VARNOT(INT,0,I4,-1);
1935 VARNOT(INT,1,I4,-2);
1936 VARNOT(UINT,0,I4,-1);
1937 VARNOT(UINT,1,I4,-2);
1938 if (HAVE_OLEAUT32_I8)
1940 VARNOT(I8,1,I8,-2);
1941 VARNOT(I8,0,I8,-1);
1942 VARNOT(UI8,0,I4,-1);
1943 VARNOT(UI8,1,I4,-2);
1945 VARNOT(R4,1,I4,-2);
1946 VARNOT(R4,0,I4,-1);
1947 VARNOT(R8,1,I4,-2);
1948 VARNOT(R8,0,I4,-1);
1949 VARNOT(DATE,1,I4,-2);
1950 VARNOT(DATE,0,I4,-1);
1951 VARNOT(BSTR,(BSTR)szNum0,I4,-1);
1952 ok(V_VT(&v) == VT_BSTR && V_BSTR(&v) == szNum0, "VarNot(0): changed input\n");
1953 VARNOT(BSTR,(BSTR)szNum1,I4,-2);
1954 ok(V_VT(&v) == VT_BSTR && V_BSTR(&v) == szNum1, "VarNot(1): changed input\n");
1956 V_VT(&v) = VT_DECIMAL;
1957 S(U(*pdec)).sign = DECIMAL_NEG;
1958 S(U(*pdec)).scale = 0;
1959 pdec->Hi32 = 0;
1960 S1(U1(*pdec)).Mid32 = 0;
1961 S1(U1(*pdec)).Lo32 = 1;
1962 VARNOT(DECIMAL,*pdec,I4,0);
1964 pcy->int64 = 10000;
1965 VARNOT(CY,*pcy,I4,-2);
1967 pcy->int64 = 0;
1968 VARNOT(CY,*pcy,I4,-1);
1970 pcy->int64 = -1;
1971 VARNOT(CY,*pcy,I4,-1);
1973 static HRESULT (WINAPI *pVarSub)(LPVARIANT,LPVARIANT,LPVARIANT);
1975 static void test_VarSub(void)
1977 VARIANT va, vb, vc;
1978 HRESULT hr;
1980 CHECKPTR(VarSub);
1982 V_VT(&va) = VT_DATE;
1983 V_DATE(&va) = 200000.0;
1984 V_VT(&vb) = VT_DATE;
1985 V_DATE(&vb) = 100000.0;
1987 hr = pVarSub(&va, &vb, &vc);
1988 ok(hr == S_OK,"VarSub of VT_DATE - VT_DATE failed with %lx\n", hr);
1989 ok(V_VT(&vc) == VT_R8,"VarSub of VT_DATE - VT_DATE returned vt 0x%x\n", V_VT(&vc));
1990 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));
1991 /* fprintf(stderr,"VarSub of 10000-20000 returned: %g\n", V_R8(&vc)); */
1994 static const char *szVarModFail = "VarMod: expected 0x%lx,%d(%s),%d, got 0x%lX,%d(%s),%d\n";
1995 #define VARMOD(vt1,vt2,val1,val2,rvt,rval,hexpected) V_VT(&v1) = VT_##vt1; V_##vt1(&v1) = val1; \
1996 V_VT(&v2) = VT_##vt2; V_##vt2(&v2) = val2; \
1997 memset(&vDst,0,sizeof(vDst)); hres = pVarMod(&v1,&v2,&vDst); \
1998 ok(hres == hexpected && V_VT(&vDst) == VT_##rvt && V_##rvt(&vDst) == (rval), \
1999 szVarModFail, hexpected, VT_##rvt, vtstr(VT_##rvt), (int)(rval), \
2000 hres, V_VT(&vDst), vtstr(V_VT(&vDst)), (int)V_##rvt(&vDst))
2002 static const char *szVarMod2Fail = "VarMod: expected 0x%lx,%d(%s),%d, got 0x%lX,%d(%s),%d\n";
2003 #define VARMOD2(vt1,vt2,val1,val2,rvt,rval,hexpected) V_VT(&v1) = VT_##vt1; V_I4(&v1) = val1; \
2004 V_VT(&v2) = VT_##vt2; V_I4(&v2) = val2; \
2005 memset(&vDst,0,sizeof(vDst)); hres = pVarMod(&v1,&v2,&vDst); \
2006 ok(hres == hexpected && V_VT(&vDst) == VT_##rvt && V_I4(&vDst) == (rval), \
2007 szVarMod2Fail, hexpected, VT_##rvt, vtstr(VT_##rvt), (int)(rval), \
2008 hres, V_VT(&vDst), vtstr(V_VT(&vDst)), (int)V_I4(&vDst))
2010 static HRESULT (WINAPI *pVarMod)(LPVARIANT,LPVARIANT,LPVARIANT);
2012 static void test_VarMod(void)
2014 VARIANT v1, v2, vDst;
2015 HRESULT hres;
2016 HRESULT hexpected = 0;
2017 static const WCHAR szNum0[] = {'1','2','5','\0'};
2018 static const WCHAR szNum1[] = {'1','0','\0'};
2019 int l, r;
2020 BOOL lFound, rFound;
2021 BOOL lValid, rValid;
2022 BSTR strNum0, strNum1;
2024 CHECKPTR(VarMod);
2026 VARMOD(I1,BOOL,100,10,I4,0,S_OK);
2027 VARMOD(I1,I1,100,10,I4,0,S_OK);
2028 VARMOD(I1,UI1,100,10,I4,0,S_OK);
2029 VARMOD(I1,I2,100,10,I4,0,S_OK);
2030 VARMOD(I1,UI2,100,10,I4,0,S_OK);
2031 VARMOD(I1,I4,100,10,I4,0,S_OK);
2032 VARMOD(I1,UI4,100,10,I4,0,S_OK);
2033 VARMOD(I1,R4,100,10,I4,0,S_OK);
2034 VARMOD(I1,R8,100,10,I4,0,S_OK);
2036 VARMOD(UI1,BOOL,100,10,I2,0,S_OK);
2037 VARMOD(UI1,I1,100,10,I4,0,S_OK);
2038 VARMOD(UI1,UI1,100,10,UI1,0,S_OK);
2039 VARMOD(UI1,I2,100,10,I2,0,S_OK);
2040 VARMOD(UI1,UI2,100,10,I4,0,S_OK);
2041 VARMOD(UI1,I4,100,10,I4,0,S_OK);
2042 VARMOD(UI1,UI4,100,10,I4,0,S_OK);
2043 VARMOD(UI1,R4,100,10,I4,0,S_OK);
2044 VARMOD(UI1,R8,100,10,I4,0,S_OK);
2046 VARMOD(I2,BOOL,100,10,I2,0,S_OK);
2047 VARMOD(I2,I1,100,10,I4,0,S_OK);
2048 VARMOD(I2,UI1,100,10,I2,0,S_OK);
2049 VARMOD(I2,I2,100,10,I2,0,S_OK);
2050 VARMOD(I2,UI2,100,10,I4,0,S_OK);
2051 VARMOD(I2,I4,100,10,I4,0,S_OK);
2052 VARMOD(I2,UI4,100,10,I4,0,S_OK);
2053 VARMOD(I2,R4,100,10,I4,0,S_OK);
2054 VARMOD(I2,R8,100,10,I4,0,S_OK);
2056 VARMOD(I4,BOOL,100,10,I4,0,S_OK);
2057 VARMOD(I4,I1,100,10,I4,0,S_OK);
2058 VARMOD(I4,UI1,100,10,I4,0,S_OK);
2059 VARMOD(I4,I2,100,10,I4,0,S_OK);
2060 VARMOD(I4,UI2,100,10,I4,0,S_OK);
2061 VARMOD(I4,I4,100,10,I4,0,S_OK);
2062 VARMOD(I4,UI4,100,10,I4,0,S_OK);
2063 VARMOD(I4,R4,100,10,I4,0,S_OK);
2064 VARMOD(I4,R8,100,10,I4,0,S_OK);
2065 VARMOD(UI4,BOOL,100,10,I4,0,S_OK);
2066 VARMOD(UI4,I1,100,10,I4,0,S_OK);
2067 VARMOD(UI4,UI1,100,10,I4,0,S_OK);
2068 VARMOD(UI4,I2,100,10,I4,0,S_OK);
2069 VARMOD(UI4,UI2,100,10,I4,0,S_OK);
2070 VARMOD(UI4,I4,100,10,I4,0,S_OK);
2071 VARMOD(UI4,UI4,100,10,I4,0,S_OK);
2072 VARMOD(UI4,R4,100,10,I4,0,S_OK);
2073 VARMOD(UI4,R8,100,10,I4,0,S_OK);
2074 VARMOD(R4,BOOL,100,10,I4,0,S_OK);
2075 VARMOD(R4,I1,100,10,I4,0,S_OK);
2076 VARMOD(R4,UI1,100,10,I4,0,S_OK);
2077 VARMOD(R4,I2,100,10,I4,0,S_OK);
2078 VARMOD(R4,UI2,100,10,I4,0,S_OK);
2079 VARMOD(R4,I4,100,10,I4,0,S_OK);
2080 VARMOD(R4,UI4,100,10,I4,0,S_OK);
2081 VARMOD(R4,R4,100,10,I4,0,S_OK);
2082 VARMOD(R4,R8,100,10,I4,0,S_OK);
2083 VARMOD(R8,BOOL,100,10,I4,0,S_OK);
2084 VARMOD(R8,I1,100,10,I4,0,S_OK);
2085 VARMOD(R8,UI1,100,10,I4,0,S_OK);
2086 VARMOD(R8,I2,100,10,I4,0,S_OK);
2087 VARMOD(R8,UI2,100,10,I4,0,S_OK);
2088 VARMOD(R8,I4,100,10,I4,0,S_OK);
2089 VARMOD(R8,UI4,100,10,I4,0,S_OK);
2090 VARMOD(R8,R4,100,10,I4,0,S_OK);
2091 VARMOD(R8,R8,100,10,I4,0,S_OK);
2093 VARMOD(INT,INT,100,10,I4,0,S_OK);
2094 VARMOD(INT,UINT,100,10,I4,0,S_OK);
2096 VARMOD(BOOL,BOOL,100,10,I2,0,S_OK);
2097 VARMOD(BOOL,I1,100,10,I4,0,S_OK);
2098 VARMOD(BOOL,UI1,100,10,I2,0,S_OK);
2099 VARMOD(BOOL,I2,100,10,I2,0,S_OK);
2100 VARMOD(BOOL,UI2,100,10,I4,0,S_OK);
2101 VARMOD(BOOL,I4,100,10,I4,0,S_OK);
2102 VARMOD(BOOL,UI4,100,10,I4,0,S_OK);
2103 VARMOD(BOOL,R4,100,10,I4,0,S_OK);
2104 VARMOD(BOOL,R8,100,10,I4,0,S_OK);
2105 VARMOD(BOOL,DATE,100,10,I4,0,S_OK);
2107 VARMOD(DATE,BOOL,100,10,I4,0,S_OK);
2108 VARMOD(DATE,I1,100,10,I4,0,S_OK);
2109 VARMOD(DATE,UI1,100,10,I4,0,S_OK);
2110 VARMOD(DATE,I2,100,10,I4,0,S_OK);
2111 VARMOD(DATE,UI2,100,10,I4,0,S_OK);
2112 VARMOD(DATE,I4,100,10,I4,0,S_OK);
2113 VARMOD(DATE,UI4,100,10,I4,0,S_OK);
2114 VARMOD(DATE,R4,100,10,I4,0,S_OK);
2115 VARMOD(DATE,R8,100,10,I4,0,S_OK);
2116 VARMOD(DATE,DATE,100,10,I4,0,S_OK);
2118 strNum0 = SysAllocString(szNum0);
2119 strNum1 = SysAllocString(szNum1);
2120 VARMOD(BSTR,BSTR,strNum0,strNum1,I4,5,S_OK);
2121 VARMOD(BSTR,I1,strNum0,10,I4,5,S_OK);
2122 VARMOD(BSTR,I2,strNum0,10,I4,5,S_OK);
2123 VARMOD(BSTR,I4,strNum0,10,I4,5,S_OK);
2124 VARMOD(BSTR,R4,strNum0,10,I4,5,S_OK);
2125 VARMOD(BSTR,R8,strNum0,10,I4,5,S_OK);
2126 VARMOD(I4,BSTR,125,strNum1,I4,5,S_OK);
2128 if (HAVE_OLEAUT32_I8)
2130 VARMOD(BOOL,I8,100,10,I8,0,S_OK);
2131 VARMOD(I1,I8,100,10,I8,0,S_OK);
2132 VARMOD(UI1,I8,100,10,I8,0,S_OK);
2133 VARMOD(I2,I8,100,10,I8,0,S_OK);
2134 VARMOD(I4,I8,100,10,I8,0,S_OK);
2135 VARMOD(UI4,I8,100,10,I8,0,S_OK);
2136 VARMOD(R4,I8,100,10,I8,0,S_OK);
2137 VARMOD(R8,I8,100,10,I8,0,S_OK);
2138 VARMOD(DATE,I8,100,10,I8,0,S_OK);
2140 VARMOD(I8,BOOL,100,10,I8,0,S_OK);
2141 VARMOD(I8,I1,100,10,I8,0,S_OK);
2142 VARMOD(I8,UI1,100,10,I8,0,S_OK);
2143 VARMOD(I8,I2,100,10,I8,0,S_OK);
2144 VARMOD(I8,UI2,100,10,I8,0,S_OK);
2145 VARMOD(I8,I4,100,10,I8,0,S_OK);
2146 VARMOD(I8,UI4,100,10,I8,0,S_OK);
2147 VARMOD(I8,R4,100,10,I8,0,S_OK);
2148 VARMOD(I8,R8,100,10,I8,0,S_OK);
2149 VARMOD(I8,I8,100,10,I8,0,S_OK);
2151 VARMOD(BSTR,I8,strNum0,10,I8,5,S_OK);
2154 /* test all combinations of types */
2155 for(l = 0; l < VT_BSTR_BLOB; l++)
2157 SKIPTESTS(l);
2159 for(r = 0; r < VT_BSTR_BLOB; r++)
2161 SKIPTESTS(r);
2163 if(l == VT_BSTR) continue;
2164 if(l == VT_DISPATCH) continue;
2165 if(r == VT_BSTR) continue;
2166 if(r == VT_DISPATCH) continue;
2168 lFound = TRUE;
2169 lValid = TRUE;
2170 switch(l)
2172 case VT_EMPTY:
2173 case VT_NULL:
2174 case VT_I1:
2175 case VT_UI1:
2176 case VT_I2:
2177 case VT_UI2:
2178 case VT_I4:
2179 case VT_I8:
2180 case VT_UI4:
2181 case VT_UI8:
2182 case VT_INT:
2183 case VT_UINT:
2184 case VT_R4:
2185 case VT_R8:
2186 case VT_BOOL:
2187 case VT_DATE:
2188 case VT_CY:
2189 hexpected = S_OK;
2190 break;
2191 case VT_ERROR:
2192 case VT_VARIANT:
2193 case VT_UNKNOWN:
2194 case VT_DECIMAL:
2195 case VT_RECORD:
2196 lValid = FALSE;
2197 break;
2198 default:
2199 lFound = FALSE;
2200 hexpected = DISP_E_BADVARTYPE;
2201 break;
2204 rFound = TRUE;
2205 rValid = TRUE;
2206 switch(r)
2208 case VT_EMPTY:
2209 case VT_NULL:
2210 case VT_I1:
2211 case VT_UI1:
2212 case VT_I2:
2213 case VT_UI2:
2214 case VT_I4:
2215 case VT_I8:
2216 case VT_UI4:
2217 case VT_UI8:
2218 case VT_INT:
2219 case VT_UINT:
2220 case VT_R4:
2221 case VT_R8:
2222 case VT_BOOL:
2223 case VT_DATE:
2224 case VT_CY:
2225 hexpected = S_OK;
2226 break;
2227 case VT_ERROR:
2228 case VT_VARIANT:
2229 case VT_UNKNOWN:
2230 case VT_DECIMAL:
2231 case VT_RECORD:
2232 rValid = FALSE;
2233 break;
2234 default:
2235 rFound = FALSE;
2236 break;
2239 if(((l == VT_I8) && (r == VT_INT)) || ((l == VT_INT) && (r == VT_I8)))
2241 hexpected = DISP_E_TYPEMISMATCH;
2242 } else if((l == VT_EMPTY) && (r == VT_NULL))
2244 hexpected = S_OK;
2245 } else if((l == VT_NULL) && (r == VT_EMPTY))
2247 hexpected = S_OK;
2248 } else if((l == VT_EMPTY) && (r == VT_CY))
2250 hexpected = S_OK;
2251 } else if((l == VT_EMPTY) && (r == VT_RECORD))
2253 hexpected = DISP_E_TYPEMISMATCH;
2254 } else if((r == VT_EMPTY) && lFound && lValid)
2256 hexpected = DISP_E_DIVBYZERO;
2257 } else if((l == VT_ERROR) || ((r == VT_ERROR) && lFound && lValid))
2259 hexpected = DISP_E_TYPEMISMATCH;
2260 } else if((l == VT_NULL) && (r == VT_NULL))
2262 hexpected = S_OK;
2263 } else if((l == VT_VARIANT) || ((r == VT_VARIANT) && lFound && lValid))
2265 hexpected = DISP_E_TYPEMISMATCH;
2266 } else if((l == VT_NULL) && (r == VT_RECORD))
2268 hexpected = DISP_E_TYPEMISMATCH;
2269 } else if((l == VT_NULL) && (r == VT_DECIMAL))
2271 hexpected = DISP_E_OVERFLOW;
2272 } else if((l == VT_UNKNOWN) || ((r == VT_UNKNOWN) && lFound && lValid))
2274 hexpected = DISP_E_TYPEMISMATCH;
2275 } else if((l == VT_NULL) && rFound)
2277 hexpected = S_OK;
2278 } else if((l == VT_DECIMAL) || ((r == VT_DECIMAL) && lFound && lValid))
2280 hexpected = DISP_E_OVERFLOW;
2281 } else if(l == VT_RECORD)
2283 hexpected = DISP_E_TYPEMISMATCH;
2284 } else if((r == VT_RECORD) && lValid && lFound)
2286 hexpected = DISP_E_TYPEMISMATCH;
2287 } else if((l == VT_EMPTY) && (r == VT_EMPTY))
2289 hexpected = DISP_E_DIVBYZERO;
2290 } else if((l == VT_CY) && !rFound)
2292 hexpected = DISP_E_BADVARTYPE;
2293 } else if(lFound && !rFound)
2295 hexpected = DISP_E_BADVARTYPE;
2296 } else if(!lFound && rFound)
2298 hexpected = DISP_E_BADVARTYPE;
2299 } else if((r == VT_NULL) && lFound && lValid)
2301 hexpected = S_OK;
2302 } else if((l == VT_NULL) || (r == VT_NULL))
2304 hexpected = DISP_E_BADVARTYPE;
2305 } else if((l == VT_VARIANT) || (r == VT_VARIANT))
2307 hexpected = DISP_E_BADVARTYPE;
2308 } else if(lFound && !rFound)
2310 hexpected = DISP_E_BADVARTYPE;
2311 } else if(!lFound && !rFound)
2313 hexpected = DISP_E_BADVARTYPE;
2316 V_VT(&v1) = l;
2317 V_VT(&v2) = r;
2319 if(l == VT_CY)
2320 V_CY(&v1).int64 = 1000000;
2321 else if(l == VT_R4)
2322 V_R4(&v1) = 100;
2323 else if(l == VT_R8)
2324 V_R8(&v1) = 100;
2325 else if(l == VT_UI8)
2326 V_UI8(&v1) = 100;
2327 else if(l == VT_DATE)
2328 V_DATE(&v1) = 1000;
2329 else
2330 V_I4(&v1) = 10000;
2332 if(r == VT_CY)
2333 V_CY(&v2).int64 = 10000;
2334 else if(r == VT_R4)
2335 V_R4(&v2) = 100;
2336 else if(r == VT_R8)
2337 V_R8(&v2) = 100;
2338 else if(r == VT_UI8)
2339 V_UI8(&v2) = 100;
2340 else if(r == VT_DATE)
2341 V_DATE(&v2) = 1000;
2342 else
2343 V_I4(&v2) = 10000;
2345 if ((l != VT_I8 && l != VT_UI8 && r != VT_I8 && r != VT_UI8) || HAVE_OLEAUT32_I8)
2347 hres = pVarMod(&v1,&v2,&vDst);
2348 ok(hres == hexpected,
2349 "VarMod: expected 0x%lx, got 0x%lX for l type of %d, r type of %d,\n", hexpected, hres, l, r);
2355 /****************************/
2356 /* test some bad parameters */
2357 VARMOD(I4,I4,-1,-1,I4,0,S_OK);
2359 /* test modulus with zero */
2360 VARMOD2(I4,I4,100,0,EMPTY,0,DISP_E_DIVBYZERO);
2362 VARMOD(I4,I4,0,10,I4,0,S_OK); /* test 0 mod 10 */
2364 /* right parameter is type empty */
2365 VARMOD2(I4,EMPTY,100,10,EMPTY,0,DISP_E_DIVBYZERO);
2367 /* left parameter is type empty */
2368 VARMOD2(EMPTY,I4,100,10,I4,0,S_OK);
2370 /* mod with a null left value */
2371 VARMOD2(NULL,I4,125,10,NULL,0,S_OK);
2373 /* mod with a null right value */
2374 VARMOD2(I4,NULL,100,10,NULL,0,S_OK);
2376 /* void left value */
2377 VARMOD2(VOID,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2379 /* void right value */
2380 VARMOD2(I4,VOID,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2382 /* null left value, void right value */
2383 VARMOD2(NULL,VOID,100,10,EMPTY, 0, DISP_E_BADVARTYPE);
2385 /* void left value, null right value */
2386 VARMOD2(VOID,NULL,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2388 /* some currencies */
2389 V_VT(&v1) = VT_CY;
2390 V_VT(&v2) = VT_CY;
2391 V_CY(&v1).int64 = 100000;
2392 V_CY(&v2).int64 = 100000;
2393 hres = pVarMod(&v1,&v2,&vDst);
2394 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
2395 "VarMod: expected 0x%lx,%d,%d, got 0x%lX,%d,%ld\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
2397 V_VT(&v1) = VT_I4;
2398 V_VT(&v2) = VT_CY;
2399 V_I4(&v1) = 100;
2400 V_CY(&v2).int64 = 100000;
2401 hres = pVarMod(&v1,&v2,&vDst);
2402 ok(hres == S_OK && V_VT(&vDst) == VT_I4 && V_I4(&vDst) == 0,
2403 "VarMod: expected 0x%lx,%d,%d, got 0x%lX,%d,%ld\n", S_OK, VT_I4, 0, hres, V_VT(&vDst), V_I4(&vDst));
2405 VARMOD2(UINT,I4,100,10,I4,0,S_OK);
2407 /* test that an error results in the type of the result changing but not its value */
2408 V_VT(&v1) = VT_UNKNOWN;
2409 V_VT(&v2) = VT_EMPTY;
2410 V_I4(&v1) = 100;
2411 V_CY(&v2).int64 = 100000;
2412 V_VT(&vDst) = VT_I4;
2413 V_I4(&vDst) = 1231;
2414 hres = pVarMod(&v1,&v2,&vDst);
2415 ok(hres == DISP_E_TYPEMISMATCH && V_VT(&vDst) == VT_EMPTY && V_I4(&vDst) == 1231,
2416 "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));
2419 /* test some invalid types */
2420 /*TODO: not testing VT_DISPATCH */
2421 if (HAVE_OLEAUT32_I8)
2423 VARMOD2(I8,INT,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
2425 VARMOD2(ERROR,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
2426 VARMOD2(VARIANT,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
2427 VARMOD2(UNKNOWN,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
2428 VARMOD2(DECIMAL,I4,100,10,EMPTY,0,DISP_E_OVERFLOW);
2429 VARMOD2(VOID,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2430 VARMOD2(HRESULT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2431 VARMOD2(PTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2432 VARMOD2(SAFEARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2433 VARMOD2(CARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2434 VARMOD2(USERDEFINED,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2435 VARMOD2(LPSTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2436 VARMOD2(LPWSTR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2437 VARMOD2(RECORD,I4,100,10,EMPTY,0,DISP_E_TYPEMISMATCH);
2438 VARMOD2(FILETIME,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2439 VARMOD2(BLOB,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2440 VARMOD2(STREAM,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2441 VARMOD2(STORAGE,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2442 VARMOD2(STREAMED_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2443 VARMOD2(STORED_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2444 VARMOD2(BLOB_OBJECT,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2445 VARMOD2(CF,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2446 VARMOD2(CLSID,CLSID,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2447 VARMOD2(VECTOR,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2448 VARMOD2(ARRAY,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2449 VARMOD2(BYREF,I4,100,10,EMPTY,0,DISP_E_BADVARTYPE);
2451 /* test some more invalid types */
2452 V_VT(&v1) = 456;
2453 V_VT(&v2) = 234;
2454 V_I4(&v1) = 100;
2455 V_I4(&v2)= 10;
2456 hres = pVarMod(&v1,&v2,&vDst);
2457 ok(hres == DISP_E_BADVARTYPE && V_VT(&vDst) == VT_EMPTY && V_I4(&vDst) == 0,
2458 "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));
2461 static HRESULT (WINAPI *pVarFix)(LPVARIANT,LPVARIANT);
2463 static const char *szVarFixFail = "VarFix: expected 0x0,%d,%d, got 0x%lX,%d,%d\n";
2464 #define VARFIX(vt,val,rvt,rval) V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
2465 memset(&vDst,0,sizeof(vDst)); hres = pVarFix(&v,&vDst); \
2466 ok(hres == S_OK && V_VT(&vDst) == VT_##rvt && V_##rvt(&vDst) == (rval), \
2467 szVarFixFail, VT_##rvt, (int)(rval), \
2468 hres, V_VT(&vDst), (int)V_##rvt(&vDst))
2470 static void test_VarFix(void)
2472 static const WCHAR szNumMinus1[] = {'-','1','\0' };
2473 HRESULT hres;
2474 VARIANT v, vDst;
2475 DECIMAL *pdec = &V_DECIMAL(&v);
2476 CY *pcy = &V_CY(&v);
2477 size_t i;
2479 CHECKPTR(VarFix);
2481 /* Test all possible V_VT values */
2482 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2484 VARTYPE vt;
2486 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2488 HRESULT bFail = TRUE;
2490 SKIPTESTS(vt);
2492 memset(&v, 0, sizeof(v));
2493 V_VT(&v) = vt | ExtraFlags[i];
2494 V_VT(&vDst) = VT_EMPTY;
2496 switch (V_VT(&v))
2498 case VT_UI1: case VT_I2: case VT_I4: case VT_R4: case VT_R8:
2499 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
2500 case VT_DATE: case VT_CY:
2501 bFail = FALSE;
2502 break;
2503 case VT_I8:
2504 if (HAVE_OLEAUT32_I8)
2505 bFail = FALSE;
2506 break;
2509 hres = pVarFix(&v,&vDst);
2510 if (bFail)
2511 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
2512 "VarFix: expected failure, got 0x%lX vt %d|0x%X\n",
2513 hres, vt, ExtraFlags[i]);
2514 else
2515 ok(hres == S_OK, "VarFix: expected S_OK, got 0x%lX vt %d|0x%X\n",
2516 hres, vt, ExtraFlags[i]);
2520 VARFIX(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE);
2521 VARFIX(BOOL,VARIANT_FALSE,I2,0);
2522 VARFIX(BOOL,1,I2,1);
2523 VARFIX(UI1,1,UI1,1);
2524 VARFIX(I2,-1,I2,-1);
2525 VARFIX(I4,-1,I4,-1);
2526 if (HAVE_OLEAUT32_I8)
2528 VARFIX(I8,-1,I8,-1);
2530 VARFIX(R4,1.4,R4,1);
2531 VARFIX(R4,1.5,R4,1);
2532 VARFIX(R4,1.6,R4,1);
2533 VARFIX(R4,-1.4,R4,-1);
2534 VARFIX(R4,-1.5,R4,-1);
2535 VARFIX(R4,-1.6,R4,-1);
2536 /* DATE & R8 round as for R4 */
2537 VARFIX(DATE,-1,DATE,-1);
2538 VARFIX(R8,-1,R8,-1);
2539 VARFIX(BSTR,(BSTR)szNumMinus1,R8,-1);
2541 V_VT(&v) = VT_EMPTY;
2542 hres = pVarFix(&v,&vDst);
2543 ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
2544 "VarFix: expected 0x0,%d,0 got 0x%lX,%d,%d\n", VT_EMPTY,
2545 hres, V_VT(&vDst), V_I2(&vDst));
2547 V_VT(&v) = VT_NULL;
2548 hres = pVarFix(&v,&vDst);
2549 ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
2550 "VarFix: expected 0x0,%d got 0x%lX,%d\n", VT_NULL, hres, V_VT(&vDst));
2552 V_VT(&v) = VT_DECIMAL;
2553 S(U(*pdec)).sign = DECIMAL_NEG;
2554 S(U(*pdec)).scale = 0;
2555 pdec->Hi32 = 0;
2556 S1(U1(*pdec)).Mid32 = 0;
2557 S1(U1(*pdec)).Lo32 = 1;
2558 hres = pVarFix(&v,&vDst);
2559 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && !memcmp(&v, &vDst, sizeof(v)),
2560 "VarFix: expected 0x0,%d,identical, got 0x%lX,%d\n", VT_DECIMAL,
2561 hres, V_VT(&vDst));
2563 /* FIXME: Test some fractional decimals when VarDecFix is implemented */
2565 V_VT(&v) = VT_CY;
2566 pcy->int64 = -10000;
2567 hres = pVarFix(&v,&vDst);
2568 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
2569 "VarFix: VT_CY wrong, hres=0x%lX\n", hres);
2571 V_VT(&v) = VT_CY;
2572 pcy->int64 = -16000;
2573 hres = pVarFix(&v,&vDst);
2574 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
2575 "VarFix: VT_CY wrong, hres=0x%lX\n", hres);
2578 static HRESULT (WINAPI *pVarInt)(LPVARIANT,LPVARIANT);
2580 static const char *szVarIntFail = "VarInt: expected 0x0,%d,%d, got 0x%lX,%d,%d\n";
2581 #define VARINT(vt,val,rvt,rval) V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
2582 memset(&vDst,0,sizeof(vDst)); hres = pVarInt(&v,&vDst); \
2583 ok(hres == S_OK && V_VT(&vDst) == VT_##rvt && V_##rvt(&vDst) == (rval), \
2584 szVarIntFail, VT_##rvt, (int)(rval), \
2585 hres, V_VT(&vDst), (int)V_##rvt(&vDst))
2587 static void test_VarInt(void)
2589 static const WCHAR szNumMinus1[] = {'-','1','\0' };
2590 HRESULT hres;
2591 VARIANT v, vDst;
2592 DECIMAL *pdec = &V_DECIMAL(&v);
2593 CY *pcy = &V_CY(&v);
2594 size_t i;
2596 CHECKPTR(VarInt);
2598 /* Test all possible V_VT values */
2599 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2601 VARTYPE vt;
2603 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2605 HRESULT bFail = TRUE;
2607 SKIPTESTS(vt);
2609 memset(&v, 0, sizeof(v));
2610 V_VT(&v) = vt | ExtraFlags[i];
2611 V_VT(&vDst) = VT_EMPTY;
2613 switch (V_VT(&v))
2615 case VT_UI1: case VT_I2: case VT_I4: case VT_R4: case VT_R8:
2616 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
2617 case VT_DATE: case VT_CY:
2618 bFail = FALSE;
2619 break;
2620 case VT_I8:
2621 if (HAVE_OLEAUT32_I8)
2622 bFail = FALSE;
2623 break;
2626 hres = pVarInt(&v,&vDst);
2627 if (bFail)
2628 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
2629 "VarInt: expected failure, got 0x%lX vt %d|0x%X\n",
2630 hres, vt, ExtraFlags[i]);
2631 else
2632 ok(hres == S_OK, "VarInt: expected S_OK, got 0x%lX vt %d|0x%X\n",
2633 hres, vt, ExtraFlags[i]);
2637 VARINT(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE);
2638 VARINT(BOOL,VARIANT_FALSE,I2,0);
2639 VARINT(BOOL,1,I2,1);
2640 VARINT(UI1,1,UI1,1);
2641 VARINT(I2,-1,I2,-1);
2642 VARINT(I4,-1,I4,-1);
2643 if (HAVE_OLEAUT32_I8)
2645 VARINT(I8,-1,I8,-1);
2647 VARINT(R4,1.4,R4,1);
2648 VARINT(R4,1.5,R4,1);
2649 VARINT(R4,1.6,R4,1);
2650 VARINT(R4,-1.4,R4,-2); /* Note these 3 are different from VarFix */
2651 VARINT(R4,-1.5,R4,-2);
2652 VARINT(R4,-1.6,R4,-2);
2653 /* DATE & R8 round as for R4 */
2654 VARINT(DATE,-1,DATE,-1);
2655 VARINT(R8,-1,R8,-1);
2656 VARINT(BSTR,(BSTR)szNumMinus1,R8,-1);
2658 V_VT(&v) = VT_EMPTY;
2659 hres = pVarInt(&v,&vDst);
2660 ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
2661 "VarInt: expected 0x0,%d,0 got 0x%lX,%d,%d\n", VT_EMPTY,
2662 hres, V_VT(&vDst), V_I2(&vDst));
2664 V_VT(&v) = VT_NULL;
2665 hres = pVarInt(&v,&vDst);
2666 ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
2667 "VarInt: expected 0x0,%d got 0x%lX,%d\n", VT_NULL, hres, V_VT(&vDst));
2669 V_VT(&v) = VT_DECIMAL;
2670 S(U(*pdec)).sign = DECIMAL_NEG;
2671 S(U(*pdec)).scale = 0;
2672 pdec->Hi32 = 0;
2673 S1(U1(*pdec)).Mid32 = 0;
2674 S1(U1(*pdec)).Lo32 = 1;
2675 hres = pVarInt(&v,&vDst);
2676 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL && !memcmp(&v, &vDst, sizeof(v)),
2677 "VarInt: expected 0x0,%d,identical, got 0x%lX,%d\n", VT_DECIMAL,
2678 hres, V_VT(&vDst));
2680 /* FIXME: Test some fractional decimals when VarDecInt is implemented */
2682 V_VT(&v) = VT_CY;
2683 pcy->int64 = -10000;
2684 hres = pVarInt(&v,&vDst);
2685 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -10000,
2686 "VarInt: VT_CY wrong, hres=0x%lX\n", hres);
2688 V_VT(&v) = VT_CY;
2689 pcy->int64 = -11000;
2690 hres = pVarInt(&v,&vDst);
2691 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == -20000,
2692 "VarInt: VT_CY wrong, hres=0x%lX %lld\n", hres,V_CY(&vDst).int64);
2695 static HRESULT (WINAPI *pVarNeg)(LPVARIANT,LPVARIANT);
2697 static const char *szVarNegFail = "VarNeg: expected 0x0,%d,%d, got 0x%lX,%d,%d\n";
2698 #define VARNEG(vt,val,rvt,rval) V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
2699 memset(&vDst,0,sizeof(vDst)); hres = pVarNeg(&v,&vDst); \
2700 ok(hres == S_OK && V_VT(&vDst) == VT_##rvt && V_##rvt(&vDst) == (rval), \
2701 szVarNegFail, VT_##rvt, (int)(rval), \
2702 hres, V_VT(&vDst), (int)V_##rvt(&vDst))
2704 static void test_VarNeg(void)
2706 static const WCHAR szNumMinus1[] = {'-','1','\0' };
2707 static const WCHAR szNum1[] = {'1','\0' };
2708 HRESULT hres;
2709 VARIANT v, vDst;
2710 DECIMAL *pdec = &V_DECIMAL(&v);
2711 CY *pcy = &V_CY(&v);
2712 size_t i;
2714 CHECKPTR(VarNeg);
2716 /* Test all possible V_VT values. But don't test the exact return values
2717 * except for success/failure, since M$ made a hash of them in the
2718 * native version. This at least ensures (as with all tests here) that
2719 * we will notice if/when new vtypes/flags are added in native.
2721 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2723 VARTYPE vt;
2725 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2727 HRESULT bFail = TRUE;
2729 SKIPTESTS(vt);
2731 memset(&v, 0, sizeof(v));
2732 V_VT(&v) = vt | ExtraFlags[i];
2733 V_VT(&vDst) = VT_EMPTY;
2735 switch (V_VT(&v))
2737 case VT_UI1: case VT_I2: case VT_I4:
2738 case VT_R4: case VT_R8:
2739 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
2740 case VT_DATE: case VT_CY:
2741 bFail = FALSE;
2742 break;
2743 case VT_I8:
2744 if (HAVE_OLEAUT32_I8)
2745 bFail = FALSE;
2748 hres = pVarNeg(&v,&vDst);
2749 if (bFail)
2750 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
2751 "VarNeg: expected failure, got 0x%lX vt %d|0x%X\n",
2752 hres, vt, ExtraFlags[i]);
2753 else
2754 ok(hres == S_OK, "VarNeg: expected S_OK, got 0x%lX vt %d|0x%X\n",
2755 hres, vt, ExtraFlags[i]);
2759 VARNEG(BOOL,VARIANT_TRUE,I2,1);
2760 VARNEG(BOOL,VARIANT_FALSE,I2,0);
2761 VARNEG(BOOL,1,I2,-1);
2762 VARNEG(UI1,1,I2,-1);
2763 VARNEG(UI1,254,I2,-254);
2764 VARNEG(I2,-32768,I4,32768);
2765 VARNEG(I2,-1,I2,1);
2766 VARNEG(I2,1,I2,-1);
2767 VARNEG(I4,-((int)(~0u >> 1)) - 1,R8,-2147483648u);
2768 VARNEG(I4,-1,I4,1);
2769 VARNEG(I4,1,I4,-1);
2770 if (HAVE_OLEAUT32_I8)
2772 VARNEG(I8,1,I8,-1);
2773 VARNEG(I8,-1,I8,1);
2775 VARNEG(R4,1,R4,-1);
2776 VARNEG(R4,-1,R4,1);
2777 VARNEG(DATE,1,DATE,-1);
2778 VARNEG(DATE,-1,DATE,1);
2779 VARNEG(R8,1,R8,-1);
2780 VARNEG(R8,-1,R8,1);
2781 VARNEG(BSTR,(BSTR)szNumMinus1,R8,1);
2782 VARNEG(BSTR,(BSTR)szNum1,R8,-1);
2784 V_VT(&v) = VT_EMPTY;
2785 hres = pVarNeg(&v,&vDst);
2786 ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
2787 "VarNeg: expected 0x0,%d,0 got 0x%lX,%d,%d\n", VT_EMPTY,
2788 hres, V_VT(&vDst), V_I2(&vDst));
2790 V_VT(&v) = VT_NULL;
2791 hres = pVarNeg(&v,&vDst);
2792 ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
2793 "VarNeg: expected 0x0,%d got 0x%lX,%d\n", VT_NULL, hres, V_VT(&vDst));
2795 V_VT(&v) = VT_DECIMAL;
2796 S(U(*pdec)).sign = DECIMAL_NEG;
2797 S(U(*pdec)).scale = 0;
2798 pdec->Hi32 = 0;
2799 S1(U1(*pdec)).Mid32 = 0;
2800 S1(U1(*pdec)).Lo32 = 1;
2801 hres = pVarNeg(&v,&vDst);
2802 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
2803 S(U(V_DECIMAL(&vDst))).sign == 0,
2804 "VarNeg: expected 0x0,%d,0x00, got 0x%lX,%d,%02x\n", VT_DECIMAL,
2805 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
2807 S(U(*pdec)).sign = 0;
2808 hres = pVarNeg(&v,&vDst);
2809 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
2810 S(U(V_DECIMAL(&vDst))).sign == DECIMAL_NEG,
2811 "VarNeg: expected 0x0,%d,0x7f, got 0x%lX,%d,%02x\n", VT_DECIMAL,
2812 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
2814 V_VT(&v) = VT_CY;
2815 pcy->int64 = -10000;
2816 hres = pVarNeg(&v,&vDst);
2817 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
2818 "VarNeg: VT_CY wrong, hres=0x%lX\n", hres);
2821 static HRESULT (WINAPI *pVarRound)(LPVARIANT,int,LPVARIANT);
2823 #define VARROUND(vt,val,deci,rvt,rval) V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
2824 memset(&vDst,0,sizeof(vDst)); hres = pVarRound(&v,deci,&vDst); \
2825 ok(hres == S_OK && V_VT(&vDst) == VT_##rvt && V_##rvt(&vDst) == (rval), \
2826 "VarRound: expected 0x0,%d,%d, got 0x%lX,%d,%d\n", VT_##rvt, (int)(rval), \
2827 hres, V_VT(&vDst), (int)V_##rvt(&vDst))
2829 #define VARROUNDF(vt,val,deci,rvt,rval) V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
2830 memset(&vDst,0,sizeof(vDst)); hres = pVarRound(&v,deci,&vDst); \
2831 ok(hres == S_OK && V_VT(&vDst) == VT_##rvt && V_##rvt(&vDst) == (rval), \
2832 "VarRound: expected 0x0,%d,%f, got 0x%lX,%d,%f\n", VT_##rvt, rval, \
2833 hres, V_VT(&vDst), V_##rvt(&vDst))
2835 static void test_VarRound(void)
2837 /* static const WCHAR szNumMin[] = {'-','1','.','4','5','\0' };
2838 static const WCHAR szNum[] = {'1','.','4','5','\0' }; */
2839 HRESULT hres;
2840 VARIANT v, vDst;
2841 CY *pcy = &V_CY(&v);
2843 CHECKPTR(VarRound);
2845 /* first check valid integer types */
2846 VARROUND(BOOL,VARIANT_TRUE,0,I2,-1);
2847 VARROUND(BOOL,VARIANT_FALSE,0,I2,0);
2848 VARROUND(BOOL,1,0,I2,1);
2849 VARROUND(UI1,1,0,UI1,1);
2850 VARROUND(UI1,254,0,UI1,254);
2851 VARROUND(I2,-32768,0,I2,-32768);
2852 VARROUND(I2,-1,0,I2,-1);
2853 VARROUND(I2,1,0,I2,1);
2854 VARROUND(I4,-((int)(~0u >> 1)) - 1,0,I4,-((int)(~0u >> 1)) - 1);
2855 VARROUND(I4,-1,0,I4,-1);
2856 VARROUND(I4,1,0,I4,1);
2859 /* MSDN states that rounding of R4/R8 is dependent on the underlying
2860 * bit pattern of the number and so is architecture dependent. In this
2861 * case Wine returns .2 (which is more correct) and Native returns .3
2864 VARROUNDF(R4,1.0,0,R4,1.0);
2865 VARROUNDF(R4,-1.0,0,R4,-1.0);
2866 VARROUNDF(R8,1.0,0,R8,1.0);
2867 VARROUNDF(R8,-1.0,0,R8,-1.0);
2869 /* floating point numbers aren't exactly equal and we can't just
2870 * compare the first few digits.
2871 todo_wine {
2872 VARROUNDF(DATE,1.451,1,DATE,1.5);
2873 VARROUNDF(DATE,-1.45,1,DATE,-1.4);
2874 VARROUNDF(BSTR,(BSTR)szNumMin,1,R8,-1.40);
2875 VARROUNDF(BSTR,(BSTR)szNum,1,R8,1.50);
2877 VARROUNDF(R4,1.23456,0,R4,1.0);
2878 VARROUNDF(R4,1.23456,1,R4,1.2);
2879 VARROUNDF(R4,1.23456,2,R4,1.23);
2880 VARROUNDF(R4,1.23456,3,R4,1.235);
2881 VARROUNDF(R4,1.23456,4,R4,1.2346);
2882 VARROUNDF(R4,-1.23456,0,R4,-1.0);
2883 VARROUNDF(R4,-1.23456,1,R4,-1.2);
2884 VARROUNDF(R4,-1.23456,2,R4,-1.23);
2885 VARROUNDF(R4,-1.23456,3,R4,-1.235);
2886 VARROUNDF(R4,-1.23456,4,R4,-1.2346);
2888 VARROUNDF(R8,1.23456,0,R8,1.0);
2889 VARROUNDF(R8,1.23456,1,R8,1.2);
2890 VARROUNDF(R8,1.23456,2,R8,1.23);
2891 VARROUNDF(R8,1.23456,3,R8,1.235);
2892 VARROUNDF(R8,1.23456,4,R8,1.2346);
2893 VARROUNDF(R8,-1.23456,0,R8,-1.0);
2894 VARROUNDF(R8,-1.23456,1,R8,-1.2);
2895 VARROUNDF(R8,-1.23456,2,R8,-1.23);
2896 VARROUNDF(R8,-1.23456,3,R8,-1.235);
2897 VARROUNDF(R8,-1.23456,4,R8,-1.2346);
2901 V_VT(&v) = VT_EMPTY;
2902 hres = pVarRound(&v,0,&vDst);
2903 ok(hres == S_OK && V_VT(&vDst) == VT_I2 && V_I2(&vDst) == 0,
2904 "VarRound: expected 0x0,%d,0 got 0x%lX,%d,%d\n", VT_EMPTY,
2905 hres, V_VT(&vDst), V_I2(&vDst));
2907 V_VT(&v) = VT_NULL;
2908 hres = pVarRound(&v,0,&vDst);
2909 ok(hres == S_OK && V_VT(&vDst) == VT_NULL,
2910 "VarRound: expected 0x0,%d got 0x%lX,%d\n", VT_NULL, hres, V_VT(&vDst));
2912 /* not yet implemented so no use testing yet
2913 todo_wine {
2914 DECIMAL *pdec = &V_DECIMAL(&v);
2915 V_VT(&v) = VT_DECIMAL;
2916 S(U(*pdec)).sign = DECIMAL_NEG;
2917 S(U(*pdec)).scale = 0;
2918 pdec->Hi32 = 0;
2919 S1(U1(*pdec)).Mid32 = 0;
2920 S1(U1(*pdec)).Lo32 = 1;
2921 hres = pVarRound(&v,0,&vDst);
2922 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
2923 S(U(V_DECIMAL(&vDst))).sign == 0,
2924 "VarRound: expected 0x0,%d,0x00, got 0x%lX,%d,%02x\n", VT_DECIMAL,
2925 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
2927 S(U(*pdec)).sign = 0;
2928 hres = pVarRound(&v,0,&vDst);
2929 ok(hres == S_OK && V_VT(&vDst) == VT_DECIMAL &&
2930 S(U(V_DECIMAL(&vDst))).sign == DECIMAL_NEG,
2931 "VarRound: expected 0x0,%d,0x7f, got 0x%lX,%d,%02x\n", VT_DECIMAL,
2932 hres, V_VT(&vDst), S(U(V_DECIMAL(&vDst))).sign);
2936 V_VT(&v) = VT_CY;
2937 pcy->int64 = 10000;
2938 hres = pVarRound(&v,0,&vDst);
2939 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
2940 "VarRound: VT_CY wrong, hres=0x%lX\n", hres);
2944 static HRESULT (WINAPI *pVarXor)(LPVARIANT,LPVARIANT,LPVARIANT);
2946 static const char *szVarXorFail = "VarXor(%d,%d): expected 0x0,%d,%d, got 0x%lX,%d,%d\n";
2947 #define VARXOR(vt1,val1,vt2,val2,rvt,rval) \
2948 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
2949 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
2950 memset(&result,0,sizeof(result)); hres = pVarXor(&left,&right,&result); \
2951 ok(hres == S_OK && V_VT(&result) == VT_##rvt && V_##rvt(&result) == (rval), \
2952 szVarXorFail, VT_##vt1, VT_##vt2, \
2953 VT_##rvt, (int)(rval), hres, V_VT(&result), (int)V_##rvt(&result)); \
2954 ok(V_VT(&left) == VT_##vt1 && V_##vt1(&left) == val1 && \
2955 V_VT(&right) == VT_##vt2 && V_##vt2(&right) == val2, \
2956 "VarXor(%d,%d): Modified input arguments\n",VT_##vt1,VT_##vt2)
2957 #define VARXORCY(vt1,val1,val2,rvt,rval) \
2958 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
2959 V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \
2960 memset(&result,0,sizeof(result)); hres = pVarXor(&left,&right,&result); \
2961 ok(hres == S_OK && V_VT(&result) == VT_##rvt && V_##rvt(&result) == (rval), \
2962 "VarXor(%d,%d): expected 0x0,%d,%d, got 0x%lX,%d,%d\n", VT_##vt1, VT_CY, \
2963 VT_##rvt, (int)(rval), hres, V_VT(&result), (int)V_##rvt(&result)); \
2964 ok(V_VT(&left) == VT_##vt1 && V_##vt1(&left) == val1 && \
2965 V_VT(&right) == VT_CY && V_CY(&right).int64 == val2, \
2966 "VarXor(%d,%d): Modified input arguments\n",VT_##vt1,VT_CY)
2968 static void test_VarXor(void)
2970 static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
2971 static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
2972 VARIANT left, right, result;
2973 BSTR lbstr, rbstr;
2974 VARTYPE i;
2975 HRESULT hres;
2977 CHECKPTR(VarXor);
2979 /* Test all possible flag/vt combinations & the resulting vt type */
2980 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2982 VARTYPE leftvt, rightvt, resvt;
2984 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
2987 SKIPTESTS(leftvt);
2989 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
2991 BOOL bFail = FALSE;
2993 SKIPTESTS(rightvt);
2995 if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
2996 leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
2997 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
2998 continue;
3000 memset(&left, 0, sizeof(left));
3001 memset(&right, 0, sizeof(right));
3002 V_VT(&left) = leftvt | ExtraFlags[i];
3003 V_VT(&right) = rightvt | ExtraFlags[i];
3004 V_VT(&result) = VT_EMPTY;
3005 resvt = VT_I4;
3007 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
3008 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
3009 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
3010 leftvt == VT_CLSID || rightvt == VT_CLSID ||
3011 leftvt == VT_RECORD || rightvt == VT_RECORD ||
3012 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
3013 leftvt == VT_ERROR || rightvt == VT_ERROR)
3015 bFail = TRUE;
3017 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
3019 if (leftvt == rightvt ||
3020 leftvt == VT_I2 || rightvt == VT_I2 ||
3021 leftvt == VT_UI1 || rightvt == VT_UI1 ||
3022 leftvt == VT_BOOL || rightvt == VT_BOOL)
3023 resvt = VT_I2;
3024 else if (leftvt == VT_NULL || rightvt == VT_NULL)
3025 resvt = VT_NULL;
3026 else if (leftvt == VT_I8 || rightvt == VT_I8)
3027 resvt = VT_I8;
3029 else if (leftvt == VT_NULL || rightvt == VT_NULL)
3031 resvt = VT_NULL;
3033 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
3035 if (leftvt == rightvt)
3036 resvt = VT_UI1;
3037 else if (leftvt == rightvt ||
3038 leftvt == VT_I2 || rightvt == VT_I2 ||
3039 leftvt == VT_BOOL || rightvt == VT_BOOL)
3041 resvt = VT_I2;
3043 else if (leftvt == VT_I8 || rightvt == VT_I8)
3044 resvt = VT_I8;
3046 else if (leftvt == VT_I2 || rightvt == VT_I2)
3048 if (leftvt == rightvt ||
3049 leftvt == VT_BOOL || rightvt == VT_BOOL)
3050 resvt = VT_I2;
3051 else if (leftvt == VT_I8 || rightvt == VT_I8)
3052 resvt = VT_I8;
3054 else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
3056 resvt = VT_BOOL;
3058 else if (leftvt == VT_I8 || rightvt == VT_I8)
3060 if (leftvt == VT_INT || rightvt == VT_INT)
3061 bFail = TRUE;
3062 else
3063 resvt = VT_I8;
3065 hres = pVarXor(&left, &right, &result);
3066 if (bFail)
3067 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3068 "VarXor: %d|0x%X, %d|0x%X: Expected failure, got 0x%lX vt %d\n",
3069 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
3070 V_VT(&result));
3071 else
3072 ok(hres == S_OK && V_VT(&result) == resvt,
3073 "VarXor: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%lX vt %d\n",
3074 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
3075 V_VT(&result));
3080 /* Test returned values
3081 * FIXME: Test VT_DECIMAL/VT_DISPATCH
3083 VARXOR(EMPTY,0,EMPTY,0,I2,0);
3084 VARXOR(EMPTY,1,EMPTY,0,I2,0);
3085 VARXOR(EMPTY,0,NULL,0,NULL,0);
3086 VARXOR(EMPTY,0,I1,0,I4,0);
3087 VARXOR(EMPTY,0,I1,1,I4,1);
3088 VARXOR(EMPTY,0,UI1,0,I2,0);
3089 VARXOR(EMPTY,0,UI1,1,I2,1);
3090 VARXOR(EMPTY,0,I2,0,I2,0);
3091 VARXOR(EMPTY,0,I2,1,I2,1);
3092 VARXOR(EMPTY,0,UI2,0,I4,0);
3093 VARXOR(EMPTY,0,UI2,1,I4,1);
3094 VARXOR(EMPTY,0,I4,0,I4,0);
3095 VARXOR(EMPTY,0,I4,1,I4,1);
3096 VARXOR(EMPTY,0,UI4,0,I4,0);
3097 VARXOR(EMPTY,0,UI4,1,I4,1);
3098 if (HAVE_OLEAUT32_I8)
3100 VARXOR(EMPTY,0,I8,0,I8,0);
3101 VARXOR(EMPTY,0,I8,1,I8,1);
3102 VARXOR(EMPTY,0,UI8,0,I4,0);
3103 VARXOR(EMPTY,0,UI8,1,I4,1);
3105 VARXOR(EMPTY,0,INT,0,I4,0);
3106 VARXOR(EMPTY,0,INT,1,I4,1);
3107 VARXOR(EMPTY,0,UINT,0,I4,0);
3108 VARXOR(EMPTY,0,UINT,1,I4,1);
3109 VARXOR(EMPTY,0,BOOL,0,I2,0);
3110 VARXOR(EMPTY,0,BOOL,1,I2,1);
3111 VARXOR(EMPTY,0,R4,0,I4,0);
3112 VARXOR(EMPTY,0,R4,1,I4,1);
3113 VARXOR(EMPTY,0,R8,0,I4,0);
3114 VARXOR(EMPTY,0,R8,1,I4,1);
3115 rbstr = SysAllocString(szFalse);
3116 VARXOR(EMPTY,0,BSTR,rbstr,I2,0);
3117 rbstr = SysAllocString(szTrue);
3118 VARXOR(EMPTY,0,BSTR,rbstr,I2,-1);
3119 VARXORCY(EMPTY,0,10000,I4,1);
3121 /* NULL OR 0 = NULL. NULL OR n = n */
3122 VARXOR(NULL,0,NULL,0,NULL,0);
3123 VARXOR(NULL,1,NULL,0,NULL,0);
3124 VARXOR(NULL,0,I1,0,NULL,0);
3125 VARXOR(NULL,0,I1,1,NULL,0);
3126 VARXOR(NULL,0,UI1,0,NULL,0);
3127 VARXOR(NULL,0,UI1,1,NULL,0);
3128 VARXOR(NULL,0,I2,0,NULL,0);
3129 VARXOR(NULL,0,I2,1,NULL,0);
3130 VARXOR(NULL,0,UI2,0,NULL,0);
3131 VARXOR(NULL,0,UI2,1,NULL,0);
3132 VARXOR(NULL,0,I4,0,NULL,0);
3133 VARXOR(NULL,0,I4,1,NULL,0);
3134 VARXOR(NULL,0,UI4,0,NULL,0);
3135 VARXOR(NULL,0,UI4,1,NULL,0);
3136 if (HAVE_OLEAUT32_I8)
3138 VARXOR(NULL,0,I8,0,NULL,0);
3139 VARXOR(NULL,0,I8,1,NULL,0);
3140 VARXOR(NULL,0,UI8,0,NULL,0);
3141 VARXOR(NULL,0,UI8,1,NULL,0);
3143 VARXOR(NULL,0,INT,0,NULL,0);
3144 VARXOR(NULL,0,INT,1,NULL,0);
3145 VARXOR(NULL,0,UINT,0,NULL,0);
3146 VARXOR(NULL,0,UINT,1,NULL,0);
3147 VARXOR(NULL,0,BOOL,0,NULL,0);
3148 VARXOR(NULL,0,BOOL,1,NULL,0);
3149 VARXOR(NULL,0,R4,0,NULL,0);
3150 VARXOR(NULL,0,R4,1,NULL,0);
3151 VARXOR(NULL,0,R8,0,NULL,0);
3152 VARXOR(NULL,0,R8,1,NULL,0);
3153 rbstr = SysAllocString(szFalse);
3154 VARXOR(NULL,0,BSTR,rbstr,NULL,0);
3155 rbstr = SysAllocString(szTrue);
3156 VARXOR(NULL,0,BSTR,rbstr,NULL,0);
3157 VARXORCY(NULL,0,10000,NULL,0);
3158 VARXORCY(NULL,0,0,NULL,0);
3160 VARXOR(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
3161 VARXOR(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
3162 VARXOR(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
3163 VARXOR(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
3164 /* Assume x,y & y,x are the same from now on to reduce the number of tests */
3165 VARXOR(BOOL,VARIANT_TRUE,I1,-1,I4,0);
3166 VARXOR(BOOL,VARIANT_TRUE,I1,0,I4,-1);
3167 VARXOR(BOOL,VARIANT_FALSE,I1,0,I4,0);
3168 VARXOR(BOOL,VARIANT_TRUE,UI1,255,I2,-256);
3169 VARXOR(BOOL,VARIANT_TRUE,UI1,0,I2,-1);
3170 VARXOR(BOOL,VARIANT_FALSE,UI1,0,I2,0);
3171 VARXOR(BOOL,VARIANT_TRUE,I2,-1,I2,0);
3172 VARXOR(BOOL,VARIANT_TRUE,I2,0,I2,-1);
3173 VARXOR(BOOL,VARIANT_FALSE,I2,0,I2,0);
3174 VARXOR(BOOL,VARIANT_TRUE,UI2,65535,I4,-65536);
3175 VARXOR(BOOL,VARIANT_TRUE,UI2,0,I4,-1);
3176 VARXOR(BOOL,VARIANT_FALSE,UI2,0,I4,0);
3177 VARXOR(BOOL,VARIANT_TRUE,I4,-1,I4,0);
3178 VARXOR(BOOL,VARIANT_TRUE,I4,0,I4,-1);
3179 VARXOR(BOOL,VARIANT_FALSE,I4,0,I4,0);
3180 VARXOR(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,0);
3181 VARXOR(BOOL,VARIANT_TRUE,UI4,0,I4,-1);
3182 VARXOR(BOOL,VARIANT_FALSE,UI4,0,I4,0);
3183 VARXOR(BOOL,VARIANT_TRUE,R4,-1,I4,0);
3184 VARXOR(BOOL,VARIANT_TRUE,R4,0,I4,-1);
3185 VARXOR(BOOL,VARIANT_FALSE,R4,0,I4,0);
3186 VARXOR(BOOL,VARIANT_TRUE,R8,-1,I4,0);
3187 VARXOR(BOOL,VARIANT_TRUE,R8,0,I4,-1);
3188 VARXOR(BOOL,VARIANT_FALSE,R8,0,I4,0);
3189 VARXOR(BOOL,VARIANT_TRUE,DATE,-1,I4,0);
3190 VARXOR(BOOL,VARIANT_TRUE,DATE,0,I4,-1);
3191 VARXOR(BOOL,VARIANT_FALSE,DATE,0,I4,0);
3192 if (HAVE_OLEAUT32_I8)
3194 VARXOR(BOOL,VARIANT_TRUE,I8,-1,I8,0);
3195 VARXOR(BOOL,VARIANT_TRUE,I8,0,I8,-1);
3196 VARXOR(BOOL,VARIANT_FALSE,I8,0,I8,0);
3197 /* This returns DISP_E_OVERFLOW which indicates that a conversion
3198 * to I4 is performed.
3200 /* VARXOR(BOOL,VARIANT_TRUE,UI8,-1,I4,-1); */
3201 VARXOR(BOOL,VARIANT_TRUE,UI8,0,I4,-1);
3202 VARXOR(BOOL,VARIANT_FALSE,UI8,0,I4,0);
3204 VARXOR(BOOL,VARIANT_TRUE,INT,-1,I4,0);
3205 VARXOR(BOOL,VARIANT_TRUE,INT,0,I4,-1);
3206 VARXOR(BOOL,VARIANT_FALSE,INT,0,I4,0);
3207 VARXOR(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,0);
3208 VARXOR(BOOL,VARIANT_TRUE,UINT,0,I4,-1);
3209 VARXOR(BOOL,VARIANT_FALSE,UINT,0,I4,0);
3210 rbstr = SysAllocString(szFalse);
3211 VARXOR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_FALSE);
3212 VARXOR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
3213 rbstr = SysAllocString(szTrue);
3214 VARXOR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_TRUE);
3215 VARXOR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_FALSE);
3216 VARXORCY(BOOL,VARIANT_TRUE,10000,I4,-2);
3217 VARXORCY(BOOL,VARIANT_TRUE,0,I4,-1);
3218 VARXORCY(BOOL,VARIANT_FALSE,0,I4,0);
3220 VARXOR(I1,-1,I1,-1,I4,0);
3221 VARXOR(I1,-1,I1,0,I4,-1);
3222 VARXOR(I1,0,I1,0,I4,0);
3223 VARXOR(I1,-1,UI1,255,I4,-256);
3224 VARXOR(I1,-1,UI1,0,I4,-1);
3225 VARXOR(I1,0,UI1,0,I4,0);
3226 VARXOR(I1,-1,I2,-1,I4,0);
3227 VARXOR(I1,-1,I2,0,I4,-1);
3228 VARXOR(I1,0,I2,0,I4,0);
3229 VARXOR(I1,-1,UI2,65535,I4,-65536);
3230 VARXOR(I1,-1,UI2,0,I4,-1);
3231 VARXOR(I1,0,UI2,0,I4,0);
3232 VARXOR(I1,-1,I4,-1,I4,0);
3233 VARXOR(I1,-1,I4,0,I4,-1);
3234 VARXOR(I1,0,I4,0,I4,0);
3235 VARXOR(I1,-1,UI4,0xffffffff,I4,0);
3236 VARXOR(I1,-1,UI4,0,I4,-1);
3237 VARXOR(I1,0,UI4,0,I4,0);
3238 VARXOR(I1,-1,R4,-1,I4,0);
3239 VARXOR(I1,-1,R4,0,I4,-1);
3240 VARXOR(I1,0,R4,0,I4,0);
3241 VARXOR(I1,-1,R8,-1,I4,0);
3242 VARXOR(I1,-1,R8,0,I4,-1);
3243 VARXOR(I1,0,R8,0,I4,0);
3244 VARXOR(I1,-1,DATE,-1,I4,0);
3245 VARXOR(I1,-1,DATE,0,I4,-1);
3246 VARXOR(I1,0,DATE,0,I4,0);
3247 if (HAVE_OLEAUT32_I8)
3249 VARXOR(I1,-1,I8,-1,I8,0);
3250 VARXOR(I1,-1,I8,0,I8,-1);
3251 VARXOR(I1,0,I8,0,I8,0);
3252 VARXOR(I1,-1,UI8,0,I4,-1);
3253 VARXOR(I1,0,UI8,0,I4,0);
3255 VARXOR(I1,-1,INT,-1,I4,0);
3256 VARXOR(I1,-1,INT,0,I4,-1);
3257 VARXOR(I1,0,INT,0,I4,0);
3258 VARXOR(I1,-1,UINT,0xffffffff,I4,0);
3259 VARXOR(I1,-1,UINT,0,I4,-1);
3260 VARXOR(I1,0,UINT,0,I4,0);
3261 rbstr = SysAllocString(szFalse);
3262 VARXOR(I1,0,BSTR,rbstr,I4,0);
3263 VARXOR(I1,-1,BSTR,rbstr,I4,-1);
3264 rbstr = SysAllocString(szTrue);
3265 VARXOR(I1,0,BSTR,rbstr,I4,-1);
3266 VARXOR(I1,-1,BSTR,rbstr,I4,0);
3267 VARXORCY(I1,-1,10000,I4,-2);
3268 VARXORCY(I1,-1,0,I4,-1);
3269 VARXORCY(I1,0,0,I4,0);
3271 VARXOR(UI1,255,UI1,255,UI1,0);
3272 VARXOR(UI1,255,UI1,0,UI1,255);
3273 VARXOR(UI1,0,UI1,0,UI1,0);
3274 VARXOR(UI1,255,I2,-1,I2,-256);
3275 VARXOR(UI1,255,I2,0,I2,255);
3276 VARXOR(UI1,0,I2,0,I2,0);
3277 VARXOR(UI1,255,UI2,65535,I4,65280);
3278 VARXOR(UI1,255,UI2,0,I4,255);
3279 VARXOR(UI1,0,UI2,0,I4,0);
3280 VARXOR(UI1,255,I4,-1,I4,-256);
3281 VARXOR(UI1,255,I4,0,I4,255);
3282 VARXOR(UI1,0,I4,0,I4,0);
3283 VARXOR(UI1,255,UI4,0xffffffff,I4,-256);
3284 VARXOR(UI1,255,UI4,0,I4,255);
3285 VARXOR(UI1,0,UI4,0,I4,0);
3286 VARXOR(UI1,255,R4,-1,I4,-256);
3287 VARXOR(UI1,255,R4,0,I4,255);
3288 VARXOR(UI1,0,R4,0,I4,0);
3289 VARXOR(UI1,255,R8,-1,I4,-256);
3290 VARXOR(UI1,255,R8,0,I4,255);
3291 VARXOR(UI1,0,R8,0,I4,0);
3292 VARXOR(UI1,255,DATE,-1,I4,-256);
3293 VARXOR(UI1,255,DATE,0,I4,255);
3294 VARXOR(UI1,0,DATE,0,I4,0);
3295 if (HAVE_OLEAUT32_I8)
3297 VARXOR(UI1,255,I8,-1,I8,-256);
3298 VARXOR(UI1,255,I8,0,I8,255);
3299 VARXOR(UI1,0,I8,0,I8,0);
3300 VARXOR(UI1,255,UI8,0,I4,255);
3301 VARXOR(UI1,0,UI8,0,I4,0);
3303 VARXOR(UI1,255,INT,-1,I4,-256);
3304 VARXOR(UI1,255,INT,0,I4,255);
3305 VARXOR(UI1,0,INT,0,I4,0);
3306 VARXOR(UI1,255,UINT,0xffffffff,I4,-256);
3307 VARXOR(UI1,255,UINT,0,I4,255);
3308 VARXOR(UI1,0,UINT,0,I4,0);
3309 rbstr = SysAllocString(szFalse);
3310 VARXOR(UI1,0,BSTR,rbstr,I2,0);
3311 VARXOR(UI1,255,BSTR,rbstr,I2,255);
3312 rbstr = SysAllocString(szTrue);
3313 VARXOR(UI1,0,BSTR,rbstr,I2,-1);
3314 VARXOR(UI1,255,BSTR,rbstr,I2,-256);
3315 VARXORCY(UI1,255,10000,I4,254);
3316 VARXORCY(UI1,255,0,I4,255);
3317 VARXORCY(UI1,0,0,I4,0);
3319 VARXOR(I2,-1,I2,-1,I2,0);
3320 VARXOR(I2,-1,I2,0,I2,-1);
3321 VARXOR(I2,0,I2,0,I2,0);
3322 VARXOR(I2,-1,UI2,65535,I4,-65536);
3323 VARXOR(I2,-1,UI2,0,I4,-1);
3324 VARXOR(I2,0,UI2,0,I4,0);
3325 VARXOR(I2,-1,I4,-1,I4,0);
3326 VARXOR(I2,-1,I4,0,I4,-1);
3327 VARXOR(I2,0,I4,0,I4,0);
3328 VARXOR(I2,-1,UI4,0xffffffff,I4,0);
3329 VARXOR(I2,-1,UI4,0,I4,-1);
3330 VARXOR(I2,0,UI4,0,I4,0);
3331 VARXOR(I2,-1,R4,-1,I4,0);
3332 VARXOR(I2,-1,R4,0,I4,-1);
3333 VARXOR(I2,0,R4,0,I4,0);
3334 VARXOR(I2,-1,R8,-1,I4,0);
3335 VARXOR(I2,-1,R8,0,I4,-1);
3336 VARXOR(I2,0,R8,0,I4,0);
3337 VARXOR(I2,-1,DATE,-1,I4,0);
3338 VARXOR(I2,-1,DATE,0,I4,-1);
3339 VARXOR(I2,0,DATE,0,I4,0);
3340 if (HAVE_OLEAUT32_I8)
3342 VARXOR(I2,-1,I8,-1,I8,0);
3343 VARXOR(I2,-1,I8,0,I8,-1);
3344 VARXOR(I2,0,I8,0,I8,0);
3345 VARXOR(I2,-1,UI8,0,I4,-1);
3346 VARXOR(I2,0,UI8,0,I4,0);
3348 VARXOR(I2,-1,INT,-1,I4,0);
3349 VARXOR(I2,-1,INT,0,I4,-1);
3350 VARXOR(I2,0,INT,0,I4,0);
3351 VARXOR(I2,-1,UINT,0xffffffff,I4,0);
3352 VARXOR(I2,-1,UINT,0,I4,-1);
3353 VARXOR(I2,0,UINT,0,I4,0);
3354 rbstr = SysAllocString(szFalse);
3355 VARXOR(I2,0,BSTR,rbstr,I2,0);
3356 VARXOR(I2,-1,BSTR,rbstr,I2,-1);
3357 rbstr = SysAllocString(szTrue);
3358 VARXOR(I2,0,BSTR,rbstr,I2,-1);
3359 VARXOR(I2,-1,BSTR,rbstr,I2,0);
3360 VARXORCY(I2,-1,10000,I4,-2);
3361 VARXORCY(I2,-1,0,I4,-1);
3362 VARXORCY(I2,0,0,I4,0);
3364 VARXOR(UI2,65535,UI2,65535,I4,0);
3365 VARXOR(UI2,65535,UI2,0,I4,65535);
3366 VARXOR(UI2,0,UI2,0,I4,0);
3367 VARXOR(UI2,65535,I4,-1,I4,-65536);
3368 VARXOR(UI2,65535,I4,0,I4,65535);
3369 VARXOR(UI2,0,I4,0,I4,0);
3370 VARXOR(UI2,65535,UI4,0xffffffff,I4,-65536);
3371 VARXOR(UI2,65535,UI4,0,I4,65535);
3372 VARXOR(UI2,0,UI4,0,I4,0);
3373 VARXOR(UI2,65535,R4,-1,I4,-65536);
3374 VARXOR(UI2,65535,R4,0,I4,65535);
3375 VARXOR(UI2,0,R4,0,I4,0);
3376 VARXOR(UI2,65535,R8,-1,I4,-65536);
3377 VARXOR(UI2,65535,R8,0,I4,65535);
3378 VARXOR(UI2,0,R8,0,I4,0);
3379 VARXOR(UI2,65535,DATE,-1,I4,-65536);
3380 VARXOR(UI2,65535,DATE,0,I4,65535);
3381 VARXOR(UI2,0,DATE,0,I4,0);
3382 if (HAVE_OLEAUT32_I8)
3384 VARXOR(UI2,65535,I8,-1,I8,-65536);
3385 VARXOR(UI2,65535,I8,0,I8,65535);
3386 VARXOR(UI2,0,I8,0,I8,0);
3387 VARXOR(UI2,65535,UI8,0,I4,65535);
3388 VARXOR(UI2,0,UI8,0,I4,0);
3390 VARXOR(UI2,65535,INT,-1,I4,-65536);
3391 VARXOR(UI2,65535,INT,0,I4,65535);
3392 VARXOR(UI2,0,INT,0,I4,0);
3393 VARXOR(UI2,65535,UINT,0xffffffff,I4,-65536);
3394 VARXOR(UI2,65535,UINT,0,I4,65535);
3395 VARXOR(UI2,0,UINT,0,I4,0);
3396 rbstr = SysAllocString(szFalse);
3397 VARXOR(UI2,0,BSTR,rbstr,I4,0);
3398 VARXOR(UI2,65535,BSTR,rbstr,I4,65535);
3399 rbstr = SysAllocString(szTrue);
3400 VARXOR(UI2,0,BSTR,rbstr,I4,-1);
3401 VARXOR(UI2,65535,BSTR,rbstr,I4,-65536);
3402 VARXORCY(UI2,65535,10000,I4,65534);
3403 VARXORCY(UI2,65535,0,I4,65535);
3404 VARXORCY(UI2,0,0,I4,0);
3406 VARXOR(I4,-1,I4,-1,I4,0);
3407 VARXOR(I4,-1,I4,0,I4,-1);
3408 VARXOR(I4,0,I4,0,I4,0);
3409 VARXOR(I4,-1,UI4,0xffffffff,I4,0);
3410 VARXOR(I4,-1,UI4,0,I4,-1);
3411 VARXOR(I4,0,UI4,0,I4,0);
3412 VARXOR(I4,-1,R4,-1,I4,0);
3413 VARXOR(I4,-1,R4,0,I4,-1);
3414 VARXOR(I4,0,R4,0,I4,0);
3415 VARXOR(I4,-1,R8,-1,I4,0);
3416 VARXOR(I4,-1,R8,0,I4,-1);
3417 VARXOR(I4,0,R8,0,I4,0);
3418 VARXOR(I4,-1,DATE,-1,I4,0);
3419 VARXOR(I4,-1,DATE,0,I4,-1);
3420 VARXOR(I4,0,DATE,0,I4,0);
3421 if (HAVE_OLEAUT32_I8)
3423 VARXOR(I4,-1,I8,-1,I8,0);
3424 VARXOR(I4,-1,I8,0,I8,-1);
3425 VARXOR(I4,0,I8,0,I8,0);
3426 VARXOR(I4,-1,UI8,0,I4,-1);
3427 VARXOR(I4,0,UI8,0,I4,0);
3429 VARXOR(I4,-1,INT,-1,I4,0);
3430 VARXOR(I4,-1,INT,0,I4,-1);
3431 VARXOR(I4,0,INT,0,I4,0);
3432 VARXOR(I4,-1,UINT,0xffffffff,I4,0);
3433 VARXOR(I4,-1,UINT,0,I4,-1);
3434 VARXOR(I4,0,UINT,0,I4,0);
3435 rbstr = SysAllocString(szFalse);
3436 VARXOR(I4,0,BSTR,rbstr,I4,0);
3437 VARXOR(I4,-1,BSTR,rbstr,I4,-1);
3438 rbstr = SysAllocString(szTrue);
3439 VARXOR(I4,0,BSTR,rbstr,I4,-1);
3440 VARXOR(I4,-1,BSTR,rbstr,I4,0);
3441 VARXORCY(I4,-1,10000,I4,-2);
3442 VARXORCY(I4,-1,0,I4,-1);
3443 VARXORCY(I4,0,0,I4,0);
3445 VARXOR(UI4,0xffffffff,UI4,0xffffffff,I4,0);
3446 VARXOR(UI4,0xffffffff,UI4,0,I4,-1);
3447 VARXOR(UI4,0,UI4,0,I4,0);
3448 VARXOR(UI4,0xffffffff,R4,-1,I4,0);
3449 VARXOR(UI4,0xffffffff,R4,0,I4,-1);
3450 VARXOR(UI4,0,R4,0,I4,0);
3451 VARXOR(UI4,0xffffffff,R8,-1,I4,0);
3452 VARXOR(UI4,0xffffffff,R8,0,I4,-1);
3453 VARXOR(UI4,0,R8,0,I4,0);
3454 VARXOR(UI4,0xffffffff,DATE,-1,I4,0);
3455 VARXOR(UI4,0xffffffff,DATE,0,I4,-1);
3456 VARXOR(UI4,0,DATE,0,I4,0);
3457 if (HAVE_OLEAUT32_I8)
3459 VARXOR(UI4,0xffffffff,I8,0,I8,0xffffffff);
3460 VARXOR(UI4,VARIANT_FALSE,I8,VARIANT_FALSE,I8,0);
3461 VARXOR(UI4,0,I8,0,I8,0);
3462 VARXOR(UI4,0xffffffff,UI8,0,I4,-1);
3463 VARXOR(UI4,0,UI8,0,I4,0);
3465 VARXOR(UI4,0xffffffff,INT,-1,I4,0);
3466 VARXOR(UI4,0xffffffff,INT,0,I4,-1);
3467 VARXOR(UI4,0,INT,0,I4,0);
3468 VARXOR(UI4,0xffffffff,UINT,0xffffffff,I4,0);
3469 VARXOR(UI4,0xffffffff,UINT,0,I4,-1);
3470 VARXOR(UI4,0,UINT,0,I4,0);
3471 rbstr = SysAllocString(szFalse);
3472 VARXOR(UI4,0,BSTR,rbstr,I4,0);
3473 VARXOR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
3474 rbstr = SysAllocString(szTrue);
3475 VARXOR(UI4,0,BSTR,rbstr,I4,-1);
3476 VARXOR(UI4,0xffffffff,BSTR,rbstr,I4,0);
3477 VARXORCY(UI4,0xffffffff,10000,I4,-2);
3478 VARXORCY(UI4,0xffffffff,0,I4,-1);
3479 VARXORCY(UI4,0,0,I4,0);
3481 VARXOR(R4,-1,R4,-1,I4,0);
3482 VARXOR(R4,-1,R4,0,I4,-1);
3483 VARXOR(R4,0,R4,0,I4,0);
3484 VARXOR(R4,-1,R8,-1,I4,0);
3485 VARXOR(R4,-1,R8,0,I4,-1);
3486 VARXOR(R4,0,R8,0,I4,0);
3487 VARXOR(R4,-1,DATE,-1,I4,0);
3488 VARXOR(R4,-1,DATE,0,I4,-1);
3489 VARXOR(R4,0,DATE,0,I4,0);
3490 if (HAVE_OLEAUT32_I8)
3492 VARXOR(R4,-1,I8,-1,I8,0);
3493 VARXOR(R4,-1,I8,0,I8,-1);
3494 VARXOR(R4,0,I8,0,I8,0);
3495 VARXOR(R4,-1,UI8,0,I4,-1);
3496 VARXOR(R4,0,UI8,0,I4,0);
3498 VARXOR(R4,-1,INT,-1,I4,0);
3499 VARXOR(R4,-1,INT,0,I4,-1);
3500 VARXOR(R4,0,INT,0,I4,0);
3501 VARXOR(R4,-1,UINT,0xffffffff,I4,0);
3502 VARXOR(R4,-1,UINT,0,I4,-1);
3503 VARXOR(R4,0,UINT,0,I4,0);
3504 rbstr = SysAllocString(szFalse);
3505 VARXOR(R4,0,BSTR,rbstr,I4,0);
3506 VARXOR(R4,-1,BSTR,rbstr,I4,-1);
3507 rbstr = SysAllocString(szTrue);
3508 VARXOR(R4,0,BSTR,rbstr,I4,-1);
3509 VARXOR(R4,-1,BSTR,rbstr,I4,0);
3510 VARXORCY(R4,-1,10000,I4,-2);
3511 VARXORCY(R4,-1,0,I4,-1);
3512 VARXORCY(R4,0,0,I4,0);
3514 VARXOR(R8,-1,R8,-1,I4,0);
3515 VARXOR(R8,-1,R8,0,I4,-1);
3516 VARXOR(R8,0,R8,0,I4,0);
3517 VARXOR(R8,-1,DATE,-1,I4,0);
3518 VARXOR(R8,-1,DATE,0,I4,-1);
3519 VARXOR(R8,0,DATE,0,I4,0);
3520 if (HAVE_OLEAUT32_I8)
3522 VARXOR(R8,-1,I8,-1,I8,0);
3523 VARXOR(R8,-1,I8,0,I8,-1);
3524 VARXOR(R8,0,I8,0,I8,0);
3525 VARXOR(R8,-1,UI8,0,I4,-1);
3526 VARXOR(R8,0,UI8,0,I4,0);
3528 VARXOR(R8,-1,INT,-1,I4,0);
3529 VARXOR(R8,-1,INT,0,I4,-1);
3530 VARXOR(R8,0,INT,0,I4,0);
3531 VARXOR(R8,-1,UINT,0xffffffff,I4,0);
3532 VARXOR(R8,-1,UINT,0,I4,-1);
3533 VARXOR(R8,0,UINT,0,I4,0);
3534 rbstr = SysAllocString(szFalse);
3535 VARXOR(R8,0,BSTR,rbstr,I4,0);
3536 VARXOR(R8,-1,BSTR,rbstr,I4,-1);
3537 rbstr = SysAllocString(szTrue);
3538 VARXOR(R8,0,BSTR,rbstr,I4,-1);
3539 VARXOR(R8,-1,BSTR,rbstr,I4,0);
3540 VARXORCY(R8,-1,10000,I4,-2);
3541 VARXORCY(R8,-1,0,I4,-1);
3542 VARXORCY(R8,0,0,I4,0);
3544 VARXOR(DATE,-1,DATE,-1,I4,0);
3545 VARXOR(DATE,-1,DATE,0,I4,-1);
3546 VARXOR(DATE,0,DATE,0,I4,0);
3547 if (HAVE_OLEAUT32_I8)
3549 VARXOR(DATE,-1,I8,-1,I8,0);
3550 VARXOR(DATE,-1,I8,0,I8,-1);
3551 VARXOR(DATE,0,I8,0,I8,0);
3552 VARXOR(DATE,-1,UI8,0,I4,-1);
3553 VARXOR(DATE,0,UI8,0,I4,0);
3555 VARXOR(DATE,-1,INT,-1,I4,0);
3556 VARXOR(DATE,-1,INT,0,I4,-1);
3557 VARXOR(DATE,0,INT,0,I4,0);
3558 VARXOR(DATE,-1,UINT,0xffffffff,I4,0);
3559 VARXOR(DATE,-1,UINT,0,I4,-1);
3560 VARXOR(DATE,0,UINT,0,I4,0);
3561 rbstr = SysAllocString(szFalse);
3562 VARXOR(DATE,0,BSTR,rbstr,I4,0);
3563 VARXOR(DATE,-1,BSTR,rbstr,I4,-1);
3564 rbstr = SysAllocString(szTrue);
3565 VARXOR(DATE,0,BSTR,rbstr,I4,-1);
3566 VARXOR(DATE,-1,BSTR,rbstr,I4,0);
3567 VARXORCY(DATE,-1,10000,I4,-2);
3568 VARXORCY(DATE,-1,0,I4,-1);
3569 VARXORCY(DATE,0,0,I4,0);
3571 if (HAVE_OLEAUT32_I8)
3573 VARXOR(I8,-1,I8,-1,I8,0);
3574 VARXOR(I8,-1,I8,0,I8,-1);
3575 VARXOR(I8,0,I8,0,I8,0);
3576 VARXOR(I8,-1,UI8,0,I8,-1);
3577 VARXOR(I8,0,UI8,0,I8,0);
3578 VARXOR(I8,-1,UINT,0,I8,-1);
3579 VARXOR(I8,0,UINT,0,I8,0);
3580 rbstr = SysAllocString(szFalse);
3581 VARXOR(I8,0,BSTR,rbstr,I8,0);
3582 VARXOR(I8,-1,BSTR,rbstr,I8,-1);
3583 rbstr = SysAllocString(szTrue);
3584 VARXOR(I8,0,BSTR,rbstr,I8,-1);
3585 VARXOR(I8,-1,BSTR,rbstr,I8,0);
3586 VARXORCY(I8,-1,10000,I8,-2);
3587 VARXORCY(I8,-1,0,I8,-1);
3588 VARXORCY(I8,0,0,I8,0);
3590 VARXOR(UI8,0xffff,UI8,0xffff,I4,0);
3591 VARXOR(UI8,0xffff,UI8,0,I4,0xffff);
3592 VARXOR(UI8,0,UI8,0,I4,0);
3593 VARXOR(UI8,0xffff,INT,-1,I4,-65536);
3594 VARXOR(UI8,0xffff,INT,0,I4,0xffff);
3595 VARXOR(UI8,0,INT,0,I4,0);
3596 VARXOR(UI8,0xffff,UINT,0xffff,I4,0);
3597 VARXOR(UI8,0xffff,UINT,0,I4,0xffff);
3598 VARXOR(UI8,0,UINT,0,I4,0);
3599 rbstr = SysAllocString(szFalse);
3600 VARXOR(UI8,0,BSTR,rbstr,I4,0);
3601 VARXOR(UI8,0xffff,BSTR,rbstr,I4,0xffff);
3602 rbstr = SysAllocString(szTrue);
3603 VARXOR(UI8,0,BSTR,rbstr,I4,-1);
3604 VARXOR(UI8,0xffff,BSTR,rbstr,I4,-65536);
3605 VARXORCY(UI8,0xffff,10000,I4,65534);
3606 VARXORCY(UI8,0xffff,0,I4,0xffff);
3607 VARXORCY(UI8,0,0,I4,0);
3610 VARXOR(INT,-1,INT,-1,I4,0);
3611 VARXOR(INT,-1,INT,0,I4,-1);
3612 VARXOR(INT,0,INT,0,I4,0);
3613 VARXOR(INT,-1,UINT,0xffff,I4,-65536);
3614 VARXOR(INT,-1,UINT,0,I4,-1);
3615 VARXOR(INT,0,UINT,0,I4,0);
3616 rbstr = SysAllocString(szFalse);
3617 VARXOR(INT,0,BSTR,rbstr,I4,0);
3618 VARXOR(INT,-1,BSTR,rbstr,I4,-1);
3619 rbstr = SysAllocString(szTrue);
3620 VARXOR(INT,0,BSTR,rbstr,I4,-1);
3621 VARXOR(INT,-1,BSTR,rbstr,I4,0);
3622 VARXORCY(INT,-1,10000,I4,-2);
3623 VARXORCY(INT,-1,0,I4,-1);
3624 VARXORCY(INT,0,0,I4,0);
3626 VARXOR(UINT,0xffff,UINT,0xffff,I4,0);
3627 VARXOR(UINT,0xffff,UINT,0,I4,0xffff);
3628 VARXOR(UINT,0,UINT,0,I4,0);
3629 rbstr = SysAllocString(szFalse);
3630 VARXOR(UINT,0,BSTR,rbstr,I4,0);
3631 VARXOR(UINT,0xffff,BSTR,rbstr,I4,0xffff);
3632 rbstr = SysAllocString(szTrue);
3633 VARXOR(UINT,0,BSTR,rbstr,I4,-1);
3634 VARXOR(UINT,0xffff,BSTR,rbstr,I4,-65536);
3635 VARXORCY(UINT,0xffff,10000,I4,65534);
3636 VARXORCY(UINT,0xffff,0,I4,0xffff);
3637 VARXORCY(UINT,0,0,I4,0);
3639 lbstr = SysAllocString(szFalse);
3640 rbstr = SysAllocString(szFalse);
3641 VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,0);
3642 rbstr = SysAllocString(szTrue);
3643 VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
3644 lbstr = SysAllocString(szTrue);
3645 VARXOR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_FALSE);
3646 VARXORCY(BSTR,lbstr,10000,I4,-2);
3647 lbstr = SysAllocString(szFalse);
3648 VARXORCY(BSTR,lbstr,10000,I4,1);
3651 static HRESULT (WINAPI *pVarOr)(LPVARIANT,LPVARIANT,LPVARIANT);
3653 static const char *szVarOrFail = "VarOr(%d,%d): expected 0x0,%d,%d, got 0x%lX,%d,%d\n";
3654 static const char *szVarOrChanged = "VarOr(%d,%d): Modified input arguments\n";
3655 #define VAROR(vt1,val1,vt2,val2,rvt,rval) \
3656 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
3657 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
3658 memset(&result,0,sizeof(result)); hres = pVarOr(&left,&right,&result); \
3659 ok(hres == S_OK && V_VT(&result) == VT_##rvt && V_##rvt(&result) == (rval), \
3660 szVarOrFail, VT_##vt1, VT_##vt2, \
3661 VT_##rvt, (int)(rval), hres, V_VT(&result), (int)V_##rvt(&result)); \
3662 ok(V_VT(&left) == VT_##vt1 && V_##vt1(&left) == val1 && \
3663 V_VT(&right) == VT_##vt2 && V_##vt2(&right) == val2, \
3664 szVarOrChanged,VT_##vt1,VT_##vt2)
3665 #define VARORCY(vt1,val1,val2,rvt,rval) \
3666 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
3667 V_VT(&right) = VT_CY; V_CY(&right).int64 = val2; \
3668 memset(&result,0,sizeof(result)); hres = pVarOr(&left,&right,&result); \
3669 ok(hres == S_OK && V_VT(&result) == VT_##rvt && V_##rvt(&result) == (rval), \
3670 "VarOr(%d,%d): expected 0x0,%d,%d, got 0x%lX,%d,%d\n", VT_##vt1, VT_CY, \
3671 VT_##rvt, (int)(rval), hres, V_VT(&result), (int)V_##rvt(&result)); \
3672 ok(V_VT(&left) == VT_##vt1 && V_##vt1(&left) == val1 && \
3673 V_VT(&right) == VT_CY && V_CY(&right).int64 == val2, \
3674 "VarOr(%d,%d): Modified input arguments\n",VT_##vt1,VT_CY)
3676 static void test_VarOr(void)
3678 static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
3679 static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
3680 VARIANT left, right, result;
3681 BSTR lbstr, rbstr;
3682 VARTYPE i;
3683 HRESULT hres;
3685 CHECKPTR(VarOr);
3687 /* Test all possible flag/vt combinations & the resulting vt type */
3688 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
3690 VARTYPE leftvt, rightvt, resvt;
3692 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
3695 SKIPTESTS(leftvt);
3697 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
3699 BOOL bFail = FALSE;
3701 SKIPTESTS(rightvt);
3703 if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
3704 leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
3705 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
3706 continue;
3708 memset(&left, 0, sizeof(left));
3709 memset(&right, 0, sizeof(right));
3710 V_VT(&left) = leftvt | ExtraFlags[i];
3711 V_VT(&right) = rightvt | ExtraFlags[i];
3712 V_VT(&result) = VT_EMPTY;
3713 resvt = VT_I4;
3715 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
3716 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
3717 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
3718 leftvt == VT_CLSID || rightvt == VT_CLSID ||
3719 leftvt == VT_RECORD || rightvt == VT_RECORD ||
3720 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
3721 leftvt == VT_ERROR || rightvt == VT_ERROR)
3723 bFail = TRUE;
3725 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
3727 if (leftvt == rightvt ||
3728 leftvt == VT_I2 || rightvt == VT_I2 ||
3729 leftvt == VT_UI1 || rightvt == VT_UI1 ||
3730 leftvt == VT_BOOL || rightvt == VT_BOOL)
3731 resvt = VT_I2;
3732 else if (leftvt == VT_NULL || rightvt == VT_NULL)
3733 resvt = VT_NULL;
3734 else if (leftvt == VT_I8 || rightvt == VT_I8)
3735 resvt = VT_I8;
3737 else if (leftvt == VT_NULL || rightvt == VT_NULL)
3739 resvt = VT_NULL;
3741 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
3743 if (leftvt == rightvt)
3744 resvt = VT_UI1;
3745 else if (leftvt == rightvt ||
3746 leftvt == VT_I2 || rightvt == VT_I2 ||
3747 leftvt == VT_BOOL || rightvt == VT_BOOL)
3749 resvt = VT_I2;
3751 else if (leftvt == VT_I8 || rightvt == VT_I8)
3752 resvt = VT_I8;
3754 else if (leftvt == VT_I2 || rightvt == VT_I2)
3756 if (leftvt == rightvt ||
3757 leftvt == VT_BOOL || rightvt == VT_BOOL)
3758 resvt = VT_I2;
3759 else if (leftvt == VT_I8 || rightvt == VT_I8)
3760 resvt = VT_I8;
3762 else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
3764 resvt = VT_BOOL;
3766 else if (leftvt == VT_I8 || rightvt == VT_I8)
3768 if (leftvt == VT_INT || rightvt == VT_INT)
3769 bFail = TRUE;
3770 else
3771 resvt = VT_I8;
3773 hres = pVarOr(&left, &right, &result);
3774 if (bFail)
3775 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
3776 "VarOr: %d|0x%X, %d|0x%X: Expected failure, got 0x%lX vt %d\n",
3777 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
3778 V_VT(&result));
3779 else
3780 ok(hres == S_OK && V_VT(&result) == resvt,
3781 "VarOr: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%lX vt %d\n",
3782 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
3783 V_VT(&result));
3788 /* Test returned values. Since we know the returned type is correct
3789 * and that we handle all combinations of invalid types, just check
3790 * that good type combinations produce the desired value.
3791 * FIXME: Test VT_DECIMAL/VT_DISPATCH
3793 VAROR(EMPTY,0,EMPTY,0,I2,0);
3794 VAROR(EMPTY,1,EMPTY,0,I2,0);
3795 VAROR(EMPTY,0,NULL,0,NULL,0);
3796 VAROR(EMPTY,0,I1,0,I4,0);
3797 VAROR(EMPTY,0,I1,1,I4,1);
3798 VAROR(EMPTY,0,UI1,0,I2,0);
3799 VAROR(EMPTY,0,UI1,1,I2,1);
3800 VAROR(EMPTY,0,I2,0,I2,0);
3801 VAROR(EMPTY,0,I2,1,I2,1);
3802 VAROR(EMPTY,0,UI2,0,I4,0);
3803 VAROR(EMPTY,0,UI2,1,I4,1);
3804 VAROR(EMPTY,0,I4,0,I4,0);
3805 VAROR(EMPTY,0,I4,1,I4,1);
3806 VAROR(EMPTY,0,UI4,0,I4,0);
3807 VAROR(EMPTY,0,UI4,1,I4,1);
3808 if (HAVE_OLEAUT32_I8)
3810 VAROR(EMPTY,0,I8,0,I8,0);
3811 VAROR(EMPTY,0,I8,1,I8,1);
3812 VAROR(EMPTY,0,UI8,0,I4,0);
3813 VAROR(EMPTY,0,UI8,1,I4,1);
3815 VAROR(EMPTY,0,INT,0,I4,0);
3816 VAROR(EMPTY,0,INT,1,I4,1);
3817 VAROR(EMPTY,0,UINT,0,I4,0);
3818 VAROR(EMPTY,0,UINT,1,I4,1);
3819 VAROR(EMPTY,0,BOOL,0,I2,0);
3820 VAROR(EMPTY,0,BOOL,1,I2,1);
3821 VAROR(EMPTY,0,R4,0,I4,0);
3822 VAROR(EMPTY,0,R4,1,I4,1);
3823 VAROR(EMPTY,0,R8,0,I4,0);
3824 VAROR(EMPTY,0,R8,1,I4,1);
3825 rbstr = SysAllocString(szFalse);
3826 VAROR(EMPTY,0,BSTR,rbstr,I2,0);
3827 rbstr = SysAllocString(szTrue);
3828 VAROR(EMPTY,0,BSTR,rbstr,I2,-1);
3829 VARORCY(EMPTY,0,10000,I4,1);
3831 /* NULL OR 0 = NULL. NULL OR n = n */
3832 VAROR(NULL,0,NULL,0,NULL,0);
3833 VAROR(NULL,1,NULL,0,NULL,0);
3834 VAROR(NULL,0,I1,0,NULL,0);
3835 VAROR(NULL,0,I1,1,I4,1);
3836 VAROR(NULL,0,UI1,0,NULL,0);
3837 VAROR(NULL,0,UI1,1,UI1,1);
3838 VAROR(NULL,0,I2,0,NULL,0);
3839 VAROR(NULL,0,I2,1,I2,1);
3840 VAROR(NULL,0,UI2,0,NULL,0);
3841 VAROR(NULL,0,UI2,1,I4,1);
3842 VAROR(NULL,0,I4,0,NULL,0);
3843 VAROR(NULL,0,I4,1,I4,1);
3844 VAROR(NULL,0,UI4,0,NULL,0);
3845 VAROR(NULL,0,UI4,1,I4,1);
3846 if (HAVE_OLEAUT32_I8)
3848 VAROR(NULL,0,I8,0,NULL,0);
3849 VAROR(NULL,0,I8,1,I8,1);
3850 VAROR(NULL,0,UI8,0,NULL,0);
3851 VAROR(NULL,0,UI8,1,I4,1);
3853 VAROR(NULL,0,INT,0,NULL,0);
3854 VAROR(NULL,0,INT,1,I4,1);
3855 VAROR(NULL,0,UINT,0,NULL,0);
3856 VAROR(NULL,0,UINT,1,I4,1);
3857 VAROR(NULL,0,BOOL,0,NULL,0);
3858 VAROR(NULL,0,BOOL,1,BOOL,1);
3859 VAROR(NULL,0,R4,0,NULL,0);
3860 VAROR(NULL,0,R4,1,I4,1);
3861 VAROR(NULL,0,R8,0,NULL,0);
3862 VAROR(NULL,0,R8,1,I4,1);
3863 rbstr = SysAllocString(szFalse);
3864 VAROR(NULL,0,BSTR,rbstr,NULL,0);
3865 rbstr = SysAllocString(szTrue);
3866 VAROR(NULL,0,BSTR,rbstr,BOOL,VARIANT_TRUE);
3867 VARORCY(NULL,0,10000,I4,1);
3868 VARORCY(NULL,0,0,NULL,0);
3870 VAROR(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
3871 VAROR(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
3872 VAROR(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
3873 VAROR(BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE,BOOL,VARIANT_FALSE);
3874 /* Assume x,y & y,x are the same from now on to reduce the number of tests */
3875 VAROR(BOOL,VARIANT_TRUE,I1,-1,I4,-1);
3876 VAROR(BOOL,VARIANT_TRUE,I1,0,I4,-1);
3877 VAROR(BOOL,VARIANT_FALSE,I1,0,I4,0);
3878 VAROR(BOOL,VARIANT_TRUE,UI1,255,I2,-1);
3879 VAROR(BOOL,VARIANT_TRUE,UI1,0,I2,-1);
3880 VAROR(BOOL,VARIANT_FALSE,UI1,0,I2,0);
3881 VAROR(BOOL,VARIANT_TRUE,I2,-1,I2,-1);
3882 VAROR(BOOL,VARIANT_TRUE,I2,0,I2,-1);
3883 VAROR(BOOL,VARIANT_FALSE,I2,0,I2,0);
3884 VAROR(BOOL,VARIANT_TRUE,UI2,65535,I4,-1);
3885 VAROR(BOOL,VARIANT_TRUE,UI2,0,I4,-1);
3886 VAROR(BOOL,VARIANT_FALSE,UI2,0,I4,0);
3887 VAROR(BOOL,VARIANT_TRUE,I4,-1,I4,-1);
3888 VAROR(BOOL,VARIANT_TRUE,I4,0,I4,-1);
3889 VAROR(BOOL,VARIANT_FALSE,I4,0,I4,0);
3890 VAROR(BOOL,VARIANT_TRUE,UI4,0xffffffff,I4,-1);
3891 VAROR(BOOL,VARIANT_TRUE,UI4,0,I4,-1);
3892 VAROR(BOOL,VARIANT_FALSE,UI4,0,I4,0);
3893 VAROR(BOOL,VARIANT_TRUE,R4,-1,I4,-1);
3894 VAROR(BOOL,VARIANT_TRUE,R4,0,I4,-1);
3895 VAROR(BOOL,VARIANT_FALSE,R4,0,I4,0);
3896 VAROR(BOOL,VARIANT_TRUE,R8,-1,I4,-1);
3897 VAROR(BOOL,VARIANT_TRUE,R8,0,I4,-1);
3898 VAROR(BOOL,VARIANT_FALSE,R8,0,I4,0);
3899 VAROR(BOOL,VARIANT_TRUE,DATE,-1,I4,-1);
3900 VAROR(BOOL,VARIANT_TRUE,DATE,0,I4,-1);
3901 VAROR(BOOL,VARIANT_FALSE,DATE,0,I4,0);
3902 if (HAVE_OLEAUT32_I8)
3904 VAROR(BOOL,VARIANT_TRUE,I8,-1,I8,-1);
3905 VAROR(BOOL,VARIANT_TRUE,I8,0,I8,-1);
3906 VAROR(BOOL,VARIANT_FALSE,I8,0,I8,0);
3907 /* This returns DISP_E_OVERFLOW which indicates that a conversion
3908 * to I4 is performed.
3910 /* VAROR(BOOL,VARIANT_TRUE,UI8,-1,I4,-1); */
3911 VAROR(BOOL,VARIANT_TRUE,UI8,0,I4,-1);
3912 VAROR(BOOL,VARIANT_FALSE,UI8,0,I4,0);
3914 VAROR(BOOL,VARIANT_TRUE,INT,-1,I4,-1);
3915 VAROR(BOOL,VARIANT_TRUE,INT,0,I4,-1);
3916 VAROR(BOOL,VARIANT_FALSE,INT,0,I4,0);
3917 VAROR(BOOL,VARIANT_TRUE,UINT,0xffffffff,I4,-1);
3918 VAROR(BOOL,VARIANT_TRUE,UINT,0,I4,-1);
3919 VAROR(BOOL,VARIANT_FALSE,UINT,0,I4,0);
3920 rbstr = SysAllocString(szFalse);
3921 VAROR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_FALSE);
3922 VAROR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
3923 rbstr = SysAllocString(szTrue);
3924 VAROR(BOOL,VARIANT_FALSE,BSTR,rbstr,BOOL,VARIANT_TRUE);
3925 VAROR(BOOL,VARIANT_TRUE,BSTR,rbstr,BOOL,VARIANT_TRUE);
3926 VARORCY(BOOL,VARIANT_TRUE,10000,I4,-1);
3927 VARORCY(BOOL,VARIANT_TRUE,0,I4,-1);
3928 VARORCY(BOOL,VARIANT_FALSE,0,I4,0);
3930 VAROR(I1,-1,I1,-1,I4,-1);
3931 VAROR(I1,-1,I1,0,I4,-1);
3932 VAROR(I1,0,I1,0,I4,0);
3933 VAROR(I1,-1,UI1,255,I4,-1);
3934 VAROR(I1,-1,UI1,0,I4,-1);
3935 VAROR(I1,0,UI1,0,I4,0);
3936 VAROR(I1,-1,I2,-1,I4,-1);
3937 VAROR(I1,-1,I2,0,I4,-1);
3938 VAROR(I1,0,I2,0,I4,0);
3939 VAROR(I1,-1,UI2,65535,I4,-1);
3940 VAROR(I1,-1,UI2,0,I4,-1);
3941 VAROR(I1,0,UI2,0,I4,0);
3942 VAROR(I1,-1,I4,-1,I4,-1);
3943 VAROR(I1,-1,I4,0,I4,-1);
3944 VAROR(I1,0,I4,0,I4,0);
3945 VAROR(I1,-1,UI4,0xffffffff,I4,-1);
3946 VAROR(I1,-1,UI4,0,I4,-1);
3947 VAROR(I1,0,UI4,0,I4,0);
3948 VAROR(I1,-1,R4,-1,I4,-1);
3949 VAROR(I1,-1,R4,0,I4,-1);
3950 VAROR(I1,0,R4,0,I4,0);
3951 VAROR(I1,-1,R8,-1,I4,-1);
3952 VAROR(I1,-1,R8,0,I4,-1);
3953 VAROR(I1,0,R8,0,I4,0);
3954 VAROR(I1,-1,DATE,-1,I4,-1);
3955 VAROR(I1,-1,DATE,0,I4,-1);
3956 VAROR(I1,0,DATE,0,I4,0);
3957 if (HAVE_OLEAUT32_I8)
3959 VAROR(I1,-1,I8,-1,I8,-1);
3960 VAROR(I1,-1,I8,0,I8,-1);
3961 VAROR(I1,0,I8,0,I8,0);
3962 VAROR(I1,-1,UI8,0,I4,-1);
3963 VAROR(I1,0,UI8,0,I4,0);
3965 VAROR(I1,-1,INT,-1,I4,-1);
3966 VAROR(I1,-1,INT,0,I4,-1);
3967 VAROR(I1,0,INT,0,I4,0);
3968 VAROR(I1,-1,UINT,0xffffffff,I4,-1);
3969 VAROR(I1,-1,UINT,0,I4,-1);
3970 VAROR(I1,0,UINT,0,I4,0);
3971 rbstr = SysAllocString(szFalse);
3972 VAROR(I1,0,BSTR,rbstr,I4,0);
3973 VAROR(I1,-1,BSTR,rbstr,I4,-1);
3974 rbstr = SysAllocString(szTrue);
3975 VAROR(I1,0,BSTR,rbstr,I4,-1);
3976 VAROR(I1,-1,BSTR,rbstr,I4,-1);
3977 VARORCY(I1,-1,10000,I4,-1);
3978 VARORCY(I1,-1,0,I4,-1);
3979 VARORCY(I1,0,0,I4,0);
3981 VAROR(UI1,255,UI1,255,UI1,255);
3982 VAROR(UI1,255,UI1,0,UI1,255);
3983 VAROR(UI1,0,UI1,0,UI1,0);
3984 VAROR(UI1,255,I2,-1,I2,-1);
3985 VAROR(UI1,255,I2,0,I2,255);
3986 VAROR(UI1,0,I2,0,I2,0);
3987 VAROR(UI1,255,UI2,65535,I4,65535);
3988 VAROR(UI1,255,UI2,0,I4,255);
3989 VAROR(UI1,0,UI2,0,I4,0);
3990 VAROR(UI1,255,I4,-1,I4,-1);
3991 VAROR(UI1,255,I4,0,I4,255);
3992 VAROR(UI1,0,I4,0,I4,0);
3993 VAROR(UI1,255,UI4,0xffffffff,I4,-1);
3994 VAROR(UI1,255,UI4,0,I4,255);
3995 VAROR(UI1,0,UI4,0,I4,0);
3996 VAROR(UI1,255,R4,-1,I4,-1);
3997 VAROR(UI1,255,R4,0,I4,255);
3998 VAROR(UI1,0,R4,0,I4,0);
3999 VAROR(UI1,255,R8,-1,I4,-1);
4000 VAROR(UI1,255,R8,0,I4,255);
4001 VAROR(UI1,0,R8,0,I4,0);
4002 VAROR(UI1,255,DATE,-1,I4,-1);
4003 VAROR(UI1,255,DATE,0,I4,255);
4004 VAROR(UI1,0,DATE,0,I4,0);
4005 if (HAVE_OLEAUT32_I8)
4007 VAROR(UI1,255,I8,-1,I8,-1);
4008 VAROR(UI1,255,I8,0,I8,255);
4009 VAROR(UI1,0,I8,0,I8,0);
4010 VAROR(UI1,255,UI8,0,I4,255);
4011 VAROR(UI1,0,UI8,0,I4,0);
4013 VAROR(UI1,255,INT,-1,I4,-1);
4014 VAROR(UI1,255,INT,0,I4,255);
4015 VAROR(UI1,0,INT,0,I4,0);
4016 VAROR(UI1,255,UINT,0xffffffff,I4,-1);
4017 VAROR(UI1,255,UINT,0,I4,255);
4018 VAROR(UI1,0,UINT,0,I4,0);
4019 rbstr = SysAllocString(szFalse);
4020 VAROR(UI1,0,BSTR,rbstr,I2,0);
4021 VAROR(UI1,255,BSTR,rbstr,I2,255);
4022 rbstr = SysAllocString(szTrue);
4023 VAROR(UI1,0,BSTR,rbstr,I2,-1);
4024 VAROR(UI1,255,BSTR,rbstr,I2,-1);
4025 VARORCY(UI1,255,10000,I4,255);
4026 VARORCY(UI1,255,0,I4,255);
4027 VARORCY(UI1,0,0,I4,0);
4029 VAROR(I2,-1,I2,-1,I2,-1);
4030 VAROR(I2,-1,I2,0,I2,-1);
4031 VAROR(I2,0,I2,0,I2,0);
4032 VAROR(I2,-1,UI2,65535,I4,-1);
4033 VAROR(I2,-1,UI2,0,I4,-1);
4034 VAROR(I2,0,UI2,0,I4,0);
4035 VAROR(I2,-1,I4,-1,I4,-1);
4036 VAROR(I2,-1,I4,0,I4,-1);
4037 VAROR(I2,0,I4,0,I4,0);
4038 VAROR(I2,-1,UI4,0xffffffff,I4,-1);
4039 VAROR(I2,-1,UI4,0,I4,-1);
4040 VAROR(I2,0,UI4,0,I4,0);
4041 VAROR(I2,-1,R4,-1,I4,-1);
4042 VAROR(I2,-1,R4,0,I4,-1);
4043 VAROR(I2,0,R4,0,I4,0);
4044 VAROR(I2,-1,R8,-1,I4,-1);
4045 VAROR(I2,-1,R8,0,I4,-1);
4046 VAROR(I2,0,R8,0,I4,0);
4047 VAROR(I2,-1,DATE,-1,I4,-1);
4048 VAROR(I2,-1,DATE,0,I4,-1);
4049 VAROR(I2,0,DATE,0,I4,0);
4050 if (HAVE_OLEAUT32_I8)
4052 VAROR(I2,-1,I8,-1,I8,-1);
4053 VAROR(I2,-1,I8,0,I8,-1);
4054 VAROR(I2,0,I8,0,I8,0);
4055 VAROR(I2,-1,UI8,0,I4,-1);
4056 VAROR(I2,0,UI8,0,I4,0);
4058 VAROR(I2,-1,INT,-1,I4,-1);
4059 VAROR(I2,-1,INT,0,I4,-1);
4060 VAROR(I2,0,INT,0,I4,0);
4061 VAROR(I2,-1,UINT,0xffffffff,I4,-1);
4062 VAROR(I2,-1,UINT,0,I4,-1);
4063 VAROR(I2,0,UINT,0,I4,0);
4064 rbstr = SysAllocString(szFalse);
4065 VAROR(I2,0,BSTR,rbstr,I2,0);
4066 VAROR(I2,-1,BSTR,rbstr,I2,-1);
4067 rbstr = SysAllocString(szTrue);
4068 VAROR(I2,0,BSTR,rbstr,I2,-1);
4069 VAROR(I2,-1,BSTR,rbstr,I2,-1);
4070 VARORCY(I2,-1,10000,I4,-1);
4071 VARORCY(I2,-1,0,I4,-1);
4072 VARORCY(I2,0,0,I4,0);
4074 VAROR(UI2,65535,UI2,65535,I4,65535);
4075 VAROR(UI2,65535,UI2,0,I4,65535);
4076 VAROR(UI2,0,UI2,0,I4,0);
4077 VAROR(UI2,65535,I4,-1,I4,-1);
4078 VAROR(UI2,65535,I4,0,I4,65535);
4079 VAROR(UI2,0,I4,0,I4,0);
4080 VAROR(UI2,65535,UI4,0xffffffff,I4,-1);
4081 VAROR(UI2,65535,UI4,0,I4,65535);
4082 VAROR(UI2,0,UI4,0,I4,0);
4083 VAROR(UI2,65535,R4,-1,I4,-1);
4084 VAROR(UI2,65535,R4,0,I4,65535);
4085 VAROR(UI2,0,R4,0,I4,0);
4086 VAROR(UI2,65535,R8,-1,I4,-1);
4087 VAROR(UI2,65535,R8,0,I4,65535);
4088 VAROR(UI2,0,R8,0,I4,0);
4089 VAROR(UI2,65535,DATE,-1,I4,-1);
4090 VAROR(UI2,65535,DATE,0,I4,65535);
4091 VAROR(UI2,0,DATE,0,I4,0);
4092 if (HAVE_OLEAUT32_I8)
4094 VAROR(UI2,65535,I8,-1,I8,-1);
4095 VAROR(UI2,65535,I8,0,I8,65535);
4096 VAROR(UI2,0,I8,0,I8,0);
4097 VAROR(UI2,65535,UI8,0,I4,65535);
4098 VAROR(UI2,0,UI8,0,I4,0);
4100 VAROR(UI2,65535,INT,-1,I4,-1);
4101 VAROR(UI2,65535,INT,0,I4,65535);
4102 VAROR(UI2,0,INT,0,I4,0);
4103 VAROR(UI2,65535,UINT,0xffffffff,I4,-1);
4104 VAROR(UI2,65535,UINT,0,I4,65535);
4105 VAROR(UI2,0,UINT,0,I4,0);
4106 rbstr = SysAllocString(szFalse);
4107 VAROR(UI2,0,BSTR,rbstr,I4,0);
4108 VAROR(UI2,65535,BSTR,rbstr,I4,65535);
4109 rbstr = SysAllocString(szTrue);
4110 VAROR(UI2,0,BSTR,rbstr,I4,-1);
4111 VAROR(UI2,65535,BSTR,rbstr,I4,-1);
4112 VARORCY(UI2,65535,10000,I4,65535);
4113 VARORCY(UI2,65535,0,I4,65535);
4114 VARORCY(UI2,0,0,I4,0);
4116 VAROR(I4,-1,I4,-1,I4,-1);
4117 VAROR(I4,-1,I4,0,I4,-1);
4118 VAROR(I4,0,I4,0,I4,0);
4119 VAROR(I4,-1,UI4,0xffffffff,I4,-1);
4120 VAROR(I4,-1,UI4,0,I4,-1);
4121 VAROR(I4,0,UI4,0,I4,0);
4122 VAROR(I4,-1,R4,-1,I4,-1);
4123 VAROR(I4,-1,R4,0,I4,-1);
4124 VAROR(I4,0,R4,0,I4,0);
4125 VAROR(I4,-1,R8,-1,I4,-1);
4126 VAROR(I4,-1,R8,0,I4,-1);
4127 VAROR(I4,0,R8,0,I4,0);
4128 VAROR(I4,-1,DATE,-1,I4,-1);
4129 VAROR(I4,-1,DATE,0,I4,-1);
4130 VAROR(I4,0,DATE,0,I4,0);
4131 if (HAVE_OLEAUT32_I8)
4133 VAROR(I4,-1,I8,-1,I8,-1);
4134 VAROR(I4,-1,I8,0,I8,-1);
4135 VAROR(I4,0,I8,0,I8,0);
4136 VAROR(I4,-1,UI8,0,I4,-1);
4137 VAROR(I4,0,UI8,0,I4,0);
4139 VAROR(I4,-1,INT,-1,I4,-1);
4140 VAROR(I4,-1,INT,0,I4,-1);
4141 VAROR(I4,0,INT,0,I4,0);
4142 VAROR(I4,-1,UINT,0xffffffff,I4,-1);
4143 VAROR(I4,-1,UINT,0,I4,-1);
4144 VAROR(I4,0,UINT,0,I4,0);
4145 rbstr = SysAllocString(szFalse);
4146 VAROR(I4,0,BSTR,rbstr,I4,0);
4147 VAROR(I4,-1,BSTR,rbstr,I4,-1);
4148 rbstr = SysAllocString(szTrue);
4149 VAROR(I4,0,BSTR,rbstr,I4,-1);
4150 VAROR(I4,-1,BSTR,rbstr,I4,-1);
4151 VARORCY(I4,-1,10000,I4,-1);
4152 VARORCY(I4,-1,0,I4,-1);
4153 VARORCY(I4,0,0,I4,0);
4155 VAROR(UI4,0xffffffff,UI4,0xffffffff,I4,-1);
4156 VAROR(UI4,0xffffffff,UI4,0,I4,-1);
4157 VAROR(UI4,0,UI4,0,I4,0);
4158 VAROR(UI4,0xffffffff,R4,-1,I4,-1);
4159 VAROR(UI4,0xffffffff,R4,0,I4,-1);
4160 VAROR(UI4,0,R4,0,I4,0);
4161 VAROR(UI4,0xffffffff,R8,-1,I4,-1);
4162 VAROR(UI4,0xffffffff,R8,0,I4,-1);
4163 VAROR(UI4,0,R8,0,I4,0);
4164 VAROR(UI4,0xffffffff,DATE,-1,I4,-1);
4165 VAROR(UI4,0xffffffff,DATE,0,I4,-1);
4166 VAROR(UI4,0,DATE,0,I4,0);
4167 if (HAVE_OLEAUT32_I8)
4169 VAROR(UI4,0xffffffff,I8,-1,I8,-1);
4170 VAROR(UI4,0xffffffff,I8,0,I8,0xffffffff);
4171 VAROR(UI4,0,I8,0,I8,0);
4172 VAROR(UI4,0xffffffff,UI8,0,I4,-1);
4173 VAROR(UI4,0,UI8,0,I4,0);
4175 VAROR(UI4,0xffffffff,INT,-1,I4,-1);
4176 VAROR(UI4,0xffffffff,INT,0,I4,-1);
4177 VAROR(UI4,0,INT,0,I4,0);
4178 VAROR(UI4,0xffffffff,UINT,0xffffffff,I4,-1);
4179 VAROR(UI4,0xffffffff,UINT,0,I4,-1);
4180 VAROR(UI4,0,UINT,0,I4,0);
4181 rbstr = SysAllocString(szFalse);
4182 VAROR(UI4,0,BSTR,rbstr,I4,0);
4183 VAROR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
4184 rbstr = SysAllocString(szTrue);
4185 VAROR(UI4,0,BSTR,rbstr,I4,-1);
4186 VAROR(UI4,0xffffffff,BSTR,rbstr,I4,-1);
4187 VARORCY(UI4,0xffffffff,10000,I4,-1);
4188 VARORCY(UI4,0xffffffff,0,I4,-1);
4189 VARORCY(UI4,0,0,I4,0);
4191 VAROR(R4,-1,R4,-1,I4,-1);
4192 VAROR(R4,-1,R4,0,I4,-1);
4193 VAROR(R4,0,R4,0,I4,0);
4194 VAROR(R4,-1,R8,-1,I4,-1);
4195 VAROR(R4,-1,R8,0,I4,-1);
4196 VAROR(R4,0,R8,0,I4,0);
4197 VAROR(R4,-1,DATE,-1,I4,-1);
4198 VAROR(R4,-1,DATE,0,I4,-1);
4199 VAROR(R4,0,DATE,0,I4,0);
4200 if (HAVE_OLEAUT32_I8)
4202 VAROR(R4,-1,I8,-1,I8,-1);
4203 VAROR(R4,-1,I8,0,I8,-1);
4204 VAROR(R4,0,I8,0,I8,0);
4205 VAROR(R4,-1,UI8,0,I4,-1);
4206 VAROR(R4,0,UI8,0,I4,0);
4208 VAROR(R4,-1,INT,-1,I4,-1);
4209 VAROR(R4,-1,INT,0,I4,-1);
4210 VAROR(R4,0,INT,0,I4,0);
4211 VAROR(R4,-1,UINT,0xffffffff,I4,-1);
4212 VAROR(R4,-1,UINT,0,I4,-1);
4213 VAROR(R4,0,UINT,0,I4,0);
4214 rbstr = SysAllocString(szFalse);
4215 VAROR(R4,0,BSTR,rbstr,I4,0);
4216 VAROR(R4,-1,BSTR,rbstr,I4,-1);
4217 rbstr = SysAllocString(szTrue);
4218 VAROR(R4,0,BSTR,rbstr,I4,-1);
4219 VAROR(R4,-1,BSTR,rbstr,I4,-1);
4220 VARORCY(R4,-1,10000,I4,-1);
4221 VARORCY(R4,-1,0,I4,-1);
4222 VARORCY(R4,0,0,I4,0);
4224 VAROR(R8,-1,R8,-1,I4,-1);
4225 VAROR(R8,-1,R8,0,I4,-1);
4226 VAROR(R8,0,R8,0,I4,0);
4227 VAROR(R8,-1,DATE,-1,I4,-1);
4228 VAROR(R8,-1,DATE,0,I4,-1);
4229 VAROR(R8,0,DATE,0,I4,0);
4230 if (HAVE_OLEAUT32_I8)
4232 VAROR(R8,-1,I8,-1,I8,-1);
4233 VAROR(R8,-1,I8,0,I8,-1);
4234 VAROR(R8,0,I8,0,I8,0);
4235 VAROR(R8,-1,UI8,0,I4,-1);
4236 VAROR(R8,0,UI8,0,I4,0);
4238 VAROR(R8,-1,INT,-1,I4,-1);
4239 VAROR(R8,-1,INT,0,I4,-1);
4240 VAROR(R8,0,INT,0,I4,0);
4241 VAROR(R8,-1,UINT,0xffffffff,I4,-1);
4242 VAROR(R8,-1,UINT,0,I4,-1);
4243 VAROR(R8,0,UINT,0,I4,0);
4244 rbstr = SysAllocString(szFalse);
4245 VAROR(R8,0,BSTR,rbstr,I4,0);
4246 VAROR(R8,-1,BSTR,rbstr,I4,-1);
4247 rbstr = SysAllocString(szTrue);
4248 VAROR(R8,0,BSTR,rbstr,I4,-1);
4249 VAROR(R8,-1,BSTR,rbstr,I4,-1);
4250 VARORCY(R8,-1,10000,I4,-1);
4251 VARORCY(R8,-1,0,I4,-1);
4252 VARORCY(R8,0,0,I4,0);
4254 VAROR(DATE,-1,DATE,-1,I4,-1);
4255 VAROR(DATE,-1,DATE,0,I4,-1);
4256 VAROR(DATE,0,DATE,0,I4,0);
4257 if (HAVE_OLEAUT32_I8)
4259 VAROR(DATE,-1,I8,-1,I8,-1);
4260 VAROR(DATE,-1,I8,0,I8,-1);
4261 VAROR(DATE,0,I8,0,I8,0);
4262 VAROR(DATE,-1,UI8,0,I4,-1);
4263 VAROR(DATE,0,UI8,0,I4,0);
4265 VAROR(DATE,-1,INT,-1,I4,-1);
4266 VAROR(DATE,-1,INT,0,I4,-1);
4267 VAROR(DATE,0,INT,0,I4,0);
4268 VAROR(DATE,-1,UINT,0xffffffff,I4,-1);
4269 VAROR(DATE,-1,UINT,0,I4,-1);
4270 VAROR(DATE,0,UINT,0,I4,0);
4271 rbstr = SysAllocString(szFalse);
4272 VAROR(DATE,0,BSTR,rbstr,I4,0);
4273 VAROR(DATE,-1,BSTR,rbstr,I4,-1);
4274 rbstr = SysAllocString(szTrue);
4275 VAROR(DATE,0,BSTR,rbstr,I4,-1);
4276 VAROR(DATE,-1,BSTR,rbstr,I4,-1);
4277 VARORCY(DATE,-1,10000,I4,-1);
4278 VARORCY(DATE,-1,0,I4,-1);
4279 VARORCY(DATE,0,0,I4,0);
4281 if (HAVE_OLEAUT32_I8)
4283 VAROR(I8,-1,I8,-1,I8,-1);
4284 VAROR(I8,-1,I8,0,I8,-1);
4285 VAROR(I8,0,I8,0,I8,0);
4286 VAROR(I8,-1,UI8,0,I8,-1);
4287 VAROR(I8,0,UI8,0,I8,0);
4288 /* These overflow under native and Wine
4289 VAROR(I8,-1,INT,-1,I4,-1);
4290 VAROR(I8,-1,INT,0,I4,-1);
4291 VAROR(I8,0,INT,0,I4,0); */
4292 VAROR(I8,-1,UINT,0xffffffff,I8,-1);
4293 VAROR(I8,-1,UINT,0,I8,-1);
4294 VAROR(I8,0,UINT,0,I8,0);
4295 rbstr = SysAllocString(szFalse);
4296 VAROR(I8,0,BSTR,rbstr,I8,0);
4297 VAROR(I8,-1,BSTR,rbstr,I8,-1);
4298 rbstr = SysAllocString(szTrue);
4299 VAROR(I8,0,BSTR,rbstr,I8,-1);
4300 VAROR(I8,-1,BSTR,rbstr,I8,-1);
4301 VARORCY(I8,-1,10000,I8,-1);
4302 VARORCY(I8,-1,0,I8,-1);
4303 VARORCY(I8,0,0,I8,0);
4305 VAROR(UI8,0xffff,UI8,0xffff,I4,0xffff);
4306 VAROR(UI8,0xffff,UI8,0,I4,0xffff);
4307 VAROR(UI8,0,UI8,0,I4,0);
4308 VAROR(UI8,0xffff,INT,-1,I4,-1);
4309 VAROR(UI8,0xffff,INT,0,I4,0xffff);
4310 VAROR(UI8,0,INT,0,I4,0);
4311 VAROR(UI8,0xffff,UINT,0xffff,I4,0xffff);
4312 VAROR(UI8,0xffff,UINT,0,I4,0xffff);
4313 VAROR(UI8,0,UINT,0,I4,0);
4314 rbstr = SysAllocString(szFalse);
4315 VAROR(UI8,0,BSTR,rbstr,I4,0);
4316 VAROR(UI8,0xffff,BSTR,rbstr,I4,0xffff);
4317 rbstr = SysAllocString(szTrue);
4318 VAROR(UI8,0,BSTR,rbstr,I4,-1);
4319 VAROR(UI8,0xffff,BSTR,rbstr,I4,-1);
4320 VARORCY(UI8,0xffff,10000,I4,0xffff);
4321 VARORCY(UI8,0xffff,0,I4,0xffff);
4322 VARORCY(UI8,0,0,I4,0);
4325 VAROR(INT,-1,INT,-1,I4,-1);
4326 VAROR(INT,-1,INT,0,I4,-1);
4327 VAROR(INT,0,INT,0,I4,0);
4328 VAROR(INT,-1,UINT,0xffff,I4,-1);
4329 VAROR(INT,-1,UINT,0,I4,-1);
4330 VAROR(INT,0,UINT,0,I4,0);
4331 rbstr = SysAllocString(szFalse);
4332 VAROR(INT,0,BSTR,rbstr,I4,0);
4333 VAROR(INT,-1,BSTR,rbstr,I4,-1);
4334 rbstr = SysAllocString(szTrue);
4335 VAROR(INT,0,BSTR,rbstr,I4,-1);
4336 VAROR(INT,-1,BSTR,rbstr,I4,-1);
4337 VARORCY(INT,-1,10000,I4,-1);
4338 VARORCY(INT,-1,0,I4,-1);
4339 VARORCY(INT,0,0,I4,0);
4341 VAROR(UINT,0xffff,UINT,0xffff,I4,0xffff);
4342 VAROR(UINT,0xffff,UINT,0,I4,0xffff);
4343 VAROR(UINT,0,UINT,0,I4,0);
4344 rbstr = SysAllocString(szFalse);
4345 VAROR(UINT,0,BSTR,rbstr,I4,0);
4346 VAROR(UINT,0xffff,BSTR,rbstr,I4,0xffff);
4347 rbstr = SysAllocString(szTrue);
4348 VAROR(UINT,0,BSTR,rbstr,I4,-1);
4349 VAROR(UINT,0xffff,BSTR,rbstr,I4,-1);
4350 VARORCY(UINT,0xffff,10000,I4,0xffff);
4351 VARORCY(UINT,0xffff,0,I4,0xffff);
4352 VARORCY(UINT,0,0,I4,0);
4354 lbstr = SysAllocString(szFalse);
4355 rbstr = SysAllocString(szFalse);
4356 VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,0);
4357 rbstr = SysAllocString(szTrue);
4358 VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
4359 lbstr = SysAllocString(szTrue);
4360 VAROR(BSTR,lbstr,BSTR,rbstr,BOOL,VARIANT_TRUE);
4361 VARORCY(BSTR,lbstr,10000,I4,-1);
4362 lbstr = SysAllocString(szFalse);
4363 VARORCY(BSTR,lbstr,10000,I4,1);
4366 static HRESULT (WINAPI *pVarEqv)(LPVARIANT,LPVARIANT,LPVARIANT);
4368 static const char *szVarEqvFail = "VarEqv(%d,%d): expected 0x0,%d,%d, got 0x%lX,%d,%d\n";
4369 #define VAREQV(vt1,val1,vt2,val2,rvt,rval) \
4370 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
4371 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
4372 memset(&result,0,sizeof(result)); hres = pVarEqv(&left,&right,&result); \
4373 ok(hres == S_OK && V_VT(&result) == VT_##rvt && V_##rvt(&result) == (rval), \
4374 szVarEqvFail, VT_##vt1, VT_##vt2, \
4375 VT_##rvt, (int)(rval), hres, V_VT(&result), (int)V_##rvt(&result))
4377 static void test_VarEqv(void)
4379 VARIANT left, right, result;
4380 VARTYPE i;
4381 HRESULT hres;
4383 CHECKPTR(VarEqv);
4385 /* Test all possible flag/vt combinations & the resulting vt type */
4386 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
4388 VARTYPE leftvt, rightvt, resvt;
4390 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
4392 SKIPTESTS(leftvt);
4394 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
4396 BOOL bFail = FALSE;
4398 SKIPTESTS(rightvt);
4400 if (leftvt == VT_BSTR || rightvt == VT_BSTR ||
4401 leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
4402 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
4403 continue;
4405 memset(&left, 0, sizeof(left));
4406 memset(&right, 0, sizeof(right));
4407 V_VT(&left) = leftvt | ExtraFlags[i];
4408 V_VT(&right) = rightvt | ExtraFlags[i];
4409 V_VT(&result) = VT_EMPTY;
4410 resvt = VT_I4;
4412 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
4413 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
4414 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
4415 leftvt == VT_CLSID || rightvt == VT_CLSID ||
4416 leftvt == VT_RECORD || rightvt == VT_RECORD ||
4417 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
4418 leftvt == VT_ERROR || rightvt == VT_ERROR)
4420 bFail = TRUE;
4422 if (leftvt == VT_EMPTY || rightvt == VT_EMPTY)
4424 if (leftvt == rightvt ||
4425 leftvt == VT_I2 || rightvt == VT_I2 ||
4426 leftvt == VT_UI1 || rightvt == VT_UI1 ||
4427 leftvt == VT_BOOL || rightvt == VT_BOOL)
4428 resvt = VT_I2;
4429 else if (leftvt == VT_NULL || rightvt == VT_NULL)
4430 resvt = VT_NULL;
4431 else if (leftvt == VT_I8 || rightvt == VT_I8)
4432 resvt = VT_I8;
4434 else if (leftvt == VT_NULL || rightvt == VT_NULL)
4436 resvt = VT_NULL;
4438 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
4440 if (leftvt == rightvt)
4441 resvt = VT_UI1;
4442 else if (leftvt == rightvt ||
4443 leftvt == VT_I2 || rightvt == VT_I2 ||
4444 leftvt == VT_BOOL || rightvt == VT_BOOL)
4446 resvt = VT_I2;
4448 else if (leftvt == VT_I8 || rightvt == VT_I8)
4449 resvt = VT_I8;
4451 else if (leftvt == VT_I2 || rightvt == VT_I2)
4453 if (leftvt == rightvt ||
4454 leftvt == VT_BOOL || rightvt == VT_BOOL)
4455 resvt = VT_I2;
4456 else if (leftvt == VT_I8 || rightvt == VT_I8)
4457 resvt = VT_I8;
4459 else if (leftvt == VT_BOOL && rightvt == VT_BOOL)
4461 resvt = VT_BOOL;
4463 else if (leftvt == VT_I8 || rightvt == VT_I8)
4465 if (leftvt == VT_INT || rightvt == VT_INT)
4466 bFail = TRUE;
4467 else
4468 resvt = VT_I8;
4470 hres = pVarEqv(&left, &right, &result);
4471 if (bFail)
4472 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
4473 "VarEqv: %d|0x%X, %d|0x%X: Expected failure, got 0x%lX vt %d\n",
4474 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
4475 V_VT(&result));
4476 else
4477 ok(hres == S_OK && V_VT(&result) == resvt,
4478 "VarEqv: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%lX vt %d\n",
4479 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
4480 V_VT(&result));
4485 /* Test returned values */
4486 VAREQV(BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE,BOOL,VARIANT_TRUE);
4487 VAREQV(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
4488 VAREQV(BOOL,TRUE,BOOL,TRUE,BOOL,VARIANT_TRUE);
4489 VAREQV(BOOL,FALSE,BOOL,FALSE,BOOL,VARIANT_TRUE);
4490 VAREQV(BOOL,TRUE,BOOL,FALSE,BOOL,-2);
4491 VAREQV(BOOL,FALSE,BOOL,TRUE,BOOL,-2);
4492 VAREQV(BOOL,6,BOOL,7,BOOL,-2);
4493 VAREQV(BOOL,6,BOOL,6,BOOL,VARIANT_TRUE);
4494 VAREQV(BOOL,VARIANT_TRUE,I2,VARIANT_TRUE,I2,VARIANT_TRUE);
4495 VAREQV(BOOL,VARIANT_TRUE,I2,VARIANT_FALSE,I2,VARIANT_FALSE);
4496 VAREQV(BOOL,6,I2,7,I2,-2);
4497 VAREQV(UI1,1,UI1,1,UI1,255);
4498 VAREQV(UI1,1,UI1,0,UI1,254);
4499 VAREQV(UI1,0,UI1,1,UI1,254);
4500 if (HAVE_OLEAUT32_I8)
4502 VAREQV(UI4,VARIANT_FALSE,I8,VARIANT_FALSE,I8,-1);
4503 VAREQV(UI4,5,I8,19,I8,-23);
4504 VAREQV(UI4,VARIANT_FALSE,UI8,VARIANT_FALSE,I4,-1);
4508 static HRESULT (WINAPI *pVarMul)(LPVARIANT,LPVARIANT,LPVARIANT);
4510 static const char *szVarMulI4 = "VarMul(%d,%d): expected 0x0,%d,%d, got 0x%lX,%d,%d\n";
4511 static const char *szVarMulR8 = "VarMul(%d,%d): expected 0x0,%d,%f, got 0x%lX,%d,%f\n";
4513 #define VARMUL(vt1,val1,vt2,val2,rvt,rval) \
4514 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
4515 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
4516 memset(&result,0,sizeof(result)); hres = pVarMul(&left,&right,&result); \
4517 if (VT_##rvt == VT_R4 || VT_##rvt == VT_R8) { \
4518 ok(hres == S_OK && V_VT(&result) == VT_##rvt && \
4519 EQ_FLOAT(V_##rvt(&result), rval), \
4520 szVarMulR8, VT_##vt1, VT_##vt2, \
4521 VT_##rvt, (double)(rval), hres, V_VT(&result), (double)V_##rvt(&result)); \
4522 } else { \
4523 ok(hres == S_OK && V_VT(&result) == VT_##rvt && V_##rvt(&result) == (rval), \
4524 szVarMulI4, VT_##vt1, VT_##vt2, \
4525 VT_##rvt, (int)(rval), hres, V_VT(&result), (int)V_##rvt(&result)); }
4527 static void test_VarMul(void)
4529 static const WCHAR sz12[] = {'1','2','\0'};
4530 VARIANT left, right, result, cy, dec;
4531 VARTYPE i;
4532 BSTR lbstr, rbstr;
4533 HRESULT hres;
4534 double r;
4536 CHECKPTR(VarMul);
4538 lbstr = SysAllocString(sz12);
4539 rbstr = SysAllocString(sz12);
4541 /* Test all possible flag/vt combinations & the resulting vt type */
4542 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
4544 VARTYPE leftvt, rightvt, resvt;
4546 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
4549 SKIPTESTS(leftvt);
4551 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
4553 BOOL bFail = FALSE;
4555 SKIPTESTS(rightvt);
4557 if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
4558 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN)
4559 continue;
4561 memset(&left, 0, sizeof(left));
4562 memset(&right, 0, sizeof(right));
4563 V_VT(&left) = leftvt | ExtraFlags[i];
4564 if (leftvt == VT_BSTR)
4565 V_BSTR(&left) = lbstr;
4566 V_VT(&right) = rightvt | ExtraFlags[i];
4567 if (rightvt == VT_BSTR)
4568 V_BSTR(&right) = rbstr;
4569 V_VT(&result) = VT_EMPTY;
4570 resvt = VT_UNKNOWN;
4572 /* Don't ask me why but native VarMul cannot handle:
4573 VT_I1, VT_UI2, VT_UI4, VT_INT, VT_UINT and VT_UI8.
4574 Tested with DCOM98, Win2k, WinXP */
4575 if (ExtraFlags[i] & VT_ARRAY || ExtraFlags[i] & VT_BYREF ||
4576 !IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
4577 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
4578 leftvt == VT_CLSID || rightvt == VT_CLSID ||
4579 leftvt == VT_RECORD || rightvt == VT_RECORD ||
4580 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
4581 leftvt == VT_ERROR || rightvt == VT_ERROR ||
4582 leftvt == VT_I1 || rightvt == VT_I1 ||
4583 leftvt == VT_UI2 || rightvt == VT_UI2 ||
4584 leftvt == VT_UI4 || rightvt == VT_UI4 ||
4585 leftvt == VT_UI8 || rightvt == VT_UI8 ||
4586 leftvt == VT_INT || rightvt == VT_INT ||
4587 leftvt == VT_UINT || rightvt == VT_UINT) {
4588 bFail = TRUE;
4591 if (leftvt == VT_NULL || rightvt == VT_NULL)
4592 resvt = VT_NULL;
4593 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
4594 resvt = VT_DECIMAL;
4595 else if (leftvt == VT_R8 || rightvt == VT_R8 ||
4596 leftvt == VT_BSTR || rightvt == VT_BSTR ||
4597 leftvt == VT_DATE || rightvt == VT_DATE)
4598 resvt = VT_R8;
4599 else if (leftvt == VT_R4 || rightvt == VT_R4) {
4600 if (leftvt == VT_I4 || rightvt == VT_I4 ||
4601 leftvt == VT_I8 || rightvt == VT_I8 ||
4602 leftvt == VT_CY || rightvt == VT_CY)
4603 resvt = VT_R8;
4604 else
4605 resvt = VT_R4;
4606 } else if (leftvt == VT_CY || rightvt == VT_CY)
4607 resvt = VT_CY;
4608 else if (leftvt == VT_I8 || rightvt == VT_I8)
4609 resvt = VT_I8;
4610 else if (leftvt == VT_I4 || rightvt == VT_I4)
4611 resvt = VT_I4;
4612 else if (leftvt == VT_I2 || rightvt == VT_I2 ||
4613 leftvt == VT_BOOL || rightvt == VT_BOOL ||
4614 (leftvt == VT_EMPTY && rightvt == VT_EMPTY))
4615 resvt = VT_I2;
4616 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
4617 resvt = VT_UI1;
4619 hres = pVarMul(&left, &right, &result);
4620 if (bFail) {
4621 ok(hres == DISP_E_TYPEMISMATCH || hres == DISP_E_BADVARTYPE,
4622 "VarMul: %d|0x%X, %d|0x%X: Expected failure, got 0x%lX vt %d\n",
4623 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], hres,
4624 V_VT(&result));
4625 } else {
4626 ok(hres == S_OK && V_VT(&result) == resvt,
4627 "VarMul: %d|0x%X, %d|0x%X: expected S_OK, vt %d, got 0x%lX vt %d\n",
4628 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i], resvt, hres,
4629 V_VT(&result));
4635 /* Test returned values */
4636 VARMUL(I4,4,I4,2,I4,8);
4637 VARMUL(I2,4,I2,2,I2,8);
4638 VARMUL(I2,-13,I4,5,I4,-65);
4639 VARMUL(I4,-13,I4,5,I4,-65);
4640 VARMUL(I2,7,R4,0.5,R4,3.5);
4641 VARMUL(R4,0.5,I4,5,R8,2.5);
4642 VARMUL(R8,7.1,BOOL,0,R8,0);
4643 VARMUL(BSTR,lbstr,I2,4,R8,48);
4644 VARMUL(BSTR,lbstr,BOOL,1,R8,12);
4645 VARMUL(BSTR,lbstr,R4,0.1,R8,1.2);
4646 VARMUL(R4,0.2,BSTR,rbstr,R8,2.4);
4647 VARMUL(DATE,2.25,I4,7,R8,15.75);
4649 VARMUL(UI1, UI1_MAX, UI1, UI1_MAX, I4, UI1_MAX * UI1_MAX);
4650 VARMUL(I2, I2_MAX, I2, I2_MAX, I4, I2_MAX * I2_MAX);
4651 VARMUL(I2, I2_MAX, I2, I2_MIN, I4, I2_MAX * I2_MIN);
4652 VARMUL(I2, I2_MIN, I2, I2_MIN, I4, I2_MIN * I2_MIN);
4653 if (HAVE_OLEAUT32_I8) {
4654 VARMUL(I4, I4_MAX, I4, I4_MAX, I8, (long long)I4_MAX * I4_MAX);
4655 VARMUL(I4, I4_MAX, I4, I4_MIN, I8, (long long)I4_MAX * I4_MIN);
4656 VARMUL(I4, I4_MIN, I4, I4_MIN, I8, (long long)I4_MIN * I4_MIN);
4657 } else {
4658 VARMUL(I4, I4_MAX, I4, I4_MAX, R8, (double)I4_MAX * I4_MAX);
4659 VARMUL(I4, I4_MAX, I4, I4_MIN, R8, (double)I4_MAX * I4_MIN);
4660 VARMUL(I4, I4_MIN, I4, I4_MIN, R8, (double)I4_MIN * I4_MIN);
4662 VARMUL(R4, R4_MAX, R4, R4_MAX, R8, (double)R4_MAX * R4_MAX);
4663 VARMUL(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX * R4_MIN);
4664 VARMUL(R4, R4_MIN, R4, R4_MIN, R4, R4_MIN * R4_MIN);
4665 VARMUL(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX * R8_MIN);
4666 VARMUL(R8, R8_MIN, R8, R8_MIN, R8, R8_MIN * R8_MIN);
4668 /* Manuly test some VT_CY and VT_DECIMAL variants */
4669 V_VT(&cy) = VT_CY;
4670 hres = VarCyFromI4(4711, &V_CY(&cy));
4671 ok(hres == S_OK, "VarCyFromI4 failed!\n");
4672 V_VT(&dec) = VT_DECIMAL;
4673 hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec));
4674 ok(hres == S_OK, "VarDecFromR4 failed!\n");
4675 memset(&left, 0, sizeof(left));
4676 memset(&right, 0, sizeof(right));
4677 V_VT(&left) = VT_I4;
4678 V_I4(&left) = -11;
4679 V_VT(&right) = VT_UI1;
4680 V_UI1(&right) = 9;
4682 hres = VarMul(&cy, &right, &result);
4683 ok(hres == S_OK && V_VT(&result) == VT_CY, "VarMul: expected coerced type VT_CY, got %s!\n'", vtstr(V_VT(&result)));
4684 hres = VarR8FromCy(V_CY(&result), &r);
4685 ok(hres == S_OK && EQ_DOUBLE(r, 42399), "VarMul: CY value %f, expected %f\n", r, (double)42399);
4687 hres = VarMul(&left, &dec, &result);
4688 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL, "VarMul: expected coerced type VT_DECIMAL, got %s!\n'", vtstr(V_VT(&result)));
4689 hres = VarR8FromDec(&V_DECIMAL(&result), &r);
4690 ok(hres == S_OK && EQ_DOUBLE(r, 46.2), "VarMul: DECIMAL value %f, expected %f\n", r, (double)46.2);
4693 START_TEST(vartest)
4695 hOleaut32 = LoadLibraryA("oleaut32.dll");
4697 test_VariantInit();
4698 test_VariantClear();
4699 test_VariantCopy();
4700 test_VariantCopyInd();
4701 test_VarParseNumFromStr();
4702 test_VarNumFromParseNum();
4703 test_VarUdateFromDate();
4704 test_VarDateFromUdate();
4705 test_SystemTimeToVariantTime();
4706 test_VariantTimeToSystemTime();
4707 test_DosDateTimeToVariantTime();
4708 test_VariantTimeToDosDateTime();
4709 test_VarFormatNumber();
4710 test_VarFormat();
4711 test_VarAbs();
4712 test_VarNot();
4713 test_VarSub();
4714 test_VarMod();
4715 test_VarFix();
4716 test_VarInt();
4717 test_VarNeg();
4718 test_VarRound();
4719 test_VarXor();
4720 test_VarOr();
4721 test_VarEqv();
4722 test_VarMul();