langtools/test/tools/javah/T7126832/T7126832.java
author jwilhelm
Thu, 07 Feb 2013 15:51:25 +0100
changeset 15605 bf7de87bbe3a
parent 11708 f83264d62af2
child 30730 d3ce7619db2c
permissions -rw-r--r--
8006432: Ratio flags should be unsigned Summary: Flags changed to be of uintx type Reviewed-by: johnc, tamao
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11708
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
     1
/*
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
     4
 *
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
     8
 *
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    13
 * accompanied this code).
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    14
 *
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    18
 *
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    21
 * questions.
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    22
 */
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    23
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    24
/*
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    25
 * @test
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    26
 * @bug 7126832
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    27
 * @compile java.java
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    28
 * @summary com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    29
 * @run main T7126832
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    30
 */
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    31
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    32
import java.io.*;
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    33
import java.util.*;
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    34
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    35
public class T7126832 {
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    36
    public static void main(String... args) throws Exception {
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    37
        new T7126832().run();
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    38
    }
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    39
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    40
    void run() throws Exception {
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    41
        Locale prev = Locale.getDefault();
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    42
        Locale.setDefault(Locale.ENGLISH);
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    43
        try {
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    44
            // Verify that a .java file is correctly diagnosed
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    45
            File ff = writeFile(new File("JavahTest.java"), "class JavahTest {}");
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    46
            test(Arrays.asList(ff.getPath()), 1, "Could not find class file for 'JavahTest.java'.");
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    47
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    48
            // Verify that a class named 'xx.java' is accepted.
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    49
            // Note that ./xx/java.class exists, so this should work ok
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    50
            test(Arrays.asList("xx.java"), 0, null);
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    51
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    52
            if (errors > 0) {
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    53
                throw new Exception(errors + " errors occurred");
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    54
            }
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    55
        } finally {
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    56
           Locale.setDefault(prev);
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    57
        }
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    58
    }
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    59
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    60
    void test(List<String> args, int expectRC, String expectOut) {
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    61
        System.err.println("Test: " + args
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    62
                + " rc:" + expectRC
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    63
                + ((expectOut != null) ? " out:" + expectOut : ""));
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    64
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    65
        StringWriter sw = new StringWriter();
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    66
        PrintWriter pw = new PrintWriter(sw);
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    67
        int rc = 0;
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    68
        String out = null;
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    69
        try {
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    70
            rc = com.sun.tools.javah.Main.run(args.toArray(new String[args.size()]), pw);
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    71
            out = sw.toString();
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    72
        } catch(Exception ee) {
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    73
            rc = 1;
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    74
            out = ee.toString();;
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    75
        }
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    76
        pw.close();
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    77
        if (!out.isEmpty()) {
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    78
            System.err.println(out);
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    79
        }
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    80
        if (rc != expectRC) {
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    81
            error("Unexpected exit code: " + rc + "; expected: " + expectRC);
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    82
        }
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    83
        if (expectOut != null && !out.contains(expectOut)) {
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    84
            error("Expected string not found: " + expectOut);
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    85
        }
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    86
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    87
        System.err.println();
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    88
    }
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    89
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    90
    File writeFile(File ff, String ss) throws IOException {
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    91
        if (ff.getParentFile() != null)
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    92
            ff.getParentFile().mkdirs();
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    93
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    94
        try (FileWriter out = new FileWriter(ff)) {
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    95
            out.write(ss);
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    96
        }
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    97
        return ff;
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    98
    }
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
    99
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
   100
    void error(String msg) {
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
   101
        System.err.println(msg);
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
   102
        errors++;
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
   103
    }
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
   104
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
   105
    int errors;
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
   106
}
f83264d62af2 7126832: com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager cannot be cast
jjh
parents:
diff changeset
   107