langtools/test/tools/javah/T6893943.java
author peterz
Fri, 28 May 2010 13:32:40 +0400
changeset 5594 3db39773da2e
parent 5217 e20e20050405
child 5520 86e4b9a9da40
permissions -rw-r--r--
6954231: SynthTextPaneUI.installUI() doesn't set component to opaque even if prop was not set by client progr Reviewed-by: alexp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5005
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
     1
/*
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
     2
 * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
     4
 *
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
     8
 *
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    13
 * accompanied this code).
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    14
 *
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    18
 *
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    21
 * have any questions.
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    22
 */
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    23
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    24
/*
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    25
 * @test
5217
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    26
 * @bug 6893943 6937318
5005
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    27
 * @summary exit code from javah with no args is 0
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    28
 */
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    29
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    30
import java.io.*;
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    31
import java.util.*;
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    32
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    33
public class T6893943 {
5217
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    34
    static final String[] NO_ARGS = { };
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    35
    static final String[] HELP = { "-help" };
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    36
    static final String NEWLINE = System.getProperty("line.separator");
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    37
5005
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    38
    public static void main(String... args) throws Exception {
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    39
        new T6893943().run();
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    40
    }
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    41
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    42
    void run() throws Exception {
5217
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    43
        testSimpleAPI(NO_ARGS, 1);
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    44
        testSimpleAPI(HELP, 0);
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    45
        testCommand(NO_ARGS, 1);
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    46
        testCommand(HELP, 0);
5005
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    47
    }
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    48
5217
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    49
    void testSimpleAPI(String[] args, int expect_rc) throws Exception {
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    50
        System.err.println("Test simple api: " + Arrays.asList(args));
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    51
        StringWriter sw = new StringWriter();
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    52
        PrintWriter pw = new PrintWriter(sw);
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    53
        int rc = com.sun.tools.javah.Main.run(args, pw);
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    54
        pw.close();
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    55
        expect("testSimpleAPI", sw.toString(), rc, expect_rc);
5005
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    56
    }
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    57
5217
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    58
    void testCommand(String[] args, int expect_rc) throws Exception {
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    59
        System.err.println("Test command: " + Arrays.asList(args));
5005
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    60
        File javaHome = new File(System.getProperty("java.home"));
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    61
        if (javaHome.getName().equals("jre"))
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    62
            javaHome = javaHome.getParentFile();
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    63
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    64
        List<String> command = new ArrayList<String>();
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    65
        command.add(new File(new File(javaHome, "bin"), "javah").getPath());
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    66
        command.add("-J-Xbootclasspath:" + System.getProperty("sun.boot.class.path"));
5217
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    67
        command.addAll(Arrays.asList(args));
5005
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    68
        //System.err.println("command: " + command);
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    69
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    70
        ProcessBuilder pb = new ProcessBuilder(command);
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    71
        pb.redirectErrorStream(true);
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    72
        Process p = pb.start();
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    73
        p.getOutputStream().close();
5217
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    74
        StringWriter sw = new StringWriter();
5005
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    75
        String line;
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    76
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    77
        while ((line = in.readLine()) != null)
5217
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    78
            sw.write(line + NEWLINE);
5005
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    79
        int rc = p.waitFor();
5217
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    80
        expect("testCommand", sw.toString(), rc, expect_rc);
5005
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    81
    }
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    82
5217
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    83
    void expect(String name, String out, int actual_rc, int expect_rc) throws Exception {
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    84
        if (out.isEmpty())
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    85
            throw new Exception("No output from javah");
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    86
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    87
        if (!out.startsWith("Usage:")) {
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    88
            System.err.println(out);
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    89
            throw new Exception("Unexpected output from javah");
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    90
        }
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    91
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    92
        if (actual_rc != expect_rc)
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
    93
            throw new Exception(name + ": unexpected exit: " + actual_rc + ", expected: " + expect_rc);
5005
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    94
    }
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents:
diff changeset
    95
}