1 /* Copyright 2015 Google Inc. All Rights Reserved. 2 3 Distributed under MIT license. 4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT 5 */ 6 7 package org.brotli.wrapper.common; 8 9 import static org.junit.Assert.assertArrayEquals; 10 import static org.junit.Assert.assertEquals; 11 12 import org.brotli.integration.BrotliJniTestBase; 13 import org.brotli.wrapper.dec.BrotliInputStream; 14 import java.io.ByteArrayInputStream; 15 import java.io.IOException; 16 import org.junit.Test; 17 import org.junit.runner.RunWith; 18 import org.junit.runners.JUnit4; 19 20 /** 21 * Tests for {@link BrotliCommon}. 22 */ 23 @RunWith(JUnit4.class) 24 public class SetZeroDictionaryTest extends BrotliJniTestBase { 25 26 @Test testZeroDictionary()27 public void testZeroDictionary() throws IOException { 28 /* "leftdatadataleft" encoded with dictionary words. */ 29 byte[] data = {27, 15, 0, 0, 0, 0, -128, -29, -76, 13, 0, 0, 7, 91, 38, 49, 64, 2, 0, -32, 78, 30 27, 65, -128, 32, 80, 16, 36, 8, 6}; 31 byte[] dictionary = new byte[BrotliCommon.RFC_DICTIONARY_SIZE]; 32 BrotliCommon.setDictionaryData(dictionary); 33 34 BrotliInputStream decoder = new BrotliInputStream(new ByteArrayInputStream(data)); 35 byte[] output = new byte[17]; 36 int offset = 0; 37 try { 38 int bytesRead; 39 while ((bytesRead = decoder.read(output, offset, 17 - offset)) != -1) { 40 offset += bytesRead; 41 } 42 } finally { 43 decoder.close(); 44 } 45 assertEquals(16, offset); 46 assertArrayEquals(new byte[17], output); 47 } 48 } 49