File: check.java

package info (click to toggle)
mauve 20161030-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 44,628 kB
  • ctags: 35,425
  • sloc: java: 336,555; sh: 2,834; xml: 208; makefile: 72
file content (217 lines) | stat: -rw-r--r-- 5,544 bytes parent folder | download | duplicates (5)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// Test Expression.check().

// Written by Jerry Quinn <jlquinn@optonline.net>

// 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.

// Tags: JDK1.4

// Test features added by JDK 1.4

package gnu.testlet.java.beans.Expression;

import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;
import java.beans.Expression;

public class check implements Testlet
{
  public static int x = 0;

  public static int test1(int y) { x = y; return x; }

  public class dummy
  {
    public String s;
    public int x;
    public dummy() { s = ""; x = 5;}

    public String method(String s)
    {
      this.s = s;
      return this.s + " " + this.x;
    }

    public String method(String s, int y)
    {
      this.s = s;
      this.x = y + 1;
      return this.s + " " + this.x;
    }

    public String method1(String s, Integer y)
    {
      this.s = s;
      this.x = y.intValue();
      return this.s + " " + this.x;
    }

//     public static String method2(String s)
//     {
//       return s + "static";
//     }
  }

  public void test (TestHarness harness)
  {
    dummy d = new dummy();

    // Check that we can create and getValue a expression
    Object arg1[] = {"test"};
    Expression expr = new Expression(d, "method", arg1);
    harness.check(expr != null, "Construct an Expression");
    harness.check(expr.getTarget() == d);
    harness.check(expr.getMethodName().equals("method"));
    String res1 = "";
    try
      {
	res1 = (String) expr.getValue();
      }
    catch (Exception e)
      {
	harness.fail("Expression getValue failed");
      }

    harness.check(d.s.equals("test"), "Test getValue with method of single arg");
    harness.check(d.x == 5);
    harness.check(res1.equals("test 5"));

    // Check that we can create and getValue a expression and that a
    // wrapper class resolves to a method taking a primitive.
    Object arg2[] = {"test", new Integer(6) };
    expr = new Expression(d, "method", arg2);
    harness.check(expr != null, "Construct an Expression with 2 args");

    Object exprArgs[] = expr.getArguments();
    harness.check(exprArgs.length == arg2.length && exprArgs[0] == arg2[0]
		  && exprArgs[1] == arg2[1]);
    String res2 = "";
    try
      {
	res2 = (String) expr.getValue();
      }
    catch (Exception e)
      {
	harness.fail("Expression getValue failed");
      }

    harness.check(d.s.equals("test"), "Test getValue with method of single arg");
    harness.check(d.x == 7);
    harness.check(res2.equals("test 7"));


    // Check that we can create and getValue a expression for a static method.
    Object arg3[] = {new Integer(1)};
    expr = new Expression(this, "test1", arg3);
    int res3 = 0;

    try
      {
	res3 = ((Integer)expr.getValue()).intValue();
      }
    catch (Exception e)
      {
	harness.fail("Static method getValue " + e.toString());
      }
    harness.check(res3 == 1, "Test Expression with static method");


    // Check that we can call get and set on an array object in a expression
    int iarray[] = {1, 2, 3, 4, 5};
    Object arg4[] = { new Integer(2), new Integer(6) };

    expr = new Expression(iarray, "set", arg4);
    Object res4 = new Object();
    try
      {
	res4 = expr.getValue();
      }
    catch (Exception e)
      {
	harness.fail("Expression set failed");
      }
    //Array.set is public static void and should have no return value
    harness.check(res4 == null);

    harness.check(iarray[2] == 6);

    Object arg5[] = { new Integer(2) };
    expr = new Expression(iarray, "get", arg5);
    int res5 = 0;
    try
      {
	res5 = ((Integer)expr.getValue()).intValue();
      }
    catch (Exception e)
      {
	harness.fail("Expression get failed");
      }

    harness.check(res5 == 6, "Test Expression of array and method named get");

    // check that Expression can call object constructor
    Object arg6[] = { this };
    expr = new Expression(d.getClass(), "new", arg6);
    dummy d1 = null;
    try
      {
	d1 = (dummy) expr.getValue();
      }
    catch (Exception e)
      {
	harness.debug(e);
	harness.fail("Expression using new failed");
      }

    harness.check(d1 != d, "Test expr using new");

    // check that Expression constructer with val uses val
    expr = new Expression(d, d, "new", arg6);
    d1 = null;
    try
      {
	d1 = (dummy) expr.getValue();
      }
    catch (Exception e)
      {
	harness.fail("Constructor failed");
      }

    harness.check(d1 == d, "Test expr constructor with value");
   

    // check that setvalue works and getvalue returns it
    String s1 = "t";
    expr.setValue(s1);
    
    String s2 = "";
    try
      {
	s2 = (String) expr.getValue();
      }
    catch (Exception e)
      {
	harness.fail("Constructor failed");
      }
    harness.check(s1 == s2, "Test expr setValue and getValue");

    // check that tostring does something
    String s3 = expr.toString();
  }

}