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