1 /* 2 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 4749567 8071982 8175200 8186332 8185371 8182765 8217034 27 * @summary Test the output for -header, -footer, -nooverview, -nodeprecatedlist, -nonavbar, -notree, 28 * -stylesheetfile, --main-stylesheet, --add-stylesheet options. 29 * @author Bhavesh Patel 30 * @library ../../lib 31 * @modules jdk.javadoc/jdk.javadoc.internal.tool 32 * @build javadoc.tester.* 33 * @run main TestOptions 34 */ 35 36 import java.io.File; 37 38 import javadoc.tester.JavadocTester; 39 40 public class TestOptions extends JavadocTester { 41 42 public static void main(String... args) throws Exception { 43 TestOptions tester = new TestOptions(); 44 tester.runTests(); 45 } 46 47 @Test 48 public void testHeaderFooter() { 49 javadoc("-d", "out-1", 50 "-header", "Test header", 51 "-footer", "Test footer", 52 "-sourcepath", testSrc, 53 "pkg"); 54 checkExit(Exit.OK); 55 56 checkOutput("pkg/package-summary.html", true, 57 "<div class=\"aboutLanguage\">Test header</div>", 58 "<div class=\"aboutLanguage\">Test footer</div>"); 59 } 60 61 @Test 62 public void testNoOverview() { 63 javadoc("-d", "out-4", 64 "-nooverview", 65 "-sourcepath", testSrc, 66 "pkg", "deprecated"); 67 68 checkExit(Exit.OK); 69 70 checkFiles(false, "overview-summary.html"); 71 } 72 73 @Test 74 public void testNoDeprecatedList() { 75 javadoc("-d", "out-5", 76 "-nodeprecatedlist", 77 "-sourcepath", testSrc, 78 "deprecated"); 79 checkExit(Exit.OK); 80 81 checkFiles(false, "deprecated-list.html"); 82 } 83 84 @Test 85 public void testNoNavbar() { 86 javadoc("-d", "out-6", 87 "-nonavbar", 88 "-bottom", "Bottom text", 89 "-sourcepath", testSrc, 90 "pkg"); 91 checkExit(Exit.OK); 92 93 checkOutput("pkg/Foo.html", false, "navbar"); 94 checkOutput("pkg/Foo.html", true, "Bottom text"); 95 } 96 97 @Test 98 public void testNoTree() { 99 javadoc("-d", "out-7", 100 "-notree", 101 "-sourcepath", testSrc, 102 "pkg"); 103 checkExit(Exit.OK); 104 105 checkFiles(false, "overview-tree.html"); 106 checkFiles(false, "pkg/package-tree.html"); 107 checkOutput("pkg/Foo.html", false, "<li><a href=\"package-tree.html\">Tree</a></li>"); 108 } 109 110 @Test 111 public void testStylesheetFile() { 112 javadoc("-d", "out-8", 113 "-stylesheetfile", new File(testSrc, "custom-stylesheet.css").getAbsolutePath(), 114 "-sourcepath", testSrc, 115 "pkg"); 116 checkExit(Exit.OK); 117 118 checkOutput("custom-stylesheet.css", true, "Custom javadoc style sheet"); 119 checkOutput("pkg/Foo.html", true, "<link rel=\"stylesheet\" type=\"text/css\" " 120 + "href=\"../custom-stylesheet.css\" title=\"Style\">"); 121 } 122 123 @Test 124 public void testStylesheetFileAltOption() { 125 javadoc("-d", "out-stylesheet-file", 126 "--main-stylesheet", new File(testSrc, "custom-stylesheet.css").getAbsolutePath(), 127 "-sourcepath", testSrc, 128 "pkg"); 129 checkExit(Exit.OK); 130 131 checkOutput("custom-stylesheet.css", true, "Custom javadoc style sheet"); 132 checkOutput("pkg/Foo.html", true, "<link rel=\"stylesheet\" type=\"text/css\" " 133 + "href=\"../custom-stylesheet.css\" title=\"Style\">"); 134 } 135 136 @Test 137 public void testAdditionalStylesheetFile() { 138 javadoc("-d", "out-additional-css", 139 "--add-stylesheet", new File(testSrc, "additional-stylesheet-1.css").getAbsolutePath(), 140 "--add-stylesheet", new File(testSrc, "additional-stylesheet-2.css").getAbsolutePath(), 141 "--add-stylesheet", new File(testSrc, "additional-stylesheet-3.css").getAbsolutePath(), 142 "-sourcepath", testSrc, 143 "pkg"); 144 checkExit(Exit.OK); 145 146 checkOutput("additional-stylesheet-1.css", true, "Additional javadoc style sheet 1"); 147 checkOutput("additional-stylesheet-2.css", true, "Additional javadoc style sheet 2"); 148 checkOutput("additional-stylesheet-3.css", true, "Additional javadoc style sheet 3"); 149 checkOutput("pkg/Foo.html", true, 150 "<link rel=\"stylesheet\" type=\"text/css\" href=\"../additional-stylesheet-1.css\" title=\"Style\">\n" 151 + "<link rel=\"stylesheet\" type=\"text/css\" href=\"../additional-stylesheet-2.css\" title=\"Style\">\n" 152 + "<link rel=\"stylesheet\" type=\"text/css\" href=\"../additional-stylesheet-3.css\" title=\"Style\">"); 153 } 154 155 @Test 156 public void testInvalidStylesheetFile() { 157 javadoc("-d", "out-invalid-css", 158 "--main-stylesheet", new File(testSrc, "custom-stylesheet-1.css").getAbsolutePath(), 159 "-sourcepath", testSrc, 160 "pkg"); 161 checkExit(Exit.ERROR); 162 163 checkOutput(Output.OUT, true, 164 "javadoc: error - File not found:", 165 "custom-stylesheet-1.css"); 166 } 167 168 @Test 169 public void testInvalidAdditionalStylesheetFiles() { 170 javadoc("-d", "out-invalid-additional-css", 171 "--add-stylesheet", new File(testSrc, "additional-stylesheet-4.css").getAbsolutePath(), 172 "-sourcepath", testSrc, 173 "pkg"); 174 checkExit(Exit.ERROR); 175 176 checkOutput(Output.OUT, true, 177 "javadoc: error - File not found:", 178 "additional-stylesheet-4.css"); 179 } 180 181 @Test 182 public void testLinkSource() { 183 javadoc("-d", "out-9", 184 "-linksource", 185 "-javafx", 186 "--disable-javafx-strict-checks", 187 "-sourcepath", testSrc, 188 "-package", 189 "linksource"); 190 checkExit(Exit.OK); 191 checkLinks(); 192 checkOutput("linksource/AnnotationTypeField.html", true, 193 "<pre>@Documented\npublic @interface <a href=" 194 + "\"../src-html/linksource/AnnotationTypeField.html#line.31\">" 195 + "AnnotationTypeField</a></pre>", 196 "<h3>DEFAULT_NAME</h3>\n" 197 + "<a id=\"DEFAULT_NAME\">\n" 198 + "<!-- -->\n" 199 + "</a>\n" 200 + "<pre>static final java.lang.String " 201 + "<a href=\"../src-html/linksource/AnnotationTypeField.html#line.32\">" 202 + "DEFAULT_NAME</a></pre>", 203 "<h3>name</h3>\n" 204 + "<a id=\"name()\">\n" 205 + "<!-- -->\n" 206 + "</a>\n" 207 + "<pre>java.lang.String <a href=" 208 + "\"../src-html/linksource/AnnotationTypeField.html#line.34\">name</a></pre>"); 209 210 checkOutput("src-html/linksource/AnnotationTypeField.html", true, 211 "<title>Source code</title>", 212 "<span class=\"sourceLineNo\">031</span><a id=\"line.31\">" 213 + "@Documented public @interface AnnotationTypeField {</a>"); 214 215 checkOutput("linksource/Properties.html", true, 216 "<pre>public class <a href=\"../src-html/linksource/Properties.html#line.29\">" 217 + "Properties</a>", 218 "<pre>public java.lang.Object <a href=" 219 + "\"../src-html/linksource/Properties.html#line.31\">someProperty</a></pre>", 220 "<pre class=\"methodSignature\">public java.lang.Object <a href=" 221 + "\"../src-html/linksource/Properties.html#line.31\">someProperty</a>()</pre>"); 222 223 checkOutput("src-html/linksource/Properties.html", true, 224 "<title>Source code</title>", 225 "<span class=\"sourceLineNo\">031</span><a id=\"line.31\"> " 226 + "public Object someProperty() {</a>"); 227 228 checkOutput("linksource/SomeClass.html", true, 229 "<pre>public class <a href=\"../src-html/linksource/SomeClass.html#line.29\">" 230 + "SomeClass</a>\nextends java.lang.Object</pre>", 231 "<pre>public int <a href=\"../src-html/linksource/SomeClass.html#line.31\">" 232 + "field</a></pre>", 233 "<pre>public <a href=\"../src-html/linksource/SomeClass.html#line.33\">" 234 + "SomeClass</a>()</pre>", 235 "<pre class=\"methodSignature\">public int <a href=\"../src-html/linksource/SomeClass.html#line.36\">" 236 + "method</a>()</pre>"); 237 238 checkOutput("src-html/linksource/SomeClass.html", true, 239 "<title>Source code</title>", 240 "<span class=\"sourceLineNo\">029</span><a id=\"line.29\">" 241 + "public class SomeClass {</a>", 242 "<span class=\"sourceLineNo\">031</span><a id=\"line.31\"> " 243 + "public int field;</a>", 244 "<span class=\"sourceLineNo\">033</span><a id=\"line.33\"> " 245 + "public SomeClass() {</a>", 246 "<span class=\"sourceLineNo\">036</span><a id=\"line.36\"> " 247 + "public int method() {</a>"); 248 249 checkOutput("linksource/SomeEnum.html", true, 250 "<pre>public static final <a href=\"SomeEnum.html\" " 251 + "title=\"enum in linksource\">SomeEnum</a> <a href=" 252 + "\"../src-html/linksource/SomeEnum.html#line.29\">VALUE1</a></pre>", 253 "<pre>public static final <a href=\"SomeEnum.html\" " 254 + "title=\"enum in linksource\">SomeEnum</a> <a href=" 255 + "\"../src-html/linksource/SomeEnum.html#line.30\">VALUE2</a></pre>"); 256 257 checkOutput("src-html/linksource/SomeEnum.html", true, 258 "<span class=\"sourceLineNo\">029</span><a id=\"line.29\"> VALUE1,</a>", 259 "<span class=\"sourceLineNo\">030</span><a id=\"line.30\"> VALUE2</a>"); 260 } 261 262 @Test 263 public void testNoQualifier() { 264 javadoc("-d", "out-10", 265 "-noqualifier", "pkg", 266 "-sourcepath", testSrc, 267 "pkg", "deprecated"); 268 checkExit(Exit.OK); 269 270 checkOutput("pkg/Foo.html", true, 271 "<div class=\"inheritance\">Foo</div>"); 272 checkOutput("deprecated/Foo.html", true, 273 "<div class=\"inheritance\">deprecated.Foo</div>"); 274 275 javadoc("-d", "out-10a", 276 "-noqualifier", "all", 277 "-sourcepath", testSrc, 278 "pkg", "deprecated"); 279 checkExit(Exit.OK); 280 281 checkOutput("pkg/Foo.html", true, 282 "<div class=\"inheritance\">Foo</div>"); 283 checkOutput("deprecated/Foo.html", true, 284 "<div class=\"inheritance\">Foo</div>"); 285 } 286 }