1 /*
   2  * Copyright (c) 2002, 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 4496290 4985072 7006178 7068595 8016328 8050031 8048351 8081854 8071982 8162363 8175200 8186332
  27  *      8182765 8196202 8202626
  28  * @summary A simple test to ensure class-use files are correct.
  29  * @library ../../lib
  30  * @modules jdk.javadoc/jdk.javadoc.internal.tool
  31  * @build javadoc.tester.*
  32  * @run main TestUseOption
  33  */
  34 
  35 import javadoc.tester.JavadocTester;
  36 
  37 public class TestUseOption extends JavadocTester {
  38 
  39     public static void main(String... args) throws Exception {
  40         TestUseOption tester = new TestUseOption();
  41         tester.runTests();
  42     }
  43 
  44     @Test
  45     public void test1() {
  46         javadoc("-d", "out-1",
  47                 "-sourcepath", testSrc,
  48                 "-use",
  49                 "pkg1", "pkg2");
  50         checkExit(Exit.OK);
  51 
  52         // Eight tests for class use.
  53         for (int i = 1; i <= 8; i++) {
  54             checkOutput("pkg1/class-use/C1.html", true,
  55                     "Test " + i + " passes");
  56         }
  57 
  58         // Three more tests for package use.
  59         for (int i = 1; i <= 3; i++) {
  60             checkOutput("pkg1/package-use.html", true,
  61                     "Test " + i + " passes");
  62         }
  63 
  64         checkOrder("pkg1/class-use/UsedClass.html",
  65                 "Field in C1.",
  66                 "Field in C2.",
  67                 "Field in C4.",
  68                 "Field in C5.",
  69                 "Field in C6.",
  70                 "Field in C7.",
  71                 "Field in C8.",
  72                 "Method in C1.",
  73                 "Method in C2.",
  74                 "Method in C4.",
  75                 "Method in C5.",
  76                 "Method in C6.",
  77                 "Method in C7.",
  78                 "Method in C8."
  79         );
  80 
  81         checkOutput("pkg1/class-use/UsedClass.html", true,
  82           "that return types with arguments of type"
  83         );
  84         checkOutput("pkg1/class-use/UsedClass.html", true,
  85           "<a href=\"../C1.html#methodInC1ReturningType()\">methodInC1ReturningType</a>"
  86         );
  87         checkOutput("pkg1/class-use/UsedInterface.html", true,
  88           "Classes in <a href=\"../package-summary.html\">pkg1</a> that implement " +
  89           "<a href=\"../UsedInterface.html\" title=\"interface in pkg1\">UsedInterface</a>"
  90         );
  91         checkOutput("pkg1/class-use/UsedInterfaceA.html", true,
  92           "Classes in <a href=\"../package-summary.html\">pkg1</a> that implement " +
  93           "<a href=\"../UsedInterfaceA.html\" title=\"interface in pkg1\">UsedInterfaceA</a>"
  94         );
  95         checkOutput("pkg1/class-use/UsedClass.html", false,
  96            "methodInC1Protected"
  97         );
  98         checkOutput("pkg1/class-use/UsedInterface.html", true,
  99            "<a href=\"../AnAbstract.html\" title=\"class in pkg1\">AnAbstract</a>"
 100         );
 101         checkOutput("pkg1/class-use/UsedInterface.html", true,
 102             "../C10.html#withReturningTypeParameters()"
 103         );
 104         checkOutput("pkg1/class-use/UsedInterface.html", true,
 105             "../C10.html#withTypeParametersOfType(java.lang.Class)"
 106         );
 107         checkOutput("pkg1/class-use/UsedInterface.html", true,
 108             "\"../package-summary.html\">pkg1</a> that return " +
 109             "<a href=\"../UsedInterface.html\" title=\"interface in pkg1\""
 110         );
 111         checkOutput("pkg1/class-use/UsedInterface.html", true,
 112             "<a href=\"../C10.html#addAll(pkg1.UsedInterface...)\">addAll</a>"
 113         );
 114         checkOutput("pkg1/class-use/UsedInterface.html", true,
 115             "<a href=\"../C10.html#create(pkg1.UsedInterfaceA,pkg1." +
 116             "UsedInterface,java.lang.String)\">"
 117         );
 118         checkOutput("pkg1/class-use/UsedInterface.html", true,
 119             "<a href=\"../C10.html#withTypeParametersOfType(java.lang.Class)\">" +
 120             "withTypeParametersOfType</a>"
 121         );
 122         checkOutput("pkg1/class-use/UsedInterface.html", true,
 123             "Subinterfaces of <a href=\"../UsedInterface.html\" title=\"interface in pkg1\">"
 124             + "UsedInterface</a> in <a href=\"../package-summary.html\">pkg1",
 125             "<td class=\"colFirst\"><code>interface&nbsp;</code></td>\n<th class=\"colSecond\" scope=\"row\">"
 126             + "<code><span class=\"memberNameLink\"><a href=\"../SubInterface.html\" "
 127             + "title=\"interface in pkg1\">SubInterface</a>&lt;T&gt;</span></code></th>"
 128         );
 129         checkOutput("pkg1/class-use/UsedThrowable.html", true,
 130             "Methods in <a href=\"../package-summary.html\">pkg1</a> that throw "
 131             + "<a href=\"../UsedThrowable.html\" title=\"class in pkg1\">UsedThrowable</a>",
 132             "<td class=\"colFirst\"><code>void</code></td>\n<th class=\"colSecond\" scope=\"row\"><span class="
 133             + "\"typeNameLabel\">C1.</span><code><span class=\"memberNameLink\">"
 134             + "<a href=\"../C1.html#methodInC1ThrowsThrowable()\">methodInC1ThrowsThrowable"
 135             + "</a></span>()</code></th>"
 136         );
 137     }
 138 
 139     @Test
 140     public void test2() {
 141         javadoc("-d", "out-2",
 142                 "-sourcepath", testSrc,
 143                 "-use",
 144                 testSrc("C.java"), testSrc("UsedInC.java"), "pkg3");
 145         checkExit(Exit.OK);
 146 
 147         checkOutput("class-use/UsedInC.html", true,
 148                 "Uses of <a href=\"../UsedInC.html\" title=\"class in &lt;Unnamed&gt;\">"
 149                 + "UsedInC</a> in <a href=\"../package-summary.html\">&lt;Unnamed&gt;</a>"
 150         );
 151         checkOutput("class-use/UsedInC.html", true,
 152                 "<li class=\"blockList\">\n"
 153                 + "<section class=\"detail\" id=\"unnamed.package\">\n"
 154         );
 155         checkOutput("package-use.html", true,
 156                 "<th class=\"colFirst\" scope=\"row\">"
 157                 + "<a href=\"class-use/UsedInC.html#unnamed.package\">UsedInC</a></th>",
 158                 "<th class=\"colFirst\" scope=\"row\"><a href=\"#unnamed.package\">&lt;Unnamed&gt;</a></th>\n"
 159                 + "<td class=\"colLast\">&nbsp;</td>"
 160         );
 161     }
 162 
 163     @Test
 164     public void test3() {
 165         javadoc("-d", "out-3",
 166                 "-sourcepath", testSrc,
 167                 "-use",
 168                 "-package", "unique");
 169         checkExit(Exit.OK);
 170         checkUnique("unique/class-use/UseMe.html",
 171                 "<a href=\"../C1.html#umethod1(unique.UseMe,unique.UseMe%5B%5D)\">",
 172                 "<a href=\"../C1.html#umethod2(unique.UseMe,unique.UseMe)\">",
 173                 "<a href=\"../C1.html#umethod3(unique.UseMe,unique.UseMe)\">",
 174                 "<a href=\"../C1.html#%3Cinit%3E(unique.UseMe,unique.UseMe)\">");
 175     }
 176 }