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