source: trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestInnerClass.java @ 302

Last change on this file since 302 was 288, checked in by boris, 19 years ago
  • added a 'parent package' field to new package dialog and implemented infrastructure to be animate it among others:
  • IModelicaProject.getPackageRoots() method to fetch all top level package in a project
  • IModelicaProject.getPackage() method to fetch a package by its full name
  • IModelicaProject.findElement() method to fetch project's elements by path
  • modelica source files are now wraped by IModelicaSourceFile
  • plain files are now wraped by IModelicaFile inside a modelica project
  • an abstract wizard page superclass NewTypePage? added wich implemets source and parent package fields which are used in createing new classes/packages
  • some other stuff i forgot about, this kinda got out of hand, smaller commits in the future !
File size: 11.2 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 org.eclipse.core.runtime.CoreException;
45import org.eclipse.jface.text.IRegion;
46import org.modelica.mdt.core.IModelicaClass;
47import org.modelica.mdt.core.IModelicaComponent;
48import org.modelica.mdt.core.IModelicaSourceFile;
49import org.modelica.mdt.core.IModelicaProject;
50import org.modelica.mdt.core.compiler.CompilerInstantiationException;
51import org.modelica.mdt.core.compiler.ConnectException;
52import org.modelica.mdt.core.compiler.InvocationError;
53import org.modelica.mdt.core.compiler.UnexpectedReplyException;
54import org.modelica.mdt.internal.core.InnerClass;
55import org.modelica.mdt.test.util.Area51Projects;
56import org.modelica.mdt.test.util.Utility;
57
58import junit.framework.TestCase;
59
60/**
61 * @author Elmir Jagudin
62 */
63
64public class TestInnerClass extends TestCase
65{
66
67    /* the test subject */
68    private InnerClass componentsBananza;
69    @Override
70    protected void setUp() throws Exception
71    {
72        Area51Projects.createProjects();
73       
74        /* navigate to the model 'component_bananza' */
75        IModelicaProject proj = 
76            Utility.getProject(Area51Projects.MODELICA_PROJECT_NAME);
77       
78        IModelicaSourceFile file = 
79            Utility.findModelicaFileInFolder(proj.getRootFolder(), 
80                "component_model.mo");
81       
82        componentsBananza = null;
83        for (Object obj : file.getChildren())
84        {
85            if (obj instanceof InnerClass)
86            {
87                if (((InnerClass)obj).getElementName().equals("components_bananza"))
88                {
89                    componentsBananza = (InnerClass)obj;
90                    break;
91                }
92            }
93        }
94       
95        assertNotNull("could not find the model component_bonanza",
96                componentsBananza);
97
98    }
99   
100    /**
101     * do some sanity checks on InnerClass children
102     *
103     * @throws CoreException
104     * @throws InvocationError
105     * @throws UnexpectedReplyException
106     * @throws ConnectException
107     * @throws CompilerInstantiationException
108     */
109    public void testChildren()
110    throws ConnectException, UnexpectedReplyException,
111        InvocationError, CoreException, CompilerInstantiationException
112    { 
113        IModelicaComponent a_real = null;
114        IModelicaComponent an_undocumented_real = null;
115        IModelicaComponent a_protected_real = null;
116        IModelicaComponent a_protected_integer = null;
117        IModelicaClass a_package = null;
118        IModelicaClass a_class = null;
119        IModelicaClass a_model = null;
120        IModelicaClass a_connector = null;
121        IModelicaClass a_record = null;
122        IModelicaClass a_block = null;
123        IModelicaClass a_type = null;
124        IModelicaClass a_function = null;       
125       
126       
127        /*
128         * fetch children to local variables
129         * so we can perfort check on 'em
130         */
131        for (Object obj : componentsBananza.getChildren())
132        {
133            if (obj instanceof IModelicaComponent)
134            {
135                IModelicaComponent comp = (IModelicaComponent) obj;
136               
137                if (comp.getElementName().endsWith("a_real"))
138                {
139                    a_real = comp;
140                }
141                else if (comp.getElementName().endsWith("an_undocumented_real"))
142                {
143                    an_undocumented_real = comp;
144                }
145                else if (comp.getElementName().endsWith("a_protected_real"))
146                {
147                    a_protected_real = comp;
148                }
149                else if (comp.getElementName().endsWith("a_protected_integer"))
150                {
151                    a_protected_integer = comp;
152                }
153            }
154            else if (obj instanceof IModelicaClass)
155            {
156                switch (((IModelicaClass)obj).getRestrictionType())
157                {
158                case PACKAGE:
159                    a_package = (IModelicaClass)obj;
160                    break;
161                case BLOCK:
162                    a_block = (IModelicaClass)obj;
163                    break;
164                case CLASS:
165                    a_class = (IModelicaClass)obj;
166                    break;
167                case CONNECTOR:
168                    a_connector = (IModelicaClass)obj;
169                    break;
170                case FUNCTION:
171                    a_function = (IModelicaClass)obj;
172                    break;
173                case MODEL:
174                    a_model = (IModelicaClass)obj;
175                    break;
176                case RECORD:
177                    a_record = (IModelicaClass)obj;
178                    break;
179                case TYPE:
180                    a_type = (IModelicaClass)obj;
181                    break;
182                }
183            }
184        }
185       
186        /* sanity checks on components_bananza.a_type */
187        assertNotNull("components_bananza.a_type not found", a_type);
188        assertEquals("wrong element name", a_type.getElementName(), "a_type");
189        assertTrue("fishy file path", 
190                a_type.getFilePath().endsWith("component_model.mo"));
191        IRegion reg = a_type.getLocation();
192        assertEquals("wrong start offset", 338, reg.getOffset());
193        assertEquals("wrong length", 28, reg.getLength());
194
195        /* sanity checks on components_bananza.a_package */
196        assertNotNull("components_bananza.a_package not found", a_package);
197        assertEquals("wrong element name",
198                a_package.getElementName(), "a_package");
199        assertTrue("fishy file path", 
200                a_package.getFilePath().endsWith("component_model.mo"));
201        reg = a_package.getLocation();
202        assertEquals("wrong start offset", 91, reg.getOffset());
203        assertEquals("wrong length", 37, reg.getLength());
204
205        /* sanity checks on components_bananza.a_block */
206        assertNotNull("components_bananza.a_block not found", a_block);
207        assertEquals("wrong element name",
208                a_block.getElementName(), "a_block");
209        assertTrue("fishy file path", 
210                a_block.getFilePath().endsWith("component_model.mo"));
211        reg = a_block.getLocation();
212        assertEquals("wrong start offset", 267, reg.getOffset());
213        assertEquals("wrong length", 31, reg.getLength());
214
215        /* sanity checks on components_bananza.a_class */
216        assertNotNull("components_bananza.a_class not found", a_class);
217        assertEquals("wrong element name", a_class.getElementName(), "a_class");
218        assertTrue("fishy file path", 
219                a_class.getFilePath().endsWith("component_model.mo"));
220        reg = a_class.getLocation();
221        assertEquals("wrong start offset", 128, reg.getOffset());
222        assertEquals("wrong length", 31, reg.getLength());
223
224        /* sanity checks on components_bananza.a_connector */
225        assertNotNull("components_bananza.a_connector not found", a_connector);
226        assertEquals("wrong element name", a_connector.getElementName(), 
227                "a_connector");
228        assertTrue("fishy file path", 
229                a_connector.getFilePath().endsWith("component_model.mo"));
230        reg = a_connector.getLocation();
231        assertEquals("wrong start offset", 190, reg.getOffset());
232        assertEquals("wrong length", 43, reg.getLength());
233
234        /* sanity checks on components_bananza.a_function */
235        assertNotNull("components_bananza.a_function not found", a_function);
236        assertEquals("wrong element name", a_function.getElementName(),
237                "a_function");
238        assertTrue("fishy file path", 
239                a_function.getFilePath().endsWith("component_model.mo"));
240        reg = a_function.getLocation();
241        assertEquals("wrong start offset", 298, reg.getOffset());
242        assertEquals("wrong length", 40, reg.getLength());
243
244        /* sanity checks on components_bananza.a_model */
245        assertNotNull("components_bananza.a_model not found", a_model);
246        assertEquals("wrong element name", a_model.getElementName(), "a_model");
247        assertTrue("fishy file path", 
248                a_model.getFilePath().endsWith("component_model.mo"));
249        reg = a_model.getLocation();
250        assertEquals("wrong start offset", 159, reg.getOffset());
251        assertEquals("wrong length", 31, reg.getLength());
252
253        /* sanity checks on components_bananza.a_record */
254        assertNotNull("components_bananza.a_record not found", a_record);
255        assertEquals("wrong element name", a_record.getElementName(), "a_record");
256        assertTrue("fishy file path", 
257                a_record.getFilePath().endsWith("component_model.mo"));
258        reg = a_record.getLocation();
259        assertEquals("wrong start offset", 233, reg.getOffset());
260        assertEquals("wrong length", 34, reg.getLength());
261
262        /* sanity checks on components_bananza.a_real */
263        assertNotNull("components_bananza.a_real not found", a_real);
264        assertEquals("wrong element name", a_real.getElementName(), "a_real");
265        assertEquals("wrong visibility", a_real.getVisbility(),
266                IModelicaComponent.Visibility.PUBLIC);
267
268        reg = a_real.getLocation();
269        assertEquals("wrong start offset", 25, reg.getOffset());
270        assertEquals("wrong length", 35, reg.getLength());
271       
272        /* sanity checks on components_bananza.a_undocumented_real */
273        assertNotNull("components_bananza.an_undocumented_real not found", 
274                an_undocumented_real);
275        assertEquals("wrong element name", an_undocumented_real.getElementName(),
276                "an_undocumented_real");
277        assertEquals("wrong visibility", an_undocumented_real.getVisbility(),
278                IModelicaComponent.Visibility.PUBLIC);
279        reg = an_undocumented_real.getLocation();
280        assertEquals("wrong start offset", 60, reg.getOffset());
281        assertEquals("wrong length", 31, reg.getLength());
282       
283        /* sanity checks on components_bananza.a_protected_integer */
284        assertNotNull("components_bananza.a_protected_integer not found", 
285                a_protected_integer);
286        assertEquals("wrong element name", a_protected_integer.getElementName(),
287                "a_protected_integer");
288        assertEquals("wrong visibility", a_protected_integer.getVisbility(),
289                IModelicaComponent.Visibility.PROTECTED);
290        reg = a_protected_integer.getLocation();
291        assertEquals("wrong start offset", 400, reg.getOffset());
292        assertEquals("wrong length", 47, reg.getLength());
293
294
295        /* sanity checks on components_bananza.a_protected_real */
296        assertNotNull("components_bananza.a_protected_real not found", 
297                a_protected_real);
298        assertEquals("wrong element name", a_protected_real.getElementName(), 
299                "a_protected_real");
300        assertEquals("wrong visibility", a_protected_real.getVisbility(),
301                IModelicaComponent.Visibility.PROTECTED);
302        reg = a_protected_real.getLocation();
303        assertEquals("wrong start offset", 376, reg.getOffset());
304        assertEquals("wrong length", 24, reg.getLength());
305
306    } 
307}
Note: See TracBrowser for help on using the repository browser.