Thu, 15 Jul 2010 16:31:02 +0100
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, 2003, 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 4706779 4956908
27 * @summary Add text equivalent of class tree ASCII art for accessibility
28 * @author dkramer
29 * @run main AccessAsciiArt
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 AccessAsciiArt {
45 private static final String BUGID = "4706779-4956908";
46 private static final String BUGNAME = "AccessAsciiArt";
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 TMPDEST_DIR1 = "." + FS + "docs1" + FS;
50 private static final String TMPDEST_DIR2 = "." + FS + "docs2" + FS;
52 // Subtest number. Needed because runResultsOnHTML is run twice,
53 // and subtestNum should increment across subtest runs.
54 public static int subtestNum = 0;
55 public static int numSubtestsPassed = 0;
57 // Entry point
58 public static void main(String[] args) {
60 // Directory that contains source files that javadoc runs on
61 String srcdir = System.getProperty("test.src", ".");
63 // Test for all cases except the split index page
64 runJavadoc(new String[] {"-d", TMPDEST_DIR1,
65 "-sourcepath", srcdir,
66 "p1", "p1.subpkg"});
67 runTestsOnHTML(testArray);
69 printSummary();
70 }
72 /** Run javadoc */
73 public static void runJavadoc(String[] javadocArgs) {
74 if (com.sun.tools.javadoc.Main.execute(javadocArgs) != 0) {
75 throw new Error("Javadoc failed to execute");
76 }
77 }
79 /**
80 * Assign value for [ stringToFind, filename ]
81 * NOTE: The standard doclet uses the same separator "\n" for all OS's
82 */
83 private static final String[][] testArray = {
85 // Test the top line of the class tree
86 {
87 " <IMG SRC=\"../../resources/inherit.gif\" ALT=\"extended by \"><A HREF=\"../../p1/C.html\" title=\"class in p1\">p1.C</A>",
88 TMPDEST_DIR1 + "p1" + FS + "subpkg" + FS + "SSC.html" },
90 // Test the second line of the class tree
91 {
92 " <IMG SRC=\"../../resources/inherit.gif\" ALT=\"extended by \"><A HREF=\"../../p1/SC.html\" title=\"class in p1\">p1.SC</A>",
93 TMPDEST_DIR1 + "p1" + FS + "subpkg" + FS + "SSC.html" },
95 // Test the third line of the class tree
96 {
97 " <IMG SRC=\"../../resources/inherit.gif\" ALT=\"extended by \"><STRONG>p1.subpkg.SSC</STRONG>",
98 TMPDEST_DIR1 + "p1" + FS + "subpkg" + FS +"SSC.html" },
100 };
102 public static void runTestsOnHTML(String[][] testArray) {
104 for (int i = 0; i < testArray.length; i++) {
106 subtestNum += 1;
108 // Read contents of file into a string
109 String fileString = readFileToString(testArray[i][1]);
111 // Get string to find
112 String stringToFind = testArray[i][0];
114 // Find string in file's contents
115 if (findString(fileString, stringToFind) == -1) {
116 System.out.println("\nSub-test " + (subtestNum)
117 + " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n"
118 + "when searching for:\n"
119 + stringToFind);
120 } else {
121 numSubtestsPassed += 1;
122 System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind);
123 }
124 }
125 }
127 public static void printSummary() {
128 if ( numSubtestsPassed == subtestNum ) {
129 System.out.println("\nAll " + numSubtestsPassed + " subtests passed");
130 } else {
131 throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum)
132 + " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n");
133 }
134 }
136 // Read the file into a String
137 public static String readFileToString(String filename) {
138 try {
139 File file = new File(filename);
140 if ( !file.exists() ) {
141 System.out.println("\nFILE DOES NOT EXIST: " + filename);
142 }
143 BufferedReader in = new BufferedReader(new FileReader(file));
145 // Create an array of characters the size of the file
146 char[] allChars = new char[(int)file.length()];
148 // Read the characters into the allChars array
149 in.read(allChars, 0, (int)file.length());
150 in.close();
152 // Convert to a string
153 String allCharsString = new String(allChars);
155 return allCharsString;
157 } catch (FileNotFoundException e) {
158 System.err.println(e);
159 return "";
160 } catch (IOException e) {
161 System.err.println(e);
162 return "";
163 }
164 }
166 public static int findString(String fileString, String stringToFind) {
167 return fileString.indexOf(stringToFind);
168 }
169 }