1// Copyright 2024 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 "runtime" 19 "testing" 20 21 "android/soong/android" 22) 23 24var prepareRobolectricRuntime = android.GroupFixturePreparers( 25 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { 26 RegisterRobolectricBuildComponents(ctx) 27 }), 28 android.FixtureAddTextFile("robolectric/Android.bp", ` 29 java_library { 30 name: "Robolectric_all-target_upstream", 31 srcs: ["Robo.java"] 32 } 33 34 java_library { 35 name: "mockito-robolectric-prebuilt", 36 srcs: ["Mockito.java"] 37 } 38 39 java_library { 40 name: "truth", 41 srcs: ["Truth.java"] 42 } 43 44 java_library { 45 name: "junitxml", 46 srcs: ["JUnitXml.java"] 47 } 48 49 java_library_host { 50 name: "robolectric-host-android_all", 51 srcs: ["Runtime.java"] 52 } 53 54 android_robolectric_runtimes { 55 name: "robolectric-android-all-prebuilts", 56 jars: ["android-all/Runtime.jar"], 57 lib: "robolectric-host-android_all", 58 } 59 `), 60) 61 62func TestRobolectricJniTest(t *testing.T) { 63 if runtime.GOOS != "linux" { 64 t.Skip("requires linux") 65 } 66 67 ctx := android.GroupFixturePreparers( 68 PrepareForIntegrationTestWithJava, 69 prepareRobolectricRuntime, 70 ).RunTestWithBp(t, ` 71 android_app { 72 name: "inst-target", 73 srcs: ["App.java"], 74 platform_apis: true, 75 } 76 77 cc_library_shared { 78 name: "jni-lib1", 79 host_supported: true, 80 srcs: ["jni.cpp"], 81 } 82 83 android_robolectric_test { 84 name: "robo-test", 85 instrumentation_for: "inst-target", 86 srcs: ["FooTest.java"], 87 jni_libs: [ 88 "jni-lib1" 89 ], 90 } 91 `) 92 93 CheckModuleHasDependency(t, ctx.TestContext, "robo-test", "android_common", "jni-lib1") 94 95 // Check that the .so files make it into the output. 96 module := ctx.ModuleForTests("robo-test", "android_common") 97 module.Output(installPathPrefix + "/robo-test/lib64/jni-lib1.so") 98} 99