1 | /* |
---|
2 | * This file is part of Modelica Development Tooling. |
---|
3 | * |
---|
4 | * Copyright (c) 2005, Linköpings universitet, Department of |
---|
5 | * Computer and Information Science, PELAB |
---|
6 | * |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * (The new BSD license, see also |
---|
10 | * http://www.opensource.org/licenses/bsd-license.php) |
---|
11 | * |
---|
12 | * |
---|
13 | * Redistribution and use in source and binary forms, with or without |
---|
14 | * modification, are permitted provided that the following conditions are |
---|
15 | * met: |
---|
16 | * |
---|
17 | * * Redistributions of source code must retain the above copyright |
---|
18 | * notice, this list of conditions and the following disclaimer. |
---|
19 | * |
---|
20 | * * Redistributions in binary form must reproduce the above copyright |
---|
21 | * notice, this list of conditions and the following disclaimer in |
---|
22 | * the documentation and/or other materials provided with the |
---|
23 | * distribution. |
---|
24 | * |
---|
25 | * * Neither the name of Linköpings universitet nor the names of its |
---|
26 | * contributors may be used to endorse or promote products derived from |
---|
27 | * this software without specific prior written permission. |
---|
28 | * |
---|
29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
30 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
32 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
---|
33 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
---|
34 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
---|
35 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
---|
36 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
---|
37 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
38 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
---|
39 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
40 | */ |
---|
41 | |
---|
42 | package org.modelica.mdt.test; |
---|
43 | |
---|
44 | import org.modelica.mdt.core.IModelicaClass; |
---|
45 | import org.modelica.mdt.core.IModelicaProject; |
---|
46 | import org.modelica.mdt.core.IModelicaSourceFile; |
---|
47 | import org.modelica.mdt.test.util.Area51Projects; |
---|
48 | import org.modelica.mdt.test.util.Utility; |
---|
49 | |
---|
50 | import junit.framework.TestCase; |
---|
51 | |
---|
52 | /** |
---|
53 | * test org.modelica.mdt.core.compiler.ModelicaSourceFile class' code |
---|
54 | */ |
---|
55 | public class TestModelicaSourceFile extends TestCase |
---|
56 | { |
---|
57 | IModelicaSourceFile nestedModelsMo = null; |
---|
58 | |
---|
59 | @Override |
---|
60 | protected void setUp() throws Exception |
---|
61 | { |
---|
62 | Area51Projects.createProjects(); |
---|
63 | |
---|
64 | /* |
---|
65 | * fetch a reference to nested_models.mo source file |
---|
66 | */ |
---|
67 | IModelicaProject proj = |
---|
68 | Utility.getProject(Area51Projects.MODELICA_PROJECT_NAME); |
---|
69 | |
---|
70 | nestedModelsMo = |
---|
71 | Utility.findModelicaFileInFolder(proj.getRootFolder(), |
---|
72 | "nested_models.mo"); |
---|
73 | |
---|
74 | assertNotNull("could not find nested_models.mo file", nestedModelsMo); |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | /** |
---|
79 | * test ModelicaSourceFile.getClassAt() |
---|
80 | */ |
---|
81 | public void testGetClassAt() throws Exception |
---|
82 | { |
---|
83 | IModelicaClass clazz; |
---|
84 | |
---|
85 | clazz = nestedModelsMo.getClassAt(22); |
---|
86 | assertNotNull(clazz); |
---|
87 | assertEquals("nested_models", clazz.getElementName()); |
---|
88 | |
---|
89 | clazz = nestedModelsMo.getClassAt(56); |
---|
90 | assertNotNull(clazz); |
---|
91 | assertEquals("hepp", clazz.getElementName()); |
---|
92 | |
---|
93 | clazz = nestedModelsMo.getClassAt(80); |
---|
94 | assertNotNull(clazz); |
---|
95 | assertEquals("foo", clazz.getElementName()); |
---|
96 | |
---|
97 | clazz = nestedModelsMo.getClassAt(98); |
---|
98 | assertNotNull(clazz); |
---|
99 | assertEquals("bar", clazz.getElementName()); |
---|
100 | |
---|
101 | clazz = nestedModelsMo.getClassAt(164); |
---|
102 | assertNotNull(clazz); |
---|
103 | assertEquals("muu", clazz.getElementName()); |
---|
104 | |
---|
105 | clazz = nestedModelsMo.getClassAt(194); |
---|
106 | assertNull("no class definition should be found here", clazz); |
---|
107 | |
---|
108 | clazz = nestedModelsMo.getClassAt(195); |
---|
109 | assertNull("no class definition should be found here", clazz); |
---|
110 | |
---|
111 | clazz = nestedModelsMo.getClassAt(213); |
---|
112 | assertNotNull(clazz); |
---|
113 | assertEquals("foo", clazz.getElementName()); |
---|
114 | |
---|
115 | clazz = nestedModelsMo.getClassAt(243); |
---|
116 | assertNotNull(clazz); |
---|
117 | assertEquals("hej", clazz.getElementName()); |
---|
118 | |
---|
119 | clazz = nestedModelsMo.getClassAt(263); |
---|
120 | assertNotNull(clazz); |
---|
121 | assertEquals("ine_paketen", clazz.getElementName()); |
---|
122 | |
---|
123 | clazz = nestedModelsMo.getClassAt(310); |
---|
124 | assertNotNull(clazz); |
---|
125 | assertEquals("hejhej", clazz.getElementName()); |
---|
126 | |
---|
127 | clazz = nestedModelsMo.getClassAt(388); |
---|
128 | assertNotNull(clazz); |
---|
129 | assertEquals("hepp", clazz.getElementName()); |
---|
130 | |
---|
131 | /* check at the first character of the definition */ |
---|
132 | clazz = nestedModelsMo.getClassAt(391); |
---|
133 | assertNotNull(clazz); |
---|
134 | assertEquals("hopp", clazz.getElementName()); |
---|
135 | |
---|
136 | clazz = nestedModelsMo.getClassAt(400); |
---|
137 | assertNotNull(clazz); |
---|
138 | assertEquals("hopp", clazz.getElementName()); |
---|
139 | |
---|
140 | /* check at the last character of the definition */ |
---|
141 | clazz = nestedModelsMo.getClassAt(416); |
---|
142 | assertNotNull(clazz); |
---|
143 | assertEquals("hopp", clazz.getElementName()); |
---|
144 | |
---|
145 | clazz = nestedModelsMo.getClassAt(447); |
---|
146 | assertNotNull(clazz); |
---|
147 | assertEquals("hehehe", clazz.getElementName()); |
---|
148 | } |
---|
149 | } |
---|