Jamie Garside | 56f2b70 | 2024-07-09 12:00:12 +0100 | [diff] [blame] | 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 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
| 18 | "runtime" |
| 19 | "testing" |
| 20 | |
| 21 | "android/soong/android" |
| 22 | ) |
| 23 | |
| 24 | var 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 Hoffman | 39e3e08 | 2024-12-29 07:29:56 +0000 | [diff] [blame] | 35 | name: "Robolectric_all-target", |
| 36 | srcs: ["Robo.java"] |
| 37 | } |
| 38 | |
| 39 | java_library { |
Jamie Garside | 56f2b70 | 2024-07-09 12:00:12 +0100 | [diff] [blame] | 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"] |
Rex Hoffman | eef7fca | 2024-12-26 13:38:30 -0800 | [diff] [blame] | 52 | |
| 53 | } |
| 54 | |
| 55 | java_library { |
| 56 | name: "ClearcutJunitListenerAar", |
| 57 | srcs: ["Runtime.java"] |
Jamie Garside | 56f2b70 | 2024-07-09 12:00:12 +0100 | [diff] [blame] | 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 | |
| 73 | func TestRobolectricJniTest(t *testing.T) { |
Colin Cross | 844cb6a | 2025-01-29 15:53:21 -0800 | [diff] [blame] | 74 | t.Parallel() |
Jamie Garside | 56f2b70 | 2024-07-09 12:00:12 +0100 | [diff] [blame] | 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. |
Colin Cross | 90607e9 | 2025-02-11 14:58:07 -0800 | [diff] [blame] | 108 | module := ctx.ModuleForTests(t, "robo-test", "android_common") |
Jamie Garside | 56f2b70 | 2024-07-09 12:00:12 +0100 | [diff] [blame] | 109 | module.Output(installPathPrefix + "/robo-test/lib64/jni-lib1.so") |
| 110 | } |