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"
38 static int my_alloc_called
;
39 static int my_free_called
;
40 static void * CALLBACK
my_alloc(size_t size
)
43 return NdrOleAllocate(size
);
46 static void CALLBACK
my_free(void *ptr
)
52 static const MIDL_STUB_DESC Object_StubDesc
=
62 NULL
, /* format string, filled in by tests */
63 1, /* -error bounds_check flag */
64 0x20000, /* Ndr library version */
66 0x50100a4, /* MIDL Version 5.1.164 */
69 0, /* notify & notify_flag routine table */
77 static void test_ndr_simple_type(void)
79 RPC_MESSAGE RpcMessage
;
80 MIDL_STUB_MESSAGE StubMsg
;
81 MIDL_STUB_DESC StubDesc
;
84 StubDesc
= Object_StubDesc
;
85 StubDesc
.pFormatTypes
= NULL
;
87 NdrClientInitializeNew(
93 StubMsg
.BufferLength
= 16;
94 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
96 NdrSimpleTypeMarshall(&StubMsg
, (unsigned char*)&l
, 8 /* FC_LONG */);
97 ok(StubMsg
.Buffer
== StubMsg
.BufferStart
+ 4, "%p %p\n", StubMsg
.Buffer
, StubMsg
.BufferStart
);
98 ok(*(long*)StubMsg
.BufferStart
== l
, "%ld\n", *(long*)StubMsg
.BufferStart
);
100 StubMsg
.Buffer
= StubMsg
.BufferStart
+ 1;
101 NdrSimpleTypeMarshall(&StubMsg
, (unsigned char*)&l
, 8 /* FC_LONG */);
102 ok(StubMsg
.Buffer
== StubMsg
.BufferStart
+ 8, "%p %p\n", StubMsg
.Buffer
, StubMsg
.BufferStart
);
103 ok(*(long*)(StubMsg
.BufferStart
+ 4) == l
, "%ld\n", *(long*)StubMsg
.BufferStart
);
105 StubMsg
.Buffer
= StubMsg
.BufferStart
+ 1;
106 NdrSimpleTypeUnmarshall(&StubMsg
, (unsigned char*)&l2
, 8 /* FC_LONG */);
107 ok(StubMsg
.Buffer
== StubMsg
.BufferStart
+ 8, "%p %p\n", StubMsg
.Buffer
, StubMsg
.BufferStart
);
108 ok(l2
== l
, "%ld\n", l2
);
110 HeapFree(GetProcessHeap(), 0, StubMsg
.BufferStart
);
113 static void test_pointer_marshal(const unsigned char *formattypes
,
116 const void *wiredata
,
118 int(*cmp
)(const void*,const void*,size_t),
119 long num_additional_allocs
,
122 RPC_MESSAGE RpcMessage
;
123 MIDL_STUB_MESSAGE StubMsg
;
124 MIDL_STUB_DESC StubDesc
;
127 unsigned char *mem
, *mem_orig
;
129 my_alloc_called
= my_free_called
= 0;
133 StubDesc
= Object_StubDesc
;
134 StubDesc
.pFormatTypes
= formattypes
;
136 NdrClientInitializeNew(
142 StubMsg
.BufferLength
= 0;
143 NdrPointerBufferSize( &StubMsg
,
146 ok(StubMsg
.BufferLength
>= wiredatalen
, "%s: length %d\n", msgpfx
, StubMsg
.BufferLength
);
148 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
149 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
150 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
152 memset(StubMsg
.BufferStart
, 0x0, StubMsg
.BufferLength
); /* This is a hack to clear the padding between the ptr and longlong/double */
154 ptr
= NdrPointerMarshall( &StubMsg
, memsrc
, formattypes
);
155 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
156 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %ld\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
157 ok(!memcmp(StubMsg
.BufferStart
, wiredata
, wiredatalen
), "%s: incorrectly marshaled\n", msgpfx
);
159 StubMsg
.Buffer
= StubMsg
.BufferStart
;
160 StubMsg
.MemorySize
= 0;
164 /* NdrPointerMemorySize crashes under Wine */
165 size
= NdrPointerMemorySize( &StubMsg
, formattypes
);
166 ok(size
== StubMsg
.MemorySize
, "%s: mem size %u size %u\n", msgpfx
, StubMsg
.MemorySize
, size
);
167 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %ld\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
168 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
169 ok(size
== srcsize
+ 4, "%s: mem size %u\n", msgpfx
, size
);
171 ok(size
== srcsize
, "%s: mem size %u\n", msgpfx
, size
);
173 StubMsg
.Buffer
= StubMsg
.BufferStart
;
174 StubMsg
.MemorySize
= 16;
175 size
= NdrPointerMemorySize( &StubMsg
, formattypes
);
176 ok(size
== StubMsg
.MemorySize
, "%s: mem size %u size %u\n", msgpfx
, StubMsg
.MemorySize
, size
);
177 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %ld\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
178 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
179 ok(size
== srcsize
+ 4 + 16, "%s: mem size %u\n", msgpfx
, size
);
181 ok(size
== srcsize
+ 16, "%s: mem size %u\n", msgpfx
, size
);
183 StubMsg
.Buffer
= StubMsg
.BufferStart
;
184 StubMsg
.MemorySize
= 1;
185 size
= NdrPointerMemorySize( &StubMsg
, formattypes
);
186 ok(size
== StubMsg
.MemorySize
, "%s: mem size %u size %u\n", msgpfx
, StubMsg
.MemorySize
, size
);
187 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %ld\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
188 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
189 ok(size
== srcsize
+ 4 + (srcsize
== 8 ? 8 : 4), "%s: mem size %u\n", msgpfx
, size
);
191 ok(size
== srcsize
+ (srcsize
== 8 ? 8 : 4), "%s: mem size %u\n", msgpfx
, size
);
195 if(formattypes
[1] & 0x10) size
+= 4;
197 StubMsg
.Buffer
= StubMsg
.BufferStart
;
198 StubMsg
.MemorySize
= 0;
199 mem_orig
= mem
= HeapAlloc(GetProcessHeap(), 0, size
);
201 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
203 ptr
= NdrPointerUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
204 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
205 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
206 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
207 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %ld\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
208 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
209 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
212 /* reset the buffer and call with must alloc */
213 StubMsg
.Buffer
= StubMsg
.BufferStart
;
214 if(formattypes
[1] & 0x10 /* FC_POINTER_DEREF */)
216 ptr
= NdrPointerUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
217 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
218 /* doesn't allocate mem in this case */
220 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
222 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
223 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %ld\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
224 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
227 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
230 if(formattypes
[0] != 0x11 /* FC_RP */)
232 /* now pass the address of a NULL ptr */
234 StubMsg
.Buffer
= StubMsg
.BufferStart
;
235 ptr
= NdrPointerUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
236 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
237 ok(mem
!= StubMsg
.BufferStart
+ wiredatalen
- srcsize
, "%s: mem points to buffer %p %p\n", msgpfx
, mem
, StubMsg
.BufferStart
);
238 ok(!cmp(mem
, memsrc
, size
), "%s: incorrectly unmarshaled\n", msgpfx
);
239 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %ld\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
240 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
241 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
243 NdrPointerFree(&StubMsg
, mem
, formattypes
);
245 /* again pass address of NULL ptr, but pretend we're a server */
247 StubMsg
.Buffer
= StubMsg
.BufferStart
;
248 StubMsg
.IsClient
= 0;
249 ptr
= NdrPointerUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
250 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
252 ok(mem
== StubMsg
.BufferStart
+ wiredatalen
- srcsize
, "%s: mem doesn't point to buffer %p %p\n", msgpfx
, mem
, StubMsg
.BufferStart
);
254 ok(!cmp(mem
, memsrc
, size
), "%s: incorrecly unmarshaled\n", msgpfx
);
255 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p len %ld\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
, wiredatalen
);
256 ok(StubMsg
.MemorySize
== 0, "%s: memorysize %d\n", msgpfx
, StubMsg
.MemorySize
);
258 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
262 HeapFree(GetProcessHeap(), 0, mem_orig
);
263 HeapFree(GetProcessHeap(), 0, StubMsg
.BufferStart
);
266 static int deref_cmp(const void *s1
, const void *s2
, size_t num
)
268 return memcmp(*(const void *const *)s1
, *(const void *const *)s2
, num
);
272 static void test_simple_types(void)
274 unsigned char wiredata
[16];
276 unsigned char *ch_ptr
;
284 static const unsigned char fmtstr_up_char
[] =
286 0x12, 0x8, /* FC_UP [simple_pointer] */
290 static const unsigned char fmtstr_up_byte
[] =
292 0x12, 0x8, /* FC_UP [simple_pointer] */
296 static const unsigned char fmtstr_up_small
[] =
298 0x12, 0x8, /* FC_UP [simple_pointer] */
302 static const unsigned char fmtstr_up_usmall
[] =
304 0x12, 0x8, /* FC_UP [simple_pointer] */
308 static const unsigned char fmtstr_rp_char
[] =
310 0x11, 0x8, /* FC_RP [simple_pointer] */
314 static const unsigned char fmtstr_rpup_char
[] =
316 0x11, 0x14, /* FC_RP [alloced_on_stack] */
317 NdrFcShort( 0x2 ), /* Offset= 2 (4) */
318 0x12, 0x8, /* FC_UP [simple_pointer] */
322 static const unsigned char fmtstr_rpup_char2
[] =
324 0x11, 0x04, /* FC_RP [alloced_on_stack] */
325 NdrFcShort( 0x2 ), /* Offset= 2 (4) */
326 0x12, 0x8, /* FC_UP [simple_pointer] */
331 static const unsigned char fmtstr_up_wchar
[] =
333 0x12, 0x8, /* FC_UP [simple_pointer] */
337 static const unsigned char fmtstr_up_short
[] =
339 0x12, 0x8, /* FC_UP [simple_pointer] */
343 static const unsigned char fmtstr_up_ushort
[] =
345 0x12, 0x8, /* FC_UP [simple_pointer] */
349 static const unsigned char fmtstr_up_enum16
[] =
351 0x12, 0x8, /* FC_UP [simple_pointer] */
355 static const unsigned char fmtstr_up_long
[] =
357 0x12, 0x8, /* FC_UP [simple_pointer] */
361 static const unsigned char fmtstr_up_ulong
[] =
363 0x12, 0x8, /* FC_UP [simple_pointer] */
367 static const unsigned char fmtstr_up_enum32
[] =
369 0x12, 0x8, /* FC_UP [simple_pointer] */
373 static const unsigned char fmtstr_up_errorstatus
[] =
375 0x12, 0x8, /* FC_UP [simple_pointer] */
376 0x10, /* FC_ERROR_STATUS_T */
380 static const unsigned char fmtstr_up_longlong
[] =
382 0x12, 0x8, /* FC_UP [simple_pointer] */
386 static const unsigned char fmtstr_up_float
[] =
388 0x12, 0x8, /* FC_UP [simple_pointer] */
392 static const unsigned char fmtstr_up_double
[] =
394 0x12, 0x8, /* FC_UP [simple_pointer] */
401 *(void**)wiredata
= ch_ptr
;
402 wiredata
[sizeof(void*)] = ch
;
404 test_pointer_marshal(fmtstr_up_char
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_char");
405 test_pointer_marshal(fmtstr_up_byte
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_byte");
406 test_pointer_marshal(fmtstr_up_small
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_small");
407 test_pointer_marshal(fmtstr_up_usmall
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "up_usmall");
409 test_pointer_marshal(fmtstr_rp_char
, ch_ptr
, 1, &ch
, 1, NULL
, 0, "rp_char");
411 test_pointer_marshal(fmtstr_rpup_char
, &ch_ptr
, 1, wiredata
, 5, deref_cmp
, 1, "rpup_char");
412 test_pointer_marshal(fmtstr_rpup_char2
, ch_ptr
, 1, wiredata
, 5, NULL
, 0, "rpup_char2");
415 *(void**)wiredata
= &s
;
416 *(unsigned short*)(wiredata
+ sizeof(void*)) = s
;
418 test_pointer_marshal(fmtstr_up_wchar
, &s
, 2, wiredata
, 6, NULL
, 0, "up_wchar");
419 test_pointer_marshal(fmtstr_up_short
, &s
, 2, wiredata
, 6, NULL
, 0, "up_short");
420 test_pointer_marshal(fmtstr_up_ushort
, &s
, 2, wiredata
, 6, NULL
, 0, "up_ushort");
423 *(void**)wiredata
= &i
;
424 test_pointer_marshal(fmtstr_up_enum16
, &i
, 2, wiredata
, 6, NULL
, 0, "up_enum16");
427 *(void**)wiredata
= &l
;
428 *(unsigned long*)(wiredata
+ sizeof(void*)) = l
;
430 test_pointer_marshal(fmtstr_up_long
, &l
, 4, wiredata
, 8, NULL
, 0, "up_long");
431 test_pointer_marshal(fmtstr_up_ulong
, &l
, 4, wiredata
, 8, NULL
, 0, "up_ulong");
432 test_pointer_marshal(fmtstr_up_enum32
, &l
, 4, wiredata
, 8, NULL
, 0, "up_emun32");
433 test_pointer_marshal(fmtstr_up_errorstatus
, &l
, 4, wiredata
, 8, NULL
, 0, "up_errorstatus");
435 ll
= ((ULONGLONG
)0xcafebabe) << 32 | 0xdeadbeef;
436 *(void**)wiredata
= &ll
;
437 *(void**)(wiredata
+ sizeof(void*)) = NULL
;
438 *(ULONGLONG
*)(wiredata
+ 2 * sizeof(void*)) = ll
;
439 test_pointer_marshal(fmtstr_up_longlong
, &ll
, 8, wiredata
, 16, NULL
, 0, "up_longlong");
442 *(void**)wiredata
= &f
;
443 *(float*)(wiredata
+ sizeof(void*)) = f
;
444 test_pointer_marshal(fmtstr_up_float
, &f
, 4, wiredata
, 8, NULL
, 0, "up_float");
447 *(void**)wiredata
= &d
;
448 *(void**)(wiredata
+ sizeof(void*)) = NULL
;
449 *(double*)(wiredata
+ 2 * sizeof(void*)) = d
;
450 test_pointer_marshal(fmtstr_up_double
, &d
, 8, wiredata
, 16, NULL
, 0, "up_double");
454 static void test_simple_struct_marshal(const unsigned char *formattypes
,
457 const void *wiredata
,
459 int(*cmp
)(const void*,const void*,size_t),
460 long num_additional_allocs
,
463 RPC_MESSAGE RpcMessage
;
464 MIDL_STUB_MESSAGE StubMsg
;
465 MIDL_STUB_DESC StubDesc
;
468 unsigned char *mem
, *mem_orig
;
470 my_alloc_called
= my_free_called
= 0;
474 StubDesc
= Object_StubDesc
;
475 StubDesc
.pFormatTypes
= formattypes
;
477 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &StubDesc
, 0);
479 StubMsg
.BufferLength
= 0;
480 NdrSimpleStructBufferSize( &StubMsg
, (unsigned char *)memsrc
, formattypes
);
481 ok(StubMsg
.BufferLength
>= wiredatalen
, "%s: length %d\n", msgpfx
, StubMsg
.BufferLength
);
482 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
483 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
484 ptr
= NdrSimpleStructMarshall( &StubMsg
, (unsigned char*)memsrc
, formattypes
);
485 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
486 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
487 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));
491 /* FIXME: Causes Wine to crash */
492 StubMsg
.Buffer
= StubMsg
.BufferStart
;
493 StubMsg
.MemorySize
= 0;
494 size
= NdrSimpleStructMemorySize( &StubMsg
, formattypes
);
495 ok(size
== StubMsg
.MemorySize
, "%s: size != MemorySize\n", msgpfx
);
496 ok(size
== srcsize
, "%s: mem size %u\n", msgpfx
, size
);
497 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
499 StubMsg
.Buffer
= StubMsg
.BufferStart
;
500 size
= NdrSimpleStructMemorySize( &StubMsg
, formattypes
);
502 ok(size
== StubMsg
.MemorySize
, "%s: size != MemorySize\n", msgpfx
);
504 ok(StubMsg
.MemorySize
== ((srcsize
+ 3) & ~3) + srcsize
, "%s: mem size %u\n", msgpfx
, size
);
505 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
508 /*** Unmarshalling first with must_alloc false ***/
510 StubMsg
.Buffer
= StubMsg
.BufferStart
;
511 StubMsg
.MemorySize
= 0;
512 mem_orig
= mem
= HeapAlloc(GetProcessHeap(), 0, srcsize
);
513 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
514 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
515 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== wiredatalen
, "%s: Buffer %p Start %p\n", msgpfx
, StubMsg
.Buffer
, StubMsg
.BufferStart
);
516 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
517 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
518 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
520 ok(StubMsg
.MemorySize
== 0, "%s: memorysize touched in unmarshal\n", msgpfx
);
522 /* if we're a server we still use the suppiled memory */
523 StubMsg
.Buffer
= StubMsg
.BufferStart
;
524 StubMsg
.IsClient
= 0;
525 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
526 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
527 ok(mem
== mem_orig
, "%s: mem has changed %p %p\n", msgpfx
, mem
, mem_orig
);
528 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
529 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
531 ok(StubMsg
.MemorySize
== 0, "%s: memorysize touched in unmarshal\n", msgpfx
);
533 /* ...unless we pass a NULL ptr, then the buffer is used.
534 Passing a NULL ptr while we're a client && !must_alloc
535 crashes on Windows, so we won't do that. */
538 StubMsg
.IsClient
= 0;
539 StubMsg
.Buffer
= StubMsg
.BufferStart
;
540 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 0 );
541 ok(ptr
== NULL
, "%s: ret %p\n", msgpfx
, ptr
);
542 ok(mem
== StubMsg
.BufferStart
, "%s: mem not equal buffer\n", msgpfx
);
543 ok(!cmp(mem
, memsrc
, srcsize
), "%s: incorrectly unmarshaled\n", msgpfx
);
544 ok(my_alloc_called
== num_additional_allocs
, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
546 ok(StubMsg
.MemorySize
== 0, "%s: memorysize touched in unmarshal\n", msgpfx
);
548 /*** now must_alloc is true ***/
550 /* with must_alloc set we always allocate new memory whether or not we're
551 a server and also when passing NULL */
553 StubMsg
.IsClient
= 1;
554 StubMsg
.Buffer
= StubMsg
.BufferStart
;
555 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
556 ok(ptr
== NULL
, "ret %p\n", ptr
);
557 ok(mem
!= mem_orig
, "mem not changed %p %p\n", mem
, mem_orig
);
558 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
559 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
561 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
564 StubMsg
.Buffer
= StubMsg
.BufferStart
;
565 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
566 ok(ptr
== NULL
, "ret %p\n", ptr
);
567 ok(mem
!= mem_orig
, "mem not changed %p %p\n", mem
, mem_orig
);
568 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
569 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
571 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
574 StubMsg
.Buffer
= StubMsg
.BufferStart
;
575 StubMsg
.IsClient
= 0;
576 StubMsg
.ReuseBuffer
= 1;
577 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
578 ok(ptr
== NULL
, "ret %p\n", ptr
);
579 ok(mem
!= mem_orig
, "mem not changed %p %p\n", mem
, mem_orig
);
580 ok(mem
!= StubMsg
.BufferStart
, "mem is buffer mem\n");
581 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
582 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
584 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
587 StubMsg
.Buffer
= StubMsg
.BufferStart
;
588 StubMsg
.IsClient
= 0;
589 StubMsg
.ReuseBuffer
= 1;
590 ptr
= NdrSimpleStructUnmarshall( &StubMsg
, &mem
, formattypes
, 1 );
591 ok(ptr
== NULL
, "ret %p\n", ptr
);
592 ok(mem
!= StubMsg
.BufferStart
, "mem is buffer mem\n");
593 ok(!cmp(mem
, memsrc
, srcsize
), "incorrectly unmarshaled\n");
594 ok(my_alloc_called
== num_additional_allocs
+ 1, "%s: my_alloc got called %d times\n", msgpfx
, my_alloc_called
);
596 ok(StubMsg
.MemorySize
== 0, "memorysize touched in unmarshal\n");
607 static int ps1_cmp(const void *s1
, const void *s2
, size_t num
)
609 const ps1_t
*p1
, *p2
;
617 if(p1
->pl1
&& p2
->pl1
)
619 if(*p1
->pl1
!= *p2
->pl1
)
622 else if(p1
->pl1
|| p1
->pl1
)
625 if(p1
->pc1
&& p2
->pc1
)
627 if(*p1
->pc1
!= *p2
->pc1
)
630 else if(p1
->pc1
|| p1
->pc1
)
636 static void test_simple_struct(void)
638 unsigned char wiredata
[28];
639 unsigned long wiredatalen
;
644 static const unsigned char fmtstr_simple_struct
[] =
646 0x12, 0x0, /* FC_UP */
647 NdrFcShort( 0x2 ), /* Offset=2 */
648 0x15, 0x3, /* FC_STRUCT [align 4] */
649 NdrFcShort( 0x18 ), /* [size 24] */
652 0x38, /* FC_ALIGNM4 */
655 0x39, /* FC_ALIGNM8 */
666 static const unsigned char fmtstr_pointer_struct
[] =
668 0x12, 0x0, /* FC_UP */
669 NdrFcShort( 0x2 ), /* Offset=2 */
670 0x16, 0x3, /* FC_PSTRUCT [align 4] */
671 NdrFcShort( 0xc ), /* [size 12] */
674 0x46, /* FC_NO_REPEAT */
676 NdrFcShort( 0x4 ), /* 4 */
677 NdrFcShort( 0x4 ), /* 4 */
678 0x13, 0x8, /* FC_OP [simple_pointer] */
681 0x46, /* FC_NO_REPEAT */
683 NdrFcShort( 0x8 ), /* 8 */
684 NdrFcShort( 0x8 ), /* 8 */
685 0x13, 0x8, /* FC_OP [simple_pointer] */
702 s1
.ll
= ((LONGLONG
) 0xbadefeed << 32) | 0x2468ace0;
705 memcpy(wiredata
, &s1
, wiredatalen
);
706 test_simple_struct_marshal(fmtstr_simple_struct
+ 4, &s1
, 24, wiredata
, 24, NULL
, 0, "struct");
708 *(void**)wiredata
= &s1
;
709 memcpy(wiredata
+ 4, &s1
, wiredatalen
);
712 /* one of the unmarshallings crashes Wine */
713 test_pointer_marshal(fmtstr_simple_struct
, &s1
, 24, wiredata
, 28, NULL
, 0, "struct");
722 memcpy(wiredata
+ 4, &ps1
, 12);
723 memcpy(wiredata
+ 16, &l
, 4);
724 memcpy(wiredata
+ 20, &c
, 1);
726 test_simple_struct_marshal(fmtstr_pointer_struct
+ 4, &ps1
, 17, wiredata
+ 4, 17, ps1_cmp
, 2, "pointer_struct");
727 *(void**)wiredata
= &ps1
;
730 /* one of the unmarshallings crashes Wine */
731 test_pointer_marshal(fmtstr_pointer_struct
, &ps1
, 17, wiredata
, 21, ps1_cmp
, 2, "pointer_struct");
735 static void test_complex_struct(void)
737 RPC_MESSAGE RpcMessage
;
738 MIDL_STUB_MESSAGE StubMsg
;
739 MIDL_STUB_DESC StubDesc
;
746 static const unsigned char fmtstr_funcdesc
[] =
748 /* 0 */ 0x11, 0x14, /* FC_RP [alloced_on_stack] */
749 /* 2 */ NdrFcShort( 0x2 ), /* Offset= 2 (4) */
750 /* 4 */ 0x13, 0x0, /* FC_OP */
751 /* 6 */ NdrFcShort( 0xaa ), /* Offset= 170 (176) */
753 /** TYPEDESC union **/
754 /* 8 */ 0x2b, /* FC_NON_ENCAPSULATED_UNION */
756 /* 10 */ 0x7, /* Corr desc: FC_USHORT */
758 /* 12 */ NdrFcShort( 0x4 ), /* 4 */
759 /* 14 */ NdrFcShort( 0x2 ), /* Offset= 2 (16) */
760 /* 16 */ NdrFcShort( 0x4 ), /* 4 */
761 /* 18 */ NdrFcShort( 0x4 ), /* 4 */
762 /* 20 */ NdrFcLong( 0x1a ), /* 26 */
763 /* 24 */ NdrFcShort( 0x16 ), /* Offset= 22 (46) */
764 /* 26 */ NdrFcLong( 0x1b ), /* 27 */
765 /* 30 */ NdrFcShort( 0x10 ), /* Offset= 16 (46) */
766 /* 32 */ NdrFcLong( 0x1c ), /* 28 */
767 /* 36 */ NdrFcShort( 0xe ), /* Offset= 14 (50) */
768 /* 38 */ NdrFcLong( 0x1d ), /* 29 */
769 /* 42 */ NdrFcShort( 0x8008 ), /* Simple arm type: FC_LONG */
770 /* 44 */ NdrFcShort( 0x0 ), /* Offset= 0 */
771 /* 46 */ 0x13, 0x0, /* FC_OP */
772 /* 48 */ NdrFcShort( 0x24 ), /* Offset= 36 (84) */
773 /* 50 */ 0x13, 0x0, /* FC_OP */
774 /* 52 */ NdrFcShort( 0x10 ), /* Offset= 16 (68) */
776 /** ARRAYDESC carray **/
777 /* 54 */ 0x1b, /* FC_CARRAY */
779 /* 56 */ NdrFcShort( 0x8 ), /* 8 */
780 /* 58 */ 0x7, /* Corr desc: FC_USHORT */
782 /* 60 */ NdrFcShort( 0xfffc ), /* -4 */
783 /* 62 */ 0x4c, /* FC_EMBEDDED_COMPLEX */
785 /* 64 */ NdrFcShort( 0x92 ), /* Offset= 146 (210) */
786 /* 66 */ 0x5c, /* FC_PAD */
790 /* 68 */ 0x1a, /* FC_BOGUS_STRUCT */
792 /* 70 */ NdrFcShort( 0x4 ), /* 4 */
793 /* 72 */ NdrFcShort( 0xffffffee ), /* Offset= -18 (54) */
794 /* 74 */ NdrFcShort( 0x0 ), /* Offset= 0 */
795 /* 76 */ 0x4c, /* FC_EMBEDDED_COMPLEX */
797 /* 78 */ NdrFcShort( 0x6 ), /* Offset= 6 (84) */
798 /* 80 */ 0x6, /* FC_SHORT */
799 0x3e, /* FC_STRUCTPAD2 */
800 /* 82 */ 0x5c, /* FC_PAD */
804 /* 84 */ 0x1a, /* FC_BOGUS_STRUCT */
806 /* 86 */ NdrFcShort( 0x8 ), /* 8 */
807 /* 88 */ NdrFcShort( 0x0 ), /* 0 */
808 /* 90 */ NdrFcShort( 0x0 ), /* Offset= 0 */
809 /* 92 */ 0x4c, /* FC_EMBEDDED_COMPLEX */
811 /* 94 */ NdrFcShort( 0xffffffaa ), /* Offset= -86 (8) */
812 /* 96 */ 0x6, /* FC_SHORT */
813 0x3e, /* FC_STRUCTPAD2 */
814 /* 98 */ 0x5c, /* FC_PAD */
819 /* 100 */ 0x1a, /* FC_BOGUS_STRUCT */
821 /* 102 */ NdrFcShort( 0x18 ), /* 24 */
822 /* 104 */ NdrFcShort( 0x0 ), /* 0 */
823 /* 106 */ NdrFcShort( 0x0 ), /* Offset= 0 */
824 /* 108 */ 0x8, /* FC_LONG */
825 0x4c, /* FC_EMBEDDED_COMPLEX */
826 /* 110 */ 0x4, /* 4 */
827 NdrFcShort( 0xffffff01 ), /* Offset= -255 (1110) */ /* FIXME!! */
832 /* 114 */ 0x1a, /* FC_BOGUS_STRUCT */
834 /* 116 */ NdrFcShort( 0x8 ), /* 8 */
835 /* 118 */ NdrFcShort( 0x0 ), /* 0 */
836 /* 120 */ NdrFcShort( 0x6 ), /* Offset= 6 (126) */
837 /* 122 */ 0x36, /* FC_POINTER */
839 /* 124 */ 0x3e, /* FC_STRUCTPAD2 */
842 0x13, 0x0, /* FC_OP */
843 /* 128 */ NdrFcShort( 0xffffffe4 ), /* Offset= -28 (100) */
847 0x1a, /* FC_BOGUS_STRUCT */
849 /* 132 */ NdrFcShort( 0x10 ), /* 16 */
850 /* 134 */ NdrFcShort( 0x0 ), /* 0 */
851 /* 136 */ NdrFcShort( 0x0 ), /* 0 */
852 /* 138 */ 0x4c, /* FC_EMBEDDED_COMPLEX */
854 /* 140 */ NdrFcShort( 0xffffffc8 ), /* Offset= -56 (84) */
855 /* 142 */ 0x4c, /* FC_EMBEDDED_COMPLEX */
857 /* 144 */ NdrFcShort( 0xffffffe2 ), /* Offset= -30 (114) */
858 /* 146 */ 0x5c, /* FC_PAD */
863 0x1b, /* FC_CARRAY */
865 /* 150 */ NdrFcShort( 0x4 ), /* 4 */
866 /* 152 */ 0x16, /* Corr desc: field pointer, FC_SHORT */
868 /* 154 */ NdrFcShort( 0x1e ), /* 30 */
869 /* 156 */ 0x8, /* FC_LONG */
873 0x21, /* FC_BOGUS_ARRAY */
875 /* 160 */ NdrFcShort( 0x0 ), /* 0 */
876 /* 162 */ 0x16, /* Corr desc: field pointer, FC_SHORT */
878 /* 164 */ NdrFcShort( 0x18 ), /* 24 */
879 /* 166 */ NdrFcLong( 0xffffffff ), /* -1 */
880 /* 170 */ 0x4c, /* FC_EMBEDDED_COMPLEX */
882 /* 172 */ NdrFcShort( 0xffffffd6 ), /* Offset= -42 (130) */
883 /* 174 */ 0x5c, /* FC_PAD */
886 /* 176 */ 0x1a, /* FC_BOGUS_STRUCT */
888 /* 178 */ NdrFcShort( 0x34 ), /* 52 */
889 /* 180 */ NdrFcShort( 0x0 ), /* 0 */
890 /* 182 */ NdrFcShort( 0x14 ), /* Offset= 20 (202) */
891 /* 184 */ 0x8, /* FC_LONG */
892 0x36, /* FC_POINTER */
893 /* 186 */ 0x36, /* FC_POINTER */
895 /* 188 */ 0xe, /* FC_ENUM32 */
897 /* 190 */ 0x6, /* FC_SHORT */
899 /* 192 */ 0x6, /* FC_SHORT */
901 /* 194 */ 0x4c, /* FC_EMBEDDED_COMPLEX */
903 /* 196 */ NdrFcShort( 0xffffffbe ), /* Offset= -66 (130) */
904 /* 198 */ 0x6, /* FC_SHORT */
905 0x3e, /* FC_STRUCTPAD2 */
906 /* 200 */ 0x5c, /* FC_PAD */
909 0x13, 0x0, /* FC_OP */
910 /* 204 */ NdrFcShort( 0xffffffc8 ), /* Offset= -56 (148) */
912 0x13, 0x0, /* FC_OP */
913 /* 208 */ NdrFcShort( 0xffffffce ), /* Offset= -50 (158) */
915 /** SAFEARRAYBOUND **/
917 0x15, /* FC_STRUCT */
919 /* 212 */ NdrFcShort( 0x8 ), /* 8 */
920 /* 214 */ 0x8, /* FC_LONG */
922 /* 216 */ 0x5c, /* FC_PAD */
926 StubDesc
= Object_StubDesc
;
927 StubDesc
.pFormatTypes
= fmtstr_funcdesc
;
930 memset(&fd
, 0, sizeof(fd
));
932 fd
.memid
= 0xcafebabe;
934 fd
.lprgelemdescParam
= params
;
935 params
[0].tdesc
.vt
= VT_PTR
;
936 U(params
[0].tdesc
).lptdesc
= &td
[0];
937 U(params
[0].tdesc
).lptdesc
->vt
= VT_SAFEARRAY
;
938 U(*U(params
[0].tdesc
).lptdesc
).lptdesc
= &td
[1];
939 U(*U(params
[0].tdesc
).lptdesc
).lptdesc
->vt
= VT_R8
;
940 U(params
[0]).paramdesc
.pparamdescex
= NULL
;
941 U(params
[0]).paramdesc
.wParamFlags
= 0xbeef;
943 params
[1].tdesc
.vt
= VT_I4
;
944 /* U(params[1].tdesc).vt = VT_PTR;
945 U(params[1].tdesc).lptdesc = &td[2];
946 U(params[1].tdesc).lptdesc->vt = VT_SAFEARRAY;
947 U(*U(params[1].tdesc).lptdesc).lptdesc = &td[3];
948 U(*U(params[1].tdesc).lptdesc).lptdesc->vt = VT_R8;*/
949 U(params
[1]).paramdesc
.pparamdescex
= NULL
;
950 U(params
[1]).paramdesc
.wParamFlags
= 0xdead;
958 fd
.elemdescFunc
.tdesc
.vt
= VT_R8
;
959 U(fd
.elemdescFunc
).paramdesc
.pparamdescex
= NULL
;
960 U(fd
.elemdescFunc
).paramdesc
.wParamFlags
= 0xcafe;
963 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &StubDesc
, 0);
965 StubMsg
.BufferLength
= 0;
966 StubMsg
.PointerLength
= 0;
968 NdrComplexStructBufferSize( &StubMsg
, (unsigned char *)memsrc
, fmtstr_funcdesc
+ 176 );
969 ok(StubMsg
.BufferLength
>= 96, "buffer size %d\n", StubMsg
.BufferLength
);
971 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, StubMsg
.BufferLength
);
972 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
974 ptr
= NdrComplexStructMarshall( &StubMsg
, memsrc
, fmtstr_funcdesc
+ 176 );
976 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== 96, "marshaled length %d\n", StubMsg
.Buffer
- StubMsg
.BufferStart
);
978 /* Compare upto the first embedded union (elemdescFunc) */
979 ok(!memcmp(StubMsg
.BufferStart
, &fd
, 32), "top level differ\n");
981 ok(!memcmp(StubMsg
.BufferStart
+ 32, &fd
.elemdescFunc
.tdesc
.vt
, sizeof(short)), "discrimants differ\n");
982 /* now the vt itself */
983 ok(!memcmp(StubMsg
.BufferStart
+ 34, &fd
.elemdescFunc
.tdesc
.vt
, sizeof(short)), "vts differ\n");
985 ok(!memcmp(StubMsg
.BufferStart
+ 36, &U(fd
.elemdescFunc
).paramdesc
, sizeof(PARAMDESC
)), "paramdesc differ\n");
986 /* param array discrim */
987 ok(!memcmp(StubMsg
.BufferStart
+ 44, &fd
.cParams
, sizeof(short)), "param array discrim differs\n");
989 ok(!memcmp(StubMsg
.BufferStart
+ 48, ¶ms
[0].tdesc
.vt
, sizeof(short)), "param[0] first vt differ\n");
990 ok(!memcmp(StubMsg
.BufferStart
+ 52, ¶ms
[0].tdesc
, 6), "param[0] first tdesc differ\n");
991 ok(!memcmp(StubMsg
.BufferStart
+ 60, &U(params
[0]).paramdesc
, 6), "param[0] paramdesc differ\n");
993 ok(!memcmp(StubMsg
.BufferStart
+ 68, ¶ms
[1].tdesc
.vt
, sizeof(short)), "param[1] first vt differ\n");
994 ok(!memcmp(StubMsg
.BufferStart
+ 70, ¶ms
[1].tdesc
.vt
, sizeof(short)), "param[1] first tdesc differ\n");
995 ok(!memcmp(StubMsg
.BufferStart
+ 72, &U(params
[1]).paramdesc
, 6), "param[1] paramdesc differ\n");
997 ok(!memcmp(StubMsg
.BufferStart
+ 80, &U(params
[0].tdesc
).lptdesc
->vt
, sizeof(short)), "param[0] 2nd vt differ\n");
998 ok(!memcmp(StubMsg
.BufferStart
+ 84, U(params
[0].tdesc
).lptdesc
, 6), "param[0] 2nd tdesc differ\n");
1000 ok(!memcmp(StubMsg
.BufferStart
+ 92, &U(*U(params
[0].tdesc
).lptdesc
).lptdesc
->vt
, sizeof(short)), "param[0] 3rd vt differ\n");
1001 ok(!memcmp(StubMsg
.BufferStart
+ 94, &U(*U(params
[0].tdesc
).lptdesc
).lptdesc
->vt
, 2), "param[0] 3rd tdesc differ\n");
1003 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1004 StubMsg
.MemorySize
= 0;
1006 dst
= HeapAlloc(GetProcessHeap(), 0, 1000);
1007 NdrComplexStructUnmarshall( &StubMsg
, (void*)&dst
, fmtstr_funcdesc
+ 176, 1);
1008 ok(dst
->cParams
== fd
.cParams
, "params not right\n");
1009 ok(U(*U(dst
->lprgelemdescParam
[0].tdesc
).lptdesc
).lptdesc
->vt
== U(*U(params
[0].tdesc
).lptdesc
).lptdesc
->vt
, "param[0] tdesc differ\n");
1012 static void test_fullpointer_xlat(void)
1014 PFULL_PTR_XLAT_TABLES pXlatTables
;
1019 pXlatTables
= NdrFullPointerXlatInit(2, XLAT_CLIENT
);
1021 /* "marshaling" phase */
1023 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
1024 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1025 ok(RefId
== 0x1, "RefId should be 0x1 instead of 0x%x\n", RefId
);
1027 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 0, &RefId
);
1028 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1029 ok(RefId
== 0x1, "RefId should be 0x1 instead of 0x%x\n", RefId
);
1031 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebabe, 0, &RefId
);
1032 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1033 ok(RefId
== 0x2, "RefId should be 0x2 instead of 0x%x\n", RefId
);
1035 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 0, &RefId
);
1036 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1037 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1039 ret
= NdrFullPointerQueryPointer(pXlatTables
, NULL
, 0, &RefId
);
1040 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1041 ok(RefId
== 0, "RefId should be 0 instead of 0x%x\n", RefId
);
1043 /* "unmarshaling" phase */
1045 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 0, &Pointer
);
1046 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1047 ok(Pointer
== (void *)0xcafebabe, "Pointer should be 0xcafebabe instead of %p\n", Pointer
);
1049 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x4, 0, &Pointer
);
1050 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1051 ok(Pointer
== NULL
, "Pointer should be NULL instead of %p\n", Pointer
);
1053 NdrFullPointerInsertRefId(pXlatTables
, 0x4, (void *)0xdeadbabe);
1055 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x4, 1, &Pointer
);
1056 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1057 ok(Pointer
== (void *)0xdeadbabe, "Pointer should be (void *)0xdeadbabe instead of %p\n", Pointer
);
1059 NdrFullPointerXlatFree(pXlatTables
);
1061 pXlatTables
= NdrFullPointerXlatInit(2, XLAT_SERVER
);
1063 /* "unmarshaling" phase */
1065 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 1, &Pointer
);
1066 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1067 ok(Pointer
== NULL
, "Pointer should be NULL instead of %p\n", Pointer
);
1069 NdrFullPointerInsertRefId(pXlatTables
, 0x2, (void *)0xcafebabe);
1071 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 0, &Pointer
);
1072 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1073 ok(Pointer
== (void *)0xcafebabe, "Pointer should be (void *)0xcafebabe instead of %p\n", Pointer
);
1075 ret
= NdrFullPointerQueryRefId(pXlatTables
, 0x2, 1, &Pointer
);
1076 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1077 ok(Pointer
== (void *)0xcafebabe, "Pointer should be (void *)0xcafebabe instead of %p\n", Pointer
);
1079 /* "marshaling" phase */
1081 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
1082 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1083 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1085 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
1086 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1087 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1089 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 0, &RefId
);
1090 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1091 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1093 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebabe, 0, &RefId
);
1094 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1095 ok(RefId
== 0x2, "RefId should be 0x2 instead of 0x%x\n", RefId
);
1097 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 0, &RefId
);
1098 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1099 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
1101 /* "freeing" phase */
1103 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xcafebeef);
1104 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1106 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 0x20, &RefId
);
1107 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1108 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1110 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xcafebeef, 1, &RefId
);
1111 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1112 ok(RefId
== 0x3, "RefId should be 0x3 instead of 0x%x\n", RefId
);
1114 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xcafebabe);
1115 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1117 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xdeadbeef);
1118 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1120 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 0x20, &RefId
);
1121 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1122 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
1124 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 1, &RefId
);
1125 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1126 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
1128 ret
= NdrFullPointerQueryPointer(pXlatTables
, (void *)0xdeadbeef, 1, &RefId
);
1129 ok(ret
== 1, "ret should be 1 instead of 0x%x\n", ret
);
1130 ok(RefId
== 0x4, "RefId should be 0x4 instead of 0x%x\n", RefId
);
1132 ret
= NdrFullPointerFree(pXlatTables
, (void *)0xdeadbeef);
1133 ok(ret
== 0, "ret should be 0 instead of 0x%x\n", ret
);
1135 NdrFullPointerXlatFree(pXlatTables
);
1138 static void test_client_init(void)
1140 MIDL_STUB_MESSAGE stubMsg
;
1143 memset(&stubMsg
, 0xcc, sizeof(stubMsg
));
1145 NdrClientInitializeNew(&rpcMsg
, &stubMsg
, &Object_StubDesc
, 1);
1147 #define TEST_ZERO(field, fmt) ok(stubMsg.field == 0, #field " should have be set to zero instead of " fmt "\n", stubMsg.field)
1148 #define TEST_POINTER_UNSET(field) ok(stubMsg.field == (void *)0xcccccccc, #field " should have be unset instead of %p\n", stubMsg.field)
1149 #define TEST_ULONG_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have be unset instead of 0x%x\n", stubMsg.field)
1150 #define TEST_ULONG_PTR_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have be unset instead of 0x%lx\n", stubMsg.field)
1152 ok(stubMsg
.RpcMsg
== &rpcMsg
, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg
, stubMsg
.RpcMsg
);
1153 TEST_POINTER_UNSET(Buffer
);
1154 TEST_ZERO(BufferStart
, "%p");
1155 TEST_ZERO(BufferEnd
, "%p");
1156 TEST_POINTER_UNSET(BufferMark
);
1157 TEST_ZERO(BufferLength
, "%d");
1158 TEST_ULONG_UNSET(MemorySize
);
1159 TEST_POINTER_UNSET(Memory
);
1160 ok(stubMsg
.IsClient
== 1, "stubMsg.IsClient should have been 1 instead of %u\n", stubMsg
.IsClient
);
1161 TEST_ZERO(ReuseBuffer
, "%d");
1162 TEST_ZERO(pAllocAllNodesContext
, "%p");
1163 TEST_ZERO(pPointerQueueState
, "%p");
1164 TEST_ZERO(IgnoreEmbeddedPointers
, "%d");
1165 TEST_ZERO(PointerBufferMark
, "%p");
1166 TEST_ZERO(fBufferValid
, "%d");
1167 TEST_ZERO(uFlags
, "%d");
1168 /* FIXME: UniquePtrCount */
1169 TEST_ULONG_PTR_UNSET(MaxCount
);
1170 TEST_ULONG_UNSET(Offset
);
1171 TEST_ULONG_UNSET(ActualCount
);
1172 ok(stubMsg
.pfnAllocate
== my_alloc
, "stubMsg.pfnAllocate should have been %p instead of %p\n", my_alloc
, stubMsg
.pfnAllocate
);
1173 ok(stubMsg
.pfnFree
== my_free
, "stubMsg.pfnFree should have been %p instead of %p\n", my_free
, stubMsg
.pfnFree
);
1174 TEST_ZERO(StackTop
, "%p");
1175 TEST_POINTER_UNSET(pPresentedType
);
1176 TEST_POINTER_UNSET(pTransmitType
);
1177 TEST_POINTER_UNSET(SavedHandle
);
1178 ok(stubMsg
.StubDesc
== &Object_StubDesc
, "stubMsg.StubDesc should have been %p instead of %p\n", &Object_StubDesc
, stubMsg
.StubDesc
);
1179 TEST_POINTER_UNSET(FullPtrXlatTables
);
1180 TEST_ZERO(FullPtrRefId
, "%d");
1181 TEST_ZERO(PointerLength
, "%d");
1182 TEST_ZERO(fInDontFree
, "%d");
1183 TEST_ZERO(fDontCallFreeInst
, "%d");
1184 TEST_ZERO(fInOnlyParam
, "%d");
1185 TEST_ZERO(fHasReturn
, "%d");
1186 TEST_ZERO(fHasExtensions
, "%d");
1187 TEST_ZERO(fHasNewCorrDesc
, "%d");
1188 TEST_ZERO(fUnused
, "%d");
1189 ok(stubMsg
.fUnused2
== 0xffffcccc, "stubMsg.fUnused2 should have been 0xcccc instead of 0x%x\n", stubMsg
.fUnused2
);
1190 ok(stubMsg
.dwDestContext
== MSHCTX_DIFFERENTMACHINE
, "stubMsg.dwDestContext should have been MSHCTX_DIFFERENTMACHINE instead of %d\n", stubMsg
.dwDestContext
);
1191 TEST_ZERO(pvDestContext
, "%p");
1192 TEST_POINTER_UNSET(SavedContextHandles
);
1193 TEST_ULONG_UNSET(ParamNumber
);
1194 TEST_ZERO(pRpcChannelBuffer
, "%p");
1195 TEST_ZERO(pArrayInfo
, "%p");
1196 TEST_POINTER_UNSET(SizePtrCountArray
);
1197 TEST_POINTER_UNSET(SizePtrOffsetArray
);
1198 TEST_POINTER_UNSET(SizePtrLengthArray
);
1199 TEST_POINTER_UNSET(pArgQueue
);
1200 TEST_ZERO(dwStubPhase
, "%d");
1201 /* FIXME: where does this value come from? */
1202 trace("LowStackMark is %p\n", stubMsg
.LowStackMark
);
1203 TEST_ZERO(pAsyncMsg
, "%p");
1204 TEST_ZERO(pCorrInfo
, "%p");
1205 TEST_ZERO(pCorrMemory
, "%p");
1206 TEST_ZERO(pMemoryList
, "%p");
1207 TEST_POINTER_UNSET(pCSInfo
);
1208 TEST_POINTER_UNSET(ConformanceMark
);
1209 TEST_POINTER_UNSET(VarianceMark
);
1210 ok(stubMsg
.Unused
== 0xcccccccc, "Unused should have be unset instead of 0x%x\n", stubMsg
.Unused
);
1211 TEST_POINTER_UNSET(pContext
);
1212 TEST_POINTER_UNSET(ContextHandleHash
);
1213 TEST_POINTER_UNSET(pUserMarshalList
);
1214 TEST_ULONG_UNSET(Reserved51_3
);
1215 TEST_ULONG_UNSET(Reserved51_4
);
1216 TEST_ULONG_UNSET(Reserved51_5
);
1217 #undef TEST_ULONG_UNSET
1218 #undef TEST_POINTER_UNSET
1223 static void test_ndr_allocate(void)
1225 RPC_MESSAGE RpcMessage
;
1226 MIDL_STUB_MESSAGE StubMsg
;
1227 MIDL_STUB_DESC StubDesc
;
1229 struct tag_mem_list_t
1233 struct tag_mem_list_t
*next
;
1235 const DWORD magic_MEML
= 'M' << 24 | 'E' << 16 | 'M' << 8 | 'L';
1237 StubDesc
= Object_StubDesc
;
1238 NdrClientInitializeNew(&RpcMessage
, &StubMsg
, &StubDesc
, 0);
1240 ok(StubMsg
.pMemoryList
== NULL
, "memlist %p\n", StubMsg
.pMemoryList
);
1241 my_alloc_called
= my_free_called
= 0;
1242 p1
= NdrAllocate(&StubMsg
, 10);
1243 p2
= NdrAllocate(&StubMsg
, 20);
1244 ok(my_alloc_called
== 2, "alloc called %d\n", my_alloc_called
);
1245 mem_list
= StubMsg
.pMemoryList
;
1247 ok(mem_list
!= NULL
, "mem_list NULL\n");
1251 ok(mem_list
->magic
== magic_MEML
, "magic %08x\n", mem_list
->magic
);
1252 ok(mem_list
->ptr
== p2
, "ptr != p2\n");
1253 ok(mem_list
->next
!= NULL
, "next NULL\n");
1254 mem_list
= mem_list
->next
;
1257 ok(mem_list
->magic
== magic_MEML
, "magic %08x\n", mem_list
->magic
);
1258 ok(mem_list
->ptr
== p1
, "ptr != p2\n");
1259 ok(mem_list
->next
== NULL
, "next %p\n", mem_list
->next
);
1262 /* NdrFree isn't exported so we can't test free'ing */
1265 static void test_conformant_array(void)
1267 RPC_MESSAGE RpcMessage
;
1268 MIDL_STUB_MESSAGE StubMsg
;
1269 MIDL_STUB_DESC StubDesc
;
1271 unsigned char *mem
, *mem_orig
;
1272 unsigned char memsrc
[20];
1274 static const unsigned char fmtstr_conf_array
[] =
1276 0x1b, /* FC_CARRAY */
1278 NdrFcShort( 0x1 ), /* elem size */
1279 0x40, /* Corr desc: const */
1281 NdrFcShort(0x10), /* const = 0x10 */
1286 StubDesc
= Object_StubDesc
;
1287 StubDesc
.pFormatTypes
= fmtstr_conf_array
;
1289 NdrClientInitializeNew(
1295 StubMsg
.BufferLength
= 0;
1296 NdrConformantArrayBufferSize( &StubMsg
,
1298 fmtstr_conf_array
);
1299 ok(StubMsg
.BufferLength
>= 20, "length %d\n", StubMsg
.BufferLength
);
1301 /*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
1302 StubMsg
.RpcMsg
->Buffer
= StubMsg
.BufferStart
= StubMsg
.Buffer
= HeapAlloc(GetProcessHeap(), 0, StubMsg
.BufferLength
);
1303 StubMsg
.BufferEnd
= StubMsg
.BufferStart
+ StubMsg
.BufferLength
;
1305 ptr
= NdrConformantArrayMarshall( &StubMsg
, memsrc
, fmtstr_conf_array
);
1306 ok(ptr
== NULL
, "ret %p\n", ptr
);
1307 ok(StubMsg
.Buffer
- StubMsg
.BufferStart
== 20, "Buffer %p Start %p len %d\n", StubMsg
.Buffer
, StubMsg
.BufferStart
, 20);
1308 ok(!memcmp(StubMsg
.BufferStart
+ 4, memsrc
, 16), "incorrectly marshaled\n");
1310 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1311 StubMsg
.MemorySize
= 0;
1315 my_alloc_called
= 0;
1316 /* passing mem == NULL with must_alloc == 0 crashes under Windows */
1317 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1318 ok(mem
!= NULL
, "mem not alloced\n");
1319 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1320 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1322 my_alloc_called
= 0;
1323 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1325 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 0);
1326 ok(mem
== mem_orig
, "mem alloced\n");
1327 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1328 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1330 my_alloc_called
= 0;
1331 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1332 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1333 ok(mem
!= mem_orig
, "mem not alloced\n");
1334 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1335 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1338 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1339 NdrConformantArrayFree( &StubMsg
, mem
, fmtstr_conf_array
);
1340 ok(my_free_called
== 0, "free called %d\n", my_free_called
);
1341 StubMsg
.pfnFree(mem
);
1344 my_alloc_called
= 0;
1345 StubMsg
.IsClient
= 0;
1347 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1348 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 0);
1350 ok(mem
== StubMsg
.BufferStart
+ 4, "mem not pointing at buffer\n");
1351 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1353 my_alloc_called
= 0;
1355 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1356 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1357 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1358 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1359 StubMsg
.pfnFree(mem
);
1361 my_alloc_called
= 0;
1363 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1364 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 0);
1365 ok(mem
== mem_orig
, "mem alloced\n");
1366 ok(my_alloc_called
== 0, "alloc called %d\n", my_alloc_called
);
1368 my_alloc_called
= 0;
1370 StubMsg
.Buffer
= StubMsg
.BufferStart
;
1371 NdrConformantArrayUnmarshall( &StubMsg
, &mem
, fmtstr_conf_array
, 1);
1372 ok(mem
!= StubMsg
.BufferStart
+ 4, "mem pointing at buffer\n");
1373 ok(my_alloc_called
== 1, "alloc called %d\n", my_alloc_called
);
1374 StubMsg
.pfnFree(mem
);
1375 StubMsg
.pfnFree(mem_orig
);
1377 HeapFree(GetProcessHeap(), 0, StubMsg
.RpcMsg
->Buffer
);
1380 START_TEST( ndr_marshall
)
1382 test_ndr_simple_type();
1383 test_simple_types();
1384 test_simple_struct();
1385 test_complex_struct();
1386 test_fullpointer_xlat();
1388 test_ndr_allocate();
1389 test_conformant_array();