blob: 4bf224b4fd543f3a731588093209c8d5026d066f [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) {
Colin Cross844cb6a2025-01-29 15:53:21 -080074 t.Parallel()
Jamie Garside56f2b702024-07-09 12:00:12 +010075 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.
Colin Cross90607e92025-02-11 14:58:07 -0800108 module := ctx.ModuleForTests(t, "robo-test", "android_common")
Jamie Garside56f2b702024-07-09 12:00:12 +0100109 module.Output(installPathPrefix + "/robo-test/lib64/jni-lib1.so")
110}