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

changeset 177
8db0c5fd6e99
parent 1
9a66ca7c79fa
child 554
9d9f26857129
     1.1 --- a/test/com/sun/javadoc/testSourceTab/TestSourceTab.java	Mon Dec 01 12:15:14 2008 -0800
     1.2 +++ b/test/com/sun/javadoc/testSourceTab/TestSourceTab.java	Tue Dec 02 14:35:22 2008 -0800
     1.3 @@ -1,5 +1,5 @@
     1.4 -/* 
     1.5 - * Copyright 2002-2004 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 +/*
     1.7 + * Copyright 2002-2008 Sun Microsystems, Inc.  All Rights Reserved.
     1.8   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.9   *
    1.10   * This code is free software; you can redistribute it and/or modify it
    1.11 @@ -33,59 +33,102 @@
    1.12   * @run main TestSourceTab
    1.13   */
    1.14  
    1.15 +import java.io.*;
    1.16 +
    1.17  public class TestSourceTab extends JavadocTester {
    1.18 -    
    1.19 +
    1.20      private static final String BUG_ID = "4510979";
    1.21 +    private static final String TMP_SRC_DIR = "tmpSrc";
    1.22      private static final String OUTPUT_DIR1 = BUG_ID + "-tabLengthEight";
    1.23      private static final String OUTPUT_DIR2 = BUG_ID + "-tabLengthFour";
    1.24      private static final String[][] TEST = NO_TEST;
    1.25      private static final String[][] NEGATED_TEST = NO_TEST;
    1.26 -    
    1.27 +
    1.28      //Run Javadoc on a source file with that is indented with a single tab per line
    1.29      private static final String[] ARGS1 =
    1.30          new String[] {
    1.31 -            "-d", OUTPUT_DIR1, "-sourcepath", SRC_DIR,
    1.32 -            "-notimestamp", "-linksource", SRC_DIR + FS + "SingleTab" + FS + "C.java"
    1.33 +            "-d", OUTPUT_DIR1, "-sourcepath", TMP_SRC_DIR,
    1.34 +            "-notimestamp", "-linksource", TMP_SRC_DIR + FS + "SingleTab" + FS + "C.java"
    1.35          };
    1.36 -    
    1.37 +
    1.38      //Run Javadoc on a source file with that is indented with a two tab per line
    1.39      //If we double the tabs and decrease the tab length by a half, the output should
    1.40      //be the same as the one generated above.
    1.41      private static final String[] ARGS2 =
    1.42          new String[] {
    1.43 -            "-d", OUTPUT_DIR2, "-sourcepath", SRC_DIR,
    1.44 -            "-notimestamp", "-sourcetab", "4", SRC_DIR + FS + "DoubleTab" + FS + "C.java"
    1.45 +            "-d", OUTPUT_DIR2, "-sourcepath", TMP_SRC_DIR,
    1.46 +            "-notimestamp", "-sourcetab", "4", TMP_SRC_DIR + FS + "DoubleTab" + FS + "C.java"
    1.47          };
    1.48 -    
    1.49 +
    1.50      //Files to diff
    1.51      private static final String[][] FILES_TO_DIFF = {
    1.52          {OUTPUT_DIR1 + FS + "src-html" + FS + "C.html",
    1.53           OUTPUT_DIR2 + FS + "src-html" + FS + "C.html"
    1.54 -        }, 
    1.55 +        },
    1.56          {OUTPUT_DIR1 + FS + "C.html",
    1.57           OUTPUT_DIR2 + FS + "C.html"
    1.58          }
    1.59 -        
    1.60 +
    1.61      };
    1.62 -    
    1.63 +
    1.64      /**
    1.65       * The entry point of the test.
    1.66       * @param args the array of command line arguments.
    1.67       */
    1.68 -    public static void main(String[] args) {
    1.69 +    public static void main(String[] args) throws IOException {
    1.70          TestSourceTab tester = new TestSourceTab();
    1.71          run(tester, ARGS1, TEST, NEGATED_TEST);
    1.72          run(tester, ARGS2, TEST, NEGATED_TEST);
    1.73          tester.runDiffs(FILES_TO_DIFF);
    1.74      }
    1.75 -    
    1.76 +
    1.77 +    TestSourceTab() throws IOException {
    1.78 +        initTabs(new File(SRC_DIR), new File(TMP_SRC_DIR));
    1.79 +    }
    1.80 +
    1.81 +    void initTabs(File from, File to) throws IOException {
    1.82 +        for (File f: from.listFiles()) {
    1.83 +            File t = new File(to, f.getName());
    1.84 +            if (f.isDirectory()) {
    1.85 +                initTabs(f, t);
    1.86 +            } else if (f.getName().endsWith(".java")) {
    1.87 +                write(t, read(f).replace("\\t", "\t"));
    1.88 +            }
    1.89 +        }
    1.90 +    }
    1.91 +
    1.92 +    String read(File f) throws IOException {
    1.93 +        StringBuilder sb = new StringBuilder();
    1.94 +        BufferedReader in = new BufferedReader(new FileReader(f));
    1.95 +        try {
    1.96 +            String line;
    1.97 +            while ((line = in.readLine()) != null) {
    1.98 +                sb.append(line);
    1.99 +                sb.append("\n");
   1.100 +            }
   1.101 +        } finally {
   1.102 +            in.close();
   1.103 +        }
   1.104 +        return sb.toString();
   1.105 +    }
   1.106 +
   1.107 +    void write(File f, String s) throws IOException {
   1.108 +        f.getParentFile().mkdirs();
   1.109 +        Writer out = new FileWriter(f);
   1.110 +        try {
   1.111 +            out.write(s);
   1.112 +        } finally {
   1.113 +            out.close();
   1.114 +        }
   1.115 +    }
   1.116 +
   1.117      /**
   1.118       * {@inheritDoc}
   1.119       */
   1.120      public String getBugId() {
   1.121          return BUG_ID;
   1.122      }
   1.123 -    
   1.124 +
   1.125      /**
   1.126       * {@inheritDoc}
   1.127       */

mercurial