Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 11 additions & 31 deletions generator/javascript/test/mavlink10.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var fs = require('fs');
// Actual data stream taken from APM.
global.fixtures = global.fixtures || {};
global.fixtures.serialStream = fs.readFileSync("test/capture.mavlink");
//global.fixtures.heartbeatBinaryStream = fs.readFileSync("javascript/test/heartbeat-data-fixture");

describe("Generated MAVLink 1.0 protocol handler object", function() {

Expand Down Expand Up @@ -81,14 +80,7 @@ describe("Generated MAVLink 1.0 protocol handler object", function() {

describe("buffer decoder (parseBuffer)", function() {

// This test prepopulates a single message as a binary buffer.
it("decodes a binary stream representation of a single message correctly", function() {
this.m.pushBuffer(global.fixtures.heartbeatBinaryStream);
var messages = this.m.parseBuffer();

});

// This test includes a "noisy" signal, with non-mavlink data/messages/noise.
// This test includes a "noisy" signal, with non-mavlink data/messages/noise.
it("decodes a real serial binary stream into an array of MAVLink messages", function() {
this.m.pushBuffer(global.fixtures.serialStream);
var messages = this.m.parseBuffer();
Expand All @@ -113,11 +105,11 @@ describe("Generated MAVLink 1.0 protocol handler object", function() {
});

it("emits a 'message' event, provisioning callbacks with the message", function(done) {
this.m.on('message', function(message) {
message.should.be.an.instanceof(mavlink10.messages.heartbeat);
this.m.on('message', function(message) {
message.should.be.an.instanceof(mavlink10.messages.heartbeat);
done();
});
this.m.parseChar(this.heartbeatPayload);
});
this.m.parseChar(this.heartbeatPayload);
});

it("emits a 'message' event for bad messages, provisioning callbacks with the message", function(done) {
Expand All @@ -129,24 +121,12 @@ describe("Generated MAVLink 1.0 protocol handler object", function() {
this.m.parseChar(b);
});

it("on bad prefix: cuts-off first char in buffer and returns correct bad data", function() {
var b = new Buffer.from([3, 0, 1, 2, 3, 4, 5]); // invalid message
var message = this.m.parseChar(b);
message._msgbuf.length.should.be.eql(1);
message._msgbuf[0].should.be.eql(3);
this.m.buf.length.should.be.eql(6);
// should process next char
message = this.m.parseChar();
message._msgbuf.length.should.be.eql(1);
message._msgbuf[0].should.be.eql(0);
this.m.buf.length.should.be.eql(5);
});

it("on bad message: cuts-off message length and returns correct bad data", function() {
it("on bad message: cuts-off message length and returns correct bad data", function() {
var message = this.m.parseChar(this.completeInvalidMessage);
message._msgbuf.length.should.be.eql(8);
message._msgbuf.should.be.eql(this.completeInvalidMessage);
this.m.buf.length.should.be.eql(0);

message._msgbuf.length.should.be.eql(8);
Buffer.from(message._msgbuf).should.be.eql(this.completeInvalidMessage);
this.m.buf.length.should.be.eql(0);
});

it("error counter is raised on error", function() {
Expand Down Expand Up @@ -180,7 +160,7 @@ describe("Generated MAVLink 1.0 protocol handler object", function() {
var b = new Buffer.alloc(16);
b.fill("h");
this.m.pushBuffer(b);
this.m.buf.should.eql(b); // eql = wiggly equality
Buffer.from(this.m.buf).should.eql(b); // eql = wiggly equality
});
});

Expand Down
29 changes: 4 additions & 25 deletions generator/javascript/test/mavlink20.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var fs = require('fs');
// Actual data stream taken from APM.
global.fixtures = global.fixtures || {};
global.fixtures.serialStream = fs.readFileSync("test/capture.mavlink");
//global.fixtures.heartbeatBinaryStream = fs.readFileSync("javascript/test/heartbeat-data-fixture");

describe("Generated MAVLink 2.0 protocol handler object", function() {

Expand Down Expand Up @@ -85,14 +84,7 @@ describe("Generated MAVLink 2.0 protocol handler object", function() {

describe("buffer decoder (parseBuffer)", function() {

// This test prepopulates a single message as a binary buffer.
it("decodes a binary stream representation of a single message correctly", function() {
this.m.pushBuffer(global.fixtures.heartbeatBinaryStream);
var messages = this.m.parseBuffer();

});

// This test includes a "noisy" signal, with non-mavlink data/messages/noise.
// This test includes a "noisy" signal, with non-mavlink data/messages/noise.
it("decodes a real serial binary stream into an array of MAVLink messages", function() {
this.m.pushBuffer(global.fixtures.serialStream);
var messages = this.m.parseBuffer();
Expand Down Expand Up @@ -133,23 +125,10 @@ describe("Generated MAVLink 2.0 protocol handler object", function() {
this.m.parseChar(b);
});

it("on bad prefix: cuts-off first char in buffer and returns correct bad data", function() {
var b = new Buffer.from([3, 0, 1, 2, 3, 4, 5, 6, 7]); // invalid message
var message = this.m.parseChar(b);
message._msgbuf.length.should.be.eql(1);
message._msgbuf[0].should.be.eql(3);
this.m.buf.length.should.be.eql(8);
// should process next char
message = this.m.parseChar();
message._msgbuf.length.should.be.eql(1);
message._msgbuf[0].should.be.eql(0);
this.m.buf.length.should.be.eql(7);
});

it("on bad message: cuts-off message length and returns correct bad data", function() {
it("on bad message: cuts-off message length and returns correct bad data", function() {
var message = this.m.parseChar(this.completeInvalidMessage);
message._msgbuf.length.should.be.eql(12);
message._msgbuf.should.be.eql(this.completeInvalidMessage);
Buffer.from(message._msgbuf).should.be.eql(this.completeInvalidMessage);
this.m.buf.length.should.be.eql(0);
});

Expand Down Expand Up @@ -184,7 +163,7 @@ describe("Generated MAVLink 2.0 protocol handler object", function() {
var b = new Buffer.alloc(16);
b.fill("h");
this.m.pushBuffer(b);
this.m.buf.should.eql(b); // eql = wiggly equality
Buffer.from(this.m.buf).should.eql(b); // eql = wiggly equality
});
});

Expand Down
Loading