SerializationStressTest4.java revision f6c387128427e121477c1b32ad35cdcaa5101ba3
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package tests.api.java.io; 19 20import dalvik.annotation.TestTargets; 21import dalvik.annotation.TestLevel; 22import dalvik.annotation.TestTargetNew; 23import dalvik.annotation.TestTargetClass; 24 25import java.io.File; 26import java.io.FilePermission; 27import java.io.IOException; 28import java.io.Serializable; 29import java.lang.reflect.InvocationHandler; 30import java.lang.reflect.Method; 31import java.lang.reflect.Proxy; 32import java.net.URI; 33import java.net.URISyntaxException; 34import java.security.AllPermission; 35import java.security.PermissionCollection; 36import java.security.cert.Certificate; 37import java.text.DateFormat; 38import java.text.MessageFormat; 39import java.text.NumberFormat; 40import java.util.Arrays; 41import java.util.Comparator; 42import java.util.Date; 43import java.util.Enumeration; 44import java.util.HashMap; 45import java.util.IdentityHashMap; 46import java.util.Iterator; 47import java.util.List; 48import java.util.Locale; 49import java.util.Map; 50import java.util.Set; 51import java.util.TimeZone; 52 53import tests.support.Support_Configuration; 54import tests.support.Support_Proxy_I1; 55 56@TestTargetClass(java.io.Serializable.class) 57public class SerializationStressTest4 extends SerializationStressTest { 58 // ----------------------------------------------------------------------------------- 59 private static class GuardImplementation implements java.security.Guard, 60 java.io.Serializable { 61 public GuardImplementation() { 62 } 63 64 public void checkGuard(Object o) { 65 } 66 } 67 68 @TestTargetNew( 69 level = TestLevel.COMPLETE, 70 notes = "Verifies serialization.", 71 method = "!Serialization", 72 args = {} 73 ) 74 public void test_writeObject_EventObject() { 75 // Test for method void 76 // java.io.ObjectOutputStream.writeObject(java.util.EventObject) 77 78 Object objToSave = null; 79 Object objLoaded = null; 80 81 try { 82 objToSave = new java.util.EventObject("Source"); 83 if (DEBUG) 84 System.out.println("Obj = " + objToSave); 85 objLoaded = dumpAndReload(objToSave); 86 87 // Has to have worked 88 boolean equals; 89 equals = true; 90 // The the only data in EventObject that 91 // differentiates between instantiations is transient 92 assertTrue(MSG_TEST_FAILED + objToSave, equals); 93 } catch (IOException e) { 94 fail("IOException serializing " + objToSave + " : " 95 + e.getMessage()); 96 } catch (ClassNotFoundException e) { 97 fail("ClassNotFoundException reading Object type : " 98 + e.getMessage()); 99 } catch (Error err) { 100 System.out.println("Error when obj = " + objToSave); 101 // err.printStackTrace(); 102 throw err; 103 } 104 } 105 106 @TestTargetNew( 107 level = TestLevel.COMPLETE, 108 notes = "Verifies serialization.", 109 method = "!Serialization", 110 args = {} 111 ) 112 public void test_writeObject_PermissionCollection() { 113 // Test for method void 114 // java.io.ObjectOutputStream.writeObject(java.security.PermissionCollection) 115 116 Object objToSave = null; 117 Object objLoaded = null; 118 119 try { 120 objToSave = null; 121 objToSave = new java.security.PermissionCollection() { 122 boolean added = false; 123 124 public void add(java.security.Permission p1) { 125 added = true; 126 } 127 128 public java.util.Enumeration elements() { 129 return (new java.util.Vector()).elements(); 130 } 131 132 public boolean implies(java.security.Permission p1) { 133 return added; 134 } 135 136 public boolean equals(Object obj) { 137 if (!(obj instanceof java.security.PermissionCollection)) 138 return false; 139 return implies(null) == ((PermissionCollection) obj) 140 .implies(null); 141 } 142 }; 143 144 ((java.security.PermissionCollection) objToSave).add(null); 145 if (DEBUG) 146 System.out.println("Obj = " + objToSave); 147 objLoaded = dumpAndReload(objToSave); 148 149 // Has to have worked 150 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 151 } catch (IOException e) { 152 fail("IOException serializing " + objToSave + " : " 153 + e.getMessage()); 154 } catch (ClassNotFoundException e) { 155 fail("ClassNotFoundException reading Object type : " 156 + e.getMessage()); 157 } catch (Error err) { 158 System.out.println("Error when obj = " + objToSave); 159 // err.printStackTrace(); 160 throw err; 161 } 162 163 } 164 165 @TestTargetNew( 166 level = TestLevel.COMPLETE, 167 notes = "Verifies serialization.", 168 method = "!Serialization", 169 args = {} 170 ) 171 public void test_writeObject_Collections_EmptySet() { 172 // Test for method void 173 // java.io.ObjectOutputStream.writeObject(java.util.Collections.EmptySet) 174 175 Object objToSave = null; 176 Object objLoaded = null; 177 178 try { 179 objToSave = java.util.Collections.EMPTY_SET; 180 if (DEBUG) 181 System.out.println("Obj = " + objToSave); 182 objLoaded = dumpAndReload(objToSave); 183 184 // Has to have worked 185 boolean equals; 186 equals = objToSave.equals(objLoaded); 187 if (equals) 188 equals = ((Set) objLoaded).size() == 0; 189 assertTrue(MSG_TEST_FAILED + objToSave, equals); 190 } catch (IOException e) { 191 fail("IOException serializing " + objToSave + " : " 192 + e.getMessage()); 193 } catch (ClassNotFoundException e) { 194 fail("ClassNotFoundException reading Object type : " 195 + e.getMessage()); 196 } catch (Error err) { 197 System.out.println("Error when obj = " + objToSave); 198 // err.printStackTrace(); 199 throw err; 200 } 201 202 } 203 204 @TestTargetNew( 205 level = TestLevel.COMPLETE, 206 notes = "Verifies serialization.", 207 method = "!Serialization", 208 args = {} 209 ) 210 public void test_writeObject_Collections_EmptyMap() { 211 // Test for method void 212 // java.io.ObjectOutputStream.writeObject(java.util.Collections.EmptySet) 213 214 Object objToSave = null; 215 Object objLoaded = null; 216 217 try { 218 objToSave = java.util.Collections.EMPTY_MAP; 219 if (DEBUG) 220 System.out.println("Obj = " + objToSave); 221 objLoaded = dumpAndReload(objToSave); 222 223 // Has to have worked 224 boolean equals; 225 equals = objToSave.equals(objLoaded); 226 if (equals) 227 equals = ((Map) objLoaded).size() == 0; 228 assertTrue(MSG_TEST_FAILED + objToSave, equals); 229 } catch (IOException e) { 230 fail("IOException serializing " + objToSave + " : " 231 + e.getMessage()); 232 } catch (ClassNotFoundException e) { 233 fail("ClassNotFoundException reading Object type : " 234 + e.getMessage()); 235 } catch (Error err) { 236 System.out.println("Error when obj = " + objToSave); 237 // err.printStackTrace(); 238 throw err; 239 } 240 241 } 242 243 @TestTargetNew( 244 level = TestLevel.COMPLETE, 245 notes = "Verifies serialization.", 246 method = "!Serialization", 247 args = {} 248 ) 249 public void test_writeObject_BasicPermissionCollection() { 250 // Test for method void 251 // java.io.ObjectOutputStream.writeObject(java.security.BasicPermissionCollection) 252 253 Object objToSave = null; 254 Object objLoaded = null; 255 256 try { 257 objToSave = (new RuntimePermission("test")) 258 .newPermissionCollection(); 259 ((java.security.PermissionCollection) objToSave) 260 .add(new RuntimePermission("test")); 261 if (DEBUG) 262 System.out.println("Obj = " + objToSave); 263 objLoaded = dumpAndReload(objToSave); 264 265 // Has to have worked 266 boolean equals; 267 Enumeration enum1 = ((java.security.PermissionCollection) objToSave) 268 .elements(), enum2 = ((java.security.PermissionCollection) objLoaded) 269 .elements(); 270 271 equals = true; 272 while (enum1.hasMoreElements() && equals) { 273 if (enum2.hasMoreElements()) 274 equals = enum1.nextElement().equals(enum2.nextElement()); 275 else 276 equals = false; 277 } 278 279 if (equals) 280 equals = !enum2.hasMoreElements(); 281 assertTrue(MSG_TEST_FAILED + objToSave, equals); 282 } catch (IOException e) { 283 fail("IOException serializing " + objToSave + " : " 284 + e.getMessage()); 285 } catch (ClassNotFoundException e) { 286 fail("ClassNotFoundException reading Object type : " 287 + e.getMessage()); 288 } catch (Error err) { 289 System.out.println("Error when obj = " + objToSave); 290 // err.printStackTrace(); 291 throw err; 292 } 293 294 } 295 296 @TestTargetNew( 297 level = TestLevel.COMPLETE, 298 notes = "Verifies serialization.", 299 method = "!Serialization", 300 args = {} 301 ) 302 public void test_writeObject_UnresolvedPermission() { 303 // Test for method void 304 // java.io.ObjectOutputStream.writeObject(java.security.UnresolvedPermission) 305 306 Object objToSave = null; 307 Object objLoaded = null; 308 309 try { 310 objToSave = new java.security.UnresolvedPermission("type", "name", 311 "actions", null); 312 if (DEBUG) 313 System.out.println("Obj = " + objToSave); 314 objLoaded = dumpAndReload(objToSave); 315 316 // Has to have worked 317 boolean equals; 318 equals = objToSave.toString().equals(objLoaded.toString()); 319 assertTrue(MSG_TEST_FAILED + objToSave, equals); 320 } catch (IOException e) { 321 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 322 } catch (ClassNotFoundException e) { 323 fail("ClassNotFoundException reading Object type: " 324 + e.getMessage()); 325 } catch (Error err) { 326 System.out.println("Error when obj = " + objToSave); 327 // err.printStackTrace(); 328 throw err; 329 } 330 331 } 332 333 @TestTargetNew( 334 level = TestLevel.COMPLETE, 335 notes = "Verifies serialization.", 336 method = "!Serialization", 337 args = {} 338 ) 339 public void test_writeObject_Character() { 340 // Test for method void 341 // java.io.ObjectOutputStream.writeObject(java.lang.Character) 342 343 Object objToSave = null; 344 Object objLoaded = null; 345 346 try { 347 objToSave = new java.lang.Character('c'); 348 if (DEBUG) 349 System.out.println("Obj = " + objToSave); 350 objLoaded = dumpAndReload(objToSave); 351 352 // Has to have worked 353 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 354 } catch (IOException e) { 355 fail("IOException serializing " + objToSave + " : " 356 + e.getMessage()); 357 } catch (ClassNotFoundException e) { 358 fail("ClassNotFoundException reading Object type : " 359 + e.getMessage()); 360 } catch (Error err) { 361 System.out.println("Error when obj = " + objToSave); 362 // err.printStackTrace(); 363 throw err; 364 } 365 366 } 367 368 @TestTargetNew( 369 level = TestLevel.COMPLETE, 370 notes = "Verifies serialization.", 371 method = "!Serialization", 372 args = {} 373 ) 374 public void test_writeObject_Collections_UnmodifiableCollection() { 375 // Test for method void 376 // java.io.ObjectOutputStream.writeObject(java.util.Collections.UnmodifiableCollection) 377 378 Object objToSave = null; 379 Object objLoaded = null; 380 381 try { 382 objToSave = java.util.Collections.unmodifiableCollection(SET); 383 if (DEBUG) 384 System.out.println("Obj = " + objToSave); 385 objLoaded = dumpAndReload(objToSave); 386 387 // Has to have worked 388 boolean equals; 389 equals = ((java.util.Collection) objToSave).size() == ((java.util.Collection) objLoaded) 390 .size(); 391 if (equals) { 392 java.util.Iterator iter1 = ((java.util.Collection) objToSave) 393 .iterator(), iter2 = ((java.util.Collection) objLoaded) 394 .iterator(); 395 while (iter1.hasNext()) 396 equals = equals && iter1.next().equals(iter2.next()); 397 } 398 assertTrue(MSG_TEST_FAILED + objToSave, equals); 399 } catch (IOException e) { 400 fail("IOException serializing " + objToSave + " : " 401 + e.getMessage()); 402 } catch (ClassNotFoundException e) { 403 fail("ClassNotFoundException reading Object type : " 404 + e.getMessage()); 405 } catch (Error err) { 406 System.out.println("Error when obj = " + objToSave); 407 // err.printStackTrace(); 408 throw err; 409 } 410 411 } 412 413 @TestTargetNew( 414 level = TestLevel.COMPLETE, 415 notes = "Verifies serialization.", 416 method = "!Serialization", 417 args = {} 418 ) 419 public void test_writeObject_Format() { 420 // Test for method void 421 // java.io.ObjectOutputStream.writeObject(java.text.Format) 422 423 Object objToSave = null; 424 Object objLoaded = null; 425 426 try { 427 objToSave = null; 428 objToSave = new java.text.Format() { 429 String save = "default"; 430 431 public StringBuffer format(Object p1, StringBuffer p2, 432 java.text.FieldPosition p3) { 433 return new StringBuffer(); 434 } 435 436 public Object parseObject(String p1, java.text.ParsePosition p2) { 437 if (p1 != null) 438 save = p1; 439 return save; 440 } 441 442 public boolean equals(Object obj) { 443 if (!(obj instanceof java.text.Format)) 444 return false; 445 return save.equals(((java.text.Format) obj).parseObject( 446 null, null)); 447 } 448 }; 449 450 ((java.text.Format) objToSave).parseObject("Test", null); 451 if (DEBUG) 452 System.out.println("Obj = " + objToSave); 453 objLoaded = dumpAndReload(objToSave); 454 455 // Has to have worked 456 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 457 } catch (IOException e) { 458 fail("IOException serializing " + objToSave + " : " 459 + e.getMessage()); 460 } catch (ClassNotFoundException e) { 461 fail("ClassNotFoundException reading Object type : " 462 + e.getMessage()); 463 } catch (Error err) { 464 System.out.println("Error when obj = " + objToSave); 465 // err.printStackTrace(); 466 throw err; 467 } 468 } 469 470 @TestTargetNew( 471 level = TestLevel.COMPLETE, 472 notes = "Verifies serialization.", 473 method = "!Serialization", 474 args = {} 475 ) 476 public void test_writeObject_BigDecimal() { 477 // Test for method void 478 // java.io.ObjectOutputStream.writeObject(java.math.BigDecimal) 479 480 Object objToSave = null; 481 Object objLoaded = null; 482 483 try { 484 objToSave = new java.math.BigDecimal("1.2345"); 485 if (DEBUG) 486 System.out.println("Obj = " + objToSave); 487 objLoaded = dumpAndReload(objToSave); 488 489 // Has to have worked 490 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 491 } catch (IOException e) { 492 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 493 } catch (ClassNotFoundException e) { 494 fail("ClassNotFoundException reading Object type: " 495 + e.getMessage()); 496 } catch (Error err) { 497 System.out.println("Error when obj = " + objToSave); 498 // err.printStackTrace(); 499 throw err; 500 } 501 502 } 503 504 @TestTargetNew( 505 level = TestLevel.COMPLETE, 506 notes = "Verifies serialization.", 507 method = "!Serialization", 508 args = {} 509 ) 510 public void test_writeObject_UnresolvedPermissionCollection() { 511 // Test for method void 512 // java.io.ObjectOutputStream.writeObject(java.security.UnresolvedPermissionCollection) 513 514 Object objToSave = null; 515 Object objLoaded = null; 516 517 try { 518 objToSave = (new java.security.UnresolvedPermission("type", "name", 519 "actions", null)).newPermissionCollection(); 520 ((java.security.PermissionCollection) objToSave) 521 .add(new java.security.UnresolvedPermission("type", "name", 522 "actions", null)); 523 if (DEBUG) 524 System.out.println("Obj = " + objToSave); 525 objLoaded = dumpAndReload(objToSave); 526 527 // Has to have worked 528 boolean equals; 529 Enumeration enum1 = ((java.security.PermissionCollection) objToSave) 530 .elements(), enum2 = ((java.security.PermissionCollection) objLoaded) 531 .elements(); 532 533 equals = true; 534 while (enum1.hasMoreElements() && equals) { 535 if (enum2.hasMoreElements()) 536 equals = enum1.nextElement().toString().equals( 537 enum2.nextElement().toString()); 538 else 539 equals = false; 540 } 541 542 if (equals) 543 equals = !enum2.hasMoreElements(); 544 assertTrue(MSG_TEST_FAILED + objToSave, equals); 545 } catch (IOException e) { 546 fail("IOException serializing " + objToSave + " : " 547 + e.getMessage()); 548 } catch (ClassNotFoundException e) { 549 fail("ClassNotFoundException reading Object type : " 550 + e.getMessage()); 551 } catch (Error err) { 552 System.out.println("Error when obj = " + objToSave); 553 // err.printStackTrace(); 554 throw err; 555 } 556 557 } 558 559 @TestTargetNew( 560 level = TestLevel.COMPLETE, 561 notes = "Verifies serialization.", 562 method = "!Serialization", 563 args = {} 564 ) 565 public void test_writeObject_SecureRandomSpi() { 566 // Test for method void 567 // java.io.ObjectOutputStream.writeObject(java.security.SecureRandomSpi) 568 569 Object objToSave = null; 570 Object objLoaded = null; 571 572 try { 573 objToSave = null; 574 objToSave = new java.security.SecureRandomSpi() { 575 protected byte[] engineGenerateSeed(int p1) { 576 return new byte[0]; 577 } 578 579 protected void engineNextBytes(byte[] p1) { 580 } 581 582 protected void engineSetSeed(byte[] p1) { 583 } 584 585 public boolean equals(Object obj) { 586 return true; 587 } 588 }; 589 if (DEBUG) 590 System.out.println("Obj = " + objToSave); 591 objLoaded = dumpAndReload(objToSave); 592 593 // Has to have worked 594 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 595 } catch (IOException e) { 596 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 597 } catch (ClassNotFoundException e) { 598 fail("ClassNotFoundException reading Object type: " 599 + e.getMessage()); 600 } catch (Error err) { 601 System.out.println("Error when obj = " + objToSave); 602 // err.printStackTrace(); 603 throw err; 604 } 605 } 606 607 @TestTargetNew( 608 level = TestLevel.COMPLETE, 609 notes = "Verifies serialization.", 610 method = "!Serialization", 611 args = {} 612 ) 613 public void test_writeObject_Short() { 614 // Test for method void 615 // java.io.ObjectOutputStream.writeObject(java.lang.Short) 616 617 Object objToSave = null; 618 Object objLoaded = null; 619 620 try { 621 objToSave = new java.lang.Short((short) 107); 622 if (DEBUG) 623 System.out.println("Obj = " + objToSave); 624 objLoaded = dumpAndReload(objToSave); 625 626 // Has to have worked 627 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 628 } catch (IOException e) { 629 fail("IOException serializing " + objToSave + " : " 630 + e.getMessage()); 631 } catch (ClassNotFoundException e) { 632 fail("ClassNotFoundException reading Object type : " 633 + e.getMessage()); 634 } catch (Error err) { 635 System.out.println("Error when obj = " + objToSave); 636 // err.printStackTrace(); 637 throw err; 638 } 639 640 } 641 642 @TestTargetNew( 643 level = TestLevel.COMPLETE, 644 notes = "Verifies serialization.", 645 method = "!Serialization", 646 args = {} 647 ) 648 public void test_writeObject_Byte() { 649 // Test for method void 650 // java.io.ObjectOutputStream.writeObject(java.lang.Byte) 651 652 Object objToSave = null; 653 Object objLoaded = null; 654 655 try { 656 objToSave = new java.lang.Byte((byte) 107); 657 if (DEBUG) 658 System.out.println("Obj = " + objToSave); 659 objLoaded = dumpAndReload(objToSave); 660 661 // Has to have worked 662 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 663 } catch (IOException e) { 664 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 665 } catch (ClassNotFoundException e) { 666 fail("ClassNotFoundException reading Object type: " 667 + e.getMessage()); 668 } catch (Error err) { 669 System.out.println("Error when obj = " + objToSave); 670 // err.printStackTrace(); 671 throw err; 672 } 673 674 } 675 676 @TestTargetNew( 677 level = TestLevel.COMPLETE, 678 notes = "Verifies serialization.", 679 method = "!Serialization", 680 args = {} 681 ) 682 public void test_writeObject_String_CaseInsensitiveComparator() { 683 // Test for method void 684 // java.io.ObjectOutputStream.writeObject(java.lang.String.CaseInsensitiveComparator) 685 686 Object objToSave = null; 687 Object objLoaded = null; 688 689 try { 690 objToSave = java.lang.String.CASE_INSENSITIVE_ORDER; 691 if (DEBUG) 692 System.out.println("Obj = " + objToSave); 693 objLoaded = dumpAndReload(objToSave); 694 695 // Has to have worked 696 boolean equals; 697 equals = ((Comparator) objToSave).compare("apple", "Banana") == ((Comparator) objLoaded) 698 .compare("apple", "Banana"); 699 assertTrue(MSG_TEST_FAILED + objToSave, equals); 700 } catch (IOException e) { 701 fail("IOException serializing " + objToSave + " : " 702 + e.getMessage()); 703 } catch (ClassNotFoundException e) { 704 fail("ClassNotFoundException reading Object type : " 705 + e.getMessage()); 706 } catch (Error err) { 707 System.out.println("Error when obj = " + objToSave); 708 // err.printStackTrace(); 709 throw err; 710 } 711 712 } 713 714 @TestTargetNew( 715 level = TestLevel.COMPLETE, 716 notes = "Verifies serialization.", 717 method = "!Serialization", 718 args = {} 719 ) 720 public void _test_writeObject_Calendar() { 721 // Test for method void 722 // java.io.ObjectOutputStream.writeObject(java.util.Calendar) 723 724 Object objToSave = null; 725 Object objLoaded = null; 726 727 try { 728 objToSave = new java.util.Calendar(TimeZone.getTimeZone("EST"), 729 Locale.CANADA) { 730 public void add(int p1, int p2) { 731 } 732 733 protected void computeFields() { 734 } 735 736 protected void computeTime() { 737 } 738 739 public int getGreatestMinimum(int p1) { 740 return 0; 741 } 742 743 public int getLeastMaximum(int p1) { 744 return 0; 745 } 746 747 public int getMaximum(int p1) { 748 return 0; 749 } 750 751 public int getMinimum(int p1) { 752 return 0; 753 } 754 755 public void roll(int p1, boolean p2) { 756 } 757 }; 758 if (DEBUG) 759 System.out.println("Obj = " + objToSave); 760 objLoaded = dumpAndReload(objToSave); 761 762 // Has to have worked 763 assertTrue(MSG_TEST_FAILED + "Calendar", objToSave 764 .equals(objLoaded)); 765 } catch (IOException e) { 766 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 767 } catch (ClassNotFoundException e) { 768 fail("ClassNotFoundException reading Object type: " 769 + e.getMessage()); 770 } catch (Error err) { 771 System.out.println("Error when obj = " + objToSave); 772 // err.printStackTrace(); 773 throw err; 774 } 775 776 } 777 778 @TestTargetNew( 779 level = TestLevel.COMPLETE, 780 notes = "Verifies serialization.", 781 method = "!Serialization", 782 args = {} 783 ) 784 public void test_writeObject_ReflectPermission() { 785 // Test for method void 786 // java.io.ObjectOutputStream.writeObject(java.lang.reflect.ReflectPermission) 787 788 Object objToSave = null; 789 Object objLoaded = null; 790 791 try { 792 objToSave = new java.lang.reflect.ReflectPermission( 793 "TestSerialization", "test"); 794 if (DEBUG) 795 System.out.println("Obj = " + objToSave); 796 objLoaded = dumpAndReload(objToSave); 797 798 // Has to have worked 799 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 800 } catch (IOException e) { 801 fail("IOException serializing " + objToSave + " : " 802 + e.getMessage()); 803 } catch (ClassNotFoundException e) { 804 fail("ClassNotFoundException reading Object type : " 805 + e.getMessage()); 806 } catch (Error err) { 807 System.out.println("Error when obj = " + objToSave); 808 // err.printStackTrace(); 809 throw err; 810 } 811 812 } 813 814 @TestTargetNew( 815 level = TestLevel.COMPLETE, 816 notes = "Verifies serialization.", 817 method = "!Serialization", 818 args = {} 819 ) 820 public void test_writeObject_StringBuffer() { 821 // Test for method void 822 // java.io.ObjectOutputStream.writeObject(java.lang.StringBuffer) 823 824 Object objToSave = null; 825 Object objLoaded = null; 826 827 try { 828 objToSave = new java.lang.StringBuffer("This is a test."); 829 if (DEBUG) 830 System.out.println("Obj = " + objToSave); 831 objLoaded = dumpAndReload(objToSave); 832 833 // Has to have worked 834 boolean equals; 835 equals = ((java.lang.StringBuffer) objToSave).toString().equals( 836 ((java.lang.StringBuffer) objLoaded).toString()); 837 assertTrue(MSG_TEST_FAILED + objToSave, equals); 838 } catch (IOException e) { 839 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 840 } catch (ClassNotFoundException e) { 841 fail("ClassNotFoundException reading Object type: " 842 + e.getMessage()); 843 } catch (Error err) { 844 System.out.println("Error when obj = " + objToSave); 845 // err.printStackTrace(); 846 throw err; 847 } 848 849 } 850 851 @TestTargetNew( 852 level = TestLevel.COMPLETE, 853 notes = "Verifies serialization.", 854 method = "!Serialization", 855 args = {} 856 ) 857 public void test_writeObject_File() { 858 // Test for method void 859 // java.io.ObjectOutputStream.writeObject(java.io.File) 860 861 Object objToSave = null; 862 Object objLoaded = null; 863 864 try { 865 objToSave = new File("afile.txt"); 866 if (DEBUG) 867 System.out.println("Obj = " + objToSave); 868 objLoaded = dumpAndReload(objToSave); 869 870 // Has to have worked 871 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 872 } catch (IOException e) { 873 fail("IOException serializing " + objToSave + " : " 874 + e.getMessage()); 875 } catch (ClassNotFoundException e) { 876 fail("ClassNotFoundException reading Object type : " 877 + e.getMessage()); 878 } catch (Error err) { 879 System.out.println("Error when obj = " + objToSave); 880 // err.printStackTrace(); 881 throw err; 882 } 883 884 } 885 886 @TestTargetNew( 887 level = TestLevel.COMPLETE, 888 notes = "Verifies serialization.", 889 method = "!Serialization", 890 args = {} 891 ) 892 public void test_writeObject_AllPermissionCollection() { 893 // Test for method void 894 // java.io.ObjectOutputStream.writeObject(java.security.AllPermissionCollection) 895 896 Object objToSave = null; 897 Object objLoaded = null; 898 899 try { 900 objToSave = (new java.security.AllPermission()) 901 .newPermissionCollection(); 902 ((java.security.PermissionCollection) objToSave) 903 .add(new java.security.AllPermission()); 904 if (DEBUG) 905 System.out.println("Obj = " + objToSave); 906 objLoaded = dumpAndReload(objToSave); 907 908 // Has to have worked 909 boolean equals; 910 Enumeration enum1 = ((java.security.PermissionCollection) objToSave) 911 .elements(), enum2 = ((java.security.PermissionCollection) objLoaded) 912 .elements(); 913 914 equals = true; 915 while (enum1.hasMoreElements() && equals) { 916 if (enum2.hasMoreElements()) 917 equals = enum1.nextElement().equals(enum2.nextElement()); 918 else 919 equals = false; 920 } 921 922 if (equals) 923 equals = !enum2.hasMoreElements(); 924 assertTrue(MSG_TEST_FAILED + objToSave, equals); 925 } catch (IOException e) { 926 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 927 } catch (ClassNotFoundException e) { 928 fail("ClassNotFoundException reading Object type: " 929 + e.getMessage()); 930 } catch (Error err) { 931 System.out.println("Error when obj = " + objToSave); 932 // err.printStackTrace(); 933 throw err; 934 } 935 936 } 937 938 @TestTargetNew( 939 level = TestLevel.COMPLETE, 940 notes = "Verifies serialization.", 941 method = "!Serialization", 942 args = {} 943 ) 944 public void test_writeObject_BitSet() { 945 // Test for method void 946 // java.io.ObjectOutputStream.writeObject(java.util.BitSet) 947 948 Object objToSave = null; 949 Object objLoaded = null; 950 951 try { 952 objToSave = new java.util.BitSet(); 953 ((java.util.BitSet) objToSave).set(3); 954 ((java.util.BitSet) objToSave).set(5); 955 ((java.util.BitSet) objToSave).set(61, 89); 956 if (DEBUG) 957 System.out.println("Obj = " + objToSave); 958 objLoaded = dumpAndReload(objToSave); 959 960 // Has to have worked 961 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 962 } catch (IOException e) { 963 fail("IOException serializing " + objToSave + " : " 964 + e.getMessage()); 965 } catch (ClassNotFoundException e) { 966 fail("ClassNotFoundException reading Object type : " 967 + e.getMessage()); 968 } catch (Error err) { 969 System.out.println("Error when obj = " + objToSave); 970 // err.printStackTrace(); 971 throw err; 972 } 973 974 } 975 976 @TestTargetNew( 977 level = TestLevel.COMPLETE, 978 notes = "Verifies serialization.", 979 method = "!Serialization", 980 args = {} 981 ) 982 public void test_writeObject_DateFormat() { 983 // Test for method void 984 // java.io.ObjectOutputStream.writeObject(java.text.DateFormat) 985 986 Object objToSave = null; 987 Object objLoaded = null; 988 989 try { 990 objToSave = null; 991 objToSave = new java.text.DateFormat() { 992 // Thu Feb 01 01:01:01 EST 2001 993 java.util.Date save = new java.util.Date(981007261000L); 994 995 public StringBuffer format(Date p1, StringBuffer p2, 996 java.text.FieldPosition p3) { 997 if (p1 != null) 998 save = p1; 999 return new StringBuffer(Long.toString(save.getTime())); 1000 } 1001 1002 public Date parse(String p1, java.text.ParsePosition p2) { 1003 return save; 1004 } 1005 1006 public String toString() { 1007 return save.toString(); 1008 } 1009 1010 public boolean equals(Object obj) { 1011 if (!(obj instanceof java.text.DateFormat)) 1012 return false; 1013 return save.equals(((java.text.DateFormat) obj).parse(null, 1014 null)); 1015 } 1016 }; 1017 if (DEBUG) 1018 System.out.println("Obj = " + objToSave); 1019 objLoaded = dumpAndReload(objToSave); 1020 1021 // Has to have worked 1022 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1023 } catch (IOException e) { 1024 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1025 } catch (ClassNotFoundException e) { 1026 fail("ClassNotFoundException reading Object type: " 1027 + e.getMessage()); 1028 } catch (Error err) { 1029 System.out.println("Error when obj = " + objToSave); 1030 // err.printStackTrace(); 1031 throw err; 1032 } 1033 1034 } 1035 1036 @TestTargetNew( 1037 level = TestLevel.COMPLETE, 1038 notes = "Verifies serialization.", 1039 method = "!Serialization", 1040 args = {} 1041 ) 1042 public void test_writeObject_Collections_CopiesList() { 1043 // Test for method void 1044 // java.io.ObjectOutputStream.writeObject(java.util.Collections.CopiesList) 1045 1046 Object objToSave = null; 1047 Object objLoaded = null; 1048 1049 try { 1050 objToSave = java.util.Collections.nCopies(2, new Integer(2)); 1051 if (DEBUG) 1052 System.out.println("Obj = " + objToSave); 1053 objLoaded = dumpAndReload(objToSave); 1054 1055 // Has to have worked 1056 boolean equals; 1057 equals = ((List) objToSave).get(0) 1058 .equals(((List) objLoaded).get(0)); 1059 if (equals) 1060 equals = ((List) objToSave).get(1).equals( 1061 ((List) objLoaded).get(1)); 1062 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1063 } catch (IOException e) { 1064 fail("IOException serializing " + objToSave + " : " 1065 + e.getMessage()); 1066 } catch (ClassNotFoundException e) { 1067 fail("ClassNotFoundException reading Object type : " 1068 + e.getMessage()); 1069 } catch (Error err) { 1070 System.out.println("Error when obj = " + objToSave); 1071 // err.printStackTrace(); 1072 throw err; 1073 } 1074 1075 } 1076 1077 @TestTargetNew( 1078 level = TestLevel.COMPLETE, 1079 notes = "Verifies serialization.", 1080 method = "!Serialization", 1081 args = {} 1082 ) 1083 public void test_writeObject_SerializablePermission() { 1084 // Test for method void 1085 // java.io.ObjectOutputStream.writeObject(java.io.SerializablePermission) 1086 1087 Object objToSave = null; 1088 Object objLoaded = null; 1089 1090 try { 1091 objToSave = new java.io.SerializablePermission("TestSerialization", 1092 "Test"); 1093 if (DEBUG) 1094 System.out.println("Obj = " + objToSave); 1095 objLoaded = dumpAndReload(objToSave); 1096 1097 // Has to have worked 1098 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1099 } catch (IOException e) { 1100 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1101 } catch (ClassNotFoundException e) { 1102 fail("ClassNotFoundException reading Object type: " 1103 + e.getMessage()); 1104 } catch (Error err) { 1105 System.out.println("Error when obj = " + objToSave); 1106 // err.printStackTrace(); 1107 throw err; 1108 } 1109 1110 } 1111 1112 @TestTargetNew( 1113 level = TestLevel.COMPLETE, 1114 notes = "Verifies serialization.", 1115 method = "!Serialization", 1116 args = {} 1117 ) 1118 public void test_writeObject_Properties() { 1119 // Test for method void 1120 // java.io.ObjectOutputStream.writeObject(java.util.Properties) 1121 1122 Object objToSave = null; 1123 Object objLoaded = null; 1124 1125 try { 1126 objToSave = new java.util.Properties(); 1127 ((java.util.Properties) objToSave).put("key1", "value1"); 1128 ((java.util.Properties) objToSave).put("key2", "value2"); 1129 if (DEBUG) 1130 System.out.println("Obj = " + objToSave); 1131 objLoaded = dumpAndReload(objToSave); 1132 1133 // Has to have worked 1134 boolean equals; 1135 Enumeration enum1 = ((java.util.Properties) objToSave).elements(), enum2 = ((java.util.Properties) objLoaded) 1136 .elements(); 1137 1138 equals = true; 1139 while (enum1.hasMoreElements() && equals) { 1140 if (enum2.hasMoreElements()) 1141 equals = enum1.nextElement().equals(enum2.nextElement()); 1142 else 1143 equals = false; 1144 } 1145 1146 if (equals) 1147 equals = !enum2.hasMoreElements(); 1148 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1149 } catch (IOException e) { 1150 fail("IOException serializing " + objToSave + " : " 1151 + e.getMessage()); 1152 } catch (ClassNotFoundException e) { 1153 fail("ClassNotFoundException reading Object type : " 1154 + e.getMessage()); 1155 } catch (Error err) { 1156 System.out.println("Error when obj = " + objToSave); 1157 // err.printStackTrace(); 1158 throw err; 1159 } 1160 1161 } 1162 1163 // TODO : requires working security implementation 1164 // public void test_writeObject_BasicPermission() { 1165 // // Test for method void 1166 // // 1167 // java.io.ObjectOutputStream.writeObject(tests.java.security.Test_BasicPermission.BasicPermissionSubclass) 1168 // 1169 // Object objToSave = null; 1170 // Object objLoaded = null; 1171 // 1172 // try { 1173 // objToSave = new 1174 // tests.java.security.Test_BasicPermission.BasicPermissionSubclass( 1175 // "TestSerialization"); 1176 // if (DEBUG) 1177 // System.out.println("Obj = " + objToSave); 1178 // objLoaded = dumpAndReload(objToSave); 1179 // 1180 // // Has to have worked 1181 // assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1182 // } catch (IOException e) { 1183 // fail("Exception serializing " + objToSave + " : " 1184 // + e.getMessage()); 1185 // } catch (ClassNotFoundException e) { 1186 // fail("ClassNotFoundException reading Object type : " + e.getMessage()); 1187 // } catch (Error err) { 1188 // System.out.println("Error when obj = " + objToSave); 1189 // // err.printStackTrace(); 1190 // throw err; 1191 // } 1192 // 1193 // } 1194 1195 @TestTargetNew( 1196 level = TestLevel.COMPLETE, 1197 notes = "Verifies serialization.", 1198 method = "!Serialization", 1199 args = {} 1200 ) 1201 public void _test_writeObject_Collections_UnmodifiableMap_UnmodifiableEntrySet() { 1202 // Test for method void 1203 // java.io.ObjectOutputStream.writeObject(java.util.Collections.UnmodifiableMap.UnmodifiableEntrySet) 1204 1205 Object objToSave = null; 1206 Object objLoaded = null; 1207 1208 try { 1209 objToSave = java.util.Collections.unmodifiableMap(MAP).entrySet(); 1210 if (DEBUG) 1211 System.out.println("Obj = " + objToSave); 1212 objLoaded = dumpAndReload(objToSave); 1213 1214 // Has to have worked 1215 boolean equals; 1216 equals = ((java.util.Collection) objToSave).size() == ((java.util.Collection) objLoaded) 1217 .size(); 1218 if (equals) { 1219 java.util.Iterator iter1 = ((java.util.Collection) objToSave) 1220 .iterator(), iter2 = ((java.util.Collection) objLoaded) 1221 .iterator(); 1222 while (iter1.hasNext()) 1223 equals = equals && iter1.next().equals(iter2.next()); 1224 } 1225 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1226 } catch (IOException e) { 1227 fail("IOException serializing " + objToSave + " : " 1228 + e.getMessage()); 1229 } catch (ClassNotFoundException e) { 1230 fail("ClassNotFoundException reading Object type : " 1231 + e.getMessage()); 1232 } catch (Error err) { 1233 System.out.println("Error when obj = " + objToSave); 1234 // err.printStackTrace(); 1235 throw err; 1236 } 1237 1238 } 1239 1240 @TestTargetNew( 1241 level = TestLevel.COMPLETE, 1242 notes = "Verifies serialization.", 1243 method = "!Serialization", 1244 args = {} 1245 ) 1246 public void test_writeObject_NumberFormat() { 1247 // Test for method void 1248 // java.io.ObjectOutputStream.writeObject(java.text.NumberFormat) 1249 1250 Object objToSave = null; 1251 Object objLoaded = null; 1252 1253 try { 1254 objToSave = null; 1255 objToSave = new java.text.NumberFormat() { 1256 long save = 107; 1257 1258 public StringBuffer format(double p1, StringBuffer p2, 1259 java.text.FieldPosition p3) { 1260 return new StringBuffer(); 1261 } 1262 1263 public StringBuffer format(long p1, StringBuffer p2, 1264 java.text.FieldPosition p3) { 1265 if (p1 != 0) 1266 save = p1; 1267 return new StringBuffer(Long.toString(save)); 1268 } 1269 1270 public Number parse(String p1, java.text.ParsePosition p2) { 1271 return new Long(save); 1272 } 1273 1274 public boolean equals(Object obj) { 1275 if (!(obj instanceof java.text.NumberFormat)) 1276 return false; 1277 return save == ((Long) ((java.text.NumberFormat) obj) 1278 .parse(null, null)).longValue(); 1279 } 1280 }; 1281 1282 ((java.text.NumberFormat) objToSave).format(63L, null, null); 1283 if (DEBUG) 1284 System.out.println("Obj = " + objToSave); 1285 objLoaded = dumpAndReload(objToSave); 1286 1287 // Has to have worked 1288 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1289 } catch (IOException e) { 1290 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1291 } catch (ClassNotFoundException e) { 1292 fail("ClassNotFoundException reading Object type: " 1293 + e.getMessage()); 1294 } catch (Error err) { 1295 System.out.println("Error when obj = " + objToSave); 1296 // err.printStackTrace(); 1297 throw err; 1298 } 1299 1300 } 1301 1302 @TestTargetNew( 1303 level = TestLevel.COMPLETE, 1304 notes = "Verifies serialization.", 1305 method = "!Serialization", 1306 args = {} 1307 ) 1308 public void test_writeObject_TimeZone() { 1309 // Test for method void 1310 // java.io.ObjectOutputStream.writeObject(java.util.TimeZone) 1311 1312 Object objToSave = null; 1313 Object objLoaded = null; 1314 1315 try { 1316 objToSave = null; 1317 objToSave = new java.util.TimeZone() { 1318 int save = 0; 1319 1320 public int getOffset(int p1, int p2, int p3, int p4, int p5, 1321 int p6) { 1322 return 0; 1323 } 1324 1325 public int getRawOffset() { 1326 return save; 1327 } 1328 1329 public boolean inDaylightTime(java.util.Date p1) { 1330 return false; 1331 } 1332 1333 public void setRawOffset(int p1) { 1334 save = p1; 1335 } 1336 1337 public boolean useDaylightTime() { 1338 return false; 1339 } 1340 1341 public boolean equals(Object obj) { 1342 if (obj instanceof TimeZone) 1343 return save == ((TimeZone) obj).getRawOffset(); 1344 return false; 1345 } 1346 }; 1347 1348 ((java.util.TimeZone) objToSave).setRawOffset(48); 1349 if (DEBUG) 1350 System.out.println("Obj = " + objToSave); 1351 objLoaded = dumpAndReload(objToSave); 1352 1353 // Has to have worked 1354 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1355 } catch (IOException e) { 1356 fail("IOException serializing " + objToSave + " : " 1357 + e.getMessage()); 1358 } catch (ClassNotFoundException e) { 1359 fail("ClassNotFoundException reading Object type : " 1360 + e.getMessage()); 1361 } catch (Error err) { 1362 System.out.println("Error when obj = " + objToSave); 1363 // err.printStackTrace(); 1364 throw err; 1365 } 1366 1367 } 1368 1369 @TestTargetNew( 1370 level = TestLevel.COMPLETE, 1371 notes = "Verifies serialization.", 1372 method = "!Serialization", 1373 args = {} 1374 ) 1375 public void test_writeObject_Double() { 1376 // Test for method void 1377 // java.io.ObjectOutputStream.writeObject(java.lang.Double) 1378 1379 Object objToSave = null; 1380 Object objLoaded = null; 1381 1382 try { 1383 objToSave = new java.lang.Double(1.23); 1384 if (DEBUG) 1385 System.out.println("Obj = " + objToSave); 1386 objLoaded = dumpAndReload(objToSave); 1387 1388 // Has to have worked 1389 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1390 } catch (IOException e) { 1391 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1392 } catch (ClassNotFoundException e) { 1393 fail("ClassNotFoundException reading Object type: " 1394 + e.getMessage()); 1395 } catch (Error err) { 1396 System.out.println("Error when obj = " + objToSave); 1397 // err.printStackTrace(); 1398 throw err; 1399 } 1400 1401 } 1402 1403 @TestTargetNew( 1404 level = TestLevel.COMPLETE, 1405 notes = "Verifies serialization.", 1406 method = "!Serialization", 1407 args = {} 1408 ) 1409 public void test_writeObject_Number() { 1410 // Test for method void 1411 // java.io.ObjectOutputStream.writeObject(java.lang.Number) 1412 1413 Object objToSave = null; 1414 Object objLoaded = null; 1415 1416 try { 1417 objToSave = null; 1418 objToSave = new Number() { 1419 int numCalls = 0; 1420 1421 public double doubleValue() { 1422 return ++numCalls; 1423 } 1424 1425 public float floatValue() { 1426 return ++numCalls; 1427 } 1428 1429 public int intValue() { 1430 return numCalls; 1431 } 1432 1433 public long longValue() { 1434 return ++numCalls; 1435 } 1436 1437 public boolean equals(Object obj) { 1438 if (!(obj instanceof java.lang.Number)) 1439 return false; 1440 return intValue() == ((Number) obj).intValue(); 1441 } 1442 }; 1443 ((java.lang.Number) objToSave).doubleValue(); 1444 ((java.lang.Number) objToSave).floatValue(); 1445 if (DEBUG) 1446 System.out.println("Obj = " + objToSave); 1447 objLoaded = dumpAndReload(objToSave); 1448 1449 // Has to have worked 1450 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1451 } catch (IOException e) { 1452 fail("IOException serializing " + objToSave + " : " 1453 + e.getMessage()); 1454 } catch (ClassNotFoundException e) { 1455 fail("ClassNotFoundException reading Object type : " 1456 + e.getMessage()); 1457 } catch (Error err) { 1458 System.out.println("Error when obj = " + objToSave); 1459 // err.printStackTrace(); 1460 throw err; 1461 } 1462 1463 } 1464 1465 @TestTargetNew( 1466 level = TestLevel.COMPLETE, 1467 notes = "Verifies serialization.", 1468 method = "!Serialization", 1469 args = {} 1470 ) 1471 public void test_writeObject_AllPermission() { 1472 // Test for method void 1473 // java.io.ObjectOutputStream.writeObject(java.security.AllPermission) 1474 1475 Object objToSave = null; 1476 Object objLoaded = null; 1477 1478 try { 1479 objToSave = new java.security.AllPermission(); 1480 if (DEBUG) 1481 System.out.println("Obj = " + objToSave); 1482 objLoaded = dumpAndReload(objToSave); 1483 1484 // Has to have worked 1485 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1486 } catch (IOException e) { 1487 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1488 } catch (ClassNotFoundException e) { 1489 fail("ClassNotFoundException reading Object type: " 1490 + e.getMessage()); 1491 } catch (Error err) { 1492 System.out.println("Error when obj = " + objToSave); 1493 // err.printStackTrace(); 1494 throw err; 1495 } 1496 1497 } 1498 1499 @TestTargetNew( 1500 level = TestLevel.COMPLETE, 1501 notes = "Verifies serialization.", 1502 method = "!Serialization", 1503 args = {} 1504 ) 1505 public void test_writeObject_Collections_ReverseComparator() { 1506 // Test for method void 1507 // java.io.ObjectOutputStream.writeObject(java.util.Collections.ReverseComparator) 1508 1509 Object objToSave = null; 1510 Object objLoaded = null; 1511 1512 try { 1513 objToSave = java.util.Collections.reverseOrder(); 1514 if (DEBUG) 1515 System.out.println("Obj = " + objToSave); 1516 objLoaded = dumpAndReload(objToSave); 1517 1518 // Has to have worked 1519 boolean equals; 1520 equals = ((Comparator) objToSave).compare("Hello", "Jello") == ((Comparator) objLoaded) 1521 .compare("Hello", "Jello"); 1522 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1523 } catch (IOException e) { 1524 fail("IOException serializing " + objToSave + " : " 1525 + e.getMessage()); 1526 } catch (ClassNotFoundException e) { 1527 fail("ClassNotFoundException reading Object type : " 1528 + e.getMessage()); 1529 } catch (Error err) { 1530 System.out.println("Error when obj = " + objToSave); 1531 // err.printStackTrace(); 1532 throw err; 1533 } 1534 1535 } 1536 1537 @TestTargetNew( 1538 level = TestLevel.COMPLETE, 1539 notes = "Verifies serialization.", 1540 method = "!Serialization", 1541 args = {} 1542 ) 1543 public void test_writeObject_DateFormatSymbols() { 1544 // Test for method void 1545 // java.io.ObjectOutputStream.writeObject(java.text.DateFormatSymbols) 1546 1547 Object objToSave = null; 1548 Object objLoaded = null; 1549 1550 try { 1551 objToSave = new java.text.DateFormatSymbols(Locale.CHINESE); 1552 ((java.text.DateFormatSymbols) objToSave) 1553 .setZoneStrings(new String[][] { { "a", "b", "c", "d" }, 1554 { "e", "f", "g", "h" } }); 1555 if (DEBUG) 1556 System.out.println("Obj = " + objToSave); 1557 objLoaded = dumpAndReload(objToSave); 1558 1559 // Has to have worked 1560 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1561 } catch (IOException e) { 1562 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1563 } catch (ClassNotFoundException e) { 1564 fail("ClassNotFoundException reading Object type: " 1565 + e.getMessage()); 1566 } catch (Error err) { 1567 System.out.println("Error when obj = " + objToSave); 1568 // err.printStackTrace(); 1569 throw err; 1570 } 1571 1572 } 1573 1574 @TestTargetNew( 1575 level = TestLevel.COMPLETE, 1576 notes = "Verifies serialization.", 1577 method = "!Serialization", 1578 args = {} 1579 ) 1580 public void test_writeObject_Collections_EmptyList() { 1581 // Test for method void 1582 // java.io.ObjectOutputStream.writeObject(java.util.Collections.EmptyList) 1583 1584 Object objToSave = null; 1585 Object objLoaded = null; 1586 1587 try { 1588 objToSave = java.util.Collections.EMPTY_LIST; 1589 if (DEBUG) 1590 System.out.println("Obj = " + objToSave); 1591 objLoaded = dumpAndReload(objToSave); 1592 1593 // Has to have worked 1594 boolean equals; 1595 equals = objToSave.equals(objLoaded); 1596 if (equals) 1597 equals = ((List) objLoaded).size() == 0; 1598 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1599 } catch (IOException e) { 1600 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1601 } catch (ClassNotFoundException e) { 1602 fail("ClassNotFoundException reading Object type: " 1603 + e.getMessage()); 1604 } catch (Error err) { 1605 System.out.println("Error when obj = " + objToSave); 1606 // err.printStackTrace(); 1607 throw err; 1608 } 1609 1610 } 1611 1612 @TestTargetNew( 1613 level = TestLevel.COMPLETE, 1614 notes = "Verifies serialization.", 1615 method = "!Serialization", 1616 args = {} 1617 ) 1618 public void test_writeObject_Boolean() { 1619 // Test for method void 1620 // java.io.ObjectOutputStream.writeObject(java.lang.Boolean) 1621 1622 Object objToSave = null; 1623 Object objLoaded = null; 1624 1625 try { 1626 objToSave = new java.lang.Boolean(true); 1627 if (DEBUG) 1628 System.out.println("Obj = " + objToSave); 1629 objLoaded = dumpAndReload(objToSave); 1630 1631 // Has to have worked 1632 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1633 } catch (IOException e) { 1634 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1635 } catch (ClassNotFoundException e) { 1636 fail("ClassNotFoundException reading Object type: " 1637 + e.getMessage()); 1638 } catch (Error err) { 1639 System.out.println("Error when obj = " + objToSave); 1640 // err.printStackTrace(); 1641 throw err; 1642 } 1643 1644 } 1645 1646 @TestTargetNew( 1647 level = TestLevel.COMPLETE, 1648 notes = "Verifies serialization.", 1649 method = "!Serialization", 1650 args = {} 1651 ) 1652 public void test_writeObject_Collections_SingletonSet() { 1653 // Test for method void 1654 // java.io.ObjectOutputStream.writeObject(java.util.Collections.SingletonSet) 1655 1656 Object objToSave = null; 1657 Object objLoaded = null; 1658 1659 try { 1660 objToSave = java.util.Collections.singleton(new Byte((byte) 107)); 1661 if (DEBUG) 1662 System.out.println("Obj = " + objToSave); 1663 objLoaded = dumpAndReload(objToSave); 1664 1665 // Has to have worked 1666 boolean equals; 1667 java.util.Iterator iter = ((Set) objLoaded).iterator(); 1668 equals = iter.hasNext(); 1669 if (equals) 1670 equals = iter.next().equals(new Byte((byte) 107)); 1671 if (equals) 1672 equals = !iter.hasNext(); 1673 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1674 } catch (IOException e) { 1675 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1676 } catch (ClassNotFoundException e) { 1677 fail("ClassNotFoundException reading Object type: " 1678 + e.getMessage()); 1679 } catch (Error err) { 1680 System.out.println("Error when obj = " + objToSave); 1681 // err.printStackTrace(); 1682 throw err; 1683 } 1684 1685 } 1686 1687 @TestTargetNew( 1688 level = TestLevel.COMPLETE, 1689 notes = "Verifies serialization.", 1690 method = "!Serialization", 1691 args = {} 1692 ) 1693 public void test_writeObject_Collections_SingletonList() { 1694 // Test for method void 1695 // java.io.ObjectOutputStream.writeObject(java.util.Collections.SingletonSet) 1696 1697 Object objToSave = null; 1698 Object objLoaded = null; 1699 1700 try { 1701 objToSave = java.util.Collections 1702 .singletonList(new Byte((byte) 107)); 1703 if (DEBUG) 1704 System.out.println("Obj = " + objToSave); 1705 objLoaded = dumpAndReload(objToSave); 1706 1707 // Has to have worked 1708 boolean equals; 1709 java.util.Iterator iter = ((List) objLoaded).iterator(); 1710 equals = objLoaded.equals(objToSave) && iter.hasNext() 1711 && iter.next().equals(new Byte((byte) 107)) 1712 && !iter.hasNext(); 1713 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1714 } catch (IOException e) { 1715 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1716 } catch (ClassNotFoundException e) { 1717 fail("ClassNotFoundException reading Object type: " 1718 + e.getMessage()); 1719 } catch (Error err) { 1720 System.out.println("Error when obj = " + objToSave); 1721 // err.printStackTrace(); 1722 throw err; 1723 } 1724 1725 } 1726 1727 @TestTargetNew( 1728 level = TestLevel.COMPLETE, 1729 notes = "Verifies serialization.", 1730 method = "!Serialization", 1731 args = {} 1732 ) 1733 public void test_writeObject_Collections_SingletonMap() { 1734 // Test for method void 1735 // java.io.ObjectOutputStream.writeObject(java.util.Collections.SingletonSet) 1736 1737 Object objToSave = null; 1738 Object objLoaded = null; 1739 1740 try { 1741 objToSave = java.util.Collections.singletonMap("key", new Byte( 1742 (byte) 107)); 1743 if (DEBUG) 1744 System.out.println("Obj = " + objToSave); 1745 objLoaded = dumpAndReload(objToSave); 1746 1747 // Has to have worked 1748 boolean equals; 1749 java.util.Iterator iter = ((Map) objLoaded).entrySet().iterator(); 1750 equals = objLoaded.equals(objToSave) && iter.hasNext(); 1751 Map.Entry entry = (Map.Entry) iter.next(); 1752 equals = equals && entry.getKey().equals("key") 1753 && entry.getValue().equals(new Byte((byte) 107)) 1754 && !iter.hasNext(); 1755 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1756 } catch (IOException e) { 1757 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1758 } catch (ClassNotFoundException e) { 1759 fail("ClassNotFoundException reading Object type: " 1760 + e.getMessage()); 1761 } catch (Error err) { 1762 System.out.println("Error when obj = " + objToSave); 1763 // err.printStackTrace(); 1764 throw err; 1765 } 1766 1767 } 1768 1769 @TestTargetNew( 1770 level = TestLevel.COMPLETE, 1771 notes = "Verifies serialization.", 1772 method = "!Serialization", 1773 args = {} 1774 ) 1775 public void test_writeObject_FilePermission_FilePermissionCollection() { 1776 // Test for method void 1777 // java.io.ObjectOutputStream.writeObject(java.io.FilePermission.FilePermissionCollection) 1778 1779 Object objToSave = null; 1780 Object objLoaded = null; 1781 1782 try { 1783 objToSave = (new java.io.FilePermission("<<ALL FILES>>", "read")) 1784 .newPermissionCollection(); 1785 ((java.security.PermissionCollection) objToSave) 1786 .add(new FilePermission("<<ALL FILES>>", "read")); 1787 ((java.security.PermissionCollection) objToSave) 1788 .add(new FilePermission("d:\\", "read")); 1789 if (DEBUG) 1790 System.out.println("Obj = " + objToSave); 1791 objLoaded = dumpAndReload(objToSave); 1792 1793 // Has to have worked 1794 boolean equals; 1795 java.util.Enumeration enum1 = ((java.security.PermissionCollection) objToSave) 1796 .elements(), enum2 = ((java.security.PermissionCollection) objLoaded) 1797 .elements(); 1798 1799 equals = true; 1800 while (enum1.hasMoreElements() && equals) { 1801 if (enum2.hasMoreElements()) 1802 equals = enum1.nextElement().equals(enum2.nextElement()); 1803 else 1804 equals = false; 1805 } 1806 1807 if (equals) 1808 equals = !enum2.hasMoreElements(); 1809 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1810 } catch (IOException e) { 1811 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1812 } catch (ClassNotFoundException e) { 1813 fail("ClassNotFoundException reading Object type: " 1814 + e.getMessage()); 1815 } catch (Error err) { 1816 System.out.println("Error when obj = " + objToSave); 1817 // err.printStackTrace(); 1818 throw err; 1819 } 1820 1821 } 1822 1823 @TestTargetNew( 1824 level = TestLevel.COMPLETE, 1825 notes = "Verifies serialization.", 1826 method = "!Serialization", 1827 args = {} 1828 ) 1829 public void test_writeObject_SecureRandom() { 1830 // Test for method void 1831 // java.io.ObjectOutputStream.writeObject(java.security.SecureRandom) 1832 1833 Object objToSave = null; 1834 Object objLoaded = null; 1835 1836 try { 1837 objToSave = new java.security.SecureRandom(); 1838 if (DEBUG) 1839 System.out.println("Obj = " + objToSave); 1840 objLoaded = dumpAndReload(objToSave); 1841 1842 // Has to have worked 1843 boolean equals; 1844 equals = true; // assume fine because of the nature of the class, 1845 // it is difficult to determine if they are the same 1846 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1847 } catch (IOException e) { 1848 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1849 } catch (ClassNotFoundException e) { 1850 fail("ClassNotFoundException reading Object type: " 1851 + e.getMessage()); 1852 } catch (Error err) { 1853 System.out.println("Error when obj = " + objToSave); 1854 // err.printStackTrace(); 1855 throw err; 1856 } 1857 1858 } 1859 1860 @TestTargetNew( 1861 level = TestLevel.COMPLETE, 1862 notes = "Verifies serialization.", 1863 method = "!Serialization", 1864 args = {} 1865 ) 1866 public void test_writeObject_FilePermission() { 1867 // Test for method void 1868 // java.io.ObjectOutputStream.writeObject(java.io.FilePermission) 1869 1870 Object objToSave = null; 1871 Object objLoaded = null; 1872 1873 try { 1874 objToSave = new java.io.FilePermission("<<ALL FILES>>", "read"); 1875 if (DEBUG) 1876 System.out.println("Obj = " + objToSave); 1877 objLoaded = dumpAndReload(objToSave); 1878 1879 // Has to have worked 1880 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1881 } catch (IOException e) { 1882 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1883 } catch (ClassNotFoundException e) { 1884 fail("ClassNotFoundException reading Object type: " 1885 + e.getMessage()); 1886 } catch (Error err) { 1887 System.out.println("Error when obj = " + objToSave); 1888 // err.printStackTrace(); 1889 throw err; 1890 } 1891 1892 } 1893 1894 @TestTargetNew( 1895 level = TestLevel.COMPLETE, 1896 notes = "Verifies serialization.", 1897 method = "!Serialization", 1898 args = {} 1899 ) 1900 public void test_writeObject_InetAddress() { 1901 // Test for method void 1902 // java.io.ObjectOutputStream.writeObject(java.net.InetAddress) 1903 1904 Object objToSave = null; 1905 Object objLoaded = null; 1906 1907 try { 1908 objToSave = java.net.InetAddress 1909 .getByName(Support_Configuration.InetTestIP); 1910 if (DEBUG) 1911 System.out.println("Obj = " + objToSave); 1912 objLoaded = dumpAndReload(objToSave); 1913 1914 // Has to have worked 1915 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1916 } catch (IOException e) { 1917 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1918 } catch (ClassNotFoundException e) { 1919 fail("ClassNotFoundException reading Object type: " 1920 + e.getMessage()); 1921 } catch (Error err) { 1922 System.out.println("Error when obj = " + objToSave); 1923 // err.printStackTrace(); 1924 throw err; 1925 } 1926 1927 } 1928 1929 @TestTargetNew( 1930 level = TestLevel.COMPLETE, 1931 notes = "Verifies serialization.", 1932 method = "!Serialization", 1933 args = {} 1934 ) 1935 public void test_writeObject_Inet6Address() { 1936 // Test for method void 1937 // java.io.ObjectOutputStream.writeObject(java.net.Inet6Address) 1938 1939 Object objToSave = null; 1940 Object objLoaded = null; 1941 1942 try { 1943 objToSave = java.net.Inet6Address 1944 .getByName(Support_Configuration.InetTestIP6); 1945 if (DEBUG) 1946 System.out.println("Obj = " + objToSave); 1947 objLoaded = dumpAndReload(objToSave); 1948 1949 // Has to have worked 1950 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1951 1952 } catch (IOException e) { 1953 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1954 } catch (ClassNotFoundException e) { 1955 fail("ClassNotFoundException reading Object type: " 1956 + e.getMessage()); 1957 } catch (Error err) { 1958 System.out.println("Error when obj = " + objToSave); 1959 // err.printStackTrace(); 1960 throw err; 1961 } 1962 1963 } 1964 1965 @TestTargetNew( 1966 level = TestLevel.COMPLETE, 1967 notes = "Verifies serialization.", 1968 method = "!Serialization", 1969 args = {} 1970 ) 1971 public void test_writeObject_RuntimePermission() { 1972 // Test for method void 1973 // java.io.ObjectOutputStream.writeObject(java.lang.RuntimePermission) 1974 1975 Object objToSave = null; 1976 Object objLoaded = null; 1977 1978 try { 1979 objToSave = new java.lang.RuntimePermission("TestSerialization", 1980 "Test"); 1981 if (DEBUG) 1982 System.out.println("Obj = " + objToSave); 1983 objLoaded = dumpAndReload(objToSave); 1984 1985 // Has to have worked 1986 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1987 } catch (IOException e) { 1988 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1989 } catch (ClassNotFoundException e) { 1990 fail("ClassNotFoundException reading Object type: " 1991 + e.getMessage()); 1992 } catch (Error err) { 1993 System.out.println("Error when obj = " + objToSave); 1994 // err.printStackTrace(); 1995 throw err; 1996 } 1997 1998 } 1999 2000 @TestTargetNew( 2001 level = TestLevel.COMPLETE, 2002 notes = "Verifies serialization.", 2003 method = "!Serialization", 2004 args = {} 2005 ) 2006 public void test_writeObject_Permissions() { 2007 // Test for method void 2008 // java.io.ObjectOutputStream.writeObject(java.security.Permissions) 2009 2010 Object objToSave = null; 2011 Object objLoaded = null; 2012 2013 try { 2014 objToSave = new java.security.Permissions(); 2015 ((java.security.Permissions) objToSave).add(new AllPermission()); 2016 if (DEBUG) 2017 System.out.println("Obj = " + objToSave); 2018 objLoaded = dumpAndReload(objToSave); 2019 2020 // Has to have worked 2021 boolean equals; 2022 Enumeration enum1 = ((java.security.PermissionCollection) objToSave) 2023 .elements(), enum2 = ((java.security.PermissionCollection) objLoaded) 2024 .elements(); 2025 java.util.Vector vec1 = new java.util.Vector(), vec2 = new java.util.Vector(); 2026 2027 while (enum1.hasMoreElements()) 2028 vec1.add(enum1.nextElement()); 2029 while (enum2.hasMoreElements()) 2030 vec2.add(enum2.nextElement()); 2031 2032 equals = vec1.size() == vec2.size(); 2033 if (equals) { 2034 int length = vec1.size(); 2035 Object[] perms1 = new Object[length], perms2 = new Object[length]; 2036 for (int i = 0; i < length; ++i) { 2037 perms1[i] = vec1.elementAt(i); 2038 perms2[i] = vec2.elementAt(i); 2039 } 2040 2041 Comparator comparator = new Comparator() { 2042 public int compare(Object o1, Object o2) { 2043 return o1.toString().compareTo(o2.toString()); 2044 } 2045 2046 public boolean equals(Object o1, Object o2) { 2047 return o1.toString().equals(o2.toString()); 2048 } 2049 }; 2050 2051 java.util.Arrays.sort(perms1, comparator); 2052 java.util.Arrays.sort(perms2, comparator); 2053 2054 for (int i = 0; i < length && equals; ++i) 2055 equals = perms1[i].equals(perms2[i]); 2056 } 2057 2058 assertTrue(MSG_TEST_FAILED + objToSave, equals); 2059 } catch (IOException e) { 2060 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2061 } catch (ClassNotFoundException e) { 2062 fail("ClassNotFoundException reading Object type: " 2063 + e.getMessage()); 2064 } catch (Error err) { 2065 System.out.println("Error when obj = " + objToSave); 2066 // err.printStackTrace(); 2067 throw err; 2068 } 2069 2070 } 2071 2072 @TestTargetNew( 2073 level = TestLevel.COMPLETE, 2074 notes = "Verifies serialization.", 2075 method = "!Serialization", 2076 args = {} 2077 ) 2078 public void test_writeObject_Date() { 2079 // Test for method void 2080 // java.io.ObjectOutputStream.writeObject(java.util.Date) 2081 2082 Object objToSave = null; 2083 Object objLoaded = null; 2084 2085 try { 2086 // Thu Feb 01 01:01:01 EST 2001 2087 objToSave = new java.util.Date(981007261000L); 2088 if (DEBUG) 2089 System.out.println("Obj = " + objToSave); 2090 objLoaded = dumpAndReload(objToSave); 2091 2092 // Has to have worked 2093 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2094 } catch (IOException e) { 2095 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2096 } catch (ClassNotFoundException e) { 2097 fail("ClassNotFoundException reading Object type: " 2098 + e.getMessage()); 2099 } catch (Error err) { 2100 System.out.println("Error when obj = " + objToSave); 2101 // err.printStackTrace(); 2102 throw err; 2103 } 2104 2105 } 2106 2107 @TestTargetNew( 2108 level = TestLevel.COMPLETE, 2109 notes = "Verifies serialization.", 2110 method = "!Serialization", 2111 args = {} 2112 ) 2113 public void test_writeObject_Float() { 2114 // Test for method void 2115 // java.io.ObjectOutputStream.writeObject(java.lang.Float) 2116 2117 Object objToSave = null; 2118 Object objLoaded = null; 2119 2120 try { 2121 objToSave = new java.lang.Float(1.23f); 2122 if (DEBUG) 2123 System.out.println("Obj = " + objToSave); 2124 objLoaded = dumpAndReload(objToSave); 2125 2126 // Has to have worked 2127 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2128 } catch (IOException e) { 2129 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2130 } catch (ClassNotFoundException e) { 2131 fail("ClassNotFoundException reading Object type: " 2132 + e.getMessage()); 2133 } catch (Error err) { 2134 System.out.println("Error when obj = " + objToSave); 2135 // err.printStackTrace(); 2136 throw err; 2137 } 2138 2139 } 2140 2141 @TestTargetNew( 2142 level = TestLevel.COMPLETE, 2143 notes = "Verifies serialization.", 2144 method = "!Serialization", 2145 args = {} 2146 ) 2147 public void test_writeObject_SecurityPermission() { 2148 // Test for method void 2149 // java.io.ObjectOutputStream.writeObject(java.security.SecurityPermission) 2150 2151 Object objToSave = null; 2152 Object objLoaded = null; 2153 2154 try { 2155 objToSave = new java.security.SecurityPermission( 2156 "TestSerialization", "Test"); 2157 if (DEBUG) 2158 System.out.println("Obj = " + objToSave); 2159 objLoaded = dumpAndReload(objToSave); 2160 2161 // Has to have worked 2162 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2163 } catch (IOException e) { 2164 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2165 } catch (ClassNotFoundException e) { 2166 fail("ClassNotFoundException reading Object type: " 2167 + e.getMessage()); 2168 } catch (Error err) { 2169 System.out.println("Error when obj = " + objToSave); 2170 // err.printStackTrace(); 2171 throw err; 2172 } 2173 2174 } 2175 2176 @TestTargetNew( 2177 level = TestLevel.COMPLETE, 2178 notes = "Verifies serialization.", 2179 method = "!Serialization", 2180 args = {} 2181 ) 2182 public void test_writeObject_SocketPermission_SocketPermissionCollection() { 2183 // Test for method void 2184 // java.io.ObjectOutputStream.writeObject(java.net.SocketPermission.SocketPermissionCollection) 2185 2186 Object objToSave = null; 2187 Object objLoaded = null; 2188 2189 try { 2190 objToSave = (new java.net.SocketPermission("www.yahoo.com", 2191 "connect")).newPermissionCollection(); 2192 ((java.security.PermissionCollection) objToSave) 2193 .add(new java.net.SocketPermission("www.yahoo.com", 2194 "connect")); 2195 if (DEBUG) 2196 System.out.println("Obj = " + objToSave); 2197 objLoaded = dumpAndReload(objToSave); 2198 2199 // Has to have worked 2200 boolean equals; 2201 Enumeration enum1 = ((java.security.PermissionCollection) objToSave) 2202 .elements(), enum2 = ((java.security.PermissionCollection) objLoaded) 2203 .elements(); 2204 2205 equals = true; 2206 while (enum1.hasMoreElements() && equals) { 2207 if (enum2.hasMoreElements()) 2208 equals = enum1.nextElement().equals(enum2.nextElement()); 2209 else 2210 equals = false; 2211 } 2212 2213 if (equals) 2214 equals = !enum2.hasMoreElements(); 2215 assertTrue(MSG_TEST_FAILED + objToSave, equals); 2216 } catch (IOException e) { 2217 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2218 } catch (ClassNotFoundException e) { 2219 fail("ClassNotFoundException reading Object type: " 2220 + e.getMessage()); 2221 } catch (Error err) { 2222 System.out.println("Error when obj = " + objToSave); 2223 // err.printStackTrace(); 2224 throw err; 2225 } 2226 2227 } 2228 2229 @TestTargetNew( 2230 level = TestLevel.COMPLETE, 2231 notes = "Verifies serialization.", 2232 method = "!Serialization", 2233 args = {} 2234 ) 2235 public void test_writeObject_Stack() { 2236 // Test for method void 2237 // java.io.ObjectOutputStream.writeObject(java.util.Stack) 2238 2239 Object objToSave = null; 2240 Object objLoaded = null; 2241 2242 try { 2243 objToSave = new java.util.Stack(); 2244 ((java.util.Stack) objToSave).push("String 1"); 2245 ((java.util.Stack) objToSave).push("String 2"); 2246 if (DEBUG) 2247 System.out.println("Obj = " + objToSave); 2248 objLoaded = dumpAndReload(objToSave); 2249 2250 // Has to have worked 2251 boolean equals; 2252 equals = true; 2253 while (!((java.util.Stack) objToSave).empty() && equals) { 2254 if (!((java.util.Stack) objLoaded).empty()) 2255 equals = ((java.util.Stack) objToSave).pop().equals( 2256 ((java.util.Stack) objLoaded).pop()); 2257 else 2258 equals = false; 2259 } 2260 2261 if (equals) 2262 equals = ((java.util.Stack) objLoaded).empty(); 2263 assertTrue(MSG_TEST_FAILED + objToSave, equals); 2264 } catch (IOException e) { 2265 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2266 } catch (ClassNotFoundException e) { 2267 fail("ClassNotFoundException reading Object type: " 2268 + e.getMessage()); 2269 } catch (Error err) { 2270 System.out.println("Error when obj = " + objToSave); 2271 // err.printStackTrace(); 2272 throw err; 2273 } 2274 2275 } 2276 2277 @TestTargetNew( 2278 level = TestLevel.COMPLETE, 2279 notes = "Verifies serialization.", 2280 method = "!Serialization", 2281 args = {} 2282 ) 2283 public void test_writeObject_DecimalFormatSymbols() { 2284 // Test for method void 2285 // java.io.ObjectOutputStream.writeObject(java.text.DecimalFormatSymbols) 2286 2287 Object objToSave = null; 2288 Object objLoaded = null; 2289 2290 try { 2291 objToSave = new java.text.DecimalFormatSymbols(Locale.CHINESE); 2292 if (DEBUG) 2293 System.out.println("Obj = " + objToSave); 2294 objLoaded = dumpAndReload(objToSave); 2295 2296 // Has to have worked 2297 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2298 } catch (IOException e) { 2299 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2300 } catch (ClassNotFoundException e) { 2301 fail("ClassNotFoundException reading Object type: " 2302 + e.getMessage()); 2303 } catch (Error err) { 2304 System.out.println("Error when obj = " + objToSave); 2305 // err.printStackTrace(); 2306 throw err; 2307 } 2308 2309 } 2310 2311 @TestTargetNew( 2312 level = TestLevel.COMPLETE, 2313 notes = "Verifies serialization.", 2314 method = "!Serialization", 2315 args = {} 2316 ) 2317 public void test_writeObject_NetPermission() { 2318 // Test for method void 2319 // java.io.ObjectOutputStream.writeObject(java.net.NetPermission) 2320 2321 Object objToSave = null; 2322 Object objLoaded = null; 2323 2324 try { 2325 objToSave = new java.net.NetPermission("TestSerialization", "Test"); 2326 if (DEBUG) 2327 System.out.println("Obj = " + objToSave); 2328 objLoaded = dumpAndReload(objToSave); 2329 2330 // Has to have worked 2331 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2332 } catch (IOException e) { 2333 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2334 } catch (ClassNotFoundException e) { 2335 fail("ClassNotFoundException reading Object type: " 2336 + e.getMessage()); 2337 } catch (Error err) { 2338 System.out.println("Error when obj = " + objToSave); 2339 // err.printStackTrace(); 2340 throw err; 2341 } 2342 } 2343 2344 @TestTargetNew( 2345 level = TestLevel.COMPLETE, 2346 notes = "Verifies serialization.", 2347 method = "!Serialization", 2348 args = {} 2349 ) 2350 public void test_writeObject_AttributedCharacterIterator_Attribute() { 2351 // Test for method void 2352 // java.io.ObjectOutputStream.writeObject(java.text.AttributedCharacterIterator.Attribute) 2353 2354 Object objToSave = null; 2355 Object objLoaded = null; 2356 2357 try { 2358 objToSave = java.text.AttributedCharacterIterator.Attribute.LANGUAGE; 2359 if (DEBUG) 2360 System.out.println("Obj = " + objToSave); 2361 objLoaded = dumpAndReload(objToSave); 2362 2363 // Has to have worked 2364 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2365 } catch (IOException e) { 2366 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2367 } catch (ClassNotFoundException e) { 2368 fail("ClassNotFoundException reading Object type: " 2369 + e.getMessage()); 2370 } catch (Error err) { 2371 System.out.println("Error when obj = " + objToSave); 2372 // err.printStackTrace(); 2373 throw err; 2374 } 2375 } 2376 2377 @TestTargetNew( 2378 level = TestLevel.COMPLETE, 2379 notes = "Verifies serialization.", 2380 method = "!Serialization", 2381 args = {} 2382 ) 2383 public void test_writeObject_Long() { 2384 // Test for method void 2385 // java.io.ObjectOutputStream.writeObject(java.lang.Long) 2386 2387 Object objToSave = null; 2388 Object objLoaded = null; 2389 2390 try { 2391 objToSave = new java.lang.Long(107L); 2392 if (DEBUG) 2393 System.out.println("Obj = " + objToSave); 2394 objLoaded = dumpAndReload(objToSave); 2395 2396 // Has to have worked 2397 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2398 } catch (IOException e) { 2399 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2400 } catch (ClassNotFoundException e) { 2401 fail("ClassNotFoundException reading Object type: " 2402 + e.getMessage()); 2403 } catch (Error err) { 2404 System.out.println("Error when obj = " + objToSave); 2405 // err.printStackTrace(); 2406 throw err; 2407 } 2408 2409 } 2410 2411 @TestTargetNew( 2412 level = TestLevel.COMPLETE, 2413 notes = "Verifies serialization.", 2414 method = "!Serialization", 2415 args = {} 2416 ) 2417 public void test_writeObject_CodeSource() { 2418 // Test for method void 2419 // java.io.ObjectOutputStream.writeObject(java.security.CodeSource) 2420 2421 Object objToSave = null; 2422 Object objLoaded = null; 2423 2424 try { 2425 objToSave = null; 2426 try { 2427 objToSave = new java.security.CodeSource(new java.net.URL( 2428 "http://localhost/a.txt"), 2429 (Certificate[])null); 2430 } catch (Exception e) { 2431 fail("Exception creating object : " + e.getMessage()); 2432 } 2433 if (DEBUG) 2434 System.out.println("Obj = " + objToSave); 2435 objLoaded = dumpAndReload(objToSave); 2436 2437 // Has to have worked 2438 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2439 } catch (IOException e) { 2440 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2441 } catch (ClassNotFoundException e) { 2442 fail("ClassNotFoundException reading Object type: " 2443 + e.getMessage()); 2444 } catch (Error err) { 2445 System.out.println("Error when obj = " + objToSave); 2446 // err.printStackTrace(); 2447 throw err; 2448 } 2449 2450 } 2451 2452 @TestTargetNew( 2453 level = TestLevel.COMPLETE, 2454 notes = "Verifies serialization.", 2455 method = "!Serialization", 2456 args = {} 2457 ) 2458 public void test_writeObject_Collections_SynchronizedCollection() { 2459 // Test for method void 2460 // java.io.ObjectOutputStream.writeObject(java.util.Collections.SynchronizedCollection) 2461 2462 Object objToSave = null; 2463 Object objLoaded = null; 2464 2465 try { 2466 objToSave = java.util.Collections.synchronizedCollection(SET); 2467 if (DEBUG) 2468 System.out.println("Obj = " + objToSave); 2469 objLoaded = dumpAndReload(objToSave); 2470 2471 // Has to have worked 2472 boolean equals; 2473 equals = ((java.util.Collection) objToSave).size() == ((java.util.Collection) objLoaded) 2474 .size(); 2475 if (equals) { 2476 java.util.Iterator iter1 = ((java.util.Collection) objToSave) 2477 .iterator(), iter2 = ((java.util.Collection) objLoaded) 2478 .iterator(); 2479 while (iter1.hasNext()) 2480 equals = equals && iter1.next().equals(iter2.next()); 2481 } 2482 assertTrue(MSG_TEST_FAILED + objToSave, equals); 2483 } catch (IOException e) { 2484 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2485 } catch (ClassNotFoundException e) { 2486 fail("ClassNotFoundException reading Object type: " 2487 + e.getMessage()); 2488 } catch (Error err) { 2489 System.out.println("Error when obj = " + objToSave); 2490 // err.printStackTrace(); 2491 throw err; 2492 } 2493 2494 } 2495 2496 @TestTargetNew( 2497 level = TestLevel.COMPLETE, 2498 notes = "Verifies serialization.", 2499 method = "!Serialization", 2500 args = {} 2501 ) 2502 public void test_writeObject_Permission() { 2503 // Test for method void 2504 // java.io.ObjectOutputStream.writeObject(java.security.Permission) 2505 2506 Object objToSave = null; 2507 Object objLoaded = null; 2508 2509 try { 2510 objToSave = null; 2511 objToSave = new java.security.Permission("test") { 2512 public boolean equals(Object p1) { 2513 if (!(p1 instanceof java.security.Permission)) 2514 return false; 2515 return getName().equals( 2516 ((java.security.Permission) p1).getName()); 2517 } 2518 2519 public int hashCode() { 2520 return 0; 2521 } 2522 2523 public String getActions() { 2524 return null; 2525 } 2526 2527 public boolean implies(java.security.Permission p1) { 2528 return false; 2529 } 2530 }; 2531 if (DEBUG) 2532 System.out.println("Obj = " + objToSave); 2533 objLoaded = dumpAndReload(objToSave); 2534 2535 // Has to have worked 2536 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2537 } catch (IOException e) { 2538 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2539 } catch (ClassNotFoundException e) { 2540 fail("ClassNotFoundException reading Object type: " 2541 + e.getMessage()); 2542 } catch (Error err) { 2543 System.out.println("Error when obj = " + objToSave); 2544 // err.printStackTrace(); 2545 throw err; 2546 } 2547 2548 } 2549 2550 @TestTargetNew( 2551 level = TestLevel.COMPLETE, 2552 notes = "Verifies serialization.", 2553 method = "!Serialization", 2554 args = {} 2555 ) 2556 public void test_writeObject_Random() { 2557 // Test for method void 2558 // java.io.ObjectOutputStream.writeObject(java.util.Random) 2559 2560 Object objToSave = null; 2561 Object objLoaded = null; 2562 2563 try { 2564 objToSave = new java.util.Random(107L); 2565 if (DEBUG) 2566 System.out.println("Obj = " + objToSave); 2567 objLoaded = dumpAndReload(objToSave); 2568 2569 // Has to have worked 2570 boolean equals; 2571 equals = ((java.util.Random) objToSave).nextInt() == ((java.util.Random) objLoaded) 2572 .nextInt(); 2573 assertTrue(MSG_TEST_FAILED + objToSave, equals); 2574 } catch (IOException e) { 2575 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2576 } catch (ClassNotFoundException e) { 2577 fail("ClassNotFoundException reading Object type: " 2578 + e.getMessage()); 2579 } catch (Error err) { 2580 System.out.println("Error when obj = " + objToSave); 2581 // err.printStackTrace(); 2582 throw err; 2583 } 2584 2585 } 2586 2587 @TestTargetNew( 2588 level = TestLevel.COMPLETE, 2589 notes = "Verifies serialization.", 2590 method = "!Serialization", 2591 args = {} 2592 ) 2593 public void test_writeObject_GuardedObject() { 2594 // Test for method void 2595 // java.io.ObjectOutputStream.writeObject(java.security.GuardedObject) 2596 2597 Object objToSave = null; 2598 Object objLoaded = null; 2599 2600 try { 2601 objToSave = new java.security.GuardedObject("Test Object", 2602 new GuardImplementation()); 2603 if (DEBUG) 2604 System.out.println("Obj = " + objToSave); 2605 objLoaded = dumpAndReload(objToSave); 2606 2607 // Has to have worked 2608 boolean equals; 2609 equals = ((java.security.GuardedObject) objToSave).getObject() 2610 .equals( 2611 ((java.security.GuardedObject) objLoaded) 2612 .getObject()); 2613 assertTrue(MSG_TEST_FAILED + objToSave, equals); 2614 } catch (IOException e) { 2615 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2616 } catch (ClassNotFoundException e) { 2617 fail("ClassNotFoundException reading Object type: " 2618 + e.getMessage()); 2619 } catch (Error err) { 2620 System.out.println("Error when obj = " + objToSave); 2621 // err.printStackTrace(); 2622 throw err; 2623 } 2624 2625 } 2626 2627 // TODO : Reintroduce when we have a working security implementation 2628 // public void test_writeObject_KeyPair() { 2629 // // Test for method void 2630 // // java.io.ObjectOutputStream.writeObject(java.security.GuardedObject) 2631 // 2632 // Object objToSave = null; 2633 // Object objLoaded = null; 2634 // 2635 // try { 2636 // objToSave = new java.security.KeyPair(null, null); 2637 // if (DEBUG) 2638 // System.out.println("Obj = " + objToSave); 2639 // objLoaded = dumpAndReload(objToSave); 2640 // 2641 // // Has to have worked 2642 // boolean equals; 2643 // equals = true; 2644 // assertTrue(MSG_TEST_FAILED + objToSave, equals); 2645 // } catch (IOException e) { 2646 // fail("IOException serializing " + objToSave + " : " 2647 // + e.getMessage()); 2648 // } catch (ClassNotFoundException e) { 2649 // fail("ClassNotFoundException reading Object type : " + e.getMessage()); 2650 // } catch (Error err) { 2651 // System.out.println("Error when obj = " + objToSave); 2652 // // err.printStackTrace(); 2653 // throw err; 2654 // } 2655 // } 2656 2657 static class MyInvocationHandler implements InvocationHandler, Serializable { 2658 public Object invoke(Object proxy, Method method, Object[] args) 2659 throws Throwable { 2660 if (method.getName().equals("equals")) 2661 return new Boolean(proxy == args[0]); 2662 if (method.getName().equals("array")) 2663 return new int[] { (int) ((long[]) args[0])[1], -1 }; 2664 if (method.getName().equals("string")) { 2665 if ("error".equals(args[0])) 2666 throw new ArrayStoreException(); 2667 if ("any".equals(args[0])) 2668 throw new IllegalAccessException(); 2669 } 2670 return null; 2671 } 2672 } 2673 2674 @TestTargetNew( 2675 level = TestLevel.COMPLETE, 2676 notes = "Verifies serialization.", 2677 method = "!Serialization", 2678 args = {} 2679 ) 2680 public void _test_writeObject_Proxy() { 2681 // Test for method void 2682 // java.io.ObjectOutputStream.writeObject(java.security.GuardedObject) 2683 2684 Object objToSave = null; 2685 Object objLoaded = null; 2686 2687 try { 2688 objToSave = Proxy.getProxyClass(Support_Proxy_I1.class 2689 .getClassLoader(), new Class[] { Support_Proxy_I1.class }); 2690 if (DEBUG) 2691 System.out.println("Obj = " + objToSave); 2692 objLoaded = dumpAndReload(objToSave); 2693 2694 assertTrue(MSG_TEST_FAILED + "not a proxy class", Proxy 2695 .isProxyClass((Class) objLoaded)); 2696 Class[] interfaces = ((Class) objLoaded).getInterfaces(); 2697 assertTrue(MSG_TEST_FAILED + "wrong interfaces length", 2698 interfaces.length == 1); 2699 assertTrue(MSG_TEST_FAILED + "wrong interface", 2700 interfaces[0] == Support_Proxy_I1.class); 2701 2702 InvocationHandler handler = new MyInvocationHandler(); 2703 objToSave = Proxy.newProxyInstance(Support_Proxy_I1.class 2704 .getClassLoader(), new Class[] { Support_Proxy_I1.class }, 2705 handler); 2706 if (DEBUG) 2707 System.out.println("Obj = " + objToSave); 2708 objLoaded = dumpAndReload(objToSave); 2709 2710 boolean equals = Proxy.getInvocationHandler(objLoaded).getClass() == MyInvocationHandler.class; 2711 assertTrue(MSG_TEST_FAILED + objToSave, equals); 2712 2713 } catch (IOException e) { 2714 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2715 } catch (ClassNotFoundException e) { 2716 fail("ClassNotFoundException reading Object type: " 2717 + e.getMessage()); 2718 } catch (Error err) { 2719 System.out.println("Error when obj = " + objToSave); 2720 // err.printStackTrace(); 2721 throw err; 2722 } 2723 } 2724 2725 @TestTargetNew( 2726 level = TestLevel.COMPLETE, 2727 notes = "Verifies serialization.", 2728 method = "!Serialization", 2729 args = {} 2730 ) 2731 public void test_writeObject_URI() { 2732 // Test for method void 2733 // java.io.ObjectOutputStream.writeObject(java.net.URI) 2734 2735 Object objToSave = null; 2736 Object objLoaded = null; 2737 2738 try { 2739 try { 2740 objToSave = new URI[] { 2741 // single arg constructor 2742 new URI( 2743 "http://user%60%20info@host/a%20path?qu%60%20ery#fr%5E%20ag"), 2744 // escaped octets for illegal chars 2745 new URI( 2746 "http://user%C3%9F%C2%A3info@host:80/a%E2%82%ACpath?qu%C2%A9%C2%AEery#fr%C3%A4%C3%A8g"), 2747 // escaped octets for unicode chars 2748 new URI( 2749 "ascheme://user\u00DF\u00A3info@host:0/a\u20ACpath?qu\u00A9\u00AEery#fr\u00E4\u00E8g"), 2750 // multiple arg constructors 2751 new URI("http", "user%60%20info", "host", 80, 2752 "/a%20path", "qu%60%20ery", "fr%5E%20ag"), 2753 // escaped octets for illegal 2754 new URI("http", "user%C3%9F%C2%A3info", "host", -1, 2755 "/a%E2%82%ACpath", "qu%C2%A9%C2%AEery", 2756 "fr%C3%A4%C3%A8g"), 2757 // escaped octets for unicode 2758 new URI("ascheme", "user\u00DF\u00A3info", "host", 80, 2759 "/a\u20ACpath", "qu\u00A9\u00AEery", 2760 "fr\u00E4\u00E8g"), 2761 new URI("http", "user` info", "host", 81, "/a path", 2762 "qu` ery", "fr^ ag"), // illegal chars 2763 new URI("http", "user%info", "host", 0, "/a%path", 2764 "que%ry", "f%rag"), 2765 // % as illegal char, not escaped octet urls with 2766 // undefined components 2767 new URI("mailto", "user@domain.com", null), 2768 // no host, path, query or fragment 2769 new URI("../adirectory/file.html#"), 2770 // relative path with empty fragment; 2771 new URI("news", "comp.infosystems.www.servers.unix", 2772 null), 2773 new URI(null, null, null, "fragment"), 2774 // only fragment 2775 new URI("telnet://server.org"), // only host 2776 new URI("http://reg:istry?query"), 2777 // malformed hostname, therefore registry-based, 2778 // with query 2779 new URI("file:///c:/temp/calculate.pl?") 2780 // empty authority, non empty path, empty query 2781 }; 2782 } catch (URISyntaxException e) { 2783 fail("Unexpected Exception:" + e); 2784 } 2785 if (DEBUG) 2786 System.out.println("Obj = " + objToSave); 2787 objLoaded = dumpAndReload(objToSave); 2788 2789 // Has to have worked 2790 assertTrue(MSG_TEST_FAILED + objToSave, Arrays.equals( 2791 (URI[]) objToSave, (URI[]) objLoaded)); 2792 } catch (IOException e) { 2793 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2794 } catch (ClassNotFoundException e) { 2795 fail("ClassNotFoundException reading Object type: " 2796 + e.getMessage()); 2797 } catch (Error err) { 2798 System.out.println("Error when obj = " + objToSave); 2799 // err.printStackTrace(); 2800 throw err; 2801 } 2802 } 2803 2804 @TestTargetNew( 2805 level = TestLevel.COMPLETE, 2806 notes = "Verifies serialization.", 2807 method = "!Serialization", 2808 args = {} 2809 ) 2810 public void test_writeObject_URISyntaxException() { 2811 // Test for method void 2812 // java.io.ObjectOutputStream.writeObject(java.net.URISyntaxException) 2813 2814 URISyntaxException objToSave = null; 2815 URISyntaxException objLoaded = null; 2816 2817 try { 2818 objToSave = new URISyntaxException("str", "problem", 4); 2819 if (DEBUG) 2820 System.out.println("Obj = " + objToSave); 2821 objLoaded = (URISyntaxException) dumpAndReload(objToSave); 2822 2823 boolean equals = objToSave.getMessage().equals( 2824 objLoaded.getMessage()) 2825 && objToSave.getInput().equals(objLoaded.getInput()) 2826 && objToSave.getIndex() == objLoaded.getIndex() 2827 && objToSave.getReason().equals(objLoaded.getReason()); 2828 2829 // Has to have worked 2830 assertTrue(MSG_TEST_FAILED + objToSave, equals); 2831 } catch (IOException e) { 2832 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2833 } catch (ClassNotFoundException e) { 2834 fail("ClassNotFoundException reading Object type: " 2835 + e.getMessage()); 2836 } catch (Error err) { 2837 System.out.println("Error when obj = " + objToSave); 2838 // err.printStackTrace(); 2839 throw err; 2840 } 2841 2842 } 2843 2844 @TestTargetNew( 2845 level = TestLevel.COMPLETE, 2846 notes = "Verifies serialization.", 2847 method = "!Serialization", 2848 args = {} 2849 ) 2850 public void test_writeObject_Currency() { 2851 // Test for method void 2852 // java.io.ObjectOutputStream.writeObject(java.util.Currency) 2853 2854 Object objToSave = null; 2855 Object objLoaded = null; 2856 2857 try { 2858 objToSave = java.util.Currency.getInstance("AMD"); 2859 if (DEBUG) 2860 System.out.println("Obj = " + objToSave); 2861 objLoaded = dumpAndReload(objToSave); 2862 2863 // Has to have worked 2864 // we need same instance for the same currency code 2865 assertTrue(MSG_TEST_FAILED + objToSave, objToSave == objToSave); 2866 } catch (IOException e) { 2867 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2868 } catch (ClassNotFoundException e) { 2869 fail("ClassNotFoundException reading Object type: " 2870 + e.getMessage()); 2871 } catch (Error err) { 2872 System.out.println("Error when obj = " + objToSave); 2873 // err.printStackTrace(); 2874 throw err; 2875 } 2876 } 2877 2878 @TestTargetNew( 2879 level = TestLevel.COMPLETE, 2880 notes = "Verifies serialization.", 2881 method = "!Serialization", 2882 args = {} 2883 ) 2884 public void test_writeObject_DateFormat_Field() { 2885 // Test for method void 2886 // java.io.ObjectOutputStream.writeObject(java.text.DateFormat.Field) 2887 2888 DateFormat.Field[] objToSave = null; 2889 DateFormat.Field[] objLoaded = null; 2890 2891 try { 2892 objToSave = new DateFormat.Field[] { DateFormat.Field.AM_PM, 2893 DateFormat.Field.DAY_OF_MONTH, DateFormat.Field.ERA, 2894 DateFormat.Field.HOUR0, DateFormat.Field.HOUR1, 2895 DateFormat.Field.HOUR_OF_DAY0, 2896 DateFormat.Field.HOUR_OF_DAY1, DateFormat.Field.TIME_ZONE, 2897 DateFormat.Field.YEAR, 2898 DateFormat.Field.DAY_OF_WEEK_IN_MONTH }; 2899 if (DEBUG) 2900 System.out.println("Obj = " + objToSave); 2901 2902 objLoaded = (DateFormat.Field[]) dumpAndReload(objToSave); 2903 2904 // Has to have worked 2905 // we need same instances for the same field names 2906 for (int i = 0; i < objToSave.length; i++) { 2907 assertTrue(MSG_TEST_FAILED + objToSave[i], 2908 objToSave[i] == objLoaded[i]); 2909 } 2910 } catch (IOException e) { 2911 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2912 } catch (ClassNotFoundException e) { 2913 fail("ClassNotFoundException reading Object type: " 2914 + e.getMessage()); 2915 } catch (Error err) { 2916 System.out.println("Error when obj = " + objToSave); 2917 // err.printStackTrace(); 2918 throw err; 2919 } 2920 } 2921 2922 @TestTargetNew( 2923 level = TestLevel.COMPLETE, 2924 notes = "Verifies serialization.", 2925 method = "!Serialization", 2926 args = {} 2927 ) 2928 public void test_writeObject_NumberFormat_Field() { 2929 // Test for method void 2930 // java.io.ObjectOutputStream.writeObject(java.text.NumberFormat.Field) 2931 2932 NumberFormat.Field[] objToSave = null; 2933 NumberFormat.Field[] objLoaded = null; 2934 2935 try { 2936 objToSave = new NumberFormat.Field[] { NumberFormat.Field.CURRENCY, 2937 NumberFormat.Field.DECIMAL_SEPARATOR, 2938 NumberFormat.Field.EXPONENT, 2939 NumberFormat.Field.EXPONENT_SIGN, 2940 NumberFormat.Field.EXPONENT_SYMBOL, 2941 NumberFormat.Field.FRACTION, 2942 NumberFormat.Field.GROUPING_SEPARATOR, 2943 NumberFormat.Field.INTEGER, NumberFormat.Field.PERCENT, 2944 NumberFormat.Field.PERMILLE, NumberFormat.Field.SIGN }; 2945 if (DEBUG) 2946 System.out.println("Obj = " + objToSave); 2947 2948 objLoaded = (NumberFormat.Field[]) dumpAndReload(objToSave); 2949 2950 // Has to have worked 2951 // we need same instances for the same field names 2952 for (int i = 0; i < objToSave.length; i++) { 2953 assertTrue(MSG_TEST_FAILED + objToSave[i], 2954 objToSave[i] == objLoaded[i]); 2955 } 2956 } catch (IOException e) { 2957 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2958 } catch (ClassNotFoundException e) { 2959 fail("ClassNotFoundException reading Object type: " 2960 + e.getMessage()); 2961 } catch (Error err) { 2962 System.out.println("Error when obj = " + objToSave); 2963 // err.printStackTrace(); 2964 throw err; 2965 } 2966 } 2967 2968 @TestTargetNew( 2969 level = TestLevel.COMPLETE, 2970 notes = "Verifies serialization.", 2971 method = "!Serialization", 2972 args = {} 2973 ) 2974 public void test_writeObject_MessageFormat_Field() { 2975 // Test for method void 2976 // java.io.ObjectOutputStream.writeObject(java.text.MessageFormat.Field) 2977 2978 Object objToSave = null; 2979 Object objLoaded = null; 2980 2981 try { 2982 objToSave = MessageFormat.Field.ARGUMENT; 2983 if (DEBUG) 2984 System.out.println("Obj = " + objToSave); 2985 2986 objLoaded = dumpAndReload(objToSave); 2987 2988 // Has to have worked 2989 // we need same instance for the same field name 2990 assertTrue(MSG_TEST_FAILED + objToSave, objToSave == objLoaded); 2991 } catch (IOException e) { 2992 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2993 } catch (ClassNotFoundException e) { 2994 fail("ClassNotFoundException reading Object type: " 2995 + e.getMessage()); 2996 } catch (Error err) { 2997 System.out.println("Error when obj = " + objToSave); 2998 // err.printStackTrace(); 2999 throw err; 3000 } 3001 } 3002 3003 @TestTargetNew( 3004 level = TestLevel.COMPLETE, 3005 notes = "Verifies serialization.", 3006 method = "!Serialization", 3007 args = {} 3008 ) 3009 public void test_writeObject_LinkedHashMap() { 3010 // Test for method void 3011 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 3012 3013 Object objToSave = null; 3014 Object objLoaded; 3015 3016 try { 3017 objToSave = LINKEDMAP; 3018 if (DEBUG) 3019 System.out.println("Obj = " + objToSave); 3020 objLoaded = dumpAndReload(objToSave); 3021 // Has to have worked 3022 assertTrue(MSG_TEST_FAILED + objToSave, LINKEDMAP.equals(objLoaded)); 3023 3024 Map mapLoaded = (Map) objLoaded; 3025 Iterator loadedIterator = mapLoaded.keySet().iterator(); 3026 Iterator iterator = LINKEDMAP.keySet().iterator(); 3027 while (loadedIterator.hasNext()) { 3028 assertTrue("invalid iterator order", loadedIterator.next() 3029 .equals(iterator.next())); 3030 } 3031 assertTrue("invalid iterator size", !iterator.hasNext()); 3032 3033 loadedIterator = mapLoaded.entrySet().iterator(); 3034 iterator = LINKEDMAP.entrySet().iterator(); 3035 while (loadedIterator.hasNext()) { 3036 assertTrue("invalid entry set iterator order", loadedIterator 3037 .next().equals(iterator.next())); 3038 } 3039 assertTrue("invalid entry set iterator size", !iterator.hasNext()); 3040 3041 } catch (IOException e) { 3042 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 3043 } catch (ClassNotFoundException e) { 3044 fail("ClassNotFoundException reading Object type: " 3045 + e.getMessage()); 3046 } catch (Error err) { 3047 System.out.println("Error when obj = " + objToSave); 3048 // err.printStackTrace(); 3049 throw err; 3050 } 3051 } 3052 3053 @TestTargetNew( 3054 level = TestLevel.COMPLETE, 3055 notes = "Verifies serialization.", 3056 method = "!Serialization", 3057 args = {} 3058 ) 3059 public void test_writeObject_LinkedHashSet() { 3060 // Test for method void 3061 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 3062 3063 Object objToSave = null; 3064 Object objLoaded; 3065 3066 try { 3067 objToSave = LINKEDSET; 3068 if (DEBUG) 3069 System.out.println("Obj = " + objToSave); 3070 objLoaded = dumpAndReload(objToSave); 3071 // Has to have worked 3072 assertTrue(MSG_TEST_FAILED + objToSave, LINKEDSET.equals(objLoaded)); 3073 3074 } catch (IOException e) { 3075 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 3076 } catch (ClassNotFoundException e) { 3077 fail("ClassNotFoundException reading Object type: " 3078 + e.getMessage()); 3079 } catch (Error err) { 3080 System.out.println("Error when obj = " + objToSave); 3081 // err.printStackTrace(); 3082 throw err; 3083 } 3084 } 3085 3086 @TestTargetNew( 3087 level = TestLevel.COMPLETE, 3088 notes = "Verifies serialization.", 3089 method = "!Serialization", 3090 args = {} 3091 ) 3092 public void test_writeObject_IdentityHashMap() { 3093 // Test for method void 3094 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 3095 3096 IdentityHashMap objToSave = null; 3097 IdentityHashMap objLoaded; 3098 3099 try { 3100 objToSave = IDENTITYMAP; 3101 if (DEBUG) 3102 System.out.println("Obj = " + objToSave); 3103 objLoaded = (IdentityHashMap) dumpAndReload(objToSave); 3104 // Has to have worked 3105 3106 // a serialized identity hash map will not be equal to its original 3107 // because it is an "identity" mapping, 3108 // so we simply check for the usual meaning of equality 3109 3110 assertEquals( 3111 "Loaded IdentityHashMap is not of the same size as the saved one.", 3112 objToSave.size(), objLoaded.size()); 3113 HashMap duplicateSaved = new HashMap(); 3114 duplicateSaved.putAll(objToSave); 3115 HashMap duplicateLoaded = new HashMap(); 3116 duplicateLoaded.putAll(objLoaded); 3117 assertTrue(MSG_TEST_FAILED + duplicateSaved, duplicateSaved 3118 .equals(duplicateLoaded)); 3119 } catch (IOException e) { 3120 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 3121 } catch (ClassNotFoundException e) { 3122 fail("ClassNotFoundException reading Object type: " 3123 + e.getMessage()); 3124 } catch (Error err) { 3125 System.out.println("Error when obj = " + objToSave); 3126 // err.printStackTrace(); 3127 throw err; 3128 } 3129 } 3130} 3131