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