-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix call to undefined logging function in usb_connection.
- Loading branch information
Showing
2 changed files
with
99 additions
and
1 deletion.
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,93 @@ | ||
var sinon = require('sinon'); | ||
var Emitter = require('events').EventEmitter; | ||
var Duplex = require('stream').Duplex; | ||
var USBConnection = require('../../lib/usb_connection').USBConnection; | ||
var logs = require('../../lib/logs'); | ||
|
||
exports['USBConnection'] = { | ||
setUp: function(done) { | ||
this.usbConnection = new USBConnection({}); | ||
done(); | ||
}, | ||
|
||
tearDown: function(done) { | ||
done(); | ||
}, | ||
|
||
duplexSubclass: function(test) { | ||
test.expect(1); | ||
test.ok(this.usbConnection instanceof Duplex); | ||
test.done(); | ||
}, | ||
|
||
connectionType: function(test) { | ||
test.expect(1); | ||
test.equal(this.usbConnection.connectionType, 'USB'); | ||
test.done(); | ||
}, | ||
}; | ||
|
||
exports['USBConnection.prototype._receiveMessages'] = { | ||
setUp: function(done) { | ||
this.sinon = sinon.sandbox.create(); | ||
this.err = this.sinon.stub(logs, 'err'); | ||
this.processExit = this.sinon.stub(process, 'exit'); | ||
this.usbConnection = new USBConnection({}); | ||
this.usbConnection.epIn = new Emitter(); | ||
this.usbConnection.epIn.startPoll = this.sinon.spy(); | ||
done(); | ||
}, | ||
|
||
tearDown: function(done) { | ||
this.sinon.restore(); | ||
done(); | ||
}, | ||
|
||
startPolling: function(test) { | ||
test.expect(3); | ||
|
||
this.usbConnection._receiveMessages(); | ||
|
||
test.equal(this.usbConnection.epIn.startPoll.callCount, 1); | ||
test.equal(this.usbConnection.epIn.startPoll.lastCall.args[0], 2); | ||
test.equal(this.usbConnection.epIn.startPoll.lastCall.args[1], 4096); | ||
test.done(); | ||
}, | ||
|
||
pushReceivedData: function(test) { | ||
test.expect(1); | ||
|
||
this.usbConnection._receiveMessages(); | ||
|
||
this.usbConnection.epIn.emit('data', new Buffer([0xff, 0xff])); | ||
test.equal(this.usbConnection._readableState.length, 2); | ||
test.done(); | ||
}, | ||
|
||
errorWhenStillOpen: function(test) { | ||
test.expect(2); | ||
|
||
this.usbConnection._receiveMessages(); | ||
|
||
this.usbConnection.epIn.emit('error', 'oh no!'); | ||
|
||
test.equal(this.err.callCount, 1); | ||
test.equal(this.processExit.callCount, 1); | ||
test.done(); | ||
}, | ||
|
||
errorWhenClosed: function(test) { | ||
test.expect(2); | ||
|
||
this.usbConnection._receiveMessages(); | ||
this.usbConnection.closed = true; | ||
this.usbConnection.epIn.emit('error', 'oh no!'); | ||
|
||
// The immediate return prevents these from being | ||
// called from in the error handler | ||
test.equal(this.err.callCount, 0); | ||
test.equal(this.processExit.callCount, 0); | ||
test.done(); | ||
}, | ||
|
||
}; |