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 return CoTaskMemAlloc(size
);
196 static void WINAPI
user_free(void *p
)
201 static void init_user_marshal_cb(USER_MARSHAL_CB
*umcb
,
202 PMIDL_STUB_MESSAGE stub_msg
,
203 PRPC_MESSAGE rpc_msg
, unsigned char *buffer
,
204 unsigned int size
, MSHCTX context
)
206 memset(rpc_msg
, 0, sizeof(*rpc_msg
));
207 rpc_msg
->Buffer
= buffer
;
208 rpc_msg
->BufferLength
= size
;
210 memset(stub_msg
, 0, sizeof(*stub_msg
));
211 stub_msg
->RpcMsg
= rpc_msg
;
212 stub_msg
->Buffer
= buffer
;
213 stub_msg
->pfnAllocate
= user_allocate
;
214 stub_msg
->pfnFree
= user_free
;
216 memset(umcb
, 0, sizeof(*umcb
));
217 umcb
->Flags
= MAKELONG(context
, NDR_LOCAL_DATA_REPRESENTATION
);
218 umcb
->pStubMsg
= stub_msg
;
219 umcb
->Signature
= USER_MARSHAL_CB_SIGNATURE
;
220 umcb
->CBType
= buffer
? USER_MARSHAL_CB_UNMARSHALL
: USER_MARSHAL_CB_BUFFER_SIZE
;
223 static void test_marshal_LPSAFEARRAY(void)
225 unsigned char *buffer
, *next
;
226 ULONG size
, expected
;
228 LPSAFEARRAY lpsa2
= NULL
;
229 SAFEARRAYBOUND sab
[2];
231 MIDL_STUB_MESSAGE stub_msg
;
232 USER_MARSHAL_CB umcb
;
236 int expected_bstr_size
;
241 sab
[0].cElements
= 10;
243 lpsa
= SafeArrayCreate(VT_I2
, 1, sab
);
244 *(DWORD
*)lpsa
->pvData
= 0xcafebabe;
247 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
248 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 1, &lpsa
);
249 expected
= (44 + 1 + sizeof(ULONG
) - 1) & ~(sizeof(ULONG
) - 1);
250 expected
+= sab
[0].cElements
* sizeof(USHORT
);
251 ok(size
== expected
|| size
== expected
+ 12, /* win64 */
252 "size should be %u bytes, not %u\n", expected
, size
);
253 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
254 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 0, &lpsa
);
255 expected
= 44 + sab
[0].cElements
* sizeof(USHORT
);
256 ok(size
== expected
|| size
== expected
+ 12, /* win64 */
257 "size should be %u bytes, not %u\n", expected
, size
);
258 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
259 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
260 next
= LPSAFEARRAY_UserMarshal(&umcb
.Flags
, buffer
, &lpsa
);
261 ok(next
- buffer
== expected
, "Marshaled %u bytes, expected %u\n", (ULONG
) (next
- buffer
), expected
);
262 ok(lpsa
->cLocks
== 7, "got lock count %u\n", lpsa
->cLocks
);
264 check_safearray(buffer
, lpsa
);
266 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
267 LPSAFEARRAY_UserUnmarshal(&umcb
.Flags
, buffer
, &lpsa2
);
268 ok(lpsa2
!= NULL
, "LPSAFEARRAY didn't unmarshal\n");
269 if (pSafeArrayGetVartype
)
271 pSafeArrayGetVartype(lpsa
, &vt
);
272 pSafeArrayGetVartype(lpsa2
, &vt2
);
273 ok(vt
== vt2
, "vts differ %x %x\n", vt
, vt2
);
275 ok(lpsa2
->cLocks
== 0, "got lock count %u, expected 0\n", lpsa2
->cLocks
);
276 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
277 LPSAFEARRAY_UserFree(&umcb
.Flags
, &lpsa2
);
278 HeapFree(GetProcessHeap(), 0, buffer
);
280 hr
= SafeArrayDestroy(lpsa
);
281 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
283 /* use two dimensions */
285 sab
[0].cElements
= 10;
287 sab
[1].cElements
= 2;
289 lpsa
= SafeArrayCreate(VT_I2
, 2, sab
);
290 *(DWORD
*)lpsa
->pvData
= 0xcafebabe;
293 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
294 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 1, &lpsa
);
295 expected
= (44 + 1 + +sizeof(SAFEARRAYBOUND
) + sizeof(ULONG
) - 1) & ~(sizeof(ULONG
) - 1);
296 expected
+= max(sab
[0].cElements
, sab
[1].cElements
) * lpsa
->cDims
* sizeof(USHORT
);
297 ok(size
== expected
|| size
== expected
+ 12, /* win64 */
298 "size should be %u bytes, not %u\n", expected
, size
);
299 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
300 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 0, &lpsa
);
301 expected
= 52 + max(sab
[0].cElements
, sab
[1].cElements
) * lpsa
->cDims
* sizeof(USHORT
);
302 ok(size
== expected
|| size
== expected
+ 12, /* win64 */
303 "size should be %u bytes, not %u\n", expected
, size
);
304 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
305 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
306 next
= LPSAFEARRAY_UserMarshal(&umcb
.Flags
, buffer
, &lpsa
);
307 ok(next
- buffer
== expected
, "Marshaled %u bytes, expected %u\n", (ULONG
) (next
- buffer
), expected
);
308 ok(lpsa
->cLocks
== 7, "got lock count %u\n", lpsa
->cLocks
);
310 check_safearray(buffer
, lpsa
);
312 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
313 LPSAFEARRAY_UserUnmarshal(&umcb
.Flags
, buffer
, &lpsa2
);
314 ok(lpsa2
!= NULL
, "LPSAFEARRAY didn't unmarshal\n");
315 if (pSafeArrayGetVartype
)
317 pSafeArrayGetVartype(lpsa
, &vt
);
318 pSafeArrayGetVartype(lpsa2
, &vt2
);
319 ok(vt
== vt2
, "vts differ %x %x\n", vt
, vt2
);
321 ok(lpsa2
->cLocks
== 0, "got lock count %u, expected 0\n", lpsa2
->cLocks
);
322 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
323 LPSAFEARRAY_UserFree(&umcb
.Flags
, &lpsa2
);
324 HeapFree(GetProcessHeap(), 0, buffer
);
326 hr
= SafeArrayDestroy(lpsa
);
327 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
329 /* test NULL safe array */
332 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
333 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 0, &lpsa
);
335 ok(size
== expected
, "size should be 4 bytes, not %d\n", size
);
336 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
337 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
338 next
= LPSAFEARRAY_UserMarshal(&umcb
.Flags
, buffer
, &lpsa
);
339 ok(next
- buffer
== expected
, "Marshaled %u bytes, expected %u\n", (ULONG
) (next
- buffer
), expected
);
340 check_safearray(buffer
, lpsa
);
342 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
343 LPSAFEARRAY_UserUnmarshal(&umcb
.Flags
, buffer
, &lpsa2
);
344 ok(lpsa2
== NULL
, "NULL LPSAFEARRAY didn't unmarshal\n");
345 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
346 LPSAFEARRAY_UserFree(&umcb
.Flags
, &lpsa2
);
347 HeapFree(GetProcessHeap(), 0, buffer
);
350 sab
[0].cElements
= 10;
352 lpsa
= SafeArrayCreate(VT_R8
, 1, sab
);
353 *(double *)lpsa
->pvData
= 3.1415;
356 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
357 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 1, &lpsa
);
358 expected
= (44 + 1 + (sizeof(double) - 1)) & ~(sizeof(double) - 1);
359 expected
+= sab
[0].cElements
* sizeof(double);
360 ok(size
== expected
|| size
== expected
+ 16, /* win64 */
361 "size should be %u bytes, not %u\n", expected
, size
);
362 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
363 expected
= (44 + (sizeof(double) - 1)) & ~(sizeof(double) - 1);
364 expected
+= sab
[0].cElements
* sizeof(double);
365 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 0, &lpsa
);
366 ok(size
== expected
|| size
== expected
+ 8, /* win64 */
367 "size should be %u bytes, not %u\n", expected
, size
);
368 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
369 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
370 next
= LPSAFEARRAY_UserMarshal(&umcb
.Flags
, buffer
, &lpsa
);
371 ok(next
- buffer
== expected
|| broken(next
- buffer
+ sizeof(DWORD
) == expected
),
372 "Marshaled %u bytes, expected %u\n", (ULONG
) (next
- buffer
), expected
);
374 check_safearray(buffer
, lpsa
);
376 HeapFree(GetProcessHeap(), 0, buffer
);
378 hr
= SafeArrayDestroy(lpsa
);
379 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
381 /* VARTYPE-less arrays can be marshaled if cbElements is 1,2,4 or 8 as type SF_In */
382 hr
= SafeArrayAllocDescriptor(1, &lpsa
);
383 ok(hr
== S_OK
, "saad failed %08x\n", hr
);
384 lpsa
->cbElements
= 8;
385 lpsa
->rgsabound
[0].lLbound
= 2;
386 lpsa
->rgsabound
[0].cElements
= 48;
387 hr
= SafeArrayAllocData(lpsa
);
388 ok(hr
== S_OK
, "saad failed %08x\n", hr
);
390 if (pSafeArrayGetVartype
)
392 hr
= pSafeArrayGetVartype(lpsa
, &vt
);
393 ok(hr
== E_INVALIDARG
, "ret %08x\n", hr
);
396 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
397 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 0, &lpsa
);
398 expected
= (44 + lpsa
->cbElements
- 1) & ~(lpsa
->cbElements
- 1);
399 expected
+= lpsa
->cbElements
* lpsa
->rgsabound
[0].cElements
;
400 ok(size
== expected
|| size
== expected
+ 8, /* win64 */
401 "size should be %u bytes, not %u\n", expected
, size
);
402 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
403 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
404 next
= LPSAFEARRAY_UserMarshal(&umcb
.Flags
, buffer
, &lpsa
);
405 ok(next
- buffer
== expected
|| broken(next
- buffer
+ sizeof(DWORD
) == expected
),
406 "Marshaled %u bytes, expected %u\n", (ULONG
) (next
- buffer
), expected
);
407 check_safearray(buffer
, lpsa
);
408 HeapFree(GetProcessHeap(), 0, buffer
);
409 hr
= SafeArrayDestroyData(lpsa
);
410 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
411 hr
= SafeArrayDestroyDescriptor(lpsa
);
412 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
414 /* Test an array of VT_BSTR */
416 sab
[0].cElements
= sizeof(values
) / sizeof(values
[0]);
418 lpsa
= SafeArrayCreate(VT_BSTR
, 1, sab
);
419 expected_bstr_size
= 0;
420 for (i
= 0; i
< sab
[0].cElements
; i
++)
424 for (j
= 0; j
<= i
; j
++)
427 indices
[0] = i
+ sab
[0].lLbound
;
428 values
[i
] = SysAllocString(buf
);
429 hr
= SafeArrayPutElement(lpsa
, indices
, values
[i
]);
430 ok(hr
== S_OK
, "Failed to put bstr element hr 0x%x\n", hr
);
431 expected_bstr_size
+= (j
* sizeof(WCHAR
)) + (3 * sizeof(DWORD
));
432 if (i
% 2 == 0) /* Account for DWORD padding. Works so long as cElements is even */
433 expected_bstr_size
+= sizeof(WCHAR
);
436 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
437 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 1, &lpsa
);
438 expected
= 44 + (sab
[0].cElements
* sizeof(DWORD
)) + expected_bstr_size
;
440 ok(size
== expected
+ sizeof(DWORD
) || size
== (expected
+ sizeof(DWORD
) + 12 /* win64 */),
441 "size should be %u bytes, not %u\n", expected
+ (ULONG
) sizeof(DWORD
), size
);
442 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
443 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 0, &lpsa
);
445 ok(size
== expected
|| size
== (expected
+ 12 /* win64 */),
446 "size should be %u bytes, not %u\n", expected
, size
);
447 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
448 memset(buffer
, 0xcc, size
);
449 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
450 next
= LPSAFEARRAY_UserMarshal(&umcb
.Flags
, buffer
, &lpsa
);
452 ok(next
- buffer
== expected
, "Marshaled %u bytes, expected %u\n", (ULONG
) (next
- buffer
), expected
);
454 check_safearray(buffer
, lpsa
);
457 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
458 next
= LPSAFEARRAY_UserUnmarshal(&umcb
.Flags
, buffer
, &lpsa2
);
460 ok(next
- buffer
== expected
, "Marshaled %u bytes, expected %u\n", (ULONG
) (next
- buffer
), expected
);
461 ok(lpsa2
!= NULL
, "LPSAFEARRAY didn't unmarshal, result %p\n", next
);
463 for (i
= 0; i
< sizeof(values
) / sizeof(values
[0]); i
++)
465 BSTR gotvalue
= NULL
;
469 indices
[0] = i
+ sab
[0].lLbound
;
470 hr
= SafeArrayGetElement(lpsa2
, indices
, &gotvalue
);
471 ok(hr
== S_OK
, "Failed to get bstr element at hres 0x%x\n", hr
);
475 ok(pVarBstrCmp(values
[i
], gotvalue
, 0, 0) == VARCMP_EQ
, "String %d does not match\n", i
);
476 SysFreeString(gotvalue
);
480 SysFreeString(values
[i
]);
483 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
484 LPSAFEARRAY_UserFree(&umcb
.Flags
, &lpsa2
);
486 HeapFree(GetProcessHeap(), 0, buffer
);
487 hr
= SafeArrayDestroy(lpsa
);
488 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
490 /* VARTYPE-less arrays with FADF_VARIANT */
491 hr
= SafeArrayAllocDescriptor(1, &lpsa
);
492 ok(hr
== S_OK
, "saad failed %08x\n", hr
);
493 lpsa
->cbElements
= sizeof(VARIANT
);
494 lpsa
->fFeatures
= FADF_VARIANT
;
495 lpsa
->rgsabound
[0].lLbound
= 2;
496 lpsa
->rgsabound
[0].cElements
= 48;
497 hr
= SafeArrayAllocData(lpsa
);
498 ok(hr
== S_OK
, "saad failed %08x\n", hr
);
500 if (pSafeArrayGetVartype
)
502 hr
= pSafeArrayGetVartype(lpsa
, &vt
);
503 ok(hr
== E_INVALIDARG
, "ret %08x\n", hr
);
506 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
507 size
= LPSAFEARRAY_UserSize(&umcb
.Flags
, 0, &lpsa
);
508 expected
= 44 + 28 * lpsa
->rgsabound
[0].cElements
;
510 ok(size
== expected
|| size
== expected
+ 8, /* win64 */
511 "size should be %u bytes, not %u\n", expected
, size
);
512 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
513 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
514 next
= LPSAFEARRAY_UserMarshal(&umcb
.Flags
, buffer
, &lpsa
);
516 ok(next
- buffer
== expected
|| broken(next
- buffer
+ sizeof(DWORD
) == expected
),
517 "Marshaled %u bytes, expected %u\n", (ULONG
) (next
- buffer
), expected
);
518 lpsa
->cbElements
= 16; /* VARIANT wire size */
519 check_safearray(buffer
, lpsa
);
520 HeapFree(GetProcessHeap(), 0, buffer
);
521 hr
= SafeArrayDestroyData(lpsa
);
522 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
523 hr
= SafeArrayDestroyDescriptor(lpsa
);
524 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
527 static void check_bstr(void *buffer
, BSTR b
)
529 DWORD
*wireb
= buffer
;
530 DWORD len
= SysStringByteLen(b
);
532 ok(*wireb
== (len
+ 1) / 2, "wv[0] %08x\n", *wireb
);
535 ok(*wireb
== len
, "wv[1] %08x\n", *wireb
);
537 ok(*wireb
== 0xffffffff, "wv[1] %08x\n", *wireb
);
539 ok(*wireb
== (len
+ 1) / 2, "wv[2] %08x\n", *wireb
);
543 ok(!memcmp(wireb
, b
, (len
+ 1) & ~1), "strings differ\n");
548 static void test_marshal_BSTR(void)
552 MIDL_STUB_MESSAGE stub_msg
;
553 USER_MARSHAL_CB umcb
;
554 unsigned char *buffer
, *next
;
556 WCHAR str
[] = {'m','a','r','s','h','a','l',' ','t','e','s','t','1',0};
559 b
= SysAllocString(str
);
560 len
= SysStringLen(b
);
561 ok(len
== 13, "get %d\n", len
);
563 /* BSTRs are DWORD aligned */
565 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
566 size
= BSTR_UserSize(&umcb
.Flags
, 1, &b
);
567 ok(size
== 42, "size %d\n", size
);
569 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
570 size
= BSTR_UserSize(&umcb
.Flags
, 0, &b
);
571 ok(size
== 38, "size %d\n", size
);
573 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
574 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
575 next
= BSTR_UserMarshal(&umcb
.Flags
, buffer
, &b
);
576 ok(next
== buffer
+ size
, "got %p expect %p\n", next
, buffer
+ size
);
577 check_bstr(buffer
, b
);
580 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
581 next
= BSTR_UserUnmarshal(&umcb
.Flags
, buffer
, &b2
);
582 ok(next
== buffer
+ size
, "got %p expect %p\n", next
, buffer
+ size
);
583 ok(b2
!= NULL
, "BSTR didn't unmarshal\n");
584 ok(!memcmp(b
, b2
, (len
+ 1) * 2), "strings differ\n");
585 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
586 BSTR_UserFree(&umcb
.Flags
, &b2
);
588 HeapFree(GetProcessHeap(), 0, buffer
);
592 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
593 size
= BSTR_UserSize(&umcb
.Flags
, 0, &b
);
594 ok(size
== 12, "size %d\n", size
);
596 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
597 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
598 next
= BSTR_UserMarshal(&umcb
.Flags
, buffer
, &b
);
599 ok(next
== buffer
+ size
, "got %p expect %p\n", next
, buffer
+ size
);
601 check_bstr(buffer
, b
);
603 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
604 next
= BSTR_UserUnmarshal(&umcb
.Flags
, buffer
, &b2
);
605 ok(next
== buffer
+ size
, "got %p expect %p\n", next
, buffer
+ size
);
606 ok(b2
== NULL
, "NULL BSTR didn't unmarshal\n");
607 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
608 BSTR_UserFree(&umcb
.Flags
, &b2
);
609 HeapFree(GetProcessHeap(), 0, buffer
);
611 b
= SysAllocStringByteLen("abc", 3);
612 *(((char*)b
) + 3) = 'd';
613 len
= SysStringLen(b
);
614 ok(len
== 1, "get %d\n", len
);
615 len
= SysStringByteLen(b
);
616 ok(len
== 3, "get %d\n", len
);
618 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
619 size
= BSTR_UserSize(&umcb
.Flags
, 0, &b
);
620 ok(size
== 16, "size %d\n", size
);
622 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
623 memset(buffer
, 0xcc, size
);
624 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
625 next
= BSTR_UserMarshal(&umcb
.Flags
, buffer
, &b
);
626 ok(next
== buffer
+ size
, "got %p expect %p\n", next
, buffer
+ size
);
627 check_bstr(buffer
, b
);
628 ok(buffer
[15] == 'd', "buffer[15] %02x\n", buffer
[15]);
631 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
632 next
= BSTR_UserUnmarshal(&umcb
.Flags
, buffer
, &b2
);
633 ok(next
== buffer
+ size
, "got %p expect %p\n", next
, buffer
+ size
);
634 ok(b2
!= NULL
, "BSTR didn't unmarshal\n");
635 ok(!memcmp(b
, b2
, len
), "strings differ\n");
636 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
637 BSTR_UserFree(&umcb
.Flags
, &b2
);
638 HeapFree(GetProcessHeap(), 0, buffer
);
641 b
= SysAllocStringByteLen("", 0);
642 len
= SysStringLen(b
);
643 ok(len
== 0, "get %d\n", len
);
644 len
= SysStringByteLen(b
);
645 ok(len
== 0, "get %d\n", len
);
647 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
648 size
= BSTR_UserSize(&umcb
.Flags
, 0, &b
);
649 ok(size
== 12, "size %d\n", size
);
651 buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
652 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
653 next
= BSTR_UserMarshal(&umcb
.Flags
, buffer
, &b
);
654 ok(next
== buffer
+ size
, "got %p expect %p\n", next
, buffer
+ size
);
655 check_bstr(buffer
, b
);
658 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, buffer
, size
, MSHCTX_DIFFERENTMACHINE
);
659 next
= BSTR_UserUnmarshal(&umcb
.Flags
, buffer
, &b2
);
660 ok(next
== buffer
+ size
, "got %p expect %p\n", next
, buffer
+ size
);
661 ok(b2
!= NULL
, "NULL LPSAFEARRAY didn't unmarshal\n");
662 len
= SysStringByteLen(b2
);
663 ok(len
== 0, "byte len %d\n", len
);
664 init_user_marshal_cb(&umcb
, &stub_msg
, &rpc_msg
, NULL
, 0, MSHCTX_DIFFERENTMACHINE
);
665 BSTR_UserFree(&umcb
.Flags
, &b2
);
666 HeapFree(GetProcessHeap(), 0, buffer
);
672 IUnknown IUnknown_iface
;
676 static inline HeapUnknown
*impl_from_IUnknown(IUnknown
*iface
)
678 return CONTAINING_RECORD(iface
, HeapUnknown
, IUnknown_iface
);
681 static HRESULT WINAPI
HeapUnknown_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
683 if (IsEqualIID(riid
, &IID_IUnknown
))
685 IUnknown_AddRef(iface
);
690 return E_NOINTERFACE
;
693 static ULONG WINAPI
HeapUnknown_AddRef(IUnknown
*iface
)
695 HeapUnknown
*This
= impl_from_IUnknown(iface
);
696 return InterlockedIncrement((LONG
*)&This
->refs
);
699 static ULONG WINAPI
HeapUnknown_Release(IUnknown
*iface
)
701 HeapUnknown
*This
= impl_from_IUnknown(iface
);
702 ULONG refs
= InterlockedDecrement((LONG
*)&This
->refs
);
703 if (!refs
) HeapFree(GetProcessHeap(), 0, This
);
707 static const IUnknownVtbl HeapUnknown_Vtbl
=
709 HeapUnknown_QueryInterface
,
714 static void check_variant_header(DWORD
*wirev
, VARIANT
*v
, ULONG size
)
719 ok(*wirev
== (size
+ 7) >> 3, "wv[0] %08x, expected %08x\n", *wirev
, (size
+ 7) >> 3);
721 ok(*wirev
== 0, "wv[1] %08x\n", *wirev
);
724 ok(*wp
== V_VT(v
), "vt %04x expected %04x\n", *wp
, V_VT(v
));
726 ok(*wp
== V_U2(v
).wReserved1
, "res1 %04x expected %04x\n", *wp
, V_U2(v
).wReserved1
);
728 ok(*wp
== V_U2(v
).wReserved2
, "res2 %04x expected %04x\n", *wp
, V_U2(v
).wReserved2
);
730 ok(*wp
== V_U2(v
).wReserved3
, "res3 %04x expected %04x\n", *wp
, V_U2(v
).wReserved3
);
734 if(switch_is
& VT_ARRAY
)
735 switch_is
&= ~VT_TYPEMASK
;
736 ok(*wirev
== switch_is
, "switch_is %08x expected %08x\n", *wirev
, switch_is
);
739 /* Win9x and WinME don't always align as needed. Variants have
742 static void *alloc_aligned(SIZE_T size
, void **buf
)
744 *buf
= HeapAlloc(GetProcessHeap(), 0, size
+ 7);
745 return (void *)(((UINT_PTR
)*buf
+ 7) & ~7);
748 static void test_marshal_VARIANT(void)
751 MIDL_STUB_MESSAGE stubMsg
= { 0 };
752 RPC_MESSAGE rpcMsg
= { 0 };
753 USER_MARSHAL_CB umcb
= { 0 };
754 unsigned char *buffer
, *next
;
762 WCHAR str
[] = {'m','a','r','s','h','a','l',' ','t','e','s','t',0};
766 HeapUnknown
*heap_unknown
;
772 stubMsg
.RpcMsg
= &rpcMsg
;
774 umcb
.Flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
775 umcb
.pStubMsg
= &stubMsg
;
776 umcb
.pReserve
= NULL
;
777 umcb
.Signature
= USER_MARSHAL_CB_SIGNATURE
;
778 umcb
.CBType
= USER_MARSHAL_CB_UNMARSHALL
;
785 /* check_variant_header tests wReserved[123], so initialize to unique values.
786 * (Could probably also do this by setting the variant to a known DECIMAL.)
788 V_U2(&v
).wReserved1
= 0x1234;
789 V_U2(&v
).wReserved2
= 0x5678;
790 V_U2(&v
).wReserved3
= 0x9abc;
792 /* Variants have an alignment of 8 */
793 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 1, &v
);
794 ok(stubMsg
.BufferLength
== 29, "size %d\n", stubMsg
.BufferLength
);
796 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
797 ok(stubMsg
.BufferLength
== 21, "size %d\n", stubMsg
.BufferLength
);
799 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
800 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
801 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
802 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
803 wirev
= (DWORD
*)buffer
;
805 check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
807 ok(*(char*)wirev
== V_I1(&v
), "wv[5] %08x\n", *wirev
);
809 stubMsg
.Buffer
= buffer
;
810 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
811 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
812 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
813 ok(V_I1(&v
) == V_I1(&v2
), "got i1 %x expect %x\n", V_I1(&v
), V_I1(&v2
));
815 VARIANT_UserFree(&umcb
.Flags
, &v2
);
816 HeapFree(GetProcessHeap(), 0, oldbuffer
);
823 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
824 ok(stubMsg
.BufferLength
== 22, "size %d\n", stubMsg
.BufferLength
);
826 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
827 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
828 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
829 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
830 wirev
= (DWORD
*)buffer
;
832 check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
834 ok(*(short*)wirev
== V_I2(&v
), "wv[5] %08x\n", *wirev
);
836 stubMsg
.Buffer
= buffer
;
837 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
838 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
839 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
840 ok(V_I2(&v
) == V_I2(&v2
), "got i2 %x expect %x\n", V_I2(&v
), V_I2(&v2
));
842 VARIANT_UserFree(&umcb
.Flags
, &v2
);
843 HeapFree(GetProcessHeap(), 0, oldbuffer
);
847 V_VT(&v
) = VT_I2
| VT_BYREF
;
851 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
852 ok(stubMsg
.BufferLength
== 26, "size %d\n", stubMsg
.BufferLength
);
854 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
855 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
856 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
857 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
858 wirev
= (DWORD
*)buffer
;
860 check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
862 ok(*wirev
== 0x4, "wv[5] %08x\n", *wirev
);
864 ok(*(short*)wirev
== s
, "wv[6] %08x\n", *wirev
);
866 V_VT(&v2
) = VT_I2
| VT_BYREF
;
867 V_BYREF(&v2
) = mem
= CoTaskMemAlloc(sizeof(V_I2(&v2
)));
868 stubMsg
.Buffer
= buffer
;
869 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
870 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
871 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
872 ok(V_BYREF(&v2
) == mem
, "didn't reuse existing memory\n");
873 ok(*V_I2REF(&v
) == *V_I2REF(&v2
), "got i2 ref %x expect ui4 ref %x\n", *V_I2REF(&v
), *V_I2REF(&v2
));
875 VARIANT_UserFree(&umcb
.Flags
, &v2
);
876 HeapFree(GetProcessHeap(), 0, oldbuffer
);
883 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
884 ok(stubMsg
.BufferLength
== 24, "size %d\n", stubMsg
.BufferLength
);
886 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
887 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
888 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
889 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
890 wirev
= (DWORD
*)buffer
;
892 check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
894 ok(*wirev
== V_I4(&v
), "wv[5] %08x\n", *wirev
);
897 stubMsg
.Buffer
= buffer
;
898 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
899 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
900 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
901 ok(V_I4(&v
) == V_I4(&v2
), "got i4 %x expect %x\n", V_I4(&v
), V_I4(&v2
));
903 VARIANT_UserFree(&umcb
.Flags
, &v2
);
904 HeapFree(GetProcessHeap(), 0, oldbuffer
);
911 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
912 ok(stubMsg
.BufferLength
== 24, "size %d\n", stubMsg
.BufferLength
);
914 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
915 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
916 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
917 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
918 wirev
= (DWORD
*)buffer
;
920 check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
922 ok(*wirev
== 0x1234, "wv[5] %08x\n", *wirev
);
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(V_UI4(&v
) == V_UI4(&v2
), "got ui4 %x expect %x\n", V_UI4(&v
), V_UI4(&v2
));
930 VARIANT_UserFree(&umcb
.Flags
, &v2
);
931 HeapFree(GetProcessHeap(), 0, oldbuffer
);
935 V_VT(&v
) = VT_UI4
| VT_BYREF
;
939 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
940 ok(stubMsg
.BufferLength
== 28, "size %d\n", stubMsg
.BufferLength
);
942 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
943 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
944 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
945 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
946 wirev
= (DWORD
*)buffer
;
948 check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
950 ok(*wirev
== 0x4, "wv[5] %08x\n", *wirev
);
952 ok(*wirev
== ul
, "wv[6] %08x\n", *wirev
);
955 stubMsg
.Buffer
= buffer
;
956 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
957 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
958 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
959 ok(*V_UI4REF(&v
) == *V_UI4REF(&v2
), "got ui4 ref %x expect ui4 ref %x\n", *V_UI4REF(&v
), *V_UI4REF(&v2
));
961 VARIANT_UserFree(&umcb
.Flags
, &v2
);
962 HeapFree(GetProcessHeap(), 0, oldbuffer
);
969 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
970 ok(stubMsg
.BufferLength
== 24, "size %d\n", stubMsg
.BufferLength
);
972 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
973 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
974 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
975 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
976 wirev
= (DWORD
*)buffer
;
978 check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
980 ok(*(float*)wirev
== V_R4(&v
), "wv[5] %08x\n", *wirev
);
982 stubMsg
.Buffer
= buffer
;
983 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
984 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
985 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
986 ok(V_R4(&v
) == V_R4(&v2
), "got r4 %f expect %f\n", V_R4(&v
), V_R4(&v2
));
988 VARIANT_UserFree(&umcb
.Flags
, &v2
);
989 HeapFree(GetProcessHeap(), 0, oldbuffer
);
996 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
997 ok(stubMsg
.BufferLength
== 32, "size %d\n", stubMsg
.BufferLength
);
999 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1000 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1001 memset(buffer
, 0xcc, stubMsg
.BufferLength
);
1002 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1003 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1004 wirev
= (DWORD
*)buffer
;
1006 check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
1008 ok(*wirev
== 0xcccccccc, "wv[5] %08x\n", *wirev
); /* pad */
1010 ok(*(double*)wirev
== V_R8(&v
), "wv[6] %08x, wv[7] %08x\n", *wirev
, *(wirev
+1));
1012 stubMsg
.Buffer
= buffer
;
1013 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1014 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1015 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1016 ok(V_R8(&v
) == V_R8(&v2
), "got r8 %f expect %f\n", V_R8(&v
), V_R8(&v2
));
1018 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1019 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1023 V_VT(&v
) = VT_R8
| VT_BYREF
;
1027 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1028 ok(stubMsg
.BufferLength
== 32, "size %d\n", stubMsg
.BufferLength
);
1030 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1031 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1032 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1033 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1034 wirev
= (DWORD
*)buffer
;
1036 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 check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
1067 ok(*(short*)wirev
== V_BOOL(&v
), "wv[5] %04x\n", *(WORD
*)wirev
);
1069 stubMsg
.Buffer
= buffer
;
1070 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1071 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1072 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1073 ok(V_BOOL(&v
) == V_BOOL(&v2
), "got bool %x expect %x\n", V_BOOL(&v
), V_BOOL(&v2
));
1075 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1076 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1079 VarDecFromI4(0x12345678, &dec
);
1080 dec
.wReserved
= 0xfedc; /* Also initialize reserved field, as we check it later */
1082 V_DECIMAL(&v
) = dec
;
1083 V_VT(&v
) = VT_DECIMAL
;
1085 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1086 ok(stubMsg
.BufferLength
== 40, "size %d\n", stubMsg
.BufferLength
);
1088 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1089 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1090 memset(buffer
, 0xcc, stubMsg
.BufferLength
);
1091 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1092 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1093 wirev
= (DWORD
*)buffer
;
1095 check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
1097 ok(*wirev
== 0xcccccccc, "wirev[5] %08x\n", *wirev
); /* pad */
1100 dec2
.wReserved
= VT_DECIMAL
;
1101 ok(!memcmp(wirev
, &dec2
, sizeof(dec2
)), "wirev[6] %08x wirev[7] %08x wirev[8] %08x wirev[9] %08x\n",
1102 *wirev
, *(wirev
+ 1), *(wirev
+ 2), *(wirev
+ 3));
1104 stubMsg
.Buffer
= buffer
;
1105 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1106 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1107 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1108 ok(!memcmp(&V_DECIMAL(&v
), & V_DECIMAL(&v2
), sizeof(DECIMAL
)), "decimals differ\n");
1110 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1111 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1113 /*** DECIMAL BYREF ***/
1115 V_VT(&v
) = VT_DECIMAL
| VT_BYREF
;
1116 V_DECIMALREF(&v
) = &dec
;
1118 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1119 ok(stubMsg
.BufferLength
== 40, "size %d\n", stubMsg
.BufferLength
);
1121 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1122 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1123 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1124 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1125 wirev
= (DWORD
*)buffer
;
1127 check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
1129 ok(*wirev
== 16, "wv[5] %08x\n", *wirev
);
1131 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));
1133 /* check_variant_header tests wReserved[123], so initialize to unique values.
1134 * (Could probably also do this by setting the variant to a known DECIMAL.)
1136 V_U2(&v2
).wReserved1
= 0x0123;
1137 V_U2(&v2
).wReserved2
= 0x4567;
1138 V_U2(&v2
).wReserved3
= 0x89ab;
1140 stubMsg
.Buffer
= buffer
;
1141 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1142 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1143 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1144 ok(!memcmp(V_DECIMALREF(&v
), V_DECIMALREF(&v2
), sizeof(DECIMAL
)), "decimals differ\n");
1146 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1147 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1151 V_VT(&v
) = VT_EMPTY
;
1153 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1154 ok(stubMsg
.BufferLength
== 20, "size %d\n", stubMsg
.BufferLength
);
1156 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1157 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1158 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1159 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1160 wirev
= (DWORD
*)buffer
;
1162 check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
1164 stubMsg
.Buffer
= buffer
;
1165 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1166 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1167 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1169 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1170 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1176 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1177 ok(stubMsg
.BufferLength
== 20, "size %d\n", stubMsg
.BufferLength
);
1179 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1180 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1181 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1182 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1183 wirev
= (DWORD
*)buffer
;
1185 check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
1187 stubMsg
.Buffer
= buffer
;
1188 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1189 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1190 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1192 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1193 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1196 b
= SysAllocString(str
);
1201 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1202 ok(stubMsg
.BufferLength
== 60, "size %d\n", stubMsg
.BufferLength
);
1203 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1204 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1205 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1206 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1207 wirev
= (DWORD
*)buffer
;
1209 check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
1211 ok(*wirev
, "wv[5] %08x\n", *wirev
); /* win2k: this is b. winxp: this is (char*)b + 1 */
1213 check_bstr(wirev
, V_BSTR(&v
));
1215 stubMsg
.Buffer
= buffer
;
1216 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1217 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1218 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1219 ok(SysStringByteLen(V_BSTR(&v
)) == SysStringByteLen(V_BSTR(&v2
)), "bstr string lens differ\n");
1220 ok(!memcmp(V_BSTR(&v
), V_BSTR(&v2
), SysStringByteLen(V_BSTR(&v
))), "bstrs differ\n");
1222 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1223 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1225 /*** BSTR BYREF ***/
1227 V_VT(&v
) = VT_BSTR
| VT_BYREF
;
1230 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1231 ok(stubMsg
.BufferLength
== 64, "size %d\n", stubMsg
.BufferLength
);
1232 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1233 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1234 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1235 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1236 wirev
= (DWORD
*)buffer
;
1238 check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
1240 ok(*wirev
== 0x4, "wv[5] %08x\n", *wirev
);
1242 ok(*wirev
, "wv[6] %08x\n", *wirev
); /* win2k: this is b. winxp: this is (char*)b + 1 */
1244 check_bstr(wirev
, b
);
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(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1250 ok(SysStringByteLen(*V_BSTRREF(&v
)) == SysStringByteLen(*V_BSTRREF(&v2
)), "bstr string lens differ\n");
1251 ok(!memcmp(*V_BSTRREF(&v
), *V_BSTRREF(&v2
), SysStringByteLen(*V_BSTRREF(&v
))), "bstrs differ\n");
1253 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1254 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1261 lpsa
= SafeArrayCreate(VT_R8
, 1, &sab
);
1262 *(DWORD
*)lpsa
->pvData
= 0xcafebabe;
1263 *((DWORD
*)lpsa
->pvData
+ 1) = 0xdeadbeef;
1266 V_VT(&v
) = VT_UI4
| VT_ARRAY
;
1269 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1271 ok(stubMsg
.BufferLength
== expected
|| stubMsg
.BufferLength
== expected
+ 8, /* win64 */
1272 "size %u instead of %u\n", stubMsg
.BufferLength
, expected
);
1273 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1274 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1275 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1276 ok(next
== buffer
+ expected
, "got %p expect %p\n", next
, buffer
+ expected
);
1277 wirev
= (DWORD
*)buffer
;
1279 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 check_variant_header(wirev
, &v
, expected
);
1322 ok(*wirev
== 4, "wv[5] %08x\n", *wirev
);
1324 ok(*wirev
, "wv[6] %08x\n", *wirev
); /* win2k: this is lpsa. winxp: this is (char*)lpsa + 1 */
1326 check_safearray(wirev
, lpsa
);
1328 stubMsg
.Buffer
= buffer
;
1329 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1330 ok(next
== buffer
+ expected
, "got %p expect %p\n", next
, buffer
+ expected
);
1331 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1332 ok(SafeArrayGetDim(*V_ARRAYREF(&v
)) == SafeArrayGetDim(*V_ARRAYREF(&v2
)), "array dims differ\n");
1333 SafeArrayGetLBound(*V_ARRAYREF(&v
), 1, &bound
);
1334 SafeArrayGetLBound(*V_ARRAYREF(&v2
), 1, &bound2
);
1335 ok(bound
== bound2
, "array lbounds differ\n");
1336 SafeArrayGetUBound(*V_ARRAYREF(&v
), 1, &bound
);
1337 SafeArrayGetUBound(*V_ARRAYREF(&v2
), 1, &bound2
);
1338 ok(bound
== bound2
, "array ubounds differ\n");
1339 if (pSafeArrayGetVartype
)
1341 pSafeArrayGetVartype(*V_ARRAYREF(&v
), &vt
);
1342 pSafeArrayGetVartype(*V_ARRAYREF(&v2
), &vt2
);
1343 ok(vt
== vt2
, "array vts differ %x %x\n", vt
, vt2
);
1345 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1346 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1347 hr
= SafeArrayDestroy(lpsa
);
1348 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1350 /*** VARIANT BYREF ***/
1355 V_VT(&v
) = VT_VARIANT
| VT_BYREF
;
1356 V_VARIANTREF(&v
) = &v2
;
1358 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1359 ok(stubMsg
.BufferLength
== 64, "size %d\n", stubMsg
.BufferLength
);
1360 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1361 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1362 memset(buffer
, 0xcc, stubMsg
.BufferLength
);
1363 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1364 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1365 wirev
= (DWORD
*)buffer
;
1366 check_variant_header(wirev
, &v
, stubMsg
.BufferLength
);
1369 ok(*wirev
== sizeof(VARIANT
), "wv[5] %08x\n", *wirev
);
1371 ok(*wirev
== ('U' | 's' << 8 | 'e' << 16 | 'r' << 24), "wv[6] %08x\n", *wirev
); /* 'User' */
1373 ok(*wirev
== 0xcccccccc, "wv[7] %08x\n", *wirev
); /* pad */
1375 check_variant_header(wirev
, &v2
, stubMsg
.BufferLength
- 32);
1377 ok(*wirev
== 0xcccccccc, "wv[13] %08x\n", *wirev
); /* pad for VT_R8 */
1379 ok(*(double*)wirev
== V_R8(&v2
), "wv[6] %08x wv[7] %08x\n", *wirev
, *(wirev
+1));
1381 stubMsg
.Buffer
= buffer
;
1382 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v3
);
1383 ok(next
== buffer
+ stubMsg
.BufferLength
, "got %p expect %p\n", next
, buffer
+ stubMsg
.BufferLength
);
1384 ok(V_VT(&v
) == V_VT(&v3
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v3
));
1385 ok(V_VT(V_VARIANTREF(&v
)) == V_VT(V_VARIANTREF(&v3
)), "vts differ %x %x\n",
1386 V_VT(V_VARIANTREF(&v
)), V_VT(V_VARIANTREF(&v3
)));
1387 ok(V_R8(V_VARIANTREF(&v
)) == V_R8(V_VARIANTREF(&v3
)), "r8s differ\n");
1388 VARIANT_UserFree(&umcb
.Flags
, &v3
);
1389 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1392 heap_unknown
= HeapAlloc(GetProcessHeap(), 0, sizeof(*heap_unknown
));
1393 heap_unknown
->IUnknown_iface
.lpVtbl
= &HeapUnknown_Vtbl
;
1394 heap_unknown
->refs
= 1;
1397 V_VT(&v
) = VT_UNKNOWN
;
1398 V_UNKNOWN(&v
) = &heap_unknown
->IUnknown_iface
;
1400 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1401 ok(stubMsg
.BufferLength
> 32, "size %d\n", stubMsg
.BufferLength
);
1402 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1403 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1404 memset(buffer
, 0xcc, stubMsg
.BufferLength
);
1405 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1406 wirev
= (DWORD
*)buffer
;
1407 check_variant_header(wirev
, &v
, next
- buffer
);
1411 ok(*wirev
== (DWORD_PTR
)V_UNKNOWN(&v
) /* Win9x */ ||
1412 *wirev
== (DWORD_PTR
)V_UNKNOWN(&v
) + 1 /* NT */, "wv[5] %08x\n", *wirev
);
1415 ok(*wirev
== next
- buffer
- 0x20, "wv[6] %08x\n", *wirev
);
1418 ok(*wirev
== next
- buffer
- 0x20, "wv[7] %08x\n", *wirev
);
1421 ok(*wirev
== 0x574f454d, "wv[8] %08x\n", *wirev
);
1423 V_VT(&v3
) = VT_UNKNOWN
;
1424 V_UNKNOWN(&v3
) = &heap_unknown
->IUnknown_iface
;
1425 IUnknown_AddRef(V_UNKNOWN(&v3
));
1426 stubMsg
.Buffer
= buffer
;
1427 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v3
);
1428 ok(V_VT(&v
) == V_VT(&v3
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v3
));
1429 ok(V_UNKNOWN(&v
) == V_UNKNOWN(&v3
), "got %p expect %p\n", V_UNKNOWN(&v
), V_UNKNOWN(&v3
));
1430 VARIANT_UserFree(&umcb
.Flags
, &v3
);
1431 ok(heap_unknown
->refs
== 1, "%d refcounts of IUnknown leaked\n", heap_unknown
->refs
- 1);
1432 IUnknown_Release(&heap_unknown
->IUnknown_iface
);
1433 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1435 /*** NULL UNKNOWN ***/
1437 V_VT(&v
) = VT_UNKNOWN
;
1438 V_UNKNOWN(&v
) = NULL
;
1440 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1441 ok(stubMsg
.BufferLength
>= 24, "size %d\n", stubMsg
.BufferLength
);
1442 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1443 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1444 memset(buffer
, 0xcc, stubMsg
.BufferLength
);
1445 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1446 wirev
= (DWORD
*)buffer
;
1447 check_variant_header(wirev
, &v
, next
- buffer
);
1449 ok(*wirev
== 0, "wv[5] %08x\n", *wirev
);
1452 stubMsg
.Buffer
= buffer
;
1453 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v2
);
1454 ok(V_VT(&v
) == V_VT(&v2
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v2
));
1455 ok(V_UNKNOWN(&v2
) == NULL
, "got %p expect NULL\n", V_UNKNOWN(&v2
));
1456 VARIANT_UserFree(&umcb
.Flags
, &v2
);
1457 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1459 /*** UNKNOWN BYREF ***/
1460 heap_unknown
= HeapAlloc(GetProcessHeap(), 0, sizeof(*heap_unknown
));
1461 heap_unknown
->IUnknown_iface
.lpVtbl
= &HeapUnknown_Vtbl
;
1462 heap_unknown
->refs
= 1;
1465 V_VT(&v
) = VT_UNKNOWN
| VT_BYREF
;
1466 V_UNKNOWNREF(&v
) = (IUnknown
**)&heap_unknown
;
1468 rpcMsg
.BufferLength
= stubMsg
.BufferLength
= VARIANT_UserSize(&umcb
.Flags
, 0, &v
);
1469 ok(stubMsg
.BufferLength
> 36, "size %d\n", stubMsg
.BufferLength
);
1470 buffer
= rpcMsg
.Buffer
= stubMsg
.Buffer
= stubMsg
.BufferStart
= alloc_aligned(stubMsg
.BufferLength
, &oldbuffer
);
1471 stubMsg
.BufferEnd
= stubMsg
.Buffer
+ stubMsg
.BufferLength
;
1472 memset(buffer
, 0xcc, stubMsg
.BufferLength
);
1473 next
= VARIANT_UserMarshal(&umcb
.Flags
, buffer
, &v
);
1474 wirev
= (DWORD
*)buffer
;
1475 check_variant_header(wirev
, &v
, next
- buffer
);
1478 ok(*wirev
== 4, "wv[5] %08x\n", *wirev
);
1481 ok(*wirev
== (DWORD_PTR
)heap_unknown
/* Win9x, Win2000 */ ||
1482 *wirev
== (DWORD_PTR
)heap_unknown
+ 1 /* XP */, "wv[6] %08x\n", *wirev
);
1485 ok(*wirev
== next
- buffer
- 0x24, "wv[7] %08x\n", *wirev
);
1488 ok(*wirev
== next
- buffer
- 0x24, "wv[8] %08x\n", *wirev
);
1491 ok(*wirev
== 0x574f454d, "wv[9] %08x\n", *wirev
);
1494 V_VT(&v3
) = VT_UNKNOWN
;
1495 V_UNKNOWN(&v3
) = &heap_unknown
->IUnknown_iface
;
1496 IUnknown_AddRef(V_UNKNOWN(&v3
));
1497 stubMsg
.Buffer
= buffer
;
1498 next
= VARIANT_UserUnmarshal(&umcb
.Flags
, buffer
, &v3
);
1499 ok(V_VT(&v
) == V_VT(&v3
), "got vt %d expect %d\n", V_VT(&v
), V_VT(&v3
));
1500 ok(*V_UNKNOWNREF(&v
) == *V_UNKNOWNREF(&v3
), "got %p expect %p\n", *V_UNKNOWNREF(&v
), *V_UNKNOWNREF(&v3
));
1501 VARIANT_UserFree(&umcb
.Flags
, &v3
);
1502 ok(heap_unknown
->refs
== 1, "%d refcounts of IUnknown leaked\n", heap_unknown
->refs
- 1);
1503 IUnknown_Release(&heap_unknown
->IUnknown_iface
);
1504 HeapFree(GetProcessHeap(), 0, oldbuffer
);
1508 START_TEST(usrmarshal
)
1510 HANDLE hOleaut32
= GetModuleHandleA("oleaut32.dll");
1511 #define GETPTR(func) p##func = (void*)GetProcAddress(hOleaut32, #func)
1512 GETPTR(SafeArrayGetIID
);
1513 GETPTR(SafeArrayGetVartype
);
1517 if (!pSafeArrayGetIID
|| !pSafeArrayGetVartype
)
1518 win_skip("SafeArrayGetIID and/or SafeArrayGetVartype is not available, some tests will be skipped\n");
1522 test_marshal_LPSAFEARRAY();
1523 test_marshal_BSTR();
1524 test_marshal_VARIANT();