Changeset 1069 for trunk/org.modelica.mdt.test
- Timestamp:
- 11/01/11 23:20:13 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestModelicaProject.java
r1059 r1069 95 95 "components_bananza", 96 96 "nested_models", 97 "childless_package", 97 "childless_package", 98 98 "import_rich_model", 99 "folder_package", 99 "folder_package", 100 100 "hepp", 101 101 "muu", … … 107 107 */ 108 108 @Test 109 public void testGetClass() 109 public void testGetClass() 110 110 throws ConnectException, CompilerInstantiationException, UnexpectedReplyException, InvocationError, CoreException, Exception { 111 111 /* … … 136 136 testGetClass("components_bananza.a_class", "components_bananza.a_class", IModelicaClass.Restriction.CLASS); 137 137 138 testGetClass("components_bananza.a_type", "components_bananza.a_type", IModelicaClass.Restriction.TYPE); 138 testGetClass("components_bananza.a_type", "components_bananza.a_type", IModelicaClass.Restriction.TYPE); 139 139 140 140 testGetClass("components_bananza.a_connector", "components_bananza.a_connector", IModelicaClass.Restriction.CONNECTOR); … … 231 231 } 232 232 233 String errorMsg = " could not find following expeced root classes:";233 String errorMsg = "Could not find following expected root classes:"; 234 234 for (String cls : expectedRootPackages) { 235 235 errorMsg += " " + cls; … … 251 251 testFindElement("package_look_alike", IModelicaFolder.class, null); 252 252 253 /* 253 /* 254 254 * FIXME: We are currently not creating the empty file package.mo inside package_look_alike 255 255 * because it makes OMC to freeze. When this problem has been fixed, we can run this test … … 294 294 testFindElement("root_model.mo", IModelicaSourceFile.class, null); 295 295 296 testFindElement("empty_file", IModelicaFile.class, null); 296 testFindElement("empty_file", IModelicaFile.class, null); 297 297 298 298 testFindElement("README.txt", IModelicaFile.class, null); … … 300 300 /* 301 301 * check what happens when trying to find non-existing elements 302 * 302 * 303 303 * BEWARE, the test below can break if elements search for are added 304 304 * to the area51 modelica project … … 307 307 308 308 testFindElementNonExisting("packages_folder/file_package.mo/file_package2"); 309 309 310 310 testFindElementNonExisting("non_existing_file"); 311 311 … … 325 325 } 326 326 327 private void testGetClass(String className, String expectedFullName, IModelicaClass.Restriction expectedRestriction) throws Exception { 327 private void testGetClass(String className, String expectedFullName, IModelicaClass.Restriction expectedRestriction) 328 throws ConnectException, CompilerInstantiationException, UnexpectedReplyException, InvocationError, CoreException { 328 329 IModelicaClass pkg = project.getClass(className); 329 330 … … 332 333 } 333 334 334 assertNotNull("project.getClass() returned null for \"" + className + "\"", pkg); 335 String getClassFail = "project.getClass() returned null for className \"" + className + "\"."; 336 337 assertNotNull(getClassFail, pkg); 335 338 336 339 String actualFullName = pkg.getFullName(); 337 338 assertEquals("Expected pkg.getFullName() to return \"" + expectedFullName + "\" for className \"" + className + "\", but got \"" + actualFullName + "\".", expectedFullName, actualFullName); 340 String fullNameFail = "Expected pkg.getFullName() to return \"" + expectedFullName + "\" for className \"" + className + 341 "\", but got \"" + actualFullName + "\"."; 342 343 assertEquals(fullNameFail, expectedFullName, actualFullName); 339 344 340 345 IModelicaClass.Restriction actualRestriction = pkg.getRestriction(); 341 342 assertEquals("Expected restriction " + expectedRestriction + ", but got " + actualRestriction + ".", expectedRestriction, actualRestriction); 346 String restrictionFail = "For className \"" + className + "\", the expected restriction was \"" + expectedRestriction + 347 "\", but we got \"" + actualRestriction + "\"."; 348 349 assertEquals(restrictionFail, expectedRestriction, actualRestriction); 343 350 } 344 351 345 352 private void testGetClassNonExisting(String className) throws Exception { 346 353 IModelicaClass pkg = project.getClass(className); 347 348 assertNull("project.getClass() was called with \"" + className + "\", and was expected to return NULL, but didn't.", pkg); 349 } 350 354 String getClassNonExistingFail = "project.getClass() was called with className \"" + className + 355 "\", and was expected to return NULL, but didn't."; 356 357 assertNull(getClassNonExistingFail, pkg); 358 } 359 351 360 private void testFindElement(String pathName, Class<?> expectedClass, IModelicaClass.Restriction expectedRestriction) 352 361 throws ConnectException, UnexpectedReplyException, CompilerInstantiationException, InvocationError, CoreException { 353 362 Path path = new Path(pathName); 354 363 IModelicaElement element = project.findElement(path); 355 356 assertNotNull(element); 357 364 String findElementFail = "project.findElement() returned null for pathName \"" + pathName + "\"."; 365 366 assertNotNull(findElementFail, element); 367 358 368 Class<?> actualClass = element.getClass(); 359 369 String expectedClassName = expectedClass.getCanonicalName(); 360 370 String actualClassName = actualClass.getCanonicalName(); 361 String errorMsgClass = "Was expecting " + expectedClassName + ", but got " + actualClassName; 362 371 String errorMsgClass = "For pathName \"" + pathName + "\", we expected to find an element that is an instance of \"" + 372 expectedClassName + "\", but the returned class \"" + actualClassName + "\" is not an instance of that class."; 373 363 374 assertTrue(errorMsgClass, expectedClass.isAssignableFrom(actualClass)); 364 375 365 376 if (expectedRestriction != null) { 366 assertTrue(element instanceof IModelicaClass); 377 String typeFail = "Since a restriction \"" + expectedRestriction + "\" was specified for pathName \"" + 378 pathName + "\", it was expected to be an instance of IModelicaClass, but it was not."; 379 380 assertTrue(typeFail, element instanceof IModelicaClass); 381 367 382 IModelicaClass.Restriction actualRestriction = ((IModelicaClass)element).getRestriction(); 368 369 assertEquals("Expected restriction " + expectedRestriction + ", but got " + actualRestriction + ".", expectedRestriction, actualRestriction); 383 String restrictionFail = "For pathName \"" + pathName + "\", the expected restriction was \"" + expectedRestriction 384 + "\", but we got \"" + actualRestriction + "\"."; 385 386 assertEquals(restrictionFail, expectedRestriction, actualRestriction); 370 387 } 371 388 } 372 373 private void testFindElementNonExisting(String pathName) 389 390 private void testFindElementNonExisting(String pathName) 374 391 throws ConnectException, UnexpectedReplyException, CompilerInstantiationException, InvocationError, CoreException { 375 392 Path path = new Path(pathName); 376 393 IModelicaElement element = project.findElement(path); 377 assertNull(element); 378 } 379 380 private void printAll(Collection<? extends IModelicaElement> children, int indent) throws Exception { 394 String findElementNonExistingFail = "project.findElement() was called with pathName \"" + pathName + 395 "\", and was expected to return NULL, but didn't."; 396 397 assertNull(findElementNonExistingFail, element); 398 } 399 400 private void printAll(Collection<? extends IModelicaElement> children, int indent) 401 throws ConnectException, UnexpectedReplyException, InvocationError, CompilerInstantiationException, CoreException { 381 402 for (IModelicaElement elem : children) { 382 403 for (int i = 0; i < indent; i++) System.out.print(" ");
Note: See TracChangeset
for help on using the changeset viewer.