author | naoto |
Tue, 29 Mar 2016 17:06:33 -0700 | |
changeset 36739 | 145210aba850 |
parent 30730 | d3ce7619db2c |
child 36991 | 7f814aac1f80 |
permissions | -rw-r--r-- |
5005 | 1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27579
diff
changeset
|
2 |
* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. |
5005 | 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 |
* |
|
5520 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
5005 | 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 |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27579
diff
changeset
|
28 |
* @modules jdk.compiler |
5005 | 29 |
*/ |
30 |
||
31 |
import java.io.*; |
|
32 |
import java.util.*; |
|
33 |
||
34 |
public class T6893943 { |
|
5217
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
35 |
static final String[] NO_ARGS = { }; |
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
36 |
static final String[] HELP = { "-help" }; |
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
37 |
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
|
38 |
|
5005 | 39 |
public static void main(String... args) throws Exception { |
40 |
new T6893943().run(); |
|
41 |
} |
|
42 |
||
43 |
void run() throws Exception { |
|
5217
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
44 |
testSimpleAPI(NO_ARGS, 1); |
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
45 |
testSimpleAPI(HELP, 0); |
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
46 |
testCommand(NO_ARGS, 1); |
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
47 |
testCommand(HELP, 0); |
5005 | 48 |
} |
49 |
||
5217
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
50 |
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
|
51 |
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
|
52 |
StringWriter sw = new StringWriter(); |
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
53 |
PrintWriter pw = new PrintWriter(sw); |
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
54 |
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
|
55 |
pw.close(); |
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
56 |
expect("testSimpleAPI", sw.toString(), rc, expect_rc); |
5005 | 57 |
} |
58 |
||
5217
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
59 |
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
|
60 |
System.err.println("Test command: " + Arrays.asList(args)); |
5005 | 61 |
File javaHome = new File(System.getProperty("java.home")); |
62 |
List<String> command = new ArrayList<String>(); |
|
63 |
command.add(new File(new File(javaHome, "bin"), "javah").getPath()); |
|
5217
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
64 |
command.addAll(Arrays.asList(args)); |
5005 | 65 |
//System.err.println("command: " + command); |
66 |
||
67 |
ProcessBuilder pb = new ProcessBuilder(command); |
|
68 |
pb.redirectErrorStream(true); |
|
69 |
Process p = pb.start(); |
|
70 |
p.getOutputStream().close(); |
|
5217
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
71 |
StringWriter sw = new StringWriter(); |
5005 | 72 |
String line; |
73 |
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); |
|
74 |
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
|
75 |
sw.write(line + NEWLINE); |
5005 | 76 |
int rc = p.waitFor(); |
5217
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
77 |
expect("testCommand", sw.toString(), rc, expect_rc); |
5005 | 78 |
} |
79 |
||
5217
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
80 |
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
|
81 |
if (out.isEmpty()) |
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
82 |
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
|
83 |
|
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
84 |
if (!out.startsWith("Usage:")) { |
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
85 |
System.err.println(out); |
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
86 |
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
|
87 |
} |
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
88 |
|
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
89 |
if (actual_rc != expect_rc) |
e20e20050405
6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents:
5005
diff
changeset
|
90 |
throw new Exception(name + ": unexpected exit: " + actual_rc + ", expected: " + expect_rc); |
5005 | 91 |
} |
92 |
} |