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