10
|
1 |
/*
|
|
2 |
* Copyright 2002-2003 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 4706779 4956908
|
|
27 |
* @summary Add text equivalent of class tree ASCII art for accessibility
|
|
28 |
* @author dkramer
|
|
29 |
* @run main AccessAsciiArt
|
|
30 |
*/
|
|
31 |
|
|
32 |
|
|
33 |
import com.sun.javadoc.*;
|
|
34 |
import java.util.*;
|
|
35 |
import java.io.*;
|
|
36 |
|
|
37 |
|
|
38 |
/**
|
|
39 |
* Runs javadoc and runs regression tests on the resulting HTML.
|
|
40 |
* It reads each file, complete with newlines, into a string to easily
|
|
41 |
* find strings that contain newlines.
|
|
42 |
*/
|
|
43 |
public class AccessAsciiArt {
|
|
44 |
|
|
45 |
private static final String BUGID = "4706779-4956908";
|
|
46 |
private static final String BUGNAME = "AccessAsciiArt";
|
|
47 |
private static final String FS = System.getProperty("file.separator");
|
|
48 |
private static final String PS = System.getProperty("path.separator");
|
|
49 |
private static final String TMPDEST_DIR1 = "." + FS + "docs1" + FS;
|
|
50 |
private static final String TMPDEST_DIR2 = "." + FS + "docs2" + FS;
|
|
51 |
|
|
52 |
// Subtest number. Needed because runResultsOnHTML is run twice,
|
|
53 |
// and subtestNum should increment across subtest runs.
|
|
54 |
public static int subtestNum = 0;
|
|
55 |
public static int numSubtestsPassed = 0;
|
|
56 |
|
|
57 |
// Entry point
|
|
58 |
public static void main(String[] args) {
|
|
59 |
|
|
60 |
// Directory that contains source files that javadoc runs on
|
|
61 |
String srcdir = System.getProperty("test.src", ".");
|
|
62 |
|
|
63 |
// Test for all cases except the split index page
|
|
64 |
runJavadoc(new String[] {"-d", TMPDEST_DIR1,
|
|
65 |
"-sourcepath", srcdir,
|
|
66 |
"p1", "p1.subpkg"});
|
|
67 |
runTestsOnHTML(testArray);
|
|
68 |
|
|
69 |
printSummary();
|
|
70 |
}
|
|
71 |
|
|
72 |
/** Run javadoc */
|
|
73 |
public static void runJavadoc(String[] javadocArgs) {
|
|
74 |
if (com.sun.tools.javadoc.Main.execute(javadocArgs) != 0) {
|
|
75 |
throw new Error("Javadoc failed to execute");
|
|
76 |
}
|
|
77 |
}
|
|
78 |
|
|
79 |
/**
|
|
80 |
* Assign value for [ stringToFind, filename ]
|
|
81 |
* NOTE: The standard doclet uses the same separator "\n" for all OS's
|
|
82 |
*/
|
|
83 |
private static final String[][] testArray = {
|
|
84 |
|
|
85 |
// Test the top line of the class tree
|
|
86 |
{
|
|
87 |
" <IMG SRC=\"../../resources/inherit.gif\" ALT=\"extended by \"><A HREF=\"../../p1/C.html\" title=\"class in p1\">p1.C</A>",
|
|
88 |
TMPDEST_DIR1 + "p1" + FS + "subpkg" + FS + "SSC.html" },
|
|
89 |
|
|
90 |
// Test the second line of the class tree
|
|
91 |
{
|
|
92 |
" <IMG SRC=\"../../resources/inherit.gif\" ALT=\"extended by \"><A HREF=\"../../p1/SC.html\" title=\"class in p1\">p1.SC</A>",
|
|
93 |
TMPDEST_DIR1 + "p1" + FS + "subpkg" + FS + "SSC.html" },
|
|
94 |
|
|
95 |
// Test the third line of the class tree
|
|
96 |
{
|
|
97 |
" <IMG SRC=\"../../resources/inherit.gif\" ALT=\"extended by \"><B>p1.subpkg.SSC</B>",
|
|
98 |
TMPDEST_DIR1 + "p1" + FS + "subpkg" + FS +"SSC.html" },
|
|
99 |
|
|
100 |
};
|
|
101 |
|
|
102 |
public static void runTestsOnHTML(String[][] testArray) {
|
|
103 |
|
|
104 |
for (int i = 0; i < testArray.length; i++) {
|
|
105 |
|
|
106 |
subtestNum += 1;
|
|
107 |
|
|
108 |
// Read contents of file into a string
|
|
109 |
String fileString = readFileToString(testArray[i][1]);
|
|
110 |
|
|
111 |
// Get string to find
|
|
112 |
String stringToFind = testArray[i][0];
|
|
113 |
|
|
114 |
// Find string in file's contents
|
|
115 |
if (findString(fileString, stringToFind) == -1) {
|
|
116 |
System.out.println("\nSub-test " + (subtestNum)
|
|
117 |
+ " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n"
|
|
118 |
+ "when searching for:\n"
|
|
119 |
+ stringToFind);
|
|
120 |
} else {
|
|
121 |
numSubtestsPassed += 1;
|
|
122 |
System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind);
|
|
123 |
}
|
|
124 |
}
|
|
125 |
}
|
|
126 |
|
|
127 |
public static void printSummary() {
|
|
128 |
if ( numSubtestsPassed == subtestNum ) {
|
|
129 |
System.out.println("\nAll " + numSubtestsPassed + " subtests passed");
|
|
130 |
} else {
|
|
131 |
throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum)
|
|
132 |
+ " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n");
|
|
133 |
}
|
|
134 |
}
|
|
135 |
|
|
136 |
// Read the file into a String
|
|
137 |
public static String readFileToString(String filename) {
|
|
138 |
try {
|
|
139 |
File file = new File(filename);
|
|
140 |
if ( !file.exists() ) {
|
|
141 |
System.out.println("\nFILE DOES NOT EXIST: " + filename);
|
|
142 |
}
|
|
143 |
BufferedReader in = new BufferedReader(new FileReader(file));
|
|
144 |
|
|
145 |
// Create an array of characters the size of the file
|
|
146 |
char[] allChars = new char[(int)file.length()];
|
|
147 |
|
|
148 |
// Read the characters into the allChars array
|
|
149 |
in.read(allChars, 0, (int)file.length());
|
|
150 |
in.close();
|
|
151 |
|
|
152 |
// Convert to a string
|
|
153 |
String allCharsString = new String(allChars);
|
|
154 |
|
|
155 |
return allCharsString;
|
|
156 |
|
|
157 |
} catch (FileNotFoundException e) {
|
|
158 |
System.err.println(e);
|
|
159 |
return "";
|
|
160 |
} catch (IOException e) {
|
|
161 |
System.err.println(e);
|
|
162 |
return "";
|
|
163 |
}
|
|
164 |
}
|
|
165 |
|
|
166 |
public static int findString(String fileString, String stringToFind) {
|
|
167 |
return fileString.indexOf(stringToFind);
|
|
168 |
}
|
|
169 |
}
|