Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/com/sun/javadoc/ValidHtml/ValidHtml.java
48527 views
1
/*
2
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. 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 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.
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
67
runJavadoc(new String[]{"-d", TMPDEST_DIR1,
68
"-doctitle", "Document Title",
69
"-windowtitle", "Window Title",
70
"-use",
71
"-overview", (srcdir + FS + "overview.html"),
72
"-sourcepath", srcdir,
73
"p1", "p2"
74
});
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 = {
92
// Test the proper DOCTYPE element is present:
93
{
94
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">",
95
TMPDEST_DIR1 + "index.html"
96
},
97
// Test the proper DOCTYPE element is present:
98
{
99
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
100
TMPDEST_DIR1 + "overview-summary.html"
101
},
102
// Test the proper DOCTYPE element is present:
103
{
104
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
105
TMPDEST_DIR1 + "p1" + FS + "package-summary.html"
106
},
107
// Test the proper DOCTYPE element is present:
108
{
109
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
110
TMPDEST_DIR1 + "p1" + FS + "C.html"
111
},
112
// Test the proper DOCTYPE element is present:
113
{
114
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
115
TMPDEST_DIR1 + "overview-frame.html"
116
},
117
// Test the proper DOCTYPE element is present:
118
{
119
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
120
TMPDEST_DIR1 + "allclasses-frame.html"
121
},
122
// Test the proper DOCTYPE element is present:
123
{
124
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
125
TMPDEST_DIR1 + "p1" + FS + "package-frame.html"
126
},
127
// Test that <NOFRAMES> is inside <FRAMESET> element:
128
{
129
"</noframes>" + LS + "</frameset>",
130
TMPDEST_DIR1 + "index.html"
131
},
132
// Test the table elements are in the correct order:
133
{
134
"</td>" + LS + "</tr>",
135
TMPDEST_DIR1 + FS + "p1" + FS + "package-use.html"
136
}
137
};
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) {
153
System.out.println("\nSub-test " + (subtestNum) + " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n" + "when searching for:\n" + stringToFind);
154
} else {
155
numSubtestsPassed += 1;
156
System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind);
157
}
158
}
159
}
160
161
public static void printSummary() {
162
if (numSubtestsPassed == subtestNum) {
163
System.out.println("\nAll " + numSubtestsPassed + " subtests passed");
164
} else {
165
throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum) + " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n");
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);
173
if (!file.exists()) {
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
179
char[] allChars = new char[(int) file.length()];
180
181
// Read the characters into the allChars array
182
in.read(allChars, 0, (int) file.length());
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
}
203
204