test/com/sun/javadoc/ValidHtml/ValidHtml.java

changeset 1
9a66ca7c79fa
child 554
9d9f26857129
equal deleted inserted replaced
-1:000000000000 1:9a66ca7c79fa
1 /*
2 * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved.
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 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
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
37 import com.sun.javadoc.*;
38 import java.util.*;
39 import java.io.*;
40
41
42 /**
43 * Runs javadoc and runs regression tests on the resulting HTML.
44 * It reads each file, complete with newlines, into a string to easily
45 * find strings that contain newlines.
46 */
47 public class ValidHtml {
48
49 private static final String BUGID = "4275630";
50 private static final String BUGNAME = "ValidHtml";
51 private static final String FS = System.getProperty("file.separator");
52 private static final String PS = System.getProperty("path.separator");
53 private static final String LS = System.getProperty("line.separator");
54 private static final String TMPDEST_DIR1 = "." + FS + "docs1" + FS;
55 private static final String TMPDEST_DIR2 = "." + FS + "docs2" + FS;
56
57 // Subtest number. Needed because runResultsOnHTML is run twice,
58 // and subtestNum should increment across subtest runs.
59 public static int subtestNum = 0;
60 public static int numSubtestsPassed = 0;
61
62 // Entry point
63 public static void main(String[] args) {
64
65 // Directory that contains source files that javadoc runs on
66 String srcdir = System.getProperty("test.src", ".");
67
68 // Test for all cases except the split index page
69 runJavadoc(new String[] {"-d", TMPDEST_DIR1,
70 "-doctitle", "Document Title",
71 "-windowtitle", "Window Title",
72 "-use",
73 "-overview", (srcdir + FS + "overview.html"),
74 "-sourcepath", srcdir,
75 "p1", "p2"});
76 runTestsOnHTML(testArray);
77
78 printSummary();
79 }
80
81 /** Run javadoc */
82 public static void runJavadoc(String[] javadocArgs) {
83 if (com.sun.tools.javadoc.Main.execute(javadocArgs) != 0) {
84 throw new Error("Javadoc failed to execute");
85 }
86 }
87
88 /**
89 * Assign value for [ stringToFind, filename ]
90 * NOTE: The standard doclet uses the same separator "\n" for all OS's
91 */
92 private static final String[][] testArray = {
93
94 // Test the proper DOCTYPE element is present:
95 {
96 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">",
97 TMPDEST_DIR1 + "index.html" },
98
99 // Test the proper DOCTYPE element is present:
100 {
101 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
102 TMPDEST_DIR1 + "overview-summary.html" },
103
104 // Test the proper DOCTYPE element is present:
105 {
106 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
107 TMPDEST_DIR1 + "p1" + FS + "package-summary.html" },
108
109 // Test the proper DOCTYPE element is present:
110 {
111 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
112 TMPDEST_DIR1 + "p1" + FS + "C.html" },
113
114 // Test the proper DOCTYPE element is present:
115 {
116 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
117 TMPDEST_DIR1 + "overview-frame.html" },
118
119 // Test the proper DOCTYPE element is present:
120 {
121 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
122 TMPDEST_DIR1 + "allclasses-frame.html" },
123
124 // Test the proper DOCTYPE element is present:
125 {
126 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
127 TMPDEST_DIR1 + "p1" + FS + "package-frame.html" },
128
129 // Test that <NOFRAMES> is inside <FRAMESET> element:
130 {
131 "</NOFRAMES>" + LS + "</FRAMESET>",
132 TMPDEST_DIR1 + "index.html" },
133
134 // Test the table elements are in the correct order:
135 {
136 "</FONT></TD>" + LS + "</TR>",
137 TMPDEST_DIR1 + FS + "p1" + FS + "package-use.html" }
138
139 };
140
141 public static void runTestsOnHTML(String[][] testArray) {
142
143 for (int i = 0; i < testArray.length; i++) {
144
145 subtestNum += 1;
146
147 // Read contents of file into a string
148 String fileString = readFileToString(testArray[i][1]);
149
150 // Get string to find
151 String stringToFind = testArray[i][0];
152
153 // Find string in file's contents
154 if (findString(fileString, stringToFind) == -1) {
155 System.out.println("\nSub-test " + (subtestNum)
156 + " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n"
157 + "when searching for:\n"
158 + stringToFind);
159 } else {
160 numSubtestsPassed += 1;
161 System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind);
162 }
163 }
164 }
165
166 public static void printSummary() {
167 if ( numSubtestsPassed == subtestNum ) {
168 System.out.println("\nAll " + numSubtestsPassed + " subtests passed");
169 } else {
170 throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum)
171 + " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n");
172 }
173 }
174
175 // Read the file into a String
176 public static String readFileToString(String filename) {
177 try {
178 File file = new File(filename);
179 if ( !file.exists() ) {
180 System.out.println("\nFILE DOES NOT EXIST: " + filename);
181 }
182 BufferedReader in = new BufferedReader(new FileReader(file));
183
184 // Create an array of characters the size of the file
185 char[] allChars = new char[(int)file.length()];
186
187 // Read the characters into the allChars array
188 in.read(allChars, 0, (int)file.length());
189 in.close();
190
191 // Convert to a string
192 String allCharsString = new String(allChars);
193
194 return allCharsString;
195
196 } catch (FileNotFoundException e) {
197 System.err.println(e);
198 return "";
199 } catch (IOException e) {
200 System.err.println(e);
201 return "";
202 }
203 }
204
205 public static int findString(String fileString, String stringToFind) {
206 return fileString.indexOf(stringToFind);
207 }
208 }

mercurial