|
1 /* |
|
2 * Copyright 2009 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 */ |
|
23 |
|
24 |
|
25 /* |
|
26 * @test |
|
27 * @bug 6729471 |
|
28 * @summary javap does not output inner interfaces of an interface |
|
29 */ |
|
30 |
|
31 import java.io.*; |
|
32 import java.util.*; |
|
33 |
|
34 public class T6729471 |
|
35 { |
|
36 public static void main(String... args) { |
|
37 new T6729471().run(); |
|
38 } |
|
39 |
|
40 void run() { |
|
41 // simple class |
|
42 verify("java.util.Map", |
|
43 "public abstract boolean containsKey(java.lang.Object)"); |
|
44 |
|
45 // inner class |
|
46 verify("java.util.Map.Entry", |
|
47 "public abstract K getKey()"); |
|
48 |
|
49 // file name |
|
50 verify("../classes/tools/javap/T6729471.class", |
|
51 "public static void main(java.lang.String...)"); |
|
52 |
|
53 // file url |
|
54 verify("file:../classes/tools/javap/T6729471.class", |
|
55 "public static void main(java.lang.String...)"); |
|
56 |
|
57 // jar url: rt.jar |
|
58 File java_home = new File(System.getProperty("java.home")); |
|
59 if (java_home.getName().equals("jre")) |
|
60 java_home = java_home.getParentFile(); |
|
61 File rt_jar = new File(new File(new File(java_home, "jre"), "lib"), "rt.jar"); |
|
62 verify("jar:file:" + rt_jar + "!/java/util/Map.class", |
|
63 "public abstract boolean containsKey(java.lang.Object)"); |
|
64 |
|
65 // jar url: ct.sym, if it exists |
|
66 File ct_sym = new File(new File(java_home, "lib"), "ct.sym"); |
|
67 if (ct_sym.exists()) { |
|
68 verify("jar:file:" + ct_sym + "!/META-INF/sym/rt.jar/java/util/Map.class", |
|
69 "public abstract boolean containsKey(java.lang.Object)"); |
|
70 } else |
|
71 System.err.println("warning: ct.sym not found"); |
|
72 |
|
73 if (errors > 0) |
|
74 throw new Error(errors + " found."); |
|
75 } |
|
76 |
|
77 void verify(String className, String... expects) { |
|
78 String output = javap(className); |
|
79 for (String expect: expects) { |
|
80 if (output.indexOf(expect)< 0) |
|
81 error(expect + " not found"); |
|
82 } |
|
83 } |
|
84 |
|
85 void error(String msg) { |
|
86 System.err.println(msg); |
|
87 errors++; |
|
88 } |
|
89 |
|
90 int errors; |
|
91 |
|
92 String javap(String className) { |
|
93 String testClasses = System.getProperty("test.classes", "."); |
|
94 StringWriter sw = new StringWriter(); |
|
95 PrintWriter out = new PrintWriter(sw); |
|
96 String[] args = { "-classpath", testClasses, className }; |
|
97 int rc = com.sun.tools.javap.Main.run(args, out); |
|
98 out.close(); |
|
99 String output = sw.toString(); |
|
100 System.out.println("class " + className); |
|
101 System.out.println(output); |
|
102 if (rc != 0) |
|
103 throw new Error("javap failed. rc=" + rc); |
|
104 if (output.indexOf("Error:") != -1) |
|
105 throw new Error("javap reported error."); |
|
106 return output; |
|
107 } |
|
108 } |
|
109 |