2006-05-17 16:28:38 +02:00
/*
* Unit test suite for ndr marshalling functions
*
* Copyright 2006 Huw Davies
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ; either
* version 2.1 of the License , or ( at your option ) any later version .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library ; if not , write to the Free Software
2006-05-18 14:49:52 +02:00
* Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 , USA
2006-05-17 16:28:38 +02:00
*/
# include <stdarg.h>
2012-05-05 16:11:04 +02:00
# define _WIN32_WINNT 0x0500
2007-01-10 16:28:20 +01:00
# define NTDDI_WIN2K 0x05000000
# define NTDDI_VERSION NTDDI_WIN2K /* for some MIDL_STUB_MESSAGE fields */
2006-05-17 16:28:38 +02:00
# include "wine/test.h"
# include <windef.h>
# include <winbase.h>
# include <winnt.h>
# include <winerror.h>
# include "rpc.h"
# include "rpcdce.h"
# include "rpcproxy.h"
static int my_alloc_called ;
static int my_free_called ;
2009-01-30 14:46:17 +01:00
static void * CALLBACK my_alloc ( SIZE_T size )
2006-05-17 16:28:38 +02:00
{
my_alloc_called + + ;
return NdrOleAllocate ( size ) ;
}
2006-12-10 16:51:26 +01:00
static void CALLBACK my_free ( void * ptr )
2006-05-17 16:28:38 +02:00
{
my_free_called + + ;
2006-09-29 13:05:24 +02:00
NdrOleFree ( ptr ) ;
2006-05-17 16:28:38 +02:00
}
static const MIDL_STUB_DESC Object_StubDesc =
{
NULL ,
my_alloc ,
my_free ,
{ 0 } ,
0 ,
0 ,
0 ,
0 ,
NULL , /* format string, filled in by tests */
1 , /* -error bounds_check flag */
0x20000 , /* Ndr library version */
0 ,
0x50100a4 , /* MIDL Version 5.1.164 */
0 ,
NULL ,
0 , /* notify & notify_flag routine table */
1 , /* Flags */
0 , /* Reserved3 */
0 , /* Reserved4 */
0 /* Reserved5 */
} ;
2008-01-04 18:37:31 +01:00
static RPC_DISPATCH_FUNCTION IFoo_table [ ] =
{
0
} ;
static RPC_DISPATCH_TABLE IFoo_v0_0_DispatchTable =
{
0 ,
IFoo_table
} ;
static const RPC_SERVER_INTERFACE IFoo___RpcServerInterface =
{
sizeof ( RPC_SERVER_INTERFACE ) ,
{ { 0x00000000 , 0x0000 , 0x0000 , { 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x12 , 0x34 } } , { 0 , 0 } } ,
{ { 0x8a885d04 , 0x1ceb , 0x11c9 , { 0x9f , 0xe8 , 0x08 , 0x00 , 0x2b , 0x10 , 0x48 , 0x60 } } , { 2 , 0 } } ,
& IFoo_v0_0_DispatchTable ,
0 ,
0 ,
0 ,
0 ,
0 ,
} ;
static RPC_IF_HANDLE IFoo_v0_0_s_ifspec = ( RPC_IF_HANDLE ) & IFoo___RpcServerInterface ;
2008-06-14 17:29:35 +02:00
static BOOL use_pointer_ids = FALSE ;
static void determine_pointer_marshalling_style ( void )
{
RPC_MESSAGE RpcMessage ;
MIDL_STUB_MESSAGE StubMsg ;
MIDL_STUB_DESC StubDesc ;
char ch = 0xde ;
static const unsigned char fmtstr_up_char [ ] =
{
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0x2 , /* FC_CHAR */
0x5c , /* FC_PAD */
} ;
StubDesc = Object_StubDesc ;
StubDesc . pFormatTypes = NULL ;
NdrClientInitializeNew (
& RpcMessage ,
& StubMsg ,
& StubDesc ,
0 ) ;
StubMsg . BufferLength = 8 ;
StubMsg . RpcMsg - > Buffer = StubMsg . BufferStart = StubMsg . Buffer = HeapAlloc ( GetProcessHeap ( ) , 0 , StubMsg . BufferLength ) ;
NdrPointerMarshall ( & StubMsg , ( unsigned char * ) & ch , fmtstr_up_char ) ;
ok ( StubMsg . Buffer = = StubMsg . BufferStart + 5 , " %p %p \n " , StubMsg . Buffer , StubMsg . BufferStart ) ;
2009-05-27 21:18:35 +02:00
use_pointer_ids = ( * ( unsigned int * ) StubMsg . BufferStart ! = ( UINT_PTR ) & ch ) ;
2008-06-14 17:29:35 +02:00
trace ( " Pointer marshalling using %s \n " , use_pointer_ids ? " pointer ids " : " pointer value " ) ;
HeapFree ( GetProcessHeap ( ) , 0 , StubMsg . BufferStart ) ;
}
2006-05-17 16:28:38 +02:00
2007-01-23 12:50:06 +01:00
static void test_ndr_simple_type ( void )
{
RPC_MESSAGE RpcMessage ;
MIDL_STUB_MESSAGE StubMsg ;
MIDL_STUB_DESC StubDesc ;
2009-05-27 21:18:35 +02:00
LONG l , l2 = 0 ;
2007-01-23 12:50:06 +01:00
StubDesc = Object_StubDesc ;
StubDesc . pFormatTypes = NULL ;
NdrClientInitializeNew (
& RpcMessage ,
& StubMsg ,
& StubDesc ,
0 ) ;
StubMsg . BufferLength = 16 ;
StubMsg . RpcMsg - > Buffer = StubMsg . BufferStart = StubMsg . Buffer = HeapAlloc ( GetProcessHeap ( ) , 0 , StubMsg . BufferLength ) ;
l = 0xcafebabe ;
NdrSimpleTypeMarshall ( & StubMsg , ( unsigned char * ) & l , 8 /* FC_LONG */ ) ;
ok ( StubMsg . Buffer = = StubMsg . BufferStart + 4 , " %p %p \n " , StubMsg . Buffer , StubMsg . BufferStart ) ;
2009-05-27 21:18:35 +02:00
ok ( * ( LONG * ) StubMsg . BufferStart = = l , " %d \n " , * ( LONG * ) StubMsg . BufferStart ) ;
2007-01-23 12:50:06 +01:00
StubMsg . Buffer = StubMsg . BufferStart + 1 ;
NdrSimpleTypeMarshall ( & StubMsg , ( unsigned char * ) & l , 8 /* FC_LONG */ ) ;
ok ( StubMsg . Buffer = = StubMsg . BufferStart + 8 , " %p %p \n " , StubMsg . Buffer , StubMsg . BufferStart ) ;
2009-05-27 21:18:35 +02:00
ok ( * ( LONG * ) ( StubMsg . BufferStart + 4 ) = = l , " %d \n " , * ( LONG * ) StubMsg . BufferStart ) ;
2007-01-23 12:50:06 +01:00
StubMsg . Buffer = StubMsg . BufferStart + 1 ;
NdrSimpleTypeUnmarshall ( & StubMsg , ( unsigned char * ) & l2 , 8 /* FC_LONG */ ) ;
ok ( StubMsg . Buffer = = StubMsg . BufferStart + 8 , " %p %p \n " , StubMsg . Buffer , StubMsg . BufferStart ) ;
2009-05-27 21:18:35 +02:00
ok ( l2 = = l , " %d \n " , l2 ) ;
2007-01-23 12:50:06 +01:00
HeapFree ( GetProcessHeap ( ) , 0 , StubMsg . BufferStart ) ;
}
2006-05-17 16:28:38 +02:00
static void test_pointer_marshal ( const unsigned char * formattypes ,
2009-05-27 21:18:35 +02:00
void * memsrc , DWORD srcsize ,
2006-05-17 16:28:38 +02:00
const void * wiredata ,
2007-05-28 01:11:20 +02:00
ULONG wiredatalen ,
2006-05-19 12:47:20 +02:00
int ( * cmp ) ( const void * , const void * , size_t ) ,
2009-05-27 21:18:35 +02:00
int num_additional_allocs ,
2006-05-17 16:28:38 +02:00
const char * msgpfx )
{
RPC_MESSAGE RpcMessage ;
MIDL_STUB_MESSAGE StubMsg ;
MIDL_STUB_DESC StubDesc ;
DWORD size ;
void * ptr ;
unsigned char * mem , * mem_orig ;
my_alloc_called = my_free_called = 0 ;
2006-05-19 12:47:20 +02:00
if ( ! cmp )
cmp = memcmp ;
2006-05-17 16:28:38 +02:00
StubDesc = Object_StubDesc ;
StubDesc . pFormatTypes = formattypes ;
NdrClientInitializeNew (
& RpcMessage ,
& StubMsg ,
& StubDesc ,
0 ) ;
StubMsg . BufferLength = 0 ;
NdrPointerBufferSize ( & StubMsg ,
memsrc ,
formattypes ) ;
2006-11-08 23:46:24 +01:00
ok ( StubMsg . BufferLength > = wiredatalen , " %s: length %d \n " , msgpfx , StubMsg . BufferLength ) ;
2006-05-17 16:28:38 +02:00
/*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
StubMsg . RpcMsg - > Buffer = StubMsg . BufferStart = StubMsg . Buffer = HeapAlloc ( GetProcessHeap ( ) , 0 , StubMsg . BufferLength ) ;
StubMsg . BufferEnd = StubMsg . BufferStart + StubMsg . BufferLength ;
memset ( StubMsg . BufferStart , 0x0 , StubMsg . BufferLength ) ; /* This is a hack to clear the padding between the ptr and longlong/double */
ptr = NdrPointerMarshall ( & StubMsg , memsrc , formattypes ) ;
ok ( ptr = = NULL , " %s: ret %p \n " , msgpfx , ptr ) ;
2009-06-19 12:49:20 +02:00
if ( srcsize = = 8 & & wiredatalen = = 16 & & StubMsg . Buffer - StubMsg . BufferStart = = 12 )
{
/* win9x doesn't align 8-byte types properly */
wiredatalen = 12 ;
}
else
{
ok ( StubMsg . Buffer - StubMsg . BufferStart = = wiredatalen , " %s: Buffer %p Start %p len %d \n " , msgpfx , StubMsg . Buffer , StubMsg . BufferStart , wiredatalen ) ;
ok ( ! memcmp ( StubMsg . BufferStart , wiredata , wiredatalen ) , " %s: incorrectly marshaled \n " , msgpfx ) ;
}
2006-05-17 16:28:38 +02:00
StubMsg . Buffer = StubMsg . BufferStart ;
StubMsg . MemorySize = 0 ;
size = NdrPointerMemorySize ( & StubMsg , formattypes ) ;
2007-01-06 19:26:59 +01:00
ok ( size = = StubMsg . MemorySize , " %s: mem size %u size %u \n " , msgpfx , StubMsg . MemorySize , size ) ;
2007-05-28 01:11:20 +02:00
ok ( StubMsg . Buffer - StubMsg . BufferStart = = wiredatalen , " %s: Buffer %p Start %p len %d \n " , msgpfx , StubMsg . Buffer , StubMsg . BufferStart , wiredatalen ) ;
2006-05-17 16:28:38 +02:00
if ( formattypes [ 1 ] & 0x10 /* FC_POINTER_DEREF */ )
2009-06-19 12:38:46 +02:00
ok ( size = = srcsize + sizeof ( void * ) , " %s: mem size %u \n " , msgpfx , size ) ;
2006-05-17 16:28:38 +02:00
else
2007-01-06 19:26:59 +01:00
ok ( size = = srcsize , " %s: mem size %u \n " , msgpfx , size ) ;
2006-05-17 16:28:38 +02:00
StubMsg . Buffer = StubMsg . BufferStart ;
StubMsg . MemorySize = 16 ;
size = NdrPointerMemorySize ( & StubMsg , formattypes ) ;
2007-01-06 19:26:59 +01:00
ok ( size = = StubMsg . MemorySize , " %s: mem size %u size %u \n " , msgpfx , StubMsg . MemorySize , size ) ;
2007-05-28 01:11:20 +02:00
ok ( StubMsg . Buffer - StubMsg . BufferStart = = wiredatalen , " %s: Buffer %p Start %p len %d \n " , msgpfx , StubMsg . Buffer , StubMsg . BufferStart , wiredatalen ) ;
2006-05-17 16:28:38 +02:00
if ( formattypes [ 1 ] & 0x10 /* FC_POINTER_DEREF */ )
2009-06-19 12:38:46 +02:00
ok ( size = = srcsize + sizeof ( void * ) + 16 , " %s: mem size %u \n " , msgpfx , size ) ;
2006-05-17 16:28:38 +02:00
else
2007-01-06 19:26:59 +01:00
ok ( size = = srcsize + 16 , " %s: mem size %u \n " , msgpfx , size ) ;
2006-05-17 16:28:38 +02:00
StubMsg . Buffer = StubMsg . BufferStart ;
StubMsg . MemorySize = 1 ;
size = NdrPointerMemorySize ( & StubMsg , formattypes ) ;
2007-01-06 19:26:59 +01:00
ok ( size = = StubMsg . MemorySize , " %s: mem size %u size %u \n " , msgpfx , StubMsg . MemorySize , size ) ;
2007-05-28 01:11:20 +02:00
ok ( StubMsg . Buffer - StubMsg . BufferStart = = wiredatalen , " %s: Buffer %p Start %p len %d \n " , msgpfx , StubMsg . Buffer , StubMsg . BufferStart , wiredatalen ) ;
2006-05-17 16:28:38 +02:00
if ( formattypes [ 1 ] & 0x10 /* FC_POINTER_DEREF */ )
2009-06-19 12:38:46 +02:00
ok ( size = = srcsize + sizeof ( void * ) + ( srcsize = = 8 ? 8 : sizeof ( void * ) ) , " %s: mem size %u \n " , msgpfx , size ) ;
2006-05-17 16:28:38 +02:00
else
2009-06-19 12:38:46 +02:00
ok ( size = = srcsize + ( srcsize = = 8 ? 8 : sizeof ( void * ) ) , " %s: mem size %u \n " , msgpfx , size ) ;
2006-05-17 16:28:38 +02:00
size = srcsize ;
if ( formattypes [ 1 ] & 0x10 ) size + = 4 ;
StubMsg . Buffer = StubMsg . BufferStart ;
StubMsg . MemorySize = 0 ;
2009-11-29 11:31:05 +01:00
mem_orig = mem = HeapAlloc ( GetProcessHeap ( ) , HEAP_ZERO_MEMORY , size ) ;
2006-05-17 16:28:38 +02:00
if ( formattypes [ 1 ] & 0x10 /* FC_POINTER_DEREF */ )
* ( void * * ) mem = NULL ;
ptr = NdrPointerUnmarshall ( & StubMsg , & mem , formattypes , 0 ) ;
ok ( ptr = = NULL , " %s: ret %p \n " , msgpfx , ptr ) ;
ok ( mem = = mem_orig , " %s: mem has changed %p %p \n " , msgpfx , mem , mem_orig ) ;
2006-05-19 12:47:20 +02:00
ok ( ! cmp ( mem , memsrc , srcsize ) , " %s: incorrectly unmarshaled \n " , msgpfx ) ;
2007-05-28 01:11:20 +02:00
ok ( StubMsg . Buffer - StubMsg . BufferStart = = wiredatalen , " %s: Buffer %p Start %p len %d \n " , msgpfx , StubMsg . Buffer , StubMsg . BufferStart , wiredatalen ) ;
2006-11-08 23:46:24 +01:00
ok ( StubMsg . MemorySize = = 0 , " %s: memorysize %d \n " , msgpfx , StubMsg . MemorySize ) ;
2006-05-19 12:47:20 +02:00
ok ( my_alloc_called = = num_additional_allocs , " %s: my_alloc got called %d times \n " , msgpfx , my_alloc_called ) ;
my_alloc_called = 0 ;
2006-05-17 16:28:38 +02:00
/* reset the buffer and call with must alloc */
StubMsg . Buffer = StubMsg . BufferStart ;
if ( formattypes [ 1 ] & 0x10 /* FC_POINTER_DEREF */ )
* ( void * * ) mem = NULL ;
ptr = NdrPointerUnmarshall ( & StubMsg , & mem , formattypes , 1 ) ;
ok ( ptr = = NULL , " %s: ret %p \n " , msgpfx , ptr ) ;
/* doesn't allocate mem in this case */
todo_wine {
ok ( mem = = mem_orig , " %s: mem has changed %p %p \n " , msgpfx , mem , mem_orig ) ;
}
2006-05-19 12:47:20 +02:00
ok ( ! cmp ( mem , memsrc , srcsize ) , " %s: incorrectly unmarshaled \n " , msgpfx ) ;
2007-05-28 01:11:20 +02:00
ok ( StubMsg . Buffer - StubMsg . BufferStart = = wiredatalen , " %s: Buffer %p Start %p len %d \n " , msgpfx , StubMsg . Buffer , StubMsg . BufferStart , wiredatalen ) ;
2006-11-08 23:46:24 +01:00
ok ( StubMsg . MemorySize = = 0 , " %s: memorysize %d \n " , msgpfx , StubMsg . MemorySize ) ;
2006-05-17 16:28:38 +02:00
todo_wine {
2006-05-19 12:47:20 +02:00
ok ( my_alloc_called = = num_additional_allocs , " %s: my_alloc got called %d times \n " , msgpfx , my_alloc_called ) ;
2006-05-17 16:28:38 +02:00
}
2006-05-19 12:47:20 +02:00
my_alloc_called = 0 ;
2006-05-17 16:28:38 +02:00
if ( formattypes [ 0 ] ! = 0x11 /* FC_RP */ )
{
/* now pass the address of a NULL ptr */
mem = NULL ;
StubMsg . Buffer = StubMsg . BufferStart ;
ptr = NdrPointerUnmarshall ( & StubMsg , & mem , formattypes , 0 ) ;
ok ( ptr = = NULL , " %s: ret %p \n " , msgpfx , ptr ) ;
ok ( mem ! = StubMsg . BufferStart + wiredatalen - srcsize , " %s: mem points to buffer %p %p \n " , msgpfx , mem , StubMsg . BufferStart ) ;
2006-05-19 12:47:20 +02:00
ok ( ! cmp ( mem , memsrc , size ) , " %s: incorrectly unmarshaled \n " , msgpfx ) ;
2007-05-28 01:11:20 +02:00
ok ( StubMsg . Buffer - StubMsg . BufferStart = = wiredatalen , " %s: Buffer %p Start %p len %d \n " , msgpfx , StubMsg . Buffer , StubMsg . BufferStart , wiredatalen ) ;
2006-11-08 23:46:24 +01:00
ok ( StubMsg . MemorySize = = 0 , " %s: memorysize %d \n " , msgpfx , StubMsg . MemorySize ) ;
2006-05-19 12:47:20 +02:00
ok ( my_alloc_called = = num_additional_allocs + 1 , " %s: my_alloc got called %d times \n " , msgpfx , my_alloc_called ) ;
my_alloc_called = 0 ;
2006-05-17 16:28:38 +02:00
NdrPointerFree ( & StubMsg , mem , formattypes ) ;
/* again pass address of NULL ptr, but pretend we're a server */
2009-05-27 21:38:17 +02:00
if ( 0 ) /* crashes on Win9x and NT4 */
{
mem = NULL ;
StubMsg . Buffer = StubMsg . BufferStart ;
StubMsg . IsClient = 0 ;
ptr = NdrPointerUnmarshall ( & StubMsg , & mem , formattypes , 0 ) ;
ok ( ptr = = NULL , " %s: ret %p \n " , msgpfx , ptr ) ;
if ( formattypes [ 2 ] = = 0xd /* FC_ENUM16 */ )
ok ( mem ! = StubMsg . BufferStart + wiredatalen - srcsize , " %s: mem points to buffer %p %p \n " , msgpfx , mem , StubMsg . BufferStart ) ;
else
ok ( mem = = StubMsg . BufferStart + wiredatalen - srcsize , " %s: mem doesn't point to buffer %p %p \n " , msgpfx , mem , StubMsg . BufferStart ) ;
ok ( ! cmp ( mem , memsrc , size ) , " %s: incorrectly unmarshaled \n " , msgpfx ) ;
ok ( StubMsg . Buffer - StubMsg . BufferStart = = wiredatalen , " %s: Buffer %p Start %p len %d \n " , msgpfx , StubMsg . Buffer , StubMsg . BufferStart , wiredatalen ) ;
ok ( StubMsg . MemorySize = = 0 , " %s: memorysize %d \n " , msgpfx , StubMsg . MemorySize ) ;
if ( formattypes [ 2 ] ! = 0xd /* FC_ENUM16 */ ) {
ok ( my_alloc_called = = num_additional_allocs , " %s: my_alloc got called %d times \n " , msgpfx , my_alloc_called ) ;
my_alloc_called = 0 ;
}
2007-11-27 13:32:48 +01:00
}
2006-05-17 16:28:38 +02:00
}
HeapFree ( GetProcessHeap ( ) , 0 , mem_orig ) ;
HeapFree ( GetProcessHeap ( ) , 0 , StubMsg . BufferStart ) ;
}
2006-05-19 12:47:20 +02:00
static int deref_cmp ( const void * s1 , const void * s2 , size_t num )
{
2006-12-13 21:50:37 +01:00
return memcmp ( * ( const void * const * ) s1 , * ( const void * const * ) s2 , num ) ;
2006-05-19 12:47:20 +02:00
}
2006-08-18 20:57:46 +02:00
static void test_simple_types ( void )
2006-05-17 16:28:38 +02:00
{
unsigned char wiredata [ 16 ] ;
unsigned char ch ;
unsigned char * ch_ptr ;
unsigned short s ;
unsigned int i ;
2009-05-27 21:18:35 +02:00
ULONG l ;
2006-05-17 16:28:38 +02:00
ULONGLONG ll ;
float f ;
double d ;
static const unsigned char fmtstr_up_char [ ] =
{
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0x2 , /* FC_CHAR */
0x5c , /* FC_PAD */
} ;
static const unsigned char fmtstr_up_byte [ ] =
{
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0x1 , /* FC_BYTE */
0x5c , /* FC_PAD */
} ;
static const unsigned char fmtstr_up_small [ ] =
{
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0x3 , /* FC_SMALL */
0x5c , /* FC_PAD */
} ;
static const unsigned char fmtstr_up_usmall [ ] =
{
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0x4 , /* FC_USMALL */
0x5c , /* FC_PAD */
} ;
static const unsigned char fmtstr_rp_char [ ] =
{
0x11 , 0x8 , /* FC_RP [simple_pointer] */
0x2 , /* FC_CHAR */
0x5c , /* FC_PAD */
} ;
static const unsigned char fmtstr_rpup_char [ ] =
{
0x11 , 0x14 , /* FC_RP [alloced_on_stack] */
NdrFcShort ( 0x2 ) , /* Offset= 2 (4) */
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0x2 , /* FC_CHAR */
0x5c , /* FC_PAD */
} ;
static const unsigned char fmtstr_rpup_char2 [ ] =
{
0x11 , 0x04 , /* FC_RP [alloced_on_stack] */
NdrFcShort ( 0x2 ) , /* Offset= 2 (4) */
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0x2 , /* FC_CHAR */
0x5c , /* FC_PAD */
} ;
static const unsigned char fmtstr_up_wchar [ ] =
{
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0x5 , /* FC_WCHAR */
0x5c , /* FC_PAD */
} ;
static const unsigned char fmtstr_up_short [ ] =
{
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0x6 , /* FC_SHORT */
0x5c , /* FC_PAD */
} ;
static const unsigned char fmtstr_up_ushort [ ] =
{
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0x7 , /* FC_USHORT */
0x5c , /* FC_PAD */
} ;
static const unsigned char fmtstr_up_enum16 [ ] =
{
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0xd , /* FC_ENUM16 */
0x5c , /* FC_PAD */
} ;
static const unsigned char fmtstr_up_long [ ] =
{
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0x8 , /* FC_LONG */
0x5c , /* FC_PAD */
} ;
static const unsigned char fmtstr_up_ulong [ ] =
{
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0x9 , /* FC_ULONG */
0x5c , /* FC_PAD */
} ;
static const unsigned char fmtstr_up_enum32 [ ] =
{
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0xe , /* FC_ENUM32 */
0x5c , /* FC_PAD */
} ;
static const unsigned char fmtstr_up_errorstatus [ ] =
{
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0x10 , /* FC_ERROR_STATUS_T */
0x5c , /* FC_PAD */
} ;
static const unsigned char fmtstr_up_longlong [ ] =
{
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0xb , /* FC_HYPER */
0x5c , /* FC_PAD */
} ;
static const unsigned char fmtstr_up_float [ ] =
{
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0xa , /* FC_FLOAT */
0x5c , /* FC_PAD */
} ;
static const unsigned char fmtstr_up_double [ ] =
{
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0xc , /* FC_DOUBLE */
0x5c , /* FC_PAD */
} ;
ch = 0xa5 ;
ch_ptr = & ch ;
2008-06-14 17:29:35 +02:00
if ( use_pointer_ids )
* ( unsigned int * ) wiredata = 0x20000 ;
else
2009-05-27 21:18:35 +02:00
* ( unsigned int * ) wiredata = ( UINT_PTR ) ch_ptr ;
2008-06-14 17:29:35 +02:00
wiredata [ 4 ] = ch ;
2006-05-17 16:28:38 +02:00
2006-05-19 12:47:20 +02:00
test_pointer_marshal ( fmtstr_up_char , ch_ptr , 1 , wiredata , 5 , NULL , 0 , " up_char " ) ;
test_pointer_marshal ( fmtstr_up_byte , ch_ptr , 1 , wiredata , 5 , NULL , 0 , " up_byte " ) ;
test_pointer_marshal ( fmtstr_up_small , ch_ptr , 1 , wiredata , 5 , NULL , 0 , " up_small " ) ;
test_pointer_marshal ( fmtstr_up_usmall , ch_ptr , 1 , wiredata , 5 , NULL , 0 , " up_usmall " ) ;
2006-05-17 16:28:38 +02:00
2006-05-19 12:47:20 +02:00
test_pointer_marshal ( fmtstr_rp_char , ch_ptr , 1 , & ch , 1 , NULL , 0 , " rp_char " ) ;
2006-05-17 16:28:38 +02:00
2006-05-19 12:47:20 +02:00
test_pointer_marshal ( fmtstr_rpup_char , & ch_ptr , 1 , wiredata , 5 , deref_cmp , 1 , " rpup_char " ) ;
test_pointer_marshal ( fmtstr_rpup_char2 , ch_ptr , 1 , wiredata , 5 , NULL , 0 , " rpup_char2 " ) ;
2006-05-17 16:28:38 +02:00
s = 0xa597 ;
2008-06-14 17:29:35 +02:00
if ( use_pointer_ids )
* ( unsigned int * ) wiredata = 0x20000 ;
else
2009-05-27 21:18:35 +02:00
* ( unsigned int * ) wiredata = ( UINT_PTR ) & s ;
2008-06-14 17:29:35 +02:00
* ( unsigned short * ) ( wiredata + 4 ) = s ;
2006-05-17 16:28:38 +02:00
2006-05-19 12:47:20 +02:00
test_pointer_marshal ( fmtstr_up_wchar , & s , 2 , wiredata , 6 , NULL , 0 , " up_wchar " ) ;
test_pointer_marshal ( fmtstr_up_short , & s , 2 , wiredata , 6 , NULL , 0 , " up_short " ) ;
test_pointer_marshal ( fmtstr_up_ushort , & s , 2 , wiredata , 6 , NULL , 0 , " up_ushort " ) ;
2006-05-17 16:28:38 +02:00
2007-07-16 16:00:59 +02:00
i = 0x7fff ;
2008-06-14 17:29:35 +02:00
if ( use_pointer_ids )
* ( unsigned int * ) wiredata = 0x20000 ;
else
2009-05-27 21:18:35 +02:00
* ( unsigned int * ) wiredata = ( UINT_PTR ) & i ;
2008-06-14 17:29:35 +02:00
* ( unsigned short * ) ( wiredata + 4 ) = i ;
2009-05-28 11:52:36 +02:00
test_pointer_marshal ( fmtstr_up_enum16 , & i , 4 , wiredata , 6 , NULL , 0 , " up_enum16 " ) ;
2006-05-17 16:28:38 +02:00
l = 0xcafebabe ;
2008-06-14 17:29:35 +02:00
if ( use_pointer_ids )
* ( unsigned int * ) wiredata = 0x20000 ;
else
2009-05-27 21:18:35 +02:00
* ( unsigned int * ) wiredata = ( UINT_PTR ) & l ;
* ( ULONG * ) ( wiredata + 4 ) = l ;
2006-05-17 16:28:38 +02:00
2006-05-19 12:47:20 +02:00
test_pointer_marshal ( fmtstr_up_long , & l , 4 , wiredata , 8 , NULL , 0 , " up_long " ) ;
test_pointer_marshal ( fmtstr_up_ulong , & l , 4 , wiredata , 8 , NULL , 0 , " up_ulong " ) ;
test_pointer_marshal ( fmtstr_up_enum32 , & l , 4 , wiredata , 8 , NULL , 0 , " up_emun32 " ) ;
test_pointer_marshal ( fmtstr_up_errorstatus , & l , 4 , wiredata , 8 , NULL , 0 , " up_errorstatus " ) ;
2006-05-17 16:28:38 +02:00
ll = ( ( ULONGLONG ) 0xcafebabe ) < < 32 | 0xdeadbeef ;
2008-06-14 17:29:35 +02:00
if ( use_pointer_ids )
* ( unsigned int * ) wiredata = 0x20000 ;
else
2009-05-27 21:18:35 +02:00
* ( unsigned int * ) wiredata = ( UINT_PTR ) & ll ;
* ( unsigned int * ) ( wiredata + 4 ) = 0 ;
2008-06-14 17:29:35 +02:00
* ( ULONGLONG * ) ( wiredata + 8 ) = ll ;
2006-05-19 12:47:20 +02:00
test_pointer_marshal ( fmtstr_up_longlong , & ll , 8 , wiredata , 16 , NULL , 0 , " up_longlong " ) ;
2006-05-17 16:28:38 +02:00
2007-05-28 01:17:17 +02:00
f = 3.1415f ;
2008-06-14 17:29:35 +02:00
if ( use_pointer_ids )
* ( unsigned int * ) wiredata = 0x20000 ;
else
2009-05-27 21:18:35 +02:00
* ( unsigned int * ) wiredata = ( UINT_PTR ) & f ;
2008-06-14 17:29:35 +02:00
* ( float * ) ( wiredata + 4 ) = f ;
2006-05-19 12:47:20 +02:00
test_pointer_marshal ( fmtstr_up_float , & f , 4 , wiredata , 8 , NULL , 0 , " up_float " ) ;
2006-05-17 16:28:38 +02:00
d = 3.1415 ;
2008-06-14 17:29:35 +02:00
if ( use_pointer_ids )
* ( unsigned int * ) wiredata = 0x20000 ;
else
2009-05-27 21:18:35 +02:00
* ( unsigned int * ) wiredata = ( UINT_PTR ) & d ;
2008-06-14 17:29:35 +02:00
* ( unsigned int * ) ( wiredata + 4 ) = 0 ;
* ( double * ) ( wiredata + 8 ) = d ;
2006-05-19 12:47:20 +02:00
test_pointer_marshal ( fmtstr_up_double , & d , 8 , wiredata , 16 , NULL , 0 , " up_double " ) ;
2006-05-17 16:28:38 +02:00
}
2008-01-16 15:02:58 +01:00
static void test_nontrivial_pointer_types ( void )
{
RPC_MESSAGE RpcMessage ;
MIDL_STUB_MESSAGE StubMsg ;
MIDL_STUB_DESC StubDesc ;
2009-01-08 13:02:40 +01:00
DWORD size ;
2008-01-16 15:02:58 +01:00
void * ptr ;
char * * p1 ;
char * p2 ;
char ch ;
unsigned char * mem , * mem_orig ;
static const unsigned char fmtstr_ref_unique_out [ ] =
{
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0x2 , /* FC_CHAR */
0x5c , /* FC_PAD */
0x11 , 0x14 , /* FC_RP [alloced_on_stack] [pointer_deref] */
NdrFcShort ( 0xfffffffa ) , /* Offset= -6 (0) */
} ;
p1 = & p2 ;
p2 = & ch ;
ch = 0x22 ;
StubDesc = Object_StubDesc ;
StubDesc . pFormatTypes = fmtstr_ref_unique_out ;
NdrClientInitializeNew (
& RpcMessage ,
& StubMsg ,
& StubDesc ,
0 ) ;
StubMsg . BufferLength = 0 ;
NdrPointerBufferSize ( & StubMsg ,
( unsigned char * ) p1 ,
& fmtstr_ref_unique_out [ 4 ] ) ;
2008-05-07 00:06:17 +02:00
/* Windows overestimates the buffer size */
ok ( StubMsg . BufferLength > = 5 , " length %d \n " , StubMsg . BufferLength ) ;
2008-01-16 15:02:58 +01:00
/*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
StubMsg . RpcMsg - > Buffer = StubMsg . BufferStart = StubMsg . Buffer = HeapAlloc ( GetProcessHeap ( ) , 0 , StubMsg . BufferLength ) ;
StubMsg . BufferEnd = StubMsg . BufferStart + StubMsg . BufferLength ;
ptr = NdrPointerMarshall ( & StubMsg , ( unsigned char * ) p1 , & fmtstr_ref_unique_out [ 4 ] ) ;
ok ( ptr = = NULL , " ret %p \n " , ptr ) ;
2009-01-08 13:02:40 +01:00
size = StubMsg . Buffer - StubMsg . BufferStart ;
ok ( size = = 5 , " Buffer %p Start %p len %d \n " , StubMsg . Buffer , StubMsg . BufferStart , size ) ;
2008-01-16 15:02:58 +01:00
ok ( * ( unsigned int * ) StubMsg . BufferStart ! = 0 , " pointer ID marshalled incorrectly \n " ) ;
ok ( * ( unsigned char * ) ( StubMsg . BufferStart + 4 ) = = 0x22 , " char data marshalled incorrectly: 0x%x \n " ,
* ( unsigned char * ) ( StubMsg . BufferStart + 4 ) ) ;
StubMsg . Buffer = StubMsg . BufferStart ;
StubMsg . MemorySize = 0 ;
mem = NULL ;
/* Client */
my_alloc_called = 0 ;
StubMsg . Buffer = StubMsg . BufferStart ;
mem = mem_orig = HeapAlloc ( GetProcessHeap ( ) , 0 , sizeof ( void * ) ) ;
* ( void * * ) mem = NULL ;
NdrPointerUnmarshall ( & StubMsg , & mem , & fmtstr_ref_unique_out [ 4 ] , 0 ) ;
ok ( mem = = mem_orig , " mem alloced \n " ) ;
ok ( my_alloc_called = = 1 , " alloc called %d \n " , my_alloc_called ) ;
my_alloc_called = 0 ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrPointerUnmarshall ( & StubMsg , & mem , & fmtstr_ref_unique_out [ 4 ] , 1 ) ;
todo_wine {
ok ( mem = = mem_orig , " mem alloced \n " ) ;
ok ( my_alloc_called = = 0 , " alloc called %d \n " , my_alloc_called ) ;
}
my_free_called = 0 ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrPointerFree ( & StubMsg , mem , & fmtstr_ref_unique_out [ 4 ] ) ;
ok ( my_free_called = = 1 , " free called %d \n " , my_free_called ) ;
mem = my_alloc ( sizeof ( void * ) ) ;
* ( void * * ) mem = NULL ;
my_free_called = 0 ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrPointerFree ( & StubMsg , mem , & fmtstr_ref_unique_out [ 4 ] ) ;
ok ( my_free_called = = 0 , " free called %d \n " , my_free_called ) ;
my_free ( mem ) ;
mem = my_alloc ( sizeof ( void * ) ) ;
* ( void * * ) mem = my_alloc ( sizeof ( char ) ) ;
my_free_called = 0 ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrPointerFree ( & StubMsg , mem , & fmtstr_ref_unique_out [ 4 ] ) ;
ok ( my_free_called = = 1 , " free called %d \n " , my_free_called ) ;
my_free ( mem ) ;
/* Server */
my_alloc_called = 0 ;
StubMsg . IsClient = 0 ;
mem = NULL ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrPointerUnmarshall ( & StubMsg , & mem , & fmtstr_ref_unique_out [ 4 ] , 0 ) ;
ok ( mem ! = StubMsg . BufferStart , " mem pointing at buffer \n " ) ;
todo_wine
ok ( my_alloc_called = = 1 , " alloc called %d \n " , my_alloc_called ) ;
NdrPointerFree ( & StubMsg , mem , & fmtstr_ref_unique_out [ 4 ] ) ;
my_alloc_called = 0 ;
mem = NULL ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrPointerUnmarshall ( & StubMsg , & mem , & fmtstr_ref_unique_out [ 4 ] , 1 ) ;
ok ( mem ! = StubMsg . BufferStart , " mem pointing at buffer \n " ) ;
todo_wine
ok ( my_alloc_called = = 1 , " alloc called %d \n " , my_alloc_called ) ;
NdrPointerFree ( & StubMsg , mem , & fmtstr_ref_unique_out [ 4 ] ) ;
my_alloc_called = 0 ;
mem = mem_orig ;
* ( void * * ) mem = NULL ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrPointerUnmarshall ( & StubMsg , & mem , & fmtstr_ref_unique_out [ 4 ] , 0 ) ;
todo_wine {
ok ( mem = = mem_orig , " mem alloced \n " ) ;
ok ( my_alloc_called = = 0 , " alloc called %d \n " , my_alloc_called ) ;
}
my_alloc_called = 0 ;
mem = mem_orig ;
* ( void * * ) mem = NULL ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrPointerUnmarshall ( & StubMsg , & mem , & fmtstr_ref_unique_out [ 4 ] , 1 ) ;
todo_wine {
ok ( mem = = mem_orig , " mem alloced \n " ) ;
ok ( my_alloc_called = = 0 , " alloc called %d \n " , my_alloc_called ) ;
}
mem = my_alloc ( sizeof ( void * ) ) ;
* ( void * * ) mem = NULL ;
my_free_called = 0 ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrPointerFree ( & StubMsg , mem , & fmtstr_ref_unique_out [ 4 ] ) ;
ok ( my_free_called = = 0 , " free called %d \n " , my_free_called ) ;
my_free ( mem ) ;
mem = my_alloc ( sizeof ( void * ) ) ;
* ( void * * ) mem = my_alloc ( sizeof ( char ) ) ;
my_free_called = 0 ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrPointerFree ( & StubMsg , mem , & fmtstr_ref_unique_out [ 4 ] ) ;
ok ( my_free_called = = 1 , " free called %d \n " , my_free_called ) ;
my_free ( mem ) ;
HeapFree ( GetProcessHeap ( ) , 0 , mem_orig ) ;
HeapFree ( GetProcessHeap ( ) , 0 , StubMsg . RpcMsg - > Buffer ) ;
}
2006-05-19 12:47:20 +02:00
static void test_simple_struct_marshal ( const unsigned char * formattypes ,
2009-05-27 21:18:35 +02:00
void * memsrc , DWORD srcsize ,
2006-05-19 12:47:20 +02:00
const void * wiredata ,
2007-05-28 01:11:20 +02:00
ULONG wiredatalen ,
2006-05-19 12:47:20 +02:00
int ( * cmp ) ( const void * , const void * , size_t ) ,
2009-05-27 21:18:35 +02:00
int num_additional_allocs ,
2006-05-19 12:47:20 +02:00
const char * msgpfx )
{
RPC_MESSAGE RpcMessage ;
MIDL_STUB_MESSAGE StubMsg ;
MIDL_STUB_DESC StubDesc ;
DWORD size ;
void * ptr ;
unsigned char * mem , * mem_orig ;
my_alloc_called = my_free_called = 0 ;
if ( ! cmp )
cmp = memcmp ;
StubDesc = Object_StubDesc ;
StubDesc . pFormatTypes = formattypes ;
NdrClientInitializeNew ( & RpcMessage , & StubMsg , & StubDesc , 0 ) ;
StubMsg . BufferLength = 0 ;
2009-02-16 09:54:10 +01:00
NdrSimpleStructBufferSize ( & StubMsg , memsrc , formattypes ) ;
2006-11-08 23:46:24 +01:00
ok ( StubMsg . BufferLength > = wiredatalen , " %s: length %d \n " , msgpfx , StubMsg . BufferLength ) ;
2006-05-19 12:47:20 +02:00
StubMsg . RpcMsg - > Buffer = StubMsg . BufferStart = StubMsg . Buffer = HeapAlloc ( GetProcessHeap ( ) , 0 , StubMsg . BufferLength ) ;
StubMsg . BufferEnd = StubMsg . BufferStart + StubMsg . BufferLength ;
2009-02-16 09:54:10 +01:00
ptr = NdrSimpleStructMarshall ( & StubMsg , memsrc , formattypes ) ;
2006-05-19 12:47:20 +02:00
ok ( ptr = = NULL , " %s: ret %p \n " , msgpfx , ptr ) ;
ok ( StubMsg . Buffer - StubMsg . BufferStart = = wiredatalen , " %s: Buffer %p Start %p \n " , msgpfx , StubMsg . Buffer , StubMsg . BufferStart ) ;
2006-10-08 00:48:22 +02:00
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 ) ) ;
2006-05-19 12:47:20 +02:00
StubMsg . Buffer = StubMsg . BufferStart ;
StubMsg . MemorySize = 0 ;
size = NdrSimpleStructMemorySize ( & StubMsg , formattypes ) ;
ok ( size = = StubMsg . MemorySize , " %s: size != MemorySize \n " , msgpfx ) ;
2007-01-06 19:26:59 +01:00
ok ( size = = srcsize , " %s: mem size %u \n " , msgpfx , size ) ;
2006-05-19 12:47:20 +02:00
ok ( StubMsg . Buffer - StubMsg . BufferStart = = wiredatalen , " %s: Buffer %p Start %p \n " , msgpfx , StubMsg . Buffer , StubMsg . BufferStart ) ;
StubMsg . Buffer = StubMsg . BufferStart ;
size = NdrSimpleStructMemorySize ( & StubMsg , formattypes ) ;
ok ( size = = StubMsg . MemorySize , " %s: size != MemorySize \n " , msgpfx ) ;
2007-01-06 19:26:59 +01:00
ok ( StubMsg . MemorySize = = ( ( srcsize + 3 ) & ~ 3 ) + srcsize , " %s: mem size %u \n " , msgpfx , size ) ;
2006-05-19 12:47:20 +02:00
ok ( StubMsg . Buffer - StubMsg . BufferStart = = wiredatalen , " %s: Buffer %p Start %p \n " , msgpfx , StubMsg . Buffer , StubMsg . BufferStart ) ;
size = srcsize ;
/*** Unmarshalling first with must_alloc false ***/
StubMsg . Buffer = StubMsg . BufferStart ;
StubMsg . MemorySize = 0 ;
2007-11-30 23:03:39 +01:00
mem_orig = mem = HeapAlloc ( GetProcessHeap ( ) , HEAP_ZERO_MEMORY , srcsize ) ;
2006-05-19 12:47:20 +02:00
ptr = NdrSimpleStructUnmarshall ( & StubMsg , & mem , formattypes , 0 ) ;
ok ( ptr = = NULL , " %s: ret %p \n " , msgpfx , ptr ) ;
ok ( StubMsg . Buffer - StubMsg . BufferStart = = wiredatalen , " %s: Buffer %p Start %p \n " , msgpfx , StubMsg . Buffer , StubMsg . BufferStart ) ;
ok ( mem = = mem_orig , " %s: mem has changed %p %p \n " , msgpfx , mem , mem_orig ) ;
ok ( ! cmp ( mem , memsrc , srcsize ) , " %s: incorrectly unmarshaled \n " , msgpfx ) ;
ok ( my_alloc_called = = num_additional_allocs , " %s: my_alloc got called %d times \n " , msgpfx , my_alloc_called ) ;
my_alloc_called = 0 ;
ok ( StubMsg . MemorySize = = 0 , " %s: memorysize touched in unmarshal \n " , msgpfx ) ;
2008-04-11 04:17:14 +02:00
/* If we're a server we still use the supplied memory */
2006-05-19 12:47:20 +02:00
StubMsg . Buffer = StubMsg . BufferStart ;
StubMsg . IsClient = 0 ;
ptr = NdrSimpleStructUnmarshall ( & StubMsg , & mem , formattypes , 0 ) ;
ok ( ptr = = NULL , " %s: ret %p \n " , msgpfx , ptr ) ;
ok ( mem = = mem_orig , " %s: mem has changed %p %p \n " , msgpfx , mem , mem_orig ) ;
ok ( ! cmp ( mem , memsrc , srcsize ) , " %s: incorrectly unmarshaled \n " , msgpfx ) ;
ok ( my_alloc_called = = num_additional_allocs , " %s: my_alloc got called %d times \n " , msgpfx , my_alloc_called ) ;
my_alloc_called = 0 ;
ok ( StubMsg . MemorySize = = 0 , " %s: memorysize touched in unmarshal \n " , msgpfx ) ;
/* ...unless we pass a NULL ptr, then the buffer is used.
Passing a NULL ptr while we ' re a client & & ! must_alloc
crashes on Windows , so we won ' t do that . */
2009-05-27 21:38:17 +02:00
if ( 0 ) /* crashes on Win9x and NT4 */
{
mem = NULL ;
StubMsg . IsClient = 0 ;
StubMsg . Buffer = StubMsg . BufferStart ;
ptr = NdrSimpleStructUnmarshall ( & StubMsg , & mem , formattypes , FALSE ) ;
ok ( ptr = = NULL , " %s: ret %p \n " , msgpfx , ptr ) ;
ok ( mem = = StubMsg . BufferStart , " %s: mem not equal buffer \n " , msgpfx ) ;
ok ( ! cmp ( mem , memsrc , srcsize ) , " %s: incorrectly unmarshaled \n " , msgpfx ) ;
ok ( my_alloc_called = = num_additional_allocs , " %s: my_alloc got called %d times \n " , msgpfx , my_alloc_called ) ;
my_alloc_called = 0 ;
ok ( StubMsg . MemorySize = = 0 , " %s: memorysize touched in unmarshal \n " , msgpfx ) ;
}
2006-05-23 13:24:55 +02:00
2006-05-19 12:47:20 +02:00
/*** now must_alloc is true ***/
/* with must_alloc set we always allocate new memory whether or not we're
a server and also when passing NULL */
mem = mem_orig ;
StubMsg . IsClient = 1 ;
StubMsg . Buffer = StubMsg . BufferStart ;
ptr = NdrSimpleStructUnmarshall ( & StubMsg , & mem , formattypes , 1 ) ;
ok ( ptr = = NULL , " ret %p \n " , ptr ) ;
ok ( mem ! = mem_orig , " mem not changed %p %p \n " , mem , mem_orig ) ;
ok ( ! cmp ( mem , memsrc , srcsize ) , " incorrectly unmarshaled \n " ) ;
ok ( my_alloc_called = = num_additional_allocs + 1 , " %s: my_alloc got called %d times \n " , msgpfx , my_alloc_called ) ;
my_alloc_called = 0 ;
ok ( StubMsg . MemorySize = = 0 , " memorysize touched in unmarshal \n " ) ;
mem = NULL ;
StubMsg . Buffer = StubMsg . BufferStart ;
ptr = NdrSimpleStructUnmarshall ( & StubMsg , & mem , formattypes , 1 ) ;
ok ( ptr = = NULL , " ret %p \n " , ptr ) ;
ok ( mem ! = mem_orig , " mem not changed %p %p \n " , mem , mem_orig ) ;
ok ( ! cmp ( mem , memsrc , srcsize ) , " incorrectly unmarshaled \n " ) ;
ok ( my_alloc_called = = num_additional_allocs + 1 , " %s: my_alloc got called %d times \n " , msgpfx , my_alloc_called ) ;
my_alloc_called = 0 ;
ok ( StubMsg . MemorySize = = 0 , " memorysize touched in unmarshal \n " ) ;
mem = mem_orig ;
StubMsg . Buffer = StubMsg . BufferStart ;
StubMsg . IsClient = 0 ;
StubMsg . ReuseBuffer = 1 ;
ptr = NdrSimpleStructUnmarshall ( & StubMsg , & mem , formattypes , 1 ) ;
ok ( ptr = = NULL , " ret %p \n " , ptr ) ;
ok ( mem ! = mem_orig , " mem not changed %p %p \n " , mem , mem_orig ) ;
ok ( mem ! = StubMsg . BufferStart , " mem is buffer mem \n " ) ;
ok ( ! cmp ( mem , memsrc , srcsize ) , " incorrectly unmarshaled \n " ) ;
ok ( my_alloc_called = = num_additional_allocs + 1 , " %s: my_alloc got called %d times \n " , msgpfx , my_alloc_called ) ;
my_alloc_called = 0 ;
ok ( StubMsg . MemorySize = = 0 , " memorysize touched in unmarshal \n " ) ;
mem = NULL ;
StubMsg . Buffer = StubMsg . BufferStart ;
StubMsg . IsClient = 0 ;
StubMsg . ReuseBuffer = 1 ;
ptr = NdrSimpleStructUnmarshall ( & StubMsg , & mem , formattypes , 1 ) ;
ok ( ptr = = NULL , " ret %p \n " , ptr ) ;
ok ( mem ! = StubMsg . BufferStart , " mem is buffer mem \n " ) ;
ok ( ! cmp ( mem , memsrc , srcsize ) , " incorrectly unmarshaled \n " ) ;
ok ( my_alloc_called = = num_additional_allocs + 1 , " %s: my_alloc got called %d times \n " , msgpfx , my_alloc_called ) ;
my_alloc_called = 0 ;
ok ( StubMsg . MemorySize = = 0 , " memorysize touched in unmarshal \n " ) ;
2007-11-30 23:03:39 +01:00
HeapFree ( GetProcessHeap ( ) , 0 , mem_orig ) ;
HeapFree ( GetProcessHeap ( ) , 0 , StubMsg . BufferStart ) ;
2006-05-19 12:47:20 +02:00
}
typedef struct
{
2009-05-27 21:18:35 +02:00
LONG l1 ;
LONG * pl1 ;
2006-05-19 12:47:20 +02:00
char * pc1 ;
} ps1_t ;
static int ps1_cmp ( const void * s1 , const void * s2 , size_t num )
{
const ps1_t * p1 , * p2 ;
p1 = s1 ;
p2 = s2 ;
if ( p1 - > l1 ! = p2 - > l1 )
return 1 ;
if ( p1 - > pl1 & & p2 - > pl1 )
{
if ( * p1 - > pl1 ! = * p2 - > pl1 )
return 1 ;
}
2010-03-26 13:12:35 +01:00
else if ( p1 - > pl1 | | p2 - > pl1 )
2006-05-19 12:47:20 +02:00
return 1 ;
if ( p1 - > pc1 & & p2 - > pc1 )
{
if ( * p1 - > pc1 ! = * p2 - > pc1 )
return 1 ;
}
2010-03-26 13:12:35 +01:00
else if ( p1 - > pc1 | | p2 - > pc1 )
2006-05-19 12:47:20 +02:00
return 1 ;
return 0 ;
}
static void test_simple_struct ( void )
{
unsigned char wiredata [ 28 ] ;
2009-05-27 21:18:35 +02:00
ULONG wiredatalen ;
LONG l ;
2006-05-19 12:47:20 +02:00
char c ;
ps1_t ps1 ;
static const unsigned char fmtstr_simple_struct [ ] =
{
0x12 , 0x0 , /* FC_UP */
NdrFcShort ( 0x2 ) , /* Offset=2 */
0x15 , 0x3 , /* FC_STRUCT [align 4] */
NdrFcShort ( 0x18 ) , /* [size 24] */
0x6 , /* FC_SHORT */
0x2 , /* FC_CHAR */
0x38 , /* FC_ALIGNM4 */
0x8 , /* FC_LONG */
0x8 , /* FC_LONG */
0x39 , /* FC_ALIGNM8 */
0xb , /* FC_HYPER */
0x5b , /* FC_END */
} ;
struct {
short s ;
char c ;
2009-05-27 21:18:35 +02:00
LONG l1 , l2 ;
2006-05-19 12:47:20 +02:00
LONGLONG ll ;
} s1 ;
static const unsigned char fmtstr_pointer_struct [ ] =
{
0x12 , 0x0 , /* FC_UP */
NdrFcShort ( 0x2 ) , /* Offset=2 */
2009-06-19 12:38:46 +02:00
# ifdef _WIN64
0x1a , /* FC_BOGUS_STRUCT */
0x3 , /* 3 */
NdrFcShort ( 0x18 ) , /* [size 24] */
NdrFcShort ( 0x0 ) ,
NdrFcShort ( 0x8 ) , /* Offset= 8 (266) */
0x08 , /* FC_LONG */
0x39 , /* FC_ALIGNM8 */
0x36 , /* FC_POINTER */
0x36 , /* FC_POINTER */
0x5c , /* FC_PAD */
0x5b , /* FC_END */
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0x08 , /* FC_LONG */
0x5c , /* FC_PAD */
0x12 , 0x8 , /* FC_UP [simple_pointer] */
0x02 , /* FC_CHAR */
0x5c , /* FC_PAD */
# else
2006-05-19 12:47:20 +02:00
0x16 , 0x3 , /* FC_PSTRUCT [align 4] */
NdrFcShort ( 0xc ) , /* [size 12] */
0x4b , /* FC_PP */
0x5c , /* FC_PAD */
0x46 , /* FC_NO_REPEAT */
0x5c , /* FC_PAD */
NdrFcShort ( 0x4 ) , /* 4 */
NdrFcShort ( 0x4 ) , /* 4 */
0x13 , 0x8 , /* FC_OP [simple_pointer] */
0x8 , /* FC_LONG */
0x5c , /* FC_PAD */
0x46 , /* FC_NO_REPEAT */
0x5c , /* FC_PAD */
NdrFcShort ( 0x8 ) , /* 8 */
NdrFcShort ( 0x8 ) , /* 8 */
0x13 , 0x8 , /* FC_OP [simple_pointer] */
0x2 , /* FC_CHAR */
0x5c , /* FC_PAD */
0x5b , /* FC_END */
0x8 , /* FC_LONG */
0x8 , /* FC_LONG */
0x8 , /* FC_LONG */
0x5c , /* FC_PAD */
0x5b , /* FC_END */
2009-06-19 12:38:46 +02:00
# endif
2006-05-19 12:47:20 +02:00
} ;
2008-06-14 18:30:40 +02:00
/* zero the entire structure, including the holes */
memset ( & s1 , 0 , sizeof ( s1 ) ) ;
2006-05-19 12:47:20 +02:00
/* FC_STRUCT */
s1 . s = 0x1234 ;
s1 . c = 0xa5 ;
s1 . l1 = 0xdeadbeef ;
s1 . l2 = 0xcafebabe ;
2006-11-09 18:20:49 +01:00
s1 . ll = ( ( LONGLONG ) 0xbadefeed < < 32 ) | 0x2468ace0 ;
2006-05-19 12:47:20 +02:00
wiredatalen = 24 ;
memcpy ( wiredata , & s1 , wiredatalen ) ;
test_simple_struct_marshal ( fmtstr_simple_struct + 4 , & s1 , 24 , wiredata , 24 , NULL , 0 , " struct " ) ;
2008-06-14 17:29:35 +02:00
if ( use_pointer_ids )
* ( unsigned int * ) wiredata = 0x20000 ;
else
2009-05-27 21:18:35 +02:00
* ( unsigned int * ) wiredata = ( UINT_PTR ) & s1 ;
2006-05-19 12:47:20 +02:00
memcpy ( wiredata + 4 , & s1 , wiredatalen ) ;
test_pointer_marshal ( fmtstr_simple_struct , & s1 , 24 , wiredata , 28 , NULL , 0 , " struct " ) ;
2009-06-19 12:38:46 +02:00
if ( sizeof ( void * ) = = 8 ) return ; /* it cannot be represented as a simple struct on Win64 */
2008-06-12 23:57:55 +02:00
/* zero the entire structure, including the hole */
2008-06-14 18:30:40 +02:00
memset ( & ps1 , 0 , sizeof ( ps1 ) ) ;
2008-06-12 23:57:55 +02:00
2006-05-19 12:47:20 +02:00
/* FC_PSTRUCT */
ps1 . l1 = 0xdeadbeef ;
l = 0xcafebabe ;
ps1 . pl1 = & l ;
c = ' a ' ;
ps1 . pc1 = & c ;
2008-06-14 17:29:35 +02:00
* ( unsigned int * ) ( wiredata + 4 ) = 0xdeadbeef ;
if ( use_pointer_ids )
{
* ( unsigned int * ) ( wiredata + 8 ) = 0x20000 ;
* ( unsigned int * ) ( wiredata + 12 ) = 0x20004 ;
}
else
{
2009-05-27 21:18:35 +02:00
* ( unsigned int * ) ( wiredata + 8 ) = ( UINT_PTR ) & l ;
* ( unsigned int * ) ( wiredata + 12 ) = ( UINT_PTR ) & c ;
2008-06-14 17:29:35 +02:00
}
2006-05-19 12:47:20 +02:00
memcpy ( wiredata + 16 , & l , 4 ) ;
memcpy ( wiredata + 20 , & c , 1 ) ;
test_simple_struct_marshal ( fmtstr_pointer_struct + 4 , & ps1 , 17 , wiredata + 4 , 17 , ps1_cmp , 2 , " pointer_struct " ) ;
2008-06-14 17:29:35 +02:00
if ( use_pointer_ids )
2009-05-28 11:41:12 +02:00
{
2008-06-14 17:29:35 +02:00
* ( unsigned int * ) wiredata = 0x20000 ;
2009-05-28 11:41:12 +02:00
* ( unsigned int * ) ( wiredata + 8 ) = 0x20004 ;
* ( unsigned int * ) ( wiredata + 12 ) = 0x20008 ;
}
2008-06-14 17:29:35 +02:00
else
2009-05-27 21:18:35 +02:00
* ( unsigned int * ) wiredata = ( UINT_PTR ) & ps1 ;
2006-05-19 12:47:20 +02:00
test_pointer_marshal ( fmtstr_pointer_struct , & ps1 , 17 , wiredata , 21 , ps1_cmp , 2 , " pointer_struct " ) ;
}
2006-05-17 16:28:38 +02:00
2006-05-26 20:56:00 +02:00
static void test_fullpointer_xlat ( void )
{
PFULL_PTR_XLAT_TABLES pXlatTables ;
2006-11-08 23:46:24 +01:00
ULONG RefId ;
2006-05-26 20:56:00 +02:00
int ret ;
void * Pointer ;
pXlatTables = NdrFullPointerXlatInit ( 2 , XLAT_CLIENT ) ;
/* "marshaling" phase */
ret = NdrFullPointerQueryPointer ( pXlatTables , ( void * ) 0xcafebeef , 1 , & RefId ) ;
ok ( ret = = 0 , " ret should be 0 instead of 0x%x \n " , ret ) ;
2006-11-08 23:46:24 +01:00
ok ( RefId = = 0x1 , " RefId should be 0x1 instead of 0x%x \n " , RefId ) ;
2006-05-26 20:56:00 +02:00
ret = NdrFullPointerQueryPointer ( pXlatTables , ( void * ) 0xcafebeef , 0 , & RefId ) ;
ok ( ret = = 0 , " ret should be 0 instead of 0x%x \n " , ret ) ;
2006-11-08 23:46:24 +01:00
ok ( RefId = = 0x1 , " RefId should be 0x1 instead of 0x%x \n " , RefId ) ;
2006-05-26 20:56:00 +02:00
ret = NdrFullPointerQueryPointer ( pXlatTables , ( void * ) 0xcafebabe , 0 , & RefId ) ;
ok ( ret = = 0 , " ret should be 0 instead of 0x%x \n " , ret ) ;
2006-11-08 23:46:24 +01:00
ok ( RefId = = 0x2 , " RefId should be 0x2 instead of 0x%x \n " , RefId ) ;
2006-05-26 20:56:00 +02:00
ret = NdrFullPointerQueryPointer ( pXlatTables , ( void * ) 0xdeadbeef , 0 , & RefId ) ;
ok ( ret = = 0 , " ret should be 0 instead of 0x%x \n " , ret ) ;
2006-11-08 23:46:24 +01:00
ok ( RefId = = 0x3 , " RefId should be 0x3 instead of 0x%x \n " , RefId ) ;
2006-05-26 20:56:00 +02:00
ret = NdrFullPointerQueryPointer ( pXlatTables , NULL , 0 , & RefId ) ;
ok ( ret = = 1 , " ret should be 1 instead of 0x%x \n " , ret ) ;
2006-11-08 23:46:24 +01:00
ok ( RefId = = 0 , " RefId should be 0 instead of 0x%x \n " , RefId ) ;
2006-05-26 20:56:00 +02:00
/* "unmarshaling" phase */
2009-11-18 12:40:44 +01:00
ret = NdrFullPointerQueryRefId ( pXlatTables , 0x0 , 0 , & Pointer ) ;
ok ( ret = = 1 , " ret should be 1 instead of 0x%x \n " , ret ) ;
2006-05-26 20:56:00 +02:00
ret = NdrFullPointerQueryRefId ( pXlatTables , 0x2 , 0 , & Pointer ) ;
ok ( ret = = 0 , " ret should be 0 instead of 0x%x \n " , ret ) ;
ok ( Pointer = = ( void * ) 0xcafebabe , " Pointer should be 0xcafebabe instead of %p \n " , Pointer ) ;
ret = NdrFullPointerQueryRefId ( pXlatTables , 0x4 , 0 , & Pointer ) ;
ok ( ret = = 0 , " ret should be 0 instead of 0x%x \n " , ret ) ;
ok ( Pointer = = NULL , " Pointer should be NULL instead of %p \n " , Pointer ) ;
NdrFullPointerInsertRefId ( pXlatTables , 0x4 , ( void * ) 0xdeadbabe ) ;
ret = NdrFullPointerQueryRefId ( pXlatTables , 0x4 , 1 , & Pointer ) ;
ok ( ret = = 0 , " ret should be 0 instead of 0x%x \n " , ret ) ;
ok ( Pointer = = ( void * ) 0xdeadbabe , " Pointer should be (void *)0xdeadbabe instead of %p \n " , Pointer ) ;
NdrFullPointerXlatFree ( pXlatTables ) ;
pXlatTables = NdrFullPointerXlatInit ( 2 , XLAT_SERVER ) ;
/* "unmarshaling" phase */
ret = NdrFullPointerQueryRefId ( pXlatTables , 0x2 , 1 , & Pointer ) ;
ok ( ret = = 0 , " ret should be 0 instead of 0x%x \n " , ret ) ;
ok ( Pointer = = NULL , " Pointer should be NULL instead of %p \n " , Pointer ) ;
NdrFullPointerInsertRefId ( pXlatTables , 0x2 , ( void * ) 0xcafebabe ) ;
ret = NdrFullPointerQueryRefId ( pXlatTables , 0x2 , 0 , & Pointer ) ;
ok ( ret = = 0 , " ret should be 0 instead of 0x%x \n " , ret ) ;
ok ( Pointer = = ( void * ) 0xcafebabe , " Pointer should be (void *)0xcafebabe instead of %p \n " , Pointer ) ;
ret = NdrFullPointerQueryRefId ( pXlatTables , 0x2 , 1 , & Pointer ) ;
ok ( ret = = 1 , " ret should be 1 instead of 0x%x \n " , ret ) ;
2006-05-26 20:56:11 +02:00
ok ( Pointer = = ( void * ) 0xcafebabe , " Pointer should be (void *)0xcafebabe instead of %p \n " , Pointer ) ;
2006-05-26 20:56:00 +02:00
/* "marshaling" phase */
ret = NdrFullPointerQueryPointer ( pXlatTables , ( void * ) 0xcafebeef , 1 , & RefId ) ;
ok ( ret = = 0 , " ret should be 0 instead of 0x%x \n " , ret ) ;
2006-11-08 23:46:24 +01:00
ok ( RefId = = 0x3 , " RefId should be 0x3 instead of 0x%x \n " , RefId ) ;
2006-05-26 20:56:00 +02:00
ret = NdrFullPointerQueryPointer ( pXlatTables , ( void * ) 0xcafebeef , 1 , & RefId ) ;
ok ( ret = = 1 , " ret should be 1 instead of 0x%x \n " , ret ) ;
2006-11-08 23:46:24 +01:00
ok ( RefId = = 0x3 , " RefId should be 0x3 instead of 0x%x \n " , RefId ) ;
2006-05-26 20:56:00 +02:00
ret = NdrFullPointerQueryPointer ( pXlatTables , ( void * ) 0xcafebeef , 0 , & RefId ) ;
ok ( ret = = 0 , " ret should be 0 instead of 0x%x \n " , ret ) ;
2006-11-08 23:46:24 +01:00
ok ( RefId = = 0x3 , " RefId should be 0x3 instead of 0x%x \n " , RefId ) ;
2006-05-26 20:56:00 +02:00
ret = NdrFullPointerQueryPointer ( pXlatTables , ( void * ) 0xcafebabe , 0 , & RefId ) ;
ok ( ret = = 0 , " ret should be 0 instead of 0x%x \n " , ret ) ;
2006-11-08 23:46:24 +01:00
ok ( RefId = = 0x2 , " RefId should be 0x2 instead of 0x%x \n " , RefId ) ;
2006-05-26 20:56:00 +02:00
ret = NdrFullPointerQueryPointer ( pXlatTables , ( void * ) 0xdeadbeef , 0 , & RefId ) ;
ok ( ret = = 0 , " ret should be 0 instead of 0x%x \n " , ret ) ;
2006-11-08 23:46:24 +01:00
ok ( RefId = = 0x4 , " RefId should be 0x4 instead of 0x%x \n " , RefId ) ;
2006-05-26 20:56:00 +02:00
/* "freeing" phase */
ret = NdrFullPointerFree ( pXlatTables , ( void * ) 0xcafebeef ) ;
ok ( ret = = 1 , " ret should be 1 instead of 0x%x \n " , ret ) ;
2006-05-29 17:27:16 +02:00
ret = NdrFullPointerQueryPointer ( pXlatTables , ( void * ) 0xcafebeef , 0x20 , & RefId ) ;
ok ( ret = = 1 , " ret should be 1 instead of 0x%x \n " , ret ) ;
2006-11-08 23:46:24 +01:00
ok ( RefId = = 0x3 , " RefId should be 0x3 instead of 0x%x \n " , RefId ) ;
2006-05-29 17:27:16 +02:00
ret = NdrFullPointerQueryPointer ( pXlatTables , ( void * ) 0xcafebeef , 1 , & RefId ) ;
ok ( ret = = 1 , " ret should be 1 instead of 0x%x \n " , ret ) ;
2006-11-08 23:46:24 +01:00
ok ( RefId = = 0x3 , " RefId should be 0x3 instead of 0x%x \n " , RefId ) ;
2006-05-29 17:27:16 +02:00
2006-05-26 20:56:00 +02:00
ret = NdrFullPointerFree ( pXlatTables , ( void * ) 0xcafebabe ) ;
ok ( ret = = 1 , " ret should be 1 instead of 0x%x \n " , ret ) ;
ret = NdrFullPointerFree ( pXlatTables , ( void * ) 0xdeadbeef ) ;
ok ( ret = = 1 , " ret should be 1 instead of 0x%x \n " , ret ) ;
2006-05-29 17:27:16 +02:00
ret = NdrFullPointerQueryPointer ( pXlatTables , ( void * ) 0xdeadbeef , 0x20 , & RefId ) ;
ok ( ret = = 1 , " ret should be 1 instead of 0x%x \n " , ret ) ;
2006-11-08 23:46:24 +01:00
ok ( RefId = = 0x4 , " RefId should be 0x4 instead of 0x%x \n " , RefId ) ;
2006-05-29 17:27:16 +02:00
ret = NdrFullPointerQueryPointer ( pXlatTables , ( void * ) 0xdeadbeef , 1 , & RefId ) ;
ok ( ret = = 0 , " ret should be 0 instead of 0x%x \n " , ret ) ;
2006-11-08 23:46:24 +01:00
ok ( RefId = = 0x4 , " RefId should be 0x4 instead of 0x%x \n " , RefId ) ;
2006-05-29 17:27:16 +02:00
ret = NdrFullPointerQueryPointer ( pXlatTables , ( void * ) 0xdeadbeef , 1 , & RefId ) ;
ok ( ret = = 1 , " ret should be 1 instead of 0x%x \n " , ret ) ;
2006-11-08 23:46:24 +01:00
ok ( RefId = = 0x4 , " RefId should be 0x4 instead of 0x%x \n " , RefId ) ;
2006-05-29 17:27:16 +02:00
ret = NdrFullPointerFree ( pXlatTables , ( void * ) 0xdeadbeef ) ;
ok ( ret = = 0 , " ret should be 0 instead of 0x%x \n " , ret ) ;
2006-05-26 20:56:00 +02:00
NdrFullPointerXlatFree ( pXlatTables ) ;
}
2009-05-28 20:10:15 +02:00
/* verify stub data that is identical between client and server */
static void test_common_stub_data ( const char * prefix , const MIDL_STUB_MESSAGE * stubMsg )
2006-06-01 21:24:34 +02:00
{
2009-05-27 21:18:35 +02:00
void * unset_ptr ;
2006-06-01 21:24:34 +02:00
2009-05-27 21:18:35 +02:00
memset ( & unset_ptr , 0xcc , sizeof ( unset_ptr ) ) ;
2006-06-01 21:24:34 +02:00
2009-05-28 20:10:15 +02:00
# define TEST_ZERO(field, fmt) ok(stubMsg->field == 0, "%s: " #field " should have been set to zero instead of " fmt "\n", prefix, stubMsg->field)
# define TEST_POINTER_UNSET(field) ok(stubMsg->field == unset_ptr, "%s: " #field " should have been unset instead of %p\n", prefix, stubMsg->field)
# define TEST_ULONG_UNSET(field) ok(stubMsg->field == 0xcccccccc, "%s: " #field " should have been unset instead of 0x%x\n", prefix, stubMsg->field)
# 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)
2006-06-01 21:24:34 +02:00
TEST_POINTER_UNSET ( BufferMark ) ;
TEST_ULONG_UNSET ( MemorySize ) ;
TEST_POINTER_UNSET ( Memory ) ;
TEST_ZERO ( pAllocAllNodesContext , " %p " ) ;
2009-05-28 20:10:15 +02:00
ok ( stubMsg - > pPointerQueueState = = 0 | |
broken ( stubMsg - > pPointerQueueState = = unset_ptr ) , /* win2k */
" %s: pPointerQueueState should have been unset instead of %p \n " ,
prefix , stubMsg - > pPointerQueueState ) ;
2006-06-01 21:24:34 +02:00
TEST_ZERO ( IgnoreEmbeddedPointers , " %d " ) ;
TEST_ZERO ( PointerBufferMark , " %p " ) ;
2009-05-28 20:10:15 +02:00
ok ( stubMsg - > uFlags = = 0 | |
broken ( stubMsg - > uFlags = = 0xcc ) , /* win9x */
" %s: uFlags should have been set to zero instead of 0x%x \n " , prefix , stubMsg - > uFlags ) ;
2006-06-01 21:24:34 +02:00
/* FIXME: UniquePtrCount */
2006-11-08 23:46:24 +01:00
TEST_ULONG_PTR_UNSET ( MaxCount ) ;
2006-06-01 21:24:34 +02:00
TEST_ULONG_UNSET ( Offset ) ;
TEST_ULONG_UNSET ( ActualCount ) ;
2009-05-28 20:10:15 +02:00
ok ( stubMsg - > pfnAllocate = = my_alloc , " %s: pfnAllocate should have been %p instead of %p \n " ,
prefix , my_alloc , stubMsg - > pfnAllocate ) ;
ok ( stubMsg - > pfnFree = = my_free , " %s: pfnFree should have been %p instead of %p \n " ,
prefix , my_free , stubMsg - > pfnFree ) ;
2006-06-01 21:24:34 +02:00
TEST_ZERO ( StackTop , " %p " ) ;
TEST_POINTER_UNSET ( pPresentedType ) ;
TEST_POINTER_UNSET ( pTransmitType ) ;
TEST_POINTER_UNSET ( SavedHandle ) ;
2009-05-28 20:10:15 +02:00
ok ( stubMsg - > StubDesc = = & Object_StubDesc , " %s: StubDesc should have been %p instead of %p \n " ,
prefix , & Object_StubDesc , stubMsg - > StubDesc ) ;
2006-11-08 23:46:24 +01:00
TEST_ZERO ( FullPtrRefId , " %d " ) ;
2009-05-28 20:10:15 +02:00
ok ( stubMsg - > PointerLength = = 0 | |
broken ( stubMsg - > PointerLength = = 1 ) , /* win9x, nt4 */
" %s: pAsyncMsg should have been set to zero instead of %d \n " , prefix , stubMsg - > PointerLength ) ;
2006-06-01 21:24:34 +02:00
TEST_ZERO ( fInDontFree , " %d " ) ;
TEST_ZERO ( fDontCallFreeInst , " %d " ) ;
2009-10-09 16:09:20 +02:00
ok ( stubMsg - > fHasReturn = = 0 | | broken ( stubMsg - > fHasReturn ) , /* win9x, nt4 */
2009-05-28 20:10:15 +02:00
" %s: fHasReturn should have been set to zero instead of %d \n " , prefix , stubMsg - > fHasReturn ) ;
2006-06-01 21:24:34 +02:00
TEST_ZERO ( fHasExtensions , " %d " ) ;
TEST_ZERO ( fHasNewCorrDesc , " %d " ) ;
2009-10-09 16:09:20 +02:00
ok ( stubMsg - > fIsIn = = 0 | | broken ( stubMsg - > fIsIn ) , /* win9x, nt4 */
2009-05-28 20:10:15 +02:00
" %s: fIsIn should have been set to 0 instead of %d \n " , prefix , stubMsg - > fIsIn ) ;
2008-06-22 17:17:32 +02:00
TEST_ZERO ( fIsOicf , " %d " ) ;
2009-05-28 20:10:15 +02:00
ok ( stubMsg - > fBufferValid = = 0 ,
" %s: fBufferValid should have been set to 0 instead of %d \n " , prefix , stubMsg - > fBufferValid ) ;
2008-06-22 17:17:32 +02:00
TEST_ZERO ( fNeedMCCP , " %d " ) ;
2009-05-28 20:10:15 +02:00
ok ( stubMsg - > fUnused = = 0 | |
stubMsg - > fUnused = = - 2 , /* Vista */
" %s: fUnused should have been set to 0 or -2 instead of %d \n " , prefix , stubMsg - > fUnused ) ;
ok ( stubMsg - > fUnused2 = = 0xffffcccc , " %s: fUnused2 should have been 0xffffcccc instead of 0x%x \n " ,
prefix , stubMsg - > fUnused2 ) ;
ok ( stubMsg - > dwDestContext = = MSHCTX_DIFFERENTMACHINE ,
" %s: dwDestContext should have been MSHCTX_DIFFERENTMACHINE instead of %d \n " ,
prefix , stubMsg - > dwDestContext ) ;
2006-06-01 21:24:34 +02:00
TEST_ZERO ( pvDestContext , " %p " ) ;
TEST_POINTER_UNSET ( SavedContextHandles ) ;
TEST_ULONG_UNSET ( ParamNumber ) ;
TEST_ZERO ( pRpcChannelBuffer , " %p " ) ;
TEST_ZERO ( pArrayInfo , " %p " ) ;
TEST_POINTER_UNSET ( SizePtrCountArray ) ;
TEST_POINTER_UNSET ( SizePtrOffsetArray ) ;
TEST_POINTER_UNSET ( SizePtrLengthArray ) ;
TEST_POINTER_UNSET ( pArgQueue ) ;
2006-11-08 23:46:24 +01:00
TEST_ZERO ( dwStubPhase , " %d " ) ;
2006-06-01 21:24:34 +02:00
/* FIXME: where does this value come from? */
2009-05-28 20:10:15 +02:00
trace ( " %s: LowStackMark is %p \n " , prefix , stubMsg - > LowStackMark ) ;
ok ( stubMsg - > pAsyncMsg = = 0 | | broken ( stubMsg - > pAsyncMsg = = unset_ptr ) , /* win9x, nt4 */
" %s: pAsyncMsg should have been set to zero instead of %p \n " , prefix , stubMsg - > pAsyncMsg ) ;
ok ( stubMsg - > pCorrInfo = = 0 | | broken ( stubMsg - > pCorrInfo = = unset_ptr ) , /* win9x, nt4 */
" %s: pCorrInfo should have been set to zero instead of %p \n " , prefix , stubMsg - > pCorrInfo ) ;
ok ( stubMsg - > pCorrMemory = = 0 | | broken ( stubMsg - > pCorrMemory = = unset_ptr ) , /* win9x, nt4 */
" %s: pCorrMemory should have been set to zero instead of %p \n " , prefix , stubMsg - > pCorrMemory ) ;
ok ( stubMsg - > pMemoryList = = 0 | | broken ( stubMsg - > pMemoryList = = unset_ptr ) , /* win9x, nt4 */
" %s: pMemoryList should have been set to zero instead of %p \n " , prefix , stubMsg - > pMemoryList ) ;
2006-06-01 21:24:34 +02:00
TEST_POINTER_UNSET ( pCSInfo ) ;
TEST_POINTER_UNSET ( ConformanceMark ) ;
TEST_POINTER_UNSET ( VarianceMark ) ;
2009-05-28 20:10:15 +02:00
ok ( stubMsg - > Unused = = ( ULONG_PTR ) unset_ptr , " %s: Unused should have be unset instead of 0x%lx \n " ,
prefix , stubMsg - > Unused ) ;
2006-06-01 21:24:34 +02:00
TEST_POINTER_UNSET ( pContext ) ;
2007-01-10 16:28:20 +01:00
TEST_POINTER_UNSET ( ContextHandleHash ) ;
TEST_POINTER_UNSET ( pUserMarshalList ) ;
2007-05-24 16:41:17 +02:00
TEST_ULONG_PTR_UNSET ( Reserved51_3 ) ;
TEST_ULONG_PTR_UNSET ( Reserved51_4 ) ;
TEST_ULONG_PTR_UNSET ( Reserved51_5 ) ;
2009-05-28 20:10:15 +02:00
# undef TEST_ULONG_PTR_UNSET
2006-06-01 21:24:34 +02:00
# undef TEST_ULONG_UNSET
# undef TEST_POINTER_UNSET
# undef TEST_ZERO
2009-05-28 20:10:15 +02:00
}
2006-06-01 21:24:34 +02:00
2009-05-28 20:10:15 +02:00
static void test_client_init ( void )
{
MIDL_STUB_MESSAGE stubMsg ;
RPC_MESSAGE rpcMsg ;
void * unset_ptr ;
memset ( & rpcMsg , 0xcc , sizeof ( rpcMsg ) ) ;
memset ( & stubMsg , 0xcc , sizeof ( stubMsg ) ) ;
memset ( & unset_ptr , 0xcc , sizeof ( unset_ptr ) ) ;
NdrClientInitializeNew ( & rpcMsg , & stubMsg , & Object_StubDesc , 1 ) ;
test_common_stub_data ( " NdrClientInitializeNew " , & stubMsg ) ;
ok ( stubMsg . RpcMsg = = & rpcMsg , " stubMsg.RpcMsg should have been %p instead of %p \n " , & rpcMsg , stubMsg . RpcMsg ) ;
ok ( rpcMsg . Handle = = NULL , " rpcMsg.Handle should have been NULL instead of %p \n " , rpcMsg . Handle ) ;
ok ( rpcMsg . Buffer = = unset_ptr , " rpcMsg.Buffer should have been unset instead of %p \n " ,
rpcMsg . Buffer ) ;
ok ( rpcMsg . BufferLength = = 0xcccccccc , " rpcMsg.BufferLength should have been unset instead of %d \n " , rpcMsg . BufferLength ) ;
ok ( rpcMsg . ProcNum = = 0x8001 , " rpcMsg.ProcNum should have been 0x8001 instead of 0x%x \n " , rpcMsg . ProcNum ) ;
ok ( rpcMsg . TransferSyntax = = unset_ptr , " rpcMsg.TransferSyntax should have been unset instead of %p \n " , rpcMsg . TransferSyntax ) ;
ok ( rpcMsg . RpcInterfaceInformation = = Object_StubDesc . RpcInterfaceInformation ,
" rpcMsg.RpcInterfaceInformation should have been %p instead of %p \n " ,
Object_StubDesc . RpcInterfaceInformation , rpcMsg . RpcInterfaceInformation ) ;
/* Note: ReservedForRuntime not tested */
ok ( rpcMsg . ManagerEpv = = unset_ptr , " rpcMsg.ManagerEpv should have been unset instead of %p \n " , rpcMsg . ManagerEpv ) ;
ok ( rpcMsg . ImportContext = = unset_ptr , " rpcMsg.ImportContext should have been unset instead of %p \n " , rpcMsg . ImportContext ) ;
ok ( rpcMsg . RpcFlags = = 0 , " rpcMsg.RpcFlags should have been 0 instead of 0x%x \n " , rpcMsg . RpcFlags ) ;
ok ( stubMsg . Buffer = = unset_ptr , " stubMsg.Buffer should have been unset instead of %p \n " ,
stubMsg . Buffer ) ;
ok ( stubMsg . BufferStart = = NULL , " stubMsg.BufferStart should have been NULL instead of %p \n " ,
stubMsg . BufferStart ) ;
ok ( stubMsg . BufferEnd = = NULL , " stubMsg.BufferEnd should have been NULL instead of %p \n " ,
stubMsg . BufferEnd ) ;
ok ( stubMsg . BufferLength = = 0 , " stubMsg.BufferLength should have been 0 instead of %u \n " ,
stubMsg . BufferLength ) ;
ok ( stubMsg . IsClient = = 1 , " stubMsg.IsClient should have been 1 instead of %u \n " , stubMsg . IsClient ) ;
ok ( stubMsg . ReuseBuffer = = 0 , " stubMsg.ReuseBuffer should have been 0 instead of %d \n " ,
stubMsg . ReuseBuffer ) ;
ok ( stubMsg . CorrDespIncrement = = 0 , " stubMsg.CorrDespIncrement should have been 0 instead of %d \n " ,
stubMsg . CorrDespIncrement ) ;
ok ( stubMsg . FullPtrXlatTables = = unset_ptr , " stubMsg.FullPtrXlatTables should have been unset instead of %p \n " ,
stubMsg . FullPtrXlatTables ) ;
2006-06-01 21:24:34 +02:00
}
2007-12-30 17:46:15 +01:00
static void test_server_init ( void )
{
MIDL_STUB_MESSAGE stubMsg ;
RPC_MESSAGE rpcMsg ;
unsigned char * ret ;
unsigned char buffer [ 256 ] ;
memset ( & rpcMsg , 0 , sizeof ( rpcMsg ) ) ;
rpcMsg . Buffer = buffer ;
rpcMsg . BufferLength = sizeof ( buffer ) ;
rpcMsg . RpcFlags = RPC_BUFFER_COMPLETE ;
memset ( & stubMsg , 0xcc , sizeof ( stubMsg ) ) ;
ret = NdrServerInitializeNew ( & rpcMsg , & stubMsg , & Object_StubDesc ) ;
ok ( ret = = NULL , " NdrServerInitializeNew should have returned NULL instead of %p \n " , ret ) ;
2009-05-28 20:10:15 +02:00
test_common_stub_data ( " NdrServerInitializeNew " , & stubMsg ) ;
2007-12-30 17:46:15 +01:00
ok ( stubMsg . RpcMsg = = & rpcMsg , " stubMsg.RpcMsg should have been %p instead of %p \n " , & rpcMsg , stubMsg . RpcMsg ) ;
ok ( stubMsg . Buffer = = buffer , " stubMsg.Buffer should have been %p instead of %p \n " , buffer , stubMsg . Buffer ) ;
ok ( stubMsg . BufferStart = = buffer , " stubMsg.BufferStart should have been %p instead of %p \n " , buffer , stubMsg . BufferStart ) ;
ok ( stubMsg . BufferEnd = = buffer + sizeof ( buffer ) , " stubMsg.BufferEnd should have been %p instead of %p \n " , buffer + sizeof ( buffer ) , stubMsg . BufferEnd ) ;
todo_wine
2009-05-28 20:10:15 +02:00
ok ( stubMsg . BufferLength = = 0 , " stubMsg.BufferLength should have been 0 instead of %u \n " , stubMsg . BufferLength ) ;
2007-12-30 17:46:15 +01:00
ok ( stubMsg . IsClient = = 0 , " stubMsg.IsClient should have been 0 instead of %u \n " , stubMsg . IsClient ) ;
2008-07-01 07:28:01 +02:00
ok ( stubMsg . ReuseBuffer = = 0 | |
broken ( stubMsg . ReuseBuffer = = 1 ) , /* win2k */
" stubMsg.ReuseBuffer should have been set to zero instead of %d \n " , stubMsg . ReuseBuffer ) ;
2008-08-29 04:17:12 +02:00
ok ( stubMsg . CorrDespIncrement = = 0xcc | |
stubMsg . CorrDespIncrement = = 0 ,
" CorrDespIncrement should have been unset instead of 0x%x \n " , stubMsg . CorrDespIncrement ) ;
2009-05-28 20:10:15 +02:00
ok ( stubMsg . FullPtrXlatTables = = 0 , " stubMsg.BufferLength should have been 0 instead of %p \n " , stubMsg . FullPtrXlatTables ) ;
2007-12-30 17:46:15 +01:00
}
2006-08-16 13:38:20 +02:00
static void test_ndr_allocate ( void )
{
RPC_MESSAGE RpcMessage ;
MIDL_STUB_MESSAGE StubMsg ;
MIDL_STUB_DESC StubDesc ;
void * p1 , * p2 ;
2007-12-12 15:48:28 +01:00
struct tag_mem_list_v2_t
{
DWORD magic ;
DWORD size ;
DWORD unknown ;
struct tag_mem_list_v2_t * next ;
} * mem_list_v2 ;
2006-08-16 13:38:20 +02:00
const DWORD magic_MEML = ' M ' < < 24 | ' E ' < < 16 | ' M ' < < 8 | ' L ' ;
StubDesc = Object_StubDesc ;
NdrClientInitializeNew ( & RpcMessage , & StubMsg , & StubDesc , 0 ) ;
my_alloc_called = my_free_called = 0 ;
p1 = NdrAllocate ( & StubMsg , 10 ) ;
2007-12-12 15:48:28 +01:00
p2 = NdrAllocate ( & StubMsg , 24 ) ;
2006-08-16 13:38:20 +02:00
ok ( my_alloc_called = = 2 , " alloc called %d \n " , my_alloc_called ) ;
2007-12-12 15:48:28 +01:00
ok ( StubMsg . pMemoryList ! = NULL , " StubMsg.pMemoryList NULL \n " ) ;
if ( StubMsg . pMemoryList )
2006-08-16 13:38:20 +02:00
{
2007-12-12 15:48:28 +01:00
mem_list_v2 = StubMsg . pMemoryList ;
if ( mem_list_v2 - > size = = 24 )
{
trace ( " v2 mem list format \n " ) ;
ok ( ( char * ) mem_list_v2 = = ( char * ) p2 + 24 , " expected mem_list_v2 pointer %p, but got %p \n " , ( char * ) p2 + 24 , mem_list_v2 ) ;
ok ( mem_list_v2 - > magic = = magic_MEML , " magic %08x \n " , mem_list_v2 - > magic ) ;
ok ( mem_list_v2 - > size = = 24 , " wrong size for p2 %d \n " , mem_list_v2 - > size ) ;
ok ( mem_list_v2 - > unknown = = 0 , " wrong unknown for p2 0x%x \n " , mem_list_v2 - > unknown ) ;
ok ( mem_list_v2 - > next ! = NULL , " next NULL \n " ) ;
mem_list_v2 = mem_list_v2 - > next ;
if ( mem_list_v2 )
{
ok ( ( char * ) mem_list_v2 = = ( char * ) p1 + 16 , " expected mem_list_v2 pointer %p, but got %p \n " , ( char * ) p1 + 16 , mem_list_v2 ) ;
ok ( mem_list_v2 - > magic = = magic_MEML , " magic %08x \n " , mem_list_v2 - > magic ) ;
ok ( mem_list_v2 - > size = = 16 , " wrong size for p1 %d \n " , mem_list_v2 - > size ) ;
ok ( mem_list_v2 - > unknown = = 0 , " wrong unknown for p1 0x%x \n " , mem_list_v2 - > unknown ) ;
ok ( mem_list_v2 - > next = = NULL , " next %p \n " , mem_list_v2 - > next ) ;
}
}
2009-05-28 20:18:34 +02:00
else win_skip ( " v1 mem list format \n " ) ;
2006-08-16 13:38:20 +02:00
}
/* NdrFree isn't exported so we can't test free'ing */
}
2007-03-12 15:08:52 +01:00
static void test_conformant_array ( void )
{
RPC_MESSAGE RpcMessage ;
MIDL_STUB_MESSAGE StubMsg ;
MIDL_STUB_DESC StubDesc ;
void * ptr ;
unsigned char * mem , * mem_orig ;
unsigned char memsrc [ 20 ] ;
2008-06-12 23:58:49 +02:00
unsigned int i ;
2007-03-12 15:08:52 +01:00
static const unsigned char fmtstr_conf_array [ ] =
{
0x1b , /* FC_CARRAY */
0x0 , /* align */
NdrFcShort ( 0x1 ) , /* elem size */
0x40 , /* Corr desc: const */
0x0 ,
NdrFcShort ( 0x10 ) , /* const = 0x10 */
0x1 , /* FC_BYTE */
0x5b /* FC_END */
} ;
2008-06-12 23:58:49 +02:00
for ( i = 0 ; i < sizeof ( memsrc ) ; i + + )
memsrc [ i ] = i * i ;
2007-03-12 15:08:52 +01:00
StubDesc = Object_StubDesc ;
StubDesc . pFormatTypes = fmtstr_conf_array ;
NdrClientInitializeNew (
& RpcMessage ,
& StubMsg ,
& StubDesc ,
0 ) ;
StubMsg . BufferLength = 0 ;
NdrConformantArrayBufferSize ( & StubMsg ,
memsrc ,
fmtstr_conf_array ) ;
ok ( StubMsg . BufferLength > = 20 , " length %d \n " , StubMsg . BufferLength ) ;
/*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
StubMsg . RpcMsg - > Buffer = StubMsg . BufferStart = StubMsg . Buffer = HeapAlloc ( GetProcessHeap ( ) , 0 , StubMsg . BufferLength ) ;
StubMsg . BufferEnd = StubMsg . BufferStart + StubMsg . BufferLength ;
ptr = NdrConformantArrayMarshall ( & StubMsg , memsrc , fmtstr_conf_array ) ;
ok ( ptr = = NULL , " ret %p \n " , ptr ) ;
ok ( StubMsg . Buffer - StubMsg . BufferStart = = 20 , " Buffer %p Start %p len %d \n " , StubMsg . Buffer , StubMsg . BufferStart , 20 ) ;
ok ( ! memcmp ( StubMsg . BufferStart + 4 , memsrc , 16 ) , " incorrectly marshaled \n " ) ;
StubMsg . Buffer = StubMsg . BufferStart ;
StubMsg . MemorySize = 0 ;
mem = NULL ;
/* Client */
my_alloc_called = 0 ;
/* passing mem == NULL with must_alloc == 0 crashes under Windows */
NdrConformantArrayUnmarshall ( & StubMsg , & mem , fmtstr_conf_array , 1 ) ;
ok ( mem ! = NULL , " mem not alloced \n " ) ;
ok ( mem ! = StubMsg . BufferStart + 4 , " mem pointing at buffer \n " ) ;
ok ( my_alloc_called = = 1 , " alloc called %d \n " , my_alloc_called ) ;
my_alloc_called = 0 ;
StubMsg . Buffer = StubMsg . BufferStart ;
mem_orig = mem ;
NdrConformantArrayUnmarshall ( & StubMsg , & mem , fmtstr_conf_array , 0 ) ;
ok ( mem = = mem_orig , " mem alloced \n " ) ;
ok ( mem ! = StubMsg . BufferStart + 4 , " mem pointing at buffer \n " ) ;
ok ( my_alloc_called = = 0 , " alloc called %d \n " , my_alloc_called ) ;
my_alloc_called = 0 ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrConformantArrayUnmarshall ( & StubMsg , & mem , fmtstr_conf_array , 1 ) ;
ok ( mem ! = mem_orig , " mem not alloced \n " ) ;
ok ( mem ! = StubMsg . BufferStart + 4 , " mem pointing at buffer \n " ) ;
ok ( my_alloc_called = = 1 , " alloc called %d \n " , my_alloc_called ) ;
my_free_called = 0 ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrConformantArrayFree ( & StubMsg , mem , fmtstr_conf_array ) ;
ok ( my_free_called = = 0 , " free called %d \n " , my_free_called ) ;
StubMsg . pfnFree ( mem ) ;
/* Server */
my_alloc_called = 0 ;
StubMsg . IsClient = 0 ;
mem = NULL ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrConformantArrayUnmarshall ( & StubMsg , & mem , fmtstr_conf_array , 0 ) ;
2009-06-01 14:36:10 +02:00
ok ( mem = = StubMsg . BufferStart + 4 | | broken ( ! mem ) , /* win9x, nt4 */
" mem not pointing at buffer %p/%p \n " , mem , StubMsg . BufferStart + 4 ) ;
2007-03-12 15:08:52 +01:00
ok ( my_alloc_called = = 0 , " alloc called %d \n " , my_alloc_called ) ;
my_alloc_called = 0 ;
mem = NULL ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrConformantArrayUnmarshall ( & StubMsg , & mem , fmtstr_conf_array , 1 ) ;
ok ( mem ! = StubMsg . BufferStart + 4 , " mem pointing at buffer \n " ) ;
ok ( my_alloc_called = = 1 , " alloc called %d \n " , my_alloc_called ) ;
StubMsg . pfnFree ( mem ) ;
my_alloc_called = 0 ;
mem = mem_orig ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrConformantArrayUnmarshall ( & StubMsg , & mem , fmtstr_conf_array , 0 ) ;
ok ( mem = = mem_orig , " mem alloced \n " ) ;
ok ( my_alloc_called = = 0 , " alloc called %d \n " , my_alloc_called ) ;
my_alloc_called = 0 ;
mem = mem_orig ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrConformantArrayUnmarshall ( & StubMsg , & mem , fmtstr_conf_array , 1 ) ;
ok ( mem ! = StubMsg . BufferStart + 4 , " mem pointing at buffer \n " ) ;
ok ( my_alloc_called = = 1 , " alloc called %d \n " , my_alloc_called ) ;
StubMsg . pfnFree ( mem ) ;
StubMsg . pfnFree ( mem_orig ) ;
HeapFree ( GetProcessHeap ( ) , 0 , StubMsg . RpcMsg - > Buffer ) ;
}
2007-12-04 14:23:09 +01:00
static void test_conformant_string ( void )
{
RPC_MESSAGE RpcMessage ;
MIDL_STUB_MESSAGE StubMsg ;
MIDL_STUB_DESC StubDesc ;
2009-01-08 13:02:40 +01:00
DWORD size ;
2007-12-04 14:23:09 +01:00
void * ptr ;
unsigned char * mem , * mem_orig ;
char memsrc [ ] = " This is a test string " ;
static const unsigned char fmtstr_conf_str [ ] =
{
0x11 , 0x8 , /* FC_RP [simple_pointer] */
0x22 , /* FC_C_CSTRING */
0x5c , /* FC_PAD */
} ;
StubDesc = Object_StubDesc ;
StubDesc . pFormatTypes = fmtstr_conf_str ;
2009-06-01 14:36:10 +02:00
memset ( & StubMsg , 0 , sizeof ( StubMsg ) ) ; /* needed on win9x and nt4 */
2007-12-04 14:23:09 +01:00
NdrClientInitializeNew (
& RpcMessage ,
& StubMsg ,
& StubDesc ,
0 ) ;
StubMsg . BufferLength = 0 ;
NdrPointerBufferSize ( & StubMsg ,
( unsigned char * ) memsrc ,
fmtstr_conf_str ) ;
ok ( StubMsg . BufferLength > = sizeof ( memsrc ) + 12 , " length %d \n " , StubMsg . BufferLength ) ;
/*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
StubMsg . RpcMsg - > Buffer = StubMsg . BufferStart = StubMsg . Buffer = HeapAlloc ( GetProcessHeap ( ) , 0 , StubMsg . BufferLength ) ;
StubMsg . BufferEnd = StubMsg . BufferStart + StubMsg . BufferLength ;
ptr = NdrPointerMarshall ( & StubMsg , ( unsigned char * ) memsrc , fmtstr_conf_str ) ;
ok ( ptr = = NULL , " ret %p \n " , ptr ) ;
2009-01-08 13:02:40 +01:00
size = StubMsg . Buffer - StubMsg . BufferStart ;
ok ( size = = sizeof ( memsrc ) + 12 , " Buffer %p Start %p len %d \n " ,
StubMsg . Buffer , StubMsg . BufferStart , size ) ;
2007-12-04 14:23:09 +01:00
ok ( ! memcmp ( StubMsg . BufferStart + 12 , memsrc , sizeof ( memsrc ) ) , " incorrectly marshaled \n " ) ;
StubMsg . Buffer = StubMsg . BufferStart ;
StubMsg . MemorySize = 0 ;
mem = NULL ;
/* Client */
my_alloc_called = 0 ;
StubMsg . Buffer = StubMsg . BufferStart ;
mem = mem_orig = HeapAlloc ( GetProcessHeap ( ) , 0 , sizeof ( memsrc ) ) ;
2010-10-08 11:12:11 +02:00
/* Windows apparently checks string length on the output buffer to determine its size... */
memset ( mem , ' x ' , sizeof ( memsrc ) - 1 ) ;
mem [ sizeof ( memsrc ) - 1 ] = 0 ;
2007-12-04 14:23:09 +01:00
NdrPointerUnmarshall ( & StubMsg , & mem , fmtstr_conf_str , 0 ) ;
ok ( mem = = mem_orig , " mem not alloced \n " ) ;
ok ( my_alloc_called = = 0 , " alloc called %d \n " , my_alloc_called ) ;
my_alloc_called = 0 ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrPointerUnmarshall ( & StubMsg , & mem , fmtstr_conf_str , 1 ) ;
todo_wine {
ok ( mem = = mem_orig , " mem not alloced \n " ) ;
ok ( my_alloc_called = = 0 , " alloc called %d \n " , my_alloc_called ) ;
}
my_free_called = 0 ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrPointerFree ( & StubMsg , mem , fmtstr_conf_str ) ;
ok ( my_free_called = = 1 , " free called %d \n " , my_free_called ) ;
2007-12-13 13:40:27 +01:00
mem = my_alloc ( 10 ) ;
my_free_called = 0 ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrPointerFree ( & StubMsg , mem , fmtstr_conf_str ) ;
ok ( my_free_called = = 1 , " free called %d \n " , my_free_called ) ;
2007-12-04 14:23:09 +01:00
/* Server */
my_alloc_called = 0 ;
StubMsg . IsClient = 0 ;
mem = NULL ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrPointerUnmarshall ( & StubMsg , & mem , fmtstr_conf_str , 0 ) ;
2009-06-01 14:36:10 +02:00
ok ( mem = = StubMsg . BufferStart + 12 | | broken ( ! mem ) , /* win9x, nt4 */
" mem not pointing at buffer %p/%p \n " , mem , StubMsg . BufferStart + 12 ) ;
2007-12-04 14:23:09 +01:00
ok ( my_alloc_called = = 0 , " alloc called %d \n " , my_alloc_called ) ;
2007-12-15 14:57:21 +01:00
2007-12-04 14:23:09 +01:00
my_alloc_called = 0 ;
mem = NULL ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrPointerUnmarshall ( & StubMsg , & mem , fmtstr_conf_str , 1 ) ;
todo_wine {
2009-06-01 14:36:10 +02:00
ok ( mem = = StubMsg . BufferStart + 12 | | broken ( ! mem ) , /* win9x, nt4 */
" mem not pointing at buffer %p/%p \n " , mem , StubMsg . BufferStart + 12 ) ;
2007-12-04 14:23:09 +01:00
ok ( my_alloc_called = = 0 , " alloc called %d \n " , my_alloc_called ) ;
}
my_alloc_called = 0 ;
2009-06-19 12:38:46 +02:00
mem = mem_orig = HeapAlloc ( GetProcessHeap ( ) , 0 , sizeof ( memsrc ) ) ;
2007-12-04 14:23:09 +01:00
StubMsg . Buffer = StubMsg . BufferStart ;
NdrPointerUnmarshall ( & StubMsg , & mem , fmtstr_conf_str , 0 ) ;
2009-06-01 14:36:10 +02:00
ok ( mem = = StubMsg . BufferStart + 12 | | broken ( ! mem ) , /* win9x, nt4 */
" mem not pointing at buffer %p/%p \n " , mem , StubMsg . BufferStart + 12 ) ;
2007-12-04 14:23:09 +01:00
ok ( my_alloc_called = = 0 , " alloc called %d \n " , my_alloc_called ) ;
my_alloc_called = 0 ;
mem = mem_orig ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrPointerUnmarshall ( & StubMsg , & mem , fmtstr_conf_str , 1 ) ;
todo_wine {
2009-06-01 14:36:10 +02:00
ok ( mem = = StubMsg . BufferStart + 12 | | broken ( ! mem ) , /* win9x, nt4 */
" mem not pointing at buffer %p/%p \n " , mem , StubMsg . BufferStart + 12 ) ;
2007-12-04 14:23:09 +01:00
ok ( my_alloc_called = = 0 , " alloc called %d \n " , my_alloc_called ) ;
}
2007-12-13 13:40:27 +01:00
mem = my_alloc ( 10 ) ;
my_free_called = 0 ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrPointerFree ( & StubMsg , mem , fmtstr_conf_str ) ;
ok ( my_free_called = = 1 , " free called %d \n " , my_free_called ) ;
2007-12-04 14:23:09 +01:00
HeapFree ( GetProcessHeap ( ) , 0 , mem_orig ) ;
HeapFree ( GetProcessHeap ( ) , 0 , StubMsg . RpcMsg - > Buffer ) ;
}
2007-12-29 13:17:55 +01:00
static void test_nonconformant_string ( void )
{
RPC_MESSAGE RpcMessage ;
MIDL_STUB_MESSAGE StubMsg ;
MIDL_STUB_DESC StubDesc ;
2009-01-08 13:02:40 +01:00
DWORD size ;
2007-12-29 13:17:55 +01:00
void * ptr ;
unsigned char * mem , * mem_orig ;
unsigned char memsrc [ 10 ] = " This is " ;
unsigned char memsrc2 [ 10 ] = " This is a " ;
static const unsigned char fmtstr_nonconf_str [ ] =
{
0x26 , /* FC_CSTRING */
0x5c , /* FC_PAD */
NdrFcShort ( 0xa ) , /* 10 */
} ;
StubDesc = Object_StubDesc ;
StubDesc . pFormatTypes = fmtstr_nonconf_str ;
/* length < size */
NdrClientInitializeNew (
& RpcMessage ,
& StubMsg ,
& StubDesc ,
0 ) ;
StubMsg . BufferLength = 0 ;
2009-02-16 09:54:10 +01:00
NdrNonConformantStringBufferSize ( & StubMsg , memsrc , fmtstr_nonconf_str ) ;
2007-12-29 13:17:55 +01:00
ok ( StubMsg . BufferLength > = strlen ( ( char * ) memsrc ) + 1 + 8 , " length %d \n " , StubMsg . BufferLength ) ;
/*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
StubMsg . RpcMsg - > Buffer = StubMsg . BufferStart = StubMsg . Buffer = HeapAlloc ( GetProcessHeap ( ) , 0 , StubMsg . BufferLength ) ;
StubMsg . BufferEnd = StubMsg . BufferStart + StubMsg . BufferLength ;
2009-02-16 09:54:10 +01:00
ptr = NdrNonConformantStringMarshall ( & StubMsg , memsrc , fmtstr_nonconf_str ) ;
2007-12-29 13:17:55 +01:00
ok ( ptr = = NULL , " ret %p \n " , ptr ) ;
2009-01-08 13:02:40 +01:00
size = StubMsg . Buffer - StubMsg . BufferStart ;
ok ( size = = strlen ( ( char * ) memsrc ) + 1 + 8 , " Buffer %p Start %p len %d \n " ,
StubMsg . Buffer , StubMsg . BufferStart , size ) ;
2007-12-29 13:17:55 +01:00
ok ( ! memcmp ( StubMsg . BufferStart + 8 , memsrc , strlen ( ( char * ) memsrc ) + 1 ) , " incorrectly marshaled \n " ) ;
StubMsg . Buffer = StubMsg . BufferStart ;
StubMsg . MemorySize = 0 ;
mem = NULL ;
/* Client */
my_alloc_called = 0 ;
StubMsg . Buffer = StubMsg . BufferStart ;
mem = mem_orig = HeapAlloc ( GetProcessHeap ( ) , 0 , sizeof ( memsrc ) ) ;
NdrNonConformantStringUnmarshall ( & StubMsg , & mem , fmtstr_nonconf_str , 0 ) ;
ok ( mem = = mem_orig , " mem alloced \n " ) ;
ok ( my_alloc_called = = 0 , " alloc called %d \n " , my_alloc_called ) ;
my_alloc_called = 0 ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrNonConformantStringUnmarshall ( & StubMsg , & mem , fmtstr_nonconf_str , 1 ) ;
todo_wine
ok ( mem = = mem_orig , " mem alloced \n " ) ;
todo_wine
ok ( my_alloc_called = = 0 , " alloc called %d \n " , my_alloc_called ) ;
/* Server */
my_alloc_called = 0 ;
StubMsg . IsClient = 0 ;
mem = NULL ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrNonConformantStringUnmarshall ( & StubMsg , & mem , fmtstr_nonconf_str , 0 ) ;
ok ( mem ! = mem_orig , " mem not alloced \n " ) ;
ok ( mem ! = StubMsg . BufferStart + 8 , " mem pointing at buffer \n " ) ;
ok ( my_alloc_called = = 1 , " alloc called %d \n " , my_alloc_called ) ;
NdrOleFree ( mem ) ;
my_alloc_called = 0 ;
mem = mem_orig ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrNonConformantStringUnmarshall ( & StubMsg , & mem , fmtstr_nonconf_str , 0 ) ;
ok ( mem = = mem_orig , " mem alloced \n " ) ;
ok ( my_alloc_called = = 0 , " alloc called %d \n " , my_alloc_called ) ;
my_alloc_called = 0 ;
mem = mem_orig ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrNonConformantStringUnmarshall ( & StubMsg , & mem , fmtstr_nonconf_str , 1 ) ;
todo_wine
ok ( mem = = mem_orig , " mem alloced \n " ) ;
todo_wine
ok ( my_alloc_called = = 0 , " alloc called %d \n " , my_alloc_called ) ;
HeapFree ( GetProcessHeap ( ) , 0 , mem_orig ) ;
HeapFree ( GetProcessHeap ( ) , 0 , StubMsg . RpcMsg - > Buffer ) ;
/* length = size */
NdrClientInitializeNew (
& RpcMessage ,
& StubMsg ,
& StubDesc ,
0 ) ;
StubMsg . BufferLength = 0 ;
2009-02-16 09:54:10 +01:00
NdrNonConformantStringBufferSize ( & StubMsg , memsrc2 , fmtstr_nonconf_str ) ;
2007-12-29 13:17:55 +01:00
ok ( StubMsg . BufferLength > = strlen ( ( char * ) memsrc2 ) + 1 + 8 , " length %d \n " , StubMsg . BufferLength ) ;
/*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
StubMsg . RpcMsg - > Buffer = StubMsg . BufferStart = StubMsg . Buffer = HeapAlloc ( GetProcessHeap ( ) , 0 , StubMsg . BufferLength ) ;
StubMsg . BufferEnd = StubMsg . BufferStart + StubMsg . BufferLength ;
2009-02-16 09:54:10 +01:00
ptr = NdrNonConformantStringMarshall ( & StubMsg , memsrc2 , fmtstr_nonconf_str ) ;
2007-12-29 13:17:55 +01:00
ok ( ptr = = NULL , " ret %p \n " , ptr ) ;
2009-01-08 13:02:40 +01:00
size = StubMsg . Buffer - StubMsg . BufferStart ;
ok ( size = = strlen ( ( char * ) memsrc2 ) + 1 + 8 , " Buffer %p Start %p len %d \n " ,
StubMsg . Buffer , StubMsg . BufferStart , size ) ;
2007-12-29 13:17:55 +01:00
ok ( ! memcmp ( StubMsg . BufferStart + 8 , memsrc2 , strlen ( ( char * ) memsrc2 ) + 1 ) , " incorrectly marshaled \n " ) ;
StubMsg . Buffer = StubMsg . BufferStart ;
StubMsg . MemorySize = 0 ;
mem = NULL ;
/* Client */
my_alloc_called = 0 ;
StubMsg . Buffer = StubMsg . BufferStart ;
mem = mem_orig = HeapAlloc ( GetProcessHeap ( ) , 0 , sizeof ( memsrc ) ) ;
NdrNonConformantStringUnmarshall ( & StubMsg , & mem , fmtstr_nonconf_str , 0 ) ;
ok ( mem = = mem_orig , " mem alloced \n " ) ;
ok ( my_alloc_called = = 0 , " alloc called %d \n " , my_alloc_called ) ;
my_alloc_called = 0 ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrNonConformantStringUnmarshall ( & StubMsg , & mem , fmtstr_nonconf_str , 1 ) ;
todo_wine
ok ( mem = = mem_orig , " mem alloced \n " ) ;
todo_wine
ok ( my_alloc_called = = 0 , " alloc called %d \n " , my_alloc_called ) ;
/* Server */
my_alloc_called = 0 ;
StubMsg . IsClient = 0 ;
mem = NULL ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrNonConformantStringUnmarshall ( & StubMsg , & mem , fmtstr_nonconf_str , 0 ) ;
ok ( mem ! = mem_orig , " mem not alloced \n " ) ;
ok ( mem ! = StubMsg . BufferStart + 8 , " mem pointing at buffer \n " ) ;
ok ( my_alloc_called = = 1 , " alloc called %d \n " , my_alloc_called ) ;
NdrOleFree ( mem ) ;
my_alloc_called = 0 ;
mem = mem_orig ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrNonConformantStringUnmarshall ( & StubMsg , & mem , fmtstr_nonconf_str , 0 ) ;
ok ( mem = = mem_orig , " mem alloced \n " ) ;
ok ( my_alloc_called = = 0 , " alloc called %d \n " , my_alloc_called ) ;
my_alloc_called = 0 ;
mem = mem_orig ;
StubMsg . Buffer = StubMsg . BufferStart ;
NdrNonConformantStringUnmarshall ( & StubMsg , & mem , fmtstr_nonconf_str , 1 ) ;
todo_wine
ok ( mem = = mem_orig , " mem alloced \n " ) ;
todo_wine
ok ( my_alloc_called = = 0 , " alloc called %d \n " , my_alloc_called ) ;
HeapFree ( GetProcessHeap ( ) , 0 , mem_orig ) ;
HeapFree ( GetProcessHeap ( ) , 0 , StubMsg . RpcMsg - > Buffer ) ;
}
2008-08-10 12:14:17 +02:00
static void test_conf_complex_struct ( void )
{
RPC_MESSAGE RpcMessage ;
MIDL_STUB_MESSAGE StubMsg ;
MIDL_STUB_DESC StubDesc ;
void * ptr ;
unsigned int i ;
struct conf_complex
{
unsigned int size ;
unsigned int * array [ 1 ] ;
} ;
struct conf_complex * memsrc ;
struct conf_complex * mem ;
static const unsigned char fmtstr_complex_struct [ ] =
{
/* 0 */
0x1b , /* FC_CARRAY */
0x3 , /* 3 */
/* 2 */ NdrFcShort ( 0x4 ) , /* 4 */
/* 4 */ 0x8 , /* Corr desc: FC_LONG */
0x0 , /* */
/* 6 */ NdrFcShort ( 0xfffc ) , /* -4 */
/* 8 */
0x4b , /* FC_PP */
0x5c , /* FC_PAD */
/* 10 */
0x48 , /* FC_VARIABLE_REPEAT */
0x49 , /* FC_FIXED_OFFSET */
/* 12 */ NdrFcShort ( 0x4 ) , /* 4 */
/* 14 */ NdrFcShort ( 0x0 ) , /* 0 */
/* 16 */ NdrFcShort ( 0x1 ) , /* 1 */
/* 18 */ NdrFcShort ( 0x0 ) , /* 0 */
/* 20 */ NdrFcShort ( 0x0 ) , /* 0 */
/* 22 */ 0x12 , 0x8 , /* FC_UP [simple_pointer] */
/* 24 */ 0x8 , /* FC_LONG */
0x5c , /* FC_PAD */
/* 26 */
0x5b , /* FC_END */
0x8 , /* FC_LONG */
/* 28 */ 0x5c , /* FC_PAD */
0x5b , /* FC_END */
/* 30 */
0x1a , /* FC_BOGUS_STRUCT */
0x3 , /* 3 */
/* 32 */ NdrFcShort ( 0x4 ) , /* 4 */
/* 34 */ NdrFcShort ( 0xffffffde ) , /* Offset= -34 (0) */
/* 36 */ NdrFcShort ( 0x0 ) , /* Offset= 0 (36) */
/* 38 */ 0x8 , /* FC_LONG */
0x5b , /* FC_END */
} ;
memsrc = HeapAlloc ( GetProcessHeap ( ) , HEAP_ZERO_MEMORY ,
FIELD_OFFSET ( struct conf_complex , array [ 20 ] ) ) ;
memsrc - > size = 20 ;
StubDesc = Object_StubDesc ;
StubDesc . pFormatTypes = fmtstr_complex_struct ;
NdrClientInitializeNew (
& RpcMessage ,
& StubMsg ,
& StubDesc ,
0 ) ;
StubMsg . BufferLength = 0 ;
NdrComplexStructBufferSize ( & StubMsg ,
( unsigned char * ) memsrc ,
& fmtstr_complex_struct [ 30 ] ) ;
ok ( StubMsg . BufferLength > = 28 , " length %d \n " , StubMsg . BufferLength ) ;
/*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
StubMsg . RpcMsg - > Buffer = StubMsg . BufferStart = StubMsg . Buffer = HeapAlloc ( GetProcessHeap ( ) , 0 , StubMsg . BufferLength ) ;
StubMsg . BufferEnd = StubMsg . BufferStart + StubMsg . BufferLength ;
ptr = NdrComplexStructMarshall ( & StubMsg , ( unsigned char * ) memsrc ,
& fmtstr_complex_struct [ 30 ] ) ;
ok ( ptr = = NULL , " ret %p \n " , ptr ) ;
2009-01-08 13:02:40 +01:00
ok ( * ( unsigned int * ) StubMsg . BufferStart = = 20 , " Conformance should have been 20 instead of %d \n " , * ( unsigned int * ) StubMsg . BufferStart ) ;
ok ( * ( unsigned int * ) ( StubMsg . BufferStart + 4 ) = = 20 , " conf_complex.size should have been 20 instead of %d \n " , * ( unsigned int * ) ( StubMsg . BufferStart + 4 ) ) ;
2008-08-10 12:14:17 +02:00
for ( i = 0 ; i < 20 ; i + + )
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 ) ) ;
/* Server */
my_alloc_called = 0 ;
StubMsg . IsClient = 0 ;
mem = NULL ;
StubMsg . Buffer = StubMsg . BufferStart ;
ptr = NdrComplexStructUnmarshall ( & StubMsg , ( unsigned char * * ) & mem , & fmtstr_complex_struct [ 30 ] , 0 ) ;
ok ( ptr = = NULL , " ret %p \n " , ptr ) ;
ok ( mem - > size = = 20 , " mem->size wasn't unmarshalled correctly (%d) \n " , mem - > size ) ;
ok ( mem - > array [ 0 ] = = NULL , " mem->array[0] wasn't unmarshalled correctly (%p) \n " , mem - > array [ 0 ] ) ;
StubMsg . pfnFree ( mem ) ;
HeapFree ( GetProcessHeap ( ) , 0 , StubMsg . RpcMsg - > Buffer ) ;
2009-11-29 11:31:29 +01:00
HeapFree ( GetProcessHeap ( ) , 0 , memsrc ) ;
2008-08-10 12:14:17 +02:00
}
2010-02-11 17:18:55 +01:00
static void test_conf_complex_array ( void )
{
RPC_MESSAGE RpcMessage ;
MIDL_STUB_MESSAGE StubMsg ;
MIDL_STUB_DESC StubDesc ;
void * ptr ;
unsigned int i , j ;
struct conf_complex
{
unsigned int dim1 , dim2 ;
DWORD * * array ;
} ;
struct conf_complex memsrc ;
struct conf_complex * mem ;
DWORD * buf , expected_length ;
static const unsigned char fmtstr_complex_array [ ] =
{
/* 0 */ 0x21 , /* FC_BOGUS_ARRAY */
0x3 , /* 3 */
/* 2 */ NdrFcShort ( 0x0 ) , /* 0 */
/* 4 */ 0x19 , 0x0 , /* Corr desc: field pointer, FC_ULONG */
/* 6 */ NdrFcShort ( 0x4 ) , /* 4 */
/* 8 */ NdrFcLong ( 0xffffffff ) , /* -1 */
/* 12 */ 0x8 , /* FC_LONG */
0x5b , /* FC_END */
/* 14 */
0x21 , /* FC_BOGUS_ARRAY */
0x3 , /* 3 */
/* 16 */ NdrFcShort ( 0x0 ) , /* 0 */
/* 18 */ 0x19 , /* Corr desc: field pointer, FC_ULONG */
0x0 , /* */
/* 20 */ NdrFcShort ( 0x0 ) , /* 0 */
/* 22 */ NdrFcLong ( 0xffffffff ) , /* -1 */
/* 26 */ 0x12 , 0x0 , /* FC_UP */
/* 28 */ NdrFcShort ( 0xffe4 ) , /* Offset= -28 (0) */
/* 30 */ 0x5c , /* FC_PAD */
0x5b , /* FC_END */
2010-02-12 17:34:14 +01:00
# ifdef _WIN64
/* 32 */ 0x1a , /* FC_BOGUS_STRUCT */
0x3 , /* 3 */
/* 34 */ NdrFcShort ( 0x10 ) , /* 16 */
/* 36 */ NdrFcShort ( 0x0 ) , /* 0 */
/* 38 */ NdrFcShort ( 0x6 ) , /* Offset= 6 (44) */
/* 40 */ 0x8 , /* FC_LONG */
0x8 , /* FC_LONG */
/* 42 */ 0x36 , /* FC_POINTER */
0x5b , /* FC_END */
/* 44 */
0x12 , 0x0 , /* FC_UP */
/* 46 */ NdrFcShort ( 0xffe0 ) , /* Offset= -32 (14) */
# else
2010-02-11 17:18:55 +01:00
/* 32 */
0x16 , /* FC_PSTRUCT */
0x3 , /* 3 */
/* 34 */ NdrFcShort ( 0xc ) , /* 12 */
/* 36 */ 0x4b , /* FC_PP */
0x5c , /* FC_PAD */
/* 38 */ 0x46 , /* FC_NO_REPEAT */
0x5c , /* FC_PAD */
/* 40 */ NdrFcShort ( 0x8 ) , /* 8 */
/* 42 */ NdrFcShort ( 0x8 ) , /* 8 */
/* 44 */ 0x12 , 0x0 , /* FC_UP */
/* 46 */ NdrFcShort ( 0xffe0 ) , /* Offset= -32 (14) */
/* 48 */ 0x5b , /* FC_END */
0x8 , /* FC_LONG */
/* 50 */ 0x8 , /* FC_LONG */
0x8 , /* FC_LONG */
/* 52 */ 0x5c , /* FC_PAD */
0x5b , /* FC_END */
2010-02-12 17:34:14 +01:00
# endif
2010-02-11 17:18:55 +01:00
} ;
memsrc . dim1 = 5 ;
memsrc . dim2 = 3 ;
memsrc . array = HeapAlloc ( GetProcessHeap ( ) , HEAP_ZERO_MEMORY , memsrc . dim1 * sizeof ( DWORD * ) ) ;
for ( i = 0 ; i < memsrc . dim1 ; i + + )
{
memsrc . array [ i ] = HeapAlloc ( GetProcessHeap ( ) , HEAP_ZERO_MEMORY , memsrc . dim2 * sizeof ( DWORD ) ) ;
for ( j = 0 ; j < memsrc . dim2 ; j + + )
memsrc . array [ i ] [ j ] = i * memsrc . dim2 + j ;
}
StubDesc = Object_StubDesc ;
StubDesc . pFormatTypes = fmtstr_complex_array ;
NdrClientInitializeNew (
& RpcMessage ,
& StubMsg ,
& StubDesc ,
0 ) ;
StubMsg . BufferLength = 0 ;
2010-02-12 17:34:14 +01:00
# ifdef _WIN64
NdrComplexStructBufferSize ( & StubMsg ,
( unsigned char * ) & memsrc ,
& fmtstr_complex_array [ 32 ] ) ;
# else
2010-02-11 17:18:55 +01:00
NdrSimpleStructBufferSize ( & StubMsg ,
( unsigned char * ) & memsrc ,
& fmtstr_complex_array [ 32 ] ) ;
2010-02-12 17:34:14 +01:00
# endif
2010-02-11 17:18:55 +01:00
expected_length = ( 4 + memsrc . dim1 * ( 2 + memsrc . dim2 ) ) * 4 ;
2010-02-12 13:24:25 +01:00
if ( StubMsg . BufferLength = = 96 )
{
win_skip ( " Tests crash on Win9x, WinMe and NT4 \n " ) ;
goto cleanup ;
}
2010-02-11 17:18:55 +01:00
ok ( StubMsg . BufferLength > = expected_length , " length %d \n " , StubMsg . BufferLength ) ;
/*NdrGetBuffer(&_StubMsg, _StubMsg.BufferLength, NULL);*/
StubMsg . RpcMsg - > Buffer = StubMsg . BufferStart = StubMsg . Buffer = HeapAlloc ( GetProcessHeap ( ) , 0 , StubMsg . BufferLength ) ;
StubMsg . BufferEnd = StubMsg . BufferStart + StubMsg . BufferLength ;
2010-02-12 17:34:14 +01:00
# ifdef _WIN64
ptr = NdrComplexStructMarshall ( & StubMsg , ( unsigned char * ) & memsrc ,
& fmtstr_complex_array [ 32 ] ) ;
# else
2010-02-11 17:18:55 +01:00
ptr = NdrSimpleStructMarshall ( & StubMsg , ( unsigned char * ) & memsrc ,
& fmtstr_complex_array [ 32 ] ) ;
2010-02-12 17:34:14 +01:00
# endif
2010-02-11 17:18:55 +01:00
2010-02-12 17:34:14 +01:00
ok ( ptr = = NULL , " ret %p \n " , ptr ) ;
2010-02-11 17:18:55 +01:00
ok ( ( char * ) StubMsg . Buffer = = ( char * ) StubMsg . BufferStart + expected_length , " not at expected length \n " ) ;
buf = ( DWORD * ) StubMsg . BufferStart ;
ok ( * buf = = memsrc . dim1 , " dim1 should have been %d instead of %08x \n " , memsrc . dim1 , * buf ) ;
buf + + ;
ok ( * buf = = memsrc . dim2 , " dim2 should have been %d instead of %08x \n " , memsrc . dim2 , * buf ) ;
buf + + ;
ok ( * buf ! = 0 , " pointer id should be non-zero \n " ) ;
buf + + ;
ok ( * buf = = memsrc . dim1 , " Conformance should have been %d instead of %08x \n " , memsrc . dim1 , * buf ) ;
buf + + ;
for ( i = 0 ; i < memsrc . dim1 ; i + + )
{
ok ( * buf ! = 0 , " pointer id[%d] should be non-zero \n " , i ) ;
buf + + ;
}
for ( i = 0 ; i < memsrc . dim1 ; i + + )
{
ok ( * buf = = memsrc . dim2 , " Conformance should have been %d instead of %08x \n " , memsrc . dim2 , * buf ) ;
buf + + ;
for ( j = 0 ; j < memsrc . dim2 ; j + + )
{
ok ( * buf = = i * memsrc . dim2 + j , " got %08x \n " , * buf ) ;
buf + + ;
}
}
ok ( ( void * ) buf = = StubMsg . Buffer , " not at end of buffer \n " ) ;
/* Server */
my_alloc_called = 0 ;
StubMsg . IsClient = 0 ;
mem = NULL ;
StubMsg . Buffer = StubMsg . BufferStart ;
2010-02-12 17:34:14 +01:00
# ifdef _WIN64
ptr = NdrComplexStructUnmarshall ( & StubMsg , ( unsigned char * * ) & mem , & fmtstr_complex_array [ 32 ] , 0 ) ;
# else
2010-02-11 17:18:55 +01:00
ptr = NdrSimpleStructUnmarshall ( & StubMsg , ( unsigned char * * ) & mem , & fmtstr_complex_array [ 32 ] , 0 ) ;
2010-02-12 17:34:14 +01:00
# endif
2010-02-11 17:18:55 +01:00
ok ( ptr = = NULL , " ret %p \n " , ptr ) ;
ok ( mem - > dim1 = = memsrc . dim1 , " mem->dim1 wasn't unmarshalled correctly (%d) \n " , mem - > dim1 ) ;
ok ( mem - > dim2 = = memsrc . dim2 , " mem->dim2 wasn't unmarshalled correctly (%d) \n " , mem - > dim2 ) ;
ok ( mem - > array [ 1 ] [ 0 ] = = memsrc . dim2 , " mem->array[1][0] wasn't unmarshalled correctly (%d) \n " , mem - > array [ 1 ] [ 0 ] ) ;
StubMsg . Buffer = StubMsg . BufferStart ;
2010-02-12 17:34:14 +01:00
# ifdef _WIN64
NdrComplexStructFree ( & StubMsg , ( unsigned char * ) mem , & fmtstr_complex_array [ 32 ] ) ;
# else
2010-02-11 17:18:55 +01:00
NdrSimpleStructFree ( & StubMsg , ( unsigned char * ) mem , & fmtstr_complex_array [ 32 ] ) ;
2010-02-12 17:34:14 +01:00
# endif
2010-02-11 17:18:55 +01:00
HeapFree ( GetProcessHeap ( ) , 0 , StubMsg . RpcMsg - > Buffer ) ;
2010-02-12 13:24:25 +01:00
cleanup :
2010-02-11 17:18:55 +01:00
for ( i = 0 ; i < memsrc . dim1 ; i + + )
HeapFree ( GetProcessHeap ( ) , 0 , memsrc . array [ i ] ) ;
HeapFree ( GetProcessHeap ( ) , 0 , memsrc . array ) ;
}
2008-01-04 18:37:31 +01:00
static void test_ndr_buffer ( void )
{
static unsigned char ncalrpc [ ] = " ncalrpc " ;
2008-05-07 00:06:17 +02:00
static unsigned char endpoint [ ] = " winetest:test_ndr_buffer " ;
2008-01-04 18:37:31 +01:00
RPC_MESSAGE RpcMessage ;
MIDL_STUB_MESSAGE StubMsg ;
MIDL_STUB_DESC StubDesc = Object_StubDesc ;
unsigned char * ret ;
unsigned char * binding ;
RPC_BINDING_HANDLE Handle ;
RPC_STATUS status ;
2008-06-14 17:31:46 +02:00
ULONG prev_buffer_length ;
2008-06-22 17:17:32 +02:00
BOOL old_buffer_valid_location ;
2008-01-04 18:37:31 +01:00
StubDesc . RpcInterfaceInformation = ( void * ) & IFoo___RpcServerInterface ;
2008-05-07 00:06:17 +02:00
status = RpcServerUseProtseqEp ( ncalrpc , 20 , endpoint , NULL ) ;
2009-01-04 01:49:14 +01:00
ok ( RPC_S_OK = = status , " RpcServerUseProtseqEp failed with status %u \n " , status ) ;
2008-05-07 00:06:17 +02:00
status = RpcServerRegisterIf ( IFoo_v0_0_s_ifspec , NULL , NULL ) ;
2009-01-04 01:49:14 +01:00
ok ( RPC_S_OK = = status , " RpcServerRegisterIf failed with status %u \n " , status ) ;
2008-05-07 00:06:17 +02:00
status = RpcServerListen ( 1 , 20 , TRUE ) ;
2009-01-04 01:49:14 +01:00
ok ( RPC_S_OK = = status , " RpcServerListen failed with status %u \n " , status ) ;
2008-05-07 00:06:17 +02:00
if ( status ! = RPC_S_OK )
{
/* Failed to create a server, running client tests is useless */
return ;
}
2008-01-04 18:37:31 +01:00
status = RpcStringBindingCompose ( NULL , ncalrpc , NULL , endpoint , NULL , & binding ) ;
2009-01-04 01:49:14 +01:00
ok ( status = = RPC_S_OK , " RpcStringBindingCompose failed (%u) \n " , status ) ;
2008-01-04 18:37:31 +01:00
status = RpcBindingFromStringBinding ( binding , & Handle ) ;
2009-01-04 01:49:14 +01:00
ok ( status = = RPC_S_OK , " RpcBindingFromStringBinding failed (%u) \n " , status ) ;
2008-01-09 11:33:38 +01:00
RpcStringFree ( & binding ) ;
2008-01-04 18:37:31 +01:00
NdrClientInitializeNew ( & RpcMessage , & StubMsg , & StubDesc , 5 ) ;
ret = NdrGetBuffer ( & StubMsg , 10 , Handle ) ;
ok ( ret = = StubMsg . Buffer , " NdrGetBuffer should have returned the same value as StubMsg.Buffer instead of %p \n " , ret ) ;
ok ( RpcMessage . Handle ! = NULL , " RpcMessage.Handle should not have been NULL \n " ) ;
ok ( RpcMessage . Buffer ! = NULL , " RpcMessage.Buffer should not have been NULL \n " ) ;
2008-07-08 06:51:59 +02:00
ok ( RpcMessage . BufferLength = = 10 | |
broken ( RpcMessage . BufferLength = = 12 ) , /* win2k */
" RpcMessage.BufferLength should have been 10 instead of %d \n " , RpcMessage . BufferLength ) ;
2009-01-11 00:17:01 +01:00
ok ( RpcMessage . RpcFlags = = 0 , " RpcMessage.RpcFlags should have been 0x0 instead of 0x%x \n " , RpcMessage . RpcFlags ) ;
2008-01-04 18:37:31 +01:00
ok ( StubMsg . Buffer ! = NULL , " Buffer should not have been NULL \n " ) ;
ok ( ! StubMsg . BufferStart , " BufferStart should have been NULL instead of %p \n " , StubMsg . BufferStart ) ;
ok ( ! StubMsg . BufferEnd , " BufferEnd should have been NULL instead of %p \n " , StubMsg . BufferEnd ) ;
todo_wine
ok ( StubMsg . BufferLength = = 0 , " BufferLength should have left as 0 instead of being set to %d \n " , StubMsg . BufferLength ) ;
2008-06-22 17:17:32 +02:00
old_buffer_valid_location = ! StubMsg . fBufferValid ;
if ( old_buffer_valid_location )
ok ( broken ( StubMsg . CorrDespIncrement = = TRUE ) , " fBufferValid should have been TRUE instead of 0x%x \n " , StubMsg . CorrDespIncrement ) ;
else
ok ( StubMsg . fBufferValid , " fBufferValid should have been non-zero instead of 0x%x \n " , StubMsg . fBufferValid ) ;
2008-01-04 18:37:31 +01:00
2008-06-14 17:31:46 +02:00
prev_buffer_length = RpcMessage . BufferLength ;
2008-01-04 18:37:31 +01:00
StubMsg . BufferLength = 1 ;
NdrFreeBuffer ( & StubMsg ) ;
ok ( RpcMessage . Handle ! = NULL , " RpcMessage.Handle should not have been NULL \n " ) ;
ok ( RpcMessage . Buffer ! = NULL , " RpcMessage.Buffer should not have been NULL \n " ) ;
2008-06-14 17:31:46 +02:00
ok ( RpcMessage . BufferLength = = prev_buffer_length , " RpcMessage.BufferLength should have been left as %d instead of %d \n " , prev_buffer_length , RpcMessage . BufferLength ) ;
2008-01-04 18:37:31 +01:00
ok ( StubMsg . Buffer ! = NULL , " Buffer should not have been NULL \n " ) ;
ok ( StubMsg . BufferLength = = 1 , " BufferLength should have left as 1 instead of being set to %d \n " , StubMsg . BufferLength ) ;
2008-06-22 17:17:32 +02:00
if ( old_buffer_valid_location )
ok ( broken ( StubMsg . CorrDespIncrement = = FALSE ) , " fBufferValid should have been FALSE instead of 0x%x \n " , StubMsg . CorrDespIncrement ) ;
else
ok ( ! StubMsg . fBufferValid , " fBufferValid should have been FALSE instead of %d \n " , StubMsg . fBufferValid ) ;
2008-01-04 18:37:31 +01:00
/* attempt double-free */
NdrFreeBuffer ( & StubMsg ) ;
2008-01-09 11:33:38 +01:00
RpcBindingFree ( & Handle ) ;
2008-01-04 18:37:31 +01:00
status = RpcServerUnregisterIf ( NULL , NULL , FALSE ) ;
2009-01-04 01:49:14 +01:00
ok ( status = = RPC_S_OK , " RpcServerUnregisterIf failed (%u) \n " , status ) ;
2008-01-04 18:37:31 +01:00
}
2008-01-08 19:14:20 +01:00
static void test_NdrMapCommAndFaultStatus ( void )
{
RPC_STATUS rpc_status ;
MIDL_STUB_MESSAGE StubMsg ;
RPC_MESSAGE RpcMessage ;
NdrClientInitializeNew ( & RpcMessage , & StubMsg , & Object_StubDesc , 5 ) ;
for ( rpc_status = 0 ; rpc_status < 10000 ; rpc_status + + )
{
RPC_STATUS status ;
ULONG comm_status = 0 ;
ULONG fault_status = 0 ;
ULONG expected_comm_status = 0 ;
ULONG expected_fault_status = 0 ;
status = NdrMapCommAndFaultStatus ( & StubMsg , & comm_status , & fault_status , rpc_status ) ;
2009-01-04 01:49:14 +01:00
ok ( status = = RPC_S_OK , " NdrMapCommAndFaultStatus failed with error %d \n " , status ) ;
2008-01-08 19:14:20 +01:00
switch ( rpc_status )
{
case ERROR_INVALID_HANDLE :
case RPC_S_INVALID_BINDING :
case RPC_S_UNKNOWN_IF :
case RPC_S_SERVER_UNAVAILABLE :
case RPC_S_SERVER_TOO_BUSY :
case RPC_S_CALL_FAILED_DNE :
case RPC_S_PROTOCOL_ERROR :
case RPC_S_UNSUPPORTED_TRANS_SYN :
case RPC_S_UNSUPPORTED_TYPE :
case RPC_S_PROCNUM_OUT_OF_RANGE :
case EPT_S_NOT_REGISTERED :
case RPC_S_COMM_FAILURE :
expected_comm_status = rpc_status ;
break ;
default :
expected_fault_status = rpc_status ;
}
2009-01-04 01:49:14 +01:00
ok ( comm_status = = expected_comm_status , " NdrMapCommAndFaultStatus should have mapped %d to comm status %d instead of %d \n " ,
2008-01-08 19:14:20 +01:00
rpc_status , expected_comm_status , comm_status ) ;
2009-01-04 01:49:14 +01:00
ok ( fault_status = = expected_fault_status , " NdrMapCommAndFaultStatus should have mapped %d to fault status %d instead of %d \n " ,
2008-01-08 19:14:20 +01:00
rpc_status , expected_fault_status , fault_status ) ;
}
}
2009-01-28 13:58:42 +01:00
static void test_NdrGetUserMarshalInfo ( void )
{
RPC_STATUS status ;
MIDL_STUB_MESSAGE stubmsg ;
USER_MARSHAL_CB umcb ;
NDR_USER_MARSHAL_INFO umi ;
unsigned char buffer [ 16 ] ;
void * rpc_channel_buffer = ( void * ) ( ULONG_PTR ) 0xcafebabe ;
RPC_MESSAGE rpc_msg ;
RPC_STATUS ( RPC_ENTRY * pNdrGetUserMarshalInfo ) ( ULONG * , ULONG , NDR_USER_MARSHAL_INFO * ) ;
pNdrGetUserMarshalInfo = ( void * ) GetProcAddress ( GetModuleHandle ( " rpcrt4.dll " ) , " NdrGetUserMarshalInfo " ) ;
if ( ! pNdrGetUserMarshalInfo )
{
skip ( " NdrGetUserMarshalInfo not exported \n " ) ;
return ;
}
/* unmarshall */
memset ( & rpc_msg , 0xcc , sizeof ( rpc_msg ) ) ;
rpc_msg . Buffer = buffer ;
rpc_msg . BufferLength = 16 ;
memset ( & stubmsg , 0xcc , sizeof ( stubmsg ) ) ;
stubmsg . RpcMsg = & rpc_msg ;
stubmsg . dwDestContext = MSHCTX_INPROC ;
stubmsg . pvDestContext = NULL ;
stubmsg . Buffer = buffer + 15 ;
stubmsg . BufferLength = 0 ;
stubmsg . BufferEnd = NULL ;
stubmsg . pRpcChannelBuffer = rpc_channel_buffer ;
stubmsg . StubDesc = NULL ;
stubmsg . pfnAllocate = my_alloc ;
stubmsg . pfnFree = my_free ;
memset ( & umcb , 0xcc , sizeof ( umcb ) ) ;
umcb . Flags = MAKELONG ( MSHCTX_INPROC , NDR_LOCAL_DATA_REPRESENTATION ) ;
umcb . pStubMsg = & stubmsg ;
umcb . Signature = USER_MARSHAL_CB_SIGNATURE ;
umcb . CBType = USER_MARSHAL_CB_UNMARSHALL ;
memset ( & umi , 0xaa , sizeof ( umi ) ) ;
status = pNdrGetUserMarshalInfo ( & umcb . Flags , 1 , & umi ) ;
ok ( status = = RPC_S_OK , " NdrGetUserMarshalInfo failed with error %d \n " , status ) ;
ok ( umi . InformationLevel = = 1 ,
" umi.InformationLevel was %u instead of 1 \n " ,
umi . InformationLevel ) ;
2009-08-31 11:52:17 +02:00
ok ( U1 ( umi ) . Level1 . Buffer = = buffer + 15 ,
" umi.Level1.Buffer was %p instead of %p \n " ,
U1 ( umi ) . Level1 . Buffer , buffer ) ;
ok ( U1 ( umi ) . Level1 . BufferSize = = 1 ,
" umi.Level1.BufferSize was %u instead of 1 \n " ,
U1 ( umi ) . Level1 . BufferSize ) ;
ok ( U1 ( umi ) . Level1 . pfnAllocate = = my_alloc ,
" umi.Level1.pfnAllocate was %p instead of %p \n " ,
U1 ( umi ) . Level1 . pfnAllocate , my_alloc ) ;
ok ( U1 ( umi ) . Level1 . pfnFree = = my_free ,
" umi.Level1.pfnFree was %p instead of %p \n " ,
U1 ( umi ) . Level1 . pfnFree , my_free ) ;
ok ( U1 ( umi ) . Level1 . pRpcChannelBuffer = = rpc_channel_buffer ,
" umi.Level1.pRpcChannelBuffer was %p instead of %p \n " ,
U1 ( umi ) . Level1 . pRpcChannelBuffer , rpc_channel_buffer ) ;
2009-01-28 13:58:42 +01:00
/* buffer size */
rpc_msg . Buffer = buffer ;
rpc_msg . BufferLength = 16 ;
stubmsg . Buffer = buffer ;
stubmsg . BufferLength = 16 ;
stubmsg . BufferEnd = NULL ;
umcb . CBType = USER_MARSHAL_CB_BUFFER_SIZE ;
memset ( & umi , 0xaa , sizeof ( umi ) ) ;
status = pNdrGetUserMarshalInfo ( & umcb . Flags , 1 , & umi ) ;
ok ( status = = RPC_S_OK , " NdrGetUserMarshalInfo failed with error %d \n " , status ) ;
ok ( umi . InformationLevel = = 1 ,
" umi.InformationLevel was %u instead of 1 \n " ,
umi . InformationLevel ) ;
2009-08-31 11:52:17 +02:00
ok ( U1 ( umi ) . Level1 . Buffer = = NULL ,
" umi.Level1.Buffer was %p instead of NULL \n " ,
U1 ( umi ) . Level1 . Buffer ) ;
ok ( U1 ( umi ) . Level1 . BufferSize = = 0 ,
" umi.Level1.BufferSize was %u instead of 0 \n " ,
U1 ( umi ) . Level1 . BufferSize ) ;
ok ( U1 ( umi ) . Level1 . pfnAllocate = = my_alloc ,
" umi.Level1.pfnAllocate was %p instead of %p \n " ,
U1 ( umi ) . Level1 . pfnAllocate , my_alloc ) ;
ok ( U1 ( umi ) . Level1 . pfnFree = = my_free ,
" umi.Level1.pfnFree was %p instead of %p \n " ,
U1 ( umi ) . Level1 . pfnFree , my_free ) ;
ok ( U1 ( umi ) . Level1 . pRpcChannelBuffer = = rpc_channel_buffer ,
" umi.Level1.pRpcChannelBuffer was %p instead of %p \n " ,
U1 ( umi ) . Level1 . pRpcChannelBuffer , rpc_channel_buffer ) ;
2009-01-28 13:58:42 +01:00
/* marshall */
rpc_msg . Buffer = buffer ;
rpc_msg . BufferLength = 16 ;
stubmsg . Buffer = buffer + 15 ;
stubmsg . BufferLength = 0 ;
stubmsg . BufferEnd = NULL ;
umcb . CBType = USER_MARSHAL_CB_MARSHALL ;
memset ( & umi , 0xaa , sizeof ( umi ) ) ;
status = pNdrGetUserMarshalInfo ( & umcb . Flags , 1 , & umi ) ;
ok ( status = = RPC_S_OK , " NdrGetUserMarshalInfo failed with error %d \n " , status ) ;
ok ( umi . InformationLevel = = 1 ,
" umi.InformationLevel was %u instead of 1 \n " ,
umi . InformationLevel ) ;
2009-08-31 11:52:17 +02:00
ok ( U1 ( umi ) . Level1 . Buffer = = buffer + 15 ,
" umi.Level1.Buffer was %p instead of %p \n " ,
U1 ( umi ) . Level1 . Buffer , buffer ) ;
ok ( U1 ( umi ) . Level1 . BufferSize = = 1 ,
" umi.Level1.BufferSize was %u instead of 1 \n " ,
U1 ( umi ) . Level1 . BufferSize ) ;
ok ( U1 ( umi ) . Level1 . pfnAllocate = = my_alloc ,
" umi.Level1.pfnAllocate was %p instead of %p \n " ,
U1 ( umi ) . Level1 . pfnAllocate , my_alloc ) ;
ok ( U1 ( umi ) . Level1 . pfnFree = = my_free ,
" umi.Level1.pfnFree was %p instead of %p \n " ,
U1 ( umi ) . Level1 . pfnFree , my_free ) ;
ok ( U1 ( umi ) . Level1 . pRpcChannelBuffer = = rpc_channel_buffer ,
" umi.Level1.pRpcChannelBuffer was %p instead of %p \n " ,
U1 ( umi ) . Level1 . pRpcChannelBuffer , rpc_channel_buffer ) ;
2009-01-28 13:58:42 +01:00
/* free */
rpc_msg . Buffer = buffer ;
rpc_msg . BufferLength = 16 ;
stubmsg . Buffer = buffer ;
stubmsg . BufferLength = 16 ;
stubmsg . BufferEnd = NULL ;
umcb . CBType = USER_MARSHAL_CB_FREE ;
memset ( & umi , 0xaa , sizeof ( umi ) ) ;
status = pNdrGetUserMarshalInfo ( & umcb . Flags , 1 , & umi ) ;
ok ( status = = RPC_S_OK , " NdrGetUserMarshalInfo failed with error %d \n " , status ) ;
ok ( umi . InformationLevel = = 1 ,
" umi.InformationLevel was %u instead of 1 \n " ,
umi . InformationLevel ) ;
2009-08-31 11:52:17 +02:00
ok ( U1 ( umi ) . Level1 . Buffer = = NULL ,
" umi.Level1.Buffer was %p instead of NULL \n " ,
U1 ( umi ) . Level1 . Buffer ) ;
ok ( U1 ( umi ) . Level1 . BufferSize = = 0 ,
" umi.Level1.BufferSize was %u instead of 0 \n " ,
U1 ( umi ) . Level1 . BufferSize ) ;
ok ( U1 ( umi ) . Level1 . pfnAllocate = = my_alloc ,
" umi.Level1.pfnAllocate was %p instead of %p \n " ,
U1 ( umi ) . Level1 . pfnAllocate , my_alloc ) ;
ok ( U1 ( umi ) . Level1 . pfnFree = = my_free ,
" umi.Level1.pfnFree was %p instead of %p \n " ,
U1 ( umi ) . Level1 . pfnFree , my_free ) ;
ok ( U1 ( umi ) . Level1 . pRpcChannelBuffer = = rpc_channel_buffer ,
" umi.Level1.pRpcChannelBuffer was %p instead of %p \n " ,
U1 ( umi ) . Level1 . pRpcChannelBuffer , rpc_channel_buffer ) ;
2009-01-28 13:58:42 +01:00
/* boundary test */
rpc_msg . Buffer = buffer ;
rpc_msg . BufferLength = 15 ;
stubmsg . Buffer = buffer + 15 ;
stubmsg . BufferLength = 0 ;
stubmsg . BufferEnd = NULL ;
umcb . CBType = USER_MARSHAL_CB_MARSHALL ;
status = pNdrGetUserMarshalInfo ( & umcb . Flags , 1 , & umi ) ;
ok ( status = = RPC_S_OK , " NdrGetUserMarshalInfo failed with error %d \n " , status ) ;
2009-08-31 11:52:17 +02:00
ok ( U1 ( umi ) . Level1 . BufferSize = = 0 ,
" umi.Level1.BufferSize was %u instead of 0 \n " ,
U1 ( umi ) . Level1 . BufferSize ) ;
2009-01-28 13:58:42 +01:00
/* error conditions */
rpc_msg . BufferLength = 14 ;
status = pNdrGetUserMarshalInfo ( & umcb . Flags , 1 , & umi ) ;
ok ( status = = ERROR_INVALID_USER_BUFFER ,
" NdrGetUserMarshalInfo should have failed with ERROR_INVALID_USER_BUFFER instead of %d \n " , status ) ;
rpc_msg . BufferLength = 15 ;
status = pNdrGetUserMarshalInfo ( & umcb . Flags , 9999 , & umi ) ;
ok ( status = = RPC_S_INVALID_ARG ,
" NdrGetUserMarshalInfo should have failed with RPC_S_INVALID_ARG instead of %d \n " , status ) ;
umcb . CBType = 9999 ;
status = pNdrGetUserMarshalInfo ( & umcb . Flags , 1 , & umi ) ;
ok ( status = = RPC_S_OK , " NdrGetUserMarshalInfo failed with error %d \n " , status ) ;
umcb . CBType = USER_MARSHAL_CB_MARSHALL ;
umcb . Signature = 0 ;
status = pNdrGetUserMarshalInfo ( & umcb . Flags , 1 , & umi ) ;
ok ( status = = RPC_S_INVALID_ARG ,
" NdrGetUserMarshalInfo should have failed with RPC_S_INVALID_ARG instead of %d \n " , status ) ;
}
2006-05-17 16:28:38 +02:00
START_TEST ( ndr_marshall )
{
2008-06-14 17:29:35 +02:00
determine_pointer_marshalling_style ( ) ;
2007-01-23 12:50:06 +01:00
test_ndr_simple_type ( ) ;
2006-05-17 16:28:38 +02:00
test_simple_types ( ) ;
2008-01-16 15:02:58 +01:00
test_nontrivial_pointer_types ( ) ;
2006-05-19 12:47:20 +02:00
test_simple_struct ( ) ;
2006-05-26 20:56:00 +02:00
test_fullpointer_xlat ( ) ;
2006-06-01 21:24:34 +02:00
test_client_init ( ) ;
2007-12-30 17:46:15 +01:00
test_server_init ( ) ;
2006-08-16 13:38:20 +02:00
test_ndr_allocate ( ) ;
2007-03-12 15:08:52 +01:00
test_conformant_array ( ) ;
2007-12-04 14:23:09 +01:00
test_conformant_string ( ) ;
2007-12-29 13:17:55 +01:00
test_nonconformant_string ( ) ;
2008-08-10 12:14:17 +02:00
test_conf_complex_struct ( ) ;
2010-02-11 17:18:55 +01:00
test_conf_complex_array ( ) ;
2008-01-04 18:37:31 +01:00
test_ndr_buffer ( ) ;
2008-01-08 19:14:20 +01:00
test_NdrMapCommAndFaultStatus ( ) ;
2009-01-28 13:58:42 +01:00
test_NdrGetUserMarshalInfo ( ) ;
2006-05-17 16:28:38 +02:00
}