Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/com/sun/javadoc/VersionNumber/VersionNumber.java
86410 views
/*1* Copyright (c) 2002, 2012, 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 472084926* @summary com.sun.tools.doclets.standard.Standard contains hard-coded version number27* @author dkramer28* @run main VersionNumber29*/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 VersionNumber {4344private static final String BUGID = "4720849";45private static final String BUGNAME = "VersionNumber";46private static final String FS = System.getProperty("file.separator");47private static final String PS = System.getProperty("path.separator");48private static final String LS = System.getProperty("line.separator");49private static final String TMPDEST_DIR1 = "." + FS + "docs1" + FS;50private static final String TMPDEST_DIR2 = "." + FS + "docs2" + FS;5152// Subtest number. Needed because runResultsOnHTML is run twice,53// and subtestNum should increment across subtest runs.54public static int subtestNum = 0;55public static int numSubtestsPassed = 0;5657// Entry point58public static void main(String[] args) {5960// Directory that contains source files that javadoc runs on61String srcdir = System.getProperty("test.src", ".");6263// Test for all cases except the split index page64runJavadoc(new String[] {"-d", TMPDEST_DIR1,65"p1"});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 proper DOCTYPE element is present:85{86"<!-- Generated by javadoc (",87TMPDEST_DIR1 + "p1" + FS + "C.html" },8889};9091public static void runTestsOnHTML(String[][] testArray) {9293for (int i = 0; i < testArray.length; i++) {9495subtestNum += 1;9697// Read contents of file into a string98String fileString = readFileToString(testArray[i][1]);99100// Get string to find101String stringToFind = testArray[i][0];102103// Find string in file's contents104if (findString(fileString, stringToFind) == -1) {105System.out.println("\nSub-test " + (subtestNum)106+ " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n"107+ "when searching for:\n"108+ stringToFind);109} else {110numSubtestsPassed += 1;111System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind);112}113}114}115116public static void printSummary() {117if ( numSubtestsPassed == subtestNum ) {118System.out.println("\nAll " + numSubtestsPassed + " subtests passed");119} else {120throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum)121+ " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n");122}123}124125// Read the file into a String126public static String readFileToString(String filename) {127try {128File file = new File(filename);129if ( !file.exists() ) {130System.out.println("\nFILE DOES NOT EXIST: " + filename);131}132BufferedReader in = new BufferedReader(new FileReader(file));133134// Create an array of characters the size of the file135char[] allChars = new char[(int)file.length()];136137// Read the characters into the allChars array138in.read(allChars, 0, (int)file.length());139in.close();140141// Convert to a string142String allCharsString = new String(allChars);143144return allCharsString;145146} catch (FileNotFoundException e) {147System.err.println(e);148return "";149} catch (IOException e) {150System.err.println(e);151return "";152}153}154155public static int findString(String fileString, String stringToFind) {156return fileString.indexOf(stringToFind);157}158}159160161