Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78d6919
commit ed3222d
Showing
11 changed files
with
175 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,69 @@ | ||
require 'spec_helper' | ||
|
||
describe DataLink do | ||
before(:all) do | ||
@datalink = DataLink.new(0) | ||
end | ||
subject { described_class.new(0) } | ||
|
||
it "should map datalink names to datalink layer type values" do | ||
DataLink.name_to_val(:en10mb).should == 1 | ||
described_class.name_to_val(:en10mb).should == 1 | ||
end | ||
|
||
it "should map datalink layer type values to datalink names" do | ||
DataLink.val_to_name(1).should == "EN10MB" | ||
described_class.val_to_name(1).should == "EN10MB" | ||
end | ||
|
||
it "should be initialized from a pcap datalink value" do | ||
@datalink.name.should == 'NULL' | ||
subject.name.should == 'NULL' | ||
end | ||
|
||
it "should support initialization from a pcap datalink name symbol" do | ||
@datalink = DataLink.new(:null) | ||
DataLink.should === @datalink | ||
it "should have a description" do | ||
subject.description.should_not be_empty | ||
end | ||
|
||
it "should support initialization from a pcap datalink name string" do | ||
dl = DataLink.new('en10mb') | ||
DataLink.should === dl | ||
end | ||
describe "#initialize" do | ||
it "should support initialization from a pcap datalink name Symbol" do | ||
link = described_class.new(:null) | ||
|
||
it "should allow equality comparison against numeric values" do | ||
(@datalink == 0).should == true | ||
(@datalink == 1).should == false | ||
end | ||
link.name.should == 'NULL' | ||
end | ||
|
||
it "should allow equality comparison against String names" do | ||
(@datalink == "null").should == true | ||
(@datalink == "en10mb").should == false | ||
it "should support initialization from a pcap datalink name String" do | ||
link = described_class.new('en10mb') | ||
|
||
link.name.should == 'EN10MB' | ||
end | ||
end | ||
|
||
it "should allow equality comparison against Symbol names" do | ||
(@datalink == :null).should == true | ||
(@datalink == :en10mb).should == false | ||
end | ||
describe "#==" do | ||
it "should allow equality comparison against numeric values" do | ||
(subject == 0).should == true | ||
(subject == 1).should == false | ||
end | ||
|
||
it "should allow comparison against another DataLink" do | ||
(@datalink == DataLink.new(0)).should == true | ||
(@datalink == DataLink.new(1)).should == false | ||
end | ||
it "should allow equality comparison against String names" do | ||
(subject == "null").should == true | ||
(subject == "en10mb").should == false | ||
end | ||
|
||
it "should still compare correctly against any other object" do | ||
(@datalink == Object.new).should == false | ||
end | ||
it "should allow equality comparison against Symbol names" do | ||
(subject == :null).should == true | ||
(subject == :en10mb).should == false | ||
end | ||
|
||
it "should have a description" do | ||
@datalink.description.should_not be_empty | ||
it "should allow comparison against another described_class" do | ||
(subject == described_class.new(0)).should == true | ||
(subject == described_class.new(1)).should == false | ||
end | ||
|
||
it "should still compare correctly against any other object" do | ||
(subject == Object.new).should == false | ||
end | ||
end | ||
|
||
it "should convert to an Integer for the DLT value" do | ||
@datalink.to_i.should == 0 | ||
subject.to_i.should == 0 | ||
end | ||
|
||
it "should convert to a String for the DLT name" do | ||
@datalink.to_s.should == 'NULL' | ||
subject.to_s.should == 'NULL' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,9 +26,5 @@ | |
|
||
@pcap.close | ||
end | ||
|
||
|
||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
require 'spec_helper' | ||
|
||
describe ErrorBuffer do | ||
before(:all) do | ||
@errbuf = ErrorBuffer.create | ||
end | ||
subject { ErrorBuffer.create } | ||
|
||
it "should have a size of 256" do | ||
@errbuf.size.should == 256 | ||
it "should have a default size of 256" do | ||
subject.size.should == 256 | ||
end | ||
|
||
it "should return an error message with to_s" do | ||
@errbuf.to_s.should be_empty | ||
FFI::PCap.pcap_open_offline("/this/file/wont/exist/#{rand(0xFFFF)}", @errbuf ) | ||
@errbuf.to_s.should_not be_empty | ||
subject.to_s.should be_empty | ||
|
||
FFI::PCap.pcap_open_offline("/this/file/wont/exist",subject) | ||
|
||
subject.to_s.should_not be_empty | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
require 'spec_helper' | ||
|
||
describe FileHeader do | ||
before(:all) do | ||
@file_header = FileHeader.new( :raw => File.read(PCAP_TESTFILE) ) | ||
subject do | ||
described_class.new(:raw => File.read(PCAP_TESTFILE)) | ||
end | ||
|
||
it "should parse a pcap file correctly" do | ||
@file_header.magic.should == 0xa1b2c3d4 | ||
@file_header.version_major.should == 2 | ||
@file_header.version_minor.should == 4 | ||
@file_header.thiszone.should == 0 | ||
@file_header.sigfigs.should == 0 | ||
@file_header.snaplen.should == 96 | ||
@file_header.linktype.should == 1 | ||
subject.magic.should == 0xa1b2c3d4 | ||
subject.version_major.should == 2 | ||
subject.version_minor.should == 4 | ||
subject.thiszone.should == 0 | ||
subject.sigfigs.should == 0 | ||
subject.snaplen.should == 96 | ||
subject.linktype.should == 1 | ||
end | ||
|
||
it "should return a file format version string" do | ||
String.should === @file_header.version | ||
@file_header.version.should == "2.4" | ||
subject.version.should == "2.4" | ||
end | ||
|
||
it "should return a DataLink for the linktype using datalink()" do | ||
DataLink.should === @file_header.datalink | ||
(@file_header.datalink == :en10mb).should == true | ||
end | ||
subject.datalink.should be_kind_of(DataLink) | ||
|
||
(subject.datalink == :en10mb).should == true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.