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.File;
0021: import java.io.FilePermission;
0022: import java.io.IOException;
0023: import java.io.Serializable;
0024: import java.lang.reflect.InvocationHandler;
0025: import java.lang.reflect.Method;
0026: import java.lang.reflect.Proxy;
0027: import java.net.URI;
0028: import java.net.URISyntaxException;
0029: import java.security.AllPermission;
0030: import java.security.PermissionCollection;
0031: import java.security.cert.Certificate;
0032: import java.text.DateFormat;
0033: import java.text.MessageFormat;
0034: import java.text.NumberFormat;
0035: import java.util.*;
0036:
0037: import tests.support.Support_Configuration;
0038: import tests.support.Support_Proxy_I1;
0039:
0040: @SuppressWarnings({"serial","unused"})
0041: public class SerializationStressTest4 extends SerializationStressTest {
0042: // -----------------------------------------------------------------------------------
0043: private static class GuardImplementation implements
0044: java.security.Guard, java.io.Serializable {
0045: public GuardImplementation() {
0046: }
0047:
0048: public void checkGuard(Object o) {
0049: }
0050: }
0051:
0052: public SerializationStressTest4(String name) {
0053: super (name);
0054: }
0055:
0056: public void test_writeObject_EventObject() {
0057: // Test for method void
0058: // java.io.ObjectOutputStream.writeObject(java.util.EventObject)
0059:
0060: Object objToSave = null;
0061: Object objLoaded = null;
0062:
0063: try {
0064: objToSave = new java.util.EventObject("Source");
0065: if (DEBUG)
0066: System.out.println("Obj = " + objToSave);
0067: objLoaded = dumpAndReload(objToSave);
0068:
0069: // Has to have worked
0070: boolean equals;
0071: equals = true;
0072: // The the only data in EventObject that
0073: // differentiates between instantiations is transient
0074: assertTrue(MSG_TEST_FAILED + objToSave, equals);
0075: } catch (IOException e) {
0076: fail("IOException serializing " + objToSave + " : "
0077: + e.getMessage());
0078: } catch (ClassNotFoundException e) {
0079: fail("ClassNotFoundException reading Object type : "
0080: + e.getMessage());
0081: } catch (Error err) {
0082: System.out.println("Error when obj = " + objToSave);
0083: // err.printStackTrace();
0084: throw err;
0085: }
0086: }
0087:
0088: public void test_writeObject_PermissionCollection() {
0089: // Test for method void
0090: // java.io.ObjectOutputStream.writeObject(java.security.PermissionCollection)
0091:
0092: Object objToSave = null;
0093: Object objLoaded = null;
0094:
0095: try {
0096: objToSave = null;
0097: objToSave = new PermissionCollection() {
0098: boolean added = false;
0099:
0100: public void add(java.security.Permission p1) {
0101: added = true;
0102: }
0103:
0104: public Enumeration elements() {
0105: return (new Vector()).elements();
0106: }
0107:
0108: public boolean implies(java.security.Permission p1) {
0109: return added;
0110: }
0111:
0112: public boolean equals(Object obj) {
0113: if (!(obj instanceof java.security.PermissionCollection))
0114: return false;
0115: return implies(null) == ((PermissionCollection) obj)
0116: .implies(null);
0117: }
0118: };
0119:
0120: ((java.security.PermissionCollection) objToSave).add(null);
0121: if (DEBUG)
0122: System.out.println("Obj = " + objToSave);
0123: objLoaded = dumpAndReload(objToSave);
0124:
0125: // Has to have worked
0126: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
0127: .equals(objLoaded));
0128: } catch (IOException e) {
0129: fail("IOException serializing " + objToSave + " : "
0130: + e.getMessage());
0131: } catch (ClassNotFoundException e) {
0132: fail("ClassNotFoundException reading Object type : "
0133: + e.getMessage());
0134: } catch (Error err) {
0135: System.out.println("Error when obj = " + objToSave);
0136: // err.printStackTrace();
0137: throw err;
0138: }
0139:
0140: }
0141:
0142: public void test_writeObject_Collections_EmptySet() {
0143: // Test for method void
0144: // java.io.ObjectOutputStream.writeObject(java.util.Collections.EmptySet)
0145:
0146: Object objToSave = null;
0147: Object objLoaded = null;
0148:
0149: try {
0150: objToSave = java.util.Collections.EMPTY_SET;
0151: if (DEBUG)
0152: System.out.println("Obj = " + objToSave);
0153: objLoaded = dumpAndReload(objToSave);
0154:
0155: // Has to have worked
0156: boolean equals;
0157: equals = objToSave.equals(objLoaded);
0158: if (equals)
0159: equals = ((Set) objLoaded).size() == 0;
0160: assertTrue(MSG_TEST_FAILED + objToSave, equals);
0161: } catch (IOException e) {
0162: fail("IOException serializing " + objToSave + " : "
0163: + e.getMessage());
0164: } catch (ClassNotFoundException e) {
0165: fail("ClassNotFoundException reading Object type : "
0166: + e.getMessage());
0167: } catch (Error err) {
0168: System.out.println("Error when obj = " + objToSave);
0169: // err.printStackTrace();
0170: throw err;
0171: }
0172:
0173: }
0174:
0175: public void test_writeObject_Collections_EmptyMap() {
0176: // Test for method void
0177: // java.io.ObjectOutputStream.writeObject(java.util.Collections.EmptySet)
0178:
0179: Object objToSave = null;
0180: Object objLoaded = null;
0181:
0182: try {
0183: objToSave = java.util.Collections.EMPTY_MAP;
0184: if (DEBUG)
0185: System.out.println("Obj = " + objToSave);
0186: objLoaded = dumpAndReload(objToSave);
0187:
0188: // Has to have worked
0189: boolean equals;
0190: equals = objToSave.equals(objLoaded);
0191: if (equals)
0192: equals = ((Map) objLoaded).size() == 0;
0193: assertTrue(MSG_TEST_FAILED + objToSave, equals);
0194: } catch (IOException e) {
0195: fail("IOException serializing " + objToSave + " : "
0196: + e.getMessage());
0197: } catch (ClassNotFoundException e) {
0198: fail("ClassNotFoundException reading Object type : "
0199: + e.getMessage());
0200: } catch (Error err) {
0201: System.out.println("Error when obj = " + objToSave);
0202: // err.printStackTrace();
0203: throw err;
0204: }
0205:
0206: }
0207:
0208: public void test_writeObject_BasicPermissionCollection() {
0209: // Test for method void
0210: // java.io.ObjectOutputStream.writeObject(java.security.BasicPermissionCollection)
0211:
0212: Object objToSave = null;
0213: Object objLoaded = null;
0214:
0215: try {
0216: objToSave = (new RuntimePermission("test"))
0217: .newPermissionCollection();
0218: ((java.security.PermissionCollection) objToSave)
0219: .add(new RuntimePermission("test"));
0220: if (DEBUG)
0221: System.out.println("Obj = " + objToSave);
0222: objLoaded = dumpAndReload(objToSave);
0223:
0224: // Has to have worked
0225: boolean equals;
0226: Enumeration enum1 = ((java.security.PermissionCollection) objToSave)
0227: .elements(), enum2 = ((java.security.PermissionCollection) objLoaded)
0228: .elements();
0229:
0230: equals = true;
0231: while (enum1.hasMoreElements() && equals) {
0232: if (enum2.hasMoreElements())
0233: equals = enum1.nextElement().equals(
0234: enum2.nextElement());
0235: else
0236: equals = false;
0237: }
0238:
0239: if (equals)
0240: equals = !enum2.hasMoreElements();
0241: assertTrue(MSG_TEST_FAILED + objToSave, equals);
0242: } catch (IOException e) {
0243: fail("IOException serializing " + objToSave + " : "
0244: + e.getMessage());
0245: } catch (ClassNotFoundException e) {
0246: fail("ClassNotFoundException reading Object type : "
0247: + e.getMessage());
0248: } catch (Error err) {
0249: System.out.println("Error when obj = " + objToSave);
0250: // err.printStackTrace();
0251: throw err;
0252: }
0253:
0254: }
0255:
0256: public void test_writeObject_UnresolvedPermission() {
0257: // Test for method void
0258: // java.io.ObjectOutputStream.writeObject(java.security.UnresolvedPermission)
0259:
0260: Object objToSave = null;
0261: Object objLoaded = null;
0262:
0263: try {
0264: objToSave = new java.security.UnresolvedPermission("type",
0265: "name", "actions", null);
0266: if (DEBUG)
0267: System.out.println("Obj = " + objToSave);
0268: objLoaded = dumpAndReload(objToSave);
0269:
0270: // Has to have worked
0271: boolean equals;
0272: equals = objToSave.toString().equals(objLoaded.toString());
0273: assertTrue(MSG_TEST_FAILED + objToSave, equals);
0274: } catch (IOException e) {
0275: fail("Exception serializing " + objToSave + " : "
0276: + e.getMessage());
0277: } catch (ClassNotFoundException e) {
0278: fail("ClassNotFoundException reading Object type: "
0279: + e.getMessage());
0280: } catch (Error err) {
0281: System.out.println("Error when obj = " + objToSave);
0282: // err.printStackTrace();
0283: throw err;
0284: }
0285:
0286: }
0287:
0288: public void test_writeObject_Character() {
0289: // Test for method void
0290: // java.io.ObjectOutputStream.writeObject(java.lang.Character)
0291:
0292: Object objToSave = null;
0293: Object objLoaded = null;
0294:
0295: try {
0296: objToSave = new java.lang.Character('c');
0297: if (DEBUG)
0298: System.out.println("Obj = " + objToSave);
0299: objLoaded = dumpAndReload(objToSave);
0300:
0301: // Has to have worked
0302: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
0303: .equals(objLoaded));
0304: } catch (IOException e) {
0305: fail("IOException serializing " + objToSave + " : "
0306: + e.getMessage());
0307: } catch (ClassNotFoundException e) {
0308: fail("ClassNotFoundException reading Object type : "
0309: + e.getMessage());
0310: } catch (Error err) {
0311: System.out.println("Error when obj = " + objToSave);
0312: // err.printStackTrace();
0313: throw err;
0314: }
0315:
0316: }
0317:
0318: public void test_writeObject_Collections_UnmodifiableCollection() {
0319: // Test for method void
0320: // java.io.ObjectOutputStream.writeObject(java.util.Collections.UnmodifiableCollection)
0321:
0322: Object objToSave = null;
0323: Object objLoaded = null;
0324:
0325: try {
0326: objToSave = Collections.unmodifiableCollection(SET);
0327: if (DEBUG)
0328: System.out.println("Obj = " + objToSave);
0329: objLoaded = dumpAndReload(objToSave);
0330:
0331: // Has to have worked
0332: boolean equals;
0333: equals = ((java.util.Collection) objToSave).size() == ((java.util.Collection) objLoaded)
0334: .size();
0335: if (equals) {
0336: java.util.Iterator iter1 = ((java.util.Collection) objToSave)
0337: .iterator(), iter2 = ((java.util.Collection) objLoaded)
0338: .iterator();
0339: while (iter1.hasNext())
0340: equals = equals
0341: && iter1.next().equals(iter2.next());
0342: }
0343: assertTrue(MSG_TEST_FAILED + objToSave, equals);
0344: } catch (IOException e) {
0345: fail("IOException serializing " + objToSave + " : "
0346: + e.getMessage());
0347: } catch (ClassNotFoundException e) {
0348: fail("ClassNotFoundException reading Object type : "
0349: + e.getMessage());
0350: } catch (Error err) {
0351: System.out.println("Error when obj = " + objToSave);
0352: // err.printStackTrace();
0353: throw err;
0354: }
0355:
0356: }
0357:
0358: public void test_writeObject_Format() {
0359: // Test for method void
0360: // java.io.ObjectOutputStream.writeObject(java.text.Format)
0361:
0362: Object objToSave = null;
0363: Object objLoaded = null;
0364:
0365: try {
0366: objToSave = null;
0367: objToSave = new java.text.Format() {
0368: String save = "default";
0369:
0370: public StringBuffer format(Object p1, StringBuffer p2,
0371: java.text.FieldPosition p3) {
0372: return new StringBuffer();
0373: }
0374:
0375: public Object parseObject(String p1,
0376: java.text.ParsePosition p2) {
0377: if (p1 != null)
0378: save = p1;
0379: return save;
0380: }
0381:
0382: public boolean equals(Object obj) {
0383: if (!(obj instanceof java.text.Format))
0384: return false;
0385: return save.equals(((java.text.Format) obj)
0386: .parseObject(null, null));
0387: }
0388: };
0389:
0390: ((java.text.Format) objToSave).parseObject("Test", null);
0391: if (DEBUG)
0392: System.out.println("Obj = " + objToSave);
0393: objLoaded = dumpAndReload(objToSave);
0394:
0395: // Has to have worked
0396: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
0397: .equals(objLoaded));
0398: } catch (IOException e) {
0399: fail("IOException serializing " + objToSave + " : "
0400: + e.getMessage());
0401: } catch (ClassNotFoundException e) {
0402: fail("ClassNotFoundException reading Object type : "
0403: + e.getMessage());
0404: } catch (Error err) {
0405: System.out.println("Error when obj = " + objToSave);
0406: // err.printStackTrace();
0407: throw err;
0408: }
0409: }
0410:
0411: public void test_writeObject_BigDecimal() {
0412: // Test for method void
0413: // java.io.ObjectOutputStream.writeObject(java.math.BigDecimal)
0414:
0415: Object objToSave = null;
0416: Object objLoaded = null;
0417:
0418: try {
0419: objToSave = new java.math.BigDecimal("1.2345");
0420: if (DEBUG)
0421: System.out.println("Obj = " + objToSave);
0422: objLoaded = dumpAndReload(objToSave);
0423:
0424: // Has to have worked
0425: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
0426: .equals(objLoaded));
0427: } catch (IOException e) {
0428: fail("Exception serializing " + objToSave + " : "
0429: + e.getMessage());
0430: } catch (ClassNotFoundException e) {
0431: fail("ClassNotFoundException reading Object type: "
0432: + e.getMessage());
0433: } catch (Error err) {
0434: System.out.println("Error when obj = " + objToSave);
0435: // err.printStackTrace();
0436: throw err;
0437: }
0438:
0439: }
0440:
0441: public void test_writeObject_UnresolvedPermissionCollection() {
0442: // Test for method void
0443: // java.io.ObjectOutputStream.writeObject(java.security.UnresolvedPermissionCollection)
0444:
0445: Object objToSave = null;
0446: Object objLoaded = null;
0447:
0448: try {
0449: objToSave = (new java.security.UnresolvedPermission("type",
0450: "name", "actions", null)).newPermissionCollection();
0451: ((java.security.PermissionCollection) objToSave)
0452: .add(new java.security.UnresolvedPermission("type",
0453: "name", "actions", null));
0454: if (DEBUG)
0455: System.out.println("Obj = " + objToSave);
0456: objLoaded = dumpAndReload(objToSave);
0457:
0458: // Has to have worked
0459: boolean equals;
0460: Enumeration enum1 = ((java.security.PermissionCollection) objToSave)
0461: .elements(), enum2 = ((java.security.PermissionCollection) objLoaded)
0462: .elements();
0463:
0464: equals = true;
0465: while (enum1.hasMoreElements() && equals) {
0466: if (enum2.hasMoreElements())
0467: equals = enum1.nextElement().toString().equals(
0468: enum2.nextElement().toString());
0469: else
0470: equals = false;
0471: }
0472:
0473: if (equals)
0474: equals = !enum2.hasMoreElements();
0475: assertTrue(MSG_TEST_FAILED + objToSave, equals);
0476: } catch (IOException e) {
0477: fail("IOException serializing " + objToSave + " : "
0478: + e.getMessage());
0479: } catch (ClassNotFoundException e) {
0480: fail("ClassNotFoundException reading Object type : "
0481: + e.getMessage());
0482: } catch (Error err) {
0483: System.out.println("Error when obj = " + objToSave);
0484: // err.printStackTrace();
0485: throw err;
0486: }
0487:
0488: }
0489:
0490: public void test_writeObject_SecureRandomSpi() {
0491: // Test for method void
0492: // java.io.ObjectOutputStream.writeObject(java.security.SecureRandomSpi)
0493:
0494: Object objToSave = null;
0495: Object objLoaded = null;
0496:
0497: try {
0498: objToSave = null;
0499: objToSave = new java.security.SecureRandomSpi() {
0500: protected byte[] engineGenerateSeed(int p1) {
0501: return new byte[0];
0502: }
0503:
0504: protected void engineNextBytes(byte[] p1) {
0505: }
0506:
0507: protected void engineSetSeed(byte[] p1) {
0508: }
0509:
0510: public boolean equals(Object obj) {
0511: return true;
0512: }
0513: };
0514: if (DEBUG)
0515: System.out.println("Obj = " + objToSave);
0516: objLoaded = dumpAndReload(objToSave);
0517:
0518: // Has to have worked
0519: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
0520: .equals(objLoaded));
0521: } catch (IOException e) {
0522: fail("Exception serializing " + objToSave + " : "
0523: + e.getMessage());
0524: } catch (ClassNotFoundException e) {
0525: fail("ClassNotFoundException reading Object type: "
0526: + e.getMessage());
0527: } catch (Error err) {
0528: System.out.println("Error when obj = " + objToSave);
0529: // err.printStackTrace();
0530: throw err;
0531: }
0532: }
0533:
0534: public void test_writeObject_Short() {
0535: // Test for method void
0536: // java.io.ObjectOutputStream.writeObject(java.lang.Short)
0537:
0538: Object objToSave = null;
0539: Object objLoaded = null;
0540:
0541: try {
0542: objToSave = new java.lang.Short((short) 107);
0543: if (DEBUG)
0544: System.out.println("Obj = " + objToSave);
0545: objLoaded = dumpAndReload(objToSave);
0546:
0547: // Has to have worked
0548: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
0549: .equals(objLoaded));
0550: } catch (IOException e) {
0551: fail("IOException serializing " + objToSave + " : "
0552: + e.getMessage());
0553: } catch (ClassNotFoundException e) {
0554: fail("ClassNotFoundException reading Object type : "
0555: + e.getMessage());
0556: } catch (Error err) {
0557: System.out.println("Error when obj = " + objToSave);
0558: // err.printStackTrace();
0559: throw err;
0560: }
0561:
0562: }
0563:
0564: public void test_writeObject_Byte() {
0565: // Test for method void
0566: // java.io.ObjectOutputStream.writeObject(java.lang.Byte)
0567:
0568: Object objToSave = null;
0569: Object objLoaded = null;
0570:
0571: try {
0572: objToSave = new java.lang.Byte((byte) 107);
0573: if (DEBUG)
0574: System.out.println("Obj = " + objToSave);
0575: objLoaded = dumpAndReload(objToSave);
0576:
0577: // Has to have worked
0578: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
0579: .equals(objLoaded));
0580: } catch (IOException e) {
0581: fail("Exception serializing " + objToSave + " : "
0582: + e.getMessage());
0583: } catch (ClassNotFoundException e) {
0584: fail("ClassNotFoundException reading Object type: "
0585: + e.getMessage());
0586: } catch (Error err) {
0587: System.out.println("Error when obj = " + objToSave);
0588: // err.printStackTrace();
0589: throw err;
0590: }
0591:
0592: }
0593:
0594: @SuppressWarnings("unchecked")
0595: public void test_writeObject_String_CaseInsensitiveComparator() {
0596: // Test for method void
0597: // java.io.ObjectOutputStream.writeObject(java.lang.String.CaseInsensitiveComparator)
0598:
0599: Object objToSave = null;
0600: Object objLoaded = null;
0601:
0602: try {
0603: objToSave = java.lang.String.CASE_INSENSITIVE_ORDER;
0604: if (DEBUG)
0605: System.out.println("Obj = " + objToSave);
0606: objLoaded = dumpAndReload(objToSave);
0607:
0608: // Has to have worked
0609: boolean equals;
0610: equals = ((Comparator) objToSave)
0611: .compare("apple", "Banana") == ((Comparator) objLoaded)
0612: .compare("apple", "Banana");
0613: assertTrue(MSG_TEST_FAILED + objToSave, equals);
0614: } catch (IOException e) {
0615: fail("IOException serializing " + objToSave + " : "
0616: + e.getMessage());
0617: } catch (ClassNotFoundException e) {
0618: fail("ClassNotFoundException reading Object type : "
0619: + e.getMessage());
0620: } catch (Error err) {
0621: System.out.println("Error when obj = " + objToSave);
0622: // err.printStackTrace();
0623: throw err;
0624: }
0625:
0626: }
0627:
0628: public void test_writeObject_Calendar() {
0629: // Test for method void
0630: // java.io.ObjectOutputStream.writeObject(java.util.Calendar)
0631:
0632: Object objToSave = null;
0633: Object objLoaded = null;
0634:
0635: try {
0636: objToSave = new java.util.Calendar(TimeZone
0637: .getTimeZone("EST"), Locale.CANADA) {
0638: public void add(int p1, int p2) {
0639: }
0640:
0641: protected void computeFields() {
0642: }
0643:
0644: protected void computeTime() {
0645: }
0646:
0647: public int getGreatestMinimum(int p1) {
0648: return 0;
0649: }
0650:
0651: public int getLeastMaximum(int p1) {
0652: return 0;
0653: }
0654:
0655: public int getMaximum(int p1) {
0656: return 0;
0657: }
0658:
0659: public int getMinimum(int p1) {
0660: return 0;
0661: }
0662:
0663: public void roll(int p1, boolean p2) {
0664: }
0665: };
0666: if (DEBUG)
0667: System.out.println("Obj = " + objToSave);
0668: objLoaded = dumpAndReload(objToSave);
0669:
0670: // Has to have worked
0671: assertTrue(MSG_TEST_FAILED + "Calendar", objToSave
0672: .equals(objLoaded));
0673: } catch (IOException e) {
0674: fail("Exception serializing " + objToSave + " : "
0675: + e.getMessage());
0676: } catch (ClassNotFoundException e) {
0677: fail("ClassNotFoundException reading Object type: "
0678: + e.getMessage());
0679: } catch (Error err) {
0680: System.out.println("Error when obj = " + objToSave);
0681: // err.printStackTrace();
0682: throw err;
0683: }
0684:
0685: }
0686:
0687: public void test_writeObject_ReflectPermission() {
0688: // Test for method void
0689: // java.io.ObjectOutputStream.writeObject(java.lang.reflect.ReflectPermission)
0690:
0691: Object objToSave = null;
0692: Object objLoaded = null;
0693:
0694: try {
0695: objToSave = new java.lang.reflect.ReflectPermission(
0696: "TestSerialization", "test");
0697: if (DEBUG)
0698: System.out.println("Obj = " + objToSave);
0699: objLoaded = dumpAndReload(objToSave);
0700:
0701: // Has to have worked
0702: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
0703: .equals(objLoaded));
0704: } catch (IOException e) {
0705: fail("IOException serializing " + objToSave + " : "
0706: + e.getMessage());
0707: } catch (ClassNotFoundException e) {
0708: fail("ClassNotFoundException reading Object type : "
0709: + e.getMessage());
0710: } catch (Error err) {
0711: System.out.println("Error when obj = " + objToSave);
0712: // err.printStackTrace();
0713: throw err;
0714: }
0715:
0716: }
0717:
0718: public void test_writeObject_StringBuffer() {
0719: // Test for method void
0720: // java.io.ObjectOutputStream.writeObject(java.lang.StringBuffer)
0721:
0722: Object objToSave = null;
0723: Object objLoaded = null;
0724:
0725: try {
0726: objToSave = new java.lang.StringBuffer("This is a test.");
0727: if (DEBUG)
0728: System.out.println("Obj = " + objToSave);
0729: objLoaded = dumpAndReload(objToSave);
0730:
0731: // Has to have worked
0732: boolean equals;
0733: equals = ((java.lang.StringBuffer) objToSave).toString()
0734: .equals(
0735: ((java.lang.StringBuffer) objLoaded)
0736: .toString());
0737: assertTrue(MSG_TEST_FAILED + objToSave, equals);
0738: } catch (IOException e) {
0739: fail("Exception serializing " + objToSave + " : "
0740: + e.getMessage());
0741: } catch (ClassNotFoundException e) {
0742: fail("ClassNotFoundException reading Object type: "
0743: + e.getMessage());
0744: } catch (Error err) {
0745: System.out.println("Error when obj = " + objToSave);
0746: // err.printStackTrace();
0747: throw err;
0748: }
0749:
0750: }
0751:
0752: public void test_writeObject_File() {
0753: // Test for method void
0754: // java.io.ObjectOutputStream.writeObject(java.io.File)
0755:
0756: Object objToSave = null;
0757: Object objLoaded = null;
0758:
0759: try {
0760: objToSave = new File("afile.txt");
0761: if (DEBUG)
0762: System.out.println("Obj = " + objToSave);
0763: objLoaded = dumpAndReload(objToSave);
0764:
0765: // Has to have worked
0766: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
0767: .equals(objLoaded));
0768: } catch (IOException e) {
0769: fail("IOException serializing " + objToSave + " : "
0770: + e.getMessage());
0771: } catch (ClassNotFoundException e) {
0772: fail("ClassNotFoundException reading Object type : "
0773: + e.getMessage());
0774: } catch (Error err) {
0775: System.out.println("Error when obj = " + objToSave);
0776: // err.printStackTrace();
0777: throw err;
0778: }
0779:
0780: }
0781:
0782: public void test_writeObject_AllPermissionCollection() {
0783: // Test for method void
0784: // java.io.ObjectOutputStream.writeObject(java.security.AllPermissionCollection)
0785:
0786: Object objToSave = null;
0787: Object objLoaded = null;
0788:
0789: try {
0790: objToSave = (new java.security.AllPermission())
0791: .newPermissionCollection();
0792: ((java.security.PermissionCollection) objToSave)
0793: .add(new java.security.AllPermission());
0794: if (DEBUG)
0795: System.out.println("Obj = " + objToSave);
0796: objLoaded = dumpAndReload(objToSave);
0797:
0798: // Has to have worked
0799: boolean equals;
0800: Enumeration enum1 = ((java.security.PermissionCollection) objToSave)
0801: .elements(), enum2 = ((java.security.PermissionCollection) objLoaded)
0802: .elements();
0803:
0804: equals = true;
0805: while (enum1.hasMoreElements() && equals) {
0806: if (enum2.hasMoreElements())
0807: equals = enum1.nextElement().equals(
0808: enum2.nextElement());
0809: else
0810: equals = false;
0811: }
0812:
0813: if (equals)
0814: equals = !enum2.hasMoreElements();
0815: assertTrue(MSG_TEST_FAILED + objToSave, equals);
0816: } catch (IOException e) {
0817: fail("Exception serializing " + objToSave + " : "
0818: + e.getMessage());
0819: } catch (ClassNotFoundException e) {
0820: fail("ClassNotFoundException reading Object type: "
0821: + e.getMessage());
0822: } catch (Error err) {
0823: System.out.println("Error when obj = " + objToSave);
0824: // err.printStackTrace();
0825: throw err;
0826: }
0827:
0828: }
0829:
0830: public void test_writeObject_BitSet() {
0831: // Test for method void
0832: // java.io.ObjectOutputStream.writeObject(java.util.BitSet)
0833:
0834: Object objToSave = null;
0835: Object objLoaded = null;
0836:
0837: try {
0838: objToSave = new java.util.BitSet();
0839: ((java.util.BitSet) objToSave).set(3);
0840: ((java.util.BitSet) objToSave).set(5);
0841: ((java.util.BitSet) objToSave).set(61, 89);
0842: if (DEBUG)
0843: System.out.println("Obj = " + objToSave);
0844: objLoaded = dumpAndReload(objToSave);
0845:
0846: // Has to have worked
0847: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
0848: .equals(objLoaded));
0849: } catch (IOException e) {
0850: fail("IOException serializing " + objToSave + " : "
0851: + e.getMessage());
0852: } catch (ClassNotFoundException e) {
0853: fail("ClassNotFoundException reading Object type : "
0854: + e.getMessage());
0855: } catch (Error err) {
0856: System.out.println("Error when obj = " + objToSave);
0857: // err.printStackTrace();
0858: throw err;
0859: }
0860:
0861: }
0862:
0863: public void test_writeObject_DateFormat() {
0864: // Test for method void
0865: // java.io.ObjectOutputStream.writeObject(java.text.DateFormat)
0866:
0867: Object objToSave = null;
0868: Object objLoaded = null;
0869:
0870: try {
0871: objToSave = null;
0872: objToSave = new java.text.DateFormat() {
0873: // Thu Feb 01 01:01:01 EST 2001
0874: java.util.Date save = new java.util.Date(981007261000L);
0875:
0876: public StringBuffer format(Date p1, StringBuffer p2,
0877: java.text.FieldPosition p3) {
0878: if (p1 != null)
0879: save = p1;
0880: return new StringBuffer(Long.toString(save
0881: .getTime()));
0882: }
0883:
0884: public Date parse(String p1, java.text.ParsePosition p2) {
0885: return save;
0886: }
0887:
0888: public String toString() {
0889: return save.toString();
0890: }
0891:
0892: public boolean equals(Object obj) {
0893: if (!(obj instanceof java.text.DateFormat))
0894: return false;
0895: return save.equals(((java.text.DateFormat) obj)
0896: .parse(null, null));
0897: }
0898: };
0899: if (DEBUG)
0900: System.out.println("Obj = " + objToSave);
0901: objLoaded = dumpAndReload(objToSave);
0902:
0903: // Has to have worked
0904: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
0905: .equals(objLoaded));
0906: } catch (IOException e) {
0907: fail("Exception serializing " + objToSave + " : "
0908: + e.getMessage());
0909: } catch (ClassNotFoundException e) {
0910: fail("ClassNotFoundException reading Object type: "
0911: + e.getMessage());
0912: } catch (Error err) {
0913: System.out.println("Error when obj = " + objToSave);
0914: // err.printStackTrace();
0915: throw err;
0916: }
0917:
0918: }
0919:
0920: public void test_writeObject_Collections_CopiesList() {
0921: // Test for method void
0922: // java.io.ObjectOutputStream.writeObject(java.util.Collections.CopiesList)
0923:
0924: Object objToSave = null;
0925: Object objLoaded = null;
0926:
0927: try {
0928: objToSave = java.util.Collections
0929: .nCopies(2, new Integer(2));
0930: if (DEBUG)
0931: System.out.println("Obj = " + objToSave);
0932: objLoaded = dumpAndReload(objToSave);
0933:
0934: // Has to have worked
0935: boolean equals;
0936: equals = ((List) objToSave).get(0).equals(
0937: ((List) objLoaded).get(0));
0938: if (equals)
0939: equals = ((List) objToSave).get(1).equals(
0940: ((List) objLoaded).get(1));
0941: assertTrue(MSG_TEST_FAILED + objToSave, equals);
0942: } catch (IOException e) {
0943: fail("IOException serializing " + objToSave + " : "
0944: + e.getMessage());
0945: } catch (ClassNotFoundException e) {
0946: fail("ClassNotFoundException reading Object type : "
0947: + e.getMessage());
0948: } catch (Error err) {
0949: System.out.println("Error when obj = " + objToSave);
0950: // err.printStackTrace();
0951: throw err;
0952: }
0953:
0954: }
0955:
0956: public void test_writeObject_SerializablePermission() {
0957: // Test for method void
0958: // java.io.ObjectOutputStream.writeObject(java.io.SerializablePermission)
0959:
0960: Object objToSave = null;
0961: Object objLoaded = null;
0962:
0963: try {
0964: objToSave = new java.io.SerializablePermission(
0965: "TestSerialization", "Test");
0966: if (DEBUG)
0967: System.out.println("Obj = " + objToSave);
0968: objLoaded = dumpAndReload(objToSave);
0969:
0970: // Has to have worked
0971: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
0972: .equals(objLoaded));
0973: } catch (IOException e) {
0974: fail("Exception 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:
0987: public void test_writeObject_Properties() {
0988: // Test for method void
0989: // java.io.ObjectOutputStream.writeObject(java.util.Properties)
0990:
0991: Object objToSave = null;
0992: Object objLoaded = null;
0993:
0994: try {
0995: objToSave = new java.util.Properties();
0996: ((java.util.Properties) objToSave).put("key1", "value1");
0997: ((java.util.Properties) objToSave).put("key2", "value2");
0998: if (DEBUG)
0999: System.out.println("Obj = " + objToSave);
1000: objLoaded = dumpAndReload(objToSave);
1001:
1002: // Has to have worked
1003: boolean equals;
1004: Enumeration enum1 = ((java.util.Properties) objToSave)
1005: .elements(), enum2 = ((java.util.Properties) objLoaded)
1006: .elements();
1007:
1008: equals = true;
1009: while (enum1.hasMoreElements() && equals) {
1010: if (enum2.hasMoreElements())
1011: equals = enum1.nextElement().equals(
1012: enum2.nextElement());
1013: else
1014: equals = false;
1015: }
1016:
1017: if (equals)
1018: equals = !enum2.hasMoreElements();
1019: assertTrue(MSG_TEST_FAILED + objToSave, equals);
1020: } catch (IOException e) {
1021: fail("IOException serializing " + objToSave + " : "
1022: + e.getMessage());
1023: } catch (ClassNotFoundException e) {
1024: fail("ClassNotFoundException reading Object type : "
1025: + e.getMessage());
1026: } catch (Error err) {
1027: System.out.println("Error when obj = " + objToSave);
1028: // err.printStackTrace();
1029: throw err;
1030: }
1031:
1032: }
1033:
1034: // TODO : requires working security implementation
1035: // public void test_writeObject_BasicPermission() {
1036: // // Test for method void
1037: // //
1038: // java.io.ObjectOutputStream.writeObject(tests.java.security.Test_BasicPermission.BasicPermissionSubclass)
1039: //
1040: // Object objToSave = null;
1041: // Object objLoaded = null;
1042: //
1043: // try {
1044: // objToSave = new
1045: // tests.java.security.Test_BasicPermission.BasicPermissionSubclass(
1046: // "TestSerialization");
1047: // if (DEBUG)
1048: // System.out.println("Obj = " + objToSave);
1049: // objLoaded = dumpAndReload(objToSave);
1050: //
1051: // // Has to have worked
1052: // assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
1053: // } catch (IOException e) {
1054: // fail("Exception serializing " + objToSave + " : "
1055: // + e.getMessage());
1056: // } catch (ClassNotFoundException e) {
1057: // fail("ClassNotFoundException reading Object type : " + e.getMessage());
1058: // } catch (Error err) {
1059: // System.out.println("Error when obj = " + objToSave);
1060: // // err.printStackTrace();
1061: // throw err;
1062: // }
1063: //
1064: // }
1065:
1066: public void test_writeObject_Collections_UnmodifiableMap_UnmodifiableEntrySet() {
1067: // Test for method void
1068: // java.io.ObjectOutputStream.writeObject(java.util.Collections.UnmodifiableMap.UnmodifiableEntrySet)
1069:
1070: Object objToSave = null;
1071: Object objLoaded = null;
1072:
1073: try {
1074: objToSave = java.util.Collections.unmodifiableMap(MAP)
1075: .entrySet();
1076: if (DEBUG)
1077: System.out.println("Obj = " + objToSave);
1078: objLoaded = dumpAndReload(objToSave);
1079:
1080: // Has to have worked
1081: boolean equals;
1082: equals = ((java.util.Collection) objToSave).size() == ((java.util.Collection) objLoaded)
1083: .size();
1084: if (equals) {
1085: java.util.Iterator iter1 = ((java.util.Collection) objToSave)
1086: .iterator(), iter2 = ((java.util.Collection) objLoaded)
1087: .iterator();
1088: while (iter1.hasNext())
1089: equals = equals
1090: && iter1.next().equals(iter2.next());
1091: }
1092: assertTrue(MSG_TEST_FAILED + objToSave, equals);
1093: } catch (IOException e) {
1094: fail("IOException serializing " + objToSave + " : "
1095: + e.getMessage());
1096: } catch (ClassNotFoundException e) {
1097: fail("ClassNotFoundException reading Object type : "
1098: + e.getMessage());
1099: } catch (Error err) {
1100: System.out.println("Error when obj = " + objToSave);
1101: // err.printStackTrace();
1102: throw err;
1103: }
1104:
1105: }
1106:
1107: public void test_writeObject_NumberFormat() {
1108: // Test for method void
1109: // java.io.ObjectOutputStream.writeObject(java.text.NumberFormat)
1110:
1111: Object objToSave = null;
1112: Object objLoaded = null;
1113:
1114: try {
1115: objToSave = null;
1116: objToSave = new java.text.NumberFormat() {
1117: long save = 107;
1118:
1119: public StringBuffer format(double p1, StringBuffer p2,
1120: java.text.FieldPosition p3) {
1121: return new StringBuffer();
1122: }
1123:
1124: public StringBuffer format(long p1, StringBuffer p2,
1125: java.text.FieldPosition p3) {
1126: if (p1 != 0)
1127: save = p1;
1128: return new StringBuffer(Long.toString(save));
1129: }
1130:
1131: public Number parse(String p1,
1132: java.text.ParsePosition p2) {
1133: return new Long(save);
1134: }
1135:
1136: public boolean equals(Object obj) {
1137: if (!(obj instanceof java.text.NumberFormat))
1138: return false;
1139: return save == ((Long) ((java.text.NumberFormat) obj)
1140: .parse(null, null)).longValue();
1141: }
1142: };
1143:
1144: ((java.text.NumberFormat) objToSave)
1145: .format(63L, null, null);
1146: if (DEBUG)
1147: System.out.println("Obj = " + objToSave);
1148: objLoaded = dumpAndReload(objToSave);
1149:
1150: // Has to have worked
1151: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
1152: .equals(objLoaded));
1153: } catch (IOException e) {
1154: fail("Exception serializing " + objToSave + " : "
1155: + e.getMessage());
1156: } catch (ClassNotFoundException e) {
1157: fail("ClassNotFoundException reading Object type: "
1158: + e.getMessage());
1159: } catch (Error err) {
1160: System.out.println("Error when obj = " + objToSave);
1161: // err.printStackTrace();
1162: throw err;
1163: }
1164:
1165: }
1166:
1167: public void test_writeObject_TimeZone() {
1168: // Test for method void
1169: // java.io.ObjectOutputStream.writeObject(java.util.TimeZone)
1170:
1171: Object objToSave = null;
1172: Object objLoaded = null;
1173:
1174: try {
1175: objToSave = null;
1176: objToSave = new java.util.TimeZone() {
1177: int save = 0;
1178:
1179: public int getOffset(int p1, int p2, int p3, int p4,
1180: int p5, int p6) {
1181: return 0;
1182: }
1183:
1184: public int getRawOffset() {
1185: return save;
1186: }
1187:
1188: public boolean inDaylightTime(java.util.Date p1) {
1189: return false;
1190: }
1191:
1192: public void setRawOffset(int p1) {
1193: save = p1;
1194: }
1195:
1196: public boolean useDaylightTime() {
1197: return false;
1198: }
1199:
1200: public boolean equals(Object obj) {
1201: if (obj instanceof TimeZone)
1202: return save == ((TimeZone) obj).getRawOffset();
1203: return false;
1204: }
1205: };
1206:
1207: ((java.util.TimeZone) objToSave).setRawOffset(48);
1208: if (DEBUG)
1209: System.out.println("Obj = " + objToSave);
1210: objLoaded = dumpAndReload(objToSave);
1211:
1212: // Has to have worked
1213: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
1214: .equals(objLoaded));
1215: } catch (IOException e) {
1216: fail("IOException serializing " + objToSave + " : "
1217: + e.getMessage());
1218: } catch (ClassNotFoundException e) {
1219: fail("ClassNotFoundException reading Object type : "
1220: + e.getMessage());
1221: } catch (Error err) {
1222: System.out.println("Error when obj = " + objToSave);
1223: // err.printStackTrace();
1224: throw err;
1225: }
1226:
1227: }
1228:
1229: public void test_writeObject_Double() {
1230: // Test for method void
1231: // java.io.ObjectOutputStream.writeObject(java.lang.Double)
1232:
1233: Object objToSave = null;
1234: Object objLoaded = null;
1235:
1236: try {
1237: objToSave = new java.lang.Double(1.23);
1238: if (DEBUG)
1239: System.out.println("Obj = " + objToSave);
1240: objLoaded = dumpAndReload(objToSave);
1241:
1242: // Has to have worked
1243: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
1244: .equals(objLoaded));
1245: } catch (IOException e) {
1246: fail("Exception serializing " + objToSave + " : "
1247: + e.getMessage());
1248: } catch (ClassNotFoundException e) {
1249: fail("ClassNotFoundException reading Object type: "
1250: + e.getMessage());
1251: } catch (Error err) {
1252: System.out.println("Error when obj = " + objToSave);
1253: // err.printStackTrace();
1254: throw err;
1255: }
1256:
1257: }
1258:
1259: public void test_writeObject_Number() {
1260: // Test for method void
1261: // java.io.ObjectOutputStream.writeObject(java.lang.Number)
1262:
1263: Object objToSave = null;
1264: Object objLoaded = null;
1265:
1266: try {
1267: objToSave = null;
1268: objToSave = new Number() {
1269: int numCalls = 0;
1270:
1271: public double doubleValue() {
1272: return ++numCalls;
1273: }
1274:
1275: public float floatValue() {
1276: return ++numCalls;
1277: }
1278:
1279: public int intValue() {
1280: return numCalls;
1281: }
1282:
1283: public long longValue() {
1284: return ++numCalls;
1285: }
1286:
1287: public boolean equals(Object obj) {
1288: if (!(obj instanceof java.lang.Number))
1289: return false;
1290: return intValue() == ((Number) obj).intValue();
1291: }
1292: };
1293: ((java.lang.Number) objToSave).doubleValue();
1294: ((java.lang.Number) objToSave).floatValue();
1295: if (DEBUG)
1296: System.out.println("Obj = " + objToSave);
1297: objLoaded = dumpAndReload(objToSave);
1298:
1299: // Has to have worked
1300: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
1301: .equals(objLoaded));
1302: } catch (IOException e) {
1303: fail("IOException serializing " + objToSave + " : "
1304: + e.getMessage());
1305: } catch (ClassNotFoundException e) {
1306: fail("ClassNotFoundException reading Object type : "
1307: + e.getMessage());
1308: } catch (Error err) {
1309: System.out.println("Error when obj = " + objToSave);
1310: // err.printStackTrace();
1311: throw err;
1312: }
1313:
1314: }
1315:
1316: public void test_writeObject_AllPermission() {
1317: // Test for method void
1318: // java.io.ObjectOutputStream.writeObject(java.security.AllPermission)
1319:
1320: Object objToSave = null;
1321: Object objLoaded = null;
1322:
1323: try {
1324: objToSave = new java.security.AllPermission();
1325: if (DEBUG)
1326: System.out.println("Obj = " + objToSave);
1327: objLoaded = dumpAndReload(objToSave);
1328:
1329: // Has to have worked
1330: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
1331: .equals(objLoaded));
1332: } catch (IOException e) {
1333: fail("Exception serializing " + objToSave + " : "
1334: + e.getMessage());
1335: } catch (ClassNotFoundException e) {
1336: fail("ClassNotFoundException reading Object type: "
1337: + e.getMessage());
1338: } catch (Error err) {
1339: System.out.println("Error when obj = " + objToSave);
1340: // err.printStackTrace();
1341: throw err;
1342: }
1343:
1344: }
1345:
1346: public void test_writeObject_Collections_ReverseComparator() {
1347: // Test for method void
1348: // java.io.ObjectOutputStream.writeObject(java.util.Collections.ReverseComparator)
1349:
1350: Object objToSave = null;
1351: Object objLoaded = null;
1352:
1353: try {
1354: objToSave = java.util.Collections.reverseOrder();
1355: if (DEBUG)
1356: System.out.println("Obj = " + objToSave);
1357: objLoaded = dumpAndReload(objToSave);
1358:
1359: // Has to have worked
1360: boolean equals;
1361: equals = ((Comparator) objToSave).compare("Hello", "Jello") == ((Comparator) objLoaded)
1362: .compare("Hello", "Jello");
1363: assertTrue(MSG_TEST_FAILED + objToSave, equals);
1364: } catch (IOException e) {
1365: fail("IOException serializing " + objToSave + " : "
1366: + e.getMessage());
1367: } catch (ClassNotFoundException e) {
1368: fail("ClassNotFoundException reading Object type : "
1369: + e.getMessage());
1370: } catch (Error err) {
1371: System.out.println("Error when obj = " + objToSave);
1372: // err.printStackTrace();
1373: throw err;
1374: }
1375:
1376: }
1377:
1378: public void test_writeObject_DateFormatSymbols() {
1379: // Test for method void
1380: // java.io.ObjectOutputStream.writeObject(java.text.DateFormatSymbols)
1381:
1382: Object objToSave = null;
1383: Object objLoaded = null;
1384:
1385: try {
1386: objToSave = new java.text.DateFormatSymbols(Locale.CHINESE);
1387: ((java.text.DateFormatSymbols) objToSave)
1388: .setZoneStrings(new String[][] {
1389: { "a", "b", "c", "d" },
1390: { "e", "f", "g", "h" } });
1391: if (DEBUG)
1392: System.out.println("Obj = " + objToSave);
1393: objLoaded = dumpAndReload(objToSave);
1394:
1395: // Has to have worked
1396: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
1397: .equals(objLoaded));
1398: } catch (IOException e) {
1399: fail("Exception serializing " + objToSave + " : "
1400: + e.getMessage());
1401: } catch (ClassNotFoundException e) {
1402: fail("ClassNotFoundException reading Object type: "
1403: + e.getMessage());
1404: } catch (Error err) {
1405: System.out.println("Error when obj = " + objToSave);
1406: // err.printStackTrace();
1407: throw err;
1408: }
1409:
1410: }
1411:
1412: public void test_writeObject_Collections_EmptyList() {
1413: // Test for method void
1414: // java.io.ObjectOutputStream.writeObject(java.util.Collections.EmptyList)
1415:
1416: Object objToSave = null;
1417: Object objLoaded = null;
1418:
1419: try {
1420: objToSave = java.util.Collections.EMPTY_LIST;
1421: if (DEBUG)
1422: System.out.println("Obj = " + objToSave);
1423: objLoaded = dumpAndReload(objToSave);
1424:
1425: // Has to have worked
1426: boolean equals;
1427: equals = objToSave.equals(objLoaded);
1428: if (equals)
1429: equals = ((List) objLoaded).size() == 0;
1430: assertTrue(MSG_TEST_FAILED + objToSave, equals);
1431: } catch (IOException e) {
1432: fail("Exception serializing " + objToSave + " : "
1433: + e.getMessage());
1434: } catch (ClassNotFoundException e) {
1435: fail("ClassNotFoundException reading Object type: "
1436: + e.getMessage());
1437: } catch (Error err) {
1438: System.out.println("Error when obj = " + objToSave);
1439: // err.printStackTrace();
1440: throw err;
1441: }
1442:
1443: }
1444:
1445: public void test_writeObject_Boolean() {
1446: // Test for method void
1447: // java.io.ObjectOutputStream.writeObject(java.lang.Boolean)
1448:
1449: Object objToSave = null;
1450: Object objLoaded = null;
1451:
1452: try {
1453: objToSave = new java.lang.Boolean(true);
1454: if (DEBUG)
1455: System.out.println("Obj = " + objToSave);
1456: objLoaded = dumpAndReload(objToSave);
1457:
1458: // Has to have worked
1459: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
1460: .equals(objLoaded));
1461: } catch (IOException e) {
1462: fail("Exception serializing " + objToSave + " : "
1463: + e.getMessage());
1464: } catch (ClassNotFoundException e) {
1465: fail("ClassNotFoundException reading Object type: "
1466: + e.getMessage());
1467: } catch (Error err) {
1468: System.out.println("Error when obj = " + objToSave);
1469: // err.printStackTrace();
1470: throw err;
1471: }
1472:
1473: }
1474:
1475: public void test_writeObject_Collections_SingletonSet() {
1476: // Test for method void
1477: // java.io.ObjectOutputStream.writeObject(java.util.Collections.SingletonSet)
1478:
1479: Object objToSave = null;
1480: Object objLoaded = null;
1481:
1482: try {
1483: objToSave = java.util.Collections.singleton(new Byte(
1484: (byte) 107));
1485: if (DEBUG)
1486: System.out.println("Obj = " + objToSave);
1487: objLoaded = dumpAndReload(objToSave);
1488:
1489: // Has to have worked
1490: boolean equals;
1491: java.util.Iterator iter = ((Set) objLoaded).iterator();
1492: equals = iter.hasNext();
1493: if (equals)
1494: equals = iter.next().equals(new Byte((byte) 107));
1495: if (equals)
1496: equals = !iter.hasNext();
1497: assertTrue(MSG_TEST_FAILED + objToSave, equals);
1498: } catch (IOException e) {
1499: fail("Exception serializing " + objToSave + " : "
1500: + e.getMessage());
1501: } catch (ClassNotFoundException e) {
1502: fail("ClassNotFoundException reading Object type: "
1503: + e.getMessage());
1504: } catch (Error err) {
1505: System.out.println("Error when obj = " + objToSave);
1506: // err.printStackTrace();
1507: throw err;
1508: }
1509:
1510: }
1511:
1512: public void test_writeObject_Collections_SingletonList() {
1513: // Test for method void
1514: // java.io.ObjectOutputStream.writeObject(java.util.Collections.SingletonSet)
1515:
1516: Object objToSave = null;
1517: Object objLoaded = null;
1518:
1519: try {
1520: objToSave = java.util.Collections.singletonList(new Byte(
1521: (byte) 107));
1522: if (DEBUG)
1523: System.out.println("Obj = " + objToSave);
1524: objLoaded = dumpAndReload(objToSave);
1525:
1526: // Has to have worked
1527: boolean equals;
1528: java.util.Iterator iter = ((List) objLoaded).iterator();
1529: equals = objLoaded.equals(objToSave) && iter.hasNext()
1530: && iter.next().equals(new Byte((byte) 107))
1531: && !iter.hasNext();
1532: assertTrue(MSG_TEST_FAILED + objToSave, equals);
1533: } catch (IOException e) {
1534: fail("Exception serializing " + objToSave + " : "
1535: + e.getMessage());
1536: } catch (ClassNotFoundException e) {
1537: fail("ClassNotFoundException reading Object type: "
1538: + e.getMessage());
1539: } catch (Error err) {
1540: System.out.println("Error when obj = " + objToSave);
1541: // err.printStackTrace();
1542: throw err;
1543: }
1544:
1545: }
1546:
1547: public void test_writeObject_Collections_SingletonMap() {
1548: // Test for method void
1549: // java.io.ObjectOutputStream.writeObject(java.util.Collections.SingletonSet)
1550:
1551: Object objToSave = null;
1552: Object objLoaded = null;
1553:
1554: try {
1555: objToSave = java.util.Collections.singletonMap("key",
1556: new Byte((byte) 107));
1557: if (DEBUG)
1558: System.out.println("Obj = " + objToSave);
1559: objLoaded = dumpAndReload(objToSave);
1560:
1561: // Has to have worked
1562: boolean equals;
1563: java.util.Iterator iter = ((Map) objLoaded).entrySet()
1564: .iterator();
1565: equals = objLoaded.equals(objToSave) && iter.hasNext();
1566: Map.Entry entry = (Map.Entry) iter.next();
1567: equals = equals && entry.getKey().equals("key")
1568: && entry.getValue().equals(new Byte((byte) 107))
1569: && !iter.hasNext();
1570: assertTrue(MSG_TEST_FAILED + objToSave, equals);
1571: } catch (IOException e) {
1572: fail("Exception serializing " + objToSave + " : "
1573: + e.getMessage());
1574: } catch (ClassNotFoundException e) {
1575: fail("ClassNotFoundException reading Object type: "
1576: + e.getMessage());
1577: } catch (Error err) {
1578: System.out.println("Error when obj = " + objToSave);
1579: // err.printStackTrace();
1580: throw err;
1581: }
1582:
1583: }
1584:
1585: public void test_writeObject_FilePermission_FilePermissionCollection() {
1586: // Test for method void
1587: // java.io.ObjectOutputStream.writeObject(java.io.FilePermission.FilePermissionCollection)
1588:
1589: Object objToSave = null;
1590: Object objLoaded = null;
1591:
1592: try {
1593: objToSave = (new java.io.FilePermission("<<ALL FILES>>",
1594: "read")).newPermissionCollection();
1595: ((java.security.PermissionCollection) objToSave)
1596: .add(new FilePermission("<<ALL FILES>>", "read"));
1597: ((java.security.PermissionCollection) objToSave)
1598: .add(new FilePermission("d:\\", "read"));
1599: if (DEBUG)
1600: System.out.println("Obj = " + objToSave);
1601: objLoaded = dumpAndReload(objToSave);
1602:
1603: // Has to have worked
1604: boolean equals;
1605: java.util.Enumeration enum1 = ((java.security.PermissionCollection) objToSave)
1606: .elements(), enum2 = ((java.security.PermissionCollection) objLoaded)
1607: .elements();
1608:
1609: equals = true;
1610: while (enum1.hasMoreElements() && equals) {
1611: if (enum2.hasMoreElements())
1612: equals = enum1.nextElement().equals(
1613: enum2.nextElement());
1614: else
1615: equals = false;
1616: }
1617:
1618: if (equals)
1619: equals = !enum2.hasMoreElements();
1620: assertTrue(MSG_TEST_FAILED + objToSave, equals);
1621: } catch (IOException e) {
1622: fail("Exception serializing " + objToSave + " : "
1623: + e.getMessage());
1624: } catch (ClassNotFoundException e) {
1625: fail("ClassNotFoundException reading Object type: "
1626: + e.getMessage());
1627: } catch (Error err) {
1628: System.out.println("Error when obj = " + objToSave);
1629: // err.printStackTrace();
1630: throw err;
1631: }
1632:
1633: }
1634:
1635: public void test_writeObject_SecureRandom() {
1636: // Test for method void
1637: // java.io.ObjectOutputStream.writeObject(java.security.SecureRandom)
1638:
1639: Object objToSave = null;
1640: Object objLoaded = null;
1641:
1642: try {
1643: objToSave = new java.security.SecureRandom();
1644: if (DEBUG)
1645: System.out.println("Obj = " + objToSave);
1646: objLoaded = dumpAndReload(objToSave);
1647:
1648: // Has to have worked
1649: boolean equals;
1650: equals = true; // assume fine because of the nature of the class,
1651: // it is difficult to determine if they are the same
1652: assertTrue(MSG_TEST_FAILED + objToSave, equals);
1653: } catch (IOException e) {
1654: fail("Exception serializing " + objToSave + " : "
1655: + e.getMessage());
1656: } catch (ClassNotFoundException e) {
1657: fail("ClassNotFoundException reading Object type: "
1658: + e.getMessage());
1659: } catch (Error err) {
1660: System.out.println("Error when obj = " + objToSave);
1661: // err.printStackTrace();
1662: throw err;
1663: }
1664:
1665: }
1666:
1667: public void test_writeObject_FilePermission() {
1668: // Test for method void
1669: // java.io.ObjectOutputStream.writeObject(java.io.FilePermission)
1670:
1671: Object objToSave = null;
1672: Object objLoaded = null;
1673:
1674: try {
1675: objToSave = new java.io.FilePermission("<<ALL FILES>>",
1676: "read");
1677: if (DEBUG)
1678: System.out.println("Obj = " + objToSave);
1679: objLoaded = dumpAndReload(objToSave);
1680:
1681: // Has to have worked
1682: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
1683: .equals(objLoaded));
1684: } catch (IOException e) {
1685: fail("Exception serializing " + objToSave + " : "
1686: + e.getMessage());
1687: } catch (ClassNotFoundException e) {
1688: fail("ClassNotFoundException reading Object type: "
1689: + e.getMessage());
1690: } catch (Error err) {
1691: System.out.println("Error when obj = " + objToSave);
1692: // err.printStackTrace();
1693: throw err;
1694: }
1695:
1696: }
1697:
1698: public void test_writeObject_InetAddress() {
1699: // Test for method void
1700: // java.io.ObjectOutputStream.writeObject(java.net.InetAddress)
1701:
1702: Object objToSave = null;
1703: Object objLoaded = null;
1704:
1705: try {
1706: objToSave = java.net.InetAddress
1707: .getByName(Support_Configuration.InetTestIP);
1708: if (DEBUG)
1709: System.out.println("Obj = " + objToSave);
1710: objLoaded = dumpAndReload(objToSave);
1711:
1712: // Has to have worked
1713: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
1714: .equals(objLoaded));
1715: } catch (IOException e) {
1716: fail("Exception serializing " + objToSave + " : "
1717: + e.getMessage());
1718: } catch (ClassNotFoundException e) {
1719: fail("ClassNotFoundException reading Object type: "
1720: + e.getMessage());
1721: } catch (Error err) {
1722: System.out.println("Error when obj = " + objToSave);
1723: // err.printStackTrace();
1724: throw err;
1725: }
1726:
1727: }
1728:
1729: public void test_writeObject_Inet6Address() {
1730: // Test for method void
1731: // java.io.ObjectOutputStream.writeObject(java.net.Inet6Address)
1732:
1733: Object objToSave = null;
1734: Object objLoaded = null;
1735:
1736: try {
1737: objToSave = java.net.Inet6Address
1738: .getByName(Support_Configuration.InetTestIP6);
1739: if (DEBUG)
1740: System.out.println("Obj = " + objToSave);
1741: objLoaded = dumpAndReload(objToSave);
1742:
1743: // Has to have worked
1744: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
1745: .equals(objLoaded));
1746:
1747: } catch (IOException e) {
1748: fail("Exception serializing " + objToSave + " : "
1749: + e.getMessage());
1750: } catch (ClassNotFoundException e) {
1751: fail("ClassNotFoundException reading Object type: "
1752: + e.getMessage());
1753: } catch (Error err) {
1754: System.out.println("Error when obj = " + objToSave);
1755: // err.printStackTrace();
1756: throw err;
1757: }
1758:
1759: }
1760:
1761: public void test_writeObject_RuntimePermission() {
1762: // Test for method void
1763: // java.io.ObjectOutputStream.writeObject(java.lang.RuntimePermission)
1764:
1765: Object objToSave = null;
1766: Object objLoaded = null;
1767:
1768: try {
1769: objToSave = new java.lang.RuntimePermission(
1770: "TestSerialization", "Test");
1771: if (DEBUG)
1772: System.out.println("Obj = " + objToSave);
1773: objLoaded = dumpAndReload(objToSave);
1774:
1775: // Has to have worked
1776: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
1777: .equals(objLoaded));
1778: } catch (IOException e) {
1779: fail("Exception serializing " + objToSave + " : "
1780: + e.getMessage());
1781: } catch (ClassNotFoundException e) {
1782: fail("ClassNotFoundException reading Object type: "
1783: + e.getMessage());
1784: } catch (Error err) {
1785: System.out.println("Error when obj = " + objToSave);
1786: // err.printStackTrace();
1787: throw err;
1788: }
1789:
1790: }
1791:
1792: @SuppressWarnings("unchecked")
1793: public void test_writeObject_Permissions() {
1794: // Test for method void
1795: // java.io.ObjectOutputStream.writeObject(java.security.Permissions)
1796:
1797: Object objToSave = null;
1798: Object objLoaded = null;
1799:
1800: try {
1801: objToSave = new java.security.Permissions();
1802: ((java.security.Permissions) objToSave)
1803: .add(new AllPermission());
1804: if (DEBUG)
1805: System.out.println("Obj = " + objToSave);
1806: objLoaded = dumpAndReload(objToSave);
1807:
1808: // Has to have worked
1809: boolean equals;
1810: Enumeration enum1 = ((java.security.PermissionCollection) objToSave)
1811: .elements(), enum2 = ((java.security.PermissionCollection) objLoaded)
1812: .elements();
1813: java.util.Vector vec1 = new java.util.Vector(), vec2 = new java.util.Vector();
1814:
1815: while (enum1.hasMoreElements())
1816: vec1.add(enum1.nextElement());
1817: while (enum2.hasMoreElements())
1818: vec2.add(enum2.nextElement());
1819:
1820: equals = vec1.size() == vec2.size();
1821: if (equals) {
1822: int length = vec1.size();
1823: Object[] perms1 = new Object[length], perms2 = new Object[length];
1824: for (int i = 0; i < length; ++i) {
1825: perms1[i] = vec1.elementAt(i);
1826: perms2[i] = vec2.elementAt(i);
1827: }
1828:
1829: Comparator comparator = new Comparator() {
1830: public int compare(Object o1, Object o2) {
1831: return o1.toString().compareTo(o2.toString());
1832: }
1833:
1834: public boolean equals(Object o1, Object o2) {
1835: return o1.toString().equals(o2.toString());
1836: }
1837: };
1838:
1839: Arrays.sort(perms1, comparator);
1840: Arrays.sort(perms2, comparator);
1841:
1842: for (int i = 0; i < length && equals; ++i)
1843: equals = perms1[i].equals(perms2[i]);
1844: }
1845:
1846: assertTrue(MSG_TEST_FAILED + objToSave, equals);
1847: } catch (IOException e) {
1848: fail("Exception serializing " + objToSave + " : "
1849: + e.getMessage());
1850: } catch (ClassNotFoundException e) {
1851: fail("ClassNotFoundException reading Object type: "
1852: + e.getMessage());
1853: } catch (Error err) {
1854: System.out.println("Error when obj = " + objToSave);
1855: // err.printStackTrace();
1856: throw err;
1857: }
1858:
1859: }
1860:
1861: public void test_writeObject_Date() {
1862: // Test for method void
1863: // java.io.ObjectOutputStream.writeObject(java.util.Date)
1864:
1865: Object objToSave = null;
1866: Object objLoaded = null;
1867:
1868: try {
1869: // Thu Feb 01 01:01:01 EST 2001
1870: objToSave = new java.util.Date(981007261000L);
1871: if (DEBUG)
1872: System.out.println("Obj = " + objToSave);
1873: objLoaded = dumpAndReload(objToSave);
1874:
1875: // Has to have worked
1876: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
1877: .equals(objLoaded));
1878: } catch (IOException e) {
1879: fail("Exception serializing " + objToSave + " : "
1880: + e.getMessage());
1881: } catch (ClassNotFoundException e) {
1882: fail("ClassNotFoundException reading Object type: "
1883: + e.getMessage());
1884: } catch (Error err) {
1885: System.out.println("Error when obj = " + objToSave);
1886: // err.printStackTrace();
1887: throw err;
1888: }
1889:
1890: }
1891:
1892: public void test_writeObject_Float() {
1893: // Test for method void
1894: // java.io.ObjectOutputStream.writeObject(java.lang.Float)
1895:
1896: Object objToSave = null;
1897: Object objLoaded = null;
1898:
1899: try {
1900: objToSave = new java.lang.Float(1.23f);
1901: if (DEBUG)
1902: System.out.println("Obj = " + objToSave);
1903: objLoaded = dumpAndReload(objToSave);
1904:
1905: // Has to have worked
1906: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
1907: .equals(objLoaded));
1908: } catch (IOException e) {
1909: fail("Exception serializing " + objToSave + " : "
1910: + e.getMessage());
1911: } catch (ClassNotFoundException e) {
1912: fail("ClassNotFoundException reading Object type: "
1913: + e.getMessage());
1914: } catch (Error err) {
1915: System.out.println("Error when obj = " + objToSave);
1916: // err.printStackTrace();
1917: throw err;
1918: }
1919:
1920: }
1921:
1922: public void test_writeObject_SecurityPermission() {
1923: // Test for method void
1924: // java.io.ObjectOutputStream.writeObject(java.security.SecurityPermission)
1925:
1926: Object objToSave = null;
1927: Object objLoaded = null;
1928:
1929: try {
1930: objToSave = new java.security.SecurityPermission(
1931: "TestSerialization", "Test");
1932: if (DEBUG)
1933: System.out.println("Obj = " + objToSave);
1934: objLoaded = dumpAndReload(objToSave);
1935:
1936: // Has to have worked
1937: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
1938: .equals(objLoaded));
1939: } catch (IOException e) {
1940: fail("Exception serializing " + objToSave + " : "
1941: + e.getMessage());
1942: } catch (ClassNotFoundException e) {
1943: fail("ClassNotFoundException reading Object type: "
1944: + e.getMessage());
1945: } catch (Error err) {
1946: System.out.println("Error when obj = " + objToSave);
1947: // err.printStackTrace();
1948: throw err;
1949: }
1950:
1951: }
1952:
1953: public void test_writeObject_SocketPermission_SocketPermissionCollection() {
1954: // Test for method void
1955: // java.io.ObjectOutputStream.writeObject(java.net.SocketPermission.SocketPermissionCollection)
1956:
1957: Object objToSave = null;
1958: Object objLoaded = null;
1959:
1960: try {
1961: objToSave = (new java.net.SocketPermission("www.yahoo.com",
1962: "connect")).newPermissionCollection();
1963: ((java.security.PermissionCollection) objToSave)
1964: .add(new java.net.SocketPermission("www.yahoo.com",
1965: "connect"));
1966: if (DEBUG)
1967: System.out.println("Obj = " + objToSave);
1968: objLoaded = dumpAndReload(objToSave);
1969:
1970: // Has to have worked
1971: boolean equals;
1972: Enumeration enum1 = ((java.security.PermissionCollection) objToSave)
1973: .elements(), enum2 = ((java.security.PermissionCollection) objLoaded)
1974: .elements();
1975:
1976: equals = true;
1977: while (enum1.hasMoreElements() && equals) {
1978: if (enum2.hasMoreElements())
1979: equals = enum1.nextElement().equals(
1980: enum2.nextElement());
1981: else
1982: equals = false;
1983: }
1984:
1985: if (equals)
1986: equals = !enum2.hasMoreElements();
1987: assertTrue(MSG_TEST_FAILED + objToSave, equals);
1988: } catch (IOException e) {
1989: fail("Exception serializing " + objToSave + " : "
1990: + e.getMessage());
1991: } catch (ClassNotFoundException e) {
1992: fail("ClassNotFoundException reading Object type: "
1993: + e.getMessage());
1994: } catch (Error err) {
1995: System.out.println("Error when obj = " + objToSave);
1996: // err.printStackTrace();
1997: throw err;
1998: }
1999:
2000: }
2001:
2002: public void test_writeObject_Stack() {
2003: // Test for method void
2004: // java.io.ObjectOutputStream.writeObject(java.util.Stack)
2005:
2006: Object objToSave = null;
2007: Object objLoaded = null;
2008:
2009: try {
2010: objToSave = new java.util.Stack();
2011: ((Stack) objToSave).push("String 1");
2012: ((Stack) objToSave).push("String 2");
2013: if (DEBUG)
2014: System.out.println("Obj = " + objToSave);
2015: objLoaded = dumpAndReload(objToSave);
2016:
2017: // Has to have worked
2018: boolean equals;
2019: equals = true;
2020: while (!((java.util.Stack) objToSave).empty() && equals) {
2021: if (!((java.util.Stack) objLoaded).empty())
2022: equals = ((java.util.Stack) objToSave)
2023: .pop()
2024: .equals(((java.util.Stack) objLoaded).pop());
2025: else
2026: equals = false;
2027: }
2028:
2029: if (equals)
2030: equals = ((java.util.Stack) objLoaded).empty();
2031: assertTrue(MSG_TEST_FAILED + objToSave, equals);
2032: } catch (IOException e) {
2033: fail("Exception serializing " + objToSave + " : "
2034: + e.getMessage());
2035: } catch (ClassNotFoundException e) {
2036: fail("ClassNotFoundException reading Object type: "
2037: + e.getMessage());
2038: } catch (Error err) {
2039: System.out.println("Error when obj = " + objToSave);
2040: // err.printStackTrace();
2041: throw err;
2042: }
2043:
2044: }
2045:
2046: public void test_writeObject_DecimalFormatSymbols() {
2047: // Test for method void
2048: // java.io.ObjectOutputStream.writeObject(java.text.DecimalFormatSymbols)
2049:
2050: Object objToSave = null;
2051: Object objLoaded = null;
2052:
2053: try {
2054: objToSave = new java.text.DecimalFormatSymbols(
2055: Locale.CHINESE);
2056: if (DEBUG)
2057: System.out.println("Obj = " + objToSave);
2058: objLoaded = dumpAndReload(objToSave);
2059:
2060: // Has to have worked
2061: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
2062: .equals(objLoaded));
2063: } catch (IOException e) {
2064: fail("Exception serializing " + objToSave + " : "
2065: + e.getMessage());
2066: } catch (ClassNotFoundException e) {
2067: fail("ClassNotFoundException reading Object type: "
2068: + e.getMessage());
2069: } catch (Error err) {
2070: System.out.println("Error when obj = " + objToSave);
2071: // err.printStackTrace();
2072: throw err;
2073: }
2074:
2075: }
2076:
2077: public void test_writeObject_NetPermission() {
2078: // Test for method void
2079: // java.io.ObjectOutputStream.writeObject(java.net.NetPermission)
2080:
2081: Object objToSave = null;
2082: Object objLoaded = null;
2083:
2084: try {
2085: objToSave = new java.net.NetPermission("TestSerialization",
2086: "Test");
2087: if (DEBUG)
2088: System.out.println("Obj = " + objToSave);
2089: objLoaded = dumpAndReload(objToSave);
2090:
2091: // Has to have worked
2092: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
2093: .equals(objLoaded));
2094: } catch (IOException e) {
2095: fail("Exception serializing " + objToSave + " : "
2096: + e.getMessage());
2097: } catch (ClassNotFoundException e) {
2098: fail("ClassNotFoundException reading Object type: "
2099: + e.getMessage());
2100: } catch (Error err) {
2101: System.out.println("Error when obj = " + objToSave);
2102: // err.printStackTrace();
2103: throw err;
2104: }
2105: }
2106:
2107: public void test_writeObject_AttributedCharacterIterator_Attribute() {
2108: // Test for method void
2109: // java.io.ObjectOutputStream.writeObject(java.text.AttributedCharacterIterator.Attribute)
2110:
2111: Object objToSave = null;
2112: Object objLoaded = null;
2113:
2114: try {
2115: objToSave = java.text.AttributedCharacterIterator.Attribute.LANGUAGE;
2116: if (DEBUG)
2117: System.out.println("Obj = " + objToSave);
2118: objLoaded = dumpAndReload(objToSave);
2119:
2120: // Has to have worked
2121: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
2122: .equals(objLoaded));
2123: } catch (IOException e) {
2124: fail("Exception serializing " + objToSave + " : "
2125: + e.getMessage());
2126: } catch (ClassNotFoundException e) {
2127: fail("ClassNotFoundException reading Object type: "
2128: + e.getMessage());
2129: } catch (Error err) {
2130: System.out.println("Error when obj = " + objToSave);
2131: // err.printStackTrace();
2132: throw err;
2133: }
2134: }
2135:
2136: public void test_writeObject_Long() {
2137: // Test for method void
2138: // java.io.ObjectOutputStream.writeObject(java.lang.Long)
2139:
2140: Object objToSave = null;
2141: Object objLoaded = null;
2142:
2143: try {
2144: objToSave = new java.lang.Long(107L);
2145: if (DEBUG)
2146: System.out.println("Obj = " + objToSave);
2147: objLoaded = dumpAndReload(objToSave);
2148:
2149: // Has to have worked
2150: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
2151: .equals(objLoaded));
2152: } catch (IOException e) {
2153: fail("Exception serializing " + objToSave + " : "
2154: + e.getMessage());
2155: } catch (ClassNotFoundException e) {
2156: fail("ClassNotFoundException reading Object type: "
2157: + e.getMessage());
2158: } catch (Error err) {
2159: System.out.println("Error when obj = " + objToSave);
2160: // err.printStackTrace();
2161: throw err;
2162: }
2163:
2164: }
2165:
2166: public void test_writeObject_CodeSource() {
2167: // Test for method void
2168: // java.io.ObjectOutputStream.writeObject(java.security.CodeSource)
2169:
2170: Object objToSave = null;
2171: Object objLoaded = null;
2172:
2173: try {
2174: objToSave = null;
2175: objToSave = new java.security.CodeSource(new java.net.URL(
2176: "http://localhost/a.txt"), (Certificate[]) null);
2177:
2178: if (DEBUG)
2179: System.out.println("Obj = " + objToSave);
2180: objLoaded = dumpAndReload(objToSave);
2181:
2182: // Has to have worked
2183: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
2184: .equals(objLoaded));
2185: } catch (IOException e) {
2186: fail("Exception serializing " + objToSave + " : "
2187: + e.getMessage());
2188: } catch (ClassNotFoundException e) {
2189: fail("ClassNotFoundException reading Object type: "
2190: + e.getMessage());
2191: } catch (Error err) {
2192: System.out.println("Error when obj = " + objToSave);
2193: // err.printStackTrace();
2194: throw err;
2195: }
2196:
2197: }
2198:
2199: public void test_writeObject_Collections_SynchronizedCollection() {
2200: // Test for method void
2201: // java.io.ObjectOutputStream.writeObject(java.util.Collections.SynchronizedCollection)
2202:
2203: Object objToSave = null;
2204: Object objLoaded = null;
2205:
2206: try {
2207: objToSave = java.util.Collections
2208: .synchronizedCollection(SET);
2209: if (DEBUG)
2210: System.out.println("Obj = " + objToSave);
2211: objLoaded = dumpAndReload(objToSave);
2212:
2213: // Has to have worked
2214: boolean equals;
2215: equals = ((java.util.Collection) objToSave).size() == ((java.util.Collection) objLoaded)
2216: .size();
2217: if (equals) {
2218: java.util.Iterator iter1 = ((java.util.Collection) objToSave)
2219: .iterator(), iter2 = ((java.util.Collection) objLoaded)
2220: .iterator();
2221: while (iter1.hasNext())
2222: equals = equals
2223: && iter1.next().equals(iter2.next());
2224: }
2225: assertTrue(MSG_TEST_FAILED + objToSave, equals);
2226: } catch (IOException e) {
2227: fail("Exception serializing " + objToSave + " : "
2228: + e.getMessage());
2229: } catch (ClassNotFoundException e) {
2230: fail("ClassNotFoundException reading Object type: "
2231: + e.getMessage());
2232: } catch (Error err) {
2233: System.out.println("Error when obj = " + objToSave);
2234: // err.printStackTrace();
2235: throw err;
2236: }
2237:
2238: }
2239:
2240: public void test_writeObject_Permission() {
2241: // Test for method void
2242: // java.io.ObjectOutputStream.writeObject(java.security.Permission)
2243:
2244: Object objToSave = null;
2245: Object objLoaded = null;
2246:
2247: try {
2248: objToSave = null;
2249: objToSave = new java.security.Permission("test") {
2250: public boolean equals(Object p1) {
2251: if (!(p1 instanceof java.security.Permission))
2252: return false;
2253: return getName().equals(
2254: ((java.security.Permission) p1).getName());
2255: }
2256:
2257: public int hashCode() {
2258: return 0;
2259: }
2260:
2261: public String getActions() {
2262: return null;
2263: }
2264:
2265: public boolean implies(java.security.Permission p1) {
2266: return false;
2267: }
2268: };
2269: if (DEBUG)
2270: System.out.println("Obj = " + objToSave);
2271: objLoaded = dumpAndReload(objToSave);
2272:
2273: // Has to have worked
2274: assertTrue(MSG_TEST_FAILED + objToSave, objToSave
2275: .equals(objLoaded));
2276: } catch (IOException e) {
2277: fail("Exception serializing " + objToSave + " : "
2278: + e.getMessage());
2279: } catch (ClassNotFoundException e) {
2280: fail("ClassNotFoundException reading Object type: "
2281: + e.getMessage());
2282: } catch (Error err) {
2283: System.out.println("Error when obj = " + objToSave);
2284: // err.printStackTrace();
2285: throw err;
2286: }
2287:
2288: }
2289:
2290: public void test_writeObject_Random() {
2291: // Test for method void
2292: // java.io.ObjectOutputStream.writeObject(java.util.Random)
2293:
2294: Object objToSave = null;
2295: Object objLoaded = null;
2296:
2297: try {
2298: objToSave = new java.util.Random(107L);
2299: if (DEBUG)
2300: System.out.println("Obj = " + objToSave);
2301: objLoaded = dumpAndReload(objToSave);
2302:
2303: // Has to have worked
2304: boolean equals;
2305: equals = ((java.util.Random) objToSave).nextInt() == ((java.util.Random) objLoaded)
2306: .nextInt();
2307: assertTrue(MSG_TEST_FAILED + objToSave, equals);
2308: } catch (IOException e) {
2309: fail("Exception serializing " + objToSave + " : "
2310: + e.getMessage());
2311: } catch (ClassNotFoundException e) {
2312: fail("ClassNotFoundException reading Object type: "
2313: + e.getMessage());
2314: } catch (Error err) {
2315: System.out.println("Error when obj = " + objToSave);
2316: // err.printStackTrace();
2317: throw err;
2318: }
2319:
2320: }
2321:
2322: public void test_writeObject_GuardedObject() {
2323: // Test for method void
2324: // java.io.ObjectOutputStream.writeObject(java.security.GuardedObject)
2325:
2326: Object objToSave = null;
2327: Object objLoaded = null;
2328:
2329: try {
2330: objToSave = new java.security.GuardedObject("Test Object",
2331: new GuardImplementation());
2332: if (DEBUG)
2333: System.out.println("Obj = " + objToSave);
2334: objLoaded = dumpAndReload(objToSave);
2335:
2336: // Has to have worked
2337: boolean equals;
2338: equals = ((java.security.GuardedObject) objToSave)
2339: .getObject().equals(
2340: ((java.security.GuardedObject) objLoaded)
2341: .getObject());
2342: assertTrue(MSG_TEST_FAILED + objToSave, equals);
2343: } catch (IOException e) {
2344: fail("Exception serializing " + objToSave + " : "
2345: + e.getMessage());
2346: } catch (ClassNotFoundException e) {
2347: fail("ClassNotFoundException reading Object type: "
2348: + e.getMessage());
2349: } catch (Error err) {
2350: System.out.println("Error when obj = " + objToSave);
2351: // err.printStackTrace();
2352: throw err;
2353: }
2354:
2355: }
2356:
2357: // TODO : Reintroduce when we have a working security implementation
2358: // public void test_writeObject_KeyPair() {
2359: // // Test for method void
2360: // // java.io.ObjectOutputStream.writeObject(java.security.GuardedObject)
2361: //
2362: // Object objToSave = null;
2363: // Object objLoaded = null;
2364: //
2365: // try {
2366: // objToSave = new java.security.KeyPair(null, null);
2367: // if (DEBUG)
2368: // System.out.println("Obj = " + objToSave);
2369: // objLoaded = dumpAndReload(objToSave);
2370: //
2371: // // Has to have worked
2372: // boolean equals;
2373: // equals = true;
2374: // assertTrue(MSG_TEST_FAILED + objToSave, equals);
2375: // } catch (IOException e) {
2376: // fail("IOException serializing " + objToSave + " : "
2377: // + e.getMessage());
2378: // } catch (ClassNotFoundException e) {
2379: // fail("ClassNotFoundException reading Object type : " + e.getMessage());
2380: // } catch (Error err) {
2381: // System.out.println("Error when obj = " + objToSave);
2382: // // err.printStackTrace();
2383: // throw err;
2384: // }
2385: // }
2386:
2387: static class MyInvocationHandler implements InvocationHandler,
2388: Serializable {
2389: public Object invoke(Object proxy, Method method, Object[] args)
2390: throws Throwable {
2391: if (method.getName().equals("equals"))
2392: return new Boolean(proxy == args[0]);
2393: if (method.getName().equals("array"))
2394: return new int[] { (int) ((long[]) args[0])[1], -1 };
2395: if (method.getName().equals("string")) {
2396: if ("error".equals(args[0]))
2397: throw new ArrayStoreException();
2398: if ("any".equals(args[0]))
2399: throw new IllegalAccessException();
2400: }
2401: return null;
2402: }
2403: }
2404:
2405: public void test_writeObject_Proxy() {
2406: // Test for method void
2407: // java.io.ObjectOutputStream.writeObject(java.security.GuardedObject)
2408:
2409: Object objToSave = null;
2410: Object objLoaded = null;
2411:
2412: try {
2413: objToSave = Proxy.getProxyClass(Support_Proxy_I1.class
2414: .getClassLoader(),
2415: new Class[] { Support_Proxy_I1.class });
2416: if (DEBUG)
2417: System.out.println("Obj = " + objToSave);
2418: objLoaded = dumpAndReload(objToSave);
2419:
2420: assertTrue(MSG_TEST_FAILED + "not a proxy class", Proxy
2421: .isProxyClass((Class) objLoaded));
2422: Class[] interfaces = ((Class) objLoaded).getInterfaces();
2423: assertTrue(MSG_TEST_FAILED + "wrong interfaces length",
2424: interfaces.length == 1);
2425: assertTrue(MSG_TEST_FAILED + "wrong interface",
2426: interfaces[0] == Support_Proxy_I1.class);
2427:
2428: InvocationHandler handler = new MyInvocationHandler();
2429: objToSave = Proxy.newProxyInstance(Support_Proxy_I1.class
2430: .getClassLoader(),
2431: new Class[] { Support_Proxy_I1.class }, handler);
2432: if (DEBUG)
2433: System.out.println("Obj = " + objToSave);
2434: objLoaded = dumpAndReload(objToSave);
2435:
2436: boolean equals = Proxy.getInvocationHandler(objLoaded)
2437: .getClass() == MyInvocationHandler.class;
2438: assertTrue(MSG_TEST_FAILED + objToSave, equals);
2439:
2440: } catch (IOException e) {
2441: fail("Exception serializing " + objToSave + " : "
2442: + e.getMessage());
2443: } catch (ClassNotFoundException e) {
2444: fail("ClassNotFoundException reading Object type: "
2445: + e.getMessage());
2446: } catch (Error err) {
2447: System.out.println("Error when obj = " + objToSave);
2448: // err.printStackTrace();
2449: throw err;
2450: }
2451: }
2452:
2453: public void test_writeObject_URI() {
2454: // Test for method void
2455: // java.io.ObjectOutputStream.writeObject(java.net.URI)
2456:
2457: Object objToSave = null;
2458: Object objLoaded = null;
2459:
2460: try {
2461: try {
2462: objToSave = new URI[] {
2463: // single arg constructor
2464: new URI(
2465: "http://user%60%20info@host/a%20path?qu%60%20ery#fr%5E%20ag"),
2466: // escaped octets for illegal chars
2467: new URI(
2468: "http://user%C3%9F%C2%A3info@host:80/a%E2%82%ACpath?qu%C2%A9%C2%AEery#fr%C3%A4%C3%A8g"),
2469: // escaped octets for unicode chars
2470: new URI(
2471: "ascheme://user\u00DF\u00A3info@host:0/a\u20ACpath?qu\u00A9\u00AEery#fr\u00E4\u00E8g"),
2472: // multiple arg constructors
2473: new URI("http", "user%60%20info", "host", 80,
2474: "/a%20path", "qu%60%20ery",
2475: "fr%5E%20ag"),
2476: // escaped octets for illegal
2477: new URI("http", "user%C3%9F%C2%A3info", "host",
2478: -1, "/a%E2%82%ACpath",
2479: "qu%C2%A9%C2%AEery", "fr%C3%A4%C3%A8g"),
2480: // escaped octets for unicode
2481: new URI("ascheme", "user\u00DF\u00A3info",
2482: "host", 80, "/a\u20ACpath",
2483: "qu\u00A9\u00AEery", "fr\u00E4\u00E8g"),
2484: new URI("http", "user` info", "host", 81,
2485: "/a path", "qu` ery", "fr^ ag"), // illegal chars
2486: new URI("http", "user%info", "host", 0,
2487: "/a%path", "que%ry", "f%rag"),
2488: // % as illegal char, not escaped octet urls with
2489: // undefined components
2490: new URI("mailto", "user@domain.com", null),
2491: // no host, path, query or fragment
2492: new URI("../adirectory/file.html#"),
2493: // relative path with empty fragment;
2494: new URI("news",
2495: "comp.infosystems.www.servers.unix",
2496: null),
2497: new URI(null, null, null, "fragment"),
2498: // only fragment
2499: new URI("telnet://server.org"), // only host
2500: new URI("http://reg:istry?query"),
2501: // malformed hostname, therefore registry-based,
2502: // with query
2503: new URI("file:///c:/temp/calculate.pl?")
2504: // empty authority, non empty path, empty query
2505: };
2506: } catch (URISyntaxException e) {
2507: fail("Unexpected Exception:" + e);
2508: }
2509: if (DEBUG)
2510: System.out.println("Obj = " + objToSave);
2511: objLoaded = dumpAndReload(objToSave);
2512:
2513: // Has to have worked
2514: assertTrue(MSG_TEST_FAILED + objToSave, Arrays.equals(
2515: (URI[]) objToSave, (URI[]) objLoaded));
2516: } catch (IOException e) {
2517: fail("Exception serializing " + objToSave + " : "
2518: + e.getMessage());
2519: } catch (ClassNotFoundException e) {
2520: fail("ClassNotFoundException reading Object type: "
2521: + e.getMessage());
2522: } catch (Error err) {
2523: System.out.println("Error when obj = " + objToSave);
2524: // err.printStackTrace();
2525: throw err;
2526: }
2527: }
2528:
2529: public void test_writeObject_URISyntaxException() {
2530: // Test for method void
2531: // java.io.ObjectOutputStream.writeObject(java.net.URISyntaxException)
2532:
2533: URISyntaxException objToSave = null;
2534: URISyntaxException objLoaded = null;
2535:
2536: try {
2537: objToSave = new URISyntaxException("str", "problem", 4);
2538: if (DEBUG)
2539: System.out.println("Obj = " + objToSave);
2540: objLoaded = (URISyntaxException) dumpAndReload(objToSave);
2541:
2542: boolean equals = objToSave.getMessage().equals(
2543: objLoaded.getMessage())
2544: && objToSave.getInput()
2545: .equals(objLoaded.getInput())
2546: && objToSave.getIndex() == objLoaded.getIndex()
2547: && objToSave.getReason().equals(
2548: objLoaded.getReason());
2549:
2550: // Has to have worked
2551: assertTrue(MSG_TEST_FAILED + objToSave, equals);
2552: } catch (IOException e) {
2553: fail("Exception serializing " + objToSave + " : "
2554: + e.getMessage());
2555: } catch (ClassNotFoundException e) {
2556: fail("ClassNotFoundException reading Object type: "
2557: + e.getMessage());
2558: } catch (Error err) {
2559: System.out.println("Error when obj = " + objToSave);
2560: // err.printStackTrace();
2561: throw err;
2562: }
2563:
2564: }
2565:
2566: public void test_writeObject_Currency() {
2567: // Test for method void
2568: // java.io.ObjectOutputStream.writeObject(java.util.Currency)
2569:
2570: Object objToSave = null;
2571: Object objLoaded = null;
2572:
2573: try {
2574: objToSave = java.util.Currency.getInstance("AMD");
2575: if (DEBUG)
2576: System.out.println("Obj = " + objToSave);
2577: objLoaded = dumpAndReload(objToSave);
2578:
2579: // Has to have worked
2580: // we need same instance for the same currency code
2581: assertTrue(MSG_TEST_FAILED + objToSave,
2582: objToSave == objToSave);
2583: } catch (IOException e) {
2584: fail("Exception serializing " + objToSave + " : "
2585: + e.getMessage());
2586: } catch (ClassNotFoundException e) {
2587: fail("ClassNotFoundException reading Object type: "
2588: + e.getMessage());
2589: } catch (Error err) {
2590: System.out.println("Error when obj = " + objToSave);
2591: // err.printStackTrace();
2592: throw err;
2593: }
2594: }
2595:
2596: public void test_writeObject_DateFormat_Field() {
2597: // Test for method void
2598: // java.io.ObjectOutputStream.writeObject(java.text.DateFormat.Field)
2599:
2600: DateFormat.Field[] objToSave = null;
2601: DateFormat.Field[] objLoaded = null;
2602:
2603: try {
2604: objToSave = new DateFormat.Field[] {
2605: DateFormat.Field.AM_PM,
2606: DateFormat.Field.DAY_OF_MONTH,
2607: DateFormat.Field.ERA, DateFormat.Field.HOUR0,
2608: DateFormat.Field.HOUR1,
2609: DateFormat.Field.HOUR_OF_DAY0,
2610: DateFormat.Field.HOUR_OF_DAY1,
2611: DateFormat.Field.TIME_ZONE, DateFormat.Field.YEAR,
2612: DateFormat.Field.DAY_OF_WEEK_IN_MONTH };
2613: if (DEBUG)
2614: System.out.println("Obj = " + objToSave);
2615:
2616: objLoaded = (DateFormat.Field[]) dumpAndReload(objToSave);
2617:
2618: // Has to have worked
2619: // we need same instances for the same field names
2620: for (int i = 0; i < objToSave.length; i++) {
2621: assertTrue(MSG_TEST_FAILED + objToSave[i],
2622: objToSave[i] == objLoaded[i]);
2623: }
2624: } catch (IOException e) {
2625: fail("Exception serializing " + objToSave + " : "
2626: + e.getMessage());
2627: } catch (ClassNotFoundException e) {
2628: fail("ClassNotFoundException reading Object type: "
2629: + e.getMessage());
2630: } catch (Error err) {
2631: System.out.println("Error when obj = " + objToSave);
2632: // err.printStackTrace();
2633: throw err;
2634: }
2635: }
2636:
2637: public void test_writeObject_NumberFormat_Field() {
2638: // Test for method void
2639: // java.io.ObjectOutputStream.writeObject(java.text.NumberFormat.Field)
2640:
2641: NumberFormat.Field[] objToSave = null;
2642: NumberFormat.Field[] objLoaded = null;
2643:
2644: try {
2645: objToSave = new NumberFormat.Field[] {
2646: NumberFormat.Field.CURRENCY,
2647: NumberFormat.Field.DECIMAL_SEPARATOR,
2648: NumberFormat.Field.EXPONENT,
2649: NumberFormat.Field.EXPONENT_SIGN,
2650: NumberFormat.Field.EXPONENT_SYMBOL,
2651: NumberFormat.Field.FRACTION,
2652: NumberFormat.Field.GROUPING_SEPARATOR,
2653: NumberFormat.Field.INTEGER,
2654: NumberFormat.Field.PERCENT,
2655: NumberFormat.Field.PERMILLE,
2656: NumberFormat.Field.SIGN };
2657: if (DEBUG)
2658: System.out.println("Obj = " + objToSave);
2659:
2660: objLoaded = (NumberFormat.Field[]) dumpAndReload(objToSave);
2661:
2662: // Has to have worked
2663: // we need same instances for the same field names
2664: for (int i = 0; i < objToSave.length; i++) {
2665: assertTrue(MSG_TEST_FAILED + objToSave[i],
2666: objToSave[i] == objLoaded[i]);
2667: }
2668: } catch (IOException e) {
2669: fail("Exception serializing " + objToSave + " : "
2670: + e.getMessage());
2671: } catch (ClassNotFoundException e) {
2672: fail("ClassNotFoundException reading Object type: "
2673: + e.getMessage());
2674: } catch (Error err) {
2675: System.out.println("Error when obj = " + objToSave);
2676: // err.printStackTrace();
2677: throw err;
2678: }
2679: }
2680:
2681: public void test_writeObject_MessageFormat_Field() {
2682: // Test for method void
2683: // java.io.ObjectOutputStream.writeObject(java.text.MessageFormat.Field)
2684:
2685: Object objToSave = null;
2686: Object objLoaded = null;
2687:
2688: try {
2689: objToSave = MessageFormat.Field.ARGUMENT;
2690: if (DEBUG)
2691: System.out.println("Obj = " + objToSave);
2692:
2693: objLoaded = dumpAndReload(objToSave);
2694:
2695: // Has to have worked
2696: // we need same instance for the same field name
2697: assertTrue(MSG_TEST_FAILED + objToSave,
2698: objToSave == objLoaded);
2699: } catch (IOException e) {
2700: fail("Exception serializing " + objToSave + " : "
2701: + e.getMessage());
2702: } catch (ClassNotFoundException e) {
2703: fail("ClassNotFoundException reading Object type: "
2704: + e.getMessage());
2705: } catch (Error err) {
2706: System.out.println("Error when obj = " + objToSave);
2707: // err.printStackTrace();
2708: throw err;
2709: }
2710: }
2711:
2712: public void test_writeObject_LinkedHashMap() {
2713: // Test for method void
2714: // java.io.ObjectOutputStream.writeObject(java.lang.Object)
2715:
2716: Object objToSave = null;
2717: Object objLoaded;
2718:
2719: try {
2720: objToSave = LINKEDMAP;
2721: if (DEBUG)
2722: System.out.println("Obj = " + objToSave);
2723: objLoaded = dumpAndReload(objToSave);
2724: // Has to have worked
2725: assertTrue(MSG_TEST_FAILED + objToSave, LINKEDMAP
2726: .equals(objLoaded));
2727:
2728: Map mapLoaded = (Map) objLoaded;
2729: Iterator loadedIterator = mapLoaded.keySet().iterator();
2730: Iterator iterator = LINKEDMAP.keySet().iterator();
2731: while (loadedIterator.hasNext()) {
2732: assertTrue("invalid iterator order", loadedIterator
2733: .next().equals(iterator.next()));
2734: }
2735: assertTrue("invalid iterator size", !iterator.hasNext());
2736:
2737: loadedIterator = mapLoaded.entrySet().iterator();
2738: iterator = LINKEDMAP.entrySet().iterator();
2739: while (loadedIterator.hasNext()) {
2740: assertTrue("invalid entry set iterator order",
2741: loadedIterator.next().equals(iterator.next()));
2742: }
2743: assertTrue("invalid entry set iterator size", !iterator
2744: .hasNext());
2745:
2746: } catch (IOException e) {
2747: fail("Exception serializing " + objToSave + " : "
2748: + e.getMessage());
2749: } catch (ClassNotFoundException e) {
2750: fail("ClassNotFoundException reading Object type: "
2751: + e.getMessage());
2752: } catch (Error err) {
2753: System.out.println("Error when obj = " + objToSave);
2754: // err.printStackTrace();
2755: throw err;
2756: }
2757: }
2758:
2759: public void test_writeObject_LinkedHashSet() {
2760: // Test for method void
2761: // java.io.ObjectOutputStream.writeObject(java.lang.Object)
2762:
2763: Object objToSave = null;
2764: Object objLoaded;
2765:
2766: try {
2767: objToSave = LINKEDSET;
2768: if (DEBUG)
2769: System.out.println("Obj = " + objToSave);
2770: objLoaded = dumpAndReload(objToSave);
2771: // Has to have worked
2772: assertTrue(MSG_TEST_FAILED + objToSave, LINKEDSET
2773: .equals(objLoaded));
2774:
2775: } catch (IOException e) {
2776: fail("Exception serializing " + objToSave + " : "
2777: + e.getMessage());
2778: } catch (ClassNotFoundException e) {
2779: fail("ClassNotFoundException reading Object type: "
2780: + e.getMessage());
2781: } catch (Error err) {
2782: System.out.println("Error when obj = " + objToSave);
2783: // err.printStackTrace();
2784: throw err;
2785: }
2786: }
2787:
2788: public void test_writeObject_IdentityHashMap() {
2789: // Test for method void
2790: // java.io.ObjectOutputStream.writeObject(java.lang.Object)
2791:
2792: IdentityHashMap objToSave = null;
2793: IdentityHashMap objLoaded;
2794:
2795: try {
2796: objToSave = IDENTITYMAP;
2797: if (DEBUG)
2798: System.out.println("Obj = " + objToSave);
2799: objLoaded = (IdentityHashMap) dumpAndReload(objToSave);
2800: // Has to have worked
2801:
2802: // a serialized identity hash map will not be equal to its original
2803: // because it is an "identity" mapping,
2804: // so we simply check for the usual meaning of equality
2805:
2806: assertEquals(
2807: "Loaded IdentityHashMap is not of the same size as the saved one.",
2808: objToSave.size(), objLoaded.size());
2809: HashMap duplicateSaved = new HashMap();
2810: duplicateSaved.putAll(objToSave);
2811: HashMap duplicateLoaded = new HashMap();
2812: duplicateLoaded.putAll(objLoaded);
2813: assertTrue(MSG_TEST_FAILED + duplicateSaved, duplicateSaved
2814: .equals(duplicateLoaded));
2815: } catch (IOException e) {
2816: fail("Exception serializing " + objToSave + " : "
2817: + e.getMessage());
2818: } catch (ClassNotFoundException e) {
2819: fail("ClassNotFoundException reading Object type: "
2820: + e.getMessage());
2821: } catch (Error err) {
2822: System.out.println("Error when obj = " + objToSave);
2823: // err.printStackTrace();
2824: throw err;
2825: }
2826: }
2827: }
|