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
=> 47;
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"); });
39 is_deeply
(parse_conf
("HF_RENAME foo bar\n")->{hf_renames
}->{foo
},
40 { OLDNAME
=> "foo", NEWNAME
=> "bar", POS
=> {FILE
=> "nofile", LINE
=> 1}, USED
=> 0});
42 is_deeply
(parse_conf
("NOEMIT\n"), { "noemit_dissector" => 1 });
43 is_deeply
(parse_conf
("NOEMIT foo\n"), { "noemit" => { "foo" => 1 } });
45 test_warnings
("nofile:1: incomplete MANUAL command\n",
46 sub { parse_conf
("MANUAL\n"); } );
48 is_deeply
(parse_conf
("MANUAL foo\n"), { manual
=> {foo
=> 1}});
50 test_warnings
("nofile:1: incomplete FIELD_DESCRIPTION command\n",
51 sub { parse_conf
("FIELD_DESCRIPTION foo\n"); });
53 is_deeply
(parse_conf
("FIELD_DESCRIPTION foo \"my description\"\n"),
54 { fielddescription
=> { foo
=> { DESCRIPTION
=> "\"my description\"", POS
=> { FILE
=> "nofile", LINE
=> 1}, USED
=> 0 }}});
56 is_deeply
(parse_conf
("FIELD_DESCRIPTION foo my description\n"),
57 { fielddescription
=> { foo
=> { DESCRIPTION
=> "my", POS
=> { FILE
=> "nofile", LINE
=> 1}, USED
=> 0 }}});
59 is_deeply
(parse_conf
("CODE START\ndata\nCODE END\n"), { override
=> "data\n" });
60 is_deeply
(parse_conf
("CODE START\ndata\nmore data\nCODE END\n"), { override
=> "data\nmore data\n" });
61 test_warnings
("nofile:1: Unknown command `CODE'\n",
62 sub { parse_conf
("CODE END\n"); } );
64 is_deeply
(parse_conf
("TYPE winreg_String dissect_myminregstring(); FT_STRING BASE_DEC 0 0 2\n"), { types
=> { winreg_String
=> {
65 NAME
=> "winreg_String",
66 POS
=> { FILE
=> "nofile", LINE
=> 1 },
68 DISSECTOR_NAME
=> "dissect_myminregstring();",
69 FT_TYPE
=> "FT_STRING",
70 BASE_TYPE
=> "BASE_DEC",
75 ok
(valid_ft_type
("FT_UINT32"));
76 ok
(not valid_ft_type
("BLA"));
77 ok
(not valid_ft_type
("ft_uint32"));
78 ok
(valid_ft_type
("FT_BLA"));
80 ok
(valid_base_type
("BASE_DEC"));
81 ok
(valid_base_type
("BASE_HEX"));
82 ok
(not valid_base_type
("base_dec"));
83 ok
(not valid_base_type
("BLA"));
84 ok
(not valid_base_type
("BASEDEC"));
86 test_errors
("nofile:1: incomplete TYPE command\n",
87 sub { parse_conf
("TYPE mytype dissector\n"); });
89 test_warnings
("nofile:1: dissector name does not contain `dissect'\n",
90 sub { parse_conf
("TYPE winreg_String myminregstring; FT_STRING BASE_DEC 0 0 2\n"); });
92 test_warnings
("nofile:1: invalid FT_TYPE `BLA'\n",
93 sub { parse_conf
("TYPE winreg_String dissect_myminregstring; BLA BASE_DEC 0 0 2\n"); });
95 test_warnings
("nofile:1: invalid BASE_TYPE `BLOE'\n",
96 sub { parse_conf
("TYPE winreg_String dissect_myminregstring; FT_UINT32 BLOE 0 0 2\n"); });
98 is_deeply
(parse_conf
("TFS hf_bla \"True string\" \"False String\"\n"),
99 { tfs
=> { hf_bla
=> {
100 TRUE_STRING
=> "\"True string\"",
101 FALSE_STRING
=> "\"False String\"" } } });
103 test_errors
("nofile:1: incomplete TFS command\n",
104 sub { parse_conf
("TFS hf_bla \"Trues\""); } );
106 test_errors
("nofile:1: incomplete PARAM_VALUE command\n",
107 sub { parse_conf
("PARAM_VALUE\n"); });
109 is_deeply
(parse_conf
("PARAM_VALUE Life 42\n"),
110 { dissectorparams
=> {
113 POS
=> { FILE
=> "nofile", LINE
=> 1 },
120 is_deeply
(parse_conf
("STRIP_PREFIX bla_\n"),
121 { strip_prefixes
=> [ "bla_" ] });
123 is_deeply
(parse_conf
("STRIP_PREFIX bla_\nSTRIP_PREFIX bloe\n"),
124 { strip_prefixes
=> [ "bla_", "bloe" ] });
126 is_deeply
(parse_conf
("PROTOCOL atsvc \"Scheduling jobs on remote machines\" \"at\" \"atsvc\"\n"),
129 LONGNAME
=> "\"Scheduling jobs on remote machines\"",
130 SHORTNAME
=> "\"at\"",
131 FILTERNAME
=> "\"atsvc\""
137 is_deeply
(parse_conf
("IMPORT bla\n"), {
143 POS
=> { FILE
=> "nofile", LINE
=> 1 }
149 is_deeply
(parse_conf
("IMPORT bla fn1 fn2 fn3\n"), {
153 DATA
=> "fn1 fn2 fn3",
155 POS
=> { FILE
=> "nofile", LINE
=> 1 }
161 test_errors
("nofile:1: no dissectorname specified\n",
162 sub { parse_conf
("IMPORT\n"); } );
164 test_errors
("nofile:1: incomplete HF_FIELD command\n",
165 sub { parse_conf
("HF_FIELD hf_idx\n"); });
167 is_deeply
(parse_conf
("TYPE winreg_String dissect_myminregstring(); FT_STRING BASE_DEC 0 0 0 2\n"), {
170 NAME
=> "winreg_String",
171 POS
=> { FILE
=> "nofile", LINE
=> 1 },
173 DISSECTOR_NAME
=> "dissect_myminregstring();",
174 FT_TYPE
=> "FT_STRING",
175 BASE_TYPE
=> "BASE_DEC",
185 is_deeply
(parse_conf
("TYPE winreg_String \"offset = dissect_myminregstring(\@HF\@);\" FT_STRING BASE_DEC 0 0 0 2\n"), {
188 NAME
=> "winreg_String",
189 POS
=> { FILE
=> "nofile", LINE
=> 1 },
191 DISSECTOR_NAME
=> "offset = dissect_myminregstring(\@HF\@);",
192 FT_TYPE
=> "FT_STRING",
193 BASE_TYPE
=> "BASE_DEC",