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 [20/49] - in /incubator/harmony/enhanced/classlib/trunk:
make/ modules/archive/make/common/ modules/archive/src/test/java/tests/
modules/archive/src/test/java/tests/api/
modules/archive/src/test/java/tests/api/java/ modules/archive/...
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NegativeArraySizeExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NegativeArraySizeExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NegativeArraySizeExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NegativeArraySizeExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,64 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang;
+
+public class NegativeArraySizeExceptionTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.lang.NegativeArraySizeException#NegativeArraySizeException()
+ */
+ public void test_Constructor() {
+ // Test for method java.lang.NegativeArraySizeException()
+ try {
+ int[] x = new int[-1];
+ if (x.length > 0)
+ ; // use x[] to avoid a warning
+ } catch (NegativeArraySizeException e) {
+ return;
+ }
+ fail("Failed to generate exception");
+ }
+
+ /**
+ * @tests java.lang.NegativeArraySizeException#NegativeArraySizeException(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ // Test for method
+ // java.lang.NegativeArraySizeException(java.lang.String)
+ try {
+ int[] x = new int[-1];
+ if (x.length > 0)
+ ;// use x to avoid a warning msg
+ } catch (NegativeArraySizeException e) {
+ return;
+ }
+ fail("Failed to generate 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/lang/NoClassDefFoundErrorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NoClassDefFoundErrorTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NoClassDefFoundErrorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NoClassDefFoundErrorTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,57 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang;
+
+public class NoClassDefFoundErrorTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.lang.NoClassDefFoundError#NoClassDefFoundError()
+ */
+ public void test_Constructor() {
+ try {
+ if (true) {
+ throw new NoClassDefFoundError();
+ }
+ fail("Error not thrown.");
+ } catch (NoClassDefFoundError e) {
+ assertTrue("Error not intitialized.", e.toString().equals(
+ "java.lang.NoClassDefFoundError"));
+ }
+ }
+
+ /**
+ * @tests java.lang.NoClassDefFoundError#NoClassDefFoundError(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ try {
+ if (true) {
+ throw new NoClassDefFoundError("Hello World");
+ }
+ fail("Error not thrown.");
+ } catch (NoClassDefFoundError e) {
+ assertTrue("Wrong error message: " + e.getMessage(), e.getMessage()
+ .equals("Hello World"));
+ } catch (Exception e) {
+ fail("Exception during test : " + e.getMessage());
+ }
+ }
+
+ protected void setUp() {
+ }
+
+ protected void tearDown() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NoSuchFieldErrorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NoSuchFieldErrorTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NoSuchFieldErrorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NoSuchFieldErrorTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,57 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang;
+
+public class NoSuchFieldErrorTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.lang.NoSuchFieldError#NoSuchFieldError()
+ */
+ public void test_Constructor() {
+ try {
+ if (true)
+ throw new NoSuchFieldError();
+ } catch (NoSuchFieldError e) {
+ assertTrue("Initializer failed.", e.getMessage() == null);
+ assertTrue("To string failed.", e.toString().equals(
+ "java.lang.NoSuchFieldError"));
+ }
+ }
+
+ /**
+ * @tests java.lang.NoSuchFieldError#NoSuchFieldError(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ // No accessible method throws this error.
+ try {
+ if (true)
+ throw new NoSuchFieldError("Hello World");
+ } catch (NoSuchFieldError e) {
+ assertTrue("Incorrect message: " + e.getMessage(), e.getMessage()
+ .equals("Hello World"));
+ return;
+ } catch (Throwable e) {
+ fail("Wrong error thrown : " + e.getMessage());
+ }
+ fail("Error not thrown.");
+ }
+
+ protected void setUp() {
+ }
+
+ protected void tearDown() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NoSuchFieldExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NoSuchFieldExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NoSuchFieldExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NoSuchFieldExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,63 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang;
+
+public class NoSuchFieldExceptionTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.lang.NoSuchFieldException#NoSuchFieldException()
+ */
+ public void test_Constructor() {
+ // Test for method java.lang.NoSuchFieldException()
+ try {
+ String.class.getDeclaredField("prsttrvol");
+ } catch (NoSuchFieldException e) {
+ // Correct
+ return;
+ }
+ fail("Failed to throw exception");
+
+ }
+
+ /**
+ * @tests java.lang.NoSuchFieldException#NoSuchFieldException(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ // Test for method java.lang.NoSuchFieldException(java.lang.String)
+ try {
+ String.class.getDeclaredField("prsttrvol");
+ } catch (NoSuchFieldException e) {
+ // Correct
+ return;
+ }
+ fail("Failed to throw 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/lang/NoSuchMethodErrorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NoSuchMethodErrorTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NoSuchMethodErrorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NoSuchMethodErrorTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,57 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang;
+
+public class NoSuchMethodErrorTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.lang.NoSuchMethodError#NoSuchMethodError()
+ */
+ public void test_Constructor() {
+ try {
+ if (true)
+ throw new NoSuchMethodError();
+ } catch (NoSuchMethodError e) {
+ assertTrue("Initializer failed.", e.getMessage() == null);
+ assertTrue("To string failed.", e.toString().equals(
+ "java.lang.NoSuchMethodError"));
+ }
+ }
+
+ /**
+ * @tests java.lang.NoSuchMethodError#NoSuchMethodError(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ // No accessible method throws this error.
+ try {
+ if (true)
+ throw new NoSuchMethodError("Hello World");
+ } catch (NoSuchMethodError e) {
+ assertTrue("Incorrect message: " + e.getMessage(), e.getMessage()
+ .equals("Hello World"));
+ return;
+ } catch (Throwable e) {
+ fail("Wrong error thrown : " + e);
+ }
+ fail("Error not thrown");
+ }
+
+ protected void setUp() {
+ }
+
+ protected void tearDown() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NoSuchMethodExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NoSuchMethodExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NoSuchMethodExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NoSuchMethodExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,61 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang;
+
+public class NoSuchMethodExceptionTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.lang.NoSuchMethodException#NoSuchMethodException()
+ */
+ public void test_Constructor() {
+ // Test for method java.lang.NoSuchMethodException()
+ try {
+ String.class.getMethod("voidMethod", new Class[0]);
+ } catch (NoSuchMethodException e) {
+ // Correct
+ return;
+ }
+ fail("Failed to throw exception");
+ }
+
+ /**
+ * @tests java.lang.NoSuchMethodException#NoSuchMethodException(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ // Test for method java.lang.NoSuchMethodException(java.lang.String)
+ try {
+ String.class.getMethod("voidMethod", new Class[0]);
+ } catch (NoSuchMethodException e) {
+ // Correct
+ return;
+ }
+ fail("Failed to throw 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/lang/NullPointerExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NullPointerExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NullPointerExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NullPointerExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,64 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.java.lang;
+
+public class NullPointerExceptionTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.lang.NullPointerException#NullPointerException()
+ */
+ public void test_Constructor() {
+ // Test for method java.lang.NullPointerException()
+ try {
+ byte[] rbuf = null;
+ int z = rbuf.length;
+ if (z > 0)
+ ; // use z to avoid a warning msg
+ } catch (java.lang.NullPointerException e) {
+ return;
+ }
+ fail("Failed to generate Exception");
+ }
+
+ /**
+ * @tests java.lang.NullPointerException#NullPointerException(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ // Test for method java.lang.NullPointerException(java.lang.String)
+ try {
+ byte[] rbuf = null;
+ int z = rbuf.length;
+ if (z > 0)
+ ; // use z to avoid a warning msg
+ } catch (java.lang.NullPointerException e) {
+ return;
+ }
+ fail("Failed to generate 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/lang/NumberFormatExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NumberFormatExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NumberFormatExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NumberFormatExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,67 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang;
+
+public class NumberFormatExceptionTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.lang.NumberFormatException#NumberFormatException()
+ */
+ public void test_Constructor() {
+ // Test for method java.lang.NumberFormatException()
+ try {
+ try {
+ Byte.parseByte("128");
+ } catch (NumberFormatException e) {
+ return;
+ }
+ fail("Failed to generate Exception");
+ } catch (Exception e) {
+ fail("Exception during test : " + e.getMessage());
+ }
+ }
+
+ /**
+ * @tests java.lang.NumberFormatException#NumberFormatException(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ // Test for method java.lang.NumberFormatException(java.lang.String)
+ try {
+ try {
+ Byte.parseByte("128");
+ } catch (NumberFormatException e) {
+ return;
+ }
+ fail("Failed to generate Exception");
+ } catch (Exception e) {
+ fail("Exception during test : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ protected void tearDown() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NumberTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NumberTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NumberTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NumberTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,77 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang;
+
+public class NumberTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.lang.Number#Number()
+ */
+ public void test_Constructor() {
+ assertTrue("Nothing to test", true);
+ }
+
+ /**
+ * @tests java.lang.Number#byteValue()
+ */
+ public void test_byteValue() {
+ int number = 1231243;
+ assertTrue("Incorrect byte returned for: " + number,
+ ((byte) new Integer(number).intValue()) == new Integer(number)
+ .byteValue());
+ number = 0;
+ assertTrue("Incorrect byte returned for: " + number,
+ ((byte) new Integer(number).intValue()) == new Integer(number)
+ .byteValue());
+ number = -1;
+ assertTrue("Incorrect byte returned for: " + number,
+ ((byte) new Integer(number).intValue()) == new Integer(number)
+ .byteValue());
+ number = -84109328;
+ assertTrue("Incorrect byte returned for: " + number,
+ ((byte) new Integer(number).intValue()) == new Integer(number)
+ .byteValue());
+ }
+
+ /**
+ * @tests java.lang.Number#shortValue()
+ */
+ public void test_shortValue() {
+ int number = 1231243;
+ assertTrue("Incorrect byte returned for: " + number,
+ ((short) new Integer(number).intValue()) == new Integer(number)
+ .shortValue());
+ number = 0;
+ assertTrue("Incorrect byte returned for: " + number,
+ ((short) new Integer(number).intValue()) == new Integer(number)
+ .shortValue());
+ number = -1;
+ assertTrue("Incorrect byte returned for: " + number,
+ ((short) new Integer(number).intValue()) == new Integer(number)
+ .shortValue());
+ number = -84109328;
+ assertTrue("Incorrect byte returned for: " + number,
+ ((short) new Integer(number).intValue()) == new Integer(number)
+ .shortValue());
+
+ }
+
+ protected void setUp() {
+ }
+
+ protected void tearDown() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ObjectTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ObjectTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ObjectTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ObjectTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,404 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.java.lang;
+
+public class ObjectTest extends junit.framework.TestCase {
+
+ /**
+ * Test objects.
+ */
+ Object obj1 = new Object();
+
+ Object obj2 = new Object();
+
+ /**
+ * Generic state indicator.
+ */
+ int status = 0;
+
+ int ready = 0;
+
+ /**
+ * @tests java.lang.Object#Object()
+ */
+ public void test_Constructor() {
+ // Test for method java.lang.Object()
+ assertTrue("Constructor failed !!!", new Object() != null);
+ }
+
+ /**
+ * @tests java.lang.Object#equals(java.lang.Object)
+ */
+ public void test_equalsLjava_lang_Object() {
+ // Test for method boolean java.lang.Object.equals(java.lang.Object)
+ assertTrue("Same object should be equal", obj1.equals(obj1));
+ assertTrue("Different objects should not be equal", !obj1.equals(obj2));
+ }
+
+ /**
+ * @tests java.lang.Object#getClass()
+ */
+ public void test_getClass() {
+ // Test for method java.lang.Class java.lang.Object.getClass()
+ String classNames[] = { "java.lang.Object", "java.lang.Throwable",
+ "java.lang.StringBuffer" };
+ Class classToTest = null;
+ Object instanceToTest = null;
+
+ status = 0;
+ for (int i = 0; i < classNames.length; ++i) {
+ try {
+ classToTest = Class.forName(classNames[i]);
+ instanceToTest = classToTest.newInstance();
+ assertTrue("Instance didn't match creator class.",
+ instanceToTest.getClass() == classToTest);
+ assertTrue("Instance didn't match class with matching name.",
+ instanceToTest.getClass() == Class
+ .forName(classNames[i]));
+ } catch (Exception ex) {
+ fail("Unexpected exception : " + ex.getMessage());
+ }
+ }
+ }
+
+ /**
+ * @tests java.lang.Object#hashCode()
+ */
+ public void test_hashCode() {
+ // Test for method int java.lang.Object.hashCode()
+ assertTrue("Same object should have same hash.",
+ obj1.hashCode() == obj1.hashCode());
+ assertTrue("Same object should have same hash.",
+ obj2.hashCode() == obj2.hashCode());
+ }
+
+ /**
+ * @tests java.lang.Object#notify()
+ */
+ public void test_notify() {
+ // Test for method void java.lang.Object.notify()
+
+ // Inner class to run test thread.
+ class TestThread implements Runnable {
+ public void run() {
+ synchronized (obj1) {
+ try {
+ ready += 1;
+ obj1.wait();// Wait for ever.
+ status += 1;
+ } catch (InterruptedException ex) {
+ status = -1000;
+ }
+ }
+ }
+ }
+ ;
+
+ // Start of test code.
+
+ // Warning:
+ // This code relies on each thread getting serviced within
+ // 200 mSec of when it is notified. Although this
+ // seems reasonable, it could lead to false-failures.
+
+ ready = 0;
+ status = 0;
+ final int readyWaitSecs = 3;
+
+ final int threadCount = 20;
+ for (int i = 0; i < threadCount; ++i) {
+ new Thread(new TestThread()).start();
+ }
+ synchronized (obj1) {
+ try {
+
+ // Wait up to readyWaitSeconds for all threads to be waiting on
+ // monitor
+ for (int i = 0; i < readyWaitSecs; i++) {
+ obj1.wait(1000, 0);
+ if (ready == threadCount) {
+ break;
+ }
+ }
+
+ // Check pre-conditions of testing notifyAll
+ assertTrue("Not all launched threads are waiting. (ready = "
+ + ready + ")", ready == threadCount);
+ assertTrue("Thread woke too early. (status = " + status + ")",
+ status == 0);
+
+ for (int i = 1; i <= threadCount; ++i) {
+ obj1.notify();
+ obj1.wait(200, 0);
+ assertTrue("Out of sync. (expected " + i + " but got "
+ + status + ")", status == i);
+ }
+
+ } catch (InterruptedException ex) {
+ fail(
+ "Unexpectedly got an InterruptedException. (status = "
+ + status + ")");
+ }
+ }
+ }
+
+ /**
+ * @tests java.lang.Object#notifyAll()
+ */
+ public void test_notifyAll() {
+ // Test for method void java.lang.Object.notifyAll()
+
+ // Inner class to run test thread.
+ class TestThread implements Runnable {
+ public void run() {
+ synchronized (obj1) {
+ try {
+ ready += 1;
+ obj1.wait();// Wait for ever.
+ status += 1;
+ } catch (InterruptedException ex) {
+ status = -1000;
+ }
+ }
+ }
+ }
+ ;
+
+ // Start of test code.
+
+ // Warning:
+ // This code relies on all threads getting serviced within
+ // 5 seconds of when they are notified. Although this
+ // seems reasonable, it could lead to false-failures.
+
+ status = 0;
+ ready = 0;
+ final int readyWaitSecs = 3;
+ final int threadCount = 20;
+ for (int i = 0; i < threadCount; ++i) {
+ new Thread(new TestThread()).start();
+ }
+
+ synchronized (obj1) {
+
+ try {
+
+ // Wait up to readyWaitSeconds for all threads to be waiting on
+ // monitor
+ for (int i = 0; i < readyWaitSecs; i++) {
+ obj1.wait(1000, 0);
+ if (ready == threadCount) {
+ break;
+ }
+ }
+
+ // Check pre-conditions of testing notifyAll
+ assertTrue("Not all launched threads are waiting. (ready = "
+ + ready + ")", ready == threadCount);
+ assertTrue("At least one thread woke too early. (status = "
+ + status + ")", status == 0);
+
+ obj1.notifyAll();
+
+ obj1.wait(5000, 0);
+
+ assertTrue(
+ "At least one thread did not get notified. (status = "
+ + status + ")", status == threadCount);
+
+ } catch (InterruptedException ex) {
+ fail(
+ "Unexpectedly got an InterruptedException. (status = "
+ + status + ")");
+ }
+
+ }
+ }
+
+ /**
+ * @tests java.lang.Object#toString()
+ */
+ public void test_toString() {
+ // Test for method java.lang.String java.lang.Object.toString()
+ assertTrue("Object toString returned null.", obj1.toString() != null);
+ }
+
+ /**
+ * @tests java.lang.Object#wait()
+ */
+ public void test_wait() {
+ // Test for method void java.lang.Object.wait()
+
+ // Inner class to run test thread.
+ class TestThread implements Runnable {
+ public void run() {
+ synchronized (obj1) {
+ try {
+ obj1.wait();// Wait for ever.
+ status = 1;
+ } catch (InterruptedException ex) {
+ status = -1;
+ }
+ }
+ }
+ }
+ ;
+
+ // Start of test code.
+
+ // Warning:
+ // This code relies on threads getting serviced within
+ // 1 second of when they are notified. Although this
+ // seems reasonable, it could lead to false-failures.
+
+ status = 0;
+ new Thread(new TestThread()).start();
+ synchronized (obj1) {
+ try {
+ obj1.wait(1000, 0);
+ assertTrue("Thread woke too early. (status = " + status + ")",
+ status == 0);
+ obj1.notifyAll();
+ obj1.wait(1000, 0);
+ assertTrue("Thread did not get notified. (status = " + status
+ + ")", status == 1);
+ } catch (InterruptedException ex) {
+ fail(
+ "Unexpectedly got an InterruptedException. (status = "
+ + status + ")");
+ }
+ }
+ }
+
+ /**
+ * @tests java.lang.Object#wait(long)
+ */
+ public void test_waitJ() {
+ // Test for method void java.lang.Object.wait(long)
+
+ // Start of test code.
+
+ final int loopCount = 20;
+ final int allowableError = 100; // millesconds
+ final int delay = 200; // milliseconds
+ synchronized (obj1) {
+ try {
+ int count = 0;
+ long[][] toLong = new long[3][3];
+ for (int i = 0; i < loopCount; ++i) {
+ long before = System.currentTimeMillis();
+ obj1.wait(delay, 0);
+ long after = System.currentTimeMillis();
+ long error = (after - before - delay);
+ if (error < 0)
+ error = -error;
+ if (i > 0 && error > allowableError) {
+ // Allow jit to warm up before testing
+ if (count < toLong.length) {
+ toLong[count][0] = i;
+ toLong[count][1] = before;
+ toLong[count][2] = after;
+ count++;
+ }
+ if (error > (1000 + delay) || count == toLong.length) {
+ StringBuffer sb = new StringBuffer();
+ for (int j = 0; j < count; j++) {
+ sb
+ .append("wakeup time too inaccurate, iteration ");
+ sb.append(toLong[j][0]);
+ sb.append(", before: ");
+ sb.append(toLong[j][1]);
+ sb.append(" after: ");
+ sb.append(toLong[j][2]);
+ sb.append(" diff: ");
+ sb.append(toLong[j][2] - toLong[j][1]);
+ sb.append("\n");
+ }
+ fail(sb.toString());
+ }
+ }
+ }
+ } catch (InterruptedException ex) {
+ fail(
+ "Unexpectedly got an InterruptedException. (status = "
+ + status + ")");
+ }
+ }
+ }
+
+ /**
+ * @tests java.lang.Object#wait(long, int)
+ */
+ public void test_waitJI() {
+ // Test for method void java.lang.Object.wait(long, int)
+
+ // Inner class to run test thread.
+ class TestThread implements Runnable {
+ public void run() {
+ synchronized (obj1) {
+ try {
+ obj1.wait(0, 1); // Don't wait very long.
+ status = 1;
+ obj1.wait(0, 0); // Wait for ever.
+ status = 2;
+ } catch (InterruptedException ex) {
+ status = -1;
+ }
+ }
+ }
+ }
+ ;
+
+ // Start of test code.
+
+ // Warning:
+ // This code relies on threads getting serviced within
+ // 1 second of when they are notified. Although this
+ // seems reasonable, it could lead to false-failures.
+
+ status = 0;
+ new Thread(new TestThread()).start();
+ synchronized (obj1) {
+ try {
+ obj1.wait(1000, 0);
+ assertTrue("Thread did not wake after 1 ms. (status = "
+ + status + ")", status == 1);
+ obj1.notifyAll();
+ obj1.wait(1000, 0);
+ assertTrue("Thread did not get notified. (status = " + status
+ + ")", status == 2);
+ } catch (InterruptedException ex) {
+ fail(
+ "Unexpectedly got an InterruptedException. (status = "
+ + status + ")");
+ }
+ }
+
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ protected void tearDown() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/OutOfMemoryErrorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/OutOfMemoryErrorTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/OutOfMemoryErrorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/OutOfMemoryErrorTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,66 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang;
+
+public class OutOfMemoryErrorTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.lang.OutOfMemoryError#OutOfMemoryError()
+ */
+ public void test_Constructor() {
+ // Test for method java.lang.OutOfMemoryError()
+ try {
+ StringBuffer large[] = new StringBuffer[100000];
+
+ for (int i = 0; i < large.length; i++)
+ large[i] = new StringBuffer(1000000);
+ } catch (OutOfMemoryError e) {
+ return;
+ }
+ fail("No error generated");
+ }
+
+ /**
+ * @tests java.lang.OutOfMemoryError#OutOfMemoryError(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ // Test for method java.lang.OutOfMemoryError(java.lang.String)
+ try {
+ StringBuffer large[] = new StringBuffer[100000];
+
+ for (int i = 0; i < large.length; i++)
+ large[i] = new StringBuffer(1000000);
+ } catch (OutOfMemoryError e) {
+ return;
+ }
+ fail("No error generated");
+ }
+
+ /**
+ * 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() {
+ System.gc();
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/PackageTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/PackageTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/PackageTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/PackageTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,457 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.java.lang;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.net.URL;
+
+import tests.support.resource.Support_Resources;
+
+public class PackageTest extends junit.framework.TestCase {
+
+ private File resources;
+
+ private String resPath;
+
+ /**
+ * There is a newer version of this class with some actual tests but since
+ * the class is not implemented they all fail. For now use the stub test
+ * methods.
+ */
+
+ /**
+ * @tests java.lang.Package#getImplementationVendor()
+ * @tests java.lang.Package#getImplementationVersion()
+ * @tests java.lang.Package#getSpecificationTitle()
+ * @tests java.lang.Package#getSpecificationVendor()
+ * @tests java.lang.Package#getSpecificationVersion()
+ * @tests java.lang.Package#getImplementationTitle()
+ */
+ public void test_helper_Attributes() {
+
+ // All attributes in the package entry
+ java.net.URL[] urls = new java.net.URL[1];
+ Class c = null;
+ java.net.URLClassLoader ucl = null;
+ Support_Resources.copyFile(resources, "Package",
+ "hyts_all_attributes.jar");
+ try {
+ java.net.URL resourceURL = new URL("file:/" + resPath
+ + "/Package/hyts_all_attributes.jar");
+ urls[0] = resourceURL;
+ ucl = new java.net.URLClassLoader(urls, null);
+ c = Class.forName("p.C", true, ucl);
+ assertTrue(
+ "Package getImplementationTitle returns a wrong string (1)",
+ c.getPackage().getImplementationTitle().equals(
+ "p Implementation-Title"));
+ assertTrue(
+ "Package getImplementationVendor returns a wrong string (1)",
+ c.getPackage().getImplementationVendor().equals(
+ "p Implementation-Vendor"));
+ assertTrue(
+ "Package getImplementationVersion returns a wrong string (1)",
+ c.getPackage().getImplementationVersion().equals("2.2.2"));
+ assertTrue(
+ "Package getSpecificationTitle returns a wrong string (1)",
+ c.getPackage().getSpecificationTitle().equals(
+ "p Specification-Title"));
+ assertTrue(
+ "Package getSpecificationVendor returns a wrong string (1)",
+ c.getPackage().getSpecificationVendor().equals(
+ "p Specification-Vendor"));
+ assertTrue(
+ "Package getSpecificationVersion returns a wrong string (1)",
+ c.getPackage().getSpecificationVersion().equals("2.2.2"));
+ } catch (Exception e) {
+ fail("Exception during helperAttributes test : " + e.getMessage());
+ }
+
+ // No entry for the package
+ Support_Resources.copyFile(resources, "Package", "hyts_no_entry.jar");
+ try {
+ java.net.URL resourceURL = new URL("file:/" + resPath
+ + "/Package/hyts_no_entry.jar");
+ urls[0] = resourceURL;
+ ucl = new java.net.URLClassLoader(urls, null);
+ c = Class.forName("p.C", true, ucl);
+ assertTrue(
+ "Package getImplementationTitle returns a wrong string (2)",
+ c.getPackage().getImplementationTitle().equals(
+ "MF Implementation-Title"));
+ assertTrue(
+ "Package getImplementationVendor returns a wrong string (2)",
+ c.getPackage().getImplementationVendor().equals(
+ "MF Implementation-Vendor"));
+ assertTrue(
+ "Package getImplementationVersion returns a wrong string (2)",
+ c.getPackage().getImplementationVersion().equals("5.3.b1"));
+ assertTrue(
+ "Package getSpecificationTitle returns a wrong string (2)",
+ c.getPackage().getSpecificationTitle().equals(
+ "MF Specification-Title"));
+ assertTrue(
+ "Package getSpecificationVendor returns a wrong string (2)",
+ c.getPackage().getSpecificationVendor().equals(
+ "MF Specification-Vendor"));
+ assertTrue(
+ "Package getSpecificationVersion returns a wrong string (2)",
+ c.getPackage().getSpecificationVersion().equals("1.2.3"));
+ } catch (Exception e) {
+ fail("Exception in helperAttributes test : " + e.getMessage());
+ }
+
+ // No attributes in the package entry
+ Support_Resources.copyFile(resources, "Package",
+ "hyts_no_attributes.jar");
+ try {
+ java.net.URL resourceURL = new URL("file:/" + resPath
+ + "/Package/hyts_no_attributes.jar");
+ urls[0] = resourceURL;
+ ucl = new java.net.URLClassLoader(urls, null);
+ c = Class.forName("p.C", true, ucl);
+ assertTrue(
+ "Package getImplementationTitle returns a wrong string (3)",
+ c.getPackage().getImplementationTitle().equals(
+ "MF Implementation-Title"));
+ assertTrue(
+ "Package getImplementationVendor returns a wrong string (3)",
+ c.getPackage().getImplementationVendor().equals(
+ "MF Implementation-Vendor"));
+ assertTrue(
+ "Package getImplementationVersion returns a wrong string (3)",
+ c.getPackage().getImplementationVersion().equals("5.3.b1"));
+ assertTrue(
+ "Package getSpecificationTitle returns a wrong string (3)",
+ c.getPackage().getSpecificationTitle().equals(
+ "MF Specification-Title"));
+ assertTrue(
+ "Package getSpecificationVendor returns a wrong string (3)",
+ c.getPackage().getSpecificationVendor().equals(
+ "MF Specification-Vendor"));
+ assertTrue(
+ "Package getSpecificationVersion returns a wrong string (3)",
+ c.getPackage().getSpecificationVersion().equals("1.2.3"));
+ } catch (Exception e) {
+ fail("Exception during helperAttributes test : " + e.getMessage());
+ }
+
+ // Some attributes in the package entry
+ Support_Resources.copyFile(resources, "Package",
+ "hyts_some_attributes.jar");
+ try {
+ java.net.URL resourceURL = new URL("file:/" + resPath
+ + "/Package/hyts_some_attributes.jar");
+ urls[0] = resourceURL;
+ ucl = new java.net.URLClassLoader(urls, null);
+ c = Class.forName("p.C", true, ucl);
+ assertTrue(
+ "Package getImplementationTitle returns a wrong string (4)",
+ c.getPackage().getImplementationTitle().equals(
+ "p Implementation-Title"));
+ assertTrue(
+ "Package getImplementationVendor returns a wrong string (4)",
+ c.getPackage().getImplementationVendor().equals(
+ "MF Implementation-Vendor"));
+ assertTrue(
+ "Package getImplementationVersion returns a wrong string (4)",
+ c.getPackage().getImplementationVersion().equals("2.2.2"));
+ assertTrue(
+ "Package getSpecificationTitle returns a wrong string (4)",
+ c.getPackage().getSpecificationTitle().equals(
+ "MF Specification-Title"));
+ assertTrue(
+ "Package getSpecificationVendor returns a wrong string (4)",
+ c.getPackage().getSpecificationVendor().equals(
+ "p Specification-Vendor"));
+ assertTrue(
+ "Package getSpecificationVersion returns a wrong string (4)",
+ c.getPackage().getSpecificationVersion().equals("2.2.2"));
+ } catch (Exception e) {
+ fail("Exception during helperAttributes test : " + e.getMessage());
+ }
+
+ // subdirectory Package
+ Support_Resources.copyFile(resources, "Package", "hyts_pq.jar");
+ try {
+ java.net.URL resourceURL = new URL("file:/" + resPath
+ + "/Package/hyts_pq.jar");
+ urls[0] = resourceURL;
+ ucl = new java.net.URLClassLoader(urls, null);
+ c = Class.forName("p.q.C", true, ucl);
+ assertTrue(
+ "Package getImplementationTitle returns a wrong string (5)",
+ c.getPackage().getImplementationTitle().equals(
+ "p Implementation-Title"));
+ assertTrue(
+ "Package getImplementationVendor returns a wrong string (5)",
+ c.getPackage().getImplementationVendor().equals(
+ "p Implementation-Vendor"));
+ assertTrue(
+ "Package getImplementationVersion returns a wrong string (5)",
+ c.getPackage().getImplementationVersion().equals("1.1.3"));
+ assertTrue(
+ "Package getSpecificationTitle returns a wrong string (5)",
+ c.getPackage().getSpecificationTitle().equals(
+ "p Specification-Title"));
+ assertTrue(
+ "Package getSpecificationVendor returns a wrong string (5)",
+ c.getPackage().getSpecificationVendor().equals(
+ "p Specification-Vendor"));
+ assertTrue(
+ "Package getSpecificationVersion returns a wrong string (5)",
+ c.getPackage().getSpecificationVersion().equals(
+ "2.2.0.0.0.0.0.0.0.0.0"));
+
+ } catch (Exception e) {
+ fail("Exception during helperAttributes test : " + e.getMessage());
+ }
+ }
+
+ private static Object invokeMethod(Object obj, String name,
+ Object[] parameters) {
+
+ Class[] types = new Class[parameters.length];
+ for (int i = 0; i < parameters.length; i++) {
+ types[i] = parameters[i].getClass();
+ }
+ Class c = null;
+ if (obj instanceof Class)
+ c = (Class) obj;
+ else
+ c = obj.getClass();
+ while (c != null) {
+ try {
+ Method m = c.getDeclaredMethod(name, types);
+ m.setAccessible(true);
+ return m.invoke(obj, parameters);
+ } catch (NoSuchMethodException e) {
+ c = c.getSuperclass();
+ } catch (Exception e) {
+ break;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @tests java.lang.Package#getName()
+ */
+ public void test_getName() {
+ java.net.URL[] urls = new java.net.URL[1];
+ Class c = null;
+ java.net.URLClassLoader ucl = null;
+ Support_Resources.copyFile(resources, "Package", "hyts_pq.jar");
+ try {
+ java.net.URL resourceURL = new URL("file:/" + resPath
+ + "/Package/hyts_pq.jar");
+ urls[0] = resourceURL;
+ ucl = new java.net.URLClassLoader(urls, null);
+ c = Class.forName("p.q.C", true, ucl);
+ assertTrue("Package getName returns a wrong string", c.getPackage()
+ .getName().equals("p.q"));
+
+ } catch (Exception e) {
+ fail("Exception during getName test : " + e.getMessage());
+ }
+
+ }
+
+ /**
+ * @tests java.lang.Package#getPackage(java.lang.String)
+ */
+ public void test_getPackageLjava_lang_String() {
+ // Test for method java.lang.Package
+ // java.lang.Package.getPackage(java.lang.String)
+ Package.getPackage("java.lang");
+ try {
+ assertTrue("Package getPackage failed for java.lang", Package
+ .getPackage("java.lang") == java.lang.Object.class
+ .getPackage());
+ } catch (Exception e) {
+ fail("Unexpected exception " + e
+ + " in Package.getPackage(java.lang.String)");
+ }
+
+ }
+
+ /**
+ * @tests java.lang.Package#getPackages()
+ */
+ public void test_getPackages() {
+ // Test for method java.lang.Package [] java.lang.Package.getPackages()
+ java.net.URL[] urls = new java.net.URL[1];
+
+ java.net.URLClassLoader ucl = null;
+ Support_Resources.copyFile(resources, "Package", "hyts_pq.jar");
+ try {
+ java.net.URL resourceURL = new URL("file:/" + resPath
+ + "/Package/hyts_pq.jar");
+ urls[0] = resourceURL;
+ ucl = new java.net.URLClassLoader(urls, null);
+ Class.forName("p.q.C", true, ucl);
+ Package[] pckgs = (Package[]) invokeMethod(ucl, "getPackages",
+ new Object[0]);
+ boolean found = false;
+ for (int i = 0; i < pckgs.length; i++)
+ if (pckgs[i].getName().equals("p.q")) {
+ found = true;
+ break;
+ }
+ assertTrue("Package getPackages failed to retrieve a package",
+ found);
+ } catch (Exception e) {
+ fail("Unexpected exception " + e
+ + " in Package.getPackages()");
+ }
+ }
+
+ /**
+ * @tests java.lang.Package#hashCode()
+ */
+ public void test_hashCode() {
+ // Test for method int java.lang.Package.hashCode()
+ Package p1 = Package.getPackage("java.lang");
+ Package p2 = Package.getPackage("java.lang");
+ if (p1 != null)
+ assertTrue(
+ "Package hashCode does not return the same hashcode for 2 packages with the same name",
+ p1.hashCode() == p2.hashCode());
+ }
+
+ /**
+ * @tests java.lang.Package#isCompatibleWith(java.lang.String)
+ */
+ public void test_isCompatibleWithLjava_lang_String() {
+ // Test for method boolean
+ // java.lang.Package.isCompatibleWith(java.lang.String)
+ java.net.URL[] urls = new java.net.URL[1];
+ Class c = null;
+ java.net.URLClassLoader ucl = null;
+ Support_Resources.copyFile(resources, "Package", "hyts_c.jar");
+ try {
+ java.net.URL resourceURL = new URL("file:/" + resPath
+ + "/Package/hyts_c.jar");
+ urls[0] = resourceURL;
+ ucl = new java.net.URLClassLoader(urls, null);
+ c = Class.forName("p.C", true, ucl);
+ Package p = c.getPackage();
+ assertTrue("Package isCompatibleWith fails with lower version", p
+ .isCompatibleWith("2.1.9.") == true);
+ assertTrue("Package isCompatibleWith fails with same version (1)",
+ p.isCompatibleWith("2.2.0") == true);
+ assertTrue("Package isCompatibleWith fails with same version (2)",
+ p.isCompatibleWith("2.2") == true);
+ assertTrue("Package isCompatibleWith fails with higher version", p
+ .isCompatibleWith("2.2.0.0.1") == false);
+ } catch (Exception e) {
+ fail("Exception during isCompatibleWith test : " + e.getMessage());
+ }
+ }
+
+ /**
+ * @tests java.lang.Package#isSealed()
+ */
+ public void test_isSealed() {
+ // Test for method boolean java.lang.Package.isSealed()
+ java.net.URL[] urls = new java.net.URL[1];
+ Class c = null;
+ java.net.URLClassLoader ucl = null;
+ Support_Resources.copyFile(resources, "Package", "hyts_pq.jar");
+ try {
+ java.net.URL resourceURL = new URL("file:/" + resPath
+ + "/Package/hyts_pq.jar");
+ urls[0] = resourceURL;
+ ucl = new java.net.URLClassLoader(urls, null);
+ c = Class.forName("p.q.C", true, ucl);
+ assertTrue("Package isSealed returns wrong boolean", c.getPackage()
+ .isSealed() == true);
+
+ } catch (Exception e) {
+ fail("Exception during isSealed test : " + e.getMessage());
+ }
+
+ }
+
+ /**
+ * @tests java.lang.Package#isSealed(java.net.URL)
+ */
+ public void test_isSealedLjava_net_URL() {
+ // Test for method boolean java.lang.Package.isSealed(java.net.URL)
+ java.net.URL[] urls = new java.net.URL[1];
+ Class c = null;
+ java.net.URLClassLoader ucl = null;
+ Support_Resources.copyFile(resources, "Package", "hyts_c.jar");
+ try {
+ java.net.URL resourceURL = new URL("file:/" + resPath
+ + "/Package/hyts_c.jar");
+ urls[0] = resourceURL;
+ ucl = new java.net.URLClassLoader(urls, null);
+ c = Class.forName("p.C", true, ucl);
+ assertTrue(
+ "Package isSealed returns wrong boolean (1)",
+ c.getPackage().isSealed(new URL("file:/" + resPath + "/")) == false);
+ assertTrue("Package isSealed returns wrong boolean (2)",
+ c.getPackage()
+ .isSealed(
+ new URL("file:/" + resPath
+ + "/Package/hyts_c.jar")) == true);
+ } catch (Exception e) {
+ fail("Exception during isSealed test : " + e.getMessage());
+ }
+ }
+
+ /**
+ * @tests java.lang.Package#toString()
+ */
+ public void test_toString() {
+ // Test for method java.lang.String java.lang.Package.toString()
+ java.net.URL[] urls = new java.net.URL[1];
+ Class c = null;
+ java.net.URLClassLoader ucl = null;
+ Support_Resources.copyFile(resources, "Package", "hyts_c.jar");
+ try {
+ java.net.URL resourceURL = new URL("file:/" + resPath
+ + "/Package/hyts_c.jar");
+ urls[0] = resourceURL;
+ ucl = java.net.URLClassLoader.newInstance(urls, null);
+ c = Class.forName("p.C", true, ucl);
+ assertTrue("Package toString returns wrong string", c.getPackage()
+ .toString().length() > 0);
+ } catch (Exception e) {
+ fail("Exception during isSealed test : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+ resources = Support_Resources.createTempFolder();
+ resPath = resources.toString();
+ if (resPath.charAt(0) == '/' || resPath.charAt(0) == '\\')
+ resPath = resPath.substring(1);
+
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ protected void tearDown() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ProcessTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ProcessTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ProcessTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/ProcessTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,140 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import tests.support.Support_Exec;
+
+public class ProcessTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.lang.Process#getInputStream()
+ */
+ public void test_getInputStream() {
+ try {
+ // Test for:
+ Object[] execArgs = Support_Exec.execJava2(
+ new String[] { "tests.support.Support_AvailTest" }, null,
+ true);
+ Process proc = (Process) execArgs[0];
+
+ OutputStream os = proc.getOutputStream();
+
+ // first number indicates total stream length
+ // second number indicates length of data after second space
+ // this will allow us to verify length at start, middle, and end
+ os.write("10 5 abcde".getBytes());
+ os.close();
+
+ InputStream is = proc.getInputStream();
+ StringBuffer msg = new StringBuffer("");
+ while (true) {
+ int c = is.read();
+ if (c == -1)
+ break;
+ msg.append((char) c);
+ }
+ is.close();
+ proc.waitFor();
+ Support_Exec.checkStderr(execArgs);
+ proc.destroy();
+ assertTrue(msg.toString(), msg.toString().equals("true"));
+ } catch (IOException e) {
+ fail("IOException executing avail test: " + e);
+ } catch (InterruptedException e) {
+ fail("InterruptedException executing avail test: " + e);
+ }
+ }
+
+ /**
+ * @tests java.lang.Process#getOutputStream()
+ */
+ public void test_getOutputStream() {
+ try {
+ Object[] execArgs = Support_Exec
+ .execJava2(
+ new String[] { "tests.support.Support_ProcessReadWriteTest" },
+ null, true);
+ Process proc = (Process) execArgs[0];
+
+ OutputStream os = proc.getOutputStream();
+
+ // send data, and check if it is echoed back correctly
+ String str1 = "Some data for testing communication between processes\n";
+ String str2 = "More data that serves the same purpose.\n";
+ String str3 = "Here is some more data.\n";
+ os.write(str1.getBytes());
+ try {
+ Thread.currentThread().sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ os.write(str2.getBytes());
+ os.write(str3.getBytes());
+ os.close();
+
+ InputStream is = proc.getInputStream();
+ StringBuffer msg = new StringBuffer("");
+ while (true) {
+ int c = is.read();
+ if (c == -1)
+ break;
+ msg.append((char) c);
+ }
+ is.close();
+ proc.waitFor();
+ Support_Exec.checkStderr(execArgs);
+ proc.destroy();
+ String org = str1 + str2 + str3;
+ String recvd = msg.toString();
+ if (!recvd.equals(org)) {
+ System.out.println("Sent:");
+ for (int i = 0; i < org.length(); i++) {
+ if (i != 0 && i % 16 == 0)
+ System.out.println();
+ System.out.print(Integer.toHexString(org.charAt(i)) + " ");
+ }
+ System.out.println();
+ System.out.println("Received:");
+ for (int i = 0; i < recvd.length(); i++) {
+ if (i != 0 && i % 16 == 0)
+ System.out.println();
+ System.out
+ .print(Integer.toHexString(recvd.charAt(i)) + " ");
+ }
+ System.out.println();
+ }
+ assertTrue("Data returned did not match data sent. Received: '"
+ + recvd + "' sent: '" + org + "'", recvd.equals(org));
+ } catch (IOException e) {
+ fail("IOException executing avail test: " + e);
+ } catch (InterruptedException e) {
+ fail("InterruptedException executing avail test: " + e);
+ }
+ }
+
+ protected void setUp() {
+ }
+
+ protected void tearDown() {
+ }
+
+ protected void doneSuite() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/RuntimeExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/RuntimeExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/RuntimeExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/RuntimeExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,67 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang;
+
+public class RuntimeExceptionTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.lang.RuntimeException#RuntimeException()
+ */
+ public void test_Constructor() {
+ // Test for method java.lang.RuntimeException()
+ // Effectively tested by the subclasses
+
+ try {
+ if (true)
+ throw new RuntimeException();
+ } catch (RuntimeException e) {
+ return;
+ }
+ fail("Failed to throw Runtime Exception");
+ }
+
+ /**
+ * @tests java.lang.RuntimeException#RuntimeException(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ // Test for method java.lang.RuntimeException(java.lang.String)
+ // Effectively tested by the subclasses
+
+ try {
+ if (true)
+ throw new RuntimeException("Runtime message");
+ } catch (RuntimeException e) {
+ assertTrue("Incorrect message", e.getMessage().equals(
+ "Runtime message"));
+ return;
+ }
+ fail("Failed to throw Runtime 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/lang/RuntimePermissionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/RuntimePermissionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/RuntimePermissionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/RuntimePermissionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,56 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang;
+
+public class RuntimePermissionTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.lang.RuntimePermission#RuntimePermission(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ // Test for method java.lang.RuntimePermission(java.lang.String)
+ RuntimePermission r = new RuntimePermission("createClassLoader");
+ assertTrue("Returned incorrect name", r.getName().equals(
+ "createClassLoader"));
+
+ }
+
+ /**
+ * @tests java.lang.RuntimePermission#RuntimePermission(java.lang.String,
+ * java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_StringLjava_lang_String() {
+ // Test for method java.lang.RuntimePermission(java.lang.String,
+ // java.lang.String)
+ RuntimePermission r = new RuntimePermission("createClassLoader", null);
+ assertTrue("Returned incorrect name", r.getName().equals(
+ "createClassLoader"));
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ protected void tearDown() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/RuntimeTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/RuntimeTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/RuntimeTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/RuntimeTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,171 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Vector;
+
+public class RuntimeTest extends junit.framework.TestCase {
+
+ Runtime r = Runtime.getRuntime();
+
+ InputStream is;
+
+ String s;
+
+ static boolean flag = false;
+
+ static boolean ranFinalize = false;
+
+ class HasFinalizer {
+ String internalString;
+
+ HasFinalizer(String s) {
+ internalString = s;
+ }
+
+ protected void finalize() {
+ internalString = "hit";
+ }
+ }
+
+ protected void finalize() {
+ if (flag)
+ ranFinalize = true;
+ }
+
+ protected RuntimeTest createInstance() {
+ return new RuntimeTest("FT");
+ }
+
+ /**
+ * @tests java.lang.Runtime#exit(int)
+ */
+ public void test_exitI() {
+ // Test for method void java.lang.Runtime.exit(int)
+ assertTrue("Can't really test this", true);
+ }
+
+ /**
+ * @tests java.lang.Runtime#exec(java.lang.String)
+ */
+ public void test_exec() {
+ boolean success = false;
+
+ /* successful exec's are tested by java.lang.Process */
+ try {
+ Runtime.getRuntime().exec("AnInexistentProgram");
+ } catch (IOException e) {
+ success = true;
+ }
+ assertTrue(
+ "failed to throw IOException when exec'ed inexistent program",
+ success);
+ }
+
+ /**
+ * @tests java.lang.Runtime#freeMemory()
+ */
+ public void test_freeMemory() {
+ // Test for method long java.lang.Runtime.freeMemory()
+ assertTrue("freeMemory returned nonsense value", r.freeMemory() > 0);
+ }
+
+ /**
+ * @tests java.lang.Runtime#gc()
+ */
+ public void test_gc() {
+ // Test for method void java.lang.Runtime.gc()
+ try {
+ r.gc(); // ensure all garbage objects have been collected
+ r.gc(); // two GCs force collection phase to complete
+ long firstRead = r.totalMemory() - r.freeMemory();
+ Vector v = new Vector();
+ for (int i = 1; i < 10; i++)
+ v.addElement(new StringBuffer(10000));
+ long secondRead = r.totalMemory() - r.freeMemory();
+ v = null;
+ r.gc();
+ r.gc();
+ assertTrue("object memory did not grow", secondRead > firstRead);
+ assertTrue("space was not reclaimed", (r.totalMemory() - r
+ .freeMemory()) < secondRead);
+ } catch (Throwable t) {
+ System.out.println("Out of memory during freeMemory test");
+ r.gc();
+ r.gc();
+ }
+ }
+
+ /**
+ * @tests java.lang.Runtime#getRuntime()
+ */
+ public void test_getRuntime() {
+ // Test for method java.lang.Runtime java.lang.Runtime.getRuntime()
+ assertTrue("Used to test", true);
+ }
+
+ /**
+ * @tests java.lang.Runtime#runFinalization()
+ */
+ public void test_runFinalization() {
+ // Test for method void java.lang.Runtime.runFinalization()
+
+ flag = true;
+ createInstance();
+ int count = 10;
+ // the gc below likely bogosifies the test, but will have to do for
+ // the moment
+ while (!ranFinalize && count-- > 0) {
+ r.gc();
+ r.runFinalization();
+ }
+ assertTrue("Failed to run finalization", ranFinalize);
+ }
+
+ /**
+ * @tests java.lang.Runtime#totalMemory()
+ */
+ public void test_totalMemory() {
+ // Test for method long java.lang.Runtime.totalMemory()
+ assertTrue("totalMemory returned nonsense value", r.totalMemory() >= r
+ .freeMemory());
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+ flag = false;
+ ranFinalize = false;
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ protected void tearDown() {
+ }
+
+ public RuntimeTest() {
+ }
+
+ public RuntimeTest(String name) {
+ super(name);
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/SecurityExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/SecurityExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/SecurityExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/SecurityExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,61 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.lang;
+
+public class SecurityExceptionTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.lang.SecurityException#SecurityException()
+ */
+ public void test_Constructor() {
+ // Test for method java.lang.SecurityException()
+ boolean threwException = false;
+ try {
+ throw new SecurityException();
+ } catch (SecurityException e) {
+ threwException = true;
+ }
+ assertTrue("Failed to generate exception", threwException);
+ }
+
+ /**
+ * @tests java.lang.SecurityException#SecurityException(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ // Test for method java.lang.SecurityException(java.lang.String)
+ boolean threwException = false;
+ try {
+ throw new SecurityException("Cannot use sockets with this manager");
+ } catch (SecurityException e) {
+ threwException = true;
+ }
+ assertTrue("Failed to generate exception", threwException);
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ protected void tearDown() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/SecurityManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/SecurityManagerTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/SecurityManagerTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/SecurityManagerTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,59 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.java.lang;
+
+public class SecurityManagerTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.lang.SecurityManager#checkMemberAccess(java.lang.Class, int)
+ */
+ public void test_checkMemberAccessLjava_lang_ClassI() {
+ try {
+ getClass().getDeclaredFields();
+ } catch (SecurityException e) {
+ fail("This should not throw a security exception");
+ }
+
+ boolean exception = false;
+ try {
+ Object.class.getDeclaredFields();
+ } catch (SecurityException e) {
+ exception = true;
+ }
+ assertTrue("Should throw SecurityException", exception);
+ }
+
+ /**
+ * @tests java.lang.SecurityManager#checkPermission(java.security.Permission)
+ */
+ public void test_checkPermissionLjava_security_Permission() {
+ boolean exception = false;
+ try {
+ System.getSecurityManager().checkPermission(
+ new RuntimePermission("createClassLoader"));
+ } catch (SecurityException e) {
+ exception = true;
+ }
+ assertTrue("Should throw SecurityException", exception);
+ }
+
+ protected void setUp() {
+ System.setSecurityManager(new SecurityManager());
+ }
+
+ protected void tearDown() {
+ System.setSecurityManager(null);
+ }
+}