Skip to content

Commit

Permalink
Merge branch 'master' of github.com:huseyinkozan/t2-firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
huseyinkozan committed Jun 16, 2016
2 parents d22e0a0 + 95f49ef commit 3364c6d
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion node/test/unit/tessel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1912,14 +1912,16 @@ exports['Tessel.UART'] = {
return this.socket;
}.bind(this));

this.tessel = new Tessel();
// Block creation of automatically generated ports
this.tessel = new Tessel({ ports: {'A' : false, 'B' : false} });

this.cork = sandbox.stub(Tessel.Port.prototype, 'cork');
this.uncork = sandbox.stub(Tessel.Port.prototype, 'uncork');
this._tx = sandbox.stub(Tessel.Port.prototype, '_tx');
this._rx = sandbox.stub(Tessel.Port.prototype, '_rx');
this._simple_cmd = sandbox.stub(Tessel.Port.prototype, '_simple_cmd');

// Explicitly generate our own port
this.port = new Tessel.Port('foo', '/foo/bar/baz', this.tessel);

this.uartDisable = sandbox.spy(Tessel.UART.prototype, 'disable');
Expand Down Expand Up @@ -2033,6 +2035,41 @@ exports['Tessel.UART'] = {
test.ok(this.uartDisable.calledOnce, true);

test.done();
},

bufferOutput: function(test) {

test.expect(2);

// Create our Tessel port
var u1 = new this.port.UART();

// Buffers which we'll emit as mocked incoming UART data
var payload = new Buffer([3, 4]);
var header = new Buffer([Tessel.REPLY.ASYNC_UART_RX, payload.length]);

// Only return our test buffer on the first call, otherwise empty buff
var called = false;
this.socket.read = () => {
if (called) {
return new Buffer([]);
}
called = true;

return Buffer.concat([header, payload]);
};

// When data is emitted on the uart peripheral
u1.once('data', (shouldBeBuf) => {
// Ensure it is a buffer (not a string)
test.ok(Buffer.isBuffer(shouldBeBuf));
// Ensure the payload is what is emitted
test.deepEqual(shouldBeBuf, payload);
test.done();
});

// Prod the socket to read our buffer
u1._port.sock.emit('readable');
}
};

Expand Down

0 comments on commit 3364c6d

Please sign in to comment.