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, 0, sizeof(rpcMsg));
895 memset(&stubMsg, 0xcc, sizeof(stubMsg));
897 NdrClientInitializeNew(&rpcMsg, &stubMsg, &Object_StubDesc, 1);
899 #define TEST_ZERO(field, fmt) ok(stubMsg.field == 0, #field " should have been set to zero instead of " fmt "\n", stubMsg.field)
900 #define TEST_POINTER_UNSET(field) ok(stubMsg.field == (void *)0xcccccccc, #field " should have been unset instead of %p\n", stubMsg.field)
901 #define TEST_ULONG_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%x\n", stubMsg.field)
902 #define TEST_ULONG_PTR_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%lx\n", stubMsg.field)
904 ok(stubMsg.RpcMsg == &rpcMsg, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg, stubMsg.RpcMsg);
905 TEST_POINTER_UNSET(Buffer);
906 TEST_ZERO(BufferStart, "%p");
907 TEST_ZERO(BufferEnd, "%p");
908 TEST_POINTER_UNSET(BufferMark);
909 TEST_ZERO(BufferLength, "%d");
910 TEST_ULONG_UNSET(MemorySize);
911 TEST_POINTER_UNSET(Memory);
912 ok(stubMsg.IsClient == 1, "stubMsg.IsClient should have been 1 instead of %u\n", stubMsg.IsClient);
913 TEST_ZERO(ReuseBuffer, "%d");
914 TEST_ZERO(pAllocAllNodesContext, "%p");
915 TEST_ZERO(pPointerQueueState, "%p");
916 TEST_ZERO(IgnoreEmbeddedPointers, "%d");
917 TEST_ZERO(PointerBufferMark, "%p");
918 TEST_ZERO(fBufferValid, "%d");
919 TEST_ZERO(uFlags, "%d");
920 /* FIXME: UniquePtrCount */
921 TEST_ULONG_PTR_UNSET(MaxCount);
922 TEST_ULONG_UNSET(Offset);
923 TEST_ULONG_UNSET(ActualCount);
924 ok(stubMsg.pfnAllocate == my_alloc, "stubMsg.pfnAllocate should have been %p instead of %p\n", my_alloc, stubMsg.pfnAllocate);
925 ok(stubMsg.pfnFree == my_free, "stubMsg.pfnFree should have been %p instead of %p\n", my_free, stubMsg.pfnFree);
926 TEST_ZERO(StackTop, "%p");
927 TEST_POINTER_UNSET(pPresentedType);
928 TEST_POINTER_UNSET(pTransmitType);
929 TEST_POINTER_UNSET(SavedHandle);
930 ok(stubMsg.StubDesc == &Object_StubDesc, "stubMsg.StubDesc should have been %p instead of %p\n", &Object_StubDesc, stubMsg.StubDesc);
931 TEST_POINTER_UNSET(FullPtrXlatTables);
932 TEST_ZERO(FullPtrRefId, "%d");
933 TEST_ZERO(PointerLength, "%d");
934 TEST_ZERO(fInDontFree, "%d");
935 TEST_ZERO(fDontCallFreeInst, "%d");
936 TEST_ZERO(fInOnlyParam, "%d");
937 TEST_ZERO(fHasReturn, "%d");
938 TEST_ZERO(fHasExtensions, "%d");
939 TEST_ZERO(fHasNewCorrDesc, "%d");
940 TEST_ZERO(fUnused, "%d");
941 ok(stubMsg.fUnused2 == 0xffffcccc, "stubMsg.fUnused2 should have been 0xcccc instead of 0x%x\n", stubMsg.fUnused2);
942 ok(stubMsg.dwDestContext == MSHCTX_DIFFERENTMACHINE, "stubMsg.dwDestContext should have been MSHCTX_DIFFERENTMACHINE instead of %d\n", stubMsg.dwDestContext);
943 TEST_ZERO(pvDestContext, "%p");
944 TEST_POINTER_UNSET(SavedContextHandles);
945 TEST_ULONG_UNSET(ParamNumber);
946 TEST_ZERO(pRpcChannelBuffer, "%p");
947 TEST_ZERO(pArrayInfo, "%p");
948 TEST_POINTER_UNSET(SizePtrCountArray);
949 TEST_POINTER_UNSET(SizePtrOffsetArray);
950 TEST_POINTER_UNSET(SizePtrLengthArray);
951 TEST_POINTER_UNSET(pArgQueue);
952 TEST_ZERO(dwStubPhase, "%d");
953 /* FIXME: where does this value come from? */
954 trace("LowStackMark is %p\n", stubMsg.LowStackMark);
955 TEST_ZERO(pAsyncMsg, "%p");
956 TEST_ZERO(pCorrInfo, "%p");
957 TEST_ZERO(pCorrMemory, "%p");
958 TEST_ZERO(pMemoryList, "%p");
959 TEST_POINTER_UNSET(pCSInfo);
960 TEST_POINTER_UNSET(ConformanceMark);
961 TEST_POINTER_UNSET(VarianceMark);
962 ok(stubMsg.Unused == 0xcccccccc, "Unused should have be unset instead of 0x%lx\n", stubMsg.Unused);
963 TEST_POINTER_UNSET(pContext);
964 TEST_POINTER_UNSET(ContextHandleHash);
965 TEST_POINTER_UNSET(pUserMarshalList);
966 TEST_ULONG_PTR_UNSET(Reserved51_3);
967 TEST_ULONG_PTR_UNSET(Reserved51_4);
968 TEST_ULONG_PTR_UNSET(Reserved51_5);
969 #undef TEST_ULONG_UNSET
970 #undef TEST_POINTER_UNSET
975 static void test_server_init(void)
977 MIDL_STUB_MESSAGE stubMsg;
980 unsigned char buffer[256];
982 memset(&rpcMsg, 0, sizeof(rpcMsg));
983 rpcMsg.Buffer = buffer;
984 rpcMsg.BufferLength = sizeof(buffer);
985 rpcMsg.RpcFlags = RPC_BUFFER_COMPLETE;
987 memset(&stubMsg, 0xcc, sizeof(stubMsg));
989 ret = NdrServerInitializeNew(&rpcMsg, &stubMsg, &Object_StubDesc);
990 ok(ret == NULL, "NdrServerInitializeNew should have returned NULL instead of %p\n", ret);
992 #define TEST_ZERO(field, fmt) ok(stubMsg.field == 0, #field " should have been set to zero instead of " fmt "\n", stubMsg.field)
993 #define TEST_POINTER_UNSET(field) ok(stubMsg.field == (void *)0xcccccccc, #field " should have been unset instead of %p\n", stubMsg.field)
994 #define TEST_ULONG_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%x\n", stubMsg.field)
995 #define TEST_ULONG_PTR_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%lx\n", stubMsg.field)
997 ok(stubMsg.RpcMsg == &rpcMsg, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg, stubMsg.RpcMsg);
998 ok(stubMsg.Buffer == buffer, "stubMsg.Buffer should have been %p instead of %p\n", buffer, stubMsg.Buffer);
999 ok(stubMsg.BufferStart == buffer, "stubMsg.BufferStart should have been %p instead of %p\n", buffer, stubMsg.BufferStart);
1000 ok(stubMsg.BufferEnd == buffer + sizeof(buffer), "stubMsg.BufferEnd should have been %p instead of %p\n", buffer + sizeof(buffer), stubMsg.BufferEnd);
1001 TEST_POINTER_UNSET(BufferMark);
1003 TEST_ZERO(BufferLength, "%d");
1004 TEST_ULONG_UNSET(MemorySize);
1005 TEST_POINTER_UNSET(Memory);
1006 ok(stubMsg.IsClient == 0, "stubMsg.IsClient should have been 0 instead of %u\n", stubMsg.IsClient);
1007 TEST_ZERO(ReuseBuffer, "%d");
1008 TEST_ZERO(pAllocAllNodesContext, "%p");
1009 TEST_ZERO(pPointerQueueState, "%p");
1010 TEST_ZERO(IgnoreEmbeddedPointers, "%d");
1011 TEST_ZERO(PointerBufferMark, "%p");
1012 ok(stubMsg.fBufferValid == 0xcc, "fBufferValid should have been unset instead of 0x%x\n", stubMsg.fBufferValid);
1013 TEST_ZERO(uFlags, "%d");
1014 /* FIXME: UniquePtrCount */
1015 TEST_ULONG_PTR_UNSET(MaxCount);
1016 TEST_ULONG_UNSET(Offset);
1017 TEST_ULONG_UNSET(ActualCount);
1018 ok(stubMsg.pfnAllocate == my_alloc, "stubMsg.pfnAllocate should have been %p instead of %p\n", my_alloc, stubMsg.pfnAllocate);
1019 ok(stubMsg.pfnFree == my_free, "stubMsg.pfnFree should have been %p instead of %p\n", my_free, stubMsg.pfnFree);
1020 TEST_ZERO(StackTop, "%p");
1021 TEST_POINTER_UNSET(pPresentedType);
1022 TEST_POINTER_UNSET(pTransmitType);
1023 TEST_POINTER_UNSET(SavedHandle);
1024 ok(stubMsg.StubDesc == &Object_StubDesc, "stubMsg.StubDesc should have been %p instead of %p\n", &Object_StubDesc, stubMsg.StubDesc);
1025 TEST_ZERO(FullPtrXlatTables, "%p");
1026 TEST_ZERO(FullPtrRefId, "%d");
1027 TEST_ZERO(PointerLength, "%d");
1028 TEST_ZERO(fInDontFree, "%d");
1029 TEST_ZERO(fDontCallFreeInst, "%d");
1030 TEST_ZERO(fInOnlyParam, "%d");
1031 TEST_ZERO(fHasReturn, "%d");
1032 TEST_ZERO(fHasExtensions, "%d");
1033 TEST_ZERO(fHasNewCorrDesc, "%d");
1034 TEST_ZERO(fUnused, "%d");
1035 ok(stubMsg.fUnused2 == 0xffffcccc, "stubMsg.fUnused2 should have been 0xcccc instead of 0x%x\n", stubMsg.fUnused2);
1036 ok(stubMsg.dwDestContext == MSHCTX_DIFFERENTMACHINE, "stubMsg.dwDestContext should have been MSHCTX_DIFFERENTMACHINE instead of %d\n", stubMsg.dwDestContext);
1037 TEST_ZERO(pvDestContext, "%p");
1038 TEST_POINTER_UNSET(SavedContextHandles);
1039 TEST_ULONG_UNSET(ParamNumber);
1040 TEST_ZERO(pRpcChannelBuffer, "%p");
1041 TEST_ZERO(pArrayInfo, "%p");
1042 TEST_POINTER_UNSET(SizePtrCountArray);
1043 TEST_POINTER_UNSET(SizePtrOffsetArray);
1044 TEST_POINTER_UNSET(SizePtrLengthArray);
1045 TEST_POINTER_UNSET(pArgQueue);
1046 TEST_ZERO(dwStubPhase, "%d");
1047 /* FIXME: where does this value come from? */
1048 trace("LowStackMark is %p\n", stubMsg.LowStackMark);
1049 TEST_ZERO(pAsyncMsg, "%p");
1050 TEST_ZERO(pCorrInfo, "%p");
1051 TEST_ZERO(pCorrMemory, "%p");
1052 TEST_ZERO(pMemoryList, "%p");
1053 TEST_POINTER_UNSET(pCSInfo);
1054 TEST_POINTER_UNSET(ConformanceMark);
1055 TEST_POINTER_UNSET(VarianceMark);
1056 ok(stubMsg.Unused == 0xcccccccc, "Unused should have be unset instead of 0x%lx\n", stubMsg.Unused);
1057 TEST_POINTER_UNSET(pContext);
1058 TEST_POINTER_UNSET(ContextHandleHash);
1059 TEST_POINTER_UNSET(pUserMarshalList);
1060 TEST_ULONG_PTR_UNSET(Reserved51_3);
1061 TEST_ULONG_PTR_UNSET(Reserved51_4);
1062 TEST_ULONG_PTR_UNSET(Reserved51_5);
1063 #undef TEST_ULONG_UNSET
1064 #undef TEST_POINTER_UNSET
1069 static void test_ndr_allocate(void)
1071 RPC_MESSAGE RpcMessage;
1072 MIDL_STUB_MESSAGE StubMsg;
1073 MIDL_STUB_DESC StubDesc;
1075 struct tag_mem_list_v1_t
1079 struct tag_mem_list_v1_t *next;
1081 struct tag_mem_list_v2_t
1086 struct tag_mem_list_v2_t *next;
1088 const DWORD magic_MEML = 'M' << 24 | 'E' << 16 | 'M' << 8 | 'L';
1090 StubDesc = Object_StubDesc;
1091 NdrClientInitializeNew(&RpcMessage, &StubMsg, &StubDesc, 0);
1093 ok(StubMsg.pMemoryList == NULL, "memlist %p\n", StubMsg.pMemoryList);
1094 my_alloc_called = my_free_called = 0;
1095 p1 = NdrAllocate(&StubMsg, 10);
1096 p2 = NdrAllocate(&StubMsg, 24);
1097 ok(my_alloc_called == 2, "alloc called %d\n", my_alloc_called);
1098 ok(StubMsg.pMemoryList != NULL, "StubMsg.pMemoryList NULL\n");
1099 if(StubMsg.pMemoryList)
1101 mem_list_v2 = StubMsg.pMemoryList;
1102 if (mem_list_v2->size == 24)
1104 trace("v2 mem list format\n");
1105 ok((char *)mem_list_v2 == (char *)p2 + 24, "expected mem_list_v2 pointer %p, but got %p\n", (char *)p2 + 24, mem_list_v2);
1106 ok(mem_list_v2->magic == magic_MEML, "magic %08x\n", mem_list_v2->magic);
1107 ok(mem_list_v2->size == 24, "wrong size for p2 %d\n", mem_list_v2->size);
1108 ok(mem_list_v2->unknown == 0, "wrong unknown for p2 0x%x\n", mem_list_v2->unknown);
1109 ok(mem_list_v2->next != NULL, "next NULL\n");
1110 mem_list_v2 = mem_list_v2->next;
1113 ok((char *)mem_list_v2 == (char *)p1 + 16, "expected mem_list_v2 pointer %p, but got %p\n", (char *)p1 + 16, mem_list_v2);
1114 ok(mem_list_v2->magic == magic_MEML, "magic %08x\n", mem_list_v2->magic);
1115 ok(mem_list_v2->size == 16, "wrong size for p1 %d\n", mem_list_v2->size);
1116 ok(mem_list_v2->unknown == 0, "wrong unknown for p1 0x%x\n", mem_list_v2->unknown);
1117 ok(mem_list_v2->next == NULL, "next %p\n", mem_list_v2->next);
1122 trace("v1 mem list format\n");
1123 mem_list_v1 = StubMsg.pMemoryList;
1124 ok(mem_list_v1->magic == magic_MEML, "magic %08x\n", mem_list_v1->magic);
1125 ok(mem_list_v1->ptr == p2, "ptr != p2\n");
1126 ok(mem_list_v1->next != NULL, "next NULL\n");
1127 mem_list_v1 = mem_list_v1->next;
1130 ok(mem_list_v1->magic == magic_MEML, "magic %08x\n", mem_list_v1->magic);
1131 ok(mem_list_v1->ptr == p1, "ptr != p1\n");
1132 ok(mem_list_v1->next == NULL, "next %p\n", mem_list_v1->next);
1136 /* NdrFree isn't exported so we can't test free'ing */
1139 static void test_conformant_array(void)
1141 RPC_MESSAGE RpcMessage;
1142 MIDL_STUB_MESSAGE StubMsg;
1143 MIDL_STUB_DESC StubDesc;
1145 unsigned char *mem, *mem_orig;
1146 unsigned char memsrc[20];
1148 static const unsigned char fmtstr_conf_array[] =
1150 0x1b, /* FC_CARRAY */
1152 NdrFcShort( 0x1 ), /* elem size */
1153 0x40, /* Corr desc: const */
1155 NdrFcShort(0x10), /* const = 0x10 */
1160 StubDesc = Object_StubDesc;
1161 StubDesc.pFormatTypes = fmtstr_conf_array;
1163 NdrClientInitializeNew(
1169 StubMsg.BufferLength = 0;
1170 NdrConformantArrayBufferSize( &StubMsg,
1172 fmtstr_conf_array );
1173 ok(StubMsg.BufferLength >= 20, "length %d\n", StubMsg.BufferLength);
1175 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1176 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
1177 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
1179 ptr = NdrConformantArrayMarshall( &StubMsg, memsrc, fmtstr_conf_array );
1180 ok(ptr == NULL, "ret %p\n", ptr);
1181 ok(StubMsg.Buffer - StubMsg.BufferStart == 20, "Buffer %p Start %p len %d\n", StubMsg.Buffer, StubMsg.BufferStart, 20);
1182 ok(!memcmp(StubMsg.BufferStart + 4, memsrc, 16), "incorrectly marshaled\n");
1184 StubMsg.Buffer = StubMsg.BufferStart;
1185 StubMsg.MemorySize = 0;
1189 my_alloc_called = 0;
1190 /* passing mem == NULL with must_alloc == 0 crashes under Windows */
1191 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1192 ok(mem != NULL, "mem not alloced\n");
1193 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1194 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1196 my_alloc_called = 0;
1197 StubMsg.Buffer = StubMsg.BufferStart;
1199 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 0);
1200 ok(mem == mem_orig, "mem alloced\n");
1201 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1202 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1204 my_alloc_called = 0;
1205 StubMsg.Buffer = StubMsg.BufferStart;
1206 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1207 ok(mem != mem_orig, "mem not alloced\n");
1208 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1209 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1212 StubMsg.Buffer = StubMsg.BufferStart;
1213 NdrConformantArrayFree( &StubMsg, mem, fmtstr_conf_array );
1214 ok(my_free_called == 0, "free called %d\n", my_free_called);
1215 StubMsg.pfnFree(mem);
1218 my_alloc_called = 0;
1219 StubMsg.IsClient = 0;
1221 StubMsg.Buffer = StubMsg.BufferStart;
1222 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 0);
1223 ok(mem == StubMsg.BufferStart + 4, "mem not pointing at buffer\n");
1224 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1225 my_alloc_called = 0;
1227 StubMsg.Buffer = StubMsg.BufferStart;
1228 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1229 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1230 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1231 StubMsg.pfnFree(mem);
1233 my_alloc_called = 0;
1235 StubMsg.Buffer = StubMsg.BufferStart;
1236 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 0);
1237 ok(mem == mem_orig, "mem alloced\n");
1238 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1240 my_alloc_called = 0;
1242 StubMsg.Buffer = StubMsg.BufferStart;
1243 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1244 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1245 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1246 StubMsg.pfnFree(mem);
1247 StubMsg.pfnFree(mem_orig);
1249 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
1252 static void test_conformant_string(void)
1254 RPC_MESSAGE RpcMessage;
1255 MIDL_STUB_MESSAGE StubMsg;
1256 MIDL_STUB_DESC StubDesc;
1258 unsigned char *mem, *mem_orig;
1259 char memsrc[] = "This is a test string";
1261 static const unsigned char fmtstr_conf_str[] =
1263 0x11, 0x8, /* FC_RP [simple_pointer] */
1264 0x22, /* FC_C_CSTRING */
1268 StubDesc = Object_StubDesc;
1269 StubDesc.pFormatTypes = fmtstr_conf_str;
1271 NdrClientInitializeNew(
1277 StubMsg.BufferLength = 0;
1278 NdrPointerBufferSize( &StubMsg,
1279 (unsigned char *)memsrc,
1281 ok(StubMsg.BufferLength >= sizeof(memsrc) + 12, "length %d\n", StubMsg.BufferLength);
1283 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1284 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
1285 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
1287 ptr = NdrPointerMarshall( &StubMsg, (unsigned char *)memsrc, fmtstr_conf_str );
1288 ok(ptr == NULL, "ret %p\n", ptr);
1289 ok(StubMsg.Buffer - StubMsg.BufferStart == sizeof(memsrc) + 12, "Buffer %p Start %p len %d\n",
1290 StubMsg.Buffer, StubMsg.BufferStart, StubMsg.Buffer - StubMsg.BufferStart);
1291 ok(!memcmp(StubMsg.BufferStart + 12, memsrc, sizeof(memsrc)), "incorrectly marshaled\n");
1293 StubMsg.Buffer = StubMsg.BufferStart;
1294 StubMsg.MemorySize = 0;
1298 my_alloc_called = 0;
1299 StubMsg.Buffer = StubMsg.BufferStart;
1300 mem = mem_orig = HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc));
1301 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 0);
1302 ok(mem == mem_orig, "mem not alloced\n");
1303 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1305 my_alloc_called = 0;
1306 StubMsg.Buffer = StubMsg.BufferStart;
1307 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 1);
1309 ok(mem == mem_orig, "mem not alloced\n");
1310 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1314 StubMsg.Buffer = StubMsg.BufferStart;
1315 NdrPointerFree( &StubMsg, mem, fmtstr_conf_str );
1316 ok(my_free_called == 1, "free called %d\n", my_free_called);
1320 StubMsg.Buffer = StubMsg.BufferStart;
1321 NdrPointerFree( &StubMsg, mem, fmtstr_conf_str );
1322 ok(my_free_called == 1, "free called %d\n", my_free_called);
1325 my_alloc_called = 0;
1326 StubMsg.IsClient = 0;
1328 StubMsg.Buffer = StubMsg.BufferStart;
1329 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 0);
1330 ok(mem == StubMsg.BufferStart + 12, "mem not pointing at buffer\n");
1331 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1333 my_alloc_called = 0;
1335 StubMsg.Buffer = StubMsg.BufferStart;
1336 NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 1);
1338 ok(mem == StubMsg.BufferStart + 12, "mem not pointing at buffer\n");
1339 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1342 my_alloc_called = 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);
1360 StubMsg.Buffer = StubMsg.BufferStart;
1361 NdrPointerFree( &StubMsg, mem, fmtstr_conf_str );
1362 ok(my_free_called == 1, "free called %d\n", my_free_called);
1364 HeapFree(GetProcessHeap(), 0, mem_orig);
1365 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
1368 static void test_nonconformant_string(void)
1370 RPC_MESSAGE RpcMessage;
1371 MIDL_STUB_MESSAGE StubMsg;
1372 MIDL_STUB_DESC StubDesc;
1374 unsigned char *mem, *mem_orig;
1375 unsigned char memsrc[10] = "This is";
1376 unsigned char memsrc2[10] = "This is a";
1378 static const unsigned char fmtstr_nonconf_str[] =
1380 0x26, /* FC_CSTRING */
1382 NdrFcShort( 0xa ), /* 10 */
1385 StubDesc = Object_StubDesc;
1386 StubDesc.pFormatTypes = fmtstr_nonconf_str;
1389 NdrClientInitializeNew(
1395 StubMsg.BufferLength = 0;
1397 NdrNonConformantStringBufferSize( &StubMsg,
1398 (unsigned char *)memsrc,
1399 fmtstr_nonconf_str );
1400 ok(StubMsg.BufferLength >= strlen((char *)memsrc) + 1 + 8, "length %d\n", StubMsg.BufferLength);
1402 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1403 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
1404 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
1406 ptr = NdrNonConformantStringMarshall( &StubMsg, (unsigned char *)memsrc, fmtstr_nonconf_str );
1407 ok(ptr == NULL, "ret %p\n", ptr);
1408 ok(StubMsg.Buffer - StubMsg.BufferStart == strlen((char *)memsrc) + 1 + 8, "Buffer %p Start %p len %d\n",
1409 StubMsg.Buffer, StubMsg.BufferStart, StubMsg.Buffer - StubMsg.BufferStart);
1410 ok(!memcmp(StubMsg.BufferStart + 8, memsrc, strlen((char *)memsrc) + 1), "incorrectly marshaled\n");
1412 StubMsg.Buffer = StubMsg.BufferStart;
1413 StubMsg.MemorySize = 0;
1417 my_alloc_called = 0;
1418 StubMsg.Buffer = StubMsg.BufferStart;
1419 mem = mem_orig = HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc));
1420 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1421 ok(mem == mem_orig, "mem alloced\n");
1422 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1424 my_alloc_called = 0;
1425 StubMsg.Buffer = StubMsg.BufferStart;
1426 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 1);
1428 ok(mem == mem_orig, "mem alloced\n");
1430 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1433 my_alloc_called = 0;
1434 StubMsg.IsClient = 0;
1436 StubMsg.Buffer = StubMsg.BufferStart;
1437 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1438 ok(mem != mem_orig, "mem not alloced\n");
1439 ok(mem != StubMsg.BufferStart + 8, "mem pointing at buffer\n");
1440 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1443 my_alloc_called = 0;
1445 StubMsg.Buffer = StubMsg.BufferStart;
1446 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1447 ok(mem == mem_orig, "mem alloced\n");
1448 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1450 my_alloc_called = 0;
1452 StubMsg.Buffer = StubMsg.BufferStart;
1453 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 1);
1455 ok(mem == mem_orig, "mem alloced\n");
1457 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1459 HeapFree(GetProcessHeap(), 0, mem_orig);
1460 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
1463 NdrClientInitializeNew(
1469 StubMsg.BufferLength = 0;
1471 NdrNonConformantStringBufferSize( &StubMsg,
1472 (unsigned char *)memsrc2,
1473 fmtstr_nonconf_str );
1474 ok(StubMsg.BufferLength >= strlen((char *)memsrc2) + 1 + 8, "length %d\n", StubMsg.BufferLength);
1476 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1477 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
1478 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
1480 ptr = NdrNonConformantStringMarshall( &StubMsg, (unsigned char *)memsrc2, fmtstr_nonconf_str );
1481 ok(ptr == NULL, "ret %p\n", ptr);
1482 ok(StubMsg.Buffer - StubMsg.BufferStart == strlen((char *)memsrc2) + 1 + 8, "Buffer %p Start %p len %d\n",
1483 StubMsg.Buffer, StubMsg.BufferStart, StubMsg.Buffer - StubMsg.BufferStart);
1484 ok(!memcmp(StubMsg.BufferStart + 8, memsrc2, strlen((char *)memsrc2) + 1), "incorrectly marshaled\n");
1486 StubMsg.Buffer = StubMsg.BufferStart;
1487 StubMsg.MemorySize = 0;
1491 my_alloc_called = 0;
1492 StubMsg.Buffer = StubMsg.BufferStart;
1493 mem = mem_orig = HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc));
1494 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1495 ok(mem == mem_orig, "mem alloced\n");
1496 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1498 my_alloc_called = 0;
1499 StubMsg.Buffer = StubMsg.BufferStart;
1500 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 1);
1502 ok(mem == mem_orig, "mem alloced\n");
1504 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1507 my_alloc_called = 0;
1508 StubMsg.IsClient = 0;
1510 StubMsg.Buffer = StubMsg.BufferStart;
1511 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1512 ok(mem != mem_orig, "mem not alloced\n");
1513 ok(mem != StubMsg.BufferStart + 8, "mem pointing at buffer\n");
1514 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1517 my_alloc_called = 0;
1519 StubMsg.Buffer = StubMsg.BufferStart;
1520 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 0);
1521 ok(mem == mem_orig, "mem alloced\n");
1522 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1524 my_alloc_called = 0;
1526 StubMsg.Buffer = StubMsg.BufferStart;
1527 NdrNonConformantStringUnmarshall( &StubMsg, &mem, fmtstr_nonconf_str, 1);
1529 ok(mem == mem_orig, "mem alloced\n");
1531 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1533 HeapFree(GetProcessHeap(), 0, mem_orig);
1534 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
1537 static void test_ndr_buffer(void)
1539 static unsigned char ncalrpc[] = "ncalrpc";
1540 static unsigned char endpoint[] = "winetest:" __FILE__;
1541 RPC_MESSAGE RpcMessage;
1542 MIDL_STUB_MESSAGE StubMsg;
1543 MIDL_STUB_DESC StubDesc = Object_StubDesc;
1545 unsigned char *binding;
1546 RPC_BINDING_HANDLE Handle;
1549 StubDesc.RpcInterfaceInformation = (void *)&IFoo___RpcServerInterface;
1551 ok(RPC_S_OK == RpcServerUseProtseqEp(ncalrpc, 20, endpoint, NULL), "RpcServerUseProtseqEp\n");
1552 ok(RPC_S_OK == RpcServerRegisterIf(IFoo_v0_0_s_ifspec, NULL, NULL), "RpcServerRegisterIf\n");
1553 ok(RPC_S_OK == RpcServerListen(1, 20, TRUE), "RpcServerListen\n");
1555 status = RpcStringBindingCompose(NULL, ncalrpc, NULL, endpoint, NULL, &binding);
1556 ok(status == RPC_S_OK, "RpcStringBindingCompose failed (%lu)\n", status);
1558 status = RpcBindingFromStringBinding(binding, &Handle);
1559 ok(status == RPC_S_OK, "RpcBindingFromStringBinding failed (%lu)\n", status);
1561 NdrClientInitializeNew(&RpcMessage, &StubMsg, &StubDesc, 5);
1563 ret = NdrGetBuffer(&StubMsg, 10, Handle);
1564 ok(ret == StubMsg.Buffer, "NdrGetBuffer should have returned the same value as StubMsg.Buffer instead of %p\n", ret);
1565 ok(RpcMessage.Handle != NULL, "RpcMessage.Handle should not have been NULL\n");
1566 ok(RpcMessage.Buffer != NULL, "RpcMessage.Buffer should not have been NULL\n");
1567 ok(RpcMessage.BufferLength == 10, "RpcMessage.BufferLength should have been 10 instead of %d\n", RpcMessage.BufferLength);
1568 ok(RpcMessage.RpcFlags == 0, "RpcMessage.RpcFlags should have been 0x0 instead of 0x%lx\n", RpcMessage.RpcFlags);
1569 ok(StubMsg.Buffer != NULL, "Buffer should not have been NULL\n");
1570 ok(!StubMsg.BufferStart, "BufferStart should have been NULL instead of %p\n", StubMsg.BufferStart);
1571 ok(!StubMsg.BufferEnd, "BufferEnd should have been NULL instead of %p\n", StubMsg.BufferEnd);
1573 ok(StubMsg.BufferLength == 0, "BufferLength should have left as 0 instead of being set to %d\n", StubMsg.BufferLength);
1574 ok(StubMsg.fBufferValid == TRUE, "fBufferValid should have been TRUE instead of 0x%x\n", StubMsg.fBufferValid);
1576 StubMsg.BufferLength = 1;
1577 NdrFreeBuffer(&StubMsg);
1578 ok(RpcMessage.Handle != NULL, "RpcMessage.Handle should not have been NULL\n");
1579 ok(RpcMessage.Buffer != NULL, "RpcMessage.Buffer should not have been NULL\n");
1580 ok(RpcMessage.BufferLength == 10, "RpcMessage.BufferLength should have been left as 10 instead of %d\n", RpcMessage.BufferLength);
1581 ok(StubMsg.Buffer != NULL, "Buffer should not have been NULL\n");
1582 ok(StubMsg.BufferLength == 1, "BufferLength should have left as 1 instead of being set to %d\n", StubMsg.BufferLength);
1583 ok(StubMsg.fBufferValid == FALSE, "fBufferValid should have been FALSE instead of 0x%x\n", StubMsg.fBufferValid);
1585 /* attempt double-free */
1586 NdrFreeBuffer(&StubMsg);
1588 status = RpcServerUnregisterIf(NULL, NULL, FALSE);
1589 ok(status == RPC_S_OK, "RpcServerUnregisterIf failed (%lu)\n", status);
1592 START_TEST( ndr_marshall )
1594 test_ndr_simple_type();
1595 test_simple_types();
1596 test_simple_struct();
1597 test_fullpointer_xlat();
1600 test_ndr_allocate();
1601 test_conformant_array();
1602 test_conformant_string();
1603 test_nonconformant_string();