diff options
Diffstat (limited to 'testsuite')
32 files changed, 1435 insertions, 0 deletions
diff --git a/testsuite/java.lang/ClassForNameTest.java b/testsuite/java.lang/ClassForNameTest.java new file mode 100644 index 000000000..c69df9328 --- /dev/null +++ b/testsuite/java.lang/ClassForNameTest.java @@ -0,0 +1,25 @@ +public class ClassForNameTest +{ + public static void main(String args[]) { + Class c; + /* test for both success and failure */ + + try { + c = Class.forName("ClassForNameTest"); + } + catch (Exception e) { + System.out.println("FAILED: Couldn't find ClassForNameTest."); + System.exit(0); + } + + try { + c = Class.forName("ClazzForNameT3st"); + } + catch (Exception e) { + System.out.println("PASSED: passed both success and failure cases for Class.forName"); + System.exit(0); + } + + System.out.println("FAILED: Didn't raise exception for incorrect class name."); + } +} diff --git a/testsuite/java.lang/ExceptionTest.java b/testsuite/java.lang/ExceptionTest.java new file mode 100644 index 000000000..7a464db43 --- /dev/null +++ b/testsuite/java.lang/ExceptionTest.java @@ -0,0 +1,21 @@ +public class ExceptionTest +{ + static int foo() throws ArrayIndexOutOfBoundsException { + int f[] = new int[10]; + + return f[26]; + } + + public static void main (String args[]) { + int f; + + try { + f = foo(); + } + catch (ArrayIndexOutOfBoundsException e) { + System.out.println("PASSED: " + e.toString()); + } catch (Exception e) { + System.out.println("FAILED: " + e.toString()); + } + } +} diff --git a/testsuite/java.lang/FloatingDecimalTest.java b/testsuite/java.lang/FloatingDecimalTest.java new file mode 100644 index 000000000..f49ef7b88 --- /dev/null +++ b/testsuite/java.lang/FloatingDecimalTest.java @@ -0,0 +1,19 @@ +public class FloatingDecimalTest +{ + public static void main(String args[]) { +/* + try { +*/ + double d = 1.0; + String result; + result = "Double is " +d + " and kicking"; + System.out.println("PASSED: "+result); +/* + } + catch (Exception e) + { + System.out.println("FAILED: exception " + e.toString()); + } +*/ + } +} diff --git a/testsuite/java.lang/IsInstanceTest.java b/testsuite/java.lang/IsInstanceTest.java new file mode 100644 index 000000000..f5a828a23 --- /dev/null +++ b/testsuite/java.lang/IsInstanceTest.java @@ -0,0 +1,32 @@ +class IsInstanceTest extends Thread implements Cloneable +{ + static void main(String args[]) + { + IsInstanceTest test = new IsInstanceTest(); + + if (test instanceof java.lang.Object) + pass("IsInstanceTest is instance of java.lang.Object"); + else + fail("IsInstanceTest is not instance of java.lang.Object"); + + if (test instanceof java.lang.Cloneable) + pass("IsInstanceTest is instance of java.lang.Cloneable"); + else + fail("IsInstanceTest is not instance of java.lang.Cloneable"); + + if (test instanceof java.lang.Runnable) + pass("IsInstanceTest is instance of java.lang.Runnable"); + else + fail("IsInstanceTest is not instance of java.lang.Runnable"); + + + } + static void pass(String message) + { + System.out.println("PASSED: "+message); + } + static void fail(String message) + { + System.out.println("FAILED: "+message); + } +} diff --git a/testsuite/java.lang/JoinTest.java b/testsuite/java.lang/JoinTest.java new file mode 100644 index 000000000..5d5d62d20 --- /dev/null +++ b/testsuite/java.lang/JoinTest.java @@ -0,0 +1,77 @@ +public class JoinTest + implements Runnable +{ + public static int count = 0; + + void send() + throws Exception + { + Thread.sleep(2000); + System.out.println("PASSED: Sender completed"); + } + void receive() + throws Exception + { + synchronized(this) { + notifyAll(); + } + + Thread.sleep(5000); + count++; + System.out.println("PASSED: Receiver completed"); + } + + public void run() + { + String name = Thread.currentThread().getName(); + if (name.equals("timer")) { + try { + Thread.sleep(10000); + } catch (InterruptedException e){} + System.out.println("FAILED: timer triggered"); + System.exit(1); + } + try { + receive(); + } catch (Exception e) { + System.out.println("FAILED: receiver: " + e); + System.exit(1); + } + } + public static void main(String args[]) + { + try { + JoinTest sender = + new JoinTest(); + JoinTest receiver = + new JoinTest(); + Thread receiver_thread = new Thread(receiver); + + /* Make sure the test terminates even if it hangs on network */ + JoinTest timer = new JoinTest(); + Thread timer_thread = new Thread(timer, "timer"); + timer_thread.start(); + + synchronized(receiver) { + receiver_thread.start(); + receiver.wait(); + } + try { + sender.send(); + } catch (Exception e) { + System.out.println("FAILED: sender: " + e); + System.exit(1); + } + receiver_thread.join(); + + if (0 == count) + throw new Exception("Nothing received"); + + System.out.println("PASSED: Join send/receive count="+count); + System.exit(0); + } catch (Exception e) { + System.out.println("FAILED: " + e); + System.exit(1); + } + } +} diff --git a/testsuite/java.lang/LongFieldTest.java b/testsuite/java.lang/LongFieldTest.java new file mode 100644 index 000000000..dc5be6151 --- /dev/null +++ b/testsuite/java.lang/LongFieldTest.java @@ -0,0 +1,12 @@ +public class LongFieldTest +{ + static long field; + + public static void main(String args[]) + { + field = 1L; + + if (field == 1) + System.out.println("PASSED: field = " + field); + } +} diff --git a/testsuite/java.lang/NewInstanceTest.java b/testsuite/java.lang/NewInstanceTest.java new file mode 100644 index 000000000..845bb42cc --- /dev/null +++ b/testsuite/java.lang/NewInstanceTest.java @@ -0,0 +1,24 @@ +public class NewInstanceTest +{ + public NewInstanceTest() { + static_field = 1; + } + + public static void main(String args[]) { + try { + Class cls = Class.forName("NewInstanceTest"); + Object instance = cls.newInstance(); + + if (static_field == 1) + System.out.println("PASSED: static_field = " + static_field); + else + System.out.println("FAILED: static_field = " + static_field); + } + catch (Exception e) + { + System.out.println("FAILED: exception " + e.toString()); + } + } + + public static int static_field; +} diff --git a/testsuite/java.lang/NullcastTest.java b/testsuite/java.lang/NullcastTest.java new file mode 100644 index 000000000..75588d6fb --- /dev/null +++ b/testsuite/java.lang/NullcastTest.java @@ -0,0 +1,20 @@ +import java.lang.*; + +public class NullcastTest +{ + static String retString(String str1, String str2) + { + return str1; + } + public static void main (String args[]) { + try { + + String tmp = retString((String) null, (String)null); + + System.out.println("PASSED: (String)null"); + System.exit(0); + } catch (Exception e) { + System.out.println("FAILED: "+e); + } + } +} diff --git a/testsuite/java.lang/OutOfMemoryErrorTest.java b/testsuite/java.lang/OutOfMemoryErrorTest.java new file mode 100644 index 000000000..2dd6b1580 --- /dev/null +++ b/testsuite/java.lang/OutOfMemoryErrorTest.java @@ -0,0 +1,64 @@ +import java.util.Vector; + +/** + * Under JavaSoft's VM they arbitarily limit the amount of memory + * a Java application can use (though this can be overridden). The + * point here is to check to see whether or not an application being + * run by Japhar will ever get the OutOfMemoryError or not when resources + * are scarce. --brian + */ +public class OutOfMemoryErrorTest +{ + public static void main(String[] argv) + { + Vector v = null; + Runtime r = null; + long free = 0, total = 0; + // quickly approach memory limit 1M at a time + try { + r = Runtime.getRuntime(); + v = new Vector(); + while(true) + { + v.addElement(new byte[1048576]); + } + } + // out of memory error + catch (OutOfMemoryError oomerr1) + { + // slowly encroach on memory limit 2 bytes+ at a time + try { + while(true) + { + v.addElement(new byte[2]); + } + } + // out of memory error + catch (OutOfMemoryError oomerr2) + { + if (r != null) + { + free = r.freeMemory(); + total = r.totalMemory(); + v = null; + r.gc(); +// System.out.println("free = " + free); +// System.out.println("total = " + total); + System.out.println("PASSED: "); + } + else + System.out.println("FAILED: runtime unknown"); + } + } + // generic error + catch (Error err) + { + System.out.println("FAILED: unexpected error"); + } + // generic exception + catch (Exception e) + { + System.out.println("FAILED: unexpected exception"); + } + } +} diff --git a/testsuite/java.lang/StringTest.java b/testsuite/java.lang/StringTest.java new file mode 100644 index 000000000..cd9d83d55 --- /dev/null +++ b/testsuite/java.lang/StringTest.java @@ -0,0 +1,24 @@ +/* + * Aaron M. Renn reported a bug in Japhar having string length 17 for + * this string + */ + +public class StringTest +{ + public static void + main(String[] argv) + { + UnicodeStringLength(); + } + static void UnicodeStringLength() + { + String str = "a-->\u01FF\uA000\u6666\u0200RRR"; + int len = str.length(); + if (11 == len) { + System.out.println("PASSED: " + str + " has len=" +str.length()); + } else { + System.out.println("FAILED: " + str + + " has len=" +str.length() + " != 11"); + } + } +} diff --git a/testsuite/java.lang/SyncronizedTest.java b/testsuite/java.lang/SyncronizedTest.java new file mode 100644 index 000000000..61115efaa --- /dev/null +++ b/testsuite/java.lang/SyncronizedTest.java @@ -0,0 +1,59 @@ +public class SyncronizedTest + implements Runnable +{ + public static int count = 0; + String _name; + + public SyncronizedTest(String name) + { + _name = name; + } + + public void run() + { + if (_name.equals("timer")) { + try { + Thread.sleep(10000); + } catch (InterruptedException e){} + System.out.println("FAILED: timer triggered"); + System.exit(1); + } + try { + count++; + + synchronized(this) { + notifyAll(); + } + } catch (Exception e) { + System.out.println("FAILED: receiver: " + e); + System.exit(1); + } + } + public static void main(String args[]) + { + try { + SyncronizedTest tester = new SyncronizedTest("tester"); + Thread tester_thread = new Thread(tester); + + SyncronizedTest timer = new SyncronizedTest("timer"); + Thread timer_thread = new Thread(timer); + timer_thread.start(); + + synchronized(tester) { + tester_thread.start(); + tester.wait(); + } + + if (0 == count) + throw new Exception("Thread did not run."); + + tester_thread.join(); + + System.out.println("PASSED: count="+count); + System.exit(0); + } catch (Exception e) { + System.out.println("FAILED: " + e); + System.exit(1); + } + } +} diff --git a/testsuite/java.lang/TestCasts.java b/testsuite/java.lang/TestCasts.java new file mode 100644 index 000000000..4ee0abf78 --- /dev/null +++ b/testsuite/java.lang/TestCasts.java @@ -0,0 +1,477 @@ +/* Written by Artur Biesiadowski <abies@pg.gda.pl> */ + +/* + This class test basic 4 conversion types and compares results to ready ones, done + on sure VM (suns JDK). Conversions are + (obj instanceof clazz) + (clazz)obj + clazz.isInstance(obj) + clazz1.isAssignableFrom(clazz2); + + Hopefully all needed cases are covered. If you want to add object just put it + into objs table. If you want to add class, you need to add it to both cls and to + testCode method. Of course you need to regenerate results after that. + */ + + +/* + You can copy/modify/use this file for any purposes, as long as you do not delete + my name from top of that file. Of course you can add your own below that :) + */ + + +import java.io.*; + +interface I1 {} +interface I2 {} +interface I3 extends I2{} +class A1 implements I1 {} +class AB12 extends A1 implements I2 {} +class ABC12 extends AB12 {} +class D3 implements I3 {} + +public class TestCasts +{ + + public Object objs[] = + { + null, + new Object(), + new A1(), + new AB12(), + new ABC12(), + new D3(), + new A1[1], + new AB12[1], + new ABC12[1], + new D3[1], + new I1[1], + new I2[1], + new I3[1], + new int[1], + new A1[1][1], + new AB12[1][1], + new I1[1][1] + }; + + public Class cls[] = + { + Object.class, + A1.class, + AB12.class, + ABC12.class, + D3.class, + I1.class, + I2.class, + I3.class, + Cloneable.class, + Serializable.class, + A1[].class, + AB12[].class, + ABC12[].class, + D3[].class, + I1[].class, + I2[].class, + I3[].class, + int[].class, + A1[][].class, + AB12[][].class, + I1[][].class + }; + + java.util.Vector results = new java.util.Vector(1000); + boolean verbose = false; + boolean generate = false; + String filename = "TestCasts-results.txt"; + + public static void main(String argv[] ) + { + TestCasts tc = new TestCasts(); + if ( argv.length > 0 ) + { + int i; + for ( i =0; i < argv.length;i++ ) + { + if ( argv[i].equals("-g") ) + { + tc.generate = true; + } + else if ( argv[i].equals("-v") ) + { + tc.verbose = true; + } + else if ( argv[i].equals("-f") ) + { + i++; + if ( i > argv.length ) + { + System.out.println("You need to specify filename after -f"); + System.exit(1); + } + tc.filename = argv[i]; + } + else + { + System.out.println( "Options are: -v -g -f file"); + System.out.println( "[-v] verbose "); + System.out.println( "[-g] generate result table"); + System.out.println( "[-f file] read/write tests from/to file (default "+tc.filename+")"); + System.exit(1); + } + } + } + + + tc.test(); + //System.out.println(tc.results); + System.out.println( "Performed " + tc.counter + " tests"); + if ( tc.generate ) + System.out.println( "True: " + tc.genTrue + "\tfalse: " + tc.genFalse); + else + { + System.out.println( "Passed: " + tc.passed + "\tfailed: " + tc.failed); + if (tc.failed == 0 ) + System.out.println("PASSED: all cast tests"); + } + } + + + public final void test() + { + if (!generate) + readResultsFromFile(); + + int i; + int j; + for ( i=0; i < objs.length; i++ ) + { + for ( j=0; j < cls.length; j++ ) + { + reportClIsInst(objs[i], cls[j], cls[j].isInstance(objs[i]) ); + } + } + + for (i=0; i < objs.length; i++ ) + { + testCode(objs[i]); + } + + for ( i=0; i < cls.length; i++ ) + { + for ( j=0; j < cls.length; j++ ) + { + reportClIsAssign(cls[i], cls[j], cls[i].isAssignableFrom(cls[j])); + } + } + + if ( generate ) + writeResultsToFile(); + } + + + public final void testCode(Object o) + { + + reportInstanceof(o, Object.class, (o instanceof Object) ); + try + { + Object r1 = (Object) o; + reportCast(o, Object.class, true ); + } catch (ClassCastException e) { + reportCast(o,Object.class, false ); + } + + reportInstanceof(o, A1.class, (o instanceof A1) ); + try + { + A1 r1 = (A1) o; + reportCast(o, A1.class, true ); + } catch (ClassCastException e) { + reportCast(o,A1.class, false ); + } + reportInstanceof(o, AB12.class, (o instanceof AB12) ); + try + { + AB12 r1 = (AB12) o; + reportCast(o, AB12.class, true ); + } catch (ClassCastException e) { + reportCast(o,AB12.class, false ); + } + reportInstanceof(o, ABC12.class, (o instanceof ABC12) ); + try + { + ABC12 r1 = (ABC12) o; + reportCast(o, ABC12.class, true ); + } catch (ClassCastException e) { + reportCast(o,ABC12.class, false ); + } + reportInstanceof(o, D3.class, (o instanceof D3) ); + try + { + D3 r1 = (D3) o; + reportCast(o, D3.class, true ); + } catch (ClassCastException e) { + reportCast(o,D3.class, false ); + } + reportInstanceof(o, I1.class, (o instanceof I1) ); + try + { + I1 r1 = (I1) o; + reportCast(o, I1.class, true ); + } catch (ClassCastException e) { + reportCast(o,I1.class, false ); + } + reportInstanceof(o, I2.class, (o instanceof I2) ); + try + { + I2 r1 = (I2) o; + reportCast(o, I2.class, true ); + } catch (ClassCastException e) { + reportCast(o,I2.class, false ); + } + reportInstanceof(o, I3.class, (o instanceof I3) ); + try + { + I3 r1 = (I3) o; + reportCast(o, I3.class, true ); + } catch (ClassCastException e) { + reportCast(o,I3.class, false ); + } + reportInstanceof(o, Cloneable.class, (o instanceof Cloneable) ); + try + { + Cloneable r1 = (Cloneable) o; + reportCast(o, Cloneable.class, true ); + } catch (ClassCastException e) { + reportCast(o,Cloneable.class, false ); + } + + reportInstanceof(o, Serializable.class, (o instanceof Serializable) ); + try + { + Serializable r1 = (Serializable) o; + reportCast(o, Serializable.class, true ); + } catch (ClassCastException e) { + reportCast(o,Serializable.class, false ); + } + reportInstanceof(o, A1[].class, (o instanceof A1[]) ); + try + { + A1[] r1 = (A1[]) o; + reportCast(o, A1[].class, true ); + } catch (ClassCastException e) { + reportCast(o,A1[].class, false ); + } + + reportInstanceof(o, AB12[].class, (o instanceof AB12[]) ); + try + { + AB12[] r1 = (AB12[]) o; + reportCast(o, AB12[].class, true ); + } catch (ClassCastException e) { + reportCast(o,AB12[].class, false ); + } + reportInstanceof(o, ABC12[].class, (o instanceof ABC12[]) ); + try + { + ABC12[] r1 = (ABC12[]) o; + reportCast(o, ABC12[].class, true ); + } catch (ClassCastException e) { + reportCast(o,ABC12[].class, false ); + } + reportInstanceof(o, D3[].class, (o instanceof D3[]) ); + try + { + D3[] r1 = (D3[]) o; + reportCast(o, D3[].class, true ); + } catch (ClassCastException e) { + reportCast(o,D3[].class, false ); + } + reportInstanceof(o, I1[].class, (o instanceof I1[]) ); + try + { + I1[] r1 = (I1[]) o; + reportCast(o, I1[].class, true ); + } catch (ClassCastException e) { + reportCast(o,I1[].class, false ); + } + reportInstanceof(o, I2[].class, (o instanceof I2[]) ); + try + { + I2[] r1 = (I2[]) o; + reportCast(o, I2[].class, true ); + } catch (ClassCastException e) { + reportCast(o,I2[].class, false ); + } + + reportInstanceof(o, I3[].class, (o instanceof I3[]) ); + try + { + I3[] r1 = (I3[]) o; + reportCast(o, I3[].class, true ); + } catch (ClassCastException e) { + reportCast(o,I3[].class, false ); + } + + reportInstanceof(o, int[].class, (o instanceof int[]) ); + try + { + int[] r1 = (int[]) o; + reportCast(o, int[].class, true ); + } catch (ClassCastException e) { + reportCast(o,int[].class, false ); + } + + reportInstanceof(o, A1[][].class, (o instanceof A1[][]) ); + try + { + A1[][] r1 = (A1[][]) o; + reportCast(o, A1[][].class, true ); + } catch (ClassCastException e) { + reportCast(o,A1[][].class, false ); + } + reportInstanceof(o, AB12[][].class, (o instanceof AB12[][]) ); + try + { + AB12[][] r1 = (AB12[][]) o; + reportCast(o, AB12[][].class, true ); + } catch (ClassCastException e) { + reportCast(o,AB12[][].class, false ); + } + reportInstanceof(o, I1[][].class, (o instanceof I1[][]) ); + try + { + I1[][] r1 = (I1[][]) o; + reportCast(o, I1[][].class, true ); + } catch (ClassCastException e) { + reportCast(o,I1[][].class, false ); + } + + } + + int counter = 0; + int passed = 0; + int failed = 0; + int genTrue = 0; + int genFalse =0; + + public final boolean result(boolean b ) + { + counter++; + if ( generate ) + { + if (b ) + { + genTrue++; + results.addElement(Boolean.TRUE); + } + else + { + genFalse++; + results.addElement(Boolean.FALSE); + } + return true; + } + else + { + if ( ((Boolean)results.elementAt(counter-1)).booleanValue() != b ) + { + failed++; + return false; + } + else + { + passed++; + return true; + } + } + + } + + public final void reportClIsInst(Object obj, Class cl, boolean b ) + { + if ( result(b) ) + { + if ( verbose ) + System.out.println("PASSED: "+obj +"\tis\t"+ cl + "\t?" + b); + } + else + { + System.out.println("FAILED: " + cl + ".isInstance(" + obj + ") is\t" + b ); + } + } + + public final void reportClIsAssign( Class c1, Class c2, boolean b ) + { + if ( result(b) ) + { + if (verbose) + System.out.println("PASSED: "+c1 + "\tisAssignableFrom\t" + c2 + "\t?\t" + b); + } + else + { + System.out.println("FAILED: " + c1 + ".isAssigableFrom(" + c2 + ") is " + b); + } + } + + public final void reportInstanceof( Object obj, Class cl, boolean b ) + { + if ( result(b) ) + { + if ( verbose ) + System.out.println("PASSED: "+obj +"\tinstanceof\t"+ cl + "\t?" + b); + } + else + { + System.out.println("FAILED: (" + obj + "instanceof\t" + cl + ")\tis\t" + b ); + } + } + + public final void reportCast( Object obj, Class cl, boolean b ) + { + if ( result(b) ) + { + if ( verbose ) + System.out.println("PASSED: "+obj +"\tcastto \t"+ cl + "\t?" + b); + } + else + { + System.out.println("FAILED: " + obj + "\tcastto \t" + cl + "\tis\t" + b ); + } + } + + public final void readResultsFromFile() + { + try{ + int i; + FileInputStream fin = new FileInputStream(filename); + while ( (i=fin.read()) != -1 ) + { + results.addElement( i==1 ? Boolean.TRUE : Boolean.FALSE ); + } + } catch (IOException e ) + { + System.out.println("Cannot read from file " + filename); + System.out.println(e); + System.exit(1); + } + } + + public final void writeResultsToFile() + { + try{ + int i; + FileOutputStream fos = new FileOutputStream(filename); + for ( i=0; i < counter; i++ ) + { + fos.write( ((Boolean)results.elementAt(i)).booleanValue() ? 1 : 0 ); + } + fos.close(); + } catch (IOException e ) + { + System.out.println("Cannot read from file " + filename); + System.out.println(e); + System.exit(1); + } + } +} diff --git a/testsuite/java.lang/ThreadTest.java b/testsuite/java.lang/ThreadTest.java new file mode 100644 index 000000000..cade822ec --- /dev/null +++ b/testsuite/java.lang/ThreadTest.java @@ -0,0 +1,48 @@ +import java.lang.*; + +/* Simple producer/consumer thread test. */ + +public class ThreadTest implements Runnable { + + static String threadName = "Running thread"; + static int count = 0; + static int max = 4; // XXX Seem to fail when >4 on kaffe 0.9.0 + + public void run() { + if (! Thread.currentThread().isAlive() ) { + System.out.println("FAILED: isAlive() false in new thread!"); + } else { + System.out.println("PASSED: isAlive() working in new thread"); + } + while (0 <= count && count <= max) { + count ++; + } + } + + public static void main (String args[]) { + try { + if (! Thread.currentThread().isAlive() ) { + System.out.println("FAILED: isAlive() false in initial thread!"); + } else { + System.out.println("PASSED: isAlive() working in initial thread"); + } + ThreadTest test = new ThreadTest(); + + Thread testThread = new Thread(test, threadName); + + testThread.setDaemon(true); + testThread.start(); + + Thread.currentThread().sleep(3000); + + if (count < max) { + System.out.println("FAILED: unable to run new thread"); + } else { + System.out.println("PASSED: Theads worked"); + } + System.exit(0); + } catch (Exception e) { + System.out.println("FAILED: "+e); + } + } +} diff --git a/testsuite/java.lang/execute.exp b/testsuite/java.lang/execute.exp new file mode 100644 index 000000000..1092485c0 --- /dev/null +++ b/testsuite/java.lang/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.net/DatagramSocketSendReceiveTest.java b/testsuite/java.net/DatagramSocketSendReceiveTest.java new file mode 100644 index 000000000..b1614d23e --- /dev/null +++ b/testsuite/java.net/DatagramSocketSendReceiveTest.java @@ -0,0 +1,114 @@ +import java.net.*; + +/* + * Start one thread for receiving a packet, wait for it to set up, + * send a packet to it, and wait until it completes. Compare the + * packet to make sure it came thru without errors. + */ + +public class DatagramSocketSendReceiveTest + implements Runnable +{ + public static final int port = 4000 + (int)(java.lang.Math.random() * 1000); + public static final String message = "hello"; + public static int count = 0; + public static String received; + + void send() + throws Exception + { + DatagramSocket sender = new DatagramSocket(); + InetAddress local = sender.getLocalAddress(); + byte []message_bytes = message.getBytes(); + + DatagramPacket packet = new DatagramPacket(message_bytes, + message_bytes.length, + local, port); + + sender.send(packet); + sender.close(); + } + void receive() + throws Exception + { + DatagramSocket socket = new DatagramSocket(port); + socket.setSoTimeout(10); + + byte[] buffer = new byte[100]; + DatagramPacket packet = new DatagramPacket(buffer, buffer.length); + + synchronized(this) { + notifyAll(); + } + + socket.receive(packet); + socket.close(); + + received = new String(buffer, 0, packet.getLength()); + + count++; + if ( message.length() != received.length() ) + throw new Exception("Receved "+ received.length()+ + " bytes but sent "+message.length() + " bytes"); + + if ( ! message.equals(received) ) + throw new Exception("Receved \""+ received+ + "\" but sent \""+message + "\""); + + } + + public void run() + { + String name = Thread.currentThread().getName(); + if (name.equals("timer")) { + try { + Thread.sleep(10000); + } catch (InterruptedException e){} + System.out.println("FAILED: timer triggered"); + System.exit(0); + } + try { + receive(); + } catch (Exception e) { + System.out.println("FAILED: receiver: " + e); + System.exit(0); + } + } + public static void main(String args[]) + { + try { + DatagramSocketSendReceiveTest sender = + new DatagramSocketSendReceiveTest(); + DatagramSocketSendReceiveTest receiver = + new DatagramSocketSendReceiveTest(); + Thread receiver_thread = new Thread(receiver); + + /* Make sure the test terminates even if it hangs on network */ + DatagramSocketSendReceiveTest timer = new DatagramSocketSendReceiveTest(); + Thread timer_thread = new Thread(timer, "timer"); + timer_thread.start(); + + synchronized(receiver) { + receiver_thread.start(); + receiver.wait(); + } + try { + sender.send(); + } catch (Exception e) { + System.out.println("FAILED: sender: " + e); + System.exit(0); + } + receiver_thread.join(); + + if (0 == count) + throw new Exception("Nothing received"); + + System.out.println("PASSED: DatagramSocket send/receive count="+count+ + " message="+received); + System.exit(0); + } catch (Exception e) { + System.out.println("FAILED: " + e); + System.exit(0); + } + } +} diff --git a/testsuite/java.net/DatagramSocketTest.java b/testsuite/java.net/DatagramSocketTest.java new file mode 100644 index 000000000..4ee0d4990 --- /dev/null +++ b/testsuite/java.net/DatagramSocketTest.java @@ -0,0 +1,23 @@ +import java.net.*; + +public class DatagramSocketTest +{ + public static void main(String args[]) + { + try { + DatagramSocket socket = new DatagramSocket(); + + InetAddress local = socket.getLocalAddress(); + + int port = socket.getLocalPort(); + + socket.setSoTimeout(socket.getSoTimeout()); + + socket.close(); + + System.out.println("PASSED: new DatagramSocket()"); + } catch (Exception e) { + System.out.println("FAILED: " + e); + } + } +} diff --git a/testsuite/java.net/SocketSendReceiveTest.java b/testsuite/java.net/SocketSendReceiveTest.java new file mode 100644 index 000000000..15ab983a4 --- /dev/null +++ b/testsuite/java.net/SocketSendReceiveTest.java @@ -0,0 +1,113 @@ +import java.net.*; +import java.io.*; + +/* + * Start one thread for receiving a packet, wait for it to set up, + * send a packet to it, and wait until it completes. Compare the + * packet to make sure it came thru without errors. + */ + +public class SocketSendReceiveTest + implements Runnable +{ + public static final int port = 4000 + (int)(java.lang.Math.random() * 2000); + public static final String message = "hello"; + public static int count = 0; + public static String received; + + void send() + throws Exception + { + InetAddress local = InetAddress.getLocalHost(); + Socket sender = new Socket(local, port); + byte []message_bytes = message.getBytes(); + + DataOutputStream out = new DataOutputStream(sender.getOutputStream()); + out.write(message_bytes, 0, message_bytes.length); + out.flush(); + sender.close(); + } + void receive() + throws Exception + { + ServerSocket socket = new ServerSocket(port); + + synchronized(this) { + notifyAll(); + } + + Socket connection = socket.accept(); + DataInputStream in = new DataInputStream(connection.getInputStream()); + + byte[] buffer = new byte[100]; + + int length = in.read(buffer); + + connection.close(); + socket.close(); + + received = new String(buffer, 0, length); + + count++; + if ( message.length() != received.length() ) + throw new Exception("Receved "+ received.length()+ + " bytes but sent "+message.length() + " bytes"); + + if ( ! message.equals(received) ) + throw new Exception("Receved \""+ received+ + "\" but sent \""+message + "\""); + } + + public void run() + { + String name = Thread.currentThread().getName(); + if (name.equals("timer")) { + try { + Thread.sleep(10000); + } catch (InterruptedException e){} + System.out.println("FAILED: timer triggered"); + System.exit(0); + } + try { + receive(); + } catch (Exception e) { + System.out.println("FAILED: receiver (port "+port + "): " + e); + System.exit(0); + } + } + public static void main(String args[]) + { + try { + SocketSendReceiveTest sender = new SocketSendReceiveTest(); + SocketSendReceiveTest receiver = new SocketSendReceiveTest(); + Thread receiver_thread = new Thread(receiver); + + /* Make sure the test terminates even if it hangs on network */ + SocketSendReceiveTest timer = new SocketSendReceiveTest(); + Thread timer_thread = new Thread(timer, "timer"); + timer_thread.start(); + + synchronized(receiver) { + receiver_thread.start(); + receiver.wait(); + } + try { + sender.send(); + } catch (Exception e) { + System.out.println("FAILED: receiver (port "+port + "): " + e); + System.exit(0); + } + receiver_thread.join(); + + if (0 == count) + throw new Exception("Nothing received"); + + System.out.println("PASSED: Socket send/receive count="+count+ + " message="+received); + System.exit(0); + } catch (Exception e) { + System.out.println("FAILED: " + e); + System.exit(0); + } + } +} diff --git a/testsuite/java.net/SocketTest.java b/testsuite/java.net/SocketTest.java new file mode 100644 index 000000000..78a367b4d --- /dev/null +++ b/testsuite/java.net/SocketTest.java @@ -0,0 +1,34 @@ +import java.net.*; + +public class SocketTest +{ + public static void main(String args[]) + { + try { + Socket socket = new Socket("www.hungry.com", 80); + + InetAddress remote = socket.getInetAddress(); + InetAddress local = socket.getLocalAddress(); + + int rport = socket.getPort(); + int lport = socket.getLocalPort(); + + socket.setSoTimeout(socket.getSoTimeout()); + socket.setTcpNoDelay(socket.getTcpNoDelay()); + int linger = socket.getSoLinger(); + if (-1 != linger) + socket.setSoLinger(true, linger); + else + socket.setSoLinger(false, 0); + + String socketString = socket.toString(); + if (null == socketString) + throw new Exception("toString() failed"); + + socket.close(); + System.out.println("PASSED: new Socket()" + socketString); + } catch (Exception e) { + System.out.println("FAILED: " + e); + } + } +} diff --git a/testsuite/java.net/URLTest.java b/testsuite/java.net/URLTest.java new file mode 100644 index 000000000..026ea12b5 --- /dev/null +++ b/testsuite/java.net/URLTest.java @@ -0,0 +1,23 @@ +import java.net.*; +import java.io.*; + +public class URLTest +{ + public static void main(String args[]) + { + try { + URL url = new URL("http://www.hungry.com/"); + InputStream stream = url.openStream(); + + int size = 0; + + while (-1 != stream.read()) { size++; } + + stream.close(); + + System.out.println("PASSED: new URL() size=" + size ); + } catch (Exception e) { + System.out.println("FAILED: " + e); + } + } +} diff --git a/testsuite/java.net/execute.exp b/testsuite/java.net/execute.exp new file mode 100644 index 000000000..1092485c0 --- /dev/null +++ b/testsuite/java.net/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.sun.awt/FrameMenuTest.java b/testsuite/java.sun.awt/FrameMenuTest.java new file mode 100644 index 000000000..1ccc3db1c --- /dev/null +++ b/testsuite/java.sun.awt/FrameMenuTest.java @@ -0,0 +1,40 @@ +import java.awt.*; +import java.awt.event.*; + +public class FrameMenuTest + extends Frame +{ + public static void main(String args[]) + { + FrameMenuTest frame = new FrameMenuTest(); + frame.pack(); + frame.show(); + } + public FrameMenuTest() + { + super("FrameMenuTest"); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent event) + { + dispose(); + System.exit(0); + } + }); + + MenuBar mbar = new MenuBar(); + Menu menu = new Menu("File"); + MenuItem exit = new MenuItem("Exit"); + menu.add(exit); + mbar.add(menu); + setMenuBar(mbar); + + exit.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ev) { + dispose(); + System.exit(0); + }}); + + Label message = new Label("Choose File->Exit to continue"); + add(message, "Center"); + } +} diff --git a/testsuite/java.sun.awt/FrameTest.java b/testsuite/java.sun.awt/FrameTest.java new file mode 100644 index 000000000..02a2bef4f --- /dev/null +++ b/testsuite/java.sun.awt/FrameTest.java @@ -0,0 +1,32 @@ +import java.awt.*; +import java.awt.event.*; + +public class FrameTest + extends Frame +{ + public static void main(String args[]) + { + FrameTest frame = new FrameTest(); + frame.pack(); + frame.show(); + } + public FrameTest() + { + super("FrameTest"); + Button done = new Button("Press to continue"); + add(done, "Center"); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent event) + { + dispose(); + System.exit(0); + } + }); + done.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ev) { + dispose(); + System.exit(0); + }}); + + } +} diff --git a/testsuite/java.sun.awt/execute.exp b/testsuite/java.sun.awt/execute.exp new file mode 100644 index 000000000..1092485c0 --- /dev/null +++ b/testsuite/java.sun.awt/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.sun.tools/ClassPathTest.java b/testsuite/java.sun.tools/ClassPathTest.java new file mode 100644 index 000000000..9e17cc30f --- /dev/null +++ b/testsuite/java.sun.tools/ClassPathTest.java @@ -0,0 +1,14 @@ +import sun.tools.java.*; + +public class ClassPathTest { + public static void main(String args[]) { + ClassPath cp = + new ClassPath((String)System.getProperties().get("java.class.path")); + ClassFile cf = cp.getFile("ClassPathTest.class"); + try { + System.out.println("PASSED: "+cp.toString() +" "+ cf.toString()); + } catch (Exception e) { + System.out.println("FAILED: " + e.toString()); + } + } +} diff --git a/testsuite/java.sun.tools/JavacTest.java b/testsuite/java.sun.tools/JavacTest.java new file mode 100644 index 000000000..b7ac5243f --- /dev/null +++ b/testsuite/java.sun.tools/JavacTest.java @@ -0,0 +1,22 @@ +import java.lang.*; + +public class JavacTest { + + public static void main (String args[]) { + try { + + + sun.tools.javac.Main javac = new sun.tools.javac.Main(System.err, "javac"); + + String[] strarr = new String[1]; + strarr[0] = "java.sun.tools/JavacTest.java"; + + javac.compile(strarr); + + System.out.println("PASSED: javac worked"); + System.exit(0); + } catch (Exception e) { + System.out.println("FAILED: "+e); + } + } +} diff --git a/testsuite/java.sun.tools/execute.exp b/testsuite/java.sun.tools/execute.exp new file mode 100644 index 000000000..1092485c0 --- /dev/null +++ b/testsuite/java.sun.tools/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.text/MessageFormatTest.java b/testsuite/java.text/MessageFormatTest.java new file mode 100644 index 000000000..94efe94af --- /dev/null +++ b/testsuite/java.text/MessageFormatTest.java @@ -0,0 +1,25 @@ +import java.text.*; + +public class MessageFormatTest +{ + public static void main(String args[]) + { + try { + String[] sa = new String[3]; + String format = "{0}.{1}() {2}"; + + sa[0] = "MessageFormat"; + sa[1] = "format"; + sa[2] = "worked"; + + String message = MessageFormat.format(format, (Object[])sa); + + if (null == message) + throw new Exception("Unable to format message"); + + System.out.println("PASSED: " + message); + } catch (Exception e) { + System.out.println("FAILED: " + e); + } + } +} diff --git a/testsuite/java.text/SimpleDateFormatTest.java b/testsuite/java.text/SimpleDateFormatTest.java new file mode 100644 index 000000000..4bd8a5f4d --- /dev/null +++ b/testsuite/java.text/SimpleDateFormatTest.java @@ -0,0 +1,17 @@ +import java.util.*; // for Date() +import java.text.*; + +public class SimpleDateFormatTest +{ + public static void main(String args[]) + { + try { + SimpleDateFormat formatter + = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); + Date current = new Date(); + System.out.println("PASSED: time="+formatter.format(current)); + } catch (Exception e) { + System.out.println("FAILED: "+e); + } + } +} diff --git a/testsuite/java.text/execute.exp b/testsuite/java.text/execute.exp new file mode 100644 index 000000000..1092485c0 --- /dev/null +++ b/testsuite/java.text/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.util/ResourceBundleTest.java b/testsuite/java.util/ResourceBundleTest.java new file mode 100644 index 000000000..5ad5ad604 --- /dev/null +++ b/testsuite/java.util/ResourceBundleTest.java @@ -0,0 +1,20 @@ +import java.util.*; + +public class ResourceBundleTest +{ + public static void main(String args[]) + { + try { + ResourceBundle messageRB = + ResourceBundle.getBundle("sun.tools.javac.resources.javac"); + + String bundle = (String)messageRB.getObject("main.usage"); + if (null == bundle) + throw new Exception("javac.main.usage resource is null"); + + System.out.println("PASSED: Resource javac.main.usage existed"); + } catch (Exception e) { + System.out.println("FAILED: " + e); + } + } +} diff --git a/testsuite/java.util/SimpleTimeZoneTest.java b/testsuite/java.util/SimpleTimeZoneTest.java new file mode 100644 index 000000000..1263c2127 --- /dev/null +++ b/testsuite/java.util/SimpleTimeZoneTest.java @@ -0,0 +1,14 @@ +import java.util.*; + +public class SimpleTimeZoneTest +{ + public static void main(String args[]) + { + try { + SimpleTimeZone gmt = new SimpleTimeZone(0, "GMT"); + System.out.println("PASSED: timezone="+gmt.toString()); + } catch (Exception e) { + System.out.println("FAILED: "+e); + } + } +} diff --git a/testsuite/java.util/execute.exp b/testsuite/java.util/execute.exp new file mode 100644 index 000000000..1092485c0 --- /dev/null +++ b/testsuite/java.util/execute.exp @@ -0,0 +1,7 @@ +# +# Author: Petter Reinholdtsen <pere@td.org.uit.no> + +# Load support procs +load_lib java.exp + +test-java-source |