author | bpatel |
Wed, 01 Dec 2010 11:02:38 -0800 | |
changeset 7614 | cfadc977ca75 |
parent 5520 | 86e4b9a9da40 |
child 7681 | 1f0819a3341f |
permissions | -rw-r--r-- |
10 | 1 |
/* |
5520 | 2 |
* Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5520 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
10 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 4530730 |
|
27 |
* @summary stddoclet: With frames off, window titles have "()" appended |
|
28 |
* @author dkramer |
|
29 |
* @run main WindowTitles |
|
30 |
*/ |
|
31 |
||
32 |
||
33 |
import com.sun.javadoc.*; |
|
34 |
import java.util.*; |
|
35 |
import java.io.*; |
|
36 |
||
37 |
// If needing regular expression pattern matching, |
|
38 |
// see /java/pubs/dev/linkfix/src/LinkFix.java |
|
39 |
||
40 |
/** |
|
41 |
* Runs javadoc and runs regression tests on the resulting HTML. |
|
42 |
* It reads each file, complete with newlines, into a string to easily |
|
43 |
* find strings that contain newlines. |
|
44 |
*/ |
|
45 |
public class WindowTitles |
|
46 |
{ |
|
47 |
private static final String BUGID = "4530730"; |
|
48 |
private static final String BUGNAME = "WindowTitles"; |
|
49 |
private static final String FS = System.getProperty("file.separator"); |
|
50 |
private static final String PS = System.getProperty("path.separator"); |
|
51 |
private static final String LS = System.getProperty("line.separator"); |
|
52 |
private static final String TMPDIR_STRING1 = "." + FS + "docs1" + FS; |
|
53 |
private static final String TMPDIR_STRING2 = "." + FS + "docs2" + FS; |
|
54 |
||
55 |
// Subtest number. Needed because runResultsOnHTML is run twice, and subtestNum |
|
56 |
// should increment across subtest runs. |
|
57 |
public static int subtestNum = 0; |
|
58 |
public static int numSubtestsPassed = 0; |
|
59 |
||
60 |
// Entry point |
|
61 |
public static void main(String[] args) { |
|
62 |
||
63 |
// Directory that contains source files that javadoc runs on |
|
64 |
String srcdir = System.getProperty("test.src", "."); |
|
65 |
||
66 |
// Test for all cases except the split index page |
|
67 |
runJavadoc(new String[] {"-d", TMPDIR_STRING1, |
|
68 |
"-use", |
|
69 |
"-sourcepath", srcdir, |
|
70 |
"p1", "p2"}); |
|
71 |
runTestsOnHTML(testArray); |
|
72 |
||
73 |
// Test only for the split-index case (and run on only one package) |
|
74 |
System.out.println(""); // blank line |
|
75 |
runJavadoc(new String[] {"-d", TMPDIR_STRING2, |
|
76 |
"-splitindex", |
|
77 |
"-sourcepath", System.getProperty("test.src", "."), |
|
78 |
"p1"}); |
|
79 |
runTestsOnHTML(testSplitIndexArray); |
|
80 |
||
81 |
printSummary(); |
|
82 |
} |
|
83 |
||
84 |
/** Run javadoc */ |
|
85 |
public static void runJavadoc(String[] javadocArgs) { |
|
86 |
if (com.sun.tools.javadoc.Main.execute(javadocArgs) != 0) { |
|
87 |
throw new Error("Javadoc failed to execute"); |
|
88 |
} |
|
89 |
} |
|
90 |
||
91 |
/** |
|
92 |
* Assign value for [ stringToFind, filename ] |
|
93 |
* NOTE: The standard doclet uses platform-specific line separators (LS) |
|
94 |
*/ |
|
95 |
private static final String[][] testArray = { |
|
96 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
97 |
{ "<title>Overview</title>", |
10 | 98 |
TMPDIR_STRING1 + "overview-summary.html" }, |
99 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
100 |
{ "<title>Class Hierarchy</title>", |
10 | 101 |
TMPDIR_STRING1 + "overview-tree.html" }, |
102 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
103 |
{ "<title>Overview List</title>", |
10 | 104 |
TMPDIR_STRING1 + "overview-frame.html" }, |
105 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
106 |
{ "<title>p1</title>", |
10 | 107 |
TMPDIR_STRING1 + "p1" + FS + "package-summary.html" }, |
108 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
109 |
{ "<title>p1</title>", |
10 | 110 |
TMPDIR_STRING1 + "p1" + FS + "package-frame.html" }, |
111 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
112 |
{ "<title>p1 Class Hierarchy</title>", |
10 | 113 |
TMPDIR_STRING1 + "p1" + FS + "package-tree.html" }, |
114 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
115 |
{ "<title>Uses of Package p1</title>", |
10 | 116 |
TMPDIR_STRING1 + "p1" + FS + "package-use.html" }, |
117 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
118 |
{ "<title>C1</title>", |
10 | 119 |
TMPDIR_STRING1 + "p1" + FS + "C1.html" }, |
120 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
121 |
{ "<title>All Classes</title>", |
10 | 122 |
TMPDIR_STRING1 + "allclasses-frame.html" }, |
123 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
124 |
{ "<title>All Classes</title>", |
10 | 125 |
TMPDIR_STRING1 + "allclasses-noframe.html" }, |
126 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
127 |
{ "<title>Constant Field Values</title>", |
10 | 128 |
TMPDIR_STRING1 + "constant-values.html" }, |
129 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
130 |
{ "<title>Deprecated List</title>", |
10 | 131 |
TMPDIR_STRING1 + "deprecated-list.html" }, |
132 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
133 |
{ "<title>Serialized Form</title>", |
10 | 134 |
TMPDIR_STRING1 + "serialized-form.html" }, |
135 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
136 |
{ "<title>API Help</title>", |
10 | 137 |
TMPDIR_STRING1 + "help-doc.html" }, |
138 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
139 |
{ "<title>Index</title>", |
10 | 140 |
TMPDIR_STRING1 + "index-all.html" }, |
141 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
142 |
{ "<title>Uses of Class p1.C1</title>", |
10 | 143 |
TMPDIR_STRING1 + "p1" + FS + "class-use" + FS + "C1.html" }, |
144 |
}; |
|
145 |
||
146 |
/** |
|
147 |
* Assign value for [ stringToFind, filename ] for split index page |
|
148 |
*/ |
|
149 |
private static final String[][] testSplitIndexArray = { |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
150 |
{ "<title>C-Index</title>", |
10 | 151 |
TMPDIR_STRING2 + "index-files" + FS + "index-1.html" }, |
152 |
}; |
|
153 |
||
154 |
public static void runTestsOnHTML(String[][] testArray) { |
|
155 |
||
156 |
for (int i = 0; i < testArray.length; i++) { |
|
157 |
||
158 |
subtestNum += 1; |
|
159 |
||
160 |
// Read contents of file into a string |
|
161 |
String fileString = readFileToString(testArray[i][1]); |
|
162 |
||
163 |
// Get string to find |
|
164 |
String stringToFind = testArray[i][0]; |
|
165 |
||
166 |
// Find string in file's contents |
|
167 |
if (findString(fileString, stringToFind) == -1) { |
|
168 |
System.out.println("\nSub-test " + (subtestNum) |
|
169 |
+ " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n" |
|
170 |
+ "when searching for:\n" |
|
171 |
+ stringToFind); |
|
172 |
} else { |
|
173 |
numSubtestsPassed += 1; |
|
174 |
System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind); |
|
175 |
} |
|
176 |
} |
|
177 |
} |
|
178 |
||
179 |
public static void printSummary() { |
|
180 |
if ( numSubtestsPassed == subtestNum ) { |
|
181 |
System.out.println("\nAll " + numSubtestsPassed + " subtests passed"); |
|
182 |
} else { |
|
183 |
throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum) |
|
184 |
+ " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n"); |
|
185 |
} |
|
186 |
} |
|
187 |
||
188 |
// Read the file into a String |
|
189 |
public static String readFileToString(String filename) { |
|
190 |
try { |
|
191 |
File file = new File(filename); |
|
192 |
if ( !file.exists() ) { |
|
193 |
System.out.println("\nFILE DOES NOT EXIST: " + filename); |
|
194 |
} |
|
195 |
BufferedReader in = new BufferedReader(new FileReader(file)); |
|
196 |
||
197 |
// Create an array of characters the size of the file |
|
198 |
char[] allChars = new char[(int)file.length()]; |
|
199 |
||
200 |
// Read the characters into the allChars array |
|
201 |
in.read(allChars, 0, (int)file.length()); |
|
202 |
in.close(); |
|
203 |
||
204 |
// Convert to a string |
|
205 |
String allCharsString = new String(allChars); |
|
206 |
||
207 |
return allCharsString; |
|
208 |
||
209 |
} catch (FileNotFoundException e) { |
|
210 |
System.err.println(e); |
|
211 |
return ""; |
|
212 |
} catch (IOException e) { |
|
213 |
System.err.println(e); |
|
214 |
return ""; |
|
215 |
} |
|
216 |
} |
|
217 |
||
218 |
public static int findString(String fileString, String stringToFind) { |
|
219 |
return fileString.indexOf(stringToFind); |
|
220 |
} |
|
221 |
} |