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 [38/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/util/LinkedListTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LinkedListTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LinkedListTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LinkedListTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,476 @@
+/* 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.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+
+import tests.support.Support_ListTest;
+
+public class LinkedListTest extends junit.framework.TestCase {
+
+ LinkedList ll;
+
+ static Object[] objArray;
+ {
+ objArray = new Object[100];
+ for (int i = 0; i < objArray.length; i++)
+ objArray[i] = new Integer(i);
+ }
+
+ /**
+ * @tests java.util.LinkedList#LinkedList()
+ */
+ public void test_Constructor() {
+ // Test for method java.util.LinkedList()
+ new Support_ListTest("", ll).runTest();
+
+ LinkedList subList = new LinkedList();
+ for (int i = -50; i < 150; i++)
+ subList.add(new Integer(i));
+ new Support_ListTest("", subList.subList(50, 150)).runTest();
+ }
+
+ /**
+ * @tests java.util.LinkedList#LinkedList(java.util.Collection)
+ */
+ public void test_ConstructorLjava_util_Collection() {
+ // Test for method java.util.LinkedList(java.util.Collection)
+ assertTrue("Incorrect LinkedList constructed", new LinkedList(ll)
+ .equals(ll));
+ }
+
+ /**
+ * @tests java.util.LinkedList#add(int, java.lang.Object)
+ */
+ public void test_addILjava_lang_Object() {
+ // Test for method void java.util.LinkedList.add(int, java.lang.Object)
+ Object o;
+ ll.add(50, o = "Test");
+ assertTrue("Failed to add Object>: " + ll.get(50).toString(), ll
+ .get(50) == o);
+ assertTrue("Failed to fix up list after insert",
+ ll.get(51) == objArray[50] && (ll.get(52) == objArray[51]));
+ ll.add(50, null);
+ assertTrue("Did not add null correctly", ll.get(50) == null);
+ }
+
+ /**
+ * @tests java.util.LinkedList#add(java.lang.Object)
+ */
+ public void test_addLjava_lang_Object() {
+ // Test for method boolean java.util.LinkedList.add(java.lang.Object)
+ Object o;
+ ll.add(o = new Object());
+ assertTrue("Failed to add Object", ll.getLast() == o);
+ ll.add(null);
+ assertTrue("Did not add null correctly", ll.get(ll.size() - 1) == null);
+ }
+
+ /**
+ * @tests java.util.LinkedList#addAll(int, java.util.Collection)
+ */
+ public void test_addAllILjava_util_Collection() {
+ // Test for method boolean java.util.LinkedList.addAll(int,
+ // java.util.Collection)
+ ll.addAll(50, (Collection) ll.clone());
+ assertTrue("Returned incorrect size after adding to existing list", ll
+ .size() == 200);
+ for (int i = 0; i < 50; i++)
+ assertTrue("Manipulated elements < index", ll.get(i) == objArray[i]);
+ for (int i = 0; i >= 50 && (i < 150); i++)
+ assertTrue("Failed to ad elements properly",
+ ll.get(i) == objArray[i - 50]);
+ for (int i = 0; i >= 150 && (i < 200); i++)
+ assertTrue("Failed to ad elements properly",
+ ll.get(i) == objArray[i - 100]);
+ List myList = new LinkedList();
+ myList.add(null);
+ myList.add("Blah");
+ myList.add(null);
+ myList.add("Booga");
+ myList.add(null);
+ ll.addAll(50, myList);
+ assertTrue("a) List w/nulls not added correctly", ll.get(50) == null);
+ assertTrue("b) List w/nulls not added correctly", ll.get(51).equals(
+ "Blah"));
+ assertTrue("c) List w/nulls not added correctly", ll.get(52) == null);
+ assertTrue("d) List w/nulls not added correctly", ll.get(53).equals(
+ "Booga"));
+ assertTrue("e) List w/nulls not added correctly", ll.get(54) == null);
+ }
+
+ /**
+ * @tests java.util.LinkedList#addAll(java.util.Collection)
+ */
+ public void test_addAllLjava_util_Collection() {
+ // Test for method boolean
+ // java.util.LinkedList.addAll(java.util.Collection)
+ List l = new ArrayList();
+ l.addAll((Collection) ll.clone());
+ for (int i = 0; i < ll.size(); i++)
+ assertTrue("Failed to add elements properly", l.get(i).equals(
+ ll.get(i)));
+ ll.addAll((Collection) ll.clone());
+ assertTrue("Returned incorrect siZe after adding to existing list", ll
+ .size() == 200);
+ for (int i = 0; i < 100; i++) {
+ assertTrue("Added to list in incorrect order", ll.get(i).equals(
+ l.get(i)));
+ assertTrue("Failed to add to existing list", ll.get(i + 100)
+ .equals(l.get(i)));
+ }
+ List myList = new LinkedList();
+ myList.add(null);
+ myList.add("Blah");
+ myList.add(null);
+ myList.add("Booga");
+ myList.add(null);
+ ll.addAll(myList);
+ assertTrue("a) List w/nulls not added correctly", ll.get(200) == null);
+ assertTrue("b) List w/nulls not added correctly", ll.get(201).equals(
+ "Blah"));
+ assertTrue("c) List w/nulls not added correctly", ll.get(202) == null);
+ assertTrue("d) List w/nulls not added correctly", ll.get(203).equals(
+ "Booga"));
+ assertTrue("e) List w/nulls not added correctly", ll.get(204) == null);
+ }
+
+ /**
+ * @tests java.util.LinkedList#addFirst(java.lang.Object)
+ */
+ public void test_addFirstLjava_lang_Object() {
+ // Test for method void java.util.LinkedList.addFirst(java.lang.Object)
+ Object o;
+ ll.addFirst(o = new Object());
+ assertTrue("Failed to add Object", ll.getFirst() == o);
+ ll.addFirst(null);
+ assertTrue("Failed to add null", ll.getFirst() == null);
+ }
+
+ /**
+ * @tests java.util.LinkedList#addLast(java.lang.Object)
+ */
+ public void test_addLastLjava_lang_Object() {
+ // Test for method void java.util.LinkedList.addLast(java.lang.Object)
+ Object o;
+ ll.addLast(o = new Object());
+ assertTrue("Failed to add Object", ll.getLast() == o);
+ ll.addLast(null);
+ assertTrue("Failed to add null", ll.getLast() == null);
+ }
+
+ /**
+ * @tests java.util.LinkedList#clear()
+ */
+ public void test_clear() {
+ // Test for method void java.util.LinkedList.clear()
+ ll.clear();
+ for (int i = 0; i < ll.size(); i++)
+ assertTrue("Failed to clear list", ll.get(i) == null);
+ }
+
+ /**
+ * @tests java.util.LinkedList#clone()
+ */
+ public void test_clone() {
+ // Test for method java.lang.Object java.util.LinkedList.clone()
+ Object x = ll.clone();
+ assertTrue("Cloned list was inequal to cloned", x.equals(ll));
+ for (int i = 0; i < ll.size(); i++)
+ assertTrue("Cloned list contains incorrect elements", ll.get(i)
+ .equals(((LinkedList) x).get(i)));
+ ll.addFirst(null);
+ x = ll.clone();
+ assertTrue("List with a null did not clone properly", ll.equals(x));
+ }
+
+ /**
+ * @tests java.util.LinkedList#contains(java.lang.Object)
+ */
+ public void test_containsLjava_lang_Object() {
+ // Test for method boolean
+ // java.util.LinkedList.contains(java.lang.Object)
+ assertTrue("Returned false for valid element", ll
+ .contains(objArray[99]));
+ assertTrue("Returned false for equal element", ll.contains(new Integer(
+ 8)));
+ assertTrue("Returned true for invalid element", !ll
+ .contains(new Object()));
+ assertTrue("Should not contain null", !ll.contains(null));
+ ll.add(25, null);
+ assertTrue("Should contain null", ll.contains(null));
+ }
+
+ /**
+ * @tests java.util.LinkedList#get(int)
+ */
+ public void test_getI() {
+ // Test for method java.lang.Object java.util.LinkedList.get(int)
+ assertTrue("Returned incorrect element", ll.get(22) == objArray[22]);
+ try {
+ ll.get(8765);
+ } catch (IndexOutOfBoundsException e) {
+ // Correct
+ return;
+ }
+ fail("Failed to throw expected exception for index > size");
+ }
+
+ /**
+ * @tests java.util.LinkedList#getFirst()
+ */
+ public void test_getFirst() {
+ // Test for method java.lang.Object java.util.LinkedList.getFirst()
+ assertTrue("Returned incorrect first element", ll.getFirst().equals(
+ objArray[0]));
+ }
+
+ /**
+ * @tests java.util.LinkedList#getLast()
+ */
+ public void test_getLast() {
+ // Test for method java.lang.Object java.util.LinkedList.getLast()
+ assertTrue("Returned incorrect first element", ll.getLast().equals(
+ objArray[objArray.length - 1]));
+ }
+
+ /**
+ * @tests java.util.LinkedList#indexOf(java.lang.Object)
+ */
+ public void test_indexOfLjava_lang_Object() {
+ // Test for method int java.util.LinkedList.indexOf(java.lang.Object)
+ assertTrue("Returned incorrect index", ll.indexOf(objArray[87]) == 87);
+ assertTrue("Returned index for invalid Object", ll
+ .indexOf(new Object()) == -1);
+ ll.add(20, null);
+ ll.add(24, null);
+ assertTrue("Index of null should be 20, but got: " + ll.indexOf(null),
+ ll.indexOf(null) == 20);
+ }
+
+ /**
+ * @tests java.util.LinkedList#lastIndexOf(java.lang.Object)
+ */
+ public void test_lastIndexOfLjava_lang_Object() {
+ // Test for method int
+ // java.util.LinkedList.lastIndexOf(java.lang.Object)
+ ll.add(new Integer(99));
+ assertTrue("Returned incorrect index",
+ ll.lastIndexOf(objArray[99]) == 100);
+ assertTrue("Returned index for invalid Object", ll
+ .lastIndexOf(new Object()) == -1);
+ ll.add(20, null);
+ ll.add(24, null);
+ assertTrue("Last index of null should be 20, but got: "
+ + ll.lastIndexOf(null), ll.lastIndexOf(null) == 24);
+ }
+
+ /**
+ * @tests java.util.LinkedList#listIterator(int)
+ */
+ public void test_listIteratorI() {
+ // Test for method java.util.ListIterator
+ // java.util.LinkedList.listIterator(int)
+ ListIterator i = ll.listIterator();
+ Object elm;
+ int n = 0;
+ while (i.hasNext()) {
+ if (n == 0 || n == objArray.length - 1) {
+ if (n == 0)
+ assertTrue("First element claimed to have a previous", !i
+ .hasPrevious());
+ if (n == objArray.length)
+ assertTrue("Last element claimed to have next", !i
+ .hasNext());
+ }
+ elm = i.next();
+ assertTrue("Iterator returned elements in wrong order",
+ elm == objArray[n]);
+ if (n > 0 && n < objArray.length - 1) {
+ assertTrue("Next index returned incorrect value",
+ i.nextIndex() == n + 1);
+ assertTrue("previousIndex returned incorrect value : "
+ + i.previousIndex() + ", n val: " + n, i
+ .previousIndex() == n);
+ }
+ ++n;
+ }
+ List myList = new LinkedList();
+ myList.add(null);
+ myList.add("Blah");
+ myList.add(null);
+ myList.add("Booga");
+ myList.add(null);
+ ListIterator li = myList.listIterator();
+ assertTrue("li.hasPrevious() should be false", !li.hasPrevious());
+ assertTrue("li.next() should be null", li.next() == null);
+ assertTrue("li.hasPrevious() should be true", li.hasPrevious());
+ assertTrue("li.prev() should be null", li.previous() == null);
+ assertTrue("li.next() should be null", li.next() == null);
+ assertTrue("li.next() should be Blah", li.next().equals("Blah"));
+ assertTrue("li.next() should be null", li.next() == null);
+ assertTrue("li.next() should be Booga", li.next().equals("Booga"));
+ assertTrue("li.hasNext() should be true", li.hasNext());
+ assertTrue("li.next() should be null", li.next() == null);
+ assertTrue("li.hasNext() should be false", !li.hasNext());
+ }
+
+ /**
+ * @tests java.util.LinkedList#remove(int)
+ */
+ public void test_removeI() {
+ // Test for method java.lang.Object java.util.LinkedList.remove(int)
+ ll.remove(10);
+ assertTrue("Failed to remove element", ll.indexOf(objArray[10]) == -1);
+ try {
+ ll.remove(999);
+ } catch (IndexOutOfBoundsException e) {
+ // Correct
+ return;
+ }
+ fail("Failed to throw expected exception when index out of range");
+ ll.add(20, null);
+ ll.remove(20);
+ assertTrue("Should have removed null", ll.get(20) != null);
+ }
+
+ /**
+ * @tests java.util.LinkedList#remove(java.lang.Object)
+ */
+ public void test_removeLjava_lang_Object() {
+ // Test for method boolean java.util.LinkedList.remove(java.lang.Object)
+ assertTrue("Failed to remove valid Object", ll.remove(objArray[87]));
+ assertTrue("Removed invalid object", !ll.remove(new Object()));
+ assertTrue("Found Object after removal", ll.indexOf(objArray[87]) == -1);
+ ll.add(null);
+ ll.remove(null);
+ assertTrue("Should not contain null afrer removal", !ll.contains(null));
+ }
+
+ /**
+ * @tests java.util.LinkedList#removeFirst()
+ */
+ public void test_removeFirst() {
+ // Test for method java.lang.Object java.util.LinkedList.removeFirst()
+ ll.removeFirst();
+ assertTrue("Failed to remove first element",
+ ll.getFirst() != objArray[0]);
+ }
+
+ /**
+ * @tests java.util.LinkedList#removeLast()
+ */
+ public void test_removeLast() {
+ // Test for method java.lang.Object java.util.LinkedList.removeLast()
+ ll.removeLast();
+ assertTrue("Failed to remove last element",
+ ll.getLast() != objArray[objArray.length - 1]);
+ }
+
+ /**
+ * @tests java.util.LinkedList#set(int, java.lang.Object)
+ */
+ public void test_setILjava_lang_Object() {
+ // Test for method java.lang.Object java.util.LinkedList.set(int,
+ // java.lang.Object)
+ Object obj;
+ ll.set(65, obj = new Object());
+ assertTrue("Failed to set object", ll.get(65) == obj);
+ }
+
+ /**
+ * @tests java.util.LinkedList#size()
+ */
+ public void test_size() {
+ // Test for method int java.util.LinkedList.size()
+ assertTrue("Returned incorrect size", ll.size() == objArray.length);
+ ll.removeFirst();
+ assertTrue("Returned incorrect size", ll.size() == objArray.length - 1);
+ }
+
+ /**
+ * @tests java.util.LinkedList#toArray()
+ */
+ public void test_toArray() {
+ // Test for method java.lang.Object [] java.util.LinkedList.toArray()
+ ll.add(null);
+ Object[] obj = ll.toArray();
+ assertEquals("Returned array of incorrect size", objArray.length + 1, obj.length);
+
+ for (int i = 0; i < obj.length - 1; i++)
+ assertTrue("Returned incorrect array: " + i, obj[i] == objArray[i]);
+ assertTrue("Returned incorrect array--end isn't null",
+ obj[obj.length - 1] == null);
+ }
+
+ /**
+ * @tests java.util.LinkedList#toArray(java.lang.Object[])
+ */
+ public void test_toArray$Ljava_lang_Object() {
+ // Test for method java.lang.Object []
+ // java.util.LinkedList.toArray(java.lang.Object [])
+ Integer[] argArray = new Integer[100];
+ Object[] retArray;
+ retArray = ll.toArray(argArray);
+ assertTrue("Returned different array than passed", retArray == argArray);
+ List retList = new LinkedList(Arrays.asList(retArray));
+ Iterator li = ll.iterator();
+ Iterator ri = retList.iterator();
+ while (li.hasNext())
+ assertTrue("Lists are not equal", li.next() == ri.next());
+ argArray = new Integer[1000];
+ retArray = ll.toArray(argArray);
+ assertTrue("Failed to set first extra element to null", argArray[ll
+ .size()] == null);
+ for (int i = 0; i < ll.size(); i++)
+ assertTrue("Returned incorrect array: " + i,
+ retArray[i] == objArray[i]);
+ ll.add(50, null);
+ argArray = new Integer[101];
+ retArray = ll.toArray(argArray);
+ assertTrue("Returned different array than passed", retArray == argArray);
+ retArray = ll.toArray(argArray);
+ assertTrue("Returned different array than passed", retArray == argArray);
+ retList = new LinkedList(Arrays.asList(retArray));
+ li = ll.iterator();
+ ri = retList.iterator();
+ while (li.hasNext())
+ assertTrue("Lists are not equal", li.next() == ri.next());
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+ ll = new LinkedList();
+ for (int i = 0; i < objArray.length; i++)
+ ll.add(objArray[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/ListResourceBundleTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ListResourceBundleTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ListResourceBundleTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ListResourceBundleTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,52 @@
+/* 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.Enumeration;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.Vector;
+
+public class ListResourceBundleTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.util.ListResourceBundle#getKeys()
+ */
+ public void test_getKeys() {
+ ResourceBundle bundle;
+ String name = "tests.support.Support_TestResource";
+ Locale.setDefault(new Locale("en", "US"));
+ bundle = ResourceBundle.getBundle(name, new Locale("fr", "FR", "VAR"));
+ Enumeration keys = bundle.getKeys();
+ Vector result = new Vector();
+ while (keys.hasMoreElements()) {
+ result.addElement(keys.nextElement());
+ }
+ assertTrue("Missing key parent1", result.contains("parent1"));
+ assertTrue("Missing key parent2", result.contains("parent2"));
+ assertTrue("Missing key parent3", result.contains("parent3"));
+ assertTrue("Missing key parent4", result.contains("parent4"));
+ assertTrue("Missing key child1", result.contains("child1"));
+ assertTrue("Missing key child2", result.contains("child2"));
+ assertTrue("Missing key child3", result.contains("child3"));
+ }
+
+ protected void setUp() {
+ }
+
+ protected void tearDown() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LocaleTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LocaleTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LocaleTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LocaleTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,323 @@
+/* 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.Locale;
+
+public class LocaleTest extends junit.framework.TestCase {
+
+ Locale testLocale;
+
+ Locale l;
+
+ /**
+ * @tests java.util.Locale#Locale(java.lang.String, java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_StringLjava_lang_String() {
+ // Test for method java.util.Locale(java.lang.String, java.lang.String)
+ Locale x = new Locale("xx", "CV");
+ assertTrue("Failed to create Locale", x.getCountry().equals("CV")
+ && x.getVariant().equals(""));
+ }
+
+ /**
+ * @tests java.util.Locale#Locale(java.lang.String, java.lang.String,
+ * java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_StringLjava_lang_StringLjava_lang_String() {
+ // Test for method java.util.Locale(java.lang.String, java.lang.String,
+ // java.lang.String)
+ Locale x = new Locale("xx", "CV", "ZZ");
+ assertTrue("Failed to create Locale", x.getLanguage().equals("xx")
+ && (x.getCountry().equals("CV") && x.getVariant().equals("ZZ")));
+ }
+
+ /**
+ * @tests java.util.Locale#clone()
+ */
+ public void test_clone() {
+ // Test for method java.lang.Object java.util.Locale.clone()
+ assertTrue("Clone failed", l.clone().equals(l));
+ }
+
+ /**
+ * @tests java.util.Locale#equals(java.lang.Object)
+ */
+ public void test_equalsLjava_lang_Object() {
+ // Test for method boolean java.util.Locale.equals(java.lang.Object)
+ Locale l2 = new Locale("en", "CA", "WIN32");
+ assertTrue("Same object returned false", testLocale.equals(testLocale));
+ assertTrue("Same values returned false", testLocale.equals(l2));
+ assertTrue("Different locales returned true", !testLocale.equals(l));
+
+ }
+
+ /**
+ * @tests java.util.Locale#getAvailableLocales()
+ */
+ public void test_getAvailableLocales() {
+ // Test for method java.util.Locale []
+ // java.util.Locale.getAvailableLocales()
+ // Assumes there will generally be about 100+ available locales...
+ try {
+ Locale[] locales = testLocale.getAvailableLocales();
+ assertTrue("Wrong number of locales: ", locales.length > 100);
+ } catch (Exception e) {
+ fail("Exception during test : " + e.getMessage());
+ }
+ }
+
+ /**
+ * @tests java.util.Locale#getCountry()
+ */
+ public void test_getCountry() {
+ // Test for method java.lang.String java.util.Locale.getCountry()
+ assertTrue("Returned incorrect country: " + testLocale.getCountry(),
+ testLocale.getCountry().equals("CA"));
+ }
+
+ /**
+ * @tests java.util.Locale#getDefault()
+ */
+ public void test_getDefault() {
+ // Test for method java.util.Locale java.util.Locale.getDefault()
+ assertTrue("returns copy", Locale.getDefault() == Locale.getDefault());
+ Locale org = Locale.getDefault();
+ Locale.setDefault(l);
+ Locale x = Locale.getDefault();
+ Locale.setDefault(org);
+ assertTrue("Failed to get locale", x.toString().equals("fr_CA_WIN32"));
+ }
+
+ /**
+ * @tests java.util.Locale#getDisplayCountry()
+ */
+ public void test_getDisplayCountry() {
+ // Test for method java.lang.String java.util.Locale.getDisplayCountry()
+ assertTrue("Returned incorrect country: "
+ + testLocale.getDisplayCountry(), testLocale
+ .getDisplayCountry().equals("Canada"));
+ }
+
+ /**
+ * @tests java.util.Locale#getDisplayCountry(java.util.Locale)
+ */
+ public void test_getDisplayCountryLjava_util_Locale() {
+ // Test for method java.lang.String
+ // java.util.Locale.getDisplayCountry(java.util.Locale)
+ assertTrue("Returned incorrect country", Locale.ITALY
+ .getDisplayCountry(l).equals("Italie"));
+ }
+
+ /**
+ * @tests java.util.Locale#getDisplayLanguage()
+ */
+ public void test_getDisplayLanguage() {
+ // Test for method java.lang.String
+ // java.util.Locale.getDisplayLanguage()
+ Locale l = new Locale("fr", "CA", "WIN32");
+ assertTrue("Returned incorrect language: "
+ + testLocale.getDisplayLanguage(l), testLocale
+ .getDisplayLanguage(l).equals("anglais"));
+ }
+
+ /**
+ * @tests java.util.Locale#getDisplayLanguage(java.util.Locale)
+ */
+ public void test_getDisplayLanguageLjava_util_Locale() {
+ // Test for method java.lang.String
+ // java.util.Locale.getDisplayLanguage(java.util.Locale)
+ assertTrue("Returned incorrect language: "
+ + testLocale.getDisplayLanguage(), testLocale
+ .getDisplayLanguage().equals("English"));
+ }
+
+ /**
+ * @tests java.util.Locale#getDisplayName()
+ */
+ public void test_getDisplayName() {
+ // Test for method java.lang.String java.util.Locale.getDisplayName()
+ assertTrue("Returned incorrect name: " + testLocale.getDisplayName(),
+ testLocale.getDisplayName().equals("English (Canada,WIN32)"));
+ }
+
+ /**
+ * @tests java.util.Locale#getDisplayName(java.util.Locale)
+ */
+ public void test_getDisplayNameLjava_util_Locale() {
+ // Test for method java.lang.String
+ // java.util.Locale.getDisplayName(java.util.Locale)
+ assertTrue("Returned incorrect name: " + testLocale.getDisplayName(l),
+ testLocale.getDisplayName(l).equals("anglais (Canada,WIN32)"));
+ }
+
+ /**
+ * @tests java.util.Locale#getDisplayVariant()
+ */
+ public void test_getDisplayVariant() {
+ // Test for method java.lang.String java.util.Locale.getDisplayVariant()
+ assertTrue("Returned incorrect variant: "
+ + testLocale.getDisplayVariant(), testLocale
+ .getDisplayVariant().equals("WIN32"));
+ }
+
+ /**
+ * @tests java.util.Locale#getDisplayVariant(java.util.Locale)
+ */
+ public void test_getDisplayVariantLjava_util_Locale() {
+ // Test for method java.lang.String
+ // java.util.Locale.getDisplayVariant(java.util.Locale)
+ assertTrue("Returned incorrect variant: "
+ + testLocale.getDisplayVariant(l), testLocale
+ .getDisplayVariant(l).equals("WIN32"));
+ }
+
+ /**
+ * @tests java.util.Locale#getISO3Country()
+ */
+ public void test_getISO3Country() {
+ // Test for method java.lang.String java.util.Locale.getISO3Country()
+ assertTrue("Returned incorrect ISO3 country: "
+ + testLocale.getISO3Country(), testLocale.getISO3Country()
+ .equals("CAN"));
+ }
+
+ /**
+ * @tests java.util.Locale#getISO3Language()
+ */
+ public void test_getISO3Language() {
+ // Test for method java.lang.String java.util.Locale.getISO3Language()
+ assertTrue("Returned incorrect ISO3 language: "
+ + testLocale.getISO3Language(), testLocale.getISO3Language()
+ .equals("eng"));
+ }
+
+ /**
+ * @tests java.util.Locale#getISOCountries()
+ */
+ public void test_getISOCountries() {
+ // Test for method java.lang.String []
+ // java.util.Locale.getISOCountries()
+ // Assumes all countries are 2 digits, and that there will always be
+ // 230 countries on the list...
+ String[] isoCountries = Locale.getISOCountries();
+ int length = isoCountries.length;
+ int familiarCount = 0;
+ for (int i = 0; i < length; i++) {
+ if (isoCountries[i].length() != 2) {
+ fail("Wrong format for ISOCountries.");
+ }
+ if (isoCountries[i].equals("CA") || isoCountries[i].equals("BB")
+ || isoCountries[i].equals("US")
+ || isoCountries[i].equals("KR"))
+ familiarCount++;
+ }
+ assertTrue("ISOCountries missing.", familiarCount == 4 && length > 230);
+ }
+
+ /**
+ * @tests java.util.Locale#getISOLanguages()
+ */
+ public void test_getISOLanguages() {
+ // Test for method java.lang.String []
+ // java.util.Locale.getISOLanguages()
+ // Assumes always at least 131 ISOlanguages...
+ String[] isoLang = testLocale.getISOLanguages();
+ int length = isoLang.length;
+ assertTrue("Random element in wrong format.", (isoLang[length / 2]
+ .length() == 2)
+ && isoLang[length / 2].toLowerCase()
+ .equals(isoLang[length / 2]));
+ assertTrue("Wrong number of ISOLanguages.", length > 130);
+ }
+
+ /**
+ * @tests java.util.Locale#getLanguage()
+ */
+ public void test_getLanguage() {
+ // Test for method java.lang.String java.util.Locale.getLanguage()
+ assertTrue("Returned incorrect language: " + testLocale.getLanguage(),
+ testLocale.getLanguage().equals("en"));
+ }
+
+ /**
+ * @tests java.util.Locale#getVariant()
+ */
+ public void test_getVariant() {
+ // Test for method java.lang.String java.util.Locale.getVariant()
+ assertTrue("Returned incorrect variant: " + testLocale.getVariant(),
+ testLocale.getVariant().equals("WIN32"));
+ }
+
+ /**
+ * @tests java.util.Locale#setDefault(java.util.Locale)
+ */
+ public void test_setDefaultLjava_util_Locale() {
+ // Test for method void java.util.Locale.setDefault(java.util.Locale)
+
+ Locale org = Locale.getDefault();
+ Locale.setDefault(l);
+ Locale x = Locale.getDefault();
+ Locale.setDefault(org);
+ assertTrue("Failed to set locale", x.toString().equals("fr_CA_WIN32"));
+
+ Locale.setDefault(new Locale("tr", ""));
+ String res1 = "\u0069".toUpperCase();
+ String res2 = "\u0049".toLowerCase();
+ Locale.setDefault(org);
+ assertTrue("Wrong toUppercase conversion", res1.equals("\u0130"));
+ assertTrue("Wrong toLowercase conversion", res2.equals("\u0131"));
+ }
+
+ /**
+ * @tests java.util.Locale#toString()
+ */
+ public void test_toString() {
+ // Test for method java.lang.String java.util.Locale.toString()
+ assertTrue("Returned incorrect string representation", testLocale
+ .toString().equals("en_CA_WIN32"));
+
+ Locale l = new Locale("en", "");
+ assertTrue("Wrong representation 1", l.toString().equals("en"));
+ l = new Locale("", "CA");
+ assertTrue("Wrong representation 2", l.toString().equals("_CA"));
+ l = new Locale("", "CA", "var");
+ assertTrue("Wrong representation 2.5", l.toString().equals("_CA_var"));
+ l = new Locale("en", "", "WIN");
+ assertTrue("Wrong representation 4", l.toString().equals("en__WIN"));
+ l = new Locale("en", "CA");
+ assertTrue("Wrong representation 6", l.toString().equals("en_CA"));
+ l = new Locale("en", "CA", "VAR");
+ assertTrue("Wrong representation 7", l.toString().equals("en_CA_VAR"));
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+
+ testLocale = new Locale("en", "CA", "WIN32");
+ l = new Locale("fr", "CA", "WIN32");
+ }
+
+ /**
+ * 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/MissingResourceExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/MissingResourceExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/MissingResourceExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/MissingResourceExceptionTest.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.util;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class MissingResourceExceptionTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.util.MissingResourceException#MissingResourceException(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_StringLjava_lang_StringLjava_lang_String() {
+ // Test for method java.util.MissingResourceException(java.lang.String,
+ // java.lang.String, java.lang.String)
+ try {
+ ResourceBundle.getBundle("Non-ExistentBundle");
+ } catch (MissingResourceException e) {
+ return;
+ }
+ fail("Failed to generate expected exception");
+ }
+
+ /**
+ * @tests java.util.MissingResourceException#getClassName()
+ */
+ public void test_getClassName() {
+ // Test for method java.lang.String
+ // java.util.MissingResourceException.getClassName()
+ try {
+ ResourceBundle.getBundle("Non-ExistentBundle");
+ } catch (MissingResourceException e) {
+ assertTrue("Returned incorrect class name", e.getClassName()
+ .equals("Non-ExistentBundle"));
+ }
+ }
+
+ /**
+ * @tests java.util.MissingResourceException#getKey()
+ */
+ public void test_getKey() {
+ // Test for method java.lang.String
+ // java.util.MissingResourceException.getKey()
+ try {
+ ResourceBundle.getBundle("Non-ExistentBundle");
+ } catch (MissingResourceException e) {
+ assertTrue("Returned incorrect class name", e.getKey().equals(""));
+ }
+ }
+
+ /**
+ * 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/util/NoSuchElementExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/NoSuchElementExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/NoSuchElementExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/NoSuchElementExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,68 @@
+/* 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.NoSuchElementException;
+import java.util.Vector;
+
+public class NoSuchElementExceptionTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.util.NoSuchElementException#NoSuchElementException()
+ */
+ public void test_Constructor() {
+ // Test for method java.util.NoSuchElementException()
+
+ try {
+ Vector v = new Vector();
+ v.elements().nextElement();
+ } catch (NoSuchElementException e) {
+ return;
+ }
+ // if we make it to here, assert a fail
+ fail("Failed to catch expected Exception");
+ }
+
+ /**
+ * @tests java.util.NoSuchElementException#NoSuchElementException(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ // Test for method java.util.NoSuchElementException(java.lang.String)
+
+ try {
+ Vector v = new Vector();
+ v.firstElement();
+ } catch (NoSuchElementException e) {
+ return;
+ }
+ // if we make it to here, assert a fail
+ fail("Failed to catch Exception");
+ }
+
+ /**
+ * 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/util/ObservableTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ObservableTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ObservableTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ObservableTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,227 @@
+/* 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.Observable;
+import java.util.Observer;
+import java.util.Vector;
+
+public class ObservableTest extends junit.framework.TestCase {
+
+ static class TestObserver implements Observer {
+ public Vector objv = new Vector();
+
+ int updateCount = 0;
+
+ public void update(Observable observed, Object arg) {
+ ++updateCount;
+ objv.add(arg);
+ }
+
+ public int updateCount() {
+ return updateCount;
+ }
+
+ }
+
+ static class DeleteTestObserver implements Observer {
+ int updateCount = 0;
+
+ boolean deleteAll = false;
+
+ public DeleteTestObserver(boolean all) {
+ deleteAll = all;
+ }
+
+ public void update(Observable observed, Object arg) {
+ ++updateCount;
+ if (deleteAll)
+ observed.deleteObservers();
+ else
+ observed.deleteObserver(this);
+ }
+
+ public int updateCount() {
+ return updateCount;
+ }
+
+ }
+
+ static class TestObservable extends Observable {
+ public void doChange() {
+ setChanged();
+ }
+ }
+
+ Observer observer;
+
+ TestObservable observable;
+
+ /**
+ * @tests java.util.Observable#Observable()
+ */
+ public void test_Constructor() {
+ // Test for method java.util.Observable()
+ try {
+ Observable ov = new Observable();
+ assertTrue("Wrong initial values.", !ov.hasChanged());
+ assertTrue("Wrong initial values.", ov.countObservers() == 0);
+ } catch (Exception e) {
+ fail("Exception during test : " + e.getMessage());
+ }
+ }
+
+ /**
+ * @tests java.util.Observable#addObserver(java.util.Observer)
+ */
+ public void test_addObserverLjava_util_Observer() {
+ // Test for method void
+ // java.util.Observable.addObserver(java.util.Observer)
+ TestObserver test = new TestObserver();
+ observable.addObserver(test);
+ assertTrue("Failed to add observer", observable.countObservers() == 1);
+ observable.addObserver(test);
+ assertTrue("Duplicate observer", observable.countObservers() == 1);
+
+ Observable o = new Observable();
+ try {
+ o.addObserver(null);
+ fail("Expected adding a null observer to throw a NPE.");
+ } catch (NullPointerException ex) {
+ // expected;
+ } catch (Throwable ex) {
+ fail("Did not expect adding a new observer to throw a "
+ + ex.getClass().getName());
+ }
+ }
+
+ /**
+ * @tests java.util.Observable#countObservers()
+ */
+ public void test_countObservers() {
+ // Test for method int java.util.Observable.countObservers()
+ assertTrue("New observable had > 0 observers", observable
+ .countObservers() == 0);
+ observable.addObserver(new TestObserver());
+ assertTrue("Observable with observer returned other than 1", observable
+ .countObservers() == 1);
+ }
+
+ /**
+ * @tests java.util.Observable#deleteObserver(java.util.Observer)
+ */
+ public void test_deleteObserverLjava_util_Observer() {
+ // Test for method void
+ // java.util.Observable.deleteObserver(java.util.Observer)
+ observable.addObserver(observer = new TestObserver());
+ observable.deleteObserver(observer);
+ assertTrue("Failed to delete observer",
+ observable.countObservers() == 0);
+
+ }
+
+ /**
+ * @tests java.util.Observable#deleteObservers()
+ */
+ public void test_deleteObservers() {
+ // Test for method void java.util.Observable.deleteObservers()
+ observable.addObserver(new TestObserver());
+ observable.addObserver(new TestObserver());
+ observable.addObserver(new TestObserver());
+ observable.addObserver(new TestObserver());
+ observable.addObserver(new TestObserver());
+ observable.addObserver(new TestObserver());
+ observable.addObserver(new TestObserver());
+ observable.addObserver(new TestObserver());
+ observable.deleteObservers();
+ assertTrue("Failed to delete observers",
+ observable.countObservers() == 0);
+ }
+
+ /**
+ * @tests java.util.Observable#hasChanged()
+ */
+ public void test_hasChanged() {
+ // TODO : Implement test
+ }
+
+ /**
+ * @tests java.util.Observable#notifyObservers()
+ */
+ public void test_notifyObservers() {
+ // Test for method void java.util.Observable.notifyObservers()
+ observable.addObserver(observer = new TestObserver());
+ observable.notifyObservers();
+ assertTrue("Notified when unchnaged", ((TestObserver) observer)
+ .updateCount() == 0);
+ ((TestObservable) observable).doChange();
+ observable.notifyObservers();
+ assertTrue("Failed to notify",
+ ((TestObserver) observer).updateCount() == 1);
+
+ DeleteTestObserver observer1, observer2;
+ observable.deleteObservers();
+ observable.addObserver(observer1 = new DeleteTestObserver(false));
+ observable.addObserver(observer2 = new DeleteTestObserver(false));
+ observable.doChange();
+ observable.notifyObservers();
+ assertTrue("Failed to notify all", observer1.updateCount() == 1
+ && observer2.updateCount() == 1);
+ assertTrue("Failed to delete all", observable.countObservers() == 0);
+
+ observable.addObserver(observer1 = new DeleteTestObserver(false));
+ observable.addObserver(observer2 = new DeleteTestObserver(false));
+ observable.doChange();
+ observable.notifyObservers();
+ assertTrue("Failed to notify all 2", observer1.updateCount() == 1
+ && observer2.updateCount() == 1);
+ assertTrue("Failed to delete all 2", observable.countObservers() == 0);
+ }
+
+ /**
+ * @tests java.util.Observable#notifyObservers(java.lang.Object)
+ */
+ public void test_notifyObserversLjava_lang_Object() {
+ // Test for method void
+ // java.util.Observable.notifyObservers(java.lang.Object)
+ Object obj;
+ observable.addObserver(observer = new TestObserver());
+ observable.notifyObservers();
+ assertTrue("Notified when unchanged", ((TestObserver) observer)
+ .updateCount() == 0);
+ ((TestObservable) observable).doChange();
+ observable.notifyObservers(obj = new Object());
+ assertTrue("Failed to notify",
+ ((TestObserver) observer).updateCount() == 1);
+ assertTrue("Failed to pass Object arg", ((TestObserver) observer).objv
+ .elementAt(0).equals(obj));
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+ observable = new TestObservable();
+ }
+
+ /**
+ * 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/PropertiesTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/PropertiesTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/PropertiesTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/PropertiesTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,361 @@
+/* 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.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import tests.support.resource.Support_Resources;
+
+public class PropertiesTest extends junit.framework.TestCase {
+
+ Properties tProps;
+
+ byte[] propsFile;
+
+ /**
+ * @tests java.util.Properties#Properties()
+ */
+ public void test_Constructor() {
+ // Test for method java.util.Properties()
+ Properties p = new Properties();
+ // do something to avoid getting a variable unused warning
+ p.clear();
+ assertTrue("Created incorrect Properties", true);
+ }
+
+ /**
+ * @tests java.util.Properties#Properties(java.util.Properties)
+ */
+ public void test_ConstructorLjava_util_Properties() {
+ // Test for method java.util.Properties(java.util.Properties)
+ if (System.getProperty("java.vendor") != null) {
+ try {
+ Properties p = new Properties(System.getProperties());
+ assertTrue("failed to construct correct properties", p
+ .getProperty("java.vendor") != null);
+ } catch (Exception e) {
+ fail("exception occured while creating construcotr" + e);
+ }
+ }
+
+ }
+
+ /**
+ * @tests java.util.Properties#getProperty(java.lang.String)
+ */
+ public void test_getPropertyLjava_lang_String() {
+ // Test for method java.lang.String
+ // java.util.Properties.getProperty(java.lang.String)
+ assertTrue("Did not retrieve property", ((String) tProps
+ .getProperty("test.prop")).equals("this is a test property"));
+ }
+
+ /**
+ * @tests java.util.Properties#getProperty(java.lang.String,
+ * java.lang.String)
+ */
+ public void test_getPropertyLjava_lang_StringLjava_lang_String() {
+ // Test for method java.lang.String
+ // java.util.Properties.getProperty(java.lang.String, java.lang.String)
+ assertTrue("Did not retrieve property", ((String) tProps.getProperty(
+ "test.prop", "Blarg")).equals("this is a test property"));
+ assertTrue("Did not return default value", ((String) tProps
+ .getProperty("notInThere.prop", "Gabba")).equals("Gabba"));
+ }
+
+ /**
+ * @tests java.util.Properties#list(java.io.PrintStream)
+ */
+ public void test_listLjava_io_PrintStream() {
+ // Test for method void java.util.Properties.list(java.io.PrintStream)
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintStream ps = new PrintStream(baos);
+ Properties myProps = new Properties();
+ String propList;
+ myProps.setProperty("Abba", "Cadabra");
+ myProps.setProperty("Open", "Sesame");
+ myProps.list(ps);
+ ps.flush();
+ propList = baos.toString();
+ assertTrue("Property list innacurate", (propList
+ .indexOf("Abba=Cadabra") >= 0)
+ && (propList.indexOf("Open=Sesame") >= 0));
+ }
+
+ /**
+ * @tests java.util.Properties#list(java.io.PrintWriter)
+ */
+ public void test_listLjava_io_PrintWriter() {
+ // Test for method void java.util.Properties.list(java.io.PrintWriter)
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintWriter pw = new PrintWriter(baos);
+ Properties myProps = new Properties();
+ String propList;
+ myProps.setProperty("Abba", "Cadabra");
+ myProps.setProperty("Open", "Sesame");
+ myProps.list(pw);
+ pw.flush();
+ propList = baos.toString();
+ assertTrue("Property list innacurate", (propList
+ .indexOf("Abba=Cadabra") >= 0)
+ && (propList.indexOf("Open=Sesame") >= 0));
+ }
+
+ /**
+ * @tests java.util.Properties#load(java.io.InputStream)
+ */
+ public void test_loadLjava_io_InputStream() {
+ // Test for method void java.util.Properties.load(java.io.InputStream)
+ Properties prop = null;
+ try {
+ InputStream is;
+ prop = new Properties();
+ prop.load(is = new ByteArrayInputStream(writeProperties()));
+ is.close();
+ } catch (Exception e) {
+ fail("Exception during load test : " + e.getMessage());
+ }
+ assertTrue("Failed to load correct properties", prop.getProperty(
+ "test.pkg").equals("harmony.tests"));
+ assertTrue("Load failed to parse incorrectly", prop
+ .getProperty("commented.entry") == null);
+
+ prop = new Properties();
+ try {
+ prop.load(new ByteArrayInputStream("=".getBytes()));
+ } catch (IOException e) {
+ }
+ assertTrue("Failed to add empty key", prop.get("").equals(""));
+
+ prop = new Properties();
+ try {
+ prop.load(new ByteArrayInputStream(" = ".getBytes()));
+ } catch (IOException e) {
+ }
+ assertTrue("Failed to add empty key2", prop.get("").equals(""));
+
+ prop = new Properties();
+ try {
+ prop.load(new ByteArrayInputStream(" a= b".getBytes()));
+ } catch (IOException e) {
+ }
+ assertTrue("Failed to ignore whitespace", prop.get("a").equals("b"));
+
+ prop = new Properties();
+ try {
+ prop.load(new ByteArrayInputStream(" a b".getBytes()));
+ } catch (IOException e) {
+ }
+ assertTrue("Failed to interpret whitespace as =", prop.get("a").equals(
+ "b"));
+
+ prop = new Properties();
+ try {
+ prop.load(new ByteArrayInputStream("#\u008d\u00d2\na=\u008d\u00d3"
+ .getBytes("ISO8859_1")));
+ } catch (IOException e) {
+ }
+ assertTrue("Failed to parse chars >= 0x80", prop.get("a").equals(
+ "\u008d\u00d3"));
+
+ prop = new Properties();
+ try {
+ prop.load(new ByteArrayInputStream(
+ "#properties file\r\nfred=1\r\n#last comment"
+ .getBytes("ISO8859_1")));
+ } catch (IOException e) {
+ } catch (IndexOutOfBoundsException e) {
+ fail("IndexOutOfBoundsException when last line is a comment with no line terminator");
+ }
+ assertTrue("Failed to load when last line contains a comment", prop
+ .get("fred").equals("1"));
+ }
+
+ /**
+ * @tests java.util.Properties#load(java.io.InputStream)
+ */
+ public void test_loadLjava_io_InputStream_subtest0() {
+ try {
+ InputStream is = Support_Resources
+ .getStream("hyts_PropertiesTest.properties");
+ Properties props = new Properties();
+ props.load(is);
+ is.close();
+ assertEquals("1", "\n \t \f", props.getProperty(" \r"));
+ assertEquals("2", "a", props.getProperty("a"));
+ assertEquals("3", "bb as,dn ", props.getProperty("b"));
+ assertEquals("4", ":: cu", props.getProperty("c\r \t\nu"));
+ assertEquals("5", "bu", props.getProperty("bu"));
+ assertEquals("6", "d\r\ne=e", props.getProperty("d"));
+ assertEquals("7", "fff", props.getProperty("f"));
+ assertEquals("8", "g", props.getProperty("g"));
+ assertEquals("9", "", props.getProperty("h h"));
+ assertEquals("10", "i=i", props.getProperty(" "));
+ assertEquals("11", " j", props.getProperty("j"));
+ assertEquals("12", " c", props.getProperty("space"));
+ assertEquals("13", "\\", props.getProperty("dblbackslash"));
+ } catch (IOException e) {
+ fail("Unexpected: " + e);
+ }
+ }
+
+ /**
+ * @tests java.util.Properties#propertyNames()
+ */
+ public void test_propertyNames() {
+ // Test for method java.util.Enumeration
+ // java.util.Properties.propertyNames()
+
+ Enumeration names = tProps.propertyNames();
+ int i = 0;
+ while (names.hasMoreElements()) {
+ ++i;
+ String p = (String) names.nextElement();
+ assertTrue("Incorrect names returned", p.equals("test.prop")
+ || p.equals("bogus.prop"));
+ }
+ }
+
+ /**
+ * @tests java.util.Properties#save(java.io.OutputStream, java.lang.String)
+ */
+ public void test_saveLjava_io_OutputStreamLjava_lang_String() {
+ // Test for method void java.util.Properties.save(java.io.OutputStream,
+ // java.lang.String)
+ Properties myProps = new Properties();
+ Properties myProps2 = new Properties();
+ Enumeration e;
+ String nextKey;
+
+ myProps.setProperty("Property A", "aye");
+ myProps.setProperty("Property B", "bee");
+ myProps.setProperty("Property C", "see");
+
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ myProps.save(out, "A Header");
+ out.close();
+ ByteArrayInputStream in = new ByteArrayInputStream(out
+ .toByteArray());
+ myProps2.load(in);
+ in.close();
+ } catch (IOException ioe) {
+ fail("IOException occurred reading/writing file : "
+ + ioe.getMessage());
+ }
+
+ e = myProps.propertyNames();
+ while (e.hasMoreElements()) {
+ nextKey = (String) e.nextElement();
+ assertTrue("Stored property list not equal to original", myProps2
+ .getProperty(nextKey).equals(myProps.getProperty(nextKey)));
+ }
+
+ }
+
+ /**
+ * @tests java.util.Properties#setProperty(java.lang.String,
+ * java.lang.String)
+ */
+ public void test_setPropertyLjava_lang_StringLjava_lang_String() {
+ // Test for method java.lang.Object
+ // java.util.Properties.setProperty(java.lang.String, java.lang.String)
+ Properties myProps = new Properties();
+ myProps.setProperty("Yoink", "Yabba");
+ assertTrue("Failed to set property", myProps.getProperty("Yoink")
+ .equals("Yabba"));
+ myProps.setProperty("Yoink", "Gab");
+ assertTrue("Failed to reset property", myProps.getProperty("Yoink")
+ .equals("Gab"));
+ }
+
+ /**
+ * @tests java.util.Properties#store(java.io.OutputStream, java.lang.String)
+ */
+ public void test_storeLjava_io_OutputStreamLjava_lang_String() {
+ // Test for method void java.util.Properties.store(java.io.OutputStream,
+ // java.lang.String)
+ Properties myProps = new Properties();
+ Properties myProps2 = new Properties();
+ Enumeration e;
+ String nextKey;
+
+ myProps.put("Property A", " aye\\\f\t\n\r\b");
+ myProps.put("Property B", "b ee#!=:");
+ myProps.put("Property C", "see");
+
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ myProps.store(out, "A Header");
+ out.close();
+ ByteArrayInputStream in = new ByteArrayInputStream(out
+ .toByteArray());
+ myProps2.load(in);
+ in.close();
+ } catch (IOException ioe) {
+ fail("IOException occurred reading/writing file : "
+ + ioe.getMessage());
+ }
+
+ e = myProps.propertyNames();
+ while (e.hasMoreElements()) {
+ nextKey = (String) e.nextElement();
+ assertTrue("Stored property list not equal to original", myProps2
+ .getProperty(nextKey).equals(myProps.getProperty(nextKey)));
+ }
+
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+
+ tProps = new Properties();
+ tProps.put("test.prop", "this is a test property");
+ tProps.put("bogus.prop", "bogus");
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ protected void tearDown() {
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ protected byte[] writeProperties() throws IOException {
+ PrintStream ps = null;
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ ps = new PrintStream(bout);
+ ps.println("#commented.entry=Bogus");
+ ps.println("test.pkg=harmony.tests");
+ ps.println("test.proj=Automated Tests");
+ ps.close();
+ return bout.toByteArray();
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/PropertyPermissionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/PropertyPermissionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/PropertyPermissionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/PropertyPermissionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,135 @@
+/* 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.Enumeration;
+import java.util.PropertyPermission;
+
+public class PropertyPermissionTest extends junit.framework.TestCase {
+
+ static PropertyPermission javaPP = new PropertyPermission("java.*", "read");
+
+ static PropertyPermission userPP = new PropertyPermission("user.name",
+ "read,write");
+
+ /**
+ * @tests java.util.PropertyPermission#PropertyPermission(java.lang.String,
+ * java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_StringLjava_lang_String() {
+ // Test for method java.util.PropertyPermission(java.lang.String,
+ // java.lang.String)
+ assertTrue("Used to test", true);
+ }
+
+ /**
+ * @tests java.util.PropertyPermission#equals(java.lang.Object)
+ */
+ public void test_equalsLjava_lang_Object() {
+ // Test for method boolean
+ // java.util.PropertyPermission.equals(java.lang.Object)
+ PropertyPermission equalToJavaPP = new PropertyPermission("java.*",
+ "read");
+ PropertyPermission notEqualToJavaPP = new PropertyPermission("java.*",
+ "read, write");
+ PropertyPermission alsoNotEqualToJavaPP = new PropertyPermission(
+ "java.home", "read");
+
+ assertTrue("Equal returned false for equal objects", javaPP
+ .equals(equalToJavaPP));
+ assertTrue("Equal returned true for objects with different names",
+ !javaPP.equals(notEqualToJavaPP));
+ assertTrue(
+ "Equal returned true for objects with different permissions",
+ !javaPP.equals(alsoNotEqualToJavaPP));
+ }
+
+ /**
+ * @tests java.util.PropertyPermission#getActions()
+ */
+ public void test_getActions() {
+ // Test for method java.lang.String
+ // java.util.PropertyPermission.getActions()
+ assertTrue("getActions did not return proper action", javaPP
+ .getActions().equals("read"));
+ assertTrue(
+ "getActions did not return proper canonical representation of actions",
+ userPP.getActions().equals("read,write"));
+ }
+
+ /**
+ * @tests java.util.PropertyPermission#hashCode()
+ */
+ public void test_hashCode() {
+ // Test for method int java.util.PropertyPermission.hashCode()
+ assertTrue("javaPP returned wrong hashCode",
+ javaPP.hashCode() == javaPP.getName().hashCode());
+ assertTrue("userPP returned wrong hashCode",
+ userPP.hashCode() == userPP.getName().hashCode());
+ }
+
+ /**
+ * @tests java.util.PropertyPermission#implies(java.security.Permission)
+ */
+ public void test_impliesLjava_security_Permission() {
+ // Test for method boolean
+ // java.util.PropertyPermission.implies(java.security.Permission)
+ PropertyPermission impliedByJavaPP = new PropertyPermission(
+ "java.home", "read");
+ PropertyPermission notImpliedByJavaPP = new PropertyPermission(
+ "java.home", "read,write");
+ PropertyPermission impliedByUserPP = new PropertyPermission(
+ "user.name", "read,write");
+ PropertyPermission alsoImpliedByUserPP = new PropertyPermission(
+ "user.name", "write");
+ assertTrue("Returned false for implied permission (subset of .*)",
+ javaPP.implies(impliedByJavaPP));
+ assertTrue("Returned true for unimplied permission", !javaPP
+ .implies(notImpliedByJavaPP));
+ assertTrue("Returned false for implied permission (equal)", userPP
+ .implies(impliedByUserPP));
+ assertTrue("Returned false for implied permission (subset of actions)",
+ userPP.implies(alsoImpliedByUserPP));
+ }
+
+ /**
+ * @tests java.util.PropertyPermission#newPermissionCollection()
+ */
+ public void test_newPermissionCollection() {
+ // Test for method java.security.PermissionCollection
+ // java.util.PropertyPermission.newPermissionCollection()
+ java.security.PermissionCollection pc = javaPP
+ .newPermissionCollection();
+ pc.add(javaPP);
+ Enumeration elementEnum = pc.elements();
+ assertTrue("Invalid PermissionCollection returned", elementEnum
+ .nextElement().equals(javaPP));
+ }
+
+ /**
+ * 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/util/PropertyResourceBundleTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/PropertyResourceBundleTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/PropertyResourceBundleTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/PropertyResourceBundleTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,96 @@
+/* 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.Enumeration;
+import java.util.MissingResourceException;
+import java.util.PropertyResourceBundle;
+import java.util.Vector;
+
+public class PropertyResourceBundleTest extends junit.framework.TestCase {
+
+ static PropertyResourceBundle prb;
+
+ /**
+ * @tests java.util.PropertyResourceBundle#PropertyResourceBundle(java.io.InputStream)
+ */
+ public void test_ConstructorLjava_io_InputStream() {
+ // Test for method java.util.PropertyResourceBundle(java.io.InputStream)
+ assertTrue("Used to test", true);
+ }
+
+ /**
+ * @tests java.util.PropertyResourceBundle#getKeys()
+ */
+ public void test_getKeys() {
+ Enumeration keyEnum = prb.getKeys();
+ Vector test = new Vector();
+ int keyCount = 0;
+ while (keyEnum.hasMoreElements()) {
+ test.addElement(keyEnum.nextElement());
+ keyCount++;
+ }
+
+ assertTrue("Returned the wrong number of keys", keyCount == 2);
+ assertTrue("Returned the wrong keys", test.contains("p1")
+ && test.contains("p2"));
+ }
+
+ /**
+ * @tests java.util.PropertyResourceBundle#handleGetObject(java.lang.String)
+ */
+ public void test_handleGetObjectLjava_lang_String() {
+ // Test for method java.lang.Object
+ // java.util.PropertyResourceBundle.handleGetObject(java.lang.String)
+ try {
+ assertTrue("Returned incorrect objects", prb.getObject("p1")
+ .equals("one")
+ && prb.getObject("p2").equals("two"));
+ } catch (MissingResourceException e) {
+ fail(
+ "Threw MisingResourceException for a key contained in the bundle");
+ }
+ try {
+ prb.getObject("Not in the bundle");
+ } catch (MissingResourceException e) {
+ return;
+ }
+ fail(
+ "Failed to throw MissingResourceException for object not in the bundle");
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+ java.io.InputStream propertiesStream = new java.io.ByteArrayInputStream(
+ "p1=one\np2=two".getBytes());
+ try {
+ prb = new PropertyResourceBundle(propertiesStream);
+ } catch (java.io.IOException e) {
+ fail(
+ "Contruction of PropertyResourceBundle threw IOException");
+ }
+ }
+
+ /**
+ * 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/RandomTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/RandomTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/RandomTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/RandomTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,259 @@
+/* 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.Random;
+
+public class RandomTest extends junit.framework.TestCase {
+
+ Random r;
+
+ /**
+ * @tests java.util.Random#Random()
+ */
+ public void test_Constructor() {
+ // Test for method java.util.Random()
+ assertTrue("Used to test", true);
+ }
+
+ /**
+ * @tests java.util.Random#Random(long)
+ */
+ public void test_ConstructorJ() {
+ Random r = new Random(8409238L);
+ Random r2 = new Random(8409238L);
+ for (int i = 0; i < 100; i++)
+ assertTrue("Values from randoms with same seed don't match", r
+ .nextInt() == r2.nextInt());
+ }
+
+ /**
+ * @tests java.util.Random#nextBoolean()
+ */
+ public void test_nextBoolean() {
+ // Test for method boolean java.util.Random.nextBoolean()
+ boolean falseAppeared = false, trueAppeared = false;
+ for (int counter = 0; counter < 100; counter++)
+ if (r.nextBoolean())
+ trueAppeared = true;
+ else
+ falseAppeared = true;
+ assertTrue("Calling nextBoolean() 100 times resulted in all trues",
+ falseAppeared);
+ assertTrue("Calling nextBoolean() 100 times resulted in all falses",
+ trueAppeared);
+ }
+
+ /**
+ * @tests java.util.Random#nextBytes(byte[])
+ */
+ public void test_nextBytes$B() {
+ // Test for method void java.util.Random.nextBytes(byte [])
+ boolean someDifferent = false;
+ byte[] randomBytes = new byte[100];
+ r.nextBytes(randomBytes);
+ byte firstByte = randomBytes[0];
+ for (int counter = 1; counter < randomBytes.length; counter++)
+ if (randomBytes[counter] != firstByte)
+ someDifferent = true;
+ assertTrue(
+ "nextBytes() returned an array of length 100 of the same byte",
+ someDifferent);
+ }
+
+ /**
+ * @tests java.util.Random#nextDouble()
+ */
+ public void test_nextDouble() {
+ // Test for method double java.util.Random.nextDouble()
+ double lastNum = r.nextDouble();
+ double nextNum;
+ boolean someDifferent = false;
+ boolean inRange = true;
+ for (int counter = 0; counter < 100; counter++) {
+ nextNum = r.nextDouble();
+ if (nextNum != lastNum)
+ someDifferent = true;
+ if (!(0 <= nextNum && nextNum < 1.0))
+ inRange = false;
+ lastNum = nextNum;
+ }
+ assertTrue("Calling nextDouble 100 times resulted in same number",
+ someDifferent);
+ assertTrue(
+ "Calling nextDouble resulted in a number out of range [0,1)",
+ inRange);
+ }
+
+ /**
+ * @tests java.util.Random#nextFloat()
+ */
+ public void test_nextFloat() {
+ // Test for method float java.util.Random.nextFloat()
+ float lastNum = r.nextFloat();
+ float nextNum;
+ boolean someDifferent = false;
+ boolean inRange = true;
+ for (int counter = 0; counter < 100; counter++) {
+ nextNum = r.nextFloat();
+ if (nextNum != lastNum)
+ someDifferent = true;
+ if (!(0 <= nextNum && nextNum < 1.0))
+ inRange = false;
+ lastNum = nextNum;
+ }
+ assertTrue("Calling nextFloat 100 times resulted in same number",
+ someDifferent);
+ assertTrue("Calling nextFloat resulted in a number out of range [0,1)",
+ inRange);
+ }
+
+ /**
+ * @tests java.util.Random#nextGaussian()
+ */
+ public void test_nextGaussian() {
+ // Test for method double java.util.Random.nextGaussian()
+ double lastNum = r.nextGaussian();
+ double nextNum;
+ boolean someDifferent = false;
+ boolean someInsideStd = false;
+ for (int counter = 0; counter < 100; counter++) {
+ nextNum = r.nextGaussian();
+ if (nextNum != lastNum)
+ someDifferent = true;
+ if (-1.0 <= nextNum && nextNum <= 1.0)
+ someInsideStd = true;
+ lastNum = nextNum;
+ }
+ assertTrue("Calling nextGaussian 100 times resulted in same number",
+ someDifferent);
+ assertTrue(
+ "Calling nextGaussian 100 times resulted in no number within 1 std. deviation of mean",
+ someInsideStd);
+ }
+
+ /**
+ * @tests java.util.Random#nextInt()
+ */
+ public void test_nextInt() {
+ // Test for method int java.util.Random.nextInt()
+ int lastNum = r.nextInt();
+ int nextNum;
+ boolean someDifferent = false;
+ for (int counter = 0; counter < 100; counter++) {
+ nextNum = r.nextInt();
+ if (nextNum != lastNum)
+ someDifferent = true;
+ lastNum = nextNum;
+ }
+ assertTrue("Calling nextInt 100 times resulted in same number",
+ someDifferent);
+ }
+
+ /**
+ * @tests java.util.Random#nextInt(int)
+ */
+ public void test_nextIntI() {
+ // Test for method int java.util.Random.nextInt(int)
+ final int range = 10;
+ int lastNum = r.nextInt(range);
+ int nextNum;
+ boolean someDifferent = false;
+ boolean inRange = true;
+ for (int counter = 0; counter < 100; counter++) {
+ nextNum = r.nextInt(range);
+ if (nextNum != lastNum)
+ someDifferent = true;
+ if (!(0 <= nextNum && nextNum < range))
+ inRange = false;
+ lastNum = nextNum;
+ }
+ assertTrue("Calling nextInt (range) 100 times resulted in same number",
+ someDifferent);
+ assertTrue(
+ "Calling nextInt (range) resulted in a number outside of [0, range)",
+ inRange);
+
+ }
+
+ /**
+ * @tests java.util.Random#nextLong()
+ */
+ public void test_nextLong() {
+ // Test for method long java.util.Random.nextLong()
+ long lastNum = r.nextLong();
+ long nextNum;
+ boolean someDifferent = false;
+ for (int counter = 0; counter < 100; counter++) {
+ nextNum = r.nextLong();
+ if (nextNum != lastNum)
+ someDifferent = true;
+ lastNum = nextNum;
+ }
+ assertTrue("Calling nextLong 100 times resulted in same number",
+ someDifferent);
+ }
+
+ /**
+ * @tests java.util.Random#setSeed(long)
+ */
+ public void test_setSeedJ() {
+ // Test for method void java.util.Random.setSeed(long)
+ long[] randomArray = new long[100];
+ boolean someDifferent = false;
+ final long firstSeed = 1000;
+ long aLong, anotherLong, yetAnotherLong;
+ Random aRandom = new Random();
+ Random anotherRandom = new Random();
+ Random yetAnotherRandom = new Random();
+ aRandom.setSeed(firstSeed);
+ anotherRandom.setSeed(firstSeed);
+ for (int counter = 0; counter < randomArray.length; counter++) {
+ aLong = aRandom.nextLong();
+ anotherLong = anotherRandom.nextLong();
+ assertTrue(
+ "Two randoms with same seeds gave differing nextLong values",
+ aLong == anotherLong);
+ yetAnotherLong = yetAnotherRandom.nextLong();
+ randomArray[counter] = aLong;
+ if (aLong != yetAnotherLong)
+ someDifferent = true;
+ }
+ assertTrue(
+ "Two randoms with the different seeds gave the same chain of values",
+ someDifferent);
+ aRandom.setSeed(firstSeed);
+ for (int counter = 0; counter < randomArray.length; counter++)
+ assertTrue(
+ "Reseting a random to its old seed did not result in the same chain of values as it gave before",
+ aRandom.nextLong() == randomArray[counter]);
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+ r = new Random();
+ }
+
+ /**
+ * 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/ResourceBundleTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ResourceBundleTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ResourceBundleTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ResourceBundleTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,156 @@
+/* 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.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import tests.support.resource.Support_Resources;
+
+public class ResourceBundleTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.util.ResourceBundle#getBundle(java.lang.String,
+ * java.util.Locale)
+ */
+ public void test_getBundleLjava_lang_StringLjava_util_Locale() {
+ ResourceBundle bundle;
+ String name = "tests.support.Support_TestResource";
+ Locale defLocale = Locale.getDefault();
+
+ Locale.setDefault(new Locale("en", "US"));
+ bundle = ResourceBundle.getBundle(name, new Locale("fr", "FR", "VAR"));
+ assertTrue("Wrong bundle fr_FR_VAR", bundle.getString("parent4")
+ .equals("frFRVARValue4"));
+ bundle = ResourceBundle.getBundle(name, new Locale("fr", "FR", "v1"));
+ assertTrue("Wrong bundle fr_FR_v1", bundle.getString("parent4").equals(
+ "frFRValue4"));
+ bundle = ResourceBundle.getBundle(name, new Locale("fr", "US", "VAR"));
+ assertTrue("Wrong bundle fr_US_var", bundle.getString("parent4")
+ .equals("frValue4"));
+ bundle = ResourceBundle.getBundle(name, new Locale("de", "FR", "VAR"));
+ assertTrue("Wrong bundle de_FR_var", bundle.getString("parent4")
+ .equals("enUSValue4"));
+
+ Locale.setDefault(new Locale("fr", "FR", "VAR"));
+ bundle = ResourceBundle.getBundle(name, new Locale("de", "FR", "v1"));
+ assertTrue("Wrong bundle de_FR_var 2", bundle.getString("parent4")
+ .equals("frFRVARValue4"));
+
+ Locale.setDefault(new Locale("de", "US"));
+ bundle = ResourceBundle.getBundle(name, new Locale("de", "FR", "var"));
+ assertTrue("Wrong bundle de_FR_var 2", bundle.getString("parent4")
+ .equals("parentValue4"));
+
+ // Test with a security manager
+ Locale.setDefault(new Locale("en", "US"));
+ System.setSecurityManager(new SecurityManager());
+ try {
+ bundle = ResourceBundle.getBundle(name, new Locale("fr", "FR",
+ "VAR"));
+ assertTrue("Security: Wrong bundle fr_FR_VAR", bundle.getString(
+ "parent4").equals("frFRVARValue4"));
+ bundle = ResourceBundle.getBundle(name,
+ new Locale("fr", "FR", "v1"));
+ assertTrue("Security: Wrong bundle fr_FR_v1", bundle.getString(
+ "parent4").equals("frFRValue4"));
+ bundle = ResourceBundle.getBundle(name, new Locale("fr", "US",
+ "VAR"));
+ assertTrue("Security: Wrong bundle fr_US_var", bundle.getString(
+ "parent4").equals("frValue4"));
+ bundle = ResourceBundle.getBundle(name, new Locale("de", "FR",
+ "VAR"));
+ assertTrue("Security: Wrong bundle de_FR_var: "
+ + bundle.getString("parent4"), bundle.getString("parent4")
+ .equals("enUSValue4"));
+ } finally {
+ System.setSecurityManager(null);
+ }
+
+ Locale.setDefault(defLocale);
+ }
+
+ /**
+ * @tests java.util.ResourceBundle#getBundle(java.lang.String,
+ * java.util.Locale, java.lang.ClassLoader)
+ */
+ public void test_getBundleLjava_lang_StringLjava_util_LocaleLjava_lang_ClassLoader() {
+ String classPath = System.getProperty("java.class.path");
+ StringTokenizer tok = new StringTokenizer(classPath, File.pathSeparator);
+ Vector urlVec = new Vector();
+ String resPackage = Support_Resources.RESOURCE_PACKAGE;
+ try {
+ while (tok.hasMoreTokens()) {
+ String path = (String) tok.nextToken();
+ String url;
+ if (new File(path).isDirectory())
+ url = "file:" + path + resPackage + "subfolder/";
+ else
+ url = "jar:file:" + path + "!" + resPackage + "subfolder/";
+ urlVec.addElement(new URL(url));
+ }
+ } catch (MalformedURLException e) {
+ }
+ URL[] urls = new URL[urlVec.size()];
+ for (int i = 0; i < urlVec.size(); i++)
+ urls[i] = (URL) urlVec.elementAt(i);
+ URLClassLoader loader = new URLClassLoader(urls, null);
+
+ String name = Support_Resources.RESOURCE_PACKAGE_NAME
+ + ".hyts_resource";
+ ResourceBundle bundle = ResourceBundle.getBundle(name, Locale
+ .getDefault());
+ bundle = ResourceBundle.getBundle(name, Locale.getDefault(), loader);
+ assertTrue("Wrong cached value", bundle.getString("property").equals(
+ "resource"));
+ }
+
+ /**
+ * @tests java.util.ResourceBundle#getString(java.lang.String)
+ */
+ public void test_getStringLjava_lang_String() {
+ ResourceBundle bundle;
+ String name = "tests.support.Support_TestResource";
+ Locale.setDefault(new Locale("en", "US"));
+ bundle = ResourceBundle.getBundle(name, new Locale("fr", "FR", "VAR"));
+ assertTrue("Wrong value parent4", bundle.getString("parent4").equals(
+ "frFRVARValue4"));
+ assertTrue("Wrong value parent3", bundle.getString("parent3").equals(
+ "frFRValue3"));
+ assertTrue("Wrong value parent2", bundle.getString("parent2").equals(
+ "frValue2"));
+ assertTrue("Wrong value parent1", bundle.getString("parent1").equals(
+ "parentValue1"));
+ assertTrue("Wrong value child3", bundle.getString("child3").equals(
+ "frFRVARChildValue3"));
+ assertTrue("Wrong value child2", bundle.getString("child2").equals(
+ "frFRVARChildValue2"));
+ assertTrue("Wrong value child1", bundle.getString("child1").equals(
+ "frFRVARChildValue1"));
+ }
+
+ protected void setUp() {
+ }
+
+ protected void tearDown() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/SampleBundleClass.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/SampleBundleClass.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/SampleBundleClass.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/SampleBundleClass.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,42 @@
+/* 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.util;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * Part of the ResourceBundleTest
+ */
+public class SampleBundleClass {
+
+ private static SampleBundleClass singleton;
+ private static ResourceBundle bundle;
+
+ public SampleBundleClass() {
+ super();
+ if (singleton != null) {
+ throw new RuntimeException();
+ }
+ singleton = this;
+ try {
+ bundle = ResourceBundle.getBundle("tests.api.simple.SampleBundleClass");
+ } catch (MissingResourceException x) {
+ System.out.println("Missing resource");
+ bundle = null;
+ }
+ }
+}