Thu, 15 Dec 2011 15:47:47 -0800
Added tag jdk8-b16 for changeset ec2c0973cc31
1 /*
2 * Copyright (c) 2002, 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 */
24 /*
25 * @test
26 * @bug 4636655
27 * @summary Add title attribute to <FRAME> tags for accessibility
28 * @author dkramer
29 * @run main AccessFrameTitle
30 */
33 import com.sun.javadoc.*;
34 import java.util.*;
35 import java.io.*;
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 {
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;
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;
57 // Entry point
58 public static void main(String[] args) {
60 // Directory that contains source files that javadoc runs on
61 String srcdir = System.getProperty("test.src", ".");
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);
69 printSummary();
70 }
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 }
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 = {
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
90 { "title=\"All classes and interfaces (except non-static nested types)\"",
91 TMPDEST_DIR1 + "index.html" },
93 { "title=\"All Packages\"",
94 TMPDEST_DIR1 + "index.html" },
96 { "title=\"Package, class and interface descriptions\"",
97 TMPDEST_DIR1 + "index.html" },
99 };
101 public static void runTestsOnHTML(String[][] testArray) {
103 for (int i = 0; i < testArray.length; i++) {
105 subtestNum += 1;
107 // Read contents of file into a string
108 String fileString = readFileToString(testArray[i][1]);
110 // Get string to find
111 String stringToFind = testArray[i][0];
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 }
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 }
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));
144 // Create an array of characters the size of the file
145 char[] allChars = new char[(int)file.length()];
147 // Read the characters into the allChars array
148 in.read(allChars, 0, (int)file.length());
149 in.close();
151 // Convert to a string
152 String allCharsString = new String(allChars);
154 return allCharsString;
156 } catch (FileNotFoundException e) {
157 System.err.println(e);
158 return "";
159 } catch (IOException e) {
160 System.err.println(e);
161 return "";
162 }
163 }
165 public static int findString(String fileString, String stringToFind) {
166 return fileString.indexOf(stringToFind);
167 }
168 }