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/WindowTitles/WindowTitles.java
48580 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 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
97
{ "<title>Overview</title>",
98
TMPDIR_STRING1 + "overview-summary.html" },
99
100
{ "<title>Class Hierarchy</title>",
101
TMPDIR_STRING1 + "overview-tree.html" },
102
103
{ "<title>Overview List</title>",
104
TMPDIR_STRING1 + "overview-frame.html" },
105
106
{ "<title>p1</title>",
107
TMPDIR_STRING1 + "p1" + FS + "package-summary.html" },
108
109
{ "<title>p1</title>",
110
TMPDIR_STRING1 + "p1" + FS + "package-frame.html" },
111
112
{ "<title>p1 Class Hierarchy</title>",
113
TMPDIR_STRING1 + "p1" + FS + "package-tree.html" },
114
115
{ "<title>Uses of Package p1</title>",
116
TMPDIR_STRING1 + "p1" + FS + "package-use.html" },
117
118
{ "<title>C1</title>",
119
TMPDIR_STRING1 + "p1" + FS + "C1.html" },
120
121
{ "<title>All Classes</title>",
122
TMPDIR_STRING1 + "allclasses-frame.html" },
123
124
{ "<title>All Classes</title>",
125
TMPDIR_STRING1 + "allclasses-noframe.html" },
126
127
{ "<title>Constant Field Values</title>",
128
TMPDIR_STRING1 + "constant-values.html" },
129
130
{ "<title>Deprecated List</title>",
131
TMPDIR_STRING1 + "deprecated-list.html" },
132
133
{ "<title>Serialized Form</title>",
134
TMPDIR_STRING1 + "serialized-form.html" },
135
136
{ "<title>API Help</title>",
137
TMPDIR_STRING1 + "help-doc.html" },
138
139
{ "<title>Index</title>",
140
TMPDIR_STRING1 + "index-all.html" },
141
142
{ "<title>Uses of Class p1.C1</title>",
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 = {
150
{ "<title>C-Index</title>",
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
}
222
223