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 + "<div class=\"memberSignature\"><span class=\"modifiers\">static final</span> " 201 + "<span class=\"returnType\">java.lang.String</span> <span class=\"memberName\">" 202 + "<a href=\"../src-html/linksource/AnnotationTypeField.html#line.32\">DEFAULT_NAME</a></span></div>", 203 "<h3>name</h3>\n" 204 + "<a id=\"name()\">\n" 205 + "<!-- -->\n" 206 + "</a>\n" 207 + "<div class=\"memberSignature\"><span class=\"returnType\">java.lang.String</span> " 208 + "<span class=\"memberName\"><a href=\"../src-html/linksource/AnnotationTypeField.html#line.34\">" 209 + "name</a></span></div>"); 210 211 checkOutput("src-html/linksource/AnnotationTypeField.html", true, 212 "<title>Source code</title>", 213 "<span class=\"sourceLineNo\">031</span><a id=\"line.31\">" 214 + "@Documented public @interface AnnotationTypeField {</a>"); 215 216 checkOutput("linksource/Properties.html", true, 217 "<pre>public class <a href=\"../src-html/linksource/Properties.html#line.29\">" 218 + "Properties</a>", 219 "<div class=\"memberSignature\"><span class=\"modifiers\">public</span> " 220 + "<span class=\"returnType\">java.lang.Object</span> <span class=\"memberName\">" 221 + "<a href=\"../src-html/linksource/Properties.html#line.31\">someProperty</a></span></div>"); 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 "<div class=\"memberSignature\"><span class=\"modifiers\">public</span> " 232 + "<span class=\"returnType\">int</span> <span class=\"memberName\">" 233 + "<a href=\"../src-html/linksource/SomeClass.html#line.31\">field</a></span></div>", 234 "<div class=\"memberSignature\"><span class=\"modifiers\">public</span> " 235 + "<span class=\"memberName\"><a href=\"../src-html/linksource/SomeClass.html#line.33\">" 236 + "SomeClass</a></span>()</div>", 237 "<div class=\"memberSignature\"><span class=\"modifiers\">public</span> " 238 + "<span class=\"returnType\">int</span> <span class=\"memberName\">" 239 + "<a href=\"../src-html/linksource/SomeClass.html#line.36\">method</a></span>()</div>"); 240 241 checkOutput("src-html/linksource/SomeClass.html", true, 242 "<title>Source code</title>", 243 "<span class=\"sourceLineNo\">029</span><a id=\"line.29\">" 244 + "public class SomeClass {</a>", 245 "<span class=\"sourceLineNo\">031</span><a id=\"line.31\"> " 246 + "public int field;</a>", 247 "<span class=\"sourceLineNo\">033</span><a id=\"line.33\"> " 248 + "public SomeClass() {</a>", 249 "<span class=\"sourceLineNo\">036</span><a id=\"line.36\"> " 250 + "public int method() {</a>"); 251 252 checkOutput("linksource/SomeEnum.html", true, 253 "<div class=\"memberSignature\"><span class=\"modifiers\">public static final</span> " 254 + "<span class=\"returnType\"><a href=\"SomeEnum.html\" title=\"enum in linksource\">" 255 + "SomeEnum</a></span> <span class=\"memberName\">" 256 + "<a href=\"../src-html/linksource/SomeEnum.html#line.29\">VALUE1</a></span></div>", 257 "<div class=\"memberSignature\"><span class=\"modifiers\">public static final</span> " 258 + "<span class=\"returnType\"><a href=\"SomeEnum.html\" title=\"enum in linksource\">" 259 + "SomeEnum</a></span> <span class=\"memberName\">" 260 + "<a href=\"../src-html/linksource/SomeEnum.html#line.30\">VALUE2</a></span></div>"); 261 262 checkOutput("src-html/linksource/SomeEnum.html", true, 263 "<span class=\"sourceLineNo\">029</span><a id=\"line.29\"> VALUE1,</a>", 264 "<span class=\"sourceLineNo\">030</span><a id=\"line.30\"> VALUE2</a>"); 265 } 266 267 @Test 268 public void testNoQualifier() { 269 javadoc("-d", "out-10", 270 "-noqualifier", "pkg", 271 "-sourcepath", testSrc, 272 "pkg", "deprecated"); 273 checkExit(Exit.OK); 274 275 checkOutput("pkg/Foo.html", true, 276 "<div class=\"inheritance\">Foo</div>"); 277 checkOutput("deprecated/Foo.html", true, 278 "<div class=\"inheritance\">deprecated.Foo</div>"); 279 280 javadoc("-d", "out-10a", 281 "-noqualifier", "all", 282 "-sourcepath", testSrc, 283 "pkg", "deprecated"); 284 checkExit(Exit.OK); 285 286 checkOutput("pkg/Foo.html", true, 287 "<div class=\"inheritance\">Foo</div>"); 288 checkOutput("deprecated/Foo.html", true, 289 "<div class=\"inheritance\">Foo</div>"); 290 } 291 } --- EOF ---