- Timestamp:
- 02/13/06 12:18:28 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestInnerClass.java
r288 r310 44 44 import org.eclipse.core.runtime.CoreException; 45 45 import org.eclipse.jface.text.IRegion; 46 import org.modelica.mdt.core.CompilerProxy; 46 47 import org.modelica.mdt.core.IModelicaClass; 47 48 import org.modelica.mdt.core.IModelicaComponent; 49 import org.modelica.mdt.core.IModelicaElement; 48 50 import org.modelica.mdt.core.IModelicaSourceFile; 49 51 import org.modelica.mdt.core.IModelicaProject; … … 67 69 /* the test subject */ 68 70 private InnerClass componentsBananza; 71 72 /* teh Modelica package (from the standard library) */ 73 private InnerClass modelica = null; 74 69 75 @Override 70 76 protected void setUp() throws Exception … … 95 101 assertNotNull("could not find the model component_bonanza", 96 102 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 97 116 98 117 } … … 129 148 * so we can perfort check on 'em 130 149 */ 131 for ( Object obj: componentsBananza.getChildren())150 for (IModelicaElement elm : componentsBananza.getChildren()) 132 151 { 133 if ( objinstanceof IModelicaComponent)134 { 135 IModelicaComponent comp = (IModelicaComponent) obj;152 if (elm instanceof IModelicaComponent) 153 { 154 IModelicaComponent comp = (IModelicaComponent) elm; 136 155 137 156 if (comp.getElementName().endsWith("a_real")) … … 152 171 } 153 172 } 154 else if ( objinstanceof IModelicaClass)155 { 156 switch (((IModelicaClass) obj).getRestrictionType())173 else if (elm instanceof IModelicaClass) 174 { 175 switch (((IModelicaClass)elm).getRestrictionType()) 157 176 { 158 177 case PACKAGE: 159 a_package = (IModelicaClass) obj;178 a_package = (IModelicaClass)elm; 160 179 break; 161 180 case BLOCK: 162 a_block = (IModelicaClass) obj;181 a_block = (IModelicaClass)elm; 163 182 break; 164 183 case CLASS: 165 a_class = (IModelicaClass) obj;184 a_class = (IModelicaClass)elm; 166 185 break; 167 186 case CONNECTOR: 168 a_connector = (IModelicaClass) obj;187 a_connector = (IModelicaClass)elm; 169 188 break; 170 189 case FUNCTION: 171 a_function = (IModelicaClass) obj;190 a_function = (IModelicaClass)elm; 172 191 break; 173 192 case MODEL: 174 a_model = (IModelicaClass) obj;193 a_model = (IModelicaClass)elm; 175 194 break; 176 195 case RECORD: 177 a_record = (IModelicaClass) obj;196 a_record = (IModelicaClass)elm; 178 197 break; 179 198 case TYPE: 180 a_type = (IModelicaClass) obj;199 a_type = (IModelicaClass)elm; 181 200 break; 182 201 } … … 187 206 assertNotNull("components_bananza.a_type not found", a_type); 188 207 assertEquals("wrong element name", a_type.getElementName(), "a_type"); 208 System.out.println(a_type.getFilePath()); 209 System.out.println(a_type.getFilePath()); 189 210 assertTrue("fishy file path", 190 211 a_type.getFilePath().endsWith("component_model.mo")); … … 304 325 assertEquals("wrong length", 24, reg.getLength()); 305 326 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 } 307 442 }
Note: See TracChangeset
for help on using the changeset viewer.