b54e8372a34f0724671a48a1347069fad50d49c2
[reactos.git] / rostests / winetests / oleaut32 / vartest.c
1 /*
2 * VARIANT test program
3 *
4 * Copyright 1998 Jean-Claude Cote
5 * Copyright 2006 Google (Benjamin Arai)
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #define WIN32_NO_STATUS
23 #define _INC_WINDOWS
24 #define COM_NO_WINDOWS_H
25
26 //#include <stdarg.h>
27 #include <stdio.h>
28 #include <math.h>
29 #include <float.h>
30
31 #define COBJMACROS
32 #define CONST_VTABLE
33
34 //#include "windef.h"
35 //#include "winbase.h"
36 //#include "winsock.h"
37 #include <wine/test.h>
38 //#include "winuser.h"
39 //#include "wingdi.h"
40 #include <winnls.h>
41 //#include "winerror.h"
42 //#include "winnt.h"
43 #include <objbase.h>
44 //#include "wtypes.h"
45 #include <oleauto.h>
46
47 static HMODULE hOleaut32;
48
49 static HRESULT (WINAPI *pVarUdateFromDate)(DATE,ULONG,UDATE*);
50 static HRESULT (WINAPI *pVarDateFromUdate)(UDATE*,ULONG,DATE*);
51 static INT (WINAPI *pSystemTimeToVariantTime)(LPSYSTEMTIME,double*);
52 static INT (WINAPI *pVariantTimeToSystemTime)(double,LPSYSTEMTIME);
53 static INT (WINAPI *pDosDateTimeToVariantTime)(USHORT,USHORT,double*);
54 static INT (WINAPI *pVariantTimeToDosDateTime)(double,USHORT*,USHORT *);
55
56 static const WCHAR sz12[] = {'1','2','\0'};
57 /* the strings are localized */
58 static WCHAR sz12_false[32];
59 static WCHAR sz12_true[32];
60
61 /* Get a conversion function ptr, return if function not available */
62 #define CHECKPTR(func) p##func = (void*)GetProcAddress(hOleaut32, #func); \
63 if (!p##func) { win_skip("function " # func " not available, not testing it\n"); return; }
64
65 /* Has I8/UI8 data type? */
66 static BOOL has_i8;
67
68 /* When comparing floating point values we cannot expect an exact match
69 * because the rounding errors depend on the exact algorithm.
70 */
71 #define EQ_DOUBLE(a,b) (fabs((a)-(b)) / (1.0+fabs(a)+fabs(b)) < 1e-14)
72 #define EQ_FLOAT(a,b) (fabs((a)-(b)) / (1.0+fabs(a)+fabs(b)) < 1e-7)
73
74 #define SKIPTESTS(a) if((a > VT_CLSID+10) && (a < VT_BSTR_BLOB-10)) continue
75
76 /* Allow our test macros to work for VT_NULL and VT_EMPTY too */
77 #define V_EMPTY(v) V_I4(v)
78 #define V_NULL(v) V_I4(v)
79
80 /* Size constraints for overflow tests */
81 #define I1_MAX 0x7f
82 #define I1_MIN ((-I1_MAX)-1)
83 #define UI1_MAX 0xff
84 #define UI1_MIN 0
85 #define I2_MAX 0x7fff
86 #define I2_MIN ((-I2_MAX)-1)
87 #define UI2_MAX 0xffff
88 #define UI2_MIN 0
89 #define I4_MAX 0x7fffffff
90 #define I4_MIN ((-I4_MAX)-1)
91 #define UI4_MAX 0xffffffff
92 #define UI4_MIN 0
93 #define I8_MAX (((LONGLONG)I4_MAX << 32) | UI4_MAX)
94 #define I8_MIN ((-I8_MAX)-1)
95 #define UI8_MAX (((ULONGLONG)UI4_MAX << 32) | UI4_MAX)
96 #define UI8_MIN 0
97 #define DATE_MAX 2958465
98 #define DATE_MIN -657434
99 #define R4_MAX FLT_MAX
100 #define R4_MIN FLT_MIN
101 #define R8_MAX DBL_MAX
102 #define R8_MIN DBL_MIN
103
104 typedef struct IRecordInfoImpl
105 {
106 IRecordInfo IRecordInfo_iface;
107 LONG ref;
108 unsigned int recordclear;
109 unsigned int getsize;
110 unsigned int recordcopy;
111 struct __tagBRECORD *rec;
112 } IRecordInfoImpl;
113
114 static inline IRecordInfoImpl *impl_from_IRecordInfo(IRecordInfo *iface)
115 {
116 return CONTAINING_RECORD(iface, IRecordInfoImpl, IRecordInfo_iface);
117 }
118
119 static HRESULT WINAPI RecordInfo_QueryInterface(IRecordInfo *iface, REFIID riid, void **obj)
120 {
121 *obj = NULL;
122
123 if (IsEqualIID(riid, &IID_IUnknown) ||
124 IsEqualIID(riid, &IID_IRecordInfo))
125 {
126 *obj = iface;
127 IRecordInfo_AddRef(iface);
128 return S_OK;
129 }
130
131 return E_NOINTERFACE;
132 }
133
134 static ULONG WINAPI RecordInfo_AddRef(IRecordInfo *iface)
135 {
136 IRecordInfoImpl* This = impl_from_IRecordInfo(iface);
137 return InterlockedIncrement(&This->ref);
138 }
139
140 static ULONG WINAPI RecordInfo_Release(IRecordInfo *iface)
141 {
142 IRecordInfoImpl* This = impl_from_IRecordInfo(iface);
143 ULONG ref = InterlockedDecrement(&This->ref);
144
145 if (!ref)
146 HeapFree(GetProcessHeap(), 0, This);
147
148 return ref;
149 }
150
151 static HRESULT WINAPI RecordInfo_RecordInit(IRecordInfo *iface, PVOID pvNew)
152 {
153 ok(0, "unexpected call\n");
154 return E_NOTIMPL;
155 }
156
157 static HRESULT WINAPI RecordInfo_RecordClear(IRecordInfo *iface, void *data)
158 {
159 IRecordInfoImpl* This = impl_from_IRecordInfo(iface);
160 This->recordclear++;
161 This->rec->pvRecord = NULL;
162 return S_OK;
163 }
164
165 static HRESULT WINAPI RecordInfo_RecordCopy(IRecordInfo *iface, void *src, void *dest)
166 {
167 IRecordInfoImpl* This = impl_from_IRecordInfo(iface);
168 This->recordcopy++;
169 ok(src == (void*)0xdeadbeef, "wrong src pointer %p\n", src);
170 return S_OK;
171 }
172
173 static HRESULT WINAPI RecordInfo_GetGuid(IRecordInfo *iface, GUID *pguid)
174 {
175 ok(0, "unexpected call\n");
176 return E_NOTIMPL;
177 }
178
179 static HRESULT WINAPI RecordInfo_GetName(IRecordInfo *iface, BSTR *pbstrName)
180 {
181 ok(0, "unexpected call\n");
182 return E_NOTIMPL;
183 }
184
185 static HRESULT WINAPI RecordInfo_GetSize(IRecordInfo *iface, ULONG* size)
186 {
187 IRecordInfoImpl* This = impl_from_IRecordInfo(iface);
188 This->getsize++;
189 *size = 0;
190 return S_OK;
191 }
192
193 static HRESULT WINAPI RecordInfo_GetTypeInfo(IRecordInfo *iface, ITypeInfo **ppTypeInfo)
194 {
195 ok(0, "unexpected call\n");
196 return E_NOTIMPL;
197 }
198
199 static HRESULT WINAPI RecordInfo_GetField(IRecordInfo *iface, PVOID pvData,
200 LPCOLESTR szFieldName, VARIANT *pvarField)
201 {
202 ok(0, "unexpected call\n");
203 return E_NOTIMPL;
204 }
205
206 static HRESULT WINAPI RecordInfo_GetFieldNoCopy(IRecordInfo *iface, PVOID pvData,
207 LPCOLESTR szFieldName, VARIANT *pvarField, PVOID *ppvDataCArray)
208 {
209 ok(0, "unexpected call\n");
210 return E_NOTIMPL;
211 }
212
213 static HRESULT WINAPI RecordInfo_PutField(IRecordInfo *iface, ULONG wFlags, PVOID pvData,
214 LPCOLESTR szFieldName, VARIANT *pvarField)
215 {
216 ok(0, "unexpected call\n");
217 return E_NOTIMPL;
218 }
219
220 static HRESULT WINAPI RecordInfo_PutFieldNoCopy(IRecordInfo *iface, ULONG wFlags,
221 PVOID pvData, LPCOLESTR szFieldName, VARIANT *pvarField)
222 {
223 ok(0, "unexpected call\n");
224 return E_NOTIMPL;
225 }
226
227 static HRESULT WINAPI RecordInfo_GetFieldNames(IRecordInfo *iface, ULONG *pcNames,
228 BSTR *rgBstrNames)
229 {
230 ok(0, "unexpected call\n");
231 return E_NOTIMPL;
232 }
233
234 static BOOL WINAPI RecordInfo_IsMatchingType(IRecordInfo *iface, IRecordInfo *info2)
235 {
236 ok(0, "unexpected call\n");
237 return FALSE;
238 }
239
240 static PVOID WINAPI RecordInfo_RecordCreate(IRecordInfo *iface)
241 {
242 ok(0, "unexpected call\n");
243 return NULL;
244 }
245
246 static HRESULT WINAPI RecordInfo_RecordCreateCopy(IRecordInfo *iface, PVOID pvSource,
247 PVOID *ppvDest)
248 {
249 ok(0, "unexpected call\n");
250 return E_NOTIMPL;
251 }
252
253 static HRESULT WINAPI RecordInfo_RecordDestroy(IRecordInfo *iface, PVOID pvRecord)
254 {
255 ok(0, "unexpected call\n");
256 return E_NOTIMPL;
257 }
258
259 static const IRecordInfoVtbl RecordInfoVtbl =
260 {
261 RecordInfo_QueryInterface,
262 RecordInfo_AddRef,
263 RecordInfo_Release,
264 RecordInfo_RecordInit,
265 RecordInfo_RecordClear,
266 RecordInfo_RecordCopy,
267 RecordInfo_GetGuid,
268 RecordInfo_GetName,
269 RecordInfo_GetSize,
270 RecordInfo_GetTypeInfo,
271 RecordInfo_GetField,
272 RecordInfo_GetFieldNoCopy,
273 RecordInfo_PutField,
274 RecordInfo_PutFieldNoCopy,
275 RecordInfo_GetFieldNames,
276 RecordInfo_IsMatchingType,
277 RecordInfo_RecordCreate,
278 RecordInfo_RecordCreateCopy,
279 RecordInfo_RecordDestroy
280 };
281
282 static IRecordInfoImpl *get_test_recordinfo(void)
283 {
284 IRecordInfoImpl *rec;
285
286 rec = HeapAlloc(GetProcessHeap(), 0, sizeof(IRecordInfoImpl));
287 rec->IRecordInfo_iface.lpVtbl = &RecordInfoVtbl;
288 rec->ref = 1;
289 rec->recordclear = 0;
290 rec->getsize = 0;
291 rec->recordcopy = 0;
292
293 return rec;
294 }
295
296 static void init(void)
297 {
298 BSTR bstr;
299 HRESULT res;
300
301 res = VarBstrFromBool(VARIANT_TRUE, LANG_USER_DEFAULT, VAR_LOCALBOOL, &bstr);
302 ok(res == S_OK && bstr[0], "Expected localized string for 'True'\n");
303 /* lstrcpyW / lstrcatW do not work on win95 */
304 memcpy(sz12_true, sz12, sizeof(sz12));
305 if (bstr) memcpy(&sz12_true[2], bstr, SysStringByteLen(bstr) + sizeof(WCHAR));
306 SysFreeString(bstr);
307
308 res = VarBstrFromBool(VARIANT_FALSE, LANG_USER_DEFAULT, VAR_LOCALBOOL, &bstr);
309 ok(res == S_OK && bstr[0], "Expected localized string for 'False'\n");
310 memcpy(sz12_false, sz12, sizeof(sz12));
311 if (bstr) memcpy(&sz12_false[2], bstr, SysStringByteLen(bstr) + sizeof(WCHAR));
312 SysFreeString(bstr);
313
314 hOleaut32 = GetModuleHandleA("oleaut32.dll");
315 has_i8 = GetProcAddress(hOleaut32, "VarI8FromI1") != NULL;
316 if (!has_i8)
317 skip("No support for I8 and UI8 data types\n");
318 }
319
320 /* Functions to set a DECIMAL */
321 static void setdec(DECIMAL* dec, BYTE scl, BYTE sgn, ULONG hi32, ULONG64 lo64)
322 {
323 S(U(*dec)).scale = scl;
324 S(U(*dec)).sign = sgn;
325 dec->Hi32 = hi32;
326 U1(*dec).Lo64 = lo64;
327 }
328
329 static void setdec64(DECIMAL* dec, BYTE scl, BYTE sgn, ULONG hi32, ULONG mid32, ULONG lo32)
330 {
331 S(U(*dec)).scale = scl;
332 S(U(*dec)).sign = sgn;
333 dec->Hi32 = hi32;
334 S1(U1(*dec)).Mid32 = mid32;
335 S1(U1(*dec)).Lo32 = lo32;
336 }
337
338 /* return the string text of a given variant type */
339 static char vtstr_buffer[16][256];
340 static int vtstr_current=0;
341 static const char *vtstr(int x)
342 {
343 switch(x) {
344 #define CASE(vt) case VT_##vt: return #vt
345 CASE(EMPTY);
346 CASE(NULL);
347 CASE(I2);
348 CASE(I4);
349 CASE(R4);
350 CASE(R8);
351 CASE(CY);
352 CASE(DATE);
353 CASE(BSTR);
354 CASE(DISPATCH);
355 CASE(ERROR);
356 CASE(BOOL);
357 CASE(VARIANT);
358 CASE(UNKNOWN);
359 CASE(DECIMAL);
360 CASE(I1);
361 CASE(UI1);
362 CASE(UI2);
363 CASE(UI4);
364 CASE(I8);
365 CASE(UI8);
366 CASE(INT);
367 CASE(UINT);
368 CASE(VOID);
369 CASE(HRESULT);
370 CASE(PTR);
371 CASE(SAFEARRAY);
372 CASE(CARRAY);
373 CASE(USERDEFINED);
374 CASE(LPSTR);
375 CASE(LPWSTR);
376 CASE(RECORD);
377 CASE(INT_PTR);
378 CASE(UINT_PTR);
379 CASE(FILETIME);
380 CASE(BLOB);
381 CASE(STREAM);
382 CASE(STORAGE);
383 CASE(STREAMED_OBJECT);
384 CASE(STORED_OBJECT);
385 CASE(BLOB_OBJECT);
386 CASE(CF);
387 CASE(CLSID);
388 CASE(VERSIONED_STREAM);
389 CASE(VECTOR);
390 CASE(ARRAY);
391 CASE(BYREF);
392 CASE(RESERVED);
393 CASE(ILLEGAL);
394 #undef CASE
395
396 case 0xfff:
397 return "VT_BSTR_BLOB/VT_ILLEGALMASKED/VT_TYPEMASK";
398
399 default:
400 vtstr_current %= sizeof(vtstr_buffer)/sizeof(*vtstr_buffer);
401 sprintf(vtstr_buffer[vtstr_current], "unknown variant type %d", x);
402 return vtstr_buffer[vtstr_current++];
403 }
404 }
405
406 static const char *variantstr( const VARIANT *var )
407 {
408 vtstr_current %= sizeof(vtstr_buffer)/sizeof(*vtstr_buffer);
409 switch(V_VT(var))
410 {
411 case VT_I1:
412 sprintf( vtstr_buffer[vtstr_current], "VT_I1(%d)", V_I1(var) ); break;
413 case VT_I2:
414 sprintf( vtstr_buffer[vtstr_current], "VT_I2(%d)", V_I2(var) ); break;
415 case VT_I4:
416 sprintf( vtstr_buffer[vtstr_current], "VT_I4(%d)", V_I4(var) ); break;
417 case VT_INT:
418 sprintf( vtstr_buffer[vtstr_current], "VT_INT(%d)", V_INT(var) ); break;
419 case VT_I8:
420 sprintf( vtstr_buffer[vtstr_current], "VT_I8(%x%08x)", (UINT)(V_I8(var) >> 32), (UINT)V_I8(var) ); break;
421 case VT_UI8:
422 sprintf( vtstr_buffer[vtstr_current], "VT_UI8(%x%08x)", (UINT)(V_UI8(var) >> 32), (UINT)V_UI8(var) ); break;
423 case VT_R4:
424 sprintf( vtstr_buffer[vtstr_current], "VT_R4(%g)", V_R4(var) ); break;
425 case VT_R8:
426 sprintf( vtstr_buffer[vtstr_current], "VT_R8(%g)", V_R8(var) ); break;
427 case VT_UI1:
428 sprintf( vtstr_buffer[vtstr_current], "VT_UI1(%u)", V_UI1(var) ); break;
429 case VT_UI2:
430 sprintf( vtstr_buffer[vtstr_current], "VT_UI2(%u)", V_UI2(var) ); break;
431 case VT_UI4:
432 sprintf( vtstr_buffer[vtstr_current], "VT_UI4(%u)", V_UI4(var) ); break;
433 case VT_UINT:
434 sprintf( vtstr_buffer[vtstr_current], "VT_UINT(%d)", V_UINT(var) ); break;
435 case VT_CY:
436 sprintf( vtstr_buffer[vtstr_current], "VT_CY(%x%08x)", S(V_CY(var)).Hi, S(V_CY(var)).Lo ); break;
437 case VT_DATE:
438 sprintf( vtstr_buffer[vtstr_current], "VT_DATE(%g)", V_DATE(var) ); break;
439 default:
440 return vtstr(V_VT(var));
441 }
442 return vtstr_buffer[vtstr_current++];
443 }
444
445 static BOOL is_expected_variant( const VARIANT *result, const VARIANT *expected )
446 {
447 if (V_VT(result) != V_VT(expected)) return FALSE;
448 switch(V_VT(expected))
449 {
450 case VT_EMPTY:
451 case VT_NULL:
452 return TRUE;
453
454 #define CASE(vt) case VT_##vt: return (V_##vt(result) == V_##vt(expected))
455 CASE(BOOL);
456 CASE(I1);
457 CASE(UI1);
458 CASE(I2);
459 CASE(UI2);
460 CASE(I4);
461 CASE(UI4);
462 CASE(I8);
463 CASE(UI8);
464 CASE(INT);
465 CASE(UINT);
466 #undef CASE
467
468 case VT_DATE:
469 return EQ_FLOAT(V_DATE(result), V_DATE(expected));
470 case VT_R4:
471 return EQ_FLOAT(V_R4(result), V_R4(expected));
472 case VT_R8:
473 return EQ_FLOAT(V_R8(result), V_R8(expected));
474 case VT_CY:
475 return (V_CY(result).int64 == V_CY(expected).int64);
476 case VT_BSTR:
477 return !lstrcmpW( V_BSTR(result), V_BSTR(expected) );
478 case VT_DECIMAL:
479 return !memcmp( &V_DECIMAL(result), &V_DECIMAL(expected), sizeof(DECIMAL) );
480 default:
481 ok(0, "unhandled variant type %s\n",vtstr(V_VT(expected)));
482 return FALSE;
483 }
484 }
485
486 static void test_var_call1( int line, HRESULT (WINAPI *func)(LPVARIANT,LPVARIANT),
487 VARIANT *arg, VARIANT *expected )
488 {
489 VARIANT old_arg = *arg;
490 VARIANT result;
491 HRESULT hres;
492
493 memset( &result, 0, sizeof(result) );
494 hres = func( arg, &result );
495 ok_(__FILE__,line)( hres == S_OK, "wrong result %x\n", hres );
496 if (hres == S_OK)
497 ok_(__FILE__,line)( is_expected_variant( &result, expected ),
498 "got %s expected %s\n", variantstr(&result), variantstr(expected) );
499 ok_(__FILE__,line)( is_expected_variant( arg, &old_arg ), "Modified argument %s / %s\n",
500 variantstr(&old_arg), variantstr(arg));
501 VariantClear( &result );
502 }
503
504 static void test_var_call2( int line, HRESULT (WINAPI *func)(LPVARIANT,LPVARIANT,LPVARIANT),
505 VARIANT *left, VARIANT *right, VARIANT *expected )
506 {
507 VARIANT old_left = *left, old_right = *right;
508 VARIANT result;
509 HRESULT hres;
510
511 memset( &result, 0, sizeof(result) );
512 hres = func( left, right, &result );
513 ok_(__FILE__,line)( hres == S_OK, "wrong result %x\n", hres );
514 if (hres == S_OK)
515 ok_(__FILE__,line)( is_expected_variant( &result, expected ),
516 "got %s expected %s\n", variantstr(&result), variantstr(expected) );
517 ok_(__FILE__,line)( is_expected_variant( left, &old_left ), "Modified left argument %s / %s\n",
518 variantstr(&old_left), variantstr(left));
519 ok_(__FILE__,line)( is_expected_variant( right, &old_right ), "Modified right argument %s / %s\n",
520 variantstr(&old_right), variantstr(right));
521 VariantClear( &result );
522 }
523
524 static int strcmp_wa(const WCHAR *strw, const char *stra)
525 {
526 WCHAR buf[512];
527 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(buf[0]));
528 return lstrcmpW(strw, buf);
529 }
530
531 #define test_bstr_var(a,b) _test_bstr_var(__LINE__,a,b)
532 static void _test_bstr_var(unsigned line, const VARIANT *v, const char *str)
533 {
534 ok_(__FILE__,line)(V_VT(v) == VT_BSTR, "unexpected vt=%d\n", V_VT(v));
535 if(V_VT(v) == VT_BSTR)
536 ok(!strcmp_wa(V_BSTR(v), str), "v=%s, expected %s\n", wine_dbgstr_w(V_BSTR(v)), str);
537 }
538
539 static void test_VariantInit(void)
540 {
541 VARIANT v;
542
543 memset(&v, -1, sizeof(v));
544 VariantInit(&v);
545 ok(V_VT(&v) == VT_EMPTY, "VariantInit() returned vt %d\n", V_VT(&v));
546 }
547
548 /* All possible combinations of extra V_VT() flags */
549 static const VARTYPE ExtraFlags[16] =
550 {
551 0,
552 VT_VECTOR,
553 VT_ARRAY,
554 VT_BYREF,
555 VT_RESERVED,
556 VT_VECTOR|VT_ARRAY,
557 VT_VECTOR|VT_BYREF,
558 VT_VECTOR|VT_RESERVED,
559 VT_VECTOR|VT_ARRAY|VT_BYREF,
560 VT_VECTOR|VT_ARRAY|VT_RESERVED,
561 VT_VECTOR|VT_BYREF|VT_RESERVED,
562 VT_VECTOR|VT_ARRAY|VT_BYREF|VT_RESERVED,
563 VT_ARRAY|VT_BYREF,
564 VT_ARRAY|VT_RESERVED,
565 VT_ARRAY|VT_BYREF|VT_RESERVED,
566 VT_BYREF|VT_RESERVED,
567 };
568
569 /* Determine if a vt is valid for VariantClear() */
570 static BOOL IsValidVariantClearVT(VARTYPE vt, VARTYPE extraFlags)
571 {
572 BOOL ret = FALSE;
573
574 /* Only the following flags/types are valid */
575 if ((vt <= VT_LPWSTR || vt == VT_RECORD || vt == VT_CLSID) &&
576 vt != (VARTYPE)15 &&
577 (vt < (VARTYPE)24 || vt > (VARTYPE)31) &&
578 (!(extraFlags & (VT_BYREF|VT_ARRAY)) || vt > VT_NULL) &&
579 (extraFlags == 0 || extraFlags == VT_BYREF || extraFlags == VT_ARRAY ||
580 extraFlags == (VT_ARRAY|VT_BYREF)))
581 ret = TRUE; /* ok */
582
583 if (!has_i8 && (vt == VT_I8 || vt == VT_UI8))
584 ret = FALSE; /* Old versions of oleaut32 */
585 return ret;
586 }
587
588 typedef struct
589 {
590 IUnknown IUnknown_iface;
591 LONG ref;
592 LONG events;
593 } test_VariantClearImpl;
594
595 static inline test_VariantClearImpl *impl_from_IUnknown(IUnknown *iface)
596 {
597 return CONTAINING_RECORD(iface, test_VariantClearImpl, IUnknown_iface);
598 }
599
600 static HRESULT WINAPI VC_QueryInterface(LPUNKNOWN iface,REFIID riid,LPVOID *ppobj)
601 {
602 test_VariantClearImpl *This = impl_from_IUnknown(iface);
603 This->events |= 0x1;
604 return E_NOINTERFACE;
605 }
606
607 static ULONG WINAPI VC_AddRef(LPUNKNOWN iface) {
608 test_VariantClearImpl *This = impl_from_IUnknown(iface);
609 This->events |= 0x2;
610 return InterlockedIncrement(&This->ref);
611 }
612
613 static ULONG WINAPI VC_Release(LPUNKNOWN iface) {
614 test_VariantClearImpl *This = impl_from_IUnknown(iface);
615 /* static class, won't be freed */
616 This->events |= 0x4;
617 return InterlockedDecrement(&This->ref);
618 }
619
620 static const IUnknownVtbl test_VariantClear_vtbl = {
621 VC_QueryInterface,
622 VC_AddRef,
623 VC_Release,
624 };
625
626 static test_VariantClearImpl test_myVariantClearImpl = {{&test_VariantClear_vtbl}, 1, 0};
627
628 static void test_VariantClear(void)
629 {
630 struct __tagBRECORD *rec;
631 IRecordInfoImpl *recinfo;
632 HRESULT hres;
633 VARIANTARG v;
634 VARIANT v2;
635 size_t i;
636 LONG i4;
637 IUnknown *punk;
638
639 /* Crashes: Native does not test input for NULL, so neither does Wine */
640 if (0)
641 VariantClear(NULL);
642
643 /* Only the type field is set, to VT_EMPTY */
644 V_VT(&v) = VT_UI4;
645 V_UI4(&v) = ~0u;
646 hres = VariantClear(&v);
647 ok((hres == S_OK && V_VT(&v) == VT_EMPTY),
648 "VariantClear: Type set to %d, res %08x\n", V_VT(&v), hres);
649 ok(V_UI4(&v) == ~0u, "VariantClear: Overwrote value\n");
650
651 /* Test all possible V_VT values.
652 * Also demonstrates that null pointers in 'v' are not dereferenced.
653 * Individual variant tests should test VariantClear() with non-NULL values.
654 */
655 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
656 {
657 VARTYPE vt;
658
659 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
660 {
661 HRESULT hExpected = DISP_E_BADVARTYPE;
662
663 SKIPTESTS(vt);
664
665 memset(&v, 0, sizeof(v));
666 V_VT(&v) = vt | ExtraFlags[i];
667
668 hres = VariantClear(&v);
669
670 if (IsValidVariantClearVT(vt, ExtraFlags[i]))
671 hExpected = S_OK;
672
673 ok(hres == hExpected, "VariantClear: expected 0x%X, got 0x%X for vt %d | 0x%X\n",
674 hExpected, hres, vt, ExtraFlags[i]);
675 }
676 }
677
678 /* Some BYREF tests with non-NULL ptrs */
679
680 /* VARIANT BYREF */
681 V_VT(&v2) = VT_I4;
682 V_I4(&v2) = 0x1234;
683 V_VT(&v) = VT_VARIANT | VT_BYREF;
684 V_VARIANTREF(&v) = &v2;
685
686 hres = VariantClear(&v);
687 ok(hres == S_OK, "ret %08x\n", hres);
688 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
689 ok(V_VARIANTREF(&v) == &v2, "variant ref %p\n", V_VARIANTREF(&v2));
690 ok(V_VT(&v2) == VT_I4, "vt %04x\n", V_VT(&v2));
691 ok(V_I4(&v2) == 0x1234, "i4 %04x\n", V_I4(&v2));
692
693 /* I4 BYREF */
694 i4 = 0x4321;
695 V_VT(&v) = VT_I4 | VT_BYREF;
696 V_I4REF(&v) = &i4;
697
698 hres = VariantClear(&v);
699 ok(hres == S_OK, "ret %08x\n", hres);
700 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
701 ok(V_I4REF(&v) == &i4, "i4 ref %p\n", V_I4REF(&v2));
702 ok(i4 == 0x4321, "i4 changed %08x\n", i4);
703
704
705 /* UNKNOWN */
706 V_VT(&v) = VT_UNKNOWN;
707 V_UNKNOWN(&v) = &test_myVariantClearImpl.IUnknown_iface;
708 test_myVariantClearImpl.events = 0;
709 hres = VariantClear(&v);
710 ok(hres == S_OK, "ret %08x\n", hres);
711 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
712 ok(V_UNKNOWN(&v) == &test_myVariantClearImpl.IUnknown_iface, "unknown %p\n", V_UNKNOWN(&v));
713 /* Check that Release got called, but nothing else */
714 ok(test_myVariantClearImpl.events == 0x4, "Unexpected call. events %08x\n", test_myVariantClearImpl.events);
715
716 /* UNKNOWN BYREF */
717 punk = &test_myVariantClearImpl.IUnknown_iface;
718 V_VT(&v) = VT_UNKNOWN | VT_BYREF;
719 V_UNKNOWNREF(&v) = &punk;
720 test_myVariantClearImpl.events = 0;
721 hres = VariantClear(&v);
722 ok(hres == S_OK, "ret %08x\n", hres);
723 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
724 ok(V_UNKNOWNREF(&v) == &punk, "unknown ref %p\n", V_UNKNOWNREF(&v));
725 /* Check that nothing got called */
726 ok(test_myVariantClearImpl.events == 0, "Unexpected call. events %08x\n", test_myVariantClearImpl.events);
727
728 /* DISPATCH */
729 V_VT(&v) = VT_DISPATCH;
730 V_DISPATCH(&v) = (IDispatch*)&test_myVariantClearImpl.IUnknown_iface;
731 test_myVariantClearImpl.events = 0;
732 hres = VariantClear(&v);
733 ok(hres == S_OK, "ret %08x\n", hres);
734 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
735 ok(V_DISPATCH(&v) == (IDispatch*)&test_myVariantClearImpl.IUnknown_iface,
736 "dispatch %p\n", V_DISPATCH(&v));
737 /* Check that Release got called, but nothing else */
738 ok(test_myVariantClearImpl.events == 0x4, "Unexpected call. events %08x\n", test_myVariantClearImpl.events);
739
740 /* DISPATCH BYREF */
741 punk = &test_myVariantClearImpl.IUnknown_iface;
742 V_VT(&v) = VT_DISPATCH | VT_BYREF;
743 V_DISPATCHREF(&v) = (IDispatch**)&punk;
744 test_myVariantClearImpl.events = 0;
745 hres = VariantClear(&v);
746 ok(hres == S_OK, "ret %08x\n", hres);
747 ok(V_VT(&v) == 0, "vt %04x\n", V_VT(&v));
748 ok(V_DISPATCHREF(&v) == (IDispatch**)&punk, "dispatch ref %p\n", V_DISPATCHREF(&v));
749 /* Check that nothing got called */
750 ok(test_myVariantClearImpl.events == 0, "Unexpected call. events %08x\n", test_myVariantClearImpl.events);
751
752 /* RECORD */
753 recinfo = get_test_recordinfo();
754 V_VT(&v) = VT_RECORD;
755 rec = &V_UNION(&v, brecVal);
756 rec->pRecInfo = &recinfo->IRecordInfo_iface;
757 rec->pvRecord = (void*)0xdeadbeef;
758 recinfo->recordclear = 0;
759 recinfo->ref = 2;
760 recinfo->rec = rec;
761 hres = VariantClear(&v);
762 ok(hres == S_OK, "ret %08x\n", hres);
763 ok(rec->pvRecord == NULL, "got %p\n", rec->pvRecord);
764 ok(recinfo->recordclear == 1, "got %d\n", recinfo->recordclear);
765 ok(recinfo->ref == 1, "got %d\n", recinfo->ref);
766 IRecordInfo_Release(&recinfo->IRecordInfo_iface);
767 }
768
769 static void test_VariantCopy(void)
770 {
771 struct __tagBRECORD *rec;
772 IRecordInfoImpl *recinfo;
773 VARIANTARG vSrc, vDst;
774 VARTYPE vt;
775 size_t i;
776 HRESULT hres, hExpected;
777
778 /* Establish that the failure/other cases are dealt with. Individual tests
779 * for each type should verify that data is copied correctly, references
780 * are updated, etc.
781 */
782
783 /* vSrc == vDst */
784 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
785 {
786 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
787 {
788 SKIPTESTS(vt);
789
790 memset(&vSrc, 0, sizeof(vSrc));
791 V_VT(&vSrc) = vt | ExtraFlags[i];
792
793 hExpected = DISP_E_BADVARTYPE;
794 /* src is allowed to be a VT_CLSID */
795 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
796 hExpected = S_OK;
797
798 hres = VariantCopy(&vSrc, &vSrc);
799
800 ok(hres == hExpected,
801 "Copy(src==dst): expected 0x%X, got 0x%X for src==dest vt %d|0x%X\n",
802 hExpected, hres, vt, ExtraFlags[i]);
803 }
804 }
805
806 /* Test that if VariantClear() fails on dest, the function fails. This also
807 * shows that dest is in fact cleared and not just overwritten
808 */
809 memset(&vSrc, 0, sizeof(vSrc));
810 V_VT(&vSrc) = VT_UI1;
811
812 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
813 {
814 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
815 {
816 SKIPTESTS(vt);
817
818 hExpected = DISP_E_BADVARTYPE;
819
820 memset(&vDst, 0, sizeof(vDst));
821 V_VT(&vDst) = vt | ExtraFlags[i];
822
823 if (IsValidVariantClearVT(vt, ExtraFlags[i]))
824 hExpected = S_OK;
825
826 hres = VariantCopy(&vDst, &vSrc);
827
828 ok(hres == hExpected,
829 "Copy(bad dst): expected 0x%X, got 0x%X for dest vt %d|0x%X\n",
830 hExpected, hres, vt, ExtraFlags[i]);
831 if (hres == S_OK)
832 ok(V_VT(&vDst) == VT_UI1,
833 "Copy(bad dst): expected vt = VT_UI1, got %d\n", V_VT(&vDst));
834 }
835 }
836
837 /* Test that VariantClear() checks vSrc for validity before copying */
838 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
839 {
840 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
841 {
842 SKIPTESTS(vt);
843
844 hExpected = DISP_E_BADVARTYPE;
845
846 memset(&vDst, 0, sizeof(vDst));
847 V_VT(&vDst) = VT_EMPTY;
848
849 memset(&vSrc, 0, sizeof(vSrc));
850 V_VT(&vSrc) = vt | ExtraFlags[i];
851
852 /* src is allowed to be a VT_CLSID */
853 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
854 hExpected = S_OK;
855
856 hres = VariantCopy(&vDst, &vSrc);
857
858 ok(hres == hExpected,
859 "Copy(bad src): expected 0x%X, got 0x%X for src vt %d|0x%X\n",
860 hExpected, hres, vt, ExtraFlags[i]);
861 if (hres == S_OK)
862 {
863 ok(V_VT(&vDst) == (vt|ExtraFlags[i]),
864 "Copy(bad src): expected vt = %d, got %d\n",
865 vt | ExtraFlags[i], V_VT(&vDst));
866 VariantClear(&vDst);
867 }
868 }
869 }
870
871 /* Test that copying a NULL BSTR results in an empty BSTR */
872 memset(&vDst, 0, sizeof(vDst));
873 V_VT(&vDst) = VT_EMPTY;
874 memset(&vSrc, 0, sizeof(vSrc));
875 V_VT(&vSrc) = VT_BSTR;
876 hres = VariantCopy(&vDst, &vSrc);
877 ok(hres == S_OK, "Copy(NULL BSTR): Failed to copy a NULL BSTR\n");
878 if (hres == S_OK)
879 {
880 ok((V_VT(&vDst) == VT_BSTR) && V_BSTR(&vDst),
881 "Copy(NULL BSTR): should have non-NULL result\n");
882 if ((V_VT(&vDst) == VT_BSTR) && V_BSTR(&vDst))
883 {
884 ok(*V_BSTR(&vDst) == 0, "Copy(NULL BSTR): result not empty\n");
885 }
886 VariantClear(&vDst);
887 }
888
889 /* copy RECORD */
890 recinfo = get_test_recordinfo();
891
892 memset(&vDst, 0, sizeof(vDst));
893 V_VT(&vDst) = VT_EMPTY;
894
895 V_VT(&vSrc) = VT_RECORD;
896 rec = &V_UNION(&vSrc, brecVal);
897 rec->pRecInfo = &recinfo->IRecordInfo_iface;
898 rec->pvRecord = (void*)0xdeadbeef;
899
900 recinfo->recordclear = 0;
901 recinfo->recordcopy = 0;
902 recinfo->getsize = 0;
903 recinfo->rec = rec;
904 hres = VariantCopy(&vDst, &vSrc);
905 ok(hres == S_OK, "ret %08x\n", hres);
906
907 rec = &V_UNION(&vDst, brecVal);
908 ok(rec->pvRecord != (void*)0xdeadbeef && rec->pvRecord != NULL, "got %p\n", rec->pvRecord);
909 ok(rec->pRecInfo == &recinfo->IRecordInfo_iface, "got %p\n", rec->pRecInfo);
910 ok(recinfo->getsize == 1, "got %d\n", recinfo->recordclear);
911 ok(recinfo->recordcopy == 1, "got %d\n", recinfo->recordclear);
912
913 VariantClear(&vDst);
914 VariantClear(&vSrc);
915 }
916
917 /* Determine if a vt is valid for VariantCopyInd() */
918 static BOOL IsValidVariantCopyIndVT(VARTYPE vt, VARTYPE extraFlags)
919 {
920 BOOL ret = FALSE;
921
922 if ((extraFlags & VT_ARRAY) ||
923 (vt > VT_NULL && vt != (VARTYPE)15 && vt < VT_VOID &&
924 !(extraFlags & (VT_VECTOR|VT_RESERVED))))
925 {
926 ret = TRUE; /* ok */
927 }
928 return ret;
929 }
930
931 static void test_VariantCopyInd(void)
932 {
933 VARIANTARG vSrc, vDst, vRef, vRef2;
934 VARTYPE vt;
935 size_t i;
936 BYTE buffer[64];
937 HRESULT hres, hExpected;
938
939 memset(buffer, 0, sizeof(buffer));
940
941 /* vSrc == vDst */
942 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
943 {
944 if (ExtraFlags[i] & VT_ARRAY)
945 continue; /* Native crashes on NULL safearray */
946
947 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
948 {
949 SKIPTESTS(vt);
950
951 memset(&vSrc, 0, sizeof(vSrc));
952 V_VT(&vSrc) = vt | ExtraFlags[i];
953
954 hExpected = DISP_E_BADVARTYPE;
955 if (!(ExtraFlags[i] & VT_BYREF))
956 {
957 /* if src is not by-reference, acts as VariantCopy() */
958 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
959 hExpected = S_OK;
960 }
961 else
962 {
963 if (vt == VT_SAFEARRAY || vt == VT_BSTR || vt == VT_UNKNOWN ||
964 vt == VT_DISPATCH || vt == VT_RECORD)
965 continue; /* Need valid ptrs for deep copies */
966
967 V_BYREF(&vSrc) = &buffer;
968 hExpected = E_INVALIDARG;
969
970 if ((vt == VT_I8 || vt == VT_UI8) &&
971 ExtraFlags[i] == VT_BYREF)
972 {
973 if (has_i8)
974 hExpected = S_OK; /* Only valid if I8 is a known type */
975 }
976 else if (IsValidVariantCopyIndVT(vt, ExtraFlags[i]))
977 hExpected = S_OK;
978 }
979
980 hres = VariantCopyInd(&vSrc, &vSrc);
981
982 ok(hres == hExpected,
983 "CopyInd(src==dst): expected 0x%X, got 0x%X for src==dst vt %d|0x%X\n",
984 hExpected, hres, vt, ExtraFlags[i]);
985 }
986 }
987
988 /* Bad dest */
989 memset(&vSrc, 0, sizeof(vSrc));
990 V_VT(&vSrc) = VT_UI1|VT_BYREF;
991 V_BYREF(&vSrc) = &buffer;
992
993 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
994 {
995 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
996 {
997 SKIPTESTS(vt);
998
999 memset(&vDst, 0, sizeof(vDst));
1000 V_VT(&vDst) = vt | ExtraFlags[i];
1001
1002 hExpected = DISP_E_BADVARTYPE;
1003
1004 if (IsValidVariantClearVT(vt, ExtraFlags[i]))
1005 hExpected = S_OK;
1006
1007 hres = VariantCopyInd(&vDst, &vSrc);
1008
1009 ok(hres == hExpected,
1010 "CopyInd(bad dst): expected 0x%X, got 0x%X for dst vt %d|0x%X\n",
1011 hExpected, hres, vt, ExtraFlags[i]);
1012 if (hres == S_OK)
1013 ok(V_VT(&vDst) == VT_UI1,
1014 "CopyInd(bad dst): expected vt = VT_UI1, got %d\n", V_VT(&vDst));
1015 }
1016 }
1017
1018 /* bad src */
1019 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
1020 {
1021 if (ExtraFlags[i] & VT_ARRAY)
1022 continue; /* Native crashes on NULL safearray */
1023
1024 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
1025 {
1026 SKIPTESTS(vt);
1027
1028 memset(&vDst, 0, sizeof(vDst));
1029 V_VT(&vDst) = VT_EMPTY;
1030
1031 memset(&vSrc, 0, sizeof(vSrc));
1032 V_VT(&vSrc) = vt | ExtraFlags[i];
1033
1034 hExpected = DISP_E_BADVARTYPE;
1035 if (!(ExtraFlags[i] & VT_BYREF))
1036 {
1037 /* if src is not by-reference, acts as VariantCopy() */
1038 if (vt != VT_CLSID && IsValidVariantClearVT(vt, ExtraFlags[i]))
1039 hExpected = S_OK;
1040 }
1041 else
1042 {
1043 if (vt == VT_SAFEARRAY || vt == VT_BSTR || vt == VT_UNKNOWN ||
1044 vt == VT_DISPATCH || vt == VT_RECORD)
1045 continue; /* Need valid ptrs for deep copies, see vartype.c */
1046
1047 V_BYREF(&vSrc) = &buffer;
1048
1049 hExpected = E_INVALIDARG;
1050
1051 if ((vt == VT_I8 || vt == VT_UI8) &&
1052 ExtraFlags[i] == VT_BYREF)
1053 {
1054 if (has_i8)
1055 hExpected = S_OK; /* Only valid if I8 is a known type */
1056 }
1057 else if (IsValidVariantCopyIndVT(vt, ExtraFlags[i]))
1058 hExpected = S_OK;
1059 }
1060
1061 hres = VariantCopyInd(&vDst, &vSrc);
1062
1063 ok(hres == hExpected,
1064 "CopyInd(bad src): expected 0x%X, got 0x%X for src vt %d|0x%X\n",
1065 hExpected, hres, vt, ExtraFlags[i]);
1066 if (hres == S_OK)
1067 {
1068 if (vt == VT_VARIANT && ExtraFlags[i] == VT_BYREF)
1069 {
1070 /* Type of vDst should be the type of the referenced variant.
1071 * Since we set the buffer to all zeros, its type should be
1072 * VT_EMPTY.
1073 */
1074 ok(V_VT(&vDst) == VT_EMPTY,
1075 "CopyInd(bad src): expected dst vt = VT_EMPTY, got %d|0x%X\n",
1076 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK);
1077 }
1078 else
1079 {
1080 ok(V_VT(&vDst) == (vt|(ExtraFlags[i] & ~VT_BYREF)),
1081 "CopyInd(bad src): expected dst vt = %d|0x%X, got %d|0x%X\n",
1082 vt, ExtraFlags[i] & ~VT_BYREF,
1083 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK);
1084 }
1085 VariantClear(&vDst);
1086 }
1087 }
1088 }
1089
1090 /* By-reference variants are dereferenced */
1091 V_VT(&vRef) = VT_UI1;
1092 V_UI1(&vRef) = 0x77;
1093 V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
1094 V_VARIANTREF(&vSrc) = &vRef;
1095 VariantInit(&vDst);
1096
1097 hres = VariantCopyInd(&vDst, &vSrc);
1098 ok(hres == S_OK, "VariantCopyInd failed: 0x%08x\n", hres);
1099 ok(V_VT(&vDst) == VT_UI1 && V_UI1(&vDst) == 0x77,
1100 "CopyInd(deref): expected dst vt = VT_UI1, val 0x77, got %d|0x%X, 0x%2X\n",
1101 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK, V_UI1(&vDst));
1102
1103 /* By-reference variant to a by-reference type succeeds */
1104 V_VT(&vRef) = VT_UI1|VT_BYREF;
1105 V_UI1REF(&vRef) = buffer; buffer[0] = 0x88;
1106 V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
1107 V_VARIANTREF(&vSrc) = &vRef;
1108 VariantInit(&vDst);
1109
1110 hres = VariantCopyInd(&vDst, &vSrc);
1111 ok(hres == S_OK, "VariantCopyInd failed: 0x%08x\n", hres);
1112 ok(V_VT(&vDst) == VT_UI1 && V_UI1(&vDst) == 0x88,
1113 "CopyInd(deref): expected dst vt = VT_UI1, val 0x77, got %d|0x%X, 0x%2X\n",
1114 V_VT(&vDst) & VT_TYPEMASK, V_VT(&vDst) & ~VT_TYPEMASK, V_UI1(&vDst));
1115
1116 /* But a by-reference variant to a by-reference variant fails */
1117 V_VT(&vRef2) = VT_UI1;
1118 V_UI1(&vRef2) = 0x77;
1119 V_VT(&vRef) = VT_VARIANT|VT_BYREF;
1120 V_VARIANTREF(&vRef) = &vRef2;
1121 V_VT(&vSrc) = VT_VARIANT|VT_BYREF;
1122 V_VARIANTREF(&vSrc) = &vRef;
1123 VariantInit(&vDst);
1124
1125 hres = VariantCopyInd(&vDst, &vSrc);
1126 ok(hres == E_INVALIDARG,
1127 "CopyInd(ref->ref): expected E_INVALIDARG, got 0x%08x\n", hres);
1128 }
1129
1130 static HRESULT (WINAPI *pVarParseNumFromStr)(OLECHAR*,LCID,ULONG,NUMPARSE*,BYTE*);
1131
1132 /* Macros for converting and testing the result of VarParseNumFromStr */
1133 #define FAILDIG 255
1134
1135 static HRESULT convert_str( const char *str, INT dig, ULONG flags,
1136 NUMPARSE *np, BYTE rgb[128], LCID lcid )
1137 {
1138 OLECHAR buff[128];
1139 MultiByteToWideChar( CP_ACP,0, str, -1, buff, sizeof(buff)/sizeof(WCHAR) );
1140 memset( rgb, FAILDIG, 128 );
1141 memset( np, 255, sizeof(*np) );
1142 np->cDig = dig;
1143 np->dwInFlags = flags;
1144 return pVarParseNumFromStr( buff, lcid, LOCALE_NOUSEROVERRIDE, np, rgb);
1145 }
1146
1147 static void expect_NumFromStr( int line, HRESULT hres, NUMPARSE *np, INT a, ULONG b, ULONG c,
1148 INT d, INT e, INT f )
1149 {
1150 if (hres == (HRESULT)S_OK)
1151 {
1152 ok_(__FILE__,line)(np->cDig == a, "Expected cDig = %d, got %d\n", a, np->cDig);
1153 ok_(__FILE__,line)(np->dwInFlags == b, "Expected dwInFlags = 0x%x, got 0x%x\n", b, np->dwInFlags);
1154 ok_(__FILE__,line)(np->dwOutFlags == c, "Expected dwOutFlags = 0x%x, got 0x%x\n", c, np->dwOutFlags);
1155 ok_(__FILE__,line)(np->cchUsed == d, "Expected cchUsed = %d, got %d\n", d, np->cchUsed);
1156 ok_(__FILE__,line)(np->nBaseShift == e, "Expected nBaseShift = %d, got %d\n", e, np->nBaseShift);
1157 ok_(__FILE__,line)(np->nPwr10 == f, "Expected nPwr10 = %d, got %d\n", f, np->nPwr10);
1158 }
1159 }
1160
1161 #define CONVERTN(str,dig,flags) hres = convert_str( str, dig, flags, &np, rgb, lcid )
1162 #define CONVERT(str,flags) CONVERTN(str,sizeof(rgb),flags)
1163 #define EXPECT(a,b,c,d,e,f) expect_NumFromStr( __LINE__, hres, &np, a, b, c, d, e, f )
1164 #define EXPECTRGB(a,b) ok(rgb[a] == b, "Digit[%d], expected %d, got %d\n", a, b, rgb[a])
1165 #define EXPECTFAIL ok(hres == (HRESULT)DISP_E_TYPEMISMATCH, "Call succeeded, hres = %08x\n", hres)
1166 #define EXPECT2(a,b) EXPECTRGB(0,a); EXPECTRGB(1,b)
1167
1168 static void test_VarParseNumFromStr(void)
1169 {
1170 HRESULT hres;
1171 /* Ensure all tests are using the same locale characters for '$', ',' etc */
1172 LCID lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
1173 NUMPARSE np;
1174 BYTE rgb[128];
1175
1176 /** No flags **/
1177
1178 CHECKPTR(VarParseNumFromStr);
1179
1180 /* Consume a single digit */
1181 CONVERT("7", 0);
1182 EXPECT(1,0,0,1,0,0);
1183 EXPECT2(7,FAILDIG);
1184
1185 /* cDig is not literal digits - zeros are suppressed and nPwr10 is increased */
1186 CONVERT("10", 0);
1187 EXPECT(1,0,0,2,0,1);
1188 /* Note: Win32 writes the trailing zeros if they are within cDig's limits,
1189 * but then excludes them from the returned cDig count.
1190 * In our implementation we don't bother writing them at all.
1191 */
1192 EXPECTRGB(0, 1);
1193
1194 /* if cDig is too small and numbers follow, sets INEXACT */
1195 CONVERTN("11",1, 0);
1196 EXPECT(1,0,NUMPRS_INEXACT,2,0,1);
1197 EXPECT2(1,FAILDIG);
1198
1199 /* Strips leading zeros */
1200 CONVERT("01", 0);
1201 EXPECT(1,0,0,2,0,0);
1202 EXPECT2(1,FAILDIG);
1203
1204 /* Strips leading zeros */
1205 CONVERTN("01",1, 0);
1206 EXPECT(1,0,0,2,0,0);
1207 EXPECT2(1,FAILDIG);
1208
1209
1210 /* Fails on non digits */
1211 CONVERT("a", 0);
1212 EXPECTFAIL;
1213 EXPECTRGB(0,FAILDIG);
1214
1215 /** NUMPRS_LEADING_WHITE/NUMPRS_TRAILING_WHITE **/
1216
1217 /* Without flag, fails on whitespace */
1218 CONVERT(" 0", 0);
1219 EXPECTFAIL;
1220 EXPECTRGB(0,FAILDIG);
1221
1222
1223 /* With flag, consumes whitespace */
1224 CONVERT(" 0", NUMPRS_LEADING_WHITE);
1225 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
1226 EXPECT2(0,FAILDIG);
1227
1228 /* Test TAB once, then assume it acts as space for all cases */
1229 CONVERT("\t0", NUMPRS_LEADING_WHITE);
1230 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
1231 EXPECT2(0,FAILDIG);
1232
1233
1234 /* Doesn't pick up trailing whitespace without flag */
1235 CONVERT("0 ", 0);
1236 EXPECT(1,0,0,1,0,0);
1237 EXPECT2(0,FAILDIG);
1238
1239 /* With flag, consumes trailing whitespace */
1240 CONVERT("0 ", NUMPRS_TRAILING_WHITE);
1241 EXPECT(1,NUMPRS_TRAILING_WHITE,NUMPRS_TRAILING_WHITE,2,0,0);
1242 EXPECT2(0,FAILDIG);
1243
1244 /* Leading flag only consumes leading */
1245 CONVERT(" 0 ", NUMPRS_LEADING_WHITE);
1246 EXPECT(1,NUMPRS_LEADING_WHITE,NUMPRS_LEADING_WHITE,2,0,0);
1247 EXPECT2(0,FAILDIG);
1248
1249 /* Both flags consumes both */
1250 CONVERT(" 0 ", NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE);
1251 EXPECT(1,NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE,NUMPRS_LEADING_WHITE|NUMPRS_TRAILING_WHITE,3,0,0);
1252 EXPECT2(0,FAILDIG);
1253
1254 /** NUMPRS_LEADING_PLUS/NUMPRS_TRAILING_PLUS **/
1255
1256 /* Without flag, fails on + */
1257 CONVERT("+0", 0);
1258 EXPECTFAIL;
1259 EXPECTRGB(0,FAILDIG);
1260
1261 /* With flag, consumes + */
1262 CONVERT("+0", NUMPRS_LEADING_PLUS);
1263 EXPECT(1,NUMPRS_LEADING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
1264 EXPECT2(0,FAILDIG);
1265
1266 /* Without flag, doesn't consume trailing + */
1267 CONVERT("0+", 0);
1268 EXPECT(1,0,0,1,0,0);
1269 EXPECT2(0,FAILDIG);
1270
1271 /* With flag, consumes trailing + */
1272 CONVERT("0+", NUMPRS_TRAILING_PLUS);
1273 EXPECT(1,NUMPRS_TRAILING_PLUS,NUMPRS_TRAILING_PLUS,2,0,0);
1274 EXPECT2(0,FAILDIG);
1275
1276 /* With leading flag, doesn't consume trailing + */
1277 CONVERT("+0+", NUMPRS_LEADING_PLUS);
1278 EXPECT(1,NUMPRS_LEADING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
1279 EXPECT2(0,FAILDIG);
1280
1281 /* Trailing + doesn't get consumed if we specify both (unlike whitespace) */
1282 CONVERT("+0+", NUMPRS_LEADING_PLUS|NUMPRS_TRAILING_PLUS);
1283 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_TRAILING_PLUS,NUMPRS_LEADING_PLUS,2,0,0);
1284 EXPECT2(0,FAILDIG);
1285
1286 /** NUMPRS_LEADING_MINUS/NUMPRS_TRAILING_MINUS **/
1287
1288 /* Without flag, fails on - */
1289 CONVERT("-0", 0);
1290 EXPECTFAIL;
1291 EXPECTRGB(0,FAILDIG);
1292
1293 /* With flag, consumes - */
1294 CONVERT("-0", NUMPRS_LEADING_MINUS);
1295 EXPECT(1,NUMPRS_LEADING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
1296 EXPECT2(0,FAILDIG);
1297
1298 /* Without flag, doesn't consume trailing - */
1299 CONVERT("0-", 0);
1300 EXPECT(1,0,0,1,0,0);
1301 EXPECT2(0,FAILDIG);
1302
1303 /* With flag, consumes trailing - */
1304 CONVERT("0-", NUMPRS_TRAILING_MINUS);
1305 EXPECT(1,NUMPRS_TRAILING_MINUS,NUMPRS_NEG|NUMPRS_TRAILING_MINUS,2,0,0);
1306 EXPECT2(0,FAILDIG);
1307
1308 /* With leading flag, doesn't consume trailing - */
1309 CONVERT("-0-", NUMPRS_LEADING_MINUS);
1310 EXPECT(1,NUMPRS_LEADING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
1311 EXPECT2(0,FAILDIG);
1312
1313 /* Trailing - doesn't get consumed if we specify both (unlike whitespace) */
1314 CONVERT("-0-", NUMPRS_LEADING_MINUS|NUMPRS_TRAILING_MINUS);
1315 EXPECT(1,NUMPRS_LEADING_MINUS|NUMPRS_TRAILING_MINUS,NUMPRS_NEG|NUMPRS_LEADING_MINUS,2,0,0);
1316 EXPECT2(0,FAILDIG);
1317
1318 /** NUMPRS_HEX_OCT **/
1319
1320 /* Could be hex, octal or decimal - With flag reads as decimal */
1321 CONVERT("0", NUMPRS_HEX_OCT);
1322 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
1323 EXPECT2(0,FAILDIG);
1324
1325 /* Doesn't recognise hex in .asm syntax */
1326 CONVERT("0h", NUMPRS_HEX_OCT);
1327 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
1328 EXPECT2(0,FAILDIG);
1329
1330 /* Doesn't fail with valid leading string but no digits */
1331 CONVERT("0x", NUMPRS_HEX_OCT);
1332 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
1333 EXPECT2(0,FAILDIG);
1334
1335 /* Doesn't recognise hex format numbers at all! */
1336 CONVERT("0x0", NUMPRS_HEX_OCT);
1337 EXPECT(1,NUMPRS_HEX_OCT,0,1,0,0);
1338 EXPECT2(0,FAILDIG);
1339
1340 /* Doesn't recognise plain hex digits either */
1341 CONVERT("FE", NUMPRS_HEX_OCT);
1342 EXPECTFAIL;
1343 EXPECTRGB(0,FAILDIG);
1344
1345 /* Octal */
1346 CONVERT("0100", NUMPRS_HEX_OCT);
1347 EXPECT(1,NUMPRS_HEX_OCT,0,4,0,2);
1348 EXPECTRGB(0,1);
1349 EXPECTRGB(1,0);
1350 EXPECTRGB(2,0);
1351 EXPECTRGB(3,FAILDIG);
1352
1353 /* VB hex */
1354 CONVERT("&HF800", NUMPRS_HEX_OCT);
1355 EXPECT(4,NUMPRS_HEX_OCT,0x40,6,4,0);
1356 EXPECTRGB(0,15);
1357 EXPECTRGB(1,8);
1358 EXPECTRGB(2,0);
1359 EXPECTRGB(3,0);
1360 EXPECTRGB(4,FAILDIG);
1361
1362 /* VB hex lower case and leading zero */
1363 CONVERT("&h0abcdef", NUMPRS_HEX_OCT);
1364 EXPECT(6,NUMPRS_HEX_OCT,0x40,9,4,0);
1365 EXPECTRGB(0,10);
1366 EXPECTRGB(1,11);
1367 EXPECTRGB(2,12);
1368 EXPECTRGB(3,13);
1369 EXPECTRGB(4,14);
1370 EXPECTRGB(5,15);
1371 EXPECTRGB(6,FAILDIG);
1372
1373 /* VB oct */
1374 CONVERT("&O300", NUMPRS_HEX_OCT);
1375 EXPECT(3,NUMPRS_HEX_OCT,0x40,5,3,0);
1376 EXPECTRGB(0,3);
1377 EXPECTRGB(1,0);
1378 EXPECTRGB(2,0);
1379 EXPECTRGB(3,FAILDIG);
1380
1381 /* VB oct lower case and leading zero */
1382 CONVERT("&o0777", NUMPRS_HEX_OCT);
1383 EXPECT(3,NUMPRS_HEX_OCT,0x40,6,3,0);
1384 EXPECTRGB(0,7);
1385 EXPECTRGB(1,7);
1386 EXPECTRGB(2,7);
1387 EXPECTRGB(3,FAILDIG);
1388
1389 /* VB oct char bigger than 7 */
1390 CONVERT("&o128", NUMPRS_HEX_OCT);
1391 EXPECT(2,NUMPRS_HEX_OCT,0x40,4,3,0);
1392 EXPECTRGB(0,1);
1393 EXPECTRGB(1,2);
1394 EXPECTRGB(3,FAILDIG);
1395
1396 /** NUMPRS_PARENS **/
1397
1398 /* Empty parens = error */
1399 CONVERT("()", NUMPRS_PARENS);
1400 EXPECTFAIL;
1401 EXPECTRGB(0,FAILDIG);
1402
1403 /* With flag, trailing parens not consumed */
1404 CONVERT("0()", NUMPRS_PARENS);
1405 EXPECT(1,NUMPRS_PARENS,0,1,0,0);
1406 EXPECT2(0,FAILDIG);
1407
1408 /* With flag, Number in parens made negative and parens consumed */
1409 CONVERT("(0)", NUMPRS_PARENS);
1410 EXPECT(1,NUMPRS_PARENS,NUMPRS_NEG|NUMPRS_PARENS,3,0,0);
1411 EXPECT2(0,FAILDIG);
1412
1413 /** NUMPRS_THOUSANDS **/
1414
1415 /* With flag, thousands sep. not needed */
1416 CONVERT("0", NUMPRS_THOUSANDS);
1417 EXPECT(1,NUMPRS_THOUSANDS,0,1,0,0);
1418 EXPECT2(0,FAILDIG);
1419
1420 /* With flag, thousands sep. and following digits consumed */
1421 CONVERT("1,000", NUMPRS_THOUSANDS);
1422 EXPECT(1,NUMPRS_THOUSANDS,NUMPRS_THOUSANDS,5,0,3);
1423 EXPECTRGB(0,1);
1424
1425 /* With flag and decimal point, thousands sep. but not decimals consumed */
1426 CONVERT("1,000.0", NUMPRS_THOUSANDS);
1427 EXPECT(1,NUMPRS_THOUSANDS,NUMPRS_THOUSANDS,5,0,3);
1428 EXPECTRGB(0,1);
1429
1430 /** NUMPRS_CURRENCY **/
1431
1432 /* Without flag, chokes on currency sign */
1433 CONVERT("$11", 0);
1434 EXPECTFAIL;
1435 EXPECTRGB(0,FAILDIG);
1436
1437 /* With flag, consumes currency sign */
1438 CONVERT("$11", NUMPRS_CURRENCY);
1439 EXPECT(2,NUMPRS_CURRENCY,NUMPRS_CURRENCY,3,0,0);
1440 EXPECT2(1,1);
1441 EXPECTRGB(2,FAILDIG);
1442
1443 /* With flag only, doesn't consume decimal point */
1444 CONVERT("$11.1", NUMPRS_CURRENCY);
1445 EXPECT(2,NUMPRS_CURRENCY,NUMPRS_CURRENCY,3,0,0);
1446 EXPECT2(1,1);
1447 EXPECTRGB(2,FAILDIG);
1448
1449 /* With flag and decimal flag, consumes decimal point and following digits */
1450 CONVERT("$11.1", NUMPRS_CURRENCY|NUMPRS_DECIMAL);
1451 EXPECT(3,NUMPRS_CURRENCY|NUMPRS_DECIMAL,NUMPRS_CURRENCY|NUMPRS_DECIMAL,5,0,-1);
1452 EXPECT2(1,1);
1453 EXPECTRGB(2,1);
1454 EXPECTRGB(3,FAILDIG);
1455
1456 /* Thousands flag can only be used with currency */
1457 CONVERT("$1,234", NUMPRS_CURRENCY|NUMPRS_THOUSANDS);
1458 EXPECT(4,NUMPRS_CURRENCY|NUMPRS_THOUSANDS,NUMPRS_CURRENCY|NUMPRS_THOUSANDS,6,0,0);
1459 EXPECT2(1,2);
1460 EXPECTRGB(2,3);
1461 EXPECTRGB(3,4);
1462 EXPECTRGB(4,FAILDIG);
1463
1464 /** NUMPRS_DECIMAL **/
1465
1466 /* With flag, consumes decimal point */
1467 CONVERT("1.1", NUMPRS_DECIMAL);
1468 EXPECT(2,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1);
1469 EXPECT2(1,1);
1470 EXPECTRGB(2,FAILDIG);
1471
1472 /* With flag, consumes decimal point. Skipping the decimal part is not an error */
1473 CONVERT("1.", NUMPRS_DECIMAL);
1474 EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,2,0,0);
1475 EXPECT2(1,FAILDIG);
1476
1477 /* Consumes only one decimal point */
1478 CONVERT("1.1.", NUMPRS_DECIMAL);
1479 EXPECT(2,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1);
1480 EXPECT2(1,1);
1481 EXPECTRGB(2,FAILDIG);
1482
1483 /** NUMPRS_EXPONENT **/
1484
1485 /* Without flag, doesn't consume exponent */
1486 CONVERT("1e1", 0);
1487 EXPECT(1,0,0,1,0,0);
1488 EXPECT2(1,FAILDIG);
1489
1490 /* With flag, consumes exponent */
1491 CONVERT("1e1", NUMPRS_EXPONENT);
1492 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,1);
1493 EXPECT2(1,FAILDIG);
1494
1495 /* Negative exponents are accepted without flags */
1496 CONVERT("1e-1", NUMPRS_EXPONENT);
1497 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,-1);
1498 EXPECT2(1,FAILDIG);
1499
1500 /* As are positive exponents and leading exponent 0s */
1501 CONVERT("1e+01", NUMPRS_EXPONENT);
1502 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,5,0,1);
1503 EXPECT2(1,FAILDIG);
1504
1505 /* The same for zero exponents */
1506 CONVERT("1e0", NUMPRS_EXPONENT);
1507 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,0);
1508 EXPECT2(1,FAILDIG);
1509
1510 /* Sign on a zero exponent doesn't matter */
1511 CONVERT("1e+0", NUMPRS_EXPONENT);
1512 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,0);
1513 EXPECT2(1,FAILDIG);
1514
1515 CONVERT("1e-0", NUMPRS_EXPONENT);
1516 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,4,0,0);
1517 EXPECT2(1,FAILDIG);
1518
1519 /* Doesn't consume a real number exponent */
1520 CONVERT("1e1.", NUMPRS_EXPONENT);
1521 EXPECT(1,NUMPRS_EXPONENT,NUMPRS_EXPONENT,3,0,1);
1522 EXPECT2(1,FAILDIG);
1523
1524 /* Powers of 10 are calculated from the position of any decimal point */
1525 CONVERT("1.5e20", NUMPRS_EXPONENT|NUMPRS_DECIMAL);
1526 EXPECT(2,NUMPRS_EXPONENT|NUMPRS_DECIMAL,NUMPRS_EXPONENT|NUMPRS_DECIMAL,6,0,19);
1527 EXPECT2(1,5);
1528
1529 CONVERT("1.5e-20", NUMPRS_EXPONENT|NUMPRS_DECIMAL);
1530 EXPECT(2,NUMPRS_EXPONENT|NUMPRS_DECIMAL,NUMPRS_EXPONENT|NUMPRS_DECIMAL,7,0,-21);
1531 EXPECT2(1,5);
1532
1533 /** NUMPRS_USE_ALL **/
1534
1535 /* Flag expects all digits */
1536 CONVERT("0", NUMPRS_USE_ALL);
1537 EXPECT(1,NUMPRS_USE_ALL,0,1,0,0);
1538 EXPECT2(0,FAILDIG);
1539
1540 /* Rejects anything trailing */
1541 CONVERT("0 ", NUMPRS_USE_ALL);
1542 EXPECTFAIL;
1543 EXPECT2(0,FAILDIG);
1544
1545 /* Unless consumed by trailing flag */
1546 CONVERT("0 ", NUMPRS_USE_ALL|NUMPRS_TRAILING_WHITE);
1547 EXPECT(1,NUMPRS_USE_ALL|NUMPRS_TRAILING_WHITE,NUMPRS_TRAILING_WHITE,2,0,0);
1548 EXPECT2(0,FAILDIG);
1549
1550 /** Combinations **/
1551
1552 /* Leading whitespace and plus, doesn't consume trailing whitespace */
1553 CONVERT("+ 0 ", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1554 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,3,0,0);
1555 EXPECT2(0,FAILDIG);
1556
1557 /* Order of whitespace and plus is unimportant */
1558 CONVERT(" +0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1559 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,3,0,0);
1560 EXPECT2(0,FAILDIG);
1561
1562 /* Leading whitespace can be repeated */
1563 CONVERT(" + 0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1564 EXPECT(1,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE,4,0,0);
1565 EXPECT2(0,FAILDIG);
1566
1567 /* But plus/minus etc. cannot */
1568 CONVERT("+ +0", NUMPRS_LEADING_PLUS|NUMPRS_LEADING_WHITE);
1569 EXPECTFAIL;
1570 EXPECTRGB(0,FAILDIG);
1571
1572 /* Inexact is not set if trailing zeros are removed */
1573 CONVERTN("10", 1, 0);
1574 EXPECT(1,0,0,2,0,1);
1575 EXPECT2(1,FAILDIG);
1576
1577 /* Make sure a leading 0 is stripped but decimals after it get read */
1578 CONVERT("-0.51", NUMPRS_STD);
1579 EXPECT(2,NUMPRS_STD,NUMPRS_NEG|NUMPRS_DECIMAL|NUMPRS_LEADING_MINUS,5,0,-2);
1580 EXPECT2(5,1);
1581
1582 /* Keep trailing zeros on whole number part of a decimal */
1583 CONVERT("10.1", NUMPRS_STD);
1584 EXPECT(3,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-1);
1585 EXPECT2(1,0);
1586 EXPECTRGB(2,1);
1587
1588 /* Zeros after decimal sign */
1589 CONVERT("0.01", NUMPRS_STD);
1590 EXPECT(1,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-2);
1591 EXPECT2(1,FAILDIG);
1592
1593 /* Trailing zeros after decimal part */
1594 CONVERT("0.10", NUMPRS_STD);
1595 EXPECT(1,NUMPRS_STD,NUMPRS_DECIMAL,4,0,-1);
1596 EXPECT2(1,0);
1597 }
1598
1599 static HRESULT (WINAPI *pVarNumFromParseNum)(NUMPARSE*,BYTE*,ULONG,VARIANT*);
1600
1601 /* Macros for converting and testing the result of VarNumFromParseNum */
1602 #define SETRGB(indx,val) if (!indx) memset(rgb, FAILDIG, sizeof(rgb)); rgb[indx] = val
1603 #undef CONVERT
1604 #define CONVERT(a,b,c,d,e,f,bits) \
1605 np.cDig = (a); np.dwInFlags = (b); np.dwOutFlags = (c); np.cchUsed = (d); \
1606 np.nBaseShift = (e); np.nPwr10 = (f); hres = pVarNumFromParseNum(&np, rgb, bits, &vOut)
1607 static const char *szFailOverflow = "Expected overflow, hres = %08x\n";
1608 #define EXPECT_OVERFLOW ok(hres == (HRESULT)DISP_E_OVERFLOW, szFailOverflow, hres)
1609 static const char *szFailOk = "Call failed, hres = %08x\n";
1610 #define EXPECT_OK ok(hres == (HRESULT)S_OK, szFailOk, hres); \
1611 if (hres == (HRESULT)S_OK)
1612 #define EXPECT_TYPE(typ) ok(V_VT(&vOut) == typ,"Expected Type = " #typ ", got %d\n", V_VT(&vOut))
1613 #define EXPECT_I1(val) EXPECT_OK { EXPECT_TYPE(VT_I1); \
1614 ok(V_I1(&vOut) == val, "Expected i1 = %d, got %d\n", (signed char)val, V_I1(&vOut)); }
1615 #define EXPECT_UI1(val) EXPECT_OK { EXPECT_TYPE(VT_UI1); \
1616 ok(V_UI1(&vOut) == val, "Expected ui1 = %d, got %d\n", (BYTE)val, V_UI1(&vOut)); }
1617 #define EXPECT_I2(val) EXPECT_OK { EXPECT_TYPE(VT_I2); \
1618 ok(V_I2(&vOut) == val, "Expected i2 = %d, got %d\n", (SHORT)val, V_I2(&vOut)); }
1619 #define EXPECT_UI2(val) EXPECT_OK { EXPECT_TYPE(VT_UI2); \
1620 ok(V_UI2(&vOut) == val, "Expected ui2 = %d, got %d\n", (USHORT)val, V_UI2(&vOut)); }
1621 #define EXPECT_I4(val) EXPECT_OK { EXPECT_TYPE(VT_I4); \
1622 ok(V_I4(&vOut) == val, "Expected i4 = %d, got %d\n", (LONG)val, V_I4(&vOut)); }
1623 #define EXPECT_UI4(val) EXPECT_OK { EXPECT_TYPE(VT_UI4); \
1624 ok(V_UI4(&vOut) == val, "Expected ui4 = %d, got %d\n", (ULONG)val, V_UI4(&vOut)); }
1625 #define EXPECT_I8(high,low) EXPECT_OK { EXPECT_TYPE(VT_I8); \
1626 ok(V_I8(&vOut) == ((((ULONG64)(high))<<32)|(low)), "Expected i8 = %x%08x, got %x%08x\n", \
1627 (LONG)(high), (LONG)(low), (LONG)(V_I8(&vOut)>>32), (LONG)V_I8(&vOut) ); }
1628 #define EXPECT_UI8(val) EXPECT_OK { EXPECT_TYPE(VT_UI8); \
1629 ok(V_UI8(&vOut) == val, "Expected ui8 = 0x%x%08x, got 0x%x%08x\n", \
1630 (DWORD)((ULONG64)val >> 32), (DWORD)(ULONG64)val, (DWORD)(V_UI8(&vOut) >> 32), (DWORD)V_UI8(&vOut)); }
1631 #define EXPECT_R4(val) EXPECT_OK { EXPECT_TYPE(VT_R4); \
1632 ok(V_R4(&vOut) == val, "Expected r4 = %f, got %f\n", val, V_R4(&vOut)); }
1633 #define EXPECT_R8(val) EXPECT_OK { EXPECT_TYPE(VT_R8); \
1634 ok(V_R8(&vOut) == val, "Expected r8 = %g, got %g\n", val, V_R8(&vOut)); }
1635 #define CY_MULTIPLIER 10000
1636 #define EXPECT_CY(val) EXPECT_OK { EXPECT_TYPE(VT_CY); \
1637 ok(V_CY(&vOut).int64 == (LONG64)(val * CY_MULTIPLIER), "Expected r8 = 0x%x%08x, got 0x%x%08x\n", \
1638 (DWORD)((LONG64)val >> 23), (DWORD)(LONG64)val, (DWORD)(V_CY(&vOut).int64 >>32), (DWORD)V_CY(&vOut).int64); }
1639 #define EXPECT_DECIMAL(valHi, valMid, valLo) EXPECT_OK { EXPECT_TYPE(VT_DECIMAL); \
1640 ok((V_DECIMAL(&vOut).Hi32 == valHi) && (S1(U1(V_DECIMAL(&vOut))).Mid32 == valMid) && \
1641 (S1(U1(V_DECIMAL(&vOut))).Lo32 == valLo), \
1642 "Expected decimal = %x/0x%x%08x, got %x/0x%x%08x\n", valHi, valMid, valLo, \
1643 V_DECIMAL(&vOut).Hi32, S1(U1(V_DECIMAL(&vOut))).Mid32, S1(U1(V_DECIMAL(&vOut))).Lo32); }
1644
1645 static void test_VarNumFromParseNum(void)
1646 {
1647 HRESULT hres;
1648 NUMPARSE np;
1649 BYTE rgb[128];
1650 VARIANT vOut;
1651
1652 CHECKPTR(VarNumFromParseNum);
1653
1654 /* Convert the number 1 to different types */
1655 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I1); EXPECT_I1(1);
1656 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_UI1); EXPECT_UI1(1);
1657 /* Prefers a signed type to unsigned of the same size */
1658 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I1|VTBIT_UI1); EXPECT_I1(1);
1659 /* But takes the smaller size if possible */
1660 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_I2|VTBIT_UI1); EXPECT_UI1(1);
1661
1662 /* Try different integer sizes */
1663 #define INTEGER_VTBITS (VTBIT_I1|VTBIT_UI1|VTBIT_I2|VTBIT_UI2|VTBIT_I4|VTBIT_UI4|VTBIT_I8|VTBIT_UI8)
1664
1665 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, INTEGER_VTBITS); EXPECT_I1(1);
1666 /* 127 */
1667 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 7);
1668 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_I1(127);
1669 /* 128 */
1670 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 8);
1671 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_UI1(128);
1672 /* 255 */
1673 SETRGB(0, 2); SETRGB(1, 5); SETRGB(2, 5);
1674 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_UI1(255);
1675 /* 256 */
1676 SETRGB(0, 2); SETRGB(1, 5); SETRGB(2, 6);
1677 CONVERT(3,0,0,3,0,0, INTEGER_VTBITS); EXPECT_I2(256);
1678 /* 32767 */
1679 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 7);
1680 CONVERT(5,0,0,5,0,0, INTEGER_VTBITS); EXPECT_I2(32767);
1681 /* 32768 */
1682 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 8);
1683 CONVERT(5,0,0,5,0,0, INTEGER_VTBITS); EXPECT_UI2(32768);
1684
1685 /* Assume the above pattern holds for remaining positive integers; test negative */
1686
1687 /* -128 */
1688 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 8);
1689 CONVERT(3,0,NUMPRS_NEG,3,0,0, INTEGER_VTBITS); EXPECT_I1(-128);
1690 /* -129 */
1691 SETRGB(0, 1); SETRGB(1, 2); SETRGB(2, 9);
1692 CONVERT(3,0,NUMPRS_NEG,3,0,0, INTEGER_VTBITS); EXPECT_I2(-129);
1693 /* -32768 */
1694 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 8);
1695 CONVERT(5,0,NUMPRS_NEG,5,0,0, INTEGER_VTBITS); EXPECT_I2(-32768);
1696 /* -32768 */
1697 SETRGB(0, 3); SETRGB(1, 2); SETRGB(2, 7); SETRGB(3, 6); SETRGB(4, 9);
1698 CONVERT(5,0,NUMPRS_NEG,5,0,0, INTEGER_VTBITS); EXPECT_I4(-32769);
1699
1700 /* Assume the above pattern holds for remaining negative integers */
1701
1702 /* Test hexadecimal conversions */
1703 SETRGB(0, 1); CONVERT(1,0,0,1,4,0, INTEGER_VTBITS); EXPECT_I1(0x01);
1704 /* 0x7f */
1705 SETRGB(0, 7); SETRGB(1, 0xf);
1706 CONVERT(2,0,0,2,4,0, INTEGER_VTBITS); EXPECT_I1(0x7f);
1707 SETRGB(0, 7); SETRGB(1, 0xf);
1708 CONVERT(2,0,0,2,4,0, VTBIT_DECIMAL); EXPECT_DECIMAL(0,0,0x7f);
1709 /* 0x7fff */
1710 SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
1711 CONVERT(4,0,0,4,4,0, INTEGER_VTBITS); EXPECT_I2(0x7fff);
1712 /* 0x7fffffff */
1713 SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
1714 SETRGB(4, 0xf); SETRGB(5, 0xf); SETRGB(6, 0xf); SETRGB(7, 0xf);
1715 CONVERT(8,0,0,8,4,0, INTEGER_VTBITS); EXPECT_I4(0x7fffffffL);
1716 /* 0x7fffffffffffffff (64 bits) */
1717 SETRGB(0, 7); SETRGB(1, 0xf); SETRGB(2, 0xf); SETRGB(3, 0xf);
1718 SETRGB(4, 0xf); SETRGB(5, 0xf); SETRGB(6, 0xf); SETRGB(7, 0xf);
1719 SETRGB(8, 0xf); SETRGB(9, 0xf); SETRGB(10, 0xf); SETRGB(11, 0xf);
1720 SETRGB(12, 0xf); SETRGB(13, 0xf); SETRGB(14, 0xf); SETRGB(15, 0xf);
1721 if (has_i8)
1722 {
1723 /* We cannot use INTEGER_VTBITS as WinXP and Win2003 are broken(?). They
1724 truncate the number to the smallest integer size requested:
1725 CONVERT(16,0,0,16,4,0, INTEGER_VTBITS); EXPECT_I1((signed char)0xff); */
1726 CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x7fffffff,0xffffffff);
1727 }
1728
1729 /* Assume the above pattern holds for numbers without hi-bit set, test (preservation of) hi-bit */
1730 /* 0x82 */
1731 SETRGB(0, 8); SETRGB(1, 2);
1732 CONVERT(2,0,0,2,4,0, INTEGER_VTBITS);
1733 EXPECT_I1((signed char)0x82);
1734 /* 0x8002 */
1735 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 2);
1736 CONVERT(4,0,0,4,4,0, INTEGER_VTBITS);
1737 EXPECT_I2((signed short)0x8002);
1738 /* 0x80000002 */
1739 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1740 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 2);
1741 CONVERT(8,0,0,8,4,0, INTEGER_VTBITS); EXPECT_I4(0x80000002);
1742 /* 0x8000000000000002 (64 bits) */
1743 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1744 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 0);
1745 SETRGB(8, 0); SETRGB(9, 0); SETRGB(10, 0); SETRGB(11, 0);
1746 SETRGB(12, 0); SETRGB(13, 0); SETRGB(14, 0); SETRGB(15, 2);
1747 if (has_i8)
1748 {
1749 /* We cannot use INTEGER_VTBITS as WinXP and Win2003 are broken(?). They
1750 truncate the number to the smallest integer size requested:
1751 CONVERT(16,0,0,16,4,0, INTEGER_VTBITS & ~VTBIT_I1);
1752 EXPECT_I2((signed short)0x0002); */
1753 CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x80000000,0x00000002);
1754 }
1755
1756 /* Test (preservation of) hi-bit with STRICT type requesting */
1757 /* 0x82 */
1758 SETRGB(0, 8); SETRGB(1, 2);
1759 CONVERT(2,0,0,2,4,0, VTBIT_I1);
1760 EXPECT_I1((signed char)0x82);
1761 /* 0x8002 */
1762 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 2);
1763 CONVERT(4,0,0,4,4,0, VTBIT_I2);
1764 EXPECT_I2((signed short)0x8002);
1765 /* 0x80000002 */
1766 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1767 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 2);
1768 CONVERT(8,0,0,8,4,0, VTBIT_I4); EXPECT_I4(0x80000002);
1769 /* 0x8000000000000002 (64 bits) */
1770 SETRGB(0, 8); SETRGB(1, 0); SETRGB(2, 0); SETRGB(3, 0);
1771 SETRGB(4, 0); SETRGB(5, 0); SETRGB(6, 0); SETRGB(7, 0);
1772 SETRGB(8, 0); SETRGB(9, 0); SETRGB(10, 0); SETRGB(11, 0);
1773 SETRGB(12, 0); SETRGB(13, 0); SETRGB(14, 0); SETRGB(15, 2);
1774 if (has_i8)
1775 {
1776 CONVERT(16,0,0,16,4,0, VTBIT_I8); EXPECT_I8(0x80000000,0x00000002);
1777 }
1778 /* Assume the above pattern holds for numbers with hi-bit set */
1779
1780 /* Negative numbers overflow if we have only unsigned outputs */
1781 /* -1 */
1782 SETRGB(0, 1); CONVERT(1,0,NUMPRS_NEG,1,0,0, VTBIT_UI1); EXPECT_OVERFLOW;
1783 /* -0.6 */
1784 SETRGB(0, 6); CONVERT(1,0,NUMPRS_NEG,1,0,~0u, VTBIT_UI1); EXPECT_OVERFLOW;
1785
1786 /* Except that rounding is done first, so -0.5 to 0 are accepted as 0 */
1787 /* -0.5 */
1788 SETRGB(0, 5); CONVERT(1,0,NUMPRS_NEG,1,0,~0u, VTBIT_UI1); EXPECT_UI1(0);
1789
1790 /* Floating point zero is OK */
1791 /* 0.00000000E0 */
1792 SETRGB(0, 0); CONVERT(1,0,NUMPRS_DECIMAL|NUMPRS_EXPONENT,12,0,-8, VTBIT_R8);
1793 EXPECT_R8(0.0);
1794
1795 /* Float is acceptable for an integer input value */
1796 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R4); EXPECT_R4(1.0f);
1797 /* As is double */
1798 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R8); EXPECT_R8(1.0);
1799 /* As is currency */
1800 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_CY); EXPECT_CY(1);
1801
1802 /* Float is preferred over double */
1803 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R4|VTBIT_R8); EXPECT_R4(1.0f);
1804
1805 /* Double is preferred over currency */
1806 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_R8|VTBIT_CY); EXPECT_R8(1.0);
1807
1808 /* Currency is preferred over decimal */
1809 SETRGB(0, 1); CONVERT(1,0,0,1,0,0, VTBIT_CY|VTBIT_DECIMAL); EXPECT_CY(1);
1810 }
1811
1812
1813 static void test_UdateFromDate( int line, DATE dt, ULONG flags, HRESULT r, WORD d, WORD m, WORD y,
1814 WORD h, WORD mn, WORD s, WORD ms, WORD dw, WORD dy)
1815 {
1816 UDATE ud;
1817 HRESULT res;
1818
1819 memset(&ud, 0, sizeof(ud));
1820 res = pVarUdateFromDate(dt, flags, &ud);
1821 ok_(__FILE__,line)(r == res && (res != S_OK || (ud.st.wYear == y && ud.st.wMonth == m && ud.st.wDay == d &&
1822 ud.st.wHour == h && ud.st.wMinute == mn && ud.st.wSecond == s &&
1823 ud.st.wMilliseconds == ms && ud.st.wDayOfWeek == dw && ud.wDayOfYear == dy)),
1824 "%.16g expected res(%x) %d,%d,%d,%d,%d,%d,%d %d %d, got res(%x) %d,%d,%d,%d,%d,%d,%d %d %d\n",
1825 dt, r, d, m, y, h, mn, s, ms, dw, dy,
1826 res, ud.st.wDay, ud.st.wMonth, ud.st.wYear, ud.st.wHour, ud.st.wMinute,
1827 ud.st.wSecond, ud.st.wMilliseconds, ud.st.wDayOfWeek, ud.wDayOfYear );
1828 }
1829 #define DT2UD(dt,flags,r,d,m,y,h,mn,s,ms,dw,dy) test_UdateFromDate(__LINE__,dt,flags,r,d,m,y,h,mn,s,ms,dw,dy)
1830
1831 static void test_VarUdateFromDate(void)
1832 {
1833 CHECKPTR(VarUdateFromDate);
1834 DT2UD(29221.0,0,S_OK,1,1,1980,0,0,0,0,2,1); /* 1 Jan 1980 */
1835 DT2UD(29222.0,0,S_OK,2,1,1980,0,0,0,0,3,2); /* 2 Jan 1980 */
1836 DT2UD(33238.0,0,S_OK,31,12,1990,0,0,0,0,1,365); /* 31 Dec 1990 */
1837 DT2UD(0.0,0,S_OK,30,12,1899,0,0,0,0,6,364); /* 30 Dec 1899 - VT_DATE 0.0 */
1838 DT2UD(-657434.0,0,S_OK,1,1,100,0,0,0,0,5,1); /* 1 Jan 100 - Min */
1839 DT2UD(-657435.0,0,E_INVALIDARG,0,0,0,0,0,0,0,0,0); /* < 1 Jan 100 => err */
1840 DT2UD(2958465.0,0,S_OK,31,12,9999,0,0,0,0,5,365); /* 31 Dec 9999 - Max */
1841 DT2UD(2958466.0,0,E_INVALIDARG,0,0,0,0,0,0,0,0,0); /* > 31 Dec 9999 => err */
1842
1843 /* VAR_VALIDDATE doesn't prevent upper and lower bounds being checked */
1844 DT2UD(-657435.0,VAR_VALIDDATE,E_INVALIDARG,0,0,0,0,0,0,0,0,0);
1845 DT2UD(2958466.0,VAR_VALIDDATE,E_INVALIDARG,0,0,0,0,0,0,0,0,0);
1846
1847 /* Times */
1848 DT2UD(29221.25,0,S_OK,1,1,1980,6,0,0,0,2,1); /* 6 AM */
1849 DT2UD(29221.33333333,0,S_OK,1,1,1980,8,0,0,0,2,1); /* 8 AM */
1850 DT2UD(29221.5,0,S_OK,1,1,1980,12,0,0,0,2,1); /* 12 AM */
1851 DT2UD(29221.9888884444,0,S_OK,1,1,1980,23,44,0,0,2,1); /* 11:44 PM */
1852 DT2UD(29221.7508765432,0,S_OK,1,1,1980,18,1,16,0,2,1); /* 6:18:02 PM */
1853
1854 /* Test handling of times on dates prior to the epoch */
1855 DT2UD(-5.25,0,S_OK,25,12,1899,6,0,0,0,1,359);
1856 DT2UD(-5.9999884259259,0,S_OK,25,12,1899,23,59,59,0,1,359);
1857 /* This just demonstrates the non-linear nature of values prior to the epoch */
1858 DT2UD(-4.0,0,S_OK,26,12,1899,0,0,0,0,2,360);
1859 /* Numerical oddity: for 0.0 < x < 1.0, x and -x represent the same datetime */
1860 DT2UD(-0.25,0,S_OK,30,12,1899,6,0,0,0,6,364);
1861 DT2UD(0.25,0,S_OK,30,12,1899,6,0,0,0,6,364);
1862 }
1863
1864
1865 static void test_DateFromUDate( int line, WORD d, WORD m, WORD y, WORD h, WORD mn, WORD s, WORD ms,
1866 WORD dw, WORD dy, ULONG flags, HRESULT r, DATE dt )
1867 {
1868 UDATE ud;
1869 double out;
1870 HRESULT res;
1871
1872 ud.st.wYear = y;
1873 ud.st.wMonth = m;
1874 ud.st.wDay = d;
1875 ud.st.wHour = h;
1876 ud.st.wMinute = mn;
1877 ud.st.wSecond = s;
1878 ud.st.wMilliseconds = ms;
1879 ud.st.wDayOfWeek = dw;
1880 ud.wDayOfYear = dy;
1881 res = pVarDateFromUdate(&ud, flags, &out);
1882 ok_(__FILE__,line)(r == res && (r != S_OK || EQ_DOUBLE(out, dt)),
1883 "expected %x, %.16g, got %x, %.16g\n", r, dt, res, out);
1884 }
1885 #define UD2T(d,m,y,h,mn,s,ms,dw,dy,flags,r,dt) test_DateFromUDate(__LINE__,d,m,y,h,mn,s,ms,dw,dy,flags,r,dt)
1886
1887 static void test_VarDateFromUdate(void)
1888 {
1889 CHECKPTR(VarDateFromUdate);
1890 UD2T(1,1,1980,0,0,0,0,2,1,0,S_OK,29221.0); /* 1 Jan 1980 */
1891 UD2T(2,1,1980,0,0,0,0,3,2,0,S_OK,29222.0); /* 2 Jan 1980 */
1892 UD2T(2,1,1980,0,0,0,0,4,5,0,S_OK,29222.0); /* 2 Jan 1980 */
1893 UD2T(31,12,1990,0,0,0,0,0,0,0,S_OK,33238.0); /* 31 Dec 1990 */
1894 UD2T(31,12,90,0,0,0,0,0,0,0,S_OK,33238.0); /* year < 100 is 1900+year! */
1895 UD2T(30,12,1899,0,0,0,0,6,364,0,S_OK,0.0); /* 30 Dec 1899 - VT_DATE 0.0 */
1896 UD2T(1,1,100,0,0,0,0,0,0,0,S_OK,-657434.0); /* 1 Jan 100 - Min */
1897 UD2T(31,12,9999,0,0,0,0,0,0,0,S_OK,2958465.0); /* 31 Dec 9999 - Max */
1898 UD2T(1,1,10000,0,0,0,0,0,0,0,E_INVALIDARG,0.0); /* > 31 Dec 9999 => err */
1899 UD2T(1,1,-10000,0,0,0,0,0,0,0,E_INVALIDARG,0.0);/* < -9999 => err */
1900
1901 UD2T(30,12,1899,0,0,0,0,0,0,0,S_OK,0.0); /* 30 Dec 1899 0:00:00 */
1902 UD2T(30,12,1899,0,0,0,999,0,0,0,S_OK,0.0); /* Ignore milliseconds */
1903
1904 UD2T(1,1,1980,18,1,16,0,2,1,0,S_OK,29221.75087962963); /* 6:18:02 PM */
1905 UD2T(1,300,1980,18,1,16,0,2,1,0,S_OK,38322.75087962963); /* Test fwdrolled month */
1906 UD2T(300,1,1980,18,1,16,0,2,1,0,S_OK,29520.75087962963); /* Test fwdrolled days */
1907 UD2T(0,1,1980,42,1,16,0,2,1,0,S_OK,29221.75087962963); /* Test fwdrolled hours */
1908 UD2T(1,1,1980,17,61,16,0,2,1,0,S_OK,29221.75087962963); /* Test fwdrolled minutes */
1909 UD2T(1,1,1980,18,0,76,0,2,1,0,S_OK,29221.75087962963); /* Test fwdrolled seconds */
1910 UD2T(1,-300,1980,18,1,16,0,2,1,0,S_OK,20059.75087962963); /* Test backrolled month */
1911 UD2T(-300,1,1980,18,1,16,0,2,1,0,S_OK,28920.75087962963); /* Test backrolled days */
1912 UD2T(3,1,1980,-30,1,16,0,2,1,0,S_OK,29221.75087962963); /* Test backrolled hours */
1913 UD2T(1,1,1980,20,-119,16,0,2,1,0,S_OK,29221.75087962963); /* Test backrolled minutes */
1914 UD2T(1,1,1980,18,3,-104,0,2,1,0,S_OK,29221.75087962963); /* Test backrolled seconds */
1915 UD2T(1,12001,-1020,18,1,16,0,0,0,0,S_OK,29221.75087962963); /* Test rolled year and month */
1916 UD2T(1,-23,1982,18,1,16,0,0,0,0,S_OK,29221.75087962963); /* Test backrolled month */
1917 UD2T(-59,3,1980,18,1,16,0,0,0,0,S_OK,29221.75087962963); /* Test backrolled days */
1918 UD2T(1,1,0,0,0,0,0,0,0,0,S_OK,36526); /* Test zero year */
1919 UD2T(0,0,1980,0,0,0,0,0,0,0,S_OK,29189); /* Test zero day and month */
1920 UD2T(0,1,1980,0,0,0,0,2,1,0,S_OK,29220.0); /* Test zero day = LastDayOfMonth */
1921 UD2T(-1,1,1980,18,1,16,0,0,0,0,S_OK,29219.75087962963); /* Test day -1 = LastDayOfMonth - 1 */
1922 UD2T(1,1,-1,18,1,16,0,0,0,0,S_OK,36161.75087962963); /* Test year -1 = 1999 */
1923 UD2T(1,-1,1980,18,1,16,0,0,0,0,S_OK,29160.7508796296); /* Test month -1 = 11 */
1924 UD2T(1,13,1980,0,0,0,0,2,1,0,S_OK,29587.0); /* Rolls fwd to 1/1/1981 */
1925
1926 /* Test handling of times on dates prior to the epoch */
1927 UD2T(25,12,1899,6,0,0,0,1,359,0,S_OK,-5.25);
1928 UD2T(25,12,1899,23,59,59,0,1,359,0,S_OK,-5.9999884259259);
1929 /* This just demonstrates the non-linear nature of values prior to the epoch */
1930 UD2T(26,12,1899,0,0,0,0,2,360,0,S_OK,-4.0);
1931 /* for DATE values 0.0 < x < 1.0, x and -x represent the same datetime */
1932 /* but when converting to DATE, prefer the positive versions */
1933 UD2T(30,12,1899,6,0,0,0,6,364,0,S_OK,0.25);
1934
1935 UD2T(1,1,1980,18,1,16,0,2,1,VAR_TIMEVALUEONLY,S_OK,0.7508796296296296);
1936 UD2T(1,1,1980,18,1,16,0,2,1,VAR_DATEVALUEONLY,S_OK,29221.0);
1937 UD2T(25,12,1899,6,0,0,0,1,359,VAR_TIMEVALUEONLY,S_OK,0.25);
1938 UD2T(25,12,1899,6,0,0,0,1,359,VAR_DATEVALUEONLY,S_OK,-5.0);
1939 UD2T(1,-1,1980,18,1,16,0,0,0,VAR_TIMEVALUEONLY|VAR_DATEVALUEONLY,S_OK,0.7508796296296296);
1940 }
1941
1942 static void test_st2dt(int line, WORD d, WORD m, WORD y, WORD h, WORD mn,
1943 WORD s, WORD ms, INT r, double dt)
1944 {
1945 SYSTEMTIME st;
1946 double out;
1947 INT res;
1948
1949 st.wYear = y;
1950 st.wMonth = m;
1951 st.wDay = d;
1952 st.wHour = h;
1953 st.wMinute = mn;
1954 st.wSecond = s;
1955 st.wMilliseconds = ms;
1956 st.wDayOfWeek = 0;
1957 res = pSystemTimeToVariantTime(&st, &out);
1958 ok_(__FILE__,line)(r == res && (!r || EQ_DOUBLE(out, dt)),
1959 "expected %d, %.16g, got %d, %.16g\n", r, dt, res, out);
1960 }
1961 #define ST2DT(d,m,y,h,mn,s,ms,r,dt) test_st2dt(__LINE__,d,m,y,h,mn,s,ms,r,dt)
1962
1963 static void test_SystemTimeToVariantTime(void)
1964 {
1965 CHECKPTR(SystemTimeToVariantTime);
1966 ST2DT(1,1,1980,0,0,0,0,TRUE,29221.0);
1967 ST2DT(2,1,1980,0,0,0,0,TRUE,29222.0);
1968 ST2DT(0,1,1980,0,0,0,0,TRUE,29220.0); /* Rolls back to 31 Dec 1899 */
1969 ST2DT(1,13,1980,0,0,0,0,FALSE,29587.0); /* Fails on invalid month */
1970 ST2DT(32,1,1980,0,0,0,0,FALSE,0.0); /* Fails on invalid day */
1971 ST2DT(1,1,-1,0,0,0,0,FALSE,0.0); /* Fails on invalid year */
1972 ST2DT(1,1,10000,0,0,0,0,FALSE,0.0); /* Fails on invalid year */
1973 ST2DT(1,1,9999,0,0,0,0,TRUE,2958101.0); /* 9999 is last valid year */
1974 ST2DT(31,12,90,0,0,0,0,TRUE,33238.0); /* 30 <= year < 100 is 1900+year */
1975 ST2DT(1,1,30,0,0,0,0,TRUE,10959.0); /* 30 <= year < 100 is 1900+year */
1976 ST2DT(1,1,29,0,0,0,0,TRUE,47119.0); /* 0 <= year < 30 is 2000+year */
1977 ST2DT(1,1,0,0,0,0,0,TRUE,36526.0); /* 0 <= year < 30 is 2000+year */
1978 }
1979
1980 static void test_dt2st(int line, double dt, INT r, WORD d, WORD m, WORD y,
1981 WORD h, WORD mn, WORD s, WORD ms)
1982 {
1983 SYSTEMTIME st;
1984 INT res;
1985
1986 memset(&st, 0, sizeof(st));
1987 res = pVariantTimeToSystemTime(dt, &st);
1988 ok_(__FILE__,line)(r == res &&
1989 (!r || (st.wYear == y && st.wMonth == m && st.wDay == d &&
1990 st.wHour == h && st.wMinute == mn &&
1991 st.wSecond == s && st.wMilliseconds == ms)),
1992 "%.16g expected %d, %d,%d,%d,%d,%d,%d,%d, got %d, %d,%d,%d,%d,%d,%d,%d\n",
1993 dt, r, d, m, y, h, mn, s, ms, res, st.wDay, st.wMonth,
1994 st.wYear, st.wHour, st.wMinute, st.wSecond,
1995 st.wMilliseconds);
1996 }
1997 #define DT2ST(dt,r,d,m,y,h,mn,s,ms) test_dt2st(__LINE__,dt,r,d,m,y,h,mn,s,ms)
1998
1999 static void test_VariantTimeToSystemTime(void)
2000 {
2001 CHECKPTR(VariantTimeToSystemTime);
2002 DT2ST(29221.0,1,1,1,1980,0,0,0,0);
2003 DT2ST(29222.0,1,2,1,1980,0,0,0,0);
2004 }
2005
2006 #define MKDOSDATE(d,m,y) ((d & 0x1f) | ((m & 0xf) << 5) | (((y-1980) & 0x7f) << 9))
2007 #define MKDOSTIME(h,m,s) (((s>>1) & 0x1f) | ((m & 0x3f) << 5) | ((h & 0x1f) << 11))
2008
2009 static void test_dos2dt(int line, WORD d, WORD m, WORD y, WORD h, WORD mn,
2010 WORD s, INT r, double dt)
2011 {
2012 unsigned short dosDate, dosTime;
2013 double out;
2014 INT res;
2015
2016 out = 0.0;
2017 dosDate = MKDOSDATE(d, m, y);
2018 dosTime = MKDOSTIME(h, mn, s);
2019 res = pDosDateTimeToVariantTime(dosDate, dosTime, &out);
2020 ok_(__FILE__,line)(r == res && (!r || EQ_DOUBLE(out, dt)),
2021 "expected %d, %.16g, got %d, %.16g\n", r, dt, res, out);
2022 }
2023 #define DOS2DT(d,m,y,h,mn,s,r,dt) test_dos2dt(__LINE__,d,m,y,h,mn,s,r,dt)
2024
2025 static void test_DosDateTimeToVariantTime(void)
2026 {
2027 CHECKPTR(DosDateTimeToVariantTime);
2028
2029 /* Date */
2030 DOS2DT(1,1,1980,0,0,0,1,29221.0); /* 1/1/1980 */
2031 DOS2DT(31,12,2099,0,0,0,1,73050.0); /* 31/12/2099 */
2032 /* Dates are limited to the dos date max of 31/12/2099 */
2033 DOS2DT(31,12,2100,0,0,0,0,0.0); /* 31/12/2100 */
2034 /* Days and months of 0 cause date to roll back 1 day or month */
2035 DOS2DT(0,1,1980,0,0,0,1,29220.0); /* 0 Day => 31/12/1979 */
2036 DOS2DT(1,0,1980,0,0,0,1,29190.0); /* 0 Mth => 1/12/1979 */
2037 DOS2DT(0,0,1980,0,0,0,1,29189.0); /* 0 D/M => 30/11/1979 */
2038 /* Days > days in the month cause date to roll forward 1 month */
2039 DOS2DT(29,2,1981,0,0,0,1,29646.0); /* 29/2/1981 -> 3/1/1980 */
2040 DOS2DT(30,2,1981,0,0,0,1,29647.0); /* 30/2/1981 -> 4/1/1980 */
2041 /* Takes leap years into account when rolling forward */
2042 DOS2DT(29,2,1980,0,0,0,1,29280.0); /* 2/29/1980 */
2043 /* Months > 12 cause an error */
2044 DOS2DT(2,13,1980,0,0,0,0,0.0);
2045
2046 /* Time */
2047 DOS2DT(1,1,1980,0,0,29,1,29221.00032407407); /* 1/1/1980 12:00:28 AM */
2048 DOS2DT(1,1,1980,0,0,31,1,29221.00034722222); /* 1/1/1980 12:00:30 AM */
2049 DOS2DT(1,1,1980,0,59,0,1,29221.04097222222); /* 1/1/1980 12:59:00 AM */
2050 DOS2DT(1,1,1980,0,60,0,0,0.0); /* Invalid minutes */
2051 DOS2DT(1,1,1980,0,0,60,0,0.0); /* Invalid seconds */
2052 DOS2DT(1,1,1980,23,0,0,1,29221.95833333333); /* 1/1/1980 11:00:00 PM */
2053 DOS2DT(1,1,1980,24,0,0,0,0.0); /* Invalid hours */
2054
2055 DOS2DT(1,1,1980,0,0,1,1,29221.0);
2056 DOS2DT(2,1,1980,0,0,0,1,29222.0);
2057 DOS2DT(2,1,1980,0,0,0,1,29222.0);
2058 DOS2DT(31,12,1990,0,0,0,1,33238.0);
2059 DOS2DT(31,12,90,0,0,0,1,40543.0);
2060 DOS2DT(30,12,1899,0,0,0,1,46751.0);
2061 DOS2DT(1,1,100,0,0,0,1,43831.0);
2062 DOS2DT(31,12,9999,0,0,0,1,59901.0);
2063 DOS2DT(1,1,10000,0,0,0,1,59902.0);
2064 DOS2DT(1,1,-10000,0,0,0,1,48214.0);
2065
2066 DOS2DT(30,12,1899,0,0,0,1,46751.0);
2067 DOS2DT(30,12,1899,0,0,1,1,46751.0);
2068
2069 DOS2DT(1,1,1980,18,1,16,1,29221.75087962963);
2070 DOS2DT(1,300,1980,18,1,16,1,29556.75087962963);
2071 DOS2DT(300,1,1980,18,1,16,1,29232.75087962963);
2072 DOS2DT(0,1,1980,42,1,16,1,29220.4175462963);
2073 DOS2DT(1,1,1980,17,61,16,0,0.0);
2074 DOS2DT(1,1,1980,18,0,76,1,29221.75013888889);
2075 DOS2DT(1,-300,1980,18,1,16,1,29312.75087962963);
2076 DOS2DT(-300,1,1980,18,1,16,1,29240.75087962963);
2077 DOS2DT(3,1,1980,-30,1,16,1,29223.08421296296);
2078 DOS2DT(1,1,1980,20,-119,16,1,29221.83976851852);
2079 DOS2DT(1,1,1980,18,3,-104,1,29221.75236111111);
2080 DOS2DT(1,12001,-1020,18,1,16,1,55519.75087962963);
2081 DOS2DT(1,-23,1982,18,1,16,1,30195.75087962963);
2082 DOS2DT(-59,3,1980,18,1,16,1,29285.75087962963);
2083 DOS2DT(1,1,0,0,0,0,1,54058.0);
2084 DOS2DT(0,0,1980,0,0,0,1,29189.0);
2085 DOS2DT(0,1,1980,0,0,0,1,29220.0);
2086 DOS2DT(-1,1,1980,18,1,16,1,29251.75087962963);
2087 DOS2DT(1,1,-1,18,1,16,1,53693.75087962963);
2088 DOS2DT(1,-1,1980,18,1,16,0,0);
2089 }
2090
2091 static void test_dt2dos(int line, double dt, INT r, WORD d, WORD m, WORD y,
2092 WORD h, WORD mn, WORD s)
2093 {
2094 unsigned short dosDate, dosTime, expDosDate, expDosTime;
2095 INT res;
2096
2097 dosTime = dosDate = 0;
2098 expDosDate = MKDOSDATE(d,m,y);
2099 expDosTime = MKDOSTIME(h,mn,s);
2100 res = pVariantTimeToDosDateTime(dt, &dosDate, &dosTime);
2101 ok_(__FILE__,line)(r == res && (!r || (dosTime == expDosTime && dosDate == expDosDate)),
2102 "%g: expected %d,%d(%d/%d/%d),%d(%d:%d:%d) got %d,%d(%d/%d/%d),%d(%d:%d:%d)\n",
2103 dt, r, expDosDate, expDosDate & 0x1f,
2104 (expDosDate >> 5) & 0xf, 1980 + (expDosDate >> 9),
2105 expDosTime, expDosTime >> 11, (expDosTime >> 5) & 0x3f,
2106 (expDosTime & 0x1f),
2107 res, dosDate, dosDate & 0x1f, (dosDate >> 5) & 0xf,
2108 1980 + (dosDate >> 9), dosTime, dosTime >> 11,
2109 (dosTime >> 5) & 0x3f, (dosTime & 0x1f));
2110 }
2111 #define DT2DOS(dt,r,d,m,y,h,mn,s) test_dt2dos(__LINE__,dt,r,d,m,y,h,mn,s)
2112
2113 static void test_VariantTimeToDosDateTime(void)
2114 {
2115 CHECKPTR(VariantTimeToDosDateTime);
2116
2117 /* Date */
2118 DT2DOS(29221.0,1,1,1,1980,0,0,0); /* 1/1/1980 */
2119 DT2DOS(73050.0,1,31,12,2099,0,0,0); /* 31/12/2099 */
2120 DT2DOS(29220.0,0,0,0,0,0,0,0); /* 31/12/1979 - out of range */
2121 DT2DOS(73415.0,0,0,0,0,0,0,0); /* 31/12/2100 - out of range */
2122
2123 /* Time */
2124 DT2DOS(29221.00032407407,1,1,1,1980,0,0,29); /* 1/1/1980 12:00:28 AM */
2125 DT2DOS(29221.00034722222,1,1,1,1980,0,0,31); /* 1/1/1980 12:00:30 AM */
2126 DT2DOS(29221.04097222222,1,1,1,1980,0,59,0); /* 1/1/1980 12:59:00 AM */
2127 DT2DOS(29221.95833333333,1,1,1,1980,23,0,0); /* 1/1/1980 11:00:00 PM */
2128 }
2129
2130 static HRESULT (WINAPI *pVarAbs)(LPVARIANT,LPVARIANT);
2131
2132 #define VARABS(vt,val,rvt,rval) \
2133 V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
2134 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
2135 test_var_call1( __LINE__, pVarAbs, &v, &exp )
2136
2137 static void test_VarAbs(void)
2138 {
2139 static WCHAR szNum[] = {'-','1','.','1','\0' };
2140 char buff[8];
2141 HRESULT hres;
2142 VARIANT v, vDst, exp;
2143 size_t i;
2144
2145 CHECKPTR(VarAbs);
2146
2147 /* Test all possible V_VT values.
2148 */
2149 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2150 {
2151 VARTYPE vt;
2152
2153 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2154 {
2155 HRESULT hExpected = DISP_E_BADVARTYPE;
2156
2157 SKIPTESTS(vt);
2158
2159 memset(&v, 0, sizeof(v));
2160 V_VT(&v) = vt | ExtraFlags[i];
2161 V_VT(&vDst) = VT_EMPTY;
2162
2163 hres = pVarAbs(&v,&vDst);
2164 if (ExtraFlags[i] & VT_ARRAY ||
2165 (!ExtraFlags[i] && (vt == VT_UNKNOWN || vt == VT_BSTR ||
2166 vt == VT_DISPATCH || vt == VT_ERROR || vt == VT_RECORD)))
2167 {
2168 hExpected = DISP_E_TYPEMISMATCH;
2169 }
2170 else if (ExtraFlags[i] || vt >= VT_CLSID || vt == VT_VARIANT)
2171 {
2172 hExpected = DISP_E_BADVARTYPE;
2173 }
2174 else if (IsValidVariantClearVT(vt, ExtraFlags[i]))
2175 hExpected = S_OK;
2176
2177 /* Native always fails on some vartypes that should be valid. don't
2178 * check that Wine does the same; these are bugs in native.
2179 */
2180 if (vt == VT_I8 || vt == VT_UI8 || vt == VT_INT || vt == VT_UINT ||
2181 vt == VT_I1 || vt == VT_UI2 || vt == VT_UI4)
2182 continue;
2183 ok(hres == hExpected, "VarAbs: expected 0x%X, got 0x%X for vt %d | 0x%X\n",
2184 hExpected, hres, vt, ExtraFlags[i]);
2185 }
2186 }
2187
2188 /* BOOL->I2, BSTR->R8, all others remain the same */
2189 VARABS(BOOL,VARIANT_TRUE,I2,-VARIANT_TRUE);
2190 VARABS(BOOL,VARIANT_FALSE,I2,VARIANT_FALSE);
2191 VARABS(EMPTY,0,I2,0);
2192 VARABS(EMPTY,1,I2,0);
2193 VARABS(NULL,0,NULL,0);
2194 VARABS(NULL,1,NULL,0);
2195 VARABS(I2,1,I2,1);
2196 VARABS(I2,-1,I2,1);
2197 VARABS(I4,1,I4,1);
2198 VARABS(I4,-1,I4,1);
2199 VARABS(UI1,1,UI1,1);
2200 VARABS(R4,1,R4,1);
2201 VARABS(R4,-1,R4,1);
2202 VARABS(R8,1,R8,1);
2203 VARABS(R8,-1,R8,1);
2204 VARABS(DATE,1,DATE,1);
2205 VARABS(DATE,-1,DATE,1);
2206 V_VT(&v) = VT_CY;
2207 V_CY(&v).int64 = -10000;
2208 memset(&vDst,0,sizeof(vDst));
2209 hres = pVarAbs(&v,&vDst);
2210 ok(hres == S_OK && V_VT(&vDst) == VT_CY && V_CY(&vDst).int64 == 10000,
2211 "VarAbs(CY): expected 0x0 got 0x%X\n", hres);
2212 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buff, sizeof(buff)/sizeof(char));
2213 if (buff[1])
2214 {
2215 trace("Skipping VarAbs(BSTR) as decimal separator is '%s'\n", buff);
2216 return;
2217 } else {
2218 szNum[2] = buff[0];
2219 }
2220 V_VT(&v) = VT_BSTR;
2221 V_BSTR(&v) = (BSTR)szNum;
2222 memset(&vDst,0,sizeof(vDst));
2223 hres = pVarAbs(&v,&vDst);
2224 ok(hres == S_OK && V_VT(&vDst) == VT_R8 && V_R8(&vDst) == 1.1,
2225 "VarAbs: expected 0x0,%d,%g, got 0x%X,%d,%g\n", VT_R8, 1.1, hres, V_VT(&vDst), V_R8(&vDst));
2226 }
2227
2228 static HRESULT (WINAPI *pVarNot)(LPVARIANT,LPVARIANT);
2229
2230 #define VARNOT(vt,val,rvt,rval) \
2231 V_VT(&v) = VT_##vt; V_##vt(&v) = val; \
2232 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
2233 test_var_call1( __LINE__, pVarNot, &v, &exp )
2234
2235 static void test_VarNot(void)
2236 {
2237 static const WCHAR szNum0[] = {'0','\0' };
2238 static const WCHAR szNum1[] = {'1','\0' };
2239 static const WCHAR szFalse[] = { '#','F','A','L','S','E','#','\0' };
2240 static const WCHAR szTrue[] = { '#','T','R','U','E','#','\0' };
2241 HRESULT hres;
2242 VARIANT v, exp, vDst;
2243 DECIMAL *pdec = &V_DECIMAL(&v);
2244 CY *pcy = &V_CY(&v);
2245 size_t i;
2246
2247 CHECKPTR(VarNot);
2248
2249 /* Test all possible V_VT values */
2250 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2251 {
2252 VARTYPE vt;
2253
2254 for (vt = 0; vt <= VT_BSTR_BLOB; vt++)
2255 {
2256 HRESULT hExpected = DISP_E_BADVARTYPE;
2257
2258 SKIPTESTS(vt);
2259
2260 memset(&v, 0, sizeof(v));
2261 V_VT(&v) = vt | ExtraFlags[i];
2262 V_VT(&vDst) = VT_EMPTY;
2263
2264 switch (V_VT(&v))
2265 {
2266 case VT_I1: case VT_UI1: case VT_I2: case VT_UI2:
2267 case VT_INT: case VT_UINT: case VT_I4: case VT_UI4:
2268 case VT_R4: case VT_R8:
2269 case VT_DECIMAL: case VT_BOOL: case VT_NULL: case VT_EMPTY:
2270 case VT_DATE: case VT_CY:
2271 hExpected = S_OK;
2272 break;
2273 case VT_I8: case VT_UI8:
2274 if (has_i8)
2275 hExpected = S_OK;
2276 break;
2277 case VT_RECORD:
2278 hExpected = DISP_E_TYPEMISMATCH;
2279 break;
2280 case VT_UNKNOWN: case VT_BSTR: case VT_DISPATCH: case VT_ERROR:
2281 hExpected = DISP_E_TYPEMISMATCH;
2282 break;
2283 default:
2284 if (IsValidVariantClearVT(vt, ExtraFlags[i]) && vt != VT_CLSID)
2285 hExpected = DISP_E_TYPEMISMATCH;
2286 break;
2287 }
2288
2289 hres = pVarNot(&v,&vDst);
2290 ok(hres == hExpected, "VarNot: expected 0x%X, got 0x%X vt %d|0x%X\n",
2291 hExpected, hres, vt, ExtraFlags[i]);
2292 }
2293 }
2294 /* Test the values returned by all cases that can succeed */
2295 VARNOT(EMPTY,0,I2,-1);
2296 VARNOT(EMPTY,1,I2,-1);
2297 VARNOT(NULL,0,NULL,0);
2298 VARNOT(NULL,1,NULL,0);
2299 VARNOT(BOOL,VARIANT_TRUE,BOOL,VARIANT_FALSE);
2300 VARNOT(BOOL,VARIANT_FALSE,BOOL,VARIANT_TRUE);
2301 VARNOT(I1,-1,I4,0);
2302 VARNOT(I1,0,I4,-1);
2303 VARNOT(I2,-1,I2,0);
2304 VARNOT(I2,0,I2,-1);
2305 VARNOT(I2,1,I2,-2);
2306 VARNOT(I4,1,I4,-2);
2307 VARNOT(I4,0,I4,-1);
2308 VARNOT(UI1,1,UI1,254);
2309 VARNOT(UI1,0,UI1,255);
2310 VARNOT(UI2,0,I4,-1);
2311 VARNOT(UI2,1,I4,-2);
2312 VARNOT(UI4,0,I4,-1);
2313 VARNOT(UI4,1,I4,-2);
2314 VARNOT(INT,0,I4,-1);
2315 VARNOT(INT,1,I4,-2);
2316 VARNOT(UINT,0,I4,-1);
2317 VARNOT(UINT,1,I4,-2);
2318 if (has_i8)
2319 {
2320 VARNOT(I8,1,I8,-2);
2321 VARNOT(I8,0,I8,-1);
2322 VARNOT(UI8,0,I4,-1);
2323 VARNOT(UI8,1,I4,-2);
2324 }
2325 VARNOT(R4,1,I4,-2);
2326 VARNOT(R4,0,I4,-1);
2327 VARNOT(R8,1,I4,-2);
2328 VARNOT(R8,0,I4,-1);
2329 VARNOT(DATE,1,I4,-2);
2330 VARNOT(DATE,0,I4,-1);
2331 VARNOT(BSTR,(BSTR)szNum0,I4,-1);
2332 ok(V_VT(&v) == VT_BSTR && V_BSTR(&v) == szNum0, "VarNot(0): changed input\n");
2333 VARNOT(BSTR,(BSTR)szNum1,I4,-2);
2334 ok(V_VT(&v) == VT_BSTR && V_BSTR(&v) == szNum1, "VarNot(1): changed input\n");
2335 VARNOT(BSTR, (BSTR)szTrue, BOOL, VARIANT_FALSE);
2336 VARNOT(BSTR, (BSTR)szFalse, BOOL, VARIANT_TRUE);
2337
2338 S(U(*pdec)).sign = DECIMAL_NEG;
2339 S(U(*pdec)).scale = 0;
2340 pdec->Hi32 = 0;
2341 S1(U1(*pdec)).Mid32 = 0;
2342 S1(U1(*pdec)).Lo32 = 1;
2343 VARNOT(DECIMAL,*pdec,I4,0);
2344
2345 pcy->int64 = 10000;
2346 VARNOT(CY,*pcy,I4,-2);
2347
2348 pcy->int64 = 0;
2349 VARNOT(CY,*pcy,I4,-1);
2350
2351 pcy->int64 = -1;
2352 VARNOT(CY,*pcy,I4,-1);
2353 }
2354
2355 static HRESULT (WINAPI *pVarSub)(LPVARIANT,LPVARIANT,LPVARIANT);
2356
2357 #define VARSUB(vt1,val1,vt2,val2,rvt,rval) \
2358 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
2359 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
2360 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
2361 test_var_call2( __LINE__, pVarSub, &left, &right, &exp )
2362
2363 static void test_VarSub(void)
2364 {
2365 VARIANT left, right, exp, result, cy, dec;
2366 VARTYPE i;
2367 BSTR lbstr, rbstr;
2368 HRESULT hres, expectedhres;
2369 double r;
2370
2371 CHECKPTR(VarSub);
2372
2373 lbstr = SysAllocString(sz12);
2374 rbstr = SysAllocString(sz12);
2375
2376 VariantInit(&left);
2377 VariantInit(&right);
2378 VariantInit(&result);
2379
2380 /* Test all possible flag/vt combinations & the resulting vt type */
2381 for (i = 0; i < sizeof(ExtraFlags)/sizeof(ExtraFlags[0]); i++)
2382 {
2383
2384 VARTYPE leftvt, rightvt, resvt;
2385
2386 for (leftvt = 0; leftvt <= VT_BSTR_BLOB; leftvt++)
2387 {
2388
2389 SKIPTESTS(leftvt);
2390
2391 for (rightvt = 0; rightvt <= VT_BSTR_BLOB; rightvt++)
2392 {
2393
2394 SKIPTESTS(rightvt);
2395 expectedhres = S_OK;
2396
2397 memset(&left, 0, sizeof(left));
2398 memset(&right, 0, sizeof(right));
2399 V_VT(&left) = leftvt | ExtraFlags[i];
2400 if (leftvt == VT_BSTR)
2401 V_BSTR(&left) = lbstr;
2402 V_VT(&right) = rightvt | ExtraFlags[i];
2403 if (rightvt == VT_BSTR)
2404 V_BSTR(&right) = rbstr;
2405 V_VT(&result) = VT_EMPTY;
2406
2407 /* All extra flags produce errors */
2408 if (ExtraFlags[i] == (VT_VECTOR|VT_BYREF|VT_RESERVED) ||
2409 ExtraFlags[i] == (VT_VECTOR|VT_RESERVED) ||
2410 ExtraFlags[i] == (VT_VECTOR|VT_BYREF) ||
2411 ExtraFlags[i] == (VT_BYREF|VT_RESERVED) ||
2412 ExtraFlags[i] == VT_VECTOR ||
2413 ExtraFlags[i] == VT_BYREF ||
2414 ExtraFlags[i] == VT_RESERVED)
2415 {
2416 expectedhres = DISP_E_BADVARTYPE;
2417 resvt = VT_EMPTY;
2418 }
2419 else if (ExtraFlags[i] >= VT_ARRAY)
2420 {
2421 expectedhres = DISP_E_TYPEMISMATCH;
2422 resvt = VT_EMPTY;
2423 }
2424 /* Native VarSub cannot handle: VT_I1, VT_UI2, VT_UI4,
2425 VT_INT, VT_UINT and VT_UI8. Tested with WinXP */
2426 else if (!IsValidVariantClearVT(leftvt, ExtraFlags[i]) ||
2427 !IsValidVariantClearVT(rightvt, ExtraFlags[i]) ||
2428 leftvt == VT_CLSID || rightvt == VT_CLSID ||
2429 leftvt == VT_VARIANT || rightvt == VT_VARIANT ||
2430 leftvt == VT_I1 || rightvt == VT_I1 ||
2431 leftvt == VT_UI2 || rightvt == VT_UI2 ||
2432 leftvt == VT_UI4 || rightvt == VT_UI4 ||
2433 leftvt == VT_UI8 || rightvt == VT_UI8 ||
2434 leftvt == VT_INT || rightvt == VT_INT ||
2435 leftvt == VT_UINT || rightvt == VT_UINT ||
2436 leftvt == VT_UNKNOWN || rightvt == VT_UNKNOWN ||
2437 leftvt == VT_RECORD || rightvt == VT_RECORD)
2438 {
2439 if (leftvt == VT_RECORD && rightvt == VT_I8)
2440 {
2441 if (has_i8)
2442 expectedhres = DISP_E_TYPEMISMATCH;
2443 else
2444 expectedhres = DISP_E_BADVARTYPE;
2445 }
2446 else if (leftvt < VT_UI1 && rightvt == VT_RECORD)
2447 expectedhres = DISP_E_TYPEMISMATCH;
2448 else if (leftvt >= VT_UI1 && rightvt == VT_RECORD)
2449 expectedhres = DISP_E_TYPEMISMATCH;
2450 else if (leftvt == VT_RECORD && rightvt <= VT_UI1)
2451 expectedhres = DISP_E_TYPEMISMATCH;
2452 else if (leftvt == VT_RECORD && rightvt > VT_UI1)
2453 expectedhres = DISP_E_BADVARTYPE;
2454 else
2455 expectedhres = DISP_E_BADVARTYPE;
2456 resvt = VT_EMPTY;
2457 }
2458 else if ((leftvt == VT_NULL && rightvt == VT_DISPATCH) ||
2459 (leftvt == VT_DISPATCH && rightvt == VT_NULL))
2460 resvt = VT_NULL;
2461 else if (leftvt == VT_DISPATCH || rightvt == VT_DISPATCH ||
2462 leftvt == VT_ERROR || rightvt == VT_ERROR)
2463 {
2464 resvt = VT_EMPTY;
2465 expectedhres = DISP_E_TYPEMISMATCH;
2466 }
2467 else if (leftvt == VT_NULL || rightvt == VT_NULL)
2468 resvt = VT_NULL;
2469 else if ((leftvt == VT_EMPTY && rightvt == VT_BSTR) ||
2470 (leftvt == VT_DATE && rightvt == VT_DATE) ||
2471 (leftvt == VT_BSTR && rightvt == VT_EMPTY) ||
2472 (leftvt == VT_BSTR && rightvt == VT_BSTR))
2473 resvt = VT_R8;
2474 else if (leftvt == VT_DECIMAL || rightvt == VT_DECIMAL)
2475 resvt = VT_DECIMAL;
2476 else if (leftvt == VT_DATE || rightvt == VT_DATE)
2477 resvt = VT_DATE;
2478 else if (leftvt == VT_CY || rightvt == VT_CY)
2479 resvt = VT_CY;
2480 else if (leftvt == VT_R8 || rightvt == VT_R8)
2481 resvt = VT_R8;
2482 else if (leftvt == VT_BSTR || rightvt == VT_BSTR) {
2483 resvt = VT_R8;
2484 } else if (leftvt == VT_R4 || rightvt == VT_R4) {
2485 if (leftvt == VT_I4 || rightvt == VT_I4 ||
2486 leftvt == VT_I8 || rightvt == VT_I8)
2487 resvt = VT_R8;
2488 else
2489 resvt = VT_R4;
2490 }
2491 else if (leftvt == VT_I8 || rightvt == VT_I8)
2492 resvt = VT_I8;
2493 else if (leftvt == VT_I4 || rightvt == VT_I4)
2494 resvt = VT_I4;
2495 else if (leftvt == VT_I2 || rightvt == VT_I2 ||
2496 leftvt == VT_BOOL || rightvt == VT_BOOL ||
2497 (leftvt == VT_EMPTY && rightvt == VT_EMPTY))
2498 resvt = VT_I2;
2499 else if (leftvt == VT_UI1 || rightvt == VT_UI1)
2500 resvt = VT_UI1;
2501 else
2502 {
2503 resvt = VT_EMPTY;
2504 expectedhres = DISP_E_TYPEMISMATCH;
2505 }
2506
2507 hres = pVarSub(&left, &right, &result);
2508
2509 ok(hres == expectedhres && V_VT(&result) == resvt,
2510 "VarSub: %d|0x%X, %d|0x%X: Expected failure 0x%X, "
2511 "got 0x%X, expected vt %d got vt %d\n",
2512 leftvt, ExtraFlags[i], rightvt, ExtraFlags[i],
2513 expectedhres, hres, resvt, V_VT(&result));
2514 }
2515 }
2516 }
2517
2518 /* Test returned values */
2519 VARSUB(I4,4,I4,2,I4,2);
2520 VARSUB(I2,4,I2,2,I2,2);
2521 VARSUB(I2,-13,I4,5,I4,-18);
2522 VARSUB(I4,-13,I4,5,I4,-18);
2523 VARSUB(I2,7,R4,0.5f,R4,6.5f);
2524 VARSUB(R4,0.5f,I4,5,R8,-4.5);
2525 VARSUB(R8,7.1,BOOL,0,R8,7.1);
2526 VARSUB(BSTR,lbstr,I2,4,R8,8);
2527 VARSUB(BSTR,lbstr,BOOL,1,R8,11);
2528 VARSUB(BSTR,lbstr,R4,0.1f,R8,11.9);
2529 VARSUB(R4,0.2f,BSTR,rbstr,R8,-11.8);
2530 VARSUB(DATE,2.25,I4,7,DATE,-4.75);
2531 VARSUB(DATE,1.25,R4,-1.7f,DATE,2.95);
2532
2533 VARSUB(UI1, UI1_MAX, UI1, UI1_MAX, UI1, 0);
2534 VARSUB(I2, I2_MAX, I2, I2_MAX, I2, 0);
2535 VARSUB(I2, I2_MIN, I2, I2_MIN, I2, 0);
2536 VARSUB(I4, I4_MAX, I4, I4_MAX, I4, 0);
2537 VARSUB(I4, I4_MIN, I4, I4_MIN, I4, 0);
2538 VARSUB(R4, R4_MAX, R4, R4_MAX, R4, 0.0f);
2539 VARSUB(R4, R4_MAX, R4, R4_MIN, R4, R4_MAX - R4_MIN);
2540 VARSUB(R4, R4_MIN, R4, R4_MIN, R4, 0.0f);
2541 VARSUB(R8, R8_MAX, R8, R8_MIN, R8, R8_MAX - R8_MIN);
2542 VARSUB(R8, R8_MIN, R8, R8_MIN, R8, 0.0);
2543
2544 /* Manually test BSTR + BSTR */
2545 V_VT(&left) = VT_BSTR;
2546 V_BSTR(&left) = lbstr;
2547 V_VT(&right) = VT_BSTR;
2548 V_BSTR(&right) = rbstr;
2549 hres = pVarSub(&left, &right, &result);
2550 ok(hres == S_OK && V_VT(&result) == VT_R8,
2551 "VarSub: expected coerced type VT_R8, got %s!\n", vtstr(V_VT(&result)));
2552 ok(hres == S_OK && EQ_DOUBLE(V_R8(&result), 0.0),
2553 "VarSub: BSTR + BSTR, expected %f got %f\n", 0.0, V_R8(&result));
2554
2555 /* Manually test some VT_CY and VT_DECIMAL variants */
2556 V_VT(&cy) = VT_CY;
2557 hres = VarCyFromI4(4711, &V_CY(&cy));
2558 ok(hres == S_OK, "VarCyFromI4 failed!\n");
2559 V_VT(&dec) = VT_DECIMAL;
2560 hres = VarDecFromR8(-4.2, &V_DECIMAL(&dec));
2561 ok(hres == S_OK, "VarDecFromR4 failed!\n");
2562 memset(&left, 0, sizeof(left));
2563 memset(&right, 0, sizeof(right));
2564 V_VT(&left) = VT_I4;
2565 V_I4(&left) = -11;
2566 V_VT(&right) = VT_UI1;
2567 V_UI1(&right) = 9;
2568
2569 hres = pVarSub(&cy, &right, &result);
2570 ok(hres == S_OK && V_VT(&result) == VT_CY,
2571 "VarSub: expected coerced type VT_CY, got %s!\n", vtstr(V_VT(&result)));
2572 hres = VarR8FromCy(V_CY(&result), &r);
2573 ok(hres == S_OK && EQ_DOUBLE(r, 4702.0),
2574 "VarSub: CY value %f, expected %f\n", r, (double)4720);
2575
2576 hres = pVarSub(&left, &dec, &result);
2577 ok(hres == S_OK && V_VT(&result) == VT_DECIMAL,
2578 "VarSub: expected coerced type VT_DECIMAL, got %s!\n", vtstr(V_VT(&result)));
2579 hres = VarR8FromDec(&V_DECIMAL(&result), &r);
2580 ok(hres == S_OK && EQ_DOUBLE(r, -6.8),
2581 "VarSub: DECIMAL value %f, expected %f\n", r, (double)-15.2);
2582
2583 SysFreeString(lbstr);
2584 SysFreeString(rbstr);
2585 }
2586
2587 static HRESULT (WINAPI *pVarMod)(LPVARIANT,LPVARIANT,LPVARIANT);
2588
2589 static void test_Mod( int line, VARIANT *left, VARIANT *right, VARIANT *expected, HRESULT expres )
2590 {
2591 VARIANT result;
2592 HRESULT hres;
2593
2594 memset( &result, 0, sizeof(result) );
2595 hres = pVarMod( left, right, &result );
2596 ok_(__FILE__,line)( hres == expres, "wrong result %x/%x\n", hres, expres );
2597 if (hres == S_OK)
2598 ok_(__FILE__,line)( is_expected_variant( &result, expected ),
2599 "got %s expected %s\n", variantstr(&result), variantstr(expected) );
2600 }
2601
2602 #define VARMOD(vt1,vt2,val1,val2,rvt,rval) \
2603 V_VT(&left) = VT_##vt1; V_##vt1(&left) = val1; \
2604 V_VT(&right) = VT_##vt2; V_##vt2(&right) = val2; \
2605 V_VT(&exp) = VT_##rvt; V_##rvt(&exp) = rval; \
2606 test_var_call2( __LINE__, pVarMod, &left, &right, &exp )
2607
2608 #define VARMOD2(vt1,vt2,val1,val2,rvt,rval,hexpected) \
2609 V_VT(&left) = VT_##vt1; V_I4(&left) = val1; \
2610 V_VT(&right) = VT_##vt2; V_I4(&right) = val2; \
2611 V_VT(&exp) = VT_##rvt; V_I4(&exp) = rval; \
2612 test_Mod( __LINE__, &left, &right, &exp, hexpected )
2613
2614 static void test_VarMod(void)
2615 {
2616 VARIANT v1, v2, vDst, left, right, exp;
2617 HRESULT hres;
2618 HRESULT hexpected = 0;
2619 static const WCHAR szNum0[] = {'1','2','5','\0'};
2620 static const WCHAR szNum1[] = {'1','0','\0'};
2621 int l, r;
2622 BOOL lFound, rFound;
2623 BOOL lValid;
2624 BSTR strNum0, strNum1;
2625
2626 CHECKPTR(VarMod);
2627
2628 VARMOD(I1,BOOL,100,10,I4,0);
2629 VARMOD(I1,I1,100,10,I4,0);
2630 VARMOD(I1,UI1,100,10,I4,0);
2631 VARMOD(I1,I2,100,10,I4,0);
2632 VARMOD(I1,UI2,100,10,I4,0);
2633 VARMOD(I1,I4,100,10,I4,0);
2634 VARMOD(I1,UI4,100,10,I4,0);
2635 VARMOD(I1,R4,100,10,I4,0);
2636 VARMOD(I1,R8,100,10,I4,0);
2637
2638 VARMOD(UI1,BOOL,100,10,I2,0);
2639 VARMOD(UI1,I1,100,10,I4,0);
2640 VARMOD(UI1,UI1,100,10,UI1,0);
2641 VARMOD(UI1,I2,100,10,I2,0);
2642 VARMOD(UI1,UI2,100,10,I4,0);
2643 VARMOD(UI1,I4,100,10,I4,0);
2644 VARMOD(UI1,UI4,100,10,I4,0);
2645 VARMOD(UI1,R4,100,10,I4,0);
2646 VARMOD(UI1,R8,100,10,I4,0);
2647
2648 VARMOD(I2,BOOL,100,10,I2,0);
2649 VARMOD(I2,I1,100,10,I4,0);
2650 VARMOD(I2,UI1,100,10,I2,0);
2651 VARMOD(I2,I2,100,10,I2,0);
2652 VARMOD(I2,UI2,100,10,I4,0);
2653 VARMOD(I2,I4,100,10,I4,0);
2654 VARMOD(I2,UI4,100,10,I4,0);
2655 VARMOD(I2,R4,100,10,I4,0);
2656 VARMOD(I2,R8,100,10,I4,0);
2657
2658 VARMOD(I4,BOOL,100,10,I4,0);
2659 VARMOD(I4,I1,100,10,I4,0);
2660 VARMOD(I4,UI1,100,10,I4,0);
2661 VARMOD(I4,I2,100,10,I4,0);
2662 VARMOD(I4,UI2,100,10,I4,0);
2663 VARMOD(I4,I4,100,10,I4,0);
2664 VARMOD(I4,UI4,100,10,I4,0);
2665 VARMOD(I4,R4,100,10,I4,0);
2666 VARMOD(I4,R8,100,10,I4,0);
2667 VARMOD(UI4,BOOL,100,10,I4,0);
2668 VARMOD(UI4,I1,100,10,I4,0);
2669 VARMOD(UI4,UI1,100,10,I4,0);
2670 VARMOD(UI4,I2,100,10,I4,0);
2671 VARMOD(UI4,UI2,100,10,I4,0);
2672 VARMOD(UI4,I4,100,10,I4,0);
2673 VARMOD(UI4,UI4,100,10,I4,0);
2674 VARMOD(UI4,R4,100,10,I4,0);
2675 VARMOD(UI4,R8,100,10,I4,0);
2676 VARMOD(R4,BOOL,100,10,I4,0);
2677 VARMOD(R4,I1,100,10,I4,0);
2678 VARMOD(R4,UI1,100,10,I4,0);
2679 VARMOD(R4,I2,100,10,I4,0);
2680 VARMOD(R4,UI2,100,10,I4,0);
2681 VARMOD(R4,I4,100,10,I4,0);
2682 VARMOD(R4,UI4,100,10,I4,0);
2683 VARMOD(R4,R4,100,10,I4,0);
2684 VARMOD(R4,R8,100,10,I4,0);
2685 VARMOD(R8,BOOL,100,10,I4,0);
2686 VARMOD(R8,I1,100,10,I4,0);
2687 VARMOD(R8,UI1,100,10,I4,0);
2688 VARMOD(R8,I2,100,10,I4,0);
2689 VARMOD(R8,UI2,100,10,I4,0);
2690 VARMOD(R8,I4,100,10,I4,0);
2691 VARMOD(R8,UI4,100,10,I4,0);
2692 VARMOD(R8,R4,100,10,I4,0);
2693 VARMOD(R8,R8,100,10,I4,0);
2694
2695 VARMOD(INT,INT,100,10,I4,0);
2696 VARMOD(INT,UINT,100,10,I4,0);
2697
2698 VARMOD(BOOL,BOOL,100,10,I2,0);
2699 VARMOD(BOOL,I1,100,10,I4,0);
2700 VARMOD(BOOL,UI1,100,10,I2,0);
2701 VARMOD(BOOL,I2,100,10,I2,0);
2702 VARMOD(BOOL,UI2,100,10,I4,0);
2703 VARMOD(BOOL,I4,100,10,I4,0);
2704 VARMOD(BOOL,UI4,100,10,I4,0);
2705 VARMOD(BOOL,R4,100,10,I4,0);
2706 VARMOD(BOOL,R8,100,10,I4,0);
2707 VARMOD(BOOL,DATE,100,10,I4,0);
2708
2709 VARMOD(DATE,BOOL,100,10,I4,0);
2710 VARMOD(DATE,I1,100,10,I4,0);
2711 VARMOD(DATE,UI1,100,10,I4,0);
2712 VARMOD(DATE,I2,100,10,I4,0);
2713 VARMOD(DATE,UI2,100,10,I4,0);
2714 VARMOD(DATE,I4,100,10,I4,0);
2715 VARMOD(DATE,UI4,100,10,I4,0);
2716 VARMOD(DATE,R4,100,10,I4,0);
2717 VARMOD(DATE,R8,100,10,I4,0);
2718 VARMOD(DATE,DATE,100,10,I4,0);
2719
2720 strNum0 = SysAllocString(szNum0);
2721 strNum1 = SysAllocString(szNum1);
2722 VARMOD(BSTR,BSTR,strNum0,strNum1,I4,5);
2723 VARMOD(BSTR,I1,strNum0,10,I4,5);
2724 VARMOD(BSTR,I2,strNum0,10,I4,5);
2725 VARMOD(BSTR,I4,strNum0,10,I4,5);
2726 VARMOD(BSTR,R4,strNum0,10,I4,5);
2727 VARMOD(BSTR,R8,strNum0,10,I4,5);
2728 VARMOD(I4,BSTR,125,strNum1,I4,5);
2729
2730 if (has_i8)
2731 {
2732 VARMOD(BOOL,I8,100,10,I8,0);
2733 VARMOD(I1,I8,100,10,I8,0);
2734 VARMOD(UI1,I8,100,10,I8,0);
2735 VARMOD(I2,I8,100,10,I8,0);
2736 VARMOD(I4,I8,100,10,I8,0);
2737 VARMOD(UI4,I8,100,10,I8,0);
2738 VARMOD(R4,I8,100,10,I8,0);
2739 VARMOD(R8,I8,100,10,I8,0);
2740 VARMOD(DATE,I8,100,10,I8,0);
2741
2742 VARMOD(I8,BOOL,100,10,I8,0);
2743 VARMOD(I8,I1,100,10,I8,0);
2744 VARMOD(I8,UI1,100,10,I8,0);
2745 VARMOD(I8,I2,100,10,I8,0);
2746 VARMOD(I8,UI2,100,10,I8,0);
2747 VARMOD(I8,I4,100,10,I8,0);
2748 VARMOD(I8,UI4,100,10,I8,0);
2749 VARMOD(I8,R4,100,10,I8,0);
2750 VARMOD(I8,R8,100,10,I8,0);
2751 VARMOD(I8,I8,100,10,I8,0);
2752
2753 VARMOD(BSTR,I8,strNum0,10,I8,5);
2754 }
2755
2756 /* test all combinations of types */
2757 for(l = 0; l < VT_BSTR_BLOB; l++)
2758 {
2759 SKIPTESTS(l);
2760
2761 for(r = 0; r < VT_BSTR_BLOB; r++)
2762 {
2763 SKIPTESTS(r);
2764
2765 if(l == VT_BSTR) continue;
2766 if(l == VT_DISPATCH) continue;
2767 if(r == VT_BSTR) continue;
2768 if(r == VT_DISPATCH) continue;
2769
2770 lFound = TRUE;
2771 lValid = TRUE;
2772 switch(l)
2773 {
2774 case VT_EMPTY:
2775 case VT_NULL:
2776 case VT_I1:
2777 case VT_UI1:
2778 case VT_I2:
2779 case VT_UI2:
2780 case VT_I4:
2781 case VT_I8:
2782 case VT_UI4:
2783 case VT_UI8:
2784 case VT_INT:
2785 case VT_UINT:
2786 case VT_R4:
2787 case VT_R8:
2788 case VT_BOOL:
2789 case VT_DATE:
2790 case VT_CY:
2791 case VT_DECIMAL:
2792 hexpected = S_OK;
2793 break;
2794 case VT_ERROR:
2795 case VT_VARIANT:
2796 case VT_UNKNOWN:
2797 case VT_RECORD:
2798 lValid = FALSE;
2799 break;
2800 default:
2801 lFound = FALSE;
2802 hexpected = DISP_E_BADVARTYPE;
2803 break;
2804 }
2805
2806 rFound = TRUE;
2807 switch(r)
2808 {
2809 case VT_EMPTY:
2810 case VT_NULL:
2811 case VT_I1:
2812 case VT_UI1:
2813 case VT_I2:
2814 case VT_UI2:
2815 case VT_I4:
2816 case VT_I8:
2817 case VT_UI4:
2818 case VT_UI8:
2819 case VT_INT:
2820 case VT_UINT:
2821 case VT_R4:
2822 case VT_R8:
2823 case VT_BOOL:
2824 case VT_DATE:
2825 case VT_DECIMAL:
2826 case VT_CY:
2827 hexpected = S_OK;
2828 break;
2829 case VT_ERROR:
2830 case VT_VARIANT:
2831 case VT_UNKNOWN:
2832 case VT_RECORD:
2833 break;
2834 default:
2835 rFound = FALSE;
2836 break;
2837 }
2838
2839 if(((l == VT_I8) && (r == VT_INT)) || ((l == VT_INT) && (r == VT_I8)))
2840 {
2841 hexpected = DISP_E_TYPEMISMATCH;
2842 } else if((l == VT_EMPTY) && (r == VT_NULL))
2843 {
2844 hexpected = S_OK;
2845 } else if((l == VT_NULL) && (r == VT_EMPTY))
2846 {
2847 hexpected = S_OK;
2848 } else if((l == VT_EMPTY) && (r == VT_CY))
2849 {
2850 hexpected = S_OK;
2851 } else if((l == VT_EMPTY) && (r == VT_RECORD))
2852 {
2853 hexpected = DISP_E_TYPEMISMATCH;
2854 } else if((r == VT_EMPTY) && lFound && lValid)
2855 {
2856 hexpected = DISP_E_DIVBYZERO;
2857 } else if((l == VT_ERROR) || ((r == VT_ERROR) && lFound && lValid))
2858 {
2859 hexpected = DISP_E_TYPEMISMATCH;
2860 } else if((l == VT_NULL) && (r == VT_NULL))
2861 {
2862 hexpected = S_OK;
2863 } else if((l == VT_VARIANT) || ((r == VT_VARIANT) && lFound && lValid))
2864 {
2865 hexpected = DISP_E_TYPEMISMATCH;
2866 } else if((l == VT_NULL) && (r == VT_RECORD))
2867 {
2868 hexpected = DISP_E_TYPEMISMATCH;
2869 } else if((l == VT_I8) && (r == VT_DECIMAL))
2870 {
2871 hexpected = S_OK;
2872 } else if((l == VT_DECIMAL) && (r == VT_I8))
2873 {
2874 hexpected = S_OK;
2875 } else if((l == VT_UNKNOWN) || ((r == VT_UNKNOWN) && lFound && lValid))
2876 {
2877 hexpected = DISP_E_TYPEMISMATCH;
2878 } else if((l == VT_NULL) && rFound)
2879 {
2880 hexpected = S_OK;
2881 } else if(l == VT_RECORD)
2882 {
2883 hexpected = DISP_E_TYPEMISMATCH;
2884 } else if((r == VT_RECORD) && lValid && lFound)
2885 {
2886 hexpected = DISP_E_TYPEMISMATCH;
2887 } else if((l == VT_EMPTY) && (r == VT_EMPTY))
2888 {
2889 hexpected = DISP_E_DIVBYZERO;
2890<