test/com/sun/javadoc/ValidHtml/ValidHtml.java

Tue, 28 Dec 2010 15:54:52 -0800

author
ohair
date
Tue, 28 Dec 2010 15:54:52 -0800
changeset 798
4868a36f6fd8
parent 766
90af8d87741f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

6962318: Update copyright year
Reviewed-by: xdono

duke@1 1 /*
ohair@798 2 * Copyright (c) 2002, 2010, 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 4275630 4749453 4625400 4753048 4415270
duke@1 27 * @summary Generated HTML is invalid with frameset DTD.
duke@1 28 * Displays unnecessary horizontal scroll bars.
duke@1 29 * Missing whitespace in DOCTYPE declaration
duke@1 30 * <NOFRAMES> not allowed outside <FRAMESET> element
duke@1 31 * HTML table tags inserted in wrong place in pakcage use page
duke@1 32 * @author dkramer
duke@1 33 * @run main ValidHtml
duke@1 34 */
duke@1 35
duke@1 36 import com.sun.javadoc.*;
duke@1 37 import java.util.*;
duke@1 38 import java.io.*;
duke@1 39
duke@1 40 /**
duke@1 41 * Runs javadoc and runs regression tests on the resulting HTML.
duke@1 42 * It reads each file, complete with newlines, into a string to easily
duke@1 43 * find strings that contain newlines.
duke@1 44 */
duke@1 45 public class ValidHtml {
duke@1 46
duke@1 47 private static final String BUGID = "4275630";
duke@1 48 private static final String BUGNAME = "ValidHtml";
duke@1 49 private static final String FS = System.getProperty("file.separator");
duke@1 50 private static final String PS = System.getProperty("path.separator");
duke@1 51 private static final String LS = System.getProperty("line.separator");
duke@1 52 private static final String TMPDEST_DIR1 = "." + FS + "docs1" + FS;
duke@1 53 private static final String TMPDEST_DIR2 = "." + FS + "docs2" + FS;
duke@1 54
duke@1 55 // Subtest number. Needed because runResultsOnHTML is run twice,
duke@1 56 // and subtestNum should increment across subtest runs.
duke@1 57 public static int subtestNum = 0;
duke@1 58 public static int numSubtestsPassed = 0;
duke@1 59
duke@1 60 // Entry point
duke@1 61 public static void main(String[] args) {
duke@1 62
duke@1 63 // Directory that contains source files that javadoc runs on
duke@1 64 String srcdir = System.getProperty("test.src", ".");
duke@1 65
duke@1 66 // Test for all cases except the split index page
bpatel@766 67 runJavadoc(new String[]{"-d", TMPDEST_DIR1,
bpatel@766 68 "-doctitle", "Document Title",
bpatel@766 69 "-windowtitle", "Window Title",
bpatel@766 70 "-use",
bpatel@766 71 "-overview", (srcdir + FS + "overview.html"),
bpatel@766 72 "-sourcepath", srcdir,
bpatel@766 73 "p1", "p2"
bpatel@766 74 });
duke@1 75 runTestsOnHTML(testArray);
duke@1 76
duke@1 77 printSummary();
duke@1 78 }
duke@1 79
duke@1 80 /** Run javadoc */
duke@1 81 public static void runJavadoc(String[] javadocArgs) {
duke@1 82 if (com.sun.tools.javadoc.Main.execute(javadocArgs) != 0) {
duke@1 83 throw new Error("Javadoc failed to execute");
duke@1 84 }
duke@1 85 }
duke@1 86
duke@1 87 /**
duke@1 88 * Assign value for [ stringToFind, filename ]
duke@1 89 * NOTE: The standard doclet uses the same separator "\n" for all OS's
duke@1 90 */
duke@1 91 private static final String[][] testArray = {
bpatel@766 92 // Test the proper DOCTYPE element is present:
bpatel@766 93 {
bpatel@766 94 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">",
bpatel@766 95 TMPDEST_DIR1 + "index.html"
bpatel@766 96 },
bpatel@766 97 // Test the proper DOCTYPE element is present:
bpatel@766 98 {
bpatel@766 99 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
bpatel@766 100 TMPDEST_DIR1 + "overview-summary.html"
bpatel@766 101 },
bpatel@766 102 // Test the proper DOCTYPE element is present:
bpatel@766 103 {
bpatel@766 104 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
bpatel@766 105 TMPDEST_DIR1 + "p1" + FS + "package-summary.html"
bpatel@766 106 },
bpatel@766 107 // Test the proper DOCTYPE element is present:
bpatel@766 108 {
bpatel@766 109 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
bpatel@766 110 TMPDEST_DIR1 + "p1" + FS + "C.html"
bpatel@766 111 },
bpatel@766 112 // Test the proper DOCTYPE element is present:
bpatel@766 113 {
bpatel@766 114 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
bpatel@766 115 TMPDEST_DIR1 + "overview-frame.html"
bpatel@766 116 },
bpatel@766 117 // Test the proper DOCTYPE element is present:
bpatel@766 118 {
bpatel@766 119 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
bpatel@766 120 TMPDEST_DIR1 + "allclasses-frame.html"
bpatel@766 121 },
bpatel@766 122 // Test the proper DOCTYPE element is present:
bpatel@766 123 {
bpatel@766 124 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
bpatel@766 125 TMPDEST_DIR1 + "p1" + FS + "package-frame.html"
bpatel@766 126 },
bpatel@766 127 // Test that <NOFRAMES> is inside <FRAMESET> element:
bpatel@766 128 {
bpatel@766 129 "</noframes>" + LS + "</frameset>",
bpatel@766 130 TMPDEST_DIR1 + "index.html"
bpatel@766 131 },
bpatel@766 132 // Test the table elements are in the correct order:
bpatel@766 133 {
bpatel@766 134 "</td>" + LS + "</tr>",
bpatel@766 135 TMPDEST_DIR1 + FS + "p1" + FS + "package-use.html"
bpatel@766 136 }
bpatel@766 137 };
duke@1 138
duke@1 139 public static void runTestsOnHTML(String[][] testArray) {
duke@1 140
duke@1 141 for (int i = 0; i < testArray.length; i++) {
duke@1 142
duke@1 143 subtestNum += 1;
duke@1 144
duke@1 145 // Read contents of file into a string
duke@1 146 String fileString = readFileToString(testArray[i][1]);
duke@1 147
duke@1 148 // Get string to find
duke@1 149 String stringToFind = testArray[i][0];
duke@1 150
duke@1 151 // Find string in file's contents
duke@1 152 if (findString(fileString, stringToFind) == -1) {
bpatel@766 153 System.out.println("\nSub-test " + (subtestNum) + " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n" + "when searching for:\n" + stringToFind);
duke@1 154 } else {
duke@1 155 numSubtestsPassed += 1;
duke@1 156 System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind);
duke@1 157 }
duke@1 158 }
duke@1 159 }
duke@1 160
duke@1 161 public static void printSummary() {
bpatel@766 162 if (numSubtestsPassed == subtestNum) {
duke@1 163 System.out.println("\nAll " + numSubtestsPassed + " subtests passed");
duke@1 164 } else {
bpatel@766 165 throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum) + " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n");
duke@1 166 }
duke@1 167 }
duke@1 168
duke@1 169 // Read the file into a String
duke@1 170 public static String readFileToString(String filename) {
duke@1 171 try {
duke@1 172 File file = new File(filename);
bpatel@766 173 if (!file.exists()) {
duke@1 174 System.out.println("\nFILE DOES NOT EXIST: " + filename);
duke@1 175 }
duke@1 176 BufferedReader in = new BufferedReader(new FileReader(file));
duke@1 177
duke@1 178 // Create an array of characters the size of the file
bpatel@766 179 char[] allChars = new char[(int) file.length()];
duke@1 180
duke@1 181 // Read the characters into the allChars array
bpatel@766 182 in.read(allChars, 0, (int) file.length());
duke@1 183 in.close();
duke@1 184
duke@1 185 // Convert to a string
duke@1 186 String allCharsString = new String(allChars);
duke@1 187
duke@1 188 return allCharsString;
duke@1 189
duke@1 190 } catch (FileNotFoundException e) {
duke@1 191 System.err.println(e);
duke@1 192 return "";
duke@1 193 } catch (IOException e) {
duke@1 194 System.err.println(e);
duke@1 195 return "";
duke@1 196 }
duke@1 197 }
duke@1 198
duke@1 199 public static int findString(String fileString, String stringToFind) {
duke@1 200 return fileString.indexOf(stringToFind);
duke@1 201 }
duke@1 202 }

mercurial