1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package tests.api.java.io; 19 20import dalvik.annotation.KnownFailure; 21import dalvik.annotation.TestLevel; 22import dalvik.annotation.TestTargetNew; 23import dalvik.annotation.TestTargetClass; 24 25import java.io.ByteArrayInputStream; 26import java.io.ByteArrayOutputStream; 27import java.io.DataOutputStream; 28import java.io.IOException; 29import java.io.InvalidClassException; 30import java.io.NotActiveException; 31import java.io.ObjectInputStream; 32import java.io.ObjectOutputStream; 33import java.io.ObjectStreamClass; 34import java.io.ObjectStreamConstants; 35import java.io.ObjectStreamField; 36import java.io.OptionalDataException; 37import java.io.Serializable; 38import java.util.ArrayList; 39import java.util.Arrays; 40import java.util.Date; 41import java.util.Locale; 42 43@SuppressWarnings("serial") 44@TestTargetClass(Serializable.class) 45public class SerializationStressTest2 extends SerializationStressTest { 46 47 private static class ReadWriteObjectAndPrimitiveData implements 48 java.io.Serializable { 49 transient long milliseconds; 50 51 public boolean calledWriteObject = false; 52 53 public boolean calledReadObject = false; 54 55 public ReadWriteObjectAndPrimitiveData() { 56 super(); 57 } 58 59 private void readObject(java.io.ObjectInputStream in) 60 throws java.io.IOException, ClassNotFoundException { 61 in.defaultReadObject(); 62 // This *has* to come after the call to defaultReadObject or the 63 // value from the stream will override 64 calledReadObject = true; 65 milliseconds = in.readLong(); 66 } 67 68 private void writeObject(java.io.ObjectOutputStream out) 69 throws java.io.IOException { 70 calledWriteObject = true; 71 out.defaultWriteObject(); 72 out.writeLong(milliseconds); 73 } 74 } 75 76 // What happens if a class defines serialPersistentFields that do not match 77 // real fields but does not override read/writeObject 78 private static class WithUnmatchingSerialPersistentFields implements 79 java.io.Serializable { 80 private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField( 81 "value", String.class) }; 82 83 public int anInstanceVar = 5; 84 85 public WithUnmatchingSerialPersistentFields() { 86 super(); 87 } 88 } 89 90 // What happens if a class defines serialPersistentFields which match actual 91 // fields 92 private static class WithMatchingSerialPersistentFields implements 93 java.io.Serializable { 94 private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField( 95 "anInstanceVar", String.class) }; 96 97 public String anInstanceVar = FOO + FOO; 98 99 public WithMatchingSerialPersistentFields() { 100 super(); 101 } 102 } 103 104 // Tests the oficial behavior for serialPersistentFields 105 private static class SerialPersistentFields implements java.io.Serializable { 106 private static final String SIMULATED_FIELD_NAME = "text"; 107 108 private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField( 109 SIMULATED_FIELD_NAME, String.class) }; 110 111 public int anInstanceVar = 5; 112 113 public SerialPersistentFields() { 114 super(); 115 } 116 117 private void readObject(java.io.ObjectInputStream in) 118 throws java.io.IOException, ClassNotFoundException { 119 ObjectInputStream.GetField fields = in.readFields(); 120 anInstanceVar = Integer.parseInt((String) fields.get( 121 SIMULATED_FIELD_NAME, "-5")); 122 } 123 124 private void writeObject(java.io.ObjectOutputStream out) 125 throws java.io.IOException, ClassNotFoundException { 126 ObjectOutputStream.PutField fields = out.putFields(); 127 fields.put(SIMULATED_FIELD_NAME, Integer.toString(anInstanceVar)); 128 out.writeFields(); 129 } 130 } 131 132 // Tests the behavior for serialPersistentFields when no fields are actually 133 // set 134 private static class WriteFieldsWithoutFetchingPutFields implements 135 java.io.Serializable { 136 private static final String SIMULATED_FIELD_NAME = "text"; 137 138 private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField( 139 SIMULATED_FIELD_NAME, String.class) }; 140 141 public int anInstanceVar = 5; 142 143 public WriteFieldsWithoutFetchingPutFields() { 144 super(); 145 } 146 147 private void readObject(java.io.ObjectInputStream in) 148 throws java.io.IOException, ClassNotFoundException { 149 in.readFields(); 150 } 151 152 private void writeObject(java.io.ObjectOutputStream out) 153 throws java.io.IOException, ClassNotFoundException { 154 out.writeFields(); 155 } 156 } 157 158 // Tests what happens if one asks for PutField/getField when the class does 159 // not declare one 160 private static class SerialPersistentFieldsWithoutField implements 161 java.io.Serializable { 162 public int anInstanceVar = 5; 163 164 public SerialPersistentFieldsWithoutField() { 165 super(); 166 } 167 168 private void readObject(java.io.ObjectInputStream in) 169 throws java.io.IOException, ClassNotFoundException { 170 in.readFields(); 171 } 172 173 private void writeObject(java.io.ObjectOutputStream out) 174 throws java.io.IOException, ClassNotFoundException { 175 out.putFields(); 176 out.writeFields(); 177 } 178 } 179 180 // ----------------------------------------------------------------------------------- 181 182 // writeObject writes extra primitive types and objects which readObject 183 // does not consume. Have to make sure we can load object properly AND 184 // object after it (to show the extra byte[] is consumed) 185 private static class OptionalDataNotRead implements java.io.Serializable { 186 @SuppressWarnings("unused") 187 private int field1, field2; 188 189 public OptionalDataNotRead() { 190 } 191 192 private static final ObjectStreamField[] serialPersistentFields = { 193 new ObjectStreamField("field1", Integer.TYPE), 194 new ObjectStreamField("field2", Integer.TYPE), 195 new ObjectStreamField("monthLength", byte[].class), }; 196 197 private void writeObject(ObjectOutputStream stream) throws IOException { 198 ObjectOutputStream.PutField fields = stream.putFields(); 199 fields.put("field1", 1); 200 fields.put("field2", 2); 201 fields.put("monthLength", new byte[] { 7, 8, 9 }); 202 stream.writeFields(); 203 stream.writeInt(4); 204 byte[] values = new byte[4]; 205 values[0] = (byte) 16; 206 values[1] = (byte) 17; 207 values[2] = (byte) 18; 208 values[3] = (byte) 19; 209 stream.writeObject(values); 210 } 211 212 private void readObject(ObjectInputStream stream) throws IOException, 213 ClassNotFoundException { 214 ObjectInputStream.GetField fields = stream.readFields(); 215 field1 = fields.get("field1", 0); 216 field2 = fields.get("field1", 0); 217 } 218 } 219 220 // ----------------------------------------------------------------------------------- 221 private static class NestedPutField implements java.io.Serializable { 222 public OptionalDataNotRead field1; 223 224 public NestedPutField() { 225 } 226 227 private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField( 228 "field1", OptionalDataNotRead.class), }; 229 230 private void writeObject(ObjectOutputStream stream) throws IOException { 231 ObjectOutputStream.PutField fields = stream.putFields(); 232 fields.put("field1", new OptionalDataNotRead()); 233 stream.writeFields(); 234 } 235 236 private void readObject(ObjectInputStream stream) throws IOException, 237 ClassNotFoundException { 238 ObjectInputStream.GetField fields = stream.readFields(); 239 field1 = (OptionalDataNotRead) fields.get("field1", null); 240 } 241 } 242 243 // ----------------------------------------------------------------------------------- 244 245 // This one tests stream-based replacement when dumping 246 private static class StreamBasedReplacementWhenDumping extends 247 java.io.ObjectOutputStream { 248 public boolean calledArrayReplacement = false; 249 250 public boolean calledStringReplacement = false; 251 252 public boolean calledClassReplacement = false; 253 254 public boolean calledObjectStreamClassReplacement = false; 255 256 public StreamBasedReplacementWhenDumping(java.io.OutputStream output) 257 throws java.io.IOException { 258 super(output); 259 enableReplaceObject(true); 260 } 261 262 protected Object replaceObject(Object obj) throws IOException { 263 Class<?> objClass = obj.getClass(); 264 if (objClass == String.class) 265 calledStringReplacement = true; 266 267 if (objClass == Class.class) 268 calledClassReplacement = true; 269 270 if (objClass == ObjectStreamClass.class) 271 calledObjectStreamClassReplacement = true; 272 273 if (objClass.isArray()) 274 calledArrayReplacement = true; 275 276 return obj; 277 } 278 } 279 280 // ----------------------------------------------------------------------------------- 281 282 private static class ArrayOfSerializable implements Serializable { 283 private Serializable[] testField = null; 284 285 public ArrayOfSerializable() { 286 testField = new Serializable[2]; 287 testField[0] = "Hi"; 288 testField[1] = "there!"; 289 } 290 } 291 292 // ----------------------------------------------------------------------------------- 293 294 private static class ClassSubClassTest0 extends java.lang.Object implements 295 java.io.Serializable { 296 String stringVar; 297 298 public ClassSubClassTest0(String init) { 299 stringVar = init; 300 } 301 } 302 303 private static class ClassSubClassTest1 extends ClassSubClassTest0 { 304 String subStringVar; 305 306 public ClassSubClassTest1(String superString, String subString) { 307 super(superString); 308 subStringVar = subString; 309 } 310 311 public boolean equals(Object obj) { 312 if (obj == null) 313 return false; 314 if (!(obj instanceof ClassSubClassTest1)) 315 return false; 316 317 ClassSubClassTest1 inst = (ClassSubClassTest1) obj; 318 return inst.subStringVar.equals(this.subStringVar) 319 && inst.stringVar.equals(this.stringVar); 320 } 321 } 322 323 // ----------------------------------------------------------------------------------- 324 private static class ConstructorTestA { 325 public String instVar_classA; 326 327 public final static String ConstrA = "Init in Constructor Class A"; 328 329 public final static String ConstrB = "Init in Constructor Class B"; 330 331 public final static String ConstrC = "Init in Constructor Class C"; 332 333 public final static String ChangedC = "Changed before Serialize - Class C"; 334 335 public ConstructorTestA() { 336 instVar_classA = ConstrA; 337 } 338 } 339 340 private static class ConstructorTestB extends ConstructorTestA implements 341 java.io.Serializable { 342 public String instVar_classB; 343 344 public ConstructorTestB() { 345 instVar_classA = ConstrB; 346 instVar_classB = ConstrB; 347 } 348 } 349 350 private static class ConstructorTestC extends ConstructorTestB { 351 public String instVar_classC; 352 353 public ConstructorTestC() { 354 instVar_classA = ConstrC; 355 instVar_classB = ConstrC; 356 instVar_classC = ConstrC; 357 } 358 359 public boolean verify(Object obj) { 360 if (obj == null) 361 return false; 362 if (!(obj instanceof ConstructorTestC)) 363 return false; 364 365 ConstructorTestC inst = (ConstructorTestC) obj; 366 return inst.instVar_classC.equals(this.instVar_classC) 367 && inst.instVar_classB.equals(this.instVar_classB) 368 && inst.instVar_classA.equals(ConstrA); 369 } 370 } 371 372 // ----------------------------------------------------------------------------------- 373 private static class HashCodeTest implements java.io.Serializable { 374 private boolean serializationUsesHashCode = false; 375 376 public int hashCode() { 377 serializationUsesHashCode = true; 378 return super.hashCode(); 379 } 380 } 381 382 // ----------------------------------------------------------------------------------- 383 private static class InitializerFieldsTest implements java.io.Serializable { 384 public java.lang.String toBeSerialized; 385 386 public static java.lang.String toBeNotSerialized; 387 388 public static java.lang.String toBeNotSerialized2; 389 390 { 391 toBeSerialized = "NonStaticInitialValue"; 392 } 393 394 static { 395 toBeNotSerialized = "StaticInitialValue"; 396 toBeNotSerialized2 = new String(toBeNotSerialized); 397 } 398 399 public boolean equals(Object obj) { 400 /* 401 * This method is not answering it the objs is equal. It is 402 * answering if the vars have the value that it have to have after 403 * dumping and loading 404 */ 405 406 if (obj == null) 407 return false; 408 if (!(obj instanceof InitializerFieldsTest)) 409 return false; 410 411 InitializerFieldsTest inst = (InitializerFieldsTest) obj; 412 return inst.toBeSerialized.equals(this.toBeSerialized) 413 && InitializerFieldsTest.toBeNotSerialized.equals(InitializerFieldsTest.toBeNotSerialized2); 414 } 415 } 416 417 private static class InitializerFieldsTest2 implements java.io.Serializable { 418 public java.lang.String toBeSerialized; 419 420 public static java.lang.String toBeNotSerialized; 421 422 public static java.lang.String toBeNotSerialized2; 423 424 { 425 toBeSerialized = "NonStaticInitialValue"; 426 } 427 428 public java.lang.String toBeSerialized3; 429 430 public java.lang.String toBeSerialized4; 431 static { 432 toBeNotSerialized = "StaticInitialValue"; 433 toBeNotSerialized2 = new String(toBeNotSerialized); 434 } 435 436 public java.lang.String toBeSerialized5; 437 438 public boolean equals(Object obj) { 439 /* 440 * This method is not answering it the objs is equal. It is 441 * answering if the vars have the value that it have to have after 442 * dumping and loading 443 */ 444 445 if (obj == null) 446 return false; 447 if (!(obj instanceof InitializerFieldsTest2)) 448 return false; 449 450 InitializerFieldsTest2 inst = (InitializerFieldsTest2) obj; 451 return inst.toBeSerialized.equals(this.toBeSerialized) 452 && inst.toBeSerialized3.equals(this.toBeSerialized3) 453 && inst.toBeSerialized4.equals(this.toBeSerialized4) 454 && inst.toBeSerialized5.equals(this.toBeSerialized5) 455 && InitializerFieldsTest2.toBeNotSerialized.equals(InitializerFieldsTest2.toBeNotSerialized2); 456 } 457 } 458 459 private static class InitializerFieldsTest3 extends InitializerFieldsTest2 460 implements java.io.Serializable { 461 public java.lang.String sub_toBeSerialized; 462 463 public static java.lang.String sub_toBeNotSerialized; 464 465 public static java.lang.String sub_toBeNotSerialized2; 466 467 { 468 sub_toBeSerialized = "NonStaticInitialValue"; 469 } 470 471 public java.lang.String sub_toBeSerialized3; 472 473 public java.lang.String sub_toBeSerialized4; 474 static { 475 sub_toBeNotSerialized = "StaticInitialValue"; 476 sub_toBeNotSerialized2 = new String(sub_toBeNotSerialized); 477 } 478 479 public java.lang.String sub_toBeSerialized5; 480 481 public boolean equals(Object obj) { 482 /* 483 * This method is not answering it the objs is equal. It is 484 * answering if the vars have the value that it have to have after 485 * dumping and loading 486 */ 487 488 if (!super.equals(obj)) 489 return false; 490 if (!(obj instanceof InitializerFieldsTest3)) 491 return false; 492 493 InitializerFieldsTest3 inst = (InitializerFieldsTest3) obj; 494 return inst.sub_toBeSerialized.equals(this.sub_toBeSerialized) 495 && inst.sub_toBeSerialized3 496 .equals(this.sub_toBeSerialized3) 497 && inst.sub_toBeSerialized4 498 .equals(this.sub_toBeSerialized4) 499 && inst.sub_toBeSerialized5 500 .equals(this.sub_toBeSerialized5) 501 && InitializerFieldsTest3.sub_toBeNotSerialized 502 .equals(InitializerFieldsTest3.sub_toBeNotSerialized2); 503 } 504 } 505 506 // ----------------------------------------------------------------------------------- 507 private static class DeepNesting implements java.io.Serializable { 508 public float id; 509 510 public DeepNesting next; 511 512 public boolean dump; 513 514 public boolean load; 515 516 public DeepNesting(float id) { 517 this.id = id; 518 next = null; 519 dump = false; 520 load = false; 521 } 522 523 public DeepNesting(int howMany) { 524 DeepNesting prev = new DeepNesting(0.0F); 525 next(prev); 526 for (int i = 1; i < howMany; i++) { 527 prev = prev.next(new DeepNesting(i * 1.0F)); 528 } 529 } 530 531 public boolean equals(Object obj) { 532 if (obj == null) 533 return false; 534 if (!(obj instanceof DeepNesting)) 535 return false; 536 537 DeepNesting inst = (DeepNesting) obj; 538 if (inst.dump != this.dump || inst.load != this.load) 539 return false; 540 541 if (inst.next == null || this.next == null) 542 return inst.next == this.next; // both null 543 return this.next.equals(inst.next); 544 } 545 546 public DeepNesting next(DeepNesting ivt) { 547 next = ivt; 548 return ivt; 549 } 550 } 551 552 // ----------------------------------------------------------------------------------- 553 private static class DeepNestingWithWriteObject implements 554 java.io.Serializable { 555 public float id; 556 557 public DeepNestingWithWriteObject next; 558 559 public boolean dump; 560 561 public boolean load; 562 563 public DeepNestingWithWriteObject(float id) { 564 this.id = id; 565 next = null; 566 dump = false; 567 load = false; 568 } 569 570 public DeepNestingWithWriteObject(int howMany) { 571 DeepNestingWithWriteObject prev = new DeepNestingWithWriteObject( 572 0.0F); 573 next(prev); 574 for (int i = 1; i < howMany; i++) { 575 prev = prev.next(new DeepNestingWithWriteObject(i * 1.0F)); 576 } 577 } 578 579 public boolean equals(Object obj) { 580 if (obj == null) 581 return false; 582 if (!(obj instanceof DeepNestingWithWriteObject)) 583 return false; 584 585 DeepNestingWithWriteObject inst = (DeepNestingWithWriteObject) obj; 586 if (inst.dump != this.dump || inst.load != this.load) 587 return false; 588 589 if (inst.next == null || this.next == null) 590 return inst.next == this.next; // both null; 591 return this.next.equals(inst.next); 592 } 593 594 public DeepNestingWithWriteObject next(DeepNestingWithWriteObject ivt) { 595 next = ivt; 596 return ivt; 597 } 598 599 private void writeObject(java.io.ObjectOutputStream s) 600 throws IOException { 601 s.defaultWriteObject(); 602 } 603 604 private void readObject(java.io.ObjectInputStream s) 605 throws IOException, ClassNotFoundException { 606 s.defaultReadObject(); 607 } 608 } 609 610 // ----------------------------------------------------------------------------------- 611 static class NonPublicClassTest extends java.lang.Object implements 612 java.io.Serializable { 613 int field = 1; 614 615 public NonPublicClassTest() { 616 field = 10; 617 } 618 619 public boolean equals(Object o) { 620 if (o instanceof NonPublicClassTest) 621 return field == ((NonPublicClassTest) o).field; 622 return false; 623 } 624 625 public void x10() { 626 field *= 10; 627 } 628 } 629 630 // ----------------------------------------------------------------------------------- 631 private static class SameInstVarNameSuperClass { 632 private int foo; 633 634 public SameInstVarNameSuperClass() { 635 super(); 636 } 637 638 public SameInstVarNameSuperClass(int fooValue) { 639 foo = fooValue; 640 } 641 642 public String toString() { 643 return "foo = " + foo; 644 } 645 } 646 647 private static class SameInstVarNameSubClass extends 648 SameInstVarNameSuperClass implements java.io.Serializable { 649 protected int foo; 650 651 public SameInstVarNameSubClass() { 652 super(); 653 } 654 655 public SameInstVarNameSubClass(int fooValue) { 656 super(-fooValue); 657 foo = fooValue; 658 } 659 } 660 661 // ----------------------------------------------------------------------------------- 662 private static class SInterfaceTest implements java.io.Serializable { 663 public static int staticVar = 5; 664 665 public transient int[] transVar = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; 666 667 public int instanceVar = 7; 668 669 public boolean equals(Object obj) { 670 if (obj == null) 671 return false; 672 if (!(obj instanceof SInterfaceTest)) 673 return false; 674 675 SInterfaceTest inst = (SInterfaceTest) obj; 676 if (this.instanceVar != inst.instanceVar) 677 return false; 678 if (inst.transVar == null || this.transVar == null) 679 return inst.transVar == this.transVar; // both null 680 for (int i = 0; i < transVar.length; i++) 681 if (inst.transVar[i] != this.transVar[i]) 682 return false; 683 return true; 684 } 685 686 private void readObject(java.io.ObjectInputStream s) 687 throws IOException, ClassNotFoundException { 688 Object arr; 689 s.defaultReadObject(); 690 arr = s.readObject(); 691 transVar = (int[]) arr; 692 } 693 694 private void writeObject(java.io.ObjectOutputStream s) 695 throws IOException { 696 s.defaultWriteObject(); 697 s.writeObject(transVar); 698 } 699 700 public void x10() { 701 for (int i = 0; i < transVar.length; i++) 702 transVar[i] = transVar[i] * 10; 703 instanceVar = instanceVar * 10; 704 } 705 } 706 707 // ----------------------------------------------------------------------------------- 708 private static class SInterfaceTest2 extends SInterfaceTest { 709 private void readObject(java.io.ObjectInputStream s) 710 throws IOException, ClassNotFoundException { 711 Object arr; 712 instanceVar = s.readInt(); 713 arr = s.readObject(); 714 transVar = (int[]) arr; 715 } 716 717 private void writeObject(java.io.ObjectOutputStream s) 718 throws IOException { 719 s.writeInt(instanceVar); 720 s.writeObject(transVar); 721 } 722 } 723 724 // ----------------------------------------------------------------------------------- 725 private static class SuperclassTest extends java.lang.Object implements 726 java.io.Serializable { 727 int superfield = 1; 728 729 public SuperclassTest() { 730 superfield = 10; 731 } 732 733 public boolean equals(Object o) { 734 if (o.getClass() == this.getClass()) 735 return superfield == ((SuperclassTest) o).superfield; 736 return false; 737 } 738 739 private void readObject(java.io.ObjectInputStream s) 740 throws IOException, ClassNotFoundException { 741 superfield = s.readInt(); 742 } 743 744 private void writeObject(java.io.ObjectOutputStream s) 745 throws IOException { 746 s.writeInt(superfield); 747 } 748 749 public void x10() { 750 superfield *= 10; 751 } 752 } 753 754 // ----------------------------------------------------------------------------------- 755 private static class SuperclassTest2 extends SuperclassTest { 756 int subfield = 5; 757 758 public SuperclassTest2() { 759 subfield = 50; 760 } 761 762 public boolean equals(Object o) { 763 if (o instanceof SuperclassTest2) 764 if (subfield == ((SuperclassTest2) o).subfield) 765 return super.equals(o); 766 return false; 767 } 768 769 private void readObject(java.io.ObjectInputStream s) 770 throws IOException, ClassNotFoundException { 771 subfield = s.readInt(); 772 } 773 774 private void writeObject(java.io.ObjectOutputStream s) 775 throws IOException { 776 s.writeInt(subfield); 777 } 778 779 public void x10() { 780 subfield *= 10; 781 super.x10(); 782 } 783 } 784 785 // ----------------------------------------------------------------------------------- 786 private static class SyntheticFieldTest implements java.io.Serializable { 787 public boolean equals(Object obj) { 788 /* 789 * This method is not answering it the objs is equal. It is 790 * answering if the vars have the value that it have to have after 791 * dumping and loading 792 */ 793 if (obj == null) 794 return false; 795 return obj instanceof SyntheticFieldTest; 796 } 797 798 public int hashCode() { 799 // Insert code to generate a hash code for the receiver here. 800 // This implementation forwards the message to super. You may 801 // replace or supplement this. 802 // NOTE: if two objects are equal (equals Object) returns true) they 803 // must have the same hash code 804 @SuppressWarnings("unused") 805 Class<?>[] c = { String.class }; // *** synthetic field 806 return super.hashCode(); 807 } 808 } 809 810 @TestTargetNew( 811 level = TestLevel.COMPLETE, 812 notes = "Verifies serialization.", 813 method = "!Serialization", 814 args = {} 815 ) 816 public void test_18_41_writeObject() { 817 // Test for method void 818 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 819 820 Object objToSave = null; 821 822 try { 823 java.io.IOException ex = new java.io.WriteAbortedException(FOO, 824 null); 825 objToSave = ex; 826 if (DEBUG) 827 System.out.println("Obj = " + objToSave); 828 dumpAndReload(objToSave); 829 // Has to be able to save/load an exception 830 assertTrue(MSG_TEST_FAILED + objToSave, true); 831 832 } catch (IOException e) { 833 fail("IOException serializing " + objToSave + " : " 834 + e.getMessage()); 835 } catch (ClassNotFoundException e) { 836 fail("ClassNotFoundException reading Object type : " 837 + e.getMessage()); 838 } catch (Error err) { 839 System.out.println("Error when obj = " + objToSave); 840 // err.printStackTrace(); 841 throw err; 842 } 843 } 844 845 @TestTargetNew( 846 level = TestLevel.COMPLETE, 847 notes = "Verifies serialization.", 848 method = "!Serialization", 849 args = {} 850 ) 851 public void test_18_42_writeObject() { 852 // Test for method void 853 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 854 855 Object objToSave = null; 856 857 try { 858 WithUnmatchingSerialPersistentFields spf = new WithUnmatchingSerialPersistentFields(); 859 objToSave = spf; 860 if (DEBUG) 861 System.out.println("Obj = " + objToSave); 862 boolean causedException = false; 863 try { 864 dumpAndReload(objToSave); 865 } catch (InvalidClassException ce) { 866 causedException = true; 867 } 868 assertTrue("serialPersistentFields do not match real fields", 869 causedException); 870 871 } catch (IOException e) { 872 fail("IOException serializing " + objToSave + " : " 873 + e.getMessage()); 874 } catch (ClassNotFoundException e) { 875 fail("ClassNotFoundException reading Object type : " 876 + e.getMessage()); 877 } catch (Error err) { 878 System.out.println("Error when obj = " + objToSave); 879 // err.printStackTrace(); 880 throw err; 881 } 882 } 883 884 @TestTargetNew( 885 level = TestLevel.COMPLETE, 886 notes = "Verifies serialization.", 887 method = "!Serialization", 888 args = {} 889 ) 890 public void test_18_43_writeObject() { 891 // Test for method void 892 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 893 894 Object objToSave = null; 895 Object objLoaded; 896 897 try { 898 WithMatchingSerialPersistentFields spf = new WithMatchingSerialPersistentFields(); 899 spf.anInstanceVar = FOO; 900 objToSave = spf; 901 if (DEBUG) 902 System.out.println("Obj = " + objToSave); 903 objLoaded = dumpAndReload(objToSave); 904 assertTrue( 905 "serialPersistentFields do not work properly in this implementation", 906 FOO 907 .equals(((WithMatchingSerialPersistentFields) objLoaded).anInstanceVar)); 908 909 } catch (IOException e) { 910 fail("IOException serializing " + objToSave + " : " 911 + e.getMessage()); 912 } catch (ClassNotFoundException e) { 913 fail("ClassNotFoundException reading Object type : " 914 + e.getMessage()); 915 } catch (Error err) { 916 System.out.println("Error when obj = " + objToSave); 917 // err.printStackTrace(); 918 throw err; 919 } 920 } 921 922 @TestTargetNew( 923 level = TestLevel.COMPLETE, 924 notes = "Verifies serialization.", 925 method = "!Serialization", 926 args = {} 927 ) 928 public void test_18_44_writeObject() { 929 // Test for method void 930 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 931 932 Object objToSave = null; 933 Object objLoaded; 934 935 try { 936 SerialPersistentFields spf = new SerialPersistentFields(); 937 final int CONST = -500; 938 spf.anInstanceVar = CONST; 939 objToSave = spf; 940 if (DEBUG) 941 System.out.println("Obj = " + objToSave); 942 objLoaded = dumpAndReload(objToSave); 943 assertTrue( 944 "serialPersistentFields do not work properly in this implementation", 945 ((SerialPersistentFields) objLoaded).anInstanceVar == CONST); 946 947 } catch (IOException e) { 948 fail("IOException serializing " + objToSave + " : " 949 + e.getMessage()); 950 } catch (ClassNotFoundException e) { 951 fail("ClassNotFoundException reading Object type : " 952 + e.getMessage()); 953 } catch (Error err) { 954 System.out.println("Error when obj = " + objToSave); 955 // err.printStackTrace(); 956 throw err; 957 } 958 } 959 960 @TestTargetNew( 961 level = TestLevel.COMPLETE, 962 notes = "Verifies serialization.", 963 method = "!Serialization", 964 args = {} 965 ) 966 public void test_18_45_writeObject() { 967 // Test for method void 968 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 969 970 Object objToSave = null; 971 972 try { 973 WriteFieldsWithoutFetchingPutFields spf = new WriteFieldsWithoutFetchingPutFields(); 974 objToSave = spf; 975 if (DEBUG) 976 System.out.println("Obj = " + objToSave); 977 boolean causedException = false; 978 try { 979 dumpAndReload(objToSave); 980 } catch (NotActiveException ce) { 981 causedException = true; 982 } 983 assertTrue("WriteFieldsWithoutFetchingPutFields", causedException); 984 985 } catch (IOException e) { 986 fail("IOException serializing " + objToSave + " : " 987 + e.getMessage()); 988 } catch (ClassNotFoundException e) { 989 fail("ClassNotFoundException reading Object type : " 990 + e.getMessage()); 991 } catch (Error err) { 992 System.out.println("Error when obj = " + objToSave); 993 // err.printStackTrace(); 994 throw err; 995 } 996 } 997 998 @TestTargetNew( 999 level = TestLevel.COMPLETE, 1000 notes = "Verifies serialization.", 1001 method = "!Serialization", 1002 args = {} 1003 ) 1004 public void test_18_46_writeObject() { 1005 // Test for method void 1006 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1007 1008 Object objToSave = null; 1009 1010 try { 1011 objToSave = SerialPersistentFields.class; // Test for 1FA7TA6 1012 if (DEBUG) 1013 System.out.println("Obj = " + objToSave); 1014 dumpAndReload(objToSave); 1015 // Has to be able to save/load an exception 1016 assertTrue(MSG_TEST_FAILED + objToSave, true); 1017 1018 } catch (IOException e) { 1019 fail("IOException serializing " + objToSave + " : " 1020 + e.getMessage()); 1021 } catch (ClassNotFoundException e) { 1022 fail("ClassNotFoundException reading Object type : " 1023 + e.getMessage()); 1024 } catch (Error err) { 1025 System.out.println("Error when obj = " + objToSave); 1026 // err.printStackTrace(); 1027 throw err; 1028 } 1029 } 1030 1031 @TestTargetNew( 1032 level = TestLevel.COMPLETE, 1033 notes = "Verifies serialization.", 1034 method = "!Serialization", 1035 args = {} 1036 ) 1037 public void test_18_47_writeObject() { 1038 // Test for method void 1039 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1040 1041 Object objToSave = null; 1042 1043 try { 1044 objToSave = ObjectStreamClass.lookup(SerialPersistentFields.class); // Test 1045 // for 1046 // 1FA7TA6 1047 if (DEBUG) 1048 System.out.println("Obj = " + objToSave); 1049 dumpAndReload(objToSave); 1050 // Has to be able to save/load an exception 1051 assertTrue(MSG_TEST_FAILED + objToSave, true); 1052 1053 } catch (IOException e) { 1054 fail("IOException serializing " + objToSave + " : " 1055 + e.getMessage()); 1056 } catch (ClassNotFoundException e) { 1057 fail("ClassNotFoundException reading Object type : " 1058 + e.getMessage()); 1059 } catch (Error err) { 1060 System.out.println("Error when obj = " + objToSave); 1061 // err.printStackTrace(); 1062 throw err; 1063 } 1064 } 1065 1066 @TestTargetNew( 1067 level = TestLevel.COMPLETE, 1068 notes = "Verifies serialization.", 1069 method = "!Serialization", 1070 args = {} 1071 ) 1072 public void test_18_48_writeObject() { 1073 // Test for method void 1074 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1075 1076 Object objToSave = null; 1077 Object objLoaded; 1078 1079 try { 1080 SerialPersistentFieldsWithoutField spf = new SerialPersistentFieldsWithoutField(); 1081 final int CONST = -500; 1082 spf.anInstanceVar = CONST; 1083 objToSave = spf; 1084 if (DEBUG) 1085 System.out.println("Obj = " + objToSave); 1086 objLoaded = dumpAndReload(objToSave); 1087 assertTrue( 1088 "serialPersistentFields do not work properly in this implementation", 1089 ((SerialPersistentFieldsWithoutField) objLoaded).anInstanceVar != CONST); 1090 1091 } catch (IOException e) { 1092 fail("IOException serializing " + objToSave + " : " 1093 + e.getMessage()); 1094 } catch (ClassNotFoundException e) { 1095 fail("ClassNotFoundException reading Object type : " 1096 + e.getMessage()); 1097 } catch (Error err) { 1098 System.out.println("Error when obj = " + objToSave); 1099 // err.printStackTrace(); 1100 throw err; 1101 } 1102 } 1103 1104 @TestTargetNew( 1105 level = TestLevel.COMPLETE, 1106 notes = "Verifies serialization.", 1107 method = "!Serialization", 1108 args = {} 1109 ) 1110 public void test_18_49_writeObject() { 1111 // Test for method void 1112 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1113 1114 Object objToSave = null; 1115 Object objLoaded; 1116 1117 try { 1118 java.net.SocketPermission p = new java.net.SocketPermission( 1119 "www.yahoo.com", "connect"); 1120 objToSave = p; 1121 if (DEBUG) 1122 System.out.println("Obj = " + objToSave); 1123 objLoaded = dumpAndReload(objToSave); 1124 assertTrue("SocketPermissions are not the same: " + p + "\t,\t" 1125 + objLoaded, p.equals(objLoaded)); 1126 1127 } catch (IOException e) { 1128 fail("IOException serializing " + objToSave + " : " 1129 + e.getMessage()); 1130 } catch (ClassNotFoundException e) { 1131 fail("ClassNotFoundException reading Object type : " 1132 + e.getMessage()); 1133 } catch (Error err) { 1134 System.out.println("Error when obj = " + objToSave); 1135 // err.printStackTrace(); 1136 throw err; 1137 } 1138 } 1139 1140 @TestTargetNew( 1141 level = TestLevel.COMPLETE, 1142 notes = "Verifies serialization.", 1143 method = "!Serialization", 1144 args = {} 1145 ) 1146 public void test_18_50_writeObject() { 1147 // Test for method void 1148 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1149 1150 Object objToSave = null; 1151 Object objLoaded; 1152 1153 try { 1154 java.net.SocketPermission p = new java.net.SocketPermission( 1155 "www.yahoo.com", "ReSoLVe, ConNecT"); 1156 objToSave = p; 1157 if (DEBUG) 1158 System.out.println("Obj = " + objToSave); 1159 objLoaded = dumpAndReload(objToSave); 1160 assertTrue("SocketPermissions are not the same: " + p + "\t,\t" 1161 + objLoaded, p.equals(objLoaded)); 1162 1163 } catch (IOException e) { 1164 fail("IOException serializing " + objToSave + " : " 1165 + e.getMessage()); 1166 } catch (ClassNotFoundException e) { 1167 fail("ClassNotFoundException reading Object type : " 1168 + e.getMessage()); 1169 } catch (Error err) { 1170 System.out.println("Error when obj = " + objToSave); 1171 // err.printStackTrace(); 1172 throw err; 1173 } 1174 } 1175 1176 @TestTargetNew( 1177 level = TestLevel.COMPLETE, 1178 notes = "Verifies serialization.", 1179 method = "!Serialization", 1180 args = {} 1181 ) 1182 public void test_18_51_writeObject() { 1183 // Test for method void 1184 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1185 1186 Object objToSave = null; 1187 Object objLoaded; 1188 1189 try { 1190 1191 ReadWriteObjectAndPrimitiveData readWrite = new ReadWriteObjectAndPrimitiveData(); 1192 objToSave = readWrite; 1193 if (DEBUG) 1194 System.out.println("Obj = " + objToSave); 1195 objLoaded = dumpAndReload(objToSave); 1196 // has to have called the writeObject on the instance to dump 1197 assertTrue(MSG_TEST_FAILED + objToSave, readWrite.calledWriteObject); 1198 // has to have called the readObject on the instance loaded 1199 assertTrue( 1200 MSG_TEST_FAILED + objToSave, 1201 ((ReadWriteObjectAndPrimitiveData) objLoaded).calledReadObject); 1202 1203 } catch (IOException e) { 1204 fail("IOException serializing " + objToSave + " : " 1205 + e.getMessage()); 1206 } catch (ClassNotFoundException e) { 1207 fail("ClassNotFoundException reading Object type : " 1208 + e.getMessage()); 1209 } catch (Error err) { 1210 System.out.println("Error when obj = " + objToSave); 1211 // err.printStackTrace(); 1212 throw err; 1213 } 1214 } 1215 1216 @TestTargetNew( 1217 level = TestLevel.COMPLETE, 1218 notes = "Verifies serialization.", 1219 method = "!Serialization", 1220 args = {} 1221 ) 1222 public void test_18_52_writeObject() { 1223 // Test for method void 1224 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1225 1226 Object objToSave = null; 1227 Object objLoaded; 1228 1229 try { 1230 1231 ArrayList<String> list = new ArrayList<String>(Arrays.asList(new String[] { "a", 1232 "list", "of", "strings" })); 1233 objToSave = list; 1234 if (DEBUG) 1235 System.out.println("Obj = " + objToSave); 1236 objLoaded = dumpAndReload(objToSave); 1237 // Has to have worked 1238 assertTrue(MSG_TEST_FAILED + objToSave, true); 1239 assertNotNull(objLoaded); 1240 1241 } catch (IOException e) { 1242 fail("IOException serializing " + objToSave + " : " 1243 + e.getMessage()); 1244 } catch (ClassNotFoundException e) { 1245 fail("ClassNotFoundException reading Object type : " 1246 + e.getMessage()); 1247 } catch (Error err) { 1248 System.out.println("Error when obj = " + objToSave); 1249 // err.printStackTrace(); 1250 throw err; 1251 } 1252 } 1253 1254 @TestTargetNew( 1255 level = TestLevel.COMPLETE, 1256 notes = "Verifies serialization.", 1257 method = "!Serialization", 1258 args = {} 1259 ) 1260 public void test_18_53_writeObject() { 1261 // Test for method void 1262 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1263 1264 Object objToSave = null; 1265 Object objLoaded; 1266 1267 try { 1268 1269 objToSave = Locale.CHINESE; 1270 if (DEBUG) 1271 System.out.println("Obj = " + objToSave); 1272 objLoaded = dumpAndReload(objToSave); 1273 // Has to have worked 1274 assertTrue(MSG_TEST_FAILED + objToSave, true); 1275 assertNotNull(objLoaded); 1276 1277 } catch (IOException e) { 1278 fail("IOException serializing " + objToSave + " : " 1279 + e.getMessage()); 1280 } catch (ClassNotFoundException e) { 1281 fail("ClassNotFoundException reading Object type : " 1282 + e.getMessage()); 1283 } catch (Error err) { 1284 System.out.println("Error when obj = " + objToSave); 1285 // err.printStackTrace(); 1286 throw err; 1287 } 1288 } 1289 1290 @TestTargetNew( 1291 level = TestLevel.COMPLETE, 1292 notes = "Verifies serialization.", 1293 method = "!Serialization", 1294 args = {} 1295 ) 1296 public void test_OptionalDataNotRead() { 1297 // Test for method void 1298 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1299 1300 Object objToSave = null; 1301 Object objLoaded; 1302 1303 try { 1304 OptionalDataNotRead test = new OptionalDataNotRead(); 1305 // Have to save an object after the one above, and when we read it, 1306 // it cannot be a byte[] 1307 Date now = new Date(); 1308 Object[] twoObjects = new Object[2]; 1309 twoObjects[0] = test; 1310 twoObjects[1] = now; 1311 objToSave = twoObjects; 1312 if (DEBUG) 1313 System.out.println("Obj = " + objToSave); 1314 objLoaded = dumpAndReload(objToSave); 1315 // Has to have worked 1316 Object[] twoLoadedObjects = (Object[]) objLoaded; 1317 assertTrue(MSG_TEST_FAILED + objToSave, twoLoadedObjects[0] 1318 .getClass() == OptionalDataNotRead.class); 1319 assertTrue(MSG_TEST_FAILED + objToSave, twoLoadedObjects[1] 1320 .getClass() == Date.class); 1321 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 @TestTargetNew( 1336 level = TestLevel.COMPLETE, 1337 notes = "Verifies serialization.", 1338 method = "!Serialization", 1339 args = {} 1340 ) 1341 public void test_18_55_writeObject() { 1342 // Test for method void 1343 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1344 1345 Object objToSave = null; 1346 Object objLoaded; 1347 1348 try { 1349 Object[] threeObjects = new Object[3]; 1350 threeObjects[0] = new Integer(2); 1351 threeObjects[1] = Date.class; 1352 threeObjects[2] = threeObjects[0]; // has to be the same 1353 objToSave = threeObjects; 1354 if (DEBUG) 1355 System.out.println("Obj = " + objToSave); 1356 objLoaded = dumpAndReload(objToSave); 1357 // Has to have worked 1358 Object[] threeLoadedObjects = (Object[]) objLoaded; 1359 assertTrue(MSG_TEST_FAILED + objToSave, threeLoadedObjects[0] 1360 .getClass() == Integer.class); 1361 assertTrue(MSG_TEST_FAILED + objToSave, 1362 threeLoadedObjects[1] == Date.class); 1363 assertTrue(MSG_TEST_FAILED + objToSave, 1364 threeLoadedObjects[0] == threeLoadedObjects[2]); 1365 1366 } catch (IOException e) { 1367 fail("IOException serializing " + objToSave + " : " 1368 + e.getMessage()); 1369 } catch (ClassNotFoundException e) { 1370 fail("ClassNotFoundException reading Object type : " 1371 + e.getMessage()); 1372 } catch (Error err) { 1373 System.out.println("Error when obj = " + objToSave); 1374 // err.printStackTrace(); 1375 throw err; 1376 } 1377 } 1378 1379 @TestTargetNew( 1380 level = TestLevel.COMPLETE, 1381 notes = "Verifies serialization.", 1382 method = "!Serialization", 1383 args = {} 1384 ) 1385 public void test_18_56_writeObject() { 1386 // Test for method void 1387 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1388 1389 Object objToSave = null; 1390 Object objLoaded; 1391 1392 try { 1393 // Test for 1FD24BY 1394 NestedPutField test = new NestedPutField(); 1395 objToSave = test; 1396 if (DEBUG) 1397 System.out.println("Obj = " + objToSave); 1398 objLoaded = dumpAndReload(objToSave); 1399 // Has to have worked 1400 assertNotNull(MSG_TEST_FAILED + objToSave, 1401 ((NestedPutField) objLoaded).field1); 1402 1403 } catch (IOException e) { 1404 fail("IOException serializing " + objToSave + " : " 1405 + e.getMessage()); 1406 } catch (ClassNotFoundException e) { 1407 fail("ClassNotFoundException reading Object type : " 1408 + e.getMessage()); 1409 } catch (Error err) { 1410 System.out.println("Error when obj = " + objToSave); 1411 // err.printStackTrace(); 1412 throw err; 1413 } 1414 } 1415 1416 @TestTargetNew( 1417 level = TestLevel.COMPLETE, 1418 notes = "Verifies serialization.", 1419 method = "!Serialization", 1420 args = {} 1421 ) 1422 @KnownFailure("Executed replacement when it should not: class java.lang.String") 1423 public void test_18_57_writeObject() { 1424 // Test for method void 1425 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1426 1427 Object objToSave = null; 1428 1429 try { 1430 ByteArrayOutputStream out; 1431 StreamBasedReplacementWhenDumping streamBasedReplacementWhenDumping; 1432 1433 out = new ByteArrayOutputStream(); 1434 streamBasedReplacementWhenDumping = new StreamBasedReplacementWhenDumping( 1435 out); 1436 ; 1437 objToSave = FOO.getClass(); 1438 if (DEBUG) 1439 System.out.println("Obj = " + objToSave); 1440 streamBasedReplacementWhenDumping.writeObject(objToSave); 1441 // Has to have run the replacement method 1442 assertTrue("Executed replacement when it should not: " + objToSave, 1443 !streamBasedReplacementWhenDumping.calledClassReplacement); 1444 1445 } catch (IOException e) { 1446 fail("Exception serializing " + objToSave + "\t->" 1447 + e.toString()); 1448 } catch (Error err) { 1449 System.out.println("Error " + err + " when obj = " + objToSave); 1450 throw err; 1451 } 1452 } 1453 1454 @TestTargetNew( 1455 level = TestLevel.COMPLETE, 1456 notes = "Verifies serialization.", 1457 method = "!Serialization", 1458 args = {} 1459 ) 1460 @KnownFailure("Executed replacement when it should not: class java.lang.String") 1461 public void test_18_58_writeObject() { 1462 // Test for method void 1463 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1464 1465 Object objToSave = null; 1466 1467 try { 1468 ByteArrayOutputStream out; 1469 StreamBasedReplacementWhenDumping streamBasedReplacementWhenDumping; 1470 1471 out = new ByteArrayOutputStream(); 1472 streamBasedReplacementWhenDumping = new StreamBasedReplacementWhenDumping( 1473 out); 1474 ; 1475 objToSave = ObjectStreamClass.lookup(FOO.getClass()); 1476 if (DEBUG) 1477 System.out.println("Obj = " + objToSave); 1478 streamBasedReplacementWhenDumping.writeObject(objToSave); 1479 // Has to have run the replacement method 1480 assertTrue( 1481 "Executed replacement when it should not: " + objToSave, 1482 !streamBasedReplacementWhenDumping.calledObjectStreamClassReplacement); 1483 1484 } catch (IOException e) { 1485 fail("Exception serializing " + objToSave + "\t->" 1486 + e.toString()); 1487 } catch (Error err) { 1488 System.out.println("Error " + err + " when obj = " + objToSave); 1489 throw err; 1490 } 1491 } 1492 1493 @TestTargetNew( 1494 level = TestLevel.COMPLETE, 1495 notes = "Verifies serialization.", 1496 method = "!Serialization", 1497 args = {} 1498 ) 1499 public void test_18_59_writeObject() { 1500 // Test for method void 1501 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1502 1503 Object objToSave = null; 1504 1505 try { 1506 ByteArrayOutputStream out; 1507 StreamBasedReplacementWhenDumping streamBasedReplacementWhenDumping; 1508 1509 out = new ByteArrayOutputStream(); 1510 streamBasedReplacementWhenDumping = new StreamBasedReplacementWhenDumping( 1511 out); 1512 ; 1513 objToSave = new int[3]; 1514 if (DEBUG) 1515 System.out.println("Obj = " + objToSave); 1516 streamBasedReplacementWhenDumping.writeObject(objToSave); 1517 // Has to have run the replacement method 1518 assertTrue("DId not execute replacement when it should: " 1519 + objToSave, 1520 streamBasedReplacementWhenDumping.calledArrayReplacement); 1521 1522 } catch (IOException e) { 1523 fail("Exception serializing " + objToSave + "\t->" 1524 + e.toString()); 1525 } catch (Error err) { 1526 System.out.println("Error " + err + " when obj = " + objToSave); 1527 throw err; 1528 } 1529 } 1530 1531 @TestTargetNew( 1532 level = TestLevel.COMPLETE, 1533 notes = "Verifies serialization.", 1534 method = "!Serialization", 1535 args = {} 1536 ) 1537 public void test_18_60_writeObject() { 1538 // Test for method void 1539 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1540 1541 Object objToSave = null; 1542 1543 try { 1544 ByteArrayOutputStream out; 1545 StreamBasedReplacementWhenDumping streamBasedReplacementWhenDumping; 1546 1547 out = new ByteArrayOutputStream(); 1548 streamBasedReplacementWhenDumping = new StreamBasedReplacementWhenDumping( 1549 out); 1550 ; 1551 objToSave = FOO; 1552 if (DEBUG) 1553 System.out.println("Obj = " + objToSave); 1554 streamBasedReplacementWhenDumping.writeObject(objToSave); 1555 // Has to have run the replacement method 1556 assertTrue("Did not execute replacement when it should: " 1557 + objToSave, 1558 streamBasedReplacementWhenDumping.calledStringReplacement); 1559 1560 } catch (IOException e) { 1561 fail("Exception serializing " + objToSave + "\t->" 1562 + e.toString()); 1563 } catch (Error err) { 1564 System.out.println("Error " + err + " when obj = " + objToSave); 1565 throw err; 1566 } 1567 } 1568 1569 @TestTargetNew( 1570 level = TestLevel.COMPLETE, 1571 notes = "Verifies serialization.", 1572 method = "!Serialization", 1573 args = {} 1574 ) 1575 public void test_18_61_writeObject() { 1576 // Test for method void 1577 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1578 1579 Object objToSave = null; 1580 Object objLoaded; 1581 1582 try { 1583 ArrayOfSerializable test = new ArrayOfSerializable(); 1584 objToSave = test; 1585 if (DEBUG) 1586 System.out.println("Obj = " + objToSave); 1587 objLoaded = dumpAndReload(objToSave); 1588 // Has to have worked 1589 assertTrue(MSG_TEST_FAILED + objToSave, true); 1590 assertNotNull(objLoaded); 1591 1592 } catch (IOException e) { 1593 fail("IOException serializing " + objToSave + " : " 1594 + e.getMessage()); 1595 } catch (ClassNotFoundException e) { 1596 fail("ClassNotFoundException reading Object type : " 1597 + e.getMessage()); 1598 } catch (Error err) { 1599 System.out.println("Error when obj = " + objToSave); 1600 // err.printStackTrace(); 1601 throw err; 1602 } 1603 } 1604 1605 @TestTargetNew( 1606 level = TestLevel.COMPLETE, 1607 notes = "Verifies serialization.", 1608 method = "!Serialization", 1609 args = {} 1610 ) 1611 public void test_18_62_writeObject() { 1612 // Test for method void 1613 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1614 1615 Object objToSave = null; 1616 Object objLoaded; 1617 1618 try { 1619 ClassSubClassTest1 test = new ClassSubClassTest1( 1620 "SuperInitialString", "SubInitialString"); 1621 objToSave = test; 1622 if (DEBUG) 1623 System.out.println("Obj = " + objToSave); 1624 objLoaded = dumpAndReload(objToSave); 1625 // Has to have worked 1626 assertTrue(MSG_TEST_FAILED + objToSave, test.equals(objLoaded)); 1627 1628 } catch (IOException e) { 1629 fail("IOException serializing " + objToSave + " : " 1630 + e.getMessage()); 1631 } catch (ClassNotFoundException e) { 1632 fail("ClassNotFoundException reading Object type : " 1633 + e.getMessage()); 1634 } catch (Error err) { 1635 System.out.println("Error when obj = " + objToSave); 1636 // err.printStackTrace(); 1637 throw err; 1638 } 1639 } 1640 1641 @TestTargetNew( 1642 level = TestLevel.COMPLETE, 1643 notes = "Verifies serialization.", 1644 method = "!Serialization", 1645 args = {} 1646 ) 1647 public void test_18_63_writeObject() { 1648 // Test for method void 1649 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1650 1651 Object objToSave = null; 1652 Object objLoaded; 1653 1654 try { 1655 ConstructorTestC test = new ConstructorTestC(); 1656 objToSave = test; 1657 if (DEBUG) 1658 System.out.println("Obj = " + objToSave); 1659 objLoaded = dumpAndReload(objToSave); 1660 // Has to have worked 1661 assertTrue(MSG_TEST_FAILED + objToSave, test.verify(objLoaded)); 1662 1663 } catch (IOException e) { 1664 fail("IOException serializing " + objToSave + " : " 1665 + e.getMessage()); 1666 } catch (ClassNotFoundException e) { 1667 fail("ClassNotFoundException reading Object type : " 1668 + e.getMessage()); 1669 } catch (Error err) { 1670 System.out.println("Error when obj = " + objToSave); 1671 // err.printStackTrace(); 1672 throw err; 1673 } 1674 } 1675 1676 @TestTargetNew( 1677 level = TestLevel.COMPLETE, 1678 notes = "Verifies serialization.", 1679 method = "!Serialization", 1680 args = {} 1681 ) 1682 public void test_18_64_writeObject() { 1683 // Test for method void 1684 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1685 1686 Object objToSave = null; 1687 Object objLoaded; 1688 1689 try { 1690 HashCodeTest test = new HashCodeTest(); 1691 objToSave = test; 1692 if (DEBUG) 1693 System.out.println("Obj = " + objToSave); 1694 objLoaded = dumpAndReload(objToSave); 1695 // Has to have worked 1696 assertTrue(MSG_TEST_FAILED + objToSave, 1697 !((HashCodeTest) objLoaded).serializationUsesHashCode); 1698 1699 } catch (IOException e) { 1700 fail("IOException serializing " + objToSave + " : " 1701 + e.getMessage()); 1702 } catch (ClassNotFoundException e) { 1703 fail("ClassNotFoundException reading Object type : " 1704 + e.getMessage()); 1705 } catch (Error err) { 1706 System.out.println("Error when obj = " + objToSave); 1707 // err.printStackTrace(); 1708 throw err; 1709 } 1710 } 1711 1712 @TestTargetNew( 1713 level = TestLevel.COMPLETE, 1714 notes = "Verifies serialization.", 1715 method = "!Serialization", 1716 args = {} 1717 ) 1718 public void test_18_65_writeObject() { 1719 // Test for method void 1720 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1721 1722 Object objToSave = null; 1723 Object objLoaded; 1724 1725 try { 1726 InitializerFieldsTest test = new InitializerFieldsTest(); 1727 test.toBeSerialized = "serializing"; 1728 InitializerFieldsTest.toBeNotSerialized = "It should not have this value after loaded from a File"; 1729 InitializerFieldsTest.toBeNotSerialized2 = "Good-This is the rigth value."; 1730 1731 objToSave = test; 1732 if (DEBUG) 1733 System.out.println("Obj = " + objToSave); 1734 dump(objToSave); 1735 InitializerFieldsTest.toBeNotSerialized = new String( 1736 InitializerFieldsTest.toBeNotSerialized2); 1737 objLoaded = reload(); 1738 1739 // Has to have worked 1740 assertTrue(MSG_TEST_FAILED + objToSave, (test.equals(objLoaded))); 1741 1742 } catch (IOException e) { 1743 fail("IOException serializing " + objToSave + " : " 1744 + e.getMessage()); 1745 } catch (ClassNotFoundException e) { 1746 fail("ClassNotFoundException reading Object type : " 1747 + e.getMessage()); 1748 } catch (Error err) { 1749 System.out.println("Error when obj = " + objToSave); 1750 // err.printStackTrace(); 1751 throw err; 1752 } 1753 } 1754 1755 @TestTargetNew( 1756 level = TestLevel.COMPLETE, 1757 notes = "Verifies serialization.", 1758 method = "!Serialization", 1759 args = {} 1760 ) 1761 public void test_18_66_writeObject() { 1762 // Test for method void 1763 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1764 1765 Object objToSave = null; 1766 Object objLoaded; 1767 1768 try { 1769 InitializerFieldsTest2 test = new InitializerFieldsTest2(); 1770 test.toBeSerialized = "serializing"; 1771 test.toBeSerialized3 = "serializing3"; 1772 test.toBeSerialized4 = "serializing4"; 1773 test.toBeSerialized5 = "serializing5"; 1774 InitializerFieldsTest2.toBeNotSerialized = "It should not have this value after loaded from a File"; 1775 InitializerFieldsTest2.toBeNotSerialized2 = "Good-This is the rigth value."; 1776 1777 objToSave = test; 1778 if (DEBUG) 1779 System.out.println("Obj = " + objToSave); 1780 dump(objToSave); 1781 InitializerFieldsTest2.toBeNotSerialized = new String( 1782 InitializerFieldsTest2.toBeNotSerialized2); 1783 objLoaded = reload(); 1784 1785 // Has to have worked 1786 assertTrue(MSG_TEST_FAILED + objToSave, (test.equals(objLoaded))); 1787 1788 } catch (IOException e) { 1789 fail("IOException serializing " + objToSave + " : " 1790 + e.getMessage()); 1791 } catch (ClassNotFoundException e) { 1792 fail("ClassNotFoundException reading Object type : " 1793 + e.getMessage()); 1794 } catch (Error err) { 1795 System.out.println("Error when obj = " + objToSave); 1796 // err.printStackTrace(); 1797 throw err; 1798 } 1799 } 1800 1801 @TestTargetNew( 1802 level = TestLevel.COMPLETE, 1803 notes = "Verifies serialization.", 1804 method = "!Serialization", 1805 args = {} 1806 ) 1807 public void test_18_67_writeObject() { 1808 // Test for method void 1809 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1810 1811 Object objToSave = null; 1812 Object objLoaded; 1813 1814 try { 1815 InitializerFieldsTest3 test = new InitializerFieldsTest3(); 1816 test.toBeSerialized = "serializing"; 1817 test.toBeSerialized3 = "serializing3"; 1818 test.toBeSerialized4 = "serializing4"; 1819 test.toBeSerialized5 = "serializing5"; 1820 InitializerFieldsTest2.toBeNotSerialized = "It should not have this value after loaded from a File"; 1821 InitializerFieldsTest2.toBeNotSerialized2 = "Good-This is the rigth value."; 1822 test.sub_toBeSerialized = "serializingSub"; 1823 test.sub_toBeSerialized3 = "serializing3sub"; 1824 test.sub_toBeSerialized4 = "serializing4sub"; 1825 test.sub_toBeSerialized5 = "serializing5sub"; 1826 InitializerFieldsTest3.sub_toBeNotSerialized = "(Subclass) It should not have this value after loaded from a File"; 1827 InitializerFieldsTest3.sub_toBeNotSerialized2 = "(Subclass) Good-This is the rigth value."; 1828 // Before dumping the two static vars are differents. 1829 // After dumping the value of toBeNotSerialized2 is put in 1830 // toBeNotSerialized 1831 // After loading it must be the same. 1832 objToSave = test; 1833 if (DEBUG) 1834 System.out.println("Obj = " + objToSave); 1835 dump(objToSave); 1836 InitializerFieldsTest2.toBeNotSerialized = new String( 1837 InitializerFieldsTest2.toBeNotSerialized2); 1838 InitializerFieldsTest3.sub_toBeNotSerialized = new String( 1839 InitializerFieldsTest3.sub_toBeNotSerialized2); 1840 objLoaded = reload(); 1841 1842 // Has to have worked 1843 assertTrue(MSG_TEST_FAILED + objToSave, (test.equals(objLoaded))); 1844 1845 } catch (IOException e) { 1846 fail("IOException serializing " + objToSave + " : " 1847 + e.getMessage()); 1848 } catch (ClassNotFoundException e) { 1849 fail("ClassNotFoundException reading Object type : " 1850 + e.getMessage()); 1851 } catch (Error err) { 1852 System.out.println("Error when obj = " + objToSave); 1853 // err.printStackTrace(); 1854 throw err; 1855 } 1856 } 1857 1858 @TestTargetNew( 1859 level = TestLevel.COMPLETE, 1860 notes = "Verifies serialization.", 1861 method = "!Serialization", 1862 args = {} 1863 ) 1864 public void test_DeepNesting() { 1865 // Test for method void 1866 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1867 1868 Object objToSave = null; 1869 Object objLoaded; 1870 1871 try { 1872 DeepNesting test = new DeepNesting(11); 1873 objToSave = test; 1874 if (DEBUG) 1875 System.out.println("Obj = " + objToSave); 1876 objLoaded = dumpAndReload(objToSave); 1877 1878 // Has to have worked 1879 assertTrue(MSG_TEST_FAILED + objToSave, (test.equals(objLoaded))); 1880 1881 } catch (IOException e) { 1882 fail("IOException serializing " + objToSave + " : " 1883 + e.getMessage()); 1884 } catch (ClassNotFoundException e) { 1885 fail("ClassNotFoundException reading Object type : " 1886 + e.getMessage()); 1887 } catch (Error err) { 1888 // err.printStackTrace(); 1889 System.out.println("Error " + err + " when obj = " + objToSave); 1890 throw err; 1891 } 1892 } 1893 1894 @TestTargetNew( 1895 level = TestLevel.COMPLETE, 1896 notes = "Verifies serialization.", 1897 method = "!Serialization", 1898 args = {} 1899 ) 1900 public void test_DeepNestingWithWriteObject() throws Throwable { 1901 // Test for method void 1902 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1903 1904 // this test was wrapped in a Thread so we can increase the max stack 1905 // size to more than the default 8K. In this case we assign 256K 1906 Thread t = new Thread(null, null, "deep nested", 256*1024) { 1907 1908 @Override 1909 public void run() { 1910 try { 1911 deepNestingHelper(); 1912 } catch (Throwable e) { 1913 error = e; 1914 } 1915 } 1916 }; 1917 t.start(); 1918 1919 t.join(); 1920 1921 if (error != null) { 1922 throw error; 1923 } 1924 } 1925 1926 static Throwable error; 1927 1928 public void deepNestingHelper() throws IOException, 1929 ClassNotFoundException { 1930 // Test for method void 1931 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1932 1933 DeepNestingWithWriteObject test = new DeepNestingWithWriteObject(50); 1934 if (DEBUG) { 1935 System.out.println("Obj = " + test); 1936 } 1937 1938 Object objLoaded = dumpAndReload(test); 1939 1940 // Has to have worked 1941 assertTrue(MSG_TEST_FAILED + test, (test.equals(objLoaded))); 1942 } 1943 1944 @TestTargetNew( 1945 level = TestLevel.COMPLETE, 1946 notes = "Verifies serialization.", 1947 method = "!Serialization", 1948 args = {} 1949 ) 1950 public void test_18_69_writeObject() { 1951 // Test for method void 1952 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1953 1954 Object objToSave = null; 1955 Object objLoaded; 1956 1957 try { 1958 NonPublicClassTest test = new NonPublicClassTest(); 1959 test.x10(); 1960 objToSave = test; 1961 if (DEBUG) 1962 System.out.println("Obj = " + objToSave); 1963 objLoaded = dumpAndReload(objToSave); 1964 1965 // Has to have worked 1966 assertTrue(MSG_TEST_FAILED + objToSave, (test.equals(objLoaded))); 1967 1968 } catch (IOException e) { 1969 fail("IOException serializing " + objToSave + " : " 1970 + e.getMessage()); 1971 } catch (ClassNotFoundException e) { 1972 fail("ClassNotFoundException reading Object type : " 1973 + e.getMessage()); 1974 } catch (Error err) { 1975 System.out.println("Error when obj = " + objToSave); 1976 // err.printStackTrace(); 1977 throw err; 1978 } 1979 } 1980 1981 @TestTargetNew( 1982 level = TestLevel.COMPLETE, 1983 notes = "Verifies serialization.", 1984 method = "!Serialization", 1985 args = {} 1986 ) 1987 public void test_18_70_writeObject() { 1988 // Test for method void 1989 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1990 1991 Object objToSave = null; 1992 Object objLoaded; 1993 1994 try { 1995 int[] test = new int[1]; 1996 int intValue = 0; 1997 test[0] = intValue; 1998 objToSave = test; 1999 if (DEBUG) 2000 System.out.println("Obj = " + objToSave); 2001 objLoaded = dumpAndReload(objToSave); 2002 2003 // Has to have worked 2004 assertTrue(MSG_TEST_FAILED + objToSave, Arrays.equals(test, 2005 (int[]) objLoaded)); 2006 2007 } catch (IOException e) { 2008 fail("IOException serializing " + objToSave + " : " 2009 + e.getMessage()); 2010 } catch (ClassNotFoundException e) { 2011 fail("ClassNotFoundException reading Object type : " 2012 + e.getMessage()); 2013 } catch (Error err) { 2014 System.out.println("Error when obj = " + objToSave); 2015 // err.printStackTrace(); 2016 throw err; 2017 } 2018 } 2019 2020 @TestTargetNew( 2021 level = TestLevel.COMPLETE, 2022 notes = "Verifies serialization.", 2023 method = "!Serialization", 2024 args = {} 2025 ) 2026 public void test_18_71_writeObject() { 2027 // Test for method void 2028 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2029 2030 Object objToSave = null; 2031 Object objLoaded; 2032 2033 try { 2034 int i, j, maxJ = 3, maxI = 200; 2035 byte[][] obj = new byte[maxJ][maxI]; 2036 for (j = 0; j < maxJ; j++) { 2037 for (i = 0; i < maxI; i++) 2038 obj[j][i] = (byte) (i - 100); 2039 } 2040 objToSave = obj; 2041 if (DEBUG) 2042 System.out.println("Obj = " + objToSave); 2043 objLoaded = dumpAndReload(objToSave); 2044 byte[][] toCompare = (byte[][]) objLoaded; 2045 2046 boolean ok = true; 2047 // Has to have worked 2048 for (j = 0; j < maxJ; j++) { 2049 for (i = 0; i < maxI; i++) 2050 if (obj[j][i] != toCompare[j][i]) { 2051 ok = false; 2052 break; 2053 } 2054 } 2055 2056 assertTrue(MSG_TEST_FAILED + objToSave, ok); 2057 2058 } catch (IOException e) { 2059 fail("IOException serializing " + objToSave + " : " 2060 + e.getMessage()); 2061 } catch (ClassNotFoundException e) { 2062 fail("ClassNotFoundException reading Object type : " 2063 + e.getMessage()); 2064 } catch (Error err) { 2065 System.out.println("Error when obj = " + objToSave); 2066 // err.printStackTrace(); 2067 throw err; 2068 } 2069 } 2070 2071 @TestTargetNew( 2072 level = TestLevel.COMPLETE, 2073 notes = "Verifies serialization.", 2074 method = "!Serialization", 2075 args = {} 2076 ) 2077 public void test_18_72_writeObject() { 2078 // Test for method void 2079 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2080 2081 Object objToSave = null; 2082 Object objLoaded; 2083 2084 try { 2085 int i, j, maxJ = 3, maxI = 200; 2086 int[][] obj = new int[maxJ][maxI]; 2087 for (j = 0; j < maxJ; j++) { 2088 for (i = 0; i < maxI; i++) 2089 obj[j][i] = (i - 100); 2090 } 2091 objToSave = obj; 2092 if (DEBUG) 2093 System.out.println("Obj = " + objToSave); 2094 objLoaded = dumpAndReload(objToSave); 2095 int[][] toCompare = (int[][]) objLoaded; 2096 2097 boolean ok = true; 2098 // Has to have worked 2099 for (j = 0; j < maxJ; j++) { 2100 for (i = 0; i < maxI; i++) 2101 if (obj[j][i] != toCompare[j][i]) { 2102 ok = false; 2103 break; 2104 } 2105 } 2106 2107 assertTrue(MSG_TEST_FAILED + objToSave, ok); 2108 2109 } catch (IOException e) { 2110 fail("IOException serializing " + objToSave + " : " 2111 + e.getMessage()); 2112 } catch (ClassNotFoundException e) { 2113 fail("ClassNotFoundException reading Object type : " 2114 + e.getMessage()); 2115 } catch (Error err) { 2116 System.out.println("Error when obj = " + objToSave); 2117 // err.printStackTrace(); 2118 throw err; 2119 } 2120 } 2121 2122 @TestTargetNew( 2123 level = TestLevel.COMPLETE, 2124 notes = "Verifies serialization.", 2125 method = "!Serialization", 2126 args = {} 2127 ) 2128 public void test_18_73_writeObject() { 2129 // Test for method void 2130 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2131 2132 Object objToSave = null; 2133 Object objLoaded; 2134 2135 try { 2136 String org = "abcdefghijklmnopqrstuvxyz1234567890abcdefghijklmnopqrstuvxyz1234567890"; 2137 int i, j, maxJ = 3, maxI = 70; 2138 String[][] obj = new String[maxJ][maxI]; 2139 for (j = 0; j < maxJ; j++) { 2140 for (i = 0; i < maxI; i++) 2141 obj[j][i] = org.substring(0, i); 2142 } 2143 objToSave = obj; 2144 if (DEBUG) 2145 System.out.println("Obj = " + objToSave); 2146 objLoaded = dumpAndReload(objToSave); 2147 String[][] toCompare = (String[][]) objLoaded; 2148 2149 boolean ok = true; 2150 // Has to have worked 2151 for (j = 0; j < maxJ; j++) { 2152 for (i = 0; i < maxI; i++) 2153 if (!obj[j][i].equals(toCompare[j][i])) { 2154 ok = false; 2155 break; 2156 } 2157 } 2158 2159 assertTrue(MSG_TEST_FAILED + objToSave, ok); 2160 2161 } catch (IOException e) { 2162 fail("IOException serializing " + objToSave + " : " 2163 + e.getMessage()); 2164 } catch (ClassNotFoundException e) { 2165 fail("ClassNotFoundException reading Object type : " 2166 + e.getMessage()); 2167 } catch (Error err) { 2168 System.out.println("Error when obj = " + objToSave); 2169 // err.printStackTrace(); 2170 throw err; 2171 } 2172 } 2173 2174 @TestTargetNew( 2175 level = TestLevel.COMPLETE, 2176 notes = "Verifies serialization.", 2177 method = "!Serialization", 2178 args = {} 2179 ) 2180 public void test_18_74_writeObject() { 2181 // Test for method void 2182 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2183 2184 Object objToSave = null; 2185 Object objLoaded; 2186 2187 try { 2188 SameInstVarNameSubClass test = new SameInstVarNameSubClass(100); 2189 objToSave = test; 2190 if (DEBUG) 2191 System.out.println("Obj = " + objToSave); 2192 objLoaded = dumpAndReload(objToSave); 2193 // Has to have worked 2194 assertTrue(MSG_TEST_FAILED + objToSave, 2195 ((SameInstVarNameSubClass) objLoaded).foo == 100); 2196 2197 } catch (IOException e) { 2198 fail("IOException serializing " + objToSave + " : " 2199 + e.getMessage()); 2200 } catch (ClassNotFoundException e) { 2201 fail("ClassNotFoundException reading Object type : " 2202 + e.getMessage()); 2203 } catch (Error err) { 2204 System.out.println("Error when obj = " + objToSave); 2205 // err.printStackTrace(); 2206 throw err; 2207 } 2208 } 2209 2210 @TestTargetNew( 2211 level = TestLevel.COMPLETE, 2212 notes = "Verifies serialization.", 2213 method = "!Serialization", 2214 args = {} 2215 ) 2216 public void test_18_75_writeObject() { 2217 // Test for method void 2218 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2219 2220 Object objToSave = null; 2221 Object objLoaded; 2222 2223 try { 2224 SInterfaceTest test = new SInterfaceTest(); 2225 objToSave = test; 2226 if (DEBUG) 2227 System.out.println("Obj = " + objToSave); 2228 objLoaded = dumpAndReload(objToSave); 2229 // Has to have worked 2230 assertTrue(MSG_TEST_FAILED + objToSave, test.equals(objLoaded)); 2231 2232 } catch (IOException e) { 2233 fail("IOException serializing " + objToSave + " : " 2234 + e.getMessage()); 2235 } catch (ClassNotFoundException e) { 2236 fail("ClassNotFoundException reading Object type : " 2237 + e.getMessage()); 2238 } catch (Error err) { 2239 System.out.println("Error when obj = " + objToSave); 2240 // err.printStackTrace(); 2241 throw err; 2242 } 2243 } 2244 2245 @TestTargetNew( 2246 level = TestLevel.COMPLETE, 2247 notes = "Verifies serialization.", 2248 method = "!Serialization", 2249 args = {} 2250 ) 2251 public void test_18_76_writeObject() { 2252 // Test for method void 2253 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2254 2255 Object objToSave = null; 2256 Object objLoaded; 2257 2258 try { 2259 SInterfaceTest2 test = new SInterfaceTest2(); 2260 objToSave = test; 2261 if (DEBUG) 2262 System.out.println("Obj = " + objToSave); 2263 objLoaded = dumpAndReload(objToSave); 2264 // Has to have worked 2265 assertTrue(MSG_TEST_FAILED + objToSave, test.equals(objLoaded)); 2266 2267 } catch (IOException e) { 2268 fail("IOException serializing " + objToSave + " : " 2269 + e.getMessage()); 2270 } catch (ClassNotFoundException e) { 2271 fail("ClassNotFoundException reading Object type : " 2272 + e.getMessage()); 2273 } catch (Error err) { 2274 System.out.println("Error when obj = " + objToSave); 2275 // err.printStackTrace(); 2276 throw err; 2277 } 2278 } 2279 2280 @TestTargetNew( 2281 level = TestLevel.COMPLETE, 2282 notes = "Verifies serialization.", 2283 method = "!Serialization", 2284 args = {} 2285 ) 2286 public void test_18_77_writeObject() { 2287 // Test for method void 2288 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2289 2290 Object objToSave = null; 2291 Object objLoaded; 2292 2293 try { 2294 SuperclassTest test = new SuperclassTest(); 2295 objToSave = test; 2296 if (DEBUG) 2297 System.out.println("Obj = " + objToSave); 2298 objLoaded = dumpAndReload(objToSave); 2299 // Has to have worked 2300 assertTrue(MSG_TEST_FAILED + objToSave, test.equals(objLoaded)); 2301 2302 } catch (IOException e) { 2303 fail("IOException serializing " + objToSave + " : " 2304 + e.getMessage()); 2305 } catch (ClassNotFoundException e) { 2306 fail("ClassNotFoundException reading Object type : " 2307 + e.getMessage()); 2308 } catch (Error err) { 2309 System.out.println("Error when obj = " + objToSave); 2310 // err.printStackTrace(); 2311 throw err; 2312 } 2313 } 2314 2315 @TestTargetNew( 2316 level = TestLevel.COMPLETE, 2317 notes = "Verifies serialization.", 2318 method = "!Serialization", 2319 args = {} 2320 ) 2321 public void test_18_78_writeObject() { 2322 // Test for method void 2323 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2324 2325 Object objToSave = null; 2326 Object objLoaded; 2327 2328 try { 2329 SuperclassTest2 test = new SuperclassTest2(); 2330 objToSave = test; 2331 if (DEBUG) 2332 System.out.println("Obj = " + objToSave); 2333 objLoaded = dumpAndReload(objToSave); 2334 // Has to have worked 2335 assertTrue(MSG_TEST_FAILED + objToSave, test.equals(objLoaded)); 2336 2337 } catch (IOException e) { 2338 fail("IOException serializing " + objToSave + " : " 2339 + e.getMessage()); 2340 } catch (ClassNotFoundException e) { 2341 fail("ClassNotFoundException reading Object type : " 2342 + e.getMessage()); 2343 } catch (Error err) { 2344 System.out.println("Error when obj = " + objToSave); 2345 // err.printStackTrace(); 2346 throw err; 2347 } 2348 } 2349 2350 @TestTargetNew( 2351 level = TestLevel.COMPLETE, 2352 notes = "Verifies serialization.", 2353 method = "!Serialization", 2354 args = {} 2355 ) 2356 public void test_18_79_writeObject() { 2357 // Test for method void 2358 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2359 2360 Object objToSave = null; 2361 Object objLoaded; 2362 2363 try { 2364 SyntheticFieldTest test = new SyntheticFieldTest(); 2365 objToSave = test; 2366 if (DEBUG) 2367 System.out.println("Obj = " + objToSave); 2368 objLoaded = dumpAndReload(objToSave); 2369 // Has to have worked 2370 assertTrue(MSG_TEST_FAILED + objToSave, test.equals(objLoaded)); 2371 2372 } catch (IOException e) { 2373 fail("IOException serializing " + objToSave + " : " 2374 + e.getMessage()); 2375 } catch (ClassNotFoundException e) { 2376 fail("ClassNotFoundException reading Object type : " 2377 + e.getMessage()); 2378 } catch (Error err) { 2379 System.out.println("Error when obj = " + objToSave); 2380 // err.printStackTrace(); 2381 throw err; 2382 } 2383 } 2384 2385 @TestTargetNew( 2386 level = TestLevel.COMPLETE, 2387 notes = "Verifies serialization.", 2388 method = "!Serialization", 2389 args = {} 2390 ) 2391 public void test_18_80_writeObject() { 2392 // Test for method void 2393 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2394 2395 try { 2396 ByteArrayOutputStream out = new ByteArrayOutputStream(); 2397 DataOutputStream dos = new DataOutputStream(out); 2398 new ObjectOutputStream(dos); // just to make sure we get a header 2399 dos.writeByte(ObjectStreamConstants.TC_BLOCKDATA); 2400 int length = 99; 2401 dos.writeByte(length); 2402 for (int i = 0; i < length; i++) { 2403 dos.writeByte(0); // actual value does not matter 2404 } 2405 dos.flush(); 2406 int lengthRead = 0; 2407 try { 2408 ObjectInputStream ois = new ObjectInputStream( 2409 new ByteArrayInputStream(out.toByteArray())); 2410 ois.readObject(); 2411 } catch (OptionalDataException e) { 2412 lengthRead = e.length; 2413 } 2414 assertTrue("Did not throw exception with optional data size ", 2415 length == lengthRead); 2416 } catch (ClassNotFoundException e) { 2417 fail("Unable to read BLOCKDATA: " + e.getMessage()); 2418 } catch (IOException e) { 2419 fail("IOException testing BLOCKDATA : " + e.getMessage()); 2420 } catch (Error err) { 2421 System.out.println("Error " + err + " when testing BLOCKDATA"); 2422 throw err; 2423 } 2424 } 2425} 2426