aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Kliuchnikov <eustas.ru@gmail.com>2024-01-04 10:00:13 +0100
committerGitHub <noreply@github.com>2024-01-04 10:00:13 +0100
commit3bd5b9c0a200b53437d9229251b3da92ada8e812 (patch)
tree539e007cabe237597578a44c6f44ccb806367574
parent2b3334d559bb082c75425ecdbcdc0e236c0211e7 (diff)
parent082c9626a4717348b6d80cb1004ba9f29ebf2b3c (diff)
downloadbrotli-3bd5b9c0a200b53437d9229251b3da92ada8e812.zip
brotli-3bd5b9c0a200b53437d9229251b3da92ada8e812.tar.gz
brotli-3bd5b9c0a200b53437d9229251b3da92ada8e812.tar.bz2
Merge branch 'master' into dependabot/github_actions/actions/upload-artifact-4.0.0
-rw-r--r--java/org/brotli/wrapper/dec/CornerCasesTest.java46
1 files changed, 39 insertions, 7 deletions
diff --git a/java/org/brotli/wrapper/dec/CornerCasesTest.java b/java/org/brotli/wrapper/dec/CornerCasesTest.java
index ab02f23..796ed8d 100644
--- a/java/org/brotli/wrapper/dec/CornerCasesTest.java
+++ b/java/org/brotli/wrapper/dec/CornerCasesTest.java
@@ -6,11 +6,11 @@
package org.brotli.wrapper.dec;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertArrayEquals;
+import java.io.IOException;
import org.brotli.integration.BrotliJniTestBase;
import org.brotli.wrapper.enc.Encoder;
-import java.io.IOException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -18,16 +18,48 @@ import org.junit.runners.JUnit4;
/** Tests for {@link org.brotli.wrapper.enc.Encoder}. */
@RunWith(JUnit4.class)
public class CornerCasesTest extends BrotliJniTestBase {
+
+ private static byte[] makeInput(int len) {
+ byte[] dst = new byte[len];
+ for (int i = 0; i < len; ++i) {
+ dst[i] = (byte) Integer.bitCount(i);
+ }
+ return dst;
+ }
+
+ private static byte[] embedChunk(byte[] src, int offset, int padding) {
+ int len = src.length;
+ byte[] dst = new byte[offset + len + padding];
+ // TODO(eustas): fill with garbage?
+ System.arraycopy(src, 0, dst, offset, len);
+ return dst;
+ }
+
@Test
public void testPowerOfTwoInput() throws IOException {
// 24 == max window bits to ensure ring-buffer size is not greater than input.
int len = 1 << 24;
- byte[] data = new byte[len];
- for (int i = 0; i < len; ++i) {
- data[i] = (byte) Integer.bitCount(i);
- }
+ byte[] data = makeInput(len);
byte[] encoded = Encoder.compress(data);
byte[] decoded = Decoder.decompress(encoded);
- assertEquals(len, decoded.length);
+ assertArrayEquals(data, decoded);
+ }
+
+ @Test
+ public void testInputOffset() throws IOException {
+ int inputLength = 19;
+ int inputOffset = 4;
+ int inputPadding = 7;
+ byte[] data = makeInput(inputLength);
+ byte[] input = embedChunk(data, inputOffset, inputPadding);
+ byte[] encoded = Encoder.compress(input, inputOffset, inputLength);
+
+ int outputLength = encoded.length;
+ int outputOffset = 9;
+ int outputPadding = 5;
+ byte[] output = embedChunk(encoded, outputOffset, outputPadding);
+ byte[] decoded = Decoder.decompress(output, outputOffset, outputLength);
+
+ assertArrayEquals(data, decoded);
}
}