SerializationStressTest4.java revision ddc0d4c2f8d3fea4ddaf6e611ffd73a1169447e8
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 java.io.File; 21import java.io.FilePermission; 22import java.io.IOException; 23import java.io.Serializable; 24import java.lang.reflect.InvocationHandler; 25import java.lang.reflect.Method; 26import java.lang.reflect.Proxy; 27import java.net.URI; 28import java.net.URISyntaxException; 29import java.security.AllPermission; 30import java.security.PermissionCollection; 31import java.security.cert.Certificate; 32import java.text.DateFormat; 33import java.text.MessageFormat; 34import java.text.NumberFormat; 35import java.util.Arrays; 36import java.util.Comparator; 37import java.util.Date; 38import java.util.Enumeration; 39import java.util.HashMap; 40import java.util.IdentityHashMap; 41import java.util.Iterator; 42import java.util.List; 43import java.util.Locale; 44import java.util.Map; 45import java.util.Set; 46import java.util.TimeZone; 47import java.util.Collections; 48 49import tests.support.Support_Configuration; 50import tests.support.Support_Proxy_I1; 51import dalvik.annotation.KnownFailure; 52import dalvik.annotation.TestLevel; 53import dalvik.annotation.TestTargetClass; 54import dalvik.annotation.TestTargetNew; 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() { 1202 // Test for method void 1203 // java.io.ObjectOutputStream.writeObject(java.util.Collections.UnmodifiableMap) 1204 1205 Object objToSave = null; 1206 Object objLoaded = null; 1207 1208 try { 1209 objToSave = java.util.Collections.unmodifiableMap(MAP); 1210 if (DEBUG) System.out.println("Obj = " + objToSave); 1211 objLoaded = dumpAndReload(objToSave); 1212 1213 // Has to have worked 1214 assertEquals(MSG_TEST_FAILED, objToSave, objLoaded); 1215 } catch (IOException e) { 1216 e.printStackTrace(); 1217 fail("IOException serializing " + objToSave + " : " 1218 + e.getMessage()); 1219 } catch (ClassNotFoundException e) { 1220 fail("ClassNotFoundException reading Object type : " 1221 + e.getMessage()); 1222 } catch (Error err) { 1223 System.out.println("Error when obj = " + objToSave); 1224 // err.printStackTrace(); 1225 throw err; 1226 } 1227 1228 } 1229 1230 @TestTargetNew( 1231 level = TestLevel.COMPLETE, 1232 notes = "Verifies serialization.", 1233 method = "!Serialization", 1234 args = {} 1235 ) 1236 public void test_writeObject_NumberFormat() { 1237 // Test for method void 1238 // java.io.ObjectOutputStream.writeObject(java.text.NumberFormat) 1239 1240 Object objToSave = null; 1241 Object objLoaded = null; 1242 1243 try { 1244 objToSave = null; 1245 objToSave = new java.text.NumberFormat() { 1246 long save = 107; 1247 1248 public StringBuffer format(double p1, StringBuffer p2, 1249 java.text.FieldPosition p3) { 1250 return new StringBuffer(); 1251 } 1252 1253 public StringBuffer format(long p1, StringBuffer p2, 1254 java.text.FieldPosition p3) { 1255 if (p1 != 0) 1256 save = p1; 1257 return new StringBuffer(Long.toString(save)); 1258 } 1259 1260 public Number parse(String p1, java.text.ParsePosition p2) { 1261 return new Long(save); 1262 } 1263 1264 public boolean equals(Object obj) { 1265 if (!(obj instanceof java.text.NumberFormat)) 1266 return false; 1267 return save == ((Long) ((java.text.NumberFormat) obj) 1268 .parse(null, null)).longValue(); 1269 } 1270 }; 1271 1272 ((java.text.NumberFormat) objToSave).format(63L, null, null); 1273 if (DEBUG) 1274 System.out.println("Obj = " + objToSave); 1275 objLoaded = dumpAndReload(objToSave); 1276 1277 // Has to have worked 1278 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1279 } catch (IOException e) { 1280 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1281 } catch (ClassNotFoundException e) { 1282 fail("ClassNotFoundException reading Object type: " 1283 + e.getMessage()); 1284 } catch (Error err) { 1285 System.out.println("Error when obj = " + objToSave); 1286 // err.printStackTrace(); 1287 throw err; 1288 } 1289 1290 } 1291 1292 @TestTargetNew( 1293 level = TestLevel.COMPLETE, 1294 notes = "Verifies serialization.", 1295 method = "!Serialization", 1296 args = {} 1297 ) 1298 public void test_writeObject_TimeZone() { 1299 // Test for method void 1300 // java.io.ObjectOutputStream.writeObject(java.util.TimeZone) 1301 1302 Object objToSave = null; 1303 Object objLoaded = null; 1304 1305 try { 1306 objToSave = null; 1307 objToSave = new java.util.TimeZone() { 1308 int save = 0; 1309 1310 public int getOffset(int p1, int p2, int p3, int p4, int p5, 1311 int p6) { 1312 return 0; 1313 } 1314 1315 public int getRawOffset() { 1316 return save; 1317 } 1318 1319 public boolean inDaylightTime(java.util.Date p1) { 1320 return false; 1321 } 1322 1323 public void setRawOffset(int p1) { 1324 save = p1; 1325 } 1326 1327 public boolean useDaylightTime() { 1328 return false; 1329 } 1330 1331 public boolean equals(Object obj) { 1332 if (obj instanceof TimeZone) 1333 return save == ((TimeZone) obj).getRawOffset(); 1334 return false; 1335 } 1336 }; 1337 1338 ((java.util.TimeZone) objToSave).setRawOffset(48); 1339 if (DEBUG) 1340 System.out.println("Obj = " + objToSave); 1341 objLoaded = dumpAndReload(objToSave); 1342 1343 // Has to have worked 1344 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1345 } catch (IOException e) { 1346 fail("IOException serializing " + objToSave + " : " 1347 + e.getMessage()); 1348 } catch (ClassNotFoundException e) { 1349 fail("ClassNotFoundException reading Object type : " 1350 + e.getMessage()); 1351 } catch (Error err) { 1352 System.out.println("Error when obj = " + objToSave); 1353 // err.printStackTrace(); 1354 throw err; 1355 } 1356 1357 } 1358 1359 @TestTargetNew( 1360 level = TestLevel.COMPLETE, 1361 notes = "Verifies serialization.", 1362 method = "!Serialization", 1363 args = {} 1364 ) 1365 public void test_writeObject_Double() { 1366 // Test for method void 1367 // java.io.ObjectOutputStream.writeObject(java.lang.Double) 1368 1369 Object objToSave = null; 1370 Object objLoaded = null; 1371 1372 try { 1373 objToSave = new java.lang.Double(1.23); 1374 if (DEBUG) 1375 System.out.println("Obj = " + objToSave); 1376 objLoaded = dumpAndReload(objToSave); 1377 1378 // Has to have worked 1379 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1380 } catch (IOException e) { 1381 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1382 } catch (ClassNotFoundException e) { 1383 fail("ClassNotFoundException reading Object type: " 1384 + e.getMessage()); 1385 } catch (Error err) { 1386 System.out.println("Error when obj = " + objToSave); 1387 // err.printStackTrace(); 1388 throw err; 1389 } 1390 1391 } 1392 1393 @TestTargetNew( 1394 level = TestLevel.COMPLETE, 1395 notes = "Verifies serialization.", 1396 method = "!Serialization", 1397 args = {} 1398 ) 1399 public void test_writeObject_Number() { 1400 // Test for method void 1401 // java.io.ObjectOutputStream.writeObject(java.lang.Number) 1402 1403 Object objToSave = null; 1404 Object objLoaded = null; 1405 1406 try { 1407 objToSave = null; 1408 objToSave = new Number() { 1409 int numCalls = 0; 1410 1411 public double doubleValue() { 1412 return ++numCalls; 1413 } 1414 1415 public float floatValue() { 1416 return ++numCalls; 1417 } 1418 1419 public int intValue() { 1420 return numCalls; 1421 } 1422 1423 public long longValue() { 1424 return ++numCalls; 1425 } 1426 1427 public boolean equals(Object obj) { 1428 if (!(obj instanceof java.lang.Number)) 1429 return false; 1430 return intValue() == ((Number) obj).intValue(); 1431 } 1432 }; 1433 ((java.lang.Number) objToSave).doubleValue(); 1434 ((java.lang.Number) objToSave).floatValue(); 1435 if (DEBUG) 1436 System.out.println("Obj = " + objToSave); 1437 objLoaded = dumpAndReload(objToSave); 1438 1439 // Has to have worked 1440 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1441 } catch (IOException e) { 1442 fail("IOException serializing " + objToSave + " : " 1443 + e.getMessage()); 1444 } catch (ClassNotFoundException e) { 1445 fail("ClassNotFoundException reading Object type : " 1446 + e.getMessage()); 1447 } catch (Error err) { 1448 System.out.println("Error when obj = " + objToSave); 1449 // err.printStackTrace(); 1450 throw err; 1451 } 1452 1453 } 1454 1455 @TestTargetNew( 1456 level = TestLevel.COMPLETE, 1457 notes = "Verifies serialization.", 1458 method = "!Serialization", 1459 args = {} 1460 ) 1461 public void test_writeObject_AllPermission() { 1462 // Test for method void 1463 // java.io.ObjectOutputStream.writeObject(java.security.AllPermission) 1464 1465 Object objToSave = null; 1466 Object objLoaded = null; 1467 1468 try { 1469 objToSave = new java.security.AllPermission(); 1470 if (DEBUG) 1471 System.out.println("Obj = " + objToSave); 1472 objLoaded = dumpAndReload(objToSave); 1473 1474 // Has to have worked 1475 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1476 } catch (IOException e) { 1477 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1478 } catch (ClassNotFoundException e) { 1479 fail("ClassNotFoundException reading Object type: " 1480 + e.getMessage()); 1481 } catch (Error err) { 1482 System.out.println("Error when obj = " + objToSave); 1483 // err.printStackTrace(); 1484 throw err; 1485 } 1486 1487 } 1488 1489 @TestTargetNew( 1490 level = TestLevel.COMPLETE, 1491 notes = "Verifies serialization.", 1492 method = "!Serialization", 1493 args = {} 1494 ) 1495 public void test_writeObject_Collections_ReverseComparator() { 1496 // Test for method void 1497 // java.io.ObjectOutputStream.writeObject(java.util.Collections.ReverseComparator) 1498 1499 Object objToSave = null; 1500 Object objLoaded = null; 1501 1502 try { 1503 objToSave = java.util.Collections.reverseOrder(); 1504 if (DEBUG) 1505 System.out.println("Obj = " + objToSave); 1506 objLoaded = dumpAndReload(objToSave); 1507 1508 // Has to have worked 1509 boolean equals; 1510 equals = ((Comparator) objToSave).compare("Hello", "Jello") == ((Comparator) objLoaded) 1511 .compare("Hello", "Jello"); 1512 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1513 } catch (IOException e) { 1514 fail("IOException serializing " + objToSave + " : " 1515 + e.getMessage()); 1516 } catch (ClassNotFoundException e) { 1517 fail("ClassNotFoundException reading Object type : " 1518 + e.getMessage()); 1519 } catch (Error err) { 1520 System.out.println("Error when obj = " + objToSave); 1521 // err.printStackTrace(); 1522 throw err; 1523 } 1524 1525 } 1526 1527 @TestTargetNew( 1528 level = TestLevel.COMPLETE, 1529 notes = "Verifies serialization.", 1530 method = "!Serialization", 1531 args = {} 1532 ) 1533 public void test_writeObject_DateFormatSymbols() { 1534 // Test for method void 1535 // java.io.ObjectOutputStream.writeObject(java.text.DateFormatSymbols) 1536 1537 Object objToSave = null; 1538 Object objLoaded = null; 1539 1540 try { 1541 objToSave = new java.text.DateFormatSymbols(Locale.CHINESE); 1542 ((java.text.DateFormatSymbols) objToSave) 1543 .setZoneStrings(new String[][] { { "a", "b", "c", "d" }, 1544 { "e", "f", "g", "h" } }); 1545 if (DEBUG) 1546 System.out.println("Obj = " + objToSave); 1547 objLoaded = dumpAndReload(objToSave); 1548 1549 // Has to have worked 1550 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1551 } catch (IOException e) { 1552 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1553 } catch (ClassNotFoundException e) { 1554 fail("ClassNotFoundException reading Object type: " 1555 + e.getMessage()); 1556 } catch (Error err) { 1557 System.out.println("Error when obj = " + objToSave); 1558 // err.printStackTrace(); 1559 throw err; 1560 } 1561 1562 } 1563 1564 @TestTargetNew( 1565 level = TestLevel.COMPLETE, 1566 notes = "Verifies serialization.", 1567 method = "!Serialization", 1568 args = {} 1569 ) 1570 public void test_writeObject_Collections_EmptyList() { 1571 // Test for method void 1572 // java.io.ObjectOutputStream.writeObject(java.util.Collections.EmptyList) 1573 1574 Object objToSave = null; 1575 Object objLoaded = null; 1576 1577 try { 1578 objToSave = java.util.Collections.EMPTY_LIST; 1579 if (DEBUG) 1580 System.out.println("Obj = " + objToSave); 1581 objLoaded = dumpAndReload(objToSave); 1582 1583 // Has to have worked 1584 boolean equals; 1585 equals = objToSave.equals(objLoaded); 1586 if (equals) 1587 equals = ((List) objLoaded).size() == 0; 1588 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1589 } catch (IOException e) { 1590 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1591 } catch (ClassNotFoundException e) { 1592 fail("ClassNotFoundException reading Object type: " 1593 + e.getMessage()); 1594 } catch (Error err) { 1595 System.out.println("Error when obj = " + objToSave); 1596 // err.printStackTrace(); 1597 throw err; 1598 } 1599 1600 } 1601 1602 @TestTargetNew( 1603 level = TestLevel.COMPLETE, 1604 notes = "Verifies serialization.", 1605 method = "!Serialization", 1606 args = {} 1607 ) 1608 public void test_writeObject_Boolean() { 1609 // Test for method void 1610 // java.io.ObjectOutputStream.writeObject(java.lang.Boolean) 1611 1612 Object objToSave = null; 1613 Object objLoaded = null; 1614 1615 try { 1616 objToSave = new java.lang.Boolean(true); 1617 if (DEBUG) 1618 System.out.println("Obj = " + objToSave); 1619 objLoaded = dumpAndReload(objToSave); 1620 1621 // Has to have worked 1622 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1623 } catch (IOException e) { 1624 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1625 } catch (ClassNotFoundException e) { 1626 fail("ClassNotFoundException reading Object type: " 1627 + e.getMessage()); 1628 } catch (Error err) { 1629 System.out.println("Error when obj = " + objToSave); 1630 // err.printStackTrace(); 1631 throw err; 1632 } 1633 1634 } 1635 1636 @TestTargetNew( 1637 level = TestLevel.COMPLETE, 1638 notes = "Verifies serialization.", 1639 method = "!Serialization", 1640 args = {} 1641 ) 1642 public void test_writeObject_Collections_SingletonSet() { 1643 // Test for method void 1644 // java.io.ObjectOutputStream.writeObject(java.util.Collections.SingletonSet) 1645 1646 Object objToSave = null; 1647 Object objLoaded = null; 1648 1649 try { 1650 objToSave = java.util.Collections.singleton(new Byte((byte) 107)); 1651 if (DEBUG) 1652 System.out.println("Obj = " + objToSave); 1653 objLoaded = dumpAndReload(objToSave); 1654 1655 // Has to have worked 1656 boolean equals; 1657 java.util.Iterator iter = ((Set) objLoaded).iterator(); 1658 equals = iter.hasNext(); 1659 if (equals) 1660 equals = iter.next().equals(new Byte((byte) 107)); 1661 if (equals) 1662 equals = !iter.hasNext(); 1663 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1664 } catch (IOException e) { 1665 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1666 } catch (ClassNotFoundException e) { 1667 fail("ClassNotFoundException reading Object type: " 1668 + e.getMessage()); 1669 } catch (Error err) { 1670 System.out.println("Error when obj = " + objToSave); 1671 // err.printStackTrace(); 1672 throw err; 1673 } 1674 1675 } 1676 1677 @TestTargetNew( 1678 level = TestLevel.COMPLETE, 1679 notes = "Verifies serialization.", 1680 method = "!Serialization", 1681 args = {} 1682 ) 1683 public void test_writeObject_Collections_SingletonList() { 1684 // Test for method void 1685 // java.io.ObjectOutputStream.writeObject(java.util.Collections.SingletonSet) 1686 1687 Object objToSave = null; 1688 Object objLoaded = null; 1689 1690 try { 1691 objToSave = java.util.Collections 1692 .singletonList(new Byte((byte) 107)); 1693 if (DEBUG) 1694 System.out.println("Obj = " + objToSave); 1695 objLoaded = dumpAndReload(objToSave); 1696 1697 // Has to have worked 1698 boolean equals; 1699 java.util.Iterator iter = ((List) objLoaded).iterator(); 1700 equals = objLoaded.equals(objToSave) && iter.hasNext() 1701 && iter.next().equals(new Byte((byte) 107)) 1702 && !iter.hasNext(); 1703 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1704 } catch (IOException e) { 1705 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1706 } catch (ClassNotFoundException e) { 1707 fail("ClassNotFoundException reading Object type: " 1708 + e.getMessage()); 1709 } catch (Error err) { 1710 System.out.println("Error when obj = " + objToSave); 1711 // err.printStackTrace(); 1712 throw err; 1713 } 1714 1715 } 1716 1717 @TestTargetNew( 1718 level = TestLevel.COMPLETE, 1719 notes = "Verifies serialization.", 1720 method = "!Serialization", 1721 args = {} 1722 ) 1723 public void test_writeObject_Collections_SingletonMap() { 1724 // Test for method void 1725 // java.io.ObjectOutputStream.writeObject(java.util.Collections.SingletonSet) 1726 1727 Object objToSave = null; 1728 Object objLoaded = null; 1729 1730 try { 1731 objToSave = java.util.Collections.singletonMap("key", new Byte( 1732 (byte) 107)); 1733 if (DEBUG) 1734 System.out.println("Obj = " + objToSave); 1735 objLoaded = dumpAndReload(objToSave); 1736 1737 // Has to have worked 1738 boolean equals; 1739 java.util.Iterator iter = ((Map) objLoaded).entrySet().iterator(); 1740 equals = objLoaded.equals(objToSave) && iter.hasNext(); 1741 Map.Entry entry = (Map.Entry) iter.next(); 1742 equals = equals && entry.getKey().equals("key") 1743 && entry.getValue().equals(new Byte((byte) 107)) 1744 && !iter.hasNext(); 1745 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1746 } catch (IOException e) { 1747 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1748 } catch (ClassNotFoundException e) { 1749 fail("ClassNotFoundException reading Object type: " 1750 + e.getMessage()); 1751 } catch (Error err) { 1752 System.out.println("Error when obj = " + objToSave); 1753 // err.printStackTrace(); 1754 throw err; 1755 } 1756 1757 } 1758 1759 @TestTargetNew( 1760 level = TestLevel.COMPLETE, 1761 notes = "Verifies serialization.", 1762 method = "!Serialization", 1763 args = {} 1764 ) 1765 public void test_writeObject_FilePermission_FilePermissionCollection() { 1766 // Test for method void 1767 // java.io.ObjectOutputStream.writeObject(java.io.FilePermission.FilePermissionCollection) 1768 1769 Object objToSave = null; 1770 Object objLoaded = null; 1771 1772 try { 1773 objToSave = (new java.io.FilePermission("<<ALL FILES>>", "read")) 1774 .newPermissionCollection(); 1775 ((java.security.PermissionCollection) objToSave) 1776 .add(new FilePermission("<<ALL FILES>>", "read")); 1777 ((java.security.PermissionCollection) objToSave) 1778 .add(new FilePermission("d:\\", "read")); 1779 if (DEBUG) 1780 System.out.println("Obj = " + objToSave); 1781 objLoaded = dumpAndReload(objToSave); 1782 1783 // Has to have worked 1784 boolean equals; 1785 java.util.Enumeration enum1 = ((java.security.PermissionCollection) objToSave) 1786 .elements(), enum2 = ((java.security.PermissionCollection) objLoaded) 1787 .elements(); 1788 1789 equals = true; 1790 while (enum1.hasMoreElements() && equals) { 1791 if (enum2.hasMoreElements()) 1792 equals = enum1.nextElement().equals(enum2.nextElement()); 1793 else 1794 equals = false; 1795 } 1796 1797 if (equals) 1798 equals = !enum2.hasMoreElements(); 1799 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1800 } catch (IOException e) { 1801 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1802 } catch (ClassNotFoundException e) { 1803 fail("ClassNotFoundException reading Object type: " 1804 + e.getMessage()); 1805 } catch (Error err) { 1806 System.out.println("Error when obj = " + objToSave); 1807 // err.printStackTrace(); 1808 throw err; 1809 } 1810 1811 } 1812 1813 @TestTargetNew( 1814 level = TestLevel.COMPLETE, 1815 notes = "Verifies serialization.", 1816 method = "!Serialization", 1817 args = {} 1818 ) 1819 public void test_writeObject_SecureRandom() { 1820 // Test for method void 1821 // java.io.ObjectOutputStream.writeObject(java.security.SecureRandom) 1822 1823 Object objToSave = null; 1824 Object objLoaded = null; 1825 1826 try { 1827 objToSave = new java.security.SecureRandom(); 1828 if (DEBUG) 1829 System.out.println("Obj = " + objToSave); 1830 objLoaded = dumpAndReload(objToSave); 1831 1832 // Has to have worked 1833 boolean equals; 1834 equals = true; // assume fine because of the nature of the class, 1835 // it is difficult to determine if they are the same 1836 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1837 } catch (IOException e) { 1838 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1839 } catch (ClassNotFoundException e) { 1840 fail("ClassNotFoundException reading Object type: " 1841 + e.getMessage()); 1842 } catch (Error err) { 1843 System.out.println("Error when obj = " + objToSave); 1844 // err.printStackTrace(); 1845 throw err; 1846 } 1847 1848 } 1849 1850 @TestTargetNew( 1851 level = TestLevel.COMPLETE, 1852 notes = "Verifies serialization.", 1853 method = "!Serialization", 1854 args = {} 1855 ) 1856 public void test_writeObject_FilePermission() { 1857 // Test for method void 1858 // java.io.ObjectOutputStream.writeObject(java.io.FilePermission) 1859 1860 Object objToSave = null; 1861 Object objLoaded = null; 1862 1863 try { 1864 objToSave = new java.io.FilePermission("<<ALL FILES>>", "read"); 1865 if (DEBUG) 1866 System.out.println("Obj = " + objToSave); 1867 objLoaded = dumpAndReload(objToSave); 1868 1869 // Has to have worked 1870 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1871 } catch (IOException e) { 1872 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1873 } catch (ClassNotFoundException e) { 1874 fail("ClassNotFoundException reading Object type: " 1875 + e.getMessage()); 1876 } catch (Error err) { 1877 System.out.println("Error when obj = " + objToSave); 1878 // err.printStackTrace(); 1879 throw err; 1880 } 1881 1882 } 1883 1884 @TestTargetNew( 1885 level = TestLevel.COMPLETE, 1886 notes = "Verifies serialization.", 1887 method = "!Serialization", 1888 args = {} 1889 ) 1890 public void test_writeObject_InetAddress() { 1891 // Test for method void 1892 // java.io.ObjectOutputStream.writeObject(java.net.InetAddress) 1893 1894 Object objToSave = null; 1895 Object objLoaded = null; 1896 1897 try { 1898 objToSave = java.net.InetAddress 1899 .getByName(Support_Configuration.InetTestIP); 1900 if (DEBUG) 1901 System.out.println("Obj = " + objToSave); 1902 objLoaded = dumpAndReload(objToSave); 1903 1904 // Has to have worked 1905 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1906 } catch (IOException e) { 1907 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1908 } catch (ClassNotFoundException e) { 1909 fail("ClassNotFoundException reading Object type: " 1910 + e.getMessage()); 1911 } catch (Error err) { 1912 System.out.println("Error when obj = " + objToSave); 1913 // err.printStackTrace(); 1914 throw err; 1915 } 1916 1917 } 1918 1919 @TestTargetNew( 1920 level = TestLevel.COMPLETE, 1921 notes = "Verifies serialization.", 1922 method = "!Serialization", 1923 args = {} 1924 ) 1925 public void test_writeObject_Inet6Address() { 1926 // Test for method void 1927 // java.io.ObjectOutputStream.writeObject(java.net.Inet6Address) 1928 1929 Object objToSave = null; 1930 Object objLoaded = null; 1931 1932 try { 1933 objToSave = java.net.Inet6Address 1934 .getByName(Support_Configuration.InetTestIP6); 1935 if (DEBUG) 1936 System.out.println("Obj = " + objToSave); 1937 objLoaded = dumpAndReload(objToSave); 1938 1939 // Has to have worked 1940 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1941 1942 } catch (IOException e) { 1943 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1944 } catch (ClassNotFoundException e) { 1945 fail("ClassNotFoundException reading Object type: " 1946 + e.getMessage()); 1947 } catch (Error err) { 1948 System.out.println("Error when obj = " + objToSave); 1949 // err.printStackTrace(); 1950 throw err; 1951 } 1952 1953 } 1954 1955 @TestTargetNew( 1956 level = TestLevel.COMPLETE, 1957 notes = "Verifies serialization.", 1958 method = "!Serialization", 1959 args = {} 1960 ) 1961 public void test_writeObject_RuntimePermission() { 1962 // Test for method void 1963 // java.io.ObjectOutputStream.writeObject(java.lang.RuntimePermission) 1964 1965 Object objToSave = null; 1966 Object objLoaded = null; 1967 1968 try { 1969 objToSave = new java.lang.RuntimePermission("TestSerialization", 1970 "Test"); 1971 if (DEBUG) 1972 System.out.println("Obj = " + objToSave); 1973 objLoaded = dumpAndReload(objToSave); 1974 1975 // Has to have worked 1976 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1977 } catch (IOException e) { 1978 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1979 } catch (ClassNotFoundException e) { 1980 fail("ClassNotFoundException reading Object type: " 1981 + e.getMessage()); 1982 } catch (Error err) { 1983 System.out.println("Error when obj = " + objToSave); 1984 // err.printStackTrace(); 1985 throw err; 1986 } 1987 1988 } 1989 1990 @TestTargetNew( 1991 level = TestLevel.COMPLETE, 1992 notes = "Verifies serialization.", 1993 method = "!Serialization", 1994 args = {} 1995 ) 1996 public void test_writeObject_Permissions() { 1997 // Test for method void 1998 // java.io.ObjectOutputStream.writeObject(java.security.Permissions) 1999 2000 Object objToSave = null; 2001 Object objLoaded = null; 2002 2003 try { 2004 objToSave = new java.security.Permissions(); 2005 ((java.security.Permissions) objToSave).add(new AllPermission()); 2006 if (DEBUG) 2007 System.out.println("Obj = " + objToSave); 2008 objLoaded = dumpAndReload(objToSave); 2009 2010 // Has to have worked 2011 boolean equals; 2012 Enumeration enum1 = ((java.security.PermissionCollection) objToSave) 2013 .elements(), enum2 = ((java.security.PermissionCollection) objLoaded) 2014 .elements(); 2015 java.util.Vector vec1 = new java.util.Vector(), vec2 = new java.util.Vector(); 2016 2017 while (enum1.hasMoreElements()) 2018 vec1.add(enum1.nextElement()); 2019 while (enum2.hasMoreElements()) 2020 vec2.add(enum2.nextElement()); 2021 2022 equals = vec1.size() == vec2.size(); 2023 if (equals) { 2024 int length = vec1.size(); 2025 Object[] perms1 = new Object[length], perms2 = new Object[length]; 2026 for (int i = 0; i < length; ++i) { 2027 perms1[i] = vec1.elementAt(i); 2028 perms2[i] = vec2.elementAt(i); 2029 } 2030 2031 Comparator comparator = new Comparator() { 2032 public int compare(Object o1, Object o2) { 2033 return o1.toString().compareTo(o2.toString()); 2034 } 2035 2036 public boolean equals(Object o1, Object o2) { 2037 return o1.toString().equals(o2.toString()); 2038 } 2039 }; 2040 2041 java.util.Arrays.sort(perms1, comparator); 2042 java.util.Arrays.sort(perms2, comparator); 2043 2044 for (int i = 0; i < length && equals; ++i) 2045 equals = perms1[i].equals(perms2[i]); 2046 } 2047 2048 assertTrue(MSG_TEST_FAILED + objToSave, equals); 2049 } catch (IOException e) { 2050 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2051 } catch (ClassNotFoundException e) { 2052 fail("ClassNotFoundException reading Object type: " 2053 + e.getMessage()); 2054 } catch (Error err) { 2055 System.out.println("Error when obj = " + objToSave); 2056 // err.printStackTrace(); 2057 throw err; 2058 } 2059 2060 } 2061 2062 @TestTargetNew( 2063 level = TestLevel.COMPLETE, 2064 notes = "Verifies serialization.", 2065 method = "!Serialization", 2066 args = {} 2067 ) 2068 public void test_writeObject_Date() { 2069 // Test for method void 2070 // java.io.ObjectOutputStream.writeObject(java.util.Date) 2071 2072 Object objToSave = null; 2073 Object objLoaded = null; 2074 2075 try { 2076 // Thu Feb 01 01:01:01 EST 2001 2077 objToSave = new java.util.Date(981007261000L); 2078 if (DEBUG) 2079 System.out.println("Obj = " + objToSave); 2080 objLoaded = dumpAndReload(objToSave); 2081 2082 // Has to have worked 2083 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2084 } catch (IOException e) { 2085 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2086 } catch (ClassNotFoundException e) { 2087 fail("ClassNotFoundException reading Object type: " 2088 + e.getMessage()); 2089 } catch (Error err) { 2090 System.out.println("Error when obj = " + objToSave); 2091 // err.printStackTrace(); 2092 throw err; 2093 } 2094 2095 } 2096 2097 @TestTargetNew( 2098 level = TestLevel.COMPLETE, 2099 notes = "Verifies serialization.", 2100 method = "!Serialization", 2101 args = {} 2102 ) 2103 public void test_writeObject_Float() { 2104 // Test for method void 2105 // java.io.ObjectOutputStream.writeObject(java.lang.Float) 2106 2107 Object objToSave = null; 2108 Object objLoaded = null; 2109 2110 try { 2111 objToSave = new java.lang.Float(1.23f); 2112 if (DEBUG) 2113 System.out.println("Obj = " + objToSave); 2114 objLoaded = dumpAndReload(objToSave); 2115 2116 // Has to have worked 2117 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2118 } catch (IOException e) { 2119 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2120 } catch (ClassNotFoundException e) { 2121 fail("ClassNotFoundException reading Object type: " 2122 + e.getMessage()); 2123 } catch (Error err) { 2124 System.out.println("Error when obj = " + objToSave); 2125 // err.printStackTrace(); 2126 throw err; 2127 } 2128 2129 } 2130 2131 @TestTargetNew( 2132 level = TestLevel.COMPLETE, 2133 notes = "Verifies serialization.", 2134 method = "!Serialization", 2135 args = {} 2136 ) 2137 public void test_writeObject_SecurityPermission() { 2138 // Test for method void 2139 // java.io.ObjectOutputStream.writeObject(java.security.SecurityPermission) 2140 2141 Object objToSave = null; 2142 Object objLoaded = null; 2143 2144 try { 2145 objToSave = new java.security.SecurityPermission( 2146 "TestSerialization", "Test"); 2147 if (DEBUG) 2148 System.out.println("Obj = " + objToSave); 2149 objLoaded = dumpAndReload(objToSave); 2150 2151 // Has to have worked 2152 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2153 } catch (IOException e) { 2154 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2155 } catch (ClassNotFoundException e) { 2156 fail("ClassNotFoundException reading Object type: " 2157 + e.getMessage()); 2158 } catch (Error err) { 2159 System.out.println("Error when obj = " + objToSave); 2160 // err.printStackTrace(); 2161 throw err; 2162 } 2163 2164 } 2165 2166 @TestTargetNew( 2167 level = TestLevel.COMPLETE, 2168 notes = "Verifies serialization.", 2169 method = "!Serialization", 2170 args = {} 2171 ) 2172 public void test_writeObject_SocketPermission_SocketPermissionCollection() { 2173 // Test for method void 2174 // java.io.ObjectOutputStream.writeObject(java.net.SocketPermission.SocketPermissionCollection) 2175 2176 Object objToSave = null; 2177 Object objLoaded = null; 2178 2179 try { 2180 objToSave = (new java.net.SocketPermission("www.yahoo.com", 2181 "connect")).newPermissionCollection(); 2182 ((java.security.PermissionCollection) objToSave) 2183 .add(new java.net.SocketPermission("www.yahoo.com", 2184 "connect")); 2185 if (DEBUG) 2186 System.out.println("Obj = " + objToSave); 2187 objLoaded = dumpAndReload(objToSave); 2188 2189 // Has to have worked 2190 boolean equals; 2191 Enumeration enum1 = ((java.security.PermissionCollection) objToSave) 2192 .elements(), enum2 = ((java.security.PermissionCollection) objLoaded) 2193 .elements(); 2194 2195 equals = true; 2196 while (enum1.hasMoreElements() && equals) { 2197 if (enum2.hasMoreElements()) 2198 equals = enum1.nextElement().equals(enum2.nextElement()); 2199 else 2200 equals = false; 2201 } 2202 2203 if (equals) 2204 equals = !enum2.hasMoreElements(); 2205 assertTrue(MSG_TEST_FAILED + objToSave, equals); 2206 } catch (IOException e) { 2207 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2208 } catch (ClassNotFoundException e) { 2209 fail("ClassNotFoundException reading Object type: " 2210 + e.getMessage()); 2211 } catch (Error err) { 2212 System.out.println("Error when obj = " + objToSave); 2213 // err.printStackTrace(); 2214 throw err; 2215 } 2216 2217 } 2218 2219 @TestTargetNew( 2220 level = TestLevel.COMPLETE, 2221 notes = "Verifies serialization.", 2222 method = "!Serialization", 2223 args = {} 2224 ) 2225 public void test_writeObject_Stack() { 2226 // Test for method void 2227 // java.io.ObjectOutputStream.writeObject(java.util.Stack) 2228 2229 Object objToSave = null; 2230 Object objLoaded = null; 2231 2232 try { 2233 objToSave = new java.util.Stack(); 2234 ((java.util.Stack) objToSave).push("String 1"); 2235 ((java.util.Stack) objToSave).push("String 2"); 2236 if (DEBUG) 2237 System.out.println("Obj = " + objToSave); 2238 objLoaded = dumpAndReload(objToSave); 2239 2240 // Has to have worked 2241 boolean equals; 2242 equals = true; 2243 while (!((java.util.Stack) objToSave).empty() && equals) { 2244 if (!((java.util.Stack) objLoaded).empty()) 2245 equals = ((java.util.Stack) objToSave).pop().equals( 2246 ((java.util.Stack) objLoaded).pop()); 2247 else 2248 equals = false; 2249 } 2250 2251 if (equals) 2252 equals = ((java.util.Stack) objLoaded).empty(); 2253 assertTrue(MSG_TEST_FAILED + objToSave, equals); 2254 } catch (IOException e) { 2255 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2256 } catch (ClassNotFoundException e) { 2257 fail("ClassNotFoundException reading Object type: " 2258 + e.getMessage()); 2259 } catch (Error err) { 2260 System.out.println("Error when obj = " + objToSave); 2261 // err.printStackTrace(); 2262 throw err; 2263 } 2264 2265 } 2266 2267 @TestTargetNew( 2268 level = TestLevel.COMPLETE, 2269 notes = "Verifies serialization.", 2270 method = "!Serialization", 2271 args = {} 2272 ) 2273 public void test_writeObject_DecimalFormatSymbols() { 2274 // Test for method void 2275 // java.io.ObjectOutputStream.writeObject(java.text.DecimalFormatSymbols) 2276 2277 Object objToSave = null; 2278 Object objLoaded = null; 2279 2280 try { 2281 objToSave = new java.text.DecimalFormatSymbols(Locale.CHINESE); 2282 if (DEBUG) 2283 System.out.println("Obj = " + objToSave); 2284 objLoaded = dumpAndReload(objToSave); 2285 2286 // Has to have worked 2287 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2288 } catch (IOException e) { 2289 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2290 } catch (ClassNotFoundException e) { 2291 fail("ClassNotFoundException reading Object type: " 2292 + e.getMessage()); 2293 } catch (Error err) { 2294 System.out.println("Error when obj = " + objToSave); 2295 // err.printStackTrace(); 2296 throw err; 2297 } 2298 2299 } 2300 2301 @TestTargetNew( 2302 level = TestLevel.COMPLETE, 2303 notes = "Verifies serialization.", 2304 method = "!Serialization", 2305 args = {} 2306 ) 2307 public void test_writeObject_NetPermission() { 2308 // Test for method void 2309 // java.io.ObjectOutputStream.writeObject(java.net.NetPermission) 2310 2311 Object objToSave = null; 2312 Object objLoaded = null; 2313 2314 try { 2315 objToSave = new java.net.NetPermission("TestSerialization", "Test"); 2316 if (DEBUG) 2317 System.out.println("Obj = " + objToSave); 2318 objLoaded = dumpAndReload(objToSave); 2319 2320 // Has to have worked 2321 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2322 } catch (IOException e) { 2323 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2324 } catch (ClassNotFoundException e) { 2325 fail("ClassNotFoundException reading Object type: " 2326 + e.getMessage()); 2327 } catch (Error err) { 2328 System.out.println("Error when obj = " + objToSave); 2329 // err.printStackTrace(); 2330 throw err; 2331 } 2332 } 2333 2334 @TestTargetNew( 2335 level = TestLevel.COMPLETE, 2336 notes = "Verifies serialization.", 2337 method = "!Serialization", 2338 args = {} 2339 ) 2340 public void test_writeObject_AttributedCharacterIterator_Attribute() { 2341 // Test for method void 2342 // java.io.ObjectOutputStream.writeObject(java.text.AttributedCharacterIterator.Attribute) 2343 2344 Object objToSave = null; 2345 Object objLoaded = null; 2346 2347 try { 2348 objToSave = java.text.AttributedCharacterIterator.Attribute.LANGUAGE; 2349 if (DEBUG) 2350 System.out.println("Obj = " + objToSave); 2351 objLoaded = dumpAndReload(objToSave); 2352 2353 // Has to have worked 2354 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2355 } catch (IOException e) { 2356 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2357 } catch (ClassNotFoundException e) { 2358 fail("ClassNotFoundException reading Object type: " 2359 + e.getMessage()); 2360 } catch (Error err) { 2361 System.out.println("Error when obj = " + objToSave); 2362 // err.printStackTrace(); 2363 throw err; 2364 } 2365 } 2366 2367 @TestTargetNew( 2368 level = TestLevel.COMPLETE, 2369 notes = "Verifies serialization.", 2370 method = "!Serialization", 2371 args = {} 2372 ) 2373 public void test_writeObject_Long() { 2374 // Test for method void 2375 // java.io.ObjectOutputStream.writeObject(java.lang.Long) 2376 2377 Object objToSave = null; 2378 Object objLoaded = null; 2379 2380 try { 2381 objToSave = new java.lang.Long(107L); 2382 if (DEBUG) 2383 System.out.println("Obj = " + objToSave); 2384 objLoaded = dumpAndReload(objToSave); 2385 2386 // Has to have worked 2387 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2388 } catch (IOException e) { 2389 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2390 } catch (ClassNotFoundException e) { 2391 fail("ClassNotFoundException reading Object type: " 2392 + e.getMessage()); 2393 } catch (Error err) { 2394 System.out.println("Error when obj = " + objToSave); 2395 // err.printStackTrace(); 2396 throw err; 2397 } 2398 2399 } 2400 2401 @TestTargetNew( 2402 level = TestLevel.COMPLETE, 2403 notes = "Verifies serialization.", 2404 method = "!Serialization", 2405 args = {} 2406 ) 2407 public void test_writeObject_CodeSource() { 2408 // Test for method void 2409 // java.io.ObjectOutputStream.writeObject(java.security.CodeSource) 2410 2411 Object objToSave = null; 2412 Object objLoaded = null; 2413 2414 try { 2415 objToSave = null; 2416 try { 2417 objToSave = new java.security.CodeSource(new java.net.URL( 2418 "http://localhost/a.txt"), 2419 (Certificate[])null); 2420 } catch (Exception e) { 2421 fail("Exception creating object : " + e.getMessage()); 2422 } 2423 if (DEBUG) 2424 System.out.println("Obj = " + objToSave); 2425 objLoaded = dumpAndReload(objToSave); 2426 2427 // Has to have worked 2428 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2429 } catch (IOException e) { 2430 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2431 } catch (ClassNotFoundException e) { 2432 fail("ClassNotFoundException reading Object type: " 2433 + e.getMessage()); 2434 } catch (Error err) { 2435 System.out.println("Error when obj = " + objToSave); 2436 // err.printStackTrace(); 2437 throw err; 2438 } 2439 2440 } 2441 2442 @TestTargetNew( 2443 level = TestLevel.COMPLETE, 2444 notes = "Verifies serialization.", 2445 method = "!Serialization", 2446 args = {} 2447 ) 2448 public void test_writeObject_Collections_SynchronizedCollection() { 2449 // Test for method void 2450 // java.io.ObjectOutputStream.writeObject(java.util.Collections.SynchronizedCollection) 2451 2452 Object objToSave = null; 2453 Object objLoaded = null; 2454 2455 try { 2456 objToSave = java.util.Collections.synchronizedCollection(SET); 2457 if (DEBUG) 2458 System.out.println("Obj = " + objToSave); 2459 objLoaded = dumpAndReload(objToSave); 2460 2461 // Has to have worked 2462 boolean equals; 2463 equals = ((java.util.Collection) objToSave).size() == ((java.util.Collection) objLoaded) 2464 .size(); 2465 if (equals) { 2466 java.util.Iterator iter1 = ((java.util.Collection) objToSave) 2467 .iterator(), iter2 = ((java.util.Collection) objLoaded) 2468 .iterator(); 2469 while (iter1.hasNext()) 2470 equals = equals && iter1.next().equals(iter2.next()); 2471 } 2472 assertTrue(MSG_TEST_FAILED + objToSave, equals); 2473 } catch (IOException e) { 2474 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2475 } catch (ClassNotFoundException e) { 2476 fail("ClassNotFoundException reading Object type: " 2477 + e.getMessage()); 2478 } catch (Error err) { 2479 System.out.println("Error when obj = " + objToSave); 2480 // err.printStackTrace(); 2481 throw err; 2482 } 2483 2484 } 2485 2486 @TestTargetNew( 2487 level = TestLevel.COMPLETE, 2488 notes = "Verifies serialization.", 2489 method = "!Serialization", 2490 args = {} 2491 ) 2492 public void test_writeObject_Permission() { 2493 // Test for method void 2494 // java.io.ObjectOutputStream.writeObject(java.security.Permission) 2495 2496 Object objToSave = null; 2497 Object objLoaded = null; 2498 2499 try { 2500 objToSave = null; 2501 objToSave = new java.security.Permission("test") { 2502 public boolean equals(Object p1) { 2503 if (!(p1 instanceof java.security.Permission)) 2504 return false; 2505 return getName().equals( 2506 ((java.security.Permission) p1).getName()); 2507 } 2508 2509 public int hashCode() { 2510 return 0; 2511 } 2512 2513 public String getActions() { 2514 return null; 2515 } 2516 2517 public boolean implies(java.security.Permission p1) { 2518 return false; 2519 } 2520 }; 2521 if (DEBUG) 2522 System.out.println("Obj = " + objToSave); 2523 objLoaded = dumpAndReload(objToSave); 2524 2525 // Has to have worked 2526 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2527 } catch (IOException e) { 2528 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2529 } catch (ClassNotFoundException e) { 2530 fail("ClassNotFoundException reading Object type: " 2531 + e.getMessage()); 2532 } catch (Error err) { 2533 System.out.println("Error when obj = " + objToSave); 2534 // err.printStackTrace(); 2535 throw err; 2536 } 2537 2538 } 2539 2540 @TestTargetNew( 2541 level = TestLevel.COMPLETE, 2542 notes = "Verifies serialization.", 2543 method = "!Serialization", 2544 args = {} 2545 ) 2546 public void test_writeObject_Random() { 2547 // Test for method void 2548 // java.io.ObjectOutputStream.writeObject(java.util.Random) 2549 2550 Object objToSave = null; 2551 Object objLoaded = null; 2552 2553 try { 2554 objToSave = new java.util.Random(107L); 2555 if (DEBUG) 2556 System.out.println("Obj = " + objToSave); 2557 objLoaded = dumpAndReload(objToSave); 2558 2559 // Has to have worked 2560 boolean equals; 2561 equals = ((java.util.Random) objToSave).nextInt() == ((java.util.Random) objLoaded) 2562 .nextInt(); 2563 assertTrue(MSG_TEST_FAILED + objToSave, equals); 2564 } catch (IOException e) { 2565 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2566 } catch (ClassNotFoundException e) { 2567 fail("ClassNotFoundException reading Object type: " 2568 + e.getMessage()); 2569 } catch (Error err) { 2570 System.out.println("Error when obj = " + objToSave); 2571 // err.printStackTrace(); 2572 throw err; 2573 } 2574 2575 } 2576 2577 @TestTargetNew( 2578 level = TestLevel.COMPLETE, 2579 notes = "Verifies serialization.", 2580 method = "!Serialization", 2581 args = {} 2582 ) 2583 public void test_writeObject_GuardedObject() { 2584 // Test for method void 2585 // java.io.ObjectOutputStream.writeObject(java.security.GuardedObject) 2586 2587 Object objToSave = null; 2588 Object objLoaded = null; 2589 2590 try { 2591 objToSave = new java.security.GuardedObject("Test Object", 2592 new GuardImplementation()); 2593 if (DEBUG) 2594 System.out.println("Obj = " + objToSave); 2595 objLoaded = dumpAndReload(objToSave); 2596 2597 // Has to have worked 2598 boolean equals; 2599 equals = ((java.security.GuardedObject) objToSave).getObject() 2600 .equals( 2601 ((java.security.GuardedObject) objLoaded) 2602 .getObject()); 2603 assertTrue(MSG_TEST_FAILED + objToSave, equals); 2604 } catch (IOException e) { 2605 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2606 } catch (ClassNotFoundException e) { 2607 fail("ClassNotFoundException reading Object type: " 2608 + e.getMessage()); 2609 } catch (Error err) { 2610 System.out.println("Error when obj = " + objToSave); 2611 // err.printStackTrace(); 2612 throw err; 2613 } 2614 2615 } 2616 2617 // TODO : Reintroduce when we have a working security implementation 2618 // public void test_writeObject_KeyPair() { 2619 // // Test for method void 2620 // // java.io.ObjectOutputStream.writeObject(java.security.GuardedObject) 2621 // 2622 // Object objToSave = null; 2623 // Object objLoaded = null; 2624 // 2625 // try { 2626 // objToSave = new java.security.KeyPair(null, null); 2627 // if (DEBUG) 2628 // System.out.println("Obj = " + objToSave); 2629 // objLoaded = dumpAndReload(objToSave); 2630 // 2631 // // Has to have worked 2632 // boolean equals; 2633 // equals = true; 2634 // assertTrue(MSG_TEST_FAILED + objToSave, equals); 2635 // } catch (IOException e) { 2636 // fail("IOException serializing " + objToSave + " : " 2637 // + e.getMessage()); 2638 // } catch (ClassNotFoundException e) { 2639 // fail("ClassNotFoundException reading Object type : " + e.getMessage()); 2640 // } catch (Error err) { 2641 // System.out.println("Error when obj = " + objToSave); 2642 // // err.printStackTrace(); 2643 // throw err; 2644 // } 2645 // } 2646 2647 static class MyInvocationHandler implements InvocationHandler, Serializable { 2648 public Object invoke(Object proxy, Method method, Object[] args) 2649 throws Throwable { 2650 if (method.getName().equals("equals")) 2651 return new Boolean(proxy == args[0]); 2652 if (method.getName().equals("array")) 2653 return new int[] { (int) ((long[]) args[0])[1], -1 }; 2654 if (method.getName().equals("string")) { 2655 if ("error".equals(args[0])) 2656 throw new ArrayStoreException(); 2657 if ("any".equals(args[0])) 2658 throw new IllegalAccessException(); 2659 } 2660 return null; 2661 } 2662 } 2663 2664 @TestTargetNew( 2665 level = TestLevel.COMPLETE, 2666 notes = "Verifies serialization.", 2667 method = "!Serialization", 2668 args = {} 2669 ) 2670 @KnownFailure("Fails in CTS but passes under run-core-tests") 2671 public void test_writeObject_Proxy() 2672 throws ClassNotFoundException, IOException { 2673 2674 // serialize class 2675 Class<?> proxyClass = Proxy.getProxyClass(Support_Proxy_I1.class 2676 .getClassLoader(), new Class[]{Support_Proxy_I1.class}); 2677 Class<?> proxyClassOut = (Class<?>) dumpAndReload(proxyClass); 2678 2679 assertTrue(Proxy.isProxyClass(proxyClassOut)); 2680 assertEquals(Collections.<Class>singletonList(Support_Proxy_I1.class), 2681 Arrays.asList(proxyClassOut.getInterfaces())); 2682 2683 // serialize instance 2684 InvocationHandler handler = new MyInvocationHandler(); 2685 Object proxyInstance = Proxy.newProxyInstance(Support_Proxy_I1.class 2686 .getClassLoader(), new Class[] { Support_Proxy_I1.class }, 2687 handler); 2688 2689 Object proxyInstanceOut = dumpAndReload(proxyInstance); 2690 assertEquals(MyInvocationHandler.class, 2691 Proxy.getInvocationHandler(proxyInstanceOut).getClass()); 2692 } 2693 2694 @TestTargetNew( 2695 level = TestLevel.COMPLETE, 2696 notes = "Verifies serialization.", 2697 method = "!Serialization", 2698 args = {} 2699 ) 2700 public void test_writeObject_URI() { 2701 // Test for method void 2702 // java.io.ObjectOutputStream.writeObject(java.net.URI) 2703 2704 Object objToSave = null; 2705 Object objLoaded = null; 2706 2707 try { 2708 try { 2709 objToSave = new URI[] { 2710 // single arg constructor 2711 new URI( 2712 "http://user%60%20info@host/a%20path?qu%60%20ery#fr%5E%20ag"), 2713 // escaped octets for illegal chars 2714 new URI( 2715 "http://user%C3%9F%C2%A3info@host:80/a%E2%82%ACpath?qu%C2%A9%C2%AEery#fr%C3%A4%C3%A8g"), 2716 // escaped octets for unicode chars 2717 new URI( 2718 "ascheme://user\u00DF\u00A3info@host:0/a\u20ACpath?qu\u00A9\u00AEery#fr\u00E4\u00E8g"), 2719 // multiple arg constructors 2720 new URI("http", "user%60%20info", "host", 80, 2721 "/a%20path", "qu%60%20ery", "fr%5E%20ag"), 2722 // escaped octets for illegal 2723 new URI("http", "user%C3%9F%C2%A3info", "host", -1, 2724 "/a%E2%82%ACpath", "qu%C2%A9%C2%AEery", 2725 "fr%C3%A4%C3%A8g"), 2726 // escaped octets for unicode 2727 new URI("ascheme", "user\u00DF\u00A3info", "host", 80, 2728 "/a\u20ACpath", "qu\u00A9\u00AEery", 2729 "fr\u00E4\u00E8g"), 2730 new URI("http", "user` info", "host", 81, "/a path", 2731 "qu` ery", "fr^ ag"), // illegal chars 2732 new URI("http", "user%info", "host", 0, "/a%path", 2733 "que%ry", "f%rag"), 2734 // % as illegal char, not escaped octet urls with 2735 // undefined components 2736 new URI("mailto", "user@domain.com", null), 2737 // no host, path, query or fragment 2738 new URI("../adirectory/file.html#"), 2739 // relative path with empty fragment; 2740 new URI("news", "comp.infosystems.www.servers.unix", 2741 null), 2742 new URI(null, null, null, "fragment"), 2743 // only fragment 2744 new URI("telnet://server.org"), // only host 2745 new URI("http://reg:istry?query"), 2746 // malformed hostname, therefore registry-based, 2747 // with query 2748 new URI("file:///c:/temp/calculate.pl?") 2749 // empty authority, non empty path, empty query 2750 }; 2751 } catch (URISyntaxException e) { 2752 fail("Unexpected Exception:" + e); 2753 } 2754 if (DEBUG) 2755 System.out.println("Obj = " + objToSave); 2756 objLoaded = dumpAndReload(objToSave); 2757 2758 // Has to have worked 2759 assertTrue(MSG_TEST_FAILED + objToSave, Arrays.equals( 2760 (URI[]) objToSave, (URI[]) objLoaded)); 2761 } catch (IOException e) { 2762 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2763 } catch (ClassNotFoundException e) { 2764 fail("ClassNotFoundException reading Object type: " 2765 + e.getMessage()); 2766 } catch (Error err) { 2767 System.out.println("Error when obj = " + objToSave); 2768 // err.printStackTrace(); 2769 throw err; 2770 } 2771 } 2772 2773 @TestTargetNew( 2774 level = TestLevel.COMPLETE, 2775 notes = "Verifies serialization.", 2776 method = "!Serialization", 2777 args = {} 2778 ) 2779 public void test_writeObject_URISyntaxException() { 2780 // Test for method void 2781 // java.io.ObjectOutputStream.writeObject(java.net.URISyntaxException) 2782 2783 URISyntaxException objToSave = null; 2784 URISyntaxException objLoaded = null; 2785 2786 try { 2787 objToSave = new URISyntaxException("str", "problem", 4); 2788 if (DEBUG) 2789 System.out.println("Obj = " + objToSave); 2790 objLoaded = (URISyntaxException) dumpAndReload(objToSave); 2791 2792 boolean equals = objToSave.getMessage().equals( 2793 objLoaded.getMessage()) 2794 && objToSave.getInput().equals(objLoaded.getInput()) 2795 && objToSave.getIndex() == objLoaded.getIndex() 2796 && objToSave.getReason().equals(objLoaded.getReason()); 2797 2798 // Has to have worked 2799 assertTrue(MSG_TEST_FAILED + objToSave, equals); 2800 } catch (IOException e) { 2801 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2802 } catch (ClassNotFoundException e) { 2803 fail("ClassNotFoundException reading Object type: " 2804 + e.getMessage()); 2805 } catch (Error err) { 2806 System.out.println("Error when obj = " + objToSave); 2807 // err.printStackTrace(); 2808 throw err; 2809 } 2810 2811 } 2812 2813 @TestTargetNew( 2814 level = TestLevel.COMPLETE, 2815 notes = "Verifies serialization.", 2816 method = "!Serialization", 2817 args = {} 2818 ) 2819 public void test_writeObject_Currency() { 2820 // Test for method void 2821 // java.io.ObjectOutputStream.writeObject(java.util.Currency) 2822 2823 Object objToSave = null; 2824 Object objLoaded = null; 2825 2826 try { 2827 objToSave = java.util.Currency.getInstance("AMD"); 2828 if (DEBUG) 2829 System.out.println("Obj = " + objToSave); 2830 objLoaded = dumpAndReload(objToSave); 2831 2832 // Has to have worked 2833 // we need same instance for the same currency code 2834 assertTrue(MSG_TEST_FAILED + objToSave, objToSave == objToSave); 2835 } catch (IOException e) { 2836 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2837 } catch (ClassNotFoundException e) { 2838 fail("ClassNotFoundException reading Object type: " 2839 + e.getMessage()); 2840 } catch (Error err) { 2841 System.out.println("Error when obj = " + objToSave); 2842 // err.printStackTrace(); 2843 throw err; 2844 } 2845 } 2846 2847 @TestTargetNew( 2848 level = TestLevel.COMPLETE, 2849 notes = "Verifies serialization.", 2850 method = "!Serialization", 2851 args = {} 2852 ) 2853 @KnownFailure("deserialization of a date fomat field seems to fail") 2854 public void test_writeObject_DateFormat_Field() { 2855 // Test for method void 2856 // java.io.ObjectOutputStream.writeObject(java.text.DateFormat.Field) 2857 2858 DateFormat.Field[] objToSave = null; 2859 DateFormat.Field[] objLoaded = null; 2860 2861 try { 2862 objToSave = new DateFormat.Field[] { DateFormat.Field.AM_PM, 2863 DateFormat.Field.DAY_OF_MONTH, DateFormat.Field.ERA, 2864 DateFormat.Field.HOUR0, DateFormat.Field.HOUR1, 2865 DateFormat.Field.HOUR_OF_DAY0, 2866 DateFormat.Field.HOUR_OF_DAY1, DateFormat.Field.TIME_ZONE, 2867 DateFormat.Field.YEAR, 2868 DateFormat.Field.DAY_OF_WEEK_IN_MONTH }; 2869 if (DEBUG) 2870 System.out.println("Obj = " + objToSave); 2871 2872 objLoaded = (DateFormat.Field[]) dumpAndReload(objToSave); 2873 2874 // Has to have worked 2875 // we need same instances for the same field names 2876 for (int i = 0; i < objToSave.length; i++) { 2877 assertTrue(MSG_TEST_FAILED + objToSave[i], 2878 objToSave[i] == objLoaded[i]); 2879 } 2880 } catch (IOException e) { 2881 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2882 } catch (ClassNotFoundException e) { 2883 fail("ClassNotFoundException reading Object type: " 2884 + e.getMessage()); 2885 } catch (Error err) { 2886 System.out.println("Error when obj = " + objToSave); 2887 // err.printStackTrace(); 2888 throw err; 2889 } 2890 } 2891 2892 @TestTargetNew( 2893 level = TestLevel.COMPLETE, 2894 notes = "Verifies serialization.", 2895 method = "!Serialization", 2896 args = {} 2897 ) 2898 @KnownFailure("deserialization of a number fomat field seems to fail") 2899 public void test_writeObject_NumberFormat_Field() { 2900 // Test for method void 2901 // java.io.ObjectOutputStream.writeObject(java.text.NumberFormat.Field) 2902 2903 NumberFormat.Field[] objToSave = null; 2904 NumberFormat.Field[] objLoaded = null; 2905 2906 try { 2907 objToSave = new NumberFormat.Field[] { NumberFormat.Field.CURRENCY, 2908 NumberFormat.Field.DECIMAL_SEPARATOR, 2909 NumberFormat.Field.EXPONENT, 2910 NumberFormat.Field.EXPONENT_SIGN, 2911 NumberFormat.Field.EXPONENT_SYMBOL, 2912 NumberFormat.Field.FRACTION, 2913 NumberFormat.Field.GROUPING_SEPARATOR, 2914 NumberFormat.Field.INTEGER, NumberFormat.Field.PERCENT, 2915 NumberFormat.Field.PERMILLE, NumberFormat.Field.SIGN }; 2916 if (DEBUG) 2917 System.out.println("Obj = " + objToSave); 2918 2919 objLoaded = (NumberFormat.Field[]) dumpAndReload(objToSave); 2920 2921 // Has to have worked 2922 // we need same instances for the same field names 2923 for (int i = 0; i < objToSave.length; i++) { 2924 assertTrue(MSG_TEST_FAILED + objToSave[i], 2925 objToSave[i] == objLoaded[i]); 2926 } 2927 } catch (IOException e) { 2928 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2929 } catch (ClassNotFoundException e) { 2930 fail("ClassNotFoundException reading Object type: " 2931 + e.getMessage()); 2932 } catch (Error err) { 2933 System.out.println("Error when obj = " + objToSave); 2934 // err.printStackTrace(); 2935 throw err; 2936 } 2937 } 2938 2939 @TestTargetNew( 2940 level = TestLevel.COMPLETE, 2941 notes = "Verifies serialization.", 2942 method = "!Serialization", 2943 args = {} 2944 ) 2945 public void test_writeObject_MessageFormat_Field() { 2946 // Test for method void 2947 // java.io.ObjectOutputStream.writeObject(java.text.MessageFormat.Field) 2948 2949 Object objToSave = null; 2950 Object objLoaded = null; 2951 2952 try { 2953 objToSave = MessageFormat.Field.ARGUMENT; 2954 if (DEBUG) 2955 System.out.println("Obj = " + objToSave); 2956 2957 objLoaded = dumpAndReload(objToSave); 2958 2959 // Has to have worked 2960 // we need same instance for the same field name 2961 assertTrue(MSG_TEST_FAILED + objToSave, objToSave == objLoaded); 2962 } catch (IOException e) { 2963 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2964 } catch (ClassNotFoundException e) { 2965 fail("ClassNotFoundException reading Object type: " 2966 + e.getMessage()); 2967 } catch (Error err) { 2968 System.out.println("Error when obj = " + objToSave); 2969 // err.printStackTrace(); 2970 throw err; 2971 } 2972 } 2973 2974 @TestTargetNew( 2975 level = TestLevel.COMPLETE, 2976 notes = "Verifies serialization.", 2977 method = "!Serialization", 2978 args = {} 2979 ) 2980 public void test_writeObject_LinkedHashMap() { 2981 // Test for method void 2982 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2983 2984 Object objToSave = null; 2985 Object objLoaded; 2986 2987 try { 2988 objToSave = LINKEDMAP; 2989 if (DEBUG) 2990 System.out.println("Obj = " + objToSave); 2991 objLoaded = dumpAndReload(objToSave); 2992 // Has to have worked 2993 assertTrue(MSG_TEST_FAILED + objToSave, LINKEDMAP.equals(objLoaded)); 2994 2995 Map mapLoaded = (Map) objLoaded; 2996 Iterator loadedIterator = mapLoaded.keySet().iterator(); 2997 Iterator iterator = LINKEDMAP.keySet().iterator(); 2998 while (loadedIterator.hasNext()) { 2999 assertTrue("invalid iterator order", loadedIterator.next() 3000 .equals(iterator.next())); 3001 } 3002 assertTrue("invalid iterator size", !iterator.hasNext()); 3003 3004 loadedIterator = mapLoaded.entrySet().iterator(); 3005 iterator = LINKEDMAP.entrySet().iterator(); 3006 while (loadedIterator.hasNext()) { 3007 assertTrue("invalid entry set iterator order", loadedIterator 3008 .next().equals(iterator.next())); 3009 } 3010 assertTrue("invalid entry set iterator size", !iterator.hasNext()); 3011 3012 } catch (IOException e) { 3013 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 3014 } catch (ClassNotFoundException e) { 3015 fail("ClassNotFoundException reading Object type: " 3016 + e.getMessage()); 3017 } catch (Error err) { 3018 System.out.println("Error when obj = " + objToSave); 3019 // err.printStackTrace(); 3020 throw err; 3021 } 3022 } 3023 3024 @TestTargetNew( 3025 level = TestLevel.COMPLETE, 3026 notes = "Verifies serialization.", 3027 method = "!Serialization", 3028 args = {} 3029 ) 3030 public void test_writeObject_LinkedHashSet() { 3031 // Test for method void 3032 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 3033 3034 Object objToSave = null; 3035 Object objLoaded; 3036 3037 try { 3038 objToSave = LINKEDSET; 3039 if (DEBUG) 3040 System.out.println("Obj = " + objToSave); 3041 objLoaded = dumpAndReload(objToSave); 3042 // Has to have worked 3043 assertTrue(MSG_TEST_FAILED + objToSave, LINKEDSET.equals(objLoaded)); 3044 3045 } catch (IOException e) { 3046 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 3047 } catch (ClassNotFoundException e) { 3048 fail("ClassNotFoundException reading Object type: " 3049 + e.getMessage()); 3050 } catch (Error err) { 3051 System.out.println("Error when obj = " + objToSave); 3052 // err.printStackTrace(); 3053 throw err; 3054 } 3055 } 3056 3057 @TestTargetNew( 3058 level = TestLevel.COMPLETE, 3059 notes = "Verifies serialization.", 3060 method = "!Serialization", 3061 args = {} 3062 ) 3063 public void test_writeObject_IdentityHashMap() { 3064 // Test for method void 3065 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 3066 3067 IdentityHashMap objToSave = null; 3068 IdentityHashMap objLoaded; 3069 3070 try { 3071 objToSave = IDENTITYMAP; 3072 if (DEBUG) 3073 System.out.println("Obj = " + objToSave); 3074 objLoaded = (IdentityHashMap) dumpAndReload(objToSave); 3075 // Has to have worked 3076 3077 // a serialized identity hash map will not be equal to its original 3078 // because it is an "identity" mapping, 3079 // so we simply check for the usual meaning of equality 3080 3081 assertEquals( 3082 "Loaded IdentityHashMap is not of the same size as the saved one.", 3083 objToSave.size(), objLoaded.size()); 3084 HashMap duplicateSaved = new HashMap(); 3085 duplicateSaved.putAll(objToSave); 3086 HashMap duplicateLoaded = new HashMap(); 3087 duplicateLoaded.putAll(objLoaded); 3088 assertTrue(MSG_TEST_FAILED + duplicateSaved, duplicateSaved 3089 .equals(duplicateLoaded)); 3090 } catch (IOException e) { 3091 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 3092 } catch (ClassNotFoundException e) { 3093 fail("ClassNotFoundException reading Object type: " 3094 + e.getMessage()); 3095 } catch (Error err) { 3096 System.out.println("Error when obj = " + objToSave); 3097 // err.printStackTrace(); 3098 throw err; 3099 } 3100 } 3101} 3102