{"size": 1691, "ext": "js", "max_stars_repo_path": "spec/decode/udp.spec.js", "max_stars_repo_name": "bluepichu/node_pcap", "max_stars_repo_stars_event_min_datetime": "2017-02-13T20:17:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T12:50:03.000Z", "max_issues_repo_path": "spec/decode/udp.spec.js", "max_issues_repo_name": "bluepichu/node_pcap", "max_issues_repo_issues_event_min_datetime": "2015-01-02T19:10:35.000Z", "max_issues_repo_issues_event_max_datetime": "2017-02-13T10:11:34.000Z", "max_forks_repo_path": "spec/decode/udp.spec.js", "max_forks_repo_name": "bluepichu/node_pcap", "max_forks_repo_forks_event_min_datetime": "2017-02-27T22:43:50.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T12:19:38.000Z"}
{"max_stars_count": 310, "max_issues_count": 133, "max_forks_count": 101, "avg_line_length": 33.1568627451, "max_line_length": 76, "alphanum_fraction": 0.5890005914}
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");
    });
  });
});