11/*
2- * Copyright (c) 2003, 2019 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2003, 2021 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2323
2424/*
2525 * @test
26- * @bug 4460354 8014636 8043186 8195805 8182765 8196202
26+ * @bug 4460354 8014636 8043186 8195805 8182765 8196202 8262886
2727 * @summary Test to make sure that relative paths are redirected in the
2828 * output so that they are not broken.
2929 * @library ../../lib
@@ -46,77 +46,157 @@ public static void main(String... args) throws Exception {
4646 }
4747
4848 @ Test
49- public void test () {
49+ public void testRelativeLinks () {
5050 javadoc ("-d" , "out" ,
5151 "-use" ,
5252 "-sourcepath" , testSrc ,
53- "pkg" , "pkg2" );
54- checkExit (Exit .ERROR );
55-
56- checkOutput (Output .OUT , true ,
57- "attribute not supported in HTML5: name" );
53+ "pkg" , "pkg2" , "pkg.sub" );
54+ checkExit (Exit .OK );
5855
5956 // These relative paths should stay relative because they appear
6057 // in the right places.
6158 checkOutput ("pkg/C.html" , true ,
6259 """
6360 <a href="relative-class-link.html">relative class link</a>""" ,
61+ """
62+ <a href="#class-fragment">fragment class link</a>""" ,
63+ """
64+ <a id="class-fragment">Class fragment</a>""" ,
6465 """
6566 <a href="relative-field-link.html">relative field link</a>""" ,
6667 """
6768 <a href="relative-method-link.html">relative method link</a>""" ,
6869 """
69- \s <a href="relative-multi-line-link.html">relative-multi-line-link</a>.""" );
70+ <a href="#method-fragment">fragment method link</a>""" ,
71+ """
72+ <a href="relative-multi-line-link.html">relative-multi-line-link</a>""" );
73+
7074 checkOutput ("pkg/package-summary.html" , true ,
7175 """
72- <a href="relative-package-link.html">relative package link</a>""" );
76+ <a href="relative-package-link.html">relative package link</a>""" ,
77+ """
78+ <a href="#package-fragment">package fragment link</a>""" ,
79+ """
80+ <a id="package-fragment">Package fragment</a>""" ,
81+ """
82+ <a href="relative-class-link.html">relative class link</a>""" ,
83+ """
84+ <a href="C.html#class-fragment">fragment class link</a>""" );
85+
86+ // subclass in same pacakge
87+ checkOutput ("pkg/D.html" , true ,
88+ """
89+ <a href="relative-class-link.html">relative class link</a>""" ,
90+ """
91+ <a href="C.html#class-fragment">fragment class link</a>""" ,
92+ """
93+ <a href="relative-method-link.html">relative method link</a>""" ,
94+ """
95+ <a href="C.html#method-fragment">fragment method link</a>""" );
7396
7497 // These relative paths should be redirected because they are in different
7598 // places.
7699
100+ // subclass in subpackage
101+ checkOutput ("pkg/sub/F.html" , true ,
102+ """
103+ <a href="../../pkg/relative-class-link.html">relative class link</a>""" ,
104+ """
105+ <a href="../../pkg/C.html#class-fragment">fragment class link</a>""" ,
106+ """
107+ <a href="../../pkg/relative-method-link.html">relative method link</a>""" ,
108+ """
109+ <a href="../../pkg/C.html#method-fragment">fragment method link</a>""" );
110+
77111 // INDEX PAGE
78112 checkOutput ("index-all.html" , true ,
79113 """
80114 <a href="./pkg/relative-class-link.html">relative class link</a>""" ,
115+ """
116+ <a href="./pkg/C.html#class-fragment">fragment class link</a>""" ,
81117 """
82118 <a href="./pkg/relative-field-link.html">relative field link</a>""" ,
83119 """
84120 <a href="./pkg/relative-method-link.html">relative method link</a>""" ,
121+ """
122+ <a href="./pkg/C.html#method-fragment">fragment method link</a>""" ,
85123 """
86124 <a href="./pkg/relative-package-link.html">relative package link</a>""" ,
87125 """
88- \s <a href="./pkg/relative-multi-line-link.html">relative-multi-line-link</a>. """ );
126+ <a href="./pkg/relative-multi-line-link.html">relative-multi-line-link</a>""" );
89127
90128 // This is not a relative path and should not be redirected.
91129 checkOutput ("index-all.html" , true ,
92130 """
93- <div class="block"><a name ="masters"></a>""" );
131+ <div class="block"><a id ="masters"></a>""" );
94132 checkOutput ("index-all.html" , false ,
95133 """
96- <div class="block"><a name ="./pkg/masters"></a>""" );
134+ <div class="block"><a id ="./pkg/masters"></a>""" );
97135
98136 // PACKAGE USE
99137 checkOutput ("pkg/package-use.html" , true ,
100138 """
101- <a href="../pkg/relative-package-link.html">relative package link</a>.""" ,
139+ <a href="../pkg/relative-package-link.html">relative package link</a>""" ,
140+ """
141+ <a href="../pkg/package-summary.html#package-fragment">package fragment link</a>""" ,
102142 """
103- <a href="../pkg/relative-class-link.html">relative class link</a>""" );
143+ <a href="../pkg/relative-class-link.html">relative class link</a>""" ,
144+ """
145+ <a href="../pkg/C.html#class-fragment">fragment class link</a>""" );
104146
105147 // CLASS_USE
106148 checkOutput ("pkg/class-use/C.html" , true ,
149+ """
150+ <a href="../../pkg/relative-class-link.html">relative class link</a>""" ,
151+ """
152+ <a href="../../pkg/C.html#class-fragment">fragment class link</a>""" ,
107153 """
108154 <a href="../../pkg/relative-field-link.html">relative field link</a>""" ,
109155 """
110156 <a href="../../pkg/relative-method-link.html">relative method link</a>""" ,
157+ """
158+ <a href="../../pkg/C.html#method-fragment">fragment method link</a>""" ,
111159 """
112160 <a href="../../pkg/relative-package-link.html">relative package link</a>""" ,
113161 """
114- \s <a href="../../pkg/relative-multi-line-link.html">relative-multi-line-link</a>. """ );
162+ <a href="../../pkg/relative-multi-line-link.html">relative-multi-line-link</a>""" );
115163
116164 // PACKAGE OVERVIEW
117165 checkOutput ("index.html" , true ,
118166 """
119167 <a href="./pkg/relative-package-link.html">relative package link</a>""" );
168+
169+ // subpackage summary
170+ checkOutput ("pkg/sub/package-summary.html" , true ,
171+ // related packages
172+ """
173+ <a href="../../pkg/relative-package-link.html">relative package link</a>""" ,
174+ """
175+ <a href="../../pkg/package-summary.html#package-fragment">package fragment link</a>""" ,
176+ // subclass inheriting relative link doc
177+ """
178+ <a href="../../pkg/relative-class-link.html">relative class link</a>""" ,
179+ """
180+ <a href="../../pkg/C.html#class-fragment">fragment class link</a>""" );
181+
182+ // sibling package summary
183+ checkOutput ("pkg2/package-summary.html" , true ,
184+ """
185+ <a href="../pkg/relative-class-link.html">relative class link</a>""" ,
186+ """
187+ <a href="../pkg/C.html#class-fragment">fragment class link</a>""" );
188+ }
189+
190+ @ Override
191+ public void checkLinks () {
192+ // since the test uses explicit links to non-existent files,
193+ // we create those files to avoid false positive errors from checkLinks
194+ touch ("pkg/relative-class-link.html" );
195+ touch ("pkg/relative-field-link.html" );
196+ touch ("pkg/relative-method-link.html" );
197+ touch ("pkg/relative-package-link.html" );
198+ touch ("pkg/relative-multi-line-link.html" );
199+ super .checkLinks ();
120200 }
121201
122202 private void touch (String file ) {
0 commit comments