Release 0.9.39.
[wine/gsoc-2012-control.git] / dlls / oleaut32 / tests / usrmarshal.c
bloba168d8fab386c3b8ce11b9ee691c59422f24f989
1 /*
2 * Marshaling Tests
4 * Copyright 2004 Robert Shearman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "objbase.h"
28 #include "propidl.h" /* for LPSAFEARRAY_User* routines */
30 #include "wine/test.h"
32 #if (__STDC__ && !defined(_FORCENAMELESSUNION)) || defined(NONAMELESSUNION)
33 # define V_U2(A) ((A)->n1.n2)
34 #else
35 # define V_U2(A) (*(A))
36 #endif
38 /* doesn't work on Windows due to needing more of the
39 * MIDL_STUB_MESSAGE structure to be filled out */
40 #define LPSAFEARRAY_UNMARSHAL_WORKS 0
41 #define BSTR_UNMARSHAL_WORKS 0
42 #define VARIANT_UNMARSHAL_WORKS 1
44 static inline SF_TYPE get_union_type(SAFEARRAY *psa)
46 VARTYPE vt;
47 HRESULT hr;
49 hr = SafeArrayGetVartype(psa, &vt);
50 if (FAILED(hr))
52 switch(psa->cbElements)
54 case 1: vt = VT_I1; break;
55 case 2: vt = VT_I2; break;
56 case 4: vt = VT_I4; break;
57 case 8: vt = VT_I8; break;
58 default: return 0;
62 if (psa->fFeatures & FADF_HAVEIID)
63 return SF_HAVEIID;
65 switch (vt)
67 case VT_I1:
68 case VT_UI1: return SF_I1;
69 case VT_BOOL:
70 case VT_I2:
71 case VT_UI2: return SF_I2;
72 case VT_INT:
73 case VT_UINT:
74 case VT_I4:
75 case VT_UI4:
76 case VT_R4: return SF_I4;
77 case VT_DATE:
78 case VT_CY:
79 case VT_R8:
80 case VT_I8:
81 case VT_UI8: return SF_I8;
82 case VT_INT_PTR:
83 case VT_UINT_PTR: return (sizeof(UINT_PTR) == 4 ? SF_I4 : SF_I8);
84 case VT_BSTR: return SF_BSTR;
85 case VT_DISPATCH: return SF_DISPATCH;
86 case VT_VARIANT: return SF_VARIANT;
87 case VT_UNKNOWN: return SF_UNKNOWN;
88 /* Note: Return a non-zero size to indicate vt is valid. The actual size
89 * of a UDT is taken from the result of IRecordInfo_GetSize().
91 case VT_RECORD: return SF_RECORD;
92 default: return SF_ERROR;
96 static ULONG get_cell_count(const SAFEARRAY *psa)
98 const SAFEARRAYBOUND* psab = psa->rgsabound;
99 USHORT cCount = psa->cDims;
100 ULONG ulNumCells = 1;
102 while (cCount--)
104 if (!psab->cElements)
105 return 0;
106 ulNumCells *= psab->cElements;
107 psab++;
109 return ulNumCells;
112 static void check_safearray(void *buffer, LPSAFEARRAY lpsa)
114 unsigned char *wiresa = buffer;
115 VARTYPE vt;
116 SF_TYPE sftype;
117 ULONG cell_count;
119 if(!lpsa)
121 ok(*(void **)wiresa == NULL, "wiresa + 0x0 should be NULL instead of 0x%08x\n", *(DWORD *)wiresa);
122 return;
125 if(FAILED(SafeArrayGetVartype(lpsa, &vt)))
126 vt = 0;
128 sftype = get_union_type(lpsa);
129 cell_count = get_cell_count(lpsa);
131 ok(*(DWORD *)wiresa, "wiresa + 0x0 should be non-NULL instead of 0x%08x\n", *(DWORD *)wiresa); /* win2k: this is lpsa. winxp: this is 0x00000001 */
132 wiresa += sizeof(DWORD);
133 ok(*(DWORD *)wiresa == lpsa->cDims, "wiresa + 0x4 should be lpsa->cDims instead of 0x%08x\n", *(DWORD *)wiresa);
134 wiresa += sizeof(DWORD);
135 ok(*(WORD *)wiresa == lpsa->cDims, "wiresa + 0x8 should be lpsa->cDims instead of 0x%04x\n", *(WORD *)wiresa);
136 wiresa += sizeof(WORD);
137 ok(*(WORD *)wiresa == lpsa->fFeatures, "wiresa + 0xc should be lpsa->fFeatures instead of 0x%08x\n", *(WORD *)wiresa);
138 wiresa += sizeof(WORD);
139 ok(*(DWORD *)wiresa == lpsa->cbElements, "wiresa + 0x10 should be lpsa->cbElements instead of 0x%08x\n", *(DWORD *)wiresa);
140 wiresa += sizeof(DWORD);
141 ok(*(WORD *)wiresa == lpsa->cLocks, "wiresa + 0x16 should be lpsa->cLocks instead of 0x%04x\n", *(WORD *)wiresa);
142 wiresa += sizeof(WORD);
143 ok(*(WORD *)wiresa == vt, "wiresa + 0x14 should be %04x instead of 0x%04x\n", vt, *(WORD *)wiresa);
144 wiresa += sizeof(WORD);
145 ok(*(DWORD *)wiresa == sftype, "wiresa + 0x18 should be %08x instead of 0x%08x\n", (DWORD)sftype, *(DWORD *)wiresa);
146 wiresa += sizeof(DWORD);
147 ok(*(DWORD *)wiresa == cell_count, "wiresa + 0x1c should be %u instead of %u\n", cell_count, *(DWORD *)wiresa);
148 wiresa += sizeof(DWORD);
149 ok(*(DWORD_PTR *)wiresa == (DWORD_PTR)lpsa->pvData, "wiresa + 0x20 should be lpsa->pvData instead of 0x%08lx\n", *(DWORD_PTR *)wiresa);
150 wiresa += sizeof(DWORD_PTR);
151 if(sftype == SF_HAVEIID)
153 GUID guid;
154 SafeArrayGetIID(lpsa, &guid);
155 ok(IsEqualGUID(&guid, (GUID*)wiresa), "guid mismatch\n");
156 wiresa += sizeof(GUID);
158 ok(!memcmp(wiresa, lpsa->rgsabound, sizeof(lpsa->rgsabound[0]) * lpsa->cDims), "bounds mismatch\n");
159 wiresa += sizeof(lpsa->rgsabound[0]) * lpsa->cDims;
161 ok(*(DWORD *)wiresa == cell_count, "wiresa + 0x2c should be %u instead of %u\n", cell_count, *(DWORD*)wiresa);
162 wiresa += sizeof(DWORD);
163 /* elements are now pointed to by wiresa */
166 static void test_marshal_LPSAFEARRAY(void)
168 unsigned char *buffer;
169 unsigned long size;
170 LPSAFEARRAY lpsa;
171 LPSAFEARRAY lpsa2 = NULL;
172 SAFEARRAYBOUND sab;
173 MIDL_STUB_MESSAGE stubMsg = { 0 };
174 USER_MARSHAL_CB umcb = { 0 };
175 HRESULT hr;
176 VARTYPE vt;
178 umcb.Flags = MAKELONG(MSHCTX_DIFFERENTMACHINE, NDR_LOCAL_DATA_REPRESENTATION);
179 umcb.pReserve = NULL;
180 umcb.pStubMsg = &stubMsg;
182 sab.lLbound = 5;
183 sab.cElements = 10;
185 lpsa = SafeArrayCreate(VT_I2, 1, &sab);
186 *(DWORD *)lpsa->pvData = 0xcafebabe;
188 lpsa->cLocks = 7;
189 size = LPSAFEARRAY_UserSize(&umcb.Flags, 1, &lpsa);
190 ok(size == 68, "size should be 68 bytes, not %ld\n", size);
191 size = LPSAFEARRAY_UserSize(&umcb.Flags, 0, &lpsa);
192 ok(size == 64, "size should be 64 bytes, not %ld\n", size);
193 buffer = (unsigned char *)HeapAlloc(GetProcessHeap(), 0, size);
194 LPSAFEARRAY_UserMarshal(&umcb.Flags, buffer, &lpsa);
196 check_safearray(buffer, lpsa);
198 if (LPSAFEARRAY_UNMARSHAL_WORKS)
200 VARTYPE vt, vt2;
201 LPSAFEARRAY_UserUnmarshal(&umcb.Flags, buffer, &lpsa2);
202 ok(lpsa2 != NULL, "LPSAFEARRAY didn't unmarshal\n");
203 SafeArrayGetVartype(lpsa, &vt);
204 SafeArrayGetVartype(lpsa2, &vt2);
205 ok(vt == vt2, "vts differ %x %x\n", vt, vt2);
206 LPSAFEARRAY_UserFree(&umcb.Flags, &lpsa2);
208 HeapFree(GetProcessHeap(), 0, buffer);
209 SafeArrayDestroy(lpsa);
211 /* test NULL safe array */
212 lpsa = NULL;
214 size = LPSAFEARRAY_UserSize(&umcb.Flags, 0, &lpsa);
215 ok(size == 4, "size should be 4 bytes, not %ld\n", size);
216 buffer = (unsigned char *)HeapAlloc(GetProcessHeap(), 0, size);
217 LPSAFEARRAY_UserMarshal(&umcb.Flags, buffer, &lpsa);
218 check_safearray(buffer, lpsa);
220 if (LPSAFEARRAY_UNMARSHAL_WORKS)
222 LPSAFEARRAY_UserUnmarshal(&umcb.Flags, buffer, &lpsa2);
223 ok(lpsa2 == NULL, "NULL LPSAFEARRAY didn't unmarshal\n");
224 LPSAFEARRAY_UserFree(&umcb.Flags, &lpsa2);
226 HeapFree(GetProcessHeap(), 0, buffer);
228 sab.lLbound = 5;
229 sab.cElements = 10;
231 lpsa = SafeArrayCreate(VT_R8, 1, &sab);
232 *(double *)lpsa->pvData = 3.1415;
234 lpsa->cLocks = 7;
235 size = LPSAFEARRAY_UserSize(&umcb.Flags, 1, &lpsa);
236 ok(size == 128, "size should be 128 bytes, not %ld\n", size);
237 size = LPSAFEARRAY_UserSize(&umcb.Flags, 0, &lpsa);
238 ok(size == 128, "size should be 128 bytes, not %ld\n", size);
239 buffer = (unsigned char *)HeapAlloc(GetProcessHeap(), 0, size);
240 LPSAFEARRAY_UserMarshal(&umcb.Flags, buffer, &lpsa);
242 check_safearray(buffer, lpsa);
244 HeapFree(GetProcessHeap(), 0, buffer);
245 SafeArrayDestroy(lpsa);
247 /* VARTYPE-less arrays can be marshaled if cbElements is 1,2,4 or 8 as type SF_In */
248 hr = SafeArrayAllocDescriptor(1, &lpsa);
249 ok(hr == S_OK, "saad failed %08x\n", hr);
250 lpsa->cbElements = 8;
251 lpsa->rgsabound[0].lLbound = 2;
252 lpsa->rgsabound[0].cElements = 48;
253 hr = SafeArrayAllocData(lpsa);
254 ok(hr == S_OK, "saad failed %08x\n", hr);
256 hr = SafeArrayGetVartype(lpsa, &vt);
257 ok(hr == E_INVALIDARG, "ret %08x\n", hr);
259 size = LPSAFEARRAY_UserSize(&umcb.Flags, 0, &lpsa);
260 ok(size == 432, "size %ld\n", size);
261 buffer = (unsigned char *)HeapAlloc(GetProcessHeap(), 0, size);
262 LPSAFEARRAY_UserMarshal(&umcb.Flags, buffer, &lpsa);
263 check_safearray(buffer, lpsa);
264 HeapFree(GetProcessHeap(), 0, buffer);
265 SafeArrayDestroyData(lpsa);
266 SafeArrayDestroyDescriptor(lpsa);
269 static void check_bstr(void *buffer, BSTR b)
271 DWORD *wireb = buffer;
272 DWORD len = SysStringByteLen(b);
274 ok(*wireb == (len + 1) / 2, "wv[0] %08x\n", *wireb);
275 wireb++;
276 if(b)
277 ok(*wireb == len, "wv[1] %08x\n", *wireb);
278 else
279 ok(*wireb == 0xffffffff, "wv[1] %08x\n", *wireb);
280 wireb++;
281 ok(*wireb == (len + 1) / 2, "wv[2] %08x\n", *wireb);
282 if(len)
284 wireb++;
285 ok(!memcmp(wireb, b, (len + 1) & ~1), "strings differ\n");
287 return;
290 static void test_marshal_BSTR(void)
292 unsigned long size;
293 MIDL_STUB_MESSAGE stubMsg = { 0 };
294 USER_MARSHAL_CB umcb = { 0 };
295 unsigned char *buffer, *next;
296 BSTR b, b2;
297 WCHAR str[] = {'m','a','r','s','h','a','l',' ','t','e','s','t','1',0};
298 DWORD len;
300 umcb.Flags = MAKELONG(MSHCTX_DIFFERENTMACHINE, NDR_LOCAL_DATA_REPRESENTATION);
301 umcb.pReserve = NULL;
302 umcb.pStubMsg = &stubMsg;
304 b = SysAllocString(str);
305 len = SysStringLen(b);
306 ok(len == 13, "get %d\n", len);
308 /* BSTRs are DWORD aligned */
309 size = BSTR_UserSize(&umcb.Flags, 1, &b);
310 ok(size == 42, "size %ld\n", size);
312 size = BSTR_UserSize(&umcb.Flags, 0, &b);
313 ok(size == 38, "size %ld\n", size);
315 buffer = HeapAlloc(GetProcessHeap(), 0, size);
316 next = BSTR_UserMarshal(&umcb.Flags, buffer, &b);
317 ok(next == buffer + size, "got %p expect %p\n", next, buffer + size);
318 check_bstr(buffer, b);
320 if (BSTR_UNMARSHAL_WORKS)
322 b2 = NULL;
323 next = BSTR_UserUnmarshal(&umcb.Flags, buffer, &b2);
324 ok(next == buffer + size, "got %p expect %p\n", next, buffer + size);
325 ok(b2 != NULL, "BSTR didn't unmarshal\n");
326 ok(!memcmp(b, b2, (len + 1) * 2), "strings differ\n");
327 BSTR_UserFree(&umcb.Flags, &b2);
330 HeapFree(GetProcessHeap(), 0, buffer);
331 SysFreeString(b);
333 b = NULL;
334 size = BSTR_UserSize(&umcb.Flags, 0, &b);
335 ok(size == 12, "size %ld\n", size);
337 buffer = HeapAlloc(GetProcessHeap(), 0, size);
338 next = BSTR_UserMarshal(&umcb.Flags, buffer, &b);
339 ok(next == buffer + size, "got %p expect %p\n", next, buffer + size);
341 check_bstr(buffer, b);
342 if (BSTR_UNMARSHAL_WORKS)
344 b2 = NULL;
345 next = BSTR_UserUnmarshal(&umcb.Flags, buffer, &b2);
346 ok(next == buffer + size, "got %p expect %p\n", next, buffer + size);
347 ok(b2 == NULL, "NULL BSTR didn't unmarshal\n");
348 BSTR_UserFree(&umcb.Flags, &b2);
350 HeapFree(GetProcessHeap(), 0, buffer);
352 b = SysAllocStringByteLen("abc", 3);
353 *(((char*)b) + 3) = 'd';
354 len = SysStringLen(b);
355 ok(len == 1, "get %d\n", len);
356 len = SysStringByteLen(b);
357 ok(len == 3, "get %d\n", len);
359 size = BSTR_UserSize(&umcb.Flags, 0, &b);
360 ok(size == 16, "size %ld\n", size);
362 buffer = HeapAlloc(GetProcessHeap(), 0, size);
363 memset(buffer, 0xcc, size);
364 next = BSTR_UserMarshal(&umcb.Flags, buffer, &b);
365 ok(next == buffer + size, "got %p expect %p\n", next, buffer + size);
366 check_bstr(buffer, b);
367 ok(buffer[15] == 'd', "buffer[15] %02x\n", buffer[15]);
369 if (BSTR_UNMARSHAL_WORKS)
371 b2 = NULL;
372 next = BSTR_UserUnmarshal(&umcb.Flags, buffer, &b2);
373 ok(next == buffer + size, "got %p expect %p\n", next, buffer + size);
374 ok(b2 != NULL, "BSTR didn't unmarshal\n");
375 ok(!memcmp(b, b2, len), "strings differ\n");
376 BSTR_UserFree(&umcb.Flags, &b2);
378 HeapFree(GetProcessHeap(), 0, buffer);
379 SysFreeString(b);
381 b = SysAllocStringByteLen("", 0);
382 len = SysStringLen(b);
383 ok(len == 0, "get %d\n", len);
384 len = SysStringByteLen(b);
385 ok(len == 0, "get %d\n", len);
387 size = BSTR_UserSize(&umcb.Flags, 0, &b);
388 ok(size == 12, "size %ld\n", size);
390 buffer = HeapAlloc(GetProcessHeap(), 0, size);
391 next = BSTR_UserMarshal(&umcb.Flags, buffer, &b);
392 ok(next == buffer + size, "got %p expect %p\n", next, buffer + size);
393 check_bstr(buffer, b);
395 if (BSTR_UNMARSHAL_WORKS)
397 b2 = NULL;
398 next = BSTR_UserUnmarshal(&umcb.Flags, buffer, &b2);
399 ok(next == buffer + size, "got %p expect %p\n", next, buffer + size);
400 ok(b2 != NULL, "NULL LPSAFEARRAY didn't unmarshal\n");
401 len = SysStringByteLen(b2);
402 ok(len == 0, "byte len %d\n", len);
403 BSTR_UserFree(&umcb.Flags, &b2);
405 HeapFree(GetProcessHeap(), 0, buffer);
406 SysFreeString(b);
409 typedef struct
411 const IUnknownVtbl *lpVtbl;
412 ULONG refs;
413 } HeapUnknown;
415 static HRESULT WINAPI HeapUnknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
417 if (IsEqualIID(riid, &IID_IUnknown))
419 IUnknown_AddRef(iface);
420 *ppv = (LPVOID)iface;
421 return S_OK;
423 *ppv = NULL;
424 return E_NOINTERFACE;
427 static ULONG WINAPI HeapUnknown_AddRef(IUnknown *iface)
429 HeapUnknown *This = (HeapUnknown *)iface;
430 return InterlockedIncrement((LONG*)&This->refs);
433 static ULONG WINAPI HeapUnknown_Release(IUnknown *iface)
435 HeapUnknown *This = (HeapUnknown *)iface;
436 ULONG refs = InterlockedDecrement((LONG*)&This->refs);
437 if (!refs) HeapFree(GetProcessHeap(), 0, This);
438 return refs;
441 static const IUnknownVtbl HeapUnknown_Vtbl =
443 HeapUnknown_QueryInterface,
444 HeapUnknown_AddRef,
445 HeapUnknown_Release
448 static void check_variant_header(DWORD *wirev, VARIANT *v, unsigned long size)
450 WORD *wp;
451 DWORD switch_is;
453 ok(*wirev == (size + 7) >> 3, "wv[0] %08x, expected %08lx\n", *wirev, (size + 7) >> 3);
454 wirev++;
455 ok(*wirev == 0, "wv[1] %08x\n", *wirev);
456 wirev++;
457 wp = (WORD*)wirev;
458 ok(*wp == V_VT(v), "vt %04x expected %04x\n", *wp, V_VT(v));
459 wp++;
460 ok(*wp == V_U2(v).wReserved1, "res1 %04x expected %04x\n", *wp, V_U2(v).wReserved1);
461 wp++;
462 ok(*wp == V_U2(v).wReserved2, "res2 %04x expected %04x\n", *wp, V_U2(v).wReserved2);
463 wp++;
464 ok(*wp == V_U2(v).wReserved3, "res3 %04x expected %04x\n", *wp, V_U2(v).wReserved3);
465 wp++;
466 wirev = (DWORD*)wp;
467 switch_is = V_VT(v);
468 if(switch_is & VT_ARRAY)
469 switch_is &= ~VT_TYPEMASK;
470 ok(*wirev == switch_is, "switch_is %08x expected %08x\n", *wirev, switch_is);
473 static void test_marshal_VARIANT(void)
475 VARIANT v, v2;
476 MIDL_STUB_MESSAGE stubMsg = { 0 };
477 RPC_MESSAGE rpcMsg = { 0 };
478 USER_MARSHAL_CB umcb = { 0 };
479 unsigned char *buffer, *next;
480 ULONG ul;
481 short s;
482 double d;
483 DWORD *wirev;
484 BSTR b;
485 WCHAR str[] = {'m','a','r','s','h','a','l',' ','t','e','s','t',0};
486 SAFEARRAYBOUND sab;
487 LPSAFEARRAY lpsa;
488 DECIMAL dec, dec2;
489 HeapUnknown *heap_unknown;
491 stubMsg.RpcMsg = &rpcMsg;
493 umcb.Flags = MAKELONG(MSHCTX_DIFFERENTMACHINE, NDR_LOCAL_DATA_REPRESENTATION);
494 umcb.pStubMsg = &stubMsg;
495 umcb.pReserve = NULL;
496 umcb.Signature = USER_MARSHAL_CB_SIGNATURE;
497 umcb.CBType = USER_MARSHAL_CB_UNMARSHALL;
499 /*** I1 ***/
500 VariantInit(&v);
501 V_VT(&v) = VT_I1;
502 V_I1(&v) = 0x12;
504 /* Variants have an alignment of 8 */
505 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 1, &v);
506 ok(stubMsg.BufferLength == 29, "size %d\n", stubMsg.BufferLength);
508 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
509 ok(stubMsg.BufferLength == 21, "size %d\n", stubMsg.BufferLength);
511 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
512 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
513 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
514 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
515 wirev = (DWORD*)buffer;
517 check_variant_header(wirev, &v, stubMsg.BufferLength);
518 wirev += 5;
519 ok(*(char*)wirev == V_I1(&v), "wv[5] %08x\n", *wirev);
520 if (VARIANT_UNMARSHAL_WORKS)
522 VariantInit(&v2);
523 stubMsg.Buffer = buffer;
524 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
525 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
526 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
527 ok(V_I1(&v) == V_I1(&v2), "got i1 %x expect %x\n", V_I1(&v), V_I1(&v2));
529 VARIANT_UserFree(&umcb.Flags, &v2);
531 HeapFree(GetProcessHeap(), 0, buffer);
533 /*** I2 ***/
534 VariantInit(&v);
535 V_VT(&v) = VT_I2;
536 V_I2(&v) = 0x1234;
538 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
539 ok(stubMsg.BufferLength == 22, "size %d\n", stubMsg.BufferLength);
541 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
542 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
543 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
544 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
545 wirev = (DWORD*)buffer;
547 check_variant_header(wirev, &v, stubMsg.BufferLength);
548 wirev += 5;
549 ok(*(short*)wirev == V_I2(&v), "wv[5] %08x\n", *wirev);
550 if (VARIANT_UNMARSHAL_WORKS)
552 VariantInit(&v2);
553 stubMsg.Buffer = buffer;
554 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
555 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
556 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
557 ok(V_I2(&v) == V_I2(&v2), "got i2 %x expect %x\n", V_I2(&v), V_I2(&v2));
559 VARIANT_UserFree(&umcb.Flags, &v2);
561 HeapFree(GetProcessHeap(), 0, buffer);
563 /*** I2 BYREF ***/
564 VariantInit(&v);
565 V_VT(&v) = VT_I2 | VT_BYREF;
566 s = 0x1234;
567 V_I2REF(&v) = &s;
569 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
570 ok(stubMsg.BufferLength == 26, "size %d\n", stubMsg.BufferLength);
572 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
573 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
574 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
575 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
576 wirev = (DWORD*)buffer;
578 check_variant_header(wirev, &v, stubMsg.BufferLength);
579 wirev += 5;
580 ok(*wirev == 0x4, "wv[5] %08x\n", *wirev);
581 wirev++;
582 ok(*(short*)wirev == s, "wv[6] %08x\n", *wirev);
583 if (VARIANT_UNMARSHAL_WORKS)
585 VariantInit(&v2);
586 stubMsg.Buffer = buffer;
587 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
588 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
589 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
590 ok(*V_I2REF(&v) == *V_I2REF(&v2), "got i2 ref %x expect ui4 ref %x\n", *V_I2REF(&v), *V_I2REF(&v2));
592 VARIANT_UserFree(&umcb.Flags, &v2);
594 HeapFree(GetProcessHeap(), 0, buffer);
596 /*** I4 ***/
597 VariantInit(&v);
598 V_VT(&v) = VT_I4;
599 V_I4(&v) = 0x1234;
601 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
602 ok(stubMsg.BufferLength == 24, "size %d\n", stubMsg.BufferLength);
604 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
605 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
606 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
607 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
608 wirev = (DWORD*)buffer;
610 check_variant_header(wirev, &v, stubMsg.BufferLength);
611 wirev += 5;
612 ok(*wirev == V_I4(&v), "wv[5] %08x\n", *wirev);
614 if (VARIANT_UNMARSHAL_WORKS)
616 VariantInit(&v2);
617 stubMsg.Buffer = buffer;
618 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
619 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
620 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
621 ok(V_I4(&v) == V_I4(&v2), "got i4 %x expect %x\n", V_I4(&v), V_I4(&v2));
623 VARIANT_UserFree(&umcb.Flags, &v2);
626 HeapFree(GetProcessHeap(), 0, buffer);
628 /*** UI4 ***/
629 VariantInit(&v);
630 V_VT(&v) = VT_UI4;
631 V_UI4(&v) = 0x1234;
633 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
634 ok(stubMsg.BufferLength == 24, "size %d\n", stubMsg.BufferLength);
636 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
637 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
638 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
639 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
640 wirev = (DWORD*)buffer;
642 check_variant_header(wirev, &v, stubMsg.BufferLength);
643 wirev += 5;
644 ok(*wirev == 0x1234, "wv[5] %08x\n", *wirev);
645 if (VARIANT_UNMARSHAL_WORKS)
647 VariantInit(&v2);
648 stubMsg.Buffer = buffer;
649 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
650 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
651 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
652 ok(V_UI4(&v) == V_UI4(&v2), "got ui4 %x expect %x\n", V_UI4(&v), V_UI4(&v2));
654 VARIANT_UserFree(&umcb.Flags, &v2);
657 HeapFree(GetProcessHeap(), 0, buffer);
659 /*** UI4 BYREF ***/
660 VariantInit(&v);
661 V_VT(&v) = VT_UI4 | VT_BYREF;
662 ul = 0x1234;
663 V_UI4REF(&v) = &ul;
665 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
666 ok(stubMsg.BufferLength == 28, "size %d\n", stubMsg.BufferLength);
668 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
669 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
670 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
671 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
672 wirev = (DWORD*)buffer;
674 check_variant_header(wirev, &v, stubMsg.BufferLength);
675 wirev += 5;
676 ok(*wirev == 0x4, "wv[5] %08x\n", *wirev);
677 wirev++;
678 ok(*wirev == ul, "wv[6] %08x\n", *wirev);
680 if (VARIANT_UNMARSHAL_WORKS)
682 VariantInit(&v2);
683 stubMsg.Buffer = buffer;
684 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
685 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
686 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
687 ok(*V_UI4REF(&v) == *V_UI4REF(&v2), "got ui4 ref %x expect ui4 ref %x\n", *V_UI4REF(&v), *V_UI4REF(&v2));
689 VARIANT_UserFree(&umcb.Flags, &v2);
691 HeapFree(GetProcessHeap(), 0, buffer);
693 /*** R4 ***/
694 VariantInit(&v);
695 V_VT(&v) = VT_R4;
696 V_R8(&v) = 3.1415;
698 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
699 ok(stubMsg.BufferLength == 24, "size %d\n", stubMsg.BufferLength);
701 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
702 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
703 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
704 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
705 wirev = (DWORD*)buffer;
707 check_variant_header(wirev, &v, stubMsg.BufferLength);
708 wirev += 5;
709 ok(*(float*)wirev == V_R4(&v), "wv[5] %08x\n", *wirev);
710 if (VARIANT_UNMARSHAL_WORKS)
712 VariantInit(&v2);
713 stubMsg.Buffer = buffer;
714 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
715 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
716 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
717 ok(V_R4(&v) == V_R4(&v2), "got r4 %f expect %f\n", V_R4(&v), V_R4(&v2));
719 VARIANT_UserFree(&umcb.Flags, &v2);
721 HeapFree(GetProcessHeap(), 0, buffer);
723 /*** R8 ***/
724 VariantInit(&v);
725 V_VT(&v) = VT_R8;
726 V_R8(&v) = 3.1415;
728 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
729 ok(stubMsg.BufferLength == 32, "size %d\n", stubMsg.BufferLength);
731 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
732 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
733 memset(buffer, 0xcc, stubMsg.BufferLength);
734 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
735 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
736 wirev = (DWORD*)buffer;
738 check_variant_header(wirev, &v, stubMsg.BufferLength);
739 wirev += 5;
740 ok(*wirev == 0xcccccccc, "wv[5] %08x\n", *wirev); /* pad */
741 wirev++;
742 ok(*(double*)wirev == V_R8(&v), "wv[6] %08x, wv[7] %08x\n", *wirev, *(wirev+1));
743 if (VARIANT_UNMARSHAL_WORKS)
745 VariantInit(&v2);
746 stubMsg.Buffer = buffer;
747 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
748 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
749 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
750 ok(V_R8(&v) == V_R8(&v2), "got r8 %f expect %f\n", V_R8(&v), V_R8(&v2));
752 VARIANT_UserFree(&umcb.Flags, &v2);
754 HeapFree(GetProcessHeap(), 0, buffer);
756 /*** R8 BYREF ***/
757 VariantInit(&v);
758 V_VT(&v) = VT_R8 | VT_BYREF;
759 d = 3.1415;
760 V_R8REF(&v) = &d;
762 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
763 ok(stubMsg.BufferLength == 32, "size %d\n", stubMsg.BufferLength);
765 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
766 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
767 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
768 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
769 wirev = (DWORD*)buffer;
771 check_variant_header(wirev, &v, stubMsg.BufferLength);
772 wirev += 5;
773 ok(*wirev == 8, "wv[5] %08x\n", *wirev);
774 wirev++;
775 ok(*(double*)wirev == d, "wv[6] %08x wv[7] %08x\n", *wirev, *(wirev+1));
776 if (VARIANT_UNMARSHAL_WORKS)
778 VariantInit(&v2);
779 stubMsg.Buffer = buffer;
780 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
781 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
782 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
783 ok(*V_R8REF(&v) == *V_R8REF(&v2), "got r8 ref %f expect %f\n", *V_R8REF(&v), *V_R8REF(&v2));
785 VARIANT_UserFree(&umcb.Flags, &v2);
787 HeapFree(GetProcessHeap(), 0, buffer);
789 /*** VARIANT_BOOL ***/
790 VariantInit(&v);
791 V_VT(&v) = VT_BOOL;
792 V_BOOL(&v) = 0x1234;
794 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
795 ok(stubMsg.BufferLength == 22, "size %d\n", stubMsg.BufferLength);
797 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
798 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
799 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
800 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
801 wirev = (DWORD*)buffer;
803 check_variant_header(wirev, &v, stubMsg.BufferLength);
804 wirev += 5;
805 ok(*(short*)wirev == V_BOOL(&v), "wv[5] %04x\n", *(WORD*)wirev);
806 if (VARIANT_UNMARSHAL_WORKS)
808 VariantInit(&v2);
809 stubMsg.Buffer = buffer;
810 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
811 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
812 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
813 ok(V_BOOL(&v) == V_BOOL(&v2), "got bool %x expect %x\n", V_BOOL(&v), V_BOOL(&v2));
815 VARIANT_UserFree(&umcb.Flags, &v2);
817 HeapFree(GetProcessHeap(), 0, buffer);
819 /*** DECIMAL ***/
820 VarDecFromI4(0x12345678, &dec);
821 VariantInit(&v);
822 V_DECIMAL(&v) = dec;
823 V_VT(&v) = VT_DECIMAL;
825 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
826 ok(stubMsg.BufferLength == 40, "size %d\n", stubMsg.BufferLength);
828 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
829 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
830 memset(buffer, 0xcc, stubMsg.BufferLength);
831 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
832 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
833 wirev = (DWORD*)buffer;
835 check_variant_header(wirev, &v, stubMsg.BufferLength);
836 wirev += 5;
837 ok(*wirev == 0xcccccccc, "wirev[5] %08x\n", *wirev); /* pad */
838 wirev++;
839 dec2 = dec;
840 dec2.wReserved = VT_DECIMAL;
841 ok(!memcmp(wirev, &dec2, sizeof(dec2)), "wirev[6] %08x wirev[7] %08x wirev[8] %08x wirev[9] %08x\n",
842 *wirev, *(wirev + 1), *(wirev + 2), *(wirev + 3));
843 if (VARIANT_UNMARSHAL_WORKS)
845 VariantInit(&v2);
846 stubMsg.Buffer = buffer;
847 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
848 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
849 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
850 ok(!memcmp(&V_DECIMAL(&v), & V_DECIMAL(&v2), sizeof(DECIMAL)), "decimals differ\n");
852 VARIANT_UserFree(&umcb.Flags, &v2);
854 HeapFree(GetProcessHeap(), 0, buffer);
856 /*** DECIMAL BYREF ***/
857 VariantInit(&v);
858 V_VT(&v) = VT_DECIMAL | VT_BYREF;
859 V_DECIMALREF(&v) = &dec;
861 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
862 ok(stubMsg.BufferLength == 40, "size %d\n", stubMsg.BufferLength);
864 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
865 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
866 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
867 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
868 wirev = (DWORD*)buffer;
870 check_variant_header(wirev, &v, stubMsg.BufferLength);
871 wirev += 5;
872 ok(*wirev == 16, "wv[5] %08x\n", *wirev);
873 wirev++;
874 ok(!memcmp(wirev, &dec, sizeof(dec)), "wirev[6] %08x wirev[7] %08x wirev[8] %08x wirev[9] %08x\n", *wirev, *(wirev + 1), *(wirev + 2), *(wirev + 3));
875 if (VARIANT_UNMARSHAL_WORKS)
877 VariantInit(&v2);
878 stubMsg.Buffer = buffer;
879 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
880 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
881 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
882 ok(!memcmp(V_DECIMALREF(&v), V_DECIMALREF(&v2), sizeof(DECIMAL)), "decimals differ\n");
884 VARIANT_UserFree(&umcb.Flags, &v2);
886 HeapFree(GetProcessHeap(), 0, buffer);
888 /*** EMPTY ***/
889 VariantInit(&v);
890 V_VT(&v) = VT_EMPTY;
892 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
893 ok(stubMsg.BufferLength == 20, "size %d\n", stubMsg.BufferLength);
895 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
896 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
897 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
898 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
899 wirev = (DWORD*)buffer;
901 check_variant_header(wirev, &v, stubMsg.BufferLength);
902 if (VARIANT_UNMARSHAL_WORKS)
904 VariantInit(&v2);
905 stubMsg.Buffer = buffer;
906 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
907 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
908 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
910 VARIANT_UserFree(&umcb.Flags, &v2);
912 HeapFree(GetProcessHeap(), 0, buffer);
914 /*** NULL ***/
915 VariantInit(&v);
916 V_VT(&v) = VT_NULL;
918 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
919 ok(stubMsg.BufferLength == 20, "size %d\n", stubMsg.BufferLength);
921 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
922 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
923 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
924 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
925 wirev = (DWORD*)buffer;
927 check_variant_header(wirev, &v, stubMsg.BufferLength);
928 if (VARIANT_UNMARSHAL_WORKS)
930 VariantInit(&v2);
931 stubMsg.Buffer = buffer;
932 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
933 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
934 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
936 VARIANT_UserFree(&umcb.Flags, &v2);
938 HeapFree(GetProcessHeap(), 0, buffer);
940 /*** BSTR ***/
941 b = SysAllocString(str);
942 VariantInit(&v);
943 V_VT(&v) = VT_BSTR;
944 V_BSTR(&v) = b;
946 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
947 ok(stubMsg.BufferLength == 60, "size %d\n", stubMsg.BufferLength);
948 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
949 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
950 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
951 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
952 wirev = (DWORD*)buffer;
954 check_variant_header(wirev, &v, stubMsg.BufferLength);
955 wirev += 5;
956 ok(*wirev, "wv[5] %08x\n", *wirev); /* win2k: this is b. winxp: this is (char*)b + 1 */
957 wirev++;
958 check_bstr(wirev, V_BSTR(&v));
959 if (VARIANT_UNMARSHAL_WORKS)
961 VariantInit(&v2);
962 stubMsg.Buffer = buffer;
963 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
964 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
965 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
966 ok(SysStringByteLen(V_BSTR(&v)) == SysStringByteLen(V_BSTR(&v2)), "bstr string lens differ\n");
967 ok(!memcmp(V_BSTR(&v), V_BSTR(&v2), SysStringByteLen(V_BSTR(&v))), "bstrs differ\n");
969 VARIANT_UserFree(&umcb.Flags, &v2);
971 HeapFree(GetProcessHeap(), 0, buffer);
973 /*** BSTR BYREF ***/
974 VariantInit(&v);
975 V_VT(&v) = VT_BSTR | VT_BYREF;
976 V_BSTRREF(&v) = &b;
978 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
979 ok(stubMsg.BufferLength == 64, "size %d\n", stubMsg.BufferLength);
980 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
981 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
982 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
983 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
984 wirev = (DWORD*)buffer;
986 check_variant_header(wirev, &v, stubMsg.BufferLength);
987 wirev += 5;
988 ok(*wirev == 0x4, "wv[5] %08x\n", *wirev);
989 wirev++;
990 ok(*wirev, "wv[6] %08x\n", *wirev); /* win2k: this is b. winxp: this is (char*)b + 1 */
991 wirev++;
992 check_bstr(wirev, b);
993 if (VARIANT_UNMARSHAL_WORKS)
995 VariantInit(&v2);
996 stubMsg.Buffer = buffer;
997 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
998 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
999 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
1000 ok(SysStringByteLen(*V_BSTRREF(&v)) == SysStringByteLen(*V_BSTRREF(&v2)), "bstr string lens differ\n");
1001 ok(!memcmp(*V_BSTRREF(&v), *V_BSTRREF(&v2), SysStringByteLen(*V_BSTRREF(&v))), "bstrs differ\n");
1003 VARIANT_UserFree(&umcb.Flags, &v2);
1005 HeapFree(GetProcessHeap(), 0, buffer);
1006 SysFreeString(b);
1008 /*** ARRAY ***/
1009 sab.lLbound = 5;
1010 sab.cElements = 10;
1012 lpsa = SafeArrayCreate(VT_R8, 1, &sab);
1013 *(DWORD *)lpsa->pvData = 0xcafebabe;
1014 *((DWORD *)lpsa->pvData + 1) = 0xdeadbeef;
1015 lpsa->cLocks = 7;
1017 VariantInit(&v);
1018 V_VT(&v) = VT_UI4 | VT_ARRAY;
1019 V_ARRAY(&v) = lpsa;
1021 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
1022 ok(stubMsg.BufferLength == 152, "size %d\n", stubMsg.BufferLength);
1023 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
1024 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
1025 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
1026 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
1027 wirev = (DWORD*)buffer;
1029 check_variant_header(wirev, &v, stubMsg.BufferLength);
1030 wirev += 5;
1031 ok(*wirev, "wv[5] %08x\n", *wirev); /* win2k: this is lpsa. winxp: this is (char*)lpsa + 1 */
1032 wirev++;
1033 check_safearray(wirev, lpsa);
1034 if (VARIANT_UNMARSHAL_WORKS)
1036 LONG bound, bound2;
1037 VARTYPE vt, vt2;
1038 VariantInit(&v2);
1039 stubMsg.Buffer = buffer;
1040 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
1041 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
1042 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
1043 ok(SafeArrayGetDim(V_ARRAY(&v)) == SafeArrayGetDim(V_ARRAY(&v)), "array dims differ\n");
1044 SafeArrayGetLBound(V_ARRAY(&v), 1, &bound);
1045 SafeArrayGetLBound(V_ARRAY(&v2), 1, &bound2);
1046 ok(bound == bound2, "array lbounds differ\n");
1047 SafeArrayGetUBound(V_ARRAY(&v), 1, &bound);
1048 SafeArrayGetUBound(V_ARRAY(&v2), 1, &bound2);
1049 ok(bound == bound2, "array ubounds differ\n");
1050 SafeArrayGetVartype(V_ARRAY(&v), &vt);
1051 SafeArrayGetVartype(V_ARRAY(&v2), &vt2);
1052 ok(vt == vt2, "array vts differ %x %x\n", vt, vt2);
1053 VARIANT_UserFree(&umcb.Flags, &v2);
1055 HeapFree(GetProcessHeap(), 0, buffer);
1057 /*** ARRAY BYREF ***/
1058 VariantInit(&v);
1059 V_VT(&v) = VT_UI4 | VT_ARRAY | VT_BYREF;
1060 V_ARRAYREF(&v) = &lpsa;
1062 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
1063 ok(stubMsg.BufferLength == 152, "size %d\n", stubMsg.BufferLength);
1064 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
1065 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
1066 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
1067 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
1068 wirev = (DWORD*)buffer;
1070 check_variant_header(wirev, &v, stubMsg.BufferLength);
1071 wirev += 5;
1072 ok(*wirev == 4, "wv[5] %08x\n", *wirev);
1073 wirev++;
1074 ok(*wirev, "wv[6] %08x\n", *wirev); /* win2k: this is lpsa. winxp: this is (char*)lpsa + 1 */
1075 wirev++;
1076 check_safearray(wirev, lpsa);
1077 if (VARIANT_UNMARSHAL_WORKS)
1079 LONG bound, bound2;
1080 VARTYPE vt, vt2;
1081 VariantInit(&v2);
1082 stubMsg.Buffer = buffer;
1083 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
1084 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
1085 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
1086 ok(SafeArrayGetDim(*V_ARRAYREF(&v)) == SafeArrayGetDim(*V_ARRAYREF(&v)), "array dims differ\n");
1087 SafeArrayGetLBound(*V_ARRAYREF(&v), 1, &bound);
1088 SafeArrayGetLBound(*V_ARRAYREF(&v2), 1, &bound2);
1089 ok(bound == bound2, "array lbounds differ\n");
1090 SafeArrayGetUBound(*V_ARRAYREF(&v), 1, &bound);
1091 SafeArrayGetUBound(*V_ARRAYREF(&v2), 1, &bound2);
1092 ok(bound == bound2, "array ubounds differ\n");
1093 SafeArrayGetVartype(*V_ARRAYREF(&v), &vt);
1094 SafeArrayGetVartype(*V_ARRAYREF(&v2), &vt2);
1095 ok(vt == vt2, "array vts differ %x %x\n", vt, vt2);
1096 VARIANT_UserFree(&umcb.Flags, &v2);
1098 HeapFree(GetProcessHeap(), 0, buffer);
1099 SafeArrayDestroy(lpsa);
1101 /*** VARIANT BYREF ***/
1102 VariantInit(&v);
1103 VariantInit(&v2);
1104 V_VT(&v2) = VT_R8;
1105 V_R8(&v2) = 3.1415;
1106 V_VT(&v) = VT_VARIANT | VT_BYREF;
1107 V_VARIANTREF(&v) = &v2;
1109 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
1110 ok(stubMsg.BufferLength == 64, "size %d\n", stubMsg.BufferLength);
1111 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
1112 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
1113 memset(buffer, 0xcc, stubMsg.BufferLength);
1114 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
1115 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
1116 wirev = (DWORD*)buffer;
1117 check_variant_header(wirev, &v, stubMsg.BufferLength);
1118 wirev += 5;
1120 ok(*wirev == 16, "wv[5] %08x\n", *wirev);
1121 wirev++;
1122 ok(*wirev == ('U' | 's' << 8 | 'e' << 16 | 'r' << 24), "wv[6] %08x\n", *wirev); /* 'User' */
1123 wirev++;
1124 ok(*wirev == 0xcccccccc, "wv[7] %08x\n", *wirev); /* pad */
1125 wirev++;
1126 check_variant_header(wirev, &v2, stubMsg.BufferLength - 32);
1127 wirev += 5;
1128 ok(*wirev == 0xcccccccc, "wv[13] %08x\n", *wirev); /* pad for VT_R8 */
1129 wirev++;
1130 ok(*(double*)wirev == V_R8(&v2), "wv[6] %08x wv[7] %08x\n", *wirev, *(wirev+1));
1131 if (VARIANT_UNMARSHAL_WORKS)
1133 VARIANT v3;
1134 VariantInit(&v3);
1135 stubMsg.Buffer = buffer;
1136 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v3);
1137 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
1138 ok(V_VT(&v) == V_VT(&v3), "got vt %d expect %d\n", V_VT(&v), V_VT(&v3));
1139 ok(V_VT(V_VARIANTREF(&v)) == V_VT(V_VARIANTREF(&v3)), "vts differ %x %x\n",
1140 V_VT(V_VARIANTREF(&v)), V_VT(V_VARIANTREF(&v3)));
1141 ok(V_R8(V_VARIANTREF(&v)) == V_R8(V_VARIANTREF(&v3)), "r8s differ\n");
1142 VARIANT_UserFree(&umcb.Flags, &v3);
1144 HeapFree(GetProcessHeap(), 0, buffer);
1146 /*** UNKNOWN ***/
1147 heap_unknown = HeapAlloc(GetProcessHeap(), 0, sizeof(*heap_unknown));
1148 heap_unknown->lpVtbl = &HeapUnknown_Vtbl;
1149 heap_unknown->refs = 1;
1150 VariantInit(&v);
1151 VariantInit(&v2);
1152 V_VT(&v) = VT_UNKNOWN;
1153 V_UNKNOWN(&v) = (IUnknown *)heap_unknown;
1155 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
1156 ok(stubMsg.BufferLength > 32, "size %d\n", stubMsg.BufferLength);
1157 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
1158 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
1159 memset(buffer, 0xcc, stubMsg.BufferLength);
1160 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
1161 wirev = (DWORD*)buffer;
1162 check_variant_header(wirev, &v, next - buffer);
1163 wirev += 5;
1165 todo_wine
1166 ok(*wirev == (DWORD_PTR)V_UNKNOWN(&v) /* Win9x */ ||
1167 *wirev == (DWORD_PTR)V_UNKNOWN(&v) + 1 /* NT */, "wv[5] %08x\n", *wirev);
1168 wirev++;
1169 todo_wine
1170 ok(*wirev == next - buffer - 0x20, "wv[6] %08x\n", *wirev);
1171 wirev++;
1172 todo_wine
1173 ok(*wirev == next - buffer - 0x20, "wv[7] %08x\n", *wirev);
1174 wirev++;
1175 todo_wine
1176 ok(*wirev == 0x574f454d, "wv[8] %08x\n", *wirev);
1177 if (VARIANT_UNMARSHAL_WORKS)
1179 VARIANT v3;
1180 VariantInit(&v3);
1181 V_VT(&v3) = VT_UNKNOWN;
1182 V_UNKNOWN(&v3) = (IUnknown *)heap_unknown;
1183 IUnknown_AddRef(V_UNKNOWN(&v3));
1184 stubMsg.Buffer = buffer;
1185 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v3);
1186 ok(V_VT(&v) == V_VT(&v3), "got vt %d expect %d\n", V_VT(&v), V_VT(&v3));
1187 ok(V_VT(V_VARIANTREF(&v)) == V_VT(V_VARIANTREF(&v3)), "vts differ %x %x\n",
1188 V_VT(V_VARIANTREF(&v)), V_VT(V_VARIANTREF(&v3)));
1189 ok(V_R8(V_VARIANTREF(&v)) == V_R8(V_VARIANTREF(&v3)), "r8s differ\n");
1190 VARIANT_UserFree(&umcb.Flags, &v3);
1191 ok(heap_unknown->refs == 1, "%d refcounts of IUnknown leaked\n", heap_unknown->refs - 1);
1192 IUnknown_Release((IUnknown *)heap_unknown);
1194 HeapFree(GetProcessHeap(), 0, buffer);
1198 START_TEST(usrmarshal)
1200 CoInitialize(NULL);
1202 test_marshal_LPSAFEARRAY();
1203 test_marshal_BSTR();
1204 test_marshal_VARIANT();
1206 CoUninitialize();