Path: blob/master/test/langtools/jdk/javadoc/doclet/testAnchorNames/TestAnchorNames.java
40971 views
/*1* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 8025633 8025524 8081854 8187521 8182765 826197626* @summary Test for valid name attribute in HTML anchors.27* @library /tools/lib ../../lib28* @modules jdk.javadoc/jdk.javadoc.internal.tool29* @build toolbox.ToolBox javadoc.tester.*30* @run main TestAnchorNames31*/3233import java.io.IOException;34import java.nio.file.Path;35import java.nio.file.Paths;3637import javadoc.tester.JavadocTester;38import toolbox.ToolBox;3940public class TestAnchorNames extends JavadocTester {4142public final ToolBox tb;43public static void main(String... args) throws Exception {44TestAnchorNames tester = new TestAnchorNames();45tester.runTests(m -> new Object[] { Paths.get(m.getName()) });46}4748public TestAnchorNames() {49tb = new ToolBox();50}5152@Test53public void testHtml5(Path ignore) {54javadoc("-d", "out-html5",55"-sourcepath", testSrc,56"-source", "8", //so that '_' can be used as an identifier57"-use",58"pkg1");59checkExit(Exit.OK);6061// Test some section markers and links to these markers62checkOutput("pkg1/RegClass.html", true,63"""64<span class="skip-nav" id="skip-navbar-top">""",65"""66<a href="#skip-navbar-top" title="Skip navigation links">""",67"""68<section class="nested-class-summary" id="nested-class-summary">69<h2>Nested Class Summary</h2>""",70"<a href=\"#nested-class-summary\">",71"""72<section class="method-summary" id="method-summary">73<h2>Method Summary</h2>""",74"<a href=\"#method-summary\">",75"""76<section class="field-details" id="field-detail">77<h2>Field Details</h2>""",78"<a href=\"#field-detail\">",79"""80<section class="constructor-details" id="constructor-detail">81<h2>Constructor Details</h2>""",82"<a href=\"#constructor-detail\">");8384// Test some members and link to these members85checkOutput("pkg1/RegClass.html", true,86//The marker for this appears in the serialized-form.html which we will87//test below88"""89<a href="../serialized-form.html#pkg1.RegClass">""");9091// Test some fields92checkOutput("pkg1/RegClass.html", true,93"<section class=\"detail\" id=\"_\">",94"<a href=\"#_\" class=\"member-name-link\">",95"<section class=\"detail\" id=\"_$\">",96"<a href=\"#_$\" class=\"member-name-link\">",97"<section class=\"detail\" id=\"$_\">",98"<a href=\"#$_\" class=\"member-name-link\">",99"""100<section class="detail" id="$field">""",101"<a href=\"#$field\" class=\"member-name-link\">",102"""103<section class="detail" id="fieldInCla$$">""",104"<a href=\"#fieldInCla$$\" class=\"member-name-link\">",105"""106<section class="detail" id="S_$$$$$INT">""",107"<a href=\"#S_$$$$$INT\" class=\"member-name-link\">",108"""109<section class="detail" id="method$$">""",110"<a href=\"#method$$\" class=\"member-name-link\">");111112checkOutput("pkg1/DeprMemClass.html", true,113"""114<section class="detail" id="_field_In_Class">""",115"<a href=\"#_field_In_Class\" class=\"member-name-link\">");116117// Test constructor118checkOutput("pkg1/RegClass.html", true,119"""120<section class="detail" id="<init>(java.lang.String,int)">""",121"""122<a href="#%3Cinit%3E(java.lang.String,int)" class="member-name-link">""");123124// Test some methods125checkOutput("pkg1/RegClass.html", true,126"""127<section class="detail" id="_methodInClass(java.lang.String)">""",128"""129<a href="#_methodInClass(java.lang.String)" class="member-name-link">""",130"""131<section class="detail" id="method()">""",132"<a href=\"#method()\" class=\"member-name-link\">",133"""134<section class="detail" id="foo(java.util.Map)">""",135"<a href=\"#foo(java.util.Map)\" class=\"member-name-link\">",136"""137<section class="detail" id="methodInCla$s(java.lang.String[])">""",138"""139<a href="#methodInCla$s(java.lang.String%5B%5D)" class="member-name-link">""",140"""141<section class="detail" id="_methodInClas$(java.lang.String,int)">""",142"""143<a href="#_methodInClas$(java.lang.String,int)" class="member-name-link">""",144"""145<section class="detail" id="methodD(pkg1.RegClass.$A)">""",146"""147<a href="#methodD(pkg1.RegClass.$A)" class="member-name-link">""",148"""149<section class="detail" id="methodD(pkg1.RegClass.D[])">""",150"""151<a href="#methodD(pkg1.RegClass.D%5B%5D)" class="member-name-link">""");152153checkOutput("pkg1/DeprMemClass.html", true,154"""155<section class="detail" id="$method_In_Class()">""",156"<a href=\"#$method_In_Class()\" class=\"member-name-link\">");157158// Test enum159checkOutput("pkg1/RegClass.Te$t_Enum.html", true,160"""161<section class="detail" id="$FLD2">""",162"<a href=\"#$FLD2\" class=\"member-name-link\">");163164// Test nested class165checkOutput("pkg1/RegClass._NestedClas$.html", true,166"""167<section class="detail" id="<init>()">""",168"<a href=\"#%3Cinit%3E()\" class=\"member-name-link\">");169170// Test class use page171checkOutput("pkg1/class-use/DeprMemClass.html", true,172"""173<a href="../RegClass.html#d____mc" class="member-name-link">""");174175// Test deprecated list page176checkOutput("deprecated-list.html", true,177"""178<a href="pkg1/DeprMemClass.html#_field_In_Class">""",179"""180<a href="pkg1/DeprMemClass.html#$method_In_Class()">""");181182// Test constant values page183checkOutput("constant-values.html", true,184"""185<a href="pkg1/RegClass.html#S_$$$$$INT">""");186187// Test serialized form page188checkOutput("serialized-form.html", true,189//This is the marker for the link that appears in the pkg1.RegClass.html page190"""191<section class="serialized-class-details" id="pkg1.RegClass">""");192193// Test member name index page194checkOutput("index-all.html", true,195"""196<h2 class="title" id="I:$">$</h2>""",197"<a href=\"#I:$\">$",198"<a href=\"#I:_\">_");199}200201/**202* The following test is somewhat simplistic, but it is useful203* in conjunction with the W3C Validation Service at https://validator.w3.org/nu/#file204* @param base A working directory for this method, in which some UTF-8 source files205* will be generated206* @throws IOException if there is a problem generating the source files207*/208@Test209public void testNonAscii(Path base) throws IOException {210Path src = base.resolve("src");211tb.writeJavaFiles(src,212"package p; public class Def {\n"213+ " public int \u00e0\u00e9;\n" // a`e'214+ " public void \u00c0\u00c9() { }\n" // A`E'215+ " public int \u03b1\u03b2\u03b3;\n" // alpha beta gamma216+ " public void \u0391\u0392\u0393() { }\n" // ALPHA BETA GAMMA217+ "}",218"package p; \n"219+ "/**\n"220+ " * {@link Def#\u00e0\u00e9 àé}<br>\n"221+ " * {@link Def#\u00c0\u00c9() ÀÉ}<br>\n"222+ " * {@link Def#\u03b1\u03b2\u03b3 αβγ}<br>\n"223+ " * {@link Def#\u0391\u0392\u0393() ΑΒΓ}<br>\n"224+ " */\n"225+ "public class Ref { }");226227javadoc("-d", "out-nonAscii",228"-sourcepath", src.toString(),229"-html5",230"-encoding", "utf-8",231"p");232checkExit(Exit.OK);233234checkOutput("p/Def.html", true,235"<section class=\"detail\" id=\"\u00e0\u00e9\">",236"<section class=\"detail\" id=\"\u00c0\u00c9()\">",237"<section class=\"detail\" id=\"\u03b1\u03b2\u03b3\">",238"<section class=\"detail\" id=\"\u0391\u0392\u0393()\">");239240checkOutput("p/Ref.html", true,241"""242<a href="Def.html#%C3%A0%C3%A9"><code>àé</code></a>""",243"""244<a href="Def.html#%C3%80%C3%89()"><code>ÀÉ</code></a>""",245"""246<a href="Def.html#%CE%B1%CE%B2%CE%B3"><code>αβγ</code></a>""",247"""248<a href="Def.html#%CE%91%CE%92%CE%93()"><code>ΑΒΓ</code></a>""");249250}251}252253254