Improve Bazel/JNI portability (#611)

* Improve Bazel/JNI portability
* Update go and closure bazel addons
This commit is contained in:
Eugene Kliuchnikov 2017-10-09 17:07:34 +02:00 committed by GitHub
parent 4f8cd4c0f4
commit 42d78807bb
18 changed files with 170 additions and 153 deletions

28
BUILD
View File

@ -147,46 +147,42 @@ cc_binary(
########################################################
# WARNING: do not (transitively) depend on this target!
########################################################
cc_library(
name = "jni",
cc_binary(
name = "brotli_jni.dll",
srcs = [
":common_headers",
":common_sources",
":dec_headers",
":dec_sources",
":enc_headers",
":enc_sources",
"//java/org/brotli/wrapper/common:jni_src",
"//java/org/brotli/wrapper/dec:jni_src",
"//java/org/brotli/wrapper/enc:jni_src",
],
hdrs = [
":common_headers",
":dec_headers",
":enc_headers",
],
deps = [
":brotli_inc",
":jni_inc",
],
alwayslink = 1,
linkshared = 1,
)
########################################################
# WARNING: do not (transitively) depend on this target!
########################################################
cc_library(
name = "jni_no_dictionary_data",
cc_binary(
name = "brotli_jni_no_dictionary_data.dll",
srcs = [
":common_headers",
":common_sources",
":dec_headers",
":dec_sources",
":enc_headers",
":enc_sources",
"//java/org/brotli/wrapper/common:jni_src",
"//java/org/brotli/wrapper/dec:jni_src",
"//java/org/brotli/wrapper/enc:jni_src",
],
hdrs = [
":common_headers",
":dec_headers",
":enc_headers",
],
defines = [
"BROTLI_EXTERNAL_DICTIONARY_DATA=",
],
@ -194,7 +190,7 @@ cc_library(
":brotli_inc",
":jni_inc",
],
alwayslink = 1,
linkshared = 1,
)
filegroup(

View File

@ -11,14 +11,17 @@ maven_jar(
git_repository(
name = "io_bazel_rules_go",
remote = "https://github.com/bazelbuild/rules_go.git",
tag = "0.4.4",
tag = "0.5.5",
)
http_archive(
name = "io_bazel_rules_closure",
strip_prefix = "rules_closure-0.4.1",
sha256 = "ba5e2e10cdc4027702f96e9bdc536c6595decafa94847d08ae28c6cb48225124",
url = "http://mirror.bazel.build/github.com/bazelbuild/rules_closure/archive/0.4.1.tar.gz",
strip_prefix = "rules_closure-0.4.2",
sha256 = "25f5399f18d8bf9ce435f85c6bbf671ec4820bc4396b3022cc5dc4bc66303609",
urls = [
"http://mirror.bazel.build/github.com/bazelbuild/rules_closure/archive/0.4.2.tar.gz",
"https://github.com/bazelbuild/rules_closure/archive/0.4.2.tar.gz",
],
)
new_http_archive(

View File

@ -1,6 +1,16 @@
# Description:
# Integration test runner + corpus for Java port of Brotli decoder.
java_library(
name = "brotli_jni_test_base",
srcs = ["BrotliJniTestBase.java"],
visibility = [
"//java/org/brotli/wrapper/common:__pkg__",
"//java/org/brotli/wrapper/dec:__pkg__",
"//java/org/brotli/wrapper/enc:__pkg__",
],
)
java_library(
name = "bundle_helper",
srcs = ["BundleHelper.java"],

View File

@ -0,0 +1,13 @@
package org.brotli.integration;
/**
* Optionally loads brotli JNI wrapper native library.
*/
public class BrotliJniTestBase {
static {
String jniLibrary = System.getProperty("BROTLI_JNI_LIBRARY");
if (jniLibrary != null) {
System.load(new java.io.File(jniLibrary).getAbsolutePath());
}
}
}

View File

@ -7,37 +7,32 @@ filegroup(
srcs = ["common_jni.cc"],
)
#########################################
# WARNING: do not depend on this target!
#########################################
java_library(
name = "common_no_dictionary_data",
srcs = glob(
["*.java"],
exclude = ["*Test*.java"],
),
deps = ["//:jni_no_dictionary_data"],
filegroup(
name = "brotli_jni_no_dictionary_data",
srcs = ["//:brotli_jni_no_dictionary_data.dll"],
)
#########################################
# WARNING: do not depend on this target!
#########################################
java_library(
name = "common",
srcs = glob(
["*.java"],
exclude = ["*Test*.java"],
),
deps = ["//:jni"],
)
java_test(
name = "SetZeroDictionaryTest",
size = "small",
srcs = ["SetZeroDictionaryTest.java"],
data = ["//:jni_no_dictionary_data"], # Bazel JNI workaround
data = [
":brotli_jni_no_dictionary_data", # Bazel JNI workaround
],
jvm_flags = [
"-DBROTLI_JNI_LIBRARY=$(location :brotli_jni_no_dictionary_data)",
],
deps = [
":common_no_dictionary_data",
":common",
"//java/org/brotli/integration:brotli_jni_test_base",
"//java/org/brotli/wrapper/dec",
"@junit_junit//jar",
],
@ -54,11 +49,15 @@ java_test(
srcs = ["SetRfcDictionaryTest.java"],
data = [
":rfc_dictionary",
"//:jni_no_dictionary_data", # Bazel JNI workaround
":brotli_jni_no_dictionary_data", # Bazel JNI workaround
],
jvm_flags = [
"-DRFC_DICTIONARY=$(location :rfc_dictionary)",
"-DBROTLI_JNI_LIBRARY=$(location :brotli_jni_no_dictionary_data)",
],
jvm_flags = ["-DRFC_DICTIONARY=$(location :rfc_dictionary)"],
deps = [
":common_no_dictionary_data",
":common",
"//java/org/brotli/integration:brotli_jni_test_base",
"//java/org/brotli/wrapper/dec",
"@junit_junit//jar",
],

View File

@ -11,6 +11,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.brotli.integration.BrotliJniTestBase;
import org.brotli.wrapper.dec.BrotliInputStream;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
@ -25,13 +26,7 @@ import org.junit.runners.JUnit4;
* Tests for {@link BrotliCommon}.
*/
@RunWith(JUnit4.class)
public class SetRfcDictionaryTest {
// TODO: remove when Bazel get JNI support.
static {
System.load(new java.io.File(new java.io.File(System.getProperty("java.library.path")),
"liblibjni_Uno_Udictionary_Udata.so").getAbsolutePath());
}
public class SetRfcDictionaryTest extends BrotliJniTestBase {
@Test
public void testRfcDictionaryChecksums() throws IOException, NoSuchAlgorithmException {

View File

@ -9,6 +9,7 @@ package org.brotli.wrapper.common;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import org.brotli.integration.BrotliJniTestBase;
import org.brotli.wrapper.dec.BrotliInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@ -20,13 +21,7 @@ import org.junit.runners.JUnit4;
* Tests for {@link BrotliCommon}.
*/
@RunWith(JUnit4.class)
public class SetZeroDictionaryTest {
// TODO: remove when Bazel get JNI support.
static {
System.load(new java.io.File(new java.io.File(System.getProperty("java.library.path")),
"liblibjni_Uno_Udictionary_Udata.so").getAbsolutePath());
}
public class SetZeroDictionaryTest extends BrotliJniTestBase {
@Test
public void testZeroDictionary() throws IOException {

View File

@ -7,16 +7,17 @@ filegroup(
srcs = ["decoder_jni.cc"],
)
#########################################
# WARNING: do not depend on this target!
#########################################
java_library(
name = "dec",
srcs = glob(
["*.java"],
exclude = ["*Test*.java"],
),
deps = ["//:jni"],
)
filegroup(
name = "brotli_jni",
srcs = ["//:brotli_jni.dll"],
)
filegroup(
@ -29,12 +30,16 @@ java_test(
size = "large",
srcs = ["BrotliDecoderChannelTest.java"],
data = [
":brotli_jni", # Bazel JNI workaround
":test_bundle",
"//:jni", # Bazel JNI workaround
],
jvm_flags = ["-DTEST_BUNDLE=$(location :test_bundle)"],
jvm_flags = [
"-DBROTLI_JNI_LIBRARY=$(location :brotli_jni)",
"-DTEST_BUNDLE=$(location :test_bundle)",
],
deps = [
":dec",
"//java/org/brotli/integration:brotli_jni_test_base",
"//java/org/brotli/integration:bundle_helper",
"@junit_junit//jar",
],
@ -45,12 +50,16 @@ java_test(
size = "large",
srcs = ["BrotliInputStreamTest.java"],
data = [
":brotli_jni", # Bazel JNI workaround
":test_bundle",
"//:jni", # Bazel JNI workaround
],
jvm_flags = ["-DTEST_BUNDLE=$(location :test_bundle)"],
jvm_flags = [
"-DBROTLI_JNI_LIBRARY=$(location :brotli_jni)",
"-DTEST_BUNDLE=$(location :test_bundle)",
],
deps = [
":dec",
"//java/org/brotli/integration:brotli_jni_test_base",
"//java/org/brotli/integration:bundle_helper",
"@junit_junit//jar",
],
@ -61,12 +70,16 @@ java_test(
size = "large",
srcs = ["DecoderTest.java"],
data = [
":brotli_jni", # Bazel JNI workaround
":test_bundle",
"//:jni", # Bazel JNI workaround
],
jvm_flags = ["-DTEST_BUNDLE=$(location :test_bundle)"],
jvm_flags = [
"-DBROTLI_JNI_LIBRARY=$(location :brotli_jni)",
"-DTEST_BUNDLE=$(location :test_bundle)",
],
deps = [
":dec",
"//java/org/brotli/integration:brotli_jni_test_base",
"//java/org/brotli/integration:bundle_helper",
"@junit_junit//jar",
],

View File

@ -8,6 +8,7 @@ package org.brotli.wrapper.dec;
import static org.junit.Assert.assertEquals;
import org.brotli.integration.BrotliJniTestBase;
import org.brotli.integration.BundleHelper;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
@ -23,13 +24,7 @@ import org.junit.runners.AllTests;
/** Tests for {@link org.brotli.wrapper.dec.BrotliDecoderChannel}. */
@RunWith(AllTests.class)
public class BrotliDecoderChannelTest {
// TODO: remove when Bazel get JNI support.
static {
System.load(new java.io.File(new java.io.File(System.getProperty("java.library.path")),
"liblibjni.so").getAbsolutePath());
}
public class BrotliDecoderChannelTest extends BrotliJniTestBase {
static InputStream getBundle() throws IOException {
return new FileInputStream(System.getProperty("TEST_BUNDLE"));

View File

@ -8,6 +8,7 @@ package org.brotli.wrapper.dec;
import static org.junit.Assert.assertEquals;
import org.brotli.integration.BrotliJniTestBase;
import org.brotli.integration.BundleHelper;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
@ -21,13 +22,7 @@ import org.junit.runners.AllTests;
/** Tests for {@link org.brotli.wrapper.dec.BrotliInputStream}. */
@RunWith(AllTests.class)
public class BrotliInputStreamTest {
// TODO: remove when Bazel get JNI support.
static {
System.load(new java.io.File(new java.io.File(System.getProperty("java.library.path")),
"liblibjni.so").getAbsolutePath());
}
public class BrotliInputStreamTest extends BrotliJniTestBase {
static InputStream getBundle() throws IOException {
return new FileInputStream(System.getProperty("TEST_BUNDLE"));

View File

@ -8,6 +8,7 @@ package org.brotli.wrapper.dec;
import static org.junit.Assert.assertEquals;
import org.brotli.integration.BrotliJniTestBase;
import org.brotli.integration.BundleHelper;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
@ -21,13 +22,7 @@ import org.junit.runners.AllTests;
/** Tests for {@link org.brotli.wrapper.dec.Decoder}. */
@RunWith(AllTests.class)
public class DecoderTest {
// TODO: remove when Bazel get JNI support.
static {
System.load(new java.io.File(new java.io.File(System.getProperty("java.library.path")),
"liblibjni.so").getAbsolutePath());
}
public class DecoderTest extends BrotliJniTestBase {
static InputStream getBundle() throws IOException {
return new FileInputStream(System.getProperty("TEST_BUNDLE"));

View File

@ -7,16 +7,17 @@ filegroup(
srcs = ["encoder_jni.cc"],
)
#########################################
# WARNING: do not depend on this target!
#########################################
filegroup(
name = "brotli_jni",
srcs = ["//:brotli_jni.dll"],
)
java_library(
name = "enc",
srcs = glob(
["*.java"],
exclude = ["*Test*.java"],
),
deps = ["//:jni"],
)
filegroup(
@ -29,13 +30,17 @@ java_test(
size = "large",
srcs = ["BrotliEncoderChannelTest.java"],
data = [
":brotli_jni", # Bazel JNI workaround
":test_bundle",
"//:jni", # Bazel JNI workaround
],
jvm_flags = ["-DTEST_BUNDLE=$(location :test_bundle)"],
jvm_flags = [
"-DBROTLI_JNI_LIBRARY=$(location :brotli_jni)",
"-DTEST_BUNDLE=$(location :test_bundle)",
],
shard_count = 15,
deps = [
":enc",
"//java/org/brotli/integration:brotli_jni_test_base",
"//java/org/brotli/integration:bundle_helper",
"//java/org/brotli/wrapper/dec",
"@junit_junit//jar",
@ -47,13 +52,17 @@ java_test(
size = "large",
srcs = ["BrotliOutputStreamTest.java"],
data = [
":brotli_jni", # Bazel JNI workaround
":test_bundle",
"//:jni", # Bazel JNI workaround
],
jvm_flags = ["-DTEST_BUNDLE=$(location :test_bundle)"],
jvm_flags = [
"-DBROTLI_JNI_LIBRARY=$(location :brotli_jni)",
"-DTEST_BUNDLE=$(location :test_bundle)",
],
shard_count = 15,
deps = [
":enc",
"//java/org/brotli/integration:brotli_jni_test_base",
"//java/org/brotli/integration:bundle_helper",
"//java/org/brotli/wrapper/dec",
"@junit_junit//jar",
@ -65,13 +74,17 @@ java_test(
size = "large",
srcs = ["EncoderTest.java"],
data = [
":brotli_jni", # Bazel JNI workaround
":test_bundle",
"//:jni", # Bazel JNI workaround
],
jvm_flags = ["-DTEST_BUNDLE=$(location :test_bundle)"],
jvm_flags = [
"-DBROTLI_JNI_LIBRARY=$(location :brotli_jni)",
"-DTEST_BUNDLE=$(location :test_bundle)",
],
shard_count = 15,
deps = [
":enc",
"//java/org/brotli/integration:brotli_jni_test_base",
"//java/org/brotli/integration:bundle_helper",
"//java/org/brotli/wrapper/dec",
"@junit_junit//jar",

View File

@ -2,6 +2,7 @@ package org.brotli.wrapper.enc;
import static org.junit.Assert.assertEquals;
import org.brotli.integration.BrotliJniTestBase;
import org.brotli.integration.BundleHelper;
import org.brotli.wrapper.dec.BrotliInputStream;
import java.io.ByteArrayInputStream;
@ -20,19 +21,13 @@ import org.junit.runners.AllTests;
/** Tests for {@link org.brotli.wrapper.enc.BrotliEncoderChannel}. */
@RunWith(AllTests.class)
public class BrotliEncoderChannelTest {
public class BrotliEncoderChannelTest extends BrotliJniTestBase {
private enum TestMode {
WRITE_ALL,
WRITE_CHUNKS
}
// TODO: remove when Bazel get JNI support.
static {
System.load(new java.io.File(new java.io.File(System.getProperty("java.library.path")),
"liblibjni.so").getAbsolutePath());
}
private static final int CHUNK_SIZE = 256;
static InputStream getBundle() throws IOException {

View File

@ -2,6 +2,7 @@ package org.brotli.wrapper.enc;
import static org.junit.Assert.assertEquals;
import org.brotli.integration.BrotliJniTestBase;
import org.brotli.integration.BundleHelper;
import org.brotli.wrapper.dec.BrotliInputStream;
import java.io.ByteArrayInputStream;
@ -18,7 +19,7 @@ import org.junit.runners.AllTests;
/** Tests for {@link org.brotli.wrapper.enc.BrotliOutputStream}. */
@RunWith(AllTests.class)
public class BrotliOutputStreamTest {
public class BrotliOutputStreamTest extends BrotliJniTestBase {
private enum TestMode {
WRITE_ALL,
@ -26,12 +27,6 @@ public class BrotliOutputStreamTest {
WRITE_BYTE
}
// TODO: remove when Bazel get JNI support.
static {
System.load(new java.io.File(new java.io.File(System.getProperty("java.library.path")),
"liblibjni.so").getAbsolutePath());
}
private static final int CHUNK_SIZE = 256;
static InputStream getBundle() throws IOException {

View File

@ -2,6 +2,7 @@ package org.brotli.wrapper.enc;
import static org.junit.Assert.assertEquals;
import org.brotli.integration.BrotliJniTestBase;
import org.brotli.integration.BundleHelper;
import org.brotli.wrapper.dec.BrotliInputStream;
import java.io.ByteArrayInputStream;
@ -16,14 +17,7 @@ import org.junit.runners.AllTests;
/** Tests for {@link org.brotli.wrapper.enc.Encoder}. */
@RunWith(AllTests.class)
public class EncoderTest {
// TODO: remove when Bazel get JNI support.
static {
System.load(new java.io.File(new java.io.File(System.getProperty("java.library.path")),
"liblibjni.so").getAbsolutePath());
}
public class EncoderTest extends BrotliJniTestBase {
static InputStream getBundle() throws IOException {
return new FileInputStream(System.getProperty("TEST_BUNDLE"));
}

View File

@ -10,16 +10,21 @@ load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library")
closure_js_library(
name = "polyfill",
srcs = ["polyfill.js"],
language = "ECMASCRIPT6_STRICT",
suppress = ["JSC_MISSING_JSDOC"],
suppress = [
"JSC_MISSING_JSDOC",
"JSC_TYPE_MISMATCH",
"JSC_UNKNOWN_EXPR_TYPE",
],
)
# Do NOT use this artifact; it is for test purposes only.
closure_js_library(
name = "decode",
srcs = ["decode.js"],
language = "ECMASCRIPT6_STRICT",
suppress = ["JSC_USELESS_BLOCK"],
suppress = [
"JSC_DUP_VAR_DECLARATION",
"JSC_USELESS_BLOCK",
],
deps = [":polyfill"],
)
@ -28,7 +33,6 @@ load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_test")
closure_js_test(
name = "all_tests",
srcs = ["decode_test.js"],
language = "ECMASCRIPT6_STRICT",
deps = [
":decode",
":polyfill",

View File

@ -4,8 +4,8 @@
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
/** @export */
var BrotliDecode = (function() {
/** @return {function(!Int8Array):!Int8Array} */
function BrotliDecodeClosure() {
"use strict";
/** @type {!Int8Array} */
@ -61,7 +61,7 @@ var BrotliDecode = (function() {
/**
* @param {!State} s
* @param {!InputStream} input
* @return {!void}
* @return {void}
*/
function initState(s, input) {
if (s.runningState != 0) {
@ -80,7 +80,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
* @return {!void}
* @return {void}
*/
function close(s) {
if (s.runningState == 0) {
@ -116,7 +116,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
* @return {!void}
* @return {void}
*/
function decodeMetaBlockLength(s) {
if (s.bitOffset >= 16) {
@ -226,7 +226,7 @@ var BrotliDecode = (function() {
/**
* @param {!Int32Array} v
* @param {!number} index
* @return {!void}
* @return {void}
*/
function moveToFront(v, index) {
var /** !number */ value = v[index];
@ -238,7 +238,7 @@ var BrotliDecode = (function() {
/**
* @param {!Int8Array} v
* @param {!number} vLen
* @return {!void}
* @return {void}
*/
function inverseMoveToFrontTransform(v, vLen) {
var /** !Int32Array */ mtf = new Int32Array(256);
@ -258,7 +258,7 @@ var BrotliDecode = (function() {
* @param {!number} numSymbols
* @param {!Int32Array} codeLengths
* @param {!State} s
* @return {!void}
* @return {void}
*/
function readHuffmanCodeLengths(codeLengthCodeLengths, numSymbols, codeLengths, s) {
var /** !number */ symbol = 0;
@ -343,7 +343,7 @@ var BrotliDecode = (function() {
* @param {!Int32Array} table
* @param {!number} offset
* @param {!State} s
* @return {!void}
* @return {void}
*/
function readHuffmanCode(alphabetSize, table, offset, s) {
var /** !number */ ok = 1;
@ -517,7 +517,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
* @return {!void}
* @return {void}
*/
function decodeLiteralBlockSwitch(s) {
s.literalBlockLength = decodeBlockTypeAndLength(s, 0, s.numLiteralBlockTypes);
@ -531,7 +531,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
* @return {!void}
* @return {void}
*/
function decodeCommandBlockSwitch(s) {
s.commandBlockLength = decodeBlockTypeAndLength(s, 1, s.numCommandBlockTypes);
@ -539,7 +539,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
* @return {!void}
* @return {void}
*/
function decodeDistanceBlockSwitch(s) {
s.distanceBlockLength = decodeBlockTypeAndLength(s, 2, s.numDistanceBlockTypes);
@ -547,7 +547,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
* @return {!void}
* @return {void}
*/
function maybeReallocateRingBuffer(s) {
var /** !number */ newSize = s.maxRingBufferSize;
@ -573,7 +573,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
* @return {!void}
* @return {void}
*/
function readNextMetablockHeader(s) {
if (s.inputEnd != 0) {
@ -626,7 +626,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
* @return {!void}
* @return {void}
*/
function readMetablockHuffmanCodesAndContextMaps(s) {
s.numLiteralBlockTypes = decodeVarLenUnsignedByte(s) + 1;
@ -690,7 +690,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
* @return {!void}
* @return {void}
*/
function copyUncompressedData(s) {
var /** !Int8Array */ ringBuffer = s.ringBuffer;
@ -748,7 +748,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
* @return {!void}
* @return {void}
*/
function decompress(s) {
if (s.runningState == 0) {
@ -1044,7 +1044,7 @@ var BrotliDecode = (function() {
* @param {!Int32Array} transforms
* @param {!string} prefixSuffixSrc
* @param {!string} transformsSrc
* @return {!void}
* @return {void}
*/
function unpackTransforms(prefixSuffix, prefixSuffixHeads, transforms, prefixSuffixSrc, transformsSrc) {
var /** !number */ n = prefixSuffixSrc.length;
@ -1142,7 +1142,7 @@ var BrotliDecode = (function() {
* @param {!number} step
* @param {!number} end
* @param {!number} item
* @return {!void}
* @return {void}
*/
function replicateValue(table, offset, step, end, item) {
do {
@ -1174,7 +1174,7 @@ var BrotliDecode = (function() {
* @param {!number} rootBits
* @param {!Int32Array} codeLengths
* @param {!number} codeLengthsSize
* @return {!void}
* @return {void}
*/
function buildHuffmanTable(rootTable, tableOffset, rootBits, codeLengths, codeLengthsSize) {
var /** !number */ key;
@ -1232,7 +1232,7 @@ var BrotliDecode = (function() {
/**
* @param {!State} s
* @return {!void}
* @return {void}
*/
function doReadMoreInput(s) {
if (s.endOfStreamReached != 0) {
@ -1261,7 +1261,7 @@ var BrotliDecode = (function() {
/**
* @param {!State} s
* @param {!number} endOfStream
* @return {!void}
* @return {void}
*/
function checkHealth(s, endOfStream) {
if (s.endOfStreamReached == 0) {
@ -1298,7 +1298,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
* @return {!void}
* @return {void}
*/
function initBitReader(s) {
s.byteBuffer = new Int8Array(4160);
@ -1311,7 +1311,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
* @return {!void}
* @return {void}
*/
function prepare(s) {
if (s.halfOffset > 2030) {
@ -1325,7 +1325,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
* @return {!void}
* @return {void}
*/
function reload(s) {
if (s.bitOffset == 32) {
@ -1334,7 +1334,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
* @return {!void}
* @return {void}
*/
function jumpToByteBoundary(s) {
var /** !number */ padding = (32 - s.bitOffset) & 7;
@ -1361,7 +1361,7 @@ var BrotliDecode = (function() {
* @param {!Int8Array} data
* @param {!number} offset
* @param {!number} length
* @return {!void}
* @return {void}
*/
function copyBytes(s, data, offset, length) {
if ((s.bitOffset & 7) != 0) {
@ -1412,7 +1412,7 @@ var BrotliDecode = (function() {
/**
* @param {!State} s
* @param {!number} byteLen
* @return {!void}
* @return {void}
*/
function bytesToNibbles(s, byteLen) {
var /** !Int8Array */ byteBuffer = s.byteBuffer;
@ -1428,7 +1428,7 @@ var BrotliDecode = (function() {
* @param {!Int32Array} lookup
* @param {!string} map
* @param {!string} rle
* @return {!void}
* @return {void}
*/
function unpackLookupTable(lookup, map, rle) {
for (var /** !number */ i = 0; i < 256; ++i) {
@ -1603,7 +1603,7 @@ var BrotliDecode = (function() {
* @param {!string} data0
* @param {!string} data1
* @param {!string} skipFlip
* @return {!void}
* @return {void}
*/
function unpackDictionaryData(dictionary, data0, data1, skipFlip) {
var /** !number */ n0 = data0.length;
@ -1708,6 +1708,9 @@ var BrotliDecode = (function() {
}
return decode;
})();
}
/** @export */
var BrotliDecode = BrotliDecodeClosure();
window["BrotliDecode"] = BrotliDecode;

View File

@ -2,7 +2,7 @@ goog.require('goog.testing.asserts');
goog.require('goog.testing.jsunit');
/**
* @param {string} bytes
* @param {!Int8Array} bytes
* @return {string}
*/
function bytesToString(bytes) {
@ -20,6 +20,7 @@ function testBaseDictWord() {
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));
}
@ -30,6 +31,7 @@ function testBlockCountMessage() {
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));
}
@ -42,6 +44,7 @@ function testCompressedUncompressedShortCompressedSmallWindow() {
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" +
@ -67,6 +70,7 @@ function testIntactDistanceRingBuffer0() {
0x07, 0x5b, 0x26, 0x31, 0x40, 0x02, 0x00, 0xe0, 0x4e, 0x1b, 0xa1, 0x80,
0x20, 0x00
]);
/** @type {!Int8Array} */
var output = BrotliDecode(input);
assertEquals("himselfself", bytesToString(output));
}