1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.dynamiclinker; 18 19 import junit.framework.TestCase; 20 import android.support.test.InstrumentationRegistry; 21 22 public class DynamicLinkerTest extends TestCase { 23 24 private native int functionA(); 25 private native int functionB(); 26 27 public void testLoadLibInApkByLibName() { 28 System.loadLibrary("dynamiclinker_native_lib_a"); 29 assertEquals(1, functionA()); 30 } 31 32 public void testLoadLibInApkByFileName() { 33 String arch = System.getProperty("os.arch"); 34 String apkPath = InstrumentationRegistry.getContext().getPackageResourcePath(); 35 if (arch.equals("aarch64")) { 36 System.load(apkPath + "!/lib/arm64-v8a/libdynamiclinker_native_lib_b.so"); 37 } else if (arch.startsWith("arm")) { 38 System.load(apkPath + "!/lib/armeabi-v7a/libdynamiclinker_native_lib_b.so"); 39 } else if (arch.equals("x86_64")) { 40 System.load(apkPath + "!/lib/x86_64/libdynamiclinker_native_lib_b.so"); 41 } else if (arch.endsWith("86")) { 42 System.load(apkPath + "!/lib/x86/libdynamiclinker_native_lib_b.so"); 43 } else { 44 // Don't know which lib to load on this arch. 45 return; 46 } 47 assertEquals(1, functionB()); 48 } 49 50 } 51