|
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 */ |
|
23 |
|
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 */ |
|
34 |
|
35 import java.io.*; |
|
36 import java.nio.file.Paths; |
|
37 |
|
38 //original test: test/tools/javah/ConstMacroTest.sh |
|
39 public class ConstMacroTest { |
|
40 |
|
41 private static final String SubClassConstsGoldenFile = |
|
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 6733861379283244755LL\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"; |
|
73 |
|
74 public static void main(String[] args) throws Exception { |
|
75 //first steps are now done by jtreg |
|
76 // cp "${TESTSRC}${FS}SuperClassConsts.java" . |
|
77 // cp "${TESTSRC}${FS}SubClassConsts.java" . |
|
78 |
|
79 // "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d . "${TESTSRC}${FS}SubClassConsts.java" |
|
80 |
|
81 // "${TESTJAVA}${FS}bin${FS}javah" ${TESTTOOLVMOPTS} SubClassConsts |
|
82 ToolBox.JavaToolArgs successParams = |
|
83 new ToolBox.JavaToolArgs() |
|
84 .setAllArgs("-cp", System.getProperty("test.classes"), "SubClassConsts"); |
|
85 ToolBox.javah(successParams); |
|
86 |
|
87 // diff ${DIFFOPTS} "${TESTSRC}${FS}${EXPECTED_JAVAH_OUT_FILE}" "${GENERATED_HEADER_FILE}" |
|
88 ToolBox.compareLines(Paths.get("SubClassConsts.h"), |
|
89 ToolBox.splitLines(SubClassConstsGoldenFile), null); |
|
90 } |
|
91 |
|
92 } |
|
93 |
|
94 class SuperClassConsts implements Serializable { |
|
95 // Define class constant values, base class is serializable |
|
96 private static final long serialVersionUID = 6733861379283244755L; |
|
97 public static final int SUPER_INT_CONSTANT = 3; |
|
98 public final static float SUPER_FLOAT_CONSTANT = 99.3f; |
|
99 public final static double SUPER_DOUBLE_CONSTANT = 33.2; |
|
100 public final static boolean SUPER_BOOLEAN_CONSTANT = false; |
|
101 // A token instance field |
|
102 int instanceField; |
|
103 |
|
104 public native int numValues(); |
|
105 } |
|
106 |
|
107 class SubClassConsts extends SuperClassConsts { |
|
108 private final static int SUB_INT_CONSTANT = 2; |
|
109 private final static double SUB_DOUBLE_CONSTANT = 2.25; |
|
110 private final static float SUB_FLOAT_CONSTANT = 7.90f; |
|
111 private final static boolean SUB_BOOLEAN_CONSTANT = true; |
|
112 } |