test/com/sun/javadoc/AccessAsciiArt/AccessAsciiArt.java

Thu, 31 Aug 2017 15:17:03 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:17:03 +0800
changeset 2525
2eb010b6cb22
parent 798
4868a36f6fd8
parent 0
959103a6100f
permissions
-rw-r--r--

merge

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

mercurial