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
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)
35 # define V_U2(A) (*(A))
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)
49 hr = SafeArrayGetVartype(psa, &vt);
52 if(psa->fFeatures & FADF_VARIANT) return SF_VARIANT;
54 switch(psa->cbElements)
56 case 1: vt = VT_I1; break;
57 case 2: vt = VT_I2; break;
58 case 4: vt = VT_I4; break;
59 case 8: vt = VT_I8; break;
64 if (psa->fFeatures & FADF_HAVEIID)
70 case VT_UI1: return SF_I1;
73 case VT_UI2: return SF_I2;
78 case VT_R4: return SF_I4;
83 case VT_UI8: return SF_I8;
85 case VT_UINT_PTR: return (sizeof(UINT_PTR) == 4 ? SF_I4 : SF_I8);
86 case VT_BSTR: return SF_BSTR;
87 case VT_DISPATCH: return SF_DISPATCH;
88 case VT_VARIANT: return SF_VARIANT;
89 case VT_UNKNOWN: return SF_UNKNOWN;
90 /* Note: Return a non-zero size to indicate vt is valid. The actual size
91 * of a UDT is taken from the result of IRecordInfo_GetSize().
93 case VT_RECORD: return SF_RECORD;
94 default: return SF_ERROR;
98 static ULONG get_cell_count(const SAFEARRAY *psa)
100 const SAFEARRAYBOUND* psab = psa->rgsabound;
101 USHORT cCount = psa->cDims;
102 ULONG ulNumCells = 1;
106 if (!psab->cElements)
108 ulNumCells *= psab->cElements;
114 static void check_safearray(void *buffer, LPSAFEARRAY lpsa)
116 unsigned char *wiresa = buffer;
123 ok(*(void **)wiresa == NULL, "wiresa + 0x0 should be NULL instead of 0x%08x\n", *(DWORD *)wiresa);
127 if(FAILED(SafeArrayGetVartype(lpsa, &vt)))
130 sftype = get_union_type(lpsa);
131 cell_count = get_cell_count(lpsa);
133 ok(*(DWORD *)wiresa, "wiresa + 0x0 should be non-NULL instead of 0x%08x\n", *(DWORD *)wiresa); /* win2k: this is lpsa. winxp: this is 0x00000001 */
134 wiresa += sizeof(DWORD);
135 ok(*(DWORD *)wiresa == lpsa->cDims, "wiresa + 0x4 should be lpsa->cDims instead of 0x%08x\n", *(DWORD *)wiresa);
136 wiresa += sizeof(DWORD);
137 ok(*(WORD *)wiresa == lpsa->cDims, "wiresa + 0x8 should be lpsa->cDims instead of 0x%04x\n", *(WORD *)wiresa);
138 wiresa += sizeof(WORD);
139 ok(*(WORD *)wiresa == lpsa->fFeatures, "wiresa + 0xc should be lpsa->fFeatures instead of 0x%08x\n", *(WORD *)wiresa);
140 wiresa += sizeof(WORD);
141 ok(*(DWORD *)wiresa == lpsa->cbElements, "wiresa + 0x10 should be lpsa->cbElements instead of 0x%08x\n", *(DWORD *)wiresa);
142 wiresa += sizeof(DWORD);
143 ok(*(WORD *)wiresa == lpsa->cLocks, "wiresa + 0x16 should be lpsa->cLocks instead of 0x%04x\n", *(WORD *)wiresa);
144 wiresa += sizeof(WORD);
145 ok(*(WORD *)wiresa == vt, "wiresa + 0x14 should be %04x instead of 0x%04x\n", vt, *(WORD *)wiresa);
146 wiresa += sizeof(WORD);
147 ok(*(DWORD *)wiresa == sftype, "wiresa + 0x18 should be %08x instead of 0x%08x\n", (DWORD)sftype, *(DWORD *)wiresa);
148 wiresa += sizeof(DWORD);
149 ok(*(DWORD *)wiresa == cell_count, "wiresa + 0x1c should be %u instead of %u\n", cell_count, *(DWORD *)wiresa);
150 wiresa += sizeof(DWORD);
151 ok(*(DWORD_PTR *)wiresa == (DWORD_PTR)lpsa->pvData, "wiresa + 0x20 should be lpsa->pvData instead of 0x%08lx\n", *(DWORD_PTR *)wiresa);
152 wiresa += sizeof(DWORD_PTR);
153 if(sftype == SF_HAVEIID)
156 SafeArrayGetIID(lpsa, &guid);
157 ok(IsEqualGUID(&guid, (GUID*)wiresa), "guid mismatch\n");
158 wiresa += sizeof(GUID);
160 ok(!memcmp(wiresa, lpsa->rgsabound, sizeof(lpsa->rgsabound[0]) * lpsa->cDims), "bounds mismatch\n");
161 wiresa += sizeof(lpsa->rgsabound[0]) * lpsa->cDims;
163 ok(*(DWORD *)wiresa == cell_count, "wiresa + 0x2c should be %u instead of %u\n", cell_count, *(DWORD*)wiresa);
164 wiresa += sizeof(DWORD);
165 /* elements are now pointed to by wiresa */
168 static void test_marshal_LPSAFEARRAY(void)
170 unsigned char *buffer;
173 LPSAFEARRAY lpsa2 = NULL;
175 MIDL_STUB_MESSAGE stubMsg = { 0 };
176 USER_MARSHAL_CB umcb = { 0 };
180 umcb.Flags = MAKELONG(MSHCTX_DIFFERENTMACHINE, NDR_LOCAL_DATA_REPRESENTATION);
181 umcb.pReserve = NULL;
182 umcb.pStubMsg = &stubMsg;
187 lpsa = SafeArrayCreate(VT_I2, 1, &sab);
188 *(DWORD *)lpsa->pvData = 0xcafebabe;
191 size = LPSAFEARRAY_UserSize(&umcb.Flags, 1, &lpsa);
192 ok(size == 68, "size should be 68 bytes, not %ld\n", size);
193 size = LPSAFEARRAY_UserSize(&umcb.Flags, 0, &lpsa);
194 ok(size == 64, "size should be 64 bytes, not %ld\n", size);
195 buffer = HeapAlloc(GetProcessHeap(), 0, size);
196 LPSAFEARRAY_UserMarshal(&umcb.Flags, buffer, &lpsa);
198 check_safearray(buffer, lpsa);
200 if (LPSAFEARRAY_UNMARSHAL_WORKS)
203 LPSAFEARRAY_UserUnmarshal(&umcb.Flags, buffer, &lpsa2);
204 ok(lpsa2 != NULL, "LPSAFEARRAY didn't unmarshal\n");
205 SafeArrayGetVartype(lpsa, &vt);
206 SafeArrayGetVartype(lpsa2, &vt2);
207 ok(vt == vt2, "vts differ %x %x\n", vt, vt2);
208 LPSAFEARRAY_UserFree(&umcb.Flags, &lpsa2);
210 HeapFree(GetProcessHeap(), 0, buffer);
212 SafeArrayDestroy(lpsa);
214 /* test NULL safe array */
217 size = LPSAFEARRAY_UserSize(&umcb.Flags, 0, &lpsa);
218 ok(size == 4, "size should be 4 bytes, not %ld\n", size);
219 buffer = HeapAlloc(GetProcessHeap(), 0, size);
220 LPSAFEARRAY_UserMarshal(&umcb.Flags, buffer, &lpsa);
221 check_safearray(buffer, lpsa);
223 if (LPSAFEARRAY_UNMARSHAL_WORKS)
225 LPSAFEARRAY_UserUnmarshal(&umcb.Flags, buffer, &lpsa2);
226 ok(lpsa2 == NULL, "NULL LPSAFEARRAY didn't unmarshal\n");
227 LPSAFEARRAY_UserFree(&umcb.Flags, &lpsa2);
229 HeapFree(GetProcessHeap(), 0, buffer);
234 lpsa = SafeArrayCreate(VT_R8, 1, &sab);
235 *(double *)lpsa->pvData = 3.1415;
238 size = LPSAFEARRAY_UserSize(&umcb.Flags, 1, &lpsa);
239 ok(size == 128, "size should be 128 bytes, not %ld\n", size);
240 size = LPSAFEARRAY_UserSize(&umcb.Flags, 0, &lpsa);
241 ok(size == 128, "size should be 128 bytes, not %ld\n", size);
242 buffer = HeapAlloc(GetProcessHeap(), 0, size);
243 LPSAFEARRAY_UserMarshal(&umcb.Flags, buffer, &lpsa);
245 check_safearray(buffer, lpsa);
247 HeapFree(GetProcessHeap(), 0, buffer);
249 SafeArrayDestroy(lpsa);
251 /* VARTYPE-less arrays can be marshaled if cbElements is 1,2,4 or 8 as type SF_In */
252 hr = SafeArrayAllocDescriptor(1, &lpsa);
253 ok(hr == S_OK, "saad failed %08x\n", hr);
254 lpsa->cbElements = 8;
255 lpsa->rgsabound[0].lLbound = 2;
256 lpsa->rgsabound[0].cElements = 48;
257 hr = SafeArrayAllocData(lpsa);
258 ok(hr == S_OK, "saad failed %08x\n", hr);
260 hr = SafeArrayGetVartype(lpsa, &vt);
261 ok(hr == E_INVALIDARG, "ret %08x\n", hr);
263 size = LPSAFEARRAY_UserSize(&umcb.Flags, 0, &lpsa);
264 ok(size == 432, "size %ld\n", size);
265 buffer = HeapAlloc(GetProcessHeap(), 0, size);
266 LPSAFEARRAY_UserMarshal(&umcb.Flags, buffer, &lpsa);
267 check_safearray(buffer, lpsa);
268 HeapFree(GetProcessHeap(), 0, buffer);
269 SafeArrayDestroyData(lpsa);
270 SafeArrayDestroyDescriptor(lpsa);
272 /* VARTYPE-less arrays with FADF_VARIANT */
273 hr = SafeArrayAllocDescriptor(1, &lpsa);
274 ok(hr == S_OK, "saad failed %08x\n", hr);
275 lpsa->cbElements = 16;
276 lpsa->fFeatures = FADF_VARIANT;
277 lpsa->rgsabound[0].lLbound = 2;
278 lpsa->rgsabound[0].cElements = 48;
279 hr = SafeArrayAllocData(lpsa);
280 ok(hr == S_OK, "saad failed %08x\n", hr);
282 hr = SafeArrayGetVartype(lpsa, &vt);
283 ok(hr == E_INVALIDARG, "ret %08x\n", hr);
285 size = LPSAFEARRAY_UserSize(&umcb.Flags, 0, &lpsa);
287 ok(size == 1388, "size %ld\n", size);
288 buffer = HeapAlloc(GetProcessHeap(), 0, size);
289 LPSAFEARRAY_UserMarshal(&umcb.Flags, buffer, &lpsa);
290 check_safearray(buffer, lpsa);
291 HeapFree(GetProcessHeap(), 0, buffer);
292 SafeArrayDestroyData(lpsa);
293 SafeArrayDestroyDescriptor(lpsa);
296 static void check_bstr(void *buffer, BSTR b)
298 DWORD *wireb = buffer;
299 DWORD len = SysStringByteLen(b);
301 ok(*wireb == (len + 1) / 2, "wv[0] %08x\n", *wireb);
304 ok(*wireb == len, "wv[1] %08x\n", *wireb);
306 ok(*wireb == 0xffffffff, "wv[1] %08x\n", *wireb);
308 ok(*wireb == (len + 1) / 2, "wv[2] %08x\n", *wireb);
312 ok(!memcmp(wireb, b, (len + 1) & ~1), "strings differ\n");
317 static void test_marshal_BSTR(void)
320 MIDL_STUB_MESSAGE stubMsg = { 0 };
321 USER_MARSHAL_CB umcb = { 0 };
322 unsigned char *buffer, *next;
324 WCHAR str[] = {'m','a','r','s','h','a','l',' ','t','e','s','t','1',0};
327 umcb.Flags = MAKELONG(MSHCTX_DIFFERENTMACHINE, NDR_LOCAL_DATA_REPRESENTATION);
328 umcb.pReserve = NULL;
329 umcb.pStubMsg = &stubMsg;
331 b = SysAllocString(str);
332 len = SysStringLen(b);
333 ok(len == 13, "get %d\n", len);
335 /* BSTRs are DWORD aligned */
336 size = BSTR_UserSize(&umcb.Flags, 1, &b);
337 ok(size == 42, "size %ld\n", size);
339 size = BSTR_UserSize(&umcb.Flags, 0, &b);
340 ok(size == 38, "size %ld\n", size);
342 buffer = HeapAlloc(GetProcessHeap(), 0, size);
343 next = BSTR_UserMarshal(&umcb.Flags, buffer, &b);
344 ok(next == buffer + size, "got %p expect %p\n", next, buffer + size);
345 check_bstr(buffer, b);
347 if (BSTR_UNMARSHAL_WORKS)
350 next = BSTR_UserUnmarshal(&umcb.Flags, buffer, &b2);
351 ok(next == buffer + size, "got %p expect %p\n", next, buffer + size);
352 ok(b2 != NULL, "BSTR didn't unmarshal\n");
353 ok(!memcmp(b, b2, (len + 1) * 2), "strings differ\n");
354 BSTR_UserFree(&umcb.Flags, &b2);
357 HeapFree(GetProcessHeap(), 0, buffer);
361 size = BSTR_UserSize(&umcb.Flags, 0, &b);
362 ok(size == 12, "size %ld\n", size);
364 buffer = HeapAlloc(GetProcessHeap(), 0, size);
365 next = BSTR_UserMarshal(&umcb.Flags, buffer, &b);
366 ok(next == buffer + size, "got %p expect %p\n", next, buffer + size);
368 check_bstr(buffer, b);
369 if (BSTR_UNMARSHAL_WORKS)
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, "NULL BSTR didn't unmarshal\n");
375 BSTR_UserFree(&umcb.Flags, &b2);
377 HeapFree(GetProcessHeap(), 0, buffer);
379 b = SysAllocStringByteLen("abc", 3);
380 *(((char*)b) + 3) = 'd';
381 len = SysStringLen(b);
382 ok(len == 1, "get %d\n", len);
383 len = SysStringByteLen(b);
384 ok(len == 3, "get %d\n", len);
386 size = BSTR_UserSize(&umcb.Flags, 0, &b);
387 ok(size == 16, "size %ld\n", size);
389 buffer = HeapAlloc(GetProcessHeap(), 0, size);
390 memset(buffer, 0xcc, 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);
394 ok(buffer[15] == 'd', "buffer[15] %02x\n", buffer[15]);
396 if (BSTR_UNMARSHAL_WORKS)
399 next = BSTR_UserUnmarshal(&umcb.Flags, buffer, &b2);
400 ok(next == buffer + size, "got %p expect %p\n", next, buffer + size);
401 ok(b2 != NULL, "BSTR didn't unmarshal\n");
402 ok(!memcmp(b, b2, len), "strings differ\n");
403 BSTR_UserFree(&umcb.Flags, &b2);
405 HeapFree(GetProcessHeap(), 0, buffer);
408 b = SysAllocStringByteLen("", 0);
409 len = SysStringLen(b);
410 ok(len == 0, "get %d\n", len);
411 len = SysStringByteLen(b);
412 ok(len == 0, "get %d\n", len);
414 size = BSTR_UserSize(&umcb.Flags, 0, &b);
415 ok(size == 12, "size %ld\n", size);
417 buffer = HeapAlloc(GetProcessHeap(), 0, size);
418 next = BSTR_UserMarshal(&umcb.Flags, buffer, &b);
419 ok(next == buffer + size, "got %p expect %p\n", next, buffer + size);
420 check_bstr(buffer, b);
422 if (BSTR_UNMARSHAL_WORKS)
425 next = BSTR_UserUnmarshal(&umcb.Flags, buffer, &b2);
426 ok(next == buffer + size, "got %p expect %p\n", next, buffer + size);
427 ok(b2 != NULL, "NULL LPSAFEARRAY didn't unmarshal\n");
428 len = SysStringByteLen(b2);
429 ok(len == 0, "byte len %d\n", len);
430 BSTR_UserFree(&umcb.Flags, &b2);
432 HeapFree(GetProcessHeap(), 0, buffer);
438 const IUnknownVtbl *lpVtbl;
442 static HRESULT WINAPI HeapUnknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
444 if (IsEqualIID(riid, &IID_IUnknown))
446 IUnknown_AddRef(iface);
447 *ppv = (LPVOID)iface;
451 return E_NOINTERFACE;
454 static ULONG WINAPI HeapUnknown_AddRef(IUnknown *iface)
456 HeapUnknown *This = (HeapUnknown *)iface;
457 return InterlockedIncrement((LONG*)&This->refs);
460 static ULONG WINAPI HeapUnknown_Release(IUnknown *iface)
462 HeapUnknown *This = (HeapUnknown *)iface;
463 ULONG refs = InterlockedDecrement((LONG*)&This->refs);
464 if (!refs) HeapFree(GetProcessHeap(), 0, This);
468 static const IUnknownVtbl HeapUnknown_Vtbl =
470 HeapUnknown_QueryInterface,
475 static void check_variant_header(DWORD *wirev, VARIANT *v, unsigned long size)
480 ok(*wirev == (size + 7) >> 3, "wv[0] %08x, expected %08lx\n", *wirev, (size + 7) >> 3);
482 ok(*wirev == 0, "wv[1] %08x\n", *wirev);
485 ok(*wp == V_VT(v), "vt %04x expected %04x\n", *wp, V_VT(v));
487 ok(*wp == V_U2(v).wReserved1, "res1 %04x expected %04x\n", *wp, V_U2(v).wReserved1);
489 ok(*wp == V_U2(v).wReserved2, "res2 %04x expected %04x\n", *wp, V_U2(v).wReserved2);
491 ok(*wp == V_U2(v).wReserved3, "res3 %04x expected %04x\n", *wp, V_U2(v).wReserved3);
495 if(switch_is & VT_ARRAY)
496 switch_is &= ~VT_TYPEMASK;
497 ok(*wirev == switch_is, "switch_is %08x expected %08x\n", *wirev, switch_is);
500 static void test_marshal_VARIANT(void)
503 MIDL_STUB_MESSAGE stubMsg = { 0 };
504 RPC_MESSAGE rpcMsg = { 0 };
505 USER_MARSHAL_CB umcb = { 0 };
506 unsigned char *buffer, *next;
512 WCHAR str[] = {'m','a','r','s','h','a','l',' ','t','e','s','t',0};
516 HeapUnknown *heap_unknown;
518 stubMsg.RpcMsg = &rpcMsg;
520 umcb.Flags = MAKELONG(MSHCTX_DIFFERENTMACHINE, NDR_LOCAL_DATA_REPRESENTATION);
521 umcb.pStubMsg = &stubMsg;
522 umcb.pReserve = NULL;
523 umcb.Signature = USER_MARSHAL_CB_SIGNATURE;
524 umcb.CBType = USER_MARSHAL_CB_UNMARSHALL;
531 /* check_variant_header tests wReserved[123], so initialize to unique values.
532 * (Could probably also do this by setting the variant to a known DECIMAL.)
534 V_U2(&v).wReserved1 = 0x1234;
535 V_U2(&v).wReserved2 = 0x5678;
536 V_U2(&v).wReserved3 = 0x9abc;
538 /* Variants have an alignment of 8 */
539 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 1, &v);
540 ok(stubMsg.BufferLength == 29, "size %d\n", stubMsg.BufferLength);
542 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
543 ok(stubMsg.BufferLength == 21, "size %d\n", stubMsg.BufferLength);
545 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
546 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
547 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
548 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
549 wirev = (DWORD*)buffer;
551 check_variant_header(wirev, &v, stubMsg.BufferLength);
553 ok(*(char*)wirev == V_I1(&v), "wv[5] %08x\n", *wirev);
554 if (VARIANT_UNMARSHAL_WORKS)
557 stubMsg.Buffer = buffer;
558 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
559 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
560 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
561 ok(V_I1(&v) == V_I1(&v2), "got i1 %x expect %x\n", V_I1(&v), V_I1(&v2));
563 VARIANT_UserFree(&umcb.Flags, &v2);
565 HeapFree(GetProcessHeap(), 0, buffer);
572 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
573 ok(stubMsg.BufferLength == 22, "size %d\n", stubMsg.BufferLength);
575 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
576 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
577 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
578 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
579 wirev = (DWORD*)buffer;
581 check_variant_header(wirev, &v, stubMsg.BufferLength);
583 ok(*(short*)wirev == V_I2(&v), "wv[5] %08x\n", *wirev);
584 if (VARIANT_UNMARSHAL_WORKS)
587 stubMsg.Buffer = buffer;
588 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
589 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
590 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
591 ok(V_I2(&v) == V_I2(&v2), "got i2 %x expect %x\n", V_I2(&v), V_I2(&v2));
593 VARIANT_UserFree(&umcb.Flags, &v2);
595 HeapFree(GetProcessHeap(), 0, buffer);
599 V_VT(&v) = VT_I2 | VT_BYREF;
603 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
604 ok(stubMsg.BufferLength == 26, "size %d\n", stubMsg.BufferLength);
606 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
607 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
608 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
609 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
610 wirev = (DWORD*)buffer;
612 check_variant_header(wirev, &v, stubMsg.BufferLength);
614 ok(*wirev == 0x4, "wv[5] %08x\n", *wirev);
616 ok(*(short*)wirev == s, "wv[6] %08x\n", *wirev);
617 if (VARIANT_UNMARSHAL_WORKS)
621 V_VT(&v2) = VT_I2 | VT_BYREF;
622 V_BYREF(&v2) = mem = CoTaskMemAlloc(sizeof(V_I2(&v2)));
623 stubMsg.Buffer = buffer;
624 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
625 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
626 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
627 ok(V_BYREF(&v2) == mem, "didn't reuse existing memory\n");
628 ok(*V_I2REF(&v) == *V_I2REF(&v2), "got i2 ref %x expect ui4 ref %x\n", *V_I2REF(&v), *V_I2REF(&v2));
630 VARIANT_UserFree(&umcb.Flags, &v2);
632 HeapFree(GetProcessHeap(), 0, buffer);
639 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
640 ok(stubMsg.BufferLength == 24, "size %d\n", stubMsg.BufferLength);
642 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
643 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
644 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
645 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
646 wirev = (DWORD*)buffer;
648 check_variant_header(wirev, &v, stubMsg.BufferLength);
650 ok(*wirev == V_I4(&v), "wv[5] %08x\n", *wirev);
652 if (VARIANT_UNMARSHAL_WORKS)
655 stubMsg.Buffer = buffer;
656 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
657 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
658 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
659 ok(V_I4(&v) == V_I4(&v2), "got i4 %x expect %x\n", V_I4(&v), V_I4(&v2));
661 VARIANT_UserFree(&umcb.Flags, &v2);
664 HeapFree(GetProcessHeap(), 0, buffer);
671 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
672 ok(stubMsg.BufferLength == 24, "size %d\n", stubMsg.BufferLength);
674 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
675 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
676 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
677 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
678 wirev = (DWORD*)buffer;
680 check_variant_header(wirev, &v, stubMsg.BufferLength);
682 ok(*wirev == 0x1234, "wv[5] %08x\n", *wirev);
683 if (VARIANT_UNMARSHAL_WORKS)
686 stubMsg.Buffer = buffer;
687 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
688 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
689 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
690 ok(V_UI4(&v) == V_UI4(&v2), "got ui4 %x expect %x\n", V_UI4(&v), V_UI4(&v2));
692 VARIANT_UserFree(&umcb.Flags, &v2);
695 HeapFree(GetProcessHeap(), 0, buffer);
699 V_VT(&v) = VT_UI4 | VT_BYREF;
703 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
704 ok(stubMsg.BufferLength == 28, "size %d\n", stubMsg.BufferLength);
706 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
707 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
708 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
709 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
710 wirev = (DWORD*)buffer;
712 check_variant_header(wirev, &v, stubMsg.BufferLength);
714 ok(*wirev == 0x4, "wv[5] %08x\n", *wirev);
716 ok(*wirev == ul, "wv[6] %08x\n", *wirev);
718 if (VARIANT_UNMARSHAL_WORKS)
721 stubMsg.Buffer = buffer;
722 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
723 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
724 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
725 ok(*V_UI4REF(&v) == *V_UI4REF(&v2), "got ui4 ref %x expect ui4 ref %x\n", *V_UI4REF(&v), *V_UI4REF(&v2));
727 VARIANT_UserFree(&umcb.Flags, &v2);
729 HeapFree(GetProcessHeap(), 0, buffer);
736 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
737 ok(stubMsg.BufferLength == 24, "size %d\n", stubMsg.BufferLength);
739 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
740 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
741 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
742 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
743 wirev = (DWORD*)buffer;
745 check_variant_header(wirev, &v, stubMsg.BufferLength);
747 ok(*(float*)wirev == V_R4(&v), "wv[5] %08x\n", *wirev);
748 if (VARIANT_UNMARSHAL_WORKS)
751 stubMsg.Buffer = buffer;
752 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
753 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
754 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
755 ok(V_R4(&v) == V_R4(&v2), "got r4 %f expect %f\n", V_R4(&v), V_R4(&v2));
757 VARIANT_UserFree(&umcb.Flags, &v2);
759 HeapFree(GetProcessHeap(), 0, buffer);
766 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
767 ok(stubMsg.BufferLength == 32, "size %d\n", stubMsg.BufferLength);
769 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
770 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
771 memset(buffer, 0xcc, stubMsg.BufferLength);
772 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
773 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
774 wirev = (DWORD*)buffer;
776 check_variant_header(wirev, &v, stubMsg.BufferLength);
778 ok(*wirev == 0xcccccccc, "wv[5] %08x\n", *wirev); /* pad */
780 ok(*(double*)wirev == V_R8(&v), "wv[6] %08x, wv[7] %08x\n", *wirev, *(wirev+1));
781 if (VARIANT_UNMARSHAL_WORKS)
784 stubMsg.Buffer = buffer;
785 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
786 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
787 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
788 ok(V_R8(&v) == V_R8(&v2), "got r8 %f expect %f\n", V_R8(&v), V_R8(&v2));
790 VARIANT_UserFree(&umcb.Flags, &v2);
792 HeapFree(GetProcessHeap(), 0, buffer);
796 V_VT(&v) = VT_R8 | VT_BYREF;
800 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
801 ok(stubMsg.BufferLength == 32, "size %d\n", stubMsg.BufferLength);
803 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
804 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
805 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
806 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
807 wirev = (DWORD*)buffer;
809 check_variant_header(wirev, &v, stubMsg.BufferLength);
811 ok(*wirev == 8, "wv[5] %08x\n", *wirev);
813 ok(*(double*)wirev == d, "wv[6] %08x wv[7] %08x\n", *wirev, *(wirev+1));
814 if (VARIANT_UNMARSHAL_WORKS)
817 stubMsg.Buffer = buffer;
818 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
819 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
820 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
821 ok(*V_R8REF(&v) == *V_R8REF(&v2), "got r8 ref %f expect %f\n", *V_R8REF(&v), *V_R8REF(&v2));
823 VARIANT_UserFree(&umcb.Flags, &v2);
825 HeapFree(GetProcessHeap(), 0, buffer);
827 /*** VARIANT_BOOL ***/
832 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
833 ok(stubMsg.BufferLength == 22, "size %d\n", stubMsg.BufferLength);
835 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
836 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
837 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
838 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
839 wirev = (DWORD*)buffer;
841 check_variant_header(wirev, &v, stubMsg.BufferLength);
843 ok(*(short*)wirev == V_BOOL(&v), "wv[5] %04x\n", *(WORD*)wirev);
844 if (VARIANT_UNMARSHAL_WORKS)
847 stubMsg.Buffer = buffer;
848 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
849 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
850 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
851 ok(V_BOOL(&v) == V_BOOL(&v2), "got bool %x expect %x\n", V_BOOL(&v), V_BOOL(&v2));
853 VARIANT_UserFree(&umcb.Flags, &v2);
855 HeapFree(GetProcessHeap(), 0, buffer);
858 VarDecFromI4(0x12345678, &dec);
859 dec.wReserved = 0xfedc; /* Also initialize reserved field, as we check it later */
862 V_VT(&v) = VT_DECIMAL;
864 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
865 ok(stubMsg.BufferLength == 40, "size %d\n", stubMsg.BufferLength);
867 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
868 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
869 memset(buffer, 0xcc, stubMsg.BufferLength);
870 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
871 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
872 wirev = (DWORD*)buffer;
874 check_variant_header(wirev, &v, stubMsg.BufferLength);
876 ok(*wirev == 0xcccccccc, "wirev[5] %08x\n", *wirev); /* pad */
879 dec2.wReserved = VT_DECIMAL;
880 ok(!memcmp(wirev, &dec2, sizeof(dec2)), "wirev[6] %08x wirev[7] %08x wirev[8] %08x wirev[9] %08x\n",
881 *wirev, *(wirev + 1), *(wirev + 2), *(wirev + 3));
882 if (VARIANT_UNMARSHAL_WORKS)
885 stubMsg.Buffer = buffer;
886 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
887 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
888 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
889 ok(!memcmp(&V_DECIMAL(&v), & V_DECIMAL(&v2), sizeof(DECIMAL)), "decimals differ\n");
891 VARIANT_UserFree(&umcb.Flags, &v2);
893 HeapFree(GetProcessHeap(), 0, buffer);
895 /*** DECIMAL BYREF ***/
897 V_VT(&v) = VT_DECIMAL | VT_BYREF;
898 V_DECIMALREF(&v) = &dec;
900 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
901 ok(stubMsg.BufferLength == 40, "size %d\n", stubMsg.BufferLength);
903 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
904 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
905 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
906 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
907 wirev = (DWORD*)buffer;
909 check_variant_header(wirev, &v, stubMsg.BufferLength);
911 ok(*wirev == 16, "wv[5] %08x\n", *wirev);
913 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));
914 if (VARIANT_UNMARSHAL_WORKS)
917 /* check_variant_header tests wReserved[123], so initialize to unique values.
918 * (Could probably also do this by setting the variant to a known DECIMAL.)
920 V_U2(&v2).wReserved1 = 0x0123;
921 V_U2(&v2).wReserved2 = 0x4567;
922 V_U2(&v2).wReserved3 = 0x89ab;
924 stubMsg.Buffer = buffer;
925 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
926 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
927 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
928 ok(!memcmp(V_DECIMALREF(&v), V_DECIMALREF(&v2), sizeof(DECIMAL)), "decimals differ\n");
930 VARIANT_UserFree(&umcb.Flags, &v2);
932 HeapFree(GetProcessHeap(), 0, buffer);
938 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
939 ok(stubMsg.BufferLength == 20, "size %d\n", stubMsg.BufferLength);
941 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
942 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
943 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
944 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
945 wirev = (DWORD*)buffer;
947 check_variant_header(wirev, &v, stubMsg.BufferLength);
948 if (VARIANT_UNMARSHAL_WORKS)
951 stubMsg.Buffer = buffer;
952 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
953 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
954 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
956 VARIANT_UserFree(&umcb.Flags, &v2);
958 HeapFree(GetProcessHeap(), 0, buffer);
964 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
965 ok(stubMsg.BufferLength == 20, "size %d\n", stubMsg.BufferLength);
967 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
968 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
969 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
970 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
971 wirev = (DWORD*)buffer;
973 check_variant_header(wirev, &v, stubMsg.BufferLength);
974 if (VARIANT_UNMARSHAL_WORKS)
977 stubMsg.Buffer = buffer;
978 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
979 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
980 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
982 VARIANT_UserFree(&umcb.Flags, &v2);
984 HeapFree(GetProcessHeap(), 0, buffer);
987 b = SysAllocString(str);
992 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
993 ok(stubMsg.BufferLength == 60, "size %d\n", stubMsg.BufferLength);
994 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
995 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
996 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
997 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
998 wirev = (DWORD*)buffer;
1000 check_variant_header(wirev, &v, stubMsg.BufferLength);
1002 ok(*wirev, "wv[5] %08x\n", *wirev); /* win2k: this is b. winxp: this is (char*)b + 1 */
1004 check_bstr(wirev, V_BSTR(&v));
1005 if (VARIANT_UNMARSHAL_WORKS)
1008 stubMsg.Buffer = buffer;
1009 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
1010 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
1011 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
1012 ok(SysStringByteLen(V_BSTR(&v)) == SysStringByteLen(V_BSTR(&v2)), "bstr string lens differ\n");
1013 ok(!memcmp(V_BSTR(&v), V_BSTR(&v2), SysStringByteLen(V_BSTR(&v))), "bstrs differ\n");
1015 VARIANT_UserFree(&umcb.Flags, &v2);
1017 HeapFree(GetProcessHeap(), 0, buffer);
1019 /*** BSTR BYREF ***/
1021 V_VT(&v) = VT_BSTR | VT_BYREF;
1024 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
1025 ok(stubMsg.BufferLength == 64, "size %d\n", stubMsg.BufferLength);
1026 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
1027 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
1028 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
1029 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
1030 wirev = (DWORD*)buffer;
1032 check_variant_header(wirev, &v, stubMsg.BufferLength);
1034 ok(*wirev == 0x4, "wv[5] %08x\n", *wirev);
1036 ok(*wirev, "wv[6] %08x\n", *wirev); /* win2k: this is b. winxp: this is (char*)b + 1 */
1038 check_bstr(wirev, b);
1039 if (VARIANT_UNMARSHAL_WORKS)
1042 stubMsg.Buffer = buffer;
1043 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
1044 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
1045 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
1046 ok(SysStringByteLen(*V_BSTRREF(&v)) == SysStringByteLen(*V_BSTRREF(&v2)), "bstr string lens differ\n");
1047 ok(!memcmp(*V_BSTRREF(&v), *V_BSTRREF(&v2), SysStringByteLen(*V_BSTRREF(&v))), "bstrs differ\n");
1049 VARIANT_UserFree(&umcb.Flags, &v2);
1051 HeapFree(GetProcessHeap(), 0, buffer);
1058 lpsa = SafeArrayCreate(VT_R8, 1, &sab);
1059 *(DWORD *)lpsa->pvData = 0xcafebabe;
1060 *((DWORD *)lpsa->pvData + 1) = 0xdeadbeef;
1063 V_VT(&v) = VT_UI4 | VT_ARRAY;
1066 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
1067 ok(stubMsg.BufferLength == 152, "size %d\n", stubMsg.BufferLength);
1068 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
1069 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
1070 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
1071 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
1072 wirev = (DWORD*)buffer;
1074 check_variant_header(wirev, &v, stubMsg.BufferLength);
1076 ok(*wirev, "wv[5] %08x\n", *wirev); /* win2k: this is lpsa. winxp: this is (char*)lpsa + 1 */
1078 check_safearray(wirev, lpsa);
1079 if (VARIANT_UNMARSHAL_WORKS)
1084 stubMsg.Buffer = buffer;
1085 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
1086 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
1087 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
1088 ok(SafeArrayGetDim(V_ARRAY(&v)) == SafeArrayGetDim(V_ARRAY(&v)), "array dims differ\n");
1089 SafeArrayGetLBound(V_ARRAY(&v), 1, &bound);
1090 SafeArrayGetLBound(V_ARRAY(&v2), 1, &bound2);
1091 ok(bound == bound2, "array lbounds differ\n");
1092 SafeArrayGetUBound(V_ARRAY(&v), 1, &bound);
1093 SafeArrayGetUBound(V_ARRAY(&v2), 1, &bound2);
1094 ok(bound == bound2, "array ubounds differ\n");
1095 SafeArrayGetVartype(V_ARRAY(&v), &vt);
1096 SafeArrayGetVartype(V_ARRAY(&v2), &vt2);
1097 ok(vt == vt2, "array vts differ %x %x\n", vt, vt2);
1098 VARIANT_UserFree(&umcb.Flags, &v2);
1100 HeapFree(GetProcessHeap(), 0, buffer);
1102 /*** ARRAY BYREF ***/
1104 V_VT(&v) = VT_UI4 | VT_ARRAY | VT_BYREF;
1105 V_ARRAYREF(&v) = &lpsa;
1107 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
1108 ok(stubMsg.BufferLength == 152, "size %d\n", stubMsg.BufferLength);
1109 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
1110 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
1111 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
1112 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
1113 wirev = (DWORD*)buffer;
1115 check_variant_header(wirev, &v, stubMsg.BufferLength);
1117 ok(*wirev == 4, "wv[5] %08x\n", *wirev);
1119 ok(*wirev, "wv[6] %08x\n", *wirev); /* win2k: this is lpsa. winxp: this is (char*)lpsa + 1 */
1121 check_safearray(wirev, lpsa);
1122 if (VARIANT_UNMARSHAL_WORKS)
1127 stubMsg.Buffer = buffer;
1128 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2);
1129 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
1130 ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2));
1131 ok(SafeArrayGetDim(*V_ARRAYREF(&v)) == SafeArrayGetDim(*V_ARRAYREF(&v)), "array dims differ\n");
1132 SafeArrayGetLBound(*V_ARRAYREF(&v), 1, &bound);
1133 SafeArrayGetLBound(*V_ARRAYREF(&v2), 1, &bound2);
1134 ok(bound == bound2, "array lbounds differ\n");
1135 SafeArrayGetUBound(*V_ARRAYREF(&v), 1, &bound);
1136 SafeArrayGetUBound(*V_ARRAYREF(&v2), 1, &bound2);
1137 ok(bound == bound2, "array ubounds differ\n");
1138 SafeArrayGetVartype(*V_ARRAYREF(&v), &vt);
1139 SafeArrayGetVartype(*V_ARRAYREF(&v2), &vt2);
1140 ok(vt == vt2, "array vts differ %x %x\n", vt, vt2);
1141 VARIANT_UserFree(&umcb.Flags, &v2);
1143 HeapFree(GetProcessHeap(), 0, buffer);
1144 SafeArrayDestroy(lpsa);
1146 /*** VARIANT BYREF ***/
1151 V_VT(&v) = VT_VARIANT | VT_BYREF;
1152 V_VARIANTREF(&v) = &v2;
1154 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
1155 ok(stubMsg.BufferLength == 64, "size %d\n", stubMsg.BufferLength);
1156 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
1157 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
1158 memset(buffer, 0xcc, stubMsg.BufferLength);
1159 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
1160 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
1161 wirev = (DWORD*)buffer;
1162 check_variant_header(wirev, &v, stubMsg.BufferLength);
1165 ok(*wirev == 16, "wv[5] %08x\n", *wirev);
1167 ok(*wirev == ('U' | 's' << 8 | 'e' << 16 | 'r' << 24), "wv[6] %08x\n", *wirev); /* 'User' */
1169 ok(*wirev == 0xcccccccc, "wv[7] %08x\n", *wirev); /* pad */
1171 check_variant_header(wirev, &v2, stubMsg.BufferLength - 32);
1173 ok(*wirev == 0xcccccccc, "wv[13] %08x\n", *wirev); /* pad for VT_R8 */
1175 ok(*(double*)wirev == V_R8(&v2), "wv[6] %08x wv[7] %08x\n", *wirev, *(wirev+1));
1176 if (VARIANT_UNMARSHAL_WORKS)
1180 stubMsg.Buffer = buffer;
1181 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v3);
1182 ok(next == buffer + stubMsg.BufferLength, "got %p expect %p\n", next, buffer + stubMsg.BufferLength);
1183 ok(V_VT(&v) == V_VT(&v3), "got vt %d expect %d\n", V_VT(&v), V_VT(&v3));
1184 ok(V_VT(V_VARIANTREF(&v)) == V_VT(V_VARIANTREF(&v3)), "vts differ %x %x\n",
1185 V_VT(V_VARIANTREF(&v)), V_VT(V_VARIANTREF(&v3)));
1186 ok(V_R8(V_VARIANTREF(&v)) == V_R8(V_VARIANTREF(&v3)), "r8s differ\n");
1187 VARIANT_UserFree(&umcb.Flags, &v3);
1189 HeapFree(GetProcessHeap(), 0, buffer);
1192 heap_unknown = HeapAlloc(GetProcessHeap(), 0, sizeof(*heap_unknown));
1193 heap_unknown->lpVtbl = &HeapUnknown_Vtbl;
1194 heap_unknown->refs = 1;
1197 V_VT(&v) = VT_UNKNOWN;
1198 V_UNKNOWN(&v) = (IUnknown *)heap_unknown;
1200 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
1201 ok(stubMsg.BufferLength > 32, "size %d\n", stubMsg.BufferLength);
1202 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
1203 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
1204 memset(buffer, 0xcc, stubMsg.BufferLength);
1205 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
1206 wirev = (DWORD*)buffer;
1207 check_variant_header(wirev, &v, next - buffer);
1211 ok(*wirev == (DWORD_PTR)V_UNKNOWN(&v) /* Win9x */ ||
1212 *wirev == (DWORD_PTR)V_UNKNOWN(&v) + 1 /* NT */, "wv[5] %08x\n", *wirev);
1215 ok(*wirev == next - buffer - 0x20, "wv[6] %08x\n", *wirev);
1218 ok(*wirev == next - buffer - 0x20, "wv[7] %08x\n", *wirev);
1221 ok(*wirev == 0x574f454d, "wv[8] %08x\n", *wirev);
1222 if (VARIANT_UNMARSHAL_WORKS)
1226 V_VT(&v3) = VT_UNKNOWN;
1227 V_UNKNOWN(&v3) = (IUnknown *)heap_unknown;
1228 IUnknown_AddRef(V_UNKNOWN(&v3));
1229 stubMsg.Buffer = buffer;
1230 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v3);
1231 ok(V_VT(&v) == V_VT(&v3), "got vt %d expect %d\n", V_VT(&v), V_VT(&v3));
1232 ok(V_UNKNOWN(&v) == V_UNKNOWN(&v3), "got %p expect %p\n", V_UNKNOWN(&v), V_UNKNOWN(&v3));
1233 VARIANT_UserFree(&umcb.Flags, &v3);
1234 ok(heap_unknown->refs == 1, "%d refcounts of IUnknown leaked\n", heap_unknown->refs - 1);
1235 IUnknown_Release((IUnknown *)heap_unknown);
1237 HeapFree(GetProcessHeap(), 0, buffer);
1239 /*** UNKNOWN BYREF ***/
1240 heap_unknown = HeapAlloc(GetProcessHeap(), 0, sizeof(*heap_unknown));
1241 heap_unknown->lpVtbl = &HeapUnknown_Vtbl;
1242 heap_unknown->refs = 1;
1245 V_VT(&v) = VT_UNKNOWN | VT_BYREF;
1246 V_UNKNOWNREF(&v) = (IUnknown **)&heap_unknown;
1248 rpcMsg.BufferLength = stubMsg.BufferLength = VARIANT_UserSize(&umcb.Flags, 0, &v);
1249 ok(stubMsg.BufferLength > 36, "size %d\n", stubMsg.BufferLength);
1250 buffer = rpcMsg.Buffer = stubMsg.Buffer = stubMsg.BufferStart = HeapAlloc(GetProcessHeap(), 0, stubMsg.BufferLength);
1251 stubMsg.BufferEnd = stubMsg.Buffer + stubMsg.BufferLength;
1252 memset(buffer, 0xcc, stubMsg.BufferLength);
1253 next = VARIANT_UserMarshal(&umcb.Flags, buffer, &v);
1254 wirev = (DWORD*)buffer;
1255 check_variant_header(wirev, &v, next - buffer);
1258 ok(*wirev == 4, "wv[5] %08x\n", *wirev);
1261 ok(*wirev == (DWORD_PTR)heap_unknown /* Win9x, Win2000 */ ||
1262 *wirev == (DWORD_PTR)heap_unknown + 1 /* XP */, "wv[6] %08x\n", *wirev);
1265 ok(*wirev == next - buffer - 0x24, "wv[7] %08x\n", *wirev);
1268 ok(*wirev == next - buffer - 0x24, "wv[8] %08x\n", *wirev);
1271 ok(*wirev == 0x574f454d, "wv[9] %08x\n", *wirev);
1272 if (VARIANT_UNMARSHAL_WORKS)
1276 V_VT(&v3) = VT_UNKNOWN;
1277 V_UNKNOWN(&v3) = (IUnknown *)heap_unknown;
1278 IUnknown_AddRef(V_UNKNOWN(&v3));
1279 stubMsg.Buffer = buffer;
1280 next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v3);
1281 ok(V_VT(&v) == V_VT(&v3), "got vt %d expect %d\n", V_VT(&v), V_VT(&v3));
1282 ok(*V_UNKNOWNREF(&v) == *V_UNKNOWNREF(&v3), "got %p expect %p\n", *V_UNKNOWNREF(&v), *V_UNKNOWNREF(&v3));
1283 VARIANT_UserFree(&umcb.Flags, &v3);
1284 ok(heap_unknown->refs == 1, "%d refcounts of IUnknown leaked\n", heap_unknown->refs - 1);
1285 IUnknown_Release((IUnknown *)heap_unknown);
1287 HeapFree(GetProcessHeap(), 0, buffer);
1291 START_TEST(usrmarshal)
1295 test_marshal_LPSAFEARRAY();
1296 test_marshal_BSTR();
1297 test_marshal_VARIANT();