diff options
author | Eugene Kliuchnikov <eustas.ru@gmail.com> | 2021-06-23 09:40:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-23 09:40:57 +0200 |
commit | f8c671774514357abec2f6b14c8ee13c6fd885d3 (patch) | |
tree | fa1605f92feea7b851389d805b5bd8c1f010b636 /js/decode_test.js | |
parent | bbe5d72ba37b164c4e8e0d7baeb78a22aa849c38 (diff) | |
download | brotli-f8c671774514357abec2f6b14c8ee13c6fd885d3.zip brotli-f8c671774514357abec2f6b14c8ee13c6fd885d3.tar.gz brotli-f8c671774514357abec2f6b14c8ee13c6fd885d3.tar.bz2 |
Update (#908)
* re-enable Js build/test
* improve decoder performance
* rewrite dictionary data in Java/Js to a shorter uncompressed form
* improve dictionary generation tool
Diffstat (limited to 'js/decode_test.js')
-rw-r--r-- | js/decode_test.js | 98 |
1 files changed, 21 insertions, 77 deletions
diff --git a/js/decode_test.js b/js/decode_test.js index df2815f..cd1cbcf 100644 --- a/js/decode_test.js +++ b/js/decode_test.js @@ -1,5 +1,11 @@ +/* Copyright 2017 Google Inc. All Rights Reserved. + + Distributed under MIT license. + See file LICENSE for detail or copy at https://opensource.org/licenses/MIT +*/ +import {BrotliDecode} from "./decode.js"; +const testSuite = goog.require('goog.testing.testSuite'); goog.require('goog.testing.asserts'); -goog.require('goog.testing.jsunit'); /** * @param {!Int8Array} bytes @@ -19,79 +25,17 @@ function stringToBytes(str) { return out; } -function testMetadata() { - assertEquals("", bytesToString(BrotliDecode(Int8Array.from([1, 11, 0, 42, 3])))); -} - -function testEmpty() { - assertEquals("", bytesToString(BrotliDecode(Int8Array.from([6])))); - assertEquals("", bytesToString(BrotliDecode(Int8Array.from([0x81, 1])))); -} - -function testBaseDictWord() { - var input = Int8Array.from([ - 0x1b, 0x03, 0x00, 0x00, 0x00, 0x00, 0x80, 0xe3, 0xb4, 0x0d, 0x00, 0x00, - 0x07, 0x5b, 0x26, 0x31, 0x40, 0x02, 0x00, 0xe0, 0x4e, 0x1b, 0x41, 0x02 - ]); - /** @type {!Int8Array} */ - var output = BrotliDecode(input); - assertEquals("time", bytesToString(output)); -} - -function testBlockCountMessage() { - var input = Int8Array.from([ - 0x1b, 0x0b, 0x00, 0x11, 0x01, 0x8c, 0xc1, 0xc5, 0x0d, 0x08, 0x00, 0x22, - 0x65, 0xe1, 0xfc, 0xfd, 0x22, 0x2c, 0xc4, 0x00, 0x00, 0x38, 0xd8, 0x32, - 0x89, 0x01, 0x12, 0x00, 0x00, 0x77, 0xda, 0x04, 0x10, 0x42, 0x00, 0x00, 0x00 - ]); - /** @type {!Int8Array} */ - var output = BrotliDecode(input); - assertEquals("aabbaaaaabab", bytesToString(output)); -} - -function testCompressedUncompressedShortCompressedSmallWindow() { - var input = Int8Array.from([ - 0x21, 0xf4, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x1c, 0xa7, 0x6d, 0x00, 0x00, - 0x38, 0xd8, 0x32, 0x89, 0x01, 0x12, 0x00, 0x00, 0x77, 0xda, 0x34, 0x7b, - 0xdb, 0x50, 0x80, 0x02, 0x80, 0x62, 0x62, 0x62, 0x62, 0x62, 0x62, 0x31, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x4e, 0xdb, 0x00, 0x00, 0x70, 0xb0, - 0x65, 0x12, 0x03, 0x24, 0x00, 0x00, 0xee, 0xb4, 0x11, 0x24, 0x00 - ]); - /** @type {!Int8Array} */ - var output = BrotliDecode(input); - assertEquals( - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaabbbbbbbbbb", bytesToString(output)); -} - -function testIntactDistanceRingBuffer0() { - var input = Int8Array.from([ - 0x1b, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x80, 0xe3, 0xb4, 0x0d, 0x00, 0x00, - 0x07, 0x5b, 0x26, 0x31, 0x40, 0x02, 0x00, 0xe0, 0x4e, 0x1b, 0xa1, 0x80, - 0x20, 0x00 - ]); - /** @type {!Int8Array} */ - var output = BrotliDecode(input); - assertEquals("himselfself", bytesToString(output)); -} - -function testCompoundDictionary() { - var txt = "kot lomom kolol slona\n"; - var dictionary = stringToBytes(txt); - var compressed = [0xa1, 0xa8, 0x00, 0xc0, 0x2f, 0x01, 0x10, 0xc4, 0x44, 0x09, 0x00]; - assertEquals(txt.length, compressed.length * 2); - assertEquals(txt, bytesToString(BrotliDecode(Int8Array.from(compressed), {customDictionary: dictionary}))); -} +testSuite({ + testMetadata() { + assertEquals("", bytesToString(BrotliDecode(Int8Array.from([1, 11, 0, 42, 3])))); + }, + + testCompoundDictionary() { + var txt = "kot lomom kolol slona\n"; + var dictionary = stringToBytes(txt); + var compressed = [0xa1, 0xa8, 0x00, 0xc0, 0x2f, 0x01, 0x10, 0xc4, 0x44, 0x09, 0x00]; + assertEquals(txt.length, compressed.length * 2); + var options = {"customDictionary": dictionary}; + assertEquals(txt, bytesToString(BrotliDecode(Int8Array.from(compressed), options))); + } +}); |