1 2 package org.quilt.cl; 3 4 import junit.framework.*; 5 import org.apache.bcel.generic.*; 6 import org.quilt.graph.*; 7 8 18 public class TestVertexData extends TestCase { 19 20 private ControlFlowGraph cfg; 21 22 private CodeVertex node; 23 24 public TestVertexData (String name) { 25 super(name); 26 } 27 28 public void setUp () { 29 cfg = new ControlFlowGraph(); 30 node = new CodeVertex (cfg, 3); } 32 33 public void testNewNode() { 34 assertEquals ("empty node has wrong position", 35 3, node.getPosition() ); 36 assertTrue ("empty node has something in it", 37 node.getInstructionList().isEmpty() ); 38 assertEquals("empty node has something in instruction list", 39 0, node.getInstructionList().size() ); 40 } 41 public void testWhileNode() { 43 InstructionList ilist = node.getInstructionList(); 44 ilist.append ( new ILOAD (1) ); 45 InstructionHandle ifHandle = ilist.append ( new DUP () ); 46 InstructionHandle loopHandle = ilist.append ( new ICONST( 1 ) ); 47 ilist.append( new ISUB() ); 48 ilist.append( new GOTO( ifHandle )); 49 InstructionHandle retHandle = ilist.append ( new IRETURN() ); 50 ilist.insert( loopHandle, new IFLE( retHandle )); 51 52 assertEquals ("'while' node has wrong position", 53 3, node.getPosition() ); 54 assertTrue ("'while' node has nothing in it", 55 !node.getInstructionList().isEmpty() ); 56 assertEquals("'while' node has wrong size instruction list", 57 7, node.getInstructionList().size() ); 58 59 ControlFlowGraph graph = new ControlFlowGraph(); 60 CodeVertex v = graph.insertCodeVertex ( graph.getEntry().getEdge() ); 61 v.setPos(node.getPosition()); 62 assertEquals ("new vertex has wrong bytecode position", 63 node.getPosition(), 64 v.getPosition() ); 65 } 66 } 67 | Popular Tags |