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
;
100 static BOOL use_pointer_ids
= FALSE
;
102 static void determine_pointer_marshalling_style(void)
104 RPC_MESSAGE RpcMessage
;
105 MIDL_STUB_MESSAGE StubMsg
;
106 MIDL_STUB_DESC StubDesc
;
109 static const unsigned char fmtstr_up_char
[] =
111 0x12, 0x8, /* FC_UP [simple_pointer] */
116 StubDesc
= Object_StubDesc
;
117 StubDesc
.pFormatTypes
= NULL
;
119 NdrClientInitializeNew(
125 StubMsg
.BufferLength
= 8;
126 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
127 NdrPointerMarshall(&StubMsg
, (unsigned char*)&ch
, fmtstr_up_char
);
128 ok(StubMsg
.Buffer
== StubMsg
.BufferStart
+ 5, "%p %p\n", StubMsg
.Buffer
, StubMsg
.BufferStart
);
130 use_pointer_ids
= (*(unsigned int *)StubMsg
.BufferStart
!= (unsigned int)&ch
);
131 trace("Pointer marshalling using %s\n", use_pointer_ids
? "pointer ids" : "pointer value");
133 HeapFree(GetProcessHeap(), 0, StubMsg
.BufferStart
);
136 static void test_ndr_simple_type(void)
138 RPC_MESSAGE RpcMessage
;
139 MIDL_STUB_MESSAGE StubMsg
;
140 MIDL_STUB_DESC StubDesc
;
143 StubDesc
= Object_StubDesc
;
144 StubDesc
.pFormatTypes
= NULL
;
146 NdrClientInitializeNew(
152 StubMsg
.BufferLength
= 16;
153 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
155 NdrSimpleTypeMarshall(&StubMsg
, (unsigned char*)&l
, 8 /* FC_LONG */);
156 ok(StubMsg
.Buffer
== StubMsg
.BufferStart
+ 4, "%p %p\n", StubMsg
.Buffer
, StubMsg
.BufferStart
);
157 ok(*(long*)StubMsg
.BufferStart
== l
, "%ld\n", *(long*)StubMsg
.BufferStart
);
159 StubMsg
.Buffer
= StubMsg
.BufferStart
+ 1;
160 NdrSimpleTypeMarshall(&StubMsg
, (unsigned char*)&l
, 8 /* FC_LONG */);
161 ok(StubMsg
.Buffer
== StubMsg
.BufferStart
+ 8, "%p %p\n", StubMsg
.Buffer
, StubMsg
.BufferStart
);
162 ok(*(long*)(StubMsg
.BufferStart
+ 4) == l
, "%ld\n", *(long*)StubMsg
.BufferStart
);
164 StubMsg
.Buffer
= StubMsg
.BufferStart
+ 1;
165 NdrSimpleTypeUnmarshall(&StubMsg
, (unsigned char*)&l2
, 8 /* FC_LONG */);
166 ok(StubMsg
.Buffer
== StubMsg
.BufferStart
+ 8, "%p %p\n", StubMsg
.Buffer
, StubMsg
.BufferStart
);
167 ok(l2
== l
, "%ld\n", l2
);
169 HeapFree(GetProcessHeap(), 0, StubMsg
.BufferStart
);
172 static void test_pointer_marshal(const unsigned char *formattypes
,
175 const void *wiredata
,
177 int(*cmp
)(const void*,const void*,size_t),
178 long num_additional_allocs
,
181 RPC_MESSAGE RpcMessage
;
182 MIDL_STUB_MESSAGE StubMsg
;
183 MIDL_STUB_DESC StubDesc
;
186 unsigned char *mem
, *mem_orig
;
188 my_alloc_called
= my_free_called
= 0;
192 StubDesc
= Object_StubDesc
;
193 StubDesc
.pFormatTypes
= formattypes
;
195 NdrClientInitializeNew(
201 StubMsg
.BufferLength
= 0;
202 NdrPointerBufferSize( &StubMsg
,
205 ok(StubMsg
.BufferLength
>= wiredatalen
, "%s: length %d\n", msgpfx
, StubMsg
.BufferLength
);
207 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
208 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
209 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
211 memset(StubMsg
.BufferStart
, 0x0, StubMsg
.BufferLength
); /* This is a hack to clear the padding between the ptr and longlong/double */
213 ptr
= NdrPointerMarshall( &StubMsg
, memsrc
, formattypes
);
214 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
215 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
216 ok(!memcmp(StubMsg
.BufferStart
, wiredata
, wiredatalen
), "%s: incorrectly marshaled\n", msgpfx
);
218 StubMsg
.Buffer
= StubMsg
.BufferStart
;
219 StubMsg
.MemorySize
= 0;
223 /* NdrPointerMemorySize crashes under Wine */
224 size
= NdrPointerMemorySize( &StubMsg
, formattypes
);
225 ok(size
== StubMsg
.MemorySize
, "%s: mem size %u size %u\n", msgpfx
, StubMsg
.MemorySize
, size
);
226 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
227 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
228 ok(size
== srcsize
+ 4, "%s: mem size %u\n", msgpfx
, size
);
230 ok(size
== srcsize
, "%s: mem size %u\n", msgpfx
, size
);
232 StubMsg
.Buffer
= StubMsg
.BufferStart
;
233 StubMsg
.MemorySize
= 16;
234 size
= NdrPointerMemorySize( &StubMsg
, formattypes
);
235 ok(size
== StubMsg
.MemorySize
, "%s: mem size %u size %u\n", msgpfx
, StubMsg
.MemorySize
, size
);
236 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
237 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
238 ok(size
== srcsize
+ 4 + 16, "%s: mem size %u\n", msgpfx
, size
);
240 ok(size
== srcsize
+ 16, "%s: mem size %u\n", msgpfx
, size
);
242 StubMsg
.Buffer
= StubMsg
.BufferStart
;
243 StubMsg
.MemorySize
= 1;
244 size
= NdrPointerMemorySize( &StubMsg
, formattypes
);
245 ok(size
== StubMsg
.MemorySize
, "%s: mem size %u size %u\n", msgpfx
, StubMsg
.MemorySize
, size
);
246 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
247 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
248 ok(size
== srcsize
+ 4 + (srcsize
== 8 ? 8 : 4), "%s: mem size %u\n", msgpfx
, size
);
250 ok(size
== srcsize
+ (srcsize
== 8 ? 8 : 4), "%s: mem size %u\n", msgpfx
, size
);
254 if(formattypes
[1] & 0x10) size
+= 4;
256 StubMsg
.Buffer
= StubMsg
.BufferStart
;
257 StubMsg
.MemorySize
= 0;
258 mem_orig
= mem
= HeapAlloc(GetProcessHeap(), 0, size
);
260 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
262 ptr
= NdrPointerUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
263 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
264 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
265 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
266 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
267 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
268 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
271 /* reset the buffer and call with must alloc */
272 StubMsg
.Buffer
= StubMsg
.BufferStart
;
273 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
275 ptr
= NdrPointerUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
276 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
277 /* doesn't allocate mem in this case */
279 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
281 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
282 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
283 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
286 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
289 if(formattypes
[0] != 0x11 /* FC_RP */)
291 /* now pass the address of a NULL ptr */
293 StubMsg
.Buffer
= StubMsg
.BufferStart
;
294 ptr
= NdrPointerUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
295 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
296 ok(mem
!= StubMsg
.BufferStart
+ wiredatalen
- srcsize
, "%s: mem points to buffer %p %p\n", msgpfx
, mem
, StubMsg
.BufferStart
);
297 ok(!cmp(mem
, memsrc
, size
), "%s: incorrectly unmarshaled\n", msgpfx
);
298 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
299 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
300 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
302 NdrPointerFree(&StubMsg
, mem
, formattypes
);
304 /* again pass address of NULL ptr, but pretend we're a server */
306 StubMsg
.Buffer
= StubMsg
.BufferStart
;
307 StubMsg
.IsClient
= 0;
308 ptr
= NdrPointerUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
309 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
310 if (formattypes
[2] == 0xd /* FC_ENUM16 */)
311 ok(mem
!= StubMsg
.BufferStart
+ wiredatalen
- srcsize
, "%s: mem points to buffer %p %p\n", msgpfx
, mem
, StubMsg
.BufferStart
);
313 ok(mem
== StubMsg
.BufferStart
+ wiredatalen
- srcsize
, "%s: mem doesn't point to buffer %p %p\n", msgpfx
, mem
, StubMsg
.BufferStart
);
314 ok(!cmp(mem
, memsrc
, size
), "%s: incorrectly unmarshaled\n", msgpfx
);
315 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
316 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
317 if (formattypes
[2] != 0xd /* FC_ENUM16 */) {
318 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
322 HeapFree(GetProcessHeap(), 0, mem_orig
);
323 HeapFree(GetProcessHeap(), 0, StubMsg
.BufferStart
);
326 static int deref_cmp(const void *s1
, const void *s2
, size_t num
)
328 return memcmp(*(const void *const *)s1
, *(const void *const *)s2
, num
);
332 static void test_simple_types(void)
334 unsigned char wiredata
[16];
336 unsigned char *ch_ptr
;
344 static const unsigned char fmtstr_up_char
[] =
346 0x12, 0x8, /* FC_UP [simple_pointer] */
350 static const unsigned char fmtstr_up_byte
[] =
352 0x12, 0x8, /* FC_UP [simple_pointer] */
356 static const unsigned char fmtstr_up_small
[] =
358 0x12, 0x8, /* FC_UP [simple_pointer] */
362 static const unsigned char fmtstr_up_usmall
[] =
364 0x12, 0x8, /* FC_UP [simple_pointer] */
368 static const unsigned char fmtstr_rp_char
[] =
370 0x11, 0x8, /* FC_RP [simple_pointer] */
374 static const unsigned char fmtstr_rpup_char
[] =
376 0x11, 0x14, /* FC_RP [alloced_on_stack] */
377 NdrFcShort( 0x2 ), /* Offset= 2 (4) */
378 0x12, 0x8, /* FC_UP [simple_pointer] */
382 static const unsigned char fmtstr_rpup_char2
[] =
384 0x11, 0x04, /* FC_RP [alloced_on_stack] */
385 NdrFcShort( 0x2 ), /* Offset= 2 (4) */
386 0x12, 0x8, /* FC_UP [simple_pointer] */
391 static const unsigned char fmtstr_up_wchar
[] =
393 0x12, 0x8, /* FC_UP [simple_pointer] */
397 static const unsigned char fmtstr_up_short
[] =
399 0x12, 0x8, /* FC_UP [simple_pointer] */
403 static const unsigned char fmtstr_up_ushort
[] =
405 0x12, 0x8, /* FC_UP [simple_pointer] */
409 static const unsigned char fmtstr_up_enum16
[] =
411 0x12, 0x8, /* FC_UP [simple_pointer] */
415 static const unsigned char fmtstr_up_long
[] =
417 0x12, 0x8, /* FC_UP [simple_pointer] */
421 static const unsigned char fmtstr_up_ulong
[] =
423 0x12, 0x8, /* FC_UP [simple_pointer] */
427 static const unsigned char fmtstr_up_enum32
[] =
429 0x12, 0x8, /* FC_UP [simple_pointer] */
433 static const unsigned char fmtstr_up_errorstatus
[] =
435 0x12, 0x8, /* FC_UP [simple_pointer] */
436 0x10, /* FC_ERROR_STATUS_T */
440 static const unsigned char fmtstr_up_longlong
[] =
442 0x12, 0x8, /* FC_UP [simple_pointer] */
446 static const unsigned char fmtstr_up_float
[] =
448 0x12, 0x8, /* FC_UP [simple_pointer] */
452 static const unsigned char fmtstr_up_double
[] =
454 0x12, 0x8, /* FC_UP [simple_pointer] */
462 *(unsigned int *)wiredata
= 0x20000;
464 *(unsigned int *)wiredata
= (unsigned int)ch_ptr
;
467 test_pointer_marshal(fmtstr_up_char
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_char");
468 test_pointer_marshal(fmtstr_up_byte
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_byte");
469 test_pointer_marshal(fmtstr_up_small
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_small");
470 test_pointer_marshal(fmtstr_up_usmall
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_usmall");
472 test_pointer_marshal(fmtstr_rp_char
, ch_ptr
, 1, &ch
, 1, NULL
, 0, "rp_char");
474 test_pointer_marshal(fmtstr_rpup_char
, &ch_ptr
, 1, wiredata
, 5, deref_cmp
, 1, "rpup_char");
475 test_pointer_marshal(fmtstr_rpup_char2
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "rpup_char2");
479 *(unsigned int *)wiredata
= 0x20000;
481 *(unsigned int *)wiredata
= (unsigned int)&s
;
482 *(unsigned short*)(wiredata
+ 4) = s
;
484 test_pointer_marshal(fmtstr_up_wchar
, &s
, 2, wiredata
, 6, NULL
, 0, "up_wchar");
485 test_pointer_marshal(fmtstr_up_short
, &s
, 2, wiredata
, 6, NULL
, 0, "up_short");
486 test_pointer_marshal(fmtstr_up_ushort
, &s
, 2, wiredata
, 6, NULL
, 0, "up_ushort");
490 *(unsigned int *)wiredata
= 0x20000;
492 *(unsigned int *)wiredata
= (unsigned int)&i
;
493 *(unsigned short*)(wiredata
+ 4) = i
;
494 test_pointer_marshal(fmtstr_up_enum16
, &i
, 2, wiredata
, 6, NULL
, 0, "up_enum16");
498 *(unsigned int *)wiredata
= 0x20000;
500 *(unsigned int *)wiredata
= (unsigned int)&l
;
501 *(unsigned long*)(wiredata
+ 4) = l
;
503 test_pointer_marshal(fmtstr_up_long
, &l
, 4, wiredata
, 8, NULL
, 0, "up_long");
504 test_pointer_marshal(fmtstr_up_ulong
, &l
, 4, wiredata
, 8, NULL
, 0, "up_ulong");
505 test_pointer_marshal(fmtstr_up_enum32
, &l
, 4, wiredata
, 8, NULL
, 0, "up_emun32");
506 test_pointer_marshal(fmtstr_up_errorstatus
, &l
, 4, wiredata
, 8, NULL
, 0, "up_errorstatus");
508 ll
= ((ULONGLONG
)0xcafebabe) << 32 | 0xdeadbeef;
510 *(unsigned int *)wiredata
= 0x20000;
512 *(unsigned int *)wiredata
= (unsigned int)&ll
;
513 *(unsigned int **)(wiredata
+ 4) = 0;
514 *(ULONGLONG
*)(wiredata
+ 8) = ll
;
515 test_pointer_marshal(fmtstr_up_longlong
, &ll
, 8, wiredata
, 16, NULL
, 0, "up_longlong");
519 *(unsigned int *)wiredata
= 0x20000;
521 *(unsigned int *)wiredata
= (unsigned int)&f
;
522 *(float*)(wiredata
+ 4) = f
;
523 test_pointer_marshal(fmtstr_up_float
, &f
, 4, wiredata
, 8, NULL
, 0, "up_float");
527 *(unsigned int *)wiredata
= 0x20000;
529 *(unsigned int *)wiredata
= (unsigned int)&d
;
530 *(unsigned int *)(wiredata
+ 4) = 0;
531 *(double*)(wiredata
+ 8) = d
;
532 test_pointer_marshal(fmtstr_up_double
, &d
, 8, wiredata
, 16, NULL
, 0, "up_double");
536 static void test_nontrivial_pointer_types(void)
538 RPC_MESSAGE RpcMessage
;
539 MIDL_STUB_MESSAGE StubMsg
;
540 MIDL_STUB_DESC StubDesc
;
545 unsigned char *mem
, *mem_orig
;
547 static const unsigned char fmtstr_ref_unique_out
[] =
549 0x12, 0x8, /* FC_UP [simple_pointer] */
552 0x11, 0x14, /* FC_RP [alloced_on_stack] [pointer_deref] */
553 NdrFcShort( 0xfffffffa ), /* Offset= -6 (0) */
560 StubDesc
= Object_StubDesc
;
561 StubDesc
.pFormatTypes
= fmtstr_ref_unique_out
;
563 NdrClientInitializeNew(
569 StubMsg
.BufferLength
= 0;
570 NdrPointerBufferSize( &StubMsg
,
572 &fmtstr_ref_unique_out
[4] );
574 /* Windows overestimates the buffer size */
575 ok(StubMsg
.BufferLength
>= 5, "length %d\n", StubMsg
.BufferLength
);
577 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
578 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
579 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
581 ptr
= NdrPointerMarshall( &StubMsg
, (unsigned char *)p1
, &fmtstr_ref_unique_out
[4] );
582 ok(ptr
== NULL
, "ret %p\n", ptr
);
583 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== 5, "Buffer %p Start %p len %d\n",
584 StubMsg
.Buffer
, StubMsg
.BufferStart
, StubMsg
.Buffer
- StubMsg
.BufferStart
);
585 ok(*(unsigned int *)StubMsg
.BufferStart
!= 0, "pointer ID marshalled incorrectly\n");
586 ok(*(unsigned char *)(StubMsg
.BufferStart
+ 4) == 0x22, "char data marshalled incorrectly: 0x%x\n",
587 *(unsigned char *)(StubMsg
.BufferStart
+ 4));
589 StubMsg
.Buffer
= StubMsg
.BufferStart
;
590 StubMsg
.MemorySize
= 0;
595 StubMsg
.Buffer
= StubMsg
.BufferStart
;
596 mem
= mem_orig
= HeapAlloc(GetProcessHeap(), 0, sizeof(void *));
597 *(void **)mem
= NULL
;
598 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 0);
599 ok(mem
== mem_orig
, "mem alloced\n");
600 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
603 StubMsg
.Buffer
= StubMsg
.BufferStart
;
604 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 1);
606 ok(mem
== mem_orig
, "mem alloced\n");
607 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
611 StubMsg
.Buffer
= StubMsg
.BufferStart
;
612 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
613 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
615 mem
= my_alloc(sizeof(void *));
616 *(void **)mem
= NULL
;
618 StubMsg
.Buffer
= StubMsg
.BufferStart
;
619 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
620 ok(my_free_called
== 0, "free called %d\n", my_free_called
);
623 mem
= my_alloc(sizeof(void *));
624 *(void **)mem
= my_alloc(sizeof(char));
626 StubMsg
.Buffer
= StubMsg
.BufferStart
;
627 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
628 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
633 StubMsg
.IsClient
= 0;
635 StubMsg
.Buffer
= StubMsg
.BufferStart
;
636 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 0);
637 ok(mem
!= StubMsg
.BufferStart
, "mem pointing at buffer\n");
639 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
640 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
644 StubMsg
.Buffer
= StubMsg
.BufferStart
;
645 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 1);
646 ok(mem
!= StubMsg
.BufferStart
, "mem pointing at buffer\n");
648 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
649 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
653 *(void **)mem
= NULL
;
654 StubMsg
.Buffer
= StubMsg
.BufferStart
;
655 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 0);
657 ok(mem
== mem_orig
, "mem alloced\n");
658 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
663 *(void **)mem
= NULL
;
664 StubMsg
.Buffer
= StubMsg
.BufferStart
;
665 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 1);
667 ok(mem
== mem_orig
, "mem alloced\n");
668 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
671 mem
= my_alloc(sizeof(void *));
672 *(void **)mem
= NULL
;
674 StubMsg
.Buffer
= StubMsg
.BufferStart
;
675 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
676 ok(my_free_called
== 0, "free called %d\n", my_free_called
);
679 mem
= my_alloc(sizeof(void *));
680 *(void **)mem
= my_alloc(sizeof(char));
682 StubMsg
.Buffer
= StubMsg
.BufferStart
;
683 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
684 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
687 HeapFree(GetProcessHeap(), 0, mem_orig
);
688 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
691 static void test_simple_struct_marshal(const unsigned char *formattypes
,
694 const void *wiredata
,
696 int(*cmp
)(const void*,const void*,size_t),
697 long num_additional_allocs
,
700 RPC_MESSAGE RpcMessage
;
701 MIDL_STUB_MESSAGE StubMsg
;
702 MIDL_STUB_DESC StubDesc
;
705 unsigned char *mem
, *mem_orig
;
707 my_alloc_called
= my_free_called
= 0;
711 StubDesc
= Object_StubDesc
;
712 StubDesc
.pFormatTypes
= formattypes
;
714 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &StubDesc
, 0);
716 StubMsg
.BufferLength
= 0;
717 NdrSimpleStructBufferSize( &StubMsg
, (unsigned char *)memsrc
, formattypes
);
718 ok(StubMsg
.BufferLength
>= wiredatalen
, "%s: length %d\n", msgpfx
, StubMsg
.BufferLength
);
719 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
720 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
721 ptr
= NdrSimpleStructMarshall( &StubMsg
, (unsigned char*)memsrc
, formattypes
);
722 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
723 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
724 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));
728 /* FIXME: Causes Wine to crash */
729 StubMsg
.Buffer
= StubMsg
.BufferStart
;
730 StubMsg
.MemorySize
= 0;
731 size
= NdrSimpleStructMemorySize( &StubMsg
, formattypes
);
732 ok(size
== StubMsg
.MemorySize
, "%s: size != MemorySize\n", msgpfx
);
733 ok(size
== srcsize
, "%s: mem size %u\n", msgpfx
, size
);
734 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
736 StubMsg
.Buffer
= StubMsg
.BufferStart
;
737 size
= NdrSimpleStructMemorySize( &StubMsg
, formattypes
);
739 ok(size
== StubMsg
.MemorySize
, "%s: size != MemorySize\n", msgpfx
);
741 ok(StubMsg
.MemorySize
== ((srcsize
+ 3) & ~3) + srcsize
, "%s: mem size %u\n", msgpfx
, size
);
742 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
745 /*** Unmarshalling first with must_alloc false ***/
747 StubMsg
.Buffer
= StubMsg
.BufferStart
;
748 StubMsg
.MemorySize
= 0;
749 mem_orig
= mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, srcsize
);
750 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
751 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
752 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
753 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
754 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
755 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
757 ok(StubMsg
.MemorySize
== 0, "%s: memorysize touched in unmarshal\n", msgpfx
);
759 /* If we're a server we still use the supplied memory */
760 StubMsg
.Buffer
= StubMsg
.BufferStart
;
761 StubMsg
.IsClient
= 0;
762 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
763 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
764 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
765 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
766 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
768 ok(StubMsg
.MemorySize
== 0, "%s: memorysize touched in unmarshal\n", msgpfx
);
770 /* ...unless we pass a NULL ptr, then the buffer is used.
771 Passing a NULL ptr while we're a client && !must_alloc
772 crashes on Windows, so we won't do that. */
775 StubMsg
.IsClient
= 0;
776 StubMsg
.Buffer
= StubMsg
.BufferStart
;
777 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
778 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
779 ok(mem
== StubMsg
.BufferStart
, "%s: mem not equal buffer\n", msgpfx
);
780 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
781 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
783 ok(StubMsg
.MemorySize
== 0, "%s: memorysize touched in unmarshal\n", msgpfx
);
785 /*** now must_alloc is true ***/
787 /* with must_alloc set we always allocate new memory whether or not we're
788 a server and also when passing NULL */
790 StubMsg
.IsClient
= 1;
791 StubMsg
.Buffer
= StubMsg
.BufferStart
;
792 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
793 ok(ptr
== NULL
, "ret %p\n", ptr
);
794 ok(mem
!= mem_orig
, "mem not changed %p %p\n", mem
, mem_orig
);
795 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
796 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
798 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
801 StubMsg
.Buffer
= StubMsg
.BufferStart
;
802 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
803 ok(ptr
== NULL
, "ret %p\n", ptr
);
804 ok(mem
!= mem_orig
, "mem not changed %p %p\n", mem
, mem_orig
);
805 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
806 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
808 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
811 StubMsg
.Buffer
= StubMsg
.BufferStart
;
812 StubMsg
.IsClient
= 0;
813 StubMsg
.ReuseBuffer
= 1;
814 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
815 ok(ptr
== NULL
, "ret %p\n", ptr
);
816 ok(mem
!= mem_orig
, "mem not changed %p %p\n", mem
, mem_orig
);
817 ok(mem
!= StubMsg
.BufferStart
, "mem is buffer mem\n");
818 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
819 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
821 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
824 StubMsg
.Buffer
= StubMsg
.BufferStart
;
825 StubMsg
.IsClient
= 0;
826 StubMsg
.ReuseBuffer
= 1;
827 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
828 ok(ptr
== NULL
, "ret %p\n", ptr
);
829 ok(mem
!= StubMsg
.BufferStart
, "mem is buffer mem\n");
830 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
831 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
833 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
835 HeapFree(GetProcessHeap(), 0, mem_orig
);
836 HeapFree(GetProcessHeap(), 0, StubMsg
.BufferStart
);
846 static int ps1_cmp(const void *s1
, const void *s2
, size_t num
)
848 const ps1_t
*p1
, *p2
;
856 if(p1
->pl1
&& p2
->pl1
)
858 if(*p1
->pl1
!= *p2
->pl1
)
861 else if(p1
->pl1
|| p1
->pl1
)
864 if(p1
->pc1
&& p2
->pc1
)
866 if(*p1
->pc1
!= *p2
->pc1
)
869 else if(p1
->pc1
|| p1
->pc1
)
875 static void test_simple_struct(void)
877 unsigned char wiredata
[28];
878 unsigned long wiredatalen
;
883 static const unsigned char fmtstr_simple_struct
[] =
885 0x12, 0x0, /* FC_UP */
886 NdrFcShort( 0x2 ), /* Offset=2 */
887 0x15, 0x3, /* FC_STRUCT [align 4] */
888 NdrFcShort( 0x18 ), /* [size 24] */
891 0x38, /* FC_ALIGNM4 */
894 0x39, /* FC_ALIGNM8 */
905 static const unsigned char fmtstr_pointer_struct
[] =
907 0x12, 0x0, /* FC_UP */
908 NdrFcShort( 0x2 ), /* Offset=2 */
909 0x16, 0x3, /* FC_PSTRUCT [align 4] */
910 NdrFcShort( 0xc ), /* [size 12] */
913 0x46, /* FC_NO_REPEAT */
915 NdrFcShort( 0x4 ), /* 4 */
916 NdrFcShort( 0x4 ), /* 4 */
917 0x13, 0x8, /* FC_OP [simple_pointer] */
920 0x46, /* FC_NO_REPEAT */
922 NdrFcShort( 0x8 ), /* 8 */
923 NdrFcShort( 0x8 ), /* 8 */
924 0x13, 0x8, /* FC_OP [simple_pointer] */
941 s1
.ll
= ((LONGLONG
) 0xbadefeed << 32) | 0x2468ace0;
944 memcpy(wiredata
, &s1
, wiredatalen
);
945 test_simple_struct_marshal(fmtstr_simple_struct
+ 4, &s1
, 24, wiredata
, 24, NULL
, 0, "struct");
948 *(unsigned int *)wiredata
= 0x20000;
950 *(unsigned int *)wiredata
= (unsigned int)&s1
;
951 memcpy(wiredata
+ 4, &s1
, wiredatalen
);
954 /* one of the unmarshallings crashes Wine */
955 test_pointer_marshal(fmtstr_simple_struct
, &s1
, 24, wiredata
, 28, NULL
, 0, "struct");
958 /* zero the entire structure, including the hole */
959 memset(&ps1
, 0, sizeof(&ps1
));
967 *(unsigned int *)(wiredata
+ 4) = 0xdeadbeef;
970 *(unsigned int *)(wiredata
+ 8) = 0x20000;
971 *(unsigned int *)(wiredata
+ 12) = 0x20004;
975 *(unsigned int *)(wiredata
+ 8) = (unsigned int)&l
;
976 *(unsigned int *)(wiredata
+ 12) = (unsigned int)&c
;
978 memcpy(wiredata
+ 16, &l
, 4);
979 memcpy(wiredata
+ 20, &c
, 1);
981 test_simple_struct_marshal(fmtstr_pointer_struct
+ 4, &ps1
, 17, wiredata
+ 4, 17, ps1_cmp
, 2, "pointer_struct");
983 *(unsigned int *)wiredata
= 0x20000;
985 *(unsigned int *)wiredata
= (unsigned int)&ps1
;
988 /* one of the unmarshallings crashes Wine */
989 test_pointer_marshal(fmtstr_pointer_struct
, &ps1
, 17, wiredata
, 21, ps1_cmp
, 2, "pointer_struct");
993 static void test_fullpointer_xlat(void)
995 PFULL_PTR_XLAT_TABLES pXlatTables
;
1000 pXlatTables
= NdrFullPointerXlatInit(2, XLAT_CLIENT
);
1002 /* "marshaling" phase */
1004 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
1005 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1006 ok(RefId
== 0x1, "RefId should be 0x1 instead of 0x%x\n", RefId
);
1008 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 0, &RefId
);
1009 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1010 ok(RefId
== 0x1, "RefId should be 0x1 instead of 0x%x\n", RefId
);
1012 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebabe, 0, &RefId
);
1013 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1014 ok(RefId
== 0x2, "RefId should be 0x2 instead of 0x%x\n", RefId
);
1016 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 0, &RefId
);
1017 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1018 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1020 ret
= NdrFullPointerQueryPointer(pXlatTables
, NULL
, 0, &RefId
);
1021 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1022 ok(RefId
== 0, "RefId should be 0 instead of 0x%x\n", RefId
);
1024 /* "unmarshaling" phase */
1026 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 0, &Pointer
);
1027 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1028 ok(Pointer
== (void *)0xcafebabe, "Pointer should be 0xcafebabe instead of %p\n", Pointer
);
1030 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x4, 0, &Pointer
);
1031 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1032 ok(Pointer
== NULL
, "Pointer should be NULL instead of %p\n", Pointer
);
1034 NdrFullPointerInsertRefId(pXlatTables
, 0x4, (void *)0xdeadbabe);
1036 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x4, 1, &Pointer
);
1037 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1038 ok(Pointer
== (void *)0xdeadbabe, "Pointer should be (void *)0xdeadbabe instead of %p\n", Pointer
);
1040 NdrFullPointerXlatFree(pXlatTables
);
1042 pXlatTables
= NdrFullPointerXlatInit(2, XLAT_SERVER
);
1044 /* "unmarshaling" phase */
1046 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 1, &Pointer
);
1047 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1048 ok(Pointer
== NULL
, "Pointer should be NULL instead of %p\n", Pointer
);
1050 NdrFullPointerInsertRefId(pXlatTables
, 0x2, (void *)0xcafebabe);
1052 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 0, &Pointer
);
1053 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1054 ok(Pointer
== (void *)0xcafebabe, "Pointer should be (void *)0xcafebabe instead of %p\n", Pointer
);
1056 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 1, &Pointer
);
1057 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1058 ok(Pointer
== (void *)0xcafebabe, "Pointer should be (void *)0xcafebabe instead of %p\n", Pointer
);
1060 /* "marshaling" phase */
1062 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
1063 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1064 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1066 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
1067 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1068 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1070 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 0, &RefId
);
1071 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1072 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1074 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebabe, 0, &RefId
);
1075 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1076 ok(RefId
== 0x2, "RefId should be 0x2 instead of 0x%x\n", RefId
);
1078 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 0, &RefId
);
1079 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1080 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
1082 /* "freeing" phase */
1084 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xcafebeef);
1085 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1087 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 0x20, &RefId
);
1088 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1089 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1091 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
1092 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1093 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1095 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xcafebabe);
1096 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1098 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xdeadbeef);
1099 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1101 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 0x20, &RefId
);
1102 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1103 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
1105 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 1, &RefId
);
1106 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1107 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
1109 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 1, &RefId
);
1110 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1111 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
1113 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xdeadbeef);
1114 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1116 NdrFullPointerXlatFree(pXlatTables
);
1119 static void test_client_init(void)
1121 MIDL_STUB_MESSAGE stubMsg
;
1124 memset(&rpcMsg
, 0xcc, sizeof(rpcMsg
));
1125 memset(&stubMsg
, 0xcc, sizeof(stubMsg
));
1127 NdrClientInitializeNew(&rpcMsg
, &stubMsg
, &Object_StubDesc
, 1);
1129 #define TEST_POINTER_UNSET(field) ok(rpcMsg.field == (void *)0xcccccccc, #field " should have been unset instead of %p\n", rpcMsg.field)
1131 ok(rpcMsg
.Handle
== NULL
, "rpcMsg.Handle should have been NULL instead of %p\n", rpcMsg
.Handle
);
1132 TEST_POINTER_UNSET(Buffer
);
1133 ok(rpcMsg
.BufferLength
== 0xcccccccc, "rpcMsg.BufferLength should have been unset instead of %d\n", rpcMsg
.BufferLength
);
1134 ok(rpcMsg
.ProcNum
== 0x8001, "rpcMsg.ProcNum should have been 0x8001 instead of 0x%x\n", rpcMsg
.ProcNum
);
1135 TEST_POINTER_UNSET(TransferSyntax
);
1136 ok(rpcMsg
.RpcInterfaceInformation
== Object_StubDesc
.RpcInterfaceInformation
,
1137 "rpcMsg.RpcInterfaceInformation should have been %p instead of %p\n",
1138 Object_StubDesc
.RpcInterfaceInformation
, rpcMsg
.RpcInterfaceInformation
);
1139 /* Note: ReservedForRuntime not tested */
1140 TEST_POINTER_UNSET(ManagerEpv
);
1141 TEST_POINTER_UNSET(ImportContext
);
1142 ok(rpcMsg
.RpcFlags
== 0, "rpcMsg.RpcFlags should have been 0 instead of 0x%lx\n", rpcMsg
.RpcFlags
);
1143 #undef TEST_POINTER_UNSET
1145 #define TEST_ZERO(field, fmt) ok(stubMsg.field == 0, #field " should have been set to zero instead of " fmt "\n", stubMsg.field)
1146 #define TEST_POINTER_UNSET(field) ok(stubMsg.field == (void *)0xcccccccc, #field " should have been unset instead of %p\n", stubMsg.field)
1147 #define TEST_ULONG_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%x\n", stubMsg.field)
1148 #define TEST_ULONG_PTR_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%lx\n", stubMsg.field)
1150 ok(stubMsg
.RpcMsg
== &rpcMsg
, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg
, stubMsg
.RpcMsg
);
1151 TEST_POINTER_UNSET(Buffer
);
1152 TEST_ZERO(BufferStart
, "%p");
1153 TEST_ZERO(BufferEnd
, "%p");
1154 TEST_POINTER_UNSET(BufferMark
);
1155 TEST_ZERO(BufferLength
, "%d");
1156 TEST_ULONG_UNSET(MemorySize
);
1157 TEST_POINTER_UNSET(Memory
);
1158 ok(stubMsg
.IsClient
== 1, "stubMsg.IsClient should have been 1 instead of %u\n", stubMsg
.IsClient
);
1159 TEST_ZERO(ReuseBuffer
, "%d");
1160 TEST_ZERO(pAllocAllNodesContext
, "%p");
1161 TEST_ZERO(pPointerQueueState
, "%p");
1162 TEST_ZERO(IgnoreEmbeddedPointers
, "%d");
1163 TEST_ZERO(PointerBufferMark
, "%p");
1164 TEST_ZERO(fBufferValid
, "%d");
1165 TEST_ZERO(uFlags
, "%d");
1166 /* FIXME: UniquePtrCount */
1167 TEST_ULONG_PTR_UNSET(MaxCount
);
1168 TEST_ULONG_UNSET(Offset
);
1169 TEST_ULONG_UNSET(ActualCount
);
1170 ok(stubMsg
.pfnAllocate
== my_alloc
, "stubMsg.pfnAllocate should have been %p instead of %p\n", my_alloc
, stubMsg
.pfnAllocate
);
1171 ok(stubMsg
.pfnFree
== my_free
, "stubMsg.pfnFree should have been %p instead of %p\n", my_free
, stubMsg
.pfnFree
);
1172 TEST_ZERO(StackTop
, "%p");
1173 TEST_POINTER_UNSET(pPresentedType
);
1174 TEST_POINTER_UNSET(pTransmitType
);
1175 TEST_POINTER_UNSET(SavedHandle
);
1176 ok(stubMsg
.StubDesc
== &Object_StubDesc
, "stubMsg.StubDesc should have been %p instead of %p\n", &Object_StubDesc
, stubMsg
.StubDesc
);
1177 TEST_POINTER_UNSET(FullPtrXlatTables
);
1178 TEST_ZERO(FullPtrRefId
, "%d");
1179 TEST_ZERO(PointerLength
, "%d");
1180 TEST_ZERO(fInDontFree
, "%d");
1181 TEST_ZERO(fDontCallFreeInst
, "%d");
1182 TEST_ZERO(fInOnlyParam
, "%d");
1183 TEST_ZERO(fHasReturn
, "%d");
1184 TEST_ZERO(fHasExtensions
, "%d");
1185 TEST_ZERO(fHasNewCorrDesc
, "%d");
1186 TEST_ZERO(fUnused
, "%d");
1187 ok(stubMsg
.fUnused2
== 0xffffcccc, "stubMsg.fUnused2 should have been 0xcccc instead of 0x%x\n", stubMsg
.fUnused2
);
1188 ok(stubMsg
.dwDestContext
== MSHCTX_DIFFERENTMACHINE
, "stubMsg.dwDestContext should have been MSHCTX_DIFFERENTMACHINE instead of %d\n", stubMsg
.dwDestContext
);
1189 TEST_ZERO(pvDestContext
, "%p");
1190 TEST_POINTER_UNSET(SavedContextHandles
);
1191 TEST_ULONG_UNSET(ParamNumber
);
1192 TEST_ZERO(pRpcChannelBuffer
, "%p");
1193 TEST_ZERO(pArrayInfo
, "%p");
1194 TEST_POINTER_UNSET(SizePtrCountArray
);
1195 TEST_POINTER_UNSET(SizePtrOffsetArray
);
1196 TEST_POINTER_UNSET(SizePtrLengthArray
);
1197 TEST_POINTER_UNSET(pArgQueue
);
1198 TEST_ZERO(dwStubPhase
, "%d");
1199 /* FIXME: where does this value come from? */
1200 trace("LowStackMark is %p\n", stubMsg
.LowStackMark
);
1201 TEST_ZERO(pAsyncMsg
, "%p");
1202 TEST_ZERO(pCorrInfo
, "%p");
1203 TEST_ZERO(pCorrMemory
, "%p");
1204 TEST_ZERO(pMemoryList
, "%p");
1205 TEST_POINTER_UNSET(pCSInfo
);
1206 TEST_POINTER_UNSET(ConformanceMark
);
1207 TEST_POINTER_UNSET(VarianceMark
);
1208 ok(stubMsg
.Unused
== 0xcccccccc, "Unused should have be unset instead of 0x%lx\n", stubMsg
.Unused
);
1209 TEST_POINTER_UNSET(pContext
);
1210 TEST_POINTER_UNSET(ContextHandleHash
);
1211 TEST_POINTER_UNSET(pUserMarshalList
);
1212 TEST_ULONG_PTR_UNSET(Reserved51_3
);
1213 TEST_ULONG_PTR_UNSET(Reserved51_4
);
1214 TEST_ULONG_PTR_UNSET(Reserved51_5
);
1215 #undef TEST_ULONG_UNSET
1216 #undef TEST_POINTER_UNSET
1221 static void test_server_init(void)
1223 MIDL_STUB_MESSAGE stubMsg
;
1226 unsigned char buffer
[256];
1228 memset(&rpcMsg
, 0, sizeof(rpcMsg
));
1229 rpcMsg
.Buffer
= buffer
;
1230 rpcMsg
.BufferLength
= sizeof(buffer
);
1231 rpcMsg
.RpcFlags
= RPC_BUFFER_COMPLETE
;
1233 memset(&stubMsg
, 0xcc, sizeof(stubMsg
));
1235 ret
= NdrServerInitializeNew(&rpcMsg
, &stubMsg
, &Object_StubDesc
);
1236 ok(ret
== NULL
, "NdrServerInitializeNew should have returned NULL instead of %p\n", ret
);
1238 #define TEST_ZERO(field, fmt) ok(stubMsg.field == 0, #field " should have been set to zero instead of " fmt "\n", stubMsg.field)
1239 #define TEST_POINTER_UNSET(field) ok(stubMsg.field == (void *)0xcccccccc, #field " should have been unset instead of %p\n", stubMsg.field)
1240 #define TEST_ULONG_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%x\n", stubMsg.field)
1241 #define TEST_ULONG_PTR_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have been unset instead of 0x%lx\n", stubMsg.field)
1243 ok(stubMsg
.RpcMsg
== &rpcMsg
, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg
, stubMsg
.RpcMsg
);
1244 ok(stubMsg
.Buffer
== buffer
, "stubMsg.Buffer should have been %p instead of %p\n", buffer
, stubMsg
.Buffer
);
1245 ok(stubMsg
.BufferStart
== buffer
, "stubMsg.BufferStart should have been %p instead of %p\n", buffer
, stubMsg
.BufferStart
);
1246 ok(stubMsg
.BufferEnd
== buffer
+ sizeof(buffer
), "stubMsg.BufferEnd should have been %p instead of %p\n", buffer
+ sizeof(buffer
), stubMsg
.BufferEnd
);
1247 TEST_POINTER_UNSET(BufferMark
);
1249 TEST_ZERO(BufferLength
, "%d");
1250 TEST_ULONG_UNSET(MemorySize
);
1251 TEST_POINTER_UNSET(Memory
);
1252 ok(stubMsg
.IsClient
== 0, "stubMsg.IsClient should have been 0 instead of %u\n", stubMsg
.IsClient
);
1253 TEST_ZERO(ReuseBuffer
, "%d");
1254 TEST_ZERO(pAllocAllNodesContext
, "%p");
1255 TEST_ZERO(pPointerQueueState
, "%p");
1256 TEST_ZERO(IgnoreEmbeddedPointers
, "%d");
1257 TEST_ZERO(PointerBufferMark
, "%p");
1258 ok(stubMsg
.fBufferValid
== 0xcc, "fBufferValid should have been unset instead of 0x%x\n", stubMsg
.fBufferValid
);
1259 TEST_ZERO(uFlags
, "%d");
1260 /* FIXME: UniquePtrCount */
1261 TEST_ULONG_PTR_UNSET(MaxCount
);
1262 TEST_ULONG_UNSET(Offset
);
1263 TEST_ULONG_UNSET(ActualCount
);
1264 ok(stubMsg
.pfnAllocate
== my_alloc
, "stubMsg.pfnAllocate should have been %p instead of %p\n", my_alloc
, stubMsg
.pfnAllocate
);
1265 ok(stubMsg
.pfnFree
== my_free
, "stubMsg.pfnFree should have been %p instead of %p\n", my_free
, stubMsg
.pfnFree
);
1266 TEST_ZERO(StackTop
, "%p");
1267 TEST_POINTER_UNSET(pPresentedType
);
1268 TEST_POINTER_UNSET(pTransmitType
);
1269 TEST_POINTER_UNSET(SavedHandle
);
1270 ok(stubMsg
.StubDesc
== &Object_StubDesc
, "stubMsg.StubDesc should have been %p instead of %p\n", &Object_StubDesc
, stubMsg
.StubDesc
);
1271 TEST_ZERO(FullPtrXlatTables
, "%p");
1272 TEST_ZERO(FullPtrRefId
, "%d");
1273 TEST_ZERO(PointerLength
, "%d");
1274 TEST_ZERO(fInDontFree
, "%d");
1275 TEST_ZERO(fDontCallFreeInst
, "%d");
1276 TEST_ZERO(fInOnlyParam
, "%d");
1277 TEST_ZERO(fHasReturn
, "%d");
1278 TEST_ZERO(fHasExtensions
, "%d");
1279 TEST_ZERO(fHasNewCorrDesc
, "%d");
1280 TEST_ZERO(fUnused
, "%d");
1281 ok(stubMsg
.fUnused2
== 0xffffcccc, "stubMsg.fUnused2 should have been 0xcccc instead of 0x%x\n", stubMsg
.fUnused2
);
1282 ok(stubMsg
.dwDestContext
== MSHCTX_DIFFERENTMACHINE
, "stubMsg.dwDestContext should have been MSHCTX_DIFFERENTMACHINE instead of %d\n", stubMsg
.dwDestContext
);
1283 TEST_ZERO(pvDestContext
, "%p");
1284 TEST_POINTER_UNSET(SavedContextHandles
);
1285 TEST_ULONG_UNSET(ParamNumber
);
1286 TEST_ZERO(pRpcChannelBuffer
, "%p");
1287 TEST_ZERO(pArrayInfo
, "%p");
1288 TEST_POINTER_UNSET(SizePtrCountArray
);
1289 TEST_POINTER_UNSET(SizePtrOffsetArray
);
1290 TEST_POINTER_UNSET(SizePtrLengthArray
);
1291 TEST_POINTER_UNSET(pArgQueue
);
1292 TEST_ZERO(dwStubPhase
, "%d");
1293 /* FIXME: where does this value come from? */
1294 trace("LowStackMark is %p\n", stubMsg
.LowStackMark
);
1295 TEST_ZERO(pAsyncMsg
, "%p");
1296 TEST_ZERO(pCorrInfo
, "%p");
1297 TEST_ZERO(pCorrMemory
, "%p");
1298 TEST_ZERO(pMemoryList
, "%p");
1299 TEST_POINTER_UNSET(pCSInfo
);
1300 TEST_POINTER_UNSET(ConformanceMark
);
1301 TEST_POINTER_UNSET(VarianceMark
);
1302 ok(stubMsg
.Unused
== 0xcccccccc, "Unused should have be unset instead of 0x%lx\n", stubMsg
.Unused
);
1303 TEST_POINTER_UNSET(pContext
);
1304 TEST_POINTER_UNSET(ContextHandleHash
);
1305 TEST_POINTER_UNSET(pUserMarshalList
);
1306 TEST_ULONG_PTR_UNSET(Reserved51_3
);
1307 TEST_ULONG_PTR_UNSET(Reserved51_4
);
1308 TEST_ULONG_PTR_UNSET(Reserved51_5
);
1309 #undef TEST_ULONG_UNSET
1310 #undef TEST_POINTER_UNSET
1315 static void test_ndr_allocate(void)
1317 RPC_MESSAGE RpcMessage
;
1318 MIDL_STUB_MESSAGE StubMsg
;
1319 MIDL_STUB_DESC StubDesc
;
1321 struct tag_mem_list_v1_t
1325 struct tag_mem_list_v1_t
*next
;
1327 struct tag_mem_list_v2_t
1332 struct tag_mem_list_v2_t
*next
;
1334 const DWORD magic_MEML
= 'M' << 24 | 'E' << 16 | 'M' << 8 | 'L';
1336 StubDesc
= Object_StubDesc
;
1337 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &StubDesc
, 0);
1339 ok(StubMsg
.pMemoryList
== NULL
, "memlist %p\n", StubMsg
.pMemoryList
);
1340 my_alloc_called
= my_free_called
= 0;
1341 p1
= NdrAllocate(&StubMsg
, 10);
1342 p2
= NdrAllocate(&StubMsg
, 24);
1343 ok(my_alloc_called
== 2, "alloc called %d\n", my_alloc_called
);
1344 ok(StubMsg
.pMemoryList
!= NULL
, "StubMsg.pMemoryList NULL\n");
1345 if(StubMsg
.pMemoryList
)
1347 mem_list_v2
= StubMsg
.pMemoryList
;
1348 if (mem_list_v2
->size
== 24)
1350 trace("v2 mem list format\n");
1351 ok((char *)mem_list_v2
== (char *)p2
+ 24, "expected mem_list_v2 pointer %p, but got %p\n", (char *)p2
+ 24, mem_list_v2
);
1352 ok(mem_list_v2
->magic
== magic_MEML
, "magic %08x\n", mem_list_v2
->magic
);
1353 ok(mem_list_v2
->size
== 24, "wrong size for p2 %d\n", mem_list_v2
->size
);
1354 ok(mem_list_v2
->unknown
== 0, "wrong unknown for p2 0x%x\n", mem_list_v2
->unknown
);
1355 ok(mem_list_v2
->next
!= NULL
, "next NULL\n");
1356 mem_list_v2
= mem_list_v2
->next
;
1359 ok((char *)mem_list_v2
== (char *)p1
+ 16, "expected mem_list_v2 pointer %p, but got %p\n", (char *)p1
+ 16, mem_list_v2
);
1360 ok(mem_list_v2
->magic
== magic_MEML
, "magic %08x\n", mem_list_v2
->magic
);
1361 ok(mem_list_v2
->size
== 16, "wrong size for p1 %d\n", mem_list_v2
->size
);
1362 ok(mem_list_v2
->unknown
== 0, "wrong unknown for p1 0x%x\n", mem_list_v2
->unknown
);
1363 ok(mem_list_v2
->next
== NULL
, "next %p\n", mem_list_v2
->next
);
1368 trace("v1 mem list format\n");
1369 mem_list_v1
= StubMsg
.pMemoryList
;
1370 ok(mem_list_v1
->magic
== magic_MEML
, "magic %08x\n", mem_list_v1
->magic
);
1371 ok(mem_list_v1
->ptr
== p2
, "ptr != p2\n");
1372 ok(mem_list_v1
->next
!= NULL
, "next NULL\n");
1373 mem_list_v1
= mem_list_v1
->next
;
1376 ok(mem_list_v1
->magic
== magic_MEML
, "magic %08x\n", mem_list_v1
->magic
);
1377 ok(mem_list_v1
->ptr
== p1
, "ptr != p1\n");
1378 ok(mem_list_v1
->next
== NULL
, "next %p\n", mem_list_v1
->next
);
1382 /* NdrFree isn't exported so we can't test free'ing */
1385 static void test_conformant_array(void)
1387 RPC_MESSAGE RpcMessage
;
1388 MIDL_STUB_MESSAGE StubMsg
;
1389 MIDL_STUB_DESC StubDesc
;
1391 unsigned char *mem
, *mem_orig
;
1392 unsigned char memsrc
[20];
1395 static const unsigned char fmtstr_conf_array
[] =
1397 0x1b, /* FC_CARRAY */
1399 NdrFcShort( 0x1 ), /* elem size */
1400 0x40, /* Corr desc: const */
1402 NdrFcShort(0x10), /* const = 0x10 */
1407 for (i
= 0; i
< sizeof(memsrc
); i
++)
1410 StubDesc
= Object_StubDesc
;
1411 StubDesc
.pFormatTypes
= fmtstr_conf_array
;
1413 NdrClientInitializeNew(
1419 StubMsg
.BufferLength
= 0;
1420 NdrConformantArrayBufferSize( &StubMsg
,
1422 fmtstr_conf_array
);
1423 ok(StubMsg
.BufferLength
>= 20, "length %d\n", StubMsg
.BufferLength
);
1425 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1426 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1427 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1429 ptr
= NdrConformantArrayMarshall( &StubMsg
, memsrc
, fmtstr_conf_array
);
1430 ok(ptr
== NULL
, "ret %p\n", ptr
);
1431 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== 20, "Buffer %p Start %p len %d\n", StubMsg
.Buffer
, StubMsg
.BufferStart
, 20);
1432 ok(!memcmp(StubMsg
.BufferStart
+ 4, memsrc
, 16), "incorrectly marshaled\n");
1434 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1435 StubMsg
.MemorySize
= 0;
1439 my_alloc_called
= 0;
1440 /* passing mem == NULL with must_alloc == 0 crashes under Windows */
1441 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1442 ok(mem
!= NULL
, "mem not alloced\n");
1443 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1444 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1446 my_alloc_called
= 0;
1447 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1449 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 0);
1450 ok(mem
== mem_orig
, "mem alloced\n");
1451 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1452 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1454 my_alloc_called
= 0;
1455 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1456 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1457 ok(mem
!= mem_orig
, "mem not alloced\n");
1458 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1459 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1462 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1463 NdrConformantArrayFree( &StubMsg
, mem
, fmtstr_conf_array
);
1464 ok(my_free_called
== 0, "free called %d\n", my_free_called
);
1465 StubMsg
.pfnFree(mem
);
1468 my_alloc_called
= 0;
1469 StubMsg
.IsClient
= 0;
1471 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1472 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 0);
1473 ok(mem
== StubMsg
.BufferStart
+ 4, "mem not pointing at buffer\n");
1474 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1475 my_alloc_called
= 0;
1477 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1478 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1479 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1480 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1481 StubMsg
.pfnFree(mem
);
1483 my_alloc_called
= 0;
1485 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1486 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 0);
1487 ok(mem
== mem_orig
, "mem alloced\n");
1488 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1490 my_alloc_called
= 0;
1492 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1493 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1494 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1495 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1496 StubMsg
.pfnFree(mem
);
1497 StubMsg
.pfnFree(mem_orig
);
1499 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1502 static void test_conformant_string(void)
1504 RPC_MESSAGE RpcMessage
;
1505 MIDL_STUB_MESSAGE StubMsg
;
1506 MIDL_STUB_DESC StubDesc
;
1508 unsigned char *mem
, *mem_orig
;
1509 char memsrc
[] = "This is a test string";
1511 static const unsigned char fmtstr_conf_str
[] =
1513 0x11, 0x8, /* FC_RP [simple_pointer] */
1514 0x22, /* FC_C_CSTRING */
1518 StubDesc
= Object_StubDesc
;
1519 StubDesc
.pFormatTypes
= fmtstr_conf_str
;
1521 NdrClientInitializeNew(
1527 StubMsg
.BufferLength
= 0;
1528 NdrPointerBufferSize( &StubMsg
,
1529 (unsigned char *)memsrc
,
1531 ok(StubMsg
.BufferLength
>= sizeof(memsrc
) + 12, "length %d\n", StubMsg
.BufferLength
);
1533 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1534 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1535 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1537 ptr
= NdrPointerMarshall( &StubMsg
, (unsigned char *)memsrc
, fmtstr_conf_str
);
1538 ok(ptr
== NULL
, "ret %p\n", ptr
);
1539 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== sizeof(memsrc
) + 12, "Buffer %p Start %p len %d\n",
1540 StubMsg
.Buffer
, StubMsg
.BufferStart
, StubMsg
.Buffer
- StubMsg
.BufferStart
);
1541 ok(!memcmp(StubMsg
.BufferStart
+ 12, memsrc
, sizeof(memsrc
)), "incorrectly marshaled\n");
1543 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1544 StubMsg
.MemorySize
= 0;
1548 my_alloc_called
= 0;
1549 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1550 mem
= mem_orig
= HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc
));
1551 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 0);
1552 ok(mem
== mem_orig
, "mem not alloced\n");
1553 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1555 my_alloc_called
= 0;
1556 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1557 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 1);
1559 ok(mem
== mem_orig
, "mem not alloced\n");
1560 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1564 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1565 NdrPointerFree( &StubMsg
, mem
, fmtstr_conf_str
);
1566 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
1570 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1571 NdrPointerFree( &StubMsg
, mem
, fmtstr_conf_str
);
1572 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
1575 my_alloc_called
= 0;
1576 StubMsg
.IsClient
= 0;
1578 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1579 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 0);
1580 ok(mem
== StubMsg
.BufferStart
+ 12, "mem not pointing at buffer\n");
1581 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1583 my_alloc_called
= 0;
1585 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1586 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 1);
1588 ok(mem
== StubMsg
.BufferStart
+ 12, "mem not pointing at buffer\n");
1589 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1592 my_alloc_called
= 0;
1594 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1595 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 0);
1596 ok(mem
== StubMsg
.BufferStart
+ 12, "mem not pointing at buffer\n");
1597 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1599 my_alloc_called
= 0;
1601 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1602 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 1);
1604 ok(mem
== StubMsg
.BufferStart
+ 12, "mem not pointing at buffer\n");
1605 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1610 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1611 NdrPointerFree( &StubMsg
, mem
, fmtstr_conf_str
);
1612 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
1614 HeapFree(GetProcessHeap(), 0, mem_orig
);
1615 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1618 static void test_nonconformant_string(void)
1620 RPC_MESSAGE RpcMessage
;
1621 MIDL_STUB_MESSAGE StubMsg
;
1622 MIDL_STUB_DESC StubDesc
;
1624 unsigned char *mem
, *mem_orig
;
1625 unsigned char memsrc
[10] = "This is";
1626 unsigned char memsrc2
[10] = "This is a";
1628 static const unsigned char fmtstr_nonconf_str
[] =
1630 0x26, /* FC_CSTRING */
1632 NdrFcShort( 0xa ), /* 10 */
1635 StubDesc
= Object_StubDesc
;
1636 StubDesc
.pFormatTypes
= fmtstr_nonconf_str
;
1639 NdrClientInitializeNew(
1645 StubMsg
.BufferLength
= 0;
1647 NdrNonConformantStringBufferSize( &StubMsg
,
1648 (unsigned char *)memsrc
,
1649 fmtstr_nonconf_str
);
1650 ok(StubMsg
.BufferLength
>= strlen((char *)memsrc
) + 1 + 8, "length %d\n", StubMsg
.BufferLength
);
1652 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1653 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1654 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1656 ptr
= NdrNonConformantStringMarshall( &StubMsg
, (unsigned char *)memsrc
, fmtstr_nonconf_str
);
1657 ok(ptr
== NULL
, "ret %p\n", ptr
);
1658 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== strlen((char *)memsrc
) + 1 + 8, "Buffer %p Start %p len %d\n",
1659 StubMsg
.Buffer
, StubMsg
.BufferStart
, StubMsg
.Buffer
- StubMsg
.BufferStart
);
1660 ok(!memcmp(StubMsg
.BufferStart
+ 8, memsrc
, strlen((char *)memsrc
) + 1), "incorrectly marshaled\n");
1662 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1663 StubMsg
.MemorySize
= 0;
1667 my_alloc_called
= 0;
1668 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1669 mem
= mem_orig
= HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc
));
1670 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1671 ok(mem
== mem_orig
, "mem alloced\n");
1672 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1674 my_alloc_called
= 0;
1675 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1676 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 1);
1678 ok(mem
== mem_orig
, "mem alloced\n");
1680 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1683 my_alloc_called
= 0;
1684 StubMsg
.IsClient
= 0;
1686 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1687 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1688 ok(mem
!= mem_orig
, "mem not alloced\n");
1689 ok(mem
!= StubMsg
.BufferStart
+ 8, "mem pointing at buffer\n");
1690 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1693 my_alloc_called
= 0;
1695 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1696 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1697 ok(mem
== mem_orig
, "mem alloced\n");
1698 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1700 my_alloc_called
= 0;
1702 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1703 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 1);
1705 ok(mem
== mem_orig
, "mem alloced\n");
1707 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1709 HeapFree(GetProcessHeap(), 0, mem_orig
);
1710 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1713 NdrClientInitializeNew(
1719 StubMsg
.BufferLength
= 0;
1721 NdrNonConformantStringBufferSize( &StubMsg
,
1722 (unsigned char *)memsrc2
,
1723 fmtstr_nonconf_str
);
1724 ok(StubMsg
.BufferLength
>= strlen((char *)memsrc2
) + 1 + 8, "length %d\n", StubMsg
.BufferLength
);
1726 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1727 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1728 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1730 ptr
= NdrNonConformantStringMarshall( &StubMsg
, (unsigned char *)memsrc2
, fmtstr_nonconf_str
);
1731 ok(ptr
== NULL
, "ret %p\n", ptr
);
1732 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== strlen((char *)memsrc2
) + 1 + 8, "Buffer %p Start %p len %d\n",
1733 StubMsg
.Buffer
, StubMsg
.BufferStart
, StubMsg
.Buffer
- StubMsg
.BufferStart
);
1734 ok(!memcmp(StubMsg
.BufferStart
+ 8, memsrc2
, strlen((char *)memsrc2
) + 1), "incorrectly marshaled\n");
1736 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1737 StubMsg
.MemorySize
= 0;
1741 my_alloc_called
= 0;
1742 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1743 mem
= mem_orig
= HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc
));
1744 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1745 ok(mem
== mem_orig
, "mem alloced\n");
1746 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1748 my_alloc_called
= 0;
1749 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1750 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 1);
1752 ok(mem
== mem_orig
, "mem alloced\n");
1754 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1757 my_alloc_called
= 0;
1758 StubMsg
.IsClient
= 0;
1760 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1761 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1762 ok(mem
!= mem_orig
, "mem not alloced\n");
1763 ok(mem
!= StubMsg
.BufferStart
+ 8, "mem pointing at buffer\n");
1764 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1767 my_alloc_called
= 0;
1769 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1770 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1771 ok(mem
== mem_orig
, "mem alloced\n");
1772 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1774 my_alloc_called
= 0;
1776 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1777 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 1);
1779 ok(mem
== mem_orig
, "mem alloced\n");
1781 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1783 HeapFree(GetProcessHeap(), 0, mem_orig
);
1784 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1787 static void test_ndr_buffer(void)
1789 static unsigned char ncalrpc
[] = "ncalrpc";
1790 static unsigned char endpoint
[] = "winetest:test_ndr_buffer";
1791 RPC_MESSAGE RpcMessage
;
1792 MIDL_STUB_MESSAGE StubMsg
;
1793 MIDL_STUB_DESC StubDesc
= Object_StubDesc
;
1795 unsigned char *binding
;
1796 RPC_BINDING_HANDLE Handle
;
1799 StubDesc
.RpcInterfaceInformation
= (void *)&IFoo___RpcServerInterface
;
1801 status
= RpcServerUseProtseqEp(ncalrpc
, 20, endpoint
, NULL
);
1802 ok(RPC_S_OK
== status
, "RpcServerUseProtseqEp failed with status %lu\n", status
);
1803 status
= RpcServerRegisterIf(IFoo_v0_0_s_ifspec
, NULL
, NULL
);
1804 ok(RPC_S_OK
== status
, "RpcServerRegisterIf failed with status %lu\n", status
);
1805 status
= RpcServerListen(1, 20, TRUE
);
1806 ok(RPC_S_OK
== status
, "RpcServerListen failed with status %lu\n", status
);
1807 if (status
!= RPC_S_OK
)
1809 /* Failed to create a server, running client tests is useless */
1813 status
= RpcStringBindingCompose(NULL
, ncalrpc
, NULL
, endpoint
, NULL
, &binding
);
1814 ok(status
== RPC_S_OK
, "RpcStringBindingCompose failed (%lu)\n", status
);
1816 status
= RpcBindingFromStringBinding(binding
, &Handle
);
1817 ok(status
== RPC_S_OK
, "RpcBindingFromStringBinding failed (%lu)\n", status
);
1818 RpcStringFree(&binding
);
1820 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &StubDesc
, 5);
1822 ret
= NdrGetBuffer(&StubMsg
, 10, Handle
);
1823 ok(ret
== StubMsg
.Buffer
, "NdrGetBuffer should have returned the same value as StubMsg.Buffer instead of %p\n", ret
);
1824 ok(RpcMessage
.Handle
!= NULL
, "RpcMessage.Handle should not have been NULL\n");
1825 ok(RpcMessage
.Buffer
!= NULL
, "RpcMessage.Buffer should not have been NULL\n");
1826 ok(RpcMessage
.BufferLength
== 10, "RpcMessage.BufferLength should have been 10 instead of %d\n", RpcMessage
.BufferLength
);
1827 ok(RpcMessage
.RpcFlags
== 0, "RpcMessage.RpcFlags should have been 0x0 instead of 0x%lx\n", RpcMessage
.RpcFlags
);
1828 ok(StubMsg
.Buffer
!= NULL
, "Buffer should not have been NULL\n");
1829 ok(!StubMsg
.BufferStart
, "BufferStart should have been NULL instead of %p\n", StubMsg
.BufferStart
);
1830 ok(!StubMsg
.BufferEnd
, "BufferEnd should have been NULL instead of %p\n", StubMsg
.BufferEnd
);
1832 ok(StubMsg
.BufferLength
== 0, "BufferLength should have left as 0 instead of being set to %d\n", StubMsg
.BufferLength
);
1833 ok(StubMsg
.fBufferValid
== TRUE
, "fBufferValid should have been TRUE instead of 0x%x\n", StubMsg
.fBufferValid
);
1835 StubMsg
.BufferLength
= 1;
1836 NdrFreeBuffer(&StubMsg
);
1837 ok(RpcMessage
.Handle
!= NULL
, "RpcMessage.Handle should not have been NULL\n");
1838 ok(RpcMessage
.Buffer
!= NULL
, "RpcMessage.Buffer should not have been NULL\n");
1839 ok(RpcMessage
.BufferLength
== 10, "RpcMessage.BufferLength should have been left as 10 instead of %d\n", RpcMessage
.BufferLength
);
1840 ok(StubMsg
.Buffer
!= NULL
, "Buffer should not have been NULL\n");
1841 ok(StubMsg
.BufferLength
== 1, "BufferLength should have left as 1 instead of being set to %d\n", StubMsg
.BufferLength
);
1842 ok(StubMsg
.fBufferValid
== FALSE
, "fBufferValid should have been FALSE instead of 0x%x\n", StubMsg
.fBufferValid
);
1844 /* attempt double-free */
1845 NdrFreeBuffer(&StubMsg
);
1847 RpcBindingFree(&Handle
);
1849 status
= RpcServerUnregisterIf(NULL
, NULL
, FALSE
);
1850 ok(status
== RPC_S_OK
, "RpcServerUnregisterIf failed (%lu)\n", status
);
1853 static void test_NdrMapCommAndFaultStatus(void)
1855 RPC_STATUS rpc_status
;
1856 MIDL_STUB_MESSAGE StubMsg
;
1857 RPC_MESSAGE RpcMessage
;
1859 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &Object_StubDesc
, 5);
1861 for (rpc_status
= 0; rpc_status
< 10000; rpc_status
++)
1864 ULONG comm_status
= 0;
1865 ULONG fault_status
= 0;
1866 ULONG expected_comm_status
= 0;
1867 ULONG expected_fault_status
= 0;
1868 status
= NdrMapCommAndFaultStatus(&StubMsg
, &comm_status
, &fault_status
, rpc_status
);
1869 ok(status
== RPC_S_OK
, "NdrMapCommAndFaultStatus failed with error %ld\n", status
);
1872 case ERROR_INVALID_HANDLE
:
1873 case RPC_S_INVALID_BINDING
:
1874 case RPC_S_UNKNOWN_IF
:
1875 case RPC_S_SERVER_UNAVAILABLE
:
1876 case RPC_S_SERVER_TOO_BUSY
:
1877 case RPC_S_CALL_FAILED_DNE
:
1878 case RPC_S_PROTOCOL_ERROR
:
1879 case RPC_S_UNSUPPORTED_TRANS_SYN
:
1880 case RPC_S_UNSUPPORTED_TYPE
:
1881 case RPC_S_PROCNUM_OUT_OF_RANGE
:
1882 case EPT_S_NOT_REGISTERED
:
1883 case RPC_S_COMM_FAILURE
:
1884 expected_comm_status
= rpc_status
;
1887 expected_fault_status
= rpc_status
;
1889 ok(comm_status
== expected_comm_status
, "NdrMapCommAndFaultStatus should have mapped %ld to comm status %d instead of %d\n",
1890 rpc_status
, expected_comm_status
, comm_status
);
1891 ok(fault_status
== expected_fault_status
, "NdrMapCommAndFaultStatus should have mapped %ld to fault status %d instead of %d\n",
1892 rpc_status
, expected_fault_status
, fault_status
);
1896 START_TEST( ndr_marshall
)
1898 determine_pointer_marshalling_style();
1900 test_ndr_simple_type();
1901 test_simple_types();
1902 test_nontrivial_pointer_types();
1903 test_simple_struct();
1904 test_fullpointer_xlat();
1907 test_ndr_allocate();
1908 test_conformant_array();
1909 test_conformant_string();
1910 test_nonconformant_string();
1912 test_NdrMapCommAndFaultStatus();