source: branches/samba-3.5.x/pidl/tests/wireshark-ndr.pl@ 1036

Last change on this file since 1036 was 414, checked in by Herwig Bauernfeind, 15 years ago

Samba 3.5.0: Initial import

File size: 7.0 KB
Line 
1#!/usr/bin/perl
2# (C) 2007 Jelmer Vernooij <jelmer@samba.org>
3# Published under the GNU General Public License
4# test parsing wireshark conformance files
5use strict;
6use warnings;
7
8use Test::More tests => 40;
9use FindBin qw($RealBin);
10use lib "$RealBin";
11use Util;
12use Parse::Pidl::Util qw(MyDumper);
13use strict;
14use 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);
15
16is("Access Mask", field2name("access_mask"));
17is("Accessmask", field2name("AccessMask"));
18
19my $x = new Parse::Pidl::Wireshark::NDR();
20$x->PrintIdl("foo\nbar\n");
21is("/* IDL: foo */
22/* IDL: bar */
23
24", $x->{res}->{code});
25
26is("bla_foo", StripPrefixes("bla_foo", []));
27is("foo", StripPrefixes("bla_foo", ["bla"]));
28is("foo_bla", StripPrefixes("foo_bla", ["bla"]));
29
30$x = new Parse::Pidl::Wireshark::NDR();
31$x->RegisterInterfaceHandoff({});
32is($x->{res}->{code}, "");
33ok(not defined($x->{hf_used}->{hf_bla_opnum}));
34
35$x = new Parse::Pidl::Wireshark::NDR();
36$x->{res}->{code} = "";
37$x->RegisterInterfaceHandoff({UUID => "uuid", NAME => "bla"});
38is($x->{res}->{code}, 'void proto_reg_handoff_dcerpc_bla(void)
39{
40 dcerpc_init_uuid(proto_dcerpc_bla, ett_dcerpc_bla,
41 &uuid_dcerpc_bla, ver_dcerpc_bla,
42 bla_dissectors, hf_bla_opnum);
43}
44');
45is($x->{hf_used}->{hf_bla_opnum}, 1);
46
47$x->{conformance} = {};
48is("hf_bla_idx",
49 $x->register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF, undef));
50is_deeply($x->{conformance}, {
51 header_fields => {
52 "hf_bla_idx" => {
53 INDEX => "hf_bla_idx",
54 NAME => "bla",
55 FILTER => "my.filter",
56 BASE_TYPE => "BASE_HEX",
57 FT_TYPE => "FT_UINT32",
58 VALSSTRING => "NULL",
59 BLURB => undef,
60 MASK => 0xF
61 }
62 },
63 hf_renames => {},
64 fielddescription => {}
65});
66
67$x->{conformance} = { fielddescription => { hf_bla_idx => { DESCRIPTION => "Some Description" }}};
68is("hf_bla_idx",
69 $x->register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF, undef));
70is_deeply($x->{conformance}, {
71 fielddescription => {
72 hf_bla_idx => {
73 DESCRIPTION => "Some Description",
74 USED => 1
75 }
76 },
77 header_fields => {
78 "hf_bla_idx" => {
79 INDEX => "hf_bla_idx",
80 NAME => "bla",
81 FILTER => "my.filter",
82 BASE_TYPE => "BASE_HEX",
83 FT_TYPE => "FT_UINT32",
84 VALSSTRING => "NULL",
85 BLURB => "Some Description",
86 MASK => 0xF
87 }
88 },
89 hf_renames => {},
90});
91
92$x->{conformance} = { fielddescription => { hf_bla_idx => { DESCRIPTION => "Some Description" }}};
93is("hf_bla_idx",
94 $x->register_hf_field("hf_bla_idx", "bla", "my.filter", "FT_UINT32", "BASE_HEX", "NULL", 0xF,
95 "Actual Description"));
96is_deeply($x->{conformance}, {
97 fielddescription => {
98 hf_bla_idx => { DESCRIPTION => "Some Description" }
99 },
100 header_fields => {
101 "hf_bla_idx" => {
102 INDEX => "hf_bla_idx",
103 NAME => "bla",
104 FILTER => "my.filter",
105 BASE_TYPE => "BASE_HEX",
106 FT_TYPE => "FT_UINT32",
107 VALSSTRING => "NULL",
108 BLURB => "Actual Description",
109 MASK => 0xF
110 }
111 },
112 hf_renames => {},
113});
114
115
116
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);
119is_deeply($x->{conformance}, {
120 hf_renames => { hf_bla_idx => { USED => 1, NEWNAME => "hf_bloe_idx" } } });
121
122$x->{hf_used} = { hf_bla => 1 };
123test_warnings("", sub {
124 $x->CheckUsed({ header_fields => { foo => { INDEX => "hf_bla" }}})});
125
126$x->{hf_used} = { };
127test_warnings("hf field `hf_bla' not used\n", sub {
128 $x->CheckUsed({ header_fields => { foo => { INDEX => "hf_bla" }}})});
129
130test_warnings("hf field `hf_id' not used\n",
131 sub { $x->CheckUsed({
132 hf_renames => {
133 hf_id => {
134 OLDNAME => "hf_id",
135 NEWNAME => "hf_newid",
136 USED => 0
137 }
138 }
139}); } );
140
141test_warnings("dissector param never used\n",
142 sub { $x->CheckUsed({
143 dissectorparams => {
144 dissect_foo => {
145 PARAM => 42,
146 USED => 0
147 }
148 }
149}); } );
150
151test_warnings("description never used\n",
152 sub { $x->CheckUsed({
153 fielddescription => {
154 hf_bla => {
155 USED => 0
156 }
157 }
158}); } );
159
160test_warnings("import never used\n",
161 sub { $x->CheckUsed({
162 imports => {
163 bla => {
164 USED => 0
165 }
166 }
167}); } );
168
169test_warnings("nofile:1: type never used\n",
170 sub { $x->CheckUsed({
171 types => {
172 bla => {
173 USED => 0,
174 POS => { FILE => "nofile", LINE => 1 }
175 }
176 }
177}); } );
178
179test_warnings("True/False description never used\n",
180 sub { $x->CheckUsed({
181 tfs => {
182 hf_bloe => {
183 USED => 0
184 }
185 }
186}); } );
187
188$x = new Parse::Pidl::Wireshark::NDR();
189$x->ProcessImport("security", "bla");
190is($x->{res}->{hdr}, "#include \"packet-dcerpc-bla.h\"\n\n");
191
192$x = new Parse::Pidl::Wireshark::NDR();
193$x->ProcessImport("\"bla.idl\"", "\"foo.idl\"");
194is($x->{res}->{hdr}, "#include \"packet-dcerpc-bla.h\"\n" .
195 "#include \"packet-dcerpc-foo.h\"\n\n");
196
197$x = new Parse::Pidl::Wireshark::NDR();
198$x->ProcessInclude("foo.h", "bla.h", "bar.h");
199is($x->{res}->{hdr}, "#include \"foo.h\"\n" .
200 "#include \"bla.h\"\n" .
201 "#include \"bar.h\"\n\n");
202
203$x->{conformance} = {types => { bla => "brainslug" } };
204is("brainslug", $x->find_type("bla"));
205
206is(DumpEttList(["ett_t1", "ett_bla"]),
207 "\tstatic gint *ett[] = {\n" .
208 "\t\t&ett_t1,\n" .
209 "\t\t&ett_bla,\n" .
210 "\t};\n");
211
212is(DumpEttList(), "\tstatic gint *ett[] = {\n\t};\n");
213is(DumpEttList(["bla"]), "\tstatic gint *ett[] = {\n\t\t&bla,\n\t};\n");
214
215is(DumpEttDeclaration(["void", "zoid"]),
216 "\n/* Ett declarations */\n" .
217 "static gint void = -1;\n" .
218 "static gint zoid = -1;\n" .
219 "\n");
220
221is(DumpEttDeclaration(), "\n/* Ett declarations */\n\n");
222
223$x->{conformance} = {
224 header_fields => {
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" }
226 }
227};
228
229is($x->DumpHfList(), "\tstatic hf_register_info hf[] = {
230 { &hf_bla,
231 { \"Bla\", \"bla.field\", FT_UINT32, BASE_DEC, NULL, 255, \"NULL\", HFILL }},
232 };
233");
234
235is($x->DumpHfDeclaration(), "
236/* Header field declarations */
237static gint hf_bla = -1;
238
239");
240
241is(DumpFunctionTable({
242 NAME => "someif",
243 FUNCTIONS => [ { NAME => "fn1", OPNUM => 3 }, { NAME => "someif_fn2", OPNUM => 2 } ] }),
244'static dcerpc_sub_dissector someif_dissectors[] = {
245 { 3, "fn1",
246 someif_dissect_fn1_request, someif_dissect_fn1_response},
247 { 2, "fn2",
248 someif_dissect_fn2_request, someif_dissect_fn2_response},
249 { 0, NULL, NULL, NULL }
250};
251');
252
253$x->{conformance} = {};
254$x->register_type("bla_type", "dissect_bla", "FT_UINT32", "BASE_HEX", 0xFF, "NULL", 4);
255is_deeply($x->{conformance}, {
256 types => {
257 bla_type => {
258 NAME => "bla_type",
259 DISSECTOR_NAME => "dissect_bla",
260 FT_TYPE => "FT_UINT32",
261 BASE_TYPE => "BASE_HEX",
262 MASK => 255,
263 VALSSTRING => "NULL",
264 ALIGNMENT => 4
265 }
266 }
267 }
268);
269
270$x->{ett} = [];
271$x->register_ett("name");
272is_deeply($x->{ett}, ["name"]);
273$x->register_ett("leela");
274is_deeply($x->{ett}, ["name", "leela"]);
Note: See TracBrowser for help on using the repository browser.