OSDN Git Service

e4faf43d97e3099197ada32f03fefa8e7c6a69bc
[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(6, graph.getBasicBlockSize());\r
37     }\r
38 \r
39     @Test\r
40     public void testGraph() throws Exception{\r
41         ControlFlowGraph graph = visitor.getGraph("<init>(I)V");\r
42         int[][] graphMatrix = graph.getGraphMatrix();\r
43 \r
44         Assert.assertEquals(6, graphMatrix.length);\r
45 \r
46         Assert.assertEquals(0, graphMatrix[0][0]);\r
47         Assert.assertEquals(1, graphMatrix[0][1]);\r
48         Assert.assertEquals(1, graphMatrix[0][2]);\r
49         Assert.assertEquals(0, graphMatrix[0][3]);\r
50         Assert.assertEquals(0, graphMatrix[0][4]);\r
51         Assert.assertEquals(0, graphMatrix[0][5]);\r
52 \r
53         Assert.assertEquals(0, graphMatrix[1][0]);\r
54         Assert.assertEquals(0, graphMatrix[1][1]);\r
55         Assert.assertEquals(0, graphMatrix[1][2]);\r
56         Assert.assertEquals(1, graphMatrix[1][3]);\r
57         Assert.assertEquals(0, graphMatrix[1][4]);\r
58         Assert.assertEquals(0, graphMatrix[1][5]);\r
59 \r
60         Assert.assertEquals(0, graphMatrix[2][0]);\r
61         Assert.assertEquals(0, graphMatrix[2][1]);\r
62         Assert.assertEquals(0, graphMatrix[2][2]);\r
63         Assert.assertEquals(1, graphMatrix[2][3]);\r
64         Assert.assertEquals(0, graphMatrix[2][4]);\r
65         Assert.assertEquals(0, graphMatrix[2][5]);\r
66 \r
67         Assert.assertEquals(0, graphMatrix[3][0]);\r
68         Assert.assertEquals(0, graphMatrix[3][1]);\r
69         Assert.assertEquals(0, graphMatrix[3][2]);\r
70         Assert.assertEquals(0, graphMatrix[3][3]);\r
71         Assert.assertEquals(0, graphMatrix[3][4]);\r
72         Assert.assertEquals(1, graphMatrix[3][5]);\r
73 \r
74         Assert.assertEquals(0, graphMatrix[4][0]);\r
75         Assert.assertEquals(0, graphMatrix[4][1]);\r
76         Assert.assertEquals(0, graphMatrix[4][2]);\r
77         Assert.assertEquals(0, graphMatrix[4][3]);\r
78         Assert.assertEquals(0, graphMatrix[4][4]);\r
79         Assert.assertEquals(1, graphMatrix[4][5]);\r
80 \r
81         Assert.assertEquals(0, graphMatrix[5][0]);\r
82         Assert.assertEquals(0, graphMatrix[5][1]);\r
83         Assert.assertEquals(0, graphMatrix[5][2]);\r
84         Assert.assertEquals(0, graphMatrix[5][3]);\r
85         Assert.assertEquals(0, graphMatrix[5][4]);\r
86         Assert.assertEquals(0, graphMatrix[5][5]);\r
87     }\r
88 }\r