Skip to content

Commit

Permalink
More coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Sep 1, 2019
1 parent 64fecc0 commit c2b3c97
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
12 changes: 8 additions & 4 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ describe('SMPTE', function() {

describe('JZZ.lib', function() {
it('toBase64', function() {
assert.equal(JZZ.lib.toBase64(''), '');
assert.equal(JZZ.lib.toBase64('M'), 'TQ==');
assert.equal(JZZ.lib.toBase64('MI'), 'TUk=');
assert.equal(JZZ.lib.toBase64('MID'), 'TUlE');
assert.equal(JZZ.lib.toBase64('MIDI'), 'TUlESQ==');
});
it('fromBase64', function() {
Expand Down Expand Up @@ -418,21 +422,21 @@ describe('JZZ.Widget', function() {
var sample = new test.Sample(done, [
[0x91, 0x3c, 0x7f], [0x82, 0x3c, 0x7f], [0xff],
[0xf1, 0x04], [0xf1, 0x04],
[0x90, 0x3c, 0x7f], [0x80, 0x3c, 0x40], [0x95, 0x3c, 0x7f], [0x85, 0x3c, 0x40]
[0x90, 0x3c, 0x7f], [0x99, 0, 1], [0x80, 0x3c, 0x40], [0x95, 0x3c, 0x7f], [0x85, 0x3c, 0x40], [0x95, 0, 1]
]);
var port = JZZ.Widget({ _receive: function(msg) { sample.compare(msg); }});
port.ch(1).noteOn('C5').ch(2).noteOff('C5', 127).ch(3).reset();
port.ch(4).mtc(JZZ.SMPTE(30, 1, 2, 3, 4)).ch().mtc(JZZ.SMPTE(30, 1, 2, 3, 4));
port.note(0, 'B#4', 127, 1).ch(5).wait(10).note('Dbb5', 127, 1).wait(10).disconnect().close();
port.note(0, 'B#4', 127, 1).note(9, 0, 1).ch(5).wait(10).note('Dbb5', 127, 1).wait(10).note(0, 1).disconnect().close();
});
it('mpe', function(done) {
var sample = new test.Sample(done, [
[0xc0, 0x19], [0x91, 0x3c, 0x7f], [0x92, 0x3e, 0x7f], [0xa2, 0x3e, 0x7f], [0x81, 0x3c, 0x40],
[0x91, 0x40, 0x7f], [0x81, 0x40, 0x40]
[0x91, 0x40, 0x7f], [0x93, 0, 1], [0x81, 0x40, 0x40]
]);
var port = JZZ.Widget();
port.connect(function(msg) { sample.compare(msg); });
port.mpe(0, 4).program(25).noteOn('C5').noteOn('D5').aftertouch('D5', 127).noteOff('C5').note('E5', 127, 1);
port.mpe(0, 4).program(25).noteOn('C5').noteOn('D5').aftertouch('D5', 127).noteOff('C5').note('E5', 127, 1).note(0, 1);
});
});

Expand Down
40 changes: 33 additions & 7 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,15 @@ module.exports = function(JZZ, PARAMS, DRIVER) {
}
};
function onSuccess(midi) {
assert.equal(midi.inputs.size > 0, true);
midi.inputs.keys();
midi.inputs.values();
midi.inputs.entries();
midi.inputs.forEach(function(p) {
var inputs = midi.inputs;
var dummy = inputs.size;
assert.equal(dummy > 0, true);
dummy = inputs.keys();
dummy = inputs.values();
dummy = inputs.entries();
inputs.forEach(function(p) {
if (p.name == name) {
var sample = new Sample(function() { p.close(); p.close().then(function() { done(); }); }, [[0x90, 0x40, 0x7f]]);
var sample = new Sample(function() { p.open(); p.close(); p.close().then(function() { done(); }); }, [[0x90, 0x40, 0x7f]]);
assert.equal(p.type, 'input');
assert.equal(p.state, 'connected');
assert.equal(p.connection, 'closed');
Expand Down Expand Up @@ -409,7 +411,7 @@ module.exports = function(JZZ, PARAMS, DRIVER) {
it('MIDIOutput no sysex', function(done) {
var name = 'Widget MIDI-Out no sysex';
var myport;
var sample = new Sample(function() { myport.close(); myport.close().then(function() { done(); }); }, [
var sample = new Sample(function() { myport.open(); myport.close(); myport.close().then(function() { done(); }); }, [
[0xf8],
[0xc0, 0x10],
[0x90, 0x40, 0x7f]
Expand All @@ -433,6 +435,18 @@ module.exports = function(JZZ, PARAMS, DRIVER) {
myport = p;
var now = JZZ.lib.now();
var bad = false;
try {
p.send([300]);
bad = true;
} catch(err) {}
try {
p.send([0xf7]);
bad = true;
} catch(err) {}
try {
p.send([0x90, 0x90, 0x00]);
bad = true;
} catch(err) {}
try {
p.send([0x20, 0x20, 0x20], now + 20);
bad = true;
Expand Down Expand Up @@ -547,6 +561,7 @@ module.exports = function(JZZ, PARAMS, DRIVER) {
p.onstatechange = function(e) {
assert.equal(e.port.state, 'disconnected');
assert.equal(e.port.connection, 'closed');
e.port.onmidimessage = null;
e.port.onstatechange = null;
done();
};
Expand All @@ -562,6 +577,7 @@ module.exports = function(JZZ, PARAMS, DRIVER) {
web_midi_input_reconnect: function() {
it('MIDIInput reconnect', function(done) {
var port;
var access;
var name = 'MIDIInput reconnect';
var src = DRIVER.MidiSrc(name);
src.connect();
Expand All @@ -583,6 +599,15 @@ module.exports = function(JZZ, PARAMS, DRIVER) {
function call2() {
assert.equal(port.state, 'disconnected');
assert.equal(port.connection, 'pending');
var inputs = access.inputs;
var dummy = inputs.size;
dummy = inputs.keys();
dummy = inputs.values();
dummy = inputs.entries();
assert.equal(inputs.get(port.id), undefined);
inputs.forEach(function(p) {
assert.notEqual(p.name, name);
});
src.connect();
engine.refresh();
setTimeout(call3, 10);
Expand All @@ -597,6 +622,7 @@ module.exports = function(JZZ, PARAMS, DRIVER) {
var step = 0;

function onSuccess(midi) {
access = midi;
midi.inputs.forEach(function(p) {
if (p.name == name) {
port = p;
Expand Down

0 comments on commit c2b3c97

Please sign in to comment.