EMMA Coverage Report (generated Fri Oct 21 16:16:13 KST 2005)
[all classes][org.apache.mina.protocol.codec]

COVERAGE SUMMARY FOR SOURCE FILE [CumulativeProtocolDecoderTest.java]

nameclass, %method, %block, %line, %
CumulativeProtocolDecoderTest.java83%  (5/6)54%  (15/28)83%  (227/273)74%  (52/70)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CumulativeProtocolDecoderTest$10%   (0/1)100% (0/0)100% (0/0)100% (0/0)
     
class CumulativeProtocolDecoderTest$ProtocolSessionImpl100% (1/1)15%  (2/13)20%  (5/25)15%  (2/13)
close (boolean): void 0%   (0/1)0%   (0/1)0%   (0/1)
getConfig (): SessionConfig 0%   (0/1)0%   (0/2)0%   (0/1)
getDecoder (): ProtocolDecoder 0%   (0/1)0%   (0/2)0%   (0/1)
getEncoder (): ProtocolEncoder 0%   (0/1)0%   (0/2)0%   (0/1)
getFilterChain (): ProtocolFilterChain 0%   (0/1)0%   (0/2)0%   (0/1)
getHandler (): ProtocolHandler 0%   (0/1)0%   (0/2)0%   (0/1)
getLocalAddress (): SocketAddress 0%   (0/1)0%   (0/2)0%   (0/1)
getRemoteAddress (): SocketAddress 0%   (0/1)0%   (0/2)0%   (0/1)
getScheduledWriteRequests (): int 0%   (0/1)0%   (0/2)0%   (0/1)
isConnected (): boolean 0%   (0/1)0%   (0/2)0%   (0/1)
write (Object): void 0%   (0/1)0%   (0/1)0%   (0/1)
CumulativeProtocolDecoderTest$ProtocolSessionImpl (): void 100% (1/1)100% (3/3)100% (1/1)
getTransportType (): TransportType 100% (1/1)100% (2/2)100% (1/1)
     
class CumulativeProtocolDecoderTest$IntegerDecoderOutput100% (1/1)75%  (3/4)81%  (17/21)71%  (5/7)
clear (): void 0%   (0/1)0%   (0/4)0%   (0/2)
CumulativeProtocolDecoderTest$IntegerDecoderOutput (): void 100% (1/1)100% (8/8)100% (2/2)
getValues (): List 100% (1/1)100% (3/3)100% (1/1)
write (Object): void 100% (1/1)100% (6/6)100% (2/2)
     
class CumulativeProtocolDecoderTest100% (1/1)86%  (6/7)89%  (177/199)88%  (36/41)
main (String []): void 0%   (0/1)0%   (0/10)0%   (0/2)
testWrongImplementationDetection (): void 100% (1/1)14%  (2/14)40%  (2/5)
CumulativeProtocolDecoderTest (): void 100% (1/1)100% (9/9)100% (3/3)
setUp (): void 100% (1/1)100% (16/16)100% (4/4)
tearDown (): void 100% (1/1)100% (1/1)100% (1/1)
testCumulation (): void 100% (1/1)100% (87/87)100% (15/15)
testRepeatitiveDecode (): void 100% (1/1)100% (62/62)100% (11/11)
     
class CumulativeProtocolDecoderTest$IntegerDecoder100% (1/1)100% (2/2)100% (22/22)100% (7/7)
CumulativeProtocolDecoderTest$IntegerDecoder (): void 100% (1/1)100% (4/4)100% (2/2)
doDecode (ProtocolSession, ByteBuffer, ProtocolDecoderOutput): boolean 100% (1/1)100% (18/18)100% (5/5)
     
class CumulativeProtocolDecoderTest$WrongDecoder100% (1/1)100% (2/2)100% (6/6)100% (3/3)
CumulativeProtocolDecoderTest$WrongDecoder (): void 100% (1/1)100% (4/4)100% (2/2)
doDecode (ProtocolSession, ByteBuffer, ProtocolDecoderOutput): boolean 100% (1/1)100% (2/2)100% (1/1)

1/*
2 *   @(#) $Id: CumulativeProtocolDecoderTest.java 327113 2005-10-21 06:59:15Z trustin $
3 *
4 *   Copyright 2004 The Apache Software Foundation
5 *
6 *   Licensed under the Apache License, Version 2.0 (the "License");
7 *   you may not use this file except in compliance with the License.
8 *   You may obtain a copy of the License at
9 *
10 *       http://www.apache.org/licenses/LICENSE-2.0
11 *
12 *   Unless required by applicable law or agreed to in writing, software
13 *   distributed under the License is distributed on an "AS IS" BASIS,
14 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 *   See the License for the specific language governing permissions and
16 *   limitations under the License.
17 *
18 */
19package org.apache.mina.protocol.codec;
20 
21import java.net.SocketAddress;
22import java.util.ArrayList;
23import java.util.List;
24 
25import junit.framework.Assert;
26import junit.framework.TestCase;
27 
28import org.apache.mina.common.BaseSession;
29import org.apache.mina.common.ByteBuffer;
30import org.apache.mina.common.SessionConfig;
31import org.apache.mina.common.TransportType;
32import org.apache.mina.protocol.ProtocolDecoder;
33import org.apache.mina.protocol.ProtocolDecoderOutput;
34import org.apache.mina.protocol.ProtocolEncoder;
35import org.apache.mina.protocol.ProtocolHandler;
36import org.apache.mina.protocol.ProtocolFilterChain;
37import org.apache.mina.protocol.ProtocolSession;
38import org.apache.mina.protocol.ProtocolViolationException;
39 
40/**
41 * Tests {@link CumulativeProtocolDecoder}.
42 * 
43 * @author The Apache Directory Project (dev@directory.apache.org)
44 * @version $Rev: 327113 $, $Date: 2005-10-21 15:59:15 +0900 $ 
45 */
46public class CumulativeProtocolDecoderTest extends TestCase
47{
48    private final ProtocolSession session = new ProtocolSessionImpl();
49    private ByteBuffer buf;
50    private IntegerDecoder decoder;
51    private IntegerDecoderOutput output;
52 
53    public static void main(String[] args)
54    {
55        junit.textui.TestRunner.run(CumulativeProtocolDecoderTest.class);
56    }
57 
58    protected void setUp() throws Exception
59    {
60        buf = ByteBuffer.allocate( 16 );
61        decoder = new IntegerDecoder();
62        output = new IntegerDecoderOutput();
63    }
64 
65    protected void tearDown() throws Exception
66    {
67    }
68    
69    public void testCumulation() throws Exception
70    {
71        buf.put( (byte) 0 );
72        buf.flip();
73        
74        decoder.decode( session, buf, output );
75        Assert.assertEquals( 0, output.getValues().size() );
76        Assert.assertEquals( buf.limit(), buf.position() );
77        
78        buf.clear();
79        buf.put( (byte) 0 );
80        buf.put( (byte) 0 );
81        buf.put( (byte) 1 );
82        buf.flip();
83 
84        decoder.decode( session, buf, output );
85        Assert.assertEquals( 1, output.getValues().size() );
86        Assert.assertEquals( new Integer( 1 ), output.getValues().get( 0 ) );
87        Assert.assertEquals( buf.limit(), buf.position() );
88    }
89    
90    public void testRepeatitiveDecode() throws Exception
91    {
92        for( int i = 0; i < 4; i ++ )
93        {
94            buf.putInt( i );
95        }
96        buf.flip();
97        
98        decoder.decode( session, buf, output );
99        Assert.assertEquals( 4, output.getValues().size() );
100        Assert.assertEquals( buf.limit(), buf.position() );
101        
102        List expected = new ArrayList();
103        for( int i = 0; i < 4; i ++ )
104        {
105            expected.add( new Integer( i ) );
106        }
107        Assert.assertEquals( expected, output.getValues() );
108        
109    }
110    
111    public void testWrongImplementationDetection() throws Exception {
112        try
113        {
114            new WrongDecoder().decode( session, buf, output );
115            Assert.fail();
116        }
117        catch( IllegalStateException e )
118        {
119            // OK
120        }
121    }
122    
123    private static class IntegerDecoder extends CumulativeProtocolDecoder
124    {
125        protected IntegerDecoder()
126        {
127            super( 4 );
128        }
129 
130        protected boolean doDecode( ProtocolSession session, ByteBuffer in,
131                                    ProtocolDecoderOutput out ) throws ProtocolViolationException
132        {
133            Assert.assertTrue( in.hasRemaining() );
134            if( in.remaining() < 4 )
135                return false;
136            
137            out.write( new Integer( in.getInt() ) );
138            return true;
139        }
140        
141    }
142    
143    private static class IntegerDecoderOutput implements ProtocolDecoderOutput
144    {
145        private List values = new ArrayList();
146 
147        public void write( Object message )
148        {
149            values.add( message );
150        }
151        
152        public List getValues()
153        {
154            return values;
155        }
156        
157        public void clear()
158        {
159            values.clear();
160        }
161    }
162    
163    private static class WrongDecoder extends CumulativeProtocolDecoder
164    {
165        public WrongDecoder()
166        {
167            super( 4 );
168        }
169 
170        protected boolean doDecode( ProtocolSession session, ByteBuffer in,
171                                    ProtocolDecoderOutput out ) throws ProtocolViolationException {
172            return true;
173        }
174    }
175    
176    private static class ProtocolSessionImpl extends BaseSession implements ProtocolSession
177    {
178 
179        public ProtocolHandler getHandler() {
180            return null;
181        }
182 
183        public ProtocolEncoder getEncoder() {
184            return null;
185        }
186 
187        public ProtocolDecoder getDecoder() {
188            return null;
189        }
190 
191        public void close( boolean wait ) {
192        }
193 
194        public void write(Object message) {
195        }
196 
197        public int getScheduledWriteRequests()
198        {
199            return 0;
200        }
201 
202        public TransportType getTransportType() {
203            return TransportType.SOCKET;
204        }
205 
206        public boolean isConnected() {
207            return false;
208        }
209 
210        public SessionConfig getConfig() {
211            return null;
212        }
213 
214        public SocketAddress getRemoteAddress() {
215            return null;
216        }
217 
218        public SocketAddress getLocalAddress() {
219            return null;
220        }
221 
222        public ProtocolFilterChain getFilterChain()
223        {
224            return null;
225        }
226    }
227}

[all classes][org.apache.mina.protocol.codec]
EMMA 2.0.4217 (C) Vladimir Roubtsov