summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorBrian Jones <cbj@gnu.org>1998-06-20 22:19:43 +0000
committerBrian Jones <cbj@gnu.org>1998-06-20 22:19:43 +0000
commit9b63dbdad4eb831024095ce0b174885d73ab9c50 (patch)
treea83e002175c68d7792c5a5d6861ddde249647f1a /testsuite
parente903e6b200bf23405534d442cfd0f85e4208479f (diff)
downloadclasspath-9b63dbdad4eb831024095ce0b174885d73ab9c50.tar.gz
initial checkin
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/java.io/IsAbsoluteTest.java26
-rw-r--r--testsuite/java.io/RandomAccessFileTest.java50
-rw-r--r--testsuite/java.io/execute.exp7
-rw-r--r--testsuite/java.lang/ArrayTest.java100
-rw-r--r--testsuite/java.lang/BooleanTest.java177
-rw-r--r--testsuite/java.lang/ByteTest.java270
-rw-r--r--testsuite/java.opstack/LeftBehind.j64
-rw-r--r--testsuite/java.opstack/execute.exp7
8 files changed, 701 insertions, 0 deletions
diff --git a/testsuite/java.io/IsAbsoluteTest.java b/testsuite/java.io/IsAbsoluteTest.java
new file mode 100644
index 000000000..2e4a6502e
--- /dev/null
+++ b/testsuite/java.io/IsAbsoluteTest.java
@@ -0,0 +1,26 @@
+import java.io.*;
+
+public class IsAbsoluteTest {
+ public static void main (String args[]) {
+ try {
+ File f1 = new File("/etc/passwd");
+ File f2 = new File("\\autoexec.bat");
+ File f3 = new File("c:\\autoexec.bat");
+
+ File u1 = new File("tmp/somefile");
+
+ if ( u1.isAbsolute() )
+ throw new Exception("Claims "+u1+" is absolute!");
+
+ if ( ! f1.isAbsolute() )
+ { /* Hm, might be on MSDOS platform, test those cases */
+ if ( ! f2.isAbsolute() || ! f3.isAbsolute() )
+ throw new Exception("Claims file isn't absolute!");
+ }
+
+ System.out.println("PASSED: All ok");
+ } catch (Exception e) {
+ System.out.println("FAILED: "+e);
+ }
+ }
+}
diff --git a/testsuite/java.io/RandomAccessFileTest.java b/testsuite/java.io/RandomAccessFileTest.java
new file mode 100644
index 000000000..69dc4383c
--- /dev/null
+++ b/testsuite/java.io/RandomAccessFileTest.java
@@ -0,0 +1,50 @@
+
+import java.io.*;
+
+public class RandomAccessFileTest {
+ public static void main (String args[]) {
+ try {
+ File f = new File("/etc/passwd");
+ RandomAccessFile rf = new RandomAccessFile(f,"r");
+
+ long length = rf.length();
+
+ rf.seek(length - 10);
+ long pos = rf.getFilePointer();
+
+ if ( (length - 10) != pos )
+ throw new Exception("Bad value from getFilePointer(), " +
+ pos + " !=" + (length - 10));
+
+ int i = rf.read();
+ byte b = rf.readByte();
+ boolean test = rf.readBoolean();
+
+ byte buf[] = new byte[40];
+ rf.seek(0);
+ rf.read(buf);
+
+ rf.close();
+ try {
+ length = rf.length();
+ throw new Exception("Got length from closed RandomAccessFile().");
+ } catch (IOException e) {}
+
+ String filename2 = "/var/tmp/testfile-remove";
+
+ File f2 = new File(filename2);
+ RandomAccessFile rf2 = new RandomAccessFile(filename2, "rw");
+
+ rf2.write(100);
+ rf2.write(buf);
+
+ rf2.close();
+ f2.delete();
+
+ System.out.println("PASSED: RandomAccessFile worked.");
+ System.exit(0);
+ } catch (Exception e) {
+ System.out.println("FAILED: "+e);
+ }
+ }
+}
diff --git a/testsuite/java.io/execute.exp b/testsuite/java.io/execute.exp
new file mode 100644
index 000000000..1092485c0
--- /dev/null
+++ b/testsuite/java.io/execute.exp
@@ -0,0 +1,7 @@
+#
+# Author: Petter Reinholdtsen <pere@td.org.uit.no>
+
+# Load support procs
+load_lib java.exp
+
+test-java-source
diff --git a/testsuite/java.lang/ArrayTest.java b/testsuite/java.lang/ArrayTest.java
new file mode 100644
index 000000000..36eaff406
--- /dev/null
+++ b/testsuite/java.lang/ArrayTest.java
@@ -0,0 +1,100 @@
+
+public class ArrayTest {
+ public static void main (String args[])
+ {
+ BooleanArrayInit();
+ ByteArrayInit();
+ CharArrayInit();
+ ShortArrayInit();
+ IntArrayInit();
+ ArrayName(args);
+ }
+ public static void BooleanArrayInit()
+ {
+ try {
+ boolean val = true;
+ boolean [] x = { true };
+ if (x[0] == val)
+ passed("BooleanArrayInit() boolean[] x = {"+val+"}");
+ else
+ failed("BooleanArrayInit() boolean[] x = {"+val+"}");
+ } catch (Exception e) {
+ failed("BooleanArrayInit() "+e);
+ }
+ }
+ public static void ByteArrayInit()
+ {
+ try {
+ byte val = 42;
+ byte [] x = { 42 };
+ if (x[0] == val)
+ passed("ByteArrayInit() byte[] x = {"+val+"}");
+ else
+ failed("ByteArrayInit() byte[] x = {"+val+"}");
+ } catch (Exception e) {
+ failed("ByteArrayInit() "+e);
+ }
+ }
+ public static void CharArrayInit()
+ {
+ try {
+ char val = 'X';
+ char [] x = { 'X' };
+ if (x[0] == val)
+ passed("CharArrayInit() char[] x = {'"+val+"'}");
+ else
+ failed("CharArrayInit() char[] x = {'"+val+"'}");
+ } catch (Exception e) {
+ failed("CharArrayInit() "+e);
+ }
+ }
+ public static void ShortArrayInit()
+ {
+ try {
+ short val = 42;
+ short [] x = { 42 };
+ if (x[0] == val)
+ passed("ShortArrayInit() short[] x = {"+val+"}");
+ else
+ failed("ShortArrayInit() short[] x = {"+val+"}");
+ } catch (Exception e) {
+ failed("ShortArrayInit() "+e);
+ }
+ }
+ public static void IntArrayInit()
+ {
+ try {
+ int val = 42;
+ int [] x = { 42 };
+ if (x[0] == val)
+ passed("IntArrayInit() int[] x = {"+val+"}");
+ else
+ failed("IntArrayInit() int[] x = {"+val+"}");
+ } catch (Exception e) {
+ failed("IntArrayInit() "+e);
+ }
+ }
+ public static void failed(String s)
+ {
+ if (s != null)
+ System.out.println("FAILED: " + s);
+ else
+ System.out.println("FAILED: ");
+ }
+ public static void passed(String s)
+ {
+ if (s != null)
+ System.out.println("PASSED: " + s);
+ else
+ System.out.println("PASSED: ");
+ }
+ public static void ArrayName(String args[])
+ {
+ try {
+ String name = args.getClass().getName();
+ passed("ArrayName() name="+name);
+ } catch (Exception e) {
+ failed("ArrayName() "+e);
+ }
+ }
+}
diff --git a/testsuite/java.lang/BooleanTest.java b/testsuite/java.lang/BooleanTest.java
new file mode 100644
index 000000000..caee011bf
--- /dev/null
+++ b/testsuite/java.lang/BooleanTest.java
@@ -0,0 +1,177 @@
+/**
+ * Test the Boolean object wrapper class.
+ *
+ * @author Brian Jones (brian.jones@oryxsoft.com)
+ */
+public class BooleanTest
+{
+ Boolean j;
+ String x;
+
+ public static void main (String[] argv)
+ {
+ BooleanTest test = new BooleanTest();
+
+ test.constructorsTest();
+ test.booleanValueTest();
+ test.equalsTest();
+ test.getBooleanTest();
+ test.hashCodeTest();
+ test.toStringTest();
+ test.valueOfTest();
+ test.variablesTest();
+ }
+
+ public void constructorsTest()
+ {
+ j = new Boolean(true); // is true
+ if (j.booleanValue() != true)
+ failed("Boolean(true)");
+ else
+ passed("Boolean(true)");
+
+ j = new Boolean(false); // is false
+ if (j.booleanValue() != false)
+ failed("Boolean(false)");
+ else
+ passed("Boolean(false)");
+
+ j = new Boolean("tRuE"); // is true
+ if (j.booleanValue() != true)
+ failed("Boolean(\"tRuE\")");
+ else
+ passed("Boolean(String)");
+
+ j = new Boolean("brian"); // is false
+ if (j.booleanValue() != false)
+ failed("Boolean(\"brian\")");
+ else
+ passed("Boolean(String)");
+
+ j = new Boolean(null); // is false
+ if (j.booleanValue() != false)
+ failed("Boolean(null)");
+ else
+ passed("Boolean(String)");
+ }
+
+ public void booleanValueTest()
+ {
+ if (Boolean.TRUE.booleanValue() != true)
+ failed("Boolean.booleanValue()");
+ else
+ passed("Boolean.booleanValue()");
+ }
+
+ public void equalsTest()
+ {
+ j = new Boolean("false");
+ if (j.equals(Boolean.FALSE) != true)
+ failed("Boolean.equals(Object)");
+ else
+ passed("Boolean.equals(Object)");
+ }
+
+ public void getBooleanTest()
+ {
+ if (Boolean.getBoolean("BIG_DAWG_TEST"))
+ failed("Boolean.getBoolean(String)");
+ else
+ passed("Boolean.getBoolean(String)");
+ }
+
+ public void hashCodeTest()
+ {
+ j = new Boolean(null); // is false
+ boolean caught = false;
+ try
+ {
+ int i = j.hashCode();
+ }
+ catch (Exception e)
+ {
+ caught = true;
+ failed("Boolean.hashCode()");
+ }
+ if (!caught)
+ passed("Boolean.hashCode()");
+ }
+
+ public void toStringTest()
+ {
+ j = Boolean.TRUE;
+ String x = j.toString();
+ if (x.equals("true") != true)
+ failed("j.toString() where j is Boolean.TRUE");
+ else
+ passed("Boolean.toString()");
+
+ j = Boolean.FALSE;
+ x = j.toString();
+ if (x.equals("false") != true)
+ failed("j.toString() where j is Boolean.FALSE");
+ else
+ passed("Boolean.toString()");
+ }
+
+ public void valueOfTest()
+ {
+ j = Boolean.valueOf("tRUe"); // true
+ if (j.booleanValue() != true)
+ failed("Boolean.valueOf(String)");
+ else
+ passed("Boolean.valueOf(String)");
+
+ j = Boolean.valueOf(null); // false
+ if (j.booleanValue() != false)
+ failed("Boolean.valueOf(null)");
+ else
+ passed("Boolean.valueOf(null)");
+
+ j = Boolean.valueOf("lc"); // false
+ if (j.booleanValue() != false)
+ failed("Boolean.valueOf(String)");
+ else
+ passed("Boolean.valueOf(String)");
+ }
+
+ public void variablesTest()
+ {
+ if (Boolean.TRUE.booleanValue() != true)
+ failed("Boolean.TRUE");
+ else
+ passed("Boolean.TRUE");
+
+ if (Boolean.FALSE.booleanValue() != false)
+ failed("Boolean.FALSE");
+ else
+ passed("Boolean.FALSE");
+
+ x = Boolean.TYPE.getName();
+ if (x.equals("boolean") != true)
+ failed("Boolean.TYPE.getName() is " + x + " != boolean");
+ else
+ passed("Boolean.TYPE.getName() is boolean");
+ }
+
+ public void failed(String s)
+ {
+ if (s != null)
+ System.out.println("FAILED: " + s);
+ else
+ System.out.println("FAILED: ");
+ }
+
+ public void passed(String s)
+ {
+ if (s != null)
+ System.out.println("PASSED: " + s);
+ else
+ System.out.println("PASSED: ");
+ }
+}
+
+
+
+
+
diff --git a/testsuite/java.lang/ByteTest.java b/testsuite/java.lang/ByteTest.java
new file mode 100644
index 000000000..a00f2a91a
--- /dev/null
+++ b/testsuite/java.lang/ByteTest.java
@@ -0,0 +1,270 @@
+/**
+ * Test the Byte object wrapper class.
+ *
+ * @author Brian Jones (brian.jones@oryxsoft.com)
+ */
+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 void constructorsTest()
+ {
+ byte b = 1;
+ Byte obj1 = null, obj2 = null;
+ String y;
+
+ obj1 = new Byte(b);
+ y = obj1.toString();
+ if (y.equals("1") != true)
+ failed("Byte(byte)");
+ else
+ passed("Byte(byte)");
+
+ 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 void byteValueTest()
+ {
+ byte b = 1;
+ Byte obj = new Byte(b);
+ if (obj.byteValue() == b)
+ passed("Byte.byteValue()");
+ else
+ failed("Byte.byteValue()");
+ }
+
+ 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 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 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");
+
+ obj2 = obj1;
+ if (obj1.equals(obj2))
+ passed("Byte.equals() 1 == 1");
+ else
+ failed("Byte.equals() 1 == 1");
+ }
+
+ 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 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 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 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 void parseByteTest()
+ {
+ byte b = Byte.parseByte("1");
+ if (b == (byte)1)
+ passed("Byte.parseByte(String)");
+ else
+ failed("Byte.parseByte(String)");
+
+ b = Byte.parseByte("-4", 10);
+ if (b == (byte)-4)
+ passed("Byte.parseByte(String, int)");
+ else
+ failed("Byte.parseByte(String, int)");
+ }
+
+ 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 void toStringTest()
+ {
+ Byte obj = new Byte((byte)-2);
+ String x = obj.toString();
+ if (x.equals("-2"))
+ passed("Byte.toString()");
+ else
+ failed("Byte.toString()");
+
+ x = Byte.toString((byte)-2);
+ if (x.equals("-2"))
+ passed("Byte.toString(byte)");
+ else
+ failed("Byte.toString(byte)");
+ }
+
+ 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)");
+
+ obj1 = Byte.valueOf("2");
+ if (obj1.intValue() == obj2.intValue())
+ passed("Byte.valueOf(String)");
+ else
+ failed("Byte.valueOf(String)");
+ }
+
+ public void variables()
+ {
+ byte min = Byte.MIN_VALUE;
+ byte max = Byte.MAX_VALUE;
+
+ if (min == (byte)-128)
+ passed("Byte.MIN_VALUE is -128");
+ else
+ failed("Byte.MIN_VALUE is " + min + " != -128");
+
+ if (max == (byte)127)
+ passed("Byte.MIN_VALUE is 127");
+ else
+ failed("Byte.MIN_VALUE is " + min + " != 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 void typeInstance()
+ {
+ 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() + "'");
+ }
+ }
+
+ public void failed(String s)
+ {
+ if (s != null)
+ System.out.println("FAILED: " + s);
+ else
+ System.out.println("FAILED: ");
+ }
+
+ public void passed(String s)
+ {
+ if (s != null)
+ System.out.println("PASSED: " + s);
+ else
+ System.out.println("PASSED: ");
+ }
+}
diff --git a/testsuite/java.opstack/LeftBehind.j b/testsuite/java.opstack/LeftBehind.j
new file mode 100644
index 000000000..30a82c4b3
--- /dev/null
+++ b/testsuite/java.opstack/LeftBehind.j
@@ -0,0 +1,64 @@
+;
+; LeftBehind.j - contrived test to see how japhar reacts to
+; stuff left on the stack after a method returns.
+.class public LeftBehind
+.super java/lang/Object
+
+.method public static test()I
+ .limit stack 10 ; up to 10 items can be pushed
+
+ ; push some ints.
+ bipush 1
+ bipush 2
+ bipush 3
+ bipush 4
+ bipush 5
+ ; then push some strings.
+ ldc "6th item"
+ ldc "7th item"
+
+ bipush 5
+
+ ; now push our return value
+ bipush 9
+
+ ireturn
+.end method
+
+.method public static main([Ljava/lang/String;)V
+ .limit stack 3 ; up to three items can be pushed
+
+ ; we push a value onto the stack, and
+ ; then check to see that only one item (the return
+ ; value from the test() method) is on the stack on top
+ ; of it.
+ bipush 8
+
+ invokestatic LeftBehind/test()I
+
+ pop ; get rid of the return value
+ bipush 8
+ isub
+
+ ifeq pass
+
+fail:
+ ; push System.out onto the stack
+ getstatic java/lang/System/out Ljava/io/PrintStream;
+
+ ldc "FAILED:"
+
+ invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
+ bipush 0
+ invokestatic java/lang/System/exit(I)V
+
+pass:
+ ; push System.out onto the stack
+ getstatic java/lang/System/out Ljava/io/PrintStream;
+
+ ldc "PASSED:"
+
+ invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
+ bipush 0
+ invokestatic java/lang/System/exit(I)V
+.end method
diff --git a/testsuite/java.opstack/execute.exp b/testsuite/java.opstack/execute.exp
new file mode 100644
index 000000000..1092485c0
--- /dev/null
+++ b/testsuite/java.opstack/execute.exp
@@ -0,0 +1,7 @@
+#
+# Author: Petter Reinholdtsen <pere@td.org.uit.no>
+
+# Load support procs
+load_lib java.exp
+
+test-java-source