0N/A/*
797N/A * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 4275630 4749453 4625400 4753048 4415270
0N/A * @summary Generated HTML is invalid with frameset DTD.
0N/A * Displays unnecessary horizontal scroll bars.
0N/A * Missing whitespace in DOCTYPE declaration
0N/A * <NOFRAMES> not allowed outside <FRAMESET> element
0N/A * HTML table tags inserted in wrong place in pakcage use page
0N/A * @author dkramer
0N/A * @run main ValidHtml
0N/A */
0N/A
0N/Aimport com.sun.javadoc.*;
0N/Aimport java.util.*;
0N/Aimport java.io.*;
0N/A
0N/A/**
0N/A * Runs javadoc and runs regression tests on the resulting HTML.
0N/A * It reads each file, complete with newlines, into a string to easily
0N/A * find strings that contain newlines.
0N/A */
0N/Apublic class ValidHtml {
0N/A
0N/A private static final String BUGID = "4275630";
0N/A private static final String BUGNAME = "ValidHtml";
0N/A private static final String FS = System.getProperty("file.separator");
0N/A private static final String PS = System.getProperty("path.separator");
0N/A private static final String LS = System.getProperty("line.separator");
0N/A private static final String TMPDEST_DIR1 = "." + FS + "docs1" + FS;
0N/A private static final String TMPDEST_DIR2 = "." + FS + "docs2" + FS;
0N/A
0N/A // Subtest number. Needed because runResultsOnHTML is run twice,
0N/A // and subtestNum should increment across subtest runs.
0N/A public static int subtestNum = 0;
0N/A public static int numSubtestsPassed = 0;
0N/A
0N/A // Entry point
0N/A public static void main(String[] args) {
0N/A
0N/A // Directory that contains source files that javadoc runs on
0N/A String srcdir = System.getProperty("test.src", ".");
0N/A
0N/A // Test for all cases except the split index page
765N/A runJavadoc(new String[]{"-d", TMPDEST_DIR1,
765N/A "-doctitle", "Document Title",
765N/A "-windowtitle", "Window Title",
765N/A "-use",
765N/A "-overview", (srcdir + FS + "overview.html"),
765N/A "-sourcepath", srcdir,
765N/A "p1", "p2"
765N/A });
0N/A runTestsOnHTML(testArray);
0N/A
0N/A printSummary();
0N/A }
0N/A
0N/A /** Run javadoc */
0N/A public static void runJavadoc(String[] javadocArgs) {
0N/A if (com.sun.tools.javadoc.Main.execute(javadocArgs) != 0) {
0N/A throw new Error("Javadoc failed to execute");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Assign value for [ stringToFind, filename ]
0N/A * NOTE: The standard doclet uses the same separator "\n" for all OS's
0N/A */
0N/A private static final String[][] testArray = {
765N/A // Test the proper DOCTYPE element is present:
765N/A {
765N/A "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">",
765N/A TMPDEST_DIR1 + "index.html"
765N/A },
765N/A // Test the proper DOCTYPE element is present:
765N/A {
765N/A "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
765N/A TMPDEST_DIR1 + "overview-summary.html"
765N/A },
765N/A // Test the proper DOCTYPE element is present:
765N/A {
765N/A "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
765N/A TMPDEST_DIR1 + "p1" + FS + "package-summary.html"
765N/A },
765N/A // Test the proper DOCTYPE element is present:
765N/A {
765N/A "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
765N/A TMPDEST_DIR1 + "p1" + FS + "C.html"
765N/A },
765N/A // Test the proper DOCTYPE element is present:
765N/A {
765N/A "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
765N/A TMPDEST_DIR1 + "overview-frame.html"
765N/A },
765N/A // Test the proper DOCTYPE element is present:
765N/A {
765N/A "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
765N/A TMPDEST_DIR1 + "allclasses-frame.html"
765N/A },
765N/A // Test the proper DOCTYPE element is present:
765N/A {
765N/A "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
765N/A TMPDEST_DIR1 + "p1" + FS + "package-frame.html"
765N/A },
765N/A // Test that <NOFRAMES> is inside <FRAMESET> element:
765N/A {
765N/A "</noframes>" + LS + "</frameset>",
765N/A TMPDEST_DIR1 + "index.html"
765N/A },
765N/A // Test the table elements are in the correct order:
765N/A {
765N/A "</td>" + LS + "</tr>",
765N/A TMPDEST_DIR1 + FS + "p1" + FS + "package-use.html"
765N/A }
765N/A };
0N/A
0N/A public static void runTestsOnHTML(String[][] testArray) {
0N/A
0N/A for (int i = 0; i < testArray.length; i++) {
0N/A
0N/A subtestNum += 1;
0N/A
0N/A // Read contents of file into a string
0N/A String fileString = readFileToString(testArray[i][1]);
0N/A
0N/A // Get string to find
0N/A String stringToFind = testArray[i][0];
0N/A
0N/A // Find string in file's contents
0N/A if (findString(fileString, stringToFind) == -1) {
765N/A System.out.println("\nSub-test " + (subtestNum) + " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n" + "when searching for:\n" + stringToFind);
0N/A } else {
0N/A numSubtestsPassed += 1;
0N/A System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind);
0N/A }
0N/A }
0N/A }
0N/A
0N/A public static void printSummary() {
765N/A if (numSubtestsPassed == subtestNum) {
0N/A System.out.println("\nAll " + numSubtestsPassed + " subtests passed");
0N/A } else {
765N/A throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum) + " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n");
0N/A }
0N/A }
0N/A
0N/A // Read the file into a String
0N/A public static String readFileToString(String filename) {
0N/A try {
0N/A File file = new File(filename);
765N/A if (!file.exists()) {
0N/A System.out.println("\nFILE DOES NOT EXIST: " + filename);
0N/A }
0N/A BufferedReader in = new BufferedReader(new FileReader(file));
0N/A
0N/A // Create an array of characters the size of the file
765N/A char[] allChars = new char[(int) file.length()];
0N/A
0N/A // Read the characters into the allChars array
765N/A in.read(allChars, 0, (int) file.length());
0N/A in.close();
0N/A
0N/A // Convert to a string
0N/A String allCharsString = new String(allChars);
0N/A
0N/A return allCharsString;
0N/A
0N/A } catch (FileNotFoundException e) {
0N/A System.err.println(e);
0N/A return "";
0N/A } catch (IOException e) {
0N/A System.err.println(e);
0N/A return "";
0N/A }
0N/A }
0N/A
0N/A public static int findString(String fileString, String stringToFind) {
0N/A return fileString.indexOf(stringToFind);
0N/A }
0N/A}