31 * @build JavadocTester |
31 * @build JavadocTester |
32 * @build TestSourceTab |
32 * @build TestSourceTab |
33 * @run main TestSourceTab |
33 * @run main TestSourceTab |
34 */ |
34 */ |
35 |
35 |
|
36 import java.io.*; |
|
37 |
36 public class TestSourceTab extends JavadocTester { |
38 public class TestSourceTab extends JavadocTester { |
37 |
39 |
38 private static final String BUG_ID = "4510979"; |
40 private static final String BUG_ID = "4510979"; |
|
41 private static final String TMP_SRC_DIR = "tmpSrc"; |
39 private static final String OUTPUT_DIR1 = BUG_ID + "-tabLengthEight"; |
42 private static final String OUTPUT_DIR1 = BUG_ID + "-tabLengthEight"; |
40 private static final String OUTPUT_DIR2 = BUG_ID + "-tabLengthFour"; |
43 private static final String OUTPUT_DIR2 = BUG_ID + "-tabLengthFour"; |
41 private static final String[][] TEST = NO_TEST; |
44 private static final String[][] TEST = NO_TEST; |
42 private static final String[][] NEGATED_TEST = NO_TEST; |
45 private static final String[][] NEGATED_TEST = NO_TEST; |
43 |
46 |
44 //Run Javadoc on a source file with that is indented with a single tab per line |
47 //Run Javadoc on a source file with that is indented with a single tab per line |
45 private static final String[] ARGS1 = |
48 private static final String[] ARGS1 = |
46 new String[] { |
49 new String[] { |
47 "-d", OUTPUT_DIR1, "-sourcepath", SRC_DIR, |
50 "-d", OUTPUT_DIR1, "-sourcepath", TMP_SRC_DIR, |
48 "-notimestamp", "-linksource", SRC_DIR + FS + "SingleTab" + FS + "C.java" |
51 "-notimestamp", "-linksource", TMP_SRC_DIR + FS + "SingleTab" + FS + "C.java" |
49 }; |
52 }; |
50 |
53 |
51 //Run Javadoc on a source file with that is indented with a two tab per line |
54 //Run Javadoc on a source file with that is indented with a two tab per line |
52 //If we double the tabs and decrease the tab length by a half, the output should |
55 //If we double the tabs and decrease the tab length by a half, the output should |
53 //be the same as the one generated above. |
56 //be the same as the one generated above. |
54 private static final String[] ARGS2 = |
57 private static final String[] ARGS2 = |
55 new String[] { |
58 new String[] { |
56 "-d", OUTPUT_DIR2, "-sourcepath", SRC_DIR, |
59 "-d", OUTPUT_DIR2, "-sourcepath", TMP_SRC_DIR, |
57 "-notimestamp", "-sourcetab", "4", SRC_DIR + FS + "DoubleTab" + FS + "C.java" |
60 "-notimestamp", "-sourcetab", "4", TMP_SRC_DIR + FS + "DoubleTab" + FS + "C.java" |
58 }; |
61 }; |
59 |
62 |
60 //Files to diff |
63 //Files to diff |
61 private static final String[][] FILES_TO_DIFF = { |
64 private static final String[][] FILES_TO_DIFF = { |
62 {OUTPUT_DIR1 + FS + "src-html" + FS + "C.html", |
65 {OUTPUT_DIR1 + FS + "src-html" + FS + "C.html", |
63 OUTPUT_DIR2 + FS + "src-html" + FS + "C.html" |
66 OUTPUT_DIR2 + FS + "src-html" + FS + "C.html" |
64 }, |
67 }, |
65 {OUTPUT_DIR1 + FS + "C.html", |
68 {OUTPUT_DIR1 + FS + "C.html", |
66 OUTPUT_DIR2 + FS + "C.html" |
69 OUTPUT_DIR2 + FS + "C.html" |
67 } |
70 } |
68 |
71 |
69 }; |
72 }; |
70 |
73 |
71 /** |
74 /** |
72 * The entry point of the test. |
75 * The entry point of the test. |
73 * @param args the array of command line arguments. |
76 * @param args the array of command line arguments. |
74 */ |
77 */ |
75 public static void main(String[] args) { |
78 public static void main(String[] args) throws IOException { |
76 TestSourceTab tester = new TestSourceTab(); |
79 TestSourceTab tester = new TestSourceTab(); |
77 run(tester, ARGS1, TEST, NEGATED_TEST); |
80 run(tester, ARGS1, TEST, NEGATED_TEST); |
78 run(tester, ARGS2, TEST, NEGATED_TEST); |
81 run(tester, ARGS2, TEST, NEGATED_TEST); |
79 tester.runDiffs(FILES_TO_DIFF); |
82 tester.runDiffs(FILES_TO_DIFF); |
80 } |
83 } |
81 |
84 |
|
85 TestSourceTab() throws IOException { |
|
86 initTabs(new File(SRC_DIR), new File(TMP_SRC_DIR)); |
|
87 } |
|
88 |
|
89 void initTabs(File from, File to) throws IOException { |
|
90 for (File f: from.listFiles()) { |
|
91 File t = new File(to, f.getName()); |
|
92 if (f.isDirectory()) { |
|
93 initTabs(f, t); |
|
94 } else if (f.getName().endsWith(".java")) { |
|
95 write(t, read(f).replace("\\t", "\t")); |
|
96 } |
|
97 } |
|
98 } |
|
99 |
|
100 String read(File f) throws IOException { |
|
101 StringBuilder sb = new StringBuilder(); |
|
102 BufferedReader in = new BufferedReader(new FileReader(f)); |
|
103 try { |
|
104 String line; |
|
105 while ((line = in.readLine()) != null) { |
|
106 sb.append(line); |
|
107 sb.append("\n"); |
|
108 } |
|
109 } finally { |
|
110 in.close(); |
|
111 } |
|
112 return sb.toString(); |
|
113 } |
|
114 |
|
115 void write(File f, String s) throws IOException { |
|
116 f.getParentFile().mkdirs(); |
|
117 Writer out = new FileWriter(f); |
|
118 try { |
|
119 out.write(s); |
|
120 } finally { |
|
121 out.close(); |
|
122 } |
|
123 } |
|
124 |
82 /** |
125 /** |
83 * {@inheritDoc} |
126 * {@inheritDoc} |
84 */ |
127 */ |
85 public String getBugId() { |
128 public String getBugId() { |
86 return BUG_ID; |
129 return BUG_ID; |
87 } |
130 } |
88 |
131 |
89 /** |
132 /** |
90 * {@inheritDoc} |
133 * {@inheritDoc} |
91 */ |
134 */ |
92 public String getBugName() { |
135 public String getBugName() { |
93 return getClass().getName(); |
136 return getClass().getName(); |