1 /* |
|
2 * Copyright (c) 2011, 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 6227454 |
|
27 * @summary package.html and overview.html may not be read fully |
|
28 * @modules jdk.javadoc |
|
29 */ |
|
30 |
|
31 import java.io.*; |
|
32 |
|
33 import com.sun.javadoc.Doclet; |
|
34 import com.sun.javadoc.RootDoc; |
|
35 |
|
36 public class Test extends Doclet { |
|
37 public static void main(String... args) throws Exception { |
|
38 new Test().run(); |
|
39 } |
|
40 |
|
41 void run() throws Exception { |
|
42 test("<body>ABC XYZ</body>"); |
|
43 test("<body>ABC XYZ</BODY>"); |
|
44 test("<BODY>ABC XYZ</body>"); |
|
45 test("<BODY>ABC XYZ</BODY>"); |
|
46 test("<BoDy>ABC XYZ</bOdY>"); |
|
47 test(" ABC XYZ</bOdY>", "Body tag missing from HTML"); |
|
48 test("<body>ABC XYZ ", "Close body tag missing from HTML"); |
|
49 test(" ABC XYZ ", "Body tag missing from HTML"); |
|
50 test("<body>ABC" + bigText(8192, 40) + "XYZ</body>"); |
|
51 |
|
52 if (errors > 0) |
|
53 throw new Exception(errors + " errors occurred"); |
|
54 } |
|
55 |
|
56 void test(String body) throws IOException { |
|
57 test(body, null); |
|
58 } |
|
59 |
|
60 void test(String body, String expectError) throws IOException { |
|
61 String docType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" " |
|
62 + "\"http://www.w3.org/TR/html4/loose.dtd\">"; |
|
63 String headTag = "<head><title>Title </title></head>"; |
|
64 String text = docType + "<html>" + headTag + body + "</html>"; |
|
65 testNum++; |
|
66 System.err.println("test " + testNum); |
|
67 File file = writeFile("overview" + testNum + ".html", text); |
|
68 String thisClassName = Test.class.getName(); |
|
69 File testSrc = new File(System.getProperty("test.src")); |
|
70 String[] args = { |
|
71 "-classpath", ".", |
|
72 "-package", |
|
73 "-overview", file.getPath(), |
|
74 new File(testSrc, thisClassName + ".java").getPath() |
|
75 }; |
|
76 |
|
77 StringWriter sw = new StringWriter(); |
|
78 PrintWriter pw = new PrintWriter(sw); |
|
79 int rc = com.sun.tools.javadoc.Main.execute( |
|
80 "javadoc", |
|
81 pw, pw, pw, |
|
82 thisClassName, |
|
83 args); |
|
84 pw.close(); |
|
85 String out = sw.toString(); |
|
86 if (!out.isEmpty()) |
|
87 System.err.println(out); |
|
88 System.err.println("javadoc exit: rc=" + rc); |
|
89 |
|
90 if (expectError == null) { |
|
91 if (rc != 0) |
|
92 error("unexpected exit from javadoc; rc:" + rc); |
|
93 } else { |
|
94 if (!out.contains(expectError)) |
|
95 error("expected error text not found: " + expectError); |
|
96 } |
|
97 } |
|
98 |
|
99 String bigText(int lines, int lineLength) { |
|
100 StringBuilder sb = new StringBuilder(); |
|
101 for (int i = 0; i < lineLength; i++) |
|
102 sb.append(String.valueOf(i % 10)); |
|
103 sb.append("\n"); |
|
104 String line = sb.toString(); |
|
105 sb.setLength(0); |
|
106 for (int i = 0; i < lines; i++) |
|
107 sb.append(line); |
|
108 return sb.toString(); |
|
109 } |
|
110 |
|
111 File writeFile(String path, String body) throws IOException { |
|
112 File f = new File(path); |
|
113 FileWriter out = new FileWriter(f); |
|
114 try { |
|
115 out.write(body); |
|
116 } finally { |
|
117 out.close(); |
|
118 } |
|
119 return f; |
|
120 } |
|
121 |
|
122 void error(String msg) { |
|
123 System.err.println("Error: " + msg); |
|
124 errors++; |
|
125 } |
|
126 |
|
127 int testNum; |
|
128 int errors; |
|
129 |
|
130 public static boolean start(RootDoc root) { |
|
131 String text = root.commentText(); |
|
132 if (text.length() < 64) |
|
133 System.err.println("text: '" + text + "'"); |
|
134 else |
|
135 System.err.println("text: '" |
|
136 + text.substring(0, 20) |
|
137 + "..." |
|
138 + text.substring(text.length() - 20) |
|
139 + "'"); |
|
140 return text.startsWith("ABC") && text.endsWith("XYZ"); |
|
141 } |
|
142 } |
|