You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2004/03/10 05:08:46 UTC
svn commit: rev 9331 - in incubator/directory/snickers/trunk/ber/src: java/org/apache/snickers/ber test/org/apache/snickers/ber
Author: akarasulu
Date: Tue Mar 9 20:08:45 2004
New Revision: 9331
Added:
incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/MultiByteLengthTests.java
incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/SingleByteLengthTests.java
Modified:
incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoderState.java
Log:
Got the length part decode working.
Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoderState.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoderState.java (original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoderState.java Tue Mar 9 20:08:45 2004
@@ -58,7 +58,7 @@
new BERDecoderState( "TAG", TAG_VAL ) ;
/** enum for the LENGTH state */
public static final BERDecoderState LENGTH =
- new BERDecoderState( "LEGTH", LENGTH_VAL ) ;
+ new BERDecoderState( "LENGTH", LENGTH_VAL ) ;
/** enum for the VALUE state */
public static final BERDecoderState VALUE =
new BERDecoderState( "VALUE", VALUE_VAL ) ;
Added: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/MultiByteLengthTests.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/MultiByteLengthTests.java Tue Mar 9 20:08:45 2004
@@ -0,0 +1,146 @@
+/*
+ * 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 ;
+
+
+/**
+ * Tests single byte length encodings in a BER TLV.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class MultiByteLengthTests extends BERDecoderTest
+{
+ /**
+ * Creates a single byte lenth test case.
+ *
+ * @param name the name of this test
+ */
+ public MultiByteLengthTests( String name )
+ {
+ super( name ) ;
+ }
+
+
+ public void testLength128() throws Exception
+ {
+ 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() ) ;
+ assertEquals( 0, tlv.length ) ;
+
+ tlv = decode( "10000001" ) ;
+ assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
+ assertEquals( 0, tlv.length ) ;
+
+ tlv = decode( "10000000" ) ;
+ assertEquals( BERDecoderState.VALUE, decoder.getState() ) ;
+ assertEquals( 128, tlv.length ) ;
+ }
+
+
+ public void testLength129() throws Exception
+ {
+ 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() ) ;
+ assertEquals( 0, tlv.length ) ;
+
+ tlv = decode( "10000001" ) ;
+ assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
+ assertEquals( 0, tlv.length ) ;
+
+ tlv = decode( "10000001" ) ;
+ assertEquals( BERDecoderState.VALUE, decoder.getState() ) ;
+ assertEquals( 129, tlv.length ) ;
+ }
+
+
+ public void testLength255() throws Exception
+ {
+ 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() ) ;
+ assertEquals( 0, tlv.length ) ;
+
+ tlv = decode( "10000001" ) ;
+ assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
+ assertEquals( 0, tlv.length ) ;
+
+ tlv = decode( "11111111" ) ;
+ assertEquals( BERDecoderState.VALUE, decoder.getState() ) ;
+ assertEquals( 255, tlv.length ) ;
+ }
+
+
+ public void testLength32768() throws Exception
+ {
+ 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() ) ;
+ assertEquals( 0, tlv.length ) ;
+
+ tlv = decode( "10000010" ) ;
+ assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
+ assertEquals( 0, tlv.length ) ;
+
+ tlv = decode( "00000000" ) ;
+ assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
+ assertEquals( 0, tlv.length ) ;
+
+ tlv = decode( "10000000" ) ;
+ assertEquals( BERDecoderState.VALUE, decoder.getState() ) ;
+ assertEquals( 32768, tlv.length ) ;
+ }
+
+
+ public void testLength65535() throws Exception
+ {
+ 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() ) ;
+ assertEquals( 0, tlv.length ) ;
+
+ tlv = decode( "10000010" ) ;
+ assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
+ assertEquals( 0, tlv.length ) ;
+
+ tlv = decode( "11111111" ) ;
+ assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
+ assertEquals( 0, tlv.length ) ;
+
+ tlv = decode( "11111111" ) ;
+ assertEquals( BERDecoderState.VALUE, decoder.getState() ) ;
+ assertEquals( 65535, tlv.length ) ;
+ }
+}
\ No newline at end of file
Added: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/SingleByteLengthTests.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/SingleByteLengthTests.java Tue Mar 9 20:08:45 2004
@@ -0,0 +1,86 @@
+/*
+ * 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 ;
+
+
+/**
+ * Tests single byte length encodings in a BER TLV.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SingleByteLengthTests extends BERDecoderTest
+{
+ /**
+ * Creates a single byte lenth test case.
+ *
+ * @param name the name of this test
+ */
+ public SingleByteLengthTests( String name )
+ {
+ super( name ) ;
+ }
+
+
+ public void testLength0() throws Exception
+ {
+ Tuple tlv = decode( "00000000" + "01000001" ) ;
+ assertEquals( 1, tlv.id ) ;
+ assertEquals( 0, tlvList.size() ) ;
+ assertEquals( true, tlv.isPrimitive ) ;
+ assertEquals( TypeClass.APPLICATION, tlv.typeClass ) ;
+ assertEquals( BERDecoderState.VALUE, decoder.getState() ) ;
+ assertEquals( 0, tlv.length ) ;
+ }
+
+
+ public void testLength1() throws Exception
+ {
+ Tuple tlv = decode( "00000001" + "01000001" ) ;
+ assertEquals( 1, tlv.id ) ;
+ assertEquals( 0, tlvList.size() ) ;
+ assertEquals( true, tlv.isPrimitive ) ;
+ assertEquals( TypeClass.APPLICATION, tlv.typeClass ) ;
+ assertEquals( BERDecoderState.VALUE, decoder.getState() ) ;
+ assertEquals( 1, tlv.length ) ;
+ }
+
+
+ public void testLength3() throws Exception
+ {
+ Tuple tlv = decode( "00000011" + "01000001" ) ;
+ assertEquals( 1, tlv.id ) ;
+ assertEquals( 0, tlvList.size() ) ;
+ assertEquals( true, tlv.isPrimitive ) ;
+ assertEquals( TypeClass.APPLICATION, tlv.typeClass ) ;
+ assertEquals( BERDecoderState.VALUE, decoder.getState() ) ;
+ assertEquals( 3, tlv.length ) ;
+ }
+
+
+ public void testLength127() throws Exception
+ {
+ Tuple tlv = decode( "01111111" + "01000001" ) ;
+ assertEquals( 1, tlv.id ) ;
+ assertEquals( 0, tlvList.size() ) ;
+ assertEquals( true, tlv.isPrimitive ) ;
+ assertEquals( TypeClass.APPLICATION, tlv.typeClass ) ;
+ assertEquals( BERDecoderState.VALUE, decoder.getState() ) ;
+ assertEquals( 127, tlv.length ) ;
+ }
+}