2 * Unit test suite for ndr marshalling functions
4 * Copyright 2006 Huw Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define NTDDI_WIN2K 0x05000000
24 #define NTDDI_VERSION NTDDI_WIN2K /* for some MIDL_STUB_MESSAGE fields */
26 #include "wine/test.h"
37 static int my_alloc_called
;
38 static int my_free_called
;
39 static void * CALLBACK
my_alloc(size_t size
)
42 return NdrOleAllocate(size
);
45 static void CALLBACK
my_free(void *ptr
)
51 static const MIDL_STUB_DESC Object_StubDesc
=
61 NULL
, /* format string, filled in by tests */
62 1, /* -error bounds_check flag */
63 0x20000, /* Ndr library version */
65 0x50100a4, /* MIDL Version 5.1.164 */
68 0, /* notify & notify_flag routine table */
75 static RPC_DISPATCH_FUNCTION IFoo_table
[] =
80 static RPC_DISPATCH_TABLE IFoo_v0_0_DispatchTable
=
86 static const RPC_SERVER_INTERFACE IFoo___RpcServerInterface
=
88 sizeof(RPC_SERVER_INTERFACE
),
89 {{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x34}},{0,0}},
90 {{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},
91 &IFoo_v0_0_DispatchTable
,
99 static RPC_IF_HANDLE IFoo_v0_0_s_ifspec
= (RPC_IF_HANDLE
)& IFoo___RpcServerInterface
;
101 static void test_ndr_simple_type(void)
103 RPC_MESSAGE RpcMessage
;
104 MIDL_STUB_MESSAGE StubMsg
;
105 MIDL_STUB_DESC StubDesc
;
108 StubDesc
= Object_StubDesc
;
109 StubDesc
.pFormatTypes
= NULL
;
111 NdrClientInitializeNew(
117 StubMsg
.BufferLength
= 16;
118 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
120 NdrSimpleTypeMarshall(&StubMsg
, (unsigned char*)&l
, 8 /* FC_LONG */);
121 ok(StubMsg
.Buffer
== StubMsg
.BufferStart
+ 4, "%p %p\n", StubMsg
.Buffer
, StubMsg
.BufferStart
);
122 ok(*(long*)StubMsg
.BufferStart
== l
, "%ld\n", *(long*)StubMsg
.BufferStart
);
124 StubMsg
.Buffer
= StubMsg
.BufferStart
+ 1;
125 NdrSimpleTypeMarshall(&StubMsg
, (unsigned char*)&l
, 8 /* FC_LONG */);
126 ok(StubMsg
.Buffer
== StubMsg
.BufferStart
+ 8, "%p %p\n", StubMsg
.Buffer
, StubMsg
.BufferStart
);
127 ok(*(long*)(StubMsg
.BufferStart
+ 4) == l
, "%ld\n", *(long*)StubMsg
.BufferStart
);
129 StubMsg
.Buffer
= StubMsg
.BufferStart
+ 1;
130 NdrSimpleTypeUnmarshall(&StubMsg
, (unsigned char*)&l2
, 8 /* FC_LONG */);
131 ok(StubMsg
.Buffer
== StubMsg
.BufferStart
+ 8, "%p %p\n", StubMsg
.Buffer
, StubMsg
.BufferStart
);
132 ok(l2
== l
, "%ld\n", l2
);
134 HeapFree(GetProcessHeap(), 0, StubMsg
.BufferStart
);
137 static void test_pointer_marshal(const unsigned char *formattypes
,
140 const void *wiredata
,
142 int(*cmp
)(const void*,const void*,size_t),
143 long num_additional_allocs
,
146 RPC_MESSAGE RpcMessage
;
147 MIDL_STUB_MESSAGE StubMsg
;
148 MIDL_STUB_DESC StubDesc
;
151 unsigned char *mem
, *mem_orig
;
153 my_alloc_called
= my_free_called
= 0;
157 StubDesc
= Object_StubDesc
;
158 StubDesc
.pFormatTypes
= formattypes
;
160 NdrClientInitializeNew(
166 StubMsg
.BufferLength
= 0;
167 NdrPointerBufferSize( &StubMsg
,
170 ok(StubMsg
.BufferLength
>= wiredatalen
, "%s: length %d\n", msgpfx
, StubMsg
.BufferLength
);
172 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
173 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
174 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
176 memset(StubMsg
.BufferStart
, 0x0, StubMsg
.BufferLength
); /* This is a hack to clear the padding between the ptr and longlong/double */
178 ptr
= NdrPointerMarshall( &StubMsg
, memsrc
, formattypes
);
179 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
180 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
181 ok(!memcmp(StubMsg
.BufferStart
, wiredata
, wiredatalen
), "%s: incorrectly marshaled\n", msgpfx
);
183 StubMsg
.Buffer
= StubMsg
.BufferStart
;
184 StubMsg
.MemorySize
= 0;
188 /* NdrPointerMemorySize crashes under Wine */
189 size
= NdrPointerMemorySize( &StubMsg
, formattypes
);
190 ok(size
== StubMsg
.MemorySize
, "%s: mem size %u size %u\n", msgpfx
, StubMsg
.MemorySize
, size
);
191 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
192 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
193 ok(size
== srcsize
+ 4, "%s: mem size %u\n", msgpfx
, size
);
195 ok(size
== srcsize
, "%s: mem size %u\n", msgpfx
, size
);
197 StubMsg
.Buffer
= StubMsg
.BufferStart
;
198 StubMsg
.MemorySize
= 16;
199 size
= NdrPointerMemorySize( &StubMsg
, formattypes
);
200 ok(size
== StubMsg
.MemorySize
, "%s: mem size %u size %u\n", msgpfx
, StubMsg
.MemorySize
, size
);
201 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
202 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
203 ok(size
== srcsize
+ 4 + 16, "%s: mem size %u\n", msgpfx
, size
);
205 ok(size
== srcsize
+ 16, "%s: mem size %u\n", msgpfx
, size
);
207 StubMsg
.Buffer
= StubMsg
.BufferStart
;
208 StubMsg
.MemorySize
= 1;
209 size
= NdrPointerMemorySize( &StubMsg
, formattypes
);
210 ok(size
== StubMsg
.MemorySize
, "%s: mem size %u size %u\n", msgpfx
, StubMsg
.MemorySize
, size
);
211 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
212 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
213 ok(size
== srcsize
+ 4 + (srcsize
== 8 ? 8 : 4), "%s: mem size %u\n", msgpfx
, size
);
215 ok(size
== srcsize
+ (srcsize
== 8 ? 8 : 4), "%s: mem size %u\n", msgpfx
, size
);
219 if(formattypes
[1] & 0x10) size
+= 4;
221 StubMsg
.Buffer
= StubMsg
.BufferStart
;
222 StubMsg
.MemorySize
= 0;
223 mem_orig
= mem
= HeapAlloc(GetProcessHeap(), 0, size
);
225 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
227 ptr
= NdrPointerUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
228 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
229 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
230 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
231 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
232 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
233 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
236 /* reset the buffer and call with must alloc */
237 StubMsg
.Buffer
= StubMsg
.BufferStart
;
238 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
240 ptr
= NdrPointerUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
241 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
242 /* doesn't allocate mem in this case */
244 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
246 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
247 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
248 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
251 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
254 if(formattypes
[0] != 0x11 /* FC_RP */)
256 /* now pass the address of a NULL ptr */
258 StubMsg
.Buffer
= StubMsg
.BufferStart
;
259 ptr
= NdrPointerUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
260 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
261 ok(mem
!= StubMsg
.BufferStart
+ wiredatalen
- srcsize
, "%s: mem points to buffer %p %p\n", msgpfx
, mem
, StubMsg
.BufferStart
);
262 ok(!cmp(mem
, memsrc
, size
), "%s: incorrectly unmarshaled\n", msgpfx
);
263 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
264 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
265 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
267 NdrPointerFree(&StubMsg
, mem
, formattypes
);
269 /* again pass address of NULL ptr, but pretend we're a server */
271 StubMsg
.Buffer
= StubMsg
.BufferStart
;
272 StubMsg
.IsClient
= 0;
273 ptr
= NdrPointerUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
274 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
275 if (formattypes
[2] == 0xd /* FC_ENUM16 */)
276 ok(mem
!= StubMsg
.BufferStart
+ wiredatalen
- srcsize
, "%s: mem points to buffer %p %p\n", msgpfx
, mem
, StubMsg
.BufferStart
);
278 ok(mem
== StubMsg
.BufferStart
+ wiredatalen
- srcsize
, "%s: mem doesn't point to buffer %p %p\n", msgpfx
, mem
, StubMsg
.BufferStart
);
279 ok(!cmp(mem
, memsrc
, size
), "%s: incorrecly unmarshaled\n", msgpfx
);
280 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
281 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
282 if (formattypes
[2] != 0xd /* FC_ENUM16 */) {
283 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
287 HeapFree(GetProcessHeap(), 0, mem_orig
);
288 HeapFree(GetProcessHeap(), 0, StubMsg
.BufferStart
);
291 static int deref_cmp(const void *s1
, const void *s2
, size_t num
)
293 return memcmp(*(const void *const *)s1
, *(const void *const *)s2
, num
);
297 static void test_simple_types(void)
299 unsigned char wiredata
[16];
301 unsigned char *ch_ptr
;
309 static const unsigned char fmtstr_up_char
[] =
311 0x12, 0x8, /* FC_UP [simple_pointer] */
315 static const unsigned char fmtstr_up_byte
[] =
317 0x12, 0x8, /* FC_UP [simple_pointer] */
321 static const unsigned char fmtstr_up_small
[] =
323 0x12, 0x8, /* FC_UP [simple_pointer] */
327 static const unsigned char fmtstr_up_usmall
[] =
329 0x12, 0x8, /* FC_UP [simple_pointer] */
333 static const unsigned char fmtstr_rp_char
[] =
335 0x11, 0x8, /* FC_RP [simple_pointer] */
339 static const unsigned char fmtstr_rpup_char
[] =
341 0x11, 0x14, /* FC_RP [alloced_on_stack] */
342 NdrFcShort( 0x2 ), /* Offset= 2 (4) */
343 0x12, 0x8, /* FC_UP [simple_pointer] */
347 static const unsigned char fmtstr_rpup_char2
[] =
349 0x11, 0x04, /* FC_RP [alloced_on_stack] */
350 NdrFcShort( 0x2 ), /* Offset= 2 (4) */
351 0x12, 0x8, /* FC_UP [simple_pointer] */
356 static const unsigned char fmtstr_up_wchar
[] =
358 0x12, 0x8, /* FC_UP [simple_pointer] */
362 static const unsigned char fmtstr_up_short
[] =
364 0x12, 0x8, /* FC_UP [simple_pointer] */
368 static const unsigned char fmtstr_up_ushort
[] =
370 0x12, 0x8, /* FC_UP [simple_pointer] */
374 static const unsigned char fmtstr_up_enum16
[] =
376 0x12, 0x8, /* FC_UP [simple_pointer] */
380 static const unsigned char fmtstr_up_long
[] =
382 0x12, 0x8, /* FC_UP [simple_pointer] */
386 static const unsigned char fmtstr_up_ulong
[] =
388 0x12, 0x8, /* FC_UP [simple_pointer] */
392 static const unsigned char fmtstr_up_enum32
[] =
394 0x12, 0x8, /* FC_UP [simple_pointer] */
398 static const unsigned char fmtstr_up_errorstatus
[] =
400 0x12, 0x8, /* FC_UP [simple_pointer] */
401 0x10, /* FC_ERROR_STATUS_T */
405 static const unsigned char fmtstr_up_longlong
[] =
407 0x12, 0x8, /* FC_UP [simple_pointer] */
411 static const unsigned char fmtstr_up_float
[] =
413 0x12, 0x8, /* FC_UP [simple_pointer] */
417 static const unsigned char fmtstr_up_double
[] =
419 0x12, 0x8, /* FC_UP [simple_pointer] */
426 *(void**)wiredata
= ch_ptr
;
427 wiredata
[sizeof(void*)] = ch
;
429 test_pointer_marshal(fmtstr_up_char
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_char");
430 test_pointer_marshal(fmtstr_up_byte
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_byte");
431 test_pointer_marshal(fmtstr_up_small
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_small");
432 test_pointer_marshal(fmtstr_up_usmall
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_usmall");
434 test_pointer_marshal(fmtstr_rp_char
, ch_ptr
, 1, &ch
, 1, NULL
, 0, "rp_char");
436 test_pointer_marshal(fmtstr_rpup_char
, &ch_ptr
, 1, wiredata
, 5, deref_cmp
, 1, "rpup_char");
437 test_pointer_marshal(fmtstr_rpup_char2
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "rpup_char2");
440 *(void**)wiredata
= &s
;
441 *(unsigned short*)(wiredata
+ sizeof(void*)) = s
;
443 test_pointer_marshal(fmtstr_up_wchar
, &s
, 2, wiredata
, 6, NULL
, 0, "up_wchar");
444 test_pointer_marshal(fmtstr_up_short
, &s
, 2, wiredata
, 6, NULL
, 0, "up_short");
445 test_pointer_marshal(fmtstr_up_ushort
, &s
, 2, wiredata
, 6, NULL
, 0, "up_ushort");
448 *(void**)wiredata
= &i
;
449 *(unsigned short*)(wiredata
+ sizeof(void*)) = i
;
450 test_pointer_marshal(fmtstr_up_enum16
, &i
, 2, wiredata
, 6, NULL
, 0, "up_enum16");
453 *(void**)wiredata
= &l
;
454 *(unsigned long*)(wiredata
+ sizeof(void*)) = l
;
456 test_pointer_marshal(fmtstr_up_long
, &l
, 4, wiredata
, 8, NULL
, 0, "up_long");
457 test_pointer_marshal(fmtstr_up_ulong
, &l
, 4, wiredata
, 8, NULL
, 0, "up_ulong");
458 test_pointer_marshal(fmtstr_up_enum32
, &l
, 4, wiredata
, 8, NULL
, 0, "up_emun32");
459 test_pointer_marshal(fmtstr_up_errorstatus
, &l
, 4, wiredata
, 8, NULL
, 0, "up_errorstatus");
461 ll
= ((ULONGLONG
)0xcafebabe) << 32 | 0xdeadbeef;
462 *(void**)wiredata
= &ll
;
463 *(void**)(wiredata
+ sizeof(void*)) = NULL
;
464 *(ULONGLONG
*)(wiredata
+ 2 * sizeof(void*)) = ll
;
465 test_pointer_marshal(fmtstr_up_longlong
, &ll
, 8, wiredata
, 16, NULL
, 0, "up_longlong");
468 *(void**)wiredata
= &f
;
469 *(float*)(wiredata
+ sizeof(void*)) = f
;
470 test_pointer_marshal(fmtstr_up_float
, &f
, 4, wiredata
, 8, NULL
, 0, "up_float");
473 *(void**)wiredata
= &d
;
474 *(void**)(wiredata
+ sizeof(void*)) = NULL
;
475 *(double*)(wiredata
+ 2 * sizeof(void*)) = d
;
476 test_pointer_marshal(fmtstr_up_double
, &d
, 8, wiredata
, 16, NULL
, 0, "up_double");
480 static void test_nontrivial_pointer_types(void)
482 RPC_MESSAGE RpcMessage
;
483 MIDL_STUB_MESSAGE StubMsg
;
484 MIDL_STUB_DESC StubDesc
;
489 unsigned char *mem
, *mem_orig
;
491 static const unsigned char fmtstr_ref_unique_out
[] =
493 0x12, 0x8, /* FC_UP [simple_pointer] */
496 0x11, 0x14, /* FC_RP [alloced_on_stack] [pointer_deref] */
497 NdrFcShort( 0xfffffffa ), /* Offset= -6 (0) */
504 StubDesc
= Object_StubDesc
;
505 StubDesc
.pFormatTypes
= fmtstr_ref_unique_out
;
507 NdrClientInitializeNew(
513 StubMsg
.BufferLength
= 0;
514 NdrPointerBufferSize( &StubMsg
,
516 &fmtstr_ref_unique_out
[4] );
517 ok(StubMsg
.BufferLength
== 5, "length %d\n", StubMsg
.BufferLength
);
519 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
520 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
521 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
523 ptr
= NdrPointerMarshall( &StubMsg
, (unsigned char *)p1
, &fmtstr_ref_unique_out
[4] );
524 ok(ptr
== NULL
, "ret %p\n", ptr
);
525 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== 5, "Buffer %p Start %p len %d\n",
526 StubMsg
.Buffer
, StubMsg
.BufferStart
, StubMsg
.Buffer
- StubMsg
.BufferStart
);
527 ok(*(unsigned int *)StubMsg
.BufferStart
!= 0, "pointer ID marshalled incorrectly\n");
528 ok(*(unsigned char *)(StubMsg
.BufferStart
+ 4) == 0x22, "char data marshalled incorrectly: 0x%x\n",
529 *(unsigned char *)(StubMsg
.BufferStart
+ 4));
531 StubMsg
.Buffer
= StubMsg
.BufferStart
;
532 StubMsg
.MemorySize
= 0;
537 StubMsg
.Buffer
= StubMsg
.BufferStart
;
538 mem
= mem_orig
= HeapAlloc(GetProcessHeap(), 0, sizeof(void *));
539 *(void **)mem
= NULL
;
540 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 0);
541 ok(mem
== mem_orig
, "mem alloced\n");
542 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
545 StubMsg
.Buffer
= StubMsg
.BufferStart
;
546 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 1);
548 ok(mem
== mem_orig
, "mem alloced\n");
549 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
553 StubMsg
.Buffer
= StubMsg
.BufferStart
;
554 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
555 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
557 mem
= my_alloc(sizeof(void *));
558 *(void **)mem
= NULL
;
560 StubMsg
.Buffer
= StubMsg
.BufferStart
;
561 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
562 ok(my_free_called
== 0, "free called %d\n", my_free_called
);
565 mem
= my_alloc(sizeof(void *));
566 *(void **)mem
= my_alloc(sizeof(char));
568 StubMsg
.Buffer
= StubMsg
.BufferStart
;
569 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
570 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
575 StubMsg
.IsClient
= 0;
577 StubMsg
.Buffer
= StubMsg
.BufferStart
;
578 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 0);
579 ok(mem
!= StubMsg
.BufferStart
, "mem pointing at buffer\n");
581 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
582 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
586 StubMsg
.Buffer
= StubMsg
.BufferStart
;
587 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 1);
588 ok(mem
!= StubMsg
.BufferStart
, "mem pointing at buffer\n");
590 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
591 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
595 *(void **)mem
= NULL
;
596 StubMsg
.Buffer
= StubMsg
.BufferStart
;
597 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 0);
599 ok(mem
== mem_orig
, "mem alloced\n");
600 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
605 *(void **)mem
= NULL
;
606 StubMsg
.Buffer
= StubMsg
.BufferStart
;
607 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 1);
609 ok(mem
== mem_orig
, "mem alloced\n");
610 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
613 mem
= my_alloc(sizeof(void *));
614 *(void **)mem
= NULL
;
616 StubMsg
.Buffer
= StubMsg
.BufferStart
;
617 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
618 ok(my_free_called
== 0, "free called %d\n", my_free_called
);
621 mem
= my_alloc(sizeof(void *));
622 *(void **)mem
= my_alloc(sizeof(char));
624 StubMsg
.Buffer
= StubMsg
.BufferStart
;
625 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
626 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
629 HeapFree(GetProcessHeap(), 0, mem_orig
);
630 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
633 static void test_simple_struct_marshal(const unsigned char *formattypes
,
636 const void *wiredata
,
638 int(*cmp
)(const void*,const void*,size_t),
639 long num_additional_allocs
,
642 RPC_MESSAGE RpcMessage
;
643 MIDL_STUB_MESSAGE StubMsg
;
644 MIDL_STUB_DESC StubDesc
;
647 unsigned char *mem
, *mem_orig
;
649 my_alloc_called
= my_free_called
= 0;
653 StubDesc
= Object_StubDesc
;
654 StubDesc
.pFormatTypes
= formattypes
;
656 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &StubDesc
, 0);
658 StubMsg
.BufferLength
= 0;
659 NdrSimpleStructBufferSize( &StubMsg
, (unsigned char *)memsrc
, formattypes
);
660 ok(StubMsg
.BufferLength
>= wiredatalen
, "%s: length %d\n", msgpfx
, StubMsg
.BufferLength
);
661 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
662 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
663 ptr
= NdrSimpleStructMarshall( &StubMsg
, (unsigned char*)memsrc
, formattypes
);
664 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
665 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
666 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));
670 /* FIXME: Causes Wine to crash */
671 StubMsg
.Buffer
= StubMsg
.BufferStart
;
672 StubMsg
.MemorySize
= 0;
673 size
= NdrSimpleStructMemorySize( &StubMsg
, formattypes
);
674 ok(size
== StubMsg
.MemorySize
, "%s: size != MemorySize\n", msgpfx
);
675 ok(size
== srcsize
, "%s: mem size %u\n", msgpfx
, size
);
676 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
678 StubMsg
.Buffer
= StubMsg
.BufferStart
;
679 size
= NdrSimpleStructMemorySize( &StubMsg
, formattypes
);
681 ok(size
== StubMsg
.MemorySize
, "%s: size != MemorySize\n", msgpfx
);
683 ok(StubMsg
.MemorySize
== ((srcsize
+ 3) & ~3) + srcsize
, "%s: mem size %u\n", msgpfx
, size
);
684 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
687 /*** Unmarshalling first with must_alloc false ***/
689 StubMsg
.Buffer
= StubMsg
.BufferStart
;
690 StubMsg
.MemorySize
= 0;
691 mem_orig
= mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, srcsize
);
692 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
693 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
694 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
695 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
696 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
697 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
699 ok(StubMsg
.MemorySize
== 0, "%s: memorysize touched in unmarshal\n", msgpfx
);
701 /* If we're a server we still use the supplied memory */
702 StubMsg
.Buffer
= StubMsg
.BufferStart
;
703 StubMsg
.IsClient
= 0;
704 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
705 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
706 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
707 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
708 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
710 ok(StubMsg
.MemorySize
== 0, "%s: memorysize touched in unmarshal\n", msgpfx
);
712 /* ...unless we pass a NULL ptr, then the buffer is used.
713 Passing a NULL ptr while we're a client && !must_alloc
714 crashes on Windows, so we won't do that. */
717 StubMsg
.IsClient
= 0;
718 StubMsg
.Buffer
= StubMsg
.BufferStart
;
719 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
720 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
721 ok(mem
== StubMsg
.BufferStart
, "%s: mem not equal buffer\n", msgpfx
);
722 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
723 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
725 ok(StubMsg
.MemorySize
== 0, "%s: memorysize touched in unmarshal\n", msgpfx
);
727 /*** now must_alloc is true ***/
729 /* with must_alloc set we always allocate new memory whether or not we're
730 a server and also when passing NULL */
732 StubMsg
.IsClient
= 1;
733 StubMsg
.Buffer
= StubMsg
.BufferStart
;
734 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
735 ok(ptr
== NULL
, "ret %p\n", ptr
);
736 ok(mem
!= mem_orig
, "mem not changed %p %p\n", mem
, mem_orig
);
737 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
738 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
740 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
743 StubMsg
.Buffer
= StubMsg
.BufferStart
;
744 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
745 ok(ptr
== NULL
, "ret %p\n", ptr
);
746 ok(mem
!= mem_orig
, "mem not changed %p %p\n", mem
, mem_orig
);
747 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
748 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
750 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
753 StubMsg
.Buffer
= StubMsg
.BufferStart
;
754 StubMsg
.IsClient
= 0;
755 StubMsg
.ReuseBuffer
= 1;
756 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
757 ok(ptr
== NULL
, "ret %p\n", ptr
);
758 ok(mem
!= mem_orig
, "mem not changed %p %p\n", mem
, mem_orig
);
759 ok(mem
!= StubMsg
.BufferStart
, "mem is buffer mem\n");
760 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
761 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
763 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
766 StubMsg
.Buffer
= StubMsg
.BufferStart
;
767 StubMsg
.IsClient
= 0;
768 StubMsg
.ReuseBuffer
= 1;
769 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
770 ok(ptr
== NULL
, "ret %p\n", ptr
);
771 ok(mem
!= StubMsg
.BufferStart
, "mem is buffer mem\n");
772 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
773 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
775 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
777 HeapFree(GetProcessHeap(), 0, mem_orig
);
778 HeapFree(GetProcessHeap(), 0, StubMsg
.BufferStart
);
788 static int ps1_cmp(const void *s1
, const void *s2
, size_t num
)
790 const ps1_t
*p1
, *p2
;
798 if(p1
->pl1
&& p2
->pl1
)
800 if(*p1
->pl1
!= *p2
->pl1
)
803 else if(p1
->pl1
|| p1
->pl1
)
806 if(p1
->pc1
&& p2
->pc1
)
808 if(*p1
->pc1
!= *p2
->pc1
)
811 else if(p1
->pc1
|| p1
->pc1
)
817 static void test_simple_struct(void)
819 unsigned char wiredata
[28];
820 unsigned long wiredatalen
;
825 static const unsigned char fmtstr_simple_struct
[] =
827 0x12, 0x0, /* FC_UP */
828 NdrFcShort( 0x2 ), /* Offset=2 */
829 0x15, 0x3, /* FC_STRUCT [align 4] */
830 NdrFcShort( 0x18 ), /* [size 24] */
833 0x38, /* FC_ALIGNM4 */
836 0x39, /* FC_ALIGNM8 */
847 static const unsigned char fmtstr_pointer_struct
[] =
849 0x12, 0x0, /* FC_UP */
850 NdrFcShort( 0x2 ), /* Offset=2 */
851 0x16, 0x3, /* FC_PSTRUCT [align 4] */
852 NdrFcShort( 0xc ), /* [size 12] */
855 0x46, /* FC_NO_REPEAT */
857 NdrFcShort( 0x4 ), /* 4 */
858 NdrFcShort( 0x4 ), /* 4 */
859 0x13, 0x8, /* FC_OP [simple_pointer] */
862 0x46, /* FC_NO_REPEAT */
864 NdrFcShort( 0x8 ), /* 8 */
865 NdrFcShort( 0x8 ), /* 8 */
866 0x13, 0x8, /* FC_OP [simple_pointer] */
883 s1
.ll
= ((LONGLONG
) 0xbadefeed << 32) | 0x2468ace0;
886 memcpy(wiredata
, &s1
, wiredatalen
);
887 test_simple_struct_marshal(fmtstr_simple_struct
+ 4, &s1
, 24, wiredata
, 24, NULL
, 0, "struct");
889 *(void**)wiredata
= &s1
;
890 memcpy(wiredata
+ 4, &s1
, wiredatalen
);
893 /* one of the unmarshallings crashes Wine */
894 test_pointer_marshal(fmtstr_simple_struct
, &s1
, 24, wiredata
, 28, NULL
, 0, "struct");
903 memcpy(wiredata
+ 4, &ps1
, 12);
904 memcpy(wiredata
+ 16, &l
, 4);
905 memcpy(wiredata
+ 20, &c
, 1);
907 test_simple_struct_marshal(fmtstr_pointer_struct
+ 4, &ps1
, 17, wiredata
+ 4, 17, ps1_cmp
, 2, "pointer_struct");
908 *(void**)wiredata
= &ps1
;
911 /* one of the unmarshallings crashes Wine */
912 test_pointer_marshal(fmtstr_pointer_struct
, &ps1
, 17, wiredata
, 21, ps1_cmp
, 2, "pointer_struct");
916 static void test_fullpointer_xlat(void)
918 PFULL_PTR_XLAT_TABLES pXlatTables
;
923 pXlatTables
= NdrFullPointerXlatInit(2, XLAT_CLIENT
);
925 /* "marshaling" phase */
927 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
928 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
929 ok(RefId
== 0x1, "RefId should be 0x1 instead of 0x%x\n", RefId
);
931 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 0, &RefId
);
932 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
933 ok(RefId
== 0x1, "RefId should be 0x1 instead of 0x%x\n", RefId
);
935 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebabe, 0, &RefId
);
936 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
937 ok(RefId
== 0x2, "RefId should be 0x2 instead of 0x%x\n", RefId
);
939 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 0, &RefId
);
940 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
941 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
943 ret
= NdrFullPointerQueryPointer(pXlatTables
, NULL
, 0, &RefId
);
944 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
945 ok(RefId
== 0, "RefId should be 0 instead of 0x%x\n", RefId
);
947 /* "unmarshaling" phase */
949 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 0, &Pointer
);
950 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
951 ok(Pointer
== (void *)0xcafebabe, "Pointer should be 0xcafebabe instead of %p\n", Pointer
);
953 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x4, 0, &Pointer
);
954 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
955 ok(Pointer
== NULL
, "Pointer should be NULL instead of %p\n", Pointer
);
957 NdrFullPointerInsertRefId(pXlatTables
, 0x4, (void *)0xdeadbabe);
959 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x4, 1, &Pointer
);
960 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
961 ok(Pointer
== (void *)0xdeadbabe, "Pointer should be (void *)0xdeadbabe instead of %p\n", Pointer
);
963 NdrFullPointerXlatFree(pXlatTables
);
965 pXlatTables
= NdrFullPointerXlatInit(2, XLAT_SERVER
);
967 /* "unmarshaling" phase */
969 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 1, &Pointer
);
970 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
971 ok(Pointer
== NULL
, "Pointer should be NULL instead of %p\n", Pointer
);
973 NdrFullPointerInsertRefId(pXlatTables
, 0x2, (void *)0xcafebabe);
975 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 0, &Pointer
);
976 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
977 ok(Pointer
== (void *)0xcafebabe, "Pointer should be (void *)0xcafebabe instead of %p\n", Pointer
);
979 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 1, &Pointer
);
980 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
981 ok(Pointer
== (void *)0xcafebabe, "Pointer should be (void *)0xcafebabe instead of %p\n", Pointer
);
983 /* "marshaling" phase */
985 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
986 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
987 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
989 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
990 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
991 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
993 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 0, &RefId
);
994 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
995 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
997 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebabe, 0, &RefId
);
998 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
999 ok(RefId
== 0x2, "RefId should be 0x2 instead of 0x%x\n", RefId
);
1001 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 0, &RefId
);
1002 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1003 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
1005 /* "freeing" phase */
1007 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xcafebeef);
1008 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1010 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 0x20, &RefId
);
1011 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1012 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1014 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
1015 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1016 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1018 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xcafebabe);
1019 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1021 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xdeadbeef);
1022 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1024 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 0x20, &RefId
);
1025 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1026 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
1028 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 1, &RefId
);
1029 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1030 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
1032 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 1, &RefId
);
1033 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1034 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
1036 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xdeadbeef);
1037 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1039 NdrFullPointerXlatFree(pXlatTables
);
1042 static void test_client_init(void)
1044 MIDL_STUB_MESSAGE stubMsg
;
1047 memset(&rpcMsg
, 0xcc, sizeof(rpcMsg
));
1048 memset(&stubMsg
, 0xcc, sizeof(stubMsg
));
1050 NdrClientInitializeNew(&rpcMsg
, &stubMsg
, &Object_StubDesc
, 1);
1052 #define TEST_POINTER_UNSET(field) ok(rpcMsg.field == (void *)0xcccccccc, #field " should have been unset instead of %p\n", rpcMsg.field)
1054 ok(rpcMsg
.Handle
== NULL
, "rpcMsg.Handle should have been NULL instead of %p\n", rpcMsg
.Handle
);
1055 TEST_POINTER_UNSET(Buffer
);
1056 ok(rpcMsg
.BufferLength
== 0xcccccccc, "rpcMsg.BufferLength should have been unset instead of %d\n", rpcMsg
.BufferLength
);
1057 ok(rpcMsg
.ProcNum
== 0x8001, "rpcMsg.ProcNum should have been 0x8001 instead of 0x%x\n", rpcMsg
.ProcNum
);
1058 TEST_POINTER_UNSET(TransferSyntax
);
1059 ok(rpcMsg
.RpcInterfaceInformation
== Object_StubDesc
.RpcInterfaceInformation
,
1060 "rpcMsg.RpcInterfaceInformation should have been %p instead of %p\n",
1061 Object_StubDesc
.RpcInterfaceInformation
, rpcMsg
.RpcInterfaceInformation
);
1062 /* Note: ReservedForRuntime not tested */
1063 TEST_POINTER_UNSET(ManagerEpv
);
1064 TEST_POINTER_UNSET(ImportContext
);
1065 ok(rpcMsg
.RpcFlags
== 0, "rpcMsg.RpcFlags should have been 0 instead of 0x%lx\n", rpcMsg
.RpcFlags
);
1066 #undef TEST_POINTER_UNSET
1068 #define TEST_ZERO(field, fmt) ok(stubMsg.field == 0, #field " should have been set to zero instead of " fmt "\n", stubMsg.field)
1069 #define TEST_POINTER_UNSET(field) ok(stubMsg.field == (void *)0xcccccccc, #field " should have been unset instead of %p\n", stubMsg.field)
1070 #define TEST_ULONG_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%x\n", stubMsg.field)
1071 #define TEST_ULONG_PTR_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%lx\n", stubMsg.field)
1073 ok(stubMsg
.RpcMsg
== &rpcMsg
, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg
, stubMsg
.RpcMsg
);
1074 TEST_POINTER_UNSET(Buffer
);
1075 TEST_ZERO(BufferStart
, "%p");
1076 TEST_ZERO(BufferEnd
, "%p");
1077 TEST_POINTER_UNSET(BufferMark
);
1078 TEST_ZERO(BufferLength
, "%d");
1079 TEST_ULONG_UNSET(MemorySize
);
1080 TEST_POINTER_UNSET(Memory
);
1081 ok(stubMsg
.IsClient
== 1, "stubMsg.IsClient should have been 1 instead of %u\n", stubMsg
.IsClient
);
1082 TEST_ZERO(ReuseBuffer
, "%d");
1083 TEST_ZERO(pAllocAllNodesContext
, "%p");
1084 TEST_ZERO(pPointerQueueState
, "%p");
1085 TEST_ZERO(IgnoreEmbeddedPointers
, "%d");
1086 TEST_ZERO(PointerBufferMark
, "%p");
1087 TEST_ZERO(fBufferValid
, "%d");
1088 TEST_ZERO(uFlags
, "%d");
1089 /* FIXME: UniquePtrCount */
1090 TEST_ULONG_PTR_UNSET(MaxCount
);
1091 TEST_ULONG_UNSET(Offset
);
1092 TEST_ULONG_UNSET(ActualCount
);
1093 ok(stubMsg
.pfnAllocate
== my_alloc
, "stubMsg.pfnAllocate should have been %p instead of %p\n", my_alloc
, stubMsg
.pfnAllocate
);
1094 ok(stubMsg
.pfnFree
== my_free
, "stubMsg.pfnFree should have been %p instead of %p\n", my_free
, stubMsg
.pfnFree
);
1095 TEST_ZERO(StackTop
, "%p");
1096 TEST_POINTER_UNSET(pPresentedType
);
1097 TEST_POINTER_UNSET(pTransmitType
);
1098 TEST_POINTER_UNSET(SavedHandle
);
1099 ok(stubMsg
.StubDesc
== &Object_StubDesc
, "stubMsg.StubDesc should have been %p instead of %p\n", &Object_StubDesc
, stubMsg
.StubDesc
);
1100 TEST_POINTER_UNSET(FullPtrXlatTables
);
1101 TEST_ZERO(FullPtrRefId
, "%d");
1102 TEST_ZERO(PointerLength
, "%d");
1103 TEST_ZERO(fInDontFree
, "%d");
1104 TEST_ZERO(fDontCallFreeInst
, "%d");
1105 TEST_ZERO(fInOnlyParam
, "%d");
1106 TEST_ZERO(fHasReturn
, "%d");
1107 TEST_ZERO(fHasExtensions
, "%d");
1108 TEST_ZERO(fHasNewCorrDesc
, "%d");
1109 TEST_ZERO(fUnused
, "%d");
1110 ok(stubMsg
.fUnused2
== 0xffffcccc, "stubMsg.fUnused2 should have been 0xcccc instead of 0x%x\n", stubMsg
.fUnused2
);
1111 ok(stubMsg
.dwDestContext
== MSHCTX_DIFFERENTMACHINE
, "stubMsg.dwDestContext should have been MSHCTX_DIFFERENTMACHINE instead of %d\n", stubMsg
.dwDestContext
);
1112 TEST_ZERO(pvDestContext
, "%p");
1113 TEST_POINTER_UNSET(SavedContextHandles
);
1114 TEST_ULONG_UNSET(ParamNumber
);
1115 TEST_ZERO(pRpcChannelBuffer
, "%p");
1116 TEST_ZERO(pArrayInfo
, "%p");
1117 TEST_POINTER_UNSET(SizePtrCountArray
);
1118 TEST_POINTER_UNSET(SizePtrOffsetArray
);
1119 TEST_POINTER_UNSET(SizePtrLengthArray
);
1120 TEST_POINTER_UNSET(pArgQueue
);
1121 TEST_ZERO(dwStubPhase
, "%d");
1122 /* FIXME: where does this value come from? */
1123 trace("LowStackMark is %p\n", stubMsg
.LowStackMark
);
1124 TEST_ZERO(pAsyncMsg
, "%p");
1125 TEST_ZERO(pCorrInfo
, "%p");
1126 TEST_ZERO(pCorrMemory
, "%p");
1127 TEST_ZERO(pMemoryList
, "%p");
1128 TEST_POINTER_UNSET(pCSInfo
);
1129 TEST_POINTER_UNSET(ConformanceMark
);
1130 TEST_POINTER_UNSET(VarianceMark
);
1131 ok(stubMsg
.Unused
== 0xcccccccc, "Unused should have be unset instead of 0x%lx\n", stubMsg
.Unused
);
1132 TEST_POINTER_UNSET(pContext
);
1133 TEST_POINTER_UNSET(ContextHandleHash
);
1134 TEST_POINTER_UNSET(pUserMarshalList
);
1135 TEST_ULONG_PTR_UNSET(Reserved51_3
);
1136 TEST_ULONG_PTR_UNSET(Reserved51_4
);
1137 TEST_ULONG_PTR_UNSET(Reserved51_5
);
1138 #undef TEST_ULONG_UNSET
1139 #undef TEST_POINTER_UNSET
1144 static void test_server_init(void)
1146 MIDL_STUB_MESSAGE stubMsg
;
1149 unsigned char buffer
[256];
1151 memset(&rpcMsg
, 0, sizeof(rpcMsg
));
1152 rpcMsg
.Buffer
= buffer
;
1153 rpcMsg
.BufferLength
= sizeof(buffer
);
1154 rpcMsg
.RpcFlags
= RPC_BUFFER_COMPLETE
;
1156 memset(&stubMsg
, 0xcc, sizeof(stubMsg
));
1158 ret
= NdrServerInitializeNew(&rpcMsg
, &stubMsg
, &Object_StubDesc
);
1159 ok(ret
== NULL
, "NdrServerInitializeNew should have returned NULL instead of %p\n", ret
);
1161 #define TEST_ZERO(field, fmt) ok(stubMsg.field == 0, #field " should have been set to zero instead of " fmt "\n", stubMsg.field)
1162 #define TEST_POINTER_UNSET(field) ok(stubMsg.field == (void *)0xcccccccc, #field " should have been unset instead of %p\n", stubMsg.field)
1163 #define TEST_ULONG_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%x\n", stubMsg.field)
1164 #define TEST_ULONG_PTR_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%lx\n", stubMsg.field)
1166 ok(stubMsg
.RpcMsg
== &rpcMsg
, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg
, stubMsg
.RpcMsg
);
1167 ok(stubMsg
.Buffer
== buffer
, "stubMsg.Buffer should have been %p instead of %p\n", buffer
, stubMsg
.Buffer
);
1168 ok(stubMsg
.BufferStart
== buffer
, "stubMsg.BufferStart should have been %p instead of %p\n", buffer
, stubMsg
.BufferStart
);
1169 ok(stubMsg
.BufferEnd
== buffer
+ sizeof(buffer
), "stubMsg.BufferEnd should have been %p instead of %p\n", buffer
+ sizeof(buffer
), stubMsg
.BufferEnd
);
1170 TEST_POINTER_UNSET(BufferMark
);
1172 TEST_ZERO(BufferLength
, "%d");
1173 TEST_ULONG_UNSET(MemorySize
);
1174 TEST_POINTER_UNSET(Memory
);
1175 ok(stubMsg
.IsClient
== 0, "stubMsg.IsClient should have been 0 instead of %u\n", stubMsg
.IsClient
);
1176 TEST_ZERO(ReuseBuffer
, "%d");
1177 TEST_ZERO(pAllocAllNodesContext
, "%p");
1178 TEST_ZERO(pPointerQueueState
, "%p");
1179 TEST_ZERO(IgnoreEmbeddedPointers
, "%d");
1180 TEST_ZERO(PointerBufferMark
, "%p");
1181 ok(stubMsg
.fBufferValid
== 0xcc, "fBufferValid should have been unset instead of 0x%x\n", stubMsg
.fBufferValid
);
1182 TEST_ZERO(uFlags
, "%d");
1183 /* FIXME: UniquePtrCount */
1184 TEST_ULONG_PTR_UNSET(MaxCount
);
1185 TEST_ULONG_UNSET(Offset
);
1186 TEST_ULONG_UNSET(ActualCount
);
1187 ok(stubMsg
.pfnAllocate
== my_alloc
, "stubMsg.pfnAllocate should have been %p instead of %p\n", my_alloc
, stubMsg
.pfnAllocate
);
1188 ok(stubMsg
.pfnFree
== my_free
, "stubMsg.pfnFree should have been %p instead of %p\n", my_free
, stubMsg
.pfnFree
);
1189 TEST_ZERO(StackTop
, "%p");
1190 TEST_POINTER_UNSET(pPresentedType
);
1191 TEST_POINTER_UNSET(pTransmitType
);
1192 TEST_POINTER_UNSET(SavedHandle
);
1193 ok(stubMsg
.StubDesc
== &Object_StubDesc
, "stubMsg.StubDesc should have been %p instead of %p\n", &Object_StubDesc
, stubMsg
.StubDesc
);
1194 TEST_ZERO(FullPtrXlatTables
, "%p");
1195 TEST_ZERO(FullPtrRefId
, "%d");
1196 TEST_ZERO(PointerLength
, "%d");
1197 TEST_ZERO(fInDontFree
, "%d");
1198 TEST_ZERO(fDontCallFreeInst
, "%d");
1199 TEST_ZERO(fInOnlyParam
, "%d");
1200 TEST_ZERO(fHasReturn
, "%d");
1201 TEST_ZERO(fHasExtensions
, "%d");
1202 TEST_ZERO(fHasNewCorrDesc
, "%d");
1203 TEST_ZERO(fUnused
, "%d");
1204 ok(stubMsg
.fUnused2
== 0xffffcccc, "stubMsg.fUnused2 should have been 0xcccc instead of 0x%x\n", stubMsg
.fUnused2
);
1205 ok(stubMsg
.dwDestContext
== MSHCTX_DIFFERENTMACHINE
, "stubMsg.dwDestContext should have been MSHCTX_DIFFERENTMACHINE instead of %d\n", stubMsg
.dwDestContext
);
1206 TEST_ZERO(pvDestContext
, "%p");
1207 TEST_POINTER_UNSET(SavedContextHandles
);
1208 TEST_ULONG_UNSET(ParamNumber
);
1209 TEST_ZERO(pRpcChannelBuffer
, "%p");
1210 TEST_ZERO(pArrayInfo
, "%p");
1211 TEST_POINTER_UNSET(SizePtrCountArray
);
1212 TEST_POINTER_UNSET(SizePtrOffsetArray
);
1213 TEST_POINTER_UNSET(SizePtrLengthArray
);
1214 TEST_POINTER_UNSET(pArgQueue
);
1215 TEST_ZERO(dwStubPhase
, "%d");
1216 /* FIXME: where does this value come from? */
1217 trace("LowStackMark is %p\n", stubMsg
.LowStackMark
);
1218 TEST_ZERO(pAsyncMsg
, "%p");
1219 TEST_ZERO(pCorrInfo
, "%p");
1220 TEST_ZERO(pCorrMemory
, "%p");
1221 TEST_ZERO(pMemoryList
, "%p");
1222 TEST_POINTER_UNSET(pCSInfo
);
1223 TEST_POINTER_UNSET(ConformanceMark
);
1224 TEST_POINTER_UNSET(VarianceMark
);
1225 ok(stubMsg
.Unused
== 0xcccccccc, "Unused should have be unset instead of 0x%lx\n", stubMsg
.Unused
);
1226 TEST_POINTER_UNSET(pContext
);
1227 TEST_POINTER_UNSET(ContextHandleHash
);
1228 TEST_POINTER_UNSET(pUserMarshalList
);
1229 TEST_ULONG_PTR_UNSET(Reserved51_3
);
1230 TEST_ULONG_PTR_UNSET(Reserved51_4
);
1231 TEST_ULONG_PTR_UNSET(Reserved51_5
);
1232 #undef TEST_ULONG_UNSET
1233 #undef TEST_POINTER_UNSET
1238 static void test_ndr_allocate(void)
1240 RPC_MESSAGE RpcMessage
;
1241 MIDL_STUB_MESSAGE StubMsg
;
1242 MIDL_STUB_DESC StubDesc
;
1244 struct tag_mem_list_v1_t
1248 struct tag_mem_list_v1_t
*next
;
1250 struct tag_mem_list_v2_t
1255 struct tag_mem_list_v2_t
*next
;
1257 const DWORD magic_MEML
= 'M' << 24 | 'E' << 16 | 'M' << 8 | 'L';
1259 StubDesc
= Object_StubDesc
;
1260 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &StubDesc
, 0);
1262 ok(StubMsg
.pMemoryList
== NULL
, "memlist %p\n", StubMsg
.pMemoryList
);
1263 my_alloc_called
= my_free_called
= 0;
1264 p1
= NdrAllocate(&StubMsg
, 10);
1265 p2
= NdrAllocate(&StubMsg
, 24);
1266 ok(my_alloc_called
== 2, "alloc called %d\n", my_alloc_called
);
1267 ok(StubMsg
.pMemoryList
!= NULL
, "StubMsg.pMemoryList NULL\n");
1268 if(StubMsg
.pMemoryList
)
1270 mem_list_v2
= StubMsg
.pMemoryList
;
1271 if (mem_list_v2
->size
== 24)
1273 trace("v2 mem list format\n");
1274 ok((char *)mem_list_v2
== (char *)p2
+ 24, "expected mem_list_v2 pointer %p, but got %p\n", (char *)p2
+ 24, mem_list_v2
);
1275 ok(mem_list_v2
->magic
== magic_MEML
, "magic %08x\n", mem_list_v2
->magic
);
1276 ok(mem_list_v2
->size
== 24, "wrong size for p2 %d\n", mem_list_v2
->size
);
1277 ok(mem_list_v2
->unknown
== 0, "wrong unknown for p2 0x%x\n", mem_list_v2
->unknown
);
1278 ok(mem_list_v2
->next
!= NULL
, "next NULL\n");
1279 mem_list_v2
= mem_list_v2
->next
;
1282 ok((char *)mem_list_v2
== (char *)p1
+ 16, "expected mem_list_v2 pointer %p, but got %p\n", (char *)p1
+ 16, mem_list_v2
);
1283 ok(mem_list_v2
->magic
== magic_MEML
, "magic %08x\n", mem_list_v2
->magic
);
1284 ok(mem_list_v2
->size
== 16, "wrong size for p1 %d\n", mem_list_v2
->size
);
1285 ok(mem_list_v2
->unknown
== 0, "wrong unknown for p1 0x%x\n", mem_list_v2
->unknown
);
1286 ok(mem_list_v2
->next
== NULL
, "next %p\n", mem_list_v2
->next
);
1291 trace("v1 mem list format\n");
1292 mem_list_v1
= StubMsg
.pMemoryList
;
1293 ok(mem_list_v1
->magic
== magic_MEML
, "magic %08x\n", mem_list_v1
->magic
);
1294 ok(mem_list_v1
->ptr
== p2
, "ptr != p2\n");
1295 ok(mem_list_v1
->next
!= NULL
, "next NULL\n");
1296 mem_list_v1
= mem_list_v1
->next
;
1299 ok(mem_list_v1
->magic
== magic_MEML
, "magic %08x\n", mem_list_v1
->magic
);
1300 ok(mem_list_v1
->ptr
== p1
, "ptr != p1\n");
1301 ok(mem_list_v1
->next
== NULL
, "next %p\n", mem_list_v1
->next
);
1305 /* NdrFree isn't exported so we can't test free'ing */
1308 static void test_conformant_array(void)
1310 RPC_MESSAGE RpcMessage
;
1311 MIDL_STUB_MESSAGE StubMsg
;
1312 MIDL_STUB_DESC StubDesc
;
1314 unsigned char *mem
, *mem_orig
;
1315 unsigned char memsrc
[20];
1317 static const unsigned char fmtstr_conf_array
[] =
1319 0x1b, /* FC_CARRAY */
1321 NdrFcShort( 0x1 ), /* elem size */
1322 0x40, /* Corr desc: const */
1324 NdrFcShort(0x10), /* const = 0x10 */
1329 StubDesc
= Object_StubDesc
;
1330 StubDesc
.pFormatTypes
= fmtstr_conf_array
;
1332 NdrClientInitializeNew(
1338 StubMsg
.BufferLength
= 0;
1339 NdrConformantArrayBufferSize( &StubMsg
,
1341 fmtstr_conf_array
);
1342 ok(StubMsg
.BufferLength
>= 20, "length %d\n", StubMsg
.BufferLength
);
1344 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1345 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1346 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1348 ptr
= NdrConformantArrayMarshall( &StubMsg
, memsrc
, fmtstr_conf_array
);
1349 ok(ptr
== NULL
, "ret %p\n", ptr
);
1350 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== 20, "Buffer %p Start %p len %d\n", StubMsg
.Buffer
, StubMsg
.BufferStart
, 20);
1351 ok(!memcmp(StubMsg
.BufferStart
+ 4, memsrc
, 16), "incorrectly marshaled\n");
1353 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1354 StubMsg
.MemorySize
= 0;
1358 my_alloc_called
= 0;
1359 /* passing mem == NULL with must_alloc == 0 crashes under Windows */
1360 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1361 ok(mem
!= NULL
, "mem not alloced\n");
1362 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1363 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1365 my_alloc_called
= 0;
1366 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1368 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 0);
1369 ok(mem
== mem_orig
, "mem alloced\n");
1370 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1371 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1373 my_alloc_called
= 0;
1374 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1375 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1376 ok(mem
!= mem_orig
, "mem not alloced\n");
1377 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1378 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1381 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1382 NdrConformantArrayFree( &StubMsg
, mem
, fmtstr_conf_array
);
1383 ok(my_free_called
== 0, "free called %d\n", my_free_called
);
1384 StubMsg
.pfnFree(mem
);
1387 my_alloc_called
= 0;
1388 StubMsg
.IsClient
= 0;
1390 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1391 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 0);
1392 ok(mem
== StubMsg
.BufferStart
+ 4, "mem not pointing at buffer\n");
1393 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1394 my_alloc_called
= 0;
1396 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1397 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1398 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1399 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1400 StubMsg
.pfnFree(mem
);
1402 my_alloc_called
= 0;
1404 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1405 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 0);
1406 ok(mem
== mem_orig
, "mem alloced\n");
1407 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1409 my_alloc_called
= 0;
1411 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1412 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1413 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1414 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1415 StubMsg
.pfnFree(mem
);
1416 StubMsg
.pfnFree(mem_orig
);
1418 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1421 static void test_conformant_string(void)
1423 RPC_MESSAGE RpcMessage
;
1424 MIDL_STUB_MESSAGE StubMsg
;
1425 MIDL_STUB_DESC StubDesc
;
1427 unsigned char *mem
, *mem_orig
;
1428 char memsrc
[] = "This is a test string";
1430 static const unsigned char fmtstr_conf_str
[] =
1432 0x11, 0x8, /* FC_RP [simple_pointer] */
1433 0x22, /* FC_C_CSTRING */
1437 StubDesc
= Object_StubDesc
;
1438 StubDesc
.pFormatTypes
= fmtstr_conf_str
;
1440 NdrClientInitializeNew(
1446 StubMsg
.BufferLength
= 0;
1447 NdrPointerBufferSize( &StubMsg
,
1448 (unsigned char *)memsrc
,
1450 ok(StubMsg
.BufferLength
>= sizeof(memsrc
) + 12, "length %d\n", StubMsg
.BufferLength
);
1452 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1453 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1454 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1456 ptr
= NdrPointerMarshall( &StubMsg
, (unsigned char *)memsrc
, fmtstr_conf_str
);
1457 ok(ptr
== NULL
, "ret %p\n", ptr
);
1458 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== sizeof(memsrc
) + 12, "Buffer %p Start %p len %d\n",
1459 StubMsg
.Buffer
, StubMsg
.BufferStart
, StubMsg
.Buffer
- StubMsg
.BufferStart
);
1460 ok(!memcmp(StubMsg
.BufferStart
+ 12, memsrc
, sizeof(memsrc
)), "incorrectly marshaled\n");
1462 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1463 StubMsg
.MemorySize
= 0;
1467 my_alloc_called
= 0;
1468 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1469 mem
= mem_orig
= HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc
));
1470 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 0);
1471 ok(mem
== mem_orig
, "mem not alloced\n");
1472 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1474 my_alloc_called
= 0;
1475 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1476 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 1);
1478 ok(mem
== mem_orig
, "mem not alloced\n");
1479 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1483 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1484 NdrPointerFree( &StubMsg
, mem
, fmtstr_conf_str
);
1485 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
1489 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1490 NdrPointerFree( &StubMsg
, mem
, fmtstr_conf_str
);
1491 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
1494 my_alloc_called
= 0;
1495 StubMsg
.IsClient
= 0;
1497 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1498 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 0);
1499 ok(mem
== StubMsg
.BufferStart
+ 12, "mem not pointing at buffer\n");
1500 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1502 my_alloc_called
= 0;
1504 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1505 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 1);
1507 ok(mem
== StubMsg
.BufferStart
+ 12, "mem not pointing at buffer\n");
1508 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1511 my_alloc_called
= 0;
1513 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1514 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 0);
1515 ok(mem
== StubMsg
.BufferStart
+ 12, "mem not pointing at buffer\n");
1516 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1518 my_alloc_called
= 0;
1520 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1521 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 1);
1523 ok(mem
== StubMsg
.BufferStart
+ 12, "mem not pointing at buffer\n");
1524 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1529 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1530 NdrPointerFree( &StubMsg
, mem
, fmtstr_conf_str
);
1531 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
1533 HeapFree(GetProcessHeap(), 0, mem_orig
);
1534 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1537 static void test_nonconformant_string(void)
1539 RPC_MESSAGE RpcMessage
;
1540 MIDL_STUB_MESSAGE StubMsg
;
1541 MIDL_STUB_DESC StubDesc
;
1543 unsigned char *mem
, *mem_orig
;
1544 unsigned char memsrc
[10] = "This is";
1545 unsigned char memsrc2
[10] = "This is a";
1547 static const unsigned char fmtstr_nonconf_str
[] =
1549 0x26, /* FC_CSTRING */
1551 NdrFcShort( 0xa ), /* 10 */
1554 StubDesc
= Object_StubDesc
;
1555 StubDesc
.pFormatTypes
= fmtstr_nonconf_str
;
1558 NdrClientInitializeNew(
1564 StubMsg
.BufferLength
= 0;
1566 NdrNonConformantStringBufferSize( &StubMsg
,
1567 (unsigned char *)memsrc
,
1568 fmtstr_nonconf_str
);
1569 ok(StubMsg
.BufferLength
>= strlen((char *)memsrc
) + 1 + 8, "length %d\n", StubMsg
.BufferLength
);
1571 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1572 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1573 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1575 ptr
= NdrNonConformantStringMarshall( &StubMsg
, (unsigned char *)memsrc
, fmtstr_nonconf_str
);
1576 ok(ptr
== NULL
, "ret %p\n", ptr
);
1577 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== strlen((char *)memsrc
) + 1 + 8, "Buffer %p Start %p len %d\n",
1578 StubMsg
.Buffer
, StubMsg
.BufferStart
, StubMsg
.Buffer
- StubMsg
.BufferStart
);
1579 ok(!memcmp(StubMsg
.BufferStart
+ 8, memsrc
, strlen((char *)memsrc
) + 1), "incorrectly marshaled\n");
1581 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1582 StubMsg
.MemorySize
= 0;
1586 my_alloc_called
= 0;
1587 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1588 mem
= mem_orig
= HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc
));
1589 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1590 ok(mem
== mem_orig
, "mem alloced\n");
1591 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1593 my_alloc_called
= 0;
1594 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1595 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 1);
1597 ok(mem
== mem_orig
, "mem alloced\n");
1599 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1602 my_alloc_called
= 0;
1603 StubMsg
.IsClient
= 0;
1605 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1606 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1607 ok(mem
!= mem_orig
, "mem not alloced\n");
1608 ok(mem
!= StubMsg
.BufferStart
+ 8, "mem pointing at buffer\n");
1609 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1612 my_alloc_called
= 0;
1614 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1615 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1616 ok(mem
== mem_orig
, "mem alloced\n");
1617 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1619 my_alloc_called
= 0;
1621 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1622 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 1);
1624 ok(mem
== mem_orig
, "mem alloced\n");
1626 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1628 HeapFree(GetProcessHeap(), 0, mem_orig
);
1629 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1632 NdrClientInitializeNew(
1638 StubMsg
.BufferLength
= 0;
1640 NdrNonConformantStringBufferSize( &StubMsg
,
1641 (unsigned char *)memsrc2
,
1642 fmtstr_nonconf_str
);
1643 ok(StubMsg
.BufferLength
>= strlen((char *)memsrc2
) + 1 + 8, "length %d\n", StubMsg
.BufferLength
);
1645 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1646 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1647 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1649 ptr
= NdrNonConformantStringMarshall( &StubMsg
, (unsigned char *)memsrc2
, fmtstr_nonconf_str
);
1650 ok(ptr
== NULL
, "ret %p\n", ptr
);
1651 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== strlen((char *)memsrc2
) + 1 + 8, "Buffer %p Start %p len %d\n",
1652 StubMsg
.Buffer
, StubMsg
.BufferStart
, StubMsg
.Buffer
- StubMsg
.BufferStart
);
1653 ok(!memcmp(StubMsg
.BufferStart
+ 8, memsrc2
, strlen((char *)memsrc2
) + 1), "incorrectly marshaled\n");
1655 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1656 StubMsg
.MemorySize
= 0;
1660 my_alloc_called
= 0;
1661 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1662 mem
= mem_orig
= HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc
));
1663 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1664 ok(mem
== mem_orig
, "mem alloced\n");
1665 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1667 my_alloc_called
= 0;
1668 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1669 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 1);
1671 ok(mem
== mem_orig
, "mem alloced\n");
1673 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1676 my_alloc_called
= 0;
1677 StubMsg
.IsClient
= 0;
1679 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1680 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1681 ok(mem
!= mem_orig
, "mem not alloced\n");
1682 ok(mem
!= StubMsg
.BufferStart
+ 8, "mem pointing at buffer\n");
1683 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1686 my_alloc_called
= 0;
1688 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1689 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1690 ok(mem
== mem_orig
, "mem alloced\n");
1691 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1693 my_alloc_called
= 0;
1695 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1696 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 1);
1698 ok(mem
== mem_orig
, "mem alloced\n");
1700 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1702 HeapFree(GetProcessHeap(), 0, mem_orig
);
1703 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1706 static void test_ndr_buffer(void)
1708 static unsigned char ncalrpc
[] = "ncalrpc";
1709 static unsigned char endpoint
[] = "winetest:" __FILE__
;
1710 RPC_MESSAGE RpcMessage
;
1711 MIDL_STUB_MESSAGE StubMsg
;
1712 MIDL_STUB_DESC StubDesc
= Object_StubDesc
;
1714 unsigned char *binding
;
1715 RPC_BINDING_HANDLE Handle
;
1718 StubDesc
.RpcInterfaceInformation
= (void *)&IFoo___RpcServerInterface
;
1720 ok(RPC_S_OK
== RpcServerUseProtseqEp(ncalrpc
, 20, endpoint
, NULL
), "RpcServerUseProtseqEp\n");
1721 ok(RPC_S_OK
== RpcServerRegisterIf(IFoo_v0_0_s_ifspec
, NULL
, NULL
), "RpcServerRegisterIf\n");
1722 ok(RPC_S_OK
== RpcServerListen(1, 20, TRUE
), "RpcServerListen\n");
1724 status
= RpcStringBindingCompose(NULL
, ncalrpc
, NULL
, endpoint
, NULL
, &binding
);
1725 ok(status
== RPC_S_OK
, "RpcStringBindingCompose failed (%lu)\n", status
);
1727 status
= RpcBindingFromStringBinding(binding
, &Handle
);
1728 ok(status
== RPC_S_OK
, "RpcBindingFromStringBinding failed (%lu)\n", status
);
1729 RpcStringFree(&binding
);
1731 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &StubDesc
, 5);
1733 ret
= NdrGetBuffer(&StubMsg
, 10, Handle
);
1734 ok(ret
== StubMsg
.Buffer
, "NdrGetBuffer should have returned the same value as StubMsg.Buffer instead of %p\n", ret
);
1735 ok(RpcMessage
.Handle
!= NULL
, "RpcMessage.Handle should not have been NULL\n");
1736 ok(RpcMessage
.Buffer
!= NULL
, "RpcMessage.Buffer should not have been NULL\n");
1737 ok(RpcMessage
.BufferLength
== 10, "RpcMessage.BufferLength should have been 10 instead of %d\n", RpcMessage
.BufferLength
);
1738 ok(RpcMessage
.RpcFlags
== 0, "RpcMessage.RpcFlags should have been 0x0 instead of 0x%lx\n", RpcMessage
.RpcFlags
);
1739 ok(StubMsg
.Buffer
!= NULL
, "Buffer should not have been NULL\n");
1740 ok(!StubMsg
.BufferStart
, "BufferStart should have been NULL instead of %p\n", StubMsg
.BufferStart
);
1741 ok(!StubMsg
.BufferEnd
, "BufferEnd should have been NULL instead of %p\n", StubMsg
.BufferEnd
);
1743 ok(StubMsg
.BufferLength
== 0, "BufferLength should have left as 0 instead of being set to %d\n", StubMsg
.BufferLength
);
1744 ok(StubMsg
.fBufferValid
== TRUE
, "fBufferValid should have been TRUE instead of 0x%x\n", StubMsg
.fBufferValid
);
1746 StubMsg
.BufferLength
= 1;
1747 NdrFreeBuffer(&StubMsg
);
1748 ok(RpcMessage
.Handle
!= NULL
, "RpcMessage.Handle should not have been NULL\n");
1749 ok(RpcMessage
.Buffer
!= NULL
, "RpcMessage.Buffer should not have been NULL\n");
1750 ok(RpcMessage
.BufferLength
== 10, "RpcMessage.BufferLength should have been left as 10 instead of %d\n", RpcMessage
.BufferLength
);
1751 ok(StubMsg
.Buffer
!= NULL
, "Buffer should not have been NULL\n");
1752 ok(StubMsg
.BufferLength
== 1, "BufferLength should have left as 1 instead of being set to %d\n", StubMsg
.BufferLength
);
1753 ok(StubMsg
.fBufferValid
== FALSE
, "fBufferValid should have been FALSE instead of 0x%x\n", StubMsg
.fBufferValid
);
1755 /* attempt double-free */
1756 NdrFreeBuffer(&StubMsg
);
1758 RpcBindingFree(&Handle
);
1760 status
= RpcServerUnregisterIf(NULL
, NULL
, FALSE
);
1761 ok(status
== RPC_S_OK
, "RpcServerUnregisterIf failed (%lu)\n", status
);
1764 static void test_NdrMapCommAndFaultStatus(void)
1766 RPC_STATUS rpc_status
;
1767 MIDL_STUB_MESSAGE StubMsg
;
1768 RPC_MESSAGE RpcMessage
;
1770 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &Object_StubDesc
, 5);
1772 for (rpc_status
= 0; rpc_status
< 10000; rpc_status
++)
1775 ULONG comm_status
= 0;
1776 ULONG fault_status
= 0;
1777 ULONG expected_comm_status
= 0;
1778 ULONG expected_fault_status
= 0;
1779 status
= NdrMapCommAndFaultStatus(&StubMsg
, &comm_status
, &fault_status
, rpc_status
);
1780 ok(status
== RPC_S_OK
, "NdrMapCommAndFaultStatus failed with error %ld\n", status
);
1783 case ERROR_INVALID_HANDLE
:
1784 case RPC_S_INVALID_BINDING
:
1785 case RPC_S_UNKNOWN_IF
:
1786 case RPC_S_SERVER_UNAVAILABLE
:
1787 case RPC_S_SERVER_TOO_BUSY
:
1788 case RPC_S_CALL_FAILED_DNE
:
1789 case RPC_S_PROTOCOL_ERROR
:
1790 case RPC_S_UNSUPPORTED_TRANS_SYN
:
1791 case RPC_S_UNSUPPORTED_TYPE
:
1792 case RPC_S_PROCNUM_OUT_OF_RANGE
:
1793 case EPT_S_NOT_REGISTERED
:
1794 case RPC_S_COMM_FAILURE
:
1795 expected_comm_status
= rpc_status
;
1798 expected_fault_status
= rpc_status
;
1800 ok(comm_status
== expected_comm_status
, "NdrMapCommAndFaultStatus should have mapped %ld to comm status %d instead of %d\n",
1801 rpc_status
, expected_comm_status
, comm_status
);
1802 ok(fault_status
== expected_fault_status
, "NdrMapCommAndFaultStatus should have mapped %ld to fault status %d instead of %d\n",
1803 rpc_status
, expected_fault_status
, fault_status
);
1807 START_TEST( ndr_marshall
)
1809 test_ndr_simple_type();
1810 test_simple_types();
1811 test_nontrivial_pointer_types();
1812 test_simple_struct();
1813 test_fullpointer_xlat();
1816 test_ndr_allocate();
1817 test_conformant_array();
1818 test_conformant_string();
1819 test_nonconformant_string();
1821 test_NdrMapCommAndFaultStatus();