summaryrefslogtreecommitdiff
path: root/java/ravenwood_test.go
blob: 2443ea8e7d1b67775c6a4399b1e1689ac7f7a8de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright 2022 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package java

import (
	"runtime"
	"testing"

	"android/soong/android"
)

var prepareRavenwoodRuntime = android.GroupFixturePreparers(
	android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
		RegisterRavenwoodBuildComponents(ctx)
	}),
	android.FixtureAddTextFile("ravenwood/Android.bp", `
		java_library_static {
			name: "framework-minus-apex.ravenwood",
			srcs: ["Framework.java"],
		}
		java_library_static {
			name: "framework-services.ravenwood",
			srcs: ["Services.java"],
		}
		java_library_static {
			name: "framework-rules.ravenwood",
			srcs: ["Rules.java"],
		}
		android_ravenwood_libgroup {
			name: "ravenwood-runtime",
			libs: [
				"framework-minus-apex.ravenwood",
				"framework-services.ravenwood",
			],
		}
		android_ravenwood_libgroup {
			name: "ravenwood-utils",
			libs: [
				"framework-rules.ravenwood",
			],
		}
	`),
)

var installPathPrefix = "out/soong/host/linux-x86/testcases"

func TestRavenwoodRuntime(t *testing.T) {
	if runtime.GOOS != "linux" {
		t.Skip("requires linux")
	}

	ctx := android.GroupFixturePreparers(
		PrepareForIntegrationTestWithJava,
		prepareRavenwoodRuntime,
	).RunTest(t)

	// Verify that our runtime depends on underlying libs
	CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-runtime", "android_common", "framework-minus-apex.ravenwood")
	CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-runtime", "android_common", "framework-services.ravenwood")
	CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-utils", "android_common", "framework-rules.ravenwood")

	// Verify that we've emitted artifacts in expected location
	runtime := ctx.ModuleForTests("ravenwood-runtime", "android_common")
	runtime.Output(installPathPrefix + "/ravenwood-runtime/framework-minus-apex.ravenwood.jar")
	runtime.Output(installPathPrefix + "/ravenwood-runtime/framework-services.ravenwood.jar")
	utils := ctx.ModuleForTests("ravenwood-utils", "android_common")
	utils.Output(installPathPrefix + "/ravenwood-utils/framework-rules.ravenwood.jar")
}

func TestRavenwoodTest(t *testing.T) {
	if runtime.GOOS != "linux" {
		t.Skip("requires linux")
	}

	ctx := android.GroupFixturePreparers(
		PrepareForIntegrationTestWithJava,
		prepareRavenwoodRuntime,
	).RunTestWithBp(t, `
		android_ravenwood_test {
			name: "ravenwood-test",
			srcs: ["Test.java"],
			sdk_version: "test_current",
		}
	`)

	// Verify that our test depends on underlying libs
	CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-test", "android_common", "ravenwood-buildtime")
	CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-test", "android_common", "ravenwood-utils")

	module := ctx.ModuleForTests("ravenwood-test", "android_common")
	classpath := module.Rule("javac").Args["classpath"]

	// Verify that we're linking against test_current
	android.AssertStringDoesContain(t, "classpath", classpath, "android_test_stubs_current.jar")
	// Verify that we're linking against utils
	android.AssertStringDoesContain(t, "classpath", classpath, "framework-rules.ravenwood.jar")
	// Verify that we're *NOT* linking against runtime
	android.AssertStringDoesNotContain(t, "classpath", classpath, "framework-minus-apex.ravenwood.jar")
	android.AssertStringDoesNotContain(t, "classpath", classpath, "framework-services.ravenwood.jar")

	// Verify that we've emitted test artifacts in expected location
	outputJar := module.Output(installPathPrefix + "/ravenwood-test/ravenwood-test.jar")
	module.Output(installPathPrefix + "/ravenwood-test/ravenwood-test.config")

	// Verify that we're going to install underlying libs
	orderOnly := outputJar.OrderOnly.Strings()
	android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/framework-minus-apex.ravenwood.jar")
	android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/framework-services.ravenwood.jar")
	android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-utils/framework-rules.ravenwood.jar")
}