directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 9334 - in incubator/directory/snickers/trunk/ber/src: java/org/apache/snickers/ber test/org/apache/snickers/ber
Date Wed, 10 Mar 2004 05:26:33 GMT
Author: akarasulu
Date: Tue Mar  9 21:26:32 2004
New Revision: 9334

Added:
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/SimplePrimitiveTLVTests.java
Modified:
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoder.java
Log:
Added tests for trains of whole tlv's for simple primitives


Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoder.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoder.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoder.java
Tue Mar  9 21:26:32 2004
@@ -241,6 +241,7 @@
                 {
                     lengthOfLength = 0 ;
                     tlv.length = octet ;
+                    lengthBuffer.clear() ;
                     tlv.valueIndex = UNDEFINED ;
                     cb.lengthDecoded( tlv ) ;
 
@@ -281,6 +282,7 @@
                 lengthOfLength = 0 ;
                 tlv.length = BERUtils.getLength( lengthBuffer ) ;
                 tlv.valueIndex = UNDEFINED ;
+                lengthBuffer.clear() ;
                 cb.lengthDecoded( tlv ) ;
                 
                 if ( tlv.isPrimitive )

Added: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/SimplePrimitiveTLVTests.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/SimplePrimitiveTLVTests.java
Tue Mar  9 21:26:32 2004
@@ -0,0 +1,162 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.snickers.ber ;
+
+
+/**
+ * Performs simple primitive tlv tests.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SimplePrimitiveTLVTests extends BERDecoderTest
+{
+
+    /**
+     * @param arg0
+     */
+    public SimplePrimitiveTLVTests( String arg0 )
+    {
+        super( arg0 ) ;
+    }
+    
+    
+    public void testSingleSimpleTLV() throws Exception
+    {
+        // decode tag
+        Tuple tlv = decode( "01000001" ) ;
+        assertEquals( 1, tlv.id ) ;
+        assertEquals( 0, tlvList.size() ) ;
+        assertEquals( true, tlv.isPrimitive ) ;
+        assertEquals( TypeClass.APPLICATION, tlv.typeClass ) ;
+        assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
+        
+        // decode length 
+        tlv = decode( "00000001" ) ;
+        assertEquals( BERDecoderState.VALUE, decoder.getState() ) ;
+        assertEquals( 1, tlv.length ) ;
+        
+        // decode value
+        tlv = decode( "01010101" ) ;
+        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
+        assertEquals( 1, tlvList.size() ) ;
+        assertNotNull( tlv.value ) ;
+        assertEquals( 0x0055, 0x00ff & ( int ) ( (byte[]) tlv.value)[0] ) ;
+    }
+
+
+    public void testMultipleSimpleTLV() throws Exception
+    {
+        // decode tag
+        Tuple tlv = decode( "01000001" ) ;
+        assertEquals( 1, tlv.id ) ;
+        assertEquals( 0, tlvList.size() ) ;
+        assertEquals( true, tlv.isPrimitive ) ;
+        assertEquals( TypeClass.APPLICATION, tlv.typeClass ) ;
+        assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
+        
+        // decode length 
+        tlv = decode( "00000001" ) ;
+        assertEquals( BERDecoderState.VALUE, decoder.getState() ) ;
+        assertEquals( 1, tlv.length ) ;
+        
+        // decode value
+        tlv = decode( "01010101" ) ;
+        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
+        assertEquals( 1, tlvList.size() ) ;
+        assertNotNull( tlv.value ) ;
+        assertEquals( 0x0055, 0x00ff & ( int ) ( (byte[]) tlv.value)[0] ) ;
+
+    
+        // decode tag
+        tlv = decode( "01000001" ) ;
+        assertEquals( 1, tlv.id ) ;
+        assertEquals( 1, tlvList.size() ) ;
+        assertEquals( true, tlv.isPrimitive ) ;
+        assertEquals( TypeClass.APPLICATION, tlv.typeClass ) ;
+        assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
+        
+        // decode length 
+        tlv = decode( "00000001" ) ;
+        assertEquals( BERDecoderState.VALUE, decoder.getState() ) ;
+        assertEquals( 1, tlv.length ) ;
+        
+        // decode value
+        tlv = decode( "01010101" ) ;
+        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
+        assertEquals( 2, tlvList.size() ) ;
+        assertNotNull( tlv.value ) ;
+        assertEquals( 0x0055, 0x00ff & ( int ) ( (byte[]) tlv.value)[0] ) ;
+
+    
+        // decode tag
+        tlv = decode( "01000001" ) ;
+        assertEquals( 1, tlv.id ) ;
+        assertEquals( 2, tlvList.size() ) ;
+        assertEquals( true, tlv.isPrimitive ) ;
+        assertEquals( TypeClass.APPLICATION, tlv.typeClass ) ;
+        assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
+        
+        // decode length 
+        tlv = decode( "00000001" ) ;
+        assertEquals( BERDecoderState.VALUE, decoder.getState() ) ;
+        assertEquals( 1, tlv.length ) ;
+        
+        // decode value
+        tlv = decode( "01010101" ) ;
+        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
+        assertEquals( 3, tlvList.size() ) ;
+        assertNotNull( tlv.value ) ;
+        assertEquals( 0x0055, 0x00ff & ( int ) ( (byte[]) tlv.value)[0] ) ;
+    }
+
+
+    public void testSingleSimpleLongTLV() throws Exception
+    {
+        // decode tag
+        Tuple tlv = decode( "01000001" ) ;
+        assertEquals( 1, tlv.id ) ;
+        assertEquals( 0, tlvList.size() ) ;
+        assertEquals( true, tlv.isPrimitive ) ;
+        assertEquals( TypeClass.APPLICATION, tlv.typeClass ) ;
+        assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
+        
+        // decode length 
+        tlv = decode( "10000001" ) ;
+        assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
+        assertEquals( 0, tlv.length ) ;
+        
+        tlv = decode( "00000111" ) ;
+        assertEquals( BERDecoderState.VALUE, decoder.getState() ) ;
+        assertEquals( 7, tlv.length ) ;
+        
+        // decode value
+        tlv = decode( "01010101" + "01010101" + "01010101" + "01010101"
+                + "01010101" + "01010101" + "01010101" ) ;
+        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
+        assertEquals( 1, tlvList.size() ) ;
+        assertNotNull( tlv.value ) ;
+        assertEquals( 7, ((byte[]) tlv.value).length) ;
+        
+        byte[] value = (byte[]) tlv.value ;
+        for ( int ii = 0 ; ii < 7; ii++ )
+        {    
+            assertEquals( 0x0055, 0x00ff & ( int ) value[ii] ) ;
+        }
+    }
+}

Mime
View raw message