EMMA Coverage Report (generated Mon Jul 11 13:15:38 KST 2005)
[all classes][org.apache.mina.examples.echoserver]

COVERAGE SUMMARY FOR SOURCE FILE [AbstractTest.java]

nameclass, %method, %block, %line, %
AbstractTest.java100% (1/1)100% (7/7)78%  (127/162)84%  (29.5/35)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AbstractTest100% (1/1)100% (7/7)78%  (127/162)84%  (29.5/35)
setUp (): void 100% (1/1)68%  (76/111)74%  (15.5/21)
AbstractTest (): void 100% (1/1)100% (3/3)100% (2/2)
assertEquals (ByteBuffer, ByteBuffer): void 100% (1/1)100% (6/6)100% (2/2)
assertEquals (byte [], byte []): void 100% (1/1)100% (6/6)100% (2/2)
tearDown (): void 100% (1/1)100% (4/4)100% (2/2)
toString (ByteBuffer): String 100% (1/1)100% (3/3)100% (1/1)
toString (byte []): String 100% (1/1)100% (29/29)100% (5/5)

1/*
2 *   @(#) $Id: AbstractTest.java 210062 2005-07-11 03:52:38Z 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.examples.echoserver;
20 
21import java.io.IOException;
22 
23import junit.framework.TestCase;
24 
25import org.apache.mina.common.ByteBuffer;
26import org.apache.mina.common.TransportType;
27import org.apache.mina.registry.Service;
28import org.apache.mina.registry.ServiceRegistry;
29import org.apache.mina.registry.SimpleServiceRegistry;
30 
31/**
32 * Tests echo server example.
33 * 
34 * @author Trustin Lee (trustin@apache.org)
35 * @version $Rev: 210062 $, $Date: 2005-07-11 12:52:38 +0900 $
36 */
37public class AbstractTest extends TestCase
38{
39    protected int port;
40 
41    protected ServiceRegistry registry;
42    
43    protected AbstractTest()
44    {
45    }
46 
47    protected static void assertEquals( byte[] expected, byte[] actual )
48    {
49        assertEquals( toString( expected ), toString( actual ) );
50    }
51 
52    protected static void assertEquals( ByteBuffer expected, ByteBuffer actual )
53    {
54        assertEquals( toString( expected ), toString( actual ) );
55    }
56 
57    protected static String toString( byte[] buf )
58    {
59        StringBuffer str = new StringBuffer( buf.length * 4 );
60        for( int i = 0; i < buf.length; i ++ )
61        {
62            str.append( buf[ i ] );
63            str.append( ' ' );
64        }
65        return str.toString();
66    }
67    
68    protected static String toString( ByteBuffer buf )
69    {
70        return buf.getHexDump();
71    }
72 
73    protected void setUp() throws Exception
74    {
75        registry = new SimpleServiceRegistry();
76        
77        // Find an availble test port and bind to it.
78        boolean socketBound = false;
79        boolean datagramBound = false;
80 
81        // Let's start from port #1 to detect possible resource leak
82        // because test will fail in port 1-1023 if user run this test
83        // as a normal user.
84        for( port = 1; port <= 65535; port ++ )
85        {
86            socketBound = false;
87            datagramBound = false;
88            
89            Service socketService = new Service( "echo", TransportType.SOCKET, port );
90            Service datagramService = new Service( "echo", TransportType.DATAGRAM, port );
91            
92            try
93            {
94                registry.bind( socketService, new EchoProtocolHandler() );
95                socketBound = true;
96 
97                registry.bind( datagramService, new EchoProtocolHandler() );
98                datagramBound = true;
99 
100                break;
101            }
102            catch( IOException e )
103            {
104            }
105            finally
106            {
107                if( !socketBound || !datagramBound )
108                {
109                    registry.unbindAll();
110                }
111            }
112        }
113 
114        // If there is no port available, test fails.
115        if( !socketBound || !datagramBound )
116        {
117            throw new IOException( "Cannot bind any test port." );
118        }
119 
120        System.out.println( "Using port " + port + " for testing." );
121    }
122 
123    protected void tearDown() throws Exception
124    {
125        registry.unbindAll();
126    }
127}

[all classes][org.apache.mina.examples.echoserver]
EMMA 2.0.4217 (C) Vladimir Roubtsov