start of new file
[IRC.git] / Robust / src / Tests / OwnershipAnalysisTest / testGraphs / Main.java
1 import IR.*;
2 import IR.Flat.*;
3 import Analysis.OwnershipAnalysis.*;
4 import java.util.*;
5 import java.io.*;
6
7
8 public class Main {
9
10     protected static void test( String test,
11                                 boolean expected,
12                                 boolean result ) {
13
14         String outcome = "...\tFAILED";
15         if( expected == result ) {
16             outcome = "...\tpassed";
17         }
18         
19         System.out.println( test+" expected "+expected+outcome );
20     }
21
22     public static void main(String args[]) throws Exception {
23
24         // example test to know the testing routine is correct!
25         test( "4 == 5?", false, 4 == 5 );
26         test( "3 == 3?", true,  3 == 3 );
27
28
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" );
36
37         LabelNode ln0 = new LabelNode( lnTestA );
38         LabelNode ln1 = new LabelNode( lnTestA );
39         LabelNode ln2 = new LabelNode( lnTestB );
40
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 ) );
45
46
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
51         // order
52         int allocationDepth = 3;
53
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 );
59
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 );
67
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 );
76
77         OwnershipGraph g3 = new OwnershipGraph( allocationDepth );
78         g3.merge( g0 );
79         g3.merge( g1 );
80         g3.merge( g2 );
81
82         OwnershipGraph g4 = new OwnershipGraph( allocationDepth );
83         g4.merge( g1 );
84         g4.merge( g2 );
85         g4.merge( g0 );
86
87         test( "g0 equals to g1?", false, g0.equals( g1 ) );
88         test( "g1 equals to g0?", false, g1.equals( g0 ) );
89
90         test( "g0 equals to g2?", false, g0.equals( g2 ) );
91         test( "g2 equals to g0?", false, g2.equals( g0 ) );
92
93         test( "g1 equals to g2?", false, g1.equals( g2 ) );
94         test( "g2 equals to g1?", false, g2.equals( g1 ) );
95
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 ) );
99
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 ) );
103         
104         test( "g3 equals to g4?", true,  g3.equals( g4 ) );
105         test( "g4 equals to g3?", true,  g4.equals( g3 ) );
106     }
107 }