• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2021 The Android Open Source Project
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	"android/soong/android"
19	"path/filepath"
20	"testing"
21)
22
23var prepForJavaFuzzTest = android.GroupFixturePreparers(
24	PrepareForTestWithJavaDefaultModules,
25	android.FixtureRegisterWithContext(RegisterJavaFuzzBuildComponents),
26)
27
28func TestJavaFuzz(t *testing.T) {
29	result := prepForJavaFuzzTest.RunTestWithBp(t, `
30		java_fuzz_host {
31			name: "foo",
32			srcs: ["a.java"],
33			libs: ["bar"],
34			static_libs: ["baz"],
35		}
36
37		java_library_host {
38			name: "bar",
39			srcs: ["b.java"],
40		}
41
42		java_library_host {
43			name: "baz",
44			srcs: ["c.java"],
45		}`)
46
47	osCommonTarget := result.Config.BuildOSCommonTarget.String()
48	javac := result.ModuleForTests("foo", osCommonTarget).Rule("javac")
49	combineJar := result.ModuleForTests("foo", osCommonTarget).Description("for javac")
50
51	if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" {
52		t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs)
53	}
54
55	baz := result.ModuleForTests("baz", osCommonTarget).Rule("javac").Output.String()
56	barOut := filepath.Join("out", "soong", ".intermediates", "bar", osCommonTarget, "javac", "bar.jar")
57	bazOut := filepath.Join("out", "soong", ".intermediates", "baz", osCommonTarget, "javac", "baz.jar")
58
59	android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], barOut)
60	android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], bazOut)
61
62	if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz {
63		t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, baz)
64	}
65}
66