blob: 2256f1e2316c755ff57727cfa58e485e6e392918 [file] [log] [blame]
Colin Cross2207f872021-03-24 12:39:08 -07001// Copyright 2021 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 "reflect"
19 "strings"
20 "testing"
21
22 "android/soong/android"
23)
24
25func TestDroiddoc(t *testing.T) {
Colin Cross844cb6a2025-01-29 15:53:21 -080026 t.Parallel()
Colin Cross2207f872021-03-24 12:39:08 -070027 ctx, _ := testJavaWithFS(t, `
28 droiddoc_exported_dir {
29 name: "droiddoc-templates-sdk",
30 path: ".",
31 }
32 filegroup {
33 name: "bar-doc-aidl-srcs",
34 srcs: ["bar-doc/IBar.aidl"],
35 path: "bar-doc",
36 }
37 droidstubs {
38 name: "bar-stubs",
39 srcs: [
40 "bar-doc/a.java",
41 ],
42 exclude_srcs: [
43 "bar-doc/b.java"
44 ],
45 api_levels_annotations_dirs: [
46 "droiddoc-templates-sdk",
47 ],
48 api_levels_annotations_enabled: true,
49 }
50 droiddoc {
51 name: "bar-doc",
52 srcs: [
53 ":bar-stubs",
54 "bar-doc/IFoo.aidl",
55 ":bar-doc-aidl-srcs",
56 ],
57 custom_template: "droiddoc-templates-sdk",
58 hdf: [
59 "android.whichdoc offline",
60 ],
61 knowntags: [
62 "bar-doc/known_oj_tags.txt",
63 ],
64 proofread_file: "libcore-proofread.txt",
65 todo_file: "libcore-docs-todo.html",
66 flags: ["-offlinemode -title \"libcore\""],
67 }
68 `,
69 map[string][]byte{
70 "bar-doc/a.java": nil,
71 "bar-doc/b.java": nil,
72 })
Yu Liu51c22312024-08-20 23:56:15 +000073 barStubsOutputs := ctx.ModuleForTests("bar-stubs", "android_common").OutputFiles(ctx, t, "")
Colin Cross2207f872021-03-24 12:39:08 -070074 if len(barStubsOutputs) != 1 {
75 t.Errorf("Expected one output from \"bar-stubs\" got %s", barStubsOutputs)
76 }
77
78 barStubsOutput := barStubsOutputs[0]
79 barDoc := ctx.ModuleForTests("bar-doc", "android_common")
Paul Duffina71a67a2021-03-29 00:42:57 +010080 javaDoc := barDoc.Rule("javadoc")
Colin Cross2207f872021-03-24 12:39:08 -070081 if g, w := android.PathsRelativeToTop(javaDoc.Implicits), android.PathRelativeToTop(barStubsOutput); !inList(w, g) {
82 t.Errorf("implicits of bar-doc must contain %q, but was %q.", w, g)
83 }
84
85 expected := "-sourcepath out/soong/.intermediates/bar-doc/android_common/srcjars "
86 if !strings.Contains(javaDoc.RuleParams.Command, expected) {
87 t.Errorf("bar-doc command does not contain flag %q, but should\n%q", expected, javaDoc.RuleParams.Command)
88 }
89
90 aidl := barDoc.Rule("aidl")
91 if g, w := android.PathsRelativeToTop(javaDoc.Implicits), android.PathRelativeToTop(aidl.Output); !inList(w, g) {
92 t.Errorf("implicits of bar-doc must contain %q, but was %q.", w, g)
93 }
94
95 if g, w := aidl.Implicits.Strings(), []string{"bar-doc/IBar.aidl", "bar-doc/IFoo.aidl"}; !reflect.DeepEqual(w, g) {
96 t.Errorf("aidl inputs must be %q, but was %q", w, g)
97 }
98}
99
100func TestDroiddocArgsAndFlagsCausesError(t *testing.T) {
Colin Cross844cb6a2025-01-29 15:53:21 -0800101 t.Parallel()
Colin Cross2207f872021-03-24 12:39:08 -0700102 testJavaError(t, "flags is set. Cannot set args", `
103 droiddoc_exported_dir {
104 name: "droiddoc-templates-sdk",
105 path: ".",
106 }
107 filegroup {
108 name: "bar-doc-aidl-srcs",
109 srcs: ["bar-doc/IBar.aidl"],
110 path: "bar-doc",
111 }
112 droidstubs {
113 name: "bar-stubs",
114 srcs: [
115 "bar-doc/a.java",
116 ],
117 exclude_srcs: [
118 "bar-doc/b.java"
119 ],
120 api_levels_annotations_dirs: [
121 "droiddoc-templates-sdk",
122 ],
123 api_levels_annotations_enabled: true,
124 }
125 droiddoc {
126 name: "bar-doc",
127 srcs: [
128 ":bar-stubs",
129 "bar-doc/IFoo.aidl",
130 ":bar-doc-aidl-srcs",
131 ],
132 custom_template: "droiddoc-templates-sdk",
133 hdf: [
134 "android.whichdoc offline",
135 ],
136 knowntags: [
137 "bar-doc/known_oj_tags.txt",
138 ],
139 proofread_file: "libcore-proofread.txt",
140 todo_file: "libcore-docs-todo.html",
141 flags: ["-offlinemode -title \"libcore\""],
142 args: "-offlinemode -title \"libcore\"",
143 }
144 `)
145}