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 BranchCountMeasureUTest extends TestCase 54 { 55 58 private static final Class THIS_CLASS = BranchCountMeasureUTest.class; 59 private static final AutoDoc DOC = new AutoDoc( THIS_CLASS ); 60 61 public BranchCountMeasureUTest( String name ) 62 { 63 super( name ); 64 } 65 66 67 70 public static class MyTestClass 71 { 72 public static void main( String [] args ) 73 { 74 int i = 0; 75 i += 10; 76 if (i > 1) 77 { 78 System.out.println( ""+i ); 79 } 80 } 81 } 82 83 84 public void testAnalyze1() throws Exception 85 { 86 BranchCountMeasure bcm = new BranchCountMeasure(); 87 ModifiedClass mc = CCCreatorUtil.createModifiedClass( 88 TestLogger.createPCL(), MyTestClass.class ); 89 ModifiedMethod mm = CCCreatorUtil.getMainModifiedMethod( mc ); 90 IMethodCode imc = createMethodCode( MyTestClass.class, mm, bcm ); 91 92 bcm.analyze( imc ); 94 95 Class c = BytecodeLoaderUtil.loadClassFromBytecode( 97 mc.getClassName(), mc.getModifiedClass() ); 98 TestLogger.reset(); 99 BytecodeLoaderUtil.runMain( c ); 100 assertEquals( 101 "Did not mark every bytecode in method.", 102 3, 103 TestLogger.size() ); 104 } 105 106 107 108 111 112 protected IMethodCode createMethodCode( Class c, ModifiedMethod mm, 113 IAnalysisModule am ) 114 { 115 return CCCreatorUtil.createIMethodCode( c, mm, 116 CCCreatorUtil.createAnalysisModuleSet( 117 new IAnalysisModule[] { am } ), 118 0 ); 119 } 120 121 122 123 126 127 public static Test suite() 128 { 129 InterfaceTestSuite suite = IAnalysisModuleUTestI.suite(); 130 suite.addTestSuite( THIS_CLASS ); 131 suite.addFactory( new CxFactory( "A" ) { 132 public Object createImplObject() throws IOException { 133 return new BranchCountMeasure(); 134 } 135 } ); 136 137 return suite; 138 } 139 140 public static void main( String [] args ) 141 { 142 String [] name = { THIS_CLASS.getName() }; 143 144 147 junit.textui.TestRunner.main( name ); 148 } 149 150 151 155 protected void setUp() throws Exception 156 { 157 super.setUp(); 158 159 160 } 162 163 164 168 protected void tearDown() throws Exception 169 { 170 172 173 super.tearDown(); 174 } 175 } 176 177 | Popular Tags |