test/tools/javah/T7126832/T7126832.java

Mon, 26 Oct 2015 13:23:30 -0700

author
asaha
date
Mon, 26 Oct 2015 13:23:30 -0700
changeset 2999
683b3e7e05a7
parent 0
959103a6100f
permissions
-rw-r--r--

Added tag jdk8u76-b00 for changeset 10ffafaf5340

     1 /*
     2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     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  *
    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.
    22  */
    24 /*
    25  * @test
    26  * @bug 7126832
    27  * @compile java.java
    28  * @summary com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
    29  * @run main T7126832
    30  */
    32 import java.io.*;
    33 import java.util.*;
    35 public class T7126832 {
    36     public static void main(String... args) throws Exception {
    37         new T7126832().run();
    38     }
    40     void run() throws Exception {
    41         Locale prev = Locale.getDefault();
    42         Locale.setDefault(Locale.ENGLISH);
    43         try {
    44             // Verify that a .java file is correctly diagnosed
    45             File ff = writeFile(new File("JavahTest.java"), "class JavahTest {}");
    46             test(Arrays.asList(ff.getPath()), 1, "Could not find class file for 'JavahTest.java'.");
    48             // Verify that a class named 'xx.java' is accepted.
    49             // Note that ./xx/java.class exists, so this should work ok
    50             test(Arrays.asList("xx.java"), 0, null);
    52             if (errors > 0) {
    53                 throw new Exception(errors + " errors occurred");
    54             }
    55         } finally {
    56            Locale.setDefault(prev);
    57         }
    58     }
    60     void test(List<String> args, int expectRC, String expectOut) {
    61         System.err.println("Test: " + args
    62                 + " rc:" + expectRC
    63                 + ((expectOut != null) ? " out:" + expectOut : ""));
    65         StringWriter sw = new StringWriter();
    66         PrintWriter pw = new PrintWriter(sw);
    67         int rc = 0;
    68         String out = null;
    69         try {
    70             rc = com.sun.tools.javah.Main.run(args.toArray(new String[args.size()]), pw);
    71             out = sw.toString();
    72         } catch(Exception ee) {
    73             rc = 1;
    74             out = ee.toString();;
    75         }
    76         pw.close();
    77         if (!out.isEmpty()) {
    78             System.err.println(out);
    79         }
    80         if (rc != expectRC) {
    81             error("Unexpected exit code: " + rc + "; expected: " + expectRC);
    82         }
    83         if (expectOut != null && !out.contains(expectOut)) {
    84             error("Expected string not found: " + expectOut);
    85         }
    87         System.err.println();
    88     }
    90     File writeFile(File ff, String ss) throws IOException {
    91         if (ff.getParentFile() != null)
    92             ff.getParentFile().mkdirs();
    94         try (FileWriter out = new FileWriter(ff)) {
    95             out.write(ss);
    96         }
    97         return ff;
    98     }
   100     void error(String msg) {
   101         System.err.println(msg);
   102         errors++;
   103     }
   105     int errors;
   106 }

mercurial