1 26 27 package net.sourceforge.groboutils.codecoverage.v2.compiler; 28 29 import junit.framework.Test; 30 import junit.framework.TestCase; 31 import junit.framework.TestSuite; 32 import net.sourceforge.groboutils.autodoc.v1.AutoDoc; 33 import net.sourceforge.groboutils.codecoverage.v2.BCELCreatorUtil; 34 35 import org.apache.bcel.generic.InstructionHandle; 36 import org.apache.bcel.generic.InstructionList; 37 38 39 46 public class MarkedInstructionUTest extends TestCase 47 { 48 51 private static final Class THIS_CLASS = MarkedInstructionUTest.class; 52 private static final AutoDoc DOC = new AutoDoc( THIS_CLASS ); 53 54 public MarkedInstructionUTest( String name ) 55 { 56 super( name ); 57 } 58 59 60 63 private static final int MARK_INSTRUCTION_COUNT = 5; 64 65 66 public void testConstructor1() 67 { 68 try 69 { 70 new MarkedInstruction( (short)0, 0, 0, null ); 71 fail( "Did not throw IllegalArgumentException." ); 72 } 73 catch (IllegalArgumentException e) 74 { 75 } 77 } 78 79 80 public void testGetInstruction1() 81 { 82 InstructionHandle ih = createInstructionHandle(); 83 MarkedInstruction mi = new MarkedInstruction( 84 (short)0, 0, 0, ih ); 85 assertEquals( 86 "Did not return expected instruction.", 87 ih.getInstruction(), 88 mi.getHandle().getInstruction() ); 89 } 90 91 92 public void testAddMark1() 93 { 94 InstructionHandle ih = createInstructionHandle(); 95 MarkedInstruction mi = new MarkedInstruction( 96 (short)0, 0, 0, ih ); 97 mi.addMark( (short)1, Short.MIN_VALUE ); 98 } 99 100 101 public void testAddMark2() 102 { 103 InstructionHandle ih = createInstructionHandle(); 104 MarkedInstruction mi = new MarkedInstruction( 105 (short)0, 0, 0, ih ); 106 mi.addMark( Short.MIN_VALUE, (short)1 ); 107 } 108 109 110 public void testAddMark3() 111 { 112 InstructionHandle ih = createInstructionHandle(); 113 MarkedInstruction mi = new MarkedInstruction( 114 (short)0, 0, 0, ih ); 115 mi.addMark( (short)1, Short.MAX_VALUE ); 116 } 117 118 119 public void testAddMark4() 120 { 121 InstructionHandle ih = createInstructionHandle(); 122 MarkedInstruction mi = new MarkedInstruction( 123 (short)0, 0, 0, ih ); 124 mi.addMark( Short.MAX_VALUE, (short)1 ); 125 } 126 127 128 public void testGetMarkedList1() 129 { 130 InstructionHandle ih = createInstructionHandle(); 131 MarkedInstruction mi = new MarkedInstruction( 132 (short)0, 0, 0, ih ); 133 InstructionList il = mi.getMarkedList(); 134 assertNull( 135 "Did not return a null marked list.", 136 il ); 137 } 138 139 140 public void testGetMarkedList2() 141 { 142 InstructionHandle ih = createInstructionHandle(); 143 MarkedInstruction mi = new MarkedInstruction( 144 (short)0, 0, 0, ih ); 145 mi.addMark( (short)1, (short)1 ); 146 InstructionList il = mi.getMarkedList(); 147 assertEquals( 148 "Did not return a marked list of the expected size.", 149 MARK_INSTRUCTION_COUNT, 150 il.size() ); 151 } 152 153 154 public void testGetMarkedList3() 155 { 156 InstructionHandle ih = createInstructionHandle(); 157 MarkedInstruction mi = new MarkedInstruction( 158 (short)0, 0, 0, ih ); 159 mi.addMark( (short)1, (short)1 ); 160 mi.addMark( (short)1, (short)1 ); 161 mi.addMark( (short)1, (short)1 ); 162 InstructionList il = mi.getMarkedList(); 163 assertEquals( 164 "Did not return a marked list of the expected size.", 165 MARK_INSTRUCTION_COUNT*3, 166 il.size() ); 167 } 168 169 170 public void testGetMarkedList_state1() 171 { 172 InstructionHandle ih = createInstructionHandle(); 173 MarkedInstruction mi = new MarkedInstruction( 174 (short)0, 0, 0, ih ); 175 mi.getMarkedList(); 176 177 InstructionList il = mi.getMarkedList(); 179 assertNull( 180 "Did not return a null marked list.", 181 il ); 182 } 183 184 185 public void testGetMarkedList_state2() 186 { 187 InstructionHandle ih = createInstructionHandle(); 188 MarkedInstruction mi = new MarkedInstruction( 189 (short)0, 0, 0, ih ); 190 mi.addMark( (short)1, (short)1 ); 191 mi.addMark( (short)1, (short)1 ); 192 mi.getMarkedList(); 193 194 InstructionList il = mi.getMarkedList(); 196 assertNull( 197 "Did not return a null marked list.", 198 il ); 199 } 200 201 202 public void testGetMarkedList_state3() 203 { 204 InstructionHandle ih = createInstructionHandle(); 205 MarkedInstruction mi = new MarkedInstruction( 206 (short)0, 0, 0, ih ); 207 mi.getMarkedList(); 208 209 mi.addMark( (short)1, (short)1 ); 210 mi.addMark( (short)1, (short)1 ); 211 InstructionList il = mi.getMarkedList(); 212 assertEquals( 213 "Did not return a marked list of the expected size.", 214 MARK_INSTRUCTION_COUNT*2, 215 il.size() ); 216 } 217 218 219 public void testGetMarkedList_state4() 220 { 221 InstructionHandle ih = createInstructionHandle(); 222 MarkedInstruction mi = new MarkedInstruction( 223 (short)0, 0, 0, ih ); 224 mi.addMark( (short)0, (short)0 ); 225 mi.addMark( (short)0, (short)1 ); 226 mi.addMark( (short)0, (short)2 ); 227 mi.getMarkedList(); 228 229 mi.addMark( (short)1, (short)0 ); 230 mi.addMark( (short)1, (short)1 ); 231 InstructionList il = mi.getMarkedList(); 232 assertEquals( 233 "Did not return a marked list of the expected size.", 234 MARK_INSTRUCTION_COUNT*2, 235 il.size() ); 236 } 237 238 239 public void testGetHandle1() 240 { 241 InstructionHandle ih = createInstructionHandle(); 242 MarkedInstruction mi = new MarkedInstruction( 243 (short)0, 0, 0, ih ); 244 assertSame( 245 "Did not return same handle.", 246 ih, 247 mi.getHandle() ); 248 } 249 250 251 254 255 protected InstructionHandle createInstructionHandle() 256 { 257 return BCELCreatorUtil.createInstructionHandle(); 258 } 259 260 261 262 265 266 public static Test suite() 267 { 268 TestSuite suite = new TestSuite( THIS_CLASS ); 269 270 return suite; 271 } 272 273 public static void main( String [] args ) 274 { 275 String [] name = { THIS_CLASS.getName() }; 276 277 280 junit.textui.TestRunner.main( name ); 281 } 282 283 284 288 protected void setUp() throws Exception 289 { 290 super.setUp(); 291 292 } 294 295 296 300 protected void tearDown() throws Exception 301 { 302 304 305 super.tearDown(); 306 } 307 } 308 309 | Popular Tags |