summaryrefslogtreecommitdiff
path: root/startop/view_compiler/dex_builder_test
diff options
context:
space:
mode:
authorEric Holk <eholk@google.com>2019-07-26 20:13:32 -0700
committerandroid-build-merger <android-build-merger@google.com>2019-07-26 20:13:32 -0700
commit1c2e3a181d90e8336f6ca88bfbb20a6cf1f2ef36 (patch)
treede71babe39787787dfa46ee77f6793c4ea791a0a /startop/view_compiler/dex_builder_test
parenta4a7c1a0a5968a3dfa704d4a8277aa5d90f982af (diff)
parent8aa2b1dffd2eac9749116e92f5f9d6a7a62c5365 (diff)
Merge changes I12b38fa5,Ia11195b1
am: 8aa2b1dffd Change-Id: I2ac308ac94fd49298641c1230e731c1406913281
Diffstat (limited to 'startop/view_compiler/dex_builder_test')
-rw-r--r--startop/view_compiler/dex_builder_test/Android.bp1
-rw-r--r--startop/view_compiler/dex_builder_test/src/android/startop/test/DexBuilderTest.java23
-rw-r--r--startop/view_compiler/dex_builder_test/src/android/startop/test/TestClass.java23
3 files changed, 45 insertions, 2 deletions
diff --git a/startop/view_compiler/dex_builder_test/Android.bp b/startop/view_compiler/dex_builder_test/Android.bp
index 22a3cfafbc44..1214538e8f0d 100644
--- a/startop/view_compiler/dex_builder_test/Android.bp
+++ b/startop/view_compiler/dex_builder_test/Android.bp
@@ -39,6 +39,7 @@ android_test {
srcs: [
"src/android/startop/test/DexBuilderTest.java",
"src/android/startop/test/LayoutCompilerTest.java",
+ "src/android/startop/test/TestClass.java",
],
sdk_version: "current",
data: [":generate_dex_testcases", ":generate_compiled_layout1", ":generate_compiled_layout2"],
diff --git a/startop/view_compiler/dex_builder_test/src/android/startop/test/DexBuilderTest.java b/startop/view_compiler/dex_builder_test/src/android/startop/test/DexBuilderTest.java
index f7b1674894f5..6c0b8bbe8b83 100644
--- a/startop/view_compiler/dex_builder_test/src/android/startop/test/DexBuilderTest.java
+++ b/startop/view_compiler/dex_builder_test/src/android/startop/test/DexBuilderTest.java
@@ -24,10 +24,10 @@ import java.lang.reflect.Method;
// Adding tests here requires changes in several other places. See README.md in
// the view_compiler directory for more information.
-public class DexBuilderTest {
+public final class DexBuilderTest {
static ClassLoader loadDexFile(String filename) throws Exception {
return new PathClassLoader("/data/local/tmp/dex-builder-test/" + filename,
- ClassLoader.getSystemClassLoader());
+ DexBuilderTest.class.getClassLoader());
}
public void hello() {}
@@ -167,4 +167,23 @@ public class DexBuilderTest {
}
Assert.assertTrue(castFailed);
}
+
+ @Test
+ public void readStaticField() throws Exception {
+ ClassLoader loader = loadDexFile("simple.dex");
+ Class clazz = loader.loadClass("android.startop.test.testcases.SimpleTests");
+ Method method = clazz.getMethod("readStaticField");
+ TestClass.staticInteger = 5;
+ Assert.assertEquals(5, method.invoke(null));
+ }
+
+ @Test
+ public void setStaticField() throws Exception {
+ ClassLoader loader = loadDexFile("simple.dex");
+ Class clazz = loader.loadClass("android.startop.test.testcases.SimpleTests");
+ Method method = clazz.getMethod("setStaticField");
+ TestClass.staticInteger = 5;
+ method.invoke(null);
+ Assert.assertEquals(7, TestClass.staticInteger);
+ }
}
diff --git a/startop/view_compiler/dex_builder_test/src/android/startop/test/TestClass.java b/startop/view_compiler/dex_builder_test/src/android/startop/test/TestClass.java
new file mode 100644
index 000000000000..dd7792306030
--- /dev/null
+++ b/startop/view_compiler/dex_builder_test/src/android/startop/test/TestClass.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2018 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 android.startop.test;
+
+ /**
+ * A simple class to help test DexBuilder.
+ */
+public final class TestClass {
+ public static int staticInteger;
+
+ public int instanceField;
+}