OSDN Git Service

8775c487a3f371d81f3c72864763e9ae6de0840b
[stigmata/stigmata-plugins.git] / opcodes / src / test / java / jp / sourceforge / stigmata / birthmarks / ControlFlowGraphTest.java
1 package jp.sourceforge.stigmata.birthmarks;\r
2 \r
3 import java.util.Iterator;\r
4 \r
5 import junit.framework.Assert;\r
6 \r
7 import org.junit.Before;\r
8 import org.junit.Test;\r
9 import org.objectweb.asm.ClassReader;\r
10 import org.objectweb.asm.ClassWriter;\r
11 \r
12 public class ControlFlowGraphTest {\r
13     private ControlFlowGraphExtractVisitor visitor;\r
14 \r
15     @Before\r
16     public void setUp() throws Exception{\r
17         ClassReader reader = new ClassReader(getClass().getResource("/resources/MyServer.class").openStream());\r
18 \r
19         visitor = new ControlFlowGraphExtractVisitor(new ClassWriter(0));\r
20         reader.accept(visitor, 0);\r
21     }\r
22 \r
23     @Test\r
24     public void testBasic() throws Exception{\r
25         Iterator<String> iterator = visitor.getMethodNames();\r
26 \r
27         Assert.assertTrue(iterator.hasNext());\r
28         Assert.assertEquals("<init>(I)V", iterator.next());\r
29         Assert.assertFalse(iterator.hasNext());\r
30 \r
31         ControlFlowGraph graph = visitor.getGraph("<init>(I)V");\r
32 \r
33         Assert.assertEquals(6, graph.getBasicBlockSize());\r
34 \r
35         graph.setIncludingExceptionFlow(true);\r
36         Assert.assertEquals(7, graph.getBasicBlockSize());\r
37     }\r
38 }\r