WindowTitles.java revision 765
0N/A/*
553N/A * Copyright (c) 2002, 2005, 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 4530730
0N/A * @summary stddoclet: With frames off, window titles have "()" appended
0N/A * @author dkramer
0N/A * @run main WindowTitles
0N/A */
0N/A
0N/A
0N/Aimport com.sun.javadoc.*;
0N/Aimport java.util.*;
0N/Aimport java.io.*;
0N/A
0N/A// If needing regular expression pattern matching,
0N/A// see /java/pubs/dev/linkfix/src/LinkFix.java
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 WindowTitles
0N/A{
0N/A private static final String BUGID = "4530730";
0N/A private static final String BUGNAME = "WindowTitles";
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 TMPDIR_STRING1 = "." + FS + "docs1" + FS;
0N/A private static final String TMPDIR_STRING2 = "." + FS + "docs2" + FS;
0N/A
0N/A // Subtest number. Needed because runResultsOnHTML is run twice, and subtestNum
0N/A // 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
0N/A runJavadoc(new String[] {"-d", TMPDIR_STRING1,
0N/A "-use",
0N/A "-sourcepath", srcdir,
0N/A "p1", "p2"});
0N/A runTestsOnHTML(testArray);
0N/A
0N/A // Test only for the split-index case (and run on only one package)
0N/A System.out.println(""); // blank line
0N/A runJavadoc(new String[] {"-d", TMPDIR_STRING2,
0N/A "-splitindex",
0N/A "-sourcepath", System.getProperty("test.src", "."),
0N/A "p1"});
0N/A runTestsOnHTML(testSplitIndexArray);
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 platform-specific line separators (LS)
0N/A */
0N/A private static final String[][] testArray = {
0N/A
0N/A { "<title>Overview</title>",
0N/A TMPDIR_STRING1 + "overview-summary.html" },
0N/A
0N/A { "<title>Class Hierarchy</title>",
0N/A TMPDIR_STRING1 + "overview-tree.html" },
0N/A
0N/A { "<title>Overview List</title>",
0N/A TMPDIR_STRING1 + "overview-frame.html" },
0N/A
0N/A { "<title>p1</title>",
0N/A TMPDIR_STRING1 + "p1" + FS + "package-summary.html" },
0N/A
0N/A { "<title>p1</title>",
0N/A TMPDIR_STRING1 + "p1" + FS + "package-frame.html" },
0N/A
0N/A { "<title>p1 Class Hierarchy</title>",
0N/A TMPDIR_STRING1 + "p1" + FS + "package-tree.html" },
0N/A
0N/A { "<title>Uses of Package p1</title>",
0N/A TMPDIR_STRING1 + "p1" + FS + "package-use.html" },
0N/A
0N/A { "<title>C1</title>",
0N/A TMPDIR_STRING1 + "p1" + FS + "C1.html" },
0N/A
0N/A { "<title>All Classes</title>",
0N/A TMPDIR_STRING1 + "allclasses-frame.html" },
0N/A
0N/A { "<title>All Classes</title>",
0N/A TMPDIR_STRING1 + "allclasses-noframe.html" },
0N/A
0N/A { "<title>Constant Field Values</title>",
0N/A TMPDIR_STRING1 + "constant-values.html" },
0N/A
0N/A { "<title>Deprecated List</title>",
0N/A TMPDIR_STRING1 + "deprecated-list.html" },
0N/A
0N/A { "<title>Serialized Form</title>",
0N/A TMPDIR_STRING1 + "serialized-form.html" },
0N/A
0N/A { "<title>API Help</title>",
0N/A TMPDIR_STRING1 + "help-doc.html" },
0N/A
0N/A { "<title>Index</title>",
0N/A TMPDIR_STRING1 + "index-all.html" },
0N/A
0N/A { "<title>Uses of Class p1.C1</title>",
0N/A TMPDIR_STRING1 + "p1" + FS + "class-use" + FS + "C1.html" },
0N/A };
0N/A
0N/A /**
0N/A * Assign value for [ stringToFind, filename ] for split index page
0N/A */
0N/A private static final String[][] testSplitIndexArray = {
0N/A { "<title>C-Index</title>",
0N/A TMPDIR_STRING2 + "index-files" + FS + "index-1.html" },
0N/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) {
0N/A System.out.println("\nSub-test " + (subtestNum)
0N/A + " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n"
0N/A + "when searching for:\n"
0N/A + 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() {
0N/A if ( numSubtestsPassed == subtestNum ) {
0N/A System.out.println("\nAll " + numSubtestsPassed + " subtests passed");
0N/A } else {
0N/A throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum)
0N/A + " 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);
0N/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
0N/A char[] allChars = new char[(int)file.length()];
0N/A
0N/A // Read the characters into the allChars array
0N/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}