langtools/test/tools/javah/T6994608.java
author akulyakh
Thu, 21 May 2015 11:41:04 -0700
changeset 30730 d3ce7619db2c
parent 7078 17f1f2bdcb46
child 36991 7f814aac1f80
permissions -rw-r--r--
8076543: Add @modules as needed to the langtools tests Reviewed-by: jjg, shurailine
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7078
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 7078
diff changeset
     2
 * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
7078
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
     4
 *
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
     8
 *
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    13
 * accompanied this code).
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    14
 *
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    18
 *
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    21
 * questions.
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    22
 */
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    23
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    24
/*
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    25
 * @test
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    26
 * @bug 6994608
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    27
 * @summary javah no longer accepts parameter files as input
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 7078
diff changeset
    28
 * @modules jdk.compiler
7078
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    29
 */
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    30
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    31
import java.io.*;
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    32
import java.util.*;
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    33
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    34
public class T6994608 {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    35
    public static void main(String... args) throws Exception {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    36
        new T6994608().run();
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    37
    }
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    38
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    39
    void run() throws Exception {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    40
        Locale prev = Locale.getDefault();
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    41
        Locale.setDefault(Locale.ENGLISH);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    42
        try {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    43
            File f = writeFile(new File("classList"), "java.lang.Object");
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    44
            test(Arrays.asList("@" + f.getPath()), 0, null);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    45
            test(Arrays.asList("@badfile"), 1, "Can't find file badfile");
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    46
            if (errors > 0)
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    47
                throw new Exception(errors + " errors occurred");
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    48
        } finally {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    49
            Locale.setDefault(prev);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    50
        }
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    51
    }
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    52
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    53
    void test(List<String> args, int expectRC, String expectOut) {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    54
        System.err.println("Test: " + args
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    55
                + " rc:" + expectRC
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    56
                + ((expectOut != null) ? " out:" + expectOut : ""));
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    57
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    58
        StringWriter sw = new StringWriter();
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    59
        PrintWriter pw = new PrintWriter(sw);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    60
        int rc = com.sun.tools.javah.Main.run(args.toArray(new String[args.size()]), pw);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    61
        pw.close();
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    62
        String out = sw.toString();
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    63
        if (!out.isEmpty())
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    64
            System.err.println(out);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    65
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    66
        if (rc != expectRC)
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    67
            error("Unexpected exit code: " + rc + "; expected: " + expectRC);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    68
        if (expectOut != null && !out.contains(expectOut))
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    69
            error("Expected string not found: " + expectOut);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    70
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    71
        System.err.println();
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    72
    }
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    73
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    74
    File writeFile(File f, String s) throws IOException {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    75
        if (f.getParentFile() != null)
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    76
            f.getParentFile().mkdirs();
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    77
        try (FileWriter out = new FileWriter(f)) {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    78
            out.write(s);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    79
        }
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    80
        return f;
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    81
    }
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    82
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    83
    void error(String msg) {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    84
        System.err.println(msg);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    85
        errors++;
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    86
    }
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    87
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    88
    int errors;
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    89
}
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    90