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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [test/] [gnu.java.lang.reflect/] [TypeSignatureTest.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/*************************************************************************
2
/* TypeSignatureTest.java -- Tests TypeSignature 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
 
21
import java.lang.reflect.Constructor;
22
import java.lang.reflect.Method;
23
import java.lang.reflect.Member;
24
 
25
import gnu.java.lang.reflect.TypeSignature;
26
 
27
public class TypeSignatureTest
28
{
29
  public static void pass()
30
  {
31
    System.out.print( "PASSED: " );
32
  }
33
 
34
  public static void fail()
35
  {
36
    System.out.print( "FAILED: " );
37
  }
38
 
39
  public static void testClass( Class clazz, String type_code )
40
  {
41
    if( TypeSignature.getEncodingOfClass( clazz ).equals( type_code ) )
42
      pass();
43
    else
44
      fail();
45
 
46
    System.out.println( "class encoding of " + clazz );
47
  }
48
 
49
  public static void testGetClass( Class clazz, String type_code )
50
    throws ClassNotFoundException
51
  {
52
    if( TypeSignature.getClassForEncoding( type_code ).equals( clazz ) )
53
      pass();
54
    else
55
      fail();
56
 
57
    System.out.println( "class from encoding " + type_code );
58
  }
59
 
60
  public static void testConstructor( Constructor c, String type_code )
61
  {
62
    if( TypeSignature.getEncodingOfConstructor( c ).equals( type_code ) )
63
      pass();
64
    else
65
      fail();
66
 
67
    System.out.println( "constructor encoding of " + c );
68
  }
69
 
70
  public static void testMethod( Method m, String type_code )
71
  {
72
    if( TypeSignature.getEncodingOfMethod( m ).equals( type_code ) )
73
      pass();
74
    else
75
      fail();
76
 
77
    System.out.println( "method encoding of " + m );
78
  }
79
 
80
  public static void testMember( Member m, String type_code )
81
  {
82
    if( TypeSignature.getEncodingOfMember( m ).equals( type_code ) )
83
      pass();
84
    else
85
      fail();
86
 
87
    System.out.println( "member encoding of " + m );
88
  }
89
 
90
  public static void main( String[] args )
91
  {
92
    try
93
    {
94
      // test getEncodingOfClass
95
      testClass( Boolean.TYPE, "Z" );
96
      testClass( Byte.TYPE, "B" );
97
      testClass( Character.TYPE, "C" );
98
      testClass( Double.TYPE, "D" );
99
      testClass( Float.TYPE, "F" );
100
      testClass( Integer.TYPE, "I" );
101
      testClass( Long.TYPE, "J" );
102
      testClass( Short.TYPE, "S" );
103
      testClass( (new int[] {}).getClass(), "[I" );
104
      testClass( (new float[][][] {}).getClass(), "[[[F" );
105
      testClass( String.class, "Ljava/lang/String;" );
106
      testClass( TypeSignatureTest.class, "LTypeSignatureTest;" );
107
 
108
      // test named inner-class
109
      TypeSignatureTest tst = new TypeSignatureTest();
110
      Inner i = tst.new Inner();
111
      testClass( i.getClass(),
112
                 "LTypeSignatureTest$Inner;" );
113
 
114
      // test anonymous inner-class
115
      Anon anon = new Anon() { public void f() {} };
116
      testClass( anon.getClass(), "LTypeSignatureTest$1;" );
117
 
118
      //test getEncodingOfConstructor
119
      testConstructor( String.class.getConstructor( new Class[] {} ),
120
                       "()V" );
121
      testConstructor(
122
        String.class.getConstructor( new Class[]
123
                                     { (new byte[]{}).getClass() } ),
124
        "([B)V" );
125
 
126
      testConstructor(
127
        String.class.getConstructor( new Class[] { StringBuffer.class } ),
128
        "(Ljava/lang/StringBuffer;)V" );
129
 
130
      // test getEncodingOfMethod
131
      testMethod(
132
        String.class.getMethod( "lastIndexOf",
133
                                new Class[] { Integer.TYPE, Integer.TYPE } ),
134
        "(II)I" );
135
 
136
      testMethod(
137
        String.class.getMethod( "length", new Class[] {} ),
138
        "()I" );
139
 
140
      testMethod(
141
        TypeSignatureTest.class.getMethod( "pass", new Class[] {} ),
142
        "()V" );
143
 
144
      testMember(
145
        TypeSignatureTest.class.getField( "i" ),
146
        "I" );
147
 
148
      testMember(
149
        TypeSignatureTest.class.getField( "s" ),
150
        "Ljava/lang/String;" );
151
 
152
      testMember(
153
        TypeSignatureTest.class.getField( "o" ),
154
        "[[Ljava/lang/Object;" );
155
 
156
      // test getClassForEncoding
157
      testGetClass( Boolean.TYPE, "Z" );
158
      testGetClass( Byte.TYPE, "B" );
159
      testGetClass( Character.TYPE, "C" );
160
      testGetClass( Double.TYPE, "D" );
161
      testGetClass( Float.TYPE, "F" );
162
      testGetClass( Integer.TYPE, "I" );
163
      testGetClass( Long.TYPE, "J" );
164
      testGetClass( Short.TYPE, "S" );
165
      testGetClass( (new int[] {}).getClass(), "[I" );
166
      testGetClass( (new float[][][] {}).getClass(), "[[[F" );
167
      testGetClass( String.class, "Ljava/lang/String;" );
168
      testGetClass( TypeSignatureTest.class, "LTypeSignatureTest;" );
169
 
170
      // test named inner-class
171
      testGetClass( i.getClass(),
172
                 "LTypeSignatureTest$Inner;" );
173
 
174
      // test anonymous inner-class
175
      testGetClass( anon.getClass(), "LTypeSignatureTest$1;" );
176
    }
177
    catch( Exception e )
178
    {
179
      e.printStackTrace();
180
    }
181
  }
182
 
183
  public int i;
184
  public String s;
185
  public Object[][] o;
186
 
187
 
188
  class Inner
189
  {}
190
}
191
 
192
 
193
interface Anon
194
{
195
  public void f();
196
}

powered by: WebSVN 2.1.0

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