1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.asn1.ber ;
18
19
20 import java.nio.ByteBuffer;
21
22 import org.apache.commons.lang.ArrayUtils ;
23 import org.apache.asn1.ber.AbstractDecoderTestCase;
24
25
26 /***
27 * Tests the base test class functions.
28 *
29 * @author <a href="mailto:dev@directory.apache.org">
30 * Apache Directory Project</a>
31 * @version $Rev: 157644 $
32 */
33 public class AbstractDecoderTestCaseTest extends AbstractDecoderTestCase
34 {
35
36 public AbstractDecoderTestCaseTest()
37 {
38 super ( AbstractDecoderTestCaseTest.class.getName() ) ;
39 }
40
41 public void testFragment()
42 {
43 byte[] all = new byte[3] ;
44 assertEquals( 1, fragment(all, 3).length) ;
45 try
46 {
47 fragment(ArrayUtils.EMPTY_BYTE_ARRAY, 0) ;
48 fail( "should have thrown exception before reaching this line" ) ;
49 }
50 catch( IllegalArgumentException e )
51 {
52 assertNotNull( e ) ;
53 }
54 }
55
56
57
58
59 public void testDecodebyte() throws Exception
60 {
61 decode( ( byte ) 1 ) ;
62 decode( ( byte ) 1 ) ;
63 Tuple t = decode( ( byte ) 1 ) ;
64 assertEquals( 1, t.id ) ;
65 assertEquals( 1, t.length ) ;
66 }
67
68
69
70
71 public void testDecodeTupleArray() throws Exception
72 {
73 Tuple [] tuples = new Tuple[2] ;
74 tuples[0] = new Tuple( 1, 0 ) ;
75 tuples[1] = new Tuple( 1, 0 ) ;
76
77 ByteBuffer[] buffers = new ByteBuffer[2] ;
78 buffers[0] = ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ;
79 buffers[1] = ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ;
80 decode( tuples, buffers ) ;
81 decode( tuples[0], ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ) ;
82 }
83
84 public void testCallbackOccured() throws Exception
85 {
86 decoder.setDecoderMonitor( this ) ;
87 Tuple [] tuples = new Tuple[2] ;
88 tuples[0] = new Tuple(1, 0) ;
89 tuples[1] = new Tuple(1, 0) ;
90 ByteBuffer[] buffers = new ByteBuffer[2] ;
91 buffers[0] = ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ;
92 buffers[1] = ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ;
93 decode(tuples, buffers) ;
94 callbackOccured(decoder, this, tuples[1]) ;
95 }
96
97 public void testCallbackSet()
98 {
99 decoder.setCallback(this) ;
100 callbackSet(decoder, this, this) ;
101 }
102
103 public void testError()
104 {
105 try
106 {
107 error( decoder, new Exception() ) ;
108 fail("should not get here") ;
109 }
110 catch ( Throwable e )
111 {
112 assertNotNull( e ) ;
113 }
114 }
115
116 public void testFatalError()
117 {
118 try
119 {
120 fatalError( decoder, new Exception() ) ;
121 fail("should not get here") ;
122 }
123 catch ( Throwable e )
124 {
125 assertNotNull( e ) ;
126 }
127 }
128
129 public void testMonitorSet()
130 {
131 monitorSet( decoder, this ) ;
132 }
133
134 public void testWarning()
135 {
136 try
137 {
138 warning( decoder, new Exception() ) ;
139 fail("should not get here") ;
140 }
141 catch ( Throwable e )
142 {
143 assertNotNull( e ) ;
144 }
145 }
146 }