25 * @test |
25 * @test |
26 * @bug 4510979 |
26 * @bug 4510979 |
27 * @summary Test to make sure that the source documentation is indented properly |
27 * @summary Test to make sure that the source documentation is indented properly |
28 * when -linksourcetab is used. |
28 * when -linksourcetab is used. |
29 * @author jamieh |
29 * @author jamieh |
30 * @library ../lib/ |
30 * @library ../lib |
31 * @build JavadocTester |
31 * @build JavadocTester |
32 * @build TestSourceTab |
|
33 * @run main TestSourceTab |
32 * @run main TestSourceTab |
34 */ |
33 */ |
35 |
34 |
36 import java.io.*; |
35 import java.io.*; |
37 |
36 |
38 public class TestSourceTab extends JavadocTester { |
37 public class TestSourceTab extends JavadocTester { |
39 |
38 |
40 private static final String TMP_SRC_DIR = "tmpSrc"; |
39 public static void main(String... args) throws Exception { |
41 private static final String OUTPUT_DIR1 = OUTPUT_DIR + "-tabLengthEight"; |
|
42 private static final String OUTPUT_DIR2 = OUTPUT_DIR + "-tabLengthFour"; |
|
43 |
|
44 //Run Javadoc on a source file with that is indented with a single tab per line |
|
45 private static final String[] ARGS1 = |
|
46 new String[] { |
|
47 "-d", OUTPUT_DIR1, "-sourcepath", TMP_SRC_DIR, |
|
48 "-notimestamp", "-linksource", TMP_SRC_DIR + "/SingleTab/C.java" |
|
49 }; |
|
50 |
|
51 //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 |
|
53 //be the same as the one generated above. |
|
54 private static final String[] ARGS2 = |
|
55 new String[] { |
|
56 "-d", OUTPUT_DIR2, "-sourcepath", TMP_SRC_DIR, |
|
57 "-notimestamp", "-sourcetab", "4", TMP_SRC_DIR + "/DoubleTab/C.java" |
|
58 }; |
|
59 |
|
60 //Files to diff |
|
61 private static final String[] FILES_TO_DIFF = { |
|
62 "src-html/C.html", |
|
63 "C.html" |
|
64 }; |
|
65 |
|
66 /** |
|
67 * The entry point of the test. |
|
68 * @param args the array of command line arguments. |
|
69 */ |
|
70 public static void main(String[] args) throws IOException { |
|
71 TestSourceTab tester = new TestSourceTab(); |
40 TestSourceTab tester = new TestSourceTab(); |
72 tester.run(ARGS1, NO_TEST, NO_TEST); |
41 tester.runTests(); |
73 tester.run(ARGS2, NO_TEST, NO_TEST); |
|
74 tester.runDiffs(OUTPUT_DIR1, OUTPUT_DIR2, FILES_TO_DIFF); |
|
75 } |
42 } |
76 |
43 |
77 TestSourceTab() throws IOException { |
44 @Test |
78 initTabs(new File(SRC_DIR), new File(TMP_SRC_DIR)); |
45 void test() throws Exception { |
|
46 String tmpSrcDir = "tmpSrc"; |
|
47 String outdir1 = "out-tabLengthEight"; |
|
48 String outdir2 = "out-tabLengthFour"; |
|
49 initTabs(new File(testSrc), new File(tmpSrcDir)); |
|
50 |
|
51 // Run Javadoc on a source file with that is indented with a single tab per line |
|
52 javadoc("-d", outdir1, |
|
53 "-sourcepath", tmpSrcDir, |
|
54 "-notimestamp", |
|
55 "-linksource", |
|
56 tmpSrcDir + "/SingleTab/C.java"); |
|
57 checkExit(Exit.OK); |
|
58 |
|
59 // Run Javadoc on a source file with that is indented with a two tab per line |
|
60 // If we double the tabs and decrease the tab length by a half, the output should |
|
61 // be the same as the one generated above. |
|
62 javadoc("-d", outdir2, |
|
63 "-sourcepath", tmpSrcDir, |
|
64 "-notimestamp", |
|
65 "-sourcetab", "4", |
|
66 tmpSrcDir + "/DoubleTab/C.java"); |
|
67 checkExit(Exit.OK); |
|
68 |
|
69 diff(outdir1, outdir2, |
|
70 "src-html/C.html", |
|
71 "C.html"); |
79 } |
72 } |
80 |
73 |
81 void initTabs(File from, File to) throws IOException { |
74 void initTabs(File from, File to) throws IOException { |
82 for (File f: from.listFiles()) { |
75 for (File f: from.listFiles()) { |
83 File t = new File(to, f.getName()); |
76 File t = new File(to, f.getName()); |
89 } |
82 } |
90 } |
83 } |
91 |
84 |
92 String read(File f) throws IOException { |
85 String read(File f) throws IOException { |
93 StringBuilder sb = new StringBuilder(); |
86 StringBuilder sb = new StringBuilder(); |
94 BufferedReader in = new BufferedReader(new FileReader(f)); |
87 try (BufferedReader in = new BufferedReader(new FileReader(f))) { |
95 try { |
|
96 String line; |
88 String line; |
97 while ((line = in.readLine()) != null) { |
89 while ((line = in.readLine()) != null) { |
98 sb.append(line); |
90 sb.append(line); |
99 sb.append("\n"); |
91 sb.append(NL); |
100 } |
92 } |
101 } finally { |
|
102 in.close(); |
|
103 } |
93 } |
104 return sb.toString(); |
94 return sb.toString(); |
105 } |
95 } |
106 |
96 |
107 void write(File f, String s) throws IOException { |
97 void write(File f, String s) throws IOException { |
108 f.getParentFile().mkdirs(); |
98 f.getParentFile().mkdirs(); |
109 Writer out = new FileWriter(f); |
99 try (Writer out = new FileWriter(f)) { |
110 try { |
|
111 out.write(s); |
100 out.write(s); |
112 } finally { |
|
113 out.close(); |
|
114 } |
101 } |
115 } |
102 } |
116 } |
103 } |