1 26 27 package net.sourceforge.groboutils.codecoverage.v2.module; 28 29 import java.io.IOException ; 30 31 import junit.framework.Test; 32 import junit.framework.TestCase; 33 import net.sourceforge.groboutils.autodoc.v1.AutoDoc; 34 import net.sourceforge.groboutils.codecoverage.v2.BytecodeLoaderUtil; 35 import net.sourceforge.groboutils.codecoverage.v2.CCCreatorUtil; 36 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule; 37 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModuleUTestI; 38 import net.sourceforge.groboutils.codecoverage.v2.IMethodCode; 39 import net.sourceforge.groboutils.codecoverage.v2.compiler.ModifiedClass; 40 import net.sourceforge.groboutils.codecoverage.v2.compiler.ModifiedMethod; 41 import net.sourceforge.groboutils.codecoverage.v2.logger.TestLogger; 42 import net.sourceforge.groboutils.junit.v1.iftc.CxFactory; 43 import net.sourceforge.groboutils.junit.v1.iftc.InterfaceTestSuite; 44 45 46 53 public class BytecodeCountMeasureUTest extends TestCase 54 { 55 58 private static final Class THIS_CLASS = BytecodeCountMeasureUTest.class; 59 private static final AutoDoc DOC = new AutoDoc( THIS_CLASS ); 60 61 public BytecodeCountMeasureUTest( String name ) 62 { 63 super( name ); 64 } 65 66 67 70 71 public static class MyTestClass 72 { 73 public static void main( String [] args ) 74 { 75 int i = 0; 76 i += 10; 77 System.out.println( ""+i ); 78 } 79 } 80 81 82 public void testAnalyze1() throws Exception 83 { 84 BytecodeCountMeasure bcm = new BytecodeCountMeasure(); 85 ModifiedClass mc = CCCreatorUtil.createModifiedClass( 86 TestLogger.createPCL(), MyTestClass.class ); 87 ModifiedMethod mm = CCCreatorUtil.getMainModifiedMethod( mc ); 88 IMethodCode imc = createMethodCode( MyTestClass.class, mm, bcm ); 89 int expectedCount = mm.getInstructionList().getInstructionCount(); 90 91 bcm.analyze( imc ); 93 94 Class c = BytecodeLoaderUtil.loadClassFromBytecode( 96 mc.getClassName(), mc.getModifiedClass() ); 97 TestLogger.reset(); 98 BytecodeLoaderUtil.runMain( c ); 99 assertEquals( 100 "Did not mark every bytecode in method.", 101 expectedCount, 102 TestLogger.size() ); 103 } 104 105 106 107 110 111 protected IMethodCode createMethodCode( Class c, ModifiedMethod mm, 112 IAnalysisModule am ) 113 { 114 return CCCreatorUtil.createIMethodCode( c, mm, 115 CCCreatorUtil.createAnalysisModuleSet( 116 new IAnalysisModule[] { am } ), 117 0 ); 118 } 119 120 121 124 125 public static Test suite() 126 { 127 InterfaceTestSuite suite = IAnalysisModuleUTestI.suite(); 128 suite.addTestSuite( THIS_CLASS ); 129 suite.addFactory( new CxFactory( "A" ) { 130 public Object createImplObject() throws IOException { 131 return new BytecodeCountMeasure(); 132 } 133 } ); 134 135 return suite; 136 } 137 138 public static void main( String [] args ) 139 { 140 String [] name = { THIS_CLASS.getName() }; 141 142 145 junit.textui.TestRunner.main( name ); 146 } 147 148 149 153 protected void setUp() throws Exception 154 { 155 super.setUp(); 156 157 158 } 160 161 162 166 protected void tearDown() throws Exception 167 { 168 170 171 super.tearDown(); 172 } 173 } 174 175 | Popular Tags |