OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [test/] [java.io/] [ObjectStreamClassTest.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/*************************************************************************
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.
14
/*
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
/*************************************************************************/
19
 
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;
28
 
29
public class ObjectStreamClassTest
30
{
31
  public static void pass()
32
  {
33
    System.out.print( "PASSED: " );
34
  }
35
 
36
  public static void fail()
37
  {
38
    System.out.print( "FAILED: " );
39
  }
40
 
41
  public static void pass( boolean exp_pass )
42
  {
43
    if( exp_pass )
44
      pass();
45
    else
46
      System.out.print( "XPASSED: " );
47
  }
48
 
49
  public static void fail( boolean exp_pass )
50
  {
51
    if( exp_pass )
52
      fail();
53
    else
54
      System.out.print( "XFAIL: " );
55
  }
56
 
57
  public static void testLookup( Class cl, boolean non_null )
58
  {
59
    if( non_null == (ObjectStreamClass.lookup( cl ) != null) )
60
      pass();
61
    else
62
      fail();
63
 
64
    System.out.println( "lookup() for " + cl );
65
  }
66
 
67
  public static void testGetName( Class cl, String name )
68
  {
69
    if( ObjectStreamClass.lookup( cl ).getName().equals( name ) )
70
      pass();
71
    else
72
      fail();
73
 
74
    System.out.println( "getName() for " + cl );
75
  }
76
 
77
  public static void testForClass( Class cl, Class clazz )
78
  {
79
    if( ObjectStreamClass.lookup( cl ).forClass() == clazz )
80
      pass();
81
    else
82
      fail();
83
 
84
    System.out.println( "forClass() for " + cl );
85
  }
86
 
87
  public static void testSUID( Class cl, long suid )
88
  {
89
    testSUID( cl, suid, true );
90
  }
91
 
92
  public static void testSUID( Class cl, long suid, boolean exp_pass )
93
  {
94
    if( ObjectStreamClass.lookup( cl ).getSerialVersionUID() == suid )
95
      pass( exp_pass );
96
    else
97
      fail( exp_pass );
98
 
99
    System.out.println( "getSerialVersionUID() for " + cl );
100
  }
101
 
102
  public static void testHasWrite( Class cl, boolean has_write )
103
  {
104
    if( ObjectStreamClass.lookup( cl ).hasWriteMethod() == has_write )
105
      pass();
106
    else
107
      fail();
108
 
109
    System.out.println( "hasWriteMethod() for " + cl );
110
  }
111
 
112
  public static void testIsSerial( Class cl, boolean is_serial )
113
  {
114
    if( ObjectStreamClass.lookup( cl ).isSerializable() == is_serial )
115
      pass();
116
    else
117
      fail();
118
 
119
    System.out.println( "isSerializable() for " + cl );
120
  }
121
 
122
  public static void testIsExtern( Class cl, boolean is_extern )
123
  {
124
    if( ObjectStreamClass.lookup( cl ).isExternalizable() == is_extern )
125
      pass();
126
    else
127
      fail();
128
 
129
    System.out.println( "isExternalizable() for " + cl );
130
  }
131
 
132
  public static void main( String[] args )
133
  {
134
    try
135
    {
136
      // lookup
137
      testLookup( Serial.class, true );
138
      testLookup( NotSerial.class, false );
139
 
140
      // getName
141
      testGetName( java.lang.String.class, "java.lang.String" );
142
      testGetName( java.util.Hashtable.class, "java.util.Hashtable" );
143
 
144
      // forClass
145
      testForClass( java.lang.String.class, java.lang.String.class );
146
      testForClass( java.util.Vector.class, (new Vector()).getClass() );
147
 
148
      // getSerialVersionUID
149
      testSUID( A.class, 1577839372146469075L );
150
      testSUID( B.class, -7069956958769787679L );
151
 
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 );
159
 
160
      testSUID( Defined.class, 17 );
161
      testSUID( DefinedNotStatic.class, 8797806279193632512L );
162
      testSUID( DefinedNotFinal.class, -1014973327673071657L );
163
 
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 );
171
 
172
      // isSerializable
173
      testIsSerial( Serial.class, true );
174
      testIsSerial( Extern.class, false );
175
      testIsSerial( InherSerial.class, true );
176
      testIsSerial( InherExtern.class, false );
177
 
178
      // isExternalizable
179
      testIsExtern( Serial.class, false );
180
      testIsExtern( Extern.class, true );
181
      testIsExtern( InherSerial.class, false );
182
      testIsExtern( InherExtern.class, true );
183
    }
184
    catch( Exception e )
185
    {
186
      e.printStackTrace();
187
    }
188
  }
189
}
190
 
191
class NotSerial {}
192
 
193
class A implements Serializable
194
{
195
  int b;
196
  int a;
197
 
198
  public int f() { return 0; }
199
  float g() { return 3; }
200
 
201
  private float c;
202
}
203
 
204
abstract class B extends A
205
{
206
  private B( int[] ar ) {}
207
  public B() {}
208
  public static void foo() {}
209
  public abstract void absfoo();
210
 
211
  private static String s;
212
  public int[] a;
213
 
214
  static
215
  {
216
    s = "hello";
217
  }
218
}
219
 
220
class C extends B implements Cloneable, Externalizable
221
{
222
  public void absfoo() {}
223
  public void readExternal( ObjectInput i ) {}
224
  public void writeExternal( ObjectOutput o ) {}
225
}
226
 
227
 
228
class Defined implements Serializable
229
{
230
  static final long serialVersionUID = 17;
231
}
232
 
233
class DefinedNotStatic implements Serializable
234
{
235
  final long serialVersionUID = 17;
236
}
237
 
238
class DefinedNotFinal implements Serializable
239
{
240
  static long serialVersionUID = 17;
241
}
242
 
243
class HasWrite implements Serializable
244
{
245
  private void writeObject( ObjectOutputStream o ) {}
246
}
247
 
248
class InherWrite extends HasWrite {}
249
 
250
class PubWrite implements Serializable
251
{
252
  public void writeObject( ObjectOutputStream o ) {}
253
}
254
 
255
class StaticWrite implements Serializable
256
{
257
  private static void writeObject( ObjectOutputStream o ) {}
258
}
259
 
260
class ReturnWrite implements Serializable
261
{
262
  private int writeObject( ObjectOutputStream o )
263
  {
264
    return -1;
265
  }
266
}
267
 
268
 
269
class Serial implements Serializable {}
270
 
271
class Extern implements Externalizable
272
{
273
  public void readExternal( ObjectInput i )
274
  {}
275
 
276
  public void writeExternal( ObjectOutput o )
277
  {}
278
}
279
 
280
class InherExtern extends Extern implements Serializable {}
281
 
282
class InherSerial extends Serial {}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.