summaryrefslogtreecommitdiffstats
path: root/luni/src/test/etc/loading-test-jar
diff options
context:
space:
mode:
authorDan Bornstein <danfuzz@android.com>2011-01-14 15:05:54 -0800
committerDan Bornstein <danfuzz@android.com>2011-01-14 15:14:09 -0800
commit8c47f104820836f6bdacce83e1be6cc71c1cace0 (patch)
tree328e5cce9f08e4788efbfd7e7921b317a65b8114 /luni/src/test/etc/loading-test-jar
parent141795a53115b9a6e34cc2e2e7348b203d5df3c8 (diff)
downloadlibcore-8c47f104820836f6bdacce83e1be6cc71c1cace0.zip
libcore-8c47f104820836f6bdacce83e1be6cc71c1cace0.tar.gz
libcore-8c47f104820836f6bdacce83e1be6cc71c1cace0.tar.bz2
This test is now bona fide nontrivial.
It also demonstrates that loading from a raw dex file doesn't yet work! Change-Id: I2b0ccd517edd052d374af8d0762c8f1f8734720f
Diffstat (limited to 'luni/src/test/etc/loading-test-jar')
-rw-r--r--luni/src/test/etc/loading-test-jar/Target.java45
-rw-r--r--luni/src/test/etc/loading-test-jar/Test1.java2
-rw-r--r--luni/src/test/etc/loading-test-jar/Test2.java72
-rwxr-xr-xluni/src/test/etc/loading-test-jar/build.sh2
4 files changed, 119 insertions, 2 deletions
diff --git a/luni/src/test/etc/loading-test-jar/Target.java b/luni/src/test/etc/loading-test-jar/Target.java
new file mode 100644
index 0000000..f87144d
--- /dev/null
+++ b/luni/src/test/etc/loading-test-jar/Target.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * 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 test;
+
+/**
+ * Class which is probed at by the class loading tests.
+ */
+public class Target {
+ public static int staticVariable = 0;
+ public int instanceVariable = 0;
+
+ public Target() {
+ // This space intentionally left blank.
+ }
+
+ public static String blort() {
+ return "blort";
+ }
+
+ public static void setStaticVariable(int n) {
+ staticVariable = n;
+ }
+
+ public String zorch() {
+ return "zorch";
+ }
+
+ public void setInstanceVariable(int n) {
+ instanceVariable = n;
+ }
+}
diff --git a/luni/src/test/etc/loading-test-jar/Test1.java b/luni/src/test/etc/loading-test-jar/Test1.java
index f91aa6c..8296145 100644
--- a/luni/src/test/etc/loading-test-jar/Test1.java
+++ b/luni/src/test/etc/loading-test-jar/Test1.java
@@ -20,7 +20,7 @@ package test;
* Class used as part of the class loading tests.
*/
public class Test1 {
- static public String test() {
+ public static String test() {
return "blort";
}
}
diff --git a/luni/src/test/etc/loading-test-jar/Test2.java b/luni/src/test/etc/loading-test-jar/Test2.java
new file mode 100644
index 0000000..7d26918
--- /dev/null
+++ b/luni/src/test/etc/loading-test-jar/Test2.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * 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 test;
+
+/**
+ * Class used as part of the class loading tests. This class uses other
+ * classes that should have come from the same jar/dex file. Each test
+ * method in this class is called from the same-named method in
+ * {@code DexClassLoaderTest}.
+ */
+public class Test2 {
+ /**
+ * Simple sameness checker, to avoid pulling in JUnit as a dependency.
+ */
+ public static void assertSame(Object expected, Object actual) {
+ if (expected != actual) {
+ throw new RuntimeException(
+ "EXPECTED: " + expected + "; ACTUAL: " + actual);
+ }
+ }
+
+ /**
+ * Simple sameness checker, to avoid pulling in JUnit as a dependency.
+ */
+ public static void assertSame(int expected, int actual) {
+ if (expected != actual) {
+ throw new RuntimeException(
+ "EXPECTED: " + expected + "; ACTUAL: " + actual);
+ }
+ }
+
+ /**
+ * Test that an instance of a sibling class can be constructed.
+ */
+ public static void test_constructor() {
+ new Target();
+ }
+
+ public static void test_callStaticMethod() {
+ assertSame("blort", Target.blort());
+ }
+
+ public static void test_getStaticVariable() {
+ Target.setStaticVariable(22);
+ assertSame(22, Target.staticVariable);
+ }
+
+ public static void test_callInstanceMethod() {
+ Target target = new Target();
+ assertSame("zorch", target.zorch());
+ }
+
+ public static void test_getInstanceVariable() {
+ Target target = new Target();
+ target.setInstanceVariable(10098);
+ assertSame(10098, target.instanceVariable);
+ }
+}
diff --git a/luni/src/test/etc/loading-test-jar/build.sh b/luni/src/test/etc/loading-test-jar/build.sh
index 0fa9639..839ab8d 100755
--- a/luni/src/test/etc/loading-test-jar/build.sh
+++ b/luni/src/test/etc/loading-test-jar/build.sh
@@ -43,5 +43,5 @@ dx --dex --output=classes.dex classes
jar cf loading-test.jar classes.dex -C resources .
rm -rf classes
-rm -rf classes.dex
+mv classes.dex ../../resources/dalvik/system/loading-test.dex
mv loading-test.jar ../../resources/dalvik/system/