directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 9750 - incubator/directory/snickers/branches/chunking/ber/src/test/org/apache/snickers/ber
Date Fri, 26 Mar 2004 04:01:28 GMT
Author: akarasulu
Date: Thu Mar 25 20:01:27 2004
New Revision: 9750

Modified:
   incubator/directory/snickers/branches/chunking/ber/src/test/org/apache/snickers/ber/TupleTest.java
Log:
fixed to accomodate chunking changes

Modified: incubator/directory/snickers/branches/chunking/ber/src/test/org/apache/snickers/ber/TupleTest.java
==============================================================================
--- incubator/directory/snickers/branches/chunking/ber/src/test/org/apache/snickers/ber/TupleTest.java
(original)
+++ incubator/directory/snickers/branches/chunking/ber/src/test/org/apache/snickers/ber/TupleTest.java
Thu Mar 25 20:01:27 2004
@@ -34,6 +34,8 @@
  */
 public class TupleTest extends TestCase
 {
+    private static final ByteBuffer EMPTY_BUFFER =
+        ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ;
 
     public static void main(String[] args)
     {
@@ -118,169 +120,6 @@
     /*
      * Class to test for void Tuple(int, int, TypeClass, boolean, byte[])
      */
-    public void testTupleintTypeClassbooleanbyteArray()
-    {
-        Tuple t = new Tuple( 2, TypeClass.PRIVATE, true, 
-                ArrayUtils.EMPTY_BYTE_ARRAY ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.PRIVATE, t.getTypeClass() ) ;
-        assertEquals( true, t.isPrimitive() ) ;
-        assertEquals( 0, t.getLength() ) ;
-        assertEquals( ArrayUtils.EMPTY_BYTE_ARRAY, t.getValue() ) ;
-
-        t = new Tuple( 2, TypeClass.PRIVATE, true, (byte[]) null ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.PRIVATE, t.getTypeClass() ) ;
-        assertEquals( true, t.isPrimitive() ) ;
-        assertEquals( 0, t.getLength() ) ;
-        assertEquals( ArrayUtils.EMPTY_BYTE_ARRAY, t.getValue() ) ;
-
-        byte[] bites = new byte[7] ;
-        t = new Tuple( 2, (TypeClass) null, false, bites ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( false, t.isPrimitive() ) ;
-        assertEquals( 7, t.getLength() ) ;
-        assertEquals( bites, t.getValue() ) ;
-        
-        t = new Tuple( 2, null, false, (byte[]) null ) ; 
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( false, t.isPrimitive() ) ;
-        assertEquals( 0, t.getLength() ) ;
-        assertEquals( ArrayUtils.EMPTY_BYTE_ARRAY, t.getValue() ) ;
-    }
-
-    /*
-     * Class to test for void Tuple(int, int, TypeClass, boolean, byte[])
-     */
-    public void testTupleintTypeClassbooleanBuffer()
-    {
-        Tuple t = new Tuple( 2, TypeClass.PRIVATE, true, 
-                ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.PRIVATE, t.getTypeClass() ) ;
-        assertEquals( true, t.isPrimitive() ) ;
-        assertEquals( 0, t.getLength() ) ;
-        assertEquals( ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ), 
-                t.getValue() ) ;
-
-        t = new Tuple( 2, TypeClass.PRIVATE, true, (ByteBuffer) null ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.PRIVATE, t.getTypeClass() ) ;
-        assertEquals( true, t.isPrimitive() ) ;
-        assertEquals( 0, t.getLength() ) ;
-        assertEquals( ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ), 
-                t.getValue() ) ;
-
-        ByteBuffer bites = ByteBuffer.allocate( 7 ) ;
-        t = new Tuple( 2, (TypeClass) null, false, bites ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( false, t.isPrimitive() ) ;
-        assertEquals( 7, t.getLength() ) ;
-        assertEquals( bites, t.getValue() ) ;
-        
-        t = new Tuple( 2, null, false, (ByteBuffer) null ) ; 
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( false, t.isPrimitive() ) ;
-        assertEquals( 0, t.getLength() ) ;
-        assertEquals( ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ), 
-                t.getValue() ) ;
-    }
-
-    /*
-     * Class to test for void Tuple(int, int, TypeClass, boolean, byte[])
-     */
-    public void testTupleintbyteArray()
-    {
-        Tuple t = new Tuple( 2, ArrayUtils.EMPTY_BYTE_ARRAY ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( true, t.isPrimitive() ) ;
-        assertEquals( 0, t.getLength() ) ;
-        assertEquals( ArrayUtils.EMPTY_BYTE_ARRAY, t.getValue() ) ;
-        
-        byte[] bites = new byte[5] ;
-        t = new Tuple( 2, bites ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( true, t.isPrimitive() ) ;
-        assertEquals( 5, t.getLength() ) ;
-        assertEquals( bites, t.getValue() ) ;
-    }
-
-    /*
-     * Class to test for void Tuple(int, int, TypeClass, boolean, byte[])
-     */
-    public void testTupleintBuffer()
-    {
-        Tuple t = new Tuple( 2, 
-                ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( true, t.isPrimitive() ) ;
-        assertEquals( 0, t.getLength() ) ;
-        assertEquals( ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ), 
-                t.getValue() ) ;
-        
-        ByteBuffer bites = ByteBuffer.allocate( 5 ) ;
-        t = new Tuple( 2, bites ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( true, t.isPrimitive() ) ;
-        assertEquals( 5, t.getLength() ) ;
-        assertEquals( bites, t.getValue() ) ;
-    }
-
-    /*
-     * Class to test for void Tuple(int, int, TypeClass, boolean, byte[])
-     */
-    public void testTupleintbooleanbyteArray()
-    {
-        Tuple t = new Tuple( 2, false, ArrayUtils.EMPTY_BYTE_ARRAY ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( false, t.isPrimitive() ) ;
-        assertEquals( 0, t.getLength() ) ;
-        assertEquals( ArrayUtils.EMPTY_BYTE_ARRAY, t.getValue() ) ;
-        
-        byte[] bites = new byte[5] ;
-        t = new Tuple( 2, false, bites ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( false, t.isPrimitive() ) ;
-        assertEquals( 5, t.getLength() ) ;
-        assertEquals( bites, t.getValue() ) ;
-    }
-
-    /*
-     * Class to test for void Tuple(int, int, TypeClass, boolean, byte[])
-     */
-    public void testTupleintbooleanBuffer()
-    {
-        Tuple t = new Tuple( 2, false, 
-                ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( false, t.isPrimitive() ) ;
-        assertEquals( 0, t.getLength() ) ;
-        assertEquals( ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ), 
-                t.getValue() ) ;
-        
-        ByteBuffer bites = ByteBuffer.allocate( 5 ) ;
-        t = new Tuple( 2, false, bites ) ;
-        assertEquals( 2, t.getId() ) ;
-        assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
-        assertEquals( false, t.isPrimitive() ) ;
-        assertEquals( 5, t.getLength() ) ;
-        assertEquals( bites, t.getValue() ) ;
-    }
-
-    /*
-     * Class to test for void Tuple(int, int, TypeClass, boolean, byte[])
-     */
     public void testTupleintTypeClass()
     {
         Tuple t = new Tuple( 2, TypeClass.PRIVATE ) ;
@@ -288,14 +127,14 @@
         assertEquals( TypeClass.PRIVATE, t.getTypeClass() ) ;
         assertEquals( false, t.isPrimitive() ) ;
         assertEquals( Length.INDEFINATE, t.getLength() ) ;
-        assertEquals( ArrayUtils.EMPTY_BYTE_ARRAY, t.getValue() ) ;
+        assertEquals( EMPTY_BUFFER, t.getValue() ) ;
 
         t = new Tuple( 2, (TypeClass) null ) ;
         assertEquals( 2, t.getId() ) ;
         assertEquals( TypeClass.APPLICATION, t.getTypeClass() ) ;
         assertEquals( false, t.isPrimitive() ) ;
         assertEquals( Length.INDEFINATE, t.getLength() ) ;
-        assertEquals( ArrayUtils.EMPTY_BYTE_ARRAY, t.getValue() ) ;
+        assertEquals( EMPTY_BUFFER, t.getValue() ) ;
     }
 
     public void testGetId()
@@ -387,14 +226,14 @@
     public void testGetValue()
     {
         Tuple t = new Tuple() ;
-        assertEquals( ArrayUtils.EMPTY_BYTE_ARRAY, t.getValue() ) ;
+        assertEquals( EMPTY_BUFFER, t.getValue() ) ;
         byte[] bites = {1, 2, 3, 45} ;
-        t.value = bites ;
-        assertEquals( bites, t.getValue() ) ;
+        t.value = ByteBuffer.wrap( bites ) ;
+        assertEquals( ByteBuffer.wrap( bites ), t.getValue() ) ;
         byte[] bites2 = {1, 2, 3, 45} ;
         assertFalse( bites2 == t.getValue() ) ;
         t.clear() ;
-        assertEquals( ArrayUtils.EMPTY_BYTE_ARRAY, t.getValue() ) ;
+        assertEquals( EMPTY_BUFFER, t.getValue() ) ;
     }
 
     public void testClear()
@@ -425,10 +264,10 @@
         t.clear() ;
         assertEquals( TypeClass.APPLICATION, t.typeClass ) ;
 
-        t.value = new byte[3] ;
+        t.value = ByteBuffer.allocate( 3 ) ;
         assertNotNull( t.value ) ;
         t.clear() ;
-        assertEquals( ArrayUtils.EMPTY_BYTE_ARRAY, t.value ) ;
+        assertEquals( EMPTY_BUFFER, t.value ) ;
 
         t.valueIndex = 12 ;
         assertEquals( 12, t.valueIndex ) ;
@@ -491,9 +330,12 @@
         t1 = ( Tuple ) t0.clone() ;
         assertTrue( t0.equals( t1 ) ) ;
 
-        t0.value = new byte[4] ;
+        t0.value = ByteBuffer.allocate( 4 ) ;
         t1.value = null ;
-        assertFalse( t0.equals( t1 ) ) ;
+        
+        // The buffer does not factor into equality
+        assertTrue( t0.equals( t1 ) ) ;
+        
         t1 = ( Tuple ) t0.clone() ;
         assertTrue( t0.equals( t1 ) ) ;
 
@@ -509,229 +351,6 @@
         assertTrue( t.equals( t.clone() ) ) ;
     }
 
-    public void testToEncodedArrayConstructed()
-    {
-        Tuple t = null ;
-        byte[] encoded ;
-        String binary ;
-        
-        t = new Tuple( 0, 0 ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "01100000"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        t = new Tuple( 2, 0 ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "01100010"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        t = new Tuple( 30, 0 ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "01111110"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        t = new Tuple( 31, 0 ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "00011111" +
-                "01111111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        t = new Tuple( 128, 0 ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "00000001" +
-                "10000000" +
-                "01111111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        t = new Tuple( 128, 127 ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "01111111" +
-                "00000001" +
-                "10000000" +
-                "01111111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        t = new Tuple( 128, 128 ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "10000000" +
-                "10000001" +
-                "00000001" +
-                "10000000" +
-                "01111111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        t = new Tuple( 128, 255 ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "11111111" +
-                "10000001" +
-                "00000001" +
-                "10000000" +
-                "01111111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        t = new Tuple( 128, 256 ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000001" +
-                "00000000" +
-                "10000010" +
-                "00000001" +
-                "10000000" +
-                "01111111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        t = new Tuple( Tuple.BIT_27-1, Integer.MAX_VALUE ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( Binary.toAsciiString( Integer.MAX_VALUE ) + 
-                "10000100" +
-                "01111111" +
-                "11111111" +
-                "11111111" +
-                "11111111" +
-                "01111111"
-                , Binary.toAsciiString( encoded ) ) ;
-    }
-
-    public void testToEncodedArrayPrimitive()
-    {
-        Tuple t = null ;
-        byte[] encoded ;
-        byte[] data ;
-        String binary ;
-        
-        data = new byte[0] ;
-        t = new Tuple( 0, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "01000000"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        data = new byte[0] ;
-        t = new Tuple( 2, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "01000010"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        data = new byte[0] ;
-        t = new Tuple( 30, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "01011110"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        data = new byte[0] ;
-        t = new Tuple( 31, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "00011111" +
-                "01011111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        data = new byte[0] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "00000001" +
-                "10000000" +
-                "01011111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        data = new byte[1] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( 
-                "00000000" +
-                "00000001" +
-                "00000001" +
-                "10000000" +
-                "01011111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        data = new byte[127] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( Binary.toAsciiString( data ) +
-                "01111111" +
-                "00000001" +
-                "10000000" +
-                "01011111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        data = new byte[128] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( Binary.toAsciiString( data ) +
-                "10000000" +
-                "10000001" +
-                "00000001" +
-                "10000000" +
-                "01011111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        data = new byte[255] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( Binary.toAsciiString( data ) +
-                "11111111" +
-                "10000001" +
-                "00000001" +
-                "10000000" +
-                "01011111"
-                , Binary.toAsciiString( encoded ) ) ;
-
-        data = new byte[256] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedArray() ;
-        binary = Binary.toAsciiString( encoded ) ;
-        assertEquals( Binary.toAsciiString( data ) + 
-                "00000001" +
-                "00000000" +
-                "10000010" +
-                "00000001" +
-                "10000000" +
-                "01011111"
-                , Binary.toAsciiString( encoded ) ) ;
-    }
-
-    
     public void testToEncodedBufferConstructed()
     {
         Tuple t = null ;
@@ -739,7 +358,7 @@
         String binary ;
         
         t = new Tuple( 0, 0 ) ;
-        encoded = t.toEncodedBuffer() ;
+        encoded = t.toEncodedBuffer( EMPTY_BUFFER ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
@@ -747,7 +366,7 @@
                 , toAsciiString( encoded ) ) ;
 
         t = new Tuple( 2, 0 ) ;
-        encoded = t.toEncodedBuffer() ;
+        encoded = t.toEncodedBuffer( EMPTY_BUFFER ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
@@ -755,7 +374,7 @@
                 , toAsciiString( encoded ) ) ;
 
         t = new Tuple( 30, 0 ) ;
-        encoded = t.toEncodedBuffer() ;
+        encoded = t.toEncodedBuffer( EMPTY_BUFFER ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
@@ -763,7 +382,7 @@
                 , toAsciiString( encoded ) ) ;
 
         t = new Tuple( 31, 0 ) ;
-        encoded = t.toEncodedBuffer() ;
+        encoded = t.toEncodedBuffer( EMPTY_BUFFER ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
@@ -772,7 +391,7 @@
                 , toAsciiString( encoded ) ) ;
 
         t = new Tuple( 128, 0 ) ;
-        encoded = t.toEncodedBuffer() ;
+        encoded = t.toEncodedBuffer( EMPTY_BUFFER ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
@@ -782,7 +401,7 @@
                 , toAsciiString( encoded ) ) ;
 
         t = new Tuple( 128, 127 ) ;
-        encoded = t.toEncodedBuffer() ;
+        encoded = t.toEncodedBuffer( ByteBuffer.allocate( 127 ) ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "01111111" +
@@ -792,7 +411,7 @@
                 , toAsciiString( encoded ) ) ;
 
         t = new Tuple( 128, 128 ) ;
-        encoded = t.toEncodedBuffer() ;
+        encoded = t.toEncodedBuffer( ByteBuffer.allocate( 128 ) ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "10000000" +
@@ -803,7 +422,7 @@
                 , toAsciiString( encoded ) ) ;
 
         t = new Tuple( 128, 255 ) ;
-        encoded = t.toEncodedBuffer() ;
+        encoded = t.toEncodedBuffer( ByteBuffer.allocate( 255 ) ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "11111111" +
@@ -814,7 +433,7 @@
                 , toAsciiString( encoded ) ) ;
 
         t = new Tuple( 128, 256 ) ;
-        encoded = t.toEncodedBuffer() ;
+        encoded = t.toEncodedBuffer( ByteBuffer.allocate( 256 ) ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000001" +
@@ -824,18 +443,6 @@
                 "10000000" +
                 "01111111"
                 , toAsciiString( encoded ) ) ;
-
-        t = new Tuple( Tuple.BIT_27-1, Integer.MAX_VALUE ) ;
-        encoded = t.toEncodedBuffer() ;
-        binary = toAsciiString( encoded ) ;
-        assertEquals( Binary.toAsciiString( Integer.MAX_VALUE ) + 
-                "10000100" +
-                "01111111" +
-                "11111111" +
-                "11111111" +
-                "11111111" +
-                "01111111"
-                , toAsciiString( encoded ) ) ;
     }
 
     public void testToEncodedBufferPrimitive()
@@ -845,36 +452,32 @@
         byte[] data ;
         String binary ;
         
-        data = new byte[0] ;
-        t = new Tuple( 0, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedBuffer() ;
+        t = new Tuple( 0, 0, true, TypeClass.APPLICATION ) ;
+        encoded = t.toEncodedBuffer( EMPTY_BUFFER ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
                 "01000000"
                 , toAsciiString( encoded ) ) ;
 
-        data = new byte[0] ;
-        t = new Tuple( 2, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedBuffer() ;
+        t = new Tuple( 2, 0, true, TypeClass.APPLICATION ) ;
+        encoded = t.toEncodedBuffer( EMPTY_BUFFER ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
                 "01000010"
                 , toAsciiString( encoded ) ) ;
 
-        data = new byte[0] ;
-        t = new Tuple( 30, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedBuffer() ;
+        t = new Tuple( 30, 0, true, TypeClass.APPLICATION ) ;
+        encoded = t.toEncodedBuffer( EMPTY_BUFFER ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
                 "01011110"
                 , toAsciiString( encoded ) ) ;
 
-        data = new byte[0] ;
-        t = new Tuple( 31, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedBuffer() ;
+        t = new Tuple( 31, 0, true, TypeClass.APPLICATION ) ;
+        encoded = t.toEncodedBuffer( EMPTY_BUFFER ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
@@ -882,9 +485,8 @@
                 "01011111"
                 , toAsciiString( encoded ) ) ;
 
-        data = new byte[0] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedBuffer() ;
+        t = new Tuple( 128, 0, true, TypeClass.APPLICATION ) ;
+        encoded = t.toEncodedBuffer( EMPTY_BUFFER ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
@@ -894,8 +496,8 @@
                 , toAsciiString( encoded ) ) ;
 
         data = new byte[1] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedBuffer() ;
+        t = new Tuple( 128, 1, true, TypeClass.APPLICATION ) ;
+        encoded = t.toEncodedBuffer( ByteBuffer.wrap( data ) ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( 
                 "00000000" +
@@ -906,8 +508,8 @@
                 , toAsciiString( encoded ) ) ;
 
         data = new byte[127] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedBuffer() ;
+        t = new Tuple( 128, 127, true, TypeClass.APPLICATION ) ;
+        encoded = t.toEncodedBuffer( ByteBuffer.wrap( data ) ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( Binary.toAsciiString( data ) +
                 "01111111" +
@@ -917,8 +519,8 @@
                 , toAsciiString( encoded ) ) ;
 
         data = new byte[128] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedBuffer() ;
+        t = new Tuple( 128, 128, true, TypeClass.APPLICATION ) ;
+        encoded = t.toEncodedBuffer( ByteBuffer.wrap( data ) ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( Binary.toAsciiString( data ) +
                 "10000000" +
@@ -929,8 +531,8 @@
                 , toAsciiString( encoded ) ) ;
 
         data = new byte[255] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedBuffer() ;
+        t = new Tuple( 128, 255, true, TypeClass.APPLICATION ) ;
+        encoded = t.toEncodedBuffer( ByteBuffer.wrap( data ) ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( Binary.toAsciiString( data ) +
                 "11111111" +
@@ -941,8 +543,8 @@
                 , toAsciiString( encoded ) ) ;
 
         data = new byte[256] ;
-        t = new Tuple( 128, TypeClass.APPLICATION, true, data ) ;
-        encoded = t.toEncodedBuffer() ;
+        t = new Tuple( 128, 256, true, TypeClass.APPLICATION ) ;
+        encoded = t.toEncodedBuffer( ByteBuffer.wrap( data ) ) ;
         binary = toAsciiString( encoded ) ;
         assertEquals( Binary.toAsciiString( data ) + 
                 "00000001" +
@@ -1081,109 +683,109 @@
 
     public void testSetTagbyteArrayint()
     {
-        byte[] bites = new byte[1] ;
+        ByteBuffer bites = ByteBuffer.allocate( 1 ) ;
         Tuple t = new Tuple( 0, 0 ) ;
         t.setTag( bites, 1 ) ;
-        String binary = Binary.toAsciiString( bites ) ;
+        String binary = toAsciiString( bites ) ;
         assertEquals( "01100000", binary ) ;
         
-        bites = new byte[1] ;
+        bites = ByteBuffer.allocate( 1 ) ;
         t = new Tuple( 30, 0 ) ;
         t.setTag( bites, 1 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "01111110", binary ) ;
 
-        bites = new byte[1] ;
+        bites = ByteBuffer.allocate( 1 ) ;
         t = new Tuple( 30, 0 ) ;
         t.isPrimitive = true ;
         t.setTag( bites, 1 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "01011110", binary ) ;
 
-        bites = new byte[2] ;
+        bites = ByteBuffer.allocate( 2 ) ;
         t = new Tuple( 31, 0 ) ;
         t.setTag( bites, 2 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00011111" + "01111111", binary ) ;
 
-        bites = new byte[2] ;
+        bites = ByteBuffer.allocate( 2 ) ;
         t = new Tuple( 127, 0 ) ;
         t.setTag( bites, 2 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "01111111" + "01111111", binary ) ;
 
-        bites = new byte[3] ;
+        bites = ByteBuffer.allocate( 3 ) ;
         t = new Tuple( 128, 0 ) ;
         t.setTag( bites, 3 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00000001" + "10000000" + "01111111", binary ) ;
 
-        bites = new byte[3] ;
+        bites = ByteBuffer.allocate( 3 ) ;
         t = new Tuple( Tuple.BIT_13 - 1, 0 ) ;
         t.setTag( bites, 3 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "01111111" + 
                       "11111111" + 
                       "01111111", binary ) ;
 
-        bites = new byte[4] ;
+        bites = ByteBuffer.allocate( 4 ) ;
         t = new Tuple( Tuple.BIT_13, 0 ) ;
         t.setTag( bites, 4 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
                       "10000000" +
                       "10000000" + 
                       "01111111", binary ) ;
 
-        bites = new byte[4] ;
+        bites = ByteBuffer.allocate( 4 ) ;
         t = new Tuple( Tuple.BIT_13 + 1, 0 ) ;
         t.setTag( bites, 4 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
                       "10000000" +
                       "10000001" + 
                       "01111111", binary ) ;
 
-        bites = new byte[4] ;
+        bites = ByteBuffer.allocate( 4 ) ;
         t = new Tuple( Tuple.BIT_20 - 1, 0 ) ;
         t.setTag( bites, 4 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "01111111" + 
                       "11111111" + 
                       "11111111" + 
                       "01111111", binary ) ;
 
-        bites = new byte[5] ;
+        bites = ByteBuffer.allocate( 5 ) ;
         t = new Tuple( Tuple.BIT_20, 0 ) ;
         t.setTag( bites, 5 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
                       "10000000" +
                       "10000000" +
                       "10000000" + 
                       "01111111", binary ) ;
 
-        bites = new byte[5] ;
+        bites = ByteBuffer.allocate( 5 ) ;
         t = new Tuple( Tuple.BIT_20 + 1, 0 ) ;
         t.setTag( bites, 5 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
                       "10000000" +
                       "10000000" +
                       "10000001" + 
                       "01111111", binary ) ;
 
-        bites = new byte[5] ;
+        bites = ByteBuffer.allocate( 5 ) ;
         t = new Tuple( Tuple.BIT_27 - 1, 0 ) ;
         t.setTag( bites, 5 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "01111111" + 
                       "11111111" + 
                       "11111111" + 
                       "11111111" + 
                       "01111111", binary ) ;
 
-        bites = new byte[6] ;
+        bites = ByteBuffer.allocate( 6 ) ;
         t = new Tuple( Tuple.BIT_27, 0 ) ;
         
         try
@@ -1318,116 +920,115 @@
 
     public void testSetLengthbyteArrayintint()
     {
-        byte[] bites = new byte[1] ;
+        ByteBuffer bites = ByteBuffer.allocate( 1 ) ;
         Tuple t = new Tuple( 0, 0 ) ;
-        t.setLength( bites, 0, 1 ) ;
-        String binary = Binary.toAsciiString( bites ) ;
+        t.setLength( bites, 1 ) ;
+        String binary = toAsciiString( bites ) ;
         assertEquals( "00000000", binary ) ;
 
-        bites = new byte[1] ;
+        bites = ByteBuffer.allocate( 1 ) ;
         t = new Tuple( 30, 15 ) ;
-        t.setLength( bites, 0, 1 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        t.setLength( bites, 1 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00001111", binary ) ;
 
-        bites = new byte[1] ;
+        bites = ByteBuffer.allocate( 1 ) ;
         t = new Tuple( 30, 127 ) ;
-        t.setLength( bites, 0, 1 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        t.setLength( bites, 1 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "01111111", binary ) ;
         
-        bites = new byte[2] ;
+        bites = ByteBuffer.allocate( 2 ) ;
         t = new Tuple( 30, 128 ) ;
-        t.setLength( bites, 0, 2 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        t.setLength( bites, 2 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "10000000" +
                       "10000001", binary ) ;
         
-        bites = new byte[2] ;
+        bites = ByteBuffer.allocate( 2 ) ;
         t = new Tuple( 30, 255 ) ;
-        t.setLength( bites, 0, 2 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        t.setLength( bites, 2 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "11111111" +
                       "10000001", binary ) ;
         
-        bites = new byte[3] ;
+        bites = ByteBuffer.allocate( 3 ) ;
         t = new Tuple( 30, 256 ) ;
-        t.setLength( bites, 0, 3 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        t.setLength( bites, 3 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
                       "00000000" +
                       "10000010", binary ) ;
         
-        bites = new byte[3] ;
+        bites = ByteBuffer.allocate( 3 ) ;
         t = new Tuple( 30, Tuple.BIT_15 - 1 ) ;
-        t.setLength( bites, 0, 3 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        t.setLength( bites, 3 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "11111111" +
                       "11111111" +
                       "10000010", binary ) ;
         
-        bites = new byte[4] ;
+        bites = ByteBuffer.allocate( 4 ) ;
         t = new Tuple( 30, Tuple.BIT_15 ) ;
-        t.setLength( bites, 0, 4 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        t.setLength( bites, 4 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
                       "00000000" +
                       "00000000" +
                       "10000011", binary ) ;
         
-        bites = new byte[4] ;
+        bites = ByteBuffer.allocate( 4 ) ;
         t = new Tuple( 30, Tuple.BIT_15 + 1 ) ;
-        t.setLength( bites, 0, 4 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        t.setLength( bites, 4 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
                       "00000000" +
                       "00000001" +
                       "10000011", binary ) ;
         
-        bites = new byte[4] ;
+        bites = ByteBuffer.allocate( 4 ) ;
         t = new Tuple( 30, Tuple.BIT_23 - 1 ) ;
-        t.setLength( bites, 0, 4 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        t.setLength( bites, 4 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "11111111" +
                       "11111111" +
                       "11111111" +
                       "10000011", binary ) ;
         
-        bites = new byte[5] ;
+        bites = ByteBuffer.allocate( 5 ) ;
         t = new Tuple( 30, Tuple.BIT_23 ) ;
-        t.setLength( bites, 0, 5 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        t.setLength( bites, 5 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
                       "00000000" +
                       "00000000" +
                       "00000000" +
                       "10000100", binary ) ;
         
-        bites = new byte[5] ;
+        bites = ByteBuffer.allocate( 5 ) ;
         t = new Tuple( 30, Tuple.BIT_23 + 1 ) ;
-        t.setLength( bites, 0, 5 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        t.setLength( bites, 5 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( "00000001" +
                       "00000000" +
                       "00000000" +
                       "00000001" +
                       "10000100", binary ) ;
         
-        bites = new byte[5] ;
+        bites = ByteBuffer.allocate( 5 ) ;
         t = new Tuple( 30, Integer.MAX_VALUE ) ;
-        t.setLength( bites, 0, 5 ) ;
-        t.setLength( bites, 0, 5 ) ;
-        binary = Binary.toAsciiString( bites ) ;
+        t.setLength( bites, 5 ) ;
+        binary = toAsciiString( bites ) ;
         assertEquals( Binary.toAsciiString( Integer.MAX_VALUE ) +
                       "10000100", binary ) ;
         
         
-        bites = new byte[6] ;
+        bites = ByteBuffer.allocate( 6 ) ;
         t = new Tuple( 30, Integer.MAX_VALUE + 1 ) ;
 
         try
         {
-            t.setLength( bites, 0, 6 ) ;
+            t.setLength( bites, 6 ) ;
             fail( "should never get here due to thrown exception" ) ;
         }
         catch( IllegalArgumentException e ) 

Mime
View raw message