aoqi@0: /* aoqi@0: * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /* aoqi@0: * @test aoqi@0: * @bug 4651598 8026567 aoqi@0: * @summary Javadoc wrongly inserts tags when using multiple @author tags aoqi@0: * @author dkramer aoqi@0: * @run main AuthorDD aoqi@0: */ aoqi@0: aoqi@0: aoqi@0: import com.sun.javadoc.*; aoqi@0: import java.util.*; aoqi@0: import java.io.*; aoqi@0: aoqi@0: aoqi@0: /** aoqi@0: * Runs javadoc and runs regression tests on the resulting HTML. aoqi@0: * It reads each file, complete with newlines, into a string to easily aoqi@0: * find strings that contain newlines. aoqi@0: */ aoqi@0: public class AuthorDD aoqi@0: { aoqi@0: private static final String BUGID = "4651598"; aoqi@0: private static final String BUGNAME = "AuthorDD"; aoqi@0: private static final String FS = System.getProperty("file.separator"); aoqi@0: private static final String PS = System.getProperty("path.separator"); aoqi@0: private static final String NL = System.getProperty("line.separator"); aoqi@0: aoqi@0: // Subtest number. Needed because runResultsOnHTML is run twice, and subtestNum aoqi@0: // should increment across subtest runs. aoqi@0: public static int subtestNum = 0; aoqi@0: public static int numSubtestsPassed = 0; aoqi@0: aoqi@0: // Entry point aoqi@0: public static void main(String[] args) { aoqi@0: aoqi@0: // Directory that contains source files that javadoc runs on aoqi@0: String srcdir = System.getProperty("test.src", "."); aoqi@0: aoqi@0: // Test for all cases except the split index page aoqi@0: runJavadoc(new String[] {"-d", BUGID, aoqi@0: "-author", aoqi@0: "-version", aoqi@0: "-sourcepath", srcdir, aoqi@0: "p1"}); aoqi@0: runTestsOnHTML(testArray); aoqi@0: aoqi@0: printSummary(); aoqi@0: } aoqi@0: aoqi@0: /** Run javadoc */ aoqi@0: public static void runJavadoc(String[] javadocArgs) { aoqi@0: if (com.sun.tools.javadoc.Main.execute(AuthorDD.class.getClassLoader(), aoqi@0: javadocArgs) != 0) { aoqi@0: throw new Error("Javadoc failed to execute"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Assign value for [ stringToFind, filename ] aoqi@0: * NOTE: The standard doclet uses the same separator "\n" for all OS's aoqi@0: */ aoqi@0: private static final String[][] testArray = { aoqi@0: aoqi@0: // Test single @since tag: aoqi@0: aoqi@0: { "
Since:
"+NL+"
JDK 1.0
", aoqi@0: BUGID + FS + "p1" + FS + "C1.html" }, aoqi@0: aoqi@0: // Test multiple @author tags: aoqi@0: aoqi@0: { "
Author:
"+NL+"
Doug Kramer, Jamie, Neal
", aoqi@0: BUGID + FS + "p1" + FS + "C1.html" }, aoqi@0: aoqi@0: }; aoqi@0: aoqi@0: public static void runTestsOnHTML(String[][] testArray) { aoqi@0: aoqi@0: for (int i = 0; i < testArray.length; i++) { aoqi@0: aoqi@0: subtestNum += 1; aoqi@0: aoqi@0: // Read contents of file into a string aoqi@0: String fileString = readFileToString(testArray[i][1]); aoqi@0: aoqi@0: // Get string to find aoqi@0: String stringToFind = testArray[i][0]; aoqi@0: aoqi@0: // Find string in file's contents aoqi@0: if (findString(fileString, stringToFind) == -1) { aoqi@0: System.out.println("\nSub-test " + (subtestNum) aoqi@0: + " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n" aoqi@0: + "when searching for:\n" aoqi@0: + stringToFind); aoqi@0: } else { aoqi@0: numSubtestsPassed += 1; aoqi@0: System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public static void printSummary() { aoqi@0: if ( numSubtestsPassed == subtestNum ) { aoqi@0: System.out.println("\nAll " + numSubtestsPassed + " subtests passed"); aoqi@0: } else { aoqi@0: throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum) aoqi@0: + " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Read the file into a String aoqi@0: public static String readFileToString(String filename) { aoqi@0: try { aoqi@0: File file = new File(filename); aoqi@0: if ( !file.exists() ) { aoqi@0: System.out.println("\nFILE DOES NOT EXIST: " + filename); aoqi@0: } aoqi@0: BufferedReader in = new BufferedReader(new FileReader(file)); aoqi@0: aoqi@0: // Create an array of characters the size of the file aoqi@0: char[] allChars = new char[(int)file.length()]; aoqi@0: aoqi@0: // Read the characters into the allChars array aoqi@0: in.read(allChars, 0, (int)file.length()); aoqi@0: in.close(); aoqi@0: aoqi@0: // Convert to a string aoqi@0: String allCharsString = new String(allChars); aoqi@0: aoqi@0: return allCharsString; aoqi@0: aoqi@0: } catch (FileNotFoundException e) { aoqi@0: System.err.println(e); aoqi@0: return ""; aoqi@0: } catch (IOException e) { aoqi@0: System.err.println(e); aoqi@0: return ""; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public static int findString(String fileString, String stringToFind) { aoqi@0: return fileString.indexOf(stringToFind); aoqi@0: } aoqi@0: }