test/com/sun/javadoc/WindowTitles/WindowTitles.java

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1
9a66ca7c79fa
child 554
9d9f26857129
permissions
-rw-r--r--

Initial load

     1 /*
     2  * Copyright 2002-2005 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  */
    24 /*
    25  * @test
    26  * @bug 4530730
    27  * @summary stddoclet: With frames off, window titles have "()" appended
    28  * @author dkramer
    29  * @run main WindowTitles
    30  */
    33 import com.sun.javadoc.*;
    34 import java.util.*;
    35 import java.io.*;
    37 // If needing regular expression pattern matching,
    38 // see /java/pubs/dev/linkfix/src/LinkFix.java
    40 /**
    41  * Runs javadoc and runs regression tests on the resulting HTML.
    42  * It reads each file, complete with newlines, into a string to easily
    43  * find strings that contain newlines.
    44  */
    45 public class WindowTitles
    46 {
    47     private static final String BUGID = "4530730";
    48     private static final String BUGNAME = "WindowTitles";
    49     private static final String FS = System.getProperty("file.separator");
    50     private static final String PS = System.getProperty("path.separator");
    51     private static final String LS = System.getProperty("line.separator");
    52     private static final String TMPDIR_STRING1 = "." + FS + "docs1" + FS;
    53     private static final String TMPDIR_STRING2 = "." + FS + "docs2" + FS;
    55     // Subtest number.  Needed because runResultsOnHTML is run twice, and subtestNum
    56     // should increment across subtest runs.
    57     public static int subtestNum = 0;
    58     public static int numSubtestsPassed = 0;
    60     // Entry point
    61     public static void main(String[] args) {
    63         // Directory that contains source files that javadoc runs on
    64         String srcdir = System.getProperty("test.src", ".");
    66         // Test for all cases except the split index page
    67         runJavadoc(new String[] {"-d", TMPDIR_STRING1,
    68                                  "-use",
    69                                  "-sourcepath", srcdir,
    70                                  "p1", "p2"});
    71         runTestsOnHTML(testArray);
    73         // Test only for the split-index case (and run on only one package)
    74         System.out.println("");  // blank line
    75         runJavadoc(new String[] {"-d", TMPDIR_STRING2,
    76                                  "-splitindex",
    77                                  "-sourcepath", System.getProperty("test.src", "."),
    78                                  "p1"});
    79         runTestsOnHTML(testSplitIndexArray);
    81         printSummary();
    82     }
    84     /** Run javadoc */
    85     public static void runJavadoc(String[] javadocArgs) {
    86         if (com.sun.tools.javadoc.Main.execute(javadocArgs) != 0) {
    87             throw new Error("Javadoc failed to execute");
    88         }
    89     }
    91     /**
    92      * Assign value for [ stringToFind, filename ]
    93      * NOTE: The standard doclet uses platform-specific line separators (LS)
    94      */
    95     private static final String[][] testArray = {
    97             { "<TITLE>" + LS + "Overview" + LS + "</TITLE>",
    98                     TMPDIR_STRING1 + "overview-summary.html"                  },
   100             { "<TITLE>" + LS + "Class Hierarchy" + LS + "</TITLE>",
   101                     TMPDIR_STRING1 + "overview-tree.html"                     },
   103             { "<TITLE>" + LS + "Overview List" + LS + "</TITLE>",
   104                     TMPDIR_STRING1 + "overview-frame.html"                    },
   106             { "<TITLE>" + LS + "p1" + LS + "</TITLE>",
   107                     TMPDIR_STRING1 + "p1" + FS + "package-summary.html"       },
   109             { "<TITLE>" + LS + "p1" + LS + "</TITLE>",
   110                     TMPDIR_STRING1 + "p1" + FS + "package-frame.html"         },
   112             { "<TITLE>" + LS + "p1 Class Hierarchy" + LS + "</TITLE>",
   113                     TMPDIR_STRING1 + "p1" + FS + "package-tree.html"          },
   115             { "<TITLE>" + LS + "Uses of Package p1" + LS + "</TITLE>",
   116                     TMPDIR_STRING1 + "p1" + FS + "package-use.html"           },
   118             { "<TITLE>" + LS + "C1" + LS + "</TITLE>",
   119                     TMPDIR_STRING1 + "p1" + FS + "C1.html"                    },
   121             { "<TITLE>" + LS + "All Classes" + LS + "</TITLE>",
   122                     TMPDIR_STRING1 + "allclasses-frame.html"                  },
   124             { "<TITLE>" + LS + "All Classes" + LS + "</TITLE>",
   125                     TMPDIR_STRING1 + "allclasses-noframe.html"                },
   127             { "<TITLE>" + LS + "Constant Field Values" + LS + "</TITLE>",
   128                     TMPDIR_STRING1 + "constant-values.html"                   },
   130             { "<TITLE>" + LS + "Deprecated List" + LS + "</TITLE>",
   131                     TMPDIR_STRING1 + "deprecated-list.html"                   },
   133             { "<TITLE>" + LS + "Serialized Form" + LS + "</TITLE>",
   134                     TMPDIR_STRING1 + "serialized-form.html"                   },
   136             { "<TITLE>" + LS + "API Help" + LS + "</TITLE>",
   137                     TMPDIR_STRING1 + "help-doc.html"                          },
   139             { "<TITLE>" + LS + "Index" + LS + "</TITLE>",
   140                     TMPDIR_STRING1 + "index-all.html"                         },
   142             { "<TITLE>" + LS + "Uses of Class p1.C1" + LS + "</TITLE>",
   143                     TMPDIR_STRING1 + "p1" + FS + "class-use" + FS + "C1.html" },
   144         };
   146     /**
   147      * Assign value for [ stringToFind, filename ] for split index page
   148      */
   149     private static final String[][] testSplitIndexArray = {
   150             { "<TITLE>" + LS + "C-Index" + LS + "</TITLE>",
   151                     TMPDIR_STRING2 + "index-files" + FS + "index-1.html"       },
   152         };
   154     public static void runTestsOnHTML(String[][] testArray) {
   156         for (int i = 0; i < testArray.length; i++) {
   158             subtestNum += 1;
   160             // Read contents of file into a string
   161             String fileString = readFileToString(testArray[i][1]);
   163             // Get string to find
   164             String stringToFind = testArray[i][0];
   166             // Find string in file's contents
   167             if (findString(fileString, stringToFind) == -1) {
   168                 System.out.println("\nSub-test " + (subtestNum)
   169                     + " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n"
   170                     + "when searching for:\n"
   171                     + stringToFind);
   172             } else {
   173                 numSubtestsPassed += 1;
   174                 System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind);
   175             }
   176         }
   177     }
   179     public static void printSummary() {
   180         if ( numSubtestsPassed == subtestNum ) {
   181             System.out.println("\nAll " + numSubtestsPassed + " subtests passed");
   182         } else {
   183             throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum)
   184                              + " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n");
   185         }
   186     }
   188     // Read the file into a String
   189     public static String readFileToString(String filename) {
   190         try {
   191             File file = new File(filename);
   192             if ( !file.exists() ) {
   193                 System.out.println("\nFILE DOES NOT EXIST: " + filename);
   194             }
   195             BufferedReader in = new BufferedReader(new FileReader(file));
   197             // Create an array of characters the size of the file
   198             char[] allChars = new char[(int)file.length()];
   200             // Read the characters into the allChars array
   201             in.read(allChars, 0, (int)file.length());
   202             in.close();
   204             // Convert to a string
   205             String allCharsString = new String(allChars);
   207             return allCharsString;
   209         } catch (FileNotFoundException e) {
   210             System.err.println(e);
   211             return "";
   212         } catch (IOException e) {
   213             System.err.println(e);
   214             return "";
   215         }
   216     }
   218     public static int findString(String fileString, String stringToFind) {
   219         return fileString.indexOf(stringToFind);
   220     }
   221 }

mercurial