Thu, 21 May 2015 10:00:43 -0700
Added tag jdk8u60-b16 for changeset ecb7e46b820f
jjg@707 | 1 | /* |
jjg@707 | 2 | * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
jjg@707 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@707 | 4 | * |
jjg@707 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@707 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@707 | 7 | * published by the Free Software Foundation. |
jjg@707 | 8 | * |
jjg@707 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@707 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@707 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@707 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@707 | 13 | * accompanied this code). |
jjg@707 | 14 | * |
jjg@707 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@707 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@707 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@707 | 18 | * |
jjg@707 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jjg@707 | 20 | * or visit www.oracle.com if you need additional information or have any |
jjg@707 | 21 | * questions. |
jjg@707 | 22 | */ |
jjg@707 | 23 | |
jjg@707 | 24 | /* |
jjg@707 | 25 | * @test |
jjg@709 | 26 | * @bug 6893932 6990390 |
jjg@707 | 27 | * @summary javah help screen lists -h and -? but does not accept them |
jjg@707 | 28 | */ |
jjg@707 | 29 | |
jjg@707 | 30 | import java.io.*; |
jjg@707 | 31 | import java.util.*; |
jjg@707 | 32 | |
jjg@707 | 33 | public class TestHelpOpts { |
jjg@707 | 34 | public static void main(String... args) throws Exception { |
jjg@707 | 35 | new TestHelpOpts().run(); |
jjg@707 | 36 | } |
jjg@707 | 37 | |
jjg@707 | 38 | void run() throws Exception { |
jjg@707 | 39 | Locale prev = Locale.getDefault(); |
jjg@707 | 40 | try { |
jjg@707 | 41 | Locale.setDefault(Locale.ENGLISH); |
jjg@707 | 42 | |
jjg@707 | 43 | String[] opts = { "-h", "-help", "-?", "--help" }; |
jjg@707 | 44 | for (String opt: opts) |
jjg@707 | 45 | test(opt); |
jjg@707 | 46 | } finally { |
jjg@707 | 47 | Locale.setDefault(prev); |
jjg@707 | 48 | } |
jjg@707 | 49 | |
jjg@707 | 50 | if (errors > 0) |
jjg@707 | 51 | throw new Exception(errors + " errors occurred"); |
jjg@707 | 52 | } |
jjg@707 | 53 | |
jjg@707 | 54 | void test(String opt) { |
jjg@707 | 55 | System.err.println("test " + opt); |
jjg@707 | 56 | String[] args = { opt }; |
jjg@707 | 57 | |
jjg@707 | 58 | StringWriter sw = new StringWriter(); |
jjg@707 | 59 | PrintWriter pw = new PrintWriter(sw); |
jjg@707 | 60 | int rc = com.sun.tools.javah.Main.run(args, pw); |
jjg@707 | 61 | pw.close(); |
jjg@707 | 62 | String out = sw.toString(); |
jjg@707 | 63 | if (!out.isEmpty()) |
jjg@707 | 64 | System.err.println(out); |
jjg@707 | 65 | if (rc != 0) |
jjg@707 | 66 | error("Unexpected exit: rc=" + rc); |
jjg@707 | 67 | |
jjg@707 | 68 | String flat = out.replaceAll("\\s+", " "); // canonicalize whitespace |
jjg@707 | 69 | if (!flat.contains("Usage: javah [options] <classes> where [options] include:")) |
jjg@707 | 70 | error("expected text not found"); |
jjg@709 | 71 | if (flat.contains("main.opt")) |
jjg@709 | 72 | error("key not found in resource bundle: " + flat.replaceAll(".*(main.opt.[^ ]*).*", "$1")); |
jjg@707 | 73 | } |
jjg@707 | 74 | |
jjg@707 | 75 | void error(String msg) { |
jjg@707 | 76 | System.err.println(msg); |
jjg@707 | 77 | errors++; |
jjg@707 | 78 | } |
jjg@707 | 79 | |
jjg@707 | 80 | int errors; |
jjg@707 | 81 | } |