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);
250 if (formattypes[2] == 0xd /* FC_ENUM16 */)
251 ok(mem != StubMsg.BufferStart + wiredatalen - srcsize, "%s: mem points to buffer %p %p\n", msgpfx, mem, StubMsg.BufferStart);
254 ok(mem == StubMsg.BufferStart + wiredatalen - srcsize, "%s: mem doesn't point to buffer %p %p\n", msgpfx, mem, StubMsg.BufferStart);
256 ok(!cmp(mem, memsrc, size), "%s: incorrecly unmarshaled\n", msgpfx);
257 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen);
258 ok(StubMsg.MemorySize == 0, "%s: memorysize %d\n", msgpfx, StubMsg.MemorySize);
259 if (formattypes[2] != 0xd /* FC_ENUM16 */) {
261 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
266 HeapFree(GetProcessHeap(), 0, mem_orig);
267 HeapFree(GetProcessHeap(), 0, StubMsg.BufferStart);
270 static int deref_cmp(const void *s1, const void *s2, size_t num)
272 return memcmp(*(const void *const *)s1, *(const void *const *)s2, num);
276 static void test_simple_types(void)
278 unsigned char wiredata[16];
280 unsigned char *ch_ptr;
288 static const unsigned char fmtstr_up_char[] =
290 0x12, 0x8, /* FC_UP [simple_pointer] */
294 static const unsigned char fmtstr_up_byte[] =
296 0x12, 0x8, /* FC_UP [simple_pointer] */
300 static const unsigned char fmtstr_up_small[] =
302 0x12, 0x8, /* FC_UP [simple_pointer] */
306 static const unsigned char fmtstr_up_usmall[] =
308 0x12, 0x8, /* FC_UP [simple_pointer] */
312 static const unsigned char fmtstr_rp_char[] =
314 0x11, 0x8, /* FC_RP [simple_pointer] */
318 static const unsigned char fmtstr_rpup_char[] =
320 0x11, 0x14, /* FC_RP [alloced_on_stack] */
321 NdrFcShort( 0x2 ), /* Offset= 2 (4) */
322 0x12, 0x8, /* FC_UP [simple_pointer] */
326 static const unsigned char fmtstr_rpup_char2[] =
328 0x11, 0x04, /* FC_RP [alloced_on_stack] */
329 NdrFcShort( 0x2 ), /* Offset= 2 (4) */
330 0x12, 0x8, /* FC_UP [simple_pointer] */
335 static const unsigned char fmtstr_up_wchar[] =
337 0x12, 0x8, /* FC_UP [simple_pointer] */
341 static const unsigned char fmtstr_up_short[] =
343 0x12, 0x8, /* FC_UP [simple_pointer] */
347 static const unsigned char fmtstr_up_ushort[] =
349 0x12, 0x8, /* FC_UP [simple_pointer] */
353 static const unsigned char fmtstr_up_enum16[] =
355 0x12, 0x8, /* FC_UP [simple_pointer] */
359 static const unsigned char fmtstr_up_long[] =
361 0x12, 0x8, /* FC_UP [simple_pointer] */
365 static const unsigned char fmtstr_up_ulong[] =
367 0x12, 0x8, /* FC_UP [simple_pointer] */
371 static const unsigned char fmtstr_up_enum32[] =
373 0x12, 0x8, /* FC_UP [simple_pointer] */
377 static const unsigned char fmtstr_up_errorstatus[] =
379 0x12, 0x8, /* FC_UP [simple_pointer] */
380 0x10, /* FC_ERROR_STATUS_T */
384 static const unsigned char fmtstr_up_longlong[] =
386 0x12, 0x8, /* FC_UP [simple_pointer] */
390 static const unsigned char fmtstr_up_float[] =
392 0x12, 0x8, /* FC_UP [simple_pointer] */
396 static const unsigned char fmtstr_up_double[] =
398 0x12, 0x8, /* FC_UP [simple_pointer] */
405 *(void**)wiredata = ch_ptr;
406 wiredata[sizeof(void*)] = ch;
408 test_pointer_marshal(fmtstr_up_char, ch_ptr, 1, wiredata, 5, NULL, 0, "up_char");
409 test_pointer_marshal(fmtstr_up_byte, ch_ptr, 1, wiredata, 5, NULL, 0, "up_byte");
410 test_pointer_marshal(fmtstr_up_small, ch_ptr, 1, wiredata, 5, NULL, 0, "up_small");
411 test_pointer_marshal(fmtstr_up_usmall, ch_ptr, 1, wiredata, 5, NULL, 0, "up_usmall");
413 test_pointer_marshal(fmtstr_rp_char, ch_ptr, 1, &ch, 1, NULL, 0, "rp_char");
415 test_pointer_marshal(fmtstr_rpup_char, &ch_ptr, 1, wiredata, 5, deref_cmp, 1, "rpup_char");
416 test_pointer_marshal(fmtstr_rpup_char2, ch_ptr, 1, wiredata, 5, NULL, 0, "rpup_char2");
419 *(void**)wiredata = &s;
420 *(unsigned short*)(wiredata + sizeof(void*)) = s;
422 test_pointer_marshal(fmtstr_up_wchar, &s, 2, wiredata, 6, NULL, 0, "up_wchar");
423 test_pointer_marshal(fmtstr_up_short, &s, 2, wiredata, 6, NULL, 0, "up_short");
424 test_pointer_marshal(fmtstr_up_ushort, &s, 2, wiredata, 6, NULL, 0, "up_ushort");
427 *(void**)wiredata = &i;
428 *(unsigned short*)(wiredata + sizeof(void*)) = i;
429 test_pointer_marshal(fmtstr_up_enum16, &i, 2, wiredata, 6, NULL, 0, "up_enum16");
432 *(void**)wiredata = &l;
433 *(unsigned long*)(wiredata + sizeof(void*)) = l;
435 test_pointer_marshal(fmtstr_up_long, &l, 4, wiredata, 8, NULL, 0, "up_long");
436 test_pointer_marshal(fmtstr_up_ulong, &l, 4, wiredata, 8, NULL, 0, "up_ulong");
437 test_pointer_marshal(fmtstr_up_enum32, &l, 4, wiredata, 8, NULL, 0, "up_emun32");
438 test_pointer_marshal(fmtstr_up_errorstatus, &l, 4, wiredata, 8, NULL, 0, "up_errorstatus");
440 ll = ((ULONGLONG)0xcafebabe) << 32 | 0xdeadbeef;
441 *(void**)wiredata = ≪
442 *(void**)(wiredata + sizeof(void*)) = NULL;
443 *(ULONGLONG*)(wiredata + 2 * sizeof(void*)) = ll;
444 test_pointer_marshal(fmtstr_up_longlong, &ll, 8, wiredata, 16, NULL, 0, "up_longlong");
447 *(void**)wiredata = &f;
448 *(float*)(wiredata + sizeof(void*)) = f;
449 test_pointer_marshal(fmtstr_up_float, &f, 4, wiredata, 8, NULL, 0, "up_float");
452 *(void**)wiredata = &d;
453 *(void**)(wiredata + sizeof(void*)) = NULL;
454 *(double*)(wiredata + 2 * sizeof(void*)) = d;
455 test_pointer_marshal(fmtstr_up_double, &d, 8, wiredata, 16, NULL, 0, "up_double");
459 static void test_simple_struct_marshal(const unsigned char *formattypes,
462 const void *wiredata,
464 int(*cmp)(const void*,const void*,size_t),
465 long num_additional_allocs,
468 RPC_MESSAGE RpcMessage;
469 MIDL_STUB_MESSAGE StubMsg;
470 MIDL_STUB_DESC StubDesc;
473 unsigned char *mem, *mem_orig;
475 my_alloc_called = my_free_called = 0;
479 StubDesc = Object_StubDesc;
480 StubDesc.pFormatTypes = formattypes;
482 NdrClientInitializeNew(&RpcMessage, &StubMsg, &StubDesc, 0);
484 StubMsg.BufferLength = 0;
485 NdrSimpleStructBufferSize( &StubMsg, (unsigned char *)memsrc, formattypes );
486 ok(StubMsg.BufferLength >= wiredatalen, "%s: length %d\n", msgpfx, StubMsg.BufferLength);
487 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
488 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
489 ptr = NdrSimpleStructMarshall( &StubMsg, (unsigned char*)memsrc, formattypes );
490 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
491 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart);
492 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));
496 /* FIXME: Causes Wine to crash */
497 StubMsg.Buffer = StubMsg.BufferStart;
498 StubMsg.MemorySize = 0;
499 size = NdrSimpleStructMemorySize( &StubMsg, formattypes );
500 ok(size == StubMsg.MemorySize, "%s: size != MemorySize\n", msgpfx);
501 ok(size == srcsize, "%s: mem size %u\n", msgpfx, size);
502 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart);
504 StubMsg.Buffer = StubMsg.BufferStart;
505 size = NdrSimpleStructMemorySize( &StubMsg, formattypes );
507 ok(size == StubMsg.MemorySize, "%s: size != MemorySize\n", msgpfx);
509 ok(StubMsg.MemorySize == ((srcsize + 3) & ~3) + srcsize, "%s: mem size %u\n", msgpfx, size);
510 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart);
513 /*** Unmarshalling first with must_alloc false ***/
515 StubMsg.Buffer = StubMsg.BufferStart;
516 StubMsg.MemorySize = 0;
517 mem_orig = mem = HeapAlloc(GetProcessHeap(), 0, srcsize);
518 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 0 );
519 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
520 ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart);
521 ok(mem == mem_orig, "%s: mem has changed %p %p\n", msgpfx, mem, mem_orig);
522 ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx);
523 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
525 ok(StubMsg.MemorySize == 0, "%s: memorysize touched in unmarshal\n", msgpfx);
527 /* if we're a server we still use the suppiled memory */
528 StubMsg.Buffer = StubMsg.BufferStart;
529 StubMsg.IsClient = 0;
530 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 0 );
531 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
532 ok(mem == mem_orig, "%s: mem has changed %p %p\n", msgpfx, mem, mem_orig);
533 ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx);
534 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
536 ok(StubMsg.MemorySize == 0, "%s: memorysize touched in unmarshal\n", msgpfx);
538 /* ...unless we pass a NULL ptr, then the buffer is used.
539 Passing a NULL ptr while we're a client && !must_alloc
540 crashes on Windows, so we won't do that. */
543 StubMsg.IsClient = 0;
544 StubMsg.Buffer = StubMsg.BufferStart;
545 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 0 );
546 ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr);
547 ok(mem == StubMsg.BufferStart, "%s: mem not equal buffer\n", msgpfx);
548 ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx);
549 ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
551 ok(StubMsg.MemorySize == 0, "%s: memorysize touched in unmarshal\n", msgpfx);
553 /*** now must_alloc is true ***/
555 /* with must_alloc set we always allocate new memory whether or not we're
556 a server and also when passing NULL */
558 StubMsg.IsClient = 1;
559 StubMsg.Buffer = StubMsg.BufferStart;
560 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 1 );
561 ok(ptr == NULL, "ret %p\n", ptr);
562 ok(mem != mem_orig, "mem not changed %p %p\n", mem, mem_orig);
563 ok(!cmp(mem, memsrc, srcsize), "incorrectly unmarshaled\n");
564 ok(my_alloc_called == num_additional_allocs + 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
566 ok(StubMsg.MemorySize == 0, "memorysize touched in unmarshal\n");
569 StubMsg.Buffer = StubMsg.BufferStart;
570 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 1 );
571 ok(ptr == NULL, "ret %p\n", ptr);
572 ok(mem != mem_orig, "mem not changed %p %p\n", mem, mem_orig);
573 ok(!cmp(mem, memsrc, srcsize), "incorrectly unmarshaled\n");
574 ok(my_alloc_called == num_additional_allocs + 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
576 ok(StubMsg.MemorySize == 0, "memorysize touched in unmarshal\n");
579 StubMsg.Buffer = StubMsg.BufferStart;
580 StubMsg.IsClient = 0;
581 StubMsg.ReuseBuffer = 1;
582 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 1 );
583 ok(ptr == NULL, "ret %p\n", ptr);
584 ok(mem != mem_orig, "mem not changed %p %p\n", mem, mem_orig);
585 ok(mem != StubMsg.BufferStart, "mem is buffer mem\n");
586 ok(!cmp(mem, memsrc, srcsize), "incorrectly unmarshaled\n");
587 ok(my_alloc_called == num_additional_allocs + 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
589 ok(StubMsg.MemorySize == 0, "memorysize touched in unmarshal\n");
592 StubMsg.Buffer = StubMsg.BufferStart;
593 StubMsg.IsClient = 0;
594 StubMsg.ReuseBuffer = 1;
595 ptr = NdrSimpleStructUnmarshall( &StubMsg, &mem, formattypes, 1 );
596 ok(ptr == NULL, "ret %p\n", ptr);
597 ok(mem != StubMsg.BufferStart, "mem is buffer mem\n");
598 ok(!cmp(mem, memsrc, srcsize), "incorrectly unmarshaled\n");
599 ok(my_alloc_called == num_additional_allocs + 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called);
601 ok(StubMsg.MemorySize == 0, "memorysize touched in unmarshal\n");
612 static int ps1_cmp(const void *s1, const void *s2, size_t num)
614 const ps1_t *p1, *p2;
622 if(p1->pl1 && p2->pl1)
624 if(*p1->pl1 != *p2->pl1)
627 else if(p1->pl1 || p1->pl1)
630 if(p1->pc1 && p2->pc1)
632 if(*p1->pc1 != *p2->pc1)
635 else if(p1->pc1 || p1->pc1)
641 static void test_simple_struct(void)
643 unsigned char wiredata[28];
644 unsigned long wiredatalen;
649 static const unsigned char fmtstr_simple_struct[] =
651 0x12, 0x0, /* FC_UP */
652 NdrFcShort( 0x2 ), /* Offset=2 */
653 0x15, 0x3, /* FC_STRUCT [align 4] */
654 NdrFcShort( 0x18 ), /* [size 24] */
657 0x38, /* FC_ALIGNM4 */
660 0x39, /* FC_ALIGNM8 */
671 static const unsigned char fmtstr_pointer_struct[] =
673 0x12, 0x0, /* FC_UP */
674 NdrFcShort( 0x2 ), /* Offset=2 */
675 0x16, 0x3, /* FC_PSTRUCT [align 4] */
676 NdrFcShort( 0xc ), /* [size 12] */
679 0x46, /* FC_NO_REPEAT */
681 NdrFcShort( 0x4 ), /* 4 */
682 NdrFcShort( 0x4 ), /* 4 */
683 0x13, 0x8, /* FC_OP [simple_pointer] */
686 0x46, /* FC_NO_REPEAT */
688 NdrFcShort( 0x8 ), /* 8 */
689 NdrFcShort( 0x8 ), /* 8 */
690 0x13, 0x8, /* FC_OP [simple_pointer] */
707 s1.ll = ((LONGLONG) 0xbadefeed << 32) | 0x2468ace0;
710 memcpy(wiredata, &s1, wiredatalen);
711 test_simple_struct_marshal(fmtstr_simple_struct + 4, &s1, 24, wiredata, 24, NULL, 0, "struct");
713 *(void**)wiredata = &s1;
714 memcpy(wiredata + 4, &s1, wiredatalen);
717 /* one of the unmarshallings crashes Wine */
718 test_pointer_marshal(fmtstr_simple_struct, &s1, 24, wiredata, 28, NULL, 0, "struct");
727 memcpy(wiredata + 4, &ps1, 12);
728 memcpy(wiredata + 16, &l, 4);
729 memcpy(wiredata + 20, &c, 1);
731 test_simple_struct_marshal(fmtstr_pointer_struct + 4, &ps1, 17, wiredata + 4, 17, ps1_cmp, 2, "pointer_struct");
732 *(void**)wiredata = &ps1;
735 /* one of the unmarshallings crashes Wine */
736 test_pointer_marshal(fmtstr_pointer_struct, &ps1, 17, wiredata, 21, ps1_cmp, 2, "pointer_struct");
740 static void test_fullpointer_xlat(void)
742 PFULL_PTR_XLAT_TABLES pXlatTables;
747 pXlatTables = NdrFullPointerXlatInit(2, XLAT_CLIENT);
749 /* "marshaling" phase */
751 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 1, &RefId);
752 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
753 ok(RefId == 0x1, "RefId should be 0x1 instead of 0x%x\n", RefId);
755 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 0, &RefId);
756 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
757 ok(RefId == 0x1, "RefId should be 0x1 instead of 0x%x\n", RefId);
759 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebabe, 0, &RefId);
760 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
761 ok(RefId == 0x2, "RefId should be 0x2 instead of 0x%x\n", RefId);
763 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xdeadbeef, 0, &RefId);
764 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
765 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
767 ret = NdrFullPointerQueryPointer(pXlatTables, NULL, 0, &RefId);
768 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
769 ok(RefId == 0, "RefId should be 0 instead of 0x%x\n", RefId);
771 /* "unmarshaling" phase */
773 ret = NdrFullPointerQueryRefId(pXlatTables, 0x2, 0, &Pointer);
774 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
775 ok(Pointer == (void *)0xcafebabe, "Pointer should be 0xcafebabe instead of %p\n", Pointer);
777 ret = NdrFullPointerQueryRefId(pXlatTables, 0x4, 0, &Pointer);
778 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
779 ok(Pointer == NULL, "Pointer should be NULL instead of %p\n", Pointer);
781 NdrFullPointerInsertRefId(pXlatTables, 0x4, (void *)0xdeadbabe);
783 ret = NdrFullPointerQueryRefId(pXlatTables, 0x4, 1, &Pointer);
784 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
785 ok(Pointer == (void *)0xdeadbabe, "Pointer should be (void *)0xdeadbabe instead of %p\n", Pointer);
787 NdrFullPointerXlatFree(pXlatTables);
789 pXlatTables = NdrFullPointerXlatInit(2, XLAT_SERVER);
791 /* "unmarshaling" phase */
793 ret = NdrFullPointerQueryRefId(pXlatTables, 0x2, 1, &Pointer);
794 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
795 ok(Pointer == NULL, "Pointer should be NULL instead of %p\n", Pointer);
797 NdrFullPointerInsertRefId(pXlatTables, 0x2, (void *)0xcafebabe);
799 ret = NdrFullPointerQueryRefId(pXlatTables, 0x2, 0, &Pointer);
800 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
801 ok(Pointer == (void *)0xcafebabe, "Pointer should be (void *)0xcafebabe instead of %p\n", Pointer);
803 ret = NdrFullPointerQueryRefId(pXlatTables, 0x2, 1, &Pointer);
804 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
805 ok(Pointer == (void *)0xcafebabe, "Pointer should be (void *)0xcafebabe instead of %p\n", Pointer);
807 /* "marshaling" phase */
809 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 1, &RefId);
810 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
811 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
813 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 1, &RefId);
814 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
815 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
817 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 0, &RefId);
818 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
819 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
821 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebabe, 0, &RefId);
822 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
823 ok(RefId == 0x2, "RefId should be 0x2 instead of 0x%x\n", RefId);
825 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xdeadbeef, 0, &RefId);
826 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
827 ok(RefId == 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId);
829 /* "freeing" phase */
831 ret = NdrFullPointerFree(pXlatTables, (void *)0xcafebeef);
832 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
834 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 0x20, &RefId);
835 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
836 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
838 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xcafebeef, 1, &RefId);
839 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
840 ok(RefId == 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId);
842 ret = NdrFullPointerFree(pXlatTables, (void *)0xcafebabe);
843 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
845 ret = NdrFullPointerFree(pXlatTables, (void *)0xdeadbeef);
846 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
848 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xdeadbeef, 0x20, &RefId);
849 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
850 ok(RefId == 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId);
852 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xdeadbeef, 1, &RefId);
853 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
854 ok(RefId == 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId);
856 ret = NdrFullPointerQueryPointer(pXlatTables, (void *)0xdeadbeef, 1, &RefId);
857 ok(ret == 1, "ret should be 1 instead of 0x%x\n", ret);
858 ok(RefId == 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId);
860 ret = NdrFullPointerFree(pXlatTables, (void *)0xdeadbeef);
861 ok(ret == 0, "ret should be 0 instead of 0x%x\n", ret);
863 NdrFullPointerXlatFree(pXlatTables);
866 static void test_client_init(void)
868 MIDL_STUB_MESSAGE stubMsg;
871 memset(&stubMsg, 0xcc, sizeof(stubMsg));
873 NdrClientInitializeNew(&rpcMsg, &stubMsg, &Object_StubDesc, 1);
875 #define TEST_ZERO(field, fmt) ok(stubMsg.field == 0, #field " should have be set to zero instead of " fmt "\n", stubMsg.field)
876 #define TEST_POINTER_UNSET(field) ok(stubMsg.field == (void *)0xcccccccc, #field " should have be unset instead of %p\n", stubMsg.field)
877 #define TEST_ULONG_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have be unset instead of 0x%x\n", stubMsg.field)
878 #define TEST_ULONG_PTR_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have be unset instead of 0x%lx\n", stubMsg.field)
880 ok(stubMsg.RpcMsg == &rpcMsg, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg, stubMsg.RpcMsg);
881 TEST_POINTER_UNSET(Buffer);
882 TEST_ZERO(BufferStart, "%p");
883 TEST_ZERO(BufferEnd, "%p");
884 TEST_POINTER_UNSET(BufferMark);
885 TEST_ZERO(BufferLength, "%d");
886 TEST_ULONG_UNSET(MemorySize);
887 TEST_POINTER_UNSET(Memory);
888 ok(stubMsg.IsClient == 1, "stubMsg.IsClient should have been 1 instead of %u\n", stubMsg.IsClient);
889 TEST_ZERO(ReuseBuffer, "%d");
890 TEST_ZERO(pAllocAllNodesContext, "%p");
891 TEST_ZERO(pPointerQueueState, "%p");
892 TEST_ZERO(IgnoreEmbeddedPointers, "%d");
893 TEST_ZERO(PointerBufferMark, "%p");
894 TEST_ZERO(fBufferValid, "%d");
895 TEST_ZERO(uFlags, "%d");
896 /* FIXME: UniquePtrCount */
897 TEST_ULONG_PTR_UNSET(MaxCount);
898 TEST_ULONG_UNSET(Offset);
899 TEST_ULONG_UNSET(ActualCount);
900 ok(stubMsg.pfnAllocate == my_alloc, "stubMsg.pfnAllocate should have been %p instead of %p\n", my_alloc, stubMsg.pfnAllocate);
901 ok(stubMsg.pfnFree == my_free, "stubMsg.pfnFree should have been %p instead of %p\n", my_free, stubMsg.pfnFree);
902 TEST_ZERO(StackTop, "%p");
903 TEST_POINTER_UNSET(pPresentedType);
904 TEST_POINTER_UNSET(pTransmitType);
905 TEST_POINTER_UNSET(SavedHandle);
906 ok(stubMsg.StubDesc == &Object_StubDesc, "stubMsg.StubDesc should have been %p instead of %p\n", &Object_StubDesc, stubMsg.StubDesc);
907 TEST_POINTER_UNSET(FullPtrXlatTables);
908 TEST_ZERO(FullPtrRefId, "%d");
909 TEST_ZERO(PointerLength, "%d");
910 TEST_ZERO(fInDontFree, "%d");
911 TEST_ZERO(fDontCallFreeInst, "%d");
912 TEST_ZERO(fInOnlyParam, "%d");
913 TEST_ZERO(fHasReturn, "%d");
914 TEST_ZERO(fHasExtensions, "%d");
915 TEST_ZERO(fHasNewCorrDesc, "%d");
916 TEST_ZERO(fUnused, "%d");
917 ok(stubMsg.fUnused2 == 0xffffcccc, "stubMsg.fUnused2 should have been 0xcccc instead of 0x%x\n", stubMsg.fUnused2);
918 ok(stubMsg.dwDestContext == MSHCTX_DIFFERENTMACHINE, "stubMsg.dwDestContext should have been MSHCTX_DIFFERENTMACHINE instead of %d\n", stubMsg.dwDestContext);
919 TEST_ZERO(pvDestContext, "%p");
920 TEST_POINTER_UNSET(SavedContextHandles);
921 TEST_ULONG_UNSET(ParamNumber);
922 TEST_ZERO(pRpcChannelBuffer, "%p");
923 TEST_ZERO(pArrayInfo, "%p");
924 TEST_POINTER_UNSET(SizePtrCountArray);
925 TEST_POINTER_UNSET(SizePtrOffsetArray);
926 TEST_POINTER_UNSET(SizePtrLengthArray);
927 TEST_POINTER_UNSET(pArgQueue);
928 TEST_ZERO(dwStubPhase, "%d");
929 /* FIXME: where does this value come from? */
930 trace("LowStackMark is %p\n", stubMsg.LowStackMark);
931 TEST_ZERO(pAsyncMsg, "%p");
932 TEST_ZERO(pCorrInfo, "%p");
933 TEST_ZERO(pCorrMemory, "%p");
934 TEST_ZERO(pMemoryList, "%p");
935 TEST_POINTER_UNSET(pCSInfo);
936 TEST_POINTER_UNSET(ConformanceMark);
937 TEST_POINTER_UNSET(VarianceMark);
938 ok(stubMsg.Unused == 0xcccccccc, "Unused should have be unset instead of 0x%lx\n", stubMsg.Unused);
939 TEST_POINTER_UNSET(pContext);
940 TEST_POINTER_UNSET(ContextHandleHash);
941 TEST_POINTER_UNSET(pUserMarshalList);
942 TEST_ULONG_PTR_UNSET(Reserved51_3);
943 TEST_ULONG_PTR_UNSET(Reserved51_4);
944 TEST_ULONG_PTR_UNSET(Reserved51_5);
945 #undef TEST_ULONG_UNSET
946 #undef TEST_POINTER_UNSET
951 static void test_ndr_allocate(void)
953 RPC_MESSAGE RpcMessage;
954 MIDL_STUB_MESSAGE StubMsg;
955 MIDL_STUB_DESC StubDesc;
957 struct tag_mem_list_t
961 struct tag_mem_list_t *next;
963 const DWORD magic_MEML = 'M' << 24 | 'E' << 16 | 'M' << 8 | 'L';
965 StubDesc = Object_StubDesc;
966 NdrClientInitializeNew(&RpcMessage, &StubMsg, &StubDesc, 0);
968 ok(StubMsg.pMemoryList == NULL, "memlist %p\n", StubMsg.pMemoryList);
969 my_alloc_called = my_free_called = 0;
970 p1 = NdrAllocate(&StubMsg, 10);
971 p2 = NdrAllocate(&StubMsg, 20);
972 ok(my_alloc_called == 2, "alloc called %d\n", my_alloc_called);
973 mem_list = StubMsg.pMemoryList;
975 ok(mem_list != NULL, "mem_list NULL\n");
979 ok(mem_list->magic == magic_MEML, "magic %08x\n", mem_list->magic);
980 ok(mem_list->ptr == p2, "ptr != p2\n");
981 ok(mem_list->next != NULL, "next NULL\n");
982 mem_list = mem_list->next;
985 ok(mem_list->magic == magic_MEML, "magic %08x\n", mem_list->magic);
986 ok(mem_list->ptr == p1, "ptr != p2\n");
987 ok(mem_list->next == NULL, "next %p\n", mem_list->next);
990 /* NdrFree isn't exported so we can't test free'ing */
993 static void test_conformant_array(void)
995 RPC_MESSAGE RpcMessage;
996 MIDL_STUB_MESSAGE StubMsg;
997 MIDL_STUB_DESC StubDesc;
999 unsigned char *mem, *mem_orig;
1000 unsigned char memsrc[20];
1002 static const unsigned char fmtstr_conf_array[] =
1004 0x1b, /* FC_CARRAY */
1006 NdrFcShort( 0x1 ), /* elem size */
1007 0x40, /* Corr desc: const */
1009 NdrFcShort(0x10), /* const = 0x10 */
1014 StubDesc = Object_StubDesc;
1015 StubDesc.pFormatTypes = fmtstr_conf_array;
1017 NdrClientInitializeNew(
1023 StubMsg.BufferLength = 0;
1024 NdrConformantArrayBufferSize( &StubMsg,
1026 fmtstr_conf_array );
1027 ok(StubMsg.BufferLength >= 20, "length %d\n", StubMsg.BufferLength);
1029 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1030 StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength);
1031 StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength;
1033 ptr = NdrConformantArrayMarshall( &StubMsg, memsrc, fmtstr_conf_array );
1034 ok(ptr == NULL, "ret %p\n", ptr);
1035 ok(StubMsg.Buffer - StubMsg.BufferStart == 20, "Buffer %p Start %p len %d\n", StubMsg.Buffer, StubMsg.BufferStart, 20);
1036 ok(!memcmp(StubMsg.BufferStart + 4, memsrc, 16), "incorrectly marshaled\n");
1038 StubMsg.Buffer = StubMsg.BufferStart;
1039 StubMsg.MemorySize = 0;
1043 my_alloc_called = 0;
1044 /* passing mem == NULL with must_alloc == 0 crashes under Windows */
1045 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1046 ok(mem != NULL, "mem not alloced\n");
1047 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1048 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1050 my_alloc_called = 0;
1051 StubMsg.Buffer = StubMsg.BufferStart;
1053 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 0);
1054 ok(mem == mem_orig, "mem alloced\n");
1055 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1056 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1058 my_alloc_called = 0;
1059 StubMsg.Buffer = StubMsg.BufferStart;
1060 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1061 ok(mem != mem_orig, "mem not alloced\n");
1062 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1063 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1066 StubMsg.Buffer = StubMsg.BufferStart;
1067 NdrConformantArrayFree( &StubMsg, mem, fmtstr_conf_array );
1068 ok(my_free_called == 0, "free called %d\n", my_free_called);
1069 StubMsg.pfnFree(mem);
1072 my_alloc_called = 0;
1073 StubMsg.IsClient = 0;
1075 StubMsg.Buffer = StubMsg.BufferStart;
1076 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 0);
1078 ok(mem == StubMsg.BufferStart + 4, "mem not pointing at buffer\n");
1079 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1081 my_alloc_called = 0;
1083 StubMsg.Buffer = StubMsg.BufferStart;
1084 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1085 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1086 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1087 StubMsg.pfnFree(mem);
1089 my_alloc_called = 0;
1091 StubMsg.Buffer = StubMsg.BufferStart;
1092 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 0);
1093 ok(mem == mem_orig, "mem alloced\n");
1094 ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
1096 my_alloc_called = 0;
1098 StubMsg.Buffer = StubMsg.BufferStart;
1099 NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 1);
1100 ok(mem != StubMsg.BufferStart + 4, "mem pointing at buffer\n");
1101 ok(my_alloc_called == 1, "alloc called %d\n", my_alloc_called);
1102 StubMsg.pfnFree(mem);
1103 StubMsg.pfnFree(mem_orig);
1105 HeapFree(GetProcessHeap(), 0, StubMsg.RpcMsg->Buffer);
1108 START_TEST( ndr_marshall )
1110 test_ndr_simple_type();
1111 test_simple_types();
1112 test_simple_struct();
1113 test_fullpointer_xlat();
1115 test_ndr_allocate();
1116 test_conformant_array();