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