summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPaul Dumais <paul@itmanager.net>2021-10-05 12:04:34 -0400
committerPaul Dumais <paul@dumaison.com>2021-11-23 12:02:42 -0500
commitd4c887e23f13ea5c1da4de877ac2ddb406de3852 (patch)
tree5628818c66b38a18ce1ef558c8c959af5a29b6e0 /tests
parenta85c85fb5f34a47c0f79865252ef9dad8f257441 (diff)
downloadnovnc-d4c887e23f13ea5c1da4de877ac2ddb406de3852.tar.gz
Added support for ZRLE encoding
Fixed eslint warnings Improved memory usage of zrle decoding. Added unit tests for zrle decoding. Added support for ZRLE encoding Fixed eslint warnings Reverted allowIncomplete changes to Inflator Fixed failing tests for zrle decoder.
Diffstat (limited to 'tests')
-rw-r--r--tests/test.zrle.js124
1 files changed, 124 insertions, 0 deletions
diff --git a/tests/test.zrle.js b/tests/test.zrle.js
new file mode 100644
index 0000000..e09d208
--- /dev/null
+++ b/tests/test.zrle.js
@@ -0,0 +1,124 @@
+const expect = chai.expect;
+
+import Websock from '../core/websock.js';
+import Display from '../core/display.js';
+
+import ZRLEDecoder from '../core/decoders/zrle.js';
+
+import FakeWebSocket from './fake.websocket.js';
+
+function testDecodeRect(decoder, x, y, width, height, data, display, depth) {
+ let sock;
+
+ sock = new Websock;
+ sock.open("ws://example.com");
+
+ sock.on('message', () => {
+ 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);
+ } else {
+ sock._websocket._receiveData(new Uint8Array(data));
+ }
+
+ display.flip();
+}
+
+describe('ZRLE Decoder', function () {
+ let decoder;
+ let display;
+
+ before(FakeWebSocket.replace);
+ after(FakeWebSocket.restore);
+
+ beforeEach(function () {
+ decoder = new ZRLEDecoder();
+ display = new Display(document.createElement('canvas'));
+ display.resize(4, 4);
+ });
+
+ 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 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,
+ 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(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 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,
+ 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(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 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,
+ 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(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 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,
+ 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(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 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,
+ 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(display).to.have.displayed(targetData);
+ });
+
+ it('should fail on an invalid subencoding', function () {
+ let data = [0x00, 0x00, 0x00, 0x0c, 0x78, 0x5e, 0x6a, 0x64, 0x60, 0xf8, 0x0f, 0x00, 0x00, 0x00, 0xff, 0xff];
+ expect(() => testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24)).to.throw();
+ });
+});