diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/java.io/HairyGraph.java | 75 | ||||
-rw-r--r-- | test/java.io/OOSCallDefault.java | 39 | ||||
-rw-r--r-- | test/java.io/OOSExtern.java | 37 | ||||
-rw-r--r-- | test/java.io/OOSNoCallDefault.java | 42 | ||||
-rw-r--r-- | test/java.io/ObjectInputStreamTest.java | 65 | ||||
-rw-r--r-- | test/java.io/Test.java | 52 | ||||
-rw-r--r-- | test/java.io/calldefault.data | bin | 68 -> 68 bytes | |||
-rw-r--r-- | test/java.io/external.data | bin | 38 -> 38 bytes | |||
-rw-r--r-- | test/java.io/graph.data | bin | 299 -> 340 bytes | |||
-rw-r--r-- | test/java.io/nocalldefault.data | bin | 93 -> 93 bytes |
10 files changed, 310 insertions, 0 deletions
diff --git a/test/java.io/HairyGraph.java b/test/java.io/HairyGraph.java new file mode 100644 index 000000000..ca9a71353 --- /dev/null +++ b/test/java.io/HairyGraph.java @@ -0,0 +1,75 @@ + +import java.io.*; + +class GraphNode implements Serializable +{ + GraphNode( String s ) + { + this.s = s; + } + + public String toString() + { + return this.s; + } + + String s; + GraphNode a; + GraphNode b; + GraphNode c; + GraphNode d; +} + + +public class HairyGraph implements Serializable +{ + GraphNode A; + GraphNode B; + GraphNode C; + GraphNode D; + + HairyGraph() + { + A = new GraphNode( "A" ); + B = new GraphNode( "B" ); + C = new GraphNode( "C" ); + D = new GraphNode( "D" ); + + A.a = B; + A.b = C; + A.c = D; + A.d = A; + + B.a = C; + B.b = D; + B.c = A; + B.d = B; + + C.a = D; + C.b = A; + C.c = B; + C.d = C; + + D.a = A; + D.b = B; + D.c = C; + D.d = D; + } + + public boolean equals( Object o ) + { + HairyGraph hg = (HairyGraph)o; + + return (A.a == B.d) && (A.a == C.c) && (A.a == D.b) + && (A.b == B.a) && (A.b == C.d) && (A.b == D.c) + && (A.c == B.b) && (A.c == C.a) && (A.c == D.d) + && (A.d == B.c) && (A.d == C.b) && (A.d == D.a); + } + + void printOneLevel( GraphNode gn ) + { + System.out.println( "GraphNode< " + gn + ": " + gn.a + ", " + gn.b + + ", " + gn.c + ", " + gn.d + " >" ); + } + +} diff --git a/test/java.io/OOSCallDefault.java b/test/java.io/OOSCallDefault.java new file mode 100644 index 000000000..c0465c12e --- /dev/null +++ b/test/java.io/OOSCallDefault.java @@ -0,0 +1,39 @@ + +import java.io.*; + +public class OOSCallDefault implements Serializable +{ + int x; + double y; + transient String s; + + OOSCallDefault( int X, double Y, String S ) + { + x = X; + y = Y; + s = S; + } + + public boolean equals( Object o ) + { + OOSCallDefault oo = (OOSCallDefault)o; + return oo.x == x + && oo.y == y + && oo.s.equals( s ); + } + + private void writeObject( ObjectOutputStream oos ) throws IOException + { + oos.writeObject( s ); + oos.defaultWriteObject(); + oos.writeObject( s ); + } + + private void readObject( ObjectInputStream ois ) + throws ClassNotFoundException, IOException + { + ois.readObject(); + ois.defaultReadObject(); + s = (String)ois.readObject(); + } +} diff --git a/test/java.io/OOSExtern.java b/test/java.io/OOSExtern.java new file mode 100644 index 000000000..7394c5bc8 --- /dev/null +++ b/test/java.io/OOSExtern.java @@ -0,0 +1,37 @@ + +import java.io.*; + +public class OOSExtern extends OOSNoCallDefault implements Externalizable +{ + public OOSExtern() + {} + + OOSExtern( int X, String S, boolean B ) + { + super( X, S, B ); + } + + public void writeExternal( ObjectOutput oo ) throws IOException + { + oo.writeInt( super.x ); + oo.writeObject( super.s ); + oo.writeBoolean( super.b ); + } + + public void readExternal( ObjectInput oi ) + throws ClassNotFoundException, IOException + { + super.x = oi.readInt(); + super.s = (String)oi.readObject(); + super.b = oi.readBoolean(); + } + + public boolean equals( Object o ) + { + OOSExtern e = (OOSExtern)o; + return e.x == super.x + && e.s.equals( super.s ) + && e.b == super.b; + } + +} diff --git a/test/java.io/OOSNoCallDefault.java b/test/java.io/OOSNoCallDefault.java new file mode 100644 index 000000000..1e41754c4 --- /dev/null +++ b/test/java.io/OOSNoCallDefault.java @@ -0,0 +1,42 @@ + +import java.io.*; + +public class OOSNoCallDefault implements Serializable +{ + int x; + String s; + boolean b; + + OOSNoCallDefault() + {} + + OOSNoCallDefault( int X, String S, boolean B ) + { + x = X; + s = S; + b = B; + } + + public boolean equals( Object o ) + { + OOSNoCallDefault oo = (OOSNoCallDefault)o; + return oo.x == x + && oo.b == b + && oo.s.equals( s ); + } + + private void writeObject( ObjectOutputStream oos ) throws IOException + { + oos.writeInt( x ); + oos.writeObject( s ); + oos.writeBoolean( b ); + } + + private void readObject( ObjectInputStream ois ) + throws ClassNotFoundException, IOException + { + x = ois.readInt(); + s = (String)ois.readObject(); + b = ois.readBoolean(); + } +} diff --git a/test/java.io/ObjectInputStreamTest.java b/test/java.io/ObjectInputStreamTest.java new file mode 100644 index 000000000..7736ceb16 --- /dev/null +++ b/test/java.io/ObjectInputStreamTest.java @@ -0,0 +1,65 @@ +/************************************************************************* +/* ObjectInputStreamTest.java -- Tests ObjectInputStream class +/* +/* Copyright (c) 1998 by Geoffrey C. Berry (gcb@cs.duke.edu) +/* +/* This program is free software; you can redistribute it and/or modify +/* it under the terms of the GNU General Public License as published +/* by the Free Software Foundation, version 2. (see COPYING) +/* +/* This program is distributed in the hope that it will be useful, but +/* WITHOUT ANY WARRANTY; without even the implied warranty of +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +/* GNU General Public License for more details. +/* +/* You should have received a copy of the GNU General Public License +/* along with this program; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +import java.io.FileInputStream; +import java.io.ObjectInputStream; + +public class ObjectInputStreamTest extends Test +{ + public static void testSerial( Object obj, String filename ) + { + try + { + ObjectInputStream ois = + new ObjectInputStream( new FileInputStream( filename ) ); + + Object read_object = ois.readObject(); + ois.close(); + + if( read_object.equals( obj ) ) + pass(); + else + fail(); + } + catch( Exception e ) + { + e.printStackTrace(); + fail(); + } + } + + + public static void main( String[] args ) + { + testSerial( new OOSCallDefault( 1, 3.14, "test" ), + "calldefault.data" ); + System.out.println( "Object calling defaultWriteObject()" ); + + testSerial( new OOSNoCallDefault( 17, "no\ndefault", false ), + "nocalldefault.data" ); + System.out.println( "Object not calling defaultWriteObject()" ); + + testSerial( new OOSExtern( -1, "", true ), "external.data" ); + System.out.println( "Externalizable class" ); + + testSerial( new HairyGraph(), "graph.data" ); + System.out.println( "Graph of objects with circular references" ); + } + +} diff --git a/test/java.io/Test.java b/test/java.io/Test.java new file mode 100644 index 000000000..5cc62c615 --- /dev/null +++ b/test/java.io/Test.java @@ -0,0 +1,52 @@ +/************************************************************************* +/* Test.java -- Base class for test classes +/* +/* Copyright (c) 1998 by Geoffrey C. Berry (gcb@cs.duke.edu) +/* +/* This program is free software; you can redistribute it and/or modify +/* it under the terms of the GNU General Public License as published +/* by the Free Software Foundation, version 2. (see COPYING) +/* +/* This program is distributed in the hope that it will be useful, but +/* WITHOUT ANY WARRANTY; without even the implied warranty of +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +/* GNU General Public License for more details. +/* +/* You should have received a copy of the GNU General Public License +/* along with this program; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +public class Test +{ + public static void error() + { + System.out.print( "ERROR: " ); + } + + public static void pass() + { + System.out.print( "PASSED: " ); + } + + public static void fail() + { + System.out.print( "FAILED: " ); + } + + public static void pass( boolean exp_pass ) + { + if( exp_pass ) + pass(); + else + System.out.print( "XPASSED: " ); + } + + public static void fail( boolean exp_pass ) + { + if( exp_pass ) + fail(); + else + System.out.print( "XFAIL: " ); + } +} diff --git a/test/java.io/calldefault.data b/test/java.io/calldefault.data Binary files differindex 563585afc..60dcc0065 100644 --- a/test/java.io/calldefault.data +++ b/test/java.io/calldefault.data diff --git a/test/java.io/external.data b/test/java.io/external.data Binary files differindex b37260b1f..139cc01b3 100644 --- a/test/java.io/external.data +++ b/test/java.io/external.data diff --git a/test/java.io/graph.data b/test/java.io/graph.data Binary files differindex f1ec5ccb0..55d5b1186 100644 --- a/test/java.io/graph.data +++ b/test/java.io/graph.data diff --git a/test/java.io/nocalldefault.data b/test/java.io/nocalldefault.data Binary files differindex c0d49a44d..ba987bb15 100644 --- a/test/java.io/nocalldefault.data +++ b/test/java.io/nocalldefault.data |