T6729471.java revision 385
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith/*
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * This code is free software; you can redistribute it and/or modify it
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * under the terms of the GNU General Public License version 2 only, as
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * published by the Free Software Foundation.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * This code is distributed in the hope that it will be useful, but WITHOUT
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * version 2 for more details (a copy is included in the LICENSE file that
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * accompanied this code).
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * You should have received a copy of the GNU General Public License version
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * 2 along with this work; if not, write to the Free Software Foundation,
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * CA 95054 USA or visit www.sun.com if you need additional information or
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * have any questions.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith/*
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @test
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @bug 6729471
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @summary javap does not output inner interfaces of an interface
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmithimport java.io.*;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmithimport java.net.*;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmithimport java.util.*;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmithpublic class T6729471
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith{
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith public static void main(String... args) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith new T6729471().run();
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith void run() {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith // simple class
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith verify("java.util.Map",
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith "public abstract boolean containsKey(java.lang.Object)");
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith // inner class
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith verify("java.util.Map.Entry",
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith "public abstract K getKey()");
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith // file name
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith verify("../classes/tools/javap/T6729471.class",
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith "public static void main(java.lang.String...)");
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith // file url
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith verify("file:../classes/tools/javap/T6729471.class",
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith "public static void main(java.lang.String...)");
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith // jar url: rt.jar
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith File java_home = new File(System.getProperty("java.home"));
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith if (java_home.getName().equals("jre"))
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith java_home = java_home.getParentFile();
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith File rt_jar = new File(new File(new File(java_home, "jre"), "lib"), "rt.jar");
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith try {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith verify("jar:" + rt_jar.toURL() + "!/java/util/Map.class",
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith "public abstract boolean containsKey(java.lang.Object)");
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith } catch (MalformedURLException e) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith error(e.toString());
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith // jar url: ct.sym, if it exists
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith File ct_sym = new File(new File(java_home, "lib"), "ct.sym");
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith if (ct_sym.exists()) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith try {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith verify("jar:" + ct_sym.toURL() + "!/META-INF/sym/rt.jar/java/util/Map.class",
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith "public abstract boolean containsKey(java.lang.Object)");
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith } catch (MalformedURLException e) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith error(e.toString());
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith } else
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith System.err.println("warning: ct.sym not found");
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith if (errors > 0)
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith throw new Error(errors + " found.");
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith void verify(String className, String... expects) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith String output = javap(className);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith for (String expect: expects) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith if (output.indexOf(expect)< 0)
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith error(expect + " not found");
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith void error(String msg) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith System.err.println(msg);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith errors++;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith int errors;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith String javap(String className) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith String testClasses = System.getProperty("test.classes", ".");
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith StringWriter sw = new StringWriter();
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith PrintWriter out = new PrintWriter(sw);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith String[] args = { "-classpath", testClasses, className };
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith int rc = com.sun.tools.javap.Main.run(args, out);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith out.close();
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith String output = sw.toString();
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith System.out.println("class " + className);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith System.out.println(output);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith if (rc != 0)
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith throw new Error("javap failed. rc=" + rc);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith if (output.indexOf("Error:") != -1)
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith throw new Error("javap reported error.");
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith return output;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith}
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith