1/*
2 * Copyright (c) 2013, 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 8025633 8025524 8081854
27 * @summary Test for valid name attribute in HTML anchors.
28 * @author Bhavesh Patel
29 * @library ../lib
30 * @modules jdk.javadoc
31 * @build JavadocTester
32 * @run main TestAnchorNames
33 */
34
35public class TestAnchorNames extends JavadocTester {
36
37    private static final String[] ARGS = new String[] {
38
39    };
40
41    public static void main(String[] args) throws Exception {
42        TestAnchorNames tester = new TestAnchorNames();
43        tester.runTests();
44    }
45
46    @Test
47    void test() {
48        javadoc("-d", "out",
49                "-sourcepath", testSrc,
50                "-source", "8", //so that '_' can be used as an identifier
51                "-use",
52                "pkg1");
53        checkExit(Exit.OK);
54
55        // Test some section markers and links to these markers
56        checkOutput("pkg1/RegClass.html", true,
57                "<a name=\"skip.navbar.top\">",
58                "<a href=\"#skip.navbar.top\" title=\"Skip navigation links\">",
59                "<a name=\"nested.class.summary\">",
60                "<a href=\"#nested.class.summary\">",
61                "<a name=\"method.summary\">",
62                "<a href=\"#method.summary\">",
63                "<a name=\"field.detail\">",
64                "<a href=\"#field.detail\">",
65                "<a name=\"constructor.detail\">",
66                "<a href=\"#constructor.detail\">");
67
68        // Test some members and link to these members
69        checkOutput("pkg1/RegClass.html", true,
70                //The marker for this appears in the serialized-form.html which we will
71                //test below
72                "<a href=\"../serialized-form.html#pkg1.RegClass\">");
73
74        // Test some fields
75        checkOutput("pkg1/RegClass.html", true,
76                "<a name=\"Z:Z_\">",
77                "<a href=\"../pkg1/RegClass.html#Z:Z_\">",
78                "<a name=\"Z:Z_:D\">",
79                "<a href=\"../pkg1/RegClass.html#Z:Z_:D\">",
80                "<a name=\"Z:Z:D_\">",
81                "<a href=\"../pkg1/RegClass.html#Z:Z:D_\">",
82                "<a name=\"Z:Z:Dfield\">",
83                "<a href=\"../pkg1/RegClass.html#Z:Z:Dfield\">",
84                "<a name=\"fieldInCla:D:D\">",
85                "<a href=\"../pkg1/RegClass.html#fieldInCla:D:D\">",
86                "<a name=\"S_:D:D:D:D:DINT\">",
87                "<a href=\"../pkg1/RegClass.html#S_:D:D:D:D:DINT\">",
88                "<a name=\"method:D:D\">",
89                "<a href=\"../pkg1/RegClass.html#method:D:D\">");
90
91        checkOutput("pkg1/DeprMemClass.html", true,
92                "<a name=\"Z:Z_field_In_Class\">",
93                "<a href=\"../pkg1/DeprMemClass.html#Z:Z_field_In_Class\">");
94
95        // Test constructor
96        checkOutput("pkg1/RegClass.html", true,
97                "<a name=\"RegClass-java.lang.String-int-\">",
98                "<a href=\"../pkg1/RegClass.html#RegClass-java.lang.String-int-\">");
99
100        // Test some methods
101        checkOutput("pkg1/RegClass.html", true,
102                "<a name=\"Z:Z_methodInClass-java.lang.String-\">",
103                "<a href=\"../pkg1/RegClass.html#Z:Z_methodInClass-java.lang.String-\">",
104                "<a name=\"method--\">",
105                "<a href=\"../pkg1/RegClass.html#method--\">",
106                "<a name=\"foo-java.util.Map-\">",
107                "<a href=\"../pkg1/RegClass.html#foo-java.util.Map-\">",
108                "<a name=\"methodInCla:Ds-java.lang.String:A-\">",
109                "<a href=\"../pkg1/RegClass.html#methodInCla:Ds-java.lang.String:A-\">",
110                "<a name=\"Z:Z_methodInClas:D-java.lang.String-int-\">",
111                "<a href=\"../pkg1/RegClass.html#Z:Z_methodInClas:D-java.lang.String-int-\">",
112                "<a name=\"methodD-pkg1.RegClass.:DA-\">",
113                "<a href=\"../pkg1/RegClass.html#methodD-pkg1.RegClass.:DA-\">",
114                "<a name=\"methodD-pkg1.RegClass.D:A-\">",
115                "<a href=\"../pkg1/RegClass.html#methodD-pkg1.RegClass.D:A-\">");
116
117        checkOutput("pkg1/DeprMemClass.html", true,
118                "<a name=\"Z:Z:Dmethod_In_Class--\">",
119                "<a href=\"../pkg1/DeprMemClass.html#Z:Z:Dmethod_In_Class--\">");
120
121        // Test enum
122        checkOutput("pkg1/RegClass.Te$t_Enum.html", true,
123                "<a name=\"Z:Z:DFLD2\">",
124                "<a href=\"../pkg1/RegClass.Te$t_Enum.html#Z:Z:DFLD2\">");
125
126        // Test nested class
127        checkOutput("pkg1/RegClass._NestedClas$.html", true,
128                "<a name=\"Z:Z_NestedClas:D--\">",
129                "<a href=\"../pkg1/RegClass._NestedClas$.html#Z:Z_NestedClas:D--\">");
130
131        // Test class use page
132        checkOutput("pkg1/class-use/DeprMemClass.html", true,
133                "<a href=\"../../pkg1/RegClass.html#d____mc\">");
134
135        // Test deprecated list page
136        checkOutput("deprecated-list.html", true,
137                "<a href=\"pkg1/DeprMemClass.html#Z:Z_field_In_Class\">",
138                "<a href=\"pkg1/DeprMemClass.html#Z:Z:Dmethod_In_Class--\">");
139
140        // Test constant values page
141        checkOutput("constant-values.html", true,
142                "<a href=\"pkg1/RegClass.html#S_:D:D:D:D:DINT\">");
143
144        // Test serialized form page
145        checkOutput("serialized-form.html", true,
146                //This is the marker for the link that appears in the pkg1.RegClass.html page
147                "<a name=\"pkg1.RegClass\">");
148
149        // Test member name index page
150        checkOutput("index-all.html", true,
151                "<a name=\"I:Z:Z:D\">",
152                "<a href=\"#I:Z:Z:D\">$",
153                "<a href=\"#I:Z:Z_\">_");
154
155        // The marker name conversion should only affect HTML anchors. It should not
156        // affect the lables.
157        checkOutput("pkg1/RegClass.html", false,
158                " Z:Z_",
159                " Z:Z:Dfield",
160                " Z:Z_field_In_Class",
161                " S_:D:D:D:D:DINT");
162    }
163}
164