protected int doCompressionTest(final IRecordCompressor c,final byte[] expected,final int off,final int len){
  final ByteArrayOutputStream baos=new ByteArrayOutputStream(expected.length);
{
    final ByteBuffer wrapper=ByteBuffer.wrap(expected,off,len);
    assertEquals(off + len,wrapper.limit());
    assertEquals(off,wrapper.position());
    c.compress(wrapper,baos);
    assertEquals(len + off,wrapper.limit());
    assertEquals(len + off,wrapper.position());
  }
  final byte[] compressed=baos.toByteArray();
  final byte[] actual;
{
    final ByteBuffer decompressed=c.decompress(compressed);
    assertEquals(0,decompressed.position());
    assertEquals(len,decompressed.limit());
    assertEquals(len,decompressed.remaining());
    actual=new byte[decompressed.remaining()];
    decompressed.get(actual);
  }
  for (int i=off, j=0; i < len; i++, j++) {
    if (expected[i] != actual[j]) {
      fail("bytes differ at offset=" + j + " in decompressed data: expected.length="+ expected.length+ ", off="+ off+ ", len="+ len);
    }
  }
  return compressed.length;
}

protected int doCompressionTest ( final IRecordCompressor c , final byte [ ] expected , final int off , final int len ) { final ByteArrayOutputStream baos = new ByteArrayOutputStream ( expected . length ) ; { final ByteBuffer wrapper = ByteBuffer . wrap ( expected , off , len ) ; assertEquals ( off + len , wrapper . limit ( ) ) ; assertEquals ( off , wrapper . position ( ) ) ; c . compress ( wrapper , baos ) ; assertEquals ( len + off , wrapper . limit ( ) ) ; assertEquals ( len + off , wrapper . position ( ) ) ; } final byte [ ] compressed = baos . toByteArray ( ) ; final byte [ ] actual ; { final ByteBuffer decompressed = c . decompress ( compressed ) ; assertEquals ( 0 , decompressed . position ( ) ) ; assertEquals ( len , decompressed . limit ( ) ) ; assertEquals ( len , decompressed . remaining ( ) ) ; actual = new byte [ decompressed . remaining ( ) ] ; decompressed . get ( actual ) ; } for ( int i = off , j = 0 ; i < len ; i ++ , j ++ ) { if ( expected [ i ] != actual [ j ] ) { fail ( "bytes differ at offset=" + j + " in decompressed data: expected.length=" + expected . length + ", off=" + off + ", len=" + len ) ; } } return compressed . length ; }
test helper applies the compression algorithm to the data and then verifies that the expected data can be recovered by applying the decompression algorithm .
