diff options
author | Dan Bornstein <danfuzz@android.com> | 2011-01-17 12:23:50 -0800 |
---|---|---|
committer | Dan Bornstein <danfuzz@android.com> | 2011-01-17 12:23:50 -0800 |
commit | 30daad6ce1e6f4a94d1c01672df26d2d35eafaca (patch) | |
tree | 0d805aa16fbdfd5693fd54ccbb550d1a044755c8 /luni/src/test/etc/loading-test-jar | |
parent | be4921ea9ecbb378c80f0d318c46fd5a7d1f05e7 (diff) | |
download | libcore-30daad6ce1e6f4a94d1c01672df26d2d35eafaca.zip libcore-30daad6ce1e6f4a94d1c01672df26d2d35eafaca.tar.gz libcore-30daad6ce1e6f4a94d1c01672df26d2d35eafaca.tar.bz2 |
Start to use the second jar/dex file in DexClassLoaderTest.
This demonstrates that there is an issue with resource handling.
Change-Id: I2a33b6fd6f2be2e1d1879d539c86ecbb8e5b198c
Diffstat (limited to 'luni/src/test/etc/loading-test-jar')
-rw-r--r-- | luni/src/test/etc/loading-test-jar/Test2.java | 59 | ||||
-rwxr-xr-x | luni/src/test/etc/loading-test-jar/build.sh | 15 |
2 files changed, 70 insertions, 4 deletions
diff --git a/luni/src/test/etc/loading-test-jar/Test2.java b/luni/src/test/etc/loading-test-jar/Test2.java index cfeaefc..9accb2d 100644 --- a/luni/src/test/etc/loading-test-jar/Test2.java +++ b/luni/src/test/etc/loading-test-jar/Test2.java @@ -16,6 +16,7 @@ package test; +import test2.Target2; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -75,7 +76,7 @@ public class Test2 { } /* - * Test methods, per se + * Test methods that use another class from the same dex/jar file */ /** @@ -129,4 +130,60 @@ public class Test2 { assertSame("Muffins are tasty!\n", s.intern()); } + + /* + * Test methods that use a class from a different dex/jar file + */ + + /** + * Test that an instance of a cousin class can be constructed. + */ + public static void test_diff_constructor() { + new Target2(); + } + + /** + * Test calling a static method on a cousin class. + */ + public static void test_diff_callStaticMethod() { + assertSame("frotz", Target2.frotz()); + } + + /** + * Test getting a static variable of a cousin class. + */ + public static void test_diff_getStaticVariable() { + Target2.setStaticIgram(220); + assertSame(220, Target2.staticIgram); + } + + /** + * Test calling an instance method on a cousin class. + */ + public static void test_diff_callInstanceMethod() { + Target2 target = new Target2(); + assertSame("fizmo", target.fizmo()); + } + + /** + * Test getting an instance variable of a cousin class. + */ + public static void test_diff_getInstanceVariable() { + Target2 target = new Target2(); + target.setInstanceMagri(10098); + assertSame(10098, target.instanceMagri); + } + + /** + * Test getting a resource which should be in a different jar + * file as this class. + */ + public static void test_diff_getResourceAsStream() throws IOException { + ClassLoader cl = Test2.class.getClassLoader(); + InputStream in = cl.getResourceAsStream("test2/Resource2.txt"); + byte[] contents = readFully(in); + String s = new String(contents, "UTF-8"); + + assertSame("Who doesn't like a good biscuit?\n", s.intern()); + } } diff --git a/luni/src/test/etc/loading-test-jar/build.sh b/luni/src/test/etc/loading-test-jar/build.sh index 839ab8d..4737f14 100755 --- a/luni/src/test/etc/loading-test-jar/build.sh +++ b/luni/src/test/etc/loading-test-jar/build.sh @@ -33,15 +33,24 @@ oldwd=`pwd` progdir=`dirname "${prog}"` cd "${progdir}" +resourceDir=../../resources/dalvik/system + rm -rf classes +rm -rf classes2 rm -rf classes.dex rm -rf loading-test.jar +# This library depends on loading-test2, so compile those classes first, +# but keep them separate. +mkdir classes2 +javac -d classes2 ../loading-test2-jar/*.java + mkdir classes -javac -d classes *.java +javac -classpath classes2 -d classes *.java dx --dex --output=classes.dex classes jar cf loading-test.jar classes.dex -C resources . rm -rf classes -mv classes.dex ../../resources/dalvik/system/loading-test.dex -mv loading-test.jar ../../resources/dalvik/system/ +rm -rf classes2 +mv classes.dex ${resourceDir}/loading-test.dex +mv loading-test.jar ${resourceDir} |