2005-05-17 21:32:25 +04:00
#!/usr/bin/perl
# String tests for pidl
# (C) 2005 Jelmer Vernooij <jelmer@samba.org>
# Published under the GNU General Public License
use strict ;
2019-11-30 12:34:54 +03:00
use warnings ;
2005-05-17 21:32:25 +04:00
2009-07-27 17:52:16 +04:00
use Test::More tests = > 6 * 8 ;
2005-12-25 06:04:13 +03:00
use FindBin qw( $RealBin ) ;
use lib "$RealBin" ;
use Util qw( test_samba4_ndr ) ;
2005-05-17 21:32:25 +04:00
2005-12-25 06:04:13 +03:00
test_samba4_ndr ( "string-pull-empty" ,
2005-05-17 21:32:25 +04:00
' [public] void TestString([in,flag(STR_ASCII|LIBNDR_FLAG_STR_SIZE4)] string data);' ,
'
uint8_t data [] = { 0x00 , 0x00 , 0x00 , 0x00 } ;
DATA_BLOB b = { data , 4 } ;
2010-05-09 19:20:01 +04:00
struct ndr_pull * ndr = ndr_pull_init_blob ( & b , NULL ) ;
2005-05-17 21:32:25 +04:00
struct TestString r ;
r . in . data = NULL ;
2007-11-09 21:23:25 +03:00
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_pull_TestString ( ndr , NDR_IN , & r ) ) )
2005-05-17 21:32:25 +04:00
return 1 ;
if ( r . in . data == NULL )
return 2 ;
if ( r . in . data [ 0 ] != 0 )
return 3 ;
' ) ;
2005-12-25 06:04:13 +03:00
test_samba4_ndr ( "string-ascii-pull" ,
2005-05-17 21:32:25 +04:00
'
[ public ] void TestString ( [ in , flag ( STR_ASCII | LIBNDR_FLAG_STR_SIZE4 ) ] string data ) ;
' ,
'
uint8_t data [] = { 0x03 , 0x00 , 0x00 , 0x00 ,
\ ' f \ ' , \ ' o \ ' , \ ' o \ ' , 0 } ;
DATA_BLOB b = { data , 8 } ;
2010-05-09 19:20:01 +04:00
struct ndr_pull * ndr = ndr_pull_init_blob ( & b , NULL ) ;
2005-05-17 21:32:25 +04:00
struct TestString r ;
r . in . data = NULL ;
2007-11-09 21:23:25 +03:00
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_pull_TestString ( ndr , NDR_IN , & r ) ) )
2005-05-17 21:32:25 +04:00
return 1 ;
if ( r . in . data == NULL )
return 2 ;
if ( strncmp ( r . in . data , "foo" , 3 ) != 0 )
return 3 ;
if ( r . in . data [ 4 ] != 0 )
return 4 ;
' ) ;
2006-09-15 21:34:46 +04:00
2009-07-27 17:52:16 +04:00
test_samba4_ndr ( "string-wchar-fixed-array-01" ,
'
typedef struct {
uint32 l1 ;
[ string , charset ( UTF16 ) ] uint16 str [ 6 ] ;
uint32 l2 ;
} TestStringStruct ;
[ public ] void TestString ( [ in , ref ] TestStringStruct * str ) ;
' ,
'
uint8_t data [] = { 0x01 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 , 0x00 , 0x00 ,
0x04 , 0x00 , 0x00 , 0x00 ,
\ ' f \ ' , 0x00 , \ ' o \ ' , 0x00 ,
2009-09-13 03:58:11 +04:00
\ ' o \ ' , 0x00 , 0x00 , 0x00 ,
2009-07-27 17:52:16 +04:00
0x02 , 0x00 , 0x00 , 0x00
} ;
DATA_BLOB b = { data , sizeof ( data ) } ;
2010-05-09 19:20:01 +04:00
struct ndr_pull * ndr = ndr_pull_init_blob ( & b , NULL ) ;
2009-07-27 17:52:16 +04:00
struct TestString r ;
struct TestStringStruct str ;
r . in . str = & str ;
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_pull_TestString ( ndr , NDR_IN , & r ) ) )
return 1 ;
if ( r . in . str == NULL )
return 2 ;
2009-09-13 03:58:11 +04:00
if ( r . in . str - > l1 != 0x00000001 )
2009-07-27 17:52:16 +04:00
return 3 ;
if ( strncmp ( str . str , "foo" , 3 ) != 0 )
return 4 ;
2009-09-13 03:58:11 +04:00
if ( r . in . str - > str [ 4 ] != 0 )
2009-07-27 17:52:16 +04:00
return 5 ;
2009-09-13 03:58:11 +04:00
if ( r . in . str - > l2 != 0x00000002 )
2009-07-27 17:52:16 +04:00
return 6 ;
' ) ;
test_samba4_ndr ( "string-wchar-fixed-array-02" ,
'
typedef struct {
uint32 l1 ;
[ string , charset ( UTF16 ) ] uint16 str [ 6 ] ;
uint32 l2 ;
} TestStringStruct ;
[ public ] void TestString ( [ in , ref ] TestStringStruct * str ) ;
' ,
'
uint8_t data [] = { 0x01 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 , 0x00 , 0x00 ,
0x06 , 0x00 , 0x00 , 0x00 ,
\ ' f \ ' , 0x00 , \ ' o \ ' , 0x00 ,
2009-09-13 03:59:16 +04:00
\ ' o \ ' , 0x00 , \ ' b \ ' , 0x00 ,
2009-07-27 17:52:16 +04:00
\ ' a \ ' , 0x00 , \ ' r \ ' , 0x00 ,
2009-09-13 03:59:16 +04:00
0x00 , 0x00 , 0x00 , 0x00 ,
2009-07-27 17:52:16 +04:00
0x02 , 0x00 , 0x00 , 0x00
} ;
DATA_BLOB b = { data , sizeof ( data ) } ;
2010-05-09 19:20:01 +04:00
struct ndr_pull * ndr = ndr_pull_init_blob ( & b , NULL ) ;
2009-07-27 17:52:16 +04:00
struct TestString r ;
struct TestStringStruct str ;
r . in . str = & str ;
/* the string terminator is wrong */
if ( NDR_ERR_CODE_IS_SUCCESS ( ndr_pull_TestString ( ndr , NDR_IN , & r ) ) )
return 1 ;
' ) ;
test_samba4_ndr ( "string-wchar-fixed-array-03" ,
'
typedef struct {
uint32 l1 ;
[ string , charset ( UTF16 ) ] uint16 str [ 6 ] ;
uint32 l2 ;
} TestStringStruct ;
[ public ] void TestString ( [ in , ref ] TestStringStruct * str ) ;
' ,
'
uint8_t data [] = { 0x01 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 , 0x00 , 0x00 ,
0x07 , 0x00 , 0x00 , 0x00 ,
\ ' f \ ' , 0x00 , \ ' o \ ' , 0x00 ,
2009-09-13 03:59:48 +04:00
\ ' o \ ' , 0x00 , \ ' b \ ' , 0x00 ,
2009-07-27 17:52:16 +04:00
\ ' a \ ' , 0x00 , \ ' r \ ' , 0x00 ,
2009-09-13 03:59:48 +04:00
0x00 , 0x00 , 0x00 , 0x00 ,
2009-07-27 17:52:16 +04:00
0x02 , 0x00 , 0x00 , 0x00
} ;
DATA_BLOB b = { data , sizeof ( data ) } ;
2010-05-09 19:20:01 +04:00
struct ndr_pull * ndr = ndr_pull_init_blob ( & b , NULL ) ;
2009-07-27 17:52:16 +04:00
struct TestString r ;
struct TestStringStruct str ;
r . in . str = & str ;
/* the length 0x07 is to large */
if ( NDR_ERR_CODE_IS_SUCCESS ( ndr_pull_TestString ( ndr , NDR_IN , & r ) ) )
return 1 ;
' ) ;
2006-12-21 05:48:46 +03:00
SKIP: {
skip "doesn't seem to work yet" , 8 ;
2006-09-15 21:34:46 +04:00
test_samba4_ndr ( "string-out" ,
'
2006-12-21 05:48:46 +03:00
[ public ] void TestString ( [ out , string , charset ( UNIX ) ] uint8 ** data ) ;
2006-09-15 21:34:46 +04:00
' ,
'
uint8_t data [] = { 0x03 , 0x00 , 0x00 , 0x00 ,
\ ' f \ ' , \ ' o \ ' , \ ' o \ ' , 0 } ;
DATA_BLOB b = { data , 8 } ;
2010-05-09 19:20:01 +04:00
struct ndr_pull * ndr = ndr_pull_init_blob ( & b , NULL ) ;
2006-09-15 21:34:46 +04:00
struct TestString r ;
char * str = NULL ;
r . out . data = & str ;
2007-11-09 21:23:25 +03:00
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_pull_TestString ( ndr , NDR_IN , & r ) ) )
2006-09-15 21:34:46 +04:00
return 1 ;
if ( r . out . data == NULL )
return 2 ;
if ( * r . out . data == NULL )
return 3 ;
if ( strncmp ( r . out . data , "foo" , 3 ) != 0 )
2006-12-21 05:48:46 +03:00
return 4 ;
2006-09-15 21:34:46 +04:00
2006-11-23 23:59:09 +03:00
if ( r . out . data [ 4 ] != 0 )
2006-12-21 05:48:46 +03:00
return 5 ;
2006-09-15 21:34:46 +04:00
' ) ;
2006-12-21 05:48:46 +03:00
}