@Test public void testDeflateAndInflate_OutputIsMultiple() throws Exception { byte[] data = new byte[512]; CodecBuffer deflaterInput = Buffers.wrap(data, 0, data.length); DeflaterEncoder encoder = new DeflaterEncoder(); encoder.stored(context_, deflaterInput, null); CodecBuffer inflaterInput = context_.pollEvent(); if (context_.pollEvent() != null) { Assert.fail(); } InflaterDecoder decoder = new InflaterDecoder(); decoder.loaded(context_, inflaterInput, null); assertProcessedData(data); assertThat(((ArrayCodecBuffer) deflaterInput).referenceCount(), is(0)); assertThat(((ArrayCodecBuffer) inflaterInput).referenceCount(), is(0)); }
@Test public void testDeflateAndInflate_DeflaterBufferIsSmall() throws Exception { byte[] data = new byte[512]; Arrays.fill(data, (byte) '0'); CodecBuffer deflaterInput = Buffers.wrap(data, 0, data.length); DeflaterEncoder encoder = new DeflaterEncoder(Deflater.BEST_SPEED, 8, null, false); encoder.stored(context_, deflaterInput, null); CodecBuffer inflaterInput = context_.pollEvent(); if (context_.pollEvent() != null) { Assert.fail(); } InflaterDecoder decoder = new InflaterDecoder(); decoder.loaded(context_, inflaterInput, null); assertProcessedData(data); assertThat(((ArrayCodecBuffer) deflaterInput).referenceCount(), is(0)); assertThat(((ArrayCodecBuffer) inflaterInput).referenceCount(), is(0)); }
@Test public void testDeflateAndInflate_Simple() throws Exception { byte[] data = "0123456789012345678901234567890123456789012345678901234567890123456789".getBytes("UTF-8"); CodecBuffer deflaterInput = Buffers.wrap(data, 0, data.length); DeflaterEncoder encoder = new DeflaterEncoder(); encoder.stored(context_, deflaterInput, null); CodecBuffer inflaterInput = context_.pollEvent(); if (context_.pollEvent() != null) { Assert.fail(); } InflaterDecoder decoder = new InflaterDecoder(); decoder.loaded(context_, inflaterInput, null); CodecBuffer inflated = context_.pollEvent(); assertThat(inflated.remaining(), is(data.length)); assertThat(decoder.output(), is(nullValue())); assertThat(((ArrayCodecBuffer) deflaterInput).referenceCount(), is(0)); assertThat(((ArrayCodecBuffer) inflaterInput).referenceCount(), is(0)); }