test/tools/javah/constMacroTest/ConstMacroTest.java

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javah/constMacroTest/ConstMacroTest.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,117 @@
     1.4 +/*
     1.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test
    1.29 + * @bug 4786406 4781221 4780341 6214324
    1.30 + * @summary Validates rewritten javah handling of class defined constants and
    1.31 + * ensures that the appropriate macro definitions are placed in the generated
    1.32 + * header file.
    1.33 + * @library /tools/javac/lib
    1.34 + * @build ToolBox
    1.35 + * @run main ConstMacroTest
    1.36 + */
    1.37 +
    1.38 +import java.io.*;
    1.39 +import java.nio.file.Paths;
    1.40 +
    1.41 +//original test: test/tools/javah/ConstMacroTest.sh
    1.42 +public class ConstMacroTest {
    1.43 +
    1.44 +    private static final String subClassConstsGoldenFileTemplate =
    1.45 +        "/* DO NOT EDIT THIS FILE - it is machine generated */\n" +
    1.46 +        "#include <jni.h>\n" +
    1.47 +        "/* Header for class SubClassConsts */\n" +
    1.48 +        "\n" +
    1.49 +        "#ifndef _Included_SubClassConsts\n" +
    1.50 +        "#define _Included_SubClassConsts\n" +
    1.51 +        "#ifdef __cplusplus\n" +
    1.52 +        "extern \"C\" {\n" +
    1.53 +        "#endif\n" +
    1.54 +        "#undef SubClassConsts_serialVersionUID\n" +
    1.55 +        "#define SubClassConsts_serialVersionUID 6733861379283244755%s\n" +
    1.56 +        "#undef SubClassConsts_SUPER_INT_CONSTANT\n" +
    1.57 +        "#define SubClassConsts_SUPER_INT_CONSTANT 3L\n" +
    1.58 +        "#undef SubClassConsts_SUPER_FLOAT_CONSTANT\n" +
    1.59 +        "#define SubClassConsts_SUPER_FLOAT_CONSTANT 99.3f\n" +
    1.60 +        "#undef SubClassConsts_SUPER_DOUBLE_CONSTANT\n" +
    1.61 +        "#define SubClassConsts_SUPER_DOUBLE_CONSTANT 33.2\n" +
    1.62 +        "#undef SubClassConsts_SUPER_BOOLEAN_CONSTANT\n" +
    1.63 +        "#define SubClassConsts_SUPER_BOOLEAN_CONSTANT 0L\n" +
    1.64 +        "#undef SubClassConsts_SUB_INT_CONSTANT\n" +
    1.65 +        "#define SubClassConsts_SUB_INT_CONSTANT 2L\n" +
    1.66 +        "#undef SubClassConsts_SUB_DOUBLE_CONSTANT\n" +
    1.67 +        "#define SubClassConsts_SUB_DOUBLE_CONSTANT 2.25\n" +
    1.68 +        "#undef SubClassConsts_SUB_FLOAT_CONSTANT\n" +
    1.69 +        "#define SubClassConsts_SUB_FLOAT_CONSTANT 7.9f\n" +
    1.70 +        "#undef SubClassConsts_SUB_BOOLEAN_CONSTANT\n" +
    1.71 +        "#define SubClassConsts_SUB_BOOLEAN_CONSTANT 1L\n" +
    1.72 +        "#ifdef __cplusplus\n" +
    1.73 +        "}\n" +
    1.74 +        "#endif\n" +
    1.75 +        "#endif";
    1.76 +
    1.77 +    private static final String serialVersionUIDSuffix =
    1.78 +            ToolBox.isWindows() ? "i64" : "LL"; ;
    1.79 +
    1.80 +    public static void main(String[] args) throws Exception {
    1.81 +        //first steps are now done by jtreg
    1.82 +//        cp "${TESTSRC}${FS}SuperClassConsts.java" .
    1.83 +//        cp "${TESTSRC}${FS}SubClassConsts.java" .
    1.84 +
    1.85 +//        "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d . "${TESTSRC}${FS}SubClassConsts.java"
    1.86 +
    1.87 +//        "${TESTJAVA}${FS}bin${FS}javah" ${TESTTOOLVMOPTS} SubClassConsts
    1.88 +        ToolBox.JavaToolArgs successParams =
    1.89 +                new ToolBox.JavaToolArgs()
    1.90 +                .setAllArgs("-cp", System.getProperty("test.classes"), "SubClassConsts");
    1.91 +        ToolBox.javah(successParams);
    1.92 +
    1.93 +//        diff ${DIFFOPTS} "${TESTSRC}${FS}${EXPECTED_JAVAH_OUT_FILE}" "${GENERATED_HEADER_FILE}"
    1.94 +        String subClassConstGoldenFile = String.format(subClassConstsGoldenFileTemplate,
    1.95 +                serialVersionUIDSuffix);
    1.96 +        ToolBox.compareLines(Paths.get("SubClassConsts.h"),
    1.97 +                ToolBox.splitLines(subClassConstGoldenFile, "\n"), null, true);
    1.98 +    }
    1.99 +
   1.100 +}
   1.101 +
   1.102 +class SuperClassConsts implements Serializable {
   1.103 +    // Define class constant values, base class is serializable
   1.104 +    private static final long serialVersionUID = 6733861379283244755L;
   1.105 +    public static final int SUPER_INT_CONSTANT = 3;
   1.106 +    public final static float SUPER_FLOAT_CONSTANT = 99.3f;
   1.107 +    public final static double SUPER_DOUBLE_CONSTANT  = 33.2;
   1.108 +    public final static boolean SUPER_BOOLEAN_CONSTANT  = false;
   1.109 +    // A token instance field
   1.110 +    int instanceField;
   1.111 +
   1.112 +    public native int numValues();
   1.113 +}
   1.114 +
   1.115 +class SubClassConsts extends SuperClassConsts {
   1.116 +    private final static int SUB_INT_CONSTANT = 2;
   1.117 +    private final static double SUB_DOUBLE_CONSTANT = 2.25;
   1.118 +    private final static float SUB_FLOAT_CONSTANT = 7.90f;
   1.119 +    private final static boolean SUB_BOOLEAN_CONSTANT = true;
   1.120 +}

mercurial