1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/com/sun/javadoc/AuthorDD/AuthorDD.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,166 @@ 1.4 +/* 1.5 + * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test 1.29 + * @bug 4651598 8026567 1.30 + * @summary Javadoc wrongly inserts </DD> tags when using multiple @author tags 1.31 + * @author dkramer 1.32 + * @run main AuthorDD 1.33 + */ 1.34 + 1.35 + 1.36 +import com.sun.javadoc.*; 1.37 +import java.util.*; 1.38 +import java.io.*; 1.39 + 1.40 + 1.41 +/** 1.42 + * Runs javadoc and runs regression tests on the resulting HTML. 1.43 + * It reads each file, complete with newlines, into a string to easily 1.44 + * find strings that contain newlines. 1.45 + */ 1.46 +public class AuthorDD 1.47 +{ 1.48 + private static final String BUGID = "4651598"; 1.49 + private static final String BUGNAME = "AuthorDD"; 1.50 + private static final String FS = System.getProperty("file.separator"); 1.51 + private static final String PS = System.getProperty("path.separator"); 1.52 + private static final String NL = System.getProperty("line.separator"); 1.53 + 1.54 + // Subtest number. Needed because runResultsOnHTML is run twice, and subtestNum 1.55 + // should increment across subtest runs. 1.56 + public static int subtestNum = 0; 1.57 + public static int numSubtestsPassed = 0; 1.58 + 1.59 + // Entry point 1.60 + public static void main(String[] args) { 1.61 + 1.62 + // Directory that contains source files that javadoc runs on 1.63 + String srcdir = System.getProperty("test.src", "."); 1.64 + 1.65 + // Test for all cases except the split index page 1.66 + runJavadoc(new String[] {"-d", BUGID, 1.67 + "-author", 1.68 + "-version", 1.69 + "-sourcepath", srcdir, 1.70 + "p1"}); 1.71 + runTestsOnHTML(testArray); 1.72 + 1.73 + printSummary(); 1.74 + } 1.75 + 1.76 + /** Run javadoc */ 1.77 + public static void runJavadoc(String[] javadocArgs) { 1.78 + if (com.sun.tools.javadoc.Main.execute(AuthorDD.class.getClassLoader(), 1.79 + javadocArgs) != 0) { 1.80 + throw new Error("Javadoc failed to execute"); 1.81 + } 1.82 + } 1.83 + 1.84 + /** 1.85 + * Assign value for [ stringToFind, filename ] 1.86 + * NOTE: The standard doclet uses the same separator "\n" for all OS's 1.87 + */ 1.88 + private static final String[][] testArray = { 1.89 + 1.90 + // Test single @since tag: 1.91 + 1.92 + { "<dt><span class=\"simpleTagLabel\">Since:</span></dt>"+NL+"<dd>JDK 1.0</dd>", 1.93 + BUGID + FS + "p1" + FS + "C1.html" }, 1.94 + 1.95 + // Test multiple @author tags: 1.96 + 1.97 + { "<dt><span class=\"simpleTagLabel\">Author:</span></dt>"+NL+"<dd>Doug Kramer, Jamie, Neal</dd>", 1.98 + BUGID + FS + "p1" + FS + "C1.html" }, 1.99 + 1.100 + }; 1.101 + 1.102 + public static void runTestsOnHTML(String[][] testArray) { 1.103 + 1.104 + for (int i = 0; i < testArray.length; i++) { 1.105 + 1.106 + subtestNum += 1; 1.107 + 1.108 + // Read contents of file into a string 1.109 + String fileString = readFileToString(testArray[i][1]); 1.110 + 1.111 + // Get string to find 1.112 + String stringToFind = testArray[i][0]; 1.113 + 1.114 + // Find string in file's contents 1.115 + if (findString(fileString, stringToFind) == -1) { 1.116 + System.out.println("\nSub-test " + (subtestNum) 1.117 + + " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n" 1.118 + + "when searching for:\n" 1.119 + + stringToFind); 1.120 + } else { 1.121 + numSubtestsPassed += 1; 1.122 + System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind); 1.123 + } 1.124 + } 1.125 + } 1.126 + 1.127 + public static void printSummary() { 1.128 + if ( numSubtestsPassed == subtestNum ) { 1.129 + System.out.println("\nAll " + numSubtestsPassed + " subtests passed"); 1.130 + } else { 1.131 + throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum) 1.132 + + " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n"); 1.133 + } 1.134 + } 1.135 + 1.136 + // Read the file into a String 1.137 + public static String readFileToString(String filename) { 1.138 + try { 1.139 + File file = new File(filename); 1.140 + if ( !file.exists() ) { 1.141 + System.out.println("\nFILE DOES NOT EXIST: " + filename); 1.142 + } 1.143 + BufferedReader in = new BufferedReader(new FileReader(file)); 1.144 + 1.145 + // Create an array of characters the size of the file 1.146 + char[] allChars = new char[(int)file.length()]; 1.147 + 1.148 + // Read the characters into the allChars array 1.149 + in.read(allChars, 0, (int)file.length()); 1.150 + in.close(); 1.151 + 1.152 + // Convert to a string 1.153 + String allCharsString = new String(allChars); 1.154 + 1.155 + return allCharsString; 1.156 + 1.157 + } catch (FileNotFoundException e) { 1.158 + System.err.println(e); 1.159 + return ""; 1.160 + } catch (IOException e) { 1.161 + System.err.println(e); 1.162 + return ""; 1.163 + } 1.164 + } 1.165 + 1.166 + public static int findString(String fileString, String stringToFind) { 1.167 + return fileString.indexOf(stringToFind); 1.168 + } 1.169 +}