Source Code Cross Referenced for SerializationStressTest2.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » luni » tests » java » io » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.luni.tests.java.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
0003:         *  contributor license agreements.  See the NOTICE file distributed with
0004:         *  this work for additional information regarding copyright ownership.
0005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
0006:         *  (the "License"); you may not use this file except in compliance with
0007:         *  the License.  You may obtain a copy of the License at
0008:         *
0009:         *     http://www.apache.org/licenses/LICENSE-2.0
0010:         *
0011:         *  Unless required by applicable law or agreed to in writing, software
0012:         *  distributed under the License is distributed on an "AS IS" BASIS,
0013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         *  See the License for the specific language governing permissions and
0015:         *  limitations under the License.
0016:         */
0017:
0018:        package org.apache.harmony.luni.tests.java.io;
0019:
0020:        import java.io.ByteArrayInputStream;
0021:        import java.io.ByteArrayOutputStream;
0022:        import java.io.DataOutputStream;
0023:        import java.io.IOException;
0024:        import java.io.InvalidClassException;
0025:        import java.io.NotActiveException;
0026:        import java.io.ObjectInputStream;
0027:        import java.io.ObjectOutputStream;
0028:        import java.io.ObjectStreamClass;
0029:        import java.io.ObjectStreamConstants;
0030:        import java.io.ObjectStreamField;
0031:        import java.io.OptionalDataException;
0032:        import java.io.Serializable;
0033:        import java.util.ArrayList;
0034:        import java.util.Arrays;
0035:        import java.util.Date;
0036:        import java.util.Locale;
0037:
0038:        @SuppressWarnings({"serial","unused"})
0039:        public class SerializationStressTest2 extends SerializationStressTest {
0040:
0041:            private static class ReadWriteObjectAndPrimitiveData implements 
0042:                    java.io.Serializable {
0043:                transient long milliseconds;
0044:
0045:                public boolean calledWriteObject = false;
0046:
0047:                public boolean calledReadObject = false;
0048:
0049:                public ReadWriteObjectAndPrimitiveData() {
0050:                    super ();
0051:                }
0052:
0053:                private void readObject(java.io.ObjectInputStream in)
0054:                        throws java.io.IOException, ClassNotFoundException {
0055:                    in.defaultReadObject();
0056:                    // This *has* to come after the call to defaultReadObject or the
0057:                    // value from the stream will override
0058:                    calledReadObject = true;
0059:                    milliseconds = in.readLong();
0060:                }
0061:
0062:                private void writeObject(java.io.ObjectOutputStream out)
0063:                        throws java.io.IOException {
0064:                    calledWriteObject = true;
0065:                    out.defaultWriteObject();
0066:                    out.writeLong(milliseconds);
0067:                }
0068:            }
0069:
0070:            // What happens if a class defines serialPersistentFields that do not match
0071:            // real fields but does not override read/writeObject
0072:            private static class WithUnmatchingSerialPersistentFields implements 
0073:                    java.io.Serializable {
0074:                private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
0075:                        "value", String.class) };
0076:
0077:                public int anInstanceVar = 5;
0078:
0079:                public WithUnmatchingSerialPersistentFields() {
0080:                    super ();
0081:                }
0082:            }
0083:
0084:            // What happens if a class defines serialPersistentFields which match actual
0085:            // fields
0086:            private static class WithMatchingSerialPersistentFields implements 
0087:                    java.io.Serializable {
0088:                private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
0089:                        "anInstanceVar", String.class) };
0090:
0091:                public String anInstanceVar = FOO + FOO;
0092:
0093:                public WithMatchingSerialPersistentFields() {
0094:                    super ();
0095:                }
0096:            }
0097:
0098:            // Tests the oficial behavior for serialPersistentFields
0099:            private static class SerialPersistentFields implements 
0100:                    java.io.Serializable {
0101:                private static final String SIMULATED_FIELD_NAME = "text";
0102:
0103:                private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
0104:                        SIMULATED_FIELD_NAME, String.class) };
0105:
0106:                public int anInstanceVar = 5;
0107:
0108:                public SerialPersistentFields() {
0109:                    super ();
0110:                }
0111:
0112:                private void readObject(java.io.ObjectInputStream in)
0113:                        throws java.io.IOException, ClassNotFoundException {
0114:                    ObjectInputStream.GetField fields = in.readFields();
0115:                    anInstanceVar = Integer.parseInt((String) fields.get(
0116:                            SIMULATED_FIELD_NAME, "-5"));
0117:                }
0118:
0119:                private void writeObject(java.io.ObjectOutputStream out)
0120:                        throws java.io.IOException, ClassNotFoundException {
0121:                    ObjectOutputStream.PutField fields = out.putFields();
0122:                    fields.put(SIMULATED_FIELD_NAME, Integer
0123:                            .toString(anInstanceVar));
0124:                    out.writeFields();
0125:                }
0126:            }
0127:
0128:            // Tests the behavior for serialPersistentFields when no fields are actually
0129:            // set
0130:            private static class WriteFieldsWithoutFetchingPutFields implements 
0131:                    java.io.Serializable {
0132:                private static final String SIMULATED_FIELD_NAME = "text";
0133:
0134:                private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
0135:                        SIMULATED_FIELD_NAME, String.class) };
0136:
0137:                public int anInstanceVar = 5;
0138:
0139:                public WriteFieldsWithoutFetchingPutFields() {
0140:                    super ();
0141:                }
0142:
0143:                private void readObject(java.io.ObjectInputStream in)
0144:                        throws java.io.IOException, ClassNotFoundException {
0145:                    ObjectInputStream.GetField fields = in.readFields();
0146:                }
0147:
0148:                private void writeObject(java.io.ObjectOutputStream out)
0149:                        throws java.io.IOException, ClassNotFoundException {
0150:                    out.writeFields();
0151:                }
0152:            }
0153:
0154:            // Tests what happens if one asks for PutField/getField when the class does
0155:            // not declare one
0156:            private static class SerialPersistentFieldsWithoutField implements 
0157:                    java.io.Serializable {
0158:                public int anInstanceVar = 5;
0159:
0160:                public SerialPersistentFieldsWithoutField() {
0161:                    super ();
0162:                }
0163:
0164:                private void readObject(java.io.ObjectInputStream in)
0165:                        throws java.io.IOException, ClassNotFoundException {
0166:                    ObjectInputStream.GetField fields = in.readFields();
0167:                }
0168:
0169:                private void writeObject(java.io.ObjectOutputStream out)
0170:                        throws java.io.IOException, ClassNotFoundException {
0171:                    ObjectOutputStream.PutField fields = out.putFields();
0172:                    out.writeFields();
0173:                }
0174:            }
0175:
0176:            // -----------------------------------------------------------------------------------
0177:
0178:            // writeObject writes extra primitive types and objects which readObject
0179:            // does not consume. Have to make sure we can load object properly AND
0180:            // object after it (to show the extra byte[] is consumed)
0181:            private static class OptionalDataNotRead implements 
0182:                    java.io.Serializable {
0183:                private int field1, field2;
0184:
0185:                public OptionalDataNotRead() {
0186:                }
0187:
0188:                private static final ObjectStreamField[] serialPersistentFields = {
0189:                        new ObjectStreamField("field1", Integer.TYPE),
0190:                        new ObjectStreamField("field2", Integer.TYPE),
0191:                        new ObjectStreamField("monthLength", byte[].class), };
0192:
0193:                private void writeObject(ObjectOutputStream stream)
0194:                        throws IOException {
0195:                    ObjectOutputStream.PutField fields = stream.putFields();
0196:                    fields.put("field1", 1);
0197:                    fields.put("field2", 2);
0198:                    fields.put("monthLength", new byte[] { 7, 8, 9 });
0199:                    stream.writeFields();
0200:                    stream.writeInt(4);
0201:                    byte[] values = new byte[4];
0202:                    values[0] = (byte) 16;
0203:                    values[1] = (byte) 17;
0204:                    values[2] = (byte) 18;
0205:                    values[3] = (byte) 19;
0206:                    stream.writeObject(values);
0207:                }
0208:
0209:                private void readObject(ObjectInputStream stream)
0210:                        throws IOException, ClassNotFoundException {
0211:                    ObjectInputStream.GetField fields = stream.readFields();
0212:                    field1 = fields.get("field1", 0);
0213:                    field2 = fields.get("field1", 0);
0214:                }
0215:            }
0216:
0217:            // -----------------------------------------------------------------------------------
0218:            private static class NestedPutField implements  java.io.Serializable {
0219:                public OptionalDataNotRead field1;
0220:
0221:                public NestedPutField() {
0222:                }
0223:
0224:                private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
0225:                        "field1", OptionalDataNotRead.class), };
0226:
0227:                private void writeObject(ObjectOutputStream stream)
0228:                        throws IOException {
0229:                    ObjectOutputStream.PutField fields = stream.putFields();
0230:                    fields.put("field1", new OptionalDataNotRead());
0231:                    stream.writeFields();
0232:                }
0233:
0234:                private void readObject(ObjectInputStream stream)
0235:                        throws IOException, ClassNotFoundException {
0236:                    ObjectInputStream.GetField fields = stream.readFields();
0237:                    field1 = (OptionalDataNotRead) fields.get("field1", null);
0238:                }
0239:            }
0240:
0241:            // -----------------------------------------------------------------------------------
0242:
0243:            // This one tests stream-based replacement when dumping
0244:            private static class StreamBasedReplacementWhenDumping extends
0245:                    java.io.ObjectOutputStream {
0246:                public boolean calledArrayReplacement = false;
0247:
0248:                public boolean calledStringReplacement = false;
0249:
0250:                public boolean calledClassReplacement = false;
0251:
0252:                public boolean calledObjectStreamClassReplacement = false;
0253:
0254:                public StreamBasedReplacementWhenDumping(
0255:                        java.io.OutputStream output) throws java.io.IOException {
0256:                    super (output);
0257:                    enableReplaceObject(true);
0258:                }
0259:
0260:                protected Object replaceObject(Object obj) throws IOException {
0261:                    Class objClass = obj.getClass();
0262:                    if (objClass == String.class)
0263:                        calledStringReplacement = true;
0264:
0265:                    if (objClass == Class.class)
0266:                        calledClassReplacement = true;
0267:
0268:                    if (objClass == ObjectStreamClass.class)
0269:                        calledObjectStreamClassReplacement = true;
0270:
0271:                    if (objClass.isArray())
0272:                        calledArrayReplacement = true;
0273:
0274:                    return obj;
0275:                }
0276:            }
0277:
0278:            // -----------------------------------------------------------------------------------
0279:
0280:            private static class ArrayOfSerializable implements  Serializable {
0281:                private Serializable[] testField = null;
0282:
0283:                public ArrayOfSerializable() {
0284:                    testField = new Serializable[2];
0285:                    testField[0] = "Hi";
0286:                    testField[1] = "there!";
0287:                }
0288:            }
0289:
0290:            // -----------------------------------------------------------------------------------
0291:
0292:            private static class ClassSubClassTest0 extends java.lang.Object
0293:                    implements  java.io.Serializable {
0294:                String stringVar;
0295:
0296:                public ClassSubClassTest0(String init) {
0297:                    stringVar = init;
0298:                }
0299:            }
0300:
0301:            private static class ClassSubClassTest1 extends ClassSubClassTest0 {
0302:                String subStringVar;
0303:
0304:                public ClassSubClassTest1(String super String, String subString) {
0305:                    super (super String);
0306:                    subStringVar = subString;
0307:                }
0308:
0309:                public boolean equals(Object obj) {
0310:                    if (obj == null)
0311:                        return false;
0312:                    if (!(obj instanceof  ClassSubClassTest1))
0313:                        return false;
0314:
0315:                    ClassSubClassTest1 inst = (ClassSubClassTest1) obj;
0316:                    return inst.subStringVar.equals(this .subStringVar)
0317:                            && inst.stringVar.equals(this .stringVar);
0318:                }
0319:            }
0320:
0321:            // -----------------------------------------------------------------------------------
0322:            private static class ConstructorTestA {
0323:                public String instVar_classA;
0324:
0325:                public final static String ConstrA = "Init in Constructor Class A";
0326:
0327:                public final static String ConstrB = "Init in Constructor Class B";
0328:
0329:                public final static String ConstrC = "Init in Constructor Class C";
0330:
0331:                public final static String ChangedC = "Changed before Serialize - Class C";
0332:
0333:                public ConstructorTestA() {
0334:                    instVar_classA = ConstrA;
0335:                }
0336:            }
0337:
0338:            private static class ConstructorTestB extends ConstructorTestA
0339:                    implements  java.io.Serializable {
0340:                public String instVar_classB;
0341:
0342:                public ConstructorTestB() {
0343:                    instVar_classA = ConstrB;
0344:                    instVar_classB = ConstrB;
0345:                }
0346:            }
0347:
0348:            private static class ConstructorTestC extends ConstructorTestB {
0349:                public String instVar_classC;
0350:
0351:                public ConstructorTestC() {
0352:                    instVar_classA = ConstrC;
0353:                    instVar_classB = ConstrC;
0354:                    instVar_classC = ConstrC;
0355:                }
0356:
0357:                public boolean verify(Object obj) {
0358:                    if (obj == null)
0359:                        return false;
0360:                    if (!(obj instanceof  ConstructorTestC))
0361:                        return false;
0362:
0363:                    ConstructorTestC inst = (ConstructorTestC) obj;
0364:                    return inst.instVar_classC.equals(this .instVar_classC)
0365:                            && inst.instVar_classB.equals(this .instVar_classB)
0366:                            && inst.instVar_classA.equals(ConstrA);
0367:                }
0368:            }
0369:
0370:            // -----------------------------------------------------------------------------------
0371:            private static class HashCodeTest implements  java.io.Serializable {
0372:                private boolean serializationUsesHashCode = false;
0373:
0374:                public int hashCode() {
0375:                    serializationUsesHashCode = true;
0376:                    return super .hashCode();
0377:                }
0378:            }
0379:
0380:            // -----------------------------------------------------------------------------------
0381:            private static class InitializerFieldsTest implements 
0382:                    java.io.Serializable {
0383:                public java.lang.String toBeSerialized;
0384:
0385:                public static java.lang.String toBeNotSerialized;
0386:
0387:                public static java.lang.String toBeNotSerialized2;
0388:
0389:                {
0390:                    toBeSerialized = "NonStaticInitialValue";
0391:                }
0392:
0393:                static {
0394:                    toBeNotSerialized = "StaticInitialValue";
0395:                    toBeNotSerialized2 = new String(toBeNotSerialized);
0396:                }
0397:
0398:                public boolean equals(Object obj) {
0399:                    /*
0400:                     * This method is not answering it the objs is equal. It is
0401:                     * answering if the vars have the value that it have to have after
0402:                     * dumping and loading
0403:                     */
0404:
0405:                    if (obj == null)
0406:                        return false;
0407:                    if (!(obj instanceof  InitializerFieldsTest))
0408:                        return false;
0409:
0410:                    InitializerFieldsTest inst = (InitializerFieldsTest) obj;
0411:                    return inst.toBeSerialized.equals(this .toBeSerialized)
0412:                            && InitializerFieldsTest.toBeNotSerialized
0413:                                    .equals(toBeNotSerialized2);
0414:                }
0415:            }
0416:
0417:            private static class InitializerFieldsTest2 implements 
0418:                    java.io.Serializable {
0419:                public java.lang.String toBeSerialized;
0420:
0421:                public static java.lang.String toBeNotSerialized;
0422:
0423:                public static java.lang.String toBeNotSerialized2;
0424:
0425:                {
0426:                    toBeSerialized = "NonStaticInitialValue";
0427:                }
0428:
0429:                public java.lang.String toBeSerialized3;
0430:
0431:                public java.lang.String toBeSerialized4;
0432:                static {
0433:                    toBeNotSerialized = "StaticInitialValue";
0434:                    toBeNotSerialized2 = new String(toBeNotSerialized);
0435:                }
0436:
0437:                public java.lang.String toBeSerialized5;
0438:
0439:                public boolean equals(Object obj) {
0440:                    /*
0441:                     * This method is not answering it the objs is equal. It is
0442:                     * answering if the vars have the value that it have to have after
0443:                     * dumping and loading
0444:                     */
0445:
0446:                    if (obj == null)
0447:                        return false;
0448:                    if (!(obj instanceof  InitializerFieldsTest2))
0449:                        return false;
0450:
0451:                    InitializerFieldsTest2 inst = (InitializerFieldsTest2) obj;
0452:                    return inst.toBeSerialized.equals(this .toBeSerialized)
0453:                            && inst.toBeSerialized3
0454:                                    .equals(this .toBeSerialized3)
0455:                            && inst.toBeSerialized4
0456:                                    .equals(this .toBeSerialized4)
0457:                            && inst.toBeSerialized5
0458:                                    .equals(this .toBeSerialized5)
0459:                            && InitializerFieldsTest2.toBeNotSerialized
0460:                                    .equals(toBeNotSerialized2);
0461:                }
0462:            }
0463:
0464:            private static class InitializerFieldsTest3 extends
0465:                    InitializerFieldsTest2 implements  java.io.Serializable {
0466:                public java.lang.String sub_toBeSerialized;
0467:
0468:                public static java.lang.String sub_toBeNotSerialized;
0469:
0470:                public static java.lang.String sub_toBeNotSerialized2;
0471:
0472:                {
0473:                    sub_toBeSerialized = "NonStaticInitialValue";
0474:                }
0475:
0476:                public java.lang.String sub_toBeSerialized3;
0477:
0478:                public java.lang.String sub_toBeSerialized4;
0479:                static {
0480:                    sub_toBeNotSerialized = "StaticInitialValue";
0481:                    sub_toBeNotSerialized2 = new String(sub_toBeNotSerialized);
0482:                }
0483:
0484:                public java.lang.String sub_toBeSerialized5;
0485:
0486:                public boolean equals(Object obj) {
0487:                    /*
0488:                     * This method is not answering it the objs is equal. It is
0489:                     * answering if the vars have the value that it have to have after
0490:                     * dumping and loading
0491:                     */
0492:
0493:                    if (!super .equals(obj))
0494:                        return false;
0495:                    if (!(obj instanceof  InitializerFieldsTest3))
0496:                        return false;
0497:
0498:                    InitializerFieldsTest3 inst = (InitializerFieldsTest3) obj;
0499:                    return inst.sub_toBeSerialized
0500:                            .equals(this .sub_toBeSerialized)
0501:                            && inst.sub_toBeSerialized3
0502:                                    .equals(this .sub_toBeSerialized3)
0503:                            && inst.sub_toBeSerialized4
0504:                                    .equals(this .sub_toBeSerialized4)
0505:                            && inst.sub_toBeSerialized5
0506:                                    .equals(this .sub_toBeSerialized5)
0507:                            && InitializerFieldsTest3.sub_toBeNotSerialized
0508:                                    .equals(sub_toBeNotSerialized2);
0509:                }
0510:            }
0511:
0512:            // -----------------------------------------------------------------------------------
0513:            private static class DeepNesting implements  java.io.Serializable {
0514:                public float id;
0515:
0516:                public DeepNesting next;
0517:
0518:                public boolean dump;
0519:
0520:                public boolean load;
0521:
0522:                public DeepNesting(float id) {
0523:                    this .id = id;
0524:                    next = null;
0525:                    dump = false;
0526:                    load = false;
0527:                }
0528:
0529:                public DeepNesting(int howMany) {
0530:                    DeepNesting prev = new DeepNesting(0.0F);
0531:                    next(prev);
0532:                    for (int i = 1; i < howMany; i++) {
0533:                        prev = prev.next(new DeepNesting(i * 1.0F));
0534:                    }
0535:                }
0536:
0537:                public boolean equals(Object obj) {
0538:                    if (obj == null)
0539:                        return false;
0540:                    if (!(obj instanceof  DeepNesting))
0541:                        return false;
0542:
0543:                    DeepNesting inst = (DeepNesting) obj;
0544:                    if (inst.dump != this .dump || inst.load != this .load)
0545:                        return false;
0546:
0547:                    if (inst.next == null || this .next == null)
0548:                        return inst.next == this .next; // both null
0549:                    return this .next.equals(inst.next);
0550:                }
0551:
0552:                public DeepNesting next(DeepNesting ivt) {
0553:                    next = ivt;
0554:                    return ivt;
0555:                }
0556:            }
0557:
0558:            // -----------------------------------------------------------------------------------
0559:            private static class DeepNestingWithWriteObject implements 
0560:                    java.io.Serializable {
0561:                public float id;
0562:
0563:                public DeepNestingWithWriteObject next;
0564:
0565:                public boolean dump;
0566:
0567:                public boolean load;
0568:
0569:                public DeepNestingWithWriteObject(float id) {
0570:                    this .id = id;
0571:                    next = null;
0572:                    dump = false;
0573:                    load = false;
0574:                }
0575:
0576:                public DeepNestingWithWriteObject(int howMany) {
0577:                    DeepNestingWithWriteObject prev = new DeepNestingWithWriteObject(
0578:                            0.0F);
0579:                    next(prev);
0580:                    for (int i = 1; i < howMany; i++) {
0581:                        prev = prev.next(new DeepNestingWithWriteObject(
0582:                                i * 1.0F));
0583:                    }
0584:                }
0585:
0586:                public boolean equals(Object obj) {
0587:                    if (obj == null)
0588:                        return false;
0589:                    if (!(obj instanceof  DeepNestingWithWriteObject))
0590:                        return false;
0591:
0592:                    DeepNestingWithWriteObject inst = (DeepNestingWithWriteObject) obj;
0593:                    if (inst.dump != this .dump || inst.load != this .load)
0594:                        return false;
0595:
0596:                    if (inst.next == null || this .next == null)
0597:                        return inst.next == this .next; // both null;
0598:                    return this .next.equals(inst.next);
0599:                }
0600:
0601:                public DeepNestingWithWriteObject next(
0602:                        DeepNestingWithWriteObject ivt) {
0603:                    next = ivt;
0604:                    return ivt;
0605:                }
0606:
0607:                private void writeObject(java.io.ObjectOutputStream s)
0608:                        throws IOException {
0609:                    s.defaultWriteObject();
0610:                }
0611:
0612:                private void readObject(java.io.ObjectInputStream s)
0613:                        throws IOException, ClassNotFoundException {
0614:                    s.defaultReadObject();
0615:                }
0616:            }
0617:
0618:            // -----------------------------------------------------------------------------------
0619:            static class NonPublicClassTest extends java.lang.Object implements 
0620:                    java.io.Serializable {
0621:                int field = 1;
0622:
0623:                public NonPublicClassTest() {
0624:                    field = 10;
0625:                }
0626:
0627:                public boolean equals(Object o) {
0628:                    if (o instanceof  NonPublicClassTest)
0629:                        return field == ((NonPublicClassTest) o).field;
0630:                    return false;
0631:                }
0632:
0633:                public void x10() {
0634:                    field *= 10;
0635:                }
0636:            }
0637:
0638:            // -----------------------------------------------------------------------------------
0639:            private static class SameInstVarNameSuperClass {
0640:                private int foo;
0641:
0642:                public SameInstVarNameSuperClass() {
0643:                    super ();
0644:                }
0645:
0646:                public SameInstVarNameSuperClass(int fooValue) {
0647:                    foo = fooValue;
0648:                }
0649:
0650:                public String toString() {
0651:                    return "foo = " + foo;
0652:                }
0653:            }
0654:
0655:            private static class SameInstVarNameSubClass extends
0656:                    SameInstVarNameSuperClass implements  java.io.Serializable {
0657:                protected int foo;
0658:
0659:                public SameInstVarNameSubClass() {
0660:                    super ();
0661:                }
0662:
0663:                public SameInstVarNameSubClass(int fooValue) {
0664:                    super (-fooValue);
0665:                    foo = fooValue;
0666:                }
0667:            }
0668:
0669:            // -----------------------------------------------------------------------------------
0670:            private static class SInterfaceTest implements  java.io.Serializable {
0671:                public static int staticVar = 5;
0672:
0673:                public transient int[] transVar = { 1, 2, 3, 4, 5, 6, 7, 8, 9,
0674:                        0 };
0675:
0676:                public int instanceVar = 7;
0677:
0678:                public boolean equals(Object obj) {
0679:                    if (obj == null)
0680:                        return false;
0681:                    if (!(obj instanceof  SInterfaceTest))
0682:                        return false;
0683:
0684:                    SInterfaceTest inst = (SInterfaceTest) obj;
0685:                    if (this .instanceVar != inst.instanceVar)
0686:                        return false;
0687:                    if (inst.transVar == null || this .transVar == null)
0688:                        return inst.transVar == this .transVar; // both null
0689:                    for (int i = 0; i < transVar.length; i++)
0690:                        if (inst.transVar[i] != this .transVar[i])
0691:                            return false;
0692:                    return true;
0693:                }
0694:
0695:                private void readObject(java.io.ObjectInputStream s)
0696:                        throws IOException, ClassNotFoundException {
0697:                    Object arr;
0698:                    s.defaultReadObject();
0699:                    arr = s.readObject();
0700:                    transVar = (int[]) arr;
0701:                }
0702:
0703:                private void writeObject(java.io.ObjectOutputStream s)
0704:                        throws IOException {
0705:                    s.defaultWriteObject();
0706:                    s.writeObject(transVar);
0707:                }
0708:
0709:                public void x10() {
0710:                    for (int i = 0; i < transVar.length; i++)
0711:                        transVar[i] = transVar[i] * 10;
0712:                    instanceVar = instanceVar * 10;
0713:                }
0714:            }
0715:
0716:            // -----------------------------------------------------------------------------------
0717:            private static class SInterfaceTest2 extends SInterfaceTest {
0718:                private void readObject(java.io.ObjectInputStream s)
0719:                        throws IOException, ClassNotFoundException {
0720:                    Object arr;
0721:                    instanceVar = s.readInt();
0722:                    arr = s.readObject();
0723:                    transVar = (int[]) arr;
0724:                }
0725:
0726:                private void writeObject(java.io.ObjectOutputStream s)
0727:                        throws IOException {
0728:                    s.writeInt(instanceVar);
0729:                    s.writeObject(transVar);
0730:                }
0731:            }
0732:
0733:            // -----------------------------------------------------------------------------------
0734:            private static class SuperclassTest extends java.lang.Object
0735:                    implements  java.io.Serializable {
0736:                int super field = 1;
0737:
0738:                public SuperclassTest() {
0739:                    super field = 10;
0740:                }
0741:
0742:                public boolean equals(Object o) {
0743:                    if (o.getClass() == this .getClass())
0744:                        return super field == ((SuperclassTest) o).super field;
0745:                    return false;
0746:                }
0747:
0748:                private void readObject(java.io.ObjectInputStream s)
0749:                        throws IOException, ClassNotFoundException {
0750:                    super field = s.readInt();
0751:                }
0752:
0753:                private void writeObject(java.io.ObjectOutputStream s)
0754:                        throws IOException {
0755:                    s.writeInt(super field);
0756:                }
0757:
0758:                public void x10() {
0759:                    super field *= 10;
0760:                }
0761:            }
0762:
0763:            // -----------------------------------------------------------------------------------
0764:            private static class SuperclassTest2 extends SuperclassTest {
0765:                int subfield = 5;
0766:
0767:                public SuperclassTest2() {
0768:                    subfield = 50;
0769:                }
0770:
0771:                public boolean equals(Object o) {
0772:                    if (o instanceof  SuperclassTest2)
0773:                        if (subfield == ((SuperclassTest2) o).subfield)
0774:                            return super .equals(o);
0775:                    return false;
0776:                }
0777:
0778:                private void readObject(java.io.ObjectInputStream s)
0779:                        throws IOException, ClassNotFoundException {
0780:                    subfield = s.readInt();
0781:                }
0782:
0783:                private void writeObject(java.io.ObjectOutputStream s)
0784:                        throws IOException {
0785:                    s.writeInt(subfield);
0786:                }
0787:
0788:                public void x10() {
0789:                    subfield *= 10;
0790:                    super .x10();
0791:                }
0792:            }
0793:
0794:            // -----------------------------------------------------------------------------------
0795:            private static class SyntheticFieldTest implements 
0796:                    java.io.Serializable {
0797:                public boolean equals(Object obj) {
0798:                    /*
0799:                     * This method is not answering it the objs is equal. It is
0800:                     * answering if the vars have the value that it have to have after
0801:                     * dumping and loading
0802:                     */
0803:                    if (obj == null)
0804:                        return false;
0805:                    return obj instanceof  SyntheticFieldTest;
0806:                }
0807:
0808:                public int hashCode() {
0809:                    // Insert code to generate a hash code for the receiver here.
0810:                    // This implementation forwards the message to super. You may
0811:                    // replace or supplement this.
0812:                    // NOTE: if two objects are equal (equals Object) returns true) they
0813:                    // must have the same hash code
0814:                    Class[] c = { String.class }; // *** synthetic field
0815:                    return super .hashCode();
0816:                }
0817:            }
0818:
0819:            public SerializationStressTest2(String name) {
0820:                super (name);
0821:            }
0822:
0823:            public void test_18_41_writeObject() {
0824:                // Test for method void
0825:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
0826:
0827:                Object objToSave = null;
0828:                Object objLoaded;
0829:
0830:                try {
0831:                    java.io.IOException ex = new java.io.WriteAbortedException(
0832:                            FOO, null);
0833:                    objToSave = ex;
0834:                    if (DEBUG)
0835:                        System.out.println("Obj = " + objToSave);
0836:                    objLoaded = dumpAndReload(objToSave);
0837:                    // Has to be able to save/load an exception
0838:                    assertTrue(MSG_TEST_FAILED + objToSave, true);
0839:
0840:                } catch (IOException e) {
0841:                    fail("IOException serializing " + objToSave + " : "
0842:                            + e.getMessage());
0843:                } catch (ClassNotFoundException e) {
0844:                    fail("ClassNotFoundException reading Object type : "
0845:                            + e.getMessage());
0846:                } catch (Error err) {
0847:                    System.out.println("Error when obj = " + objToSave);
0848:                    // err.printStackTrace();
0849:                    throw err;
0850:                }
0851:            }
0852:
0853:            public void test_18_42_writeObject() {
0854:                // Test for method void
0855:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
0856:
0857:                Object objToSave = null;
0858:                Object objLoaded;
0859:
0860:                try {
0861:                    WithUnmatchingSerialPersistentFields spf = new WithUnmatchingSerialPersistentFields();
0862:                    objToSave = spf;
0863:                    if (DEBUG)
0864:                        System.out.println("Obj = " + objToSave);
0865:                    boolean causedException = false;
0866:                    try {
0867:                        objLoaded = dumpAndReload(objToSave);
0868:                    } catch (InvalidClassException ce) {
0869:                        causedException = true;
0870:                    }
0871:                    assertTrue(
0872:                            "serialPersistentFields do not match real fields",
0873:                            causedException);
0874:
0875:                } catch (IOException e) {
0876:                    fail("IOException serializing " + objToSave + " : "
0877:                            + e.getMessage());
0878:                } catch (ClassNotFoundException e) {
0879:                    fail("ClassNotFoundException reading Object type : "
0880:                            + e.getMessage());
0881:                } catch (Error err) {
0882:                    System.out.println("Error when obj = " + objToSave);
0883:                    // err.printStackTrace();
0884:                    throw err;
0885:                }
0886:            }
0887:
0888:            public void test_18_43_writeObject() {
0889:                // Test for method void
0890:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
0891:
0892:                Object objToSave = null;
0893:                Object objLoaded;
0894:
0895:                try {
0896:                    WithMatchingSerialPersistentFields spf = new WithMatchingSerialPersistentFields();
0897:                    spf.anInstanceVar = FOO;
0898:                    objToSave = spf;
0899:                    if (DEBUG)
0900:                        System.out.println("Obj = " + objToSave);
0901:                    objLoaded = dumpAndReload(objToSave);
0902:                    assertTrue(
0903:                            "serialPersistentFields do not work properly in this implementation",
0904:                            FOO
0905:                                    .equals(((WithMatchingSerialPersistentFields) objLoaded).anInstanceVar));
0906:
0907:                } catch (IOException e) {
0908:                    fail("IOException serializing " + objToSave + " : "
0909:                            + e.getMessage());
0910:                } catch (ClassNotFoundException e) {
0911:                    fail("ClassNotFoundException reading Object type : "
0912:                            + e.getMessage());
0913:                } catch (Error err) {
0914:                    System.out.println("Error when obj = " + objToSave);
0915:                    // err.printStackTrace();
0916:                    throw err;
0917:                }
0918:            }
0919:
0920:            public void test_18_44_writeObject() {
0921:                // Test for method void
0922:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
0923:
0924:                Object objToSave = null;
0925:                Object objLoaded;
0926:
0927:                try {
0928:                    SerialPersistentFields spf = new SerialPersistentFields();
0929:                    final int CONST = -500;
0930:                    spf.anInstanceVar = CONST;
0931:                    objToSave = spf;
0932:                    if (DEBUG)
0933:                        System.out.println("Obj = " + objToSave);
0934:                    objLoaded = dumpAndReload(objToSave);
0935:                    assertTrue(
0936:                            "serialPersistentFields do not work properly in this implementation",
0937:                            ((SerialPersistentFields) objLoaded).anInstanceVar == CONST);
0938:
0939:                } catch (IOException e) {
0940:                    fail("IOException serializing " + objToSave + " : "
0941:                            + e.getMessage());
0942:                } catch (ClassNotFoundException e) {
0943:                    fail("ClassNotFoundException reading Object type : "
0944:                            + e.getMessage());
0945:                } catch (Error err) {
0946:                    System.out.println("Error when obj = " + objToSave);
0947:                    // err.printStackTrace();
0948:                    throw err;
0949:                }
0950:            }
0951:
0952:            public void test_18_45_writeObject() {
0953:                // Test for method void
0954:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
0955:
0956:                Object objToSave = null;
0957:                Object objLoaded;
0958:
0959:                try {
0960:                    WriteFieldsWithoutFetchingPutFields spf = new WriteFieldsWithoutFetchingPutFields();
0961:                    objToSave = spf;
0962:                    if (DEBUG)
0963:                        System.out.println("Obj = " + objToSave);
0964:                    boolean causedException = false;
0965:                    try {
0966:                        objLoaded = dumpAndReload(objToSave);
0967:                    } catch (NotActiveException ce) {
0968:                        causedException = true;
0969:                    }
0970:                    assertTrue("WriteFieldsWithoutFetchingPutFields",
0971:                            causedException);
0972:
0973:                } catch (IOException e) {
0974:                    fail("IOException serializing " + objToSave + " : "
0975:                            + e.getMessage());
0976:                } catch (ClassNotFoundException e) {
0977:                    fail("ClassNotFoundException reading Object type : "
0978:                            + e.getMessage());
0979:                } catch (Error err) {
0980:                    System.out.println("Error when obj = " + objToSave);
0981:                    // err.printStackTrace();
0982:                    throw err;
0983:                }
0984:            }
0985:
0986:            public void test_18_46_writeObject() {
0987:                // Test for method void
0988:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
0989:
0990:                Object objToSave = null;
0991:                Object objLoaded;
0992:
0993:                try {
0994:                    objToSave = SerialPersistentFields.class; // Test for 1FA7TA6
0995:                    if (DEBUG)
0996:                        System.out.println("Obj = " + objToSave);
0997:                    objLoaded = dumpAndReload(objToSave);
0998:                    // Has to be able to save/load an exception
0999:                    assertTrue(MSG_TEST_FAILED + objToSave, true);
1000:
1001:                } catch (IOException e) {
1002:                    fail("IOException serializing " + objToSave + " : "
1003:                            + e.getMessage());
1004:                } catch (ClassNotFoundException e) {
1005:                    fail("ClassNotFoundException reading Object type : "
1006:                            + e.getMessage());
1007:                } catch (Error err) {
1008:                    System.out.println("Error when obj = " + objToSave);
1009:                    // err.printStackTrace();
1010:                    throw err;
1011:                }
1012:            }
1013:
1014:            public void test_18_47_writeObject() {
1015:                // Test for method void
1016:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1017:
1018:                Object objToSave = null;
1019:                Object objLoaded;
1020:
1021:                try {
1022:                    objToSave = ObjectStreamClass
1023:                            .lookup(SerialPersistentFields.class); // Test
1024:                    // for
1025:                    // 1FA7TA6
1026:                    if (DEBUG)
1027:                        System.out.println("Obj = " + objToSave);
1028:                    objLoaded = dumpAndReload(objToSave);
1029:                    // Has to be able to save/load an exception
1030:                    assertTrue(MSG_TEST_FAILED + objToSave, true);
1031:
1032:                } catch (IOException e) {
1033:                    fail("IOException serializing " + objToSave + " : "
1034:                            + e.getMessage());
1035:                } catch (ClassNotFoundException e) {
1036:                    fail("ClassNotFoundException reading Object type : "
1037:                            + e.getMessage());
1038:                } catch (Error err) {
1039:                    System.out.println("Error when obj = " + objToSave);
1040:                    // err.printStackTrace();
1041:                    throw err;
1042:                }
1043:            }
1044:
1045:            public void test_18_48_writeObject() {
1046:                // Test for method void
1047:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1048:
1049:                Object objToSave = null;
1050:                Object objLoaded;
1051:
1052:                try {
1053:                    SerialPersistentFieldsWithoutField spf = new SerialPersistentFieldsWithoutField();
1054:                    final int CONST = -500;
1055:                    spf.anInstanceVar = CONST;
1056:                    objToSave = spf;
1057:                    if (DEBUG)
1058:                        System.out.println("Obj = " + objToSave);
1059:                    objLoaded = dumpAndReload(objToSave);
1060:                    assertTrue(
1061:                            "serialPersistentFields do not work properly in this implementation",
1062:                            ((SerialPersistentFieldsWithoutField) objLoaded).anInstanceVar != CONST);
1063:
1064:                } catch (IOException e) {
1065:                    fail("IOException serializing " + objToSave + " : "
1066:                            + e.getMessage());
1067:                } catch (ClassNotFoundException e) {
1068:                    fail("ClassNotFoundException reading Object type : "
1069:                            + e.getMessage());
1070:                } catch (Error err) {
1071:                    System.out.println("Error when obj = " + objToSave);
1072:                    // err.printStackTrace();
1073:                    throw err;
1074:                }
1075:            }
1076:
1077:            public void test_18_49_writeObject() {
1078:                // Test for method void
1079:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1080:
1081:                Object objToSave = null;
1082:                Object objLoaded;
1083:
1084:                try {
1085:                    java.net.SocketPermission p = new java.net.SocketPermission(
1086:                            "www.yahoo.com", "connect");
1087:                    objToSave = p;
1088:                    if (DEBUG)
1089:                        System.out.println("Obj = " + objToSave);
1090:                    objLoaded = dumpAndReload(objToSave);
1091:                    assertTrue("SocketPermissions are not the same: " + p
1092:                            + "\t,\t" + objLoaded, p.equals(objLoaded));
1093:
1094:                } catch (IOException e) {
1095:                    fail("IOException serializing " + objToSave + " : "
1096:                            + e.getMessage());
1097:                } catch (ClassNotFoundException e) {
1098:                    fail("ClassNotFoundException reading Object type : "
1099:                            + e.getMessage());
1100:                } catch (Error err) {
1101:                    System.out.println("Error when obj = " + objToSave);
1102:                    // err.printStackTrace();
1103:                    throw err;
1104:                }
1105:            }
1106:
1107:            public void test_18_50_writeObject() {
1108:                // Test for method void
1109:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1110:
1111:                Object objToSave = null;
1112:                Object objLoaded;
1113:
1114:                try {
1115:                    java.net.SocketPermission p = new java.net.SocketPermission(
1116:                            "www.yahoo.com", "ReSoLVe,  		ConNecT");
1117:                    objToSave = p;
1118:                    if (DEBUG)
1119:                        System.out.println("Obj = " + objToSave);
1120:                    objLoaded = dumpAndReload(objToSave);
1121:                    assertTrue("SocketPermissions are not the same: " + p
1122:                            + "\t,\t" + objLoaded, p.equals(objLoaded));
1123:
1124:                } catch (IOException e) {
1125:                    fail("IOException serializing " + objToSave + " : "
1126:                            + e.getMessage());
1127:                } catch (ClassNotFoundException e) {
1128:                    fail("ClassNotFoundException reading Object type : "
1129:                            + e.getMessage());
1130:                } catch (Error err) {
1131:                    System.out.println("Error when obj = " + objToSave);
1132:                    // err.printStackTrace();
1133:                    throw err;
1134:                }
1135:            }
1136:
1137:            public void test_18_51_writeObject() {
1138:                // Test for method void
1139:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1140:
1141:                Object objToSave = null;
1142:                Object objLoaded;
1143:
1144:                try {
1145:
1146:                    ReadWriteObjectAndPrimitiveData readWrite = new ReadWriteObjectAndPrimitiveData();
1147:                    objToSave = readWrite;
1148:                    if (DEBUG)
1149:                        System.out.println("Obj = " + objToSave);
1150:                    objLoaded = dumpAndReload(objToSave);
1151:                    // has to have called the writeObject on the instance to dump
1152:                    assertTrue(MSG_TEST_FAILED + objToSave,
1153:                            readWrite.calledWriteObject);
1154:                    // has to have called the readObject on the instance loaded
1155:                    assertTrue(
1156:                            MSG_TEST_FAILED + objToSave,
1157:                            ((ReadWriteObjectAndPrimitiveData) objLoaded).calledReadObject);
1158:
1159:                } catch (IOException e) {
1160:                    fail("IOException serializing " + objToSave + " : "
1161:                            + e.getMessage());
1162:                } catch (ClassNotFoundException e) {
1163:                    fail("ClassNotFoundException reading Object type : "
1164:                            + e.getMessage());
1165:                } catch (Error err) {
1166:                    System.out.println("Error when obj = " + objToSave);
1167:                    // err.printStackTrace();
1168:                    throw err;
1169:                }
1170:            }
1171:
1172:            public void test_18_52_writeObject() {
1173:                // Test for method void
1174:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1175:
1176:                Object objToSave = null;
1177:                Object objLoaded;
1178:
1179:                try {
1180:
1181:                    ArrayList list = new ArrayList<String>(
1182:                            Arrays.asList(new String[] { "a", "list", "of",
1183:                                    "strings" }));
1184:                    objToSave = list;
1185:                    if (DEBUG)
1186:                        System.out.println("Obj = " + objToSave);
1187:                    objLoaded = dumpAndReload(objToSave);
1188:                    // Has to have worked
1189:                    assertTrue(MSG_TEST_FAILED + objToSave, true);
1190:
1191:                } catch (IOException e) {
1192:                    fail("IOException serializing " + objToSave + " : "
1193:                            + e.getMessage());
1194:                } catch (ClassNotFoundException e) {
1195:                    fail("ClassNotFoundException reading Object type : "
1196:                            + e.getMessage());
1197:                } catch (Error err) {
1198:                    System.out.println("Error when obj = " + objToSave);
1199:                    // err.printStackTrace();
1200:                    throw err;
1201:                }
1202:            }
1203:
1204:            public void test_18_53_writeObject() {
1205:                // Test for method void
1206:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1207:
1208:                Object objToSave = null;
1209:                Object objLoaded;
1210:
1211:                try {
1212:
1213:                    objToSave = Locale.CHINESE;
1214:                    if (DEBUG)
1215:                        System.out.println("Obj = " + objToSave);
1216:                    objLoaded = dumpAndReload(objToSave);
1217:                    // Has to have worked
1218:                    assertTrue(MSG_TEST_FAILED + objToSave, true);
1219:
1220:                } catch (IOException e) {
1221:                    fail("IOException serializing " + objToSave + " : "
1222:                            + e.getMessage());
1223:                } catch (ClassNotFoundException e) {
1224:                    fail("ClassNotFoundException reading Object type : "
1225:                            + e.getMessage());
1226:                } catch (Error err) {
1227:                    System.out.println("Error when obj = " + objToSave);
1228:                    // err.printStackTrace();
1229:                    throw err;
1230:                }
1231:            }
1232:
1233:            public void test_OptionalDataNotRead() {
1234:                // Test for method void
1235:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1236:
1237:                Object objToSave = null;
1238:                Object objLoaded;
1239:
1240:                try {
1241:                    OptionalDataNotRead test = new OptionalDataNotRead();
1242:                    // Have to save an object after the one above, and when we read it,
1243:                    // it cannot be a byte[]
1244:                    Date now = new Date();
1245:                    Object[] twoObjects = new Object[2];
1246:                    twoObjects[0] = test;
1247:                    twoObjects[1] = now;
1248:                    objToSave = twoObjects;
1249:                    if (DEBUG)
1250:                        System.out.println("Obj = " + objToSave);
1251:                    objLoaded = dumpAndReload(objToSave);
1252:                    // Has to have worked
1253:                    Object[] twoLoadedObjects = (Object[]) objLoaded;
1254:                    assertTrue(MSG_TEST_FAILED + objToSave, twoLoadedObjects[0]
1255:                            .getClass() == OptionalDataNotRead.class);
1256:                    assertTrue(MSG_TEST_FAILED + objToSave, twoLoadedObjects[1]
1257:                            .getClass() == Date.class);
1258:
1259:                } catch (IOException e) {
1260:                    fail("IOException serializing " + objToSave + " : "
1261:                            + e.getMessage());
1262:                } catch (ClassNotFoundException e) {
1263:                    fail("ClassNotFoundException reading Object type : "
1264:                            + e.getMessage());
1265:                } catch (Error err) {
1266:                    System.out.println("Error when obj = " + objToSave);
1267:                    // err.printStackTrace();
1268:                    throw err;
1269:                }
1270:            }
1271:
1272:            public void test_18_55_writeObject() {
1273:                // Test for method void
1274:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1275:
1276:                Object objToSave = null;
1277:                Object objLoaded;
1278:
1279:                try {
1280:                    Object[] threeObjects = new Object[3];
1281:                    threeObjects[0] = new Integer(2);
1282:                    threeObjects[1] = Date.class;
1283:                    threeObjects[2] = threeObjects[0]; // has to be the same
1284:                    objToSave = threeObjects;
1285:                    if (DEBUG)
1286:                        System.out.println("Obj = " + objToSave);
1287:                    objLoaded = dumpAndReload(objToSave);
1288:                    // Has to have worked
1289:                    Object[] threeLoadedObjects = (Object[]) objLoaded;
1290:                    assertTrue(MSG_TEST_FAILED + objToSave,
1291:                            threeLoadedObjects[0].getClass() == Integer.class);
1292:                    assertTrue(MSG_TEST_FAILED + objToSave,
1293:                            threeLoadedObjects[1] == Date.class);
1294:                    assertTrue(MSG_TEST_FAILED + objToSave,
1295:                            threeLoadedObjects[0] == threeLoadedObjects[2]);
1296:
1297:                } catch (IOException e) {
1298:                    fail("IOException serializing " + objToSave + " : "
1299:                            + e.getMessage());
1300:                } catch (ClassNotFoundException e) {
1301:                    fail("ClassNotFoundException reading Object type : "
1302:                            + e.getMessage());
1303:                } catch (Error err) {
1304:                    System.out.println("Error when obj = " + objToSave);
1305:                    // err.printStackTrace();
1306:                    throw err;
1307:                }
1308:            }
1309:
1310:            public void test_18_56_writeObject() {
1311:                // Test for method void
1312:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1313:
1314:                Object objToSave = null;
1315:                Object objLoaded;
1316:
1317:                try {
1318:                    // Test for 1FD24BY
1319:                    NestedPutField test = new NestedPutField();
1320:                    objToSave = test;
1321:                    if (DEBUG)
1322:                        System.out.println("Obj = " + objToSave);
1323:                    objLoaded = dumpAndReload(objToSave);
1324:                    // Has to have worked
1325:                    assertNotNull(MSG_TEST_FAILED + objToSave,
1326:                            ((NestedPutField) objLoaded).field1);
1327:
1328:                } catch (IOException e) {
1329:                    fail("IOException serializing " + objToSave + " : "
1330:                            + e.getMessage());
1331:                } catch (ClassNotFoundException e) {
1332:                    fail("ClassNotFoundException reading Object type : "
1333:                            + e.getMessage());
1334:                } catch (Error err) {
1335:                    System.out.println("Error when obj = " + objToSave);
1336:                    // err.printStackTrace();
1337:                    throw err;
1338:                }
1339:            }
1340:
1341:            public void test_18_57_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:                    ByteArrayOutputStream out;
1350:                    StreamBasedReplacementWhenDumping streamBasedReplacementWhenDumping;
1351:
1352:                    out = new ByteArrayOutputStream();
1353:                    streamBasedReplacementWhenDumping = new StreamBasedReplacementWhenDumping(
1354:                            out);
1355:                    ;
1356:                    objToSave = FOO.getClass();
1357:                    if (DEBUG)
1358:                        System.out.println("Obj = " + objToSave);
1359:                    streamBasedReplacementWhenDumping.writeObject(objToSave);
1360:                    // Has to have run the replacement method
1361:                    assertTrue(
1362:                            "Executed replacement when it should not: "
1363:                                    + objToSave,
1364:                            !streamBasedReplacementWhenDumping.calledClassReplacement);
1365:
1366:                } catch (IOException e) {
1367:                    fail("Exception serializing " + objToSave + "\t->"
1368:                            + e.toString());
1369:                } catch (Error err) {
1370:                    System.out.println("Error " + err + " when obj = "
1371:                            + objToSave);
1372:                    throw err;
1373:                }
1374:            }
1375:
1376:            public void test_18_58_writeObject() {
1377:                // Test for method void
1378:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1379:
1380:                Object objToSave = null;
1381:                Object objLoaded;
1382:
1383:                try {
1384:                    ByteArrayOutputStream out;
1385:                    StreamBasedReplacementWhenDumping streamBasedReplacementWhenDumping;
1386:
1387:                    out = new ByteArrayOutputStream();
1388:                    streamBasedReplacementWhenDumping = new StreamBasedReplacementWhenDumping(
1389:                            out);
1390:                    ;
1391:                    objToSave = ObjectStreamClass.lookup(FOO.getClass());
1392:                    if (DEBUG)
1393:                        System.out.println("Obj = " + objToSave);
1394:                    streamBasedReplacementWhenDumping.writeObject(objToSave);
1395:                    // Has to have run the replacement method
1396:                    assertTrue(
1397:                            "Executed replacement when it should not: "
1398:                                    + objToSave,
1399:                            !streamBasedReplacementWhenDumping.calledObjectStreamClassReplacement);
1400:
1401:                } catch (IOException e) {
1402:                    fail("Exception serializing " + objToSave + "\t->"
1403:                            + e.toString());
1404:                } catch (Error err) {
1405:                    System.out.println("Error " + err + " when obj = "
1406:                            + objToSave);
1407:                    throw err;
1408:                }
1409:            }
1410:
1411:            public void test_18_59_writeObject() {
1412:                // Test for method void
1413:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1414:
1415:                Object objToSave = null;
1416:                Object objLoaded;
1417:
1418:                try {
1419:                    ByteArrayOutputStream out;
1420:                    StreamBasedReplacementWhenDumping streamBasedReplacementWhenDumping;
1421:
1422:                    out = new ByteArrayOutputStream();
1423:                    streamBasedReplacementWhenDumping = new StreamBasedReplacementWhenDumping(
1424:                            out);
1425:                    ;
1426:                    objToSave = new int[3];
1427:                    if (DEBUG)
1428:                        System.out.println("Obj = " + objToSave);
1429:                    streamBasedReplacementWhenDumping.writeObject(objToSave);
1430:                    // Has to have run the replacement method
1431:                    assertTrue(
1432:                            "DId not execute replacement when it should: "
1433:                                    + objToSave,
1434:                            streamBasedReplacementWhenDumping.calledArrayReplacement);
1435:
1436:                } catch (IOException e) {
1437:                    fail("Exception serializing " + objToSave + "\t->"
1438:                            + e.toString());
1439:                } catch (Error err) {
1440:                    System.out.println("Error " + err + " when obj = "
1441:                            + objToSave);
1442:                    throw err;
1443:                }
1444:            }
1445:
1446:            public void test_18_60_writeObject() {
1447:                // Test for method void
1448:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1449:
1450:                Object objToSave = null;
1451:                Object objLoaded;
1452:
1453:                try {
1454:                    ByteArrayOutputStream out;
1455:                    StreamBasedReplacementWhenDumping streamBasedReplacementWhenDumping;
1456:
1457:                    out = new ByteArrayOutputStream();
1458:                    streamBasedReplacementWhenDumping = new StreamBasedReplacementWhenDumping(
1459:                            out);
1460:                    ;
1461:                    objToSave = FOO;
1462:                    if (DEBUG)
1463:                        System.out.println("Obj = " + objToSave);
1464:                    streamBasedReplacementWhenDumping.writeObject(objToSave);
1465:                    // Has to have run the replacement method
1466:                    assertTrue(
1467:                            "Did not execute replacement when it should: "
1468:                                    + objToSave,
1469:                            streamBasedReplacementWhenDumping.calledStringReplacement);
1470:
1471:                } catch (IOException e) {
1472:                    fail("Exception serializing " + objToSave + "\t->"
1473:                            + e.toString());
1474:                } catch (Error err) {
1475:                    System.out.println("Error " + err + " when obj = "
1476:                            + objToSave);
1477:                    throw err;
1478:                }
1479:            }
1480:
1481:            public void test_18_61_writeObject() {
1482:                // Test for method void
1483:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1484:
1485:                Object objToSave = null;
1486:                Object objLoaded;
1487:
1488:                try {
1489:                    ArrayOfSerializable test = new ArrayOfSerializable();
1490:                    objToSave = test;
1491:                    if (DEBUG)
1492:                        System.out.println("Obj = " + objToSave);
1493:                    objLoaded = dumpAndReload(objToSave);
1494:                    // Has to have worked
1495:                    assertTrue(MSG_TEST_FAILED + objToSave, true);
1496:
1497:                } catch (IOException e) {
1498:                    fail("IOException serializing " + objToSave + " : "
1499:                            + e.getMessage());
1500:                } catch (ClassNotFoundException e) {
1501:                    fail("ClassNotFoundException reading Object type : "
1502:                            + e.getMessage());
1503:                } catch (Error err) {
1504:                    System.out.println("Error when obj = " + objToSave);
1505:                    // err.printStackTrace();
1506:                    throw err;
1507:                }
1508:            }
1509:
1510:            public void test_18_62_writeObject() {
1511:                // Test for method void
1512:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1513:
1514:                Object objToSave = null;
1515:                Object objLoaded;
1516:
1517:                try {
1518:                    ClassSubClassTest1 test = new ClassSubClassTest1(
1519:                            "SuperInitialString", "SubInitialString");
1520:                    objToSave = test;
1521:                    if (DEBUG)
1522:                        System.out.println("Obj = " + objToSave);
1523:                    objLoaded = dumpAndReload(objToSave);
1524:                    // Has to have worked
1525:                    assertTrue(MSG_TEST_FAILED + objToSave, test
1526:                            .equals(objLoaded));
1527:
1528:                } catch (IOException e) {
1529:                    fail("IOException serializing " + objToSave + " : "
1530:                            + e.getMessage());
1531:                } catch (ClassNotFoundException e) {
1532:                    fail("ClassNotFoundException reading Object type : "
1533:                            + e.getMessage());
1534:                } catch (Error err) {
1535:                    System.out.println("Error when obj = " + objToSave);
1536:                    // err.printStackTrace();
1537:                    throw err;
1538:                }
1539:            }
1540:
1541:            public void test_18_63_writeObject() {
1542:                // Test for method void
1543:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1544:
1545:                Object objToSave = null;
1546:                Object objLoaded;
1547:
1548:                try {
1549:                    ConstructorTestC test = new ConstructorTestC();
1550:                    objToSave = test;
1551:                    if (DEBUG)
1552:                        System.out.println("Obj = " + objToSave);
1553:                    objLoaded = dumpAndReload(objToSave);
1554:                    // Has to have worked
1555:                    assertTrue(MSG_TEST_FAILED + objToSave, test
1556:                            .verify(objLoaded));
1557:
1558:                } catch (IOException e) {
1559:                    fail("IOException serializing " + objToSave + " : "
1560:                            + e.getMessage());
1561:                } catch (ClassNotFoundException e) {
1562:                    fail("ClassNotFoundException reading Object type : "
1563:                            + e.getMessage());
1564:                } catch (Error err) {
1565:                    System.out.println("Error when obj = " + objToSave);
1566:                    // err.printStackTrace();
1567:                    throw err;
1568:                }
1569:            }
1570:
1571:            public void test_18_64_writeObject() {
1572:                // Test for method void
1573:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1574:
1575:                Object objToSave = null;
1576:                Object objLoaded;
1577:
1578:                try {
1579:                    HashCodeTest test = new HashCodeTest();
1580:                    objToSave = test;
1581:                    if (DEBUG)
1582:                        System.out.println("Obj = " + objToSave);
1583:                    objLoaded = dumpAndReload(objToSave);
1584:                    // Has to have worked
1585:                    assertTrue(
1586:                            MSG_TEST_FAILED + objToSave,
1587:                            !((HashCodeTest) objLoaded).serializationUsesHashCode);
1588:
1589:                } catch (IOException e) {
1590:                    fail("IOException serializing " + objToSave + " : "
1591:                            + e.getMessage());
1592:                } catch (ClassNotFoundException e) {
1593:                    fail("ClassNotFoundException reading Object type : "
1594:                            + e.getMessage());
1595:                } catch (Error err) {
1596:                    System.out.println("Error when obj = " + objToSave);
1597:                    // err.printStackTrace();
1598:                    throw err;
1599:                }
1600:            }
1601:
1602:            public void test_18_65_writeObject() {
1603:                // Test for method void
1604:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1605:
1606:                Object objToSave = null;
1607:                Object objLoaded;
1608:
1609:                try {
1610:                    InitializerFieldsTest test = new InitializerFieldsTest();
1611:                    test.toBeSerialized = "serializing";
1612:                    InitializerFieldsTest.toBeNotSerialized = "It should not have this value after loaded from a File";
1613:                    InitializerFieldsTest.toBeNotSerialized2 = "Good-This is the rigth value.";
1614:
1615:                    objToSave = test;
1616:                    if (DEBUG)
1617:                        System.out.println("Obj = " + objToSave);
1618:                    dump(objToSave);
1619:                    InitializerFieldsTest.toBeNotSerialized = new String(
1620:                            InitializerFieldsTest.toBeNotSerialized2);
1621:                    objLoaded = reload();
1622:
1623:                    // Has to have worked
1624:                    assertTrue(MSG_TEST_FAILED + objToSave, (test
1625:                            .equals(objLoaded)));
1626:
1627:                } catch (IOException e) {
1628:                    fail("IOException serializing " + objToSave + " : "
1629:                            + e.getMessage());
1630:                } catch (ClassNotFoundException e) {
1631:                    fail("ClassNotFoundException reading Object type : "
1632:                            + e.getMessage());
1633:                } catch (Error err) {
1634:                    System.out.println("Error when obj = " + objToSave);
1635:                    // err.printStackTrace();
1636:                    throw err;
1637:                }
1638:            }
1639:
1640:            public void test_18_66_writeObject() {
1641:                // Test for method void
1642:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1643:
1644:                Object objToSave = null;
1645:                Object objLoaded;
1646:
1647:                try {
1648:                    InitializerFieldsTest2 test = new InitializerFieldsTest2();
1649:                    test.toBeSerialized = "serializing";
1650:                    test.toBeSerialized3 = "serializing3";
1651:                    test.toBeSerialized4 = "serializing4";
1652:                    test.toBeSerialized5 = "serializing5";
1653:                    InitializerFieldsTest2.toBeNotSerialized = "It should not have this value after loaded from a File";
1654:                    InitializerFieldsTest2.toBeNotSerialized2 = "Good-This is the rigth value.";
1655:
1656:                    objToSave = test;
1657:                    if (DEBUG)
1658:                        System.out.println("Obj = " + objToSave);
1659:                    dump(objToSave);
1660:                    InitializerFieldsTest2.toBeNotSerialized = new String(
1661:                            InitializerFieldsTest2.toBeNotSerialized2);
1662:                    objLoaded = reload();
1663:
1664:                    // Has to have worked
1665:                    assertTrue(MSG_TEST_FAILED + objToSave, (test
1666:                            .equals(objLoaded)));
1667:
1668:                } catch (IOException e) {
1669:                    fail("IOException serializing " + objToSave + " : "
1670:                            + e.getMessage());
1671:                } catch (ClassNotFoundException e) {
1672:                    fail("ClassNotFoundException reading Object type : "
1673:                            + e.getMessage());
1674:                } catch (Error err) {
1675:                    System.out.println("Error when obj = " + objToSave);
1676:                    // err.printStackTrace();
1677:                    throw err;
1678:                }
1679:            }
1680:
1681:            public void test_18_67_writeObject() {
1682:                // Test for method void
1683:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1684:
1685:                Object objToSave = null;
1686:                Object objLoaded;
1687:
1688:                try {
1689:                    InitializerFieldsTest3 test = new InitializerFieldsTest3();
1690:                    test.toBeSerialized = "serializing";
1691:                    test.toBeSerialized3 = "serializing3";
1692:                    test.toBeSerialized4 = "serializing4";
1693:                    test.toBeSerialized5 = "serializing5";
1694:                    InitializerFieldsTest2.toBeNotSerialized = "It should not have this value after loaded from a File";
1695:                    InitializerFieldsTest2.toBeNotSerialized2 = "Good-This is the rigth value.";
1696:                    test.sub_toBeSerialized = "serializingSub";
1697:                    test.sub_toBeSerialized3 = "serializing3sub";
1698:                    test.sub_toBeSerialized4 = "serializing4sub";
1699:                    test.sub_toBeSerialized5 = "serializing5sub";
1700:                    InitializerFieldsTest3.sub_toBeNotSerialized = "(Subclass) It should not have this value after loaded from a File";
1701:                    InitializerFieldsTest3.sub_toBeNotSerialized2 = "(Subclass) Good-This is the rigth value.";
1702:                    // Before dumping the two static vars are differents.
1703:                    // After dumping the value of toBeNotSerialized2 is put in
1704:                    // toBeNotSerialized
1705:                    // After loading it must be the same.
1706:                    objToSave = test;
1707:                    if (DEBUG)
1708:                        System.out.println("Obj = " + objToSave);
1709:                    dump(objToSave);
1710:                    InitializerFieldsTest2.toBeNotSerialized = new String(
1711:                            InitializerFieldsTest2.toBeNotSerialized2);
1712:                    InitializerFieldsTest3.sub_toBeNotSerialized = new String(
1713:                            InitializerFieldsTest3.sub_toBeNotSerialized2);
1714:                    objLoaded = reload();
1715:
1716:                    // Has to have worked
1717:                    assertTrue(MSG_TEST_FAILED + objToSave, (test
1718:                            .equals(objLoaded)));
1719:
1720:                } catch (IOException e) {
1721:                    fail("IOException serializing " + objToSave + " : "
1722:                            + e.getMessage());
1723:                } catch (ClassNotFoundException e) {
1724:                    fail("ClassNotFoundException reading Object type : "
1725:                            + e.getMessage());
1726:                } catch (Error err) {
1727:                    System.out.println("Error when obj = " + objToSave);
1728:                    // err.printStackTrace();
1729:                    throw err;
1730:                }
1731:            }
1732:
1733:            public void test_DeepNesting() {
1734:                // Test for method void
1735:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1736:
1737:                Object objToSave = null;
1738:                Object objLoaded;
1739:
1740:                try {
1741:                    DeepNesting test = new DeepNesting(50);
1742:                    objToSave = test;
1743:                    if (DEBUG)
1744:                        System.out.println("Obj = " + objToSave);
1745:                    objLoaded = dumpAndReload(objToSave);
1746:
1747:                    // Has to have worked
1748:                    assertTrue(MSG_TEST_FAILED + objToSave, (test
1749:                            .equals(objLoaded)));
1750:
1751:                } catch (IOException e) {
1752:                    fail("IOException serializing " + objToSave + " : "
1753:                            + e.getMessage());
1754:                } catch (ClassNotFoundException e) {
1755:                    fail("ClassNotFoundException reading Object type : "
1756:                            + e.getMessage());
1757:                } catch (Error err) {
1758:                    // err.printStackTrace();
1759:                    System.out.println("Error " + err + " when obj = "
1760:                            + objToSave);
1761:                    throw err;
1762:                }
1763:            }
1764:
1765:            public void test_DeepNestingWithWriteObject() {
1766:                // Test for method void
1767:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1768:
1769:                Object objToSave = null;
1770:                Object objLoaded;
1771:
1772:                try {
1773:                    DeepNestingWithWriteObject test = new DeepNestingWithWriteObject(
1774:                            50);
1775:                    objToSave = test;
1776:                    if (DEBUG)
1777:                        System.out.println("Obj = " + objToSave);
1778:                    objLoaded = dumpAndReload(objToSave);
1779:
1780:                    // Has to have worked
1781:                    assertTrue(MSG_TEST_FAILED + objToSave, (test
1782:                            .equals(objLoaded)));
1783:
1784:                } catch (IOException e) {
1785:                    fail("IOException serializing " + objToSave + " : "
1786:                            + e.getMessage());
1787:                } catch (ClassNotFoundException e) {
1788:                    fail("ClassNotFoundException reading Object type : "
1789:                            + e.getMessage());
1790:                } catch (Error err) {
1791:                    // err.printStackTrace();
1792:                    System.out.println("Error " + err + " when obj = "
1793:                            + objToSave);
1794:                    throw err;
1795:                }
1796:            }
1797:
1798:            public void test_18_69_writeObject() {
1799:                // Test for method void
1800:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1801:
1802:                Object objToSave = null;
1803:                Object objLoaded;
1804:
1805:                try {
1806:                    NonPublicClassTest test = new NonPublicClassTest();
1807:                    test.x10();
1808:                    objToSave = test;
1809:                    if (DEBUG)
1810:                        System.out.println("Obj = " + objToSave);
1811:                    objLoaded = dumpAndReload(objToSave);
1812:
1813:                    // Has to have worked
1814:                    assertTrue(MSG_TEST_FAILED + objToSave, (test
1815:                            .equals(objLoaded)));
1816:
1817:                } catch (IOException e) {
1818:                    fail("IOException serializing " + objToSave + " : "
1819:                            + e.getMessage());
1820:                } catch (ClassNotFoundException e) {
1821:                    fail("ClassNotFoundException reading Object type : "
1822:                            + e.getMessage());
1823:                } catch (Error err) {
1824:                    System.out.println("Error when obj = " + objToSave);
1825:                    // err.printStackTrace();
1826:                    throw err;
1827:                }
1828:            }
1829:
1830:            public void test_18_70_writeObject() {
1831:                // Test for method void
1832:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1833:
1834:                Object objToSave = null;
1835:                Object objLoaded;
1836:
1837:                try {
1838:                    int[] test = new int[1];
1839:                    int intValue = 0;
1840:                    test[0] = intValue;
1841:                    objToSave = test;
1842:                    if (DEBUG)
1843:                        System.out.println("Obj = " + objToSave);
1844:                    objLoaded = dumpAndReload(objToSave);
1845:
1846:                    // Has to have worked
1847:                    assertTrue(MSG_TEST_FAILED + objToSave, Arrays.equals(test,
1848:                            (int[]) objLoaded));
1849:
1850:                } catch (IOException e) {
1851:                    fail("IOException serializing " + objToSave + " : "
1852:                            + e.getMessage());
1853:                } catch (ClassNotFoundException e) {
1854:                    fail("ClassNotFoundException reading Object type : "
1855:                            + e.getMessage());
1856:                } catch (Error err) {
1857:                    System.out.println("Error when obj = " + objToSave);
1858:                    // err.printStackTrace();
1859:                    throw err;
1860:                }
1861:            }
1862:
1863:            public void test_18_71_writeObject() {
1864:                // Test for method void
1865:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1866:
1867:                Object objToSave = null;
1868:                Object objLoaded;
1869:
1870:                try {
1871:                    int i, j, maxJ = 3, maxI = 200;
1872:                    byte[][] obj = new byte[maxJ][maxI];
1873:                    for (j = 0; j < maxJ; j++) {
1874:                        for (i = 0; i < maxI; i++)
1875:                            obj[j][i] = (byte) (i - 100);
1876:                    }
1877:                    objToSave = obj;
1878:                    if (DEBUG)
1879:                        System.out.println("Obj = " + objToSave);
1880:                    objLoaded = dumpAndReload(objToSave);
1881:                    byte[][] toCompare = (byte[][]) objLoaded;
1882:
1883:                    boolean ok = true;
1884:                    // Has to have worked
1885:                    for (j = 0; j < maxJ; j++) {
1886:                        for (i = 0; i < maxI; i++)
1887:                            if (obj[j][i] != toCompare[j][i]) {
1888:                                ok = false;
1889:                                break;
1890:                            }
1891:                    }
1892:
1893:                    assertTrue(MSG_TEST_FAILED + objToSave, ok);
1894:
1895:                } catch (IOException e) {
1896:                    fail("IOException serializing " + objToSave + " : "
1897:                            + e.getMessage());
1898:                } catch (ClassNotFoundException e) {
1899:                    fail("ClassNotFoundException reading Object type : "
1900:                            + e.getMessage());
1901:                } catch (Error err) {
1902:                    System.out.println("Error when obj = " + objToSave);
1903:                    // err.printStackTrace();
1904:                    throw err;
1905:                }
1906:            }
1907:
1908:            public void test_18_72_writeObject() {
1909:                // Test for method void
1910:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1911:
1912:                Object objToSave = null;
1913:                Object objLoaded;
1914:
1915:                try {
1916:                    int i, j, maxJ = 3, maxI = 200;
1917:                    int[][] obj = new int[maxJ][maxI];
1918:                    for (j = 0; j < maxJ; j++) {
1919:                        for (i = 0; i < maxI; i++)
1920:                            obj[j][i] = (i - 100);
1921:                    }
1922:                    objToSave = obj;
1923:                    if (DEBUG)
1924:                        System.out.println("Obj = " + objToSave);
1925:                    objLoaded = dumpAndReload(objToSave);
1926:                    int[][] toCompare = (int[][]) objLoaded;
1927:
1928:                    boolean ok = true;
1929:                    // Has to have worked
1930:                    for (j = 0; j < maxJ; j++) {
1931:                        for (i = 0; i < maxI; i++)
1932:                            if (obj[j][i] != toCompare[j][i]) {
1933:                                ok = false;
1934:                                break;
1935:                            }
1936:                    }
1937:
1938:                    assertTrue(MSG_TEST_FAILED + objToSave, ok);
1939:
1940:                } catch (IOException e) {
1941:                    fail("IOException serializing " + objToSave + " : "
1942:                            + e.getMessage());
1943:                } catch (ClassNotFoundException e) {
1944:                    fail("ClassNotFoundException reading Object type : "
1945:                            + e.getMessage());
1946:                } catch (Error err) {
1947:                    System.out.println("Error when obj = " + objToSave);
1948:                    // err.printStackTrace();
1949:                    throw err;
1950:                }
1951:            }
1952:
1953:            public void test_18_73_writeObject() {
1954:                // Test for method void
1955:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1956:
1957:                Object objToSave = null;
1958:                Object objLoaded;
1959:
1960:                try {
1961:                    String org = "abcdefghijklmnopqrstuvxyz1234567890abcdefghijklmnopqrstuvxyz1234567890";
1962:                    int i, j, maxJ = 3, maxI = 70;
1963:                    String[][] obj = new String[maxJ][maxI];
1964:                    for (j = 0; j < maxJ; j++) {
1965:                        for (i = 0; i < maxI; i++)
1966:                            obj[j][i] = org.substring(0, i);
1967:                    }
1968:                    objToSave = obj;
1969:                    if (DEBUG)
1970:                        System.out.println("Obj = " + objToSave);
1971:                    objLoaded = dumpAndReload(objToSave);
1972:                    String[][] toCompare = (String[][]) objLoaded;
1973:
1974:                    boolean ok = true;
1975:                    // Has to have worked
1976:                    for (j = 0; j < maxJ; j++) {
1977:                        for (i = 0; i < maxI; i++)
1978:                            if (!obj[j][i].equals(toCompare[j][i])) {
1979:                                ok = false;
1980:                                break;
1981:                            }
1982:                    }
1983:
1984:                    assertTrue(MSG_TEST_FAILED + objToSave, ok);
1985:
1986:                } catch (IOException e) {
1987:                    fail("IOException serializing " + objToSave + " : "
1988:                            + e.getMessage());
1989:                } catch (ClassNotFoundException e) {
1990:                    fail("ClassNotFoundException reading Object type : "
1991:                            + e.getMessage());
1992:                } catch (Error err) {
1993:                    System.out.println("Error when obj = " + objToSave);
1994:                    // err.printStackTrace();
1995:                    throw err;
1996:                }
1997:            }
1998:
1999:            public void test_18_74_writeObject() {
2000:                // Test for method void
2001:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
2002:
2003:                Object objToSave = null;
2004:                Object objLoaded;
2005:
2006:                try {
2007:                    SameInstVarNameSubClass test = new SameInstVarNameSubClass(
2008:                            100);
2009:                    objToSave = test;
2010:                    if (DEBUG)
2011:                        System.out.println("Obj = " + objToSave);
2012:                    objLoaded = dumpAndReload(objToSave);
2013:                    // Has to have worked
2014:                    assertTrue(MSG_TEST_FAILED + objToSave,
2015:                            ((SameInstVarNameSubClass) objLoaded).foo == 100);
2016:
2017:                } catch (IOException e) {
2018:                    fail("IOException serializing " + objToSave + " : "
2019:                            + e.getMessage());
2020:                } catch (ClassNotFoundException e) {
2021:                    fail("ClassNotFoundException reading Object type : "
2022:                            + e.getMessage());
2023:                } catch (Error err) {
2024:                    System.out.println("Error when obj = " + objToSave);
2025:                    // err.printStackTrace();
2026:                    throw err;
2027:                }
2028:            }
2029:
2030:            public void test_18_75_writeObject() {
2031:                // Test for method void
2032:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
2033:
2034:                Object objToSave = null;
2035:                Object objLoaded;
2036:
2037:                try {
2038:                    SInterfaceTest test = new SInterfaceTest();
2039:                    objToSave = test;
2040:                    if (DEBUG)
2041:                        System.out.println("Obj = " + objToSave);
2042:                    objLoaded = dumpAndReload(objToSave);
2043:                    // Has to have worked
2044:                    assertTrue(MSG_TEST_FAILED + objToSave, test
2045:                            .equals(objLoaded));
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:            public void test_18_76_writeObject() {
2061:                // Test for method void
2062:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
2063:
2064:                Object objToSave = null;
2065:                Object objLoaded;
2066:
2067:                try {
2068:                    SInterfaceTest2 test = new SInterfaceTest2();
2069:                    objToSave = test;
2070:                    if (DEBUG)
2071:                        System.out.println("Obj = " + objToSave);
2072:                    objLoaded = dumpAndReload(objToSave);
2073:                    // Has to have worked
2074:                    assertTrue(MSG_TEST_FAILED + objToSave, test
2075:                            .equals(objLoaded));
2076:
2077:                } catch (IOException e) {
2078:                    fail("IOException serializing " + objToSave + " : "
2079:                            + e.getMessage());
2080:                } catch (ClassNotFoundException e) {
2081:                    fail("ClassNotFoundException reading Object type : "
2082:                            + e.getMessage());
2083:                } catch (Error err) {
2084:                    System.out.println("Error when obj = " + objToSave);
2085:                    // err.printStackTrace();
2086:                    throw err;
2087:                }
2088:            }
2089:
2090:            public void test_18_77_writeObject() {
2091:                // Test for method void
2092:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
2093:
2094:                Object objToSave = null;
2095:                Object objLoaded;
2096:
2097:                try {
2098:                    SuperclassTest test = new SuperclassTest();
2099:                    objToSave = test;
2100:                    if (DEBUG)
2101:                        System.out.println("Obj = " + objToSave);
2102:                    objLoaded = dumpAndReload(objToSave);
2103:                    // Has to have worked
2104:                    assertTrue(MSG_TEST_FAILED + objToSave, test
2105:                            .equals(objLoaded));
2106:
2107:                } catch (IOException e) {
2108:                    fail("IOException serializing " + objToSave + " : "
2109:                            + e.getMessage());
2110:                } catch (ClassNotFoundException e) {
2111:                    fail("ClassNotFoundException reading Object type : "
2112:                            + e.getMessage());
2113:                } catch (Error err) {
2114:                    System.out.println("Error when obj = " + objToSave);
2115:                    // err.printStackTrace();
2116:                    throw err;
2117:                }
2118:            }
2119:
2120:            public void test_18_78_writeObject() {
2121:                // Test for method void
2122:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
2123:
2124:                Object objToSave = null;
2125:                Object objLoaded;
2126:
2127:                try {
2128:                    SuperclassTest2 test = new SuperclassTest2();
2129:                    objToSave = test;
2130:                    if (DEBUG)
2131:                        System.out.println("Obj = " + objToSave);
2132:                    objLoaded = dumpAndReload(objToSave);
2133:                    // Has to have worked
2134:                    assertTrue(MSG_TEST_FAILED + objToSave, test
2135:                            .equals(objLoaded));
2136:
2137:                } catch (IOException e) {
2138:                    fail("IOException serializing " + objToSave + " : "
2139:                            + e.getMessage());
2140:                } catch (ClassNotFoundException e) {
2141:                    fail("ClassNotFoundException reading Object type : "
2142:                            + e.getMessage());
2143:                } catch (Error err) {
2144:                    System.out.println("Error when obj = " + objToSave);
2145:                    // err.printStackTrace();
2146:                    throw err;
2147:                }
2148:            }
2149:
2150:            public void test_18_79_writeObject() {
2151:                // Test for method void
2152:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
2153:
2154:                Object objToSave = null;
2155:                Object objLoaded;
2156:
2157:                try {
2158:                    SyntheticFieldTest test = new SyntheticFieldTest();
2159:                    objToSave = test;
2160:                    if (DEBUG)
2161:                        System.out.println("Obj = " + objToSave);
2162:                    objLoaded = dumpAndReload(objToSave);
2163:                    // Has to have worked
2164:                    assertTrue(MSG_TEST_FAILED + objToSave, test
2165:                            .equals(objLoaded));
2166:
2167:                } catch (IOException e) {
2168:                    fail("IOException serializing " + objToSave + " : "
2169:                            + e.getMessage());
2170:                } catch (ClassNotFoundException e) {
2171:                    fail("ClassNotFoundException reading Object type : "
2172:                            + e.getMessage());
2173:                } catch (Error err) {
2174:                    System.out.println("Error when obj = " + objToSave);
2175:                    // err.printStackTrace();
2176:                    throw err;
2177:                }
2178:            }
2179:
2180:            public void test_18_80_writeObject() {
2181:                // Test for method void
2182:                // java.io.ObjectOutputStream.writeObject(java.lang.Object)
2183:
2184:                try {
2185:                    ByteArrayOutputStream out = new ByteArrayOutputStream();
2186:                    DataOutputStream dos = new DataOutputStream(out);
2187:                    new ObjectOutputStream(dos); // just to make sure we get a header
2188:                    dos.writeByte(ObjectStreamConstants.TC_BLOCKDATA);
2189:                    int length = 99;
2190:                    dos.writeByte(length);
2191:                    for (int i = 0; i < length; i++) {
2192:                        dos.writeByte(0); // actual value does not matter
2193:                    }
2194:                    dos.flush();
2195:                    int lengthRead = 0;
2196:                    try {
2197:                        ObjectInputStream ois = new ObjectInputStream(
2198:                                new ByteArrayInputStream(out.toByteArray()));
2199:                        Object obj = ois.readObject();
2200:                    } catch (OptionalDataException e) {
2201:                        lengthRead = e.length;
2202:                    }
2203:                    assertTrue(
2204:                            "Did not throw exception with optional data size ",
2205:                            length == lengthRead);
2206:                } catch (ClassNotFoundException e) {
2207:                    fail("Unable to read BLOCKDATA: " + e.getMessage());
2208:                } catch (IOException e) {
2209:                    fail("IOException testing BLOCKDATA : " + e.getMessage());
2210:                } catch (Error err) {
2211:                    System.out.println("Error " + err
2212:                            + " when testing BLOCKDATA");
2213:                    throw err;
2214:                }
2215:            }
2216:        }
w_w_w__.j___a__va2_s._c_om___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.