1 package org.jacorb.test.orb.dynany; 2 3 22 23 import junit.framework.*; 24 import junit.extensions.TestSetup; 25 26 import org.omg.CORBA.TCKind ; 27 import org.omg.DynamicAny.NameValuePair ; 28 import org.omg.DynamicAny.NameDynAnyPair ; 29 30 import org.jacorb.test.common.ORBSetup; 31 import org.jacorb.test.NonEmptyException; 32 import org.jacorb.test.NonEmptyExceptionHelper; 33 34 40 41 public class DynAnyNonEmptyExTest extends TestCase 42 { 43 private static org.omg.DynamicAny.DynAnyFactory factory = null; 44 private static org.omg.CORBA.ORB orb = null; 45 46 private static final String ID = "IDL:test:1.0"; 47 private static final String NAME = "MyNonEmptyException"; 48 49 public DynAnyNonEmptyExTest (String name) 50 { 51 super (name); 52 } 53 54 55 public static Test suite () 56 { 57 TestSuite suite = new TestSuite ("Non-empty Exception DynStruct Tests"); 58 Setup setup = new Setup (suite); 59 ORBSetup osetup = new ORBSetup (setup); 60 61 suite.addTest (new DynAnyNonEmptyExTest ("testFactoryCreateFromAny")); 62 suite.addTest (new DynAnyNonEmptyExTest ("testFactoryCreateFromTypeCode")); 63 suite.addTest (new DynAnyNonEmptyExTest ("testFactoryCreateFromIDLTypeCode")); 64 suite.addTest (new DynAnyNonEmptyExTest ("testCompareDynAny")); 65 suite.addTest (new DynAnyNonEmptyExTest ("testIterateDynAny")); 66 suite.addTest (new DynAnyNonEmptyExTest ("testAccessStructMembers")); 67 suite.addTest (new DynAnyNonEmptyExTest ("testAccessStructNameValuePairs")); 68 suite.addTest (new DynAnyNonEmptyExTest ("testAccessStructDynAnyPairs")); 69 suite.addTest (new DynAnyNonEmptyExTest ("testAccessStructPairsEx")); 70 suite.addTest (new DynAnyNonEmptyExTest ("testDynAnyTypeCode")); 71 suite.addTest (new DynAnyNonEmptyExTest ("testInitDynAnyFromDynAny")); 72 suite.addTest (new DynAnyNonEmptyExTest ("testInitDynAnyFromAny")); 73 suite.addTest (new DynAnyNonEmptyExTest ("testInitFromAnyTypeMismatchEx")); 74 suite.addTest (new DynAnyNonEmptyExTest ("testGenerateAnyFromDynAny")); 75 suite.addTest (new DynAnyNonEmptyExTest ("testDestroyDynAny")); 76 suite.addTest (new DynAnyNonEmptyExTest ("testDestroyComponent")); 77 suite.addTest (new DynAnyNonEmptyExTest ("testCopyDynAny")); 78 79 return osetup; 80 } 81 82 83 87 public void testFactoryCreateFromAny () 88 { 89 NonEmptyException type = null; 90 org.omg.CORBA.Any any = null; 91 92 type = new NonEmptyException (1, "Hello"); 93 any = orb.create_any (); 94 NonEmptyExceptionHelper.insert (any, type); 95 96 createDynAnyFromAny (any); 97 } 98 99 100 104 public void testFactoryCreateFromTypeCode () 105 { 106 org.omg.CORBA.TypeCode tc = null; 107 108 tc = orb.create_exception_tc (ID, NAME, getExceptionMembers ()); 109 createDynAnyFromTypeCode (tc); 110 } 111 112 113 117 public void testFactoryCreateFromIDLTypeCode () 118 { 119 org.omg.CORBA.TypeCode tc = null; 120 121 tc = NonEmptyExceptionHelper.type (); 122 createDynAnyFromTypeCode (tc); 123 } 124 125 126 129 public void testCompareDynAny () 130 { 131 String msg; 132 NonEmptyException type; 133 org.omg.CORBA.Any any = null; 134 org.omg.DynamicAny.DynStruct dynAny = null; 135 org.omg.DynamicAny.DynStruct dynAny2 = null; 136 137 type = new NonEmptyException (1, "Hello"); 138 any = orb.create_any (); 139 NonEmptyExceptionHelper.insert (any, type); 140 dynAny = createDynAnyFromAny (any); 141 dynAny2 = createDynAnyFromAny (any); 142 143 msg = "Comparing two equal DynAny values using DynAny::equal failed"; 144 assertTrue (msg, dynAny.equal (dynAny2)); 145 } 146 147 148 151 public void testIterateDynAny () 152 { 153 String msg; 154 int compCount = -1; 155 boolean seek; 156 org.omg.CORBA.TypeCode tc = null; 157 org.omg.DynamicAny.DynStruct dynAny = null; 158 org.omg.DynamicAny.DynAny compSeek = null; 159 org.omg.DynamicAny.DynAny compRewind = null; 160 161 tc = orb.create_exception_tc (ID, NAME, getExceptionMembers ()); 162 dynAny = createDynAnyFromTypeCode (tc); 163 164 msg = "The number of components returned from the "; 166 msg += "DynAny::component_count method is incorrect"; 167 try 168 { 169 compCount = dynAny.component_count (); 170 } 171 catch (Throwable ex) 172 { 173 fail ("Unexpected error raised by DynAny::component_count operation"); 175 } 176 assertEquals (msg, 2, compCount); 178 msg = "The DynAny::seek operation indicates a valid current position "; 180 msg += "when the current position should be invalid"; 181 seek = dynAny.seek (-1); 182 assertTrue (msg, !seek); 183 184 msg = "The DynAny::seek operation indicates an invalid current position "; 186 msg += "when the current position should be valid"; 187 seek = dynAny.seek (0); 188 assertTrue (msg, seek); 189 190 try 192 { 193 compSeek = dynAny.current_component (); 194 } 195 catch (Throwable ex) 196 { 197 msg = "Failed to get the current component using the "; 198 msg += "DynAny::current_component operation after calling the "; 199 msg += "DynAny::seek operation"; 200 fail (msg); 201 } 202 203 msg = "The DynAny::next operation indicates an invalid current position "; 205 msg += "when the current position should be valid"; 206 seek = dynAny.next (); 207 assertTrue (msg, seek); 208 209 dynAny.rewind (); 211 212 try 214 { 215 compRewind = dynAny.current_component (); 216 } 217 catch (Throwable ex) 218 { 219 msg = "Failed to get the current component using the "; 220 msg += "DynAny::current_component operation after calling the "; 221 msg += "DynAny::rewind operation"; 222 fail (msg); 223 } 224 msg = "The component at DynAny::seek(0) is not equal to the "; 225 msg += "component at DynAny::rewind"; 226 assertTrue (msg, compSeek.equal (compRewind)); 227 } 228 229 230 233 public void testAccessStructMembers () 234 { 235 String msg; 236 String memberName = null; 237 TCKind memberKind = null; 238 org.omg.CORBA.TypeCode tc = null; 239 org.omg.DynamicAny.DynStruct dynAny = null; 240 241 tc = NonEmptyExceptionHelper.type (); 242 dynAny = createDynAnyFromTypeCode (tc); 243 244 msg = "Failed to get the correct name of the first member using "; 246 msg += "DynStruct::current_member_name operation"; 247 try 248 { 249 memberName = dynAny.current_member_name (); 250 251 assertEquals (msg, "field1", memberName); } 253 catch (AssertionFailedError ex) 254 { 255 throw ex; 256 } 257 catch (Throwable ex) 258 { 259 fail (msg + ": " + ex); 260 } 261 262 msg = "Failed to get the correct kind of the first member using "; 264 msg += "DynStruct::current_member_kind operation"; 265 try 266 { 267 memberKind = dynAny.current_member_kind (); 268 269 assertEquals (msg, TCKind._tk_long, memberKind.value ()); 271 } 272 catch (AssertionFailedError ex) 273 { 274 throw ex; 275 } 276 catch (Throwable ex) 277 { 278 fail (msg + ": " + ex); 279 } 280 281 dynAny.next (); 283 284 msg = "Failed to get the correct name of the second member using "; 286 msg += "DynStruct::current_member_name operation"; 287 try 288 { 289 memberName = dynAny.current_member_name (); 290 291 assertEquals (msg, "field2", memberName); } 293 catch (AssertionFailedError ex) 294 { 295 throw ex; 296 } 297 catch (Throwable ex) 298 { 299 fail (msg + ": " + ex); 300 } 301 302 msg = "Failed to get the correct kind of the second member using "; 304 msg += "DynStruct::current_member_kind operation"; 305 try 306 { 307 memberKind = dynAny.current_member_kind (); 308 309 assertEquals (msg, TCKind._tk_string, memberKind.value ()); 311 } 312 catch (AssertionFailedError ex) 313 { 314 throw ex; 315 } 316 catch (Throwable ex) 317 { 318 fail (msg + ": " + ex); 319 } 320 321 dynAny.seek (-1); 323 324 msg = "Failed to throw an InvalidValue exception when calling "; 326 msg += "DynStruct::current_member_name operation at an invalid position"; 327 try 328 { 329 memberName = dynAny.current_member_name (); 330 331 fail (msg); 332 } 333 catch (AssertionFailedError ex) 334 { 335 throw ex; 336 } 337 catch (Throwable ex) 338 { 339 if (!(ex instanceof org.omg.DynamicAny.DynAnyPackage.InvalidValue )) 340 { 341 fail (msg + ": " + ex); 342 } 343 } 344 345 msg = "Failed to throw an InvalidValue exception when calling "; 347 msg += "DynStruct::current_member_kind operation at an invalid position"; 348 try 349 { 350 memberKind = dynAny.current_member_kind (); 351 352 fail (msg); 353 } 354 catch (AssertionFailedError ex) 355 { 356 throw ex; 357 } 358 catch (Throwable ex) 359 { 360 if (!(ex instanceof org.omg.DynamicAny.DynAnyPackage.InvalidValue )) 361 { 362 fail (msg + ": " + ex); 363 } 364 } 365 } 366 367 368 371 public void testAccessStructNameValuePairs () 372 { 373 final String name1 = "field1"; final String name2 = "field2"; String msg; 376 org.omg.CORBA.Any any = null; 377 NonEmptyException type = null; 378 int oldInt = 1; 379 String oldStr = "Hello"; 380 int newInt = 2; 381 String newStr = "GoodBye"; 382 org.omg.DynamicAny.DynStruct dynAny = null; 383 org.omg.DynamicAny.NameValuePair [] pairs = null; 384 385 type = new NonEmptyException (oldInt, oldStr); 386 any = orb.create_any (); 387 NonEmptyExceptionHelper.insert (any, type); 388 dynAny = createDynAnyFromAny (any); 389 390 pairs = dynAny.get_members (); 392 msg = "Old name associated with first name/value pair is incorrect"; 393 assertEquals (msg, name1, pairs [0].id); 394 msg = "Old value associated with first name/value pair is incorrect"; 395 assertEquals (msg, oldInt, pairs [0].value.extract_long ()); 396 msg = "Old name associated with second name/value pair is incorrect"; 397 assertEquals (msg, name2, pairs [1].id); 398 msg = "Old value associated with second name/value pair is incorrect"; 399 assertEquals (msg, oldStr, pairs [1].value.extract_string ()); 400 401 pairs = new NameValuePair [2]; any = orb.create_any (); 403 any.insert_long (newInt); 404 pairs [0] = new NameValuePair (name1, any); 405 any = orb.create_any (); 406 any.insert_string (newStr); 407 pairs [1] = new NameValuePair (name2, any); 408 409 try 410 { 411 dynAny.set_members (pairs); 412 } 413 catch (Throwable ex) 414 { 415 msg = "Failed to set DynStruct members using DynStruct::set_members "; 416 msg += "operation"; 417 fail (msg + ": " + ex); 418 } 419 420 pairs = dynAny.get_members (); 422 msg = "New name associated with first name/value pair is incorrect"; 423 assertEquals (msg, name1, pairs [0].id); 424 msg = "New value associated with first name/value pair is incorrect "; 425 assertEquals (msg, newInt, pairs [0].value.extract_long ()); 426 msg = "New name associated with second name/value pair is incorrect"; 427 assertEquals (msg, name2, pairs [1].id); 428 msg = "New value associated with second name/value pair is incorrect"; 429 assertEquals (msg, newStr, pairs [1].value.extract_string ()); 430 } 431 432 433 436 public void testAccessStructDynAnyPairs () 437 { 438 final String name1 = "field1"; final String name2 = "field2"; String msg; 441 org.omg.CORBA.Any any = null; 442 NonEmptyException type = null; 443 int oldInt = 1; 444 String oldStr = "Hello"; 445 int newInt = 2; 446 String newStr = "GoodBye"; 447 org.omg.DynamicAny.DynStruct dynAny = null; 448 org.omg.DynamicAny.DynAny dynAny1 = null; 449 org.omg.DynamicAny.DynAny dynAny2 = null; 450 org.omg.DynamicAny.NameDynAnyPair [] pairs = null; 451 452 type = new NonEmptyException (oldInt, oldStr); 453 any = orb.create_any (); 454 NonEmptyExceptionHelper.insert (any, type); 455 dynAny = createDynAnyFromAny (any); 456 457 pairs = dynAny.get_members_as_dyn_any (); 459 msg = "Old name associated with first name/value pair is incorrect"; 460 assertEquals (msg, name1, pairs [0].id); 461 msg = "Old value associated with first name/value pair is incorrect"; 462 assertEquals (msg, oldInt, pairs [0].value.to_any ().extract_long ()); 463 msg = "Old name associated with second name/value pair is incorrect"; 464 assertEquals (msg, name2, pairs [1].id); 465 msg = "Old value associated with second name/value pair is incorrect"; 466 assertEquals (msg, oldStr, pairs [1].value.to_any ().extract_string ()); 467 468 any = orb.create_any (); 469 any.insert_long (newInt); 470 try 471 { 472 dynAny1 = factory.create_dyn_any (any); 473 } 474 catch (Throwable ex) 475 { 476 msg = "Factory failed to create DynAny from Any for first member "; 477 msg += "using DynAny::create_dyn_any operation: " + ex; 478 fail (msg); 479 } 480 481 any = orb.create_any (); 482 any.insert_string (newStr); 483 try 484 { 485 dynAny2 = factory.create_dyn_any (any); 486 } 487 catch (Throwable ex) 488 { 489 msg = "Factory failed to create DynAny from Any for second member "; 490 msg += "using DynAny::create_dyn_any operation: " + ex; 491 fail (msg); 492 } 493 494 pairs = new NameDynAnyPair [2]; pairs [0] = new NameDynAnyPair (name1, dynAny1); 496 pairs [1] = new NameDynAnyPair (name2, dynAny2); 497 498 msg = "Failed to set DynStruct members using "; 499 msg += "DynStruct::set_members_as_dyn_any operation"; 500 try 501 { 502 dynAny.set_members_as_dyn_any (pairs); 503 } 504 catch (Throwable ex) 505 { 506 fail (msg + ": " + ex); 507 } 508 509 pairs = dynAny.get_members_as_dyn_any (); 511 msg = "New name associated with first name/value pair is incorrect"; 512 assertEquals (msg, name1, pairs [0].id); 513 msg = "New value associated with first name/value pair is incorrect "; 514 assertEquals (msg, newInt, pairs [0].value.to_any ().extract_long ()); 515 msg = "New name associated with second name/value pair is incorrect"; 516 assertEquals (msg, name2, pairs [1].id); 517 msg = "New value associated with second name/value pair is incorrect"; 518 assertEquals (msg, newStr, pairs [1].value.to_any ().extract_string ()); 519 } 520 521 522 526 public void testAccessStructPairsEx () 527 { 528 final String name1 = "field1"; 529 final String name2 = "field2"; 530 String msg; 531 org.omg.CORBA.Any any = null; 532 org.omg.CORBA.TypeCode tc = null; 533 org.omg.DynamicAny.DynStruct dynAny = null; 534 org.omg.DynamicAny.NameValuePair [] pairs = null; 535 536 tc = orb.create_exception_tc (ID, NAME, getExceptionMembers ()); 537 dynAny = createDynAnyFromTypeCode (tc); 538 539 pairs = new NameValuePair [2]; 541 any = orb.create_any (); 542 any.insert_char ('a'); 543 pairs [0] = new NameValuePair (name1, any); 544 any = orb.create_any (); 545 any.insert_string ("WrongType"); 546 pairs [0] = new NameValuePair (name2, any); 547 548 msg = "Failed to raise a TypeMismatch exception when passing in a "; 549 msg += "name/value pair containing an incorrect member value"; 550 try 551 { 552 dynAny.set_members (pairs); 553 554 fail (msg); 555 } 556 catch (org.omg.DynamicAny.DynAnyPackage.TypeMismatch ex) 557 { 558 } 560 catch (org.omg.DynamicAny.DynAnyPackage.InvalidValue ex) 561 { 562 fail (msg + ": " + ex); 563 } 564 565 pairs = new NameValuePair [2]; 567 any = orb.create_any (); 568 any.insert_char ('a'); 569 pairs [0] = new NameValuePair (name1, any); 570 any = orb.create_any (); 571 any.insert_longlong ((long) 1); 572 pairs [1] = new NameValuePair ("WrongName", any); 573 574 msg = "Failed to raise a TypeMismatch exception when passing in a "; 575 msg += "name/value pair containing an incorrect member name"; 576 try 577 { 578 dynAny.set_members (pairs); 579 580 fail (msg); 581 } 582 catch (org.omg.DynamicAny.DynAnyPackage.TypeMismatch ex) 583 { 584 } 586 catch (org.omg.DynamicAny.DynAnyPackage.InvalidValue ex) 587 { 588 fail (msg + ": " + ex); 589 } 590 591 pairs = new NameValuePair [3]; 593 any = orb.create_any (); 594 any.insert_char ('a'); 595 pairs [0] = new NameValuePair (name1, any); 596 any = orb.create_any (); 597 any.insert_longlong ((long) 1); 598 pairs [1] = new NameValuePair (name2, any); 599 any = orb.create_any (); 600 any.insert_longlong ((long) 1); 601 pairs [2] = new NameValuePair (name2, any); 602 603 msg = "Failed to raise an InvalidValue exception when passing in a "; 604 msg += "name/value sequence containing too many members"; 605 try 606 { 607 dynAny.set_members (pairs); 608 609 fail (msg); 610 } 611 catch (org.omg.DynamicAny.DynAnyPackage.InvalidValue ex) 612 { 613 } 615 catch (org.omg.DynamicAny.DynAnyPackage.TypeMismatch ex) 616 { 617 fail (msg + ": " + ex); 618 } 619 } 620 621 622 625 public void testDynAnyTypeCode () 626 { 627 String msg; 628 org.omg.CORBA.TypeCode tc = null; 629 org.omg.DynamicAny.DynStruct dynAny = null; 630 631 tc = orb.create_exception_tc (ID, NAME, getExceptionMembers ()); 632 dynAny = createDynAnyFromTypeCode (tc); 633 634 msg = "Incorrect TypeCode retrieved from DynAny::type operation"; 635 assertTrue (msg, dynAny.type ().equal (tc)); 636 } 637 638 639 642 public void testInitDynAnyFromDynAny () 643 { 644 String msg; 645 NonEmptyException type; 646 org.omg.CORBA.Any any = null; 647 org.omg.CORBA.TypeCode tc = null; 648 org.omg.DynamicAny.DynStruct dynAny = null; 649 org.omg.DynamicAny.DynStruct dynAny2 = null; 650 651 tc = NonEmptyExceptionHelper.type (); 652 dynAny = createDynAnyFromTypeCode (tc); 653 654 type = new NonEmptyException (1, "Hello"); 655 any = orb.create_any (); 656 NonEmptyExceptionHelper.insert (any, type); 657 dynAny2 = createDynAnyFromAny (any); 658 659 msg = "Failed to initialize a DynAny object from another DynAny "; 660 msg += "object using the DynAny::assign operation"; 661 try 662 { 663 dynAny.assign (dynAny2); 664 } 665 catch (Throwable ex) 666 { 667 fail (msg + ": " + ex); 668 } 669 assertTrue (msg, dynAny.equal (dynAny2)); 670 } 671 672 673 676 public void testInitDynAnyFromAny () 677 { 678 String msg; 679 NonEmptyException type; 680 org.omg.CORBA.Any any = null; 681 org.omg.CORBA.TypeCode tc = null; 682 org.omg.DynamicAny.DynStruct dynAny = null; 683 org.omg.DynamicAny.DynStruct dynAny2 = null; 684 685 tc = NonEmptyExceptionHelper.type (); 686 dynAny = createDynAnyFromTypeCode (tc); 687 688 type = new NonEmptyException (1, "Hello"); 689 any = orb.create_any (); 690 NonEmptyExceptionHelper.insert (any, type); 691 dynAny2 = createDynAnyFromAny (any); 692 693 msg = "Failed to initialize a DynAny object from an Any object "; 694 msg += "using the DynAny::from_any operation"; 695 try 696 { 697 dynAny.from_any (any); 698 } 699 catch (Throwable ex) 700 { 701 fail (msg + ": " + ex); 702 } 703 assertTrue (msg, dynAny.equal (dynAny2)); 704 } 705 706 707 711 public void testInitFromAnyTypeMismatchEx () 712 { 713 String msg; 714 org.omg.CORBA.Any any = null; 715 org.omg.CORBA.TypeCode tc = null; 716 org.omg.DynamicAny.DynStruct dynAny = null; 717 718 any = orb.create_any (); 719 any.insert_string ("Hello"); 720 721 tc = orb.create_exception_tc (ID, NAME, getExceptionMembers ()); 722 dynAny = createDynAnyFromTypeCode (tc); 723 724 msg = "TypeMismatch exception not thrown by DynAny::from_any "; 725 msg += "operation when DynAny and Any operands have different types"; 726 try 727 { 728 dynAny.from_any (any); 729 730 fail (msg); 731 } 732 catch (org.omg.DynamicAny.DynAnyPackage.TypeMismatch ex) 733 { 734 } 736 catch (org.omg.DynamicAny.DynAnyPackage.InvalidValue ex) 737 { 738 fail (msg + ": " + ex); 739 } 740 } 741 742 743 746 public void testGenerateAnyFromDynAny () 747 { 748 String msg; 749 org.omg.CORBA.Any any = null; 750 org.omg.CORBA.TypeCode tc = null; 751 org.omg.DynamicAny.DynStruct dynAny = null; 752 org.omg.DynamicAny.DynStruct dynAny2 = null; 753 754 tc = NonEmptyExceptionHelper.type (); 755 dynAny = createDynAnyFromTypeCode (tc); 756 757 any = orb.create_any (); 758 any = dynAny.to_any (); 759 dynAny2 = createDynAnyFromAny (any); 760 761 msg = "The DynAny::to_any operation failed to create an Any "; 762 msg += "object with the same value as the DynAny object"; 763 assertTrue (msg, dynAny.equal (dynAny2)); 764 } 765 766 767 770 public void testDestroyDynAny () 771 { 772 String msg; 773 NonEmptyException type; 774 org.omg.CORBA.Any any = null; 775 org.omg.DynamicAny.DynStruct dynAny = null; 776 777 type = new NonEmptyException (1, "Hello"); 778 any = orb.create_any (); 779 NonEmptyExceptionHelper.insert (any, type); 780 dynAny = createDynAnyFromAny (any); 781 dynAny.destroy (); 782 783 try 784 { 785 dynAny.type (); 786 787 msg = "Failed to destroy DynAny using DynAny::destroy operation - "; 788 msg += "calling DynAny::type operation on a destroyed DynAny object "; 789 msg += "did not raise OBJECT_NOT_EXIST exception"; 790 fail (msg); 791 } 792 catch (org.omg.CORBA.OBJECT_NOT_EXIST ex) 793 { 794 } 796 797 msg = "Failed to destroy DynAny using DynAny::destroy operation - "; 798 msg += "calling DynAny::current_component operation on a destroyed "; 799 msg += "DynAny object did not raise OBJECT_NOT_EXIST exception"; 800 try 801 { 802 dynAny.current_component (); 803 804 fail (msg); 805 } 806 catch (org.omg.CORBA.OBJECT_NOT_EXIST ex) 807 { 808 } 810 catch (org.omg.DynamicAny.DynAnyPackage.TypeMismatch ex) 811 { 812 fail (msg + ": " + ex); 813 } 814 } 815 816 817 820 public void testDestroyComponent () 821 { 822 String msg; 823 NonEmptyException type; 824 org.omg.CORBA.Any any = null; 825 org.omg.DynamicAny.DynStruct dynAny = null; 826 org.omg.DynamicAny.DynAny comp = null; 827 828 type = new NonEmptyException (1, "Hello"); 829 any = orb.create_any (); 830 NonEmptyExceptionHelper.insert (any, type); 831 dynAny = createDynAnyFromAny (any); 832 833 try 834 { 835 comp = dynAny.current_component (); 836 } 837 catch (Throwable ex) 838 { 839 msg = "Failed to get the current component of the DynAny using the "; 840 msg += "DynAny::current_component operation before calling the "; 841 msg += "DynAny::destroy operation"; 842 fail (msg + ": " + ex); 843 } 844 845 comp.destroy (); 846 try 847 { 848 comp = dynAny.current_component (); 849 } 850 catch (Throwable ex) 851 { 852 msg = "Failed to get the current component of the DynAny using the "; 853 msg += "DynAny::current_component operation after calling the "; 854 msg += "DynAny::destroy operation"; 855 fail (msg + ": " + ex); 856 } 857 858 try 859 { 860 comp.type (); 861 } 862 catch (org.omg.CORBA.OBJECT_NOT_EXIST ex) 863 { 864 msg = "Calling destroy on a component resulted in destroying the "; 865 msg += "component object"; 866 fail (msg + ": " + ex); 867 } 868 } 869 870 871 874 public void testCopyDynAny () 875 { 876 String msg; 877 org.omg.CORBA.TypeCode tc = null; 878 org.omg.DynamicAny.DynStruct dynAny = null; 879 org.omg.DynamicAny.DynStruct dynAny2 = null; 880 881 tc = NonEmptyExceptionHelper.type (); 882 dynAny = createDynAnyFromTypeCode (tc); 883 dynAny2 = (org.omg.DynamicAny.DynStruct ) dynAny.copy (); 884 885 msg = "The DynAny object created with the DynAny::copy operation "; 886 msg += "is not equal to the DynAny object it was copied from"; 887 assertTrue (msg, dynAny.equal (dynAny2)); 888 } 889 890 891 private static class Setup extends TestSetup 892 { 893 public Setup (Test test) 894 { 895 super (test); 896 } 897 898 protected void setUp () 899 { 900 org.omg.CORBA.Object obj = null; 901 902 orb = ORBSetup.getORB (); 903 try 904 { 905 obj = orb.resolve_initial_references ("DynAnyFactory"); 906 } 907 catch (org.omg.CORBA.ORBPackage.InvalidName ex) 908 { 909 fail ("Failed to resolve DynAnyFactory: " + ex); 910 } 911 try 912 { 913 factory = org.omg.DynamicAny.DynAnyFactoryHelper.narrow (obj); 914 } 915 catch (Throwable ex) 916 { 917 fail ("Failed to narrow to DynAnyFactory: " + ex); 918 } 919 } 920 921 protected void tearDown () 922 { 923 } 924 } 925 926 927 930 private static org.omg.DynamicAny.DynStruct createDynAnyFromAny 931 (org.omg.CORBA.Any any) 932 { 933 String msg; 934 org.omg.DynamicAny.DynStruct dynAny = null; 935 936 try 937 { 938 dynAny = (org.omg.DynamicAny.DynStruct ) factory.create_dyn_any (any); 939 } 940 catch (Throwable ex) 941 { 942 msg = "Factory failed to create DynAny from Any using "; 943 msg += "DynAny::create_dyn_any operation: " + ex; 944 fail (msg); 945 } 946 return dynAny; 947 } 948 949 950 953 private static org.omg.DynamicAny.DynStruct createDynAnyFromTypeCode 954 (org.omg.CORBA.TypeCode tc) 955 { 956 String msg; 957 org.omg.DynamicAny.DynStruct dynAny = null; 958 959 try 960 { 961 dynAny = (org.omg.DynamicAny.DynStruct ) 962 factory.create_dyn_any_from_type_code (tc); 963 } 964 catch (Throwable ex) 965 { 966 msg = "Factory failed to create DynAny from TypeCode using "; 967 msg += "DynAny::create_dyn_any_from_type_code operation: " + ex; 968 fail (msg); 969 } 970 return dynAny; 971 } 972 973 974 977 private static org.omg.CORBA.StructMember [] getExceptionMembers () 978 { 979 final org.omg.CORBA.StructMember [] members = 980 new org.omg.CORBA.StructMember [2]; 981 982 members [0] = new org.omg.CORBA.StructMember 983 ( 984 "field1", 985 orb.get_primitive_tc (TCKind.tk_char), 986 null 987 ); 988 989 members [1] = new org.omg.CORBA.StructMember 990 ( 991 "field2", 992 orb.get_primitive_tc (TCKind.tk_longlong), 993 null 994 ); 995 996 return members; 997 } 998 999 } 1000 | Popular Tags |