Thu, 20 Mar 2014 10:42:00 -0700
Merge
1 /*
2 * Copyright (c) 2013, 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 4786406 4781221 4780341 6214324
27 * @summary Validates rewritten javah handling of class defined constants and
28 * ensures that the appropriate macro definitions are placed in the generated
29 * header file.
30 * @library /tools/javac/lib
31 * @build ToolBox
32 * @run main ConstMacroTest
33 */
35 import java.io.*;
36 import java.nio.file.Paths;
38 //original test: test/tools/javah/ConstMacroTest.sh
39 public class ConstMacroTest {
41 private static final String subClassConstsGoldenFileTemplate =
42 "/* DO NOT EDIT THIS FILE - it is machine generated */\n" +
43 "#include <jni.h>\n" +
44 "/* Header for class SubClassConsts */\n" +
45 "\n" +
46 "#ifndef _Included_SubClassConsts\n" +
47 "#define _Included_SubClassConsts\n" +
48 "#ifdef __cplusplus\n" +
49 "extern \"C\" {\n" +
50 "#endif\n" +
51 "#undef SubClassConsts_serialVersionUID\n" +
52 "#define SubClassConsts_serialVersionUID 6733861379283244755%s\n" +
53 "#undef SubClassConsts_SUPER_INT_CONSTANT\n" +
54 "#define SubClassConsts_SUPER_INT_CONSTANT 3L\n" +
55 "#undef SubClassConsts_SUPER_FLOAT_CONSTANT\n" +
56 "#define SubClassConsts_SUPER_FLOAT_CONSTANT 99.3f\n" +
57 "#undef SubClassConsts_SUPER_DOUBLE_CONSTANT\n" +
58 "#define SubClassConsts_SUPER_DOUBLE_CONSTANT 33.2\n" +
59 "#undef SubClassConsts_SUPER_BOOLEAN_CONSTANT\n" +
60 "#define SubClassConsts_SUPER_BOOLEAN_CONSTANT 0L\n" +
61 "#undef SubClassConsts_SUB_INT_CONSTANT\n" +
62 "#define SubClassConsts_SUB_INT_CONSTANT 2L\n" +
63 "#undef SubClassConsts_SUB_DOUBLE_CONSTANT\n" +
64 "#define SubClassConsts_SUB_DOUBLE_CONSTANT 2.25\n" +
65 "#undef SubClassConsts_SUB_FLOAT_CONSTANT\n" +
66 "#define SubClassConsts_SUB_FLOAT_CONSTANT 7.9f\n" +
67 "#undef SubClassConsts_SUB_BOOLEAN_CONSTANT\n" +
68 "#define SubClassConsts_SUB_BOOLEAN_CONSTANT 1L\n" +
69 "#ifdef __cplusplus\n" +
70 "}\n" +
71 "#endif\n" +
72 "#endif";
74 private static final String serialVersionUIDSuffix =
75 ToolBox.isWindows() ? "i64" : "LL"; ;
77 public static void main(String[] args) throws Exception {
78 //first steps are now done by jtreg
79 // cp "${TESTSRC}${FS}SuperClassConsts.java" .
80 // cp "${TESTSRC}${FS}SubClassConsts.java" .
82 // "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d . "${TESTSRC}${FS}SubClassConsts.java"
84 // "${TESTJAVA}${FS}bin${FS}javah" ${TESTTOOLVMOPTS} SubClassConsts
85 ToolBox.JavaToolArgs successParams =
86 new ToolBox.JavaToolArgs()
87 .setAllArgs("-cp", System.getProperty("test.classes"), "SubClassConsts");
88 ToolBox.javah(successParams);
90 // diff ${DIFFOPTS} "${TESTSRC}${FS}${EXPECTED_JAVAH_OUT_FILE}" "${GENERATED_HEADER_FILE}"
91 String subClassConstGoldenFile = String.format(subClassConstsGoldenFileTemplate,
92 serialVersionUIDSuffix);
93 ToolBox.compareLines(Paths.get("SubClassConsts.h"),
94 ToolBox.splitLines(subClassConstGoldenFile, "\n"), null, true);
95 }
97 }
99 class SuperClassConsts implements Serializable {
100 // Define class constant values, base class is serializable
101 private static final long serialVersionUID = 6733861379283244755L;
102 public static final int SUPER_INT_CONSTANT = 3;
103 public final static float SUPER_FLOAT_CONSTANT = 99.3f;
104 public final static double SUPER_DOUBLE_CONSTANT = 33.2;
105 public final static boolean SUPER_BOOLEAN_CONSTANT = false;
106 // A token instance field
107 int instanceField;
109 public native int numValues();
110 }
112 class SubClassConsts extends SuperClassConsts {
113 private final static int SUB_INT_CONSTANT = 2;
114 private final static double SUB_DOUBLE_CONSTANT = 2.25;
115 private final static float SUB_FLOAT_CONSTANT = 7.90f;
116 private final static boolean SUB_BOOLEAN_CONSTANT = true;
117 }