Package org.apache.directory.api.asn1.util

Examples of org.apache.directory.api.asn1.util.BitString


     */
    @Test
    public void testBitStringEmpty()
    {

        BitString bitString = new BitString( 1 );

        bitString.setData( new byte[]
            {} );

        try
        {
            bitString.getBit( 0 );
            fail( "Should not reach this point ..." );
        }
        catch ( IndexOutOfBoundsException ioobe )
        {
            assertTrue( true );
View Full Code Here


     */
    @Test
    public void testSingleBitBitString() throws DecoderException
    {

        BitString bitString = new BitString( new byte[]
            { 0x07, ( byte ) 0x80 } );

        assertEquals( true, bitString.getBit( 0 ) );
    }
View Full Code Here

     */
    @Test
    public void test32BitsBitString() throws DecoderException
    {

        BitString bitString = new BitString( 32 );

        bitString.setData( new byte[]
            { 0x00, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF } );

        for ( int i = 0; i < 32; i++ )
        {
            assertEquals( true, bitString.getBit( i ) );
        }
    }
View Full Code Here

     */
    @Test
    public void test33BitsBitString() throws DecoderException
    {

        BitString bitString = new BitString( 33 );

        bitString.setData( new byte[]
            { 0x07, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0x80 } );

        for ( int i = 0; i < 33; i++ )
        {
            assertEquals( true, bitString.getBit( i ) );
        }

        assertEquals( true, bitString.getBit( 32 ) );
    }
View Full Code Here

    @Test
    public void test0to128BitString() throws DecoderException
    {

        // bit number 14
        BitString bitString14 = new BitString( 14 );

        bitString14.setData( new byte[]
            { 0x02, ( byte ) 0xFF, ( byte ) 0xFC } );

        for ( int i = 0; i < 14; i++ )
        {
            assertEquals( true, bitString14.getBit( i ) );
        }

        // bit number 31
        BitString bitString31 = new BitString( 31 );

        bitString31.setData( new byte[]
            { 0x01, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFE } );

        for ( int i = 0; i < 31; i++ )
        {
            assertEquals( true, bitString31.getBit( i ) );
        }

        // bit number 128
        BitString bitString128 = new BitString( 128 );

        bitString128.setData( new byte[]
            { 0x00, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF,
                ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF,
                ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF } );

        for ( int i = 0; i < 128; i++ )
        {
            assertEquals( true, bitString128.getBit( i ) );
        }
    }
View Full Code Here


    @Test
    public void testBitStringSet()
    {
        BitString bitString = new BitString( 32 );

        byte[] bytes = new byte[]
            { 0x00, ( byte ) 0xAA, 0x11, ( byte ) 0x88, ( byte ) 0xFE };

        int[] bits = new int[]
            {
                1, 0, 1, 0, 1, 0, 1, 0,
                0, 0, 0, 1, 0, 0, 0, 1,
                1, 0, 0, 0, 1, 0, 0, 0,
                1, 1, 1, 1, 1, 1, 1, 0
        };

        for ( int i = 0; i < bits.length; i++ )
        {
            if ( bits[i] == 1 )
            {
                bitString.setBit( i );
            }
        }

        assertEquals( Asn1StringUtils.dumpBytes( bytes ), Asn1StringUtils.dumpBytes( bitString.getData() ) );
    }
View Full Code Here


    @Test
    public void testBitStringSetBit()
    {
        BitString bitString = new BitString( 32 );

        int[] bits = new int[]
            {
                1, 0, 1, 0, 1, 0, 1, 0,
                0, 0, 0, 1, 0, 0, 0, 1,
                1, 0, 0, 0, 1, 0, 0, 0, // After modification, will become 8A
                1,
                1,
                1,
                1,
                1,
                1,
                1,
                0
        };

        for ( int i = 0; i < bits.length; i++ )
        {
            if ( bits[i] == 1 )
            {
                bitString.setBit( i );
            }
        }

        bitString.setBit( 9 );
        byte[] bytesModified = new byte[]
            { 0x00, ( byte ) 0xAA, 0x51, ( byte ) 0x88, ( byte ) 0xFE };

        assertEquals( Asn1StringUtils.dumpBytes( bytesModified ), Asn1StringUtils.dumpBytes( bitString.getData() ) );
    }
View Full Code Here


    @Test
    public void testBitStringClearBit()
    {
        BitString bitString = new BitString( 32 );

        int[] bits = new int[]
            {
                1, 0, 1, 0, 1, 0, 1, 0,
                0, 0, 0, 1, 0, 0, 0, 1,
                1, 0, 0, 0, 1, 0, 0, 0,
                1, 1, 1, 1, 1, 1, 1, 0
        };

        for ( int i = 0; i < bits.length; i++ )
        {
            if ( bits[i] == 1 )
            {
                bitString.setBit( i );
            }
        }

        bitString.clearBit( 11 );
        byte[] bytesModified = new byte[]
            { 0x00, ( byte ) 0xAA, 0x01, ( byte ) 0x88, ( byte ) 0xFE };

        assertEquals( Asn1StringUtils.dumpBytes( bytesModified ), Asn1StringUtils.dumpBytes( bitString.getData() ) );
    }
View Full Code Here

   
    @Test
    public void testEncodeBitString()
    {
        BitString bs = new BitString( 10 );
        bs.setBit( 9 );
       
        ByteBuffer buffer = ByteBuffer.allocate( 5 );
       
        try
        {
View Full Code Here

   
    @Test
    public void testEncodeBitString()
    {
        BitString bs = new BitString( 10 );
        bs.setBit( 9 );
       
        ByteBuffer buffer = ByteBuffer.allocate( 5 );
       
        try
        {
View Full Code Here

TOP

Related Classes of org.apache.directory.api.asn1.util.BitString

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.