1 /* 2 * Copyright (C) 2018 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.cts.releaseparser; 18 19 import com.android.cts.releaseparser.ReleaseProto.*; 20 import com.google.protobuf.TextFormat; 21 22 import org.junit.Test; 23 import org.junit.runner.RunWith; 24 import org.junit.runners.JUnit4; 25 26 import java.io.File; 27 28 import static org.junit.Assert.*; 29 30 /** Unit tests for {@link SoParser} */ 31 @RunWith(JUnit4.class) 32 public class SoParserTest { 33 // ref: android/frameworks/native/opengl/libs/libEGL.map.txt 34 private static final String TEST_NDK_SO = "libEGL.so"; 35 private static final String TEST_NDK_SO_TXT = "libEGL.so.pb.txt"; 36 37 // ref: android/cts/tests/aslr/AndroidTest.xml 38 private static final String TEST_CTS_GTEST_EXE = "CtsAslrMallocTestCases32"; 39 private static final String TEST_CTS_GTEST_EXE_PB_TXT = "CtsAslrMallocTestCases32.pb.txt"; 40 41 /** 42 * Test {@link SoParser} with an NDK SO file 43 * 44 * @throws Exception 45 */ 46 @Test testNdkSo()47 public void testNdkSo() throws Exception { 48 testSoParser(TEST_NDK_SO, TEST_NDK_SO_TXT, true); 49 } 50 51 /** 52 * Test {@link SoParser} with an CTS GTEST EXE file 53 * 54 * @throws Exception 55 */ 56 @Test testCtsGtestExe()57 public void testCtsGtestExe() throws Exception { 58 testSoParser(TEST_CTS_GTEST_EXE, TEST_CTS_GTEST_EXE_PB_TXT, false); 59 } 60 testSoParser(String fileName, String txtProtobufFileName, boolean parseInternalApi)61 private void testSoParser(String fileName, String txtProtobufFileName, boolean parseInternalApi) 62 throws Exception { 63 File aFile = ClassUtils.getResrouceFile(getClass(), fileName); 64 SoParser aParser = new SoParser(aFile); 65 aParser.setPackageName(fileName); 66 aParser.setParseInternalApi(parseInternalApi); 67 AppInfo appInfo = aParser.getAppInfo(); 68 69 AppInfo.Builder expectedAppInfoBuilder = AppInfo.newBuilder(); 70 TextFormat.getParser() 71 .merge( 72 ClassUtils.getResrouceContentString(getClass(), txtProtobufFileName), 73 expectedAppInfoBuilder); 74 assertTrue( 75 String.format( 76 "SoParser does not return the same AppInfo of %s as %s.\n%s", 77 fileName, txtProtobufFileName, TextFormat.printToString(appInfo)), 78 appInfo.equals(expectedAppInfoBuilder.build())); 79 } 80 } 81