1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18package org.apache.harmony.tests.java.io;
19
20import tests.support.Support_Proxy_I1;
21import java.io.File;
22import java.io.IOException;
23import java.io.Serializable;
24import java.lang.reflect.InvocationHandler;
25import java.lang.reflect.Method;
26import java.lang.reflect.Proxy;
27import java.net.URI;
28import java.net.URISyntaxException;
29import java.text.DateFormat;
30import java.text.MessageFormat;
31import java.text.NumberFormat;
32import java.util.Arrays;
33import java.util.Collection;
34import java.util.Collections;
35import java.util.Comparator;
36import java.util.Date;
37import java.util.Enumeration;
38import java.util.HashMap;
39import java.util.HashSet;
40import java.util.IdentityHashMap;
41import java.util.Iterator;
42import java.util.List;
43import java.util.Locale;
44import java.util.Map;
45import java.util.Set;
46import java.util.Stack;
47import java.util.TimeZone;
48
49@SuppressWarnings({ "serial", "unused" })
50public class SerializationStressTest4 extends SerializationStressTest {
51    // -----------------------------------------------------------------------------------
52    private static class GuardImplementation implements java.security.Guard,
53            java.io.Serializable {
54        public GuardImplementation() {
55        }
56
57        public void checkGuard(Object o) {
58        }
59    }
60
61    public SerializationStressTest4(String name) {
62        super(name);
63    }
64
65    public void test_writeObject_EventObject() {
66        // Test for method void
67        // java.io.ObjectOutputStream.writeObject(java.util.EventObject)
68
69        Object objToSave = null;
70        Object objLoaded = null;
71
72        try {
73            objToSave = new java.util.EventObject("Source");
74            if (DEBUG)
75                System.out.println("Obj = " + objToSave);
76            objLoaded = dumpAndReload(objToSave);
77
78            // Has to have worked
79            boolean equals;
80            equals = true;
81            // The the only data in EventObject that
82            // differentiates between instantiations is transient
83            assertTrue(MSG_TEST_FAILED + objToSave, equals);
84        } catch (IOException e) {
85            fail("IOException serializing " + objToSave + " : "
86                    + e.getMessage());
87        } catch (ClassNotFoundException e) {
88            fail("ClassNotFoundException reading Object type : "
89                    + e.getMessage());
90        } catch (Error err) {
91            System.out.println("Error when obj = " + objToSave);
92            // err.printStackTrace();
93            throw err;
94        }
95    }
96
97    public void test_writeObject_Collections_EmptySet() {
98        // Test for method void
99        // java.io.ObjectOutputStream.writeObject(java.util.Collections.EmptySet)
100
101        Object objToSave = null;
102        Object objLoaded = null;
103
104        try {
105            objToSave = java.util.Collections.EMPTY_SET;
106            if (DEBUG)
107                System.out.println("Obj = " + objToSave);
108            objLoaded = dumpAndReload(objToSave);
109
110            // Has to have worked
111            boolean equals;
112            equals = objToSave.equals(objLoaded);
113            if (equals)
114                equals = ((Set) objLoaded).size() == 0;
115            assertTrue(MSG_TEST_FAILED + objToSave, equals);
116        } catch (IOException e) {
117            fail("IOException serializing " + objToSave + " : "
118                    + e.getMessage());
119        } catch (ClassNotFoundException e) {
120            fail("ClassNotFoundException reading Object type : "
121                    + e.getMessage());
122        } catch (Error err) {
123            System.out.println("Error when obj = " + objToSave);
124            // err.printStackTrace();
125            throw err;
126        }
127
128    }
129
130    public void test_writeObject_Collections_EmptyMap() {
131        // Test for method void
132        // java.io.ObjectOutputStream.writeObject(java.util.Collections.EmptySet)
133
134        Object objToSave = null;
135        Object objLoaded = null;
136
137        try {
138            objToSave = java.util.Collections.EMPTY_MAP;
139            if (DEBUG)
140                System.out.println("Obj = " + objToSave);
141            objLoaded = dumpAndReload(objToSave);
142
143            // Has to have worked
144            boolean equals;
145            equals = objToSave.equals(objLoaded);
146            if (equals)
147                equals = ((Map) objLoaded).size() == 0;
148            assertTrue(MSG_TEST_FAILED + objToSave, equals);
149        } catch (IOException e) {
150            fail("IOException serializing " + objToSave + " : "
151                    + e.getMessage());
152        } catch (ClassNotFoundException e) {
153            fail("ClassNotFoundException reading Object type : "
154                    + e.getMessage());
155        } catch (Error err) {
156            System.out.println("Error when obj = " + objToSave);
157            // err.printStackTrace();
158            throw err;
159        }
160
161    }
162
163    public void test_writeObject_Character() {
164        // Test for method void
165        // java.io.ObjectOutputStream.writeObject(java.lang.Character)
166
167        Object objToSave = null;
168        Object objLoaded = null;
169
170        try {
171            objToSave = new java.lang.Character('c');
172            if (DEBUG)
173                System.out.println("Obj = " + objToSave);
174            objLoaded = dumpAndReload(objToSave);
175
176            // Has to have worked
177            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
178        } catch (IOException e) {
179            fail("IOException serializing " + objToSave + " : "
180                    + e.getMessage());
181        } catch (ClassNotFoundException e) {
182            fail("ClassNotFoundException reading Object type : "
183                    + e.getMessage());
184        } catch (Error err) {
185            System.out.println("Error when obj = " + objToSave);
186            // err.printStackTrace();
187            throw err;
188        }
189
190    }
191
192    public void test_writeObject_Collections_UnmodifiableCollection() throws Exception {
193        // Test for method void
194        // java.io.ObjectOutputStream.writeObject(java.util.Collections.UnmodifiableCollection)
195
196        Collection<String> objToSave = java.util.Collections.unmodifiableCollection(SET);
197        Collection<String> objLoaded = (Collection<String>) dumpAndReload(objToSave);
198
199        HashSet<String> objToSaveElements = new HashSet<>(objToSave);
200        HashSet<String> objLoadedElements = new HashSet<>(objLoaded);
201
202        assertEquals(objToSaveElements, objLoadedElements);
203    }
204
205    public void test_writeObject_Format() {
206        // Test for method void
207        // java.io.ObjectOutputStream.writeObject(java.text.Format)
208
209        Object objToSave = null;
210        Object objLoaded = null;
211
212        try {
213            objToSave = null;
214            objToSave = new java.text.Format() {
215                String save = "default";
216
217                public StringBuffer format(Object p1, StringBuffer p2,
218                        java.text.FieldPosition p3) {
219                    return new StringBuffer();
220                }
221
222                public Object parseObject(String p1, java.text.ParsePosition p2) {
223                    if (p1 != null)
224                        save = p1;
225                    return save;
226                }
227
228                public boolean equals(Object obj) {
229                    if (!(obj instanceof java.text.Format))
230                        return false;
231                    return save.equals(((java.text.Format) obj).parseObject(
232                            null, null));
233                }
234            };
235
236            ((java.text.Format) objToSave).parseObject("Test", null);
237            if (DEBUG)
238                System.out.println("Obj = " + objToSave);
239            objLoaded = dumpAndReload(objToSave);
240
241            // Has to have worked
242            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
243        } catch (IOException e) {
244            fail("IOException serializing " + objToSave + " : "
245                    + e.getMessage());
246        } catch (ClassNotFoundException e) {
247            fail("ClassNotFoundException reading Object type : "
248                    + e.getMessage());
249        } catch (Error err) {
250            System.out.println("Error when obj = " + objToSave);
251            // err.printStackTrace();
252            throw err;
253        }
254    }
255
256    public void test_writeObject_BigDecimal() {
257        // Test for method void
258        // java.io.ObjectOutputStream.writeObject(java.math.BigDecimal)
259
260        Object objToSave = null;
261        Object objLoaded = null;
262
263        try {
264            objToSave = new java.math.BigDecimal("1.2345");
265            if (DEBUG)
266                System.out.println("Obj = " + objToSave);
267            objLoaded = dumpAndReload(objToSave);
268
269            // Has to have worked
270            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
271        } catch (IOException e) {
272            fail("Exception serializing " + objToSave + " : " + e.getMessage());
273        } catch (ClassNotFoundException e) {
274            fail("ClassNotFoundException reading Object type: "
275                    + e.getMessage());
276        } catch (Error err) {
277            System.out.println("Error when obj = " + objToSave);
278            // err.printStackTrace();
279            throw err;
280        }
281
282    }
283
284    public void test_writeObject_SecureRandomSpi() {
285        // Test for method void
286        // java.io.ObjectOutputStream.writeObject(java.security.SecureRandomSpi)
287
288        Object objToSave = null;
289        Object objLoaded = null;
290
291        try {
292            objToSave = null;
293            objToSave = new java.security.SecureRandomSpi() {
294                protected byte[] engineGenerateSeed(int p1) {
295                    return new byte[0];
296                }
297
298                protected void engineNextBytes(byte[] p1) {
299                }
300
301                protected void engineSetSeed(byte[] p1) {
302                }
303
304                public boolean equals(Object obj) {
305                    return true;
306                }
307            };
308            if (DEBUG)
309                System.out.println("Obj = " + objToSave);
310            objLoaded = dumpAndReload(objToSave);
311
312            // Has to have worked
313            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
314        } catch (IOException e) {
315            fail("Exception serializing " + objToSave + " : " + e.getMessage());
316        } catch (ClassNotFoundException e) {
317            fail("ClassNotFoundException reading Object type: "
318                    + e.getMessage());
319        } catch (Error err) {
320            System.out.println("Error when obj = " + objToSave);
321            // err.printStackTrace();
322            throw err;
323        }
324    }
325
326    public void test_writeObject_Short() {
327        // Test for method void
328        // java.io.ObjectOutputStream.writeObject(java.lang.Short)
329
330        Object objToSave = null;
331        Object objLoaded = null;
332
333        try {
334            objToSave = new java.lang.Short((short) 107);
335            if (DEBUG)
336                System.out.println("Obj = " + objToSave);
337            objLoaded = dumpAndReload(objToSave);
338
339            // Has to have worked
340            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
341        } catch (IOException e) {
342            fail("IOException serializing " + objToSave + " : "
343                    + e.getMessage());
344        } catch (ClassNotFoundException e) {
345            fail("ClassNotFoundException reading Object type : "
346                    + e.getMessage());
347        } catch (Error err) {
348            System.out.println("Error when obj = " + objToSave);
349            // err.printStackTrace();
350            throw err;
351        }
352
353    }
354
355    public void test_writeObject_Byte() {
356        // Test for method void
357        // java.io.ObjectOutputStream.writeObject(java.lang.Byte)
358
359        Object objToSave = null;
360        Object objLoaded = null;
361
362        try {
363            objToSave = new java.lang.Byte((byte) 107);
364            if (DEBUG)
365                System.out.println("Obj = " + objToSave);
366            objLoaded = dumpAndReload(objToSave);
367
368            // Has to have worked
369            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
370        } catch (IOException e) {
371            fail("Exception serializing " + objToSave + " : " + e.getMessage());
372        } catch (ClassNotFoundException e) {
373            fail("ClassNotFoundException reading Object type: "
374                    + e.getMessage());
375        } catch (Error err) {
376            System.out.println("Error when obj = " + objToSave);
377            // err.printStackTrace();
378            throw err;
379        }
380
381    }
382
383    @SuppressWarnings("unchecked")
384    public void test_writeObject_String_CaseInsensitiveComparator() {
385        // Test for method void
386        // java.io.ObjectOutputStream.writeObject(java.lang.String.CaseInsensitiveComparator)
387
388        Object objToSave = null;
389        Object objLoaded = null;
390
391        try {
392            objToSave = java.lang.String.CASE_INSENSITIVE_ORDER;
393            if (DEBUG)
394                System.out.println("Obj = " + objToSave);
395            objLoaded = dumpAndReload(objToSave);
396
397            // Has to have worked
398            boolean equals;
399            equals = ((Comparator) objToSave).compare("apple", "Banana") == ((Comparator) objLoaded)
400                    .compare("apple", "Banana");
401            assertTrue(MSG_TEST_FAILED + objToSave, equals);
402        } catch (IOException e) {
403            fail("IOException serializing " + objToSave + " : "
404                    + e.getMessage());
405        } catch (ClassNotFoundException e) {
406            fail("ClassNotFoundException reading Object type : "
407                    + e.getMessage());
408        } catch (Error err) {
409            System.out.println("Error when obj = " + objToSave);
410            // err.printStackTrace();
411            throw err;
412        }
413
414    }
415
416    public void test_writeObject_Calendar() {
417        // Test for method void
418        // java.io.ObjectOutputStream.writeObject(java.util.Calendar)
419
420        Object objToSave = null;
421        Object objLoaded = null;
422
423        try {
424            objToSave = new java.util.Calendar(TimeZone.getTimeZone("EST"),
425                    Locale.CANADA) {
426                public void add(int p1, int p2) {
427                }
428
429                protected void computeFields() {
430                }
431
432                protected void computeTime() {
433                }
434
435                public int getGreatestMinimum(int p1) {
436                    return 0;
437                }
438
439                public int getLeastMaximum(int p1) {
440                    return 0;
441                }
442
443                public int getMaximum(int p1) {
444                    return 0;
445                }
446
447                public int getMinimum(int p1) {
448                    return 0;
449                }
450
451                public void roll(int p1, boolean p2) {
452                }
453            };
454            if (DEBUG)
455                System.out.println("Obj = " + objToSave);
456            objLoaded = dumpAndReload(objToSave);
457
458            // Has to have worked
459            assertTrue(MSG_TEST_FAILED + "Calendar", objToSave
460                    .equals(objLoaded));
461        } catch (IOException e) {
462            fail("Exception serializing " + objToSave + " : " + e.getMessage());
463        } catch (ClassNotFoundException e) {
464            fail("ClassNotFoundException reading Object type: "
465                    + e.getMessage());
466        } catch (Error err) {
467            System.out.println("Error when obj = " + objToSave);
468            // err.printStackTrace();
469            throw err;
470        }
471
472    }
473
474    public void test_writeObject_StringBuffer() {
475        // Test for method void
476        // java.io.ObjectOutputStream.writeObject(java.lang.StringBuffer)
477
478        Object objToSave = null;
479        Object objLoaded = null;
480
481        try {
482            objToSave = new java.lang.StringBuffer("This is a test.");
483            if (DEBUG)
484                System.out.println("Obj = " + objToSave);
485            objLoaded = dumpAndReload(objToSave);
486
487            // Has to have worked
488            boolean equals;
489            equals = ((java.lang.StringBuffer) objToSave).toString().equals(
490                    ((java.lang.StringBuffer) objLoaded).toString());
491            assertTrue(MSG_TEST_FAILED + objToSave, equals);
492        } catch (IOException e) {
493            fail("Exception serializing " + objToSave + " : " + e.getMessage());
494        } catch (ClassNotFoundException e) {
495            fail("ClassNotFoundException reading Object type: "
496                    + e.getMessage());
497        } catch (Error err) {
498            System.out.println("Error when obj = " + objToSave);
499            // err.printStackTrace();
500            throw err;
501        }
502
503    }
504
505    public void test_writeObject_File() {
506        // Test for method void
507        // java.io.ObjectOutputStream.writeObject(java.io.File)
508
509        Object objToSave = null;
510        Object objLoaded = null;
511
512        try {
513            objToSave = new File("afile.txt");
514            if (DEBUG)
515                System.out.println("Obj = " + objToSave);
516            objLoaded = dumpAndReload(objToSave);
517
518            // Has to have worked
519            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
520        } catch (IOException e) {
521            fail("IOException serializing " + objToSave + " : "
522                    + e.getMessage());
523        } catch (ClassNotFoundException e) {
524            fail("ClassNotFoundException reading Object type : "
525                    + e.getMessage());
526        } catch (Error err) {
527            System.out.println("Error when obj = " + objToSave);
528            // err.printStackTrace();
529            throw err;
530        }
531
532    }
533
534    public void test_writeObject_BitSet() {
535        // Test for method void
536        // java.io.ObjectOutputStream.writeObject(java.util.BitSet)
537
538        Object objToSave = null;
539        Object objLoaded = null;
540
541        try {
542            objToSave = new java.util.BitSet();
543            ((java.util.BitSet) objToSave).set(3);
544            ((java.util.BitSet) objToSave).set(5);
545            ((java.util.BitSet) objToSave).set(61, 89);
546            if (DEBUG)
547                System.out.println("Obj = " + objToSave);
548            objLoaded = dumpAndReload(objToSave);
549
550            // Has to have worked
551            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
552        } catch (IOException e) {
553            fail("IOException serializing " + objToSave + " : "
554                    + e.getMessage());
555        } catch (ClassNotFoundException e) {
556            fail("ClassNotFoundException reading Object type : "
557                    + e.getMessage());
558        } catch (Error err) {
559            System.out.println("Error when obj = " + objToSave);
560            // err.printStackTrace();
561            throw err;
562        }
563
564    }
565
566    public void test_writeObject_DateFormat() {
567        // Test for method void
568        // java.io.ObjectOutputStream.writeObject(java.text.DateFormat)
569
570        Object objToSave = null;
571        Object objLoaded = null;
572
573        try {
574            objToSave = null;
575            objToSave = new java.text.DateFormat() {
576                // Thu Feb 01 01:01:01 EST 2001
577                java.util.Date save = new java.util.Date(981007261000L);
578
579                public StringBuffer format(Date p1, StringBuffer p2,
580                        java.text.FieldPosition p3) {
581                    if (p1 != null)
582                        save = p1;
583                    return new StringBuffer(Long.toString(save.getTime()));
584                }
585
586                public Date parse(String p1, java.text.ParsePosition p2) {
587                    return save;
588                }
589
590                public String toString() {
591                    return save.toString();
592                }
593
594                public boolean equals(Object obj) {
595                    if (!(obj instanceof java.text.DateFormat))
596                        return false;
597                    return save.equals(((java.text.DateFormat) obj).parse(null,
598                            null));
599                }
600            };
601            if (DEBUG)
602                System.out.println("Obj = " + objToSave);
603            objLoaded = dumpAndReload(objToSave);
604
605            // Has to have worked
606            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
607        } catch (IOException e) {
608            fail("Exception serializing " + objToSave + " : " + e.getMessage());
609        } catch (ClassNotFoundException e) {
610            fail("ClassNotFoundException reading Object type: "
611                    + e.getMessage());
612        } catch (Error err) {
613            System.out.println("Error when obj = " + objToSave);
614            // err.printStackTrace();
615            throw err;
616        }
617
618    }
619
620    public void test_writeObject_Collections_CopiesList() {
621        // Test for method void
622        // java.io.ObjectOutputStream.writeObject(java.util.Collections.CopiesList)
623
624        Object objToSave = null;
625        Object objLoaded = null;
626
627        try {
628            objToSave = java.util.Collections.nCopies(2, new Integer(2));
629            if (DEBUG)
630                System.out.println("Obj = " + objToSave);
631            objLoaded = dumpAndReload(objToSave);
632
633            // Has to have worked
634            boolean equals;
635            equals = ((List) objToSave).get(0)
636                    .equals(((List) objLoaded).get(0));
637            if (equals)
638                equals = ((List) objToSave).get(1).equals(
639                        ((List) objLoaded).get(1));
640            assertTrue(MSG_TEST_FAILED + objToSave, equals);
641        } catch (IOException e) {
642            fail("IOException serializing " + objToSave + " : "
643                    + e.getMessage());
644        } catch (ClassNotFoundException e) {
645            fail("ClassNotFoundException reading Object type : "
646                    + e.getMessage());
647        } catch (Error err) {
648            System.out.println("Error when obj = " + objToSave);
649            // err.printStackTrace();
650            throw err;
651        }
652
653    }
654
655    public void test_writeObject_Properties() {
656        // Test for method void
657        // java.io.ObjectOutputStream.writeObject(java.util.Properties)
658
659        Object objToSave = null;
660        Object objLoaded = null;
661
662        try {
663            objToSave = new java.util.Properties();
664            ((java.util.Properties) objToSave).put("key1", "value1");
665            ((java.util.Properties) objToSave).put("key2", "value2");
666            if (DEBUG)
667                System.out.println("Obj = " + objToSave);
668            objLoaded = dumpAndReload(objToSave);
669
670            // Has to have worked
671            boolean equals;
672            Enumeration enum1 = ((java.util.Properties) objToSave).elements(), enum2 = ((java.util.Properties) objLoaded)
673                    .elements();
674
675            equals = true;
676            while (enum1.hasMoreElements() && equals) {
677                if (enum2.hasMoreElements())
678                    equals = enum1.nextElement().equals(enum2.nextElement());
679                else
680                    equals = false;
681            }
682
683            if (equals)
684                equals = !enum2.hasMoreElements();
685            assertTrue(MSG_TEST_FAILED + objToSave, equals);
686        } catch (IOException e) {
687            fail("IOException serializing " + objToSave + " : "
688                    + e.getMessage());
689        } catch (ClassNotFoundException e) {
690            fail("ClassNotFoundException reading Object type : "
691                    + e.getMessage());
692        } catch (Error err) {
693            System.out.println("Error when obj = " + objToSave);
694            // err.printStackTrace();
695            throw err;
696        }
697
698    }
699
700    public void test_writeObject_NumberFormat() {
701        // Test for method void
702        // java.io.ObjectOutputStream.writeObject(java.text.NumberFormat)
703
704        Object objToSave = null;
705        Object objLoaded = null;
706
707        try {
708            objToSave = null;
709            objToSave = new java.text.NumberFormat() {
710                long save = 107;
711
712                public StringBuffer format(double p1, StringBuffer p2,
713                        java.text.FieldPosition p3) {
714                    return new StringBuffer();
715                }
716
717                public StringBuffer format(long p1, StringBuffer p2,
718                        java.text.FieldPosition p3) {
719                    if (p1 != 0)
720                        save = p1;
721                    return new StringBuffer(Long.toString(save));
722                }
723
724                public Number parse(String p1, java.text.ParsePosition p2) {
725                    return new Long(save);
726                }
727
728                public boolean equals(Object obj) {
729                    if (!(obj instanceof java.text.NumberFormat))
730                        return false;
731                    return save == ((Long) ((java.text.NumberFormat) obj)
732                            .parse(null, null)).longValue();
733                }
734            };
735
736            ((java.text.NumberFormat) objToSave).format(63L, null, null);
737            if (DEBUG)
738                System.out.println("Obj = " + objToSave);
739            objLoaded = dumpAndReload(objToSave);
740
741            // Has to have worked
742            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
743        } catch (IOException e) {
744            fail("Exception serializing " + objToSave + " : " + e.getMessage());
745        } catch (ClassNotFoundException e) {
746            fail("ClassNotFoundException reading Object type: "
747                    + e.getMessage());
748        } catch (Error err) {
749            System.out.println("Error when obj = " + objToSave);
750            // err.printStackTrace();
751            throw err;
752        }
753
754    }
755
756    public void test_writeObject_TimeZone() {
757        // Test for method void
758        // java.io.ObjectOutputStream.writeObject(java.util.TimeZone)
759
760        Object objToSave = null;
761        Object objLoaded = null;
762
763        try {
764            objToSave = null;
765            objToSave = new java.util.TimeZone() {
766                int save = 0;
767
768                public int getOffset(int p1, int p2, int p3, int p4, int p5,
769                        int p6) {
770                    return 0;
771                }
772
773                public int getRawOffset() {
774                    return save;
775                }
776
777                public boolean inDaylightTime(java.util.Date p1) {
778                    return false;
779                }
780
781                public void setRawOffset(int p1) {
782                    save = p1;
783                }
784
785                public boolean useDaylightTime() {
786                    return false;
787                }
788
789                public boolean equals(Object obj) {
790                    if (obj instanceof TimeZone)
791                        return save == ((TimeZone) obj).getRawOffset();
792                    return false;
793                }
794            };
795
796            ((java.util.TimeZone) objToSave).setRawOffset(48);
797            if (DEBUG)
798                System.out.println("Obj = " + objToSave);
799            objLoaded = dumpAndReload(objToSave);
800
801            // Has to have worked
802            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
803        } catch (IOException e) {
804            fail("IOException serializing " + objToSave + " : "
805                    + e.getMessage());
806        } catch (ClassNotFoundException e) {
807            fail("ClassNotFoundException reading Object type : "
808                    + e.getMessage());
809        } catch (Error err) {
810            System.out.println("Error when obj = " + objToSave);
811            // err.printStackTrace();
812            throw err;
813        }
814
815    }
816
817    public void test_writeObject_Double() {
818        // Test for method void
819        // java.io.ObjectOutputStream.writeObject(java.lang.Double)
820
821        Object objToSave = null;
822        Object objLoaded = null;
823
824        try {
825            objToSave = new java.lang.Double(1.23);
826            if (DEBUG)
827                System.out.println("Obj = " + objToSave);
828            objLoaded = dumpAndReload(objToSave);
829
830            // Has to have worked
831            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
832        } catch (IOException e) {
833            fail("Exception serializing " + objToSave + " : " + e.getMessage());
834        } catch (ClassNotFoundException e) {
835            fail("ClassNotFoundException reading Object type: "
836                    + e.getMessage());
837        } catch (Error err) {
838            System.out.println("Error when obj = " + objToSave);
839            // err.printStackTrace();
840            throw err;
841        }
842
843    }
844
845    public void test_writeObject_Number() {
846        // Test for method void
847        // java.io.ObjectOutputStream.writeObject(java.lang.Number)
848
849        Object objToSave = null;
850        Object objLoaded = null;
851
852        try {
853            objToSave = null;
854            objToSave = new Number() {
855                int numCalls = 0;
856
857                public double doubleValue() {
858                    return ++numCalls;
859                }
860
861                public float floatValue() {
862                    return ++numCalls;
863                }
864
865                public int intValue() {
866                    return numCalls;
867                }
868
869                public long longValue() {
870                    return ++numCalls;
871                }
872
873                public boolean equals(Object obj) {
874                    if (!(obj instanceof java.lang.Number))
875                        return false;
876                    return intValue() == ((Number) obj).intValue();
877                }
878            };
879            ((java.lang.Number) objToSave).doubleValue();
880            ((java.lang.Number) objToSave).floatValue();
881            if (DEBUG)
882                System.out.println("Obj = " + objToSave);
883            objLoaded = dumpAndReload(objToSave);
884
885            // Has to have worked
886            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
887        } catch (IOException e) {
888            fail("IOException serializing " + objToSave + " : "
889                    + e.getMessage());
890        } catch (ClassNotFoundException e) {
891            fail("ClassNotFoundException reading Object type : "
892                    + e.getMessage());
893        } catch (Error err) {
894            System.out.println("Error when obj = " + objToSave);
895            // err.printStackTrace();
896            throw err;
897        }
898
899    }
900
901    public void test_writeObject_Collections_ReverseComparator() {
902        // Test for method void
903        // java.io.ObjectOutputStream.writeObject(java.util.Collections.ReverseComparator)
904
905        Object objToSave = null;
906        Object objLoaded = null;
907
908        try {
909            objToSave = java.util.Collections.reverseOrder();
910            if (DEBUG)
911                System.out.println("Obj = " + objToSave);
912            objLoaded = dumpAndReload(objToSave);
913
914            // Has to have worked
915            boolean equals;
916            equals = ((Comparator) objToSave).compare("Hello", "Jello") == ((Comparator) objLoaded)
917                    .compare("Hello", "Jello");
918            assertTrue(MSG_TEST_FAILED + objToSave, equals);
919        } catch (IOException e) {
920            fail("IOException serializing " + objToSave + " : "
921                    + e.getMessage());
922        } catch (ClassNotFoundException e) {
923            fail("ClassNotFoundException reading Object type : "
924                    + e.getMessage());
925        } catch (Error err) {
926            System.out.println("Error when obj = " + objToSave);
927            // err.printStackTrace();
928            throw err;
929        }
930
931    }
932
933    public void test_writeObject_DateFormatSymbols() {
934        // Test for method void
935        // java.io.ObjectOutputStream.writeObject(java.text.DateFormatSymbols)
936
937        Object objToSave = null;
938        Object objLoaded = null;
939
940        try {
941            objToSave = new java.text.DateFormatSymbols(Locale.CHINESE);
942            ((java.text.DateFormatSymbols) objToSave)
943                    .setZoneStrings(new String[][] { { "a", "b", "c", "d", "e" },
944                            { "e", "f", "g", "h", "i" } });
945            if (DEBUG)
946                System.out.println("Obj = " + objToSave);
947            objLoaded = dumpAndReload(objToSave);
948
949            // Has to have worked
950            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
951        } catch (IOException e) {
952            fail("Exception serializing " + objToSave + " : " + e.getMessage());
953        } catch (ClassNotFoundException e) {
954            fail("ClassNotFoundException reading Object type: "
955                    + e.getMessage());
956        } catch (Error err) {
957            System.out.println("Error when obj = " + objToSave);
958            // err.printStackTrace();
959            throw err;
960        }
961
962    }
963
964    public void test_writeObject_Collections_EmptyList() {
965        // Test for method void
966        // java.io.ObjectOutputStream.writeObject(java.util.Collections.EmptyList)
967
968        Object objToSave = null;
969        Object objLoaded = null;
970
971        try {
972            objToSave = java.util.Collections.EMPTY_LIST;
973            if (DEBUG)
974                System.out.println("Obj = " + objToSave);
975            objLoaded = dumpAndReload(objToSave);
976
977            // Has to have worked
978            boolean equals;
979            equals = objToSave.equals(objLoaded);
980            if (equals)
981                equals = ((List) objLoaded).size() == 0;
982            assertTrue(MSG_TEST_FAILED + objToSave, equals);
983        } catch (IOException e) {
984            fail("Exception serializing " + objToSave + " : " + e.getMessage());
985        } catch (ClassNotFoundException e) {
986            fail("ClassNotFoundException reading Object type: "
987                    + e.getMessage());
988        } catch (Error err) {
989            System.out.println("Error when obj = " + objToSave);
990            // err.printStackTrace();
991            throw err;
992        }
993
994    }
995
996    public void test_writeObject_Boolean() {
997        // Test for method void
998        // java.io.ObjectOutputStream.writeObject(java.lang.Boolean)
999
1000        Object objToSave = null;
1001        Object objLoaded = null;
1002
1003        try {
1004            objToSave = new java.lang.Boolean(true);
1005            if (DEBUG)
1006                System.out.println("Obj = " + objToSave);
1007            objLoaded = dumpAndReload(objToSave);
1008
1009            // Has to have worked
1010            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
1011        } catch (IOException e) {
1012            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1013        } catch (ClassNotFoundException e) {
1014            fail("ClassNotFoundException reading Object type: "
1015                    + e.getMessage());
1016        } catch (Error err) {
1017            System.out.println("Error when obj = " + objToSave);
1018            // err.printStackTrace();
1019            throw err;
1020        }
1021
1022    }
1023
1024    public void test_writeObject_Collections_SingletonSet() {
1025        // Test for method void
1026        // java.io.ObjectOutputStream.writeObject(java.util.Collections.SingletonSet)
1027
1028        Object objToSave = null;
1029        Object objLoaded = null;
1030
1031        try {
1032            objToSave = java.util.Collections.singleton(new Byte((byte) 107));
1033            if (DEBUG)
1034                System.out.println("Obj = " + objToSave);
1035            objLoaded = dumpAndReload(objToSave);
1036
1037            // Has to have worked
1038            boolean equals;
1039            java.util.Iterator iter = ((Set) objLoaded).iterator();
1040            equals = iter.hasNext();
1041            if (equals)
1042                equals = iter.next().equals(new Byte((byte) 107));
1043            if (equals)
1044                equals = !iter.hasNext();
1045            assertTrue(MSG_TEST_FAILED + objToSave, equals);
1046        } catch (IOException e) {
1047            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1048        } catch (ClassNotFoundException e) {
1049            fail("ClassNotFoundException reading Object type: "
1050                    + e.getMessage());
1051        } catch (Error err) {
1052            System.out.println("Error when obj = " + objToSave);
1053            // err.printStackTrace();
1054            throw err;
1055        }
1056
1057    }
1058
1059    public void test_writeObject_Collections_SingletonList() {
1060        // Test for method void
1061        // java.io.ObjectOutputStream.writeObject(java.util.Collections.SingletonSet)
1062
1063        Object objToSave = null;
1064        Object objLoaded = null;
1065
1066        try {
1067            objToSave = java.util.Collections
1068                    .singletonList(new Byte((byte) 107));
1069            if (DEBUG)
1070                System.out.println("Obj = " + objToSave);
1071            objLoaded = dumpAndReload(objToSave);
1072
1073            // Has to have worked
1074            boolean equals;
1075            java.util.Iterator iter = ((List) objLoaded).iterator();
1076            equals = objLoaded.equals(objToSave) && iter.hasNext()
1077                    && iter.next().equals(new Byte((byte) 107))
1078                    && !iter.hasNext();
1079            assertTrue(MSG_TEST_FAILED + objToSave, equals);
1080        } catch (IOException e) {
1081            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1082        } catch (ClassNotFoundException e) {
1083            fail("ClassNotFoundException reading Object type: "
1084                    + e.getMessage());
1085        } catch (Error err) {
1086            System.out.println("Error when obj = " + objToSave);
1087            // err.printStackTrace();
1088            throw err;
1089        }
1090
1091    }
1092
1093    public void test_writeObject_Collections_SingletonMap() {
1094        // Test for method void
1095        // java.io.ObjectOutputStream.writeObject(java.util.Collections.SingletonSet)
1096
1097        Object objToSave = null;
1098        Object objLoaded = null;
1099
1100        try {
1101            objToSave = java.util.Collections.singletonMap("key", new Byte(
1102                    (byte) 107));
1103            if (DEBUG)
1104                System.out.println("Obj = " + objToSave);
1105            objLoaded = dumpAndReload(objToSave);
1106
1107            // Has to have worked
1108            boolean equals;
1109            java.util.Iterator iter = ((Map) objLoaded).entrySet().iterator();
1110            equals = objLoaded.equals(objToSave) && iter.hasNext();
1111            Map.Entry entry = (Map.Entry) iter.next();
1112            equals = equals && entry.getKey().equals("key")
1113                    && entry.getValue().equals(new Byte((byte) 107))
1114                    && !iter.hasNext();
1115            assertTrue(MSG_TEST_FAILED + objToSave, equals);
1116        } catch (IOException e) {
1117            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1118        } catch (ClassNotFoundException e) {
1119            fail("ClassNotFoundException reading Object type: "
1120                    + e.getMessage());
1121        } catch (Error err) {
1122            System.out.println("Error when obj = " + objToSave);
1123            // err.printStackTrace();
1124            throw err;
1125        }
1126
1127    }
1128
1129    public void test_writeObject_SecureRandom() {
1130        // Test for method void
1131        // java.io.ObjectOutputStream.writeObject(java.security.SecureRandom)
1132
1133        Object objToSave = null;
1134        Object objLoaded = null;
1135
1136        try {
1137            objToSave = new java.security.SecureRandom();
1138            if (DEBUG)
1139                System.out.println("Obj = " + objToSave);
1140            objLoaded = dumpAndReload(objToSave);
1141
1142            // Has to have worked
1143            boolean equals;
1144            equals = true; // assume fine because of the nature of the class,
1145            // it is difficult to determine if they are the same
1146            assertTrue(MSG_TEST_FAILED + objToSave, equals);
1147        } catch (IOException e) {
1148            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1149        } catch (ClassNotFoundException e) {
1150            fail("ClassNotFoundException reading Object type: "
1151                    + e.getMessage());
1152        } catch (Error err) {
1153            System.out.println("Error when obj = " + objToSave);
1154            // err.printStackTrace();
1155            throw err;
1156        }
1157
1158    }
1159
1160    public void test_writeObject_InetAddress() {
1161        // Test for method void
1162        // java.io.ObjectOutputStream.writeObject(java.net.InetAddress)
1163
1164        Object objToSave = null;
1165        Object objLoaded = null;
1166
1167        try {
1168            objToSave = java.net.InetAddress.getByName("127.0.0.1");
1169            if (DEBUG)
1170                System.out.println("Obj = " + objToSave);
1171            objLoaded = dumpAndReload(objToSave);
1172
1173            // Has to have worked
1174            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
1175        } catch (IOException e) {
1176            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1177        } catch (ClassNotFoundException e) {
1178            fail("ClassNotFoundException reading Object type: "
1179                    + e.getMessage());
1180        } catch (Error err) {
1181            System.out.println("Error when obj = " + objToSave);
1182            // err.printStackTrace();
1183            throw err;
1184        }
1185
1186    }
1187
1188    public void test_writeObject_Inet6Address() {
1189        // Test for method void
1190        // java.io.ObjectOutputStream.writeObject(java.net.Inet6Address)
1191
1192        Object objToSave = null;
1193        Object objLoaded = null;
1194
1195        try {
1196            objToSave = java.net.Inet6Address.getByName("fe80::20d:60ff:fe24:7410");
1197            if (DEBUG)
1198                System.out.println("Obj = " + objToSave);
1199            objLoaded = dumpAndReload(objToSave);
1200
1201            // Has to have worked
1202            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
1203
1204        } catch (IOException e) {
1205            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1206        } catch (ClassNotFoundException e) {
1207            fail("ClassNotFoundException reading Object type: "
1208                    + e.getMessage());
1209        } catch (Error err) {
1210            System.out.println("Error when obj = " + objToSave);
1211            // err.printStackTrace();
1212            throw err;
1213        }
1214
1215    }
1216
1217    public void test_writeObject_Date() {
1218        // Test for method void
1219        // java.io.ObjectOutputStream.writeObject(java.util.Date)
1220
1221        Object objToSave = null;
1222        Object objLoaded = null;
1223
1224        try {
1225            // Thu Feb 01 01:01:01 EST 2001
1226            objToSave = new java.util.Date(981007261000L);
1227            if (DEBUG)
1228                System.out.println("Obj = " + objToSave);
1229            objLoaded = dumpAndReload(objToSave);
1230
1231            // Has to have worked
1232            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
1233        } catch (IOException e) {
1234            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1235        } catch (ClassNotFoundException e) {
1236            fail("ClassNotFoundException reading Object type: "
1237                    + e.getMessage());
1238        } catch (Error err) {
1239            System.out.println("Error when obj = " + objToSave);
1240            // err.printStackTrace();
1241            throw err;
1242        }
1243
1244    }
1245
1246    public void test_writeObject_Float() {
1247        // Test for method void
1248        // java.io.ObjectOutputStream.writeObject(java.lang.Float)
1249
1250        Object objToSave = null;
1251        Object objLoaded = null;
1252
1253        try {
1254            objToSave = new java.lang.Float(1.23f);
1255            if (DEBUG)
1256                System.out.println("Obj = " + objToSave);
1257            objLoaded = dumpAndReload(objToSave);
1258
1259            // Has to have worked
1260            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
1261        } catch (IOException e) {
1262            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1263        } catch (ClassNotFoundException e) {
1264            fail("ClassNotFoundException reading Object type: "
1265                    + e.getMessage());
1266        } catch (Error err) {
1267            System.out.println("Error when obj = " + objToSave);
1268            // err.printStackTrace();
1269            throw err;
1270        }
1271
1272    }
1273
1274    public void test_writeObject_Stack() {
1275        // Test for method void
1276        // java.io.ObjectOutputStream.writeObject(java.util.Stack)
1277
1278        Object objToSave = null;
1279        Object objLoaded = null;
1280
1281        try {
1282            objToSave = new java.util.Stack();
1283            ((Stack) objToSave).push("String 1");
1284            ((Stack) objToSave).push("String 2");
1285            if (DEBUG)
1286                System.out.println("Obj = " + objToSave);
1287            objLoaded = dumpAndReload(objToSave);
1288
1289            // Has to have worked
1290            boolean equals;
1291            equals = true;
1292            while (!((java.util.Stack) objToSave).empty() && equals) {
1293                if (!((java.util.Stack) objLoaded).empty())
1294                    equals = ((java.util.Stack) objToSave).pop().equals(
1295                            ((java.util.Stack) objLoaded).pop());
1296                else
1297                    equals = false;
1298            }
1299
1300            if (equals)
1301                equals = ((java.util.Stack) objLoaded).empty();
1302            assertTrue(MSG_TEST_FAILED + objToSave, equals);
1303        } catch (IOException e) {
1304            fail("Exception serializing " + objToSave + " : " + 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_DecimalFormatSymbols() {
1317        // Test for method void
1318        // java.io.ObjectOutputStream.writeObject(java.text.DecimalFormatSymbols)
1319
1320        Object objToSave = null;
1321        Object objLoaded = null;
1322
1323        try {
1324            objToSave = new java.text.DecimalFormatSymbols(Locale.CHINESE);
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.equals(objLoaded));
1331        } catch (IOException e) {
1332            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1333        } catch (ClassNotFoundException e) {
1334            fail("ClassNotFoundException reading Object type: "
1335                    + e.getMessage());
1336        } catch (Error err) {
1337            System.out.println("Error when obj = " + objToSave);
1338            // err.printStackTrace();
1339            throw err;
1340        }
1341
1342    }
1343
1344    public void test_writeObject_AttributedCharacterIterator_Attribute() {
1345        // Test for method void
1346        // java.io.ObjectOutputStream.writeObject(java.text.AttributedCharacterIterator.Attribute)
1347
1348        Object objToSave = null;
1349        Object objLoaded = null;
1350
1351        try {
1352            objToSave = java.text.AttributedCharacterIterator.Attribute.LANGUAGE;
1353            if (DEBUG)
1354                System.out.println("Obj = " + objToSave);
1355            objLoaded = dumpAndReload(objToSave);
1356
1357            // Has to have worked
1358            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
1359        } catch (IOException e) {
1360            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1361        } catch (ClassNotFoundException e) {
1362            fail("ClassNotFoundException reading Object type: "
1363                    + e.getMessage());
1364        } catch (Error err) {
1365            System.out.println("Error when obj = " + objToSave);
1366            // err.printStackTrace();
1367            throw err;
1368        }
1369    }
1370
1371    public void test_writeObject_Long() {
1372        // Test for method void
1373        // java.io.ObjectOutputStream.writeObject(java.lang.Long)
1374
1375        Object objToSave = null;
1376        Object objLoaded = null;
1377
1378        try {
1379            objToSave = new java.lang.Long(107L);
1380            if (DEBUG)
1381                System.out.println("Obj = " + objToSave);
1382            objLoaded = dumpAndReload(objToSave);
1383
1384            // Has to have worked
1385            assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded));
1386        } catch (IOException e) {
1387            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1388        } catch (ClassNotFoundException e) {
1389            fail("ClassNotFoundException reading Object type: "
1390                    + e.getMessage());
1391        } catch (Error err) {
1392            System.out.println("Error when obj = " + objToSave);
1393            // err.printStackTrace();
1394            throw err;
1395        }
1396
1397    }
1398
1399    public void test_writeObject_Collections_SynchronizedCollection() throws Exception {
1400        // Test for method void
1401        // java.io.ObjectOutputStream.writeObject(java.util.Collections.SynchronizedCollection)
1402
1403        Collection<String> objToSave = java.util.Collections.synchronizedCollection(SET);
1404        Collection<String> objLoaded = (Collection<String>) dumpAndReload(objToSave);
1405
1406        HashSet<String> objToSaveElements = new HashSet<>(objToSave);
1407        HashSet<String> objLoadedElements = new HashSet<>(objLoaded);
1408
1409        assertEquals(objToSaveElements, objLoadedElements);
1410    }
1411
1412    public void test_writeObject_Random() {
1413        // Test for method void
1414        // java.io.ObjectOutputStream.writeObject(java.util.Random)
1415
1416        Object objToSave = null;
1417        Object objLoaded = null;
1418
1419        try {
1420            objToSave = new java.util.Random(107L);
1421            if (DEBUG)
1422                System.out.println("Obj = " + objToSave);
1423            objLoaded = dumpAndReload(objToSave);
1424
1425            // Has to have worked
1426            boolean equals;
1427            equals = ((java.util.Random) objToSave).nextInt() == ((java.util.Random) objLoaded)
1428                    .nextInt();
1429            assertTrue(MSG_TEST_FAILED + objToSave, equals);
1430        } catch (IOException e) {
1431            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1432        } catch (ClassNotFoundException e) {
1433            fail("ClassNotFoundException reading Object type: "
1434                    + e.getMessage());
1435        } catch (Error err) {
1436            System.out.println("Error when obj = " + objToSave);
1437            // err.printStackTrace();
1438            throw err;
1439        }
1440
1441    }
1442
1443    public void test_writeObject_GuardedObject() {
1444        // Test for method void
1445        // java.io.ObjectOutputStream.writeObject(java.security.GuardedObject)
1446
1447        Object objToSave = null;
1448        Object objLoaded = null;
1449
1450        try {
1451            objToSave = new java.security.GuardedObject("Test Object",
1452                    new GuardImplementation());
1453            if (DEBUG)
1454                System.out.println("Obj = " + objToSave);
1455            objLoaded = dumpAndReload(objToSave);
1456
1457            // Has to have worked
1458            boolean equals;
1459            equals = ((java.security.GuardedObject) objToSave).getObject()
1460                    .equals(
1461                            ((java.security.GuardedObject) objLoaded)
1462                                    .getObject());
1463            assertTrue(MSG_TEST_FAILED + objToSave, equals);
1464        } catch (IOException e) {
1465            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1466        } catch (ClassNotFoundException e) {
1467            fail("ClassNotFoundException reading Object type: "
1468                    + e.getMessage());
1469        } catch (Error err) {
1470            System.out.println("Error when obj = " + objToSave);
1471            // err.printStackTrace();
1472            throw err;
1473        }
1474
1475    }
1476
1477    // TODO : Reintroduce when we have a working security implementation
1478    // public void test_writeObject_KeyPair() {
1479    // // Test for method void
1480    // // java.io.ObjectOutputStream.writeObject(java.security.GuardedObject)
1481    //
1482    // Object objToSave = null;
1483    // Object objLoaded = null;
1484    //
1485    // try {
1486    // objToSave = new java.security.KeyPair(null, null);
1487    // if (DEBUG)
1488    // System.out.println("Obj = " + objToSave);
1489    // objLoaded = dumpAndReload(objToSave);
1490    //
1491    // // Has to have worked
1492    // boolean equals;
1493    // equals = true;
1494    // assertTrue(MSG_TEST_FAILED + objToSave, equals);
1495    // } catch (IOException e) {
1496    // fail("IOException serializing " + objToSave + " : "
1497    // + e.getMessage());
1498    // } catch (ClassNotFoundException e) {
1499    // fail("ClassNotFoundException reading Object type : " + e.getMessage());
1500    // } catch (Error err) {
1501    // System.out.println("Error when obj = " + objToSave);
1502    // // err.printStackTrace();
1503    // throw err;
1504    // }
1505    // }
1506
1507    static class MyInvocationHandler implements InvocationHandler, Serializable {
1508        public Object invoke(Object proxy, Method method, Object[] args)
1509                throws Throwable {
1510            if (method.getName().equals("equals"))
1511                return new Boolean(proxy == args[0]);
1512            if (method.getName().equals("array"))
1513                return new int[] { (int) ((long[]) args[0])[1], -1 };
1514            if (method.getName().equals("string")) {
1515                if ("error".equals(args[0]))
1516                    throw new ArrayStoreException();
1517                if ("any".equals(args[0]))
1518                    throw new IllegalAccessException();
1519            }
1520            return null;
1521        }
1522    }
1523
1524    public void test_writeObject_Proxy() {
1525        // Test for method void
1526        // java.io.ObjectOutputStream.writeObject(java.security.GuardedObject)
1527
1528        Object objToSave = null;
1529        Object objLoaded = null;
1530
1531        try {
1532            objToSave = Proxy.getProxyClass(Support_Proxy_I1.class
1533                    .getClassLoader(), new Class[] { Support_Proxy_I1.class });
1534            if (DEBUG)
1535                System.out.println("Obj = " + objToSave);
1536            objLoaded = dumpAndReload(objToSave);
1537
1538            assertTrue(MSG_TEST_FAILED + "not a proxy class", Proxy
1539                    .isProxyClass((Class) objLoaded));
1540            Class[] interfaces = ((Class) objLoaded).getInterfaces();
1541            assertTrue(MSG_TEST_FAILED + "wrong interfaces length",
1542                    interfaces.length == 1);
1543            assertTrue(MSG_TEST_FAILED + "wrong interface",
1544                    interfaces[0] == Support_Proxy_I1.class);
1545
1546            InvocationHandler handler = new MyInvocationHandler();
1547            objToSave = Proxy.newProxyInstance(Support_Proxy_I1.class
1548                    .getClassLoader(), new Class[] { Support_Proxy_I1.class },
1549                    handler);
1550            if (DEBUG)
1551                System.out.println("Obj = " + objToSave);
1552            objLoaded = dumpAndReload(objToSave);
1553
1554            boolean equals = Proxy.getInvocationHandler(objLoaded).getClass() == MyInvocationHandler.class;
1555            assertTrue(MSG_TEST_FAILED + objToSave, equals);
1556
1557        } catch (IOException e) {
1558            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1559        } catch (ClassNotFoundException e) {
1560            fail("ClassNotFoundException reading Object type: "
1561                    + e.getMessage());
1562        } catch (Error err) {
1563            System.out.println("Error when obj = " + objToSave);
1564            // err.printStackTrace();
1565            throw err;
1566        }
1567    }
1568
1569    public void test_writeObject_URI() {
1570        // Test for method void
1571        // java.io.ObjectOutputStream.writeObject(java.net.URI)
1572
1573        Object objToSave = null;
1574        Object objLoaded = null;
1575
1576        try {
1577            try {
1578                objToSave = new URI[] {
1579                        // single arg constructor
1580                        new URI(
1581                                "http://user%60%20info@host/a%20path?qu%60%20ery#fr%5E%20ag"),
1582                        // escaped octets for illegal chars
1583                        new URI(
1584                                "http://user%C3%9F%C2%A3info@host:80/a%E2%82%ACpath?qu%C2%A9%C2%AEery#fr%C3%A4%C3%A8g"),
1585                        // escaped octets for unicode chars
1586                        new URI(
1587                                "ascheme://user\u00DF\u00A3info@host:0/a\u20ACpath?qu\u00A9\u00AEery#fr\u00E4\u00E8g"),
1588                        // multiple arg constructors
1589                        new URI("http", "user%60%20info", "host", 80,
1590                                "/a%20path", "qu%60%20ery", "fr%5E%20ag"),
1591                        // escaped octets for illegal
1592                        new URI("http", "user%C3%9F%C2%A3info", "host", -1,
1593                                "/a%E2%82%ACpath", "qu%C2%A9%C2%AEery",
1594                                "fr%C3%A4%C3%A8g"),
1595                        // escaped octets for unicode
1596                        new URI("ascheme", "user\u00DF\u00A3info", "host", 80,
1597                                "/a\u20ACpath", "qu\u00A9\u00AEery",
1598                                "fr\u00E4\u00E8g"),
1599                        new URI("http", "user` info", "host", 81, "/a path",
1600                                "qu` ery", "fr^ ag"), // illegal chars
1601                        new URI("http", "user%info", "host", 0, "/a%path",
1602                                "que%ry", "f%rag"),
1603                        // % as illegal char, not escaped octet urls with
1604                        // undefined components
1605                        new URI("mailto", "user@domain.com", null),
1606                        // no host, path, query or fragment
1607                        new URI("../adirectory/file.html#"),
1608                        // relative path with empty fragment;
1609                        new URI("news", "comp.infosystems.www.servers.unix",
1610                                null),
1611                        new URI(null, null, null, "fragment"),
1612                        // only fragment
1613                        new URI("telnet://server.org"), // only host
1614                        new URI("http://reg:istry?query"),
1615                        // malformed hostname, therefore registry-based,
1616                        // with query
1617                        new URI("file:///c:/temp/calculate.pl?")
1618                        // empty authority, non empty path, empty query
1619                };
1620            } catch (URISyntaxException e) {
1621                fail("Unexpected Exception:" + e);
1622            }
1623            if (DEBUG)
1624                System.out.println("Obj = " + objToSave);
1625            objLoaded = dumpAndReload(objToSave);
1626
1627            // Has to have worked
1628            assertTrue(MSG_TEST_FAILED + objToSave, Arrays.equals(
1629                    (URI[]) objToSave, (URI[]) objLoaded));
1630        } catch (IOException e) {
1631            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1632        } catch (ClassNotFoundException e) {
1633            fail("ClassNotFoundException reading Object type: "
1634                    + e.getMessage());
1635        } catch (Error err) {
1636            System.out.println("Error when obj = " + objToSave);
1637            // err.printStackTrace();
1638            throw err;
1639        }
1640    }
1641
1642    public void test_writeObject_URISyntaxException() {
1643        // Test for method void
1644        // java.io.ObjectOutputStream.writeObject(java.net.URISyntaxException)
1645
1646        URISyntaxException objToSave = null;
1647        URISyntaxException objLoaded = null;
1648
1649        try {
1650            objToSave = new URISyntaxException("str", "problem", 4);
1651            if (DEBUG)
1652                System.out.println("Obj = " + objToSave);
1653            objLoaded = (URISyntaxException) dumpAndReload(objToSave);
1654
1655            boolean equals = objToSave.getMessage().equals(
1656                    objLoaded.getMessage())
1657                    && objToSave.getInput().equals(objLoaded.getInput())
1658                    && objToSave.getIndex() == objLoaded.getIndex()
1659                    && objToSave.getReason().equals(objLoaded.getReason());
1660
1661            // Has to have worked
1662            assertTrue(MSG_TEST_FAILED + objToSave, equals);
1663        } catch (IOException e) {
1664            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1665        } catch (ClassNotFoundException e) {
1666            fail("ClassNotFoundException reading Object type: "
1667                    + e.getMessage());
1668        } catch (Error err) {
1669            System.out.println("Error when obj = " + objToSave);
1670            // err.printStackTrace();
1671            throw err;
1672        }
1673
1674    }
1675
1676    public void test_writeObject_Currency() {
1677        // Test for method void
1678        // java.io.ObjectOutputStream.writeObject(java.util.Currency)
1679
1680        Object objToSave = null;
1681        Object objLoaded = null;
1682
1683        try {
1684            objToSave = java.util.Currency.getInstance("AMD");
1685            if (DEBUG)
1686                System.out.println("Obj = " + objToSave);
1687            objLoaded = dumpAndReload(objToSave);
1688
1689            // Has to have worked
1690            // we need same instance for the same currency code
1691            assertTrue(MSG_TEST_FAILED + objToSave, objToSave == objToSave);
1692        } catch (IOException e) {
1693            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1694        } catch (ClassNotFoundException e) {
1695            fail("ClassNotFoundException reading Object type: "
1696                    + e.getMessage());
1697        } catch (Error err) {
1698            System.out.println("Error when obj = " + objToSave);
1699            // err.printStackTrace();
1700            throw err;
1701        }
1702    }
1703
1704    public void test_writeObject_DateFormat_Field() {
1705        // Test for method void
1706        // java.io.ObjectOutputStream.writeObject(java.text.DateFormat.Field)
1707
1708        DateFormat.Field[] objToSave = null;
1709        DateFormat.Field[] objLoaded = null;
1710
1711        try {
1712            objToSave = new DateFormat.Field[] { DateFormat.Field.AM_PM,
1713                    DateFormat.Field.DAY_OF_MONTH, DateFormat.Field.ERA,
1714                    DateFormat.Field.HOUR0, DateFormat.Field.HOUR1,
1715                    DateFormat.Field.HOUR_OF_DAY0,
1716                    DateFormat.Field.HOUR_OF_DAY1, DateFormat.Field.TIME_ZONE,
1717                    DateFormat.Field.YEAR,
1718                    DateFormat.Field.DAY_OF_WEEK_IN_MONTH };
1719            if (DEBUG)
1720                System.out.println("Obj = " + objToSave);
1721
1722            objLoaded = (DateFormat.Field[]) dumpAndReload(objToSave);
1723
1724            // Has to have worked
1725            // we need same instances for the same field names
1726            for (int i = 0; i < objToSave.length; i++) {
1727                assertTrue(MSG_TEST_FAILED + objToSave[i],
1728                        objToSave[i] == objLoaded[i]);
1729            }
1730        } catch (IOException e) {
1731            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1732        } catch (ClassNotFoundException e) {
1733            fail("ClassNotFoundException reading Object type: "
1734                    + e.getMessage());
1735        } catch (Error err) {
1736            System.out.println("Error when obj = " + objToSave);
1737            // err.printStackTrace();
1738            throw err;
1739        }
1740    }
1741
1742    public void test_writeObject_NumberFormat_Field() {
1743        // Test for method void
1744        // java.io.ObjectOutputStream.writeObject(java.text.NumberFormat.Field)
1745
1746        NumberFormat.Field[] objToSave = null;
1747        NumberFormat.Field[] objLoaded = null;
1748
1749        try {
1750            objToSave = new NumberFormat.Field[] { NumberFormat.Field.CURRENCY,
1751                    NumberFormat.Field.DECIMAL_SEPARATOR,
1752                    NumberFormat.Field.EXPONENT,
1753                    NumberFormat.Field.EXPONENT_SIGN,
1754                    NumberFormat.Field.EXPONENT_SYMBOL,
1755                    NumberFormat.Field.FRACTION,
1756                    NumberFormat.Field.GROUPING_SEPARATOR,
1757                    NumberFormat.Field.INTEGER, NumberFormat.Field.PERCENT,
1758                    NumberFormat.Field.PERMILLE, NumberFormat.Field.SIGN };
1759            if (DEBUG)
1760                System.out.println("Obj = " + objToSave);
1761
1762            objLoaded = (NumberFormat.Field[]) dumpAndReload(objToSave);
1763
1764            // Has to have worked
1765            // we need same instances for the same field names
1766            for (int i = 0; i < objToSave.length; i++) {
1767                assertTrue(MSG_TEST_FAILED + objToSave[i],
1768                        objToSave[i] == objLoaded[i]);
1769            }
1770        } catch (IOException e) {
1771            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1772        } catch (ClassNotFoundException e) {
1773            fail("ClassNotFoundException reading Object type: "
1774                    + e.getMessage());
1775        } catch (Error err) {
1776            System.out.println("Error when obj = " + objToSave);
1777            // err.printStackTrace();
1778            throw err;
1779        }
1780    }
1781
1782    public void test_writeObject_MessageFormat_Field() {
1783        // Test for method void
1784        // java.io.ObjectOutputStream.writeObject(java.text.MessageFormat.Field)
1785
1786        Object objToSave = null;
1787        Object objLoaded = null;
1788
1789        try {
1790            objToSave = MessageFormat.Field.ARGUMENT;
1791            if (DEBUG)
1792                System.out.println("Obj = " + objToSave);
1793
1794            objLoaded = dumpAndReload(objToSave);
1795
1796            // Has to have worked
1797            // we need same instance for the same field name
1798            assertTrue(MSG_TEST_FAILED + objToSave, objToSave == objLoaded);
1799        } catch (IOException e) {
1800            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1801        } catch (ClassNotFoundException e) {
1802            fail("ClassNotFoundException reading Object type: "
1803                    + e.getMessage());
1804        } catch (Error err) {
1805            System.out.println("Error when obj = " + objToSave);
1806            // err.printStackTrace();
1807            throw err;
1808        }
1809    }
1810
1811    public void test_writeObject_LinkedHashMap() {
1812        // Test for method void
1813        // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1814
1815        Object objToSave = null;
1816        Object objLoaded;
1817
1818        try {
1819            objToSave = LINKEDMAP;
1820            if (DEBUG)
1821                System.out.println("Obj = " + objToSave);
1822            objLoaded = dumpAndReload(objToSave);
1823            // Has to have worked
1824            assertTrue(MSG_TEST_FAILED + objToSave, LINKEDMAP.equals(objLoaded));
1825
1826            Map mapLoaded = (Map) objLoaded;
1827            Iterator loadedIterator = mapLoaded.keySet().iterator();
1828            Iterator iterator = LINKEDMAP.keySet().iterator();
1829            while (loadedIterator.hasNext()) {
1830                assertTrue("invalid iterator order", loadedIterator.next()
1831                        .equals(iterator.next()));
1832            }
1833            assertTrue("invalid iterator size", !iterator.hasNext());
1834
1835            loadedIterator = mapLoaded.entrySet().iterator();
1836            iterator = LINKEDMAP.entrySet().iterator();
1837            while (loadedIterator.hasNext()) {
1838                assertTrue("invalid entry set iterator order", loadedIterator
1839                        .next().equals(iterator.next()));
1840            }
1841            assertTrue("invalid entry set iterator size", !iterator.hasNext());
1842
1843        } catch (IOException e) {
1844            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1845        } catch (ClassNotFoundException e) {
1846            fail("ClassNotFoundException reading Object type: "
1847                    + e.getMessage());
1848        } catch (Error err) {
1849            System.out.println("Error when obj = " + objToSave);
1850            // err.printStackTrace();
1851            throw err;
1852        }
1853    }
1854
1855    public void test_writeObject_LinkedHashSet() {
1856        // Test for method void
1857        // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1858
1859        Object objToSave = null;
1860        Object objLoaded;
1861
1862        try {
1863            objToSave = LINKEDSET;
1864            if (DEBUG)
1865                System.out.println("Obj = " + objToSave);
1866            objLoaded = dumpAndReload(objToSave);
1867            // Has to have worked
1868            assertTrue(MSG_TEST_FAILED + objToSave, LINKEDSET.equals(objLoaded));
1869
1870        } catch (IOException e) {
1871            fail("Exception serializing " + objToSave + " : " + e.getMessage());
1872        } catch (ClassNotFoundException e) {
1873            fail("ClassNotFoundException reading Object type: "
1874                    + e.getMessage());
1875        } catch (Error err) {
1876            System.out.println("Error when obj = " + objToSave);
1877            // err.printStackTrace();
1878            throw err;
1879        }
1880    }
1881
1882    public void test_writeObject_IdentityHashMap() {
1883        // Test for method void
1884        // java.io.ObjectOutputStream.writeObject(java.lang.Object)
1885
1886        IdentityHashMap objToSave = null;
1887        IdentityHashMap objLoaded;
1888
1889        try {
1890            objToSave = IDENTITYMAP;
1891            if (DEBUG)
1892                System.out.println("Obj = " + objToSave);
1893            objLoaded = (IdentityHashMap) dumpAndReload(objToSave);
1894            // Has to have worked
1895
1896            // a serialized identity hash map will not be equal to its original
1897            // because it is an "identity" mapping,
1898            // so we simply check for the usual meaning of equality
1899
1900            assertEquals(
1901                    "Loaded IdentityHashMap is not of the same size as the saved one.",
1902                    objToSave.size(), objLoaded.size());
1903            HashMap duplicateSaved = new HashMap();
1904            duplicateSaved.putAll(objToSave);
1905            HashMap duplicateLoaded = new HashMap();
1906            duplicateLoaded.putAll(objLoaded);
1907            assertTrue(MSG_TEST_FAILED + duplicateSaved, duplicateSaved
1908                    .equals(duplicateLoaded));
1909        } catch (IOException e) {
1910            fail("Exception serializing " + objToSave + " : " + 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