forked from node-pcap/node_pcap
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
2 changed files
with
56 additions
and
5 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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
var Udp = require("../../decode/udp"); | ||
var events = require("events"); | ||
var shouldBehaveLikeADecoder = require("./decode").shouldBehaveLikeADecoder; | ||
require("should"); | ||
|
||
describe("Udp", function(){ | ||
beforeEach(function () { | ||
this.eventEmitter = new events.EventEmitter(); | ||
this.instance = new Udp(this.eventEmitter); | ||
this.example = new Buffer("04d2" + // source port 1234 | ||
"04d3" + // dst port 1235 | ||
"0009" + // length | ||
"df03" + // checksum (this on is bad) | ||
"30", "hex"); | ||
}); | ||
|
||
describe("#decode()", function(){ | ||
shouldBehaveLikeADecoder("udp", true); | ||
|
||
it("sets #sport to the source port", function(){ | ||
this.instance.decode(this.example, 0); | ||
this.instance.should.have.property("sport", 1234); | ||
}); | ||
|
||
it("sets #dport to the destination port", function(){ | ||
this.instance.decode(this.example, 0); | ||
this.instance.should.have.property("dport", 1235); | ||
}); | ||
|
||
it("sets #length to the length of the payload", function(){ | ||
this.instance.decode(this.example, 0); | ||
this.instance.should.have.property("length", 9); | ||
}); | ||
|
||
it("sets #data to the payload", function(){ | ||
this.instance.decode(this.example, 0); | ||
this.instance.should.have.property("data", new Buffer("30", "hex")); | ||
}); | ||
|
||
it("sets #checksum to the checksum", function(){ | ||
this.instance.decode(this.example, 0); | ||
this.instance.should.have.property("checksum", 0xdf03); | ||
}); | ||
}); | ||
|
||
describe("#toString()", function(){ | ||
it("is a function", function(){ | ||
this.instance.toString.should.be.type("function"); | ||
}); | ||
}); | ||
}); |