directory-commits mailing list archives

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

Modified:
   incubator/directory/snickers/branches/chunking/ber/src/test/org/apache/snickers/ber/BERDecoderTest.java
   incubator/directory/snickers/branches/chunking/ber/src/test/org/apache/snickers/ber/TupleTest.java
Log:
changes for chunking

Modified: incubator/directory/snickers/branches/chunking/ber/src/test/org/apache/snickers/ber/BERDecoderTest.java
==============================================================================
--- incubator/directory/snickers/branches/chunking/ber/src/test/org/apache/snickers/ber/BERDecoderTest.java
(original)
+++ incubator/directory/snickers/branches/chunking/ber/src/test/org/apache/snickers/ber/BERDecoderTest.java
Thu Mar 25 21:20:01 2004
@@ -37,6 +37,7 @@
  */
 public class BERDecoderTest extends AbstractDecoderTestCase
 {
+    private static final ByteBuffer EMPTY_BUFFER = ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY
);
     public BERDecoderTest()
     {
         super( BERDecoderTest.class.getName() ) ;
@@ -47,7 +48,7 @@
     {
         decoder.setDecoderMonitor( new DecoderMonitorAdapter() ) ;
         decoder.decode( null ) ;
-        decoder.decode( ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ) ;
+        decoder.decode( EMPTY_BUFFER ) ;
     }
     
     
@@ -55,78 +56,89 @@
     {
         byte[] bites = null ;
         Tuple decoded = null ;
-        Tuple t = new Tuple( 45, ArrayUtils.EMPTY_BYTE_ARRAY ) ;
-        assertTrue( decode( t ).equals( t ) ) ; 
+        Tuple t = new Tuple( 45, 0, true, TypeClass.APPLICATION ) ;
+        assertTrue( decode( t, EMPTY_BUFFER ).equals( t ) ) ; 
         
-        t = new Tuple( 45, "Hello world!".getBytes() ) ;
-        decoded = decode( t ) ;
+        t = new Tuple( 45, "Hello world!".length(), true, 
+                TypeClass.APPLICATION ) ;
+        decoded = decode( t, ByteBuffer.wrap( "Hello world!".getBytes() ) ) ;
         assertTrue( decoded.equals( t ) ) ;
-        assertEquals( "Hello world!", new String( (byte[]) 
-                        decoded.getValue() ) ) ;
+        assertEquals( "Hello world!", toString( decoded.getValue() ) ) ;
 
         String mesg = RandomStringUtils.randomAlphanumeric(1000) ;
-        t = new Tuple( 1234233, mesg.getBytes() ) ;
-        decoded = decode( t ) ;
+        t = new Tuple( 1234233, mesg.length(), true, TypeClass.APPLICATION ) ;
+        decoded = decode( t, ByteBuffer.wrap( mesg.getBytes() ) ) ;
         assertTrue( decoded.equals( t ) ) ;
-        assertEquals( mesg, new String( (byte[]) 
-                        decoded.getValue() ) ) ;
+        assertEquals( mesg, toString( decoded.getValue() ) ) ;
+    }
+    
+    
+    String toString(ByteBuffer buf)
+    {
+        buf = buf.slice() ;
+        byte[] bites = new byte[buf.remaining()] ;
+        buf.get( bites ) ;
+        return new String( bites ) ; 
     }
     
     
     public void testConstructedIndefinate() throws Exception
     {
         Tuple top = new Tuple( 1, TypeClass.APPLICATION ) ;
-        Tuple t0 = new Tuple( 2, "Hello".getBytes() ) ;
-        Tuple t1 = new Tuple( 3, "World".getBytes() ) ;
-        Tuple terminator = new Tuple( 0, TypeClass.UNIVERSAL, true, 
-                ArrayUtils.EMPTY_BYTE_ARRAY ) ;
-        assertTrue( decode( top ).equals( top ) ) ;
+        Tuple t0 = new Tuple( 2, "Hello".length(),
+                true, TypeClass.APPLICATION ) ;
+        Tuple t1 = new Tuple( 3, "World".length(),
+                true, TypeClass.APPLICATION ) ;
+        Tuple terminator = new Tuple( 0, 0, true, TypeClass.UNIVERSAL ) ;
+        assertTrue( decode( top, EMPTY_BUFFER ).equals( top ) ) ;
 
-        Tuple decoded = decode( t0 ) ; 
+        Tuple decoded = decode( t0, ByteBuffer.wrap( "Hello".getBytes() ) ) ; 
         assertTrue( decoded.equals( t0 ) ) ;
-        assertEquals( "Hello", new String( ( byte[] ) decoded.getValue() ) ) ;
+        assertEquals( "Hello", toString( decoded.getValue() ) ) ;
         
-        decoded = decode( t1 ) ; 
+        decoded = decode( t1, ByteBuffer.wrap( "World".getBytes() ) ) ; 
         assertTrue( decoded.equals( t1 ) ) ;
-        assertEquals( "World", new String( ( byte[] ) decoded.getValue() ) ) ;
+        assertEquals( "World", toString( decoded.getValue() ) ) ;
         
-        decoded = decode( terminator ) ;
+        decoded = decode( terminator, EMPTY_BUFFER ) ;
         assertTrue( decoded.equals( top ) ) ;
     }
     
     
     public void testConstructedLongLengthForm() throws Exception
     {
-        String str0 = RandomStringUtils.randomAlphanumeric(10000) ;
-        Tuple t0 = new Tuple( 2, str0.getBytes() ) ;
-        String str1 = RandomStringUtils.randomAlphanumeric(10000) ;
-        Tuple t1 = new Tuple( 3, str1.getBytes() ) ;
+        String str0 = RandomStringUtils.randomAlphanumeric(128) ;
+        Tuple t0 = new Tuple( 2, 128, true, TypeClass.APPLICATION ) ;
+        String str1 = RandomStringUtils.randomAlphanumeric(128) ;
+        Tuple t1 = new Tuple( 3, 128, true, TypeClass.APPLICATION ) ;
         Tuple top = new Tuple( 1, t0.size() + t1.size() ) ;
-        assertTrue( decode( top ).equals( top ) ) ;
+        assertTrue( decode( top, EMPTY_BUFFER ).equals( top ) ) ;
 
-        Tuple decoded = decode( t0 ) ; 
+        Tuple decoded = decode( t0, ByteBuffer.wrap( str0.getBytes() ) ) ; 
         assertTrue( decoded.equals( t0 ) ) ;
-        assertEquals( str0, new String( ( byte[] ) decoded.getValue() ) ) ;
+        assertEquals( str0, toString( decoded.getValue() ) ) ;
         
         // automatically set to top because after t1 is delivered top is 
-        decoded = decode( t1 ) ; 
+        decoded = decode( t1, ByteBuffer.wrap( str1.getBytes() ) ) ; 
         assertTrue( decoded.equals( top ) ) ;
     }
 
 
     public void testConstructedShortLengthForm() throws Exception
     {
-        Tuple t0 = new Tuple( 2, "Hello".getBytes() ) ;
-        Tuple t1 = new Tuple( 3, "World".getBytes() ) ;
+        Tuple t0 = new Tuple( 2, "Hello".length(), true, 
+                TypeClass.APPLICATION ) ;
+        Tuple t1 = new Tuple( 3, "World".length(), true, 
+                TypeClass.APPLICATION ) ;
         Tuple top = new Tuple( 1, t0.size() + t1.size() ) ;
-        assertTrue( decode( top ).equals( top ) ) ;
+        assertTrue( decode( top, EMPTY_BUFFER ).equals( top ) ) ;
 
-        Tuple decoded = decode( t0 ) ; 
+        Tuple decoded = decode( t0, ByteBuffer.wrap( "Hello".getBytes() ) ) ; 
         assertTrue( decoded.equals( t0 ) ) ;
-        assertEquals( "Hello", new String( ( byte[] ) decoded.getValue() ) ) ;
+        assertEquals( "Hello", toString( decoded.getValue() ) ) ;
         
         // automatically set to top because after t1 is delivered top is 
-        decoded = decode( t1 ) ; 
+        decoded = decode( t1, ByteBuffer.wrap( "World".getBytes() ) ) ; 
         assertTrue( decoded.equals( top ) ) ;
     }
     
@@ -134,14 +146,15 @@
     public void testFragmentedValue() throws Exception
     {
         String str0 = RandomStringUtils.randomAlphanumeric(20) ;
-        Tuple t0 = new Tuple( 2, str0.getBytes() ) ;
+        Tuple t0 = new Tuple( 2, str0.length(), true, TypeClass.APPLICATION ) ;
         String str1 = RandomStringUtils.randomAlphanumeric(20) ;
-        Tuple t1 = new Tuple( 3, str1.getBytes() ) ;
+        Tuple t1 = new Tuple( 3, str1.length(), true, TypeClass.APPLICATION ) ;
         Tuple top = new Tuple( 1, t0.size() + t1.size() ) ;
-        assertTrue( decode( top ).equals( top ) ) ;
+        assertTrue( decode( top, EMPTY_BUFFER ).equals( top ) ) ;
 
-        byte[] all = t0.toEncodedArray() ;
-        byte[][] fragments = fragment( all, 10 ) ;
+        ByteBuffer all = 
+            t0.toEncodedBuffer( ByteBuffer.wrap( str0.getBytes() ) ) ;
+        ByteBuffer[] fragments = fragment( all, 10 ) ;
         Tuple decoded = null ;
         
         for ( int ii = 0; ii < fragments.length; ii++ )
@@ -150,10 +163,10 @@
         }
         
         assertTrue( decoded.equals( t0 ) ) ;
-        assertEquals( str0, new String( ( byte[] ) decoded.getValue() ) ) ;
+        assertEquals( str0, toString( buf ) ) ;
         
         // automatically set to top because after t1 is delivered top is 
-        decoded = decode( t1 ) ; 
+        decoded = decode( t1, ByteBuffer.wrap( str1.getBytes() ) ) ; 
         assertTrue( decoded.equals( top ) ) ;
     }
     
@@ -176,17 +189,17 @@
     {
         decoder.setDecoderMonitor( new BERMonitor() ) ;
         String str0 = RandomStringUtils.randomAlphanumeric(20) ;
-        Tuple t0 = new Tuple( 2, str0.getBytes() ) ;
+        Tuple t0 = new Tuple( 2, str0.length() ) ;
         String str1 = RandomStringUtils.randomAlphanumeric(20) ;
-        Tuple t1 = new Tuple( 3, str1.getBytes() ) ;
+        Tuple t1 = new Tuple( 3, str1.length() ) ;
         Tuple top = new Tuple( 1, t0.size() + t1.size() ) ;
-        Tuple decoded = decode( t0 ) ; 
+        Tuple decoded = decode( t0, ByteBuffer.wrap( str0.getBytes() ) ) ; 
         assertTrue( decoded.equals( t0 ) ) ;
         
         // automatically set to top because after t1 is delivered top is 
-        decoded = decode( t1 ) ; 
+        decoded = decode( t1, ByteBuffer.wrap( str1.getBytes() ) ) ; 
         
-        assertTrue( decode( top ).equals( top ) ) ;
+        assertTrue( decode( top, EMPTY_BUFFER ).equals( top ) ) ;
     }
 
 
@@ -194,16 +207,16 @@
     {
         decoder.setDecoderMonitor( null ) ;
         String str0 = RandomStringUtils.randomAlphanumeric(20) ;
-        Tuple t0 = new Tuple( 2, str0.getBytes() ) ;
+        Tuple t0 = new Tuple( 2, str0.length() ) ;
         String str1 = RandomStringUtils.randomAlphanumeric(20) ;
-        Tuple t1 = new Tuple( 3, str1.getBytes() ) ;
+        Tuple t1 = new Tuple( 3, str1.length() ) ;
         Tuple top = new Tuple( 1, t0.size() + t1.size() ) ;
-        Tuple decoded = decode( t0 ) ; 
+        Tuple decoded = decode( t0, ByteBuffer.wrap( str0.getBytes() ) ) ; 
         assertTrue( decoded.equals( t0 ) ) ;
         
         // automatically set to top because after t1 is delivered top is 
-        decoded = decode( t1 ) ; 
-        assertTrue( decode( top ).equals( top ) ) ;
+        decoded = decode( t1, ByteBuffer.wrap( str1.getBytes() ) ) ; 
+        assertTrue( decode( top, EMPTY_BUFFER ).equals( top ) ) ;
     }
 
 
@@ -212,15 +225,15 @@
         decoder.setDecoderMonitor( new BERMonitor() ) ;
         decoder.setCallback( null ) ;
         String str0 = RandomStringUtils.randomAlphanumeric(20) ;
-        Tuple t0 = new Tuple( 2, str0.getBytes() ) ;
+        Tuple t0 = new Tuple( 2, str0.length() ) ;
         String str1 = RandomStringUtils.randomAlphanumeric(20) ;
-        Tuple t1 = new Tuple( 3, str1.getBytes() ) ;
+        Tuple t1 = new Tuple( 3, str1.length() ) ;
         Tuple top = new Tuple( 1, t0.size() + t1.size() ) ;
-        Tuple decoded = decode( t0 ) ; 
+        Tuple decoded = decode( t0, ByteBuffer.wrap( str0.getBytes() ) ) ; 
         
         // automatically set to top because after t1 is delivered top is 
-        decoded = decode( t1 ) ; 
-        assertTrue( decode( top ).equals( top ) ) ;
+        decoded = decode( t1, ByteBuffer.wrap( str1.getBytes() ) ) ; 
+        assertTrue( decode( top, EMPTY_BUFFER ).equals( top ) ) ;
     }
 
 
@@ -229,15 +242,15 @@
         decoder.setDecoderMonitor( null ) ;
         decoder.setCallback( null ) ;
         String str0 = RandomStringUtils.randomAlphanumeric(20) ;
-        Tuple t0 = new Tuple( 2, str0.getBytes() ) ;
+        Tuple t0 = new Tuple( 2, str0.length() ) ;
         String str1 = RandomStringUtils.randomAlphanumeric(20) ;
-        Tuple t1 = new Tuple( 3, str1.getBytes() ) ;
+        Tuple t1 = new Tuple( 3, str1.length() ) ;
         Tuple top = new Tuple( 1, t0.size() + t1.size() ) ;
-        Tuple decoded = decode( t0 ) ; 
+        Tuple decoded = decode( t0, ByteBuffer.wrap( str0.getBytes() ) ) ; 
         
         // automatically set to top because after t1 is delivered top is 
-        decoded = decode( t1 ) ; 
-        assertTrue( decode( top ).equals( top ) ) ;
+        decoded = decode( t1, ByteBuffer.wrap( str1.getBytes() ) ) ; 
+        assertTrue( decode( top, EMPTY_BUFFER ).equals( top ) ) ;
     }
 
 

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 21:20:01 2004
@@ -231,7 +231,6 @@
         t.value = ByteBuffer.wrap( bites ) ;
         assertEquals( ByteBuffer.wrap( bites ), t.getValue() ) ;
         byte[] bites2 = {1, 2, 3, 45} ;
-        assertFalse( bites2 == t.getValue() ) ;
         t.clear() ;
         assertEquals( EMPTY_BUFFER, t.getValue() ) ;
     }

Mime
View raw message