blob: 4ae1d7cf56ed365d1ac5b4052c17d83d6d1b7f2e [file] [log] [blame]
Makoto Onuki4a9869d2023-10-20 10:42:47 -07001// Copyright 2022 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 "testing"
19
20 "android/soong/android"
21)
22
23var prepareRavenwoodRuntime = android.GroupFixturePreparers(
24 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
25 RegisterRavenwoodBuildComponents(ctx)
26 }),
27 android.FixtureAddTextFile("ravenwood/Android.bp", `
28 java_library_static {
29 name: "framework-minus-apex.ravenwood",
30 srcs: ["Framework.java"],
31 }
32 java_library_static {
33 name: "framework-services.ravenwood",
34 srcs: ["Services.java"],
35 }
36 java_library_static {
37 name: "framework-rules.ravenwood",
38 srcs: ["Rules.java"],
39 }
40 android_ravenwood_libgroup {
41 name: "ravenwood-runtime",
42 libs: [
43 "framework-minus-apex.ravenwood",
44 "framework-services.ravenwood",
45 ],
46 }
47 android_ravenwood_libgroup {
48 name: "ravenwood-utils",
49 libs: [
50 "framework-rules.ravenwood",
51 ],
52 }
53 `),
54)
55
56var installPathPrefix = "out/soong/host/linux-x86/testcases"
57
58func TestRavenwoodRuntime(t *testing.T) {
59 ctx := android.GroupFixturePreparers(
60 PrepareForIntegrationTestWithJava,
61 prepareRavenwoodRuntime,
62 ).RunTest(t)
63
64 // Verify that our runtime depends on underlying libs
65 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-runtime", "android_common", "framework-minus-apex.ravenwood")
66 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-runtime", "android_common", "framework-services.ravenwood")
67 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-utils", "android_common", "framework-rules.ravenwood")
68
69 // Verify that we've emitted artifacts in expected location
70 runtime := ctx.ModuleForTests("ravenwood-runtime", "android_common")
71 runtime.Output(installPathPrefix + "/ravenwood-runtime/framework-minus-apex.ravenwood.jar")
72 runtime.Output(installPathPrefix + "/ravenwood-runtime/framework-services.ravenwood.jar")
73 utils := ctx.ModuleForTests("ravenwood-utils", "android_common")
74 utils.Output(installPathPrefix + "/ravenwood-utils/framework-rules.ravenwood.jar")
75}
76
77func TestRavenwoodTest(t *testing.T) {
78 ctx := android.GroupFixturePreparers(
79 PrepareForIntegrationTestWithJava,
80 prepareRavenwoodRuntime,
81 ).RunTestWithBp(t, `
82 android_ravenwood_test {
83 name: "ravenwood-test",
84 srcs: ["Test.java"],
85 sdk_version: "test_current",
86 }
87 `)
88
89 // Verify that our test depends on underlying libs
90 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-test", "android_common", "ravenwood-buildtime")
91 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-test", "android_common", "ravenwood-utils")
92
93 module := ctx.ModuleForTests("ravenwood-test", "android_common")
94 classpath := module.Rule("javac").Args["classpath"]
95
96 // Verify that we're linking against test_current
97 android.AssertStringDoesContain(t, "classpath", classpath, "android_test_stubs_current.jar")
98 // Verify that we're linking against utils
99 android.AssertStringDoesContain(t, "classpath", classpath, "framework-rules.ravenwood.jar")
100 // Verify that we're *NOT* linking against runtime
101 android.AssertStringDoesNotContain(t, "classpath", classpath, "framework-minus-apex.ravenwood.jar")
102 android.AssertStringDoesNotContain(t, "classpath", classpath, "framework-services.ravenwood.jar")
103
104 // Verify that we've emitted test artifacts in expected location
105 outputJar := module.Output(installPathPrefix + "/ravenwood-test/ravenwood-test.jar")
106 module.Output(installPathPrefix + "/ravenwood-test/ravenwood-test.config")
107
108 // Verify that we're going to install underlying libs
109 orderOnly := outputJar.OrderOnly.Strings()
110 android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/framework-minus-apex.ravenwood.jar")
111 android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/framework-services.ravenwood.jar")
112 android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-utils/framework-rules.ravenwood.jar")
113}