aboutsummaryrefslogtreecommitdiff
path: root/gnu/testlet/java/lang/reflect/Method/toString.java
blob: 4cac0682921f0415ffb838fa964e5f367f1ffe5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Tags: JDK1.1

// Copyright (C) 1999, 2000, 2001, 2004 Red Hat, Inc.

// This file is part of Mauve.

// Mauve 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; either version 2, or (at your option)
// any later version.

// Mauve 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 Mauve; see the file COPYING.  If not, write to
// the Free Software Foundation, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.  */

package gnu.testlet.java.lang.reflect.Method;
import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;
import java.lang.reflect.Method;

public class toString implements Testlet
{
  public Method getMethod (Class ic, String name, Class[] list)
  {
    Method m = null;
    try
      {
	m = ic.getMethod(name, list);
      }
    catch (Throwable _)
      {
	// Nothing.
      }
    return m;
  }

  public String no_args ()
  {
    return "zardoz";
  }

  public void simpleargs (int i, byte b)
  {
  }
  
  public int arrayargs (int[] z)
  {
    return z.length;
  }

  public int multidim_arrayargs (int[][][] z)
  {
    return z.length;
  }

  public String classargs (String[][] s)
  {
    return "test";
  }

  public String[] arrayreturn()
  {
    return null;
  }

  public void test (TestHarness harness)
  {
    Class ic = null;
    try
      {
	ic = Class.forName ("gnu.testlet.java.lang.reflect.Method.toString");
      }
    catch (Throwable _)
      {
	// Lose.
      }

    Class[] na_list = new Class[0];
    Method na_meth = getMethod (ic, "no_args", na_list);
    harness.checkPoint("method with no arguments");
    harness.check (na_meth.toString (), "public java.lang.String gnu.testlet.java.lang.reflect.Method.toString.no_args()");

    Class[] simple_list = new Class[2];
    simple_list[0] = int.class;
    simple_list[1] = byte.class;
    Method simple_meth = getMethod (ic, "simpleargs", simple_list);
    harness.checkPoint("method with primitive argument types");
    harness.check (simple_meth.toString (),
		    "public void gnu.testlet.java.lang.reflect.Method.toString.simpleargs(int,byte)");
    
    Class[] aa_list = new Class[1];
    aa_list[0] = int[].class;
    Method aa_meth = getMethod (ic, "arrayargs", aa_list);
    harness.checkPoint("method with a simple array type as argument");
    harness.check (aa_meth.toString (),
		   "public int gnu.testlet.java.lang.reflect.Method.toString.arrayargs(int[])");

    Method mdaa_meth = getMethod (ic, "multidim_arrayargs", aa_list);
    harness.check(mdaa_meth == null, "invalid argument list for this method, getMethod should return null");

    aa_list = new Class[1];
    aa_list[0] = int[][][].class;
    mdaa_meth = getMethod (ic, "multidim_arrayargs", aa_list);

    harness.checkPoint("method with multiple array dims in argument");
    harness.check (mdaa_meth.toString (),
		   "public int gnu.testlet.java.lang.reflect.Method.toString.multidim_arrayargs(int[][][])");

    aa_list = new Class[1];
    aa_list[0] = String[][].class;
    Method string_meth = getMethod (ic, "classargs", aa_list);
    harness.checkPoint("method with class type array");
    harness.check (string_meth.toString (),
		    "public java.lang.String gnu.testlet.java.lang.reflect.Method.toString.classargs(java.lang.String[][])");

    na_list = new Class[0];
    Method ra_meth = getMethod (ic, "arrayreturn", na_list);
    harness.checkPoint("method with array as return type");
    harness.check (ra_meth.toString (),
		    "public java.lang.String[] gnu.testlet.java.lang.reflect.Method.toString.arrayreturn()");
  }
}