Ignore:
Timestamp:
01/24/12 21:44:17 (13 years ago)
Author:
masberg
Message:

Fix standard library tests which now work since revision 1234 fixed the loading of the Modelica standard library.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestStandardLibrary.java

    r1096 r1235  
    4141
    4242package org.modelica.mdt.test;
     43
     44import static org.junit.Assert.assertEquals;
     45import static org.junit.Assert.assertFalse;
     46import static org.junit.Assert.assertNotNull;
     47import static org.junit.Assert.assertNull;
     48import static org.junit.Assert.assertTrue;
    4349
    4450import java.util.Collection;
     
    6672import org.osgi.framework.BundleException;
    6773
    68 import static org.junit.Assert.assertEquals;
    69 import static org.junit.Assert.assertFalse;
    70 import static org.junit.Assert.assertNotNull;
    71 import static org.junit.Assert.assertNull;
    72 import static org.junit.Assert.assertTrue;
    73 
    7474/**
    7575 * Do some sanity checks regarding the standard library
     
    7777public class TestStandardLibrary {
    7878    private IStandardLibrary standardLibrary;
    79    
     79
    8080    @org.junit.Before
    8181    public void setUp() throws BundleException {
    82         /*
    83          * the adapter factory that handles standard library object
    84          * is installed by the org.modelica.mdt.ui plugin,
    85          * make sure it is loaded before running tests
    86          */
     82        // the adapter factory that handles standard library object
     83        // is installed by the org.modelica.mdt.ui plugin,
     84        // make sure it is loaded before running tests
    8785        Bundle bundle = Platform.getBundle("org.modelica.mdt.ui");     
    8886        bundle.start();
    89        
     87
    9088        IModelicaRoot modelicaRoot = ModelicaCore.getModelicaRoot();
    9189        standardLibrary = modelicaRoot.getStandardLibrary(null);
     
    102100    @org.junit.Test
    103101    public void testStandardLibraryAdapter() {
    104         /* check if standard library object is adaptable */
    105         assertTrue("standard library object must be adaptable",
    106                 (standardLibrary instanceof IAdaptable));
    107        
    108         /* check if we can convert standard library to workbench adapter */
     102        // check if standard library object is adaptable
     103        boolean instanceOfIAdaptable = standardLibrary instanceof IAdaptable;
     104        assertTrue("standard library object must be adaptable", instanceOfIAdaptable);
     105
     106        // check if we can convert standard library to workbench adapter
    109107        IWorkbenchAdapter wbAdapter =
    110             (IWorkbenchAdapter)standardLibrary.getAdapter(IWorkbenchAdapter.class);
     108                (IWorkbenchAdapter)standardLibrary.getAdapter(IWorkbenchAdapter.class);
    111109
    112110        assertNotNull("could not fetch workbench adapter", wbAdapter);
    113        
    114         /* FIXME : wbAdapter.getLabel(standardLibrary) is returning something weird right now,
    115          * at least on Windows, let's disable this test until we can investigate. */
     111
    116112        String label = wbAdapter.getLabel(standardLibrary);
    117         assertEquals("wrong label", "Standard Library", label);
     113        assertTrue("wrong label", label.startsWith("Libraries: "));
     114        assertTrue("wrong label", label.endsWith("omlibrary"));
    118115        ImageDescriptor imageDescriptor = wbAdapter.getImageDescriptor(standardLibrary);
    119116        assertNotNull("no image provided", imageDescriptor);
     
    125122    @org.junit.Test
    126123    public void testStandardLibraryElements()
    127         throws ConnectException, UnexpectedReplyException, InvocationError, CompilerInstantiationException, CoreException {
    128         /* Fetch the Modelica package from the standard library. */
     124            throws ConnectException, UnexpectedReplyException, InvocationError, CompilerInstantiationException, CoreException {
     125        // Fetch the Modelica package from the standard library.
    129126        Collection<IModelicaClass> packages = standardLibrary.getPackages();
    130127        InnerClass modelica = null;
    131        
    132         String desiredPackageName = "Modelica 3.2";
    133        
     128
     129        String desiredPackageName = "Modelica";
     130
    134131        for (IModelicaClass modelicaClass : packages) {
    135132            String elementName = modelicaClass.getElementName();
    136            
     133
    137134            if (elementName.equals(desiredPackageName)) {
    138135                modelica = (InnerClass)modelicaClass;
     
    142139        assertNotNull("Could not find standard library package \"" + desiredPackageName + "\".", modelica);
    143140
    144         /*
    145          * do checks on Modelica package
    146          */
     141        // do checks on Modelica package
    147142        IResource modelicaResource = modelica.getResource();
    148143        assertNull("Standard library should be defined outside of workspace.", modelicaResource);
     
    150145        boolean modelicaFilePathEmpty = modelicaFilePath.equals("");
    151146        assertFalse("Empty path to the source file.", modelicaFilePathEmpty);
    152 //      IRegion reg = modelica.getLocation();
    153 //      assertTrue("negative element region can't be", reg.getOffset() >= 0);
    154 //      assertTrue("elements length must be positive", reg.getLength() > 0);
    155 
    156         /*
    157          * do checks on Modelica.Blocks and Modelica.Constants packages
    158          */
     147        //IRegion reg = modelica.getLocation();
     148        //assertTrue("negative element region can't be", reg.getOffset() >= 0);
     149        //assertTrue("elements length must be positive", reg.getLength() > 0);
     150
     151        // do checks on Modelica.Blocks and Modelica.Constants packages
    159152        InnerClass blocks = null;
    160153        InnerClass constants = null;
     
    162155        for (IModelicaElement el : modelicaChildren) {
    163156            String name = el.getElementName();
    164            
     157
    165158            if (name.equals("Blocks")) {
    166159                blocks = (InnerClass)el;
     
    170163            }
    171164        }
    172        
    173         /* check Modelica.Blocks */
     165
     166        // check Modelica.Blocks
    174167        assertNotNull("Could not find package Modelica.Blocks in standard library.", blocks);
    175168        IResource blocksResource = blocks.getResource();
     
    178171        boolean blocksFilePathEmpty = blocksFilePath.equals("");
    179172        assertFalse("Empty path to the source file.", blocksFilePathEmpty);
    180 //      reg = blocks.getLocation();
    181 //      assertTrue("negative element region can't be", reg.getOffset() >= 0);
    182 //      assertTrue("elements length must be positive", reg.getLength() > 0);
    183        
    184         /* check Modelica.Blocks imports */
     173        //reg = blocks.getLocation();
     174        //assertTrue("negative element region can't be", reg.getOffset() >= 0);
     175        //assertTrue("elements length must be positive", reg.getLength() > 0);
     176
     177        // check Modelica.Blocks imports
    185178        boolean foundSIimport = false;
    186179        Collection<IModelicaImport> blocksImports = blocks.getImports();
     
    194187                }
    195188                break;
    196                 /* ignore all other types of imports */
     189                // ignore all other types of imports
    197190            }
    198191        }
    199192        assertTrue("Could not find the representation of 'import SI = Modelica.SIunits;' statement", foundSIimport);
    200        
    201         /* check Modelica.Constants */
    202        
     193
     194        // check Modelica.Constants
    203195        assertNotNull("Could not find package Modelica.Constants in standard library.", constants);
    204196        IResource constantsResource = constants.getResource();
     
    207199        boolean constantsFilePathEmpty = constantsFilePath.equals("");
    208200        assertFalse("Empty path to the source file", constantsFilePathEmpty);
    209 //      reg = constants.getLocation();
    210 //      assertTrue("negative element region can't be", reg.getOffset() >= 0);
    211 //      assertTrue("elements length must be positive", reg.getLength() > 0);
    212 
    213         /*
    214          * do checks on Modelica.Constants components
    215          */
     201        //reg = constants.getLocation();
     202        //assertTrue("negative element region can't be", reg.getOffset() >= 0);
     203        //assertTrue("elements length must be positive", reg.getLength() > 0);
     204
     205        // do checks on Modelica.Constants components
    216206        Collection<IModelicaElement> constantsChildren = constants.getChildren();
    217207        IModelicaComponent pi = null;
     
    219209        for (IModelicaElement el : constantsChildren) {
    220210            String name = el.getElementName();
    221            
     211
    222212            if (name.equals("pi")) {
    223213                pi = (IModelicaComponent)el;
     
    228218        }
    229219
    230         /* check Modelica.Constants.pi */
     220        // check Modelica.Constants.pi
    231221        assertNotNull("Could not find package Modelica.Constants.pi in standard library.", pi);
    232222        IModelicaComponent.Visibility piVisibility = pi.getVisibility();
     
    237227        boolean piFilePathEmpty = piFilePath.equals("");
    238228        assertFalse("Empty path to the source file.", piFilePathEmpty);
    239 //      reg = pi.getLocation();
    240 //      assertTrue("negative element region can't be", reg.getOffset() >= 0);
    241 //      assertTrue("elements length must be positive", reg.getLength() > 0);
    242 
    243         /* check Modelica.Constants.D2R */
     229        //reg = pi.getLocation();
     230        //assertTrue("negative element region can't be", reg.getOffset() >= 0);
     231        //assertTrue("elements length must be positive", reg.getLength() > 0);
     232
     233        // check Modelica.Constants.D2R
    244234        assertNotNull("Could not find package Modelica.Constants.pi in standard library.", D2R);
    245235        IModelicaComponent.Visibility d2rVisibility = D2R.getVisibility();
     
    250240        boolean d2rFilePathEmpty = d2rFilePath.equals("");
    251241        assertFalse("Empty path to the source file.", d2rFilePathEmpty);
    252 //      reg = pi.getLocation();
    253 //      assertTrue("negative element region can't be", reg.getOffset() >= 0);
    254 //      assertTrue("elements length must be positive", reg.getLength() > 0);
    255        
    256         /* check Modelica.Constants imports */
     242        //reg = pi.getLocation();
     243        //assertTrue("negative element region can't be", reg.getOffset() >= 0);
     244        //assertTrue("elements length must be positive", reg.getLength() > 0);
     245
     246        // check Modelica.Constants imports
    257247        foundSIimport = false;
    258248        boolean foundNonSIimport = false;
     
    271261                }
    272262                break;
    273                 /* ignore all other types of imports */
    274             }
    275         }
    276        
     263                // ignore all other types of imports
     264            }
     265        }
     266
    277267        assertTrue("Could not find the representation of 'import SI = Modelica.SIunits;' statement", foundSIimport);
    278268        assertTrue("Could not find the representation of 'import NonSI = Modelica.SIunits.Conversions.NonSIunits;' statement", foundNonSIimport);
Note: See TracChangeset for help on using the changeset viewer.