source: trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestElementsInfo.java @ 310

Last change on this file since 310 was 310, checked in by boris, 19 years ago
  • create an abstract way to access omc class getElementsInfo() thus close the hole into omc plugin, hurray !
  • added some tests that triggerd some bugs and fixed the bugs
File size: 5.1 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.Path;
45import org.modelica.mdt.core.CompilerProxy;
46import org.modelica.mdt.core.IModelicaProject;
47import org.modelica.mdt.core.IModelicaSourceFile;
48import org.modelica.mdt.core.List;
49import org.modelica.mdt.core.compiler.CompilerInstantiationException;
50import org.modelica.mdt.core.compiler.ConnectException;
51import org.modelica.mdt.core.compiler.ElementsInfo;
52import org.modelica.mdt.core.compiler.InvocationError;
53import org.modelica.mdt.core.compiler.ModelicaParser;
54import org.modelica.mdt.core.compiler.UnexpectedReplyException;
55import org.modelica.mdt.test.util.Area51Projects;
56import org.modelica.mdt.test.util.Utility;
57
58import junit.framework.TestCase;
59
60/**
61 * test org.modelica.mdt.core.compiler.ElementsInfo class' code
62 */
63public class TestElementsInfo extends TestCase
64{
65    @Override
66    protected void setUp() throws Exception
67    {
68        /*
69         * make sure nested_models.mo is created
70         */
71        Area51Projects.createProjects();
72        IModelicaProject proj = 
73            Utility.getProject(Area51Projects.MODELICA_PROJECT_NAME);
74       
75        /*
76         * make sure nested_models.mo are loaded into compiler
77         */
78        IModelicaSourceFile file = 
79            (IModelicaSourceFile)proj.findElement(new Path("nested_models.mo"));
80        file.getChildren();
81    }
82
83    /**
84     * get a list of elements infos on classes defined in nested_models.mo
85     * file in Area51 modelica project and check that fetching fields values
86     * works as expected
87     */
88    public void testFetchingFields()
89        throws ConnectException, InvocationError, 
90            UnexpectedReplyException, CompilerInstantiationException
91    {
92        String elementType;
93        String className;
94       
95        /* do some tests on nested_models class from nested_models.mo */
96        for (ElementsInfo ei : CompilerProxy.getElementsInfo("nested_models"))
97        {
98            elementType = ei.getElementType();
99           
100            if (elementType.equals("classdef"))
101            {
102                className = ei.getClassName();
103               
104                if (className.equals("hepp"))
105                {
106                    assertEquals(3, ei.getElementStartLine());
107                    assertEquals(5, ei.getElementStartColumn());
108                    // this is broken in omc at the moment (rev 2104)
109                    //assertEquals(3, ei.getElementEndLine());
110                    //assertEquals(25, ei.getElementEndColumn());
111                   
112                    assertEquals("RECORD", ei.getClassRestriction());
113                    assertTrue(ei.getClassFile().
114                            endsWith("nested_models.mo"));
115                           
116                }
117                else if (className.equals("foo"))
118                {
119                    assertEquals(4, ei.getElementStartLine());
120                    assertEquals(5, ei.getElementStartColumn());
121                    // this is broken in omc at the moment (rev 2104)
122                    //assertEquals(6, ei.getElementEndLine());
123                    //assertEquals(28, ei.getElementEndColumn());
124
125                    assertEquals("CLASS", ei.getClassRestriction());
126                    assertTrue(ei.getClassFile().
127                            endsWith("nested_models.mo"));                 
128                }
129            }
130        }
131       
132        /* do some tests on muu class from nested_models.mo */
133        for (ElementsInfo ei : CompilerProxy.getElementsInfo("muu"))
134        {
135            if(ei.getElementType().equals("component"))
136            {
137                List comp = ModelicaParser.parseList(ei.getNames());
138               
139                /* check component name */
140                assertEquals("a", comp.elementAt(0).toString());
141                /* check component comment */
142                assertEquals("\"\"", comp.elementAt(1).toString()); 
143               
144                assertEquals("public", ei.getElementVisibility());
145                assertTrue(ei.getElementFile().
146                        endsWith("nested_models.mo"));                 
147
148            }
149        }
150
151    }
152}
Note: See TracBrowser for help on using the repository browser.