FileDocCategorySizeDatePackage
Leb128UtilsTest.javaAPI DocAndroid 5.1 API3401Thu Mar 12 22:18:30 GMT 2015com.android.dx.util

Leb128UtilsTest

public final class Leb128UtilsTest extends TestCase

Fields Summary
Constructors Summary
Methods Summary
private voidassertEquals(byte[] expected, byte[] actual)

        assertTrue(Arrays.toString(actual), Arrays.equals(expected, actual));
    
private byte[]encodeSignedLeb(int value)

        ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput(5);
        Leb128.writeSignedLeb128(out, value);
        return out.toByteArray();
    
private byte[]encodeUnsignedLeb(int value)

        ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput(5);
        Leb128.writeUnsignedLeb128(out, value);
        return out.toByteArray();
    
public voidtestDecodeSignedLeb()

        assertEquals(0, Leb128.readSignedLeb128(new ByteArrayByteInput((byte) 0)));
        assertEquals(1, Leb128.readSignedLeb128(new ByteArrayByteInput((byte) 1)));
        assertEquals(-1, Leb128.readSignedLeb128(new ByteArrayByteInput((byte) 0x7f)));
        assertEquals(0x3c, Leb128.readSignedLeb128(new ByteArrayByteInput((byte) 0x3c)));
        assertEquals(-128, Leb128.readSignedLeb128(
                new ByteArrayByteInput((byte) 0x80, (byte) 0x7f)));
    
public voidtestDecodeUnsignedLeb()

        assertEquals(0, Leb128.readUnsignedLeb128(new ByteArrayByteInput((byte) 0)));
        assertEquals(1, Leb128.readUnsignedLeb128(new ByteArrayByteInput((byte) 1)));
        assertEquals(127, Leb128.readUnsignedLeb128(new ByteArrayByteInput((byte) 0x7f)));
        assertEquals(16256, Leb128.readUnsignedLeb128(
                new ByteArrayByteInput((byte) 0x80, (byte) 0x7f)));
    
public voidtestEncodeSignedLeb()

        assertEquals(new byte[] { 0 }, encodeSignedLeb(0));
        assertEquals(new byte[] { 1 }, encodeSignedLeb(1));
        assertEquals(new byte[] { 0x7f }, encodeSignedLeb(-1));
        assertEquals(new byte[] { (byte) 0x80, 0x7f }, encodeSignedLeb(-128));
    
public voidtestEncodeUnsignedLeb()

        assertEquals(new byte[] { 0 }, encodeUnsignedLeb(0));
        assertEquals(new byte[] { 1 }, encodeUnsignedLeb(1));
        assertEquals(new byte[] { 0x7f }, encodeUnsignedLeb(127));
        assertEquals(new byte[] { (byte) 0x80, 0x7f }, encodeUnsignedLeb(16256));
        assertEquals(new byte[] { (byte) 0xb4, 0x07 }, encodeUnsignedLeb(0x3b4));
        assertEquals(new byte[] { (byte) 0x8c, 0x08 }, encodeUnsignedLeb(0x40c));
        assertEquals(new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0xf },
                encodeUnsignedLeb(0xffffffff));