From 4ef16d3ab2ab50a9d04623018187d716f6cb434e Mon Sep 17 00:00:00 2001 From: chiba Date: Tue, 5 Jun 2012 14:53:58 +0000 Subject: fixed JASSIST-168 git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@631 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- src/test/javassist/JvstTest.java | 3 ++ .../bytecode/analysis/DomTreePrinter.java | 1 - .../javassist/bytecode/analysis/DomTreeTest.java | 59 ++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/test/test/javassist/bytecode/analysis/DomTreeTest.java (limited to 'src/test') diff --git a/src/test/javassist/JvstTest.java b/src/test/javassist/JvstTest.java index f4ccaf6c..f646506b 100644 --- a/src/test/javassist/JvstTest.java +++ b/src/test/javassist/JvstTest.java @@ -1126,6 +1126,9 @@ public class JvstTest extends JvstTestRoot { suite.addTestSuite(test.javassist.proxy.ProxyFactoryCompatibilityTest.class); suite.addTestSuite(test.javassist.proxy.ProxySerializationTest.class); suite.addTestSuite(test.javassist.proxy.ProxySimpleTest.class); + suite.addTestSuite(test.javassist.bytecode.analysis.AnalyzerTest.class); + suite.addTestSuite(test.javassist.convert.ArrayAccessReplaceTest.class); + suite.addTestSuite(test.javassist.bytecode.analysis.DomTreeTest.class); return suite; } } diff --git a/src/test/test/javassist/bytecode/analysis/DomTreePrinter.java b/src/test/test/javassist/bytecode/analysis/DomTreePrinter.java index 481c8abb..2ada4acd 100644 --- a/src/test/test/javassist/bytecode/analysis/DomTreePrinter.java +++ b/src/test/test/javassist/bytecode/analysis/DomTreePrinter.java @@ -20,7 +20,6 @@ public class DomTreePrinter { Node[] pdom = cf.postDominatorTree(); for (int i = 0; i < pdom.length; i++) System.out.println(i + ": " + pdom[i]); - } public int dummy(int n, int[] array) { diff --git a/src/test/test/javassist/bytecode/analysis/DomTreeTest.java b/src/test/test/javassist/bytecode/analysis/DomTreeTest.java new file mode 100644 index 00000000..dd348d01 --- /dev/null +++ b/src/test/test/javassist/bytecode/analysis/DomTreeTest.java @@ -0,0 +1,59 @@ +package test.javassist.bytecode.analysis; + +import javassist.ClassPool; +import javassist.bytecode.analysis.ControlFlow; +import javassist.bytecode.analysis.ControlFlow.Block; +import javassist.bytecode.analysis.ControlFlow.Node; +import junit.framework.TestCase; + +public class DomTreeTest extends TestCase { + private ClassPool pool = ClassPool.getDefault(); + + public void testDomtree() throws Exception { + ControlFlow cf = new ControlFlow(pool.get(DomTreeTest.class.getName()).getDeclaredMethod("test1")); + Block[] blocks = cf.basicBlocks(); + // for (int i = 0; i < blocks.length; i++) + // System.out.println(i + ": " + blocks[i]); + testBlock(blocks[0], new int[] {}, new int[] { 11, 6 } ); + testBlock(blocks[1], new int[] { 0 }, new int[] { 17, 11 } ); + testBlock(blocks[2], new int[] { 0, 6 }, new int[] { 19, 17 }); + testBlock(blocks[3], new int[] { 6, 11 }, new int[] { 19 }); + testBlock(blocks[4], new int[] { 11, 17 }, new int[] {}); + + Node[] dom = cf.dominatorTree(); + assertNull(dom[0].parent()); + assertEquals(0, dom[1].parent().block().position()); + assertEquals(0, dom[2].parent().block().position()); + assertEquals(0, dom[3].parent().block().position()); + assertEquals(0, dom[4].parent().block().position()); + + Node[] pdom = cf.postDominatorTree(); + assertEquals(19, pdom[0].parent().block().position()); + assertEquals(19, pdom[1].parent().block().position()); + assertEquals(19, pdom[2].parent().block().position()); + assertEquals(19, pdom[3].parent().block().position()); + assertNull(pdom[4].parent()); + } + + private void testBlock(Block b, int[] incoming, int[] outgoing) { + int i = 0; + for (int index: incoming) + assertEquals(index, b.incoming(i++).position()); + i = 0; + for (int index: outgoing) + assertEquals(index, b.exit(i++).position()); + } + + private void testNode(Node n, int[] incoming, int[] outgoing) { + int i = 0; + for (int index: incoming) + assertEquals(index, n.parent().block().index()); + } + + public void test1(){ + int k=0; + if (k != 0 && k!=2 || k < 7) { + k = 3 ; + } + } +} -- cgit v1.2.3