Package org.apache.harmony.pack200.tests.bytecode

Examples of org.apache.harmony.pack200.tests.bytecode.ByteCodeTest


        decode(BYTE1S2, new byte[] { 10 }, 8, 0);
        decode(BYTE1S2, new byte[] { 11 }, -3, 0);
    }

    public void testCardinality() throws Exception {
        BHSDCodec byte1 = Codec.BYTE1;
        assertEquals(256, byte1.cardinality());
        assertEquals(0, byte1.smallest());
        assertEquals(255, byte1.largest());
        assertFalse(byte1.encodes(-257));
        assertFalse(byte1.encodes(-256));
        assertFalse(byte1.encodes(-255));
        assertFalse(byte1.encodes(-129));
        assertFalse(byte1.encodes(-128));
        assertFalse(byte1.encodes(-127));
        assertFalse(byte1.encodes(-1));
        assertTrue(byte1.encodes(0));
        assertTrue(byte1.encodes(1));
        assertTrue(byte1.encodes(255));
        assertFalse(byte1.encodes(256));
        BHSDCodec byte1s = new BHSDCodec(1, 256, 1);
        assertEquals(256, byte1s.cardinality());
        assertEquals(-128, byte1s.smallest());
        assertEquals(127, byte1s.largest());
        assertFalse(byte1s.encodes(-257));
        assertFalse(byte1s.encodes(-256));
        assertFalse(byte1s.encodes(-255));
        assertFalse(byte1s.encodes(-129));
        assertTrue(byte1s.encodes(-128));
        assertTrue(byte1s.encodes(-127));
        assertTrue(byte1s.encodes(-1));
        assertTrue(byte1s.encodes(0));
        assertTrue(byte1s.encodes(1));
        assertTrue(byte1s.encodes(127));
        assertFalse(byte1s.encodes(128));
        assertFalse(byte1s.encodes(129));
        assertFalse(byte1s.encodes(255));
        assertFalse(byte1s.encodes(256));
        BHSDCodec byte2s = new BHSDCodec(1, 256, 2);
        assertEquals(256, byte2s.cardinality());
        assertEquals(-64, byte2s.smallest());
        assertEquals(191, byte2s.largest());
        assertFalse(byte2s.encodes(-257));
        assertFalse(byte2s.encodes(-256));
        assertFalse(byte2s.encodes(-255));
        assertFalse(byte2s.encodes(-129));
        assertFalse(byte2s.encodes(-128));
        assertFalse(byte2s.encodes(-127));
        assertFalse(byte2s.encodes(-65));
        assertTrue(byte2s.encodes(-64));
        assertTrue(byte2s.encodes(-64));
        assertTrue(byte2s.encodes(-1));
        assertTrue(byte2s.encodes(0));
        assertTrue(byte2s.encodes(1));
        assertTrue(byte2s.encodes(127));
        assertTrue(byte2s.encodes(128));
        assertTrue(byte2s.encodes(191));
        assertFalse(byte2s.encodes(192));
        assertFalse(byte2s.encodes(256));
    }
View Full Code Here


public class BHSDCodecTest extends TestCase {

    public void testEncodeDecode() throws IOException, Pack200Exception {
        for (int i = 1; i < 116; i++) {

            BHSDCodec codec = (BHSDCodec) CodecEncoding.getCodec(i, null, null);

            if (!codec.isDelta()) {
                // Test encode-decode with a selection of numbers within the
                // range of the codec
                long largest = codec.largest();
                long smallest = codec.isSigned() ? codec.smallest() : 0;
                long difference = (largest - smallest) / 4;
                for (long j = smallest; j <= largest; j += difference) {
                    byte[] encoded = codec.encode(j, 0);
                    long decoded = 0;
                    try {
                        decoded = codec.decode(
                                new ByteArrayInputStream(encoded), 0);
                    } catch (EOFException e) {
                        System.out.println(e);
                    }
                    if (j != decoded) {
                        fail("Failed with codec: " + i + ", " + codec
                                + " expected: " + j + ", got: " + decoded);
                    }
                }
            }

            // Test encode-decode with 0
            assertEquals(0, codec.decode(new ByteArrayInputStream(codec.encode(
                    0, 0)), 0));
        }
    }
View Full Code Here

        decode(BYTE1S2, new byte[] { 10 }, 8, 0);
        decode(BYTE1S2, new byte[] { 11 }, -3, 0);
    }

    public void testCardinality() throws Exception {
        BHSDCodec byte1 = Codec.BYTE1;
        assertEquals(256, byte1.cardinality());
        assertEquals(0, byte1.smallest());
        assertEquals(255, byte1.largest());
        assertFalse(byte1.encodes(-257));
        assertFalse(byte1.encodes(-256));
        assertFalse(byte1.encodes(-255));
        assertFalse(byte1.encodes(-129));
        assertFalse(byte1.encodes(-128));
        assertFalse(byte1.encodes(-127));
        assertFalse(byte1.encodes(-1));
        assertTrue(byte1.encodes(0));
        assertTrue(byte1.encodes(1));
        assertTrue(byte1.encodes(255));
        assertFalse(byte1.encodes(256));
        BHSDCodec byte1s = new BHSDCodec(1, 256, 1);
        assertEquals(256, byte1s.cardinality());
        assertEquals(-128, byte1s.smallest());
        assertEquals(127, byte1s.largest());
        assertFalse(byte1s.encodes(-257));
        assertFalse(byte1s.encodes(-256));
        assertFalse(byte1s.encodes(-255));
        assertFalse(byte1s.encodes(-129));
        assertTrue(byte1s.encodes(-128));
        assertTrue(byte1s.encodes(-127));
        assertTrue(byte1s.encodes(-1));
        assertTrue(byte1s.encodes(0));
        assertTrue(byte1s.encodes(1));
        assertTrue(byte1s.encodes(127));
        assertFalse(byte1s.encodes(128));
        assertFalse(byte1s.encodes(129));
        assertFalse(byte1s.encodes(255));
        assertFalse(byte1s.encodes(256));
        BHSDCodec byte2s = new BHSDCodec(1, 256, 2);
        assertEquals(256, byte2s.cardinality());
        assertEquals(-64, byte2s.smallest());
        assertEquals(191, byte2s.largest());
        assertFalse(byte2s.encodes(-257));
        assertFalse(byte2s.encodes(-256));
        assertFalse(byte2s.encodes(-255));
        assertFalse(byte2s.encodes(-129));
        assertFalse(byte2s.encodes(-128));
        assertFalse(byte2s.encodes(-127));
        assertFalse(byte2s.encodes(-65));
        assertTrue(byte2s.encodes(-64));
        assertTrue(byte2s.encodes(-64));
        assertTrue(byte2s.encodes(-1));
        assertTrue(byte2s.encodes(0));
        assertTrue(byte2s.encodes(1));
        assertTrue(byte2s.encodes(127));
        assertTrue(byte2s.encodes(128));
        assertTrue(byte2s.encodes(191));
        assertFalse(byte2s.encodes(192));
        assertFalse(byte2s.encodes(256));
    }
View Full Code Here

public class BHSDCodecTest extends TestCase {

    public void testEncodeDecode() throws IOException, Pack200Exception {
        for (int i = 1; i < 116; i++) {

            BHSDCodec codec = (BHSDCodec) CodecEncoding.getCodec(i, null, null);

            if (!codec.isDelta()) {
                // Test encode-decode with a selection of numbers within the
                // range of the codec
                long largest = codec.largest();
                long smallest = codec.isSigned() ? codec.smallest() : 0;
                long difference = (largest - smallest) / 4;
                for (long j = smallest; j <= largest; j += difference) {
                    byte[] encoded = codec.encode(j, 0);
                    long decoded = 0;
                    try {
                        decoded = codec.decode(
                                new ByteArrayInputStream(encoded), 0);
                    } catch (EOFException e) {
                        System.out.println(e);
                    }
                    if (j != decoded) {
                        fail("Failed with codec: " + i + ", " + codec
                                + " expected: " + j + ", got: " + decoded);
                    }
                }
            }

            // Test encode-decode with 0
            assertEquals(0, codec.decode(new ByteArrayInputStream(codec.encode(
                    0, 0)), 0));
        }
    }
View Full Code Here

*
*/
public class CodecEncodingTest extends TestCase {

    public void testCanonicalEncodings() throws IOException, Pack200Exception {
        Codec defaultCodec = new BHSDCodec(2, 16, 0, 0);
        assertEquals(defaultCodec, CodecEncoding
                .getCodec(0, null, defaultCodec));
        Map map = new HashMap();
        // These are the canonical encodings specified by the Pack200 spec
        map.put(new Integer(1), "(1,256)");
View Full Code Here

public class CodecTest extends TestCase {

    public void testInvalidCodings() {
        for (int i = 0; i < 256; i++) {
            try {
                new BHSDCodec(1, i);
                fail("b=1 -> h=256");
            } catch (IllegalArgumentException e) {
                assertTrue(true);
            }
        }
        for (int i = 1; i <= 5; i++) {
            try {
                new BHSDCodec(i, 256);
                if (i == 5)
                    fail("h=256 -> b!=5");
            } catch (IllegalArgumentException e) {
                assertTrue(true);
            }
View Full Code Here

        for (int i = 0; i < 255; i++)
            decode(Codec.BYTE1, new byte[] { (byte) i }, i, 0);
    }

    public void testByte1Delta() throws Exception {
        Codec BYTE1D = new BHSDCodec(1, 256, 0, 1);
        long last = 0;
        for (int i = 1; i < 255; i++)
            last = decode(BYTE1D, new byte[] { (byte) 1 }, i, last);
    }
View Full Code Here

        for (int i = 1; i < 255; i++)
            last = decode(BYTE1D, new byte[] { (byte) 1 }, i, last);
    }

    public void testByte1DeltaException() throws Exception {
        Codec BYTE1D = new BHSDCodec(1, 256, 0, 1);
        try {
            BYTE1D.decode(new ByteArrayInputStream(new byte[] { (byte) 1 }));
            fail("Decoding with a delta stream and not passing a last value should throw exception");
        } catch (Pack200Exception e) {
            assertTrue(true);
        }
    }
View Full Code Here

            assertTrue(true);
        }
    }

    public void testByte1Signed() throws Exception {
        Codec BYTE1S2 = new BHSDCodec(1, 256, 2);
        decode(BYTE1S2, new byte[] { 0 }, 0, 0);
        decode(BYTE1S2, new byte[] { 1 }, 1, 0);
        decode(BYTE1S2, new byte[] { 2 }, 2, 0);
        decode(BYTE1S2, new byte[] { 3 }, -1, 0);
        decode(BYTE1S2, new byte[] { 4 }, 3, 0);
View Full Code Here

        for (int i = 0; i < 255; i++)
            decode(Codec.BYTE1, new byte[] { (byte) i }, i, 0);
    }

    public void testByte1Delta() throws Exception {
        Codec BYTE1D = new BHSDCodec(1, 256, 0, 1);
        long last = 0;
        for (int i = 1; i < 255; i++)
            last = decode(BYTE1D, new byte[] { (byte) 1 }, i, last);
    }
View Full Code Here

TOP

Related Classes of org.apache.harmony.pack200.tests.bytecode.ByteCodeTest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.