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

Thu, 15 Jul 2010 16:31:02 +0100

author
mcimadamore
date
Thu, 15 Jul 2010 16:31:02 +0100
changeset 607
b49b0d72c071
parent 554
9d9f26857129
child 766
90af8d87741f
permissions
-rw-r--r--

6967002: JDK7 b99 javac compilation error (java.lang.AssertionError)
Summary: bug in JavacParser related to parsing of type annotations in varargs position
Reviewed-by: jjg
Contributed-by: mahmood@notnoop.com

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

mercurial