test/com/sun/javadoc/AuthorDD/AuthorDD.java

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

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

Initial load

     1 /*
     2  * Copyright 2002-2003 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 4651598
    27  * @summary Javadoc wrongly inserts </DD> tags when using multiple @author tags
    28  * @author dkramer
    29  * @run main AuthorDD
    30  */
    33 import com.sun.javadoc.*;
    34 import java.util.*;
    35 import java.io.*;
    38 /**
    39  * Runs javadoc and runs regression tests on the resulting HTML.
    40  * It reads each file, complete with newlines, into a string to easily
    41  * find strings that contain newlines.
    42  */
    43 public class AuthorDD
    44 {
    45     private static final String BUGID = "4651598";
    46     private static final String BUGNAME = "AuthorDD";
    47     private static final String FS = System.getProperty("file.separator");
    48     private static final String PS = System.getProperty("path.separator");
    49     private static final String NL = System.getProperty("line.separator");
    51     // Subtest number.  Needed because runResultsOnHTML is run twice, and subtestNum
    52     // should increment across subtest runs.
    53     public static int subtestNum = 0;
    54     public static int numSubtestsPassed = 0;
    56     // Entry point
    57     public static void main(String[] args) {
    59         // Directory that contains source files that javadoc runs on
    60         String srcdir = System.getProperty("test.src", ".");
    62         // Test for all cases except the split index page
    63         runJavadoc(new String[] {"-d", BUGID,
    64                                  "-author",
    65                                  "-version",
    66                                  "-sourcepath", srcdir,
    67                                  "p1"});
    68         runTestsOnHTML(testArray);
    70         printSummary();
    71     }
    73     /** Run javadoc */
    74     public static void runJavadoc(String[] javadocArgs) {
    75         if (com.sun.tools.javadoc.Main.execute(javadocArgs) != 0) {
    76             throw new Error("Javadoc failed to execute");
    77         }
    78     }
    80     /**
    81      * Assign value for [ stringToFind, filename ]
    82      * NOTE: The standard doclet uses the same separator "\n" for all OS's
    83      */
    84     private static final String[][] testArray = {
    86              // Test single @since tag:
    88             { "<DT><B>Since:</B></DT>"+NL+"  <DD>JDK 1.0</DD>",
    89                                   BUGID + FS + "p1" + FS + "C1.html" },
    91             // Test multiple @author tags:
    93             { "<DT><B>Author:</B></DT>"+NL+"  <DD>Doug Kramer, Jamie, Neal</DD>"+NL,
    94                                   BUGID + FS + "p1" + FS + "C1.html" },
    96         };
    98     public static void runTestsOnHTML(String[][] testArray) {
   100         for (int i = 0; i < testArray.length; i++) {
   102             subtestNum += 1;
   104             // Read contents of file into a string
   105             String fileString = readFileToString(testArray[i][1]);
   107             // Get string to find
   108             String stringToFind = testArray[i][0];
   110             // Find string in file's contents
   111             if (findString(fileString, stringToFind) == -1) {
   112                 System.out.println("\nSub-test " + (subtestNum)
   113                     + " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n"
   114                     + "when searching for:\n"
   115                     + stringToFind);
   116             } else {
   117                 numSubtestsPassed += 1;
   118                 System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind);
   119             }
   120         }
   121     }
   123     public static void printSummary() {
   124         if ( numSubtestsPassed == subtestNum ) {
   125             System.out.println("\nAll " + numSubtestsPassed + " subtests passed");
   126         } else {
   127             throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum)
   128                              + " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n");
   129         }
   130     }
   132     // Read the file into a String
   133     public static String readFileToString(String filename) {
   134         try {
   135             File file = new File(filename);
   136             if ( !file.exists() ) {
   137                 System.out.println("\nFILE DOES NOT EXIST: " + filename);
   138             }
   139             BufferedReader in = new BufferedReader(new FileReader(file));
   141             // Create an array of characters the size of the file
   142             char[] allChars = new char[(int)file.length()];
   144             // Read the characters into the allChars array
   145             in.read(allChars, 0, (int)file.length());
   146             in.close();
   148             // Convert to a string
   149             String allCharsString = new String(allChars);
   151             return allCharsString;
   153         } catch (FileNotFoundException e) {
   154             System.err.println(e);
   155             return "";
   156         } catch (IOException e) {
   157             System.err.println(e);
   158             return "";
   159         }
   160     }
   162     public static int findString(String fileString, String stringToFind) {
   163         return fileString.indexOf(stringToFind);
   164     }
   165 }

mercurial