Wed, 27 Apr 2016 01:34:52 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | */ |
aoqi@0 | 23 | |
aoqi@0 | 24 | /* |
aoqi@0 | 25 | * @test |
aoqi@0 | 26 | * @bug 4638136 7198273 8025633 |
aoqi@0 | 27 | * @summary Add ability to skip over nav bar for accessibility |
aoqi@0 | 28 | * @author dkramer |
aoqi@0 | 29 | * @run main AccessSkipNav |
aoqi@0 | 30 | */ |
aoqi@0 | 31 | |
aoqi@0 | 32 | |
aoqi@0 | 33 | import com.sun.javadoc.*; |
aoqi@0 | 34 | import java.util.*; |
aoqi@0 | 35 | import java.io.*; |
aoqi@0 | 36 | |
aoqi@0 | 37 | |
aoqi@0 | 38 | /** |
aoqi@0 | 39 | * Runs javadoc and runs regression tests on the resulting HTML. |
aoqi@0 | 40 | * It reads each file, complete with newlines, into a string to easily |
aoqi@0 | 41 | * find strings that contain newlines. |
aoqi@0 | 42 | */ |
aoqi@0 | 43 | public class AccessSkipNav { |
aoqi@0 | 44 | |
aoqi@0 | 45 | private static final String BUGID = "4638136 - 7198273"; |
aoqi@0 | 46 | private static final String BUGNAME = "AccessSkipNav"; |
aoqi@0 | 47 | private static final String FS = System.getProperty("file.separator"); |
aoqi@0 | 48 | private static final String PS = System.getProperty("path.separator"); |
aoqi@0 | 49 | private static final String LS = System.getProperty("line.separator"); |
aoqi@0 | 50 | private static final String TMPDEST_DIR1 = "." + FS + "docs1" + FS; |
aoqi@0 | 51 | private static final String TMPDEST_DIR2 = "." + FS + "docs2" + FS; |
aoqi@0 | 52 | |
aoqi@0 | 53 | // Subtest number. Needed because runResultsOnHTML is run twice, |
aoqi@0 | 54 | // and subtestNum should increment across subtest runs. |
aoqi@0 | 55 | public static int subtestNum = 0; |
aoqi@0 | 56 | public static int numSubtestsPassed = 0; |
aoqi@0 | 57 | |
aoqi@0 | 58 | // Entry point |
aoqi@0 | 59 | public static void main(String[] args) { |
aoqi@0 | 60 | |
aoqi@0 | 61 | // Directory that contains source files that javadoc runs on |
aoqi@0 | 62 | String srcdir = System.getProperty("test.src", "."); |
aoqi@0 | 63 | |
aoqi@0 | 64 | // Test for all cases except the split index page |
aoqi@0 | 65 | runJavadoc(new String[] {"-d", TMPDEST_DIR1, |
aoqi@0 | 66 | "-sourcepath", srcdir, |
aoqi@0 | 67 | "p1", "p2"}); |
aoqi@0 | 68 | runTestsOnHTML(testArray); |
aoqi@0 | 69 | |
aoqi@0 | 70 | printSummary(); |
aoqi@0 | 71 | } |
aoqi@0 | 72 | |
aoqi@0 | 73 | /** Run javadoc */ |
aoqi@0 | 74 | public static void runJavadoc(String[] javadocArgs) { |
aoqi@0 | 75 | if (com.sun.tools.javadoc.Main.execute(javadocArgs) != 0) { |
aoqi@0 | 76 | throw new Error("Javadoc failed to execute"); |
aoqi@0 | 77 | } |
aoqi@0 | 78 | } |
aoqi@0 | 79 | |
aoqi@0 | 80 | /** |
aoqi@0 | 81 | * Assign value for [ stringToFind, filename ] |
aoqi@0 | 82 | * NOTE: The standard doclet uses the same separator "\n" for all OS's |
aoqi@0 | 83 | */ |
aoqi@0 | 84 | private static final String[][] testArray = { |
aoqi@0 | 85 | |
aoqi@0 | 86 | // Testing only for the presence of the <a href> and <a name> |
aoqi@0 | 87 | |
aoqi@0 | 88 | // Top navbar <a href> |
aoqi@0 | 89 | { "<a href=\"#skip.navbar.top\" title=\"Skip navigation links\">Skip navigation links</a>", |
aoqi@0 | 90 | TMPDEST_DIR1 + "p1" + FS + "C1.html" }, |
aoqi@0 | 91 | |
aoqi@0 | 92 | // Top navbar <a name> |
aoqi@0 | 93 | { "<a name=\"skip.navbar.top\">" + LS + |
aoqi@0 | 94 | "<!-- -->" + LS + "</a>", |
aoqi@0 | 95 | TMPDEST_DIR1 + "p1" + FS + "C1.html" }, |
aoqi@0 | 96 | |
aoqi@0 | 97 | // Bottom navbar <a href> |
aoqi@0 | 98 | { "<a href=\"#skip.navbar.bottom\" title=\"Skip navigation links\">Skip navigation links</a>", |
aoqi@0 | 99 | TMPDEST_DIR1 + "p1" + FS + "C1.html" }, |
aoqi@0 | 100 | |
aoqi@0 | 101 | // Bottom navbar <a name> |
aoqi@0 | 102 | { "<a name=\"skip.navbar.bottom\">" + LS + |
aoqi@0 | 103 | "<!-- -->" + LS + "</a>", |
aoqi@0 | 104 | TMPDEST_DIR1 + "p1" + FS + "C1.html" } |
aoqi@0 | 105 | }; |
aoqi@0 | 106 | |
aoqi@0 | 107 | public static void runTestsOnHTML(String[][] testArray) { |
aoqi@0 | 108 | |
aoqi@0 | 109 | for (int i = 0; i < testArray.length; i++) { |
aoqi@0 | 110 | |
aoqi@0 | 111 | subtestNum += 1; |
aoqi@0 | 112 | |
aoqi@0 | 113 | // Read contents of file into a string |
aoqi@0 | 114 | String fileString = readFileToString(testArray[i][1]); |
aoqi@0 | 115 | |
aoqi@0 | 116 | // Get string to find |
aoqi@0 | 117 | String stringToFind = testArray[i][0]; |
aoqi@0 | 118 | |
aoqi@0 | 119 | // Find string in file's contents |
aoqi@0 | 120 | if (findString(fileString, stringToFind) == -1) { |
aoqi@0 | 121 | System.out.println("\nSub-test " + (subtestNum) |
aoqi@0 | 122 | + " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n" |
aoqi@0 | 123 | + "when searching for:\n" |
aoqi@0 | 124 | + stringToFind); |
aoqi@0 | 125 | } else { |
aoqi@0 | 126 | numSubtestsPassed += 1; |
aoqi@0 | 127 | System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind); |
aoqi@0 | 128 | } |
aoqi@0 | 129 | } |
aoqi@0 | 130 | } |
aoqi@0 | 131 | |
aoqi@0 | 132 | public static void printSummary() { |
aoqi@0 | 133 | if ( numSubtestsPassed == subtestNum ) { |
aoqi@0 | 134 | System.out.println("\nAll " + numSubtestsPassed + " subtests passed"); |
aoqi@0 | 135 | } else { |
aoqi@0 | 136 | throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum) |
aoqi@0 | 137 | + " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n"); |
aoqi@0 | 138 | } |
aoqi@0 | 139 | } |
aoqi@0 | 140 | |
aoqi@0 | 141 | // Read the file into a String |
aoqi@0 | 142 | public static String readFileToString(String filename) { |
aoqi@0 | 143 | try { |
aoqi@0 | 144 | File file = new File(filename); |
aoqi@0 | 145 | if ( !file.exists() ) { |
aoqi@0 | 146 | System.out.println("\nFILE DOES NOT EXIST: " + filename); |
aoqi@0 | 147 | } |
aoqi@0 | 148 | BufferedReader in = new BufferedReader(new FileReader(file)); |
aoqi@0 | 149 | |
aoqi@0 | 150 | // Create an array of characters the size of the file |
aoqi@0 | 151 | char[] allChars = new char[(int)file.length()]; |
aoqi@0 | 152 | |
aoqi@0 | 153 | // Read the characters into the allChars array |
aoqi@0 | 154 | in.read(allChars, 0, (int)file.length()); |
aoqi@0 | 155 | in.close(); |
aoqi@0 | 156 | |
aoqi@0 | 157 | // Convert to a string |
aoqi@0 | 158 | String allCharsString = new String(allChars); |
aoqi@0 | 159 | |
aoqi@0 | 160 | return allCharsString; |
aoqi@0 | 161 | |
aoqi@0 | 162 | } catch (FileNotFoundException e) { |
aoqi@0 | 163 | System.err.println(e); |
aoqi@0 | 164 | return ""; |
aoqi@0 | 165 | } catch (IOException e) { |
aoqi@0 | 166 | System.err.println(e); |
aoqi@0 | 167 | return ""; |
aoqi@0 | 168 | } |
aoqi@0 | 169 | } |
aoqi@0 | 170 | |
aoqi@0 | 171 | public static int findString(String fileString, String stringToFind) { |
aoqi@0 | 172 | return fileString.indexOf(stringToFind); |
aoqi@0 | 173 | } |
aoqi@0 | 174 | } |