01: /* TestVertexData.java */
02: package org.quilt.cl;
03:
04: import junit.framework.*;
05: import org.apache.bcel.generic.*;
06: import org.quilt.graph.*;
07:
08: /**
09: * Vertex data is the additional data differentiating a CodeVertex
10: * from a simple Vertex. It consists of a bytecode position, a
11: * label, and the InstructionList.
12: *
13: * XXX This code tested a now-obsolete data structure; it should be
14: * beefed up or dropped.
15: *
16: * @author <a href="jddixon@users.sourceforge.net">Jim Dixon</a>
17: */
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); // position of no significance
31: }
32:
33: public void testNewNode() {
34: assertEquals("empty node has wrong position", 3, node
35: .getPosition());
36: assertTrue("empty node has something in it", node
37: .getInstructionList().isEmpty());
38: assertEquals("empty node has something in instruction list", 0,
39: node.getInstructionList().size());
40: }
41:
42: // in fact this would become several nodes, but for testing ...
43: public void testWhileNode() {
44: InstructionList ilist = node.getInstructionList();
45: ilist.append(new ILOAD(1));
46: InstructionHandle ifHandle = ilist.append(new DUP());
47: InstructionHandle loopHandle = ilist.append(new ICONST(1));
48: ilist.append(new ISUB());
49: ilist.append(new GOTO(ifHandle));
50: InstructionHandle retHandle = ilist.append(new IRETURN());
51: ilist.insert(loopHandle, new IFLE(retHandle));
52:
53: assertEquals("'while' node has wrong position", 3, node
54: .getPosition());
55: assertTrue("'while' node has nothing in it", !node
56: .getInstructionList().isEmpty());
57: assertEquals("'while' node has wrong size instruction list", 7,
58: node.getInstructionList().size());
59:
60: ControlFlowGraph graph = new ControlFlowGraph();
61: CodeVertex v = graph.insertCodeVertex(graph.getEntry()
62: .getEdge());
63: v.setPos(node.getPosition());
64: assertEquals("new vertex has wrong bytecode position", node
65: .getPosition(), v.getPosition());
66: }
67: }
|