test/tools/javadoc/6227454/Test.java

changeset 911
4ee7de0684f5
parent 0
959103a6100f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javadoc/6227454/Test.java	Fri Mar 04 19:56:02 2011 -0800
     1.3 @@ -0,0 +1,141 @@
     1.4 +/*
     1.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test
    1.29 + * @bug 6227454
    1.30 + * @summary package.html and overview.html may not be read fully
    1.31 + */
    1.32 +
    1.33 +import java.io.*;
    1.34 +
    1.35 +import com.sun.javadoc.Doclet;
    1.36 +import com.sun.javadoc.RootDoc;
    1.37 +
    1.38 +public class Test extends Doclet {
    1.39 +    public static void main(String... args) throws Exception {
    1.40 +        new Test().run();
    1.41 +    }
    1.42 +
    1.43 +    void run() throws Exception {
    1.44 +        test("<html><body>ABC      XYZ</body></html>");
    1.45 +        test("<html><body>ABC      XYZ</BODY></html>");
    1.46 +        test("<html><BODY>ABC      XYZ</body></html>");
    1.47 +        test("<html><BODY>ABC      XYZ</BODY></html>");
    1.48 +        test("<html><BoDy>ABC      XYZ</bOdY></html>");
    1.49 +        test("<html>      ABC      XYZ</bOdY></html>", "Body tag missing from HTML");
    1.50 +        test("<html><body>ABC      XYZ       </html>", "Close body tag missing from HTML");
    1.51 +        test("<html>      ABC      XYZ       </html>", "Body tag missing from HTML");
    1.52 +        test("<html><body>ABC" + bigText(8192, 40) + "XYZ</body></html>");
    1.53 +
    1.54 +        if (errors > 0)
    1.55 +            throw new Exception(errors + " errors occurred");
    1.56 +    }
    1.57 +
    1.58 +    void test(String text) throws IOException {
    1.59 +        test(text, null);
    1.60 +    }
    1.61 +
    1.62 +    void test(String text, String expectError) throws IOException {
    1.63 +        testNum++;
    1.64 +        System.err.println("test " + testNum);
    1.65 +        File file = writeFile("overview" + testNum + ".html", text);
    1.66 +        String thisClassName = Test.class.getName();
    1.67 +        File testSrc = new File(System.getProperty("test.src"));
    1.68 +        String[] args = {
    1.69 +            "-bootclasspath",
    1.70 +                System.getProperty("java.class.path")
    1.71 +                + File.pathSeparator
    1.72 +                + System.getProperty("sun.boot.class.path"),
    1.73 +            "-classpath", ".",
    1.74 +            "-package",
    1.75 +            "-overview", file.getPath(),
    1.76 +            new File(testSrc, thisClassName + ".java").getPath()
    1.77 +        };
    1.78 +
    1.79 +        StringWriter sw = new StringWriter();
    1.80 +        PrintWriter pw = new PrintWriter(sw);
    1.81 +        int rc = com.sun.tools.javadoc.Main.execute(
    1.82 +                "javadoc",
    1.83 +                pw, pw, pw,
    1.84 +                thisClassName,
    1.85 +                args);
    1.86 +        pw.close();
    1.87 +        String out = sw.toString();
    1.88 +        if (!out.isEmpty())
    1.89 +            System.err.println(out);
    1.90 +        System.err.println("javadoc exit: rc=" + rc);
    1.91 +
    1.92 +        if (expectError == null) {
    1.93 +            if (rc != 0)
    1.94 +                error("unexpected exit from javadoc; rc:" + rc);
    1.95 +        } else {
    1.96 +            if (!out.contains(expectError))
    1.97 +                error("expected error text not found: " + expectError);
    1.98 +        }
    1.99 +    }
   1.100 +
   1.101 +    String bigText(int lines, int lineLength) {
   1.102 +        StringBuilder sb = new StringBuilder();
   1.103 +        for (int i = 0; i < lineLength; i++)
   1.104 +            sb.append(String.valueOf(i % 10));
   1.105 +        sb.append("\n");
   1.106 +        String line = sb.toString();
   1.107 +        sb.setLength(0);
   1.108 +        for (int i = 0; i < lines; i++)
   1.109 +            sb.append(line);
   1.110 +        return sb.toString();
   1.111 +    }
   1.112 +
   1.113 +    File writeFile(String path, String body) throws IOException {
   1.114 +        File f = new File(path);
   1.115 +        FileWriter out = new FileWriter(f);
   1.116 +        try {
   1.117 +            out.write(body);
   1.118 +        } finally {
   1.119 +            out.close();
   1.120 +        }
   1.121 +        return f;
   1.122 +    }
   1.123 +
   1.124 +    void error(String msg) {
   1.125 +        System.err.println("Error: " + msg);
   1.126 +        errors++;
   1.127 +    }
   1.128 +
   1.129 +    int testNum;
   1.130 +    int errors;
   1.131 +
   1.132 +    public static boolean start(RootDoc root) {
   1.133 +        String text = root.commentText();
   1.134 +        if (text.length() < 64)
   1.135 +            System.err.println("text: '" + text + "'");
   1.136 +        else
   1.137 +            System.err.println("text: '"
   1.138 +                    + text.substring(0, 20)
   1.139 +                    + "..."
   1.140 +                    + text.substring(text.length() - 20)
   1.141 +                    + "'");
   1.142 +        return text.startsWith("ABC") && text.endsWith("XYZ");
   1.143 +    }
   1.144 +}

mercurial