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 java.util.Collections; |
---|
45 | import java.util.Vector; |
---|
46 | |
---|
47 | import org.eclipse.core.resources.IFile; |
---|
48 | import org.eclipse.core.resources.IProject; |
---|
49 | import org.modelica.mdt.core.IModelicaClass.Type; |
---|
50 | import org.modelica.mdt.compiler.CompilerInstantiationException; |
---|
51 | import org.modelica.mdt.compiler.ConnectException; |
---|
52 | import org.modelica.mdt.compiler.IElementLocation; |
---|
53 | import org.modelica.mdt.compiler.InvocationError; |
---|
54 | import org.modelica.mdt.compiler.UnexpectedReplyException; |
---|
55 | import org.modelica.mdt.internal.compiler.CompilerProxy; |
---|
56 | import org.modelica.mdt.test.util.Area51Projects; |
---|
57 | import org.modelica.mdt.test.util.Utility; |
---|
58 | |
---|
59 | import junit.framework.TestCase; |
---|
60 | |
---|
61 | public class TestOMCProxy extends TestCase |
---|
62 | { |
---|
63 | private Vector<String> modelicaLibraryPackages = new Vector<String>(12); |
---|
64 | |
---|
65 | /* a source code file use in some tests */ |
---|
66 | private IFile nested_models_mo; |
---|
67 | |
---|
68 | protected void setUp() |
---|
69 | throws ConnectException, CompilerInstantiationException |
---|
70 | { |
---|
71 | Area51Projects.createProjects(); |
---|
72 | |
---|
73 | /* |
---|
74 | * fetch reference to nested_models.mo file |
---|
75 | * from Area51Projects modelica project |
---|
76 | */ |
---|
77 | IProject proj = Utility.getProject( |
---|
78 | Area51Projects.MODELICA_PROJECT_NAME).getProject(); |
---|
79 | |
---|
80 | nested_models_mo = proj.getFile("nested_models.mo"); |
---|
81 | |
---|
82 | |
---|
83 | assertTrue(Collections.addAll(modelicaLibraryPackages, |
---|
84 | "Mechanics", |
---|
85 | "Electrical", |
---|
86 | "Math", |
---|
87 | "Blocks", |
---|
88 | "Thermal", |
---|
89 | "Icons", |
---|
90 | "Constants", |
---|
91 | "SIunits")); |
---|
92 | |
---|
93 | /* we need to load modelica package */ |
---|
94 | CompilerProxy.loadSystemLibrary(); |
---|
95 | } |
---|
96 | |
---|
97 | /** |
---|
98 | * test OMCProxy.getRestrictionType() |
---|
99 | * @throws CompilerInstantiationException |
---|
100 | */ |
---|
101 | public void testGetRestrictionType() |
---|
102 | throws ConnectException, UnexpectedReplyException, |
---|
103 | CompilerInstantiationException |
---|
104 | { |
---|
105 | if (CompilerProxy.getRestrictionType("Modelica") != Type.PACKAGE) |
---|
106 | { |
---|
107 | fail("Modelica class' restriction type is wrong"); |
---|
108 | } |
---|
109 | if (CompilerProxy.getRestrictionType("Modelica.Blocks.Examples.BusUsage") |
---|
110 | != Type.MODEL) |
---|
111 | { |
---|
112 | fail("Modelica.Blocks.Examples.BusUsage class' " + |
---|
113 | "restriction type is wrong"); |
---|
114 | } |
---|
115 | if (CompilerProxy.getRestrictionType("Modelica.Math.log") |
---|
116 | != Type.FUNCTION) |
---|
117 | { |
---|
118 | fail("Modelica.Math.log class' restriction type is wrong"); |
---|
119 | } |
---|
120 | if (CompilerProxy.getRestrictionType("Modelica.Icons.Record") |
---|
121 | != Type.RECORD) |
---|
122 | { |
---|
123 | fail("Modelica.Icons.Record class' restriction type is wrong"); |
---|
124 | } |
---|
125 | if (CompilerProxy.getRestrictionType("Modelica.Electrical.Analog.Interfaces.Pin") |
---|
126 | != Type.CONNECTOR) |
---|
127 | { |
---|
128 | fail("Modelica.Blocks.Interfaces.BooleanPort class' " + |
---|
129 | "restriction type is wrong"); |
---|
130 | } |
---|
131 | if (CompilerProxy.getRestrictionType("Modelica.Blocks.Continuous.Der") |
---|
132 | != Type.BLOCK) |
---|
133 | { |
---|
134 | fail("Modelica.Blocks.Continuous.Der class' " + |
---|
135 | "restriction type is wrong"); |
---|
136 | } |
---|
137 | if (CompilerProxy.getRestrictionType("Modelica.SIunits.Lethargy") |
---|
138 | != Type.TYPE) |
---|
139 | { |
---|
140 | fail("Modelica.SIunits.Lethargy class' restriction type is wrong"); |
---|
141 | } |
---|
142 | |
---|
143 | CompilerProxy.loadFileInteractive(nested_models_mo); |
---|
144 | if (CompilerProxy.getRestrictionType("hepp.hehehe") |
---|
145 | != Type.CLASS) |
---|
146 | { |
---|
147 | fail("hepp.hehehe class' restriction type is wrong"); |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | /** |
---|
152 | * test OMCProxy.getElementLocation() |
---|
153 | * @throws CompilerInstantiationException |
---|
154 | */ |
---|
155 | public void testGetElementLocation() |
---|
156 | throws ConnectException, UnexpectedReplyException, InvocationError, |
---|
157 | CompilerInstantiationException |
---|
158 | { |
---|
159 | CompilerProxy.loadFileInteractive(nested_models_mo); |
---|
160 | |
---|
161 | /* |
---|
162 | * we are basicaly only interested in getting the right line number |
---|
163 | */ |
---|
164 | IElementLocation loc = CompilerProxy.getElementLocation("nested_models"); |
---|
165 | assertTrue(loc.getPath().endsWith("nested_models.mo")); |
---|
166 | assertEquals(loc.getLine(), 1); |
---|
167 | |
---|
168 | loc = CompilerProxy.getElementLocation("nested_models.hepp"); |
---|
169 | assertEquals(loc.getLine(), 3); |
---|
170 | |
---|
171 | loc = CompilerProxy.getElementLocation("nested_models.foo"); |
---|
172 | assertEquals(loc.getLine(), 4); |
---|
173 | |
---|
174 | loc = CompilerProxy.getElementLocation("nested_models.foo.bar"); |
---|
175 | assertEquals(loc.getLine(), 5); |
---|
176 | |
---|
177 | loc = CompilerProxy.getElementLocation("muu"); |
---|
178 | assertEquals(loc.getLine(), 8); |
---|
179 | |
---|
180 | loc = CompilerProxy.getElementLocation("foo"); |
---|
181 | assertEquals(loc.getLine(), 14); |
---|
182 | |
---|
183 | loc = CompilerProxy.getElementLocation("hej"); |
---|
184 | assertEquals(loc.getLine(), 19); |
---|
185 | |
---|
186 | loc = CompilerProxy.getElementLocation("hej.ine_paketen"); |
---|
187 | assertEquals(loc.getLine(), 20); |
---|
188 | |
---|
189 | loc = CompilerProxy.getElementLocation("hej.hejhej"); |
---|
190 | assertEquals(loc.getLine(), 22); |
---|
191 | |
---|
192 | loc = CompilerProxy.getElementLocation("hej.hejhej.foo"); |
---|
193 | assertEquals(loc.getLine(), 23); |
---|
194 | |
---|
195 | loc = CompilerProxy.getElementLocation("hepp"); |
---|
196 | assertEquals(loc.getLine(), 30); |
---|
197 | |
---|
198 | loc = CompilerProxy.getElementLocation("hepp.hopp"); |
---|
199 | assertEquals(loc.getLine(), 31); |
---|
200 | |
---|
201 | loc = CompilerProxy.getElementLocation("hepp.hehehe"); |
---|
202 | assertEquals(loc.getLine(), 33); |
---|
203 | |
---|
204 | } |
---|
205 | } |
---|