summaryrefslogtreecommitdiffstats
path: root/pidl/tests/wireshark-conf.pl
blob: 9da5c7d1ed901a3320fe70de5e8eb4f0ac51c129 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/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;

use Test::More tests => 49;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
use Parse::Pidl::Util qw(MyDumper);
use Parse::Pidl::Wireshark::Conformance qw(ReadConformanceFH valid_ft_type valid_base_type);

sub parse_conf($)
{
	my $str = shift;
    open(TMP, "+>", undef) or die("unable to open temp file");
	print TMP $str;
	seek(TMP, 0, 0);
	my $data = {};
	ReadConformanceFH(*TMP, $data, "nofile") or return undef;
	close(TMP);
	return $data;
}

ok(parse_conf("\n"), undef);
ok(parse_conf(" \n"), undef);
ok(parse_conf("CODE START\nCODE END\n"));
test_warnings("nofile:1: Expecting CODE END\n", sub { is(parse_conf("CODE START\n"), undef); });
ok(parse_conf("#foobar\n"), undef);
test_warnings("nofile:1: Unknown command `foobar'\n",
	sub { ok(parse_conf("foobar\n"), undef); });

test_warnings("nofile:1: incomplete HF_RENAME command\n",
	sub { parse_conf("HF_RENAME\n"); });

is_deeply(parse_conf("HF_RENAME foo bar\n")->{hf_renames}->{foo}, 
	{ OLDNAME => "foo", NEWNAME => "bar", POS => {FILE => "nofile", LINE => 1}, USED => 0});

is_deeply(parse_conf("NOEMIT\n"), { "noemit_dissector" => 1 });
is_deeply(parse_conf("NOEMIT foo\n"), { "noemit" => { "foo" => 1 } });

test_warnings("nofile:1: incomplete MANUAL command\n",
	sub { parse_conf("MANUAL\n"); } );

is_deeply(parse_conf("MANUAL foo\n"), { manual => {foo => 1}});

test_errors("nofile:1: incomplete INCLUDE command\n",
	sub { parse_conf("INCLUDE\n"); } );

test_warnings("nofile:1: incomplete FIELD_DESCRIPTION command\n",
	sub { parse_conf("FIELD_DESCRIPTION foo\n"); });

is_deeply(parse_conf("FIELD_DESCRIPTION foo \"my description\"\n"),
	{ fielddescription => { foo => { DESCRIPTION => "\"my description\"", POS => { FILE => "nofile", LINE => 1}, USED => 0 }}});

is_deeply(parse_conf("FIELD_DESCRIPTION foo my description\n"),
	{ fielddescription => { foo => { DESCRIPTION => "my", POS => { FILE => "nofile", LINE => 1}, USED => 0 }}});

is_deeply(parse_conf("CODE START\ndata\nCODE END\n"), { override => "data\n" });
is_deeply(parse_conf("CODE START\ndata\nmore data\nCODE END\n"), { override => "data\nmore data\n" });
test_warnings("nofile:1: Unknown command `CODE'\n",
	sub { parse_conf("CODE END\n"); } );

is_deeply(parse_conf("TYPE winreg_String dissect_myminregstring(); FT_STRING BASE_DEC 0 0 2\n"), { types => { winreg_String => { 
				NAME => "winreg_String",
				POS => { FILE => "nofile", LINE => 1 },
				USED => 0,
				DISSECTOR_NAME => "dissect_myminregstring();",
				FT_TYPE => "FT_STRING",
				BASE_TYPE => "BASE_DEC",
				MASK => 0,
				VALSSTRING => 0,
				ALIGNMENT => 2}}});

ok(valid_ft_type("FT_UINT32"));
ok(not valid_ft_type("BLA"));
ok(not valid_ft_type("ft_uint32"));
ok(valid_ft_type("FT_BLA"));

ok(valid_base_type("BASE_DEC"));
ok(valid_base_type("BASE_HEX"));
ok(not valid_base_type("base_dec"));
ok(not valid_base_type("BLA"));
ok(not valid_base_type("BASEDEC"));

test_errors("nofile:1: incomplete TYPE command\n",
	sub { parse_conf("TYPE mytype dissector\n"); });

test_warnings("nofile:1: dissector name does not contain `dissect'\n",
	sub { parse_conf("TYPE winreg_String myminregstring; FT_STRING BASE_DEC 0 0 2\n"); });

test_warnings("nofile:1: invalid FT_TYPE `BLA'\n",
	sub { parse_conf("TYPE winreg_String dissect_myminregstring; BLA BASE_DEC 0 0 2\n"); });

test_warnings("nofile:1: invalid BASE_TYPE `BLOE'\n",
	sub { parse_conf("TYPE winreg_String dissect_myminregstring; FT_UINT32 BLOE 0 0 2\n"); });

is_deeply(parse_conf("TFS hf_bla \"True string\" \"False String\"\n"),
		{ tfs => { hf_bla => {
					TRUE_STRING => "\"True string\"",
				   FALSE_STRING => "\"False String\"" } } });

test_errors("nofile:1: incomplete TFS command\n",
	sub { parse_conf("TFS hf_bla \"Trues\""); } );

test_errors("nofile:1: incomplete PARAM_VALUE command\n",
	sub { parse_conf("PARAM_VALUE\n"); });

is_deeply(parse_conf("PARAM_VALUE Life 42\n"),
	{ dissectorparams => {
			Life => {
				DISSECTOR => "Life",
				POS => { FILE => "nofile", LINE => 1 },
				PARAM => 42,
				USED => 0
			}
		}
	});

is_deeply(parse_conf("STRIP_PREFIX bla_\n"),
	{ strip_prefixes => [ "bla_" ] });

is_deeply(parse_conf("STRIP_PREFIX bla_\nSTRIP_PREFIX bloe\n"),
	{ strip_prefixes => [ "bla_", "bloe" ] });

is_deeply(parse_conf("PROTOCOL atsvc \"Scheduling jobs on remote machines\" \"at\" \"atsvc\"\n"), 
	{ protocols => {
			atsvc => {
				LONGNAME => "\"Scheduling jobs on remote machines\"",
				SHORTNAME => "\"at\"",
				FILTERNAME => "\"atsvc\""
			}
		}
	}
);

is_deeply(parse_conf("IMPORT bla\n"), {
		imports => {
			bla => {
				NAME => "bla",
				DATA => "",
				USED => 0,
				POS => { FILE => "nofile", LINE => 1 }
			}
		}
	}
);

is_deeply(parse_conf("IMPORT bla fn1 fn2 fn3\n"), {
		imports => {
			bla => {
				NAME => "bla",
				DATA => "fn1 fn2 fn3",
				USED => 0,
				POS => { FILE => "nofile", LINE => 1 }
			}
		}
	}
);

test_errors("nofile:1: no dissectorname specified\n",
	sub { parse_conf("IMPORT\n"); } );

test_errors("nofile:1: incomplete HF_FIELD command\n",
	sub { parse_conf("HF_FIELD hf_idx\n"); });

test_errors("nofile:1: incomplete ETT_FIELD command\n",
	sub { parse_conf("ETT_FIELD\n"); });

is_deeply(parse_conf("TYPE winreg_String dissect_myminregstring(); FT_STRING BASE_DEC 0 0 0 2\n"), {
		types => {
			winreg_String => {
				NAME => "winreg_String",
				POS => { FILE => "nofile", LINE => 1 },
				USED => 0,
				DISSECTOR_NAME => "dissect_myminregstring();",
				FT_TYPE => "FT_STRING",
				BASE_TYPE => "BASE_DEC",
				MASK => 0,
				VALSSTRING => 0,
				ALIGNMENT => 0
			}
		}
	}
);


is_deeply(parse_conf("TYPE winreg_String \"offset = dissect_myminregstring(\@HF\@);\" FT_STRING BASE_DEC 0 0 0 2\n"), {
		types => {
			winreg_String => {
				NAME => "winreg_String",
				POS => { FILE => "nofile", LINE => 1 },
				USED => 0,
				DISSECTOR_NAME => "offset = dissect_myminregstring(\@HF\@);",
				FT_TYPE => "FT_STRING",
				BASE_TYPE => "BASE_DEC",
				MASK => 0,
				VALSSTRING => 0,
				ALIGNMENT => 0
			}
		}
	}
);