1 26 27 package net.sourceforge.groboutils.codecoverage.v2.util; 28 29 import java.util.zip.CRC32 ; 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 44 public class HexUtilUTest extends TestCase 45 { 46 49 private static final Class THIS_CLASS = HexUtilUTest.class; 50 private static final AutoDoc DOC = new AutoDoc( THIS_CLASS ); 51 52 public HexUtilUTest( String name ) 53 { 54 super( name ); 55 } 56 57 58 59 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 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 [] args ) 205 { 206 String [] name = { THIS_CLASS.getName() }; 207 208 211 junit.textui.TestRunner.main( name ); 212 } 213 214 215 219 protected void setUp() throws Exception 220 { 221 super.setUp(); 222 223 } 225 226 227 231 protected void tearDown() throws Exception 232 { 233 235 236 super.tearDown(); 237 } 238 } 239 240 | Popular Tags |