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:
+19
-9
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user