langtools/test/tools/javah/VersionTest.java
author jwilhelm
Thu, 07 Feb 2013 15:51:25 +0100
changeset 15605 bf7de87bbe3a
parent 6715 9afc72714ca4
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:
6715
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
     1
/*
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
     4
 *
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
     8
 *
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    13
 * accompanied this code).
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    14
 *
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    18
 *
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    21
 * questions.
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    22
 */
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    23
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    24
/*
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    25
 * @test
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    26
 * @bug 6890226
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    27
 * @summary javah -version is broken
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    28
 */
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    29
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    30
import java.io.*;
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    31
import java.util.Locale;
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    32
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    33
public class VersionTest {
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    34
    public static void main(String... args) {
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    35
        Locale prev = Locale.getDefault();
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    36
        try {
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    37
            Locale.setDefault(Locale.ENGLISH);
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    38
            System.err.println(Locale.getDefault());
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    39
            test("-version", "\\S+ version \"\\S+\"");
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    40
            test("-fullversion", "\\S+ full version \"\\S+\"");
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    41
        } finally {
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    42
            Locale.setDefault(prev);
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    43
        }
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    44
    }
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    45
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    46
    static void test(String option, String regex) {
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    47
        StringWriter sw = new StringWriter();
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    48
        PrintWriter pw = new PrintWriter(sw);
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    49
        String[] args = { option };
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    50
        int rc = com.sun.tools.javah.Main.run(args, pw);
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    51
        pw.close();
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    52
        if (rc != 0)
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    53
            throw new Error("javah failed: rc=" + rc);
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    54
        String out = sw.toString().trim();
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    55
        System.err.println(out);
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    56
        if (!out.matches(regex))
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    57
            throw new Error("output does not match pattern: " + regex);
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    58
    }
9afc72714ca4 6890226: javah -version is broken
jjg
parents:
diff changeset
    59
}