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)≪
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 /* verify stub data that is identical between client and server */
1114 static void test_common_stub_data( const char *prefix, const MIDL_STUB_MESSAGE *stubMsg )
1118 memset(&unset_ptr, 0xcc, sizeof(unset_ptr));
1120 #define TEST_ZERO(field, fmt) ok(stubMsg->field == 0, "%s: " #field " should have been set to zero instead of " fmt "\n", prefix, stubMsg->field)
1121 #define TEST_POINTER_UNSET(field) ok(stubMsg->field == unset_ptr, "%s: " #field " should have been unset instead of %p\n", prefix, stubMsg->field)
1122 #define TEST_ULONG_UNSET(field) ok(stubMsg->field == 0xcccccccc, "%s: " #field " should have been unset instead of 0x%x\n", prefix, stubMsg->field)
1123 #define TEST_ULONG_PTR_UNSET(field) ok(stubMsg->field == (ULONG_PTR)unset_ptr, "%s: " #field " should have been unset instead of 0x%lx\n", prefix, stubMsg->field)
1125 TEST_POINTER_UNSET(BufferMark);
1126 TEST_ULONG_UNSET(MemorySize);
1127 TEST_POINTER_UNSET(Memory);
1128 TEST_ZERO(pAllocAllNodesContext, "%p");
1129 ok(stubMsg->pPointerQueueState == 0 ||
1130 broken(stubMsg->pPointerQueueState == unset_ptr), /* win2k */
1131 "%s: pPointerQueueState should have been unset instead of %p\n",
1132 prefix, stubMsg->pPointerQueueState);
1133 TEST_ZERO(IgnoreEmbeddedPointers, "%d");
1134 TEST_ZERO(PointerBufferMark, "%p");
1135 ok( stubMsg->uFlags == 0 ||
1136 broken(stubMsg->uFlags == 0xcc), /* win9x */
1137 "%s: uFlags should have been set to zero instead of 0x%x\n", prefix, stubMsg->uFlags );
1138 /* FIXME: UniquePtrCount */
1139 TEST_ULONG_PTR_UNSET(MaxCount);
1140 TEST_ULONG_UNSET(Offset);
1141 TEST_ULONG_UNSET(ActualCount);
1142 ok(stubMsg->pfnAllocate == my_alloc, "%s: pfnAllocate should have been %p instead of %p\n",
1143 prefix, my_alloc, stubMsg->pfnAllocate);
1144 ok(stubMsg->pfnFree == my_free, "%s: pfnFree should have been %p instead of %p\n",
1145 prefix, my_free, stubMsg->pfnFree);
1146 TEST_ZERO(StackTop, "%p");
1147 TEST_POINTER_UNSET(pPresentedType);
1148 TEST_POINTER_UNSET(pTransmitType);
1149 TEST_POINTER_UNSET(SavedHandle);
1150 ok(stubMsg->StubDesc == &Object_StubDesc, "%s: StubDesc should have been %p instead of %p\n",
1151 prefix, &Object_StubDesc, stubMsg->StubDesc);
1152 TEST_ZERO(FullPtrRefId, "%d");
1153 ok( stubMsg->PointerLength == 0 ||
1154 broken(stubMsg->PointerLength == 1), /* win9x, nt4 */
1155 "%s: pAsyncMsg should have been set to zero instead of %d\n", prefix, stubMsg->PointerLength );
1156 TEST_ZERO(fInDontFree, "%d");
1157 TEST_ZERO(fDontCallFreeInst, "%d");
1158 ok(stubMsg->fInOnlyParam == 0 ||
1159 stubMsg->fInOnlyParam == -1, /* Vista */
1160 "%s: fInOnlyParam should have been set to 0 or -1 instead of %d\n", prefix, stubMsg->fInOnlyParam);
1161 ok( stubMsg->fHasReturn == 0 ||
1162 broken(stubMsg->fHasReturn == -1), /* win9x, nt4 */
1163 "%s: fHasReturn should have been set to zero instead of %d\n", prefix, stubMsg->fHasReturn );
1164 TEST_ZERO(fHasExtensions, "%d");
1165 TEST_ZERO(fHasNewCorrDesc, "%d");
1166 ok(stubMsg->fIsIn == 0 ||
1167 broken(stubMsg->fIsIn == -1), /* win9x, nt4 */
1168 "%s: fIsIn should have been set to 0 instead of %d\n", prefix, stubMsg->fIsIn);
1169 ok(stubMsg->fIsOut == 0 ||
1170 stubMsg->fIsOut == -1, /* XP-SP3 */
1171 "%s: fIsOut should have been set to 0 or -1 instead of %d\n", prefix, stubMsg->fIsOut);
1172 TEST_ZERO(fIsOicf, "%d");
1173 ok(stubMsg->fBufferValid == 0,
1174 "%s: fBufferValid should have been set to 0 instead of %d\n", prefix, stubMsg->fBufferValid);
1175 ok(stubMsg->fHasMemoryValidateCallback == 0 ||
1176 stubMsg->fHasMemoryValidateCallback == -1, /* XP-SP3 */
1177 "%s: fHasMemoryValidateCallback should have been set to 0 or -1 instead of %d\n",
1178 prefix, stubMsg->fHasMemoryValidateCallback);
1179 ok(stubMsg->fInFree == 0 ||
1180 stubMsg->fInFree == -1, /* XP-SP3 */
1181 "%s: fInFree should have been set to 0 or -1 instead of %d\n", prefix, stubMsg->fInFree);
1182 TEST_ZERO(fNeedMCCP, "%d");
1183 ok(stubMsg->fUnused == 0 ||
1184 stubMsg->fUnused == -2, /* Vista */
1185 "%s: fUnused should have been set to 0 or -2 instead of %d\n", prefix, stubMsg->fUnused);
1186 ok(stubMsg->fUnused2 == 0xffffcccc, "%s: fUnused2 should have been 0xffffcccc instead of 0x%x\n",
1187 prefix, stubMsg->fUnused2);
1188 ok(stubMsg->dwDestContext == MSHCTX_DIFFERENTMACHINE,
1189 "%s: dwDestContext should have been MSHCTX_DIFFERENTMACHINE instead of %d\n",
1190 prefix, stubMsg->dwDestContext);
1191 TEST_ZERO(pvDestContext, "%p");
1192 TEST_POINTER_UNSET(SavedContextHandles);
1193 TEST_ULONG_UNSET(ParamNumber);
1194 TEST_ZERO(pRpcChannelBuffer, "%p");
1195 TEST_ZERO(pArrayInfo, "%p");
1196 TEST_POINTER_UNSET(SizePtrCountArray);
1197 TEST_POINTER_UNSET(SizePtrOffsetArray);
1198 TEST_POINTER_UNSET(SizePtrLengthArray);
1199 TEST_POINTER_UNSET(pArgQueue);
1200 TEST_ZERO(dwStubPhase, "%d");
1201 /* FIXME: where does this value come from? */
1202 trace("%s: LowStackMark is %p\n", prefix, stubMsg->LowStackMark);
1203 ok( stubMsg->pAsyncMsg == 0 || broken(stubMsg->pAsyncMsg == unset_ptr), /* win9x, nt4 */
1204 "%s: pAsyncMsg should have been set to zero instead of %p\n", prefix, stubMsg->pAsyncMsg );
1205 ok( stubMsg->pCorrInfo == 0 || broken(stubMsg->pCorrInfo == unset_ptr), /* win9x, nt4 */
1206 "%s: pCorrInfo should have been set to zero instead of %p\n", prefix, stubMsg->pCorrInfo );
1207 ok( stubMsg->pCorrMemory == 0 || broken(stubMsg->pCorrMemory == unset_ptr), /* win9x, nt4 */
1208 "%s: pCorrMemory should have been set to zero instead of %p\n", prefix, stubMsg->pCorrMemory );
1209 ok( stubMsg->pMemoryList == 0 || broken(stubMsg->pMemoryList == unset_ptr), /* win9x, nt4 */
1210 "%s: pMemoryList should have been set to zero instead of %p\n", prefix, stubMsg->pMemoryList );
1211 TEST_POINTER_UNSET(pCSInfo);
1212 TEST_POINTER_UNSET(ConformanceMark);
1213 TEST_POINTER_UNSET(VarianceMark);
1214 ok(stubMsg->Unused == (ULONG_PTR)unset_ptr, "%s: Unused should have be unset instead of 0x%lx\n",
1215 prefix, stubMsg->Unused);
1216 TEST_POINTER_UNSET(pContext);
1217 TEST_POINTER_UNSET(ContextHandleHash);
1218 TEST_POINTER_UNSET(pUserMarshalList);
1219 TEST_ULONG_PTR_UNSET(Reserved51_3);
1220 TEST_ULONG_PTR_UNSET(Reserved51_4);
1221 TEST_ULONG_PTR_UNSET(Reserved51_5);
1223 #undef TEST_ULONG_PTR_UNSET
1224 #undef TEST_ULONG_UNSET
1225 #undef TEST_POINTER_UNSET
1229 static void test_client_init(void)
1231 MIDL_STUB_MESSAGE stubMsg;
1235 memset(&rpcMsg, 0xcc, sizeof(rpcMsg));
1236 memset(&stubMsg, 0xcc, sizeof(stubMsg));
1237 memset(&unset_ptr, 0xcc, sizeof(unset_ptr));
1239 NdrClientInitializeNew(&rpcMsg, &stubMsg, &Object_StubDesc, 1);
1241 test_common_stub_data( "NdrClientInitializeNew", &stubMsg );
1243 ok(stubMsg.RpcMsg == &rpcMsg, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg, stubMsg.RpcMsg);
1244 ok(rpcMsg.Handle == NULL, "rpcMsg.Handle should have been NULL instead of %p\n", rpcMsg.Handle);
1245 ok(rpcMsg.Buffer == unset_ptr, "rpcMsg.Buffer should have been unset instead of %p\n",
1247 ok(rpcMsg.BufferLength == 0xcccccccc, "rpcMsg.BufferLength should have been unset instead of %d\n", rpcMsg.BufferLength);
1248 ok(rpcMsg.ProcNum == 0x8001, "rpcMsg.ProcNum should have been 0x8001 instead of 0x%x\n", rpcMsg.ProcNum);
1249 ok(rpcMsg.TransferSyntax == unset_ptr, "rpcMsg.TransferSyntax should have been unset instead of %p\n", rpcMsg.TransferSyntax);
1250 ok(rpcMsg.RpcInterfaceInformation == Object_StubDesc.RpcInterfaceInformation,
1251 "rpcMsg.RpcInterfaceInformation should have been %p instead of %p\n",
1252 Object_StubDesc.RpcInterfaceInformation, rpcMsg.RpcInterfaceInformation);
1253 /* Note: ReservedForRuntime not tested */
1254 ok(rpcMsg.ManagerEpv == unset_ptr, "rpcMsg.ManagerEpv should have been unset instead of %p\n", rpcMsg.ManagerEpv);
1255 ok(rpcMsg.ImportContext == unset_ptr, "rpcMsg.ImportContext should have been unset instead of %p\n", rpcMsg.ImportContext);
1256 ok(rpcMsg.RpcFlags == 0, "rpcMsg.RpcFlags should have been 0 instead of 0x%x\n", rpcMsg.RpcFlags);
1258 ok(stubMsg.Buffer == unset_ptr, "stubMsg.Buffer should have been unset instead of %p\n",
1260 ok(stubMsg.BufferStart == NULL, "stubMsg.BufferStart should have been NULL instead of %p\n",
1261 stubMsg.BufferStart);
1262 ok(stubMsg.BufferEnd == NULL, "stubMsg.BufferEnd should have been NULL instead of %p\n",
1264 ok(stubMsg.BufferLength == 0, "stubMsg.BufferLength should have been 0 instead of %u\n",
1265 stubMsg.BufferLength);
1266 ok(stubMsg.IsClient == 1, "stubMsg.IsClient should have been 1 instead of %u\n", stubMsg.IsClient);
1267 ok(stubMsg.ReuseBuffer == 0, "stubMsg.ReuseBuffer should have been 0 instead of %d\n",
1268 stubMsg.ReuseBuffer);
1269 ok(stubMsg.CorrDespIncrement == 0, "stubMsg.CorrDespIncrement should have been 0 instead of %d\n",
1270 stubMsg.CorrDespIncrement);
1271 ok(stubMsg.FullPtrXlatTables == unset_ptr, "stubMsg.FullPtrXlatTables should have been unset instead of %p\n",
1272 stubMsg.FullPtrXlatTables);
1275 static void test_server_init(void)
1277 MIDL_STUB_MESSAGE stubMsg;
1280 unsigned char buffer[256];
1282 memset(&rpcMsg, 0, sizeof(rpcMsg));
1283 rpcMsg.Buffer = buffer;
1284 rpcMsg.BufferLength = sizeof(buffer);
1285 rpcMsg.RpcFlags = RPC_BUFFER_COMPLETE;
1287 memset(&stubMsg, 0xcc, sizeof(stubMsg));
1289 ret = NdrServerInitializeNew(&rpcMsg, &stubMsg, &Object_StubDesc);
1290 ok(ret == NULL, "NdrServerInitializeNew should have returned NULL instead of %p\n", ret);
1292 test_common_stub_data( "NdrServerInitializeNew", &stubMsg );
1294 ok(stubMsg.RpcMsg == &rpcMsg, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg, stubMsg.RpcMsg);
1295 ok(stubMsg.Buffer == buffer, "stubMsg.Buffer should have been %p instead of %p\n", buffer, stubMsg.Buffer);
1296 ok(stubMsg.BufferStart == buffer, "stubMsg.BufferStart should have been %p instead of %p\n", buffer, stubMsg.BufferStart);
1297 ok(stubMsg.BufferEnd == buffer + sizeof(buffer), "stubMsg.BufferEnd should have been %p instead of %p\n", buffer + sizeof(buffer), stubMsg.BufferEnd);
1299 ok(stubMsg.BufferLength == 0, "stubMsg.BufferLength should have been 0 instead of %u\n", stubMsg.BufferLength);
1300 ok(stubMsg.IsClient == 0, "stubMsg.IsClient should have been 0 instead of %u\n", stubMsg.IsClient);
1301 ok(stubMsg.ReuseBuffer == 0 ||
1302 broken(stubMsg.ReuseBuffer == 1), /* win2k */
1303 "stubMsg.ReuseBuffer should have been set to zero instead of %d\n", stubMsg.ReuseBuffer);
1304 ok(stubMsg.CorrDespIncrement == 0xcc ||
1305 stubMsg.CorrDespIncrement == 0,
1306 "CorrDespIncrement should have been unset instead of 0x%x\n", stubMsg.CorrDespIncrement);
1307 ok(stubMsg.FullPtrXlatTables == 0, "stubMsg.BufferLength should have been 0 instead of %p\n", stubMsg.FullPtrXlatTables);
1310 static void test_ndr_allocate(void)
1312 RPC_MESSAGE RpcMessage;
1313 MIDL_STUB_MESSAGE StubMsg;
1314 MIDL_STUB_DESC StubDesc;
1316 struct tag_mem_list_v2_t
1321 struct tag_mem_list_v2_t *next;
1323 const DWORD magic_MEML = 'M' << 24 | 'E' << 16 | 'M' << 8 | 'L';
1325 StubDesc = Object_StubDesc;
1326 NdrClientInitializeNew(&RpcMessage, &StubMsg, &StubDesc, 0);
1328 my_alloc_called = my_free_called = 0;
1329 p1 = NdrAllocate(&StubMsg, 10);
1330 p2 = NdrAllocate(&StubMsg, 24);
1331 ok(my_alloc_called == 2, "alloc called %d\n", my_alloc_called);
1332 ok(StubMsg.pMemoryList != NULL, "StubMsg.pMemoryList NULL\n");
1333 if(StubMsg.pMemoryList)
1335 mem_list_v2 = StubMsg.pMemoryList;
1336 if (mem_list_v2->size == 24)
1338 trace("v2 mem list format\n");
1339 ok((char *)mem_list_v2 == (char *)p2 + 24, "expected mem_list_v2 pointer %p, but got %p\n", (char *)p2 + 24, mem_list_v2);
1340 ok(mem_list_v2->magic == magic_MEML, "magic %08x\n", mem_list_v2->magic);
1341 ok(mem_list_v2->size == 24, "wrong size for p2 %d\n", mem_list_v2->size);
1342 ok(mem_list_v2->unknown == 0, "wrong unknown for p2 0x%x\n", mem_list_v2->unknown);
1343 ok(mem_list_v2->next != NULL, "next NULL\n");
1344 mem_list_v2 = mem_list_v2->next;
1347 ok((char *)mem_list_v2 == (char *)p1 + 16, "expected mem_list_v2 pointer %p, but got %p\n", (char *)p1 + 16, mem_list_v2);
1348 ok(mem_list_v2->magic == magic_MEML, "magic %08x\n", mem_list_v2->magic);
1349 ok(mem_list_v2->size == 16, "wrong size for p1 %d\n", mem_list_v2->size);
1350 ok(mem_list_v2->unknown == 0, "wrong unknown for p1 0x%x\n", mem_list_v2->unknown);
1351 ok(mem_list_v2->next == NULL, "next %p\n", mem_list_v2->next);
1354 else win_skip("v1 mem list format\n");
1356 /* NdrFree isn't exported so we can't test free'ing */
1359 static void test_conformant_array(void)
1361 RPC_MESSAGE RpcMessage;
1362 MIDL_STUB_MESSAGE StubMsg;
1363 MIDL_STUB_DESC StubDesc;
1365 unsigned char *mem, *mem_orig;
1366 unsigned char memsrc[20];
1369 static const unsigned char fmtstr_conf_array[] =
1371 0x1b, /* FC_CARRAY */
1373 NdrFcShort( 0x1 ), /* elem size */
1374 0x40, /* Corr desc: const */
1376 NdrFcShort(0x10), /* const = 0x10 */
1381 for (i = 0; i < sizeof(memsrc); i++)
1384 StubDesc = Object_StubDesc;
1385 StubDesc.pFormatTypes = fmtstr_conf_array;
1387 NdrClientInitializeNew(
1393 StubMsg.BufferLength = 0;
1394 NdrConformantArrayBufferSize( &StubMsg,
1396 fmtstr_conf_array );
1397 ok(StubMsg.BufferLength >= 20, "length %d\n", StubMsg.BufferLength);
1399 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1400 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
1401 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
1403 ptr = NdrConformantArrayMarshall( &StubMsg, memsrc, fmtstr_conf_array );
1404 ok(ptr == NULL, "ret %p\n", ptr);
1405 ok(StubMsg.Buffer - StubMsg.BufferStart == 20, "Buffer %p Start %p len %d\n", StubMsg.Buffer, StubMsg.BufferStart, 20);
1406 ok(!memcmp(StubMsg.BufferStart + 4, memsrc, 16), "incorrectly marshaled\n");
1408 StubMsg.Buffer = StubMsg.BufferStart;
1409 StubMsg.MemorySize = 0;
1413 my_alloc_called = 0;
1414 /* passing mem == NULL with must_alloc == 0 crashes under Windows */
1415 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1416 ok(mem != NULL, "mem not alloced\n");
1417 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1418 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1420 my_alloc_called = 0;
1421 StubMsg.Buffer = StubMsg.BufferStart;
1423 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 0);
1424 ok(mem == mem_orig, "mem alloced\n");
1425 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1426 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1428 my_alloc_called = 0;
1429 StubMsg.Buffer = StubMsg.BufferStart;
1430 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1431 ok(mem != mem_orig, "mem not alloced\n");
1432 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1433 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1436 StubMsg.Buffer = StubMsg.BufferStart;
1437 NdrConformantArrayFree( &StubMsg, mem, fmtstr_conf_array );
1438 ok(my_free_called == 0, "free called %d\n", my_free_called);
1439 StubMsg.pfnFree(mem);
1442 my_alloc_called = 0;
1443 StubMsg.IsClient = 0;
1445 StubMsg.Buffer = StubMsg.BufferStart;
1446 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 0);
1447 ok(mem == StubMsg.BufferStart + 4, "mem not pointing at buffer\n");
1448 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1449 my_alloc_called = 0;
1451 StubMsg.Buffer = StubMsg.BufferStart;
1452 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1453 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1454 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1455 StubMsg.pfnFree(mem);
1457 my_alloc_called = 0;
1459 StubMsg.Buffer = StubMsg.BufferStart;
1460 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 0);
1461 ok(mem == mem_orig, "mem alloced\n");
1462 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1464 my_alloc_called = 0;
1466 StubMsg.Buffer = StubMsg.BufferStart;
1467 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1468 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1469 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1470 StubMsg.pfnFree(mem);
1471 StubMsg.pfnFree(mem_orig);
1473 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
1476 static void test_conformant_string(void)
1478 RPC_MESSAGE RpcMessage;
1479 MIDL_STUB_MESSAGE StubMsg;
1480 MIDL_STUB_DESC StubDesc;
1483 unsigned char *mem, *mem_orig;
1484 char memsrc[] = "This is a test string";
1486 static const unsigned char fmtstr_conf_str[] =
1488 0x11, 0x8, /* FC_RP [simple_pointer] */
1489 0x22, /* FC_C_CSTRING */
1493 StubDesc = Object_StubDesc;
1494 StubDesc.pFormatTypes = fmtstr_conf_str;
1496 NdrClientInitializeNew(
1502 StubMsg.BufferLength = 0;
1503 NdrPointerBufferSize( &StubMsg,
1504 (unsigned char *)memsrc,
1506 ok(StubMsg.BufferLength >= sizeof(memsrc) + 12, "length %d\n", StubMsg.BufferLength);
1508 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1509 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
1510 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
1512 ptr = NdrPointerMarshall( &StubMsg, (unsigned char *)memsrc, fmtstr_conf_str );
1513 ok(ptr == NULL, "ret %p\n", ptr);
1514 size = StubMsg.Buffer - StubMsg.BufferStart;
1515 ok(size == sizeof(memsrc) + 12, "Buffer %p Start %p len %d\n",
1516 StubMsg.Buffer, StubMsg.BufferStart, size);
1517 ok(!memcmp(StubMsg.BufferStart + 12, memsrc, sizeof(memsrc)), "incorrectly marshaled\n");
1519 StubMsg.Buffer = StubMsg.BufferStart;
1520 StubMsg.MemorySize = 0;
1524 my_alloc_called = 0;
1525 StubMsg.Buffer = StubMsg.BufferStart;
1526 mem = mem_orig = HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc));
1527 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 0);
1528 ok(mem == mem_orig, "mem not alloced\n");
1529 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1531 my_alloc_called = 0;
1532 StubMsg.Buffer = StubMsg.BufferStart;
1533 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 1);
1535 ok(mem == mem_orig, "mem not alloced\n");
1536 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1540 StubMsg.Buffer = StubMsg.BufferStart;
1541 NdrPointerFree( &StubMsg, mem, fmtstr_conf_str );
1542 ok(my_free_called == 1, "free called %d\n", my_free_called);
1546 StubMsg.Buffer = StubMsg.BufferStart;
1547 NdrPointerFree( &StubMsg, mem, fmtstr_conf_str );
1548 ok(my_free_called == 1, "free called %d\n", my_free_called);
1551 my_alloc_called = 0;
1552 StubMsg.IsClient = 0;
1554 StubMsg.Buffer = StubMsg.BufferStart;
1555 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 0);
1556 ok(mem == StubMsg.BufferStart + 12, "mem not pointing at buffer\n");
1557 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1559 my_alloc_called = 0;
1561 StubMsg.Buffer = StubMsg.BufferStart;
1562 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 1);
1564 ok(mem == StubMsg.BufferStart + 12, "mem not pointing at buffer\n");
1565 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1568 my_alloc_called = 0;
1570 StubMsg.Buffer = StubMsg.BufferStart;
1571 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 0);
1572 ok(mem == StubMsg.BufferStart + 12, "mem not pointing at buffer\n");
1573 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1575 my_alloc_called = 0;
1577 StubMsg.Buffer = StubMsg.BufferStart;
1578 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 1);
1580 ok(mem == StubMsg.BufferStart + 12, "mem not pointing at buffer\n");
1581 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1586 StubMsg.Buffer = StubMsg.BufferStart;
1587 NdrPointerFree( &StubMsg, mem, fmtstr_conf_str );
1588 ok(my_free_called == 1, "free called %d\n", my_free_called);
1590 HeapFree(GetProcessHeap(), 0, mem_orig);
1591 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
1594 static void test_nonconformant_string(void)
1596 RPC_MESSAGE RpcMessage;
1597 MIDL_STUB_MESSAGE StubMsg;
1598 MIDL_STUB_DESC StubDesc;
1601 unsigned char *mem, *mem_orig;
1602 unsigned char memsrc[10] = "This is";
1603 unsigned char memsrc2[10] = "This is a";
1605 static const unsigned char fmtstr_nonconf_str[] =
1607 0x26, /* FC_CSTRING */
1609 NdrFcShort( 0xa ), /* 10 */
1612 StubDesc = Object_StubDesc;
1613 StubDesc.pFormatTypes = fmtstr_nonconf_str;
1616 NdrClientInitializeNew(
1622 StubMsg.BufferLength = 0;
1624 NdrNonConformantStringBufferSize( &StubMsg, memsrc, fmtstr_nonconf_str );
1625 ok(StubMsg.BufferLength >= strlen((char *)memsrc) + 1 + 8, "length %d\n", StubMsg.BufferLength);
1627 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1628 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
1629 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
1631 ptr = NdrNonConformantStringMarshall( &StubMsg, memsrc, fmtstr_nonconf_str );
1632 ok(ptr == NULL, "ret %p\n", ptr);
1633 size = StubMsg.Buffer - StubMsg.BufferStart;
1634 ok(size == strlen((char *)memsrc) + 1 + 8, "Buffer %p Start %p len %d\n",
1635 StubMsg.Buffer, StubMsg.BufferStart, size);
1636 ok(!memcmp(StubMsg.BufferStart + 8, memsrc, strlen((char *)memsrc) + 1), "incorrectly marshaled\n");
1638 StubMsg.Buffer = StubMsg.BufferStart;
1639 StubMsg.MemorySize = 0;
1643 my_alloc_called = 0;
1644 StubMsg.Buffer = StubMsg.BufferStart;
1645 mem = mem_orig = HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc));
1646 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1647 ok(mem == mem_orig, "mem alloced\n");
1648 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1650 my_alloc_called = 0;
1651 StubMsg.Buffer = StubMsg.BufferStart;
1652 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 1);
1654 ok(mem == mem_orig, "mem alloced\n");
1656 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1659 my_alloc_called = 0;
1660 StubMsg.IsClient = 0;
1662 StubMsg.Buffer = StubMsg.BufferStart;
1663 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1664 ok(mem != mem_orig, "mem not alloced\n");
1665 ok(mem != StubMsg.BufferStart + 8, "mem pointing at buffer\n");
1666 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1669 my_alloc_called = 0;
1671 StubMsg.Buffer = StubMsg.BufferStart;
1672 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1673 ok(mem == mem_orig, "mem alloced\n");
1674 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1676 my_alloc_called = 0;
1678 StubMsg.Buffer = StubMsg.BufferStart;
1679 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 1);
1681 ok(mem == mem_orig, "mem alloced\n");
1683 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1685 HeapFree(GetProcessHeap(), 0, mem_orig);
1686 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
1689 NdrClientInitializeNew(
1695 StubMsg.BufferLength = 0;
1697 NdrNonConformantStringBufferSize( &StubMsg, memsrc2, fmtstr_nonconf_str );
1698 ok(StubMsg.BufferLength >= strlen((char *)memsrc2) + 1 + 8, "length %d\n", StubMsg.BufferLength);
1700 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1701 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
1702 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
1704 ptr = NdrNonConformantStringMarshall( &StubMsg, memsrc2, fmtstr_nonconf_str );
1705 ok(ptr == NULL, "ret %p\n", ptr);
1706 size = StubMsg.Buffer - StubMsg.BufferStart;
1707 ok(size == strlen((char *)memsrc2) + 1 + 8, "Buffer %p Start %p len %d\n",
1708 StubMsg.Buffer, StubMsg.BufferStart, size);
1709 ok(!memcmp(StubMsg.BufferStart + 8, memsrc2, strlen((char *)memsrc2) + 1), "incorrectly marshaled\n");
1711 StubMsg.Buffer = StubMsg.BufferStart;
1712 StubMsg.MemorySize = 0;
1716 my_alloc_called = 0;
1717 StubMsg.Buffer = StubMsg.BufferStart;
1718 mem = mem_orig = HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc));
1719 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1720 ok(mem == mem_orig, "mem alloced\n");
1721 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1723 my_alloc_called = 0;
1724 StubMsg.Buffer = StubMsg.BufferStart;
1725 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 1);
1727 ok(mem == mem_orig, "mem alloced\n");
1729 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1732 my_alloc_called = 0;
1733 StubMsg.IsClient = 0;
1735 StubMsg.Buffer = StubMsg.BufferStart;
1736 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1737 ok(mem != mem_orig, "mem not alloced\n");
1738 ok(mem != StubMsg.BufferStart + 8, "mem pointing at buffer\n");
1739 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1742 my_alloc_called = 0;
1744 StubMsg.Buffer = StubMsg.BufferStart;
1745 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1746 ok(mem == mem_orig, "mem alloced\n");
1747 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1749 my_alloc_called = 0;
1751 StubMsg.Buffer = StubMsg.BufferStart;
1752 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 1);
1754 ok(mem == mem_orig, "mem alloced\n");
1756 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1758 HeapFree(GetProcessHeap(), 0, mem_orig);
1759 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
1762 static void test_conf_complex_struct(void)
1764 RPC_MESSAGE RpcMessage;
1765 MIDL_STUB_MESSAGE StubMsg;
1766 MIDL_STUB_DESC StubDesc;
1772 unsigned int *array[1];
1774 struct conf_complex *memsrc;
1775 struct conf_complex *mem;
1777 static const unsigned char fmtstr_complex_struct[] =
1780 0x1b, /* FC_CARRAY */
1782 /* 2 */ NdrFcShort( 0x4 ), /* 4 */
1783 /* 4 */ 0x8, /* Corr desc: FC_LONG */
1785 /* 6 */ NdrFcShort( 0xfffc ), /* -4 */
1790 0x48, /* FC_VARIABLE_REPEAT */
1791 0x49, /* FC_FIXED_OFFSET */
1792 /* 12 */ NdrFcShort( 0x4 ), /* 4 */
1793 /* 14 */ NdrFcShort( 0x0 ), /* 0 */
1794 /* 16 */ NdrFcShort( 0x1 ), /* 1 */
1795 /* 18 */ NdrFcShort( 0x0 ), /* 0 */
1796 /* 20 */ NdrFcShort( 0x0 ), /* 0 */
1797 /* 22 */ 0x12, 0x8, /* FC_UP [simple_pointer] */
1798 /* 24 */ 0x8, /* FC_LONG */
1804 /* 28 */ 0x5c, /* FC_PAD */
1807 0x1a, /* FC_BOGUS_STRUCT */
1809 /* 32 */ NdrFcShort( 0x4 ), /* 4 */
1810 /* 34 */ NdrFcShort( 0xffffffde ), /* Offset= -34 (0) */
1811 /* 36 */ NdrFcShort( 0x0 ), /* Offset= 0 (36) */
1812 /* 38 */ 0x8, /* FC_LONG */
1816 memsrc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1817 FIELD_OFFSET(struct conf_complex, array[20]));
1820 StubDesc = Object_StubDesc;
1821 StubDesc.pFormatTypes = fmtstr_complex_struct;
1823 NdrClientInitializeNew(
1829 StubMsg.BufferLength = 0;
1830 NdrComplexStructBufferSize( &StubMsg,
1831 (unsigned char *)memsrc,
1832 &fmtstr_complex_struct[30] );
1833 ok(StubMsg.BufferLength >= 28, "length %d\n", StubMsg.BufferLength);
1835 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1836 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
1837 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
1839 ptr = NdrComplexStructMarshall( &StubMsg, (unsigned char *)memsrc,
1840 &fmtstr_complex_struct[30] );
1841 ok(ptr == NULL, "ret %p\n", ptr);
1842 ok(*(unsigned int *)StubMsg.BufferStart == 20, "Conformance should have been 20 instead of %d\n", *(unsigned int *)StubMsg.BufferStart);
1843 ok(*(unsigned int *)(StubMsg.BufferStart + 4) == 20, "conf_complex.size should have been 20 instead of %d\n", *(unsigned int *)(StubMsg.BufferStart + 4));
1844 for (i = 0; i < 20; i++)
1845 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));
1848 my_alloc_called = 0;
1849 StubMsg.IsClient = 0;
1851 StubMsg.Buffer = StubMsg.BufferStart;
1852 ptr = NdrComplexStructUnmarshall( &StubMsg, (unsigned char **)&mem, &fmtstr_complex_struct[30], 0);
1853 ok(ptr == NULL, "ret %p\n", ptr);
1854 ok(mem->size == 20, "mem->size wasn't unmarshalled correctly (%d)\n", mem->size);
1855 ok(mem->array[0] == NULL, "mem->array[0] wasn't unmarshalled correctly (%p)\n", mem->array[0]);
1856 StubMsg.pfnFree(mem);
1858 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
1861 static void test_ndr_buffer(void)
1863 static unsigned char ncalrpc[] = "ncalrpc";
1864 static unsigned char endpoint[] = "winetest:test_ndr_buffer";
1865 RPC_MESSAGE RpcMessage;
1866 MIDL_STUB_MESSAGE StubMsg;
1867 MIDL_STUB_DESC StubDesc = Object_StubDesc;
1869 unsigned char *binding;
1870 RPC_BINDING_HANDLE Handle;
1872 ULONG prev_buffer_length;
1873 BOOL old_buffer_valid_location;
1875 StubDesc.RpcInterfaceInformation = (void *)&IFoo___RpcServerInterface;
1877 status = RpcServerUseProtseqEp(ncalrpc, 20, endpoint, NULL);
1878 ok(RPC_S_OK == status, "RpcServerUseProtseqEp failed with status %u\n", status);
1879 status = RpcServerRegisterIf(IFoo_v0_0_s_ifspec, NULL, NULL);
1880 ok(RPC_S_OK == status, "RpcServerRegisterIf failed with status %u\n", status);
1881 status = RpcServerListen(1, 20, TRUE);
1882 ok(RPC_S_OK == status, "RpcServerListen failed with status %u\n", status);
1883 if (status != RPC_S_OK)
1885 /* Failed to create a server, running client tests is useless */
1889 status = RpcStringBindingCompose(NULL, ncalrpc, NULL, endpoint, NULL, &binding);
1890 ok(status == RPC_S_OK, "RpcStringBindingCompose failed (%u)\n", status);
1892 status = RpcBindingFromStringBinding(binding, &Handle);
1893 ok(status == RPC_S_OK, "RpcBindingFromStringBinding failed (%u)\n", status);
1894 RpcStringFree(&binding);
1896 NdrClientInitializeNew(&RpcMessage, &StubMsg, &StubDesc, 5);
1898 ret = NdrGetBuffer(&StubMsg, 10, Handle);
1899 ok(ret == StubMsg.Buffer, "NdrGetBuffer should have returned the same value as StubMsg.Buffer instead of %p\n", ret);
1900 ok(RpcMessage.Handle != NULL, "RpcMessage.Handle should not have been NULL\n");
1901 ok(RpcMessage.Buffer != NULL, "RpcMessage.Buffer should not have been NULL\n");
1902 ok(RpcMessage.BufferLength == 10 ||
1903 broken(RpcMessage.BufferLength == 12), /* win2k */
1904 "RpcMessage.BufferLength should have been 10 instead of %d\n", RpcMessage.BufferLength);
1905 ok(RpcMessage.RpcFlags == 0, "RpcMessage.RpcFlags should have been 0x0 instead of 0x%x\n", RpcMessage.RpcFlags);
1906 ok(StubMsg.Buffer != NULL, "Buffer should not have been NULL\n");
1907 ok(!StubMsg.BufferStart, "BufferStart should have been NULL instead of %p\n", StubMsg.BufferStart);
1908 ok(!StubMsg.BufferEnd, "BufferEnd should have been NULL instead of %p\n", StubMsg.BufferEnd);
1910 ok(StubMsg.BufferLength == 0, "BufferLength should have left as 0 instead of being set to %d\n", StubMsg.BufferLength);
1911 old_buffer_valid_location = !StubMsg.fBufferValid;
1912 if (old_buffer_valid_location)
1913 ok(broken(StubMsg.CorrDespIncrement == TRUE), "fBufferValid should have been TRUE instead of 0x%x\n", StubMsg.CorrDespIncrement);
1915 ok(StubMsg.fBufferValid, "fBufferValid should have been non-zero instead of 0x%x\n", StubMsg.fBufferValid);
1917 prev_buffer_length = RpcMessage.BufferLength;
1918 StubMsg.BufferLength = 1;
1919 NdrFreeBuffer(&StubMsg);
1920 ok(RpcMessage.Handle != NULL, "RpcMessage.Handle should not have been NULL\n");
1921 ok(RpcMessage.Buffer != NULL, "RpcMessage.Buffer should not have been NULL\n");
1922 ok(RpcMessage.BufferLength == prev_buffer_length, "RpcMessage.BufferLength should have been left as %d instead of %d\n", prev_buffer_length, RpcMessage.BufferLength);
1923 ok(StubMsg.Buffer != NULL, "Buffer should not have been NULL\n");
1924 ok(StubMsg.BufferLength == 1, "BufferLength should have left as 1 instead of being set to %d\n", StubMsg.BufferLength);
1925 if (old_buffer_valid_location)
1926 ok(broken(StubMsg.CorrDespIncrement == FALSE), "fBufferValid should have been FALSE instead of 0x%x\n", StubMsg.CorrDespIncrement);
1928 ok(!StubMsg.fBufferValid, "fBufferValid should have been FALSE instead of %d\n", StubMsg.fBufferValid);
1930 /* attempt double-free */
1931 NdrFreeBuffer(&StubMsg);
1933 RpcBindingFree(&Handle);
1935 status = RpcServerUnregisterIf(NULL, NULL, FALSE);
1936 ok(status == RPC_S_OK, "RpcServerUnregisterIf failed (%u)\n", status);
1939 static void test_NdrMapCommAndFaultStatus(void)
1941 RPC_STATUS rpc_status;
1942 MIDL_STUB_MESSAGE StubMsg;
1943 RPC_MESSAGE RpcMessage;
1945 NdrClientInitializeNew(&RpcMessage, &StubMsg, &Object_StubDesc, 5);
1947 for (rpc_status = 0; rpc_status < 10000; rpc_status++)
1950 ULONG comm_status = 0;
1951 ULONG fault_status = 0;
1952 ULONG expected_comm_status = 0;
1953 ULONG expected_fault_status = 0;
1954 status = NdrMapCommAndFaultStatus(&StubMsg, &comm_status, &fault_status, rpc_status);
1955 ok(status == RPC_S_OK, "NdrMapCommAndFaultStatus failed with error %d\n", status);
1958 case ERROR_INVALID_HANDLE:
1959 case RPC_S_INVALID_BINDING:
1960 case RPC_S_UNKNOWN_IF:
1961 case RPC_S_SERVER_UNAVAILABLE:
1962 case RPC_S_SERVER_TOO_BUSY:
1963 case RPC_S_CALL_FAILED_DNE:
1964 case RPC_S_PROTOCOL_ERROR:
1965 case RPC_S_UNSUPPORTED_TRANS_SYN:
1966 case RPC_S_UNSUPPORTED_TYPE:
1967 case RPC_S_PROCNUM_OUT_OF_RANGE:
1968 case EPT_S_NOT_REGISTERED:
1969 case RPC_S_COMM_FAILURE:
1970 expected_comm_status = rpc_status;
1973 expected_fault_status = rpc_status;
1975 ok(comm_status == expected_comm_status, "NdrMapCommAndFaultStatus should have mapped %d to comm status %d instead of %d\n",
1976 rpc_status, expected_comm_status, comm_status);
1977 ok(fault_status == expected_fault_status, "NdrMapCommAndFaultStatus should have mapped %d to fault status %d instead of %d\n",
1978 rpc_status, expected_fault_status, fault_status);
1982 static void test_NdrGetUserMarshalInfo(void)
1985 MIDL_STUB_MESSAGE stubmsg;
1986 USER_MARSHAL_CB umcb;
1987 NDR_USER_MARSHAL_INFO umi;
1988 unsigned char buffer[16];
1989 void *rpc_channel_buffer = (void *)(ULONG_PTR)0xcafebabe;
1990 RPC_MESSAGE rpc_msg;
1991 RPC_STATUS (RPC_ENTRY *pNdrGetUserMarshalInfo)(ULONG *,ULONG,NDR_USER_MARSHAL_INFO *);
1993 pNdrGetUserMarshalInfo = (void *)GetProcAddress(GetModuleHandle("rpcrt4.dll"), "NdrGetUserMarshalInfo");
1994 if (!pNdrGetUserMarshalInfo)
1996 skip("NdrGetUserMarshalInfo not exported\n");
2002 memset(&rpc_msg, 0xcc, sizeof(rpc_msg));
2003 rpc_msg.Buffer = buffer;
2004 rpc_msg.BufferLength = 16;
2006 memset(&stubmsg, 0xcc, sizeof(stubmsg));
2007 stubmsg.RpcMsg = &rpc_msg;
2008 stubmsg.dwDestContext = MSHCTX_INPROC;
2009 stubmsg.pvDestContext = NULL;
2010 stubmsg.Buffer = buffer + 15;
2011 stubmsg.BufferLength = 0;
2012 stubmsg.BufferEnd = NULL;
2013 stubmsg.pRpcChannelBuffer = rpc_channel_buffer;
2014 stubmsg.StubDesc = NULL;
2015 stubmsg.pfnAllocate = my_alloc;
2016 stubmsg.pfnFree = my_free;
2018 memset(&umcb, 0xcc, sizeof(umcb));
2019 umcb.Flags = MAKELONG(MSHCTX_INPROC, NDR_LOCAL_DATA_REPRESENTATION);
2020 umcb.pStubMsg = &stubmsg;
2021 umcb.Signature = USER_MARSHAL_CB_SIGNATURE;
2022 umcb.CBType = USER_MARSHAL_CB_UNMARSHALL;
2024 memset(&umi, 0xaa, sizeof(umi));
2026 status = pNdrGetUserMarshalInfo(&umcb.Flags, 1, &umi);
2027 ok(status == RPC_S_OK, "NdrGetUserMarshalInfo failed with error %d\n", status);
2028 ok( umi.InformationLevel == 1,
2029 "umi.InformationLevel was %u instead of 1\n",
2030 umi.InformationLevel);
2031 ok( U(umi.Level1).Buffer == buffer + 15,
2032 "U(umi.Level1).Buffer was %p instead of %p\n",
2033 U(umi.Level1).Buffer, buffer);
2034 ok( U(umi.Level1).BufferSize == 1,
2035 "U(umi.Level1).BufferSize was %u instead of 1\n",
2036 U(umi.Level1).BufferSize);
2037 ok( U(umi.Level1).pfnAllocate == my_alloc,
2038 "U(umi.Level1).pfnAllocate was %p instead of %p\n",
2039 U(umi.Level1).pfnAllocate, my_alloc);
2040 ok( U(umi.Level1).pfnFree == my_free,
2041 "U(umi.Level1).pfnFree was %p instead of %p\n",
2042 U(umi.Level1).pfnFree, my_free);
2043 ok( U(umi.Level1).pRpcChannelBuffer == rpc_channel_buffer,
2044 "U(umi.Level1).pRpcChannelBuffer was %p instead of %p\n",
2045 U(umi.Level1).pRpcChannelBuffer, rpc_channel_buffer);
2049 rpc_msg.Buffer = buffer;
2050 rpc_msg.BufferLength = 16;
2052 stubmsg.Buffer = buffer;
2053 stubmsg.BufferLength = 16;
2054 stubmsg.BufferEnd = NULL;
2056 umcb.CBType = USER_MARSHAL_CB_BUFFER_SIZE;
2058 memset(&umi, 0xaa, sizeof(umi));
2060 status = pNdrGetUserMarshalInfo(&umcb.Flags, 1, &umi);
2061 ok(status == RPC_S_OK, "NdrGetUserMarshalInfo failed with error %d\n", status);
2062 ok( umi.InformationLevel == 1,
2063 "umi.InformationLevel was %u instead of 1\n",
2064 umi.InformationLevel);
2065 ok( U(umi.Level1).Buffer == NULL,
2066 "U(umi.Level1).Buffer was %p instead of NULL\n",
2067 U(umi.Level1).Buffer);
2068 ok( U(umi.Level1).BufferSize == 0,
2069 "U(umi.Level1).BufferSize was %u instead of 0\n",
2070 U(umi.Level1).BufferSize);
2071 ok( U(umi.Level1).pfnAllocate == my_alloc,
2072 "U(umi.Level1).pfnAllocate was %p instead of %p\n",
2073 U(umi.Level1).pfnAllocate, my_alloc);
2074 ok( U(umi.Level1).pfnFree == my_free,
2075 "U(umi.Level1).pfnFree was %p instead of %p\n",
2076 U(umi.Level1).pfnFree, my_free);
2077 ok( U(umi.Level1).pRpcChannelBuffer == rpc_channel_buffer,
2078 "U(umi.Level1).pRpcChannelBuffer was %p instead of %p\n",
2079 U(umi.Level1).pRpcChannelBuffer, rpc_channel_buffer);
2083 rpc_msg.Buffer = buffer;
2084 rpc_msg.BufferLength = 16;
2086 stubmsg.Buffer = buffer + 15;
2087 stubmsg.BufferLength = 0;
2088 stubmsg.BufferEnd = NULL;
2090 umcb.CBType = USER_MARSHAL_CB_MARSHALL;
2092 memset(&umi, 0xaa, sizeof(umi));
2094 status = pNdrGetUserMarshalInfo(&umcb.Flags, 1, &umi);
2095 ok(status == RPC_S_OK, "NdrGetUserMarshalInfo failed with error %d\n", status);
2096 ok( umi.InformationLevel == 1,
2097 "umi.InformationLevel was %u instead of 1\n",
2098 umi.InformationLevel);
2099 ok( U(umi.Level1).Buffer == buffer + 15,
2100 "U(umi.Level1).Buffer was %p instead of %p\n",
2101 U(umi.Level1).Buffer, buffer);
2102 ok( U(umi.Level1).BufferSize == 1,
2103 "U(umi.Level1).BufferSize was %u instead of 1\n",
2104 U(umi.Level1).BufferSize);
2105 ok( U(umi.Level1).pfnAllocate == my_alloc,
2106 "U(umi.Level1).pfnAllocate was %p instead of %p\n",
2107 U(umi.Level1).pfnAllocate, my_alloc);
2108 ok( U(umi.Level1).pfnFree == my_free,
2109 "U(umi.Level1).pfnFree was %p instead of %p\n",
2110 U(umi.Level1).pfnFree, my_free);
2111 ok( U(umi.Level1).pRpcChannelBuffer == rpc_channel_buffer,
2112 "U(umi.Level1).pRpcChannelBuffer was %p instead of %p\n",
2113 U(umi.Level1).pRpcChannelBuffer, rpc_channel_buffer);
2117 rpc_msg.Buffer = buffer;
2118 rpc_msg.BufferLength = 16;
2120 stubmsg.Buffer = buffer;
2121 stubmsg.BufferLength = 16;
2122 stubmsg.BufferEnd = NULL;
2124 umcb.CBType = USER_MARSHAL_CB_FREE;
2126 memset(&umi, 0xaa, sizeof(umi));
2128 status = pNdrGetUserMarshalInfo(&umcb.Flags, 1, &umi);
2129 ok(status == RPC_S_OK, "NdrGetUserMarshalInfo failed with error %d\n", status);
2130 ok( umi.InformationLevel == 1,
2131 "umi.InformationLevel was %u instead of 1\n",
2132 umi.InformationLevel);
2133 ok( U(umi.Level1).Buffer == NULL,
2134 "U(umi.Level1).Buffer was %p instead of NULL\n",
2135 U(umi.Level1).Buffer);
2136 ok( U(umi.Level1).BufferSize == 0,
2137 "U(umi.Level1).BufferSize was %u instead of 0\n",
2138 U(umi.Level1).BufferSize);
2139 ok( U(umi.Level1).pfnAllocate == my_alloc,
2140 "U(umi.Level1).pfnAllocate was %p instead of %p\n",
2141 U(umi.Level1).pfnAllocate, my_alloc);
2142 ok( U(umi.Level1).pfnFree == my_free,
2143 "U(umi.Level1).pfnFree was %p instead of %p\n",
2144 U(umi.Level1).pfnFree, my_free);
2145 ok( U(umi.Level1).pRpcChannelBuffer == rpc_channel_buffer,
2146 "U(umi.Level1).pRpcChannelBuffer was %p instead of %p\n",
2147 U(umi.Level1).pRpcChannelBuffer, rpc_channel_buffer);
2151 rpc_msg.Buffer = buffer;
2152 rpc_msg.BufferLength = 15;
2154 stubmsg.Buffer = buffer + 15;
2155 stubmsg.BufferLength = 0;
2156 stubmsg.BufferEnd = NULL;
2158 umcb.CBType = USER_MARSHAL_CB_MARSHALL;
2160 status = pNdrGetUserMarshalInfo(&umcb.Flags, 1, &umi);
2161 ok(status == RPC_S_OK, "NdrGetUserMarshalInfo failed with error %d\n", status);
2162 ok( U(umi.Level1).BufferSize == 0,
2163 "U(umi.Level1).BufferSize was %u instead of 0\n",
2164 U(umi.Level1).BufferSize);
2166 /* error conditions */
2168 rpc_msg.BufferLength = 14;
2169 status = pNdrGetUserMarshalInfo(&umcb.Flags, 1, &umi);
2170 ok(status == ERROR_INVALID_USER_BUFFER,
2171 "NdrGetUserMarshalInfo should have failed with ERROR_INVALID_USER_BUFFER instead of %d\n", status);
2173 rpc_msg.BufferLength = 15;
2174 status = pNdrGetUserMarshalInfo(&umcb.Flags, 9999, &umi);
2175 ok(status == RPC_S_INVALID_ARG,
2176 "NdrGetUserMarshalInfo should have failed with RPC_S_INVALID_ARG instead of %d\n", status);
2179 status = pNdrGetUserMarshalInfo(&umcb.Flags, 1, &umi);
2180 ok(status == RPC_S_OK, "NdrGetUserMarshalInfo failed with error %d\n", status);
2182 umcb.CBType = USER_MARSHAL_CB_MARSHALL;
2184 status = pNdrGetUserMarshalInfo(&umcb.Flags, 1, &umi);
2185 ok(status == RPC_S_INVALID_ARG,
2186 "NdrGetUserMarshalInfo should have failed with RPC_S_INVALID_ARG instead of %d\n", status);
2189 START_TEST( ndr_marshall )
2191 determine_pointer_marshalling_style();
2193 test_ndr_simple_type();
2194 test_simple_types();
2195 test_nontrivial_pointer_types();
2196 test_simple_struct();
2197 test_fullpointer_xlat();
2200 test_ndr_allocate();
2201 test_conformant_array();
2202 test_conformant_string();
2203 test_nonconformant_string();
2204 test_conf_complex_struct();
2206 test_NdrMapCommAndFaultStatus();
2207 test_NdrGetUserMarshalInfo();