Wed, 15 Jul 2015 14:19:25 -0700
Merge
jjg@350 | 1 | /* |
ohair@798 | 2 | * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. |
jjg@350 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@350 | 4 | * |
jjg@350 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@350 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@350 | 7 | * published by the Free Software Foundation. |
jjg@350 | 8 | * |
jjg@350 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@350 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@350 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@350 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@350 | 13 | * accompanied this code). |
jjg@350 | 14 | * |
jjg@350 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@350 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@350 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@350 | 18 | * |
ohair@554 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 20 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 21 | * questions. |
jjg@350 | 22 | */ |
jjg@350 | 23 | |
jjg@350 | 24 | |
jjg@350 | 25 | /* |
jjg@350 | 26 | * @test |
jjg@350 | 27 | * @bug 6729471 |
jjg@350 | 28 | * @summary javap does not output inner interfaces of an interface |
jjg@350 | 29 | */ |
jjg@350 | 30 | |
jjg@350 | 31 | import java.io.*; |
jjg@386 | 32 | import java.net.*; |
jjg@350 | 33 | import java.util.*; |
jjg@350 | 34 | |
jjg@350 | 35 | public class T6729471 |
jjg@350 | 36 | { |
jjg@350 | 37 | public static void main(String... args) { |
jjg@350 | 38 | new T6729471().run(); |
jjg@350 | 39 | } |
jjg@350 | 40 | |
jjg@350 | 41 | void run() { |
jjg@755 | 42 | File testClasses = new File(System.getProperty("test.classes")); |
jjg@755 | 43 | |
jjg@350 | 44 | // simple class |
jjg@350 | 45 | verify("java.util.Map", |
jjg@350 | 46 | "public abstract boolean containsKey(java.lang.Object)"); |
jjg@350 | 47 | |
jjg@350 | 48 | // inner class |
jjg@350 | 49 | verify("java.util.Map.Entry", |
jjg@350 | 50 | "public abstract K getKey()"); |
jjg@350 | 51 | |
jjg@350 | 52 | // file name |
jjg@755 | 53 | verify(new File(testClasses, "T6729471.class").getPath(), |
jjg@350 | 54 | "public static void main(java.lang.String...)"); |
jjg@350 | 55 | |
jjg@350 | 56 | // file url |
jjg@755 | 57 | verify(new File(testClasses, "T6729471.class").toURI().toString(), |
jjg@350 | 58 | "public static void main(java.lang.String...)"); |
jjg@350 | 59 | |
jjg@350 | 60 | // jar url: rt.jar |
jjg@350 | 61 | File java_home = new File(System.getProperty("java.home")); |
jjg@350 | 62 | if (java_home.getName().equals("jre")) |
jjg@350 | 63 | java_home = java_home.getParentFile(); |
jjg@350 | 64 | File rt_jar = new File(new File(new File(java_home, "jre"), "lib"), "rt.jar"); |
jjg@386 | 65 | try { |
jjg@386 | 66 | verify("jar:" + rt_jar.toURL() + "!/java/util/Map.class", |
jjg@350 | 67 | "public abstract boolean containsKey(java.lang.Object)"); |
jjg@386 | 68 | } catch (MalformedURLException e) { |
jjg@386 | 69 | error(e.toString()); |
jjg@386 | 70 | } |
jjg@350 | 71 | |
jjg@350 | 72 | // jar url: ct.sym, if it exists |
jjg@350 | 73 | File ct_sym = new File(new File(java_home, "lib"), "ct.sym"); |
jjg@350 | 74 | if (ct_sym.exists()) { |
jjg@386 | 75 | try { |
jjg@386 | 76 | verify("jar:" + ct_sym.toURL() + "!/META-INF/sym/rt.jar/java/util/Map.class", |
jjg@386 | 77 | "public abstract boolean containsKey(java.lang.Object)"); |
jjg@386 | 78 | } catch (MalformedURLException e) { |
jjg@386 | 79 | error(e.toString()); |
jjg@386 | 80 | } |
jjg@350 | 81 | } else |
jjg@350 | 82 | System.err.println("warning: ct.sym not found"); |
jjg@350 | 83 | |
jjg@350 | 84 | if (errors > 0) |
jjg@350 | 85 | throw new Error(errors + " found."); |
jjg@350 | 86 | } |
jjg@350 | 87 | |
jjg@350 | 88 | void verify(String className, String... expects) { |
jjg@350 | 89 | String output = javap(className); |
jjg@350 | 90 | for (String expect: expects) { |
jjg@350 | 91 | if (output.indexOf(expect)< 0) |
jjg@350 | 92 | error(expect + " not found"); |
jjg@350 | 93 | } |
jjg@350 | 94 | } |
jjg@350 | 95 | |
jjg@350 | 96 | void error(String msg) { |
jjg@350 | 97 | System.err.println(msg); |
jjg@350 | 98 | errors++; |
jjg@350 | 99 | } |
jjg@350 | 100 | |
jjg@350 | 101 | int errors; |
jjg@350 | 102 | |
jjg@350 | 103 | String javap(String className) { |
jjg@350 | 104 | String testClasses = System.getProperty("test.classes", "."); |
jjg@350 | 105 | StringWriter sw = new StringWriter(); |
jjg@350 | 106 | PrintWriter out = new PrintWriter(sw); |
jjg@350 | 107 | String[] args = { "-classpath", testClasses, className }; |
jjg@350 | 108 | int rc = com.sun.tools.javap.Main.run(args, out); |
jjg@350 | 109 | out.close(); |
jjg@350 | 110 | String output = sw.toString(); |
jjg@350 | 111 | System.out.println("class " + className); |
jjg@350 | 112 | System.out.println(output); |
jjg@350 | 113 | if (rc != 0) |
jjg@350 | 114 | throw new Error("javap failed. rc=" + rc); |
jjg@350 | 115 | if (output.indexOf("Error:") != -1) |
jjg@350 | 116 | throw new Error("javap reported error."); |
jjg@350 | 117 | return output; |
jjg@350 | 118 | } |
jjg@350 | 119 | } |
jjg@350 | 120 |