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: "Robolectric_all-target", 36 srcs: ["Robo.java"] 37 } 38 39 java_library { 40 name: "mockito-robolectric-prebuilt", 41 srcs: ["Mockito.java"] 42 } 43 44 java_library { 45 name: "truth", 46 srcs: ["Truth.java"] 47 } 48 49 java_library { 50 name: "junitxml", 51 srcs: ["JUnitXml.java"] 52 53 } 54 55 java_library { 56 name: "ClearcutJunitListenerAar", 57 srcs: ["Runtime.java"] 58 } 59 60 java_library_host { 61 name: "robolectric-host-android_all", 62 srcs: ["Runtime.java"] 63 } 64 65 android_robolectric_runtimes { 66 name: "robolectric-android-all-prebuilts", 67 jars: ["android-all/Runtime.jar"], 68 lib: "robolectric-host-android_all", 69 } 70 `), 71) 72 73func TestRobolectricJniTest(t *testing.T) { 74 t.Parallel() 75 if runtime.GOOS != "linux" { 76 t.Skip("requires linux") 77 } 78 79 ctx := android.GroupFixturePreparers( 80 PrepareForIntegrationTestWithJava, 81 prepareRobolectricRuntime, 82 ).RunTestWithBp(t, ` 83 android_app { 84 name: "inst-target", 85 srcs: ["App.java"], 86 platform_apis: true, 87 } 88 89 cc_library_shared { 90 name: "jni-lib1", 91 host_supported: true, 92 srcs: ["jni.cpp"], 93 } 94 95 android_robolectric_test { 96 name: "robo-test", 97 instrumentation_for: "inst-target", 98 srcs: ["FooTest.java"], 99 jni_libs: [ 100 "jni-lib1" 101 ], 102 } 103 `) 104 105 CheckModuleHasDependency(t, ctx.TestContext, "robo-test", "android_common", "jni-lib1") 106 107 // Check that the .so files make it into the output. 108 module := ctx.ModuleForTests(t, "robo-test", "android_common") 109 module.Output(installPathPrefix + "/robo-test/lib64/jni-lib1.so") 110 111 // Ensure they are listed as "test" modules for code coverage 112 expectedTestOnlyModules := []string{ 113 "robo-test", 114 } 115 116 expectedTopLevelTests := []string{ 117 "robo-test", 118 } 119 assertTestOnlyAndTopLevel(t, ctx, expectedTestOnlyModules, expectedTopLevelTests) 120 121} 122