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
29 #include "propidl.h" /* for LPSAFEARRAY_User* routines */
31 #include "wine/test.h"
33 #if (__STDC__ && !defined(_FORCENAMELESSUNION)) || defined(NONAMELESSUNION)
34 # define V_U2(A) ((A)->n1.n2)
36 # define V_U2(A) (*(A))
39 static HRESULT (WINAPI
*pSafeArrayGetIID
)(SAFEARRAY
*,GUID
*);
40 static HRESULT (WINAPI
*pSafeArrayGetVartype
)(SAFEARRAY
*,VARTYPE
*);
41 static HRESULT (WINAPI
*pVarBstrCmp
)(BSTR
,BSTR
,LCID
,ULONG
);
43 static inline SF_TYPE
get_union_type(SAFEARRAY
*psa
)
48 hr
= pSafeArrayGetVartype(psa
, &vt
);
51 if(psa
->fFeatures
& FADF_VARIANT
) return SF_VARIANT
;
53 switch(psa
->cbElements
)
55 case 1: vt
= VT_I1
; break;
56 case 2: vt
= VT_I2
; break;
57 case 4: vt
= VT_I4
; break;
58 case 8: vt
= VT_I8
; break;
63 if (psa
->fFeatures
& FADF_HAVEIID
)
69 case VT_UI1
: return SF_I1
;
72 case VT_UI2
: return SF_I2
;
77 case VT_R4
: return SF_I4
;
82 case VT_UI8
: return SF_I8
;
84 case VT_UINT_PTR
: return (sizeof(UINT_PTR
) == 4 ? SF_I4
: SF_I8
);
85 case VT_BSTR
: return SF_BSTR
;
86 case VT_DISPATCH
: return SF_DISPATCH
;
87 case VT_VARIANT
: return SF_VARIANT
;
88 case VT_UNKNOWN
: return SF_UNKNOWN
;
89 /* Note: Return a non-zero size to indicate vt is valid. The actual size
90 * of a UDT is taken from the result of IRecordInfo_GetSize().
92 case VT_RECORD
: return SF_RECORD
;
93 default: return SF_ERROR
;
97 static ULONG
get_cell_count(const SAFEARRAY
*psa
)
99 const SAFEARRAYBOUND
* psab
= psa
->rgsabound
;
100 USHORT cCount
= psa
->cDims
;
101 ULONG ulNumCells
= 1;
105 if (!psab
->cElements
)
107 ulNumCells
*= psab
->cElements
;
113 static DWORD
elem_wire_size(LPSAFEARRAY lpsa
, SF_TYPE sftype
)
115 if (sftype
== SF_BSTR
)
116 return sizeof(DWORD
);
118 return lpsa
->cbElements
;
121 static void check_safearray(void *buffer
, LPSAFEARRAY lpsa
)
123 unsigned char *wiresa
= buffer
;
124 const SAFEARRAYBOUND
*bounds
;
132 ok(*(DWORD
*)wiresa
== 0, "wiresa + 0x0 should be NULL instead of 0x%08x\n", *(DWORD
*)wiresa
);
136 if (!pSafeArrayGetVartype
|| !pSafeArrayGetIID
)
139 if(FAILED(pSafeArrayGetVartype(lpsa
, &vt
)))
142 sftype
= get_union_type(lpsa
);
143 cell_count
= get_cell_count(lpsa
);
145 ok(*(DWORD
*)wiresa
, "wiresa + 0x0 should be non-NULL instead of 0x%08x\n", *(DWORD
*)wiresa
); /* win2k: this is lpsa. winxp: this is 0x00000001 */
146 wiresa
+= sizeof(DWORD
);
147 ok(*(DWORD
*)wiresa
== lpsa
->cDims
, "wiresa + 0x4 should be lpsa->cDims instead of 0x%08x\n", *(DWORD
*)wiresa
);
148 wiresa
+= sizeof(DWORD
);
149 ok(*(WORD
*)wiresa
== lpsa
->cDims
, "wiresa + 0x8 should be lpsa->cDims instead of 0x%04x\n", *(WORD
*)wiresa
);
150 wiresa
+= sizeof(WORD
);
151 ok(*(WORD
*)wiresa
== lpsa
->fFeatures
, "wiresa + 0xa should be lpsa->fFeatures instead of 0x%08x\n", *(WORD
*)wiresa
);
152 wiresa
+= sizeof(WORD
);
153 ok(*(DWORD
*)wiresa
== elem_wire_size(lpsa
, sftype
), "wiresa + 0xc should be 0x%08x instead of 0x%08x\n", elem_wire_size(lpsa
, sftype
), *(DWORD
*)wiresa
);
154 wiresa
+= sizeof(DWORD
);
155 ok(*(WORD
*)wiresa
== lpsa
->cLocks
, "wiresa + 0x10 should be lpsa->cLocks instead of 0x%04x\n", *(WORD
*)wiresa
);
156 wiresa
+= sizeof(WORD
);
157 ok(*(WORD
*)wiresa
== vt
, "wiresa + 0x12 should be %04x instead of 0x%04x\n", vt
, *(WORD
*)wiresa
);
158 wiresa
+= sizeof(WORD
);
159 ok(*(DWORD
*)wiresa
== sftype
, "wiresa + 0x14 should be %08x instead of 0x%08x\n", (DWORD
)sftype
, *(DWORD
*)wiresa
);
160 wiresa
+= sizeof(DWORD
);
161 ok(*(DWORD
*)wiresa
== cell_count
, "wiresa + 0x18 should be %u instead of %u\n", cell_count
, *(DWORD
*)wiresa
);
162 wiresa
+= sizeof(DWORD
);
163 ok(*(DWORD
*)wiresa
, "wiresa + 0x1c should be non-zero instead of 0x%08x\n", *(DWORD
*)wiresa
);
164 wiresa
+= sizeof(DWORD
);
165 if(sftype
== SF_HAVEIID
)
168 pSafeArrayGetIID(lpsa
, &guid
);
169 ok(IsEqualGUID(&guid
, wiresa
), "guid mismatch\n");
170 wiresa
+= sizeof(GUID
);
173 /* bounds are marshaled in natural dimensions order */
174 bounds
= (SAFEARRAYBOUND
*)wiresa
;
175 for(i
=0; i
<lpsa
->cDims
; i
++)
177 ok(memcmp(bounds
, &lpsa
->rgsabound
[lpsa
->cDims
-i
-1], sizeof(SAFEARRAYBOUND
)) == 0,
178 "bounds mismatch for dimension %d, got (%d,%d), expected (%d,%d)\n", i
,
179 bounds
->lLbound
, bounds
->cElements
, lpsa
->rgsabound
[lpsa
->cDims
-i
-1].lLbound
,
180 lpsa
->rgsabound
[lpsa
->cDims
-i
-1].cElements
);
184 wiresa
+= sizeof(lpsa
->rgsabound
[0]) * lpsa
->cDims
;
186 ok(*(DWORD
*)wiresa
== cell_count
, "wiresa + 0x28 should be %u instead of %u\n", cell_count
, *(DWORD
*)wiresa
);
187 wiresa
+= sizeof(DWORD
);
188 /* elements are now pointed to by wiresa */
191 static void * WINAPI
user_allocate(SIZE_T size
)
193 ok(0, "unexpected user_allocate call\n");
194 return CoTaskMemAlloc(size
);
197 static void WINAPI
user_free(void *p
)
199 ok(0, "unexpected user_free call\n");
203 static void init_user_marshal_cb(USER_MARSHAL_CB
*umcb
,
204 PMIDL_STUB_MESSAGE stub_msg
,
205 PRPC_MESSAGE rpc_msg
, unsigned char *buffer
,
206 unsigned int size
, MSHCTX context
)
208 memset(rpc_msg
, 0, sizeof(*rpc_msg
));
209 rpc_msg
->Buffer
= buffer
;
210 rpc_msg
->BufferLength
= size
;
212 memset(stub_msg
, 0, sizeof(*stub_msg
));
213 stub_msg
->RpcMsg
= rpc_msg
;
214 stub_msg
->Buffer
= buffer
;
215 stub_msg
->pfnAllocate
= user_allocate
;
216 stub_msg
->pfnFree
= user_free
;
218 memset(umcb
, 0, sizeof(*umcb
));
219 umcb
->Flags
= MAKELONG(context
, NDR_LOCAL_DATA_REPRESENTATION
);
220 umcb
->pStubMsg
= stub_msg
;
221 umcb
->Signature
= USER_MARSHAL_CB_SIGNATURE
;
222 umcb
->CBType
= buffer
? USER_MARSHAL_CB_UNMARSHALL
: USER_MARSHAL_CB_BUFFER_SIZE
;
225 static void test_marshal_LPSAFEARRAY(void)
227 unsigned char *buffer
, *next
;
228 ULONG size
, expected
;
230 LPSAFEARRAY lpsa2
= NULL
;
231 SAFEARRAYBOUND sab
[2];
233 MIDL_STUB_MESSAGE stub_msg
;
234 USER_MARSHAL_CB umcb
;
238 int expected_bstr_size
;
243 sab
[0].cElements
= 10;
245 lpsa
= SafeArrayCreate(VT_I2
, 1, sab
);
246 *(DWORD
*)lpsa
->pvData
= 0xcafebabe;
249 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
250 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 1, &lpsa
);
251 expected
= (44 + 1 + sizeof(ULONG
) - 1) & ~(sizeof(ULONG
) - 1);
252 expected
+= sab
[0].cElements
* sizeof(USHORT
);
253 ok(size
== expected
|| size
== expected
+ 12, /* win64 */
254 "size should be %u bytes, not %u\n", expected
, size
);
255 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
256 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 0, &lpsa
);
257 expected
= 44 + sab
[0].cElements
* sizeof(USHORT
);
258 ok(size
== expected
|| size
== expected
+ 12, /* win64 */
259 "size should be %u bytes, not %u\n", expected
, size
);
260 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
261 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
262 next
= LPSAFEARRAY_UserMarshal(&umcb
.Flags
, buffer
, &lpsa
);
263 ok(next
- buffer
== expected
, "Marshaled %u bytes, expected %u\n", (ULONG
) (next
- buffer
), expected
);
264 ok(lpsa
->cLocks
== 7, "got lock count %u\n", lpsa
->cLocks
);
266 check_safearray(buffer
, lpsa
);
268 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
269 LPSAFEARRAY_UserUnmarshal(&umcb
.Flags
, buffer
, &lpsa2
);
270 ok(lpsa2
!= NULL
, "LPSAFEARRAY didn't unmarshal\n");
271 if (pSafeArrayGetVartype
)
273 pSafeArrayGetVartype(lpsa
, &vt
);
274 pSafeArrayGetVartype(lpsa2
, &vt2
);
275 ok(vt
== vt2
, "vts differ %x %x\n", vt
, vt2
);
277 ok(lpsa2
->cLocks
== 0, "got lock count %u, expected 0\n", lpsa2
->cLocks
);
278 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
279 LPSAFEARRAY_UserFree(&umcb
.Flags
, &lpsa2
);
280 ok(!lpsa2
, "lpsa2 was not set to 0 by LPSAFEARRAY_UserFree\n");
281 HeapFree(GetProcessHeap(), 0, buffer
);
283 hr
= SafeArrayDestroy(lpsa
);
284 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
286 /* use two dimensions */
288 sab
[0].cElements
= 10;
290 sab
[1].cElements
= 2;
292 lpsa
= SafeArrayCreate(VT_I2
, 2, sab
);
293 *(DWORD
*)lpsa
->pvData
= 0xcafebabe;
296 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
297 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 1, &lpsa
);
298 expected
= (44 + 1 + +sizeof(SAFEARRAYBOUND
) + sizeof(ULONG
) - 1) & ~(sizeof(ULONG
) - 1);
299 expected
+= max(sab
[0].cElements
, sab
[1].cElements
) * lpsa
->cDims
* sizeof(USHORT
);
300 ok(size
== expected
|| size
== expected
+ 12, /* win64 */
301 "size should be %u bytes, not %u\n", expected
, size
);
302 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
303 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 0, &lpsa
);
304 expected
= 52 + max(sab
[0].cElements
, sab
[1].cElements
) * lpsa
->cDims
* sizeof(USHORT
);
305 ok(size
== expected
|| size
== expected
+ 12, /* win64 */
306 "size should be %u bytes, not %u\n", expected
, size
);
307 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
308 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
309 next
= LPSAFEARRAY_UserMarshal(&umcb
.Flags
, buffer
, &lpsa
);
310 ok(next
- buffer
== expected
, "Marshaled %u bytes, expected %u\n", (ULONG
) (next
- buffer
), expected
);
311 ok(lpsa
->cLocks
== 7, "got lock count %u\n", lpsa
->cLocks
);
313 check_safearray(buffer
, lpsa
);
315 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
316 LPSAFEARRAY_UserUnmarshal(&umcb
.Flags
, buffer
, &lpsa2
);
317 ok(lpsa2
!= NULL
, "LPSAFEARRAY didn't unmarshal\n");
318 if (pSafeArrayGetVartype
)
320 pSafeArrayGetVartype(lpsa
, &vt
);
321 pSafeArrayGetVartype(lpsa2
, &vt2
);
322 ok(vt
== vt2
, "vts differ %x %x\n", vt
, vt2
);
324 ok(lpsa2
->cLocks
== 0, "got lock count %u, expected 0\n", lpsa2
->cLocks
);
325 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
326 LPSAFEARRAY_UserFree(&umcb
.Flags
, &lpsa2
);
327 HeapFree(GetProcessHeap(), 0, buffer
);
329 hr
= SafeArrayDestroy(lpsa
);
330 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
332 /* test NULL safe array */
335 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
336 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 0, &lpsa
);
338 ok(size
== expected
, "size should be 4 bytes, not %d\n", size
);
339 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
340 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
341 next
= LPSAFEARRAY_UserMarshal(&umcb
.Flags
, buffer
, &lpsa
);
342 ok(next
- buffer
== expected
, "Marshaled %u bytes, expected %u\n", (ULONG
) (next
- buffer
), expected
);
343 check_safearray(buffer
, lpsa
);
345 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
346 LPSAFEARRAY_UserUnmarshal(&umcb
.Flags
, buffer
, &lpsa2
);
347 ok(lpsa2
== NULL
, "NULL LPSAFEARRAY didn't unmarshal\n");
348 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
349 LPSAFEARRAY_UserFree(&umcb
.Flags
, &lpsa2
);
350 HeapFree(GetProcessHeap(), 0, buffer
);
353 sab
[0].cElements
= 10;
355 lpsa
= SafeArrayCreate(VT_R8
, 1, sab
);
356 *(double *)lpsa
->pvData
= 3.1415;
359 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
360 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 1, &lpsa
);
361 expected
= (44 + 1 + (sizeof(double) - 1)) & ~(sizeof(double) - 1);
362 expected
+= sab
[0].cElements
* sizeof(double);
363 ok(size
== expected
|| size
== expected
+ 16, /* win64 */
364 "size should be %u bytes, not %u\n", expected
, size
);
365 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
366 expected
= (44 + (sizeof(double) - 1)) & ~(sizeof(double) - 1);
367 expected
+= sab
[0].cElements
* sizeof(double);
368 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 0, &lpsa
);
369 ok(size
== expected
|| size
== expected
+ 8, /* win64 */
370 "size should be %u bytes, not %u\n", expected
, size
);
371 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
372 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
373 next
= LPSAFEARRAY_UserMarshal(&umcb
.Flags
, buffer
, &lpsa
);
374 ok(next
- buffer
== expected
|| broken(next
- buffer
+ sizeof(DWORD
) == expected
),
375 "Marshaled %u bytes, expected %u\n", (ULONG
) (next
- buffer
), expected
);
377 check_safearray(buffer
, lpsa
);
379 HeapFree(GetProcessHeap(), 0, buffer
);
381 hr
= SafeArrayDestroy(lpsa
);
382 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
384 /* VARTYPE-less arrays can be marshaled if cbElements is 1,2,4 or 8 as type SF_In */
385 hr
= SafeArrayAllocDescriptor(1, &lpsa
);
386 ok(hr
== S_OK
, "saad failed %08x\n", hr
);
387 lpsa
->cbElements
= 8;
388 lpsa
->rgsabound
[0].lLbound
= 2;
389 lpsa
->rgsabound
[0].cElements
= 48;
390 hr
= SafeArrayAllocData(lpsa
);
391 ok(hr
== S_OK
, "saad failed %08x\n", hr
);
393 if (pSafeArrayGetVartype
)
395 hr
= pSafeArrayGetVartype(lpsa
, &vt
);
396 ok(hr
== E_INVALIDARG
, "ret %08x\n", hr
);
399 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
400 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 0, &lpsa
);
401 expected
= (44 + lpsa
->cbElements
- 1) & ~(lpsa
->cbElements
- 1);
402 expected
+= lpsa
->cbElements
* lpsa
->rgsabound
[0].cElements
;
403 ok(size
== expected
|| size
== expected
+ 8, /* win64 */
404 "size should be %u bytes, not %u\n", expected
, size
);
405 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
406 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
407 next
= LPSAFEARRAY_UserMarshal(&umcb
.Flags
, buffer
, &lpsa
);
408 ok(next
- buffer
== expected
|| broken(next
- buffer
+ sizeof(DWORD
) == expected
),
409 "Marshaled %u bytes, expected %u\n", (ULONG
) (next
- buffer
), expected
);
410 check_safearray(buffer
, lpsa
);
411 HeapFree(GetProcessHeap(), 0, buffer
);
412 hr
= SafeArrayDestroyData(lpsa
);
413 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
414 hr
= SafeArrayDestroyDescriptor(lpsa
);
415 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
417 /* Test an array of VT_BSTR */
419 sab
[0].cElements
= sizeof(values
) / sizeof(values
[0]);
421 lpsa
= SafeArrayCreate(VT_BSTR
, 1, sab
);
422 expected_bstr_size
= 0;
423 for (i
= 0; i
< sab
[0].cElements
; i
++)
427 for (j
= 0; j
<= i
; j
++)
430 indices
[0] = i
+ sab
[0].lLbound
;
431 values
[i
] = SysAllocString(buf
);
432 hr
= SafeArrayPutElement(lpsa
, indices
, values
[i
]);
433 ok(hr
== S_OK
, "Failed to put bstr element hr 0x%x\n", hr
);
434 expected_bstr_size
+= (j
* sizeof(WCHAR
)) + (3 * sizeof(DWORD
));
435 if (i
% 2 == 0) /* Account for DWORD padding. Works so long as cElements is even */
436 expected_bstr_size
+= sizeof(WCHAR
);
439 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
440 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 1, &lpsa
);
441 expected
= 44 + (sab
[0].cElements
* sizeof(DWORD
)) + expected_bstr_size
;
443 ok(size
== expected
+ sizeof(DWORD
) || size
== (expected
+ sizeof(DWORD
) + 12 /* win64 */),
444 "size should be %u bytes, not %u\n", expected
+ (ULONG
) sizeof(DWORD
), size
);
445 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
446 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 0, &lpsa
);
448 ok(size
== expected
|| size
== (expected
+ 12 /* win64 */),
449 "size should be %u bytes, not %u\n", expected
, size
);
450 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
451 memset(buffer
, 0xcc, size
);
452 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
453 next
= LPSAFEARRAY_UserMarshal(&umcb
.Flags
, buffer
, &lpsa
);
455 ok(next
- buffer
== expected
, "Marshaled %u bytes, expected %u\n", (ULONG
) (next
- buffer
), expected
);
457 check_safearray(buffer
, lpsa
);
460 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
461 next
= LPSAFEARRAY_UserUnmarshal(&umcb
.Flags
, buffer
, &lpsa2
);
463 ok(next
- buffer
== expected
, "Marshaled %u bytes, expected %u\n", (ULONG
) (next
- buffer
), expected
);
464 ok(lpsa2
!= NULL
, "LPSAFEARRAY didn't unmarshal, result %p\n", next
);
466 for (i
= 0; i
< sizeof(values
) / sizeof(values
[0]); i
++)
468 BSTR gotvalue
= NULL
;
472 indices
[0] = i
+ sab
[0].lLbound
;
473 hr
= SafeArrayGetElement(lpsa2
, indices
, &gotvalue
);
474 ok(hr
== S_OK
, "Failed to get bstr element at hres 0x%x\n", hr
);
478 ok(pVarBstrCmp(values
[i
], gotvalue
, 0, 0) == VARCMP_EQ
, "String %d does not match\n", i
);
479 SysFreeString(gotvalue
);
483 SysFreeString(values
[i
]);
486 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
487 LPSAFEARRAY_UserFree(&umcb
.Flags
, &lpsa2
);
489 HeapFree(GetProcessHeap(), 0, buffer
);
490 hr
= SafeArrayDestroy(lpsa
);
491 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
493 /* VARTYPE-less arrays with FADF_VARIANT */
494 hr
= SafeArrayAllocDescriptor(1, &lpsa
);
495 ok(hr
== S_OK
, "saad failed %08x\n", hr
);
496 lpsa
->cbElements
= sizeof(VARIANT
);
497 lpsa
->fFeatures
= FADF_VARIANT
;
498 lpsa
->rgsabound
[0].lLbound
= 2;
499 lpsa
->rgsabound
[0].cElements
= 48;
500 hr
= SafeArrayAllocData(lpsa
);
501 ok(hr
== S_OK
, "saad failed %08x\n", hr
);
503 if (pSafeArrayGetVartype
)
505 hr
= pSafeArrayGetVartype(lpsa
, &vt
);
506 ok(hr
== E_INVALIDARG
, "ret %08x\n", hr
);
509 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
510 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 0, &lpsa
);
511 expected
= 44 + 28 * lpsa
->rgsabound
[0].cElements
;
513 ok(size
== expected
|| size
== expected
+ 8, /* win64 */
514 "size should be %u bytes, not %u\n", expected
, size
);
515 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
516 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
517 next
= LPSAFEARRAY_UserMarshal(&umcb
.Flags
, buffer
, &lpsa
);
519 ok(next
- buffer
== expected
|| broken(next
- buffer
+ sizeof(DWORD
) == expected
),
520 "Marshaled %u bytes, expected %u\n", (ULONG
) (next
- buffer
), expected
);
521 lpsa
->cbElements
= 16; /* VARIANT wire size */
522 check_safearray(buffer
, lpsa
);
523 HeapFree(GetProcessHeap(), 0, buffer
);
524 hr
= SafeArrayDestroyData(lpsa
);
525 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
526 hr
= SafeArrayDestroyDescriptor(lpsa
);
527 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
530 static void check_bstr(void *buffer
, BSTR b
)
532 DWORD
*wireb
= buffer
;
533 DWORD len
= SysStringByteLen(b
);
535 ok(*wireb
== (len
+ 1) / 2, "wv[0] %08x\n", *wireb
);
538 ok(*wireb
== len
, "wv[1] %08x\n", *wireb
);
540 ok(*wireb
== 0xffffffff, "wv[1] %08x\n", *wireb
);
542 ok(*wireb
== (len
+ 1) / 2, "wv[2] %08x\n", *wireb
);
546 ok(!memcmp(wireb
, b
, (len
+ 1) & ~1), "strings differ\n");
551 static void test_marshal_BSTR(void)
555 MIDL_STUB_MESSAGE stub_msg
;
556 USER_MARSHAL_CB umcb
;
557 unsigned char *buffer
, *next
;
559 WCHAR str
[] = {'m','a','r','s','h','a','l',' ','t','e','s','t','1',0};
562 b
= SysAllocString(str
);
563 len
= SysStringLen(b
);
564 ok(len
== 13, "get %d\n", len
);
566 /* BSTRs are DWORD aligned */
568 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
569 size
= BSTR_UserSize(&umcb
.Flags
, 1, &b
);
570 ok(size
== 42, "size %d\n", size
);
572 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
573 size
= BSTR_UserSize(&umcb
.Flags
, 0, &b
);
574 ok(size
== 38, "size %d\n", size
);
576 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
577 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
578 next
= BSTR_UserMarshal(&umcb
.Flags
, buffer
, &b
);
579 ok(next
== buffer
+ size
, "got %p expect %p\n", next
, buffer
+ size
);
580 check_bstr(buffer
, b
);
583 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
584 next
= BSTR_UserUnmarshal(&umcb
.Flags
, buffer
, &b2
);
585 ok(next
== buffer
+ size
, "got %p expect %p\n", next
, buffer
+ size
);
586 ok(b2
!= NULL
, "BSTR didn't unmarshal\n");
587 ok(!memcmp(b
, b2
, (len
+ 1) * 2), "strings differ\n");
588 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
589 BSTR_UserFree(&umcb
.Flags
, &b2
);
591 HeapFree(GetProcessHeap(), 0, buffer
);
595 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
596 size
= BSTR_UserSize(&umcb
.Flags
, 0, &b
);
597 ok(size
== 12, "size %d\n", size
);
599 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
600 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
601 next
= BSTR_UserMarshal(&umcb
.Flags
, buffer
, &b
);
602 ok(next
== buffer
+ size
, "got %p expect %p\n", next
, buffer
+ size
);
604 check_bstr(buffer
, b
);
606 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
607 next
= BSTR_UserUnmarshal(&umcb
.Flags
, buffer
, &b2
);
608 ok(next
== buffer
+ size
, "got %p expect %p\n", next
, buffer
+ size
);
609 ok(b2
== NULL
, "NULL BSTR didn't unmarshal\n");
610 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
611 BSTR_UserFree(&umcb
.Flags
, &b2
);
612 HeapFree(GetProcessHeap(), 0, buffer
);
614 b
= SysAllocStringByteLen("abc", 3);
615 *(((char*)b
) + 3) = 'd';
616 len
= SysStringLen(b
);
617 ok(len
== 1, "get %d\n", len
);
618 len
= SysStringByteLen(b
);
619 ok(len
== 3, "get %d\n", len
);
621 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
622 size
= BSTR_UserSize(&umcb
.Flags
, 0, &b
);
623 ok(size
== 16, "size %d\n", size
);
625 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
626 memset(buffer
, 0xcc, size
);
627 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
628 next
= BSTR_UserMarshal(&umcb
.Flags
, buffer
, &b
);
629 ok(next
== buffer
+ size
, "got %p expect %p\n", next
, buffer
+ size
);
630 check_bstr(buffer
, b
);
631 ok(buffer
[15] == 'd', "buffer[15] %02x\n", buffer
[15]);
634 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
635 next
= BSTR_UserUnmarshal(&umcb
.Flags
, buffer
, &b2
);
636 ok(next
== buffer
+ size
, "got %p expect %p\n", next
, buffer
+ size
);
637 ok(b2
!= NULL
, "BSTR didn't unmarshal\n");
638 ok(!memcmp(b
, b2
, len
), "strings differ\n");
639 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
640 BSTR_UserFree(&umcb
.Flags
, &b2
);
641 HeapFree(GetProcessHeap(), 0, buffer
);
644 b
= SysAllocStringByteLen("", 0);
645 len
= SysStringLen(b
);
646 ok(len
== 0, "get %d\n", len
);
647 len
= SysStringByteLen(b
);
648 ok(len
== 0, "get %d\n", len
);
650 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
651 size
= BSTR_UserSize(&umcb
.Flags
, 0, &b
);
652 ok(size
== 12, "size %d\n", size
);
654 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
655 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
656 next
= BSTR_UserMarshal(&umcb
.Flags
, buffer
, &b
);
657 ok(next
== buffer
+ size
, "got %p expect %p\n", next
, buffer
+ size
);
658 check_bstr(buffer
, b
);
661 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
662 next
= BSTR_UserUnmarshal(&umcb
.Flags
, buffer
, &b2
);
663 ok(next
== buffer
+ size
, "got %p expect %p\n", next
, buffer
+ size
);
664 ok(b2
!= NULL
, "NULL LPSAFEARRAY didn't unmarshal\n");
665 len
= SysStringByteLen(b2
);
666 ok(len
== 0, "byte len %d\n", len
);
667 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
668 BSTR_UserFree(&umcb
.Flags
, &b2
);
669 HeapFree(GetProcessHeap(), 0, buffer
);
675 IUnknown IUnknown_iface
;
679 static inline HeapUnknown
*impl_from_IUnknown(IUnknown
*iface
)
681 return CONTAINING_RECORD(iface
, HeapUnknown
, IUnknown_iface
);
684 static HRESULT WINAPI
HeapUnknown_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
686 if (IsEqualIID(riid
, &IID_IUnknown
))
688 IUnknown_AddRef(iface
);
693 return E_NOINTERFACE
;
696 static ULONG WINAPI
HeapUnknown_AddRef(IUnknown
*iface
)
698 HeapUnknown
*This
= impl_from_IUnknown(iface
);
699 return InterlockedIncrement((LONG
*)&This
->refs
);
702 static ULONG WINAPI
HeapUnknown_Release(IUnknown
*iface
)
704 HeapUnknown
*This
= impl_from_IUnknown(iface
);
705 ULONG refs
= InterlockedDecrement((LONG
*)&This
->refs
);
706 if (!refs
) HeapFree(GetProcessHeap(), 0, This
);
710 static const IUnknownVtbl HeapUnknown_Vtbl
=
712 HeapUnknown_QueryInterface
,
728 static DWORD
*check_variant_header(DWORD
*wirev
, VARIANT
*v
, ULONG size
)
730 const variant_wire_t
*header
= (const variant_wire_t
*)wirev
;
733 ok(header
->clSize
== (size
+ 7) >> 3, "wv[0] %08x, expected %08x\n", header
->clSize
, (size
+ 7) >> 3);
734 ok(header
->rpcReserved
== 0, "wv[1] %08x\n", header
->rpcReserved
);
735 ok(header
->vt
== V_VT(v
), "vt %04x expected %04x\n", header
->vt
, V_VT(v
));
736 ok(header
->wReserved1
== V_U2(v
).wReserved1
, "res1 %04x expected %04x\n", header
->wReserved1
, V_U2(v
).wReserved1
);
737 ok(header
->wReserved2
== V_U2(v
).wReserved2
, "res2 %04x expected %04x\n", header
->wReserved2
, V_U2(v
).wReserved2
);
738 ok(header
->wReserved3
== V_U2(v
).wReserved3
, "res3 %04x expected %04x\n", header
->wReserved3
, V_U2(v
).wReserved3
);
741 if(switch_is
& VT_ARRAY
)
742 switch_is
&= ~VT_TYPEMASK
;
743 ok(header
->switch_is
== switch_is
, "switch_is %08x expected %08x\n", header
->switch_is
, switch_is
);
745 return (DWORD
*)((unsigned char*)wirev
+ sizeof(variant_wire_t
));
748 /* Win9x and WinME don't always align as needed. Variants have
751 static void *alloc_aligned(SIZE_T size
, void **buf
)
753 *buf
= HeapAlloc(GetProcessHeap(), 0, size
+ 7);
754 return (void *)(((UINT_PTR
)*buf
+ 7) & ~7);
757 static void test_marshal_VARIANT(void)
760 MIDL_STUB_MESSAGE stubMsg
= { 0 };
761 RPC_MESSAGE rpcMsg
= { 0 };
762 USER_MARSHAL_CB umcb
= { 0 };
763 unsigned char *buffer
, *next
;
771 WCHAR str
[] = {'m','a','r','s','h','a','l',' ','t','e','s','t',0};
773 LPSAFEARRAY lpsa
, lpsa2
, lpsa_copy
;
775 HeapUnknown
*heap_unknown
;
781 stubMsg
.RpcMsg
= &rpcMsg
;
783 umcb
.Flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
784 umcb
.pStubMsg
= &stubMsg
;
785 umcb
.pReserve
= NULL
;
786 umcb
.Signature
= USER_MARSHAL_CB_SIGNATURE
;
787 umcb
.CBType
= USER_MARSHAL_CB_UNMARSHALL
;
794 /* check_variant_header tests wReserved[123], so initialize to unique values.
795 * (Could probably also do this by setting the variant to a known DECIMAL.)
797 V_U2(&v
).wReserved1
= 0x1234;
798 V_U2(&v
).wReserved2
= 0x5678;
799 V_U2(&v
).wReserved3
= 0x9abc;
801 /* Variants have an alignment of 8 */
802 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 1, &v
);
803 ok(stubMsg
.BufferLength
== 29, "size %d\n", stubMsg
.BufferLength
);
805 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
806 ok(stubMsg
.BufferLength
== 21, "size %d\n", stubMsg
.BufferLength
);
808 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
809 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
810 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
811 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
812 wirev
= (DWORD
*)buffer
;
814 wirev
= check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
815 ok(*(char*)wirev
== V_I1(&v
), "wv[5] %08x\n", *wirev
);
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_I1(&v
) == V_I1(&v2
), "got i1 %x expect %x\n", V_I1(&v
), V_I1(&v2
));
823 VARIANT_UserFree(&umcb
.Flags
, &v2
);
824 HeapFree(GetProcessHeap(), 0, oldbuffer
);
831 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
832 ok(stubMsg
.BufferLength
== 22, "size %d\n", stubMsg
.BufferLength
);
834 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
835 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
836 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
837 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
838 wirev
= (DWORD
*)buffer
;
840 wirev
= check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
841 ok(*(short*)wirev
== V_I2(&v
), "wv[5] %08x\n", *wirev
);
843 stubMsg
.Buffer
= buffer
;
844 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
845 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
846 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
847 ok(V_I2(&v
) == V_I2(&v2
), "got i2 %x expect %x\n", V_I2(&v
), V_I2(&v2
));
849 VARIANT_UserFree(&umcb
.Flags
, &v2
);
850 HeapFree(GetProcessHeap(), 0, oldbuffer
);
854 V_VT(&v
) = VT_I2
| VT_BYREF
;
858 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
859 ok(stubMsg
.BufferLength
== 26, "size %d\n", stubMsg
.BufferLength
);
861 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
862 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
863 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
864 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
865 wirev
= (DWORD
*)buffer
;
867 wirev
= check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
868 ok(*wirev
== 0x4, "wv[5] %08x\n", *wirev
);
870 ok(*(short*)wirev
== s
, "wv[6] %08x\n", *wirev
);
872 V_VT(&v2
) = VT_I2
| VT_BYREF
;
873 V_BYREF(&v2
) = mem
= CoTaskMemAlloc(sizeof(V_I2(&v2
)));
874 stubMsg
.Buffer
= buffer
;
875 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
876 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
877 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
878 ok(V_BYREF(&v2
) == mem
, "didn't reuse existing memory\n");
879 ok(*V_I2REF(&v
) == *V_I2REF(&v2
), "got i2 ref %x expect ui4 ref %x\n", *V_I2REF(&v
), *V_I2REF(&v2
));
881 VARIANT_UserFree(&umcb
.Flags
, &v2
);
882 HeapFree(GetProcessHeap(), 0, oldbuffer
);
889 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
890 ok(stubMsg
.BufferLength
== 24, "size %d\n", stubMsg
.BufferLength
);
892 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
893 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
894 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
895 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
896 wirev
= (DWORD
*)buffer
;
898 wirev
= check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
899 ok(*wirev
== V_I4(&v
), "wv[5] %08x\n", *wirev
);
902 stubMsg
.Buffer
= buffer
;
903 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
904 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
905 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
906 ok(V_I4(&v
) == V_I4(&v2
), "got i4 %x expect %x\n", V_I4(&v
), V_I4(&v2
));
908 VARIANT_UserFree(&umcb
.Flags
, &v2
);
909 HeapFree(GetProcessHeap(), 0, oldbuffer
);
916 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
917 ok(stubMsg
.BufferLength
== 24, "size %d\n", stubMsg
.BufferLength
);
919 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
920 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
921 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
922 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
923 wirev
= (DWORD
*)buffer
;
925 wirev
= check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
926 ok(*wirev
== 0x1234, "wv[5] %08x\n", *wirev
);
928 stubMsg
.Buffer
= buffer
;
929 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
930 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
931 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
932 ok(V_UI4(&v
) == V_UI4(&v2
), "got ui4 %x expect %x\n", V_UI4(&v
), V_UI4(&v2
));
934 VARIANT_UserFree(&umcb
.Flags
, &v2
);
935 HeapFree(GetProcessHeap(), 0, oldbuffer
);
939 V_VT(&v
) = VT_UI4
| VT_BYREF
;
943 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
944 ok(stubMsg
.BufferLength
== 28, "size %d\n", stubMsg
.BufferLength
);
946 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
947 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
948 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
949 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
950 wirev
= (DWORD
*)buffer
;
952 wirev
= check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
953 ok(*wirev
== 0x4, "wv[5] %08x\n", *wirev
);
955 ok(*wirev
== ul
, "wv[6] %08x\n", *wirev
);
958 stubMsg
.Buffer
= buffer
;
959 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
960 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
961 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
962 ok(*V_UI4REF(&v
) == *V_UI4REF(&v2
), "got ui4 ref %x expect ui4 ref %x\n", *V_UI4REF(&v
), *V_UI4REF(&v2
));
964 VARIANT_UserFree(&umcb
.Flags
, &v2
);
965 HeapFree(GetProcessHeap(), 0, oldbuffer
);
972 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
973 ok(stubMsg
.BufferLength
== 24, "size %d\n", stubMsg
.BufferLength
);
975 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
976 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
977 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
978 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
979 wirev
= (DWORD
*)buffer
;
981 wirev
= check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
982 ok(*(float*)wirev
== V_R4(&v
), "wv[5] %08x\n", *wirev
);
984 stubMsg
.Buffer
= buffer
;
985 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
986 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
987 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
988 ok(V_R4(&v
) == V_R4(&v2
), "got r4 %f expect %f\n", V_R4(&v
), V_R4(&v2
));
990 VARIANT_UserFree(&umcb
.Flags
, &v2
);
991 HeapFree(GetProcessHeap(), 0, oldbuffer
);
998 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
999 ok(stubMsg
.BufferLength
== 32, "size %d\n", stubMsg
.BufferLength
);
1001 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1002 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1003 memset(buffer
, 0xcc, stubMsg
.BufferLength
);
1004 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1005 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1006 wirev
= (DWORD
*)buffer
;
1008 wirev
= check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
1009 ok(*wirev
== 0xcccccccc, "wv[5] %08x\n", *wirev
); /* pad */
1011 ok(*(double*)wirev
== V_R8(&v
), "wv[6] %08x, wv[7] %08x\n", *wirev
, *(wirev
+1));
1013 stubMsg
.Buffer
= buffer
;
1014 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1015 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1016 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1017 ok(V_R8(&v
) == V_R8(&v2
), "got r8 %f expect %f\n", V_R8(&v
), V_R8(&v2
));
1019 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1020 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1024 V_VT(&v
) = VT_R8
| VT_BYREF
;
1028 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1029 ok(stubMsg
.BufferLength
== 32, "size %d\n", stubMsg
.BufferLength
);
1031 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1032 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1033 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1034 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1035 wirev
= (DWORD
*)buffer
;
1037 wirev
= check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
1038 ok(*wirev
== 8, "wv[5] %08x\n", *wirev
);
1040 ok(*(double*)wirev
== d
, "wv[6] %08x wv[7] %08x\n", *wirev
, *(wirev
+1));
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(*V_R8REF(&v
) == *V_R8REF(&v2
), "got r8 ref %f expect %f\n", *V_R8REF(&v
), *V_R8REF(&v2
));
1048 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1049 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1051 /*** VARIANT_BOOL ***/
1054 V_BOOL(&v
) = 0x1234;
1056 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1057 ok(stubMsg
.BufferLength
== 22, "size %d\n", stubMsg
.BufferLength
);
1059 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1060 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1061 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1062 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1063 wirev
= (DWORD
*)buffer
;
1065 wirev
= check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
1066 ok(*(short*)wirev
== V_BOOL(&v
), "wv[5] %04x\n", *(WORD
*)wirev
);
1068 stubMsg
.Buffer
= buffer
;
1069 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1070 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1071 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1072 ok(V_BOOL(&v
) == V_BOOL(&v2
), "got bool %x expect %x\n", V_BOOL(&v
), V_BOOL(&v2
));
1074 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1075 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1078 VarDecFromI4(0x12345678, &dec
);
1079 dec
.wReserved
= 0xfedc; /* Also initialize reserved field, as we check it later */
1081 V_DECIMAL(&v
) = dec
;
1082 V_VT(&v
) = VT_DECIMAL
;
1084 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1085 ok(stubMsg
.BufferLength
== 40, "size %d\n", stubMsg
.BufferLength
);
1087 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1088 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1089 memset(buffer
, 0xcc, stubMsg
.BufferLength
);
1090 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1091 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1092 wirev
= (DWORD
*)buffer
;
1094 wirev
= check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
1095 ok(*wirev
== 0xcccccccc, "wirev[5] %08x\n", *wirev
); /* pad */
1098 dec2
.wReserved
= VT_DECIMAL
;
1099 ok(!memcmp(wirev
, &dec2
, sizeof(dec2
)), "wirev[6] %08x wirev[7] %08x wirev[8] %08x wirev[9] %08x\n",
1100 *wirev
, *(wirev
+ 1), *(wirev
+ 2), *(wirev
+ 3));
1102 stubMsg
.Buffer
= buffer
;
1103 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1104 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1105 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1106 ok(!memcmp(&V_DECIMAL(&v
), & V_DECIMAL(&v2
), sizeof(DECIMAL
)), "decimals differ\n");
1108 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1109 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1111 /*** DECIMAL BYREF ***/
1113 V_VT(&v
) = VT_DECIMAL
| VT_BYREF
;
1114 V_DECIMALREF(&v
) = &dec
;
1116 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1117 ok(stubMsg
.BufferLength
== 40, "size %d\n", stubMsg
.BufferLength
);
1119 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1120 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1121 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1122 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1123 wirev
= (DWORD
*)buffer
;
1125 wirev
= check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
1126 ok(*wirev
== 16, "wv[5] %08x\n", *wirev
);
1128 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));
1130 /* check_variant_header tests wReserved[123], so initialize to unique values.
1131 * (Could probably also do this by setting the variant to a known DECIMAL.)
1133 V_U2(&v2
).wReserved1
= 0x0123;
1134 V_U2(&v2
).wReserved2
= 0x4567;
1135 V_U2(&v2
).wReserved3
= 0x89ab;
1137 stubMsg
.Buffer
= buffer
;
1138 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1139 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1140 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1141 ok(!memcmp(V_DECIMALREF(&v
), V_DECIMALREF(&v2
), sizeof(DECIMAL
)), "decimals differ\n");
1143 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1144 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1148 V_VT(&v
) = VT_EMPTY
;
1150 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1151 ok(stubMsg
.BufferLength
== 20, "size %d\n", stubMsg
.BufferLength
);
1153 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1154 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1155 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1156 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1157 wirev
= (DWORD
*)buffer
;
1159 check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
1161 stubMsg
.Buffer
= buffer
;
1162 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1163 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1164 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1166 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1167 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1173 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1174 ok(stubMsg
.BufferLength
== 20, "size %d\n", stubMsg
.BufferLength
);
1176 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1177 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1178 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1179 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1180 wirev
= (DWORD
*)buffer
;
1182 check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
1184 stubMsg
.Buffer
= buffer
;
1185 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1186 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1187 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1189 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1190 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1193 b
= SysAllocString(str
);
1198 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1199 ok(stubMsg
.BufferLength
== 60, "size %d\n", stubMsg
.BufferLength
);
1200 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1201 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1202 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1203 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1204 wirev
= (DWORD
*)buffer
;
1206 wirev
= check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
1207 ok(*wirev
, "wv[5] %08x\n", *wirev
); /* win2k: this is b. winxp: this is (char*)b + 1 */
1209 check_bstr(wirev
, V_BSTR(&v
));
1211 stubMsg
.Buffer
= buffer
;
1212 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1213 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1214 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1215 ok(SysStringByteLen(V_BSTR(&v
)) == SysStringByteLen(V_BSTR(&v2
)), "bstr string lens differ\n");
1216 ok(!memcmp(V_BSTR(&v
), V_BSTR(&v2
), SysStringByteLen(V_BSTR(&v
))), "bstrs differ\n");
1218 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1219 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1221 /*** BSTR BYREF ***/
1223 V_VT(&v
) = VT_BSTR
| VT_BYREF
;
1226 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1227 ok(stubMsg
.BufferLength
== 64, "size %d\n", stubMsg
.BufferLength
);
1228 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1229 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1230 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1231 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1232 wirev
= (DWORD
*)buffer
;
1234 wirev
= check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
1235 ok(*wirev
== 0x4, "wv[5] %08x\n", *wirev
);
1237 ok(*wirev
, "wv[6] %08x\n", *wirev
); /* win2k: this is b. winxp: this is (char*)b + 1 */
1239 check_bstr(wirev
, b
);
1240 b2
= SysAllocString(str
);
1242 V_VT(&v2
) = VT_BSTR
| VT_BYREF
;
1243 V_BSTRREF(&v2
) = &b2
;
1246 stubMsg
.Buffer
= buffer
;
1247 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1248 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1249 ok(mem
== b2
, "BSTR should be reused\n");
1250 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1251 ok(SysStringByteLen(*V_BSTRREF(&v
)) == SysStringByteLen(*V_BSTRREF(&v2
)), "bstr string lens differ\n");
1252 ok(!memcmp(*V_BSTRREF(&v
), *V_BSTRREF(&v2
), SysStringByteLen(*V_BSTRREF(&v
))), "bstrs differ\n");
1255 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1262 lpsa
= SafeArrayCreate(VT_R8
, 1, &sab
);
1263 *(DWORD
*)lpsa
->pvData
= 0xcafebabe;
1264 *((DWORD
*)lpsa
->pvData
+ 1) = 0xdeadbeef;
1267 V_VT(&v
) = VT_UI4
| VT_ARRAY
;
1270 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1272 ok(stubMsg
.BufferLength
== expected
|| stubMsg
.BufferLength
== expected
+ 8, /* win64 */
1273 "size %u instead of %u\n", stubMsg
.BufferLength
, expected
);
1274 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1275 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1276 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1277 ok(next
== buffer
+ expected
, "got %p expect %p\n", next
, buffer
+ expected
);
1278 wirev
= (DWORD
*)buffer
;
1280 wirev
= check_variant_header(wirev
, &v
, expected
);
1281 ok(*wirev
, "wv[5] %08x\n", *wirev
); /* win2k: this is lpsa. winxp: this is (char*)lpsa + 1 */
1283 check_safearray(wirev
, lpsa
);
1285 stubMsg
.Buffer
= buffer
;
1286 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1287 ok(next
== buffer
+ expected
, "got %p expect %p\n", next
, buffer
+ expected
);
1288 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1289 ok(SafeArrayGetDim(V_ARRAY(&v
)) == SafeArrayGetDim(V_ARRAY(&v2
)), "array dims differ\n");
1290 SafeArrayGetLBound(V_ARRAY(&v
), 1, &bound
);
1291 SafeArrayGetLBound(V_ARRAY(&v2
), 1, &bound2
);
1292 ok(bound
== bound2
, "array lbounds differ\n");
1293 SafeArrayGetUBound(V_ARRAY(&v
), 1, &bound
);
1294 SafeArrayGetUBound(V_ARRAY(&v2
), 1, &bound2
);
1295 ok(bound
== bound2
, "array ubounds differ\n");
1296 if (pSafeArrayGetVartype
)
1298 pSafeArrayGetVartype(V_ARRAY(&v
), &vt
);
1299 pSafeArrayGetVartype(V_ARRAY(&v2
), &vt2
);
1300 ok(vt
== vt2
, "array vts differ %x %x\n", vt
, vt2
);
1302 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1303 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1305 /*** ARRAY BYREF ***/
1307 V_VT(&v
) = VT_UI4
| VT_ARRAY
| VT_BYREF
;
1308 V_ARRAYREF(&v
) = &lpsa
;
1310 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1312 ok(stubMsg
.BufferLength
== expected
|| stubMsg
.BufferLength
== expected
+ 16, /* win64 */
1313 "size %u instead of %u\n", stubMsg
.BufferLength
, expected
);
1314 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1315 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1316 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1317 ok(next
== buffer
+ expected
, "got %p expect %p\n", next
, buffer
+ expected
);
1318 wirev
= (DWORD
*)buffer
;
1320 wirev
= check_variant_header(wirev
, &v
, expected
);
1321 ok(*wirev
== 4, "wv[5] %08x\n", *wirev
);
1323 ok(*wirev
, "wv[6] %08x\n", *wirev
); /* win2k: this is lpsa. winxp: this is (char*)lpsa + 1 */
1325 check_safearray(wirev
, lpsa
);
1327 stubMsg
.Buffer
= buffer
;
1328 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1329 ok(next
== buffer
+ expected
, "got %p expect %p\n", next
, buffer
+ expected
);
1330 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1331 ok(SafeArrayGetDim(*V_ARRAYREF(&v
)) == SafeArrayGetDim(*V_ARRAYREF(&v2
)), "array dims differ\n");
1332 SafeArrayGetLBound(*V_ARRAYREF(&v
), 1, &bound
);
1333 SafeArrayGetLBound(*V_ARRAYREF(&v2
), 1, &bound2
);
1334 ok(bound
== bound2
, "array lbounds differ\n");
1335 SafeArrayGetUBound(*V_ARRAYREF(&v
), 1, &bound
);
1336 SafeArrayGetUBound(*V_ARRAYREF(&v2
), 1, &bound2
);
1337 ok(bound
== bound2
, "array ubounds differ\n");
1338 if (pSafeArrayGetVartype
)
1340 pSafeArrayGetVartype(*V_ARRAYREF(&v
), &vt
);
1341 pSafeArrayGetVartype(*V_ARRAYREF(&v2
), &vt2
);
1342 ok(vt
== vt2
, "array vts differ %x %x\n", vt
, vt2
);
1344 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1345 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1347 /*** ARRAY BYREF ***/
1349 V_VT(&v
) = VT_UI4
| VT_ARRAY
| VT_BYREF
;
1350 V_ARRAYREF(&v
) = &lpsa
;
1351 lpsa
->fFeatures
|= FADF_STATIC
;
1353 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1355 ok(stubMsg
.BufferLength
== expected
|| stubMsg
.BufferLength
== expected
+ 16, /* win64 */
1356 "size %u instead of %u\n", stubMsg
.BufferLength
, expected
);
1357 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1358 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1359 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1360 ok(next
== buffer
+ expected
, "got %p expect %p\n", next
, buffer
+ expected
);
1361 wirev
= (DWORD
*)buffer
;
1363 wirev
= check_variant_header(wirev
, &v
, expected
);
1364 ok(*wirev
== 4, "wv[5] %08x\n", *wirev
);
1366 ok(*wirev
, "wv[6] %08x\n", *wirev
); /* win2k: this is lpsa. winxp: this is (char*)lpsa + 1 */
1368 check_safearray(wirev
, lpsa
);
1369 lpsa_copy
= lpsa2
= SafeArrayCreate(VT_I8
, 1, &sab
);
1370 /* set FADF_STATIC feature to make sure lpsa2->pvData pointer changes if new data buffer is allocated */
1371 lpsa2
->fFeatures
|= FADF_STATIC
;
1372 mem
= lpsa2
->pvData
;
1373 V_VT(&v2
) = VT_UI4
| VT_ARRAY
| VT_BYREF
;
1374 V_ARRAYREF(&v2
) = &lpsa2
;
1375 stubMsg
.Buffer
= buffer
;
1376 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1377 ok(next
== buffer
+ expected
, "got %p expect %p\n", next
, buffer
+ expected
);
1378 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1379 ok(lpsa2
== lpsa_copy
, "safearray should be reused\n");
1380 ok(mem
== lpsa2
->pvData
, "safearray data should be reused\n");
1381 ok(SafeArrayGetDim(*V_ARRAYREF(&v
)) == SafeArrayGetDim(*V_ARRAYREF(&v2
)), "array dims differ\n");
1382 SafeArrayGetLBound(*V_ARRAYREF(&v
), 1, &bound
);
1383 SafeArrayGetLBound(*V_ARRAYREF(&v2
), 1, &bound2
);
1384 ok(bound
== bound2
, "array lbounds differ\n");
1385 SafeArrayGetUBound(*V_ARRAYREF(&v
), 1, &bound
);
1386 SafeArrayGetUBound(*V_ARRAYREF(&v2
), 1, &bound2
);
1387 ok(bound
== bound2
, "array ubounds differ\n");
1388 if (pSafeArrayGetVartype
)
1390 pSafeArrayGetVartype(*V_ARRAYREF(&v
), &vt
);
1391 pSafeArrayGetVartype(*V_ARRAYREF(&v2
), &vt2
);
1392 ok(vt
== vt2
, "array vts differ %x %x\n", vt
, vt2
);
1394 lpsa2
->fFeatures
&= ~FADF_STATIC
;
1395 hr
= SafeArrayDestroy(*V_ARRAYREF(&v2
));
1396 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1397 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1398 lpsa
->fFeatures
&= ~FADF_STATIC
;
1399 hr
= SafeArrayDestroy(lpsa
);
1400 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1402 /*** VARIANT BYREF ***/
1407 V_VT(&v
) = VT_VARIANT
| VT_BYREF
;
1408 V_VARIANTREF(&v
) = &v2
;
1410 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1411 ok(stubMsg
.BufferLength
== 64, "size %d\n", stubMsg
.BufferLength
);
1412 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1413 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1414 memset(buffer
, 0xcc, stubMsg
.BufferLength
);
1415 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1416 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1417 wirev
= (DWORD
*)buffer
;
1418 wirev
= check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
1420 ok(*wirev
== sizeof(VARIANT
), "wv[5] %08x\n", *wirev
);
1422 ok(*wirev
== ('U' | 's' << 8 | 'e' << 16 | 'r' << 24), "wv[6] %08x\n", *wirev
); /* 'User' */
1424 ok(*wirev
== 0xcccccccc, "wv[7] %08x\n", *wirev
); /* pad */
1426 wirev
= check_variant_header(wirev
, &v2
, stubMsg
.BufferLength
- 32);
1427 ok(*wirev
== 0xcccccccc, "wv[13] %08x\n", *wirev
); /* pad for VT_R8 */
1429 ok(*(double*)wirev
== V_R8(&v2
), "wv[6] %08x wv[7] %08x\n", *wirev
, *(wirev
+1));
1431 stubMsg
.Buffer
= buffer
;
1432 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v3
);
1433 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1434 ok(V_VT(&v
) == V_VT(&v3
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v3
));
1435 ok(V_VT(V_VARIANTREF(&v
)) == V_VT(V_VARIANTREF(&v3
)), "vts differ %x %x\n",
1436 V_VT(V_VARIANTREF(&v
)), V_VT(V_VARIANTREF(&v3
)));
1437 ok(V_R8(V_VARIANTREF(&v
)) == V_R8(V_VARIANTREF(&v3
)), "r8s differ\n");
1438 VARIANT_UserFree(&umcb
.Flags
, &v3
);
1439 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1442 heap_unknown
= HeapAlloc(GetProcessHeap(), 0, sizeof(*heap_unknown
));
1443 heap_unknown
->IUnknown_iface
.lpVtbl
= &HeapUnknown_Vtbl
;
1444 heap_unknown
->refs
= 1;
1447 V_VT(&v
) = VT_UNKNOWN
;
1448 V_UNKNOWN(&v
) = &heap_unknown
->IUnknown_iface
;
1450 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1451 ok(stubMsg
.BufferLength
> 40, "size %d\n", stubMsg
.BufferLength
);
1452 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1453 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1454 memset(buffer
, 0xcc, stubMsg
.BufferLength
);
1455 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1457 ok(heap_unknown
->refs
== 2, "got refcount %d\n", heap_unknown
->refs
);
1458 wirev
= (DWORD
*)buffer
;
1459 wirev
= check_variant_header(wirev
, &v
, next
- buffer
);
1461 ok(*wirev
== (DWORD_PTR
)V_UNKNOWN(&v
) /* Win9x */ ||
1462 *wirev
== (DWORD_PTR
)V_UNKNOWN(&v
) + 1 /* NT */, "wv[5] %08x\n", *wirev
);
1464 ok(*wirev
== next
- buffer
- 0x20, "wv[6] %08x\n", *wirev
);
1466 ok(*wirev
== next
- buffer
- 0x20, "wv[7] %08x\n", *wirev
);
1468 ok(*wirev
== 0x574f454d, "wv[8] %08x\n", *wirev
);
1470 V_VT(&v3
) = VT_UNKNOWN
;
1471 V_UNKNOWN(&v3
) = &heap_unknown
->IUnknown_iface
;
1472 IUnknown_AddRef(V_UNKNOWN(&v3
));
1473 stubMsg
.Buffer
= buffer
;
1475 ok(heap_unknown
->refs
== 3, "got refcount %d\n", heap_unknown
->refs
);
1476 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v3
);
1477 ok(V_VT(&v
) == V_VT(&v3
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v3
));
1478 ok(V_UNKNOWN(&v
) == V_UNKNOWN(&v3
), "got %p expect %p\n", V_UNKNOWN(&v
), V_UNKNOWN(&v3
));
1479 VARIANT_UserFree(&umcb
.Flags
, &v3
);
1480 ok(heap_unknown
->refs
== 1, "%d refcounts of IUnknown leaked\n", heap_unknown
->refs
- 1);
1481 IUnknown_Release(&heap_unknown
->IUnknown_iface
);
1482 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1484 /*** NULL UNKNOWN ***/
1486 V_VT(&v
) = VT_UNKNOWN
;
1487 V_UNKNOWN(&v
) = NULL
;
1489 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1490 ok(stubMsg
.BufferLength
>= 24, "size %d\n", stubMsg
.BufferLength
);
1491 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1492 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1493 memset(buffer
, 0xcc, stubMsg
.BufferLength
);
1494 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1495 wirev
= (DWORD
*)buffer
;
1496 wirev
= check_variant_header(wirev
, &v
, next
- buffer
);
1497 ok(*wirev
== 0, "wv[5] %08x\n", *wirev
);
1500 stubMsg
.Buffer
= buffer
;
1501 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1502 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1503 ok(V_UNKNOWN(&v2
) == NULL
, "got %p expect NULL\n", V_UNKNOWN(&v2
));
1504 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1505 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1507 /*** UNKNOWN BYREF ***/
1508 heap_unknown
= HeapAlloc(GetProcessHeap(), 0, sizeof(*heap_unknown
));
1509 heap_unknown
->IUnknown_iface
.lpVtbl
= &HeapUnknown_Vtbl
;
1510 heap_unknown
->refs
= 1;
1513 V_VT(&v
) = VT_UNKNOWN
| VT_BYREF
;
1514 V_UNKNOWNREF(&v
) = (IUnknown
**)&heap_unknown
;
1516 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1517 ok(stubMsg
.BufferLength
>= 44, "size %d\n", stubMsg
.BufferLength
);
1518 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1519 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1520 memset(buffer
, 0xcc, stubMsg
.BufferLength
);
1521 ok(heap_unknown
->refs
== 1, "got refcount %d\n", heap_unknown
->refs
);
1522 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1524 ok(heap_unknown
->refs
== 2, "got refcount %d\n", heap_unknown
->refs
);
1525 wirev
= (DWORD
*)buffer
;
1526 wirev
= check_variant_header(wirev
, &v
, next
- buffer
);
1528 ok(*wirev
== 4, "wv[5] %08x\n", *wirev
);
1530 ok(*wirev
== (DWORD_PTR
)heap_unknown
/* Win9x, Win2000 */ ||
1531 *wirev
== (DWORD_PTR
)heap_unknown
+ 1 /* XP */, "wv[6] %08x\n", *wirev
);
1533 ok(*wirev
== next
- buffer
- 0x24, "wv[7] %08x\n", *wirev
);
1535 ok(*wirev
== next
- buffer
- 0x24, "wv[8] %08x\n", *wirev
);
1537 ok(*wirev
== 0x574f454d, "wv[9] %08x\n", *wirev
);
1540 V_VT(&v3
) = VT_UNKNOWN
;
1541 V_UNKNOWN(&v3
) = &heap_unknown
->IUnknown_iface
;
1542 IUnknown_AddRef(V_UNKNOWN(&v3
));
1543 stubMsg
.Buffer
= buffer
;
1544 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v3
);
1545 ok(heap_unknown
->refs
== 2, "got refcount %d\n", heap_unknown
->refs
);
1546 ok(V_VT(&v
) == V_VT(&v3
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v3
));
1547 ok(*V_UNKNOWNREF(&v
) == *V_UNKNOWNREF(&v3
), "got %p expect %p\n", *V_UNKNOWNREF(&v
), *V_UNKNOWNREF(&v3
));
1548 VARIANT_UserFree(&umcb
.Flags
, &v3
);
1549 ok(heap_unknown
->refs
== 1, "%d refcounts of IUnknown leaked\n", heap_unknown
->refs
- 1);
1550 IUnknown_Release(&heap_unknown
->IUnknown_iface
);
1551 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1555 START_TEST(usrmarshal
)
1557 HANDLE hOleaut32
= GetModuleHandleA("oleaut32.dll");
1558 #define GETPTR(func) p##func = (void*)GetProcAddress(hOleaut32, #func)
1559 GETPTR(SafeArrayGetIID
);
1560 GETPTR(SafeArrayGetVartype
);
1564 if (!pSafeArrayGetIID
|| !pSafeArrayGetVartype
)
1565 win_skip("SafeArrayGetIID and/or SafeArrayGetVartype is not available, some tests will be skipped\n");
1569 test_marshal_LPSAFEARRAY();
1570 test_marshal_BSTR();
1571 test_marshal_VARIANT();