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 */
76 static void test_ndr_simple_type(void)
78 RPC_MESSAGE RpcMessage;
79 MIDL_STUB_MESSAGE StubMsg;
80 MIDL_STUB_DESC StubDesc;
83 StubDesc = Object_StubDesc;
84 StubDesc.pFormatTypes = NULL;
86 NdrClientInitializeNew(
92 StubMsg.BufferLength = 16;
93 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
95 NdrSimpleTypeMarshall(&StubMsg, (unsigned char*)&l, 8 /* FC_LONG */);
96 ok(StubMsg.Buffer == StubMsg.BufferStart + 4, "%p %p\n", StubMsg.Buffer, StubMsg.BufferStart);
97 ok(*(long*)StubMsg.BufferStart == l, "%ld\n", *(long*)StubMsg.BufferStart);
99 StubMsg.Buffer = StubMsg.BufferStart + 1;
100 NdrSimpleTypeMarshall(&StubMsg, (unsigned char*)&l, 8 /* FC_LONG */);
101 ok(StubMsg.Buffer == StubMsg.BufferStart + 8, "%p %p\n", StubMsg.Buffer, StubMsg.BufferStart);
102 ok(*(long*)(StubMsg.BufferStart + 4) == l, "%ld\n", *(long*)StubMsg.BufferStart);
104 StubMsg.Buffer = StubMsg.BufferStart + 1;
105 NdrSimpleTypeUnmarshall(&StubMsg, (unsigned char*)&l2, 8 /* FC_LONG */);
106 ok(StubMsg.Buffer == StubMsg.BufferStart + 8, "%p %p\n", StubMsg.Buffer, StubMsg.BufferStart);
107 ok(l2 == l, "%ld\n", l2);
109 HeapFree(GetProcessHeap(), 0, StubMsg.BufferStart);
112 static void test_pointer_marshal(const unsigned char *formattypes,
115 const void *wiredata,
117 int(*cmp)(const void*,const void*,size_t),
118 long num_additional_allocs,
121 RPC_MESSAGE RpcMessage;
122 MIDL_STUB_MESSAGE StubMsg;
123 MIDL_STUB_DESC StubDesc;
126 unsigned char *mem, *mem_orig;
128 my_alloc_called = my_free_called = 0;
132 StubDesc = Object_StubDesc;
133 StubDesc.pFormatTypes = formattypes;
135 NdrClientInitializeNew(
141 StubMsg.BufferLength = 0;
142 NdrPointerBufferSize( &StubMsg,
145 ok(StubMsg.BufferLength >= wiredatalen, "%s: length %d\n", msgpfx, StubMsg.BufferLength);
147 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
148 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
149 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
151 memset(StubMsg.BufferStart, 0x0, StubMsg.BufferLength); /* This is a hack to clear the padding between the ptr and longlong/double */
153 ptr = NdrPointerMarshall( &StubMsg, memsrc, formattypes );
154 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
155 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
156 ok(!memcmp(StubMsg.BufferStart, wiredata, wiredatalen), "%s: incorrectly marshaled\n", msgpfx);
158 StubMsg.Buffer = StubMsg.BufferStart;
159 StubMsg.MemorySize = 0;
163 /* NdrPointerMemorySize crashes under Wine */
164 size = NdrPointerMemorySize( &StubMsg, formattypes );
165 ok(size == StubMsg.MemorySize, "%s: mem size %u size %u\n", msgpfx, StubMsg.MemorySize, size);
166 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
167 if(formattypes[1] & 0x10 /* FC_POINTER_DEREF */)
168 ok(size == srcsize + 4, "%s: mem size %u\n", msgpfx, size);
170 ok(size == srcsize, "%s: mem size %u\n", msgpfx, size);
172 StubMsg.Buffer = StubMsg.BufferStart;
173 StubMsg.MemorySize = 16;
174 size = NdrPointerMemorySize( &StubMsg, formattypes );
175 ok(size == StubMsg.MemorySize, "%s: mem size %u size %u\n", msgpfx, StubMsg.MemorySize, size);
176 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
177 if(formattypes[1] & 0x10 /* FC_POINTER_DEREF */)
178 ok(size == srcsize + 4 + 16, "%s: mem size %u\n", msgpfx, size);
180 ok(size == srcsize + 16, "%s: mem size %u\n", msgpfx, size);
182 StubMsg.Buffer = StubMsg.BufferStart;
183 StubMsg.MemorySize = 1;
184 size = NdrPointerMemorySize( &StubMsg, formattypes );
185 ok(size == StubMsg.MemorySize, "%s: mem size %u size %u\n", msgpfx, StubMsg.MemorySize, size);
186 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
187 if(formattypes[1] & 0x10 /* FC_POINTER_DEREF */)
188 ok(size == srcsize + 4 + (srcsize == 8 ? 8 : 4), "%s: mem size %u\n", msgpfx, size);
190 ok(size == srcsize + (srcsize == 8 ? 8 : 4), "%s: mem size %u\n", msgpfx, size);
194 if(formattypes[1] & 0x10) size += 4;
196 StubMsg.Buffer = StubMsg.BufferStart;
197 StubMsg.MemorySize = 0;
198 mem_orig = mem = HeapAlloc(GetProcessHeap(), 0, size);
200 if(formattypes[1] & 0x10 /* FC_POINTER_DEREF */)
202 ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 0 );
203 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
204 ok(mem == mem_orig, "%s: mem has changed %p %p\n", msgpfx, mem, mem_orig);
205 ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx);
206 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
207 ok(StubMsg.MemorySize == 0, "%s: memorysize %d\n", msgpfx, StubMsg.MemorySize);
208 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
211 /* reset the buffer and call with must alloc */
212 StubMsg.Buffer = StubMsg.BufferStart;
213 if(formattypes[1] & 0x10 /* FC_POINTER_DEREF */)
215 ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 1 );
216 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
217 /* doesn't allocate mem in this case */
219 ok(mem == mem_orig, "%s: mem has changed %p %p\n", msgpfx, mem, mem_orig);
221 ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx);
222 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
223 ok(StubMsg.MemorySize == 0, "%s: memorysize %d\n", msgpfx, StubMsg.MemorySize);
226 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
229 if(formattypes[0] != 0x11 /* FC_RP */)
231 /* now pass the address of a NULL ptr */
233 StubMsg.Buffer = StubMsg.BufferStart;
234 ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 0 );
235 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
236 ok(mem != StubMsg.BufferStart + wiredatalen - srcsize, "%s: mem points to buffer %p %p\n", msgpfx, mem, StubMsg.BufferStart);
237 ok(!cmp(mem, memsrc, size), "%s: incorrectly unmarshaled\n", msgpfx);
238 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
239 ok(StubMsg.MemorySize == 0, "%s: memorysize %d\n", msgpfx, StubMsg.MemorySize);
240 ok(my_alloc_called == num_additional_allocs + 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
242 NdrPointerFree(&StubMsg, mem, formattypes);
244 /* again pass address of NULL ptr, but pretend we're a server */
246 StubMsg.Buffer = StubMsg.BufferStart;
247 StubMsg.IsClient = 0;
248 ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 0 );
249 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
251 ok(mem == StubMsg.BufferStart + wiredatalen - srcsize, "%s: mem doesn't point to buffer %p %p\n", msgpfx, mem, StubMsg.BufferStart);
253 ok(!cmp(mem, memsrc, size), "%s: incorrecly unmarshaled\n", msgpfx);
254 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
255 ok(StubMsg.MemorySize == 0, "%s: memorysize %d\n", msgpfx, StubMsg.MemorySize);
257 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
261 HeapFree(GetProcessHeap(), 0, mem_orig);
262 HeapFree(GetProcessHeap(), 0, StubMsg.BufferStart);
265 static int deref_cmp(const void *s1, const void *s2, size_t num)
267 return memcmp(*(const void *const *)s1, *(const void *const *)s2, num);
271 static void test_simple_types(void)
273 unsigned char wiredata[16];
275 unsigned char *ch_ptr;
283 static const unsigned char fmtstr_up_char[] =
285 0x12, 0x8, /* FC_UP [simple_pointer] */
289 static const unsigned char fmtstr_up_byte[] =
291 0x12, 0x8, /* FC_UP [simple_pointer] */
295 static const unsigned char fmtstr_up_small[] =
297 0x12, 0x8, /* FC_UP [simple_pointer] */
301 static const unsigned char fmtstr_up_usmall[] =
303 0x12, 0x8, /* FC_UP [simple_pointer] */
307 static const unsigned char fmtstr_rp_char[] =
309 0x11, 0x8, /* FC_RP [simple_pointer] */
313 static const unsigned char fmtstr_rpup_char[] =
315 0x11, 0x14, /* FC_RP [alloced_on_stack] */
316 NdrFcShort( 0x2 ), /* Offset= 2 (4) */
317 0x12, 0x8, /* FC_UP [simple_pointer] */
321 static const unsigned char fmtstr_rpup_char2[] =
323 0x11, 0x04, /* FC_RP [alloced_on_stack] */
324 NdrFcShort( 0x2 ), /* Offset= 2 (4) */
325 0x12, 0x8, /* FC_UP [simple_pointer] */
330 static const unsigned char fmtstr_up_wchar[] =
332 0x12, 0x8, /* FC_UP [simple_pointer] */
336 static const unsigned char fmtstr_up_short[] =
338 0x12, 0x8, /* FC_UP [simple_pointer] */
342 static const unsigned char fmtstr_up_ushort[] =
344 0x12, 0x8, /* FC_UP [simple_pointer] */
348 static const unsigned char fmtstr_up_enum16[] =
350 0x12, 0x8, /* FC_UP [simple_pointer] */
354 static const unsigned char fmtstr_up_long[] =
356 0x12, 0x8, /* FC_UP [simple_pointer] */
360 static const unsigned char fmtstr_up_ulong[] =
362 0x12, 0x8, /* FC_UP [simple_pointer] */
366 static const unsigned char fmtstr_up_enum32[] =
368 0x12, 0x8, /* FC_UP [simple_pointer] */
372 static const unsigned char fmtstr_up_errorstatus[] =
374 0x12, 0x8, /* FC_UP [simple_pointer] */
375 0x10, /* FC_ERROR_STATUS_T */
379 static const unsigned char fmtstr_up_longlong[] =
381 0x12, 0x8, /* FC_UP [simple_pointer] */
385 static const unsigned char fmtstr_up_float[] =
387 0x12, 0x8, /* FC_UP [simple_pointer] */
391 static const unsigned char fmtstr_up_double[] =
393 0x12, 0x8, /* FC_UP [simple_pointer] */
400 *(void**)wiredata = ch_ptr;
401 wiredata[sizeof(void*)] = ch;
403 test_pointer_marshal(fmtstr_up_char, ch_ptr, 1, wiredata, 5, NULL, 0, "up_char");
404 test_pointer_marshal(fmtstr_up_byte, ch_ptr, 1, wiredata, 5, NULL, 0, "up_byte");
405 test_pointer_marshal(fmtstr_up_small, ch_ptr, 1, wiredata, 5, NULL, 0, "up_small");
406 test_pointer_marshal(fmtstr_up_usmall, ch_ptr, 1, wiredata, 5, NULL, 0, "up_usmall");
408 test_pointer_marshal(fmtstr_rp_char, ch_ptr, 1, &ch, 1, NULL, 0, "rp_char");
410 test_pointer_marshal(fmtstr_rpup_char, &ch_ptr, 1, wiredata, 5, deref_cmp, 1, "rpup_char");
411 test_pointer_marshal(fmtstr_rpup_char2, ch_ptr, 1, wiredata, 5, NULL, 0, "rpup_char2");
414 *(void**)wiredata = &s;
415 *(unsigned short*)(wiredata + sizeof(void*)) = s;
417 test_pointer_marshal(fmtstr_up_wchar, &s, 2, wiredata, 6, NULL, 0, "up_wchar");
418 test_pointer_marshal(fmtstr_up_short, &s, 2, wiredata, 6, NULL, 0, "up_short");
419 test_pointer_marshal(fmtstr_up_ushort, &s, 2, wiredata, 6, NULL, 0, "up_ushort");
422 *(void**)wiredata = &i;
423 *(unsigned short*)(wiredata + sizeof(void*)) = i;
424 test_pointer_marshal(fmtstr_up_enum16, &i, 2, wiredata, 6, NULL, 0, "up_enum16");
427 *(void**)wiredata = &l;
428 *(unsigned long*)(wiredata + sizeof(void*)) = l;
430 test_pointer_marshal(fmtstr_up_long, &l, 4, wiredata, 8, NULL, 0, "up_long");
431 test_pointer_marshal(fmtstr_up_ulong, &l, 4, wiredata, 8, NULL, 0, "up_ulong");
432 test_pointer_marshal(fmtstr_up_enum32, &l, 4, wiredata, 8, NULL, 0, "up_emun32");
433 test_pointer_marshal(fmtstr_up_errorstatus, &l, 4, wiredata, 8, NULL, 0, "up_errorstatus");
435 ll = ((ULONGLONG)0xcafebabe) << 32 | 0xdeadbeef;
436 *(void**)wiredata = ≪
437 *(void**)(wiredata + sizeof(void*)) = NULL;
438 *(ULONGLONG*)(wiredata + 2 * sizeof(void*)) = ll;
439 test_pointer_marshal(fmtstr_up_longlong, &ll, 8, wiredata, 16, NULL, 0, "up_longlong");
442 *(void**)wiredata = &f;
443 *(float*)(wiredata + sizeof(void*)) = f;
444 test_pointer_marshal(fmtstr_up_float, &f, 4, wiredata, 8, NULL, 0, "up_float");
447 *(void**)wiredata = &d;
448 *(void**)(wiredata + sizeof(void*)) = NULL;
449 *(double*)(wiredata + 2 * sizeof(void*)) = d;
450 test_pointer_marshal(fmtstr_up_double, &d, 8, wiredata, 16, NULL, 0, "up_double");
454 static void test_simple_struct_marshal(const unsigned char *formattypes,
457 const void *wiredata,
459 int(*cmp)(const void*,const void*,size_t),
460 long num_additional_allocs,
463 RPC_MESSAGE RpcMessage;
464 MIDL_STUB_MESSAGE StubMsg;
465 MIDL_STUB_DESC StubDesc;
468 unsigned char *mem, *mem_orig;
470 my_alloc_called = my_free_called = 0;
474 StubDesc = Object_StubDesc;
475 StubDesc.pFormatTypes = formattypes;
477 NdrClientInitializeNew(&RpcMessage, &StubMsg, &StubDesc, 0);
479 StubMsg.BufferLength = 0;
480 NdrSimpleStructBufferSize( &StubMsg, (unsigned char *)memsrc, formattypes );
481 ok(StubMsg.BufferLength >= wiredatalen, "%s: length %d\n", msgpfx, StubMsg.BufferLength);
482 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
483 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
484 ptr = NdrSimpleStructMarshall( &StubMsg, (unsigned char*)memsrc, formattypes );
485 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
486 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart);
487 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));
491 /* FIXME: Causes Wine to crash */
492 StubMsg.Buffer = StubMsg.BufferStart;
493 StubMsg.MemorySize = 0;
494 size = NdrSimpleStructMemorySize( &StubMsg, formattypes );
495 ok(size == StubMsg.MemorySize, "%s: size != MemorySize\n", msgpfx);
496 ok(size == srcsize, "%s: mem size %u\n", msgpfx, size);
497 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart);
499 StubMsg.Buffer = StubMsg.BufferStart;
500 size = NdrSimpleStructMemorySize( &StubMsg, formattypes );
502 ok(size == StubMsg.MemorySize, "%s: size != MemorySize\n", msgpfx);
504 ok(StubMsg.MemorySize == ((srcsize + 3) & ~3) + srcsize, "%s: mem size %u\n", msgpfx, size);
505 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart);
508 /*** Unmarshalling first with must_alloc false ***/
510 StubMsg.Buffer = StubMsg.BufferStart;
511 StubMsg.MemorySize = 0;
512 mem_orig = mem = HeapAlloc(GetProcessHeap(), 0, srcsize);
513 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 0 );
514 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
515 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart);
516 ok(mem == mem_orig, "%s: mem has changed %p %p\n", msgpfx, mem, mem_orig);
517 ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx);
518 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
520 ok(StubMsg.MemorySize == 0, "%s: memorysize touched in unmarshal\n", msgpfx);
522 /* if we're a server we still use the suppiled memory */
523 StubMsg.Buffer = StubMsg.BufferStart;
524 StubMsg.IsClient = 0;
525 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 0 );
526 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
527 ok(mem == mem_orig, "%s: mem has changed %p %p\n", msgpfx, mem, mem_orig);
528 ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx);
529 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
531 ok(StubMsg.MemorySize == 0, "%s: memorysize touched in unmarshal\n", msgpfx);
533 /* ...unless we pass a NULL ptr, then the buffer is used.
534 Passing a NULL ptr while we're a client && !must_alloc
535 crashes on Windows, so we won't do that. */
538 StubMsg.IsClient = 0;
539 StubMsg.Buffer = StubMsg.BufferStart;
540 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 0 );
541 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
542 ok(mem == StubMsg.BufferStart, "%s: mem not equal buffer\n", msgpfx);
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 /*** now must_alloc is true ***/
550 /* with must_alloc set we always allocate new memory whether or not we're
551 a server and also when passing NULL */
553 StubMsg.IsClient = 1;
554 StubMsg.Buffer = StubMsg.BufferStart;
555 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 1 );
556 ok(ptr == NULL, "ret %p\n", ptr);
557 ok(mem != mem_orig, "mem not changed %p %p\n", mem, mem_orig);
558 ok(!cmp(mem, memsrc, srcsize), "incorrectly unmarshaled\n");
559 ok(my_alloc_called == num_additional_allocs + 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
561 ok(StubMsg.MemorySize == 0, "memorysize touched in unmarshal\n");
564 StubMsg.Buffer = StubMsg.BufferStart;
565 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 1 );
566 ok(ptr == NULL, "ret %p\n", ptr);
567 ok(mem != mem_orig, "mem not changed %p %p\n", mem, mem_orig);
568 ok(!cmp(mem, memsrc, srcsize), "incorrectly unmarshaled\n");
569 ok(my_alloc_called == num_additional_allocs + 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
571 ok(StubMsg.MemorySize == 0, "memorysize touched in unmarshal\n");
574 StubMsg.Buffer = StubMsg.BufferStart;
575 StubMsg.IsClient = 0;
576 StubMsg.ReuseBuffer = 1;
577 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 1 );
578 ok(ptr == NULL, "ret %p\n", ptr);
579 ok(mem != mem_orig, "mem not changed %p %p\n", mem, mem_orig);
580 ok(mem != StubMsg.BufferStart, "mem is buffer mem\n");
581 ok(!cmp(mem, memsrc, srcsize), "incorrectly unmarshaled\n");
582 ok(my_alloc_called == num_additional_allocs + 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
584 ok(StubMsg.MemorySize == 0, "memorysize touched in unmarshal\n");
587 StubMsg.Buffer = StubMsg.BufferStart;
588 StubMsg.IsClient = 0;
589 StubMsg.ReuseBuffer = 1;
590 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 1 );
591 ok(ptr == NULL, "ret %p\n", ptr);
592 ok(mem != StubMsg.BufferStart, "mem is buffer mem\n");
593 ok(!cmp(mem, memsrc, srcsize), "incorrectly unmarshaled\n");
594 ok(my_alloc_called == num_additional_allocs + 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
596 ok(StubMsg.MemorySize == 0, "memorysize touched in unmarshal\n");
607 static int ps1_cmp(const void *s1, const void *s2, size_t num)
609 const ps1_t *p1, *p2;
617 if(p1->pl1 && p2->pl1)
619 if(*p1->pl1 != *p2->pl1)
622 else if(p1->pl1 || p1->pl1)
625 if(p1->pc1 && p2->pc1)
627 if(*p1->pc1 != *p2->pc1)
630 else if(p1->pc1 || p1->pc1)
636 static void test_simple_struct(void)
638 unsigned char wiredata[28];
639 unsigned long wiredatalen;
644 static const unsigned char fmtstr_simple_struct[] =
646 0x12, 0x0, /* FC_UP */
647 NdrFcShort( 0x2 ), /* Offset=2 */
648 0x15, 0x3, /* FC_STRUCT [align 4] */
649 NdrFcShort( 0x18 ), /* [size 24] */
652 0x38, /* FC_ALIGNM4 */
655 0x39, /* FC_ALIGNM8 */
666 static const unsigned char fmtstr_pointer_struct[] =
668 0x12, 0x0, /* FC_UP */
669 NdrFcShort( 0x2 ), /* Offset=2 */
670 0x16, 0x3, /* FC_PSTRUCT [align 4] */
671 NdrFcShort( 0xc ), /* [size 12] */
674 0x46, /* FC_NO_REPEAT */
676 NdrFcShort( 0x4 ), /* 4 */
677 NdrFcShort( 0x4 ), /* 4 */
678 0x13, 0x8, /* FC_OP [simple_pointer] */
681 0x46, /* FC_NO_REPEAT */
683 NdrFcShort( 0x8 ), /* 8 */
684 NdrFcShort( 0x8 ), /* 8 */
685 0x13, 0x8, /* FC_OP [simple_pointer] */
702 s1.ll = ((LONGLONG) 0xbadefeed << 32) | 0x2468ace0;
705 memcpy(wiredata, &s1, wiredatalen);
706 test_simple_struct_marshal(fmtstr_simple_struct + 4, &s1, 24, wiredata, 24, NULL, 0, "struct");
708 *(void**)wiredata = &s1;
709 memcpy(wiredata + 4, &s1, wiredatalen);
712 /* one of the unmarshallings crashes Wine */
713 test_pointer_marshal(fmtstr_simple_struct, &s1, 24, wiredata, 28, NULL, 0, "struct");
722 memcpy(wiredata + 4, &ps1, 12);
723 memcpy(wiredata + 16, &l, 4);
724 memcpy(wiredata + 20, &c, 1);
726 test_simple_struct_marshal(fmtstr_pointer_struct + 4, &ps1, 17, wiredata + 4, 17, ps1_cmp, 2, "pointer_struct");
727 *(void**)wiredata = &ps1;
730 /* one of the unmarshallings crashes Wine */
731 test_pointer_marshal(fmtstr_pointer_struct, &ps1, 17, wiredata, 21, ps1_cmp, 2, "pointer_struct");
735 static void test_fullpointer_xlat(void)
737 PFULL_PTR_XLAT_TABLES pXlatTables;
742 pXlatTables = NdrFullPointerXlatInit(2, XLAT_CLIENT);
744 /* "marshaling" phase */
746 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 1, &RefId);
747 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
748 ok(RefId == 0x1, "RefId should be 0x1 instead of 0x%x\n", RefId);
750 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 0, &RefId);
751 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
752 ok(RefId == 0x1, "RefId should be 0x1 instead of 0x%x\n", RefId);
754 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebabe, 0, &RefId);
755 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
756 ok(RefId == 0x2, "RefId should be 0x2 instead of 0x%x\n", RefId);
758 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xdeadbeef, 0, &RefId);
759 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
760 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
762 ret = NdrFullPointerQueryPointer(pXlatTables, NULL, 0, &RefId);
763 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
764 ok(RefId == 0, "RefId should be 0 instead of 0x%x\n", RefId);
766 /* "unmarshaling" phase */
768 ret = NdrFullPointerQueryRefId(pXlatTables, 0x2, 0, &Pointer);
769 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
770 ok(Pointer == (void *)0xcafebabe, "Pointer should be 0xcafebabe instead of %p\n", Pointer);
772 ret = NdrFullPointerQueryRefId(pXlatTables, 0x4, 0, &Pointer);
773 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
774 ok(Pointer == NULL, "Pointer should be NULL instead of %p\n", Pointer);
776 NdrFullPointerInsertRefId(pXlatTables, 0x4, (void *)0xdeadbabe);
778 ret = NdrFullPointerQueryRefId(pXlatTables, 0x4, 1, &Pointer);
779 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
780 ok(Pointer == (void *)0xdeadbabe, "Pointer should be (void *)0xdeadbabe instead of %p\n", Pointer);
782 NdrFullPointerXlatFree(pXlatTables);
784 pXlatTables = NdrFullPointerXlatInit(2, XLAT_SERVER);
786 /* "unmarshaling" phase */
788 ret = NdrFullPointerQueryRefId(pXlatTables, 0x2, 1, &Pointer);
789 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
790 ok(Pointer == NULL, "Pointer should be NULL instead of %p\n", Pointer);
792 NdrFullPointerInsertRefId(pXlatTables, 0x2, (void *)0xcafebabe);
794 ret = NdrFullPointerQueryRefId(pXlatTables, 0x2, 0, &Pointer);
795 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
796 ok(Pointer == (void *)0xcafebabe, "Pointer should be (void *)0xcafebabe instead of %p\n", Pointer);
798 ret = NdrFullPointerQueryRefId(pXlatTables, 0x2, 1, &Pointer);
799 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
800 ok(Pointer == (void *)0xcafebabe, "Pointer should be (void *)0xcafebabe instead of %p\n", Pointer);
802 /* "marshaling" phase */
804 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 1, &RefId);
805 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
806 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
808 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 1, &RefId);
809 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
810 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
812 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 0, &RefId);
813 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
814 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
816 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebabe, 0, &RefId);
817 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
818 ok(RefId == 0x2, "RefId should be 0x2 instead of 0x%x\n", RefId);
820 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xdeadbeef, 0, &RefId);
821 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
822 ok(RefId == 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId);
824 /* "freeing" phase */
826 ret = NdrFullPointerFree(pXlatTables, (void *)0xcafebeef);
827 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
829 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 0x20, &RefId);
830 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
831 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
833 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 1, &RefId);
834 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
835 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
837 ret = NdrFullPointerFree(pXlatTables, (void *)0xcafebabe);
838 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
840 ret = NdrFullPointerFree(pXlatTables, (void *)0xdeadbeef);
841 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
843 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xdeadbeef, 0x20, &RefId);
844 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
845 ok(RefId == 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId);
847 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xdeadbeef, 1, &RefId);
848 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
849 ok(RefId == 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId);
851 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xdeadbeef, 1, &RefId);
852 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
853 ok(RefId == 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId);
855 ret = NdrFullPointerFree(pXlatTables, (void *)0xdeadbeef);
856 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
858 NdrFullPointerXlatFree(pXlatTables);
861 static void test_client_init(void)
863 MIDL_STUB_MESSAGE stubMsg;
866 memset(&stubMsg, 0xcc, sizeof(stubMsg));
868 NdrClientInitializeNew(&rpcMsg, &stubMsg, &Object_StubDesc, 1);
870 #define TEST_ZERO(field, fmt) ok(stubMsg.field == 0, #field " should have be set to zero instead of " fmt "\n", stubMsg.field)
871 #define TEST_POINTER_UNSET(field) ok(stubMsg.field == (void *)0xcccccccc, #field " should have be unset instead of %p\n", stubMsg.field)
872 #define TEST_ULONG_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have be unset instead of 0x%x\n", stubMsg.field)
873 #define TEST_ULONG_PTR_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have be unset instead of 0x%lx\n", stubMsg.field)
875 ok(stubMsg.RpcMsg == &rpcMsg, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg, stubMsg.RpcMsg);
876 TEST_POINTER_UNSET(Buffer);
877 TEST_ZERO(BufferStart, "%p");
878 TEST_ZERO(BufferEnd, "%p");
879 TEST_POINTER_UNSET(BufferMark);
880 TEST_ZERO(BufferLength, "%d");
881 TEST_ULONG_UNSET(MemorySize);
882 TEST_POINTER_UNSET(Memory);
883 ok(stubMsg.IsClient == 1, "stubMsg.IsClient should have been 1 instead of %u\n", stubMsg.IsClient);
884 TEST_ZERO(ReuseBuffer, "%d");
885 TEST_ZERO(pAllocAllNodesContext, "%p");
886 TEST_ZERO(pPointerQueueState, "%p");
887 TEST_ZERO(IgnoreEmbeddedPointers, "%d");
888 TEST_ZERO(PointerBufferMark, "%p");
889 TEST_ZERO(fBufferValid, "%d");
890 TEST_ZERO(uFlags, "%d");
891 /* FIXME: UniquePtrCount */
892 TEST_ULONG_PTR_UNSET(MaxCount);
893 TEST_ULONG_UNSET(Offset);
894 TEST_ULONG_UNSET(ActualCount);
895 ok(stubMsg.pfnAllocate == my_alloc, "stubMsg.pfnAllocate should have been %p instead of %p\n", my_alloc, stubMsg.pfnAllocate);
896 ok(stubMsg.pfnFree == my_free, "stubMsg.pfnFree should have been %p instead of %p\n", my_free, stubMsg.pfnFree);
897 TEST_ZERO(StackTop, "%p");
898 TEST_POINTER_UNSET(pPresentedType);
899 TEST_POINTER_UNSET(pTransmitType);
900 TEST_POINTER_UNSET(SavedHandle);
901 ok(stubMsg.StubDesc == &Object_StubDesc, "stubMsg.StubDesc should have been %p instead of %p\n", &Object_StubDesc, stubMsg.StubDesc);
902 TEST_POINTER_UNSET(FullPtrXlatTables);
903 TEST_ZERO(FullPtrRefId, "%d");
904 TEST_ZERO(PointerLength, "%d");
905 TEST_ZERO(fInDontFree, "%d");
906 TEST_ZERO(fDontCallFreeInst, "%d");
907 TEST_ZERO(fInOnlyParam, "%d");
908 TEST_ZERO(fHasReturn, "%d");
909 TEST_ZERO(fHasExtensions, "%d");
910 TEST_ZERO(fHasNewCorrDesc, "%d");
911 TEST_ZERO(fUnused, "%d");
912 ok(stubMsg.fUnused2 == 0xffffcccc, "stubMsg.fUnused2 should have been 0xcccc instead of 0x%x\n", stubMsg.fUnused2);
913 ok(stubMsg.dwDestContext == MSHCTX_DIFFERENTMACHINE, "stubMsg.dwDestContext should have been MSHCTX_DIFFERENTMACHINE instead of %d\n", stubMsg.dwDestContext);
914 TEST_ZERO(pvDestContext, "%p");
915 TEST_POINTER_UNSET(SavedContextHandles);
916 TEST_ULONG_UNSET(ParamNumber);
917 TEST_ZERO(pRpcChannelBuffer, "%p");
918 TEST_ZERO(pArrayInfo, "%p");
919 TEST_POINTER_UNSET(SizePtrCountArray);
920 TEST_POINTER_UNSET(SizePtrOffsetArray);
921 TEST_POINTER_UNSET(SizePtrLengthArray);
922 TEST_POINTER_UNSET(pArgQueue);
923 TEST_ZERO(dwStubPhase, "%d");
924 /* FIXME: where does this value come from? */
925 trace("LowStackMark is %p\n", stubMsg.LowStackMark);
926 TEST_ZERO(pAsyncMsg, "%p");
927 TEST_ZERO(pCorrInfo, "%p");
928 TEST_ZERO(pCorrMemory, "%p");
929 TEST_ZERO(pMemoryList, "%p");
930 TEST_POINTER_UNSET(pCSInfo);
931 TEST_POINTER_UNSET(ConformanceMark);
932 TEST_POINTER_UNSET(VarianceMark);
933 ok(stubMsg.Unused == 0xcccccccc, "Unused should have be unset instead of 0x%lx\n", stubMsg.Unused);
934 TEST_POINTER_UNSET(pContext);
935 TEST_POINTER_UNSET(ContextHandleHash);
936 TEST_POINTER_UNSET(pUserMarshalList);
937 TEST_ULONG_PTR_UNSET(Reserved51_3);
938 TEST_ULONG_PTR_UNSET(Reserved51_4);
939 TEST_ULONG_PTR_UNSET(Reserved51_5);
940 #undef TEST_ULONG_UNSET
941 #undef TEST_POINTER_UNSET
946 static void test_ndr_allocate(void)
948 RPC_MESSAGE RpcMessage;
949 MIDL_STUB_MESSAGE StubMsg;
950 MIDL_STUB_DESC StubDesc;
952 struct tag_mem_list_t
956 struct tag_mem_list_t *next;
958 const DWORD magic_MEML = 'M' << 24 | 'E' << 16 | 'M' << 8 | 'L';
960 StubDesc = Object_StubDesc;
961 NdrClientInitializeNew(&RpcMessage, &StubMsg, &StubDesc, 0);
963 ok(StubMsg.pMemoryList == NULL, "memlist %p\n", StubMsg.pMemoryList);
964 my_alloc_called = my_free_called = 0;
965 p1 = NdrAllocate(&StubMsg, 10);
966 p2 = NdrAllocate(&StubMsg, 20);
967 ok(my_alloc_called == 2, "alloc called %d\n", my_alloc_called);
968 mem_list = StubMsg.pMemoryList;
970 ok(mem_list != NULL, "mem_list NULL\n");
974 ok(mem_list->magic == magic_MEML, "magic %08x\n", mem_list->magic);
975 ok(mem_list->ptr == p2, "ptr != p2\n");
976 ok(mem_list->next != NULL, "next NULL\n");
977 mem_list = mem_list->next;
980 ok(mem_list->magic == magic_MEML, "magic %08x\n", mem_list->magic);
981 ok(mem_list->ptr == p1, "ptr != p2\n");
982 ok(mem_list->next == NULL, "next %p\n", mem_list->next);
985 /* NdrFree isn't exported so we can't test free'ing */
988 static void test_conformant_array(void)
990 RPC_MESSAGE RpcMessage;
991 MIDL_STUB_MESSAGE StubMsg;
992 MIDL_STUB_DESC StubDesc;
994 unsigned char *mem, *mem_orig;
995 unsigned char memsrc[20];
997 static const unsigned char fmtstr_conf_array[] =
999 0x1b, /* FC_CARRAY */
1001 NdrFcShort( 0x1 ), /* elem size */
1002 0x40, /* Corr desc: const */
1004 NdrFcShort(0x10), /* const = 0x10 */
1009 StubDesc = Object_StubDesc;
1010 StubDesc.pFormatTypes = fmtstr_conf_array;
1012 NdrClientInitializeNew(
1018 StubMsg.BufferLength = 0;
1019 NdrConformantArrayBufferSize( &StubMsg,
1021 fmtstr_conf_array );
1022 ok(StubMsg.BufferLength >= 20, "length %d\n", StubMsg.BufferLength);
1024 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1025 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
1026 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
1028 ptr = NdrConformantArrayMarshall( &StubMsg, memsrc, fmtstr_conf_array );
1029 ok(ptr == NULL, "ret %p\n", ptr);
1030 ok(StubMsg.Buffer - StubMsg.BufferStart == 20, "Buffer %p Start %p len %d\n", StubMsg.Buffer, StubMsg.BufferStart, 20);
1031 ok(!memcmp(StubMsg.BufferStart + 4, memsrc, 16), "incorrectly marshaled\n");
1033 StubMsg.Buffer = StubMsg.BufferStart;
1034 StubMsg.MemorySize = 0;
1038 my_alloc_called = 0;
1039 /* passing mem == NULL with must_alloc == 0 crashes under Windows */
1040 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1041 ok(mem != NULL, "mem not alloced\n");
1042 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1043 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1045 my_alloc_called = 0;
1046 StubMsg.Buffer = StubMsg.BufferStart;
1048 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 0);
1049 ok(mem == mem_orig, "mem alloced\n");
1050 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1051 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1053 my_alloc_called = 0;
1054 StubMsg.Buffer = StubMsg.BufferStart;
1055 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1056 ok(mem != mem_orig, "mem not alloced\n");
1057 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1058 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1061 StubMsg.Buffer = StubMsg.BufferStart;
1062 NdrConformantArrayFree( &StubMsg, mem, fmtstr_conf_array );
1063 ok(my_free_called == 0, "free called %d\n", my_free_called);
1064 StubMsg.pfnFree(mem);
1067 my_alloc_called = 0;
1068 StubMsg.IsClient = 0;
1070 StubMsg.Buffer = StubMsg.BufferStart;
1071 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 0);
1073 ok(mem == StubMsg.BufferStart + 4, "mem not pointing at buffer\n");
1074 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1076 my_alloc_called = 0;
1078 StubMsg.Buffer = StubMsg.BufferStart;
1079 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1080 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1081 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1082 StubMsg.pfnFree(mem);
1084 my_alloc_called = 0;
1086 StubMsg.Buffer = StubMsg.BufferStart;
1087 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 0);
1088 ok(mem == mem_orig, "mem alloced\n");
1089 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1091 my_alloc_called = 0;
1093 StubMsg.Buffer = StubMsg.BufferStart;
1094 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1095 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1096 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1097 StubMsg.pfnFree(mem);
1098 StubMsg.pfnFree(mem_orig);
1100 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
1103 START_TEST( ndr_marshall )
1105 test_ndr_simple_type();
1106 test_simple_types();
1107 test_simple_struct();
1108 test_fullpointer_xlat();
1110 test_ndr_allocate();
1111 test_conformant_array();