Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/com/sun/javadoc/AccessAsciiArt/AccessAsciiArt.java
48498 views
/*1* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 4706779 495690826* @summary Add text equivalent of class tree ASCII art for accessibility27* @author dkramer28* @run main AccessAsciiArt29*/303132import com.sun.javadoc.*;33import java.util.*;34import java.io.*;353637/**38* Runs javadoc and runs regression tests on the resulting HTML.39* It reads each file, complete with newlines, into a string to easily40* find strings that contain newlines.41*/42public class AccessAsciiArt {4344private static final String BUGID = "4706779-4956908";45private static final String BUGNAME = "AccessAsciiArt";46private static final String FS = System.getProperty("file.separator");47private static final String PS = System.getProperty("path.separator");48private static final String TMPDEST_DIR1 = "." + FS + "docs1" + FS;49private static final String TMPDEST_DIR2 = "." + FS + "docs2" + FS;5051// Subtest number. Needed because runResultsOnHTML is run twice,52// and subtestNum should increment across subtest runs.53public static int subtestNum = 0;54public static int numSubtestsPassed = 0;5556// Entry point57public static void main(String[] args) {5859// Directory that contains source files that javadoc runs on60String srcdir = System.getProperty("test.src", ".");6162// Test for all cases except the split index page63runJavadoc(new String[] {"-d", TMPDEST_DIR1,64"-sourcepath", srcdir,65"p1", "p1.subpkg"});66runTestsOnHTML(testArray);6768printSummary();69}7071/** Run javadoc */72public static void runJavadoc(String[] javadocArgs) {73if (com.sun.tools.javadoc.Main.execute(javadocArgs) != 0) {74throw new Error("Javadoc failed to execute");75}76}7778/**79* Assign value for [ stringToFind, filename ]80* NOTE: The standard doclet uses the same separator "\n" for all OS's81*/82private static final String[][] testArray = {8384// Test the top line of the class tree85{86"<li><a href=\"../../p1/C.html\" title=\"class in p1\">p1.C</a></li>",87TMPDEST_DIR1 + "p1" + FS + "subpkg" + FS + "SSC.html" },8889// Test the second line of the class tree90{91"<li><a href=\"../../p1/SC.html\" title=\"class in p1\">p1.SC</a></li>",92TMPDEST_DIR1 + "p1" + FS + "subpkg" + FS + "SSC.html" },9394// Test the third line of the class tree95{96"<li>p1.subpkg.SSC</li>",97TMPDEST_DIR1 + "p1" + FS + "subpkg" + FS +"SSC.html" },9899};100101public static void runTestsOnHTML(String[][] testArray) {102103for (int i = 0; i < testArray.length; i++) {104105subtestNum += 1;106107// Read contents of file into a string108String fileString = readFileToString(testArray[i][1]);109110// Get string to find111String stringToFind = testArray[i][0];112113// Find string in file's contents114if (findString(fileString, stringToFind) == -1) {115System.out.println("\nSub-test " + (subtestNum)116+ " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n"117+ "when searching for:\n"118+ stringToFind);119} else {120numSubtestsPassed += 1;121System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind);122}123}124}125126public static void printSummary() {127if ( numSubtestsPassed == subtestNum ) {128System.out.println("\nAll " + numSubtestsPassed + " subtests passed");129} else {130throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum)131+ " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n");132}133}134135// Read the file into a String136public static String readFileToString(String filename) {137try {138File file = new File(filename);139if ( !file.exists() ) {140System.out.println("\nFILE DOES NOT EXIST: " + filename);141}142BufferedReader in = new BufferedReader(new FileReader(file));143144// Create an array of characters the size of the file145char[] allChars = new char[(int)file.length()];146147// Read the characters into the allChars array148in.read(allChars, 0, (int)file.length());149in.close();150151// Convert to a string152String allCharsString = new String(allChars);153154return allCharsString;155156} catch (FileNotFoundException e) {157System.err.println(e);158return "";159} catch (IOException e) {160System.err.println(e);161return "";162}163}164165public static int findString(String fileString, String stringToFind) {166return fileString.indexOf(stringToFind);167}168}169170171