706N/A/*
706N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
706N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
706N/A *
706N/A * This code is free software; you can redistribute it and/or modify it
706N/A * under the terms of the GNU General Public License version 2 only, as
706N/A * published by the Free Software Foundation.
706N/A *
706N/A * This code is distributed in the hope that it will be useful, but WITHOUT
706N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
706N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
706N/A * version 2 for more details (a copy is included in the LICENSE file that
706N/A * accompanied this code).
706N/A *
706N/A * You should have received a copy of the GNU General Public License version
706N/A * 2 along with this work; if not, write to the Free Software Foundation,
706N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
706N/A *
706N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
706N/A * or visit www.oracle.com if you need additional information or have any
706N/A * questions.
706N/A */
706N/A
706N/A/*
706N/A * @test
708N/A * @bug 6893932 6990390
706N/A * @summary javah help screen lists -h and -? but does not accept them
706N/A */
706N/A
706N/Aimport java.io.*;
706N/Aimport java.util.*;
706N/A
706N/Apublic class TestHelpOpts {
706N/A public static void main(String... args) throws Exception {
706N/A new TestHelpOpts().run();
706N/A }
706N/A
706N/A void run() throws Exception {
706N/A Locale prev = Locale.getDefault();
706N/A try {
706N/A Locale.setDefault(Locale.ENGLISH);
706N/A
706N/A String[] opts = { "-h", "-help", "-?", "--help" };
706N/A for (String opt: opts)
706N/A test(opt);
706N/A } finally {
706N/A Locale.setDefault(prev);
706N/A }
706N/A
706N/A if (errors > 0)
706N/A throw new Exception(errors + " errors occurred");
706N/A }
706N/A
706N/A void test(String opt) {
706N/A System.err.println("test " + opt);
706N/A String[] args = { opt };
706N/A
706N/A StringWriter sw = new StringWriter();
706N/A PrintWriter pw = new PrintWriter(sw);
706N/A int rc = com.sun.tools.javah.Main.run(args, pw);
706N/A pw.close();
706N/A String out = sw.toString();
706N/A if (!out.isEmpty())
706N/A System.err.println(out);
706N/A if (rc != 0)
706N/A error("Unexpected exit: rc=" + rc);
706N/A
706N/A String flat = out.replaceAll("\\s+", " "); // canonicalize whitespace
706N/A if (!flat.contains("Usage: javah [options] <classes> where [options] include:"))
706N/A error("expected text not found");
708N/A if (flat.contains("main.opt"))
708N/A error("key not found in resource bundle: " + flat.replaceAll(".*(main.opt.[^ ]*).*", "$1"));
706N/A }
706N/A
706N/A void error(String msg) {
706N/A System.err.println(msg);
706N/A errors++;
706N/A }
706N/A
706N/A int errors;
706N/A}