summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorBrian Jones <cbj@gnu.org>1998-10-02 04:42:42 +0000
committerBrian Jones <cbj@gnu.org>1998-10-02 04:42:42 +0000
commit1dc1326d1e9e4ca31cdccd4bc6ec7b4609e3c223 (patch)
tree3f1a8c631cb3e24d83794aa38f121b6915b0ae18 /testsuite
parent24fbbbda0bf614067885c7a028d0a61c4f2ede7c (diff)
downloadclasspath-1dc1326d1e9e4ca31cdccd4bc6ec7b4609e3c223.tar.gz
Modified for testing framework
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/java.lang/ByteTest.java647
1 files changed, 437 insertions, 210 deletions
diff --git a/testsuite/java.lang/ByteTest.java b/testsuite/java.lang/ByteTest.java
index a00f2a91a..b5e5bc075 100644
--- a/testsuite/java.lang/ByteTest.java
+++ b/testsuite/java.lang/ByteTest.java
@@ -1,3 +1,6 @@
+import gnu.test;
+import java.lang;
+
/**
* Test the Byte object wrapper class.
*
@@ -5,266 +8,490 @@
*/
public class ByteTest
{
- public static void main(String[] argv)
- {
- ByteTest test = new ByteTest();
- test.constructorsTest();
- test.byteValueTest();
- test.decodeTest();
- test.doubleValueTest();
- test.equalsTest();
- test.floatValueTest();
- test.hashCodeTest();
- test.intValueTest();
- test.longValueTest();
- test.parseByteTest();
- test.shortValueTest();
- test.toStringTest();
- test.valueOfTest();
- test.variables();
- test.typeInstance();
+ public static class constructorTest1 implements Test
+ {
+ byte b = 1;
+ Byte byteObject = null;
+
+ public String getName() {
+ return "Byte(byte)";
}
-
- public void constructorsTest()
- {
+
+ public Result test() {
+ try {
+ Byte byteObject = new Byte(b);
+ } catch (Exception e) {
+ return new Fail(e.getMessage());
+ } catch (Error err) {
+ return new Fail(err.getMessage());
+ }
+ return new Pass();
+ }
+ }
+
+ public static class constructorTest2 implements Test
+ {
+ Byte byteObject = null;
+
+ public String getName() {
+ return "Byte(String)";
+ }
+
+ public Result test() {
+ try {
+ byteObject = new Byte("1");
+ } catch (Exception e) {
+ return new Fail(e.getMessage());
+ } catch (Error err) {
+ return new Fail(err.getMessage());
+ }
+ return new Pass();
+ }
+ }
+
+ public static class byteValueTest implements Test
+ {
+ public String getName() {
+ return "Byte.byteValue()";
+ }
+
+ public Result test() {
byte b = 1;
- Byte obj1 = null, obj2 = null;
- String y;
+ Byte byteObject = null;
+ try {
+ byteObject = new Byte(b);
+ if (byteObject.byteValue() == b)
+ return new Pass();
+ else
+ return new Fail();
+ } catch (Exception e) {
+ return new Fail(e.getMessage());
+ } catch (Error err) {
+ return new Fail(err.getMessage());
+ }
+ return new Fail(); // shouldn't get here
+ }
+ }
- obj1 = new Byte(b);
- y = obj1.toString();
- if (y.equals("1") != true)
- failed("Byte(byte)");
- else
- passed("Byte(byte)");
+ public static class decodeTest implements Test
+ {
+ public String getName() {
+ return "Byte.decode(String)";
+ }
+
+ public Result test() {
+ try {
+ Byte obj = Byte.decode("1");
+ if (obj.byteValue() == 1)
+ return new Pass();
+ else
+ return new Fail();
+ } catch (Exception e) {
+ return new Fail(e.getMessage());
+ } catch (Error err) {
+ return new Fail(err.getMessage());
+ }
+ return new Fail(); // shouldn't get here
+ }
+ }
+
+ public static class doubleValueTest implements Test
+ {
+ public String getName() {
+ return "Byte.doubleValue()";
+ }
+
+ public Result test() {
+ try {
+ byte b = 4;
+ double d = b;
+ Byte obj = new Byte(b);
+ if (obj.doubleValue() == d)
+ return new Pass();
+ else
+ return new Fail();
+ } catch (Exception e) {
+ return new Fail(e.getMessage());
+ } catch (Error err) {
+ return new Fail(err.getMessage());
+ }
+ return new Fail(); // shouldn't get here
+ }
+ }
+
+ public static class equalsTest1 implements Test
+ {
+ public String getName() {
+ return "Byte.equals(Object)";
+ }
- try
- {
- obj2 = new Byte("1");
- y = obj2.toString();
- if (y.equals("1") != true)
- failed("Byte(String)");
- else
- passed("Byte(String)");
- }
- catch (NumberFormatException nfe)
- {
- failed("Byte(String)");
- }
+ public Result test() {
+ try {
+ Byte obj1 = null, obj2 = null;
+ obj1 = new Byte((byte)1);
+ obj2 = new Byte((byte)2);
+ if (obj1.equals(obj2))
+ return new Fail("1 != 2");
+ else
+ return new Pass("1 != 2");
+ } catch (Exception e) {
+ return new Fail(e.getMessage());
+ } catch (Error err) {
+ return new Fail(err.getMessage());
+ }
+ return new Fail(); // shouldn't get here
}
+ }
- public void byteValueTest()
- {
- byte b = 1;
- Byte obj = new Byte(b);
- if (obj.byteValue() == b)
- passed("Byte.byteValue()");
- else
- failed("Byte.byteValue()");
+ public static class equalsTest2 implements Test
+ {
+ public String getName() {
+ return "Byte.equals(Object)";
}
- public void decodeTest()
- {
- try
- {
- Byte obj = Byte.decode("1");
- if (obj.byteValue() == 1)
- passed("Byte.decode(String)");
- else
- failed("Byte.decode(String)");
- }
- catch (NumberFormatException nfe)
- {
- failed("Byte.decode(String) threw NumberFormatException");
- }
+ public Result test() {
+ try {
+ Byte obj1 = null, obj2 = null;
+ obj1 = new Byte((byte)1);
+ obj2 = new Byte((byte)2);
+ obj2 = obj1;
+ if (obj1.equals(obj2))
+ return new Pass("1 == 1");
+ else
+ return new Fail("1 == 1");
+ } catch (Exception e) {
+ return new Fail(e.getMessage());
+ } catch (Error err) {
+ return new Fail(err.getMessage());
+ }
+ return new Fail(); // shouldn't get here
+ }
+ }
+
+ public static class floatValueTest implements Test
+ {
+ public String getName() {
+ return "Byte.floatValue()";
}
- public void doubleValueTest()
- {
- byte b = 4;
- double d = b;
- Byte obj = new Byte(b);
- if (obj.doubleValue() == d)
- passed("Byte.doubleValue()");
- else
- failed("Byte.doubleValue()");
+ public Result test() {
+ try {
+ byte b = 4;
+ float f = b;
+ Byte obj = new Byte(b);
+ if (obj.floatValue() == f)
+ return new Pass();
+ else
+ return new Fail();
+ } catch (Exception e) {
+ return new Fail(e.getMessage());
+ } catch (Error err) {
+ return new Fail(err.getMessage());
+ }
+ return new Fail(); // shouldn't get here
}
+ }
- public void equalsTest()
- {
- Byte obj1 = null, obj2 = null;
- obj1 = new Byte((byte)1);
- obj2 = new Byte((byte)2);
- if (obj1.equals(obj2))
- failed("Byte.equals() 1 != 2");
- else
- passed("Byte.equals() 1 != 2");
+ public static class hashCodeTest implements Test
+ {
+ public String getName() {
+ return "Byte.hashCode()";
+ }
- obj2 = obj1;
- if (obj1.equals(obj2))
- passed("Byte.equals() 1 == 1");
- else
- failed("Byte.equals() 1 == 1");
+ public Result test() {
+ try {
+ boolean caught = false;
+ Byte obj = new Byte((byte)1);
+ int i = obj.hashCode();
+ } catch (Exception e) {
+ return new Fail(e.getMessage());
+ } catch (Error err) {
+ return new Fail(err.getMessage());
+ }
+ return new Pass();
+ }
+ }
+
+ public static class intValueTest implements Test
+ {
+ public String getName() {
+ return "Byte.intValue()";
}
- public void floatValueTest()
- {
- byte b = 4;
- float f = b;
- Byte obj = new Byte(b);
- if (obj.floatValue() == f)
- passed("Byte.floatValue()");
- else
- failed("Byte.floatValue()");
+ public Result test() {
+ try {
+ byte b = 4;
+ int i = b;
+ Byte obj = new Byte(b);
+ if (obj.intValue() == i)
+ return new Pass();
+ else
+ return new Fail();
+ } catch (Exception e) {
+ return new Fail(e.getMessage());
+ } catch (Error err) {
+ return new Fail(err.getMessage());
+ }
+ return new Fail(); // shouldn't get here
+ }
+ }
+
+ public static class longValueTest implements Test
+ {
+ public String getName() {
+ return "Byte.longValue()";
}
- public void hashCodeTest()
- {
- boolean caught = false;
- Byte obj = new Byte((byte)1);
- try
- {
- int i = obj.hashCode();
- }
- catch (Exception e)
- {
- caught = true;
- failed("Byte.hashCode()");
- }
- if (!caught)
- passed("Byte.hashCode()");
+ public Result test() {
+ try {
+ byte b = 4;
+ long l = b;
+ Byte obj = new Byte(b);
+ if (obj.longValue() == l)
+ return new Pass();
+ else
+ return new Fail();
+ } catch (Exception e) {
+ return new Fail(e.getMessage());
+ } catch (Error err) {
+ return new Fail(err.getMessage());
+ }
+ return new Fail(); // shouldn't get here
}
+ }
- public void intValueTest()
- {
- byte b = 4;
- int i = b;
- Byte obj = new Byte(b);
- if (obj.intValue() == i)
- passed("Byte.intValue()");
- else
- failed("Byte.intValue()");
+ public static class parseByteTest1 implements Test
+ {
+ public String getName() {
+ return "Byte.parseByte(String)";
}
- public void longValueTest()
- {
- byte b = 4;
- long l = b;
- Byte obj = new Byte(b);
- if (obj.longValue() == l)
- passed("Byte.longValue()");
- else
- failed("Byte.longValue()");
+ public Result test() {
+ try {
+ byte b = Byte.parseByte("1");
+ if (b == (byte)1)
+ return new Pass();
+ else
+ return new Fail();
+ } catch (Exception e) {
+ return new Fail(e.getMessage());
+ } catch (Error err) {
+ return new Fail(err.getMessage());
+ }
+ return new Fail(); // shouldn't get here
}
+ }
- public void parseByteTest()
- {
- byte b = Byte.parseByte("1");
- if (b == (byte)1)
- passed("Byte.parseByte(String)");
- else
- failed("Byte.parseByte(String)");
+ public static class parseByteTest2 implements Test
+ {
+ public String getName() {
+ return "Byte.parseByte(String, int)";
+ }
- b = Byte.parseByte("-4", 10);
- if (b == (byte)-4)
- passed("Byte.parseByte(String, int)");
- else
- failed("Byte.parseByte(String, int)");
+ public Result test() {
+ try {
+ b = Byte.parseByte("-4", 10);
+ if (b == (byte)-4)
+ return new Pass();
+ else
+ return new Fail();
+ } catch (Exception e) {
+ return new Fail(e.getMessage());
+ } catch (Error err) {
+ return new Fail(err.getMessage());
+ }
+ return new Fail(); // shouldn't get here
}
+ }
- public void shortValueTest()
- {
- byte b = 4;
- short s = b;
- Byte obj = new Byte(b);
- if (obj.shortValue() == s)
- passed("Byte.shortValue()");
- else
- failed("Byte.shortValue()");
+ public static class shortValueTest implements Test
+ {
+ public String getName() {
+ return "Byte.shortValue()";
}
- public void toStringTest()
- {
- Byte obj = new Byte((byte)-2);
- String x = obj.toString();
- if (x.equals("-2"))
- passed("Byte.toString()");
- else
- failed("Byte.toString()");
+ public Result test() {
+ try {
+ byte b = 4;
+ short s = b;
+ Byte obj = new Byte(b);
+ if (obj.shortValue() == s)
+ return new Pass();
+ else
+ return new Fail();
+ } catch (Exception e) {
+ return new Fail(e.getMessage());
+ } catch (Error err) {
+ return new Fail(err.getMessage());
+ }
+ return new Fail(); // shouldn't get here
+ }
+ }
- x = Byte.toString((byte)-2);
- if (x.equals("-2"))
- passed("Byte.toString(byte)");
- else
- failed("Byte.toString(byte)");
+ public static class toStringTest1 implements Test
+ {
+ public String getName() {
+ return "Byte.toString()";
}
- public void valueOfTest()
- {
- Byte obj1 = Byte.valueOf("2",10);
- Byte obj2 = new Byte((byte)2);
- if (obj1.intValue() == obj2.intValue())
- passed("Byte.valueOf(String,int)");
- else
- failed("Byte.valueOf(String,int)");
+ public Result test() {
+ try {
+ Byte obj = new Byte((byte)-2);
+ String x = obj.toString();
+ if (x.equals("-2"))
+ return new Pass();
+ else
+ return new Fail();
+ } catch (Exception e) {
+ return new Fail(e.getMessage());
+ } catch (Error err) {
+ return new Fail(err.getMessage());
+ }
+ return new Fail(); // shouldn't get here
+ }
+ }
+
+ public static class toStringTest2 implements Test
+ {
+ public String getName() {
+ return "Byte.toString(byte)";
+ }
- obj1 = Byte.valueOf("2");
- if (obj1.intValue() == obj2.intValue())
- passed("Byte.valueOf(String)");
- else
- failed("Byte.valueOf(String)");
+ public Result test() {
+ try {
+ x = Byte.toString((byte)-2);
+ if (x.equals("-2"))
+ return new Pass();
+ else
+ return new Fail();
+ } catch (Exception e) {
+ return new Fail(e.getMessage());
+ } catch (Error err) {
+ return new Fail(err.getMessage());
+ }
+ return new Fail(); // shouldn't get here
}
+ }
- public void variables()
- {
+ public static class valueOfTest1 implements Test
+ {
+ public String getName() {
+ return "Byte.valueOf(String, int)";
+ }
+
+ public Result test() {
+ try {
+ Byte obj1 = Byte.valueOf("2",10);
+ Byte obj2 = new Byte((byte)2);
+ if (obj1.intValue() == obj2.intValue())
+ return new Pass();
+ else
+ return new Fail();
+ } catch (Exception e) {
+ return new Fail(e.getMessage());
+ } catch (Error err) {
+ return new Fail(err.getMessage());
+ }
+ return new Fail(); // shouldn't get here
+ }
+ }
+
+ public static class valueOfTest2 implements Test
+ {
+ public String getName() {
+ return "Byte.valueOf(String)";
+ }
+
+ public Result test() {
+ try {
+ obj1 = Byte.valueOf("2");
+ if (obj1.intValue() == obj2.intValue())
+ return new Pass();
+ else
+ return new Fail();
+ } catch (Exception e) {
+ return new Fail(e.getMessage());
+ } catch (Error err) {
+ return new Fail(err.getMessage());
+ }
+ return new Fail(); // shouldn't get here
+ }
+ }
+
+ public static class variablesTest1 implements Test
+ {
+ public String getName() {
+ return "Byte.MIN_VALUE";
+ }
+
+ public Result test() {
byte min = Byte.MIN_VALUE;
byte max = Byte.MAX_VALUE;
if (min == (byte)-128)
- passed("Byte.MIN_VALUE is -128");
+ return new Pass("Byte.MIN_VALUE is -128");
else
- failed("Byte.MIN_VALUE is " + min + " != -128");
+ return new Fail("Byte.MIN_VALUE is " + min + " != -128");
+ }
+ }
+
+ public static class variablesTest2 implements Test
+ {
+ public String getName() {
+ return "Byte.MAX_VALUE";
+ }
+ public Result test() {
+ byte min = Byte.MIN_VALUE;
+ byte max = Byte.MAX_VALUE;
+
if (max == (byte)127)
- passed("Byte.MIN_VALUE is 127");
+ return new Pass("Byte.MAX_VALUE is 127");
else
- failed("Byte.MIN_VALUE is " + min + " != 127");
+ return new Fail("Byte.MAX_VALUE is " + max + " != 127");
+ }
+ }
- String x = Byte.TYPE.getName();
- if (x.equals("byte") != true)
- failed("Byte.TYPE.getName() is " + x + " != byte");
- else
- passed("Byte.TYPE.getName() is byte");
+ public static class variablesTest3 implements Test
+ {
+ public String getName() {
+ return "Byte.TYPE.getName()";
}
- public void typeInstance()
- {
+ public Result test() {
try {
- Object b = Byte.TYPE.newInstance();
-
- failed("Byte.TYPE.newInstance succeeded.");
- }
- catch (InstantiationException e) {
- passed("Byte.TYPE.newInstance failed with exception '" + e.toString() + "'");
- }
- catch (Exception e) {
- failed("Byte.TYPE.newInstance threw incorrect exception '" + e.toString() + "'");
+ String x = Byte.TYPE.getName();
+ if (x.equals("byte") != true)
+ return new Fail("Byte.TYPE.getName() is " + x + " != byte");
+ else
+ return new Pass("Byte.TYPE.getName() is byte");
+ } catch (Exception e) {
+ return new Fail(e.getMessage());
+ } catch (Error err) {
+ return new Fail(err.getMessage());
}
+ return new Fail(); // shouldn't get here
}
+ }
- public void failed(String s)
- {
- if (s != null)
- System.out.println("FAILED: " + s);
- else
- System.out.println("FAILED: ");
+ public static class typeInstance implements Test
+ {
+ public String getName() {
+ return "Byte.TYPE.newInstance()";
}
- public void passed(String s)
- {
- if (s != null)
- System.out.println("PASSED: " + s);
- else
- System.out.println("PASSED: ");
+ public Result test() {
+ try {
+ Object b = Byte.TYPE.newInstance();
+ return new Fail("Byte.TYPE.newInstance succeeded.");
+ }
+ catch (InstantiationException e) {
+ return new Pass("Byte.TYPE.newInstance failed with exception '" + e.toString() + "'");
+ }
+ catch (Exception ex) {
+ return new Fail("Byte.TYPE.newInstance threw incorrect exception '" + ex.toString() + "'");
+ }
+ return new Fail(); // shouldn't get here
}
+ }
}