Ignore:
Timestamp:
02/13/06 12:18:28 (19 years ago)
Author:
boris
Message:
  • create an abstract way to access omc class getElementsInfo() thus close the hole into omc plugin, hurray !
  • added some tests that triggerd some bugs and fixed the bugs
File:
1 edited

Legend:

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

    r288 r310  
    4444import org.eclipse.core.runtime.CoreException;
    4545import org.eclipse.jface.text.IRegion;
     46import org.modelica.mdt.core.CompilerProxy;
    4647import org.modelica.mdt.core.IModelicaClass;
    4748import org.modelica.mdt.core.IModelicaComponent;
     49import org.modelica.mdt.core.IModelicaElement;
    4850import org.modelica.mdt.core.IModelicaSourceFile;
    4951import org.modelica.mdt.core.IModelicaProject;
     
    6769    /* the test subject */
    6870    private InnerClass componentsBananza;
     71   
     72    /* teh Modelica package (from the standard library) */
     73    private InnerClass modelica = null;
     74   
    6975    @Override
    7076    protected void setUp() throws Exception
     
    95101        assertNotNull("could not find the model component_bonanza",
    96102                componentsBananza);
     103       
     104        /* fetch teh Modelica package from the standard library */
     105        for (IModelicaClass clazz : CompilerProxy.getStandardLibrary())
     106        {
     107            if (clazz.getElementName().equals("Modelica"))
     108            {
     109                modelica = (InnerClass)clazz;
     110                break;
     111            }
     112        }
     113        assertNotNull("could not found standard library package 'Modelica'",
     114                modelica);
     115       
    97116
    98117    }
     
    129148         * so we can perfort check on 'em
    130149         */
    131         for (Object obj : componentsBananza.getChildren())
     150        for (IModelicaElement elm : componentsBananza.getChildren())
    132151        {
    133             if (obj instanceof IModelicaComponent)
    134             {
    135                 IModelicaComponent comp = (IModelicaComponent) obj;
     152            if (elm instanceof IModelicaComponent)
     153            {
     154                IModelicaComponent comp = (IModelicaComponent) elm;
    136155               
    137156                if (comp.getElementName().endsWith("a_real"))
     
    152171                }
    153172            }
    154             else if (obj instanceof IModelicaClass)
    155             {
    156                 switch (((IModelicaClass)obj).getRestrictionType())
     173            else if (elm instanceof IModelicaClass)
     174            {
     175                switch (((IModelicaClass)elm).getRestrictionType())
    157176                {
    158177                case PACKAGE:
    159                     a_package = (IModelicaClass)obj;
     178                    a_package = (IModelicaClass)elm;
    160179                    break;
    161180                case BLOCK:
    162                     a_block = (IModelicaClass)obj;
     181                    a_block = (IModelicaClass)elm;
    163182                    break;
    164183                case CLASS:
    165                     a_class = (IModelicaClass)obj;
     184                    a_class = (IModelicaClass)elm;
    166185                    break;
    167186                case CONNECTOR:
    168                     a_connector = (IModelicaClass)obj;
     187                    a_connector = (IModelicaClass)elm;
    169188                    break;
    170189                case FUNCTION:
    171                     a_function = (IModelicaClass)obj;
     190                    a_function = (IModelicaClass)elm;
    172191                    break;
    173192                case MODEL:
    174                     a_model = (IModelicaClass)obj;
     193                    a_model = (IModelicaClass)elm;
    175194                    break;
    176195                case RECORD:
    177                     a_record = (IModelicaClass)obj;
     196                    a_record = (IModelicaClass)elm;
    178197                    break;
    179198                case TYPE:
    180                     a_type = (IModelicaClass)obj;
     199                    a_type = (IModelicaClass)elm;
    181200                    break;
    182201                }
     
    187206        assertNotNull("components_bananza.a_type not found", a_type);
    188207        assertEquals("wrong element name", a_type.getElementName(), "a_type");
     208        System.out.println(a_type.getFilePath());
     209        System.out.println(a_type.getFilePath());
    189210        assertTrue("fishy file path",
    190211                a_type.getFilePath().endsWith("component_model.mo"));
     
    304325        assertEquals("wrong length", 24, reg.getLength());
    305326
    306     }
     327    }
     328   
     329    /**
     330     * Do some integrity tests on classes/packages from the standard library.
     331     */
     332    public void testStandardLibraryElements()
     333        throws ConnectException, UnexpectedReplyException,
     334            InvocationError, CompilerInstantiationException, CoreException
     335    {
     336        /*
     337         * do checks on Modelica package
     338         */
     339        assertNull("standard library should be defined outside of workspace",
     340                modelica.getResource());
     341        assertFalse("empty path to the source file",
     342                modelica.getFilePath().equals(""));
     343        IRegion reg = modelica.getLocation();
     344        assertTrue("negative element region can't be", reg.getOffset() >= 0);
     345        assertTrue("elements length must be positive", reg.getLength() > 0);
     346
     347
     348        /*
     349         * do checks on Modelica.Blocks and Modelica.Constants packages
     350         */
     351
     352        InnerClass blocks = null;
     353        InnerClass constants = null;
     354 
     355        for (IModelicaElement el : modelica.getChildren())
     356        {
     357            String name = el.getElementName();
     358           
     359            if (name.equals("Blocks"))
     360            {
     361                blocks = (InnerClass)el;
     362            }
     363            else if (name.equals("Constants"))
     364            {
     365                constants = (InnerClass)el;
     366            }
     367        }
     368       
     369        /* check Modelica.Blocks */
     370        assertNotNull("could not find package Modelica.Blocks in standard" +
     371                "library ", blocks);
     372        assertNull("standard library should be defined outside of workspace",
     373                blocks.getResource());
     374        assertFalse("empty path to the source file",
     375                blocks.getFilePath().equals(""));
     376        reg = blocks.getLocation();
     377        assertTrue("negative element region can't be", reg.getOffset() >= 0);
     378        assertTrue("elements length must be positive", reg.getLength() > 0);
     379
     380       
     381        /* check Modelica.Constants */
     382        assertNotNull("could not find package Modelica.Constants in standard" +
     383                "library ", constants);
     384        assertNull("standard library should be defined outside of workspace",
     385                constants.getResource());
     386        assertFalse("empty path to the source file",
     387                constants.getFilePath().equals(""));
     388        reg = constants.getLocation();
     389        assertTrue("negative element region can't be", reg.getOffset() >= 0);
     390        assertTrue("elements length must be positive", reg.getLength() > 0);
     391
     392
     393        IModelicaComponent pi = null;
     394        IModelicaComponent D2R = null;
     395       
     396        /*
     397         * do checks on Modelica.Constants components
     398         */
     399        for (IModelicaElement el : constants.getChildren())
     400        {
     401            String name = el.getElementName();
     402           
     403            if (name.equals("pi"))
     404            {
     405                pi = (IModelicaComponent)el;
     406            }
     407            else if (name.equals("D2R"))
     408            {
     409                D2R = (IModelicaComponent)el;
     410            }
     411        }
     412
     413        /* check Modelica.Constants.pi */
     414        assertNotNull("could not find package Modelica.Constants.pi in standard"
     415                + "library ", pi);
     416        assertEquals("pi must have public visibility",
     417                IModelicaComponent.Visibility.PUBLIC,
     418                pi.getVisbility());
     419        assertNull("standard library should be defined outside of workspace",
     420                pi.getResource());
     421        assertFalse("empty path to the source file",
     422                pi.getFilePath().equals(""));
     423        reg = pi.getLocation();
     424        assertTrue("negative element region can't be", reg.getOffset() >= 0);
     425        assertTrue("elements length must be positive", reg.getLength() > 0);
     426
     427        /* check Modelica.Constants.D2R */
     428        assertNotNull("could not find package Modelica.Constants.pi in standard"
     429                + "library ", D2R);
     430        assertEquals("pi must have public visibility",
     431                IModelicaComponent.Visibility.PUBLIC,
     432                D2R.getVisbility());
     433        assertNull("standard library should be defined outside of workspace",
     434                D2R.getResource());
     435        assertFalse("empty path to the source file",
     436                D2R.getFilePath().equals(""));
     437        reg = pi.getLocation();
     438        assertTrue("negative element region can't be", reg.getOffset() >= 0);
     439        assertTrue("elements length must be positive", reg.getLength() > 0);
     440       
     441    }
    307442}
Note: See TracChangeset for help on using the changeset viewer.