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;
101 static void test_ndr_simple_type(void)
103 RPC_MESSAGE RpcMessage;
104 MIDL_STUB_MESSAGE StubMsg;
105 MIDL_STUB_DESC StubDesc;
108 StubDesc = Object_StubDesc;
109 StubDesc.pFormatTypes = NULL;
111 NdrClientInitializeNew(
117 StubMsg.BufferLength = 16;
118 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
120 NdrSimpleTypeMarshall(&StubMsg, (unsigned char*)&l, 8 /* FC_LONG */);
121 ok(StubMsg.Buffer == StubMsg.BufferStart + 4, "%p %p\n", StubMsg.Buffer, StubMsg.BufferStart);
122 ok(*(long*)StubMsg.BufferStart == l, "%ld\n", *(long*)StubMsg.BufferStart);
124 StubMsg.Buffer = StubMsg.BufferStart + 1;
125 NdrSimpleTypeMarshall(&StubMsg, (unsigned char*)&l, 8 /* FC_LONG */);
126 ok(StubMsg.Buffer == StubMsg.BufferStart + 8, "%p %p\n", StubMsg.Buffer, StubMsg.BufferStart);
127 ok(*(long*)(StubMsg.BufferStart + 4) == l, "%ld\n", *(long*)StubMsg.BufferStart);
129 StubMsg.Buffer = StubMsg.BufferStart + 1;
130 NdrSimpleTypeUnmarshall(&StubMsg, (unsigned char*)&l2, 8 /* FC_LONG */);
131 ok(StubMsg.Buffer == StubMsg.BufferStart + 8, "%p %p\n", StubMsg.Buffer, StubMsg.BufferStart);
132 ok(l2 == l, "%ld\n", l2);
134 HeapFree(GetProcessHeap(), 0, StubMsg.BufferStart);
137 static void test_pointer_marshal(const unsigned char *formattypes,
140 const void *wiredata,
142 int(*cmp)(const void*,const void*,size_t),
143 long num_additional_allocs,
146 RPC_MESSAGE RpcMessage;
147 MIDL_STUB_MESSAGE StubMsg;
148 MIDL_STUB_DESC StubDesc;
151 unsigned char *mem, *mem_orig;
153 my_alloc_called = my_free_called = 0;
157 StubDesc = Object_StubDesc;
158 StubDesc.pFormatTypes = formattypes;
160 NdrClientInitializeNew(
166 StubMsg.BufferLength = 0;
167 NdrPointerBufferSize( &StubMsg,
170 ok(StubMsg.BufferLength >= wiredatalen, "%s: length %d\n", msgpfx, StubMsg.BufferLength);
172 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
173 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
174 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
176 memset(StubMsg.BufferStart, 0x0, StubMsg.BufferLength); /* This is a hack to clear the padding between the ptr and longlong/double */
178 ptr = NdrPointerMarshall( &StubMsg, memsrc, formattypes );
179 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
180 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
181 ok(!memcmp(StubMsg.BufferStart, wiredata, wiredatalen), "%s: incorrectly marshaled\n", msgpfx);
183 StubMsg.Buffer = StubMsg.BufferStart;
184 StubMsg.MemorySize = 0;
188 /* NdrPointerMemorySize crashes under Wine */
189 size = NdrPointerMemorySize( &StubMsg, formattypes );
190 ok(size == StubMsg.MemorySize, "%s: mem size %u size %u\n", msgpfx, StubMsg.MemorySize, size);
191 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
192 if(formattypes[1] & 0x10 /* FC_POINTER_DEREF */)
193 ok(size == srcsize + 4, "%s: mem size %u\n", msgpfx, size);
195 ok(size == srcsize, "%s: mem size %u\n", msgpfx, size);
197 StubMsg.Buffer = StubMsg.BufferStart;
198 StubMsg.MemorySize = 16;
199 size = NdrPointerMemorySize( &StubMsg, formattypes );
200 ok(size == StubMsg.MemorySize, "%s: mem size %u size %u\n", msgpfx, StubMsg.MemorySize, size);
201 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
202 if(formattypes[1] & 0x10 /* FC_POINTER_DEREF */)
203 ok(size == srcsize + 4 + 16, "%s: mem size %u\n", msgpfx, size);
205 ok(size == srcsize + 16, "%s: mem size %u\n", msgpfx, size);
207 StubMsg.Buffer = StubMsg.BufferStart;
208 StubMsg.MemorySize = 1;
209 size = NdrPointerMemorySize( &StubMsg, formattypes );
210 ok(size == StubMsg.MemorySize, "%s: mem size %u size %u\n", msgpfx, StubMsg.MemorySize, size);
211 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
212 if(formattypes[1] & 0x10 /* FC_POINTER_DEREF */)
213 ok(size == srcsize + 4 + (srcsize == 8 ? 8 : 4), "%s: mem size %u\n", msgpfx, size);
215 ok(size == srcsize + (srcsize == 8 ? 8 : 4), "%s: mem size %u\n", msgpfx, size);
219 if(formattypes[1] & 0x10) size += 4;
221 StubMsg.Buffer = StubMsg.BufferStart;
222 StubMsg.MemorySize = 0;
223 mem_orig = mem = HeapAlloc(GetProcessHeap(), 0, size);
225 if(formattypes[1] & 0x10 /* FC_POINTER_DEREF */)
227 ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 0 );
228 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
229 ok(mem == mem_orig, "%s: mem has changed %p %p\n", msgpfx, mem, mem_orig);
230 ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx);
231 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
232 ok(StubMsg.MemorySize == 0, "%s: memorysize %d\n", msgpfx, StubMsg.MemorySize);
233 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
236 /* reset the buffer and call with must alloc */
237 StubMsg.Buffer = StubMsg.BufferStart;
238 if(formattypes[1] & 0x10 /* FC_POINTER_DEREF */)
240 ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 1 );
241 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
242 /* doesn't allocate mem in this case */
244 ok(mem == mem_orig, "%s: mem has changed %p %p\n", msgpfx, mem, mem_orig);
246 ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx);
247 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
248 ok(StubMsg.MemorySize == 0, "%s: memorysize %d\n", msgpfx, StubMsg.MemorySize);
251 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
254 if(formattypes[0] != 0x11 /* FC_RP */)
256 /* now pass the address of a NULL ptr */
258 StubMsg.Buffer = StubMsg.BufferStart;
259 ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 0 );
260 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
261 ok(mem != StubMsg.BufferStart + wiredatalen - srcsize, "%s: mem points to buffer %p %p\n", msgpfx, mem, StubMsg.BufferStart);
262 ok(!cmp(mem, memsrc, size), "%s: incorrectly unmarshaled\n", msgpfx);
263 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
264 ok(StubMsg.MemorySize == 0, "%s: memorysize %d\n", msgpfx, StubMsg.MemorySize);
265 ok(my_alloc_called == num_additional_allocs + 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
267 NdrPointerFree(&StubMsg, mem, formattypes);
269 /* again pass address of NULL ptr, but pretend we're a server */
271 StubMsg.Buffer = StubMsg.BufferStart;
272 StubMsg.IsClient = 0;
273 ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 0 );
274 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
275 if (formattypes[2] == 0xd /* FC_ENUM16 */)
276 ok(mem != StubMsg.BufferStart + wiredatalen - srcsize, "%s: mem points to buffer %p %p\n", msgpfx, mem, StubMsg.BufferStart);
278 ok(mem == StubMsg.BufferStart + wiredatalen - srcsize, "%s: mem doesn't point to buffer %p %p\n", msgpfx, mem, StubMsg.BufferStart);
279 ok(!cmp(mem, memsrc, size), "%s: incorrecly unmarshaled\n", msgpfx);
280 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
281 ok(StubMsg.MemorySize == 0, "%s: memorysize %d\n", msgpfx, StubMsg.MemorySize);
282 if (formattypes[2] != 0xd /* FC_ENUM16 */) {
283 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
287 HeapFree(GetProcessHeap(), 0, mem_orig);
288 HeapFree(GetProcessHeap(), 0, StubMsg.BufferStart);
291 static int deref_cmp(const void *s1, const void *s2, size_t num)
293 return memcmp(*(const void *const *)s1, *(const void *const *)s2, num);
297 static void test_simple_types(void)
299 unsigned char wiredata[16];
301 unsigned char *ch_ptr;
309 static const unsigned char fmtstr_up_char[] =
311 0x12, 0x8, /* FC_UP [simple_pointer] */
315 static const unsigned char fmtstr_up_byte[] =
317 0x12, 0x8, /* FC_UP [simple_pointer] */
321 static const unsigned char fmtstr_up_small[] =
323 0x12, 0x8, /* FC_UP [simple_pointer] */
327 static const unsigned char fmtstr_up_usmall[] =
329 0x12, 0x8, /* FC_UP [simple_pointer] */
333 static const unsigned char fmtstr_rp_char[] =
335 0x11, 0x8, /* FC_RP [simple_pointer] */
339 static const unsigned char fmtstr_rpup_char[] =
341 0x11, 0x14, /* FC_RP [alloced_on_stack] */
342 NdrFcShort( 0x2 ), /* Offset= 2 (4) */
343 0x12, 0x8, /* FC_UP [simple_pointer] */
347 static const unsigned char fmtstr_rpup_char2[] =
349 0x11, 0x04, /* FC_RP [alloced_on_stack] */
350 NdrFcShort( 0x2 ), /* Offset= 2 (4) */
351 0x12, 0x8, /* FC_UP [simple_pointer] */
356 static const unsigned char fmtstr_up_wchar[] =
358 0x12, 0x8, /* FC_UP [simple_pointer] */
362 static const unsigned char fmtstr_up_short[] =
364 0x12, 0x8, /* FC_UP [simple_pointer] */
368 static const unsigned char fmtstr_up_ushort[] =
370 0x12, 0x8, /* FC_UP [simple_pointer] */
374 static const unsigned char fmtstr_up_enum16[] =
376 0x12, 0x8, /* FC_UP [simple_pointer] */
380 static const unsigned char fmtstr_up_long[] =
382 0x12, 0x8, /* FC_UP [simple_pointer] */
386 static const unsigned char fmtstr_up_ulong[] =
388 0x12, 0x8, /* FC_UP [simple_pointer] */
392 static const unsigned char fmtstr_up_enum32[] =
394 0x12, 0x8, /* FC_UP [simple_pointer] */
398 static const unsigned char fmtstr_up_errorstatus[] =
400 0x12, 0x8, /* FC_UP [simple_pointer] */
401 0x10, /* FC_ERROR_STATUS_T */
405 static const unsigned char fmtstr_up_longlong[] =
407 0x12, 0x8, /* FC_UP [simple_pointer] */
411 static const unsigned char fmtstr_up_float[] =
413 0x12, 0x8, /* FC_UP [simple_pointer] */
417 static const unsigned char fmtstr_up_double[] =
419 0x12, 0x8, /* FC_UP [simple_pointer] */
426 *(void**)wiredata = ch_ptr;
427 wiredata[sizeof(void*)] = ch;
429 test_pointer_marshal(fmtstr_up_char, ch_ptr, 1, wiredata, 5, NULL, 0, "up_char");
430 test_pointer_marshal(fmtstr_up_byte, ch_ptr, 1, wiredata, 5, NULL, 0, "up_byte");
431 test_pointer_marshal(fmtstr_up_small, ch_ptr, 1, wiredata, 5, NULL, 0, "up_small");
432 test_pointer_marshal(fmtstr_up_usmall, ch_ptr, 1, wiredata, 5, NULL, 0, "up_usmall");
434 test_pointer_marshal(fmtstr_rp_char, ch_ptr, 1, &ch, 1, NULL, 0, "rp_char");
436 test_pointer_marshal(fmtstr_rpup_char, &ch_ptr, 1, wiredata, 5, deref_cmp, 1, "rpup_char");
437 test_pointer_marshal(fmtstr_rpup_char2, ch_ptr, 1, wiredata, 5, NULL, 0, "rpup_char2");
440 *(void**)wiredata = &s;
441 *(unsigned short*)(wiredata + sizeof(void*)) = s;
443 test_pointer_marshal(fmtstr_up_wchar, &s, 2, wiredata, 6, NULL, 0, "up_wchar");
444 test_pointer_marshal(fmtstr_up_short, &s, 2, wiredata, 6, NULL, 0, "up_short");
445 test_pointer_marshal(fmtstr_up_ushort, &s, 2, wiredata, 6, NULL, 0, "up_ushort");
448 *(void**)wiredata = &i;
449 *(unsigned short*)(wiredata + sizeof(void*)) = i;
450 test_pointer_marshal(fmtstr_up_enum16, &i, 2, wiredata, 6, NULL, 0, "up_enum16");
453 *(void**)wiredata = &l;
454 *(unsigned long*)(wiredata + sizeof(void*)) = l;
456 test_pointer_marshal(fmtstr_up_long, &l, 4, wiredata, 8, NULL, 0, "up_long");
457 test_pointer_marshal(fmtstr_up_ulong, &l, 4, wiredata, 8, NULL, 0, "up_ulong");
458 test_pointer_marshal(fmtstr_up_enum32, &l, 4, wiredata, 8, NULL, 0, "up_emun32");
459 test_pointer_marshal(fmtstr_up_errorstatus, &l, 4, wiredata, 8, NULL, 0, "up_errorstatus");
461 ll = ((ULONGLONG)0xcafebabe) << 32 | 0xdeadbeef;
462 *(void**)wiredata = ≪
463 *(void**)(wiredata + sizeof(void*)) = NULL;
464 *(ULONGLONG*)(wiredata + 2 * sizeof(void*)) = ll;
465 test_pointer_marshal(fmtstr_up_longlong, &ll, 8, wiredata, 16, NULL, 0, "up_longlong");
468 *(void**)wiredata = &f;
469 *(float*)(wiredata + sizeof(void*)) = f;
470 test_pointer_marshal(fmtstr_up_float, &f, 4, wiredata, 8, NULL, 0, "up_float");
473 *(void**)wiredata = &d;
474 *(void**)(wiredata + sizeof(void*)) = NULL;
475 *(double*)(wiredata + 2 * sizeof(void*)) = d;
476 test_pointer_marshal(fmtstr_up_double, &d, 8, wiredata, 16, NULL, 0, "up_double");
480 static void test_simple_struct_marshal(const unsigned char *formattypes,
483 const void *wiredata,
485 int(*cmp)(const void*,const void*,size_t),
486 long num_additional_allocs,
489 RPC_MESSAGE RpcMessage;
490 MIDL_STUB_MESSAGE StubMsg;
491 MIDL_STUB_DESC StubDesc;
494 unsigned char *mem, *mem_orig;
496 my_alloc_called = my_free_called = 0;
500 StubDesc = Object_StubDesc;
501 StubDesc.pFormatTypes = formattypes;
503 NdrClientInitializeNew(&RpcMessage, &StubMsg, &StubDesc, 0);
505 StubMsg.BufferLength = 0;
506 NdrSimpleStructBufferSize( &StubMsg, (unsigned char *)memsrc, formattypes );
507 ok(StubMsg.BufferLength >= wiredatalen, "%s: length %d\n", msgpfx, StubMsg.BufferLength);
508 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
509 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
510 ptr = NdrSimpleStructMarshall( &StubMsg, (unsigned char*)memsrc, formattypes );
511 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
512 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart);
513 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));
517 /* FIXME: Causes Wine to crash */
518 StubMsg.Buffer = StubMsg.BufferStart;
519 StubMsg.MemorySize = 0;
520 size = NdrSimpleStructMemorySize( &StubMsg, formattypes );
521 ok(size == StubMsg.MemorySize, "%s: size != MemorySize\n", msgpfx);
522 ok(size == srcsize, "%s: mem size %u\n", msgpfx, size);
523 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart);
525 StubMsg.Buffer = StubMsg.BufferStart;
526 size = NdrSimpleStructMemorySize( &StubMsg, formattypes );
528 ok(size == StubMsg.MemorySize, "%s: size != MemorySize\n", msgpfx);
530 ok(StubMsg.MemorySize == ((srcsize + 3) & ~3) + srcsize, "%s: mem size %u\n", msgpfx, size);
531 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart);
534 /*** Unmarshalling first with must_alloc false ***/
536 StubMsg.Buffer = StubMsg.BufferStart;
537 StubMsg.MemorySize = 0;
538 mem_orig = mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, srcsize);
539 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 0 );
540 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
541 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart);
542 ok(mem == mem_orig, "%s: mem has changed %p %p\n", msgpfx, mem, mem_orig);
543 ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx);
544 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
546 ok(StubMsg.MemorySize == 0, "%s: memorysize touched in unmarshal\n", msgpfx);
548 /* if we're a server we still use the suppiled memory */
549 StubMsg.Buffer = StubMsg.BufferStart;
550 StubMsg.IsClient = 0;
551 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 0 );
552 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
553 ok(mem == mem_orig, "%s: mem has changed %p %p\n", msgpfx, mem, mem_orig);
554 ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx);
555 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
557 ok(StubMsg.MemorySize == 0, "%s: memorysize touched in unmarshal\n", msgpfx);
559 /* ...unless we pass a NULL ptr, then the buffer is used.
560 Passing a NULL ptr while we're a client && !must_alloc
561 crashes on Windows, so we won't do that. */
564 StubMsg.IsClient = 0;
565 StubMsg.Buffer = StubMsg.BufferStart;
566 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 0 );
567 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
568 ok(mem == StubMsg.BufferStart, "%s: mem not equal buffer\n", msgpfx);
569 ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx);
570 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
572 ok(StubMsg.MemorySize == 0, "%s: memorysize touched in unmarshal\n", msgpfx);
574 /*** now must_alloc is true ***/
576 /* with must_alloc set we always allocate new memory whether or not we're
577 a server and also when passing NULL */
579 StubMsg.IsClient = 1;
580 StubMsg.Buffer = StubMsg.BufferStart;
581 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 1 );
582 ok(ptr == NULL, "ret %p\n", ptr);
583 ok(mem != mem_orig, "mem not changed %p %p\n", mem, mem_orig);
584 ok(!cmp(mem, memsrc, srcsize), "incorrectly unmarshaled\n");
585 ok(my_alloc_called == num_additional_allocs + 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
587 ok(StubMsg.MemorySize == 0, "memorysize touched in unmarshal\n");
590 StubMsg.Buffer = StubMsg.BufferStart;
591 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 1 );
592 ok(ptr == NULL, "ret %p\n", ptr);
593 ok(mem != mem_orig, "mem not changed %p %p\n", mem, mem_orig);
594 ok(!cmp(mem, memsrc, srcsize), "incorrectly unmarshaled\n");
595 ok(my_alloc_called == num_additional_allocs + 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
597 ok(StubMsg.MemorySize == 0, "memorysize touched in unmarshal\n");
600 StubMsg.Buffer = StubMsg.BufferStart;
601 StubMsg.IsClient = 0;
602 StubMsg.ReuseBuffer = 1;
603 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 1 );
604 ok(ptr == NULL, "ret %p\n", ptr);
605 ok(mem != mem_orig, "mem not changed %p %p\n", mem, mem_orig);
606 ok(mem != StubMsg.BufferStart, "mem is buffer mem\n");
607 ok(!cmp(mem, memsrc, srcsize), "incorrectly unmarshaled\n");
608 ok(my_alloc_called == num_additional_allocs + 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
610 ok(StubMsg.MemorySize == 0, "memorysize touched in unmarshal\n");
613 StubMsg.Buffer = StubMsg.BufferStart;
614 StubMsg.IsClient = 0;
615 StubMsg.ReuseBuffer = 1;
616 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 1 );
617 ok(ptr == NULL, "ret %p\n", ptr);
618 ok(mem != StubMsg.BufferStart, "mem is buffer mem\n");
619 ok(!cmp(mem, memsrc, srcsize), "incorrectly unmarshaled\n");
620 ok(my_alloc_called == num_additional_allocs + 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
622 ok(StubMsg.MemorySize == 0, "memorysize touched in unmarshal\n");
624 HeapFree(GetProcessHeap(), 0, mem_orig);
625 HeapFree(GetProcessHeap(), 0, StubMsg.BufferStart);
635 static int ps1_cmp(const void *s1, const void *s2, size_t num)
637 const ps1_t *p1, *p2;
645 if(p1->pl1 && p2->pl1)
647 if(*p1->pl1 != *p2->pl1)
650 else if(p1->pl1 || p1->pl1)
653 if(p1->pc1 && p2->pc1)
655 if(*p1->pc1 != *p2->pc1)
658 else if(p1->pc1 || p1->pc1)
664 static void test_simple_struct(void)
666 unsigned char wiredata[28];
667 unsigned long wiredatalen;
672 static const unsigned char fmtstr_simple_struct[] =
674 0x12, 0x0, /* FC_UP */
675 NdrFcShort( 0x2 ), /* Offset=2 */
676 0x15, 0x3, /* FC_STRUCT [align 4] */
677 NdrFcShort( 0x18 ), /* [size 24] */
680 0x38, /* FC_ALIGNM4 */
683 0x39, /* FC_ALIGNM8 */
694 static const unsigned char fmtstr_pointer_struct[] =
696 0x12, 0x0, /* FC_UP */
697 NdrFcShort( 0x2 ), /* Offset=2 */
698 0x16, 0x3, /* FC_PSTRUCT [align 4] */
699 NdrFcShort( 0xc ), /* [size 12] */
702 0x46, /* FC_NO_REPEAT */
704 NdrFcShort( 0x4 ), /* 4 */
705 NdrFcShort( 0x4 ), /* 4 */
706 0x13, 0x8, /* FC_OP [simple_pointer] */
709 0x46, /* FC_NO_REPEAT */
711 NdrFcShort( 0x8 ), /* 8 */
712 NdrFcShort( 0x8 ), /* 8 */
713 0x13, 0x8, /* FC_OP [simple_pointer] */
730 s1.ll = ((LONGLONG) 0xbadefeed << 32) | 0x2468ace0;
733 memcpy(wiredata, &s1, wiredatalen);
734 test_simple_struct_marshal(fmtstr_simple_struct + 4, &s1, 24, wiredata, 24, NULL, 0, "struct");
736 *(void**)wiredata = &s1;
737 memcpy(wiredata + 4, &s1, wiredatalen);
740 /* one of the unmarshallings crashes Wine */
741 test_pointer_marshal(fmtstr_simple_struct, &s1, 24, wiredata, 28, NULL, 0, "struct");
750 memcpy(wiredata + 4, &ps1, 12);
751 memcpy(wiredata + 16, &l, 4);
752 memcpy(wiredata + 20, &c, 1);
754 test_simple_struct_marshal(fmtstr_pointer_struct + 4, &ps1, 17, wiredata + 4, 17, ps1_cmp, 2, "pointer_struct");
755 *(void**)wiredata = &ps1;
758 /* one of the unmarshallings crashes Wine */
759 test_pointer_marshal(fmtstr_pointer_struct, &ps1, 17, wiredata, 21, ps1_cmp, 2, "pointer_struct");
763 static void test_fullpointer_xlat(void)
765 PFULL_PTR_XLAT_TABLES pXlatTables;
770 pXlatTables = NdrFullPointerXlatInit(2, XLAT_CLIENT);
772 /* "marshaling" phase */
774 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 1, &RefId);
775 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
776 ok(RefId == 0x1, "RefId should be 0x1 instead of 0x%x\n", RefId);
778 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 0, &RefId);
779 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
780 ok(RefId == 0x1, "RefId should be 0x1 instead of 0x%x\n", RefId);
782 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebabe, 0, &RefId);
783 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
784 ok(RefId == 0x2, "RefId should be 0x2 instead of 0x%x\n", RefId);
786 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xdeadbeef, 0, &RefId);
787 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
788 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
790 ret = NdrFullPointerQueryPointer(pXlatTables, NULL, 0, &RefId);
791 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
792 ok(RefId == 0, "RefId should be 0 instead of 0x%x\n", RefId);
794 /* "unmarshaling" phase */
796 ret = NdrFullPointerQueryRefId(pXlatTables, 0x2, 0, &Pointer);
797 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
798 ok(Pointer == (void *)0xcafebabe, "Pointer should be 0xcafebabe instead of %p\n", Pointer);
800 ret = NdrFullPointerQueryRefId(pXlatTables, 0x4, 0, &Pointer);
801 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
802 ok(Pointer == NULL, "Pointer should be NULL instead of %p\n", Pointer);
804 NdrFullPointerInsertRefId(pXlatTables, 0x4, (void *)0xdeadbabe);
806 ret = NdrFullPointerQueryRefId(pXlatTables, 0x4, 1, &Pointer);
807 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
808 ok(Pointer == (void *)0xdeadbabe, "Pointer should be (void *)0xdeadbabe instead of %p\n", Pointer);
810 NdrFullPointerXlatFree(pXlatTables);
812 pXlatTables = NdrFullPointerXlatInit(2, XLAT_SERVER);
814 /* "unmarshaling" phase */
816 ret = NdrFullPointerQueryRefId(pXlatTables, 0x2, 1, &Pointer);
817 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
818 ok(Pointer == NULL, "Pointer should be NULL instead of %p\n", Pointer);
820 NdrFullPointerInsertRefId(pXlatTables, 0x2, (void *)0xcafebabe);
822 ret = NdrFullPointerQueryRefId(pXlatTables, 0x2, 0, &Pointer);
823 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
824 ok(Pointer == (void *)0xcafebabe, "Pointer should be (void *)0xcafebabe instead of %p\n", Pointer);
826 ret = NdrFullPointerQueryRefId(pXlatTables, 0x2, 1, &Pointer);
827 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
828 ok(Pointer == (void *)0xcafebabe, "Pointer should be (void *)0xcafebabe instead of %p\n", Pointer);
830 /* "marshaling" phase */
832 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 1, &RefId);
833 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
834 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
836 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 1, &RefId);
837 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
838 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
840 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 0, &RefId);
841 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
842 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
844 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebabe, 0, &RefId);
845 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
846 ok(RefId == 0x2, "RefId should be 0x2 instead of 0x%x\n", RefId);
848 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xdeadbeef, 0, &RefId);
849 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
850 ok(RefId == 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId);
852 /* "freeing" phase */
854 ret = NdrFullPointerFree(pXlatTables, (void *)0xcafebeef);
855 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
857 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 0x20, &RefId);
858 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
859 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
861 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 1, &RefId);
862 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
863 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
865 ret = NdrFullPointerFree(pXlatTables, (void *)0xcafebabe);
866 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
868 ret = NdrFullPointerFree(pXlatTables, (void *)0xdeadbeef);
869 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
871 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xdeadbeef, 0x20, &RefId);
872 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
873 ok(RefId == 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId);
875 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xdeadbeef, 1, &RefId);
876 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
877 ok(RefId == 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId);
879 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xdeadbeef, 1, &RefId);
880 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
881 ok(RefId == 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId);
883 ret = NdrFullPointerFree(pXlatTables, (void *)0xdeadbeef);
884 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
886 NdrFullPointerXlatFree(pXlatTables);
889 static void test_client_init(void)
891 MIDL_STUB_MESSAGE stubMsg;
894 memset(&rpcMsg, 0xcc, sizeof(rpcMsg));
895 memset(&stubMsg, 0xcc, sizeof(stubMsg));
897 NdrClientInitializeNew(&rpcMsg, &stubMsg, &Object_StubDesc, 1);
899 #define TEST_POINTER_UNSET(field) ok(rpcMsg.field == (void *)0xcccccccc, #field " should have been unset instead of %p\n", rpcMsg.field)
901 ok(rpcMsg.Handle == NULL, "rpcMsg.Handle should have been NULL instead of %p\n", rpcMsg.Handle);
902 TEST_POINTER_UNSET(Buffer);
903 ok(rpcMsg.BufferLength == 0xcccccccc, "rpcMsg.BufferLength should have been unset instead of %d\n", rpcMsg.BufferLength);
904 ok(rpcMsg.ProcNum == 0x8001, "rpcMsg.ProcNum should have been 0x8001 instead of 0x%x\n", rpcMsg.ProcNum);
905 TEST_POINTER_UNSET(TransferSyntax);
906 ok(rpcMsg.RpcInterfaceInformation == Object_StubDesc.RpcInterfaceInformation,
907 "rpcMsg.RpcInterfaceInformation should have been %p instead of %p\n",
908 Object_StubDesc.RpcInterfaceInformation, rpcMsg.RpcInterfaceInformation);
909 /* Note: ReservedForRuntime not tested */
910 TEST_POINTER_UNSET(ManagerEpv);
911 TEST_POINTER_UNSET(ImportContext);
912 ok(rpcMsg.RpcFlags == 0, "rpcMsg.RpcFlags should have been 0 instead of 0x%lx\n", rpcMsg.RpcFlags);
913 #undef TEST_POINTER_UNSET
915 #define TEST_ZERO(field, fmt) ok(stubMsg.field == 0, #field " should have been set to zero instead of " fmt "\n", stubMsg.field)
916 #define TEST_POINTER_UNSET(field) ok(stubMsg.field == (void *)0xcccccccc, #field " should have been unset instead of %p\n", stubMsg.field)
917 #define TEST_ULONG_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%x\n", stubMsg.field)
918 #define TEST_ULONG_PTR_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%lx\n", stubMsg.field)
920 ok(stubMsg.RpcMsg == &rpcMsg, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg, stubMsg.RpcMsg);
921 TEST_POINTER_UNSET(Buffer);
922 TEST_ZERO(BufferStart, "%p");
923 TEST_ZERO(BufferEnd, "%p");
924 TEST_POINTER_UNSET(BufferMark);
925 TEST_ZERO(BufferLength, "%d");
926 TEST_ULONG_UNSET(MemorySize);
927 TEST_POINTER_UNSET(Memory);
928 ok(stubMsg.IsClient == 1, "stubMsg.IsClient should have been 1 instead of %u\n", stubMsg.IsClient);
929 TEST_ZERO(ReuseBuffer, "%d");
930 TEST_ZERO(pAllocAllNodesContext, "%p");
931 TEST_ZERO(pPointerQueueState, "%p");
932 TEST_ZERO(IgnoreEmbeddedPointers, "%d");
933 TEST_ZERO(PointerBufferMark, "%p");
934 TEST_ZERO(fBufferValid, "%d");
935 TEST_ZERO(uFlags, "%d");
936 /* FIXME: UniquePtrCount */
937 TEST_ULONG_PTR_UNSET(MaxCount);
938 TEST_ULONG_UNSET(Offset);
939 TEST_ULONG_UNSET(ActualCount);
940 ok(stubMsg.pfnAllocate == my_alloc, "stubMsg.pfnAllocate should have been %p instead of %p\n", my_alloc, stubMsg.pfnAllocate);
941 ok(stubMsg.pfnFree == my_free, "stubMsg.pfnFree should have been %p instead of %p\n", my_free, stubMsg.pfnFree);
942 TEST_ZERO(StackTop, "%p");
943 TEST_POINTER_UNSET(pPresentedType);
944 TEST_POINTER_UNSET(pTransmitType);
945 TEST_POINTER_UNSET(SavedHandle);
946 ok(stubMsg.StubDesc == &Object_StubDesc, "stubMsg.StubDesc should have been %p instead of %p\n", &Object_StubDesc, stubMsg.StubDesc);
947 TEST_POINTER_UNSET(FullPtrXlatTables);
948 TEST_ZERO(FullPtrRefId, "%d");
949 TEST_ZERO(PointerLength, "%d");
950 TEST_ZERO(fInDontFree, "%d");
951 TEST_ZERO(fDontCallFreeInst, "%d");
952 TEST_ZERO(fInOnlyParam, "%d");
953 TEST_ZERO(fHasReturn, "%d");
954 TEST_ZERO(fHasExtensions, "%d");
955 TEST_ZERO(fHasNewCorrDesc, "%d");
956 TEST_ZERO(fUnused, "%d");
957 ok(stubMsg.fUnused2 == 0xffffcccc, "stubMsg.fUnused2 should have been 0xcccc instead of 0x%x\n", stubMsg.fUnused2);
958 ok(stubMsg.dwDestContext == MSHCTX_DIFFERENTMACHINE, "stubMsg.dwDestContext should have been MSHCTX_DIFFERENTMACHINE instead of %d\n", stubMsg.dwDestContext);
959 TEST_ZERO(pvDestContext, "%p");
960 TEST_POINTER_UNSET(SavedContextHandles);
961 TEST_ULONG_UNSET(ParamNumber);
962 TEST_ZERO(pRpcChannelBuffer, "%p");
963 TEST_ZERO(pArrayInfo, "%p");
964 TEST_POINTER_UNSET(SizePtrCountArray);
965 TEST_POINTER_UNSET(SizePtrOffsetArray);
966 TEST_POINTER_UNSET(SizePtrLengthArray);
967 TEST_POINTER_UNSET(pArgQueue);
968 TEST_ZERO(dwStubPhase, "%d");
969 /* FIXME: where does this value come from? */
970 trace("LowStackMark is %p\n", stubMsg.LowStackMark);
971 TEST_ZERO(pAsyncMsg, "%p");
972 TEST_ZERO(pCorrInfo, "%p");
973 TEST_ZERO(pCorrMemory, "%p");
974 TEST_ZERO(pMemoryList, "%p");
975 TEST_POINTER_UNSET(pCSInfo);
976 TEST_POINTER_UNSET(ConformanceMark);
977 TEST_POINTER_UNSET(VarianceMark);
978 ok(stubMsg.Unused == 0xcccccccc, "Unused should have be unset instead of 0x%lx\n", stubMsg.Unused);
979 TEST_POINTER_UNSET(pContext);
980 TEST_POINTER_UNSET(ContextHandleHash);
981 TEST_POINTER_UNSET(pUserMarshalList);
982 TEST_ULONG_PTR_UNSET(Reserved51_3);
983 TEST_ULONG_PTR_UNSET(Reserved51_4);
984 TEST_ULONG_PTR_UNSET(Reserved51_5);
985 #undef TEST_ULONG_UNSET
986 #undef TEST_POINTER_UNSET
991 static void test_server_init(void)
993 MIDL_STUB_MESSAGE stubMsg;
996 unsigned char buffer[256];
998 memset(&rpcMsg, 0, sizeof(rpcMsg));
999 rpcMsg.Buffer = buffer;
1000 rpcMsg.BufferLength = sizeof(buffer);
1001 rpcMsg.RpcFlags = RPC_BUFFER_COMPLETE;
1003 memset(&stubMsg, 0xcc, sizeof(stubMsg));
1005 ret = NdrServerInitializeNew(&rpcMsg, &stubMsg, &Object_StubDesc);
1006 ok(ret == NULL, "NdrServerInitializeNew should have returned NULL instead of %p\n", ret);
1008 #define TEST_ZERO(field, fmt) ok(stubMsg.field == 0, #field " should have been set to zero instead of " fmt "\n", stubMsg.field)
1009 #define TEST_POINTER_UNSET(field) ok(stubMsg.field == (void *)0xcccccccc, #field " should have been unset instead of %p\n", stubMsg.field)
1010 #define TEST_ULONG_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%x\n", stubMsg.field)
1011 #define TEST_ULONG_PTR_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%lx\n", stubMsg.field)
1013 ok(stubMsg.RpcMsg == &rpcMsg, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg, stubMsg.RpcMsg);
1014 ok(stubMsg.Buffer == buffer, "stubMsg.Buffer should have been %p instead of %p\n", buffer, stubMsg.Buffer);
1015 ok(stubMsg.BufferStart == buffer, "stubMsg.BufferStart should have been %p instead of %p\n", buffer, stubMsg.BufferStart);
1016 ok(stubMsg.BufferEnd == buffer + sizeof(buffer), "stubMsg.BufferEnd should have been %p instead of %p\n", buffer + sizeof(buffer), stubMsg.BufferEnd);
1017 TEST_POINTER_UNSET(BufferMark);
1019 TEST_ZERO(BufferLength, "%d");
1020 TEST_ULONG_UNSET(MemorySize);
1021 TEST_POINTER_UNSET(Memory);
1022 ok(stubMsg.IsClient == 0, "stubMsg.IsClient should have been 0 instead of %u\n", stubMsg.IsClient);
1023 TEST_ZERO(ReuseBuffer, "%d");
1024 TEST_ZERO(pAllocAllNodesContext, "%p");
1025 TEST_ZERO(pPointerQueueState, "%p");
1026 TEST_ZERO(IgnoreEmbeddedPointers, "%d");
1027 TEST_ZERO(PointerBufferMark, "%p");
1028 ok(stubMsg.fBufferValid == 0xcc, "fBufferValid should have been unset instead of 0x%x\n", stubMsg.fBufferValid);
1029 TEST_ZERO(uFlags, "%d");
1030 /* FIXME: UniquePtrCount */
1031 TEST_ULONG_PTR_UNSET(MaxCount);
1032 TEST_ULONG_UNSET(Offset);
1033 TEST_ULONG_UNSET(ActualCount);
1034 ok(stubMsg.pfnAllocate == my_alloc, "stubMsg.pfnAllocate should have been %p instead of %p\n", my_alloc, stubMsg.pfnAllocate);
1035 ok(stubMsg.pfnFree == my_free, "stubMsg.pfnFree should have been %p instead of %p\n", my_free, stubMsg.pfnFree);
1036 TEST_ZERO(StackTop, "%p");
1037 TEST_POINTER_UNSET(pPresentedType);
1038 TEST_POINTER_UNSET(pTransmitType);
1039 TEST_POINTER_UNSET(SavedHandle);
1040 ok(stubMsg.StubDesc == &Object_StubDesc, "stubMsg.StubDesc should have been %p instead of %p\n", &Object_StubDesc, stubMsg.StubDesc);
1041 TEST_ZERO(FullPtrXlatTables, "%p");
1042 TEST_ZERO(FullPtrRefId, "%d");
1043 TEST_ZERO(PointerLength, "%d");
1044 TEST_ZERO(fInDontFree, "%d");
1045 TEST_ZERO(fDontCallFreeInst, "%d");
1046 TEST_ZERO(fInOnlyParam, "%d");
1047 TEST_ZERO(fHasReturn, "%d");
1048 TEST_ZERO(fHasExtensions, "%d");
1049 TEST_ZERO(fHasNewCorrDesc, "%d");
1050 TEST_ZERO(fUnused, "%d");
1051 ok(stubMsg.fUnused2 == 0xffffcccc, "stubMsg.fUnused2 should have been 0xcccc instead of 0x%x\n", stubMsg.fUnused2);
1052 ok(stubMsg.dwDestContext == MSHCTX_DIFFERENTMACHINE, "stubMsg.dwDestContext should have been MSHCTX_DIFFERENTMACHINE instead of %d\n", stubMsg.dwDestContext);
1053 TEST_ZERO(pvDestContext, "%p");
1054 TEST_POINTER_UNSET(SavedContextHandles);
1055 TEST_ULONG_UNSET(ParamNumber);
1056 TEST_ZERO(pRpcChannelBuffer, "%p");
1057 TEST_ZERO(pArrayInfo, "%p");
1058 TEST_POINTER_UNSET(SizePtrCountArray);
1059 TEST_POINTER_UNSET(SizePtrOffsetArray);
1060 TEST_POINTER_UNSET(SizePtrLengthArray);
1061 TEST_POINTER_UNSET(pArgQueue);
1062 TEST_ZERO(dwStubPhase, "%d");
1063 /* FIXME: where does this value come from? */
1064 trace("LowStackMark is %p\n", stubMsg.LowStackMark);
1065 TEST_ZERO(pAsyncMsg, "%p");
1066 TEST_ZERO(pCorrInfo, "%p");
1067 TEST_ZERO(pCorrMemory, "%p");
1068 TEST_ZERO(pMemoryList, "%p");
1069 TEST_POINTER_UNSET(pCSInfo);
1070 TEST_POINTER_UNSET(ConformanceMark);
1071 TEST_POINTER_UNSET(VarianceMark);
1072 ok(stubMsg.Unused == 0xcccccccc, "Unused should have be unset instead of 0x%lx\n", stubMsg.Unused);
1073 TEST_POINTER_UNSET(pContext);
1074 TEST_POINTER_UNSET(ContextHandleHash);
1075 TEST_POINTER_UNSET(pUserMarshalList);
1076 TEST_ULONG_PTR_UNSET(Reserved51_3);
1077 TEST_ULONG_PTR_UNSET(Reserved51_4);
1078 TEST_ULONG_PTR_UNSET(Reserved51_5);
1079 #undef TEST_ULONG_UNSET
1080 #undef TEST_POINTER_UNSET
1085 static void test_ndr_allocate(void)
1087 RPC_MESSAGE RpcMessage;
1088 MIDL_STUB_MESSAGE StubMsg;
1089 MIDL_STUB_DESC StubDesc;
1091 struct tag_mem_list_v1_t
1095 struct tag_mem_list_v1_t *next;
1097 struct tag_mem_list_v2_t
1102 struct tag_mem_list_v2_t *next;
1104 const DWORD magic_MEML = 'M' << 24 | 'E' << 16 | 'M' << 8 | 'L';
1106 StubDesc = Object_StubDesc;
1107 NdrClientInitializeNew(&RpcMessage, &StubMsg, &StubDesc, 0);
1109 ok(StubMsg.pMemoryList == NULL, "memlist %p\n", StubMsg.pMemoryList);
1110 my_alloc_called = my_free_called = 0;
1111 p1 = NdrAllocate(&StubMsg, 10);
1112 p2 = NdrAllocate(&StubMsg, 24);
1113 ok(my_alloc_called == 2, "alloc called %d\n", my_alloc_called);
1114 ok(StubMsg.pMemoryList != NULL, "StubMsg.pMemoryList NULL\n");
1115 if(StubMsg.pMemoryList)
1117 mem_list_v2 = StubMsg.pMemoryList;
1118 if (mem_list_v2->size == 24)
1120 trace("v2 mem list format\n");
1121 ok((char *)mem_list_v2 == (char *)p2 + 24, "expected mem_list_v2 pointer %p, but got %p\n", (char *)p2 + 24, mem_list_v2);
1122 ok(mem_list_v2->magic == magic_MEML, "magic %08x\n", mem_list_v2->magic);
1123 ok(mem_list_v2->size == 24, "wrong size for p2 %d\n", mem_list_v2->size);
1124 ok(mem_list_v2->unknown == 0, "wrong unknown for p2 0x%x\n", mem_list_v2->unknown);
1125 ok(mem_list_v2->next != NULL, "next NULL\n");
1126 mem_list_v2 = mem_list_v2->next;
1129 ok((char *)mem_list_v2 == (char *)p1 + 16, "expected mem_list_v2 pointer %p, but got %p\n", (char *)p1 + 16, mem_list_v2);
1130 ok(mem_list_v2->magic == magic_MEML, "magic %08x\n", mem_list_v2->magic);
1131 ok(mem_list_v2->size == 16, "wrong size for p1 %d\n", mem_list_v2->size);
1132 ok(mem_list_v2->unknown == 0, "wrong unknown for p1 0x%x\n", mem_list_v2->unknown);
1133 ok(mem_list_v2->next == NULL, "next %p\n", mem_list_v2->next);
1138 trace("v1 mem list format\n");
1139 mem_list_v1 = StubMsg.pMemoryList;
1140 ok(mem_list_v1->magic == magic_MEML, "magic %08x\n", mem_list_v1->magic);
1141 ok(mem_list_v1->ptr == p2, "ptr != p2\n");
1142 ok(mem_list_v1->next != NULL, "next NULL\n");
1143 mem_list_v1 = mem_list_v1->next;
1146 ok(mem_list_v1->magic == magic_MEML, "magic %08x\n", mem_list_v1->magic);
1147 ok(mem_list_v1->ptr == p1, "ptr != p1\n");
1148 ok(mem_list_v1->next == NULL, "next %p\n", mem_list_v1->next);
1152 /* NdrFree isn't exported so we can't test free'ing */
1155 static void test_conformant_array(void)
1157 RPC_MESSAGE RpcMessage;
1158 MIDL_STUB_MESSAGE StubMsg;
1159 MIDL_STUB_DESC StubDesc;
1161 unsigned char *mem, *mem_orig;
1162 unsigned char memsrc[20];
1164 static const unsigned char fmtstr_conf_array[] =
1166 0x1b, /* FC_CARRAY */
1168 NdrFcShort( 0x1 ), /* elem size */
1169 0x40, /* Corr desc: const */
1171 NdrFcShort(0x10), /* const = 0x10 */
1176 StubDesc = Object_StubDesc;
1177 StubDesc.pFormatTypes = fmtstr_conf_array;
1179 NdrClientInitializeNew(
1185 StubMsg.BufferLength = 0;
1186 NdrConformantArrayBufferSize( &StubMsg,
1188 fmtstr_conf_array );
1189 ok(StubMsg.BufferLength >= 20, "length %d\n", StubMsg.BufferLength);
1191 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1192 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
1193 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
1195 ptr = NdrConformantArrayMarshall( &StubMsg, memsrc, fmtstr_conf_array );
1196 ok(ptr == NULL, "ret %p\n", ptr);
1197 ok(StubMsg.Buffer - StubMsg.BufferStart == 20, "Buffer %p Start %p len %d\n", StubMsg.Buffer, StubMsg.BufferStart, 20);
1198 ok(!memcmp(StubMsg.BufferStart + 4, memsrc, 16), "incorrectly marshaled\n");
1200 StubMsg.Buffer = StubMsg.BufferStart;
1201 StubMsg.MemorySize = 0;
1205 my_alloc_called = 0;
1206 /* passing mem == NULL with must_alloc == 0 crashes under Windows */
1207 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1208 ok(mem != NULL, "mem not alloced\n");
1209 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1210 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1212 my_alloc_called = 0;
1213 StubMsg.Buffer = StubMsg.BufferStart;
1215 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 0);
1216 ok(mem == mem_orig, "mem alloced\n");
1217 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1218 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1220 my_alloc_called = 0;
1221 StubMsg.Buffer = StubMsg.BufferStart;
1222 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1223 ok(mem != mem_orig, "mem not alloced\n");
1224 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1225 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1228 StubMsg.Buffer = StubMsg.BufferStart;
1229 NdrConformantArrayFree( &StubMsg, mem, fmtstr_conf_array );
1230 ok(my_free_called == 0, "free called %d\n", my_free_called);
1231 StubMsg.pfnFree(mem);
1234 my_alloc_called = 0;
1235 StubMsg.IsClient = 0;
1237 StubMsg.Buffer = StubMsg.BufferStart;
1238 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 0);
1239 ok(mem == StubMsg.BufferStart + 4, "mem not pointing at buffer\n");
1240 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1241 my_alloc_called = 0;
1243 StubMsg.Buffer = StubMsg.BufferStart;
1244 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1245 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1246 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1247 StubMsg.pfnFree(mem);
1249 my_alloc_called = 0;
1251 StubMsg.Buffer = StubMsg.BufferStart;
1252 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 0);
1253 ok(mem == mem_orig, "mem alloced\n");
1254 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1256 my_alloc_called = 0;
1258 StubMsg.Buffer = StubMsg.BufferStart;
1259 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1260 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1261 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1262 StubMsg.pfnFree(mem);
1263 StubMsg.pfnFree(mem_orig);
1265 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
1268 static void test_conformant_string(void)
1270 RPC_MESSAGE RpcMessage;
1271 MIDL_STUB_MESSAGE StubMsg;
1272 MIDL_STUB_DESC StubDesc;
1274 unsigned char *mem, *mem_orig;
1275 char memsrc[] = "This is a test string";
1277 static const unsigned char fmtstr_conf_str[] =
1279 0x11, 0x8, /* FC_RP [simple_pointer] */
1280 0x22, /* FC_C_CSTRING */
1284 StubDesc = Object_StubDesc;
1285 StubDesc.pFormatTypes = fmtstr_conf_str;
1287 NdrClientInitializeNew(
1293 StubMsg.BufferLength = 0;
1294 NdrPointerBufferSize( &StubMsg,
1295 (unsigned char *)memsrc,
1297 ok(StubMsg.BufferLength >= sizeof(memsrc) + 12, "length %d\n", StubMsg.BufferLength);
1299 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1300 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
1301 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
1303 ptr = NdrPointerMarshall( &StubMsg, (unsigned char *)memsrc, fmtstr_conf_str );
1304 ok(ptr == NULL, "ret %p\n", ptr);
1305 ok(StubMsg.Buffer - StubMsg.BufferStart == sizeof(memsrc) + 12, "Buffer %p Start %p len %d\n",
1306 StubMsg.Buffer, StubMsg.BufferStart, StubMsg.Buffer - StubMsg.BufferStart);
1307 ok(!memcmp(StubMsg.BufferStart + 12, memsrc, sizeof(memsrc)), "incorrectly marshaled\n");
1309 StubMsg.Buffer = StubMsg.BufferStart;
1310 StubMsg.MemorySize = 0;
1314 my_alloc_called = 0;
1315 StubMsg.Buffer = StubMsg.BufferStart;
1316 mem = mem_orig = HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc));
1317 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 0);
1318 ok(mem == mem_orig, "mem not alloced\n");
1319 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1321 my_alloc_called = 0;
1322 StubMsg.Buffer = StubMsg.BufferStart;
1323 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 1);
1325 ok(mem == mem_orig, "mem not alloced\n");
1326 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1330 StubMsg.Buffer = StubMsg.BufferStart;
1331 NdrPointerFree( &StubMsg, mem, fmtstr_conf_str );
1332 ok(my_free_called == 1, "free called %d\n", my_free_called);
1336 StubMsg.Buffer = StubMsg.BufferStart;
1337 NdrPointerFree( &StubMsg, mem, fmtstr_conf_str );
1338 ok(my_free_called == 1, "free called %d\n", my_free_called);
1341 my_alloc_called = 0;
1342 StubMsg.IsClient = 0;
1344 StubMsg.Buffer = StubMsg.BufferStart;
1345 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 0);
1346 ok(mem == StubMsg.BufferStart + 12, "mem not pointing at buffer\n");
1347 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1349 my_alloc_called = 0;
1351 StubMsg.Buffer = StubMsg.BufferStart;
1352 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 1);
1354 ok(mem == StubMsg.BufferStart + 12, "mem not pointing at buffer\n");
1355 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1358 my_alloc_called = 0;
1360 StubMsg.Buffer = StubMsg.BufferStart;
1361 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 0);
1362 ok(mem == StubMsg.BufferStart + 12, "mem not pointing at buffer\n");
1363 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1365 my_alloc_called = 0;
1367 StubMsg.Buffer = StubMsg.BufferStart;
1368 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 1);
1370 ok(mem == StubMsg.BufferStart + 12, "mem not pointing at buffer\n");
1371 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1376 StubMsg.Buffer = StubMsg.BufferStart;
1377 NdrPointerFree( &StubMsg, mem, fmtstr_conf_str );
1378 ok(my_free_called == 1, "free called %d\n", my_free_called);
1380 HeapFree(GetProcessHeap(), 0, mem_orig);
1381 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
1384 static void test_nonconformant_string(void)
1386 RPC_MESSAGE RpcMessage;
1387 MIDL_STUB_MESSAGE StubMsg;
1388 MIDL_STUB_DESC StubDesc;
1390 unsigned char *mem, *mem_orig;
1391 unsigned char memsrc[10] = "This is";
1392 unsigned char memsrc2[10] = "This is a";
1394 static const unsigned char fmtstr_nonconf_str[] =
1396 0x26, /* FC_CSTRING */
1398 NdrFcShort( 0xa ), /* 10 */
1401 StubDesc = Object_StubDesc;
1402 StubDesc.pFormatTypes = fmtstr_nonconf_str;
1405 NdrClientInitializeNew(
1411 StubMsg.BufferLength = 0;
1413 NdrNonConformantStringBufferSize( &StubMsg,
1414 (unsigned char *)memsrc,
1415 fmtstr_nonconf_str );
1416 ok(StubMsg.BufferLength >= strlen((char *)memsrc) + 1 + 8, "length %d\n", StubMsg.BufferLength);
1418 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1419 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
1420 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
1422 ptr = NdrNonConformantStringMarshall( &StubMsg, (unsigned char *)memsrc, fmtstr_nonconf_str );
1423 ok(ptr == NULL, "ret %p\n", ptr);
1424 ok(StubMsg.Buffer - StubMsg.BufferStart == strlen((char *)memsrc) + 1 + 8, "Buffer %p Start %p len %d\n",
1425 StubMsg.Buffer, StubMsg.BufferStart, StubMsg.Buffer - StubMsg.BufferStart);
1426 ok(!memcmp(StubMsg.BufferStart + 8, memsrc, strlen((char *)memsrc) + 1), "incorrectly marshaled\n");
1428 StubMsg.Buffer = StubMsg.BufferStart;
1429 StubMsg.MemorySize = 0;
1433 my_alloc_called = 0;
1434 StubMsg.Buffer = StubMsg.BufferStart;
1435 mem = mem_orig = HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc));
1436 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1437 ok(mem == mem_orig, "mem alloced\n");
1438 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1440 my_alloc_called = 0;
1441 StubMsg.Buffer = StubMsg.BufferStart;
1442 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 1);
1444 ok(mem == mem_orig, "mem alloced\n");
1446 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1449 my_alloc_called = 0;
1450 StubMsg.IsClient = 0;
1452 StubMsg.Buffer = StubMsg.BufferStart;
1453 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1454 ok(mem != mem_orig, "mem not alloced\n");
1455 ok(mem != StubMsg.BufferStart + 8, "mem pointing at buffer\n");
1456 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1459 my_alloc_called = 0;
1461 StubMsg.Buffer = StubMsg.BufferStart;
1462 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1463 ok(mem == mem_orig, "mem alloced\n");
1464 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1466 my_alloc_called = 0;
1468 StubMsg.Buffer = StubMsg.BufferStart;
1469 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 1);
1471 ok(mem == mem_orig, "mem alloced\n");
1473 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1475 HeapFree(GetProcessHeap(), 0, mem_orig);
1476 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
1479 NdrClientInitializeNew(
1485 StubMsg.BufferLength = 0;
1487 NdrNonConformantStringBufferSize( &StubMsg,
1488 (unsigned char *)memsrc2,
1489 fmtstr_nonconf_str );
1490 ok(StubMsg.BufferLength >= strlen((char *)memsrc2) + 1 + 8, "length %d\n", StubMsg.BufferLength);
1492 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1493 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
1494 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
1496 ptr = NdrNonConformantStringMarshall( &StubMsg, (unsigned char *)memsrc2, fmtstr_nonconf_str );
1497 ok(ptr == NULL, "ret %p\n", ptr);
1498 ok(StubMsg.Buffer - StubMsg.BufferStart == strlen((char *)memsrc2) + 1 + 8, "Buffer %p Start %p len %d\n",
1499 StubMsg.Buffer, StubMsg.BufferStart, StubMsg.Buffer - StubMsg.BufferStart);
1500 ok(!memcmp(StubMsg.BufferStart + 8, memsrc2, strlen((char *)memsrc2) + 1), "incorrectly marshaled\n");
1502 StubMsg.Buffer = StubMsg.BufferStart;
1503 StubMsg.MemorySize = 0;
1507 my_alloc_called = 0;
1508 StubMsg.Buffer = StubMsg.BufferStart;
1509 mem = mem_orig = HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc));
1510 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1511 ok(mem == mem_orig, "mem alloced\n");
1512 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1514 my_alloc_called = 0;
1515 StubMsg.Buffer = StubMsg.BufferStart;
1516 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 1);
1518 ok(mem == mem_orig, "mem alloced\n");
1520 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1523 my_alloc_called = 0;
1524 StubMsg.IsClient = 0;
1526 StubMsg.Buffer = StubMsg.BufferStart;
1527 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1528 ok(mem != mem_orig, "mem not alloced\n");
1529 ok(mem != StubMsg.BufferStart + 8, "mem pointing at buffer\n");
1530 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1533 my_alloc_called = 0;
1535 StubMsg.Buffer = StubMsg.BufferStart;
1536 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1537 ok(mem == mem_orig, "mem alloced\n");
1538 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1540 my_alloc_called = 0;
1542 StubMsg.Buffer = StubMsg.BufferStart;
1543 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 1);
1545 ok(mem == mem_orig, "mem alloced\n");
1547 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1549 HeapFree(GetProcessHeap(), 0, mem_orig);
1550 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
1553 static void test_ndr_buffer(void)
1555 static unsigned char ncalrpc[] = "ncalrpc";
1556 static unsigned char endpoint[] = "winetest:" __FILE__;
1557 RPC_MESSAGE RpcMessage;
1558 MIDL_STUB_MESSAGE StubMsg;
1559 MIDL_STUB_DESC StubDesc = Object_StubDesc;
1561 unsigned char *binding;
1562 RPC_BINDING_HANDLE Handle;
1565 StubDesc.RpcInterfaceInformation = (void *)&IFoo___RpcServerInterface;
1567 ok(RPC_S_OK == RpcServerUseProtseqEp(ncalrpc, 20, endpoint, NULL), "RpcServerUseProtseqEp\n");
1568 ok(RPC_S_OK == RpcServerRegisterIf(IFoo_v0_0_s_ifspec, NULL, NULL), "RpcServerRegisterIf\n");
1569 ok(RPC_S_OK == RpcServerListen(1, 20, TRUE), "RpcServerListen\n");
1571 status = RpcStringBindingCompose(NULL, ncalrpc, NULL, endpoint, NULL, &binding);
1572 ok(status == RPC_S_OK, "RpcStringBindingCompose failed (%lu)\n", status);
1574 status = RpcBindingFromStringBinding(binding, &Handle);
1575 ok(status == RPC_S_OK, "RpcBindingFromStringBinding failed (%lu)\n", status);
1577 NdrClientInitializeNew(&RpcMessage, &StubMsg, &StubDesc, 5);
1579 ret = NdrGetBuffer(&StubMsg, 10, Handle);
1580 ok(ret == StubMsg.Buffer, "NdrGetBuffer should have returned the same value as StubMsg.Buffer instead of %p\n", ret);
1581 ok(RpcMessage.Handle != NULL, "RpcMessage.Handle should not have been NULL\n");
1582 ok(RpcMessage.Buffer != NULL, "RpcMessage.Buffer should not have been NULL\n");
1583 ok(RpcMessage.BufferLength == 10, "RpcMessage.BufferLength should have been 10 instead of %d\n", RpcMessage.BufferLength);
1584 ok(RpcMessage.RpcFlags == 0, "RpcMessage.RpcFlags should have been 0x0 instead of 0x%lx\n", RpcMessage.RpcFlags);
1585 ok(StubMsg.Buffer != NULL, "Buffer should not have been NULL\n");
1586 ok(!StubMsg.BufferStart, "BufferStart should have been NULL instead of %p\n", StubMsg.BufferStart);
1587 ok(!StubMsg.BufferEnd, "BufferEnd should have been NULL instead of %p\n", StubMsg.BufferEnd);
1589 ok(StubMsg.BufferLength == 0, "BufferLength should have left as 0 instead of being set to %d\n", StubMsg.BufferLength);
1590 ok(StubMsg.fBufferValid == TRUE, "fBufferValid should have been TRUE instead of 0x%x\n", StubMsg.fBufferValid);
1592 StubMsg.BufferLength = 1;
1593 NdrFreeBuffer(&StubMsg);
1594 ok(RpcMessage.Handle != NULL, "RpcMessage.Handle should not have been NULL\n");
1595 ok(RpcMessage.Buffer != NULL, "RpcMessage.Buffer should not have been NULL\n");
1596 ok(RpcMessage.BufferLength == 10, "RpcMessage.BufferLength should have been left as 10 instead of %d\n", RpcMessage.BufferLength);
1597 ok(StubMsg.Buffer != NULL, "Buffer should not have been NULL\n");
1598 ok(StubMsg.BufferLength == 1, "BufferLength should have left as 1 instead of being set to %d\n", StubMsg.BufferLength);
1599 ok(StubMsg.fBufferValid == FALSE, "fBufferValid should have been FALSE instead of 0x%x\n", StubMsg.fBufferValid);
1601 /* attempt double-free */
1602 NdrFreeBuffer(&StubMsg);
1604 status = RpcServerUnregisterIf(NULL, NULL, FALSE);
1605 ok(status == RPC_S_OK, "RpcServerUnregisterIf failed (%lu)\n", status);
1608 static void test_NdrMapCommAndFaultStatus(void)
1610 RPC_STATUS rpc_status;
1611 MIDL_STUB_MESSAGE StubMsg;
1612 RPC_MESSAGE RpcMessage;
1614 NdrClientInitializeNew(&RpcMessage, &StubMsg, &Object_StubDesc, 5);
1616 for (rpc_status = 0; rpc_status < 10000; rpc_status++)
1619 ULONG comm_status = 0;
1620 ULONG fault_status = 0;
1621 ULONG expected_comm_status = 0;
1622 ULONG expected_fault_status = 0;
1623 status = NdrMapCommAndFaultStatus(&StubMsg, &comm_status, &fault_status, rpc_status);
1624 ok(status == RPC_S_OK, "NdrMapCommAndFaultStatus failed with error %ld\n", status);
1627 case ERROR_INVALID_HANDLE:
1628 case RPC_S_INVALID_BINDING:
1629 case RPC_S_UNKNOWN_IF:
1630 case RPC_S_SERVER_UNAVAILABLE:
1631 case RPC_S_SERVER_TOO_BUSY:
1632 case RPC_S_CALL_FAILED_DNE:
1633 case RPC_S_PROTOCOL_ERROR:
1634 case RPC_S_UNSUPPORTED_TRANS_SYN:
1635 case RPC_S_UNSUPPORTED_TYPE:
1636 case RPC_S_PROCNUM_OUT_OF_RANGE:
1637 case EPT_S_NOT_REGISTERED:
1638 case RPC_S_COMM_FAILURE:
1639 expected_comm_status = rpc_status;
1642 expected_fault_status = rpc_status;
1644 ok(comm_status == expected_comm_status, "NdrMapCommAndFaultStatus should have mapped %ld to comm status %d instead of %d\n",
1645 rpc_status, expected_comm_status, comm_status);
1646 ok(fault_status == expected_fault_status, "NdrMapCommAndFaultStatus should have mapped %ld to fault status %d instead of %d\n",
1647 rpc_status, expected_fault_status, fault_status);
1651 START_TEST( ndr_marshall )
1653 test_ndr_simple_type();
1654 test_simple_types();
1655 test_simple_struct();
1656 test_fullpointer_xlat();
1659 test_ndr_allocate();
1660 test_conformant_array();
1661 test_conformant_string();
1662 test_nonconformant_string();
1664 test_NdrMapCommAndFaultStatus();