harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r386058 [40/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/...
Date Wed, 15 Mar 2006 11:47:39 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeMapTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeMapTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeMapTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeMapTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,393 @@
+/* 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.util;
+
+import java.util.AbstractMap;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import tests.support.Support_MapTest2;
+import tests.support.Support_UnmodifiableCollectionTest;
+
+public class TreeMapTest extends junit.framework.TestCase {
+
+	public static class ReversedComparator implements Comparator {
+		public int compare(Object o1, Object o2) {
+			return -(((Comparable) o1).compareTo((Comparable) o2));
+		}
+
+		public boolean equals(Object o1, Object o2) {
+			return (((Comparable) o1).compareTo((Comparable) o2)) == 0;
+		}
+	}
+
+	TreeMap tm;
+
+	Object objArray[] = new Object[1000];
+
+	/**
+	 * @tests java.util.TreeMap#TreeMap()
+	 */
+	public void test_Constructor() {
+		// Test for method java.util.TreeMap()
+		new Support_MapTest2(new TreeMap()).runTest();
+
+		assertTrue("New treeMap non-empty", new TreeMap().isEmpty());
+	}
+
+	/**
+	 * @tests java.util.TreeMap#TreeMap(java.util.Comparator)
+	 */
+	public void test_ConstructorLjava_util_Comparator() {
+		// Test for method java.util.TreeMap(java.util.Comparator)
+		Comparator comp = new ReversedComparator();
+		TreeMap reversedTreeMap = new TreeMap(comp);
+		assertTrue("TreeMap answered incorrect comparator", reversedTreeMap
+				.comparator() == comp);
+		reversedTreeMap.put(new Integer(1).toString(), new Integer(1));
+		reversedTreeMap.put(new Integer(2).toString(), new Integer(2));
+		assertTrue("TreeMap does not use comparator (firstKey was incorrect)",
+				reversedTreeMap.firstKey().equals(new Integer(2).toString()));
+		assertTrue("TreeMap does not use comparator (lastKey was incorrect)",
+				reversedTreeMap.lastKey().equals(new Integer(1).toString()));
+
+	}
+
+	/**
+	 * @tests java.util.TreeMap#TreeMap(java.util.Map)
+	 */
+	public void test_ConstructorLjava_util_Map() {
+		// Test for method java.util.TreeMap(java.util.Map)
+		TreeMap myTreeMap = new TreeMap(new HashMap(tm));
+		assertTrue("Map is incorrect size", myTreeMap.size() == objArray.length);
+		for (int counter = 0; counter < objArray.length; counter++)
+			assertTrue("Map has incorrect mappings", myTreeMap.get(
+					objArray[counter].toString()).equals(objArray[counter]));
+	}
+
+	/**
+	 * @tests java.util.TreeMap#TreeMap(java.util.SortedMap)
+	 */
+	public void test_ConstructorLjava_util_SortedMap() {
+		// Test for method java.util.TreeMap(java.util.SortedMap)
+		Comparator comp = new ReversedComparator();
+		TreeMap reversedTreeMap = new TreeMap(comp);
+		reversedTreeMap.put(new Integer(1).toString(), new Integer(1));
+		reversedTreeMap.put(new Integer(2).toString(), new Integer(2));
+		TreeMap anotherTreeMap = new TreeMap(reversedTreeMap);
+		assertTrue("New tree map does not answer correct comparator",
+				anotherTreeMap.comparator() == comp);
+		assertTrue("TreeMap does not use comparator (firstKey was incorrect)",
+				anotherTreeMap.firstKey().equals(new Integer(2).toString()));
+		assertTrue("TreeMap does not use comparator (lastKey was incorrect)",
+				anotherTreeMap.lastKey().equals(new Integer(1).toString()));
+
+	}
+
+	/**
+	 * @tests java.util.TreeMap#clear()
+	 */
+	public void test_clear() {
+		// Test for method void java.util.TreeMap.clear()
+		tm.clear();
+		assertTrue("Cleared map returned non-zero size", tm.size() == 0);
+	}
+
+	/**
+	 * @tests java.util.TreeMap#clone()
+	 */
+	public void test_clone() {
+		// Test for method java.lang.Object java.util.TreeMap.clone()
+		TreeMap clonedMap = (TreeMap) tm.clone();
+		assertTrue("Cloned map does not equal the original map", clonedMap
+				.equals(tm));
+		assertTrue("Cloned map is the same reference as the original map",
+				clonedMap != tm);
+		for (int counter = 0; counter < objArray.length; counter++)
+			assertTrue("Cloned map contains incorrect elements", clonedMap
+					.get(objArray[counter].toString()) == tm
+					.get(objArray[counter].toString()));
+
+		TreeMap map = new TreeMap();
+		map.put("key", "value");
+		// get the keySet() and values() on the original Map
+		Set keys = map.keySet();
+		Collection values = map.values();
+		assertTrue("values() does not work", values.iterator().next().equals(
+				"value"));
+		assertTrue("keySet() does not work", keys.iterator().next().equals(
+				"key"));
+		AbstractMap map2 = (AbstractMap) map.clone();
+		map2.put("key", "value2");
+		Collection values2 = map2.values();
+		assertTrue("values() is identical", values2 != values);
+		// values() and keySet() on the cloned() map should be different
+		assertTrue("values() was not cloned", values2.iterator().next().equals(
+				"value2"));
+		map2.clear();
+		map2.put("key2", "value3");
+		Set key2 = map2.keySet();
+		assertTrue("keySet() is identical", key2 != keys);
+		assertTrue("keySet() was not cloned", key2.iterator().next().equals(
+				"key2"));
+	}
+
+	/**
+	 * @tests java.util.TreeMap#comparator()
+	 */
+	public void test_comparator() {
+		// Test for method java.util.Comparator java.util.TreeMap.comparator()\
+		Comparator comp = new ReversedComparator();
+		TreeMap reversedTreeMap = new TreeMap(comp);
+		assertTrue("TreeMap answered incorrect comparator", reversedTreeMap
+				.comparator() == comp);
+		reversedTreeMap.put(new Integer(1).toString(), new Integer(1));
+		reversedTreeMap.put(new Integer(2).toString(), new Integer(2));
+		assertTrue("TreeMap does not use comparator (firstKey was incorrect)",
+				reversedTreeMap.firstKey().equals(new Integer(2).toString()));
+		assertTrue("TreeMap does not use comparator (lastKey was incorrect)",
+				reversedTreeMap.lastKey().equals(new Integer(1).toString()));
+	}
+
+	/**
+	 * @tests java.util.TreeMap#containsKey(java.lang.Object)
+	 */
+	public void test_containsKeyLjava_lang_Object() {
+		// Test for method boolean
+		// java.util.TreeMap.containsKey(java.lang.Object)
+		assertTrue("Returned false for valid key", tm.containsKey("95"));
+		assertTrue("Returned true for invalid key", !tm.containsKey("XXXXX"));
+	}
+
+	/**
+	 * @tests java.util.TreeMap#containsValue(java.lang.Object)
+	 */
+	public void test_containsValueLjava_lang_Object() {
+		// Test for method boolean
+		// java.util.TreeMap.containsValue(java.lang.Object)
+		assertTrue("Returned false for valid value", tm
+				.containsValue(objArray[986]));
+		assertTrue("Returned true for invalid value", !tm
+				.containsValue(new Object()));
+	}
+
+	/**
+	 * @tests java.util.TreeMap#entrySet()
+	 */
+	public void test_entrySet() {
+		// Test for method java.util.Set java.util.TreeMap.entrySet()
+		Set anEntrySet = tm.entrySet();
+		Iterator entrySetIterator = anEntrySet.iterator();
+		assertTrue("EntrySet is incorrect size",
+				anEntrySet.size() == objArray.length);
+		Map.Entry entry;
+		while (entrySetIterator.hasNext()) {
+			entry = (Map.Entry) entrySetIterator.next();
+			assertTrue("EntrySet does not contain correct mappings", tm
+					.get(entry.getKey()) == entry.getValue());
+		}
+	}
+
+	/**
+	 * @tests java.util.TreeMap#firstKey()
+	 */
+	public void test_firstKey() {
+		// Test for method java.lang.Object java.util.TreeMap.firstKey()
+		assertTrue("Returned incorrect first key", tm.firstKey().equals("0"));
+	}
+
+	/**
+	 * @tests java.util.TreeMap#get(java.lang.Object)
+	 */
+	public void test_getLjava_lang_Object() {
+		// Test for method java.lang.Object
+		// java.util.TreeMap.get(java.lang.Object)
+		Object o = new Object();
+		tm.put("Hello", o);
+		assertTrue("Failed to get mapping", tm.get("Hello") == o);
+
+	}
+
+	/**
+	 * @tests java.util.TreeMap#headMap(java.lang.Object)
+	 */
+	public void test_headMapLjava_lang_Object() {
+		// Test for method java.util.SortedMap
+		// java.util.TreeMap.headMap(java.lang.Object)
+		Map head = tm.headMap("100");
+		assertTrue("Returned map of incorrect size", head.size() == 3);
+		assertTrue("Returned incorrect elements", head.containsKey("0")
+				&& head.containsValue(new Integer("1"))
+				&& head.containsKey("10"));
+	}
+
+	/**
+	 * @tests java.util.TreeMap#keySet()
+	 */
+	public void test_keySet() {
+		// Test for method java.util.Set java.util.TreeMap.keySet()
+		Set ks = tm.keySet();
+		assertTrue("Returned set of incorrect size",
+				ks.size() == objArray.length);
+		for (int i = 0; i < tm.size(); i++)
+			assertTrue("Returned set is missing keys", ks.contains(new Integer(
+					i).toString()));
+	}
+
+	/**
+	 * @tests java.util.TreeMap#lastKey()
+	 */
+	public void test_lastKey() {
+		// Test for method java.lang.Object java.util.TreeMap.lastKey()
+		assertTrue("Returned incorrect last key", tm.lastKey().equals(
+				objArray[objArray.length - 1].toString()));
+	}
+
+	/**
+	 * @tests java.util.TreeMap#put(java.lang.Object, java.lang.Object)
+	 */
+	public void test_putLjava_lang_ObjectLjava_lang_Object() {
+		// Test for method java.lang.Object
+		// java.util.TreeMap.put(java.lang.Object, java.lang.Object)
+		Object o = new Object();
+		tm.put("Hello", o);
+		assertTrue("Failed to put mapping", tm.get("Hello") == o);
+
+	}
+
+	/**
+	 * @tests java.util.TreeMap#putAll(java.util.Map)
+	 */
+	public void test_putAllLjava_util_Map() {
+		// Test for method void java.util.TreeMap.putAll(java.util.Map)
+		TreeMap x = new TreeMap();
+		x.putAll(tm);
+		assertTrue("Map incorrect size after put", x.size() == tm.size());
+		for (int i = 0; i < objArray.length; i++)
+			assertTrue("Failed to put all elements", x.get(
+					objArray[i].toString()).equals(objArray[i]));
+	}
+
+	/**
+	 * @tests java.util.TreeMap#remove(java.lang.Object)
+	 */
+	public void test_removeLjava_lang_Object() {
+		// Test for method java.lang.Object
+		// java.util.TreeMap.remove(java.lang.Object)
+		tm.remove("990");
+		assertTrue("Failed to remove mapping", !tm.containsKey("990"));
+
+	}
+
+	/**
+	 * @tests java.util.TreeMap#size()
+	 */
+	public void test_size() {
+		// Test for method int java.util.TreeMap.size()
+		assertTrue("Returned incorrect size", tm.size() == 1000);
+	}
+
+	/**
+	 * @tests java.util.TreeMap#subMap(java.lang.Object, java.lang.Object)
+	 */
+	public void test_subMapLjava_lang_ObjectLjava_lang_Object() {
+		// Test for method java.util.SortedMap
+		// java.util.TreeMap.subMap(java.lang.Object, java.lang.Object)
+		SortedMap subMap = tm.subMap(objArray[100].toString(), objArray[109]
+				.toString());
+		assertTrue("subMap is of incorrect size", subMap.size() == 9);
+		for (int counter = 100; counter < 109; counter++)
+			assertTrue("SubMap contains incorrect elements", subMap.get(
+					objArray[counter].toString()).equals(objArray[counter]));
+
+		int result;
+		try {
+			tm.subMap(objArray[9].toString(), objArray[1].toString());
+			result = 0;
+		} catch (IllegalArgumentException e) {
+			result = 1;
+		}
+		assertTrue(
+				"end key less than start key should throw IllegalArgumentException",
+				result == 1);
+	}
+
+	/**
+	 * @tests java.util.TreeMap#tailMap(java.lang.Object)
+	 */
+	public void test_tailMapLjava_lang_Object() {
+		// Test for method java.util.SortedMap
+		// java.util.TreeMap.tailMap(java.lang.Object)
+		Map tail = tm.tailMap(objArray[900].toString());
+		assertTrue("Returned map of incorrect size : " + tail.size(), tail
+				.size() == (objArray.length - 900) + 9);
+		for (int i = 900; i < objArray.length; i++)
+			assertTrue("Map contains incorrect entries", tail
+					.containsValue(objArray[i]));
+	}
+
+	/**
+	 * @tests java.util.TreeMap#values()
+	 */
+	public void test_values() {
+		// Test for method java.util.Collection java.util.TreeMap.values()
+		Collection vals = tm.values();
+		vals.iterator();
+		assertTrue("Returned collection of incorrect size",
+				vals.size() == objArray.length);
+		for (int i = 0; i < objArray.length; i++)
+			assertTrue("Collection contains incorrect elements", vals
+					.contains(objArray[i]));
+
+		TreeMap myTreeMap = new TreeMap();
+		for (int i = 0; i < 100; i++)
+			myTreeMap.put(objArray[i], objArray[i]);
+		Collection values = myTreeMap.values();
+		new Support_UnmodifiableCollectionTest(
+				"Test Returned Collection From TreeMap.values()", values)
+				.runTest();
+		values.remove(new Integer(0));
+		assertTrue(
+				"Removing from the values collection should remove from the original map",
+				!myTreeMap.containsValue(new Integer(0)));
+
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+		tm = new TreeMap();
+		for (int i = 0; i < objArray.length; i++) {
+			Object x = objArray[i] = new Integer(i);
+			tm.put(x.toString(), x);
+		}
+	}
+
+	/**
+	 * 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/util/TreeSetTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeSetTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeSetTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeSetTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,315 @@
+/* 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.util;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+public class TreeSetTest extends junit.framework.TestCase {
+
+	public static class ReversedIntegerComparator implements Comparator {
+		public int compare(Object o1, Object o2) {
+			return -(((Integer) o1).compareTo((Integer) o2));
+		}
+
+		public boolean equals(Object o1, Object o2) {
+			return ((Integer) o1).compareTo((Integer) o2) == 0;
+		}
+	}
+
+	TreeSet ts;
+
+	Object objArray[] = new Object[1000];
+
+	/**
+	 * @tests java.util.TreeSet#TreeSet()
+	 */
+	public void test_Constructor() {
+		// Test for method java.util.TreeSet()
+		assertTrue("Did not construct correct TreeSet", new TreeSet().isEmpty());
+	}
+
+	/**
+	 * @tests java.util.TreeSet#TreeSet(java.util.Collection)
+	 */
+	public void test_ConstructorLjava_util_Collection() {
+		// Test for method java.util.TreeSet(java.util.Collection)
+		TreeSet myTreeSet = new TreeSet(Arrays.asList(objArray));
+		assertTrue("TreeSet incorrect size",
+				myTreeSet.size() == objArray.length);
+		for (int counter = 0; counter < objArray.length; counter++)
+			assertTrue("TreeSet does not contain correct elements", myTreeSet
+					.contains(objArray[counter]));
+	}
+
+	/**
+	 * @tests java.util.TreeSet#TreeSet(java.util.Comparator)
+	 */
+	public void test_ConstructorLjava_util_Comparator() {
+		// Test for method java.util.TreeSet(java.util.Comparator)
+		TreeSet myTreeSet = new TreeSet(new ReversedIntegerComparator());
+		assertTrue("Did not construct correct TreeSet", myTreeSet.isEmpty());
+		myTreeSet.add(new Integer(1));
+		myTreeSet.add(new Integer(2));
+		assertTrue(
+				"Answered incorrect first element--did not use custom comparator ",
+				myTreeSet.first().equals(new Integer(2)));
+		assertTrue(
+				"Answered incorrect last element--did not use custom comparator ",
+				myTreeSet.last().equals(new Integer(1)));
+	}
+
+	/**
+	 * @tests java.util.TreeSet#TreeSet(java.util.SortedSet)
+	 */
+	public void test_ConstructorLjava_util_SortedSet() {
+		// Test for method java.util.TreeSet(java.util.SortedSet)
+		ReversedIntegerComparator comp = new ReversedIntegerComparator();
+		TreeSet myTreeSet = new TreeSet(comp);
+		for (int i = 0; i < objArray.length; i++)
+			myTreeSet.add(objArray[i]);
+		TreeSet anotherTreeSet = new TreeSet(myTreeSet);
+		assertTrue("TreeSet is not correct size",
+				anotherTreeSet.size() == objArray.length);
+		for (int counter = 0; counter < objArray.length; counter++)
+			assertTrue("TreeSet does not contain correct elements",
+					anotherTreeSet.contains(objArray[counter]));
+		assertTrue("TreeSet does not answer correct comparator", anotherTreeSet
+				.comparator() == comp);
+		assertTrue("TreeSet does not use comparator",
+				anotherTreeSet.first() == objArray[objArray.length - 1]);
+	}
+
+	/**
+	 * @tests java.util.TreeSet#add(java.lang.Object)
+	 */
+	public void test_addLjava_lang_Object() {
+		// Test for method boolean java.util.TreeSet.add(java.lang.Object)
+		ts.add(new Integer(-8));
+		assertTrue("Failed to add Object", ts.contains(new Integer(-8)));
+		ts.add(objArray[0]);
+		assertTrue("Added existing element", ts.size() == objArray.length + 1);
+
+	}
+
+	/**
+	 * @tests java.util.TreeSet#addAll(java.util.Collection)
+	 */
+	public void test_addAllLjava_util_Collection() {
+		// Test for method boolean
+		// java.util.TreeSet.addAll(java.util.Collection)
+		TreeSet s = new TreeSet();
+		s.addAll(ts);
+		assertTrue("Incorrect size after add", s.size() == ts.size());
+		Iterator i = ts.iterator();
+		while (i.hasNext())
+			assertTrue("Returned incorrect set", s.contains(i.next()));
+
+	}
+
+	/**
+	 * @tests java.util.TreeSet#clear()
+	 */
+	public void test_clear() {
+		// Test for method void java.util.TreeSet.clear()
+		ts.clear();
+		assertTrue("Returned non-zero size after clear", ts.size() == 0);
+		assertTrue("Found element in cleared set", !ts.contains(objArray[0]));
+	}
+
+	/**
+	 * @tests java.util.TreeSet#clone()
+	 */
+	public void test_clone() {
+		// Test for method java.lang.Object java.util.TreeSet.clone()
+		TreeSet s = (TreeSet) ts.clone();
+		Iterator i = ts.iterator();
+		while (i.hasNext())
+			assertTrue("Clone failed to copy all elements", s
+					.contains(i.next()));
+	}
+
+	/**
+	 * @tests java.util.TreeSet#comparator()
+	 */
+	public void test_comparator() {
+		// Test for method java.util.Comparator java.util.TreeSet.comparator()
+		ReversedIntegerComparator comp = new ReversedIntegerComparator();
+		TreeSet myTreeSet = new TreeSet(comp);
+		assertTrue("Answered incorrect comparator",
+				myTreeSet.comparator() == comp);
+	}
+
+	/**
+	 * @tests java.util.TreeSet#contains(java.lang.Object)
+	 */
+	public void test_containsLjava_lang_Object() {
+		// Test for method boolean java.util.TreeSet.contains(java.lang.Object)
+		assertTrue("Returned false for valid Object", ts
+				.contains(objArray[objArray.length / 2]));
+		assertTrue("Returned true for invalid Object", !ts
+				.contains(new Integer(-9)));
+		try {
+			ts.contains(new Object());
+		} catch (ClassCastException e) {
+			// Correct
+			return;
+		}
+		fail("Failed to throw exception when passed invalid element");
+
+	}
+
+	/**
+	 * @tests java.util.TreeSet#first()
+	 */
+	public void test_first() {
+		// Test for method java.lang.Object java.util.TreeSet.first()
+		assertTrue("Returned incorrect first element",
+				ts.first() == objArray[0]);
+	}
+
+	/**
+	 * @tests java.util.TreeSet#headSet(java.lang.Object)
+	 */
+	public void test_headSetLjava_lang_Object() {
+		// Test for method java.util.SortedSet
+		// java.util.TreeSet.headSet(java.lang.Object)
+		Set s = ts.headSet(new Integer(100));
+		assertTrue("Returned set of incorrect size", s.size() == 100);
+		for (int i = 0; i < 100; i++)
+			assertTrue("Returned incorrect set", s.contains(objArray[i]));
+	}
+
+	/**
+	 * @tests java.util.TreeSet#isEmpty()
+	 */
+	public void test_isEmpty() {
+		// Test for method boolean java.util.TreeSet.isEmpty()
+		assertTrue("Empty set returned false", new TreeSet().isEmpty());
+		assertTrue("Non-Empty returned true", !ts.isEmpty());
+	}
+
+	/**
+	 * @tests java.util.TreeSet#iterator()
+	 */
+	public void test_iterator() {
+		// Test for method java.util.Iterator java.util.TreeSet.iterator()
+		TreeSet s = new TreeSet();
+		s.addAll(ts);
+		Iterator i = ts.iterator();
+		Set as = new HashSet(Arrays.asList(objArray));
+		while (i.hasNext())
+			as.remove(i.next());
+		assertTrue("Returned incorrect iterator", as.size() == 0);
+
+	}
+
+	/**
+	 * @tests java.util.TreeSet#last()
+	 */
+	public void test_last() {
+		// Test for method java.lang.Object java.util.TreeSet.last()
+		assertTrue("Returned incorrect last element",
+				ts.last() == objArray[objArray.length - 1]);
+	}
+
+	/**
+	 * @tests java.util.TreeSet#remove(java.lang.Object)
+	 */
+	public void test_removeLjava_lang_Object() {
+		// Test for method boolean java.util.TreeSet.remove(java.lang.Object)
+		ts.remove(objArray[0]);
+		assertTrue("Failed to remove object", !ts.contains(objArray[0]));
+		assertTrue("Failed to change size after remove",
+				ts.size() == objArray.length - 1);
+		try {
+			ts.remove(new Object());
+		} catch (ClassCastException e) {
+			// Correct
+			return;
+		}
+		fail("Failed to throw exception when past uncomparable value");
+	}
+
+	/**
+	 * @tests java.util.TreeSet#size()
+	 */
+	public void test_size() {
+		// Test for method int java.util.TreeSet.size()
+		assertTrue("Returned incorrect size", ts.size() == objArray.length);
+	}
+
+	/**
+	 * @tests java.util.TreeSet#subSet(java.lang.Object, java.lang.Object)
+	 */
+	public void test_subSetLjava_lang_ObjectLjava_lang_Object() {
+		// Test for method java.util.SortedSet
+		// java.util.TreeSet.subSet(java.lang.Object, java.lang.Object)
+		final int startPos = objArray.length / 4;
+		final int endPos = 3 * objArray.length / 4;
+		SortedSet aSubSet = ts.subSet(objArray[startPos], objArray[endPos]);
+		assertTrue("Subset has wrong number of elements",
+				aSubSet.size() == (endPos - startPos));
+		for (int counter = startPos; counter < endPos; counter++)
+			assertTrue("Subset does not contain all the elements it should",
+					aSubSet.contains(objArray[counter]));
+
+		int result;
+		try {
+			ts.subSet(objArray[3], objArray[0]);
+			result = 0;
+		} catch (IllegalArgumentException e) {
+			result = 1;
+		}
+		assertTrue("end less than start should throw", result == 1);
+	}
+
+	/**
+	 * @tests java.util.TreeSet#tailSet(java.lang.Object)
+	 */
+	public void test_tailSetLjava_lang_Object() {
+		// Test for method java.util.SortedSet
+		// java.util.TreeSet.tailSet(java.lang.Object)
+		Set s = ts.tailSet(new Integer(900));
+		assertTrue("Returned set of incorrect size", s.size() == 100);
+		for (int i = 900; i < objArray.length; i++)
+			assertTrue("Returned incorrect set", s.contains(objArray[i]));
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+		ts = new TreeSet();
+		for (int i = 0; i < objArray.length; i++) {
+			Object x = objArray[i] = new Integer(i);
+			ts.add(x);
+		}
+	}
+
+	/**
+	 * 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/util/VectorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/VectorTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/VectorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/VectorTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,905 @@
+/* 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.util;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Vector;
+
+import tests.support.Support_ListTest;
+
+public class VectorTest extends junit.framework.TestCase {
+
+	private Vector tVector = new Vector();
+
+	Object[] objArray;
+
+	private String vString = "[Test 0, Test 1, Test 2, Test 3, Test 4, Test 5, Test 6, Test 7, Test 8, Test 9, Test 10, Test 11, Test 12, Test 13, Test 14, Test 15, Test 16, Test 17, Test 18, Test 19, Test 20, Test 21, Test 22, Test 23, Test 24, Test 25, Test 26, Test 27, Test 28, Test 29, Test 30, Test 31, Test 32, Test 33, Test 34, Test 35, Test 36, Test 37, Test 38, Test 39, Test 40, Test 41, Test 42, Test 43, Test 44, Test 45, Test 46, Test 47, Test 48, Test 49, Test 50, Test 51, Test 52, Test 53, Test 54, Test 55, Test 56, Test 57, Test 58, Test 59, Test 60, Test 61, Test 62, Test 63, Test 64, Test 65, Test 66, Test 67, Test 68, Test 69, Test 70, Test 71, Test 72, Test 73, Test 74, Test 75, Test 76, Test 77, Test 78, Test 79, Test 80, Test 81, Test 82, Test 83, Test 84, Test 85, Test 86, Test 87, Test 88, Test 89, Test 90, Test 91, Test 92, Test 93, Test 94, Test 95, Test 96, Test 97, Test 98, Test 99]";
+
+	/**
+	 * @tests java.util.Vector#Vector()
+	 */
+	public void test_Constructor() {
+		// Test for method java.util.Vector()
+
+		Vector tv = new Vector(100);
+		for (int i = 0; i < 100; i++)
+			tv.addElement(new Integer(i));
+		new Support_ListTest("", tv).runTest();
+
+		tv = new Vector(200);
+		for (int i = -50; i < 150; i++)
+			tv.addElement(new Integer(i));
+		new Support_ListTest("", tv.subList(50, 150)).runTest();
+
+		Vector v = new Vector();
+		assertTrue("Vector creation failed", v.size() == 0);
+		assertTrue("Wrong capacity", v.capacity() == 10);
+	}
+
+	/**
+	 * @tests java.util.Vector#Vector(int)
+	 */
+	public void test_ConstructorI() {
+		// Test for method java.util.Vector(int)
+
+		Vector v = new Vector(100);
+		assertTrue("Vector creation failed", v.size() == 0);
+		assertTrue("Wrong capacity", v.capacity() == 100);
+	}
+
+	/**
+	 * @tests java.util.Vector#Vector(int, int)
+	 */
+	public void test_ConstructorII() {
+		// Test for method java.util.Vector(int, int)
+
+		Vector v = new Vector(2, 10);
+		v.addElement(new Object());
+		v.addElement(new Object());
+		v.addElement(new Object());
+
+		assertTrue("Failed to inc capacity by proper amount",
+				v.capacity() == 12);
+
+		Vector grow = new Vector(3, -1);
+		grow.addElement("one");
+		grow.addElement("two");
+		grow.addElement("three");
+		grow.addElement("four");
+		assertTrue("Wrong size", grow.size() == 4);
+		assertTrue("Wrong capacity", grow.capacity() == 6);
+	}
+
+	/**
+	 * @tests java.util.Vector#Vector(java.util.Collection)
+	 */
+	public void test_ConstructorLjava_util_Collection() {
+		// Test for method java.util.Vector(java.util.Collection)
+		Collection l = new LinkedList();
+		for (int i = 0; i < 100; i++)
+			l.add("Test " + i);
+		Vector myVector = new Vector(l);
+		assertTrue("Vector is not correct size",
+				myVector.size() == objArray.length);
+		for (int counter = 0; counter < objArray.length; counter++)
+			assertTrue("Vector does not contain correct elements", myVector
+					.contains(((List) l).get(counter)));
+	}
+
+	/**
+	 * @tests java.util.Vector#add(int, java.lang.Object)
+	 */
+	public void test_addILjava_lang_Object() {
+		// Test for method void java.util.Vector.add(int, java.lang.Object)
+		Object o = new Object();
+		Object prev = tVector.get(45);
+		tVector.add(45, o);
+		assertTrue("Failed to add Object", tVector.get(45) == o);
+		assertTrue("Failed to fix-up existing indices", tVector.get(46) == prev);
+		assertTrue("Wrong size after add", tVector.size() == 101);
+
+		prev = tVector.get(50);
+		tVector.add(50, null);
+		assertTrue("Failed to add null", tVector.get(50) == null);
+		assertTrue("Failed to fix-up existing indices after adding null",
+				tVector.get(51) == prev);
+		assertTrue("Wrong size after add", tVector.size() == 102);
+	}
+
+	/**
+	 * @tests java.util.Vector#add(java.lang.Object)
+	 */
+	public void test_addLjava_lang_Object() {
+		// Test for method boolean java.util.Vector.add(java.lang.Object)
+		Object o = new Object();
+		tVector.add(o);
+		assertTrue("Failed to add Object", tVector.lastElement() == o);
+		assertTrue("Wrong size after add", tVector.size() == 101);
+
+		tVector.add(null);
+		assertTrue("Failed to add null", tVector.lastElement() == null);
+		assertTrue("Wrong size after add", tVector.size() == 102);
+	}
+
+	/**
+	 * @tests java.util.Vector#addAll(int, java.util.Collection)
+	 */
+	public void test_addAllILjava_util_Collection() {
+		// Test for method boolean java.util.Vector.addAll(int,
+		// java.util.Collection)
+		Collection l = new LinkedList();
+		for (int i = 0; i < 100; i++)
+			l.add("Test " + i);
+		Vector v = new Vector();
+		tVector.addAll(50, l);
+		for (int i = 50; i < 100; i++)
+			assertTrue("Failed to add all elements",
+					tVector.get(i) == ((List) l).get(i - 50));
+		v = new Vector();
+		v.add("one");
+		int r = 0;
+		try {
+			v.addAll(3, Arrays.asList(new String[] { "two", "three" }));
+		} catch (ArrayIndexOutOfBoundsException e) {
+			r = 1;
+		} catch (IndexOutOfBoundsException e) {
+			r = 2;
+		}
+		assertTrue("Invalid add: " + r, r == 1);
+		l = new LinkedList();
+		l.add(null);
+		l.add("gah");
+		l.add(null);
+		tVector.addAll(50, l);
+		assertTrue("Wrong element at position 50--wanted null",
+				tVector.get(50) == null);
+		assertTrue("Wrong element at position 51--wanted 'gah'", tVector
+				.get(51).equals("gah"));
+		assertTrue("Wrong element at position 52--wanted null",
+				tVector.get(52) == null);
+	}
+
+	/**
+	 * @tests java.util.Vector#addAll(java.util.Collection)
+	 */
+	public void test_addAllLjava_util_Collection() {
+		// Test for method boolean java.util.Vector.addAll(java.util.Collection)
+		Vector v = new Vector();
+		Collection l = new LinkedList();
+		for (int i = 0; i < 100; i++)
+			l.add("Test " + i);
+		v.addAll(l);
+		assertTrue("Failed to add all elements", tVector.equals(v));
+
+		v.addAll(l);
+		int vSize = tVector.size();
+		for (int counter = vSize - 1; counter >= 0; counter--)
+			assertTrue("Failed to add elements correctly", v.get(counter) == v
+					.get(counter + vSize));
+
+		l = new LinkedList();
+		l.add(null);
+		l.add("gah");
+		l.add(null);
+		tVector.addAll(l);
+		assertTrue("Wrong element at 3rd last position--wanted null", tVector
+				.get(vSize) == null);
+		assertTrue("Wrong element at 2nd last position--wanted 'gah'", tVector
+				.get(vSize + 1).equals("gah"));
+		assertTrue("Wrong element at last position--wanted null", tVector
+				.get(vSize + 2) == null);
+	}
+
+	/**
+	 * @tests java.util.Vector#addElement(java.lang.Object)
+	 */
+	public void test_addElementLjava_lang_Object() {
+		// Test for method void java.util.Vector.addElement(java.lang.Object)
+		Vector v = vectorClone(tVector);
+		v.addElement("Added Element");
+		assertTrue("Failed to add element", v.contains("Added Element"));
+		assertTrue("Added Element to wrong slot", ((String) v.elementAt(100))
+				.equals("Added Element"));
+		v.addElement(null);
+		assertTrue("Failed to add null", v.contains(null));
+		assertTrue("Added null to wrong slot", v.elementAt(101) == null);
+	}
+
+	/**
+	 * @tests java.util.Vector#addElement(java.lang.Object)
+	 */
+	public void test_addElementLjava_lang_Object_subtest0() {
+		// Test for method void java.util.Vector.addElement(java.lang.Object)
+		Vector v = vectorClone(tVector);
+		v.addElement("Added Element");
+		assertTrue("Failed to add element", v.contains("Added Element"));
+		assertTrue("Added Element to wrong slot", ((String) v.elementAt(100))
+				.equals("Added Element"));
+		v.addElement(null);
+		assertTrue("Failed to add null", v.contains(null));
+		assertTrue("Added null to wrong slot", v.elementAt(101) == null);
+	}
+
+	/**
+	 * @tests java.util.Vector#capacity()
+	 */
+	public void test_capacity() {
+		// Test for method int java.util.Vector.capacity()
+
+		Vector v = new Vector(9);
+		assertTrue("Incorrect capacity returned", v.capacity() == 9);
+	}
+
+	/**
+	 * @tests java.util.Vector#clear()
+	 */
+	public void test_clear() {
+		// Test for method void java.util.Vector.clear()
+		Vector orgVector = vectorClone(tVector);
+		tVector.clear();
+		assertTrue("a) Cleared Vector has non-zero size", tVector.size() == 0);
+		Enumeration e = orgVector.elements();
+		while (e.hasMoreElements())
+			assertTrue("a) Cleared vector contained elements", !tVector
+					.contains(e.nextElement()));
+
+		tVector.add(null);
+		tVector.clear();
+		assertTrue("b) Cleared Vector has non-zero size", tVector.size() == 0);
+		e = orgVector.elements();
+		while (e.hasMoreElements())
+			assertTrue("b) Cleared vector contained elements", !tVector
+					.contains(e.nextElement()));
+	}
+
+	/**
+	 * @tests java.util.Vector#clone()
+	 */
+	public void test_clone() {
+		// Test for method java.lang.Object java.util.Vector.clone()
+		tVector.add(25, null);
+		tVector.add(75, null);
+		Vector v = (Vector) tVector.clone();
+		Enumeration orgNum = tVector.elements();
+		Enumeration cnum = v.elements();
+
+		while (orgNum.hasMoreElements()) {
+			assertTrue("Not enough elements copied", cnum.hasMoreElements());
+			assertTrue("Vector cloned improperly, elements do not match",
+					orgNum.nextElement() == cnum.nextElement());
+		}
+		assertTrue("Not enough elements copied", !cnum.hasMoreElements());
+
+	}
+
+	/**
+	 * @tests java.util.Vector#contains(java.lang.Object)
+	 */
+	public void test_containsLjava_lang_Object() {
+		// Test for method boolean java.util.Vector.contains(java.lang.Object)
+		assertTrue("Did not find element", tVector.contains("Test 42"));
+		assertTrue("Found bogus element", !tVector.contains("Hello"));
+		assertTrue(
+				"Returned true looking for null in vector without null element",
+				!tVector.contains(null));
+		tVector.insertElementAt(null, 20);
+		assertTrue(
+				"Returned false looking for null in vector with null element",
+				tVector.contains(null));
+	}
+
+	/**
+	 * @tests java.util.Vector#containsAll(java.util.Collection)
+	 */
+	public void test_containsAllLjava_util_Collection() {
+		// Test for method boolean
+		// java.util.Vector.containsAll(java.util.Collection)
+		Collection s = new HashSet();
+		for (int i = 0; i < 100; i++)
+			s.add("Test " + i);
+
+		assertTrue("Returned false for valid collection", tVector
+				.containsAll(s));
+		s.add(null);
+		assertTrue("Returned true for invlaid collection containing null",
+				!tVector.containsAll(s));
+		tVector.add(25, null);
+		assertTrue("Returned false for valid collection containing null",
+				tVector.containsAll(s));
+		s = new HashSet();
+		s.add(new Object());
+		assertTrue("Returned true for invalid collection", !tVector
+				.containsAll(s));
+	}
+
+	/**
+	 * @tests java.util.Vector#copyInto(java.lang.Object[])
+	 */
+	public void test_copyInto$Ljava_lang_Object() {
+		// Test for method void java.util.Vector.copyInto(java.lang.Object [])
+
+		Object[] a = new Object[100];
+		tVector.setElementAt(null, 20);
+		tVector.copyInto(a);
+
+		for (int i = 0; i < 100; i++)
+			assertTrue("copyInto failed", a[i] == tVector.elementAt(i));
+	}
+
+	/**
+	 * @tests java.util.Vector#elementAt(int)
+	 */
+	public void test_elementAtI() {
+		// Test for method java.lang.Object java.util.Vector.elementAt(int)
+		assertTrue("Incorrect element returned", ((String) tVector
+				.elementAt(18)).equals("Test 18"));
+		tVector.setElementAt(null, 20);
+		assertTrue("Incorrect element returned--wanted null", tVector
+				.elementAt(20) == null);
+
+	}
+
+	/**
+	 * @tests java.util.Vector#elements()
+	 */
+	public void test_elements() {
+		// Test for method java.util.Enumeration java.util.Vector.elements()
+		tVector.insertElementAt(null, 20);
+		Enumeration e = tVector.elements();
+		int i = 0;
+		while (e.hasMoreElements()) {
+			assertTrue("Enumeration returned incorrect element at pos: " + i, e
+					.nextElement() == tVector.elementAt(i));
+			i++;
+		}
+		assertTrue("Invalid enumeration", i == tVector.size());
+	}
+
+	/**
+	 * @tests java.util.Vector#elements()
+	 */
+	public void test_elements_subtest0() {
+		final int iterations = 10000;
+		final Vector v = new Vector();
+		Thread t1 = new Thread() {
+			public void run() {
+				for (int i = 0; i < iterations; i++) {
+					synchronized (v) {
+						v.addElement(String.valueOf(i));
+						v.removeElementAt(0);
+					}
+				}
+			}
+		};
+		t1.start();
+		for (int i = 0; i < iterations; i++) {
+			Enumeration en = v.elements();
+			try {
+				while (true) {
+					Object result = en.nextElement();
+					if (result == null) {
+						fail("Null result: " + i);
+					}
+				}
+			} catch (NoSuchElementException e) {
+			}
+		}
+	}
+
+	/**
+	 * @tests java.util.Vector#ensureCapacity(int)
+	 */
+	public void test_ensureCapacityI() {
+		// Test for method void java.util.Vector.ensureCapacity(int)
+
+		Vector v = new Vector(9);
+		v.ensureCapacity(20);
+		assertTrue("ensureCapacity failed to set correct capacity", v
+				.capacity() == 20);
+		v = new Vector(100);
+		assertTrue("ensureCapacity reduced capacity", v.capacity() == 100);
+	}
+
+	/**
+	 * @tests java.util.Vector#equals(java.lang.Object)
+	 */
+	public void test_equalsLjava_lang_Object() {
+		// Test for method boolean java.util.Vector.equals(java.lang.Object)
+		Vector v = new Vector();
+		for (int i = 0; i < 100; i++)
+			v.addElement("Test " + i);
+		assertTrue("a) Equal vectors returned false", tVector.equals(v));
+		v.addElement(null);
+		assertTrue("b) UnEqual vectors returned true", !tVector.equals(v));
+		tVector.addElement(null);
+		assertTrue("c) Equal vectors returned false", tVector.equals(v));
+		tVector.removeElementAt(22);
+		assertTrue("d) UnEqual vectors returned true", !tVector.equals(v));
+	}
+
+	/**
+	 * @tests java.util.Vector#firstElement()
+	 */
+	public void test_firstElement() {
+		// Test for method java.lang.Object java.util.Vector.firstElement()
+		assertTrue("Returned incorrect firstElement", tVector.firstElement()
+				.equals("Test 0"));
+		tVector.insertElementAt(null, 0);
+		assertTrue("Returned incorrect firstElement--wanted null", tVector
+				.firstElement() == null);
+	}
+
+	/**
+	 * @tests java.util.Vector#get(int)
+	 */
+	public void test_getI() {
+		// Test for method java.lang.Object java.util.Vector.get(int)
+		assertTrue("Get returned incorrect object", tVector.get(80).equals(
+				"Test 80"));
+		tVector.add(25, null);
+		assertTrue("Returned incorrect element--wanted null",
+				tVector.get(25) == null);
+	}
+
+	/**
+	 * @tests java.util.Vector#hashCode()
+	 */
+	public void test_hashCode() {
+		// Test for method int java.util.Vector.hashCode()
+		int hashCode = 1; // one
+		tVector.insertElementAt(null, 20);
+		for (int i = 0; i < tVector.size(); i++) {
+			Object obj = tVector.elementAt(i);
+			hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
+		}
+		assertTrue("Incorrect hashCode returned.  Wanted: " + hashCode
+				+ " got: " + tVector.hashCode(), tVector.hashCode() == hashCode);
+	}
+
+	/**
+	 * @tests java.util.Vector#indexOf(java.lang.Object)
+	 */
+	public void test_indexOfLjava_lang_Object() {
+		// Test for method int java.util.Vector.indexOf(java.lang.Object)
+		assertTrue("Incorrect index returned", tVector.indexOf("Test 10") == 10);
+		assertTrue("Index returned for invalid Object", tVector
+				.indexOf("XXXXXXXXXXX") == -1);
+		tVector.setElementAt(null, 20);
+		tVector.setElementAt(null, 40);
+		assertTrue("Incorrect indexOf returned for null: "
+				+ tVector.indexOf(null), tVector.indexOf(null) == 20);
+	}
+
+	/**
+	 * @tests java.util.Vector#indexOf(java.lang.Object, int)
+	 */
+	public void test_indexOfLjava_lang_ObjectI() {
+		// Test for method int java.util.Vector.indexOf(java.lang.Object, int)
+		assertTrue("Failed to find correct index", (tVector.indexOf("Test 98",
+				50) == 98));
+		assertTrue("Found index of bogus element", (tVector.indexOf(
+				"Test 1001", 50) == -1));
+		tVector.setElementAt(null, 20);
+		tVector.setElementAt(null, 40);
+		tVector.setElementAt(null, 60);
+		assertTrue("a) Incorrect indexOf returned for null: "
+				+ tVector.indexOf(null, 25), tVector.indexOf(null, 25) == 40);
+		assertTrue("b) Incorrect indexOf returned for null: "
+				+ tVector.indexOf(null, 20), tVector.indexOf(null, 20) == 20);
+	}
+
+	/**
+	 * @tests java.util.Vector#insertElementAt(java.lang.Object, int)
+	 */
+	public void test_insertElementAtLjava_lang_ObjectI() {
+		// Test for method void
+		// java.util.Vector.insertElementAt(java.lang.Object, int)
+		Vector v = vectorClone(tVector);
+		String prevElement = (String) v.elementAt(99);
+		v.insertElementAt("Inserted Element", 99);
+		assertTrue("Element not inserted", ((String) v.elementAt(99))
+				.equals("Inserted Element"));
+		assertTrue("Elements shifted incorrectly", ((String) v.elementAt(100))
+				.equals(prevElement));
+		v.insertElementAt(null, 20);
+		assertTrue("null not inserted", v.elementAt(20) == null);
+	}
+
+	/**
+	 * @tests java.util.Vector#isEmpty()
+	 */
+	public void test_isEmpty() {
+		// Test for method boolean java.util.Vector.isEmpty()Vector
+		Vector v = new java.util.Vector();
+		assertTrue("Empty vector returned false", v.isEmpty());
+		v.addElement(new Object());
+		assertTrue("non-Empty vector returned true", !v.isEmpty());
+	}
+
+	/**
+	 * @tests java.util.Vector#isEmpty()
+	 */
+	public void test_isEmpty_subtest0() {
+		final Vector v = new Vector();
+		v.addElement("initial");
+		Thread t1 = new Thread() {
+			public void run() {
+				while (!v.isEmpty())
+					;
+				v.addElement("final");
+			}
+		};
+		t1.start();
+		for (int i = 0; i < 10000; i++) {
+			synchronized (v) {
+				v.removeElementAt(0);
+				v.addElement(String.valueOf(i));
+			}
+			int size;
+			if ((size = v.size()) != 1) {
+				String result = "Size is not 1: " + size + " " + v;
+				// terminate the thread
+				v.removeAllElements();
+				fail(result);
+			}
+		}
+		// terminate the thread
+		v.removeElementAt(0);
+	}
+
+	/**
+	 * @tests java.util.Vector#lastElement()
+	 */
+	public void test_lastElement() {
+		// Test for method java.lang.Object java.util.Vector.lastElement()
+		assertTrue("Incorrect last element returned", tVector.lastElement()
+				.equals("Test 99"));
+		tVector.addElement(null);
+		assertTrue("Incorrect last element returned--wanted null", tVector
+				.lastElement() == null);
+	}
+
+	/**
+	 * @tests java.util.Vector#lastIndexOf(java.lang.Object)
+	 */
+	public void test_lastIndexOfLjava_lang_Object() {
+		// Test for method int java.util.Vector.lastIndexOf(java.lang.Object)
+		Vector v = new Vector(9);
+		for (int i = 0; i < 9; i++)
+			v.addElement("Test");
+		v.addElement("z");
+		assertTrue("Failed to return correct index", v.lastIndexOf("Test") == 8);
+		tVector.setElementAt(null, 20);
+		tVector.setElementAt(null, 40);
+		assertTrue("Incorrect lastIndexOf returned for null: "
+				+ tVector.lastIndexOf(null), tVector.lastIndexOf(null) == 40);
+	}
+
+	/**
+	 * @tests java.util.Vector#lastIndexOf(java.lang.Object, int)
+	 */
+	public void test_lastIndexOfLjava_lang_ObjectI() {
+		// Test for method int java.util.Vector.lastIndexOf(java.lang.Object,
+		// int)
+		assertTrue("Failed to find object",
+				tVector.lastIndexOf("Test 0", 0) == 0);
+		assertTrue("Found Object outside of index", (tVector.lastIndexOf(
+				"Test 0", 10) > -1));
+		tVector.setElementAt(null, 20);
+		tVector.setElementAt(null, 40);
+		tVector.setElementAt(null, 60);
+		assertTrue("Incorrect lastIndexOf returned for null: "
+				+ tVector.lastIndexOf(null, 15),
+				tVector.lastIndexOf(null, 15) == -1);
+		assertTrue("Incorrect lastIndexOf returned for null: "
+				+ tVector.lastIndexOf(null, 45),
+				tVector.lastIndexOf(null, 45) == 40);
+	}
+
+	/**
+	 * @tests java.util.Vector#remove(int)
+	 */
+	public void test_removeI() {
+		// Test for method java.lang.Object java.util.Vector.remove(int)
+		tVector.remove(36);
+		assertTrue("Contained element after remove", !tVector
+				.contains("Test 36"));
+		assertTrue("Failed to decrement size after remove",
+				tVector.size() == 99);
+		tVector.add(20, null);
+		tVector.remove(19);
+		assertTrue("Didn't move null element over", tVector.get(19) == null);
+		tVector.remove(19);
+		assertTrue("Didn't remove null element", tVector.get(19) != null);
+		assertTrue("Failed to decrement size after removing null", tVector
+				.size() == 98);
+	}
+
+	/**
+	 * @tests java.util.Vector#remove(java.lang.Object)
+	 */
+	public void test_removeLjava_lang_Object() {
+		// Test for method boolean java.util.Vector.remove(java.lang.Object)
+		tVector.remove("Test 0");
+		assertTrue("Contained element after remove", !tVector
+				.contains("Test 0"));
+		assertTrue("Failed to decrement size after remove",
+				tVector.size() == 99);
+		tVector.add(null);
+		tVector.remove(null);
+		assertTrue("Contained null after remove", !tVector.contains(null));
+		assertTrue("Failed to decrement size after removing null", tVector
+				.size() == 99);
+	}
+
+	/**
+	 * @tests java.util.Vector#removeAll(java.util.Collection)
+	 */
+	public void test_removeAllLjava_util_Collection() {
+		// Test for method boolean
+		// java.util.Vector.removeAll(java.util.Collection)
+		Vector v = new Vector();
+		Collection l = new LinkedList();
+		for (int i = 0; i < 5; i++)
+			l.add("Test " + i);
+		v.addElement(l);
+
+		Collection s = new HashSet();
+		Object o;
+		s.add(o = v.firstElement());
+		v.removeAll(s);
+		assertTrue("Failed to remove items in collection", !v.contains(o));
+		v.removeAll(l);
+		assertTrue("Failed to remove all elements", v.isEmpty());
+
+		v.add(null);
+		v.add(null);
+		v.add("Boom");
+		v.removeAll(s);
+		assertTrue("Should not have removed any elements", v.size() == 3);
+		l = new LinkedList();
+		l.add(null);
+		v.removeAll(l);
+		assertTrue("Should only have one element", v.size() == 1);
+		assertTrue("Element should be 'Boom'", v.firstElement().equals("Boom"));
+	}
+
+	/**
+	 * @tests java.util.Vector#removeAllElements()
+	 */
+	public void test_removeAllElements() {
+		// Test for method void java.util.Vector.removeAllElements()
+		Vector v = vectorClone(tVector);
+		v.removeAllElements();
+		assertTrue("Failed to remove all elements", v.size() == 0);
+	}
+
+	/**
+	 * @tests java.util.Vector#removeElement(java.lang.Object)
+	 */
+	public void test_removeElementLjava_lang_Object() {
+		// Test for method boolean
+		// java.util.Vector.removeElement(java.lang.Object)
+		Vector v = vectorClone(tVector);
+		v.removeElement("Test 98");
+		assertTrue("Element not removed", ((String) v.elementAt(98))
+				.equals("Test 99"));
+		assertTrue("Vector is wrong size after removal: " + v.size(),
+				v.size() == 99);
+		tVector.addElement(null);
+		v.removeElement(null);
+		assertTrue("Vector is wrong size after removing null: " + v.size(), v
+				.size() == 99);
+	}
+
+	/**
+	 * @tests java.util.Vector#removeElementAt(int)
+	 */
+	public void test_removeElementAtI() {
+		// Test for method void java.util.Vector.removeElementAt(int)
+		Vector v = vectorClone(tVector);
+		v.removeElementAt(50);
+		assertTrue("Failed to remove element", v.indexOf("Test 50", 0) == -1);
+		tVector.insertElementAt(null, 60);
+		tVector.removeElementAt(60);
+		assertTrue("Element at 60 should not be null after removal", tVector
+				.elementAt(60) != null);
+	}
+
+	/**
+	 * @tests java.util.Vector#retainAll(java.util.Collection)
+	 */
+	public void test_retainAllLjava_util_Collection() {
+		// Test for method boolean
+		// java.util.Vector.retainAll(java.util.Collection)
+		Object o = tVector.firstElement();
+		tVector.add(null);
+		Collection s = new HashSet();
+		s.add(o);
+		s.add(null);
+		tVector.retainAll(s);
+		assertTrue("Retained items other than specified", tVector.size() == 2
+				&& tVector.contains(o) && tVector.contains(null));
+	}
+
+	/**
+	 * @tests java.util.Vector#set(int, java.lang.Object)
+	 */
+	public void test_setILjava_lang_Object() {
+		// Test for method java.lang.Object java.util.Vector.set(int,
+		// java.lang.Object)
+		Object o = new Object();
+		tVector.set(23, o);
+		assertTrue("Failed to set Object", tVector.get(23) == o);
+	}
+
+	/**
+	 * @tests java.util.Vector#setElementAt(java.lang.Object, int)
+	 */
+	public void test_setElementAtLjava_lang_ObjectI() {
+		// Test for method void java.util.Vector.setElementAt(java.lang.Object,
+		// int)
+		Vector v = vectorClone(tVector);
+		v.setElementAt("Inserted Element", 99);
+		assertTrue("Element not set", ((String) v.elementAt(99))
+				.equals("Inserted Element"));
+	}
+
+	/**
+	 * @tests java.util.Vector#setSize(int)
+	 */
+	public void test_setSizeI() {
+		// Test for method void java.util.Vector.setSize(int)
+		Vector v = vectorClone(tVector);
+		v.setSize(10);
+		assertTrue("Failed to set size", v.size() == 10);
+	}
+
+	/**
+	 * @tests java.util.Vector#size()
+	 */
+	public void test_size() {
+		// Test for method int java.util.Vector.size()
+		assertTrue("Returned incorrect size", tVector.size() == 100);
+
+		final Vector v = new Vector();
+		v.addElement("initial");
+		Thread t1 = new Thread() {
+			public void run() {
+				while (v.size() > 0)
+					;
+				v.addElement("final");
+			}
+		};
+		t1.start();
+		for (int i = 0; i < 10000; i++) {
+			synchronized (v) {
+				v.removeElementAt(0);
+				v.addElement(String.valueOf(i));
+			}
+			int size;
+			if ((size = v.size()) != 1) {
+				String result = "Size is not 1: " + size + " " + v;
+				// terminate the thread
+				v.removeAllElements();
+				fail(result);
+			}
+		}
+		// terminate the thread
+		v.removeElementAt(0);
+	}
+
+	/**
+	 * @tests java.util.Vector#subList(int, int)
+	 */
+	public void test_subListII() {
+		// Test for method java.util.List java.util.Vector.subList(int, int)
+		List sl = tVector.subList(10, 25);
+		assertTrue("Returned sublist of incorrect size", sl.size() == 15);
+		for (int i = 10; i < 25; i++)
+			assertTrue("Returned incorrect sublist", sl
+					.contains(tVector.get(i)));
+
+		assertTrue("Not synchronized random access", sl.getClass().getName()
+				.equals("java.util.Collections$SynchronizedRandomAccessList"));
+
+	}
+
+	/**
+	 * @tests java.util.Vector#toArray()
+	 */
+	public void test_toArray() {
+		// Test for method java.lang.Object [] java.util.Vector.toArray()
+		assertTrue("Returned incorrect array", Arrays.equals(objArray, tVector
+				.toArray()));
+	}
+
+	/**
+	 * @tests java.util.Vector#toArray(java.lang.Object[])
+	 */
+	public void test_toArray$Ljava_lang_Object() {
+		// Test for method java.lang.Object []
+		// java.util.Vector.toArray(java.lang.Object [])
+		Object[] o = new Object[1000];
+		Object f = new Object();
+		for (int i = 0; i < o.length; i++)
+			o[i] = f;
+		tVector.toArray(o);
+		assertTrue("Failed to set slot to null", o[100] == null);
+		for (int i = 0; i < tVector.size(); i++)
+			assertTrue("Returned incorrect array", tVector.elementAt(i) == o[i]);
+	}
+
+	/**
+	 * @tests java.util.Vector#toString()
+	 */
+	public void test_toString() {
+		// Test for method java.lang.String java.util.Vector.toString()
+		assertTrue("Incorrect String returned", tVector.toString().equals(
+				vString));
+
+		Vector v = new Vector();
+		v.addElement("one");
+		v.addElement(v);
+		v.addElement("3");
+		// test last element
+		v.addElement(v);
+		String result = v.toString();
+		assertTrue("should contain self ref", result.indexOf("(this") > -1);
+	}
+
+	/**
+	 * @tests java.util.Vector#trimToSize()
+	 */
+	public void test_trimToSize() {
+		// Test for method void java.util.Vector.trimToSize()
+		Vector v = new Vector(10);
+		v.addElement(new Object());
+		v.trimToSize();
+		assertTrue("Failed to trim capacity", v.capacity() == 1);
+	}
+
+	protected Vector vectorClone(Vector s) {
+		return (Vector) s.clone();
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+		for (int i = 0; i < 100; i++) {
+			tVector.addElement("Test " + i);
+		}
+		objArray = new Object[100];
+		for (int i = 0; i < 100; i++) {
+			objArray[i] = "Test " + i;
+		}
+	}
+
+	/**
+	 * 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/util/WeakHashMapTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/WeakHashMapTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/WeakHashMapTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/WeakHashMapTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,325 @@
+/* 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.util;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+
+import tests.support.Support_MapTest2;
+
+public class WeakHashMapTest extends junit.framework.TestCase {
+
+	Object[] keyArray = new Object[100];
+
+	Object[] valueArray = new Object[100];
+
+	WeakHashMap whm;
+
+	/**
+	 * @tests java.util.WeakHashMap#WeakHashMap()
+	 */
+	public void test_Constructor() {
+		// Test for method java.util.WeakHashMap()
+		new Support_MapTest2(new WeakHashMap()).runTest();
+
+		whm = new WeakHashMap();
+		for (int i = 0; i < 100; i++)
+			whm.put(keyArray[i], valueArray[i]);
+		for (int i = 0; i < 100; i++)
+			assertTrue("Incorrect value retrieved",
+					whm.get(keyArray[i]) == valueArray[i]);
+
+	}
+
+	/**
+	 * @tests java.util.WeakHashMap#WeakHashMap(int)
+	 */
+	public void test_ConstructorI() {
+		// Test for method java.util.WeakHashMap(int)
+		whm = new WeakHashMap(50);
+		for (int i = 0; i < 100; i++)
+			whm.put(keyArray[i], valueArray[i]);
+		for (int i = 0; i < 100; i++)
+			assertTrue("Incorrect value retrieved",
+					whm.get(keyArray[i]) == valueArray[i]);
+
+		WeakHashMap empty = new WeakHashMap(0);
+		assertTrue("Empty weakhashmap access", empty.get("nothing") == null);
+		empty.put("something", "here");
+		assertTrue("cannot get element", empty.get("something") == "here");
+	}
+
+	/**
+	 * @tests java.util.WeakHashMap#WeakHashMap(int, float)
+	 */
+	public void test_ConstructorIF() {
+		// Test for method java.util.WeakHashMap(int, float)
+		whm = new WeakHashMap(50, 0.5f);
+		for (int i = 0; i < 100; i++)
+			whm.put(keyArray[i], valueArray[i]);
+		for (int i = 0; i < 100; i++)
+			assertTrue("Incorrect value retrieved",
+					whm.get(keyArray[i]) == valueArray[i]);
+
+		WeakHashMap empty = new WeakHashMap(0, 0.75f);
+		assertTrue("Empty hashtable access", empty.get("nothing") == null);
+		empty.put("something", "here");
+		assertTrue("cannot get element", empty.get("something") == "here");
+	}
+
+	/**
+	 * @tests java.util.WeakHashMap#clear()
+	 */
+	public void test_clear() {
+		// Test for method boolean java.util.WeakHashMap.clear()
+		whm = new WeakHashMap();
+		for (int i = 0; i < 100; i++)
+			whm.put(keyArray[i], valueArray[i]);
+		whm.clear();
+		assertTrue("Cleared map should be empty", whm.isEmpty());
+		for (int i = 0; i < 100; i++)
+			assertTrue("Cleared map should only return null", whm
+					.get(keyArray[i]) == null);
+
+	}
+
+	/**
+	 * @tests java.util.WeakHashMap#containsKey(java.lang.Object)
+	 */
+	public void test_containsKeyLjava_lang_Object() {
+		// Test for method boolean java.util.WeakHashMap.containsKey()
+		whm = new WeakHashMap();
+		for (int i = 0; i < 100; i++)
+			whm.put(keyArray[i], valueArray[i]);
+		for (int i = 0; i < 100; i++)
+			assertTrue("Should contain referenced key", whm
+					.containsKey(keyArray[i]));
+		keyArray[25] = null;
+		keyArray[50] = null;
+	}
+
+	/**
+	 * @tests java.util.WeakHashMap#containsValue(java.lang.Object)
+	 */
+	public void test_containsValueLjava_lang_Object() {
+		// Test for method boolean java.util.WeakHashMap.containsValue()
+		whm = new WeakHashMap();
+		for (int i = 0; i < 100; i++)
+			whm.put(keyArray[i], valueArray[i]);
+		for (int i = 0; i < 100; i++)
+			assertTrue("Should contain referenced value", whm
+					.containsValue(valueArray[i]));
+		keyArray[25] = null;
+		keyArray[50] = null;
+	}
+
+	/**
+	 * @tests java.util.WeakHashMap#entrySet()
+	 */
+	public void test_entrySet() {
+		// Test for method java.util.Set java.util.WeakHashMap.entrySet()
+		whm = new WeakHashMap();
+		for (int i = 0; i < 100; i++)
+			whm.put(keyArray[i], valueArray[i]);
+		List keys = Arrays.asList(keyArray);
+		List values = Arrays.asList(valueArray);
+		Set entrySet = whm.entrySet();
+		assertTrue("Incorrect number of entries returned--wanted 100, got: "
+				+ entrySet.size(), entrySet.size() == 100);
+		Iterator it = entrySet.iterator();
+		while (it.hasNext()) {
+			Map.Entry entry = (Map.Entry) it.next();
+			assertTrue("Invalid map entry returned--bad key", keys
+					.contains(entry.getKey()));
+			assertTrue("Invalid map entry returned--bad key", values
+					.contains(entry.getValue()));
+		}
+		keys = null;
+		values = null;
+		keyArray[50] = null;
+
+		int count = 0;
+		do {
+			System.gc();
+			System.gc();
+			Runtime.getRuntime().runFinalization();
+			count++;
+		} while (count <= 5 && entrySet.size() == 100);
+
+		assertTrue(
+				"Incorrect number of entries returned after gc--wanted 99, got: "
+						+ entrySet.size(), entrySet.size() == 99);
+	}
+
+	/**
+	 * @tests java.util.WeakHashMap#get(java.lang.Object)
+	 */
+	public void test_getLjava_lang_Object() {
+		// Test for method java.lang.Object
+		// java.util.WeakHashMap.get(java.lang.Object)
+		assertTrue("Used to test", true);
+	}
+
+	/**
+	 * @tests java.util.WeakHashMap#isEmpty()
+	 */
+	public void test_isEmpty() {
+		// Test for method boolean java.util.WeakHashMap.isEmpty()
+		whm = new WeakHashMap();
+		assertTrue("New map should be empty", whm.isEmpty());
+		Object myObject = new Object();
+		whm.put(myObject, myObject);
+		assertTrue("Map should not be empty", !whm.isEmpty());
+		whm.remove(myObject);
+		assertTrue("Map with elements removed should be empty", whm.isEmpty());
+	}
+
+	/**
+	 * @tests java.util.WeakHashMap#put(java.lang.Object, java.lang.Object)
+	 */
+	public void test_putLjava_lang_ObjectLjava_lang_Object() {
+		// Test for method java.lang.Object
+		// java.util.WeakHashMap.put(java.lang.Object, java.lang.Object)
+		WeakHashMap map = new WeakHashMap();
+		map.put(null, "value"); // add null key
+		System.gc();
+		System.runFinalization();
+		map.remove("nothing"); // Cause objects in queue to be removed
+		assertTrue("null key was removed", map.size() == 1);
+	}
+
+	/**
+	 * @tests java.util.WeakHashMap#remove(java.lang.Object)
+	 */
+	public void test_removeLjava_lang_Object() {
+		// Test for method java.lang.Object
+		// java.util.WeakHashMap.remove(java.lang.Object)
+		whm = new WeakHashMap();
+		for (int i = 0; i < 100; i++)
+			whm.put(keyArray[i], valueArray[i]);
+
+		assertTrue("Remove returned incorrect value",
+				whm.remove(keyArray[25]) == valueArray[25]);
+		assertTrue("Remove returned incorrect value",
+				whm.remove(keyArray[25]) == null);
+		assertTrue("Size should be 99 after remove", whm.size() == 99);
+	}
+
+	/**
+	 * @tests java.util.WeakHashMap#size()
+	 */
+	public void test_size() {
+		// Test for method int java.util.WeakHashMap.size()
+		assertTrue("Used to test", true);
+	}
+
+	/**
+	 * @tests java.util.WeakHashMap#keySet()
+	 */
+	public void test_keySet() {
+		// Test for method java.util.Set java.util.WeakHashMap.keySet()
+		whm = new WeakHashMap();
+		for (int i = 0; i < 100; i++)
+			whm.put(keyArray[i], valueArray[i]);
+
+		List keys = Arrays.asList(keyArray);
+		List values = Arrays.asList(valueArray);
+
+		Set keySet = whm.keySet();
+		assertEquals("Incorrect number of keys returned,", 100, keySet.size());
+		Iterator it = keySet.iterator();
+		while (it.hasNext()) {
+			Object key = it.next();
+			assertTrue("Invalid map entry returned--bad key", keys
+					.contains(key));
+		}
+		keys = null;
+		values = null;
+		keyArray[50] = null;
+
+		int count = 0;
+		do {
+			System.gc();
+			System.gc();
+			Runtime.getRuntime().runFinalization();
+			count++;
+		} while (count <= 5 && keySet.size() == 100);
+
+		assertEquals("Incorrect number of keys returned after gc,", 99, keySet
+				.size());
+	}
+
+	/**
+	 * @tests java.util.WeakHashMap#values()
+	 */
+	public void test_values() {
+		// Test for method java.util.Set java.util.WeakHashMap.values()
+		whm = new WeakHashMap();
+		for (int i = 0; i < 100; i++)
+			whm.put(keyArray[i], valueArray[i]);
+
+		List keys = Arrays.asList(keyArray);
+		List values = Arrays.asList(valueArray);
+
+		Collection valuesCollection = whm.values();
+		assertEquals("Incorrect number of keys returned,", 100,
+				valuesCollection.size());
+		Iterator it = valuesCollection.iterator();
+		while (it.hasNext()) {
+			Object value = it.next();
+			assertTrue("Invalid map entry returned--bad value", values
+					.contains(value));
+		}
+		keys = null;
+		values = null;
+		keyArray[50] = null;
+
+		int count = 0;
+		do {
+			System.gc();
+			System.gc();
+			Runtime.getRuntime().runFinalization();
+			count++;
+		} while (count <= 5 && valuesCollection.size() == 100);
+
+		assertEquals("Incorrect number of keys returned after gc,", 99,
+				valuesCollection.size());
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+		for (int i = 0; i < 100; i++) {
+			keyArray[i] = new Object();
+			valueArray[i] = new Object();
+		}
+
+	}
+
+	/**
+	 * 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/impl/com/ibm/misc/util/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/impl/com/ibm/misc/util/AllTests.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/impl/com/ibm/misc/util/AllTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/impl/com/ibm/misc/util/AllTests.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,35 @@
+/* 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.impl.com.ibm.misc.util;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+
+	public static void main(String[] args) {
+		junit.textui.TestRunner.run(AllTests.suite());
+	}
+
+	public static Test suite() {
+		TestSuite suite = new TestSuite(
+				"Simple implementation test suite to test basic functionality");
+		// $JUnit-BEGIN$
+		suite.addTestSuite(NYITest.class);
+		// $JUnit-END$
+		return suite;
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/impl/com/ibm/misc/util/NYITest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/impl/com/ibm/misc/util/NYITest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/impl/com/ibm/misc/util/NYITest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/impl/com/ibm/misc/util/NYITest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,43 @@
+/* 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.impl.com.ibm.misc.util;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.luni.util.NotYetImplementedException;
+
+/**
+ * Testing the NYI framework code.
+ */
+public class NYITest extends TestCase {
+
+	public NYITest() {
+		super();
+	}
+
+	public void testNYI() {
+		System.err
+				.println("Test suite -> expect a Not yet implemented output >>>");
+		try {
+			throw new NotYetImplementedException();
+		} catch (NotYetImplementedException exception) {
+			// Expected
+		}
+		System.err
+				.println("Test suite finished Not yet implemented output <<<");
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/luni/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/luni/AllTests.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/luni/AllTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/luni/AllTests.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,43 @@
+/* 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.luni;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that includes all tests for the LUNI project.
+ */
+public class AllTests {
+
+	public static void main(String[] args) {
+		junit.textui.TestRunner.run(AllTests.suite());
+	}
+
+	public static Test suite() {
+		TestSuite suite = new TestSuite("All LUNI test suites");
+		// $JUnit-BEGIN$
+		suite.addTest(tests.api.java.io.AllTests.suite());
+		suite.addTest(tests.api.java.lang.AllTests.suite());
+		suite.addTest(tests.api.java.lang.ref.AllTests.suite());
+		suite.addTest(tests.api.java.lang.reflect.AllTests.suite());
+		suite.addTest(tests.api.java.net.AllTests.suite());
+		suite.addTest(tests.api.java.util.AllTests.suite());
+		suite.addTest(tests.impl.com.ibm.misc.util.AllTests.suite());
+		// $JUnit-END$
+		return suite;
+	}
+}
\ No newline at end of file

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/make/common/build.xml
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/make/common/build.xml?rev=386058&r1=386057&r2=386058&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/make/common/build.xml (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/make/common/build.xml Wed Mar 15 03:46:17 2006
@@ -60,6 +60,7 @@
 					<include name="*.jar" />
 				</fileset>
 			</bootclasspath>
+                        <classpath location="../../../../build/tests" />
 		</javac>
 	</target>
 
@@ -89,6 +90,31 @@
 			<batchtest todir="${hy.tests.reports}" haltonfailure="no">
 				<fileset dir="${hy.nio_char.src.test.java}">
 					<include name="**/*Test.java"/>
+                                        <exclude name="**/ASCCharsetDecoderTest.java"/>
+                                        <exclude name="**/ASCCharsetEncoderTest.java"/>
+                                        <exclude name="**/CharacterCodingExceptionTest.java"/>
+                                        <exclude name="**/CharsetDecoderTest.java"/>
+                                        <exclude name="**/CharsetEncoderTest.java"/>
+                                        <exclude name="**/CharsetProviderTest.java"/>
+                                        <exclude name="**/CharsetTest.java"/>
+                                        <exclude name="**/CoderMalfunctionErrorTest.java"/>
+                                        <exclude name="**/ConcreteCharsetTest.java"/>
+                                        <exclude name="**/GBCharsetDecoderTest.java"/>
+                                        <exclude name="**/GBCharsetEncoderTest.java"/>
+                                        <exclude name="**/ISOCharsetDecoderTest.java"/>
+                                        <exclude name="**/ISOCharsetEncoderTest.java"/>
+                                        <exclude name="**/IllegalCharsetNameExceptionTest.java"/>
+                                        <exclude name="**/MalformedInputExceptionTest.java"/>
+                                        <exclude name="**/UTF16BECharsetDecoderTest.java"/>
+                                        <exclude name="**/UTF16BECharsetEncoderTest.java"/>
+                                        <exclude name="**/UTF16CharsetDecoderTest.java"/>
+                                        <exclude name="**/UTF16CharsetEncoderTest.java"/>
+                                        <exclude name="**/UTF16LECharsetDecoderTest.java"/>
+                                        <exclude name="**/UTF16LECharsetEncoderTest.java"/>
+                                        <exclude name="**/UTFCharsetDecoderTest.java"/>
+                                        <exclude name="**/UTFCharsetEncoderTest.java"/>
+                                        <exclude name="**/UnmappableCharacterExceptionTest.java"/>
+                                        <exclude name="**/UnsupportedCharsetExceptionTest.java"/>
 				</fileset>
 			</batchtest>
 		</junit>

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ASCCharsetDecoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ASCCharsetDecoderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ASCCharsetDecoderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ASCCharsetDecoderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,71 @@
+/* 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.nio.charset;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+
+public class ASCCharsetDecoderTest extends CharsetDecoderTest {
+
+	protected void setUp() throws Exception {
+		cs = Charset.forName("ascii");
+		super.setUp();
+	}
+
+	/*
+	 * @see CharsetDecoderTest#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	// FIXME: give up this tests
+	// public void testDefaultCharsPerByte(){
+	// // assertTrue(decoder.averageCharsPerByte() == 1);
+	// // assertTrue(decoder.maxCharsPerByte() == 1);
+	// assertEquals(decoder.averageCharsPerByte(), 1, 0.001);
+	// assertEquals(decoder.maxCharsPerByte(), 2, 0.001);
+	// }
+
+	ByteBuffer getUnmappedByteBuffer() throws UnsupportedEncodingException {
+		// FIXME: different here
+		return null;
+		// ByteBuffer buffer = ByteBuffer.allocate(8);
+		// buffer.put((byte)-1);
+		// buffer.put(unibytes);
+		// buffer.flip();
+		// return buffer;
+
+	}
+
+	ByteBuffer getMalformByteBuffer() throws UnsupportedEncodingException {
+		// FIXME: different here
+		ByteBuffer buffer = ByteBuffer.allocate(8);
+		buffer.put((byte) -1);
+		buffer.put(unibytes);
+		buffer.flip();
+		return buffer;
+
+		// TODO: how malform?
+		// return null;
+	}
+
+	ByteBuffer getExceptionByteArray() throws UnsupportedEncodingException {
+		return null;
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ASCCharsetEncoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ASCCharsetEncoderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ASCCharsetEncoderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ASCCharsetEncoderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,110 @@
+/* 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.nio.charset;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CoderResult;
+import java.nio.charset.CodingErrorAction;
+import java.nio.charset.UnmappableCharacterException;
+
+public class ASCCharsetEncoderTest extends CharsetEncoderTest {
+
+	// charset for ascii
+	private static final Charset CS = Charset.forName("ascii");
+
+	/*
+	 * @see CharsetEncoderTest#setUp()
+	 */
+	protected void setUp() throws Exception {
+		cs = CS;
+		super.setUp();
+	}
+
+	/*
+	 * @see CharsetEncoderTest#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	public void testCanEncodeCharSequence() {
+		// normal case for ascCS
+		assertTrue(encoder.canEncode("\u0077"));
+		assertFalse(encoder.canEncode("\uc2a3"));
+		assertFalse(encoder.canEncode("\ud800\udc00"));
+		try {
+			encoder.canEncode(null);
+		} catch (NullPointerException e) {
+		}
+		assertTrue(encoder.canEncode(""));
+	}
+
+	public void testCanEncodeICUBug() {
+		assertFalse(encoder.canEncode('\ud800'));
+		assertFalse(encoder.canEncode("\ud800"));
+	}
+
+	public void testCanEncodechar() throws CharacterCodingException {
+		assertTrue(encoder.canEncode('\u0077'));
+		assertFalse(encoder.canEncode('\uc2a3'));
+	}
+
+	public void testSpecificDefaultValue() {
+		assertTrue(encoder.averageBytesPerChar() == 1);
+		assertTrue(encoder.maxBytesPerChar() == 1);
+	}
+
+	CharBuffer getMalformedCharBuffer() {
+		return CharBuffer.wrap("\ud800 buffer");
+	}
+
+	CharBuffer getUnmapCharBuffer() {
+		return CharBuffer.wrap("\ud800\udc00 buffer");
+	}
+
+	CharBuffer getExceptionCharBuffer() {
+		return null;
+	}
+
+	protected byte[] getIllegalByteArray() {
+		return new byte[] { (byte) -1 };
+	}
+
+	public void testMultiStepEncode() throws CharacterCodingException {
+		encoder.onMalformedInput(CodingErrorAction.REPORT);
+		encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
+		try {
+			encoder.encode(CharBuffer.wrap("\ud800\udc00"));
+			fail("should unmappable");
+		} catch (UnmappableCharacterException e) {
+		}
+		encoder.reset();
+		ByteBuffer out = ByteBuffer.allocate(10);
+		assertTrue(encoder.encode(CharBuffer.wrap("\ud800"), out, true)
+				.isMalformed());
+		encoder.flush(out);
+		encoder.reset();
+		out = ByteBuffer.allocate(10);
+		assertSame(CoderResult.UNDERFLOW, encoder.encode(CharBuffer
+				.wrap("\ud800"), out, false));
+		assertTrue(encoder.encode(CharBuffer.wrap("\udc00"), out, true)
+				.isMalformed());
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ASCCharsetTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ASCCharsetTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ASCCharsetTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ASCCharsetTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,58 @@
+/* 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.nio.charset;
+
+/**
+ * Test charset US-ASCII.
+ */
+public class ASCCharsetTest extends ConcreteCharsetTest {
+
+	/**
+	 * Constructor.
+	 * 
+	 */
+	public ASCCharsetTest(String arg0) {
+		super(arg0, "US-ASCII", new String[] { "ISO646-US", "ASCII", "cp367",
+				"ascii7", "ANSI_X3.4-1986", "iso-ir-6", "us", "646",
+				"iso_646.irv:1983", "csASCII", "ANSI_X3.4-1968",
+				"ISO_646.irv:1991" }, true, true); // "ibm-367"
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see tests.api.java.nio.charset.ConcreteCharsetTest#testEncode_Normal()
+	 */
+	public void testEncode_Normal() {
+		String input = "ab\u5D14\u654F";
+		byte[] output = new byte[] { 97, 98,
+				this.testingCharset.newEncoder().replacement()[0],
+				this.testingCharset.newEncoder().replacement()[0] };
+		internalTestEncode(input, output);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see tests.api.java.nio.charset.ConcreteCharsetTest#testDecode_Normal()
+	 */
+	public void testDecode_Normal() {
+		byte[] input = new byte[] { 97, 98, 63, 63 };
+		char[] output = "ab??".toCharArray();
+		internalTestDecode(input, output);
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/AllTests.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/AllTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/AllTests.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,65 @@
+/* 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.nio.charset;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite for java.nio.charset package.
+ */
+public class AllTests {
+
+	public static Test suite() {
+		TestSuite suite = new TestSuite("Test for tests.api.java.nio.charset");
+		// $JUnit-BEGIN$
+		suite.addTestSuite(CharacterCodingExceptionTest.class);
+		suite.addTestSuite(MalformedInputExceptionTest.class);
+		suite.addTestSuite(IllegalCharsetNameExceptionTest.class);
+		suite.addTestSuite(CodingErrorActionTest.class);
+		suite.addTestSuite(UnmappableCharacterExceptionTest.class);
+		suite.addTestSuite(UnsupportedCharsetExceptionTest.class);
+		suite.addTestSuite(CoderMalfunctionErrorTest.class);
+		suite.addTestSuite(CoderResultTest.class);
+		suite.addTestSuite(CharsetTest.class);
+		suite.addTestSuite(ASCCharsetTest.class);
+		suite.addTestSuite(ISOCharsetTest.class);
+		suite.addTestSuite(UTF8CharsetTest.class);
+		suite.addTestSuite(UTF16CharsetTest.class);
+		suite.addTestSuite(UTF16BECharsetTest.class);
+		suite.addTestSuite(UTF16LECharsetTest.class);
+
+		suite.addTestSuite(CharsetEncoderTest.class);
+		suite.addTestSuite(ISOCharsetEncoderTest.class);
+		suite.addTestSuite(UTFCharsetEncoderTest.class);
+		// suite.addTestSuite(GBCharsetEncoderTest.class);
+		suite.addTestSuite(ASCCharsetEncoderTest.class);
+		suite.addTestSuite(UTF16CharsetEncoderTest.class);
+		suite.addTestSuite(UTF16LECharsetEncoderTest.class);
+		suite.addTestSuite(UTF16BECharsetEncoderTest.class);
+
+		suite.addTestSuite(CharsetDecoderTest.class);
+		suite.addTestSuite(ISOCharsetDecoderTest.class);
+		suite.addTestSuite(UTFCharsetDecoderTest.class);
+		// suite.addTestSuite(GBCharsetDecoderTest.class);
+		suite.addTestSuite(ASCCharsetDecoderTest.class);
+		suite.addTestSuite(UTF16CharsetDecoderTest.class);
+		suite.addTestSuite(UTF16LECharsetDecoderTest.class);
+		suite.addTestSuite(UTF16BECharsetDecoderTest.class);
+		// $JUnit-END$
+		return suite;
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CharacterCodingException.ser
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CharacterCodingException.ser?rev=386058&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CharacterCodingException.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message