Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / test / java.io / ObjectStreamClassTest.java
blob7002bf7f02ba55bdcb1d7b89be7848d6fd52ea59
1 /*************************************************************************
2 /* ObjectStreamClassTest.java -- Tests ObjectStreamClass class
3 /*
4 /* Copyright (c) 1998 by Free Software Foundation, Inc.
5 /*
6 /* This program is free software; you can redistribute it and/or modify
7 /* it under the terms of the GNU General Public License as published
8 /* by the Free Software Foundation, version 2. (see COPYING)
9 /*
10 /* This program is distributed in the hope that it will be useful, but
11 /* WITHOUT ANY WARRANTY; without even the implied warranty of
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 /* GNU General Public License for more details.
15 /* You should have received a copy of the GNU General Public License
16 /* along with this program; if not, write to the Free Software Foundation
17 /* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 /*************************************************************************/
20 import java.io.Externalizable;
21 import java.io.ObjectInput;
22 import java.io.ObjectOutput;
23 import java.io.ObjectOutputStream;
24 import java.io.ObjectStreamClass;
25 import java.io.Serializable;
26 import java.util.Hashtable;
27 import java.util.Vector;
29 public class ObjectStreamClassTest
31 public static void pass()
33 System.out.print( "PASSED: " );
36 public static void fail()
38 System.out.print( "FAILED: " );
41 public static void pass( boolean exp_pass )
43 if( exp_pass )
44 pass();
45 else
46 System.out.print( "XPASSED: " );
49 public static void fail( boolean exp_pass )
51 if( exp_pass )
52 fail();
53 else
54 System.out.print( "XFAIL: " );
57 public static void testLookup( Class cl, boolean non_null )
59 if( non_null == (ObjectStreamClass.lookup( cl ) != null) )
60 pass();
61 else
62 fail();
64 System.out.println( "lookup() for " + cl );
67 public static void testGetName( Class cl, String name )
69 if( ObjectStreamClass.lookup( cl ).getName().equals( name ) )
70 pass();
71 else
72 fail();
74 System.out.println( "getName() for " + cl );
77 public static void testForClass( Class cl, Class clazz )
79 if( ObjectStreamClass.lookup( cl ).forClass() == clazz )
80 pass();
81 else
82 fail();
84 System.out.println( "forClass() for " + cl );
87 public static void testSUID( Class cl, long suid )
89 testSUID( cl, suid, true );
92 public static void testSUID( Class cl, long suid, boolean exp_pass )
94 if( ObjectStreamClass.lookup( cl ).getSerialVersionUID() == suid )
95 pass( exp_pass );
96 else
97 fail( exp_pass );
99 System.out.println( "getSerialVersionUID() for " + cl );
102 public static void testHasWrite( Class cl, boolean has_write )
104 if( ObjectStreamClass.lookup( cl ).hasWriteMethod() == has_write )
105 pass();
106 else
107 fail();
109 System.out.println( "hasWriteMethod() for " + cl );
112 public static void testIsSerial( Class cl, boolean is_serial )
114 if( ObjectStreamClass.lookup( cl ).isSerializable() == is_serial )
115 pass();
116 else
117 fail();
119 System.out.println( "isSerializable() for " + cl );
122 public static void testIsExtern( Class cl, boolean is_extern )
124 if( ObjectStreamClass.lookup( cl ).isExternalizable() == is_extern )
125 pass();
126 else
127 fail();
129 System.out.println( "isExternalizable() for " + cl );
132 public static void main( String[] args )
136 // lookup
137 testLookup( Serial.class, true );
138 testLookup( NotSerial.class, false );
140 // getName
141 testGetName( java.lang.String.class, "java.lang.String" );
142 testGetName( java.util.Hashtable.class, "java.util.Hashtable" );
144 // forClass
145 testForClass( java.lang.String.class, java.lang.String.class );
146 testForClass( java.util.Vector.class, (new Vector()).getClass() );
148 // getSerialVersionUID
149 testSUID( A.class, 1577839372146469075L );
150 testSUID( B.class, -7069956958769787679L );
152 // NOTE: this fails for JDK 1.1.5v5 on linux because a non-null
153 // jmethodID is returned from
154 // GetStaticMethodID( env, C, "<clinit>", "()V" )
155 // even though class C does not have a class initializer.
156 // The JDK's serialver tool does not have this problem somehow.
157 // I have not tested this on other platforms.
158 testSUID( C.class, 7441756018870420732L, false );
160 testSUID( Defined.class, 17 );
161 testSUID( DefinedNotStatic.class, 8797806279193632512L );
162 testSUID( DefinedNotFinal.class, -1014973327673071657L );
164 // hasWriteMethod
165 testHasWrite( Serial.class, false );
166 testHasWrite( HasWrite.class, true );
167 testHasWrite( InherWrite.class, false );
168 testHasWrite( PubWrite.class, false );
169 testHasWrite( StaticWrite.class, false );
170 testHasWrite( ReturnWrite.class, false );
172 // isSerializable
173 testIsSerial( Serial.class, true );
174 testIsSerial( Extern.class, false );
175 testIsSerial( InherSerial.class, true );
176 testIsSerial( InherExtern.class, false );
178 // isExternalizable
179 testIsExtern( Serial.class, false );
180 testIsExtern( Extern.class, true );
181 testIsExtern( InherSerial.class, false );
182 testIsExtern( InherExtern.class, true );
184 catch( Exception e )
186 e.printStackTrace();
191 class NotSerial {}
193 class A implements Serializable
195 int b;
196 int a;
198 public int f() { return 0; }
199 float g() { return 3; }
201 private float c;
204 abstract class B extends A
206 private B( int[] ar ) {}
207 public B() {}
208 public static void foo() {}
209 public abstract void absfoo();
211 private static String s;
212 public int[] a;
214 static
216 s = "hello";
220 class C extends B implements Cloneable, Externalizable
222 public void absfoo() {}
223 public void readExternal( ObjectInput i ) {}
224 public void writeExternal( ObjectOutput o ) {}
228 class Defined implements Serializable
230 static final long serialVersionUID = 17;
233 class DefinedNotStatic implements Serializable
235 final long serialVersionUID = 17;
238 class DefinedNotFinal implements Serializable
240 static long serialVersionUID = 17;
243 class HasWrite implements Serializable
245 private void writeObject( ObjectOutputStream o ) {}
248 class InherWrite extends HasWrite {}
250 class PubWrite implements Serializable
252 public void writeObject( ObjectOutputStream o ) {}
255 class StaticWrite implements Serializable
257 private static void writeObject( ObjectOutputStream o ) {}
260 class ReturnWrite implements Serializable
262 private int writeObject( ObjectOutputStream o )
264 return -1;
269 class Serial implements Serializable {}
271 class Extern implements Externalizable
273 public void readExternal( ObjectInput i )
276 public void writeExternal( ObjectOutput o )
280 class InherExtern extends Extern implements Serializable {}
282 class InherSerial extends Serial {}