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

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

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

mercurial