Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/com/sun/javadoc/ValidHtml/ValidHtml.java
48527 views
/*1* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 4275630 4749453 4625400 4753048 441527026* @summary Generated HTML is invalid with frameset DTD.27* Displays unnecessary horizontal scroll bars.28* Missing whitespace in DOCTYPE declaration29* <NOFRAMES> not allowed outside <FRAMESET> element30* HTML table tags inserted in wrong place in pakcage use page31* @author dkramer32* @run main ValidHtml33*/3435import com.sun.javadoc.*;36import java.util.*;37import java.io.*;3839/**40* Runs javadoc and runs regression tests on the resulting HTML.41* It reads each file, complete with newlines, into a string to easily42* find strings that contain newlines.43*/44public class ValidHtml {4546private static final String BUGID = "4275630";47private static final String BUGNAME = "ValidHtml";48private static final String FS = System.getProperty("file.separator");49private static final String PS = System.getProperty("path.separator");50private static final String LS = System.getProperty("line.separator");51private static final String TMPDEST_DIR1 = "." + FS + "docs1" + FS;52private static final String TMPDEST_DIR2 = "." + FS + "docs2" + FS;5354// Subtest number. Needed because runResultsOnHTML is run twice,55// and subtestNum should increment across subtest runs.56public static int subtestNum = 0;57public static int numSubtestsPassed = 0;5859// Entry point60public static void main(String[] args) {6162// Directory that contains source files that javadoc runs on63String srcdir = System.getProperty("test.src", ".");6465// Test for all cases except the split index page66runJavadoc(new String[]{"-d", TMPDEST_DIR1,67"-doctitle", "Document Title",68"-windowtitle", "Window Title",69"-use",70"-overview", (srcdir + FS + "overview.html"),71"-sourcepath", srcdir,72"p1", "p2"73});74runTestsOnHTML(testArray);7576printSummary();77}7879/** Run javadoc */80public static void runJavadoc(String[] javadocArgs) {81if (com.sun.tools.javadoc.Main.execute(javadocArgs) != 0) {82throw new Error("Javadoc failed to execute");83}84}8586/**87* Assign value for [ stringToFind, filename ]88* NOTE: The standard doclet uses the same separator "\n" for all OS's89*/90private static final String[][] testArray = {91// Test the proper DOCTYPE element is present:92{93"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">",94TMPDEST_DIR1 + "index.html"95},96// Test the proper DOCTYPE element is present:97{98"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",99TMPDEST_DIR1 + "overview-summary.html"100},101// Test the proper DOCTYPE element is present:102{103"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",104TMPDEST_DIR1 + "p1" + FS + "package-summary.html"105},106// Test the proper DOCTYPE element is present:107{108"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",109TMPDEST_DIR1 + "p1" + FS + "C.html"110},111// Test the proper DOCTYPE element is present:112{113"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",114TMPDEST_DIR1 + "overview-frame.html"115},116// Test the proper DOCTYPE element is present:117{118"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",119TMPDEST_DIR1 + "allclasses-frame.html"120},121// Test the proper DOCTYPE element is present:122{123"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",124TMPDEST_DIR1 + "p1" + FS + "package-frame.html"125},126// Test that <NOFRAMES> is inside <FRAMESET> element:127{128"</noframes>" + LS + "</frameset>",129TMPDEST_DIR1 + "index.html"130},131// Test the table elements are in the correct order:132{133"</td>" + LS + "</tr>",134TMPDEST_DIR1 + FS + "p1" + FS + "package-use.html"135}136};137138public static void runTestsOnHTML(String[][] testArray) {139140for (int i = 0; i < testArray.length; i++) {141142subtestNum += 1;143144// Read contents of file into a string145String fileString = readFileToString(testArray[i][1]);146147// Get string to find148String stringToFind = testArray[i][0];149150// Find string in file's contents151if (findString(fileString, stringToFind) == -1) {152System.out.println("\nSub-test " + (subtestNum) + " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n" + "when searching for:\n" + stringToFind);153} else {154numSubtestsPassed += 1;155System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind);156}157}158}159160public static void printSummary() {161if (numSubtestsPassed == subtestNum) {162System.out.println("\nAll " + numSubtestsPassed + " subtests passed");163} else {164throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum) + " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n");165}166}167168// Read the file into a String169public static String readFileToString(String filename) {170try {171File file = new File(filename);172if (!file.exists()) {173System.out.println("\nFILE DOES NOT EXIST: " + filename);174}175BufferedReader in = new BufferedReader(new FileReader(file));176177// Create an array of characters the size of the file178char[] allChars = new char[(int) file.length()];179180// Read the characters into the allChars array181in.read(allChars, 0, (int) file.length());182in.close();183184// Convert to a string185String allCharsString = new String(allChars);186187return allCharsString;188189} catch (FileNotFoundException e) {190System.err.println(e);191return "";192} catch (IOException e) {193System.err.println(e);194return "";195}196}197198public static int findString(String fileString, String stringToFind) {199return fileString.indexOf(stringToFind);200}201}202203204