test/tools/javah/T6994608.java

Fri, 23 Aug 2013 14:17:49 -0700

author
lana
date
Fri, 23 Aug 2013 14:17:49 -0700
changeset 1967
375834b5cf08
parent 0
959103a6100f
permissions
-rw-r--r--

Merge

     1 /*
     2  * Copyright (c) 2010, 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 6994608
    27  * @summary javah no longer accepts parameter files as input
    28  */
    30 import java.io.*;
    31 import java.util.*;
    33 public class T6994608 {
    34     public static void main(String... args) throws Exception {
    35         new T6994608().run();
    36     }
    38     void run() throws Exception {
    39         Locale prev = Locale.getDefault();
    40         Locale.setDefault(Locale.ENGLISH);
    41         try {
    42             File f = writeFile(new File("classList"), "java.lang.Object");
    43             test(Arrays.asList("@" + f.getPath()), 0, null);
    44             test(Arrays.asList("@badfile"), 1, "Can't find file badfile");
    45             if (errors > 0)
    46                 throw new Exception(errors + " errors occurred");
    47         } finally {
    48             Locale.setDefault(prev);
    49         }
    50     }
    52     void test(List<String> args, int expectRC, String expectOut) {
    53         System.err.println("Test: " + args
    54                 + " rc:" + expectRC
    55                 + ((expectOut != null) ? " out:" + expectOut : ""));
    57         StringWriter sw = new StringWriter();
    58         PrintWriter pw = new PrintWriter(sw);
    59         int rc = com.sun.tools.javah.Main.run(args.toArray(new String[args.size()]), pw);
    60         pw.close();
    61         String out = sw.toString();
    62         if (!out.isEmpty())
    63             System.err.println(out);
    65         if (rc != expectRC)
    66             error("Unexpected exit code: " + rc + "; expected: " + expectRC);
    67         if (expectOut != null && !out.contains(expectOut))
    68             error("Expected string not found: " + expectOut);
    70         System.err.println();
    71     }
    73     File writeFile(File f, String s) throws IOException {
    74         if (f.getParentFile() != null)
    75             f.getParentFile().mkdirs();
    76         try (FileWriter out = new FileWriter(f)) {
    77             out.write(s);
    78         }
    79         return f;
    80     }
    82     void error(String msg) {
    83         System.err.println(msg);
    84         errors++;
    85     }
    87     int errors;
    88 }

mercurial