author | lana |
Thu, 20 Jan 2011 10:49:03 -0800 | |
changeset 7957 | 900a9e8d6c4e |
parent 7681 | 1f0819a3341f |
child 23971 | f5ff1f5a8dee |
permissions | -rw-r--r-- |
10 | 1 |
/* |
7681 | 2 |
* Copyright (c) 2002, 2010, 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 4275630 4749453 4625400 4753048 4415270 |
|
27 |
* @summary Generated HTML is invalid with frameset DTD. |
|
28 |
* Displays unnecessary horizontal scroll bars. |
|
29 |
* Missing whitespace in DOCTYPE declaration |
|
30 |
* <NOFRAMES> not allowed outside <FRAMESET> element |
|
31 |
* HTML table tags inserted in wrong place in pakcage use page |
|
32 |
* @author dkramer |
|
33 |
* @run main ValidHtml |
|
34 |
*/ |
|
35 |
||
36 |
import com.sun.javadoc.*; |
|
37 |
import java.util.*; |
|
38 |
import java.io.*; |
|
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 ValidHtml { |
|
46 |
||
47 |
private static final String BUGID = "4275630"; |
|
48 |
private static final String BUGNAME = "ValidHtml"; |
|
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 TMPDEST_DIR1 = "." + FS + "docs1" + FS; |
|
53 |
private static final String TMPDEST_DIR2 = "." + FS + "docs2" + FS; |
|
54 |
||
55 |
// Subtest number. Needed because runResultsOnHTML is run twice, |
|
56 |
// and subtestNum 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 |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
67 |
runJavadoc(new String[]{"-d", TMPDEST_DIR1, |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
68 |
"-doctitle", "Document Title", |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
69 |
"-windowtitle", "Window Title", |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
70 |
"-use", |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
71 |
"-overview", (srcdir + FS + "overview.html"), |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
72 |
"-sourcepath", srcdir, |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
73 |
"p1", "p2" |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
74 |
}); |
10 | 75 |
runTestsOnHTML(testArray); |
76 |
||
77 |
printSummary(); |
|
78 |
} |
|
79 |
||
80 |
/** Run javadoc */ |
|
81 |
public static void runJavadoc(String[] javadocArgs) { |
|
82 |
if (com.sun.tools.javadoc.Main.execute(javadocArgs) != 0) { |
|
83 |
throw new Error("Javadoc failed to execute"); |
|
84 |
} |
|
85 |
} |
|
86 |
||
87 |
/** |
|
88 |
* Assign value for [ stringToFind, filename ] |
|
89 |
* NOTE: The standard doclet uses the same separator "\n" for all OS's |
|
90 |
*/ |
|
91 |
private static final String[][] testArray = { |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
92 |
// Test the proper DOCTYPE element is present: |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
93 |
{ |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
94 |
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">", |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
95 |
TMPDEST_DIR1 + "index.html" |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
96 |
}, |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
97 |
// Test the proper DOCTYPE element is present: |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
98 |
{ |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
99 |
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">", |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
100 |
TMPDEST_DIR1 + "overview-summary.html" |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
101 |
}, |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
102 |
// Test the proper DOCTYPE element is present: |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
103 |
{ |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
104 |
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">", |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
105 |
TMPDEST_DIR1 + "p1" + FS + "package-summary.html" |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
106 |
}, |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
107 |
// Test the proper DOCTYPE element is present: |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
108 |
{ |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
109 |
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">", |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
110 |
TMPDEST_DIR1 + "p1" + FS + "C.html" |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
111 |
}, |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
112 |
// Test the proper DOCTYPE element is present: |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
113 |
{ |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
114 |
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">", |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
115 |
TMPDEST_DIR1 + "overview-frame.html" |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
116 |
}, |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
117 |
// Test the proper DOCTYPE element is present: |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
118 |
{ |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
119 |
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">", |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
120 |
TMPDEST_DIR1 + "allclasses-frame.html" |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
121 |
}, |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
122 |
// Test the proper DOCTYPE element is present: |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
123 |
{ |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
124 |
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">", |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
125 |
TMPDEST_DIR1 + "p1" + FS + "package-frame.html" |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
126 |
}, |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
127 |
// Test that <NOFRAMES> is inside <FRAMESET> element: |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
128 |
{ |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
129 |
"</noframes>" + LS + "</frameset>", |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
130 |
TMPDEST_DIR1 + "index.html" |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
131 |
}, |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
132 |
// Test the table elements are in the correct order: |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
133 |
{ |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
134 |
"</td>" + LS + "</tr>", |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
135 |
TMPDEST_DIR1 + FS + "p1" + FS + "package-use.html" |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
136 |
} |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
137 |
}; |
10 | 138 |
|
139 |
public static void runTestsOnHTML(String[][] testArray) { |
|
140 |
||
141 |
for (int i = 0; i < testArray.length; i++) { |
|
142 |
||
143 |
subtestNum += 1; |
|
144 |
||
145 |
// Read contents of file into a string |
|
146 |
String fileString = readFileToString(testArray[i][1]); |
|
147 |
||
148 |
// Get string to find |
|
149 |
String stringToFind = testArray[i][0]; |
|
150 |
||
151 |
// Find string in file's contents |
|
152 |
if (findString(fileString, stringToFind) == -1) { |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
153 |
System.out.println("\nSub-test " + (subtestNum) + " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n" + "when searching for:\n" + stringToFind); |
10 | 154 |
} else { |
155 |
numSubtestsPassed += 1; |
|
156 |
System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind); |
|
157 |
} |
|
158 |
} |
|
159 |
} |
|
160 |
||
161 |
public static void printSummary() { |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
162 |
if (numSubtestsPassed == subtestNum) { |
10 | 163 |
System.out.println("\nAll " + numSubtestsPassed + " subtests passed"); |
164 |
} else { |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
165 |
throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum) + " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n"); |
10 | 166 |
} |
167 |
} |
|
168 |
||
169 |
// Read the file into a String |
|
170 |
public static String readFileToString(String filename) { |
|
171 |
try { |
|
172 |
File file = new File(filename); |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
173 |
if (!file.exists()) { |
10 | 174 |
System.out.println("\nFILE DOES NOT EXIST: " + filename); |
175 |
} |
|
176 |
BufferedReader in = new BufferedReader(new FileReader(file)); |
|
177 |
||
178 |
// Create an array of characters the size of the file |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
179 |
char[] allChars = new char[(int) file.length()]; |
10 | 180 |
|
181 |
// Read the characters into the allChars array |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
182 |
in.read(allChars, 0, (int) file.length()); |
10 | 183 |
in.close(); |
184 |
||
185 |
// Convert to a string |
|
186 |
String allCharsString = new String(allChars); |
|
187 |
||
188 |
return allCharsString; |
|
189 |
||
190 |
} catch (FileNotFoundException e) { |
|
191 |
System.err.println(e); |
|
192 |
return ""; |
|
193 |
} catch (IOException e) { |
|
194 |
System.err.println(e); |
|
195 |
return ""; |
|
196 |
} |
|
197 |
} |
|
198 |
||
199 |
public static int findString(String fileString, String stringToFind) { |
|
200 |
return fileString.indexOf(stringToFind); |
|
201 |
} |
|
202 |
} |