1 /*
   2  * Copyright (c) 2009, 2015, 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 6786690 6820360 8025633 8026567
  27  * @summary This test verifies the nesting of definition list tags.
  28  * @author Bhavesh Patel
  29  * @library ../lib
  30  * @modules jdk.javadoc
  31  * @build JavadocTester
  32  * @run main TestHtmlDefinitionListTag
  33  */
  34 
  35 import java.util.ArrayList;
  36 import java.util.Arrays;
  37 import java.util.List;
  38 
  39 public class TestHtmlDefinitionListTag extends JavadocTester {
  40 
  41     public static void main(String... args) throws Exception {
  42         TestHtmlDefinitionListTag tester = new TestHtmlDefinitionListTag();
  43         tester.runTests();
  44     }
  45 
  46     @Test
  47     void test_Comment_Deprecated() {
  48 //        tester.run(ARGS1, TEST_ALL, NEGATED_TEST_NO_C5);
  49 //        tester.runTestsOnHTML(NO_TEST,  NEGATED_TEST_C5);
  50 //        tester.runTestsOnHTML(TEST_CMNT_DEPR, NO_TEST);
  51         javadoc("-Xdoclint:none",
  52                 "-d", "out-1",
  53                 "-sourcepath", testSrc,
  54                 "pkg1");
  55         checkExit(Exit.OK);
  56         checkCommon(true);
  57         checkCommentDeprecated(true);
  58     }
  59 
  60     @Test
  61     void test_NoComment_Deprecated() {
  62 //        tester.run(ARGS2, TEST_ALL, NEGATED_TEST_NO_C5);
  63 //        tester.runTestsOnHTML(NO_TEST,  NEGATED_TEST_C5);
  64 //        tester.runTestsOnHTML(NO_TEST, TEST_CMNT_DEPR);
  65         javadoc("-Xdoclint:none",
  66                 "-d", "out-2",
  67                 "-nocomment",
  68                 "-sourcepath", testSrc,
  69                 "pkg1");
  70         checkExit(Exit.OK);
  71         checkCommon(true);
  72         checkCommentDeprecated(false); // ??
  73     }
  74 
  75     @Test
  76     void test_Comment_NoDeprecated() {
  77 //        tester.run(ARGS3, TEST_ALL, NEGATED_TEST_NO_C5);
  78 //        tester.runTestsOnHTML(TEST_NODEPR, TEST_NOCMNT_NODEPR);
  79         javadoc("-Xdoclint:none",
  80                 "-d", "out-3",
  81                 "-nodeprecated",
  82                 "-sourcepath", testSrc,
  83                 "pkg1");
  84         checkExit(Exit.OK);
  85         checkCommon(false);
  86         checkNoDeprecated();
  87         checkNoCommentNoDeprecated(false);
  88     }
  89 
  90     @Test
  91     void testNoCommentNoDeprecated() {
  92 //        tester.run(ARGS4, TEST_ALL, NEGATED_TEST_NO_C5);
  93 //        tester.runTestsOnHTML(TEST_NOCMNT_NODEPR, TEST_CMNT_DEPR);
  94         javadoc("-Xdoclint:none",
  95                 "-d", "out-4",
  96                 "-nocomment",
  97                 "-nodeprecated",
  98                 "-sourcepath", testSrc,
  99                 "pkg1");
 100         checkExit(Exit.OK);
 101         checkCommon(false);
 102         checkNoCommentNoDeprecated(true);
 103         checkCommentDeprecated(false);
 104     }
 105 
 106     void checkCommon(boolean checkC5) {
 107         // Test common to all runs of javadoc. The class signature should print
 108         // properly enclosed definition list tags and the Annotation Type
 109         // Optional Element should print properly nested definition list tags
 110         // for default value.
 111         checkOutput("pkg1/C1.html", true,
 112                 "<pre>public class <span class=\"typeNameLabel\">C1</span>\n" +
 113                 "extends java.lang.Object\n" +
 114                 "implements java.io.Serializable</pre>");
 115         checkOutput("pkg1/C4.html", true,
 116                 "<dl>\n" +
 117                 "<dt>Default:</dt>\n" +
 118                 "<dd>true</dd>\n" +
 119                 "</dl>");
 120 
 121         // Test for valid HTML generation which should not comprise of empty
 122         // definition list tags.
 123         List<String> files= new ArrayList<>(Arrays.asList(
 124             "pkg1/package-summary.html",
 125             "pkg1/C1.html",
 126             "pkg1/C1.ModalExclusionType.html",
 127             "pkg1/C2.html",
 128             "pkg1/C2.ModalType.html",
 129             "pkg1/C3.html",
 130             "pkg1/C4.html",
 131             "overview-tree.html",
 132             "serialized-form.html"
 133         ));
 134 
 135         if (checkC5)
 136             files.add("pkg1/C5.html");
 137 
 138         for (String f: files) {
 139             checkOutput(f, false,
 140                     "<dl></dl>",
 141                     "<dl>\n</dl>");
 142         }
 143     }
 144 
 145     void checkCommentDeprecated(boolean expectFound) {
 146         // Test for normal run of javadoc in which various ClassDocs and
 147         // serialized form should have properly nested definition list tags
 148         // enclosing comments, tags and deprecated information.
 149         checkOutput("pkg1/package-summary.html", expectFound,
 150                 "<dl>\n" +
 151                 "<dt><span class=\"simpleTagLabel\">Since:</span></dt>\n" +
 152                 "<dd>JDK1.0</dd>\n" +
 153                 "</dl>");
 154 
 155         checkOutput("pkg1/C1.html", expectFound,
 156                 "<dl>\n"
 157                 + "<dt><span class=\"simpleTagLabel\">Since:</span></dt>\n"
 158                 + "<dd>JDK1.0</dd>\n"
 159                 + "<dt><span class=\"seeLabel\">See Also:</span></dt>\n"
 160                 + "<dd><a href=\"../pkg1/C2.html\" title=\"class in pkg1\"><code>"
 161                 + "C2</code></a>, \n"
 162                 + "<a href=\"../serialized-form.html#pkg1.C1\">"
 163                 + "Serialized Form</a></dd>\n"
 164                 + "</dl>",
 165                 "<dl>\n"
 166                 + "<dt><span class=\"simpleTagLabel\">Since:</span></dt>\n"
 167                 + "<dd>1.4</dd>\n"
 168                 + "<dt><span class=\"seeLabel\">See Also:</span></dt>\n"
 169                 + "<dd><a href=\"../pkg1/C1.html#setUndecorated-boolean-\">"
 170                 + "<code>setUndecorated(boolean)</code></a></dd>\n"
 171                 + "</dl>",
 172                 "<dl>\n"
 173                 + "<dt><span class=\"paramLabel\">Parameters:</span></dt>\n"
 174                 + "<dd><code>title</code> - the title</dd>\n"
 175                 + "<dd><code>test</code> - boolean value"
 176                 + "</dd>\n"
 177                 + "<dt><span class=\"throwsLabel\">Throws:</span></dt>\n"
 178                 + "<dd><code>java.lang.IllegalArgumentException</code> - if the "
 179                 + "<code>owner</code>'s\n"
 180                 + "     <code>GraphicsConfiguration</code> is not from a screen "
 181                 + "device</dd>\n"
 182                 + "<dd><code>HeadlessException</code></dd>\n"
 183                 + "</dl>",
 184                 "<dl>\n"
 185                 + "<dt><span class=\"paramLabel\">Parameters:</span></dt>\n"
 186                 + "<dd><code>undecorated"
 187                 + "</code> - <code>true</code> if no decorations are\n"
 188                 + "         to be enabled;\n"
 189                 + "         <code>false</code> "
 190                 + "if decorations are to be enabled.</dd>\n"
 191                 + "<dt><span class=\"simpleTagLabel\">Since:"
 192                 + "</span></dt>\n"
 193                 + "<dd>1.4</dd>\n"
 194                 + "<dt><span class=\"seeLabel\">See Also:</span></dt>\n"
 195                 + "<dd>"
 196                 + "<a href=\"../pkg1/C1.html#readObject--\"><code>readObject()"
 197                 + "</code></a></dd>\n"
 198                 + "</dl>",
 199                 "<dl>\n"
 200                 + "<dt><span class=\"throwsLabel\">Throws:</span></dt>\n"
 201                 + "<dd><code>java.io.IOException</code></dd>\n"
 202                 + "<dt><span class=\"seeLabel\">See Also:"
 203                 + "</span></dt>\n"
 204                 + "<dd><a href=\"../pkg1/C1.html#setUndecorated-boolean-\">"
 205                 + "<code>setUndecorated(boolean)</code></a></dd>\n"
 206                 + "</dl>");
 207 
 208         checkOutput("pkg1/C2.html", expectFound,
 209                 "<dl>\n"
 210                 + "<dt><span class=\"paramLabel\">Parameters:"
 211                 + "</span></dt>\n"
 212                 + "<dd><code>set</code> - boolean</dd>\n"
 213                 + "<dt><span class=\"simpleTagLabel\">"
 214                 + "Since:</span></dt>\n"
 215                 + "<dd>1.4</dd>\n"
 216                 + "</dl>");
 217 
 218         checkOutput("serialized-form.html", expectFound,
 219                 "<dl>\n"
 220                 + "<dt><span class=\"throwsLabel\">Throws:</span>"
 221                 + "</dt>\n"
 222                 + "<dd><code>"
 223                 + "java.io.IOException</code></dd>\n"
 224                 + "<dt><span class=\"seeLabel\">See Also:</span>"
 225                 + "</dt>\n"
 226                 + "<dd><a href=\"pkg1/C1.html#setUndecorated-boolean-\">"
 227                 + "<code>C1.setUndecorated(boolean)</code></a></dd>\n"
 228                 + "</dl>",
 229                 "<span class=\"deprecatedLabel\">Deprecated.</span>"
 230                 + "&nbsp;<span class=\"deprecationComment\">As of JDK version 1.5, replaced by\n"
 231                 + " <a href=\"pkg1/C1.html#setUndecorated-boolean-\">"
 232                 + "<code>setUndecorated(boolean)</code></a>.</span></div>\n"
 233                 + "<div class=\"block\">This field indicates whether the C1 is "
 234                 + "undecorated.</div>\n"
 235                 + "&nbsp;\n"
 236                 + "<dl>\n"
 237                 + "<dt><span class=\"simpleTagLabel\">Since:</span></dt>\n"
 238                 + "<dd>1.4</dd>\n"
 239                 + "<dt><span class=\"seeLabel\">See Also:</span>"
 240                 + "</dt>\n"
 241                 + "<dd><a href=\"pkg1/C1.html#setUndecorated-boolean-\">"
 242                 + "<code>C1.setUndecorated(boolean)</code></a></dd>\n"
 243                 + "</dl>",
 244                 "<span class=\"deprecatedLabel\">Deprecated.</span>"
 245                 + "&nbsp;<span class=\"deprecationComment\">As of JDK version 1.5, replaced by\n"
 246                 + " <a href=\"pkg1/C1.html#setUndecorated-boolean-\">"
 247                 + "<code>setUndecorated(boolean)</code></a>.</span></div>\n"
 248                 + "<div class=\"block\">Reads the object stream.</div>\n"
 249                 + "<dl>\n"
 250                 + "<dt><span class=\"throwsLabel\">Throws:"
 251                 + "</span></dt>\n"
 252                 + "<dd><code>java.io.IOException</code></dd>\n"
 253                 + "</dl>",
 254                 "<span class=\"deprecatedLabel\">Deprecated.</span>"
 255                 + "&nbsp;</div>\n"
 256                 + "<div class=\"block\">The name for this class.</div>");
 257     }
 258 
 259     void checkNoDeprecated() {
 260         // Test with -nodeprecated option. The ClassDocs should have properly nested
 261         // definition list tags enclosing comments and tags. The ClassDocs should not
 262         // display definition list for deprecated information. The serialized form
 263         // should display properly nested definition list tags for comments, tags
 264         // and deprecated information.
 265         checkOutput("pkg1/package-summary.html", true,
 266                 "<dl>\n" +
 267                 "<dt><span class=\"simpleTagLabel\">Since:</span></dt>\n" +
 268                 "<dd>JDK1.0</dd>\n" +
 269                 "</dl>");
 270 
 271         checkOutput("pkg1/C1.html", true,
 272                 "<dl>\n" +
 273                 "<dt><span class=\"simpleTagLabel\">Since:</span>" +
 274                 "</dt>\n" +
 275                 "<dd>JDK1.0</dd>\n" +
 276                 "<dt><span class=\"seeLabel\">See Also:" +
 277                 "</span></dt>\n" +
 278                 "<dd><a href=\"../pkg1/C2.html\" title=\"class in pkg1\">" +
 279                 "<code>C2</code></a>, \n" +
 280                 "<a href=\"../serialized-form.html#pkg1.C1\">" +
 281                 "Serialized Form</a></dd>\n" +
 282                 "</dl>");
 283 
 284         checkOutput("pkg1/C1.html", true,
 285                 "<dl>\n"
 286                 + "<dt><span class=\"paramLabel\">Parameters:"
 287                 + "</span></dt>\n"
 288                 + "<dd><code>title</code> - the title</dd>\n"
 289                 + "<dd><code>"
 290                 + "test</code> - boolean value</dd>\n"
 291                 + "<dt><span class=\"throwsLabel\">Throws:"
 292                 + "</span></dt>\n"
 293                 + "<dd><code>java.lang.IllegalArgumentException"
 294                 + "</code> - if the <code>owner</code>'s\n"
 295                 + "     <code>GraphicsConfiguration"
 296                 + "</code> is not from a screen device</dd>\n"
 297                 + "<dd><code>"
 298                 + "HeadlessException</code></dd>\n"
 299                 + "</dl>",
 300                 "<dl>\n"
 301                 + "<dt><span class=\"paramLabel\">Parameters:"
 302                 + "</span></dt>\n"
 303                 + "<dd><code>undecorated</code> - <code>true</code>"
 304                 + " if no decorations are\n"
 305                 + "         to be enabled;\n"
 306                 + "         <code>false</code> if decorations are to be enabled."
 307                 + "</dd>\n"
 308                 + "<dt><span class=\"simpleTagLabel\">Since:</span></dt>\n"
 309                 + "<dd>1.4</dd>\n"
 310                 + "<dt><span class=\"seeLabel\">See Also:</span></dt>\n"
 311                 + "<dd><a href=\"../pkg1/C1.html#readObject--\">"
 312                 + "<code>readObject()</code></a></dd>\n"
 313                 + "</dl>",
 314                 "<dl>\n"
 315                 + "<dt><span class=\"throwsLabel\">Throws:</span>"
 316                 + "</dt>\n"
 317                 + "<dd><code>java.io.IOException</code></dd>\n"
 318                 + "<dt>"
 319                 + "<span class=\"seeLabel\">See Also:</span></dt>\n"
 320                 + "<dd><a href=\"../pkg1/C1.html#setUndecorated-boolean-\">"
 321                 + "<code>setUndecorated(boolean)</code></a></dd>\n"
 322                 + "</dl>");
 323 
 324         checkOutput("serialized-form.html", true,
 325                 "<dl>\n"
 326                 + "<dt><span class=\"throwsLabel\">Throws:</span>"
 327                 + "</dt>\n"
 328                 + "<dd><code>"
 329                 + "java.io.IOException</code></dd>\n"
 330                 + "<dt><span class=\"seeLabel\">See Also:</span>"
 331                 + "</dt>\n"
 332                 + "<dd><a href=\"pkg1/C1.html#setUndecorated-boolean-\">"
 333                 + "<code>C1.setUndecorated(boolean)</code></a></dd>\n"
 334                 + "</dl>",
 335                 "<span class=\"deprecatedLabel\">Deprecated.</span>"
 336                 + "&nbsp;<span class=\"deprecationComment\">As of JDK version 1.5, replaced by\n"
 337                 + " <a href=\"pkg1/C1.html#setUndecorated-boolean-\">"
 338                 + "<code>setUndecorated(boolean)</code></a>.</span></div>\n"
 339                 + "<div class=\"block\">This field indicates whether the C1 is "
 340                 + "undecorated.</div>\n"
 341                 + "&nbsp;\n"
 342                 + "<dl>\n"
 343                 + "<dt><span class=\"simpleTagLabel\">Since:</span></dt>\n"
 344                 + "<dd>1.4</dd>\n"
 345                 + "<dt><span class=\"seeLabel\">See Also:</span>"
 346                 + "</dt>\n"
 347                 + "<dd><a href=\"pkg1/C1.html#setUndecorated-boolean-\">"
 348                 + "<code>C1.setUndecorated(boolean)</code></a></dd>\n"
 349                 + "</dl>",
 350                 "<span class=\"deprecatedLabel\">Deprecated.</span>"
 351                 + "&nbsp;<span class=\"deprecationComment\">As of JDK version 1.5, replaced by\n"
 352                 + " <a href=\"pkg1/C1.html#setUndecorated-boolean-\">"
 353                 + "<code>setUndecorated(boolean)</code></a>.</span></div>\n"
 354                 + "<div class=\"block\">Reads the object stream.</div>\n"
 355                 + "<dl>\n"
 356                 + "<dt><span class=\"throwsLabel\">Throws:"
 357                 + "</span></dt>\n"
 358                 + "<dd><code>java.io.IOException</code></dd>\n"
 359                 + "</dl>",
 360                 "<span class=\"deprecatedLabel\">Deprecated.</span>"
 361                 + "&nbsp;</div>\n"
 362                 + "<div class=\"block\">"
 363                 + "The name for this class.</div>");
 364     }
 365 
 366     void checkNoCommentNoDeprecated(boolean expectFound) {
 367         // Test with -nocomment and -nodeprecated options. The ClassDocs whould
 368         // not display definition lists for any member details.
 369         checkOutput("pkg1/C1.html", expectFound,
 370                 "<pre>public&nbsp;void&nbsp;readObject()\n" +
 371                 "                throws java.io.IOException</pre>\n" +
 372                 "</li>");
 373 
 374         checkOutput("pkg1/C2.html", expectFound,
 375                 "<pre>public&nbsp;C2()</pre>\n" +
 376                 "</li>");
 377 
 378         checkOutput("pkg1/C1.ModalExclusionType.html", expectFound,
 379                 "<pre>public " +
 380                 "static final&nbsp;<a href=\"../pkg1/C1.ModalExclusionType.html\" " +
 381                 "title=\"enum in pkg1\">C1.ModalExclusionType</a> " +
 382                 "APPLICATION_EXCLUDE</pre>\n" +
 383                 "</li>");
 384 
 385         checkOutput("serialized-form.html", expectFound,
 386                 "<pre>boolean " +
 387                 "undecorated</pre>\n" +
 388                 "<div class=\"block\"><span class=\"deprecatedLabel\">" +
 389                 "Deprecated.</span>&nbsp;<span class=\"deprecationComment\">As of JDK version 1.5, replaced by\n" +
 390                 " <a href=\"pkg1/C1.html#setUndecorated-boolean-\"><code>" +
 391                 "setUndecorated(boolean)</code></a>.</span></div>\n" +
 392                 "</li>",
 393                 "<span class=\"deprecatedLabel\">" +
 394                 "Deprecated.</span>&nbsp;<span class=\"deprecationComment\">As of JDK version" +
 395                 " 1.5, replaced by\n" +
 396                 " <a href=\"pkg1/C1.html#setUndecorated-boolean-\">" +
 397                 "<code>setUndecorated(boolean)</code></a>.</span></div>\n" +
 398                 "</li>");
 399     }
 400 }