1137N/A/*
1137N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
1137N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1137N/A *
1137N/A * This code is free software; you can redistribute it and/or modify it
1137N/A * under the terms of the GNU General Public License version 2 only, as
1137N/A * published by the Free Software Foundation.
1137N/A *
1137N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1137N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1137N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1137N/A * version 2 for more details (a copy is included in the LICENSE file that
1137N/A * accompanied this code).
1137N/A *
1137N/A * You should have received a copy of the GNU General Public License version
1137N/A * 2 along with this work; if not, write to the Free Software Foundation,
1137N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1137N/A *
1137N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1137N/A * or visit www.oracle.com if you need additional information or have any
1137N/A * questions.
1137N/A */
1137N/A
1137N/A/*
1137N/A * @test
1137N/A * @bug 7126832
1137N/A * @compile java.java
1137N/A * @summary com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
1137N/A * @run main T7126832
1137N/A */
1137N/A
1137N/Aimport java.io.*;
1137N/Aimport java.util.*;
1137N/A
1137N/Apublic class T7126832 {
1137N/A public static void main(String... args) throws Exception {
1137N/A new T7126832().run();
1137N/A }
1137N/A
1137N/A void run() throws Exception {
1137N/A Locale prev = Locale.getDefault();
1137N/A Locale.setDefault(Locale.ENGLISH);
1137N/A try {
1137N/A // Verify that a .java file is correctly diagnosed
1137N/A File ff = writeFile(new File("JavahTest.java"), "class JavahTest {}");
1137N/A test(Arrays.asList(ff.getPath()), 1, "Could not find class file for 'JavahTest.java'.");
1137N/A
1137N/A // Verify that a class named 'xx.java' is accepted.
1137N/A // Note that ./xx/java.class exists, so this should work ok
1137N/A test(Arrays.asList("xx.java"), 0, null);
1137N/A
1137N/A if (errors > 0) {
1137N/A throw new Exception(errors + " errors occurred");
1137N/A }
1137N/A } finally {
1137N/A Locale.setDefault(prev);
1137N/A }
1137N/A }
1137N/A
1137N/A void test(List<String> args, int expectRC, String expectOut) {
1137N/A System.err.println("Test: " + args
1137N/A + " rc:" + expectRC
1137N/A + ((expectOut != null) ? " out:" + expectOut : ""));
1137N/A
1137N/A StringWriter sw = new StringWriter();
1137N/A PrintWriter pw = new PrintWriter(sw);
1137N/A int rc = 0;
1137N/A String out = null;
1137N/A try {
1137N/A rc = com.sun.tools.javah.Main.run(args.toArray(new String[args.size()]), pw);
1137N/A out = sw.toString();
1137N/A } catch(Exception ee) {
1137N/A rc = 1;
1137N/A out = ee.toString();;
1137N/A }
1137N/A pw.close();
1137N/A if (!out.isEmpty()) {
1137N/A System.err.println(out);
1137N/A }
1137N/A if (rc != expectRC) {
1137N/A error("Unexpected exit code: " + rc + "; expected: " + expectRC);
1137N/A }
1137N/A if (expectOut != null && !out.contains(expectOut)) {
1137N/A error("Expected string not found: " + expectOut);
1137N/A }
1137N/A
1137N/A System.err.println();
1137N/A }
1137N/A
1137N/A File writeFile(File ff, String ss) throws IOException {
1137N/A if (ff.getParentFile() != null)
1137N/A ff.getParentFile().mkdirs();
1137N/A
1137N/A try (FileWriter out = new FileWriter(ff)) {
1137N/A out.write(ss);
1137N/A }
1137N/A return ff;
1137N/A }
1137N/A
1137N/A void error(String msg) {
1137N/A System.err.println(msg);
1137N/A errors++;
1137N/A }
1137N/A
1137N/A int errors;
1137N/A}
1137N/A