2 * Unit test suite for ndr marshalling functions
4 * Copyright 2006 Huw Davies
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
23 #define NTDDI_WIN2K 0x05000000
24 #define NTDDI_VERSION NTDDI_WIN2K /* for some MIDL_STUB_MESSAGE fields */
26 #include "wine/test.h"
37 static int my_alloc_called
;
38 static int my_free_called
;
39 static void * CALLBACK
my_alloc(SIZE_T size
)
42 return NdrOleAllocate(size
);
45 static void CALLBACK
my_free(void *ptr
)
51 static const MIDL_STUB_DESC Object_StubDesc
=
61 NULL
, /* format string, filled in by tests */
62 1, /* -error bounds_check flag */
63 0x20000, /* Ndr library version */
65 0x50100a4, /* MIDL Version 5.1.164 */
68 0, /* notify & notify_flag routine table */
75 static RPC_DISPATCH_FUNCTION IFoo_table
[] =
80 static RPC_DISPATCH_TABLE IFoo_v0_0_DispatchTable
=
86 static const RPC_SERVER_INTERFACE IFoo___RpcServerInterface
=
88 sizeof(RPC_SERVER_INTERFACE
),
89 {{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x34}},{0,0}},
90 {{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},
91 &IFoo_v0_0_DispatchTable
,
99 static RPC_IF_HANDLE IFoo_v0_0_s_ifspec
= (RPC_IF_HANDLE
)& IFoo___RpcServerInterface
;
100 static BOOL use_pointer_ids
= FALSE
;
102 static void determine_pointer_marshalling_style(void)
104 RPC_MESSAGE RpcMessage
;
105 MIDL_STUB_MESSAGE StubMsg
;
106 MIDL_STUB_DESC StubDesc
;
109 static const unsigned char fmtstr_up_char
[] =
111 0x12, 0x8, /* FC_UP [simple_pointer] */
116 StubDesc
= Object_StubDesc
;
117 StubDesc
.pFormatTypes
= NULL
;
119 NdrClientInitializeNew(
125 StubMsg
.BufferLength
= 8;
126 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
127 NdrPointerMarshall(&StubMsg
, (unsigned char*)&ch
, fmtstr_up_char
);
128 ok(StubMsg
.Buffer
== StubMsg
.BufferStart
+ 5, "%p %p\n", StubMsg
.Buffer
, StubMsg
.BufferStart
);
130 use_pointer_ids
= (*(unsigned int *)StubMsg
.BufferStart
!= (UINT_PTR
)&ch
);
131 trace("Pointer marshalling using %s\n", use_pointer_ids
? "pointer ids" : "pointer value");
133 HeapFree(GetProcessHeap(), 0, StubMsg
.BufferStart
);
136 static void test_ndr_simple_type(void)
138 RPC_MESSAGE RpcMessage
;
139 MIDL_STUB_MESSAGE StubMsg
;
140 MIDL_STUB_DESC StubDesc
;
143 StubDesc
= Object_StubDesc
;
144 StubDesc
.pFormatTypes
= NULL
;
146 NdrClientInitializeNew(
152 StubMsg
.BufferLength
= 16;
153 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
155 NdrSimpleTypeMarshall(&StubMsg
, (unsigned char*)&l
, 8 /* FC_LONG */);
156 ok(StubMsg
.Buffer
== StubMsg
.BufferStart
+ 4, "%p %p\n", StubMsg
.Buffer
, StubMsg
.BufferStart
);
157 ok(*(LONG
*)StubMsg
.BufferStart
== l
, "%d\n", *(LONG
*)StubMsg
.BufferStart
);
159 StubMsg
.Buffer
= StubMsg
.BufferStart
+ 1;
160 NdrSimpleTypeMarshall(&StubMsg
, (unsigned char*)&l
, 8 /* FC_LONG */);
161 ok(StubMsg
.Buffer
== StubMsg
.BufferStart
+ 8, "%p %p\n", StubMsg
.Buffer
, StubMsg
.BufferStart
);
162 ok(*(LONG
*)(StubMsg
.BufferStart
+ 4) == l
, "%d\n", *(LONG
*)StubMsg
.BufferStart
);
164 StubMsg
.Buffer
= StubMsg
.BufferStart
+ 1;
165 NdrSimpleTypeUnmarshall(&StubMsg
, (unsigned char*)&l2
, 8 /* FC_LONG */);
166 ok(StubMsg
.Buffer
== StubMsg
.BufferStart
+ 8, "%p %p\n", StubMsg
.Buffer
, StubMsg
.BufferStart
);
167 ok(l2
== l
, "%d\n", l2
);
169 HeapFree(GetProcessHeap(), 0, StubMsg
.BufferStart
);
172 static void test_pointer_marshal(const unsigned char *formattypes
,
173 void *memsrc
, DWORD srcsize
,
174 const void *wiredata
,
176 int(*cmp
)(const void*,const void*,size_t),
177 int num_additional_allocs
,
180 RPC_MESSAGE RpcMessage
;
181 MIDL_STUB_MESSAGE StubMsg
;
182 MIDL_STUB_DESC StubDesc
;
185 unsigned char *mem
, *mem_orig
;
187 my_alloc_called
= my_free_called
= 0;
191 StubDesc
= Object_StubDesc
;
192 StubDesc
.pFormatTypes
= formattypes
;
194 NdrClientInitializeNew(
200 StubMsg
.BufferLength
= 0;
201 NdrPointerBufferSize( &StubMsg
,
204 ok(StubMsg
.BufferLength
>= wiredatalen
, "%s: length %d\n", msgpfx
, StubMsg
.BufferLength
);
206 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
207 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
208 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
210 memset(StubMsg
.BufferStart
, 0x0, StubMsg
.BufferLength
); /* This is a hack to clear the padding between the ptr and longlong/double */
212 ptr
= NdrPointerMarshall( &StubMsg
, memsrc
, formattypes
);
213 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
214 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
215 ok(!memcmp(StubMsg
.BufferStart
, wiredata
, wiredatalen
), "%s: incorrectly marshaled\n", msgpfx
);
217 StubMsg
.Buffer
= StubMsg
.BufferStart
;
218 StubMsg
.MemorySize
= 0;
220 size
= NdrPointerMemorySize( &StubMsg
, formattypes
);
221 ok(size
== StubMsg
.MemorySize
, "%s: mem size %u size %u\n", msgpfx
, StubMsg
.MemorySize
, size
);
222 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
223 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
224 ok(size
== srcsize
+ 4, "%s: mem size %u\n", msgpfx
, size
);
226 ok(size
== srcsize
, "%s: mem size %u\n", msgpfx
, size
);
228 StubMsg
.Buffer
= StubMsg
.BufferStart
;
229 StubMsg
.MemorySize
= 16;
230 size
= NdrPointerMemorySize( &StubMsg
, formattypes
);
231 ok(size
== StubMsg
.MemorySize
, "%s: mem size %u size %u\n", msgpfx
, StubMsg
.MemorySize
, size
);
232 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
233 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
234 ok(size
== srcsize
+ 4 + 16, "%s: mem size %u\n", msgpfx
, size
);
236 ok(size
== srcsize
+ 16, "%s: mem size %u\n", msgpfx
, size
);
238 StubMsg
.Buffer
= StubMsg
.BufferStart
;
239 StubMsg
.MemorySize
= 1;
240 size
= NdrPointerMemorySize( &StubMsg
, formattypes
);
241 ok(size
== StubMsg
.MemorySize
, "%s: mem size %u size %u\n", msgpfx
, StubMsg
.MemorySize
, size
);
242 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
243 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
244 ok(size
== srcsize
+ 4 + (srcsize
== 8 ? 8 : 4), "%s: mem size %u\n", msgpfx
, size
);
246 ok(size
== srcsize
+ (srcsize
== 8 ? 8 : 4), "%s: mem size %u\n", msgpfx
, size
);
249 if(formattypes
[1] & 0x10) size
+= 4;
251 StubMsg
.Buffer
= StubMsg
.BufferStart
;
252 StubMsg
.MemorySize
= 0;
253 mem_orig
= mem
= HeapAlloc(GetProcessHeap(), 0, size
);
255 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
257 ptr
= NdrPointerUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
258 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
259 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
260 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
261 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
262 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
263 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
266 /* reset the buffer and call with must alloc */
267 StubMsg
.Buffer
= StubMsg
.BufferStart
;
268 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
270 ptr
= NdrPointerUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
271 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
272 /* doesn't allocate mem in this case */
274 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
276 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
277 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
278 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
281 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
284 if(formattypes
[0] != 0x11 /* FC_RP */)
286 /* now pass the address of a NULL ptr */
288 StubMsg
.Buffer
= StubMsg
.BufferStart
;
289 ptr
= NdrPointerUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
290 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
291 ok(mem
!= StubMsg
.BufferStart
+ wiredatalen
- srcsize
, "%s: mem points to buffer %p %p\n", msgpfx
, mem
, StubMsg
.BufferStart
);
292 ok(!cmp(mem
, memsrc
, size
), "%s: incorrectly unmarshaled\n", msgpfx
);
293 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
294 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
295 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
297 NdrPointerFree(&StubMsg
, mem
, formattypes
);
299 /* again pass address of NULL ptr, but pretend we're a server */
300 if (0) /* crashes on Win9x and NT4 */
303 StubMsg
.Buffer
= StubMsg
.BufferStart
;
304 StubMsg
.IsClient
= 0;
305 ptr
= NdrPointerUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
306 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
307 if (formattypes
[2] == 0xd /* FC_ENUM16 */)
308 ok(mem
!= StubMsg
.BufferStart
+ wiredatalen
- srcsize
, "%s: mem points to buffer %p %p\n", msgpfx
, mem
, StubMsg
.BufferStart
);
310 ok(mem
== StubMsg
.BufferStart
+ wiredatalen
- srcsize
, "%s: mem doesn't point to buffer %p %p\n", msgpfx
, mem
, StubMsg
.BufferStart
);
311 ok(!cmp(mem
, memsrc
, size
), "%s: incorrectly unmarshaled\n", msgpfx
);
312 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
313 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
314 if (formattypes
[2] != 0xd /* FC_ENUM16 */) {
315 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
320 HeapFree(GetProcessHeap(), 0, mem_orig
);
321 HeapFree(GetProcessHeap(), 0, StubMsg
.BufferStart
);
324 static int deref_cmp(const void *s1
, const void *s2
, size_t num
)
326 return memcmp(*(const void *const *)s1
, *(const void *const *)s2
, num
);
330 static void test_simple_types(void)
332 unsigned char wiredata
[16];
334 unsigned char *ch_ptr
;
342 static const unsigned char fmtstr_up_char
[] =
344 0x12, 0x8, /* FC_UP [simple_pointer] */
348 static const unsigned char fmtstr_up_byte
[] =
350 0x12, 0x8, /* FC_UP [simple_pointer] */
354 static const unsigned char fmtstr_up_small
[] =
356 0x12, 0x8, /* FC_UP [simple_pointer] */
360 static const unsigned char fmtstr_up_usmall
[] =
362 0x12, 0x8, /* FC_UP [simple_pointer] */
366 static const unsigned char fmtstr_rp_char
[] =
368 0x11, 0x8, /* FC_RP [simple_pointer] */
372 static const unsigned char fmtstr_rpup_char
[] =
374 0x11, 0x14, /* FC_RP [alloced_on_stack] */
375 NdrFcShort( 0x2 ), /* Offset= 2 (4) */
376 0x12, 0x8, /* FC_UP [simple_pointer] */
380 static const unsigned char fmtstr_rpup_char2
[] =
382 0x11, 0x04, /* FC_RP [alloced_on_stack] */
383 NdrFcShort( 0x2 ), /* Offset= 2 (4) */
384 0x12, 0x8, /* FC_UP [simple_pointer] */
389 static const unsigned char fmtstr_up_wchar
[] =
391 0x12, 0x8, /* FC_UP [simple_pointer] */
395 static const unsigned char fmtstr_up_short
[] =
397 0x12, 0x8, /* FC_UP [simple_pointer] */
401 static const unsigned char fmtstr_up_ushort
[] =
403 0x12, 0x8, /* FC_UP [simple_pointer] */
407 static const unsigned char fmtstr_up_enum16
[] =
409 0x12, 0x8, /* FC_UP [simple_pointer] */
413 static const unsigned char fmtstr_up_long
[] =
415 0x12, 0x8, /* FC_UP [simple_pointer] */
419 static const unsigned char fmtstr_up_ulong
[] =
421 0x12, 0x8, /* FC_UP [simple_pointer] */
425 static const unsigned char fmtstr_up_enum32
[] =
427 0x12, 0x8, /* FC_UP [simple_pointer] */
431 static const unsigned char fmtstr_up_errorstatus
[] =
433 0x12, 0x8, /* FC_UP [simple_pointer] */
434 0x10, /* FC_ERROR_STATUS_T */
438 static const unsigned char fmtstr_up_longlong
[] =
440 0x12, 0x8, /* FC_UP [simple_pointer] */
444 static const unsigned char fmtstr_up_float
[] =
446 0x12, 0x8, /* FC_UP [simple_pointer] */
450 static const unsigned char fmtstr_up_double
[] =
452 0x12, 0x8, /* FC_UP [simple_pointer] */
460 *(unsigned int *)wiredata
= 0x20000;
462 *(unsigned int *)wiredata
= (UINT_PTR
)ch_ptr
;
465 test_pointer_marshal(fmtstr_up_char
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_char");
466 test_pointer_marshal(fmtstr_up_byte
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_byte");
467 test_pointer_marshal(fmtstr_up_small
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_small");
468 test_pointer_marshal(fmtstr_up_usmall
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_usmall");
470 test_pointer_marshal(fmtstr_rp_char
, ch_ptr
, 1, &ch
, 1, NULL
, 0, "rp_char");
472 test_pointer_marshal(fmtstr_rpup_char
, &ch_ptr
, 1, wiredata
, 5, deref_cmp
, 1, "rpup_char");
473 test_pointer_marshal(fmtstr_rpup_char2
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "rpup_char2");
477 *(unsigned int *)wiredata
= 0x20000;
479 *(unsigned int *)wiredata
= (UINT_PTR
)&s
;
480 *(unsigned short*)(wiredata
+ 4) = s
;
482 test_pointer_marshal(fmtstr_up_wchar
, &s
, 2, wiredata
, 6, NULL
, 0, "up_wchar");
483 test_pointer_marshal(fmtstr_up_short
, &s
, 2, wiredata
, 6, NULL
, 0, "up_short");
484 test_pointer_marshal(fmtstr_up_ushort
, &s
, 2, wiredata
, 6, NULL
, 0, "up_ushort");
488 *(unsigned int *)wiredata
= 0x20000;
490 *(unsigned int *)wiredata
= (UINT_PTR
)&i
;
491 *(unsigned short*)(wiredata
+ 4) = i
;
492 test_pointer_marshal(fmtstr_up_enum16
, &i
, 4, wiredata
, 6, NULL
, 0, "up_enum16");
496 *(unsigned int *)wiredata
= 0x20000;
498 *(unsigned int *)wiredata
= (UINT_PTR
)&l
;
499 *(ULONG
*)(wiredata
+ 4) = l
;
501 test_pointer_marshal(fmtstr_up_long
, &l
, 4, wiredata
, 8, NULL
, 0, "up_long");
502 test_pointer_marshal(fmtstr_up_ulong
, &l
, 4, wiredata
, 8, NULL
, 0, "up_ulong");
503 test_pointer_marshal(fmtstr_up_enum32
, &l
, 4, wiredata
, 8, NULL
, 0, "up_emun32");
504 test_pointer_marshal(fmtstr_up_errorstatus
, &l
, 4, wiredata
, 8, NULL
, 0, "up_errorstatus");
506 ll
= ((ULONGLONG
)0xcafebabe) << 32 | 0xdeadbeef;
508 *(unsigned int *)wiredata
= 0x20000;
510 *(unsigned int *)wiredata
= (UINT_PTR
)&ll
;
511 *(unsigned int *)(wiredata
+ 4) = 0;
512 *(ULONGLONG
*)(wiredata
+ 8) = ll
;
513 test_pointer_marshal(fmtstr_up_longlong
, &ll
, 8, wiredata
, 16, NULL
, 0, "up_longlong");
517 *(unsigned int *)wiredata
= 0x20000;
519 *(unsigned int *)wiredata
= (UINT_PTR
)&f
;
520 *(float*)(wiredata
+ 4) = f
;
521 test_pointer_marshal(fmtstr_up_float
, &f
, 4, wiredata
, 8, NULL
, 0, "up_float");
525 *(unsigned int *)wiredata
= 0x20000;
527 *(unsigned int *)wiredata
= (UINT_PTR
)&d
;
528 *(unsigned int *)(wiredata
+ 4) = 0;
529 *(double*)(wiredata
+ 8) = d
;
530 test_pointer_marshal(fmtstr_up_double
, &d
, 8, wiredata
, 16, NULL
, 0, "up_double");
534 static void test_nontrivial_pointer_types(void)
536 RPC_MESSAGE RpcMessage
;
537 MIDL_STUB_MESSAGE StubMsg
;
538 MIDL_STUB_DESC StubDesc
;
544 unsigned char *mem
, *mem_orig
;
546 static const unsigned char fmtstr_ref_unique_out
[] =
548 0x12, 0x8, /* FC_UP [simple_pointer] */
551 0x11, 0x14, /* FC_RP [alloced_on_stack] [pointer_deref] */
552 NdrFcShort( 0xfffffffa ), /* Offset= -6 (0) */
559 StubDesc
= Object_StubDesc
;
560 StubDesc
.pFormatTypes
= fmtstr_ref_unique_out
;
562 NdrClientInitializeNew(
568 StubMsg
.BufferLength
= 0;
569 NdrPointerBufferSize( &StubMsg
,
571 &fmtstr_ref_unique_out
[4] );
573 /* Windows overestimates the buffer size */
574 ok(StubMsg
.BufferLength
>= 5, "length %d\n", StubMsg
.BufferLength
);
576 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
577 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
578 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
580 ptr
= NdrPointerMarshall( &StubMsg
, (unsigned char *)p1
, &fmtstr_ref_unique_out
[4] );
581 ok(ptr
== NULL
, "ret %p\n", ptr
);
582 size
= StubMsg
.Buffer
- StubMsg
.BufferStart
;
583 ok(size
== 5, "Buffer %p Start %p len %d\n", StubMsg
.Buffer
, StubMsg
.BufferStart
, size
);
584 ok(*(unsigned int *)StubMsg
.BufferStart
!= 0, "pointer ID marshalled incorrectly\n");
585 ok(*(unsigned char *)(StubMsg
.BufferStart
+ 4) == 0x22, "char data marshalled incorrectly: 0x%x\n",
586 *(unsigned char *)(StubMsg
.BufferStart
+ 4));
588 StubMsg
.Buffer
= StubMsg
.BufferStart
;
589 StubMsg
.MemorySize
= 0;
594 StubMsg
.Buffer
= StubMsg
.BufferStart
;
595 mem
= mem_orig
= HeapAlloc(GetProcessHeap(), 0, sizeof(void *));
596 *(void **)mem
= NULL
;
597 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 0);
598 ok(mem
== mem_orig
, "mem alloced\n");
599 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
602 StubMsg
.Buffer
= StubMsg
.BufferStart
;
603 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 1);
605 ok(mem
== mem_orig
, "mem alloced\n");
606 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
610 StubMsg
.Buffer
= StubMsg
.BufferStart
;
611 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
612 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
614 mem
= my_alloc(sizeof(void *));
615 *(void **)mem
= NULL
;
617 StubMsg
.Buffer
= StubMsg
.BufferStart
;
618 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
619 ok(my_free_called
== 0, "free called %d\n", my_free_called
);
622 mem
= my_alloc(sizeof(void *));
623 *(void **)mem
= my_alloc(sizeof(char));
625 StubMsg
.Buffer
= StubMsg
.BufferStart
;
626 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
627 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
632 StubMsg
.IsClient
= 0;
634 StubMsg
.Buffer
= StubMsg
.BufferStart
;
635 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 0);
636 ok(mem
!= StubMsg
.BufferStart
, "mem pointing at buffer\n");
638 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
639 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
643 StubMsg
.Buffer
= StubMsg
.BufferStart
;
644 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 1);
645 ok(mem
!= StubMsg
.BufferStart
, "mem pointing at buffer\n");
647 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
648 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
652 *(void **)mem
= NULL
;
653 StubMsg
.Buffer
= StubMsg
.BufferStart
;
654 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 0);
656 ok(mem
== mem_orig
, "mem alloced\n");
657 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
662 *(void **)mem
= NULL
;
663 StubMsg
.Buffer
= StubMsg
.BufferStart
;
664 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 1);
666 ok(mem
== mem_orig
, "mem alloced\n");
667 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
670 mem
= my_alloc(sizeof(void *));
671 *(void **)mem
= NULL
;
673 StubMsg
.Buffer
= StubMsg
.BufferStart
;
674 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
675 ok(my_free_called
== 0, "free called %d\n", my_free_called
);
678 mem
= my_alloc(sizeof(void *));
679 *(void **)mem
= my_alloc(sizeof(char));
681 StubMsg
.Buffer
= StubMsg
.BufferStart
;
682 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
683 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
686 HeapFree(GetProcessHeap(), 0, mem_orig
);
687 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
690 static void test_simple_struct_marshal(const unsigned char *formattypes
,
691 void *memsrc
, DWORD srcsize
,
692 const void *wiredata
,
694 int(*cmp
)(const void*,const void*,size_t),
695 int num_additional_allocs
,
698 RPC_MESSAGE RpcMessage
;
699 MIDL_STUB_MESSAGE StubMsg
;
700 MIDL_STUB_DESC StubDesc
;
703 unsigned char *mem
, *mem_orig
;
705 my_alloc_called
= my_free_called
= 0;
709 StubDesc
= Object_StubDesc
;
710 StubDesc
.pFormatTypes
= formattypes
;
712 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &StubDesc
, 0);
714 StubMsg
.BufferLength
= 0;
715 NdrSimpleStructBufferSize( &StubMsg
, memsrc
, formattypes
);
716 ok(StubMsg
.BufferLength
>= wiredatalen
, "%s: length %d\n", msgpfx
, StubMsg
.BufferLength
);
717 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
718 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
719 ptr
= NdrSimpleStructMarshall( &StubMsg
, memsrc
, formattypes
);
720 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
721 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
722 ok(!memcmp(StubMsg
.BufferStart
, wiredata
, wiredatalen
), "%s: incorrectly marshaled %08x %08x %08x\n", msgpfx
, *(DWORD
*)StubMsg
.BufferStart
,*((DWORD
*)StubMsg
.BufferStart
+1),*((DWORD
*)StubMsg
.BufferStart
+2));
724 StubMsg
.Buffer
= StubMsg
.BufferStart
;
725 StubMsg
.MemorySize
= 0;
726 size
= NdrSimpleStructMemorySize( &StubMsg
, formattypes
);
727 ok(size
== StubMsg
.MemorySize
, "%s: size != MemorySize\n", msgpfx
);
728 ok(size
== srcsize
, "%s: mem size %u\n", msgpfx
, size
);
729 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
731 StubMsg
.Buffer
= StubMsg
.BufferStart
;
732 size
= NdrSimpleStructMemorySize( &StubMsg
, formattypes
);
733 ok(size
== StubMsg
.MemorySize
, "%s: size != MemorySize\n", msgpfx
);
734 ok(StubMsg
.MemorySize
== ((srcsize
+ 3) & ~3) + srcsize
, "%s: mem size %u\n", msgpfx
, size
);
735 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
737 /*** Unmarshalling first with must_alloc false ***/
739 StubMsg
.Buffer
= StubMsg
.BufferStart
;
740 StubMsg
.MemorySize
= 0;
741 mem_orig
= mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, srcsize
);
742 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
743 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
744 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
745 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
746 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
747 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
749 ok(StubMsg
.MemorySize
== 0, "%s: memorysize touched in unmarshal\n", msgpfx
);
751 /* If we're a server we still use the supplied memory */
752 StubMsg
.Buffer
= StubMsg
.BufferStart
;
753 StubMsg
.IsClient
= 0;
754 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
755 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
756 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
757 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
758 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
760 ok(StubMsg
.MemorySize
== 0, "%s: memorysize touched in unmarshal\n", msgpfx
);
762 /* ...unless we pass a NULL ptr, then the buffer is used.
763 Passing a NULL ptr while we're a client && !must_alloc
764 crashes on Windows, so we won't do that. */
766 if (0) /* crashes on Win9x and NT4 */
769 StubMsg
.IsClient
= 0;
770 StubMsg
.Buffer
= StubMsg
.BufferStart
;
771 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, FALSE
);
772 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
773 ok(mem
== StubMsg
.BufferStart
, "%s: mem not equal buffer\n", msgpfx
);
774 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
775 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
777 ok(StubMsg
.MemorySize
== 0, "%s: memorysize touched in unmarshal\n", msgpfx
);
780 /*** now must_alloc is true ***/
782 /* with must_alloc set we always allocate new memory whether or not we're
783 a server and also when passing NULL */
785 StubMsg
.IsClient
= 1;
786 StubMsg
.Buffer
= StubMsg
.BufferStart
;
787 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
788 ok(ptr
== NULL
, "ret %p\n", ptr
);
789 ok(mem
!= mem_orig
, "mem not changed %p %p\n", mem
, mem_orig
);
790 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
791 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
793 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
796 StubMsg
.Buffer
= StubMsg
.BufferStart
;
797 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
798 ok(ptr
== NULL
, "ret %p\n", ptr
);
799 ok(mem
!= mem_orig
, "mem not changed %p %p\n", mem
, mem_orig
);
800 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
801 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
803 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
806 StubMsg
.Buffer
= StubMsg
.BufferStart
;
807 StubMsg
.IsClient
= 0;
808 StubMsg
.ReuseBuffer
= 1;
809 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
810 ok(ptr
== NULL
, "ret %p\n", ptr
);
811 ok(mem
!= mem_orig
, "mem not changed %p %p\n", mem
, mem_orig
);
812 ok(mem
!= StubMsg
.BufferStart
, "mem is buffer mem\n");
813 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
814 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
816 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
819 StubMsg
.Buffer
= StubMsg
.BufferStart
;
820 StubMsg
.IsClient
= 0;
821 StubMsg
.ReuseBuffer
= 1;
822 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
823 ok(ptr
== NULL
, "ret %p\n", ptr
);
824 ok(mem
!= StubMsg
.BufferStart
, "mem is buffer mem\n");
825 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
826 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
828 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
830 HeapFree(GetProcessHeap(), 0, mem_orig
);
831 HeapFree(GetProcessHeap(), 0, StubMsg
.BufferStart
);
841 static int ps1_cmp(const void *s1
, const void *s2
, size_t num
)
843 const ps1_t
*p1
, *p2
;
851 if(p1
->pl1
&& p2
->pl1
)
853 if(*p1
->pl1
!= *p2
->pl1
)
856 else if(p1
->pl1
|| p1
->pl1
)
859 if(p1
->pc1
&& p2
->pc1
)
861 if(*p1
->pc1
!= *p2
->pc1
)
864 else if(p1
->pc1
|| p1
->pc1
)
870 static void test_simple_struct(void)
872 unsigned char wiredata
[28];
878 static const unsigned char fmtstr_simple_struct
[] =
880 0x12, 0x0, /* FC_UP */
881 NdrFcShort( 0x2 ), /* Offset=2 */
882 0x15, 0x3, /* FC_STRUCT [align 4] */
883 NdrFcShort( 0x18 ), /* [size 24] */
886 0x38, /* FC_ALIGNM4 */
889 0x39, /* FC_ALIGNM8 */
900 static const unsigned char fmtstr_pointer_struct
[] =
902 0x12, 0x0, /* FC_UP */
903 NdrFcShort( 0x2 ), /* Offset=2 */
904 0x16, 0x3, /* FC_PSTRUCT [align 4] */
905 NdrFcShort( 0xc ), /* [size 12] */
908 0x46, /* FC_NO_REPEAT */
910 NdrFcShort( 0x4 ), /* 4 */
911 NdrFcShort( 0x4 ), /* 4 */
912 0x13, 0x8, /* FC_OP [simple_pointer] */
915 0x46, /* FC_NO_REPEAT */
917 NdrFcShort( 0x8 ), /* 8 */
918 NdrFcShort( 0x8 ), /* 8 */
919 0x13, 0x8, /* FC_OP [simple_pointer] */
931 /* zero the entire structure, including the holes */
932 memset(&s1
, 0, sizeof(s1
));
939 s1
.ll
= ((LONGLONG
) 0xbadefeed << 32) | 0x2468ace0;
942 memcpy(wiredata
, &s1
, wiredatalen
);
943 test_simple_struct_marshal(fmtstr_simple_struct
+ 4, &s1
, 24, wiredata
, 24, NULL
, 0, "struct");
946 *(unsigned int *)wiredata
= 0x20000;
948 *(unsigned int *)wiredata
= (UINT_PTR
)&s1
;
949 memcpy(wiredata
+ 4, &s1
, wiredatalen
);
950 test_pointer_marshal(fmtstr_simple_struct
, &s1
, 24, wiredata
, 28, NULL
, 0, "struct");
952 /* zero the entire structure, including the hole */
953 memset(&ps1
, 0, sizeof(ps1
));
961 *(unsigned int *)(wiredata
+ 4) = 0xdeadbeef;
964 *(unsigned int *)(wiredata
+ 8) = 0x20000;
965 *(unsigned int *)(wiredata
+ 12) = 0x20004;
969 *(unsigned int *)(wiredata
+ 8) = (UINT_PTR
)&l
;
970 *(unsigned int *)(wiredata
+ 12) = (UINT_PTR
)&c
;
972 memcpy(wiredata
+ 16, &l
, 4);
973 memcpy(wiredata
+ 20, &c
, 1);
975 test_simple_struct_marshal(fmtstr_pointer_struct
+ 4, &ps1
, 17, wiredata
+ 4, 17, ps1_cmp
, 2, "pointer_struct");
978 *(unsigned int *)wiredata
= 0x20000;
979 *(unsigned int *)(wiredata
+ 8) = 0x20004;
980 *(unsigned int *)(wiredata
+ 12) = 0x20008;
983 *(unsigned int *)wiredata
= (UINT_PTR
)&ps1
;
984 test_pointer_marshal(fmtstr_pointer_struct
, &ps1
, 17, wiredata
, 21, ps1_cmp
, 2, "pointer_struct");
987 static void test_fullpointer_xlat(void)
989 PFULL_PTR_XLAT_TABLES pXlatTables
;
994 pXlatTables
= NdrFullPointerXlatInit(2, XLAT_CLIENT
);
996 /* "marshaling" phase */
998 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
999 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1000 ok(RefId
== 0x1, "RefId should be 0x1 instead of 0x%x\n", RefId
);
1002 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 0, &RefId
);
1003 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1004 ok(RefId
== 0x1, "RefId should be 0x1 instead of 0x%x\n", RefId
);
1006 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebabe, 0, &RefId
);
1007 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1008 ok(RefId
== 0x2, "RefId should be 0x2 instead of 0x%x\n", RefId
);
1010 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 0, &RefId
);
1011 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1012 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1014 ret
= NdrFullPointerQueryPointer(pXlatTables
, NULL
, 0, &RefId
);
1015 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1016 ok(RefId
== 0, "RefId should be 0 instead of 0x%x\n", RefId
);
1018 /* "unmarshaling" phase */
1020 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 0, &Pointer
);
1021 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1022 ok(Pointer
== (void *)0xcafebabe, "Pointer should be 0xcafebabe instead of %p\n", Pointer
);
1024 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x4, 0, &Pointer
);
1025 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1026 ok(Pointer
== NULL
, "Pointer should be NULL instead of %p\n", Pointer
);
1028 NdrFullPointerInsertRefId(pXlatTables
, 0x4, (void *)0xdeadbabe);
1030 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x4, 1, &Pointer
);
1031 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1032 ok(Pointer
== (void *)0xdeadbabe, "Pointer should be (void *)0xdeadbabe instead of %p\n", Pointer
);
1034 NdrFullPointerXlatFree(pXlatTables
);
1036 pXlatTables
= NdrFullPointerXlatInit(2, XLAT_SERVER
);
1038 /* "unmarshaling" phase */
1040 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 1, &Pointer
);
1041 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1042 ok(Pointer
== NULL
, "Pointer should be NULL instead of %p\n", Pointer
);
1044 NdrFullPointerInsertRefId(pXlatTables
, 0x2, (void *)0xcafebabe);
1046 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 0, &Pointer
);
1047 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1048 ok(Pointer
== (void *)0xcafebabe, "Pointer should be (void *)0xcafebabe instead of %p\n", Pointer
);
1050 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 1, &Pointer
);
1051 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1052 ok(Pointer
== (void *)0xcafebabe, "Pointer should be (void *)0xcafebabe instead of %p\n", Pointer
);
1054 /* "marshaling" phase */
1056 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
1057 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1058 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1060 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
1061 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1062 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1064 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 0, &RefId
);
1065 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1066 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1068 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebabe, 0, &RefId
);
1069 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1070 ok(RefId
== 0x2, "RefId should be 0x2 instead of 0x%x\n", RefId
);
1072 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 0, &RefId
);
1073 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1074 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
1076 /* "freeing" phase */
1078 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xcafebeef);
1079 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1081 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 0x20, &RefId
);
1082 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1083 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1085 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
1086 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1087 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1089 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xcafebabe);
1090 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1092 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xdeadbeef);
1093 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1095 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 0x20, &RefId
);
1096 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1097 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
1099 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 1, &RefId
);
1100 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1101 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
1103 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 1, &RefId
);
1104 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1105 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
1107 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xdeadbeef);
1108 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1110 NdrFullPointerXlatFree(pXlatTables
);
1113 static void test_client_init(void)
1115 MIDL_STUB_MESSAGE stubMsg
;
1119 memset(&rpcMsg
, 0xcc, sizeof(rpcMsg
));
1120 memset(&stubMsg
, 0xcc, sizeof(stubMsg
));
1121 memset(&unset_ptr
, 0xcc, sizeof(unset_ptr
));
1123 NdrClientInitializeNew(&rpcMsg
, &stubMsg
, &Object_StubDesc
, 1);
1125 #define TEST_POINTER_UNSET(field) ok(rpcMsg.field == unset_ptr, #field " should have been unset instead of %p\n", rpcMsg.field)
1127 ok(rpcMsg
.Handle
== NULL
, "rpcMsg.Handle should have been NULL instead of %p\n", rpcMsg
.Handle
);
1128 TEST_POINTER_UNSET(Buffer
);
1129 ok(rpcMsg
.BufferLength
== 0xcccccccc, "rpcMsg.BufferLength should have been unset instead of %d\n", rpcMsg
.BufferLength
);
1130 ok(rpcMsg
.ProcNum
== 0x8001, "rpcMsg.ProcNum should have been 0x8001 instead of 0x%x\n", rpcMsg
.ProcNum
);
1131 TEST_POINTER_UNSET(TransferSyntax
);
1132 ok(rpcMsg
.RpcInterfaceInformation
== Object_StubDesc
.RpcInterfaceInformation
,
1133 "rpcMsg.RpcInterfaceInformation should have been %p instead of %p\n",
1134 Object_StubDesc
.RpcInterfaceInformation
, rpcMsg
.RpcInterfaceInformation
);
1135 /* Note: ReservedForRuntime not tested */
1136 TEST_POINTER_UNSET(ManagerEpv
);
1137 TEST_POINTER_UNSET(ImportContext
);
1138 ok(rpcMsg
.RpcFlags
== 0, "rpcMsg.RpcFlags should have been 0 instead of 0x%x\n", rpcMsg
.RpcFlags
);
1139 #undef TEST_POINTER_UNSET
1141 #define TEST_ZERO(field, fmt) ok(stubMsg.field == 0, #field " should have been set to zero instead of " fmt "\n", stubMsg.field)
1142 #define TEST_POINTER_UNSET(field) ok(stubMsg.field == unset_ptr, #field " should have been unset instead of %p\n", stubMsg.field)
1143 #define TEST_ULONG_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%x\n", stubMsg.field)
1144 #define TEST_ULONG_PTR_UNSET(field) ok(stubMsg.field == (ULONG_PTR)unset_ptr, #field " should have been unset instead of 0x%lx\n", stubMsg.field)
1146 ok(stubMsg
.RpcMsg
== &rpcMsg
, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg
, stubMsg
.RpcMsg
);
1147 TEST_POINTER_UNSET(Buffer
);
1148 TEST_ZERO(BufferStart
, "%p");
1149 TEST_ZERO(BufferEnd
, "%p");
1150 TEST_POINTER_UNSET(BufferMark
);
1151 TEST_ZERO(BufferLength
, "%d");
1152 TEST_ULONG_UNSET(MemorySize
);
1153 TEST_POINTER_UNSET(Memory
);
1154 ok(stubMsg
.IsClient
== 1, "stubMsg.IsClient should have been 1 instead of %u\n", stubMsg
.IsClient
);
1155 TEST_ZERO(ReuseBuffer
, "%d");
1156 TEST_ZERO(pAllocAllNodesContext
, "%p");
1157 ok(stubMsg
.pPointerQueueState
== 0 ||
1158 broken(stubMsg
.pPointerQueueState
== unset_ptr
), /* win2k */
1159 "stubMsg.pPointerQueueState should have been unset instead of %p\n", stubMsg
.pPointerQueueState
);
1160 TEST_ZERO(IgnoreEmbeddedPointers
, "%d");
1161 TEST_ZERO(PointerBufferMark
, "%p");
1162 TEST_ZERO(CorrDespIncrement
, "%d");
1163 TEST_ZERO(uFlags
, "%d");
1164 /* FIXME: UniquePtrCount */
1165 TEST_ULONG_PTR_UNSET(MaxCount
);
1166 TEST_ULONG_UNSET(Offset
);
1167 TEST_ULONG_UNSET(ActualCount
);
1168 ok(stubMsg
.pfnAllocate
== my_alloc
, "stubMsg.pfnAllocate should have been %p instead of %p\n", my_alloc
, stubMsg
.pfnAllocate
);
1169 ok(stubMsg
.pfnFree
== my_free
, "stubMsg.pfnFree should have been %p instead of %p\n", my_free
, stubMsg
.pfnFree
);
1170 TEST_ZERO(StackTop
, "%p");
1171 TEST_POINTER_UNSET(pPresentedType
);
1172 TEST_POINTER_UNSET(pTransmitType
);
1173 TEST_POINTER_UNSET(SavedHandle
);
1174 ok(stubMsg
.StubDesc
== &Object_StubDesc
, "stubMsg.StubDesc should have been %p instead of %p\n", &Object_StubDesc
, stubMsg
.StubDesc
);
1175 TEST_POINTER_UNSET(FullPtrXlatTables
);
1176 TEST_ZERO(FullPtrRefId
, "%d");
1177 TEST_ZERO(PointerLength
, "%d");
1178 TEST_ZERO(fInDontFree
, "%d");
1179 TEST_ZERO(fDontCallFreeInst
, "%d");
1180 ok(stubMsg
.fInOnlyParam
== 0 ||
1181 stubMsg
.fInOnlyParam
== -1, /* Vista */
1182 "fInOnlyParam should have been set to 0 or -1 instead of %d\n", stubMsg
.fInOnlyParam
);
1183 TEST_ZERO(fHasReturn
, "%d");
1184 TEST_ZERO(fHasExtensions
, "%d");
1185 TEST_ZERO(fHasNewCorrDesc
, "%d");
1186 TEST_ZERO(fIsIn
, "%d");
1187 ok(stubMsg
.fIsOut
== 0 ||
1188 stubMsg
.fIsOut
== -1, /* XP-SP3 */
1189 "fIsOut should have been set to 0 or -1 instead of %d\n", stubMsg
.fIsOut
);
1190 TEST_ZERO(fIsOicf
, "%d");
1191 trace("NdrClientInitializeNew: fBufferValid = %d\n", stubMsg
.fBufferValid
);
1192 ok(stubMsg
.fHasMemoryValidateCallback
== 0 ||
1193 stubMsg
.fHasMemoryValidateCallback
== -1, /* XP-SP3 */
1194 "fHasMemoryValidateCallback should have been set to 0 or -1 instead of %d\n", stubMsg
.fHasMemoryValidateCallback
);
1195 ok(stubMsg
.fInFree
== 0 ||
1196 stubMsg
.fInFree
== -1, /* XP-SP3 */
1197 "fInFree should have been set to 0 or -1 instead of %d\n", stubMsg
.fInFree
);
1198 TEST_ZERO(fNeedMCCP
, "%d");
1199 ok(stubMsg
.fUnused
== 0 ||
1200 stubMsg
.fUnused
== -2, /* Vista */
1201 "fUnused should have been set to 0 or -2 instead of %d\n", stubMsg
.fUnused
);
1202 ok(stubMsg
.fUnused2
== 0xffffcccc, "stubMsg.fUnused2 should have been 0xffffcccc instead of 0x%x\n", stubMsg
.fUnused2
);
1203 ok(stubMsg
.dwDestContext
== MSHCTX_DIFFERENTMACHINE
, "stubMsg.dwDestContext should have been MSHCTX_DIFFERENTMACHINE instead of %d\n", stubMsg
.dwDestContext
);
1204 TEST_ZERO(pvDestContext
, "%p");
1205 TEST_POINTER_UNSET(SavedContextHandles
);
1206 TEST_ULONG_UNSET(ParamNumber
);
1207 TEST_ZERO(pRpcChannelBuffer
, "%p");
1208 TEST_ZERO(pArrayInfo
, "%p");
1209 TEST_POINTER_UNSET(SizePtrCountArray
);
1210 TEST_POINTER_UNSET(SizePtrOffsetArray
);
1211 TEST_POINTER_UNSET(SizePtrLengthArray
);
1212 TEST_POINTER_UNSET(pArgQueue
);
1213 TEST_ZERO(dwStubPhase
, "%d");
1214 /* FIXME: where does this value come from? */
1215 trace("LowStackMark is %p\n", stubMsg
.LowStackMark
);
1216 TEST_ZERO(pAsyncMsg
, "%p");
1217 TEST_ZERO(pCorrInfo
, "%p");
1218 TEST_ZERO(pCorrMemory
, "%p");
1219 TEST_ZERO(pMemoryList
, "%p");
1220 TEST_POINTER_UNSET(pCSInfo
);
1221 TEST_POINTER_UNSET(ConformanceMark
);
1222 TEST_POINTER_UNSET(VarianceMark
);
1223 ok(stubMsg
.Unused
== (ULONG_PTR
)unset_ptr
, "Unused should have be unset instead of 0x%lx\n", stubMsg
.Unused
);
1224 TEST_POINTER_UNSET(pContext
);
1225 TEST_POINTER_UNSET(ContextHandleHash
);
1226 TEST_POINTER_UNSET(pUserMarshalList
);
1227 TEST_ULONG_PTR_UNSET(Reserved51_3
);
1228 TEST_ULONG_PTR_UNSET(Reserved51_4
);
1229 TEST_ULONG_PTR_UNSET(Reserved51_5
);
1230 #undef TEST_ULONG_UNSET
1231 #undef TEST_POINTER_UNSET
1236 static void test_server_init(void)
1238 MIDL_STUB_MESSAGE stubMsg
;
1241 unsigned char buffer
[256];
1244 memset(&rpcMsg
, 0, sizeof(rpcMsg
));
1245 rpcMsg
.Buffer
= buffer
;
1246 rpcMsg
.BufferLength
= sizeof(buffer
);
1247 rpcMsg
.RpcFlags
= RPC_BUFFER_COMPLETE
;
1249 memset(&stubMsg
, 0xcc, sizeof(stubMsg
));
1250 memset(&unset_ptr
, 0xcc, sizeof(unset_ptr
));
1252 ret
= NdrServerInitializeNew(&rpcMsg
, &stubMsg
, &Object_StubDesc
);
1253 ok(ret
== NULL
, "NdrServerInitializeNew should have returned NULL instead of %p\n", ret
);
1255 #define TEST_ZERO(field, fmt) ok(stubMsg.field == 0, #field " should have been set to zero instead of " fmt "\n", stubMsg.field)
1256 #define TEST_POINTER_UNSET(field) ok(stubMsg.field == unset_ptr, #field " should have been unset instead of %p\n", stubMsg.field)
1257 #define TEST_ULONG_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%x\n", stubMsg.field)
1258 #define TEST_ULONG_PTR_UNSET(field) ok(stubMsg.field == (ULONG_PTR)unset_ptr, #field " should have been unset instead of 0x%lx\n", stubMsg.field)
1260 ok(stubMsg
.RpcMsg
== &rpcMsg
, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg
, stubMsg
.RpcMsg
);
1261 ok(stubMsg
.Buffer
== buffer
, "stubMsg.Buffer should have been %p instead of %p\n", buffer
, stubMsg
.Buffer
);
1262 ok(stubMsg
.BufferStart
== buffer
, "stubMsg.BufferStart should have been %p instead of %p\n", buffer
, stubMsg
.BufferStart
);
1263 ok(stubMsg
.BufferEnd
== buffer
+ sizeof(buffer
), "stubMsg.BufferEnd should have been %p instead of %p\n", buffer
+ sizeof(buffer
), stubMsg
.BufferEnd
);
1264 TEST_POINTER_UNSET(BufferMark
);
1266 TEST_ZERO(BufferLength
, "%d");
1267 TEST_ULONG_UNSET(MemorySize
);
1268 TEST_POINTER_UNSET(Memory
);
1269 ok(stubMsg
.IsClient
== 0, "stubMsg.IsClient should have been 0 instead of %u\n", stubMsg
.IsClient
);
1270 ok(stubMsg
.ReuseBuffer
== 0 ||
1271 broken(stubMsg
.ReuseBuffer
== 1), /* win2k */
1272 "stubMsg.ReuseBuffer should have been set to zero instead of %d\n", stubMsg
.ReuseBuffer
);
1273 TEST_ZERO(pAllocAllNodesContext
, "%p");
1274 ok(stubMsg
.pPointerQueueState
== 0 ||
1275 broken(stubMsg
.pPointerQueueState
== unset_ptr
), /* win2k */
1276 "stubMsg.pPointerQueueState should have been unset instead of %p\n", stubMsg
.pPointerQueueState
);
1277 TEST_ZERO(IgnoreEmbeddedPointers
, "%d");
1278 TEST_ZERO(PointerBufferMark
, "%p");
1279 ok(stubMsg
.CorrDespIncrement
== 0xcc ||
1280 stubMsg
.CorrDespIncrement
== 0,
1281 "CorrDespIncrement should have been unset instead of 0x%x\n", stubMsg
.CorrDespIncrement
);
1282 TEST_ZERO(uFlags
, "%d");
1283 /* FIXME: UniquePtrCount */
1284 TEST_ULONG_PTR_UNSET(MaxCount
);
1285 TEST_ULONG_UNSET(Offset
);
1286 TEST_ULONG_UNSET(ActualCount
);
1287 ok(stubMsg
.pfnAllocate
== my_alloc
, "stubMsg.pfnAllocate should have been %p instead of %p\n", my_alloc
, stubMsg
.pfnAllocate
);
1288 ok(stubMsg
.pfnFree
== my_free
, "stubMsg.pfnFree should have been %p instead of %p\n", my_free
, stubMsg
.pfnFree
);
1289 TEST_ZERO(StackTop
, "%p");
1290 TEST_POINTER_UNSET(pPresentedType
);
1291 TEST_POINTER_UNSET(pTransmitType
);
1292 TEST_POINTER_UNSET(SavedHandle
);
1293 ok(stubMsg
.StubDesc
== &Object_StubDesc
, "stubMsg.StubDesc should have been %p instead of %p\n", &Object_StubDesc
, stubMsg
.StubDesc
);
1294 TEST_ZERO(FullPtrXlatTables
, "%p");
1295 TEST_ZERO(FullPtrRefId
, "%d");
1296 TEST_ZERO(PointerLength
, "%d");
1297 TEST_ZERO(fInDontFree
, "%d");
1298 TEST_ZERO(fDontCallFreeInst
, "%d");
1299 ok(stubMsg
.fInOnlyParam
== 0 ||
1300 stubMsg
.fInOnlyParam
== -1, /* Vista */
1301 "fInOnlyParam should have been set to 0 or -1 instead of %d\n", stubMsg
.fInOnlyParam
);
1302 TEST_ZERO(fHasReturn
, "%d");
1303 TEST_ZERO(fHasExtensions
, "%d");
1304 TEST_ZERO(fHasNewCorrDesc
, "%d");
1305 TEST_ZERO(fIsIn
, "%d");
1306 ok(stubMsg
.fIsOut
== 0 ||
1307 stubMsg
.fIsOut
== -1, /* XP-SP3 */
1308 "fIsOut should have been set to 0 or -1 instead of %d\n", stubMsg
.fIsOut
);
1309 TEST_ZERO(fIsOicf
, "%d");
1310 trace("NdrServerInitializeNew: fBufferValid = %d\n", stubMsg
.fBufferValid
);
1311 ok(stubMsg
.fHasMemoryValidateCallback
== 0 ||
1312 stubMsg
.fHasMemoryValidateCallback
== -1, /* XP-SP3 */
1313 "fHasMemoryValidateCallback should have been set to 0 or -1 instead of %d\n", stubMsg
.fHasMemoryValidateCallback
);
1314 ok(stubMsg
.fInFree
== 0 ||
1315 stubMsg
.fInFree
== -1, /* XP-SP3 */
1316 "fInFree should have been set to 0 or -1 instead of %d\n", stubMsg
.fInFree
);
1317 TEST_ZERO(fNeedMCCP
, "%d");
1318 ok(stubMsg
.fUnused
== 0 ||
1319 stubMsg
.fUnused
== -2, /* Vista */
1320 "fUnused should have been set to 0 or -2 instead of %d\n", stubMsg
.fUnused
);
1321 ok(stubMsg
.fUnused2
== 0xffffcccc, "stubMsg.fUnused2 should have been 0xffffcccc instead of 0x%x\n", stubMsg
.fUnused2
);
1322 ok(stubMsg
.dwDestContext
== MSHCTX_DIFFERENTMACHINE
, "stubMsg.dwDestContext should have been MSHCTX_DIFFERENTMACHINE instead of %d\n", stubMsg
.dwDestContext
);
1323 TEST_ZERO(pvDestContext
, "%p");
1324 TEST_POINTER_UNSET(SavedContextHandles
);
1325 TEST_ULONG_UNSET(ParamNumber
);
1326 TEST_ZERO(pRpcChannelBuffer
, "%p");
1327 TEST_ZERO(pArrayInfo
, "%p");
1328 TEST_POINTER_UNSET(SizePtrCountArray
);
1329 TEST_POINTER_UNSET(SizePtrOffsetArray
);
1330 TEST_POINTER_UNSET(SizePtrLengthArray
);
1331 TEST_POINTER_UNSET(pArgQueue
);
1332 TEST_ZERO(dwStubPhase
, "%d");
1333 /* FIXME: where does this value come from? */
1334 trace("LowStackMark is %p\n", stubMsg
.LowStackMark
);
1335 TEST_ZERO(pAsyncMsg
, "%p");
1336 TEST_ZERO(pCorrInfo
, "%p");
1337 TEST_ZERO(pCorrMemory
, "%p");
1338 TEST_ZERO(pMemoryList
, "%p");
1339 TEST_POINTER_UNSET(pCSInfo
);
1340 TEST_POINTER_UNSET(ConformanceMark
);
1341 TEST_POINTER_UNSET(VarianceMark
);
1342 ok(stubMsg
.Unused
== (ULONG_PTR
)unset_ptr
, "Unused should have be unset instead of 0x%lx\n", stubMsg
.Unused
);
1343 TEST_POINTER_UNSET(pContext
);
1344 TEST_POINTER_UNSET(ContextHandleHash
);
1345 TEST_POINTER_UNSET(pUserMarshalList
);
1346 TEST_ULONG_PTR_UNSET(Reserved51_3
);
1347 TEST_ULONG_PTR_UNSET(Reserved51_4
);
1348 TEST_ULONG_PTR_UNSET(Reserved51_5
);
1349 #undef TEST_ULONG_UNSET
1350 #undef TEST_POINTER_UNSET
1355 static void test_ndr_allocate(void)
1357 RPC_MESSAGE RpcMessage
;
1358 MIDL_STUB_MESSAGE StubMsg
;
1359 MIDL_STUB_DESC StubDesc
;
1361 struct tag_mem_list_v1_t
1365 struct tag_mem_list_v1_t
*next
;
1367 struct tag_mem_list_v2_t
1372 struct tag_mem_list_v2_t
*next
;
1374 const DWORD magic_MEML
= 'M' << 24 | 'E' << 16 | 'M' << 8 | 'L';
1376 StubDesc
= Object_StubDesc
;
1377 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &StubDesc
, 0);
1379 ok(StubMsg
.pMemoryList
== NULL
, "memlist %p\n", StubMsg
.pMemoryList
);
1380 my_alloc_called
= my_free_called
= 0;
1381 p1
= NdrAllocate(&StubMsg
, 10);
1382 p2
= NdrAllocate(&StubMsg
, 24);
1383 ok(my_alloc_called
== 2, "alloc called %d\n", my_alloc_called
);
1384 ok(StubMsg
.pMemoryList
!= NULL
, "StubMsg.pMemoryList NULL\n");
1385 if(StubMsg
.pMemoryList
)
1387 mem_list_v2
= StubMsg
.pMemoryList
;
1388 if (mem_list_v2
->size
== 24)
1390 trace("v2 mem list format\n");
1391 ok((char *)mem_list_v2
== (char *)p2
+ 24, "expected mem_list_v2 pointer %p, but got %p\n", (char *)p2
+ 24, mem_list_v2
);
1392 ok(mem_list_v2
->magic
== magic_MEML
, "magic %08x\n", mem_list_v2
->magic
);
1393 ok(mem_list_v2
->size
== 24, "wrong size for p2 %d\n", mem_list_v2
->size
);
1394 ok(mem_list_v2
->unknown
== 0, "wrong unknown for p2 0x%x\n", mem_list_v2
->unknown
);
1395 ok(mem_list_v2
->next
!= NULL
, "next NULL\n");
1396 mem_list_v2
= mem_list_v2
->next
;
1399 ok((char *)mem_list_v2
== (char *)p1
+ 16, "expected mem_list_v2 pointer %p, but got %p\n", (char *)p1
+ 16, mem_list_v2
);
1400 ok(mem_list_v2
->magic
== magic_MEML
, "magic %08x\n", mem_list_v2
->magic
);
1401 ok(mem_list_v2
->size
== 16, "wrong size for p1 %d\n", mem_list_v2
->size
);
1402 ok(mem_list_v2
->unknown
== 0, "wrong unknown for p1 0x%x\n", mem_list_v2
->unknown
);
1403 ok(mem_list_v2
->next
== NULL
, "next %p\n", mem_list_v2
->next
);
1408 trace("v1 mem list format\n");
1409 mem_list_v1
= StubMsg
.pMemoryList
;
1410 ok(mem_list_v1
->magic
== magic_MEML
, "magic %08x\n", mem_list_v1
->magic
);
1411 ok(mem_list_v1
->ptr
== p2
, "ptr != p2\n");
1412 ok(mem_list_v1
->next
!= NULL
, "next NULL\n");
1413 mem_list_v1
= mem_list_v1
->next
;
1416 ok(mem_list_v1
->magic
== magic_MEML
, "magic %08x\n", mem_list_v1
->magic
);
1417 ok(mem_list_v1
->ptr
== p1
, "ptr != p1\n");
1418 ok(mem_list_v1
->next
== NULL
, "next %p\n", mem_list_v1
->next
);
1422 /* NdrFree isn't exported so we can't test free'ing */
1425 static void test_conformant_array(void)
1427 RPC_MESSAGE RpcMessage
;
1428 MIDL_STUB_MESSAGE StubMsg
;
1429 MIDL_STUB_DESC StubDesc
;
1431 unsigned char *mem
, *mem_orig
;
1432 unsigned char memsrc
[20];
1435 static const unsigned char fmtstr_conf_array
[] =
1437 0x1b, /* FC_CARRAY */
1439 NdrFcShort( 0x1 ), /* elem size */
1440 0x40, /* Corr desc: const */
1442 NdrFcShort(0x10), /* const = 0x10 */
1447 for (i
= 0; i
< sizeof(memsrc
); i
++)
1450 StubDesc
= Object_StubDesc
;
1451 StubDesc
.pFormatTypes
= fmtstr_conf_array
;
1453 NdrClientInitializeNew(
1459 StubMsg
.BufferLength
= 0;
1460 NdrConformantArrayBufferSize( &StubMsg
,
1462 fmtstr_conf_array
);
1463 ok(StubMsg
.BufferLength
>= 20, "length %d\n", StubMsg
.BufferLength
);
1465 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1466 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1467 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1469 ptr
= NdrConformantArrayMarshall( &StubMsg
, memsrc
, fmtstr_conf_array
);
1470 ok(ptr
== NULL
, "ret %p\n", ptr
);
1471 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== 20, "Buffer %p Start %p len %d\n", StubMsg
.Buffer
, StubMsg
.BufferStart
, 20);
1472 ok(!memcmp(StubMsg
.BufferStart
+ 4, memsrc
, 16), "incorrectly marshaled\n");
1474 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1475 StubMsg
.MemorySize
= 0;
1479 my_alloc_called
= 0;
1480 /* passing mem == NULL with must_alloc == 0 crashes under Windows */
1481 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1482 ok(mem
!= NULL
, "mem not alloced\n");
1483 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1484 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1486 my_alloc_called
= 0;
1487 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1489 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 0);
1490 ok(mem
== mem_orig
, "mem alloced\n");
1491 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1492 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1494 my_alloc_called
= 0;
1495 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1496 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1497 ok(mem
!= mem_orig
, "mem not alloced\n");
1498 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1499 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1502 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1503 NdrConformantArrayFree( &StubMsg
, mem
, fmtstr_conf_array
);
1504 ok(my_free_called
== 0, "free called %d\n", my_free_called
);
1505 StubMsg
.pfnFree(mem
);
1508 my_alloc_called
= 0;
1509 StubMsg
.IsClient
= 0;
1511 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1512 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 0);
1513 ok(mem
== StubMsg
.BufferStart
+ 4, "mem not pointing at buffer\n");
1514 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1515 my_alloc_called
= 0;
1517 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1518 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1519 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1520 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1521 StubMsg
.pfnFree(mem
);
1523 my_alloc_called
= 0;
1525 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1526 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 0);
1527 ok(mem
== mem_orig
, "mem alloced\n");
1528 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1530 my_alloc_called
= 0;
1532 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1533 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1534 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1535 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1536 StubMsg
.pfnFree(mem
);
1537 StubMsg
.pfnFree(mem_orig
);
1539 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1542 static void test_conformant_string(void)
1544 RPC_MESSAGE RpcMessage
;
1545 MIDL_STUB_MESSAGE StubMsg
;
1546 MIDL_STUB_DESC StubDesc
;
1549 unsigned char *mem
, *mem_orig
;
1550 char memsrc
[] = "This is a test string";
1552 static const unsigned char fmtstr_conf_str
[] =
1554 0x11, 0x8, /* FC_RP [simple_pointer] */
1555 0x22, /* FC_C_CSTRING */
1559 StubDesc
= Object_StubDesc
;
1560 StubDesc
.pFormatTypes
= fmtstr_conf_str
;
1562 NdrClientInitializeNew(
1568 StubMsg
.BufferLength
= 0;
1569 NdrPointerBufferSize( &StubMsg
,
1570 (unsigned char *)memsrc
,
1572 ok(StubMsg
.BufferLength
>= sizeof(memsrc
) + 12, "length %d\n", StubMsg
.BufferLength
);
1574 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1575 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1576 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1578 ptr
= NdrPointerMarshall( &StubMsg
, (unsigned char *)memsrc
, fmtstr_conf_str
);
1579 ok(ptr
== NULL
, "ret %p\n", ptr
);
1580 size
= StubMsg
.Buffer
- StubMsg
.BufferStart
;
1581 ok(size
== sizeof(memsrc
) + 12, "Buffer %p Start %p len %d\n",
1582 StubMsg
.Buffer
, StubMsg
.BufferStart
, size
);
1583 ok(!memcmp(StubMsg
.BufferStart
+ 12, memsrc
, sizeof(memsrc
)), "incorrectly marshaled\n");
1585 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1586 StubMsg
.MemorySize
= 0;
1590 my_alloc_called
= 0;
1591 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1592 mem
= mem_orig
= HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc
));
1593 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 0);
1594 ok(mem
== mem_orig
, "mem not alloced\n");
1595 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1597 my_alloc_called
= 0;
1598 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1599 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 1);
1601 ok(mem
== mem_orig
, "mem not alloced\n");
1602 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1606 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1607 NdrPointerFree( &StubMsg
, mem
, fmtstr_conf_str
);
1608 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
1612 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1613 NdrPointerFree( &StubMsg
, mem
, fmtstr_conf_str
);
1614 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
1617 my_alloc_called
= 0;
1618 StubMsg
.IsClient
= 0;
1620 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1621 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 0);
1622 ok(mem
== StubMsg
.BufferStart
+ 12, "mem not pointing at buffer\n");
1623 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1625 my_alloc_called
= 0;
1627 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1628 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 1);
1630 ok(mem
== StubMsg
.BufferStart
+ 12, "mem not pointing at buffer\n");
1631 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1634 my_alloc_called
= 0;
1636 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1637 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 0);
1638 ok(mem
== StubMsg
.BufferStart
+ 12, "mem not pointing at buffer\n");
1639 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1641 my_alloc_called
= 0;
1643 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1644 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 1);
1646 ok(mem
== StubMsg
.BufferStart
+ 12, "mem not pointing at buffer\n");
1647 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1652 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1653 NdrPointerFree( &StubMsg
, mem
, fmtstr_conf_str
);
1654 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
1656 HeapFree(GetProcessHeap(), 0, mem_orig
);
1657 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1660 static void test_nonconformant_string(void)
1662 RPC_MESSAGE RpcMessage
;
1663 MIDL_STUB_MESSAGE StubMsg
;
1664 MIDL_STUB_DESC StubDesc
;
1667 unsigned char *mem
, *mem_orig
;
1668 unsigned char memsrc
[10] = "This is";
1669 unsigned char memsrc2
[10] = "This is a";
1671 static const unsigned char fmtstr_nonconf_str
[] =
1673 0x26, /* FC_CSTRING */
1675 NdrFcShort( 0xa ), /* 10 */
1678 StubDesc
= Object_StubDesc
;
1679 StubDesc
.pFormatTypes
= fmtstr_nonconf_str
;
1682 NdrClientInitializeNew(
1688 StubMsg
.BufferLength
= 0;
1690 NdrNonConformantStringBufferSize( &StubMsg
, memsrc
, fmtstr_nonconf_str
);
1691 ok(StubMsg
.BufferLength
>= strlen((char *)memsrc
) + 1 + 8, "length %d\n", StubMsg
.BufferLength
);
1693 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1694 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1695 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1697 ptr
= NdrNonConformantStringMarshall( &StubMsg
, memsrc
, fmtstr_nonconf_str
);
1698 ok(ptr
== NULL
, "ret %p\n", ptr
);
1699 size
= StubMsg
.Buffer
- StubMsg
.BufferStart
;
1700 ok(size
== strlen((char *)memsrc
) + 1 + 8, "Buffer %p Start %p len %d\n",
1701 StubMsg
.Buffer
, StubMsg
.BufferStart
, size
);
1702 ok(!memcmp(StubMsg
.BufferStart
+ 8, memsrc
, strlen((char *)memsrc
) + 1), "incorrectly marshaled\n");
1704 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1705 StubMsg
.MemorySize
= 0;
1709 my_alloc_called
= 0;
1710 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1711 mem
= mem_orig
= HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc
));
1712 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1713 ok(mem
== mem_orig
, "mem alloced\n");
1714 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1716 my_alloc_called
= 0;
1717 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1718 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 1);
1720 ok(mem
== mem_orig
, "mem alloced\n");
1722 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1725 my_alloc_called
= 0;
1726 StubMsg
.IsClient
= 0;
1728 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1729 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1730 ok(mem
!= mem_orig
, "mem not alloced\n");
1731 ok(mem
!= StubMsg
.BufferStart
+ 8, "mem pointing at buffer\n");
1732 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1735 my_alloc_called
= 0;
1737 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1738 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1739 ok(mem
== mem_orig
, "mem alloced\n");
1740 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1742 my_alloc_called
= 0;
1744 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1745 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 1);
1747 ok(mem
== mem_orig
, "mem alloced\n");
1749 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1751 HeapFree(GetProcessHeap(), 0, mem_orig
);
1752 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1755 NdrClientInitializeNew(
1761 StubMsg
.BufferLength
= 0;
1763 NdrNonConformantStringBufferSize( &StubMsg
, memsrc2
, fmtstr_nonconf_str
);
1764 ok(StubMsg
.BufferLength
>= strlen((char *)memsrc2
) + 1 + 8, "length %d\n", StubMsg
.BufferLength
);
1766 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1767 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1768 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1770 ptr
= NdrNonConformantStringMarshall( &StubMsg
, memsrc2
, fmtstr_nonconf_str
);
1771 ok(ptr
== NULL
, "ret %p\n", ptr
);
1772 size
= StubMsg
.Buffer
- StubMsg
.BufferStart
;
1773 ok(size
== strlen((char *)memsrc2
) + 1 + 8, "Buffer %p Start %p len %d\n",
1774 StubMsg
.Buffer
, StubMsg
.BufferStart
, size
);
1775 ok(!memcmp(StubMsg
.BufferStart
+ 8, memsrc2
, strlen((char *)memsrc2
) + 1), "incorrectly marshaled\n");
1777 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1778 StubMsg
.MemorySize
= 0;
1782 my_alloc_called
= 0;
1783 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1784 mem
= mem_orig
= HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc
));
1785 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1786 ok(mem
== mem_orig
, "mem alloced\n");
1787 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1789 my_alloc_called
= 0;
1790 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1791 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 1);
1793 ok(mem
== mem_orig
, "mem alloced\n");
1795 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1798 my_alloc_called
= 0;
1799 StubMsg
.IsClient
= 0;
1801 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1802 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1803 ok(mem
!= mem_orig
, "mem not alloced\n");
1804 ok(mem
!= StubMsg
.BufferStart
+ 8, "mem pointing at buffer\n");
1805 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1808 my_alloc_called
= 0;
1810 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1811 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1812 ok(mem
== mem_orig
, "mem alloced\n");
1813 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1815 my_alloc_called
= 0;
1817 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1818 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 1);
1820 ok(mem
== mem_orig
, "mem alloced\n");
1822 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1824 HeapFree(GetProcessHeap(), 0, mem_orig
);
1825 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1828 static void test_conf_complex_struct(void)
1830 RPC_MESSAGE RpcMessage
;
1831 MIDL_STUB_MESSAGE StubMsg
;
1832 MIDL_STUB_DESC StubDesc
;
1838 unsigned int *array
[1];
1840 struct conf_complex
*memsrc
;
1841 struct conf_complex
*mem
;
1843 static const unsigned char fmtstr_complex_struct
[] =
1846 0x1b, /* FC_CARRAY */
1848 /* 2 */ NdrFcShort( 0x4 ), /* 4 */
1849 /* 4 */ 0x8, /* Corr desc: FC_LONG */
1851 /* 6 */ NdrFcShort( 0xfffc ), /* -4 */
1856 0x48, /* FC_VARIABLE_REPEAT */
1857 0x49, /* FC_FIXED_OFFSET */
1858 /* 12 */ NdrFcShort( 0x4 ), /* 4 */
1859 /* 14 */ NdrFcShort( 0x0 ), /* 0 */
1860 /* 16 */ NdrFcShort( 0x1 ), /* 1 */
1861 /* 18 */ NdrFcShort( 0x0 ), /* 0 */
1862 /* 20 */ NdrFcShort( 0x0 ), /* 0 */
1863 /* 22 */ 0x12, 0x8, /* FC_UP [simple_pointer] */
1864 /* 24 */ 0x8, /* FC_LONG */
1870 /* 28 */ 0x5c, /* FC_PAD */
1873 0x1a, /* FC_BOGUS_STRUCT */
1875 /* 32 */ NdrFcShort( 0x4 ), /* 4 */
1876 /* 34 */ NdrFcShort( 0xffffffde ), /* Offset= -34 (0) */
1877 /* 36 */ NdrFcShort( 0x0 ), /* Offset= 0 (36) */
1878 /* 38 */ 0x8, /* FC_LONG */
1882 memsrc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1883 FIELD_OFFSET(struct conf_complex
, array
[20]));
1886 StubDesc
= Object_StubDesc
;
1887 StubDesc
.pFormatTypes
= fmtstr_complex_struct
;
1889 NdrClientInitializeNew(
1895 StubMsg
.BufferLength
= 0;
1896 NdrComplexStructBufferSize( &StubMsg
,
1897 (unsigned char *)memsrc
,
1898 &fmtstr_complex_struct
[30] );
1899 ok(StubMsg
.BufferLength
>= 28, "length %d\n", StubMsg
.BufferLength
);
1901 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1902 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1903 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1905 ptr
= NdrComplexStructMarshall( &StubMsg
, (unsigned char *)memsrc
,
1906 &fmtstr_complex_struct
[30] );
1907 ok(ptr
== NULL
, "ret %p\n", ptr
);
1908 ok(*(unsigned int *)StubMsg
.BufferStart
== 20, "Conformance should have been 20 instead of %d\n", *(unsigned int *)StubMsg
.BufferStart
);
1909 ok(*(unsigned int *)(StubMsg
.BufferStart
+ 4) == 20, "conf_complex.size should have been 20 instead of %d\n", *(unsigned int *)(StubMsg
.BufferStart
+ 4));
1910 for (i
= 0; i
< 20; i
++)
1911 ok(*(unsigned int *)(StubMsg
.BufferStart
+ 8 + i
* 4) == 0, "pointer id for conf_complex.array[%d] should have been 0 instead of 0x%x\n", i
, *(unsigned int *)(StubMsg
.BufferStart
+ 8 + i
* 4));
1914 my_alloc_called
= 0;
1915 StubMsg
.IsClient
= 0;
1917 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1918 ptr
= NdrComplexStructUnmarshall( &StubMsg
, (unsigned char **)&mem
, &fmtstr_complex_struct
[30], 0);
1919 ok(ptr
== NULL
, "ret %p\n", ptr
);
1920 ok(mem
->size
== 20, "mem->size wasn't unmarshalled correctly (%d)\n", mem
->size
);
1921 ok(mem
->array
[0] == NULL
, "mem->array[0] wasn't unmarshalled correctly (%p)\n", mem
->array
[0]);
1922 StubMsg
.pfnFree(mem
);
1924 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1927 static void test_ndr_buffer(void)
1929 static unsigned char ncalrpc
[] = "ncalrpc";
1930 static unsigned char endpoint
[] = "winetest:test_ndr_buffer";
1931 RPC_MESSAGE RpcMessage
;
1932 MIDL_STUB_MESSAGE StubMsg
;
1933 MIDL_STUB_DESC StubDesc
= Object_StubDesc
;
1935 unsigned char *binding
;
1936 RPC_BINDING_HANDLE Handle
;
1938 ULONG prev_buffer_length
;
1939 BOOL old_buffer_valid_location
;
1941 StubDesc
.RpcInterfaceInformation
= (void *)&IFoo___RpcServerInterface
;
1943 status
= RpcServerUseProtseqEp(ncalrpc
, 20, endpoint
, NULL
);
1944 ok(RPC_S_OK
== status
, "RpcServerUseProtseqEp failed with status %u\n", status
);
1945 status
= RpcServerRegisterIf(IFoo_v0_0_s_ifspec
, NULL
, NULL
);
1946 ok(RPC_S_OK
== status
, "RpcServerRegisterIf failed with status %u\n", status
);
1947 status
= RpcServerListen(1, 20, TRUE
);
1948 ok(RPC_S_OK
== status
, "RpcServerListen failed with status %u\n", status
);
1949 if (status
!= RPC_S_OK
)
1951 /* Failed to create a server, running client tests is useless */
1955 status
= RpcStringBindingCompose(NULL
, ncalrpc
, NULL
, endpoint
, NULL
, &binding
);
1956 ok(status
== RPC_S_OK
, "RpcStringBindingCompose failed (%u)\n", status
);
1958 status
= RpcBindingFromStringBinding(binding
, &Handle
);
1959 ok(status
== RPC_S_OK
, "RpcBindingFromStringBinding failed (%u)\n", status
);
1960 RpcStringFree(&binding
);
1962 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &StubDesc
, 5);
1964 ret
= NdrGetBuffer(&StubMsg
, 10, Handle
);
1965 ok(ret
== StubMsg
.Buffer
, "NdrGetBuffer should have returned the same value as StubMsg.Buffer instead of %p\n", ret
);
1966 ok(RpcMessage
.Handle
!= NULL
, "RpcMessage.Handle should not have been NULL\n");
1967 ok(RpcMessage
.Buffer
!= NULL
, "RpcMessage.Buffer should not have been NULL\n");
1968 ok(RpcMessage
.BufferLength
== 10 ||
1969 broken(RpcMessage
.BufferLength
== 12), /* win2k */
1970 "RpcMessage.BufferLength should have been 10 instead of %d\n", RpcMessage
.BufferLength
);
1971 ok(RpcMessage
.RpcFlags
== 0, "RpcMessage.RpcFlags should have been 0x0 instead of 0x%x\n", RpcMessage
.RpcFlags
);
1972 ok(StubMsg
.Buffer
!= NULL
, "Buffer should not have been NULL\n");
1973 ok(!StubMsg
.BufferStart
, "BufferStart should have been NULL instead of %p\n", StubMsg
.BufferStart
);
1974 ok(!StubMsg
.BufferEnd
, "BufferEnd should have been NULL instead of %p\n", StubMsg
.BufferEnd
);
1976 ok(StubMsg
.BufferLength
== 0, "BufferLength should have left as 0 instead of being set to %d\n", StubMsg
.BufferLength
);
1977 old_buffer_valid_location
= !StubMsg
.fBufferValid
;
1978 if (old_buffer_valid_location
)
1979 ok(broken(StubMsg
.CorrDespIncrement
== TRUE
), "fBufferValid should have been TRUE instead of 0x%x\n", StubMsg
.CorrDespIncrement
);
1981 ok(StubMsg
.fBufferValid
, "fBufferValid should have been non-zero instead of 0x%x\n", StubMsg
.fBufferValid
);
1983 prev_buffer_length
= RpcMessage
.BufferLength
;
1984 StubMsg
.BufferLength
= 1;
1985 NdrFreeBuffer(&StubMsg
);
1986 ok(RpcMessage
.Handle
!= NULL
, "RpcMessage.Handle should not have been NULL\n");
1987 ok(RpcMessage
.Buffer
!= NULL
, "RpcMessage.Buffer should not have been NULL\n");
1988 ok(RpcMessage
.BufferLength
== prev_buffer_length
, "RpcMessage.BufferLength should have been left as %d instead of %d\n", prev_buffer_length
, RpcMessage
.BufferLength
);
1989 ok(StubMsg
.Buffer
!= NULL
, "Buffer should not have been NULL\n");
1990 ok(StubMsg
.BufferLength
== 1, "BufferLength should have left as 1 instead of being set to %d\n", StubMsg
.BufferLength
);
1991 if (old_buffer_valid_location
)
1992 ok(broken(StubMsg
.CorrDespIncrement
== FALSE
), "fBufferValid should have been FALSE instead of 0x%x\n", StubMsg
.CorrDespIncrement
);
1994 ok(!StubMsg
.fBufferValid
, "fBufferValid should have been FALSE instead of %d\n", StubMsg
.fBufferValid
);
1996 /* attempt double-free */
1997 NdrFreeBuffer(&StubMsg
);
1999 RpcBindingFree(&Handle
);
2001 status
= RpcServerUnregisterIf(NULL
, NULL
, FALSE
);
2002 ok(status
== RPC_S_OK
, "RpcServerUnregisterIf failed (%u)\n", status
);
2005 static void test_NdrMapCommAndFaultStatus(void)
2007 RPC_STATUS rpc_status
;
2008 MIDL_STUB_MESSAGE StubMsg
;
2009 RPC_MESSAGE RpcMessage
;
2011 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &Object_StubDesc
, 5);
2013 for (rpc_status
= 0; rpc_status
< 10000; rpc_status
++)
2016 ULONG comm_status
= 0;
2017 ULONG fault_status
= 0;
2018 ULONG expected_comm_status
= 0;
2019 ULONG expected_fault_status
= 0;
2020 status
= NdrMapCommAndFaultStatus(&StubMsg
, &comm_status
, &fault_status
, rpc_status
);
2021 ok(status
== RPC_S_OK
, "NdrMapCommAndFaultStatus failed with error %d\n", status
);
2024 case ERROR_INVALID_HANDLE
:
2025 case RPC_S_INVALID_BINDING
:
2026 case RPC_S_UNKNOWN_IF
:
2027 case RPC_S_SERVER_UNAVAILABLE
:
2028 case RPC_S_SERVER_TOO_BUSY
:
2029 case RPC_S_CALL_FAILED_DNE
:
2030 case RPC_S_PROTOCOL_ERROR
:
2031 case RPC_S_UNSUPPORTED_TRANS_SYN
:
2032 case RPC_S_UNSUPPORTED_TYPE
:
2033 case RPC_S_PROCNUM_OUT_OF_RANGE
:
2034 case EPT_S_NOT_REGISTERED
:
2035 case RPC_S_COMM_FAILURE
:
2036 expected_comm_status
= rpc_status
;
2039 expected_fault_status
= rpc_status
;
2041 ok(comm_status
== expected_comm_status
, "NdrMapCommAndFaultStatus should have mapped %d to comm status %d instead of %d\n",
2042 rpc_status
, expected_comm_status
, comm_status
);
2043 ok(fault_status
== expected_fault_status
, "NdrMapCommAndFaultStatus should have mapped %d to fault status %d instead of %d\n",
2044 rpc_status
, expected_fault_status
, fault_status
);
2048 static void test_NdrGetUserMarshalInfo(void)
2051 MIDL_STUB_MESSAGE stubmsg
;
2052 USER_MARSHAL_CB umcb
;
2053 NDR_USER_MARSHAL_INFO umi
;
2054 unsigned char buffer
[16];
2055 void *rpc_channel_buffer
= (void *)(ULONG_PTR
)0xcafebabe;
2056 RPC_MESSAGE rpc_msg
;
2057 RPC_STATUS (RPC_ENTRY
*pNdrGetUserMarshalInfo
)(ULONG
*,ULONG
,NDR_USER_MARSHAL_INFO
*);
2059 pNdrGetUserMarshalInfo
= (void *)GetProcAddress(GetModuleHandle("rpcrt4.dll"), "NdrGetUserMarshalInfo");
2060 if (!pNdrGetUserMarshalInfo
)
2062 skip("NdrGetUserMarshalInfo not exported\n");
2068 memset(&rpc_msg
, 0xcc, sizeof(rpc_msg
));
2069 rpc_msg
.Buffer
= buffer
;
2070 rpc_msg
.BufferLength
= 16;
2072 memset(&stubmsg
, 0xcc, sizeof(stubmsg
));
2073 stubmsg
.RpcMsg
= &rpc_msg
;
2074 stubmsg
.dwDestContext
= MSHCTX_INPROC
;
2075 stubmsg
.pvDestContext
= NULL
;
2076 stubmsg
.Buffer
= buffer
+ 15;
2077 stubmsg
.BufferLength
= 0;
2078 stubmsg
.BufferEnd
= NULL
;
2079 stubmsg
.pRpcChannelBuffer
= rpc_channel_buffer
;
2080 stubmsg
.StubDesc
= NULL
;
2081 stubmsg
.pfnAllocate
= my_alloc
;
2082 stubmsg
.pfnFree
= my_free
;
2084 memset(&umcb
, 0xcc, sizeof(umcb
));
2085 umcb
.Flags
= MAKELONG(MSHCTX_INPROC
, NDR_LOCAL_DATA_REPRESENTATION
);
2086 umcb
.pStubMsg
= &stubmsg
;
2087 umcb
.Signature
= USER_MARSHAL_CB_SIGNATURE
;
2088 umcb
.CBType
= USER_MARSHAL_CB_UNMARSHALL
;
2090 memset(&umi
, 0xaa, sizeof(umi
));
2092 status
= pNdrGetUserMarshalInfo(&umcb
.Flags
, 1, &umi
);
2093 ok(status
== RPC_S_OK
, "NdrGetUserMarshalInfo failed with error %d\n", status
);
2094 ok( umi
.InformationLevel
== 1,
2095 "umi.InformationLevel was %u instead of 1\n",
2096 umi
.InformationLevel
);
2097 ok( U(umi
.Level1
).Buffer
== buffer
+ 15,
2098 "U(umi.Level1).Buffer was %p instead of %p\n",
2099 U(umi
.Level1
).Buffer
, buffer
);
2100 ok( U(umi
.Level1
).BufferSize
== 1,
2101 "U(umi.Level1).BufferSize was %u instead of 1\n",
2102 U(umi
.Level1
).BufferSize
);
2103 ok( U(umi
.Level1
).pfnAllocate
== my_alloc
,
2104 "U(umi.Level1).pfnAllocate was %p instead of %p\n",
2105 U(umi
.Level1
).pfnAllocate
, my_alloc
);
2106 ok( U(umi
.Level1
).pfnFree
== my_free
,
2107 "U(umi.Level1).pfnFree was %p instead of %p\n",
2108 U(umi
.Level1
).pfnFree
, my_free
);
2109 ok( U(umi
.Level1
).pRpcChannelBuffer
== rpc_channel_buffer
,
2110 "U(umi.Level1).pRpcChannelBuffer was %p instead of %p\n",
2111 U(umi
.Level1
).pRpcChannelBuffer
, rpc_channel_buffer
);
2115 rpc_msg
.Buffer
= buffer
;
2116 rpc_msg
.BufferLength
= 16;
2118 stubmsg
.Buffer
= buffer
;
2119 stubmsg
.BufferLength
= 16;
2120 stubmsg
.BufferEnd
= NULL
;
2122 umcb
.CBType
= USER_MARSHAL_CB_BUFFER_SIZE
;
2124 memset(&umi
, 0xaa, sizeof(umi
));
2126 status
= pNdrGetUserMarshalInfo(&umcb
.Flags
, 1, &umi
);
2127 ok(status
== RPC_S_OK
, "NdrGetUserMarshalInfo failed with error %d\n", status
);
2128 ok( umi
.InformationLevel
== 1,
2129 "umi.InformationLevel was %u instead of 1\n",
2130 umi
.InformationLevel
);
2131 ok( U(umi
.Level1
).Buffer
== NULL
,
2132 "U(umi.Level1).Buffer was %p instead of NULL\n",
2133 U(umi
.Level1
).Buffer
);
2134 ok( U(umi
.Level1
).BufferSize
== 0,
2135 "U(umi.Level1).BufferSize was %u instead of 0\n",
2136 U(umi
.Level1
).BufferSize
);
2137 ok( U(umi
.Level1
).pfnAllocate
== my_alloc
,
2138 "U(umi.Level1).pfnAllocate was %p instead of %p\n",
2139 U(umi
.Level1
).pfnAllocate
, my_alloc
);
2140 ok( U(umi
.Level1
).pfnFree
== my_free
,
2141 "U(umi.Level1).pfnFree was %p instead of %p\n",
2142 U(umi
.Level1
).pfnFree
, my_free
);
2143 ok( U(umi
.Level1
).pRpcChannelBuffer
== rpc_channel_buffer
,
2144 "U(umi.Level1).pRpcChannelBuffer was %p instead of %p\n",
2145 U(umi
.Level1
).pRpcChannelBuffer
, rpc_channel_buffer
);
2149 rpc_msg
.Buffer
= buffer
;
2150 rpc_msg
.BufferLength
= 16;
2152 stubmsg
.Buffer
= buffer
+ 15;
2153 stubmsg
.BufferLength
= 0;
2154 stubmsg
.BufferEnd
= NULL
;
2156 umcb
.CBType
= USER_MARSHAL_CB_MARSHALL
;
2158 memset(&umi
, 0xaa, sizeof(umi
));
2160 status
= pNdrGetUserMarshalInfo(&umcb
.Flags
, 1, &umi
);
2161 ok(status
== RPC_S_OK
, "NdrGetUserMarshalInfo failed with error %d\n", status
);
2162 ok( umi
.InformationLevel
== 1,
2163 "umi.InformationLevel was %u instead of 1\n",
2164 umi
.InformationLevel
);
2165 ok( U(umi
.Level1
).Buffer
== buffer
+ 15,
2166 "U(umi.Level1).Buffer was %p instead of %p\n",
2167 U(umi
.Level1
).Buffer
, buffer
);
2168 ok( U(umi
.Level1
).BufferSize
== 1,
2169 "U(umi.Level1).BufferSize was %u instead of 1\n",
2170 U(umi
.Level1
).BufferSize
);
2171 ok( U(umi
.Level1
).pfnAllocate
== my_alloc
,
2172 "U(umi.Level1).pfnAllocate was %p instead of %p\n",
2173 U(umi
.Level1
).pfnAllocate
, my_alloc
);
2174 ok( U(umi
.Level1
).pfnFree
== my_free
,
2175 "U(umi.Level1).pfnFree was %p instead of %p\n",
2176 U(umi
.Level1
).pfnFree
, my_free
);
2177 ok( U(umi
.Level1
).pRpcChannelBuffer
== rpc_channel_buffer
,
2178 "U(umi.Level1).pRpcChannelBuffer was %p instead of %p\n",
2179 U(umi
.Level1
).pRpcChannelBuffer
, rpc_channel_buffer
);
2183 rpc_msg
.Buffer
= buffer
;
2184 rpc_msg
.BufferLength
= 16;
2186 stubmsg
.Buffer
= buffer
;
2187 stubmsg
.BufferLength
= 16;
2188 stubmsg
.BufferEnd
= NULL
;
2190 umcb
.CBType
= USER_MARSHAL_CB_FREE
;
2192 memset(&umi
, 0xaa, sizeof(umi
));
2194 status
= pNdrGetUserMarshalInfo(&umcb
.Flags
, 1, &umi
);
2195 ok(status
== RPC_S_OK
, "NdrGetUserMarshalInfo failed with error %d\n", status
);
2196 ok( umi
.InformationLevel
== 1,
2197 "umi.InformationLevel was %u instead of 1\n",
2198 umi
.InformationLevel
);
2199 ok( U(umi
.Level1
).Buffer
== NULL
,
2200 "U(umi.Level1).Buffer was %p instead of NULL\n",
2201 U(umi
.Level1
).Buffer
);
2202 ok( U(umi
.Level1
).BufferSize
== 0,
2203 "U(umi.Level1).BufferSize was %u instead of 0\n",
2204 U(umi
.Level1
).BufferSize
);
2205 ok( U(umi
.Level1
).pfnAllocate
== my_alloc
,
2206 "U(umi.Level1).pfnAllocate was %p instead of %p\n",
2207 U(umi
.Level1
).pfnAllocate
, my_alloc
);
2208 ok( U(umi
.Level1
).pfnFree
== my_free
,
2209 "U(umi.Level1).pfnFree was %p instead of %p\n",
2210 U(umi
.Level1
).pfnFree
, my_free
);
2211 ok( U(umi
.Level1
).pRpcChannelBuffer
== rpc_channel_buffer
,
2212 "U(umi.Level1).pRpcChannelBuffer was %p instead of %p\n",
2213 U(umi
.Level1
).pRpcChannelBuffer
, rpc_channel_buffer
);
2217 rpc_msg
.Buffer
= buffer
;
2218 rpc_msg
.BufferLength
= 15;
2220 stubmsg
.Buffer
= buffer
+ 15;
2221 stubmsg
.BufferLength
= 0;
2222 stubmsg
.BufferEnd
= NULL
;
2224 umcb
.CBType
= USER_MARSHAL_CB_MARSHALL
;
2226 status
= pNdrGetUserMarshalInfo(&umcb
.Flags
, 1, &umi
);
2227 ok(status
== RPC_S_OK
, "NdrGetUserMarshalInfo failed with error %d\n", status
);
2228 ok( U(umi
.Level1
).BufferSize
== 0,
2229 "U(umi.Level1).BufferSize was %u instead of 0\n",
2230 U(umi
.Level1
).BufferSize
);
2232 /* error conditions */
2234 rpc_msg
.BufferLength
= 14;
2235 status
= pNdrGetUserMarshalInfo(&umcb
.Flags
, 1, &umi
);
2236 ok(status
== ERROR_INVALID_USER_BUFFER
,
2237 "NdrGetUserMarshalInfo should have failed with ERROR_INVALID_USER_BUFFER instead of %d\n", status
);
2239 rpc_msg
.BufferLength
= 15;
2240 status
= pNdrGetUserMarshalInfo(&umcb
.Flags
, 9999, &umi
);
2241 ok(status
== RPC_S_INVALID_ARG
,
2242 "NdrGetUserMarshalInfo should have failed with RPC_S_INVALID_ARG instead of %d\n", status
);
2245 status
= pNdrGetUserMarshalInfo(&umcb
.Flags
, 1, &umi
);
2246 ok(status
== RPC_S_OK
, "NdrGetUserMarshalInfo failed with error %d\n", status
);
2248 umcb
.CBType
= USER_MARSHAL_CB_MARSHALL
;
2250 status
= pNdrGetUserMarshalInfo(&umcb
.Flags
, 1, &umi
);
2251 ok(status
== RPC_S_INVALID_ARG
,
2252 "NdrGetUserMarshalInfo should have failed with RPC_S_INVALID_ARG instead of %d\n", status
);
2255 START_TEST( ndr_marshall
)
2257 determine_pointer_marshalling_style();
2259 test_ndr_simple_type();
2260 test_simple_types();
2261 test_nontrivial_pointer_types();
2262 test_simple_struct();
2263 test_fullpointer_xlat();
2266 test_ndr_allocate();
2267 test_conformant_array();
2268 test_conformant_string();
2269 test_nonconformant_string();
2270 test_conf_complex_struct();
2272 test_NdrMapCommAndFaultStatus();
2273 test_NdrGetUserMarshalInfo();