2 # (C) 2007 Jelmer Vernooij <jelmer@samba.org>
3 # Published under the GNU General Public License
4 # test parsing wireshark conformance files
8 use Test
::More tests
=> 40;
9 use FindBin
qw($RealBin);
12 use Parse::Pidl::Util qw(MyDumper);
14 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);
16 is("Access Mask", field2name("access_mask"));
17 is("Accessmask", field2name("AccessMask"));
19 my $x = new Parse::Pidl::Wireshark::NDR();
20 $x->PrintIdl("foo\nbar\n");
24 ", $x->{res}->{code});
26 is("bla_foo", StripPrefixes("bla_foo", []));
27 is("foo", StripPrefixes("bla_foo", ["bla"]));
28 is("foo_bla", StripPrefixes("foo_bla", ["bla"]));
30 $x = new Parse::Pidl::Wireshark::NDR();
31 $x->RegisterInterfaceHandoff({});
32 is($x->{res}->{code}, "");
33 ok(not defined($x->{hf_used}->{hf_bla_opnum}));
35 $x = new Parse::Pidl::Wireshark::NDR();
36 $x->{res}->{code} = "";
37 $x->RegisterInterfaceHandoff({UUID => "uuid", NAME => "bla"});
38 is($x->{res}->{code}, 'void proto_reg_handoff_dcerpc_bla(void)
40 dcerpc_init_uuid(proto_dcerpc_bla, ett_dcerpc_bla,
41 &uuid_dcerpc_bla, ver_dcerpc_bla,
42 bla_dissectors, hf_bla_opnum);
45 is($x->{hf_used}->{hf_bla_opnum}, 1);
47 $x->{conformance} = {};
49 $x->register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF, undef));
50 is_deeply($x->{conformance}, {
53 INDEX => "hf_bla_idx",
55 FILTER => "my.filter",
56 BASE_TYPE => "BASE_HEX",
57 FT_TYPE => "FT_UINT32",
64 fielddescription => {}
67 $x->{conformance} = { fielddescription => { hf_bla_idx => { DESCRIPTION => "Some Description" }}};
69 $x->register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF, undef));
70 is_deeply($x->{conformance}, {
73 DESCRIPTION => "Some Description",
79 INDEX => "hf_bla_idx",
81 FILTER => "my.filter",
82 BASE_TYPE => "BASE_HEX",
83 FT_TYPE => "FT_UINT32",
85 BLURB => "Some Description",
92 $x->{conformance} = { fielddescription => { hf_bla_idx => { DESCRIPTION => "Some Description" }}};
94 $x->register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF,
95 "Actual Description"));
96 is_deeply($x->{conformance}, {
98 hf_bla_idx => { DESCRIPTION => "Some Description" }
102 INDEX => "hf_bla_idx",
104 FILTER => "my.filter",
105 BASE_TYPE => "BASE_HEX",
106 FT_TYPE => "FT_UINT32",
107 VALSSTRING => "NULL",
108 BLURB => "Actual Description",
117 $x->{conformance} = { hf_renames => { "hf_bla_idx" => { NEWNAME => "hf_bloe_idx" } } };
118 $x->register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF, undef);
119 is_deeply($x->{conformance}, {
120 hf_renames => { hf_bla_idx => { USED => 1, NEWNAME => "hf_bloe_idx" } } });
122 $x->{hf_used} = { hf_bla => 1 };
123 test_warnings("", sub {
124 $x->CheckUsed({ header_fields => { foo => { INDEX => "hf_bla" }}})});
127 test_warnings("hf field `hf_bla' not used\n", sub {
128 $x->CheckUsed({ header_fields => { foo => { INDEX => "hf_bla" }}})});
130 test_warnings("hf field `hf_id' not used\n",
131 sub { $x->CheckUsed({
135 NEWNAME => "hf_newid",
141 test_warnings("dissector param never used\n",
142 sub { $x->CheckUsed({
151 test_warnings("description never used\n",
152 sub { $x->CheckUsed({
153 fielddescription => {
160 test_warnings("import never used\n",
161 sub { $x->CheckUsed({
169 test_warnings("nofile:1: type never used\n",
170 sub { $x->CheckUsed({
174 POS => { FILE => "nofile", LINE => 1 }
179 test_warnings("True/False description never used\n",
180 sub { $x->CheckUsed({
188 $x = new Parse::Pidl::Wireshark::NDR();
189 $x->ProcessImport("security", "bla");
190 is($x->{res}->{hdr}, "#include \"packet-dcerpc-bla.h\"\n\n");
192 $x = new Parse::Pidl::Wireshark::NDR();
193 $x->ProcessImport("\"bla.idl\"", "\"foo.idl\"");
194 is($x->{res}->{hdr}, "#include \"packet-dcerpc-bla.h\"\n" .
195 "#include \"packet-dcerpc-foo.h\"\n\n");
197 $x = new Parse::Pidl::Wireshark::NDR();
198 $x->ProcessInclude("foo.h", "bla.h", "bar.h");
199 is($x->{res}->{hdr}, "#include \"foo.h\"\n" .
200 "#include \"bla.h\"\n" .
201 "#include \"bar.h\"\n\n");
203 $x->{conformance} = {types => { bla => "brainslug" } };
204 is("brainslug", $x->find_type("bla"));
206 is(DumpEttList(["ett_t1", "ett_bla"]),
207 "\tstatic gint *ett[] = {\n" .
212 is(DumpEttList(), "\tstatic gint *ett[] = {\n\t};\n");
213 is(DumpEttList(["bla"]), "\tstatic gint *ett[] = {\n\t\t&bla,\n\t};\n");
215 is(DumpEttDeclaration(["void", "zoid"]),
216 "\n/* Ett declarations */\n" .
217 "static gint void = -1;\n" .
218 "static gint zoid = -1;\n" .
221 is(DumpEttDeclaration(), "\n/* Ett declarations */\n\n");
223 $x->{conformance} = {
225 hf_bla => { INDEX => "hf_bla", NAME => "Bla", FILTER => "bla.field", FT_TYPE => "FT_UINT32", BASE_TYPE => "BASE_DEC", VALSSTRING => "NULL", MASK => 0xFF, BLURB => "NULL" }
229 is($x->DumpHfList(), "\tstatic hf_register_info hf[] = {
231 { \"Bla\", \"bla.field\", FT_UINT32, BASE_DEC, NULL, 255, \"NULL\", HFILL }},
235 is($x->DumpHfDeclaration(), "
236 /* Header field declarations */
237 static gint hf_bla = -1;
241 is(DumpFunctionTable({
243 FUNCTIONS => [ { NAME => "fn1", OPNUM => 3 }, { NAME => "someif_fn2", OPNUM => 2 } ] }),
244 'static dcerpc_sub_dissector someif_dissectors[] = {
246 someif_dissect_fn1_request, someif_dissect_fn1_response},
248 someif_dissect_fn2_request, someif_dissect_fn2_response},
249 { 0, NULL, NULL, NULL }
253 $x->{conformance} = {};
254 $x->register_type("bla_type", "dissect_bla", "FT_UINT32", "BASE_HEX", 0xFF, "NULL", 4);
255 is_deeply($x->{conformance}, {
259 DISSECTOR_NAME => "dissect_bla",
260 FT_TYPE => "FT_UINT32",
261 BASE_TYPE => "BASE_HEX",
263 VALSSTRING => "NULL",
271 $x->register_ett("name");
272 is_deeply($x->{ett}, ["name"]);
273 $x->register_ett("leela");
274 is_deeply($x->{ett}, ["name", "leela"]);