Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/com/sun/javadoc/AccessFrameTitle/AccessFrameTitle.java
48425 views
/*1* Copyright (c) 2002, 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 463665526* @summary Add title attribute to <FRAME> tags for accessibility27* @author dkramer28* @run main AccessFrameTitle29*/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 AccessFrameTitle {4344private static final String BUGID = "4636655";45private static final String BUGNAME = "AccessFrameTitle";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", "p2"});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// Testing only for the presence of the title attributes.85// To make this test more robust, only86// the initial part of each title string is tested for,87// in case the ending part of the string later changes8889{ "title=\"All classes and interfaces (except non-static nested types)\"",90TMPDEST_DIR1 + "index.html" },9192{ "title=\"All Packages\"",93TMPDEST_DIR1 + "index.html" },9495{ "title=\"Package, class and interface descriptions\"",96TMPDEST_DIR1 + "index.html" },9798};99100public static void runTestsOnHTML(String[][] testArray) {101102for (int i = 0; i < testArray.length; i++) {103104subtestNum += 1;105106// Read contents of file into a string107String fileString = readFileToString(testArray[i][1]);108109// Get string to find110String stringToFind = testArray[i][0];111112// Find string in file's contents113if (findString(fileString, stringToFind) == -1) {114System.out.println("\nSub-test " + (subtestNum)115+ " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n"116+ "when searching for:\n"117+ stringToFind);118} else {119numSubtestsPassed += 1;120System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind);121}122}123}124125public static void printSummary() {126if ( numSubtestsPassed == subtestNum ) {127System.out.println("\nAll " + numSubtestsPassed + " subtests passed");128} else {129throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum)130+ " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n");131}132}133134// Read the file into a String135public static String readFileToString(String filename) {136try {137File file = new File(filename);138if ( !file.exists() ) {139System.out.println("\nFILE DOES NOT EXIST: " + filename);140}141BufferedReader in = new BufferedReader(new FileReader(file));142143// Create an array of characters the size of the file144char[] allChars = new char[(int)file.length()];145146// Read the characters into the allChars array147in.read(allChars, 0, (int)file.length());148in.close();149150// Convert to a string151String allCharsString = new String(allChars);152153return allCharsString;154155} catch (FileNotFoundException e) {156System.err.println(e);157return "";158} catch (IOException e) {159System.err.println(e);160return "";161}162}163164public static int findString(String fileString, String stringToFind) {165return fileString.indexOf(stringToFind);166}167}168169170