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