2005-12-25 02:32:50 +03:00
#!/usr/bin/perl
# Some simple tests for pidls parsing routines
# (C) 2005 Jelmer Vernooij <jelmer@samba.org>
# Published under the GNU General Public License
use strict ;
2008-01-13 02:05:24 +03:00
use Test::More tests = > 65 * 2 + 7 ;
2005-12-25 02:32:50 +03:00
use FindBin qw( $RealBin ) ;
2007-01-05 18:20:23 +03:00
use lib "$RealBin" ;
use Util qw( test_errors ) ;
2005-12-25 02:32:50 +03:00
use Parse::Pidl::IDL ;
use Parse::Pidl::NDR ;
sub testok ($$)
{
my ( $ name , $ data ) = @ _ ;
2007-01-05 18:20:23 +03:00
test_errors ( "" , sub {
my $ pidl = Parse::Pidl::IDL:: parse_string ( $ data , "<$name>" ) ;
ok ( defined ( $ pidl ) , $ name ) ;
} ) ;
2005-12-25 02:32:50 +03:00
}
2007-01-05 18:20:23 +03:00
sub testfail ($$$)
2005-12-25 02:32:50 +03:00
{
2007-01-05 18:20:23 +03:00
my ( $ name , $ data , $ error ) = @ _ ;
2005-12-25 02:32:50 +03:00
2007-01-05 18:20:23 +03:00
test_errors ( $ error , sub {
my $ pidl = Parse::Pidl::IDL:: parse_string ( $ data , "<$name>" ) ;
2005-12-25 02:32:50 +03:00
2007-01-05 18:20:23 +03:00
ok ( ( not defined $ pidl ) , $ name ) ;
} ) ;
2005-12-25 02:32:50 +03:00
}
2007-01-05 18:20:23 +03:00
testfail "unknowntag" , "bla test {};" ,
"<unknowntag>:0: Syntax error near 'bla'\n" ;
2005-12-25 02:32:50 +03:00
testok "test1" , "interface test { void Test(); }; " ;
testok "voidtest" , "interface test { int Testx(void); }; " ;
2007-01-05 18:20:23 +03:00
testfail "voidtest" , "interface test { Test(); }; " ,
"<voidtest>:0: Syntax error near '('\n" ;
2005-12-25 02:32:50 +03:00
testok "argtest" , "interface test { int Test(int a, long b, uint32 c); }; " ;
testok "array1" , "interface test { int Test(int a[]); };" ;
testok "array2" , "interface test { int Test(int a[2]); };" ;
testok "array3" , "interface test { int Test(int a[b]); };" ;
2007-01-05 18:20:23 +03:00
testfail "array4" , "interface test { int Test(int[] a); };" ,
"<array4>:0: Syntax error near '['\n" ;
2005-12-25 02:32:50 +03:00
testok "ptr1" , "interface test { int Test(int *a); };" ;
testok "ptr2" , "interface test { int Test(int **a); };" ;
testok "ptr3" , "interface test { int Test(int ***a); };" ;
2007-01-05 18:20:23 +03:00
testfail "empty1" , "interface test { };" , "<empty1>:0: Syntax error near '}'\n" ;
testfail "empty2" , "" , "" ;
2005-12-25 02:32:50 +03:00
testok "attr1" , "[uuid(\"myuuid\"),attr] interface test { int Test(int ***a); };" ;
testok "attr2" , "interface test { [public] int Test(); };" ;
2005-12-25 17:11:59 +03:00
testok "attr3" , "[attr1] [attr2] interface test { [public] int Test(); };" ;
2005-12-25 02:32:50 +03:00
testok "multfn" , "interface test { int test1(); int test2(); };" ;
testok "multif" , "interface test { int test1(); }; interface test2 { int test2(); };" ;
testok "tdstruct1" , "interface test { typedef struct { } foo; };" ;
testok "tdstruct2" , "interface test { typedef struct { int a; } foo; };" ;
testok "tdstruct3" , "interface test { typedef struct { int a; int b; } foo; };" ;
2007-01-05 18:20:23 +03:00
testfail "tdstruct4" , "interface test { typedef struct { int a, int b; } foo; };" ,
"<tdstruct4>:0: Syntax error near ','\n" ;
2005-12-25 17:11:59 +03:00
testok "struct1" , "interface test { struct x { }; };" ;
testok "struct2" , "interface test { struct x { int a; }; };" ;
testok "struct3" , "interface test { struct x { int a; int b; }; };" ;
2007-01-05 18:20:23 +03:00
testfail "struct4" , "interface test { struct x { int a, int b; }; };" ,
"<struct4>:0: Syntax error near ','\n" ;
testfail "struct5" , "interface test { struct { int a; } x; };" ,
"<struct5>:0: Syntax error near 'x'\n" ;
2005-12-25 02:32:50 +03:00
testok "tdunion1" , "interface test { typedef union { } a; };" ;
testok "tdunion2" , "interface test { typedef union { int a; } a; };" ;
2005-12-25 17:11:59 +03:00
testok "union1" , "interface test { union a { }; };" ;
testok "union2" , "interface test { union x { int a; }; };" ;
2007-01-05 18:20:23 +03:00
testfail "union3" , "interface test { union { int a; } x; };" ,
"<union3>:0: Syntax error near 'x'\n" ;
2005-12-25 02:32:50 +03:00
testok "typedef1" , "interface test { typedef int a; };" ;
2007-01-05 18:20:23 +03:00
testfail "typedef2" , "interface test { typedef x; };" ,
"<typedef2>:0: Syntax error near ';'\n" ;
2005-12-25 02:32:50 +03:00
testok "tdenum1" , "interface test { typedef enum { A=1, B=2, C} a; };" ;
2005-12-25 17:11:59 +03:00
testok "enum1" , "interface test { enum a { A=1, B=2, C}; };" ;
2007-01-05 18:20:23 +03:00
testfail "enum2" , "interface test { enum { A=1, B=2, C} a; };" ,
"<enum2>:0: Syntax error near 'a'\n" ;
2005-12-25 17:11:59 +03:00
testok "nested1" , "interface test { struct x { struct { int a; } z; }; };" ;
testok "nested2" , "interface test { struct x { struct y { int a; } z; }; };" ;
testok "bitmap1" , "interface test { bitmap x { a=1 }; };" ;
2005-12-25 17:59:39 +03:00
testok "unsigned" , "interface test { struct x { unsigned short y; }; };" ;
2007-02-18 19:21:28 +03:00
testok "struct-property" , "interface test { [public] struct x { short y; }; };" ;
2005-12-25 17:59:39 +03:00
testok "signed" , "interface test { struct x { signed short y; }; };" ;
testok "declarg" , "interface test { void test(struct { int x; } a); };" ;
2007-02-18 19:21:28 +03:00
testok "structarg" , "interface test { void test(struct a b); };" ;
testfail "structargmissing" , "interface test { void test(struct a); };" ,
"<structargmissing>:0: Syntax error near ')'\n" ;
2005-12-25 17:59:39 +03:00
testok "structqual" , "interface test { struct x { struct y z; }; };" ;
testok "unionqual" , "interface test { struct x { union y z; }; };" ;
testok "enumqual" , "interface test { struct x { enum y z; }; };" ;
testok "bitmapqual" , "interface test { struct x { bitmap y z; }; };" ;
testok "emptystructdecl" , "interface test { struct x; };" ;
testok "emptyenumdecl" , "interface test { enum x; };" ;
testok "emptytdstructdecl" , "interface test { typedef struct x y; };" ;
2006-11-17 01:11:32 +03:00
testok "import" , "import \"foo.idl\";" ;
testok "include" , "include \"foo.h\";" ;
2007-01-05 18:20:23 +03:00
testfail "import-noquotes" , "import foo.idl;" ,
"<import-noquotes>:0: Syntax error near 'foo'\n" ;
testfail "include-noquotes" , "include foo.idl;" ,
"<include-noquotes>:0: Syntax error near 'foo'\n" ;
2006-11-17 01:11:32 +03:00
testok "importlib" , "importlib \"foo.idl\";" ;
2007-01-05 18:20:23 +03:00
testfail "import-nosemicolon" , "import \"foo.idl\"" ,
"<import-nosemicolon>:0: Syntax error near 'foo.idl'\n" ;
2006-11-17 01:11:32 +03:00
testok "import-multiple" , "import \"foo.idl\", \"bar.idl\";" ;
testok "include-multiple" , "include \"foo.idl\", \"bar.idl\";" ;
2007-03-04 17:16:52 +03:00
testok "empty-struct" , "interface test { struct foo { }; }" ;
2007-03-05 03:03:44 +03:00
testok "typedef-double" , "interface test { typedef struct foo { } foo; }" ;
2007-08-31 04:03:54 +04:00
testok "cpp-quote" , "cpp_quote(\"bla\")" ;
2007-03-04 17:16:52 +03:00
my $ x = Parse::Pidl::IDL:: parse_string ( "interface foo { struct x {}; }" , "<foo>" ) ;
2009-08-12 12:24:01 +04:00
is_deeply ( $ x , [ {
'TYPE' = > 'INTERFACE' ,
'NAME' = > 'foo' ,
'DATA' = > [ {
'TYPE' = > 'STRUCT' ,
'NAME' = > 'x' ,
'ELEMENTS' = > [] ,
'FILE' = > '<foo>' ,
'LINE' = > 0
} ] ,
'FILE' = > '<foo>' ,
'LINE' = > 0
} ] ) ;
2007-03-04 17:16:52 +03:00
$ x = Parse::Pidl::IDL:: parse_string ( "interface foo { struct x; }" , "<foo>" ) ;
2009-08-12 12:24:01 +04:00
is_deeply ( $ x , [ {
'TYPE' = > 'INTERFACE' ,
'NAME' = > 'foo' ,
'DATA' = > [ {
'TYPE' = > 'STRUCT' ,
'NAME' = > 'x' ,
'FILE' = > '<foo>' ,
'LINE' = > 0
} ] ,
'FILE' = > '<foo>' ,
'LINE' = > 0
} ] ) ;
2007-08-31 04:03:54 +04:00
$ x = Parse::Pidl::IDL:: parse_string ( "cpp_quote(\"foobar\")" , "<quote>" ) ;
2009-08-12 12:24:01 +04:00
is_deeply ( $ x , [ {
'TYPE' = > 'CPP_QUOTE' ,
'DATA' = > '"foobar"' ,
'FILE' = > '<quote>' ,
'LINE' = > 0
} ] ) ;
2007-08-31 04:03:54 +04:00
2008-01-12 23:37:46 +03:00
# A typedef of a struct without body
$ x = Parse::Pidl::IDL:: parse_string ( "interface foo { typedef struct x y; }" , "<foo>" ) ;
2007-08-31 04:03:54 +04:00
2009-08-12 12:24:01 +04:00
is_deeply ( $ x , [ {
'TYPE' = > 'INTERFACE' ,
'NAME' = > 'foo' ,
'DATA' = > [ {
'TYPE' = > 'TYPEDEF' ,
'NAME' = > 'y' ,
2009-08-05 15:43:49 +04:00
'POINTERS' = > 0 ,
2009-08-12 12:24:01 +04:00
'DATA' = > {
'TYPE' = > 'STRUCT' ,
'NAME' = > 'x' ,
'FILE' = > '<foo>' ,
'LINE' = > 0 ,
} ,
'FILE' = > '<foo>' ,
'LINE' = > 0 ,
} ] ,
'FILE' = > '<foo>' ,
'LINE' = > 0
} ] ) ;
2008-01-12 23:37:46 +03:00
# A typedef of a struct with empty body
$ x = Parse::Pidl::IDL:: parse_string ( "interface foo { typedef struct {} y; }" , "<foo>" ) ;
2009-08-12 12:24:01 +04:00
is_deeply ( $ x , [ {
'TYPE' = > 'INTERFACE' ,
'NAME' = > 'foo' ,
'DATA' = > [ {
'TYPE' = > 'TYPEDEF' ,
'NAME' = > 'y' ,
2009-08-05 15:43:49 +04:00
'POINTERS' = > 0 ,
2009-08-12 12:24:01 +04:00
'DATA' = > {
'TYPE' = > 'STRUCT' ,
'ELEMENTS' = > [] ,
'FILE' = > '<foo>' ,
'LINE' = > 0
} ,
'FILE' = > '<foo>' ,
'LINE' = > 0
} ] ,
'FILE' = > '<foo>' ,
'LINE' = > 0
} ] ) ;
2008-01-13 01:38:05 +03:00
# A typedef of a bitmap with no body
$ x = Parse::Pidl::IDL:: parse_string ( "interface foo { typedef bitmap x y; }" , "<foo>" ) ;
2009-08-12 12:24:01 +04:00
is_deeply ( $ x , [ {
'TYPE' = > 'INTERFACE' ,
'NAME' = > 'foo' ,
'DATA' = > [ {
'TYPE' = > 'TYPEDEF' ,
'NAME' = > 'y' ,
2009-08-05 15:43:49 +04:00
'POINTERS' = > 0 ,
2009-08-12 12:24:01 +04:00
'DATA' = > {
'TYPE' = > 'BITMAP' ,
'NAME' = > 'x' ,
'FILE' = > '<foo>' ,
'LINE' = > 0
} ,
'FILE' = > '<foo>' ,
'LINE' = > 0
} ] ,
'FILE' = > '<foo>' ,
'LINE' = > 0
} ] ) ;
2008-01-13 02:05:24 +03:00
# A typedef of a union with no body
$ x = Parse::Pidl::IDL:: parse_string ( "interface foo { typedef union x y; }" , "<foo>" ) ;
2009-08-12 12:24:01 +04:00
is_deeply ( $ x , [ {
'TYPE' = > 'INTERFACE' ,
'NAME' = > 'foo' ,
'DATA' = > [ {
'TYPE' = > 'TYPEDEF' ,
'NAME' = > 'y' ,
2009-08-05 15:43:49 +04:00
'POINTERS' = > 0 ,
2009-08-12 12:24:01 +04:00
'DATA' = > {
'TYPE' = > 'UNION' ,
'NAME' = > 'x' ,
'FILE' = > '<foo>' ,
'LINE' = > 0
} ,
'FILE' = > '<foo>' ,
'LINE' = > 0
} ] ,
'FILE' = > '<foo>' ,
'LINE' = > 0
} ] ) ;