1 26 27 package net.sourceforge.groboutils.codecoverage.v2; 28 29 import net.sourceforge.groboutils.autodoc.v1.AutoDoc; 30 import net.sourceforge.groboutils.codecoverage.v2.module.DefaultAnalysisMetaData; 31 import net.sourceforge.groboutils.junit.v1.iftc.ImplFactory; 32 import net.sourceforge.groboutils.junit.v1.iftc.InterfaceTestCase; 33 import net.sourceforge.groboutils.junit.v1.iftc.InterfaceTestSuite; 34 35 import org.apache.bcel.classfile.Method; 36 37 38 45 public class IMethodCodeUTestI extends InterfaceTestCase 46 { 47 50 private static final Class THIS_CLASS = IMethodCodeUTestI.class; 51 private static final AutoDoc DOC = new AutoDoc( THIS_CLASS ); 52 53 public IMethodCodeUTestI( String name, ImplFactory f ) 54 { 55 super( name, IMethodCode.class, f ); 56 } 57 58 59 public IMethodCode createIMethodCode() 60 { 61 return (IMethodCode)createImplObject(); 62 } 63 64 65 68 69 public void testGetOriginalMethod1() 70 { 71 IMethodCode mc = createIMethodCode(); 72 Method m = mc.getOriginalMethod(); 73 assertNotNull( 74 "Must not return null original method.", 75 m ); 76 } 77 78 79 public void testGetMethod1() 80 { 81 IMethodCode mc = createIMethodCode(); 82 assertNotNull( 83 "Method name is null.", 84 mc.getMethodName() ); 85 } 86 87 88 public void testGetClassName1() 89 { 90 IMethodCode mc = createIMethodCode(); 91 assertNotNull( 92 "Class name is null.", 93 mc.getClassName() ); 94 } 95 96 97 public void testGetInstructionCount1() 98 { 99 IMethodCode mc = createIMethodCode(); 100 int count = mc.getInstructionCount(); 101 assertTrue( 102 "Count is not valid", 103 count >= 0 ); 104 } 105 106 107 public void testMethodName1() 108 { 109 IMethodCode mc = createIMethodCode(); 110 Method m = mc.getOriginalMethod(); 111 String name = mc.getMethodName(); 112 assertEquals( 113 "Method name doesn't match returned method's name", 114 m.getName()+m.getSignature(), 115 name 116 ); 117 } 118 119 120 public void testInstructionConsistency1() 121 { 122 IMethodCode mc = createIMethodCode(); 123 int count = mc.getInstructionCount(); 124 for (int i = 0; i < count; ++i) 125 { 126 assertNotNull( 127 "Null instruction at position "+i+".", 128 mc.getInstructionAt( i ) ); 129 } 130 } 131 132 133 public void testInstructionConsistency2() 134 { 135 IMethodCode mc = createIMethodCode(); 136 int count = mc.getInstructionCount(); 137 try 138 { 139 mc.getInstructionAt( -1 ); 140 fail( "Did not throw excption w/ -1 index." ); 141 } 142 catch (IndexOutOfBoundsException e) 143 { 144 } 146 147 try 148 { 149 mc.getInstructionAt( count ); 150 fail( "Did not throw exception w/ "+count+" index." ); 151 } 152 catch (IndexOutOfBoundsException e) 153 { 154 } 156 } 157 158 159 public void testMarkInstruction1() 160 { 161 IMethodCode mc = createIMethodCode(); 162 int count = mc.getInstructionCount(); 163 if (count <= 0) 164 { 165 DOC.getLog().warn( "No instructions to mark for '"+mc+"'." ); 166 return; 167 } 168 169 for (int i = 0; i <= count; ++i) 172 { 173 IAnalysisMetaData meta = new DefaultAnalysisMetaData( 174 "", "", (byte)0 ); 175 mc.markInstruction( i, meta ); 176 } 177 } 178 179 180 public void testMarkInstruction2() 181 { 182 IMethodCode mc = createIMethodCode(); 183 184 try 185 { 186 IAnalysisMetaData meta = new DefaultAnalysisMetaData( 187 "", "", (byte)0 ); 188 mc.markInstruction( -1, meta ); 189 fail( "Did not throw IndexOutOfBoundsException." ); 190 } 191 catch (IndexOutOfBoundsException e) 192 { 193 } 195 } 196 197 198 public void testMarkInstruction4() 199 { 200 IMethodCode mc = createIMethodCode(); 201 int count = mc.getInstructionCount(); 202 203 try 204 { 205 IAnalysisMetaData meta = new DefaultAnalysisMetaData( 206 "", "", (byte)0 ); 207 mc.markInstruction( count+1, meta ); 208 fail( "Did not throw IndexOutOfBoundsException." ); 209 } 210 catch (IndexOutOfBoundsException e) 211 { 212 } 214 } 215 216 217 public void testMarkInstruction5() 218 { 219 IMethodCode mc = createIMethodCode(); 220 int count = mc.getInstructionCount(); 221 222 225 try 227 { 228 mc.markInstruction( 0, null ); 229 fail( "Did not throw IllegalArgumentException." ); 230 } 231 catch (IllegalArgumentException e) 232 { 233 } 235 } 236 237 238 241 242 public static InterfaceTestSuite suite() 243 { 244 InterfaceTestSuite suite = new InterfaceTestSuite( THIS_CLASS ); 245 246 return suite; 247 } 248 249 public static void main( String [] args ) 250 { 251 String [] name = { THIS_CLASS.getName() }; 252 253 256 junit.textui.TestRunner.main( name ); 257 } 258 259 260 264 protected void setUp() throws Exception 265 { 266 super.setUp(); 267 268 } 270 271 272 276 protected void tearDown() throws Exception 277 { 278 280 281 super.tearDown(); 282 } 283 } 284 285 | Popular Tags |