Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javah/T7126832/T7126832.java
38813 views
/*1* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 712683226* @compile java.java27* @summary com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast28* @run main T712683229*/3031import java.io.*;32import java.util.*;3334public class T7126832 {35public static void main(String... args) throws Exception {36new T7126832().run();37}3839void run() throws Exception {40Locale prev = Locale.getDefault();41Locale.setDefault(Locale.ENGLISH);42try {43// Verify that a .java file is correctly diagnosed44File ff = writeFile(new File("JavahTest.java"), "class JavahTest {}");45test(Arrays.asList(ff.getPath()), 1, "Could not find class file for 'JavahTest.java'.");4647// Verify that a class named 'xx.java' is accepted.48// Note that ./xx/java.class exists, so this should work ok49test(Arrays.asList("xx.java"), 0, null);5051if (errors > 0) {52throw new Exception(errors + " errors occurred");53}54} finally {55Locale.setDefault(prev);56}57}5859void test(List<String> args, int expectRC, String expectOut) {60System.err.println("Test: " + args61+ " rc:" + expectRC62+ ((expectOut != null) ? " out:" + expectOut : ""));6364StringWriter sw = new StringWriter();65PrintWriter pw = new PrintWriter(sw);66int rc = 0;67String out = null;68try {69rc = com.sun.tools.javah.Main.run(args.toArray(new String[args.size()]), pw);70out = sw.toString();71} catch(Exception ee) {72rc = 1;73out = ee.toString();;74}75pw.close();76if (!out.isEmpty()) {77System.err.println(out);78}79if (rc != expectRC) {80error("Unexpected exit code: " + rc + "; expected: " + expectRC);81}82if (expectOut != null && !out.contains(expectOut)) {83error("Expected string not found: " + expectOut);84}8586System.err.println();87}8889File writeFile(File ff, String ss) throws IOException {90if (ff.getParentFile() != null)91ff.getParentFile().mkdirs();9293try (FileWriter out = new FileWriter(ff)) {94out.write(ss);95}96return ff;97}9899void error(String msg) {100System.err.println(msg);101errors++;102}103104int errors;105}106107108109