SerializationStressTest2.java revision a99b695964e28a5906003d40db48cbd550fbcdf4
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 @KnownFailure("Maybe the stack gets too deep for android. Change the test?") 1904 public void test_DeepNestingWithWriteObject() { 1905 // Test for method void 1906 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1907 1908 Object objToSave = null; 1909 Object objLoaded; 1910 1911 try { 1912 DeepNestingWithWriteObject test = new DeepNestingWithWriteObject(50); 1913 objToSave = test; 1914 if (DEBUG) 1915 System.out.println("Obj = " + objToSave); 1916 objLoaded = dumpAndReload(objToSave); 1917 1918 // Has to have worked 1919 assertTrue(MSG_TEST_FAILED + objToSave, (test.equals(objLoaded))); 1920 1921 } catch (IOException e) { 1922 fail("IOException serializing " + objToSave + " : " 1923 + e.getMessage()); 1924 } catch (ClassNotFoundException e) { 1925 fail("ClassNotFoundException reading Object type : " 1926 + e.getMessage()); 1927 } catch (Error err) { 1928 // err.printStackTrace(); 1929 System.out.println("Error " + err + " when obj = " + objToSave); 1930 throw err; 1931 } 1932 } 1933 1934 @TestTargetNew( 1935 level = TestLevel.COMPLETE, 1936 notes = "Verifies serialization.", 1937 method = "!Serialization", 1938 args = {} 1939 ) 1940 public void test_18_69_writeObject() { 1941 // Test for method void 1942 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1943 1944 Object objToSave = null; 1945 Object objLoaded; 1946 1947 try { 1948 NonPublicClassTest test = new NonPublicClassTest(); 1949 test.x10(); 1950 objToSave = test; 1951 if (DEBUG) 1952 System.out.println("Obj = " + objToSave); 1953 objLoaded = dumpAndReload(objToSave); 1954 1955 // Has to have worked 1956 assertTrue(MSG_TEST_FAILED + objToSave, (test.equals(objLoaded))); 1957 1958 } catch (IOException e) { 1959 fail("IOException serializing " + objToSave + " : " 1960 + e.getMessage()); 1961 } catch (ClassNotFoundException e) { 1962 fail("ClassNotFoundException reading Object type : " 1963 + e.getMessage()); 1964 } catch (Error err) { 1965 System.out.println("Error when obj = " + objToSave); 1966 // err.printStackTrace(); 1967 throw err; 1968 } 1969 } 1970 1971 @TestTargetNew( 1972 level = TestLevel.COMPLETE, 1973 notes = "Verifies serialization.", 1974 method = "!Serialization", 1975 args = {} 1976 ) 1977 public void test_18_70_writeObject() { 1978 // Test for method void 1979 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1980 1981 Object objToSave = null; 1982 Object objLoaded; 1983 1984 try { 1985 int[] test = new int[1]; 1986 int intValue = 0; 1987 test[0] = intValue; 1988 objToSave = test; 1989 if (DEBUG) 1990 System.out.println("Obj = " + objToSave); 1991 objLoaded = dumpAndReload(objToSave); 1992 1993 // Has to have worked 1994 assertTrue(MSG_TEST_FAILED + objToSave, Arrays.equals(test, 1995 (int[]) objLoaded)); 1996 1997 } catch (IOException e) { 1998 fail("IOException serializing " + objToSave + " : " 1999 + e.getMessage()); 2000 } catch (ClassNotFoundException e) { 2001 fail("ClassNotFoundException reading Object type : " 2002 + e.getMessage()); 2003 } catch (Error err) { 2004 System.out.println("Error when obj = " + objToSave); 2005 // err.printStackTrace(); 2006 throw err; 2007 } 2008 } 2009 2010 @TestTargetNew( 2011 level = TestLevel.COMPLETE, 2012 notes = "Verifies serialization.", 2013 method = "!Serialization", 2014 args = {} 2015 ) 2016 public void test_18_71_writeObject() { 2017 // Test for method void 2018 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2019 2020 Object objToSave = null; 2021 Object objLoaded; 2022 2023 try { 2024 int i, j, maxJ = 3, maxI = 200; 2025 byte[][] obj = new byte[maxJ][maxI]; 2026 for (j = 0; j < maxJ; j++) { 2027 for (i = 0; i < maxI; i++) 2028 obj[j][i] = (byte) (i - 100); 2029 } 2030 objToSave = obj; 2031 if (DEBUG) 2032 System.out.println("Obj = " + objToSave); 2033 objLoaded = dumpAndReload(objToSave); 2034 byte[][] toCompare = (byte[][]) objLoaded; 2035 2036 boolean ok = true; 2037 // Has to have worked 2038 for (j = 0; j < maxJ; j++) { 2039 for (i = 0; i < maxI; i++) 2040 if (obj[j][i] != toCompare[j][i]) { 2041 ok = false; 2042 break; 2043 } 2044 } 2045 2046 assertTrue(MSG_TEST_FAILED + objToSave, ok); 2047 2048 } catch (IOException e) { 2049 fail("IOException serializing " + objToSave + " : " 2050 + e.getMessage()); 2051 } catch (ClassNotFoundException e) { 2052 fail("ClassNotFoundException reading Object type : " 2053 + e.getMessage()); 2054 } catch (Error err) { 2055 System.out.println("Error when obj = " + objToSave); 2056 // err.printStackTrace(); 2057 throw err; 2058 } 2059 } 2060 2061 @TestTargetNew( 2062 level = TestLevel.COMPLETE, 2063 notes = "Verifies serialization.", 2064 method = "!Serialization", 2065 args = {} 2066 ) 2067 public void test_18_72_writeObject() { 2068 // Test for method void 2069 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2070 2071 Object objToSave = null; 2072 Object objLoaded; 2073 2074 try { 2075 int i, j, maxJ = 3, maxI = 200; 2076 int[][] obj = new int[maxJ][maxI]; 2077 for (j = 0; j < maxJ; j++) { 2078 for (i = 0; i < maxI; i++) 2079 obj[j][i] = (i - 100); 2080 } 2081 objToSave = obj; 2082 if (DEBUG) 2083 System.out.println("Obj = " + objToSave); 2084 objLoaded = dumpAndReload(objToSave); 2085 int[][] toCompare = (int[][]) objLoaded; 2086 2087 boolean ok = true; 2088 // Has to have worked 2089 for (j = 0; j < maxJ; j++) { 2090 for (i = 0; i < maxI; i++) 2091 if (obj[j][i] != toCompare[j][i]) { 2092 ok = false; 2093 break; 2094 } 2095 } 2096 2097 assertTrue(MSG_TEST_FAILED + objToSave, ok); 2098 2099 } catch (IOException e) { 2100 fail("IOException serializing " + objToSave + " : " 2101 + e.getMessage()); 2102 } catch (ClassNotFoundException e) { 2103 fail("ClassNotFoundException reading Object type : " 2104 + e.getMessage()); 2105 } catch (Error err) { 2106 System.out.println("Error when obj = " + objToSave); 2107 // err.printStackTrace(); 2108 throw err; 2109 } 2110 } 2111 2112 @TestTargetNew( 2113 level = TestLevel.COMPLETE, 2114 notes = "Verifies serialization.", 2115 method = "!Serialization", 2116 args = {} 2117 ) 2118 public void test_18_73_writeObject() { 2119 // Test for method void 2120 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2121 2122 Object objToSave = null; 2123 Object objLoaded; 2124 2125 try { 2126 String org = "abcdefghijklmnopqrstuvxyz1234567890abcdefghijklmnopqrstuvxyz1234567890"; 2127 int i, j, maxJ = 3, maxI = 70; 2128 String[][] obj = new String[maxJ][maxI]; 2129 for (j = 0; j < maxJ; j++) { 2130 for (i = 0; i < maxI; i++) 2131 obj[j][i] = org.substring(0, i); 2132 } 2133 objToSave = obj; 2134 if (DEBUG) 2135 System.out.println("Obj = " + objToSave); 2136 objLoaded = dumpAndReload(objToSave); 2137 String[][] toCompare = (String[][]) objLoaded; 2138 2139 boolean ok = true; 2140 // Has to have worked 2141 for (j = 0; j < maxJ; j++) { 2142 for (i = 0; i < maxI; i++) 2143 if (!obj[j][i].equals(toCompare[j][i])) { 2144 ok = false; 2145 break; 2146 } 2147 } 2148 2149 assertTrue(MSG_TEST_FAILED + objToSave, ok); 2150 2151 } catch (IOException e) { 2152 fail("IOException serializing " + objToSave + " : " 2153 + e.getMessage()); 2154 } catch (ClassNotFoundException e) { 2155 fail("ClassNotFoundException reading Object type : " 2156 + e.getMessage()); 2157 } catch (Error err) { 2158 System.out.println("Error when obj = " + objToSave); 2159 // err.printStackTrace(); 2160 throw err; 2161 } 2162 } 2163 2164 @TestTargetNew( 2165 level = TestLevel.COMPLETE, 2166 notes = "Verifies serialization.", 2167 method = "!Serialization", 2168 args = {} 2169 ) 2170 public void test_18_74_writeObject() { 2171 // Test for method void 2172 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2173 2174 Object objToSave = null; 2175 Object objLoaded; 2176 2177 try { 2178 SameInstVarNameSubClass test = new SameInstVarNameSubClass(100); 2179 objToSave = test; 2180 if (DEBUG) 2181 System.out.println("Obj = " + objToSave); 2182 objLoaded = dumpAndReload(objToSave); 2183 // Has to have worked 2184 assertTrue(MSG_TEST_FAILED + objToSave, 2185 ((SameInstVarNameSubClass) objLoaded).foo == 100); 2186 2187 } catch (IOException e) { 2188 fail("IOException serializing " + objToSave + " : " 2189 + e.getMessage()); 2190 } catch (ClassNotFoundException e) { 2191 fail("ClassNotFoundException reading Object type : " 2192 + e.getMessage()); 2193 } catch (Error err) { 2194 System.out.println("Error when obj = " + objToSave); 2195 // err.printStackTrace(); 2196 throw err; 2197 } 2198 } 2199 2200 @TestTargetNew( 2201 level = TestLevel.COMPLETE, 2202 notes = "Verifies serialization.", 2203 method = "!Serialization", 2204 args = {} 2205 ) 2206 public void test_18_75_writeObject() { 2207 // Test for method void 2208 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2209 2210 Object objToSave = null; 2211 Object objLoaded; 2212 2213 try { 2214 SInterfaceTest test = new SInterfaceTest(); 2215 objToSave = test; 2216 if (DEBUG) 2217 System.out.println("Obj = " + objToSave); 2218 objLoaded = dumpAndReload(objToSave); 2219 // Has to have worked 2220 assertTrue(MSG_TEST_FAILED + objToSave, test.equals(objLoaded)); 2221 2222 } catch (IOException e) { 2223 fail("IOException serializing " + objToSave + " : " 2224 + e.getMessage()); 2225 } catch (ClassNotFoundException e) { 2226 fail("ClassNotFoundException reading Object type : " 2227 + e.getMessage()); 2228 } catch (Error err) { 2229 System.out.println("Error when obj = " + objToSave); 2230 // err.printStackTrace(); 2231 throw err; 2232 } 2233 } 2234 2235 @TestTargetNew( 2236 level = TestLevel.COMPLETE, 2237 notes = "Verifies serialization.", 2238 method = "!Serialization", 2239 args = {} 2240 ) 2241 public void test_18_76_writeObject() { 2242 // Test for method void 2243 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2244 2245 Object objToSave = null; 2246 Object objLoaded; 2247 2248 try { 2249 SInterfaceTest2 test = new SInterfaceTest2(); 2250 objToSave = test; 2251 if (DEBUG) 2252 System.out.println("Obj = " + objToSave); 2253 objLoaded = dumpAndReload(objToSave); 2254 // Has to have worked 2255 assertTrue(MSG_TEST_FAILED + objToSave, test.equals(objLoaded)); 2256 2257 } catch (IOException e) { 2258 fail("IOException serializing " + objToSave + " : " 2259 + e.getMessage()); 2260 } catch (ClassNotFoundException e) { 2261 fail("ClassNotFoundException reading Object type : " 2262 + e.getMessage()); 2263 } catch (Error err) { 2264 System.out.println("Error when obj = " + objToSave); 2265 // err.printStackTrace(); 2266 throw err; 2267 } 2268 } 2269 2270 @TestTargetNew( 2271 level = TestLevel.COMPLETE, 2272 notes = "Verifies serialization.", 2273 method = "!Serialization", 2274 args = {} 2275 ) 2276 public void test_18_77_writeObject() { 2277 // Test for method void 2278 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2279 2280 Object objToSave = null; 2281 Object objLoaded; 2282 2283 try { 2284 SuperclassTest test = new SuperclassTest(); 2285 objToSave = test; 2286 if (DEBUG) 2287 System.out.println("Obj = " + objToSave); 2288 objLoaded = dumpAndReload(objToSave); 2289 // Has to have worked 2290 assertTrue(MSG_TEST_FAILED + objToSave, test.equals(objLoaded)); 2291 2292 } catch (IOException e) { 2293 fail("IOException serializing " + objToSave + " : " 2294 + e.getMessage()); 2295 } catch (ClassNotFoundException e) { 2296 fail("ClassNotFoundException reading Object type : " 2297 + e.getMessage()); 2298 } catch (Error err) { 2299 System.out.println("Error when obj = " + objToSave); 2300 // err.printStackTrace(); 2301 throw err; 2302 } 2303 } 2304 2305 @TestTargetNew( 2306 level = TestLevel.COMPLETE, 2307 notes = "Verifies serialization.", 2308 method = "!Serialization", 2309 args = {} 2310 ) 2311 public void test_18_78_writeObject() { 2312 // Test for method void 2313 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2314 2315 Object objToSave = null; 2316 Object objLoaded; 2317 2318 try { 2319 SuperclassTest2 test = new SuperclassTest2(); 2320 objToSave = test; 2321 if (DEBUG) 2322 System.out.println("Obj = " + objToSave); 2323 objLoaded = dumpAndReload(objToSave); 2324 // Has to have worked 2325 assertTrue(MSG_TEST_FAILED + objToSave, test.equals(objLoaded)); 2326 2327 } catch (IOException e) { 2328 fail("IOException serializing " + objToSave + " : " 2329 + e.getMessage()); 2330 } catch (ClassNotFoundException e) { 2331 fail("ClassNotFoundException reading Object type : " 2332 + e.getMessage()); 2333 } catch (Error err) { 2334 System.out.println("Error when obj = " + objToSave); 2335 // err.printStackTrace(); 2336 throw err; 2337 } 2338 } 2339 2340 @TestTargetNew( 2341 level = TestLevel.COMPLETE, 2342 notes = "Verifies serialization.", 2343 method = "!Serialization", 2344 args = {} 2345 ) 2346 public void test_18_79_writeObject() { 2347 // Test for method void 2348 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2349 2350 Object objToSave = null; 2351 Object objLoaded; 2352 2353 try { 2354 SyntheticFieldTest test = new SyntheticFieldTest(); 2355 objToSave = test; 2356 if (DEBUG) 2357 System.out.println("Obj = " + objToSave); 2358 objLoaded = dumpAndReload(objToSave); 2359 // Has to have worked 2360 assertTrue(MSG_TEST_FAILED + objToSave, test.equals(objLoaded)); 2361 2362 } catch (IOException e) { 2363 fail("IOException serializing " + objToSave + " : " 2364 + e.getMessage()); 2365 } catch (ClassNotFoundException e) { 2366 fail("ClassNotFoundException reading Object type : " 2367 + e.getMessage()); 2368 } catch (Error err) { 2369 System.out.println("Error when obj = " + objToSave); 2370 // err.printStackTrace(); 2371 throw err; 2372 } 2373 } 2374 2375 @TestTargetNew( 2376 level = TestLevel.COMPLETE, 2377 notes = "Verifies serialization.", 2378 method = "!Serialization", 2379 args = {} 2380 ) 2381 public void test_18_80_writeObject() { 2382 // Test for method void 2383 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 2384 2385 try { 2386 ByteArrayOutputStream out = new ByteArrayOutputStream(); 2387 DataOutputStream dos = new DataOutputStream(out); 2388 new ObjectOutputStream(dos); // just to make sure we get a header 2389 dos.writeByte(ObjectStreamConstants.TC_BLOCKDATA); 2390 int length = 99; 2391 dos.writeByte(length); 2392 for (int i = 0; i < length; i++) { 2393 dos.writeByte(0); // actual value does not matter 2394 } 2395 dos.flush(); 2396 int lengthRead = 0; 2397 try { 2398 ObjectInputStream ois = new ObjectInputStream( 2399 new ByteArrayInputStream(out.toByteArray())); 2400 Object obj = ois.readObject(); 2401 } catch (OptionalDataException e) { 2402 lengthRead = e.length; 2403 } 2404 assertTrue("Did not throw exception with optional data size ", 2405 length == lengthRead); 2406 } catch (ClassNotFoundException e) { 2407 fail("Unable to read BLOCKDATA: " + e.getMessage()); 2408 } catch (IOException e) { 2409 fail("IOException testing BLOCKDATA : " + e.getMessage()); 2410 } catch (Error err) { 2411 System.out.println("Error " + err + " when testing BLOCKDATA"); 2412 throw err; 2413 } 2414 } 2415} 2416