TestUseOption.java revision 3294:9adfb22ff08f
1/*
2 * Copyright (c) 2002, 2016, 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
27 * @summary A simple test to ensure class-use files are correct.
28 * @author jamieh
29 * @library ../lib
30 * @modules jdk.javadoc/jdk.javadoc.internal.tool
31 * @build JavadocTester
32 * @run main TestUseOption
33 */
34
35public class TestUseOption extends JavadocTester {
36
37    public static void main(String... args) throws Exception {
38        TestUseOption tester = new TestUseOption();
39        tester.runTests();
40    }
41
42    @Test
43    void test1() {
44        javadoc("-d", "out-1",
45                "-sourcepath", testSrc,
46                "-use",
47                "pkg1", "pkg2");
48        checkExit(Exit.OK);
49
50        // Eight tests for class use.
51        for (int i = 1; i <= 8; i++) {
52            checkOutput("pkg1/class-use/C1.html", true,
53                    "Test " + i + " passes");
54        }
55
56        // Three more tests for package use.
57        for (int i = 1; i <= 3; i++) {
58            checkOutput("pkg1/package-use.html", true,
59                    "Test " + i + " passes");
60        }
61
62        checkOrder("pkg1/class-use/UsedClass.html",
63                "Field in C1.",
64                "Field in C2.",
65                "Field in C4.",
66                "Field in C5.",
67                "Field in C6.",
68                "Field in C7.",
69                "Field in C8.",
70                "Method in C1.",
71                "Method in C2.",
72                "Method in C4.",
73                "Method in C5.",
74                "Method in C6.",
75                "Method in C7.",
76                "Method in C8."
77        );
78
79        checkOutput("pkg2/class-use/C3.html", true,
80                "<a href=\"../../index.html?pkg2/class-use/C3.html\" target=\"_top\">"
81                + "Frames</a></li>"
82        );
83        checkOutput("pkg1/class-use/UsedClass.html", true,
84          "that return types with arguments of type"
85        );
86        checkOutput("pkg1/class-use/UsedClass.html", true,
87          "<a href=\"../../pkg1/C1.html#methodInC1ReturningType--\">methodInC1ReturningType</a>"
88        );
89        checkOutput("pkg1/class-use/UsedInterface.html", true,
90          "Classes in <a href=\"../../pkg1/package-summary.html\">pkg1</a> that implement " +
91          "<a href=\"../../pkg1/UsedInterface.html\" title=\"interface in pkg1\">UsedInterface</a>"
92        );
93        checkOutput("pkg1/class-use/UsedInterfaceA.html", true,
94          "Classes in <a href=\"../../pkg1/package-summary.html\">pkg1</a> that implement " +
95          "<a href=\"../../pkg1/UsedInterfaceA.html\" title=\"interface in pkg1\">UsedInterfaceA</a>"
96        );
97        checkOutput("pkg1/class-use/UsedClass.html", false,
98           "methodInC1Protected"
99        );
100        checkOutput("pkg1/class-use/UsedInterface.html", true,
101           "<a href=\"../../pkg1/AnAbstract.html\" title=\"class in pkg1\">AnAbstract</a>"
102        );
103        checkOutput("pkg1/class-use/UsedInterface.html", true,
104            "../../pkg1/C10.html#withReturningTypeParameters--"
105        );
106        checkOutput("pkg1/class-use/UsedInterface.html", true,
107            "../../pkg1/C10.html#withTypeParametersOfType-java.lang.Class-"
108        );
109        checkOutput("pkg1/class-use/UsedInterface.html", true,
110            "\"../../pkg1/package-summary.html\">pkg1</a> that return " +
111            "<a href=\"../../pkg1/UsedInterface.html\" title=\"interface in pkg1\""
112        );
113        checkOutput("pkg1/class-use/UsedInterface.html", true,
114            "<a href=\"../../pkg1/C10.html#addAll-pkg1.UsedInterface...-\">addAll</a>"
115        );
116        checkOutput("pkg1/class-use/UsedInterface.html", true,
117            "<a href=\"../../pkg1/C10.html#create-pkg1.UsedInterfaceA-pkg1." +
118            "UsedInterface-java.lang.String-\">"
119        );
120        checkOutput("pkg1/class-use/UsedInterface.html", true,
121            "<a href=\"../../pkg1/C10.html#withTypeParametersOfType-java.lang.Class-\">" +
122            "withTypeParametersOfType</a>"
123        );
124    }
125
126    @Test
127    void test2() {
128        javadoc("-d", "out-2",
129                "-sourcepath", testSrc,
130                "-use",
131                testSrc("C.java"), testSrc("UsedInC.java"));
132        checkExit(Exit.OK);
133
134        checkOutput("class-use/UsedInC.html", true,
135                "Uses of <a href=\"../UsedInC.html\" title=\"class in &lt;Unnamed&gt;\">"
136                + "UsedInC</a> in <a href=\"../package-summary.html\">&lt;Unnamed&gt;</a>"
137        );
138        checkOutput("class-use/UsedInC.html", true,
139                "<li class=\"blockList\"><a name=\"unnamed.package\">"
140        );
141        checkOutput("package-use.html", true,
142                "<td class=\"colOne\">"
143                + "<a href=\"class-use/UsedInC.html#unnamed.package\">UsedInC</a>&nbsp;</td>"
144        );
145    }
146
147    @Test
148    void test3() {
149        javadoc("-d", "out-3",
150                "-sourcepath", testSrc,
151                "-use",
152                "-package", "unique");
153        checkExit(Exit.OK);
154        checkUnique("unique/class-use/UseMe.html",
155                "<a href=\"../../unique/C1.html#umethod1-unique.UseMe-unique.UseMe:A-\">",
156                "<a href=\"../../unique/C1.html#umethod2-unique.UseMe-unique.UseMe-\">",
157                "<a href=\"../../unique/C1.html#umethod3-unique.UseMe-unique.UseMe-\">",
158                "<a href=\"../../unique/C1.html#C1-unique.UseMe-unique.UseMe-\">");
159    }
160}
161