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 if (srcsize == 8 && wiredatalen == 16 && StubMsg.Buffer - StubMsg.BufferStart == 12)
216 /* win9x doesn't align 8-byte types properly */
221 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
222 ok(!memcmp(StubMsg.BufferStart, wiredata, wiredatalen), "%s: incorrectly marshaled\n", msgpfx);
225 StubMsg.Buffer = StubMsg.BufferStart;
226 StubMsg.MemorySize = 0;
228 size = NdrPointerMemorySize( &StubMsg, formattypes );
229 ok(size == StubMsg.MemorySize, "%s: mem size %u size %u\n", msgpfx, StubMsg.MemorySize, size);
230 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
231 if(formattypes[1] & 0x10 /* FC_POINTER_DEREF */)
232 ok(size == srcsize + sizeof(void *), "%s: mem size %u\n", msgpfx, size);
234 ok(size == srcsize, "%s: mem size %u\n", msgpfx, size);
236 StubMsg.Buffer = StubMsg.BufferStart;
237 StubMsg.MemorySize = 16;
238 size = NdrPointerMemorySize( &StubMsg, formattypes );
239 ok(size == StubMsg.MemorySize, "%s: mem size %u size %u\n", msgpfx, StubMsg.MemorySize, size);
240 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
241 if(formattypes[1] & 0x10 /* FC_POINTER_DEREF */)
242 ok(size == srcsize + sizeof(void *) + 16, "%s: mem size %u\n", msgpfx, size);
244 ok(size == srcsize + 16, "%s: mem size %u\n", msgpfx, size);
246 StubMsg.Buffer = StubMsg.BufferStart;
247 StubMsg.MemorySize = 1;
248 size = NdrPointerMemorySize( &StubMsg, formattypes );
249 ok(size == StubMsg.MemorySize, "%s: mem size %u size %u\n", msgpfx, StubMsg.MemorySize, size);
250 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
251 if(formattypes[1] & 0x10 /* FC_POINTER_DEREF */)
252 ok(size == srcsize + sizeof(void *) + (srcsize == 8 ? 8 : sizeof(void *)), "%s: mem size %u\n", msgpfx, size);
254 ok(size == srcsize + (srcsize == 8 ? 8 : sizeof(void *)), "%s: mem size %u\n", msgpfx, size);
257 if(formattypes[1] & 0x10) size += 4;
259 StubMsg.Buffer = StubMsg.BufferStart;
260 StubMsg.MemorySize = 0;
261 mem_orig = mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
263 if(formattypes[1] & 0x10 /* FC_POINTER_DEREF */)
265 ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 0 );
266 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
267 ok(mem == mem_orig, "%s: mem has changed %p %p\n", msgpfx, mem, mem_orig);
268 ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx);
269 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
270 ok(StubMsg.MemorySize == 0, "%s: memorysize %d\n", msgpfx, StubMsg.MemorySize);
271 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
274 /* reset the buffer and call with must alloc */
275 StubMsg.Buffer = StubMsg.BufferStart;
276 if(formattypes[1] & 0x10 /* FC_POINTER_DEREF */)
278 ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 1 );
279 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
280 /* doesn't allocate mem in this case */
282 ok(mem == mem_orig, "%s: mem has changed %p %p\n", msgpfx, mem, mem_orig);
284 ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx);
285 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
286 ok(StubMsg.MemorySize == 0, "%s: memorysize %d\n", msgpfx, StubMsg.MemorySize);
289 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
292 if(formattypes[0] != 0x11 /* FC_RP */)
294 /* now pass the address of a NULL ptr */
296 StubMsg.Buffer = StubMsg.BufferStart;
297 ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 0 );
298 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
299 ok(mem != StubMsg.BufferStart + wiredatalen - srcsize, "%s: mem points to buffer %p %p\n", msgpfx, mem, StubMsg.BufferStart);
300 ok(!cmp(mem, memsrc, size), "%s: incorrectly unmarshaled\n", msgpfx);
301 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
302 ok(StubMsg.MemorySize == 0, "%s: memorysize %d\n", msgpfx, StubMsg.MemorySize);
303 ok(my_alloc_called == num_additional_allocs + 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
305 NdrPointerFree(&StubMsg, mem, formattypes);
307 /* again pass address of NULL ptr, but pretend we're a server */
308 if (0) /* crashes on Win9x and NT4 */
311 StubMsg.Buffer = StubMsg.BufferStart;
312 StubMsg.IsClient = 0;
313 ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 0 );
314 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
315 if (formattypes[2] == 0xd /* FC_ENUM16 */)
316 ok(mem != StubMsg.BufferStart + wiredatalen - srcsize, "%s: mem points to buffer %p %p\n", msgpfx, mem, StubMsg.BufferStart);
318 ok(mem == StubMsg.BufferStart + wiredatalen - srcsize, "%s: mem doesn't point to buffer %p %p\n", msgpfx, mem, StubMsg.BufferStart);
319 ok(!cmp(mem, memsrc, size), "%s: incorrectly unmarshaled\n", msgpfx);
320 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
321 ok(StubMsg.MemorySize == 0, "%s: memorysize %d\n", msgpfx, StubMsg.MemorySize);
322 if (formattypes[2] != 0xd /* FC_ENUM16 */) {
323 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
328 HeapFree(GetProcessHeap(), 0, mem_orig);
329 HeapFree(GetProcessHeap(), 0, StubMsg.BufferStart);
332 static int deref_cmp(const void *s1, const void *s2, size_t num)
334 return memcmp(*(const void *const *)s1, *(const void *const *)s2, num);
338 static void test_simple_types(void)
340 unsigned char wiredata[16];
342 unsigned char *ch_ptr;
350 static const unsigned char fmtstr_up_char[] =
352 0x12, 0x8, /* FC_UP [simple_pointer] */
356 static const unsigned char fmtstr_up_byte[] =
358 0x12, 0x8, /* FC_UP [simple_pointer] */
362 static const unsigned char fmtstr_up_small[] =
364 0x12, 0x8, /* FC_UP [simple_pointer] */
368 static const unsigned char fmtstr_up_usmall[] =
370 0x12, 0x8, /* FC_UP [simple_pointer] */
374 static const unsigned char fmtstr_rp_char[] =
376 0x11, 0x8, /* FC_RP [simple_pointer] */
380 static const unsigned char fmtstr_rpup_char[] =
382 0x11, 0x14, /* FC_RP [alloced_on_stack] */
383 NdrFcShort( 0x2 ), /* Offset= 2 (4) */
384 0x12, 0x8, /* FC_UP [simple_pointer] */
388 static const unsigned char fmtstr_rpup_char2[] =
390 0x11, 0x04, /* FC_RP [alloced_on_stack] */
391 NdrFcShort( 0x2 ), /* Offset= 2 (4) */
392 0x12, 0x8, /* FC_UP [simple_pointer] */
397 static const unsigned char fmtstr_up_wchar[] =
399 0x12, 0x8, /* FC_UP [simple_pointer] */
403 static const unsigned char fmtstr_up_short[] =
405 0x12, 0x8, /* FC_UP [simple_pointer] */
409 static const unsigned char fmtstr_up_ushort[] =
411 0x12, 0x8, /* FC_UP [simple_pointer] */
415 static const unsigned char fmtstr_up_enum16[] =
417 0x12, 0x8, /* FC_UP [simple_pointer] */
421 static const unsigned char fmtstr_up_long[] =
423 0x12, 0x8, /* FC_UP [simple_pointer] */
427 static const unsigned char fmtstr_up_ulong[] =
429 0x12, 0x8, /* FC_UP [simple_pointer] */
433 static const unsigned char fmtstr_up_enum32[] =
435 0x12, 0x8, /* FC_UP [simple_pointer] */
439 static const unsigned char fmtstr_up_errorstatus[] =
441 0x12, 0x8, /* FC_UP [simple_pointer] */
442 0x10, /* FC_ERROR_STATUS_T */
446 static const unsigned char fmtstr_up_longlong[] =
448 0x12, 0x8, /* FC_UP [simple_pointer] */
452 static const unsigned char fmtstr_up_float[] =
454 0x12, 0x8, /* FC_UP [simple_pointer] */
458 static const unsigned char fmtstr_up_double[] =
460 0x12, 0x8, /* FC_UP [simple_pointer] */
468 *(unsigned int *)wiredata = 0x20000;
470 *(unsigned int *)wiredata = (UINT_PTR)ch_ptr;
473 test_pointer_marshal(fmtstr_up_char, ch_ptr, 1, wiredata, 5, NULL, 0, "up_char");
474 test_pointer_marshal(fmtstr_up_byte, ch_ptr, 1, wiredata, 5, NULL, 0, "up_byte");
475 test_pointer_marshal(fmtstr_up_small, ch_ptr, 1, wiredata, 5, NULL, 0, "up_small");
476 test_pointer_marshal(fmtstr_up_usmall, ch_ptr, 1, wiredata, 5, NULL, 0, "up_usmall");
478 test_pointer_marshal(fmtstr_rp_char, ch_ptr, 1, &ch, 1, NULL, 0, "rp_char");
480 test_pointer_marshal(fmtstr_rpup_char, &ch_ptr, 1, wiredata, 5, deref_cmp, 1, "rpup_char");
481 test_pointer_marshal(fmtstr_rpup_char2, ch_ptr, 1, wiredata, 5, NULL, 0, "rpup_char2");
485 *(unsigned int *)wiredata = 0x20000;
487 *(unsigned int *)wiredata = (UINT_PTR)&s;
488 *(unsigned short*)(wiredata + 4) = s;
490 test_pointer_marshal(fmtstr_up_wchar, &s, 2, wiredata, 6, NULL, 0, "up_wchar");
491 test_pointer_marshal(fmtstr_up_short, &s, 2, wiredata, 6, NULL, 0, "up_short");
492 test_pointer_marshal(fmtstr_up_ushort, &s, 2, wiredata, 6, NULL, 0, "up_ushort");
496 *(unsigned int *)wiredata = 0x20000;
498 *(unsigned int *)wiredata = (UINT_PTR)&i;
499 *(unsigned short*)(wiredata + 4) = i;
500 test_pointer_marshal(fmtstr_up_enum16, &i, 4, wiredata, 6, NULL, 0, "up_enum16");
504 *(unsigned int *)wiredata = 0x20000;
506 *(unsigned int *)wiredata = (UINT_PTR)&l;
507 *(ULONG*)(wiredata + 4) = l;
509 test_pointer_marshal(fmtstr_up_long, &l, 4, wiredata, 8, NULL, 0, "up_long");
510 test_pointer_marshal(fmtstr_up_ulong, &l, 4, wiredata, 8, NULL, 0, "up_ulong");
511 test_pointer_marshal(fmtstr_up_enum32, &l, 4, wiredata, 8, NULL, 0, "up_emun32");
512 test_pointer_marshal(fmtstr_up_errorstatus, &l, 4, wiredata, 8, NULL, 0, "up_errorstatus");
514 ll = ((ULONGLONG)0xcafebabe) << 32 | 0xdeadbeef;
516 *(unsigned int *)wiredata = 0x20000;
518 *(unsigned int *)wiredata = (UINT_PTR)≪
519 *(unsigned int *)(wiredata + 4) = 0;
520 *(ULONGLONG*)(wiredata + 8) = ll;
521 test_pointer_marshal(fmtstr_up_longlong, &ll, 8, wiredata, 16, NULL, 0, "up_longlong");
525 *(unsigned int *)wiredata = 0x20000;
527 *(unsigned int *)wiredata = (UINT_PTR)&f;
528 *(float*)(wiredata + 4) = f;
529 test_pointer_marshal(fmtstr_up_float, &f, 4, wiredata, 8, NULL, 0, "up_float");
533 *(unsigned int *)wiredata = 0x20000;
535 *(unsigned int *)wiredata = (UINT_PTR)&d;
536 *(unsigned int *)(wiredata + 4) = 0;
537 *(double*)(wiredata + 8) = d;
538 test_pointer_marshal(fmtstr_up_double, &d, 8, wiredata, 16, NULL, 0, "up_double");
542 static void test_nontrivial_pointer_types(void)
544 RPC_MESSAGE RpcMessage;
545 MIDL_STUB_MESSAGE StubMsg;
546 MIDL_STUB_DESC StubDesc;
552 unsigned char *mem, *mem_orig;
554 static const unsigned char fmtstr_ref_unique_out[] =
556 0x12, 0x8, /* FC_UP [simple_pointer] */
559 0x11, 0x14, /* FC_RP [alloced_on_stack] [pointer_deref] */
560 NdrFcShort( 0xfffffffa ), /* Offset= -6 (0) */
567 StubDesc = Object_StubDesc;
568 StubDesc.pFormatTypes = fmtstr_ref_unique_out;
570 NdrClientInitializeNew(
576 StubMsg.BufferLength = 0;
577 NdrPointerBufferSize( &StubMsg,
579 &fmtstr_ref_unique_out[4] );
581 /* Windows overestimates the buffer size */
582 ok(StubMsg.BufferLength >= 5, "length %d\n", StubMsg.BufferLength);
584 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
585 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
586 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
588 ptr = NdrPointerMarshall( &StubMsg, (unsigned char *)p1, &fmtstr_ref_unique_out[4] );
589 ok(ptr == NULL, "ret %p\n", ptr);
590 size = StubMsg.Buffer - StubMsg.BufferStart;
591 ok(size == 5, "Buffer %p Start %p len %d\n", StubMsg.Buffer, StubMsg.BufferStart, size);
592 ok(*(unsigned int *)StubMsg.BufferStart != 0, "pointer ID marshalled incorrectly\n");
593 ok(*(unsigned char *)(StubMsg.BufferStart + 4) == 0x22, "char data marshalled incorrectly: 0x%x\n",
594 *(unsigned char *)(StubMsg.BufferStart + 4));
596 StubMsg.Buffer = StubMsg.BufferStart;
597 StubMsg.MemorySize = 0;
602 StubMsg.Buffer = StubMsg.BufferStart;
603 mem = mem_orig = HeapAlloc(GetProcessHeap(), 0, sizeof(void *));
604 *(void **)mem = NULL;
605 NdrPointerUnmarshall( &StubMsg, &mem, &fmtstr_ref_unique_out[4], 0);
606 ok(mem == mem_orig, "mem alloced\n");
607 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
610 StubMsg.Buffer = StubMsg.BufferStart;
611 NdrPointerUnmarshall( &StubMsg, &mem, &fmtstr_ref_unique_out[4], 1);
613 ok(mem == mem_orig, "mem alloced\n");
614 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
618 StubMsg.Buffer = StubMsg.BufferStart;
619 NdrPointerFree( &StubMsg, mem, &fmtstr_ref_unique_out[4] );
620 ok(my_free_called == 1, "free called %d\n", my_free_called);
622 mem = my_alloc(sizeof(void *));
623 *(void **)mem = NULL;
625 StubMsg.Buffer = StubMsg.BufferStart;
626 NdrPointerFree( &StubMsg, mem, &fmtstr_ref_unique_out[4] );
627 ok(my_free_called == 0, "free called %d\n", my_free_called);
630 mem = my_alloc(sizeof(void *));
631 *(void **)mem = my_alloc(sizeof(char));
633 StubMsg.Buffer = StubMsg.BufferStart;
634 NdrPointerFree( &StubMsg, mem, &fmtstr_ref_unique_out[4] );
635 ok(my_free_called == 1, "free called %d\n", my_free_called);
640 StubMsg.IsClient = 0;
642 StubMsg.Buffer = StubMsg.BufferStart;
643 NdrPointerUnmarshall( &StubMsg, &mem, &fmtstr_ref_unique_out[4], 0);
644 ok(mem != StubMsg.BufferStart, "mem pointing at buffer\n");
646 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
647 NdrPointerFree( &StubMsg, mem, &fmtstr_ref_unique_out[4] );
651 StubMsg.Buffer = StubMsg.BufferStart;
652 NdrPointerUnmarshall( &StubMsg, &mem, &fmtstr_ref_unique_out[4], 1);
653 ok(mem != StubMsg.BufferStart, "mem pointing at buffer\n");
655 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
656 NdrPointerFree( &StubMsg, mem, &fmtstr_ref_unique_out[4] );
660 *(void **)mem = NULL;
661 StubMsg.Buffer = StubMsg.BufferStart;
662 NdrPointerUnmarshall( &StubMsg, &mem, &fmtstr_ref_unique_out[4], 0);
664 ok(mem == mem_orig, "mem alloced\n");
665 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
670 *(void **)mem = NULL;
671 StubMsg.Buffer = StubMsg.BufferStart;
672 NdrPointerUnmarshall( &StubMsg, &mem, &fmtstr_ref_unique_out[4], 1);
674 ok(mem == mem_orig, "mem alloced\n");
675 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
678 mem = my_alloc(sizeof(void *));
679 *(void **)mem = NULL;
681 StubMsg.Buffer = StubMsg.BufferStart;
682 NdrPointerFree( &StubMsg, mem, &fmtstr_ref_unique_out[4] );
683 ok(my_free_called == 0, "free called %d\n", my_free_called);
686 mem = my_alloc(sizeof(void *));
687 *(void **)mem = my_alloc(sizeof(char));
689 StubMsg.Buffer = StubMsg.BufferStart;
690 NdrPointerFree( &StubMsg, mem, &fmtstr_ref_unique_out[4] );
691 ok(my_free_called == 1, "free called %d\n", my_free_called);
694 HeapFree(GetProcessHeap(), 0, mem_orig);
695 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
698 static void test_simple_struct_marshal(const unsigned char *formattypes,
699 void *memsrc, DWORD srcsize,
700 const void *wiredata,
702 int(*cmp)(const void*,const void*,size_t),
703 int num_additional_allocs,
706 RPC_MESSAGE RpcMessage;
707 MIDL_STUB_MESSAGE StubMsg;
708 MIDL_STUB_DESC StubDesc;
711 unsigned char *mem, *mem_orig;
713 my_alloc_called = my_free_called = 0;
717 StubDesc = Object_StubDesc;
718 StubDesc.pFormatTypes = formattypes;
720 NdrClientInitializeNew(&RpcMessage, &StubMsg, &StubDesc, 0);
722 StubMsg.BufferLength = 0;
723 NdrSimpleStructBufferSize( &StubMsg, memsrc, formattypes );
724 ok(StubMsg.BufferLength >= wiredatalen, "%s: length %d\n", msgpfx, StubMsg.BufferLength);
725 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
726 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
727 ptr = NdrSimpleStructMarshall( &StubMsg, memsrc, formattypes );
728 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
729 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart);
730 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));
732 StubMsg.Buffer = StubMsg.BufferStart;
733 StubMsg.MemorySize = 0;
734 size = NdrSimpleStructMemorySize( &StubMsg, formattypes );
735 ok(size == StubMsg.MemorySize, "%s: size != MemorySize\n", msgpfx);
736 ok(size == srcsize, "%s: mem size %u\n", msgpfx, size);
737 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart);
739 StubMsg.Buffer = StubMsg.BufferStart;
740 size = NdrSimpleStructMemorySize( &StubMsg, formattypes );
741 ok(size == StubMsg.MemorySize, "%s: size != MemorySize\n", msgpfx);
742 ok(StubMsg.MemorySize == ((srcsize + 3) & ~3) + srcsize, "%s: mem size %u\n", msgpfx, size);
743 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart);
745 /*** Unmarshalling first with must_alloc false ***/
747 StubMsg.Buffer = StubMsg.BufferStart;
748 StubMsg.MemorySize = 0;
749 mem_orig = mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, srcsize);
750 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 0 );
751 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
752 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart);
753 ok(mem == mem_orig, "%s: mem has changed %p %p\n", msgpfx, mem, mem_orig);
754 ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx);
755 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
757 ok(StubMsg.MemorySize == 0, "%s: memorysize touched in unmarshal\n", msgpfx);
759 /* If we're a server we still use the supplied memory */
760 StubMsg.Buffer = StubMsg.BufferStart;
761 StubMsg.IsClient = 0;
762 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 0 );
763 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
764 ok(mem == mem_orig, "%s: mem has changed %p %p\n", msgpfx, mem, mem_orig);
765 ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx);
766 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
768 ok(StubMsg.MemorySize == 0, "%s: memorysize touched in unmarshal\n", msgpfx);
770 /* ...unless we pass a NULL ptr, then the buffer is used.
771 Passing a NULL ptr while we're a client && !must_alloc
772 crashes on Windows, so we won't do that. */
774 if (0) /* crashes on Win9x and NT4 */
777 StubMsg.IsClient = 0;
778 StubMsg.Buffer = StubMsg.BufferStart;
779 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, FALSE );
780 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
781 ok(mem == StubMsg.BufferStart, "%s: mem not equal buffer\n", msgpfx);
782 ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx);
783 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
785 ok(StubMsg.MemorySize == 0, "%s: memorysize touched in unmarshal\n", msgpfx);
788 /*** now must_alloc is true ***/
790 /* with must_alloc set we always allocate new memory whether or not we're
791 a server and also when passing NULL */
793 StubMsg.IsClient = 1;
794 StubMsg.Buffer = StubMsg.BufferStart;
795 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 1 );
796 ok(ptr == NULL, "ret %p\n", ptr);
797 ok(mem != mem_orig, "mem not changed %p %p\n", mem, mem_orig);
798 ok(!cmp(mem, memsrc, srcsize), "incorrectly unmarshaled\n");
799 ok(my_alloc_called == num_additional_allocs + 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
801 ok(StubMsg.MemorySize == 0, "memorysize touched in unmarshal\n");
804 StubMsg.Buffer = StubMsg.BufferStart;
805 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 1 );
806 ok(ptr == NULL, "ret %p\n", ptr);
807 ok(mem != mem_orig, "mem not changed %p %p\n", mem, mem_orig);
808 ok(!cmp(mem, memsrc, srcsize), "incorrectly unmarshaled\n");
809 ok(my_alloc_called == num_additional_allocs + 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
811 ok(StubMsg.MemorySize == 0, "memorysize touched in unmarshal\n");
814 StubMsg.Buffer = StubMsg.BufferStart;
815 StubMsg.IsClient = 0;
816 StubMsg.ReuseBuffer = 1;
817 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 1 );
818 ok(ptr == NULL, "ret %p\n", ptr);
819 ok(mem != mem_orig, "mem not changed %p %p\n", mem, mem_orig);
820 ok(mem != StubMsg.BufferStart, "mem is buffer mem\n");
821 ok(!cmp(mem, memsrc, srcsize), "incorrectly unmarshaled\n");
822 ok(my_alloc_called == num_additional_allocs + 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
824 ok(StubMsg.MemorySize == 0, "memorysize touched in unmarshal\n");
827 StubMsg.Buffer = StubMsg.BufferStart;
828 StubMsg.IsClient = 0;
829 StubMsg.ReuseBuffer = 1;
830 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 1 );
831 ok(ptr == NULL, "ret %p\n", ptr);
832 ok(mem != StubMsg.BufferStart, "mem is buffer mem\n");
833 ok(!cmp(mem, memsrc, srcsize), "incorrectly unmarshaled\n");
834 ok(my_alloc_called == num_additional_allocs + 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
836 ok(StubMsg.MemorySize == 0, "memorysize touched in unmarshal\n");
838 HeapFree(GetProcessHeap(), 0, mem_orig);
839 HeapFree(GetProcessHeap(), 0, StubMsg.BufferStart);
849 static int ps1_cmp(const void *s1, const void *s2, size_t num)
851 const ps1_t *p1, *p2;
859 if(p1->pl1 && p2->pl1)
861 if(*p1->pl1 != *p2->pl1)
864 else if(p1->pl1 || p1->pl1)
867 if(p1->pc1 && p2->pc1)
869 if(*p1->pc1 != *p2->pc1)
872 else if(p1->pc1 || p1->pc1)
878 static void test_simple_struct(void)
880 unsigned char wiredata[28];
886 static const unsigned char fmtstr_simple_struct[] =
888 0x12, 0x0, /* FC_UP */
889 NdrFcShort( 0x2 ), /* Offset=2 */
890 0x15, 0x3, /* FC_STRUCT [align 4] */
891 NdrFcShort( 0x18 ), /* [size 24] */
894 0x38, /* FC_ALIGNM4 */
897 0x39, /* FC_ALIGNM8 */
908 static const unsigned char fmtstr_pointer_struct[] =
910 0x12, 0x0, /* FC_UP */
911 NdrFcShort( 0x2 ), /* Offset=2 */
913 0x1a, /* FC_BOGUS_STRUCT */
915 NdrFcShort(0x18), /* [size 24] */
917 NdrFcShort(0x8), /* Offset= 8 (266) */
919 0x39, /* FC_ALIGNM8 */
920 0x36, /* FC_POINTER */
921 0x36, /* FC_POINTER */
924 0x12, 0x8, /* FC_UP [simple_pointer] */
927 0x12, 0x8, /* FC_UP [simple_pointer] */
931 0x16, 0x3, /* FC_PSTRUCT [align 4] */
932 NdrFcShort( 0xc ), /* [size 12] */
935 0x46, /* FC_NO_REPEAT */
937 NdrFcShort( 0x4 ), /* 4 */
938 NdrFcShort( 0x4 ), /* 4 */
939 0x13, 0x8, /* FC_OP [simple_pointer] */
942 0x46, /* FC_NO_REPEAT */
944 NdrFcShort( 0x8 ), /* 8 */
945 NdrFcShort( 0x8 ), /* 8 */
946 0x13, 0x8, /* FC_OP [simple_pointer] */
958 /* zero the entire structure, including the holes */
959 memset(&s1, 0, sizeof(s1));
966 s1.ll = ((LONGLONG) 0xbadefeed << 32) | 0x2468ace0;
969 memcpy(wiredata, &s1, wiredatalen);
970 test_simple_struct_marshal(fmtstr_simple_struct + 4, &s1, 24, wiredata, 24, NULL, 0, "struct");
973 *(unsigned int *)wiredata = 0x20000;
975 *(unsigned int *)wiredata = (UINT_PTR)&s1;
976 memcpy(wiredata + 4, &s1, wiredatalen);
977 test_pointer_marshal(fmtstr_simple_struct, &s1, 24, wiredata, 28, NULL, 0, "struct");
979 if (sizeof(void *) == 8) return; /* it cannot be represented as a simple struct on Win64 */
981 /* zero the entire structure, including the hole */
982 memset(&ps1, 0, sizeof(ps1));
990 *(unsigned int *)(wiredata + 4) = 0xdeadbeef;
993 *(unsigned int *)(wiredata + 8) = 0x20000;
994 *(unsigned int *)(wiredata + 12) = 0x20004;
998 *(unsigned int *)(wiredata + 8) = (UINT_PTR)&l;
999 *(unsigned int *)(wiredata + 12) = (UINT_PTR)&c;
1001 memcpy(wiredata + 16, &l, 4);
1002 memcpy(wiredata + 20, &c, 1);
1004 test_simple_struct_marshal(fmtstr_pointer_struct + 4, &ps1, 17, wiredata + 4, 17, ps1_cmp, 2, "pointer_struct");
1005 if (use_pointer_ids)
1007 *(unsigned int *)wiredata = 0x20000;
1008 *(unsigned int *)(wiredata + 8) = 0x20004;
1009 *(unsigned int *)(wiredata + 12) = 0x20008;
1012 *(unsigned int *)wiredata = (UINT_PTR)&ps1;
1013 test_pointer_marshal(fmtstr_pointer_struct, &ps1, 17, wiredata, 21, ps1_cmp, 2, "pointer_struct");
1016 static void test_fullpointer_xlat(void)
1018 PFULL_PTR_XLAT_TABLES pXlatTables;
1023 pXlatTables = NdrFullPointerXlatInit(2, XLAT_CLIENT);
1025 /* "marshaling" phase */
1027 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 1, &RefId);
1028 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
1029 ok(RefId == 0x1, "RefId should be 0x1 instead of 0x%x\n", RefId);
1031 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 0, &RefId);
1032 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
1033 ok(RefId == 0x1, "RefId should be 0x1 instead of 0x%x\n", RefId);
1035 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebabe, 0, &RefId);
1036 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
1037 ok(RefId == 0x2, "RefId should be 0x2 instead of 0x%x\n", RefId);
1039 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xdeadbeef, 0, &RefId);
1040 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
1041 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
1043 ret = NdrFullPointerQueryPointer(pXlatTables, NULL, 0, &RefId);
1044 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
1045 ok(RefId == 0, "RefId should be 0 instead of 0x%x\n", RefId);
1047 /* "unmarshaling" phase */
1049 ret = NdrFullPointerQueryRefId(pXlatTables, 0x0, 0, &Pointer);
1050 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
1052 ret = NdrFullPointerQueryRefId(pXlatTables, 0x2, 0, &Pointer);
1053 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
1054 ok(Pointer == (void *)0xcafebabe, "Pointer should be 0xcafebabe instead of %p\n", Pointer);
1056 ret = NdrFullPointerQueryRefId(pXlatTables, 0x4, 0, &Pointer);
1057 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
1058 ok(Pointer == NULL, "Pointer should be NULL instead of %p\n", Pointer);
1060 NdrFullPointerInsertRefId(pXlatTables, 0x4, (void *)0xdeadbabe);
1062 ret = NdrFullPointerQueryRefId(pXlatTables, 0x4, 1, &Pointer);
1063 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
1064 ok(Pointer == (void *)0xdeadbabe, "Pointer should be (void *)0xdeadbabe instead of %p\n", Pointer);
1066 NdrFullPointerXlatFree(pXlatTables);
1068 pXlatTables = NdrFullPointerXlatInit(2, XLAT_SERVER);
1070 /* "unmarshaling" phase */
1072 ret = NdrFullPointerQueryRefId(pXlatTables, 0x2, 1, &Pointer);
1073 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
1074 ok(Pointer == NULL, "Pointer should be NULL instead of %p\n", Pointer);
1076 NdrFullPointerInsertRefId(pXlatTables, 0x2, (void *)0xcafebabe);
1078 ret = NdrFullPointerQueryRefId(pXlatTables, 0x2, 0, &Pointer);
1079 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
1080 ok(Pointer == (void *)0xcafebabe, "Pointer should be (void *)0xcafebabe instead of %p\n", Pointer);
1082 ret = NdrFullPointerQueryRefId(pXlatTables, 0x2, 1, &Pointer);
1083 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
1084 ok(Pointer == (void *)0xcafebabe, "Pointer should be (void *)0xcafebabe instead of %p\n", Pointer);
1086 /* "marshaling" phase */
1088 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 1, &RefId);
1089 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
1090 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
1092 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 1, &RefId);
1093 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
1094 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
1096 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 0, &RefId);
1097 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
1098 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
1100 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebabe, 0, &RefId);
1101 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
1102 ok(RefId == 0x2, "RefId should be 0x2 instead of 0x%x\n", RefId);
1104 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xdeadbeef, 0, &RefId);
1105 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
1106 ok(RefId == 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId);
1108 /* "freeing" phase */
1110 ret = NdrFullPointerFree(pXlatTables, (void *)0xcafebeef);
1111 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
1113 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 0x20, &RefId);
1114 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
1115 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
1117 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 1, &RefId);
1118 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
1119 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
1121 ret = NdrFullPointerFree(pXlatTables, (void *)0xcafebabe);
1122 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
1124 ret = NdrFullPointerFree(pXlatTables, (void *)0xdeadbeef);
1125 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
1127 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xdeadbeef, 0x20, &RefId);
1128 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
1129 ok(RefId == 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId);
1131 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xdeadbeef, 1, &RefId);
1132 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
1133 ok(RefId == 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId);
1135 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xdeadbeef, 1, &RefId);
1136 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
1137 ok(RefId == 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId);
1139 ret = NdrFullPointerFree(pXlatTables, (void *)0xdeadbeef);
1140 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
1142 NdrFullPointerXlatFree(pXlatTables);
1145 /* verify stub data that is identical between client and server */
1146 static void test_common_stub_data( const char *prefix, const MIDL_STUB_MESSAGE *stubMsg )
1150 memset(&unset_ptr, 0xcc, sizeof(unset_ptr));
1152 #define TEST_ZERO(field, fmt) ok(stubMsg->field == 0, "%s: " #field " should have been set to zero instead of " fmt "\n", prefix, stubMsg->field)
1153 #define TEST_POINTER_UNSET(field) ok(stubMsg->field == unset_ptr, "%s: " #field " should have been unset instead of %p\n", prefix, stubMsg->field)
1154 #define TEST_ULONG_UNSET(field) ok(stubMsg->field == 0xcccccccc, "%s: " #field " should have been unset instead of 0x%x\n", prefix, stubMsg->field)
1155 #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)
1157 TEST_POINTER_UNSET(BufferMark);
1158 TEST_ULONG_UNSET(MemorySize);
1159 TEST_POINTER_UNSET(Memory);
1160 TEST_ZERO(pAllocAllNodesContext, "%p");
1161 ok(stubMsg->pPointerQueueState == 0 ||
1162 broken(stubMsg->pPointerQueueState == unset_ptr), /* win2k */
1163 "%s: pPointerQueueState should have been unset instead of %p\n",
1164 prefix, stubMsg->pPointerQueueState);
1165 TEST_ZERO(IgnoreEmbeddedPointers, "%d");
1166 TEST_ZERO(PointerBufferMark, "%p");
1167 ok( stubMsg->uFlags == 0 ||
1168 broken(stubMsg->uFlags == 0xcc), /* win9x */
1169 "%s: uFlags should have been set to zero instead of 0x%x\n", prefix, stubMsg->uFlags );
1170 /* FIXME: UniquePtrCount */
1171 TEST_ULONG_PTR_UNSET(MaxCount);
1172 TEST_ULONG_UNSET(Offset);
1173 TEST_ULONG_UNSET(ActualCount);
1174 ok(stubMsg->pfnAllocate == my_alloc, "%s: pfnAllocate should have been %p instead of %p\n",
1175 prefix, my_alloc, stubMsg->pfnAllocate);
1176 ok(stubMsg->pfnFree == my_free, "%s: pfnFree should have been %p instead of %p\n",
1177 prefix, my_free, stubMsg->pfnFree);
1178 TEST_ZERO(StackTop, "%p");
1179 TEST_POINTER_UNSET(pPresentedType);
1180 TEST_POINTER_UNSET(pTransmitType);
1181 TEST_POINTER_UNSET(SavedHandle);
1182 ok(stubMsg->StubDesc == &Object_StubDesc, "%s: StubDesc should have been %p instead of %p\n",
1183 prefix, &Object_StubDesc, stubMsg->StubDesc);
1184 TEST_ZERO(FullPtrRefId, "%d");
1185 ok( stubMsg->PointerLength == 0 ||
1186 broken(stubMsg->PointerLength == 1), /* win9x, nt4 */
1187 "%s: pAsyncMsg should have been set to zero instead of %d\n", prefix, stubMsg->PointerLength );
1188 TEST_ZERO(fInDontFree, "%d");
1189 TEST_ZERO(fDontCallFreeInst, "%d");
1190 ok( stubMsg->fHasReturn == 0 || broken(stubMsg->fHasReturn), /* win9x, nt4 */
1191 "%s: fHasReturn should have been set to zero instead of %d\n", prefix, stubMsg->fHasReturn );
1192 TEST_ZERO(fHasExtensions, "%d");
1193 TEST_ZERO(fHasNewCorrDesc, "%d");
1194 ok(stubMsg->fIsIn == 0 || broken(stubMsg->fIsIn), /* win9x, nt4 */
1195 "%s: fIsIn should have been set to 0 instead of %d\n", prefix, stubMsg->fIsIn);
1196 TEST_ZERO(fIsOicf, "%d");
1197 ok(stubMsg->fBufferValid == 0,
1198 "%s: fBufferValid should have been set to 0 instead of %d\n", prefix, stubMsg->fBufferValid);
1199 TEST_ZERO(fNeedMCCP, "%d");
1200 ok(stubMsg->fUnused == 0 ||
1201 stubMsg->fUnused == -2, /* Vista */
1202 "%s: fUnused should have been set to 0 or -2 instead of %d\n", prefix, stubMsg->fUnused);
1203 ok(stubMsg->fUnused2 == 0xffffcccc, "%s: fUnused2 should have been 0xffffcccc instead of 0x%x\n",
1204 prefix, stubMsg->fUnused2);
1205 ok(stubMsg->dwDestContext == MSHCTX_DIFFERENTMACHINE,
1206 "%s: dwDestContext should have been MSHCTX_DIFFERENTMACHINE instead of %d\n",
1207 prefix, stubMsg->dwDestContext);
1208 TEST_ZERO(pvDestContext, "%p");
1209 TEST_POINTER_UNSET(SavedContextHandles);
1210 TEST_ULONG_UNSET(ParamNumber);
1211 TEST_ZERO(pRpcChannelBuffer, "%p");
1212 TEST_ZERO(pArrayInfo, "%p");
1213 TEST_POINTER_UNSET(SizePtrCountArray);
1214 TEST_POINTER_UNSET(SizePtrOffsetArray);
1215 TEST_POINTER_UNSET(SizePtrLengthArray);
1216 TEST_POINTER_UNSET(pArgQueue);
1217 TEST_ZERO(dwStubPhase, "%d");
1218 /* FIXME: where does this value come from? */
1219 trace("%s: LowStackMark is %p\n", prefix, stubMsg->LowStackMark);
1220 ok( stubMsg->pAsyncMsg == 0 || broken(stubMsg->pAsyncMsg == unset_ptr), /* win9x, nt4 */
1221 "%s: pAsyncMsg should have been set to zero instead of %p\n", prefix, stubMsg->pAsyncMsg );
1222 ok( stubMsg->pCorrInfo == 0 || broken(stubMsg->pCorrInfo == unset_ptr), /* win9x, nt4 */
1223 "%s: pCorrInfo should have been set to zero instead of %p\n", prefix, stubMsg->pCorrInfo );
1224 ok( stubMsg->pCorrMemory == 0 || broken(stubMsg->pCorrMemory == unset_ptr), /* win9x, nt4 */
1225 "%s: pCorrMemory should have been set to zero instead of %p\n", prefix, stubMsg->pCorrMemory );
1226 ok( stubMsg->pMemoryList == 0 || broken(stubMsg->pMemoryList == unset_ptr), /* win9x, nt4 */
1227 "%s: pMemoryList should have been set to zero instead of %p\n", prefix, stubMsg->pMemoryList );
1228 TEST_POINTER_UNSET(pCSInfo);
1229 TEST_POINTER_UNSET(ConformanceMark);
1230 TEST_POINTER_UNSET(VarianceMark);
1231 ok(stubMsg->Unused == (ULONG_PTR)unset_ptr, "%s: Unused should have be unset instead of 0x%lx\n",
1232 prefix, stubMsg->Unused);
1233 TEST_POINTER_UNSET(pContext);
1234 TEST_POINTER_UNSET(ContextHandleHash);
1235 TEST_POINTER_UNSET(pUserMarshalList);
1236 TEST_ULONG_PTR_UNSET(Reserved51_3);
1237 TEST_ULONG_PTR_UNSET(Reserved51_4);
1238 TEST_ULONG_PTR_UNSET(Reserved51_5);
1240 #undef TEST_ULONG_PTR_UNSET
1241 #undef TEST_ULONG_UNSET
1242 #undef TEST_POINTER_UNSET
1246 static void test_client_init(void)
1248 MIDL_STUB_MESSAGE stubMsg;
1252 memset(&rpcMsg, 0xcc, sizeof(rpcMsg));
1253 memset(&stubMsg, 0xcc, sizeof(stubMsg));
1254 memset(&unset_ptr, 0xcc, sizeof(unset_ptr));
1256 NdrClientInitializeNew(&rpcMsg, &stubMsg, &Object_StubDesc, 1);
1258 test_common_stub_data( "NdrClientInitializeNew", &stubMsg );
1260 ok(stubMsg.RpcMsg == &rpcMsg, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg, stubMsg.RpcMsg);
1261 ok(rpcMsg.Handle == NULL, "rpcMsg.Handle should have been NULL instead of %p\n", rpcMsg.Handle);
1262 ok(rpcMsg.Buffer == unset_ptr, "rpcMsg.Buffer should have been unset instead of %p\n",
1264 ok(rpcMsg.BufferLength == 0xcccccccc, "rpcMsg.BufferLength should have been unset instead of %d\n", rpcMsg.BufferLength);
1265 ok(rpcMsg.ProcNum == 0x8001, "rpcMsg.ProcNum should have been 0x8001 instead of 0x%x\n", rpcMsg.ProcNum);
1266 ok(rpcMsg.TransferSyntax == unset_ptr, "rpcMsg.TransferSyntax should have been unset instead of %p\n", rpcMsg.TransferSyntax);
1267 ok(rpcMsg.RpcInterfaceInformation == Object_StubDesc.RpcInterfaceInformation,
1268 "rpcMsg.RpcInterfaceInformation should have been %p instead of %p\n",
1269 Object_StubDesc.RpcInterfaceInformation, rpcMsg.RpcInterfaceInformation);
1270 /* Note: ReservedForRuntime not tested */
1271 ok(rpcMsg.ManagerEpv == unset_ptr, "rpcMsg.ManagerEpv should have been unset instead of %p\n", rpcMsg.ManagerEpv);
1272 ok(rpcMsg.ImportContext == unset_ptr, "rpcMsg.ImportContext should have been unset instead of %p\n", rpcMsg.ImportContext);
1273 ok(rpcMsg.RpcFlags == 0, "rpcMsg.RpcFlags should have been 0 instead of 0x%x\n", rpcMsg.RpcFlags);
1275 ok(stubMsg.Buffer == unset_ptr, "stubMsg.Buffer should have been unset instead of %p\n",
1277 ok(stubMsg.BufferStart == NULL, "stubMsg.BufferStart should have been NULL instead of %p\n",
1278 stubMsg.BufferStart);
1279 ok(stubMsg.BufferEnd == NULL, "stubMsg.BufferEnd should have been NULL instead of %p\n",
1281 ok(stubMsg.BufferLength == 0, "stubMsg.BufferLength should have been 0 instead of %u\n",
1282 stubMsg.BufferLength);
1283 ok(stubMsg.IsClient == 1, "stubMsg.IsClient should have been 1 instead of %u\n", stubMsg.IsClient);
1284 ok(stubMsg.ReuseBuffer == 0, "stubMsg.ReuseBuffer should have been 0 instead of %d\n",
1285 stubMsg.ReuseBuffer);
1286 ok(stubMsg.CorrDespIncrement == 0, "stubMsg.CorrDespIncrement should have been 0 instead of %d\n",
1287 stubMsg.CorrDespIncrement);
1288 ok(stubMsg.FullPtrXlatTables == unset_ptr, "stubMsg.FullPtrXlatTables should have been unset instead of %p\n",
1289 stubMsg.FullPtrXlatTables);
1292 static void test_server_init(void)
1294 MIDL_STUB_MESSAGE stubMsg;
1297 unsigned char buffer[256];
1299 memset(&rpcMsg, 0, sizeof(rpcMsg));
1300 rpcMsg.Buffer = buffer;
1301 rpcMsg.BufferLength = sizeof(buffer);
1302 rpcMsg.RpcFlags = RPC_BUFFER_COMPLETE;
1304 memset(&stubMsg, 0xcc, sizeof(stubMsg));
1306 ret = NdrServerInitializeNew(&rpcMsg, &stubMsg, &Object_StubDesc);
1307 ok(ret == NULL, "NdrServerInitializeNew should have returned NULL instead of %p\n", ret);
1309 test_common_stub_data( "NdrServerInitializeNew", &stubMsg );
1311 ok(stubMsg.RpcMsg == &rpcMsg, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg, stubMsg.RpcMsg);
1312 ok(stubMsg.Buffer == buffer, "stubMsg.Buffer should have been %p instead of %p\n", buffer, stubMsg.Buffer);
1313 ok(stubMsg.BufferStart == buffer, "stubMsg.BufferStart should have been %p instead of %p\n", buffer, stubMsg.BufferStart);
1314 ok(stubMsg.BufferEnd == buffer + sizeof(buffer), "stubMsg.BufferEnd should have been %p instead of %p\n", buffer + sizeof(buffer), stubMsg.BufferEnd);
1316 ok(stubMsg.BufferLength == 0, "stubMsg.BufferLength should have been 0 instead of %u\n", stubMsg.BufferLength);
1317 ok(stubMsg.IsClient == 0, "stubMsg.IsClient should have been 0 instead of %u\n", stubMsg.IsClient);
1318 ok(stubMsg.ReuseBuffer == 0 ||
1319 broken(stubMsg.ReuseBuffer == 1), /* win2k */
1320 "stubMsg.ReuseBuffer should have been set to zero instead of %d\n", stubMsg.ReuseBuffer);
1321 ok(stubMsg.CorrDespIncrement == 0xcc ||
1322 stubMsg.CorrDespIncrement == 0,
1323 "CorrDespIncrement should have been unset instead of 0x%x\n", stubMsg.CorrDespIncrement);
1324 ok(stubMsg.FullPtrXlatTables == 0, "stubMsg.BufferLength should have been 0 instead of %p\n", stubMsg.FullPtrXlatTables);
1327 static void test_ndr_allocate(void)
1329 RPC_MESSAGE RpcMessage;
1330 MIDL_STUB_MESSAGE StubMsg;
1331 MIDL_STUB_DESC StubDesc;
1333 struct tag_mem_list_v2_t
1338 struct tag_mem_list_v2_t *next;
1340 const DWORD magic_MEML = 'M' << 24 | 'E' << 16 | 'M' << 8 | 'L';
1342 StubDesc = Object_StubDesc;
1343 NdrClientInitializeNew(&RpcMessage, &StubMsg, &StubDesc, 0);
1345 my_alloc_called = my_free_called = 0;
1346 p1 = NdrAllocate(&StubMsg, 10);
1347 p2 = NdrAllocate(&StubMsg, 24);
1348 ok(my_alloc_called == 2, "alloc called %d\n", my_alloc_called);
1349 ok(StubMsg.pMemoryList != NULL, "StubMsg.pMemoryList NULL\n");
1350 if(StubMsg.pMemoryList)
1352 mem_list_v2 = StubMsg.pMemoryList;
1353 if (mem_list_v2->size == 24)
1355 trace("v2 mem list format\n");
1356 ok((char *)mem_list_v2 == (char *)p2 + 24, "expected mem_list_v2 pointer %p, but got %p\n", (char *)p2 + 24, mem_list_v2);
1357 ok(mem_list_v2->magic == magic_MEML, "magic %08x\n", mem_list_v2->magic);
1358 ok(mem_list_v2->size == 24, "wrong size for p2 %d\n", mem_list_v2->size);
1359 ok(mem_list_v2->unknown == 0, "wrong unknown for p2 0x%x\n", mem_list_v2->unknown);
1360 ok(mem_list_v2->next != NULL, "next NULL\n");
1361 mem_list_v2 = mem_list_v2->next;
1364 ok((char *)mem_list_v2 == (char *)p1 + 16, "expected mem_list_v2 pointer %p, but got %p\n", (char *)p1 + 16, mem_list_v2);
1365 ok(mem_list_v2->magic == magic_MEML, "magic %08x\n", mem_list_v2->magic);
1366 ok(mem_list_v2->size == 16, "wrong size for p1 %d\n", mem_list_v2->size);
1367 ok(mem_list_v2->unknown == 0, "wrong unknown for p1 0x%x\n", mem_list_v2->unknown);
1368 ok(mem_list_v2->next == NULL, "next %p\n", mem_list_v2->next);
1371 else win_skip("v1 mem list format\n");
1373 /* NdrFree isn't exported so we can't test free'ing */
1376 static void test_conformant_array(void)
1378 RPC_MESSAGE RpcMessage;
1379 MIDL_STUB_MESSAGE StubMsg;
1380 MIDL_STUB_DESC StubDesc;
1382 unsigned char *mem, *mem_orig;
1383 unsigned char memsrc[20];
1386 static const unsigned char fmtstr_conf_array[] =
1388 0x1b, /* FC_CARRAY */
1390 NdrFcShort( 0x1 ), /* elem size */
1391 0x40, /* Corr desc: const */
1393 NdrFcShort(0x10), /* const = 0x10 */
1398 for (i = 0; i < sizeof(memsrc); i++)
1401 StubDesc = Object_StubDesc;
1402 StubDesc.pFormatTypes = fmtstr_conf_array;
1404 NdrClientInitializeNew(
1410 StubMsg.BufferLength = 0;
1411 NdrConformantArrayBufferSize( &StubMsg,
1413 fmtstr_conf_array );
1414 ok(StubMsg.BufferLength >= 20, "length %d\n", StubMsg.BufferLength);
1416 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1417 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
1418 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
1420 ptr = NdrConformantArrayMarshall( &StubMsg, memsrc, fmtstr_conf_array );
1421 ok(ptr == NULL, "ret %p\n", ptr);
1422 ok(StubMsg.Buffer - StubMsg.BufferStart == 20, "Buffer %p Start %p len %d\n", StubMsg.Buffer, StubMsg.BufferStart, 20);
1423 ok(!memcmp(StubMsg.BufferStart + 4, memsrc, 16), "incorrectly marshaled\n");
1425 StubMsg.Buffer = StubMsg.BufferStart;
1426 StubMsg.MemorySize = 0;
1430 my_alloc_called = 0;
1431 /* passing mem == NULL with must_alloc == 0 crashes under Windows */
1432 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1433 ok(mem != NULL, "mem not alloced\n");
1434 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1435 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1437 my_alloc_called = 0;
1438 StubMsg.Buffer = StubMsg.BufferStart;
1440 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 0);
1441 ok(mem == mem_orig, "mem alloced\n");
1442 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1443 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1445 my_alloc_called = 0;
1446 StubMsg.Buffer = StubMsg.BufferStart;
1447 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1448 ok(mem != mem_orig, "mem not alloced\n");
1449 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1450 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1453 StubMsg.Buffer = StubMsg.BufferStart;
1454 NdrConformantArrayFree( &StubMsg, mem, fmtstr_conf_array );
1455 ok(my_free_called == 0, "free called %d\n", my_free_called);
1456 StubMsg.pfnFree(mem);
1459 my_alloc_called = 0;
1460 StubMsg.IsClient = 0;
1462 StubMsg.Buffer = StubMsg.BufferStart;
1463 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 0);
1464 ok(mem == StubMsg.BufferStart + 4 || broken(!mem), /* win9x, nt4 */
1465 "mem not pointing at buffer %p/%p\n", mem, StubMsg.BufferStart + 4);
1466 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1467 my_alloc_called = 0;
1469 StubMsg.Buffer = StubMsg.BufferStart;
1470 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1471 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1472 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1473 StubMsg.pfnFree(mem);
1475 my_alloc_called = 0;
1477 StubMsg.Buffer = StubMsg.BufferStart;
1478 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 0);
1479 ok(mem == mem_orig, "mem alloced\n");
1480 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1482 my_alloc_called = 0;
1484 StubMsg.Buffer = StubMsg.BufferStart;
1485 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1486 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1487 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1488 StubMsg.pfnFree(mem);
1489 StubMsg.pfnFree(mem_orig);
1491 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
1494 static void test_conformant_string(void)
1496 RPC_MESSAGE RpcMessage;
1497 MIDL_STUB_MESSAGE StubMsg;
1498 MIDL_STUB_DESC StubDesc;
1501 unsigned char *mem, *mem_orig;
1502 char memsrc[] = "This is a test string";
1504 static const unsigned char fmtstr_conf_str[] =
1506 0x11, 0x8, /* FC_RP [simple_pointer] */
1507 0x22, /* FC_C_CSTRING */
1511 StubDesc = Object_StubDesc;
1512 StubDesc.pFormatTypes = fmtstr_conf_str;
1514 memset( &StubMsg, 0, sizeof(StubMsg) ); /* needed on win9x and nt4 */
1515 NdrClientInitializeNew(
1521 StubMsg.BufferLength = 0;
1522 NdrPointerBufferSize( &StubMsg,
1523 (unsigned char *)memsrc,
1525 ok(StubMsg.BufferLength >= sizeof(memsrc) + 12, "length %d\n", StubMsg.BufferLength);
1527 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1528 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
1529 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
1531 ptr = NdrPointerMarshall( &StubMsg, (unsigned char *)memsrc, fmtstr_conf_str );
1532 ok(ptr == NULL, "ret %p\n", ptr);
1533 size = StubMsg.Buffer - StubMsg.BufferStart;
1534 ok(size == sizeof(memsrc) + 12, "Buffer %p Start %p len %d\n",
1535 StubMsg.Buffer, StubMsg.BufferStart, size);
1536 ok(!memcmp(StubMsg.BufferStart + 12, memsrc, sizeof(memsrc)), "incorrectly marshaled\n");
1538 StubMsg.Buffer = StubMsg.BufferStart;
1539 StubMsg.MemorySize = 0;
1543 my_alloc_called = 0;
1544 StubMsg.Buffer = StubMsg.BufferStart;
1545 mem = mem_orig = HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc));
1546 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 0);
1547 ok(mem == mem_orig, "mem not alloced\n");
1548 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1550 my_alloc_called = 0;
1551 StubMsg.Buffer = StubMsg.BufferStart;
1552 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 1);
1554 ok(mem == mem_orig, "mem not alloced\n");
1555 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1559 StubMsg.Buffer = StubMsg.BufferStart;
1560 NdrPointerFree( &StubMsg, mem, fmtstr_conf_str );
1561 ok(my_free_called == 1, "free called %d\n", my_free_called);
1565 StubMsg.Buffer = StubMsg.BufferStart;
1566 NdrPointerFree( &StubMsg, mem, fmtstr_conf_str );
1567 ok(my_free_called == 1, "free called %d\n", my_free_called);
1570 my_alloc_called = 0;
1571 StubMsg.IsClient = 0;
1573 StubMsg.Buffer = StubMsg.BufferStart;
1574 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 0);
1575 ok(mem == StubMsg.BufferStart + 12 || broken(!mem), /* win9x, nt4 */
1576 "mem not pointing at buffer %p/%p\n", mem, StubMsg.BufferStart + 12 );
1577 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1579 my_alloc_called = 0;
1581 StubMsg.Buffer = StubMsg.BufferStart;
1582 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 1);
1584 ok(mem == StubMsg.BufferStart + 12 || broken(!mem), /* win9x, nt4 */
1585 "mem not pointing at buffer %p/%p\n", mem, StubMsg.BufferStart + 12 );
1586 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1589 my_alloc_called = 0;
1590 mem = mem_orig = HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc));
1591 StubMsg.Buffer = StubMsg.BufferStart;
1592 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 0);
1593 ok(mem == StubMsg.BufferStart + 12 || broken(!mem), /* win9x, nt4 */
1594 "mem not pointing at buffer %p/%p\n", mem, StubMsg.BufferStart + 12 );
1595 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1597 my_alloc_called = 0;
1599 StubMsg.Buffer = StubMsg.BufferStart;
1600 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 1);
1602 ok(mem == StubMsg.BufferStart + 12 || broken(!mem), /* win9x, nt4 */
1603 "mem not pointing at buffer %p/%p\n", mem, StubMsg.BufferStart + 12 );
1604 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1609 StubMsg.Buffer = StubMsg.BufferStart;
1610 NdrPointerFree( &StubMsg, mem, fmtstr_conf_str );
1611 ok(my_free_called == 1, "free called %d\n", my_free_called);
1613 HeapFree(GetProcessHeap(), 0, mem_orig);
1614 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
1617 static void test_nonconformant_string(void)
1619 RPC_MESSAGE RpcMessage;
1620 MIDL_STUB_MESSAGE StubMsg;
1621 MIDL_STUB_DESC StubDesc;
1624 unsigned char *mem, *mem_orig;
1625 unsigned char memsrc[10] = "This is";
1626 unsigned char memsrc2[10] = "This is a";
1628 static const unsigned char fmtstr_nonconf_str[] =
1630 0x26, /* FC_CSTRING */
1632 NdrFcShort( 0xa ), /* 10 */
1635 StubDesc = Object_StubDesc;
1636 StubDesc.pFormatTypes = fmtstr_nonconf_str;
1639 NdrClientInitializeNew(
1645 StubMsg.BufferLength = 0;
1647 NdrNonConformantStringBufferSize( &StubMsg, memsrc, fmtstr_nonconf_str );
1648 ok(StubMsg.BufferLength >= strlen((char *)memsrc) + 1 + 8, "length %d\n", StubMsg.BufferLength);
1650 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1651 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
1652 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
1654 ptr = NdrNonConformantStringMarshall( &StubMsg, memsrc, fmtstr_nonconf_str );
1655 ok(ptr == NULL, "ret %p\n", ptr);
1656 size = StubMsg.Buffer - StubMsg.BufferStart;
1657 ok(size == strlen((char *)memsrc) + 1 + 8, "Buffer %p Start %p len %d\n",
1658 StubMsg.Buffer, StubMsg.BufferStart, size);
1659 ok(!memcmp(StubMsg.BufferStart + 8, memsrc, strlen((char *)memsrc) + 1), "incorrectly marshaled\n");
1661 StubMsg.Buffer = StubMsg.BufferStart;
1662 StubMsg.MemorySize = 0;
1666 my_alloc_called = 0;
1667 StubMsg.Buffer = StubMsg.BufferStart;
1668 mem = mem_orig = HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc));
1669 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1670 ok(mem == mem_orig, "mem alloced\n");
1671 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1673 my_alloc_called = 0;
1674 StubMsg.Buffer = StubMsg.BufferStart;
1675 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 1);
1677 ok(mem == mem_orig, "mem alloced\n");
1679 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1682 my_alloc_called = 0;
1683 StubMsg.IsClient = 0;
1685 StubMsg.Buffer = StubMsg.BufferStart;
1686 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1687 ok(mem != mem_orig, "mem not alloced\n");
1688 ok(mem != StubMsg.BufferStart + 8, "mem pointing at buffer\n");
1689 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1692 my_alloc_called = 0;
1694 StubMsg.Buffer = StubMsg.BufferStart;
1695 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1696 ok(mem == mem_orig, "mem alloced\n");
1697 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1699 my_alloc_called = 0;
1701 StubMsg.Buffer = StubMsg.BufferStart;
1702 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 1);
1704 ok(mem == mem_orig, "mem alloced\n");
1706 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1708 HeapFree(GetProcessHeap(), 0, mem_orig);
1709 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
1712 NdrClientInitializeNew(
1718 StubMsg.BufferLength = 0;
1720 NdrNonConformantStringBufferSize( &StubMsg, memsrc2, fmtstr_nonconf_str );
1721 ok(StubMsg.BufferLength >= strlen((char *)memsrc2) + 1 + 8, "length %d\n", StubMsg.BufferLength);
1723 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1724 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
1725 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
1727 ptr = NdrNonConformantStringMarshall( &StubMsg, memsrc2, fmtstr_nonconf_str );
1728 ok(ptr == NULL, "ret %p\n", ptr);
1729 size = StubMsg.Buffer - StubMsg.BufferStart;
1730 ok(size == strlen((char *)memsrc2) + 1 + 8, "Buffer %p Start %p len %d\n",
1731 StubMsg.Buffer, StubMsg.BufferStart, size);
1732 ok(!memcmp(StubMsg.BufferStart + 8, memsrc2, strlen((char *)memsrc2) + 1), "incorrectly marshaled\n");
1734 StubMsg.Buffer = StubMsg.BufferStart;
1735 StubMsg.MemorySize = 0;
1739 my_alloc_called = 0;
1740 StubMsg.Buffer = StubMsg.BufferStart;
1741 mem = mem_orig = HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc));
1742 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1743 ok(mem == mem_orig, "mem alloced\n");
1744 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1746 my_alloc_called = 0;
1747 StubMsg.Buffer = StubMsg.BufferStart;
1748 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 1);
1750 ok(mem == mem_orig, "mem alloced\n");
1752 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1755 my_alloc_called = 0;
1756 StubMsg.IsClient = 0;
1758 StubMsg.Buffer = StubMsg.BufferStart;
1759 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1760 ok(mem != mem_orig, "mem not alloced\n");
1761 ok(mem != StubMsg.BufferStart + 8, "mem pointing at buffer\n");
1762 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1765 my_alloc_called = 0;
1767 StubMsg.Buffer = StubMsg.BufferStart;
1768 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1769 ok(mem == mem_orig, "mem alloced\n");
1770 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1772 my_alloc_called = 0;
1774 StubMsg.Buffer = StubMsg.BufferStart;
1775 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 1);
1777 ok(mem == mem_orig, "mem alloced\n");
1779 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1781 HeapFree(GetProcessHeap(), 0, mem_orig);
1782 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
1785 static void test_conf_complex_struct(void)
1787 RPC_MESSAGE RpcMessage;
1788 MIDL_STUB_MESSAGE StubMsg;
1789 MIDL_STUB_DESC StubDesc;
1795 unsigned int *array[1];
1797 struct conf_complex *memsrc;
1798 struct conf_complex *mem;
1800 static const unsigned char fmtstr_complex_struct[] =
1803 0x1b, /* FC_CARRAY */
1805 /* 2 */ NdrFcShort( 0x4 ), /* 4 */
1806 /* 4 */ 0x8, /* Corr desc: FC_LONG */
1808 /* 6 */ NdrFcShort( 0xfffc ), /* -4 */
1813 0x48, /* FC_VARIABLE_REPEAT */
1814 0x49, /* FC_FIXED_OFFSET */
1815 /* 12 */ NdrFcShort( 0x4 ), /* 4 */
1816 /* 14 */ NdrFcShort( 0x0 ), /* 0 */
1817 /* 16 */ NdrFcShort( 0x1 ), /* 1 */
1818 /* 18 */ NdrFcShort( 0x0 ), /* 0 */
1819 /* 20 */ NdrFcShort( 0x0 ), /* 0 */
1820 /* 22 */ 0x12, 0x8, /* FC_UP [simple_pointer] */
1821 /* 24 */ 0x8, /* FC_LONG */
1827 /* 28 */ 0x5c, /* FC_PAD */
1830 0x1a, /* FC_BOGUS_STRUCT */
1832 /* 32 */ NdrFcShort( 0x4 ), /* 4 */
1833 /* 34 */ NdrFcShort( 0xffffffde ), /* Offset= -34 (0) */
1834 /* 36 */ NdrFcShort( 0x0 ), /* Offset= 0 (36) */
1835 /* 38 */ 0x8, /* FC_LONG */
1839 memsrc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1840 FIELD_OFFSET(struct conf_complex, array[20]));
1843 StubDesc = Object_StubDesc;
1844 StubDesc.pFormatTypes = fmtstr_complex_struct;
1846 NdrClientInitializeNew(
1852 StubMsg.BufferLength = 0;
1853 NdrComplexStructBufferSize( &StubMsg,
1854 (unsigned char *)memsrc,
1855 &fmtstr_complex_struct[30] );
1856 ok(StubMsg.BufferLength >= 28, "length %d\n", StubMsg.BufferLength);
1858 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1859 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
1860 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
1862 ptr = NdrComplexStructMarshall( &StubMsg, (unsigned char *)memsrc,
1863 &fmtstr_complex_struct[30] );
1864 ok(ptr == NULL, "ret %p\n", ptr);
1865 ok(*(unsigned int *)StubMsg.BufferStart == 20, "Conformance should have been 20 instead of %d\n", *(unsigned int *)StubMsg.BufferStart);
1866 ok(*(unsigned int *)(StubMsg.BufferStart + 4) == 20, "conf_complex.size should have been 20 instead of %d\n", *(unsigned int *)(StubMsg.BufferStart + 4));
1867 for (i = 0; i < 20; i++)
1868 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));
1871 my_alloc_called = 0;
1872 StubMsg.IsClient = 0;
1874 StubMsg.Buffer = StubMsg.BufferStart;
1875 ptr = NdrComplexStructUnmarshall( &StubMsg, (unsigned char **)&mem, &fmtstr_complex_struct[30], 0);
1876 ok(ptr == NULL, "ret %p\n", ptr);
1877 ok(mem->size == 20, "mem->size wasn't unmarshalled correctly (%d)\n", mem->size);
1878 ok(mem->array[0] == NULL, "mem->array[0] wasn't unmarshalled correctly (%p)\n", mem->array[0]);
1879 StubMsg.pfnFree(mem);
1881 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
1882 HeapFree(GetProcessHeap(), 0, memsrc);
1885 static void test_ndr_buffer(void)
1887 static unsigned char ncalrpc[] = "ncalrpc";
1888 static unsigned char endpoint[] = "winetest:test_ndr_buffer";
1889 RPC_MESSAGE RpcMessage;
1890 MIDL_STUB_MESSAGE StubMsg;
1891 MIDL_STUB_DESC StubDesc = Object_StubDesc;
1893 unsigned char *binding;
1894 RPC_BINDING_HANDLE Handle;
1896 ULONG prev_buffer_length;
1897 BOOL old_buffer_valid_location;
1899 StubDesc.RpcInterfaceInformation = (void *)&IFoo___RpcServerInterface;
1901 status = RpcServerUseProtseqEp(ncalrpc, 20, endpoint, NULL);
1902 ok(RPC_S_OK == status, "RpcServerUseProtseqEp failed with status %u\n", status);
1903 status = RpcServerRegisterIf(IFoo_v0_0_s_ifspec, NULL, NULL);
1904 ok(RPC_S_OK == status, "RpcServerRegisterIf failed with status %u\n", status);
1905 status = RpcServerListen(1, 20, TRUE);
1906 ok(RPC_S_OK == status, "RpcServerListen failed with status %u\n", status);
1907 if (status != RPC_S_OK)
1909 /* Failed to create a server, running client tests is useless */
1913 status = RpcStringBindingCompose(NULL, ncalrpc, NULL, endpoint, NULL, &binding);
1914 ok(status == RPC_S_OK, "RpcStringBindingCompose failed (%u)\n", status);
1916 status = RpcBindingFromStringBinding(binding, &Handle);
1917 ok(status == RPC_S_OK, "RpcBindingFromStringBinding failed (%u)\n", status);
1918 RpcStringFree(&binding);
1920 NdrClientInitializeNew(&RpcMessage, &StubMsg, &StubDesc, 5);
1922 ret = NdrGetBuffer(&StubMsg, 10, Handle);
1923 ok(ret == StubMsg.Buffer, "NdrGetBuffer should have returned the same value as StubMsg.Buffer instead of %p\n", ret);
1924 ok(RpcMessage.Handle != NULL, "RpcMessage.Handle should not have been NULL\n");
1925 ok(RpcMessage.Buffer != NULL, "RpcMessage.Buffer should not have been NULL\n");
1926 ok(RpcMessage.BufferLength == 10 ||
1927 broken(RpcMessage.BufferLength == 12), /* win2k */
1928 "RpcMessage.BufferLength should have been 10 instead of %d\n", RpcMessage.BufferLength);
1929 ok(RpcMessage.RpcFlags == 0, "RpcMessage.RpcFlags should have been 0x0 instead of 0x%x\n", RpcMessage.RpcFlags);
1930 ok(StubMsg.Buffer != NULL, "Buffer should not have been NULL\n");
1931 ok(!StubMsg.BufferStart, "BufferStart should have been NULL instead of %p\n", StubMsg.BufferStart);
1932 ok(!StubMsg.BufferEnd, "BufferEnd should have been NULL instead of %p\n", StubMsg.BufferEnd);
1934 ok(StubMsg.BufferLength == 0, "BufferLength should have left as 0 instead of being set to %d\n", StubMsg.BufferLength);
1935 old_buffer_valid_location = !StubMsg.fBufferValid;
1936 if (old_buffer_valid_location)
1937 ok(broken(StubMsg.CorrDespIncrement == TRUE), "fBufferValid should have been TRUE instead of 0x%x\n", StubMsg.CorrDespIncrement);
1939 ok(StubMsg.fBufferValid, "fBufferValid should have been non-zero instead of 0x%x\n", StubMsg.fBufferValid);
1941 prev_buffer_length = RpcMessage.BufferLength;
1942 StubMsg.BufferLength = 1;
1943 NdrFreeBuffer(&StubMsg);
1944 ok(RpcMessage.Handle != NULL, "RpcMessage.Handle should not have been NULL\n");
1945 ok(RpcMessage.Buffer != NULL, "RpcMessage.Buffer should not have been NULL\n");
1946 ok(RpcMessage.BufferLength == prev_buffer_length, "RpcMessage.BufferLength should have been left as %d instead of %d\n", prev_buffer_length, RpcMessage.BufferLength);
1947 ok(StubMsg.Buffer != NULL, "Buffer should not have been NULL\n");
1948 ok(StubMsg.BufferLength == 1, "BufferLength should have left as 1 instead of being set to %d\n", StubMsg.BufferLength);
1949 if (old_buffer_valid_location)
1950 ok(broken(StubMsg.CorrDespIncrement == FALSE), "fBufferValid should have been FALSE instead of 0x%x\n", StubMsg.CorrDespIncrement);
1952 ok(!StubMsg.fBufferValid, "fBufferValid should have been FALSE instead of %d\n", StubMsg.fBufferValid);
1954 /* attempt double-free */
1955 NdrFreeBuffer(&StubMsg);
1957 RpcBindingFree(&Handle);
1959 status = RpcServerUnregisterIf(NULL, NULL, FALSE);
1960 ok(status == RPC_S_OK, "RpcServerUnregisterIf failed (%u)\n", status);
1963 static void test_NdrMapCommAndFaultStatus(void)
1965 RPC_STATUS rpc_status;
1966 MIDL_STUB_MESSAGE StubMsg;
1967 RPC_MESSAGE RpcMessage;
1969 NdrClientInitializeNew(&RpcMessage, &StubMsg, &Object_StubDesc, 5);
1971 for (rpc_status = 0; rpc_status < 10000; rpc_status++)
1974 ULONG comm_status = 0;
1975 ULONG fault_status = 0;
1976 ULONG expected_comm_status = 0;
1977 ULONG expected_fault_status = 0;
1978 status = NdrMapCommAndFaultStatus(&StubMsg, &comm_status, &fault_status, rpc_status);
1979 ok(status == RPC_S_OK, "NdrMapCommAndFaultStatus failed with error %d\n", status);
1982 case ERROR_INVALID_HANDLE:
1983 case RPC_S_INVALID_BINDING:
1984 case RPC_S_UNKNOWN_IF:
1985 case RPC_S_SERVER_UNAVAILABLE:
1986 case RPC_S_SERVER_TOO_BUSY:
1987 case RPC_S_CALL_FAILED_DNE:
1988 case RPC_S_PROTOCOL_ERROR:
1989 case RPC_S_UNSUPPORTED_TRANS_SYN:
1990 case RPC_S_UNSUPPORTED_TYPE:
1991 case RPC_S_PROCNUM_OUT_OF_RANGE:
1992 case EPT_S_NOT_REGISTERED:
1993 case RPC_S_COMM_FAILURE:
1994 expected_comm_status = rpc_status;
1997 expected_fault_status = rpc_status;
1999 ok(comm_status == expected_comm_status, "NdrMapCommAndFaultStatus should have mapped %d to comm status %d instead of %d\n",
2000 rpc_status, expected_comm_status, comm_status);
2001 ok(fault_status == expected_fault_status, "NdrMapCommAndFaultStatus should have mapped %d to fault status %d instead of %d\n",
2002 rpc_status, expected_fault_status, fault_status);
2006 static void test_NdrGetUserMarshalInfo(void)
2009 MIDL_STUB_MESSAGE stubmsg;
2010 USER_MARSHAL_CB umcb;
2011 NDR_USER_MARSHAL_INFO umi;
2012 unsigned char buffer[16];
2013 void *rpc_channel_buffer = (void *)(ULONG_PTR)0xcafebabe;
2014 RPC_MESSAGE rpc_msg;
2015 RPC_STATUS (RPC_ENTRY *pNdrGetUserMarshalInfo)(ULONG *,ULONG,NDR_USER_MARSHAL_INFO *);
2017 pNdrGetUserMarshalInfo = (void *)GetProcAddress(GetModuleHandle("rpcrt4.dll"), "NdrGetUserMarshalInfo");
2018 if (!pNdrGetUserMarshalInfo)
2020 skip("NdrGetUserMarshalInfo not exported\n");
2026 memset(&rpc_msg, 0xcc, sizeof(rpc_msg));
2027 rpc_msg.Buffer = buffer;
2028 rpc_msg.BufferLength = 16;
2030 memset(&stubmsg, 0xcc, sizeof(stubmsg));
2031 stubmsg.RpcMsg = &rpc_msg;
2032 stubmsg.dwDestContext = MSHCTX_INPROC;
2033 stubmsg.pvDestContext = NULL;
2034 stubmsg.Buffer = buffer + 15;
2035 stubmsg.BufferLength = 0;
2036 stubmsg.BufferEnd = NULL;
2037 stubmsg.pRpcChannelBuffer = rpc_channel_buffer;
2038 stubmsg.StubDesc = NULL;
2039 stubmsg.pfnAllocate = my_alloc;
2040 stubmsg.pfnFree = my_free;
2042 memset(&umcb, 0xcc, sizeof(umcb));
2043 umcb.Flags = MAKELONG(MSHCTX_INPROC, NDR_LOCAL_DATA_REPRESENTATION);
2044 umcb.pStubMsg = &stubmsg;
2045 umcb.Signature = USER_MARSHAL_CB_SIGNATURE;
2046 umcb.CBType = USER_MARSHAL_CB_UNMARSHALL;
2048 memset(&umi, 0xaa, sizeof(umi));
2050 status = pNdrGetUserMarshalInfo(&umcb.Flags, 1, &umi);
2051 ok(status == RPC_S_OK, "NdrGetUserMarshalInfo failed with error %d\n", status);
2052 ok( umi.InformationLevel == 1,
2053 "umi.InformationLevel was %u instead of 1\n",
2054 umi.InformationLevel);
2055 ok( U1(umi).Level1.Buffer == buffer + 15,
2056 "umi.Level1.Buffer was %p instead of %p\n",
2057 U1(umi).Level1.Buffer, buffer);
2058 ok( U1(umi).Level1.BufferSize == 1,
2059 "umi.Level1.BufferSize was %u instead of 1\n",
2060 U1(umi).Level1.BufferSize);
2061 ok( U1(umi).Level1.pfnAllocate == my_alloc,
2062 "umi.Level1.pfnAllocate was %p instead of %p\n",
2063 U1(umi).Level1.pfnAllocate, my_alloc);
2064 ok( U1(umi).Level1.pfnFree == my_free,
2065 "umi.Level1.pfnFree was %p instead of %p\n",
2066 U1(umi).Level1.pfnFree, my_free);
2067 ok( U1(umi).Level1.pRpcChannelBuffer == rpc_channel_buffer,
2068 "umi.Level1.pRpcChannelBuffer was %p instead of %p\n",
2069 U1(umi).Level1.pRpcChannelBuffer, rpc_channel_buffer);
2073 rpc_msg.Buffer = buffer;
2074 rpc_msg.BufferLength = 16;
2076 stubmsg.Buffer = buffer;
2077 stubmsg.BufferLength = 16;
2078 stubmsg.BufferEnd = NULL;
2080 umcb.CBType = USER_MARSHAL_CB_BUFFER_SIZE;
2082 memset(&umi, 0xaa, sizeof(umi));
2084 status = pNdrGetUserMarshalInfo(&umcb.Flags, 1, &umi);
2085 ok(status == RPC_S_OK, "NdrGetUserMarshalInfo failed with error %d\n", status);
2086 ok( umi.InformationLevel == 1,
2087 "umi.InformationLevel was %u instead of 1\n",
2088 umi.InformationLevel);
2089 ok( U1(umi).Level1.Buffer == NULL,
2090 "umi.Level1.Buffer was %p instead of NULL\n",
2091 U1(umi).Level1.Buffer);
2092 ok( U1(umi).Level1.BufferSize == 0,
2093 "umi.Level1.BufferSize was %u instead of 0\n",
2094 U1(umi).Level1.BufferSize);
2095 ok( U1(umi).Level1.pfnAllocate == my_alloc,
2096 "umi.Level1.pfnAllocate was %p instead of %p\n",
2097 U1(umi).Level1.pfnAllocate, my_alloc);
2098 ok( U1(umi).Level1.pfnFree == my_free,
2099 "umi.Level1.pfnFree was %p instead of %p\n",
2100 U1(umi).Level1.pfnFree, my_free);
2101 ok( U1(umi).Level1.pRpcChannelBuffer == rpc_channel_buffer,
2102 "umi.Level1.pRpcChannelBuffer was %p instead of %p\n",
2103 U1(umi).Level1.pRpcChannelBuffer, rpc_channel_buffer);
2107 rpc_msg.Buffer = buffer;
2108 rpc_msg.BufferLength = 16;
2110 stubmsg.Buffer = buffer + 15;
2111 stubmsg.BufferLength = 0;
2112 stubmsg.BufferEnd = NULL;
2114 umcb.CBType = USER_MARSHAL_CB_MARSHALL;
2116 memset(&umi, 0xaa, sizeof(umi));
2118 status = pNdrGetUserMarshalInfo(&umcb.Flags, 1, &umi);
2119 ok(status == RPC_S_OK, "NdrGetUserMarshalInfo failed with error %d\n", status);
2120 ok( umi.InformationLevel == 1,
2121 "umi.InformationLevel was %u instead of 1\n",
2122 umi.InformationLevel);
2123 ok( U1(umi).Level1.Buffer == buffer + 15,
2124 "umi.Level1.Buffer was %p instead of %p\n",
2125 U1(umi).Level1.Buffer, buffer);
2126 ok( U1(umi).Level1.BufferSize == 1,
2127 "umi.Level1.BufferSize was %u instead of 1\n",
2128 U1(umi).Level1.BufferSize);
2129 ok( U1(umi).Level1.pfnAllocate == my_alloc,
2130 "umi.Level1.pfnAllocate was %p instead of %p\n",
2131 U1(umi).Level1.pfnAllocate, my_alloc);
2132 ok( U1(umi).Level1.pfnFree == my_free,
2133 "umi.Level1.pfnFree was %p instead of %p\n",
2134 U1(umi).Level1.pfnFree, my_free);
2135 ok( U1(umi).Level1.pRpcChannelBuffer == rpc_channel_buffer,
2136 "umi.Level1.pRpcChannelBuffer was %p instead of %p\n",
2137 U1(umi).Level1.pRpcChannelBuffer, rpc_channel_buffer);
2141 rpc_msg.Buffer = buffer;
2142 rpc_msg.BufferLength = 16;
2144 stubmsg.Buffer = buffer;
2145 stubmsg.BufferLength = 16;
2146 stubmsg.BufferEnd = NULL;
2148 umcb.CBType = USER_MARSHAL_CB_FREE;
2150 memset(&umi, 0xaa, sizeof(umi));
2152 status = pNdrGetUserMarshalInfo(&umcb.Flags, 1, &umi);
2153 ok(status == RPC_S_OK, "NdrGetUserMarshalInfo failed with error %d\n", status);
2154 ok( umi.InformationLevel == 1,
2155 "umi.InformationLevel was %u instead of 1\n",
2156 umi.InformationLevel);
2157 ok( U1(umi).Level1.Buffer == NULL,
2158 "umi.Level1.Buffer was %p instead of NULL\n",
2159 U1(umi).Level1.Buffer);
2160 ok( U1(umi).Level1.BufferSize == 0,
2161 "umi.Level1.BufferSize was %u instead of 0\n",
2162 U1(umi).Level1.BufferSize);
2163 ok( U1(umi).Level1.pfnAllocate == my_alloc,
2164 "umi.Level1.pfnAllocate was %p instead of %p\n",
2165 U1(umi).Level1.pfnAllocate, my_alloc);
2166 ok( U1(umi).Level1.pfnFree == my_free,
2167 "umi.Level1.pfnFree was %p instead of %p\n",
2168 U1(umi).Level1.pfnFree, my_free);
2169 ok( U1(umi).Level1.pRpcChannelBuffer == rpc_channel_buffer,
2170 "umi.Level1.pRpcChannelBuffer was %p instead of %p\n",
2171 U1(umi).Level1.pRpcChannelBuffer, rpc_channel_buffer);
2175 rpc_msg.Buffer = buffer;
2176 rpc_msg.BufferLength = 15;
2178 stubmsg.Buffer = buffer + 15;
2179 stubmsg.BufferLength = 0;
2180 stubmsg.BufferEnd = NULL;
2182 umcb.CBType = USER_MARSHAL_CB_MARSHALL;
2184 status = pNdrGetUserMarshalInfo(&umcb.Flags, 1, &umi);
2185 ok(status == RPC_S_OK, "NdrGetUserMarshalInfo failed with error %d\n", status);
2186 ok( U1(umi).Level1.BufferSize == 0,
2187 "umi.Level1.BufferSize was %u instead of 0\n",
2188 U1(umi).Level1.BufferSize);
2190 /* error conditions */
2192 rpc_msg.BufferLength = 14;
2193 status = pNdrGetUserMarshalInfo(&umcb.Flags, 1, &umi);
2194 ok(status == ERROR_INVALID_USER_BUFFER,
2195 "NdrGetUserMarshalInfo should have failed with ERROR_INVALID_USER_BUFFER instead of %d\n", status);
2197 rpc_msg.BufferLength = 15;
2198 status = pNdrGetUserMarshalInfo(&umcb.Flags, 9999, &umi);
2199 ok(status == RPC_S_INVALID_ARG,
2200 "NdrGetUserMarshalInfo should have failed with RPC_S_INVALID_ARG instead of %d\n", status);
2203 status = pNdrGetUserMarshalInfo(&umcb.Flags, 1, &umi);
2204 ok(status == RPC_S_OK, "NdrGetUserMarshalInfo failed with error %d\n", status);
2206 umcb.CBType = USER_MARSHAL_CB_MARSHALL;
2208 status = pNdrGetUserMarshalInfo(&umcb.Flags, 1, &umi);
2209 ok(status == RPC_S_INVALID_ARG,
2210 "NdrGetUserMarshalInfo should have failed with RPC_S_INVALID_ARG instead of %d\n", status);
2213 START_TEST( ndr_marshall )
2215 determine_pointer_marshalling_style();
2217 test_ndr_simple_type();
2218 test_simple_types();
2219 test_nontrivial_pointer_types();
2220 test_simple_struct();
2221 test_fullpointer_xlat();
2224 test_ndr_allocate();
2225 test_conformant_array();
2226 test_conformant_string();
2227 test_nonconformant_string();
2228 test_conf_complex_struct();
2230 test_NdrMapCommAndFaultStatus();
2231 test_NdrGetUserMarshalInfo();