KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > codecoverage > v2 > util > HexUtilUTest


1 /*
2  * @(#)HexUtilUTest.java
3  *
4  * Copyright (C) 2004 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  */

26
27 package net.sourceforge.groboutils.codecoverage.v2.util;
28
29 import java.util.zip.CRC32 JavaDoc;
30
31 import junit.framework.Test;
32 import junit.framework.TestCase;
33 import junit.framework.TestSuite;
34 import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
35
36
37 /**
38  * Tests the ChecksumUtil class.
39  *
40  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
41  * @version $Date: 2004/07/07 09:39:14 $
42  * @since July 7, 2004
43  */

44 public class HexUtilUTest extends TestCase
45 {
46     //-------------------------------------------------------------------------
47
// Standard JUnit Class-specific declarations
48

49     private static final Class JavaDoc THIS_CLASS = HexUtilUTest.class;
50     private static final AutoDoc DOC = new AutoDoc( THIS_CLASS );
51     
52     public HexUtilUTest( String JavaDoc name )
53     {
54         super( name );
55     }
56
57
58
59     //-------------------------------------------------------------------------
60
// Tests
61

62     public void testGetInstance()
63     {
64         assertNotNull(
65             "getInstance must never return null.",
66             HexUtil.getInstance() );
67     }
68     
69     
70     public void testParseTwoHex1()
71     {
72         assertFalse(
73             "Null TS",
74             HexUtil.getInstance().parseTwoHex( "a a", null, ' ', 0 ) );
75     }
76     
77     
78     public void testParseTwoHex2()
79     {
80         HexUtil.TwoShorts ts = new HexUtil.TwoShorts();
81         assertFalse(
82             "Null string",
83             HexUtil.getInstance().parseTwoHex( null, ts, ' ', 0 ));
84     }
85     
86     
87     public void testParseTwoHex3()
88     {
89         HexUtil.TwoShorts ts = new HexUtil.TwoShorts();
90         assertFalse(
91             "Negative start",
92             HexUtil.getInstance().parseTwoHex( "a a", ts, ' ', -1 ) );
93     }
94     
95     
96     public void testParseTwoHex4()
97     {
98         HexUtil.TwoShorts ts = new HexUtil.TwoShorts();
99         assertFalse(
100             "No separator",
101             HexUtil.getInstance().parseTwoHex( "a", ts, ' ', 0 ) );
102     }
103     
104     
105     public void testParseTwoHex5()
106     {
107         HexUtil.TwoShorts ts = new HexUtil.TwoShorts();
108         assertFalse(
109             "No separator after start",
110             HexUtil.getInstance().parseTwoHex( "a a", ts, ' ', 2 ) );
111     }
112     
113     
114     public void testParseTwoHex6()
115     {
116         HexUtil.TwoShorts ts = new HexUtil.TwoShorts();
117         assertFalse(
118             "Start is after string length",
119             HexUtil.getInstance().parseTwoHex( "x x", ts, ' ', 12 ) );
120     }
121     
122     
123     public void testParseTwoHex7()
124     {
125         HexUtil.TwoShorts ts = new HexUtil.TwoShorts();
126         assertTrue(
127             "Should have parsed correctly",
128             HexUtil.getInstance().parseTwoHex( "0AAA F", ts, ' ', 0 ) );
129         assertEquals(
130             "Bad first string translate",
131             0x0AAA,
132             ts.a );
133         assertEquals(
134             "Bad second string translate",
135             0xF,
136             ts.b );
137     }
138     
139     
140     public void testParseTwoHex8()
141     {
142         HexUtil.TwoShorts ts = new HexUtil.TwoShorts();
143         assertTrue(
144             "Should have parsed correctly",
145             HexUtil.getInstance().parseTwoHex( " 0BB 12", ts, ' ', 1 ) );
146         assertEquals(
147             "Bad first string translate",
148             0x0BB,
149             ts.a );
150         assertEquals(
151             "Bad second string translate",
152             0x12,
153             ts.b );
154     }
155     
156     
157     public void testParseTwoHex9()
158     {
159         HexUtil.TwoShorts ts = new HexUtil.TwoShorts();
160         assertTrue(
161             "Should have parsed correctly",
162             HexUtil.getInstance().parseTwoHex( "1 2 ", ts, ' ', 0 ) );
163         assertEquals(
164             "Bad first string translate",
165             0x1,
166             ts.a );
167         assertEquals(
168             "Bad second string translate",
169             0x2,
170             ts.b );
171     }
172     
173     
174     public void testParseTwoHex10()
175     {
176         HexUtil.TwoShorts ts = new HexUtil.TwoShorts();
177         ts.a = ts.b = -1;
178         assertTrue(
179             "Should have parsed correctly",
180             HexUtil.getInstance().parseTwoHex( "0 0", ts, ' ', 0 ) );
181         assertEquals(
182             "Bad first string translate",
183             0x0,
184             ts.a );
185         assertEquals(
186             "Bad second string translate",
187             0x0,
188             ts.b );
189     }
190     
191     
192     
193     //-------------------------------------------------------------------------
194
// Standard JUnit declarations
195

196     
197     public static Test suite()
198     {
199         TestSuite suite = new TestSuite( THIS_CLASS );
200         
201         return suite;
202     }
203     
204     public static void main( String JavaDoc[] args )
205     {
206         String JavaDoc[] name = { THIS_CLASS.getName() };
207         
208         // junit.textui.TestRunner.main( name );
209
// junit.swingui.TestRunner.main( name );
210

211         junit.textui.TestRunner.main( name );
212     }
213     
214     
215     /**
216      *
217      * @exception Exception thrown under any exceptional condition.
218      */

219     protected void setUp() throws Exception JavaDoc
220     {
221         super.setUp();
222         
223         // set ourself up
224
}
225     
226     
227     /**
228      *
229      * @exception Exception thrown under any exceptional condition.
230      */

231     protected void tearDown() throws Exception JavaDoc
232     {
233         // tear ourself down
234

235         
236         super.tearDown();
237     }
238 }
239
240
Popular Tags