|
1 /* |
|
2 * Copyright (c) 2018, 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 8195796 |
|
27 * @summary Add normalize and relative methods to DocPath |
|
28 * @library /tools/lib |
|
29 * @modules jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.util |
|
30 * @build toolbox.TestRunner |
|
31 * @run main TestDocPaths |
|
32 */ |
|
33 |
|
34 import jdk.javadoc.internal.doclets.toolkit.util.DocPath; |
|
35 import toolbox.TestRunner; |
|
36 |
|
37 public class TestDocPaths extends TestRunner { |
|
38 |
|
39 public static void main(String... args) throws Exception { |
|
40 TestDocPaths tester = new TestDocPaths(); |
|
41 tester.runTests(); |
|
42 } |
|
43 |
|
44 TestDocPaths() { |
|
45 super(System.err); |
|
46 } |
|
47 |
|
48 @Test |
|
49 public void testNormalize() { |
|
50 testNormalize("", ""); |
|
51 testNormalize(".", ""); |
|
52 testNormalize("a/b", "a/b"); |
|
53 testNormalize("a//b", "a/b"); |
|
54 testNormalize("./b", "b"); |
|
55 testNormalize("a/.", "a"); |
|
56 testNormalize("a/./b", "a/b"); |
|
57 testNormalize("../b", "../b"); |
|
58 testNormalize("a/..", ""); |
|
59 testNormalize("a/../b", "b"); |
|
60 testNormalize("a/../../b", "../b"); |
|
61 testNormalize("a/./../b", "b"); |
|
62 testNormalize("./../b", "../b"); |
|
63 testNormalize("a/./../b", "b"); |
|
64 } |
|
65 |
|
66 private void testNormalize(String p, String expect) { |
|
67 out.println("test " + p); |
|
68 String found = DocPath.create(p).normalize().getPath(); |
|
69 out.println(" result: " + found); |
|
70 if (!expect.equals(found)) { |
|
71 error("Mismatch:\n" |
|
72 + " expect: " + expect); |
|
73 } |
|
74 out.println(); |
|
75 } |
|
76 |
|
77 @Test |
|
78 public void testRelativize() { |
|
79 testRelativize("a/b/c/file.html", "file.html", ""); |
|
80 testRelativize("a/b/c/file.html", "file2.html", "file2.html"); |
|
81 testRelativize("a/b/c/file.html", "../../../a/b/file.html", "../file.html"); |
|
82 testRelativize("a/b/c/file.html", "../../../a/b/c/file.html", ""); |
|
83 testRelativize("a/b/c/file.html", "../../../a/b/c2/file.html", "../c2/file.html"); |
|
84 testRelativize("a/b/c/file.html", "../../../a/b/c/d/file.html", "d/file.html"); |
|
85 } |
|
86 |
|
87 private void testRelativize(String file, String href, String expect) { |
|
88 out.println("test " + file + " " + href); |
|
89 String found = DocPath.create(file) |
|
90 .relativize(DocPath.create(href)) |
|
91 .getPath(); |
|
92 out.println(" result: " + found); |
|
93 if (!expect.equals(found)) { |
|
94 error("Mismatch:\n" |
|
95 + " expect: " + expect); |
|
96 } |
|
97 out.println(); |
|
98 } |
|
99 } |