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
21 #define _WIN32_WINNT 0x0500
22 #define NTDDI_WIN2K 0x05000000
23 #define NTDDI_VERSION NTDDI_WIN2K /* for some MIDL_STUB_MESSAGE fields */
27 #include "wine/test.h"
39 static int my_alloc_called
;
40 static int my_free_called
;
41 static void * CALLBACK
my_alloc(SIZE_T size
)
44 return NdrOleAllocate(size
);
47 static void CALLBACK
my_free(void *ptr
)
53 static const MIDL_STUB_DESC Object_StubDesc
=
63 NULL
, /* format string, filled in by tests */
64 1, /* -error bounds_check flag */
65 0x20000, /* Ndr library version */
67 0x50100a4, /* MIDL Version 5.1.164 */
70 0, /* notify & notify_flag routine table */
77 static RPC_DISPATCH_FUNCTION IFoo_table
[] =
82 static RPC_DISPATCH_TABLE IFoo_v0_0_DispatchTable
=
88 static const RPC_SERVER_INTERFACE IFoo___RpcServerInterface
=
90 sizeof(RPC_SERVER_INTERFACE
),
91 {{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x34}},{0,0}},
92 {{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},
93 &IFoo_v0_0_DispatchTable
,
101 static RPC_IF_HANDLE IFoo_v0_0_s_ifspec
= (RPC_IF_HANDLE
)& IFoo___RpcServerInterface
;
102 static BOOL use_pointer_ids
= FALSE
;
104 static void determine_pointer_marshalling_style(void)
106 RPC_MESSAGE RpcMessage
;
107 MIDL_STUB_MESSAGE StubMsg
;
108 MIDL_STUB_DESC StubDesc
;
111 static const unsigned char fmtstr_up_char
[] =
113 0x12, 0x8, /* FC_UP [simple_pointer] */
118 StubDesc
= Object_StubDesc
;
119 StubDesc
.pFormatTypes
= NULL
;
121 NdrClientInitializeNew(
127 StubMsg
.BufferLength
= 8;
128 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
129 NdrPointerMarshall(&StubMsg
, (unsigned char*)&ch
, fmtstr_up_char
);
130 ok(StubMsg
.Buffer
== StubMsg
.BufferStart
+ 5, "%p %p\n", StubMsg
.Buffer
, StubMsg
.BufferStart
);
132 use_pointer_ids
= (*(unsigned int *)StubMsg
.BufferStart
!= (UINT_PTR
)&ch
);
133 trace("Pointer marshalling using %s\n", use_pointer_ids
? "pointer ids" : "pointer value");
135 HeapFree(GetProcessHeap(), 0, StubMsg
.BufferStart
);
138 static void test_ndr_simple_type(void)
140 RPC_MESSAGE RpcMessage
;
141 MIDL_STUB_MESSAGE StubMsg
;
142 MIDL_STUB_DESC StubDesc
;
145 StubDesc
= Object_StubDesc
;
146 StubDesc
.pFormatTypes
= NULL
;
148 NdrClientInitializeNew(
154 StubMsg
.BufferLength
= 16;
155 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
157 NdrSimpleTypeMarshall(&StubMsg
, (unsigned char*)&l
, 8 /* FC_LONG */);
158 ok(StubMsg
.Buffer
== StubMsg
.BufferStart
+ 4, "%p %p\n", StubMsg
.Buffer
, StubMsg
.BufferStart
);
159 ok(*(LONG
*)StubMsg
.BufferStart
== l
, "%d\n", *(LONG
*)StubMsg
.BufferStart
);
161 StubMsg
.Buffer
= StubMsg
.BufferStart
+ 1;
162 NdrSimpleTypeMarshall(&StubMsg
, (unsigned char*)&l
, 8 /* FC_LONG */);
163 ok(StubMsg
.Buffer
== StubMsg
.BufferStart
+ 8, "%p %p\n", StubMsg
.Buffer
, StubMsg
.BufferStart
);
164 ok(*(LONG
*)(StubMsg
.BufferStart
+ 4) == l
, "%d\n", *(LONG
*)StubMsg
.BufferStart
);
166 StubMsg
.Buffer
= StubMsg
.BufferStart
+ 1;
167 NdrSimpleTypeUnmarshall(&StubMsg
, (unsigned char*)&l2
, 8 /* FC_LONG */);
168 ok(StubMsg
.Buffer
== StubMsg
.BufferStart
+ 8, "%p %p\n", StubMsg
.Buffer
, StubMsg
.BufferStart
);
169 ok(l2
== l
, "%d\n", l2
);
171 HeapFree(GetProcessHeap(), 0, StubMsg
.BufferStart
);
174 static void test_pointer_marshal(const unsigned char *formattypes
,
175 void *memsrc
, DWORD srcsize
,
176 const void *wiredata
,
178 int(*cmp
)(const void*,const void*,size_t),
179 int num_additional_allocs
,
182 RPC_MESSAGE RpcMessage
;
183 MIDL_STUB_MESSAGE StubMsg
;
184 MIDL_STUB_DESC StubDesc
;
187 unsigned char *mem
, *mem_orig
;
189 my_alloc_called
= my_free_called
= 0;
193 StubDesc
= Object_StubDesc
;
194 StubDesc
.pFormatTypes
= formattypes
;
196 NdrClientInitializeNew(
202 StubMsg
.BufferLength
= 0;
203 NdrPointerBufferSize( &StubMsg
,
206 ok(StubMsg
.BufferLength
>= wiredatalen
, "%s: length %d\n", msgpfx
, StubMsg
.BufferLength
);
208 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
209 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
210 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
212 memset(StubMsg
.BufferStart
, 0x0, StubMsg
.BufferLength
); /* This is a hack to clear the padding between the ptr and longlong/double */
214 ptr
= NdrPointerMarshall( &StubMsg
, memsrc
, formattypes
);
215 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
216 if (srcsize
== 8 && wiredatalen
== 16 && StubMsg
.Buffer
- StubMsg
.BufferStart
== 12)
218 /* win9x doesn't align 8-byte types properly */
223 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
224 ok(!memcmp(StubMsg
.BufferStart
, wiredata
, wiredatalen
), "%s: incorrectly marshaled\n", msgpfx
);
227 StubMsg
.Buffer
= StubMsg
.BufferStart
;
228 StubMsg
.MemorySize
= 0;
230 size
= NdrPointerMemorySize( &StubMsg
, formattypes
);
231 ok(size
== StubMsg
.MemorySize
, "%s: mem size %u size %u\n", msgpfx
, StubMsg
.MemorySize
, size
);
232 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
233 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
234 ok(size
== srcsize
+ sizeof(void *), "%s: mem size %u\n", msgpfx
, size
);
236 ok(size
== srcsize
, "%s: mem size %u\n", msgpfx
, size
);
238 StubMsg
.Buffer
= StubMsg
.BufferStart
;
239 StubMsg
.MemorySize
= 16;
240 size
= NdrPointerMemorySize( &StubMsg
, formattypes
);
241 ok(size
== StubMsg
.MemorySize
, "%s: mem size %u size %u\n", msgpfx
, StubMsg
.MemorySize
, size
);
242 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
243 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
244 ok(size
== srcsize
+ sizeof(void *) + 16, "%s: mem size %u\n", msgpfx
, size
);
246 ok(size
== srcsize
+ 16, "%s: mem size %u\n", msgpfx
, size
);
248 StubMsg
.Buffer
= StubMsg
.BufferStart
;
249 StubMsg
.MemorySize
= 1;
250 size
= NdrPointerMemorySize( &StubMsg
, formattypes
);
251 ok(size
== StubMsg
.MemorySize
, "%s: mem size %u size %u\n", msgpfx
, StubMsg
.MemorySize
, size
);
252 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
253 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
254 ok(size
== srcsize
+ sizeof(void *) + (srcsize
== 8 ? 8 : sizeof(void *)), "%s: mem size %u\n", msgpfx
, size
);
256 ok(size
== srcsize
+ (srcsize
== 8 ? 8 : sizeof(void *)), "%s: mem size %u\n", msgpfx
, size
);
259 if(formattypes
[1] & 0x10) size
+= 4;
261 StubMsg
.Buffer
= StubMsg
.BufferStart
;
262 StubMsg
.MemorySize
= 0;
263 mem_orig
= mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
265 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
267 ptr
= NdrPointerUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
268 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
269 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
270 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
271 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
272 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
273 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
276 /* reset the buffer and call with must alloc */
277 StubMsg
.Buffer
= StubMsg
.BufferStart
;
278 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
280 ptr
= NdrPointerUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
281 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
282 /* doesn't allocate mem in this case */
284 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
286 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
287 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
288 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
291 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
294 if(formattypes
[0] != 0x11 /* FC_RP */)
296 /* now pass the address of a NULL ptr */
298 StubMsg
.Buffer
= StubMsg
.BufferStart
;
299 ptr
= NdrPointerUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
300 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
301 ok(mem
!= StubMsg
.BufferStart
+ wiredatalen
- srcsize
, "%s: mem points to buffer %p %p\n", msgpfx
, mem
, StubMsg
.BufferStart
);
302 ok(!cmp(mem
, memsrc
, size
), "%s: incorrectly unmarshaled\n", msgpfx
);
303 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
304 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
305 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
307 NdrPointerFree(&StubMsg
, mem
, formattypes
);
309 /* again pass address of NULL ptr, but pretend we're a server */
310 if (0) /* crashes on Win9x and NT4 */
313 StubMsg
.Buffer
= StubMsg
.BufferStart
;
314 StubMsg
.IsClient
= 0;
315 ptr
= NdrPointerUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
316 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
317 if (formattypes
[2] == 0xd /* FC_ENUM16 */)
318 ok(mem
!= StubMsg
.BufferStart
+ wiredatalen
- srcsize
, "%s: mem points to buffer %p %p\n", msgpfx
, mem
, StubMsg
.BufferStart
);
320 ok(mem
== StubMsg
.BufferStart
+ wiredatalen
- srcsize
, "%s: mem doesn't point to buffer %p %p\n", msgpfx
, mem
, StubMsg
.BufferStart
);
321 ok(!cmp(mem
, memsrc
, size
), "%s: incorrectly unmarshaled\n", msgpfx
);
322 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %d\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
323 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
324 if (formattypes
[2] != 0xd /* FC_ENUM16 */) {
325 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
330 HeapFree(GetProcessHeap(), 0, mem_orig
);
331 HeapFree(GetProcessHeap(), 0, StubMsg
.BufferStart
);
334 static int deref_cmp(const void *s1
, const void *s2
, size_t num
)
336 return memcmp(*(const void *const *)s1
, *(const void *const *)s2
, num
);
340 static void test_simple_types(void)
342 unsigned char wiredata
[16];
344 unsigned char *ch_ptr
;
352 static const unsigned char fmtstr_up_char
[] =
354 0x12, 0x8, /* FC_UP [simple_pointer] */
358 static const unsigned char fmtstr_up_byte
[] =
360 0x12, 0x8, /* FC_UP [simple_pointer] */
364 static const unsigned char fmtstr_up_small
[] =
366 0x12, 0x8, /* FC_UP [simple_pointer] */
370 static const unsigned char fmtstr_up_usmall
[] =
372 0x12, 0x8, /* FC_UP [simple_pointer] */
376 static const unsigned char fmtstr_rp_char
[] =
378 0x11, 0x8, /* FC_RP [simple_pointer] */
382 static const unsigned char fmtstr_rpup_char
[] =
384 0x11, 0x14, /* FC_RP [alloced_on_stack] */
385 NdrFcShort( 0x2 ), /* Offset= 2 (4) */
386 0x12, 0x8, /* FC_UP [simple_pointer] */
390 static const unsigned char fmtstr_rpup_char2
[] =
392 0x11, 0x04, /* FC_RP [alloced_on_stack] */
393 NdrFcShort( 0x2 ), /* Offset= 2 (4) */
394 0x12, 0x8, /* FC_UP [simple_pointer] */
399 static const unsigned char fmtstr_up_wchar
[] =
401 0x12, 0x8, /* FC_UP [simple_pointer] */
405 static const unsigned char fmtstr_up_short
[] =
407 0x12, 0x8, /* FC_UP [simple_pointer] */
411 static const unsigned char fmtstr_up_ushort
[] =
413 0x12, 0x8, /* FC_UP [simple_pointer] */
417 static const unsigned char fmtstr_up_enum16
[] =
419 0x12, 0x8, /* FC_UP [simple_pointer] */
423 static const unsigned char fmtstr_up_long
[] =
425 0x12, 0x8, /* FC_UP [simple_pointer] */
429 static const unsigned char fmtstr_up_ulong
[] =
431 0x12, 0x8, /* FC_UP [simple_pointer] */
435 static const unsigned char fmtstr_up_enum32
[] =
437 0x12, 0x8, /* FC_UP [simple_pointer] */
441 static const unsigned char fmtstr_up_errorstatus
[] =
443 0x12, 0x8, /* FC_UP [simple_pointer] */
444 0x10, /* FC_ERROR_STATUS_T */
448 static const unsigned char fmtstr_up_longlong
[] =
450 0x12, 0x8, /* FC_UP [simple_pointer] */
454 static const unsigned char fmtstr_up_float
[] =
456 0x12, 0x8, /* FC_UP [simple_pointer] */
460 static const unsigned char fmtstr_up_double
[] =
462 0x12, 0x8, /* FC_UP [simple_pointer] */
470 *(unsigned int *)wiredata
= 0x20000;
472 *(unsigned int *)wiredata
= (UINT_PTR
)ch_ptr
;
475 test_pointer_marshal(fmtstr_up_char
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_char");
476 test_pointer_marshal(fmtstr_up_byte
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_byte");
477 test_pointer_marshal(fmtstr_up_small
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_small");
478 test_pointer_marshal(fmtstr_up_usmall
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_usmall");
480 test_pointer_marshal(fmtstr_rp_char
, ch_ptr
, 1, &ch
, 1, NULL
, 0, "rp_char");
482 test_pointer_marshal(fmtstr_rpup_char
, &ch_ptr
, 1, wiredata
, 5, deref_cmp
, 1, "rpup_char");
483 test_pointer_marshal(fmtstr_rpup_char2
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "rpup_char2");
487 *(unsigned int *)wiredata
= 0x20000;
489 *(unsigned int *)wiredata
= (UINT_PTR
)&s
;
490 *(unsigned short*)(wiredata
+ 4) = s
;
492 test_pointer_marshal(fmtstr_up_wchar
, &s
, 2, wiredata
, 6, NULL
, 0, "up_wchar");
493 test_pointer_marshal(fmtstr_up_short
, &s
, 2, wiredata
, 6, NULL
, 0, "up_short");
494 test_pointer_marshal(fmtstr_up_ushort
, &s
, 2, wiredata
, 6, NULL
, 0, "up_ushort");
498 *(unsigned int *)wiredata
= 0x20000;
500 *(unsigned int *)wiredata
= (UINT_PTR
)&i
;
501 *(unsigned short*)(wiredata
+ 4) = i
;
502 test_pointer_marshal(fmtstr_up_enum16
, &i
, 4, wiredata
, 6, NULL
, 0, "up_enum16");
506 *(unsigned int *)wiredata
= 0x20000;
508 *(unsigned int *)wiredata
= (UINT_PTR
)&l
;
509 *(ULONG
*)(wiredata
+ 4) = l
;
511 test_pointer_marshal(fmtstr_up_long
, &l
, 4, wiredata
, 8, NULL
, 0, "up_long");
512 test_pointer_marshal(fmtstr_up_ulong
, &l
, 4, wiredata
, 8, NULL
, 0, "up_ulong");
513 test_pointer_marshal(fmtstr_up_enum32
, &l
, 4, wiredata
, 8, NULL
, 0, "up_emun32");
514 test_pointer_marshal(fmtstr_up_errorstatus
, &l
, 4, wiredata
, 8, NULL
, 0, "up_errorstatus");
516 ll
= ((ULONGLONG
)0xcafebabe) << 32 | 0xdeadbeef;
518 *(unsigned int *)wiredata
= 0x20000;
520 *(unsigned int *)wiredata
= (UINT_PTR
)&ll
;
521 *(unsigned int *)(wiredata
+ 4) = 0;
522 *(ULONGLONG
*)(wiredata
+ 8) = ll
;
523 test_pointer_marshal(fmtstr_up_longlong
, &ll
, 8, wiredata
, 16, NULL
, 0, "up_longlong");
527 *(unsigned int *)wiredata
= 0x20000;
529 *(unsigned int *)wiredata
= (UINT_PTR
)&f
;
530 *(float*)(wiredata
+ 4) = f
;
531 test_pointer_marshal(fmtstr_up_float
, &f
, 4, wiredata
, 8, NULL
, 0, "up_float");
535 *(unsigned int *)wiredata
= 0x20000;
537 *(unsigned int *)wiredata
= (UINT_PTR
)&d
;
538 *(unsigned int *)(wiredata
+ 4) = 0;
539 *(double*)(wiredata
+ 8) = d
;
540 test_pointer_marshal(fmtstr_up_double
, &d
, 8, wiredata
, 16, NULL
, 0, "up_double");
544 static void test_nontrivial_pointer_types(void)
546 RPC_MESSAGE RpcMessage
;
547 MIDL_STUB_MESSAGE StubMsg
;
548 MIDL_STUB_DESC StubDesc
;
554 unsigned char *mem
, *mem_orig
;
556 static const unsigned char fmtstr_ref_unique_out
[] =
558 0x12, 0x8, /* FC_UP [simple_pointer] */
561 0x11, 0x14, /* FC_RP [alloced_on_stack] [pointer_deref] */
562 NdrFcShort( 0xfffffffa ), /* Offset= -6 (0) */
569 StubDesc
= Object_StubDesc
;
570 StubDesc
.pFormatTypes
= fmtstr_ref_unique_out
;
572 NdrClientInitializeNew(
578 StubMsg
.BufferLength
= 0;
579 NdrPointerBufferSize( &StubMsg
,
581 &fmtstr_ref_unique_out
[4] );
583 /* Windows overestimates the buffer size */
584 ok(StubMsg
.BufferLength
>= 5, "length %d\n", StubMsg
.BufferLength
);
586 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
587 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
588 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
590 ptr
= NdrPointerMarshall( &StubMsg
, (unsigned char *)p1
, &fmtstr_ref_unique_out
[4] );
591 ok(ptr
== NULL
, "ret %p\n", ptr
);
592 size
= StubMsg
.Buffer
- StubMsg
.BufferStart
;
593 ok(size
== 5, "Buffer %p Start %p len %d\n", StubMsg
.Buffer
, StubMsg
.BufferStart
, size
);
594 ok(*(unsigned int *)StubMsg
.BufferStart
!= 0, "pointer ID marshalled incorrectly\n");
595 ok(*(unsigned char *)(StubMsg
.BufferStart
+ 4) == 0x22, "char data marshalled incorrectly: 0x%x\n",
596 *(unsigned char *)(StubMsg
.BufferStart
+ 4));
598 StubMsg
.Buffer
= StubMsg
.BufferStart
;
599 StubMsg
.MemorySize
= 0;
604 StubMsg
.Buffer
= StubMsg
.BufferStart
;
605 mem
= mem_orig
= HeapAlloc(GetProcessHeap(), 0, sizeof(void *));
606 *(void **)mem
= NULL
;
607 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 0);
608 ok(mem
== mem_orig
, "mem alloced\n");
609 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
612 StubMsg
.Buffer
= StubMsg
.BufferStart
;
613 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 1);
615 ok(mem
== mem_orig
, "mem alloced\n");
616 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
620 StubMsg
.Buffer
= StubMsg
.BufferStart
;
621 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
622 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
624 mem
= my_alloc(sizeof(void *));
625 *(void **)mem
= NULL
;
627 StubMsg
.Buffer
= StubMsg
.BufferStart
;
628 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
629 ok(my_free_called
== 0, "free called %d\n", my_free_called
);
632 mem
= my_alloc(sizeof(void *));
633 *(void **)mem
= my_alloc(sizeof(char));
635 StubMsg
.Buffer
= StubMsg
.BufferStart
;
636 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
637 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
642 StubMsg
.IsClient
= 0;
644 StubMsg
.Buffer
= StubMsg
.BufferStart
;
645 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 0);
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 StubMsg
.Buffer
= StubMsg
.BufferStart
;
654 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 1);
655 ok(mem
!= StubMsg
.BufferStart
, "mem pointing at buffer\n");
657 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
658 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
662 *(void **)mem
= NULL
;
663 StubMsg
.Buffer
= StubMsg
.BufferStart
;
664 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 0);
666 ok(mem
== mem_orig
, "mem alloced\n");
667 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
672 *(void **)mem
= NULL
;
673 StubMsg
.Buffer
= StubMsg
.BufferStart
;
674 NdrPointerUnmarshall( &StubMsg
, &mem
, &fmtstr_ref_unique_out
[4], 1);
676 ok(mem
== mem_orig
, "mem alloced\n");
677 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
680 mem
= my_alloc(sizeof(void *));
681 *(void **)mem
= NULL
;
683 StubMsg
.Buffer
= StubMsg
.BufferStart
;
684 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
685 ok(my_free_called
== 0, "free called %d\n", my_free_called
);
688 mem
= my_alloc(sizeof(void *));
689 *(void **)mem
= my_alloc(sizeof(char));
691 StubMsg
.Buffer
= StubMsg
.BufferStart
;
692 NdrPointerFree( &StubMsg
, mem
, &fmtstr_ref_unique_out
[4] );
693 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
696 HeapFree(GetProcessHeap(), 0, mem_orig
);
697 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
700 static void test_simple_struct_marshal(const unsigned char *formattypes
,
701 void *memsrc
, DWORD srcsize
,
702 const void *wiredata
,
704 int(*cmp
)(const void*,const void*,size_t),
705 int num_additional_allocs
,
708 RPC_MESSAGE RpcMessage
;
709 MIDL_STUB_MESSAGE StubMsg
;
710 MIDL_STUB_DESC StubDesc
;
713 unsigned char *mem
, *mem_orig
;
715 my_alloc_called
= my_free_called
= 0;
719 StubDesc
= Object_StubDesc
;
720 StubDesc
.pFormatTypes
= formattypes
;
722 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &StubDesc
, 0);
724 StubMsg
.BufferLength
= 0;
725 NdrSimpleStructBufferSize( &StubMsg
, memsrc
, formattypes
);
726 ok(StubMsg
.BufferLength
>= wiredatalen
, "%s: length %d\n", msgpfx
, StubMsg
.BufferLength
);
727 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
728 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
729 ptr
= NdrSimpleStructMarshall( &StubMsg
, memsrc
, formattypes
);
730 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
731 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
732 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));
734 StubMsg
.Buffer
= StubMsg
.BufferStart
;
735 StubMsg
.MemorySize
= 0;
736 size
= NdrSimpleStructMemorySize( &StubMsg
, formattypes
);
737 ok(size
== StubMsg
.MemorySize
, "%s: size != MemorySize\n", msgpfx
);
738 ok(size
== srcsize
, "%s: mem size %u\n", msgpfx
, size
);
739 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
741 StubMsg
.Buffer
= StubMsg
.BufferStart
;
742 size
= NdrSimpleStructMemorySize( &StubMsg
, formattypes
);
743 ok(size
== StubMsg
.MemorySize
, "%s: size != MemorySize\n", msgpfx
);
744 ok(StubMsg
.MemorySize
== ((srcsize
+ 3) & ~3) + srcsize
, "%s: mem size %u\n", msgpfx
, size
);
745 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
747 /*** Unmarshalling first with must_alloc false ***/
749 StubMsg
.Buffer
= StubMsg
.BufferStart
;
750 StubMsg
.MemorySize
= 0;
751 mem_orig
= mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, srcsize
);
752 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
753 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
754 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
755 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
756 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
757 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
759 ok(StubMsg
.MemorySize
== 0, "%s: memorysize touched in unmarshal\n", msgpfx
);
761 /* If we're a server we still use the supplied memory */
762 StubMsg
.Buffer
= StubMsg
.BufferStart
;
763 StubMsg
.IsClient
= 0;
764 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
765 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
766 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
767 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
768 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
770 ok(StubMsg
.MemorySize
== 0, "%s: memorysize touched in unmarshal\n", msgpfx
);
772 /* ...unless we pass a NULL ptr, then the buffer is used.
773 Passing a NULL ptr while we're a client && !must_alloc
774 crashes on Windows, so we won't do that. */
776 if (0) /* crashes on Win9x and NT4 */
779 StubMsg
.IsClient
= 0;
780 StubMsg
.Buffer
= StubMsg
.BufferStart
;
781 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, FALSE
);
782 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
783 ok(mem
== StubMsg
.BufferStart
, "%s: mem not equal buffer\n", msgpfx
);
784 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
785 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
787 ok(StubMsg
.MemorySize
== 0, "%s: memorysize touched in unmarshal\n", msgpfx
);
790 /*** now must_alloc is true ***/
792 /* with must_alloc set we always allocate new memory whether or not we're
793 a server and also when passing NULL */
795 StubMsg
.IsClient
= 1;
796 StubMsg
.Buffer
= StubMsg
.BufferStart
;
797 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
798 ok(ptr
== NULL
, "ret %p\n", ptr
);
799 ok(mem
!= mem_orig
, "mem not changed %p %p\n", mem
, mem_orig
);
800 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
801 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
803 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
806 StubMsg
.Buffer
= StubMsg
.BufferStart
;
807 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
808 ok(ptr
== NULL
, "ret %p\n", ptr
);
809 ok(mem
!= mem_orig
, "mem not changed %p %p\n", mem
, mem_orig
);
810 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
811 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
813 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
816 StubMsg
.Buffer
= StubMsg
.BufferStart
;
817 StubMsg
.IsClient
= 0;
818 StubMsg
.ReuseBuffer
= 1;
819 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
820 ok(ptr
== NULL
, "ret %p\n", ptr
);
821 ok(mem
!= mem_orig
, "mem not changed %p %p\n", mem
, mem_orig
);
822 ok(mem
!= StubMsg
.BufferStart
, "mem is buffer mem\n");
823 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
824 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
826 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
829 StubMsg
.Buffer
= StubMsg
.BufferStart
;
830 StubMsg
.IsClient
= 0;
831 StubMsg
.ReuseBuffer
= 1;
832 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
833 ok(ptr
== NULL
, "ret %p\n", ptr
);
834 ok(mem
!= StubMsg
.BufferStart
, "mem is buffer mem\n");
835 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
836 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
838 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
840 HeapFree(GetProcessHeap(), 0, mem_orig
);
841 HeapFree(GetProcessHeap(), 0, StubMsg
.BufferStart
);
851 static int ps1_cmp(const void *s1
, const void *s2
, size_t num
)
853 const ps1_t
*p1
, *p2
;
861 if(p1
->pl1
&& p2
->pl1
)
863 if(*p1
->pl1
!= *p2
->pl1
)
866 else if(p1
->pl1
|| p2
->pl1
)
869 if(p1
->pc1
&& p2
->pc1
)
871 if(*p1
->pc1
!= *p2
->pc1
)
874 else if(p1
->pc1
|| p2
->pc1
)
880 static void test_simple_struct(void)
882 unsigned char wiredata
[28];
888 static const unsigned char fmtstr_simple_struct
[] =
890 0x12, 0x0, /* FC_UP */
891 NdrFcShort( 0x2 ), /* Offset=2 */
892 0x15, 0x3, /* FC_STRUCT [align 4] */
893 NdrFcShort( 0x18 ), /* [size 24] */
896 0x38, /* FC_ALIGNM4 */
899 0x39, /* FC_ALIGNM8 */
910 static const unsigned char fmtstr_pointer_struct
[] =
912 0x12, 0x0, /* FC_UP */
913 NdrFcShort( 0x2 ), /* Offset=2 */
915 0x1a, /* FC_BOGUS_STRUCT */
917 NdrFcShort(0x18), /* [size 24] */
919 NdrFcShort(0x8), /* Offset= 8 (266) */
921 0x39, /* FC_ALIGNM8 */
922 0x36, /* FC_POINTER */
923 0x36, /* FC_POINTER */
926 0x12, 0x8, /* FC_UP [simple_pointer] */
929 0x12, 0x8, /* FC_UP [simple_pointer] */
933 0x16, 0x3, /* FC_PSTRUCT [align 4] */
934 NdrFcShort( 0xc ), /* [size 12] */
937 0x46, /* FC_NO_REPEAT */
939 NdrFcShort( 0x4 ), /* 4 */
940 NdrFcShort( 0x4 ), /* 4 */
941 0x13, 0x8, /* FC_OP [simple_pointer] */
944 0x46, /* FC_NO_REPEAT */
946 NdrFcShort( 0x8 ), /* 8 */
947 NdrFcShort( 0x8 ), /* 8 */
948 0x13, 0x8, /* FC_OP [simple_pointer] */
960 /* zero the entire structure, including the holes */
961 memset(&s1
, 0, sizeof(s1
));
968 s1
.ll
= ((ULONGLONG
) 0xbadefeed << 32) | 0x2468ace0;
971 memcpy(wiredata
, &s1
, wiredatalen
);
972 test_simple_struct_marshal(fmtstr_simple_struct
+ 4, &s1
, 24, wiredata
, 24, NULL
, 0, "struct");
975 *(unsigned int *)wiredata
= 0x20000;
977 *(unsigned int *)wiredata
= (UINT_PTR
)&s1
;
978 memcpy(wiredata
+ 4, &s1
, wiredatalen
);
979 test_pointer_marshal(fmtstr_simple_struct
, &s1
, 24, wiredata
, 28, NULL
, 0, "struct");
981 if (sizeof(void *) == 8) return; /* it cannot be represented as a simple struct on Win64 */
983 /* zero the entire structure, including the hole */
984 memset(&ps1
, 0, sizeof(ps1
));
992 *(unsigned int *)(wiredata
+ 4) = 0xdeadbeef;
995 *(unsigned int *)(wiredata
+ 8) = 0x20000;
996 *(unsigned int *)(wiredata
+ 12) = 0x20004;
1000 *(unsigned int *)(wiredata
+ 8) = (UINT_PTR
)&l
;
1001 *(unsigned int *)(wiredata
+ 12) = (UINT_PTR
)&c
;
1003 memcpy(wiredata
+ 16, &l
, 4);
1004 memcpy(wiredata
+ 20, &c
, 1);
1006 test_simple_struct_marshal(fmtstr_pointer_struct
+ 4, &ps1
, 17, wiredata
+ 4, 17, ps1_cmp
, 2, "pointer_struct");
1007 if (use_pointer_ids
)
1009 *(unsigned int *)wiredata
= 0x20000;
1010 *(unsigned int *)(wiredata
+ 8) = 0x20004;
1011 *(unsigned int *)(wiredata
+ 12) = 0x20008;
1014 *(unsigned int *)wiredata
= (UINT_PTR
)&ps1
;
1015 test_pointer_marshal(fmtstr_pointer_struct
, &ps1
, 17, wiredata
, 21, ps1_cmp
, 2, "pointer_struct");
1018 static void test_fullpointer_xlat(void)
1020 PFULL_PTR_XLAT_TABLES pXlatTables
;
1025 pXlatTables
= NdrFullPointerXlatInit(2, XLAT_CLIENT
);
1027 /* "marshaling" phase */
1029 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
1030 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1031 ok(RefId
== 0x1, "RefId should be 0x1 instead of 0x%x\n", RefId
);
1033 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 0, &RefId
);
1034 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1035 ok(RefId
== 0x1, "RefId should be 0x1 instead of 0x%x\n", RefId
);
1037 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebabe, 0, &RefId
);
1038 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1039 ok(RefId
== 0x2, "RefId should be 0x2 instead of 0x%x\n", RefId
);
1041 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 0, &RefId
);
1042 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1043 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1045 ret
= NdrFullPointerQueryPointer(pXlatTables
, NULL
, 0, &RefId
);
1046 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1047 ok(RefId
== 0, "RefId should be 0 instead of 0x%x\n", RefId
);
1049 /* "unmarshaling" phase */
1051 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x0, 0, &Pointer
);
1052 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1054 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 0, &Pointer
);
1055 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1056 ok(Pointer
== (void *)0xcafebabe, "Pointer should be 0xcafebabe instead of %p\n", Pointer
);
1058 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x4, 0, &Pointer
);
1059 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1060 ok(Pointer
== NULL
, "Pointer should be NULL instead of %p\n", Pointer
);
1062 NdrFullPointerInsertRefId(pXlatTables
, 0x4, (void *)0xdeadbabe);
1064 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x4, 1, &Pointer
);
1065 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1066 ok(Pointer
== (void *)0xdeadbabe, "Pointer should be (void *)0xdeadbabe instead of %p\n", Pointer
);
1068 NdrFullPointerXlatFree(pXlatTables
);
1070 pXlatTables
= NdrFullPointerXlatInit(2, XLAT_SERVER
);
1072 /* "unmarshaling" phase */
1074 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 1, &Pointer
);
1075 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1076 ok(Pointer
== NULL
, "Pointer should be NULL instead of %p\n", Pointer
);
1078 NdrFullPointerInsertRefId(pXlatTables
, 0x2, (void *)0xcafebabe);
1080 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 0, &Pointer
);
1081 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1082 ok(Pointer
== (void *)0xcafebabe, "Pointer should be (void *)0xcafebabe instead of %p\n", Pointer
);
1084 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 1, &Pointer
);
1085 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1086 ok(Pointer
== (void *)0xcafebabe, "Pointer should be (void *)0xcafebabe instead of %p\n", Pointer
);
1088 /* "marshaling" phase */
1090 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
1091 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1092 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1094 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
1095 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1096 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1098 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 0, &RefId
);
1099 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1100 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1102 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebabe, 0, &RefId
);
1103 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1104 ok(RefId
== 0x2, "RefId should be 0x2 instead of 0x%x\n", RefId
);
1106 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 0, &RefId
);
1107 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1108 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
1110 /* "freeing" phase */
1112 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xcafebeef);
1113 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1115 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 0x20, &RefId
);
1116 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1117 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1119 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
1120 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1121 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1123 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xcafebabe);
1124 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1126 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xdeadbeef);
1127 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1129 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 0x20, &RefId
);
1130 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1131 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
1133 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 1, &RefId
);
1134 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1135 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
1137 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 1, &RefId
);
1138 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1139 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
1141 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xdeadbeef);
1142 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1144 NdrFullPointerXlatFree(pXlatTables
);
1147 /* verify stub data that is identical between client and server */
1148 static void test_common_stub_data( const char *prefix
, const MIDL_STUB_MESSAGE
*stubMsg
)
1152 memset(&unset_ptr
, 0xcc, sizeof(unset_ptr
));
1154 #define TEST_ZERO(field, fmt) ok(stubMsg->field == 0, "%s: " #field " should have been set to zero instead of " fmt "\n", prefix, stubMsg->field)
1155 #define TEST_POINTER_UNSET(field) ok(stubMsg->field == unset_ptr, "%s: " #field " should have been unset instead of %p\n", prefix, stubMsg->field)
1156 #define TEST_ULONG_UNSET(field) ok(stubMsg->field == 0xcccccccc, "%s: " #field " should have been unset instead of 0x%x\n", prefix, stubMsg->field)
1157 #define TEST_ULONG_PTR_UNSET(field) ok(stubMsg->field == (ULONG_PTR)unset_ptr, "%s: " #field " should have been unset instead of 0x%lx\n", prefix, stubMsg->field)
1159 TEST_POINTER_UNSET(BufferMark
);
1160 TEST_ULONG_UNSET(MemorySize
);
1161 TEST_POINTER_UNSET(Memory
);
1162 TEST_ZERO(pAllocAllNodesContext
, "%p");
1163 ok(stubMsg
->pPointerQueueState
== 0 ||
1164 broken(stubMsg
->pPointerQueueState
== unset_ptr
), /* win2k */
1165 "%s: pPointerQueueState should have been unset instead of %p\n",
1166 prefix
, stubMsg
->pPointerQueueState
);
1167 TEST_ZERO(IgnoreEmbeddedPointers
, "%d");
1168 TEST_ZERO(PointerBufferMark
, "%p");
1169 ok( stubMsg
->uFlags
== 0 ||
1170 broken(stubMsg
->uFlags
== 0xcc), /* win9x */
1171 "%s: uFlags should have been set to zero instead of 0x%x\n", prefix
, stubMsg
->uFlags
);
1172 /* FIXME: UniquePtrCount */
1173 TEST_ULONG_PTR_UNSET(MaxCount
);
1174 TEST_ULONG_UNSET(Offset
);
1175 TEST_ULONG_UNSET(ActualCount
);
1176 ok(stubMsg
->pfnAllocate
== my_alloc
, "%s: pfnAllocate should have been %p instead of %p\n",
1177 prefix
, my_alloc
, stubMsg
->pfnAllocate
);
1178 ok(stubMsg
->pfnFree
== my_free
, "%s: pfnFree should have been %p instead of %p\n",
1179 prefix
, my_free
, stubMsg
->pfnFree
);
1180 TEST_ZERO(StackTop
, "%p");
1181 TEST_POINTER_UNSET(pPresentedType
);
1182 TEST_POINTER_UNSET(pTransmitType
);
1183 TEST_POINTER_UNSET(SavedHandle
);
1184 ok(stubMsg
->StubDesc
== &Object_StubDesc
, "%s: StubDesc should have been %p instead of %p\n",
1185 prefix
, &Object_StubDesc
, stubMsg
->StubDesc
);
1186 TEST_ZERO(FullPtrRefId
, "%d");
1187 ok( stubMsg
->PointerLength
== 0 ||
1188 broken(stubMsg
->PointerLength
== 1), /* win9x, nt4 */
1189 "%s: pAsyncMsg should have been set to zero instead of %d\n", prefix
, stubMsg
->PointerLength
);
1190 TEST_ZERO(fInDontFree
, "%d");
1191 TEST_ZERO(fDontCallFreeInst
, "%d");
1192 ok( stubMsg
->fHasReturn
== 0 || broken(stubMsg
->fHasReturn
), /* win9x, nt4 */
1193 "%s: fHasReturn should have been set to zero instead of %d\n", prefix
, stubMsg
->fHasReturn
);
1194 TEST_ZERO(fHasExtensions
, "%d");
1195 TEST_ZERO(fHasNewCorrDesc
, "%d");
1196 ok(stubMsg
->fIsIn
== 0 || broken(stubMsg
->fIsIn
), /* win9x, nt4 */
1197 "%s: fIsIn should have been set to 0 instead of %d\n", prefix
, stubMsg
->fIsIn
);
1198 TEST_ZERO(fIsOicf
, "%d");
1199 ok(stubMsg
->fBufferValid
== 0,
1200 "%s: fBufferValid should have been set to 0 instead of %d\n", prefix
, stubMsg
->fBufferValid
);
1201 TEST_ZERO(fNeedMCCP
, "%d");
1202 ok(stubMsg
->fUnused
== 0 ||
1203 stubMsg
->fUnused
== -2, /* Vista */
1204 "%s: fUnused should have been set to 0 or -2 instead of %d\n", prefix
, stubMsg
->fUnused
);
1205 ok(stubMsg
->fUnused2
== 0xffffcccc, "%s: fUnused2 should have been 0xffffcccc instead of 0x%x\n",
1206 prefix
, stubMsg
->fUnused2
);
1207 ok(stubMsg
->dwDestContext
== MSHCTX_DIFFERENTMACHINE
,
1208 "%s: dwDestContext should have been MSHCTX_DIFFERENTMACHINE instead of %d\n",
1209 prefix
, stubMsg
->dwDestContext
);
1210 TEST_ZERO(pvDestContext
, "%p");
1211 TEST_POINTER_UNSET(SavedContextHandles
);
1212 TEST_ULONG_UNSET(ParamNumber
);
1213 TEST_ZERO(pRpcChannelBuffer
, "%p");
1214 TEST_ZERO(pArrayInfo
, "%p");
1215 TEST_POINTER_UNSET(SizePtrCountArray
);
1216 TEST_POINTER_UNSET(SizePtrOffsetArray
);
1217 TEST_POINTER_UNSET(SizePtrLengthArray
);
1218 TEST_POINTER_UNSET(pArgQueue
);
1219 TEST_ZERO(dwStubPhase
, "%d");
1220 /* FIXME: where does this value come from? */
1221 trace("%s: LowStackMark is %p\n", prefix
, stubMsg
->LowStackMark
);
1222 ok( stubMsg
->pAsyncMsg
== 0 || broken(stubMsg
->pAsyncMsg
== unset_ptr
), /* win9x, nt4 */
1223 "%s: pAsyncMsg should have been set to zero instead of %p\n", prefix
, stubMsg
->pAsyncMsg
);
1224 ok( stubMsg
->pCorrInfo
== 0 || broken(stubMsg
->pCorrInfo
== unset_ptr
), /* win9x, nt4 */
1225 "%s: pCorrInfo should have been set to zero instead of %p\n", prefix
, stubMsg
->pCorrInfo
);
1226 ok( stubMsg
->pCorrMemory
== 0 || broken(stubMsg
->pCorrMemory
== unset_ptr
), /* win9x, nt4 */
1227 "%s: pCorrMemory should have been set to zero instead of %p\n", prefix
, stubMsg
->pCorrMemory
);
1228 ok( stubMsg
->pMemoryList
== 0 || broken(stubMsg
->pMemoryList
== unset_ptr
), /* win9x, nt4 */
1229 "%s: pMemoryList should have been set to zero instead of %p\n", prefix
, stubMsg
->pMemoryList
);
1230 TEST_POINTER_UNSET(pCSInfo
);
1231 TEST_POINTER_UNSET(ConformanceMark
);
1232 TEST_POINTER_UNSET(VarianceMark
);
1233 ok(stubMsg
->Unused
== (ULONG_PTR
)unset_ptr
, "%s: Unused should have be unset instead of 0x%lx\n",
1234 prefix
, stubMsg
->Unused
);
1235 TEST_POINTER_UNSET(pContext
);
1236 TEST_POINTER_UNSET(ContextHandleHash
);
1237 TEST_POINTER_UNSET(pUserMarshalList
);
1238 TEST_ULONG_PTR_UNSET(Reserved51_3
);
1239 TEST_ULONG_PTR_UNSET(Reserved51_4
);
1240 TEST_ULONG_PTR_UNSET(Reserved51_5
);
1242 #undef TEST_ULONG_PTR_UNSET
1243 #undef TEST_ULONG_UNSET
1244 #undef TEST_POINTER_UNSET
1248 static void test_client_init(void)
1250 MIDL_STUB_MESSAGE stubMsg
;
1254 memset(&rpcMsg
, 0xcc, sizeof(rpcMsg
));
1255 memset(&stubMsg
, 0xcc, sizeof(stubMsg
));
1256 memset(&unset_ptr
, 0xcc, sizeof(unset_ptr
));
1258 NdrClientInitializeNew(&rpcMsg
, &stubMsg
, &Object_StubDesc
, 1);
1260 test_common_stub_data( "NdrClientInitializeNew", &stubMsg
);
1262 ok(stubMsg
.RpcMsg
== &rpcMsg
, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg
, stubMsg
.RpcMsg
);
1263 ok(rpcMsg
.Handle
== NULL
, "rpcMsg.Handle should have been NULL instead of %p\n", rpcMsg
.Handle
);
1264 ok(rpcMsg
.Buffer
== unset_ptr
, "rpcMsg.Buffer should have been unset instead of %p\n",
1266 ok(rpcMsg
.BufferLength
== 0xcccccccc, "rpcMsg.BufferLength should have been unset instead of %d\n", rpcMsg
.BufferLength
);
1267 ok(rpcMsg
.ProcNum
== 0x8001, "rpcMsg.ProcNum should have been 0x8001 instead of 0x%x\n", rpcMsg
.ProcNum
);
1268 ok(rpcMsg
.TransferSyntax
== unset_ptr
, "rpcMsg.TransferSyntax should have been unset instead of %p\n", rpcMsg
.TransferSyntax
);
1269 ok(rpcMsg
.RpcInterfaceInformation
== Object_StubDesc
.RpcInterfaceInformation
,
1270 "rpcMsg.RpcInterfaceInformation should have been %p instead of %p\n",
1271 Object_StubDesc
.RpcInterfaceInformation
, rpcMsg
.RpcInterfaceInformation
);
1272 /* Note: ReservedForRuntime not tested */
1273 ok(rpcMsg
.ManagerEpv
== unset_ptr
, "rpcMsg.ManagerEpv should have been unset instead of %p\n", rpcMsg
.ManagerEpv
);
1274 ok(rpcMsg
.ImportContext
== unset_ptr
, "rpcMsg.ImportContext should have been unset instead of %p\n", rpcMsg
.ImportContext
);
1275 ok(rpcMsg
.RpcFlags
== 0, "rpcMsg.RpcFlags should have been 0 instead of 0x%x\n", rpcMsg
.RpcFlags
);
1277 ok(stubMsg
.Buffer
== unset_ptr
, "stubMsg.Buffer should have been unset instead of %p\n",
1279 ok(stubMsg
.BufferStart
== NULL
, "stubMsg.BufferStart should have been NULL instead of %p\n",
1280 stubMsg
.BufferStart
);
1281 ok(stubMsg
.BufferEnd
== NULL
, "stubMsg.BufferEnd should have been NULL instead of %p\n",
1283 ok(stubMsg
.BufferLength
== 0, "stubMsg.BufferLength should have been 0 instead of %u\n",
1284 stubMsg
.BufferLength
);
1285 ok(stubMsg
.IsClient
== 1, "stubMsg.IsClient should have been 1 instead of %u\n", stubMsg
.IsClient
);
1286 ok(stubMsg
.ReuseBuffer
== 0, "stubMsg.ReuseBuffer should have been 0 instead of %d\n",
1287 stubMsg
.ReuseBuffer
);
1288 ok(stubMsg
.CorrDespIncrement
== 0, "stubMsg.CorrDespIncrement should have been 0 instead of %d\n",
1289 stubMsg
.CorrDespIncrement
);
1290 ok(stubMsg
.FullPtrXlatTables
== unset_ptr
, "stubMsg.FullPtrXlatTables should have been unset instead of %p\n",
1291 stubMsg
.FullPtrXlatTables
);
1294 static void test_server_init(void)
1296 MIDL_STUB_MESSAGE stubMsg
;
1299 unsigned char buffer
[256];
1301 memset(&rpcMsg
, 0, sizeof(rpcMsg
));
1302 rpcMsg
.Buffer
= buffer
;
1303 rpcMsg
.BufferLength
= sizeof(buffer
);
1304 rpcMsg
.RpcFlags
= RPC_BUFFER_COMPLETE
;
1306 memset(&stubMsg
, 0xcc, sizeof(stubMsg
));
1308 ret
= NdrServerInitializeNew(&rpcMsg
, &stubMsg
, &Object_StubDesc
);
1309 ok(ret
== NULL
, "NdrServerInitializeNew should have returned NULL instead of %p\n", ret
);
1311 test_common_stub_data( "NdrServerInitializeNew", &stubMsg
);
1313 ok(stubMsg
.RpcMsg
== &rpcMsg
, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg
, stubMsg
.RpcMsg
);
1314 ok(stubMsg
.Buffer
== buffer
, "stubMsg.Buffer should have been %p instead of %p\n", buffer
, stubMsg
.Buffer
);
1315 ok(stubMsg
.BufferStart
== buffer
, "stubMsg.BufferStart should have been %p instead of %p\n", buffer
, stubMsg
.BufferStart
);
1316 ok(stubMsg
.BufferEnd
== buffer
+ sizeof(buffer
), "stubMsg.BufferEnd should have been %p instead of %p\n", buffer
+ sizeof(buffer
), stubMsg
.BufferEnd
);
1318 ok(stubMsg
.BufferLength
== 0, "stubMsg.BufferLength should have been 0 instead of %u\n", stubMsg
.BufferLength
);
1319 ok(stubMsg
.IsClient
== 0, "stubMsg.IsClient should have been 0 instead of %u\n", stubMsg
.IsClient
);
1320 ok(stubMsg
.ReuseBuffer
== 0 ||
1321 broken(stubMsg
.ReuseBuffer
== 1), /* win2k */
1322 "stubMsg.ReuseBuffer should have been set to zero instead of %d\n", stubMsg
.ReuseBuffer
);
1323 ok(stubMsg
.CorrDespIncrement
== 0 ||
1324 broken(stubMsg
.CorrDespIncrement
== 0xcc), /* <= Win 2003 */
1325 "CorrDespIncrement should have been set to zero instead of 0x%x\n", stubMsg
.CorrDespIncrement
);
1326 ok(stubMsg
.FullPtrXlatTables
== 0, "stubMsg.BufferLength should have been 0 instead of %p\n", stubMsg
.FullPtrXlatTables
);
1329 static void test_ndr_allocate(void)
1331 RPC_MESSAGE RpcMessage
;
1332 MIDL_STUB_MESSAGE StubMsg
;
1333 MIDL_STUB_DESC StubDesc
;
1335 struct tag_mem_list_v2_t
1340 struct tag_mem_list_v2_t
*next
;
1342 const DWORD magic_MEML
= 'M' << 24 | 'E' << 16 | 'M' << 8 | 'L';
1344 StubDesc
= Object_StubDesc
;
1345 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &StubDesc
, 0);
1347 my_alloc_called
= my_free_called
= 0;
1348 p1
= NdrAllocate(&StubMsg
, 10);
1349 p2
= NdrAllocate(&StubMsg
, 24);
1350 ok(my_alloc_called
== 2, "alloc called %d\n", my_alloc_called
);
1351 ok(StubMsg
.pMemoryList
!= NULL
, "StubMsg.pMemoryList NULL\n");
1352 if(StubMsg
.pMemoryList
)
1354 mem_list_v2
= StubMsg
.pMemoryList
;
1355 if (mem_list_v2
->size
== 24)
1357 trace("v2 mem list format\n");
1358 ok((char *)mem_list_v2
== (char *)p2
+ 24, "expected mem_list_v2 pointer %p, but got %p\n", (char *)p2
+ 24, mem_list_v2
);
1359 ok(mem_list_v2
->magic
== magic_MEML
, "magic %08x\n", mem_list_v2
->magic
);
1360 ok(mem_list_v2
->size
== 24, "wrong size for p2 %d\n", mem_list_v2
->size
);
1361 ok(mem_list_v2
->unknown
== 0, "wrong unknown for p2 0x%x\n", mem_list_v2
->unknown
);
1362 ok(mem_list_v2
->next
!= NULL
, "next NULL\n");
1363 mem_list_v2
= mem_list_v2
->next
;
1366 ok((char *)mem_list_v2
== (char *)p1
+ 16, "expected mem_list_v2 pointer %p, but got %p\n", (char *)p1
+ 16, mem_list_v2
);
1367 ok(mem_list_v2
->magic
== magic_MEML
, "magic %08x\n", mem_list_v2
->magic
);
1368 ok(mem_list_v2
->size
== 16, "wrong size for p1 %d\n", mem_list_v2
->size
);
1369 ok(mem_list_v2
->unknown
== 0, "wrong unknown for p1 0x%x\n", mem_list_v2
->unknown
);
1370 ok(mem_list_v2
->next
== NULL
, "next %p\n", mem_list_v2
->next
);
1373 else win_skip("v1 mem list format\n");
1375 /* NdrFree isn't exported so we can't test free'ing */
1378 static void test_conformant_array(void)
1380 RPC_MESSAGE RpcMessage
;
1381 MIDL_STUB_MESSAGE StubMsg
;
1382 MIDL_STUB_DESC StubDesc
;
1384 unsigned char *mem
, *mem_orig
;
1385 unsigned char memsrc
[20];
1388 static const unsigned char fmtstr_conf_array
[] =
1390 0x1b, /* FC_CARRAY */
1392 NdrFcShort( 0x1 ), /* elem size */
1393 0x40, /* Corr desc: const */
1395 NdrFcShort(0x10), /* const = 0x10 */
1400 for (i
= 0; i
< sizeof(memsrc
); i
++)
1403 StubDesc
= Object_StubDesc
;
1404 StubDesc
.pFormatTypes
= fmtstr_conf_array
;
1406 NdrClientInitializeNew(
1412 StubMsg
.BufferLength
= 0;
1413 NdrConformantArrayBufferSize( &StubMsg
,
1415 fmtstr_conf_array
);
1416 ok(StubMsg
.BufferLength
>= 20, "length %d\n", StubMsg
.BufferLength
);
1418 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1419 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1420 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1422 ptr
= NdrConformantArrayMarshall( &StubMsg
, memsrc
, fmtstr_conf_array
);
1423 ok(ptr
== NULL
, "ret %p\n", ptr
);
1424 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== 20, "Buffer %p Start %p len %d\n", StubMsg
.Buffer
, StubMsg
.BufferStart
, 20);
1425 ok(!memcmp(StubMsg
.BufferStart
+ 4, memsrc
, 16), "incorrectly marshaled\n");
1427 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1428 StubMsg
.MemorySize
= 0;
1432 my_alloc_called
= 0;
1433 /* passing mem == NULL with must_alloc == 0 crashes under Windows */
1434 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1435 ok(mem
!= NULL
, "mem not alloced\n");
1436 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1437 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1439 my_alloc_called
= 0;
1440 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1442 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 0);
1443 ok(mem
== mem_orig
, "mem alloced\n");
1444 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1445 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1447 my_alloc_called
= 0;
1448 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1449 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1450 ok(mem
!= mem_orig
, "mem not alloced\n");
1451 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1452 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1455 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1456 NdrConformantArrayFree( &StubMsg
, mem
, fmtstr_conf_array
);
1457 ok(my_free_called
== 0, "free called %d\n", my_free_called
);
1458 StubMsg
.pfnFree(mem
);
1461 my_alloc_called
= 0;
1462 StubMsg
.IsClient
= 0;
1464 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1465 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 0);
1466 ok(mem
== StubMsg
.BufferStart
+ 4 || broken(!mem
), /* win9x, nt4 */
1467 "mem not pointing at buffer %p/%p\n", mem
, StubMsg
.BufferStart
+ 4);
1468 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1469 my_alloc_called
= 0;
1471 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1472 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1473 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1474 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1475 StubMsg
.pfnFree(mem
);
1477 my_alloc_called
= 0;
1479 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1480 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 0);
1481 ok(mem
== mem_orig
, "mem alloced\n");
1482 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1484 my_alloc_called
= 0;
1486 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1487 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1488 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1489 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1490 StubMsg
.pfnFree(mem
);
1491 StubMsg
.pfnFree(mem_orig
);
1493 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1496 static void test_conformant_string(void)
1498 RPC_MESSAGE RpcMessage
;
1499 MIDL_STUB_MESSAGE StubMsg
;
1500 MIDL_STUB_DESC StubDesc
;
1503 unsigned char *mem
, *mem_orig
;
1504 char memsrc
[] = "This is a test string";
1506 static const unsigned char fmtstr_conf_str
[] =
1508 0x11, 0x8, /* FC_RP [simple_pointer] */
1509 0x22, /* FC_C_CSTRING */
1513 StubDesc
= Object_StubDesc
;
1514 StubDesc
.pFormatTypes
= fmtstr_conf_str
;
1516 memset( &StubMsg
, 0, sizeof(StubMsg
) ); /* needed on win9x and nt4 */
1517 NdrClientInitializeNew(
1523 StubMsg
.BufferLength
= 0;
1524 NdrPointerBufferSize( &StubMsg
,
1525 (unsigned char *)memsrc
,
1527 ok(StubMsg
.BufferLength
>= sizeof(memsrc
) + 12, "length %d\n", StubMsg
.BufferLength
);
1529 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1530 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1531 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1533 ptr
= NdrPointerMarshall( &StubMsg
, (unsigned char *)memsrc
, fmtstr_conf_str
);
1534 ok(ptr
== NULL
, "ret %p\n", ptr
);
1535 size
= StubMsg
.Buffer
- StubMsg
.BufferStart
;
1536 ok(size
== sizeof(memsrc
) + 12, "Buffer %p Start %p len %d\n",
1537 StubMsg
.Buffer
, StubMsg
.BufferStart
, size
);
1538 ok(!memcmp(StubMsg
.BufferStart
+ 12, memsrc
, sizeof(memsrc
)), "incorrectly marshaled\n");
1540 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1541 StubMsg
.MemorySize
= 0;
1545 my_alloc_called
= 0;
1546 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1547 mem
= mem_orig
= HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc
));
1548 /* Windows apparently checks string length on the output buffer to determine its size... */
1549 memset( mem
, 'x', sizeof(memsrc
) - 1 );
1550 mem
[sizeof(memsrc
) - 1] = 0;
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
);
1563 /* Prevent a memory leak when running with Wine.
1564 Remove once the todo_wine block above is fixed. */
1565 if (mem
!= mem_orig
)
1566 HeapFree(GetProcessHeap(), 0, mem_orig
);
1569 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1570 NdrPointerFree( &StubMsg
, mem
, fmtstr_conf_str
);
1571 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
1575 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1576 NdrPointerFree( &StubMsg
, mem
, fmtstr_conf_str
);
1577 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
1580 my_alloc_called
= 0;
1581 StubMsg
.IsClient
= 0;
1583 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1584 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 0);
1585 ok(mem
== StubMsg
.BufferStart
+ 12 || broken(!mem
), /* win9x, nt4 */
1586 "mem not pointing at buffer %p/%p\n", mem
, StubMsg
.BufferStart
+ 12 );
1587 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1589 my_alloc_called
= 0;
1591 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1592 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 1);
1594 ok(mem
== StubMsg
.BufferStart
+ 12 || broken(!mem
), /* win9x, nt4 */
1595 "mem not pointing at buffer %p/%p\n", mem
, StubMsg
.BufferStart
+ 12 );
1596 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1599 my_alloc_called
= 0;
1600 mem
= mem_orig
= HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc
));
1601 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1602 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 0);
1603 ok(mem
== StubMsg
.BufferStart
+ 12 || broken(!mem
), /* win9x, nt4 */
1604 "mem not pointing at buffer %p/%p\n", mem
, StubMsg
.BufferStart
+ 12 );
1605 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1607 my_alloc_called
= 0;
1609 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1610 NdrPointerUnmarshall( &StubMsg
, &mem
, fmtstr_conf_str
, 1);
1612 ok(mem
== StubMsg
.BufferStart
+ 12 || broken(!mem
), /* win9x, nt4 */
1613 "mem not pointing at buffer %p/%p\n", mem
, StubMsg
.BufferStart
+ 12 );
1614 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1619 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1620 NdrPointerFree( &StubMsg
, mem
, fmtstr_conf_str
);
1621 ok(my_free_called
== 1, "free called %d\n", my_free_called
);
1623 HeapFree(GetProcessHeap(), 0, mem_orig
);
1624 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1627 static void test_nonconformant_string(void)
1629 RPC_MESSAGE RpcMessage
;
1630 MIDL_STUB_MESSAGE StubMsg
;
1631 MIDL_STUB_DESC StubDesc
;
1634 unsigned char *mem
, *mem_orig
;
1635 unsigned char memsrc
[10] = "This is";
1636 unsigned char memsrc2
[10] = "This is a";
1638 static const unsigned char fmtstr_nonconf_str
[] =
1640 0x26, /* FC_CSTRING */
1642 NdrFcShort( 0xa ), /* 10 */
1645 StubDesc
= Object_StubDesc
;
1646 StubDesc
.pFormatTypes
= fmtstr_nonconf_str
;
1649 NdrClientInitializeNew(
1655 StubMsg
.BufferLength
= 0;
1657 NdrNonConformantStringBufferSize( &StubMsg
, memsrc
, fmtstr_nonconf_str
);
1658 ok(StubMsg
.BufferLength
>= strlen((char *)memsrc
) + 1 + 8, "length %d\n", StubMsg
.BufferLength
);
1660 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1661 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1662 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1664 ptr
= NdrNonConformantStringMarshall( &StubMsg
, memsrc
, fmtstr_nonconf_str
);
1665 ok(ptr
== NULL
, "ret %p\n", ptr
);
1666 size
= StubMsg
.Buffer
- StubMsg
.BufferStart
;
1667 ok(size
== strlen((char *)memsrc
) + 1 + 8, "Buffer %p Start %p len %d\n",
1668 StubMsg
.Buffer
, StubMsg
.BufferStart
, size
);
1669 ok(!memcmp(StubMsg
.BufferStart
+ 8, memsrc
, strlen((char *)memsrc
) + 1), "incorrectly marshaled\n");
1671 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1672 StubMsg
.MemorySize
= 0;
1676 my_alloc_called
= 0;
1677 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1678 mem
= mem_orig
= HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc
));
1679 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1680 ok(mem
== mem_orig
, "mem alloced\n");
1681 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1683 my_alloc_called
= 0;
1684 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1685 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 1);
1687 ok(mem
== mem_orig
, "mem alloced\n");
1689 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1692 my_alloc_called
= 0;
1693 StubMsg
.IsClient
= 0;
1695 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1696 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1697 ok(mem
!= mem_orig
, "mem not alloced\n");
1698 ok(mem
!= StubMsg
.BufferStart
+ 8, "mem pointing at buffer\n");
1699 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1702 my_alloc_called
= 0;
1704 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1705 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1706 ok(mem
== mem_orig
, "mem alloced\n");
1707 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1709 my_alloc_called
= 0;
1711 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1712 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 1);
1714 ok(mem
== mem_orig
, "mem alloced\n");
1716 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1718 HeapFree(GetProcessHeap(), 0, mem_orig
);
1719 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1722 NdrClientInitializeNew(
1728 StubMsg
.BufferLength
= 0;
1730 NdrNonConformantStringBufferSize( &StubMsg
, memsrc2
, fmtstr_nonconf_str
);
1731 ok(StubMsg
.BufferLength
>= strlen((char *)memsrc2
) + 1 + 8, "length %d\n", StubMsg
.BufferLength
);
1733 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1734 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1735 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1737 ptr
= NdrNonConformantStringMarshall( &StubMsg
, memsrc2
, fmtstr_nonconf_str
);
1738 ok(ptr
== NULL
, "ret %p\n", ptr
);
1739 size
= StubMsg
.Buffer
- StubMsg
.BufferStart
;
1740 ok(size
== strlen((char *)memsrc2
) + 1 + 8, "Buffer %p Start %p len %d\n",
1741 StubMsg
.Buffer
, StubMsg
.BufferStart
, size
);
1742 ok(!memcmp(StubMsg
.BufferStart
+ 8, memsrc2
, strlen((char *)memsrc2
) + 1), "incorrectly marshaled\n");
1744 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1745 StubMsg
.MemorySize
= 0;
1749 my_alloc_called
= 0;
1750 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1751 mem
= mem_orig
= HeapAlloc(GetProcessHeap(), 0, sizeof(memsrc
));
1752 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1753 ok(mem
== mem_orig
, "mem alloced\n");
1754 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1756 my_alloc_called
= 0;
1757 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1758 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 1);
1760 ok(mem
== mem_orig
, "mem alloced\n");
1762 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1765 my_alloc_called
= 0;
1766 StubMsg
.IsClient
= 0;
1768 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1769 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1770 ok(mem
!= mem_orig
, "mem not alloced\n");
1771 ok(mem
!= StubMsg
.BufferStart
+ 8, "mem pointing at buffer\n");
1772 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1775 my_alloc_called
= 0;
1777 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1778 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 0);
1779 ok(mem
== mem_orig
, "mem alloced\n");
1780 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1782 my_alloc_called
= 0;
1784 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1785 NdrNonConformantStringUnmarshall( &StubMsg
, &mem
, fmtstr_nonconf_str
, 1);
1787 ok(mem
== mem_orig
, "mem alloced\n");
1789 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1791 HeapFree(GetProcessHeap(), 0, mem_orig
);
1792 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1795 static void test_conf_complex_struct(void)
1797 RPC_MESSAGE RpcMessage
;
1798 MIDL_STUB_MESSAGE StubMsg
;
1799 MIDL_STUB_DESC StubDesc
;
1805 unsigned int *array
[1];
1807 struct conf_complex
*memsrc
;
1808 struct conf_complex
*mem
;
1810 static const unsigned char fmtstr_complex_struct
[] =
1813 0x1b, /* FC_CARRAY */
1815 /* 2 */ NdrFcShort( 0x4 ), /* 4 */
1816 /* 4 */ 0x8, /* Corr desc: FC_LONG */
1818 /* 6 */ NdrFcShort( 0xfffc ), /* -4 */
1823 0x48, /* FC_VARIABLE_REPEAT */
1824 0x49, /* FC_FIXED_OFFSET */
1825 /* 12 */ NdrFcShort( 0x4 ), /* 4 */
1826 /* 14 */ NdrFcShort( 0x0 ), /* 0 */
1827 /* 16 */ NdrFcShort( 0x1 ), /* 1 */
1828 /* 18 */ NdrFcShort( 0x0 ), /* 0 */
1829 /* 20 */ NdrFcShort( 0x0 ), /* 0 */
1830 /* 22 */ 0x12, 0x8, /* FC_UP [simple_pointer] */
1831 /* 24 */ 0x8, /* FC_LONG */
1837 /* 28 */ 0x5c, /* FC_PAD */
1840 0x1a, /* FC_BOGUS_STRUCT */
1842 /* 32 */ NdrFcShort( 0x4 ), /* 4 */
1843 /* 34 */ NdrFcShort( 0xffffffde ), /* Offset= -34 (0) */
1844 /* 36 */ NdrFcShort( 0x0 ), /* Offset= 0 (36) */
1845 /* 38 */ 0x8, /* FC_LONG */
1849 memsrc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1850 FIELD_OFFSET(struct conf_complex
, array
[20]));
1853 StubDesc
= Object_StubDesc
;
1854 StubDesc
.pFormatTypes
= fmtstr_complex_struct
;
1856 NdrClientInitializeNew(
1862 StubMsg
.BufferLength
= 0;
1863 NdrComplexStructBufferSize( &StubMsg
,
1864 (unsigned char *)memsrc
,
1865 &fmtstr_complex_struct
[30] );
1866 ok(StubMsg
.BufferLength
>= 28, "length %d\n", StubMsg
.BufferLength
);
1868 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1869 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1870 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1872 ptr
= NdrComplexStructMarshall( &StubMsg
, (unsigned char *)memsrc
,
1873 &fmtstr_complex_struct
[30] );
1874 ok(ptr
== NULL
, "ret %p\n", ptr
);
1875 ok(*(unsigned int *)StubMsg
.BufferStart
== 20, "Conformance should have been 20 instead of %d\n", *(unsigned int *)StubMsg
.BufferStart
);
1876 ok(*(unsigned int *)(StubMsg
.BufferStart
+ 4) == 20, "conf_complex.size should have been 20 instead of %d\n", *(unsigned int *)(StubMsg
.BufferStart
+ 4));
1877 for (i
= 0; i
< 20; i
++)
1878 ok(*(unsigned int *)(StubMsg
.BufferStart
+ 8 + i
* 4) == 0, "pointer id for conf_complex.array[%d] should have been 0 instead of 0x%x\n", i
, *(unsigned int *)(StubMsg
.BufferStart
+ 8 + i
* 4));
1881 my_alloc_called
= 0;
1882 StubMsg
.IsClient
= 0;
1884 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1885 ptr
= NdrComplexStructUnmarshall( &StubMsg
, (unsigned char **)&mem
, &fmtstr_complex_struct
[30], 0);
1886 ok(ptr
== NULL
, "ret %p\n", ptr
);
1887 ok(mem
->size
== 20, "mem->size wasn't unmarshalled correctly (%d)\n", mem
->size
);
1888 ok(mem
->array
[0] == NULL
, "mem->array[0] wasn't unmarshalled correctly (%p)\n", mem
->array
[0]);
1889 StubMsg
.pfnFree(mem
);
1891 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1892 HeapFree(GetProcessHeap(), 0, memsrc
);
1896 static void test_conf_complex_array(void)
1898 RPC_MESSAGE RpcMessage
;
1899 MIDL_STUB_MESSAGE StubMsg
;
1900 MIDL_STUB_DESC StubDesc
;
1905 unsigned int dim1
, dim2
;
1908 struct conf_complex memsrc
;
1909 struct conf_complex
*mem
;
1910 DWORD
*buf
, expected_length
;
1912 static const unsigned char fmtstr_complex_array
[] =
1915 /* 0 */ 0x21, /* FC_BOGUS_ARRAY */
1917 /* 2 */ NdrFcShort( 0x0 ), /* 0 */
1918 /* 4 */ 0x19, 0x0, /* Corr desc: field pointer, FC_ULONG */
1919 /* 6 */ NdrFcShort( 0x4 ), /* 4 */
1920 /* 8 */ NdrFcLong( 0xffffffff ), /* -1 */
1921 /* 12 */ 0x8, /* FC_LONG */
1924 0x21, /* FC_BOGUS_ARRAY */
1926 /* 16 */ NdrFcShort( 0x0 ), /* 0 */
1927 /* 18 */ 0x19, /* Corr desc: field pointer, FC_ULONG */
1929 /* 20 */ NdrFcShort( 0x0 ), /* 0 */
1930 /* 22 */ NdrFcLong( 0xffffffff ), /* -1 */
1931 /* 26 */ 0x12, 0x0, /* FC_UP */
1932 /* 28 */ NdrFcShort( 0xffe4 ), /* Offset= -28 (0) */
1933 /* 30 */ 0x5c, /* FC_PAD */
1937 /* 32 */ 0x1a, /* FC_BOGUS_STRUCT */
1939 /* 34 */ NdrFcShort( 0x10 ), /* 16 */
1940 /* 36 */ NdrFcShort( 0x0 ), /* 0 */
1941 /* 38 */ NdrFcShort( 0x6 ), /* Offset= 6 (44) */
1942 /* 40 */ 0x8, /* FC_LONG */
1944 /* 42 */ 0x36, /* FC_POINTER */
1947 0x12, 0x0, /* FC_UP */
1948 /* 46 */ NdrFcShort( 0xffe0 ), /* Offset= -32 (14) */
1951 0x16, /* FC_PSTRUCT */
1953 /* 34 */ NdrFcShort( 0xc ), /* 12 */
1954 /* 36 */ 0x4b, /* FC_PP */
1956 /* 38 */ 0x46, /* FC_NO_REPEAT */
1958 /* 40 */ NdrFcShort( 0x8 ), /* 8 */
1959 /* 42 */ NdrFcShort( 0x8 ), /* 8 */
1960 /* 44 */ 0x12, 0x0, /* FC_UP */
1961 /* 46 */ NdrFcShort( 0xffe0 ), /* Offset= -32 (14) */
1962 /* 48 */ 0x5b, /* FC_END */
1964 /* 50 */ 0x8, /* FC_LONG */
1966 /* 52 */ 0x5c, /* FC_PAD */
1974 memsrc
.array
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, memsrc
.dim1
* sizeof(DWORD
*));
1976 for(i
= 0; i
< memsrc
.dim1
; i
++)
1978 memsrc
.array
[i
] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, memsrc
.dim2
* sizeof(DWORD
));
1979 for(j
= 0; j
< memsrc
.dim2
; j
++)
1980 memsrc
.array
[i
][j
] = i
* memsrc
.dim2
+ j
;
1983 StubDesc
= Object_StubDesc
;
1984 StubDesc
.pFormatTypes
= fmtstr_complex_array
;
1986 NdrClientInitializeNew(
1992 StubMsg
.BufferLength
= 0;
1995 NdrComplexStructBufferSize( &StubMsg
,
1996 (unsigned char *)&memsrc
,
1997 &fmtstr_complex_array
[32] );
1999 NdrSimpleStructBufferSize( &StubMsg
,
2000 (unsigned char *)&memsrc
,
2001 &fmtstr_complex_array
[32] );
2004 expected_length
= (4 + memsrc
.dim1
* (2 + memsrc
.dim2
)) * 4;
2005 if (StubMsg
.BufferLength
== 96)
2007 win_skip("Tests crash on Win9x, WinMe and NT4\n");
2010 ok(StubMsg
.BufferLength
>= expected_length
, "length %d\n", StubMsg
.BufferLength
);
2012 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
2013 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
2014 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
2017 ptr
= NdrComplexStructMarshall( &StubMsg
, (unsigned char *)&memsrc
,
2018 &fmtstr_complex_array
[32] );
2020 ptr
= NdrSimpleStructMarshall( &StubMsg
, (unsigned char *)&memsrc
,
2021 &fmtstr_complex_array
[32] );
2024 ok(ptr
== NULL
, "ret %p\n", ptr
);
2025 ok((char*)StubMsg
.Buffer
== (char*)StubMsg
.BufferStart
+ expected_length
, "not at expected length\n");
2027 buf
= (DWORD
*)StubMsg
.BufferStart
;
2029 ok(*buf
== memsrc
.dim1
, "dim1 should have been %d instead of %08x\n", memsrc
.dim1
, *buf
);
2031 ok(*buf
== memsrc
.dim2
, "dim2 should have been %d instead of %08x\n", memsrc
.dim2
, *buf
);
2033 ok(*buf
!= 0, "pointer id should be non-zero\n");
2035 ok(*buf
== memsrc
.dim1
, "Conformance should have been %d instead of %08x\n", memsrc
.dim1
, *buf
);
2037 for(i
= 0; i
< memsrc
.dim1
; i
++)
2039 ok(*buf
!= 0, "pointer id[%d] should be non-zero\n", i
);
2042 for(i
= 0; i
< memsrc
.dim1
; i
++)
2044 ok(*buf
== memsrc
.dim2
, "Conformance should have been %d instead of %08x\n", memsrc
.dim2
, *buf
);
2046 for(j
= 0; j
< memsrc
.dim2
; j
++)
2048 ok(*buf
== i
* memsrc
.dim2
+ j
, "got %08x\n", *buf
);
2053 ok((void*)buf
== StubMsg
.Buffer
, "not at end of buffer\n");
2056 my_alloc_called
= 0;
2057 StubMsg
.IsClient
= 0;
2059 StubMsg
.Buffer
= StubMsg
.BufferStart
;
2061 ptr
= NdrComplexStructUnmarshall( &StubMsg
, (unsigned char **)&mem
, &fmtstr_complex_array
[32], 0);
2063 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, (unsigned char **)&mem
, &fmtstr_complex_array
[32], 0);
2065 ok(ptr
== NULL
, "ret %p\n", ptr
);
2066 ok(mem
->dim1
== memsrc
.dim1
, "mem->dim1 wasn't unmarshalled correctly (%d)\n", mem
->dim1
);
2067 ok(mem
->dim2
== memsrc
.dim2
, "mem->dim2 wasn't unmarshalled correctly (%d)\n", mem
->dim2
);
2068 ok(mem
->array
[1][0] == memsrc
.dim2
, "mem->array[1][0] wasn't unmarshalled correctly (%d)\n", mem
->array
[1][0]);
2070 StubMsg
.Buffer
= StubMsg
.BufferStart
;
2072 NdrComplexStructFree( &StubMsg
, (unsigned char*)mem
, &fmtstr_complex_array
[32]);
2074 NdrSimpleStructFree( &StubMsg
, (unsigned char*)mem
, &fmtstr_complex_array
[32]);
2077 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
2080 for(i
= 0; i
< memsrc
.dim1
; i
++)
2081 HeapFree(GetProcessHeap(), 0, memsrc
.array
[i
]);
2082 HeapFree(GetProcessHeap(), 0, memsrc
.array
);
2085 static void test_ndr_buffer(void)
2087 static unsigned char ncalrpc
[] = "ncalrpc";
2088 static unsigned char endpoint
[] = "winetest:test_ndr_buffer";
2089 RPC_MESSAGE RpcMessage
;
2090 MIDL_STUB_MESSAGE StubMsg
;
2091 MIDL_STUB_DESC StubDesc
= Object_StubDesc
;
2093 unsigned char *binding
;
2094 RPC_BINDING_HANDLE Handle
;
2096 ULONG prev_buffer_length
;
2097 BOOL old_buffer_valid_location
;
2099 StubDesc
.RpcInterfaceInformation
= (void *)&IFoo___RpcServerInterface
;
2101 status
= RpcServerUseProtseqEpA(ncalrpc
, 20, endpoint
, NULL
);
2102 ok(RPC_S_OK
== status
, "RpcServerUseProtseqEp failed with status %u\n", status
);
2103 status
= RpcServerRegisterIf(IFoo_v0_0_s_ifspec
, NULL
, NULL
);
2104 ok(RPC_S_OK
== status
, "RpcServerRegisterIf failed with status %u\n", status
);
2105 status
= RpcServerListen(1, 20, TRUE
);
2106 ok(RPC_S_OK
== status
, "RpcServerListen failed with status %u\n", status
);
2107 if (status
!= RPC_S_OK
)
2109 /* Failed to create a server, running client tests is useless */
2113 status
= RpcStringBindingComposeA(NULL
, ncalrpc
, NULL
, endpoint
, NULL
, &binding
);
2114 ok(status
== RPC_S_OK
, "RpcStringBindingCompose failed (%u)\n", status
);
2116 status
= RpcBindingFromStringBindingA(binding
, &Handle
);
2117 ok(status
== RPC_S_OK
, "RpcBindingFromStringBinding failed (%u)\n", status
);
2118 RpcStringFreeA(&binding
);
2120 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &StubDesc
, 5);
2122 ret
= NdrGetBuffer(&StubMsg
, 10, Handle
);
2123 ok(ret
== StubMsg
.Buffer
, "NdrGetBuffer should have returned the same value as StubMsg.Buffer instead of %p\n", ret
);
2124 ok(RpcMessage
.Handle
!= NULL
, "RpcMessage.Handle should not have been NULL\n");
2125 ok(RpcMessage
.Buffer
!= NULL
, "RpcMessage.Buffer should not have been NULL\n");
2126 ok(RpcMessage
.BufferLength
== 10 ||
2127 broken(RpcMessage
.BufferLength
== 12), /* win2k */
2128 "RpcMessage.BufferLength should have been 10 instead of %d\n", RpcMessage
.BufferLength
);
2129 ok(RpcMessage
.RpcFlags
== 0, "RpcMessage.RpcFlags should have been 0x0 instead of 0x%x\n", RpcMessage
.RpcFlags
);
2130 ok(StubMsg
.Buffer
!= NULL
, "Buffer should not have been NULL\n");
2131 ok(!StubMsg
.BufferStart
, "BufferStart should have been NULL instead of %p\n", StubMsg
.BufferStart
);
2132 ok(!StubMsg
.BufferEnd
, "BufferEnd should have been NULL instead of %p\n", StubMsg
.BufferEnd
);
2134 ok(StubMsg
.BufferLength
== 0, "BufferLength should have left as 0 instead of being set to %d\n", StubMsg
.BufferLength
);
2135 old_buffer_valid_location
= !StubMsg
.fBufferValid
;
2136 if (old_buffer_valid_location
)
2137 ok(broken(StubMsg
.CorrDespIncrement
== TRUE
), "fBufferValid should have been TRUE instead of 0x%x\n", StubMsg
.CorrDespIncrement
);
2139 ok(StubMsg
.fBufferValid
, "fBufferValid should have been non-zero instead of 0x%x\n", StubMsg
.fBufferValid
);
2141 prev_buffer_length
= RpcMessage
.BufferLength
;
2142 StubMsg
.BufferLength
= 1;
2143 NdrFreeBuffer(&StubMsg
);
2144 ok(RpcMessage
.Handle
!= NULL
, "RpcMessage.Handle should not have been NULL\n");
2145 ok(RpcMessage
.Buffer
!= NULL
, "RpcMessage.Buffer should not have been NULL\n");
2146 ok(RpcMessage
.BufferLength
== prev_buffer_length
, "RpcMessage.BufferLength should have been left as %d instead of %d\n", prev_buffer_length
, RpcMessage
.BufferLength
);
2147 ok(StubMsg
.Buffer
!= NULL
, "Buffer should not have been NULL\n");
2148 ok(StubMsg
.BufferLength
== 1, "BufferLength should have left as 1 instead of being set to %d\n", StubMsg
.BufferLength
);
2149 if (old_buffer_valid_location
)
2150 ok(broken(StubMsg
.CorrDespIncrement
== FALSE
), "fBufferValid should have been FALSE instead of 0x%x\n", StubMsg
.CorrDespIncrement
);
2152 ok(!StubMsg
.fBufferValid
, "fBufferValid should have been FALSE instead of %d\n", StubMsg
.fBufferValid
);
2154 /* attempt double-free */
2155 NdrFreeBuffer(&StubMsg
);
2157 RpcBindingFree(&Handle
);
2159 status
= RpcServerUnregisterIf(NULL
, NULL
, FALSE
);
2160 ok(status
== RPC_S_OK
, "RpcServerUnregisterIf failed (%u)\n", status
);
2163 static void test_NdrMapCommAndFaultStatus(void)
2165 RPC_STATUS rpc_status
;
2166 MIDL_STUB_MESSAGE StubMsg
;
2167 RPC_MESSAGE RpcMessage
;
2169 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &Object_StubDesc
, 5);
2171 for (rpc_status
= 0; rpc_status
< 10000; rpc_status
++)
2174 ULONG comm_status
= 0;
2175 ULONG fault_status
= 0;
2176 ULONG expected_comm_status
= 0;
2177 ULONG expected_fault_status
= 0;
2178 status
= NdrMapCommAndFaultStatus(&StubMsg
, &comm_status
, &fault_status
, rpc_status
);
2179 ok(status
== RPC_S_OK
, "NdrMapCommAndFaultStatus failed with error %d\n", status
);
2182 case ERROR_INVALID_HANDLE
:
2183 case RPC_S_INVALID_BINDING
:
2184 case RPC_S_UNKNOWN_IF
:
2185 case RPC_S_SERVER_UNAVAILABLE
:
2186 case RPC_S_SERVER_TOO_BUSY
:
2187 case RPC_S_CALL_FAILED_DNE
:
2188 case RPC_S_PROTOCOL_ERROR
:
2189 case RPC_S_UNSUPPORTED_TRANS_SYN
:
2190 case RPC_S_UNSUPPORTED_TYPE
:
2191 case RPC_S_PROCNUM_OUT_OF_RANGE
:
2192 case EPT_S_NOT_REGISTERED
:
2193 case RPC_S_COMM_FAILURE
:
2194 expected_comm_status
= rpc_status
;
2197 expected_fault_status
= rpc_status
;
2199 ok(comm_status
== expected_comm_status
, "NdrMapCommAndFaultStatus should have mapped %d to comm status %d instead of %d\n",
2200 rpc_status
, expected_comm_status
, comm_status
);
2201 ok(fault_status
== expected_fault_status
, "NdrMapCommAndFaultStatus should have mapped %d to fault status %d instead of %d\n",
2202 rpc_status
, expected_fault_status
, fault_status
);
2206 static void test_NdrGetUserMarshalInfo(void)
2209 MIDL_STUB_MESSAGE stubmsg
;
2210 USER_MARSHAL_CB umcb
;
2211 NDR_USER_MARSHAL_INFO umi
;
2212 unsigned char buffer
[16];
2213 void *rpc_channel_buffer
= (void *)(ULONG_PTR
)0xcafebabe;
2214 RPC_MESSAGE rpc_msg
;
2215 RPC_STATUS (RPC_ENTRY
*pNdrGetUserMarshalInfo
)(ULONG
*,ULONG
,NDR_USER_MARSHAL_INFO
*);
2217 pNdrGetUserMarshalInfo
= (void *)GetProcAddress(GetModuleHandleA("rpcrt4.dll"), "NdrGetUserMarshalInfo");
2218 if (!pNdrGetUserMarshalInfo
)
2220 skip("NdrGetUserMarshalInfo not exported\n");
2226 memset(&rpc_msg
, 0xcc, sizeof(rpc_msg
));
2227 rpc_msg
.Buffer
= buffer
;
2228 rpc_msg
.BufferLength
= 16;
2230 memset(&stubmsg
, 0xcc, sizeof(stubmsg
));
2231 stubmsg
.RpcMsg
= &rpc_msg
;
2232 stubmsg
.dwDestContext
= MSHCTX_INPROC
;
2233 stubmsg
.pvDestContext
= NULL
;
2234 stubmsg
.Buffer
= buffer
+ 15;
2235 stubmsg
.BufferLength
= 0;
2236 stubmsg
.BufferEnd
= NULL
;
2237 stubmsg
.pRpcChannelBuffer
= rpc_channel_buffer
;
2238 stubmsg
.StubDesc
= NULL
;
2239 stubmsg
.pfnAllocate
= my_alloc
;
2240 stubmsg
.pfnFree
= my_free
;
2242 memset(&umcb
, 0xcc, sizeof(umcb
));
2243 umcb
.Flags
= MAKELONG(MSHCTX_INPROC
, NDR_LOCAL_DATA_REPRESENTATION
);
2244 umcb
.pStubMsg
= &stubmsg
;
2245 umcb
.Signature
= USER_MARSHAL_CB_SIGNATURE
;
2246 umcb
.CBType
= USER_MARSHAL_CB_UNMARSHALL
;
2248 memset(&umi
, 0xaa, sizeof(umi
));
2250 status
= pNdrGetUserMarshalInfo(&umcb
.Flags
, 1, &umi
);
2251 ok(status
== RPC_S_OK
, "NdrGetUserMarshalInfo failed with error %d\n", status
);
2252 ok( umi
.InformationLevel
== 1,
2253 "umi.InformationLevel was %u instead of 1\n",
2254 umi
.InformationLevel
);
2255 ok( U1(umi
).Level1
.Buffer
== buffer
+ 15,
2256 "umi.Level1.Buffer was %p instead of %p\n",
2257 U1(umi
).Level1
.Buffer
, buffer
);
2258 ok( U1(umi
).Level1
.BufferSize
== 1,
2259 "umi.Level1.BufferSize was %u instead of 1\n",
2260 U1(umi
).Level1
.BufferSize
);
2261 ok( U1(umi
).Level1
.pfnAllocate
== my_alloc
,
2262 "umi.Level1.pfnAllocate was %p instead of %p\n",
2263 U1(umi
).Level1
.pfnAllocate
, my_alloc
);
2264 ok( U1(umi
).Level1
.pfnFree
== my_free
,
2265 "umi.Level1.pfnFree was %p instead of %p\n",
2266 U1(umi
).Level1
.pfnFree
, my_free
);
2267 ok( U1(umi
).Level1
.pRpcChannelBuffer
== rpc_channel_buffer
,
2268 "umi.Level1.pRpcChannelBuffer was %p instead of %p\n",
2269 U1(umi
).Level1
.pRpcChannelBuffer
, rpc_channel_buffer
);
2273 rpc_msg
.Buffer
= buffer
;
2274 rpc_msg
.BufferLength
= 16;
2276 stubmsg
.Buffer
= buffer
;
2277 stubmsg
.BufferLength
= 16;
2278 stubmsg
.BufferEnd
= NULL
;
2280 umcb
.CBType
= USER_MARSHAL_CB_BUFFER_SIZE
;
2282 memset(&umi
, 0xaa, sizeof(umi
));
2284 status
= pNdrGetUserMarshalInfo(&umcb
.Flags
, 1, &umi
);
2285 ok(status
== RPC_S_OK
, "NdrGetUserMarshalInfo failed with error %d\n", status
);
2286 ok( umi
.InformationLevel
== 1,
2287 "umi.InformationLevel was %u instead of 1\n",
2288 umi
.InformationLevel
);
2289 ok( U1(umi
).Level1
.Buffer
== NULL
,
2290 "umi.Level1.Buffer was %p instead of NULL\n",
2291 U1(umi
).Level1
.Buffer
);
2292 ok( U1(umi
).Level1
.BufferSize
== 0,
2293 "umi.Level1.BufferSize was %u instead of 0\n",
2294 U1(umi
).Level1
.BufferSize
);
2295 ok( U1(umi
).Level1
.pfnAllocate
== my_alloc
,
2296 "umi.Level1.pfnAllocate was %p instead of %p\n",
2297 U1(umi
).Level1
.pfnAllocate
, my_alloc
);
2298 ok( U1(umi
).Level1
.pfnFree
== my_free
,
2299 "umi.Level1.pfnFree was %p instead of %p\n",
2300 U1(umi
).Level1
.pfnFree
, my_free
);
2301 ok( U1(umi
).Level1
.pRpcChannelBuffer
== rpc_channel_buffer
,
2302 "umi.Level1.pRpcChannelBuffer was %p instead of %p\n",
2303 U1(umi
).Level1
.pRpcChannelBuffer
, rpc_channel_buffer
);
2307 rpc_msg
.Buffer
= buffer
;
2308 rpc_msg
.BufferLength
= 16;
2310 stubmsg
.Buffer
= buffer
+ 15;
2311 stubmsg
.BufferLength
= 0;
2312 stubmsg
.BufferEnd
= NULL
;
2314 umcb
.CBType
= USER_MARSHAL_CB_MARSHALL
;
2316 memset(&umi
, 0xaa, sizeof(umi
));
2318 status
= pNdrGetUserMarshalInfo(&umcb
.Flags
, 1, &umi
);
2319 ok(status
== RPC_S_OK
, "NdrGetUserMarshalInfo failed with error %d\n", status
);
2320 ok( umi
.InformationLevel
== 1,
2321 "umi.InformationLevel was %u instead of 1\n",
2322 umi
.InformationLevel
);
2323 ok( U1(umi
).Level1
.Buffer
== buffer
+ 15,
2324 "umi.Level1.Buffer was %p instead of %p\n",
2325 U1(umi
).Level1
.Buffer
, buffer
);
2326 ok( U1(umi
).Level1
.BufferSize
== 1,
2327 "umi.Level1.BufferSize was %u instead of 1\n",
2328 U1(umi
).Level1
.BufferSize
);
2329 ok( U1(umi
).Level1
.pfnAllocate
== my_alloc
,
2330 "umi.Level1.pfnAllocate was %p instead of %p\n",
2331 U1(umi
).Level1
.pfnAllocate
, my_alloc
);
2332 ok( U1(umi
).Level1
.pfnFree
== my_free
,
2333 "umi.Level1.pfnFree was %p instead of %p\n",
2334 U1(umi
).Level1
.pfnFree
, my_free
);
2335 ok( U1(umi
).Level1
.pRpcChannelBuffer
== rpc_channel_buffer
,
2336 "umi.Level1.pRpcChannelBuffer was %p instead of %p\n",
2337 U1(umi
).Level1
.pRpcChannelBuffer
, rpc_channel_buffer
);
2341 rpc_msg
.Buffer
= buffer
;
2342 rpc_msg
.BufferLength
= 16;
2344 stubmsg
.Buffer
= buffer
;
2345 stubmsg
.BufferLength
= 16;
2346 stubmsg
.BufferEnd
= NULL
;
2348 umcb
.CBType
= USER_MARSHAL_CB_FREE
;
2350 memset(&umi
, 0xaa, sizeof(umi
));
2352 status
= pNdrGetUserMarshalInfo(&umcb
.Flags
, 1, &umi
);
2353 ok(status
== RPC_S_OK
, "NdrGetUserMarshalInfo failed with error %d\n", status
);
2354 ok( umi
.InformationLevel
== 1,
2355 "umi.InformationLevel was %u instead of 1\n",
2356 umi
.InformationLevel
);
2357 ok( U1(umi
).Level1
.Buffer
== NULL
,
2358 "umi.Level1.Buffer was %p instead of NULL\n",
2359 U1(umi
).Level1
.Buffer
);
2360 ok( U1(umi
).Level1
.BufferSize
== 0,
2361 "umi.Level1.BufferSize was %u instead of 0\n",
2362 U1(umi
).Level1
.BufferSize
);
2363 ok( U1(umi
).Level1
.pfnAllocate
== my_alloc
,
2364 "umi.Level1.pfnAllocate was %p instead of %p\n",
2365 U1(umi
).Level1
.pfnAllocate
, my_alloc
);
2366 ok( U1(umi
).Level1
.pfnFree
== my_free
,
2367 "umi.Level1.pfnFree was %p instead of %p\n",
2368 U1(umi
).Level1
.pfnFree
, my_free
);
2369 ok( U1(umi
).Level1
.pRpcChannelBuffer
== rpc_channel_buffer
,
2370 "umi.Level1.pRpcChannelBuffer was %p instead of %p\n",
2371 U1(umi
).Level1
.pRpcChannelBuffer
, rpc_channel_buffer
);
2375 rpc_msg
.Buffer
= buffer
;
2376 rpc_msg
.BufferLength
= 15;
2378 stubmsg
.Buffer
= buffer
+ 15;
2379 stubmsg
.BufferLength
= 0;
2380 stubmsg
.BufferEnd
= NULL
;
2382 umcb
.CBType
= USER_MARSHAL_CB_MARSHALL
;
2384 status
= pNdrGetUserMarshalInfo(&umcb
.Flags
, 1, &umi
);
2385 ok(status
== RPC_S_OK
, "NdrGetUserMarshalInfo failed with error %d\n", status
);
2386 ok( U1(umi
).Level1
.BufferSize
== 0,
2387 "umi.Level1.BufferSize was %u instead of 0\n",
2388 U1(umi
).Level1
.BufferSize
);
2390 /* error conditions */
2392 rpc_msg
.BufferLength
= 14;
2393 status
= pNdrGetUserMarshalInfo(&umcb
.Flags
, 1, &umi
);
2394 ok(status
== ERROR_INVALID_USER_BUFFER
,
2395 "NdrGetUserMarshalInfo should have failed with ERROR_INVALID_USER_BUFFER instead of %d\n", status
);
2397 rpc_msg
.BufferLength
= 15;
2398 status
= pNdrGetUserMarshalInfo(&umcb
.Flags
, 9999, &umi
);
2399 ok(status
== RPC_S_INVALID_ARG
,
2400 "NdrGetUserMarshalInfo should have failed with RPC_S_INVALID_ARG instead of %d\n", status
);
2403 status
= pNdrGetUserMarshalInfo(&umcb
.Flags
, 1, &umi
);
2404 ok(status
== RPC_S_OK
, "NdrGetUserMarshalInfo failed with error %d\n", status
);
2406 umcb
.CBType
= USER_MARSHAL_CB_MARSHALL
;
2408 status
= pNdrGetUserMarshalInfo(&umcb
.Flags
, 1, &umi
);
2409 ok(status
== RPC_S_INVALID_ARG
,
2410 "NdrGetUserMarshalInfo should have failed with RPC_S_INVALID_ARG instead of %d\n", status
);
2413 static void test_MesEncodeFixedBufferHandleCreate(void)
2420 status
= MesEncodeFixedBufferHandleCreate(NULL
, 0, NULL
, NULL
);
2421 ok(status
== RPC_S_INVALID_ARG
, "got %d\n", status
);
2423 status
= MesEncodeFixedBufferHandleCreate(NULL
, 0, NULL
, &handle
);
2424 ok(status
== RPC_S_INVALID_ARG
, "got %d\n", status
);
2426 status
= MesEncodeFixedBufferHandleCreate((char*)0xdeadbeef, 0, NULL
, &handle
);
2427 ok(status
== RPC_X_INVALID_BUFFER
, "got %d\n", status
);
2429 buffer
= (void*)((0xdeadbeef + 7) & ~7);
2430 status
= MesEncodeFixedBufferHandleCreate(buffer
, 0, NULL
, &handle
);
2431 ok(status
== RPC_S_INVALID_ARG
, "got %d\n", status
);
2433 status
= MesEncodeFixedBufferHandleCreate(buffer
, 0, &encoded_size
, &handle
);
2435 ok(status
== RPC_S_INVALID_ARG
, "got %d\n", status
);
2436 if (status
== RPC_S_OK
) {
2437 MesHandleFree(handle
);
2439 status
= MesEncodeFixedBufferHandleCreate(buffer
, 32, NULL
, &handle
);
2440 ok(status
== RPC_S_INVALID_ARG
, "got %d\n", status
);
2442 status
= MesEncodeFixedBufferHandleCreate(buffer
, 32, &encoded_size
, &handle
);
2443 ok(status
== RPC_S_OK
, "got %d\n", status
);
2445 status
= MesBufferHandleReset(NULL
, MES_DYNAMIC_BUFFER_HANDLE
, MES_ENCODE
,
2446 &buffer
, 32, &encoded_size
);
2447 ok(status
== RPC_S_INVALID_ARG
, "got %d\n", status
);
2449 /* convert to dynamic buffer handle */
2450 status
= MesBufferHandleReset(handle
, MES_DYNAMIC_BUFFER_HANDLE
, MES_ENCODE
,
2451 &buffer
, 32, &encoded_size
);
2452 ok(status
== RPC_S_OK
, "got %d\n", status
);
2454 status
= MesBufferHandleReset(handle
, MES_DYNAMIC_BUFFER_HANDLE
, MES_ENCODE
,
2455 NULL
, 32, &encoded_size
);
2456 ok(status
== RPC_S_INVALID_ARG
, "got %d\n", status
);
2458 status
= MesBufferHandleReset(handle
, MES_DYNAMIC_BUFFER_HANDLE
, MES_ENCODE
,
2460 ok(status
== RPC_S_INVALID_ARG
, "got %d\n", status
);
2462 /* invalid handle type */
2463 status
= MesBufferHandleReset(handle
, MES_DYNAMIC_BUFFER_HANDLE
+1, MES_ENCODE
,
2464 &buffer
, 32, &encoded_size
);
2465 ok(status
== RPC_S_INVALID_ARG
, "got %d\n", status
);
2467 status
= MesHandleFree(handle
);
2468 ok(status
== RPC_S_OK
, "got %d\n", status
);
2471 static void test_NdrCorrelationInitialize(void)
2473 MIDL_STUB_MESSAGE stub_msg
;
2476 memset( &stub_msg
, 0, sizeof(stub_msg
) );
2477 memset( buf
, 0, sizeof(buf
) );
2479 NdrCorrelationInitialize( &stub_msg
, buf
, sizeof(buf
), 0 );
2480 ok( stub_msg
.CorrDespIncrement
== 2 ||
2481 broken(stub_msg
.CorrDespIncrement
== 0), /* <= Win 2003 */
2482 "got %d\n", stub_msg
.CorrDespIncrement
);
2484 memset( &stub_msg
, 0, sizeof(stub_msg
) );
2485 memset( buf
, 0, sizeof(buf
) );
2487 stub_msg
.CorrDespIncrement
= 1;
2488 NdrCorrelationInitialize( &stub_msg
, buf
, sizeof(buf
), 0 );
2489 ok( stub_msg
.CorrDespIncrement
== 1, "got %d\n", stub_msg
.CorrDespIncrement
);
2492 START_TEST( ndr_marshall
)
2494 determine_pointer_marshalling_style();
2496 test_ndr_simple_type();
2497 test_simple_types();
2498 test_nontrivial_pointer_types();
2499 test_simple_struct();
2500 test_fullpointer_xlat();
2503 test_ndr_allocate();
2504 test_conformant_array();
2505 test_conformant_string();
2506 test_nonconformant_string();
2507 test_conf_complex_struct();
2508 test_conf_complex_array();
2510 test_NdrMapCommAndFaultStatus();
2511 test_NdrGetUserMarshalInfo();
2512 test_MesEncodeFixedBufferHandleCreate();
2513 test_NdrCorrelationInitialize();