| Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1 | // 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 |  | 
|  | 15 | package java | 
|  | 16 |  | 
|  | 17 | import ( | 
|  | 18 | "reflect" | 
|  | 19 | "strings" | 
|  | 20 | "testing" | 
|  | 21 |  | 
|  | 22 | "android/soong/android" | 
|  | 23 | ) | 
|  | 24 |  | 
|  | 25 | func 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 | }) | 
| Yu Liu | 51c2231 | 2024-08-20 23:56:15 +0000 | [diff] [blame] | 72 | barStubsOutputs := ctx.ModuleForTests("bar-stubs", "android_common").OutputFiles(ctx, t, "") | 
| Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 73 | if len(barStubsOutputs) != 1 { | 
|  | 74 | t.Errorf("Expected one output from \"bar-stubs\" got %s", barStubsOutputs) | 
|  | 75 | } | 
|  | 76 |  | 
|  | 77 | barStubsOutput := barStubsOutputs[0] | 
|  | 78 | barDoc := ctx.ModuleForTests("bar-doc", "android_common") | 
| Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 79 | javaDoc := barDoc.Rule("javadoc") | 
| Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 80 | if g, w := android.PathsRelativeToTop(javaDoc.Implicits), android.PathRelativeToTop(barStubsOutput); !inList(w, g) { | 
|  | 81 | t.Errorf("implicits of bar-doc must contain %q, but was %q.", w, g) | 
|  | 82 | } | 
|  | 83 |  | 
|  | 84 | expected := "-sourcepath out/soong/.intermediates/bar-doc/android_common/srcjars " | 
|  | 85 | if !strings.Contains(javaDoc.RuleParams.Command, expected) { | 
|  | 86 | t.Errorf("bar-doc command does not contain flag %q, but should\n%q", expected, javaDoc.RuleParams.Command) | 
|  | 87 | } | 
|  | 88 |  | 
|  | 89 | aidl := barDoc.Rule("aidl") | 
|  | 90 | if g, w := android.PathsRelativeToTop(javaDoc.Implicits), android.PathRelativeToTop(aidl.Output); !inList(w, g) { | 
|  | 91 | t.Errorf("implicits of bar-doc must contain %q, but was %q.", w, g) | 
|  | 92 | } | 
|  | 93 |  | 
|  | 94 | if g, w := aidl.Implicits.Strings(), []string{"bar-doc/IBar.aidl", "bar-doc/IFoo.aidl"}; !reflect.DeepEqual(w, g) { | 
|  | 95 | t.Errorf("aidl inputs must be %q, but was %q", w, g) | 
|  | 96 | } | 
|  | 97 | } | 
|  | 98 |  | 
|  | 99 | func TestDroiddocArgsAndFlagsCausesError(t *testing.T) { | 
|  | 100 | testJavaError(t, "flags is set. Cannot set args", ` | 
|  | 101 | droiddoc_exported_dir { | 
|  | 102 | name: "droiddoc-templates-sdk", | 
|  | 103 | path: ".", | 
|  | 104 | } | 
|  | 105 | filegroup { | 
|  | 106 | name: "bar-doc-aidl-srcs", | 
|  | 107 | srcs: ["bar-doc/IBar.aidl"], | 
|  | 108 | path: "bar-doc", | 
|  | 109 | } | 
|  | 110 | droidstubs { | 
|  | 111 | name: "bar-stubs", | 
|  | 112 | srcs: [ | 
|  | 113 | "bar-doc/a.java", | 
|  | 114 | ], | 
|  | 115 | exclude_srcs: [ | 
|  | 116 | "bar-doc/b.java" | 
|  | 117 | ], | 
|  | 118 | api_levels_annotations_dirs: [ | 
|  | 119 | "droiddoc-templates-sdk", | 
|  | 120 | ], | 
|  | 121 | api_levels_annotations_enabled: true, | 
|  | 122 | } | 
|  | 123 | droiddoc { | 
|  | 124 | name: "bar-doc", | 
|  | 125 | srcs: [ | 
|  | 126 | ":bar-stubs", | 
|  | 127 | "bar-doc/IFoo.aidl", | 
|  | 128 | ":bar-doc-aidl-srcs", | 
|  | 129 | ], | 
|  | 130 | custom_template: "droiddoc-templates-sdk", | 
|  | 131 | hdf: [ | 
|  | 132 | "android.whichdoc offline", | 
|  | 133 | ], | 
|  | 134 | knowntags: [ | 
|  | 135 | "bar-doc/known_oj_tags.txt", | 
|  | 136 | ], | 
|  | 137 | proofread_file: "libcore-proofread.txt", | 
|  | 138 | todo_file: "libcore-docs-todo.html", | 
|  | 139 | flags: ["-offlinemode -title \"libcore\""], | 
|  | 140 | args: "-offlinemode -title \"libcore\"", | 
|  | 141 | } | 
|  | 142 | `) | 
|  | 143 | } |