1// Copyright 2022 Google Inc. All rights reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// 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 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package java 16 17import ( 18 "android/soong/android" 19 "testing" 20) 21 22func TestAarImportProducesJniPackages(t *testing.T) { 23 ctx := android.GroupFixturePreparers( 24 PrepareForTestWithJavaDefaultModules, 25 ).RunTestWithBp(t, ` 26 android_library_import { 27 name: "aar-no-jni", 28 aars: ["aary.aar"], 29 } 30 android_library_import { 31 name: "aar-jni", 32 aars: ["aary.aar"], 33 extract_jni: true, 34 }`) 35 36 testCases := []struct { 37 name string 38 hasPackage bool 39 }{ 40 { 41 name: "aar-no-jni", 42 hasPackage: false, 43 }, 44 { 45 name: "aar-jni", 46 hasPackage: true, 47 }, 48 } 49 50 for _, tc := range testCases { 51 t.Run(tc.name, func(t *testing.T) { 52 appMod := ctx.Module(tc.name, "android_common") 53 appTestMod := ctx.ModuleForTests(tc.name, "android_common") 54 55 info, ok := ctx.ModuleProvider(appMod, JniPackageProvider).(JniPackageInfo) 56 if !ok { 57 t.Errorf("expected android_library_import to have JniPackageProvider") 58 } 59 60 if !tc.hasPackage { 61 if len(info.JniPackages) != 0 { 62 t.Errorf("expected JniPackages to be empty, but got %v", info.JniPackages) 63 } 64 outputFile := "arm64-v8a_jni.zip" 65 jniOutputLibZip := appTestMod.MaybeOutput(outputFile) 66 if jniOutputLibZip.Rule != nil { 67 t.Errorf("did not expect an output file, but found %v", outputFile) 68 } 69 return 70 } 71 72 if len(info.JniPackages) != 1 { 73 t.Errorf("expected a single JniPackage, but got %v", info.JniPackages) 74 } 75 76 outputFile := info.JniPackages[0].String() 77 jniOutputLibZip := appTestMod.Output(outputFile) 78 if jniOutputLibZip.Rule == nil { 79 t.Errorf("did not find output file %v", outputFile) 80 } 81 }) 82 } 83} 84