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