|
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 4636655 |
|
27 * @summary Add title attribute to <FRAME> tags for accessibility |
|
28 * @author dkramer |
|
29 * @run main AccessFrameTitle |
|
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 AccessFrameTitle { |
|
44 |
|
45 private static final String BUGID = "4636655"; |
|
46 private static final String BUGNAME = "AccessFrameTitle"; |
|
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", "p2"}); |
|
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 // Testing only for the presence of the title attributes. |
|
86 // To make this test more robust, only |
|
87 // the initial part of each title string is tested for, |
|
88 // in case the ending part of the string later changes |
|
89 |
|
90 { "title=\"All classes and interfaces (except non-static nested types)\"", |
|
91 TMPDEST_DIR1 + "index.html" }, |
|
92 |
|
93 { "title=\"All Packages\"", |
|
94 TMPDEST_DIR1 + "index.html" }, |
|
95 |
|
96 { "title=\"Package, class and interface descriptions\"", |
|
97 TMPDEST_DIR1 + "index.html" }, |
|
98 |
|
99 }; |
|
100 |
|
101 public static void runTestsOnHTML(String[][] testArray) { |
|
102 |
|
103 for (int i = 0; i < testArray.length; i++) { |
|
104 |
|
105 subtestNum += 1; |
|
106 |
|
107 // Read contents of file into a string |
|
108 String fileString = readFileToString(testArray[i][1]); |
|
109 |
|
110 // Get string to find |
|
111 String stringToFind = testArray[i][0]; |
|
112 |
|
113 // Find string in file's contents |
|
114 if (findString(fileString, stringToFind) == -1) { |
|
115 System.out.println("\nSub-test " + (subtestNum) |
|
116 + " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n" |
|
117 + "when searching for:\n" |
|
118 + stringToFind); |
|
119 } else { |
|
120 numSubtestsPassed += 1; |
|
121 System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind); |
|
122 } |
|
123 } |
|
124 } |
|
125 |
|
126 public static void printSummary() { |
|
127 if ( numSubtestsPassed == subtestNum ) { |
|
128 System.out.println("\nAll " + numSubtestsPassed + " subtests passed"); |
|
129 } else { |
|
130 throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum) |
|
131 + " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n"); |
|
132 } |
|
133 } |
|
134 |
|
135 // Read the file into a String |
|
136 public static String readFileToString(String filename) { |
|
137 try { |
|
138 File file = new File(filename); |
|
139 if ( !file.exists() ) { |
|
140 System.out.println("\nFILE DOES NOT EXIST: " + filename); |
|
141 } |
|
142 BufferedReader in = new BufferedReader(new FileReader(file)); |
|
143 |
|
144 // Create an array of characters the size of the file |
|
145 char[] allChars = new char[(int)file.length()]; |
|
146 |
|
147 // Read the characters into the allChars array |
|
148 in.read(allChars, 0, (int)file.length()); |
|
149 in.close(); |
|
150 |
|
151 // Convert to a string |
|
152 String allCharsString = new String(allChars); |
|
153 |
|
154 return allCharsString; |
|
155 |
|
156 } catch (FileNotFoundException e) { |
|
157 System.err.println(e); |
|
158 return ""; |
|
159 } catch (IOException e) { |
|
160 System.err.println(e); |
|
161 return ""; |
|
162 } |
|
163 } |
|
164 |
|
165 public static int findString(String fileString, String stringToFind) { |
|
166 return fileString.indexOf(stringToFind); |
|
167 } |
|
168 } |