SerializationStressTest4.java revision 470c1f75f26d58eb33bbaa0d7e08ed2723f25647
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.getByName("127.0.0.1"); 1648 if (DEBUG) 1649 System.out.println("Obj = " + objToSave); 1650 objLoaded = dumpAndReload(objToSave); 1651 1652 // Has to have worked 1653 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1654 } catch (IOException e) { 1655 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1656 } catch (ClassNotFoundException e) { 1657 fail("ClassNotFoundException reading Object type: " 1658 + e.getMessage()); 1659 } catch (Error err) { 1660 System.out.println("Error when obj = " + objToSave); 1661 // err.printStackTrace(); 1662 throw err; 1663 } 1664 1665 } 1666 1667 public void test_writeObject_Inet6Address() { 1668 // Test for method void 1669 // java.io.ObjectOutputStream.writeObject(java.net.Inet6Address) 1670 1671 Object objToSave = null; 1672 Object objLoaded = null; 1673 1674 try { 1675 objToSave = java.net.Inet6Address.getByName("fe80::20d:60ff:fe24:7410"); 1676 if (DEBUG) 1677 System.out.println("Obj = " + objToSave); 1678 objLoaded = dumpAndReload(objToSave); 1679 1680 // Has to have worked 1681 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1682 1683 } catch (IOException e) { 1684 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1685 } catch (ClassNotFoundException e) { 1686 fail("ClassNotFoundException reading Object type: " 1687 + e.getMessage()); 1688 } catch (Error err) { 1689 System.out.println("Error when obj = " + objToSave); 1690 // err.printStackTrace(); 1691 throw err; 1692 } 1693 1694 } 1695 1696 public void test_writeObject_RuntimePermission() { 1697 // Test for method void 1698 // java.io.ObjectOutputStream.writeObject(java.lang.RuntimePermission) 1699 1700 Object objToSave = null; 1701 Object objLoaded = null; 1702 1703 try { 1704 objToSave = new java.lang.RuntimePermission("TestSerialization", 1705 "Test"); 1706 if (DEBUG) 1707 System.out.println("Obj = " + objToSave); 1708 objLoaded = dumpAndReload(objToSave); 1709 1710 // Has to have worked 1711 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1712 } catch (IOException e) { 1713 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1714 } catch (ClassNotFoundException e) { 1715 fail("ClassNotFoundException reading Object type: " 1716 + e.getMessage()); 1717 } catch (Error err) { 1718 System.out.println("Error when obj = " + objToSave); 1719 // err.printStackTrace(); 1720 throw err; 1721 } 1722 1723 } 1724 1725 @SuppressWarnings("unchecked") 1726 public void test_writeObject_Permissions() { 1727 // Test for method void 1728 // java.io.ObjectOutputStream.writeObject(java.security.Permissions) 1729 1730 Object objToSave = null; 1731 Object objLoaded = null; 1732 1733 try { 1734 objToSave = new java.security.Permissions(); 1735 ((java.security.Permissions) objToSave).add(new AllPermission()); 1736 if (DEBUG) 1737 System.out.println("Obj = " + objToSave); 1738 objLoaded = dumpAndReload(objToSave); 1739 1740 // Has to have worked 1741 boolean equals; 1742 Enumeration enum1 = ((java.security.PermissionCollection) objToSave) 1743 .elements(), enum2 = ((java.security.PermissionCollection) objLoaded) 1744 .elements(); 1745 java.util.Vector vec1 = new java.util.Vector(), vec2 = new java.util.Vector(); 1746 1747 while (enum1.hasMoreElements()) 1748 vec1.add(enum1.nextElement()); 1749 while (enum2.hasMoreElements()) 1750 vec2.add(enum2.nextElement()); 1751 1752 equals = vec1.size() == vec2.size(); 1753 if (equals) { 1754 int length = vec1.size(); 1755 Object[] perms1 = new Object[length], perms2 = new Object[length]; 1756 for (int i = 0; i < length; ++i) { 1757 perms1[i] = vec1.elementAt(i); 1758 perms2[i] = vec2.elementAt(i); 1759 } 1760 1761 Comparator comparator = new Comparator() { 1762 public int compare(Object o1, Object o2) { 1763 return o1.toString().compareTo(o2.toString()); 1764 } 1765 1766 public boolean equals(Object o1, Object o2) { 1767 return o1.toString().equals(o2.toString()); 1768 } 1769 }; 1770 1771 Arrays.sort(perms1, comparator); 1772 Arrays.sort(perms2, comparator); 1773 1774 for (int i = 0; i < length && equals; ++i) 1775 equals = perms1[i].equals(perms2[i]); 1776 } 1777 1778 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1779 } catch (IOException e) { 1780 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1781 } catch (ClassNotFoundException e) { 1782 fail("ClassNotFoundException reading Object type: " 1783 + e.getMessage()); 1784 } catch (Error err) { 1785 System.out.println("Error when obj = " + objToSave); 1786 // err.printStackTrace(); 1787 throw err; 1788 } 1789 1790 } 1791 1792 public void test_writeObject_Date() { 1793 // Test for method void 1794 // java.io.ObjectOutputStream.writeObject(java.util.Date) 1795 1796 Object objToSave = null; 1797 Object objLoaded = null; 1798 1799 try { 1800 // Thu Feb 01 01:01:01 EST 2001 1801 objToSave = new java.util.Date(981007261000L); 1802 if (DEBUG) 1803 System.out.println("Obj = " + objToSave); 1804 objLoaded = dumpAndReload(objToSave); 1805 1806 // Has to have worked 1807 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1808 } catch (IOException e) { 1809 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1810 } catch (ClassNotFoundException e) { 1811 fail("ClassNotFoundException reading Object type: " 1812 + e.getMessage()); 1813 } catch (Error err) { 1814 System.out.println("Error when obj = " + objToSave); 1815 // err.printStackTrace(); 1816 throw err; 1817 } 1818 1819 } 1820 1821 public void test_writeObject_Float() { 1822 // Test for method void 1823 // java.io.ObjectOutputStream.writeObject(java.lang.Float) 1824 1825 Object objToSave = null; 1826 Object objLoaded = null; 1827 1828 try { 1829 objToSave = new java.lang.Float(1.23f); 1830 if (DEBUG) 1831 System.out.println("Obj = " + objToSave); 1832 objLoaded = dumpAndReload(objToSave); 1833 1834 // Has to have worked 1835 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1836 } catch (IOException e) { 1837 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1838 } catch (ClassNotFoundException e) { 1839 fail("ClassNotFoundException reading Object type: " 1840 + e.getMessage()); 1841 } catch (Error err) { 1842 System.out.println("Error when obj = " + objToSave); 1843 // err.printStackTrace(); 1844 throw err; 1845 } 1846 1847 } 1848 1849 public void test_writeObject_SecurityPermission() { 1850 // Test for method void 1851 // java.io.ObjectOutputStream.writeObject(java.security.SecurityPermission) 1852 1853 Object objToSave = null; 1854 Object objLoaded = null; 1855 1856 try { 1857 objToSave = new java.security.SecurityPermission( 1858 "TestSerialization", "Test"); 1859 if (DEBUG) 1860 System.out.println("Obj = " + objToSave); 1861 objLoaded = dumpAndReload(objToSave); 1862 1863 // Has to have worked 1864 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1865 } catch (IOException e) { 1866 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1867 } catch (ClassNotFoundException e) { 1868 fail("ClassNotFoundException reading Object type: " 1869 + e.getMessage()); 1870 } catch (Error err) { 1871 System.out.println("Error when obj = " + objToSave); 1872 // err.printStackTrace(); 1873 throw err; 1874 } 1875 1876 } 1877 1878 public void test_writeObject_SocketPermission_SocketPermissionCollection() { 1879 // Test for method void 1880 // java.io.ObjectOutputStream.writeObject(java.net.SocketPermission.SocketPermissionCollection) 1881 1882 Object objToSave = null; 1883 Object objLoaded = null; 1884 1885 try { 1886 objToSave = (new java.net.SocketPermission("www.yahoo.com", 1887 "connect")).newPermissionCollection(); 1888 ((java.security.PermissionCollection) objToSave) 1889 .add(new java.net.SocketPermission("www.yahoo.com", 1890 "connect")); 1891 if (DEBUG) 1892 System.out.println("Obj = " + objToSave); 1893 objLoaded = dumpAndReload(objToSave); 1894 1895 // Has to have worked 1896 boolean equals; 1897 Enumeration enum1 = ((java.security.PermissionCollection) objToSave) 1898 .elements(), enum2 = ((java.security.PermissionCollection) objLoaded) 1899 .elements(); 1900 1901 equals = true; 1902 while (enum1.hasMoreElements() && equals) { 1903 if (enum2.hasMoreElements()) 1904 equals = enum1.nextElement().equals(enum2.nextElement()); 1905 else 1906 equals = false; 1907 } 1908 1909 if (equals) 1910 equals = !enum2.hasMoreElements(); 1911 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1912 } catch (IOException e) { 1913 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1914 } catch (ClassNotFoundException e) { 1915 fail("ClassNotFoundException reading Object type: " 1916 + e.getMessage()); 1917 } catch (Error err) { 1918 System.out.println("Error when obj = " + objToSave); 1919 // err.printStackTrace(); 1920 throw err; 1921 } 1922 1923 } 1924 1925 public void test_writeObject_Stack() { 1926 // Test for method void 1927 // java.io.ObjectOutputStream.writeObject(java.util.Stack) 1928 1929 Object objToSave = null; 1930 Object objLoaded = null; 1931 1932 try { 1933 objToSave = new java.util.Stack(); 1934 ((Stack) objToSave).push("String 1"); 1935 ((Stack) objToSave).push("String 2"); 1936 if (DEBUG) 1937 System.out.println("Obj = " + objToSave); 1938 objLoaded = dumpAndReload(objToSave); 1939 1940 // Has to have worked 1941 boolean equals; 1942 equals = true; 1943 while (!((java.util.Stack) objToSave).empty() && equals) { 1944 if (!((java.util.Stack) objLoaded).empty()) 1945 equals = ((java.util.Stack) objToSave).pop().equals( 1946 ((java.util.Stack) objLoaded).pop()); 1947 else 1948 equals = false; 1949 } 1950 1951 if (equals) 1952 equals = ((java.util.Stack) objLoaded).empty(); 1953 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1954 } catch (IOException e) { 1955 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1956 } catch (ClassNotFoundException e) { 1957 fail("ClassNotFoundException reading Object type: " 1958 + e.getMessage()); 1959 } catch (Error err) { 1960 System.out.println("Error when obj = " + objToSave); 1961 // err.printStackTrace(); 1962 throw err; 1963 } 1964 1965 } 1966 1967 public void test_writeObject_DecimalFormatSymbols() { 1968 // Test for method void 1969 // java.io.ObjectOutputStream.writeObject(java.text.DecimalFormatSymbols) 1970 1971 Object objToSave = null; 1972 Object objLoaded = null; 1973 1974 try { 1975 objToSave = new java.text.DecimalFormatSymbols(Locale.CHINESE); 1976 if (DEBUG) 1977 System.out.println("Obj = " + objToSave); 1978 objLoaded = dumpAndReload(objToSave); 1979 1980 // Has to have worked 1981 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1982 } catch (IOException e) { 1983 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1984 } catch (ClassNotFoundException e) { 1985 fail("ClassNotFoundException reading Object type: " 1986 + e.getMessage()); 1987 } catch (Error err) { 1988 System.out.println("Error when obj = " + objToSave); 1989 // err.printStackTrace(); 1990 throw err; 1991 } 1992 1993 } 1994 1995 public void test_writeObject_NetPermission() { 1996 // Test for method void 1997 // java.io.ObjectOutputStream.writeObject(java.net.NetPermission) 1998 1999 Object objToSave = null; 2000 Object objLoaded = null; 2001 2002 try { 2003 objToSave = new java.net.NetPermission("TestSerialization", "Test"); 2004 if (DEBUG) 2005 System.out.println("Obj = " + objToSave); 2006 objLoaded = dumpAndReload(objToSave); 2007 2008 // Has to have worked 2009 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2010 } catch (IOException e) { 2011 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2012 } catch (ClassNotFoundException e) { 2013 fail("ClassNotFoundException reading Object type: " 2014 + e.getMessage()); 2015 } catch (Error err) { 2016 System.out.println("Error when obj = " + objToSave); 2017 // err.printStackTrace(); 2018 throw err; 2019 } 2020 } 2021 2022 public void test_writeObject_AttributedCharacterIterator_Attribute() { 2023 // Test for method void 2024 // java.io.ObjectOutputStream.writeObject(java.text.AttributedCharacterIterator.Attribute) 2025 2026 Object objToSave = null; 2027 Object objLoaded = null; 2028 2029 try { 2030 objToSave = java.text.AttributedCharacterIterator.Attribute.LANGUAGE; 2031 if (DEBUG) 2032 System.out.println("Obj = " + objToSave); 2033 objLoaded = dumpAndReload(objToSave); 2034 2035 // Has to have worked 2036 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2037 } catch (IOException e) { 2038 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2039 } catch (ClassNotFoundException e) { 2040 fail("ClassNotFoundException reading Object type: " 2041 + e.getMessage()); 2042 } catch (Error err) { 2043 System.out.println("Error when obj = " + objToSave); 2044 // err.printStackTrace(); 2045 throw err; 2046 } 2047 } 2048 2049 public void test_writeObject_Long() { 2050 // Test for method void 2051 // java.io.ObjectOutputStream.writeObject(java.lang.Long) 2052 2053 Object objToSave = null; 2054 Object objLoaded = null; 2055 2056 try { 2057 objToSave = new java.lang.Long(107L); 2058 if (DEBUG) 2059 System.out.println("Obj = " + objToSave); 2060 objLoaded = dumpAndReload(objToSave); 2061 2062 // Has to have worked 2063 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2064 } catch (IOException e) { 2065 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2066 } catch (ClassNotFoundException e) { 2067 fail("ClassNotFoundException reading Object type: " 2068 + e.getMessage()); 2069 } catch (Error err) { 2070 System.out.println("Error when obj = " + objToSave); 2071 // err.printStackTrace(); 2072 throw err; 2073 } 2074 2075 } 2076 2077 public void test_writeObject_CodeSource() { 2078 // Test for method void 2079 // java.io.ObjectOutputStream.writeObject(java.security.CodeSource) 2080 2081 Object objToSave = null; 2082 Object objLoaded = null; 2083 2084 try { 2085 objToSave = null; 2086 objToSave = new java.security.CodeSource(new java.net.URL( 2087 "http://localhost/a.txt"), 2088 (Certificate[])null); 2089 2090 if (DEBUG) 2091 System.out.println("Obj = " + objToSave); 2092 objLoaded = dumpAndReload(objToSave); 2093 2094 // Has to have worked 2095 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2096 } catch (IOException e) { 2097 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2098 } catch (ClassNotFoundException e) { 2099 fail("ClassNotFoundException reading Object type: " 2100 + e.getMessage()); 2101 } catch (Error err) { 2102 System.out.println("Error when obj = " + objToSave); 2103 // err.printStackTrace(); 2104 throw err; 2105 } 2106 2107 } 2108 2109 public void test_writeObject_Collections_SynchronizedCollection() { 2110 // Test for method void 2111 // java.io.ObjectOutputStream.writeObject(java.util.Collections.SynchronizedCollection) 2112 2113 Object objToSave = null; 2114 Object objLoaded = null; 2115 2116 try { 2117 objToSave = java.util.Collections.synchronizedCollection(SET); 2118 if (DEBUG) 2119 System.out.println("Obj = " + objToSave); 2120 objLoaded = dumpAndReload(objToSave); 2121 2122 // Has to have worked 2123 boolean equals; 2124 equals = ((java.util.Collection) objToSave).size() == ((java.util.Collection) objLoaded) 2125 .size(); 2126 if (equals) { 2127 java.util.Iterator iter1 = ((java.util.Collection) objToSave) 2128 .iterator(), iter2 = ((java.util.Collection) objLoaded) 2129 .iterator(); 2130 while (iter1.hasNext()) 2131 equals = equals && iter1.next().equals(iter2.next()); 2132 } 2133 assertTrue(MSG_TEST_FAILED + objToSave, equals); 2134 } catch (IOException e) { 2135 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2136 } catch (ClassNotFoundException e) { 2137 fail("ClassNotFoundException reading Object type: " 2138 + e.getMessage()); 2139 } catch (Error err) { 2140 System.out.println("Error when obj = " + objToSave); 2141 // err.printStackTrace(); 2142 throw err; 2143 } 2144 2145 } 2146 2147 public void test_writeObject_Permission() { 2148 // Test for method void 2149 // java.io.ObjectOutputStream.writeObject(java.security.Permission) 2150 2151 Object objToSave = null; 2152 Object objLoaded = null; 2153 2154 try { 2155 objToSave = null; 2156 objToSave = new java.security.Permission("test") { 2157 public boolean equals(Object p1) { 2158 if (!(p1 instanceof java.security.Permission)) 2159 return false; 2160 return getName().equals( 2161 ((java.security.Permission) p1).getName()); 2162 } 2163 2164 public int hashCode() { 2165 return 0; 2166 } 2167 2168 public String getActions() { 2169 return null; 2170 } 2171 2172 public boolean implies(java.security.Permission p1) { 2173 return false; 2174 } 2175 }; 2176 if (DEBUG) 2177 System.out.println("Obj = " + objToSave); 2178 objLoaded = dumpAndReload(objToSave); 2179 2180 // Has to have worked 2181 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 2182 } catch (IOException e) { 2183 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2184 } catch (ClassNotFoundException e) { 2185 fail("ClassNotFoundException reading Object type: " 2186 + e.getMessage()); 2187 } catch (Error err) { 2188 System.out.println("Error when obj = " + objToSave); 2189 // err.printStackTrace(); 2190 throw err; 2191 } 2192 2193 } 2194 2195 public void test_writeObject_Random() { 2196 // Test for method void 2197 // java.io.ObjectOutputStream.writeObject(java.util.Random) 2198 2199 Object objToSave = null; 2200 Object objLoaded = null; 2201 2202 try { 2203 objToSave = new java.util.Random(107L); 2204 if (DEBUG) 2205 System.out.println("Obj = " + objToSave); 2206 objLoaded = dumpAndReload(objToSave); 2207 2208 // Has to have worked 2209 boolean equals; 2210 equals = ((java.util.Random) objToSave).nextInt() == ((java.util.Random) objLoaded) 2211 .nextInt(); 2212 assertTrue(MSG_TEST_FAILED + objToSave, equals); 2213 } catch (IOException e) { 2214 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2215 } catch (ClassNotFoundException e) { 2216 fail("ClassNotFoundException reading Object type: " 2217 + e.getMessage()); 2218 } catch (Error err) { 2219 System.out.println("Error when obj = " + objToSave); 2220 // err.printStackTrace(); 2221 throw err; 2222 } 2223 2224 } 2225 2226 public void test_writeObject_GuardedObject() { 2227 // Test for method void 2228 // java.io.ObjectOutputStream.writeObject(java.security.GuardedObject) 2229 2230 Object objToSave = null; 2231 Object objLoaded = null; 2232 2233 try { 2234 objToSave = new java.security.GuardedObject("Test Object", 2235 new GuardImplementation()); 2236 if (DEBUG) 2237 System.out.println("Obj = " + objToSave); 2238 objLoaded = dumpAndReload(objToSave); 2239 2240 // Has to have worked 2241 boolean equals; 2242 equals = ((java.security.GuardedObject) objToSave).getObject() 2243 .equals( 2244 ((java.security.GuardedObject) objLoaded) 2245 .getObject()); 2246 assertTrue(MSG_TEST_FAILED + objToSave, equals); 2247 } catch (IOException e) { 2248 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2249 } catch (ClassNotFoundException e) { 2250 fail("ClassNotFoundException reading Object type: " 2251 + e.getMessage()); 2252 } catch (Error err) { 2253 System.out.println("Error when obj = " + objToSave); 2254 // err.printStackTrace(); 2255 throw err; 2256 } 2257 2258 } 2259 2260 // TODO : Reintroduce when we have a working security implementation 2261 // public void test_writeObject_KeyPair() { 2262 // // Test for method void 2263 // // java.io.ObjectOutputStream.writeObject(java.security.GuardedObject) 2264 // 2265 // Object objToSave = null; 2266 // Object objLoaded = null; 2267 // 2268 // try { 2269 // objToSave = new java.security.KeyPair(null, null); 2270 // if (DEBUG) 2271 // System.out.println("Obj = " + objToSave); 2272 // objLoaded = dumpAndReload(objToSave); 2273 // 2274 // // Has to have worked 2275 // boolean equals; 2276 // equals = true; 2277 // assertTrue(MSG_TEST_FAILED + objToSave, equals); 2278 // } catch (IOException e) { 2279 // fail("IOException serializing " + objToSave + " : " 2280 // + e.getMessage()); 2281 // } catch (ClassNotFoundException e) { 2282 // fail("ClassNotFoundException reading Object type : " + e.getMessage()); 2283 // } catch (Error err) { 2284 // System.out.println("Error when obj = " + objToSave); 2285 // // err.printStackTrace(); 2286 // throw err; 2287 // } 2288 // } 2289 2290 static class MyInvocationHandler implements InvocationHandler, Serializable { 2291 public Object invoke(Object proxy, Method method, Object[] args) 2292 throws Throwable { 2293 if (method.getName().equals("equals")) 2294 return new Boolean(proxy == args[0]); 2295 if (method.getName().equals("array")) 2296 return new int[] { (int) ((long[]) args[0])[1], -1 }; 2297 if (method.getName().equals("string")) { 2298 if ("error".equals(args[0])) 2299 throw new ArrayStoreException(); 2300 if ("any".equals(args[0])) 2301 throw new IllegalAccessException(); 2302 } 2303 return null; 2304 } 2305 } 2306 2307 public void test_writeObject_Proxy() { 2308 // Test for method void 2309 // java.io.ObjectOutputStream.writeObject(java.security.GuardedObject) 2310 2311 Object objToSave = null; 2312 Object objLoaded = null; 2313 2314 try { 2315 objToSave = Proxy.getProxyClass(Support_Proxy_I1.class 2316 .getClassLoader(), new Class[] { Support_Proxy_I1.class }); 2317 if (DEBUG) 2318 System.out.println("Obj = " + objToSave); 2319 objLoaded = dumpAndReload(objToSave); 2320 2321 assertTrue(MSG_TEST_FAILED + "not a proxy class", Proxy 2322 .isProxyClass((Class) objLoaded)); 2323 Class[] interfaces = ((Class) objLoaded).getInterfaces(); 2324 assertTrue(MSG_TEST_FAILED + "wrong interfaces length", 2325 interfaces.length == 1); 2326 assertTrue(MSG_TEST_FAILED + "wrong interface", 2327 interfaces[0] == Support_Proxy_I1.class); 2328 2329 InvocationHandler handler = new MyInvocationHandler(); 2330 objToSave = Proxy.newProxyInstance(Support_Proxy_I1.class 2331 .getClassLoader(), new Class[] { Support_Proxy_I1.class }, 2332 handler); 2333 if (DEBUG) 2334 System.out.println("Obj = " + objToSave); 2335 objLoaded = dumpAndReload(objToSave); 2336 2337 boolean equals = Proxy.getInvocationHandler(objLoaded).getClass() == MyInvocationHandler.class; 2338 assertTrue(MSG_TEST_FAILED + objToSave, equals); 2339 2340 } catch (IOException e) { 2341 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2342 } catch (ClassNotFoundException e) { 2343 fail("ClassNotFoundException reading Object type: " 2344 + e.getMessage()); 2345 } catch (Error err) { 2346 System.out.println("Error when obj = " + objToSave); 2347 // err.printStackTrace(); 2348 throw err; 2349 } 2350 } 2351 2352 public void test_writeObject_URI() { 2353 // Test for method void 2354 // java.io.ObjectOutputStream.writeObject(java.net.URI) 2355 2356 Object objToSave = null; 2357 Object objLoaded = null; 2358 2359 try { 2360 try { 2361 objToSave = new URI[] { 2362 // single arg constructor 2363 new URI( 2364 "http://user%60%20info@host/a%20path?qu%60%20ery#fr%5E%20ag"), 2365 // escaped octets for illegal chars 2366 new URI( 2367 "http://user%C3%9F%C2%A3info@host:80/a%E2%82%ACpath?qu%C2%A9%C2%AEery#fr%C3%A4%C3%A8g"), 2368 // escaped octets for unicode chars 2369 new URI( 2370 "ascheme://user\u00DF\u00A3info@host:0/a\u20ACpath?qu\u00A9\u00AEery#fr\u00E4\u00E8g"), 2371 // multiple arg constructors 2372 new URI("http", "user%60%20info", "host", 80, 2373 "/a%20path", "qu%60%20ery", "fr%5E%20ag"), 2374 // escaped octets for illegal 2375 new URI("http", "user%C3%9F%C2%A3info", "host", -1, 2376 "/a%E2%82%ACpath", "qu%C2%A9%C2%AEery", 2377 "fr%C3%A4%C3%A8g"), 2378 // escaped octets for unicode 2379 new URI("ascheme", "user\u00DF\u00A3info", "host", 80, 2380 "/a\u20ACpath", "qu\u00A9\u00AEery", 2381 "fr\u00E4\u00E8g"), 2382 new URI("http", "user` info", "host", 81, "/a path", 2383 "qu` ery", "fr^ ag"), // illegal chars 2384 new URI("http", "user%info", "host", 0, "/a%path", 2385 "que%ry", "f%rag"), 2386 // % as illegal char, not escaped octet urls with 2387 // undefined components 2388 new URI("mailto", "user@domain.com", null), 2389 // no host, path, query or fragment 2390 new URI("../adirectory/file.html#"), 2391 // relative path with empty fragment; 2392 new URI("news", "comp.infosystems.www.servers.unix", 2393 null), 2394 new URI(null, null, null, "fragment"), 2395 // only fragment 2396 new URI("telnet://server.org"), // only host 2397 new URI("http://reg:istry?query"), 2398 // malformed hostname, therefore registry-based, 2399 // with query 2400 new URI("file:///c:/temp/calculate.pl?") 2401 // empty authority, non empty path, empty query 2402 }; 2403 } catch (URISyntaxException e) { 2404 fail("Unexpected Exception:" + e); 2405 } 2406 if (DEBUG) 2407 System.out.println("Obj = " + objToSave); 2408 objLoaded = dumpAndReload(objToSave); 2409 2410 // Has to have worked 2411 assertTrue(MSG_TEST_FAILED + objToSave, Arrays.equals( 2412 (URI[]) objToSave, (URI[]) objLoaded)); 2413 } catch (IOException e) { 2414 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2415 } catch (ClassNotFoundException e) { 2416 fail("ClassNotFoundException reading Object type: " 2417 + e.getMessage()); 2418 } catch (Error err) { 2419 System.out.println("Error when obj = " + objToSave); 2420 // err.printStackTrace(); 2421 throw err; 2422 } 2423 } 2424 2425 public void test_writeObject_URISyntaxException() { 2426 // Test for method void 2427 // java.io.ObjectOutputStream.writeObject(java.net.URISyntaxException) 2428 2429 URISyntaxException objToSave = null; 2430 URISyntaxException objLoaded = null; 2431 2432 try { 2433 objToSave = new URISyntaxException("str", "problem", 4); 2434 if (DEBUG) 2435 System.out.println("Obj = " + objToSave); 2436 objLoaded = (URISyntaxException) dumpAndReload(objToSave); 2437 2438 boolean equals = objToSave.getMessage().equals( 2439 objLoaded.getMessage()) 2440 && objToSave.getInput().equals(objLoaded.getInput()) 2441 && objToSave.getIndex() == objLoaded.getIndex() 2442 && objToSave.getReason().equals(objLoaded.getReason()); 2443 2444 // Has to have worked 2445 assertTrue(MSG_TEST_FAILED + objToSave, equals); 2446 } catch (IOException e) { 2447 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2448 } catch (ClassNotFoundException e) { 2449 fail("ClassNotFoundException reading Object type: " 2450 + e.getMessage()); 2451 } catch (Error err) { 2452 System.out.println("Error when obj = " + objToSave); 2453 // err.printStackTrace(); 2454 throw err; 2455 } 2456 2457 } 2458 2459 public void test_writeObject_Currency() { 2460 // Test for method void 2461 // java.io.ObjectOutputStream.writeObject(java.util.Currency) 2462 2463 Object objToSave = null; 2464 Object objLoaded = null; 2465 2466 try { 2467 objToSave = java.util.Currency.getInstance("AMD"); 2468 if (DEBUG) 2469 System.out.println("Obj = " + objToSave); 2470 objLoaded = dumpAndReload(objToSave); 2471 2472 // Has to have worked 2473 // we need same instance for the same currency code 2474 assertTrue(MSG_TEST_FAILED + objToSave, objToSave == objToSave); 2475 } catch (IOException e) { 2476 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2477 } catch (ClassNotFoundException e) { 2478 fail("ClassNotFoundException reading Object type: " 2479 + e.getMessage()); 2480 } catch (Error err) { 2481 System.out.println("Error when obj = " + objToSave); 2482 // err.printStackTrace(); 2483 throw err; 2484 } 2485 } 2486 2487 public void test_writeObject_DateFormat_Field() { 2488 // Test for method void 2489 // java.io.ObjectOutputStream.writeObject(java.text.DateFormat.Field) 2490 2491 DateFormat.Field[] objToSave = null; 2492 DateFormat.Field[] objLoaded = null; 2493 2494 try { 2495 objToSave = new DateFormat.Field[] { DateFormat.Field.AM_PM, 2496 DateFormat.Field.DAY_OF_MONTH, DateFormat.Field.ERA, 2497 DateFormat.Field.HOUR0, DateFormat.Field.HOUR1, 2498 DateFormat.Field.HOUR_OF_DAY0, 2499 DateFormat.Field.HOUR_OF_DAY1, DateFormat.Field.TIME_ZONE, 2500 DateFormat.Field.YEAR, 2501 DateFormat.Field.DAY_OF_WEEK_IN_MONTH }; 2502 if (DEBUG) 2503 System.out.println("Obj = " + objToSave); 2504 2505 objLoaded = (DateFormat.Field[]) dumpAndReload(objToSave); 2506 2507 // Has to have worked 2508 // we need same instances for the same field names 2509 for (int i = 0; i < objToSave.length; i++) { 2510 assertTrue(MSG_TEST_FAILED + objToSave[i], 2511 objToSave[i] == objLoaded[i]); 2512 } 2513 } catch (IOException e) { 2514 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2515 } catch (ClassNotFoundException e) { 2516 fail("ClassNotFoundException reading Object type: " 2517 + e.getMessage()); 2518 } catch (Error err) { 2519 System.out.println("Error when obj = " + objToSave); 2520 // err.printStackTrace(); 2521 throw err; 2522 } 2523 } 2524 2525 public void test_writeObject_NumberFormat_Field() { 2526 // Test for method void 2527 // java.io.ObjectOutputStream.writeObject(java.text.NumberFormat.Field) 2528 2529 NumberFormat.Field[] objToSave = null; 2530 NumberFormat.Field[] objLoaded = null; 2531 2532 try { 2533 objToSave = new NumberFormat.Field[] { NumberFormat.Field.CURRENCY, 2534 NumberFormat.Field.DECIMAL_SEPARATOR, 2535 NumberFormat.Field.EXPONENT, 2536 NumberFormat.Field.EXPONENT_SIGN, 2537 NumberFormat.Field.EXPONENT_SYMBOL, 2538 NumberFormat.Field.FRACTION, 2539 NumberFormat.Field.GROUPING_SEPARATOR, 2540 NumberFormat.Field.INTEGER, NumberFormat.Field.PERCENT, 2541 NumberFormat.Field.PERMILLE, NumberFormat.Field.SIGN }; 2542 if (DEBUG) 2543 System.out.println("Obj = " + objToSave); 2544 2545 objLoaded = (NumberFormat.Field[]) dumpAndReload(objToSave); 2546 2547 // Has to have worked 2548 // we need same instances for the same field names 2549 for (int i = 0; i < objToSave.length; i++) { 2550 assertTrue(MSG_TEST_FAILED + objToSave[i], 2551 objToSave[i] == objLoaded[i]); 2552 } 2553 } catch (IOException e) { 2554 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2555 } catch (ClassNotFoundException e) { 2556 fail("ClassNotFoundException reading Object type: " 2557 + e.getMessage()); 2558 } catch (Error err) { 2559 System.out.println("Error when obj = " + objToSave); 2560 // err.printStackTrace(); 2561 throw err; 2562 } 2563 } 2564 2565 public void test_writeObject_MessageFormat_Field() { 2566 // Test for method void 2567 // java.io.ObjectOutputStream.writeObject(java.text.MessageFormat.Field) 2568 2569 Object objToSave = null; 2570 Object objLoaded = null; 2571 2572 try { 2573 objToSave = MessageFormat.Field.ARGUMENT; 2574 if (DEBUG) 2575 System.out.println("Obj = " + objToSave); 2576 2577 objLoaded = dumpAndReload(objToSave); 2578 2579 // Has to have worked 2580 // we need same instance for the same field name 2581 assertTrue(MSG_TEST_FAILED + objToSave, objToSave == objLoaded); 2582 } catch (IOException e) { 2583 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2584 } catch (ClassNotFoundException e) { 2585 fail("ClassNotFoundException reading Object type: " 2586 + e.getMessage()); 2587 } catch (Error err) { 2588 System.out.println("Error when obj = " + objToSave); 2589 // err.printStackTrace(); 2590 throw err; 2591 } 2592 } 2593 2594 public void test_writeObject_LinkedHashMap() { 2595 // Test for method void 2596 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2597 2598 Object objToSave = null; 2599 Object objLoaded; 2600 2601 try { 2602 objToSave = LINKEDMAP; 2603 if (DEBUG) 2604 System.out.println("Obj = " + objToSave); 2605 objLoaded = dumpAndReload(objToSave); 2606 // Has to have worked 2607 assertTrue(MSG_TEST_FAILED + objToSave, LINKEDMAP.equals(objLoaded)); 2608 2609 Map mapLoaded = (Map) objLoaded; 2610 Iterator loadedIterator = mapLoaded.keySet().iterator(); 2611 Iterator iterator = LINKEDMAP.keySet().iterator(); 2612 while (loadedIterator.hasNext()) { 2613 assertTrue("invalid iterator order", loadedIterator.next() 2614 .equals(iterator.next())); 2615 } 2616 assertTrue("invalid iterator size", !iterator.hasNext()); 2617 2618 loadedIterator = mapLoaded.entrySet().iterator(); 2619 iterator = LINKEDMAP.entrySet().iterator(); 2620 while (loadedIterator.hasNext()) { 2621 assertTrue("invalid entry set iterator order", loadedIterator 2622 .next().equals(iterator.next())); 2623 } 2624 assertTrue("invalid entry set iterator size", !iterator.hasNext()); 2625 2626 } catch (IOException e) { 2627 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2628 } catch (ClassNotFoundException e) { 2629 fail("ClassNotFoundException reading Object type: " 2630 + e.getMessage()); 2631 } catch (Error err) { 2632 System.out.println("Error when obj = " + objToSave); 2633 // err.printStackTrace(); 2634 throw err; 2635 } 2636 } 2637 2638 public void test_writeObject_LinkedHashSet() { 2639 // Test for method void 2640 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2641 2642 Object objToSave = null; 2643 Object objLoaded; 2644 2645 try { 2646 objToSave = LINKEDSET; 2647 if (DEBUG) 2648 System.out.println("Obj = " + objToSave); 2649 objLoaded = dumpAndReload(objToSave); 2650 // Has to have worked 2651 assertTrue(MSG_TEST_FAILED + objToSave, LINKEDSET.equals(objLoaded)); 2652 2653 } catch (IOException e) { 2654 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2655 } catch (ClassNotFoundException e) { 2656 fail("ClassNotFoundException reading Object type: " 2657 + e.getMessage()); 2658 } catch (Error err) { 2659 System.out.println("Error when obj = " + objToSave); 2660 // err.printStackTrace(); 2661 throw err; 2662 } 2663 } 2664 2665 public void test_writeObject_IdentityHashMap() { 2666 // Test for method void 2667 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2668 2669 IdentityHashMap objToSave = null; 2670 IdentityHashMap objLoaded; 2671 2672 try { 2673 objToSave = IDENTITYMAP; 2674 if (DEBUG) 2675 System.out.println("Obj = " + objToSave); 2676 objLoaded = (IdentityHashMap) dumpAndReload(objToSave); 2677 // Has to have worked 2678 2679 // a serialized identity hash map will not be equal to its original 2680 // because it is an "identity" mapping, 2681 // so we simply check for the usual meaning of equality 2682 2683 assertEquals( 2684 "Loaded IdentityHashMap is not of the same size as the saved one.", 2685 objToSave.size(), objLoaded.size()); 2686 HashMap duplicateSaved = new HashMap(); 2687 duplicateSaved.putAll(objToSave); 2688 HashMap duplicateLoaded = new HashMap(); 2689 duplicateLoaded.putAll(objLoaded); 2690 assertTrue(MSG_TEST_FAILED + duplicateSaved, duplicateSaved 2691 .equals(duplicateLoaded)); 2692 } catch (IOException e) { 2693 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 2694 } catch (ClassNotFoundException e) { 2695 fail("ClassNotFoundException reading Object type: " 2696 + e.getMessage()); 2697 } catch (Error err) { 2698 System.out.println("Error when obj = " + objToSave); 2699 // err.printStackTrace(); 2700 throw err; 2701 } 2702 } 2703} 2704