source: trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestModelicaElementContentProvider.java @ 523

Last change on this file since 523 was 523, checked in by adrpo, 17 years ago
  • MDT 0.7.1 updates
File size: 5.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 java.util.LinkedList;
45
46import org.eclipse.jface.viewers.TreeViewer;
47import org.eclipse.swt.widgets.Shell;
48import org.eclipse.ui.model.WorkbenchLabelProvider;
49import org.modelica.mdt.core.IModelicaClass;
50import org.modelica.mdt.core.IModelicaProject;
51import org.modelica.mdt.core.IStandardLibrary;
52import org.modelica.mdt.core.ModelicaCore;
53import org.modelica.mdt.core.compiler.CompilerInstantiationException;
54import org.modelica.mdt.core.compiler.ConnectException;
55import org.modelica.mdt.test.util.Area51Projects;
56import org.modelica.mdt.test.util.Utility;
57import org.modelica.mdt.ui.ModelicaElementContentProvider;
58
59import junit.framework.TestCase;
60
61/**
62 * @author Elmir Jagudin
63 */
64public class TestModelicaElementContentProvider extends TestCase
65{
66
67    private IModelicaProject modelicaProject;
68    private IModelicaProject nonModelicaProject;
69   
70    /* the test subject */
71    ModelicaElementContentProvider provider;
72
73   
74    @Override
75    protected void setUp() 
76    {
77        Area51Projects.createProjects();
78       
79        modelicaProject = 
80            Utility.getProject(Area51Projects.MODELICA_PROJECT_NAME);
81       
82        nonModelicaProject = 
83            Utility.getProject(Area51Projects.SIMPLE_PROJECT_NAME);
84       
85        /*
86         * the content provider must be hooked to a viewer
87         * and the input to the viewer must be set,
88         * otherwise stuff will break in bad ways
89         */
90        provider = new ModelicaElementContentProvider();
91        TreeViewer viewer = new TreeViewer(new Shell());
92        viewer.setLabelProvider(new WorkbenchLabelProvider());
93        viewer.setContentProvider(provider);
94        viewer.setInput(ModelicaCore.getModelicaRoot());
95    }
96   
97    /**
98     * this test checks that modelica elements have a system library element
99     * and non-modelica lacks it
100     */
101    public void testPresensOfSystemLibrary()
102    {
103       
104        /*
105         * check that the modelica project have a system library
106         */
107        boolean standardLibraryElementFound = false;
108        for (Object elm : provider.getChildren(modelicaProject))
109        {
110            if (elm instanceof IStandardLibrary)
111            {
112                standardLibraryElementFound = true;
113                break;
114            }
115        }
116        assertTrue("no system library element found in modelica project",
117                standardLibraryElementFound);
118
119        /*
120         * check that the non-modelica project does _not_ have a system library
121         */
122        for (Object elm : provider.getChildren(nonModelicaProject))
123        {
124            if (elm instanceof IStandardLibrary)
125            {
126                fail("non modelica project contains system library");
127            }
128        }
129    }
130   
131    /**
132     * check that content provider returns correkt children
133     * on the standard library object
134     */
135    public void testSystemLibraryChildren()
136        throws ConnectException, CompilerInstantiationException
137    {
138        IStandardLibrary standardLibrary =
139            ModelicaCore.getModelicaRoot().getStandardLibrary(null);
140       
141        assertTrue("standard library node should have children",
142                provider.hasChildren(standardLibrary));
143       
144        /*
145         * build a collection of all children's names that standard library
146         * node should have
147         */
148        LinkedList<String> expectedChildren = 
149            new LinkedList<String>();
150       
151        for (IModelicaClass ch : standardLibrary.getPackages())
152        {
153            expectedChildren.add(ch.getFullName());
154        }
155       
156        /*
157         * check that content provider returns an array of the expected
158         * children (we only check that names match)
159         */
160        for (Object obj : provider.getChildren(standardLibrary))
161        {           
162            assertTrue("provider returned an unexpected child",
163                expectedChildren.remove(((IModelicaClass)obj).getFullName()));
164        }
165       
166        assertTrue("content provider did not return all of the expected children",
167                expectedChildren.isEmpty());
168    }
169
170}
Note: See TracBrowser for help on using the repository browser.