Path: blob/jdk8u272-b10-aarch32-20201026/langtools/test/tools/javadoc/6227454/Test.java
48788 views
/*1* Copyright (c) 2011, 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 622745426* @summary package.html and overview.html may not be read fully27*/2829import java.io.*;3031import com.sun.javadoc.Doclet;32import com.sun.javadoc.RootDoc;3334public class Test extends Doclet {35public static void main(String... args) throws Exception {36new Test().run();37}3839void run() throws Exception {40test("<html><body>ABC XYZ</body></html>");41test("<html><body>ABC XYZ</BODY></html>");42test("<html><BODY>ABC XYZ</body></html>");43test("<html><BODY>ABC XYZ</BODY></html>");44test("<html><BoDy>ABC XYZ</bOdY></html>");45test("<html> ABC XYZ</bOdY></html>", "Body tag missing from HTML");46test("<html><body>ABC XYZ </html>", "Close body tag missing from HTML");47test("<html> ABC XYZ </html>", "Body tag missing from HTML");48test("<html><body>ABC" + bigText(8192, 40) + "XYZ</body></html>");4950if (errors > 0)51throw new Exception(errors + " errors occurred");52}5354void test(String text) throws IOException {55test(text, null);56}5758void test(String text, String expectError) throws IOException {59testNum++;60System.err.println("test " + testNum);61File file = writeFile("overview" + testNum + ".html", text);62String thisClassName = Test.class.getName();63File testSrc = new File(System.getProperty("test.src"));64String[] args = {65"-bootclasspath",66System.getProperty("java.class.path")67+ File.pathSeparator68+ System.getProperty("sun.boot.class.path"),69"-classpath", ".",70"-package",71"-overview", file.getPath(),72new File(testSrc, thisClassName + ".java").getPath()73};7475StringWriter sw = new StringWriter();76PrintWriter pw = new PrintWriter(sw);77int rc = com.sun.tools.javadoc.Main.execute(78"javadoc",79pw, pw, pw,80thisClassName,81args);82pw.close();83String out = sw.toString();84if (!out.isEmpty())85System.err.println(out);86System.err.println("javadoc exit: rc=" + rc);8788if (expectError == null) {89if (rc != 0)90error("unexpected exit from javadoc; rc:" + rc);91} else {92if (!out.contains(expectError))93error("expected error text not found: " + expectError);94}95}9697String bigText(int lines, int lineLength) {98StringBuilder sb = new StringBuilder();99for (int i = 0; i < lineLength; i++)100sb.append(String.valueOf(i % 10));101sb.append("\n");102String line = sb.toString();103sb.setLength(0);104for (int i = 0; i < lines; i++)105sb.append(line);106return sb.toString();107}108109File writeFile(String path, String body) throws IOException {110File f = new File(path);111FileWriter out = new FileWriter(f);112try {113out.write(body);114} finally {115out.close();116}117return f;118}119120void error(String msg) {121System.err.println("Error: " + msg);122errors++;123}124125int testNum;126int errors;127128public static boolean start(RootDoc root) {129String text = root.commentText();130if (text.length() < 64)131System.err.println("text: '" + text + "'");132else133System.err.println("text: '"134+ text.substring(0, 20)135+ "..."136+ text.substring(text.length() - 20)137+ "'");138return text.startsWith("ABC") && text.endsWith("XYZ");139}140}141142143