Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / testsuite / java.lang / ByteTest.java
blobef1b1937de50c43ecd0b0fe5e0d2c7fde9b450d4
1 import gnu.test.*;
3 /**
4 * Test the Byte object wrapper class.
6 * @author Brian Jones (cbj@gnu.org)
7 */
8 public class ByteTest
10 public static class constructorTest1 implements Test
12 byte b = 1;
14 public String getName() {
15 return "Byte(byte)";
18 public Result test() {
19 try {
20 Byte byteObject = new Byte(b);
21 } catch (Exception e) {
22 return new Fail(e.getMessage());
23 } catch (Error err) {
24 return new Fail(err.getMessage());
26 return new Pass();
30 public static class constructorTest2 implements Test
32 Byte byteObject = null;
34 public String getName() {
35 return "Byte(String)";
38 public Result test() {
39 try {
40 byteObject = new Byte("1");
41 } catch (Exception e) {
42 return new Fail(e.getMessage());
43 } catch (Error err) {
44 return new Fail(err.getMessage());
46 return new Pass();
50 public static class byteValueTest implements Test
52 public String getName() {
53 return "Byte.byteValue()";
56 public Result test() {
57 byte b = 1;
58 Byte byteObject = new Byte(b);
59 if (byteObject.byteValue() == b)
60 return new Pass();
61 else
62 return new Fail();
66 public static class decodeTest implements Test
68 public String getName() {
69 return "Byte.decode(String)";
72 public Result test() {
73 Byte obj = Byte.decode("1");
74 if (obj.byteValue() == 1)
75 return new Pass();
76 else
77 return new Fail();
81 public static class doubleValueTest implements Test
83 public String getName() {
84 return "Byte.doubleValue()";
87 public Result test() {
88 byte b = 4;
89 double d = b;
90 Byte obj = new Byte(b);
91 if (obj.doubleValue() == d)
92 return new Pass();
93 else
94 return new Fail();
98 public static class equalsTest1 implements Test
100 public String getName() {
101 return "Byte.equals(Object)";
104 public Result test() {
105 Byte obj1 = null, obj2 = null;
106 obj1 = new Byte((byte)1);
107 obj2 = new Byte((byte)2);
108 if (obj1.equals(obj2))
109 return new Fail("1 != 2");
110 else
111 return new Pass("1 != 2");
115 public static class equalsTest2 implements Test
117 public String getName() {
118 return "Byte.equals(Object)";
121 public Result test() {
122 Byte obj1 = null, obj2 = null;
123 obj1 = new Byte((byte)1);
124 obj2 = new Byte((byte)2);
125 obj2 = obj1;
126 if (obj1.equals(obj2))
127 return new Pass("1 == 1");
128 else
129 return new Fail("1 == 1");
133 public static class floatValueTest implements Test
135 public String getName() {
136 return "Byte.floatValue()";
139 public Result test() {
140 byte b = 4;
141 float f = b;
142 Byte obj = new Byte(b);
143 if (obj.floatValue() == f)
144 return new Pass();
145 else
146 return new Fail();
150 public static class hashCodeTest implements Test
152 public String getName() {
153 return "Byte.hashCode()";
156 public Result test() {
157 boolean caught = false;
158 Byte obj = new Byte((byte)1);
159 int i = obj.hashCode();
160 if (i == 1)
161 return new Pass();
162 else
163 return new Fail("hash is " + i + ". It should be 1.");
167 public static class intValueTest implements Test
169 public String getName() {
170 return "Byte.intValue()";
173 public Result test() {
174 byte b = 4;
175 int i = b;
176 Byte obj = new Byte(b);
177 if (obj.intValue() == i)
178 return new Pass();
179 else
180 return new Fail();
184 public static class longValueTest implements Test
186 public String getName() {
187 return "Byte.longValue()";
190 public Result test() {
191 byte b = 4;
192 long l = b;
193 Byte obj = new Byte(b);
194 if (obj.longValue() == l)
195 return new Pass();
196 else
197 return new Fail();
201 public static class parseByteTest1 implements Test
203 public String getName() {
204 return "Byte.parseByte(String)";
207 public Result test() {
208 byte b = Byte.parseByte("1");
209 if (b == (byte)1)
210 return new Pass();
211 else
212 return new Fail();
216 public static class parseByteTest2 implements Test
218 public String getName() {
219 return "Byte.parseByte(String, int)";
222 public Result test() {
223 byte b = Byte.parseByte("-4", 10);
224 if (b == (byte)-4)
225 return new Pass();
226 else
227 return new Fail();
231 public static class shortValueTest implements Test
233 public String getName() {
234 return "Byte.shortValue()";
237 public Result test() {
238 byte b = 4;
239 short s = b;
240 Byte obj = new Byte(b);
241 if (obj.shortValue() == s)
242 return new Pass();
243 else
244 return new Fail();
248 public static class toStringTest1 implements Test
250 public String getName() {
251 return "Byte.toString()";
254 public Result test() {
255 Byte obj = new Byte((byte)-2);
256 String x = obj.toString();
257 if (x.equals("-2"))
258 return new Pass();
259 else
260 return new Fail();
264 public static class toStringTest2 implements Test
266 public String getName() {
267 return "Byte.toString(byte)";
270 public Result test() {
271 String x = Byte.toString((byte)-2);
272 if (x.equals("-2"))
273 return new Pass();
274 else
275 return new Fail();
279 public static class valueOfTest1 implements Test
281 public String getName() {
282 return "Byte.valueOf(String, int)";
285 public Result test() {
286 Byte obj1 = Byte.valueOf("2",10);
287 Byte obj2 = new Byte((byte)2);
288 if (obj1.intValue() == obj2.intValue())
289 return new Pass();
290 else
291 return new Fail();
295 public static class valueOfTest2 implements Test
297 public String getName() {
298 return "Byte.valueOf(String)";
301 public Result test() {
302 Byte obj1 = Byte.valueOf("2");
303 if (obj1.intValue() == 2)
304 return new Pass();
305 else
306 return new Fail();
310 public static class variablesTest1 implements Test
312 public String getName() {
313 return "Byte.MIN_VALUE";
316 public Result test() {
317 byte min = Byte.MIN_VALUE;
318 byte max = Byte.MAX_VALUE;
320 if (min == (byte)-128)
321 return new Pass("Byte.MIN_VALUE is -128");
322 else
323 return new Fail("Byte.MIN_VALUE is " + min + " != -128");
327 public static class variablesTest2 implements Test
329 public String getName() {
330 return "Byte.MAX_VALUE";
333 public Result test() {
334 byte min = Byte.MIN_VALUE;
335 byte max = Byte.MAX_VALUE;
337 if (max == (byte)127)
338 return new Pass("Byte.MAX_VALUE is 127");
339 else
340 return new Fail("Byte.MAX_VALUE is " + max + " != 127");
344 public static class variablesTest3 implements Test
346 public String getName() {
347 return "Byte.TYPE.getName()";
350 public Result test() {
351 String x = Byte.TYPE.getName();
352 if (x.equals("byte") != true)
353 return new Fail("Byte.TYPE.getName() is " + x + " != byte");
354 else
355 return new Pass("Byte.TYPE.getName() is byte");
359 public static class typeInstance implements Test
361 public String getName() {
362 return "Byte.TYPE.newInstance()";
365 public Result test() {
366 try {
367 Object b = Byte.TYPE.newInstance();
368 return new Fail("Byte.TYPE.newInstance succeeded.");
370 catch (InstantiationException e) {
371 return new Pass("Byte.TYPE.newInstance failed with exception '" +
372 e.toString() + "'");
374 catch (Exception ex) {
375 return new Fail("Byte.TYPE.newInstance threw incorrect exception '"
376 + ex.toString() + "'");