Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/com/sun/javadoc/AuthorDD/AuthorDD.java
48534 views
/*1* Copyright (c) 2002, 2013, 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 4651598 802656726* @summary Javadoc wrongly inserts </DD> tags when using multiple @author tags27* @author dkramer28* @run main AuthorDD29*/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 AuthorDD43{44private static final String BUGID = "4651598";45private static final String BUGNAME = "AuthorDD";46private static final String FS = System.getProperty("file.separator");47private static final String PS = System.getProperty("path.separator");48private static final String NL = System.getProperty("line.separator");4950// Subtest number. Needed because runResultsOnHTML is run twice, and subtestNum51// should increment across subtest runs.52public static int subtestNum = 0;53public static int numSubtestsPassed = 0;5455// Entry point56public static void main(String[] args) {5758// Directory that contains source files that javadoc runs on59String srcdir = System.getProperty("test.src", ".");6061// Test for all cases except the split index page62runJavadoc(new String[] {"-d", BUGID,63"-author",64"-version",65"-sourcepath", srcdir,66"p1"});67runTestsOnHTML(testArray);6869printSummary();70}7172/** Run javadoc */73public static void runJavadoc(String[] javadocArgs) {74if (com.sun.tools.javadoc.Main.execute(AuthorDD.class.getClassLoader(),75javadocArgs) != 0) {76throw new Error("Javadoc failed to execute");77}78}7980/**81* Assign value for [ stringToFind, filename ]82* NOTE: The standard doclet uses the same separator "\n" for all OS's83*/84private static final String[][] testArray = {8586// Test single @since tag:8788{ "<dt><span class=\"simpleTagLabel\">Since:</span></dt>"+NL+"<dd>JDK 1.0</dd>",89BUGID + FS + "p1" + FS + "C1.html" },9091// Test multiple @author tags:9293{ "<dt><span class=\"simpleTagLabel\">Author:</span></dt>"+NL+"<dd>Doug Kramer, Jamie, Neal</dd>",94BUGID + FS + "p1" + FS + "C1.html" },9596};9798public static void runTestsOnHTML(String[][] testArray) {99100for (int i = 0; i < testArray.length; i++) {101102subtestNum += 1;103104// Read contents of file into a string105String fileString = readFileToString(testArray[i][1]);106107// Get string to find108String stringToFind = testArray[i][0];109110// Find string in file's contents111if (findString(fileString, stringToFind) == -1) {112System.out.println("\nSub-test " + (subtestNum)113+ " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n"114+ "when searching for:\n"115+ stringToFind);116} else {117numSubtestsPassed += 1;118System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind);119}120}121}122123public static void printSummary() {124if ( numSubtestsPassed == subtestNum ) {125System.out.println("\nAll " + numSubtestsPassed + " subtests passed");126} else {127throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum)128+ " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n");129}130}131132// Read the file into a String133public static String readFileToString(String filename) {134try {135File file = new File(filename);136if ( !file.exists() ) {137System.out.println("\nFILE DOES NOT EXIST: " + filename);138}139BufferedReader in = new BufferedReader(new FileReader(file));140141// Create an array of characters the size of the file142char[] allChars = new char[(int)file.length()];143144// Read the characters into the allChars array145in.read(allChars, 0, (int)file.length());146in.close();147148// Convert to a string149String allCharsString = new String(allChars);150151return allCharsString;152153} catch (FileNotFoundException e) {154System.err.println(e);155return "";156} catch (IOException e) {157System.err.println(e);158return "";159}160}161162public static int findString(String fileString, String stringToFind) {163return fileString.indexOf(stringToFind);164}165}166167168