org.apache.asn1.ber
Class AbstractDecoderTestCase

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byorg.apache.asn1.ber.AbstractDecoderTestCase
All Implemented Interfaces:
BERDecoderCallback, org.apache.asn1.codec.stateful.DecoderCallback, org.apache.asn1.codec.stateful.DecoderMonitor, junit.framework.Test

public abstract class AbstractDecoderTestCase
extends junit.framework.TestCase
implements BERDecoderCallback, org.apache.asn1.codec.stateful.DecoderMonitor

Tests the BER decoder.

Version:
$Rev: 158144 $
Author:
Apache Directory Project

Field Summary
(package private)  java.nio.ByteBuffer buf
          value accumulator
protected  BERDecoder decoder
          the decoder that is constructed every time
protected  java.util.ArrayList tlvList
          list of encountered TLV's as we recieve completed decode callbacks
 
Fields inherited from class junit.framework.TestCase
 
Constructor Summary
AbstractDecoderTestCase(java.lang.String arg0)
          Constructor for BERDecoderTest.
 
Method Summary
 void callbackOccured(org.apache.asn1.codec.stateful.StatefulDecoder decoder, org.apache.asn1.codec.stateful.DecoderCallback cb, java.lang.Object decoded)
           
 void callbackSet(org.apache.asn1.codec.stateful.StatefulDecoder decoder, org.apache.asn1.codec.stateful.DecoderCallback oldcb, org.apache.asn1.codec.stateful.DecoderCallback newcb)
           
 Tuple decode(byte bite)
          BER decodes a single byte.
 Tuple decode(byte[] pdu)
           
 Tuple decode(java.nio.ByteBuffer bites)
          BER decodes a byte buffer.
 Tuple decode(java.lang.String bitString)
          BER decodes a string of 0's and 1's.
 Tuple decode(Tuple[] tlvs, java.nio.ByteBuffer[] values)
          First BER encodes then BER decodes a train of Tuples.
 Tuple decode(Tuple tlv, java.nio.ByteBuffer value)
          First BER encodes then BER decodes a Tuple.
 void decodeOccurred(org.apache.asn1.codec.stateful.StatefulDecoder decoder, java.lang.Object decoded)
           
 void error(org.apache.asn1.codec.stateful.StatefulDecoder decoder, java.lang.Exception exception)
           
 void fatalError(org.apache.asn1.codec.stateful.StatefulDecoder decoder, java.lang.Exception exception)
           
 byte[][] fragment(byte[] bites, int size)
          Fragments an array of bytes into multiple arrays 'attempting' to keep them the same size however the last fragment will be an array bites.length%size which may or may not be of the requested fragment size.
 java.nio.ByteBuffer[] fragment(java.nio.ByteBuffer bites, int size)
          Fragments a byte buffer into multiple buffer 'attempting' to keep them the same size however the last fragment will be an array bites.length%size which may or may not be of the requested fragment size.
 void lengthDecoded(Tuple tlv)
          Method used to receive notification that a length was decoded.
 void monitorSet(org.apache.asn1.codec.stateful.StatefulDecoder decoder, org.apache.asn1.codec.stateful.DecoderMonitor oldmon)
           
 void partialValueDecoded(Tuple tlv)
          Method used to recieve notification that a part of the value was decoded.
protected  void setUp()
           
 void tagDecoded(Tuple tlv)
          Method used to receive notification that a tag was decoded.
protected  void tearDown()
           
 void warning(org.apache.asn1.codec.stateful.StatefulDecoder decoder, java.lang.Exception exception)
           
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

tlvList

protected java.util.ArrayList tlvList
list of encountered TLV's as we recieve completed decode callbacks


decoder

protected BERDecoder decoder
the decoder that is constructed every time


buf

java.nio.ByteBuffer buf
value accumulator

Constructor Detail

AbstractDecoderTestCase

public AbstractDecoderTestCase(java.lang.String arg0)
Constructor for BERDecoderTest.

Parameters:
arg0 -
Method Detail

setUp

protected void setUp()
              throws java.lang.Exception
Throws:
java.lang.Exception

tearDown

protected void tearDown()
                 throws java.lang.Exception
Throws:
java.lang.Exception

fragment

public byte[][] fragment(byte[] bites,
                         int size)
Fragments an array of bytes into multiple arrays 'attempting' to keep them the same size however the last fragment will be an array bites.length%size which may or may not be of the requested fragment size. However it will never be greater. Use this method to break appart TLV byte arrays to feed them into the decoder for testing.

Parameters:
bites - the bites to fragment
size - the maximum size of a fragment
Returns:
the array of byte[] fragments

fragment

public java.nio.ByteBuffer[] fragment(java.nio.ByteBuffer bites,
                                      int size)
Fragments a byte buffer into multiple buffer 'attempting' to keep them the same size however the last fragment will be an array bites.length%size which may or may not be of the requested fragment size. However it will never be greater. Use this method to break appart TLV bytes to feed them into the decoder for testing.

Parameters:
bites - the bites to fragment
size - the maximum size of a fragment
Returns:
the buffer fragment

decode

public Tuple decode(java.lang.String bitString)
             throws org.apache.asn1.codec.DecoderException
BER decodes a string of 0's and 1's.

Parameters:
bitString - a string of ascii 0's and 1's
Returns:
a copy of the decoded tuple or the partially decoded current tlv
Throws:
org.apache.asn1.codec.DecoderException - if there are errors while decoding.

decode

public Tuple decode(byte bite)
             throws org.apache.asn1.codec.DecoderException
BER decodes a single byte.

Parameters:
bite - a single byte to decode
Returns:
a copy of the decoded tuple or the partially decoded current tlv
Throws:
org.apache.asn1.codec.DecoderException - if there are errors while decoding.

decode

public Tuple decode(java.nio.ByteBuffer bites)
             throws org.apache.asn1.codec.DecoderException
BER decodes a byte buffer.

Parameters:
bites - a byte buffer to decode
Returns:
a copy of the decoded tuple or the partially decoded current tlv
Throws:
org.apache.asn1.codec.DecoderException - if there are errors while decoding.

decode

public Tuple decode(Tuple tlv,
                    java.nio.ByteBuffer value)
             throws org.apache.asn1.codec.DecoderException
First BER encodes then BER decodes a Tuple.

Parameters:
tlv - a tuple to encode then decode
Returns:
a copy of the decoded tuple or the partially decoded current tlv
Throws:
org.apache.asn1.codec.DecoderException - if there are errors while decoding

decode

public Tuple decode(Tuple[] tlvs,
                    java.nio.ByteBuffer[] values)
             throws org.apache.asn1.codec.DecoderException
First BER encodes then BER decodes a train of Tuples.

Parameters:
tlvs - a tuple array to encode then decode
Returns:
a copy of the decoded tuple or the partially decoded current tlv
Throws:
org.apache.asn1.codec.DecoderException - if there are errors while decoding

decode

public Tuple decode(byte[] pdu)
             throws org.apache.asn1.codec.DecoderException
Throws:
org.apache.asn1.codec.DecoderException

tagDecoded

public void tagDecoded(Tuple tlv)
Description copied from interface: BERDecoderCallback
Method used to receive notification that a tag was decoded. The following tag properties of the TLV tuple are valid at this point:

Specified by:
tagDecoded in interface BERDecoderCallback
Parameters:
tlv - the TLV tuple

lengthDecoded

public void lengthDecoded(Tuple tlv)
Description copied from interface: BERDecoderCallback
Method used to receive notification that a length was decoded. The following properties of the TLV tuple are valid at this point:

Specified by:
lengthDecoded in interface BERDecoderCallback
Parameters:
tlv - the TLV tuple

partialValueDecoded

public void partialValueDecoded(Tuple tlv)
Description copied from interface: BERDecoderCallback
Method used to recieve notification that a part of the value was decoded.

Specified by:
partialValueDecoded in interface BERDecoderCallback
Parameters:
tlv - the TLV tuple

decodeOccurred

public void decodeOccurred(org.apache.asn1.codec.stateful.StatefulDecoder decoder,
                           java.lang.Object decoded)
Specified by:
decodeOccurred in interface org.apache.asn1.codec.stateful.DecoderCallback

callbackOccured

public void callbackOccured(org.apache.asn1.codec.stateful.StatefulDecoder decoder,
                            org.apache.asn1.codec.stateful.DecoderCallback cb,
                            java.lang.Object decoded)
Specified by:
callbackOccured in interface org.apache.asn1.codec.stateful.DecoderMonitor

callbackSet

public void callbackSet(org.apache.asn1.codec.stateful.StatefulDecoder decoder,
                        org.apache.asn1.codec.stateful.DecoderCallback oldcb,
                        org.apache.asn1.codec.stateful.DecoderCallback newcb)
Specified by:
callbackSet in interface org.apache.asn1.codec.stateful.DecoderMonitor

error

public void error(org.apache.asn1.codec.stateful.StatefulDecoder decoder,
                  java.lang.Exception exception)
Specified by:
error in interface org.apache.asn1.codec.stateful.DecoderMonitor

fatalError

public void fatalError(org.apache.asn1.codec.stateful.StatefulDecoder decoder,
                       java.lang.Exception exception)
Specified by:
fatalError in interface org.apache.asn1.codec.stateful.DecoderMonitor

monitorSet

public void monitorSet(org.apache.asn1.codec.stateful.StatefulDecoder decoder,
                       org.apache.asn1.codec.stateful.DecoderMonitor oldmon)

warning

public void warning(org.apache.asn1.codec.stateful.StatefulDecoder decoder,
                    java.lang.Exception exception)
Specified by:
warning in interface org.apache.asn1.codec.stateful.DecoderMonitor


Copyright © 2004-2006 . All Rights Reserved.