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.IProject; |
---|
48 | import org.modelica.mdt.internal.omcproxy.CompilerException; |
---|
49 | import org.modelica.mdt.internal.omcproxy.ConnectionException; |
---|
50 | import org.modelica.mdt.internal.omcproxy.ElementLocation; |
---|
51 | import org.modelica.mdt.internal.omcproxy.InvocationError; |
---|
52 | import org.modelica.mdt.internal.omcproxy.OMCProxy; |
---|
53 | import org.modelica.mdt.internal.omcproxy.UnexpectedReplyException; |
---|
54 | import org.modelica.mdt.test.util.Area51Projects; |
---|
55 | import org.modelica.mdt.test.util.Utility; |
---|
56 | |
---|
57 | import junit.framework.TestCase; |
---|
58 | |
---|
59 | public class TestOMCProxy extends TestCase |
---|
60 | { |
---|
61 | private Vector<String> modelicaLibraryPackages = new Vector<String>(12); |
---|
62 | |
---|
63 | protected void setUp() |
---|
64 | { |
---|
65 | Area51Projects.createProjects(); |
---|
66 | |
---|
67 | assertTrue(Collections.addAll(modelicaLibraryPackages, |
---|
68 | "Mechanics", |
---|
69 | "Electrical", |
---|
70 | "Math", |
---|
71 | "Blocks", |
---|
72 | "Thermal", |
---|
73 | "Icons", |
---|
74 | "Constants", |
---|
75 | "SIunits")); |
---|
76 | } |
---|
77 | |
---|
78 | /** |
---|
79 | * test OMCProxy.getPackages() |
---|
80 | */ |
---|
81 | public void testGetPackages() |
---|
82 | { |
---|
83 | try |
---|
84 | { |
---|
85 | OMCProxy.loadSystemLibrary(); |
---|
86 | String[] str = OMCProxy.getPackages("Modelica"); |
---|
87 | |
---|
88 | assertNotNull("Could not fetch Modelica package", str); |
---|
89 | |
---|
90 | Vector<String> packages = new Vector<String>(); |
---|
91 | for(String s : str) |
---|
92 | { |
---|
93 | packages.addElement(s); |
---|
94 | } |
---|
95 | |
---|
96 | assertTrue(packages.containsAll(modelicaLibraryPackages)); |
---|
97 | } |
---|
98 | catch(CompilerException e) |
---|
99 | { |
---|
100 | fail(e.getMessage()); |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | /** |
---|
105 | * test OMCProxy.getElementLocation() |
---|
106 | */ |
---|
107 | public void testGetElementLocation() |
---|
108 | throws ConnectionException, UnexpectedReplyException, InvocationError |
---|
109 | { |
---|
110 | /* load file nested_models.mo from Area51Projects modelica project */ |
---|
111 | IProject proj = Utility.getProject( |
---|
112 | Area51Projects.MODELICA_PROJECT_NAME).getProject(); |
---|
113 | |
---|
114 | OMCProxy.loadFileInteractive(proj.getFile("nested_models.mo")); |
---|
115 | |
---|
116 | /* |
---|
117 | * we are basicaly only interested in getting the right line number |
---|
118 | */ |
---|
119 | ElementLocation loc = OMCProxy.getElementLocation("nested_models"); |
---|
120 | assertTrue(loc.getPath().endsWith("nested_models.mo")); |
---|
121 | assertEquals(loc.getLine(), 1); |
---|
122 | |
---|
123 | loc = OMCProxy.getElementLocation("nested_models.hepp"); |
---|
124 | assertEquals(loc.getLine(), 3); |
---|
125 | |
---|
126 | loc = OMCProxy.getElementLocation("nested_models.foo"); |
---|
127 | assertEquals(loc.getLine(), 4); |
---|
128 | |
---|
129 | loc = OMCProxy.getElementLocation("nested_models.foo.bar"); |
---|
130 | assertEquals(loc.getLine(), 5); |
---|
131 | |
---|
132 | loc = OMCProxy.getElementLocation("muu"); |
---|
133 | assertEquals(loc.getLine(), 8); |
---|
134 | |
---|
135 | loc = OMCProxy.getElementLocation("foo"); |
---|
136 | assertEquals(loc.getLine(), 14); |
---|
137 | |
---|
138 | loc = OMCProxy.getElementLocation("hej"); |
---|
139 | assertEquals(loc.getLine(), 19); |
---|
140 | |
---|
141 | loc = OMCProxy.getElementLocation("hej.ine_paketen"); |
---|
142 | assertEquals(loc.getLine(), 20); |
---|
143 | |
---|
144 | loc = OMCProxy.getElementLocation("hej.hejhej"); |
---|
145 | assertEquals(loc.getLine(), 22); |
---|
146 | |
---|
147 | loc = OMCProxy.getElementLocation("hej.hejhej.foo"); |
---|
148 | assertEquals(loc.getLine(), 23); |
---|
149 | |
---|
150 | loc = OMCProxy.getElementLocation("hepp"); |
---|
151 | assertEquals(loc.getLine(), 30); |
---|
152 | |
---|
153 | loc = OMCProxy.getElementLocation("hepp.hopp"); |
---|
154 | assertEquals(loc.getLine(), 31); |
---|
155 | |
---|
156 | loc = OMCProxy.getElementLocation("hepp.hehehe"); |
---|
157 | assertEquals(loc.getLine(), 33); |
---|
158 | |
---|
159 | } |
---|
160 | } |
---|