summaryrefslogtreecommitdiffstats
path: root/luni
diff options
context:
space:
mode:
authorJesse Wilson <jessewilson@google.com>2009-09-30 11:57:49 -0700
committerJesse Wilson <jessewilson@google.com>2009-09-30 13:19:44 -0700
commitce61ae6a101cef0b8ea9ecc74d4690523ab2cec3 (patch)
treeeb6b1a41f98e59e6d259a481dd43dfd6e5725b6d /luni
parentcbb67b37b1a0223097763f84ebae072eca183164 (diff)
downloadlibcore-ce61ae6a101cef0b8ea9ecc74d4690523ab2cec3.zip
libcore-ce61ae6a101cef0b8ea9ecc74d4690523ab2cec3.tar.gz
libcore-ce61ae6a101cef0b8ea9ecc74d4690523ab2cec3.tar.bz2
Fixing tests that exercise SecurityManager plus stack inspection.
The tests were both broken previously. They both relied on having specific bootloader classes in their call stack.
Diffstat (limited to 'luni')
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassTest.java7
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManagerTest.java28
2 files changed, 22 insertions, 13 deletions
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassTest.java
index 3097fbe..2b492b1 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassTest.java
+++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassTest.java
@@ -838,9 +838,6 @@ public class ClassTest extends junit.framework.TestCase {
args = {}
)
public void test_getClassLoader() {
- // this fails if ClassTest.class was loaded by the regular classloader,
- // but passes if it was loaded by the boot class loader.
-
assertEquals(ExtendTestClass.class.getClassLoader(),
PublicTestClass.class.getClassLoader());
@@ -861,8 +858,8 @@ public class ClassTest extends junit.framework.TestCase {
System.setSecurityManager(sm);
try {
System.class.getClassLoader();
- } catch (SecurityException e) {
- fail("SecurityException should not be thrown.");
+ fail("SecurityException should be thrown.");
+ } catch (SecurityException expected) {
} finally {
System.setSecurityManager(oldSm);
}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManagerTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManagerTest.java
index be5aa41..0bd0c1f 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManagerTest.java
+++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManagerTest.java
@@ -16,14 +16,11 @@
package org.apache.harmony.luni.tests.java.lang;
-import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
-
+import dalvik.annotation.TestTargetNew;
import junit.framework.TestCase;
-import java.io.File;
import java.io.FileDescriptor;
import java.io.FilePermission;
import java.io.IOException;
@@ -41,8 +38,6 @@ import java.security.ProtectionDomain;
import java.security.Security;
import java.security.SecurityPermission;
-import tests.support.Support_Exec;
-
/**
* Test case for java.lang.SecurityManager
*/
@@ -230,14 +225,14 @@ public class SecurityManagerTest extends TestCase {
}
try {
- mutableSM.checkMemberAccess(Object.class, Member.DECLARED);
+ delegateCallToCheckMemberAccess2(Object.class, Member.DECLARED);
fail("SecurityException was not thrown.");
} catch(SecurityException se) {
//expected
}
try {
- mutableSM.checkMemberAccess(null, Member.PUBLIC);
+ delegateCallToCheckMemberAccess2(null, Member.PUBLIC);
fail("NullPointerException was not thrown.");
} catch(NullPointerException npe) {
//expected
@@ -248,6 +243,23 @@ public class SecurityManagerTest extends TestCase {
}
/**
+ * Don't call checkMemberAccess directly, since we're checking our caller
+ * (and not ourselves). This is necessary for unit tests, since JUnit's
+ * TestCase is usually in the boot classpath for dalvik. This delegating
+ * method corresponds to Class.getDeclared*();
+ */
+ private void delegateCallToCheckMemberAccess2(Class<Object> cls, int type) {
+ delegateCallToCheckMemberAccess1(cls, type);
+ }
+
+ /**
+ * This delegating method corresponds to Class.checkMemberAccess().
+ */
+ private void delegateCallToCheckMemberAccess1(Class<Object> cls, int type) {
+ mutableSM.checkMemberAccess(cls, type);
+ }
+
+ /**
* @tests java.lang.SecurityManager#checkPermission(java.security.Permission)
*/
@TestTargetNew(