From eb0ad829d23971377dc001dbe0fbdf47a0ea2a0f Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Sat, 3 Jun 2023 15:36:29 +0200 Subject: [PATCH] Check that decoders consume all data This is extra important in the tests where we expect no changes to the display, as otherwise we can't tell the difference between success and a decoder that is simply waiting for more data. --- tests/test.copyrect.js | 27 ++++++++----- tests/test.hextile.js | 28 ++++++++----- tests/test.jpeg.js | 18 ++++++--- tests/test.raw.js | 89 +++++++++++++++++++++++++++--------------- tests/test.rre.js | 19 +++++---- tests/test.tight.js | 79 ++++++++++++++++++++++++------------- tests/test.tightpng.js | 10 +++-- tests/test.zrle.js | 54 +++++++++++++++++-------- 8 files changed, 215 insertions(+), 109 deletions(-) diff --git a/tests/test.copyrect.js b/tests/test.copyrect.js index 90ba0c68..a10cddce 100644 --- a/tests/test.copyrect.js +++ b/tests/test.copyrect.js @@ -9,23 +9,26 @@ import FakeWebSocket from './fake.websocket.js'; function testDecodeRect(decoder, x, y, width, height, data, display, depth) { let sock; + let done = false; sock = new Websock; sock.open("ws://example.com"); sock.on('message', () => { - decoder.decodeRect(x, y, width, height, sock, display, depth); + done = decoder.decodeRect(x, y, width, height, sock, display, depth); }); // Empty messages are filtered at multiple layers, so we need to // do a direct call if (data.length === 0) { - decoder.decodeRect(x, y, width, height, sock, display, depth); + done = decoder.decodeRect(x, y, width, height, sock, display, depth); } else { sock._websocket._receiveData(new Uint8Array(data)); } display.flip(); + + return done; } describe('CopyRect Decoder', function () { @@ -47,12 +50,15 @@ describe('CopyRect Decoder', function () { display.fillRect(0, 0, 2, 2, [ 0x00, 0x00, 0xff ]); display.fillRect(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]); - testDecodeRect(decoder, 0, 2, 2, 2, - [0x00, 0x02, 0x00, 0x00], - display, 24); - testDecodeRect(decoder, 2, 2, 2, 2, - [0x00, 0x00, 0x00, 0x00], - display, 24); + let done; + done = testDecodeRect(decoder, 0, 2, 2, 2, + [0x00, 0x02, 0x00, 0x00], + display, 24); + expect(done).to.be.true; + done = testDecodeRect(decoder, 2, 2, 2, 2, + [0x00, 0x00, 0x00, 0x00], + display, 24); + expect(done).to.be.true; let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, @@ -69,7 +75,9 @@ describe('CopyRect Decoder', function () { display.fillRect(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]); display.fillRect(0, 2, 2, 2, [ 0x00, 0xff, 0x00 ]); - testDecodeRect(decoder, 1, 2, 0, 0, [0x00, 0x00, 0x00, 0x00], display, 24); + let done = testDecodeRect(decoder, 1, 2, 0, 0, + [0x00, 0x00, 0x00, 0x00], + display, 24); let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, @@ -78,6 +86,7 @@ describe('CopyRect Decoder', function () { 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255 ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); }); diff --git a/tests/test.hextile.js b/tests/test.hextile.js index a7034f05..cbe6f7b5 100644 --- a/tests/test.hextile.js +++ b/tests/test.hextile.js @@ -9,23 +9,26 @@ import FakeWebSocket from './fake.websocket.js'; function testDecodeRect(decoder, x, y, width, height, data, display, depth) { let sock; + let done = false; sock = new Websock; sock.open("ws://example.com"); sock.on('message', () => { - decoder.decodeRect(x, y, width, height, sock, display, depth); + done = decoder.decodeRect(x, y, width, height, sock, display, depth); }); // Empty messages are filtered at multiple layers, so we need to // do a direct call if (data.length === 0) { - decoder.decodeRect(x, y, width, height, sock, display, depth); + done = decoder.decodeRect(x, y, width, height, sock, display, depth); } else { sock._websocket._receiveData(new Uint8Array(data)); } display.flip(); + + return done; } function push32(arr, num) { @@ -62,7 +65,7 @@ describe('Hextile Decoder', function () { data.push(2 | (2 << 4)); // x: 2, y: 2 data.push(1 | (1 << 4)); // width: 2, height: 2 - testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); + let done = testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, @@ -71,6 +74,7 @@ describe('Hextile Decoder', function () { 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255 ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); @@ -92,8 +96,9 @@ describe('Hextile Decoder', function () { data.push(0); } - testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); + let done = testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); @@ -102,13 +107,14 @@ describe('Hextile Decoder', function () { data.push(0x02); push32(data, 0x00ff0000); // becomes 00ff0000 --> #00FF00 bg color - testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); + let done = testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); let expected = []; for (let i = 0; i < 16; i++) { push32(expected, 0x00ff00ff); } + expect(done).to.be.true; expect(display).to.have.displayed(new Uint8Array(expected)); }); @@ -125,7 +131,7 @@ describe('Hextile Decoder', function () { // send an empty frame data.push(0x00); - testDecodeRect(decoder, 0, 0, 32, 4, data, display, 24); + let done = testDecodeRect(decoder, 0, 0, 32, 4, data, display, 24); let expected = []; for (let i = 0; i < 16; i++) { @@ -135,6 +141,7 @@ describe('Hextile Decoder', function () { push32(expected, 0x00ff00ff); // rect 2: same bkground color } + expect(done).to.be.true; expect(display).to.have.displayed(new Uint8Array(expected)); }); @@ -156,7 +163,7 @@ describe('Hextile Decoder', function () { data.push(2 | (2 << 4)); // x: 2, y: 2 data.push(1 | (1 << 4)); // width: 2, height: 2 - testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); + let done = testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, @@ -165,6 +172,7 @@ describe('Hextile Decoder', function () { 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255 ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); @@ -190,7 +198,7 @@ describe('Hextile Decoder', function () { data.push(0); // x: 0, y: 0 data.push(1 | (1 << 4)); // width: 2, height: 2 - testDecodeRect(decoder, 0, 0, 4, 17, data, display, 24); + let done = testDecodeRect(decoder, 0, 0, 4, 17, data, display, 24); let targetData = [ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, @@ -205,6 +213,7 @@ describe('Hextile Decoder', function () { } expected = expected.concat(targetData.slice(0, 16)); + expect(done).to.be.true; expect(display).to.have.displayed(new Uint8Array(expected)); }); @@ -218,7 +227,7 @@ describe('Hextile Decoder', function () { display.fillRect(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]); display.fillRect(0, 2, 2, 2, [ 0x00, 0xff, 0x00 ]); - testDecodeRect(decoder, 1, 2, 0, 0, [], display, 24); + let done = testDecodeRect(decoder, 1, 2, 0, 0, [], display, 24); let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, @@ -227,6 +236,7 @@ describe('Hextile Decoder', function () { 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255 ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); }); diff --git a/tests/test.jpeg.js b/tests/test.jpeg.js index 7580c617..5211cc7c 100644 --- a/tests/test.jpeg.js +++ b/tests/test.jpeg.js @@ -9,23 +9,26 @@ import FakeWebSocket from './fake.websocket.js'; function testDecodeRect(decoder, x, y, width, height, data, display, depth) { let sock; + let done = false; sock = new Websock; sock.open("ws://example.com"); sock.on('message', () => { - decoder.decodeRect(x, y, width, height, sock, display, depth); + done = decoder.decodeRect(x, y, width, height, sock, display, depth); }); // Empty messages are filtered at multiple layers, so we need to // do a direct call if (data.length === 0) { - decoder.decodeRect(x, y, width, height, sock, display, depth); + done = decoder.decodeRect(x, y, width, height, sock, display, depth); } else { sock._websocket._receiveData(new Uint8Array(data)); } display.flip(); + + return done; } describe('JPEG Decoder', function () { @@ -131,7 +134,8 @@ describe('JPEG Decoder', function () { 0xff, 0xd9, ]; - testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); + let decodeDone = testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); + expect(decodeDone).to.be.true; let targetData = new Uint8Array([ 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, @@ -244,7 +248,10 @@ describe('JPEG Decoder', function () { 0xff, 0xd9, ]; - testDecodeRect(decoder, 0, 0, 4, 4, data1, display, 24); + let decodeDone; + + decodeDone = testDecodeRect(decoder, 0, 0, 4, 4, data1, display, 24); + expect(decodeDone).to.be.true; display.fillRect(0, 0, 4, 4, [128, 128, 128, 255]); @@ -265,7 +272,8 @@ describe('JPEG Decoder', function () { 0xcf, 0xff, 0x00, 0x0b, 0xab, 0x1f, 0xff, 0xd9, ]; - testDecodeRect(decoder, 0, 0, 4, 4, data2, display, 24); + decodeDone = testDecodeRect(decoder, 0, 0, 4, 4, data2, display, 24); + expect(decodeDone).to.be.true; let targetData = new Uint8Array([ 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, diff --git a/tests/test.raw.js b/tests/test.raw.js index bc7adc78..4a634ccd 100644 --- a/tests/test.raw.js +++ b/tests/test.raw.js @@ -9,23 +9,26 @@ import FakeWebSocket from './fake.websocket.js'; function testDecodeRect(decoder, x, y, width, height, data, display, depth) { let sock; + let done = false; sock = new Websock; sock.open("ws://example.com"); sock.on('message', () => { - decoder.decodeRect(x, y, width, height, sock, display, depth); + done = decoder.decodeRect(x, y, width, height, sock, display, depth); }); // Empty messages are filtered at multiple layers, so we need to // do a direct call if (data.length === 0) { - decoder.decodeRect(x, y, width, height, sock, display, depth); + done = decoder.decodeRect(x, y, width, height, sock, display, depth); } else { sock._websocket._receiveData(new Uint8Array(data)); } display.flip(); + + return done; } describe('Raw Decoder', function () { @@ -42,22 +45,36 @@ describe('Raw Decoder', function () { }); it('should handle the Raw encoding', function () { - testDecodeRect(decoder, 0, 0, 2, 2, - [0xff, 0x00, 0x00, 0, 0x00, 0xff, 0x00, 0, - 0x00, 0xff, 0x00, 0, 0xff, 0x00, 0x00, 0], - display, 24); - testDecodeRect(decoder, 2, 0, 2, 2, - [0x00, 0x00, 0xff, 0, 0x00, 0x00, 0xff, 0, - 0x00, 0x00, 0xff, 0, 0x00, 0x00, 0xff, 0], - display, 24); - testDecodeRect(decoder, 0, 2, 4, 1, - [0xee, 0x00, 0xff, 0, 0x00, 0xee, 0xff, 0, - 0xaa, 0xee, 0xff, 0, 0xab, 0xee, 0xff, 0], - display, 24); - testDecodeRect(decoder, 0, 3, 4, 1, - [0xee, 0x00, 0xff, 0, 0x00, 0xee, 0xff, 0, - 0xaa, 0xee, 0xff, 0, 0xab, 0xee, 0xff, 0], - display, 24); + let done; + + done = testDecodeRect(decoder, 0, 0, 2, 2, + [0xff, 0x00, 0x00, 0, + 0x00, 0xff, 0x00, 0, + 0x00, 0xff, 0x00, 0, + 0xff, 0x00, 0x00, 0], + display, 24); + expect(done).to.be.true; + done = testDecodeRect(decoder, 2, 0, 2, 2, + [0x00, 0x00, 0xff, 0, + 0x00, 0x00, 0xff, 0, + 0x00, 0x00, 0xff, 0, + 0x00, 0x00, 0xff, 0], + display, 24); + expect(done).to.be.true; + done = testDecodeRect(decoder, 0, 2, 4, 1, + [0xee, 0x00, 0xff, 0, + 0x00, 0xee, 0xff, 0, + 0xaa, 0xee, 0xff, 0, + 0xab, 0xee, 0xff, 0], + display, 24); + expect(done).to.be.true; + done = testDecodeRect(decoder, 0, 3, 4, 1, + [0xee, 0x00, 0xff, 0, + 0x00, 0xee, 0xff, 0, + 0xaa, 0xee, 0xff, 0, + 0xab, 0xee, 0xff, 0], + display, 24); + expect(done).to.be.true; let targetData = new Uint8Array([ 0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, @@ -70,18 +87,24 @@ describe('Raw Decoder', function () { }); it('should handle the Raw encoding in low colour mode', function () { - testDecodeRect(decoder, 0, 0, 2, 2, - [0x30, 0x30, 0x30, 0x30], - display, 8); - testDecodeRect(decoder, 2, 0, 2, 2, - [0x0c, 0x0c, 0x0c, 0x0c], - display, 8); - testDecodeRect(decoder, 0, 2, 4, 1, - [0x0c, 0x0c, 0x30, 0x30], - display, 8); - testDecodeRect(decoder, 0, 3, 4, 1, - [0x0c, 0x0c, 0x30, 0x30], - display, 8); + let done; + + done = testDecodeRect(decoder, 0, 0, 2, 2, + [0x30, 0x30, 0x30, 0x30], + display, 8); + expect(done).to.be.true; + done = testDecodeRect(decoder, 2, 0, 2, 2, + [0x0c, 0x0c, 0x0c, 0x0c], + display, 8); + expect(done).to.be.true; + done = testDecodeRect(decoder, 0, 2, 4, 1, + [0x0c, 0x0c, 0x30, 0x30], + display, 8); + expect(done).to.be.true; + done = testDecodeRect(decoder, 0, 3, 4, 1, + [0x0c, 0x0c, 0x30, 0x30], + display, 8); + expect(done).to.be.true; let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, @@ -98,7 +121,7 @@ describe('Raw Decoder', function () { display.fillRect(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]); display.fillRect(0, 2, 2, 2, [ 0x00, 0xff, 0x00 ]); - testDecodeRect(decoder, 1, 2, 0, 0, [], display, 24); + let done = testDecodeRect(decoder, 1, 2, 0, 0, [], display, 24); let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, @@ -107,6 +130,7 @@ describe('Raw Decoder', function () { 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255 ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); @@ -115,7 +139,7 @@ describe('Raw Decoder', function () { display.fillRect(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]); display.fillRect(0, 2, 2, 2, [ 0x00, 0xff, 0x00 ]); - testDecodeRect(decoder, 1, 2, 0, 0, [], display, 8); + let done = testDecodeRect(decoder, 1, 2, 0, 0, [], display, 8); let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, @@ -124,6 +148,7 @@ describe('Raw Decoder', function () { 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255 ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); }); diff --git a/tests/test.rre.js b/tests/test.rre.js index ac3aabbb..c55d7f39 100644 --- a/tests/test.rre.js +++ b/tests/test.rre.js @@ -9,23 +9,26 @@ import FakeWebSocket from './fake.websocket.js'; function testDecodeRect(decoder, x, y, width, height, data, display, depth) { let sock; + let done = false; sock = new Websock; sock.open("ws://example.com"); sock.on('message', () => { - decoder.decodeRect(x, y, width, height, sock, display, depth); + done = decoder.decodeRect(x, y, width, height, sock, display, depth); }); // Empty messages are filtered at multiple layers, so we need to // do a direct call if (data.length === 0) { - decoder.decodeRect(x, y, width, height, sock, display, depth); + done = decoder.decodeRect(x, y, width, height, sock, display, depth); } else { sock._websocket._receiveData(new Uint8Array(data)); } display.flip(); + + return done; } function push16(arr, num) { @@ -76,7 +79,7 @@ describe('RRE Decoder', function () { push16(data, 2); // width: 2 push16(data, 2); // height: 2 - testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); + let done = testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, @@ -85,6 +88,7 @@ describe('RRE Decoder', function () { 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255 ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); @@ -93,10 +97,10 @@ describe('RRE Decoder', function () { display.fillRect(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]); display.fillRect(0, 2, 2, 2, [ 0x00, 0xff, 0x00 ]); - testDecodeRect(decoder, 1, 2, 0, 0, - [ 0x00, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff ], - display, 24); + let done = testDecodeRect(decoder, 1, 2, 0, 0, + [ 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff ], + display, 24); let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, @@ -105,6 +109,7 @@ describe('RRE Decoder', function () { 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255 ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); }); diff --git a/tests/test.tight.js b/tests/test.tight.js index cc5db36b..cc92c1a2 100644 --- a/tests/test.tight.js +++ b/tests/test.tight.js @@ -9,23 +9,26 @@ import FakeWebSocket from './fake.websocket.js'; function testDecodeRect(decoder, x, y, width, height, data, display, depth) { let sock; + let done = false; sock = new Websock; sock.open("ws://example.com"); sock.on('message', () => { - decoder.decodeRect(x, y, width, height, sock, display, depth); + done = decoder.decodeRect(x, y, width, height, sock, display, depth); }); // Empty messages are filtered at multiple layers, so we need to // do a direct call if (data.length === 0) { - decoder.decodeRect(x, y, width, height, sock, display, depth); + done = decoder.decodeRect(x, y, width, height, sock, display, depth); } else { sock._websocket._receiveData(new Uint8Array(data)); } display.flip(); + + return done; } describe('Tight Decoder', function () { @@ -42,9 +45,9 @@ describe('Tight Decoder', function () { }); it('should handle fill rects', function () { - testDecodeRect(decoder, 0, 0, 4, 4, - [0x80, 0xff, 0x88, 0x44], - display, 24); + let done = testDecodeRect(decoder, 0, 0, 4, 4, + [0x80, 0xff, 0x88, 0x44], + display, 24); let targetData = new Uint8Array([ 0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255, @@ -53,21 +56,31 @@ describe('Tight Decoder', function () { 0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255, ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); it('should handle uncompressed copy rects', function () { + let done; let blueData = [ 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff ]; let greenData = [ 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00 ]; - testDecodeRect(decoder, 0, 0, 2, 1, blueData, display, 24); - testDecodeRect(decoder, 0, 1, 2, 1, blueData, display, 24); - testDecodeRect(decoder, 2, 0, 2, 1, greenData, display, 24); - testDecodeRect(decoder, 2, 1, 2, 1, greenData, display, 24); - testDecodeRect(decoder, 0, 2, 2, 1, greenData, display, 24); - testDecodeRect(decoder, 0, 3, 2, 1, greenData, display, 24); - testDecodeRect(decoder, 2, 2, 2, 1, blueData, display, 24); - testDecodeRect(decoder, 2, 3, 2, 1, blueData, display, 24); + done = testDecodeRect(decoder, 0, 0, 2, 1, blueData, display, 24); + expect(done).to.be.true; + done = testDecodeRect(decoder, 0, 1, 2, 1, blueData, display, 24); + expect(done).to.be.true; + done = testDecodeRect(decoder, 2, 0, 2, 1, greenData, display, 24); + expect(done).to.be.true; + done = testDecodeRect(decoder, 2, 1, 2, 1, greenData, display, 24); + expect(done).to.be.true; + done = testDecodeRect(decoder, 0, 2, 2, 1, greenData, display, 24); + expect(done).to.be.true; + done = testDecodeRect(decoder, 0, 3, 2, 1, greenData, display, 24); + expect(done).to.be.true; + done = testDecodeRect(decoder, 2, 2, 2, 1, blueData, display, 24); + expect(done).to.be.true; + done = testDecodeRect(decoder, 2, 3, 2, 1, blueData, display, 24); + expect(done).to.be.true; let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, @@ -89,7 +102,7 @@ describe('Tight Decoder', function () { 0x60, 0x82, 0x01, 0x99, 0x8d, 0x29, 0x02, 0xa6, 0x00, 0x7e, 0xbf, 0x0f, 0xf1 ]; - testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); + let done = testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, @@ -98,6 +111,7 @@ describe('Tight Decoder', function () { 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255 ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); @@ -110,7 +124,7 @@ describe('Tight Decoder', function () { // Pixels 0x30, 0x30, 0xc0, 0xc0 ]; - testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); + let done = testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, @@ -119,6 +133,7 @@ describe('Tight Decoder', function () { 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255 ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); @@ -135,7 +150,7 @@ describe('Tight Decoder', function () { 0x78, 0x9c, 0x33, 0x30, 0x38, 0x70, 0xc0, 0x00, 0x8a, 0x01, 0x21, 0x3c, 0x05, 0xa1 ]; - testDecodeRect(decoder, 0, 0, 4, 12, data, display, 24); + let done = testDecodeRect(decoder, 0, 0, 4, 12, data, display, 24); let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, @@ -152,10 +167,12 @@ describe('Tight Decoder', function () { 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255 ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); it('should handle uncompressed palette rects', function () { + let done; let data1 = [ // Control bytes 0x40, 0x01, @@ -171,8 +188,10 @@ describe('Tight Decoder', function () { // Pixels 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00 ]; - testDecodeRect(decoder, 0, 0, 4, 2, data1, display, 24); - testDecodeRect(decoder, 0, 2, 4, 2, data2, display, 24); + done = testDecodeRect(decoder, 0, 0, 4, 2, data1, display, 24); + expect(done).to.be.true; + done = testDecodeRect(decoder, 0, 2, 4, 2, data2, display, 24); + expect(done).to.be.true; let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, @@ -196,7 +215,7 @@ describe('Tight Decoder', function () { 0x62, 0x08, 0xc9, 0xc0, 0x00, 0x00, 0x00, 0x54, 0x00, 0x09 ]; - testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); + let done = testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, @@ -205,6 +224,7 @@ describe('Tight Decoder', function () { 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255 ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); @@ -221,7 +241,7 @@ describe('Tight Decoder', function () { display.fillRect(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]); display.fillRect(0, 2, 2, 2, [ 0x00, 0xff, 0x00 ]); - testDecodeRect(decoder, 1, 2, 0, 0, [ 0x00 ], display, 24); + let done = testDecodeRect(decoder, 1, 2, 0, 0, [ 0x00 ], display, 24); let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, @@ -230,6 +250,7 @@ describe('Tight Decoder', function () { 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255 ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); @@ -238,10 +259,10 @@ describe('Tight Decoder', function () { display.fillRect(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]); display.fillRect(0, 2, 2, 2, [ 0x00, 0xff, 0x00 ]); - testDecodeRect(decoder, 1, 2, 0, 0, - [ 0x40, 0x01, 0x01, - 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff ], display, 24); + let done = testDecodeRect(decoder, 1, 2, 0, 0, + [ 0x40, 0x01, 0x01, + 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff ], display, 24); let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, @@ -250,6 +271,7 @@ describe('Tight Decoder', function () { 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255 ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); @@ -258,8 +280,9 @@ describe('Tight Decoder', function () { display.fillRect(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]); display.fillRect(0, 2, 2, 2, [ 0x00, 0xff, 0x00 ]); - testDecodeRect(decoder, 1, 2, 0, 0, - [ 0x80, 0xff, 0xff, 0xff ], display, 24); + let done = testDecodeRect(decoder, 1, 2, 0, 0, + [ 0x80, 0xff, 0xff, 0xff ], + display, 24); let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, @@ -268,6 +291,7 @@ describe('Tight Decoder', function () { 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255 ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); @@ -369,7 +393,8 @@ describe('Tight Decoder', function () { 0x3f, 0xeb, 0xff, 0x00, 0xff, 0xd9, ]; - testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); + let decodeDone = testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); + expect(decodeDone).to.be.true; let targetData = new Uint8Array([ 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, diff --git a/tests/test.tightpng.js b/tests/test.tightpng.js index 253400b8..c72c20d7 100644 --- a/tests/test.tightpng.js +++ b/tests/test.tightpng.js @@ -9,23 +9,26 @@ import FakeWebSocket from './fake.websocket.js'; function testDecodeRect(decoder, x, y, width, height, data, display, depth) { let sock; + let done = false; sock = new Websock; sock.open("ws://example.com"); sock.on('message', () => { - decoder.decodeRect(x, y, width, height, sock, display, depth); + done = decoder.decodeRect(x, y, width, height, sock, display, depth); }); // Empty messages are filtered at multiple layers, so we need to // do a direct call if (data.length === 0) { - decoder.decodeRect(x, y, width, height, sock, display, depth); + done = decoder.decodeRect(x, y, width, height, sock, display, depth); } else { sock._websocket._receiveData(new Uint8Array(data)); } display.flip(); + + return done; } describe('TightPng Decoder', function () { @@ -119,7 +122,8 @@ describe('TightPng Decoder', function () { 0xae, 0x42, 0x60, 0x82, ]; - testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); + let decodeDone = testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24); + expect(decodeDone).to.be.true; let targetData = new Uint8Array([ 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, diff --git a/tests/test.zrle.js b/tests/test.zrle.js index e09d208d..be046409 100644 --- a/tests/test.zrle.js +++ b/tests/test.zrle.js @@ -9,23 +9,26 @@ import FakeWebSocket from './fake.websocket.js'; function testDecodeRect(decoder, x, y, width, height, data, display, depth) { let sock; + let done = false; sock = new Websock; sock.open("ws://example.com"); sock.on('message', () => { - decoder.decodeRect(x, y, width, height, sock, display, depth); + done = decoder.decodeRect(x, y, width, height, sock, display, depth); }); // Empty messages are filtered at multiple layers, so we need to // do a direct call if (data.length === 0) { - decoder.decodeRect(x, y, width, height, sock, display, depth); + done = decoder.decodeRect(x, y, width, height, sock, display, depth); } else { sock._websocket._receiveData(new Uint8Array(data)); } display.flip(); + + return done; } describe('ZRLE Decoder', function () { @@ -42,9 +45,11 @@ describe('ZRLE Decoder', function () { }); it('should handle the Raw subencoding', function () { - testDecodeRect(decoder, 0, 0, 4, 4, - [0x00, 0x00, 0x00, 0x0e, 0x78, 0x5e, 0x62, 0x60, 0x60, 0xf8, 0x4f, 0x12, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff], - display, 24); + let done = testDecodeRect(decoder, 0, 0, 4, 4, + [0x00, 0x00, 0x00, 0x0e, 0x78, 0x5e, + 0x62, 0x60, 0x60, 0xf8, 0x4f, 0x12, + 0x02, 0x00, 0x00, 0x00, 0xff, 0xff], + display, 24); let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, @@ -53,13 +58,16 @@ describe('ZRLE Decoder', function () { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); it('should handle the Solid subencoding', function () { - testDecodeRect(decoder, 0, 0, 4, 4, - [0x00, 0x00, 0x00, 0x0c, 0x78, 0x5e, 0x62, 0x64, 0x60, 0xf8, 0x0f, 0x00, 0x00, 0x00, 0xff, 0xff], - display, 24); + let done = testDecodeRect(decoder, 0, 0, 4, 4, + [0x00, 0x00, 0x00, 0x0c, 0x78, 0x5e, + 0x62, 0x64, 0x60, 0xf8, 0x0f, 0x00, + 0x00, 0x00, 0xff, 0xff], + display, 24); let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, @@ -68,14 +76,18 @@ describe('ZRLE Decoder', function () { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); it('should handle the Palette Tile subencoding', function () { - testDecodeRect(decoder, 0, 0, 4, 4, - [0x00, 0x00, 0x00, 0x12, 0x78, 0x5E, 0x62, 0x62, 0x60, 248, 0xff, 0x9F, 0x01, 0x08, 0x3E, 0x7C, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff], - display, 24); + let done = testDecodeRect(decoder, 0, 0, 4, 4, + [0x00, 0x00, 0x00, 0x12, 0x78, 0x5E, + 0x62, 0x62, 0x60, 248, 0xff, 0x9F, + 0x01, 0x08, 0x3E, 0x7C, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff], + display, 24); let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, @@ -84,13 +96,16 @@ describe('ZRLE Decoder', function () { 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); it('should handle the RLE Tile subencoding', function () { - testDecodeRect(decoder, 0, 0, 4, 4, - [0x00, 0x00, 0x00, 0x0d, 0x78, 0x5e, 0x6a, 0x60, 0x60, 0xf8, 0x2f, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff], - display, 24); + let done = testDecodeRect(decoder, 0, 0, 4, 4, + [0x00, 0x00, 0x00, 0x0d, 0x78, 0x5e, + 0x6a, 0x60, 0x60, 0xf8, 0x2f, 0x00, + 0x00, 0x00, 0x00, 0xff, 0xff], + display, 24); let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, @@ -99,13 +114,17 @@ describe('ZRLE Decoder', function () { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); }); it('should handle the RLE Palette Tile subencoding', function () { - testDecodeRect(decoder, 0, 0, 4, 4, - [0x00, 0x00, 0x00, 0x11, 0x78, 0x5e, 0x6a, 0x62, 0x60, 0xf8, 0xff, 0x9f, 0x81, 0xa1, 0x81, 0x1f, 0x00, 0x00, 0x00, 0xff, 0xff], - display, 24); + let done = testDecodeRect(decoder, 0, 0, 4, 4, + [0x00, 0x00, 0x00, 0x11, 0x78, 0x5e, + 0x6a, 0x62, 0x60, 0xf8, 0xff, 0x9f, + 0x81, 0xa1, 0x81, 0x1f, 0x00, 0x00, + 0x00, 0xff, 0xff], + display, 24); let targetData = new Uint8Array([ 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, @@ -114,6 +133,7 @@ describe('ZRLE Decoder', function () { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff ]); + expect(done).to.be.true; expect(display).to.have.displayed(targetData); });