File: TestAnchorNames.java

package info (click to toggle)
openjdk-11 11.0.4%2B11-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 757,028 kB
  • sloc: java: 5,016,041; xml: 1,191,974; cpp: 934,731; ansic: 555,697; sh: 24,299; objc: 12,703; python: 3,602; asm: 3,415; makefile: 2,772; awk: 351; sed: 172; perl: 114; jsp: 24; csh: 3
file content (330 lines) | stat: -rw-r--r-- 13,634 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/*
 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

/*
 * @test
 * @bug 8025633 8025524 8081854 8187521 8182765
 * @summary Test for valid name attribute in HTML anchors.
 * @author Bhavesh Patel
 * @library /tools/lib ../lib
 * @modules jdk.javadoc/jdk.javadoc.internal.tool
 * @build toolbox.ToolBox JavadocTester
 * @run main TestAnchorNames
 */

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

import toolbox.*;

public class TestAnchorNames extends JavadocTester {

    public final ToolBox tb;
    public static void main(String... args) throws Exception {
        TestAnchorNames tester = new TestAnchorNames();
        tester.runTests(m -> new Object[] { Paths.get(m.getName()) });
    }

    public TestAnchorNames() {
        tb = new ToolBox();
    }

    @Test
    void testHtml4(Path ignore) {
        setAutomaticCheckLinks(false); // @ignore JDK-8202622
        javadoc("-d", "out-html4",
                "-html4",
                "-sourcepath", testSrc,
                "-source", "8", //so that '_' can be used as an identifier
                "-use",
                "pkg1");
        setAutomaticCheckLinks(true); // @ignore JDK-8202622
        checkExit(Exit.OK);

        // Test some section markers and links to these markers
        checkOutput("pkg1/RegClass.html", true,
                "<a name=\"skip.navbar.top\">",
                "<a href=\"#skip.navbar.top\" title=\"Skip navigation links\">",
                "<a name=\"nested.class.summary\">",
                "<a href=\"#nested.class.summary\">",
                "<a name=\"method.summary\">",
                "<a href=\"#method.summary\">",
                "<a name=\"field.detail\">",
                "<a href=\"#field.detail\">",
                "<a name=\"constructor.detail\">",
                "<a href=\"#constructor.detail\">");

        // Test some members and link to these members
        checkOutput("pkg1/RegClass.html", true,
                //The marker for this appears in the serialized-form.html which we will
                //test below
                "<a href=\"../serialized-form.html#pkg1.RegClass\">");

        // Test some fields
        checkOutput("pkg1/RegClass.html", true,
                "<a name=\"Z:Z_\">",
                "<a href=\"#Z:Z_\">",
                "<a name=\"Z:Z_:D\">",
                "<a href=\"#Z:Z_:D\">",
                "<a name=\"Z:Z:D_\">",
                "<a href=\"#Z:Z:D_\">",
                "<a name=\"Z:Z:Dfield\">",
                "<a href=\"#Z:Z:Dfield\">",
                "<a name=\"fieldInCla:D:D\">",
                "<a href=\"#fieldInCla:D:D\">",
                "<a name=\"S_:D:D:D:D:DINT\">",
                "<a href=\"#S_:D:D:D:D:DINT\">",
                "<a name=\"method:D:D\">",
                "<a href=\"#method:D:D\">");

        checkOutput("pkg1/DeprMemClass.html", true,
                "<a name=\"Z:Z_field_In_Class\">",
                "<a href=\"#Z:Z_field_In_Class\">");

        // Test constructor
        checkOutput("pkg1/RegClass.html", true,
                "<a name=\"RegClass-java.lang.String-int-\">",
                "<a href=\"#RegClass-java.lang.String-int-\">");

        // Test some methods
        checkOutput("pkg1/RegClass.html", true,
                "<a name=\"Z:Z_methodInClass-java.lang.String-\">",
                "<a href=\"#Z:Z_methodInClass-java.lang.String-\">",
                "<a name=\"method--\">",
                "<a href=\"#method--\">",
                "<a name=\"foo-java.util.Map-\">",
                "<a href=\"#foo-java.util.Map-\">",
                "<a name=\"methodInCla:Ds-java.lang.String:A-\">",
                "<a href=\"#methodInCla:Ds-java.lang.String:A-\">",
                "<a name=\"Z:Z_methodInClas:D-java.lang.String-int-\">",
                "<a href=\"#Z:Z_methodInClas:D-java.lang.String-int-\">",
                "<a name=\"methodD-pkg1.RegClass.:DA-\">",
                "<a href=\"#methodD-pkg1.RegClass.:DA-\">",
                "<a name=\"methodD-pkg1.RegClass.D:A-\">",
                "<a href=\"#methodD-pkg1.RegClass.D:A-\">");

        checkOutput("pkg1/DeprMemClass.html", true,
                "<a name=\"Z:Z:Dmethod_In_Class--\">",
                "<a href=\"#Z:Z:Dmethod_In_Class--\">");

        // Test enum
        checkOutput("pkg1/RegClass.Te$t_Enum.html", true,
                "<a name=\"Z:Z:DFLD2\">",
                "<a href=\"#Z:Z:DFLD2\">");

        // Test nested class
        checkOutput("pkg1/RegClass._NestedClas$.html", true,
                "<a name=\"Z:Z_NestedClas:D--\">",
                "<a href=\"#Z:Z_NestedClas:D--\">");

        // Test class use page
        checkOutput("pkg1/class-use/DeprMemClass.html", true,
                "<a href=\"../RegClass.html#d____mc\">");

        // Test deprecated list page
        checkOutput("deprecated-list.html", true,
                "<a href=\"pkg1/DeprMemClass.html#Z:Z_field_In_Class\">",
                "<a href=\"pkg1/DeprMemClass.html#Z:Z:Dmethod_In_Class--\">");

        // Test constant values page
        checkOutput("constant-values.html", true,
                "<a href=\"pkg1/RegClass.html#S_:D:D:D:D:DINT\">");

        // Test serialized form page
        checkOutput("serialized-form.html", true,
                //This is the marker for the link that appears in the pkg1.RegClass.html page
                "<a name=\"pkg1.RegClass\">");

        // Test member name index page
        checkOutput("index-all.html", true,
                "<a name=\"I:Z:Z:D\">",
                "<a href=\"#I:Z:Z:D\">$",
                "<a href=\"#I:Z:Z_\">_");

        // The marker name conversion should only affect HTML anchors. It should not
        // affect the labels.
        checkOutput("pkg1/RegClass.html", false,
                " Z:Z_",
                " Z:Z:Dfield",
                " Z:Z_field_In_Class",
                " S_:D:D:D:D:DINT");
    }

    @Test
    void testHtml5(Path ignore) {
        javadoc("-d", "out-html5",
                "-sourcepath", testSrc,
                "-source", "8", //so that '_' can be used as an identifier
                "-use",
                "pkg1");
        checkExit(Exit.OK);

        // Test some section markers and links to these markers
        checkOutput("pkg1/RegClass.html", true,
                "<a id=\"skip.navbar.top\">",
                "<a href=\"#skip.navbar.top\" title=\"Skip navigation links\">",
                "<a id=\"nested.class.summary\">",
                "<a href=\"#nested.class.summary\">",
                "<a id=\"method.summary\">",
                "<a href=\"#method.summary\">",
                "<a id=\"field.detail\">",
                "<a href=\"#field.detail\">",
                "<a id=\"constructor.detail\">",
                "<a href=\"#constructor.detail\">");

        // Test some members and link to these members
        checkOutput("pkg1/RegClass.html", true,
                //The marker for this appears in the serialized-form.html which we will
                //test below
                "<a href=\"../serialized-form.html#pkg1.RegClass\">");

        // Test some fields
        checkOutput("pkg1/RegClass.html", true,
                "<a id=\"_\">",
                "<a href=\"#_\">",
                "<a id=\"_$\">",
                "<a href=\"#_$\">",
                "<a id=\"$_\">",
                "<a href=\"#$_\">",
                "<a id=\"$field\">",
                "<a href=\"#$field\">",
                "<a id=\"fieldInCla$$\">",
                "<a href=\"#fieldInCla$$\">",
                "<a id=\"S_$$$$$INT\">",
                "<a href=\"#S_$$$$$INT\">",
                "<a id=\"method$$\">",
                "<a href=\"#method$$\">");

        checkOutput("pkg1/DeprMemClass.html", true,
                "<a id=\"_field_In_Class\">",
                "<a href=\"#_field_In_Class\">");

        // Test constructor
        checkOutput("pkg1/RegClass.html", true,
                "<a id=\"&lt;init&gt;(java.lang.String,int)\">",
                "<a href=\"#%3Cinit%3E(java.lang.String,int)\">");

        // Test some methods
        checkOutput("pkg1/RegClass.html", true,
                "<a id=\"_methodInClass(java.lang.String)\">",
                "<a href=\"#_methodInClass(java.lang.String)\">",
                "<a id=\"method()\">",
                "<a href=\"#method()\">",
                "<a id=\"foo(java.util.Map)\">",
                "<a href=\"#foo(java.util.Map)\">",
                "<a id=\"methodInCla$s(java.lang.String[])\">",
                "<a href=\"#methodInCla$s(java.lang.String%5B%5D)\">",
                "<a id=\"_methodInClas$(java.lang.String,int)\">",
                "<a href=\"#_methodInClas$(java.lang.String,int)\">",
                "<a id=\"methodD(pkg1.RegClass.$A)\">",
                "<a href=\"#methodD(pkg1.RegClass.$A)\">",
                "<a id=\"methodD(pkg1.RegClass.D[])\">",
                "<a href=\"#methodD(pkg1.RegClass.D%5B%5D)\">");

        checkOutput("pkg1/DeprMemClass.html", true,
                "<a id=\"$method_In_Class()\">",
                "<a href=\"#$method_In_Class()\">");

        // Test enum
        checkOutput("pkg1/RegClass.Te$t_Enum.html", true,
                "<a id=\"$FLD2\">",
                "<a href=\"#$FLD2\">");

        // Test nested class
        checkOutput("pkg1/RegClass._NestedClas$.html", true,
                "<a id=\"&lt;init&gt;()\">",
                "<a href=\"#%3Cinit%3E()\">");

        // Test class use page
        checkOutput("pkg1/class-use/DeprMemClass.html", true,
                "<a href=\"../RegClass.html#d____mc\">");

        // Test deprecated list page
        checkOutput("deprecated-list.html", true,
                "<a href=\"pkg1/DeprMemClass.html#_field_In_Class\">",
                "<a href=\"pkg1/DeprMemClass.html#$method_In_Class()\">");

        // Test constant values page
        checkOutput("constant-values.html", true,
                "<a href=\"pkg1/RegClass.html#S_$$$$$INT\">");

        // Test serialized form page
        checkOutput("serialized-form.html", true,
                //This is the marker for the link that appears in the pkg1.RegClass.html page
                "<a id=\"pkg1.RegClass\">");

        // Test member name index page
        checkOutput("index-all.html", true,
                "<a id=\"I:$\">",
                "<a href=\"#I:$\">$",
                "<a href=\"#I:_\">_");
    }

    /**
     * The following test is somewhat simplistic, but it is useful
     * in conjunction with the W3C Validation Service at https://validator.w3.org/nu/#file
     * @param base A working directory for this method, in which some UTF-8 source files
     *      will be generated
     * @throws IOException if there is a problem generating the source files
     */
    @Test
    void testNonAscii(Path base) throws IOException {
        Path src = base.resolve("src");
        tb.writeJavaFiles(src,
                "package p; public class Def {\n"
                + "    public int \u00e0\u00e9;\n"              // a`e'
                + "    public void \u00c0\u00c9() { }\n"        // A`E'
                + "    public int \u03b1\u03b2\u03b3;\n"        // alpha beta gamma
                + "    public void \u0391\u0392\u0393() { }\n"  // ALPHA BETA GAMMA
                + "}",
                "package p; \n"
                + "/**\n"
                + " * {@link Def#\u00e0\u00e9 &agrave;&eacute;}<br>\n"
                + " * {@link Def#\u00c0\u00c9() &Agrave;&Eacute;}<br>\n"
                + " * {@link Def#\u03b1\u03b2\u03b3 &alpha;&beta;&gamma;}<br>\n"
                + " * {@link Def#\u0391\u0392\u0393() &Alpha;&Beta;&Gamma;}<br>\n"
                + " */\n"
                + "public class Ref { }");

        javadoc("-d", "out-nonAscii",
                "-sourcepath", src.toString(),
                "-html5",
                "-encoding", "utf-8",
                "p");
        checkExit(Exit.OK);

        checkOutput("p/Def.html", true,
                "<a id=\"\u00e0\u00e9\">",
                "<a id=\"\u00c0\u00c9()\">",
                "<a id=\"\u03b1\u03b2\u03b3\">",
                "<a id=\"\u0391\u0392\u0393()\">");

        checkOutput("p/Ref.html", true,
                "<a href=\"Def.html#%C3%A0%C3%A9\"><code>&agrave;&eacute;</code></a>",
                "<a href=\"Def.html#%C3%80%C3%89()\"><code>&Agrave;&Eacute;</code></a>",
                "<a href=\"Def.html#%CE%B1%CE%B2%CE%B3\"><code>&alpha;&beta;&gamma;</code></a>",
                "<a href=\"Def.html#%CE%91%CE%92%CE%93()\"><code>&Alpha;&Beta;&Gamma;</code></a>");

    }
}