- Timestamp:
- 11/07/11 22:45:13 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestInnerClass.java
r1076 r1077 549 549 public void testImports() 550 550 throws ConnectException, UnexpectedReplyException, InvocationError, CompilerInstantiationException, CoreException { 551 int importCounter = 0;552 551 Collection<IModelicaImport> imports = importRichModel.getImports(); 553 552 554 for (IModelicaImport imp : imports) { 555 importCounter++; 556 557 /* 558 * we are expecting 8 import statements in following order: 559 * 1. qualified (import Modelica) 560 * 2. qualified (import Modelica.Math.sin) 561 * 3. unqualified (import Modelica.*) 562 * 4. renaming (import mm = Modelica.Math) 563 * 5. local renaming (import foo = hepp) 564 * 6. local qualified (import hepp.hopp) 565 * 7. local unqualified (import hepp.*) 566 * 8. local single definition 567 * (import root_package.root_package_model) 568 */ 569 switch (importCounter) { 570 case 1: {// import Modelica 571 assertEquals(IModelicaImport.Type.QUALIFIED, imp.getType()); 572 IModelicaClass importedPackage = imp.getImportedPackage(); 573 assertEquals("wrong imported package returned", 574 "Modelica", 575 importedPackage.getFullName()); 576 break; 577 } 578 case 2: {// import Modelica.Math.sin 579 assertEquals(IModelicaImport.Type.QUALIFIED, imp.getType()); 580 IModelicaClass importedPackage = imp.getImportedPackage(); 581 assertEquals("wrong imported package returned", 582 "Modelica.Math.sin", 583 importedPackage.getFullName()); 584 break; 585 } 586 case 3: {// import Modelica.* 587 assertEquals(IModelicaImport.Type.UNQUALIFIED, imp.getType()); 588 IModelicaClass importedPackage = imp.getImportedPackage(); 589 assertEquals("wrong imported package returned", 590 "Modelica", 591 importedPackage.getFullName()); 592 break; 593 } 594 case 4: {// import mm = Modelica.Math 595 assertEquals(IModelicaImport.Type.RENAMING, imp.getType()); 596 assertEquals("mm", imp.getAlias()); 597 break; 598 } 599 case 5: {// import foo = hepp 600 assertEquals(IModelicaImport.Type.RENAMING, imp.getType()); 601 assertEquals("foo", imp.getAlias()); 602 break; 603 } 604 case 6: {// import hepp.hopp 605 assertEquals(IModelicaImport.Type.QUALIFIED, imp.getType()); 606 break; 607 } 608 case 7: {// import hepp.* 609 assertEquals(IModelicaImport.Type.UNQUALIFIED, imp.getType()); 610 break; 611 } 612 case 8: {// import root_package.root_package_model 613 assertEquals(IModelicaImport.Type.QUALIFIED, imp.getType()); 614 break; 615 } 616 default: { 617 fail("unexpectedly many imports found"); 618 } 619 } 620 } 621 622 assertFalse("did not find all import statments", 623 importCounter < 4); 553 /* 554 * we are expecting 8 import statements in following order: 555 * 1. qualified (import Modelica) 556 * 2. qualified (import Modelica.Math.sin) 557 * 3. unqualified (import Modelica.*) 558 * 4. renaming (import mm = Modelica.Math) 559 * 5. local renaming (import foo = hepp) 560 * 6. local qualified (import hepp.hopp) 561 * 7. local unqualified (import hepp.*) 562 * 8. local single definition (import root_package.root_package_model) 563 */ 564 565 int actualNumImports = imports.size(); 566 int expectedNumImports = 8; 567 568 assertEquals("Unexpected number of imports", actualNumImports, expectedNumImports); 569 570 testImport(imports.toArray(new IModelicaImport[0])[0], IModelicaImport.Type.QUALIFIED, "Modelica", null); 571 testImport(imports.toArray(new IModelicaImport[0])[1], IModelicaImport.Type.QUALIFIED, "Modelica.Math.sin", null); 572 testImport(imports.toArray(new IModelicaImport[0])[2], IModelicaImport.Type.UNQUALIFIED, "Modelica", null); 573 testImport(imports.toArray(new IModelicaImport[0])[3], IModelicaImport.Type.RENAMING, "Modelica.Math", "mm"); 574 testImport(imports.toArray(new IModelicaImport[0])[4], IModelicaImport.Type.RENAMING, "hepp", "foo"); 575 testImport(imports.toArray(new IModelicaImport[0])[5], IModelicaImport.Type.QUALIFIED, "hepp.hopp", null); 576 testImport(imports.toArray(new IModelicaImport[0])[6], IModelicaImport.Type.UNQUALIFIED, "hepp", null); 577 testImport(imports.toArray(new IModelicaImport[0])[7], IModelicaImport.Type.QUALIFIED, "root_package.root_package_model", null); 624 578 } 625 579 … … 698 652 public void testLocationUpdates() 699 653 throws CoreException, ConnectException, CompilerInstantiationException, UnexpectedReplyException, InvocationError { 700 /* create initial class definitions*/654 /* Create initial class definitions. */ 701 655 createClassDef(); 702 656 703 /* 704 * Check some initial locations. 705 */ 657 /* Check some initial locations. */ 706 658 testLocation("EquationComponent", 6, 1, 13, 22); 707 708 /* checks on EquationComponent.R */709 659 testLocation("EquationComponent.R", 7, 3, 9, 8); 710 660 711 /* modify class definitions*/661 /* Modify class definitions. */ 712 662 modifyClassDef(); 713 663 714 /* 715 * check that locations where updated 716 */ 664 /* Check that locations where updated. */ 717 665 testLocation("EquationComponent", 2, 1, 11, 22); 718 719 Utility.printFile(proj, TestInnerClass.CHANGING_FILE); 666 Utility.printFile(proj, TestInnerClass.CHANGING_FILE); 720 667 testLocation("EquationComponent.R", 4, 3, 6, 8); 668 } 669 670 private void testImport(IModelicaImport modelicaImport, IModelicaImport.Type importType, String importedPackageName, String alias) 671 throws ConnectException, CompilerInstantiationException, UnexpectedReplyException, InvocationError, CoreException { 672 IModelicaImport.Type actualImportType = modelicaImport.getType(); 673 674 assertEquals("IModelicaImport.Type mis-match.", importType, actualImportType); 675 676 IModelicaClass importedPackage = modelicaImport.getImportedPackage(); 677 678 String errorMsg = "importedPackageName was set to \"" + importedPackageName + 679 "\" but modelicaImport.getImportedPackage() returned null."; 680 681 assertNotNull(errorMsg, importedPackage); 682 683 String actualImportedPackagename = importedPackage.getFullName(); 684 685 assertEquals("The expected imported package name does not match the actual one.", importedPackageName, actualImportedPackagename); 686 687 String actualAlias = modelicaImport.getAlias(); 688 689 assertEquals("The expected alias does not match the actual one.", alias, actualAlias); 721 690 } 722 691
Note: See TracChangeset
for help on using the changeset viewer.