directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r679445 - in /directory/shared/branches/bigbang/asn1/src: main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java test/java/org/apache/directory/shared/asn1/ber/tlv/ValueTest.java
Date Thu, 24 Jul 2008 16:11:33 GMT
Author: elecharny
Date: Thu Jul 24 09:11:32 2008
New Revision: 679445

URL: http://svn.apache.org/viewvc?rev=679445&view=rev
Log:
Added the getBytes(long) method to encode a long value.
Added the associated test
Improved the test for getBytes(int) 

Modified:
    directory/shared/branches/bigbang/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java
    directory/shared/branches/bigbang/asn1/src/test/java/org/apache/directory/shared/asn1/ber/tlv/ValueTest.java

Modified: directory/shared/branches/bigbang/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java?rev=679445&r1=679444&r2=679445&view=diff
==============================================================================
--- directory/shared/branches/bigbang/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java
(original)
+++ directory/shared/branches/bigbang/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java
Thu Jul 24 09:11:32 2008
@@ -359,7 +359,7 @@
                 else if ( value >= 0xFFFF8000 )
                 {
                     bytes = new byte[2];
-                    bytes[1] = ( byte ) ( value & 0x000000FF );
+                    bytes[1] = ( byte ) ( value );
                     bytes[0] = ( byte ) ( value >> 8 );
                 }
                 else if ( value >= 0xFF800000 )
@@ -385,6 +385,241 @@
 
 
     /**
+     * Utility function that return a byte array representing the Value.
+     * We must respect the ASN.1 BER encoding scheme : <br>
+     * 1) positive integer <br>
+     * - [0 - 0x7F] : 0xVV <br>
+     * - [0x80 - 0xFF] : 0x00 0xVV <br>
+     * - [0x0100 - 0x7FFF] : 0xVV 0xVV <br>
+     * - [0x8000 - 0xFFFF] : 0x00 0xVV 0xVV <br>
+     * - [0x010000 - 0x7FFFFF] : 0xVV 0xVV 0xVV <br>
+     * - [0x800000 - 0xFFFFFF] : 0x00 0xVV 0xVV 0xVV <br>
+     * - [0x01000000 - 0x7FFFFFFF] : 0xVV 0xVV 0xVV 0xVV <br>
+     * 2) Negative number - (~value) + 1 <br>
+     * They are encoded following the table (the <br>
+     * encode bytes are those enclosed by squared braquets) :<br>
+     * <br>
+     *   -1                      -> FF FF FF FF FF FF FF [FF]<br>
+     *   -127                    -> FF FF FF FF FF FF FF [81]<br>
+     *   -128                    -> FF FF FF FF FF FF FF [80]<br>
+     *   -129                    -> FF FF FF FF FF FF [FF 7F]<br>
+     *   -255                    -> FF FF FF FF FF FF [FF 01]<br>
+     *   -256                    -> FF FF FF FF FF FF [FF 00]<br>
+     *   -257                    -> FF FF FF FF FF FF [FE FF]<br>
+     *   -32767                  -> FF FF FF FF FF FF [80 01]<br>
+     *   -32768                  -> FF FF FF FF FF FF [80 00]<br>
+     *   -32769                  -> FF FF FF FF FF [FF 7F FF]<br>
+     *   -65535                  -> FF FF FF FF FF [FF 00 01]<br>
+     *   -65536                  -> FF FF FF FF FF [FF 00 00]<br>
+     *   -65537                  -> FF FF FF FF FF [FE FF FF]<br>
+     *   -8388607                -> FF FF FF FF FF [80 00 01]<br>
+     *   -8388608                -> FF FF FF FF FF [80 00 00]<br>
+     *   -8388609                -> FF FF FF FF [FF 7F FF FF]<br>
+     *   -16777215               -> FF FF FF FF [FF 00 00 01]<br>
+     *   -16777216               -> FF FF FF FF [FF 00 00 00]<br>
+     *   -16777217               -> FF FF FF FF [FE FF FF FF]<br>
+     *   -2147483647             -> FF FF FF FF [80 00 00 01]<br>
+     *   -2147483648             -> FF FF FF FF [80 00 00 00]<br>
+     *   -2147483649             -> FF FF FF [FF 7F FF FF FF]<br>
+     *   -4294967295             -> FF FF FF [FF 00 00 00 01]<br>
+     *   -4294967296             -> FF FF FF [FF 00 00 00 00]<br>
+     *   -4294967297             -> FF FF FF [FE FF FF FF FF]<br>
+     *   -549755813887           -> FF FF FF [80 00 00 00 01]<br>
+     *   -549755813888           -> FF FF FF [80 00 00 00 00]<br>
+     *   -549755813889           -> FF FF [FF 7F FF FF FF FF]<br>
+     *   -1099511627775          -> FF FF [FF 00 00 00 00 01]<br>
+     *   -1099511627776          -> FF FF [FF 00 00 00 00 00]<br>
+     *   -1099511627777          -> FF FF [FE FF FF FF FF FF]<br>
+     *   -140737488355327        -> FF FF [80 00 00 00 00 01]<br>
+     *   -140737488355328        -> FF FF [80 00 00 00 00 00]<br>
+     *   -140737488355329        -> FF [FF 7F FF FF FF FF FF]<br>
+     *   -281474976710655        -> FF [FF 00 00 00 00 00 01]<br>
+     *   -281474976710656        -> FF [FF 00 00 00 00 00 00]<br>
+     *   -281474976710657        -> FF [FE FF FF FF FF FF FF]<br>
+     *   -36028797018963967      -> FF [80 00 00 00 00 00 01]<br>
+     *   -36028797018963968      -> FF [80 00 00 00 00 00 00]<br>
+     *   -36028797018963969      -> [FF 7F FF FF FF FF FF FF]<br>
+     *   -72057594037927935      -> [FF 00 00 00 00 00 00 01]<br>
+     *   -72057594037927936      -> [FF 00 00 00 00 00 00 00]<br>
+     *   -72057594037927937      -> [FE FF FF FF FF FF FF FF]<br>
+     *   -9223372036854775807    -> [80 00 00 00 00 00 00 01]<br>
+     *   -9223372036854775808    -> [80 00 00 00 00 00 00 00]<br>
+     * 
+     * 
+     * @param value The value to store in a byte array
+     * @return The byte array representing the value.
+     */
+    public static byte[] getBytes( long value )
+    {
+        byte[] bytes = null;
+
+        if ( value >= 0 )
+        {
+            if ( ( value >= 0 ) && ( value <= ONE_BYTE_MAX ) )
+            {
+                bytes = new byte[1];
+                bytes[0] = ( byte ) value;
+            }
+            else if ( ( value > ONE_BYTE_MAX ) && ( value <= TWO_BYTE_MAX )
)
+            {
+                bytes = new byte[2];
+                bytes[1] = ( byte ) value;
+                bytes[0] = ( byte ) ( value >> 8 );
+            }
+            else if ( ( value > TWO_BYTE_MAX ) && ( value <= THREE_BYTE_MAX
) )
+            {
+                bytes = new byte[3];
+                bytes[2] = ( byte ) value;
+                bytes[1] = ( byte ) ( value >> 8 );
+                bytes[0] = ( byte ) ( value >> 16 );
+            }
+            else if ( ( value > THREE_BYTE_MAX ) && ( value <= FOUR_BYTE_MAX
) )
+            {
+                bytes = new byte[4];
+                bytes[3] = ( byte ) value;
+                bytes[2] = ( byte ) ( value >> 8 );
+                bytes[1] = ( byte ) ( value >> 16 );
+                bytes[0] = ( byte ) ( value >> 24 );
+            }
+            else if ( ( value > FOUR_BYTE_MAX ) && ( value <= FIVE_BYTE_MAX
) )
+            {
+                bytes = new byte[5];
+                bytes[4] = ( byte ) value;
+                bytes[3] = ( byte ) ( value >> 8 );
+                bytes[2] = ( byte ) ( value >> 16 );
+                bytes[1] = ( byte ) ( value >> 24 );
+                bytes[0] = ( byte ) ( value >> 32 );
+            }
+            else if ( ( value > FIVE_BYTE_MAX ) && ( value <= SIX_BYTE_MAX
) )
+            {
+                bytes = new byte[6];
+                bytes[5] = ( byte ) value;
+                bytes[4] = ( byte ) ( value >> 8 );
+                bytes[3] = ( byte ) ( value >> 16 );
+                bytes[2] = ( byte ) ( value >> 24 );
+                bytes[1] = ( byte ) ( value >> 32 );
+                bytes[0] = ( byte ) ( value >> 40 );
+            }
+            else if ( ( value > SIX_BYTE_MAX ) && ( value <= SEVEN_BYTE_MAX
) )
+            {
+                bytes = new byte[7];
+                bytes[6] = ( byte ) value;
+                bytes[5] = ( byte ) ( value >> 8 );
+                bytes[4] = ( byte ) ( value >> 16 );
+                bytes[3] = ( byte ) ( value >> 24 );
+                bytes[2] = ( byte ) ( value >> 32 );
+                bytes[1] = ( byte ) ( value >> 40 );
+                bytes[0] = ( byte ) ( value >> 48 );
+            }
+            else
+            {
+                bytes = new byte[8];
+                bytes[7] = ( byte ) value;
+                bytes[6] = ( byte ) ( value >> 8 );
+                bytes[5] = ( byte ) ( value >> 16 );
+                bytes[4] = ( byte ) ( value >> 24 );
+                bytes[3] = ( byte ) ( value >> 32 );
+                bytes[2] = ( byte ) ( value >> 40 );
+                bytes[1] = ( byte ) ( value >> 48 );
+                bytes[0] = ( byte ) ( value >> 56 );
+            }
+        }
+        else
+        {
+            // On special case : 0x80000000
+            if ( value == 0x8000000000000000L )
+            {
+                bytes = new byte[8];
+                bytes[7] = ( byte ) 0x00;
+                bytes[6] = ( byte ) 0x00;
+                bytes[5] = ( byte ) 0x00;
+                bytes[4] = ( byte ) 0x00;
+                bytes[3] = ( byte ) 0x00;
+                bytes[2] = ( byte ) 0x00;
+                bytes[1] = ( byte ) 0x00;
+                bytes[0] = ( byte ) 0x80;
+            }
+            else 
+            {
+                // We have to compute the complement, and add 1
+                // value = ( ~value ) + 1;
+                
+                if ( value >= 0xFFFFFFFFFFFFFF80L )
+                {
+                    bytes = new byte[1];
+                    bytes[0] = ( byte ) value;
+                }
+                else if ( value >= 0xFFFFFFFFFFFF8000L )
+                {
+                    bytes = new byte[2];
+                    bytes[1] = ( byte ) ( value );
+                    bytes[0] = ( byte ) ( value >> 8 );
+                }
+                else if ( value >= 0xFFFFFFFFFF800000L )
+                {
+                    bytes = new byte[3];
+                    bytes[2] = ( byte ) value ;
+                    bytes[1] = ( byte ) ( value >> 8 );
+                    bytes[0] = ( byte ) ( value >> 16 );
+                }
+                else if ( value >= 0xFFFFFFFF80000000L )
+                {
+                    bytes = new byte[4];
+                    bytes[3] = ( byte ) value;
+                    bytes[2] = ( byte ) ( value >> 8 );
+                    bytes[1] = ( byte ) ( value >> 16 );
+                    bytes[0] = ( byte ) ( value >> 24 );
+                }
+                else if ( value >= 0xFFFFFF8000000000L )
+                {
+                    bytes = new byte[5];
+                    bytes[4] = ( byte ) value;
+                    bytes[3] = ( byte ) ( value >> 8 );
+                    bytes[2] = ( byte ) ( value >> 16 );
+                    bytes[1] = ( byte ) ( value >> 24 );
+                    bytes[0] = ( byte ) ( value >> 32 );
+                }
+                else if ( value >= 0xFFFF800000000000L )
+                {
+                    bytes = new byte[6];
+                    bytes[5] = ( byte ) value;
+                    bytes[4] = ( byte ) ( value >> 8 );
+                    bytes[3] = ( byte ) ( value >> 16 );
+                    bytes[2] = ( byte ) ( value >> 24 );
+                    bytes[1] = ( byte ) ( value >> 32 );
+                    bytes[0] = ( byte ) ( value >> 40 );
+                }
+                else if ( value >= 0xFF80000000000000L )
+                {
+                    bytes = new byte[7];
+                    bytes[6] = ( byte ) value;
+                    bytes[5] = ( byte ) ( value >> 8 );
+                    bytes[4] = ( byte ) ( value >> 16 );
+                    bytes[3] = ( byte ) ( value >> 24 );
+                    bytes[2] = ( byte ) ( value >> 32 );
+                    bytes[1] = ( byte ) ( value >> 40 );
+                    bytes[0] = ( byte ) ( value >> 48 );
+                }
+                else
+                {
+                    bytes = new byte[8];
+                    bytes[7] = ( byte ) value;
+                    bytes[6] = ( byte ) ( value >> 8 );
+                    bytes[5] = ( byte ) ( value >> 16 );
+                    bytes[4] = ( byte ) ( value >> 24 );
+                    bytes[3] = ( byte ) ( value >> 32 );
+                    bytes[2] = ( byte ) ( value >> 40 );
+                    bytes[1] = ( byte ) ( value >> 48 );
+                    bytes[0] = ( byte ) ( value >> 56 );
+                }
+            }
+        }
+
+        return bytes;
+    }
+
+
+    /**
      * Encode a String value
      * 
      * @param buffer The PDU in which the value will be put
@@ -559,6 +794,36 @@
 
 
     /**
+     * Encode a long value
+     * 
+     * @param buffer The PDU in which the value will be put
+     * @param value The long to be encoded
+     * @throws EncoderException if the PDU in which the value should be encoded is
+     * two small
+     */
+    public static void encode( ByteBuffer buffer, long value ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try
+        {
+            buffer.put( UniversalTag.INTEGER_TAG );
+            buffer.put( ( byte ) getNbBytes( value ) );
+            buffer.put( getBytes( value ) );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException( "The PDU buffer size is too small !" );
+        }
+
+        return;
+    }
+
+
+    /**
      * Encode an integer value
      * 
      * @param buffer The PDU in which the value will be put

Modified: directory/shared/branches/bigbang/asn1/src/test/java/org/apache/directory/shared/asn1/ber/tlv/ValueTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/asn1/src/test/java/org/apache/directory/shared/asn1/ber/tlv/ValueTest.java?rev=679445&r1=679444&r2=679445&view=diff
==============================================================================
--- directory/shared/branches/bigbang/asn1/src/test/java/org/apache/directory/shared/asn1/ber/tlv/ValueTest.java
(original)
+++ directory/shared/branches/bigbang/asn1/src/test/java/org/apache/directory/shared/asn1/ber/tlv/ValueTest.java
Thu Jul 24 09:11:32 2008
@@ -22,6 +22,7 @@
 
 import java.math.BigInteger;
 import java.nio.ByteBuffer;
+import java.util.Arrays;
 
 import junit.framework.Assert;
 import junit.framework.TestCase;
@@ -90,10 +91,112 @@
         assertEquals( 1, Value.getNbBytes( 0xFFFFFFFFFFFFFFFFL ) );
     }
 
-    
+
+    /**
+     * Test the generation of an Integer Value
+     *
+     */
     @Test
-    public void testGetBytes()
+    public void testGetBytesInt()
     {
+        int[] positiveValues = new int[]
+             {
+                 0x00, 0x01, 0x7F,
+                 0x0080, 0x0081, 0x7FFF,
+                 0x008000, 0x008001, 0x7FFFFF,
+                 0x00800000, 0x00800001, 0x7FFFFFFF
+             };
+
+         byte[][] expectedPositiveBytes = new byte[][]
+             {
+                 // 1 byte
+                 { 0x00 }, 
+                 { 0x01 }, 
+                 { 0x7F },
+                 
+                 // 2 bytes
+                 { 0x00, (byte)0x80 }, 
+                 { 0x00, (byte)0x81 }, 
+                 { 0x7F, (byte)0xFF },
+
+                 // 3 bytes
+                 { 0x00, (byte)0x80, 0x00 },
+                 { 0x00, (byte)0x80, 0x01 },
+                 { 0x7F, (byte)0xFF, (byte)0xFF },
+
+                 // 4 bytes
+                 { 0x00, (byte)0x80, 0x00, 0x00 },
+                 { 0x00, (byte)0x80, 0x00, 0x01 },
+                 { 0x7F, (byte)0xFF, (byte)0xFF, (byte)0xFF },
+             };
+
+         int[] negativeValues = new int[]
+             {
+                 // 1 byte
+                 -1, -127, -128,  
+                             
+                 // 2 bytes
+                 -129, -255, -256, -257, -32767, -32768,
+
+                 // 3 bytes
+                 -32769, -65535, -65536, -65537, -8388607, -8388608,
+
+                 // 4 bytes
+                 -8388609, -16777215, -16777216, -16777217, -2147483647, -2147483648,
+             };
+
+         byte[][] expectedNegativeBytes = new byte[][]
+             {
+                 // 1 byte
+                 { (byte)0xFF },
+                 { (byte)0x81 }, 
+                 { (byte)0x80 }, 
+     
+                 // 2 bytes
+                 { (byte)0xFF, 0x7F }, 
+                 { (byte)0xFF, 0x01 }, 
+                 { (byte)0xFF, 0x00 }, 
+                 { (byte)0xFE, (byte)0xFF }, 
+                 { (byte)0x80, 0x01 }, 
+                 { (byte)0x80, 0x00 }, 
+     
+                 // 3 bytes
+                 { (byte)0xFF, 0x7F, (byte)0xFF }, 
+                 { (byte)0xFF, 0x00, 0x01 },
+                 { (byte)0xFF, 0x00, 0x00 },
+                 { (byte)0xFE, (byte)0xFF, (byte)0xFF },
+                 { (byte)0x80, 0x00, 0x01 },
+                 { (byte)0x80, 0x00, 0x00 },
+     
+                 // 4 bytes
+                 { (byte)0xFF, 0x7F, (byte)0xFF, (byte)0xFF },
+                 { (byte)0xFF, 0x00, 0x00, 0x01 },
+                 { (byte)0xFF, 0x00, 0x00, 0x00 },
+                 { (byte)0xFE, (byte)0xFF, (byte)0xFF, (byte)0xFF },
+                 { (byte)0x80, 0x00, 0x00, 0x01 },
+                 { (byte)0x80, 0x00, 0x00, 0x00 },
+             };
+
+         int i = 0;
+         
+         for ( int value:positiveValues )
+         {
+             byte[] bb = Value.getBytes( value );
+             assertEquals( expectedPositiveBytes[i].length, bb.length );
+             assertTrue( Arrays.equals( expectedPositiveBytes[i], bb ) );
+             i++;
+         }
+         
+         i=0;
+         
+         for ( int value:negativeValues )
+         {
+             byte[] bb = Value.getBytes( value );
+             assertEquals( expectedNegativeBytes[i].length, bb.length );
+             assertTrue( Arrays.equals( expectedNegativeBytes[i], bb ) );
+             i++;
+         }
+
         byte[] bb = Value.getBytes( 0x00000000 );
         assertEquals( 1, bb.length );
         assertEquals( 0, bb[0] );
@@ -244,6 +347,184 @@
     }
 
 
+    /**
+     * Test the generation of a Long Value
+     *
+     */
+    @Test
+    public void testGetBytesLong()
+    {
+        long[] positiveValues = new long[]
+            {
+                0x00L, 0x01L, 0x7FL,
+                0x0080L, 0x0081L, 0x7FFFL,
+                0x008000L, 0x008001L, 0x7FFFFFL,
+                0x00800000L, 0x00800001L, 0x7FFFFFFFL,
+                0x0080000000L, 0x0080000001L, 0x7FFFFFFFFFL,
+                0x008000000000L, 0x008000000001L, 0x7FFFFFFFFFFFL,
+                0x00800000000000L, 0x00800000000001L, 0x7FFFFFFFFFFFFFL,
+                0x0080000000000000L, 0x0080000000000001L, 0x7FFFFFFFFFFFFFFFL
+            };
+        
+        byte[][] expectedPositiveBytes = new byte[][]
+            {
+                // 1 byte
+                { 0x00 }, 
+                { 0x01 }, 
+                { 0x7F },
+                
+                // 2 bytes
+                { 0x00, (byte)0x80 }, 
+                { 0x00, (byte)0x81 }, 
+                { 0x7F, (byte)0xFF },
+
+                // 3 bytes
+                { 0x00, (byte)0x80, 0x00 },
+                { 0x00, (byte)0x80, 0x01 },
+                { 0x7F, (byte)0xFF, (byte)0xFF },
+
+                // 4 bytes
+                { 0x00, (byte)0x80, 0x00, 0x00 },
+                { 0x00, (byte)0x80, 0x00, 0x01 },
+                { 0x7F, (byte)0xFF, (byte)0xFF, (byte)0xFF },
+
+                // 5 bytes
+                { 0x00, (byte)0x80, 0x00, 0x00, 0x00 },
+                { 0x00, (byte)0x80, 0x00, 0x00, 0x01 },
+                { 0x7F, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF },
+
+                // 6 bytes
+                { 0x00, (byte)0x80, 0x00, 0x00, 0x00, 0x00 },
+                { 0x00, (byte)0x80, 0x00, 0x00, 0x00, 0x01 },
+                { 0x7F, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF },
+
+                // 7 bytes
+                { 0x00, (byte)0x80, 0x00, 0x00, 0x00, 0x00, 0x00 },
+                { 0x00, (byte)0x80, 0x00, 0x00, 0x00, 0x00, 0x01 },
+                { 0x7F, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF
},
+
+                // 8 bytes
+                { 0x00, (byte)0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 
+                { 0x00, (byte)0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, 
+                { 0x7F, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF,
(byte)0xFF }
+            };
+
+        long[] negativeValues = new long[]
+            {
+                // 1 byte
+                -1L, -127L, -128L,  
+                            
+                // 2 bytes
+                -129L, -255L, -256L, -257L, -32767L, -32768L,
+
+                // 3 bytes
+                -32769L, -65535L, -65536L, -65537L, -8388607L, -8388608L,
+
+                // 4 bytes
+                -8388609L, -16777215L, -16777216L, -16777217L, -2147483647L, -2147483648L,
+
+                // 5 bytes
+                -2147483649L, -4294967295L, -4294967296L, -4294967297L, -549755813887L, -549755813888L,
+
+                // 6 bytes
+                -549755813889L, -1099511627775L, -1099511627776L, 
+                -1099511627777L, -140737488355327L, -140737488355328L,
+
+                // 7 bytes
+                -140737488355329L, -281474976710655L, -281474976710656L,
+                -281474976710657L, -36028797018963967L, -36028797018963968L,
+                
+                // 8 bytes
+                -36028797018963969L, -72057594037927935L, -72057594037927936L,
+                -72057594037927937L, -9223372036854775807L, -9223372036854775808L
+            };
+        
+        byte[][] expectedNegativeBytes = new byte[][]
+            {
+                // 1 byte
+                { (byte)0xFF },
+                { (byte)0x81 }, 
+                { (byte)0x80 }, 
+    
+                // 2 bytes
+                { (byte)0xFF, 0x7F }, 
+                { (byte)0xFF, 0x01 }, 
+                { (byte)0xFF, 0x00 }, 
+                { (byte)0xFE, (byte)0xFF }, 
+                { (byte)0x80, 0x01 }, 
+                { (byte)0x80, 0x00 }, 
+    
+                // 3 bytes
+                { (byte)0xFF, 0x7F, (byte)0xFF }, 
+                { (byte)0xFF, 0x00, 0x01 },
+                { (byte)0xFF, 0x00, 0x00 },
+                { (byte)0xFE, (byte)0xFF, (byte)0xFF },
+                { (byte)0x80, 0x00, 0x01 },
+                { (byte)0x80, 0x00, 0x00 },
+    
+                // 4 bytes
+                { (byte)0xFF, 0x7F, (byte)0xFF, (byte)0xFF },
+                { (byte)0xFF, 0x00, 0x00, 0x01 },
+                { (byte)0xFF, 0x00, 0x00, 0x00 },
+                { (byte)0xFE, (byte)0xFF, (byte)0xFF, (byte)0xFF },
+                { (byte)0x80, 0x00, 0x00, 0x01 },
+                { (byte)0x80, 0x00, 0x00, 0x00 },
+    
+                // 5 bytes
+                { (byte)0xFF, 0x7F, (byte)0xFF, (byte)0xFF, (byte)0xFF },
+                { (byte)0xFF, 0x00, 0x00, 0x00, 0x01 },
+                { (byte)0xFF, 0x00, 0x00, 0x00, 0x00 },
+                { (byte)0xFE, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF },
+                { (byte)0x80, 0x00, 0x00, 0x00, 0x01 },
+                { (byte)0x80, 0x00, 0x00, 0x00, 0x00 },
+    
+                // 6 bytes
+                { (byte)0xFF, 0x7F, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF },
+                { (byte)0xFF, 0x00, 0x00, 0x00, 0x00, 0x01 },
+                { (byte)0xFF, 0x00, 0x00, 0x00, 0x00, 0x00 },
+                { (byte)0xFE, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF
},
+                { (byte)0x80, 0x00, 0x00, 0x00, 0x00, 0x01 },
+                { (byte)0x80, 0x00, 0x00, 0x00, 0x00, 0x00 },
+    
+                // 7 bytes
+                { (byte)0xFF, 0x7F, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF
},
+                { (byte)0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
+                { (byte)0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+                { (byte)0xFE, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF,
(byte)0xFF },
+                { (byte)0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
+                { (byte)0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+    
+                // 8 bytes
+                { (byte)0xFF, 0x7F, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF,
(byte)0xFF },
+                { (byte)0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
+                { (byte)0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+                { (byte)0xFE, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF,
(byte)0xFF, (byte)0xFF },
+                { (byte)0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
+                { (byte)0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
+            };
+                                                    
+        int i = 0;
+        
+        for ( long value:positiveValues )
+        {
+            byte[] bb = Value.getBytes( value );
+            assertEquals( expectedPositiveBytes[i].length, bb.length );
+            assertTrue( Arrays.equals( expectedPositiveBytes[i], bb ) );
+            i++;
+        }
+        
+        i=0;
+        
+        for ( long value:negativeValues )
+        {
+            byte[] bb = Value.getBytes( value );
+            assertEquals( expectedNegativeBytes[i].length, bb.length );
+            assertTrue( Arrays.equals( expectedNegativeBytes[i], bb ) );
+            i++;
+        }
+    }
+
+
     @Test
     public void testEncodeInt2Bytes()
     {



Mime
View raw message