in = new ByteArrayInputStream(bytes);
assertEquals(c1, CodecEncoding.getCodec(116, in, null));
}
public void testGetSpeciferForRunCodec() throws Pack200Exception, IOException {
RunCodec runCodec = new RunCodec(25, Codec.DELTA5, Codec.BYTE1);
int[] specifiers = CodecEncoding.getSpecifier(runCodec, null);
assertTrue(specifiers[0] > 116);
assertTrue(specifiers[0] < 141);
byte[] bytes = new byte[specifiers.length - 1];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) specifiers[i+1];
}
InputStream in = new ByteArrayInputStream(bytes);
RunCodec runCodec2 = (RunCodec) CodecEncoding.getCodec(specifiers[0], in, null);
assertEquals(runCodec.getK(), runCodec2.getK());
assertEquals(runCodec.getACodec(), runCodec2.getACodec());
assertEquals(runCodec.getBCodec(), runCodec2.getBCodec());
// One codec is the same as the default
runCodec = new RunCodec(4096, Codec.DELTA5, Codec.BYTE1);
specifiers = CodecEncoding.getSpecifier(runCodec, Codec.DELTA5);
assertTrue(specifiers[0] > 116);
assertTrue(specifiers[0] < 141);
bytes = new byte[specifiers.length - 1];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) specifiers[i+1];
}
in = new ByteArrayInputStream(bytes);
runCodec2 = (RunCodec) CodecEncoding.getCodec(specifiers[0], in, Codec.DELTA5);
assertEquals(runCodec.getK(), runCodec2.getK());
assertEquals(runCodec.getACodec(), runCodec2.getACodec());
assertEquals(runCodec.getBCodec(), runCodec2.getBCodec());
// Nested run codecs
runCodec = new RunCodec(64, Codec.SIGNED5, new RunCodec(25, Codec.UDELTA5, Codec.DELTA5));
specifiers = CodecEncoding.getSpecifier(runCodec, null);
assertTrue(specifiers[0] > 116);
assertTrue(specifiers[0] < 141);
bytes = new byte[specifiers.length - 1];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) specifiers[i+1];
}
in = new ByteArrayInputStream(bytes);
runCodec2 = (RunCodec) CodecEncoding.getCodec(specifiers[0], in, null);
assertEquals(runCodec.getK(), runCodec2.getK());
assertEquals(runCodec.getACodec(), runCodec2.getACodec());
RunCodec bCodec = (RunCodec) runCodec.getBCodec();
RunCodec bCodec2 = (RunCodec) runCodec2.getBCodec();
assertEquals(bCodec.getK(), bCodec2.getK());
assertEquals(bCodec.getACodec(), bCodec2.getACodec());
assertEquals(bCodec.getBCodec(), bCodec2.getBCodec());
// Nested with one the same as the default
runCodec = new RunCodec(64, Codec.SIGNED5, new RunCodec(25, Codec.UDELTA5, Codec.DELTA5));
specifiers = CodecEncoding.getSpecifier(runCodec, Codec.UDELTA5);
assertTrue(specifiers[0] > 116);
assertTrue(specifiers[0] < 141);
bytes = new byte[specifiers.length - 1];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) specifiers[i+1];
}
in = new ByteArrayInputStream(bytes);
runCodec2 = (RunCodec) CodecEncoding.getCodec(specifiers[0], in, Codec.UDELTA5);
assertEquals(runCodec.getK(), runCodec2.getK());
assertEquals(runCodec.getACodec(), runCodec2.getACodec());
bCodec = (RunCodec) runCodec.getBCodec();
bCodec2 = (RunCodec) runCodec2.getBCodec();
assertEquals(bCodec.getK(), bCodec2.getK());
assertEquals(bCodec.getACodec(), bCodec2.getACodec());
assertEquals(bCodec.getBCodec(), bCodec2.getBCodec());
}