source: trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestStandardLibrary.java @ 720

Last change on this file since 720 was 720, checked in by masberg, 13 years ago

Made test project build, it is, however, still unusable due to severe bit-rot

File size: 9.9 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.runtime.CoreException;
45//import org.eclipse.core.runtime.IAdaptable;
46//import org.eclipse.core.runtime.Platform;
47//import org.eclipse.jface.text.IRegion;
48//import org.eclipse.ui.model.IWorkbenchAdapter;
49//import org.modelica.mdt.core.IModelicaClass;
50//import org.modelica.mdt.core.IModelicaComponent;
51//import org.modelica.mdt.core.IModelicaElement;
52//import org.modelica.mdt.core.IModelicaImport;
53//import org.modelica.mdt.core.IStandardLibrary;
54//import org.modelica.mdt.core.ModelicaCore;
55import org.modelica.mdt.core.compiler.CompilerInstantiationException;
56import org.modelica.mdt.core.compiler.ConnectException;
57import org.modelica.mdt.core.compiler.InvocationError;
58import org.modelica.mdt.core.compiler.UnexpectedReplyException;
59//import org.modelica.mdt.internal.core.InnerClass;
60//import org.osgi.framework.Bundle;
61import org.osgi.framework.BundleException;
62
63import junit.framework.TestCase;
64
65/**
66 * Do some sanity checks regarding the standard library
67 */
68public class TestStandardLibrary extends TestCase
69{
70    /**
71     * check that we can convert an IStandardLibrary object, return
72     * by modelica root, to workbench object, etc via the IAdapter
73     * mechanism.
74     *
75     * This is used by the UI layer when displaying modelica standard library
76     * in for example modelica projects view.
77     */
78    public void testStandardLibraryAdapter() throws BundleException
79    {
80//      /*
81//       * the adapter factory that handles standard library object
82//       * is installed by the org.modelica.mdt.ui plugin,
83//       * make sure it is loaded before running tests
84//       */
85//      Bundle bundle = Platform.getBundle("org.modelica.mdt.ui");     
86//      bundle.start();
87//     
88//      IStandardLibrary standardLibrary =
89//          ModelicaCore.getModelicaRoot().getStandardLibrary();
90//
91//      /* check if standard library object is adaptable */
92//      assertTrue("standard library object must be adaptable",
93//              (standardLibrary instanceof IAdaptable));
94//     
95//      /* check if we can convert standard library to workbench adapter */
96//      IWorkbenchAdapter wbAdapter =
97//          (IWorkbenchAdapter)standardLibrary.getAdapter(IWorkbenchAdapter.class);
98//
99//      assertNotNull("could not fetch workbench adapter", wbAdapter);
100//      assertEquals("wrong label", "Standard Library",
101//              wbAdapter.getLabel(standardLibrary));
102//      assertNotNull("no image provided",
103//              wbAdapter.getImageDescriptor(standardLibrary));
104
105    }
106   
107   
108    /**
109     * Do some integrity tests on classes/packages from the standard library.
110     */
111    public void testStandardLibraryElements()
112        throws ConnectException, UnexpectedReplyException, 
113            InvocationError, CompilerInstantiationException, CoreException
114    {
115                       
116//      /* fetch teh Modelica package from the standard library */     
117//      IStandardLibrary standardLibrary =
118//          ModelicaCore.getModelicaRoot().getStandardLibrary();
119//     
120//      InnerClass modelica = null;
121//     
122//      for (IModelicaClass clazz : standardLibrary.getPackages())
123//      {
124//          if (clazz.getElementName().equals("Modelica"))
125//          {
126//              modelica = (InnerClass)clazz;
127//              break;
128//          }
129//      }
130//
131//      assertNotNull("could not found standard library package 'Modelica'",
132//              modelica);
133//
134//     
135//      /*
136//       * do checks on Modelica package
137//       */
138//      assertNull("standard library should be defined outside of workspace",
139//              modelica.getResource());
140//      assertFalse("empty path to the source file",
141//              modelica.getFilePath().equals(""));
142//      IRegion reg = modelica.getLocation();
143//      assertTrue("negative element region can't be", reg.getOffset() >= 0);
144//      assertTrue("elements length must be positive", reg.getLength() > 0);
145//
146//
147//      /*
148//       * do checks on Modelica.Blocks and Modelica.Constants packages
149//       */
150//
151//      InnerClass blocks = null;
152//      InnerClass constants = null;
153//
154//      for (IModelicaElement el : modelica.getChildren())
155//      {
156//          String name = el.getElementName();
157//         
158//          if (name.equals("Blocks"))
159//          {
160//              blocks = (InnerClass)el;
161//          }
162//          else if (name.equals("Constants"))
163//          {
164//              constants = (InnerClass)el;
165//          }
166//      }
167//     
168//      /* check Modelica.Blocks */
169//      assertNotNull("could not find package Modelica.Blocks in standard" +
170//              "library ", blocks);
171//      assertNull("standard library should be defined outside of workspace",
172//              blocks.getResource());
173//      assertFalse("empty path to the source file",
174//              blocks.getFilePath().equals(""));
175//      reg = blocks.getLocation();
176//      assertTrue("negative element region can't be", reg.getOffset() >= 0);
177//      assertTrue("elements length must be positive", reg.getLength() > 0);
178//     
179//      /* check Modelica.Blocks imports */
180//      boolean foundSIimport = false;
181//
182//      for (IModelicaImport imp : blocks.getImports())
183//      {
184//          switch (imp.getType())
185//          {
186//          case RENAMING:
187//              if (imp.getAlias().equals("SI"))
188//              {
189//                  foundSIimport = true;
190//              }
191//              break;
192//              /* ignore all other types of imports */
193//          }
194//      }
195//     
196//      assertTrue("could not find the representation of" +
197//              " 'import SI = Modelica.SIunits;' statment", foundSIimport);
198//     
199//      /* check Modelica.Constants */
200//      assertNotNull("could not find package Modelica.Constants in standard" +
201//              "library ", constants);
202//      assertNull("standard library should be defined outside of workspace",
203//              constants.getResource());
204//      assertFalse("empty path to the source file",
205//              constants.getFilePath().equals(""));
206//      reg = constants.getLocation();
207//      assertTrue("negative element region can't be", reg.getOffset() >= 0);
208//      assertTrue("elements length must be positive", reg.getLength() > 0);
209//
210//      IModelicaComponent pi = null;
211//      IModelicaComponent D2R = null;
212//     
213//      /*
214//       * do checks on Modelica.Constants components
215//       */
216//      for (IModelicaElement el : constants.getChildren())
217//      {
218//          String name = el.getElementName();
219//         
220//          if (name.equals("pi"))
221//          {
222//              pi = (IModelicaComponent)el;
223//          }
224//          else if (name.equals("D2R"))
225//          {
226//              D2R = (IModelicaComponent)el;
227//          }
228//      }
229//
230//      /* check Modelica.Constants.pi */
231//      assertNotNull("could not find package Modelica.Constants.pi in standard"
232//              + "library ", pi);
233//      assertEquals("pi must have public visibility",
234//              IModelicaComponent.Visibility.PUBLIC,
235//              pi.getVisbility());
236//      assertNull("standard library should be defined outside of workspace",
237//              pi.getResource());
238//      assertFalse("empty path to the source file",
239//              pi.getFilePath().equals(""));
240//      reg = pi.getLocation();
241//      assertTrue("negative element region can't be", reg.getOffset() >= 0);
242//      assertTrue("elements length must be positive", reg.getLength() > 0);
243//
244//      /* check Modelica.Constants.D2R */
245//      assertNotNull("could not find package Modelica.Constants.pi in standard"
246//              + "library ", D2R);
247//      assertEquals("pi must have public visibility",
248//              IModelicaComponent.Visibility.PUBLIC,
249//              D2R.getVisbility());
250//      assertNull("standard library should be defined outside of workspace",
251//              D2R.getResource());
252//      assertFalse("empty path to the source file",
253//              D2R.getFilePath().equals(""));
254//      reg = pi.getLocation();
255//      assertTrue("negative element region can't be", reg.getOffset() >= 0);
256//      assertTrue("elements length must be positive", reg.getLength() > 0);
257//     
258//      /* check Modelica.Constants imports */
259//      foundSIimport = false;
260//      boolean foundNonSIimport = false;
261//
262//      for (IModelicaImport imp : constants.getImports())
263//      {
264//          switch (imp.getType())
265//          {
266//          case RENAMING:
267//              if (imp.getAlias().equals("SI"))
268//              {
269//                  foundSIimport = true;
270//              }
271//              else if (imp.getAlias().equals("NonSI"))
272//              {
273//                  foundNonSIimport = true;
274//              }
275//              break;
276//              /* ignore all other types of imports */
277//          }
278//      }
279//     
280//      assertTrue("could not find the representation of" +
281//              " 'import SI = Modelica.SIunits;' statment", foundSIimport);
282//      assertTrue("could not find the representation of" +
283//              " import NonSI = Modelica.SIunits.Conversions.NonSIunits;' " +
284//              "statment", foundNonSIimport);
285    }
286}
Note: See TracBrowser for help on using the repository browser.