langtools/test/tools/javap/T6729471.java
author jjg
Wed, 05 Aug 2009 08:38:18 -0700
changeset 3548 fd92f0d28cb9
child 3768 46e043243c0e
permissions -rw-r--r--
6729471: javap should accept class files on the command line Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3548
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
     1
/*
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
     2
 * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
     4
 *
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
     8
 *
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    13
 * accompanied this code).
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    14
 *
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    18
 *
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    21
 * have any questions.
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    22
 */
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    23
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    24
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    25
/*
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    26
 * @test
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    27
 * @bug 6729471
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    28
 * @summary javap does not output inner interfaces of an interface
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    29
 */
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    30
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    31
import java.io.*;
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    32
import java.util.*;
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    33
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    34
public class T6729471
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    35
{
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    36
    public static void main(String... args) {
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    37
        new T6729471().run();
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    38
    }
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    39
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    40
    void run() {
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    41
        // simple class
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    42
        verify("java.util.Map",
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    43
                "public abstract boolean containsKey(java.lang.Object)");
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    44
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    45
        // inner class
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    46
        verify("java.util.Map.Entry",
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    47
                "public abstract K getKey()");
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    48
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    49
        // file name
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    50
        verify("../classes/tools/javap/T6729471.class",
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    51
                "public static void main(java.lang.String...)");
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    52
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    53
        // file url
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    54
        verify("file:../classes/tools/javap/T6729471.class",
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    55
                "public static void main(java.lang.String...)");
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    56
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    57
        // jar url: rt.jar
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    58
        File java_home = new File(System.getProperty("java.home"));
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    59
        if (java_home.getName().equals("jre"))
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    60
            java_home = java_home.getParentFile();
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    61
        File rt_jar = new File(new File(new File(java_home, "jre"), "lib"), "rt.jar");
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    62
        verify("jar:file:" + rt_jar + "!/java/util/Map.class",
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    63
                "public abstract boolean containsKey(java.lang.Object)");
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    64
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    65
        // jar url: ct.sym, if it exists
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    66
        File ct_sym = new File(new File(java_home, "lib"), "ct.sym");
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    67
        if (ct_sym.exists()) {
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    68
            verify("jar:file:" + ct_sym + "!/META-INF/sym/rt.jar/java/util/Map.class",
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    69
                "public abstract boolean containsKey(java.lang.Object)");
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    70
        } else
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    71
            System.err.println("warning: ct.sym not found");
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    72
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    73
        if (errors > 0)
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    74
            throw new Error(errors + " found.");
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    75
    }
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    76
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    77
    void verify(String className, String... expects) {
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    78
        String output = javap(className);
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    79
        for (String expect: expects) {
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    80
            if (output.indexOf(expect)< 0)
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    81
                error(expect + " not found");
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    82
        }
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    83
    }
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    84
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    85
    void error(String msg) {
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    86
        System.err.println(msg);
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    87
        errors++;
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    88
    }
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    89
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    90
    int errors;
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    91
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    92
    String javap(String className) {
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    93
        String testClasses = System.getProperty("test.classes", ".");
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    94
        StringWriter sw = new StringWriter();
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    95
        PrintWriter out = new PrintWriter(sw);
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    96
        String[] args = { "-classpath", testClasses, className };
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    97
        int rc = com.sun.tools.javap.Main.run(args, out);
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    98
        out.close();
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
    99
        String output = sw.toString();
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
   100
        System.out.println("class " + className);
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
   101
        System.out.println(output);
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
   102
        if (rc != 0)
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
   103
            throw new Error("javap failed. rc=" + rc);
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
   104
        if (output.indexOf("Error:") != -1)
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
   105
            throw new Error("javap reported error.");
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
   106
        return output;
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
   107
    }
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
   108
}
fd92f0d28cb9 6729471: javap should accept class files on the command line
jjg
parents:
diff changeset
   109