test/tools/javah/T6893943.java

Thu, 25 Feb 2010 13:32:08 -0800

author
jjg
date
Thu, 25 Feb 2010 13:32:08 -0800
changeset 508
af75fd6155de
child 529
3058880c0b8d
permissions
-rw-r--r--

6893943: exit code from javah with no args is 0
Reviewed-by: darcy

jjg@508 1 /*
jjg@508 2 * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
jjg@508 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@508 4 *
jjg@508 5 * This code is free software; you can redistribute it and/or modify it
jjg@508 6 * under the terms of the GNU General Public License version 2 only, as
jjg@508 7 * published by the Free Software Foundation.
jjg@508 8 *
jjg@508 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@508 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@508 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@508 12 * version 2 for more details (a copy is included in the LICENSE file that
jjg@508 13 * accompanied this code).
jjg@508 14 *
jjg@508 15 * You should have received a copy of the GNU General Public License version
jjg@508 16 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@508 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@508 18 *
jjg@508 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
jjg@508 20 * CA 95054 USA or visit www.sun.com if you need additional information or
jjg@508 21 * have any questions.
jjg@508 22 */
jjg@508 23
jjg@508 24 /*
jjg@508 25 * @test
jjg@508 26 * @bug 6893943
jjg@508 27 * @summary exit code from javah with no args is 0
jjg@508 28 */
jjg@508 29
jjg@508 30 import java.io.*;
jjg@508 31 import java.util.*;
jjg@508 32
jjg@508 33 public class T6893943 {
jjg@508 34 public static void main(String... args) throws Exception {
jjg@508 35 new T6893943().run();
jjg@508 36 }
jjg@508 37
jjg@508 38 void run() throws Exception {
jjg@508 39 testSimpleAPI();
jjg@508 40 testCommand();
jjg@508 41 }
jjg@508 42
jjg@508 43 void testSimpleAPI() throws Exception {
jjg@508 44 PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.err));
jjg@508 45 int rc = com.sun.tools.javah.Main.run(new String[] { }, pw);
jjg@508 46 expect("testSimpleAPI", rc, 1);
jjg@508 47 }
jjg@508 48
jjg@508 49 void testCommand() throws Exception {
jjg@508 50 File javaHome = new File(System.getProperty("java.home"));
jjg@508 51 if (javaHome.getName().equals("jre"))
jjg@508 52 javaHome = javaHome.getParentFile();
jjg@508 53
jjg@508 54 List<String> command = new ArrayList<String>();
jjg@508 55 command.add(new File(new File(javaHome, "bin"), "javah").getPath());
jjg@508 56 command.add("-J-Xbootclasspath:" + System.getProperty("sun.boot.class.path"));
jjg@508 57 //System.err.println("command: " + command);
jjg@508 58
jjg@508 59 ProcessBuilder pb = new ProcessBuilder(command);
jjg@508 60 pb.redirectErrorStream(true);
jjg@508 61 Process p = pb.start();
jjg@508 62 p.getOutputStream().close();
jjg@508 63 String line;
jjg@508 64 BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
jjg@508 65 while ((line = in.readLine()) != null)
jjg@508 66 System.err.println("javah: " + line);
jjg@508 67 int rc = p.waitFor();
jjg@508 68 expect("testCommand", rc, 1);
jjg@508 69 }
jjg@508 70
jjg@508 71 void expect(String name, int actual, int expect) throws Exception {
jjg@508 72 if (actual != expect)
jjg@508 73 throw new Exception(name + ": unexpected exit: " + actual + ", expected: " + expect);
jjg@508 74 }
jjg@508 75 }

mercurial