~ubuntu-branches/ubuntu/utopic/aspectj/utopic

« back to all changes in this revision

Viewing changes to org.aspectj/modules/ajde/testsrc/org/aspectj/ajde/StructureModelTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch, Michael Koch, Thomas Girard, Mark Howard
  • Date: 2008-01-05 23:31:47 UTC
  • mfrom: (1.1.2 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080105233147-r425rd8nymruj6fk
Tags: 1.5.4-1
[ Michael Koch ]
* New upstream version. Closes: #459363
* Updated Standards-Version to 3.7.3.
* Added myself to Uploaders.

[ Thomas Girard ]
* Add Homepage: control field, and convert XS-Vcs-* to Vcs-*.

[ Mark Howard ]
* debian/watch: added.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* *******************************************************************
2
 
 * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
3
 
 * All rights reserved. 
4
 
 * This program and the accompanying materials are made available 
5
 
 * under the terms of the Eclipse Public License v1.0 
6
 
 * which accompanies this distribution and is available at 
7
 
 * http://www.eclipse.org/legal/epl-v10.html 
8
 
 *  
9
 
 * Contributors: 
10
 
 *     Xerox/PARC     initial implementation 
11
 
 *     AMC 21.01.2003 fixed for new source location in eclipse.org
12
 
 * ******************************************************************/
13
 
 
14
 
package org.aspectj.ajde;
15
 
 
16
 
import java.io.*;
17
 
import java.util.Iterator;
18
 
 
19
 
import junit.framework.TestSuite;
20
 
 
21
 
import org.aspectj.asm.*;
22
 
 
23
 
/**
24
 
 * @author Mik Kersten
25
 
 */
26
 
public class StructureModelTest extends AjdeTestCase {
27
 
        
28
 
    // TODO-path
29
 
        private final String CONFIG_FILE_PATH = "../examples/figures-coverage/all.lst";
30
 
 
31
 
        public StructureModelTest(String name) {
32
 
                super(name);
33
 
        }
34
 
 
35
 
        public static void main(String[] args) {
36
 
                junit.swingui.TestRunner.run(StructureModelTest.class);
37
 
        }
38
 
 
39
 
        public static TestSuite suite() {
40
 
                TestSuite result = new TestSuite();
41
 
                result.addTestSuite(StructureModelTest.class);  
42
 
                return result;
43
 
        }
44
 
 
45
 
//  XXX this should work
46
 
//      public void testFieldInitializerCorrespondence() throws IOException {
47
 
//              File testFile = createFile("testdata/examples/figures-coverage/figures/Figure.java");   
48
 
//              IProgramElement node = Ajde.getDefault().getStructureModelManager().getStructureModel().findNodeForSourceLine(
49
 
//                      testFile.getCanonicalPath(), 28);
50
 
//              assertTrue("find result", node != null) ;       
51
 
//              ProgramElementNode pNode = (ProgramElementNode)node;
52
 
//              ProgramElementNode foundNode = null;
53
 
//              final List list = pNode.getRelations();
54
 
//        assertNotNull("pNode.getRelations()", list);
55
 
//              for (Iterator it = list.iterator(); it.hasNext(); ) {
56
 
//                      RelationNode relation = (RelationNode)it.next();
57
 
//                      
58
 
//                      if (relation.getRelation().equals(AdviceAssociation.FIELD_ACCESS_RELATION)) {
59
 
//                              for (Iterator it2 = relation.getChildren().iterator(); it2.hasNext(); ) {
60
 
//                                      LinkNode linkNode = (LinkNode)it2.next();
61
 
//                                      if (linkNode.getProgramElementNode().getName().equals("this.currVal = 0")) {
62
 
//                                              foundNode = linkNode.getProgramElementNode();   
63
 
//                                      }
64
 
//                              }
65
 
//                      }
66
 
//              }
67
 
//              
68
 
//              assertTrue("find associated node", foundNode != null) ;
69
 
//              
70
 
//              File pointFile = createFile("testdata/examples/figures-coverage/figures/primitives/planar/Point.java"); 
71
 
//              IProgramElement fieldNode = Ajde.getDefault().getStructureModelManager().getStructureModel().findNodeForSourceLine(
72
 
//                      pointFile.getCanonicalPath(), 12);              
73
 
//              assertTrue("find result", fieldNode != null);
74
 
//              
75
 
//              assertTrue("matches", foundNode.getParent() == fieldNode.getParent());
76
 
//      }
77
 
 
78
 
 
79
 
        public void testRootForSourceFile() throws IOException {
80
 
                File testFile = openFile("figures-coverage/figures/Figure.java");       
81
 
                IProgramElement node = Ajde.getDefault().getStructureModelManager().getHierarchy().findElementForSourceFile(
82
 
                        testFile.getAbsolutePath());
83
 
                assertTrue("find result", node != null) ;       
84
 
                IProgramElement pNode = (IProgramElement)node;
85
 
                String child = ((IProgramElement)pNode.getChildren().get(1)).getName();
86
 
        assertTrue("expected Figure got child " + child, child.equals("Figure"));
87
 
        }
88
 
 
89
 
        public void testPointcutName() throws IOException {
90
 
                File testFile = openFile("figures-coverage/figures/Main.java"); 
91
 
                IProgramElement node = Ajde.getDefault().getStructureModelManager().getHierarchy().findElementForSourceFile(
92
 
                        testFile.getAbsolutePath());
93
 
                assertTrue("find result", node != null) ;       
94
 
                IProgramElement pNode = (IProgramElement)((IProgramElement)node).getChildren().get(2);
95
 
                IProgramElement pointcut = (IProgramElement)pNode.getChildren().get(0);
96
 
                assertTrue("kind", pointcut.getKind().equals(IProgramElement.Kind.POINTCUT));
97
 
                assertTrue("found node: " + pointcut.getName(), pointcut.toLabelString().equals("testptct()"));
98
 
        }
99
 
 
100
 
        public void testFileNodeFind() throws IOException {
101
 
                File testFile = openFile("figures-coverage/figures/Main.java");
102
 
                
103
 
//              System.err.println(((IProgramElement)((IProgramElement)Ajde.getDefault().getStructureModelManager().getHierarchy().getRoot().getChildren().get(0)).getChildren().get(3)).getSourceLocation().getSourceFile().getAbsolutePath());
104
 
//              System.err.println(testFile.getAbsolutePath());
105
 
                
106
 
                IProgramElement node = Ajde.getDefault().getStructureModelManager().getHierarchy().findElementForSourceLine(
107
 
                        testFile.getAbsolutePath(), 1);
108
 
                assertTrue("find result", node != null) ;       
109
 
                assertEquals("find result has children", 3, node.getChildren().size()) ;        
110
 
                IProgramElement pNode = (IProgramElement)node;
111
 
                assertTrue("found node: " + pNode.getName(), pNode.getKind().equals(IProgramElement.Kind.FILE_JAVA));
112
 
        }
113
 
  
114
 
        /**
115
 
         * @todo        add negative test to make sure things that aren't runnable aren't annotated
116
 
         */ 
117
 
        public void testMainClassNodeInfo() throws IOException {
118
 
        IHierarchy model = Ajde.getDefault().getStructureModelManager().getHierarchy();
119
 
        assertTrue("model exists", model != null);
120
 
                assertTrue("root exists", model.getRoot() != null);
121
 
                File testFile = openFile("figures-coverage/figures/Main.java");
122
 
                IProgramElement node = model.findElementForSourceLine(testFile.getAbsolutePath(), 11);  
123
 
                assertTrue("find result", node != null);        
124
 
                IProgramElement pNode = (IProgramElement)((IProgramElement)node).getParent();
125
 
        if (null == pNode) {
126
 
            assertTrue("null parent of " + node, false);
127
 
        }
128
 
                assertTrue("found node: " + pNode.getName(), pNode.isRunnable());
129
 
        }  
130
 
        
131
 
        /**
132
 
         * Integrity could be checked somewhere in the API.
133
 
         */ 
134
 
        public void testModelIntegrity() {
135
 
                IProgramElement modelRoot = Ajde.getDefault().getStructureModelManager().getHierarchy().getRoot();
136
 
                assertTrue("root exists", modelRoot != null);   
137
 
                
138
 
                try {
139
 
                        testModelIntegrityHelper(modelRoot);
140
 
                } catch (Exception e) {
141
 
                        assertTrue(e.toString(), false);        
142
 
                }
143
 
        }
144
 
 
145
 
        private void testModelIntegrityHelper(IProgramElement node) throws Exception {
146
 
                for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
147
 
                        IProgramElement child = (IProgramElement)it.next();
148
 
                        if (node == child.getParent()) {
149
 
                                testModelIntegrityHelper(child);
150
 
                        } else {
151
 
                                throw new Exception("parent-child check failed for child: " + child.toString());
152
 
                        }
153
 
                }               
154
 
        }
155
 
  
156
 
        public void testNoChildIsNull() {
157
 
                HierarchyWalker walker = new HierarchyWalker() {
158
 
                    public void preProcess(IProgramElement node) {
159
 
                        if (node.getChildren() == null) return;
160
 
                        for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
161
 
                                if (it.next() == null) throw new NullPointerException("null child on node: " + node.getName()); 
162
 
                        }
163
 
                    }
164
 
                };
165
 
                Ajde.getDefault().getStructureModelManager().getHierarchy().getRoot().walk(walker);
166
 
        }  
167
 
  
168
 
        protected void setUp() throws Exception {
169
 
                super.setUp("examples");
170
 
                doSynchronousBuild(CONFIG_FILE_PATH);   
171
 
        }
172
 
 
173
 
        protected void tearDown() throws Exception {
174
 
                super.tearDown();
175
 
        }
176
 
}
177