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
);
253 ok(mem
== StubMsg
.BufferStart
+ wiredatalen
- srcsize
, "%s: mem doesn't point to buffer %p %p\n", msgpfx
, mem
, StubMsg
.BufferStart
);
254 ok(!cmp(mem
, memsrc
, size
), "%s: incorrecly unmarshaled\n", msgpfx
);
255 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
256 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
257 if (formattypes
[2] != 0xd /* FC_ENUM16 */) {
258 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
262 HeapFree(GetProcessHeap(), 0, mem_orig
);
263 HeapFree(GetProcessHeap(), 0, StubMsg
.BufferStart
);
266 static int deref_cmp(const void *s1
, const void *s2
, size_t num
)
268 return memcmp(*(const void *const *)s1
, *(const void *const *)s2
, num
);
272 static void test_simple_types(void)
274 unsigned char wiredata
[16];
276 unsigned char *ch_ptr
;
284 static const unsigned char fmtstr_up_char
[] =
286 0x12, 0x8, /* FC_UP [simple_pointer] */
290 static const unsigned char fmtstr_up_byte
[] =
292 0x12, 0x8, /* FC_UP [simple_pointer] */
296 static const unsigned char fmtstr_up_small
[] =
298 0x12, 0x8, /* FC_UP [simple_pointer] */
302 static const unsigned char fmtstr_up_usmall
[] =
304 0x12, 0x8, /* FC_UP [simple_pointer] */
308 static const unsigned char fmtstr_rp_char
[] =
310 0x11, 0x8, /* FC_RP [simple_pointer] */
314 static const unsigned char fmtstr_rpup_char
[] =
316 0x11, 0x14, /* FC_RP [alloced_on_stack] */
317 NdrFcShort( 0x2 ), /* Offset= 2 (4) */
318 0x12, 0x8, /* FC_UP [simple_pointer] */
322 static const unsigned char fmtstr_rpup_char2
[] =
324 0x11, 0x04, /* FC_RP [alloced_on_stack] */
325 NdrFcShort( 0x2 ), /* Offset= 2 (4) */
326 0x12, 0x8, /* FC_UP [simple_pointer] */
331 static const unsigned char fmtstr_up_wchar
[] =
333 0x12, 0x8, /* FC_UP [simple_pointer] */
337 static const unsigned char fmtstr_up_short
[] =
339 0x12, 0x8, /* FC_UP [simple_pointer] */
343 static const unsigned char fmtstr_up_ushort
[] =
345 0x12, 0x8, /* FC_UP [simple_pointer] */
349 static const unsigned char fmtstr_up_enum16
[] =
351 0x12, 0x8, /* FC_UP [simple_pointer] */
355 static const unsigned char fmtstr_up_long
[] =
357 0x12, 0x8, /* FC_UP [simple_pointer] */
361 static const unsigned char fmtstr_up_ulong
[] =
363 0x12, 0x8, /* FC_UP [simple_pointer] */
367 static const unsigned char fmtstr_up_enum32
[] =
369 0x12, 0x8, /* FC_UP [simple_pointer] */
373 static const unsigned char fmtstr_up_errorstatus
[] =
375 0x12, 0x8, /* FC_UP [simple_pointer] */
376 0x10, /* FC_ERROR_STATUS_T */
380 static const unsigned char fmtstr_up_longlong
[] =
382 0x12, 0x8, /* FC_UP [simple_pointer] */
386 static const unsigned char fmtstr_up_float
[] =
388 0x12, 0x8, /* FC_UP [simple_pointer] */
392 static const unsigned char fmtstr_up_double
[] =
394 0x12, 0x8, /* FC_UP [simple_pointer] */
401 *(void**)wiredata
= ch_ptr
;
402 wiredata
[sizeof(void*)] = ch
;
404 test_pointer_marshal(fmtstr_up_char
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_char");
405 test_pointer_marshal(fmtstr_up_byte
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_byte");
406 test_pointer_marshal(fmtstr_up_small
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_small");
407 test_pointer_marshal(fmtstr_up_usmall
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_usmall");
409 test_pointer_marshal(fmtstr_rp_char
, ch_ptr
, 1, &ch
, 1, NULL
, 0, "rp_char");
411 test_pointer_marshal(fmtstr_rpup_char
, &ch_ptr
, 1, wiredata
, 5, deref_cmp
, 1, "rpup_char");
412 test_pointer_marshal(fmtstr_rpup_char2
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "rpup_char2");
415 *(void**)wiredata
= &s
;
416 *(unsigned short*)(wiredata
+ sizeof(void*)) = s
;
418 test_pointer_marshal(fmtstr_up_wchar
, &s
, 2, wiredata
, 6, NULL
, 0, "up_wchar");
419 test_pointer_marshal(fmtstr_up_short
, &s
, 2, wiredata
, 6, NULL
, 0, "up_short");
420 test_pointer_marshal(fmtstr_up_ushort
, &s
, 2, wiredata
, 6, NULL
, 0, "up_ushort");
423 *(void**)wiredata
= &i
;
424 *(unsigned short*)(wiredata
+ sizeof(void*)) = i
;
425 test_pointer_marshal(fmtstr_up_enum16
, &i
, 2, wiredata
, 6, NULL
, 0, "up_enum16");
428 *(void**)wiredata
= &l
;
429 *(unsigned long*)(wiredata
+ sizeof(void*)) = l
;
431 test_pointer_marshal(fmtstr_up_long
, &l
, 4, wiredata
, 8, NULL
, 0, "up_long");
432 test_pointer_marshal(fmtstr_up_ulong
, &l
, 4, wiredata
, 8, NULL
, 0, "up_ulong");
433 test_pointer_marshal(fmtstr_up_enum32
, &l
, 4, wiredata
, 8, NULL
, 0, "up_emun32");
434 test_pointer_marshal(fmtstr_up_errorstatus
, &l
, 4, wiredata
, 8, NULL
, 0, "up_errorstatus");
436 ll
= ((ULONGLONG
)0xcafebabe) << 32 | 0xdeadbeef;
437 *(void**)wiredata
= &ll
;
438 *(void**)(wiredata
+ sizeof(void*)) = NULL
;
439 *(ULONGLONG
*)(wiredata
+ 2 * sizeof(void*)) = ll
;
440 test_pointer_marshal(fmtstr_up_longlong
, &ll
, 8, wiredata
, 16, NULL
, 0, "up_longlong");
443 *(void**)wiredata
= &f
;
444 *(float*)(wiredata
+ sizeof(void*)) = f
;
445 test_pointer_marshal(fmtstr_up_float
, &f
, 4, wiredata
, 8, NULL
, 0, "up_float");
448 *(void**)wiredata
= &d
;
449 *(void**)(wiredata
+ sizeof(void*)) = NULL
;
450 *(double*)(wiredata
+ 2 * sizeof(void*)) = d
;
451 test_pointer_marshal(fmtstr_up_double
, &d
, 8, wiredata
, 16, NULL
, 0, "up_double");
455 static void test_simple_struct_marshal(const unsigned char *formattypes
,
458 const void *wiredata
,
460 int(*cmp
)(const void*,const void*,size_t),
461 long num_additional_allocs
,
464 RPC_MESSAGE RpcMessage
;
465 MIDL_STUB_MESSAGE StubMsg
;
466 MIDL_STUB_DESC StubDesc
;
469 unsigned char *mem
, *mem_orig
;
471 my_alloc_called
= my_free_called
= 0;
475 StubDesc
= Object_StubDesc
;
476 StubDesc
.pFormatTypes
= formattypes
;
478 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &StubDesc
, 0);
480 StubMsg
.BufferLength
= 0;
481 NdrSimpleStructBufferSize( &StubMsg
, (unsigned char *)memsrc
, formattypes
);
482 ok(StubMsg
.BufferLength
>= wiredatalen
, "%s: length %d\n", msgpfx
, StubMsg
.BufferLength
);
483 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
484 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
485 ptr
= NdrSimpleStructMarshall( &StubMsg
, (unsigned char*)memsrc
, formattypes
);
486 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
487 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
488 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));
492 /* FIXME: Causes Wine to crash */
493 StubMsg
.Buffer
= StubMsg
.BufferStart
;
494 StubMsg
.MemorySize
= 0;
495 size
= NdrSimpleStructMemorySize( &StubMsg
, formattypes
);
496 ok(size
== StubMsg
.MemorySize
, "%s: size != MemorySize\n", msgpfx
);
497 ok(size
== srcsize
, "%s: mem size %u\n", msgpfx
, size
);
498 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
500 StubMsg
.Buffer
= StubMsg
.BufferStart
;
501 size
= NdrSimpleStructMemorySize( &StubMsg
, formattypes
);
503 ok(size
== StubMsg
.MemorySize
, "%s: size != MemorySize\n", msgpfx
);
505 ok(StubMsg
.MemorySize
== ((srcsize
+ 3) & ~3) + srcsize
, "%s: mem size %u\n", msgpfx
, size
);
506 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
509 /*** Unmarshalling first with must_alloc false ***/
511 StubMsg
.Buffer
= StubMsg
.BufferStart
;
512 StubMsg
.MemorySize
= 0;
513 mem_orig
= mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, srcsize
);
514 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
515 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
516 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
517 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
518 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
519 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
521 ok(StubMsg
.MemorySize
== 0, "%s: memorysize touched in unmarshal\n", msgpfx
);
523 /* if we're a server we still use the suppiled memory */
524 StubMsg
.Buffer
= StubMsg
.BufferStart
;
525 StubMsg
.IsClient
= 0;
526 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
527 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
528 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
529 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
530 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
532 ok(StubMsg
.MemorySize
== 0, "%s: memorysize touched in unmarshal\n", msgpfx
);
534 /* ...unless we pass a NULL ptr, then the buffer is used.
535 Passing a NULL ptr while we're a client && !must_alloc
536 crashes on Windows, so we won't do that. */
539 StubMsg
.IsClient
= 0;
540 StubMsg
.Buffer
= StubMsg
.BufferStart
;
541 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
542 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
543 ok(mem
== StubMsg
.BufferStart
, "%s: mem not equal buffer\n", msgpfx
);
544 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
545 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
547 ok(StubMsg
.MemorySize
== 0, "%s: memorysize touched in unmarshal\n", msgpfx
);
549 /*** now must_alloc is true ***/
551 /* with must_alloc set we always allocate new memory whether or not we're
552 a server and also when passing NULL */
554 StubMsg
.IsClient
= 1;
555 StubMsg
.Buffer
= StubMsg
.BufferStart
;
556 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
557 ok(ptr
== NULL
, "ret %p\n", ptr
);
558 ok(mem
!= mem_orig
, "mem not changed %p %p\n", mem
, mem_orig
);
559 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
560 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
562 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
565 StubMsg
.Buffer
= StubMsg
.BufferStart
;
566 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
567 ok(ptr
== NULL
, "ret %p\n", ptr
);
568 ok(mem
!= mem_orig
, "mem not changed %p %p\n", mem
, mem_orig
);
569 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
570 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
572 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
575 StubMsg
.Buffer
= StubMsg
.BufferStart
;
576 StubMsg
.IsClient
= 0;
577 StubMsg
.ReuseBuffer
= 1;
578 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
579 ok(ptr
== NULL
, "ret %p\n", ptr
);
580 ok(mem
!= mem_orig
, "mem not changed %p %p\n", mem
, mem_orig
);
581 ok(mem
!= StubMsg
.BufferStart
, "mem is buffer mem\n");
582 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
583 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
585 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
588 StubMsg
.Buffer
= StubMsg
.BufferStart
;
589 StubMsg
.IsClient
= 0;
590 StubMsg
.ReuseBuffer
= 1;
591 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
592 ok(ptr
== NULL
, "ret %p\n", ptr
);
593 ok(mem
!= StubMsg
.BufferStart
, "mem is buffer mem\n");
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");
599 HeapFree(GetProcessHeap(), 0, mem_orig
);
600 HeapFree(GetProcessHeap(), 0, StubMsg
.BufferStart
);
610 static int ps1_cmp(const void *s1
, const void *s2
, size_t num
)
612 const ps1_t
*p1
, *p2
;
620 if(p1
->pl1
&& p2
->pl1
)
622 if(*p1
->pl1
!= *p2
->pl1
)
625 else if(p1
->pl1
|| p1
->pl1
)
628 if(p1
->pc1
&& p2
->pc1
)
630 if(*p1
->pc1
!= *p2
->pc1
)
633 else if(p1
->pc1
|| p1
->pc1
)
639 static void test_simple_struct(void)
641 unsigned char wiredata
[28];
642 unsigned long wiredatalen
;
647 static const unsigned char fmtstr_simple_struct
[] =
649 0x12, 0x0, /* FC_UP */
650 NdrFcShort( 0x2 ), /* Offset=2 */
651 0x15, 0x3, /* FC_STRUCT [align 4] */
652 NdrFcShort( 0x18 ), /* [size 24] */
655 0x38, /* FC_ALIGNM4 */
658 0x39, /* FC_ALIGNM8 */
669 static const unsigned char fmtstr_pointer_struct
[] =
671 0x12, 0x0, /* FC_UP */
672 NdrFcShort( 0x2 ), /* Offset=2 */
673 0x16, 0x3, /* FC_PSTRUCT [align 4] */
674 NdrFcShort( 0xc ), /* [size 12] */
677 0x46, /* FC_NO_REPEAT */
679 NdrFcShort( 0x4 ), /* 4 */
680 NdrFcShort( 0x4 ), /* 4 */
681 0x13, 0x8, /* FC_OP [simple_pointer] */
684 0x46, /* FC_NO_REPEAT */
686 NdrFcShort( 0x8 ), /* 8 */
687 NdrFcShort( 0x8 ), /* 8 */
688 0x13, 0x8, /* FC_OP [simple_pointer] */
705 s1
.ll
= ((LONGLONG
) 0xbadefeed << 32) | 0x2468ace0;
708 memcpy(wiredata
, &s1
, wiredatalen
);
709 test_simple_struct_marshal(fmtstr_simple_struct
+ 4, &s1
, 24, wiredata
, 24, NULL
, 0, "struct");
711 *(void**)wiredata
= &s1
;
712 memcpy(wiredata
+ 4, &s1
, wiredatalen
);
715 /* one of the unmarshallings crashes Wine */
716 test_pointer_marshal(fmtstr_simple_struct
, &s1
, 24, wiredata
, 28, NULL
, 0, "struct");
725 memcpy(wiredata
+ 4, &ps1
, 12);
726 memcpy(wiredata
+ 16, &l
, 4);
727 memcpy(wiredata
+ 20, &c
, 1);
729 test_simple_struct_marshal(fmtstr_pointer_struct
+ 4, &ps1
, 17, wiredata
+ 4, 17, ps1_cmp
, 2, "pointer_struct");
730 *(void**)wiredata
= &ps1
;
733 /* one of the unmarshallings crashes Wine */
734 test_pointer_marshal(fmtstr_pointer_struct
, &ps1
, 17, wiredata
, 21, ps1_cmp
, 2, "pointer_struct");
738 static void test_fullpointer_xlat(void)
740 PFULL_PTR_XLAT_TABLES pXlatTables
;
745 pXlatTables
= NdrFullPointerXlatInit(2, XLAT_CLIENT
);
747 /* "marshaling" phase */
749 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
750 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
751 ok(RefId
== 0x1, "RefId should be 0x1 instead of 0x%x\n", RefId
);
753 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 0, &RefId
);
754 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
755 ok(RefId
== 0x1, "RefId should be 0x1 instead of 0x%x\n", RefId
);
757 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebabe, 0, &RefId
);
758 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
759 ok(RefId
== 0x2, "RefId should be 0x2 instead of 0x%x\n", RefId
);
761 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 0, &RefId
);
762 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
763 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
765 ret
= NdrFullPointerQueryPointer(pXlatTables
, NULL
, 0, &RefId
);
766 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
767 ok(RefId
== 0, "RefId should be 0 instead of 0x%x\n", RefId
);
769 /* "unmarshaling" phase */
771 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 0, &Pointer
);
772 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
773 ok(Pointer
== (void *)0xcafebabe, "Pointer should be 0xcafebabe instead of %p\n", Pointer
);
775 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x4, 0, &Pointer
);
776 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
777 ok(Pointer
== NULL
, "Pointer should be NULL instead of %p\n", Pointer
);
779 NdrFullPointerInsertRefId(pXlatTables
, 0x4, (void *)0xdeadbabe);
781 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x4, 1, &Pointer
);
782 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
783 ok(Pointer
== (void *)0xdeadbabe, "Pointer should be (void *)0xdeadbabe instead of %p\n", Pointer
);
785 NdrFullPointerXlatFree(pXlatTables
);
787 pXlatTables
= NdrFullPointerXlatInit(2, XLAT_SERVER
);
789 /* "unmarshaling" phase */
791 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 1, &Pointer
);
792 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
793 ok(Pointer
== NULL
, "Pointer should be NULL instead of %p\n", Pointer
);
795 NdrFullPointerInsertRefId(pXlatTables
, 0x2, (void *)0xcafebabe);
797 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 0, &Pointer
);
798 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
799 ok(Pointer
== (void *)0xcafebabe, "Pointer should be (void *)0xcafebabe instead of %p\n", Pointer
);
801 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 1, &Pointer
);
802 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
803 ok(Pointer
== (void *)0xcafebabe, "Pointer should be (void *)0xcafebabe instead of %p\n", Pointer
);
805 /* "marshaling" phase */
807 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
808 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
809 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
811 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
812 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
813 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
815 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 0, &RefId
);
816 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
817 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
819 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebabe, 0, &RefId
);
820 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
821 ok(RefId
== 0x2, "RefId should be 0x2 instead of 0x%x\n", RefId
);
823 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 0, &RefId
);
824 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
825 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
827 /* "freeing" phase */
829 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xcafebeef);
830 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
832 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 0x20, &RefId
);
833 ok(ret
== 1, "ret should be 1 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
= NdrFullPointerFree(pXlatTables
, (void *)0xcafebabe);
841 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
843 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xdeadbeef);
844 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
846 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 0x20, &RefId
);
847 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
848 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
850 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 1, &RefId
);
851 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
852 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
854 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 1, &RefId
);
855 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
856 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
858 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xdeadbeef);
859 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
861 NdrFullPointerXlatFree(pXlatTables
);
864 static void test_client_init(void)
866 MIDL_STUB_MESSAGE stubMsg
;
869 memset(&rpcMsg
, 0, sizeof(rpcMsg
));
870 memset(&stubMsg
, 0xcc, sizeof(stubMsg
));
872 NdrClientInitializeNew(&rpcMsg
, &stubMsg
, &Object_StubDesc
, 1);
874 #define TEST_ZERO(field, fmt) ok(stubMsg.field == 0, #field " should have been set to zero instead of " fmt "\n", stubMsg.field)
875 #define TEST_POINTER_UNSET(field) ok(stubMsg.field == (void *)0xcccccccc, #field " should have been unset instead of %p\n", stubMsg.field)
876 #define TEST_ULONG_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%x\n", stubMsg.field)
877 #define TEST_ULONG_PTR_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%lx\n", stubMsg.field)
879 ok(stubMsg
.RpcMsg
== &rpcMsg
, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg
, stubMsg
.RpcMsg
);
880 TEST_POINTER_UNSET(Buffer
);
881 TEST_ZERO(BufferStart
, "%p");
882 TEST_ZERO(BufferEnd
, "%p");
883 TEST_POINTER_UNSET(BufferMark
);
884 TEST_ZERO(BufferLength
, "%d");
885 TEST_ULONG_UNSET(MemorySize
);
886 TEST_POINTER_UNSET(Memory
);
887 ok(stubMsg
.IsClient
== 1, "stubMsg.IsClient should have been 1 instead of %u\n", stubMsg
.IsClient
);
888 TEST_ZERO(ReuseBuffer
, "%d");
889 TEST_ZERO(pAllocAllNodesContext
, "%p");
890 TEST_ZERO(pPointerQueueState
, "%p");
891 TEST_ZERO(IgnoreEmbeddedPointers
, "%d");
892 TEST_ZERO(PointerBufferMark
, "%p");
893 TEST_ZERO(fBufferValid
, "%d");
894 TEST_ZERO(uFlags
, "%d");
895 /* FIXME: UniquePtrCount */
896 TEST_ULONG_PTR_UNSET(MaxCount
);
897 TEST_ULONG_UNSET(Offset
);
898 TEST_ULONG_UNSET(ActualCount
);
899 ok(stubMsg
.pfnAllocate
== my_alloc
, "stubMsg.pfnAllocate should have been %p instead of %p\n", my_alloc
, stubMsg
.pfnAllocate
);
900 ok(stubMsg
.pfnFree
== my_free
, "stubMsg.pfnFree should have been %p instead of %p\n", my_free
, stubMsg
.pfnFree
);
901 TEST_ZERO(StackTop
, "%p");
902 TEST_POINTER_UNSET(pPresentedType
);
903 TEST_POINTER_UNSET(pTransmitType
);
904 TEST_POINTER_UNSET(SavedHandle
);
905 ok(stubMsg
.StubDesc
== &Object_StubDesc
, "stubMsg.StubDesc should have been %p instead of %p\n", &Object_StubDesc
, stubMsg
.StubDesc
);
906 TEST_POINTER_UNSET(FullPtrXlatTables
);
907 TEST_ZERO(FullPtrRefId
, "%d");
908 TEST_ZERO(PointerLength
, "%d");
909 TEST_ZERO(fInDontFree
, "%d");
910 TEST_ZERO(fDontCallFreeInst
, "%d");
911 TEST_ZERO(fInOnlyParam
, "%d");
912 TEST_ZERO(fHasReturn
, "%d");
913 TEST_ZERO(fHasExtensions
, "%d");
914 TEST_ZERO(fHasNewCorrDesc
, "%d");
915 TEST_ZERO(fUnused
, "%d");
916 ok(stubMsg
.fUnused2
== 0xffffcccc, "stubMsg.fUnused2 should have been 0xcccc instead of 0x%x\n", stubMsg
.fUnused2
);
917 ok(stubMsg
.dwDestContext
== MSHCTX_DIFFERENTMACHINE
, "stubMsg.dwDestContext should have been MSHCTX_DIFFERENTMACHINE instead of %d\n", stubMsg
.dwDestContext
);
918 TEST_ZERO(pvDestContext
, "%p");
919 TEST_POINTER_UNSET(SavedContextHandles
);
920 TEST_ULONG_UNSET(ParamNumber
);
921 TEST_ZERO(pRpcChannelBuffer
, "%p");
922 TEST_ZERO(pArrayInfo
, "%p");
923 TEST_POINTER_UNSET(SizePtrCountArray
);
924 TEST_POINTER_UNSET(SizePtrOffsetArray
);
925 TEST_POINTER_UNSET(SizePtrLengthArray
);
926 TEST_POINTER_UNSET(pArgQueue
);
927 TEST_ZERO(dwStubPhase
, "%d");
928 /* FIXME: where does this value come from? */
929 trace("LowStackMark is %p\n", stubMsg
.LowStackMark
);
930 TEST_ZERO(pAsyncMsg
, "%p");
931 TEST_ZERO(pCorrInfo
, "%p");
932 TEST_ZERO(pCorrMemory
, "%p");
933 TEST_ZERO(pMemoryList
, "%p");
934 TEST_POINTER_UNSET(pCSInfo
);
935 TEST_POINTER_UNSET(ConformanceMark
);
936 TEST_POINTER_UNSET(VarianceMark
);
937 ok(stubMsg
.Unused
== 0xcccccccc, "Unused should have be unset instead of 0x%lx\n", stubMsg
.Unused
);
938 TEST_POINTER_UNSET(pContext
);
939 TEST_POINTER_UNSET(ContextHandleHash
);
940 TEST_POINTER_UNSET(pUserMarshalList
);
941 TEST_ULONG_PTR_UNSET(Reserved51_3
);
942 TEST_ULONG_PTR_UNSET(Reserved51_4
);
943 TEST_ULONG_PTR_UNSET(Reserved51_5
);
944 #undef TEST_ULONG_UNSET
945 #undef TEST_POINTER_UNSET
950 static void test_server_init(void)
952 MIDL_STUB_MESSAGE stubMsg
;
955 unsigned char buffer
[256];
957 memset(&rpcMsg
, 0, sizeof(rpcMsg
));
958 rpcMsg
.Buffer
= buffer
;
959 rpcMsg
.BufferLength
= sizeof(buffer
);
960 rpcMsg
.RpcFlags
= RPC_BUFFER_COMPLETE
;
962 memset(&stubMsg
, 0xcc, sizeof(stubMsg
));
964 ret
= NdrServerInitializeNew(&rpcMsg
, &stubMsg
, &Object_StubDesc
);
965 ok(ret
== NULL
, "NdrServerInitializeNew should have returned NULL instead of %p\n", ret
);
967 #define TEST_ZERO(field, fmt) ok(stubMsg.field == 0, #field " should have been set to zero instead of " fmt "\n", stubMsg.field)
968 #define TEST_POINTER_UNSET(field) ok(stubMsg.field == (void *)0xcccccccc, #field " should have been unset instead of %p\n", stubMsg.field)
969 #define TEST_ULONG_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%x\n", stubMsg.field)
970 #define TEST_ULONG_PTR_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%lx\n", stubMsg.field)
972 ok(stubMsg
.RpcMsg
== &rpcMsg
, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg
, stubMsg
.RpcMsg
);
973 ok(stubMsg
.Buffer
== buffer
, "stubMsg.Buffer should have been %p instead of %p\n", buffer
, stubMsg
.Buffer
);
974 ok(stubMsg
.BufferStart
== buffer
, "stubMsg.BufferStart should have been %p instead of %p\n", buffer
, stubMsg
.BufferStart
);
975 ok(stubMsg
.BufferEnd
== buffer
+ sizeof(buffer
), "stubMsg.BufferEnd should have been %p instead of %p\n", buffer
+ sizeof(buffer
), stubMsg
.BufferEnd
);
976 TEST_POINTER_UNSET(BufferMark
);
978 TEST_ZERO(BufferLength
, "%d");
979 TEST_ULONG_UNSET(MemorySize
);
980 TEST_POINTER_UNSET(Memory
);
981 ok(stubMsg
.IsClient
== 0, "stubMsg.IsClient should have been 0 instead of %u\n", stubMsg
.IsClient
);
982 TEST_ZERO(ReuseBuffer
, "%d");
983 TEST_ZERO(pAllocAllNodesContext
, "%p");
984 TEST_ZERO(pPointerQueueState
, "%p");
985 TEST_ZERO(IgnoreEmbeddedPointers
, "%d");
986 TEST_ZERO(PointerBufferMark
, "%p");
987 ok(stubMsg
.fBufferValid
== 0xcc, "fBufferValid should have been unset instead of 0x%x\n", stubMsg
.fBufferValid
);
988 TEST_ZERO(uFlags
, "%d");
989 /* FIXME: UniquePtrCount */
990 TEST_ULONG_PTR_UNSET(MaxCount
);
991 TEST_ULONG_UNSET(Offset
);
992 TEST_ULONG_UNSET(ActualCount
);
993 ok(stubMsg
.pfnAllocate
== my_alloc
, "stubMsg.pfnAllocate should have been %p instead of %p\n", my_alloc
, stubMsg
.pfnAllocate
);
994 ok(stubMsg
.pfnFree
== my_free
, "stubMsg.pfnFree should have been %p instead of %p\n", my_free
, stubMsg
.pfnFree
);
995 TEST_ZERO(StackTop
, "%p");
996 TEST_POINTER_UNSET(pPresentedType
);
997 TEST_POINTER_UNSET(pTransmitType
);
998 TEST_POINTER_UNSET(SavedHandle
);
999 ok(stubMsg
.StubDesc
== &Object_StubDesc
, "stubMsg.StubDesc should have been %p instead of %p\n", &Object_StubDesc
, stubMsg
.StubDesc
);
1000 TEST_ZERO(FullPtrXlatTables
, "%p");
1001 TEST_ZERO(FullPtrRefId
, "%d");
1002 TEST_ZERO(PointerLength
, "%d");
1003 TEST_ZERO(fInDontFree
, "%d");
1004 TEST_ZERO(fDontCallFreeInst
, "%d");
1005 TEST_ZERO(fInOnlyParam
, "%d");
1006 TEST_ZERO(fHasReturn
, "%d");
1007 TEST_ZERO(fHasExtensions
, "%d");
1008 TEST_ZERO(fHasNewCorrDesc
, "%d");
1009 TEST_ZERO(fUnused
, "%d");
1010 ok(stubMsg
.fUnused2
== 0xffffcccc, "stubMsg.fUnused2 should have been 0xcccc instead of 0x%x\n", stubMsg
.fUnused2
);
1011 ok(stubMsg
.dwDestContext
== MSHCTX_DIFFERENTMACHINE
, "stubMsg.dwDestContext should have been MSHCTX_DIFFERENTMACHINE instead of %d\n", stubMsg
.dwDestContext
);
1012 TEST_ZERO(pvDestContext
, "%p");
1013 TEST_POINTER_UNSET(SavedContextHandles
);
1014 TEST_ULONG_UNSET(ParamNumber
);
1015 TEST_ZERO(pRpcChannelBuffer
, "%p");
1016 TEST_ZERO(pArrayInfo
, "%p");
1017 TEST_POINTER_UNSET(SizePtrCountArray
);
1018 TEST_POINTER_UNSET(SizePtrOffsetArray
);
1019 TEST_POINTER_UNSET(SizePtrLengthArray
);
1020 TEST_POINTER_UNSET(pArgQueue
);
1021 TEST_ZERO(dwStubPhase
, "%d");
1022 /* FIXME: where does this value come from? */
1023 trace("LowStackMark is %p\n", stubMsg
.LowStackMark
);
1024 TEST_ZERO(pAsyncMsg
, "%p");
1025 TEST_ZERO(pCorrInfo
, "%p");
1026 TEST_ZERO(pCorrMemory
, "%p");
1027 TEST_ZERO(pMemoryList
, "%p");
1028 TEST_POINTER_UNSET(pCSInfo
);
1029 TEST_POINTER_UNSET(ConformanceMark
);
1030 TEST_POINTER_UNSET(VarianceMark
);
1031 ok(stubMsg
.Unused
== 0xcccccccc, "Unused should have be unset instead of 0x%lx\n", stubMsg
.Unused
);
1032 TEST_POINTER_UNSET(pContext
);
1033 TEST_POINTER_UNSET(ContextHandleHash
);
1034 TEST_POINTER_UNSET(pUserMarshalList
);
1035 TEST_ULONG_PTR_UNSET(Reserved51_3
);
1036 TEST_ULONG_PTR_UNSET(Reserved51_4
);
1037 TEST_ULONG_PTR_UNSET(Reserved51_5
);
1038 #undef TEST_ULONG_UNSET
1039 #undef TEST_POINTER_UNSET
1044 static void test_ndr_allocate(void)
1046 RPC_MESSAGE RpcMessage
;
1047 MIDL_STUB_MESSAGE StubMsg
;
1048 MIDL_STUB_DESC StubDesc
;
1050 struct tag_mem_list_v1_t
1054 struct tag_mem_list_v1_t
*next
;
1056 struct tag_mem_list_v2_t
1061 struct tag_mem_list_v2_t
*next
;
1063 const DWORD magic_MEML
= 'M' << 24 | 'E' << 16 | 'M' << 8 | 'L';
1065 StubDesc
= Object_StubDesc
;
1066 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &StubDesc
, 0);
1068 ok(StubMsg
.pMemoryList
== NULL
, "memlist %p\n", StubMsg
.pMemoryList
);
1069 my_alloc_called
= my_free_called
= 0;
1070 p1
= NdrAllocate(&StubMsg
, 10);
1071 p2
= NdrAllocate(&StubMsg
, 24);
1072 ok(my_alloc_called
== 2, "alloc called %d\n", my_alloc_called
);
1073 ok(StubMsg
.pMemoryList
!= NULL
, "StubMsg.pMemoryList NULL\n");
1074 if(StubMsg
.pMemoryList
)
1076 mem_list_v2
= StubMsg
.pMemoryList
;
1077 if (mem_list_v2
->size
== 24)
1079 trace("v2 mem list format\n");
1080 ok((char *)mem_list_v2
== (char *)p2
+ 24, "expected mem_list_v2 pointer %p, but got %p\n", (char *)p2
+ 24, mem_list_v2
);
1081 ok(mem_list_v2
->magic
== magic_MEML
, "magic %08x\n", mem_list_v2
->magic
);
1082 ok(mem_list_v2
->size
== 24, "wrong size for p2 %d\n", mem_list_v2
->size
);
1083 ok(mem_list_v2
->unknown
== 0, "wrong unknown for p2 0x%x\n", mem_list_v2
->unknown
);
1084 ok(mem_list_v2
->next
!= NULL
, "next NULL\n");
1085 mem_list_v2
= mem_list_v2
->next
;
1088 ok((char *)mem_list_v2
== (char *)p1
+ 16, "expected mem_list_v2 pointer %p, but got %p\n", (char *)p1
+ 16, mem_list_v2
);
1089 ok(mem_list_v2
->magic
== magic_MEML
, "magic %08x\n", mem_list_v2
->magic
);
1090 ok(mem_list_v2
->size
== 16, "wrong size for p1 %d\n", mem_list_v2
->size
);
1091 ok(mem_list_v2
->unknown
== 0, "wrong unknown for p1 0x%x\n", mem_list_v2
->unknown
);
1092 ok(mem_list_v2
->next
== NULL
, "next %p\n", mem_list_v2
->next
);
1097 trace("v1 mem list format\n");
1098 mem_list_v1
= StubMsg
.pMemoryList
;
1099 ok(mem_list_v1
->magic
== magic_MEML
, "magic %08x\n", mem_list_v1
->magic
);
1100 ok(mem_list_v1
->ptr
== p2
, "ptr != p2\n");
1101 ok(mem_list_v1
->next
!= NULL
, "next NULL\n");
1102 mem_list_v1
= mem_list_v1
->next
;
1105 ok(mem_list_v1
->magic
== magic_MEML
, "magic %08x\n", mem_list_v1
->magic
);
1106 ok(mem_list_v1
->ptr
== p1
, "ptr != p1\n");
1107 ok(mem_list_v1
->next
== NULL
, "next %p\n", mem_list_v1
->next
);
1111 /* NdrFree isn't exported so we can't test free'ing */
1114 static void test_conformant_array(void)
1116 RPC_MESSAGE RpcMessage
;
1117 MIDL_STUB_MESSAGE StubMsg
;
1118 MIDL_STUB_DESC StubDesc
;
1120 unsigned char *mem
, *mem_orig
;
1121 unsigned char memsrc
[20];
1123 static const unsigned char fmtstr_conf_array
[] =
1125 0x1b, /* FC_CARRAY */
1127 NdrFcShort( 0x1 ), /* elem size */
1128 0x40, /* Corr desc: const */
1130 NdrFcShort(0x10), /* const = 0x10 */
1135 StubDesc
= Object_StubDesc
;
1136 StubDesc
.pFormatTypes
= fmtstr_conf_array
;
1138 NdrClientInitializeNew(
1144 StubMsg
.BufferLength
= 0;
1145 NdrConformantArrayBufferSize( &StubMsg
,
1147 fmtstr_conf_array
);
1148 ok(StubMsg
.BufferLength
>= 20, "length %d\n", StubMsg
.BufferLength
);
1150 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1151 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1152 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1154 ptr
= NdrConformantArrayMarshall( &StubMsg
, memsrc
, fmtstr_conf_array
);
1155 ok(ptr
== NULL
, "ret %p\n", ptr
);
1156 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== 20, "Buffer %p Start %p len %d\n", StubMsg
.Buffer
, StubMsg
.BufferStart
, 20);
1157 ok(!memcmp(StubMsg
.BufferStart
+ 4, memsrc
, 16), "incorrectly marshaled\n");
1159 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1160 StubMsg
.MemorySize
= 0;
1164 my_alloc_called
= 0;
1165 /* passing mem == NULL with must_alloc == 0 crashes under Windows */
1166 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1167 ok(mem
!= NULL
, "mem not alloced\n");
1168 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1169 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1171 my_alloc_called
= 0;
1172 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1174 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 0);
1175 ok(mem
== mem_orig
, "mem alloced\n");
1176 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1177 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1179 my_alloc_called
= 0;
1180 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1181 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1182 ok(mem
!= mem_orig
, "mem not alloced\n");
1183 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1184 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1187 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1188 NdrConformantArrayFree( &StubMsg
, mem
, fmtstr_conf_array
);
1189 ok(my_free_called
== 0, "free called %d\n", my_free_called
);
1190 StubMsg
.pfnFree(mem
);
1193 my_alloc_called
= 0;
1194 StubMsg
.IsClient
= 0;
1196 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1197 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 0);
1198 ok(mem
== StubMsg
.BufferStart
+ 4, "mem not pointing at buffer\n");
1199 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1200 my_alloc_called
= 0;
1202 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1203 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1204 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1205 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1206 StubMsg
.pfnFree(mem
);
1208 my_alloc_called
= 0;
1210 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1211 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 0);
1212 ok(mem
== mem_orig
, "mem alloced\n");
1213 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1215 my_alloc_called
= 0;
1217 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1218 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1219 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1220 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1221 StubMsg
.pfnFree(mem
);
1222 StubMsg
.pfnFree(mem_orig
);
1224 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1227 static void test_conformant_string(void)
1229 RPC_MESSAGE RpcMessage
;
1230 MIDL_STUB_MESSAGE StubMsg
;
1231 MIDL_STUB_DESC StubDesc
;
1233 unsigned char *mem
, *mem_orig
;
1234 char memsrc
[] = "This is a test string";
1236 static const unsigned char fmtstr_conf_str
[] =
1238 0x11, 0x8, /* FC_RP [simple_pointer] */
1239 0x22, /* FC_C_CSTRING */
1243 StubDesc
= Object_StubDesc
;
1244 StubDesc
.pFormatTypes
= fmtstr_conf_str
;
1246 NdrClientInitializeNew(
1252 StubMsg
.BufferLength
= 0;
1253 NdrPointerBufferSize( &StubMsg
,
1254 (unsigned char *)memsrc
,
1256 ok(StubMsg
.BufferLength
>= sizeof(memsrc
) + 12, "length %d\n", StubMsg
.BufferLength
);
1258 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1259 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1260 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1262 ptr
= NdrPointerMarshall( &StubMsg
, (unsigned char *)memsrc
, fmtstr_conf_str
);
1263 ok(ptr
== NULL
, "ret %p\n", ptr
);
1264 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== sizeof(memsrc
) + 12, "Buffer %p Start %p len %d\n",
1265 StubMsg
.Buffer
, StubMsg
.BufferStart
, StubMsg
.Buffer
- StubMsg
.BufferStart
);
1266 ok(!memcmp(StubMsg
.BufferStart
+ 12, memsrc
, sizeof(memsrc
)), "incorrectly marshaled\n");
1268 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1269 StubMsg
.MemorySize
= 0;
1273 my_alloc_called
= 0;
1274 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1275 mem
= mem_orig
= HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc
));
1276 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 0);
1277 ok(mem
== mem_orig
, "mem not alloced\n");
1278 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1280 my_alloc_called
= 0;
1281 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1282 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 1);
1284 ok(mem
== mem_orig
, "mem not alloced\n");
1285 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1289 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1290 NdrPointerFree( &StubMsg
, mem
, fmtstr_conf_str
);
1291 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
1295 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1296 NdrPointerFree( &StubMsg
, mem
, fmtstr_conf_str
);
1297 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
1300 my_alloc_called
= 0;
1301 StubMsg
.IsClient
= 0;
1303 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1304 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 0);
1305 ok(mem
== StubMsg
.BufferStart
+ 12, "mem not pointing at buffer\n");
1306 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1308 my_alloc_called
= 0;
1310 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1311 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 1);
1313 ok(mem
== StubMsg
.BufferStart
+ 12, "mem not pointing at buffer\n");
1314 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1317 my_alloc_called
= 0;
1319 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1320 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 0);
1321 ok(mem
== StubMsg
.BufferStart
+ 12, "mem not pointing at buffer\n");
1322 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1324 my_alloc_called
= 0;
1326 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1327 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 1);
1329 ok(mem
== StubMsg
.BufferStart
+ 12, "mem not pointing at buffer\n");
1330 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1335 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1336 NdrPointerFree( &StubMsg
, mem
, fmtstr_conf_str
);
1337 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
1339 HeapFree(GetProcessHeap(), 0, mem_orig
);
1340 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1343 static void test_nonconformant_string(void)
1345 RPC_MESSAGE RpcMessage
;
1346 MIDL_STUB_MESSAGE StubMsg
;
1347 MIDL_STUB_DESC StubDesc
;
1349 unsigned char *mem
, *mem_orig
;
1350 unsigned char memsrc
[10] = "This is";
1351 unsigned char memsrc2
[10] = "This is a";
1353 static const unsigned char fmtstr_nonconf_str
[] =
1355 0x26, /* FC_CSTRING */
1357 NdrFcShort( 0xa ), /* 10 */
1360 StubDesc
= Object_StubDesc
;
1361 StubDesc
.pFormatTypes
= fmtstr_nonconf_str
;
1364 NdrClientInitializeNew(
1370 StubMsg
.BufferLength
= 0;
1372 NdrNonConformantStringBufferSize( &StubMsg
,
1373 (unsigned char *)memsrc
,
1374 fmtstr_nonconf_str
);
1375 ok(StubMsg
.BufferLength
>= strlen((char *)memsrc
) + 1 + 8, "length %d\n", StubMsg
.BufferLength
);
1377 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1378 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1379 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1381 ptr
= NdrNonConformantStringMarshall( &StubMsg
, (unsigned char *)memsrc
, fmtstr_nonconf_str
);
1382 ok(ptr
== NULL
, "ret %p\n", ptr
);
1383 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== strlen((char *)memsrc
) + 1 + 8, "Buffer %p Start %p len %d\n",
1384 StubMsg
.Buffer
, StubMsg
.BufferStart
, StubMsg
.Buffer
- StubMsg
.BufferStart
);
1385 ok(!memcmp(StubMsg
.BufferStart
+ 8, memsrc
, strlen((char *)memsrc
) + 1), "incorrectly marshaled\n");
1387 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1388 StubMsg
.MemorySize
= 0;
1392 my_alloc_called
= 0;
1393 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1394 mem
= mem_orig
= HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc
));
1395 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1396 ok(mem
== mem_orig
, "mem alloced\n");
1397 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1399 my_alloc_called
= 0;
1400 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1401 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 1);
1403 ok(mem
== mem_orig
, "mem alloced\n");
1405 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1408 my_alloc_called
= 0;
1409 StubMsg
.IsClient
= 0;
1411 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1412 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1413 ok(mem
!= mem_orig
, "mem not alloced\n");
1414 ok(mem
!= StubMsg
.BufferStart
+ 8, "mem pointing at buffer\n");
1415 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1418 my_alloc_called
= 0;
1420 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1421 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1422 ok(mem
== mem_orig
, "mem alloced\n");
1423 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1425 my_alloc_called
= 0;
1427 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1428 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 1);
1430 ok(mem
== mem_orig
, "mem alloced\n");
1432 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1434 HeapFree(GetProcessHeap(), 0, mem_orig
);
1435 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1438 NdrClientInitializeNew(
1444 StubMsg
.BufferLength
= 0;
1446 NdrNonConformantStringBufferSize( &StubMsg
,
1447 (unsigned char *)memsrc2
,
1448 fmtstr_nonconf_str
);
1449 ok(StubMsg
.BufferLength
>= strlen((char *)memsrc2
) + 1 + 8, "length %d\n", StubMsg
.BufferLength
);
1451 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1452 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1453 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1455 ptr
= NdrNonConformantStringMarshall( &StubMsg
, (unsigned char *)memsrc2
, fmtstr_nonconf_str
);
1456 ok(ptr
== NULL
, "ret %p\n", ptr
);
1457 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== strlen((char *)memsrc2
) + 1 + 8, "Buffer %p Start %p len %d\n",
1458 StubMsg
.Buffer
, StubMsg
.BufferStart
, StubMsg
.Buffer
- StubMsg
.BufferStart
);
1459 ok(!memcmp(StubMsg
.BufferStart
+ 8, memsrc2
, strlen((char *)memsrc2
) + 1), "incorrectly marshaled\n");
1461 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1462 StubMsg
.MemorySize
= 0;
1466 my_alloc_called
= 0;
1467 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1468 mem
= mem_orig
= HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc
));
1469 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1470 ok(mem
== mem_orig
, "mem alloced\n");
1471 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1473 my_alloc_called
= 0;
1474 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1475 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 1);
1477 ok(mem
== mem_orig
, "mem alloced\n");
1479 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1482 my_alloc_called
= 0;
1483 StubMsg
.IsClient
= 0;
1485 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1486 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1487 ok(mem
!= mem_orig
, "mem not alloced\n");
1488 ok(mem
!= StubMsg
.BufferStart
+ 8, "mem pointing at buffer\n");
1489 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1492 my_alloc_called
= 0;
1494 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1495 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1496 ok(mem
== mem_orig
, "mem alloced\n");
1497 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1499 my_alloc_called
= 0;
1501 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1502 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 1);
1504 ok(mem
== mem_orig
, "mem alloced\n");
1506 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1508 HeapFree(GetProcessHeap(), 0, mem_orig
);
1509 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1512 START_TEST( ndr_marshall
)
1514 test_ndr_simple_type();
1515 test_simple_types();
1516 test_simple_struct();
1517 test_fullpointer_xlat();
1520 test_ndr_allocate();
1521 test_conformant_array();
1522 test_conformant_string();
1523 test_nonconformant_string();