1   /*
2    *   Copyright 2004 The Apache Software Foundation
3    *
4    *   Licensed under the Apache License, Version 2.0 (the "License");
5    *   you may not use this file except in compliance with the License.
6    *   You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *   Unless required by applicable law or agreed to in writing, software
11   *   distributed under the License is distributed on an "AS IS" BASIS,
12   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *   See the License for the specific language governing permissions and
14   *   limitations under the License.
15   *
16   */
17  package org.apache.asn1.ber ;
18  
19  
20  import org.apache.asn1.ber.AbstractDecoderTestCase;
21  import org.apache.asn1.ber.BERDecoderState;
22  
23  
24  /***
25   * Tests single byte length encodings in a BER TLV.
26   *
27   * @author <a href="mailto:dev@directory.apache.org">
28   * Apache Directory Project</a>
29   * @version $Rev: 157644 $
30   */
31  public class SingleByteLengthTests extends AbstractDecoderTestCase
32  {
33      /***
34       * Creates a single byte lenth test case.
35       * 
36       * @param name the name of this test
37       */
38      public SingleByteLengthTests( String name )
39      {
40          super( name ) ;
41      }
42  
43      
44      public void testLength0() throws Exception
45      {
46          Tuple tlv = decode( "00000000" + "01000001" ) ;
47          assertEquals( 1, tlv.id ) ;
48          assertEquals( 1, tlvList.size() ) ;
49          assertEquals( true, tlv.isPrimitive ) ;
50          assertEquals( TypeClass.APPLICATION, tlv.typeClass ) ;
51          assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
52          assertEquals( 0, tlv.length ) ;
53      }
54  
55  
56      public void testLength1() throws Exception
57      {
58          Tuple tlv = decode( "00000001" + "01000001" ) ;
59          assertEquals( 1, tlv.id ) ;
60          assertEquals( 0, tlvList.size() ) ;
61          assertEquals( true, tlv.isPrimitive ) ;
62          assertEquals( TypeClass.APPLICATION, tlv.typeClass ) ;
63          assertEquals( BERDecoderState.VALUE, decoder.getState() ) ;
64          assertEquals( 1, tlv.length ) ;
65      }
66  
67  
68      public void testLength3() throws Exception
69      {
70          Tuple tlv = decode( "00000011" + "01000001" ) ;
71          assertEquals( 1, tlv.id ) ;
72          assertEquals( 0, tlvList.size() ) ;
73          assertEquals( true, tlv.isPrimitive ) ;
74          assertEquals( TypeClass.APPLICATION, tlv.typeClass ) ;
75          assertEquals( BERDecoderState.VALUE, decoder.getState() ) ;
76          assertEquals( 3, tlv.length ) ;
77      }
78  
79  
80      public void testLength127() throws Exception
81      {
82          Tuple tlv = decode( "01111111" + "01000001" ) ;
83          assertEquals( 1, tlv.id ) ;
84          assertEquals( 0, tlvList.size() ) ;
85          assertEquals( true, tlv.isPrimitive ) ;
86          assertEquals( TypeClass.APPLICATION, tlv.typeClass ) ;
87          assertEquals( BERDecoderState.VALUE, decoder.getState() ) ;
88          assertEquals( 127, tlv.length ) ;
89      }
90  }