Changeset 1076 for trunk/org.modelica.mdt.test/src
- Timestamp:
- 11/07/11 00:54:51 (13 years ago)
- Location:
- trunk/org.modelica.mdt.test/src/org/modelica/mdt/test
- Files:
-
- 3 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestInnerClass.java
r1072 r1076 42 42 package org.modelica.mdt.test; 43 43 44 import java.io.InputStream; 45 import java.util.Collection; 46 44 47 import org.eclipse.core.resources.IFile; 45 48 import org.eclipse.core.resources.IProject; … … 49 52 import org.eclipse.jface.text.IRegion; 50 53 import org.eclipse.ui.model.IWorkbenchAdapter; 54 import org.modelica.mdt.core.IDefinitionLocation; 51 55 import org.modelica.mdt.core.IModelicaClass; 52 56 import org.modelica.mdt.core.IModelicaComponent; … … 55 59 import org.modelica.mdt.core.IModelicaSourceFile; 56 60 import org.modelica.mdt.core.IModelicaProject; 61 import org.modelica.mdt.core.ISourceRegion; 57 62 import org.modelica.mdt.core.IStandardLibrary; 58 63 import org.modelica.mdt.core.ModelicaCore; … … 70 75 71 76 /** 72 * test org.modelica.mdt.core.compiler.InnerClass class' code 77 * test org.modelica.mdt.core.compiler.InnerClass class' code 73 78 */ 74 public class TestInnerClass extends TestCase 75 { 76 79 public class TestInnerClass extends TestCase { 77 80 /* the file on which we make the changing locations test */ 78 81 private static final String CHANGING_FILE = "changing_file.mo"; 79 82 80 83 /* the test subject */ 81 84 private InnerClass componentsBananza; 82 85 private InnerClass importRichModel; 83 86 84 87 private IModelicaProject proj; 85 86 88 87 89 @Override 88 protected void setUp() throws Exception 89 { 90 protected void setUp() throws Exception { 90 91 Area51Projects.createProjects(); 91 92 92 93 /* navigate to the model 'component_bananza' */ 93 94 proj = Utility.getProject(Area51Projects.MODELICA_PROJECT_NAME); 94 95 IModelicaSourceFile file = 96 Utility.findModelicaFileInFolder(proj.getRootFolder(),97 "component_model.mo");98 95 96 IModelicaSourceFile file = 97 Utility.findModelicaFileInFolder(proj.getRootFolder(), 98 "component_model.mo"); 99 99 100 componentsBananza = null; 100 for (IModelicaElement el : file.getChildren()) 101 { 102 if (el instanceof InnerClass) 103 { 104 if (el.getElementName().equals("components_bananza")) 105 { 101 for (IModelicaElement el : file.getChildren()) { 102 if (el instanceof InnerClass) { 103 String elementName = el.getElementName(); 104 105 if (elementName.equals("components_bananza")) { 106 106 componentsBananza = (InnerClass)el; 107 107 break; … … 110 110 } 111 111 112 113 112 /* navigate to the model 'import_rich_model' */ 114 file = Utility.findModelicaFileInFolder(proj.getRootFolder(), 113 file = Utility.findModelicaFileInFolder(proj.getRootFolder(), 115 114 "import_rich_model.mo"); 116 115 117 116 importRichModel = null; 118 for (IModelicaElement el : file.getChildren()) 119 { 120 if (el instanceof InnerClass) 121 { 122 if (el.getElementName().equals("import_rich_model")) 123 { 117 for (IModelicaElement el : file.getChildren()) { 118 if (el instanceof InnerClass) { 119 String elementName = el.getElementName(); 120 121 if (elementName.equals("import_rich_model")) { 124 122 importRichModel = (InnerClass)el; 125 123 break; … … 131 129 importRichModel); 132 130 } 133 131 134 132 /** 135 133 * do some sanity checks on InnerClass children 136 134 */ 137 135 public void testChildren() 138 throws ConnectException, UnexpectedReplyException, 139 InvocationError, CoreException, CompilerInstantiationException, 140 BundleException 141 { 142 /* 143 * we want to check if we can convert modelica elemnts to workbench 136 throws ConnectException, UnexpectedReplyException, InvocationError, CoreException, CompilerInstantiationException, BundleException { 137 /* 138 * we want to check if we can convert modelica elements to workbench 144 139 * object and get correct label and some image 145 140 * the adapter factory that handles modelica elements object 146 141 * is installed by the org.modelica.mdt.ui plugin, 147 * make sure it is loaded before running tests 148 */ 149 Bundle bundle = Platform.getBundle("org.modelica.mdt.ui"); 142 * make sure it is loaded before running tests 143 */ 144 Bundle bundle = Platform.getBundle("org.modelica.mdt.ui"); 150 145 bundle.start(); 151 146 152 153 147 IModelicaComponent a_real = null; 154 148 IModelicaComponent an_undocumented_real = null; … … 162 156 IModelicaClass a_block = null; 163 157 IModelicaClass a_type = null; 164 IModelicaClass a_function = null; 165 158 IModelicaClass a_function = null; 159 166 160 /* 167 161 * fetch children to local variables 168 * so we can perfort check on 'em 169 */ 170 for (IModelicaElement elm : componentsBananza.getChildren()) 171 { 172 if (elm instanceof IModelicaComponent) 173 { 174 IModelicaComponent comp = (IModelicaComponent) elm; 175 176 if (comp.getElementName().endsWith("a_real")) 177 { 178 a_real = comp; 162 * so we can perform checks on them 163 */ 164 for (IModelicaElement elm : componentsBananza.getChildren()) { 165 if (elm instanceof IModelicaComponent) { 166 IModelicaComponent component = (IModelicaComponent)elm; 167 String elementName = component.getElementName(); 168 169 if (elementName.endsWith("a_real")) { 170 a_real = component; 179 171 } 180 else if (comp.getElementName().endsWith("an_undocumented_real")) 181 { 182 an_undocumented_real = comp; 172 else if (elementName.endsWith("an_undocumented_real")) { 173 an_undocumented_real = component; 183 174 } 184 else if (comp.getElementName().endsWith("a_protected_real")) 185 { 186 a_protected_real = comp; 175 else if (elementName.endsWith("a_protected_real")) { 176 a_protected_real = component; 187 177 } 188 else if (comp.getElementName().endsWith("a_protected_integer")) 189 { 190 a_protected_integer = comp; 178 else if (elementName.endsWith("a_protected_integer")) { 179 a_protected_integer = component; 191 180 } 192 181 } 193 else if (elm instanceof IModelicaClass) 194 { 195 switch (((IModelicaClass)elm).getRestriction()) 196 { 182 else if (elm instanceof IModelicaClass) { 183 IModelicaClass cls = ((IModelicaClass)elm); 184 IModelicaClass.Restriction restriction = cls.getRestriction(); 185 186 switch (restriction) { 197 187 case PACKAGE: 198 a_package = (IModelicaClass)elm;188 a_package = cls; 199 189 break; 200 190 case BLOCK: 201 a_block = (IModelicaClass)elm;191 a_block = cls; 202 192 break; 203 193 case CLASS: 204 a_class = (IModelicaClass)elm;194 a_class = cls; 205 195 break; 206 196 case CONNECTOR: 207 a_connector = (IModelicaClass)elm;197 a_connector = cls; 208 198 break; 209 199 case FUNCTION: 210 a_function = (IModelicaClass)elm;200 a_function = cls; 211 201 break; 212 202 case MODEL: 213 a_model = (IModelicaClass)elm;203 a_model = cls; 214 204 break; 215 205 case RECORD: 216 a_record = (IModelicaClass)elm;206 a_record = cls; 217 207 break; 218 208 case TYPE: 219 a_type = (IModelicaClass)elm;209 a_type = cls; 220 210 break; 221 211 } 222 212 } 223 213 } 224 225 /* 226 * sanity checks on components_bananza.a_type 214 215 /* 216 * sanity checks on components_bananza.a_type 227 217 */ 228 218 assertNotNull("components_bananza.a_type not found", a_type); 229 219 assertEquals("wrong element name", "a_type", a_type.getElementName()); 230 assertEquals("wrong element full name", 231 "components_bananza.a_type", a_type.getFullName()); 232 assertTrue("fishy file path", 220 assertEquals("wrong element full name", 221 "components_bananza.a_type", a_type.getFullName()); 222 assertTrue("fishy file path", 233 223 a_type.getFilePath().endsWith("component_model.mo")); 234 224 IRegion reg = a_type.getLocation().getRegion(); 235 225 assertEquals("wrong start offset", 342, reg.getOffset()); 236 226 assertEquals("wrong length", 364-342+1, reg.getLength()); 237 227 238 228 /* check if element is adaptable */ 239 229 assertTrue("element object must be adaptable", 240 230 (a_type instanceof IAdaptable)); 241 242 /* check if we can convert element to workbench adapter */ 243 IWorkbenchAdapter wbAdapter = 244 (IWorkbenchAdapter)a_type.getAdapter(IWorkbenchAdapter.class);231 232 /* check if we can convert element to workbench adapter */ 233 IWorkbenchAdapter wbAdapter = 234 (IWorkbenchAdapter)a_type.getAdapter(IWorkbenchAdapter.class); 245 235 246 236 assertNotNull("could not fetch workbench adapter", wbAdapter); 247 237 assertEquals("wrong label", "a_type", 248 238 wbAdapter.getLabel(a_type)); 249 assertNotNull("no image provided", 239 assertNotNull("no image provided", 250 240 wbAdapter.getImageDescriptor(a_type)); 251 252 241 253 242 /* … … 259 248 assertEquals("wrong element full name", "components_bananza.a_package", 260 249 a_package.getFullName()); 261 assertTrue("fishy file path", 250 assertTrue("fishy file path", 262 251 a_package.getFilePath().endsWith("component_model.mo")); 263 252 reg = a_package.getLocation().getRegion(); … … 268 257 assertTrue("element object must be adaptable", 269 258 (a_package instanceof IAdaptable)); 270 259 271 260 /* check if we can convert element to workbench adapter */ 272 261 wbAdapter = (IWorkbenchAdapter)a_package.getAdapter(IWorkbenchAdapter.class); … … 276 265 assertEquals("wrong label", "a_package", 277 266 wbAdapter.getLabel(a_package)); 278 assertNotNull("no image provided", 267 assertNotNull("no image provided", 279 268 wbAdapter.getImageDescriptor(a_package)); 280 269 281 270 /* 282 271 * sanity checks on components_bananza.a_block … … 287 276 assertEquals("wrong element full name", "components_bananza.a_block", 288 277 a_block.getFullName()); 289 assertTrue("fishy file path", 278 assertTrue("fishy file path", 290 279 a_block.getFilePath().endsWith("component_model.mo")); 291 280 reg = a_block.getLocation().getRegion(); … … 296 285 assertTrue("element object must be adaptable", 297 286 (a_block instanceof IAdaptable)); 298 287 299 288 /* check if we can convert element to workbench adapter */ 300 289 wbAdapter = (IWorkbenchAdapter)a_block.getAdapter(IWorkbenchAdapter.class); … … 303 292 assertEquals("wrong label", "a_block", 304 293 wbAdapter.getLabel(a_block)); 305 assertNotNull("no image provided", 294 assertNotNull("no image provided", 306 295 wbAdapter.getImageDescriptor(a_block)); 307 296 … … 313 302 assertEquals("wrong element full name", "components_bananza.a_class", 314 303 a_class.getFullName()); 315 assertTrue("fishy file path", 304 assertTrue("fishy file path", 316 305 a_class.getFilePath().endsWith("component_model.mo")); 317 306 reg = a_class.getLocation().getRegion(); … … 322 311 assertTrue("element object must be adaptable", 323 312 (a_class instanceof IAdaptable)); 324 313 325 314 /* check if we can convert element to workbench adapter */ 326 315 wbAdapter = (IWorkbenchAdapter)a_class.getAdapter(IWorkbenchAdapter.class); … … 329 318 assertEquals("wrong label", "a_class", 330 319 wbAdapter.getLabel(a_class)); 331 assertNotNull("no image provided", 320 assertNotNull("no image provided", 332 321 wbAdapter.getImageDescriptor(a_class)); 333 322 334 323 /* 335 * sanity checks on components_bananza.a_connector 324 * sanity checks on components_bananza.a_connector 336 325 */ 337 326 assertNotNull("components_bananza.a_connector not found", a_connector); 338 assertEquals("wrong element name", "a_connector", 327 assertEquals("wrong element name", "a_connector", 339 328 a_connector.getElementName()); 340 assertEquals("wrong element full name", "components_bananza.a_connector", 329 assertEquals("wrong element full name", "components_bananza.a_connector", 341 330 a_connector.getFullName()); 342 assertTrue("fishy file path", 331 assertTrue("fishy file path", 343 332 a_connector.getFilePath().endsWith("component_model.mo")); 344 333 reg = a_connector.getLocation().getRegion(); … … 349 338 assertTrue("element object must be adaptable", 350 339 (a_connector instanceof IAdaptable)); 351 340 352 341 /* check if we can convert element to workbench adapter */ 353 342 wbAdapter = (IWorkbenchAdapter)a_connector.getAdapter(IWorkbenchAdapter.class); … … 356 345 assertEquals("wrong label", "a_connector", 357 346 wbAdapter.getLabel(a_connector)); 358 assertNotNull("no image provided", 347 assertNotNull("no image provided", 359 348 wbAdapter.getImageDescriptor(a_connector)); 360 349 361 350 /* 362 * sanity checks on components_bananza.a_function 351 * sanity checks on components_bananza.a_function 363 352 */ 364 353 assertNotNull("components_bananza.a_function not found", a_function); 365 assertEquals("wrong element name", "a_function", 354 assertEquals("wrong element name", "a_function", 366 355 a_function.getElementName()); 367 assertEquals("wrong element full name", "components_bananza.a_function", 356 assertEquals("wrong element full name", "components_bananza.a_function", 368 357 a_function.getFullName()); 369 assertTrue("fishy file path", 358 assertTrue("fishy file path", 370 359 a_function.getFilePath().endsWith("component_model.mo")); 371 360 reg = a_function.getLocation().getRegion(); … … 376 365 assertTrue("element object must be adaptable", 377 366 (a_function instanceof IAdaptable)); 378 367 379 368 /* check if we can convert element to workbench adapter */ 380 369 wbAdapter = (IWorkbenchAdapter)a_function.getAdapter(IWorkbenchAdapter.class); … … 383 372 assertEquals("wrong label", "a_function", 384 373 wbAdapter.getLabel(a_function)); 385 assertNotNull("no image provided", 374 assertNotNull("no image provided", 386 375 wbAdapter.getImageDescriptor(a_function)); 387 376 388 /* 389 * sanity checks on components_bananza.a_model 377 /* 378 * sanity checks on components_bananza.a_model 390 379 */ 391 380 assertNotNull("components_bananza.a_model not found", a_model); 392 381 assertEquals("wrong element name", "a_model", a_model.getElementName()); 393 assertEquals("wrong element full name", "components_bananza.a_model", 382 assertEquals("wrong element full name", "components_bananza.a_model", 394 383 a_model.getFullName()); 395 assertTrue("fishy file path", 384 assertTrue("fishy file path", 396 385 a_model.getFilePath().endsWith("component_model.mo")); 397 386 reg = a_model.getLocation().getRegion(); … … 402 391 assertTrue("element object must be adaptable", 403 392 (a_model instanceof IAdaptable)); 404 393 405 394 /* check if we can convert element to workbench adapter */ 406 395 wbAdapter = (IWorkbenchAdapter)a_model.getAdapter(IWorkbenchAdapter.class); … … 409 398 assertEquals("wrong label", "a_model", 410 399 wbAdapter.getLabel(a_model)); 411 assertNotNull("no image provided", 400 assertNotNull("no image provided", 412 401 wbAdapter.getImageDescriptor(a_model)); 413 414 /* 415 * sanity checks on components_bananza.a_record 402 403 /* 404 * sanity checks on components_bananza.a_record 416 405 */ 417 406 assertNotNull("components_bananza.a_record not found", a_record); … … 419 408 assertEquals("wrong element full name", "components_bananza.a_record", 420 409 a_record.getFullName()); 421 assertTrue("fishy file path", 410 assertTrue("fishy file path", 422 411 a_record.getFilePath().endsWith("component_model.mo")); 423 412 reg = a_record.getLocation().getRegion(); … … 428 417 assertTrue("element object must be adaptable", 429 418 (a_record instanceof IAdaptable)); 430 419 431 420 /* check if we can convert element to workbench adapter */ 432 421 wbAdapter = (IWorkbenchAdapter)a_record.getAdapter(IWorkbenchAdapter.class); … … 435 424 assertEquals("wrong label", "a_record", 436 425 wbAdapter.getLabel(a_record)); 437 assertNotNull("no image provided", 426 assertNotNull("no image provided", 438 427 wbAdapter.getImageDescriptor(a_record)); 439 440 /* 441 * sanity checks on components_bananza.a_real 428 429 /* 430 * sanity checks on components_bananza.a_real 442 431 */ 443 432 assertNotNull("components_bananza.a_real not found", a_real); 444 433 assertEquals("wrong element name", "a_real", a_real.getElementName()); 445 assertEquals("wrong element full name", "components_bananza.a_real", 434 assertEquals("wrong element full name", "components_bananza.a_real", 446 435 a_real.getFullName()); 447 436 assertEquals("wrong visibility", a_real.getVisibility(), … … 455 444 assertTrue("element object must be adaptable", 456 445 (a_real instanceof IAdaptable)); 457 446 458 447 /* check if we can convert element to workbench adapter */ 459 448 wbAdapter = (IWorkbenchAdapter)a_real.getAdapter(IWorkbenchAdapter.class); … … 462 451 assertEquals("wrong label", "a_real", 463 452 wbAdapter.getLabel(a_real)); 464 assertNotNull("no image provided", 453 assertNotNull("no image provided", 465 454 wbAdapter.getImageDescriptor(a_real)); 466 467 /* 468 * sanity checks on components_bananza.a_undocumented_real 469 */ 470 assertNotNull("components_bananza.an_undocumented_real not found", 455 456 /* 457 * sanity checks on components_bananza.a_undocumented_real 458 */ 459 assertNotNull("components_bananza.an_undocumented_real not found", 471 460 an_undocumented_real); 472 461 assertEquals("wrong element name", "an_undocumented_real", 473 462 an_undocumented_real.getElementName()); 474 assertEquals("wrong element full name", 463 assertEquals("wrong element full name", 475 464 "components_bananza.an_undocumented_real", 476 465 an_undocumented_real.getFullName()); … … 480 469 assertEquals("wrong start offset", 64, reg.getOffset()); 481 470 assertEquals("wrong length", 89-64+1, reg.getLength()); 482 471 483 472 /* check if element is adaptable */ 484 473 assertTrue("element object must be adaptable", 485 474 (an_undocumented_real instanceof IAdaptable)); 486 487 /* check if we can convert element to workbench adapter */ 488 wbAdapter = 489 (IWorkbenchAdapter)an_undocumented_real.getAdapter(IWorkbenchAdapter.class);475 476 /* check if we can convert element to workbench adapter */ 477 wbAdapter = 478 (IWorkbenchAdapter)an_undocumented_real.getAdapter(IWorkbenchAdapter.class); 490 479 491 480 assertNotNull("could not fetch workbench adapter", wbAdapter); 492 481 assertEquals("wrong label", "an_undocumented_real", 493 482 wbAdapter.getLabel(an_undocumented_real)); 494 assertNotNull("no image provided", 483 assertNotNull("no image provided", 495 484 wbAdapter.getImageDescriptor(an_undocumented_real)); 496 497 /* 498 * sanity checks on components_bananza.a_protected_integer 499 */ 500 assertNotNull("components_bananza.a_protected_integer not found", 485 486 /* 487 * sanity checks on components_bananza.a_protected_integer 488 */ 489 assertNotNull("components_bananza.a_protected_integer not found", 501 490 a_protected_integer); 502 assertEquals("wrong element name", "a_protected_integer", 491 assertEquals("wrong element name", "a_protected_integer", 503 492 a_protected_integer.getElementName()); 504 assertEquals("wrong element full name", 505 "components_bananza.a_protected_integer", 493 assertEquals("wrong element full name", 494 "components_bananza.a_protected_integer", 506 495 a_protected_integer.getFullName()); 507 496 assertEquals("wrong visibility", a_protected_integer.getVisibility(), … … 514 503 assertTrue("element object must be adaptable", 515 504 (a_protected_integer instanceof IAdaptable)); 516 517 /* check if we can convert element to workbench adapter */ 518 wbAdapter = 519 (IWorkbenchAdapter)a_protected_integer.getAdapter(IWorkbenchAdapter.class); 505 506 /* check if we can convert element to workbench adapter */ 507 wbAdapter = (IWorkbenchAdapter)a_protected_integer.getAdapter(IWorkbenchAdapter.class); 520 508 521 509 assertNotNull("could not fetch workbench adapter", wbAdapter); 522 510 assertEquals("wrong label", "a_protected_integer", 523 511 wbAdapter.getLabel(a_protected_integer)); 524 assertNotNull("no image provided", 512 assertNotNull("no image provided", 525 513 wbAdapter.getImageDescriptor(a_protected_integer)); 526 527 /* 528 * sanity checks on components_bananza.a_protected_real 529 */ 530 assertNotNull("components_bananza.a_protected_real not found", 514 515 /* 516 * sanity checks on components_bananza.a_protected_real 517 */ 518 assertNotNull("components_bananza.a_protected_real not found", 531 519 a_protected_real); 532 assertEquals("wrong element name", "a_protected_real", 520 assertEquals("wrong element name", "a_protected_real", 533 521 a_protected_real.getElementName()); 534 assertEquals("wrong element full name", 535 "components_bananza.a_protected_real", 536 a_protected_real.getFullName()); 522 assertEquals("wrong element full name", 523 "components_bananza.a_protected_real", 524 a_protected_real.getFullName()); 537 525 assertEquals("wrong visibility", a_protected_real.getVisibility(), 538 526 IModelicaComponent.Visibility.PROTECTED); … … 544 532 assertTrue("element object must be adaptable", 545 533 (a_protected_real instanceof IAdaptable)); 546 547 /* check if we can convert element to workbench adapter */ 548 wbAdapter = 549 (IWorkbenchAdapter)a_protected_real.getAdapter(IWorkbenchAdapter.class);534 535 /* check if we can convert element to workbench adapter */ 536 wbAdapter = 537 (IWorkbenchAdapter)a_protected_real.getAdapter(IWorkbenchAdapter.class); 550 538 551 539 assertNotNull("could not fetch workbench adapter", wbAdapter); 552 540 assertEquals("wrong label", "a_protected_real", 553 541 wbAdapter.getLabel(a_protected_real)); 554 assertNotNull("no image provided", 542 assertNotNull("no image provided", 555 543 wbAdapter.getImageDescriptor(a_protected_real)); 556 544 } 557 545 558 546 /** 559 547 * do some sanity checks on InnerClass' imports 560 548 */ 561 public void testImports() 562 throws ConnectException, UnexpectedReplyException, InvocationError, 563 CompilerInstantiationException, CoreException 564 { 549 public void testImports() 550 throws ConnectException, UnexpectedReplyException, InvocationError, CompilerInstantiationException, CoreException { 565 551 int importCounter = 0; 566 IModelicaClass importedPackage;567 for (IModelicaImport imp : importRichModel.getImports()) 568 {552 Collection<IModelicaImport> imports = importRichModel.getImports(); 553 554 for (IModelicaImport imp : imports) { 569 555 importCounter++; 570 556 571 557 /* 572 * we are expecting 8 import stat ments in following order:558 * we are expecting 8 import statements in following order: 573 559 * 1. qualified (import Modelica) 574 560 * 2. qualified (import Modelica.Math.sin) … … 578 564 * 6. local qualified (import hepp.hopp) 579 565 * 7. local unqualified (import hepp.*) 580 * 8. local single definition 566 * 8. local single definition 581 567 * (import root_package.root_package_model) 582 568 */ 583 584 switch (importCounter) 585 { 586 case 1: // import Modelica 569 switch (importCounter) { 570 case 1: {// import Modelica 587 571 assertEquals(IModelicaImport.Type.QUALIFIED, imp.getType()); 588 importedPackage = imp.getImportedPackage();572 IModelicaClass importedPackage = imp.getImportedPackage(); 589 573 assertEquals("wrong imported package returned", 590 574 "Modelica", 591 575 importedPackage.getFullName()); 592 576 break; 593 case 2: // import Modelica.Math.sin 577 } 578 case 2: {// import Modelica.Math.sin 594 579 assertEquals(IModelicaImport.Type.QUALIFIED, imp.getType()); 595 importedPackage = imp.getImportedPackage();580 IModelicaClass importedPackage = imp.getImportedPackage(); 596 581 assertEquals("wrong imported package returned", 597 582 "Modelica.Math.sin", 598 583 importedPackage.getFullName()); 599 584 break; 600 case 3: // import Modelica.* 585 } 586 case 3: {// import Modelica.* 601 587 assertEquals(IModelicaImport.Type.UNQUALIFIED, imp.getType()); 602 importedPackage = imp.getImportedPackage();588 IModelicaClass importedPackage = imp.getImportedPackage(); 603 589 assertEquals("wrong imported package returned", 604 590 "Modelica", 605 591 importedPackage.getFullName()); 606 592 break; 607 case 4: // import mm = Modelica.Math 593 } 594 case 4: {// import mm = Modelica.Math 608 595 assertEquals(IModelicaImport.Type.RENAMING, imp.getType()); 609 596 assertEquals("mm", imp.getAlias()); 610 597 break; 611 case 5: // import foo = hepp 598 } 599 case 5: {// import foo = hepp 612 600 assertEquals(IModelicaImport.Type.RENAMING, imp.getType()); 613 601 assertEquals("foo", imp.getAlias()); 614 602 break; 615 case 6: // import hepp.hopp 603 } 604 case 6: {// import hepp.hopp 616 605 assertEquals(IModelicaImport.Type.QUALIFIED, imp.getType()); 617 606 break; 618 case 7: // import hepp.* 607 } 608 case 7: {// import hepp.* 619 609 assertEquals(IModelicaImport.Type.UNQUALIFIED, imp.getType()); 620 610 break; 621 case 8: // import root_package.root_package_model 611 } 612 case 8: {// import root_package.root_package_model 622 613 assertEquals(IModelicaImport.Type.QUALIFIED, imp.getType()); 623 614 break; 624 default: 625 fail("unexpectedly many imports found"); 615 } 616 default: { 617 fail("unexpectedly many imports found"); 618 } 626 619 } 627 620 } 628 629 assertFalse("did not find all import statments", 621 622 assertFalse("did not find all import statments", 630 623 importCounter < 4); 631 632 624 } 633 625 634 626 public void testIsEncapsulated() 635 throws ConnectException, CompilerInstantiationException, UnexpectedReplyException, 636 InvocationError, CoreException 637 { 627 throws ConnectException, CompilerInstantiationException, UnexpectedReplyException, InvocationError, CoreException { 638 628 IModelicaClass clazz; 639 IStandardLibrary stdLib = 629 IStandardLibrary stdLib = 640 630 ModelicaCore.getModelicaRoot().getStandardLibrary(null); 641 631 642 632 /* 643 633 * check correctness of isEncapsulated() in classes from standard library … … 646 636 assertNotNull(clazz); 647 637 assertTrue("wrong encapsulated status", clazz.isEncapsulated()); 648 638 649 639 clazz = stdLib.getPackage("Modelica.Math.acos"); 650 640 assertNotNull(clazz); … … 658 648 assertNotNull(clazz); 659 649 assertTrue("wrong encapsulated status", clazz.isEncapsulated()); 660 650 661 651 clazz = stdLib.getPackage("Modelica"); 662 652 assertNotNull(clazz); 663 653 assertFalse("wrong encapsulated status", clazz.isEncapsulated()); 664 654 665 655 /* 666 656 * check correctness of isEncapsulated() on classes from area51 project 667 657 */ 668 658 669 659 /* test inner packager */ 670 660 clazz = proj.getClass("root_model"); … … 702 692 } 703 693 704 /** 705 * test that the when a class definit on is changed in the disk706 * it 's location is updated694 /** 695 * test that the when a class definition is changed in the disk 696 * its location is updated 707 697 */ 708 public void testLocationUpdates() throws CoreException, 709 ConnectException, CompilerInstantiationException, 710 UnexpectedReplyException, InvocationError 711 { 712 713 /* create initial class definitons */ 714 createClassDef(); 715 /* 716 * check the initial locations 717 */ 718 IModelicaClass clazz; 719 IRegion defReg; 720 721 /* checks on EquationComponent */ 722 clazz = proj.getClass("EquationComponent"); 723 assertNotNull(clazz); 724 725 defReg = clazz.getLocation().getRegion(); 726 assertEquals("wrong start offset", 111, defReg.getOffset()); 727 assertEquals("wrong length", 239-111+1, defReg.getLength()); 698 public void testLocationUpdates() 699 throws CoreException, ConnectException, CompilerInstantiationException, UnexpectedReplyException, InvocationError { 700 /* create initial class definitions */ 701 createClassDef(); 702 703 /* 704 * Check some initial locations. 705 */ 706 testLocation("EquationComponent", 6, 1, 13, 22); 728 707 729 708 /* checks on EquationComponent.R */ 730 clazz = proj.getClass("EquationComponent.R"); 731 assertNotNull(clazz); 732 733 defReg = clazz.getLocation().getRegion(); 734 assertEquals("wrong start offset", 137, defReg.getOffset()); 735 assertEquals("wrong length", 167-137+1, defReg.getLength()); 736 737 738 /* modify class defintions */ 709 testLocation("EquationComponent.R", 7, 3, 9, 8); 710 711 /* modify class definitions */ 739 712 modifyClassDef(); 740 741 /* 742 * check that locations where updated 743 */ 744 /* checks on EquationComponent */ 745 clazz = proj.getClass("EquationComponent"); 746 assertNotNull(clazz); 747 748 defReg = clazz.getLocation().getRegion(); 749 assertEquals("wrong start offset", 25, defReg.getOffset()); 750 assertEquals("wrong length", 179-25+1, defReg.getLength()); 751 752 /* checks on EquationComponent.R */ 753 clazz = proj.getClass("EquationComponent.R"); 754 assertNotNull(clazz); 755 756 defReg = clazz.getLocation().getRegion(); 757 assertEquals("wrong start offset", 76, defReg.getOffset()); 758 assertEquals("wrong length", 106-76+1, defReg.getLength()); 759 713 714 /* 715 * check that locations where updated 716 */ 717 testLocation("EquationComponent", 2, 1, 11, 22); 718 719 Utility.printFile(proj, TestInnerClass.CHANGING_FILE); 720 testLocation("EquationComponent.R", 4, 3, 6, 8); 760 721 } 761 722 723 private void testLocation(String className, int startLine, int startCol, int endLine, int endCol) 724 throws ConnectException, CompilerInstantiationException, UnexpectedReplyException, InvocationError, CoreException { 725 IModelicaClass cls = proj.getClass(className); 726 727 assertNotNull("IModelicaProject.getClass() returned null for \"" + className + "\".", cls); 728 729 IDefinitionLocation definitionLocation = cls.getLocation(); 730 ISourceRegion sourceRegion = definitionLocation.getSourceRegion(); 731 732 int actualStartLine = sourceRegion.getStartLine(); 733 int actualStartCol = sourceRegion.getStartColumn(); 734 int actualEndLine = sourceRegion.getEndLine(); 735 int actualEndCol = sourceRegion.getEndColumn(); 736 737 assertEquals("Expected start line did not match actual start line.", startLine, actualStartLine); 738 assertEquals("Expected start column did not match actual start column.", startCol, actualStartCol); 739 assertEquals("Expected end line did not match actual end line.", endLine, actualEndLine); 740 assertEquals("Expected end column did not match actual end column.", endCol, actualEndCol); 741 } 742 762 743 /** 763 744 * utility function for the testLocationUpdates test 764 * 745 * 746 * Creates the initial definitions in a source file 747 */ 748 private void createClassDef() throws CoreException { 749 IProject project = proj.getWrappedProject(); 750 IFile file = project.getFile(CHANGING_FILE); 751 752 InputStream stream = TestInnerClass.class.getResourceAsStream("/org/modelica/mdt/test/modelicafiles/TestInnerClass_changing_file_before.mo"); 753 file.create(stream, true, null); 754 } 755 756 /** 757 * utility function for the testLocationUpdates test 758 * 765 759 * overwrites the initial definitions in a source file with 766 760 * some modifications 767 761 */ 768 private void modifyClassDef() throws CoreException 769 { 770 String contents = 771 "// funny comment removed\n" + 772 "class EquationComponent\n" + 773 " /* records are nice */\n" + 774 " record R\n" + 775 " Real x,y;\n" + 776 " end R;\n" + 777 "\n" + 778 " R a,b,c;\n" + 779 "equation\n" + 780 " a = if true then b else c;\n" + 781 "end EquationComponent;"; 782 762 private void modifyClassDef() throws CoreException { 783 763 IProject project = proj.getWrappedProject(); 784 764 IFile file = project.getFile(CHANGING_FILE); 785 786 file.setContents(Utility.getByteStream(contents), true, true, null); 787 } 788 789 /** 790 * utility function for the testLocationUpdates test 791 * 792 * Creates the initial definitions in a source file 793 * 794 */ 795 private void createClassDef() throws CoreException 796 { 797 String contents = 798 "/*\n" + 799 " * However, don't ever expect you can parse\n" + 800 " * the error message from the compiler.\n" + 801 " * -- Adrian Pop\n" + 802 " */\n" + 803 "class EquationComponent\n" + 804 " record R\n" + 805 " Real x,y;\n" + 806 " end R;\n" + 807 " R a,b,c;\n" + 808 "equation\n" + 809 " a = if true then b else c;\n" + 810 "end EquationComponent;"; 811 812 IProject project = proj.getWrappedProject(); 813 IFile file = project.getFile(CHANGING_FILE); 814 815 file.create(Utility.getByteStream(contents), true, null); 765 766 InputStream stream = TestInnerClass.class.getResourceAsStream("/org/modelica/mdt/test/modelicafiles/TestInnerClass_changing_file_after.mo"); 767 file.setContents(stream, IFile.FORCE, null); 816 768 } 817 769 }
Note: See TracChangeset
for help on using the changeset viewer.