author | peterz |
Fri, 28 May 2010 13:32:40 +0400 | |
changeset 5594 | 3db39773da2e |
parent 5217 | e20e20050405 |
child 5520 | 86e4b9a9da40 |
permissions | -rw-r--r-- |
5005 | 1 |
/* |
2 |
* Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 |
* have any questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
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 | 27 |
* @summary exit code from javah with no args is 0 |
28 |
*/ |
|
29 |
||
30 |
import java.io.*; |
|
31 |
import java.util.*; |
|
32 |
||
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 | 38 |
public static void main(String... args) throws Exception { |
39 |
new T6893943().run(); |
|
40 |
} |
|
41 |
||
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 | 47 |
} |
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 | 56 |
} |
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 | 60 |
File javaHome = new File(System.getProperty("java.home")); |
61 |
if (javaHome.getName().equals("jre")) |
|
62 |
javaHome = javaHome.getParentFile(); |
|
63 |
||
64 |
List<String> command = new ArrayList<String>(); |
|
65 |
command.add(new File(new File(javaHome, "bin"), "javah").getPath()); |
|
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 | 68 |
//System.err.println("command: " + command); |
69 |
||
70 |
ProcessBuilder pb = new ProcessBuilder(command); |
|
71 |
pb.redirectErrorStream(true); |
|
72 |
Process p = pb.start(); |
|
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 | 75 |
String line; |
76 |
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); |
|
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 | 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 | 81 |
} |
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 | 94 |
} |
95 |
} |