Rev 11394: Add some tests for the wireshark conformance file
reader. in file:///home/jelmer/bzr.samba/pidl-fixes/
Jelmer Vernooij
jelmer at samba.org
Thu Feb 8 15:43:17 GMT 2007
At file:///home/jelmer/bzr.samba/pidl-fixes/
------------------------------------------------------------
revno: 11394
revision-id: jelmer at samba.org-20070208154257-zqh0w412ym1w22u9
parent: jelmer at samba.org-20070208141706-afd7md02c83t939w
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: pidl-fixes
timestamp: Thu 2007-02-08 16:42:57 +0100
message:
Add some tests for the wireshark conformance file reader.
added:
source/pidl/tests/wireshark-conf.pl wiresharkconf.pl-20070208154028-socda2mp78zkog3t-1
modified:
source/pidl/lib/Parse/Pidl/Wireshark/Conformance.pm svn-v2:16824 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2flib%2fParse%2fPidl%2fWireshark%2fConformance.pm
source/pidl/lib/Parse/Pidl/Wireshark/NDR.pm svn-v2:16824 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2flib%2fParse%2fPidl%2fWireshark%2fNDR.pm
=== added file 'source/pidl/tests/wireshark-conf.pl'
--- a/source/pidl/tests/wireshark-conf.pl 1970-01-01 00:00:00 +0000
+++ b/source/pidl/tests/wireshark-conf.pl 2007-02-08 15:42:57 +0000
@@ -0,0 +1,57 @@
+#!/usr/bin/perl
+# (C) 2007 Jelmer Vernooij <jelmer at samba.org>
+# Published under the GNU General Public License
+# test parsing wireshark conformance files
+use strict;
+use warnings;
+
+use Test::More tests => 17;
+use FindBin qw($RealBin);
+use lib "$RealBin";
+use Util;
+use Parse::Pidl::Util qw(MyDumper);
+use Parse::Pidl::Wireshark::Conformance qw(ReadConformanceFH);
+
+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 }}});
=== modified file 'source/pidl/lib/Parse/Pidl/Wireshark/Conformance.pm'
--- a/source/pidl/lib/Parse/Pidl/Wireshark/Conformance.pm 2007-01-03 15:34:01 +0000
+++ b/source/pidl/lib/Parse/Pidl/Wireshark/Conformance.pm 2007-02-08 15:42:57 +0000
@@ -96,7 +96,7 @@
$VERSION = '0.01';
@ISA = qw(Exporter);
- at EXPORT_OK = qw(ReadConformance);
+ at EXPORT_OK = qw(ReadConformance ReadConformanceFH);
use strict;
@@ -157,7 +157,7 @@
my ($pos,$data,$old,$new) = @_;
unless(defined($new)) {
- error($pos, "incomplete HF_RENAME command");
+ warning($pos, "incomplete HF_RENAME command");
return;
}
@@ -253,6 +253,11 @@
{
my ($pos,$data,$fn) = @_;
+ unless(defined($fn)) {
+ warning($pos, "incomplete MANUAL command");
+ return;
+ }
+
$data->{manual}->{$fn} = 1;
}
@@ -271,6 +276,11 @@
{
my ($pos,$data,$field,$desc) = @_;
+ unless(defined($desc)) {
+ warning($pos, "incomplete FIELD_DESCRIPTION command");
+ return;
+ }
+
$data->{fielddescription}->{$field} = {
DESCRIPTION => $desc,
POS => $pos,
@@ -314,16 +324,26 @@
sub ReadConformance($$)
{
my ($f,$data) = @_;
-
- $data->{override} = "";
+ my $ret;
+
+ open(IN,"<$f") or return undef;
+
+ $ret = ReadConformanceFH(*IN, $data, $f);
+
+ close(IN);
+
+ return $ret;
+}
+
+sub ReadConformanceFH($$$)
+{
+ my ($fh,$data,$f) = @_;
my $incodeblock = 0;
- open(IN,"<$f") or return undef;
-
my $ln = 0;
- foreach (<IN>) {
+ foreach (<$fh>) {
$ln++;
next if (/^#.*$/);
next if (/^$/);
@@ -337,7 +357,11 @@
$incodeblock = 0;
next;
} elsif ($incodeblock) {
- $data->{override}.="$_\n";
+ if (exists $data->{override}) {
+ $data->{override}.="$_\n";
+ } else {
+ $data->{override} = "$_\n";
+ }
next;
}
@@ -349,7 +373,7 @@
my $pos = { FILE => $f, LINE => $ln };
- if (not defined($field_handlers{$cmd})) {
+ if (not exists($field_handlers{$cmd})) {
warning($pos, "Unknown command `$cmd'");
next;
}
@@ -357,7 +381,13 @@
$field_handlers{$cmd}($pos, $data, @fields);
}
- close(IN);
+ if ($incodeblock) {
+ warning({ FILE => $f, LINE => $ln },
+ "Expecting CODE END");
+ return undef;
+ }
+
+ return 1;
}
1;
=== modified file 'source/pidl/lib/Parse/Pidl/Wireshark/NDR.pm'
--- a/source/pidl/lib/Parse/Pidl/Wireshark/NDR.pm 2007-01-05 20:52:12 +0000
+++ b/source/pidl/lib/Parse/Pidl/Wireshark/NDR.pm 2007-02-08 15:42:57 +0000
@@ -2,7 +2,7 @@
# Samba4 NDR parser generator for IDL structures
# Copyright tridge at samba.org 2000-2003
# Copyright tpot at samba.org 2001,2005
-# Copyright jelmer at samba.org 2004-2005
+# Copyright jelmer at samba.org 2004-2007
# Portions based on idl2eth.c by Ronnie Sahlberg
# released under the GNU GPL
@@ -918,7 +918,9 @@
$parser.=$res{ett};
$parser.=$res{hf};
$parser.=$res{def};
- $parser.=$conformance->{override};
+ if (exists ($conformance->{override})) {
+ $parser.=$conformance->{override};
+ }
$parser.=$res{code};
my $header = "/* autogenerated by pidl */\n\n";
More information about the samba-cvs
mailing list