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);
13 use Parse
::Pidl
::Wireshark
::NDR
qw(field2name %res PrintIdl StripPrefixes %hf_used RegisterInterfaceHandoff $conformance register_hf_field CheckUsed ProcessImport ProcessInclude find_type DumpEttList DumpEttDeclaration DumpHfList DumpHfDeclaration DumpFunctionTable register_type @ett register_ett);
15 is("Access Mask", field2name("access_mask"));
16 is("Accessmask", field2name("AccessMask"));
19 PrintIdl("foo\nbar\n");
25 is("bla_foo", StripPrefixes("bla_foo", []));
26 is("foo", StripPrefixes("bla_foo", ["bla"]));
27 is("foo_bla", StripPrefixes("foo_bla", ["bla"]));
31 RegisterInterfaceHandoff({});
33 ok(not defined($hf_used{hf_bla_opnum}));
37 RegisterInterfaceHandoff({UUID => "uuid", NAME => "bla"});
38 is($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($hf_used{hf_bla_opnum}, 1);
49 register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF, undef));
50 is_deeply($conformance, {
53 INDEX => "hf_bla_idx",
55 FILTER => "my.filter",
56 BASE_TYPE => "BASE_HEX",
57 FT_TYPE => "FT_UINT32",
64 fielddescription => {}
67 $conformance = { fielddescription => { hf_bla_idx => { DESCRIPTION => "Some Description" }}};
69 register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF, undef));
70 is_deeply($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 $conformance = { fielddescription => { hf_bla_idx => { DESCRIPTION => "Some Description" }}};
94 register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF,
95 "Actual Description"));
96 is_deeply($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 $conformance = { hf_renames => { "hf_bla_idx" => { NEWNAME => "hf_bloe_idx" } } };
118 register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF, undef);
119 is_deeply($conformance, {
120 hf_renames => { hf_bla_idx => { USED => 1, NEWNAME => "hf_bloe_idx" } } });
122 %hf_used = ( hf_bla => 1 );
123 test_warnings("", sub {
124 CheckUsed({ header_fields => { foo => { INDEX => "hf_bla" }}})});
127 test_warnings("hf field `hf_bla' not used\n", sub {
128 CheckUsed({ header_fields => { foo => { INDEX => "hf_bla" }}})});
130 test_warnings("hf field `hf_id' not used\n",
135 NEWNAME => "hf_newid",
141 test_warnings("dissector param never used\n",
151 test_warnings("description never used\n",
153 fielddescription => {
160 test_warnings("import never used\n",
169 test_warnings("nofile:1: type never used\n",
174 POS => { FILE => "nofile", LINE => 1 }
179 test_warnings("True/False description never used\n",
189 ProcessImport("security", "bla");
190 is($res{hdr}, "#include \"packet-dcerpc-bla.h\"\n\n");
193 ProcessImport("\"bla.idl\"", "\"foo.idl\"");
194 is($res{hdr}, "#include \"packet-dcerpc-bla.h\"\n" .
195 "#include \"packet-dcerpc-foo.h\"\n\n");
198 ProcessInclude("foo.h", "bla.h", "bar.h");
199 is($res{hdr}, "#include \"foo.h\"\n" .
200 "#include \"bla.h\"\n" .
201 "#include \"bar.h\"\n\n");
203 $conformance = {types => { bla => "brainslug" } };
204 is("brainslug", 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");
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(DumpHfList(), "\tstatic hf_register_info hf[] = {
231 { \"Bla\", \"bla.field\", FT_UINT32, BASE_DEC, NULL, 255, \"NULL\", HFILL }},
235 is(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 }
254 register_type("bla_type", "dissect_bla", "FT_UINT32", "BASE_HEX", 0xFF, "NULL", 4);
255 is_deeply($conformance, {
259 DISSECTOR_NAME => "dissect_bla",
260 FT_TYPE => "FT_UINT32",
261 BASE_TYPE => "BASE_HEX",
263 VALSSTRING => "NULL",
271 register_ett("name");
272 is_deeply(\@ett, ["name"]);
273 register_ett("leela");
274 is_deeply(\@ett, ["name", "leela"]);