source: trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestModelicaRoot.java @ 160

Last change on this file since 160 was 152, checked in by boris, 19 years ago
  • added a test for problem marker creator (aka the builder)
File size: 4.4 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.IProject;
45import org.eclipse.core.resources.ResourcesPlugin;
46import org.eclipse.core.runtime.CoreException;
47import org.eclipse.core.resources.IWorkspaceRoot;
48
49import org.eclipse.ui.PlatformUI;
50
51import org.modelica.mdt.MdtPlugin;
52import org.modelica.mdt.core.IModelicaProject;
53import org.modelica.mdt.core.IModelicaRoot;
54import org.modelica.mdt.core.ModelicaCore;
55import org.modelica.mdt.test.util.Area51Projects;
56
57import junit.framework.TestCase;
58
59/**
60 * @author Elmir Jagudin
61 *
62 */
63public class TestModelicaRoot extends TestCase
64{
65
66    private static final String PROJECT_NAME_1 = 
67        TestModelicaRoot.class.getName() + "1";
68    private static final String PROJECT_NAME_2 = 
69        TestModelicaRoot.class.getName() + "2";
70    private static final String PROJECT_NAME_3 = 
71        TestModelicaRoot.class.getName() + "3";
72   
73    private IModelicaRoot modelicaRoot = ModelicaCore.getModelicaRoot();
74   
75    @Override
76    protected void setUp() throws Exception
77    {
78        Area51Projects.createProjects();
79        IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
80         
81        /*
82         * create a modelica project
83         */
84        IProject project = 
85            ModelicaCore.createProject(PROJECT_NAME_1, 
86                    PlatformUI.getWorkbench().getActiveWorkbenchWindow());
87        assertNotNull("failed to create project", project);
88       
89        /*
90         * create a regular projects
91         */
92        project = workspaceRoot.getProject(PROJECT_NAME_2);
93        project.create(null);
94        project.open(null);
95       
96        /*
97         * create a regular projects which remains closed
98         */
99        project = workspaceRoot.getProject(PROJECT_NAME_3);
100        project.create(null);
101
102    }
103   
104    public void testProjectsEnumeration()
105    {
106        try 
107        {
108            /*
109             * check that all wrapped (with IModelicaProject) projects have
110             * modelica nature and check that non of the unwrapped projects
111             * have modelica nature
112             */
113            Object[] projs = modelicaRoot.getProjects();
114            for (Object p : projs)
115            {
116                if (p instanceof IModelicaProject)
117                {
118                    if (((IModelicaProject)p).getProject().isOpen())
119                    {
120                        assertTrue("project without modelica nature wrapped",
121                            ((IModelicaProject)p).getProject().
122                            hasNature(MdtPlugin.MODELICA_NATURE));
123                    }
124                }
125                else if (p instanceof IProject)
126                {
127                    if (((IProject)p).isOpen())
128                    {
129                        assertFalse("project with modelica nature not wrapped",
130                            ((IProject)p).hasNature(MdtPlugin.MODELICA_NATURE));
131                    }
132                }
133                else
134                {
135                    fail("unexpected type of project");
136                }
137            }
138        }
139        catch (CoreException e) 
140        {
141            fail("could not get projects list, exception thrown:" + e);
142        }
143    }
144}
Note: See TracBrowser for help on using the repository browser.