source: trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestModelicaFolder.java @ 271

Last change on this file since 271 was 271, checked in by boris, 19 years ago
  • renaming org.modelica.mdt plugin to org.modelica.mdt.core (step 1)
File size: 6.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 java.util.Collections;
45import java.util.Vector;
46
47import org.eclipse.core.resources.IFile;
48import org.eclipse.core.runtime.CoreException;
49import org.modelica.mdt.core.IModelicaElement;
50import org.modelica.mdt.core.IModelicaFile;
51import org.modelica.mdt.core.IModelicaFolder;
52import org.modelica.mdt.core.compiler.CompilerInstantiationException;
53import org.modelica.mdt.core.compiler.ConnectException;
54import org.modelica.mdt.core.compiler.InvocationError;
55import org.modelica.mdt.core.compiler.UnexpectedReplyException;
56import org.modelica.mdt.test.util.Area51Projects;
57import org.modelica.mdt.test.util.Utility;
58
59import junit.framework.TestCase;
60
61/**
62 * Test various methods in org.modelica.mdt.internal.core.ModelicaFolder
63 *
64 * @author Elmir Jagudin
65 */
66public class TestModelicaFolder extends TestCase
67{
68    /*
69     * the test subject
70     * the root folder of Area51 modelica project
71     */
72    private IModelicaFolder root;
73   
74    /* collection of expected children */
75    private Vector<String> expectedChildren = new Vector<String>(10);   
76    private Vector<String> expectedRootFolderChildren = new Vector<String>(1);
77   
78    /* expected modelica file names in package_look_alike folder */
79    private Vector<String> expectedPackageLookAlikeChildren
80        = new Vector<String>(1);
81   
82    @Override
83    protected void setUp() throws Exception
84    {
85        Area51Projects.createProjects();
86       
87        root = 
88            Utility.getProject(Area51Projects.MODELICA_PROJECT_NAME).
89                getRootFolder();
90       
91        /*
92         * setup expected collections
93         */
94        assertTrue(Collections.addAll(expectedChildren,
95                ".project", "empty_file", "README.txt", "empty_folder", 
96                "root_folder", "package_look_alike", "root_model.mo", 
97                "nested_models.mo", "root_package", "childless_package"));
98               
99        assertTrue(Collections.addAll(expectedRootFolderChildren,
100                "hej_hopp"));
101
102        assertTrue(Collections.addAll(expectedPackageLookAlikeChildren,
103                "package.mo"));
104    }
105
106    /**
107     * test ModelicaFolder.hasChildren()
108     */
109    public void testHasChildren()
110    {
111        try 
112        {
113            assertTrue(root.hasChildren());
114        }
115        catch (Exception e)
116        {
117            fail("exception thrown " + e.getMessage());
118        }
119    }
120
121    /**
122     * test ModelciaFoldet.getChildren()
123     * @throws CompilerInstantiationException
124     *
125     */
126    public void testGetChildren() 
127        throws ConnectException, UnexpectedReplyException, 
128            InvocationError, CoreException, CompilerInstantiationException
129    {
130        IModelicaFolder root_folder = null;
131        IModelicaFolder empty_folder = null;
132        IModelicaFolder package_look_alike = null;
133       
134       
135        String name = "";
136        for (Object elm : root.getChildren())
137        {
138           
139            if (elm instanceof IFile)
140            {
141                name = ((IFile)elm).getName();
142            }
143            else
144            {
145                name = ((IModelicaElement)elm).getElementName();
146            }
147            expectedChildren.remove(name);
148           
149            if (name.equals("root_folder"))
150            {
151                root_folder = (IModelicaFolder) elm;
152            }
153            else if (name.equals("empty_folder"))
154            {
155                empty_folder = (IModelicaFolder) elm;
156            }
157            else if (name.equals("package_look_alike"))
158            {
159                package_look_alike = (IModelicaFolder) elm;
160            }
161
162        }
163        assertTrue("could not find all expected children in the root folder",
164                expectedChildren.isEmpty());
165       
166        assertNotNull("root_folder element not found", root_folder);
167        assertNotNull("empty_folder element not found", empty_folder);
168        assertNotNull("package_look_alike element not found",
169                package_look_alike);
170       
171        for (Object elm : root_folder.getChildren())
172        {
173            if (elm instanceof IFile)
174            {
175                /* we only expect (looking for) files inside root_folder */
176                name = ((IFile)elm).getName();
177                expectedRootFolderChildren.remove(name);
178            }
179        }
180        assertTrue("could no find all expected files in root_folder",
181                expectedRootFolderChildren.isEmpty());
182       
183        for (Object elm : package_look_alike.getChildren())
184        {
185            if (elm instanceof IModelicaFile)
186            {
187                /*
188                 * we only expect (looking for) modelica files
189                 * inside package_look_alike
190                 */
191                name = ((IModelicaFile)elm).getElementName();
192                expectedPackageLookAlikeChildren.remove(name);
193            }
194        }
195        assertTrue("could no find all expected files in package_look_alike",
196                expectedPackageLookAlikeChildren.isEmpty());
197       
198        /*
199         * test the empty_folder IS empty
200         */
201        assertFalse("empty_folder not empty", empty_folder.hasChildren());
202        assertTrue("empty_folder returns children", 
203                empty_folder.getChildren().isEmpty());
204    }
205}
Note: See TracBrowser for help on using the repository browser.