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
=> 49;
9 use FindBin
qw($RealBin);
12 use Parse::Pidl::Util qw(MyDumper);
13 use Parse
::Pidl
::Wireshark
::Conformance
qw(ReadConformanceFH valid_ft_type valid_base_type);
18 open(TMP
, "+>", undef) or die("unable to open temp file");
22 ReadConformanceFH
(*TMP
, $data, "nofile") or return undef;
27 ok
(parse_conf
("\n"), undef);
28 ok
(parse_conf
(" \n"), undef);
29 ok
(parse_conf
("CODE START\nCODE END\n"));
30 test_warnings
("nofile:1: Expecting CODE END\n", sub { is
(parse_conf
("CODE START\n"), undef); });
31 ok
(parse_conf
("#foobar\n"), undef);
32 test_warnings
("nofile:1: Unknown command `foobar'\n",
33 sub { ok
(parse_conf
("foobar\n"), undef); });
35 test_warnings
("nofile:1: incomplete HF_RENAME command\n",
36 sub { parse_conf
("HF_RENAME\n"); });
38 is_deeply
(parse_conf
("HF_RENAME foo bar\n")->{hf_renames
}->{foo
},
39 { OLDNAME
=> "foo", NEWNAME
=> "bar", POS
=> {FILE
=> "nofile", LINE
=> 1}, USED
=> 0});
41 is_deeply
(parse_conf
("NOEMIT\n"), { "noemit_dissector" => 1 });
42 is_deeply
(parse_conf
("NOEMIT foo\n"), { "noemit" => { "foo" => 1 } });
44 test_warnings
("nofile:1: incomplete MANUAL command\n",
45 sub { parse_conf
("MANUAL\n"); } );
47 is_deeply
(parse_conf
("MANUAL foo\n"), { manual
=> {foo
=> 1}});
49 test_errors
("nofile:1: incomplete INCLUDE command\n",
50 sub { parse_conf
("INCLUDE\n"); } );
52 test_warnings
("nofile:1: incomplete FIELD_DESCRIPTION command\n",
53 sub { parse_conf
("FIELD_DESCRIPTION foo\n"); });
55 is_deeply
(parse_conf
("FIELD_DESCRIPTION foo \"my description\"\n"),
56 { fielddescription
=> { foo
=> { DESCRIPTION
=> "\"my description\"", POS
=> { FILE
=> "nofile", LINE
=> 1}, USED
=> 0 }}});
58 is_deeply
(parse_conf
("FIELD_DESCRIPTION foo my description\n"),
59 { fielddescription
=> { foo
=> { DESCRIPTION
=> "my", POS
=> { FILE
=> "nofile", LINE
=> 1}, USED
=> 0 }}});
61 is_deeply
(parse_conf
("CODE START\ndata\nCODE END\n"), { override
=> "data\n" });
62 is_deeply
(parse_conf
("CODE START\ndata\nmore data\nCODE END\n"), { override
=> "data\nmore data\n" });
63 test_warnings
("nofile:1: CODE END outside CODE section\n",
64 sub { parse_conf
("CODE END\n"); } );
66 is_deeply
(parse_conf
("TYPE winreg_String dissect_myminregstring(); FT_STRING BASE_DEC 0 0 2\n"), { types
=> { winreg_String
=> {
67 NAME
=> "winreg_String",
68 POS
=> { FILE
=> "nofile", LINE
=> 1 },
70 DISSECTOR_NAME
=> "dissect_myminregstring();",
71 FT_TYPE
=> "FT_STRING",
72 BASE_TYPE
=> "BASE_DEC",
77 ok
(valid_ft_type
("FT_UINT32"));
78 ok
(not valid_ft_type
("BLA"));
79 ok
(not valid_ft_type
("ft_uint32"));
80 ok
(valid_ft_type
("FT_BLA"));
82 ok
(valid_base_type
("BASE_DEC"));
83 ok
(valid_base_type
("BASE_HEX"));
84 ok
(not valid_base_type
("base_dec"));
85 ok
(not valid_base_type
("BLA"));
86 ok
(not valid_base_type
("BASEDEC"));
88 test_errors
("nofile:1: incomplete TYPE command\n",
89 sub { parse_conf
("TYPE mytype dissector\n"); });
91 test_warnings
("nofile:1: dissector name does not contain `dissect'\n",
92 sub { parse_conf
("TYPE winreg_String myminregstring; FT_STRING BASE_DEC 0 0 2\n"); });
94 test_warnings
("nofile:1: invalid FT_TYPE `BLA'\n",
95 sub { parse_conf
("TYPE winreg_String dissect_myminregstring; BLA BASE_DEC 0 0 2\n"); });
97 test_warnings
("nofile:1: invalid BASE_TYPE `BLOE'\n",
98 sub { parse_conf
("TYPE winreg_String dissect_myminregstring; FT_UINT32 BLOE 0 0 2\n"); });
100 is_deeply
(parse_conf
("TFS hf_bla \"True string\" \"False String\"\n"),
101 { tfs
=> { hf_bla
=> {
102 TRUE_STRING
=> "\"True string\"",
103 FALSE_STRING
=> "\"False String\"" } } });
105 test_errors
("nofile:1: incomplete TFS command\n",
106 sub { parse_conf
("TFS hf_bla \"Trues\""); } );
108 test_errors
("nofile:1: incomplete PARAM_VALUE command\n",
109 sub { parse_conf
("PARAM_VALUE\n"); });
111 is_deeply
(parse_conf
("PARAM_VALUE Life 42\n"),
112 { dissectorparams
=> {
115 POS
=> { FILE
=> "nofile", LINE
=> 1 },
122 is_deeply
(parse_conf
("STRIP_PREFIX bla_\n"),
123 { strip_prefixes
=> [ "bla_" ] });
125 is_deeply
(parse_conf
("STRIP_PREFIX bla_\nSTRIP_PREFIX bloe\n"),
126 { strip_prefixes
=> [ "bla_", "bloe" ] });
128 is_deeply
(parse_conf
("PROTOCOL atsvc \"Scheduling jobs on remote machines\" \"at\" \"atsvc\"\n"),
131 LONGNAME
=> "\"Scheduling jobs on remote machines\"",
132 SHORTNAME
=> "\"at\"",
133 FILTERNAME
=> "\"atsvc\""
139 is_deeply
(parse_conf
("IMPORT bla\n"), {
145 POS
=> { FILE
=> "nofile", LINE
=> 1 }
151 is_deeply
(parse_conf
("IMPORT bla fn1 fn2 fn3\n"), {
155 DATA
=> "fn1 fn2 fn3",
157 POS
=> { FILE
=> "nofile", LINE
=> 1 }
163 test_errors
("nofile:1: no dissectorname specified\n",
164 sub { parse_conf
("IMPORT\n"); } );
166 test_errors
("nofile:1: incomplete HF_FIELD command\n",
167 sub { parse_conf
("HF_FIELD hf_idx\n"); });
169 test_errors
("nofile:1: incomplete ETT_FIELD command\n",
170 sub { parse_conf
("ETT_FIELD\n"); });
172 is_deeply
(parse_conf
("TYPE winreg_String dissect_myminregstring(); FT_STRING BASE_DEC 0 0 0 2\n"), {
175 NAME
=> "winreg_String",
176 POS
=> { FILE
=> "nofile", LINE
=> 1 },
178 DISSECTOR_NAME
=> "dissect_myminregstring();",
179 FT_TYPE
=> "FT_STRING",
180 BASE_TYPE
=> "BASE_DEC",
190 is_deeply
(parse_conf
("TYPE winreg_String \"offset = dissect_myminregstring(\@HF\@);\" FT_STRING BASE_DEC 0 0 0 2\n"), {
193 NAME
=> "winreg_String",
194 POS
=> { FILE
=> "nofile", LINE
=> 1 },
196 DISSECTOR_NAME
=> "offset = dissect_myminregstring(\@HF\@);",
197 FT_TYPE
=> "FT_STRING",
198 BASE_TYPE
=> "BASE_DEC",