test/com/sun/javadoc/AuthorDD/AuthorDD.java

Wed, 01 Dec 2010 11:02:38 -0800

author
bpatel
date
Wed, 01 Dec 2010 11:02:38 -0800
changeset 766
90af8d87741f
parent 554
9d9f26857129
child 798
4868a36f6fd8
permissions
-rw-r--r--

6851834: Javadoc doclet needs a structured approach to generate the output HTML.
Reviewed-by: jjg

duke@1 1 /*
ohair@554 2 * Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation.
duke@1 8 *
duke@1 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 13 * accompanied this code).
duke@1 14 *
duke@1 15 * You should have received a copy of the GNU General Public License version
duke@1 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 18 *
ohair@554 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 20 * or visit www.oracle.com if you need additional information or have any
ohair@554 21 * questions.
duke@1 22 */
duke@1 23
duke@1 24 /*
duke@1 25 * @test
duke@1 26 * @bug 4651598
duke@1 27 * @summary Javadoc wrongly inserts </DD> tags when using multiple @author tags
duke@1 28 * @author dkramer
duke@1 29 * @run main AuthorDD
duke@1 30 */
duke@1 31
duke@1 32
duke@1 33 import com.sun.javadoc.*;
duke@1 34 import java.util.*;
duke@1 35 import java.io.*;
duke@1 36
duke@1 37
duke@1 38 /**
duke@1 39 * Runs javadoc and runs regression tests on the resulting HTML.
duke@1 40 * It reads each file, complete with newlines, into a string to easily
duke@1 41 * find strings that contain newlines.
duke@1 42 */
duke@1 43 public class AuthorDD
duke@1 44 {
duke@1 45 private static final String BUGID = "4651598";
duke@1 46 private static final String BUGNAME = "AuthorDD";
duke@1 47 private static final String FS = System.getProperty("file.separator");
duke@1 48 private static final String PS = System.getProperty("path.separator");
duke@1 49 private static final String NL = System.getProperty("line.separator");
duke@1 50
duke@1 51 // Subtest number. Needed because runResultsOnHTML is run twice, and subtestNum
duke@1 52 // should increment across subtest runs.
duke@1 53 public static int subtestNum = 0;
duke@1 54 public static int numSubtestsPassed = 0;
duke@1 55
duke@1 56 // Entry point
duke@1 57 public static void main(String[] args) {
duke@1 58
duke@1 59 // Directory that contains source files that javadoc runs on
duke@1 60 String srcdir = System.getProperty("test.src", ".");
duke@1 61
duke@1 62 // Test for all cases except the split index page
duke@1 63 runJavadoc(new String[] {"-d", BUGID,
duke@1 64 "-author",
duke@1 65 "-version",
duke@1 66 "-sourcepath", srcdir,
duke@1 67 "p1"});
duke@1 68 runTestsOnHTML(testArray);
duke@1 69
duke@1 70 printSummary();
duke@1 71 }
duke@1 72
duke@1 73 /** Run javadoc */
duke@1 74 public static void runJavadoc(String[] javadocArgs) {
jjg@140 75 if (com.sun.tools.javadoc.Main.execute(AuthorDD.class.getClassLoader(),
jjg@140 76 javadocArgs) != 0) {
duke@1 77 throw new Error("Javadoc failed to execute");
duke@1 78 }
duke@1 79 }
duke@1 80
duke@1 81 /**
duke@1 82 * Assign value for [ stringToFind, filename ]
duke@1 83 * NOTE: The standard doclet uses the same separator "\n" for all OS's
duke@1 84 */
duke@1 85 private static final String[][] testArray = {
duke@1 86
duke@1 87 // Test single @since tag:
duke@1 88
bpatel@766 89 { "<dt><span class=\"strong\">Since:</span></dt>"+NL+" <dd>JDK 1.0</dd>",
duke@1 90 BUGID + FS + "p1" + FS + "C1.html" },
duke@1 91
duke@1 92 // Test multiple @author tags:
duke@1 93
bpatel@766 94 { "<dt><span class=\"strong\">Author:</span></dt>"+NL+" <dd>Doug Kramer, Jamie, Neal</dd>",
duke@1 95 BUGID + FS + "p1" + FS + "C1.html" },
duke@1 96
duke@1 97 };
duke@1 98
duke@1 99 public static void runTestsOnHTML(String[][] testArray) {
duke@1 100
duke@1 101 for (int i = 0; i < testArray.length; i++) {
duke@1 102
duke@1 103 subtestNum += 1;
duke@1 104
duke@1 105 // Read contents of file into a string
duke@1 106 String fileString = readFileToString(testArray[i][1]);
duke@1 107
duke@1 108 // Get string to find
duke@1 109 String stringToFind = testArray[i][0];
duke@1 110
duke@1 111 // Find string in file's contents
duke@1 112 if (findString(fileString, stringToFind) == -1) {
duke@1 113 System.out.println("\nSub-test " + (subtestNum)
duke@1 114 + " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n"
duke@1 115 + "when searching for:\n"
duke@1 116 + stringToFind);
duke@1 117 } else {
duke@1 118 numSubtestsPassed += 1;
duke@1 119 System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind);
duke@1 120 }
duke@1 121 }
duke@1 122 }
duke@1 123
duke@1 124 public static void printSummary() {
duke@1 125 if ( numSubtestsPassed == subtestNum ) {
duke@1 126 System.out.println("\nAll " + numSubtestsPassed + " subtests passed");
duke@1 127 } else {
duke@1 128 throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum)
duke@1 129 + " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n");
duke@1 130 }
duke@1 131 }
duke@1 132
duke@1 133 // Read the file into a String
duke@1 134 public static String readFileToString(String filename) {
duke@1 135 try {
duke@1 136 File file = new File(filename);
duke@1 137 if ( !file.exists() ) {
duke@1 138 System.out.println("\nFILE DOES NOT EXIST: " + filename);
duke@1 139 }
duke@1 140 BufferedReader in = new BufferedReader(new FileReader(file));
duke@1 141
duke@1 142 // Create an array of characters the size of the file
duke@1 143 char[] allChars = new char[(int)file.length()];
duke@1 144
duke@1 145 // Read the characters into the allChars array
duke@1 146 in.read(allChars, 0, (int)file.length());
duke@1 147 in.close();
duke@1 148
duke@1 149 // Convert to a string
duke@1 150 String allCharsString = new String(allChars);
duke@1 151
duke@1 152 return allCharsString;
duke@1 153
duke@1 154 } catch (FileNotFoundException e) {
duke@1 155 System.err.println(e);
duke@1 156 return "";
duke@1 157 } catch (IOException e) {
duke@1 158 System.err.println(e);
duke@1 159 return "";
duke@1 160 }
duke@1 161 }
duke@1 162
duke@1 163 public static int findString(String fileString, String stringToFind) {
duke@1 164 return fileString.indexOf(stringToFind);
duke@1 165 }
duke@1 166 }

mercurial