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.
This commit is contained in:
Pierre Ossman 2023-06-03 15:36:29 +02:00
parent d33f5ce77f
commit eb0ad829d2
8 changed files with 215 additions and 109 deletions

View File

@ -9,23 +9,26 @@ import FakeWebSocket from './fake.websocket.js';
function testDecodeRect(decoder, x, y, width, height, data, display, depth) { function testDecodeRect(decoder, x, y, width, height, data, display, depth) {
let sock; let sock;
let done = false;
sock = new Websock; sock = new Websock;
sock.open("ws://example.com"); sock.open("ws://example.com");
sock.on('message', () => { 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 // Empty messages are filtered at multiple layers, so we need to
// do a direct call // do a direct call
if (data.length === 0) { if (data.length === 0) {
decoder.decodeRect(x, y, width, height, sock, display, depth); done = decoder.decodeRect(x, y, width, height, sock, display, depth);
} else { } else {
sock._websocket._receiveData(new Uint8Array(data)); sock._websocket._receiveData(new Uint8Array(data));
} }
display.flip(); display.flip();
return done;
} }
describe('CopyRect Decoder', function () { describe('CopyRect Decoder', function () {
@ -47,12 +50,15 @@ describe('CopyRect Decoder', function () {
display.fillRect(0, 0, 2, 2, [ 0x00, 0x00, 0xff ]); display.fillRect(0, 0, 2, 2, [ 0x00, 0x00, 0xff ]);
display.fillRect(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]); display.fillRect(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]);
testDecodeRect(decoder, 0, 2, 2, 2, let done;
[0x00, 0x02, 0x00, 0x00], done = testDecodeRect(decoder, 0, 2, 2, 2,
display, 24); [0x00, 0x02, 0x00, 0x00],
testDecodeRect(decoder, 2, 2, 2, 2, display, 24);
[0x00, 0x00, 0x00, 0x00], expect(done).to.be.true;
display, 24); done = testDecodeRect(decoder, 2, 2, 2, 2,
[0x00, 0x00, 0x00, 0x00],
display, 24);
expect(done).to.be.true;
let targetData = new Uint8Array([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 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(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]);
display.fillRect(0, 2, 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([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 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 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); expect(display).to.have.displayed(targetData);
}); });
}); });

View File

@ -9,23 +9,26 @@ import FakeWebSocket from './fake.websocket.js';
function testDecodeRect(decoder, x, y, width, height, data, display, depth) { function testDecodeRect(decoder, x, y, width, height, data, display, depth) {
let sock; let sock;
let done = false;
sock = new Websock; sock = new Websock;
sock.open("ws://example.com"); sock.open("ws://example.com");
sock.on('message', () => { 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 // Empty messages are filtered at multiple layers, so we need to
// do a direct call // do a direct call
if (data.length === 0) { if (data.length === 0) {
decoder.decodeRect(x, y, width, height, sock, display, depth); done = decoder.decodeRect(x, y, width, height, sock, display, depth);
} else { } else {
sock._websocket._receiveData(new Uint8Array(data)); sock._websocket._receiveData(new Uint8Array(data));
} }
display.flip(); display.flip();
return done;
} }
function push32(arr, num) { function push32(arr, num) {
@ -62,7 +65,7 @@ describe('Hextile Decoder', function () {
data.push(2 | (2 << 4)); // x: 2, y: 2 data.push(2 | (2 << 4)); // x: 2, y: 2
data.push(1 | (1 << 4)); // width: 2, height: 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([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 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 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); expect(display).to.have.displayed(targetData);
}); });
@ -92,8 +96,9 @@ describe('Hextile Decoder', function () {
data.push(0); 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); expect(display).to.have.displayed(targetData);
}); });
@ -102,13 +107,14 @@ describe('Hextile Decoder', function () {
data.push(0x02); data.push(0x02);
push32(data, 0x00ff0000); // becomes 00ff0000 --> #00FF00 bg color 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 = []; let expected = [];
for (let i = 0; i < 16; i++) { for (let i = 0; i < 16; i++) {
push32(expected, 0x00ff00ff); push32(expected, 0x00ff00ff);
} }
expect(done).to.be.true;
expect(display).to.have.displayed(new Uint8Array(expected)); expect(display).to.have.displayed(new Uint8Array(expected));
}); });
@ -125,7 +131,7 @@ describe('Hextile Decoder', function () {
// send an empty frame // send an empty frame
data.push(0x00); 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 = []; let expected = [];
for (let i = 0; i < 16; i++) { for (let i = 0; i < 16; i++) {
@ -135,6 +141,7 @@ describe('Hextile Decoder', function () {
push32(expected, 0x00ff00ff); // rect 2: same bkground color push32(expected, 0x00ff00ff); // rect 2: same bkground color
} }
expect(done).to.be.true;
expect(display).to.have.displayed(new Uint8Array(expected)); 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(2 | (2 << 4)); // x: 2, y: 2
data.push(1 | (1 << 4)); // width: 2, height: 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([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 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 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); expect(display).to.have.displayed(targetData);
}); });
@ -190,7 +198,7 @@ describe('Hextile Decoder', function () {
data.push(0); // x: 0, y: 0 data.push(0); // x: 0, y: 0
data.push(1 | (1 << 4)); // width: 2, height: 2 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 = [ let targetData = [
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 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)); expected = expected.concat(targetData.slice(0, 16));
expect(done).to.be.true;
expect(display).to.have.displayed(new Uint8Array(expected)); 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(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]);
display.fillRect(0, 2, 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([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 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 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); expect(display).to.have.displayed(targetData);
}); });
}); });

View File

@ -9,23 +9,26 @@ import FakeWebSocket from './fake.websocket.js';
function testDecodeRect(decoder, x, y, width, height, data, display, depth) { function testDecodeRect(decoder, x, y, width, height, data, display, depth) {
let sock; let sock;
let done = false;
sock = new Websock; sock = new Websock;
sock.open("ws://example.com"); sock.open("ws://example.com");
sock.on('message', () => { 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 // Empty messages are filtered at multiple layers, so we need to
// do a direct call // do a direct call
if (data.length === 0) { if (data.length === 0) {
decoder.decodeRect(x, y, width, height, sock, display, depth); done = decoder.decodeRect(x, y, width, height, sock, display, depth);
} else { } else {
sock._websocket._receiveData(new Uint8Array(data)); sock._websocket._receiveData(new Uint8Array(data));
} }
display.flip(); display.flip();
return done;
} }
describe('JPEG Decoder', function () { describe('JPEG Decoder', function () {
@ -131,7 +134,8 @@ describe('JPEG Decoder', function () {
0xff, 0xd9, 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([ let targetData = new Uint8Array([
0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 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, 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]); 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, 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([ let targetData = new Uint8Array([
0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255,

View File

@ -9,23 +9,26 @@ import FakeWebSocket from './fake.websocket.js';
function testDecodeRect(decoder, x, y, width, height, data, display, depth) { function testDecodeRect(decoder, x, y, width, height, data, display, depth) {
let sock; let sock;
let done = false;
sock = new Websock; sock = new Websock;
sock.open("ws://example.com"); sock.open("ws://example.com");
sock.on('message', () => { 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 // Empty messages are filtered at multiple layers, so we need to
// do a direct call // do a direct call
if (data.length === 0) { if (data.length === 0) {
decoder.decodeRect(x, y, width, height, sock, display, depth); done = decoder.decodeRect(x, y, width, height, sock, display, depth);
} else { } else {
sock._websocket._receiveData(new Uint8Array(data)); sock._websocket._receiveData(new Uint8Array(data));
} }
display.flip(); display.flip();
return done;
} }
describe('Raw Decoder', function () { describe('Raw Decoder', function () {
@ -42,22 +45,36 @@ describe('Raw Decoder', function () {
}); });
it('should handle the Raw encoding', function () { it('should handle the Raw encoding', function () {
testDecodeRect(decoder, 0, 0, 2, 2, let done;
[0xff, 0x00, 0x00, 0, 0x00, 0xff, 0x00, 0,
0x00, 0xff, 0x00, 0, 0xff, 0x00, 0x00, 0], done = testDecodeRect(decoder, 0, 0, 2, 2,
display, 24); [0xff, 0x00, 0x00, 0,
testDecodeRect(decoder, 2, 0, 2, 2, 0x00, 0xff, 0x00, 0,
[0x00, 0x00, 0xff, 0, 0x00, 0x00, 0xff, 0, 0x00, 0xff, 0x00, 0,
0x00, 0x00, 0xff, 0, 0x00, 0x00, 0xff, 0], 0xff, 0x00, 0x00, 0],
display, 24); display, 24);
testDecodeRect(decoder, 0, 2, 4, 1, expect(done).to.be.true;
[0xee, 0x00, 0xff, 0, 0x00, 0xee, 0xff, 0, done = testDecodeRect(decoder, 2, 0, 2, 2,
0xaa, 0xee, 0xff, 0, 0xab, 0xee, 0xff, 0], [0x00, 0x00, 0xff, 0,
display, 24); 0x00, 0x00, 0xff, 0,
testDecodeRect(decoder, 0, 3, 4, 1, 0x00, 0x00, 0xff, 0,
[0xee, 0x00, 0xff, 0, 0x00, 0xee, 0xff, 0, 0x00, 0x00, 0xff, 0],
0xaa, 0xee, 0xff, 0, 0xab, 0xee, 0xff, 0], display, 24);
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([ let targetData = new Uint8Array([
0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 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 () { it('should handle the Raw encoding in low colour mode', function () {
testDecodeRect(decoder, 0, 0, 2, 2, let done;
[0x30, 0x30, 0x30, 0x30],
display, 8); done = testDecodeRect(decoder, 0, 0, 2, 2,
testDecodeRect(decoder, 2, 0, 2, 2, [0x30, 0x30, 0x30, 0x30],
[0x0c, 0x0c, 0x0c, 0x0c], display, 8);
display, 8); expect(done).to.be.true;
testDecodeRect(decoder, 0, 2, 4, 1, done = testDecodeRect(decoder, 2, 0, 2, 2,
[0x0c, 0x0c, 0x30, 0x30], [0x0c, 0x0c, 0x0c, 0x0c],
display, 8); display, 8);
testDecodeRect(decoder, 0, 3, 4, 1, expect(done).to.be.true;
[0x0c, 0x0c, 0x30, 0x30], done = testDecodeRect(decoder, 0, 2, 4, 1,
display, 8); [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([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 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(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]);
display.fillRect(0, 2, 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([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 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 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); 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(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]);
display.fillRect(0, 2, 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([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 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 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); expect(display).to.have.displayed(targetData);
}); });
}); });

View File

@ -9,23 +9,26 @@ import FakeWebSocket from './fake.websocket.js';
function testDecodeRect(decoder, x, y, width, height, data, display, depth) { function testDecodeRect(decoder, x, y, width, height, data, display, depth) {
let sock; let sock;
let done = false;
sock = new Websock; sock = new Websock;
sock.open("ws://example.com"); sock.open("ws://example.com");
sock.on('message', () => { 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 // Empty messages are filtered at multiple layers, so we need to
// do a direct call // do a direct call
if (data.length === 0) { if (data.length === 0) {
decoder.decodeRect(x, y, width, height, sock, display, depth); done = decoder.decodeRect(x, y, width, height, sock, display, depth);
} else { } else {
sock._websocket._receiveData(new Uint8Array(data)); sock._websocket._receiveData(new Uint8Array(data));
} }
display.flip(); display.flip();
return done;
} }
function push16(arr, num) { function push16(arr, num) {
@ -76,7 +79,7 @@ describe('RRE Decoder', function () {
push16(data, 2); // width: 2 push16(data, 2); // width: 2
push16(data, 2); // height: 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([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 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 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); 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(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]);
display.fillRect(0, 2, 2, 2, [ 0x00, 0xff, 0x00 ]); display.fillRect(0, 2, 2, 2, [ 0x00, 0xff, 0x00 ]);
testDecodeRect(decoder, 1, 2, 0, 0, let done = testDecodeRect(decoder, 1, 2, 0, 0,
[ 0x00, 0x00, 0x00, 0x00, [ 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff ], 0xff, 0xff, 0xff, 0xff ],
display, 24); display, 24);
let targetData = new Uint8Array([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 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 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); expect(display).to.have.displayed(targetData);
}); });
}); });

View File

@ -9,23 +9,26 @@ import FakeWebSocket from './fake.websocket.js';
function testDecodeRect(decoder, x, y, width, height, data, display, depth) { function testDecodeRect(decoder, x, y, width, height, data, display, depth) {
let sock; let sock;
let done = false;
sock = new Websock; sock = new Websock;
sock.open("ws://example.com"); sock.open("ws://example.com");
sock.on('message', () => { 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 // Empty messages are filtered at multiple layers, so we need to
// do a direct call // do a direct call
if (data.length === 0) { if (data.length === 0) {
decoder.decodeRect(x, y, width, height, sock, display, depth); done = decoder.decodeRect(x, y, width, height, sock, display, depth);
} else { } else {
sock._websocket._receiveData(new Uint8Array(data)); sock._websocket._receiveData(new Uint8Array(data));
} }
display.flip(); display.flip();
return done;
} }
describe('Tight Decoder', function () { describe('Tight Decoder', function () {
@ -42,9 +45,9 @@ describe('Tight Decoder', function () {
}); });
it('should handle fill rects', function () { it('should handle fill rects', function () {
testDecodeRect(decoder, 0, 0, 4, 4, let done = testDecodeRect(decoder, 0, 0, 4, 4,
[0x80, 0xff, 0x88, 0x44], [0x80, 0xff, 0x88, 0x44],
display, 24); display, 24);
let targetData = new Uint8Array([ let targetData = new Uint8Array([
0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255, 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, 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); expect(display).to.have.displayed(targetData);
}); });
it('should handle uncompressed copy rects', function () { it('should handle uncompressed copy rects', function () {
let done;
let blueData = [ 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff ]; let blueData = [ 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff ];
let greenData = [ 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00 ]; let greenData = [ 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00 ];
testDecodeRect(decoder, 0, 0, 2, 1, blueData, display, 24); done = testDecodeRect(decoder, 0, 0, 2, 1, blueData, display, 24);
testDecodeRect(decoder, 0, 1, 2, 1, blueData, display, 24); expect(done).to.be.true;
testDecodeRect(decoder, 2, 0, 2, 1, greenData, display, 24); done = testDecodeRect(decoder, 0, 1, 2, 1, blueData, display, 24);
testDecodeRect(decoder, 2, 1, 2, 1, greenData, display, 24); expect(done).to.be.true;
testDecodeRect(decoder, 0, 2, 2, 1, greenData, display, 24); done = testDecodeRect(decoder, 2, 0, 2, 1, greenData, display, 24);
testDecodeRect(decoder, 0, 3, 2, 1, greenData, display, 24); expect(done).to.be.true;
testDecodeRect(decoder, 2, 2, 2, 1, blueData, display, 24); done = testDecodeRect(decoder, 2, 1, 2, 1, greenData, display, 24);
testDecodeRect(decoder, 2, 3, 2, 1, blueData, 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([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 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, 0x60, 0x82, 0x01, 0x99, 0x8d, 0x29, 0x02, 0xa6,
0x00, 0x7e, 0xbf, 0x0f, 0xf1 ]; 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([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 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 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); expect(display).to.have.displayed(targetData);
}); });
@ -110,7 +124,7 @@ describe('Tight Decoder', function () {
// Pixels // Pixels
0x30, 0x30, 0xc0, 0xc0 ]; 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([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 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 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); expect(display).to.have.displayed(targetData);
}); });
@ -135,7 +150,7 @@ describe('Tight Decoder', function () {
0x78, 0x9c, 0x33, 0x30, 0x38, 0x70, 0xc0, 0x00, 0x78, 0x9c, 0x33, 0x30, 0x38, 0x70, 0xc0, 0x00,
0x8a, 0x01, 0x21, 0x3c, 0x05, 0xa1 ]; 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([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 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 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); expect(display).to.have.displayed(targetData);
}); });
it('should handle uncompressed palette rects', function () { it('should handle uncompressed palette rects', function () {
let done;
let data1 = [ let data1 = [
// Control bytes // Control bytes
0x40, 0x01, 0x40, 0x01,
@ -171,8 +188,10 @@ describe('Tight Decoder', function () {
// Pixels // Pixels
0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00 ]; 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00 ];
testDecodeRect(decoder, 0, 0, 4, 2, data1, display, 24); done = testDecodeRect(decoder, 0, 0, 4, 2, data1, display, 24);
testDecodeRect(decoder, 0, 2, 4, 2, data2, 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([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 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, 0x62, 0x08, 0xc9, 0xc0, 0x00, 0x00, 0x00, 0x54,
0x00, 0x09 ]; 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([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 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 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); 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(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]);
display.fillRect(0, 2, 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([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 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 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); 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(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]);
display.fillRect(0, 2, 2, 2, [ 0x00, 0xff, 0x00 ]); display.fillRect(0, 2, 2, 2, [ 0x00, 0xff, 0x00 ]);
testDecodeRect(decoder, 1, 2, 0, 0, let done = testDecodeRect(decoder, 1, 2, 0, 0,
[ 0x40, 0x01, 0x01, [ 0x40, 0x01, 0x01,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff ], display, 24); 0xff, 0xff, 0xff ], display, 24);
let targetData = new Uint8Array([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 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 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); 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(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]);
display.fillRect(0, 2, 2, 2, [ 0x00, 0xff, 0x00 ]); display.fillRect(0, 2, 2, 2, [ 0x00, 0xff, 0x00 ]);
testDecodeRect(decoder, 1, 2, 0, 0, let done = testDecodeRect(decoder, 1, 2, 0, 0,
[ 0x80, 0xff, 0xff, 0xff ], display, 24); [ 0x80, 0xff, 0xff, 0xff ],
display, 24);
let targetData = new Uint8Array([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 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 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); expect(display).to.have.displayed(targetData);
}); });
@ -369,7 +393,8 @@ describe('Tight Decoder', function () {
0x3f, 0xeb, 0xff, 0x00, 0xff, 0xd9, 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([ let targetData = new Uint8Array([
0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,

View File

@ -9,23 +9,26 @@ import FakeWebSocket from './fake.websocket.js';
function testDecodeRect(decoder, x, y, width, height, data, display, depth) { function testDecodeRect(decoder, x, y, width, height, data, display, depth) {
let sock; let sock;
let done = false;
sock = new Websock; sock = new Websock;
sock.open("ws://example.com"); sock.open("ws://example.com");
sock.on('message', () => { 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 // Empty messages are filtered at multiple layers, so we need to
// do a direct call // do a direct call
if (data.length === 0) { if (data.length === 0) {
decoder.decodeRect(x, y, width, height, sock, display, depth); done = decoder.decodeRect(x, y, width, height, sock, display, depth);
} else { } else {
sock._websocket._receiveData(new Uint8Array(data)); sock._websocket._receiveData(new Uint8Array(data));
} }
display.flip(); display.flip();
return done;
} }
describe('TightPng Decoder', function () { describe('TightPng Decoder', function () {
@ -119,7 +122,8 @@ describe('TightPng Decoder', function () {
0xae, 0x42, 0x60, 0x82, 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([ let targetData = new Uint8Array([
0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,

View File

@ -9,23 +9,26 @@ import FakeWebSocket from './fake.websocket.js';
function testDecodeRect(decoder, x, y, width, height, data, display, depth) { function testDecodeRect(decoder, x, y, width, height, data, display, depth) {
let sock; let sock;
let done = false;
sock = new Websock; sock = new Websock;
sock.open("ws://example.com"); sock.open("ws://example.com");
sock.on('message', () => { 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 // Empty messages are filtered at multiple layers, so we need to
// do a direct call // do a direct call
if (data.length === 0) { if (data.length === 0) {
decoder.decodeRect(x, y, width, height, sock, display, depth); done = decoder.decodeRect(x, y, width, height, sock, display, depth);
} else { } else {
sock._websocket._receiveData(new Uint8Array(data)); sock._websocket._receiveData(new Uint8Array(data));
} }
display.flip(); display.flip();
return done;
} }
describe('ZRLE Decoder', function () { describe('ZRLE Decoder', function () {
@ -42,9 +45,11 @@ describe('ZRLE Decoder', function () {
}); });
it('should handle the Raw subencoding', function () { it('should handle the Raw subencoding', function () {
testDecodeRect(decoder, 0, 0, 4, 4, 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], [0x00, 0x00, 0x00, 0x0e, 0x78, 0x5e,
display, 24); 0x62, 0x60, 0x60, 0xf8, 0x4f, 0x12,
0x02, 0x00, 0x00, 0x00, 0xff, 0xff],
display, 24);
let targetData = new Uint8Array([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 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 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); expect(display).to.have.displayed(targetData);
}); });
it('should handle the Solid subencoding', function () { it('should handle the Solid subencoding', function () {
testDecodeRect(decoder, 0, 0, 4, 4, let done = testDecodeRect(decoder, 0, 0, 4, 4,
[0x00, 0x00, 0x00, 0x0c, 0x78, 0x5e, 0x62, 0x64, 0x60, 0xf8, 0x0f, 0x00, 0x00, 0x00, 0xff, 0xff], [0x00, 0x00, 0x00, 0x0c, 0x78, 0x5e,
display, 24); 0x62, 0x64, 0x60, 0xf8, 0x0f, 0x00,
0x00, 0x00, 0xff, 0xff],
display, 24);
let targetData = new Uint8Array([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 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 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); expect(display).to.have.displayed(targetData);
}); });
it('should handle the Palette Tile subencoding', function () { it('should handle the Palette Tile subencoding', function () {
testDecodeRect(decoder, 0, 0, 4, 4, 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], [0x00, 0x00, 0x00, 0x12, 0x78, 0x5E,
display, 24); 0x62, 0x62, 0x60, 248, 0xff, 0x9F,
0x01, 0x08, 0x3E, 0x7C, 0x00, 0x00,
0x00, 0x00, 0xff, 0xff],
display, 24);
let targetData = new Uint8Array([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 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 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); expect(display).to.have.displayed(targetData);
}); });
it('should handle the RLE Tile subencoding', function () { it('should handle the RLE Tile subencoding', function () {
testDecodeRect(decoder, 0, 0, 4, 4, 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], [0x00, 0x00, 0x00, 0x0d, 0x78, 0x5e,
display, 24); 0x6a, 0x60, 0x60, 0xf8, 0x2f, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff],
display, 24);
let targetData = new Uint8Array([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 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 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); expect(display).to.have.displayed(targetData);
}); });
it('should handle the RLE Palette Tile subencoding', function () { it('should handle the RLE Palette Tile subencoding', function () {
testDecodeRect(decoder, 0, 0, 4, 4, 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], [0x00, 0x00, 0x00, 0x11, 0x78, 0x5e,
display, 24); 0x6a, 0x62, 0x60, 0xf8, 0xff, 0x9f,
0x81, 0xa1, 0x81, 0x1f, 0x00, 0x00,
0x00, 0xff, 0xff],
display, 24);
let targetData = new Uint8Array([ let targetData = new Uint8Array([
0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 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 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); expect(display).to.have.displayed(targetData);
}); });