source: trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestTraversingPackages.java @ 240

Last change on this file since 240 was 240, checked in by boris, 19 years ago
  • moved out code that handles communication with OMC to a separate plugin
File size: 7.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.resources.IFile;
45import org.eclipse.core.runtime.CoreException;
46import org.modelica.mdt.core.IModelicaElement;
47import org.modelica.mdt.core.IModelicaFile;
48import org.modelica.mdt.core.IModelicaFolder;
49import org.modelica.mdt.core.IModelicaClass;
50import org.modelica.mdt.compiler.CompilerException;
51import org.modelica.mdt.test.util.Area51Projects;
52import org.modelica.mdt.test.util.Utility;
53
54import junit.framework.TestCase;
55
56/**
57 * Traverses a heirarchy of packages and makes consistensy checks.
58 *
59 * @author Elmir Jagudin
60 */
61public class TestTraversingPackages extends TestCase
62{
63    private IModelicaFolder project_root = null;
64   
65    @Override
66    protected void setUp() throws Exception
67    {
68        /*
69         * create the project and fetch the reference to the root folder
70         */
71        Area51Projects.createProjects();
72       
73        project_root = 
74            Utility.getProject(Area51Projects.MODELICA_PROJECT_NAME).getRootFolder();
75       
76    }
77   
78    public void testTraverse() throws CoreException, CompilerException
79    {
80        IModelicaClass root_package = null;
81        IModelicaClass childless_package = null;
82        IModelicaFile root_package_model = null;
83        IModelicaFile root_package_function = null;
84
85        /* for a temporary reference oo package.mo */
86        IModelicaFile package_mo = null;
87
88        /* root_package/plain_file */
89        IFile root_package_plain_file = null;
90
91        /* root_package/root_package_folder */
92        IModelicaFolder root_package_folder = null;
93       
94        IModelicaClass sub_package = null;
95        IModelicaClass leaf_package = null;
96        IModelicaFile sub_package_model = null;
97
98        /*
99         * traverse children of project_root
100         */
101        String name;
102        for (Object elm : project_root.getChildren())
103        {
104            if (elm instanceof IFile)
105            {
106                name = ((IFile)elm).getName();
107            }
108            else
109            {
110                name = ((IModelicaElement)elm).getElementName();
111            }
112
113            if (name.equals("root_package"))
114            {
115                root_package = (IModelicaClass)elm;
116            }
117            else if (name.equals("childless_package"))
118            {
119                childless_package = (IModelicaClass)elm;
120            }
121        }
122
123        assertNotNull("root_package not found", root_package);
124        assertEquals("Package base name", root_package.getPrefix(), "");
125        assertEquals("Package name", root_package.getElementName(), 
126                "root_package");
127               
128        assertNotNull("childless_package not found", childless_package);
129        assertEquals("Package base name", childless_package.getPrefix(), "");
130        assertEquals("Package name", childless_package.getElementName(), 
131                "childless_package");
132       
133        /*
134         * traverse children of root_package
135         */
136        for (Object elm : root_package.getChildren())
137        {
138            if (elm instanceof IFile)
139            {
140                name = ((IFile)elm).getName();
141            }
142            else
143            {
144                name = ((IModelicaElement)elm).getElementName();
145            }
146
147            if (name.equals("sub_package"))
148            {
149                sub_package = (IModelicaClass)elm;
150            }
151            else if (name.equals("root_package_model.mo"))
152            {
153                root_package_model = (IModelicaFile)elm;
154            }
155            else if (name.equals("root_package_function.mo"))
156            {
157                root_package_function = (IModelicaFile)elm;
158            }
159            else if (name.equals("package.mo"))
160            {
161                package_mo = (IModelicaFile)elm;
162            }
163            else if (name.equals("plain_file"))
164            {
165                root_package_plain_file = (IFile)elm;;
166            }
167            else if (name.equals("root_package_folder"))
168            {
169                    root_package_folder = (IModelicaFolder)elm;;
170            }
171           
172        }
173
174        assertNotNull("sub_package not found", sub_package);
175        checkFullName(sub_package, "root_package.sub_package");
176
177        assertNotNull("root_package_model.mo not found", root_package_model);
178        assertNotNull("root_package_function.mo not found", 
179                root_package_function);
180        assertNotNull("root_package/package.mo not found",
181                package_mo);
182        assertNotNull("root_package/plain_file not found",
183                root_package_plain_file);
184        assertNotNull("root_package/root_package_folder not found",
185                root_package_folder);
186
187
188        /*
189         * traverse children of sub_package
190         */
191
192        /* traverse packages */     
193        for (Object elm : sub_package.getChildren())
194        {
195            if (elm instanceof IFile)
196            {
197                name = ((IFile)elm).getName();
198            }
199            else
200            {
201                name = ((IModelicaElement)elm).getElementName();
202            }
203           
204            if (name.equals("leaf_package"))
205            {
206                leaf_package = (IModelicaClass)elm;
207            }
208            else if (name.equals("package.mo"))
209            {
210                package_mo = (IModelicaFile)elm;
211            }
212            else if (name.equals("sub_package_model.mo"))
213            {
214                sub_package_model = (IModelicaFile)elm;
215            }       
216
217        }
218        assertNotNull("leaf_package not found", leaf_package);
219        checkFullName(leaf_package, "root_package.sub_package.leaf_package");
220        assertNotNull("root_package/sub_package/package.mo not found",
221                package_mo);
222        assertNotNull("root_package/sub_package/sub_package_model.mo not found",
223                sub_package_model);
224
225    }
226
227    /**
228     * Check that ze package's full name matches the fullName, otherwize
229     * fails.
230     * @param zePackage
231     * @param fullName
232     */
233    private void checkFullName(IModelicaClass zePackage, String fullName) 
234    {
235        assertEquals("Package full name does not match",
236                     fullName, 
237                     zePackage.getPrefix() + "." + 
238                             zePackage.getElementName());
239    }
240}
Note: See TracBrowser for help on using the repository browser.