3 import Analysis.OwnershipAnalysis.*;
10 protected static void test( String test,
14 String outcome = "...\tFAILED";
15 if( expected == result ) {
16 outcome = "...\tpassed";
19 System.out.println( test+" expected "+expected+outcome );
22 public static void main(String args[]) throws Exception {
24 // example test to know the testing routine is correct!
25 test( "4 == 5?", false, 4 == 5 );
26 test( "3 == 3?", true, 3 == 3 );
29 // test equality of label objects that are logically
30 // same/different but all separate objects
31 // these tests show how a label node object or other
32 // ownership graph element can be equivalent logically
33 // to a different object in another graph
34 TempDescriptor lnTestA = new TempDescriptor( "lnTestA" );
35 TempDescriptor lnTestB = new TempDescriptor( "lnTestB" );
37 LabelNode ln0 = new LabelNode( lnTestA );
38 LabelNode ln1 = new LabelNode( lnTestA );
39 LabelNode ln2 = new LabelNode( lnTestB );
41 test( "ln0 equals ln1?", true, ln0.equals( ln1 ) );
42 test( "ln1 equals ln0?", true, ln1.equals( ln0 ) );
43 test( "ln0 equals ln2?", false, ln0.equals( ln2 ) );
44 test( "ln2 equals ln1?", false, ln2.equals( ln1 ) );
47 // ownership graphs g3 and g4 are equivalent
48 // graphs as specified in OwnershipGraph.java,
49 // just built from different objects that contain the
50 // equivalent values and merged in a different
52 int allocationDepth = 3;
54 OwnershipGraph g0 = new OwnershipGraph( allocationDepth );
55 TempDescriptor g0tdp1 = new TempDescriptor( "p1" );
56 TempDescriptor g0tdx = new TempDescriptor( "x" );
57 g0.parameterAllocation( true, g0tdp1 );
58 g0.assignTempToTemp ( g0tdx, g0tdp1 );
60 OwnershipGraph g1 = new OwnershipGraph( allocationDepth );
61 TempDescriptor g1tdp2 = new TempDescriptor( "p2" );
62 TempDescriptor g1tdy = new TempDescriptor( "y" );
63 TempDescriptor g1tdz = new TempDescriptor( "z" );
64 g1.parameterAllocation( true, g1tdp2 );
65 g1.assignTempToTemp ( g1tdy, g1tdp2 );
66 g1.assignTempToField ( g1tdz, g1tdp2, null );
68 OwnershipGraph g2 = new OwnershipGraph( allocationDepth );
69 TempDescriptor g2tdp3 = new TempDescriptor( "p3" );
70 TempDescriptor g2tdp4 = new TempDescriptor( "p4" );
71 TempDescriptor g2tdw = new TempDescriptor( "w" );
72 g2.parameterAllocation( true, g2tdp3 );
73 g2.parameterAllocation( true, g2tdp4 );
74 g2.assignTempToTemp ( g2tdw, g2tdp4 );
75 g2.assignFieldToTemp ( g2tdp3, g2tdw, null );
77 OwnershipGraph g3 = new OwnershipGraph( allocationDepth );
82 OwnershipGraph g4 = new OwnershipGraph( allocationDepth );
87 test( "g0 equals to g1?", false, g0.equals( g1 ) );
88 test( "g1 equals to g0?", false, g1.equals( g0 ) );
90 test( "g0 equals to g2?", false, g0.equals( g2 ) );
91 test( "g2 equals to g0?", false, g2.equals( g0 ) );
93 test( "g1 equals to g2?", false, g1.equals( g2 ) );
94 test( "g2 equals to g1?", false, g2.equals( g1 ) );
96 test( "g3 equals to g0?", false, g3.equals( g0 ) );
97 test( "g3 equals to g1?", false, g3.equals( g1 ) );
98 test( "g3 equals to g2?", false, g3.equals( g2 ) );
100 test( "g4 equals to g0?", false, g4.equals( g0 ) );
101 test( "g4 equals to g1?", false, g4.equals( g1 ) );
102 test( "g4 equals to g2?", false, g4.equals( g2 ) );
104 test( "g3 equals to g4?", true, g3.equals( g4 ) );
105 test( "g4 equals to g3?", true, g4.equals( g3 ) );