-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInheritanceTreeManagerTest.java
161 lines (121 loc) · 4.91 KB
/
InheritanceTreeManagerTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package qimpp;
import xtc.tree.Node;
import xtc.tree.GNode;
import xtc.tree.Visitor;
import qimpp.InheritanceTreeManager;
import static org.junit.Assert.assertEquals;
import junit.framework.JUnit4TestAdapter;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import static org.junit.Assert.*;
/**
* Tests for InheritanceTreeManager. Template. Not done yet
*
*/
public class InheritanceTreeManagerTest {
InheritanceTreeManager treeManager;
@Before public void setUp() {
//
// Insert some initial values into the inheritance
// tree
//
//
treeManager = new InheritanceTreeManager(
GNode.create("ClassDeclaration"));
// Put in some example classes
GNode newClass = GNode.create("ClassDeclaration", "Point");
//
ArrayList<String> point = new ArrayList<String>();
point.add("qimpp");
point.add("Point");
treeManager.insertClass(point, null, newClass);
//
//
//
newClass = GNode.create("ClassDeclaration", "ColorPoint");
ArrayList<String> ColorPoint = new ArrayList<String>();
ColorPoint.add("qimpp");
ColorPoint.add("ColorPoint");
treeManager.insertClass(ColorPoint, point, newClass);
//
//
// Test that classes with the same name in different
// packages are distinct
//
newClass = GNode.create("ClassDeclaration", "OtherColorPoint");
ColorPoint = new ArrayList<String>(
Arrays.asList("org", "fake", "ColorPoint") );
treeManager.insertClass(ColorPoint, null, newClass);
}
@Test public void testDereference() {
ArrayList<String> point = new ArrayList<String>();
point.add("qimpp");
point.add("Point");
GNode pointHopefully = treeManager.dereference(point);
assertTrue(pointHopefully != null);
//
pointHopefully = (GNode) treeManager.dereference(point).getProperty("ClassDeclaration");
assertTrue("Point".equals(pointHopefully.getString(0)));
// Test that classes in the same sub-namespace are
// inserted correctly
point = new ArrayList<String>( Arrays.asList("qimpp",
"ColorPoint") );
////
pointHopefully = (GNode) treeManager.dereference(point).getProperty("ClassDeclaration");
assertTrue(pointHopefully.getString(0).equals("ColorPoint"));
// Test that getClassTreeNode(ArrayList<String>) aliases
// dereference
pointHopefully = treeManager.getClassTreeNode(point);
//assertTrue("Point".equals((GNode)pointHopefully.get(0)));
}
/** See that inheritance is properly preserved */
@Test public void testInheritance () {
ArrayList<String> point = new ArrayList<String>(
Arrays.asList("qimpp", "Point") );
GNode pointNode = treeManager.dereference(point);
ArrayList<String> colorPoint = new ArrayList<String>(
Arrays.asList("qimpp", "ColorPoint") );
GNode colorNode = treeManager.dereference(colorPoint);
assertTrue( colorNode != null );
assertTrue( pointNode != null );
GNode g = (GNode)(treeManager.getParent(colorNode).getProperty("ClassDeclaration"));
assertTrue( treeManager.getParent(colorNode) == pointNode );
//
// Test distinction between package names
//
ArrayList<String> otherColor =
new ArrayList<String>( Arrays.asList("org", "fake",
"ColorPoint"));
GNode otherColorNode = treeManager.dereference(otherColor);
assertTrue( otherColorNode != null );
assertTrue( treeManager.getParent( otherColorNode )
!= treeManager.getParent(colorNode) );
assertTrue( otherColorNode != colorNode );
}
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(InheritanceTreeManagerTest.class);
}
/*
public int unused;
@Test public void divideByZero() {
int zero= 0;
int result= 8/zero;
unused= result; // avoid warning for not using result
}*/
/*
@Test public void testEquals() {
assertEquals(12, 12);
assertEquals(12L, 12L);
assertEquals(new Long(12), new Long(12));
assertEquals("Size", 12, 13);
assertEquals("Capacity", 12.0, 11.99, 0.0);
}*/
@Test public void testDisambiguate(){
}
@Test public void testGetClassTreeNode() {
}
@Test public void testGetParent() {
}
}