blob: 78326abee965f6e08ef3bc3a478e6c03bf5c0f63 [file] [log] [blame]
Jamie Garside56f2b702024-07-09 12:00:12 +01001// 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 {
Rex Hoffman39e3e082024-12-29 07:29:56 +000035 name: "Robolectric_all-target",
36 srcs: ["Robo.java"]
37 }
38
39 java_library {
Jamie Garside56f2b702024-07-09 12:00:12 +010040 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"]
Rex Hoffmaneef7fca2024-12-26 13:38:30 -080052
53 }
54
55 java_library {
56 name: "ClearcutJunitListenerAar",
57 srcs: ["Runtime.java"]
Jamie Garside56f2b702024-07-09 12:00:12 +010058 }
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 if runtime.GOOS != "linux" {
75 t.Skip("requires linux")
76 }
77
78 ctx := android.GroupFixturePreparers(
79 PrepareForIntegrationTestWithJava,
80 prepareRobolectricRuntime,
81 ).RunTestWithBp(t, `
82 android_app {
83 name: "inst-target",
84 srcs: ["App.java"],
85 platform_apis: true,
86 }
87
88 cc_library_shared {
89 name: "jni-lib1",
90 host_supported: true,
91 srcs: ["jni.cpp"],
92 }
93
94 android_robolectric_test {
95 name: "robo-test",
96 instrumentation_for: "inst-target",
97 srcs: ["FooTest.java"],
98 jni_libs: [
99 "jni-lib1"
100 ],
101 }
102 `)
103
104 CheckModuleHasDependency(t, ctx.TestContext, "robo-test", "android_common", "jni-lib1")
105
106 // Check that the .so files make it into the output.
107 module := ctx.ModuleForTests("robo-test", "android_common")
108 module.Output(installPathPrefix + "/robo-test/lib64/jni-lib1.so")
109}