You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/03/15 12:47:39 UTC

svn commit: r386058 [23/49] - in /incubator/harmony/enhanced/classlib/trunk: make/ modules/archive/make/common/ modules/archive/src/test/java/tests/ modules/archive/src/test/java/tests/api/ modules/archive/src/test/java/tests/api/java/ modules/archive/...

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ThreadTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ThreadTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ThreadTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ThreadTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,1146 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang;
+
+public class ThreadTest extends junit.framework.TestCase {
+
+	static class SimpleThread implements Runnable {
+		int delay;
+
+		public void run() {
+			try {
+				synchronized (this) {
+					this.notify();
+					this.wait(delay);
+				}
+			} catch (InterruptedException e) {
+				return;
+			}
+
+		}
+
+		public SimpleThread(int d) {
+			if (d >= 0)
+				delay = d;
+		}
+	}
+
+	static class YieldThread implements Runnable {
+		volatile int delay;
+
+		public void run() {
+			int x = 0;
+			while (true) {
+				++x;
+			}
+		}
+
+		public YieldThread(int d) {
+			if (d >= 0)
+				delay = d;
+		}
+	}
+
+	static class ResSupThread implements Runnable {
+		Thread parent;
+
+		volatile int checkVal = -1;
+
+		public void run() {
+			try {
+				synchronized (this) {
+					this.notify();
+				}
+				while (true) {
+					checkVal++;
+					zz();
+					Thread.sleep(100);
+				}
+			} catch (InterruptedException e) {
+				return;
+			} catch (BogusException e) {
+				try {
+					// Give parent a chance to sleep
+					Thread.sleep(500);
+				} catch (InterruptedException x) {
+				}
+				parent.interrupt();
+				while (!Thread.currentThread().isInterrupted()) {
+					// Don't hog the CPU
+					try {
+						Thread.sleep(50);
+					} catch (InterruptedException x) {
+						// This is what we've been waiting for...don't throw it
+						// away!
+						break;
+					}
+				}
+			}
+		}
+
+		public void zz() throws BogusException {
+		}
+
+		public ResSupThread(Thread t) {
+			parent = t;
+		}
+
+		public synchronized int getCheckVal() {
+			return checkVal;
+		}
+	}
+
+	static class BogusException extends Throwable {
+		public BogusException(String s) {
+			super(s);
+		}
+	}
+
+	Thread st, ct, spinner;
+
+	static boolean calledMySecurityManager = false;
+
+	/**
+	 * @tests java.lang.Thread#Thread()
+	 */
+	public void test_Constructor() {
+		// Test for method java.lang.Thread()
+
+		Thread t;
+		SecurityManager m = new SecurityManager() {
+			public ThreadGroup getThreadGroup() {
+				calledMySecurityManager = true;
+				return Thread.currentThread().getThreadGroup();
+			}
+		};
+		try {
+			// To see if it checks Thread creation with our SecurityManager
+			System.setSecurityManager(m);
+			t = new Thread();
+		} finally {
+			// restore original, no side-effects
+			System.setSecurityManager(null);
+		}
+		assertTrue("Did not call SecurityManager.getThreadGroup ()",
+				calledMySecurityManager);
+		t.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#Thread(java.lang.Runnable)
+	 */
+	public void test_ConstructorLjava_lang_Runnable() {
+		// Test for method java.lang.Thread(java.lang.Runnable)
+		try {
+			ct = new Thread(new SimpleThread(10));
+			ct.start();
+		} catch (Exception e) {
+			fail("Failed to create subthread : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.lang.Thread#Thread(java.lang.Runnable, java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_RunnableLjava_lang_String() {
+		// Test for method java.lang.Thread(java.lang.Runnable,
+		// java.lang.String)
+		Thread st1 = new Thread(new SimpleThread(1), "SimpleThread1");
+		assertTrue("Constructed thread with incorrect thread name", st1
+				.getName().equals("SimpleThread1"));
+		st1.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#Thread(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// Test for method java.lang.Thread(java.lang.String)
+		Thread t = new Thread("Testing");
+		assertTrue("Created tread with incorrect name", t.getName().equals(
+				"Testing"));
+		t.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#Thread(java.lang.ThreadGroup, java.lang.Runnable)
+	 */
+	public void test_ConstructorLjava_lang_ThreadGroupLjava_lang_Runnable() {
+		// Test for method java.lang.Thread(java.lang.ThreadGroup,
+		// java.lang.Runnable)
+		ThreadGroup tg = new ThreadGroup("Test Group1");
+		st = new Thread(tg, new SimpleThread(1), "SimpleThread2");
+		assertTrue("Returned incorrect thread group", st.getThreadGroup() == tg);
+		st.start();
+		try {
+			st.join();
+		} catch (InterruptedException e) {
+		}
+		tg.destroy();
+	}
+
+	/**
+	 * @tests java.lang.Thread#Thread(java.lang.ThreadGroup, java.lang.Runnable,
+	 *        java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_ThreadGroupLjava_lang_RunnableLjava_lang_String() {
+		// Test for method java.lang.Thread(java.lang.ThreadGroup,
+		// java.lang.Runnable, java.lang.String)
+		ThreadGroup tg = new ThreadGroup("Test Group2");
+		st = new Thread(tg, new SimpleThread(1), "SimpleThread3");
+		assertTrue("Constructed incorrect thread", (st.getThreadGroup() == tg)
+				&& st.getName().equals("SimpleThread3"));
+		st.start();
+		try {
+			st.join();
+		} catch (InterruptedException e) {
+		}
+		tg.destroy();
+
+		Runnable r = new Runnable() {
+			public void run() {
+			}
+		};
+
+		ThreadGroup foo = null;
+		try {
+			new Thread(foo = new ThreadGroup("foo"), r, null);
+			// Should not get here
+			fail("Null cannot be accepted as Thread name");
+		} catch (NullPointerException npe) {
+			assertTrue("Null cannot be accepted as Thread name", true);
+			foo.destroy();
+		}
+
+	}
+
+	/**
+	 * @tests java.lang.Thread#Thread(java.lang.ThreadGroup, java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_ThreadGroupLjava_lang_String() {
+		// Test for method java.lang.Thread(java.lang.ThreadGroup,
+		// java.lang.String)
+		st = new Thread(new SimpleThread(1), "SimpleThread4");
+		assertTrue("Returned incorrect thread name", st.getName().equals(
+				"SimpleThread4"));
+		st.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#activeCount()
+	 */
+	public void test_activeCount() {
+		// Test for method int java.lang.Thread.activeCount()
+		Thread t = new Thread(new SimpleThread(1));
+		int active = t.activeCount();
+		assertTrue("Incorrect read made: " + active, active > 0);
+		t.start();
+		try {
+			t.join();
+		} catch (InterruptedException e) {
+		}
+	}
+
+	/**
+	 * @tests java.lang.Thread#checkAccess()
+	 */
+	public void test_checkAccess() {
+		// Test for method void java.lang.Thread.checkAccess()
+		ThreadGroup tg = new ThreadGroup("Test Group3");
+		try {
+			st = new Thread(tg, new SimpleThread(1), "SimpleThread5");
+			st.checkAccess();
+			assertTrue("CheckAccess passed", true);
+		} catch (SecurityException e) {
+			fail("CheckAccess failed : " + e.getMessage());
+		}
+		st.start();
+		try {
+			st.join();
+		} catch (InterruptedException e) {
+		}
+		tg.destroy();
+	}
+
+	/**
+	 * @tests java.lang.Thread#countStackFrames()
+	 */
+	public void test_countStackFrames() {
+		// Test for method int java.lang.Thread.countStackFrames()
+		// SM.
+		assertTrue("Test failed.",
+				Thread.currentThread().countStackFrames() == 0);
+	}
+
+	/**
+	 * @tests java.lang.Thread#currentThread()
+	 */
+	public void test_currentThread() {
+		// Test for method java.lang.Thread java.lang.Thread.currentThread()
+		assertTrue("Current thread was not main thread: "
+				+ Thread.currentThread().getName(), Thread.currentThread()
+				.getName().equals("main"));
+	}
+
+	/**
+	 * @tests java.lang.Thread#destroy()
+	 */
+	public void test_destroy() {
+		// Test for method void java.lang.Thread.destroy()
+		assertTrue(
+				"The method 'destroy' is not implemented so nothing to test",
+				true);
+	}
+
+	/**
+	 * @tests java.lang.Thread#enumerate(java.lang.Thread[])
+	 */
+	public void test_enumerate$Ljava_lang_Thread() {
+		// Test for method int java.lang.Thread.enumerate(java.lang.Thread [])
+		Thread[] tarray = new Thread[10];
+		int initialCount = Thread.enumerate(tarray);
+		ThreadGroup mytg = new ThreadGroup("jp");
+		SimpleThread st1 = new SimpleThread(-1);
+		SimpleThread st2 = new SimpleThread(-1);
+		Thread firstOne = new Thread(mytg, st1, "firstOne2");
+		Thread secondOne = new Thread(mytg, st2, "secondOne1");
+		assertTrue("Incorrect value returned1",
+				Thread.enumerate(tarray) == initialCount);
+		synchronized (st1) {
+			firstOne.start();
+			try {
+				st1.wait();
+			} catch (InterruptedException e) {
+			}
+		}
+		assertTrue("Incorrect value returned2",
+				Thread.enumerate(tarray) == (initialCount + 1));
+
+		synchronized (st2) {
+			secondOne.start();
+			try {
+				st2.wait();
+			} catch (InterruptedException e) {
+			}
+		}
+		assertTrue("Incorrect value returned3",
+				Thread.enumerate(tarray) == (initialCount + 2));
+
+		synchronized (st1) {
+			firstOne.interrupt();
+		}
+		synchronized (st2) {
+			secondOne.interrupt();
+		}
+		try {
+			firstOne.join();
+			secondOne.join();
+		} catch (InterruptedException e) {
+		}
+		mytg.destroy();
+	}
+
+	/**
+	 * @tests java.lang.Thread#getContextClassLoader()
+	 */
+	public void test_getContextClassLoader() {
+		// Test for method java.lang.ClassLoader
+		// java.lang.Thread.getContextClassLoader()
+		Thread t = new Thread();
+		assertTrue("Incorrect class loader returned",
+				t.getContextClassLoader() == Thread.currentThread()
+						.getContextClassLoader());
+		t.start();
+
+	}
+
+	/**
+	 * @tests java.lang.Thread#getName()
+	 */
+	public void test_getName() {
+		// Test for method java.lang.String java.lang.Thread.getName()
+		st = new Thread(new SimpleThread(1), "SimpleThread6");
+		assertTrue("Returned incorrect thread name", st.getName().equals(
+				"SimpleThread6"));
+		st.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#getPriority()
+	 */
+	public void test_getPriority() {
+		// Test for method int java.lang.Thread.getPriority()
+		st = new Thread(new SimpleThread(1));
+		st.setPriority(Thread.MAX_PRIORITY);
+		assertTrue("Returned incorrect thread priority",
+				st.getPriority() == Thread.MAX_PRIORITY);
+		st.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#getThreadGroup()
+	 */
+	public void test_getThreadGroup() {
+		// Test for method java.lang.ThreadGroup
+		// java.lang.Thread.getThreadGroup()
+		ThreadGroup tg = new ThreadGroup("Test Group4");
+		st = new Thread(tg, new SimpleThread(1), "SimpleThread8");
+		assertTrue("Returned incorrect thread group", st.getThreadGroup() == tg);
+		st.start();
+		try {
+			st.join();
+		} catch (InterruptedException e) {
+		}
+		assertTrue("group should be null", st.getThreadGroup() == null);
+		assertTrue("toString() should not be null", st.toString() != null);
+		tg.destroy();
+
+		final Object lock = new Object();
+		Thread t = new Thread() {
+			public void run() {
+				synchronized (lock) {
+					lock.notifyAll();
+				}
+			}
+		};
+		synchronized (lock) {
+			t.start();
+			try {
+				lock.wait();
+			} catch (InterruptedException e) {
+			}
+		}
+		int running = 0;
+		while (t.isAlive())
+			running++;
+		ThreadGroup group = t.getThreadGroup();
+		assertTrue("ThreadGroup is not null", group == null);
+	}
+
+	/**
+	 * @tests java.lang.Thread#interrupt()
+	 */
+	public void test_interrupt() {
+		// Test for method void java.lang.Thread.interrupt()
+		final Object lock = new Object();
+		class ChildThread1 extends Thread {
+			Thread parent;
+
+			boolean sync;
+
+			public void run() {
+				if (sync) {
+					synchronized (lock) {
+						lock.notify();
+						try {
+							lock.wait();
+						} catch (InterruptedException e) {
+						}
+					}
+				}
+				parent.interrupt();
+			}
+
+			public ChildThread1(Thread p, String name, boolean sync) {
+				super(name);
+				parent = p;
+				this.sync = sync;
+			}
+		}
+		boolean interrupted = false;
+		try {
+			ct = new ChildThread1(Thread.currentThread(), "Interrupt Test1",
+					false);
+			synchronized (lock) {
+				ct.start();
+				lock.wait();
+			}
+		} catch (InterruptedException e) {
+			interrupted = true;
+		}
+		assertTrue("Failed to Interrupt thread1", interrupted);
+
+		interrupted = false;
+		try {
+			ct = new ChildThread1(Thread.currentThread(), "Interrupt Test2",
+					true);
+			synchronized (lock) {
+				ct.start();
+				lock.wait();
+				lock.notify();
+			}
+			Thread.sleep(20000);
+		} catch (InterruptedException e) {
+			interrupted = true;
+		}
+		assertTrue("Failed to Interrupt thread2", interrupted);
+
+	}
+
+	/**
+	 * @tests java.lang.Thread#interrupted()
+	 */
+	public void test_interrupted() {
+		// Test for method boolean java.lang.Thread.interrupted()
+
+		assertTrue("Interrupted returned true for non-interrupted thread",
+				Thread.interrupted() == false);
+		Thread.currentThread().interrupt();
+		assertTrue("Interrupted returned true for non-interrupted thread",
+				Thread.interrupted() == true);
+		assertTrue("Failed to clear interrupted flag",
+				Thread.interrupted() == false);
+	}
+
+	/**
+	 * @tests java.lang.Thread#isAlive()
+	 */
+	public void test_isAlive() {
+		// Test for method boolean java.lang.Thread.isAlive()
+		SimpleThread simple;
+		st = new Thread(simple = new SimpleThread(500));
+		assertTrue("Unstarted thread returned true", !st.isAlive());
+		synchronized (simple) {
+			st.start();
+			try {
+				simple.wait();
+			} catch (InterruptedException e) {
+			}
+		}
+		assertTrue("Started thread returned false", st.isAlive());
+		try {
+			st.join();
+		} catch (InterruptedException e) {
+			fail("Thread did not die");
+		}
+		assertTrue("Stopped thread returned true", !st.isAlive());
+	}
+
+	/**
+	 * @tests java.lang.Thread#isDaemon()
+	 */
+	public void test_isDaemon() {
+		// Test for method boolean java.lang.Thread.isDaemon()
+		st = new Thread(new SimpleThread(1), "SimpleThread10");
+		assertTrue("Non-Daemon thread returned true", !st.isDaemon());
+		st.setDaemon(true);
+		assertTrue("Daemon thread returned false", st.isDaemon());
+		st.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#isInterrupted()
+	 */
+	public void test_isInterrupted() {
+		// Test for method boolean java.lang.Thread.isInterrupted()
+		class SpinThread implements Runnable {
+			public volatile boolean done = false;
+
+			public void run() {
+				while (!Thread.currentThread().isInterrupted())
+					;
+				while (!done)
+					;
+			}
+		}
+
+		SpinThread spin = new SpinThread();
+		spinner = new Thread(spin);
+		spinner.start();
+		Thread.yield();
+		try {
+			assertTrue("Non-Interrupted thread returned true", !spinner
+					.isInterrupted());
+			spinner.interrupt();
+			assertTrue("Interrupted thread returned false", spinner
+					.isInterrupted());
+			spin.done = true;
+		} finally {
+			spinner.interrupt();
+			spin.done = true;
+		}
+	}
+
+	/**
+	 * @tests java.lang.Thread#join()
+	 */
+	public void test_join() {
+		// Test for method void java.lang.Thread.join()
+		SimpleThread simple;
+		try {
+			st = new Thread(simple = new SimpleThread(100));
+			// cause isAlive() to be compiled by the jit, as it must be called
+			// within 100ms below.
+			assertTrue("Thread is alive", !st.isAlive());
+			synchronized (simple) {
+				st.start();
+				simple.wait();
+			}
+			st.join();
+		} catch (InterruptedException e) {
+			fail("Join failed ");
+		}
+		assertTrue("Joined thread is still alive", !st.isAlive());
+		boolean result = true;
+		Thread th = new Thread("test");
+		try {
+			th.join();
+		} catch (InterruptedException e) {
+			result = false;
+		}
+		assertTrue("Hung joining a non-started thread", result);
+		th.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#join(long)
+	 */
+	public void test_joinJ() {
+		// Test for method void java.lang.Thread.join(long)
+		SimpleThread simple;
+		try {
+			st = new Thread(simple = new SimpleThread(1000), "SimpleThread12");
+			// cause isAlive() to be compiled by the jit, as it must be called
+			// within 100ms below.
+			assertTrue("Thread is alive", !st.isAlive());
+			synchronized (simple) {
+				st.start();
+				simple.wait();
+			}
+			st.join(10);
+		} catch (InterruptedException e) {
+			fail("Join failed ");
+		}
+		assertTrue("Join failed to timeout", st.isAlive());
+
+		st.interrupt();
+		try {
+			st = new Thread(simple = new SimpleThread(100), "SimpleThread13");
+			synchronized (simple) {
+				st.start();
+				simple.wait();
+			}
+			st.join(1000);
+		} catch (InterruptedException e) {
+			fail("Join failed : " + e.getMessage());
+			return;
+		}
+		assertTrue("Joined thread is still alive", !st.isAlive());
+
+		final Object lock = new Object();
+		final Thread main = Thread.currentThread();
+		Thread killer = new Thread(new Runnable() {
+			public void run() {
+				try {
+					synchronized (lock) {
+						lock.notify();
+					}
+					Thread.sleep(100);
+				} catch (InterruptedException e) {
+					return;
+				}
+				main.interrupt();
+			}
+		});
+		boolean result = true;
+		Thread th = new Thread("test");
+		try {
+			synchronized (lock) {
+				killer.start();
+				lock.wait();
+			}
+			th.join(200);
+		} catch (InterruptedException e) {
+			result = false;
+		}
+		killer.interrupt();
+		assertTrue("Hung joining a non-started thread", result);
+		th.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#join(long, int)
+	 */
+	public void test_joinJI() {
+		// Test for method void java.lang.Thread.join(long, int)
+		SimpleThread simple;
+		try {
+			st = new Thread(simple = new SimpleThread(1000), "Squawk1");
+			assertTrue("Thread is alive", !st.isAlive());
+			synchronized (simple) {
+				st.start();
+				simple.wait();
+			}
+			
+			long firstRead = System.currentTimeMillis();
+			st.join(100, 999999);
+			long secondRead = System.currentTimeMillis();
+			assertTrue("Did not join by appropriate time: " + secondRead + "-"
+					+ firstRead + "=" + (secondRead - firstRead), secondRead
+					- firstRead <= 300);
+			assertTrue("Joined thread is not alive", st.isAlive());
+			st.interrupt();  
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+
+		final Object lock = new Object();
+		final Thread main = Thread.currentThread();
+		Thread killer = new Thread(new Runnable() {
+			public void run() {
+				try {
+					synchronized (lock) {
+						lock.notify();
+					}
+					Thread.sleep(100);
+				} catch (InterruptedException e) {
+					return;
+				}
+				main.interrupt();
+			}
+		});
+		boolean result = true;
+		Thread th = new Thread("test");
+		try {
+			synchronized (lock) {
+				killer.start();
+				lock.wait();
+			}
+			th.join(200, 20);
+		} catch (InterruptedException e) {
+			result = false;
+		}
+		killer.interrupt();
+		assertTrue("Hung joining a non-started thread", result);
+		th.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#resume()
+	 */
+	public void test_resume() {
+		// Test for method void java.lang.Thread.resume()
+		int orgval;
+		ResSupThread t;
+		try {
+			t = new ResSupThread(Thread.currentThread());
+			synchronized (t) {
+				ct = new Thread(t, "Interupt Test2");
+				ct.start();
+				t.wait();
+			}
+			ct.suspend();
+			// Wait to be sure the suspend has occurred
+			Thread.sleep(500);
+			orgval = t.getCheckVal();
+			// Wait to be sure the thread is suspended
+			Thread.sleep(500);
+			assertTrue("Failed to suspend thread", orgval == t.getCheckVal());
+			ct.resume();
+			// Wait to be sure the resume has occurred.
+			Thread.sleep(500);
+			assertTrue("Failed to resume thread", orgval != t.getCheckVal());
+			ct.interrupt();
+		} catch (InterruptedException e) {
+			fail("Unexpected interrupt occurred : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.lang.Thread#run()
+	 */
+	public void test_run() {
+		// Test for method void java.lang.Thread.run()
+		class RunThread implements Runnable {
+			boolean didThreadRun = false;
+
+			public void run() {
+				didThreadRun = true;
+			}
+		}
+		RunThread rt = new RunThread();
+		Thread t = new Thread(rt);
+		try {
+			t.start();
+			int count = 0;
+			while (!rt.didThreadRun && count < 20) {
+				Thread.sleep(100);
+				count++;
+			}
+			assertTrue("Thread did not run", rt.didThreadRun);
+			t.join();
+		} catch (InterruptedException e) {
+			assertTrue("Joined thread was interrupted", true);
+		}
+		assertTrue("Joined thread is still alive", !t.isAlive());
+	}
+
+	/**
+	 * @tests java.lang.Thread#setDaemon(boolean)
+	 */
+	public void test_setDaemonZ() {
+		// Test for method void java.lang.Thread.setDaemon(boolean)
+		st = new Thread(new SimpleThread(1), "SimpleThread14");
+		st.setDaemon(true);
+		assertTrue("Failed to set thread as daemon thread", st.isDaemon());
+		st.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#setName(java.lang.String)
+	 */
+	public void test_setNameLjava_lang_String() {
+		// Test for method void java.lang.Thread.setName(java.lang.String)
+		st = new Thread(new SimpleThread(1), "SimpleThread15");
+		st.setName("Bogus Name");
+		assertTrue("Failed to set thread name", st.getName().equals(
+				"Bogus Name"));
+		try {
+			st.setName(null);
+			fail("Null should not be accepted as a valid name");
+		} catch (NullPointerException e) {
+			// success
+			assertTrue("Null should not be accepted as a valid name", true);
+		}
+		st.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#setPriority(int)
+	 */
+	public void test_setPriorityI() {
+		// Test for method void java.lang.Thread.setPriority(int)
+		st = new Thread(new SimpleThread(1));
+		st.setPriority(Thread.MAX_PRIORITY);
+		assertTrue("Failed to set priority",
+				st.getPriority() == Thread.MAX_PRIORITY);
+		st.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#sleep(long)
+	 */
+	public void test_sleepJ() {
+		// Test for method void java.lang.Thread.sleep(long)
+
+		// TODO : Test needs enhancing.
+		long stime = 0, ftime = 0;
+		try {
+			stime = System.currentTimeMillis();
+			Thread.currentThread().sleep(1000);
+			ftime = System.currentTimeMillis();
+		} catch (InterruptedException e) {
+			fail("Unexpected interrupt received");
+		}
+		assertTrue("Failed to sleep long enough", (ftime - stime) >= 800);
+	}
+
+	/**
+	 * @tests java.lang.Thread#sleep(long, int)
+	 */
+	public void test_sleepJI() {
+		// Test for method void java.lang.Thread.sleep(long, int)
+
+		// TODO : Test needs revisiting.
+		long stime = 0, ftime = 0;
+		try {
+			stime = System.currentTimeMillis();
+			Thread.currentThread().sleep(1000, 999999);
+			ftime = System.currentTimeMillis();
+		} catch (InterruptedException e) {
+			fail("Unexpected interrupt received");
+		}
+		long result = ftime - stime;
+		assertTrue("Failed to sleep long enough: " + result, result >= 900
+				&& result <= 1100);
+	}
+
+	/**
+	 * @tests java.lang.Thread#start()
+	 */
+	public void test_start() {
+		// Test for method void java.lang.Thread.start()
+		try {
+			ResSupThread t = new ResSupThread(Thread.currentThread());
+			synchronized (t) {
+				ct = new Thread(t, "Interrupt Test4");
+				ct.start();
+				t.wait();
+			}
+			assertTrue("Thread is not running1", ct.isAlive());
+			// Let the child thread get going.
+			int orgval = t.getCheckVal();
+			Thread.sleep(150);
+			assertTrue("Thread is not running2", orgval != t.getCheckVal());
+			ct.interrupt();
+		} catch (InterruptedException e) {
+			fail("Unexpected interrupt occurred");
+		}
+	}
+
+	/**
+	 * @tests java.lang.Thread#stop()
+	 */
+	public void test_stop() {
+		// Test for method void java.lang.Thread.stop()
+		try {
+			Runnable r = new ResSupThread(null);
+			synchronized (r) {
+				st = new Thread(r, "Interupt Test5");
+				st.start();
+				r.wait();
+			}
+
+		} catch (InterruptedException e) {
+			fail("Unexpected interrupt received");
+		}
+		st.stop();
+
+		try {
+			st.join(10000);
+		} catch (InterruptedException e1) {
+			st.interrupt();
+			fail("Failed to stopThread before 10000 timeout");
+		}
+		assertTrue("Failed to stopThread", !st.isAlive());
+	}
+
+	/**
+	 * @tests java.lang.Thread#stop()
+	 */
+	public void test_stop_subtest0() {
+		Thread t = new Thread("t");
+		class MySecurityManager extends SecurityManager {
+			public boolean intest = false;
+
+			public void checkAccess(Thread t) {
+				if (intest) {
+					fail("checkAccess called");
+				}
+			}
+		}
+		MySecurityManager sm = new MySecurityManager();
+		System.setSecurityManager(sm);
+		try {
+			sm.intest = true;
+			try {
+				t.stop();
+				// Ignore any SecurityExceptions, may not have stopThread
+				// permission
+			} catch (SecurityException e) {
+			}
+			sm.intest = false;
+			t.start();
+			try {
+				t.join(2000);
+			} catch (InterruptedException e) {
+			}
+			sm.intest = true;
+			try {
+				t.stop();
+				// Ignore any SecurityExceptions, may not have stopThread
+				// permission
+			} catch (SecurityException e) {
+			}
+			sm.intest = false;
+		} finally {
+			System.setSecurityManager(null);
+		}
+	}
+
+	/**
+	 * @tests java.lang.Thread#stop(java.lang.Throwable)
+	 */
+	public void test_stopLjava_lang_Throwable_subtest0() {
+		Thread t = new Thread("t");
+		class MySecurityManager extends SecurityManager {
+			public boolean intest = false;
+
+			public boolean checkAccess = false;
+
+			public void checkAccess(Thread t) {
+				if (intest) {
+					checkAccess = true;
+				}
+			}
+		}
+		MySecurityManager sm = new MySecurityManager();
+		System.setSecurityManager(sm);
+		try {
+			sm.intest = true;
+			try {
+				t.stop(new ThreadDeath());
+				// Ignore any SecurityExceptions, may not have stopThread
+				// permission
+			} catch (SecurityException e) {
+			}
+			sm.intest = false;
+			assertTrue("no checkAccess 1", sm.checkAccess);
+			t.start();
+			try {
+				t.join(2000);
+			} catch (InterruptedException e) {
+			}
+			sm.intest = true;
+			sm.checkAccess = false;
+			try {
+				t.stop(new ThreadDeath());
+				// Ignore any SecurityExceptions, may not have stopThread
+				// permission
+			} catch (SecurityException e) {
+			}
+			assertTrue("no checkAccess 2", sm.checkAccess);
+			sm.intest = false;
+		} finally {
+			System.setSecurityManager(null);
+		}
+	}
+
+	/**
+	 * @tests java.lang.Thread#stop(java.lang.Throwable)
+	 */
+	public void test_stopLjava_lang_Throwable() {
+		// Test for method void java.lang.Thread.stop(java.lang.Throwable)
+		ResSupThread t = new ResSupThread(Thread.currentThread());
+		synchronized (t) {
+			st = new Thread(t, "StopThread");
+			st.setPriority(Thread.MAX_PRIORITY);
+			st.start();
+			try {
+				t.wait();
+			} catch (InterruptedException e) {
+			}
+		}
+		try {
+			st.stop(new BogusException("Bogus"));
+			Thread.sleep(20000);
+		} catch (InterruptedException e) {
+			assertTrue("Stopped child with exception not alive", st.isAlive());
+			st.interrupt();
+			return;
+		}
+		st.interrupt();
+		fail("Stopped child did not throw exception");
+	}
+
+	/**
+	 * @tests java.lang.Thread#suspend()
+	 */
+	public void test_suspend() {
+		// Test for method void java.lang.Thread.suspend()
+		int orgval;
+		ResSupThread t = new ResSupThread(Thread.currentThread());
+		try {
+			synchronized (t) {
+				ct = new Thread(t, "Interupt Test6");
+				ct.start();
+				t.wait();
+			}
+			ct.suspend();
+			// Wait to be sure the suspend has occurred
+			Thread.sleep(500);
+			orgval = t.getCheckVal();
+			// Wait to be sure the thread is suspended
+			Thread.sleep(500);
+			assertTrue("Failed to suspend thread", orgval == t.getCheckVal());
+			ct.resume();
+			// Wait to be sure the resume has occurred.
+			Thread.sleep(500);
+			assertTrue("Failed to resume thread", orgval != t.getCheckVal());
+			ct.interrupt();
+		} catch (InterruptedException e) {
+			fail("Unexpected interrupt occurred");
+		}
+
+		final Object notify = new Object();
+		Thread t1 = new Thread(new Runnable() {
+			public void run() {
+				synchronized (notify) {
+					notify.notify();
+				}
+				Thread.currentThread().suspend();
+			}
+		});
+		try {
+			synchronized (notify) {
+				t1.start();
+				notify.wait();
+			}
+			// wait for Thread to suspend
+			Thread.sleep(500);
+			assertTrue("Thread should be alive", t1.isAlive());
+			t1.resume();
+			t1.join();
+		} catch (InterruptedException e) {
+		}
+	}
+
+	/**
+	 * @tests java.lang.Thread#toString()
+	 */
+	public void test_toString() {
+		// Test for method java.lang.String java.lang.Thread.toString()
+		ThreadGroup tg = new ThreadGroup("Test Group5");
+		st = new Thread(tg, new SimpleThread(1), "SimpleThread17");
+		final String stString = st.toString();
+		final String expected = "Thread[SimpleThread17,5,Test Group5]";
+		assertTrue("Returned incorrect string: " + stString + "\t(expecting :"
+				+ expected + ")", stString.equals(expected));
+		st.start();
+		try {
+			st.join();
+		} catch (InterruptedException e) {
+		}
+		tg.destroy();
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+		try {
+			if (st != null)
+				st.interrupt();
+		} catch (Exception e) {
+		}
+		try {
+			if (spinner != null)
+				spinner.interrupt();
+		} catch (Exception e) {
+		}
+		try {
+			if (ct != null)
+				ct.interrupt();
+		} catch (Exception e) {
+		}
+
+		try {
+			spinner = null;
+			st = null;
+			ct = null;
+			System.runFinalization();
+		} catch (Exception e) {
+		}
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ThrowableTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ThrowableTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ThrowableTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ThrowableTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,222 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.java.lang;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+
+public class ThrowableTest extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.lang.Throwable#Throwable()
+	 */
+	public void test_Constructor() {
+		// Test for method java.lang.Throwable()
+		try {
+			if (true)
+				throw new Throwable();
+		} catch (Throwable e) {
+			return;
+		}
+		fail("Failed to throw Throwable");
+	}
+
+	/**
+	 * @tests java.lang.Throwable#Throwable(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// Test for method java.lang.Throwable(java.lang.String)
+		try {
+			if (true)
+				throw new Throwable("Throw");
+		} catch (Throwable e) {
+			assertTrue("Threw Throwable with incorrect message", e.getMessage()
+					.equals("Throw"));
+			return;
+		}
+		fail("Failed to throw Throwable");
+	}
+
+	/**
+	 * @tests java.lang.Throwable#fillInStackTrace()
+	 */
+	public void test_fillInStackTrace() {
+		// Test for method java.lang.Throwable
+		// java.lang.Throwable.fillInStackTrace()
+		class Test implements Runnable {
+			public int x;
+
+			public Test(int x) {
+				this.x = x;
+			}
+
+			public void anotherMethod() {
+				if (true)
+					throw new IndexOutOfBoundsException();
+			}
+
+			public void run() {
+				if (x == 0)
+					throw new IndexOutOfBoundsException();
+				try {
+					anotherMethod();
+				} catch (IndexOutOfBoundsException e) {
+					e.fillInStackTrace();
+					throw e;
+				}
+			}
+		}
+		ByteArrayOutputStream bao = new ByteArrayOutputStream();
+		PrintStream ps = new PrintStream(bao);
+		try {
+			new Test(0).run();
+		} catch (Throwable e) {
+			e.printStackTrace(ps);
+		}
+		ps.flush();
+		String s = fixStacktrace(new String(bao.toByteArray(), 0, bao.size()));
+
+		bao.reset();
+		try {
+			new Test(1).run();
+		} catch (Throwable e) {
+			e.printStackTrace(ps);
+		}
+		ps.close();
+		String s2 = fixStacktrace(new String(bao.toByteArray(), 0, bao.size()));
+		assertTrue("Invalid stackTrace? length: " + s2.length() + "\n" + s2, s2
+				.length() > 300);
+		assertTrue("Incorrect stackTrace printed: \n" + s2
+				+ "\n\nCompared with:\n" + s, s2.equals(s));
+	}
+
+	private String fixStacktrace(String trace) {
+		// remove linenumbers
+		StringBuffer sb = new StringBuffer();
+		int lastIndex = 0;
+		while (lastIndex < trace.length()) {
+			int index = trace.indexOf('\n', lastIndex);
+			if (index == -1)
+				index = trace.length();
+			String line = trace.substring(lastIndex, index);
+			lastIndex = index + 1;
+
+			index = line.indexOf("(");
+			if (index > -1) {
+				line = line.substring(0, index);
+			}
+			// Usually the construction of the exception is removed
+			// however if running with the JIT, it may not be removed
+			if (line.indexOf("java.lang.Throwable") > -1)
+				continue;
+			sb.append(line);
+			sb.append('\n');
+		}
+		return sb.toString();
+	}
+
+	/**
+	 * @tests java.lang.Throwable#getMessage()
+	 */
+	public void test_getMessage() {
+		// Test for method java.lang.String java.lang.Throwable.getMessage()
+
+		Throwable x = new ClassNotFoundException("A Message");
+		assertTrue("Returned incorrect messasge string", x.getMessage().equals(
+				"A Message"));
+	}
+
+	/**
+	 * @tests java.lang.Throwable#printStackTrace()
+	 */
+	public void test_printStackTrace() {
+		// Test for method void java.lang.Throwable.printStackTrace()
+		Throwable x = new ClassNotFoundException("A Test Message");
+		ByteArrayOutputStream bao = new ByteArrayOutputStream();
+		PrintStream ps = new PrintStream(bao);
+		PrintStream err = System.err;
+		System.setErr(ps);
+		x.printStackTrace();
+		System.setErr(err);
+		ps.close();
+		String s = new String(bao.toByteArray(), 0, bao.size());
+		assertTrue("Incorrect stackTrace printed:\n" + s, s != null
+				&& s.length() > 400);
+	}
+
+	/**
+	 * @tests java.lang.Throwable#printStackTrace(java.io.PrintStream)
+	 */
+	public void test_printStackTraceLjava_io_PrintStream() {
+		// Test for method void
+		// java.lang.Throwable.printStackTrace(java.io.PrintStream)
+		ByteArrayOutputStream bao = new ByteArrayOutputStream();
+		PrintStream ps = new PrintStream(bao);
+		Throwable x = new java.net.UnknownHostException("A Message");
+		x.printStackTrace(ps);
+		ps.close();
+		String s = new String(bao.toByteArray(), 0, bao.size());
+		assertTrue("Incorrect stackTrace printed:\n" + s, s != null
+				&& s.length() > 400);
+	}
+
+	/**
+	 * @tests java.lang.Throwable#printStackTrace(java.io.PrintWriter)
+	 */
+	public void test_printStackTraceLjava_io_PrintWriter() {
+		// Test for method void
+		// java.lang.Throwable.printStackTrace(java.io.PrintWriter)
+		// SM
+		ByteArrayOutputStream bao = new ByteArrayOutputStream();
+		PrintWriter pw = new PrintWriter(bao);
+		Throwable x = new java.net.UnknownHostException("A Message");
+		x.printStackTrace(pw);
+		pw.close();
+		String s = new String(bao.toByteArray(), 0, bao.size());
+		assertTrue("Incorrect stackTrace printed:\n" + s, s != null
+				&& s.length() > 400);
+	}
+
+	/**
+	 * @tests java.lang.Throwable#toString()
+	 */
+	public void test_toString() {
+		// Test for method java.lang.String java.lang.Throwable.toString()
+		try {
+			if (true)
+				throw new Throwable("Throw");
+		} catch (Throwable e) {
+			assertTrue("Threw Throwable with incorrect string", e.toString()
+					.equals("java.lang.Throwable: Throw"));
+			return;
+		}
+		fail("Failed to throw Throwable");
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/UnknownErrorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/UnknownErrorTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/UnknownErrorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/UnknownErrorTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,63 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang;
+
+public class UnknownErrorTest extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.lang.UnknownError#UnknownError()
+	 */
+	public void test_Constructor() {
+		// Test for method java.lang.UnknownError()
+		try {
+			if (true)
+				throw new UnknownError();
+		} catch (UnknownError e) {
+			return;
+		}
+		fail("Failed to generate error");
+	}
+
+	/**
+	 * @tests java.lang.UnknownError#UnknownError(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// Test for method java.lang.UnknownError(java.lang.String)
+		try {
+			if (true)
+				throw new UnknownError("Unknown");
+		} catch (UnknownError e) {
+			assertTrue(" Incorrect msg string ", e.getMessage().equals(
+					"Unknown"));
+			return;
+		}
+		fail("Failed to generate error");
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/UnsatisfiedLinkErrorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/UnsatisfiedLinkErrorTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/UnsatisfiedLinkErrorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/UnsatisfiedLinkErrorTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,58 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang;
+
+public class UnsatisfiedLinkErrorTest extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.lang.UnsatisfiedLinkError#UnsatisfiedLinkError()
+	 */
+	public void test_Constructor() {
+		// SM.
+		try {
+			if (true)
+				throw new UnsatisfiedLinkError();
+		} catch (UnsatisfiedLinkError e) {
+			assertTrue("Initializer failed.", e.getMessage() == null);
+			assertTrue("To string failed.", e.toString().equals(
+					"java.lang.UnsatisfiedLinkError"));
+		}
+	}
+
+	/**
+	 * @tests java.lang.UnsatisfiedLinkError#UnsatisfiedLinkError(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// TODO : No method throws this error.
+		boolean exception = false;
+		try {
+			Runtime.getRuntime().loadLibrary("Hello World89797");
+		} catch (UnsatisfiedLinkError e) {
+			assertTrue("Does not set message", e.getMessage() != null);
+			exception = true;
+		}
+		assertTrue("Does not throw UnsatisfiedLinkError", exception);
+
+		UnsatisfiedLinkError err = new UnsatisfiedLinkError("my message");
+		assertTrue("Incorrect message", "my message".equals(err.getMessage()));
+	}
+
+	protected void setUp() {
+	}
+
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/UnsupportedOperationExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/UnsupportedOperationExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/UnsupportedOperationExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/UnsupportedOperationExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,79 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang;
+
+import java.util.AbstractCollection;
+import java.util.Iterator;
+
+public class UnsupportedOperationExceptionTest extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.lang.UnsupportedOperationException#UnsupportedOperationException()
+	 */
+	public void test_Constructor() {
+		// Test for method java.lang.UnsupportedOperationException()
+		class UnsupportedCollection extends AbstractCollection {
+			public int size() {
+				return 0;
+			}
+
+			public Iterator iterator() {
+				return null;
+			}
+		}
+		try {
+			UnsupportedCollection uc = new UnsupportedCollection();
+			uc.add(new Object());
+		} catch (UnsupportedOperationException e) {
+			return;
+		} catch (Exception e) {
+			fail("Exception during Constructor : " + e.getMessage());
+		}
+		fail("Constructor failed.");
+	}
+
+	/**
+	 * @tests java.lang.UnsupportedOperationException#UnsupportedOperationException(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// Test for method
+		// java.lang.UnsupportedOperationException(java.lang.String)
+		try {
+			throw new UnsupportedOperationException("HelloWorld");
+		} catch (UnsupportedOperationException e) {
+			assertTrue("Wrong message given.", e.getMessage().equals(
+					"HelloWorld"));
+			return;
+		} catch (Exception e) {
+			fail("Exception during Constructor : " + e.getMessage());
+		}
+		fail("Constructor failed");
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/VerifyErrorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/VerifyErrorTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/VerifyErrorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/VerifyErrorTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,53 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang;
+
+public class VerifyErrorTest extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.lang.VerifyError#VerifyError()
+	 */
+	public void test_Constructor() {
+		try {
+			if (true)
+				throw new VerifyError();
+		} catch (VerifyError e) {
+			return;
+		}
+		fail("Constructor failed");
+	}
+
+	/**
+	 * @tests java.lang.VerifyError#VerifyError(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		try {
+			if (true)
+				throw new VerifyError("HelloWorld");
+		} catch (VerifyError e) {
+			assertTrue("VerifyError(String) failed.", e.getMessage().equals(
+					"HelloWorld"));
+			return;
+		}
+		fail("Constructor failed");
+	}
+
+	protected void setUp() {
+	}
+
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/VirtualMachineErrorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/VirtualMachineErrorTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/VirtualMachineErrorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/VirtualMachineErrorTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,74 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.java.lang;
+
+public class VirtualMachineErrorTest extends junit.framework.TestCase {
+
+	public class TestVirtualMachineError extends VirtualMachineError {
+		public TestVirtualMachineError() {
+			super();
+		}
+
+		public TestVirtualMachineError(String detailMessage) {
+			super(detailMessage);
+		}
+	}
+
+	/**
+	 * @tests java.lang.VirtualMachineError#VirtualMachineError()
+	 */
+	public void test_Constructor() {
+		// Test for method java.lang.VirtualMachineError()
+		// Tested more via subclasses (i.e. StackOverFlowError).
+		try {
+			if (true)
+				throw new TestVirtualMachineError();
+		} catch (VirtualMachineError e) {
+			return;
+		}
+		fail("Constructor failed");
+	}
+
+	/**
+	 * @tests java.lang.VirtualMachineError#VirtualMachineError(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// Test for method java.lang.VirtualMachineError(java.lang.String)
+		// Tested more via subclasses (i.e. StackOverFlowError).
+		try {
+			if (true)
+				throw new TestVirtualMachineError("HelloWorld");
+		} catch (VirtualMachineError e) {
+			assertTrue("VerifyError(String) failed.", e.getMessage().equals(
+					"HelloWorld"));
+			return;
+		}
+		fail("Constructor failed");
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/AllTests.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/AllTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/AllTests.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,41 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang.ref;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite for java.lang.ref package.
+ */
+public class AllTests {
+
+	public static void main(String[] args) {
+		junit.textui.TestRunner.run(suite());
+	}
+
+	public static Test suite() {
+		TestSuite suite = new TestSuite("Tests for java.lang.ref");
+		// $JUnit-BEGIN$
+		suite.addTestSuite(PhantomReferenceTest.class);
+		suite.addTestSuite(ReferenceTest.class);
+		suite.addTestSuite(ReferenceQueueTest.class);
+		suite.addTestSuite(SoftReferenceTest.class);
+		suite.addTestSuite(WeakReferenceTest.class);
+		// $JUnit-END$
+		return suite;
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/PhantomReferenceTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/PhantomReferenceTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/PhantomReferenceTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/PhantomReferenceTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,70 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang.ref;
+
+import java.lang.ref.PhantomReference;
+import java.lang.ref.ReferenceQueue;
+
+public class PhantomReferenceTest extends junit.framework.TestCase {
+	static Boolean bool;
+
+	protected void doneSuite() {
+		bool = null;
+	}
+
+	/**
+	 * @tests java.lang.ref.PhantomReference#get()
+	 */
+	public void test_get() {
+		ReferenceQueue rq = new ReferenceQueue();
+		bool = new Boolean(false);
+		PhantomReference pr = new PhantomReference(bool, rq);
+		assertTrue("Same object returned.", pr.get() == null);
+	}
+
+	/**
+	 * @tests java.lang.ref.PhantomReference#PhantomReference(java.lang.Object,
+	 *        java.lang.ref.ReferenceQueue)
+	 */
+	public void test_ConstructorLjava_lang_ObjectLjava_lang_ref_ReferenceQueue() {
+		ReferenceQueue rq = new ReferenceQueue();
+		bool = new Boolean(true);
+		try {
+			PhantomReference pr = new PhantomReference(bool, rq);
+			// Allow the finalizer to run to potentially enqueue
+			Thread.sleep(1000);
+			assertTrue("Initialization failed.", !pr.isEnqueued());
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+		// need a reference to bool so the jit does not optimize it away
+		assertTrue("should always pass", bool.booleanValue());
+
+		boolean exception = false;
+		try {
+			new PhantomReference(bool, null);
+		} catch (NullPointerException e) {
+			exception = true;
+		}
+		assertTrue("Should not throw NullPointerException", !exception);
+	}
+
+	protected void setUp() {
+	}
+
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/ReferenceQueueTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/ReferenceQueueTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/ReferenceQueueTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/ReferenceQueueTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,120 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang.ref;
+
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
+
+public class ReferenceQueueTest extends junit.framework.TestCase {
+	static Boolean b;
+
+	static Integer integer;
+
+	protected void doneSuite() {
+		b = null;
+		integer = null;
+	}
+
+	public class ChildThread implements Runnable {
+		public ChildThread() {
+		}
+
+		public void run() {
+			try {
+				rq.wait(1000);
+			} catch (Exception e) {
+			}
+			synchronized (rq) {
+				// store in a static so it won't be gc'ed because the jit
+				// optimized it out
+				integer = new Integer(667);
+				SoftReference sr = new SoftReference(integer, rq);
+				sr.enqueue();
+				rq.notify();
+			}
+		}
+	}
+
+	ReferenceQueue rq;
+
+	/**
+	 * @tests java.lang.ref.ReferenceQueue#poll()
+	 */
+	public void test_poll() {
+		// store in a static so it won't be gc'ed because the jit
+		// optimized it out
+		b = new Boolean(true);
+		SoftReference sr = new SoftReference(b, rq);
+		sr.enqueue();
+		try {
+			assertTrue("Remove failed.", ((Boolean) rq.poll().get())
+					.booleanValue());
+		} catch (Exception e) {
+			fail("Exception during the test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.lang.ref.ReferenceQueue#remove()
+	 */
+	public void test_remove() {
+		// store in a static so it won't be gc'ed because the jit
+		// optimized it out
+		b = new Boolean(true);
+		SoftReference sr = new SoftReference(b, rq);
+		sr.enqueue();
+		try {
+			assertTrue("Remove failed.", ((Boolean) rq.remove().get())
+					.booleanValue());
+		} catch (Exception e) {
+			fail("Exception during the test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.lang.ref.ReferenceQueue#remove(long)
+	 */
+	public void test_removeJ() {
+		try {
+			assertTrue("Queue is empty.", rq.poll() == null);
+			assertTrue("Queue is empty.", rq.remove((long) 1) == null);
+			Thread ct = new Thread(new ChildThread());
+			ct.start();
+			Reference ret = rq.remove(0L);
+			assertTrue("Delayed remove failed.", ret != null);
+		} catch (InterruptedException e) {
+			fail("InterruptedExeException during test : " + e.getMessage());
+		}
+		catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.lang.ref.ReferenceQueue#ReferenceQueue()
+	 */
+	public void test_Constructor() {
+		assertTrue("Used for testing.", true);
+	}
+
+	protected void setUp() {
+		rq = new ReferenceQueue();
+	}
+
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/ReferenceTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/ReferenceTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/ReferenceTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/ReferenceTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,171 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.java.lang.ref;
+
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
+import java.lang.ref.WeakReference;
+
+public class ReferenceTest extends junit.framework.TestCase {
+	Object tmpA, tmpB, obj;
+
+	volatile WeakReference wr;
+
+	protected void doneSuite() {
+		tmpA = tmpB = obj = null;
+	}
+
+	/**
+	 * @tests java.lang.ref.Reference#clear()
+	 */
+	public void test_clear() {
+		tmpA = new Object();
+		tmpB = new Object();
+		SoftReference sr = new SoftReference(tmpA, new ReferenceQueue());
+		WeakReference wr = new WeakReference(tmpB, new ReferenceQueue());
+		assertTrue("Start: Object not cleared.", (sr.get() != null)
+				&& (wr.get() != null));
+		sr.clear();
+		wr.clear();
+		assertTrue("End: Object cleared.", (sr.get() == null)
+				&& (wr.get() == null));
+		// Must reference tmpA and tmpB so the jit does not optimize them away
+		assertTrue("should always pass", tmpA != sr.get() && tmpB != wr.get());
+	}
+
+	/**
+	 * @tests java.lang.ref.Reference#enqueue()
+	 */
+	public void test_enqueue() {
+		ReferenceQueue rq = new ReferenceQueue();
+		obj = new Object();
+		Reference ref = new SoftReference(obj, rq);
+		assertTrue("Enqueue failed.", (!ref.isEnqueued())
+				&& ((ref.enqueue()) && (ref.isEnqueued())));
+		assertTrue("Not properly enqueued.", rq.poll().get() == obj);
+		// This fails...
+		assertTrue("Should remain enqueued.", !ref.isEnqueued());
+		assertTrue("Can not enqueue twice.", (!ref.enqueue())
+				&& (rq.poll() == null));
+
+		rq = new ReferenceQueue();
+		obj = new Object();
+		ref = new WeakReference(obj, rq);
+		assertTrue("Enqueue failed2.", (!ref.isEnqueued())
+				&& ((ref.enqueue()) && (ref.isEnqueued())));
+		assertTrue("Not properly enqueued2.", rq.poll().get() == obj);
+		assertTrue("Should remain enqueued2.", !ref.isEnqueued()); // This
+		// fails.
+		assertTrue("Can not enqueue twice2.", (!ref.enqueue())
+				&& (rq.poll() == null));
+	}
+
+	/**
+	 * @tests java.lang.ref.Reference#enqueue()
+	 */
+	public void test_general() {
+		// Test the general/overall functionality of Reference.
+
+		class TestObject {
+			public boolean finalized;
+
+			public TestObject() {
+				finalized = false;
+			}
+
+			protected void finalize() {
+				finalized = true;
+			}
+		}
+
+		final ReferenceQueue rq = new ReferenceQueue();
+
+		class TestThread extends Thread {
+			public void run() {
+				// Create the object in a separate thread to ensure it will be
+				// gc'ed
+				Object testObj = new TestObject();
+				wr = new WeakReference(testObj, rq);
+				testObj = null;
+			}
+		}
+
+		Reference ref;
+
+		try {
+			Thread t = new TestThread();
+			t.start();
+			t.join();
+			System.gc();
+			System.runFinalization();
+			ref = rq.remove();
+			assertTrue("Unexpected ref1", ref == wr);
+			assertTrue("Object not garbage collected1.", ref != null);
+			assertTrue("Object could not be reclaimed1.", wr.get() == null);
+		} catch (InterruptedException e) {
+			fail("InterruptedException : " + e.getMessage());
+		}
+
+		try {
+			Thread t = new TestThread();
+			t.start();
+			t.join();
+			System.gc();
+			System.runFinalization();
+			ref = rq.poll();
+			assertTrue("Unexpected ref2", ref == wr);
+			assertTrue("Object not garbage collected.", ref != null);
+			assertTrue("Object could not be reclaimed.", ref.get() == null);
+			// Reference wr so it does not get collected
+			assertTrue("Object could not be reclaimed.", wr.get() == null);
+		} catch (Exception e) {
+			fail("Exception : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.lang.ref.Reference#get()
+	 */
+	public void test_get() {
+		// SM.
+		obj = new Object();
+		Reference ref = new WeakReference(obj, new ReferenceQueue());
+		assertTrue("Get succeeded.", ref.get() == obj);
+	}
+
+	/**
+	 * @tests java.lang.ref.Reference#isEnqueued()
+	 */
+	public void test_isEnqueued() {
+		ReferenceQueue rq = new ReferenceQueue();
+		obj = new Object();
+		Reference ref = new SoftReference(obj, rq);
+		assertTrue("Should start off not enqueued.", !ref.isEnqueued());
+		ref.enqueue();
+		assertTrue("Should now be enqueued.", ref.isEnqueued());
+		ref.enqueue();
+		assertTrue("Should still be enqueued.", ref.isEnqueued());
+		rq.poll();
+		// This fails ...
+		assertTrue("Should now be not enqueued.", !ref.isEnqueued());
+	}
+
+	protected void setUp() {
+	}
+
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/SoftReferenceTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/SoftReferenceTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/SoftReferenceTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/SoftReferenceTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,79 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.java.lang.ref;
+
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
+
+public class SoftReferenceTest extends junit.framework.TestCase {
+	static Boolean bool;
+
+	protected void doneSuite() {
+		bool = null;
+	}
+
+	/**
+	 * @tests java.lang.ref.SoftReference#SoftReference(java.lang.Object,
+	 *        java.lang.ref.ReferenceQueue)
+	 */
+	public void test_ConstructorLjava_lang_ObjectLjava_lang_ref_ReferenceQueue() {
+		ReferenceQueue rq = new ReferenceQueue();
+		bool = new Boolean(true);
+		try {
+			SoftReference sr = new SoftReference(bool, rq);
+			assertTrue("Initialization failed.", ((Boolean) sr.get())
+					.booleanValue());
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+
+		boolean exception = false;
+		try {
+			new SoftReference(bool, null);
+		} catch (NullPointerException e) {
+			exception = true;
+		}
+		assertTrue("Should not throw NullPointerException", !exception);
+	}
+
+	/**
+	 * @tests java.lang.ref.SoftReference#SoftReference(java.lang.Object)
+	 */
+	public void test_ConstructorLjava_lang_Object() {
+		bool = new Boolean(true);
+		try {
+			SoftReference sr = new SoftReference(bool);
+			assertTrue("Initialization failed.", ((Boolean) sr.get())
+					.booleanValue());
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.lang.ref.SoftReference#get()
+	 */
+	public void test_get() {
+		bool = new Boolean(false);
+		SoftReference sr = new SoftReference(bool);
+		assertTrue("Same object not returned.", bool == sr.get());
+	}
+
+	protected void setUp() {
+	}
+
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/WeakReferenceTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/WeakReferenceTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/WeakReferenceTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ref/WeakReferenceTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,78 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang.ref;
+
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.WeakReference;
+
+public class WeakReferenceTest extends junit.framework.TestCase {
+	static Boolean bool;
+
+	protected void doneSuite() {
+		bool = null;
+	}
+
+	/**
+	 * @tests java.lang.ref.WeakReference#WeakReference(java.lang.Object,
+	 *        java.lang.ref.ReferenceQueue)
+	 */
+	public void test_ConstructorLjava_lang_ObjectLjava_lang_ref_ReferenceQueue() {
+		ReferenceQueue rq = new ReferenceQueue();
+		bool = new Boolean(true);
+		try {
+			// Allow the finalizer to run to potentially enqueue
+			WeakReference wr = new WeakReference(bool, rq);
+			assertTrue("Initialization failed.", ((Boolean) wr.get())
+					.booleanValue());
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+		// need a reference to bool so the jit does not optimize it away
+		assertTrue("should always pass", bool.booleanValue());
+
+		boolean exception = false;
+		try {
+			new WeakReference(bool, null);
+		} catch (NullPointerException e) {
+			exception = true;
+		}
+		assertTrue("Should not throw NullPointerException", !exception);
+	}
+
+	/**
+	 * @tests java.lang.ref.WeakReference#WeakReference(java.lang.Object)
+	 */
+	public void test_ConstructorLjava_lang_Object() {
+		bool = new Boolean(true);
+		try {
+			WeakReference wr = new WeakReference(bool);
+			// Allow the finalizer to run to potentially enqueue
+			Thread.sleep(1000);
+			assertTrue("Initialization failed.", ((Boolean) wr.get())
+					.booleanValue());
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+		// need a reference to bool so the jit does not optimize it away
+		assertTrue("should always pass", bool.booleanValue());
+	}
+
+	protected void setUp() {
+	}
+
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/reflect/AccessibleObjectTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/reflect/AccessibleObjectTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/reflect/AccessibleObjectTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/reflect/AccessibleObjectTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,85 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang.reflect;
+
+import java.lang.reflect.AccessibleObject;
+
+public class AccessibleObjectTest extends junit.framework.TestCase {
+
+	public class TestClass {
+		public Object aField;
+	}
+
+	/**
+	 * @tests java.lang.reflect.AccessibleObject#isAccessible()
+	 */
+	public void test_isAccessible() {
+		// Test for method boolean
+		// java.lang.reflect.AccessibleObject.isAccessible()
+		try {
+			AccessibleObject ao = TestClass.class.getField("aField");
+			ao.setAccessible(true);
+			assertTrue("Returned false to isAccessible", ao.isAccessible());
+			ao.setAccessible(false);
+			assertTrue("Returned true to isAccessible", !ao.isAccessible());
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.lang.reflect.AccessibleObject#setAccessible(java.lang.reflect.AccessibleObject[],
+	 *        boolean)
+	 */
+	public void test_setAccessible$Ljava_lang_reflect_AccessibleObjectZ() {
+		// Test for method void
+		// java.lang.reflect.AccessibleObject.setAccessible(java.lang.reflect.AccessibleObject
+		// [], boolean)
+		try {
+			AccessibleObject ao = TestClass.class.getField("aField");
+			AccessibleObject[] aoa = new AccessibleObject[] { ao };
+			AccessibleObject.setAccessible(aoa, true);
+			assertTrue("Returned false to isAccessible", ao.isAccessible());
+			AccessibleObject.setAccessible(aoa, false);
+			assertTrue("Returned true to isAccessible", !ao.isAccessible());
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.lang.reflect.AccessibleObject#setAccessible(boolean)
+	 */
+	public void test_setAccessibleZ() {
+		// Test for method void
+		// java.lang.reflect.AccessibleObject.setAccessible(boolean)
+		assertTrue("Used to test", true);
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/reflect/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/reflect/AllTests.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/reflect/AllTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/reflect/AllTests.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,45 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang.reflect;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite for java.lang.reflect package.
+ */
+public class AllTests {
+
+	public static void main(String[] args) {
+		junit.textui.TestRunner.run(suite());
+	}
+
+	public static Test suite() {
+		TestSuite suite = new TestSuite("Tests for java.lang.reflect");
+		// $JUnit-BEGIN$
+		suite.addTestSuite(AccessibleObjectTest.class);
+		suite.addTestSuite(ArrayTest.class);
+		suite.addTestSuite(ConstructorTest.class);
+		suite.addTestSuite(FieldTest.class);
+		suite.addTestSuite(InvocationTargetExceptionTest.class);
+		suite.addTestSuite(MethodTest.class);
+		suite.addTestSuite(ModifierTest.class);
+		suite.addTestSuite(ProxyTest.class);
+		suite.addTestSuite(ReflectPermissionTest.class);
+		// $JUnit-END$
+		return suite;
+	}
+}