jjg@508: /* jjg@508: * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. jjg@508: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@508: * jjg@508: * This code is free software; you can redistribute it and/or modify it jjg@508: * under the terms of the GNU General Public License version 2 only, as jjg@508: * published by the Free Software Foundation. jjg@508: * jjg@508: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@508: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@508: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@508: * version 2 for more details (a copy is included in the LICENSE file that jjg@508: * accompanied this code). jjg@508: * jjg@508: * You should have received a copy of the GNU General Public License version jjg@508: * 2 along with this work; if not, write to the Free Software Foundation, jjg@508: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@508: * jjg@508: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, jjg@508: * CA 95054 USA or visit www.sun.com if you need additional information or jjg@508: * have any questions. jjg@508: */ jjg@508: jjg@508: /* jjg@508: * @test jjg@508: * @bug 6893943 jjg@508: * @summary exit code from javah with no args is 0 jjg@508: */ jjg@508: jjg@508: import java.io.*; jjg@508: import java.util.*; jjg@508: jjg@508: public class T6893943 { jjg@508: public static void main(String... args) throws Exception { jjg@508: new T6893943().run(); jjg@508: } jjg@508: jjg@508: void run() throws Exception { jjg@508: testSimpleAPI(); jjg@508: testCommand(); jjg@508: } jjg@508: jjg@508: void testSimpleAPI() throws Exception { jjg@508: PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.err)); jjg@508: int rc = com.sun.tools.javah.Main.run(new String[] { }, pw); jjg@508: expect("testSimpleAPI", rc, 1); jjg@508: } jjg@508: jjg@508: void testCommand() throws Exception { jjg@508: File javaHome = new File(System.getProperty("java.home")); jjg@508: if (javaHome.getName().equals("jre")) jjg@508: javaHome = javaHome.getParentFile(); jjg@508: jjg@508: List command = new ArrayList(); jjg@508: command.add(new File(new File(javaHome, "bin"), "javah").getPath()); jjg@508: command.add("-J-Xbootclasspath:" + System.getProperty("sun.boot.class.path")); jjg@508: //System.err.println("command: " + command); jjg@508: jjg@508: ProcessBuilder pb = new ProcessBuilder(command); jjg@508: pb.redirectErrorStream(true); jjg@508: Process p = pb.start(); jjg@508: p.getOutputStream().close(); jjg@508: String line; jjg@508: BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); jjg@508: while ((line = in.readLine()) != null) jjg@508: System.err.println("javah: " + line); jjg@508: int rc = p.waitFor(); jjg@508: expect("testCommand", rc, 1); jjg@508: } jjg@508: jjg@508: void expect(String name, int actual, int expect) throws Exception { jjg@508: if (actual != expect) jjg@508: throw new Exception(name + ": unexpected exit: " + actual + ", expected: " + expect); jjg@508: } jjg@508: }