source: trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestOMCProxy.java @ 270

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