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

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