test/com/sun/javadoc/testSourceTab/TestSourceTab.java

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/com/sun/javadoc/testSourceTab/TestSourceTab.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,138 @@
     1.4 +/*
     1.5 + * Copyright (c) 2002, 2008, 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 4510979
    1.30 + * @summary Test to make sure that the source documentation is indented properly
    1.31 + * when -linksourcetab is used.
    1.32 + * @author jamieh
    1.33 + * @library ../lib/
    1.34 + * @build JavadocTester
    1.35 + * @build TestSourceTab
    1.36 + * @run main TestSourceTab
    1.37 + */
    1.38 +
    1.39 +import java.io.*;
    1.40 +
    1.41 +public class TestSourceTab extends JavadocTester {
    1.42 +
    1.43 +    private static final String BUG_ID = "4510979";
    1.44 +    private static final String TMP_SRC_DIR = "tmpSrc";
    1.45 +    private static final String OUTPUT_DIR1 = BUG_ID + "-tabLengthEight";
    1.46 +    private static final String OUTPUT_DIR2 = BUG_ID + "-tabLengthFour";
    1.47 +    private static final String[][] TEST = NO_TEST;
    1.48 +    private static final String[][] NEGATED_TEST = NO_TEST;
    1.49 +
    1.50 +    //Run Javadoc on a source file with that is indented with a single tab per line
    1.51 +    private static final String[] ARGS1 =
    1.52 +        new String[] {
    1.53 +            "-d", OUTPUT_DIR1, "-sourcepath", TMP_SRC_DIR,
    1.54 +            "-notimestamp", "-linksource", TMP_SRC_DIR + FS + "SingleTab" + FS + "C.java"
    1.55 +        };
    1.56 +
    1.57 +    //Run Javadoc on a source file with that is indented with a two tab per line
    1.58 +    //If we double the tabs and decrease the tab length by a half, the output should
    1.59 +    //be the same as the one generated above.
    1.60 +    private static final String[] ARGS2 =
    1.61 +        new String[] {
    1.62 +            "-d", OUTPUT_DIR2, "-sourcepath", TMP_SRC_DIR,
    1.63 +            "-notimestamp", "-sourcetab", "4", TMP_SRC_DIR + FS + "DoubleTab" + FS + "C.java"
    1.64 +        };
    1.65 +
    1.66 +    //Files to diff
    1.67 +    private static final String[][] FILES_TO_DIFF = {
    1.68 +        {OUTPUT_DIR1 + FS + "src-html" + FS + "C.html",
    1.69 +         OUTPUT_DIR2 + FS + "src-html" + FS + "C.html"
    1.70 +        },
    1.71 +        {OUTPUT_DIR1 + FS + "C.html",
    1.72 +         OUTPUT_DIR2 + FS + "C.html"
    1.73 +        }
    1.74 +
    1.75 +    };
    1.76 +
    1.77 +    /**
    1.78 +     * The entry point of the test.
    1.79 +     * @param args the array of command line arguments.
    1.80 +     */
    1.81 +    public static void main(String[] args) throws IOException {
    1.82 +        TestSourceTab tester = new TestSourceTab();
    1.83 +        run(tester, ARGS1, TEST, NEGATED_TEST);
    1.84 +        run(tester, ARGS2, TEST, NEGATED_TEST);
    1.85 +        tester.runDiffs(FILES_TO_DIFF);
    1.86 +    }
    1.87 +
    1.88 +    TestSourceTab() throws IOException {
    1.89 +        initTabs(new File(SRC_DIR), new File(TMP_SRC_DIR));
    1.90 +    }
    1.91 +
    1.92 +    void initTabs(File from, File to) throws IOException {
    1.93 +        for (File f: from.listFiles()) {
    1.94 +            File t = new File(to, f.getName());
    1.95 +            if (f.isDirectory()) {
    1.96 +                initTabs(f, t);
    1.97 +            } else if (f.getName().endsWith(".java")) {
    1.98 +                write(t, read(f).replace("\\t", "\t"));
    1.99 +            }
   1.100 +        }
   1.101 +    }
   1.102 +
   1.103 +    String read(File f) throws IOException {
   1.104 +        StringBuilder sb = new StringBuilder();
   1.105 +        BufferedReader in = new BufferedReader(new FileReader(f));
   1.106 +        try {
   1.107 +            String line;
   1.108 +            while ((line = in.readLine()) != null) {
   1.109 +                sb.append(line);
   1.110 +                sb.append("\n");
   1.111 +            }
   1.112 +        } finally {
   1.113 +            in.close();
   1.114 +        }
   1.115 +        return sb.toString();
   1.116 +    }
   1.117 +
   1.118 +    void write(File f, String s) throws IOException {
   1.119 +        f.getParentFile().mkdirs();
   1.120 +        Writer out = new FileWriter(f);
   1.121 +        try {
   1.122 +            out.write(s);
   1.123 +        } finally {
   1.124 +            out.close();
   1.125 +        }
   1.126 +    }
   1.127 +
   1.128 +    /**
   1.129 +     * {@inheritDoc}
   1.130 +     */
   1.131 +    public String getBugId() {
   1.132 +        return BUG_ID;
   1.133 +    }
   1.134 +
   1.135 +    /**
   1.136 +     * {@inheritDoc}
   1.137 +     */
   1.138 +    public String getBugName() {
   1.139 +        return getClass().getName();
   1.140 +    }
   1.141 +}

mercurial