droiddoc_test.go 4.1 KB

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