test/tools/javadoc/6227454/Test.java

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

mercurial