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.InstructionList; 36 37 38 45 public class ModifiedInstructionListUTest extends TestCase 46 { 47 50 private static final Class THIS_CLASS = ModifiedInstructionListUTest.class; 51 private static final AutoDoc DOC = new AutoDoc( THIS_CLASS ); 52 53 public ModifiedInstructionListUTest( String name ) 54 { 55 super( name ); 56 } 57 58 59 62 public void testConstructor1() 63 { 64 try 65 { 66 new ModifiedInstructionList( (short)0, 0, 0, null, null ); 67 fail( "Did not throw IllegalArgumentException." ); 68 } 69 catch (IllegalArgumentException e) 70 { 71 } 73 } 74 75 76 public void testConstructor2() 77 { 78 new ModifiedInstructionList( (short)0, 0, 79 0, createInstructionList(), createModifiedTargeters() ); 80 } 81 82 83 public void testClose1() 84 { 85 ModifiedInstructionList mil = new ModifiedInstructionList( 86 (short)0, 0, 0, createInstructionList(), 87 createModifiedTargeters() ); 88 mil.close(); 89 } 90 91 92 public void testClose2() 93 { 94 ModifiedInstructionList mil = new ModifiedInstructionList( 95 (short)0, 0, 0, createInstructionList(), 96 createModifiedTargeters() ); 97 mil.close(); 98 try 99 { 100 mil.close(); 101 fail( "Did not throw IllegalStateException." ); 102 } 103 catch (IllegalStateException e) 104 { 105 } 107 } 108 109 110 public void testClose3() 111 { 112 ModifiedInstructionList mil = new ModifiedInstructionList( 113 (short)0, 0, 0, createInstructionList(), 114 createModifiedTargeters() ); 115 mil.close(); 116 try 117 { 118 mil.getInstructionAt(0); 119 fail( "Did not throw IllegalStateException." ); 120 } 121 catch (IllegalStateException e) 122 { 123 } 125 } 126 127 128 public void testClose4() 129 { 130 ModifiedInstructionList mil = new ModifiedInstructionList( 131 (short)0, 0, 0, createInstructionList(), 132 createModifiedTargeters() ); 133 mil.close(); 134 try 135 { 136 mil.getInstructionCount(); 137 fail( "Did not throw IllegalStateException." ); 138 } 139 catch (IllegalStateException e) 140 { 141 } 143 } 144 145 146 public void testClose5() 147 { 148 ModifiedInstructionList mil = new ModifiedInstructionList( 149 (short)0, 0, 0, createInstructionList(), 150 createModifiedTargeters() ); 151 mil.close(); 152 try 153 { 154 mil.updateInstructionList(); 155 fail( "Did not throw IllegalStateException." ); 156 } 157 catch (IllegalStateException e) 158 { 159 } 161 } 162 163 164 public void testUpdateInstructionList1() 165 { 166 ModifiedInstructionList mil = new ModifiedInstructionList( 167 (short)0, 0, 0, createInstructionList(), 168 createModifiedTargeters() ); 169 int origCount = mil.getInstructionCount(); 170 mil.updateInstructionList(); 171 assertEquals( "Changed instruction count!", origCount, 172 mil.getInstructionCount() ); 173 mil.updateInstructionList(); 174 assertEquals( "Changed instruction count!", origCount, 175 mil.getInstructionCount() ); 176 mil.updateInstructionList(); 177 assertEquals( "Changed instruction count!", origCount, 178 mil.getInstructionCount() ); 179 } 180 181 182 public void testUpdateInstructionList2() 183 { 184 ModifiedInstructionList mil = new ModifiedInstructionList( 185 (short)0, 0, 0, createInstructionList(), 186 createModifiedTargeters() ); 187 int origCount = mil.getInstructionCount(); 188 mil.getInstructionAt( origCount - 1 ). 189 addMark( (short)1, Short.MAX_VALUE ); 190 mil.updateInstructionList(); 191 mil.getInstructionAt( origCount - 1 ). 192 addMark( (short)1, Short.MAX_VALUE ); 193 mil.updateInstructionList(); 194 int count = mil.getInstructionCount(); 195 mil.updateInstructionList(); 196 assertEquals( "Changed instruction count!", count, 197 mil.getInstructionCount() ); 198 } 199 200 201 public void testGetInstructionAt1() 202 { 203 ModifiedInstructionList mil = new ModifiedInstructionList( 206 (short)0, 0, 0, new InstructionList(), 207 createModifiedTargeters() ); 208 MarkedInstruction mi = mil.getInstructionAt( 0 ); 209 assertNotNull( 210 "Returned null end instruction.", 211 mi ); 212 assertTrue( 213 "End instruction is not the NullInstruction.", 214 mi.getInstruction() instanceof NullInstruction ); 215 } 216 217 218 219 222 223 protected InstructionList createInstructionList() 224 { 225 InstructionList il = BCELCreatorUtil.createInstructionList(); 226 BCELCreatorUtil.addInstructionHandle( il ); 227 return il; 228 } 229 230 231 protected ModifiedTargeters createModifiedTargeters() 232 { 233 org.apache.bcel.classfile.JavaClass jc = null; 234 try 235 { 236 jc = BCELCreatorUtil.createJavaClass( THIS_CLASS ); 237 } 238 catch (java.io.IOException ex) 239 { 240 ex.printStackTrace(); 241 fail( ex.getMessage() ); 242 } 243 return new ModifiedTargeters( 244 BCELCreatorUtil.createMethodGen( jc, 0 ) ); 245 } 246 247 248 251 252 public static Test suite() 253 { 254 TestSuite suite = new TestSuite( THIS_CLASS ); 255 256 return suite; 257 } 258 259 public static void main( String [] args ) 260 { 261 String [] name = { THIS_CLASS.getName() }; 262 263 266 junit.textui.TestRunner.main( name ); 267 } 268 269 270 274 protected void setUp() throws Exception 275 { 276 super.setUp(); 277 278 } 280 281 282 286 protected void tearDown() throws Exception 287 { 288 290 291 super.tearDown(); 292 } 293 } 294 295 | Popular Tags |