diff options
author | Richard Uhler <ruhler@google.com> | 2015-05-28 16:43:34 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-05-28 16:43:34 +0000 |
commit | fc3995ca1d76db921af840108db1a52fb426411b (patch) | |
tree | fa88013e6cb64a2c4cab75b757a626be8f0733aa /luni | |
parent | 874742e871e805ccfb1c2d1bf0d0af92b4c47aff (diff) | |
parent | 7da5bba6f670090bdd258c700d0db58b28ba551d (diff) | |
download | libcore-fc3995ca1d76db921af840108db1a52fb426411b.zip libcore-fc3995ca1d76db921af840108db1a52fb426411b.tar.gz libcore-fc3995ca1d76db921af840108db1a52fb426411b.tar.bz2 |
Merge "Add test for application use of PathClassLoader." into mnc-dev
Diffstat (limited to 'luni')
-rw-r--r-- | luni/src/test/java/libcore/dalvik/system/PathClassLoaderTest.java | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/luni/src/test/java/libcore/dalvik/system/PathClassLoaderTest.java b/luni/src/test/java/libcore/dalvik/system/PathClassLoaderTest.java index 9e6d8d7..31e8fc7 100644 --- a/luni/src/test/java/libcore/dalvik/system/PathClassLoaderTest.java +++ b/luni/src/test/java/libcore/dalvik/system/PathClassLoaderTest.java @@ -17,9 +17,12 @@ package libcore.dalvik.system; import dalvik.system.PathClassLoader; +import java.lang.reflect.Method; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; +import libcore.io.Streams; import junit.framework.TestCase; public final class PathClassLoaderTest extends TestCase { @@ -52,6 +55,26 @@ public final class PathClassLoaderTest extends TestCase { return result; } + public void testAppUseOfPathClassLoader() throws Exception { + // Extract loading-test.jar from the resource. + ClassLoader pcl = PathClassLoaderTest.class.getClassLoader(); + File jar = File.createTempFile("loading-test", ".jar"); + try (InputStream in = pcl.getResourceAsStream("dalvik/system/loading-test.jar"); + FileOutputStream out = new FileOutputStream(jar)) { + Streams.copy(in, out); + } + + // Execute code from the jar file using a PathClassLoader. + PathClassLoader cl = new PathClassLoader(jar.getPath(), pcl); + Class c = cl.loadClass("test.Test1"); + Method m = c.getMethod("test", (Class[]) null); + String result = (String) m.invoke(null, (Object[]) null); + assertSame("blort", result); + + // Clean up the extracted jar file. + assertTrue(jar.delete()); + } + @Override protected void setUp() throws Exception { super.setUp(); } |