langtools/test/tools/javah/constMacroTest/ConstMacroTest.java
author duke
Wed, 05 Jul 2017 18:59:39 +0200
changeset 18044 f1a01fb5f958
parent 16549 1bdeedb5446c
child 26100 bb7dd001d190
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16304
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
     1
/*
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
     4
 *
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
     7
 * published by the Free Software Foundation.
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
     8
 *
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    13
 * accompanied this code).
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    14
 *
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    18
 *
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    21
 * questions.
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    22
 */
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    23
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    24
/*
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    25
 * @test
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    26
 * @bug 4786406 4781221 4780341 6214324
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    27
 * @summary Validates rewritten javah handling of class defined constants and
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    28
 * ensures that the appropriate macro definitions are placed in the generated
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    29
 * header file.
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    30
 * @library /tools/javac/lib
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    31
 * @build ToolBox
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    32
 * @run main ConstMacroTest
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    33
 */
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    34
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    35
import java.io.*;
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    36
import java.nio.file.Paths;
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    37
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    38
//original test: test/tools/javah/ConstMacroTest.sh
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    39
public class ConstMacroTest {
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    40
16549
1bdeedb5446c 8008582: jtreg failures after conversion of shell tests to Java
vromero
parents: 16304
diff changeset
    41
    private static final String subClassConstsGoldenFileTemplate =
16304
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    42
        "/* DO NOT EDIT THIS FILE - it is machine generated */\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    43
        "#include <jni.h>\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    44
        "/* Header for class SubClassConsts */\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    45
        "\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    46
        "#ifndef _Included_SubClassConsts\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    47
        "#define _Included_SubClassConsts\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    48
        "#ifdef __cplusplus\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    49
        "extern \"C\" {\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    50
        "#endif\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    51
        "#undef SubClassConsts_serialVersionUID\n" +
16549
1bdeedb5446c 8008582: jtreg failures after conversion of shell tests to Java
vromero
parents: 16304
diff changeset
    52
        "#define SubClassConsts_serialVersionUID 6733861379283244755%s\n" +
16304
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    53
        "#undef SubClassConsts_SUPER_INT_CONSTANT\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    54
        "#define SubClassConsts_SUPER_INT_CONSTANT 3L\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    55
        "#undef SubClassConsts_SUPER_FLOAT_CONSTANT\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    56
        "#define SubClassConsts_SUPER_FLOAT_CONSTANT 99.3f\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    57
        "#undef SubClassConsts_SUPER_DOUBLE_CONSTANT\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    58
        "#define SubClassConsts_SUPER_DOUBLE_CONSTANT 33.2\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    59
        "#undef SubClassConsts_SUPER_BOOLEAN_CONSTANT\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    60
        "#define SubClassConsts_SUPER_BOOLEAN_CONSTANT 0L\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    61
        "#undef SubClassConsts_SUB_INT_CONSTANT\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    62
        "#define SubClassConsts_SUB_INT_CONSTANT 2L\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    63
        "#undef SubClassConsts_SUB_DOUBLE_CONSTANT\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    64
        "#define SubClassConsts_SUB_DOUBLE_CONSTANT 2.25\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    65
        "#undef SubClassConsts_SUB_FLOAT_CONSTANT\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    66
        "#define SubClassConsts_SUB_FLOAT_CONSTANT 7.9f\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    67
        "#undef SubClassConsts_SUB_BOOLEAN_CONSTANT\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    68
        "#define SubClassConsts_SUB_BOOLEAN_CONSTANT 1L\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    69
        "#ifdef __cplusplus\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    70
        "}\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    71
        "#endif\n" +
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    72
        "#endif";
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    73
16549
1bdeedb5446c 8008582: jtreg failures after conversion of shell tests to Java
vromero
parents: 16304
diff changeset
    74
    private static final String serialVersionUIDSuffix =
1bdeedb5446c 8008582: jtreg failures after conversion of shell tests to Java
vromero
parents: 16304
diff changeset
    75
            ToolBox.isWindows() ? "i64" : "LL"; ;
1bdeedb5446c 8008582: jtreg failures after conversion of shell tests to Java
vromero
parents: 16304
diff changeset
    76
16304
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    77
    public static void main(String[] args) throws Exception {
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    78
        //first steps are now done by jtreg
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    79
//        cp "${TESTSRC}${FS}SuperClassConsts.java" .
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    80
//        cp "${TESTSRC}${FS}SubClassConsts.java" .
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    81
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    82
//        "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d . "${TESTSRC}${FS}SubClassConsts.java"
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    83
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    84
//        "${TESTJAVA}${FS}bin${FS}javah" ${TESTTOOLVMOPTS} SubClassConsts
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    85
        ToolBox.JavaToolArgs successParams =
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    86
                new ToolBox.JavaToolArgs()
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    87
                .setAllArgs("-cp", System.getProperty("test.classes"), "SubClassConsts");
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    88
        ToolBox.javah(successParams);
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    89
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    90
//        diff ${DIFFOPTS} "${TESTSRC}${FS}${EXPECTED_JAVAH_OUT_FILE}" "${GENERATED_HEADER_FILE}"
16549
1bdeedb5446c 8008582: jtreg failures after conversion of shell tests to Java
vromero
parents: 16304
diff changeset
    91
        String subClassConstGoldenFile = String.format(subClassConstsGoldenFileTemplate,
1bdeedb5446c 8008582: jtreg failures after conversion of shell tests to Java
vromero
parents: 16304
diff changeset
    92
                serialVersionUIDSuffix);
16304
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    93
        ToolBox.compareLines(Paths.get("SubClassConsts.h"),
16549
1bdeedb5446c 8008582: jtreg failures after conversion of shell tests to Java
vromero
parents: 16304
diff changeset
    94
                ToolBox.splitLines(subClassConstGoldenFile, "\n"), null, true);
16304
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    95
    }
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    96
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    97
}
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    98
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
    99
class SuperClassConsts implements Serializable {
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
   100
    // Define class constant values, base class is serializable
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
   101
    private static final long serialVersionUID = 6733861379283244755L;
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
   102
    public static final int SUPER_INT_CONSTANT = 3;
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
   103
    public final static float SUPER_FLOAT_CONSTANT = 99.3f;
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
   104
    public final static double SUPER_DOUBLE_CONSTANT  = 33.2;
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
   105
    public final static boolean SUPER_BOOLEAN_CONSTANT  = false;
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
   106
    // A token instance field
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
   107
    int instanceField;
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
   108
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
   109
    public native int numValues();
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
   110
}
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
   111
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
   112
class SubClassConsts extends SuperClassConsts {
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
   113
    private final static int SUB_INT_CONSTANT = 2;
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
   114
    private final static double SUB_DOUBLE_CONSTANT = 2.25;
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
   115
    private final static float SUB_FLOAT_CONSTANT = 7.90f;
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
   116
    private final static boolean SUB_BOOLEAN_CONSTANT = true;
475504933a2d 8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff changeset
   117
}