2007-02-18 02:38:57 +03:00
#!/usr/bin/perl
# (C) 2007 Jelmer Vernooij <jelmer@samba.org>
# Published under the GNU General Public License
# test parsing wireshark conformance files
use strict ;
use warnings ;
2007-02-28 00:37:31 +03:00
use Test::More tests = > 40 ;
2007-02-18 02:38:57 +03:00
use FindBin qw( $RealBin ) ;
use lib "$RealBin" ;
use Util ;
use Parse::Pidl::Util qw( MyDumper ) ;
2007-04-22 17:57:07 +04:00
use strict ;
use Parse::Pidl::Wireshark::NDR qw( field2name %res PrintIdl StripPrefixes RegisterInterfaceHandoff register_hf_field ProcessImport ProcessInclude find_type DumpEttList DumpEttDeclaration DumpHfList DumpHfDeclaration DumpFunctionTable register_type register_ett ) ;
2007-02-18 02:38:57 +03:00
is ( "Access Mask" , field2name ( "access_mask" ) ) ;
is ( "Accessmask" , field2name ( "AccessMask" ) ) ;
2007-04-22 17:57:07 +04:00
my $ x = new Parse::Pidl::Wireshark:: NDR ( ) ;
$ x - > PrintIdl ( "foo\nbar\n" ) ;
2007-02-18 02:38:57 +03:00
is ( " /* IDL: foo */
/* IDL: bar */
2007-04-22 17:57:07 +04:00
" , $ x - > { res } - > { code } ) ;
2007-02-25 12:55:57 +03:00
is ( "bla_foo" , StripPrefixes ( "bla_foo" , [] ) ) ;
is ( "foo" , StripPrefixes ( "bla_foo" , [ "bla" ] ) ) ;
is ( "foo_bla" , StripPrefixes ( "foo_bla" , [ "bla" ] ) ) ;
2007-02-26 04:03:19 +03:00
2007-04-22 17:57:07 +04:00
$ x = new Parse::Pidl::Wireshark:: NDR ( ) ;
$ x - > RegisterInterfaceHandoff ( { } ) ;
is ( $ x - > { res } - > { code } , "" ) ;
ok ( not defined ( $ x - > { hf_used } - > { hf_bla_opnum } ) ) ;
2007-02-26 04:03:19 +03:00
2007-04-22 17:57:07 +04:00
$ x = new Parse::Pidl::Wireshark:: NDR ( ) ;
$ x - > { res } - > { code } = "" ;
$ x - > RegisterInterfaceHandoff ( { UUID = > "uuid" , NAME = > "bla" } ) ;
is ( $ x - > { res } - > { code } , ' void proto_reg_handoff_dcerpc_bla ( void )
2007-02-26 04:03:19 +03:00
{
dcerpc_init_uuid ( proto_dcerpc_bla , ett_dcerpc_bla ,
& uuid_dcerpc_bla , ver_dcerpc_bla ,
bla_dissectors , hf_bla_opnum ) ;
}
' ) ;
2007-04-22 17:57:07 +04:00
is ( $ x - > { hf_used } - > { hf_bla_opnum } , 1 ) ;
2007-02-26 04:03:19 +03:00
2007-04-22 17:57:07 +04:00
$ x - > { conformance } = { } ;
2007-02-28 00:37:31 +03:00
is ( "hf_bla_idx" ,
2007-04-22 17:57:07 +04:00
$ x - > register_hf_field ( "hf_bla_idx" , "bla" , "my.filter" , "FT_UINT32" , "BASE_HEX" , "NULL" , 0xF , undef ) ) ;
is_deeply ( $ x - > { conformance } , {
2007-02-26 04:03:19 +03:00
header_fields = > {
"hf_bla_idx" = > {
INDEX = > "hf_bla_idx" ,
NAME = > "bla" ,
FILTER = > "my.filter" ,
BASE_TYPE = > "BASE_HEX" ,
FT_TYPE = > "FT_UINT32" ,
VALSSTRING = > "NULL" ,
BLURB = > undef ,
MASK = > 0xF
}
} ,
hf_renames = > { } ,
fielddescription = > { }
} ) ;
2007-04-22 17:57:07 +04:00
$ x - > { conformance } = { fielddescription = > { hf_bla_idx = > { DESCRIPTION = > "Some Description" } } } ;
2007-02-28 00:37:31 +03:00
is ( "hf_bla_idx" ,
2007-04-22 17:57:07 +04:00
$ x - > register_hf_field ( "hf_bla_idx" , "bla" , "my.filter" , "FT_UINT32" , "BASE_HEX" , "NULL" , 0xF , undef ) ) ;
is_deeply ( $ x - > { conformance } , {
2007-02-28 00:37:31 +03:00
fielddescription = > {
hf_bla_idx = > {
DESCRIPTION = > "Some Description" ,
USED = > 1
}
} ,
header_fields = > {
"hf_bla_idx" = > {
INDEX = > "hf_bla_idx" ,
NAME = > "bla" ,
FILTER = > "my.filter" ,
BASE_TYPE = > "BASE_HEX" ,
FT_TYPE = > "FT_UINT32" ,
VALSSTRING = > "NULL" ,
BLURB = > "Some Description" ,
MASK = > 0xF
}
} ,
hf_renames = > { } ,
} ) ;
2007-04-22 17:57:07 +04:00
$ x - > { conformance } = { fielddescription = > { hf_bla_idx = > { DESCRIPTION = > "Some Description" } } } ;
2007-02-28 00:37:31 +03:00
is ( "hf_bla_idx" ,
2007-04-22 17:57:07 +04:00
$ x - > register_hf_field ( "hf_bla_idx" , "bla" , "my.filter" , "FT_UINT32" , "BASE_HEX" , "NULL" , 0xF ,
2007-02-28 00:37:31 +03:00
"Actual Description" ) ) ;
2007-04-22 17:57:07 +04:00
is_deeply ( $ x - > { conformance } , {
2007-02-28 00:37:31 +03:00
fielddescription = > {
hf_bla_idx = > { DESCRIPTION = > "Some Description" }
} ,
header_fields = > {
"hf_bla_idx" = > {
INDEX = > "hf_bla_idx" ,
NAME = > "bla" ,
FILTER = > "my.filter" ,
BASE_TYPE = > "BASE_HEX" ,
FT_TYPE = > "FT_UINT32" ,
VALSSTRING = > "NULL" ,
BLURB = > "Actual Description" ,
MASK = > 0xF
}
} ,
hf_renames = > { } ,
} ) ;
2007-04-22 17:57:07 +04:00
$ x - > { conformance } = { hf_renames = > { "hf_bla_idx" = > { NEWNAME = > "hf_bloe_idx" } } } ;
$ x - > register_hf_field ( "hf_bla_idx" , "bla" , "my.filter" , "FT_UINT32" , "BASE_HEX" , "NULL" , 0xF , undef ) ;
is_deeply ( $ x - > { conformance } , {
2007-02-28 00:37:31 +03:00
hf_renames = > { hf_bla_idx = > { USED = > 1 , NEWNAME = > "hf_bloe_idx" } } } ) ;
2007-04-22 17:57:07 +04:00
$ x - > { hf_used } = { hf_bla = > 1 } ;
2007-02-26 04:03:19 +03:00
test_warnings ( "" , sub {
2007-04-22 17:57:07 +04:00
$ x - > CheckUsed ( { header_fields = > { foo = > { INDEX = > "hf_bla" } } } ) } ) ;
2007-02-26 04:03:19 +03:00
2007-04-22 17:57:07 +04:00
$ x - > { hf_used } = { } ;
2007-02-26 20:43:01 +03:00
test_warnings ( "hf field `hf_bla' not used\n" , sub {
2007-04-22 17:57:07 +04:00
$ x - > CheckUsed ( { header_fields = > { foo = > { INDEX = > "hf_bla" } } } ) } ) ;
2007-02-27 23:35:56 +03:00
2007-02-28 00:37:31 +03:00
test_warnings ( "hf field `hf_id' not used\n" ,
2007-04-22 17:57:07 +04:00
sub { $ x - > CheckUsed ( {
2007-02-28 00:37:31 +03:00
hf_renames = > {
hf_id = > {
OLDNAME = > "hf_id" ,
NEWNAME = > "hf_newid" ,
USED = > 0
}
}
} ) ; } ) ;
test_warnings ( "dissector param never used\n" ,
2007-04-22 17:57:07 +04:00
sub { $ x - > CheckUsed ( {
2007-02-28 00:37:31 +03:00
dissectorparams = > {
dissect_foo = > {
PARAM = > 42 ,
USED = > 0
}
}
} ) ; } ) ;
test_warnings ( "description never used\n" ,
2007-04-22 17:57:07 +04:00
sub { $ x - > CheckUsed ( {
2007-02-28 00:37:31 +03:00
fielddescription = > {
hf_bla = > {
USED = > 0
}
}
} ) ; } ) ;
test_warnings ( "import never used\n" ,
2007-04-22 17:57:07 +04:00
sub { $ x - > CheckUsed ( {
2007-02-28 00:37:31 +03:00
imports = > {
bla = > {
USED = > 0
}
}
} ) ; } ) ;
test_warnings ( "nofile:1: type never used\n" ,
2007-04-22 17:57:07 +04:00
sub { $ x - > CheckUsed ( {
2007-02-28 00:37:31 +03:00
types = > {
bla = > {
USED = > 0 ,
POS = > { FILE = > "nofile" , LINE = > 1 }
}
}
} ) ; } ) ;
test_warnings ( "True/False description never used\n" ,
2007-04-22 17:57:07 +04:00
sub { $ x - > CheckUsed ( {
2007-02-28 00:37:31 +03:00
tfs = > {
hf_bloe = > {
USED = > 0
}
}
} ) ; } ) ;
2007-04-22 17:57:07 +04:00
$ x = new Parse::Pidl::Wireshark:: NDR ( ) ;
$ x - > ProcessImport ( "security" , "bla" ) ;
is ( $ x - > { res } - > { hdr } , "#include \"packet-dcerpc-bla.h\"\n\n" ) ;
2007-02-27 23:35:56 +03:00
2007-04-22 17:57:07 +04:00
$ x = new Parse::Pidl::Wireshark:: NDR ( ) ;
$ x - > ProcessImport ( "\"bla.idl\"" , "\"foo.idl\"" ) ;
is ( $ x - > { res } - > { hdr } , "#include \"packet-dcerpc-bla.h\"\n" .
2007-02-27 23:35:56 +03:00
"#include \"packet-dcerpc-foo.h\"\n\n" ) ;
2007-04-22 17:57:07 +04:00
$ x = new Parse::Pidl::Wireshark:: NDR ( ) ;
$ x - > ProcessInclude ( "foo.h" , "bla.h" , "bar.h" ) ;
is ( $ x - > { res } - > { hdr } , "#include \"foo.h\"\n" .
2007-02-27 23:35:56 +03:00
"#include \"bla.h\"\n" .
"#include \"bar.h\"\n\n" ) ;
2007-04-22 17:57:07 +04:00
$ x - > { conformance } = { types = > { bla = > "brainslug" } } ;
is ( "brainslug" , $ x - > find_type ( "bla" ) ) ;
2007-02-27 23:35:56 +03:00
2007-04-22 17:57:07 +04:00
is ( DumpEttList ( [ "ett_t1" , "ett_bla" ] ) ,
2007-02-27 23:35:56 +03:00
"\tstatic gint *ett[] = {\n" .
"\t\t&ett_t1,\n" .
"\t\t&ett_bla,\n" .
"\t};\n" ) ;
is ( DumpEttList ( ) , "\tstatic gint *ett[] = {\n\t};\n" ) ;
2007-04-22 17:57:07 +04:00
is ( DumpEttList ( [ "bla" ] ) , "\tstatic gint *ett[] = {\n\t\t&bla,\n\t};\n" ) ;
2007-02-27 23:35:56 +03:00
2007-04-22 17:57:07 +04:00
is ( DumpEttDeclaration ( [ "void" , "zoid" ] ) ,
2007-02-27 23:35:56 +03:00
"\n/* Ett declarations */\n" .
"static gint void = -1;\n" .
"static gint zoid = -1;\n" .
"\n" ) ;
is ( DumpEttDeclaration ( ) , "\n/* Ett declarations */\n\n" ) ;
2007-04-22 17:57:07 +04:00
$ x - > { conformance } = {
2007-02-27 23:35:56 +03:00
header_fields = > {
hf_bla = > { INDEX = > "hf_bla" , NAME = > "Bla" , FILTER = > "bla.field" , FT_TYPE = > "FT_UINT32" , BASE_TYPE = > "BASE_DEC" , VALSSTRING = > "NULL" , MASK = > 0xFF , BLURB = > "NULL" }
}
} ;
2007-04-22 17:57:07 +04:00
is ( $ x - > DumpHfList ( ) , " \ tstatic hf_register_info hf [] = {
2007-02-27 23:35:56 +03:00
{ & hf_bla ,
{ \ " Bla \ " , \ " bla . field \ " , FT_UINT32 , BASE_DEC , NULL , 255 , \ " NULL \ " , HFILL } } ,
} ;
" ) ;
2007-04-22 17:57:07 +04:00
is ( $ x - > DumpHfDeclaration ( ) , "
2007-02-27 23:35:56 +03:00
/* Header field declarations */
2007-04-22 17:57:07 +04:00
static gint hf_bla = - 1 ;
2007-02-27 23:35:56 +03:00
" ) ;
is ( DumpFunctionTable ( {
NAME = > "someif" ,
FUNCTIONS = > [ { NAME = > "fn1" , OPNUM = > 3 } , { NAME = > "someif_fn2" , OPNUM = > 2 } ] } ) ,
' static dcerpc_sub_dissector someif_dissectors [] = {
{ 3 , "fn1" ,
someif_dissect_fn1_request , someif_dissect_fn1_response } ,
{ 2 , "fn2" ,
someif_dissect_fn2_request , someif_dissect_fn2_response } ,
{ 0 , NULL , NULL , NULL }
} ;
' ) ;
2007-02-28 00:37:31 +03:00
2007-04-22 17:57:07 +04:00
$ x - > { conformance } = { } ;
$ x - > register_type ( "bla_type" , "dissect_bla" , "FT_UINT32" , "BASE_HEX" , 0xFF , "NULL" , 4 ) ;
is_deeply ( $ x - > { conformance } , {
2007-02-28 00:37:31 +03:00
types = > {
bla_type = > {
NAME = > "bla_type" ,
DISSECTOR_NAME = > "dissect_bla" ,
FT_TYPE = > "FT_UINT32" ,
BASE_TYPE = > "BASE_HEX" ,
MASK = > 255 ,
VALSSTRING = > "NULL" ,
ALIGNMENT = > 4
}
}
}
) ;
2007-04-22 17:57:07 +04:00
$ x - > { ett } = [] ;
$ x - > register_ett ( "name" ) ;
is_deeply ( $ x - > { ett } , [ "name" ] ) ;
$ x - > register_ett ( "leela" ) ;
is_deeply ( $ x - > { ett } , [ "name" , "leela" ] ) ;