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

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