summaryrefslogtreecommitdiff
path: root/source4/pidl/tests/wireshark-conf.pl
blob: 0e6e1e78ac8a269cc35305e871158ac86ceb8a53 (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
#!/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 => 34;
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_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"); });