• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 
15 package android.startop.test;
16 
17 import android.content.Context;
18 
19 import androidx.test.InstrumentationRegistry;
20 
21 import dalvik.system.PathClassLoader;
22 
23 import org.junit.Test;
24 
25 import java.lang.reflect.Method;
26 
27 // Adding tests here requires changes in several other places. See README.md in
28 // the view_compiler directory for more information.
29 public class LayoutCompilerTest {
loadDexFile(String filename)30     static ClassLoader loadDexFile(String filename) throws Exception {
31         return new PathClassLoader("/data/local/tmp/dex-builder-test/" + filename,
32                 ClassLoader.getSystemClassLoader());
33     }
34 
35     @Test
loadAndInflateLayout1()36     public void loadAndInflateLayout1() throws Exception {
37         ClassLoader dex_file = loadDexFile("layout1.dex");
38         Class compiled_view = dex_file.loadClass("android.startop.test.CompiledView");
39         Method layout1 = compiled_view.getMethod("layout1", Context.class, int.class);
40         Context context = InstrumentationRegistry.getTargetContext();
41         layout1.invoke(null, context, R.layout.layout1);
42     }
43 
44     @Test
loadAndInflateLayout2()45     public void loadAndInflateLayout2() throws Exception {
46         ClassLoader dex_file = loadDexFile("layout2.dex");
47         Class compiled_view = dex_file.loadClass("android.startop.test.CompiledView");
48         Method layout1 = compiled_view.getMethod("layout2", Context.class, int.class);
49         Context context = InstrumentationRegistry.getTargetContext();
50         layout1.invoke(null, context, R.layout.layout1);
51     }
52 }
53