Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/com/sun/javadoc/WindowTitles/WindowTitles.java
48580 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 453073026* @summary stddoclet: With frames off, window titles have "()" appended27* @author dkramer28* @run main WindowTitles29*/303132import com.sun.javadoc.*;33import java.util.*;34import java.io.*;3536// If needing regular expression pattern matching,37// see /java/pubs/dev/linkfix/src/LinkFix.java3839/**40* Runs javadoc and runs regression tests on the resulting HTML.41* It reads each file, complete with newlines, into a string to easily42* find strings that contain newlines.43*/44public class WindowTitles45{46private static final String BUGID = "4530730";47private static final String BUGNAME = "WindowTitles";48private static final String FS = System.getProperty("file.separator");49private static final String PS = System.getProperty("path.separator");50private static final String LS = System.getProperty("line.separator");51private static final String TMPDIR_STRING1 = "." + FS + "docs1" + FS;52private static final String TMPDIR_STRING2 = "." + FS + "docs2" + FS;5354// Subtest number. Needed because runResultsOnHTML is run twice, and subtestNum55// should increment across subtest runs.56public static int subtestNum = 0;57public static int numSubtestsPassed = 0;5859// Entry point60public static void main(String[] args) {6162// Directory that contains source files that javadoc runs on63String srcdir = System.getProperty("test.src", ".");6465// Test for all cases except the split index page66runJavadoc(new String[] {"-d", TMPDIR_STRING1,67"-use",68"-sourcepath", srcdir,69"p1", "p2"});70runTestsOnHTML(testArray);7172// Test only for the split-index case (and run on only one package)73System.out.println(""); // blank line74runJavadoc(new String[] {"-d", TMPDIR_STRING2,75"-splitindex",76"-sourcepath", System.getProperty("test.src", "."),77"p1"});78runTestsOnHTML(testSplitIndexArray);7980printSummary();81}8283/** Run javadoc */84public static void runJavadoc(String[] javadocArgs) {85if (com.sun.tools.javadoc.Main.execute(javadocArgs) != 0) {86throw new Error("Javadoc failed to execute");87}88}8990/**91* Assign value for [ stringToFind, filename ]92* NOTE: The standard doclet uses platform-specific line separators (LS)93*/94private static final String[][] testArray = {9596{ "<title>Overview</title>",97TMPDIR_STRING1 + "overview-summary.html" },9899{ "<title>Class Hierarchy</title>",100TMPDIR_STRING1 + "overview-tree.html" },101102{ "<title>Overview List</title>",103TMPDIR_STRING1 + "overview-frame.html" },104105{ "<title>p1</title>",106TMPDIR_STRING1 + "p1" + FS + "package-summary.html" },107108{ "<title>p1</title>",109TMPDIR_STRING1 + "p1" + FS + "package-frame.html" },110111{ "<title>p1 Class Hierarchy</title>",112TMPDIR_STRING1 + "p1" + FS + "package-tree.html" },113114{ "<title>Uses of Package p1</title>",115TMPDIR_STRING1 + "p1" + FS + "package-use.html" },116117{ "<title>C1</title>",118TMPDIR_STRING1 + "p1" + FS + "C1.html" },119120{ "<title>All Classes</title>",121TMPDIR_STRING1 + "allclasses-frame.html" },122123{ "<title>All Classes</title>",124TMPDIR_STRING1 + "allclasses-noframe.html" },125126{ "<title>Constant Field Values</title>",127TMPDIR_STRING1 + "constant-values.html" },128129{ "<title>Deprecated List</title>",130TMPDIR_STRING1 + "deprecated-list.html" },131132{ "<title>Serialized Form</title>",133TMPDIR_STRING1 + "serialized-form.html" },134135{ "<title>API Help</title>",136TMPDIR_STRING1 + "help-doc.html" },137138{ "<title>Index</title>",139TMPDIR_STRING1 + "index-all.html" },140141{ "<title>Uses of Class p1.C1</title>",142TMPDIR_STRING1 + "p1" + FS + "class-use" + FS + "C1.html" },143};144145/**146* Assign value for [ stringToFind, filename ] for split index page147*/148private static final String[][] testSplitIndexArray = {149{ "<title>C-Index</title>",150TMPDIR_STRING2 + "index-files" + FS + "index-1.html" },151};152153public static void runTestsOnHTML(String[][] testArray) {154155for (int i = 0; i < testArray.length; i++) {156157subtestNum += 1;158159// Read contents of file into a string160String fileString = readFileToString(testArray[i][1]);161162// Get string to find163String stringToFind = testArray[i][0];164165// Find string in file's contents166if (findString(fileString, stringToFind) == -1) {167System.out.println("\nSub-test " + (subtestNum)168+ " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n"169+ "when searching for:\n"170+ stringToFind);171} else {172numSubtestsPassed += 1;173System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind);174}175}176}177178public static void printSummary() {179if ( numSubtestsPassed == subtestNum ) {180System.out.println("\nAll " + numSubtestsPassed + " subtests passed");181} else {182throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum)183+ " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n");184}185}186187// Read the file into a String188public static String readFileToString(String filename) {189try {190File file = new File(filename);191if ( !file.exists() ) {192System.out.println("\nFILE DOES NOT EXIST: " + filename);193}194BufferedReader in = new BufferedReader(new FileReader(file));195196// Create an array of characters the size of the file197char[] allChars = new char[(int)file.length()];198199// Read the characters into the allChars array200in.read(allChars, 0, (int)file.length());201in.close();202203// Convert to a string204String allCharsString = new String(allChars);205206return allCharsString;207208} catch (FileNotFoundException e) {209System.err.println(e);210return "";211} catch (IOException e) {212System.err.println(e);213return "";214}215}216217public static int findString(String fileString, String stringToFind) {218return fileString.indexOf(stringToFind);219}220}221222223