TestSourceTab.java revision 176
10302N/A/*
10302N/A * Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved.
10302N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
13617N/A *
10302N/A * This code is free software; you can redistribute it and/or modify it
10302N/A * under the terms of the GNU General Public License version 2 only, as
10302N/A * published by the Free Software Foundation.
10304N/A *
10304N/A * This code is distributed in the hope that it will be useful, but WITHOUT
10656N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10302N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10302N/A * version 2 for more details (a copy is included in the LICENSE file that
10302N/A * accompanied this code).
12943N/A *
10302N/A * You should have received a copy of the GNU General Public License version
10302N/A * 2 along with this work; if not, write to the Free Software Foundation,
10302N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
10302N/A *
10337N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
10656N/A * CA 95054 USA or visit www.sun.com if you need additional information or
12773N/A * have any questions.
12773N/A */
12773N/A
10352N/A/*
10302N/A * @test
13617N/A * @bug 4510979
13617N/A * @summary Test to make sure that the source documentation is indented properly
13708N/A * when -linksourcetab is used.
13708N/A * @author jamieh
10302N/A * @library ../lib/
10302N/A * @build JavadocTester
10302N/A * @build TestSourceTab
10302N/A * @run main TestSourceTab
10302N/A */
10302N/A
10302N/Aimport java.io.*;
10302N/A
10302N/Apublic class TestSourceTab extends JavadocTester {
10302N/A
10302N/A private static final String BUG_ID = "4510979";
10302N/A private static final String TMP_SRC_DIR = "tmpSrc";
10302N/A private static final String OUTPUT_DIR1 = BUG_ID + "-tabLengthEight";
10302N/A private static final String OUTPUT_DIR2 = BUG_ID + "-tabLengthFour";
10302N/A private static final String[][] TEST = NO_TEST;
10302N/A private static final String[][] NEGATED_TEST = NO_TEST;
10302N/A
10302N/A //Run Javadoc on a source file with that is indented with a single tab per line
10302N/A private static final String[] ARGS1 =
10302N/A new String[] {
10302N/A "-d", OUTPUT_DIR1, "-sourcepath", TMP_SRC_DIR,
10302N/A "-notimestamp", "-linksource", TMP_SRC_DIR + FS + "SingleTab" + FS + "C.java"
10302N/A };
10302N/A
10302N/A //Run Javadoc on a source file with that is indented with a two tab per line
10302N/A //If we double the tabs and decrease the tab length by a half, the output should
10302N/A //be the same as the one generated above.
10302N/A private static final String[] ARGS2 =
10302N/A new String[] {
10302N/A "-d", OUTPUT_DIR2, "-sourcepath", TMP_SRC_DIR,
10302N/A "-notimestamp", "-sourcetab", "4", TMP_SRC_DIR + FS + "DoubleTab" + FS + "C.java"
10302N/A };
10302N/A
10302N/A //Files to diff
10302N/A private static final String[][] FILES_TO_DIFF = {
10302N/A {OUTPUT_DIR1 + FS + "src-html" + FS + "C.html",
10302N/A OUTPUT_DIR2 + FS + "src-html" + FS + "C.html"
10302N/A },
10656N/A {OUTPUT_DIR1 + FS + "C.html",
10656N/A OUTPUT_DIR2 + FS + "C.html"
10656N/A }
10656N/A
10302N/A };
13617N/A
13708N/A /**
10302N/A * The entry point of the test.
10302N/A * @param args the array of command line arguments.
10302N/A */
10302N/A public static void main(String[] args) throws IOException {
10302N/A TestSourceTab tester = new TestSourceTab();
10302N/A run(tester, ARGS1, TEST, NEGATED_TEST);
10302N/A run(tester, ARGS2, TEST, NEGATED_TEST);
10302N/A tester.runDiffs(FILES_TO_DIFF);
10302N/A }
10302N/A
10302N/A TestSourceTab() throws IOException {
10302N/A initTabs(new File(SRC_DIR), new File(TMP_SRC_DIR));
10302N/A }
10302N/A
11149N/A void initTabs(File from, File to) throws IOException {
12773N/A for (File f: from.listFiles()) {
12773N/A File t = new File(to, f.getName());
12773N/A if (f.isDirectory()) {
12773N/A initTabs(f, t);
12773N/A } else if (f.getName().endsWith(".java")) {
10302N/A write(t, read(f).replace("\\t", "\t"));
10302N/A }
10302N/A }
10302N/A }
10302N/A
10302N/A String read(File f) throws IOException {
10302N/A StringBuilder sb = new StringBuilder();
10302N/A BufferedReader in = new BufferedReader(new FileReader(f));
10302N/A try {
10304N/A String line;
10304N/A while ((line = in.readLine()) != null) {
10302N/A sb.append(line);
10302N/A sb.append("\n");
10302N/A }
10302N/A } finally {
10302N/A in.close();
10302N/A }
10302N/A return sb.toString();
10302N/A }
10302N/A
10302N/A void write(File f, String s) throws IOException {
10302N/A f.getParentFile().mkdirs();
10302N/A Writer out = new FileWriter(f);
10302N/A try {
10302N/A out.write(s);
10302N/A } finally {
10302N/A out.close();
10302N/A }
10302N/A }
10302N/A
10302N/A /**
10302N/A * {@inheritDoc}
10302N/A */
10302N/A public String getBugId() {
10302N/A return BUG_ID;
10302N/A }
10302N/A
10302N/A /**
10302N/A * {@inheritDoc}
10302N/A */
10302N/A public String getBugName() {
10302N/A return getClass().getName();
10302N/A }
10302N/A}
10302N/A