2005-05-17 19:51:35 +04:00
#!/usr/bin/perl
# NDR allocation tests
# (C) 2005 Jelmer Vernooij. Published under the GNU GPL
use strict ;
2005-12-25 06:04:13 +03:00
use Test::More tests = > 5 * 8 ;
use FindBin qw( $RealBin ) ;
use lib "$RealBin" ;
use Util qw( test_samba4_ndr ) ;
2005-05-17 19:51:35 +04:00
# Check that an outgoing scalar pointer is allocated correctly
2005-12-25 06:04:13 +03:00
test_samba4_ndr ( "alloc-scalar" ,
2005-05-17 19:51:35 +04:00
'
typedef struct {
uint8 * x ;
} bla ;
[ public ] void TestAlloc ( [ in ] bla foo ) ;
','
uint8_t data [] = { 0xde , 0xad , 0xbe , 0xef , 0x03 } ;
DATA_BLOB b = { data , 5 } ;
2007-12-14 02:27:38 +03:00
struct ndr_pull * ndr = ndr_pull_init_blob ( & b , NULL , NULL ) ;
2005-05-17 19:51:35 +04:00
struct TestAlloc r ;
2007-11-09 21:23:25 +03:00
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_pull_TestAlloc ( ndr , NDR_IN , & r ) ) )
2005-05-17 19:51:35 +04:00
return 1 ;
if ( r . in . foo . x == NULL )
return 2 ;
if ( * r . in . foo . x != 0x03 )
return 3 ;
'
) ;
# Check that an outgoing buffer pointer is allocated correctly
2005-12-25 06:04:13 +03:00
test_samba4_ndr ( "alloc-buffer" ,
2005-05-17 19:51:35 +04:00
'
2005-12-25 02:32:50 +03:00
typedef struct { uint8 data ; } blie ;
typedef struct { blie * x ; } bla ;
2005-05-17 19:51:35 +04:00
[ public ] void TestAlloc ( [ in ] bla foo ) ;
','
uint8_t data [] = { 0xde , 0xad , 0xbe , 0xef , 0x03 } ;
DATA_BLOB b = { data , 5 } ;
2007-12-14 02:27:38 +03:00
struct ndr_pull * ndr = ndr_pull_init_blob ( & b , NULL , NULL ) ;
2005-05-17 19:51:35 +04:00
struct TestAlloc r ;
2007-11-09 21:23:25 +03:00
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_pull_TestAlloc ( ndr , NDR_IN , & r ) ) )
2005-05-17 19:51:35 +04:00
return 1 ;
if ( r . in . foo . x == NULL )
return 2 ;
if ( r . in . foo . x - > data != 0x03 )
return 3 ;
'
) ;
# Check that ref pointers aren't allocated by default
2005-12-25 06:04:13 +03:00
test_samba4_ndr ( "ref-noalloc-null" ,
2005-05-17 19:51:35 +04:00
'
[ public ] void TestAlloc ( [ in , ref ] uint8 * t ) ;
','
uint8_t data [] = { 0x03 } ;
DATA_BLOB b = { data , 1 } ;
2007-12-14 02:27:38 +03:00
struct ndr_pull * ndr = ndr_pull_init_blob ( & b , NULL , NULL ) ;
2005-05-17 19:51:35 +04:00
struct TestAlloc r ;
r . in . t = NULL ;
2007-11-09 21:23:25 +03:00
if ( NDR_ERR_CODE_IS_SUCCESS ( ndr_pull_TestAlloc ( ndr , NDR_IN , & r ) ) )
2005-05-17 19:51:35 +04:00
return 1 ;
'
) ;
# Check that ref pointers aren't allocated by default
2005-12-25 06:04:13 +03:00
test_samba4_ndr ( "ref-noalloc" ,
2005-05-17 19:51:35 +04:00
'
[ public ] void TestAlloc ( [ in , ref ] uint8 * t ) ;
','
uint8_t data [] = { 0x03 } ;
DATA_BLOB b = { data , 1 } ;
2007-12-14 02:27:38 +03:00
struct ndr_pull * ndr = ndr_pull_init_blob ( & b , NULL , NULL ) ;
2005-05-17 19:51:35 +04:00
struct TestAlloc r ;
uint8_t x ;
r . in . t = & x ;
2007-11-09 21:23:25 +03:00
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_pull_TestAlloc ( ndr , NDR_IN , & r ) ) )
2005-05-17 19:51:35 +04:00
return 1 ;
if ( * r . in . t != 0x03 )
return 2 ;
'
) ;
# Check that an outgoing ref pointer is allocated correctly
2005-12-25 06:04:13 +03:00
test_samba4_ndr ( "ref-alloc" ,
2005-05-17 19:51:35 +04:00
'
[ public ] void TestAlloc ( [ in , ref ] uint8 * t ) ;
','
uint8_t data [] = { 0x03 } ;
DATA_BLOB b = { data , 1 } ;
2007-12-14 02:27:38 +03:00
struct ndr_pull * ndr = ndr_pull_init_blob ( & b , NULL , NULL ) ;
2005-05-17 19:51:35 +04:00
struct TestAlloc r ;
ndr - > flags |= LIBNDR_FLAG_REF_ALLOC ;
r . in . t = NULL ;
2007-11-09 21:23:25 +03:00
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_pull_TestAlloc ( ndr , NDR_IN , & r ) ) )
2005-05-17 19:51:35 +04:00
return 1 ;
if ( r . in . t == NULL )
return 2 ;
if ( * r . in . t != 0x03 )
return 3 ;
'
) ;